NEW: Add invoice subtype in customer template invoice (#26543)

* Add invoice subtype in template invoice

* Add invoice subtype in template invoice

* Add invoice subtype in template invoice
This commit is contained in:
sonikf
2023-11-12 23:08:46 +02:00
committed by GitHub
parent a1c295185d
commit 65b9f4e6de
3 changed files with 60 additions and 15 deletions

View File

@@ -204,21 +204,22 @@ if (empty($reshook)) {
}
if (!$error) {
$object->title = GETPOST('title', 'alphanohtml');
$object->note_private = GETPOST('note_private', 'restricthtml');
$object->note_public = GETPOST('note_public', 'restricthtml');
$object->model_pdf = GETPOST('modelpdf', 'alphanohtml');
$object->usenewprice = GETPOST('usenewprice', 'alphanohtml');
$object->subtype = GETPOST('subtype');
$object->title = GETPOST('title', 'alphanohtml');
$object->note_private = GETPOST('note_private', 'restricthtml');
$object->note_public = GETPOST('note_public', 'restricthtml');
$object->model_pdf = GETPOST('modelpdf', 'alphanohtml');
$object->usenewprice = GETPOST('usenewprice', 'alphanohtml');
$object->mode_reglement_id = GETPOST('mode_reglement_id', 'int');
$object->cond_reglement_id = GETPOST('cond_reglement_id', 'int');
$object->mode_reglement_id = GETPOST('mode_reglement_id', 'int');
$object->cond_reglement_id = GETPOST('cond_reglement_id', 'int');
$object->frequency = $frequency;
$object->unit_frequency = GETPOST('unit_frequency', 'alpha');
$object->nb_gen_max = $nb_gen_max;
$object->auto_validate = GETPOST('auto_validate', 'int');
$object->generate_pdf = GETPOST('generate_pdf', 'int');
$object->fk_project = $projectid;
$object->frequency = $frequency;
$object->unit_frequency = GETPOST('unit_frequency', 'alpha');
$object->nb_gen_max = $nb_gen_max;
$object->auto_validate = GETPOST('auto_validate', 'int');
$object->generate_pdf = GETPOST('generate_pdf', 'int');
$object->fk_project = $projectid;
$date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear);
$object->date_when = $date_next_execution;
@@ -1002,6 +1003,13 @@ if ($action == 'create') {
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', -1, 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;
@@ -1285,14 +1293,24 @@ if ($action == 'create') {
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_rec');
print "</td></tr>";
}
// Author
print '<tr><td class="titlefield">'.$langs->trans("Author").'</td><td>';
print $author->getNomUrl(-1);
print "</td></tr>";
// Amount (excl. tax)
print '<tr><td>'.$langs->trans("AmountHT").'</td>';
print '<td>'.price($object->total_ht, '', $langs, 1, -1, -1, $conf->currency).'</td>';
print '</tr>';
// Amount tax
print '<tr><td>'.$langs->trans("AmountVAT").'</td><td>'.price($object->total_tva, '', $langs, 1, -1, -1, $conf->currency).'</td>';
print '</tr>';

View File

@@ -7,6 +7,7 @@
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2017-2020 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2023 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
@@ -174,7 +175,8 @@ class FactureRec extends CommonInvoice
'titre' =>array('type'=>'varchar(100)', 'label'=>'Titre', 'enabled'=>1, 'showoncombobox' => 1, 'visible'=>-1, 'position'=>15),
'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>20, 'index'=>1),
'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'enabled'=>'isModEnabled("societe")', 'visible'=>-1, 'notnull'=>1, 'position'=>25),
'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>30),
'subtype' =>array('type'=>'smallint(6)', 'label'=>'InvoiceSubtype', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>30),
'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>35),
'total_tva' =>array('type'=>'double(24,8)', 'label'=>'Tva', 'enabled'=>1, 'visible'=>-1, 'position'=>55, 'isameasure'=>1),
'localtax1' =>array('type'=>'double(24,8)', 'label'=>'Localtax1', 'enabled'=>1, 'visible'=>-1, 'position'=>60, 'isameasure'=>1),
'localtax2' =>array('type'=>'double(24,8)', 'label'=>'Localtax2', 'enabled'=>1, 'visible'=>-1, 'position'=>65, 'isameasure'=>1),
@@ -273,6 +275,7 @@ class FactureRec extends CommonInvoice
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_rec (";
$sql .= "titre";
$sql .= ", fk_soc";
$sql .= ", subtype";
$sql .= ", entity";
$sql .= ", datec";
$sql .= ", amount";
@@ -301,6 +304,7 @@ class FactureRec extends CommonInvoice
$sql .= ") VALUES (";
$sql .= "'".$this->db->escape($this->titre ? $this->titre : $this->title)."'";
$sql .= ", ".((int) $this->socid);
$sql .= ", ".($this->subtype ? "'".$this->db->escape($this->subtype)."'" : "null");
$sql .= ", ".((int) $conf->entity);
$sql .= ", '".$this->db->idate($now)."'";
$sql .= ", ".(!empty($facsrc->total_ttc) ? ((float) $facsrc->total_ttc) : '0');
@@ -545,7 +549,7 @@ class FactureRec extends CommonInvoice
{
dol_syslog('FactureRec::fetch', LOG_DEBUG);
$sql = 'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc, f.total_tva, f.localtax1, f.localtax2, f.total_ht, f.total_ttc';
$sql = 'SELECT f.rowid, f.entity, f.titre as title, f.suspended, f.fk_soc, f.subtype, f.total_tva, f.localtax1, f.localtax2, f.total_ht, f.total_ttc';
$sql .= ', f.date_lim_reglement as dlr';
$sql .= ', f.note_private, f.note_public, f.fk_user_author';
$sql .= ', f.modelpdf as model_pdf';
@@ -583,6 +587,7 @@ class FactureRec extends CommonInvoice
$this->titre = $obj->title; // deprecated
$this->title = $obj->title;
$this->ref = $obj->title;
$this->subtype = $obj->subtype;
$this->suspended = $obj->suspended;
$this->total_ht = $obj->total_ht;
$this->total_tva = $obj->total_tva;
@@ -1345,6 +1350,7 @@ class FactureRec extends CommonInvoice
$facture->fk_fac_rec_source = $facturerec->id; // We will create $facture from this recurring invoice
$facture->type = self::TYPE_STANDARD;
$facture->subtype = $facturerec->subtype;
$facture->statut = self::STATUS_DRAFT; // deprecated
$facture->status = self::STATUS_DRAFT;
$facture->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.

View File

@@ -694,6 +694,27 @@ abstract class CommonInvoice extends CommonObject
$resql = $this->db->query($sql);
if ($resql) {
$subtypeLabel = '';
while ($obj = $this->db->fetch_object($resql)) {
$subtypeLabel = $obj->label;
}
if (!empty($subtypeLabel)) {
print ' ' . $subtypeLabel;
}
} else {
dol_print_error($this->db);
return -1;
}
} elseif ($table === 'facture_rec' || $table === 'facture_fourn_rec') {
$sql = "SELECT s.label FROM " . MAIN_DB_PREFIX . $table . " AS f";
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "c_invoice_subtype AS s ON f.subtype = s.rowid";
$sql .= " WHERE f.titre = '".$this->db->escape($this->titre)."'";
$resql = $this->db->query($sql);
if ($resql) {
$subtypeLabel = '';