From 93477c102f725a449cc912dbc8b0ba168c9926e4 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 26 Jun 2017 15:44:04 +0200 Subject: [PATCH 01/20] FIX delete linked element on facture rec --- htdocs/compta/facture/class/facture-rec.class.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index ef23a30b878..e39a4a7b994 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -475,7 +475,13 @@ class FactureRec extends CommonInvoice { $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_rec WHERE rowid = ".$rowid; dol_syslog($sql); - if (! $this->db->query($sql)) + if ($this->db->query($sql)) + { + // Delete linked object + $res = $this->deleteObjectLinked(); + if ($res < 0) $error=-3; + } + else { $this->error=$this->db->lasterror(); $error=-1; From 3664956b8c98859e0f97b33cf219509889c208a4 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Wed, 28 Jun 2017 00:31:33 +0200 Subject: [PATCH 02/20] Update pdf_azur.modules.php --- htdocs/core/modules/propale/doc/pdf_azur.modules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index 972a75eecc8..3eb284ec7fc 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -120,7 +120,7 @@ class pdf_azur extends ModelePDFPropales } $this->posxdiscount=162; $this->postotalht=174; - if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxtva=$this->posxup; + if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup; $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images if ($this->page_largeur < 210) // To work with US executive format { From cef5c0b37514c38ed370d996abf541d1f5d2438d Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Wed, 28 Jun 2017 00:38:24 +0200 Subject: [PATCH 03/20] Fix column position in PDF when VAT is hidden --- htdocs/core/modules/commande/doc/pdf_einstein.modules.php | 2 +- htdocs/core/modules/facture/doc/pdf_crabe.modules.php | 2 +- .../core/modules/supplier_proposal/doc/pdf_aurore.modules.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php index d31ed238965..54c1f546903 100644 --- a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php @@ -122,7 +122,7 @@ class pdf_einstein extends ModelePDFCommandes } $this->posxdiscount=162; $this->postotalht=174; - if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxtva=$this->posxup; + if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup; $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images if ($this->page_largeur < 210) // To work with US executive format { diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index c1682c78087..7fb55b398bc 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -132,7 +132,7 @@ class pdf_crabe extends ModelePDFFactures $this->posxdiscount=162; $this->posxprogress=126; // Only displayed for situation invoices $this->postotalht=174; - if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxtva=$this->posxup; + if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup; $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images if ($this->page_largeur < 210) // To work with US executive format { 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 c546aad91ad..10ea968c041 100644 --- a/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php +++ b/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php @@ -108,7 +108,7 @@ class pdf_aurore extends ModelePDFSupplierProposal $this->posxqty=145; $this->posxdiscount=162; $this->postotalht=174; - if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxtva=$this->posxup; + if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT) || ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT_COLUMN)) $this->posxtva=$this->posxup; $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images if ($this->page_largeur < 210) // To work with US executive format { From 58328d36b3e40534a78c0a6d36f28b6a8cf21aa9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 29 Jun 2017 15:32:36 +0200 Subject: [PATCH 04/20] To provide solution to get thirdparty when name is not unique. --- htdocs/societe/class/societe.class.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 097537ac71a..1423b53b9da 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1004,21 +1004,22 @@ class Societe extends CommonObject * @param int $rowid Id of third party to load * @param string $ref Reference of third party, name (Warning, this can return several records) * @param string $ref_ext External reference of third party (Warning, this information is a free field not provided by Dolibarr) - * @param string $ref_int Internal reference of third party + * @param string $ref_int Internal reference of third party (not used by dolibarr) * @param string $idprof1 Prof id 1 of third party (Warning, this can return several records) * @param string $idprof2 Prof id 2 of third party (Warning, this can return several records) * @param string $idprof3 Prof id 3 of third party (Warning, this can return several records) * @param string $idprof4 Prof id 4 of third party (Warning, this can return several records) * @param string $idprof5 Prof id 5 of third party (Warning, this can return several records) * @param string $idprof6 Prof id 6 of third party (Warning, this can return several records) + * @param string $email Email (Warning, this can return several records) * @return int >0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found. */ - function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2='',$idprof3='',$idprof4='',$idprof5='',$idprof6='') + function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2='',$idprof3='',$idprof4='',$idprof5='',$idprof6='', $email='') { global $langs; global $conf; - if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6)) return -1; + if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) return -1; $sql = 'SELECT s.rowid, s.nom as name, s.name_alias, s.entity, s.ref_ext, s.ref_int, s.address, s.datec as date_creation, s.prefix_comm'; $sql .= ', s.status'; @@ -1062,6 +1063,7 @@ class Societe extends CommonObject else if ($idprof4) $sql .= " WHERE s.idprof4 = '".$this->db->escape($idprof4)."' AND s.entity IN (".getEntity($this->element, 1).")"; else if ($idprof5) $sql .= " WHERE s.idprof5 = '".$this->db->escape($idprof5)."' AND s.entity IN (".getEntity($this->element, 1).")"; else if ($idprof6) $sql .= " WHERE s.idprof6 = '".$this->db->escape($idprof6)."' AND s.entity IN (".getEntity($this->element, 1).")"; + else if ($email) $sql .= " WHERE email = '".$this->db->escape($email)."' AND s.entity IN (".getEntity($this->element, 1).")"; $resql=$this->db->query($sql); dol_syslog(get_class($this)."::fetch ".$sql); @@ -1886,7 +1888,7 @@ class Societe extends CommonObject $label.= '' . $langs->trans("ShowMargin") . ''; $linkstart = ''; @@ -1949,7 +1951,7 @@ class Societe extends CommonObject $linkstart=''; $linkend=''; } - + if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), 'company', ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend); if ($withpicto && $withpicto != 2) $result.=' '; if ($withpicto != 2) $result.=$linkstart.($maxlen?dol_trunc($name,$maxlen):$name).$linkend; @@ -3449,9 +3451,9 @@ class Societe extends CommonObject return 0; } } - + $modelpath = "core/modules/societe/doc/"; - + $result=$this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); } @@ -3472,7 +3474,7 @@ class Societe extends CommonObject public function setCategories($categories, $type) { require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; - + // Decode type if ($type == 'customer') { $type_id = Categorie::TYPE_CUSTOMER; From 2f8c0bb555a089fe5b36065a0ca830709ecacb58 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 29 Jun 2017 15:36:39 +0200 Subject: [PATCH 05/20] Revert "To provide solution to get thirdparty when name is not unique." This reverts commit 58328d36b3e40534a78c0a6d36f28b6a8cf21aa9. --- htdocs/societe/class/societe.class.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 1423b53b9da..097537ac71a 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1004,22 +1004,21 @@ class Societe extends CommonObject * @param int $rowid Id of third party to load * @param string $ref Reference of third party, name (Warning, this can return several records) * @param string $ref_ext External reference of third party (Warning, this information is a free field not provided by Dolibarr) - * @param string $ref_int Internal reference of third party (not used by dolibarr) + * @param string $ref_int Internal reference of third party * @param string $idprof1 Prof id 1 of third party (Warning, this can return several records) * @param string $idprof2 Prof id 2 of third party (Warning, this can return several records) * @param string $idprof3 Prof id 3 of third party (Warning, this can return several records) * @param string $idprof4 Prof id 4 of third party (Warning, this can return several records) * @param string $idprof5 Prof id 5 of third party (Warning, this can return several records) * @param string $idprof6 Prof id 6 of third party (Warning, this can return several records) - * @param string $email Email (Warning, this can return several records) * @return int >0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found. */ - function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2='',$idprof3='',$idprof4='',$idprof5='',$idprof6='', $email='') + function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2='',$idprof3='',$idprof4='',$idprof5='',$idprof6='') { global $langs; global $conf; - if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) return -1; + if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6)) return -1; $sql = 'SELECT s.rowid, s.nom as name, s.name_alias, s.entity, s.ref_ext, s.ref_int, s.address, s.datec as date_creation, s.prefix_comm'; $sql .= ', s.status'; @@ -1063,7 +1062,6 @@ class Societe extends CommonObject else if ($idprof4) $sql .= " WHERE s.idprof4 = '".$this->db->escape($idprof4)."' AND s.entity IN (".getEntity($this->element, 1).")"; else if ($idprof5) $sql .= " WHERE s.idprof5 = '".$this->db->escape($idprof5)."' AND s.entity IN (".getEntity($this->element, 1).")"; else if ($idprof6) $sql .= " WHERE s.idprof6 = '".$this->db->escape($idprof6)."' AND s.entity IN (".getEntity($this->element, 1).")"; - else if ($email) $sql .= " WHERE email = '".$this->db->escape($email)."' AND s.entity IN (".getEntity($this->element, 1).")"; $resql=$this->db->query($sql); dol_syslog(get_class($this)."::fetch ".$sql); @@ -1888,7 +1886,7 @@ class Societe extends CommonObject $label.= '' . $langs->trans("ShowMargin") . ''; $linkstart = ''; @@ -1951,7 +1949,7 @@ class Societe extends CommonObject $linkstart=''; $linkend=''; } - + if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), 'company', ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend); if ($withpicto && $withpicto != 2) $result.=' '; if ($withpicto != 2) $result.=$linkstart.($maxlen?dol_trunc($name,$maxlen):$name).$linkend; @@ -3451,9 +3449,9 @@ class Societe extends CommonObject return 0; } } - + $modelpath = "core/modules/societe/doc/"; - + $result=$this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); } @@ -3474,7 +3472,7 @@ class Societe extends CommonObject public function setCategories($categories, $type) { require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; - + // Decode type if ($type == 'customer') { $type_id = Categorie::TYPE_CUSTOMER; From ea504a0516b2f521408270423803f6ef9d0992f0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 30 Jun 2017 11:08:40 +0200 Subject: [PATCH 06/20] FIX We should be able to insert data with value '0' into const --- htdocs/core/modules/DolibarrModules.class.php | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index 8e526baa241..f0dce5f37a1 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -50,13 +50,13 @@ class DolibarrModules // Can not be abstract, because we need to insta * @since 4.0.0 */ public $editor_name; - + /** * @var string URL of module at publisher site * @since 4.0.0 */ public $editor_url; - + /** * @var string Family * @see familyinfo @@ -80,13 +80,13 @@ class DolibarrModules // Can not be abstract, because we need to insta * */ public $familyinfo; - + /** * @var int Module position * @since 3.9.0 */ public $module_position=500; - + /** * @var string Module name * @@ -214,7 +214,7 @@ class DolibarrModules // Can not be abstract, because we need to insta * HTML content supported. */ public $descriptionlong; - + /** * @var string[] Module language files */ @@ -254,7 +254,7 @@ class DolibarrModules // Can not be abstract, because we need to insta * @var bool Module is enabled globally (Multicompany support) */ public $core_enabled; - + /** * @var string Relative path to module style sheet * @deprecated @@ -573,9 +573,9 @@ class DolibarrModules // Can not be abstract, because we need to insta { global $langs; $langs->load("admin"); - + if (empty($this->descriptionlong)) return ''; - + // If module description translation does not exist using its unique id, we can use its name to find translation if (is_array($this->langfiles)) { @@ -586,7 +586,7 @@ class DolibarrModules // Can not be abstract, because we need to insta } return $langs->trans($this->descriptionlong); } - + /** * Gives the publisher name * @@ -596,7 +596,7 @@ class DolibarrModules // Can not be abstract, because we need to insta { return $this->editor_name; } - + /** * Gives the publisher url * @@ -606,7 +606,7 @@ class DolibarrModules // Can not be abstract, because we need to insta { return $this->editor_url; } - + /** * Gives module version (translated if param $translated is on) * For 'experimental' modules, gives 'experimental' translation @@ -709,7 +709,7 @@ class DolibarrModules // Can not be abstract, because we need to insta } } - + /** * Gives the last date of activation * @@ -718,11 +718,11 @@ class DolibarrModules // Can not be abstract, because we need to insta function getLastActivationDate() { global $conf; - + $sql = "SELECT tms FROM ".MAIN_DB_PREFIX."const"; $sql.= " WHERE ".$this->db->decrypt('name')." = '".$this->const_name."'"; $sql.= " AND entity IN (0, ".$conf->entity.")"; - + dol_syslog(get_class($this)."::getLastActiveDate", LOG_DEBUG); $resql=$this->db->query($sql); if (! $resql) $err++; @@ -731,11 +731,11 @@ class DolibarrModules // Can not be abstract, because we need to insta $obj=$this->db->fetch_object($resql); if ($obj) return $this->db->jdate($obj->tms); } - + return ''; } - - + + /** * Insert constants for module activation * @@ -836,7 +836,7 @@ class DolibarrModules // Can not be abstract, because we need to insta $files[] = $file; } sort($files); - foreach ($files as $file) + foreach ($files as $file) { if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'llx_' && substr($file,0,4) != 'data') { @@ -854,7 +854,7 @@ class DolibarrModules // Can not be abstract, because we need to insta $files[] = $file; } sort($files); - foreach ($files as $file) + foreach ($files as $file) { if (preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'llx_' && substr($file,0,4) != 'data') { @@ -872,7 +872,7 @@ class DolibarrModules // Can not be abstract, because we need to insta $files[] = $file; } sort($files); - foreach ($files as $file) + foreach ($files as $file) { if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,4) == 'data') { @@ -890,7 +890,7 @@ class DolibarrModules // Can not be abstract, because we need to insta $files[] = $file; } sort($files); - foreach ($files as $file) + foreach ($files as $file) { if (preg_match('/\.sql$/i',$file) && ! preg_match('/\.key\.sql$/i',$file) && substr($file,0,6) == 'update') { @@ -1030,19 +1030,19 @@ class DolibarrModules // Can not be abstract, because we need to insta //$titre = $this->boxes[$key][0]; $file = $this->boxes[$key]['file']; //$note = $this->boxes[$key][2]; - + // TODO If the box is also included by another module and the other module is still on, we should not remove it. // For the moment, we manage this with hard coded exception //print "Remove box ".$file.'
'; if ($file == 'box_graph_product_distribution.php') { - if (! empty($conf->produit->enabled) || ! empty($conf->service->enabled)) + if (! empty($conf->produit->enabled) || ! empty($conf->service->enabled)) { dol_syslog("We discard disabling of module ".$file." because another module still active require it."); continue; } } - + if (empty($file)) $file = isset($this->boxes[$key][1])?$this->boxes[$key][1]:''; // For backward compatibility if ($this->db->type == 'sqlite3') { @@ -1117,7 +1117,7 @@ class DolibarrModules // Can not be abstract, because we need to insta $status = isset($this->cronjobs[$key]['status'])?$this->cronjobs[$key]['status']:''; $priority = isset($this->cronjobs[$key]['priority'])?$this->cronjobs[$key]['priority']:''; $test = isset($this->cronjobs[$key]['test'])?$this->cronjobs[$key]['test']:''; // Line must be visible - + // Search if boxes def already present $sql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."cronjob"; $sql.= " WHERE module_name = '".$this->db->escape($this->rights_class)."'"; @@ -1329,11 +1329,11 @@ class DolibarrModules // Can not be abstract, because we need to insta // Clean if (empty($visible)) $visible='0'; - if (empty($val)) $val=''; + if (empty($val) && $val != '0') $val=''; $sql = "SELECT count(*)"; $sql.= " FROM ".MAIN_DB_PREFIX."const"; - $sql.= " WHERE ".$this->db->decrypt('name')." = '".$name."'"; + $sql.= " WHERE ".$this->db->decrypt('name')." = '".$this->db->escape($name)."'"; $sql.= " AND entity = ".$entity; $result=$this->db->query($sql); @@ -1347,7 +1347,7 @@ class DolibarrModules // Can not be abstract, because we need to insta $sql.= " VALUES ("; $sql.= $this->db->encrypt($name,1); $sql.= ",'".$type."'"; - $sql.= ",".($val?$this->db->encrypt($val,1):"''"); + $sql.= ",".(($val != '')?$this->db->encrypt($val,1):"''"); $sql.= ",".($note?"'".$this->db->escape($note)."'":"null"); $sql.= ",'".$visible."'"; $sql.= ",".$entity; @@ -1552,7 +1552,7 @@ class DolibarrModules // Can not be abstract, because we need to insta /** * Removes access rights - * + * * @return int Error count (0 if OK) */ function delete_permissions() @@ -1585,7 +1585,7 @@ class DolibarrModules // Can not be abstract, because we need to insta global $user; if (! is_array($this->menu) || empty($this->menu)) return 0; - + require_once DOL_DOCUMENT_ROOT . '/core/class/menubase.class.php'; $err=0; From d55213286e805102493e647bcbcb6090b89f85c8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 30 Jun 2017 11:40:26 +0200 Subject: [PATCH 07/20] Fix missing parameter --- htdocs/commande/class/commande.class.php | 10 +-- .../class/fournisseur.commande.class.php | 60 +++++++------- .../fourn/class/fournisseur.facture.class.php | 2 +- .../class/supplier_proposal.class.php | 78 +++++++++---------- 4 files changed, 75 insertions(+), 75 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 65769ea795f..40e258a8e82 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1412,7 +1412,7 @@ class Commande extends CommonOrder if (! empty($fk_parent_line)) $this->line_order(true,'DESC'); // Mise a jour informations denormalisees au niveau de la commande meme - $result=$this->update_price(1,'auto'); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. + $result=$this->update_price(1,'auto',0,$mysoc); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. if ($result > 0) { $this->db->commit(); @@ -1469,7 +1469,7 @@ class Commande extends CommonOrder $tva_npr = get_default_npr($mysoc,$this->thirdparty,$prod->id); if (empty($tva_tx)) $tva_npr=0; $vat_src_code = ''; // May be defined into tva_tx - + $localtax1_tx=get_localtax($tva_tx,1,$this->thirdparty,$mysoc,$tva_npr); $localtax2_tx=get_localtax($tva_tx,2,$this->thirdparty,$mysoc,$tva_npr); @@ -1799,7 +1799,7 @@ class Commande extends CommonOrder $line->product_type = $objp->product_type; $line->qty = $objp->qty; - $line->vat_src_code = $objp->vat_src_code; + $line->vat_src_code = $objp->vat_src_code; $line->tva_tx = $objp->tva_tx; $line->localtax1_tx = $objp->localtax1_tx; $line->localtax2_tx = $objp->localtax2_tx; @@ -3389,7 +3389,7 @@ class Commande extends CommonOrder global $conf, $langs, $user; if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips - + $result=''; if (! empty($conf->expedition->enabled) && ($option == 1 || $option == 2)) $url = DOL_URL_ROOT.'/expedition/shipment.php?id='.$this->id; @@ -3426,7 +3426,7 @@ class Commande extends CommonOrder $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose.=' class="classfortooltip"'; } - + $linkstart = '
'; $linkend=''; diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 245947932a3..e9da56d2093 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -45,7 +45,7 @@ class CommandeFournisseur extends CommonOrder public $fk_element = 'fk_commande'; protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe public $picto='order'; - + /** * {@inheritdoc} */ @@ -132,9 +132,9 @@ class CommandeFournisseur extends CommonOrder * Draft status */ const STATUS_DRAFT = 0; - - - + + + /** * Constructor * @@ -318,7 +318,7 @@ class CommandeFournisseur extends CommonOrder $line->subprice = $objp->subprice; $line->pu_ht = $objp->subprice; $line->remise_percent = $objp->remise_percent; - + $line->vat_src_code = $objp->vat_src_code; $line->total_ht = $objp->total_ht; $line->total_tva = $objp->total_tva; @@ -615,7 +615,7 @@ class CommandeFournisseur extends CommonOrder $picto='order'; $url = DOL_URL_ROOT.'/fourn/commande/card.php?id='.$this->id; - + $linkclose=''; if (empty($notooltip)) { @@ -627,7 +627,7 @@ class CommandeFournisseur extends CommonOrder $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose.=' class="classfortooltip"'; } - + $linkstart = ''; $linkend=''; @@ -1378,7 +1378,7 @@ class CommandeFournisseur extends CommonOrder } $desc=trim($desc); $ref_supplier=''; // Ref of supplier price when we add line - + // Check parameters if ($qty < 1 && ! $fk_product) { @@ -1402,7 +1402,7 @@ class CommandeFournisseur extends CommonOrder { $product_type = $prod->type; $label = $prod->label; - + // We use 'none' instead of $fourn_ref, because fourn_ref may not exists anymore. So we will take the first supplier price ok. // If we want a dedicated supplier price, we must provide $fk_prod_fourn_price. $result=$prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product, 'none', $this->fk_soc); // Search on couple $fk_prod_fourn_price/$qty first, then on triplet $qty/$fk_product/$fourn_ref/$this->fk_soc @@ -1417,7 +1417,7 @@ class CommandeFournisseur extends CommonOrder $this->error = "Ref " . $prod->ref . " " . $langs->trans("ErrorQtyTooLowForThisSupplier"); $this->db->rollback(); dol_syslog(get_class($this)."::addline we did not found supplier price, so we can't guess unit price"); - //$pu = $prod->fourn_pu; // We do not overwrite unit price + //$pu = $prod->fourn_pu; // We do not overwrite unit price //$ref = $prod->ref_fourn; // We do not overwrite ref supplier price return -1; } @@ -1463,7 +1463,7 @@ class CommandeFournisseur extends CommonOrder $vat_src_code = $reg[1]; $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. } - + $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx,$pu_ht_devise); $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; @@ -1482,7 +1482,7 @@ class CommandeFournisseur extends CommonOrder $localtax2_type=$localtaxes_type[2]; $subprice = price2num($pu,'MU'); - + $rangmax = $this->line_max(); $rang = $rangmax + 1; @@ -1508,7 +1508,7 @@ class CommandeFournisseur extends CommonOrder $this->line->subprice=$pu_ht; $this->line->rang=$this->rang; $this->line->info_bits=$info_bits; - + $this->line->vat_src_code=$vat_src_code; $this->line->total_ht=$total_ht; $this->line->total_tva=$total_tva; @@ -1548,7 +1548,7 @@ class CommandeFournisseur extends CommonOrder if (! empty($fk_parent_line)) $this->line_order(true,'DESC'); // Mise a jour informations denormalisees au niveau de la commande meme - $result=$this->update_price(1,'auto'); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. + $result=$this->update_price(1,'auto',0,$this->thirdparty); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. if ($result > 0) { $this->db->commit(); @@ -1993,7 +1993,7 @@ class CommandeFournisseur extends CommonOrder $old_statut = $this->statut; $this->statut = $statut; $this->actionmsg2 = $comment; - + // Call trigger $result=$this->call_trigger('ORDER_SUPPLIER_RECEIVE',$user); if ($result < 0) $error++; @@ -2326,7 +2326,7 @@ class CommandeFournisseur extends CommonOrder $vat_src_code = $reg[1]; $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. } - + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise); $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; @@ -2809,7 +2809,7 @@ class CommandeFournisseur extends CommonOrder return $text; } - + /** * Calc status regarding dispatch stock * @@ -2818,7 +2818,7 @@ class CommandeFournisseur extends CommonOrder * @param string $comment Comment * @return int <0 if KO, 0 if not applicable, >0 if OK */ - public function calcAndSetStatusDispatch(User $user, $closeopenorder=1, $comment='') + public function calcAndSetStatusDispatch(User $user, $closeopenorder=1, $comment='') { global $conf, $langs; @@ -2835,14 +2835,14 @@ class CommandeFournisseur extends CommonOrder $filter['t.status']=1; } $ret=$supplierorderdispatch->fetchAll('','',0,0,$filter); - if ($ret<0) + if ($ret<0) { $this->error=$supplierorderdispatch->error; $this->errors=$supplierorderdispatch->errors; return $ret; - } - else + } + else { - if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines)>0) + if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines)>0) { //Build array with quantity deliverd by product foreach($supplierorderdispatch->lines as $line) { @@ -2851,12 +2851,12 @@ class CommandeFournisseur extends CommonOrder foreach($this->lines as $line) { $qtywished[$line->fk_product]+=$line->qty; } - + $date_liv = dol_now(); - + //Compare array $diff_array=array_diff_assoc($qtydelivered,$qtywished); - + if (count($diff_array)==0) //No diff => mean everythings is received { if ($closeopenorder) @@ -2878,8 +2878,8 @@ class CommandeFournisseur extends CommonOrder } return 4; } - } - else + } + else { //Diff => received partially $ret = $this->Livraison($user, $date_liv, 'par', $comment); // GETPOST("type") is 'tot', 'par', 'nev', 'can' @@ -3004,12 +3004,12 @@ class CommandeFournisseurLigne extends CommonOrderLine $this->date_start = $this->db->jdate($objp->date_start); $this->date_end = $this->db->jdate($objp->date_end); $this->fk_unit = $objp->fk_unit; - + $this->multicurrency_subprice = $objp->multicurrency_subprice; $this->multicurrency_total_ht = $objp->multicurrency_total_ht; $this->multicurrency_total_tva = $objp->multicurrency_total_tva; $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc; - + $this->db->free($result); return 1; } @@ -3198,7 +3198,7 @@ class CommandeFournisseurLigne extends CommonOrderLine $sql.= ", subprice='".price2num($this->subprice)."'"; //$sql.= ",remise='".price2num($remise)."'"; $sql.= ", remise_percent='".price2num($this->remise_percent)."'"; - + $sql.= ", vat_src_code = '".(empty($this->vat_src_code)?'':$this->vat_src_code)."'"; $sql.= ", tva_tx='".price2num($this->tva_tx)."'"; $sql.= ", localtax1_tx='".price2num($this->total_localtax1)."'"; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 38d0fcd5bfb..f4cf4762a91 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1422,7 +1422,7 @@ class FactureFournisseur extends CommonInvoice if (! empty($fk_parent_line)) $this->line_order(true,'DESC'); // Mise a jour informations denormalisees au niveau de la facture meme - $result=$this->update_price(1,'auto',0,$mysoc); // The addline method is designed to add line from user input so total calculation with update_price must be done using 'auto' mode. + $result=$this->update_price(1,'auto',0,$this->thirdparty); // The addline method is designed to add line from user input so total calculation with update_price must be done using 'auto' mode. if ($result > 0) { $this->db->commit(); diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index 23c8257a4f5..1ff988e19fd 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -50,7 +50,7 @@ class SupplierProposal extends CommonObject public $fk_element='fk_supplier_proposal'; protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe public $picto='propal'; - + /** * {@inheritdoc} */ @@ -140,7 +140,7 @@ class SupplierProposal extends CommonObject var $multicurrency_total_ht; var $multicurrency_total_tva; var $multicurrency_total_ttc; - + /** * Draft status */ @@ -160,10 +160,10 @@ class SupplierProposal extends CommonObject /** * Billed or processed quote */ - const STATUS_BILLED = 4; - - - + const STATUS_BILLED = 4; + + + /** * Constructor * @@ -407,7 +407,7 @@ class SupplierProposal extends CommonObject $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc); $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. - + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx); $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; @@ -419,7 +419,7 @@ class SupplierProposal extends CommonObject $multicurrency_total_ht = $tabprice[16]; $multicurrency_total_tva = $tabprice[17]; $multicurrency_total_ttc = $tabprice[18]; - + // Rang to use $rangtouse = $rang; if ($rangtouse == -1) @@ -487,7 +487,7 @@ class SupplierProposal extends CommonObject $this->line->multicurrency_total_ht = $multicurrency_total_ht; $this->line->multicurrency_total_tva = $multicurrency_total_tva; $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; - + // Mise en option de la ligne if (empty($qty) && empty($special_code)) $this->line->special_code=3; @@ -506,7 +506,7 @@ class SupplierProposal extends CommonObject if (! empty($fk_parent_line)) $this->line_order(true,'DESC'); // Mise a jour informations denormalisees au niveau de la propale meme - $result=$this->update_price(1,'auto'); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. + $result=$this->update_price(1,'auto',0,$this->thirdparty); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. if ($result > 0) { $this->db->commit(); @@ -583,7 +583,7 @@ class SupplierProposal extends CommonObject $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc); $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. - + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx); $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; @@ -595,7 +595,7 @@ class SupplierProposal extends CommonObject $multicurrency_total_ht = $tabprice[16]; $multicurrency_total_tva = $tabprice[17]; $multicurrency_total_ttc = $tabprice[18]; - + // Anciens indicateurs: $price, $remise (a ne plus utiliser) $price = $pu; if ($remise_percent > 0) @@ -662,7 +662,7 @@ class SupplierProposal extends CommonObject if (is_array($array_option) && count($array_option)>0) { $this->line->array_options=$array_option; } - + // Multicurrency $this->line->multicurrency_subprice = price2num($pu * $this->multicurrency_tx); $this->line->multicurrency_total_ht = $multicurrency_total_ht; @@ -1181,7 +1181,7 @@ class SupplierProposal extends CommonObject $this->multicurrency_total_ht = $obj->multicurrency_total_ht; $this->multicurrency_total_tva = $obj->multicurrency_total_tva; $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc; - + if ($obj->fk_statut == 0) { $this->brouillon = 1; @@ -1272,7 +1272,7 @@ class SupplierProposal extends CommonObject $line->multicurrency_total_tva = $objp->multicurrency_total_tva; $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc; $line->fk_unit = $objp->fk_unit; - + $this->lines[$i] = $line; $i++; @@ -1654,7 +1654,7 @@ class SupplierProposal extends CommonObject { $trigger_name='SUPPLIER_PROPOSAL_CLASSIFY_BILLED'; } - + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { // Define output language @@ -1705,7 +1705,7 @@ class SupplierProposal extends CommonObject $productsupplier = new ProductFournisseur($this->db); dol_syslog(get_class($this)."::updateOrCreatePriceFournisseur", LOG_DEBUG); - foreach ($this->lines as $product) + foreach ($this->lines as $product) { if ($product->subprice <= 0) continue; @@ -1722,7 +1722,7 @@ class SupplierProposal extends CommonObject $this->createPriceFournisseur($product, $user); } } - + return 1; } @@ -2150,7 +2150,7 @@ class SupplierProposal extends CommonObject $response->label = $label; $response->url = DOL_URL_ROOT.'/supplier_proposal/list.php?viewstatut='.$statut; $response->img = img_object($langs->trans("SupplierProposals"),"propal"); - + // This assignment in condition is not a bug. It allows walking the results. while ($obj=$this->db->fetch_object($resql)) { @@ -2188,7 +2188,7 @@ class SupplierProposal extends CommonObject global $user,$langs,$conf; // Load array of products prodids - $num_prods = 0; + $num_prods = 0; $prodids = array(); $sql = "SELECT rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."product"; @@ -2251,7 +2251,7 @@ class SupplierProposal extends CommonObject $prodid = mt_rand(1, $num_prods); $line->fk_product=$prodids[$prodid]; } - + $this->lines[$xnbp]=$line; $this->total_ht += $line->total_ht; @@ -2376,10 +2376,10 @@ class SupplierProposal extends CommonObject global $langs, $conf, $user; if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips - + $url=''; $result=''; - + $label=''.$langs->trans("ShowSupplierProposal").''; if (! empty($this->ref)) $label.= '
'.$langs->trans('Ref').': '.$this->ref; @@ -2397,7 +2397,7 @@ class SupplierProposal extends CommonObject if ($option == 'document') { $url = DOL_URL_ROOT.'/supplier_proposal/document.php?id='.$this->id. $get_params; } - + $linkclose=''; if (empty($notooltip) && $user->rights->propal->lire) { @@ -2409,7 +2409,7 @@ class SupplierProposal extends CommonObject $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose.=' class="classfortooltip"'; } - + $linkstart = ''; $linkend=''; @@ -2433,7 +2433,7 @@ class SupplierProposal extends CommonObject function getLinesArray() { // For other object, here we call fetch_lines. But fetch_lines does not exists on supplier proposal - + $sql = 'SELECT pt.rowid, pt.label as custom_label, pt.description, pt.fk_product, pt.fk_remise_except,'; $sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,'; $sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc, pt.fk_product_fournisseur_price as fk_fournprice, pt.buy_price_ht as pa_ht, pt.special_code, pt.localtax1_tx, pt.localtax2_tx,'; @@ -2487,7 +2487,7 @@ class SupplierProposal extends CommonObject $this->lines[$i]->rang = $obj->rang; $this->lines[$i]->ref_fourn = $obj->ref_produit_fourn; - + // Multicurrency $this->lines[$i]->fk_multicurrency = $obj->fk_multicurrency; $this->lines[$i]->multicurrency_code = $obj->multicurrency_code; @@ -2544,7 +2544,7 @@ class SupplierProposal extends CommonObject return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); } - + /** * Function used to replace a thirdparty id with another one. * @@ -2558,10 +2558,10 @@ class SupplierProposal extends CommonObject $tables = array( 'supplier_proposal' ); - + return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); } - + } @@ -2672,7 +2672,7 @@ class SupplierProposalLine extends CommonObjectLine var $skip_update_total; // Skip update price total for special lines var $ref_fourn; - + // Multicurrency var $fk_multicurrency; var $multicurrency_code; @@ -2753,7 +2753,7 @@ class SupplierProposalLine extends CommonObjectLine $this->product_desc = $objp->product_desc; $this->ref_fourn = $objp->ref_produit_forun; - + // Multicurrency $this->fk_multicurrency = $objp->fk_multicurrency; $this->multicurrency_code = $objp->multicurrency_code; @@ -2801,11 +2801,11 @@ class SupplierProposalLine extends CommonObjectLine if (empty($this->fk_parent_line)) $this->fk_parent_line=0; if (empty($this->fk_fournprice)) $this->fk_fournprice=0; if (empty($this->fk_unit)) $this->fk_unit=0; - + if (empty($this->pa_ht)) $this->pa_ht=0; // if buy price not defined, define buyprice as configured in margin admin - if ($this->pa_ht == 0) + if ($this->pa_ht == 0) { if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { @@ -2872,7 +2872,7 @@ class SupplierProposalLine extends CommonObjectLine { $this->rowid=$this->db->last_insert_id(MAIN_DB_PREFIX.'supplier_proposaldet'); $this->id=$this->rowid; - + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used { $result=$this->insertExtraFields(); @@ -2985,11 +2985,11 @@ class SupplierProposalLine extends CommonObjectLine if (empty($this->fk_parent_line)) $this->fk_parent_line=0; if (empty($this->fk_fournprice)) $this->fk_fournprice=0; if (empty($this->fk_unit)) $this->fk_unit=0; - + if (empty($this->pa_ht)) $this->pa_ht=0; // if buy price not defined, define buyprice as configured in margin admin - if ($this->pa_ht == 0) + if ($this->pa_ht == 0) { if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { @@ -3033,14 +3033,14 @@ class SupplierProposalLine extends CommonObjectLine $sql.= " , fk_parent_line=".($this->fk_parent_line>0?$this->fk_parent_line:"null"); if (! empty($this->rang)) $sql.= ", rang=".$this->rang; $sql.= " , ref_fourn=".(! empty($this->ref_fourn)?"'".$this->db->escape($this->ref_fourn)."'":"null"); - + // Multicurrency $sql.= " , multicurrency_subprice=".price2num($this->multicurrency_subprice).""; $sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht).""; $sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva).""; $sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc).""; $sql.= " , fk_unit=".$this->fk_unit; - + $sql.= " WHERE rowid = ".$this->rowid; dol_syslog(get_class($this)."::update", LOG_DEBUG); From b308cfef1d2335c68442d77115c99caf7e1a8e16 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 30 Jun 2017 18:30:01 +0200 Subject: [PATCH 08/20] Fix dol_trunc --- htdocs/core/lib/functions.lib.php | 9 +++-- test/phpunit/FunctionsLibTest.php | 66 +++++++++++++++++++------------ 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index aa70c2680dd..5c3d78aa0ee 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2243,12 +2243,12 @@ function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie', * MAIN_DISABLE_TRUNC=1 can disable all truncings * * @param string $string String to truncate - * @param int $size Max string size visible. 0 for no limit. Final string size can be 1 more (if size was max+1) or 3 more (if we added ...) + * @param int $size Max string size visible (excluding ...). 0 for no limit. WARNING: Final string size can have 3 more chars (if we added ..., or if size was max+1 or max+2 or max+3 so it does not worse to replace with ...) * @param string $trunc Where to trunc: right, left, middle (size must be a 2 power), wrap * @param string $stringencoding Tell what is source string encoding * @param int $nodot Truncation do not add ... after truncation. So it's an exact truncation. * @param int $display Trunc is use to display and can be changed for small screen. TODO Remove this param (must be dealt with CSS) - * @return string Truncated string + * @return string Truncated string. WARNING: length is never higher than $size if $nodot is set, but can be 3 chars higher otherwise. */ function dol_trunc($string,$size=40,$trunc='right',$stringencoding='UTF-8',$nodot=0, $display=0) { @@ -2264,9 +2264,10 @@ function dol_trunc($string,$size=40,$trunc='right',$stringencoding='UTF-8',$nodo if ($trunc == 'right') { $newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string; - if (dol_strlen($newstring,$stringencoding) > ($size+($nodot?0:1))) + if (dol_strlen($newstring,$stringencoding) > ($size+($nodot?0:3))) // If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ... return dol_substr($newstring,0,$size,$stringencoding).($nodot?'':'...'); else + //return 'u'.$size.'-'.$newstring.'-'.dol_strlen($newstring,$stringencoding).'-'.$string; return $string; } elseif ($trunc == 'middle') @@ -2284,7 +2285,7 @@ function dol_trunc($string,$size=40,$trunc='right',$stringencoding='UTF-8',$nodo elseif ($trunc == 'left') { $newstring=dol_textishtml($string)?dol_string_nohtmltag($string,1):$string; - if (dol_strlen($newstring,$stringencoding) > ($size+1)) + if (dol_strlen($newstring,$stringencoding) > ($size+($nodot?0:3))) // If nodot is 0 and size is 1,2 or 3 chars more, we don't trunc and don't add ... return '...'.dol_substr($newstring,dol_strlen($newstring,$stringencoding) - $size,$size,$stringencoding); else return $string; diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 786970e2b3a..3345d780b7e 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -130,21 +130,21 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase /*$tmp=dol_buildpath('/google/oauth2callback.php', 0); var_dump($tmp); */ - + /*$tmp=dol_buildpath('/google/oauth2callback.php', 1); var_dump($tmp); */ - + $result=dol_buildpath('/google/oauth2callback.php', 2); print __METHOD__." result=".$result."\n"; $this->assertStringStartsWith('http', $result); - + $result=dol_buildpath('/google/oauth2callback.php', 3); print __METHOD__." result=".$result."\n"; $this->assertStringStartsWith('http', $result); } - - + + /** * testGetBrowserInfo * @@ -502,32 +502,48 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase // Default trunc (will add ... if truncation truncation or keep last char if only one char) $input="éeéeéeàa"; $after=dol_trunc($input,3); - $this->assertEquals("éeé...",$after); + $this->assertEquals("éeé...",$after,'Test A1'); $after=dol_trunc($input,2); - $this->assertEquals("ée...",$after); + $this->assertEquals("ée...",$after,'Test A2'); + $after=dol_trunc($input,1); + $this->assertEquals("é...",$after,'Test A3'); + $input="éeéeé"; + $after=dol_trunc($input,3); + $this->assertEquals("éeéeé",$after,'Test B1'); + $after=dol_trunc($input,2); + $this->assertEquals("éeéeé",$after,'Test B2'); + $after=dol_trunc($input,1); + $this->assertEquals("é...",$after,'Test B3'); + $input="éeée"; + $after=dol_trunc($input,3); + $this->assertEquals("éeée",$after,'Test C1'); + $after=dol_trunc($input,2); + $this->assertEquals("éeée",$after,'Test C2'); + $after=dol_trunc($input,1); + $this->assertEquals("éeée",$after,'Test C3'); $input="éeé"; $after=dol_trunc($input,3); - $this->assertEquals("éeé",$after); + $this->assertEquals("éeé",$after,'Test C'); $after=dol_trunc($input,2); - $this->assertEquals("éeé",$after); + $this->assertEquals("éeé",$after,'Test D'); $after=dol_trunc($input,1); - $this->assertEquals("é...",$after); + $this->assertEquals("éeé",$after,'Test E'); // Trunc with no ... $input="éeéeéeàa"; $after=dol_trunc($input,3,'right','UTF-8',1); - $this->assertEquals("éeé",$after); + $this->assertEquals("éeé",$after,'Test F'); $after=dol_trunc($input,2,'right','UTF-8',1); - $this->assertEquals("ée",$after); + $this->assertEquals("ée",$after,'Test G'); $input="éeé"; $after=dol_trunc($input,3,'right','UTF-8',1); - $this->assertEquals("éeé",$after); + $this->assertEquals("éeé",$after,'Test H'); $after=dol_trunc($input,2,'right','UTF-8',1); - $this->assertEquals("ée",$after); + $this->assertEquals("ée",$after,'Test I'); $after=dol_trunc($input,1,'right','UTF-8',1); - $this->assertEquals("é",$after); + $this->assertEquals("é",$after,'Test J'); $input="éeéeéeàa"; $after=dol_trunc($input,4,'middle'); - $this->assertEquals("ée...àa",$after); + $this->assertEquals("ée...àa",$after,'Test K'); return true; } @@ -658,7 +674,7 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase $this->assertEquals("21 jump street\nMyTown, MyState, 99999",$address); } - + /** * testDolFormatAddress * @@ -671,18 +687,18 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - + $object=new Societe($db); $object->initAsSpecimen(); - + $object->country_code='FR'; $phone=dol_print_phone('1234567890', $object->country_code); $this->assertEquals('12 34 56 78 90', $phone, 'Phone for FR 1'); - + $object->country_code='FR'; $phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, ''); $this->assertEquals('1234567890', $phone, 'Phone for FR 2'); - + $object->country_code='FR'; $phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, ' '); $this->assertEquals('12 34 56 78 90', $phone, 'Phone for FR 3'); @@ -690,10 +706,10 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase $object->country_code='CA'; $phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, ' '); $this->assertEquals('(123) 456-7890', $phone, 'Phone for CA 1'); - + } - - + + /** * testImgPicto * @@ -1043,5 +1059,5 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase return true; } - + } From a5cfd7c2e281505d33678ad823bf3ffec01fdc48 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 1 Jul 2017 16:24:33 +0200 Subject: [PATCH 09/20] FIX Error when updating thirdparty not returned --- htdocs/societe/class/societe.class.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 097537ac71a..45c183c7495 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -884,8 +884,6 @@ class Societe extends CommonObject $sql .= ', multicurrency_code = \''.$this->db->escape($this->multicurrency_code)."'"; $sql .= " WHERE rowid = '" . $id ."'"; - - dol_syslog(get_class($this)."::Update", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -980,11 +978,12 @@ class Societe extends CommonObject { // Doublon $this->error = $langs->trans("ErrorDuplicateField"); - $result = -1; + $result = -1; } else { - $result = -2; + $this->error = $this->db->lasterror(); + $result = -2; } $this->db->rollback(); return $result; @@ -1886,7 +1885,7 @@ class Societe extends CommonObject $label.= '' . $langs->trans("ShowMargin") . ''; $linkstart = ''; @@ -1949,7 +1948,7 @@ class Societe extends CommonObject $linkstart=''; $linkend=''; } - + if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), 'company', ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend); if ($withpicto && $withpicto != 2) $result.=' '; if ($withpicto != 2) $result.=$linkstart.($maxlen?dol_trunc($name,$maxlen):$name).$linkend; @@ -3449,9 +3448,9 @@ class Societe extends CommonObject return 0; } } - + $modelpath = "core/modules/societe/doc/"; - + $result=$this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); } @@ -3472,7 +3471,7 @@ class Societe extends CommonObject public function setCategories($categories, $type) { require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; - + // Decode type if ($type == 'customer') { $type_id = Categorie::TYPE_CUSTOMER; From 451e8fc02472b11acf05f0f0a7577d01e4f31150 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 4 Jul 2017 17:37:28 +0200 Subject: [PATCH 10/20] FIX Support of vat code when using price per customer --- htdocs/societe/price.php | 148 +++++++++++++++++++++++++-------------- 1 file changed, 95 insertions(+), 53 deletions(-) diff --git a/htdocs/societe/price.php b/htdocs/societe/price.php index e8dc595c6c3..c3575ae249b 100644 --- a/htdocs/societe/price.php +++ b/htdocs/societe/price.php @@ -21,10 +21,11 @@ */ /** - * \file htdocs/societe/price.php + * \file htdocs/societe/price.php * \ingroup product - * \brief Page to show product prices by customer + * \brief Page to show product prices by customer */ + require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; @@ -42,7 +43,8 @@ $langs->load("companies"); $langs->load("bills"); $action = GETPOST('action', 'alpha'); -$search_prod = GETPOST('search_prod'); +$search_prod = GETPOST('search_prod','alpha'); +$cancel = GETPOST('cancel','alpha'); // Security check $socid = GETPOST('socid', 'int')?GETPOST('socid', 'int'):GETPOST('id', 'int'); @@ -71,36 +73,72 @@ if (empty($reshook)) { $search_prod = ''; } - - if ($action == 'add_customer_price_confirm' && ! $_POST ["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer)) { - + + if ($action == 'add_customer_price_confirm' && ! $cancel && ($user->rights->produit->creer || $user->rights->service->creer)) { + $update_child_soc = GETPOST('updatechildprice'); - + // add price by customer $prodcustprice->fk_soc = $socid; $prodcustprice->fk_product = GETPOST('prodid', 'int'); $prodcustprice->price = price2num(GETPOST("price"), 'MU'); $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU'); $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha'); - $prodcustprice->tva_tx = str_replace('*', '', GETPOST("tva_tx")); - $prodcustprice->recuperableonly = (preg_match('/\*/', GETPOST("tva_tx")) ? 1 : 0); - + + $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)' + + // We must define tva_tx, npr and local taxes + $vatratecode = ''; + $tva_tx = preg_replace('/[^0-9\.].*$/', '', $tva_tx_txt); // keep remove all after the numbers and dot + $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0; + $localtax1 = 0; $localtax2 = 0; $localtax1_type = '0'; $localtax2_type = '0'; + // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes + if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) + { + // We look into database using code (we can't use get_localtax() because it depends on buyer that is not known). Same in update price. + $vatratecode=$reg[1]; + // Get record from code + $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; + $sql.= " WHERE t.fk_pays = c.rowid AND c.code = '".$mysoc->country_code."'"; + $sql.= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1"; + $sql.= " AND t.code ='".$vatratecode."'"; + $resql=$db->query($sql); + if ($resql) + { + $obj = $db->fetch_object($resql); + $npr = $obj->recuperableonly; + $localtax1 = $obj->localtax1; + $localtax2 = $obj->localtax2; + $localtax1_type = $obj->localtax1_type; + $localtax2_type = $obj->localtax2_type; + } + } + + $prodcustprice->default_vat_code = $vatratecode; + $prodcustprice->tva_tx = $tva_tx; + $prodcustprice->recuperableonly = $npr; + $prodcustprice->localtax1_tx = $localtax1; + $prodcustprice->localtax2_tx = $localtax2; + $prodcustprice->localtax1_type = $localtax1_type; + $prodcustprice->localtax2_type = $localtax2_type; + $result = $prodcustprice->create($user, 0, $update_child_soc); - + if ($result < 0) { setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors'); } else { setEventMessages($langs->trans('Save'), null, 'mesgs'); } - + $action = ''; } - + if ($action == 'delete_customer_price' && ($user->rights->produit->creer || $user->rights->service->creer)) { // Delete price by customer $prodcustprice->id = GETPOST('lineid'); $result = $prodcustprice->delete($user); - + if ($result < 0) { setEventMessages($prodcustprice->error, $prodcustprice->errors, 'mesgs'); } else { @@ -108,27 +146,27 @@ if (empty($reshook)) } $action = ''; } - + if ($action == 'update_customer_price_confirm' && ! $_POST ["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer)) { - + $prodcustprice->fetch(GETPOST('lineid', 'int')); - + $update_child_soc = GETPOST('updatechildprice'); - + // update price by customer $prodcustprice->price = price2num(GETPOST("price"), 'MU'); $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU'); $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha'); $prodcustprice->tva_tx = str_replace('*', '', GETPOST("tva_tx")); $prodcustprice->recuperableonly = (preg_match('/\*/', GETPOST("tva_tx")) ? 1 : 0); - + $result = $prodcustprice->update($user, 0, $update_child_soc); if ($result < 0) { setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors'); } else { setEventMessages($langs->trans('Save'), null, 'mesgs'); } - + $action = ''; } } @@ -154,7 +192,7 @@ dol_fiche_head($head, 'price', $langs->trans("ThirdParty"), 0, 'company'); $linkback = ''.$langs->trans("BackToList").''; dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); - + print '
'; print '
'; @@ -239,7 +277,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { // VAT print '' . $langs->trans("VATRate") . ''; - print $form->load_tva("tva_tx", $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr); + print $form->load_tva("tva_tx", $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr, '', false, 1); print ''; // Price base @@ -299,7 +337,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { print load_fiche_titre($langs->trans('PriceByCustomer')); $result = $prodcustprice->fetch(GETPOST('lineid', 'int')); - if ($result < 0) + if ($result < 0) { setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors'); } @@ -374,6 +412,8 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { print '
'; } elseif ($action == 'showlog_customer_price') { + print ''."\n"; + $filter = array ( 't.fk_product' => GETPOST('prodid', 'int'),'t.fk_soc' => $socid ); @@ -385,7 +425,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { } $result = $prodcustprice->fetch_all_log($sortorder, $sortfield, $conf->liste_limit, $offset, $filter); - if ($result < 0) + if ($result < 0) { setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors'); } @@ -440,8 +480,8 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { print ''; } print ""; - } - else + } + else { print $langs->trans('None'); } @@ -449,8 +489,8 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { print "\n" . '
' . "\n"; print ''; print "\n

\n"; - } - else + } + else { // View mode @@ -466,30 +506,32 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { print ''; } print "\n
\n"; - - + + // Count total nb of records $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords = $prodcustprice->fetch_all('', '', 0, 0, $filter); } - + $result = $prodcustprice->fetch_all($sortorder, $sortfield, $conf->liste_limit, $offset, $filter); if ($result < 0) { setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors'); } - + $option = '&search_prod=' . $search_prod . '&id=' . $object->id; - - print_barre_liste($langs->trans('PriceForEachProduct'), $page, $_SERVEUR['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords, ''); - + + print ''."\n"; + + print_barre_liste($langs->trans('PriceForEachProduct'), $page, $_SERVEUR['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords, ''); + print '
'; print ''; - + print ''; - + print ''; print ''; print ''; @@ -502,12 +544,12 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { print ''; print ''; print ''; - + if (count($prodcustprice->lines) > 0 || $search_prod) { print ''; - print ''; - print ''; + print ''; + print ''; // Print the search button print ''; print ''; } - + if (count($prodcustprice->lines) > 0) { $var = False; - + foreach ($prodcustprice->lines as $line) { print ""; - + $staticprod = new Product($db); $staticprod->fetch($line->fk_product); - + print ""; print ""; - + print '"; - print '"; + print '"; print '"; print '"; print ''; print ''; - + // User $userstatic = new User($db); $userstatic->fetch($line->fk_user); print ''; - + // Action if ($user->rights->produit->creer || $user->rights->service->creer) { @@ -561,21 +603,21 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { print ''; print ''; } - + print "\n"; } } else { $colspan=9; - if ($user->rights->produit->supprimer || $user->rights->service->supprimer) $colspan+=1; + if ($user->rights->produit->supprimer || $user->rights->service->supprimer) $colspan+=1; print ''; } - + print "
' . $langs->trans("Product") . '' . $langs->trans("AppliedPricesFrom") . '' . $langs->trans("ChangedBy") . ' 
  '; $searchpitco=$form->showFilterAndCheckAddButtons(0); @@ -515,35 +557,35 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { print '
" . $staticprod->getNomUrl(1) . "" . dol_print_date($line->datec, "dayhour") . "' . $langs->trans($line->price_base_type) . "' . vatrate($line->tva_tx, true, $line->recuperableonly) . "' . vatrate($line->tva_tx.($line->default_vat_code?' ('.$line->default_vat_code.')':''), true, $line->recuperableonly) . "' . price($line->price) . "' . price($line->price_ttc) . "' . price($line->price_min) . '' . price($line->price_min_ttc) . ''; print $userstatic->getLoginUrl(1); print '
' . $langs->trans('None') . '
"; - + print "
"; - + } } From ea8a49aea36899cbb3970cbd1eaeb0523b72315f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 4 Jul 2017 17:38:20 +0200 Subject: [PATCH 11/20] Prepare 5.0.5 --- htdocs/filefunc.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php index 9e065451001..537f8908de7 100644 --- a/htdocs/filefunc.inc.php +++ b/htdocs/filefunc.inc.php @@ -31,7 +31,7 @@ */ if (! defined('DOL_APPLICATION_TITLE')) define('DOL_APPLICATION_TITLE','Dolibarr'); -if (! defined('DOL_VERSION')) define('DOL_VERSION','5.0.4'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c +if (! defined('DOL_VERSION')) define('DOL_VERSION','5.0.5'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c if (! defined('EURO')) define('EURO',chr(128)); From e199864fce9600488c736d7701ac6bed5e9e48e2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 5 Jul 2017 00:09:35 +0200 Subject: [PATCH 12/20] Better log --- htdocs/categories/class/categorie.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 0263395ec50..dbac2f0236a 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -52,7 +52,7 @@ class Categorie extends CommonObject const TYPE_ACCOUNT = 5; // for bank account TODO Replace this value with 'account' const TYPE_PROJECT = 6; public $picto = 'category'; - + /** * @var array ID mapping from type string @@ -556,7 +556,7 @@ class Categorie extends CommonObject $error++; } } - + if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_lang"; @@ -1163,11 +1163,11 @@ class Categorie extends CommonObject */ if($obj[0] > 0 && $obj[0] != $this->id) { - dol_syslog(get_class($this)."::already_exists category with name=".$this->label." exist rowid=".$obj[0]." current_id=".$this->id, LOG_DEBUG); + dol_syslog(get_class($this)."::already_exists category with name=".$this->label." and parent ".$this->fk_parent." exists: rowid=".$obj[0]." current_id=".$this->id, LOG_DEBUG); return 1; } } - dol_syslog(get_class($this)."::already_exists no category with same name=".$this->label." rowid=".$obj[0]." current_id=".$this->id, LOG_DEBUG); + dol_syslog(get_class($this)."::already_exists no category with same name=".$this->label." and same parent ".$this->fk_parent.": rowid=".$obj[0]." current_id=".$this->id, LOG_DEBUG); return 0; } else @@ -1737,8 +1737,8 @@ class Categorie extends CommonObject { return ''; } - - + + /** * Initialise an instance with random values. * Used to build previews or test instances. From a2e2149eb2cce8bef560b1cb9c2385f0b48e135f Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 5 Jul 2017 11:12:48 +0200 Subject: [PATCH 13/20] Fix: multiple preg_match $reg confusion ! --- htdocs/api/index.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 0e54d0cb8af..21d60bdab73 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -131,9 +131,9 @@ if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/resources.json' | { while (($file = readdir($handle))!==false) { - if (is_readable($dir.$file) && preg_match("/^mod(.*)\.class\.php$/i",$file,$reg)) + if (is_readable($dir.$file) && preg_match("/^mod(.*)\.class\.php$/i",$file,$regmod)) { - $module = strtolower($reg[1]); + $module = strtolower($regmod[1]); $moduledirforclass = getModuleDirForApiClass($module); $moduleforperm = $module; if ($module == 'propale') { $moduleforperm='propal'; } @@ -159,9 +159,9 @@ if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/resources.json' | if ($file_searched == 'api_access.class.php') continue; // Support of the deprecated API. - if (is_readable($dir_part.$file_searched) && preg_match("/^api_deprecated_(.*)\.class\.php$/i",$file_searched,$reg)) + if (is_readable($dir_part.$file_searched) && preg_match("/^api_deprecated_(.*)\.class\.php$/i",$file_searched,$regapi)) { - $classname = ucwords($reg[1]).'Api'; + $classname = ucwords($regapi[1]).'Api'; require_once $dir_part.$file_searched; if (class_exists($classname)) { @@ -173,9 +173,9 @@ if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/resources.json' | dol_syslog("We found an api_xxx file (".$file_searched.") but class ".$classname." does not exists after loading file", LOG_WARNING); } } - elseif (is_readable($dir_part.$file_searched) && preg_match("/^api_(.*)\.class\.php$/i",$file_searched,$reg)) + elseif (is_readable($dir_part.$file_searched) && preg_match("/^api_(.*)\.class\.php$/i",$file_searched,$regapi)) { - $classname = ucwords($reg[1]); + $classname = ucwords($regapi[1]); $classname = str_replace('_', '', $classname); require_once $dir_part.$file_searched; if (class_exists($classname)) From c5442c355395759d02c853cca3514c6adfc03c49 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 5 Jul 2017 12:21:35 +0200 Subject: [PATCH 14/20] Fix: module "root" not exists ! (deprecated api) --- htdocs/api/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 21d60bdab73..905d560f9c2 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -206,7 +206,7 @@ if (! empty($reg[1]) && $reg[1] == 'explorer' && ($reg[2] == '/resources.json' | } // Call one APIs or one definition of an API -if (! empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/resources.json' && preg_match('/^\/resources.json\/(.+)$/', $reg[2], $regbis)))) +if (! empty($reg[1]) && ($reg[1] != 'explorer' || ($reg[2] != '/resources.json' && preg_match('/^\/resources.json\/(.+)$/', $reg[2], $regbis) && $regbis[1] != 'root'))) { $module = $reg[1]; if ($module == 'explorer') // If we call page to explore details of a service From 2aaf8b22f22b2ef1a0ba391b938260c39875279e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 7 Jul 2017 10:10:12 +0200 Subject: [PATCH 15/20] Fix substitution var --- htdocs/core/class/commondocgenerator.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index bb806257d01..e85434ccd37 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -386,7 +386,7 @@ abstract class CommonDocGenerator $array_key.'_note_private'=>$object->note, $array_key.'_note_public'=>$object->note_public, $array_key.'_note'=>$object->note_public, // For backward compatibility - + // Payments $array_key.'_already_payed_locale'=>price($sumpayed, 0, $outputlangs), $array_key.'_already_payed'=>price2num($sumpayed), @@ -394,10 +394,10 @@ abstract class CommonDocGenerator $array_key.'_already_deposit'=>price2num($sumdeposit), $array_key.'_already_creditnote_locale'=>price($sumcreditnote, 0, $outputlangs), $array_key.'_already_creditnote'=>price2num($sumcreditnote), - + $array_key.'_already_payed_all_locale'=>price(price2num($sumpayed + $sumdeposit + $sumcreditnote, 'MT'), 0, $outputlangs), - $array_key.'already_payed_all'=> price2num(($sumpayed + $sumdeposit + $sumcreditnote), 'MT'), - + $array_key.'_already_payed_all'=> price2num(($sumpayed + $sumdeposit + $sumcreditnote), 'MT'), + // Remain to pay with all know infrmation (except open direct debit requests) $array_key.'_remain_to_pay_locale'=>price(price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT'), 0, $outputlangs), $array_key.'_remain_to_pay'=>price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT') From 9baeee893f13a51c153a765254fbbbbd81576158 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 7 Jul 2017 10:54:54 +0200 Subject: [PATCH 16/20] Fix multicurrency (tags for odt) --- .../core/class/commondocgenerator.class.php | 80 ++++++++++++------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 00394b0e03f..4d8bc356ef4 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -318,34 +318,6 @@ abstract class CommonDocGenerator return $array_other; } - - - - /** - * Define array with couple subtitution key => subtitution value - * - * @param Object $object Dolibarr Object - * @param Translate $outputlangs Language object for output - * @param boolean $recursive Want to fetch child array or child object - * @return array Array of substitution key->code - */ - function get_substitutionarray_each_var_object(&$object,$outputlangs,$recursive=true) { - $array_other = array(); - if(!empty($object)) { - foreach($object as $key => $value) { - if(!empty($value)) { - if(!is_array($value) && !is_object($value)) { - $array_other['object_'.$key] = $value; - } - if(is_array($value) && $recursive){ - $array_other['object_'.$key] = $this->get_substitutionarray_each_var_object($value,$outputlangs,false); - } - } - } - } - return $array_other; - } - /** @@ -410,10 +382,19 @@ abstract class CommonDocGenerator $array_key.'_total_ttc'=>price2num($object->total_ttc), $array_key.'_total_discount_ht' => price2num($object->getTotalDiscount()), + $array_key.'_multicurrency_code' => price2num($object->multicurrency_code), + $array_key.'_multicurrency_tx' => price2num($object->multicurrency_tx), + $array_key.'_multicurrency_total_ht' => price2num($object->multicurrency_total_ht), + $array_key.'_multicurrency_total_tva' => price2num($object->multicurrency_total_tva), + $array_key.'_multicurrency_total_ttc' => price2num($object->multicurrency_total_ttc), + $array_key.'_multicurrency_total_ht_locale' => price($object->multicurrency_total_ht, 0, $outputlangs), + $array_key.'_multicurrency_total_tva_locale' => price($object->multicurrency_total_tva, 0, $outputlangs), + $array_key.'_multicurrency_total_ttc_locale' => price($object->multicurrency_total_ttc, 0, $outputlangs), + $array_key.'_note_private'=>$object->note, $array_key.'_note_public'=>$object->note_public, $array_key.'_note'=>$object->note_public, // For backward compatibility - + // Payments $array_key.'_already_payed_locale'=>price($sumpayed, 0, $outputlangs), $array_key.'_already_payed'=>price2num($sumpayed), @@ -421,10 +402,10 @@ abstract class CommonDocGenerator $array_key.'_already_deposit'=>price2num($sumdeposit), $array_key.'_already_creditnote_locale'=>price($sumcreditnote, 0, $outputlangs), $array_key.'_already_creditnote'=>price2num($sumcreditnote), - + $array_key.'_already_payed_all_locale'=>price(price2num($sumpayed + $sumdeposit + $sumcreditnote, 'MT'), 0, $outputlangs), $array_key.'already_payed_all'=> price2num(($sumpayed + $sumdeposit + $sumcreditnote), 'MT'), - + // Remain to pay with all know infrmation (except open direct debit requests) $array_key.'_remain_to_pay_locale'=>price(price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT'), 0, $outputlangs), $array_key.'_remain_to_pay'=>price2num($object->total_ttc - $sumpayed - $sumdeposit - $sumcreditnote, 'MT') @@ -493,6 +474,16 @@ abstract class CommonDocGenerator 'line_date_end'=>dol_print_date($line->date_end, 'day', 'tzuser'), 'line_date_end_locale'=>dol_print_date($line->date_end, 'day', 'tzuser', $outputlangs), 'line_date_end_rfc'=>dol_print_date($line->date_end, 'dayrfc', 'tzuser'), + + 'line_multicurrency_code' => price2num($line->multicurrency_code), + 'line_multicurrency_subprice' => price2num($line->multicurrency_subprice), + 'line_multicurrency_total_ht' => price2num($line->multicurrency_total_ht), + 'line_multicurrency_total_tva' => price2num($line->multicurrency_total_tva), + 'line_multicurrency_total_ttc' => price2num($line->multicurrency_total_ttc), + 'line_multicurrency_subprice_locale' => price($line->multicurrency_subprice, 0, $outputlangs), + 'line_multicurrency_total_ht_locale' => price($line->multicurrency_total_ht, 0, $outputlangs), + 'line_multicurrency_total_tva_locale' => price($line->multicurrency_total_tva, 0, $outputlangs), + 'line_multicurrency_total_ttc_locale' => price($line->multicurrency_total_ttc, 0, $outputlangs), ); // Retrieve extrafields @@ -601,6 +592,33 @@ abstract class CommonDocGenerator ); } + + /** + * Define array with couple subtitution key => subtitution value + * + * @param Object $object Dolibarr Object + * @param Translate $outputlangs Language object for output + * @param boolean $recursive Want to fetch child array or child object + * @return array Array of substitution key->code + */ + function get_substitutionarray_each_var_object(&$object,$outputlangs,$recursive=true) { + $array_other = array(); + if(!empty($object)) { + foreach($object as $key => $value) { + if(!empty($value)) { + if(!is_array($value) && !is_object($value)) { + $array_other['object_'.$key] = $value; + } + if(is_array($value) && $recursive){ + $array_other['object_'.$key] = $this->get_substitutionarray_each_var_object($value,$outputlangs,false); + } + } + } + } + return $array_other; + } + + /** * Fill array with couple extrafield key => extrafield value * From de1a7042d455a771ec64bac1a17bf2bbb9244a47 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 7 Jul 2017 10:55:42 +0200 Subject: [PATCH 17/20] Fix filter on list of actions --- htdocs/comm/action/listactions.php | 15 +++++++++++---- htdocs/langs/en_US/agenda.lang | 3 +++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/htdocs/comm/action/listactions.php b/htdocs/comm/action/listactions.php index 13a7015059b..55f73575f78 100644 --- a/htdocs/comm/action/listactions.php +++ b/htdocs/comm/action/listactions.php @@ -59,9 +59,9 @@ else if ($actioncode == '' && empty($actioncodearray)) $actioncode=(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE); $search_title=GETPOST('search_title','alpha'); -$dateselect=dol_mktime(0, 0, 0, GETPOST('dateselectmonth'), GETPOST('dateselectday'), GETPOST('dateselectyear')); -$datestart=dol_mktime(0, 0, 0, GETPOST('datestartmonth'), GETPOST('datestartday'), GETPOST('datestartyear')); -$dateend=dol_mktime(0, 0, 0, GETPOST('dateendmonth'), GETPOST('dateendday'), GETPOST('dateendyear')); +$dateselect=dol_mktime(0, 0, 0, GETPOST('dateselectmonth','int'), GETPOST('dateselectday','int'), GETPOST('dateselectyear','int')); +$datestart=dol_mktime(0, 0, 0, GETPOST('datestartmonth','int'), GETPOST('datestartday','int'), GETPOST('datestartyear','int')); +$dateend=dol_mktime(0, 0, 0, GETPOST('dateendmonth','int'), GETPOST('dateendday','int'), GETPOST('dateendyear','int')); if ($status == '' && ! isset($_GET['status']) && ! isset($_POST['status'])) $status=(empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS)?'':$conf->global->AGENDA_DEFAULT_FILTER_STATUS); if (empty($action) && ! isset($_GET['action']) && ! isset($_POST['action'])) $action=(empty($conf->global->AGENDA_DEFAULT_VIEW)?'show_month':$conf->global->AGENDA_DEFAULT_VIEW); @@ -168,7 +168,7 @@ if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&con if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; if ($actioncode != '') $param.="&actioncode=".$actioncode; if ($resourceid > 0) $param.="&resourceid=".$resourceid; -if ($status || isset($_GET['status']) || isset($_POST['status'])) $param.="&status=".$status; +if ($status != '' && $status > -1) $param.="&status=".$status; if ($filter) $param.="&filter=".$filter; if ($filtert) $param.="&filtert=".$filtert; if ($socid) $param.="&socid=".$socid; @@ -177,6 +177,13 @@ if ($pid) $param.="&projectid=".$pid; if ($type) $param.="&type=".$type; if ($usergroup) $param.="&usergroup=".$usergroup; if ($optioncss != '') $param.='&optioncss='.$optioncss; +if ($search_title != '') $param.='&search_title='.$search_title; +if (GETPOST('datestartday','int')) $param.='&datestartday='.GETPOST('datestartday','int'); +if (GETPOST('datestartmonth','int')) $param.='&datestartmonth='.GETPOST('datestartmonth','int'); +if (GETPOST('datestartyear','int')) $param.='&datestartyear='.GETPOST('datestartyear','int'); +if (GETPOST('dateendday','int')) $param.='&dateendday='.GETPOST('dateendday','int'); +if (GETPOST('dateendmonth','int')) $param.='&dateendmonth='.GETPOST('dateendmonth','int'); +if (GETPOST('dateendyear','int')) $param.='&dateendyear='.GETPOST('dateendyear','int'); $sql = "SELECT"; if ($usergroup > 0) $sql.=" DISTINCT"; diff --git a/htdocs/langs/en_US/agenda.lang b/htdocs/langs/en_US/agenda.lang index 4e2e2acf378..38a40315985 100644 --- a/htdocs/langs/en_US/agenda.lang +++ b/htdocs/langs/en_US/agenda.lang @@ -75,6 +75,9 @@ InterventionSentByEMail=Intervention %s sent by EMail ProposalDeleted=Proposal deleted OrderDeleted=Order deleted InvoiceDeleted=Invoice deleted +PRODUCT_CREATEInDolibarr=Product %s created +PRODUCT_MODIFYInDolibarr=Product %s modified +PRODUCT_DELETEInDolibarr=Product %s deleted ##### End agenda events ##### AgendaModelModule=Document templates for event DateActionStart=Start date From 2be9f402c6acfa1bdaf6fb89823c7e1e97e1a0db Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 7 Jul 2017 10:58:18 +0200 Subject: [PATCH 18/20] Fix order of tab --- htdocs/admin/agenda_other.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/admin/agenda_other.php b/htdocs/admin/agenda_other.php index 31bcf1077e6..cf4f3832a1f 100644 --- a/htdocs/admin/agenda_other.php +++ b/htdocs/admin/agenda_other.php @@ -385,7 +385,7 @@ print ''."\n"; print ''.$langs->trans("AGENDA_DEFAULT_VIEW").''."\n"; print ' '."\n"; print ''."\n"; -$tmplist=array('show_month'=>$langs->trans("ViewCal"), 'show_week'=>$langs->trans("ViewWeek"), 'show_day'=>$langs->trans("ViewDay"), 'show_list'=>$langs->trans("ViewList"), 'show_peruser'=>$langs->trans("ViewPerUser")); +$tmplist=array('show_list'=>$langs->trans("ViewList"), 'show_month'=>$langs->trans("ViewCal"), 'show_week'=>$langs->trans("ViewWeek"), 'show_day'=>$langs->trans("ViewDay"), 'show_peruser'=>$langs->trans("ViewPerUser")); print $form->selectarray('AGENDA_DEFAULT_VIEW', $tmplist, $conf->global->AGENDA_DEFAULT_VIEW); print ''."\n"; From 8abec461a6908f2d4024df69cf96f3c229eda5d4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 7 Jul 2017 12:31:00 +0200 Subject: [PATCH 19/20] Fix total with tax does not include local taxes. To solve, i show both totals. --- htdocs/langs/en_US/main.lang | 1 + htdocs/product/price.php | 104 ++++++++++++++++++++++++----------- 2 files changed, 73 insertions(+), 32 deletions(-) diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index a35342f2af9..8b1c0df7f40 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -358,6 +358,7 @@ TotalLT1ES=Total RE TotalLT2ES=Total IRPF HT=Net of tax TTC=Inc. tax +INCT=Inc. all taxes VAT=Sales tax VATs=Sales taxes LT1ES=RE diff --git a/htdocs/product/price.php b/htdocs/product/price.php index 8c86f544dba..a701a637aa8 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -33,6 +33,7 @@ */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php'; require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT . '/product/dynamic_price/class/price_expression.class.php'; require_once DOL_DOCUMENT_ROOT . '/product/dynamic_price/class/price_parser.class.php'; @@ -759,12 +760,8 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES)) print ''.$langs->trans("MinPrice").''; print ''; - $var=True; - for($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { - $var = ! $var; - print ''; // Label of price @@ -1244,11 +1241,8 @@ if ($action == 'edit_price' && $object->getRights()->creer) print ''; - $var = false; for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i ++) { - $var = !$var; - print ''; print ''; print $form->textwithpicto($langs->trans('SellingPrice') . ' ' . $i, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1); @@ -1389,13 +1383,12 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action=='showlog_default_ $notfirstlineforlevel=array(); - $var = True; $i = 0; while ($i < $num) { $objp = $db->fetch_object($result); - $var = ! $var; - print ''; + + print ''; // Date print "" . dol_print_date($db->jdate($objp->dp), "dayhour") . ""; @@ -1440,7 +1433,9 @@ if ((empty($conf->global->PRODUIT_CUSTOMER_PRICES) || $action=='showlog_default_ print ''; } } + print '' . ($objp->price_base_type != 'TTC' ? price($objp->price_min) : '') . ''; + print '' . ($objp->price_base_type == 'TTC' ? price($objp->price_min_ttc) : '') . ''; // User @@ -1729,11 +1724,8 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print ' '; print ''; - $var = True; - foreach ($prodcustprice->lines as $line) { - $var = ! $var; print ''; // Date $staticsoc = new Societe($db); @@ -1748,6 +1740,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print '' . vatrate($tva_tx, true, $line->recuperableonly) . ""; print '' . price($line->price) . ""; print '' . price($line->price_ttc) . ""; + print '' . price($line->price_min) . ''; print '' . price($line->price_min_ttc) . ''; @@ -1757,6 +1750,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print ''; print $userstatic->getLoginUrl(1); print ''; + print ''; } print ""; } else { @@ -1788,24 +1782,14 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if (count($prodcustprice->lines) > 0 || $search_soc) { + $colspan=8; + if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") $colspan++; + print ''; print ''; - print ''; + print ''; // Print the search button print ''; } - $var = False; - + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") print ''; + print ''; + print ''; + print ''; + print ''; + print ''; // Line for default price + if ($object->price_base_type=='HT') + { + $pu=$object->price; + } + else + { + $pu=$object->price_ttc; + } + + // Local tax is not saved into table of product. We use value linked to VAT code. + $localtaxarray=getLocalTaxesFromRate($object->tva_tx.($object->default_vat_code?' ('.$object->default_vat_code.')':''), 0, $mysoc, $mysoc); + // Define part of HT, VAT, TTC + $resultarray=calcul_price_total(1, $pu, 0, $object->tva_tx, 1, 1, 0, $object->price_base_type, $object->recuperableonly, $object->type, $mysoc, $localtaxarray); + // Calcul du total ht sans remise + $total_ht = $resultarray[0]; + $total_vat = $resultarray[1]; + $total_localtax1 = $resultarray[9]; + $total_localtax2 = $resultarray[10]; + $total_ttc = $resultarray[2]; + print ''; print ""; print ""; @@ -1827,8 +1842,12 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print vatrate($object->tva_tx, true, $object->recuperableonly); print $object->default_vat_code?' ('.$object->default_vat_code.')':''; print ""; + print '"; print '"; + + if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") print ''; + print ''; print ''; print ''; // Date @@ -1864,6 +1880,27 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) $tva_tx = $line->default_vat_code ? $line->tva_tx.' ('.$line->default_vat_code.')' : $line->tva_tx; + // Line for default price + if ($object->price_base_type=='HT') + { + $pu=$line->price; + } + else + { + $pu=$line->price_ttc; + } + + // Local tax is not saved into table of product. We use value linked to VAT code. + $localtaxarray=getLocalTaxesFromRate($object->tva_tx.($object->default_vat_code?' ('.$object->default_vat_code.')':''), 0, $mysoc, $mysoc); + // Define part of HT, VAT, TTC + $resultarray=calcul_price_total(1, $pu, 0, $object->tva_tx, 1, 1, 0, $object->price_base_type, $object->recuperableonly, $object->type, $mysoc, $localtaxarray); + // Calcul du total ht sans remise + $total_ht = $resultarray[0]; + $total_vat = $resultarray[1]; + $total_localtax1 = $resultarray[9]; + $total_localtax2 = $resultarray[10]; + $total_ttc = $resultarray[2]; + print ""; print ""; @@ -1871,6 +1908,9 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print '"; print '"; print '"; + + if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") print ''; + print ''; print ''; From 4c0fcb2b9a45dbd39fc0cc6b7215649cb1816739 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 7 Jul 2017 14:58:57 +0200 Subject: [PATCH 20/20] Fix total with tax does not include local taxes. To solve, i show both totals. --- htdocs/product/price.php | 73 ++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/htdocs/product/price.php b/htdocs/product/price.php index a701a637aa8..e296d44bd33 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -1606,9 +1606,12 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print ''; print ''; print ''; + + dol_fiche_head(); + print '
' . $langs->trans("ThirdParty") . '' . $langs->trans("AppliedPricesFrom") . '' . $langs->trans("PriceBase") . '' . $langs->trans("VATRate") . '' . $langs->trans("HT") . '' . $langs->trans("TTC") . '' . $langs->trans("MinPrice") . ' ' . $langs->trans("HT") . '' . $langs->trans("MinPrice") . ' ' . $langs->trans("TTC") . '' . $langs->trans("ChangedBy") . ' 
  '; $searchpicto=$form->showFilterAndCheckAddButtons(0); @@ -1814,10 +1798,41 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print '
' . $langs->trans("ThirdParty") . '' . $langs->trans("AppliedPricesFrom") . '' . $langs->trans("PriceBase") . '' . $langs->trans("VATRate") . '' . $langs->trans("HT") . '' . $langs->trans("TTC") . '' . $langs->trans("INCT") . '' . $langs->trans("MinPrice") . ' ' . $langs->trans("HT") . '' . $langs->trans("MinPrice") . ' ' . $langs->trans("TTC") . '' . $langs->trans("ChangedBy") . ' 
" . $langs->trans("Default") . "" . "' . price($object->price) . "' . price($object->price_ttc) . "' . price($resultarray[2]) . '' . price($object->price_min) . '' . price($object->price_min_ttc) . ''; @@ -1851,11 +1870,8 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) if (count($prodcustprice->lines) > 0) { - $var = false; foreach ($prodcustprice->lines as $line) { - $var = ! $var; - print '
" . $staticsoc->getNomUrl(1) . "" . dol_print_date($line->datec, "dayhour") . "' . vatrate($tva_tx, true, $line->recuperableonly) . "' . price($line->price) . "' . price($line->price_ttc) . "' . price($resultarray[2]) . '' . price($line->price_min) . '' . price($line->price_min_ttc) . '
'; print ''; - print ''; + print ''; $staticsoc = new Societe($db); $staticsoc->fetch($prodcustprice->fk_soc); print ""; @@ -1620,7 +1623,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print ''; // Price base - print ''; print ''; // Price - print ''; // Update all child soc - print ''; print '
' . $langs->trans('ThirdParty') . '' . $langs->trans('ThirdParty') . '" . $staticsoc->getNomUrl(1) . "
'; + print '
'; print $langs->trans('PriceBase'); print ''; @@ -1629,7 +1632,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print '
'; + print '
'; $text = $langs->trans('SellingPrice'); print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1); print ''; @@ -1658,7 +1661,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print '
'; + print '
'; print $langs->trans('ForceUpdateChildPriceSoc'); print ''; @@ -1668,7 +1671,9 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print '
'; - print '
'; + dol_fiche_end(); + + print '
'; print ''; print '     '; print ''; @@ -1678,7 +1683,10 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) } elseif ($action == 'showlog_customer_price') { - $filter = array('t.fk_product' => $object->id,'t.fk_soc' => GETPOST('socid', 'int')); + // List of all log of prices by customers + print ''."\n"; + + $filter = array('t.fk_product' => $object->id,'t.fk_soc' => GETPOST('socid', 'int')); // Count total nb of records $nbtotalofrecords = ''; @@ -1705,7 +1713,6 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) if (count($prodcustprice->lines) > 0) { - print '
'; print ''; @@ -1718,6 +1725,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) print '' . $langs->trans("VATRate") . ''; print '' . $langs->trans("HT") . ''; print '' . $langs->trans("TTC") . ''; + if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") print '' . $langs->trans("INCT") . ''; print '' . $langs->trans("MinPrice") . ' ' . $langs->trans("HT") . ''; print '' . $langs->trans("MinPrice") . ' ' . $langs->trans("TTC") . ''; print '' . $langs->trans("ChangedBy") . ''; @@ -1726,21 +1734,44 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) foreach ($prodcustprice->lines as $line) { - print ''; - // Date - $staticsoc = new Societe($db); - $staticsoc->fetch($line->fk_soc); - - print "" . $staticsoc->getNomUrl(1) . ""; - print "" . dol_print_date($line->datec, "dayhour") . ""; + // Date + $staticsoc = new Societe($db); + $staticsoc->fetch($line->fk_soc); $tva_tx = $line->default_vat_code ? $line->tva_tx.' ('.$line->default_vat_code.')' : $line->tva_tx; - print '' . $langs->trans($line->price_base_type) . ""; + // Line for default price + if ($line->price_base_type=='HT') + { + $pu=$line->price; + } + else + { + $pu=$line->price_ttc; + } + + // Local tax is not saved into table of product. We use value linked to VAT code. + $localtaxarray=getLocalTaxesFromRate($line->tva_tx.($line->default_vat_code?' ('.$line->default_vat_code.')':''), 0, $staticsoc, $mysoc); + // Define part of HT, VAT, TTC + $resultarray=calcul_price_total(1, $pu, 0, $line->tva_tx, 1, 1, 0, $line->price_base_type, $line->recuperableonly, $object->type, $mysoc, $localtaxarray); + // Calcul du total ht sans remise + $total_ht = $resultarray[0]; + $total_vat = $resultarray[1]; + $total_localtax1 = $resultarray[9]; + $total_localtax2 = $resultarray[10]; + $total_ttc = $resultarray[2]; + + print ''; + + print "" . $staticsoc->getNomUrl(1) . ""; + print "" . dol_print_date($line->datec, "dayhour") . ""; + print '' . $langs->trans($line->price_base_type) . ""; print '' . vatrate($tva_tx, true, $line->recuperableonly) . ""; print '' . price($line->price) . ""; print '' . price($line->price_ttc) . ""; + if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") print '' . price($resultarray[2]) . ''; + print '' . price($line->price_min) . ''; print '' . price($line->price_min_ttc) . ''; @@ -1760,7 +1791,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) else if ($action != 'showlog_default_price' && $action != 'edit_price') { // List of all prices by customers - print ''."\n"; + print ''."\n"; // Count total nb of records $nbtotalofrecords = ''; @@ -1872,8 +1903,6 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { foreach ($prodcustprice->lines as $line) { - print ''; - // Date $staticsoc = new Societe($db); $staticsoc->fetch($line->fk_soc); @@ -1881,7 +1910,7 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) $tva_tx = $line->default_vat_code ? $line->tva_tx.' ('.$line->default_vat_code.')' : $line->tva_tx; // Line for default price - if ($object->price_base_type=='HT') + if ($line->price_base_type=='HT') { $pu=$line->price; } @@ -1891,9 +1920,9 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) } // Local tax is not saved into table of product. We use value linked to VAT code. - $localtaxarray=getLocalTaxesFromRate($object->tva_tx.($object->default_vat_code?' ('.$object->default_vat_code.')':''), 0, $mysoc, $mysoc); + $localtaxarray=getLocalTaxesFromRate($line->tva_tx.($line->default_vat_code?' ('.$line->default_vat_code.')':''), 0, $staticsoc, $mysoc); // Define part of HT, VAT, TTC - $resultarray=calcul_price_total(1, $pu, 0, $object->tva_tx, 1, 1, 0, $object->price_base_type, $object->recuperableonly, $object->type, $mysoc, $localtaxarray); + $resultarray=calcul_price_total(1, $pu, 0, $line->tva_tx, 1, 1, 0, $line->price_base_type, $line->recuperableonly, $object->type, $mysoc, $localtaxarray); // Calcul du total ht sans remise $total_ht = $resultarray[0]; $total_vat = $resultarray[1]; @@ -1901,6 +1930,8 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) $total_localtax2 = $resultarray[10]; $total_ttc = $resultarray[2]; + print ''; + print "" . $staticsoc->getNomUrl(1) . ""; print "" . dol_print_date($line->datec, "dayhour") . "";