Skip to content

Commit

Permalink
QUAL: feature parity between vendor and customer template invoice (#2…
Browse files Browse the repository at this point in the history
…6588)

* NEW: Add invoice subtype

* Add subtype, propagate extrafields and clean up

* fix empty line

* fix phan error
  • Loading branch information
sonikf authored Apr 8, 2024
1 parent 3949197 commit 672ba6f
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 73 deletions.
23 changes: 14 additions & 9 deletions htdocs/fourn/class/fournisseur.facture-rec.class.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2017-2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2017-2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2023-2024 Nick Fragoulis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -239,7 +240,6 @@ class FactureFournisseurRec extends CommonInvoice
'revenuestamp' => array('type' => 'double(24,8)', 'label' => 'RevenueStamp', 'enabled' => 1, 'visible' => -1, 'position' => 160, 'isameasure' => 1),
'auto_validate' => array('type' => 'integer', 'label' => 'Auto validate', 'enabled' => 1, 'visible' => -1, 'position' => 165),
'generate_pdf' => array('type' => 'integer', 'label' => 'Generate pdf', 'enabled' => 1, 'visible' => -1, 'position' => 170),

);
// END MODULEBUILDER PROPERTIES

Expand Down Expand Up @@ -300,6 +300,7 @@ public function create($user, $facFournId, $notrigger = 0)
if ($result > 0) {
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_rec (';
$sql .= 'titre';
$sql .= ", subtype";
$sql .= ', ref_supplier';
$sql .= ', entity';
$sql .= ', fk_soc';
Expand Down Expand Up @@ -330,6 +331,7 @@ public function create($user, $facFournId, $notrigger = 0)
$sql .= ', generate_pdf';
$sql .= ') VALUES (';
$sql .= "'".$this->db->escape($this->title)."'";
$sql .= ", ".($this->subtype ? "'".$this->db->escape($this->subtype)."'" : "null");
$sql .= ", '".$this->db->escape($this->ref_supplier)."'";
$sql .= ", ".((int) $conf->entity);
$sql .= ", ".((int) $facfourn_src->socid);
Expand Down Expand Up @@ -498,6 +500,7 @@ public function update(User $user, $notrigger = 0)

$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_rec SET";
$sql .= " titre = '" . (!empty($this->title) ? $this->db->escape($this->title) : "")."'," ;
$sql .= " subtype=".(isset($this->subtype) ? $this->db->escape($this->subtype) : "null").",";
$sql .= " ref_supplier = '". (!empty($this->ref_supplier) ? $this->db->escape($this->ref_supplier) : "")."',";
$sql .= " entity = ". (!empty($this->entity) ? ((int) $this->entity) : 1) . ',';
if (!empty($this->socid) && $this->socid > 0) {
Expand Down Expand Up @@ -578,7 +581,7 @@ public function update(User $user, $notrigger = 0)
*/
public function fetch($rowid, $ref = '', $ref_ext = '')
{
$sql = 'SELECT f.rowid, f.titre as title, f.ref_supplier, f.entity, f.fk_soc';
$sql = 'SELECT f.rowid, f.titre as title, f.subtype, f.ref_supplier, f.entity, f.fk_soc';
$sql .= ', f.datec, f.tms, f.suspended';
$sql .= ', f.libelle as label';
$sql .= ', f.vat_src_code, f.localtax1, f.localtax2';
Expand Down Expand Up @@ -614,6 +617,7 @@ public function fetch($rowid, $ref = '', $ref_ext = '')
$this->id = $obj->rowid;
$this->titre = $obj->title;
$this->title = $obj->title;
$this->subtype = $obj->subtype;
$this->ref = $obj->title;
$this->ref_supplier = $obj->ref_supplier;
$this->entity = $obj->entity;
Expand Down Expand Up @@ -1338,6 +1342,7 @@ public function createRecurringInvoices($restrictioninvoiceid = 0, $forcevalidat
$new_fac_fourn->fk_fac_rec_source = $facturerec->id; // We will create $facture from this recurring invoice

$new_fac_fourn->type = self::TYPE_STANDARD;
$new_fac_fourn->subtype = $facturerec->subtype;
$new_fac_fourn->statut = self::STATUS_DRAFT; // deprecated
$new_fac_fourn->status = self::STATUS_DRAFT;
$new_fac_fourn->date = empty($facturerec->date_when) ? $now : $facturerec->date_when; // We could also use dol_now here but we prefer date_when so invoice has real date when we would like even if we generate later.
Expand Down
158 changes: 94 additions & 64 deletions htdocs/fourn/facture/card-rec.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
* Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2016 Meziane Sof <virtualsof@yahoo.fr>
* Copyright (C) 2017-2018 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2023-2024 Nick Fragoulis
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -191,38 +192,38 @@
}

if (! $error) {
$object->titre = GETPOST('title', 'alphanohtml'); // deprecated
$object->title = GETPOST('title', 'alphanohtml');
$object->libelle = GETPOST('libelle', 'alpha'); // deprecated
$object->label = GETPOST('libelle', 'alpha');
$object->fk_project = GETPOSTINT('projectid');
$object->ref_supplier = GETPOST('ref_supplier', 'alphanohtml');

$object->note_private = GETPOST('note_private', 'restricthtml');
$object->note_public = GETPOST('note_public', 'restricthtml');
$object->model_pdf = GETPOST('modelpdf', 'alpha');
$object->usenewprice = GETPOST('usenewprice', 'alpha');

$object->frequency = $frequency;
$object->unit_frequency = GETPOST('unit_frequency', 'alpha');
$object->nb_gen_max = $nb_gen_max;
$object->auto_validate = GETPOSTINT('auto_validate');
$object->generate_pdf = GETPOSTINT('generate_pdf');
$object->subtype = GETPOSTINT('subtype');
$object->title = GETPOST('title', 'alphanohtml');
$object->libelle = GETPOST('libelle', 'alpha'); // deprecated
$object->label = GETPOST('libelle', 'alpha');
$object->fk_project = GETPOSTINT('projectid');
$object->ref_supplier = GETPOST('ref_supplier', 'alphanohtml');

$object->note_private = GETPOST('note_private', 'restricthtml');
$object->note_public = GETPOST('note_public', 'restricthtml');
$object->model_pdf = GETPOST('modelpdf', 'alpha');
$object->usenewprice = GETPOST('usenewprice', 'alpha');

$object->frequency = $frequency;
$object->unit_frequency = GETPOST('unit_frequency', 'alpha');
$object->nb_gen_max = $nb_gen_max;
$object->auto_validate = GETPOSTINT('auto_validate');
$object->generate_pdf = GETPOSTINT('generate_pdf');

$date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear);
$object->date_when = $date_next_execution;

$ret = $extrafields->setOptionalsFromPost(null, $object);
if ($ret < 0) {
$error++;
}


$db->begin();

$oldinvoice = new FactureFournisseur($db);
$oldinvoice->fetch(GETPOSTINT('facid'));

$object->cond_reglement_id = $oldinvoice->cond_reglement_id;
$object->cond_reglement_code = $oldinvoice->cond_reglement_code;
$object->cond_reglement_label = $oldinvoice->cond_reglement_label;
$object->cond_reglement_doc = $oldinvoice->cond_reglement_doc;
$object->mode_reglement_id = $oldinvoice->mode_reglement_id;
$object->mode_reglement_code = $oldinvoice->mode_reglement_code;

$result = $object->create($user, $oldinvoice->id);

Expand Down Expand Up @@ -933,6 +934,13 @@
print '<tr><td class="titlefieldcreate">' . $langs->trans("Customer") . '</td><td>' . $object->thirdparty->getNomUrl(1, 'customer') . '</td>';
print '</tr>';

// Invoice subtype
if (getDolGlobalInt('INVOICE_SUBTYPE_ENABLED')) {
print "<tr><td>".$langs->trans("InvoiceSubtype")."</td><td>";
print $form->getSelectInvoiceSubtype(GETPOSTISSET('subtype') ? GETPOST('subtype') : $object->subtype, 'subtype', 0, 0, '');
print "</td></tr>";
}

$note_public = GETPOSTISSET('note_public') ? GETPOST('note_public', 'restricthtml') : $object->note_public;
$note_private = GETPOSTISSET('note_private') ? GETPOST('note_private', 'restricthtml') : $object->note_private;

Expand Down Expand Up @@ -965,38 +973,18 @@
print '<input class="flat quatrevingtpercent" type="text" name="libelle" value="' . $object->label . '">';
print '</td></tr>';

// Public note
print '<tr>';
print '<td class="tdtop">';
print $form->textwithpicto($langs->trans('NotePublic'), $htmltext, 1, 'help', '', 0, 2, 'notepublic');
print '</td>';
print '<td>';
$doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
print $doleditor->Create(1);

// Private note
if (empty($user->socid)) {
print '<tr>';
print '<td class="tdtop">';
print $form->textwithpicto($langs->trans('NotePrivate'), $htmltext, 1, 'help', '', 0, 2, 'noteprivate');
print '</td>';
print '<td>';
$doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
print $doleditor->Create(1);
print '</td></tr>';
}

// Author
print "<tr><td>" . $langs->trans("Author") . "</td><td>" . $user->getFullName($langs) . "</td></tr>";

// Payment term
print "<tr><td>" . $langs->trans("PaymentConditions") . "</td><td>";
$form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->cond_reglement_id, 'none');
print $form->getSelectConditionsPaiements(GETPOSTISSET('cond_reglement_id') ? GETPOST('cond_reglement_id', 'int') : $object->cond_reglement_id, 'cond_reglement_id', -1, 0, 0, '');
print "</td></tr>";

// Payment mode
print "<tr><td>" . $langs->trans("PaymentMode") . "</td><td>";
$form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'none', '', 1);
print img_picto('', 'payment', 'class="pictofixedwidth"');
print $form->select_types_paiements(GETPOSTISSET('mode_reglement_id') ? GETPOST('mode_reglement_id', 'int') : $object->mode_reglement_id, 'mode_reglement_id', '', 0, 1, 0, 0, 1, '', 1);
print "</td></tr>";

// Project
Expand All @@ -1016,13 +1004,46 @@
print "</td></tr>";
}

//extrafields
$draft = new FactureFournisseur($db);
$draft->fetch(GETPOST('facid', 'int'));

$extralabels = new ExtraFields($db);
$extralabels = $extrafields->fetch_name_optionals_label($draft->table_element);
if ($draft->fetch_optionals() > 0) {
$object->array_options = array_merge($object->array_options, $draft->array_options);
}

print $object->showOptionals($extrafields, 'create', $parameters);

// Model pdf
print "<tr><td>" . $langs->trans('Model') . "</td><td>";
include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_invoice/modules_facturefournisseur.php';
$list = ModelePDFSuppliersInvoices::liste_modeles($db);
print $form->selectarray('modelpdf', $list, $conf->global->INVOICE_SUPPLIER_ADDON_PDF);
print "</td></tr>";

// Public note
print '<tr>';
print '<td class="tdtop">';
print $form->textwithpicto($langs->trans('NotePublic'), $htmltext, 1, 'help', '', 0, 2, 'notepublic');
print '</td>';
print '<td>';
$doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
print $doleditor->Create(1);

// Private note
if (empty($user->socid)) {
print '<tr>';
print '<td class="tdtop">';
print $form->textwithpicto($langs->trans('NotePrivate'), $htmltext, 1, 'help', '', 0, 2, 'noteprivate');
print '</td>';
print '<td>';
$doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
print $doleditor->Create(1);
print '</td></tr>';
}

print "</table>";

print dol_get_fiche_end();
Expand Down Expand Up @@ -1195,6 +1216,13 @@

print '<table class="border centpercent tableforfield">';

// Invoice subtype
if (getDolGlobalInt('INVOICE_SUBTYPE_ENABLED')) {
print "<tr><td>".$langs->trans("InvoiceSubtype")."</td><td>";
print $object->getSubtypeLabel('facture_fourn_rec');
print "</td></tr>";
}

print '<tr><td class="titlefield">' . $langs->trans('Author') . '</td><td>';
print $author->getNomUrl(-1);
print "</td></tr>";
Expand Down Expand Up @@ -1335,22 +1363,6 @@
}
$htmltext .= '</i>';

