--- /tmp/dsg/dolibarr/htdocs/expedition/class/github_19.0.3_api_shipments.class.php +++ /tmp/dsg/dolibarr/htdocs/expedition/class/client_api_shipments.class.php @@ -31,704 +31,639 @@ - /** - * @var array $FIELDS Mandatory fields, checked when create and update object - */ - public 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 Object Object with cleaned properties - * - * @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')" - * @param string $properties Restrict the data returned to theses properties. Ignored if empty. Comma separated list of properties names - * @return array Array of shipment objects - * - * @throws RestException - */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '', $properties = '') - { - global $db, $conf; - - if (!DolibarrApiAccess::$user->rights->expedition->lire) { - throw new RestException(401); - } - - $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 LEFT JOIN ".MAIN_DB_PREFIX."expedition_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields - - 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 (".$this->db->sanitize($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 = ".((int) $search_sale); - } - // Add sql filters - if ($sqlfilters) { - $errormessage = ''; - $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage); - if ($errormessage) { - throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage); - } - } - - $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->_filterObjectProperties($this->_cleanObjectDatas($shipment_static), $properties); - } - $i++; - } - } else { - throw new RestException(503, 'Error when retrieve commande list : '.$this->db->lasterror()); - } - - 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) { - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $this->shipment->context['caller'] = $request_data['caller']; - continue; - } - - $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) { - 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->getLinesArray(); - $result = array(); - foreach ($this->shipment->lines as $line) { - array_push($result,$this->_cleanObjectDatas($line)); - } - return $result; - } - */ - - // /** - // * 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) { - 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); - } - - $request_data = (object) $request_data; - - $request_data->desc = sanitizeVal($request_data->desc, 'restricthtml'); - $request_data->label = sanitizeVal($request_data->label); - - $updateRes = $this->shipment->addline( - $request_data->desc, - $request_data->subprice, - $request_data->qty, - $request_data->tva_tx, - $request_data->localtax1_tx, - $request_data->localtax2_tx, - $request_data->fk_product, - $request_data->remise_percent, - $request_data->info_bits, - $request_data->fk_remise_except, - 'HT', - 0, - $request_data->date_start, - $request_data->date_end, - $request_data->product_type, - $request_data->rang, - $request_data->special_code, - $fk_parent_line, - $request_data->fk_fournprice, - $request_data->pa_ht, - $request_data->label, - $request_data->array_options, - $request_data->fk_unit, - $request_data->origin, - $request_data->origin_id, - $request_data->multicurrency_subprice - ); - - if ($updateRes > 0) { - return $updateRes; - - } - 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 - // */ - /* - public function putLine($id, $lineid, $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); - } - - $request_data = (object) $request_data; - - $request_data->desc = sanitizeVal($request_data->desc, 'restricthtml'); - $request_data->label = sanitizeVal($request_data->label); - - $updateRes = $this->shipment->updateline( - $lineid, - $request_data->desc, - $request_data->subprice, - $request_data->qty, - $request_data->remise_percent, - $request_data->tva_tx, - $request_data->localtax1_tx, - $request_data->localtax2_tx, - 'HT', - $request_data->info_bits, - $request_data->date_start, - $request_data->date_end, - $request_data->product_type, - $request_data->fk_parent_line, - 0, - $request_data->fk_fournprice, - $request_data->pa_ht, - $request_data->label, - $request_data->special_code, - $request_data->array_options, - $request_data->fk_unit, - $request_data->multicurrency_subprice - ); - - if ($updateRes > 0) { - $result = $this->get($id); - unset($result->line); - return $this->_cleanObjectDatas($result); - } - 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 - - $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; - } - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $this->shipment->context['caller'] = $request_data['caller']; - 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 object - * \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); - } - - // Reload shipment - $result = $this->shipment->fetch($id); - - $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) - { - - if(! DolibarrApiAccess::$user->rights->expedition->creer) { - throw new RestException(401); - } - if(empty($id)) { - throw new RestException(400, 'Shipment ID is mandatory'); - } - $result = $this->shipment->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Shipment not found'); - } - - $result = $this->shipment->classifyBilled(DolibarrApiAccess::$user); - if( $result < 0) { - throw new RestException(400, $this->shipment->error); - } - return $result; - } - */ - - - // /** - // * 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) - { - - require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php'; - - if(! DolibarrApiAccess::$user->rights->expedition->lire) { - throw new RestException(401); - } - if(! DolibarrApiAccess::$user->rights->expedition->creer) { - throw new RestException(401); - } - if(empty($proposalid)) { - throw new RestException(400, 'Order ID is mandatory'); - } - - $order = new Commande($this->db); - $result = $order->fetch($proposalid); - if( ! $result ) { - throw new RestException(404, 'Order not found'); - } - - $result = $this->shipment->createFromOrder($order, DolibarrApiAccess::$user); - if( $result < 0) { - throw new RestException(405, $this->shipment->error); - } - $this->shipment->fetchObjectLinked(); - return $this->_cleanObjectDatas($this->shipment); - } - */ - - /** - * Close a shipment (Classify it as "Delivered") - * - * @param int $id Expedition ID - * @param int $notrigger Disabled triggers - * - * @url POST {id}/close - * - * @return object - */ - public function close($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->setClosed(); - if ($result == 0) { - throw new RestException(304, 'Error nothing done. May be object is already closed'); - } - if ($result < 0) { - throw new RestException(500, 'Error when closing Order: '.$this->shipment->error); - } - - // Reload shipment - $result = $this->shipment->fetch($id); - - $this->shipment->fetchObjectLinked(); - - return $this->_cleanObjectDatas($this->shipment); - } - - // 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) { - if (is_array($line->detail_batch)) { - foreach ($line->detail_batch as $keytmp2 => $valtmp2) { - unset($line->detail_batch[$keytmp2]->db); - } - } - 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; - } + + /** + * @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) { + 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->getLinesArray(); + $result = array(); + foreach ($this->shipment->lines as $line) { + array_push($result,$this->_cleanObjectDatas($line)); + } + return $result; + } + */ + + // /** + // * 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) { + 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); + } + $request_data = (object) $request_data; + $updateRes = $this->shipment->addline( + $request_data->desc, + $request_data->subprice, + $request_data->qty, + $request_data->tva_tx, + $request_data->localtax1_tx, + $request_data->localtax2_tx, + $request_data->fk_product, + $request_data->remise_percent, + $request_data->info_bits, + $request_data->fk_remise_except, + 'HT', + 0, + $request_data->date_start, + $request_data->date_end, + $request_data->product_type, + $request_data->rang, + $request_data->special_code, + $fk_parent_line, + $request_data->fk_fournprice, + $request_data->pa_ht, + $request_data->label, + $request_data->array_options, + $request_data->fk_unit, + $request_data->origin, + $request_data->origin_id, + $request_data->multicurrency_subprice + ); + + if ($updateRes > 0) { + return $updateRes; + + } + 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 + // */ + /* + public function putLine($id, $lineid, $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); + } + $request_data = (object) $request_data; + $updateRes = $this->shipment->updateline( + $lineid, + $request_data->desc, + $request_data->subprice, + $request_data->qty, + $request_data->remise_percent, + $request_data->tva_tx, + $request_data->localtax1_tx, + $request_data->localtax2_tx, + 'HT', + $request_data->info_bits, + $request_data->date_start, + $request_data->date_end, + $request_data->product_type, + $request_data->fk_parent_line, + 0, + $request_data->fk_fournprice, + $request_data->pa_ht, + $request_data->label, + $request_data->special_code, + $request_data->array_options, + $request_data->fk_unit, + $request_data->multicurrency_subprice + ); + + if ($updateRes > 0) { + $result = $this->get($id); + unset($result->line); + return $this->_cleanObjectDatas($result); + } + 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 + // */ + /* + public function setinvoiced($id) + { + + if(! DolibarrApiAccess::$user->rights->expedition->creer) { + throw new RestException(401); + } + if(empty($id)) { + throw new RestException(400, 'Shipment ID is mandatory'); + } + $result = $this->shipment->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Shipment not found'); + } + + $result = $this->shipment->classifyBilled(DolibarrApiAccess::$user); + if( $result < 0) { + throw new RestException(400, $this->shipment->error); + } + return $result; + } + */ + + + // /** + // * 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) + { + + require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php'; + + if(! DolibarrApiAccess::$user->rights->expedition->lire) { + throw new RestException(401); + } + if(! DolibarrApiAccess::$user->rights->expedition->creer) { + throw new RestException(401); + } + if(empty($proposalid)) { + throw new RestException(400, 'Order ID is mandatory'); + } + + $order = new Commande($this->db); + $result = $order->fetch($proposalid); + if( ! $result ) { + throw new RestException(404, 'Order not found'); + } + + $result = $this->shipment->createFromOrder($order, DolibarrApiAccess::$user); + if( $result < 0) { + throw new RestException(405, $this->shipment->error); + } + $this->shipment->fetchObjectLinked(); + return $this->_cleanObjectDatas($this->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_19.0.3_expedition.class.php +++ /tmp/dsg/dolibarr/htdocs/expedition/class/client_expedition.class.php @@ -6 +6 @@ - * Copyright (C) 2011-2020 Juanjo Menent + * Copyright (C) 2011-2017 Juanjo Menent @@ -12 +12 @@ - * Copyright (C) 2016-2024 Ferran Marcet + * Copyright (C) 2016 Ferran Marcet @@ -14 +14 @@ - * Copyright (C) 2018-2022 Frédéric France + * Copyright (C) 2018 Frédéric France @@ -39,8 +39,3 @@ -require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php'; -if (isModEnabled("propal")) { - require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; -} -if (isModEnabled('commande')) { - require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; -} -require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionlinebatch.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'; @@ -54,2 +48,0 @@ - use CommonIncoterm; - @@ -62 +55 @@ - * @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 @@ -72 +65 @@ - * @var string Name of subtable line + * @var int Name of subtable line @@ -83,5 +75,0 @@ - * @var int Does object support extrafields ? 0=No, 1=Yes - */ - public $isextrafieldmanaged = 1; - - /** @@ -92,16 +79,0 @@ - - /** - * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. - */ - public $fields = array(); - - /** - * @var int ID of user author - */ - public $user_author_id; - - /** - * @var int ID of user author - */ - public $fk_user_author; - @@ -111,0 +84,5 @@ + */ + public $ref_customer; + + /** + * @var string internal ref @@ -113,8 +90,4 @@ - * @see $ref_customer - */ - public $ref_client; - - /** - * @var string Customer ref - */ - public $ref_customer; + */ + public $ref_int; + + public $brouillon; @@ -125,0 +99 @@ + public $lines = array(); @@ -154,17 +127,0 @@ - public $livraison_id; - - /** - * @var double - */ - public $multicurrency_subprice; - - public $size_units; - - public $sizeH; - - public $sizeS; - - public $sizeW; - - public $weight; - @@ -195,2 +152,2 @@ - * @var integer|string date_creation - */ + * @var integer|string date_creation + */ @@ -207,31 +164 @@ - /** - * @var int ID of order - */ - public $commande_id; - - /** - * @var Commande order - */ - public $commande; - - /** - * @var ExpeditionLigne[] array of shipping lines - */ - public $lines = array(); - - // Multicurrency - /** - * @var int Currency ID - */ - public $fk_multicurrency; - - /** - * @var string multicurrency code - */ - public $multicurrency_code; - public $multicurrency_tx; - public $multicurrency_total_ht; - public $multicurrency_total_tva; - public $multicurrency_total_ttc; - - /** + /** @@ -267,0 +195,2 @@ + $this->lines = array(); + $this->products = array(); @@ -270,5 +199,5 @@ - $this->labelStatus = array(); - $this->labelStatus[-1] = 'StatusSendingCanceled'; - $this->labelStatus[0] = 'StatusSendingDraft'; - $this->labelStatus[1] = 'StatusSendingValidated'; - $this->labelStatus[2] = 'StatusSendingProcessed'; + $this->statuts = array(); + $this->statuts[-1] = 'StatusSendingCanceled'; + $this->statuts[0] = 'StatusSendingDraft'; + $this->statuts[1] = 'StatusSendingValidated'; + $this->statuts[2] = 'StatusSendingProcessed'; @@ -277,9 +206,9 @@ - $this->labelStatusShort = array(); - $this->labelStatusShort[-1] = 'StatusSendingCanceledShort'; - $this->labelStatusShort[0] = 'StatusSendingDraftShort'; - $this->labelStatusShort[1] = 'StatusSendingValidatedShort'; - $this->labelStatusShort[2] = 'StatusSendingProcessedShort'; - } - - /** - * Return next expedition ref + $this->statutshorts = array(); + $this->statutshorts[-1] = 'StatusSendingCanceledShort'; + $this->statutshorts[0] = 'StatusSendingDraftShort'; + $this->statutshorts[1] = 'StatusSendingValidatedShort'; + $this->statutshorts[2] = 'StatusSendingProcessedShort'; + } + + /** + * Return next contract ref @@ -288 +217 @@ - * @return string Free reference for expedition + * @return string Free reference for contract @@ -295 +224,2 @@ - if (getDolGlobalString('EXPEDITION_ADDON_NUMBER')) { + if (!empty($conf->global->EXPEDITION_ADDON_NUMBER)) + { @@ -298 +228 @@ - $file = getDolGlobalString('EXPEDITION_ADDON_NUMBER') . ".php"; + $file = $conf->global->EXPEDITION_ADDON_NUMBER.".php"; @@ -311 +241,2 @@ - if (!$mybool) { + if (!$mybool) + { @@ -320 +251,2 @@ - if ($numref != "") { + if ($numref != "") + { @@ -322 +254,3 @@ - } else { + } + else + { @@ -326 +260,3 @@ - } else { + } + else + { @@ -337 +273 @@ - * @return int Return integer <0 si erreur, id expedition creee si ok + * @return int <0 si erreur, id expedition creee si ok @@ -348,0 +285 @@ + $this->brouillon = 1; @@ -350,3 +287 @@ - if (empty($this->fk_project)) { - $this->fk_project = 0; - } + if (empty($this->fk_project)) $this->fk_project = 0; @@ -354,0 +290 @@ + @@ -361,0 +298 @@ + $sql .= ", ref_int"; @@ -384 +321 @@ - $sql .= ", ".((int) $conf->entity); + $sql .= ", ".$conf->entity; @@ -385,0 +323 @@ + $sql .= ", ".($this->ref_int ? "'".$this->db->escape($this->ref_int)."'" : "null"); @@ -388 +326 @@ - $sql .= ", ".((int) $user->id); + $sql .= ", ".$user->id; @@ -391,2 +329,2 @@ - $sql .= ", ".($this->socid > 0 ? ((int) $this->socid) : "null"); - $sql .= ", ".($this->fk_project > 0 ? ((int) $this->fk_project) : "null"); + $sql .= ", ".$this->socid; + $sql .= ", ".$this->fk_project; @@ -394 +332 @@ - $sql .= ", ".($this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) : "null"); + $sql .= ", ".($this->shipping_method_id > 0 ? $this->shipping_method_id : "null"); @@ -396,4 +334,4 @@ - $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 @@ -411 +349,2 @@ - if ($resql) { + if ($resql) + { @@ -416 +355 @@ - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " WHERE rowid = ".$this->id; @@ -419 +358,2 @@ - if ($this->db->query($sql)) { + if ($this->db->query($sql)) + { @@ -422,10 +362,7 @@ - for ($i = 0; $i < $num; $i++) { - if (empty($this->lines[$i]->product_type) || getDolGlobalString('STOCK_SUPPORTS_SERVICES') || getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES')) { - if (!isset($this->lines[$i]->detail_batch)) { // no batch management - if ($this->create_line($this->lines[$i]->entrepot_id, $this->lines[$i]->origin_line_id, $this->lines[$i]->qty, $this->lines[$i]->rang, $this->lines[$i]->array_options) <= 0) { - $error++; - } - } else { // with batch management - if ($this->create_line_batch($this->lines[$i], $this->lines[$i]->array_options) <= 0) { - $error++; - } + for ($i = 0; $i < $num; $i++) + { + if (!isset($this->lines[$i]->detail_batch)) + { // no batch management + if (!$this->create_line($this->lines[$i]->entrepot_id, $this->lines[$i]->origin_line_id, $this->lines[$i]->qty, $this->lines[$i]->rang, $this->lines[$i]->array_options) > 0) + { + $error++; @@ -434,3 +371,11 @@ - } - - if (!$error && $this->id && $this->origin_id) { + else + { // with batch management + if (!$this->create_line_batch($this->lines[$i], $this->lines[$i]->array_options) > 0) + { + $error++; + } + } + } + + if (!$error && $this->id && $this->origin_id) + { @@ -438 +383,2 @@ - if (!$ret) { + if (!$ret) + { @@ -444 +390,2 @@ - if (!$error) { + if (!$error) + { @@ -446 +393,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -451 +399,2 @@ - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { @@ -454,3 +403 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } @@ -459 +406,2 @@ - if (!$error) { + if (!$error) + { @@ -462,2 +410,5 @@ - } else { - foreach ($this->errors as $errmsg) { + } + else + { + foreach ($this->errors as $errmsg) + { @@ -470 +421,3 @@ - } else { + } + else + { @@ -471,0 +425 @@ + $this->error = $this->db->lasterror()." - sql=$sql"; @@ -475 +429,3 @@ - } else { + } + else + { @@ -481 +437,3 @@ - } else { + } + else + { @@ -489 +447 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -498,3 +456,3 @@ - * @return int Return integer <0 if KO, line_id if OK - */ - public function create_line($entrepot_id, $origin_line_id, $qty, $rang = 0, $array_options = null) + * @return int <0 if KO, line_id if OK + */ + public function create_line($entrepot_id, $origin_line_id, $qty, $rang = 0, $array_options = 0) @@ -513 +471,2 @@ - if (($lineId = $expeditionline->insert($user)) < 0) { + if (($lineId = $expeditionline->insert($user)) < 0) + { @@ -520,5 +479,5 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Create the detail of the expedition line. Create 1 record into expeditiondet for each warehouse and n record for each lot in this warehouse into expeditiondet_batch. - * - * @param object $line_ext Objet with full information of line. $line_ext->detail_batch must be an array of ExpeditionLineBatch + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Create the detail (eat-by date) of the expedition line + * + * @param object $line_ext full line informations @@ -526 +485 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -530 +489 @@ - // phpcs:enable + // phpcs:enable @@ -536,5 +495,4 @@ - foreach ($tab as $detbatch) { - if (!empty($detbatch->entrepot_id)) { - if (empty($stockLocationQty[$detbatch->entrepot_id])) { - $stockLocationQty[$detbatch->entrepot_id] = 0; - } + foreach ($tab as $detbatch) + { + if ($detbatch->entrepot_id) + { @@ -545,3 +503,4 @@ - 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) { + foreach ($stockLocationQty as $stockLocation => $qty) + { + if (($line_id = $this->create_line($stockLocation, $line_ext->origin_line_id, $qty, $line_ext->rang, $array_options)) < 0) + { @@ -549 +508,3 @@ - } else { + } + else + { @@ -551 +512,2 @@ - foreach ($tab as $detbatch) { + foreach ($tab as $detbatch) + { @@ -553,2 +515,2 @@ - if (!($detbatch->create($line_id) > 0)) { // Create an ExpeditionLineBatch - $this->errors = $detbatch->errors; + if (!($detbatch->create($line_id) > 0)) // Create an expeditionlinebatch + { @@ -562,5 +524,2 @@ - if (!$error) { - return 1; - } else { - return -1; - } + if (!$error) return 1; + else return -1; @@ -583,6 +542,4 @@ - 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.fk_user_author, e.fk_statut, e.fk_projet as fk_project, e.billed"; - $sql .= ", e.date_valid"; + 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"; @@ -602,9 +559,4 @@ - if ($id) { - $sql .= " AND e.rowid = ".((int) $id); - } - if ($ref) { - $sql .= " AND e.ref='".$this->db->escape($ref)."'"; - } - if ($ref_ext) { - $sql .= " AND e.ref_ext='".$this->db->escape($ref_ext)."'"; - } + if ($id) $sql .= " AND e.rowid=".$id; + if ($ref) $sql .= " AND e.ref='".$this->db->escape($ref)."'"; + if ($ref_ext) $sql .= " AND e.ref_ext='".$this->db->escape($ref_ext)."'"; + if ($notused) $sql .= " AND e.ref_int='".$this->db->escape($notused)."'"; @@ -614,2 +566,4 @@ - if ($result) { - if ($this->db->num_rows($result)) { + if ($result) + { + if ($this->db->num_rows($result)) + { @@ -624,2 +578,2 @@ - $this->status = $obj->fk_statut; - $this->statut = $this->status; // Deprecated + $this->ref_int = $obj->ref_int; + $this->statut = $obj->fk_statut; @@ -627 +580,0 @@ - $this->fk_user_author = $obj->fk_user_author; @@ -629 +582 @@ - $this->date_valid = $this->db->jdate($obj->date_valid); + $this->date_valid = $this->db->jdate($obj->date_valid); @@ -635 +588 @@ - $this->model_pdf = $obj->model_pdf; + $this->modelpdf = $obj->model_pdf; @@ -667,0 +621,2 @@ + if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1; + @@ -671,4 +626,6 @@ - // Thirdparty - $result = $this->fetch_thirdparty(); // TODO Remove this - - // Retrieve extrafields + /* + * Thirdparty + */ + $result = $this->fetch_thirdparty(); + + // Retreive extrafields @@ -678,7 +635,4 @@ - if (isModEnabled('multicurrency')) { - if (!empty($this->multicurrency_code)) { - $this->multicurrency_code = $this->thirdparty->multicurrency_code; - } - if (getDolGlobalString('MULTICURRENCY_USE_ORIGIN_TX') && !empty($this->thirdparty->multicurrency_tx)) { - $this->multicurrency_tx = $this->thirdparty->multicurrency_tx; - } + 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($objectsrc->multicurrency_tx)) $this->multicurrency_tx = $this->thirdparty->multicurrency_tx; @@ -691 +645,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -696 +651,3 @@ - } else { + } + else + { @@ -698 +655 @@ - $this->error = 'Shipment with id '.$id.' not found'; + $this->error = 'Delivery with id '.$id.' not found'; @@ -701 +658,3 @@ - } else { + } + else + { @@ -712 +671 @@ - * @return int Return integer <0 if OK, >0 if KO + * @return int <0 if OK, >0 if KO @@ -716 +675 @@ - global $conf; + global $conf, $langs; @@ -723,2 +682,3 @@ - if ($this->status) { - dol_syslog(get_class($this)."::valid not in draft status", LOG_WARNING); + if ($this->statut) + { + dol_syslog(get_class($this)."::valid no draft status", LOG_WARNING); @@ -728,2 +688,3 @@ - if (!((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'creer')) - || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expedition', 'shipping_advance', 'validate')))) { + if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->creer)) + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->shipping_advance->validate)))) + { @@ -744 +705 @@ - $result = $soc->setAsCustomer(); + $result = $soc->set_as_client(); @@ -747 +708,2 @@ - if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life + if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life + { @@ -749,3 +711,3 @@ - } elseif (!empty($this->ref)) { - $numref = $this->ref; - } else { + } + else + { @@ -760 +722 @@ - $sql .= " ref='".$this->db->escape($numref)."'"; + $sql .= " ref='".$numref."'"; @@ -764 +726 @@ - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " WHERE rowid = ".$this->id; @@ -768 +730,2 @@ - if (!$resql) { + if (!$resql) + { @@ -774,3 +737,72 @@ - if (!$error && isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT')) { - $result = $this->manageStockMvtOnEvt($user, "ShipmentValidatedInDolibarr"); - if ($result < 0) { + if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)) + { + require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; + + $langs->load("agenda"); + + // Loop on each product line to add a stock movement + $sql = "SELECT cd.fk_product, cd.subprice,"; + $sql .= " ed.rowid, ed.qty, ed.fk_entrepot,"; + $sql .= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock"; + $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd,"; + $sql .= " ".MAIN_DB_PREFIX."expeditiondet as ed"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid"; + $sql .= " WHERE ed.fk_expedition = ".$this->id; + $sql .= " AND cd.rowid = ed.fk_origin_line"; + + dol_syslog(get_class($this)."::valid select details", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + $cpt = $this->db->num_rows($resql); + for ($i = 0; $i < $cpt; $i++) + { + $obj = $this->db->fetch_object($resql); + if (empty($obj->edbrowid)) + { + $qty = $obj->qty; + } + else + { + $qty = $obj->edbqty; + } + if ($qty <= 0) continue; + dol_syslog(get_class($this)."::valid movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid); + + //var_dump($this->lines[$i]); + $mouvS = new MouvementStock($this->db); + $mouvS->origin = &$this; + + if (empty($obj->edbrowid)) + { + // line without 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. + $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentValidatedInDolibarr", $numref)); + if ($result < 0) { + $error++; + $this->error = $mouvS->error; + $this->errors = array_merge($this->errors, $mouvS->errors); + break; + } + } + 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. + // Note: ->fk_origin_stock = id into table llx_product_batch (may be rename into llx_product_stock_batch in another version) + $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentValidatedInDolibarr", $numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock); + if ($result < 0) { + $error++; + $this->error = $mouvS->error; + $this->errors = array_merge($this->errors, $mouvS->errors); + break; + } + } + } + } + else + { + $this->db->rollback(); + $this->error = $this->db->error(); @@ -783 +815,3 @@ - if (!$ret) { + + if (!$ret) + { @@ -787 +821,2 @@ - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { @@ -790,3 +825 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } @@ -796 +829,2 @@ - if (!$error) { + if (!$error) + { @@ -800 +834,2 @@ - if (preg_match('/^[\(]?PROV/i', $this->ref)) { + if (preg_match('/^[\(]?PROV/i', $this->ref)) + { @@ -803 +838 @@ - $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'expedition/sending/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity); + $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'expedition/sending/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; @@ -805,11 +840 @@ - if (!$resql) { - $error++; - $this->error = $this->db->lasterror(); - } - $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'expedition/sending/".$this->db->escape($this->newref)."'"; - $sql .= " WHERE filepath = 'expedition/sending/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->error = $this->db->lasterror(); - } + if (!$resql) { $error++; $this->error = $this->db->lasterror(); } @@ -822 +847,2 @@ - if (!$error && file_exists($dirsource)) { + if (!$error && file_exists($dirsource)) + { @@ -825 +851,2 @@ - if (@rename($dirsource, $dirdest)) { + if (@rename($dirsource, $dirdest)) + { @@ -829 +856,2 @@ - foreach ($listoffiles as $fileentry) { + foreach ($listoffiles as $fileentry) + { @@ -842 +870,2 @@ - if (!$error) { + if (!$error) + { @@ -847 +876,2 @@ - if (!$error) { + if (!$error) + { @@ -850 +880,3 @@ - } else { + } + else + { @@ -857 +889 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -862 +894 @@ - * @return int Return integer <0 if KO, >=0 if OK + * @return int <0 if KO, >=0 if OK @@ -866 +898 @@ - // phpcs:enable + // phpcs:enable @@ -869,2 +901,4 @@ - if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) { - if ($this->statut == self::STATUS_VALIDATED || $this->statut == self::STATUS_CLOSED) { + if ($conf->livraison_bon->enabled) + { + if ($this->statut == self::STATUS_VALIDATED || $this->statut == self::STATUS_CLOSED) + { @@ -872,2 +906,2 @@ - 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); @@ -875 +909,2 @@ - if ($result > 0) { + if ($result > 0) + { @@ -877 +912,3 @@ - } else { + } + else + { @@ -881,6 +918,4 @@ - } else { - return 0; - } - } else { - return 0; - } + } + else return 0; + } + else return 0; @@ -893 +927,0 @@ - * Note: For product that need a batch number, you must use addline_batch() @@ -899 +933 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -910 +943,0 @@ - $line->fk_origin_line = $id; @@ -918,3 +951,3 @@ - $line->product_type = $orderline->product_type; - - if (isModEnabled('stock') && !empty($orderline->fk_product)) { + + if (!empty($conf->stock->enabled) && !empty($orderline->fk_product)) + { @@ -923 +956,2 @@ - if (!($entrepot_id > 0) && !getDolGlobalString('STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS') && !(getDolGlobalString('SHIPMENT_SUPPORTS_SERVICES') && $line->product_type == Product::TYPE_SERVICE)) { + if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS)) + { @@ -929 +963,3 @@ - if (getDolGlobalString('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 @@ -931,3 +967,2 @@ - $product->fetch($fk_product); - - // Check must be done for stock of product into warehouse if $entrepot_id defined + $result = $product->fetch($fk_product); + @@ -937 +972,2 @@ - } else { + } + else @@ -939 +974,0 @@ - } @@ -942,13 +977,6 @@ - if ($product_type == 0 || getDolGlobalString('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 || !getDolGlobalString('PRODUIT_SOUSPRODUITS') || ($isavirtualproduct && !getDolGlobalString('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; @@ -960,3 +988,3 @@ - // If this happen, we may have a bug in card.php page - if (isModEnabled('productbatch') && !empty($orderline->fk_product) && !empty($orderline->product_tobatch)) { - $this->error = 'ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH '.$orderline->id.' '.$orderline->fk_product; // + if (!empty($conf->productbatch->enabled) && !empty($orderline->fk_product) && !empty($orderline->product_tobatch)) + { + $this->error = 'ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH'; @@ -967 +995 @@ - if (!getDolGlobalString('MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) { // For avoid conflicts if trigger used + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used @@ -969 +996,0 @@ - } @@ -972,5 +999,3 @@ - - return 1; - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -982 +1007 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -986 +1011 @@ - // phpcs:enable + // phpcs:enable @@ -990 +1015,2 @@ - if ($dbatch['qty'] > 0 || ($dbatch['qty'] == 0 && getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) { + if ($dbatch['qty'] > 0) + { @@ -993,2 +1019,4 @@ - foreach ($dbatch['detail'] as $key => $value) { - if ($value['q'] > 0 || ($value['q'] == 0 && getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS'))) { + foreach ($dbatch['detail'] as $key=>$value) + { + if ($value['q'] > 0) + { @@ -1001,2 +1029,3 @@ - if ($ret < 0) { - $this->setErrorsFromObject($linebatch); + if ($ret < 0) + { + $this->error = $linebatch->error; @@ -1006,3 +1034,0 @@ - if ($linebatch->qty == 0 && getDolGlobalString('SHIPMENT_GETS_ALL_ORDER_PRODUCTS')) { - $linebatch->batch = null; - } @@ -1011 +1037,2 @@ - if (getDolGlobalString("STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT", '0')) { + if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) + { @@ -1016 +1043,2 @@ - if ($prod_batch->qty < $linebatch->qty) { + if ($prod_batch->qty < $linebatch->qty) + { @@ -1035 +1063 @@ - if (!getDolGlobalString('MAIN_EXTRAFIELDS_DISABLED') && is_array($array_options) && count($array_options) > 0) { // For avoid conflicts if trigger used + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used @@ -1037 +1064,0 @@ - } @@ -1043 +1069,0 @@ - return 0; @@ -1051 +1077 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -1060,57 +1086,21 @@ - if (isset($this->ref)) { - $this->ref = trim($this->ref); - } - if (isset($this->entity)) { - $this->entity = (int) $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->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); - } - if (isset($this->trueWidth)) { - $this->trueWidth = trim($this->trueWidth); - } - if (isset($this->trueHeight)) { - $this->trueHeight = trim($this->trueHeight); - } - 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->ref)) $this->ref = trim($this->ref); + 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 = 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); + if (isset($this->trueWidth)) $this->trueWidth = trim($this->trueWidth); + if (isset($this->trueHeight)) $this->trueHeight = trim($this->trueHeight); + 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 = trim($this->note_private); + if (isset($this->note_public)) $this->note = trim($this->note_public); + if (isset($this->modelpdf)) $this->modelpdf = trim($this->modelpdf); + + @@ -1122,0 +1113,2 @@ + + $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; @@ -1146 +1138 @@ - $sql .= " model_pdf=".(isset($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null").","; + $sql .= " model_pdf=".(isset($this->modelpdf) ? "'".$this->db->escape($this->modelpdf)."'" : "null").","; @@ -1148 +1140,2 @@ - $sql .= " WHERE rowid=".((int) $this->id); + + $sql .= " WHERE rowid=".$this->id; @@ -1154,12 +1147,11 @@ - 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 (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + + if (!$error) + { + if (!$notrigger) + { + // Call trigger + $result = $this->call_trigger('SHIPPING_MODIFY', $user); + if ($result < 0) { $error++; } + // End call triggers + } @@ -1169,2 +1161,4 @@ - if ($error) { - foreach ($this->errors as $errmsg) { + if ($error) + { + foreach ($this->errors as $errmsg) + { @@ -1176 +1170,3 @@ - } else { + } + else + { @@ -1187 +1183 @@ - * @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) @@ -1195,3 +1191,4 @@ - - $error = 0; - $this->error = ''; + require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php'; + + $error=0; + $this->error=''; @@ -1202,3 +1199,4 @@ - $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'; @@ -1208,7 +1206,9 @@ - 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 + } @@ -1218 +1218 @@ - if (!$error && isModEnabled('stock') && + if (! $error && $conf->stock->enabled && @@ -1220 +1220,2 @@ - ($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE && $this->statut == self::STATUS_CLOSED && $also_update_stock))) { + ($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE && $this->statut == self::STATUS_CLOSED && $also_update_stock))) + { @@ -1229 +1230 @@ - $sql .= " WHERE ed.fk_expedition = ".((int) $this->id); + $sql .= " WHERE ed.fk_expedition = ".$this->id; @@ -1234 +1235,2 @@ - if ($resql) { + if ($resql) + { @@ -1236,4 +1238,2 @@ - - $shipmentlinebatch = new ExpeditionLineBatch($this->db); - - for ($i = 0; $i < $cpt; $i++) { + for ($i = 0; $i < $cpt; $i++) + { @@ -1248,5 +1248,6 @@ - if (isModEnabled('productbatch')) { - $lotArray = $shipmentlinebatch->fetchAll($obj->expeditiondet_id); - if (!is_array($lotArray)) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); + if ($conf->productbatch->enabled) + { + $lotArray = ExpeditionLineBatch::fetchAll($this->db, $obj->expeditiondet_id); + if (!is_array($lotArray)) + { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); @@ -1255 +1255,0 @@ - @@ -1261,3 +1261,3 @@ - if ($result < 0) { - $error++; - $this->errors = array_merge($this->errors, $mouvS->errors); + if ($result < 0) + { + $error++; $this->errors = $this->errors + $mouvS->errors; @@ -1266 +1266,3 @@ - } else { + } + else + { @@ -1269 +1271,2 @@ - foreach ($lotArray as $lot) { + foreach ($lotArray as $lot) + { @@ -1271,3 +1274,3 @@ - if ($result < 0) { - $error++; - $this->errors = array_merge($this->errors, $mouvS->errors); + if ($result < 0) + { + $error++; $this->errors = $this->errors + $mouvS->errors; @@ -1277,3 +1280 @@ - if ($error) { - break; // break for loop incase of error - } + if ($error) break; // break for loop incase of error @@ -1282,3 +1283,4 @@ - } else { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); + } + else + { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); @@ -1289,10 +1291,11 @@ - if (!$error && isModEnabled('productbatch')) { - $shipmentlinebatch = new ExpeditionLineBatch($this->db); - if ($shipmentlinebatch->deleteFromShipment($this->id) < 0) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - } - - - if (!$error) { + if (!$error && $conf->productbatch->enabled) + { + if (ExpeditionLineBatch::deletefromexp($this->db, $this->id) < 0) + { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } + } + + + if (!$error) + { @@ -1300,3 +1303,4 @@ - $sql .= " WHERE fk_expedition = ".((int) $this->id); - - if ($this->db->query($sql)) { + $sql .= " WHERE fk_expedition = ".$this->id; + + if ($this->db->query($sql)) + { @@ -1305,3 +1309 @@ - if ($res < 0) { - $error++; - } + if ($res < 0) $error++; @@ -1310 +1312,2 @@ - if (!$error) { + if (!$error) + { @@ -1312,4 +1315,6 @@ - $sql .= " WHERE rowid = ".((int) $this->id); - - if ($this->db->query($sql)) { - if (!empty($this->origin) && $this->origin_id > 0) { + $sql .= " WHERE rowid = ".$this->id; + + if ($this->db->query($sql)) + { + if (!empty($this->origin) && $this->origin_id > 0) + { @@ -1318 +1323,2 @@ - if ($this->$origin->statut == Commande::STATUS_SHIPMENTONPROCESS) { // If order source of shipment is "shipment in progress" + if ($this->$origin->statut == Commande::STATUS_SHIPMENTONPROCESS) // If order source of shipment is "shipment in progress" + { @@ -1322 +1328,2 @@ - if (count($this->$origin->expeditions) <= 0) { + if (count($this->$origin->expeditions) <= 0) + { @@ -1328 +1335,2 @@ - if (!$error) { + if (!$error) + { @@ -1333 +1341,2 @@ - if (!empty($conf->expedition->dir_output)) { + if (!empty($conf->expedition->dir_output)) + { @@ -1336,2 +1345,4 @@ - if (file_exists($file)) { - if (!dol_delete_file($file)) { + if (file_exists($file)) + { + if (!dol_delete_file($file)) + { @@ -1341,2 +1352,4 @@ - if (file_exists($dir)) { - if (!dol_delete_dir_recursive($dir)) { + if (file_exists($dir)) + { + if (!dol_delete_dir_recursive($dir)) + { @@ -1350 +1363,3 @@ - } else { + } + else + { @@ -1354 +1369,3 @@ - } else { + } + else + { @@ -1359 +1376,3 @@ - } else { + } + else + { @@ -1364 +1383,3 @@ - } else { + } + else + { @@ -1369 +1390,3 @@ - } else { + } + else + { @@ -1380 +1403 @@ - * @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) @@ -1387,0 +1411 @@ + require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php'; @@ -1396 +1420,2 @@ - if (count($this->linkedObjectsIds) > 0) { + if (count($this->linkedObjectsIds) > 0) + { @@ -1401,7 +1426,9 @@ - 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 + } @@ -1411 +1438 @@ - if (!$error && isModEnabled('stock') && + if (!$error && $conf->stock->enabled && @@ -1413 +1440,2 @@ - ($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE && $this->statut == self::STATUS_CLOSED && $also_update_stock))) { + ($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE && $this->statut == self::STATUS_CLOSED && $also_update_stock))) + { @@ -1417,3 +1444,0 @@ - - // we try deletion of batch line even if module batch not enabled in case of the module were enabled and disabled previously - $shipmentlinebatch = new ExpeditionLineBatch($this->db); @@ -1425 +1450 @@ - $sql .= " WHERE ed.fk_expedition = ".((int) $this->id); + $sql .= " WHERE ed.fk_expedition = ".$this->id; @@ -1430 +1455,2 @@ - if ($resql) { + if ($resql) + { @@ -1432 +1458,2 @@ - for ($i = 0; $i < $cpt; $i++) { + for ($i = 0; $i < $cpt; $i++) + { @@ -1440,4 +1467,8 @@ - $lotArray = $shipmentlinebatch->fetchAll($obj->expeditiondet_id); - if (!is_array($lotArray)) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); + $lotArray = null; + if ($conf->productbatch->enabled) + { + $lotArray = ExpeditionLineBatch::fetchAll($this->db, $obj->expeditiondet_id); + if (!is_array($lotArray)) + { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } @@ -1450,3 +1481,3 @@ - if ($result < 0) { - $error++; - $this->errors = array_merge($this->errors, $mouvS->errors); + if ($result < 0) + { + $error++; $this->errors = $this->errors + $mouvS->errors; @@ -1455 +1486,3 @@ - } else { + } + else + { @@ -1458 +1491,2 @@ - foreach ($lotArray as $lot) { + foreach ($lotArray as $lot) + { @@ -1460,3 +1494,3 @@ - if ($result < 0) { - $error++; - $this->errors = array_merge($this->errors, $mouvS->errors); + if ($result < 0) + { + $error++; $this->errors = $this->errors + $mouvS->errors; @@ -1466,3 +1500 @@ - if ($error) { - break; // break for loop incase of error - } + if ($error) break; // break for loop incase of error @@ -1471,3 +1503,4 @@ - } else { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); + } + else + { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); @@ -1478,12 +1511,13 @@ - if (!$error) { - $shipmentlinebatch = new ExpeditionLineBatch($this->db); - if ($shipmentlinebatch->deleteFromShipment($this->id) < 0) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - } - - 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 = ".((int) $this->id).")"; + if (!$error && $conf->productbatch->enabled) + { + if (ExpeditionLineBatch::deletefromexp($this->db, $this->id) < 0) + { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } + } + + 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.")"; @@ -1492,3 +1526,4 @@ - $sql .= " WHERE fk_expedition = ".((int) $this->id); - - if ($this->db->query($sqlef) && $this->db->query($sql)) { + $sql .= " WHERE fk_expedition = ".$this->id; + + if ($this->db->query($sqlef) && $this->db->query($sql)) + { @@ -1497,11 +1532,8 @@ - if ($res < 0) { - $error++; - } - - // delete extrafields - $res = $this->deleteExtraFields(); - if ($res < 0) { - $error++; - } - - if (!$error) { + if ($res < 0) $error++; + + // delete extrafields + $res = $this->deleteExtraFields(); + if ($res < 0) $error++; + + if (!$error) + { @@ -1509,4 +1541,6 @@ - $sql .= " WHERE rowid = ".((int) $this->id); - - if ($this->db->query($sql)) { - if (!empty($this->origin) && $this->origin_id > 0) { + $sql .= " WHERE rowid = ".$this->id; + + if ($this->db->query($sql)) + { + if (!empty($this->origin) && $this->origin_id > 0) + { @@ -1515 +1549,2 @@ - if ($this->$origin->statut == Commande::STATUS_SHIPMENTONPROCESS) { // If order source of shipment is "shipment in progress" + if ($this->$origin->statut == Commande::STATUS_SHIPMENTONPROCESS) // If order source of shipment is "shipment in progress" + { @@ -1519 +1554,2 @@ - if (count($this->$origin->expeditions) <= 0) { + if (count($this->$origin->expeditions) <= 0) + { @@ -1525 +1561,2 @@ - if (!$error) { + if (!$error) + { @@ -1527,4 +1563,0 @@ - - // Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive - $this->deleteEcmFiles(0); // Deleting files physically is done later with the dol_delete_dir_recursive - $this->deleteEcmFiles(1); // Deleting files physically is done later with the dol_delete_dir_recursive @@ -1534 +1567,2 @@ - if (!empty($conf->expedition->dir_output)) { + if (!empty($conf->expedition->dir_output)) + { @@ -1537,2 +1571,4 @@ - if (file_exists($file)) { - if (!dol_delete_file($file)) { + if (file_exists($file)) + { + if (!dol_delete_file($file)) + { @@ -1542,2 +1578,4 @@ - if (file_exists($dir)) { - if (!dol_delete_dir_recursive($dir)) { + if (file_exists($dir)) + { + if (!dol_delete_dir_recursive($dir)) + { @@ -1551 +1589,3 @@ - } else { + } + else + { @@ -1555 +1595,3 @@ - } else { + } + else + { @@ -1560 +1602,3 @@ - } else { + } + else + { @@ -1565 +1609,3 @@ - } else { + } + else + { @@ -1570 +1616,3 @@ - } else { + } + else + { @@ -1576 +1624 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -1584 +1632 @@ - // phpcs:enable + // phpcs:enable @@ -1586 +1634 @@ - + // TODO: recuperer les champs du document associe a part @@ -1588,3 +1635,0 @@ - - // NOTE: This fetch_lines is special because it groups all lines with the same origin_line_id into one line. - // TODO: See if we can restore a common fetch_lines (one line = one record) @@ -1597,2 +1642,2 @@ - $sql .= ", p.ref as product_ref, p.label as product_label, p.fk_product_type, p.barcode as product_barcode"; - $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.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.tobatch as product_tobatch"; @@ -1601 +1646 @@ - $sql .= " WHERE ed.fk_expedition = ".((int) $this->id); + $sql .= " WHERE ed.fk_expedition = ".$this->id; @@ -1603 +1648 @@ - $sql .= " ORDER BY cd.rang, ed.fk_origin_line"; // We need after a break on fk_origin_line but when there is no break on fk_origin_line, cd.rang is same so we can add it as first order criteria. + $sql .= " ORDER BY cd.rang, ed.fk_origin_line"; @@ -1607 +1652,2 @@ - if ($resql) { + if ($resql) + { @@ -1621,7 +1667,4 @@ - $this->multicurrency_total_ht = 0; - $this->multicurrency_total_tva = 0; - $this->multicurrency_total_ttc = 0; - - $shipmentlinebatch = new ExpeditionLineBatch($this->db); - - while ($i < $num) { + $line = new ExpeditionLigne($this->db); + + while ($i < $num) + { @@ -1630,2 +1673 @@ - - if ($originline > 0 && $originline == $obj->fk_origin_line) { + if ($originline == $obj->fk_origin_line) { @@ -1635,6 +1677,6 @@ - $line = new ExpeditionLigne($this->db); // new group to start - $line->entrepot_id = $obj->fk_entrepot; // this is a property of a shipment line - $line->qty_shipped = $obj->qty_shipped; // this is a property of a shipment line - } - - $detail_entrepot = new stdClass(); + $line = new ExpeditionLigne($this->db); + $line->entrepot_id = $obj->fk_entrepot; + $line->qty_shipped = $obj->qty_shipped; + } + + $detail_entrepot = new stdClass; @@ -1663,3 +1704,0 @@ - $line->product_barcode = $obj->product_barcode; // Barcode number product - $line->product_tosell = $obj->product_tosell; - $line->product_tobuy = $obj->product_tobuy; @@ -1715,10 +1754,7 @@ - $line->multicurrency_subprice = $obj->multicurrency_subprice; - $line->multicurrency_total_ht = $obj->multicurrency_total_ht; - $line->multicurrency_total_tva = $obj->multicurrency_total_tva; - $line->multicurrency_total_ttc = $obj->multicurrency_total_ttc; - - $this->multicurrency_total_ht += $obj->multicurrency_total_ht; - $this->multicurrency_total_tva += $obj->multicurrency_total_tva; - $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc; - - if ($originline != $obj->fk_origin_line) { + $this->multicurrency_subprice = $obj->multicurrency_subprice; + $this->multicurrency_total_ht = $obj->multicurrency_total_ht; + $this->multicurrency_total_tva = $obj->multicurrency_total_tva; + $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc; + + if ($originline != $obj->fk_origin_line) + { @@ -1729,5 +1765,9 @@ - if (isModEnabled('productbatch') && $obj->line_id > 0 && $obj->product_tobatch > 0) { - $newdetailbatch = $shipmentlinebatch->fetchAll($obj->line_id, $obj->fk_product); - - if (is_array($newdetailbatch)) { - if ($originline != $obj->fk_origin_line) { + if (!empty($conf->productbatch->enabled) && $obj->line_id > 0 && $obj->product_tobatch > 0) + { + require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php'; + + $newdetailbatch = ExpeditionLineBatch::fetchAll($this->db, $obj->line_id, $obj->fk_product); + if (is_array($newdetailbatch)) + { + if ($originline != $obj->fk_origin_line) + { @@ -1735 +1775,3 @@ - } else { + } + else + { @@ -1741,3 +1783,2 @@ - $line->fetch_optionals(); - - if ($originline != $obj->fk_origin_line) { + if ($originline != $obj->fk_origin_line) + { @@ -1746 +1787,3 @@ - } else { + } + else + { @@ -1759 +1802,3 @@ - } else { + } + else + { @@ -1776 +1821,2 @@ - if ($this->statut == self::STATUS_DRAFT) { + if ($this->statut == self::STATUS_DRAFT) + { @@ -1784 +1830,2 @@ - if ($line->delete($user) > 0) { + if ($line->delete($user) > 0) + { @@ -1789 +1836,3 @@ - } else { + } + else + { @@ -1793 +1842,3 @@ - } else { + } + else + { @@ -1799,33 +1849,0 @@ - - /** - * getTooltipContentArray - * - * @param array $params ex option, infologin - * @since v18 - * @return array - */ - public function getTooltipContentArray($params) - { - global $conf, $langs; - - $langs->load('sendings'); - - $nofetch = !empty($params['nofetch']); - - $datas = array(); - $datas['picto'] = img_picto('', $this->picto).' '.$langs->trans("Shipment").''; - if (isset($this->statut)) { - $datas['picto'] .= ' '.$this->getLibStatut(5); - } - $datas['ref'] = '
'.$langs->trans('Ref').': '.$this->ref; - $datas['refcustomer'] = '
'.$langs->trans('RefCustomer').': '.($this->ref_customer ? $this->ref_customer : $this->ref_client); - if (!$nofetch) { - $langs->load('companies'); - if (empty($this->thirdparty)) { - $this->fetch_thirdparty(); - } - $datas['customer'] = '
'.$langs->trans('Customer').': '.$this->thirdparty->getNomUrl(1, '', 0, 1); - } - - return $datas; - } @@ -1846 +1864 @@ - global $langs, $hookmanager; + global $langs, $conf; @@ -1849,15 +1867,3 @@ - $params = [ - 'id' => $this->id, - 'objecttype' => $this->element, - 'option' => $option, - 'nofetch' => 1, - ]; - $classfortooltip = 'classfortooltip'; - $dataparams = ''; - if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) { - $classfortooltip = 'classforajaxtooltip'; - $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"'; - $label = ''; - } else { - $label = implode($this->getTooltipContentArray($params)); - } + $label = ''.$langs->trans("Shipment").''; + $label .= '
'.$langs->trans('Ref').': '.$this->ref; + $label .= '
'.$langs->trans('RefCustomer').': '.($this->ref_customer ? $this->ref_customer : $this->ref_client); @@ -1867,5 +1873,4 @@ - if ($short) { - return $url; - } - - if ($option !== 'nolink') { + if ($short) return $url; + + if ($option !== 'nolink') + { @@ -1874,6 +1879,2 @@ - if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { - $add_save_lastsearch_values = 1; - } - if ($add_save_lastsearch_values) { - $url .= '&save_lastsearch_values=1'; - } + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; @@ -1883,2 +1884,4 @@ - if (empty($notooltip)) { - if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { + if (empty($notooltip)) + { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { @@ -1888,2 +1891,2 @@ - $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"'); - $linkclose .= $dataparams.' class="'.$classfortooltip.'"'; + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="classfortooltip"'; @@ -1897,6 +1900,2 @@ - if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1); - } - if ($withpicto != 2) { - $result .= $this->ref; - } + if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + if ($withpicto != 2) $result .= $this->ref; @@ -1904,9 +1903 @@ - global $action; - $hookmanager->initHooks(array($this->element . 'dao')); - $parameters = array('id'=>$this->id, 'getnomurl' => &$result); - $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook > 0) { - $result = $hookmanager->resPrint; - } else { - $result .= $hookmanager->resPrint; - } + @@ -1920 +1911 @@ - * @return string Label + * @return string Libelle @@ -1927 +1918 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -1937,5 +1928,5 @@ - // phpcs:enable - global $langs; - - $labelStatus = $langs->transnoentitiesnoconv($this->labelStatus[$status]); - $labelStatusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]); + // phpcs:enable + global $langs; + + $labelStatus = $langs->trans($this->statuts[$status]); + $labelStatusShort = $langs->trans($this->statutshorts[$status]); @@ -1944,9 +1935,2 @@ - if ($status == self::STATUS_VALIDATED) { - $statusType = 'status4'; - } - if ($status == self::STATUS_CLOSED) { - $statusType = 'status6'; - } - if ($status == self::STATUS_CANCELED) { - $statusType = 'status9'; - } + if ($status == self::STATUS_VALIDATED) $statusType = 'status4'; + if ($status == self::STATUS_CLOSED) $statusType = 'status6'; @@ -1955,39 +1938,0 @@ - } - - /** - * Return clicable link of object (with eventually picto) - * - * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link) - * @param array $arraydata Array of data - * @return string HTML Code for Kanban thumb. - */ - public function getKanbanView($option = '', $arraydata = null) - { - global $langs, $conf; - - $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']); - - $return = '
'; - $return .= '
'; - $return .= '
'; - $return .= img_picto('', 'order'); - $return .= '
'; - $return .= '
'; - $return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).''; - if ($selected >= 0) { - $return .= ''; - } - if (property_exists($this, 'thirdparty') && is_object($this->thirdparty)) { - $return .= '
'.$this->thirdparty->getNomUrl(1).'
'; - } - if (property_exists($this, 'total_ht')) { - $return .= '
'.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency).' '.$langs->trans('HT').'
'; - } - if (method_exists($this, 'getLibStatut')) { - $return .= '
'.$this->getLibStatut(3).'
'; - } - $return .= '
'; - $return .= '
'; - $return .= '
'; - - return $return; @@ -2009,0 +1955,19 @@ + + // Load array of products prodids + $num_prods = 0; + $prodids = array(); + $sql = "SELECT rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."product"; + $sql .= " WHERE entity IN (".getEntity('product').")"; + $resql = $this->db->query($sql); + if ($resql) + { + $num_prods = $this->db->num_rows($resql); + $i = 0; + while ($i < $num_prods) + { + $i++; + $row = $this->db->fetch_row($resql); + $prodids[$i] = $row[0]; + } + } @@ -2023 +1987 @@ - $this->date_delivery = $now + 24 * 3600; + $this->date_delivery = $now; @@ -2041 +2005,2 @@ - while ($xnbp < $nbp) { + while ($xnbp < $nbp) + { @@ -2043,2 +2008,3 @@ - $line->product_desc = $langs->trans("Description")." ".$xnbp; - $line->product_label = $langs->trans("Description")." ".$xnbp; + $line->desc = $langs->trans("Description")." ".$xnbp; + $line->libelle = $langs->trans("Description")." ".$xnbp; // deprecated + $line->label = $langs->trans("Description")." ".$xnbp; @@ -2055,15 +2021 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Set delivery date - * - * @param User $user Object user that modify - * @param int $delivery_date Delivery date - * @return int Return integer <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 @@ -2074,6 +2026,8 @@ - * @param integer $delivery_date Date of delivery - * @return int Return integer <0 if KO, >0 if OK - */ - public function setDeliveryDate($user, $delivery_date) - { - if ($user->hasRight('expedition', 'creer')) { + * @param integer $date_livraison Date of delivery + * @return int <0 if KO, >0 if OK + */ + public function set_date_livraison($user, $date_livraison) + { + // phpcs:enable + if ($user->rights->expedition->creer) + { @@ -2081,4 +2035,4 @@ - $sql .= " SET date_delivery = ".($delivery_date ? "'".$this->db->idate($delivery_date)."'" : 'null'); - $sql .= " WHERE rowid = ".((int) $this->id); - - dol_syslog(get_class($this)."::setDeliveryDate", LOG_DEBUG); + $sql .= " SET date_delivery = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null'); + $sql .= " WHERE rowid = ".$this->id; + + dol_syslog(get_class($this)."::set_date_livraison", LOG_DEBUG); @@ -2086,2 +2040,3 @@ - if ($resql) { - $this->date_delivery = $delivery_date; + if ($resql) + { + $this->date_delivery = $date_livraison; @@ -2089 +2044,3 @@ - } else { + } + else + { @@ -2093 +2050,3 @@ - } else { + } + else + { @@ -2098 +2057 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2106 +2065 @@ - // phpcs:enable + // phpcs:enable @@ -2116,2 +2075,4 @@ - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { + if ($resql) + { + while ($obj = $this->db->fetch_object($resql)) + { @@ -2124 +2085 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2133 +2094 @@ - // phpcs:enable + // phpcs:enable @@ -2141,3 +2102 @@ - if ($id != '') { - $sql .= " WHERE em.rowid=".((int) $id); - } + if ($id != '') $sql .= " WHERE em.rowid=".$id; @@ -2146,2 +2105,4 @@ - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { + if ($resql) + { + while ($obj = $this->db->fetch_object($resql)) + { @@ -2159,0 +2121,64 @@ + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Update/create delivery method. + * + * @param string $id id method to activate + * + * @return void + */ + public function update_delivery_method($id = '') + { + // 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 + { + $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'])."'"; + $sql .= ",description='".$this->db->escape($this->update['description'])."'"; + $sql .= ",tracking='".$this->db->escape($this->update['tracking'])."'"; + $sql .= " WHERE rowid=".$id; + $resql = $this->db->query($sql); + } + if ($resql < 0) dol_print_error($this->db, ''); + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Activate delivery method. + * + * @param int $id id method to activate + * @return void + */ + public function activ_delivery_method($id) + { + // 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 + /** + * DesActivate delivery method. + * + * @param int $id id method to desactivate + * + * @return void + */ + public function disable_delivery_method($id) + { + // phpcs:enable + $sql = 'UPDATE '.MAIN_DB_PREFIX.'c_shipment_mode SET active=0'; + $sql .= ' WHERE rowid='.$id; + + $resql = $this->db->query($sql); + } + + @@ -2168 +2193,2 @@ - if (!empty($this->shipping_method_id)) { + if (!empty($this->shipping_method_id)) + { @@ -2171 +2197 @@ - $sql .= " WHERE em.rowid = ".((int) $this->shipping_method_id); + $sql .= " WHERE em.rowid = ".$this->shipping_method_id; @@ -2174,2 +2200,4 @@ - if ($resql) { - if ($obj = $this->db->fetch_object($resql)) { + if ($resql) + { + if ($obj = $this->db->fetch_object($resql)) + { @@ -2181 +2209,2 @@ - if (!empty($tracking) && !empty($value)) { + if (!empty($tracking) && !empty($value)) + { @@ -2183,2 +2212,4 @@ - $this->tracking_url = sprintf(''.($value ? $value : 'url').'', $url, $url); - } else { + $this->tracking_url = sprintf(''.($value ? $value : 'url').'', $url, $url); + } + else + { @@ -2190,3 +2221,3 @@ - * Classify the shipping as closed (this record also the stock movement) - * - * @return int Return integer <0 if KO, >0 if OK + * Classify the shipping as closed. + * + * @return int <0 if KO, >0 if OK @@ -2196 +2227 @@ - global $conf, $user; + global $conf, $langs, $user; @@ -2201 +2232,2 @@ - if ($this->statut == self::STATUS_CLOSED) { + if ($this->statut == self::STATUS_CLOSED) + { @@ -2207,2 +2239,2 @@ - $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET fk_statut = ".self::STATUS_CLOSED; - $sql .= " WHERE rowid = ".((int) $this->id)." AND fk_statut > 0"; + $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut='.self::STATUS_CLOSED; + $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; @@ -2211 +2243,2 @@ - if ($resql) { + if ($resql) + { @@ -2213 +2246,2 @@ - if ($this->origin == 'commande' && $this->origin_id > 0) { + if ($this->origin == 'commande' && $this->origin_id > 0) + { @@ -2220 +2254,2 @@ - foreach ($order->lines as $line) { + foreach ($order->lines as $line) + { @@ -2223 +2258,2 @@ - if (($line->product_type == 0 || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) && $order->expeditions[$lineid] != $qty) { + if (($line->product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->expeditions[$lineid] != $qty) + { @@ -2230,9 +2266,9 @@ - if ($shipments_match_order) { - dol_syslog("Qty for the ".count($order->lines)." lines of the origin order is same than qty for lines in the shipment we close (shipments_match_order is true), with new status Expedition::STATUS_CLOSED=".self::STATUS_CLOSED.', so we close order'); - // We close the order - $order->cloture($user); // Note this may also create an invoice if module workflow ask it - } - } - - $this->statut = self::STATUS_CLOSED; // Will be revert to STATUS_VALIDATED at end if there is a rollback - $this->status = self::STATUS_CLOSED; // Will be revert to STATUS_VALIDATED at end if there is a rollback + if ($shipments_match_order) + { + dol_syslog("Qty for the ".count($order->lines)." lines of order have same value for shipments with status Expedition::STATUS_CLOSED=".self::STATUS_CLOSED.', so we close order'); + $order->cloture($user); + } + } + + $this->statut = self::STATUS_CLOSED; + @@ -2241,3 +2277,68 @@ - if (!$error && isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) { - $result = $this->manageStockMvtOnEvt($user); - if ($result<0) { + if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) + { + require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; + + $langs->load("agenda"); + + // Loop on each product line to add a stock movement + // TODO possibilite d'expedier a partir d'une propale ou autre origine ? + $sql = "SELECT cd.fk_product, cd.subprice,"; + $sql .= " ed.rowid, ed.qty, ed.fk_entrepot,"; + $sql .= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock"; + $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd,"; + $sql .= " ".MAIN_DB_PREFIX."expeditiondet as ed"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid"; + $sql .= " WHERE ed.fk_expedition = ".$this->id; + $sql .= " AND cd.rowid = ed.fk_origin_line"; + + dol_syslog(get_class($this)."::valid select details", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + $cpt = $this->db->num_rows($resql); + for ($i = 0; $i < $cpt; $i++) + { + $obj = $this->db->fetch_object($resql); + if (empty($obj->edbrowid)) + { + $qty = $obj->qty; + } + else + { + $qty = $obj->edbqty; + } + if ($qty <= 0) continue; + dol_syslog(get_class($this)."::valid movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid); + + $mouvS = new MouvementStock($this->db); + $mouvS->origin = &$this; + + if (empty($obj->edbrowid)) + { + // line without 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 + $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentClassifyClosedInDolibarr", $numref)); + if ($result < 0) { + $this->error = $mouvS->error; + $this->errors = $mouvS->errors; + $error++; break; + } + } + 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 + $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans("ShipmentClassifyClosedInDolibarr", $numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock); + if ($result < 0) { + $this->error = $mouvS->error; + $this->errors = $mouvS->errors; + $error++; break; + } + } + } + } + else + { + $this->error = $this->db->lasterror(); @@ -2249 +2350,2 @@ - if (!$error) { + if (!$error) + { @@ -2255 +2357,3 @@ - } else { + } + else + { @@ -2260 +2364,2 @@ - if (!$error) { + if (!$error) + { @@ -2263 +2368,3 @@ - } else { + } + else + { @@ -2265,2 +2371,0 @@ - $this->status = self::STATUS_VALIDATED; - @@ -2272,98 +2377,9 @@ - /** - * Manage Stock MVt onb Close or valid Shipment - * - * @param User $user Object user that modify - * @param string $labelmovement Label of movement - * @return int Return integer <0 if KO, >0 if OK - * @throws Exception - * - */ - private function manageStockMvtOnEvt($user, $labelmovement = 'ShipmentClassifyClosedInDolibarr') - { - global $langs; - - $error=0; - - require_once DOL_DOCUMENT_ROOT . '/product/stock/class/mouvementstock.class.php'; - - $langs->load("agenda"); - - // Loop on each product line to add a stock movement - $sql = "SELECT cd.fk_product, cd.subprice,"; - $sql .= " ed.rowid, ed.qty, ed.fk_entrepot,"; - $sql .= " e.ref,"; - $sql .= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock,"; - $sql .= " cd.rowid as cdid, ed.rowid as edid"; - $sql .= " FROM " . MAIN_DB_PREFIX . "commandedet as cd,"; - $sql .= " " . MAIN_DB_PREFIX . "expeditiondet as ed"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "expeditiondet_batch as edb on edb.fk_expeditiondet = ed.rowid"; - $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "expedition as e ON ed.fk_expedition = e.rowid"; - $sql .= " WHERE ed.fk_expedition = " . ((int) $this->id); - $sql .= " AND cd.rowid = ed.fk_origin_line"; - - dol_syslog(get_class($this) . "::valid select details", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - $cpt = $this->db->num_rows($resql); - for ($i = 0; $i < $cpt; $i++) { - $obj = $this->db->fetch_object($resql); - if (empty($obj->edbrowid)) { - $qty = $obj->qty; - } else { - $qty = $obj->edbqty; - } - if ($qty <= 0 || ($qty < 0 && !getDolGlobalInt('SHIPMENT_ALLOW_NEGATIVE_QTY'))) { - continue; - } - dol_syslog(get_class($this) . "::valid movement index " . $i . " ed.rowid=" . $obj->rowid . " edb.rowid=" . $obj->edbrowid); - - $mouvS = new MouvementStock($this->db); - $mouvS->origin = &$this; - $mouvS->setOrigin($this->element, $this->id, $obj->cdid, $obj->edid); - - if (empty($obj->edbrowid)) { - // line without 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 - $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans($labelmovement, $obj->ref)); - if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; - $error++; - break; - } - } 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 - $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $qty, $obj->subprice, $langs->trans($labelmovement, $obj->ref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock); - if ($result < 0) { - $this->error = $mouvS->error; - $this->errors = $mouvS->errors; - $error++; - break; - } - } - - // If some stock lines are now 0, we can remove entry into llx_product_stock, but only if there is no child lines into llx_product_batch (detail of batch, because we can imagine - // having a lot1/qty=X and lot2/qty=-X, so 0 but we must not loose repartition of different lot. - $sqldelete = "DELETE FROM ".MAIN_DB_PREFIX."product_stock WHERE reel = 0 AND rowid NOT IN (SELECT fk_product_stock FROM ".MAIN_DB_PREFIX."product_batch as pb)"; - $resqldelete = $this->db->query($sqldelete); - // We do not test error, it can fails if there is child in batch details - } - } else { - $this->error = $this->db->lasterror(); - $this->errors[] = $this->db->lasterror(); - $error ++; - } - - return $error; - } - - /** - * Classify the shipping as invoiced (used for exemple by trigger when WORKFLOW_SHIPPING_CLASSIFY_BILLED_INVOICE is on) - * - * @return int Return integer <0 if ko, >0 if ok - */ - public function setBilled() - { + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Classify the shipping as invoiced (used when WORKFLOW_BILL_ON_SHIPMENT is on) + * + * @return int <0 if ko, >0 if ok + */ + public function set_billed() + { + // phpcs:enable @@ -2375,2 +2391,2 @@ - $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET billed = 1'; - $sql .= " WHERE rowid = ".((int) $this->id).' AND fk_statut > 0'; + $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=2, billed=1'; // TODO Update only billed + $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; @@ -2379 +2395,3 @@ - if ($resql) { + if ($resql) + { + $this->statut = self::STATUS_CLOSED; @@ -2385 +2402,0 @@ - $this->billed = 0; @@ -2396 +2413,5 @@ - } else { + } + else + { + $this->statut = self::STATUS_VALIDATED; + $this->billed = 0; @@ -2403,10 +2424,13 @@ - * Set draft status - * - * @param User $user Object user that modify - * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers - * @return int Return integer <0 if KO, >0 if OK - */ - public function setDraft($user, $notrigger = 0) - { - // Protection - if ($this->statut <= self::STATUS_DRAFT) { + * Classify the shipping as validated/opened + * + * @return int <0 if KO, 0 if already open, >0 if OK + */ + public function reOpen() + { + global $conf, $langs, $user; + + $error = 0; + + // Protection. This avoid to move stock later when we should not + if ($this->statut == self::STATUS_VALIDATED) + { @@ -2416,19 +2439,0 @@ - return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'SHIPMENT_UNVALIDATE'); - } - - /** - * Classify the shipping as validated/opened - * - * @return int Return integer <0 if KO, 0 if already open, >0 if OK - */ - public function reOpen() - { - global $conf, $langs, $user; - - $error = 0; - - // Protection. This avoid to move stock later when we should not - if ($this->statut == self::STATUS_VALIDATED) { - return 0; - } - @@ -2439,2 +2444,2 @@ - $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut = 1'; - $sql .= " WHERE rowid = ".((int) $this->id).' AND fk_statut > 0'; + $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=1'; + $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; @@ -2443 +2448,2 @@ - if ($resql) { + if ($resql) + { @@ -2448 +2454,2 @@ - if (!$error && isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) { + if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) + { @@ -2461 +2468 @@ - $sql .= " WHERE ed.fk_expedition = ".((int) $this->id); + $sql .= " WHERE ed.fk_expedition = ".$this->id; @@ -2466 +2473,2 @@ - if ($resql) { + if ($resql) + { @@ -2468 +2476,2 @@ - for ($i = 0; $i < $cpt; $i++) { + for ($i = 0; $i < $cpt; $i++) + { @@ -2470 +2479,2 @@ - if (empty($obj->edbrowid)) { + if (empty($obj->edbrowid)) + { @@ -2472 +2482,3 @@ - } else { + } + else + { @@ -2475,3 +2487 @@ - if ($qty <= 0) { - continue; - } + if ($qty <= 0) continue; @@ -2483,3 +2493,3 @@ - $mouvS->setOrigin($this->element, $this->id); - - if (empty($obj->edbrowid)) { + + if (empty($obj->edbrowid)) + { @@ -2489 +2499 @@ - $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr", $this->ref)); + $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr", $numref)); @@ -2493,2 +2503 @@ - $error++; - break; + $error++; break; @@ -2496 +2505,3 @@ - } else { + } + else + { @@ -2500 +2511 @@ - $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr", $this->ref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock); + $result = $mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, -$qty, $obj->subprice, $langs->trans("ShipmentUnClassifyCloseddInDolibarr", $numref), '', $this->db->jdate($obj->eatby), $this->db->jdate($obj->sellby), $obj->batch, $obj->fk_origin_stock); @@ -2504,2 +2515 @@ - $error++; - break; + $error++; break; @@ -2509 +2519,3 @@ - } else { + } + else + { @@ -2515 +2527 @@ - if (!$error) { + if (!$error) { @@ -2521 +2533 @@ - } + } @@ -2527 +2539,2 @@ - if (!$error) { + if (!$error) + { @@ -2530 +2543,3 @@ - } else { + } + else + { @@ -2546 +2561 @@ - * @param null|array $moreparams Array to provide more information + * @param null|array $moreparams Array to provide more information @@ -2551,3 +2566,3 @@ - global $conf; - - $outputlangs->load("products"); + global $conf, $langs; + + $langs->load("sendings"); @@ -2558,3 +2573,3 @@ - if (!empty($this->model_pdf)) { - $modele = $this->model_pdf; - } elseif (getDolGlobalString('EXPEDITION_ADDON_PDF')) { + if ($this->modelpdf) { + $modele = $this->modelpdf; + } elseif (!empty($conf->global->EXPEDITION_ADDON_PDF)) { @@ -2575,6 +2590,6 @@ - * @param DoliDB $dbs Database handler, because function is static we name it $dbs not $db to avoid breaking coding test - * @param int $origin_id Old thirdparty id - * @param int $dest_id New thirdparty id - * @return bool - */ - public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id) + * @param DoliDB $db Database handler + * @param int $origin_id Old thirdparty id + * @param int $dest_id New thirdparty id + * @return bool + */ + public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id) @@ -2586 +2601 @@ - return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables); + return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); @@ -2606,9 +2620,0 @@ - - /** - * Id of the line. Duplicate of $id. - * - * @var int - * @deprecated - */ - public $line_id; // deprecated - @@ -2622,9 +2628,2 @@ - * Code of object line that is origin of the shipment line. - * - * @var string - */ - public $fk_origin; // Example: 'orderline' - - /** - * @var int ID - */ + * @var int ID + */ @@ -2639,31 +2638,23 @@ - * @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; - - // detail of lot and qty = array(id in llx_expeditiondet_batch, fk_expeditiondet, batch, qty, fk_origin_stock) - // We can use this to know warehouse planned to be used for each lot. - public $detail_batch; - - // detail of warehouses and qty - // We can use this to know warehouse when there is no lot. - public $details_entrepot; - - - /** - * @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 + */ @@ -2673,3 +2664,3 @@ - /** - * @var float qty asked From llx_commandedet or llx_propaldet - */ + /** + * @var float qty asked From llx_commandedet or llx_propaldet + */ @@ -2678,5 +2669,5 @@ - /** - * @deprecated - * @see $product_ref - */ - public $ref; + /** + * @deprecated + * @see $product_ref + */ + public $ref; @@ -2695,3 +2686,3 @@ - /** - * @var string product label - */ + /** + * @var string product label + */ @@ -2700,10 +2691,10 @@ - /** - * @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 + */ @@ -2712,34 +2703,28 @@ - /** - * Type of the product. 0 for product, 1 for service - * @var int - */ - public $product_type = 0; - - /** - * @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; @@ -2749,33 +2734,33 @@ - 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 + */ @@ -2791 +2776 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -2797 +2782 @@ - $sql .= ' WHERE ed.rowid = '.((int) $rowid); + $sql .= ' WHERE ed.rowid = '.$rowid; @@ -2799 +2784,2 @@ - if ($result) { + if ($result) + { @@ -2811 +2797,3 @@ - } else { + } + else + { @@ -2823 +2811 @@ - * @return int Return integer <0 if KO, line id >0 if OK + * @return int <0 if KO, line id >0 if OK @@ -2826,0 +2815,2 @@ + global $langs, $conf; + @@ -2830 +2820,2 @@ - if (empty($this->fk_expedition) || empty($this->fk_origin_line) || !is_numeric($this->qty)) { + if (empty($this->fk_expedition) || empty($this->fk_origin_line) || !is_numeric($this->qty)) + { @@ -2837,3 +2828 @@ - if (empty($this->rang)) { - $this->rang = 0; - } + if (empty($this->rang)) $this->rang = 0; @@ -2843,2 +2832,3 @@ - if ($ranktouse == -1) { - $rangmax = $this->line_max($this->fk_expedition); + if ($ranktouse == -1) + { + $rangmax = $this->line_max($fk_expedition); @@ -2857,3 +2847,3 @@ - $sql .= ", ".((int) $this->fk_origin_line); - $sql .= ", ".price2num($this->qty, 'MS'); - $sql .= ", ".((int) $ranktouse); + $sql .= ", ".$this->fk_origin_line; + $sql .= ", ".$this->qty; + $sql .= ", ".$ranktouse; @@ -2864 +2854,2 @@ - if ($resql) { + if ($resql) + { @@ -2867 +2858,2 @@ - if (!$error) { + if (!$error) + { @@ -2869 +2861,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -2874 +2867,2 @@ - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { @@ -2877 +2871,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -2883,7 +2878,16 @@ - if ($error) { - foreach ($this->errors as $errmsg) { - dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); - $this->error .= ($this->error ? ', '.$errmsg : $errmsg); - } - } - } else { + if (!$error) { + $this->db->commit(); + return $this->id; + } + + foreach ($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + } + + $this->db->rollback(); + return -1 * $error; + } + else + { @@ -2891,8 +2894,0 @@ - } - - if ($error) { - $this->db->rollback(); - return -1; - } else { - $this->db->commit(); - return $this->id; @@ -2910,0 +2907,2 @@ + global $conf; + @@ -2916 +2914,2 @@ - if (isModEnabled('productbatch')) { + if ($conf->productbatch->enabled) + { @@ -2918,3 +2917,4 @@ - $sql .= " WHERE fk_expeditiondet = ".((int) $this->id); - - if (!$this->db->query($sql)) { + $sql .= " WHERE fk_expeditiondet = ".$this->id; + + if (!$this->db->query($sql)) + { @@ -2927,3 +2927,4 @@ - $sql .= " WHERE rowid = ".((int) $this->id); - - if (!$error && $this->db->query($sql)) { + $sql .= " WHERE rowid = ".$this->id; + + if (!$error && $this->db->query($sql)) + { @@ -2931 +2932,2 @@ - if (!$error) { + if (!$error) + { @@ -2933 +2935,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -2938 +2941,2 @@ - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { @@ -2941 +2945,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -2947 +2952,3 @@ - } else { + } + else + { @@ -2955,2 +2962,5 @@ - } else { - foreach ($this->errors as $errmsg) { + } + else + { + foreach ($this->errors as $errmsg) + { @@ -2970 +2980 @@ - * @return int Return integer < 0 if KO, > 0 if OK + * @return int < 0 if KO, > 0 if OK @@ -2973,0 +2984,2 @@ + global $conf; + @@ -2981,3 +2993 @@ - if (empty($this->qty)) { - $this->qty = 0; - } + if (empty($this->qty)) $this->qty = 0; @@ -2989,2 +2999,4 @@ - if (is_array($this->detail_batch)) { // array of ExpeditionLineBatch - if (count($this->detail_batch) > 1) { + if (is_array($this->detail_batch)) // array of ExpeditionLineBatch + { + if (count($this->detail_batch) > 1) + { @@ -2994 +3006,3 @@ - } else { + } + else + { @@ -2998 +3012,2 @@ - if ($this->entrepot_id != $this->detail_batch[0]->entrepot_id) { + if ($this->entrepot_id != $this->detail_batch[0]->entrepot_id) + { @@ -3005 +3020,3 @@ - } elseif (!empty($this->detail_batch)) { + } + elseif (!empty($this->detail_batch)) + { @@ -3009 +3026,2 @@ - if ($this->entrepot_id != $this->detail_batch->entrepot_id) { + if ($this->entrepot_id != $this->detail_batch->entrepot_id) + { @@ -3018 +3036,2 @@ - if (!isset($this->id) || !isset($this->entrepot_id)) { + if (!isset($this->id) || !isset($this->entrepot_id)) + { @@ -3027 +3046,2 @@ - if (!empty($batch) && isModEnabled('productbatch')) { + if (!empty($batch) && $conf->productbatch->enabled) + { @@ -3037,3 +3057,3 @@ - $shipmentlinebatch = new ExpeditionLineBatch($this->db); - - if (!$error && ($lotArray = $shipmentlinebatch->fetchAll($this->id)) < 0) { + require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php'; + if (!$error && ($lotArray = ExpeditionLineBatch::fetchAll($this->db, $this->id)) < 0) + { @@ -3042 +3062,3 @@ - } else { + } + else + { @@ -3044,2 +3066,4 @@ - foreach ($lotArray as $lot) { - if ($expedition_batch_id != $lot->id) { + foreach ($lotArray as $lot) + { + if ($expedition_batch_id != $lot->id) + { @@ -3056 +3080,2 @@ - if ($lot->fetch(0, $this->fk_product, $batch) < 0) { + if ($lot->fetch(0, $this->fk_product, $batch) < 0) + { @@ -3060 +3085,2 @@ - if (!$error && !empty($expedition_batch_id)) { + if (!$error && !empty($expedition_batch_id)) + { @@ -3063,4 +3089,5 @@ - $sql .= " WHERE fk_expeditiondet = ".((int) $this->id); - $sql .= " AND rowid = ".((int) $expedition_batch_id); - - if (!$this->db->query($sql)) { + $sql .= " WHERE fk_expeditiondet = ".$this->id; + $sql .= " AND rowid = ".$expedition_batch_id; + + if (!$this->db->query($sql)) + { @@ -3071 +3098,2 @@ - if (!$error && $this->detail_batch->qty > 0) { + if (!$error && $this->detail_batch->qty > 0) + { @@ -3073 +3101,2 @@ - if (isset($lot->id)) { + if (isset($lot->id)) + { @@ -3081,2 +3110,3 @@ - if ($shipmentLot->create($this->id) < 0) { - $this->errors = $shipmentLot->errors; + if ($shipmentLot->create($this->id) < 0) + { + $this->errors[] = $shipmentLot->errors; @@ -3089 +3119,2 @@ - if (!$error) { + if (!$error) + { @@ -3093,4 +3124,5 @@ - $sql .= " , qty = ".((float) price2num($qty, 'MS')); - $sql .= " WHERE rowid = ".((int) $this->id); - - if (!$this->db->query($sql)) { + $sql .= " , qty = ".$qty; + $sql .= " WHERE rowid = ".$this->id; + + if (!$this->db->query($sql)) + { @@ -3102,2 +3134,4 @@ - if (!$error) { - if (!$error) { + if (!$error) + { + if (!$error) + { @@ -3105 +3139,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -3112 +3147,2 @@ - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { @@ -3114,2 +3150,3 @@ - $result = $this->call_trigger('LINESHIPPING_MODIFY', $user); - if ($result < 0) { + $result = $this->call_trigger('LINESHIPPING_UPDATE', $user); + if ($result < 0) + { @@ -3124,2 +3161,5 @@ - } else { - foreach ($this->errors as $errmsg) { + } + else + { + foreach ($this->errors as $errmsg) + { --- /tmp/dsg/dolibarr/htdocs/expedition/class/github_19.0.3_expeditionbatch.class.php +++ /tmp/dsg/dolibarr/htdocs/expedition/class/client_expeditionbatch.class.php @@ -0,0 +1,240 @@ + + * Copyright (C) 2013-2014 Cedric GROSS + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file expedition/class/expeditionbatch.class.php + * \ingroup productbatch + * \brief This file implements CRUD method for managing shipment batch lines + * with batch record + */ + +/** + * CRUD class for batch number management within shipment + */ +class ExpeditionLineBatch extends CommonObject +{ + /** + * @var string ID to identify managed object + */ + public $element = 'expeditionlignebatch'; + + private static $_table_element = 'expeditiondet_batch'; //!< Name of table without prefix where object is stored + + public $sellby; + public $eatby; + public $batch; + public $qty; + public $dluo_qty; // deprecated, use qty + public $entrepot_id; + public $fk_origin_stock; + public $fk_expeditiondet; + + /** + * Constructor + * + * @param DoliDb $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + } + + /** + * Fill object based on a product-warehouse-batch's record + * + * @param int $id_stockdluo Rowid in product_batch table + * @return int -1 if KO, 1 if OK + */ + public function fetchFromStock($id_stockdluo) + { + $sql = "SELECT"; + $sql .= " pb.batch,"; + $sql .= " pl.sellby,"; + $sql .= " pl.eatby,"; + $sql .= " ps.fk_entrepot"; + + $sql .= " FROM ".MAIN_DB_PREFIX."product_batch as pb"; + $sql .= " JOIN ".MAIN_DB_PREFIX."product_stock as ps on pb.fk_product_stock=ps.rowid"; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."product_lot as pl on pl.batch = pb.batch AND pl.fk_product = ps.fk_product"; + $sql .= " WHERE pb.rowid = ".(int) $id_stockdluo; + + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->sellby = $this->db->jdate($obj->sellby); + $this->eatby = $this->db->jdate($obj->eatby); + $this->batch = $obj->batch; + $this->entrepot_id = $obj->fk_entrepot; + $this->fk_origin_stock = (int) $id_stockdluo; + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error = "Error ".$this->db->lasterror(); + return -1; + } + } + + /** + * Create an expeditiondet_batch DB record link to an expedtiondet record + * + * @param int $id_line_expdet rowid of expedtiondet record + * @return int <0 if KO, Id of record (>0) if OK + */ + public function create($id_line_expdet) + { + $error = 0; + + $id_line_expdet = (int) $id_line_expdet; + + $sql = "INSERT INTO ".MAIN_DB_PREFIX.self::$_table_element." ("; + $sql .= "fk_expeditiondet"; + $sql .= ", sellby"; + $sql .= ", eatby"; + $sql .= ", batch"; + $sql .= ", qty"; + $sql .= ", fk_origin_stock"; + $sql .= ") VALUES ("; + $sql .= $id_line_expdet.","; + $sql .= " ".(!isset($this->sellby) || dol_strlen($this->sellby) == 0 ? 'NULL' : ("'".$this->db->idate($this->sellby))."'").","; + $sql .= " ".(!isset($this->eatby) || dol_strlen($this->eatby) == 0 ? 'NULL' : ("'".$this->db->idate($this->eatby))."'").","; + $sql .= " ".(!isset($this->batch) ? 'NULL' : ("'".$this->db->escape($this->batch)."'")).","; + $sql .= " ".(!isset($this->qty) ? ((!isset($this->dluo_qty)) ? 'NULL' : $this->dluo_qty) : $this->qty).","; // dluo_qty deprecated, use qty + $sql .= " ".(!isset($this->fk_origin_stock) ? 'NULL' : $this->fk_origin_stock); + $sql .= ")"; + + dol_syslog(__METHOD__, LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + + if (!$error) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.self::$_table_element); + $this->fk_expeditiondet = $id_line_expdet; + return $this->id; + } + else + { + foreach ($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + } + $this->db->rollback(); + return -1 * $error; + } + } + + /** + * Delete batch record attach to a shipment + * + * @param DoliDB $db Database object + * @param int $id_expedition rowid of shipment + * @return int -1 if KO, 1 if OK + */ + public static function deletefromexp($db, $id_expedition) + { + $id_expedition = (int) $id_expedition; + + $sql = "DELETE FROM ".MAIN_DB_PREFIX.self::$_table_element; + $sql .= " WHERE fk_expeditiondet in (SELECT rowid FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition=".$id_expedition.")"; + + dol_syslog(__METHOD__, LOG_DEBUG); + if ($db->query($sql)) + { + return 1; + } + else + { + return -1; + } + } + + /** + * Retrieve all batch number detailed information of a shipment line + * + * @param DoliDB $db Database object + * @param int $id_line_expdet id of shipment line + * @param int $fk_product If provided, load also detailed information of lot + * @return int|array -1 if KO, array of ExpeditionLineBatch if OK + */ + public static function fetchAll($db, $id_line_expdet, $fk_product = 0) + { + $sql = "SELECT"; + $sql .= " eb.rowid,"; + $sql .= " eb.fk_expeditiondet,"; + $sql .= " eb.sellby as oldsellby,"; // deprecated + $sql .= " eb.eatby as oldeatby,"; // deprecated + $sql .= " eb.batch,"; + $sql .= " eb.qty,"; + $sql .= " eb.fk_origin_stock"; + if ($fk_product > 0) + { + $sql .= ", pl.sellby"; + $sql .= ", pl.eatby"; + } + $sql .= " FROM ".MAIN_DB_PREFIX.self::$_table_element." as eb"; + if ($fk_product > 0) + { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON pl.batch = eb.batch AND pl.fk_product = ".$fk_product; + } + $sql .= " WHERE fk_expeditiondet=".(int) $id_line_expdet; + + dol_syslog(__METHOD__."", LOG_DEBUG); + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + $ret = array(); + while ($i < $num) + { + $tmp = new self($db); + + $obj = $db->fetch_object($resql); + + $tmp->sellby = $db->jdate($obj->sellby ? $obj->sellby : $obj->oldsellby); + $tmp->eatby = $db->jdate($obj->eatby ? $obj->eatby : $obj->oldeatby); + $tmp->batch = $obj->batch; + $tmp->id = $obj->rowid; + $tmp->fk_origin_stock = $obj->fk_origin_stock; + $tmp->fk_expeditiondet = $obj->fk_expeditiondet; + $tmp->dluo_qty = $obj->qty; // dluo_qty deprecated, use qty + $tmp->qty = $obj->qty; + + $ret[] = $tmp; + $i++; + } + $db->free($resql); + return $ret; + } + else + { + dol_print_error($db); + return -1; + } + } +} --- /tmp/dsg/dolibarr/htdocs/expedition/class/github_19.0.3_expeditionstats.class.php +++ /tmp/dsg/dolibarr/htdocs/expedition/class/client_expeditionstats.class.php @@ -37,4 +37,4 @@ - /** - * @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; @@ -42,4 +42,2 @@ - /** - * @var int ID thirdparty - */ - public $socid; + public $socid; + public $userid; @@ -47,24 +45,3 @@ - /** - * @var int ID user - */ - public $userid; - - /** - * @var string sql part from - */ - public $from; - - /** - * @var string sql part join - */ - public $join; - - /** - * @var string sql part fields - */ - public $field; - - /** - * @var string sql part where - */ - public $where; + public $from; + public $field; + public $where; @@ -73,4 +50,4 @@ - /** - * Constructor - * - * @param DoliDB $db Database handler + /** + * Constructor + * + * @param DoliDB $db Database handler @@ -80,3 +57,3 @@ - */ - public function __construct($db, $socid, $mode, $userid = 0) - { + */ + public function __construct($db, $socid, $mode, $userid = 0) + { @@ -88 +65 @@ - $this->userid = $userid; + $this->userid = $userid; @@ -91 +68 @@ - $object = new Expedition($this->db); + $object = new Expedition($this->db); @@ -99,2 +76,4 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$this->socid) { - $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); + if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; + if ($this->socid) + { + $this->where .= " AND c.fk_soc = ".$this->socid; @@ -102,7 +81,2 @@ - if ($this->socid) { - $this->where .= " AND c.fk_soc = ".((int) $this->socid); - } - if ($this->userid > 0) { - $this->where .= ' AND c.fk_user_author = '.((int) $this->userid); - } - } + if ($this->userid > 0) $this->where .= ' AND c.fk_user_author = '.$this->userid; + } @@ -110,3 +84,3 @@ - /** - * Return shipment number by month for a year - * + /** + * Return shipment number by month for a year + * @@ -114 +88 @@ - * @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 @@ -116,4 +90,4 @@ - */ - public function getNbByMonth($year, $format = 0) - { - global $user; + */ + public function getNbByMonth($year, $format = 0) + { + global $user; @@ -121 +95 @@ - $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"; @@ -123,3 +97 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$this->socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - } + if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; @@ -129 +101 @@ - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); @@ -133 +105 @@ - } + } @@ -147,3 +119 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$this->socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - } + if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; @@ -152 +122 @@ - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); @@ -155,48 +124,0 @@ - } - - /** - * Return the orders amount 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 - * @return array Array with amount by month - */ - public function getAmountByMonth($year, $format = 0) - { - global $user; - - $sql = "SELECT date_format(c.date_valid,'%m') as dm, SUM(c.".$this->field.")"; - $sql .= " FROM ".$this->from; - if (!$user->hasRight('societe', 'client', 'voir') && !$this->socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - } - $sql .= $this->join; - $sql .= " WHERE ".$this->where; - $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); - - $res = $this->_getAmountByMonth($year, $sql, $format); - return $res; - } - - /** - * Return the orders amount average by month for a year - * - * @param int $year year for stats - * @return array array with number by month - */ - public function getAverageByMonth($year) - { - global $user; - - $sql = "SELECT date_format(c.date_valid,'%m') as dm, AVG(c.".$this->field.")"; - $sql .= " FROM ".$this->from; - if (!$user->hasRight('societe', 'client', 'voir') && !$this->socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - } - $sql .= $this->join; - $sql .= " WHERE ".$this->where; - $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); - - return $this->_getAverageByMonth($year, $sql); @@ -216,3 +138 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$this->socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - } + if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; @@ -221 +141 @@ - $sql .= $this->db->order('year', 'DESC'); + $sql .= $this->db->order('year', 'DESC');