--- /tmp/dsg/dolibarr/htdocs/comm/propal/class/github_api_proposals.class.php +++ /tmp/dsg/dolibarr/htdocs/comm/propal/class/client_api_proposals.class.php @@ -30,7 +30,7 @@ */ class Proposals extends DolibarrApi { - /** + /** * @var array $FIELDS Mandatory fields, checked when create and update object */ static $FIELDS = array( @@ -65,60 +65,60 @@ */ public function get($id, $contact_list = 1) { - 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 + 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) - { + * @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) { throw new RestException(401); } @@ -151,8 +151,8 @@ * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.datec:<:'20160101')" * @return array Array of order objects */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '') - { + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '') + { global $db, $conf; $obj_ret = array(); @@ -190,7 +190,7 @@ $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; } - $sql .= $this->db->order($sortfield, $sortorder); + $sql .= $db->order($sortfield, $sortorder); if ($limit) { if ($page < 0) { @@ -198,21 +198,21 @@ } $offset = $limit * $page; - $sql .= $this->db->plimit($limit + 1, $offset); - } - - dol_syslog("API Rest request"); - $result = $this->db->query($sql); + $sql .= $db->plimit($limit + 1, $offset); + } + + dol_syslog("API Rest request"); + $result = $db->query($sql); if ($result) { - $num = $this->db->num_rows($result); + $num = $db->num_rows($result); $min = min($num, ($limit <= 0 ? $num : $limit)); $i = 0; while ($i < $min) { - $obj = $this->db->fetch_object($result); - $proposal_static = new Propal($this->db); + $obj = $db->fetch_object($result); + $proposal_static = new Propal($db); if ($proposal_static->fetch($obj->rowid)) { // Add external contacts ids $proposal_static->contacts_ids = $proposal_static->liste_contact(-1, 'external', 1); @@ -220,8 +220,9 @@ } $i++; } - } 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'); @@ -235,13 +236,13 @@ * @param array $request_data Request data * @return int ID of proposal */ - 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); foreach ($request_data as $field => $value) { $this->propal->$field = $value; @@ -258,7 +259,7 @@ } return $this->propal->id; - } + } /** * Get lines of a commercial proposal @@ -269,26 +270,26 @@ * * @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; + 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; } /** @@ -309,50 +310,50 @@ $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); - } - } + 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 @@ -388,37 +389,37 @@ 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; + $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; } /** @@ -432,13 +433,13 @@ * * @return int * - * @throws RestException 401 - * @throws RestException 404 - */ - public function deleteLine($id, $lineid) - { + * @throws RestException 401 + * @throws RestException 404 + */ + public function deleteLine($id, $lineid) + { if (!DolibarrApiAccess::$user->rights->propal->creer) { - throw new RestException(401); + throw new RestException(401); } $result = $this->propal->fetch($id); @@ -455,12 +456,14 @@ $updateRes = $this->propal->deleteline($lineid); if ($updateRes > 0) { return $this->get($id); - } else { + } + else + { throw new RestException(405, $this->propal->error); } } - /** + /** * Add a contact type of given commercial proposal * * @param int $id Id of commercial proposal to update @@ -471,83 +474,76 @@ * * @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); + * @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); if (!$result) { throw new RestException(404, 'Proposal not found'); } - 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; - } - - /** - * Delete a contact type of given commercial proposal - * - * @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). - * - * @url DELETE {id}/contact/{contactid}/{type} - * - * @return int - * - * @throws RestException 401 - * @throws RestException 404 - * @throws RestException 500 - */ - public function deleteContact($id, $contactid, $type) - { - if (!DolibarrApiAccess::$user->rights->propal->creer) { - throw new RestException(401); - } - - $result = $this->propal->fetch($id); + 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; + } + + /** + * Delete a contact type of given commercial proposal + * + * @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); 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); - } - - $contacts = $this->invoice->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; + } /** * Update commercial proposal general fields (won't touch lines of commercial proposal) @@ -556,12 +552,12 @@ * @param array $request_data Datas * * @return int - */ - public function put($id, $request_data = null) - { - if (!DolibarrApiAccess::$user->rights->propal->creer) { - throw new RestException(401); - } + */ + public function put($id, $request_data = null) + { + if (!DolibarrApiAccess::$user->rights->propal->creer) { + throw new RestException(401); + } $result = $this->propal->fetch($id); if (!$result) { @@ -592,7 +588,9 @@ if ($this->propal->update(DolibarrApiAccess::$user) > 0) { return $this->get($id); - } else { + } + else + { throw new RestException(500, $this->propal->error); } } @@ -631,14 +629,14 @@ } /** - * Set a proposal to draft - * - * @param int $id Order ID - * - * @url POST {id}/settodraft - * - * @return array - */ + * Set a proposal to draft + * + * @param int $id Order ID + * + * @url POST {id}/settodraft + * + * @return array + */ public function settodraft($id) { if (!DolibarrApiAccess::$user->rights->propal->creer) { @@ -690,14 +688,14 @@ * @url POST {id}/validate * * @throws RestException 304 - * @throws RestException 401 - * @throws RestException 404 - * @throws RestException 500 - * - * @return array - */ - public function validate($id, $notrigger = 0) - { + * @throws RestException 401 + * @throws RestException 404 + * @throws RestException 500 + * + * @return array + */ + public function validate($id, $notrigger = 0) + { if (!DolibarrApiAccess::$user->rights->propal->creer) { throw new RestException(401); } @@ -718,19 +716,19 @@ throw new RestException(500, 'Error when validating Commercial Proposal: '.$this->propal->error); } - $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); + } /** * Close (Accept or refuse) a quote / commercial proposal @@ -780,47 +778,47 @@ 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); - } + /** + * 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); + } /** @@ -842,25 +840,25 @@ } - // 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_propal.class.php +++ /tmp/dsg/dolibarr/htdocs/comm/propal/class/client_propal.class.php @@ -6,14 +6,14 @@ * 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-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-2020 Frédéric France + * Copyright (C) 2018-2019 Frédéric France * Copyright (C) 2018 Ferran Marcet * * This program is free software; you can redistribute it and/or modify @@ -41,15 +41,12 @@ require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php'; require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php'; /** * Class to manage proposals */ class Propal extends CommonObject { - use CommonIncoterm; - /** * @var string ID to identify managed object */ @@ -66,7 +63,7 @@ public $table_element_line = 'propaldet'; /** - * @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 */ public $fk_element = 'fk_propal'; @@ -124,9 +121,9 @@ */ public $datec; - /** - * @var integer|string $date_creation; - */ + /** + * @var integer|string $date_creation; + */ public $date_creation; /** @@ -136,13 +133,13 @@ public $datev; /** - * @var integer|string $date_validation; - */ + * @var integer|string $date_validation; + */ public $date_validation; /** - * @var integer|string date of the quote; - */ + * @var integer|string date of the quote; + */ public $date; /** @@ -152,15 +149,9 @@ public $datep; /** - * @var int Date expected for delivery - * @deprecated - */ - public $date_livraison; // deprecated; Use delivery_date instead. - - /** - * @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; public $fin_validite; @@ -192,22 +183,19 @@ public $remise_absolue = 0; /** - * @var int ID - * @deprecated - */ + * @var int ID + * @deprecated + */ public $fk_address; public $address_type; public $address; - public $availability_id; public $availability_code; - - public $duree_validite; - public $demand_reason_id; public $demand_reason_code; + public $products = array(); public $extraparams = array(); /** @@ -219,10 +207,12 @@ public $labelStatus = array(); public $labelStatusShort = array(); + public $specimen; + // Multicurrency /** - * @var int ID - */ + * @var int ID + */ public $fk_multicurrency; public $multicurrency_code; @@ -345,7 +335,7 @@ * @param int $socid Id third party * @param int $propalid Id proposal */ - public function __construct($db, $socid = 0, $propalid = 0) + public function __construct($db, $socid = 0, $propalid = 0) { global $conf, $langs; @@ -354,13 +344,15 @@ $this->socid = $socid; $this->id = $propalid; - $this->duree_validite = ((int) $conf->global->PROPALE_VALIDITY_DURATION); - } - - - // 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 * $this->thirdparty should be loaded * * @param int $idproduct Product Id to add @@ -369,10 +361,11 @@ * @return int <0 if KO, >0 if OK * * TODO Replace calls to this function by generation objet Ligne - */ - 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 global $conf, $mysoc; if (!$qty) $qty = 1; @@ -397,7 +390,9 @@ if ($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level) { $price = $prod->multiprices[$this->thirdparty->price_level]; - } else { + } + else + { $price = $prod->price; } @@ -417,16 +412,16 @@ } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Adding line of fixed discount in the proposal in DB * * @param int $idremise Id of fixed discount * @return int >0 if OK, <0 if KO */ - public function insert_discount($idremise) - { - // phpcs:enable + public function insert_discount($idremise) + { + // phpcs:enable global $langs; include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; @@ -478,59 +473,64 @@ { $this->db->commit(); return 1; - } else { + } + else + { $this->db->rollback(); return -1; } - } else { + } + else + { $this->error = $line->error; - $this->errors = $line->errors; $this->db->rollback(); return -2; } - } else { + } + else + { $this->db->rollback(); return -2; } } - /** - * 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) + /** + * 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) { global $mysoc, $conf, $langs; @@ -561,7 +561,9 @@ if ($price_base_type == 'HT') { $pu = $pu_ht; - } else { + } + else + { $pu = $pu_ttc; } @@ -599,9 +601,7 @@ $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc); // Clean vat code - $reg = array(); $vat_src_code = ''; - $reg = array(); if (preg_match('/\((.*)\)/', $txtva, $reg)) { $vat_src_code = $reg[1]; @@ -657,8 +657,8 @@ $this->line->tva_tx = $txtva; $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0); $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0); - $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]; $this->line->fk_product = $fk_product; $this->line->product_type = $type; $this->line->fk_remise_except = $fk_remise_except; @@ -709,42 +709,47 @@ // Reorder if child line 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->errors = $this->line->errors; - $this->db->rollback(); - return -2; - } - } else { + // 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 + { dol_syslog(get_class($this)."::addline status of proposal must be Draft to allow use of ->addline()", LOG_ERR); return -3; } - } + } /** * Update a proposal line * - * @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) * @param float $qty Quantity - * @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 * @param float $txlocaltax1 Local tax 1 rate * @param float $txlocaltax2 Local tax 2 rate * @param string $desc Description - * @param string $price_base_type HT or TTC + * @param string $price_base_type HT ou TTC * @param int $info_bits Miscellaneous informations * @param int $special_code Special code (also used by externals modules!) * @param int $fk_parent_line Id of parent line (0 in most cases, used by modules adding sublevels into lines). @@ -761,11 +766,11 @@ * @param int $notrigger disable line update trigger * @return int 0 if OK, <0 if KO */ - 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) + 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) { global $mysoc, $langs; - 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, txtva=$txtva, desc=$desc, price_base_type=$price_base_type, info_bits=$info_bits, special_code=$special_code, fk_parent_line=$fk_parent_line, pa_ht=$pa_ht, type=$type, date_start=$date_start, date_end=$date_end"); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; @@ -774,9 +779,7 @@ $qty = price2num($qty); $pu = price2num($pu); $pu_ht_devise = price2num($pu_ht_devise); - if (!preg_match('/\((.*)\)/', $txtva)) { - $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5' - } + $txtva = price2num($txtva); $txlocaltax1 = price2num($txlocaltax1); $txlocaltax2 = price2num($txlocaltax2); $pa_ht = price2num($pa_ht); @@ -784,11 +787,11 @@ 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 ($date_start && $date_end && $date_start > $date_end) { + $langs->load("errors"); + $this->error = $langs->trans('ErrorStartDateGreaterEnd'); + return -1; + } if ($this->statut == self::STATUS_DRAFT) { @@ -838,6 +841,7 @@ //Fetch current line from the database and then clone the object and set it in $oldline property $line = new PropaleLigne($this->db); $line->fetch($rowid); + $line->fetch_optionals(); $staticline = clone $line; @@ -913,13 +917,17 @@ $this->db->commit(); return $result; - } else { + } + else + { $this->error = $this->line->error; - $this->errors = $this->line->errors; + $this->db->rollback(); return -1; } - } else { + } + else + { dol_syslog(get_class($this)."::updateline Erreur -2 Propal en mode incompatible pour cette action"); return -2; } @@ -932,7 +940,7 @@ * @param int $lineid Id of line to delete * @return int >0 if OK, <0 if KO */ - public function deleteline($lineid) + public function deleteline($lineid) { global $user; @@ -951,11 +959,15 @@ $this->db->commit(); return 1; - } else { + } + else + { $this->db->rollback(); return -1; } - } else { + } + else + { $this->error = 'ErrorDeleteLineNotAllowedByObjectStatus'; return -2; } @@ -970,7 +982,7 @@ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >=0 if OK */ - public function create($user, $notrigger = 0) + public function create($user, $notrigger = 0) { global $conf, $hookmanager; $error = 0; @@ -992,9 +1004,6 @@ $this->fk_multicurrency = 0; $this->multicurrency_tx = 1; } - - // Set tmp vars - $delivery_date = empty($this->delivery_date) ? $this->date_livraison : $this->delivery_date; dol_syslog(get_class($this)."::create"); @@ -1074,16 +1083,16 @@ $sql .= ", '".$this->db->idate($this->date)."'"; $sql .= ", '".$this->db->idate($now)."'"; $sql .= ", '(PROV)'"; - $sql .= ", ".($user->id > 0 ? "'".$this->db->escape($user->id)."'" : "NULL"); + $sql .= ", ".($user->id > 0 ? "'".$user->id."'" : "NULL"); $sql .= ", '".$this->db->escape($this->note_private)."'"; $sql .= ", '".$this->db->escape($this->note_public)."'"; - $sql .= ", '".$this->db->escape($this->model_pdf)."'"; + $sql .= ", '".$this->db->escape($this->modelpdf)."'"; $sql .= ", ".($this->fin_validite != '' ? "'".$this->db->idate($this->fin_validite)."'" : "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'); $sql .= ", '".$this->db->escape($this->ref_client)."'"; - $sql .= ", ".(empty($delivery_date) ? "NULL" : "'".$this->db->idate($delivery_date)."'"); + $sql .= ", ".($this->date_livraison != '' ? "'".$this->db->idate($this->date_livraison)."'" : "NULL"); $sql .= ", ".($this->shipping_method_id > 0 ? $this->shipping_method_id : 'NULL'); $sql .= ", ".$this->availability_id; $sql .= ", ".$this->demand_reason_id; @@ -1105,68 +1114,71 @@ if ($this->id) { $this->ref = '(PROV'.$this->id.')'; - $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; dol_syslog(get_class($this)."::create", LOG_DEBUG); $resql = $this->db->query($sql); 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++; - } - } - } - } - - /* + 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); + 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 (!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]; + } // Reset fk_parent_line for line that are not child lines or special product if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) { $fk_parent_line = 0; } - // Complete vat rate with code + // Complete vat rate with code $vatrate = $line->tva_tx; if ($line->vat_src_code && !preg_match('/\(.*\)/', $vatrate)) $vatrate .= ' ('.$line->vat_src_code.')'; @@ -1255,12 +1267,16 @@ if ($result < 0) { $error++; } // End call triggers } - } else { + } + else + { $this->error = $this->db->lasterror(); $error++; } } - } else { + } + else + { $this->error = $this->db->lasterror(); $error++; } @@ -1270,15 +1286,37 @@ $this->db->commit(); dol_syslog(get_class($this)."::create done id=".$this->id); return $this->id; - } else { + } + else + { $this->db->rollback(); return -2; } - } else { + } + else + { $this->error = $this->db->lasterror(); $this->db->rollback(); return -1; } + } + + + // 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); } /** @@ -1306,6 +1344,7 @@ // Load source object $object->fetch($this->id); + $object->fetch_lines(); $objsoc = new Societe($this->db); @@ -1314,10 +1353,10 @@ { 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 = ''; + $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)) { @@ -1329,20 +1368,22 @@ $clonedObj->fk_project = ''; } }*/ - $object->fk_project = ''; // A cloned proposal is set by default to no project. + $object->fk_project = ''; // A cloned proposal is set by default to no project. } // reset ref_client $object->ref_client = ''; // TODO Change product price if multi-prices - } else { - $objsoc->fetch($object->socid); + } + else + { + $objsoc->fetch($object->socid); } $object->id = 0; $object->ref = ''; - $object->entity = (!empty($forceentity) ? $forceentity : $object->entity); + $object->entity = (! empty($forceentity) ? $forceentity : $object->entity); $object->statut = self::STATUS_DRAFT; // Clear fields @@ -1362,18 +1403,18 @@ $result = $object->create($user); if ($result < 0) { - $this->error = $object->error; - $this->errors = array_merge($this->errors, $object->errors); - $error++; + $this->error = $object->error; + $this->errors = array_merge($this->errors, $object->errors); + $error++; } if (!$error) { // copy internal contacts - if ($object->copy_linked_contact($this, 'internal') < 0) - { + if ($object->copy_linked_contact($this, 'internal') < 0) + { $error++; - } + } } if (!$error) @@ -1381,7 +1422,7 @@ // copy external contacts if same company if ($this->socid == $object->socid) { - if ($object->copy_linked_contact($this, 'external') < 0) + if ($object->copy_linked_contact($this, 'external') < 0) $error++; } } @@ -1405,7 +1446,9 @@ { $this->db->commit(); return $object->id; - } else { + } + else + { $this->db->rollback(); return -1; } @@ -1419,7 +1462,7 @@ * @param string $ref_ext Ref ext of proposal * @return int >0 if OK, <0 if KO */ - public function fetch($rowid, $ref = '', $ref_ext = '') + 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"; @@ -1427,7 +1470,7 @@ $sql .= ", p.date_valid as datev"; $sql .= ", p.datep as dp"; $sql .= ", p.fin_validite as dfv"; - $sql .= ", p.date_livraison as delivery_date"; + $sql .= ", p.date_livraison as date_livraison"; $sql .= ", p.model_pdf, p.last_main_doc, p.ref_client, p.extraparams"; $sql .= ", p.note_private, p.note_public"; $sql .= ", p.fk_projet as fk_project, p.fk_statut"; @@ -1459,7 +1502,8 @@ if ($ref) { $sql .= " WHERE p.entity IN (".getEntity('propal').")"; // Dont't use entity if you use rowid $sql .= " AND p.ref='".$this->db->escape($ref)."'"; - } else $sql .= " WHERE p.rowid=".$rowid; + } + else $sql .= " WHERE p.rowid=".$rowid; dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql = $this->db->query($sql); @@ -1490,15 +1534,14 @@ $this->fk_project = $obj->fk_project; $this->project = null; // Clear if another value was already set by fetch_projet - $this->model_pdf = $obj->model_pdf; - $this->modelpdf = $obj->model_pdf; // deprecated + $this->modelpdf = $obj->model_pdf; $this->last_main_doc = $obj->last_main_doc; $this->note = $obj->note_private; // TODO deprecated $this->note_private = $obj->note_private; $this->note_public = $obj->note_public; $this->status = (int) $obj->fk_statut; - $this->statut = $this->status; // deprecated + $this->statut = $this->status; // deprecated $this->statut_libelle = $obj->statut_label; $this->datec = $this->db->jdate($obj->datec); // TODO deprecated @@ -1509,8 +1552,7 @@ $this->date = $this->db->jdate($obj->dp); // Proposal date $this->datep = $this->db->jdate($obj->dp); // deprecated $this->fin_validite = $this->db->jdate($obj->dfv); - $this->date_livraison = $this->db->jdate($obj->delivery_date); // deprecated - $this->delivery_date = $this->db->jdate($obj->delivery_date); + $this->date_livraison = $this->db->jdate($obj->date_livraison); $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method : null; $this->availability_id = $obj->fk_availability; $this->availability_code = $obj->availability_code; @@ -1553,7 +1595,7 @@ $this->brouillon = 1; } - // Retrieve all extrafield + // Retreive all extrafield // fetch optionals attributes and labels $this->fetch_optionals(); @@ -1573,7 +1615,9 @@ $this->error = "Record Not Found"; return 0; - } else { + } + else + { $this->error = $this->db->lasterror(); return -1; } @@ -1586,7 +1630,7 @@ * @param int $notrigger 0=launch triggers after, 1=disable triggers * @return int <0 if KO, >0 if OK */ - public function update(User $user, $notrigger = 0) + public function update(User $user, $notrigger = 0) { global $conf; @@ -1597,15 +1641,16 @@ 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->modelpdf)) $this->modelpdf = trim($this->modelpdf); 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 (!empty($this->duree_validite)) $this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600); // Check parameters // Put here code to add control on parameters values // Update request $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET"; + $sql .= " ref=".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "null").","; $sql .= " ref_client=".(isset($this->ref_client) ? "'".$this->db->escape($this->ref_client)."'" : "null").","; $sql .= " ref_ext=".(isset($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null").","; @@ -1624,11 +1669,11 @@ $sql .= " fk_projet=".(isset($this->fk_project) ? $this->fk_project : "null").","; $sql .= " fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id : "null").","; $sql .= " fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id : "null").","; - $sql .= " fk_input_reason=".(isset($this->demand_reason_id) ? $this->demand_reason_id : "null").","; $sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").","; $sql .= " note_public=".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").","; $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; $this->db->begin(); @@ -1666,14 +1711,16 @@ } $this->db->rollback(); return -1 * $error; - } else { + } + else + { $this->db->commit(); return 1; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Load array lines * @@ -1685,13 +1732,13 @@ public function fetch_lines($only_product = 0, $loadalsotranslation = 0) { global $langs, $conf; - // phpcs:enable + // phpcs:enable $this->lines = array(); $sql = 'SELECT d.rowid, d.fk_propal, d.fk_parent_line, d.label as custom_label, d.description, d.price, d.vat_src_code, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.localtax1_type, d.localtax2_type, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,'; $sql .= ' d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht, d.special_code, d.rang, d.product_type,'; $sql .= ' d.fk_unit,'; - $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,'; $sql .= ' p.weight, p.weight_units, p.volume, p.volume_units,'; $sql .= ' d.date_start, d.date_end,'; $sql .= ' d.fk_multicurrency, d.multicurrency_code, d.multicurrency_subprice, d.multicurrency_total_ht, d.multicurrency_total_tva, d.multicurrency_total_ttc'; @@ -1753,14 +1800,11 @@ $line->fk_product = $objp->fk_product; $line->ref = $objp->product_ref; // deprecated + $line->product_ref = $objp->product_ref; $line->libelle = $objp->product_label; // deprecated - - $line->product_ref = $objp->product_ref; $line->product_label = $objp->product_label; $line->product_desc = $objp->product_desc; // Description produit $line->product_tobatch = $objp->product_tobatch; - $line->product_barcode = $objp->product_barcode; - $line->fk_product_type = $objp->fk_product_type; // deprecated $line->fk_unit = $objp->fk_unit; $line->weight = $objp->weight; @@ -1782,11 +1826,11 @@ $line->fetch_optionals(); // 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(); - } + if (!empty($conf->global->MAIN_MULTILANGS) && !empty($objp->fk_product) && !empty($loadalsotranslation)) { + $line = new Product($this->db); + $line->fetch($objp->fk_product); + $line->getMultiLangs(); + } $this->lines[$i] = $line; //dol_syslog("1 ".$line->fk_product); @@ -1797,7 +1841,9 @@ $this->db->free($result); return $num; - } else { + } + else + { $this->error = $this->db->lasterror(); return -3; } @@ -1810,7 +1856,7 @@ * @param int $notrigger 1=Does not execute triggers, 0=execute triggers * @return int <0 if KO, 0=Nothing done, >=0 if OK */ - public function valid($user, $notrigger = 0) + public function valid($user, $notrigger = 0) { global $conf; @@ -1845,7 +1891,9 @@ if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life { $num = $this->getNextNumRef($soc); - } else { + } + else + { $num = $this->ref; } $this->newref = dol_sanitizeFileName($num); @@ -1918,14 +1966,16 @@ $this->db->commit(); return 1; - } else { + } + else + { $this->db->rollback(); return -1; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define proposal date * @@ -1934,9 +1984,9 @@ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >0 if OK */ - public function set_date($user, $date, $notrigger = 0) - { - // phpcs:enable + public function set_date($user, $date, $notrigger = 0) + { + // phpcs:enable if (empty($date)) { $this->error = 'ErrorBadParameter'; @@ -1980,7 +2030,9 @@ { $this->db->commit(); return 1; - } else { + } + else + { foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); @@ -1992,7 +2044,7 @@ } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Define end validity date * @@ -2001,9 +2053,9 @@ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >0 if OK */ - public function set_echeance($user, $date_fin_validite, $notrigger = 0) - { - // phpcs:enable + public function set_echeance($user, $date_fin_validite, $notrigger = 0) + { + // phpcs:enable if (!empty($user->rights->propal->creer)) { $error = 0; @@ -2040,7 +2092,9 @@ { $this->db->commit(); return 1; - } else { + } + else + { foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); @@ -2052,32 +2106,18 @@ } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set delivery date * * @param User $user Object user that modify - * @param int $delivery_date Delivery date + * @param int $date_livraison Delivery date * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <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 <0 if ko, >0 if ok - */ - public function setDeliveryDate($user, $delivery_date, $notrigger = 0) - { + */ + public function set_date_livraison($user, $date_livraison, $notrigger = 0) + { + // phpcs:enable if (!empty($user->rights->propal->creer)) { $error = 0; @@ -2085,7 +2125,7 @@ $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."propal "; - $sql .= " SET date_livraison = ".($delivery_date != '' ? "'".$this->db->idate($delivery_date)."'" : 'null'); + $sql .= " SET date_livraison = ".($date_livraison != '' ? "'".$this->db->idate($date_livraison)."'" : 'null'); $sql .= " WHERE rowid = ".$this->id; dol_syslog(__METHOD__, LOG_DEBUG); @@ -2099,8 +2139,7 @@ if (!$error) { $this->oldcopy = clone $this; - $this->date_livraison = $delivery_date; - $this->delivery_date = $delivery_date; + $this->date_livraison = $date_livraison; } if (!$notrigger && empty($error)) @@ -2115,7 +2154,9 @@ { $this->db->commit(); return 1; - } else { + } + else + { foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); @@ -2127,7 +2168,7 @@ } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set delivery * @@ -2136,9 +2177,9 @@ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >0 if OK */ - public function set_availability($user, $id, $notrigger = 0) - { - // phpcs:enable + public function set_availability($user, $id, $notrigger = 0) + { + // phpcs:enable if (!empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT) { $error = 0; @@ -2176,7 +2217,9 @@ { $this->db->commit(); return 1; - } else { + } + else + { foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); @@ -2185,7 +2228,9 @@ $this->db->rollback(); return -1 * $error; } - } else { + } + else + { $error_str = 'Propal status do not meet requirement '.$this->statut; dol_syslog(__METHOD__.$error_str, LOG_ERR); $this->error = $error_str; @@ -2194,7 +2239,7 @@ } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set source of demand * @@ -2203,9 +2248,9 @@ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >0 if OK */ - public function set_demand_reason($user, $id, $notrigger = 0) - { - // phpcs:enable + public function set_demand_reason($user, $id, $notrigger = 0) + { + // phpcs:enable if (!empty($user->rights->propal->creer) && $this->statut >= self::STATUS_DRAFT) { $error = 0; @@ -2245,7 +2290,9 @@ { $this->db->commit(); return 1; - } else { + } + else + { foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); @@ -2254,7 +2301,9 @@ $this->db->rollback(); return -1 * $error; } - } else { + } + else + { $error_str = 'Propal status do not meet requirement '.$this->statut; dol_syslog(__METHOD__.$error_str, LOG_ERR); $this->error = $error_str; @@ -2263,7 +2312,7 @@ } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set customer reference number * @@ -2272,9 +2321,9 @@ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if ko, >0 if ok */ - public function set_ref_client($user, $ref_client, $notrigger = 0) - { - // phpcs:enable + public function set_ref_client($user, $ref_client, $notrigger = 0) + { + // phpcs:enable if (!empty($user->rights->propal->creer)) { $error = 0; @@ -2310,7 +2359,9 @@ { $this->db->commit(); return 1; - } else { + } + else + { foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); @@ -2319,12 +2370,14 @@ $this->db->rollback(); return -1 * $error; } - } else { + } + else + { return -1; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set an overall discount on the proposal * @@ -2333,9 +2386,9 @@ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if ko, >0 if ok */ - public function set_remise_percent($user, $remise, $notrigger = 0) - { - // phpcs:enable + public function set_remise_percent($user, $remise, $notrigger = 0) + { + // phpcs:enable $remise = trim($remise) ?trim($remise) : 0; if (!empty($user->rights->propal->creer)) @@ -2376,7 +2429,9 @@ { $this->db->commit(); return 1; - } else { + } + else + { foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); @@ -2389,7 +2444,7 @@ } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set an absolute overall discount on the proposal * @@ -2398,9 +2453,9 @@ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if ko, >0 if ok */ - public function set_remise_absolue($user, $remise, $notrigger = 0) - { - // phpcs:enable + public function set_remise_absolue($user, $remise, $notrigger = 0) + { + // phpcs:enable $remise = trim($remise) ?trim($remise) : 0; if (!empty($user->rights->propal->creer)) @@ -2442,7 +2497,9 @@ { $this->db->commit(); return 1; - } else { + } + else + { foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); @@ -2465,7 +2522,7 @@ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >0 if OK */ - public function reopen($user, $statut, $note = '', $notrigger = 0) + public function reopen($user, $statut, $note = '', $notrigger = 0) { $this->statut = $statut; @@ -2508,7 +2565,9 @@ } $this->db->rollback(); return -1 * $error; - } else { + } + else + { $this->db->commit(); return 1; } @@ -2519,12 +2578,12 @@ * Close the commercial proposal * * @param User $user Object user that close - * @param int $status Status + * @param int $statut Statut * @param string $note Complete private note with this note * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers * @return int <0 if KO, >0 if OK */ - public function cloture($user, $status, $note = "", $notrigger = 0) + public function cloture($user, $statut, $note = "", $notrigger = 0) { global $langs, $conf; @@ -2536,19 +2595,19 @@ $newprivatenote = dol_concatdesc($this->note_private, $note); $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; - $sql .= " SET fk_statut = ".$status.", note_private = '".$this->db->escape($newprivatenote)."', date_cloture='".$this->db->idate($now)."', fk_user_cloture=".$user->id; + $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; $resql = $this->db->query($sql); if ($resql) { - $modelpdf = $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED ? $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED : $this->model_pdf; + $modelpdf = $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED ? $conf->global->PROPALE_ADDON_PDF_ODT_CLOSED : $this->modelpdf; $triggerName = 'PROPAL_CLOSE_REFUSED'; - if ($status == self::STATUS_SIGNED) + 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->model_pdf; + $modelpdf = $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL ? $conf->global->PROPALE_ADDON_PDF_ODT_TOBILL : $this->modelpdf; // The connected company is classified as a client $soc = new Societe($this->db); @@ -2562,7 +2621,7 @@ return -2; } } - if ($status == self::STATUS_BILLED) // ->cloture() can also be called when we set it to billed, after setting it to signed + if ($statut == self::STATUS_BILLED) // Why this ? { $triggerName = 'PROPAL_CLASSIFY_BILLED'; } @@ -2584,7 +2643,7 @@ if (!$error) { $this->oldcopy = clone $this; - $this->statut = $status; + $this->statut = $statut; $this->date_cloture = $now; $this->note_private = $newprivatenote; } @@ -2601,7 +2660,9 @@ { $this->db->commit(); return 1; - } else { + } + else + { $this->statut = $this->oldcopy->statut; $this->date_cloture = $this->oldcopy->date_cloture; $this->note_private = $this->oldcopy->note_private; @@ -2609,7 +2670,9 @@ $this->db->rollback(); return -1; } - } else { + } + else + { $this->error = $this->db->lasterror(); $this->db->rollback(); return -1; @@ -2623,7 +2686,7 @@ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 si ko, >0 si ok */ - public function classifyBilled(User $user, $notrigger = 0) + public function classifyBilled(User $user, $notrigger = 0) { $error = 0; @@ -2658,7 +2721,9 @@ { $this->db->commit(); return 1; - } else { + } + else + { foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); @@ -2669,7 +2734,7 @@ } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set draft status * @@ -2677,15 +2742,15 @@ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >0 if OK */ - public function setDraft($user, $notrigger = 0) - { - // phpcs:enable + public function setDraft($user, $notrigger = 0) + { + // phpcs:enable $error = 0; // Protection if ($this->statut <= self::STATUS_DRAFT) { - return 0; + return 0; } dol_syslog(get_class($this)."::setDraft", LOG_DEBUG); @@ -2718,12 +2783,14 @@ if (!$error) { - $this->statut = self::STATUS_DRAFT; - $this->brouillon = 1; - - $this->db->commit(); + $this->statut = self::STATUS_DRAFT; + $this->brouillon = 1; + + $this->db->commit(); return 1; - } else { + } + else + { foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); @@ -2735,7 +2802,7 @@ } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return list of proposal (eventually filtered on user) into an array * @@ -2749,9 +2816,9 @@ * @param string $sortorder Sort order * @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 + public function liste_array($shortlist = 0, $draft = 0, $notcurrentuser = 0, $socid = 0, $limit = 0, $offset = 0, $sortfield = 'p.datep', $sortorder = 'DESC') + { + // phpcs:enable global $user; $ga = array(); @@ -2789,10 +2856,13 @@ if ($shortlist == 1) { $ga[$obj->propalid] = $obj->ref; - } elseif ($shortlist == 2) + } + elseif ($shortlist == 2) { $ga[$obj->propalid] = $obj->ref.' ('.$obj->name.')'; - } else { + } + else + { $ga[$i]['id'] = $obj->propalid; $ga[$i]['ref'] = $obj->ref; $ga[$i]['name'] = $obj->name; @@ -2802,7 +2872,9 @@ } } return $ga; - } else { + } + else + { dol_print_error($this->db); return -1; } @@ -2813,21 +2885,21 @@ * * @return array Array of invoices */ - public function getInvoiceArrayList() + public function getInvoiceArrayList() { return $this->InvoiceArrayList($this->id); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Returns an array with id and ref of related invoices * * @param int $id Id propal * @return array Array of invoices id */ - public function InvoiceArrayList($id) - { - // phpcs:enable + public function InvoiceArrayList($id) + { + // phpcs:enable $ga = array(); $linkedInvoices = array(); @@ -2842,8 +2914,10 @@ if ($objecttype == 'facture') { $linkedInvoices[] = $object; - } // Cas des factures liees par un autre objet (ex: commande) - else { + } + // Cas des factures liees par un autre objet (ex: commande) + else + { $this->fetchObjectLinked($object, $objecttype); foreach ($this->linkedObjectsIds as $subobjecttype => $subobjectid) { @@ -2894,10 +2968,13 @@ } } return $ga; - } else { + } + else + { return -1; } - } else return $ga; + } + else return $ga; } /** @@ -2905,9 +2982,9 @@ * * @param User $user Object user that delete * @param int $notrigger 1=Does not execute triggers, 0= execute triggers - * @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) { global $conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -2916,100 +2993,108 @@ $this->db->begin(); - if (!$notrigger) { + if (!$notrigger) + { // Call trigger $result = $this->call_trigger('PROPAL_DELETE', $user); if ($result < 0) { $error++; } // End call triggers } - // 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." = ".$this->id.")"; - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete." WHERE ".$this->fk_element." = ".$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 = ".$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 - 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(); $this->db->rollback(); return 0; } } - if (file_exists($dir)) { - $res = @dol_delete_dir_recursive($dir); - 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; } } - } - - 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 + { $this->db->rollback(); return -1; } @@ -3023,7 +3108,7 @@ * @return int >0 if OK, <0 if KO * @deprecated use set_availability */ - public function availability($availability_id, $notrigger = 0) + public function availability($availability_id, $notrigger = 0) { global $user; @@ -3063,7 +3148,9 @@ { $this->db->commit(); return 1; - } else { + } + else + { foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); @@ -3072,7 +3159,9 @@ $this->db->rollback(); return -1 * $error; } - } else { + } + else + { $error_str = 'Propal status do not meet requirement '.$this->statut; dol_syslog(__METHOD__.$error_str, LOG_ERR); $this->error = $error_str; @@ -3081,7 +3170,7 @@ } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Change source demand * @@ -3090,9 +3179,9 @@ * @return int >0 si ok, <0 si ko * @deprecated use set_demand_reason */ - public function demand_reason($demand_reason_id, $notrigger = 0) - { - // phpcs:enable + public function demand_reason($demand_reason_id, $notrigger = 0) + { + // phpcs:enable global $user; if ($this->statut >= self::STATUS_DRAFT) @@ -3131,7 +3220,9 @@ { $this->db->commit(); return 1; - } else { + } + else + { foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); @@ -3140,7 +3231,9 @@ $this->db->rollback(); return -1 * $error; } - } else { + } + else + { $error_str = 'Propal status do not meet requirement '.$this->statut; dol_syslog(__METHOD__.$error_str, LOG_ERR); $this->error = $error_str; @@ -3156,13 +3249,13 @@ * @param int $id Proposal id * @return void */ - public function info($id) + public function info($id) { $sql = "SELECT c.rowid, "; $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"; $sql .= " FROM ".MAIN_DB_PREFIX."propal as c"; - $sql .= " WHERE c.rowid = ".((int) $id); + $sql .= " WHERE c.rowid = ".$id; $result = $this->db->query($sql); @@ -3197,7 +3290,9 @@ } } $this->db->free($result); - } else { + } + else + { dol_print_error($this->db); } } @@ -3209,12 +3304,12 @@ * @param int $mode 0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto, 6=Long label + Picto * @return string Label */ - public function getLibStatut($mode = 0) + public function getLibStatut($mode = 0) { return $this->LibStatut($this->statut, $mode); } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return label of a status (draft, validated, ...) * @@ -3222,9 +3317,9 @@ * @param int $mode 0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto, 6=Long label + Picto * @return string Label */ - public function LibStatut($status, $mode = 1) - { - // phpcs:enable + public function LibStatut($status, $mode = 1) + { + // phpcs:enable global $conf; // Init/load array of translation of status @@ -3232,16 +3327,16 @@ { global $langs; $langs->load("propal"); - $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"); } $statusType = ''; @@ -3255,7 +3350,7 @@ } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Load indicators for dashboard (this->nbtodo and this->nbtodolate) * @@ -3263,9 +3358,9 @@ * @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 + public function load_board($user, $mode) + { + // phpcs:enable global $conf, $langs; $clause = " WHERE"; @@ -3295,8 +3390,8 @@ if ($mode == 'opened') { $delay_warning = $conf->propal->cloture->warning_delay; $status = self::STATUS_VALIDATED; - $label = $langs->transnoentitiesnoconv("PropalsToClose"); - $labelShort = $langs->transnoentitiesnoconv("ToAcceptRefuse"); + $label = $langs->trans("PropalsToClose"); + $labelShort = $langs->trans("ToAcceptRefuse"); } if ($mode == 'signed') { $delay_warning = $conf->propal->facturation->warning_delay; @@ -3332,7 +3427,9 @@ } return $response; - } else { + } + else + { $this->error = $this->db->error(); return -1; } @@ -3346,7 +3443,7 @@ * * @return void */ - public function initAsSpecimen() + public function initAsSpecimen() { global $conf, $langs; @@ -3356,8 +3453,6 @@ $sql = "SELECT rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."product"; $sql .= " WHERE entity IN (".getEntity('product').")"; - $sql .= $this->db->plimit(100); - $resql = $this->db->query($sql); if ($resql) { @@ -3412,7 +3507,9 @@ $line->total_ttc = 60; $line->total_tva = 10; $line->remise_percent = 50; - } else { + } + else + { $line->total_ht = 100; $line->total_ttc = 120; $line->total_tva = 20; @@ -3423,7 +3520,7 @@ { $prodid = mt_rand(1, $num_prods); $line->fk_product = $prodids[$prodid]; - $line->product_ref = 'SPECIMEN'; + $line->product_ref = 'SPECIMEN'; } $this->lines[$xnbp] = $line; @@ -3436,15 +3533,15 @@ } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Charge indicateurs this->nb de tableau de bord * * @return int <0 if ko, >0 if ok */ - public function load_state_board() - { - // phpcs:enable + public function load_state_board() + { + // phpcs:enable global $user; $this->nb = array(); @@ -3471,7 +3568,9 @@ } $this->db->free($resql); return 1; - } else { + } + else + { dol_print_error($this->db); $this->error = $this->db->error(); return -1; @@ -3486,7 +3585,7 @@ * @param Societe $soc Object thirdparty * @return string Reference libre pour la propale */ - public function getNextNumRef($soc) + public function getNextNumRef($soc) { global $conf, $langs; $langs->load("propal"); @@ -3521,12 +3620,16 @@ if ($numref != "") { return $numref; - } else { + } + else + { $this->error = $obj->error; //dol_print_error($db,"Propale::getNextNumRef ".$obj->error); return ""; } - } else { + } + else + { $langs->load("errors"); print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Proposal")); return ""; @@ -3541,10 +3644,10 @@ * @param string $get_params Parametres added to url * @param int $notooltip 1=Disable tooltip * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking - * @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) * @return string String with URL */ - public function getNomUrl($withpicto = 0, $option = '', $get_params = '', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = -1) + public function getNomUrl($withpicto = 0, $option = '', $get_params = '', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = -1) { global $langs, $conf, $user; @@ -3556,36 +3659,32 @@ if ($user->rights->propal->lire) { - $label = img_picto('', $this->picto).' '.$langs->trans("Proposal").''; + $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 .= ' '.$this->getLibStatut(5); - } - 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 (!empty($this->delivery_date)) { - $label .= '
'.$langs->trans('DeliveryDate').': '.dol_print_date($this->delivery_date, 'dayhour'); - } + $label .= '
'.$langs->trans("Status").": ".$this->getLibStatut(5); + } + if ($option == '') { $url = DOL_URL_ROOT.'/comm/propal/card.php?id='.$this->id.$get_params; - } elseif ($option == 'compta') { // deprecated + } + elseif ($option == 'compta') { // deprecated $url = DOL_URL_ROOT.'/comm/propal/card.php?id='.$this->id.$get_params; - } elseif ($option == 'expedition') { + } + elseif ($option == 'expedition') { $url = DOL_URL_ROOT.'/expedition/propal.php?id='.$this->id.$get_params; - } elseif ($option == 'document') { + } + elseif ($option == 'document') { $url = DOL_URL_ROOT.'/comm/propal/document.php?id='.$this->id.$get_params; } @@ -3619,45 +3718,45 @@ if ($withpicto != 2) $result .= $this->ref; $result .= $linkend; - 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 .= ''; - } - } + 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 .= ''; + } + } return $result; } @@ -3667,7 +3766,7 @@ * * @return int >0 if OK, <0 if KO */ - public function getLinesArray() + public function getLinesArray() { return $this->fetch_lines(); } @@ -3680,7 +3779,7 @@ * @param int $hidedetails Hide details of lines * @param int $hidedesc Hide description * @param int $hideref Hide ref - * @param null|array $moreparams Array to provide more information + * @param null|array $moreparams Array to provide more information * @return int 0 if KO, 1 if OK */ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) @@ -3688,13 +3787,12 @@ global $conf, $langs; $langs->load("propale"); - $outputlangs->load("products"); if (!dol_strlen($modele)) { $modele = 'azur'; - if ($this->model_pdf) { - $modele = $this->model_pdf; + if ($this->modelpdf) { + $modele = $this->modelpdf; } elseif (!empty($conf->global->PROPALE_ADDON_PDF)) { $modele = $conf->global->PROPALE_ADDON_PDF; } @@ -3739,71 +3837,68 @@ */ public $table_element = 'propaldet'; - public $oldline; + public $oldline; // From llx_propaldet - 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 /** * @deprecated * @see $product_type */ - public $fk_product_type; + public $fk_product_type; /** * Product type. * @var int * @see Product::TYPE_PRODUCT, Product::TYPE_SERVICE */ - 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) // 1: frais de port // 2: ecotaxe // 3: option line (when qty = 0) - public $info_bits = 0; // Some other info: + public $info_bits = 0; // Some other info: // Bit 0: 0 si TVA normal - 1 si TVA NPR // Bit 1: 0 ligne normale - 1 si ligne de remise fixe - 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 /** * @deprecated * @see $remise_percent, $fk_remise_except */ - public $remise; + public $remise; /** * @deprecated * @see $subprice */ - public $price; + public $price; // From llx_product /** * @deprecated * @see $product_ref */ - public $ref; + public $ref; /** * Product reference * @var string @@ -3813,12 +3908,7 @@ * @deprecated * @see $product_label */ - public $libelle; - /** - * @deprecated - * @see $product_label - */ - public $label; + public $libelle; /** * Product label * @var string @@ -3830,44 +3920,32 @@ */ public $product_desc; - /** - * 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 // Multicurrency - 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; /** * Class line Contructor * * @param DoliDB $db Database handler */ - public function __construct($db) + public function __construct($db) { $this->db = $db; } @@ -3878,7 +3956,7 @@ * @param int $rowid Propal line id * @return int <0 if KO, >0 if OK */ - public function fetch($rowid) + public function fetch($rowid) { $sql = 'SELECT pd.rowid, pd.fk_propal, pd.fk_parent_line, pd.fk_product, pd.label as custom_label, pd.description, pd.price, pd.qty, pd.vat_src_code, pd.tva_tx,'; $sql .= ' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice,'; @@ -3954,10 +4032,14 @@ $this->db->free($result); return 1; - } else { + } + else + { return 0; } - } else { + } + else + { return -1; } } @@ -3968,7 +4050,7 @@ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >0 if OK */ - public function insert($notrigger = 0) + public function insert($notrigger = 0) { global $conf, $user; @@ -4000,13 +4082,15 @@ 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 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) { return $result; - } else { + } + else + { $this->pa_ht = $result; } } @@ -4093,7 +4177,9 @@ $this->db->commit(); return 1; - } else { + } + else + { $this->error = $this->db->error()." sql=".$sql; $this->db->rollback(); return -1; @@ -4107,7 +4193,7 @@ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if ko, >0 if ok */ - public function delete(User $user, $notrigger = 0) + public function delete(User $user, $notrigger = 0) { global $conf; @@ -4145,7 +4231,9 @@ $this->db->commit(); return 1; - } else { + } + else + { $this->error = $this->db->error()." sql=".$sql; $this->db->rollback(); return -1; @@ -4158,15 +4246,13 @@ * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if ko, >0 if ok */ - public function update($notrigger = 0) + public function update($notrigger = 0) { global $conf, $user; $error = 0; $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'. - - if (empty($this->id) && !empty($this->rowid)) $this->id = $this->rowid; // Clean parameters if (empty($this->tva_tx)) $this->tva_tx = 0; @@ -4194,7 +4280,9 @@ if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { return $result; - } else { + } + else + { $this->pa_ht = $result; } } @@ -4241,7 +4329,7 @@ $sql .= ", multicurrency_total_tva=".price2num($this->multicurrency_total_tva).""; $sql .= ", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc).""; - $sql .= " WHERE rowid = ".$this->id; + $sql .= " WHERE rowid = ".$this->rowid; dol_syslog(get_class($this)."::update", LOG_DEBUG); $resql = $this->db->query($sql); @@ -4249,6 +4337,7 @@ { if (!$error) { + $this->id = $this->rowid; $result = $this->insertExtraFields(); if ($result < 0) { @@ -4270,23 +4359,25 @@ $this->db->commit(); return 1; - } else { + } + else + { $this->error = $this->db->error(); $this->db->rollback(); return -2; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Update DB line fields total_xxx * Used by migration * * @return int <0 if KO, >0 if OK */ - public function update_total() - { - // phpcs:enable + public function update_total() + { + // phpcs:enable $this->db->begin(); // Mise a jour ligne en base @@ -4303,7 +4394,9 @@ { $this->db->commit(); return 1; - } else { + } + else + { $this->error = $this->db->error(); $this->db->rollback(); return -2; --- /tmp/dsg/dolibarr/htdocs/comm/propal/class/github_propalestats.class.php +++ /tmp/dsg/dolibarr/htdocs/comm/propal/class/client_propalestats.class.php @@ -36,18 +36,18 @@ */ class PropaleStats extends Stats { - /** + /** * @var string Name of table without prefix where object is stored */ public $table_element; - public $socid; - public $userid; - - public $from; - public $field; - public $where; - public $join; + public $socid; + public $userid; + + public $from; + public $field; + public $where; + public $join; /** @@ -55,65 +55,65 @@ * * @param DoliDB $db Database handler * @param int $socid Id third party for filter. This value must be forced during the new to external user company if user is an external user. - * @param int $userid Id user for filter (creation user) + * @param int $userid Id user for filter (creation user) * @param string $mode Option ('customer', 'supplier') - * @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; $this->db = $db; - $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->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 .= ($this->where ? ' AND ' : '')."p.entity IN (".getEntity('propal').")"; + $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; } - 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; - } + 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; + } } @@ -121,21 +121,21 @@ * Return propals number by month for a year * * @param int $year Year to scan - * @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month + * @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month * @return array Array with number by month */ - public function getNbByMonth($year, $format = 0) + public function getNbByMonth($year, $format = 0) { global $user; $sql = "SELECT date_format(".$this->field_date.",'%m') as dm, COUNT(*) as nb"; $sql .= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql .= $this->join; + $sql .= $this->join; $sql .= " WHERE ".$this->field_date." BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); $res = $this->_getNbByMonth($year, $sql, $format); return $res; @@ -147,17 +147,17 @@ * @return array Array with number by year * */ - public function getNbByYear() + public function getNbByYear() { global $user; $sql = "SELECT date_format(".$this->field_date.",'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")"; $sql .= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql .= $this->join; + $sql .= $this->join; $sql .= " WHERE ".$this->where; $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); return $this->_getNbByYear($sql); } @@ -166,21 +166,21 @@ * Return the propals amount by month for a year * * @param int $year Year to scan - * @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month + * @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month * @return array Array with amount by month */ - public function getAmountByMonth($year, $format) + public function getAmountByMonth($year, $format) { global $user; $sql = "SELECT date_format(".$this->field_date.",'%m') as dm, SUM(p.".$this->field.")"; $sql .= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql .= $this->join; + $sql .= $this->join; $sql .= " WHERE ".$this->field_date." BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); $res = $this->_getAmountByMonth($year, $sql, $format); return $res; @@ -192,18 +192,18 @@ * @param int $year year for stats * @return array array with number by month */ - public function getAverageByMonth($year) + public function getAverageByMonth($year) { global $user; $sql = "SELECT date_format(".$this->field_date.",'%m') as dm, AVG(p.".$this->field.")"; $sql .= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql .= $this->join; + $sql .= $this->join; $sql .= " WHERE ".$this->field_date." BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); return $this->_getAverageByMonth($year, $sql); } @@ -213,17 +213,17 @@ * * @return array Array of values */ - public function getAllByYear() + public function getAllByYear() { global $user; $sql = "SELECT date_format(".$this->field_date.",'%Y') as year, COUNT(*) as nb, SUM(".$this->field.") as total, AVG(".$this->field.") as avg"; $sql .= " FROM ".$this->from; if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql .= $this->join; + $sql .= $this->join; $sql .= " WHERE ".$this->where; $sql .= " GROUP BY year"; - $sql .= $this->db->order('year', 'DESC'); + $sql .= $this->db->order('year', 'DESC'); return $this->_getAllByYear($sql); } @@ -234,23 +234,23 @@ * Return nb, amount of predefined product for year * * @param int $year Year to scan - * @param int $limit Limit + * @param int $limit Limit * @return array Array of values */ - public function getAllByProduct($year, $limit = 10) + public function getAllByProduct($year, $limit = 10) { global $user; $sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.") as total, AVG(tl.".$this->field_line.") as avg"; $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; + $sql .= $this->join; $sql .= " WHERE ".$this->where; $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))."'"; + $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 .= " GROUP BY product.ref"; - $sql .= $this->db->order('nb', 'DESC'); - //$sql.= $this->db->plimit(20); + $sql .= $this->db->order('nb', 'DESC'); + //$sql.= $this->db->plimit(20); return $this->_getAllByProduct($sql, $limit); }