--- /tmp/dsg/dolibarr/htdocs/comm/propal/class/github_19.0.3_api_proposals.class.php +++ /tmp/dsg/dolibarr/htdocs/comm/propal/class/client_api_proposals.class.php @@ -2,5 +2,3 @@ -/* Copyright (C) 2015 Jean-François Ferry - * Copyright (C) 2016 Laurent Destailleur - * Copyright (C) 2020 Thibault FOUCART - * Copyright (C) 2022 ATM Consulting - * Copyright (C) 2022 OpenDSI +/* Copyright (C) 2015 Jean-François Ferry + * Copyright (C) 2016 Laurent Destailleur + * Copyright (C) 2020 Thibault FOUCART @@ -35 +33 @@ - /** + /** @@ -38 +36 @@ - public static $FIELDS = array( + static $FIELDS = array( @@ -52 +50 @@ - global $db; + global $db, $conf; @@ -62,5 +60,5 @@ - * @param int $id ID of commercial proposal - * @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id - * @return Object Object with cleaned properties - * - * @throws RestException + * @param int $id ID of commercial proposal + * @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id + * @return array|mixed data without useless information + * + * @throws RestException @@ -70,55 +68,55 @@ - return $this->_fetch($id, '', '', $contact_list); - } - - /** - * Get properties of an proposal object by ref - * - * Return an array with proposal informations - * - * @param string $ref Ref of object - * @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id - * @return Object Object with cleaned properties - * - * @url GET ref/{ref} - * - * @throws RestException - */ - public function getByRef($ref, $contact_list = 1) - { - return $this->_fetch('', $ref, '', $contact_list); - } - - /** - * Get properties of an proposal object by ref_ext - * - * Return an array with proposal informations - * - * @param string $ref_ext External reference of object - * @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id - * @return Object Object with cleaned properties - * - * @url GET ref_ext/{ref_ext} - * - * @throws RestException - */ - public function getByRefExt($ref_ext, $contact_list = 1) - { - return $this->_fetch('', '', $ref_ext, $contact_list); - } - - /** - * Get properties of an proposal object - * - * Return an array with proposal informations - * - * @param int $id ID of order - * @param string $ref Ref of object - * @param string $ref_ext External reference of object - * @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id - * @return Object Object with cleaned properties - * - * @throws RestException - */ - private function _fetch($id, $ref = '', $ref_ext = '', $contact_list = 1) - { - if (!DolibarrApiAccess::$user->hasRight('propal', 'lire')) { + return $this->_fetch($id, '', '', $contact_list); + } + + /** + * Get properties of an proposal object by ref + * + * Return an array with proposal informations + * + * @param string $ref Ref of object + * @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id + * @return array|mixed data without useless information + * + * @url GET ref/{ref} + * + * @throws RestException + */ + public function getByRef($ref, $contact_list = 1) + { + return $this->_fetch('', $ref, '', $contact_list); + } + + /** + * Get properties of an proposal object by ref_ext + * + * Return an array with proposal informations + * + * @param string $ref_ext External reference of object + * @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id + * @return array|mixed data without useless information + * + * @url GET ref_ext/{ref_ext} + * + * @throws RestException + */ + public function getByRefExt($ref_ext, $contact_list = 1) + { + return $this->_fetch('', '', $ref_ext, $contact_list); + } + + /** + * Get properties of an proposal object + * + * Return an array with proposal informations + * + * @param int $id ID of order + * @param string $ref Ref of object + * @param string $ref_ext External reference of object + * @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id + * @return array|mixed data without useless information + * + * @throws RestException + */ + private function _fetch($id, $ref = '', $ref_ext = '', $contact_list = 1) + { + if (!DolibarrApiAccess::$user->rights->propal->lire) { @@ -138,5 +136 @@ - $tmparray = $this->propal->liste_contact(-1, 'external', $contact_list); - if (is_array($tmparray)) { - $this->propal->contacts_ids = $tmparray; - } - + $this->propal->contacts_ids = $this->propal->liste_contact(-1, 'external', $contact_list); @@ -144 +137,0 @@ - @@ -153,5 +146,5 @@ - * @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 commercial proposals (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i} + * @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 commercial proposals (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i} @@ -159 +151,0 @@ - * @param string $properties Restrict the data returned to theses properties. Ignored if empty. Comma separated list of properties names @@ -162,2 +154,2 @@ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '', $properties = '') - { + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '') + { @@ -165,4 +156,0 @@ - - if (!DolibarrApiAccess::$user->hasRight('propal', 'lire')) { - throw new RestException(401); - } @@ -177,3 +165 @@ - if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) { - $search_sale = DolibarrApiAccess::$user->id; - } + if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id; @@ -182,9 +168,4 @@ - 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."propal AS t LEFT JOIN ".MAIN_DB_PREFIX."propal_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 - } + 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."propal 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 @@ -193,9 +174,3 @@ - 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 - } + 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 @@ -203,2 +178,3 @@ - if ($search_sale > 0) { - $sql .= " AND sc.fk_user = ".((int) $search_sale); + if ($search_sale > 0) + { + $sql .= " AND sc.fk_user = ".$search_sale; @@ -207,5 +183,5 @@ - if ($sqlfilters) { - $errormessage = ''; - $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage); - if ($errormessage) { - throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage); + if ($sqlfilters) + { + if (!DolibarrApi::_checkFilters($sqlfilters)) + { + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); @@ -213,3 +189,5 @@ - } - - $sql .= $this->db->order($sortfield, $sortorder); + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; + } + + $sql .= $db->order($sortfield, $sortorder); @@ -217 +195,2 @@ - if ($page < 0) { + if ($page < 0) + { @@ -222,8 +201,9 @@ - $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); + $sql .= $db->plimit($limit + 1, $offset); + } + + dol_syslog("API Rest request"); + $result = $db->query($sql); + + if ($result) + { + $num = $db->num_rows($result); @@ -232,3 +212,4 @@ - while ($i < $min) { - $obj = $this->db->fetch_object($result); - $proposal_static = new Propal($this->db); + while ($i < $min) + { + $obj = $db->fetch_object($result); + $proposal_static = new Propal($db); @@ -237,5 +218,2 @@ - $tmparray = $proposal_static->liste_contact(-1, 'external', 1); - if (is_array($tmparray)) { - $proposal_static->contacts_ids = $tmparray; - } - $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($proposal_static), $properties); + $proposal_static->contacts_ids = $proposal_static->liste_contact(-1, 'external', 1); + $obj_ret[] = $this->_cleanObjectDatas($proposal_static); @@ -245,4 +223,7 @@ - } else { - throw new RestException(503, 'Error when retrieve propal list : '.$this->db->lasterror()); - } - + } + else { + throw new RestException(503, 'Error when retrieve propal list : '.$db->lasterror()); + } + if (!count($obj_ret)) { + throw new RestException(404, 'No proposal found'); + } @@ -258,7 +239,7 @@ - public function post($request_data = null) - { - if (!DolibarrApiAccess::$user->rights->propal->creer) { - throw new RestException(401, "Insuffisant rights"); - } - // Check mandatory fields - $result = $this->_validate($request_data); + public function post($request_data = null) + { + if (!DolibarrApiAccess::$user->rights->propal->creer) { + throw new RestException(401, "Insuffisant rights"); + } + // Check mandatory fields + $result = $this->_validate($request_data); @@ -267,6 +247,0 @@ - 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->propal->context['caller'] = $request_data['caller']; - continue; - } - @@ -276,6 +251,6 @@ - $lines = array(); - foreach ($request_data["lines"] as $line) { - array_push($lines, (object) $line); - } - $this->propal->lines = $lines; - }*/ + $lines = array(); + foreach ($request_data["lines"] as $line) { + array_push($lines, (object) $line); + } + $this->propal->lines = $lines; + }*/ @@ -286,2 +261,2 @@ - return ((int) $this->propal->id); - } + return $this->propal->id; + } @@ -292,2 +267 @@ - * @param int $id Id of commercial proposal - * @param string $sqlfilters Other criteria to filter answers separated by a comma. d is the alias for proposal lines table, p is the alias for product table. "Syntax example "(p.ref:like:'SO-%') AND (d.date_start:<:'20220101')" + * @param int $id Id of commercial proposal @@ -297,32 +271,22 @@ - * @return array - */ - public function getLines($id, $sqlfilters = '') - { - if (!DolibarrApiAccess::$user->hasRight('propal', 'lire')) { - throw new RestException(401); - } - - $result = $this->propal->fetch($id); - if (!$result) { - throw new RestException(404, 'Commercial Proposal not found'); - } - - if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $sql = ''; - if (!empty($sqlfilters)) { - $errormessage = ''; - $sql = forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage); - if ($errormessage) { - throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage); - } - } - - $this->propal->getLinesArray($sql); - $result = array(); - foreach ($this->propal->lines as $line) { - array_push($result, $this->_cleanObjectDatas($line)); - } - return $result; + * @return int + */ + public function getLines($id) + { + if (!DolibarrApiAccess::$user->rights->propal->lire) { + throw new RestException(401); + } + + $result = $this->propal->fetch($id); + if (!$result) { + throw new RestException(404, 'Commercial Proposal not found'); + } + + if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $this->propal->getLinesArray(); + $result = array(); + foreach ($this->propal->lines as $line) { + array_push($result, $this->_cleanObjectDatas($line)); + } + return $result; @@ -337 +301 @@ - * @url POST {id}/line + * @url POST {id}/lines @@ -344,55 +308,52 @@ - throw new RestException(401); - } - - $result = $this->propal->fetch($id); - if (!$result) { - throw new RestException(404, 'Commercial Proposal not found'); - } - - if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->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->propal->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->price_base_type ? $request_data->price_base_type : 'HT', - $request_data->subprice, - $request_data->info_bits, - $request_data->product_type, - $request_data->rang, - $request_data->special_code, - $request_data->fk_parent_line, - $request_data->fk_fournprice, - $request_data->pa_ht, - $request_data->label, - $request_data->date_start, - $request_data->date_end, - $request_data->array_options, - $request_data->fk_unit, - $request_data->origin, - $request_data->origin_id, - $request_data->multicurrency_subprice, - $request_data->fk_remise_except - ); - - if ($updateRes > 0) { - return $updateRes; - } else { - throw new RestException(400, $this->propal->error); - } - } - - /** - * Add lines to given commercial proposal + throw new RestException(401); + } + + $result = $this->propal->fetch($id); + if (!$result) { + throw new RestException(404, 'Commercial Proposal not found'); + } + + if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $request_data = (object) $request_data; + + $updateRes = $this->propal->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, + 'HT', + 0, + $request_data->info_bits, + $request_data->product_type, + $request_data->rang, + $request_data->special_code, + $request_data->fk_parent_line, + $request_data->fk_fournprice, + $request_data->pa_ht, + $request_data->label, + $request_data->date_start, + $request_data->date_end, + $request_data->array_options, + $request_data->fk_unit, + $request_data->origin, + $request_data->origin_id, + $request_data->multicurrency_subprice, + $request_data->fk_remise_except + ); + + if ($updateRes > 0) { + return $updateRes; + } else { + throw new RestException(400, $this->propal->error); + } + } + + /** + * Update a line of given commercial proposal @@ -400,0 +362 @@ + * @param int $lineid Id of line to update @@ -403,82 +364,0 @@ - * @url POST {id}/lines - * - * @return int - */ - public function postLines($id, $request_data = null) - { - if (!DolibarrApiAccess::$user->rights->propal->creer) { - throw new RestException(401); - } - - $result = $this->propal->fetch($id); - if (!$result) { - throw new RestException(404, 'Commercial Proposal not found'); - } - - if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $errors = []; - $this->db->begin(); - - foreach ($request_data as $TData) { - if (empty($TData[0])) { - $TData = array($TData); - } - - foreach ($TData as $lineData) { - $line = (object) $lineData; - - $updateRes = $this->propal->addline( - $line->desc, - $line->subprice, - $line->qty, - $line->tva_tx, - $line->localtax1_tx, - $line->localtax2_tx, - $line->fk_product, - $line->remise_percent, - 'HT', - 0, - $line->info_bits, - $line->product_type, - $line->rang, - $line->special_code, - $line->fk_parent_line, - $line->fk_fournprice, - $line->pa_ht, - $line->label, - $line->date_start, - $line->date_end, - $line->array_options, - $line->fk_unit, - $line->origin, - $line->origin_id, - $line->multicurrency_subprice, - $line->fk_remise_except - ); - - if ($updateRes < 0) { - $errors['lineLabel'] = $line->label; - $errors['msg'] = $this->propal->errors; - } - } - } - if (empty($errors)) { - $this->db->commit(); - return $updateRes; - } else { - $this->db->rollback(); - throw new RestException(400, implode(", ", $errors)); - } - } - - /** - * Update a line of given commercial proposal - * - * @param int $id Id of commercial proposal to update - * @param int $lineid Id of line to update - * @param array $request_data Commercial proposal line data - * @return Object|false Object with cleaned properties - * @@ -485,0 +366,2 @@ + * + * @return object @@ -500,50 +382,41 @@ - } - - $request_data = (object) $request_data; - - if (isset($request_data->desc)) { - $request_data->desc = sanitizeVal($request_data->desc, 'restricthtml'); - } - if (isset($request_data->label)) { - $request_data->label = sanitizeVal($request_data->label); - } - - $propalline = new PropaleLigne($this->db); - $result = $propalline->fetch($lineid); - if ($result <= 0) { - throw new RestException(404, 'Proposal line not found'); - } - - $updateRes = $this->propal->updateline( - $lineid, - isset($request_data->subprice) ? $request_data->subprice : $propalline->subprice, - isset($request_data->qty) ? $request_data->qty : $propalline->qty, - isset($request_data->remise_percent) ? $request_data->remise_percent : $propalline->remise_percent, - isset($request_data->tva_tx) ? $request_data->tva_tx : $propalline->tva_tx, - isset($request_data->localtax1_tx) ? $request_data->localtax1_tx : $propalline->localtax1_tx, - isset($request_data->localtax2_tx) ? $request_data->localtax2_tx : $propalline->localtax2_tx, - isset($request_data->desc) ? $request_data->desc : $propalline->desc, - isset($request_data->price_base_type) ? $request_data->price_base_type : 'HT', - isset($request_data->info_bits) ? $request_data->info_bits : $propalline->info_bits, - isset($request_data->special_code) ? $request_data->special_code : $propalline->special_code, - isset($request_data->fk_parent_line) ? $request_data->fk_parent_line : $propalline->fk_parent_line, - 0, - isset($request_data->fk_fournprice) ? $request_data->fk_fournprice : $propalline->fk_fournprice, - isset($request_data->pa_ht) ? $request_data->pa_ht : $propalline->pa_ht, - isset($request_data->label) ? $request_data->label : $propalline->label, - isset($request_data->product_type) ? $request_data->product_type : $propalline->product_type, - isset($request_data->date_start) ? $request_data->date_start : $propalline->date_start, - isset($request_data->date_end) ? $request_data->date_end : $propalline->date_end, - isset($request_data->array_options) ? $request_data->array_options : $propalline->array_options, - isset($request_data->fk_unit) ? $request_data->fk_unit : $propalline->fk_unit, - isset($request_data->multicurrency_subprice) ? $request_data->multicurrency_subprice : $propalline->subprice, - 0, - isset($request_data->rang) ? $request_data->rang : $propalline->rang - ); - - if ($updateRes > 0) { - $result = $this->get($id); - unset($result->line); - return $this->_cleanObjectDatas($result); - } - return false; + } + + $request_data = (object) $request_data; + + $propalline = new PropaleLigne($this->db); + $result = $propalline->fetch($lineid); + if ($result <= 0) { + throw new RestException(404, 'Proposal line not found'); + } + + $updateRes = $this->propal->updateline( + $lineid, + isset($request_data->subprice) ? $request_data->subprice : $propalline->subprice, + isset($request_data->qty) ? $request_data->qty : $propalline->qty, + isset($request_data->remise_percent) ? $request_data->remise_percent : $propalline->remise_percent, + isset($request_data->tva_tx) ? $request_data->tva_tx : $propalline->tva_tx, + isset($request_data->localtax1_tx) ? $request_data->localtax1_tx : $propalline->localtax1_tx, + isset($request_data->localtax2_tx) ? $request_data->localtax2_tx : $propalline->localtax2_tx, + isset($request_data->desc) ? $request_data->desc : $propalline->desc, + 'HT', + isset($request_data->info_bits) ? $request_data->info_bits : $propalline->info_bits, + isset($request_data->special_code) ? $request_data->special_code : $propalline->special_code, + isset($request_data->fk_parent_line) ? $request_data->fk_parent_line : $propalline->fk_parent_line, + 0, + isset($request_data->fk_fournprice) ? $request_data->fk_fournprice : $propalline->fk_fournprice, + isset($request_data->pa_ht) ? $request_data->pa_ht : $propalline->pa_ht, + isset($request_data->label) ? $request_data->label : $propalline->label, + isset($request_data->product_type) ? $request_data->product_type : $propalline->product_type, + isset($request_data->date_start) ? $request_data->date_start : $propalline->date_start, + isset($request_data->date_end) ? $request_data->date_end : $propalline->date_end, + isset($request_data->array_options) ? $request_data->array_options : $propalline->array_options, + isset($request_data->fk_unit) ? $request_data->fk_unit : $propalline->fk_unit, + isset($request_data->multicurrency_subprice) ? $request_data->multicurrency_subprice : $propalline->subprice + ); + + if ($updateRes > 0) { + $result = $this->get($id); + unset($result->line); + return $this->_cleanObjectDatas($result); + } + return false; @@ -556,3 +429,2 @@ - * @param int $id Id of commercial proposal to update - * @param int $lineid Id of line to delete - * @return Object|false Object with cleaned properties + * @param int $id Id of commercial proposal to update + * @param int $lineid Id of line to delete @@ -562,5 +434,7 @@ - * @throws RestException 401 - * @throws RestException 404 - */ - public function deleteLine($id, $lineid) - { + * @return int + * + * @throws RestException 401 + * @throws RestException 404 + */ + public function deleteLine($id, $lineid) + { @@ -568 +442 @@ - throw new RestException(401); + throw new RestException(401); @@ -580 +454,3 @@ - $updateRes = $this->propal->deleteline($lineid, $id); + // TODO Check the lineid $lineid is a line of ojbect + + $updateRes = $this->propal->deleteline($lineid); @@ -583 +459,3 @@ - } else { + } + else + { @@ -588 +466 @@ - /** + /** @@ -594 +471,0 @@ - * @return array @@ -598,10 +475,12 @@ - * @throws RestException 401 - * @throws RestException 404 - */ - public function postContact($id, $contactid, $type) - { - if (!DolibarrApiAccess::$user->rights->propal->creer) { - throw new RestException(401); - } - - $result = $this->propal->fetch($id); + * @return int + * + * @throws RestException 401 + * @throws RestException 404 + */ + public function postContact($id, $contactid, $type) + { + if (!DolibarrApiAccess::$user->rights->propal->creer) { + throw new RestException(401); + } + + $result = $this->propal->fetch($id); @@ -613,23 +492,18 @@ - if (!in_array($type, array('BILLING', 'SHIPPING', 'CUSTOMER'), true)) { - throw new RestException(500, 'Availables types: BILLING, SHIPPING OR CUSTOMER'); - } - - if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $result = $this->propal->add_contact($contactid, $type, 'external'); - - if (!$result) { - throw new RestException(500, 'Error when added the contact'); - } - - return array( - 'success' => array( - 'code' => 200, - 'message' => 'Contact linked to the proposal' - ) - ); - } - - /** + if (!in_array($type, array('BILLING', 'SHIPPING', 'CUSTOMER'), true)) { + throw new RestException(500, 'Availables types: BILLING, SHIPPING OR CUSTOMER'); + } + + if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $result = $this->propal->add_contact($contactid, $type, 'external'); + + if (!$result) { + throw new RestException(500, 'Error when added the contact'); + } + + return $this->propal; + } + + /** @@ -638,18 +512,18 @@ - * @param int $id Id of commercial proposal to update - * @param int $contactid Row key of the contact in the array contact_ids. - * @param string $type Type of the contact (BILLING, SHIPPING, CUSTOMER). - * @return Object Object with cleaned properties - * - * @url DELETE {id}/contact/{contactid}/{type} - * - * @throws RestException 401 - * @throws RestException 404 - * @throws RestException 500 System error - */ - public function deleteContact($id, $contactid, $type) - { - if (!DolibarrApiAccess::$user->rights->propal->creer) { - throw new RestException(401); - } - - $result = $this->propal->fetch($id); + * @param int $id Id of commercial proposal to update + * @param int $rowid Row key of the contact in the array contact_ids. + * + * @url DELETE {id}/contact/{rowid} + * + * @return int + * + * @throws RestException 401 + * @throws RestException 404 + * @throws RestException 500 + */ + public function deleteContact($id, $rowid) + { + if (!DolibarrApiAccess::$user->rights->propal->creer) { + throw new RestException(401); + } + + $result = $this->propal->fetch($id); @@ -661,18 +535,12 @@ - if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $contacts = $this->propal->liste_contact(); - - foreach ($contacts as $contact) { - if ($contact['id'] == $contactid && $contact['code'] == $type) { - $result = $this->propal->delete_contact($contact['rowid']); - - if (!$result) { - throw new RestException(500, 'Error when deleted the contact'); - } - } - } - - return $this->_cleanObjectDatas($this->propal); - } + if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $result = $this->propal->delete_contact($rowid); + + if (!$result) { + throw new RestException(500, 'Error when deleted the contact'); + } + + return $this->propal; + } @@ -683,9 +551,10 @@ - * @param int $id Id of commercial proposal to update - * @param array $request_data Datas - * @return Object Object with cleaned properties - */ - public function put($id, $request_data = null) - { - if (!DolibarrApiAccess::$user->rights->propal->creer) { - throw new RestException(401); - } + * @param int $id Id of commercial proposal to update + * @param array $request_data Datas + * + * @return int + */ + public function put($id, $request_data = null) + { + if (!DolibarrApiAccess::$user->rights->propal->creer) { + throw new RestException(401); + } @@ -702,9 +571 @@ - 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->propal->context['caller'] = $request_data['caller']; - continue; - } - + if ($field == 'id') continue; @@ -715 +576,2 @@ - if (empty($this->propal->fin_validite) && !empty($this->propal->duree_validite) && !empty($this->propal->date_creation)) { + if (empty($this->propal->fin_validite) && !empty($this->propal->duree_validite) && !empty($this->propal->date_creation)) + { @@ -718,2 +580,4 @@ - if (!empty($this->propal->fin_validite)) { - if ($this->propal->set_echeance(DolibarrApiAccess::$user, $this->propal->fin_validite) < 0) { + if (!empty($this->propal->fin_validite)) + { + if ($this->propal->set_echeance(DolibarrApiAccess::$user, $this->propal->fin_validite) < 0) + { @@ -724 +588,2 @@ - if ($this->propal->update(DolibarrApiAccess::$user) > 0) { + if ($this->propal->update(DolibarrApiAccess::$user) > 0) + { @@ -726 +591,3 @@ - } else { + } + else + { @@ -734,0 +602 @@ + * @@ -764,7 +632,8 @@ - * Set a proposal to draft - * - * @param int $id Order ID - * @return Object Object with cleaned properties - * - * @url POST {id}/settodraft - */ + * Set a proposal to draft + * + * @param int $id Order ID + * + * @url POST {id}/settodraft + * + * @return array + */ @@ -818 +686,0 @@ - * @return Object Object with cleaned properties @@ -823,6 +691,8 @@ - * @throws RestException 401 - * @throws RestException 404 - * @throws RestException 500 System error - */ - public function validate($id, $notrigger = 0) - { + * @throws RestException 401 + * @throws RestException 404 + * @throws RestException 500 + * + * @return array + */ + public function validate($id, $notrigger = 0) + { @@ -849,13 +719,13 @@ - $result = $this->propal->fetch($id); - if (!$result) { - throw new RestException(404, 'Commercial Proposal not found'); - } - - if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $this->propal->fetchObjectLinked(); - - return $this->_cleanObjectDatas($this->propal); - } + $result = $this->propal->fetch($id); + if (!$result) { + throw new RestException(404, 'Commercial Proposal not found'); + } + + if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $this->propal->fetchObjectLinked(); + + return $this->_cleanObjectDatas($this->propal); + } @@ -867 +737 @@ - * @param int $status Must be 2 (accepted) or 3 (refused) {@min 2}{@max 3} + * @param int $status Must be 2 (accepted) or 3 (refused) {@min 2}{@max 3} @@ -870 +739,0 @@ - * @return Object Object with cleaned properties @@ -872,0 +742,2 @@ + * + * @return array @@ -888 +759 @@ - $result = $this->propal->closeProposal(DolibarrApiAccess::$user, $status, $note_private, $notrigger); + $result = $this->propal->cloture(DolibarrApiAccess::$user, $status, $note_private, $notrigger); @@ -910,40 +781,41 @@ - /** - * Set a commercial proposal billed. Could be also called setbilled - * - * @param int $id Commercial proposal ID - * @return Object Object with cleaned properties - * - * @url POST {id}/setinvoiced - */ - public function setinvoiced($id) - { - if (!DolibarrApiAccess::$user->rights->propal->creer) { - throw new RestException(401); - } - $result = $this->propal->fetch($id); - if (!$result) { - throw new RestException(404, 'Commercial Proposal not found'); - } - - if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $result = $this->propal->classifyBilled(DolibarrApiAccess::$user); - if ($result < 0) { - throw new RestException(500, 'Error : '.$this->propal->error); - } - - $result = $this->propal->fetch($id); - if (!$result) { - throw new RestException(404, 'Proposal not found'); - } - - if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $this->propal->fetchObjectLinked(); - - return $this->_cleanObjectDatas($this->propal); - } + /** + * Set a commercial proposal billed. Could be also called setbilled + * + * @param int $id Commercial proposal ID + * + * @url POST {id}/setinvoiced + * + * @return array + */ + public function setinvoiced($id) + { + if (!DolibarrApiAccess::$user->rights->propal->creer) { + throw new RestException(401); + } + $result = $this->propal->fetch($id); + if (!$result) { + throw new RestException(404, 'Commercial Proposal not found'); + } + + if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $result = $this->propal->classifyBilled(DolibarrApiAccess::$user); + if ($result < 0) { + throw new RestException(500, 'Error : '.$this->propal->error); + } + + $result = $this->propal->fetch($id); + if (!$result) { + throw new RestException(404, 'Proposal not found'); + } + + if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $this->propal->fetchObjectLinked(); + + return $this->_cleanObjectDatas($this->propal); + } @@ -957 +828,0 @@ - * @@ -964 +835 @@ - if (!isset($data[$field])) { + if (!isset($data[$field])) @@ -966 +836,0 @@ - } @@ -973,21 +843,21 @@ - // 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->note); - unset($object->name); - unset($object->lastname); - unset($object->firstname); - unset($object->civility_id); - unset($object->address); - - return $object; - } + // 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->note); + unset($object->name); + unset($object->lastname); + unset($object->firstname); + unset($object->civility_id); + unset($object->address); + + return $object; + } --- /tmp/dsg/dolibarr/htdocs/comm/propal/class/github_19.0.3_propal.class.php +++ /tmp/dsg/dolibarr/htdocs/comm/propal/class/client_propal.class.php @@ -2,19 +2,16 @@ -/* Copyright (C) 2002-2004 Rodolphe Quiedeville - * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2004-2011 Laurent Destailleur - * Copyright (C) 2005 Marc Barilley - * Copyright (C) 2005-2013 Regis Houssin - * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2008 Raphael Bertrand - * Copyright (C) 2010-2020 Juanjo Menent - * Copyright (C) 2010-2022 Philippe Grand - * Copyright (C) 2012-2014 Christophe Battarel - * Copyright (C) 2012 Cedric Salvador - * Copyright (C) 2013 Florian Henry - * Copyright (C) 2014-2015 Marcos García - * Copyright (C) 2018 Nicolas ZABOURI - * Copyright (C) 2018-2021 Frédéric France - * Copyright (C) 2018 Ferran Marcet - * Copyright (C) 2022 ATM Consulting - * Copyright (C) 2022 OpenDSI - * Copyright (C) 2022 Gauthier VERDOL +/* Copyright (C) 2002-2004 Rodolphe Quiedeville + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2004-2011 Laurent Destailleur + * Copyright (C) 2005 Marc Barilley + * Copyright (C) 2005-2013 Regis Houssin + * Copyright (C) 2006 Andre Cianfarani + * Copyright (C) 2008 Raphael Bertrand + * Copyright (C) 2010-2019 Juanjo Menent + * Copyright (C) 2010-2017 Philippe Grand + * Copyright (C) 2012-2014 Christophe Battarel + * Copyright (C) 2012 Cedric Salvador + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2014-2015 Marcos García + * Copyright (C) 2018 Nicolas ZABOURI + * Copyright (C) 2018-2019 Frédéric France + * Copyright (C) 2018 Ferran Marcet @@ -47 +43,0 @@ -require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php'; @@ -54,7 +49,0 @@ - use CommonIncoterm; - - /** - * @var string code - */ - public $code = ""; - @@ -77 +66 @@ - * @var string Fieldname 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 @@ -119,2 +107,0 @@ - * @deprecated - * @see $ref_customer @@ -123,19 +109,0 @@ - - /** - * Ref from thirdparty - * @var string - */ - public $ref_customer; - - /** - * @var Propal oldcopy with propal properties - */ - public $oldcopy; - - /** - * Status of the quote - * @var int - * @deprecated Try to use $status now - * @see Propal::STATUS_DRAFT, Propal::STATUS_VALIDATED, Propal::STATUS_SIGNED, Propal::STATUS_NOTSIGNED, Propal::STATUS_BILLED - */ - public $statut; @@ -148 +116 @@ - public $status; + public $statut; @@ -156,3 +124,3 @@ - /** - * @var integer|string $date_creation; - */ + /** + * @var integer|string $date_creation; + */ @@ -168,2 +136,2 @@ - * @var integer|string $date_validation; - */ + * @var integer|string $date_validation; + */ @@ -173,12 +141,2 @@ - * @var integer|string $date_signature; - */ - public $date_signature; - - /** - * @var User $user_signature - */ - public $user_signature; - - /** - * @var integer|string date of the quote; - */ + * @var integer|string date of the quote; + */ @@ -194,3 +152,3 @@ - * @var integer|string $delivery_date; - */ - public $delivery_date; // Date expected of shipment (date starting shipment, not the reception that occurs some days after) + * @var integer|string $date_livraison; + */ + public $date_livraison; @@ -201,0 +160,2 @@ + public $user_valid_id; + public $user_close_id; @@ -219,13 +179,10 @@ - public $cond_reglement_code; // code - public $cond_reglement; // label - public $cond_reglement_doc; // label doc - - public $mode_reglement_code; // code - public $mode_reglement; // label - - public $deposit_percent; - - /** - * @var int ID - * @deprecated - */ + public $cond_reglement_code; + public $mode_reglement_code; + public $remise = 0; + public $remise_percent = 0; + public $remise_absolue = 0; + + /** + * @var int ID + * @deprecated + */ @@ -236,4 +192,0 @@ - - /** - * @var int availabilty ID - */ @@ -241,11 +193,0 @@ - - /** - * @var int availabilty ID - * @deprecated - * @see $availability_id - */ - public $fk_availability; - - /** - * @var string availabilty code - */ @@ -253,14 +195,4 @@ - - /** - * @var string availabilty label - */ - public $availability; - - public $duree_validite; - - public $demand_reason_id; // id - public $demand_reason_code; // code - public $demand_reason; // label - - public $warehouse_id; - + public $demand_reason_id; + public $demand_reason_code; + + public $products = array(); @@ -273,4 +204,0 @@ - - /** - * @var PropaleLigne - */ @@ -280,0 +209,16 @@ + + public $specimen; + + // Multicurrency + /** + * @var int ID + */ + public $fk_multicurrency; + + public $multicurrency_code; + public $multicurrency_tx; + public $multicurrency_total_ht; + public $multicurrency_total_tva; + public $multicurrency_total_ttc; + + public $oldcopy; @@ -301 +245 @@ - * 'arrayofkeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel") + * 'arraykeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel") @@ -317,2 +261,2 @@ - 'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'enabled'=>'isModEnabled("societe")', 'visible'=>-1, 'position'=>23), - 'fk_projet' =>array('type'=>'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)', 'label'=>'Fk projet', 'enabled'=>"isModEnabled('project')", 'visible'=>-1, 'position'=>24), + 'fk_soc' =>array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'enabled'=>1, 'visible'=>-1, 'position'=>23), + 'fk_projet' =>array('type'=>'integer:Project:projet/class/project.class.php:1:fk_statut=1', 'label'=>'Fk projet', 'enabled'=>1, 'visible'=>-1, 'position'=>24), @@ -329,0 +274,3 @@ + 'remise_percent' =>array('type'=>'double', 'label'=>'RelativeDiscount', 'enabled'=>1, 'visible'=>-1, 'position'=>110), + 'remise_absolue' =>array('type'=>'double', 'label'=>'CustomerRelativeDiscount', 'enabled'=>1, 'visible'=>-1, 'position'=>115), + //'remise' =>array('type'=>'double', 'label'=>'Remise', 'enabled'=>1, 'visible'=>-1, 'position'=>120), @@ -331 +278 @@ - 'total_tva' =>array('type'=>'double(24,8)', 'label'=>'VAT', 'enabled'=>1, 'visible'=>-1, 'position'=>130, 'isameasure'=>1), + 'tva' =>array('type'=>'double(24,8)', 'label'=>'VAT', 'enabled'=>1, 'visible'=>-1, 'position'=>130, 'isameasure'=>1), @@ -334,2 +281,2 @@ - 'total_ttc' =>array('type'=>'double(24,8)', 'label'=>'TotalTTC', 'enabled'=>1, 'visible'=>-1, 'position'=>145, 'isameasure'=>1), - 'fk_account' =>array('type'=>'integer', 'label'=>'BankAccount', 'enabled'=>'isModEnabled("banque")', 'visible'=>-1, 'position'=>150), + 'total' =>array('type'=>'double(24,8)', 'label'=>'TotalTTC', 'enabled'=>1, 'visible'=>-1, 'position'=>145, 'isameasure'=>1), + 'fk_account' =>array('type'=>'integer', 'label'=>'BankAccount', 'enabled'=>1, 'visible'=>-1, 'position'=>150), @@ -338 +284,0 @@ - 'deposit_percent' =>array('type'=>'varchar(63)', 'label'=>'DepositPercent', 'enabled'=>1, 'visible'=>-1, 'position'=>161), @@ -340,2 +286,2 @@ - 'note_private' =>array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>170), - 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>175), + 'note_private' =>array('type'=>'text', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>170), + 'note_public' =>array('type'=>'text', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>175), @@ -345 +290,0 @@ - 'fk_warehouse' =>array('type'=>'integer:Entrepot:product/stock/class/entrepot.class.php', 'label'=>'Fk warehouse', 'enabled'=>'isModEnabled("stock")', 'visible'=>-1, 'position'=>191), @@ -353,5 +298,5 @@ - 'multicurrency_code' =>array('type'=>'varchar(255)', 'label'=>'MulticurrencyCurrency', 'enabled'=>'isModEnabled("multicurrency")', 'visible'=>-1, 'position'=>235), - 'multicurrency_tx' =>array('type'=>'double(24,8)', 'label'=>'MulticurrencyRate', 'enabled'=>'isModEnabled("multicurrency")', 'visible'=>-1, 'position'=>240, 'isameasure'=>1), - 'multicurrency_total_ht' =>array('type'=>'double(24,8)', 'label'=>'MulticurrencyAmountHT', 'enabled'=>'isModEnabled("multicurrency")', 'visible'=>-1, 'position'=>245, 'isameasure'=>1), - 'multicurrency_total_tva' =>array('type'=>'double(24,8)', 'label'=>'MulticurrencyAmountVAT', 'enabled'=>'isModEnabled("multicurrency")', 'visible'=>-1, 'position'=>250, 'isameasure'=>1), - 'multicurrency_total_ttc' =>array('type'=>'double(24,8)', 'label'=>'MulticurrencyAmountTTC', 'enabled'=>'isModEnabled("multicurrency")', 'visible'=>-1, 'position'=>255, 'isameasure'=>1), + 'multicurrency_code' =>array('type'=>'varchar(255)', 'label'=>'MulticurrencyCurrency', 'enabled'=>'$conf->multicurrency->enabled', 'visible'=>-1, 'position'=>235), + 'multicurrency_tx' =>array('type'=>'double(24,8)', 'label'=>'MulticurrencyRate', 'enabled'=>'$conf->multicurrency->enabled', 'visible'=>-1, 'position'=>240, 'isameasure'=>1), + 'multicurrency_total_ht' =>array('type'=>'double(24,8)', 'label'=>'MulticurrencyAmountHT', 'enabled'=>'$conf->multicurrency->enabled', 'visible'=>-1, 'position'=>245, 'isameasure'=>1), + 'multicurrency_total_tva' =>array('type'=>'double(24,8)', 'label'=>'MulticurrencyAmountVAT', 'enabled'=>'$conf->multicurrency->enabled', 'visible'=>-1, 'position'=>250, 'isameasure'=>1), + 'multicurrency_total_ttc' =>array('type'=>'double(24,8)', 'label'=>'MulticurrencyAmountTTC', 'enabled'=>'$conf->multicurrency->enabled', 'visible'=>-1, 'position'=>255, 'isameasure'=>1), @@ -393 +338 @@ - public function __construct($db, $socid = 0, $propalid = 0) + public function __construct($db, $socid = 0, $propalid = 0) @@ -402,7 +347,9 @@ - $this->duree_validite = getDolGlobalInt('PROPALE_VALIDITY_DURATION', 0); - } - - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Add line into array ->lines + $this->products = array(); + + $this->duree_validite = $conf->global->PROPALE_VALIDITY_DURATION; + } + + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Add line into array products @@ -414 +361 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -417,4 +364,5 @@ - */ - public function add_product($idproduct, $qty, $remise_percent = 0) - { - // phpcs:enable + * inserted into table $this->products + */ + public function add_product($idproduct, $qty, $remise_percent = 0) + { + // phpcs:enable @@ -423,3 +371 @@ - if (!$qty) { - $qty = 1; - } + if (!$qty) $qty = 1; @@ -428 +374,2 @@ - if ($idproduct > 0) { + if ($idproduct > 0) + { @@ -436,3 +383 @@ - if (empty($tva_tx)) { - $tva_npr = 0; - } + if (empty($tva_tx)) $tva_npr = 0; @@ -445 +390,2 @@ - if ($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level) { + if ($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level) + { @@ -447 +393,3 @@ - } else { + } + else + { @@ -461,3 +409 @@ - if ($tva_npr) { - $line->info_bits = 1; - } + if ($tva_npr) $line->info_bits = 1; @@ -467,5 +413,3 @@ - - return 1; - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -478,3 +422,3 @@ - public function insert_discount($idremise) - { - // phpcs:enable + public function insert_discount($idremise) + { + // phpcs:enable @@ -491,2 +435,4 @@ - if ($result > 0) { - if ($remise->fk_facture) { // Protection against multiple submission + if ($result > 0) + { + if ($remise->fk_facture) // Protection against multiple submission + { @@ -509,0 +456 @@ + $line->remise = 0; @@ -522 +469,2 @@ - if ($result > 0) { + if ($result > 0) + { @@ -524 +472,2 @@ - if ($result > 0) { + if ($result > 0) + { @@ -527 +476,3 @@ - } else { + } + else + { @@ -531 +482,3 @@ - } else { + } + else + { @@ -533 +485,0 @@ - $this->errors = $line->errors; @@ -537 +489,3 @@ - } else { + } + else + { @@ -543,38 +497,37 @@ - /** - * Add a proposal line into database (linked to product/service or not) - * The parameters are already supposed to be appropriate and with final values to the call - * of this method. Also, for the VAT rate, it must have already been defined - * by whose calling the method get_default_tva (societe_vendeuse, societe_acheteuse, '' product) - * and desc must already have the right value (it's up to the caller to manage multilanguage) - * - * @param string $desc Description of line - * @param float $pu_ht Unit price - * @param float $qty Quantity - * @param float $txtva Force Vat rate, -1 for auto (Can contain the vat_src_code too with syntax '9.9 (CODE)') - * @param float $txlocaltax1 Local tax 1 rate (deprecated, use instead txtva with code inside) - * @param float $txlocaltax2 Local tax 2 rate (deprecated, use instead txtva with code inside) - * @param int $fk_product Product/Service ID predefined - * @param float $remise_percent Pourcentage de remise de la ligne - * @param string $price_base_type HT or TTC - * @param float $pu_ttc Prix unitaire TTC - * @param int $info_bits Bits for type of lines - * @param int $type Type of line (0=product, 1=service). Not used if fk_product is defined, the type of product is used. - * @param int $rang Position of line - * @param int $special_code Special code (also used by externals modules!) - * @param int $fk_parent_line Id of parent line - * @param int $fk_fournprice Id supplier price - * @param int $pa_ht Buying price without tax - * @param string $label ??? - * @param int|string $date_start Start date of the line - * @param int|string $date_end End date of the line - * @param array $array_options extrafields array - * @param string $fk_unit Code of the unit to use. Null to use the default one - * @param string $origin Depend on global conf MAIN_CREATEFROM_KEEP_LINE_ORIGIN_INFORMATION can be 'orderdet', 'propaldet'..., else 'order','propal,'.... - * @param int $origin_id Depend on global conf MAIN_CREATEFROM_KEEP_LINE_ORIGIN_INFORMATION can be Id of origin object (aka line id), else object id - * @param double $pu_ht_devise Unit price in currency - * @param int $fk_remise_except Id discount if line is from a discount - * @param int $noupdateafterinsertline No update after insert of line - * @return int >0 if OK, <0 if KO - * @see add_product() - */ - public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $fk_product = 0, $remise_percent = 0.0, $price_base_type = 'HT', $pu_ttc = 0.0, $info_bits = 0, $type = 0, $rang = -1, $special_code = 0, $fk_parent_line = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $date_start = '', $date_end = '', $array_options = array(), $fk_unit = null, $origin = '', $origin_id = 0, $pu_ht_devise = 0, $fk_remise_except = 0, $noupdateafterinsertline = 0) + /** + * Add a proposal line into database (linked to product/service or not) + * The parameters are already supposed to be appropriate and with final values to the call + * of this method. Also, for the VAT rate, it must have already been defined + * by whose calling the method get_default_tva (societe_vendeuse, societe_acheteuse, '' product) + * and desc must already have the right value (it's up to the caller to manage multilanguage) + * + * @param string $desc Description of line + * @param float $pu_ht Unit price + * @param float $qty Quantity + * @param float $txtva Force Vat rate, -1 for auto (Can contain the vat_src_code too with syntax '9.9 (CODE)') + * @param float $txlocaltax1 Local tax 1 rate (deprecated, use instead txtva with code inside) + * @param float $txlocaltax2 Local tax 2 rate (deprecated, use instead txtva with code inside) + * @param int $fk_product Product/Service ID predefined + * @param float $remise_percent Pourcentage de remise de la ligne + * @param string $price_base_type HT or TTC + * @param float $pu_ttc Prix unitaire TTC + * @param int $info_bits Bits for type of lines + * @param int $type Type of line (0=product, 1=service). Not used if fk_product is defined, the type of product is used. + * @param int $rang Position of line + * @param int $special_code Special code (also used by externals modules!) + * @param int $fk_parent_line Id of parent line + * @param int $fk_fournprice Id supplier price + * @param int $pa_ht Buying price without tax + * @param string $label ??? + * @param int $date_start Start date of the line + * @param int $date_end End date of the line + * @param array $array_options extrafields array + * @param string $fk_unit Code of the unit to use. Null to use the default one + * @param string $origin Depend on global conf MAIN_CREATEFROM_KEEP_LINE_ORIGIN_INFORMATION can be 'orderdet', 'propaldet'..., else 'order','propal,'.... + * @param int $origin_id Depend on global conf MAIN_CREATEFROM_KEEP_LINE_ORIGIN_INFORMATION can be Id of origin object (aka line id), else object id + * @param double $pu_ht_devise Unit price in currency + * @param int $fk_remise_except Id discount if line is from a discount + * @return int >0 if OK, <0 if KO + * @see add_product() + */ + public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $fk_product = 0, $remise_percent = 0.0, $price_base_type = 'HT', $pu_ttc = 0.0, $info_bits = 0, $type = 0, $rang = -1, $special_code = 0, $fk_parent_line = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $date_start = '', $date_end = '', $array_options = 0, $fk_unit = null, $origin = '', $origin_id = 0, $pu_ht_devise = 0, $fk_remise_except = 0) @@ -586 +539,2 @@ - if ($this->statut == self::STATUS_DRAFT) { + if ($this->statut == self::STATUS_DRAFT) + { @@ -590,15 +544,5 @@ - if (empty($remise_percent)) { - $remise_percent = 0; - } - if (empty($qty)) { - $qty = 0; - } - if (empty($info_bits)) { - $info_bits = 0; - } - if (empty($rang)) { - $rang = 0; - } - if (empty($fk_parent_line) || $fk_parent_line < 0) { - $fk_parent_line = 0; - } + if (empty($remise_percent)) $remise_percent = 0; + if (empty($qty)) $qty = 0; + if (empty($info_bits)) $info_bits = 0; + if (empty($rang)) $rang = 0; + if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line = 0; @@ -617 +561,2 @@ - if ($price_base_type == 'HT') { + if ($price_base_type == 'HT') + { @@ -619 +564,3 @@ - } else { + } + else + { @@ -624,3 +571 @@ - if ($type < 0) { - return -1; - } + if ($type < 0) return -1; @@ -637 +582,2 @@ - if (!empty($fk_product) && $fk_product > 0) { + if (!empty($fk_product)) + { @@ -642 +588 @@ - if (getDolGlobalString('STOCK_MUST_BE_ENOUGH_FOR_PROPOSAL') && $product_type == 0 && $product->stock_reel < $qty) { + if (!empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_PROPOSAL) && $product_type == 0 && $product->stock_reel < $qty) { @@ -658 +603,0 @@ - $reg = array(); @@ -660,2 +605,2 @@ - $reg = array(); - if (preg_match('/\((.*)\)/', $txtva, $reg)) { + if (preg_match('/\((.*)\)/', $txtva, $reg)) + { @@ -685 +630,2 @@ - if ($ranktouse == -1) { + if ($ranktouse == -1) + { @@ -694 +640,2 @@ - if ($remise_percent > 0) { + if ($remise_percent > 0) + { @@ -713,2 +660,2 @@ - $this->line->localtax1_type = empty($localtaxes_type[0]) ? '' : $localtaxes_type[0]; - $this->line->localtax2_type = empty($localtaxes_type[2]) ? '' : $localtaxes_type[2]; + $this->line->localtax1_type = $localtaxes_type[0]; + $this->line->localtax2_type = $localtaxes_type[2]; @@ -749,3 +696 @@ - if (empty($qty) && empty($special_code)) { - $this->line->special_code = 3; - } + if (empty($qty) && empty($special_code)) $this->line->special_code = 3; @@ -754,0 +700 @@ + $this->line->remise = $remise; @@ -761 +707,2 @@ - if ($result > 0) { + if ($result > 0) + { @@ -763,29 +710,25 @@ - if (!empty($fk_parent_line)) { - $this->line_order(true, 'DESC'); - } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) { // Update all rank of all other lines - $linecount = count($this->lines); - for ($ii = $ranktouse; $ii <= $linecount; $ii++) { - $this->updateRangOfLine($this->lines[$ii - 1]->id, $ii + 1); - } - } - - // Mise a jour informations denormalisees au niveau de la propale meme - if (empty($noupdateafterinsertline)) { - $result = $this->update_price(1, 'auto', 0, $mysoc); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. - } - - if ($result > 0) { - $this->db->commit(); - return $this->line->id; - } else { - $this->error = $this->db->error(); - $this->db->rollback(); - return -1; - } - } else { - $this->error = $this->line->error; - $this->errors = $this->line->errors; - $this->db->rollback(); - return -2; - } - } else { + if (!empty($fk_parent_line)) $this->line_order(true, 'DESC'); + + // Mise a jour informations denormalisees au niveau de la propale meme + $result = $this->update_price(1, 'auto', 0, $mysoc); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. + if ($result > 0) + { + $this->db->commit(); + return $this->line->id; + } + else + { + $this->error = $this->db->error(); + $this->db->rollback(); + return -1; + } + } + else + { + $this->error = $this->line->error; + $this->db->rollback(); + return -2; + } + } + else + { @@ -795 +738 @@ - } + } @@ -801,2 +744,2 @@ - * @param int $rowid Id of line - * @param float $pu Unit price (HT or TTC depending on price_base_type) + * @param int $rowid Id de la ligne + * @param float $pu Prix unitaire (HT ou TTC selon price_base_type) @@ -804,2 +747,2 @@ - * @param float $remise_percent Discount on line - * @param float $txtva VAT Rate (Can be '1.23' or '1.23 (ABC)') + * @param float $remise_percent Remise effectuee sur le produit + * @param float $txtva Taux de TVA @@ -809 +752 @@ - * @param string $price_base_type HT or TTC + * @param string $price_base_type HT ou TTC @@ -818,2 +761,2 @@ - * @param int|string $date_start Start date of the line - * @param int|string $date_end End date of the line + * @param int $date_start Start date of the line + * @param int $date_end End date of the line @@ -824 +766,0 @@ - * @param integer $rang line rank @@ -827 +769 @@ - public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $desc = '', $price_base_type = 'HT', $info_bits = 0, $special_code = 0, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $type = 0, $date_start = '', $date_end = '', $array_options = array(), $fk_unit = null, $pu_ht_devise = 0, $notrigger = 0, $rang = 0) + public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $desc = '', $price_base_type = 'HT', $info_bits = 0, $special_code = 0, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $type = 0, $date_start = '', $date_end = '', $array_options = 0, $fk_unit = null, $pu_ht_devise = 0, $notrigger = 0) @@ -831 +773 @@ - dol_syslog(get_class($this)."::updateLine rowid=$rowid, pu=$pu, qty=$qty, remise_percent=$remise_percent, + dol_syslog(get_class($this)."::updateLine rowid=$rowid, pu=$pu, qty=$qty, remise_percent=$remise_percent, @@ -840,3 +782 @@ - if (!preg_match('/\((.*)\)/', $txtva)) { - $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5' - } + $txtva = price2num($txtva); @@ -846,17 +786,12 @@ - if (empty($qty) && empty($special_code)) { - $special_code = 3; // Set option tag - } - if (!empty($qty) && $special_code == 3) { - $special_code = 0; // Remove option tag - } - if (empty($type)) { - $type = 0; - } - - if ($date_start && $date_end && $date_start > $date_end) { - $langs->load("errors"); - $this->error = $langs->trans('ErrorStartDateGreaterEnd'); - return -1; - } - - if ($this->statut == self::STATUS_DRAFT) { + if (empty($qty) && empty($special_code)) $special_code = 3; // Set option tag + if (!empty($qty) && $special_code == 3) $special_code = 0; // Remove option tag + if (empty($type)) $type = 0; + + if ($date_start && $date_end && $date_start > $date_end) { + $langs->load("errors"); + $this->error = $langs->trans('ErrorStartDateGreaterEnd'); + return -1; + } + + if ($this->statut == self::STATUS_DRAFT) + { @@ -875 +810,2 @@ - if (preg_match('/\((.*)\)/', $txtva, $reg)) { + if (preg_match('/\((.*)\)/', $txtva, $reg)) + { @@ -879,2 +814,0 @@ - - // TODO Implement if (getDolGlobalInt('MAIN_UNIT_PRICE_WITH_TAX_IS_FOR_ALL_TAXES')) ? @@ -901 +835,2 @@ - if ($remise_percent > 0) { + if ($remise_percent > 0) + { @@ -908,0 +844 @@ + $line->fetch_optionals(); @@ -915 +850,0 @@ - $this->line->rang = $rang; @@ -918 +853,2 @@ - if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) { + if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) + { @@ -932,2 +868,2 @@ - $this->line->localtax1_type = empty($localtaxes_type[0]) ? '' : $localtaxes_type[0]; - $this->line->localtax2_type = empty($localtaxes_type[2]) ? '' : $localtaxes_type[2]; + $this->line->localtax1_type = $localtaxes_type[0]; + $this->line->localtax2_type = $localtaxes_type[2]; @@ -953,0 +890,4 @@ + // TODO deprecated + $this->line->price = $price; + $this->line->remise = $remise; + @@ -968 +908,2 @@ - if ($result > 0) { + if ($result > 0) + { @@ -970,9 +911,6 @@ - if (!empty($fk_parent_line)) { - $this->line_order(true, 'DESC'); - } - - $this->update_price(1, 'auto'); - - // $this is Propal - // $this->fk_propal = $this->id; - // $this->rowid = $rowid; + if (!empty($fk_parent_line)) $this->line_order(true, 'DESC'); + + $this->update_price(1); + + $this->fk_propal = $this->id; + $this->rowid = $rowid; @@ -982 +920,3 @@ - } else { + } + else + { @@ -984 +924 @@ - $this->errors = $this->line->errors; + @@ -988 +928,3 @@ - } else { + } + else + { @@ -999 +940,0 @@ - * @param int $id Id of object (for a check) @@ -1002 +943 @@ - public function deleteline($lineid, $id = 0) + public function deleteline($lineid) @@ -1006 +947,2 @@ - if ($this->statut == self::STATUS_DRAFT) { + if ($this->statut == self::STATUS_DRAFT) + { @@ -1011,3 +953 @@ - $line->context = $this->context; - - // Load data + // For triggers @@ -1016,10 +956,2 @@ - if ($id > 0 && $line->fk_propal != $id) { - $this->error = 'ErrorLineIDDoesNotMatchWithObjectID'; - return -1; - } - - // Memorize previous line for triggers - $staticline = clone $line; - $line->oldline = $staticline; - - if ($line->delete($user) > 0) { + if ($line->delete($user) > 0) + { @@ -1030,3 +962,3 @@ - } else { - $this->error = $line->error; - $this->errors = $line->errors; + } + else + { @@ -1036 +968,3 @@ - } else { + } + else + { @@ -1049,5 +983,5 @@ - * @return int Return integer <0 if KO, >=0 if OK - */ - public function create($user, $notrigger = 0) - { - global $conf, $hookmanager, $mysoc; + * @return int <0 if KO, >=0 if OK + */ + public function create($user, $notrigger = 0) + { + global $conf, $hookmanager; @@ -1059,3 +993 @@ - if (empty($this->date)) { - $this->date = $this->datep; - } + if (empty($this->date)) $this->date = $this->datep; @@ -1063,6 +995,2 @@ - if (empty($this->availability_id)) { - $this->availability_id = 0; - } - if (empty($this->demand_reason_id)) { - $this->demand_reason_id = 0; - } + if (empty($this->availability_id)) $this->availability_id = 0; + if (empty($this->demand_reason_id)) $this->demand_reason_id = 0; @@ -1071,6 +999,4 @@ - if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) { - list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $this->date); - } else { - $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); - } - if (empty($this->fk_multicurrency)) { + if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $this->date); + else $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); + if (empty($this->fk_multicurrency)) + { @@ -1082,3 +1007,0 @@ - // Set tmp vars - $delivery_date = $this->delivery_date; - @@ -1089 +1012,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -1096 +1020,2 @@ - if (!empty($this->ref)) { // We check that ref is not already used + if (!empty($this->ref)) // We check that ref is not already used + { @@ -1098 +1023,2 @@ - if ($result > 0) { + if ($result > 0) + { @@ -1106 +1032,2 @@ - if (empty($this->date)) { + if (empty($this->date)) + { @@ -1119,2 +1046,5 @@ - $sql .= ", total_tva"; - $sql .= ", total_ttc"; + $sql .= ", remise"; + $sql .= ", remise_percent"; + $sql .= ", remise_absolue"; + $sql .= ", tva"; + $sql .= ", total"; @@ -1130 +1059,0 @@ - $sql .= ", deposit_percent"; @@ -1134 +1062,0 @@ - $sql .= ", ref_ext"; @@ -1137 +1064,0 @@ - $sql .= ", fk_warehouse"; @@ -1150,0 +1078,3 @@ + $sql .= ", ".$this->remise; + $sql .= ", ".($this->remise_percent ? $this->db->escape($this->remise_percent) : 'NULL'); + $sql .= ", ".($this->remise_absolue ? $this->db->escape($this->remise_absolue) : 'NULL'); @@ -1156 +1086 @@ - $sql .= ", ".($user->id > 0 ? ((int) $user->id) : "NULL"); + $sql .= ", ".($user->id > 0 ? "'".$user->id."'" : "NULL"); @@ -1159 +1089 @@ - $sql .= ", '".$this->db->escape($this->model_pdf)."'"; + $sql .= ", '".$this->db->escape($this->modelpdf)."'"; @@ -1161,4 +1091,3 @@ - $sql .= ", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) : 'NULL'); - $sql .= ", ".(!empty($this->deposit_percent) ? "'".$this->db->escape($this->deposit_percent)."'" : 'NULL'); - $sql .= ", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) : 'NULL'); - $sql .= ", ".($this->fk_account > 0 ? ((int) $this->fk_account) : 'NULL'); + $sql .= ", ".($this->cond_reglement_id > 0 ? $this->cond_reglement_id : 'NULL'); + $sql .= ", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id : 'NULL'); + $sql .= ", ".($this->fk_account > 0 ? $this->fk_account : 'NULL'); @@ -1166,2 +1095 @@ - $sql .= ", '".$this->db->escape($this->ref_ext)."'"; - $sql .= ", ".(empty($delivery_date) ? "NULL" : "'".$this->db->idate($delivery_date)."'"); + $sql .= ", ".($this->date_livraison != '' ? "'".$this->db->idate($this->date_livraison)."'" : "NULL"); @@ -1169 +1096,0 @@ - $sql .= ", ".($this->warehouse_id > 0 ? $this->warehouse_id : 'NULL'); @@ -1178 +1105 @@ - $sql .= ", ".(float) $this->multicurrency_tx; + $sql .= ", ".(double) $this->multicurrency_tx; @@ -1183 +1110,2 @@ - if ($resql) { + if ($resql) + { @@ -1186 +1114,2 @@ - if ($this->id) { + if ($this->id) + { @@ -1188 +1117 @@ - $sql = 'UPDATE '.MAIN_DB_PREFIX."propal SET ref='".$this->db->escape($this->ref)."' WHERE rowid=".((int) $this->id); + $sql = 'UPDATE '.MAIN_DB_PREFIX."propal SET ref='".$this->db->escape($this->ref)."' WHERE rowid=".$this->id; @@ -1192,45 +1121,56 @@ - if (!$resql) { - $error++; - } - - if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) { // To use new linkedObjectsIds instead of old linked_objects - $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds - } - - // Add object linked - if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) { - foreach ($this->linked_objects as $origin => $tmp_origin_id) { - if (is_array($tmp_origin_id)) { // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) - foreach ($tmp_origin_id as $origin_id) { - $ret = $this->add_object_linked($origin, $origin_id); - if (!$ret) { - $this->error = $this->db->lasterror(); - $error++; - } - } - } else { // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1)) - $origin_id = $tmp_origin_id; - $ret = $this->add_object_linked($origin, $origin_id); - if (!$ret) { - $this->error = $this->db->lasterror(); - $error++; - } - } - } - } - - /* - * Insertion du detail des produits dans la base - * Insert products detail in database - */ - if (!$error) { - $fk_parent_line = 0; - $num = count($this->lines); - - for ($i = 0; $i < $num; $i++) { - if (!is_object($this->lines[$i])) { // If this->lines is not array of objects, coming from REST API - // Convert into object this->lines[$i]. - $line = (object) $this->lines[$i]; - } else { - $line = $this->lines[$i]; - } + if (!$resql) $error++; + + if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects + { + $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds + } + + // Add object linked + if (!$error && $this->id && is_array($this->linked_objects) && !empty($this->linked_objects)) + { + foreach ($this->linked_objects as $origin => $tmp_origin_id) + { + if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) + { + foreach ($tmp_origin_id as $origin_id) + { + $ret = $this->add_object_linked($origin, $origin_id); + if (!$ret) + { + $this->error = $this->db->lasterror(); + $error++; + } + } + } + else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1)) + { + $origin_id = $tmp_origin_id; + $ret = $this->add_object_linked($origin, $origin_id); + if (!$ret) + { + $this->error = $this->db->lasterror(); + $error++; + } + } + } + } + + /* + * Insertion du detail des produits dans la base + * Insert products detail in database + */ + if (!$error) + { + $fk_parent_line = 0; + $num = count($this->lines); + + for ($i = 0; $i < $num; $i++) + { + if (!is_object($this->lines[$i])) // If this->lines is not array of objects, coming from REST API + { // Convert into object this->lines[$i]. + $line = (object) $this->lines[$i]; + } + else + { + $line = $this->lines[$i]; + } @@ -1241 +1181 @@ - // Complete vat rate with code + // Complete vat rate with code @@ -1243,5 +1183,3 @@ - if ($line->vat_src_code && !preg_match('/\(.*\)/', $vatrate)) { - $vatrate .= ' ('.$line->vat_src_code.')'; - } - - if (getDolGlobalString('MAIN_CREATEFROM_KEEP_LINE_ORIGIN_INFORMATION')) { + if ($line->vat_src_code && !preg_match('/\(.*\)/', $vatrate)) $vatrate .= ' ('.$line->vat_src_code.')'; + + if (!empty($conf->global->MAIN_CREATEFROM_KEEP_LINE_ORIGIN_INFORMATION)) { @@ -1279,4 +1217 @@ - $originid, - 0, - 0, - 1 + $originid @@ -1285 +1220,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -1291,4 +1226,0 @@ - - // Set the id on created row - $line->id = $result; - @@ -1306 +1238 @@ - $sql.= " SET fk_delivery_address = ".((int) $this->fk_delivery_address); + $sql.= " SET fk_delivery_address = ".$this->fk_delivery_address; @@ -1313 +1245,2 @@ - if (!$error) { + if (!$error) + { @@ -1315,2 +1248,3 @@ - $resql = $this->update_price(1, 'auto', 0, $mysoc); - if ($resql) { + $resql = $this->update_price(1); + if ($resql) + { @@ -1320 +1254,2 @@ - if (!$error) { + if (!$error) + { @@ -1322 +1257,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -1327 +1263,2 @@ - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { @@ -1330,3 +1267 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } @@ -1335 +1270,3 @@ - } else { + } + else + { @@ -1340 +1277,3 @@ - } else { + } + else + { @@ -1345 +1284,2 @@ - if (!$error) { + if (!$error) + { @@ -1349 +1289,3 @@ - } else { + } + else + { @@ -1353 +1295,3 @@ - } else { + } + else + { @@ -1359,0 +1304,18 @@ + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Insert into DB a proposal object completely defined by its data members (ex, results from copy). + * + * @param User $user User that create + * @return int Id of the new object if ok, <0 if ko + * @see create() + */ + public function create_from($user) + { + // phpcs:enable + // i love this function because $this->products is not used in create function... + $this->products = $this->lines; + + return $this->create($user); + } + @@ -1366,2 +1327,0 @@ - * @param bool $update_prices [=false] Update prices if true - * @param bool $update_desc [=false] Update description if true @@ -1370,3 +1330,3 @@ - public function createFromClone(User $user, $socid = 0, $forceentity = null, $update_prices = false, $update_desc = false) - { - global $conf, $hookmanager, $mysoc; + public function createFromClone(User $user, $socid = 0, $forceentity = null) + { + global $conf, $hookmanager; @@ -1386,0 +1347 @@ + $object->fetch_lines(); @@ -1391,19 +1352,20 @@ - if (!empty($socid) && $socid != $object->socid) { - if ($objsoc->fetch($socid) > 0) { - $object->socid = $objsoc->id; - $object->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0); - $object->deposit_percent = (!empty($objsoc->deposit_percent) ? $objsoc->deposit_percent : null); - $object->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0); - $object->fk_delivery_address = ''; - - /*if (isModEnabled('project')) - { - $project = new Project($db); - if ($this->fk_project > 0 && $project->fetch($this->fk_project)) { - if ($project->socid <= 0) $clonedObj->fk_project = $this->fk_project; - else $clonedObj->fk_project = ''; - } else { - $clonedObj->fk_project = ''; - } - }*/ - $object->fk_project = ''; // A cloned proposal is set by default to no project. + if (!empty($socid) && $socid != $object->socid) + { + if ($objsoc->fetch($socid) > 0) + { + $object->socid = $objsoc->id; + $object->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0); + $object->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0); + $object->fk_delivery_address = ''; + + /*if (!empty($conf->projet->enabled)) + { + $project = new Project($db); + if ($this->fk_project > 0 && $project->fetch($this->fk_project)) { + if ($project->socid <= 0) $clonedObj->fk_project = $this->fk_project; + else $clonedObj->fk_project = ''; + } else { + $clonedObj->fk_project = ''; + } + }*/ + $object->fk_project = ''; // A cloned proposal is set by default to no project. @@ -1413,3 +1375 @@ - if (!getDolGlobalString('MAIN_KEEP_REF_CUSTOMER_ON_CLONING')) { - $object->ref_client = ''; - } + $object->ref_client = ''; @@ -1418,58 +1378,4 @@ - } else { - $objsoc->fetch($object->socid); - } - - // update prices - if ($update_prices === true || $update_desc === true) { - if ($objsoc->id > 0 && !empty($object->lines)) { - if ($update_prices === true && getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) { - // If price per customer - require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php'; - } - - foreach ($object->lines as $line) { - $line->id = 0; - - if ($line->fk_product > 0) { - $prod = new Product($this->db); - $res = $prod->fetch($line->fk_product); - if ($res > 0) { - if ($update_prices === true) { - $pu_ht = $prod->price; - $tva_tx = get_default_tva($mysoc, $objsoc, $prod->id); - $remise_percent = $objsoc->remise_percent; - - if (getDolGlobalString('PRODUIT_MULTIPRICES') && $objsoc->price_level > 0) { - $pu_ht = $prod->multiprices[$objsoc->price_level]; - if (getDolGlobalString('PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL')) { // using this option is a bug. kept for backward compatibility - if (isset($prod->multiprices_tva_tx[$objsoc->price_level])) { - $tva_tx = $prod->multiprices_tva_tx[$objsoc->price_level]; - } - } - } elseif (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) { - $prodcustprice = new ProductCustomerPrice($this->db); - $filter = array('t.fk_product' => $prod->id, 't.fk_soc' => $objsoc->id); - $result = $prodcustprice->fetchAll('', '', 0, 0, $filter); - if ($result) { - // If there is some prices specific to the customer - if (count($prodcustprice->lines) > 0) { - $pu_ht = price($prodcustprice->lines[0]->price); - $tva_tx = ($prodcustprice->lines[0]->default_vat_code ? $prodcustprice->lines[0]->tva_tx.' ('.$prodcustprice->lines[0]->default_vat_code.' )' : $prodcustprice->lines[0]->tva_tx); - if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) { - $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')'; - } - } - } - } - - $line->subprice = $pu_ht; - $line->tva_tx = $tva_tx; - $line->remise_percent = $remise_percent; - } - if ($update_desc === true) { - $line->desc = $prod->description; - } - } - } - } - } + } + else + { + $objsoc->fetch($object->socid); @@ -1480 +1386 @@ - $object->entity = (!empty($forceentity) ? $forceentity : $object->entity); + $object->entity = (! empty($forceentity) ? $forceentity : $object->entity); @@ -1485 +1391 @@ - $object->user_validation_id = 0; + $object->user_valid = ''; @@ -1489,4 +1395,3 @@ - if (!getDolGlobalString('MAIN_KEEP_REF_CUSTOMER_ON_CLONING')) { - $object->ref_client = ''; - } - if (getDolGlobalInt('MAIN_DONT_KEEP_NOTE_ON_CLONING') == 1) { + if (empty($conf->global->MAIN_KEEP_REF_CUSTOMER_ON_CLONING)) $object->ref_client = ''; + if ($conf->global->MAIN_DONT_KEEP_NOTE_ON_CLONING == 1) + { @@ -1499,7 +1404,9 @@ - if ($result < 0) { - $this->error = $object->error; - $this->errors = array_merge($this->errors, $object->errors); - $error++; - } - - if (!$error && !getDolGlobalInt('MAIN_IGNORE_CONTACTS_ON_CLONING')) { + if ($result < 0) + { + $this->error = $object->error; + $this->errors = array_merge($this->errors, $object->errors); + $error++; + } + + if (!$error) + { @@ -1507 +1414,2 @@ - if ($object->copy_linked_contact($this, 'internal') < 0) { + if ($object->copy_linked_contact($this, 'internal') < 0) + { @@ -1509,4 +1417,5 @@ - } - } - - if (!$error) { + } + } + + if (!$error) + { @@ -1514,2 +1423,3 @@ - if ($this->socid == $object->socid) { - if ($object->copy_linked_contact($this, 'external') < 0) { + if ($this->socid == $object->socid) + { + if ($object->copy_linked_contact($this, 'external') < 0) @@ -1517,5 +1427,5 @@ - } - } - } - - if (!$error) { + } + } + + if (!$error) + { @@ -1523 +1433,2 @@ - if (is_object($hookmanager)) { + if (is_object($hookmanager)) + { @@ -1527,4 +1438 @@ - if ($reshook < 0) { - $this->setErrorsFromObject($hookmanager); - $error++; - } + if ($reshook < 0) $error++; @@ -1537 +1445,2 @@ - if (!$error) { + if (!$error) + { @@ -1540 +1449,3 @@ - } else { + } + else + { @@ -1549,10 +1460,9 @@ - * @param int $rowid Id of object to load - * @param string $ref Ref of proposal - * @param string $ref_ext Ref ext of proposal - * @param int $forceentity Entity id to force when searching on ref or ref_ext - * @return int >0 if OK, <0 if KO - */ - public function fetch($rowid, $ref = '', $ref_ext = '', $forceentity = 0) - { - $sql = "SELECT p.rowid, p.ref, p.entity, p.fk_soc"; - $sql .= ", p.total_ttc, p.total_tva, p.localtax1, p.localtax2, p.total_ht"; + * @param int $rowid id of object to load + * @param string $ref Ref of proposal + * @param string $ref_ext Ref ext of proposal + * @return int >0 if OK, <0 if KO + */ + public function fetch($rowid, $ref = '', $ref_ext = '') + { + $sql = "SELECT p.rowid, p.ref, p.entity, p.remise, p.remise_percent, p.remise_absolue, p.fk_soc"; + $sql .= ", p.total, p.tva, p.localtax1, p.localtax2, p.total_ht"; @@ -1560 +1469,0 @@ - $sql .= ", p.date_signature as dates"; @@ -1564,2 +1473,2 @@ - $sql .= ", p.date_livraison as delivery_date"; - $sql .= ", p.model_pdf, p.last_main_doc, p.ref_client, ref_ext, p.extraparams"; + $sql .= ", p.date_livraison as date_livraison"; + $sql .= ", p.model_pdf, p.last_main_doc, p.ref_client, p.extraparams"; @@ -1576 +1484,0 @@ - $sql .= ", p.fk_warehouse"; @@ -1584 +1492 @@ - $sql .= ", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc, p.deposit_percent"; + $sql .= ", cr.code as cond_reglement_code, cr.libelle as cond_reglement, cr.libelle_facture as cond_reglement_libelle_doc"; @@ -1594,6 +1502,2 @@ - if (!empty($ref)) { - if (!empty($forceentity)) { - $sql .= " WHERE p.entity = ".(int) $forceentity; // Check only the current entity because we may have the same reference in several entities - } else { - $sql .= " WHERE p.entity IN (".getEntity('propal').")"; - } + if ($ref) { + $sql .= " WHERE p.entity IN (".getEntity('propal').")"; // Dont't use entity if you use rowid @@ -1601,4 +1505,2 @@ - } else { - // Dont't use entity if you use rowid - $sql .= " WHERE p.rowid = ".((int) $rowid); - } + } + else $sql .= " WHERE p.rowid=".$rowid; @@ -1608,2 +1510,4 @@ - if ($resql) { - if ($this->db->num_rows($resql)) { + if ($resql) + { + if ($this->db->num_rows($resql)) + { @@ -1617,5 +1521,4 @@ - $this->ref_customer = $obj->ref_client; - $this->ref_ext = $obj->ref_ext; - - $this->total = $obj->total_ttc; // TODO deprecated - $this->total_ttc = $obj->total_ttc; + $this->remise = $obj->remise; + $this->remise_percent = $obj->remise_percent; + $this->remise_absolue = $obj->remise_absolue; + $this->total = $obj->total; // TODO deprecated @@ -1623 +1526 @@ - $this->total_tva = $obj->total_tva; + $this->total_tva = $obj->tva; @@ -1625,0 +1529 @@ + $this->total_ttc = $obj->total; @@ -1633 +1537 @@ - $this->model_pdf = $obj->model_pdf; + $this->modelpdf = $obj->model_pdf; @@ -1640 +1544,2 @@ - $this->statut = $this->status; // deprecated + $this->statut = $this->status; // deprecated + $this->statut_libelle = $obj->statut_label; @@ -1647 +1551,0 @@ - $this->date_signature = $this->db->jdate($obj->dates); // Signature date @@ -1651 +1555 @@ - $this->delivery_date = $this->db->jdate($obj->delivery_date); + $this->date_livraison = $this->db->jdate($obj->date_livraison); @@ -1653 +1556,0 @@ - $this->warehouse_id = ($obj->fk_warehouse > 0) ? $obj->fk_warehouse : null; @@ -1670,3 +1573,2 @@ - $this->deposit_percent = $obj->deposit_percent; - - $this->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams, true) : array(); + + $this->extraparams = (array) json_decode($obj->extraparams, true); @@ -1675,2 +1577,2 @@ - $this->user_validation_id = $obj->fk_user_valid; - $this->user_closing_id = $obj->fk_user_cloture; + $this->user_valid_id = $obj->fk_user_valid; + $this->user_close_id = $obj->fk_user_cloture; @@ -1688,4 +1590,9 @@ - $this->multicurrency_total_tva = $obj->multicurrency_total_tva; - $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc; - - // Retrieve all extrafield + $this->multicurrency_total_tva = $obj->multicurrency_total_tva; + $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc; + + if ($obj->fk_statut == self::STATUS_DRAFT) + { + $this->brouillon = 1; + } + + // Retreive all extrafield @@ -1701 +1608,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -1710 +1618,3 @@ - } else { + } + else + { @@ -1721,3 +1631,3 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function update(User $user, $notrigger = 0) + * @return int <0 if KO, >0 if OK + */ + public function update(User $user, $notrigger = 0) @@ -1730,21 +1640,7 @@ - if (isset($this->ref)) { - $this->ref = trim($this->ref); - } - if (isset($this->ref_client)) { - $this->ref_client = trim($this->ref_client); - } - if (isset($this->note) || isset($this->note_private)) { - $this->note_private = (isset($this->note_private) ? trim($this->note_private) : trim($this->note)); - } - 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->import_key)) { - $this->import_key = trim($this->import_key); - } - if (!empty($this->duree_validite) && is_numeric($this->duree_validite)) { - $this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600); - } + if (isset($this->ref)) $this->ref = trim($this->ref); + if (isset($this->ref_client)) $this->ref_client = trim($this->ref_client); + if (isset($this->note) || isset($this->note_private)) $this->note_private = (isset($this->note_private) ? trim($this->note_private) : trim($this->note)); + if (isset($this->note_public)) $this->note_public = trim($this->note_public); + if (isset($this->modelpdf)) $this->modelpdf = trim($this->modelpdf); + if (isset($this->import_key)) $this->import_key = trim($this->import_key); + if (!empty($this->duree_validite)) $this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600); @@ -1756,0 +1653 @@ + @@ -1762,3 +1659 @@ - if (!empty($this->fin_validite)) { - $sql .= " fin_validite=".(strval($this->fin_validite) != '' ? "'".$this->db->idate($this->fin_validite)."'" : 'null').","; - } + if (!empty($this->fin_validite)) $sql .= " fin_validite=".(strval($this->fin_validite) != '' ? "'".$this->db->idate($this->fin_validite)."'" : 'null').","; @@ -1766 +1661 @@ - $sql .= " total_tva=".(isset($this->total_tva) ? $this->total_tva : "null").","; + $sql .= " tva=".(isset($this->total_tva) ? $this->total_tva : "null").","; @@ -1770 +1665 @@ - $sql .= " total_ttc=".(isset($this->total_ttc) ? $this->total_ttc : "null").","; + $sql .= " total=".(isset($this->total_ttc) ? $this->total_ttc : "null").","; @@ -1773 +1668 @@ - $sql .= " fk_user_valid=".(isset($this->user_validation_id) ? $this->user_validation_id : "null").","; + $sql .= " fk_user_valid=".(isset($this->user_valid) ? $this->user_valid : "null").","; @@ -1776 +1670,0 @@ - $sql .= " deposit_percent=".(!empty($this->deposit_percent) ? "'".$this->db->escape($this->deposit_percent)."'" : "null").","; @@ -1778 +1671,0 @@ - $sql .= " fk_input_reason=".(isset($this->demand_reason_id) ? $this->demand_reason_id : "null").","; @@ -1781,3 +1674,4 @@ - $sql .= " model_pdf=".(isset($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null").","; - $sql .= " import_key=".(isset($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null"); - $sql .= " WHERE rowid=".((int) $this->id); + $sql .= " model_pdf=".(isset($this->modelpdf) ? "'".$this->db->escape($this->modelpdf)."'" : "null").","; + $sql .= " import_key=".(isset($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null").""; + + $sql .= " WHERE rowid=".$this->id; @@ -1790,5 +1684,5 @@ - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - - if (!$error) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } + + if (!$error) + { @@ -1796 +1690,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -1801 +1696,2 @@ - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { @@ -1804,3 +1700 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -1811,2 +1705,4 @@ - if ($error) { - foreach ($this->errors as $errmsg) { + if ($error) + { + foreach ($this->errors as $errmsg) + { @@ -1818 +1714,3 @@ - } else { + } + else + { @@ -1825 +1723 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -1829,8 +1727,9 @@ - * @param int $only_product Return only physical products - * @param int $loadalsotranslation Return translation for products - * @param string $sqlforgedfilters Filter on other fields - * @return int Return integer <0 if KO, >0 if OK - */ - public function fetch_lines($only_product = 0, $loadalsotranslation = 0, $sqlforgedfilters = '') - { - // phpcs:enable + * @param int $only_product Return only physical products + * @param int $loadalsotranslation Return translation for products + * + * @return int <0 if KO, >0 if OK + */ + public function fetch_lines($only_product = 0, $loadalsotranslation = 0) + { + global $langs, $conf; + // phpcs:enable @@ -1842 +1741 @@ - $sql .= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label, p.tobatch as product_tobatch, p.barcode as product_barcode,'; + $sql .= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label, p.tobatch as product_batch,'; @@ -1848,7 +1747,2 @@ - $sql .= ' WHERE d.fk_propal = '.((int) $this->id); - if ($only_product) { - $sql .= ' AND p.fk_product_type = 0'; - } - if ($sqlforgedfilters) { - $sql .= $sqlforgedfilters; - } + $sql .= ' WHERE d.fk_propal = '.$this->id; + if ($only_product) $sql .= ' AND p.fk_product_type = 0'; @@ -1859 +1753,2 @@ - if ($result) { + if ($result) + { @@ -1865 +1760,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -1906,0 +1803 @@ + $line->product_ref = $objp->product_ref; @@ -1908,2 +1804,0 @@ - - $line->product_ref = $objp->product_ref; @@ -1913,2 +1807,0 @@ - $line->product_barcode = $objp->product_barcode; - @@ -1936,7 +1829,5 @@ - if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($objp->fk_product) && !empty($loadalsotranslation)) { - $tmpproduct = new Product($this->db); - $tmpproduct->fetch($objp->fk_product); - $tmpproduct->getMultiLangs(); - - $line->multilangs = $tmpproduct->multilangs; - } + if (!empty($conf->global->MAIN_MULTILANGS) && !empty($objp->fk_product) && !empty($loadalsotranslation)) { + $line = new Product($this->db); + $line->fetch($objp->fk_product); + $line->getMultiLangs(); + } @@ -1945 +1836,2 @@ - + //dol_syslog("1 ".$line->fk_product); + //print "xx $i ".$this->lines[$i]->fk_product; @@ -1952 +1844,3 @@ - } else { + } + else + { @@ -1963,3 +1857,3 @@ - * @return int Return integer <0 if KO, 0=Nothing done, >=0 if OK - */ - public function valid($user, $notrigger = 0) + * @return int <0 if KO, 0=Nothing done, >=0 if OK + */ + public function valid($user, $notrigger = 0) @@ -1974 +1868,2 @@ - if ($this->statut == self::STATUS_VALIDATED) { + if ($this->statut == self::STATUS_VALIDATED) + { @@ -1979,2 +1874,3 @@ - if (!((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('propal', 'creer')) - || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('propal', 'propal_advance', 'validate')))) { + if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->creer)) + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->propal->propal_advance->validate)))) + { @@ -1995 +1891,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 + { @@ -1997 +1894,3 @@ - } else { + } + else + { @@ -2004,2 +1903,2 @@ - $sql .= " fk_statut = ".self::STATUS_VALIDATED.", date_valid='".$this->db->idate($now)."', fk_user_valid=".((int) $user->id); - $sql .= " WHERE rowid = ".((int) $this->id)." AND fk_statut = ".self::STATUS_DRAFT; + $sql .= " fk_statut = ".self::STATUS_VALIDATED.", date_valid='".$this->db->idate($now)."', fk_user_valid=".$user->id; + $sql .= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; @@ -2009 +1908,2 @@ - if (!$resql) { + if (!$resql) + { @@ -2015 +1915,2 @@ - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { @@ -2018,3 +1919 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } @@ -2024 +1923,2 @@ - if (!$error) { + if (!$error) + { @@ -2028 +1928,2 @@ - if (preg_match('/^[\(]?PROV/i', $this->ref)) { + if (preg_match('/^[\(]?PROV/i', $this->ref)) + { @@ -2031 +1932 @@ - $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'propale/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity); + $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'propale/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; @@ -2033,11 +1934 @@ - if (!$resql) { - $error++; - $this->error = $this->db->lasterror(); - } - $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'propale/".$this->db->escape($this->newref)."'"; - $sql .= " WHERE filepath = 'propale/".$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(); } @@ -2050 +1941,2 @@ - if (!$error && file_exists($dirsource)) { + if (!$error && file_exists($dirsource)) + { @@ -2052 +1944,2 @@ - if (@rename($dirsource, $dirdest)) { + if (@rename($dirsource, $dirdest)) + { @@ -2056 +1949,2 @@ - foreach ($listoffiles as $fileentry) { + foreach ($listoffiles as $fileentry) + { @@ -2067,0 +1962 @@ + $this->brouillon = 0; @@ -2069,2 +1964 @@ - $this->status = self::STATUS_VALIDATED; - $this->user_validation_id = $user->id; + $this->user_valid_id = $user->id; @@ -2072 +1965,0 @@ - $this->date_validation = $now; @@ -2076 +1969,3 @@ - } else { + } + else + { @@ -2083 +1978 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2090,6 +1985,7 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function set_date($user, $date, $notrigger = 0) - { - // phpcs:enable - if (empty($date)) { + * @return int <0 if KO, >0 if OK + */ + public function set_date($user, $date, $notrigger = 0) + { + // phpcs:enable + if (empty($date)) + { @@ -2101 +1997,2 @@ - if ($user->hasRight('propal', 'creer')) { + if (!empty($user->rights->propal->creer)) + { @@ -2107 +2004 @@ - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; @@ -2111 +2008,2 @@ - if (!$resql) { + if (!$resql) + { @@ -2116 +2014,2 @@ - if (!$error) { + if (!$error) + { @@ -2122 +2021,2 @@ - if (!$notrigger && empty($error)) { + if (!$notrigger && empty($error)) + { @@ -2125,3 +2025 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -2131 +2029,2 @@ - if (!$error) { + if (!$error) + { @@ -2134,2 +2033,5 @@ - } else { - foreach ($this->errors as $errmsg) { + } + else + { + foreach ($this->errors as $errmsg) + { @@ -2143,5 +2045,3 @@ - - return -1; - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2152 +2052 @@ - * @param int $date_end_validity End of validity date + * @param int $date_fin_validite End of validity date @@ -2154,6 +2054,7 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function set_echeance($user, $date_end_validity, $notrigger = 0) - { - // phpcs:enable - if ($user->hasRight('propal', 'creer')) { + * @return int <0 if KO, >0 if OK + */ + public function set_echeance($user, $date_fin_validite, $notrigger = 0) + { + // phpcs:enable + if (!empty($user->rights->propal->creer)) + { @@ -2164,2 +2065,2 @@ - $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fin_validite = ".($date_end_validity != '' ? "'".$this->db->idate($date_end_validity)."'" : 'null'); - $sql .= " WHERE rowid = ".((int) $this->id); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fin_validite = ".($date_fin_validite != '' ? "'".$this->db->idate($date_fin_validite)."'" : 'null'); + $sql .= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; @@ -2168 +2068,0 @@ - @@ -2170 +2070,2 @@ - if (!$resql) { + if (!$resql) + { @@ -2176 +2077,2 @@ - if (!$error) { + if (!$error) + { @@ -2178,4 +2080,5 @@ - $this->fin_validite = $date_end_validity; - } - - if (!$notrigger && empty($error)) { + $this->fin_validite = $date_fin_validite; + } + + if (!$notrigger && empty($error)) + { @@ -2184,3 +2087 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -2190 +2091,2 @@ - if (!$error) { + if (!$error) + { @@ -2193,2 +2095,5 @@ - } else { - foreach ($this->errors as $errmsg) { + } + else + { + foreach ($this->errors as $errmsg) + { @@ -2202,5 +2107,3 @@ - - return -1; - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2211 +2114 @@ - * @param int $delivery_date Delivery date + * @param int $date_livraison Delivery date @@ -2213,20 +2116,7 @@ - * @return int Return integer <0 if ko, >0 if ok - * @deprecated Use setDeliveryDate - */ - public function set_date_livraison($user, $delivery_date, $notrigger = 0) - { - // phpcs:enable - return $this->setDeliveryDate($user, $delivery_date, $notrigger); - } - - /** - * Set delivery date - * - * @param User $user Object user that modify - * @param int $delivery_date Delivery date - * @param int $notrigger 1=Does not execute triggers, 0= execute triggers - * @return int Return integer <0 if ko, >0 if ok - */ - public function setDeliveryDate($user, $delivery_date, $notrigger = 0) - { - if ($user->hasRight('propal', 'creer')) { + * @return int <0 if ko, >0 if ok + */ + public function set_date_livraison($user, $date_livraison, $notrigger = 0) + { + // phpcs:enable + if (!empty($user->rights->propal->creer)) + { @@ -2238,2 +2128,2 @@ - $sql .= " SET date_livraison = ".($delivery_date != '' ? "'".$this->db->idate($delivery_date)."'" : 'null'); - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " SET date_livraison = ".($date_livraison != '' ? "'".$this->db->idate($date_livraison)."'" : 'null'); + $sql .= " WHERE rowid = ".$this->id; @@ -2243 +2133,2 @@ - if (!$resql) { + if (!$resql) + { @@ -2248 +2139,2 @@ - if (!$error) { + if (!$error) + { @@ -2250,4 +2142,5 @@ - $this->delivery_date = $delivery_date; - } - - if (!$notrigger && empty($error)) { + $this->date_livraison = $date_livraison; + } + + if (!$notrigger && empty($error)) + { @@ -2256,3 +2149 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -2262 +2153,2 @@ - if (!$error) { + if (!$error) + { @@ -2265,2 +2157,5 @@ - } else { - foreach ($this->errors as $errmsg) { + } + else + { + foreach ($this->errors as $errmsg) + { @@ -2274,5 +2169,3 @@ - - return -1; - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2285,6 +2178,7 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function set_availability($user, $id, $notrigger = 0) - { - // phpcs:enable - if ($user->hasRight('propal', 'creer') && $this->statut >= self::STATUS_DRAFT) { + * @return int <0 if KO, >0 if OK + */ + public function set_availability($user, $id, $notrigger = 0) + { + // phpcs:enable + if (!empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT) + { @@ -2295,3 +2189,3 @@ - $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; - $sql .= " SET fk_availability = ".((int) $id); - $sql .= " WHERE rowid = ".((int) $this->id); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal "; + $sql .= " SET fk_availability = '".$id."'"; + $sql .= " WHERE rowid = ".$this->id; @@ -2301 +2195,2 @@ - if (!$resql) { + if (!$resql) + { @@ -2306 +2201,2 @@ - if (!$error) { + if (!$error) + { @@ -2312 +2208,2 @@ - if (!$notrigger && empty($error)) { + if (!$notrigger && empty($error)) + { @@ -2315,3 +2212 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -2321 +2216,2 @@ - if (!$error) { + if (!$error) + { @@ -2324,2 +2220,5 @@ - } else { - foreach ($this->errors as $errmsg) { + } + else + { + foreach ($this->errors as $errmsg) + { @@ -2332 +2231,3 @@ - } else { + } + else + { @@ -2341 +2242 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2348,6 +2249,7 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function set_demand_reason($user, $id, $notrigger = 0) - { - // phpcs:enable - if ($user->hasRight('propal', 'creer') && $this->statut >= self::STATUS_DRAFT) { + * @return int <0 if KO, >0 if OK + */ + public function set_demand_reason($user, $id, $notrigger = 0) + { + // phpcs:enable + if (!empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT) + { @@ -2359,2 +2261,2 @@ - $sql .= " SET fk_input_reason = ".((int) $id); - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " SET fk_input_reason = ".$id; + $sql .= " WHERE rowid = ".$this->id; @@ -2364 +2266,2 @@ - if (!$resql) { + if (!$resql) + { @@ -2370 +2273,2 @@ - if (!$error) { + if (!$error) + { @@ -2372 +2276 @@ - + $this->fk_input_reason = $id; @@ -2377 +2281,2 @@ - if (!$notrigger && empty($error)) { + if (!$notrigger && empty($error)) + { @@ -2380,3 +2285 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -2386 +2289,2 @@ - if (!$error) { + if (!$error) + { @@ -2389,2 +2293,5 @@ - } else { - foreach ($this->errors as $errmsg) { + } + else + { + foreach ($this->errors as $errmsg) + { @@ -2397 +2304,3 @@ - } else { + } + else + { @@ -2406 +2315 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2413,6 +2322,7 @@ - * @return int Return integer <0 if ko, >0 if ok - */ - public function set_ref_client($user, $ref_client, $notrigger = 0) - { - // phpcs:enable - if ($user->hasRight('propal', 'creer')) { + * @return int <0 if ko, >0 if ok + */ + public function set_ref_client($user, $ref_client, $notrigger = 0) + { + // phpcs:enable + if (!empty($user->rights->propal->creer)) + { @@ -2423,2 +2333,2 @@ - $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET ref_client = ".(empty($ref_client) ? 'NULL' : "'".$this->db->escape($ref_client)."'"); - $sql .= " WHERE rowid = ".((int) $this->id); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET ref_client = '.(empty($ref_client) ? 'NULL' : '\''.$this->db->escape($ref_client).'\''); + $sql .= ' WHERE rowid = '.$this->id; @@ -2428 +2338,2 @@ - if (!$resql) { + if (!$resql) + { @@ -2433 +2344,2 @@ - if (!$error) { + if (!$error) + { @@ -2438 +2350,2 @@ - if (!$notrigger && empty($error)) { + if (!$notrigger && empty($error)) + { @@ -2441,3 +2354 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -2447 +2358,2 @@ - if (!$error) { + if (!$error) + { @@ -2450,2 +2362,5 @@ - } else { - foreach ($this->errors as $errmsg) { + } + else + { + foreach ($this->errors as $errmsg) + { @@ -2459,5 +2374,7 @@ - - return -1; - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + else + { + return -1; + } + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2470,7 +2387,5 @@ - * @return int Return integer <0 if ko, >0 if ok - * @deprecated remise_percent is a deprecated field for object parent - */ - /* - public function set_remise_percent($user, $remise, $notrigger = 0) - { - // phpcs:enable + * @return int <0 if ko, >0 if ok + */ + public function set_remise_percent($user, $remise, $notrigger = 0) + { + // phpcs:enable @@ -2479,2 +2394,3 @@ - if ($user->hasRight('propal', 'creer')) { - $remise = price2num($remise, 2); + if (!empty($user->rights->propal->creer)) + { + $remise = price2num($remise); @@ -2486,2 +2402,2 @@ - $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".((float) $remise); - $sql .= " WHERE rowid = ".((int) $this->id)." AND fk_statut = ".self::STATUS_DRAFT; + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise; + $sql .= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; @@ -2491 +2407,2 @@ - if (!$resql) { + if (!$resql) + { @@ -2496 +2413,2 @@ - if (!$error) { + if (!$error) + { @@ -2502 +2420,2 @@ - if (!$notrigger && empty($error)) { + if (!$notrigger && empty($error)) + { @@ -2505,3 +2424 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -2511 +2428,2 @@ - if (!$error) { + if (!$error) + { @@ -2514,2 +2432,5 @@ - } else { - foreach ($this->errors as $errmsg) { + } + else + { + foreach ($this->errors as $errmsg) + { @@ -2523,6 +2444,4 @@ - - return -1; - } - */ - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + } + + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2535,12 +2454,11 @@ - * @return int Return integer <0 if ko, >0 if ok - */ - /* - public function set_remise_absolue($user, $remise, $notrigger = 0) - { - // phpcs:enable - if (empty($remise)) { - $remise = 0; - } - $remise = price2num($remise); - - if ($user->hasRight('propal', 'creer')) { + * @return int <0 if ko, >0 if ok + */ + public function set_remise_absolue($user, $remise, $notrigger = 0) + { + // phpcs:enable + $remise = trim($remise) ?trim($remise) : 0; + + if (!empty($user->rights->propal->creer)) + { + $remise = price2num($remise); + @@ -2551,3 +2469,3 @@ - $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; - $sql .= " SET remise_absolue = ".((float) $remise); - $sql .= " WHERE rowid = ".((int) $this->id)." AND fk_statut = ".self::STATUS_DRAFT; + $sql = "UPDATE ".MAIN_DB_PREFIX."propal "; + $sql .= " SET remise_absolue = ".$remise; + $sql .= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; @@ -2557 +2475,2 @@ - if (!$resql) { + if (!$resql) + { @@ -2562 +2481,2 @@ - if (!$error) { + if (!$error) + { @@ -2563,0 +2484 @@ + $this->remise_absolue = $remise; @@ -2567 +2488,2 @@ - if (!$notrigger && empty($error)) { + if (!$notrigger && empty($error)) + { @@ -2570,3 +2492 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -2576 +2496,2 @@ - if (!$error) { + if (!$error) + { @@ -2579,2 +2500,5 @@ - } else { - foreach ($this->errors as $errmsg) { + } + else + { + foreach ($this->errors as $errmsg) + { @@ -2588,4 +2512,2 @@ - - return -1; - } - */ + } + @@ -2598 +2520 @@ - * @param int $status Status + * @param int $statut Statut @@ -2601,4 +2523,6 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function reopen($user, $status, $note = '', $notrigger = 0) - { + * @return int <0 if KO, >0 if OK + */ + public function reopen($user, $statut, $note = '', $notrigger = 0) + { + + $this->statut = $statut; @@ -2608,4 +2532,2 @@ - $sql .= " SET fk_statut = ".((int) $status).","; - if (!empty($note)) { - $sql .= " note_private = '".$this->db->escape($note)."',"; - } + $sql .= " SET fk_statut = ".$this->statut.","; + if (!empty($note)) $sql .= " note_private = '".$this->db->escape($note)."',"; @@ -2613 +2535 @@ - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " WHERE rowid = ".$this->id; @@ -2620,5 +2542,6 @@ - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - if (!$error) { - if (!$notrigger) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } + if (!$error) + { + if (!$notrigger) + { @@ -2627,3 +2550 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } @@ -2635,3 +2556,6 @@ - if ($error) { - if (!empty($this->errors)) { - foreach ($this->errors as $errmsg) { + if ($error) + { + if (!empty($this->errors)) + { + foreach ($this->errors as $errmsg) + { @@ -2644,4 +2568,3 @@ - } else { - $this->statut = $status; - $this->status = $status; - + } + else + { @@ -2653,2 +2576,3 @@ - /** - * Close/set the commercial proposal to status signed or refused (fill also date signature) + + /** + * Close the commercial proposal @@ -2657 +2581 @@ - * @param int $status Status (self::STATUS_BILLED or self::STATUS_REFUSED) + * @param int $statut Statut @@ -2660,5 +2584,5 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function closeProposal($user, $status, $note = '', $notrigger = 0) - { - global $langs,$conf; + * @return int <0 if KO, >0 if OK + */ + public function cloture($user, $statut, $note = "", $notrigger = 0) + { + global $langs, $conf; @@ -2673,20 +2597,3 @@ - if (!getDolGlobalString('PROPALE_KEEP_OLD_SIGNATURE_INFO')) { - $date_signature = $now; - $fk_user_signature = $user->id; - } else { - $this->info($this->id); - if (!isset($this->date_signature) || $this->date_signature == '') { - $date_signature = $now; - $fk_user_signature = $user->id; - } else { - $date_signature = $this->date_signature; - $fk_user_signature = $this->user_signature->id; - } - } - - $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; - $sql .= " SET fk_statut = ".((int) $status).", note_private = '".$this->db->escape($newprivatenote)."'"; - if ($status == self::STATUS_SIGNED) { - $sql .= ", date_signature='".$this->db->idate($now)."', fk_user_signature = ".($fk_user_signature); - } - $sql .= " WHERE rowid = ".((int) $this->id); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; + $sql .= " SET fk_statut = ".$statut.", note_private = '".$this->db->escape($newprivatenote)."', date_cloture='".$this->db->idate($now)."', fk_user_cloture=".$user->id; + $sql .= " WHERE rowid = ".$this->id; @@ -2695,8 +2602,9 @@ - if ($resql) { - // Status self::STATUS_REFUSED by default - $modelpdf = getDolGlobalString('PROPALE_ADDON_PDF_ODT_CLOSED') ? $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED : $this->model_pdf; - $trigger_name = 'PROPAL_CLOSE_REFUSED'; // used later in call_trigger() - - if ($status == self::STATUS_SIGNED) { // Status self::STATUS_SIGNED - $trigger_name = 'PROPAL_CLOSE_SIGNED'; // used later in call_trigger() - $modelpdf = getDolGlobalString('PROPALE_ADDON_PDF_ODT_TOBILL') ? $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL : $this->model_pdf; + if ($resql) + { + $modelpdf = $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED ? $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED : $this->modelpdf; + $triggerName = 'PROPAL_CLOSE_REFUSED'; + + if ($statut == self::STATUS_SIGNED) + { + $triggerName = 'PROPAL_CLOSE_SIGNED'; + $modelpdf = $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL ? $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL : $this->modelpdf; @@ -2705 +2613 @@ - $soc=new Societe($this->db); + $soc = new Societe($this->db); @@ -2707,4 +2615,5 @@ - $result = $soc->setAsCustomer(); - - if ($result < 0) { - $this->error=$this->db->lasterror(); + $result = $soc->set_as_client(); + + if ($result < 0) + { + $this->error = $this->db->lasterror(); @@ -2715,2 +2624,7 @@ - - if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE') && !getDolGlobalInt('PROPAL_DISABLE_AUTOUPDATE_ON_CLOSE')) { + if ($statut == self::STATUS_BILLED) // Why this ? + { + $triggerName = 'PROPAL_CLASSIFY_BILLED'; + } + + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { @@ -2719 +2633,2 @@ - if (getDolGlobalInt('MAIN_MULTILANGS')) { + if (!empty($conf->global->MAIN_MULTILANGS)) + { @@ -2724,6 +2638,0 @@ - - // PDF - $hidedetails = (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0); - $hidedesc = (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0); - $hideref = (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0); - @@ -2731,8 +2640,8 @@ - $this->generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - - if (!$error) { - $this->oldcopy= clone $this; - $this->statut = $status; - $this->status = $status; - $this->date_signature = $date_signature; + $this->generateDocument($modelpdf, $outputlangs); + } + + if (!$error) + { + $this->oldcopy = clone $this; + $this->statut = $statut; + $this->date_cloture = $now; @@ -2742 +2651,2 @@ - if (!$notrigger && empty($error)) { + if (!$notrigger && empty($error)) + { @@ -2744,4 +2654,2 @@ - $result=$this->call_trigger($trigger_name, $user); - if ($result < 0) { - $error++; - } + $result = $this->call_trigger($triggerName, $user); + if ($result < 0) { $error++; } @@ -2751 +2659,2 @@ - if (!$error) { + if (!$error) + { @@ -2754 +2663,3 @@ - } else { + } + else + { @@ -2756,2 +2667 @@ - $this->status = $this->oldcopy->statut; - $this->date_signature = $this->oldcopy->date_signature; + $this->date_cloture = $this->oldcopy->date_cloture; @@ -2763 +2673,3 @@ - } else { + } + else + { @@ -2771 +2683 @@ - * Classify the proposal to status Billed + * Class invoiced the Propal @@ -2775,7 +2687,4 @@ - * @param string $note Complete private note with this note - * @return int Return integer <0 if KO, 0 = nothing done, >0 if OK - */ - public function classifyBilled(User $user, $notrigger = 0, $note = '') - { - global $conf, $langs; - + * @return int <0 si ko, >0 si ok + */ + public function classifyBilled(User $user, $notrigger = 0) + { @@ -2784,5 +2692,0 @@ - $now = dol_now(); - $num = 0; - - $triggerName = 'PROPAL_CLASSIFY_BILLED'; - @@ -2791,5 +2695,2 @@ - $newprivatenote = dol_concatdesc($this->note_private, $note); - - $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_statut = '.self::STATUS_BILLED.", "; - $sql .= " note_private = '".$this->db->escape($newprivatenote)."', date_cloture='".$this->db->idate($now)."', fk_user_cloture=".((int) $user->id); - $sql .= ' WHERE rowid = '.((int) $this->id).' AND fk_statut = '.((int) self::STATUS_SIGNED); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_statut = '.self::STATUS_BILLED; + $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > '.self::STATUS_DRAFT; @@ -2799 +2700,2 @@ - if (!$resql) { + if (!$resql) + { @@ -2802,25 +2704,4 @@ - } else { - $num = $this->db->affected_rows($resql); - } - - if (!$error) { - $modelpdf = $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED ? $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED : $this->model_pdf; - - if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) { - // Define output language - $outputlangs = $langs; - if (getDolGlobalInt('MAIN_MULTILANGS')) { - $outputlangs = new Translate("", $conf); - $newlang = (GETPOST('lang_id', 'aZ09') ? GETPOST('lang_id', 'aZ09') : $this->thirdparty->default_lang); - $outputlangs->setDefaultLang($newlang); - } - - // PDF - $hidedetails = (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0); - $hidedesc = (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0); - $hideref = (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0); - - //$ret=$object->fetch($id); // Reload to get new records - $this->generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - + } + + if (!$error) + { @@ -2829,5 +2710,4 @@ - $this->date_cloture = $now; - $this->note_private = $newprivatenote; - } - - if (!$notrigger && empty($error)) { + } + + if (!$notrigger && empty($error)) + { @@ -2835,4 +2715,2 @@ - $result = $this->call_trigger($triggerName, $user); - if ($result < 0) { - $error++; - } + $result = $this->call_trigger('PROPAL_MODIFY', $user); + if ($result < 0) $error++; @@ -2842 +2720,2 @@ - if (!$error) { + if (!$error) + { @@ -2844,3 +2723,6 @@ - return $num; - } else { - foreach ($this->errors as $errmsg) { + return 1; + } + else + { + foreach ($this->errors as $errmsg) + { @@ -2855 +2737 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2861,5 +2743,5 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function setDraft($user, $notrigger = 0) - { - // phpcs:enable + * @return int <0 if KO, >0 if OK + */ + public function setDraft($user, $notrigger = 0) + { + // phpcs:enable @@ -2869,2 +2751,3 @@ - if ($this->statut <= self::STATUS_DRAFT) { - return 0; + if ($this->statut <= self::STATUS_DRAFT) + { + return 0; @@ -2879,2 +2762 @@ - $sql .= ", online_sign_ip = NULL , online_sign_name = NULL"; - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " WHERE rowid = ".$this->id; @@ -2883 +2765,2 @@ - if (!$resql) { + if (!$resql) + { @@ -2888 +2771,2 @@ - if (!$error) { + if (!$error) + { @@ -2892 +2776,2 @@ - if (!$notrigger && empty($error)) { + if (!$notrigger && empty($error)) + { @@ -2895,3 +2780 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -2901,5 +2784,6 @@ - if (!$error) { - $this->statut = self::STATUS_DRAFT; - $this->status = self::STATUS_DRAFT; - - $this->db->commit(); + if (!$error) + { + $this->statut = self::STATUS_DRAFT; + $this->brouillon = 1; + + $this->db->commit(); @@ -2907,2 +2791,5 @@ - } else { - foreach ($this->errors as $errmsg) { + } + else + { + foreach ($this->errors as $errmsg) + { @@ -2918 +2805 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2930,5 +2817,5 @@ - * @return array|int -1 if KO, array with result if OK - */ - public function liste_array($shortlist = 0, $draft = 0, $notcurrentuser = 0, $socid = 0, $limit = 0, $offset = 0, $sortfield = 'p.datep', $sortorder = 'DESC') - { - // phpcs:enable + * @return int -1 if KO, array with result if OK + */ + public function liste_array($shortlist = 0, $draft = 0, $notcurrentuser = 0, $socid = 0, $limit = 0, $offset = 0, $sortfield = 'p.datep', $sortorder = 'DESC') + { + // phpcs:enable @@ -2942,3 +2829 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { - $sql .= ", sc.fk_soc, sc.fk_user"; - } + if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user"; @@ -2946,3 +2831 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - } + if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; @@ -2952,12 +2835,7 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$socid) { //restriction - $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); - } - if ($socid) { - $sql .= " AND s.rowid = ".((int) $socid); - } - if ($draft) { - $sql .= " AND p.fk_statut = ".self::STATUS_DRAFT; - } - if ($notcurrentuser > 0) { - $sql .= " AND p.fk_user_author <> ".((int) $user->id); - } + if (!$user->rights->societe->client->voir && !$socid) //restriction + { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + } + if ($socid) $sql .= " AND s.rowid = ".$socid; + if ($draft) $sql .= " AND p.fk_statut = ".self::STATUS_DRAFT; + if ($notcurrentuser > 0) $sql .= " AND p.fk_user_author <> ".$user->id; @@ -2968 +2846,2 @@ - if ($result) { + if ($result) + { @@ -2970 +2849,2 @@ - if ($num) { + if ($num) + { @@ -2972 +2852,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -2975 +2856,2 @@ - if ($shortlist == 1) { + if ($shortlist == 1) + { @@ -2977 +2859,3 @@ - } elseif ($shortlist == 2) { + } + elseif ($shortlist == 2) + { @@ -2979 +2863,3 @@ - } else { + } + else + { @@ -2989 +2875,3 @@ - } else { + } + else + { @@ -3000 +2888 @@ - public function getInvoiceArrayList() + public function getInvoiceArrayList() @@ -3005 +2893 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -3009,6 +2897,6 @@ - * @param int $id Id propal - * @return array|int Array of invoices id - */ - public function InvoiceArrayList($id) - { - // phpcs:enable + * @param int $id Id propal + * @return array Array of invoices id + */ + public function InvoiceArrayList($id) + { + // phpcs:enable @@ -3019 +2907,2 @@ - foreach ($this->linkedObjectsIds as $objecttype => $objectid) { + foreach ($this->linkedObjectsIds as $objecttype => $objectid) + { @@ -3022 +2911,2 @@ - foreach ($objectid as $key => $object) { + foreach ($objectid as $key => $object) + { @@ -3024 +2914,2 @@ - if ($objecttype == 'facture') { + if ($objecttype == 'facture') + { @@ -3026,2 +2917,4 @@ - } else { - // Cas des factures liees par un autre objet (ex: commande) + } + // Cas des factures liees par un autre objet (ex: commande) + else + { @@ -3029,3 +2922,6 @@ - foreach ($this->linkedObjectsIds as $subobjecttype => $subobjectid) { - foreach ($subobjectid as $subkey => $subobject) { - if ($subobjecttype == 'facture') { + foreach ($this->linkedObjectsIds as $subobjecttype => $subobjectid) + { + foreach ($subobjectid as $subkey => $subobject) + { + if ($subobjecttype == 'facture') + { @@ -3040,2 +2936,3 @@ - if (count($linkedInvoices) > 0) { - $sql = "SELECT rowid as facid, ref, total_ht as total, datef as df, fk_user_author, fk_statut, paye"; + if (count($linkedInvoices) > 0) + { + $sql = "SELECT rowid as facid, ref, total, datef as df, fk_user_author, fk_statut, paye"; @@ -3043 +2940 @@ - $sql .= " WHERE rowid IN (".$this->db->sanitize(implode(',', $linkedInvoices)).")"; + $sql .= " WHERE rowid IN (".implode(',', $linkedInvoices).")"; @@ -3048 +2945,2 @@ - if ($resql) { + if ($resql) + { @@ -3051 +2949,2 @@ - for ($i = 0; $i < $nump; $i++) { + for ($i = 0; $i < $nump; $i++) + { @@ -3059 +2958,2 @@ - if ($nump) { + if ($nump) + { @@ -3061 +2961,2 @@ - while ($i < $nump) { + while ($i < $nump) + { @@ -3070 +2971,3 @@ - } else { + } + else + { @@ -3073,3 +2976,2 @@ - } else { - return $ga; - } + } + else return $ga; @@ -3083,3 +2985,3 @@ - * @return int >0 if OK, <=0 if KO - */ - public function delete($user, $notrigger = 0) + * @return int 1 if ok, otherwise if error + */ + public function delete($user, $notrigger = 0) @@ -3094 +2996,2 @@ - if (!$notrigger) { + if (!$notrigger) + { @@ -3097,3 +3000 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } @@ -3103,71 +3004,74 @@ - // Delete extrafields of lines and lines - if (!$error && !empty($this->table_element_line)) { - $tabletodelete = $this->table_element_line; - $sqlef = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete."_extrafields WHERE fk_object IN (SELECT rowid FROM ".MAIN_DB_PREFIX.$tabletodelete." WHERE ".$this->fk_element." = ".((int) $this->id).")"; - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete." WHERE ".$this->fk_element." = ".((int) $this->id); - if (!$this->db->query($sqlef) || !$this->db->query($sql)) { - $error++; - $this->error = $this->db->lasterror(); - $this->errors[] = $this->error; - dol_syslog(get_class($this)."::delete error ".$this->error, LOG_ERR); - } - } - - if (!$error) { - // Delete linked object - $res = $this->deleteObjectLinked(); - if ($res < 0) { - $error++; - } - } - - if (!$error) { - // Delete linked contacts - $res = $this->delete_linked_contact(); - if ($res < 0) { - $error++; - } - } - - // Removed extrafields of object - if (!$error) { - $result = $this->deleteExtraFields(); - if ($result < 0) { - $error++; - dol_syslog(get_class($this)."::delete error ".$this->error, LOG_ERR); - } - } - - // Delete main record - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element." WHERE rowid = ".((int) $this->id); - $res = $this->db->query($sql); - if (!$res) { - $error++; - $this->error = $this->db->lasterror(); - $this->errors[] = $this->error; - dol_syslog(get_class($this)."::delete error ".$this->error, LOG_ERR); - } - } - - // Delete record into ECM index and physically - if (!$error) { - $res = $this->deleteEcmFiles(0); // Deleting files physically is done later with the dol_delete_dir_recursive - $res = $this->deleteEcmFiles(1); // Deleting files physically is done later with the dol_delete_dir_recursive - if (!$res) { - $error++; - } - } - - if (!$error) { - // We remove directory - $ref = dol_sanitizeFileName($this->ref); - if ($conf->propal->multidir_output[$this->entity] && !empty($this->ref)) { - $dir = $conf->propal->multidir_output[$this->entity]."/".$ref; - $file = $dir."/".$ref.".pdf"; - if (file_exists($file)) { - dol_delete_preview($this); - - if (!dol_delete_file($file, 0, 0, 0, $this)) { - $this->error = 'ErrorFailToDeleteFile'; - $this->errors[] = $this->error; + if (!$error) + { + $main = MAIN_DB_PREFIX.'propaldet'; + $ef = $main."_extrafields"; + $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_propal = ".$this->id.")"; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = ".$this->id; + if ($this->db->query($sqlef) && $this->db->query($sql)) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = ".$this->id; + if ($this->db->query($sql)) + { + // Delete linked object + $res = $this->deleteObjectLinked(); + if ($res < 0) $error++; + + // Delete linked contacts + $res = $this->delete_linked_contact(); + if ($res < 0) $error++; + + if (!$error) + { + // We remove directory + $ref = dol_sanitizeFileName($this->ref); + if ($conf->propal->multidir_output[$this->entity] && !empty($this->ref)) + { + $dir = $conf->propal->multidir_output[$this->entity]."/".$ref; + $file = $dir."/".$ref.".pdf"; + if (file_exists($file)) + { + dol_delete_preview($this); + + if (!dol_delete_file($file, 0, 0, 0, $this)) // For triggers + { + $this->error = 'ErrorFailToDeleteFile'; + $this->errors = array('ErrorFailToDeleteFile'); + $this->db->rollback(); + return 0; + } + } + if (file_exists($dir)) + { + $res = @dol_delete_dir_recursive($dir); + if (!$res) + { + $this->error = 'ErrorFailToDeleteDir'; + $this->errors = array('ErrorFailToDeleteDir'); + $this->db->rollback(); + return 0; + } + } + } + } + + // Removed extrafields + if (!$error) + { + $result = $this->deleteExtraFields(); + if ($result < 0) + { + $error++; + $errorflag = -4; + dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR); + } + } + + if (!$error) + { + dol_syslog(get_class($this)."::delete ".$this->id." by ".$user->id, LOG_DEBUG); + $this->db->commit(); + return 1; + } + else + { + $this->error = $this->db->lasterror(); @@ -3178,8 +3082,5 @@ - if (file_exists($dir)) { - $res = @dol_delete_dir_recursive($dir); // delete files physically + into ecm tables - if (!$res) { - $this->error = 'ErrorFailToDeleteDir'; - $this->errors[] = $this->error; - $this->db->rollback(); - return 0; - } + else + { + $this->error = $this->db->lasterror(); + $this->db->rollback(); + return -3; @@ -3188,7 +3089,9 @@ - } - - if (!$error) { - dol_syslog(get_class($this)."::delete ".$this->id." by ".$user->id, LOG_DEBUG); - $this->db->commit(); - return 1; - } else { + else + { + $this->error = $this->db->lasterror(); + $this->db->rollback(); + return -2; + } + } + else + { @@ -3208 +3111 @@ - public function availability($availability_id, $notrigger = 0) + public function availability($availability_id, $notrigger = 0) @@ -3212 +3115,2 @@ - if ($this->statut >= self::STATUS_DRAFT) { + if ($this->statut >= self::STATUS_DRAFT) + { @@ -3218,2 +3122,2 @@ - $sql .= ' SET fk_availability = '.((int) $availability_id); - $sql .= ' WHERE rowid='.((int) $this->id); + $sql .= ' SET fk_availability = '.$availability_id; + $sql .= ' WHERE rowid='.$this->id; @@ -3223 +3127,2 @@ - if (!$resql) { + if (!$resql) + { @@ -3228 +3133,2 @@ - if (!$error) { + if (!$error) + { @@ -3233 +3139,2 @@ - if (!$notrigger && empty($error)) { + if (!$notrigger && empty($error)) + { @@ -3236,3 +3143 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -3242 +3147,2 @@ - if (!$error) { + if (!$error) + { @@ -3245,2 +3151,5 @@ - } else { - foreach ($this->errors as $errmsg) { + } + else + { + foreach ($this->errors as $errmsg) + { @@ -3253 +3162,3 @@ - } else { + } + else + { @@ -3262 +3173 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -3271,3 +3182,3 @@ - public function demand_reason($demand_reason_id, $notrigger = 0) - { - // phpcs:enable + public function demand_reason($demand_reason_id, $notrigger = 0) + { + // phpcs:enable @@ -3276 +3187,2 @@ - if ($this->status >= self::STATUS_DRAFT) { + if ($this->statut >= self::STATUS_DRAFT) + { @@ -3282,2 +3194,2 @@ - $sql .= ' SET fk_input_reason = '.((int) $demand_reason_id); - $sql .= ' WHERE rowid='.((int) $this->id); + $sql .= ' SET fk_input_reason = '.$demand_reason_id; + $sql .= ' WHERE rowid='.$this->id; @@ -3287 +3199,2 @@ - if (!$resql) { + if (!$resql) + { @@ -3292 +3205,2 @@ - if (!$error) { + if (!$error) + { @@ -3297 +3211,2 @@ - if (!$notrigger && empty($error)) { + if (!$notrigger && empty($error)) + { @@ -3300,3 +3215 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -3306 +3219,2 @@ - if (!$error) { + if (!$error) + { @@ -3309,2 +3223,5 @@ - } else { - foreach ($this->errors as $errmsg) { + } + else + { + foreach ($this->errors as $errmsg) + { @@ -3317 +3234,3 @@ - } else { + } + else + { @@ -3333 +3252 @@ - public function info($id) + public function info($id) @@ -3336,2 +3255,2 @@ - $sql .= " c.datec, c.date_valid as datev, c.date_signature, c.date_cloture,"; - $sql .= " c.fk_user_author, c.fk_user_valid, c.fk_user_signature, c.fk_user_cloture"; + $sql .= " c.datec, c.date_valid as datev, c.date_cloture as dateo,"; + $sql .= " c.fk_user_author, c.fk_user_valid, c.fk_user_cloture"; @@ -3339 +3258 @@ - $sql .= " WHERE c.rowid = ".((int) $id); + $sql .= " WHERE c.rowid = ".$id; @@ -3343,2 +3262,4 @@ - if ($result) { - if ($this->db->num_rows($result)) { + if ($result) + { + if ($this->db->num_rows($result)) + { @@ -3351,10 +3272,11 @@ - $this->date_signature = $this->db->jdate($obj->date_signature); - $this->date_cloture = $this->db->jdate($obj->date_cloture); - - $this->user_creation_id = $obj->fk_user_author; - $this->user_validation_id = $obj->fk_user_valid; - - if ($obj->fk_user_signature) { - $user_signature = new User($this->db); - $user_signature->fetch($obj->fk_user_signature); - $this->user_signature = $user_signature; + $this->date_cloture = $this->db->jdate($obj->dateo); + + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_author); + $this->user_creation = $cuser; + + if ($obj->fk_user_valid) + { + $vuser = new User($this->db); + $vuser->fetch($obj->fk_user_valid); + $this->user_validation = $vuser; @@ -3363 +3285,6 @@ - $this->user_closing_id = $obj->fk_user_cloture; + if ($obj->fk_user_cloture) + { + $cluser = new User($this->db); + $cluser->fetch($obj->fk_user_cloture); + $this->user_cloture = $cluser; + } @@ -3366 +3293,3 @@ - } else { + } + else + { @@ -3378 +3307 @@ - public function getLibStatut($mode = 0) + public function getLibStatut($mode = 0) @@ -3383 +3312 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -3391,4 +3320,4 @@ - public function LibStatut($status, $mode = 1) - { - // phpcs:enable - global $conf, $hookmanager; + public function LibStatut($status, $mode = 1) + { + // phpcs:enable + global $conf; @@ -3397 +3326,2 @@ - if (empty($this->labelStatus) || empty($this->labelStatusShort)) { + if (empty($this->labelStatus) || empty($this->labelStatusShort)) + { @@ -3400,10 +3330,10 @@ - $this->labelStatus[0] = $langs->transnoentitiesnoconv("PropalStatusDraft"); - $this->labelStatus[1] = $langs->transnoentitiesnoconv("PropalStatusValidated"); - $this->labelStatus[2] = $langs->transnoentitiesnoconv("PropalStatusSigned"); - $this->labelStatus[3] = $langs->transnoentitiesnoconv("PropalStatusNotSigned"); - $this->labelStatus[4] = $langs->transnoentitiesnoconv("PropalStatusBilled"); - $this->labelStatusShort[0] = $langs->transnoentitiesnoconv("PropalStatusDraftShort"); - $this->labelStatusShort[1] = $langs->transnoentitiesnoconv("PropalStatusValidatedShort"); - $this->labelStatusShort[2] = $langs->transnoentitiesnoconv("PropalStatusSignedShort"); - $this->labelStatusShort[3] = $langs->transnoentitiesnoconv("PropalStatusNotSignedShort"); - $this->labelStatusShort[4] = $langs->transnoentitiesnoconv("PropalStatusBilledShort"); + $this->labelStatus[0] = $langs->trans("PropalStatusDraft"); + $this->labelStatus[1] = $langs->trans("PropalStatusValidated"); + $this->labelStatus[2] = $langs->trans("PropalStatusSigned"); + $this->labelStatus[3] = $langs->trans("PropalStatusNotSigned"); + $this->labelStatus[4] = $langs->trans("PropalStatusBilled"); + $this->labelStatusShort[0] = $langs->trans("PropalStatusDraftShort"); + $this->labelStatusShort[1] = $langs->trans("PropalStatusValidatedShort"); + $this->labelStatusShort[2] = $langs->trans("PropalStatusSignedShort"); + $this->labelStatusShort[3] = $langs->trans("PropalStatusNotSignedShort"); + $this->labelStatusShort[4] = $langs->trans("PropalStatusBilledShort"); @@ -3413,19 +3343,5 @@ - if ($status == self::STATUS_DRAFT) { - $statusType = 'status0'; - } elseif ($status == self::STATUS_VALIDATED) { - $statusType = 'status1'; - } elseif ($status == self::STATUS_SIGNED) { - $statusType = 'status4'; - } elseif ($status == self::STATUS_NOTSIGNED) { - $statusType = 'status9'; - } elseif ($status == self::STATUS_BILLED) { - $statusType = 'status6'; - } - - - $parameters = array('status' => $status, 'mode' => $mode); - $reshook = $hookmanager->executeHooks('LibStatut', $parameters, $this); // Note that $action and $object may have been modified by hook - - if ($reshook > 0) { - return $hookmanager->resPrint; - } + if ($status == self::STATUS_DRAFT) $statusType = 'status0'; + elseif ($status == self::STATUS_VALIDATED) $statusType = 'status1'; + elseif ($status == self::STATUS_SIGNED) $statusType = 'status4'; + elseif ($status == self::STATUS_NOTSIGNED) $statusType = 'status9'; + elseif ($status == self::STATUS_BILLED) $statusType = 'status6'; @@ -3437 +3353 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -3442,6 +3358,6 @@ - * @param string $mode "opened" for proposal to close, "signed" for proposal to invoice - * @return WorkboardResponse|int Return integer <0 if KO, WorkboardResponse if OK - */ - public function load_board($user, $mode) - { - // phpcs:enable + * @param int $mode "opened" for proposal to close, "signed" for proposal to invoice + * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK + */ + public function load_board($user, $mode) + { + // phpcs:enable @@ -3454 +3370,2 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { + if (!$user->rights->societe->client->voir && !$user->socid) + { @@ -3456 +3373 @@ - $sql .= " WHERE sc.fk_user = ".((int) $user->id); + $sql .= " WHERE sc.fk_user = ".$user->id; @@ -3460,9 +3377,3 @@ - if ($mode == 'opened') { - $sql .= " AND p.fk_statut = ".self::STATUS_VALIDATED; - } - if ($mode == 'signed') { - $sql .= " AND p.fk_statut = ".self::STATUS_SIGNED; - } - if ($user->socid) { - $sql .= " AND p.fk_soc = ".((int) $user->socid); - } + if ($mode == 'opened') $sql .= " AND p.fk_statut = ".self::STATUS_VALIDATED; + if ($mode == 'signed') $sql .= " AND p.fk_statut = ".self::STATUS_SIGNED; + if ($user->socid) $sql .= " AND p.fk_soc = ".$user->socid; @@ -3471 +3382,2 @@ - if ($resql) { + if ($resql) + { @@ -3481,2 +3393,2 @@ - $label = $langs->transnoentitiesnoconv("PropalsToClose"); - $labelShort = $langs->transnoentitiesnoconv("ToAcceptRefuse"); + $label = $langs->trans("PropalsToClose"); + $labelShort = $langs->trans("ToAcceptRefuse"); @@ -3500 +3412,2 @@ - while ($obj = $this->db->fetch_object($resql)) { + while ($obj = $this->db->fetch_object($resql)) + { @@ -3504 +3417,2 @@ - if ($mode == 'opened') { + if ($mode == 'opened') + { @@ -3506 +3420,2 @@ - if ($datelimit < ($now - $delay_warning)) { + if ($datelimit < ($now - $delay_warning)) + { @@ -3515 +3430,3 @@ - } else { + } + else + { @@ -3529 +3446 @@ - public function initAsSpecimen() + public function initAsSpecimen() @@ -3539,2 +3455,0 @@ - $sql .= $this->db->plimit(100); - @@ -3542 +3457,2 @@ - if ($resql) { + if ($resql) + { @@ -3545 +3461,2 @@ - while ($i < $num_prods) { + while ($i < $num_prods) + { @@ -3577 +3494,2 @@ - while ($xnbp < $nbp) { + while ($xnbp < $nbp) + { @@ -3586 +3504,2 @@ - if ($xnbp == 2) { + if ($xnbp == 2) + { @@ -3591 +3510,3 @@ - } else { + } + else + { @@ -3598 +3519,2 @@ - if ($num_prods > 0) { + if ($num_prods > 0) + { @@ -3601 +3523 @@ - $line->product_ref = 'SPECIMEN'; + $line->product_ref = 'SPECIMEN'; @@ -3614 +3536 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -3618,5 +3540,5 @@ - * @return int Return integer <0 if ko, >0 if ok - */ - public function load_state_board() - { - // phpcs:enable + * @return int <0 if ko, >0 if ok + */ + public function load_state_board() + { + // phpcs:enable @@ -3631 +3553,2 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { + if (!$user->rights->societe->client->voir && !$user->socid) + { @@ -3633 +3556 @@ - $sql .= " WHERE sc.fk_user = ".((int) $user->id); + $sql .= " WHERE sc.fk_user = ".$user->id; @@ -3639 +3562,2 @@ - if ($resql) { + if ($resql) + { @@ -3641 +3565,2 @@ - while ($obj = $this->db->fetch_object($resql)) { + while ($obj = $this->db->fetch_object($resql)) + { @@ -3646 +3571,3 @@ - } else { + } + else + { @@ -3661 +3588 @@ - public function getNextNumRef($soc) + public function getNextNumRef($soc) @@ -3668 +3595,2 @@ - if (!empty($classname)) { + if (!empty($classname)) + { @@ -3682 +3610,2 @@ - if (!$mybool) { + if (!$mybool) + { @@ -3691 +3620,2 @@ - if ($numref != "") { + if ($numref != "") + { @@ -3693 +3623,3 @@ - } else { + } + else + { @@ -3698 +3630,3 @@ - } else { + } + else + { @@ -3703,64 +3636,0 @@ - } - - /** - * getTooltipContentArray - * @param array $params params to construct tooltip data - * @since v18 - * @return array - */ - public function getTooltipContentArray($params) - { - global $conf, $langs, $user; - - $langs->load('propal'); - $datas = []; - $nofetch = !empty($params['nofetch']); - - if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { - return ['optimize' => $langs->trans("Proposal")]; - } - if ($user->hasRight('propal', 'lire')) { - $datas['picto'] = img_picto('', $this->picto).' '.$langs->trans("Proposal").''; - if (isset($this->statut)) { - $datas['status'] = ' '.$this->getLibStatut(5); - } - if (!empty($this->ref)) { - $datas['ref'] = '
'.$langs->trans('Ref').': '.$this->ref; - } - if (!$nofetch) { - $langs->load('companies'); - if (empty($this->thirdparty)) { - $this->fetch_thirdparty(); - } - $datas['customer'] = '
'.$langs->trans('Customer').': '.$this->thirdparty->getNomUrl(1, '', 0, 1); - } - if (!empty($this->ref_client)) { - $datas['refcustomer'] = '
'.$langs->trans('RefCustomer').': '.$this->ref_client; - } - if (!$nofetch) { - $langs->load('project'); - if (empty($this->project)) { - $res = $this->fetch_project(); - if ($res > 0) { - $datas['project'] = '
'.$langs->trans('Project').': '.$this->project->getNomUrl(1, '', 0, 1); - } - } - } - if (!empty($this->total_ht)) { - $datas['amountht'] = '
'.$langs->trans('AmountHT').': '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency); - } - if (!empty($this->total_tva)) { - $datas['vat'] = '
'.$langs->trans('VAT').': '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency); - } - if (!empty($this->total_ttc)) { - $datas['amountttc'] = '
'.$langs->trans('AmountTTC').': '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); - } - if (!empty($this->date)) { - $datas['date'] = '
'.$langs->trans('Date').': '.dol_print_date($this->date, 'day'); - } - if (!empty($this->delivery_date)) { - $datas['deliverydate'] = '
'.$langs->trans('DeliveryDate').': '.dol_print_date($this->delivery_date, 'dayhour'); - } - } - - return $datas; @@ -3777 +3647 @@ - * @param int $addlinktonotes -1=Disable, 0=Just add label show notes, 1=Add private note (only internal user), 2=Add public note (internal or external user), 3=Add private (internal user) and public note (internal and external user) + * @param int $addlinktonotes -1=Disable, 0=Just add label show notes, 1=Add private note (only internal user), 2=Add public note (internal or external user), 3=Add private (internal user) and public note (internal and external user) @@ -3780,7 +3650,5 @@ - public function getNomUrl($withpicto = 0, $option = '', $get_params = '', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = -1) - { - global $langs, $conf, $user, $hookmanager; - - if (!empty($conf->dol_no_mouse_hover)) { - $notooltip = 1; // Force disable tooltips - } + public function getNomUrl($withpicto = 0, $option = '', $get_params = '', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = -1) + { + global $langs, $conf, $user; + + if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips @@ -3789,16 +3657 @@ - $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 = ''; @@ -3806 +3659,19 @@ - if ($user->hasRight('propal', 'lire')) { + + if ($user->rights->propal->lire) + { + $label = ''.$langs->trans("Proposal").''; + if (!empty($this->ref)) + $label .= '
'.$langs->trans('Ref').': '.$this->ref; + if (!empty($this->ref_client)) + $label .= '
'.$langs->trans('RefCustomer').': '.$this->ref_client; + if (!empty($this->total_ht)) + $label .= '
'.$langs->trans('AmountHT').': '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency); + if (!empty($this->total_tva)) + $label .= '
'.$langs->trans('VAT').': '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency); + if (!empty($this->total_ttc)) + $label .= '
'.$langs->trans('AmountTTC').': '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); + if (isset($this->statut)) { + $label .= '
'.$langs->trans("Status").": ".$this->getLibStatut(5); + } + + @@ -3809 +3680,2 @@ - } elseif ($option == 'compta') { // deprecated + } + elseif ($option == 'compta') { // deprecated @@ -3811 +3683,2 @@ - } elseif ($option == 'expedition') { + } + elseif ($option == 'expedition') { @@ -3813 +3686,2 @@ - } elseif ($option == 'document') { + } + elseif ($option == 'document') { @@ -3817 +3691,2 @@ - if ($option != 'nolink') { + if ($option != 'nolink') + { @@ -3820,6 +3695,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'; @@ -3830,2 +3701,4 @@ - if (empty($notooltip) && $user->hasRight('propal', 'lire')) { - if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { + if (empty($notooltip) && $user->rights->propal->lire) + { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { @@ -3835,2 +3708,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"'; @@ -3844,6 +3717,2 @@ - if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="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; @@ -3852,51 +3721,40 @@ - if ($addlinktonotes >= 0) { - $txttoshow = ''; - - if ($addlinktonotes == 0) { - if (!empty($this->note_private) || !empty($this->note_public)) { - $txttoshow = $langs->trans('ViewPrivateNote'); - } - } elseif ($addlinktonotes == 1) { - if (!empty($this->note_private)) { - $txttoshow .= ($user->socid > 0 ? '' : dol_string_nohtmltag($this->note_private, 1)); - } - } elseif ($addlinktonotes == 2) { - if (!empty($this->note_public)) { - $txttoshow .= dol_string_nohtmltag($this->note_public, 1); - } - } elseif ($addlinktonotes == 3) { - if ($user->socid > 0) { - if (!empty($this->note_public)) { - $txttoshow .= dol_string_nohtmltag($this->note_public, 1); - } - } else { - if (!empty($this->note_public)) { - $txttoshow .= dol_string_nohtmltag($this->note_public, 1); - } - if (!empty($this->note_private)) { - if (!empty($txttoshow)) { - $txttoshow .= '

'; - } - $txttoshow .= dol_string_nohtmltag($this->note_private, 1); - } - } - } - - if ($txttoshow) { - $result .= ' '; - $result .= ''; - $result .= img_picto('', 'note'); - $result .= ''; - $result .= ''; - } - } - - 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; - } + if ($addlinktonotes >= 0) { + $txttoshow = ''; + + if ($addlinktonotes == 0) { + if (!empty($this->note_private) || !empty($this->note_public)) { + $txttoshow = $langs->trans('ViewPrivateNote'); + } + } elseif ($addlinktonotes == 1) { + if (!empty($this->note_private)) { + $txttoshow .= ($user->socid > 0 ? '' : dol_string_nohtmltag($this->note_private, 1)); + } + } elseif ($addlinktonotes == 2) { + if (!empty($this->note_public)) { + $txttoshow .= dol_string_nohtmltag($this->note_public, 1); + } + } elseif ($addlinktonotes == 3) { + if ($user->socid > 0) { + if (!empty($this->note_public)) { + $txttoshow .= dol_string_nohtmltag($this->note_public, 1); + } + } else { + if (!empty($this->note_public)) { + $txttoshow .= dol_string_nohtmltag($this->note_public, 1); + } + if (!empty($this->note_private)) { + if (!empty($txttoshow)) $txttoshow .= '

'; + $txttoshow .= dol_string_nohtmltag($this->note_private, 1); + } + } + } + + if ($txttoshow) { + $result .= ' '; + $result .= ''; + $result .= img_picto('', 'note'); + $result .= ''; + $result .= ''; + } + } + @@ -3909,6 +3767,5 @@ - * @param string $sqlforgedfilters Filter on other fields - * @return int >0 if OK, <0 if KO - */ - public function getLinesArray($sqlforgedfilters = '') - { - return $this->fetch_lines(0, 0, $sqlforgedfilters); + * @return int >0 if OK, <0 if KO + */ + public function getLinesArray() + { + return $this->fetch_lines(); @@ -3925 +3782 @@ - * @param null|array $moreparams Array to provide more information + * @param null|array $moreparams Array to provide more information @@ -3933 +3789,0 @@ - $outputlangs->load("products"); @@ -3938,3 +3794,3 @@ - if ($this->model_pdf) { - $modele = $this->model_pdf; - } elseif (getDolGlobalString('PROPALE_ADDON_PDF')) { + if ($this->modelpdf) { + $modele = $this->modelpdf; + } elseif (!empty($conf->global->PROPALE_ADDON_PDF)) { @@ -3953,6 +3809,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) @@ -3964,59 +3820 @@ - return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables); - } - - /** - * Function used to replace a product id with another one. - * - * @param DoliDB $db Database handler - * @param int $origin_id Old product id - * @param int $dest_id New product id - * @return bool - */ - public static function replaceProduct(DoliDB $db, $origin_id, $dest_id) - { - $tables = array( - 'propaldet' - ); - - return CommonObject::commonReplaceProduct($db, $origin_id, $dest_id, $tables); - } - - /** - * 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; - - $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']); - - $return = '
'; - $return .= '
'; - $return .= ''; - $return .= img_picto('', $this->picto); - $return .= ''; - $return .= '
'; - $return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).''; - if ($selected >= 0) { - $return .= ''; - } - if (!empty($arraydata['projectlink'])) { - $return .= ' | '.$arraydata['projectlink'].''; - } - if (!empty($arraydata['authorlink'])) { - $return .= '
'.$arraydata['authorlink'].''; - } - if (property_exists($this, 'total_ht')) { - $return .='
'.price($this->total_ht).''; - } - if (method_exists($this, 'getLibStatut')) { - $return .= '
'.$this->getLibStatut(3).'
'; - } - $return .= '
'; - $return .= '
'; - $return .= '
'; - return $return; + return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); @@ -4024,0 +3823 @@ + @@ -4041 +3840 @@ - public $oldline; + public $oldline; @@ -4044,4 +3843,4 @@ - public $fk_propal; - public $fk_parent_line; - public $desc; // Description ligne - public $fk_product; // Id produit predefini + public $fk_propal; + public $fk_parent_line; + public $desc; // Description ligne + public $fk_product; // Id produit predefini @@ -4052 +3851 @@ - public $fk_product_type; + public $fk_product_type; @@ -4058,19 +3857,16 @@ - public $product_type = Product::TYPE_PRODUCT; - - public $qty; - - public $tva_tx; - public $vat_src_code; - - public $subprice; - public $remise_percent; - public $fk_remise_except; - - public $rang = 0; - - public $fk_fournprice; - public $pa_ht; - public $marge_tx; - public $marque_tx; - - public $special_code; // Tag for special lines (exlusive tags) + public $product_type = Product::TYPE_PRODUCT; + + public $qty; + public $tva_tx; + public $subprice; + public $remise_percent; + public $fk_remise_except; + + public $rang = 0; + + public $fk_fournprice; + public $pa_ht; + public $marge_tx; + public $marque_tx; + + public $special_code; // Tag for special lines (exlusive tags) @@ -4081 +3877 @@ - public $info_bits = 0; // Some other info: + public $info_bits = 0; // Some other info: @@ -4085,3 +3881,3 @@ - public $total_ht; // Total HT de la ligne toute quantite et incluant la remise ligne - public $total_tva; // Total TVA de la ligne toute quantite et incluant la remise ligne - public $total_ttc; // Total TTC de la ligne toute quantite et incluant la remise ligne + public $total_ht; // Total HT de la ligne toute quantite et incluant la remise ligne + public $total_tva; // Total TVA de la ligne toute quantite et incluant la remise ligne + public $total_ttc; // Total TTC de la ligne toute quantite et incluant la remise ligne @@ -4093 +3889 @@ - public $remise; + public $remise; @@ -4098 +3894 @@ - public $price; + public $price; @@ -4105 +3901 @@ - public $ref; + public $ref; @@ -4115,6 +3911 @@ - public $libelle; - /** - * @deprecated - * @see $product_label - */ - public $label; + public $libelle; @@ -4132,23 +3923,11 @@ - /** - * Product use lot - * @var string - */ - public $product_tobatch; - - /** - * Product barcode - * @var string - */ - public $product_barcode; - - public $localtax1_tx; // Local tax 1 - public $localtax2_tx; // Local tax 2 - public $localtax1_type; // Local tax 1 type - public $localtax2_type; // Local tax 2 type - public $total_localtax1; // Line total local tax 1 - public $total_localtax2; // Line total local tax 2 - - public $date_start; - public $date_end; - - public $skip_update_total; // Skip update price total for special lines + public $localtax1_tx; // Local tax 1 + public $localtax2_tx; // Local tax 2 + public $localtax1_type; // Local tax 1 type + public $localtax2_type; // Local tax 2 type + public $total_localtax1; // Line total local tax 1 + public $total_localtax2; // Line total local tax 2 + + public $date_start; + public $date_end; + + public $skip_update_total; // Skip update price total for special lines @@ -4157,7 +3936,6 @@ - public $fk_multicurrency; - public $multicurrency_code; - public $multicurrency_subprice; - public $multicurrency_total_ht; - public $multicurrency_total_tva; - public $multicurrency_total_ttc; - + public $fk_multicurrency; + public $multicurrency_code; + public $multicurrency_subprice; + public $multicurrency_total_ht; + public $multicurrency_total_tva; + public $multicurrency_total_ttc; @@ -4170 +3948 @@ - public function __construct($db) + public function __construct($db) @@ -4179,3 +3957,3 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function fetch($rowid) + * @return int <0 if KO, >0 if OK + */ + public function fetch($rowid) @@ -4193 +3971 @@ - $sql .= ' WHERE pd.rowid = '.((int) $rowid); + $sql .= ' WHERE pd.rowid = '.$rowid; @@ -4196 +3974,2 @@ - if ($result) { + if ($result) + { @@ -4199 +3978,2 @@ - if ($objp) { + if ($objp) + { @@ -4255 +4035,3 @@ - } else { + } + else + { @@ -4258 +4040,3 @@ - } else { + } + else + { @@ -4267,3 +4051,3 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function insert($notrigger = 0) + * @return int <0 if KO, >0 if OK + */ + public function insert($notrigger = 0) @@ -4280,61 +4064,26 @@ - if (empty($this->tva_tx)) { - $this->tva_tx = 0; - } - if (empty($this->localtax1_tx)) { - $this->localtax1_tx = 0; - } - if (empty($this->localtax2_tx)) { - $this->localtax2_tx = 0; - } - if (empty($this->localtax1_type)) { - $this->localtax1_type = 0; - } - if (empty($this->localtax2_type)) { - $this->localtax2_type = 0; - } - if (empty($this->total_localtax1)) { - $this->total_localtax1 = 0; - } - if (empty($this->total_localtax2)) { - $this->total_localtax2 = 0; - } - if (empty($this->rang)) { - $this->rang = 0; - } - if (empty($this->remise_percent) || !is_numeric($this->remise_percent)) { - $this->remise_percent = 0; - } - if (empty($this->info_bits)) { - $this->info_bits = 0; - } - if (empty($this->special_code)) { - $this->special_code = 0; - } - if (empty($this->fk_parent_line)) { - $this->fk_parent_line = 0; - } - if (empty($this->fk_fournprice)) { - $this->fk_fournprice = 0; - } - if (!is_numeric($this->qty)) { - $this->qty = 0; - } - if (empty($this->pa_ht)) { - $this->pa_ht = 0; - } - if (empty($this->multicurrency_subprice)) { - $this->multicurrency_subprice = 0; - } - if (empty($this->multicurrency_total_ht)) { - $this->multicurrency_total_ht = 0; - } - if (empty($this->multicurrency_total_tva)) { - $this->multicurrency_total_tva = 0; - } - if (empty($this->multicurrency_total_ttc)) { - $this->multicurrency_total_ttc = 0; - } - - // if buy price not defined, define buyprice as configured in margin admin - if ($this->pa_ht == 0 && $pa_ht_isemptystring) { - if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { + if (empty($this->tva_tx)) $this->tva_tx = 0; + if (empty($this->localtax1_tx)) $this->localtax1_tx = 0; + if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; + if (empty($this->localtax1_type)) $this->localtax1_type = 0; + if (empty($this->localtax2_type)) $this->localtax2_type = 0; + if (empty($this->total_localtax1)) $this->total_localtax1 = 0; + if (empty($this->total_localtax2)) $this->total_localtax2 = 0; + if (empty($this->rang)) $this->rang = 0; + if (empty($this->remise)) $this->remise = 0; + if (empty($this->remise_percent) || !is_numeric($this->remise_percent)) $this->remise_percent = 0; + if (empty($this->info_bits)) $this->info_bits = 0; + if (empty($this->special_code)) $this->special_code = 0; + if (empty($this->fk_parent_line)) $this->fk_parent_line = 0; + if (empty($this->fk_fournprice)) $this->fk_fournprice = 0; + if (!is_numeric($this->qty)) $this->qty = 0; + if (empty($this->pa_ht)) $this->pa_ht = 0; + if (empty($this->multicurrency_subprice)) $this->multicurrency_subprice = 0; + if (empty($this->multicurrency_total_ht)) $this->multicurrency_total_ht = 0; + if (empty($this->multicurrency_total_tva)) $this->multicurrency_total_tva = 0; + if (empty($this->multicurrency_total_ttc)) $this->multicurrency_total_ttc = 0; + + // if buy price not defined, define buyprice as configured in margin admin + if ($this->pa_ht == 0 && $pa_ht_isemptystring) + { + if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) + { @@ -4342 +4091,3 @@ - } else { + } + else + { @@ -4348,3 +4099 @@ - if ($this->product_type < 0) { - return -1; - } + if ($this->product_type < 0) return -1; @@ -4371 +4120 @@ - $sql .= " ".price2num($this->qty, 'MS').","; + $sql .= " ".price2num($this->qty).","; @@ -4378,8 +4127,8 @@ - $sql .= " ".(price2num($this->subprice) !== '' ? price2num($this->subprice, 'MU') : "null").","; - $sql .= " ".price2num($this->remise_percent, 3).","; - $sql .= " ".(isset($this->info_bits) ? ((int) $this->info_bits) : "null").","; - $sql .= " ".price2num($this->total_ht, 'MT').","; - $sql .= " ".price2num($this->total_tva, 'MT').","; - $sql .= " ".price2num($this->total_localtax1, 'MT').","; - $sql .= " ".price2num($this->total_localtax2, 'MT').","; - $sql .= " ".price2num($this->total_ttc, 'MT').","; + $sql .= " ".(price2num($this->subprice) !== '' ?price2num($this->subprice) : "null").","; + $sql .= " ".price2num($this->remise_percent).","; + $sql .= " ".(isset($this->info_bits) ? "'".$this->db->escape($this->info_bits)."'" : "null").","; + $sql .= " ".price2num($this->total_ht).","; + $sql .= " ".price2num($this->total_tva).","; + $sql .= " ".price2num($this->total_localtax1).","; + $sql .= " ".price2num($this->total_localtax2).","; + $sql .= " ".price2num($this->total_ttc).","; @@ -4388,3 +4137,3 @@ - $sql .= ' '.((int) $this->special_code).','; - $sql .= ' '.((int) $this->rang).','; - $sql .= ' '.(empty($this->fk_unit) ? 'NULL' : ((int) $this->fk_unit)).','; + $sql .= ' '.$this->special_code.','; + $sql .= ' '.$this->rang.','; + $sql .= ' '.(!$this->fk_unit ? 'NULL' : $this->fk_unit).','; @@ -4393 +4142 @@ - $sql .= ", ".($this->fk_multicurrency > 0 ? ((int) $this->fk_multicurrency) : 'null'); + $sql .= ", ".($this->fk_multicurrency > 0 ? $this->fk_multicurrency : 'null'); @@ -4395,4 +4144,4 @@ - $sql .= ", ".price2num($this->multicurrency_subprice, 'CU'); - $sql .= ", ".price2num($this->multicurrency_total_ht, 'CT'); - $sql .= ", ".price2num($this->multicurrency_total_tva, 'CT'); - $sql .= ", ".price2num($this->multicurrency_total_ttc, 'CT'); + $sql .= ", ".$this->multicurrency_subprice; + $sql .= ", ".$this->multicurrency_total_ht; + $sql .= ", ".$this->multicurrency_total_tva; + $sql .= ", ".$this->multicurrency_total_ttc; @@ -4403 +4152,2 @@ - if ($resql) { + if ($resql) + { @@ -4406 +4156,2 @@ - if (!$error) { + if (!$error) + { @@ -4409 +4160,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -4414 +4166,2 @@ - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { @@ -4417 +4170,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -4426 +4180,3 @@ - } else { + } + else + { @@ -4438,3 +4194,3 @@ - * @return int Return integer <0 if ko, >0 if ok - */ - public function delete(User $user, $notrigger = 0) + * @return int <0 if ko, >0 if ok + */ + public function delete(User $user, $notrigger = 0) @@ -4447,21 +4203,13 @@ - if (!$notrigger) { - // Call trigger - $result = $this->call_trigger('LINEPROPAL_DELETE', $user); - if ($result < 0) { - $error++; - } - } - // End call triggers - - if (!$error) { - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "propaldet WHERE rowid = " . ((int) $this->rowid); - dol_syslog("PropaleLigne::delete", LOG_DEBUG); - if ($this->db->query($sql)) { - // Remove extrafields - if (!$error) { - $this->id = $this->rowid; - $result = $this->deleteExtraFields(); - if ($result < 0) { - $error++; - dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR); - } + $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE rowid = ".$this->rowid; + dol_syslog("PropaleLigne::delete", LOG_DEBUG); + if ($this->db->query($sql)) + { + // Remove extrafields + if (!$error) + { + $this->id = $this->rowid; + $result = $this->deleteExtraFields(); + if ($result < 0) + { + $error++; + dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR); @@ -4469,7 +4217,21 @@ - } else { - $this->error = $this->db->error() . " sql=" . $sql; - $error++; - } - } - - if ($error) { + } + + if (!$error && !$notrigger) + { + // Call trigger + $result = $this->call_trigger('LINEPROPAL_DELETE', $user); + if ($result < 0) + { + $this->db->rollback(); + return -1; + } + } + // End call triggers + + $this->db->commit(); + + return 1; + } + else + { + $this->error = $this->db->error()." sql=".$sql; @@ -4478,3 +4239,0 @@ - } else { - $this->db->commit(); - return 1; @@ -4488,3 +4247,3 @@ - * @return int Return integer <0 if ko, >0 if ok - */ - public function update($notrigger = 0) + * @return int <0 if ko, >0 if ok + */ + public function update($notrigger = 0) @@ -4498,4 +4256,0 @@ - if (empty($this->id) && !empty($this->rowid)) { - $this->id = $this->rowid; - } - @@ -4503,51 +4258,18 @@ - if (empty($this->tva_tx)) { - $this->tva_tx = 0; - } - if (empty($this->localtax1_tx)) { - $this->localtax1_tx = 0; - } - if (empty($this->localtax2_tx)) { - $this->localtax2_tx = 0; - } - if (empty($this->total_localtax1)) { - $this->total_localtax1 = 0; - } - if (empty($this->total_localtax2)) { - $this->total_localtax2 = 0; - } - if (empty($this->localtax1_type)) { - $this->localtax1_type = 0; - } - if (empty($this->localtax2_type)) { - $this->localtax2_type = 0; - } - if (empty($this->marque_tx)) { - $this->marque_tx = 0; - } - if (empty($this->marge_tx)) { - $this->marge_tx = 0; - } - if (empty($this->price)) { - $this->price = 0; // TODO A virer - } - if (empty($this->remise_percent)) { - $this->remise_percent = 0; - } - if (empty($this->info_bits)) { - $this->info_bits = 0; - } - if (empty($this->special_code)) { - $this->special_code = 0; - } - if (empty($this->fk_parent_line)) { - $this->fk_parent_line = 0; - } - if (empty($this->fk_fournprice)) { - $this->fk_fournprice = 0; - } - if (empty($this->subprice)) { - $this->subprice = 0; - } - if (empty($this->pa_ht)) { - $this->pa_ht = 0; - } + if (empty($this->tva_tx)) $this->tva_tx = 0; + if (empty($this->localtax1_tx)) $this->localtax1_tx = 0; + if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; + if (empty($this->total_localtax1)) $this->total_localtax1 = 0; + if (empty($this->total_localtax2)) $this->total_localtax2 = 0; + if (empty($this->localtax1_type)) $this->localtax1_type = 0; + if (empty($this->localtax2_type)) $this->localtax2_type = 0; + if (empty($this->marque_tx)) $this->marque_tx = 0; + if (empty($this->marge_tx)) $this->marge_tx = 0; + if (empty($this->price)) $this->price = 0; // TODO A virer + if (empty($this->remise)) $this->remise = 0; // TODO A virer + if (empty($this->remise_percent)) $this->remise_percent = 0; + if (empty($this->info_bits)) $this->info_bits = 0; + if (empty($this->special_code)) $this->special_code = 0; + if (empty($this->fk_parent_line)) $this->fk_parent_line = 0; + if (empty($this->fk_fournprice)) $this->fk_fournprice = 0; + if (empty($this->subprice)) $this->subprice = 0; + if (empty($this->pa_ht)) $this->pa_ht = 0; @@ -4556,2 +4278,4 @@ - if ($this->pa_ht == 0 && $pa_ht_isemptystring) { - if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { + if ($this->pa_ht == 0 && $pa_ht_isemptystring) + { + if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) + { @@ -4559 +4283,3 @@ - } else { + } + else + { @@ -4578,4 +4304,4 @@ - $sql .= ", subprice=".price2num($this->subprice); - $sql .= ", remise_percent=".price2num($this->remise_percent); - $sql .= ", price=".(float) price2num($this->price); // TODO A virer - $sql .= ", remise=".(float) price2num($this->remise); // TODO A virer + $sql .= ", subprice=".price2num($this->subprice).""; + $sql .= ", remise_percent=".price2num($this->remise_percent).""; + $sql .= ", price=".price2num($this->price).""; // TODO A virer + $sql .= ", remise=".price2num($this->remise).""; // TODO A virer @@ -4583,6 +4309,7 @@ - if (empty($this->skip_update_total)) { - $sql .= ", total_ht=".price2num($this->total_ht); - $sql .= ", total_tva=".price2num($this->total_tva); - $sql .= ", total_ttc=".price2num($this->total_ttc); - $sql .= ", total_localtax1=".price2num($this->total_localtax1); - $sql .= ", total_localtax2=".price2num($this->total_localtax2); + if (empty($this->skip_update_total)) + { + $sql .= ", total_ht=".price2num($this->total_ht).""; + $sql .= ", total_tva=".price2num($this->total_tva).""; + $sql .= ", total_ttc=".price2num($this->total_ttc).""; + $sql .= ", total_localtax1=".price2num($this->total_localtax1).""; + $sql .= ", total_localtax2=".price2num($this->total_localtax2).""; @@ -4592,3 +4319 @@ - if (strlen($this->special_code)) { - $sql .= ", special_code=".$this->special_code; - } + if (strlen($this->special_code)) $sql .= ", special_code=".$this->special_code; @@ -4596,3 +4321 @@ - if (!empty($this->rang)) { - $sql .= ", rang=".((int) $this->rang); - } + if (!empty($this->rang)) $sql .= ", rang=".$this->rang; @@ -4604,6 +4327,6 @@ - $sql .= ", multicurrency_subprice=".price2num($this->multicurrency_subprice); - $sql .= ", multicurrency_total_ht=".price2num($this->multicurrency_total_ht); - $sql .= ", multicurrency_total_tva=".price2num($this->multicurrency_total_tva); - $sql .= ", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc); - - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= ", multicurrency_subprice=".price2num($this->multicurrency_subprice).""; + $sql .= ", multicurrency_total_ht=".price2num($this->multicurrency_total_ht).""; + $sql .= ", multicurrency_total_tva=".price2num($this->multicurrency_total_tva).""; + $sql .= ", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc).""; + + $sql .= " WHERE rowid = ".$this->rowid; @@ -4613,2 +4336,5 @@ - if ($resql) { - if (!$error) { + if ($resql) + { + if (!$error) + { + $this->id = $this->rowid; @@ -4616 +4342,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -4621 +4348,2 @@ - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { @@ -4623,2 +4351,3 @@ - $result = $this->call_trigger('LINEPROPAL_MODIFY', $user); - if ($result < 0) { + $result = $this->call_trigger('LINEPROPAL_UPDATE', $user); + if ($result < 0) + { @@ -4633 +4362,3 @@ - } else { + } + else + { @@ -4640 +4371 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -4645,5 +4376,5 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function update_total() - { - // phpcs:enable + * @return int <0 if KO, >0 if OK + */ + public function update_total() + { + // phpcs:enable @@ -4654,4 +4385,4 @@ - $sql .= " total_ht=".price2num($this->total_ht, 'MT'); - $sql .= ",total_tva=".price2num($this->total_tva, 'MT'); - $sql .= ",total_ttc=".price2num($this->total_ttc, 'MT'); - $sql .= " WHERE rowid = ".((int) $this->rowid); + $sql .= " total_ht=".price2num($this->total_ht, 'MT').""; + $sql .= ",total_tva=".price2num($this->total_tva, 'MT').""; + $sql .= ",total_ttc=".price2num($this->total_ttc, 'MT').""; + $sql .= " WHERE rowid = ".$this->rowid; @@ -4662 +4393,2 @@ - if ($resql) { + if ($resql) + { @@ -4665 +4397,3 @@ - } else { + } + else + { --- /tmp/dsg/dolibarr/htdocs/comm/propal/class/github_19.0.3_propalestats.class.php +++ /tmp/dsg/dolibarr/htdocs/comm/propal/class/client_propalestats.class.php @@ -39 +39 @@ - /** + /** @@ -44,7 +44,7 @@ - public $socid; - public $userid; - - public $from; - public $field; - public $where; - public $join; + public $socid; + public $userid; + + public $from; + public $field; + public $where; + public $join; @@ -58 +58 @@ - * @param int $userid Id user for filter (creation user) + * @param int $userid Id user for filter (creation user) @@ -60,5 +60,7 @@ - * @param int $typentid Id typent of thirdpary for filter - * @param int $categid Id category of thirdpary for filter - */ - public function __construct($db, $socid = 0, $userid = 0, $mode = 'customer', $typentid = 0, $categid = 0) - { + * @param int $typentid Id typent of thirdpary for filter + * @param int $categid Id category of thirdpary for filter + */ + public function __construct($db, $socid = 0, $userid = 0, $mode = 'customer', $typentid = 0, $categid = 0) + { + global $user, $conf; + @@ -66,14 +68,34 @@ - $this->socid = ($socid > 0 ? $socid : 0); - $this->userid = $userid; - $this->join = ''; - - if ($mode == 'customer') { - $object = new Propal($this->db); - - $this->from = MAIN_DB_PREFIX.$object->table_element." as p"; - $this->from_line = MAIN_DB_PREFIX.$object->table_element_line." as tl"; - $this->field_date = 'p.datep'; - $this->field = 'total_ht'; - $this->field_line = 'total_ht'; - - //$this->where .= " p.fk_statut > 0"; + $this->socid = ($socid > 0 ? $socid : 0); + $this->userid = $userid; + $this->join = ''; + + if ($mode == 'customer') + { + $object = new Propal($this->db); + + $this->from = MAIN_DB_PREFIX.$object->table_element." as p"; + $this->from_line = MAIN_DB_PREFIX.$object->table_element_line." as tl"; + $this->field_date = 'p.datep'; + $this->field = 'total_ht'; + $this->field_line = 'total_ht'; + + $this->where .= " p.fk_statut > 0"; + } + if ($mode == 'supplier') + { + $object = new SupplierProposal($this->db); + + $this->from = MAIN_DB_PREFIX.$object->table_element." as p"; + $this->from_line = MAIN_DB_PREFIX.$object->table_element_line." as tl"; + $this->field_date = 'p.date_valid'; + $this->field = 'total_ht'; + $this->field_line = 'total_ht'; + + $this->where .= " p.fk_statut > 0"; // Validated, accepted, refused and closed + } + //$this->where.= " AND p.fk_soc = s.rowid AND p.entity = ".$conf->entity; + $this->where .= " AND p.entity IN (".getEntity('propal').")"; + if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; + if ($this->socid) + { + $this->where .= " AND p.fk_soc = ".$this->socid; @@ -81,28 +103,14 @@ - if ($mode == 'supplier') { - $object = new SupplierProposal($this->db); - - $this->from = MAIN_DB_PREFIX.$object->table_element." as p"; - $this->from_line = MAIN_DB_PREFIX.$object->table_element_line." as tl"; - $this->field_date = 'p.date_valid'; - $this->field = 'total_ht'; - $this->field_line = 'total_ht'; - - //$this->where .= " p.fk_statut > 0"; // Validated, accepted, refused and closed - } - //$this->where.= " AND p.fk_soc = s.rowid AND p.entity = ".$conf->entity; - $this->where .= ($this->where ? ' AND ' : '')."p.entity IN (".getEntity('propal').")"; - if ($this->socid) { - $this->where .= " AND p.fk_soc = ".((int) $this->socid); - } - if ($this->userid > 0) { - $this->where .= ' AND fk_user_author = '.((int) $this->userid); - } - - if ($typentid) { - $this->join .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc'; - $this->where .= ' AND s.fk_typent = '.((int) $typentid); - } - - if ($categid) { - $this->where .= ' AND EXISTS (SELECT rowid FROM '.MAIN_DB_PREFIX.'categorie_societe as cats WHERE cats.fk_soc = p.fk_soc AND cats.fk_categorie = '.((int) $categid).')'; - } + if ($this->userid > 0) $this->where .= ' AND fk_user_author = '.$this->userid; + + if ($typentid) + { + $this->join .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc'; + $this->where .= ' AND s.fk_typent = '.$typentid; + } + + if ($categid) + { + $this->join .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_societe as cs ON cs.fk_soc = p.fk_soc'; + $this->join .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as c ON c.rowid = cs.fk_categorie'; + $this->where .= ' AND c.rowid = '.$categid; + } @@ -116 +124 @@ - * @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 @@ -119 +127 @@ - public function getNbByMonth($year, $format = 0) + public function getNbByMonth($year, $format = 0) @@ -125,4 +133,2 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); - } - $sql .= $this->join; + if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= $this->join; @@ -132 +138 @@ - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); @@ -144 +150 @@ - public function getNbByYear() + public function getNbByYear() @@ -150,4 +156,2 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$this->socid) { - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); - } - $sql .= $this->join; + if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= $this->join; @@ -156 +160 @@ - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); @@ -165 +169 @@ - * @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 @@ -168 +172 @@ - public function getAmountByMonth($year, $format = 0) + public function getAmountByMonth($year, $format) @@ -174,4 +178,2 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$this->socid) { - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); - } - $sql .= $this->join; + if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= $this->join; @@ -181 +183 @@ - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); @@ -193 +195 @@ - public function getAverageByMonth($year) + public function getAverageByMonth($year) @@ -199,4 +201,2 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$this->socid) { - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); - } - $sql .= $this->join; + if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= $this->join; @@ -206 +206 @@ - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); @@ -216 +216 @@ - public function getAllByYear() + public function getAllByYear() @@ -222,4 +222,2 @@ - if (!$user->hasRight('societe', 'client', 'voir') && !$this->socid) { - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); - } - $sql .= $this->join; + if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= $this->join; @@ -228 +226 @@ - $sql .= $this->db->order('year', 'DESC'); + $sql .= $this->db->order('year', 'DESC'); @@ -239 +237 @@ - * @param int $limit Limit + * @param int $limit Limit @@ -242 +240 @@ - public function getAllByProduct($year, $limit = 10) + public function getAllByProduct($year, $limit = 10) @@ -247,7 +245,3 @@ - $sql .= " FROM ".$this->from; - $sql .= " INNER JOIN ".$this->from_line." ON p.rowid = tl.fk_propal"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."product as product ON tl.fk_product = product.rowid"; - if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) { - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id); - } - $sql .= $this->join; + $sql .= " FROM ".$this->from.", ".$this->from_line.", ".MAIN_DB_PREFIX."product as product"; + if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= $this->join; @@ -255 +249,2 @@ - $sql .= " AND ".$this->field_date." BETWEEN '".$this->db->idate(dol_get_first_day($year, 1, false))."' AND '".$this->db->idate(dol_get_last_day($year, 12, false))."'"; + $sql .= " AND p.rowid = tl.fk_propal AND tl.fk_product = product.rowid"; + $sql .= " AND ".$this->field_date." BETWEEN '".$this->db->idate(dol_get_first_day($year, 1, false))."' AND '".$this->db->idate(dol_get_last_day($year, 12, false))."'"; @@ -257,2 +252,2 @@ - $sql .= $this->db->order('nb', 'DESC'); - //$sql.= $this->db->plimit(20); + $sql .= $this->db->order('nb', 'DESC'); + //$sql.= $this->db->plimit(20);