From 832db82fcece9f9c44c7aec286fcec9cf75239a7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 18 Dec 2020 14:40:45 +0100 Subject: [PATCH] Fix warnings --- htdocs/compta/facture/class/facture-rec.class.php | 4 ++-- htdocs/core/lib/functions.lib.php | 2 +- htdocs/core/lib/price.lib.php | 2 +- .../modules/commande/doc/pdf_einstein.modules.php | 4 ++-- .../commande/doc/pdf_eratosthene.modules.php | 4 ++-- .../core/modules/facture/doc/pdf_crabe.modules.php | 4 ++-- .../modules/facture/doc/pdf_sponge.modules.php | 4 ++-- .../modules/product/doc/pdf_standard.modules.php | 4 ++-- .../core/modules/propale/doc/pdf_azur.modules.php | 4 ++-- .../core/modules/propale/doc/pdf_cyan.modules.php | 4 ++-- .../supplier_order/doc/pdf_cornas.modules.php | 4 ++-- .../supplier_order/doc/pdf_muscadet.modules.php | 4 ++-- .../supplier_proposal/doc/pdf_aurore.modules.php | 4 ++-- .../mymodule/doc/pdf_standard_myobject.modules.php | 4 ++-- .../class/supplier_proposal.class.php | 14 +++++++++++++- 15 files changed, 39 insertions(+), 27 deletions(-) diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index c9157f7b43d..9c0d191f0cf 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -935,9 +935,9 @@ class FactureRec extends CommonInvoice $sql .= ", ".price2num($txtva); $sql .= ", '".$this->db->escape($vat_src_code)."'"; $sql .= ", ".price2num($txlocaltax1); - $sql .= ", '".$this->db->escape($localtaxes_type[0])."'"; + $sql .= ", '".$this->db->escape(isset($localtaxes_type[0]) ? $localtaxes_type[0] : '')."'"; $sql .= ", ".price2num($txlocaltax2); - $sql .= ", '".$this->db->escape($localtaxes_type[2])."'"; + $sql .= ", '".$this->db->escape(isset($localtaxes_type[2]) ? $localtaxes_type[2] : '')."'"; $sql .= ", ".(!empty($fk_product) ? "'".$this->db->escape($fk_product)."'" : "null"); $sql .= ", ".$product_type; $sql .= ", ".price2num($remise_percent); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 67dcc5f44f9..db05f29fe5a 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5216,7 +5216,7 @@ function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisi } } - return 0; + return array(); } /** diff --git a/htdocs/core/lib/price.lib.php b/htdocs/core/lib/price.lib.php index ce14295b4b2..4e3ce29f69e 100644 --- a/htdocs/core/lib/price.lib.php +++ b/htdocs/core/lib/price.lib.php @@ -104,7 +104,7 @@ function calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocalt //var_dump($seller->country_id);exit; } if (empty($localtaxes_array) || !is_array($localtaxes_array)) { - dol_syslog("Price.lib::calcul_price_total Warning: function is called with parameter localtaxes_array that is missing", LOG_WARNING); + dol_syslog("Price.lib::calcul_price_total Warning: function is called with parameter localtaxes_array that is missing or empty", LOG_WARNING); } if (!is_numeric($txtva)) { dol_syslog("Price.lib::calcul_price_total Warning: function was called with a parameter vat rate that is not a real numeric value. There is surely a bug.", LOG_ERR); diff --git a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php index 5a0bbc30327..0b99583e08e 100644 --- a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php @@ -534,8 +534,8 @@ class pdf_einstein extends ModelePDFCommandes && (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax { $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc); - $localtax1_type = $localtaxtmp_array[0]; - $localtax2_type = $localtaxtmp_array[2]; + $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : ''; + $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : ''; } // retrieve global local tax diff --git a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php index 97354c5c266..d1492dbc5eb 100644 --- a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php @@ -758,8 +758,8 @@ class pdf_eratosthene extends ModelePDFCommandes && (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax { $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc); - $localtax1_type = $localtaxtmp_array[0]; - $localtax2_type = $localtaxtmp_array[2]; + $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : ''; + $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : ''; } // retrieve global local tax diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index ca3144ad9a3..ce44aac0319 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -658,8 +658,8 @@ class pdf_crabe extends ModelePDFFactures && (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax { $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc); - $localtax1_type = $localtaxtmp_array[0]; - $localtax2_type = $localtaxtmp_array[2]; + $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : ''; + $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : ''; } // retrieve global local tax diff --git a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php index 4087e3db098..423aa5b79d1 100644 --- a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php @@ -816,8 +816,8 @@ class pdf_sponge extends ModelePDFFactures && (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax { $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc); - $localtax1_type = $localtaxtmp_array[0]; - $localtax2_type = $localtaxtmp_array[2]; + $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : ''; + $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : ''; } // retrieve global local tax diff --git a/htdocs/core/modules/product/doc/pdf_standard.modules.php b/htdocs/core/modules/product/doc/pdf_standard.modules.php index dcd8419bca6..ceb1819df37 100644 --- a/htdocs/core/modules/product/doc/pdf_standard.modules.php +++ b/htdocs/core/modules/product/doc/pdf_standard.modules.php @@ -470,8 +470,8 @@ class pdf_standard extends ModelePDFProduct && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax { $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc); - $localtax1_type = $localtaxtmp_array[0]; - $localtax2_type = $localtaxtmp_array[2]; + $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : ''; + $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : ''; } // retrieve global local tax diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index a889dec7815..3b09d639bf0 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -626,8 +626,8 @@ class pdf_azur extends ModelePDFPropales && (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax { $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc); - $localtax1_type = $localtaxtmp_array[0]; - $localtax2_type = $localtaxtmp_array[2]; + $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : ''; + $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : ''; } // retrieve global local tax diff --git a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php index 119932949b2..80433eb2201 100644 --- a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php @@ -773,8 +773,8 @@ class pdf_cyan extends ModelePDFPropales && (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax { $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc); - $localtax1_type = $localtaxtmp_array[0]; - $localtax2_type = $localtaxtmp_array[2]; + $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : ''; + $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : ''; } // retrieve global local tax diff --git a/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php b/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php index 3a4bc56f64a..22bc80e161d 100644 --- a/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php +++ b/htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php @@ -688,8 +688,8 @@ class pdf_cornas extends ModelePDFSuppliersOrders && (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax { $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $mysoc, $object->thirdparty); - $localtax1_type = $localtaxtmp_array[0]; - $localtax2_type = $localtaxtmp_array[2]; + $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : ''; + $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : ''; } // retrieve global local tax diff --git a/htdocs/core/modules/supplier_order/doc/pdf_muscadet.modules.php b/htdocs/core/modules/supplier_order/doc/pdf_muscadet.modules.php index c8edef0679c..b48cb60df45 100644 --- a/htdocs/core/modules/supplier_order/doc/pdf_muscadet.modules.php +++ b/htdocs/core/modules/supplier_order/doc/pdf_muscadet.modules.php @@ -570,8 +570,8 @@ class pdf_muscadet extends ModelePDFSuppliersOrders && (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax { $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $mysoc, $object->thirdparty); - $localtax1_type = $localtaxtmp_array[0]; - $localtax2_type = $localtaxtmp_array[2]; + $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : ''; + $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : ''; } // retrieve global local tax diff --git a/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php b/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php index 27cfd949ca6..d8307226e41 100644 --- a/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php +++ b/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php @@ -582,8 +582,8 @@ class pdf_aurore extends ModelePDFSupplierProposal if ((!isset($localtax1_type) || $localtax1_type == '' || !isset($localtax2_type) || $localtax2_type == '') // if tax type not defined && (!empty($localtax1_rate) || !empty($localtax2_rate))) { // and there is local tax $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc); - $localtax1_type = $localtaxtmp_array[0]; - $localtax2_type = $localtaxtmp_array[2]; + $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : ''; + $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : ''; } // retrieve global local tax diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php b/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php index fbab4d53b0f..cb9e4f0a6dd 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php @@ -686,8 +686,8 @@ class pdf_standard_myobject extends ModelePDFMyObject && (!empty($localtax1_rate) || !empty($localtax2_rate))) // and there is local tax { $localtaxtmp_array = getLocalTaxesFromRate($vatrate, 0, $object->thirdparty, $mysoc); - $localtax1_type = $localtaxtmp_array[0]; - $localtax2_type = $localtaxtmp_array[2]; + $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : ''; + $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : ''; } // retrieve global local tax diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index 022c5a13354..8a74b14095b 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -499,7 +499,15 @@ class SupplierProposal extends CommonObject // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva. $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc); - $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. + + // Clean vat code + $reg = array(); + $vat_src_code = ''; + if (preg_match('/\((.*)\)/', $txtva, $reg)) + { + $vat_src_code = $reg[1]; + $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. + } if (!empty($conf->multicurrency->enabled) && $pu_ht_devise > 0) { $pu = 0; @@ -544,6 +552,8 @@ class SupplierProposal extends CommonObject $this->line->label = $label; $this->line->desc = $desc; $this->line->qty = $qty; + + $this->line->vat_src_code = $vat_src_code; $this->line->tva_tx = $txtva; $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0); $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0); @@ -2736,6 +2746,8 @@ class SupplierProposalLine extends CommonObjectLine public $qty; public $tva_tx; + public $vat_src_code; + public $subprice; public $remise_percent;