// Note public
print '<tr><td>';
print $form->editfieldkey($form->textwithpicto($langs->trans('NotePublic'), $htmltext, 1, 'help', '', 0, 2, 'notepublic'), 'note_public', $object->note_public, $object, $usercancreate);
print '</td><td class="wordbreak">';
print $form->editfieldval($langs->trans("NotePublic"), 'note_public', $object->note_public, $object, $usercancreate, 'textarea:' . ROWS_4 . ':90%', '', null, null, '', 1);
print '</td>';
print '</tr>';

// Note private
print '<tr><td>';
print $form->editfieldkey($form->textwithpicto($langs->trans("NotePrivate"), $htmltext, 1, 'help', '', 0, 2, 'noteprivate'), 'note_private', $object->note_private, $object, $usercancreate);
print '</td><td class="wordbreak">';
print $form->editfieldval($langs->trans("NotePrivate"), 'note_private', $object->note_private, $object, $usercancreate, 'textarea:' . ROWS_4 . ':90%', '', null, null, '', 1);
print '</td>';
print '</tr>';

// Bank Account
print '<tr><td class="nowrap">';
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
Expand All @@ -1369,6 +1381,25 @@
print "</td>";
print '</tr>';

// Extrafields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';

// Note public
print '<tr><td>';
print $form->editfieldkey($form->textwithpicto($langs->trans('NotePublic'), $htmltext, 1, 'help', '', 0, 2, 'notepublic'), 'note_public', $object->note_public, $object, $user->hasRight('facture', 'creer'));
print '</td><td class="wordbreak">';
print $form->editfieldval($langs->trans("NotePublic"), 'note_public', $object->note_public, $object, $user->hasRight('facture', 'creer'), 'textarea:'.ROWS_4.':90%', '', null, null, '', 1);
print '</td>';
print '</tr>';

// Note private
print '<tr><td>';
print $form->editfieldkey($form->textwithpicto($langs->trans("NotePrivate"), $htmltext, 1, 'help', '', 0, 2, 'noteprivate'), 'note_private', $object->note_private, $object, $user->hasRight('facture', 'creer'));
print '</td><td class="wordbreak">';
print $form->editfieldval($langs->trans("NotePrivate"), 'note_private', $object->note_private, $object, $user->hasRight('facture', 'creer'), 'textarea:'.ROWS_4.':90%', '', null, null, '', 1);
print '</td>';
print '</tr>';

// Model pdf
print '<tr><td class="nowrap">';
print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
Expand Down Expand Up @@ -1397,7 +1428,6 @@

// Other attributes
$cols = 2;
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';

print '</table>';

Expand Down

0 comments on commit 672ba6f

Please sign in to comment.