From 7a651b50719a74bfcd795b8a59efc18933230f15 Mon Sep 17 00:00:00 2001 From: Ferran Marcet Date: Fri, 26 Apr 2019 13:53:22 +0200 Subject: [PATCH 1/7] New: Add ref_client field on template invoice --- .../facture/class/facture-rec.class.php | 6 ++++- htdocs/compta/facture/class/facture.class.php | 1 + htdocs/compta/facture/fiche-rec.php | 22 ++++++++++++++++--- .../install/mysql/migration/9.0.0-10.0.0.sql | 1 + .../install/mysql/tables/llx_facture_rec.sql | 1 + 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 89f324d2450..eba6fa42288 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -77,6 +77,7 @@ class FactureRec extends CommonInvoice public $total; public $db_table; public $propalid; + public $ref_client; public $date_last_gen; public $date_when; @@ -166,6 +167,7 @@ class FactureRec extends CommonInvoice $sql.= ", fk_account"; $sql.= ", fk_cond_reglement"; $sql.= ", fk_mode_reglement"; + $sql.= ", ref_client"; $sql.= ", usenewprice"; $sql.= ", frequency"; $sql.= ", unit_frequency"; @@ -194,6 +196,7 @@ class FactureRec extends CommonInvoice $sql.= ", ".(! empty($facsrc->fk_account)?"'".$facsrc->fk_account."'":"null"); $sql.= ", ".($facsrc->cond_reglement_id > 0 ? $this->db->escape($facsrc->cond_reglement_id) : "null"); $sql.= ", ".($facsrc->mode_reglement_id > 0 ? $this->db->escape($facsrc->mode_reglement_id) : "null"); + $sql.= ",'".$this->db->escape($this->ref_client)."'"; $sql.= ", ".$this->usenewprice; $sql.= ", ".$this->frequency; $sql.= ", '".$this->db->escape($this->unit_frequency)."'"; @@ -382,7 +385,7 @@ class FactureRec extends CommonInvoice $sql.= ', f.note_private, f.note_public, f.fk_user_author'; $sql.= ', f.modelpdf'; $sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet as fk_project'; - $sql.= ', f.fk_account'; + $sql.= ', f.fk_account, f.ref_client'; $sql.= ', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.usenewprice, f.auto_validate'; $sql.= ', f.generate_pdf'; $sql.= ", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc"; @@ -1127,6 +1130,7 @@ class FactureRec extends CommonInvoice $facture->brouillon = 1; $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. $facture->socid = $facturerec->socid; + $facture->ref_client = $facturerec->ref_client; $invoiceidgenerated = $facture->create($user); if ($invoiceidgenerated <= 0) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index c2dc89c903e..9e9005d471d 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -358,6 +358,7 @@ class Facture extends CommonInvoice $this->socid = $_facrec->socid; // Invoice created on same thirdparty than template $this->entity = $_facrec->entity; // Invoice created in same entity than template + $this->ref_client = $_facrec->ref_client; // Fields coming from GUI (priority on template). TODO Value of template should be used as default value on GUI so we can use here always value from GUI $this->fk_project = GETPOST('projectid', 'int') > 0 ? ((int) GETPOST('projectid', 'int')) : $_facrec->fk_project; diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index fa8af87ac29..25144edbcb3 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -174,6 +174,7 @@ if (empty($reshook)) if (! $error) { $object->titre = GETPOST('titre', 'alpha'); + $object->ref_client = GETPOST('ref_client', 'alpha'); $object->note_private = GETPOST('note_private', 'none'); $object->note_public = GETPOST('note_public', 'none'); $object->modelpdf = GETPOST('modelpdf', 'alpha'); @@ -274,7 +275,7 @@ if (empty($reshook)) { $object->setProject(GETPOST('projectid', 'int')); } - // Set bank account + // Set titre elseif ($action == 'setref' && $user->rights->facture->creer) { //var_dump(GETPOST('ref', 'alpha'));exit; @@ -286,6 +287,15 @@ if (empty($reshook)) } else dol_print_error($db, $object->error, $object->errors); } + elseif ($action == 'setref_client' && $user->rights->facture->creer) + { + $result=$object->setValueFrom('ref_client', GETPOST('ref_client', 'alpha'), '', null, 'text', '', $user, 'BILLREC_MODIFY'); + if ($result > 0) + { + $object->ref_client = GETPOST('ref_client', 'alpha'); + } + else dol_print_error($db, $object->error, $object->errors); + } // Set bank account elseif ($action == 'setbankaccount' && $user->rights->facture->creer) { @@ -997,6 +1007,11 @@ if ($action == 'create') print ''; print ''; + // Ref Client + print ''.$langs->trans("RefCustomer").''; + print ''; + print ''; + // Third party print ''.$langs->trans("Customer").''.$object->thirdparty->getNomUrl(1, 'customer').''; print ''; @@ -1229,8 +1244,9 @@ else $morehtmlref.='
'; // Ref customer - //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', 0, 1); - //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', null, null, '', 1); + $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', 0, 1); + $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', null, null, '', 1); + $morehtmlref.='
'; // Thirdparty $morehtmlref.=$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1); // Project diff --git a/htdocs/install/mysql/migration/9.0.0-10.0.0.sql b/htdocs/install/mysql/migration/9.0.0-10.0.0.sql index 9aa395c22d6..49a19de5316 100644 --- a/htdocs/install/mysql/migration/9.0.0-10.0.0.sql +++ b/htdocs/install/mysql/migration/9.0.0-10.0.0.sql @@ -297,3 +297,4 @@ ALTER TABLE llx_inventorydet DROP COLUMN pmp; ALTER TABLE llx_inventorydet DROP COLUMN pa; ALTER TABLE llx_inventorydet DROP COLUMN new_pmp; +ALTER TABLE llx_facture_rec ADD COLUMN ref_client varchar(255) after suspended; \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_facture_rec.sql b/htdocs/install/mysql/tables/llx_facture_rec.sql index 1add07c6e8c..2c1c2514488 100644 --- a/htdocs/install/mysql/tables/llx_facture_rec.sql +++ b/htdocs/install/mysql/tables/llx_facture_rec.sql @@ -29,6 +29,7 @@ create table llx_facture_rec tms timestamp, -- date creation/modification suspended integer DEFAULT 0, -- 1=suspended + ref_client varchar(255), -- reference for customer amount double(24,8) DEFAULT 0 NOT NULL, remise real DEFAULT 0, From be17e31be18e8bf2e126262f870b6b724b679a0b Mon Sep 17 00:00:00 2001 From: Ferran Marcet Date: Thu, 2 May 2019 11:04:55 +0200 Subject: [PATCH 2/7] New: Add ref_client field on template invoice --- htdocs/compta/facture/fiche-rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index 25144edbcb3..fa71bdd7f2e 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -1009,7 +1009,7 @@ if ($action == 'create') // Ref Client print ''.$langs->trans("RefCustomer").''; - print ''; + print ''; print ''; // Third party From d810e11c4ed967fff1533e003d6567504b31ab2e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 24 Jun 2019 19:23:32 +0200 Subject: [PATCH 3/7] Update fiche-rec.php --- htdocs/compta/facture/fiche-rec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index fa71bdd7f2e..c9ee6e592ee 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -275,7 +275,7 @@ if (empty($reshook)) { $object->setProject(GETPOST('projectid', 'int')); } - // Set titre + // Set title/label of template invoice elseif ($action == 'setref' && $user->rights->facture->creer) { //var_dump(GETPOST('ref', 'alpha'));exit; From e4984492b3173a053362da42bd11f59b7d511ed4 Mon Sep 17 00:00:00 2001 From: Ferran Marcet Date: Tue, 17 Sep 2019 09:32:43 +0200 Subject: [PATCH 4/7] Dejarlo igual que develop --- htdocs/compta/facture/class/facture-rec.class.php | 6 +----- htdocs/compta/facture/class/facture.class.php | 1 - htdocs/install/mysql/tables/llx_facture_rec.sql | 1 - 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 57ecc836acf..37a031198bc 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -77,7 +77,6 @@ class FactureRec extends CommonInvoice public $total; public $db_table; public $propalid; - public $ref_client; public $date_last_gen; public $date_when; @@ -168,7 +167,6 @@ class FactureRec extends CommonInvoice $sql.= ", fk_account"; $sql.= ", fk_cond_reglement"; $sql.= ", fk_mode_reglement"; - $sql.= ", ref_client"; $sql.= ", usenewprice"; $sql.= ", frequency"; $sql.= ", unit_frequency"; @@ -197,7 +195,6 @@ class FactureRec extends CommonInvoice $sql.= ", ".(! empty($facsrc->fk_account)?"'".$facsrc->fk_account."'":"null"); $sql.= ", ".($facsrc->cond_reglement_id > 0 ? $this->db->escape($facsrc->cond_reglement_id) : "null"); $sql.= ", ".($facsrc->mode_reglement_id > 0 ? $this->db->escape($facsrc->mode_reglement_id) : "null"); - $sql.= ",'".$this->db->escape($this->ref_client)."'"; $sql.= ", ".$this->usenewprice; $sql.= ", ".$this->frequency; $sql.= ", '".$this->db->escape($this->unit_frequency)."'"; @@ -386,7 +383,7 @@ class FactureRec extends CommonInvoice $sql.= ', f.note_private, f.note_public, f.fk_user_author'; $sql.= ', f.modelpdf'; $sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet as fk_project'; - $sql.= ', f.fk_account, f.ref_client'; + $sql.= ', f.fk_account'; $sql.= ', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.usenewprice, f.auto_validate'; $sql.= ', f.generate_pdf'; $sql.= ", f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc"; @@ -1147,7 +1144,6 @@ class FactureRec extends CommonInvoice $facture->brouillon = 1; $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. $facture->socid = $facturerec->socid; - $facture->ref_client = $facturerec->ref_client; $invoiceidgenerated = $facture->create($user); if ($invoiceidgenerated <= 0) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 70ecf6500f5..131f0ee90fd 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -372,7 +372,6 @@ class Facture extends CommonInvoice $this->socid = $_facrec->socid; // Invoice created on same thirdparty than template $this->entity = $_facrec->entity; // Invoice created in same entity than template - $this->ref_client = $_facrec->ref_client; // Fields coming from GUI (priority on template). TODO Value of template should be used as default value on GUI so we can use here always value from GUI $this->fk_project = GETPOST('projectid', 'int') > 0 ? ((int) GETPOST('projectid', 'int')) : $_facrec->fk_project; diff --git a/htdocs/install/mysql/tables/llx_facture_rec.sql b/htdocs/install/mysql/tables/llx_facture_rec.sql index 2c1c2514488..1add07c6e8c 100644 --- a/htdocs/install/mysql/tables/llx_facture_rec.sql +++ b/htdocs/install/mysql/tables/llx_facture_rec.sql @@ -29,7 +29,6 @@ create table llx_facture_rec tms timestamp, -- date creation/modification suspended integer DEFAULT 0, -- 1=suspended - ref_client varchar(255), -- reference for customer amount double(24,8) DEFAULT 0 NOT NULL, remise real DEFAULT 0, From 3f25a8d8d57d38792f46ac736dd6ce75630075da Mon Sep 17 00:00:00 2001 From: Ferran Marcet Date: Tue, 17 Sep 2019 09:38:08 +0200 Subject: [PATCH 5/7] New: Load invoices only if showed --- htdocs/compta/facture/card.php | 88 +++++++++++++++++----------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index ff5a280a118..6d0bf2f56bc 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -12,7 +12,7 @@ * Copyright (C) 2013 Jean-Francois FERRY * Copyright (C) 2013-2014 Florian Henry * Copyright (C) 2013 Cédric Salvador - * Copyright (C) 2014-2018 Ferran Marcet + * Copyright (C) 2014-2019 Ferran Marcet * Copyright (C) 2015-2016 Marcos García * Copyright (C) 2018 Frédéric France * @@ -2862,49 +2862,6 @@ if ($action == 'create') } } - // Type de facture - $facids = $facturestatic->list_replacable_invoices($soc->id); - if ($facids < 0) { - dol_print_error($db, $facturestatic); - exit(); - } - $options = ""; - foreach ($facids as $facparam) - { - $options .= ''; - } - - // Show link for credit note - $facids=$facturestatic->list_qualified_avoir_invoices($soc->id); - if ($facids < 0) - { - dol_print_error($db, $facturestatic); - exit; - } - $optionsav = ""; - $newinvoice_static = new Facture($db); - foreach ($facids as $key => $valarray) - { - $newinvoice_static->id = $key; - $newinvoice_static->ref = $valarray ['ref']; - $newinvoice_static->statut = $valarray ['status']; - $newinvoice_static->type = $valarray ['type']; - $newinvoice_static->paye = $valarray ['paye']; - - $optionsav .= ''; - } - print '' . $langs->trans('Type') . ''; print '
' . "\n"; @@ -2981,6 +2938,23 @@ if ($action == 'create') // Replacement if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT)) { + // Type de facture + $facids = $facturestatic->list_replacable_invoices($soc->id); + if ($facids < 0) { + dol_print_error($db, $facturestatic); + exit(); + } + $options = ""; + foreach ($facids as $facparam) + { + $options .= ''; + } + print ''; print '
'; $tmp='global->INVOICE_DISABLE_CREDIT_NOTE)) { + // Show link for credit note + $facids=$facturestatic->list_qualified_avoir_invoices($soc->id); + if ($facids < 0) + { + dol_print_error($db, $facturestatic); + exit; + } + $optionsav = ""; + $newinvoice_static = new Facture($db); + foreach ($facids as $key => $valarray) + { + $newinvoice_static->id = $key; + $newinvoice_static->ref = $valarray ['ref']; + $newinvoice_static->statut = $valarray ['status']; + $newinvoice_static->type = $valarray ['type']; + $newinvoice_static->paye = $valarray ['paye']; + + $optionsav .= ''; + } + print '
'; $tmp=' Date: Tue, 17 Sep 2019 09:43:15 +0200 Subject: [PATCH 6/7] New: Load invoices only if showed --- htdocs/fourn/facture/card.php | 87 ++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index ae042b4c4b8..db5b87e590f 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -10,6 +10,7 @@ * Copyright (C) 2014-2016 Marcos García * Copyright (C) 2016-2017 Alexandre Spangaro * Copyright (C) 2018 Frédéric France + * Copyright (C) 2019 Ferran Marcet * * 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 @@ -1765,49 +1766,6 @@ if ($action == 'create') print ''.$langs->trans('RefSupplier').''; print ''; - // Type invoice - $facids = $facturestatic->list_replacable_supplier_invoices($societe->id); - if ($facids < 0) { - dol_print_error($db, $facturestatic); - exit(); - } - $options = ""; - foreach ($facids as $facparam) - { - $options .= ''; - } - - // Show link for credit note - $facids=$facturestatic->list_qualified_avoir_supplier_invoices($societe->id); - if ($facids < 0) - { - dol_print_error($db, $facturestatic); - exit; - } - $optionsav = ""; - $newinvoice_static = new FactureFournisseur($db); - foreach ($facids as $key => $valarray) - { - $newinvoice_static->id = $key; - $newinvoice_static->ref = $valarray ['ref']; - $newinvoice_static->statut = $valarray ['status']; - $newinvoice_static->type = $valarray ['type']; - $newinvoice_static->paye = $valarray ['paye']; - - $optionsav .= ''; - } - print ''.$langs->trans('Type').''; print '
' . "\n"; @@ -1860,6 +1818,23 @@ if ($action == 'create') // Replacement if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT)) { + // Type invoice + $facids = $facturestatic->list_replacable_supplier_invoices($societe->id); + if ($facids < 0) { + dol_print_error($db, $facturestatic); + exit(); + } + $options = ""; + foreach ($facids as $facparam) + { + $options .= ''; + } + print ''; print '
'; $tmp='global->INVOICE_DISABLE_CREDIT_NOTE)) { + // Show link for credit note + $facids=$facturestatic->list_qualified_avoir_supplier_invoices($societe->id); + if ($facids < 0) + { + dol_print_error($db, $facturestatic); + exit; + } + $optionsav = ""; + $newinvoice_static = new FactureFournisseur($db); + foreach ($facids as $key => $valarray) + { + $newinvoice_static->id = $key; + $newinvoice_static->ref = $valarray ['ref']; + $newinvoice_static->statut = $valarray ['status']; + $newinvoice_static->type = $valarray ['type']; + $newinvoice_static->paye = $valarray ['paye']; + + $optionsav .= ''; + } + print '
'; $tmp=' Date: Tue, 24 Sep 2019 17:52:11 +0200 Subject: [PATCH 7/7] Qual: Clean code on sellist extrafields. Translate if query has only one field --- htdocs/core/class/extrafields.class.php | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 0a9f98b4afd..7e143af863a 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1269,7 +1269,7 @@ class ExtraFields // Several field into label (eq table:code|libelle:rowid) $notrans = false; $fields_label = explode('|', $InfoFieldList[1]); - if (is_array($fields_label)) { + if (is_array($fields_label) && count($fields_label) > 1) { $notrans = true; foreach ($fields_label as $field_toshow) { $labeltoshow .= $obj->$field_toshow . ' '; @@ -1283,27 +1283,16 @@ class ExtraFields if (!$notrans) { foreach ($fields_label as $field_toshow) { $translabel = $langs->trans($obj->$field_toshow); - if ($translabel != $obj->$field_toshow) { - $labeltoshow = dol_trunc($translabel, 18) . ' '; - } else { - $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' '; - } + $labeltoshow = dol_trunc($translabel, 18) . ' '; } } $out .= ''; } else { if (!$notrans) { $translabel = $langs->trans($obj->{$InfoFieldList[1]}); - if ($translabel != $obj->{$InfoFieldList[1]}) { - $labeltoshow = dol_trunc($translabel, 18); - } else { - $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18); - } + $labeltoshow = dol_trunc($translabel, 18); } if (empty($labeltoshow)) $labeltoshow = '(not defined)'; - if ($value == $obj->rowid) { - $out .= ''; - } if (!empty($InfoFieldList[3]) && $parentField) { $parent = $parentName . ':' . $obj->{$parentField};