From e513ed09f68e61f758b8a01ac88cf15f706faf28 Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Tue, 14 Nov 2017 14:43:50 +0100 Subject: [PATCH 01/17] Change the way pa_ht is calculated --- htdocs/compta/facture/class/api_invoices.class.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index eccc537b3b3..d25c4542929 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -452,6 +452,9 @@ class Invoices extends DolibarrApi $request_data->fk_parent_line = 0; } + // calculate pa_ht + $marginInfos = getMarginInfos($request_data->subprice, $request_data->remise_percent, $request_data->tva_tx, $request_data->localtax1_tx, $request_data->localtax2_tx, $request_data->fk_fournprice, $request_data->pa_ht); + $updateRes = $this->invoice->addline( $request_data->desc, $request_data->subprice, @@ -475,7 +478,7 @@ class Invoices extends DolibarrApi $id, $request_data->fk_parent_line, $request_data->fk_fournprice, - $request_data->pa_ht, + $marginInfos[0], $request_data->label, $request_data->array_options, $request_data->situation_percent, From 9b2611933d0368fe9ac16bae8eacd1af144d0ce7 Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Tue, 14 Nov 2017 15:49:09 +0100 Subject: [PATCH 02/17] NEW Create an invoice using an existing order Create an invoice using an existing order using the REST API --- .../facture/class/api_invoices.class.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index d25c4542929..115080811e6 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -217,6 +217,48 @@ class Invoices extends DolibarrApi return $this->invoice->id; } + /** + * Create an invoice using an existing order. + * + * + * @param int $orderid Id of the order + * + * @url POST /createfromorder/{orderid} + * + * @return int + * @throws 400 + * @throws 401 + * @throws 404 + * @throws 405 + */ + function createInvoiceFromOrder($orderid) { + + require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php'; + + if(! DolibarrApiAccess::$user->rights->commande->lire) { + throw new RestException(401); + } + if(! DolibarrApiAccess::$user->rights->facture->creer) { + throw new RestException(401); + } + if(empty($orderid)) { + throw new RestException(400, 'Order ID is mandatory'); + } + + $order = new Commande($this->db); + $result = $order->fetch($orderid); + if( ! $result ) { + throw new RestException(404, 'Order not found'); + } + + $result = $this->invoice->createFromOrder($order, DolibarrApiAccess::$user); + if( $result < 0) { + throw new RestException(405, $this->invoice->error); + } + $this->invoice->fetchObjectLinked(); + return $this->_cleanObjectDatas($this->invoice); + } + /** * Get lines of an invoice * From 42d1072dee1b3d8a74643ad5139906c82287229e Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Wed, 15 Nov 2017 10:55:39 +0100 Subject: [PATCH 03/17] NEW Tag the order as validated (opened) in the REST API Tag the order as validated (opened) --- htdocs/commande/class/api_orders.class.php | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index e5228185657..eb6e7f82532 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -511,6 +511,45 @@ class Orders extends DolibarrApi return $this->_cleanObjectDatas($this->commande); } + /** + * Tag the order as validated (opened) + * + * Function used when order is reopend after being closed. + * + * @param int $id Id of the order + * + * @url POST {id}/reopen + * + * @return int + * + * @throws 304 + * @throws 400 + * @throws 401 + * @throws 404 + * @throws 405 + */ + function reopen($id) { + + if(! DolibarrApiAccess::$user->rights->commande->creer) { + throw new RestException(401); + } + if(empty($id)) { + throw new RestException(400, 'Order ID is mandatory'); + } + $result = $this->commande->fetch($orderid); + if( ! $result ) { + throw new RestException(404, 'Order not found'); + } + + $result = $this->commande->set_reopen(DolibarrApiAccess::$user); + if( $result < 0) { + throw new RestException(405, $this->commande->error); + }else if( $result == 0) { + throw new RestException(304); + } + return $result; + } + /** * Close an order (Classify it as "Delivered") * From d97cf63a16f5f9ab7ea8bf1a34de369936b4ea2c Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Wed, 15 Nov 2017 12:14:28 +0100 Subject: [PATCH 04/17] NEW Classify the order as invoiced in the REST API Classify the order as invoiced FIX variable name --- htdocs/commande/class/api_orders.class.php | 38 +++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index eb6e7f82532..3dd19a030a0 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -536,7 +536,7 @@ class Orders extends DolibarrApi if(empty($id)) { throw new RestException(400, 'Order ID is mandatory'); } - $result = $this->commande->fetch($orderid); + $result = $this->commande->fetch($id); if( ! $result ) { throw new RestException(404, 'Order not found'); } @@ -550,6 +550,42 @@ class Orders extends DolibarrApi return $result; } + + /** + * Classify the order as invoiced + * + * @param int $id Id of the order + * @param int $notrigger {@from body} 1=Does not execute triggers, 0= execute triggers {@choice 0,1} + * + * @url POST {id}/setinvoiced + * + * @return int + * + * @throws 400 + * @throws 401 + * @throws 404 + * @throws 405 + */ + function setinvoiced($id,$notrigger=0) { + + if(! DolibarrApiAccess::$user->rights->commande->creer) { + throw new RestException(401); + } + if(empty($id)) { + throw new RestException(400, 'Order ID is mandatory'); + } + $result = $this->commande->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Order not found'); + } + + $result = $this->commande->classifyBilled(DolibarrApiAccess::$user,$notrigger); + if( $result < 0) { + throw new RestException(400, $this->commande->error); + } + return $result; + } + /** * Close an order (Classify it as "Delivered") * From 24ae3d5879fe81035831894e56cea28f5fb148ab Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Fri, 15 Dec 2017 07:04:05 +0100 Subject: [PATCH 05/17] NEW : Add search on date and accounting account in various payment list --- htdocs/compta/bank/various_payment/index.php | 38 +++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/htdocs/compta/bank/various_payment/index.php b/htdocs/compta/bank/various_payment/index.php index 30a8d2d4353..11811d1c6aa 100644 --- a/htdocs/compta/bank/various_payment/index.php +++ b/htdocs/compta/bank/various_payment/index.php @@ -25,6 +25,7 @@ require '../../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; +if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php'; if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php'; @@ -44,6 +45,8 @@ $search_label = GETPOST('search_label','alpha'); $search_amount_deb = GETPOST('search_amount_deb','alpha'); $search_amount_cred = GETPOST('search_amount_cred','alpha'); $search_account = GETPOST('search_account','int'); +$search_date = dol_mktime(0, 0, 0, GETPOST('date_docmonth', 'int'), GETPOST('date_docday', 'int'), GETPOST('date_docyear', 'int')); +$search_accountancy_code = GETPOST("search_accountancy_code"); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); @@ -80,6 +83,8 @@ if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x', $search_amount_cred=""; $search_account=''; $typeid=""; + $search_date = ''; + $search_accountancy_code = ''; } /* @@ -89,6 +94,7 @@ if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x', llxHeader(); $form = new Form($db); +$formaccounting = new FormAccounting($db); $variousstatic = new PaymentVarious($db); $accountstatic = new Account($db); @@ -102,11 +108,14 @@ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.row $sql.= " WHERE v.entity IN (".getEntity('payment_various').")"; // Search criteria -if ($search_ref) $sql.=" AND v.rowid=".$search_ref; -if ($search_label) $sql.=natural_search(array('v.label'), $search_label); -if ($search_amount_deb) $sql.=natural_search("v.amount", $search_amount_deb, 1); -if ($search_amount_cred) $sql.=natural_search("v.amount", $search_amount_cred, 1); -if ($search_account > 0) $sql .=" AND b.fk_account=".$search_account; +if ($search_ref) $sql.=" AND v.rowid=".$search_ref; +if ($search_label) $sql.=natural_search(array('v.label'), $search_label); +if ($search_amount_deb) $sql.=natural_search("v.amount", $search_amount_deb, 1); +if ($search_amount_cred) $sql.=natural_search("v.amount", $search_amount_cred, 1); +if ($search_account > 0) $sql.=" AND b.fk_account=".$search_account; +if ($search_date) $sql.=" AND v.datep=".$search_date; +if ($search_accountancy_code) $sql.=" AND v.accountancy_code=".$search_accountancy_code; + if ($filtre) { $filtre=str_replace(":","=",$filtre); $sql .= " AND ".$filtre; @@ -159,7 +168,7 @@ if ($result) print_liste_field_titre("DatePayment",$_SERVER["PHP_SELF"],"v.datep","",$param,'align="center"',$sortfield,$sortorder); print_liste_field_titre("PaymentMode",$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder); if (! empty($conf->banque->enabled)) print_liste_field_titre("BankAccount",$_SERVER["PHP_SELF"],"ba.label","",$param,"",$sortfield,$sortorder); - print_liste_field_titre("AccountAccounting",$_SERVER["PHP_SELF"],"v.accountancy_code","",$param,'align="left"',$sortfield,$sortorder); + if (! empty($conf->accounting->enabled)) print_liste_field_titre("AccountAccounting",$_SERVER["PHP_SELF"],"v.accountancy_code","",$param,'align="left"',$sortfield,$sortorder); print_liste_field_titre("Debit",$_SERVER["PHP_SELF"],"v.amount","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre("Credit",$_SERVER["PHP_SELF"],"v.amount","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch '); @@ -176,7 +185,11 @@ if ($result) print ''; // Date - print ' '; + print ''; + print '
'; + print $form->select_date($search_date, 'date_doc', 0, 0, 1); + print '
'; + print ''; // Type print ''; @@ -192,7 +205,14 @@ if ($result) } // Accounting account - if (! empty($conf->accounting->enabled)) print ' '; + if (! empty($conf->accounting->enabled)) + { + print ''; + print '
'; + print $formaccounting->select_account($search_accountancy_code, 'search_accountancy_code', 1, array (), 1, 1, 'maxwidth200'); + print '
'; + print ''; + } // Debit print ''; @@ -224,7 +244,7 @@ if ($result) print "".dol_trunc($obj->label,40)."\n"; // Date payment - print ''.dol_print_date($db->jdate($obj->datep),'day')."\n"; + print ''.dol_print_date($db->jdate($obj->datep),'day')."\n"; // Type print ''.$langs->trans("PaymentTypeShort".$obj->payment_code).' '.$obj->num_payment.''; From d35fc67cfcae0b8913462bdc905ffdbc4ba13ee6 Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Fri, 15 Dec 2017 10:00:50 +0100 Subject: [PATCH 06/17] Unknown --- htdocs/compta/facture/class/api_invoices.class.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 115080811e6..34935c3088a 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -472,6 +472,11 @@ class Invoices extends DolibarrApi * @url POST {id}/lines * * @return int + * + * @throws 200 + * @throws 401 + * @throws 404 + * @throws 400 */ function postLine($id, $request_data = NULL) { if(! DolibarrApiAccess::$user->rights->facture->creer) { @@ -528,11 +533,11 @@ class Invoices extends DolibarrApi $request_data->fk_unit ); - if ($updateRes > 0) { - return $updateRes; - + if ($updateRes < 0) { + throw new RestException(400, 'Unable to insert the new line. Check your inputs. '.$this->invoice->error); } - throw new RestException(400, 'Unable to insert the new line. Check your inputs.'); + + return $updateRes; } /** From e61d625577e6e9aa80833520cdef2a190503247f Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Fri, 15 Dec 2017 10:00:50 +0100 Subject: [PATCH 07/17] FIX error message --- htdocs/compta/facture/class/api_invoices.class.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 115080811e6..34935c3088a 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -472,6 +472,11 @@ class Invoices extends DolibarrApi * @url POST {id}/lines * * @return int + * + * @throws 200 + * @throws 401 + * @throws 404 + * @throws 400 */ function postLine($id, $request_data = NULL) { if(! DolibarrApiAccess::$user->rights->facture->creer) { @@ -528,11 +533,11 @@ class Invoices extends DolibarrApi $request_data->fk_unit ); - if ($updateRes > 0) { - return $updateRes; - + if ($updateRes < 0) { + throw new RestException(400, 'Unable to insert the new line. Check your inputs. '.$this->invoice->error); } - throw new RestException(400, 'Unable to insert the new line. Check your inputs.'); + + return $updateRes; } /** From 4c852d1b6f638c17c329d7dc29b467b8f8e07cd4 Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Fri, 15 Dec 2017 16:34:30 +0100 Subject: [PATCH 08/17] NEW Set a proposal to draft Set a proposal to draft --- .../comm/propal/class/api_proposals.class.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index adf1140e004..7e02ba3c30c 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -466,6 +466,51 @@ class Proposals extends DolibarrApi } + /** + * Set a proposal to draft + * + * @param int $id Order ID + * + * @url POST {id}/settodraft + * + * @return array + */ + function settodraft($id) + { + if(! DolibarrApiAccess::$user->rights->propal->creer) { + throw new RestException(401); + } + $result = $this->propal->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Proposal not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('propal',$this->propal->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $result = $this->propal->set_draft(DolibarrApiAccess::$user); + if ($result == 0) { + throw new RestException(304, 'Nothing done. May be object is already draft'); + } + if ($result < 0) { + throw new RestException(500, 'Error : '.$this->propal->error); + } + + $result = $this->propal->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Proposal not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('propal',$this->propal->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $this->propal->fetchObjectLinked(); + return $this->_cleanObjectDatas($this->propal); + } + + /** * Validate a commercial proposal * From d8dac909d6cc9e2bbd85ca8d8604c497781129e9 Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Mon, 18 Dec 2017 14:36:41 +0100 Subject: [PATCH 09/17] NEW Add error message Returns the error message when the API can't add a new line in a proposal --- htdocs/comm/propal/class/api_proposals.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index 7e02ba3c30c..cb0e94cf88f 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -290,8 +290,9 @@ class Proposals extends DolibarrApi if ($updateRes > 0) { return $updateRes; } - - return false; + else { + throw new RestException(400, $this->propal->error); + } } /** From 081787326710471d8fdad079bdd8ee39f9fad6ca Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Mon, 18 Dec 2017 16:13:54 +0100 Subject: [PATCH 10/17] NEW Create an order using an existing proposal Create an order using an existing proposal. --- htdocs/commande/class/api_orders.class.php | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index b7cd76520c4..0b508b59f31 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -676,6 +676,49 @@ class Orders extends DolibarrApi } + /** + * Create an order using an existing proposal. + * + * + * @param int $proposalid Id of the proposal + * + * @url POST /createfromproposal/{proposalid} + * + * @return int + * @throws 400 + * @throws 401 + * @throws 404 + * @throws 405 + */ + function createOrderFromProposal($proposalid) { + + require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php'; + + if(! DolibarrApiAccess::$user->rights->propal->lire) { + throw new RestException(401); + } + if(! DolibarrApiAccess::$user->rights->commande->creer) { + throw new RestException(401); + } + if(empty($proposalid)) { + throw new RestException(400, 'Proposal ID is mandatory'); + } + + $propal = new Propal($this->db); + $result = $propal->fetch($proposalid); + if( ! $result ) { + throw new RestException(404, 'Proposal not found'); + } + + $result = $this->commande->createFromProposal($propal, DolibarrApiAccess::$user); + if( $result < 0) { + throw new RestException(405, $this->commande->error); + } + $this->commande->fetchObjectLinked(); + return $this->_cleanObjectDatas($this->commande); + } + + /** * Clean sensible object datas * From e90183f4bafd3496fdb50d8be08c636c52e456fa Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Tue, 19 Dec 2017 12:37:37 +0100 Subject: [PATCH 11/17] NEW Update end of validity date of proposal using the API Add the ability to update the end of validity date when modifying a proposal --- htdocs/comm/propal/class/api_proposals.class.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index cb0e94cf88f..204d4c12dc4 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -423,6 +423,19 @@ class Proposals extends DolibarrApi $this->propal->$field = $value; } + // update end of validity date + if(!empty($this->propal->duree_validite) && !empty($this->propal->date_creation) ) + { + $this->propal->fin_validite = $this->propal->date_creation + ($this->propal->duree_validite * 24 * 3600); + } + if(!empty($this->propal->fin_validite)) + { + if($this->propal->set_echeance(DolibarrApiAccess::$user, $this->propal->fin_validite)<0) + { + throw new RestException(500, $this->propal->error); + } + } + if ($this->propal->update(DolibarrApiAccess::$user) > 0) { return $this->get($id); From 7e3a2d75bb186303ad722ab5031a016813c5f866 Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Tue, 19 Dec 2017 13:06:28 +0100 Subject: [PATCH 12/17] FIX Error when classify the order as invoiced unsing API Remove of notrigger parameter. The notrigger attribute caused a type error when used. --- htdocs/commande/class/api_orders.class.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index 0b508b59f31..1b080c4e995 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -559,7 +559,6 @@ class Orders extends DolibarrApi * Classify the order as invoiced * * @param int $id Id of the order - * @param int $notrigger {@from body} 1=Does not execute triggers, 0= execute triggers {@choice 0,1} * * @url POST {id}/setinvoiced * @@ -570,7 +569,7 @@ class Orders extends DolibarrApi * @throws 404 * @throws 405 */ - function setinvoiced($id,$notrigger=0) { + function setinvoiced($id) { if(! DolibarrApiAccess::$user->rights->commande->creer) { throw new RestException(401); @@ -583,7 +582,7 @@ class Orders extends DolibarrApi throw new RestException(404, 'Order not found'); } - $result = $this->commande->classifyBilled(DolibarrApiAccess::$user,$notrigger); + $result = $this->commande->classifyBilled(DolibarrApiAccess::$user); if( $result < 0) { throw new RestException(400, $this->commande->error); } From a3f40667900da18679bd44dacaae88456e6c044b Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Tue, 19 Dec 2017 14:14:26 +0100 Subject: [PATCH 13/17] NEW Update bank account when updating an invoice Add the ability to update the bankaccount when updating an invoice --- htdocs/compta/facture/class/api_invoices.class.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 34935c3088a..1e0392bf452 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -422,6 +422,15 @@ class Invoices extends DolibarrApi $this->invoice->$field = $value; } + // update bank account + if(!empty($this->invoice->fk_account)) + { + if($this->invoice->setBankAccount($this->invoice->fk_account) == 0) + { + throw new RestException(400,$this->invoice->error); + } + } + if($this->invoice->update($id, DolibarrApiAccess::$user)) return $this->get ($id); From 171e388f6df562c1d2b2cad538304bee17830840 Mon Sep 17 00:00:00 2001 From: Neil Orley Date: Tue, 19 Dec 2017 14:16:51 +0100 Subject: [PATCH 14/17] NEW Update bank account when updating an order Add the ability to update the bankaccount when updating an order --- htdocs/commande/class/api_orders.class.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index 1b080c4e995..c15befe46e2 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -418,6 +418,15 @@ class Orders extends DolibarrApi if ($this->commande->availability($this->commande->availability_id) < 0) throw new RestException(400, 'Error while updating availability'); } + // update bank account + if(!empty($this->commande->fk_account)) + { + if($this->commande->setBankAccount($this->commande->fk_account) == 0) + { + throw new RestException(400,$this->commande->error); + } + } + if ($this->commande->update(DolibarrApiAccess::$user) > 0) { From 3635e883962b7e3c3be33c8d3c88f03accab7680 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Dec 2017 18:01:38 +0100 Subject: [PATCH 15/17] Update api_proposals.class.php --- htdocs/comm/propal/class/api_proposals.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index 204d4c12dc4..160f6999c40 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -424,11 +424,11 @@ class Proposals extends DolibarrApi } // update end of validity date - if(!empty($this->propal->duree_validite) && !empty($this->propal->date_creation) ) + if (empty($this->propal->fin_validite) && !empty($this->propal->duree_validite) && !empty($this->propal->date_creation)) { $this->propal->fin_validite = $this->propal->date_creation + ($this->propal->duree_validite * 24 * 3600); } - if(!empty($this->propal->fin_validite)) + if (!empty($this->propal->fin_validite)) { if($this->propal->set_echeance(DolibarrApiAccess::$user, $this->propal->fin_validite)<0) { From bffed79132578dfa7950288ffbc44403a7923624 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Dec 2017 18:06:05 +0100 Subject: [PATCH 16/17] Update api_invoices.class.php --- htdocs/compta/facture/class/api_invoices.class.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 1e0392bf452..f41a2ee9ae0 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -508,8 +508,14 @@ class Invoices extends DolibarrApi $request_data->fk_parent_line = 0; } - // calculate pa_ht - $marginInfos = getMarginInfos($request_data->subprice, $request_data->remise_percent, $request_data->tva_tx, $request_data->localtax1_tx, $request_data->localtax2_tx, $request_data->fk_fournprice, $request_data->pa_ht); + $pa_ht = $request_data->pa_ht; + + // calculate pa_ht + if ($pa_ht == 'auto') + { + $marginInfos = getMarginInfos($request_data->subprice, $request_data->remise_percent, $request_data->tva_tx, $request_data->localtax1_tx, $request_data->localtax2_tx, $request_data->fk_fournprice, $request_data->pa_ht); + $pa_ht = $marginInfos[0]; + } $updateRes = $this->invoice->addline( $request_data->desc, @@ -534,7 +540,7 @@ class Invoices extends DolibarrApi $id, $request_data->fk_parent_line, $request_data->fk_fournprice, - $marginInfos[0], + $pa_ht, $request_data->label, $request_data->array_options, $request_data->situation_percent, From 57603e3df43096e4b9a722150eff613b38e21c4c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Dec 2017 18:16:39 +0100 Subject: [PATCH 17/17] Update api_invoices.class.php --- htdocs/compta/facture/class/api_invoices.class.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index f41a2ee9ae0..e6a2be07184 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -508,15 +508,10 @@ class Invoices extends DolibarrApi $request_data->fk_parent_line = 0; } - $pa_ht = $request_data->pa_ht; - // calculate pa_ht - if ($pa_ht == 'auto') - { - $marginInfos = getMarginInfos($request_data->subprice, $request_data->remise_percent, $request_data->tva_tx, $request_data->localtax1_tx, $request_data->localtax2_tx, $request_data->fk_fournprice, $request_data->pa_ht); - $pa_ht = $marginInfos[0]; - } - + $marginInfos = getMarginInfos($request_data->subprice, $request_data->remise_percent, $request_data->tva_tx, $request_data->localtax1_tx, $request_data->localtax2_tx, $request_data->fk_fournprice, $request_data->pa_ht); + $pa_ht = $marginInfos[0]; + $updateRes = $this->invoice->addline( $request_data->desc, $request_data->subprice,