From e85b4a5a207fa9f9dd3f78ec72346e2539a34c50 Mon Sep 17 00:00:00 2001 From: Pierre Ardoin <32256817+mapiolca@users.noreply.github.com> Date: Thu, 16 Apr 2020 12:15:41 +0200 Subject: [PATCH 01/38] FIX Directory Issue with Multicompany Before : Cannot show documents added entity who created the product/service Now : show all files. Warning : all products must be generated in $object->entity directory and not in $conf->entity. --- htdocs/product/card.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index ad793f4f7d3..499ac1ec1e4 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -2255,7 +2255,11 @@ if ($action != 'create' && $action != 'edit' && $action != 'delete') // Documents $objectref = dol_sanitizeFileName($object->ref); $relativepath = $comref.'/'.$objectref.'.pdf'; - $filedir = $conf->product->dir_output.'/'.$objectref; + if ($conf->product->entity != $object->entity) { + $filedir = $conf->product->multidir_output[$object->entity].'/'.$objectref; //Check repertories of current entities + } else { + $filedir = $conf->product->dir_output.'/'.$objectref; //Check repertory of the current product + } $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; $genallowed = $usercanread; $delallowed = $usercancreate; From 19c85785f7d049f4b4e8002d1291738482ceec1b Mon Sep 17 00:00:00 2001 From: Pierre Ardoin <32256817+mapiolca@users.noreply.github.com> Date: Thu, 16 Apr 2020 13:26:55 +0200 Subject: [PATCH 02/38] Fix --- htdocs/product/card.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 499ac1ec1e4..de863769519 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -18,6 +18,7 @@ * Copyright (C) 2017 Josep Lluís Amador * Copyright (C) 2019 Frédéric France * Copyright (C) 2019-2020 Thibault FOUCART + * Copyright (C) 2020 Pierre Ardoin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -2255,11 +2256,7 @@ if ($action != 'create' && $action != 'edit' && $action != 'delete') // Documents $objectref = dol_sanitizeFileName($object->ref); $relativepath = $comref.'/'.$objectref.'.pdf'; - if ($conf->product->entity != $object->entity) { - $filedir = $conf->product->multidir_output[$object->entity].'/'.$objectref; //Check repertories of current entities - } else { - $filedir = $conf->product->dir_output.'/'.$objectref; //Check repertory of the current product - } + $filedir = $conf->product->multidir_output[$object->entity].'/'.$objectref; //Check repertories of current entities $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; $genallowed = $usercanread; $delallowed = $usercancreate; From 720a113125d762000eb589467a963cb2d30f8355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Sat, 19 Sep 2020 14:16:17 +0200 Subject: [PATCH 03/38] Update api_invoices.class.php --- .../facture/class/api_invoices.class.php | 114 ++++++++++-------- 1 file changed, 63 insertions(+), 51 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 1828493d89f..778d34446bf 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -1397,28 +1397,27 @@ class Invoices extends DolibarrApi /** * Add a payment to pay partially or completely one or several invoices. * Warning: Take care that all invoices are owned by the same customer. - * Example of value for parameter arrayofamounts: {"1": "99.99", "2": "10"} + * Example of value for parameter arrayofamounts: {"1": {"amount": "99.99", "multicurrency_amount": ""}, "2": {"amount": "", "multicurrency_amount": "10"}} * * @param array $arrayofamounts {@from body} Array with id of invoices with amount to pay for each invoice * @param string $datepaye {@from body} Payment date {@type timestamp} - * @param int $paymentid {@from body} Payment mode Id {@min 1} + * @param int $paiementid {@from body} Payment mode Id {@min 1} * @param string $closepaidinvoices {@from body} Close paid invoices {@choice yes,no} * @param int $accountid {@from body} Account Id {@min 1} - * @param string $num_payment {@from body} Payment number (optional) - * @param string $comment {@from body} Note private (optional) + * @param string $num_paiement {@from body} Payment number (optional) + * @param string $comment {@from body} Note (optional) * @param string $chqemetteur {@from body} Payment issuer (mandatory if paiementcode = 'CHQ') * @param string $chqbank {@from body} Issuer bank name (optional) * * @url POST /paymentsdistributed * * @return int Payment ID - * - * @throws RestException 400 - * @throws RestException 401 - * @throws RestException 403 - * @throws RestException 404 + * @throws 400 + * @throws 401 + * @throws 403 + * @throws 404 */ - public function addPaymentDistributed($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment = '', $comment = '', $chqemetteur = '', $chqbank = '') + public function addPaymentDistributed($arrayofamounts, $datepaye, $paiementid, $closepaidinvoices, $accountid, $num_paiement = '', $comment = '', $chqemetteur = '', $chqbank = '') { global $conf; @@ -1441,8 +1440,8 @@ class Invoices extends DolibarrApi throw new RestException(400, 'Account ID is mandatory'); } } - if (empty($paymentid)) { - throw new RestException(400, 'Payment ID or Payment Code is mandatory'); + if (empty($paiementid)) { + throw new RestException(400, 'Paiement ID or Paiement Code is mandatory'); } $this->db->begin(); @@ -1451,77 +1450,90 @@ class Invoices extends DolibarrApi $multicurrency_amounts = array(); // Loop on each invoice to pay - foreach ($arrayofamounts as $id => $amount) + foreach ($arrayofamounts as $id => $amountarray) { $result = $this->invoice->fetch($id); if (!$result) { $this->db->rollback(); throw new RestException(404, 'Invoice ID '.$id.' not found'); } + + if (($amountarray["amount"] == "remain" || $amountarray["amount"] > 0) && ($amountarray["multicurrency_amount"] == "remain" || $amountarray["multicurrency_amount"] > 0)) { + $this->db->rollback(); + throw new RestException(400, 'Payment in both currency '.$id.' ( amount: '.$amountarray["amount"].', multicurrency_amount: '.$amountarray["multicurrency_amount"].')'); + } + + $is_multicurrency = 0; + $total_ttc = $this->invoice->total_ttc; + + if ($amountarray["multicurrency_amount"] > 0 || $amountarray["multicurrency_amount"] == "remain") { + $is_multicurrency = 1; + $total_ttc = $this->invoice->multicurrency_total_ttc; + } // Calculate amount to pay - $totalpaye = $this->invoice->getSommePaiement(); - $totalcreditnotes = $this->invoice->getSumCreditNotesUsed(); - $totaldeposits = $this->invoice->getSumDepositsUsed(); - $resteapayer = price2num($this->invoice->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT'); - if ($amount != 'remain') + $totalpaye = $this->invoice->getSommePaiement($is_multicurrency); + $totalcreditnotes = $this->invoice->getSumCreditNotesUsed($is_multicurrency); + $totaldeposits = $this->invoice->getSumDepositsUsed($is_multicurrency); + $amount = price2num($total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT'); + + if (!$is_multicurrency && $amountarray["amount"] != 'remain') { - if ($amount > $resteapayer) - { - $this->db->rollback(); - throw new RestException(400, 'Payment amount on invoice ID '.$id.' ('.$amount.') is higher than remain to pay ('.$resteapayer.')'); - } - $resteapayer = $amount; + $amount = price2num($amountarray["amount"], 'MT'); } - // Clean parameters amount if payment is for a credit note - if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE) { - $resteapayer = price2num($resteapayer, 'MT'); - $amounts[$id] = -$resteapayer; + + if ($is_multicurrency && $amountarray["multicurrency_amount"] != 'remain') + { + $amount = price2num($amountarray["multicurrency_amount"], 'MT'); + } + + if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE) { + $amount = -$amount; + } + + if ($is_multicurrency) { + $amounts[$id] = null; // Multicurrency - $newvalue = price2num($this->invoice->multicurrency_total_ttc, 'MT'); - $multicurrency_amounts[$id] = -$newvalue; + $multicurrency_amounts[$id] = $amount; } else { - $resteapayer = price2num($resteapayer, 'MT'); - $amounts[$id] = $resteapayer; + $amounts[$id] = $amount; // Multicurrency - $newvalue = price2num($this->invoice->multicurrency_total_ttc, 'MT'); - $multicurrency_amounts[$id] = $newvalue; + $multicurrency_amounts[$id] = null; } } // Creation of payment line - $paymentobj = new Paiement($this->db); - $paymentobj->datepaye = $datepaye; - $paymentobj->amounts = $amounts; // Array with all payments dispatching with invoice id - $paymentobj->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching - $paymentobj->paiementid = $paymentid; - $paymentobj->paiementcode = dol_getIdFromCode($this->db, $paymentid, 'c_paiement', 'id', 'code', 1); - $paymentobj->num_payment = $num_payment; - $paymentobj->note_private = $comment; - - $payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices - if ($payment_id < 0) + $paiement = new Paiement($this->db); + $paiement->datepaye = $datepaye; + $paiement->amounts = $amounts; // Array with all payments dispatching with invoice id + $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching + $paiement->paiementid = $paiementid; + $paiement->paiementcode = dol_getIdFromCode($this->db, $paiementid, 'c_paiement', 'id', 'code', 1); + $paiement->num_paiement = $num_paiement; + $paiement->note = $comment; + $paiement_id = $paiement->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices + if ($paiement_id < 0) { $this->db->rollback(); - throw new RestException(400, 'Payment error : '.$paymentobj->error); + throw new RestException(400, 'Payment error : '.$paiement->error); } if (!empty($conf->banque->enabled)) { $label = '(CustomerInvoicePayment)'; - if ($paymentobj->paiementcode == 'CHQ' && empty($chqemetteur)) { - throw new RestException(400, 'Emetteur is mandatory when payment code is '.$paymentobj->paiementcode); + if ($paiement->paiementcode == 'CHQ' && empty($chqemetteur)) { + throw new RestException(400, 'Emetteur is mandatory when payment code is '.$paiement->paiementcode); } if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE) $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note - $result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user, 'payment', $label, $accountid, $chqemetteur, $chqbank); + $result = $paiement->addPaymentToBank(DolibarrApiAccess::$user, 'payment', $label, $accountid, $chqemetteur, $chqbank); if ($result < 0) { $this->db->rollback(); - throw new RestException(400, 'Add payment to bank error : '.$paymentobj->error); + throw new RestException(400, 'Add payment to bank error : '.$paiement->error); } } $this->db->commit(); - return $payment_id; + return $paiement_id; } /** From e1751d4bfbf0dbddcbc05ded576a47a2282cc740 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sat, 19 Sep 2020 12:23:53 +0000 Subject: [PATCH 04/38] Fixing style errors. --- htdocs/compta/facture/class/api_invoices.class.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 778d34446bf..5d824396b80 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -1457,15 +1457,15 @@ class Invoices extends DolibarrApi $this->db->rollback(); throw new RestException(404, 'Invoice ID '.$id.' not found'); } - + if (($amountarray["amount"] == "remain" || $amountarray["amount"] > 0) && ($amountarray["multicurrency_amount"] == "remain" || $amountarray["multicurrency_amount"] > 0)) { $this->db->rollback(); throw new RestException(400, 'Payment in both currency '.$id.' ( amount: '.$amountarray["amount"].', multicurrency_amount: '.$amountarray["multicurrency_amount"].')'); } - + $is_multicurrency = 0; $total_ttc = $this->invoice->total_ttc; - + if ($amountarray["multicurrency_amount"] > 0 || $amountarray["multicurrency_amount"] == "remain") { $is_multicurrency = 1; $total_ttc = $this->invoice->multicurrency_total_ttc; @@ -1476,21 +1476,21 @@ class Invoices extends DolibarrApi $totalcreditnotes = $this->invoice->getSumCreditNotesUsed($is_multicurrency); $totaldeposits = $this->invoice->getSumDepositsUsed($is_multicurrency); $amount = price2num($total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT'); - + if (!$is_multicurrency && $amountarray["amount"] != 'remain') { $amount = price2num($amountarray["amount"], 'MT'); } - + if ($is_multicurrency && $amountarray["multicurrency_amount"] != 'remain') { $amount = price2num($amountarray["multicurrency_amount"], 'MT'); } - + if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE) { $amount = -$amount; } - + if ($is_multicurrency) { $amounts[$id] = null; // Multicurrency From 9f228824172567269cdf153ce14900e7bac57dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Sat, 19 Sep 2020 15:05:28 +0200 Subject: [PATCH 05/38] Update api_invoices.class.php --- htdocs/compta/facture/class/api_invoices.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 5d824396b80..4c27ac54b58 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -1408,6 +1408,7 @@ class Invoices extends DolibarrApi * @param string $comment {@from body} Note (optional) * @param string $chqemetteur {@from body} Payment issuer (mandatory if paiementcode = 'CHQ') * @param string $chqbank {@from body} Issuer bank name (optional) + * @param string $ref_ext {@from body} External reference (optional) * * @url POST /paymentsdistributed * @@ -1417,7 +1418,7 @@ class Invoices extends DolibarrApi * @throws 403 * @throws 404 */ - public function addPaymentDistributed($arrayofamounts, $datepaye, $paiementid, $closepaidinvoices, $accountid, $num_paiement = '', $comment = '', $chqemetteur = '', $chqbank = '') + public function addPaymentDistributed($arrayofamounts, $datepaye, $paiementid, $closepaidinvoices, $accountid, $num_paiement = '', $comment = '', $chqemetteur = '', $chqbank = '', $ref_ext = '') { global $conf; @@ -1511,6 +1512,7 @@ class Invoices extends DolibarrApi $paiement->paiementcode = dol_getIdFromCode($this->db, $paiementid, 'c_paiement', 'id', 'code', 1); $paiement->num_paiement = $num_paiement; $paiement->note = $comment; + $paiement->ref_ext = $ref_ext; $paiement_id = $paiement->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices if ($paiement_id < 0) { From a0efd47ccee8aee222172fb789de79c3fe815a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Sat, 19 Sep 2020 15:12:57 +0200 Subject: [PATCH 06/38] Update api_invoices.class.php --- .../facture/class/api_invoices.class.php | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 4c27ac54b58..e620d30e087 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -1401,11 +1401,11 @@ class Invoices extends DolibarrApi * * @param array $arrayofamounts {@from body} Array with id of invoices with amount to pay for each invoice * @param string $datepaye {@from body} Payment date {@type timestamp} - * @param int $paiementid {@from body} Payment mode Id {@min 1} + * @param int $paymentid {@from body} Payment mode Id {@min 1} * @param string $closepaidinvoices {@from body} Close paid invoices {@choice yes,no} * @param int $accountid {@from body} Account Id {@min 1} - * @param string $num_paiement {@from body} Payment number (optional) - * @param string $comment {@from body} Note (optional) + * @param string $num_payment {@from body} Payment number (optional) + * @param string $comment {@from body} Note private (optional) * @param string $chqemetteur {@from body} Payment issuer (mandatory if paiementcode = 'CHQ') * @param string $chqbank {@from body} Issuer bank name (optional) * @param string $ref_ext {@from body} External reference (optional) @@ -1413,12 +1413,12 @@ class Invoices extends DolibarrApi * @url POST /paymentsdistributed * * @return int Payment ID - * @throws 400 - * @throws 401 - * @throws 403 - * @throws 404 + * @throws RestException 400 + * @throws RestException 401 + * @throws RestException 403 + * @throws RestException 404 */ - public function addPaymentDistributed($arrayofamounts, $datepaye, $paiementid, $closepaidinvoices, $accountid, $num_paiement = '', $comment = '', $chqemetteur = '', $chqbank = '', $ref_ext = '') + public function addPaymentDistributed($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment = '', $comment = '', $chqemetteur = '', $chqbank = '', $ref_ext = '') { global $conf; @@ -1441,8 +1441,8 @@ class Invoices extends DolibarrApi throw new RestException(400, 'Account ID is mandatory'); } } - if (empty($paiementid)) { - throw new RestException(400, 'Paiement ID or Paiement Code is mandatory'); + if (empty($paymentid)) { + throw new RestException(400, 'Payment ID or Payment Code is mandatory'); } $this->db->begin(); @@ -1504,38 +1504,38 @@ class Invoices extends DolibarrApi } // Creation of payment line - $paiement = new Paiement($this->db); - $paiement->datepaye = $datepaye; - $paiement->amounts = $amounts; // Array with all payments dispatching with invoice id - $paiement->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching - $paiement->paiementid = $paiementid; - $paiement->paiementcode = dol_getIdFromCode($this->db, $paiementid, 'c_paiement', 'id', 'code', 1); - $paiement->num_paiement = $num_paiement; - $paiement->note = $comment; - $paiement->ref_ext = $ref_ext; - $paiement_id = $paiement->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices - if ($paiement_id < 0) + $paymentobj = new Paiement($this->db); + $paymentobj->datepaye = $datepaye; + $paymentobj->amounts = $amounts; // Array with all payments dispatching with invoice id + $paymentobj->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching + $paymentobj->paiementid = $paymentid; + $paymentobj->paiementcode = dol_getIdFromCode($this->db, $paymentid, 'c_paiement', 'id', 'code', 1); + $paymentobj->num_paiement = $num_payment; + $paymentobj->note = $comment; + $paymentobj->ref_ext = $ref_ext; + $payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices + if ($payment_id < 0) { $this->db->rollback(); - throw new RestException(400, 'Payment error : '.$paiement->error); + throw new RestException(400, 'Payment error : '.$paymentobj->error); } if (!empty($conf->banque->enabled)) { $label = '(CustomerInvoicePayment)'; - if ($paiement->paiementcode == 'CHQ' && empty($chqemetteur)) { - throw new RestException(400, 'Emetteur is mandatory when payment code is '.$paiement->paiementcode); + if ($paymentobj->paiementcode == 'CHQ' && empty($chqemetteur)) { + throw new RestException(400, 'Emetteur is mandatory when payment code is '.$paymentobj->paiementcode); } if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE) $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note - $result = $paiement->addPaymentToBank(DolibarrApiAccess::$user, 'payment', $label, $accountid, $chqemetteur, $chqbank); + $result = $paymentobj->addPaymentToBank(DolibarrApiAccess::$user, 'payment', $label, $accountid, $chqemetteur, $chqbank); if ($result < 0) { $this->db->rollback(); - throw new RestException(400, 'Add payment to bank error : '.$paiement->error); + throw new RestException(400, 'Add payment to bank error : '.$paymentobj->error); } } $this->db->commit(); - return $paiement_id; + return $payment_id; } /** From fbc8fe1e0c0d49b42dea1d2fdb066708d46509fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Sat, 19 Sep 2020 15:14:29 +0200 Subject: [PATCH 07/38] Update api_invoices.class.php --- htdocs/compta/facture/class/api_invoices.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index e620d30e087..207bfef5c46 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -1510,8 +1510,8 @@ class Invoices extends DolibarrApi $paymentobj->multicurrency_amounts = $multicurrency_amounts; // Array with all payments dispatching $paymentobj->paiementid = $paymentid; $paymentobj->paiementcode = dol_getIdFromCode($this->db, $paymentid, 'c_paiement', 'id', 'code', 1); - $paymentobj->num_paiement = $num_payment; - $paymentobj->note = $comment; + $paymentobj->num_payment = $num_payment; + $paymentobj->note_private = $comment; $paymentobj->ref_ext = $ref_ext; $payment_id = $paymentobj->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices if ($payment_id < 0) From 90d2dfcca764dc4d304c12cd4c4b51638450eb63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Sat, 19 Sep 2020 22:01:48 +0200 Subject: [PATCH 08/38] FIX deleteContact --- .../compta/facture/class/api_invoices.class.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 207bfef5c46..400828998cb 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -502,10 +502,19 @@ class Invoices extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - $result = $this->invoice->delete_contact($rowid); - if ($result < 0) { - throw new RestException(500, 'Error when deleted the contact'); - } + $contacts = $this->invoice->liste_contact(); + + foreach ($contacts as $contact) { + if ($contact['id'] == $rowid) { + $result = $this->invoice->delete_contact($contact['rowid']); + + if (!$result) { + throw new RestException(500, 'Error when deleted the contact'); + } + + break; + } + } return $this->_cleanObjectDatas($this->invoice); } From 7306a949e3c37368c99d1e2eec1df6b087a569d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Sat, 19 Sep 2020 22:02:52 +0200 Subject: [PATCH 09/38] Update api_invoices.class.php --- htdocs/compta/facture/class/api_invoices.class.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 400828998cb..24c71d51cb4 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -511,8 +511,6 @@ class Invoices extends DolibarrApi if (!$result) { throw new RestException(500, 'Error when deleted the contact'); } - - break; } } From 3deed426717e04b8cde5dee9eb5b4314cc04cf56 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sat, 19 Sep 2020 20:05:08 +0000 Subject: [PATCH 10/38] Fixing style errors. --- htdocs/compta/facture/class/api_invoices.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 24c71d51cb4..7b19e95a974 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -503,11 +503,11 @@ class Invoices extends DolibarrApi } $contacts = $this->invoice->liste_contact(); - + foreach ($contacts as $contact) { if ($contact['id'] == $rowid) { $result = $this->invoice->delete_contact($contact['rowid']); - + if (!$result) { throw new RestException(500, 'Error when deleted the contact'); } From 68ccbac49c09362d9fe09b3bd28505c12268fc80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Sat, 19 Sep 2020 22:35:33 +0200 Subject: [PATCH 11/38] Update api_orders.class.php --- htdocs/commande/class/api_orders.class.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index f62c00ee81b..d89c2770f64 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -545,8 +545,9 @@ class Orders extends DolibarrApi * * @param int $id Id of order to update * @param int $rowid Row key of the contact in the array contact_ids. + * @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER). * - * @url DELETE {id}/contact/{rowid} + * @url DELETE {id}/contact/{rowid}/{type} * * @return int * @@ -554,7 +555,7 @@ class Orders extends DolibarrApi * @throws RestException 404 * @throws RestException 500 */ - public function deleteContact($id, $rowid) + public function deleteContact($id, $rowid, $type) { if (!DolibarrApiAccess::$user->rights->commande->creer) { throw new RestException(401); @@ -569,10 +570,16 @@ class Orders extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - $result = $this->commande->delete_linked_contact($rowid); + $contacts = $this->commande->liste_contact(); - if (!$result) { - throw new RestException(500, 'Error when deleted the contact'); + foreach ($contacts as $contact) { + if ($contact['id'] == $rowid && $contact['code'] == $type) { + $result = $this->commande->delete_contact($contact['rowid']); + + if (!$result) { + throw new RestException(500, 'Error when deleted the contact'); + } + } } return array( From a0313fdc52e6738d84938ecbd8f0f1270f899d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Sat, 19 Sep 2020 22:39:39 +0200 Subject: [PATCH 12/38] Update api_invoices.class.php --- htdocs/compta/facture/class/api_invoices.class.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 7b19e95a974..ab712a5f854 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -477,8 +477,9 @@ class Invoices extends DolibarrApi * * @param int $id Id of invoice to update * @param int $rowid Row key of the contact in the array contact_ids. + * @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER). * - * @url DELETE {id}/contact/{rowid} + * @url DELETE {id}/contact/{rowid}/{type} * * @return array * @@ -486,7 +487,7 @@ class Invoices extends DolibarrApi * @throws RestException 404 * @throws RestException 500 */ - public function deleteContact($id, $rowid) + public function deleteContact($id, $rowid, $type) { if (!DolibarrApiAccess::$user->rights->facture->creer) { throw new RestException(401); @@ -505,7 +506,7 @@ class Invoices extends DolibarrApi $contacts = $this->invoice->liste_contact(); foreach ($contacts as $contact) { - if ($contact['id'] == $rowid) { + if ($contact['id'] == $rowid && $contact['code'] == $type) { $result = $this->invoice->delete_contact($contact['rowid']); if (!$result) { From 2dc148eae002a0624c0607a5066f1c6c096379c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Tue, 22 Sep 2020 16:38:59 +0200 Subject: [PATCH 13/38] $accepthigherpayment (tested and work) Accept higher payments that it remains to be paid --- .../facture/class/api_invoices.class.php | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index ab712a5f854..3cbbabbed6e 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -1409,14 +1409,15 @@ class Invoices extends DolibarrApi * * @param array $arrayofamounts {@from body} Array with id of invoices with amount to pay for each invoice * @param string $datepaye {@from body} Payment date {@type timestamp} - * @param int $paymentid {@from body} Payment mode Id {@min 1} - * @param string $closepaidinvoices {@from body} Close paid invoices {@choice yes,no} - * @param int $accountid {@from body} Account Id {@min 1} - * @param string $num_payment {@from body} Payment number (optional) - * @param string $comment {@from body} Note private (optional) - * @param string $chqemetteur {@from body} Payment issuer (mandatory if paiementcode = 'CHQ') - * @param string $chqbank {@from body} Issuer bank name (optional) - * @param string $ref_ext {@from body} External reference (optional) + * @param int $paymentid {@from body} Payment mode Id {@min 1} + * @param string $closepaidinvoices {@from body} Close paid invoices {@choice yes,no} + * @param int $accountid {@from body} Account Id {@min 1} + * @param string $num_payment {@from body} Payment number (optional) + * @param string $comment {@from body} Note private (optional) + * @param string $chqemetteur {@from body} Payment issuer (mandatory if paiementcode = 'CHQ') + * @param string $chqbank {@from body} Issuer bank name (optional) + * @param string $ref_ext {@from body} External reference (optional) + * @param bool $accepthigherpayment {@from body} Accept higher payments that it remains to be paid (optional) * * @url POST /paymentsdistributed * @@ -1426,7 +1427,7 @@ class Invoices extends DolibarrApi * @throws RestException 403 * @throws RestException 404 */ - public function addPaymentDistributed($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment = '', $comment = '', $chqemetteur = '', $chqbank = '', $ref_ext = '') + public function addPaymentDistributed($arrayofamounts, $datepaye, $paymentid, $closepaidinvoices, $accountid, $num_payment = '', $comment = '', $chqemetteur = '', $chqbank = '', $ref_ext = '', $accepthigherpayment = false) { global $conf; @@ -1484,7 +1485,7 @@ class Invoices extends DolibarrApi $totalpaye = $this->invoice->getSommePaiement($is_multicurrency); $totalcreditnotes = $this->invoice->getSumCreditNotesUsed($is_multicurrency); $totaldeposits = $this->invoice->getSumDepositsUsed($is_multicurrency); - $amount = price2num($total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT'); + $remainstopay = $amount = price2num($total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT'); if (!$is_multicurrency && $amountarray["amount"] != 'remain') { @@ -1495,6 +1496,11 @@ class Invoices extends DolibarrApi { $amount = price2num($amountarray["multicurrency_amount"], 'MT'); } + + if ($amount > $remainstopay && $accepthigherpayment == false) { + $this->db->rollback(); + throw new RestException(400, 'Payment amount on invoice ID '.$id.' ('.$amount.') is higher than remain to pay ('.$remainstopay.')'); + } if ($this->invoice->type == Facture::TYPE_CREDIT_NOTE) { $amount = -$amount; From 06d41c029d4db5e50a9e500f201d2006946163e8 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 22 Sep 2020 14:41:28 +0000 Subject: [PATCH 14/38] Fixing style errors. --- htdocs/compta/facture/class/api_invoices.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 3cbbabbed6e..56f4e7f44ec 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -1496,7 +1496,7 @@ class Invoices extends DolibarrApi { $amount = price2num($amountarray["multicurrency_amount"], 'MT'); } - + if ($amount > $remainstopay && $accepthigherpayment == false) { $this->db->rollback(); throw new RestException(400, 'Payment amount on invoice ID '.$id.' ('.$amount.') is higher than remain to pay ('.$remainstopay.')'); From 3bc9c49307d1e2cfcc6e54d72c0ee277a26c4dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com> Date: Mon, 28 Sep 2020 16:57:30 +0200 Subject: [PATCH 15/38] Update api_orders.class.php --- htdocs/commande/class/api_orders.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index d89c2770f64..4c3def4b796 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -547,7 +547,7 @@ class Orders extends DolibarrApi * @param int $rowid Row key of the contact in the array contact_ids. * @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER). * - * @url DELETE {id}/contact/{rowid}/{type} + * @url DELETE {id}/contact/{contactid}/{type} * * @return int * @@ -555,7 +555,7 @@ class Orders extends DolibarrApi * @throws RestException 404 * @throws RestException 500 */ - public function deleteContact($id, $rowid, $type) + public function deleteContact($id, $contactid, $type) { if (!DolibarrApiAccess::$user->rights->commande->creer) { throw new RestException(401); @@ -573,7 +573,7 @@ class Orders extends DolibarrApi $contacts = $this->commande->liste_contact(); foreach ($contacts as $contact) { - if ($contact['id'] == $rowid && $contact['code'] == $type) { + if ($contact['id'] == $contactid && $contact['code'] == $type) { $result = $this->commande->delete_contact($contact['rowid']); if (!$result) { From 03ede719890d03f2f1a8665056bef35330800abc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 2 Oct 2020 16:15:24 +0200 Subject: [PATCH 16/38] Clean code --- htdocs/admin/system/modules.php | 16 ++++++++++++++++ htdocs/core/modules/modBom.class.php | 2 +- htdocs/core/modules/modCashDesk.class.php | 3 +-- htdocs/core/modules/modDeplacement.class.php | 2 +- htdocs/core/modules/modEmailCollector.class.php | 2 +- htdocs/core/modules/modMailing.class.php | 2 +- htdocs/core/modules/modMrp.class.php | 2 +- htdocs/core/modules/modProduct.class.php | 2 +- htdocs/core/modules/modRecruitment.class.php | 2 +- .../core/modules/modWebServicesClient.class.php | 2 +- 10 files changed, 25 insertions(+), 10 deletions(-) diff --git a/htdocs/admin/system/modules.php b/htdocs/admin/system/modules.php index c909084f1d6..28dcb6641ef 100644 --- a/htdocs/admin/system/modules.php +++ b/htdocs/admin/system/modules.php @@ -56,11 +56,13 @@ $arrayfields = array( 'name'=>array('label'=>$langs->trans("Modules"), 'checked'=>1, 'position'=>10), 'version'=>array('label'=>$langs->trans("Version"), 'checked'=>1, 'position'=>20), 'id'=>array('label'=>$langs->trans("IdModule"), 'checked'=>1, 'position'=>30), + 'module_position'=>array('label'=>$langs->trans("Position"), 'checked'=>1, 'position'=>35), 'permission'=>array('label'=>$langs->trans("IdPermissions"), 'checked'=>1, 'position'=>40) ); $arrayfields = dol_sort_array($arrayfields, 'position'); + /* * Actions */ @@ -129,6 +131,7 @@ foreach ($modules as $key=>$module) { $newModule->name = $module->getName(); $newModule->version = $module->getVersion(); $newModule->id = $key; + $newModule->module_position = $module->module_position; $alt = $module->name.' - '.$modules_files[$key]; @@ -223,6 +226,10 @@ if ($arrayfields['id']['checked']) { print ''; print ''; } +if ($arrayfields['module_position']['checked']) { + print ''; + print ''; +} if ($arrayfields['permission']['checked']) { print ''; print ''; @@ -247,6 +254,9 @@ if ($arrayfields['version']['checked']) { if ($arrayfields['id']['checked']) { print_liste_field_titre($arrayfields['id']['label'], $_SERVER["PHP_SELF"], "id", "", "", "", $sortfield, $sortorder); } +if ($arrayfields['module_position']['checked']) { + print_liste_field_titre($arrayfields['module_position']['label'], $_SERVER["PHP_SELF"], "module_position", "", "", "", $sortfield, $sortorder); +} if ($arrayfields['permission']['checked']) { print_liste_field_titre($arrayfields['permission']['label'], $_SERVER["PHP_SELF"], "permission", "", "", "", $sortfield, $sortorder); } @@ -273,6 +283,8 @@ if ($sortfield == "id" && $sortorder == "desc") usort($moduleList, "compareIdDes if ($sortfield == "permission" && $sortorder == "asc") usort($moduleList, "comparePermissionIdsAsc"); if ($sortfield == "permission" && $sortorder == "desc") usort($moduleList, "comparePermissionIdsDesc"); +$moduleList = dol_sort_array($moduleList, 'module_position'); + foreach ($moduleList as $module) { print ''; @@ -291,6 +303,10 @@ foreach ($moduleList as $module) { print ''.$module->id.''; } + if ($arrayfields['module_position']['checked']) { + print ''.$module->module_position.''; + } + if ($arrayfields['permission']['checked']) { $idperms = ''; diff --git a/htdocs/core/modules/modBom.class.php b/htdocs/core/modules/modBom.class.php index 7258541a7da..78b4efa1567 100644 --- a/htdocs/core/modules/modBom.class.php +++ b/htdocs/core/modules/modBom.class.php @@ -54,7 +54,7 @@ class modBom extends DolibarrModules // It is used to group modules by family in module setup page $this->family = "products"; // Module position in the family on 2 digits ('01', '10', '20', ...) - $this->module_position = '60'; + $this->module_position = '65'; // Gives the possibility for the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this) //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily"))); diff --git a/htdocs/core/modules/modCashDesk.class.php b/htdocs/core/modules/modCashDesk.class.php index b27a1ae30e4..2863760b138 100644 --- a/htdocs/core/modules/modCashDesk.class.php +++ b/htdocs/core/modules/modCashDesk.class.php @@ -46,12 +46,11 @@ class modCashDesk extends DolibarrModules $this->rights_class = 'cashdesk'; $this->family = "portal"; - $this->module_position = '55'; + $this->module_position = '59'; // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) $this->name = preg_replace('/^mod/i', '', get_class($this)); $this->description = "CashDesk module"; - $this->revision = '1.27'; $this->version = 'dolibarr'; $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); diff --git a/htdocs/core/modules/modDeplacement.class.php b/htdocs/core/modules/modDeplacement.class.php index d89aac28e98..349fde7eba7 100644 --- a/htdocs/core/modules/modDeplacement.class.php +++ b/htdocs/core/modules/modDeplacement.class.php @@ -45,7 +45,7 @@ class modDeplacement extends DolibarrModules $this->numero = 75; $this->family = "hr"; - $this->module_position = '41'; + $this->module_position = '43'; // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) $this->name = preg_replace('/^mod/i', '', get_class($this)); $this->description = "Gestion des notes de frais et deplacements"; // Si traduction Module75Desc non trouvee diff --git a/htdocs/core/modules/modEmailCollector.class.php b/htdocs/core/modules/modEmailCollector.class.php index 86bf582edf2..1e00f28d40f 100644 --- a/htdocs/core/modules/modEmailCollector.class.php +++ b/htdocs/core/modules/modEmailCollector.class.php @@ -52,7 +52,7 @@ class modEmailCollector extends DolibarrModules // It is used to group modules by family in module setup page $this->family = "interface"; // Module position in the family on 2 digits ('01', '10', '20', ...) - $this->module_position = '12'; + $this->module_position = '23'; // Gives the possibility to the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this) //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily"))); diff --git a/htdocs/core/modules/modMailing.class.php b/htdocs/core/modules/modMailing.class.php index ae475836bb5..3f410a1e3f2 100644 --- a/htdocs/core/modules/modMailing.class.php +++ b/htdocs/core/modules/modMailing.class.php @@ -48,7 +48,7 @@ class modMailing extends DolibarrModules // It is used to group modules by family in module setup page $this->family = "interface"; // Module position in the family on 2 digits ('01', '10', '20', ...) - $this->module_position = '11'; + $this->module_position = '22'; // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) $this->name = preg_replace('/^mod/i', '', get_class($this)); diff --git a/htdocs/core/modules/modMrp.class.php b/htdocs/core/modules/modMrp.class.php index 73df7523843..b7901e38fd7 100644 --- a/htdocs/core/modules/modMrp.class.php +++ b/htdocs/core/modules/modMrp.class.php @@ -52,7 +52,7 @@ class modMrp extends DolibarrModules // It is used to group modules by family in module setup page $this->family = "products"; // Module position in the family on 2 digits ('01', '10', '20', ...) - $this->module_position = '62'; + $this->module_position = '66'; // Gives the possibility for the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this) //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily"))); // Module label (no space allowed), used if translation string 'ModuleMrpName' not found (Mrp is name of module). diff --git a/htdocs/core/modules/modProduct.class.php b/htdocs/core/modules/modProduct.class.php index 5237f5f9b4b..e1a1a51160a 100644 --- a/htdocs/core/modules/modProduct.class.php +++ b/htdocs/core/modules/modProduct.class.php @@ -51,7 +51,7 @@ class modProduct extends DolibarrModules $this->numero = 50; $this->family = "products"; - $this->module_position = '25'; + $this->module_position = '26'; // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) $this->name = preg_replace('/^mod/i', '', get_class($this)); $this->description = "Product management"; diff --git a/htdocs/core/modules/modRecruitment.class.php b/htdocs/core/modules/modRecruitment.class.php index 6d994ac1071..8e282a9513d 100644 --- a/htdocs/core/modules/modRecruitment.class.php +++ b/htdocs/core/modules/modRecruitment.class.php @@ -52,7 +52,7 @@ class modRecruitment extends DolibarrModules // It is used to group modules by family in module setup page $this->family = "hr"; // Module position in the family on 2 digits ('01', '10', '20', ...) - $this->module_position = '51'; + $this->module_position = '44'; // Gives the possibility for the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this) //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily"))); // Module label (no space allowed), used if translation string 'ModuleRecruitmentName' not found (Recruitment is name of module). diff --git a/htdocs/core/modules/modWebServicesClient.class.php b/htdocs/core/modules/modWebServicesClient.class.php index d61052c0e1b..720a756a828 100644 --- a/htdocs/core/modules/modWebServicesClient.class.php +++ b/htdocs/core/modules/modWebServicesClient.class.php @@ -41,7 +41,7 @@ class modWebServicesClient extends DolibarrModules $this->numero = 2660; $this->family = "interface"; - $this->module_position = '26'; + $this->module_position = '25'; // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) $this->name = preg_replace('/^mod/i', '', get_class($this)); $this->description = "Enable the web service client to call external supplier web services"; From 1a535dc77bc6238b5af0e73137772e2e3e597a2d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 2 Oct 2020 19:00:15 +0200 Subject: [PATCH 17/38] Clean code --- htdocs/core/boxes/modules_boxes.php | 23 ---------------------- htdocs/core/class/html.formother.class.php | 8 ++++---- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/htdocs/core/boxes/modules_boxes.php b/htdocs/core/boxes/modules_boxes.php index 80589e4c4f3..fd179dec7b6 100644 --- a/htdocs/core/boxes/modules_boxes.php +++ b/htdocs/core/boxes/modules_boxes.php @@ -170,29 +170,6 @@ class ModeleBoxes // Can't be abtract as it is instantiated to build "empty" box } } - - /** - * Standard method to get content of a box - * - * @param array $head Array with properties of box title - * @param array $contents Array with properties of box lines - * - * @return string - */ - public function outputBox($head = null, $contents = null) - { - global $langs, $user, $conf; - - // Trick to get result into a var from a function that makes print instead of return - // TODO Replace ob_start with param nooutput=1 into showBox - ob_start(); - $result = $this->showBox($head, $contents); - $output = ob_get_contents(); - ob_end_clean(); - - return $output; - } - /** * Standard method to show a box (usage by boxes not mandatory, a box can still use its own showBox function) * diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index dc55d0931f7..a6c458fc67b 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -1162,7 +1162,7 @@ class FormOther //print 'box_order '.$boxactivated[$ii]->box_order.'
'; // Show box $box->loadBox($box_max_lines); - $boxlista .= $box->outputBox(); + $boxlista .= $box->showBox(null, null, 1); } } @@ -1171,7 +1171,7 @@ class FormOther $emptybox->box_id = 'A'; $emptybox->info_box_head = array(); $emptybox->info_box_contents = array(); - $boxlista .= $emptybox->outputBox(array(), array()); + $boxlista .= $emptybox->showBox(array(), array(), 1); } $boxlista .= "\n"; @@ -1189,7 +1189,7 @@ class FormOther //print 'box_order '.$boxactivated[$ii]->box_order.'
'; // Show box $box->loadBox($box_max_lines); - $boxlistb .= $box->outputBox(); + $boxlistb .= $box->showBox(null, null, 1); } } @@ -1198,7 +1198,7 @@ class FormOther $emptybox->box_id = 'B'; $emptybox->info_box_head = array(); $emptybox->info_box_contents = array(); - $boxlistb .= $emptybox->outputBox(array(), array()); + $boxlistb .= $emptybox->showBox(array(), array(), 1); } $boxlistb .= "\n"; From 50ca9f4145754e679f635c7934713a137b02ff24 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 2 Oct 2020 19:10:30 +0200 Subject: [PATCH 18/38] Clean code --- htdocs/core/lib/admin.lib.php | 5 ++- .../product/inventory/lib/inventory.lib.php | 45 ------------------- htdocs/takepos/send.php | 2 + 3 files changed, 6 insertions(+), 46 deletions(-) diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 9227d9a1cfd..038b4be27a6 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -1689,8 +1689,11 @@ function phpinfo_array() { ob_start(); phpinfo(); + $phpinfostring = ob_get_contents(); + ob_end_clean(); + $info_arr = array(); - $info_lines = explode("\n", strip_tags(ob_get_clean(), "

