Merge pull request #5788 from atm-florian/dev_CommandeLine_Class_CleanDeclaration

wotk on declaration method OrderLine
This commit is contained in:
Laurent Destailleur 2016-09-28 19:03:00 +02:00 committed by GitHub
commit 5bf365e091
4 changed files with 186 additions and 178 deletions

View File

@ -183,7 +183,7 @@ if (empty($reshook))
// Remove a product line // Remove a product line
else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->commande->creer) else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->commande->creer)
{ {
$result = $object->deleteline($lineid); $result = $object->deleteline($user, $lineid);
if ($result > 0) if ($result > 0)
{ {
// Define output language // Define output language
@ -1919,9 +1919,9 @@ if ($action == 'create' && $user->rights->commande->creer)
// Order card // Order card
$linkback = '<a href="' . DOL_URL_ROOT . '/commande/list.php' . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>'; $linkback = '<a href="' . DOL_URL_ROOT . '/commande/list.php' . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
$morehtmlref='<div class="refidno">'; $morehtmlref='<div class="refidno">';
// Ref customer // Ref customer
@ -1962,17 +1962,17 @@ if ($action == 'create' && $user->rights->commande->creer)
} }
} }
$morehtmlref.='</div>'; $morehtmlref.='</div>';
dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
print '<div class="fichecenter">'; print '<div class="fichecenter">';
print '<div class="fichehalfleft">'; print '<div class="fichehalfleft">';
print '<div class="underbanner clearboth"></div>'; print '<div class="underbanner clearboth"></div>';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Ref // Ref
/* /*
print '<tr><td class="titlefield">' . $langs->trans('Ref') . '</td>'; print '<tr><td class="titlefield">' . $langs->trans('Ref') . '</td>';
@ -2309,7 +2309,7 @@ if ($action == 'create' && $user->rights->commande->creer)
print '</td></tr>'; print '</td></tr>';
} }
*/ */
// Incoterms // Incoterms
if (!empty($conf->incoterm->enabled)) if (!empty($conf->incoterm->enabled))
{ {
@ -2358,14 +2358,14 @@ if ($action == 'create' && $user->rights->commande->creer)
include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
print '</table>'; print '</table>';
print '</div>'; print '</div>';
print '<div class="fichehalfright">'; print '<div class="fichehalfright">';
print '<div class="ficheaddleft">'; print '<div class="ficheaddleft">';
print '<div class="underbanner clearboth"></div>'; print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent">'; print '<table class="border centpercent">';
// Total HT // Total HT
print '<tr><td class="titlefield">' . $langs->trans('AmountHT') . '</td>'; print '<tr><td class="titlefield">' . $langs->trans('AmountHT') . '</td>';
print '<td>' . price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency) . '</td>'; print '<td>' . price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency) . '</td>';
@ -2408,19 +2408,19 @@ if ($action == 'create' && $user->rights->commande->creer)
// Statut // Statut
//print '<tr><td>' . $langs->trans('Status') . '</td><td>' . $object->getLibStatut(4) . '</td></tr>'; //print '<tr><td>' . $langs->trans('Status') . '</td><td>' . $object->getLibStatut(4) . '</td></tr>';
print '</table>'; print '</table>';
// Margin Infos // Margin Infos
if (! empty($conf->margin->enabled)) { if (! empty($conf->margin->enabled)) {
$formmargin->displayMarginInfos($object); $formmargin->displayMarginInfos($object);
} }
print '</div>'; print '</div>';
print '</div>'; print '</div>';
print '</div>'; print '</div>';
print '<div class="clearboth"></div><br>'; print '<div class="clearboth"></div><br>';
if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) { if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
@ -2634,7 +2634,7 @@ if ($action == 'create' && $user->rights->commande->creer)
// Show links to link elements // Show links to link elements
$linktoelem = $form->showLinkToObjectBlock($object, null, array('order')); $linktoelem = $form->showLinkToObjectBlock($object, null, array('order'));
$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
print '</div><div class="fichehalfright"><div class="ficheaddleft">'; print '</div><div class="fichehalfright"><div class="ficheaddleft">';

View File

@ -23,19 +23,19 @@
* API class for commande object * API class for commande object
* *
* @smart-auto-routing false * @smart-auto-routing false
* @access protected * @access protected
* @class DolibarrApiAccess {@requires user,external} * @class DolibarrApiAccess {@requires user,external}
* *
* @category Api * @category Api
* @package Api * @package Api
* *
* @deprecated Use Orders instead (defined in api_orders.class.php) * @deprecated Use Orders instead (defined in api_orders.class.php)
*/ */
class CommandeApi extends DolibarrApi class CommandeApi extends DolibarrApi
{ {
/** /**
* @var array $FIELDS Mandatory fields, checked when create and update object * @var array $FIELDS Mandatory fields, checked when create and update object
*/ */
static $FIELDS = array( static $FIELDS = array(
'socid' 'socid'
@ -50,7 +50,7 @@ class CommandeApi extends DolibarrApi
* Constructor <b>Warning: Deprecated</b> * Constructor <b>Warning: Deprecated</b>
* *
* @url GET order/ * @url GET order/
* *
*/ */
function __construct() function __construct()
{ {
@ -63,40 +63,40 @@ class CommandeApi extends DolibarrApi
* Get properties of a commande object <b>Warning: Deprecated</b> * Get properties of a commande object <b>Warning: Deprecated</b>
* *
* Return an array with commande informations * Return an array with commande informations
* *
* @param int $id ID of order * @param int $id ID of order
* @param string $ref Ref of object * @param string $ref Ref of object
* @param string $ref_ext External reference of object * @param string $ref_ext External reference of object
* @param string $ref_int Internal reference of other object * @param string $ref_int Internal reference of other object
* @return array|mixed data without useless information * @return array|mixed data without useless information
* *
* @url GET order/{id} * @url GET order/{id}
* @throws RestException * @throws RestException
*/ */
function get($id='',$ref='', $ref_ext='', $ref_int='') function get($id='',$ref='', $ref_ext='', $ref_int='')
{ {
if(! DolibarrApiAccess::$user->rights->commande->lire) { if(! DolibarrApiAccess::$user->rights->commande->lire) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->commande->fetch($id); $result = $this->commande->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Order not found'); throw new RestException(404, 'Order not found');
} }
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
$this->commande->fetchObjectLinked(); $this->commande->fetchObjectLinked();
return $this->_cleanObjectDatas($this->commande); return $this->_cleanObjectDatas($this->commande);
} }
/** /**
* List orders <b>Warning: Deprecated</b> * List orders <b>Warning: Deprecated</b>
* *
* Get a list of orders * Get a list of orders
* *
* @param string $sortfield Sort field * @param string $sortfield Sort field
* @param string $sortorder Sort order * @param string $sortorder Sort order
* @param int $limit Limit for list * @param int $limit Limit for list
@ -109,20 +109,20 @@ class CommandeApi extends DolibarrApi
*/ */
function getList($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $societe = 0) { function getList($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $societe = 0) {
global $db, $conf; global $db, $conf;
$obj_ret = array(); $obj_ret = array();
// case of external user, $societe param is ignored and replaced by user's socid // case of external user, $societe param is ignored and replaced by user's socid
$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $societe; $socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $societe;
// If the internal user must only see his customers, force searching by him // If the internal user must only see his customers, force searching by him
if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id; if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
$sql = "SELECT s.rowid"; $sql = "SELECT s.rowid";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
$sql.= " FROM ".MAIN_DB_PREFIX."commande as s"; $sql.= " FROM ".MAIN_DB_PREFIX."commande as s";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
// Example of use $mode // Example of use $mode
//if ($mode == 1) $sql.= " AND s.client IN (1, 3)"; //if ($mode == 1) $sql.= " AND s.client IN (1, 3)";
//if ($mode == 2) $sql.= " AND s.client IN (2, 3)"; //if ($mode == 2) $sql.= " AND s.client IN (2, 3)";
@ -131,13 +131,13 @@ class CommandeApi extends DolibarrApi
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.fk_soc = sc.fk_soc"; if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.fk_soc = sc.fk_soc";
if ($socid) $sql.= " AND s.fk_soc = ".$socid; if ($socid) $sql.= " AND s.fk_soc = ".$socid;
if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
// Insert sale filter // Insert sale filter
if ($search_sale > 0) if ($search_sale > 0)
{ {
$sql .= " AND sc.fk_user = ".$search_sale; $sql .= " AND sc.fk_user = ".$search_sale;
} }
$nbtotalofrecords = 0; $nbtotalofrecords = 0;
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{ {
@ -157,7 +157,7 @@ class CommandeApi extends DolibarrApi
} }
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result)
{ {
$i=0; $i=0;
@ -183,9 +183,9 @@ class CommandeApi extends DolibarrApi
/** /**
* List orders for specific thirdparty <b>Warning: Deprecated</b> * List orders for specific thirdparty <b>Warning: Deprecated</b>
* *
* Get a list of orders * Get a list of orders
* *
* @param int $socid Id of customer * @param int $socid Id of customer
* *
* @url GET /customer/{socid}/order/list * @url GET /customer/{socid}/order/list
@ -196,14 +196,14 @@ class CommandeApi extends DolibarrApi
return getList(0,"s.rowid","ASC",0,0,$socid); return getList(0,"s.rowid","ASC",0,0,$socid);
} }
/** /**
* Create order object <b>Warning: Deprecated</b> * Create order object <b>Warning: Deprecated</b>
* *
* @param array $request_data Request datas * @param array $request_data Request datas
* *
* @url POST order/ * @url POST order/
* *
* @return int ID of commande * @return int ID of commande
*/ */
function post($request_data = NULL) function post($request_data = NULL)
@ -227,7 +227,7 @@ class CommandeApi extends DolibarrApi
if(! $this->commande->create(DolibarrApiAccess::$user) ) { if(! $this->commande->create(DolibarrApiAccess::$user) ) {
throw new RestException(500, "Error while creating order"); throw new RestException(500, "Error while creating order");
} }
return $this->commande->id; return $this->commande->id;
} }
/** /**
@ -235,21 +235,21 @@ class CommandeApi extends DolibarrApi
* *
* *
* @param int $id Id of order * @param int $id Id of order
* *
* @url GET order/{id}/line/list * @url GET order/{id}/line/list
* *
* @return int * @return int
*/ */
function getLines($id) { function getLines($id) {
if(! DolibarrApiAccess::$user->rights->commande->lire) { if(! DolibarrApiAccess::$user->rights->commande->lire) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->commande->fetch($id); $result = $this->commande->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Commande not found'); throw new RestException(404, 'Commande not found');
} }
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
@ -265,22 +265,22 @@ class CommandeApi extends DolibarrApi
* *
* *
* @param int $id Id of commande to update * @param int $id Id of commande to update
* @param array $request_data Orderline data * @param array $request_data Orderline data
* *
* @url POST order/{id}/line * @url POST order/{id}/line
* *
* @return int * @return int
*/ */
function postLine($id, $request_data = NULL) { function postLine($id, $request_data = NULL) {
if(! DolibarrApiAccess::$user->rights->commande->creer) { if(! DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->commande->fetch($id); $result = $this->commande->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Commande not found'); throw new RestException(404, 'Commande not found');
} }
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
@ -325,22 +325,22 @@ class CommandeApi extends DolibarrApi
* *
* @param int $id Id of commande to update * @param int $id Id of commande to update
* @param int $lineid Id of line to update * @param int $lineid Id of line to update
* @param array $request_data Orderline data * @param array $request_data Orderline data
* *
* @url PUT order/{id}/line/{lineid} * @url PUT order/{id}/line/{lineid}
* *
* @return object * @return object
*/ */
function putLine($id, $lineid, $request_data = NULL) { function putLine($id, $lineid, $request_data = NULL) {
if(! DolibarrApiAccess::$user->rights->commande->creer) { if(! DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->commande->fetch($id); $result = $this->commande->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Commande not found'); throw new RestException(404, 'Commande not found');
} }
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
@ -382,26 +382,26 @@ class CommandeApi extends DolibarrApi
* *
* @param int $id Id of commande to update * @param int $id Id of commande to update
* @param int $lineid Id of line to delete * @param int $lineid Id of line to delete
* *
* @url DELETE order/{id}/line/{lineid} * @url DELETE order/{id}/line/{lineid}
* *
* @return int * @return int
*/ */
function delLine($id, $lineid) { function delLine($id, $lineid) {
if(! DolibarrApiAccess::$user->rights->commande->creer) { if(! DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->commande->fetch($id); $result = $this->commande->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Commande not found'); throw new RestException(404, 'Commande not found');
} }
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
$request_data = (object) $request_data; $request_data = (object) $request_data;
$updateRes = $this->commande->deleteline($lineid); $updateRes = $this->commande->deleteline(DolibarrApiAccess::$user,$lineid);
if ($updateRes == 1) { if ($updateRes == 1) {
return $this->get($id); return $this->get($id);
} }
@ -412,42 +412,42 @@ class CommandeApi extends DolibarrApi
* Update order general fields (won't touch lines of order) <b>Warning: Deprecated</b> * Update order general fields (won't touch lines of order) <b>Warning: Deprecated</b>
* *
* @param int $id Id of commande to update * @param int $id Id of commande to update
* @param array $request_data Datas * @param array $request_data Datas
* *
* @url PUT order/{id} * @url PUT order/{id}
* *
* @return int * @return int
*/ */
function put($id, $request_data = NULL) { function put($id, $request_data = NULL) {
if(! DolibarrApiAccess::$user->rights->commande->creer) { if(! DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->commande->fetch($id); $result = $this->commande->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Commande not found'); throw new RestException(404, 'Commande not found');
} }
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
foreach($request_data as $field => $value) { foreach($request_data as $field => $value) {
$this->commande->$field = $value; $this->commande->$field = $value;
} }
if($this->commande->update($id, DolibarrApiAccess::$user,1,'','','update')) if($this->commande->update($id, DolibarrApiAccess::$user,1,'','','update'))
return $this->get($id); return $this->get($id);
return false; return false;
} }
/** /**
* Delete order <b>Warning: Deprecated</b> * Delete order <b>Warning: Deprecated</b>
* *
* @param int $id Order ID * @param int $id Order ID
* *
* @url DELETE order/{id} * @url DELETE order/{id}
* *
* @return array * @return array
*/ */
function delete($id) function delete($id)
@ -459,35 +459,35 @@ class CommandeApi extends DolibarrApi
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Order not found'); throw new RestException(404, 'Order not found');
} }
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
if( ! $this->commande->delete(DolibarrApiAccess::$user)) { if( ! $this->commande->delete(DolibarrApiAccess::$user)) {
throw new RestException(500, 'Error when delete order : '.$this->commande->error); throw new RestException(500, 'Error when delete order : '.$this->commande->error);
} }
return array( return array(
'success' => array( 'success' => array(
'code' => 200, 'code' => 200,
'message' => 'Order deleted' 'message' => 'Order deleted'
) )
); );
} }
/** /**
* Validate an order <b>Warning: Deprecated</b> * Validate an order <b>Warning: Deprecated</b>
* *
* @param int $id Order ID * @param int $id Order ID
* @param int $idwarehouse Warehouse ID * @param int $idwarehouse Warehouse ID
* *
* @url GET order/{id}/validate * @url GET order/{id}/validate
* @url POST order/{id}/validate * @url POST order/{id}/validate
* *
* @return array * @return array
* *
*/ */
function validOrder($id, $idwarehouse=0) function validOrder($id, $idwarehouse=0)
{ {
@ -498,15 +498,15 @@ class CommandeApi extends DolibarrApi
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Order not found'); throw new RestException(404, 'Order not found');
} }
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
if( ! $this->commande->valid(DolibarrApiAccess::$user, $idwarehouse)) { if( ! $this->commande->valid(DolibarrApiAccess::$user, $idwarehouse)) {
throw new RestException(500, 'Error when validate order'); throw new RestException(500, 'Error when validate order');
} }
return array( return array(
'success' => array( 'success' => array(
'code' => 200, 'code' => 200,
@ -514,12 +514,12 @@ class CommandeApi extends DolibarrApi
) )
); );
} }
/** /**
* Validate fields before create or update object * Validate fields before create or update object
* *
* @param array $data Array with data to verify * @param array $data Array with data to verify
* @return array * @return array
* @throws RestException * @throws RestException
*/ */
function _validate($data) function _validate($data)
@ -529,7 +529,7 @@ class CommandeApi extends DolibarrApi
if (!isset($data[$field])) if (!isset($data[$field]))
throw new RestException(400, "$field field missing"); throw new RestException(400, "$field field missing");
$commande[$field] = $data[$field]; $commande[$field] = $data[$field];
} }
return $commande; return $commande;
} }

View File

@ -23,14 +23,14 @@
/** /**
* API class for orders * API class for orders
* *
* @access protected * @access protected
* @class DolibarrApiAccess {@requires user,external} * @class DolibarrApiAccess {@requires user,external}
*/ */
class Orders extends DolibarrApi class Orders extends DolibarrApi
{ {
/** /**
* @var array $FIELDS Mandatory fields, checked when create and update object * @var array $FIELDS Mandatory fields, checked when create and update object
*/ */
static $FIELDS = array( static $FIELDS = array(
'socid' 'socid'
@ -55,36 +55,36 @@ class Orders extends DolibarrApi
* Get properties of a commande object * Get properties of a commande object
* *
* Return an array with commande informations * Return an array with commande informations
* *
* @param int $id ID of order * @param int $id ID of order
* @return array|mixed data without useless information * @return array|mixed data without useless information
* *
* @throws RestException * @throws RestException
*/ */
function get($id) function get($id)
{ {
if(! DolibarrApiAccess::$user->rights->commande->lire) { if(! DolibarrApiAccess::$user->rights->commande->lire) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->commande->fetch($id); $result = $this->commande->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Order not found'); throw new RestException(404, 'Order not found');
} }
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
$this->commande->fetchObjectLinked(); $this->commande->fetchObjectLinked();
return $this->_cleanObjectDatas($this->commande); return $this->_cleanObjectDatas($this->commande);
} }
/** /**
* List orders * List orders
* *
* Get a list of orders * Get a list of orders
* *
* @param string $sortfield Sort field * @param string $sortfield Sort field
* @param string $sortorder Sort order * @param string $sortorder Sort order
* @param int $limit Limit for list * @param int $limit Limit for list
@ -95,31 +95,31 @@ class Orders extends DolibarrApi
*/ */
function index($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '') { function index($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '') {
global $db, $conf; global $db, $conf;
$obj_ret = array(); $obj_ret = array();
// case of external user, $thirdpartyid param is ignored and replaced by user's socid // case of external user, $thirdpartyid param is ignored and replaced by user's socid
$socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $thirdparty_ids; $socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $thirdparty_ids;
// If the internal user must only see his customers, force searching by him // If the internal user must only see his customers, force searching by him
if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id; if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
$sql = "SELECT s.rowid"; $sql = "SELECT s.rowid";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
$sql.= " FROM ".MAIN_DB_PREFIX."commande as s"; $sql.= " FROM ".MAIN_DB_PREFIX."commande as s";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale
$sql.= ' WHERE s.entity IN ('.getEntity('commande', 1).')'; $sql.= ' WHERE s.entity IN ('.getEntity('commande', 1).')';
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND s.fk_soc = sc.fk_soc"; if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND s.fk_soc = sc.fk_soc";
if ($socids) $sql.= " AND s.fk_soc IN (".$socids.")"; if ($socids) $sql.= " AND s.fk_soc IN (".$socids.")";
if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
// Insert sale filter // Insert sale filter
if ($search_sale > 0) if ($search_sale > 0)
{ {
$sql .= " AND sc.fk_user = ".$search_sale; $sql .= " AND sc.fk_user = ".$search_sale;
} }
$nbtotalofrecords = 0; $nbtotalofrecords = 0;
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{ {
@ -139,7 +139,7 @@ class Orders extends DolibarrApi
} }
$result = $db->query($sql); $result = $db->query($sql);
if ($result) if ($result)
{ {
$num = $db->num_rows($result); $num = $db->num_rows($result);
@ -190,7 +190,7 @@ class Orders extends DolibarrApi
$errormsg = $this->commande->error; $errormsg = $this->commande->error;
throw new RestException(500, $errormsg ? $errormsg : "Error while creating order"); throw new RestException(500, $errormsg ? $errormsg : "Error while creating order");
} }
return $this->commande->id; return $this->commande->id;
} }
@ -198,21 +198,21 @@ class Orders extends DolibarrApi
* Get lines of an order * Get lines of an order
* *
* @param int $id Id of order * @param int $id Id of order
* *
* @url GET {id}/lines * @url GET {id}/lines
* *
* @return int * @return int
*/ */
function getLines($id) { function getLines($id) {
if(! DolibarrApiAccess::$user->rights->commande->lire) { if(! DolibarrApiAccess::$user->rights->commande->lire) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->commande->fetch($id); $result = $this->commande->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Order not found'); throw new RestException(404, 'Order not found');
} }
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
@ -228,22 +228,22 @@ class Orders extends DolibarrApi
* Add a line to given order * Add a line to given order
* *
* @param int $id Id of commande to update * @param int $id Id of commande to update
* @param array $request_data Orderline data * @param array $request_data Orderline data
* *
* @url POST {id}/lines * @url POST {id}/lines
* *
* @return int * @return int
*/ */
function postLine($id, $request_data = NULL) { function postLine($id, $request_data = NULL) {
if(! DolibarrApiAccess::$user->rights->commande->creer) { if(! DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->commande->fetch($id); $result = $this->commande->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Order not found'); throw new RestException(404, 'Order not found');
} }
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
@ -288,22 +288,22 @@ class Orders extends DolibarrApi
* *
* @param int $id Id of commande to update * @param int $id Id of commande to update
* @param int $lineid Id of line to update * @param int $lineid Id of line to update
* @param array $request_data Orderline data * @param array $request_data Orderline data
* *
* @url PUT {id}/lines/{lineid} * @url PUT {id}/lines/{lineid}
* *
* @return object * @return object
*/ */
function putLine($id, $lineid, $request_data = NULL) { function putLine($id, $lineid, $request_data = NULL) {
if(! DolibarrApiAccess::$user->rights->commande->creer) { if(! DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->commande->fetch($id); $result = $this->commande->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Commande not found'); throw new RestException(404, 'Commande not found');
} }
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
@ -346,26 +346,26 @@ class Orders extends DolibarrApi
* *
* @param int $id Id of commande to update * @param int $id Id of commande to update
* @param int $lineid Id of line to delete * @param int $lineid Id of line to delete
* *
* @url DELETE {id}/lines/{lineid} * @url DELETE {id}/lines/{lineid}
* *
* @return int * @return int
*/ */
function delLine($id, $lineid) { function delLine($id, $lineid) {
if(! DolibarrApiAccess::$user->rights->commande->creer) { if(! DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->commande->fetch($id); $result = $this->commande->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Commande not found'); throw new RestException(404, 'Commande not found');
} }
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
$request_data = (object) $request_data; $request_data = (object) $request_data;
$updateRes = $this->commande->deleteline($lineid); $updateRes = $this->commande->deleteline(DolibarrApiAccess::$user,$lineid);
if ($updateRes == 1) { if ($updateRes == 1) {
return $this->get($id); return $this->get($id);
} }
@ -376,38 +376,38 @@ class Orders extends DolibarrApi
* Update order general fields (won't touch lines of order) * Update order general fields (won't touch lines of order)
* *
* @param int $id Id of commande to update * @param int $id Id of commande to update
* @param array $request_data Datas * @param array $request_data Datas
* *
* @return int * @return int
*/ */
function put($id, $request_data = NULL) { function put($id, $request_data = NULL) {
if(! DolibarrApiAccess::$user->rights->commande->creer) { if(! DolibarrApiAccess::$user->rights->commande->creer) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->commande->fetch($id); $result = $this->commande->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Commande not found'); throw new RestException(404, 'Commande not found');
} }
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
foreach($request_data as $field => $value) { foreach($request_data as $field => $value) {
$this->commande->$field = $value; $this->commande->$field = $value;
} }
if($this->commande->update($id, DolibarrApiAccess::$user, 1, '', '', 'update')) if($this->commande->update($id, DolibarrApiAccess::$user, 1, '', '', 'update'))
return $this->get($id); return $this->get($id);
return false; return false;
} }
/** /**
* Delete order * Delete order
* *
* @param int $id Order ID * @param int $id Order ID
* *
* @return array * @return array
*/ */
function delete($id) function delete($id)
@ -419,33 +419,33 @@ class Orders extends DolibarrApi
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Order not found'); throw new RestException(404, 'Order not found');
} }
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
if( ! $this->commande->delete(DolibarrApiAccess::$user)) { if( ! $this->commande->delete(DolibarrApiAccess::$user)) {
throw new RestException(500, 'Error when delete order : '.$this->commande->error); throw new RestException(500, 'Error when delete order : '.$this->commande->error);
} }
return array( return array(
'success' => array( 'success' => array(
'code' => 200, 'code' => 200,
'message' => 'Order deleted' 'message' => 'Order deleted'
) )
); );
} }
/** /**
* Validate an order * Validate an order
* *
* @param int $id Order ID * @param int $id Order ID
* @param int $idwarehouse Warehouse ID * @param int $idwarehouse Warehouse ID
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @param int $notrigger 1=Does not execute triggers, 0= execute triggers
* *
* @url POST {id}/validate * @url POST {id}/validate
* *
* @return array * @return array
* FIXME An error 403 is returned if the request has an empty body. * FIXME An error 403 is returned if the request has an empty body.
* Error message: "Forbidden: Content type `text/plain` is not supported." * Error message: "Forbidden: Content type `text/plain` is not supported."
@ -464,11 +464,11 @@ class Orders extends DolibarrApi
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Order not found'); throw new RestException(404, 'Order not found');
} }
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
$result = $this->commande->valid(DolibarrApiAccess::$user, $idwarehouse, $notrigger); $result = $this->commande->valid(DolibarrApiAccess::$user, $idwarehouse, $notrigger);
if ($result == 0) { if ($result == 0) {
throw new RestException(500, 'Error nothing done. May be object is already validated'); throw new RestException(500, 'Error nothing done. May be object is already validated');
@ -476,7 +476,7 @@ class Orders extends DolibarrApi
if ($result < 0) { if ($result < 0) {
throw new RestException(500, 'Error when validating Order: '.$this->commande->error); throw new RestException(500, 'Error when validating Order: '.$this->commande->error);
} }
return array( return array(
'success' => array( 'success' => array(
'code' => 200, 'code' => 200,
@ -484,12 +484,12 @@ class Orders extends DolibarrApi
) )
); );
} }
/** /**
* Validate fields before create or update object * Validate fields before create or update object
* *
* @param array $data Array with data to verify * @param array $data Array with data to verify
* @return array * @return array
* @throws RestException * @throws RestException
*/ */
function _validate($data) function _validate($data)
@ -499,7 +499,7 @@ class Orders extends DolibarrApi
if (!isset($data[$field])) if (!isset($data[$field]))
throw new RestException(400, "$field field missing"); throw new RestException(400, "$field field missing");
$commande[$field] = $data[$field]; $commande[$field] = $data[$field];
} }
return $commande; return $commande;
} }

View File

@ -48,7 +48,7 @@ class Commande extends CommonOrder
public $fk_element = 'fk_commande'; public $fk_element = 'fk_commande';
protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
public $picto = 'order'; public $picto = 'order';
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -810,11 +810,11 @@ class Commande extends CommonOrder
for ($i=0;$i<$num;$i++) for ($i=0;$i<$num;$i++)
{ {
$line = $this->lines[$i]; $line = $this->lines[$i];
// Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array // Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array
//if (! is_object($line)) $line=json_decode(json_encode($line), FALSE); // convert recursively array into object. //if (! is_object($line)) $line=json_decode(json_encode($line), FALSE); // convert recursively array into object.
if (! is_object($line)) $line = (object) $line; if (! is_object($line)) $line = (object) $line;
// Reset fk_parent_line for no child products and special product // Reset fk_parent_line for no child products and special product
if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) { if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
$fk_parent_line = 0; $fk_parent_line = 0;
@ -906,10 +906,10 @@ class Commande extends CommonOrder
} }
} }
} }
$sqlcontact = "SELECT ctc.code, ctc.source, ec.fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc"; $sqlcontact = "SELECT ctc.code, ctc.source, ec.fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc";
$sqlcontact.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'"; $sqlcontact.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'";
$resqlcontact = $this->db->query($sqlcontact); $resqlcontact = $this->db->query($sqlcontact);
if ($resqlcontact) if ($resqlcontact)
{ {
@ -1220,7 +1220,7 @@ class Commande extends CommonOrder
*/ */
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $info_bits=0, $fk_remise_except=0, $price_base_type='HT', $pu_ttc=0, $date_start='', $date_end='', $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='',$array_options=0, $fk_unit=null, $origin='', $origin_id=0) function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $info_bits=0, $fk_remise_except=0, $price_base_type='HT', $pu_ttc=0, $date_start='', $date_end='', $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='',$array_options=0, $fk_unit=null, $origin='', $origin_id=0)
{ {
global $mysoc, $conf, $langs; global $mysoc, $conf, $langs, $user;
dol_syslog(get_class($this)."::addline commandeid=$this->id, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_percent=$remise_percent, info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc, date_start=$date_start, date_end=$date_end, type=$type special_code=$special_code, fk_unit=$fk_unit", LOG_DEBUG); dol_syslog(get_class($this)."::addline commandeid=$this->id, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_percent=$remise_percent, info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc, date_start=$date_start, date_end=$date_end, type=$type special_code=$special_code, fk_unit=$fk_unit", LOG_DEBUG);
@ -1373,7 +1373,7 @@ class Commande extends CommonOrder
$this->line->array_options=$array_options; $this->line->array_options=$array_options;
} }
$result=$this->line->insert(); $result=$this->line->insert($user);
if ($result > 0) if ($result > 0)
{ {
// Reorder if child line // Reorder if child line
@ -1972,10 +1972,11 @@ class Commande extends CommonOrder
/** /**
* Delete an order line * Delete an order line
* *
* @param User $user User object
* @param int $lineid Id of line to delete * @param int $lineid Id of line to delete
* @return int >0 if OK, 0 if nothing to do, <0 if KO * @return int >0 if OK, 0 if nothing to do, <0 if KO
*/ */
function deleteline($lineid) function deleteline($user=null, $lineid=0)
{ {
if ($this->statut == self::STATUS_DRAFT) if ($this->statut == self::STATUS_DRAFT)
@ -2002,7 +2003,7 @@ class Commande extends CommonOrder
// For triggers // For triggers
$line->fetch($lineid); $line->fetch($lineid);
if ($line->delete() > 0) if ($line->delete($user) > 0)
{ {
$result=$this->update_price(1); $result=$this->update_price(1);
@ -2387,7 +2388,7 @@ class Commande extends CommonOrder
function availability($availability_id, $notrigger=0) function availability($availability_id, $notrigger=0)
{ {
global $user; global $user;
dol_syslog('Commande::availability('.$availability_id.')'); dol_syslog('Commande::availability('.$availability_id.')');
if ($this->statut >= self::STATUS_DRAFT) if ($this->statut >= self::STATUS_DRAFT)
{ {
@ -2457,7 +2458,7 @@ class Commande extends CommonOrder
function demand_reason($demand_reason_id, $notrigger=0) function demand_reason($demand_reason_id, $notrigger=0)
{ {
global $user; global $user;
dol_syslog('Commande::demand_reason('.$demand_reason_id.')'); dol_syslog('Commande::demand_reason('.$demand_reason_id.')');
if ($this->statut >= self::STATUS_DRAFT) if ($this->statut >= self::STATUS_DRAFT)
{ {
@ -2740,7 +2741,7 @@ class Commande extends CommonOrder
*/ */
function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0.0,$txlocaltax2=0.0, $price_base_type='HT', $info_bits=0, $date_start='', $date_end='', $type=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_options=0, $fk_unit=null) function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0.0,$txlocaltax2=0.0, $price_base_type='HT', $info_bits=0, $date_start='', $date_end='', $type=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_options=0, $fk_unit=null)
{ {
global $conf, $mysoc, $langs; global $conf, $mysoc, $langs, $user;
dol_syslog(get_class($this)."::updateline id=$rowid, desc=$desc, pu=$pu, qty=$qty, remise_percent=$remise_percent, txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, price_base_type=$price_base_type, info_bits=$info_bits, date_start=$date_start, date_end=$date_end, type=$type, fk_parent_line=$fk_parent_line, pa_ht=$pa_ht, special_code=$special_code"); dol_syslog(get_class($this)."::updateline id=$rowid, desc=$desc, pu=$pu, qty=$qty, remise_percent=$remise_percent, txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, price_base_type=$price_base_type, info_bits=$info_bits, date_start=$date_start, date_end=$date_end, type=$type, fk_parent_line=$fk_parent_line, pa_ht=$pa_ht, special_code=$special_code");
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
@ -2885,7 +2886,7 @@ class Commande extends CommonOrder
$this->line->array_options=$array_options; $this->line->array_options=$array_options;
} }
$result=$this->line->update(); $result=$this->line->update($user);
if ($result > 0) if ($result > 0)
{ {
// Reorder if child line // Reorder if child line
@ -3805,9 +3806,11 @@ class OrderLine extends CommonOrderLine
/** /**
* Delete line in database * Delete line in database
* *
* @param User $user User that modify
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 si ko, >0 si ok * @return int <0 si ko, >0 si ok
*/ */
function delete() function delete($user=null, $notrigger=0)
{ {
global $conf, $user, $langs; global $conf, $user, $langs;
@ -3833,10 +3836,13 @@ class OrderLine extends CommonOrderLine
} }
} }
// Call trigger if (! $error && ! $notrigger)
$result=$this->call_trigger('LINEORDER_DELETE',$user); {
if ($result < 0) $error++; // Call trigger
// End call triggers $result=$this->call_trigger('LINEORDER_DELETE',$user);
if ($result < 0) $error++;
// End call triggers
}
if (!$error) { if (!$error) {
$this->db->commit(); $this->db->commit();
@ -3861,12 +3867,13 @@ class OrderLine extends CommonOrderLine
/** /**
* Insert line into database * Insert line into database
* *
* @param User $user User that modify
* @param int $notrigger 1 = disable triggers * @param int $notrigger 1 = disable triggers
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function insert($notrigger=0) function insert($user=null, $notrigger=0)
{ {
global $langs, $conf, $user; global $langs, $conf;
$error=0; $error=0;
@ -4004,12 +4011,13 @@ class OrderLine extends CommonOrderLine
/** /**
* Update the line object into db * Update the line object into db
* *
* @param User $user User that modify
* @param int $notrigger 1 = disable triggers * @param int $notrigger 1 = disable triggers
* @return int <0 si ko, >0 si ok * @return int <0 si ko, >0 si ok
*/ */
function update($notrigger=0) function update($user=null, $notrigger=0)
{ {
global $conf,$langs,$user; global $conf,$langs;
$error=0; $error=0;