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 01/11] 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 02/11] 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 03/11] 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 04/11] 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 05/11] 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 06/11] 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 07/11] 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 08/11] 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 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 09/11] 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 10/11] $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 11/11] 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.')');