")); // end of ob_start() + $info_lines = explode("\n", strip_tags($phpinfostring, "

")); $cat = "General"; foreach ($info_lines as $line) { diff --git a/htdocs/product/inventory/lib/inventory.lib.php b/htdocs/product/inventory/lib/inventory.lib.php index da2b626ab5c..47fa1e53510 100644 --- a/htdocs/product/inventory/lib/inventory.lib.php +++ b/htdocs/product/inventory/lib/inventory.lib.php @@ -73,48 +73,3 @@ function inventoryPrepareHead(&$inventory, $title = 'Inventory', $get = '') array(dol_buildpath('/product/inventory/inventory.php?id='.$inventory->id.$get, 1), $langs->trans('Inventory'), 'inventory') ); } - - - -/** - * Define head array for tabs of inventory tools setup pages - * - * @param Inventory $inventory Object inventory - * - * @return string html of products - */ -function inventorySelectProducts(&$inventory) -{ - global $conf, $db, $langs; - - $except_product_id = array(); - - foreach ($inventory->Inventorydet as $Inventorydet) - { - $except_product_id[] = $Inventorydet->fk_product; - } - - ob_start(); - $form = new Form($db); - $form->select_produits(-1, 'fk_product'); - - $TChildWarehouses = array($inventory->fk_warehouse); - $e = new Entrepot($db); - $e->fetch($inventory->fk_warehouse); - if (method_exists($e, 'get_children_warehouses')) $e->get_children_warehouses($e->id, $TChildWarehouses); - - $Tab = array(); - $sql = 'SELECT rowid, label - FROM '.MAIN_DB_PREFIX.'entrepot WHERE rowid IN('.implode(', ', $TChildWarehouses).')'; - if (method_exists($e, 'get_children_warehouses')) $sql .= ' ORDER BY fk_parent'; - $resql = $db->query($sql); - while ($res = $db->fetch_object($resql)) { - $Tab[$res->rowid] = $res->label; - } - print '   '; - print $langs->trans('Warehouse').' : '.$form::selectarray('fk_warehouse', $Tab); - - $select_html = ob_get_clean(); - - return $select_html; -} diff --git a/htdocs/takepos/send.php b/htdocs/takepos/send.php index ba1e3f5e5ad..f618b260db1 100644 --- a/htdocs/takepos/send.php +++ b/htdocs/takepos/send.php @@ -60,10 +60,12 @@ if ($action=="send") $model_id = $conf->global->TAKEPOS_EMAIL_TEMPLATE_INVOICE; $arraydefaultmessage = $formmail->getEMailTemplate($db, 'facture_send', $user, $outputlangs, $model_id); $subject = $arraydefaultmessage->topic; + ob_start(); // turn on output receipt include 'receipt.php'; $receipt = ob_get_contents(); // get the contents of the output buffer ob_end_clean(); + $msg="".$arraydefaultmessage->content."
".$receipt.""; $sendto=$email; $from=$mysoc->email; From c2fed95dc4b894b3ee96b7a556020c19642d7e92 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 2 Oct 2020 19:54:06 +0200 Subject: [PATCH 19/38] FIX #14877 --- htdocs/admin/dict.php | 11 +++-------- htdocs/expedition/stats/index.php | 8 ++++++-- htdocs/install/mysql/migration/repair.sql | 1 + 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 1ac1e0f4ad4..e40a84db0ec 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -91,11 +91,7 @@ $hookmanager->initHooks(array('admin')); // Put here declaration of dictionaries properties // Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this. -if (! empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES)) { - $taborder = array(9, 0, 4, 3, 2, 0, 1, 8, 19, 16, 39, 27, 40, 38, 0, 5, 11, 0, 32, 33, 34, 0, 6, 0, 29, 0, 7, 24, 28, 17, 35, 36, 0, 10, 23, 12, 13, 0, 14, 0, 22, 20, 18, 21, 0, 15, 30, 0, 37, 0, 25, 0); -} else { - $taborder = array(9, 0, 4, 3, 2, 0, 1, 8, 19, 16, 27, 38, 0, 5, 11, 0, 32, 33, 34, 0, 6, 0, 29, 0, 7, 24, 28, 17, 35, 36, 0, 10, 23, 12, 13, 0, 14, 0, 22, 20, 18, 21, 0, 15, 30, 0, 37, 0, 25, 0); -} +$taborder = array(9, 0, 4, 3, 2, 0, 1, 8, 19, 16, 39, 27, 40, 38, 0, 5, 11, 0, 32, 33, 34, 0, 6, 0, 29, 0, 7, 24, 28, 17, 35, 36, 0, 10, 23, 12, 13, 0, 14, 0, 22, 20, 18, 21, 0, 15, 30, 0, 37, 0, 25, 0); // Name of SQL tables of dictionaries $tabname = array(); @@ -133,7 +129,6 @@ $tabname[30] = MAIN_DB_PREFIX."c_format_cards"; $tabname[32] = MAIN_DB_PREFIX."c_hrm_public_holiday"; $tabname[33] = MAIN_DB_PREFIX."c_hrm_department"; $tabname[34] = MAIN_DB_PREFIX."c_hrm_function"; - $tabname[35] = MAIN_DB_PREFIX."c_exp_tax_cat"; $tabname[36] = MAIN_DB_PREFIX."c_exp_tax_range"; $tabname[37] = MAIN_DB_PREFIX."c_units"; @@ -485,8 +480,8 @@ $tabcond[35] = !empty($conf->expensereport->enabled); $tabcond[36] = !empty($conf->expensereport->enabled); $tabcond[37] = !empty($conf->product->enabled); $tabcond[38] = !empty($conf->socialnetworks->enabled); -$tabcond[39] = (! empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)); -$tabcond[40] = ! empty($conf->societe->enabled); +$tabcond[39] = (!empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && !empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES)); +$tabcond[40] = (!empty($conf->societe->enabled) && !empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES)); // List of help for fields $tabhelp = array(); diff --git a/htdocs/expedition/stats/index.php b/htdocs/expedition/stats/index.php index fcccb545a33..9521cd46d10 100644 --- a/htdocs/expedition/stats/index.php +++ b/htdocs/expedition/stats/index.php @@ -269,8 +269,12 @@ foreach ($data as $val) print ''; print ''; - if ($year) print ''.$year.''; - else print $langs->trans("ValidationDateNotDefinedEvenIfShipmentValidated"); + if ($year) { + print ''.$year.''; + } else { + // Technical error that should not happen + print 'Error: validation date of shipment is not defined. This looks strange because shipment is validated. Try to run /install/repair.php?standard=confirmed'; + } print ''; print ''.$val['nb'].''; /*print ''.price(price2num($val['total'],'MT'),1).''; diff --git a/htdocs/install/mysql/migration/repair.sql b/htdocs/install/mysql/migration/repair.sql index aa5ab65d3ff..c9c916ed3ad 100644 --- a/htdocs/install/mysql/migration/repair.sql +++ b/htdocs/install/mysql/migration/repair.sql @@ -383,6 +383,7 @@ delete from llx_commande_fournisseur_dispatch where fk_commandefourndet = 0 or f delete from llx_menu where menu_handler = 'smartphone'; update llx_expedition set date_valid = date_creation where fk_statut = 1 and date_valid IS NULL; +update llx_expedition set date_valid = NOW() where fk_statut = 1 and date_valid IS NULL; -- Detect bad consistency between duraction_effective of a task and sum of time of tasks -- select pt.rowid, pt.duration_effective, SUM(ptt.task_duration) as y from llx_projet_task as pt, llx_projet_task_time as ptt where ptt.fk_task = pt.rowid group by pt.rowid, pt.duration_effective having pt.duration_effective <> y; From 1c34868028b6aa14a2446d32174c9b7b5d2f9696 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Oct 2020 11:16:31 +0200 Subject: [PATCH 20/38] Fix field must be null because there is no numbering ref module yet --- htdocs/install/mysql/migration/12.0.0-13.0.0.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql index ffce6b110dc..88c17cc0619 100644 --- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql +++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql @@ -30,6 +30,9 @@ -- Missing in v12 or lower +ALTER TABLE llx_payment_salary MODIFY COLUMN ref varchar(30) NULL; +ALTER TABLE llx_payment_various MODIFY COLUMN ref varchar(30) NULL; + ALTER TABLE llx_prelevement_bons ADD COLUMN type varchar(16) DEFAULT 'debit-order'; ALTER TABLE llx_prelevement_facture_demande ADD INDEX idx_prelevement_facture_demande_fk_facture (fk_facture); From 272b98faab625861a81a8fa382280dd4c4b7ccac Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Oct 2020 11:31:56 +0200 Subject: [PATCH 21/38] FIX #14901 --- htdocs/fichinter/card.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index 5359d64fbca..404955f8ef4 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -482,7 +482,7 @@ if (empty($reshook)) // Add line elseif ($action == "addline" && $user->rights->ficheinter->creer) { - if (!GETPOST('np_desc', 'none') && empty($conf->global->FICHINTER_EMPTY_LINE_DESC)) + if (!GETPOST('np_desc', 'restricthtml') && empty($conf->global->FICHINTER_EMPTY_LINE_DESC)) { $mesg = '
'.$langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")).'
'; $error++; @@ -501,7 +501,7 @@ if (empty($reshook)) { $db->begin(); - $desc = GETPOST('np_desc', 'none'); + $desc = GETPOST('np_desc', 'restricthtml'); $date_intervention = dol_mktime(GETPOST('dihour', 'int'), GETPOST('dimin', 'int'), 0, GETPOST('dimonth', 'int'), GETPOST('diday', 'int'), GETPOST('diyear', 'int')); $duration = empty($conf->global->FICHINTER_WITHOUT_DURATION) ?convertTime2Seconds(GETPOST('durationhour', 'int'), GETPOST('durationmin', 'int')) : 0; @@ -609,7 +609,7 @@ if (empty($reshook)) } $object->fetch_thirdparty(); - $desc = GETPOST('np_desc', 'alpha'); + $desc = GETPOST('np_desc', 'restricthtml'); $date_inter = dol_mktime(GETPOST('dihour', 'int'), GETPOST('dimin', 'int'), 0, GETPOST('dimonth', 'int'), GETPOST('diday', 'int'), GETPOST('diyear', 'int')); $duration = convertTime2Seconds(GETPOST('durationhour', 'int'), GETPOST('durationmin', 'int')); @@ -1537,7 +1537,7 @@ elseif ($id > 0 || !empty($ref)) // editeur wysiwyg if (empty($conf->global->FICHINTER_EMPTY_LINE_DESC)) { require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor = new DolEditor('np_desc', GETPOST('np_desc', 'alpha'), '', 100, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_DETAILS, ROWS_2, '90%'); + $doleditor = new DolEditor('np_desc', GETPOST('np_desc', 'restricthtml'), '', 100, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_DETAILS, ROWS_2, '90%'); $doleditor->Create(); } print ''; From 581a3d8808bceae7846f649aaf5d3fa1a247ce81 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Oct 2020 14:02:53 +0200 Subject: [PATCH 22/38] FIX Add a better message when file size is too large --- htdocs/core/class/html.formfile.class.php | 3 ++ htdocs/core/lib/functions.lib.php | 42 +++++++++++++++++++++++ htdocs/document.php | 7 ++-- htdocs/main.inc.php | 16 ++++++--- 4 files changed, 61 insertions(+), 7 deletions(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 7264c83b152..2b98bac30c6 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -114,6 +114,9 @@ class FormFile if (empty($usewithoutform)) // Try to avoid this and set instead the form by the caller. { + // Add a param as GET parameter to detect when POST were cleaned by PHP because a file larger than post_max_size + $url .= (strpos('?', $url) === false ? '?' : '&').'uploadform=1'; + $out .= '
'; $out .= ''; $out .= ''; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 4fe156b249b..25b67455d70 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -8919,3 +8919,45 @@ function addSummaryTableLine($tableColumnCount, $num, $nbofloop = 0, $total = 0, print ''; } + +/** + * Return a file on output using a lo memory. + * It can return very large files with no need of memory. + * + * @param string $fullpath_original_file_osencoded Full path of file to return. + * @param int $method -1 automatic, 0=readfile, 1=fread, 2=stream_copy_to_stream + */ +function readfileLowMemory($fullpath_original_file_osencoded, $method = -1) +{ + global $conf; + + if ($method == -1) { + $method = 0; + if (! empty($conf->global->MAIN_FORCE_READFILE_WITH_FREAD)) $method = 1; + if (! empty($conf->global->MAIN_FORCE_READFILE_WITH_STREAM_COPY)) $method = 2; + } + + // Solution 0 + if ($method == 0) { + // Be sure we don't have output buffering enabled to have readfile working correctly + while (ob_get_level()) ob_end_flush(); + + readfile($fullpath_original_file_osencoded); + } + // Solution 1 + elseif ($method == 1) { + $handle = fopen($fullpath_original_file_osencoded, "rb"); + while (!feof($handle)) { + print fread($handle, 8192); + } + fclose($handle); + } + // Solution 2 + elseif ($method == 2) { + $handle1 = fopen($fullpath_original_file_osencoded, "rb"); + $handle2 = fopen("php://output", "wb"); + stream_copy_to_stream($handle1, $handle2); + fclose($handle1); + fclose($handle2); + } +} diff --git a/htdocs/document.php b/htdocs/document.php index ab3ad20a8f8..bc0cc1eb933 100644 --- a/htdocs/document.php +++ b/htdocs/document.php @@ -261,10 +261,11 @@ if (!$attachment && !empty($conf->global->MAIN_USE_EXIF_ROTATION) && image_forma $readfile = !$imgres; } +if (is_object($db)) $db->close(); + +// Send file now if ($readfile) { header('Content-Length: '.dol_filesize($fullpath_original_file)); - readfile($fullpath_original_file_osencoded); + readfileLowMemory($fullpath_original_file_osencoded); } - -if (is_object($db)) $db->close(); diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 1344287044e..ef7b5e33a7d 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -378,10 +378,18 @@ if ((!defined('NOCSRFCHECK') && empty($dolibarr_nocsrfcheck) && !empty($conf->gl in_array(GETPOST('action', 'aZ09'), array('add', 'addtimespent', 'update', 'install', 'delete', 'deleteprof', 'deletepayment'))) { if (!GETPOSTISSET('token')) { - dol_syslog("--- Access to ".$_SERVER["PHP_SELF"]." refused by CSRFCHECK_WITH_TOKEN protection. Token not provided."); - print "Access to this page this way (POST method or page with CSRFCHECK_WITH_TOKEN on or having a sensible value for action parameter) is refused by CSRF protection in main.inc.php. Token not provided.\n"; - print "If you access your server behind a proxy using url rewriting, you might check that all HTTP header is propagated (or add the line \$dolibarr_nocsrfcheck=1 into your conf.php file or MAIN_SECURITY_CSRF_WITH_TOKEN to 0 into setup).\n"; - die; + if (GETPOST('uploadform')) { + dol_syslog("--- Access to ".$_SERVER["PHP_SELF"]." refused. File size too large."); + $langs->loadLangs(array("errors", "install")); + print $langs->trans("ErrorFileSizeTooLarge").' '; + print $langs->trans("ErrorGoBackAndCorrectParameters"); + die; + } else { + dol_syslog("--- Access to ".$_SERVER["PHP_SELF"]." refused by CSRFCHECK_WITH_TOKEN protection. Token not provided."); + print "Access to this page this way (POST method or page with CSRFCHECK_WITH_TOKEN on or having a sensible value for action parameter) is refused by CSRF protection in main.inc.php. Token not provided.\n"; + print "If you access your server behind a proxy using url rewriting, you might check that all HTTP header is propagated (or add the line \$dolibarr_nocsrfcheck=1 into your conf.php file or MAIN_SECURITY_CSRF_WITH_TOKEN to 0 into setup).\n"; + die; + } } } From 3b34c496ccb60bf69119892a61efac4f92f8415d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Oct 2020 14:11:47 +0200 Subject: [PATCH 23/38] Code --- htdocs/core/lib/functions.lib.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 25b67455d70..e7a80627636 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -8923,6 +8923,7 @@ function addSummaryTableLine($tableColumnCount, $num, $nbofloop = 0, $total = 0, /** * Return a file on output using a lo memory. * It can return very large files with no need of memory. + * WARNING: This close output buffers. * * @param string $fullpath_original_file_osencoded Full path of file to return. * @param int $method -1 automatic, 0=readfile, 1=fread, 2=stream_copy_to_stream @@ -8937,11 +8938,11 @@ function readfileLowMemory($fullpath_original_file_osencoded, $method = -1) if (! empty($conf->global->MAIN_FORCE_READFILE_WITH_STREAM_COPY)) $method = 2; } + // Be sure we don't have output buffering enabled to have readfile working correctly + while (ob_get_level()) ob_end_flush(); + // Solution 0 if ($method == 0) { - // Be sure we don't have output buffering enabled to have readfile working correctly - while (ob_get_level()) ob_end_flush(); - readfile($fullpath_original_file_osencoded); } // Solution 1 From 5ed7b43214e26d6d658706de50bfe10eb853813f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Oct 2020 14:48:19 +0200 Subject: [PATCH 24/38] phpcs --- htdocs/core/tpl/objectline_edit.tpl.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index e735a047878..245f4578043 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -305,21 +305,21 @@ if (!empty($extrafields)) rights->margins->creer) { -?> + ?> /* Some js test when we click on button "Add" */ jQuery(document).ready(function() { global->DISPLAY_MARGIN_RATES)) { ?> - $("input[name='np_marginRate']:first").blur(function(e) { - return checkFreeLine(e, "np_marginRate"); - }); - global->DISPLAY_MARK_RATES)) { ?> - $("input[name='np_markRate']:first").blur(function(e) { - return checkFreeLine(e, "np_markRate"); - }); - }); @@ -369,7 +369,7 @@ if (! empty($usemargins) && $user->rights->margins->creer) return true; } - From 9b3cd421eee486446733579689eeb68d6e4ba6f2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 3 Oct 2020 14:56:04 +0200 Subject: [PATCH 25/38] Fix doc --- htdocs/core/lib/functions.lib.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index e7a80627636..3af3f7c2562 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -8927,6 +8927,7 @@ function addSummaryTableLine($tableColumnCount, $num, $nbofloop = 0, $total = 0, * * @param string $fullpath_original_file_osencoded Full path of file to return. * @param int $method -1 automatic, 0=readfile, 1=fread, 2=stream_copy_to_stream + * @return void */ function readfileLowMemory($fullpath_original_file_osencoded, $method = -1) { From 017d4946fe312462a5bbd24712db8a66e95bf400 Mon Sep 17 00:00:00 2001 From: "jove@bisquerra.com" Date: Sat, 3 Oct 2020 22:13:32 +0200 Subject: [PATCH 26/38] NEW: TakePOS Multicurrency compatibility --- htdocs/takepos/index.php | 52 +++++++++++++++++++++++++++++--------- htdocs/takepos/invoice.php | 11 +++++++- htdocs/takepos/receipt.php | 11 ++++++++ 3 files changed, 61 insertions(+), 13 deletions(-) diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index bad5f112d21..111ae5fa4ad 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -44,6 +44,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : 0); // $place is id of table for Bar or Restaurant or multiple sales $action = GETPOST('action', 'aZ09'); $setterminal = GETPOST('setterminal', 'int'); +$setcurrency = GETPOST('setcurrency', 'aZ09'); if ($_SESSION["takeposterminal"] == "") { @@ -57,6 +58,11 @@ if ($setterminal > 0) setcookie("takeposterminal", $setterminal, (time() + (86400 * 354)), '/', null, false, true); // Permanent takeposterminal var in a cookie } +if ($setcurrency!="") +{ + $_SESSION["takeposcustomercurrency"] = $setcurrency; +} + $_SESSION["urlfrom"] = '/takepos/index.php'; $langs->loadLangs(array("bills", "orders", "commercial", "cashdesk", "receiptprinter", "banks")); @@ -725,14 +731,10 @@ function CashReport(rowid) $.colorbox({href:"../compta/cashcontrol/report.php?id="+rowid+"&contextpage=takepos", width:"60%", height:"90%", transition:"none", iframe:"true", title:"trans("CashReport"); ?>"}); } -// Popup to select the terminal to use -function TerminalsDialog() +// TakePOS Popup +function ModalBox(ModalID) { - var modal = document.getElementById("ModalTerminal"); - var span = document.getElementsByClassName("close")[0]; - span.onclick = function() { - modal.style.display = "none"; - } + var modal = document.getElementById(ModalID); modal.style.display = "block"; } @@ -767,7 +769,7 @@ $( document ).ready(function() { //IF NO TERMINAL SELECTED if ($_SESSION["takeposterminal"] == "") { - print "TerminalsDialog();"; + print "ModalBox('ModalTerminal');"; } if ($conf->global->TAKEPOS_CONTROL_CASH_OPENING) { @@ -798,7 +800,7 @@ if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {
@@ -841,7 +849,7 @@ if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) { + +
diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index f560fee0b44..d3ec86a7268 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -1090,7 +1090,16 @@ if ($placeid > 0) } else $htmlforlines .= $line->qty; $htmlforlines .= ''; - $htmlforlines .= ''.price($line->total_ttc).''; + $htmlforlines .= ''; + $htmlforlines .= price($line->total_ttc); + if (!empty($conf->multicurrency->enabled) && $_SESSION["takeposcustomercurrency"]!="" && $conf->currency!=$_SESSION["takeposcustomercurrency"]) { + //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency + include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php'; + $multicurrency = new MultiCurrency($db); + $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]); + $htmlforlines .= ' ('.price($line->total_ttc*$multicurrency->rate->rate).' '.$_SESSION["takeposcustomercurrency"].')'; + } + $htmlforlines .= ''; } $htmlforlines .= ''."\n"; $htmlforlines .= $htmlsupplements[$line->id]; diff --git a/htdocs/takepos/receipt.php b/htdocs/takepos/receipt.php index c7ca395a316..2bf24aa0cd3 100644 --- a/htdocs/takepos/receipt.php +++ b/htdocs/takepos/receipt.php @@ -182,6 +182,17 @@ if ($conf->global->TAKEPOS_SHOW_CUSTOMER) trans("TotalTTC").''.price($object->total_ttc, 1, '', 1, - 1, - 1, $conf->currency)."\n"; ?> multicurrency->enabled) && $_SESSION["takeposcustomercurrency"]!="" && $conf->currency!=$_SESSION["takeposcustomercurrency"]) { + //Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency + include_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php'; + $multicurrency = new MultiCurrency($db); + $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]); + echo ''; + if ($gift!=1) echo ''.$langs->trans("TotalTTC").' '.$_SESSION["takeposcustomercurrency"].''.price($object->total_ttc*$multicurrency->rate->rate, 1, '', 1, - 1, - 1, $_SESSION["takeposcustomercurrency"])."\n"; + //if ($gift!=1) echo ''.$langs->trans("TotalTTC").''.price($line->total_ttc*$multicurrency->rate->rate).' '.$_SESSION["takeposcustomercurrency"]."\n"; + echo ''; +} + if ($conf->global->TAKEPOS_PRINT_PAYMENT_METHOD) { $sql = "SELECT p.pos_change as pos_change, p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,"; $sql .= " cp.code"; From 18cd8703078e490bb4adc1279a46668750a66dcf Mon Sep 17 00:00:00 2001 From: andreubisquerra Date: Sat, 3 Oct 2020 22:31:55 +0200 Subject: [PATCH 27/38] Fix travis --- htdocs/takepos/index.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index 111ae5fa4ad..603749208d2 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -874,13 +874,13 @@ if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) { From d43d1e851910d24e50981f73baa6ca929cccec6f Mon Sep 17 00:00:00 2001 From: andreubisquerra Date: Sat, 3 Oct 2020 23:03:08 +0200 Subject: [PATCH 28/38] Clean --- htdocs/takepos/receipt.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/takepos/receipt.php b/htdocs/takepos/receipt.php index 2bf24aa0cd3..f32e4d82061 100644 --- a/htdocs/takepos/receipt.php +++ b/htdocs/takepos/receipt.php @@ -189,7 +189,6 @@ if (!empty($conf->multicurrency->enabled) && $_SESSION["takeposcustomercurrency" $multicurrency->fetch(0, $_SESSION["takeposcustomercurrency"]); echo ''; if ($gift!=1) echo ''.$langs->trans("TotalTTC").' '.$_SESSION["takeposcustomercurrency"].''.price($object->total_ttc*$multicurrency->rate->rate, 1, '', 1, - 1, - 1, $_SESSION["takeposcustomercurrency"])."\n"; - //if ($gift!=1) echo ''.$langs->trans("TotalTTC").''.price($line->total_ttc*$multicurrency->rate->rate).' '.$_SESSION["takeposcustomercurrency"]."\n"; echo ''; } From 4c64b992350614f0c89689ac36fd441a2873c2b9 Mon Sep 17 00:00:00 2001 From: andreubisquerra Date: Sat, 3 Oct 2020 23:16:13 +0200 Subject: [PATCH 29/38] Lang fix --- htdocs/takepos/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index 603749208d2..dd96a8ae333 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -869,7 +869,7 @@ if (empty($conf->global->TAKEPOS_HIDE_HEAD_BAR)) {