diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 30a6d839ba8a36e51f19c24b07b9fde8e5981723..67a671a4bf9cdf43e0385914f8a67809a3239d1e 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -183,7 +183,7 @@ if (empty($reshook)) // Remove a product line else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->commande->creer) { - $result = $object->deleteline($lineid); + $result = $object->deleteline($user, $lineid); if ($result > 0) { // Define output language @@ -1919,9 +1919,9 @@ if ($action == 'create' && $user->rights->commande->creer) // Order card - + $linkback = '<a href="' . DOL_URL_ROOT . '/commande/list.php' . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>'; - + $morehtmlref='<div class="refidno">'; // Ref customer @@ -1962,17 +1962,17 @@ if ($action == 'create' && $user->rights->commande->creer) } } $morehtmlref.='</div>'; - - + + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - - + + print '<div class="fichecenter">'; print '<div class="fichehalfleft">'; print '<div class="underbanner clearboth"></div>'; - + print '<table class="border" width="100%">'; - + // Ref /* print '<tr><td class="titlefield">' . $langs->trans('Ref') . '</td>'; @@ -2309,7 +2309,7 @@ if ($action == 'create' && $user->rights->commande->creer) print '</td></tr>'; } */ - + // Incoterms 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'; print '</table>'; - + print '</div>'; print '<div class="fichehalfright">'; print '<div class="ficheaddleft">'; print '<div class="underbanner clearboth"></div>'; - + print '<table class="border centpercent">'; - + // Total HT print '<tr><td class="titlefield">' . $langs->trans('AmountHT') . '</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 //print '<tr><td>' . $langs->trans('Status') . '</td><td>' . $object->getLibStatut(4) . '</td></tr>'; - + print '</table>'; - + // Margin Infos if (! empty($conf->margin->enabled)) { $formmargin->displayMarginInfos($object); } - + print '</div>'; print '</div>'; print '</div>'; - + print '<div class="clearboth"></div><br>'; if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) { @@ -2634,7 +2634,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Show links to link elements $linktoelem = $form->showLinkToObjectBlock($object, null, array('order')); $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); - + print '</div><div class="fichehalfright"><div class="ficheaddleft">'; diff --git a/htdocs/commande/class/api_deprecated_commande.class.php b/htdocs/commande/class/api_deprecated_commande.class.php index bc04ec5fe77bfa12b0bafbd7a8f9875a647b907b..06da6fa874a2e84622bbf7317d976f2d555e360e 100644 --- a/htdocs/commande/class/api_deprecated_commande.class.php +++ b/htdocs/commande/class/api_deprecated_commande.class.php @@ -23,19 +23,19 @@ * API class for commande object * * @smart-auto-routing false - * @access protected + * @access protected * @class DolibarrApiAccess {@requires user,external} - * + * * @category Api * @package Api - * + * * @deprecated Use Orders instead (defined in api_orders.class.php) */ 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( 'socid' @@ -50,7 +50,7 @@ class CommandeApi extends DolibarrApi * Constructor <b>Warning: Deprecated</b> * * @url GET order/ - * + * */ function __construct() { @@ -63,40 +63,40 @@ class CommandeApi extends DolibarrApi * Get properties of a commande object <b>Warning: Deprecated</b> * * Return an array with commande informations - * + * * @param int $id ID of order * @param string $ref Ref of object * @param string $ref_ext External reference of object * @param string $ref_int Internal reference of other object * @return array|mixed data without useless information * - * @url GET order/{id} + * @url GET order/{id} * @throws RestException */ function get($id='',$ref='', $ref_ext='', $ref_int='') - { + { if(! DolibarrApiAccess::$user->rights->commande->lire) { throw new RestException(401); } - + $result = $this->commande->fetch($id); if( ! $result ) { throw new RestException(404, 'Order not found'); } - + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - + $this->commande->fetchObjectLinked(); return $this->_cleanObjectDatas($this->commande); } /** * List orders <b>Warning: Deprecated</b> - * + * * Get a list of orders - * + * * @param string $sortfield Sort field * @param string $sortorder Sort order * @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) { global $db, $conf; - + $obj_ret = array(); // case of external user, $societe param is ignored and replaced by user's socid $socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $societe; - + // 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; $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) $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 - + // Example of use $mode //if ($mode == 1) $sql.= " AND s.client IN (1, 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 ($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 - + // Insert sale filter if ($search_sale > 0) { $sql .= " AND sc.fk_user = ".$search_sale; } - + $nbtotalofrecords = 0; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { @@ -157,7 +157,7 @@ class CommandeApi extends DolibarrApi } $result = $db->query($sql); - + if ($result) { $i=0; @@ -183,9 +183,9 @@ class CommandeApi extends DolibarrApi /** * List orders for specific thirdparty <b>Warning: Deprecated</b> - * + * * Get a list of orders - * + * * @param int $socid Id of customer * * @url GET /customer/{socid}/order/list @@ -196,14 +196,14 @@ class CommandeApi extends DolibarrApi return getList(0,"s.rowid","ASC",0,0,$socid); } - + /** * Create order object <b>Warning: Deprecated</b> * * @param array $request_data Request datas - * + * * @url POST order/ - * + * * @return int ID of commande */ function post($request_data = NULL) @@ -227,7 +227,7 @@ class CommandeApi extends DolibarrApi if(! $this->commande->create(DolibarrApiAccess::$user) ) { throw new RestException(500, "Error while creating order"); } - + return $this->commande->id; } /** @@ -235,21 +235,21 @@ class CommandeApi extends DolibarrApi * * * @param int $id Id of order - * + * * @url GET order/{id}/line/list - * - * @return int + * + * @return int */ function getLines($id) { if(! DolibarrApiAccess::$user->rights->commande->lire) { throw new RestException(401); } - + $result = $this->commande->fetch($id); if( ! $result ) { throw new RestException(404, 'Commande not found'); } - + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { 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 array $request_data Orderline data - * + * @param array $request_data Orderline data + * * @url POST order/{id}/line - * - * @return int + * + * @return int */ function postLine($id, $request_data = NULL) { if(! DolibarrApiAccess::$user->rights->commande->creer) { throw new RestException(401); } - + $result = $this->commande->fetch($id); if( ! $result ) { throw new RestException(404, 'Commande not found'); } - + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { 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 $lineid Id of line to update - * @param array $request_data Orderline data - * + * @param array $request_data Orderline data + * * @url PUT order/{id}/line/{lineid} - * - * @return object + * + * @return object */ function putLine($id, $lineid, $request_data = NULL) { if(! DolibarrApiAccess::$user->rights->commande->creer) { throw new RestException(401); } - + $result = $this->commande->fetch($id); if( ! $result ) { throw new RestException(404, 'Commande not found'); } - + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { 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 $lineid Id of line to delete - * + * * @url DELETE order/{id}/line/{lineid} - * - * @return int + * + * @return int */ function delLine($id, $lineid) { if(! DolibarrApiAccess::$user->rights->commande->creer) { throw new RestException(401); } - + $result = $this->commande->fetch($id); if( ! $result ) { throw new RestException(404, 'Commande not found'); } - + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } $request_data = (object) $request_data; - $updateRes = $this->commande->deleteline($lineid); + $updateRes = $this->commande->deleteline(DolibarrApiAccess::$user,$lineid); if ($updateRes == 1) { 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> * * @param int $id Id of commande to update - * @param array $request_data Datas - * + * @param array $request_data Datas + * * @url PUT order/{id} - * - * @return int + * + * @return int */ function put($id, $request_data = NULL) { if(! DolibarrApiAccess::$user->rights->commande->creer) { throw new RestException(401); } - + $result = $this->commande->fetch($id); if( ! $result ) { throw new RestException(404, 'Commande not found'); } - + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } foreach($request_data as $field => $value) { $this->commande->$field = $value; } - + if($this->commande->update($id, DolibarrApiAccess::$user,1,'','','update')) return $this->get($id); - + return false; } - + /** * Delete order <b>Warning: Deprecated</b> * * @param int $id Order ID - * + * * @url DELETE order/{id} - * + * * @return array */ function delete($id) @@ -459,35 +459,35 @@ class CommandeApi extends DolibarrApi if( ! $result ) { throw new RestException(404, 'Order not found'); } - + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - + if( ! $this->commande->delete(DolibarrApiAccess::$user)) { throw new RestException(500, 'Error when delete order : '.$this->commande->error); } - + return array( 'success' => array( 'code' => 200, 'message' => 'Order deleted' ) ); - + } - + /** * Validate an order <b>Warning: Deprecated</b> - * + * * @param int $id Order ID * @param int $idwarehouse Warehouse ID - * + * * @url GET order/{id}/validate * @url POST order/{id}/validate - * + * * @return array - * + * */ function validOrder($id, $idwarehouse=0) { @@ -498,15 +498,15 @@ class CommandeApi extends DolibarrApi if( ! $result ) { throw new RestException(404, 'Order not found'); } - + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - + if( ! $this->commande->valid(DolibarrApiAccess::$user, $idwarehouse)) { throw new RestException(500, 'Error when validate order'); } - + return array( 'success' => array( 'code' => 200, @@ -514,12 +514,12 @@ class CommandeApi extends DolibarrApi ) ); } - + /** * Validate fields before create or update object - * + * * @param array $data Array with data to verify - * @return array + * @return array * @throws RestException */ function _validate($data) @@ -529,7 +529,7 @@ class CommandeApi extends DolibarrApi if (!isset($data[$field])) throw new RestException(400, "$field field missing"); $commande[$field] = $data[$field]; - + } return $commande; } diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index 5e000165bed1f5884872996b2a9dd1d507ebde56..6ba66a7801372d352107e2bcd9028265806b2cc3 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -23,14 +23,14 @@ /** * API class for orders * - * @access protected + * @access protected * @class DolibarrApiAccess {@requires user,external} */ 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( 'socid' @@ -55,36 +55,36 @@ class Orders extends DolibarrApi * Get properties of a commande object * * Return an array with commande informations - * + * * @param int $id ID of order * @return array|mixed data without useless information * * @throws RestException */ function get($id) - { + { if(! DolibarrApiAccess::$user->rights->commande->lire) { throw new RestException(401); } - + $result = $this->commande->fetch($id); if( ! $result ) { throw new RestException(404, 'Order not found'); } - + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - + $this->commande->fetchObjectLinked(); return $this->_cleanObjectDatas($this->commande); } /** * List orders - * + * * Get a list of orders - * + * * @param string $sortfield Sort field * @param string $sortorder Sort order * @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 = '') { global $db, $conf; - + $obj_ret = array(); // 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; - + // 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; $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) $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 $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 ($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 - + // Insert sale filter if ($search_sale > 0) { $sql .= " AND sc.fk_user = ".$search_sale; } - + $nbtotalofrecords = 0; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { @@ -139,7 +139,7 @@ class Orders extends DolibarrApi } $result = $db->query($sql); - + if ($result) { $num = $db->num_rows($result); @@ -190,7 +190,7 @@ class Orders extends DolibarrApi $errormsg = $this->commande->error; throw new RestException(500, $errormsg ? $errormsg : "Error while creating order"); } - + return $this->commande->id; } @@ -198,21 +198,21 @@ class Orders extends DolibarrApi * Get lines of an order * * @param int $id Id of order - * + * * @url GET {id}/lines - * - * @return int + * + * @return int */ function getLines($id) { if(! DolibarrApiAccess::$user->rights->commande->lire) { throw new RestException(401); } - + $result = $this->commande->fetch($id); if( ! $result ) { throw new RestException(404, 'Order not found'); } - + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { 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 * * @param int $id Id of commande to update - * @param array $request_data Orderline data - * + * @param array $request_data Orderline data + * * @url POST {id}/lines - * - * @return int + * + * @return int */ function postLine($id, $request_data = NULL) { if(! DolibarrApiAccess::$user->rights->commande->creer) { throw new RestException(401); } - + $result = $this->commande->fetch($id); if( ! $result ) { throw new RestException(404, 'Order not found'); } - + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { 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 $lineid Id of line to update - * @param array $request_data Orderline data - * + * @param array $request_data Orderline data + * * @url PUT {id}/lines/{lineid} - * - * @return object + * + * @return object */ function putLine($id, $lineid, $request_data = NULL) { if(! DolibarrApiAccess::$user->rights->commande->creer) { throw new RestException(401); } - + $result = $this->commande->fetch($id); if( ! $result ) { throw new RestException(404, 'Commande not found'); } - + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { 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 $lineid Id of line to delete - * + * * @url DELETE {id}/lines/{lineid} - * - * @return int + * + * @return int */ function delLine($id, $lineid) { if(! DolibarrApiAccess::$user->rights->commande->creer) { throw new RestException(401); } - + $result = $this->commande->fetch($id); if( ! $result ) { throw new RestException(404, 'Commande not found'); } - + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } $request_data = (object) $request_data; - $updateRes = $this->commande->deleteline($lineid); + $updateRes = $this->commande->deleteline(DolibarrApiAccess::$user,$lineid); if ($updateRes == 1) { return $this->get($id); } @@ -376,38 +376,38 @@ class Orders extends DolibarrApi * Update order general fields (won't touch lines of order) * * @param int $id Id of commande to update - * @param array $request_data Datas - * - * @return int + * @param array $request_data Datas + * + * @return int */ function put($id, $request_data = NULL) { if(! DolibarrApiAccess::$user->rights->commande->creer) { throw new RestException(401); } - + $result = $this->commande->fetch($id); if( ! $result ) { throw new RestException(404, 'Commande not found'); } - + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } foreach($request_data as $field => $value) { $this->commande->$field = $value; } - + if($this->commande->update($id, DolibarrApiAccess::$user, 1, '', '', 'update')) return $this->get($id); - + return false; } - + /** * Delete order * * @param int $id Order ID - * + * * @return array */ function delete($id) @@ -419,33 +419,33 @@ class Orders extends DolibarrApi if( ! $result ) { throw new RestException(404, 'Order not found'); } - + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - + if( ! $this->commande->delete(DolibarrApiAccess::$user)) { throw new RestException(500, 'Error when delete order : '.$this->commande->error); } - + return array( 'success' => array( 'code' => 200, 'message' => 'Order deleted' ) ); - + } - + /** * Validate an order - * + * * @param int $id Order ID * @param int $idwarehouse Warehouse ID * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * * @url POST {id}/validate - * + * * @return array * FIXME An error 403 is returned if the request has an empty body. * Error message: "Forbidden: Content type `text/plain` is not supported." @@ -464,11 +464,11 @@ class Orders extends DolibarrApi if( ! $result ) { throw new RestException(404, 'Order not found'); } - + if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - + $result = $this->commande->valid(DolibarrApiAccess::$user, $idwarehouse, $notrigger); if ($result == 0) { throw new RestException(500, 'Error nothing done. May be object is already validated'); @@ -476,7 +476,7 @@ class Orders extends DolibarrApi if ($result < 0) { throw new RestException(500, 'Error when validating Order: '.$this->commande->error); } - + return array( 'success' => array( 'code' => 200, @@ -484,12 +484,12 @@ class Orders extends DolibarrApi ) ); } - + /** * Validate fields before create or update object - * + * * @param array $data Array with data to verify - * @return array + * @return array * @throws RestException */ function _validate($data) @@ -499,7 +499,7 @@ class Orders extends DolibarrApi if (!isset($data[$field])) throw new RestException(400, "$field field missing"); $commande[$field] = $data[$field]; - + } return $commande; } diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 894f58f930efdc046593cbf8d23a78ca8aecb2cc..271c2515b6fc46bbf4bfabb6a2c9d07f49631c14 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -48,7 +48,7 @@ class Commande extends CommonOrder public $fk_element = 'fk_commande'; protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe public $picto = 'order'; - + /** * {@inheritdoc} */ @@ -810,11 +810,11 @@ class Commande extends CommonOrder for ($i=0;$i<$num;$i++) { $line = $this->lines[$i]; - + // 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 = (object) $line; - + // 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) { $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.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'"; - + $resqlcontact = $this->db->query($sqlcontact); if ($resqlcontact) { @@ -1972,10 +1972,11 @@ class Commande extends CommonOrder /** * Delete an order line * + * @param User $user User object * @param int $lineid Id of line to delete * @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) @@ -2002,7 +2003,7 @@ class Commande extends CommonOrder // For triggers $line->fetch($lineid); - if ($line->delete() > 0) + if ($line->delete($user) > 0) { $result=$this->update_price(1); @@ -2387,7 +2388,7 @@ class Commande extends CommonOrder function availability($availability_id, $notrigger=0) { global $user; - + dol_syslog('Commande::availability('.$availability_id.')'); if ($this->statut >= self::STATUS_DRAFT) { @@ -2457,7 +2458,7 @@ class Commande extends CommonOrder function demand_reason($demand_reason_id, $notrigger=0) { global $user; - + dol_syslog('Commande::demand_reason('.$demand_reason_id.')'); 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) { - 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"); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; @@ -2885,7 +2886,7 @@ class Commande extends CommonOrder $this->line->array_options=$array_options; } - $result=$this->line->update(); + $result=$this->line->update($user); if ($result > 0) { // Reorder if child line @@ -3805,9 +3806,11 @@ class OrderLine extends CommonOrderLine /** * 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 */ - function delete() + function delete($user=null, $notrigger=0) { global $conf, $user, $langs; @@ -3833,10 +3836,13 @@ class OrderLine extends CommonOrderLine } } - // Call trigger - $result=$this->call_trigger('LINEORDER_DELETE',$user); - if ($result < 0) $error++; - // End call triggers + if (! $error && ! $notrigger) + { + // Call trigger + $result=$this->call_trigger('LINEORDER_DELETE',$user); + if ($result < 0) $error++; + // End call triggers + } if (!$error) { $this->db->commit(); @@ -3861,12 +3867,13 @@ class OrderLine extends CommonOrderLine /** * Insert line into database * + * @param User $user User that modify * @param int $notrigger 1 = disable triggers * @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; @@ -4004,12 +4011,13 @@ class OrderLine extends CommonOrderLine /** * Update the line object into db * + * @param User $user User that modify * @param int $notrigger 1 = disable triggers * @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;