--- /tmp/dsg/dolibarr/htdocs/expedition/class/github_api_shipments.class.php +++ /tmp/dsg/dolibarr/htdocs/expedition/class/client_api_shipments.class.php @@ -29,194 +29,195 @@ class Shipments extends DolibarrApi { - /** - * @var array $FIELDS Mandatory fields, checked when create and update object - */ - static $FIELDS = array( - 'socid', - 'origin_id', - 'origin_type', - ); - - /** - * @var Expedition $shipment {@type Expedition} - */ - public $shipment; - - /** - * Constructor - */ - public function __construct() - { - global $db, $conf; - $this->db = $db; - $this->shipment = new Expedition($this->db); - } - - /** - * Get properties of a shipment object - * - * Return an array with shipment informations - * - * @param int $id ID of shipment - * @return array|mixed data without useless information - * - * @throws RestException - */ - public function get($id) - { - if (!DolibarrApiAccess::$user->rights->expedition->lire) { - throw new RestException(401); - } - - $result = $this->shipment->fetch($id); - if (!$result) { - throw new RestException(404, 'Shipment not found'); - } - - if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $this->shipment->fetchObjectLinked(); - return $this->_cleanObjectDatas($this->shipment); - } - - - - /** - * List shipments - * - * Get a list of shipments - * - * @param string $sortfield Sort field - * @param string $sortorder Sort order - * @param int $limit Limit for list - * @param int $page Page number - * @param string $thirdparty_ids Thirdparty ids to filter shipments of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i} - * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" - * @return array Array of shipment objects - * - * @throws RestException - */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '') - { - global $db, $conf; - - $obj_ret = array(); - - // case of external user, $thirdparty_ids param is ignored and replaced by user's socid - $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids; - - // If the internal user must only see his customers, force searching by him - $search_sale = 0; - if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id; - - $sql = "SELECT t.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."expedition as t"; - - 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 t.entity IN ('.getEntity('expedition').')'; - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.fk_soc = sc.fk_soc"; - if ($socids) $sql .= " AND t.fk_soc IN (".$socids.")"; - if ($search_sale > 0) $sql .= " AND t.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; - } - // Add sql filters - if ($sqlfilters) - { - if (!DolibarrApi::_checkFilters($sqlfilters)) - { - throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); - } - $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; - $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; - } - - $sql .= $this->db->order($sortfield, $sortorder); - if ($limit) { - if ($page < 0) - { - $page = 0; - } - $offset = $limit * $page; - - $sql .= $this->db->plimit($limit + 1, $offset); - } - - dol_syslog("API Rest request"); - $result = $this->db->query($sql); - - if ($result) - { - $num = $this->db->num_rows($result); - $min = min($num, ($limit <= 0 ? $num : $limit)); - $i = 0; - while ($i < $min) - { - $obj = $this->db->fetch_object($result); - $shipment_static = new Expedition($this->db); - if ($shipment_static->fetch($obj->rowid)) { - $obj_ret[] = $this->_cleanObjectDatas($shipment_static); - } - $i++; - } - } else { - throw new RestException(503, 'Error when retrieve commande list : '.$this->db->lasterror()); - } - if (!count($obj_ret)) { - throw new RestException(404, 'No shipment found'); - } - return $obj_ret; - } - - /** - * Create shipment object - * - * @param array $request_data Request data - * @return int ID of shipment - */ - public function post($request_data = null) - { - if (!DolibarrApiAccess::$user->rights->expedition->creer) { - throw new RestException(401, "Insuffisant rights"); - } - // Check mandatory fields - $result = $this->_validate($request_data); - - foreach ($request_data as $field => $value) { - $this->shipment->$field = $value; - } - if (isset($request_data["lines"])) { - $lines = array(); - foreach ($request_data["lines"] as $line) { - array_push($lines, (object) $line); - } - $this->shipment->lines = $lines; - } - - if ($this->shipment->create(DolibarrApiAccess::$user) < 0) { - throw new RestException(500, "Error creating shipment", array_merge(array($this->shipment->error), $this->shipment->errors)); - } - - return $this->shipment->id; - } - - // /** - // * Get lines of an shipment - // * - // * @param int $id Id of shipment - // * - // * @url GET {id}/lines - // * - // * @return int - // */ - /* + /** + * @var array $FIELDS Mandatory fields, checked when create and update object + */ + static $FIELDS = array( + 'socid', + 'origin_id', + 'origin_type', + ); + + /** + * @var Expedition $shipment {@type Expedition} + */ + public $shipment; + + /** + * Constructor + */ + public function __construct() + { + global $db, $conf; + $this->db = $db; + $this->shipment = new Expedition($this->db); + } + + /** + * Get properties of a shipment object + * + * Return an array with shipment informations + * + * @param int $id ID of shipment + * @return array|mixed data without useless information + * + * @throws RestException + */ + public function get($id) + { + if (!DolibarrApiAccess::$user->rights->expedition->lire) { + throw new RestException(401); + } + + $result = $this->shipment->fetch($id); + if (!$result) { + throw new RestException(404, 'Shipment not found'); + } + + if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $this->shipment->fetchObjectLinked(); + return $this->_cleanObjectDatas($this->shipment); + } + + + + /** + * List shipments + * + * Get a list of shipments + * + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * @param string $thirdparty_ids Thirdparty ids to filter shipments of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i} + * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" + * @return array Array of shipment objects + * + * @throws RestException + */ + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '') + { + global $db, $conf; + + $obj_ret = array(); + + // case of external user, $thirdparty_ids param is ignored and replaced by user's socid + $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids; + + // If the internal user must only see his customers, force searching by him + $search_sale = 0; + if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id; + + $sql = "SELECT t.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."expedition as t"; + + 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 t.entity IN ('.getEntity('expedition').')'; + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.fk_soc = sc.fk_soc"; + if ($socids) $sql .= " AND t.fk_soc IN (".$socids.")"; + if ($search_sale > 0) $sql .= " AND t.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; + } + // Add sql filters + if ($sqlfilters) + { + if (!DolibarrApi::_checkFilters($sqlfilters)) + { + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); + } + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; + } + + $sql .= $db->order($sortfield, $sortorder); + if ($limit) { + if ($page < 0) + { + $page = 0; + } + $offset = $limit * $page; + + $sql .= $db->plimit($limit + 1, $offset); + } + + dol_syslog("API Rest request"); + $result = $db->query($sql); + + if ($result) + { + $num = $db->num_rows($result); + $min = min($num, ($limit <= 0 ? $num : $limit)); + $i = 0; + while ($i < $min) + { + $obj = $db->fetch_object($result); + $shipment_static = new Expedition($db); + if ($shipment_static->fetch($obj->rowid)) { + $obj_ret[] = $this->_cleanObjectDatas($shipment_static); + } + $i++; + } + } + else { + throw new RestException(503, 'Error when retrieve commande list : '.$db->lasterror()); + } + if (!count($obj_ret)) { + throw new RestException(404, 'No shipment found'); + } + return $obj_ret; + } + + /** + * Create shipment object + * + * @param array $request_data Request data + * @return int ID of shipment + */ + public function post($request_data = null) + { + if (!DolibarrApiAccess::$user->rights->expedition->creer) { + throw new RestException(401, "Insuffisant rights"); + } + // Check mandatory fields + $result = $this->_validate($request_data); + + foreach ($request_data as $field => $value) { + $this->shipment->$field = $value; + } + if (isset($request_data["lines"])) { + $lines = array(); + foreach ($request_data["lines"] as $line) { + array_push($lines, (object) $line); + } + $this->shipment->lines = $lines; + } + + if ($this->shipment->create(DolibarrApiAccess::$user) < 0) { + throw new RestException(500, "Error creating shipment", array_merge(array($this->shipment->error), $this->shipment->errors)); + } + + return $this->shipment->id; + } + + // /** + // * Get lines of an shipment + // * + // * @param int $id Id of shipment + // * + // * @url GET {id}/lines + // * + // * @return int + // */ + /* public function getLines($id) { if(! DolibarrApiAccess::$user->rights->expedition->lire) { @@ -240,17 +241,17 @@ } */ - // /** - // * Add a line to given shipment - // * - // * @param int $id Id of shipment to update - // * @param array $request_data ShipmentLine data - // * - // * @url POST {id}/lines - // * - // * @return int - // */ - /* + // /** + // * Add a line to given shipment + // * + // * @param int $id Id of shipment to update + // * @param array $request_data ShipmentLine data + // * + // * @url POST {id}/lines + // * + // * @return int + // */ + /* public function postLine($id, $request_data = null) { if(! DolibarrApiAccess::$user->rights->expedition->creer) { @@ -302,18 +303,18 @@ return false; }*/ - // /** - // * Update a line to given shipment - // * - // * @param int $id Id of shipment to update - // * @param int $lineid Id of line to update - // * @param array $request_data ShipmentLine data - // * - // * @url PUT {id}/lines/{lineid} - // * - // * @return object - // */ - /* + // /** + // * Update a line to given shipment + // * + // * @param int $id Id of shipment to update + // * @param int $lineid Id of line to update + // * @param array $request_data ShipmentLine data + // * + // * @url PUT {id}/lines/{lineid} + // * + // * @return object + // */ + /* public function putLine($id, $lineid, $request_data = null) { if (! DolibarrApiAccess::$user->rights->expedition->creer) { @@ -362,183 +363,187 @@ return false; }*/ - /** - * Delete a line to given shipment - * - * - * @param int $id Id of shipment to update - * @param int $lineid Id of line to delete - * - * @url DELETE {id}/lines/{lineid} - * - * @return int - * - * @throws RestException 401 - * @throws RestException 404 - */ - public function deleteLine($id, $lineid) - { - if (!DolibarrApiAccess::$user->rights->expedition->creer) { - throw new RestException(401); - } - - $result = $this->shipment->fetch($id); - if (!$result) { - throw new RestException(404, 'Shipment not found'); - } - - if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - // TODO Check the lineid $lineid is a line of ojbect - - $request_data = (object) $request_data; - $updateRes = $this->shipment->deleteline(DolibarrApiAccess::$user, $lineid); - if ($updateRes > 0) { - return $this->get($id); - } else { - throw new RestException(405, $this->shipment->error); - } - } - - /** - * Update shipment general fields (won't touch lines of shipment) - * - * @param int $id Id of shipment to update - * @param array $request_data Datas - * - * @return int - */ - public function put($id, $request_data = null) - { - if (!DolibarrApiAccess::$user->rights->expedition->creer) { - throw new RestException(401); - } - - $result = $this->shipment->fetch($id); - if (!$result) { - throw new RestException(404, 'Shipment not found'); - } - - if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - foreach ($request_data as $field => $value) { - if ($field == 'id') continue; - $this->shipment->$field = $value; - } - - if ($this->shipment->update(DolibarrApiAccess::$user) > 0) - { - return $this->get($id); - } else { - throw new RestException(500, $this->shipment->error); - } - } - - /** - * Delete shipment - * - * @param int $id Shipment ID - * - * @return array - */ - public function delete($id) - { - if (!DolibarrApiAccess::$user->rights->expedition->supprimer) { - throw new RestException(401); - } - $result = $this->shipment->fetch($id); - if (!$result) { - throw new RestException(404, 'Shipment not found'); - } - - if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - if (!$this->shipment->delete(DolibarrApiAccess::$user)) { - throw new RestException(500, 'Error when deleting shipment : '.$this->shipment->error); - } - - return array( - 'success' => array( - 'code' => 200, - 'message' => 'Shipment deleted' - ) - ); - } - - /** - * Validate a shipment - * - * This may record stock movements if module stock is enabled and option to - * decrease stock on shipment is on. - * - * @param int $id Shipment ID - * @param int $notrigger 1=Does not execute triggers, 0= execute triggers - * - * @url POST {id}/validate - * - * @return array - * \todo An error 403 is returned if the request has an empty body. - * Error message: "Forbidden: Content type `text/plain` is not supported." - * Workaround: send this in the body - * { - * "notrigger": 0 - * } - */ - public function validate($id, $notrigger = 0) - { - if (!DolibarrApiAccess::$user->rights->expedition->creer) { - throw new RestException(401); - } - $result = $this->shipment->fetch($id); - if (!$result) { - throw new RestException(404, 'Shipment not found'); - } - - if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $result = $this->shipment->valid(DolibarrApiAccess::$user, $notrigger); - if ($result == 0) { - throw new RestException(304, 'Error nothing done. May be object is already validated'); - } - if ($result < 0) { - throw new RestException(500, 'Error when validating Shipment: '.$this->shipment->error); - } - $result = $this->shipment->fetch($id); - if (!$result) { - throw new RestException(404, 'Shipment not found'); - } - - if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $this->shipment->fetchObjectLinked(); - return $this->_cleanObjectDatas($this->shipment); - } - - - // /** - // * Classify the shipment as invoiced - // * - // * @param int $id Id of the shipment - // * - // * @url POST {id}/setinvoiced - // * - // * @return int - // * - // * @throws RestException 400 - // * @throws RestException 401 - // * @throws RestException 404 - // * @throws RestException 405 - // */ - /* + /** + * Delete a line to given shipment + * + * + * @param int $id Id of shipment to update + * @param int $lineid Id of line to delete + * + * @url DELETE {id}/lines/{lineid} + * + * @return int + * + * @throws RestException 401 + * @throws RestException 404 + */ + public function deleteLine($id, $lineid) + { + if (!DolibarrApiAccess::$user->rights->expedition->creer) { + throw new RestException(401); + } + + $result = $this->shipment->fetch($id); + if (!$result) { + throw new RestException(404, 'Shipment not found'); + } + + if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + // TODO Check the lineid $lineid is a line of ojbect + + $request_data = (object) $request_data; + $updateRes = $this->shipment->deleteline(DolibarrApiAccess::$user, $lineid); + if ($updateRes > 0) { + return $this->get($id); + } + else + { + throw new RestException(405, $this->shipment->error); + } + } + + /** + * Update shipment general fields (won't touch lines of shipment) + * + * @param int $id Id of shipment to update + * @param array $request_data Datas + * + * @return int + */ + public function put($id, $request_data = null) + { + if (!DolibarrApiAccess::$user->rights->expedition->creer) { + throw new RestException(401); + } + + $result = $this->shipment->fetch($id); + if (!$result) { + throw new RestException(404, 'Shipment not found'); + } + + if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + foreach ($request_data as $field => $value) { + if ($field == 'id') continue; + $this->shipment->$field = $value; + } + + if ($this->shipment->update(DolibarrApiAccess::$user) > 0) + { + return $this->get($id); + } + else + { + throw new RestException(500, $this->shipment->error); + } + } + + /** + * Delete shipment + * + * @param int $id Shipment ID + * + * @return array + */ + public function delete($id) + { + if (!DolibarrApiAccess::$user->rights->expedition->supprimer) { + throw new RestException(401); + } + $result = $this->shipment->fetch($id); + if (!$result) { + throw new RestException(404, 'Shipment not found'); + } + + if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + if (!$this->shipment->delete(DolibarrApiAccess::$user)) { + throw new RestException(500, 'Error when deleting shipment : '.$this->shipment->error); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'Shipment deleted' + ) + ); + } + + /** + * Validate a shipment + * + * This may record stock movements if module stock is enabled and option to + * decrease stock on shipment is on. + * + * @param int $id Shipment ID + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers + * + * @url POST {id}/validate + * + * @return array + * \todo An error 403 is returned if the request has an empty body. + * Error message: "Forbidden: Content type `text/plain` is not supported." + * Workaround: send this in the body + * { + * "notrigger": 0 + * } + */ + public function validate($id, $notrigger = 0) + { + if (!DolibarrApiAccess::$user->rights->expedition->creer) { + throw new RestException(401); + } + $result = $this->shipment->fetch($id); + if (!$result) { + throw new RestException(404, 'Shipment not found'); + } + + if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $result = $this->shipment->valid(DolibarrApiAccess::$user, $notrigger); + if ($result == 0) { + throw new RestException(304, 'Error nothing done. May be object is already validated'); + } + if ($result < 0) { + throw new RestException(500, 'Error when validating Shipment: '.$this->shipment->error); + } + $result = $this->shipment->fetch($id); + if (!$result) { + throw new RestException(404, 'Shipment not found'); + } + + if (!DolibarrApi::_checkAccessToResource('expedition', $this->shipment->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $this->shipment->fetchObjectLinked(); + return $this->_cleanObjectDatas($this->shipment); + } + + + // /** + // * Classify the shipment as invoiced + // * + // * @param int $id Id of the shipment + // * + // * @url POST {id}/setinvoiced + // * + // * @return int + // * + // * @throws RestException 400 + // * @throws RestException 401 + // * @throws RestException 404 + // * @throws RestException 405 + // */ + /* public function setinvoiced($id) { @@ -562,20 +567,20 @@ */ - // /** - // * Create a shipment using an existing order. - // * - // * @param int $orderid Id of the order - // * - // * @url POST /createfromorder/{orderid} - // * - // * @return int - // * @throws RestException 400 - // * @throws RestException 401 - // * @throws RestException 404 - // * @throws RestException 405 - // */ - /* + // /** + // * Create a shipment using an existing order. + // * + // * @param int $orderid Id of the order + // * + // * @url POST /createfromorder/{orderid} + // * + // * @return int + // * @throws RestException 400 + // * @throws RestException 401 + // * @throws RestException 404 + // * @throws RestException 405 + // */ + /* public function createShipmentFromOrder($orderid) { @@ -606,60 +611,60 @@ } */ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore - /** - * Clean sensible object datas - * - * @param Object $object Object to clean - * @return Object Object with cleaned properties - */ - protected function _cleanObjectDatas($object) - { - // phpcs:enable - $object = parent::_cleanObjectDatas($object); - - unset($object->thirdparty); // id already returned - - unset($object->note); - unset($object->address); - unset($object->barcode_type); - unset($object->barcode_type_code); - unset($object->barcode_type_label); - unset($object->barcode_type_coder); - - if (!empty($object->lines) && is_array($object->lines)) - { - foreach ($object->lines as $line) - { - unset($line->tva_tx); - unset($line->vat_src_code); - unset($line->total_ht); - unset($line->total_ttc); - unset($line->total_tva); - unset($line->total_localtax1); - unset($line->total_localtax2); - unset($line->remise_percent); - } - } - - return $object; - } - - /** - * Validate fields before create or update object - * - * @param array $data Array with data to verify - * @return array - * @throws RestException - */ - private function _validate($data) - { - $shipment = array(); - foreach (Shipments::$FIELDS as $field) { - if (!isset($data[$field])) - throw new RestException(400, "$field field missing"); - $shipment[$field] = $data[$field]; - } - return $shipment; - } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore + /** + * Clean sensible object datas + * + * @param object $object Object to clean + * @return array Array of cleaned object properties + */ + protected function _cleanObjectDatas($object) + { + // phpcs:enable + $object = parent::_cleanObjectDatas($object); + + unset($object->thirdparty); // id already returned + + unset($object->note); + unset($object->address); + unset($object->barcode_type); + unset($object->barcode_type_code); + unset($object->barcode_type_label); + unset($object->barcode_type_coder); + + if (!empty($object->lines) && is_array($object->lines)) + { + foreach ($object->lines as $line) + { + unset($line->tva_tx); + unset($line->vat_src_code); + unset($line->total_ht); + unset($line->total_ttc); + unset($line->total_tva); + unset($line->total_localtax1); + unset($line->total_localtax2); + unset($line->remise_percent); + } + } + + return $object; + } + + /** + * Validate fields before create or update object + * + * @param array $data Array with data to verify + * @return array + * @throws RestException + */ + private function _validate($data) + { + $shipment = array(); + foreach (Shipments::$FIELDS as $field) { + if (!isset($data[$field])) + throw new RestException(400, "$field field missing"); + $shipment[$field] = $data[$field]; + } + return $shipment; + } } --- /tmp/dsg/dolibarr/htdocs/expedition/class/github_expedition.class.php +++ /tmp/dsg/dolibarr/htdocs/expedition/class/client_expedition.class.php @@ -3,7 +3,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2007 Franky Van Liedekerke * Copyright (C) 2006-2012 Laurent Destailleur - * Copyright (C) 2011-2020 Juanjo Menent + * Copyright (C) 2011-2017 Juanjo Menent * Copyright (C) 2013 Florian Henry * Copyright (C) 2014 Cedric GROSS * Copyright (C) 2014-2015 Marcos García @@ -11,7 +11,7 @@ * Copyright (C) 2015 Claudio Aschieri * Copyright (C) 2016 Ferran Marcet * Copyright (C) 2018 Nicolas ZABOURI - * Copyright (C) 2018-2020 Frédéric France + * Copyright (C) 2018 Frédéric France * Copyright (C) 2020 Lenin Rivas * * This program is free software; you can redistribute it and/or modify @@ -36,7 +36,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; require_once DOL_DOCUMENT_ROOT."/core/class/commonobjectline.class.php"; -require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php'; if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; if (!empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php'; @@ -47,15 +46,13 @@ */ class Expedition extends CommonObject { - use CommonIncoterm; - /** * @var string ID to identify managed object */ public $element = "shipping"; /** - * @var string Field with ID of parent key if this field has a parent + * @var int Field with ID of parent key if this field has a parent */ public $fk_element = "fk_expedition"; @@ -65,7 +62,7 @@ public $table_element = "expedition"; /** - * @var string Name of subtable line + * @var int Name of subtable line */ public $table_element_line = "expeditiondet"; @@ -84,13 +81,6 @@ /** * @var string Customer ref - * @deprecated - * @see $ref_customer - */ - public $ref_client; - - /** - * @var string Customer ref */ public $ref_customer; @@ -106,6 +96,7 @@ * @var int warehouse id */ public $entrepot_id; + public $lines = array(); /** * @var string Tracking number @@ -158,8 +149,8 @@ public $date_shipping; /** - * @var integer|string date_creation - */ + * @var integer|string date_creation + */ public $date_creation; /** @@ -170,10 +161,7 @@ public $meths; public $listmeths; // List of carriers - public $lines = array(); - - - /** + /** * Draft status */ const STATUS_DRAFT = 0; @@ -204,6 +192,8 @@ global $conf; $this->db = $db; + $this->lines = array(); + $this->products = array(); // List of long language codes for status $this->statuts = array(); @@ -261,11 +251,15 @@ if ($numref != "") { return $numref; - } else { + } + else + { dol_print_error($this->db, get_class($this)."::getNextNumRef ".$obj->error); return ""; } - } else { + } + else + { print $langs->trans("Error")." ".$langs->trans("Error_EXPEDITION_ADDON_NUMBER_NotDefined"); return ""; } @@ -298,7 +292,6 @@ $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."expedition ("; - $sql .= "ref"; $sql .= ", entity"; $sql .= ", ref_customer"; @@ -338,10 +331,10 @@ $sql .= ", ".($this->fk_delivery_address > 0 ? $this->fk_delivery_address : "null"); $sql .= ", ".($this->shipping_method_id > 0 ? $this->shipping_method_id : "null"); $sql .= ", '".$this->db->escape($this->tracking_number)."'"; - $sql .= ", ".(is_numeric($this->weight) ? $this->weight : 'NULL'); - $sql .= ", ".(is_numeric($this->sizeS) ? $this->sizeS : 'NULL'); // TODO Should use this->trueDepth - $sql .= ", ".(is_numeric($this->sizeW) ? $this->sizeW : 'NULL'); // TODO Should use this->trueWidth - $sql .= ", ".(is_numeric($this->sizeH) ? $this->sizeH : 'NULL'); // TODO Should use this->trueHeight + $sql .= ", ".$this->weight; + $sql .= ", ".$this->sizeS; // TODO Should use this->trueDepth + $sql .= ", ".$this->sizeW; // TODO Should use this->trueWidth + $sql .= ", ".$this->sizeH; // TODO Should use this->trueHeight $sql .= ", ".($this->weight_units != '' ? (int) $this->weight_units : 'NULL'); $sql .= ", ".($this->size_units != '' ? (int) $this->size_units : 'NULL'); $sql .= ", ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null"); @@ -374,7 +367,9 @@ { $error++; } - } else { // with batch management + } + else + { // with batch management if (!$this->create_line_batch($this->lines[$i], $this->lines[$i]->array_options) > 0) { $error++; @@ -412,7 +407,9 @@ { $this->db->commit(); return $this->id; - } else { + } + else + { foreach ($this->errors as $errmsg) { dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); @@ -421,19 +418,25 @@ $this->db->rollback(); return -1 * $error; } - } else { + } + else + { $error++; $this->error = $this->db->lasterror()." - sql=$sql"; $this->db->rollback(); return -3; } - } else { + } + else + { $error++; $this->error = $this->db->lasterror()." - sql=$sql"; $this->db->rollback(); return -2; } - } else { + } + else + { $error++; $this->error = $this->db->error()." - sql=$sql"; $this->db->rollback(); @@ -441,7 +444,7 @@ } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Create a expedition line * @@ -473,7 +476,7 @@ } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Create the detail (eat-by date) of the expedition line * @@ -483,7 +486,7 @@ */ public function create_line_batch($line_ext, $array_options = 0) { - // phpcs:enable + // phpcs:enable $error = 0; $stockLocationQty = array(); // associated array with batch qty in stock location @@ -499,10 +502,12 @@ // create shipment lines foreach ($stockLocationQty as $stockLocation => $qty) { - $line_id = $this->create_line($stockLocation, $line_ext->origin_line_id, $qty, $line_ext->rang, $array_options); - if ($line_id < 0) { + if (($line_id = $this->create_line($stockLocation, $line_ext->origin_line_id, $qty, $line_ext->rang, $array_options)) < 0) + { $error++; - } else { + } + else + { // create shipment batch lines for stockLocation foreach ($tab as $detbatch) { @@ -537,7 +542,7 @@ if (empty($id) && empty($ref) && empty($ref_ext)) return -1; $sql = "SELECT e.rowid, e.entity, e.ref, e.fk_soc as socid, e.date_creation, e.ref_customer, e.ref_ext, e.ref_int, e.fk_user_author, e.fk_statut, e.fk_projet as fk_project, e.billed"; - $sql .= ", e.date_valid"; + $sql .= ", e.date_valid"; $sql .= ", e.weight, e.weight_units, e.size, e.size_units, e.width, e.height"; $sql .= ", e.date_expedition as date_expedition, e.model_pdf, e.fk_address, e.date_delivery"; $sql .= ", e.fk_shipping_method, e.tracking_number"; @@ -574,13 +579,12 @@ $this->statut = $obj->fk_statut; $this->user_author_id = $obj->fk_user_author; $this->date_creation = $this->db->jdate($obj->date_creation); - $this->date_valid = $this->db->jdate($obj->date_valid); + $this->date_valid = $this->db->jdate($obj->date_valid); $this->date = $this->db->jdate($obj->date_expedition); // TODO deprecated $this->date_expedition = $this->db->jdate($obj->date_expedition); // TODO deprecated $this->date_shipping = $this->db->jdate($obj->date_expedition); // Date real $this->date_delivery = $this->db->jdate($obj->date_delivery); // Date planed $this->fk_delivery_address = $obj->fk_address; - $this->model_pdf = $obj->model_pdf; $this->modelpdf = $obj->model_pdf; $this->shipping_method_id = $obj->fk_shipping_method; $this->shipping_method = $obj->shipping_method; @@ -619,17 +623,19 @@ // Tracking url $this->getUrlTrackingStatus($obj->tracking_number); - // Thirdparty - $result = $this->fetch_thirdparty(); // TODO Remove this - - // Retrieve extrafields + /* + * Thirdparty + */ + $result = $this->fetch_thirdparty(); + + // Retreive extrafields $this->fetch_optionals(); // Fix Get multicurrency param for transmited if (!empty($conf->multicurrency->enabled)) { if (!empty($this->multicurrency_code)) $this->multicurrency_code = $this->thirdparty->multicurrency_code; - if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($this->thirdparty->multicurrency_tx)) $this->multicurrency_tx = $this->thirdparty->multicurrency_tx; + if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) $this->multicurrency_tx = $this->thirdparty->multicurrency_tx; } /* @@ -642,12 +648,16 @@ } return 1; - } else { + } + else + { dol_syslog(get_class($this).'::Fetch no expedition found', LOG_ERR); $this->error = 'Delivery with id '.$id.' not found'; return 0; } - } else { + } + else + { $this->error = $this->db->error(); return -1; } @@ -698,7 +708,9 @@ if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life { $numref = $this->getNextNumRef($soc); - } else { + } + else + { $numref = "EXP".$this->id; } $this->newref = dol_sanitizeFileName($numref); @@ -707,7 +719,7 @@ // Validate $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET"; - $sql .= " ref='".$this->db->escape($numref)."'"; + $sql .= " ref='".$numref."'"; $sql .= ", fk_statut = 1"; $sql .= ", date_valid = '".$this->db->idate($now)."'"; $sql .= ", fk_user_valid = ".$user->id; @@ -749,7 +761,9 @@ if (empty($obj->edbrowid)) { $qty = $obj->qty; - } else { + } + else + { $qty = $obj->edbqty; } if ($qty <= 0) continue; @@ -771,7 +785,9 @@ $this->errors = array_merge($this->errors, $mouvS->errors); break; } - } else { + } + else + { // line with batch detail // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record. @@ -785,7 +801,9 @@ } } } - } else { + } + else + { $this->db->rollback(); $this->error = $this->db->error(); return -2; @@ -859,14 +877,16 @@ { $this->db->commit(); return 1; - } else { + } + else + { $this->db->rollback(); return -1 * $error; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Create a delivery receipt from a shipment * @@ -875,26 +895,30 @@ */ public function create_delivery($user) { - // phpcs:enable + // phpcs:enable global $conf; - if ($conf->delivery_note->enabled) + if ($conf->livraison_bon->enabled) { if ($this->statut == self::STATUS_VALIDATED || $this->statut == self::STATUS_CLOSED) { // Expedition validee - include_once DOL_DOCUMENT_ROOT.'/delivery/class/delivery.class.php'; - $delivery = new Delivery($this->db); + include_once DOL_DOCUMENT_ROOT.'/livraison/class/livraison.class.php'; + $delivery = new Livraison($this->db); $result = $delivery->create_from_sending($user, $this->id); if ($result > 0) { return $result; - } else { + } + else + { $this->error = $delivery->error; return $result; } - } else return 0; - } else return 0; + } + else return 0; + } + else return 0; } /** @@ -917,7 +941,6 @@ $line->entrepot_id = $entrepot_id; $line->origin_line_id = $id; - $line->fk_origin_line = $id; $line->qty = $qty; $orderline = new OrderLine($this->db); @@ -930,38 +953,33 @@ { $fk_product = $orderline->fk_product; - if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS)) { + if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS)) + { $langs->load("errors"); $this->error = $langs->trans("ErrorWarehouseRequiredIntoShipmentLine"); return -1; } - if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) { + if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) + { + // Check must be done for stock of product into warehouse if $entrepot_id defined $product = new Product($this->db); - $product->fetch($fk_product); - - // Check must be done for stock of product into warehouse if $entrepot_id defined + $result = $product->fetch($fk_product); + if ($entrepot_id > 0) { $product->load_stock('warehouseopen'); $product_stock = $product->stock_warehouse[$entrepot_id]->real; - } else { + } + else $product_stock = $product->stock_reel; - } $product_type = $product->type; - if ($product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { - $isavirtualproduct = ($product->hasFatherOrChild(1) > 0); - // The product is qualified for a check of quantity (must be enough in stock to be added into shipment). - if (!$isavirtualproduct || empty($conf->global->PRODUIT_SOUSPRODUITS) || ($isavirtualproduct && empty($conf->global->STOCK_EXCLUDE_VIRTUAL_PRODUCTS))) { // If STOCK_EXCLUDE_VIRTUAL_PRODUCTS is set, we do not manage stock for kits/virtual products. - if ($product_stock < $qty) { - $langs->load("errors"); - $this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref); - $this->errorhidden = 'ErrorStockIsNotEnoughToAddProductOnShipment'; - - $this->db->rollback(); - return -3; - } - } + if ($product_type == 0 && $product_stock < $qty) + { + $langs->load("errors"); + $this->error = $langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref); + $this->db->rollback(); + return -3; } } } @@ -980,7 +998,7 @@ $this->lines[$num] = $line; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Add a shipment line with batch record * @@ -990,7 +1008,7 @@ */ public function addline_batch($dbatch, $array_options = 0) { - // phpcs:enable + // phpcs:enable global $conf, $langs; $num = count($this->lines); @@ -1066,13 +1084,13 @@ // Clean parameters if (isset($this->ref)) $this->ref = trim($this->ref); - if (isset($this->entity)) $this->entity = (int) $this->entity; + if (isset($this->entity)) $this->entity = trim($this->entity); if (isset($this->ref_customer)) $this->ref_customer = trim($this->ref_customer); - if (isset($this->socid)) $this->socid = (int) $this->socid; - if (isset($this->fk_user_author)) $this->fk_user_author = (int) $this->fk_user_author; - if (isset($this->fk_user_valid)) $this->fk_user_valid = (int) $this->fk_user_valid; - if (isset($this->fk_delivery_address)) $this->fk_delivery_address = (int) $this->fk_delivery_address; - if (isset($this->shipping_method_id)) $this->shipping_method_id = (int) $this->shipping_method_id; + if (isset($this->socid)) $this->socid = trim($this->socid); + if (isset($this->fk_user_author)) $this->fk_user_author = trim($this->fk_user_author); + if (isset($this->fk_user_valid)) $this->fk_user_valid = trim($this->fk_user_valid); + if (isset($this->fk_delivery_address)) $this->fk_delivery_address = trim($this->fk_delivery_address); + if (isset($this->shipping_method_id)) $this->shipping_method_id = trim($this->shipping_method_id); if (isset($this->tracking_number)) $this->tracking_number = trim($this->tracking_number); if (isset($this->statut)) $this->statut = (int) $this->statut; if (isset($this->trueDepth)) $this->trueDepth = trim($this->trueDepth); @@ -1081,9 +1099,9 @@ if (isset($this->size_units)) $this->size_units = trim($this->size_units); if (isset($this->weight_units)) $this->weight_units = trim($this->weight_units); if (isset($this->trueWeight)) $this->weight = trim($this->trueWeight); - if (isset($this->note_private)) $this->note_private = trim($this->note_private); - if (isset($this->note_public)) $this->note_public = trim($this->note_public); - if (isset($this->model_pdf)) $this->model_pdf = trim($this->model_pdf); + if (isset($this->note_private)) $this->note = trim($this->note_private); + if (isset($this->note_public)) $this->note = trim($this->note_public); + if (isset($this->modelpdf)) $this->modelpdf = trim($this->modelpdf); @@ -1093,6 +1111,7 @@ // Update request $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET"; + $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; $sql .= " ref=".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "null").","; $sql .= " ref_ext=".(isset($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null").","; $sql .= " ref_customer=".(isset($this->ref_customer) ? "'".$this->db->escape($this->ref_customer)."'" : "null").","; @@ -1127,11 +1146,15 @@ $resql = $this->db->query($sql); if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } - if (!$error && !$notrigger) { - // Call trigger - $result = $this->call_trigger('SHIPPING_MODIFY', $user); - if ($result < 0) { $error++; } - // End call triggers + if (!$error) + { + if (!$notrigger) + { + // Call trigger + $result = $this->call_trigger('SHIPPING_MODIFY', $user); + if ($result < 0) { $error++; } + // End call triggers + } } // Commit or rollback @@ -1144,7 +1167,9 @@ } $this->db->rollback(); return -1 * $error; - } else { + } + else + { $this->db->commit(); return 1; } @@ -1155,7 +1180,7 @@ * Cancel shipment. * * @param int $notrigger Disable triggers - * @param bool $also_update_stock true if the stock should be increased back (false by default) + * @param bool $also_update_stock true if the stock should be increased back (false by default) * @return int >0 if OK, 0 if deletion done but failed to delete files, <0 if KO */ public function cancel($notrigger = 0, $also_update_stock = false) @@ -1165,27 +1190,32 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php'; - $error = 0; - $this->error = ''; + $error=0; + $this->error=''; $this->db->begin(); // Add a protection to refuse deleting if shipment has at least one delivery - $this->fetchObjectLinked($this->id, 'shipping', 0, 'delivery'); // Get deliveries linked to this shipment - if (count($this->linkedObjectsIds) > 0) { - $this->error = 'ErrorThereIsSomeDeliveries'; + $this->fetchObjectLinked($this->id, 'shipping', 0, 'delivery'); // Get deliveries linked to this shipment + if (count($this->linkedObjectsIds) > 0) + { + $this->error='ErrorThereIsSomeDeliveries'; $error++; } - if (!$error && !$notrigger) { - // Call trigger - $result = $this->call_trigger('SHIPPING_CANCEL', $user); - if ($result < 0) { $error++; } - // End call triggers + if (! $error) + { + if (! $notrigger) + { + // Call trigger + $result=$this->call_trigger('SHIPPING_CANCEL', $user); + if ($result < 0) { $error++; } + // End call triggers + } } // Stock control - if (!$error && $conf->stock->enabled && + if (! $error && $conf->stock->enabled && (($conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > self::STATUS_DRAFT) || ($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE && $this->statut == self::STATUS_CLOSED && $also_update_stock))) { @@ -1233,7 +1263,9 @@ $error++; $this->errors = $this->errors + $mouvS->errors; break; } - } else { + } + else + { // We increment stock of batches // We use warehouse selected for each line foreach ($lotArray as $lot) @@ -1248,7 +1280,9 @@ if ($error) break; // break for loop incase of error } } - } else { + } + else + { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } } @@ -1326,26 +1360,36 @@ } return 1; - } else { + } + else + { $this->db->rollback(); return -1; } - } else { + } + else + { $this->error = $this->db->lasterror()." - sql=$sql"; $this->db->rollback(); return -3; } - } else { + } + else + { $this->error = $this->db->lasterror()." - sql=$sql"; $this->db->rollback(); return -2; }//*/ - } else { + } + else + { $this->error = $this->db->lasterror()." - sql=$sql"; $this->db->rollback(); return -1; } - } else { + } + else + { $this->db->rollback(); return -1; } @@ -1356,7 +1400,7 @@ * Warning, do not delete a shipment if a delivery is linked to (with table llx_element_element) * * @param int $notrigger Disable triggers - * @param bool $also_update_stock true if the stock should be increased back (false by default) + * @param bool $also_update_stock true if the stock should be increased back (false by default) * @return int >0 if OK, 0 if deletion done but failed to delete files, <0 if KO */ public function delete($notrigger = 0, $also_update_stock = false) @@ -1379,11 +1423,15 @@ $error++; } - if (!$error && !$notrigger) { - // Call trigger - $result = $this->call_trigger('SHIPPING_DELETE', $user); - if ($result < 0) { $error++; } - // End call triggers + if (!$error) + { + if (!$notrigger) + { + // Call trigger + $result = $this->call_trigger('SHIPPING_DELETE', $user); + if ($result < 0) { $error++; } + // End call triggers + } } // Stock control @@ -1435,7 +1483,9 @@ $error++; $this->errors = $this->errors + $mouvS->errors; break; } - } else { + } + else + { // We increment stock of batches // We use warehouse selected for each line foreach ($lotArray as $lot) @@ -1450,7 +1500,9 @@ if ($error) break; // break for loop incase of error } } - } else { + } + else + { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } } @@ -1466,9 +1518,9 @@ if (!$error) { - $main = MAIN_DB_PREFIX.'expeditiondet'; - $ef = $main."_extrafields"; - $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_expedition = ".$this->id.")"; + $main = MAIN_DB_PREFIX.'expeditiondet'; + $ef = $main."_extrafields"; + $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_expedition = ".$this->id.")"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet"; $sql .= " WHERE fk_expedition = ".$this->id; @@ -1479,9 +1531,9 @@ $res = $this->deleteObjectLinked(); if ($res < 0) $error++; - // delete extrafields - $res = $this->deleteExtraFields(); - if ($res < 0) $error++; + // delete extrafields + $res = $this->deleteExtraFields(); + if ($res < 0) $error++; if (!$error) { @@ -1509,9 +1561,6 @@ if (!$error) { $this->db->commit(); - - // Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive - $this->deleteEcmFiles(); // We delete PDFs $ref = dol_sanitizeFileName($this->ref); @@ -1537,32 +1586,42 @@ } return 1; - } else { + } + else + { $this->db->rollback(); return -1; } - } else { + } + else + { $this->error = $this->db->lasterror()." - sql=$sql"; $this->db->rollback(); return -3; } - } else { + } + else + { $this->error = $this->db->lasterror()." - sql=$sql"; $this->db->rollback(); return -2; } - } else { + } + else + { $this->error = $this->db->lasterror()." - sql=$sql"; $this->db->rollback(); return -1; } - } else { + } + else + { $this->db->rollback(); return -1; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Load lines * @@ -1570,7 +1629,7 @@ */ public function fetch_lines() { - // phpcs:enable + // phpcs:enable global $conf, $mysoc; // TODO: recuperer les champs du document associe a part $this->lines = array(); @@ -1581,7 +1640,7 @@ $sql .= ", cd.fk_multicurrency, cd.multicurrency_code, cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc, cd.rang"; $sql .= ", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot"; $sql .= ", p.ref as product_ref, p.label as product_label, p.fk_product_type"; - $sql .= ", p.weight, p.weight_units, p.length, p.length_units, p.surface, p.surface_units, p.volume, p.volume_units, p.tosell as product_tosell, p.tobuy as product_tobuy, p.tobatch as product_tobatch"; + $sql .= ", p.weight, p.weight_units, p.length, p.length_units, p.surface, p.surface_units, p.volume, p.volume_units, p.tobatch as product_tobatch"; $sql .= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = cd.fk_product"; $sql .= " WHERE ed.fk_expedition = ".$this->id; @@ -1643,8 +1702,6 @@ $line->product_ref = $obj->product_ref; $line->product_label = $obj->product_label; $line->libelle = $obj->product_label; // TODO deprecated - $line->product_tosell = $obj->product_tosell; - $line->product_tobuy = $obj->product_tobuy; $line->product_tobatch = $obj->product_tobatch; $line->label = $obj->custom_label; $line->description = $obj->description; @@ -1715,7 +1772,9 @@ if ($originline != $obj->fk_origin_line) { $line->detail_batch = $newdetailbatch; - } else { + } + else + { $line->detail_batch = array_merge($line->detail_batch, $newdetailbatch); } } @@ -1725,20 +1784,24 @@ { $this->lines[$lineindex] = $line; $lineindex++; - } else { + } + else + { $line->total_ht += $tabprice[0]; $line->total_localtax1 += $tabprice[9]; $line->total_localtax2 += $tabprice[10]; $line->total_ttc += $tabprice[2]; $line->total_tva += $tabprice[1]; } - $line->fetch_optionals(); + $i++; $originline = $obj->fk_origin_line; } $this->db->free($resql); return 1; - } else { + } + else + { $this->error = $this->db->error(); return -3; } @@ -1770,11 +1833,15 @@ $this->db->commit(); return 1; - } else { + } + else + { $this->db->rollback(); return -1; } - } else { + } + else + { $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus'; return -2; } @@ -1848,7 +1915,7 @@ return $this->LibStatut($this->statut, $mode); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return label of a status * @@ -1858,8 +1925,8 @@ */ public function LibStatut($status, $mode) { - // phpcs:enable - global $langs; + // phpcs:enable + global $langs; $labelStatus = $langs->trans($this->statuts[$status]); $labelStatusShort = $langs->trans($this->statutshorts[$status]); @@ -1867,7 +1934,6 @@ $statusType = 'status'.$status; if ($status == self::STATUS_VALIDATED) $statusType = 'status4'; if ($status == self::STATUS_CLOSED) $statusType = 'status6'; - if ($status == self::STATUS_CANCELED) $statusType = 'status9'; return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode); } @@ -1952,52 +2018,43 @@ } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Set delivery date - * - * @param User $user Object user that modify - * @param int $delivery_date Delivery date - * @return int <0 if ko, >0 if ok - * @deprecated Use setDeliveryDate - */ - public function set_date_livraison($user, $delivery_date) - { - // phpcs:enable - return $this->setDeliveryDate($user, $delivery_date); - } - + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set the planned delivery date * * @param User $user Objet user that modify - * @param integer $delivery_date Date of delivery + * @param integer $date_livraison Date of delivery * @return int <0 if KO, >0 if OK */ - public function setDeliveryDate($user, $delivery_date) - { + public function set_date_livraison($user, $date_livraison) + { + // phpcs:enable if ($user->rights->expedition->creer) { $sql = "UPDATE ".MAIN_DB_PREFIX."expedition"; - $sql .= " SET date_delivery = ".($delivery_date ? "'".$this->db->idate($delivery_date)."'" : 'null'); + $sql .= " SET date_delivery = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null'); $sql .= " WHERE rowid = ".$this->id; - dol_syslog(get_class($this)."::setDeliveryDate", LOG_DEBUG); + dol_syslog(get_class($this)."::set_date_livraison", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - $this->date_delivery = $delivery_date; + $this->date_delivery = $date_livraison; return 1; - } else { + } + else + { $this->error = $this->db->error(); return -1; } - } else { + } + else + { return -2; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Fetch deliveries method and return an array. Load array this->meths(rowid=>label). * @@ -2005,7 +2062,7 @@ */ public function fetch_delivery_methods() { - // phpcs:enable + // phpcs:enable global $langs; $this->meths = array(); @@ -2025,7 +2082,7 @@ } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Fetch all deliveries method and return an array. Load array this->listmeths. * @@ -2034,7 +2091,7 @@ */ public function list_delivery_methods($id = '') { - // phpcs:enable + // phpcs:enable global $langs; $this->listmeths = array(); @@ -2061,7 +2118,7 @@ } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Update/create delivery method. * @@ -2071,13 +2128,15 @@ */ public function update_delivery_method($id = '') { - // phpcs:enable + // phpcs:enable if ($id == '') { $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_shipment_mode (code, libelle, description, tracking)"; $sql .= " VALUES ('".$this->db->escape($this->update['code'])."','".$this->db->escape($this->update['libelle'])."','".$this->db->escape($this->update['description'])."','".$this->db->escape($this->update['tracking'])."')"; $resql = $this->db->query($sql); - } else { + } + else + { $sql = "UPDATE ".MAIN_DB_PREFIX."c_shipment_mode SET"; $sql .= " code='".$this->db->escape($this->update['code'])."'"; $sql .= ",libelle='".$this->db->escape($this->update['libelle'])."'"; @@ -2089,7 +2148,7 @@ if ($resql < 0) dol_print_error($this->db, ''); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Activate delivery method. * @@ -2098,14 +2157,14 @@ */ public function activ_delivery_method($id) { - // phpcs:enable + // phpcs:enable $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=1'; $sql .= ' WHERE rowid='.$id; $resql = $this->db->query($sql); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * DesActivate delivery method. * @@ -2115,7 +2174,7 @@ */ public function disable_delivery_method($id) { - // phpcs:enable + // phpcs:enable $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=0'; $sql .= ' WHERE rowid='.$id; @@ -2151,7 +2210,9 @@ { $url = str_replace('{TRACKID}', $value, $tracking); $this->tracking_url = sprintf(''.($value ? $value : 'url').'', $url, $url); - } else { + } + else + { $this->tracking_url = $value; } } @@ -2241,7 +2302,9 @@ if (empty($obj->edbrowid)) { $qty = $obj->qty; - } else { + } + else + { $qty = $obj->edbqty; } if ($qty <= 0) continue; @@ -2261,7 +2324,9 @@ $this->errors = $mouvS->errors; $error++; break; } - } else { + } + else + { // line with batch detail // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record @@ -2273,7 +2338,9 @@ } } } - } else { + } + else + { $this->error = $this->db->lasterror(); $error++; } @@ -2287,7 +2354,9 @@ $error++; } } - } else { + } + else + { dol_print_error($this->db); $error++; } @@ -2296,14 +2365,16 @@ { $this->db->commit(); return 1; - } else { + } + else + { $this->statut = self::STATUS_VALIDATED; $this->db->rollback(); return -1; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Classify the shipping as invoiced (used when WORKFLOW_BILL_ON_SHIPMENT is on) * @@ -2311,7 +2382,7 @@ */ public function set_billed() { - // phpcs:enable + // phpcs:enable global $user; $error = 0; @@ -2339,7 +2410,9 @@ if (empty($error)) { $this->db->commit(); return 1; - } else { + } + else + { $this->statut = self::STATUS_VALIDATED; $this->billed = 0; $this->db->rollback(); @@ -2406,7 +2479,9 @@ if (empty($obj->edbrowid)) { $qty = $obj->qty; - } else { + } + else + { $qty = $obj->edbqty; } if ($qty <= 0) continue; @@ -2427,7 +2502,9 @@ $this->errors = $mouvS->errors; $error++; break; } - } else { + } + else + { // line with batch detail // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record @@ -2439,19 +2516,21 @@ } } } - } else { + } + else + { $this->error = $this->db->lasterror(); $error++; } } - if (!$error) { + if (!$error) { // Call trigger $result = $this->call_trigger('SHIPPING_REOPEN', $user); if ($result < 0) { $error++; } - } + } } else { $error++; $this->errors[] = $this->db->lasterror(); @@ -2461,7 +2540,9 @@ { $this->db->commit(); return 1; - } else { + } + else + { $this->statut = self::STATUS_CLOSED; $this->billed = $oldbilled; $this->db->rollback(); @@ -2477,21 +2558,19 @@ * @param int $hidedetails Hide details of lines * @param int $hidedesc Hide description * @param int $hideref Hide ref - * @param null|array $moreparams Array to provide more information + * @param null|array $moreparams Array to provide more information * @return int 0 if KO, 1 if OK */ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) { - global $conf; - - $outputlangs->load("products"); + global $conf, $langs; + + $langs->load("sendings"); if (!dol_strlen($modele)) { $modele = 'rouget'; - if (!empty($this->model_pdf)) { - $modele = $this->model_pdf; - } elseif (!empty($this->modelpdf)) { // deprecated + if ($this->modelpdf) { $modele = $this->modelpdf; } elseif (!empty($conf->global->EXPEDITION_ADDON_PDF)) { $modele = $conf->global->EXPEDITION_ADDON_PDF; @@ -2546,8 +2625,8 @@ public $origin_line_id; /** - * @var int ID - */ + * @var int ID + */ public $fk_origin_line; /** @@ -2556,42 +2635,42 @@ public $fk_expedition; /** - * @var DoliDB Database handler. - */ - public $db; - - /** - * @var float qty asked From llx_expeditiondet - */ - public $qty; - - /** - * @var float qty shipped - */ - public $qty_shipped; - - /** - * @var int Id of product - */ - public $fk_product; - public $detail_batch; - - /** - * @var int Id of warehouse - */ + * @var DoliDB Database handler. + */ + public $db; + + /** + * @var float qty asked From llx_expeditiondet + */ + public $qty; + + /** + * @var float qty shipped + */ + public $qty_shipped; + + /** + * @var int Id of product + */ + public $fk_product; + public $detail_batch; + + /** + * @var int Id of warehouse + */ public $entrepot_id; - /** - * @var float qty asked From llx_commandedet or llx_propaldet - */ + /** + * @var float qty asked From llx_commandedet or llx_propaldet + */ public $qty_asked; - /** - * @deprecated - * @see $product_ref - */ - public $ref; + /** + * @deprecated + * @see $product_ref + */ + public $ref; /** * @var string product ref @@ -2604,87 +2683,87 @@ */ public $libelle; - /** - * @var string product label - */ + /** + * @var string product label + */ public $product_label; - /** - * @var string product description - * @deprecated - * @see $product_desc - */ - public $desc; - - /** - * @var string product description - */ + /** + * @var string product description + * @deprecated + * @see $product_desc + */ + public $desc; + + /** + * @var string product description + */ public $product_desc; - /** - * @var int rang of line - */ - public $rang; - - /** - * @var float weight - */ - public $weight; - public $weight_units; - - /** - * @var float weight - */ - public $length; - public $length_units; - - /** - * @var float weight - */ - public $surface; - public $surface_units; - - /** - * @var float weight - */ - public $volume; - public $volume_units; + /** + * @var int rang of line + */ + public $rang; + + /** + * @var float weight + */ + public $weight; + public $weight_units; + + /** + * @var float weight + */ + public $length; + public $length_units; + + /** + * @var float weight + */ + public $surface; + public $surface_units; + + /** + * @var float weight + */ + public $volume; + public $volume_units; // Invoicing public $remise_percent; - public $tva_tx; - - /** - * @var float total without tax - */ - public $total_ht; - - /** - * @var float total with tax - */ - public $total_ttc; - - /** - * @var float total vat - */ - public $total_tva; - - /** - * @var float total localtax 1 - */ - public $total_localtax1; - - /** - * @var float total localtax 2 - */ - public $total_localtax2; - - - /** - * Constructor - * - * @param DoliDB $db Database handler - */ + public $tva_tx; + + /** + * @var float total without tax + */ + public $total_ht; + + /** + * @var float total with tax + */ + public $total_ttc; + + /** + * @var float total vat + */ + public $total_tva; + + /** + * @var float total localtax 1 + */ + public $total_localtax1; + + /** + * @var float total localtax 2 + */ + public $total_localtax2; + + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ public function __construct($db) { $this->db = $db; @@ -2715,7 +2794,9 @@ $this->db->free($result); return 1; - } else { + } + else + { $this->errors[] = $this->db->lasterror(); $this->error = $this->db->lasterror(); return -1; @@ -2750,7 +2831,7 @@ $ranktouse = $this->rang; if ($ranktouse == -1) { - $rangmax = $this->line_max($this->fk_expedition); + $rangmax = $this->line_max($fk_expedition); $ranktouse = $rangmax + 1; } @@ -2807,7 +2888,9 @@ $this->db->rollback(); return -1 * $error; - } else { + } + else + { $error++; } } @@ -2866,7 +2949,9 @@ } // End call triggers } - } else { + } + else + { $this->errors[] = $this->db->lasterror()." - sql=$sql"; $error++; } @@ -2874,7 +2959,9 @@ if (!$error) { $this->db->commit(); return 1; - } else { + } + else + { foreach ($this->errors as $errmsg) { dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); @@ -2916,7 +3003,9 @@ dol_syslog(get_class($this).'::update only possible for one batch', LOG_ERR); $this->errors[] = 'ErrorBadParameters'; $error++; - } else { + } + else + { $batch = $this->detail_batch[0]->batch; $batch_id = $this->detail_batch[0]->fk_origin_stock; $expedition_batch_id = $this->detail_batch[0]->id; @@ -2928,7 +3017,8 @@ } $qty = price2num($this->detail_batch[0]->qty); } - } elseif (!empty($this->detail_batch)) + } + elseif (!empty($this->detail_batch)) { $batch = $this->detail_batch->batch; $batch_id = $this->detail_batch->fk_origin_stock; @@ -2969,7 +3059,9 @@ { $this->errors[] = $this->db->lasterror()." - ExpeditionLineBatch::fetchAll"; $error++; - } else { + } + else + { // caculate new total line qty foreach ($lotArray as $lot) { @@ -3066,7 +3158,9 @@ if (!$error) { $this->db->commit(); return 1; - } else { + } + else + { foreach ($this->errors as $errmsg) { dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); --- /tmp/dsg/dolibarr/htdocs/expedition/class/github_expeditionbatch.class.php +++ /tmp/dsg/dolibarr/htdocs/expedition/class/client_expeditionbatch.class.php @@ -44,15 +44,15 @@ public $fk_origin_stock; public $fk_expeditiondet; - /** - * Constructor - * - * @param DoliDb $db Database handler - */ - public function __construct($db) - { - $this->db = $db; - } + /** + * Constructor + * + * @param DoliDb $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + } /** * Fill object based on a product-warehouse-batch's record @@ -90,7 +90,9 @@ $this->db->free($resql); return 1; - } else { + } + else + { $this->error = "Error ".$this->db->lasterror(); return -1; } @@ -130,14 +132,16 @@ if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.self::$_table_element); + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.self::$_table_element); $this->fk_expeditiondet = $id_line_expdet; return $this->id; - } else { + } + else + { foreach ($this->errors as $errmsg) { - dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); - $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } $this->db->rollback(); return -1 * $error; @@ -162,7 +166,9 @@ if ($db->query($sql)) { return 1; - } else { + } + else + { return -1; } } @@ -224,7 +230,9 @@ } $db->free($resql); return $ret; - } else { + } + else + { dol_print_error($db); return -1; } --- /tmp/dsg/dolibarr/htdocs/expedition/class/github_expeditionstats.class.php +++ /tmp/dsg/dolibarr/htdocs/expedition/class/client_expeditionstats.class.php @@ -34,38 +34,38 @@ */ class ExpeditionStats extends Stats { - /** - * @var string Name of table without prefix where object is stored - */ - public $table_element; + /** + * @var string Name of table without prefix where object is stored + */ + public $table_element; - public $socid; - public $userid; + public $socid; + public $userid; - public $from; - public $field; - public $where; + public $from; + public $field; + public $where; - /** - * Constructor - * - * @param DoliDB $db Database handler + /** + * Constructor + * + * @param DoliDB $db Database handler * @param int $socid Id third party for filter * @param string $mode Option (not used) * @param int $userid Id user for filter (creation user) - */ - public function __construct($db, $socid, $mode, $userid = 0) - { + */ + public function __construct($db, $socid, $mode, $userid = 0) + { global $user, $conf; $this->db = $db; $this->socid = ($socid > 0 ? $socid : 0); - $this->userid = $userid; + $this->userid = $userid; $this->cachefilesuffix = $mode; - $object = new Expedition($this->db); + $object = new Expedition($this->db); $this->from = MAIN_DB_PREFIX.$object->table_element." as c"; //$this->from.= ", ".MAIN_DB_PREFIX."societe as s"; $this->field = 'weight'; // Warning, unit of weight is NOT USED AND MUST BE @@ -78,31 +78,31 @@ { $this->where .= " AND c.fk_soc = ".$this->socid; } - if ($this->userid > 0) $this->where .= ' AND c.fk_user_author = '.$this->userid; - } + if ($this->userid > 0) $this->where .= ' AND c.fk_user_author = '.$this->userid; + } - /** - * Return shipment number by month for a year - * + /** + * Return shipment number by month for a year + * * @param int $year Year to scan - * @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month + * @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month * @return array Array with number by month - */ - public function getNbByMonth($year, $format = 0) - { - global $user; + */ + public function getNbByMonth($year, $format = 0) + { + global $user; - $sql = "SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb"; + $sql = "SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb"; $sql .= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql .= " WHERE c.date_valid BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); $res = $this->_getNbByMonth($year, $sql, $format); return $res; - } + } /** * Return shipments number per year @@ -119,7 +119,7 @@ if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql .= " WHERE ".$this->where; $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); return $this->_getNbByYear($sql); } @@ -138,7 +138,7 @@ if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql .= " WHERE ".$this->where; $sql .= " GROUP BY year"; - $sql .= $this->db->order('year', 'DESC'); + $sql .= $this->db->order('year', 'DESC'); return $this->_getAllByYear($sql); }