From f19fb90ab0e9ef315b2c7f9e29a2dd7b20942834 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 4 Jan 2018 21:14:45 +0100 Subject: [PATCH] Merge #8008 manually --- htdocs/api/class/api_documents.class.php | 14 ++++++ .../comm/propal/class/api_proposals.class.php | 43 ++++++++++++++++--- htdocs/commande/class/api_orders.class.php | 5 +-- .../facture/class/api_invoices.class.php | 16 +++++-- 4 files changed, 65 insertions(+), 13 deletions(-) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index df2ca288f35..cd63037c668 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -196,6 +196,20 @@ class Documents extends DolibarrApi throw new RestException(500, 'Error generating document'); } } + elseif ($module_part == 'propal' || $module_part == 'proposal') + { + require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; + $this->propal = new Propal($this->db); + $result = $this->propal->fetch(0, preg_replace('/\.[^\.]+$/', '', basename($original_file))); + if( ! $result ) { + throw new RestException(404, 'Proposal not found'); + } + $templateused = $doctemplate?$doctemplate:$this->propal->modelpdf; + $result = $this->propal->generateDocument($templateused, $outputlangs, $hidedetails, $hidedesc, $hideref); + if( $result <= 0 ) { + throw new RestException(500, 'Error generating document'); + } + } else { throw new RestException(403, 'Generation not available for this modulepart'); diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index 48311faa263..844c204f441 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -531,6 +531,37 @@ class Proposals extends DolibarrApi } + /** + * Set a commercial proposal billed. Could be also called setbilled + * + * @param int $id Commercial proposal ID + * + * @url POST {id}/setbilled + * + * @return array + */ + function setinvoiced($id) + { + if(! DolibarrApiAccess::$user->rights->propal->creer) { + throw new RestException(401); + } + $result = $this->propal->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Commercial 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->classifyBilled(DolibarrApiAccess::$user); + if( $result < 0) { + throw new RestException(400, $this->propal->error); + } + + return $result; + } + /** * Validate a commercial proposal * @@ -538,7 +569,7 @@ class Proposals extends DolibarrApi * { * "notrigger": 0 * } - * + * * @param int $id Commercial proposal ID * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @@ -548,13 +579,13 @@ class Proposals extends DolibarrApi * @throws 401 * @throws 404 * @throws 500 - * + * * @return array */ function validate($id, $notrigger=0) { var_dump($notrigger);exit; - + if(! DolibarrApiAccess::$user->rights->propal->creer) { throw new RestException(401); } @@ -656,7 +687,7 @@ class Proposals extends DolibarrApi if ($result < 0) { throw new RestException(500, 'Error : '.$this->propal->error); } - + return array( 'success' => array( 'code' => 200, @@ -664,8 +695,8 @@ class Proposals extends DolibarrApi ) ); } - - + + /** * Validate fields before create or update object * diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index 0c5e7531305..1d30e08205b 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -573,9 +573,8 @@ class Orders extends DolibarrApi return $result; } - /** - * Classify the order as invoiced + * Classify the order as invoiced. Could be also called setbilled * * @param int $id Id of the order * @@ -605,7 +604,7 @@ class Orders extends DolibarrApi if( $result < 0) { throw new RestException(400, $this->commande->error); } - + return $result; } diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 57e832fcf21..5e8f33d419f 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -147,7 +147,8 @@ class Invoices extends DolibarrApi } $sql.= $db->order($sortfield, $sortorder); - if ($limit) { + if ($limit) + { if ($page < 0) { $page = 0; @@ -167,8 +168,15 @@ class Invoices extends DolibarrApi { $obj = $db->fetch_object($result); $invoice_static = new Facture($db); - if($invoice_static->fetch($obj->rowid)) { - $obj_ret[] = $this->_cleanObjectDatas($invoice_static); + if ($invoice_static->fetch($obj->rowid)) + { + // Get payment details + $invoice_static->totalpaid = $invoice_static->getSommePaiement(); + $invoice_static->totalcreditnotes = $invoice_static->getSumCreditNotesUsed(); + $invoice_static->totaldeposits = $invoice_static->getSumDepositsUsed(); + $invoice_static->remaintopay = price2num($invoice_static->total_ttc - $invoice_static->totalpaid - $invoice_static->totalcreditnotes - $invoice_static->totaldeposits, 'MT'); + + $obj_ret[] = $this->_cleanObjectDatas($invoice_static); } $i++; } @@ -752,7 +760,7 @@ class Invoices extends DolibarrApi return $this->_cleanObjectDatas($this->invoice); } - + /** * Add a discount line into an invoice (as an invoice line) using an existing absolute discount *