Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop
This commit is contained in:
commit
846453e94b
@ -290,8 +290,9 @@ class Proposals extends DolibarrApi
|
||||
if ($updateRes > 0) {
|
||||
return $updateRes;
|
||||
}
|
||||
|
||||
return false;
|
||||
else {
|
||||
throw new RestException(400, $this->propal->error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -422,6 +423,19 @@ class Proposals extends DolibarrApi
|
||||
$this->propal->$field = $value;
|
||||
}
|
||||
|
||||
// update end of validity date
|
||||
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($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);
|
||||
@ -466,6 +480,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
|
||||
*
|
||||
|
||||
@ -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)
|
||||
{
|
||||
@ -515,6 +524,80 @@ 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($id);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Classify the order as invoiced
|
||||
*
|
||||
* @param int $id Id of the order
|
||||
*
|
||||
* @url POST {id}/setinvoiced
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws 400
|
||||
* @throws 401
|
||||
* @throws 404
|
||||
* @throws 405
|
||||
*/
|
||||
function setinvoiced($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($id);
|
||||
if( ! $result ) {
|
||||
throw new RestException(404, 'Order not found');
|
||||
}
|
||||
|
||||
$result = $this->commande->classifyBilled(DolibarrApiAccess::$user);
|
||||
if( $result < 0) {
|
||||
throw new RestException(400, $this->commande->error);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close an order (Classify it as "Delivered")
|
||||
*
|
||||
@ -601,6 +684,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
|
||||
*
|
||||
|
||||
@ -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 '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_label" value="'.dol_escape_htmltag($search_label).'"></td>';
|
||||
|
||||
// Date
|
||||
print '<td class="liste_titre"> </td>';
|
||||
print '<td class="liste_titre center">';
|
||||
print '<div class="nowrap">';
|
||||
print $form->select_date($search_date, 'date_doc', 0, 0, 1);
|
||||
print '</div>';
|
||||
print '</td>';
|
||||
|
||||
// Type
|
||||
print '<td class="liste_titre" align="left">';
|
||||
@ -192,7 +205,14 @@ if ($result)
|
||||
}
|
||||
|
||||
// Accounting account
|
||||
if (! empty($conf->accounting->enabled)) print '<td class="liste_titre"> </td>';
|
||||
if (! empty($conf->accounting->enabled))
|
||||
{
|
||||
print '<td class="liste_titre">';
|
||||
print '<div class="nowrap">';
|
||||
print $formaccounting->select_account($search_accountancy_code, 'search_accountancy_code', 1, array (), 1, 1, 'maxwidth200');
|
||||
print '</div>';
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
// Debit
|
||||
print '<td class="liste_titre" align="right"><input name="search_amount_deb" class="flat" type="text" size="8" value="'.$search_amount_deb.'"></td>';
|
||||
@ -224,7 +244,7 @@ if ($result)
|
||||
print "<td>".dol_trunc($obj->label,40)."</td>\n";
|
||||
|
||||
// Date payment
|
||||
print '<td align="center">'.dol_print_date($db->jdate($obj->datep),'day')."</td>\n";
|
||||
print '<td class="center">'.dol_print_date($db->jdate($obj->datep),'day')."</td>\n";
|
||||
|
||||
// Type
|
||||
print '<td>'.$langs->trans("PaymentTypeShort".$obj->payment_code).' '.$obj->num_payment.'</td>';
|
||||
|
||||
@ -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
|
||||
*
|
||||
@ -380,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);
|
||||
|
||||
@ -430,6 +481,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) {
|
||||
@ -452,6 +508,10 @@ 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 = $marginInfos[0];
|
||||
|
||||
$updateRes = $this->invoice->addline(
|
||||
$request_data->desc,
|
||||
$request_data->subprice,
|
||||
@ -475,7 +535,7 @@ class Invoices extends DolibarrApi
|
||||
$id,
|
||||
$request_data->fk_parent_line,
|
||||
$request_data->fk_fournprice,
|
||||
$request_data->pa_ht,
|
||||
$pa_ht,
|
||||
$request_data->label,
|
||||
$request_data->array_options,
|
||||
$request_data->situation_percent,
|
||||
@ -483,11 +543,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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user