--- /tmp/dsg/dolibarr/htdocs/don/class/github_19.0.3_api_donations.class.php +++ /tmp/dsg/dolibarr/htdocs/don/class/client_api_donations.class.php @@ -19,3 +19,3 @@ -use Luracast\Restler\RestException; - -require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; + use Luracast\Restler\RestException; + + require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php'; @@ -31,34 +31,35 @@ - /** - * @var array $FIELDS Mandatory fields, checked when create and update object - */ - public static $FIELDS = array( - 'amount' - ); - - /** - * @var Don $don {@type Don} - */ - public $don; - - /** - * Constructor - */ - public function __construct() - { - global $db, $conf; - $this->db = $db; - $this->don = new Don($this->db); - } - - /** - * Get properties of an donation object - * - * Return an array with donation informations - * - * @param int $id ID of order - * @return Object Object with cleaned properties - * - * @throws RestException - */ - public function get($id) - { + + /** + * @var array $FIELDS Mandatory fields, checked when create and update object + */ + static $FIELDS = array( + 'socid' + ); + + /** + * @var Don $don {@type Don} + */ + public $don; + + /** + * Constructor + */ + public function __construct() + { + global $db, $conf; + $this->db = $db; + $this->don = new Don($this->db); + } + + /** + * Get properties of an donation object + * + * Return an array with donation informations + * + * @param int $id ID of order + * @return array|mixed data without useless information + * + * @throws RestException + */ + public function get($id) + { @@ -69,4 +70,4 @@ - $result = $this->don->fetch($id); - if (!$result) { - throw new RestException(404, 'Donation not found'); - } + $result = $this->don->fetch($id); + if (!$result) { + throw new RestException(404, 'Donation not found'); + } @@ -86,21 +87,127 @@ - /** - * List donations - * - * Get a list of donations - * - * @param string $sortfield Sort field - * @param string $sortorder Sort order - * @param int $limit Limit for list - * @param int $page Page number - * @param string $thirdparty_ids Thirdparty ids to filter orders of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i} - * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" - * @param string $properties Restrict the data returned to theses properties. Ignored if empty. Comma separated list of properties names - * @return array Array of order objects - * - * @throws RestException - */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '', $properties = '') - { - global $db, $conf; - - if (!DolibarrApiAccess::$user->rights->don->lire) { + /** + * List donations + * + * Get a list of donations + * + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * @param string $thirdparty_ids Thirdparty ids to filter orders of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i} + * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" + * @return array Array of order objects + * + * @throws RestException + */ + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '') + { + global $db, $conf; + + $obj_ret = array(); + + // case of external user, $thirdparty_ids param is ignored and replaced by user's socid + $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids; + + $sql = "SELECT t.rowid"; + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids)) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) + $sql .= " FROM ".MAIN_DB_PREFIX."don as t"; + + $sql .= ' WHERE t.entity IN ('.getEntity('don').')'; + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids)) $sql .= " AND t.fk_soc = sc.fk_soc"; + if ($thirdparty_ids) $sql .= " AND t.fk_soc = ".$thirdparty_ids." "; + + // Add sql filters + if ($sqlfilters) + { + if (!DolibarrApi::_checkFilters($sqlfilters)) + { + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); + } + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; + } + + $sql .= $db->order($sortfield, $sortorder); + if ($limit) { + if ($page < 0) + { + $page = 0; + } + $offset = $limit * $page; + + $sql .= $db->plimit($limit + 1, $offset); + } + + dol_syslog("API Rest request"); + $result = $db->query($sql); + + if ($result) + { + $num = $db->num_rows($result); + $min = min($num, ($limit <= 0 ? $num : $limit)); + $i = 0; + while ($i < $min) + { + $obj = $db->fetch_object($result); + $don_static = new Don($db); + if ($don_static->fetch($obj->rowid)) { + // Add external contacts ids + //$don_static->contacts_ids = $don_static->liste_contact(-1, 'external', 1); + $obj_ret[] = $this->_cleanObjectDatas($don_static); + } + $i++; + } + } + else { + throw new RestException(503, 'Error when retrieve donation list : '.$db->lasterror()); + } + if (!count($obj_ret)) { + throw new RestException(404, 'No donation found'); + } + + return $obj_ret; + } + + /** + * Create donation object + * + * @param array $request_data Request data + * @return int ID of order + */ + public function post($request_data = null) + { + if (!DolibarrApiAccess::$user->rights->don->creer) { + throw new RestException(401, "Insuffisant rights"); + } + // Check mandatory fields + $result = $this->_validate($request_data); + + foreach ($request_data as $field => $value) { + $this->don->$field = $value; + } + /*if (isset($request_data["lines"])) { + $lines = array(); + foreach ($request_data["lines"] as $line) { + array_push($lines, (object) $line); + } + $this->don->lines = $lines; + }*/ + + if ($this->don->create(DolibarrApiAccess::$user) < 0) { + throw new RestException(500, "Error creating order", array_merge(array($this->don->error), $this->don->errors)); + } + + return $this->don->id; + } + + /** + * Update order general fields (won't touch lines of order) + * + * @param int $id Id of order to update + * @param array $request_data Datas + * + * @return int + */ + public function put($id, $request_data = null) + { + if (!DolibarrApiAccess::$user->rights->don->creer) { @@ -110,119 +217,4 @@ - $obj_ret = array(); - - // case of external user, $thirdparty_ids param is ignored and replaced by user's socid - $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids; - - $sql = "SELECT t.rowid"; - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids)) { - $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) - } - $sql .= " FROM ".MAIN_DB_PREFIX."don AS t LEFT JOIN ".MAIN_DB_PREFIX."don_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields - - $sql .= ' WHERE t.entity IN ('.getEntity('don').')'; - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids)) { - $sql .= " AND t.fk_soc = sc.fk_soc"; - } - if ($thirdparty_ids) { - $sql .= " AND t.fk_soc = ".((int) $thirdparty_ids)." "; - } - - // Add sql filters - if ($sqlfilters) { - $errormessage = ''; - $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage); - if ($errormessage) { - throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage); - } - } - - $sql .= $this->db->order($sortfield, $sortorder); - if ($limit) { - if ($page < 0) { - $page = 0; - } - $offset = $limit * $page; - - $sql .= $this->db->plimit($limit + 1, $offset); - } - - dol_syslog("API Rest request"); - $result = $this->db->query($sql); - - if ($result) { - $num = $this->db->num_rows($result); - $min = min($num, ($limit <= 0 ? $num : $limit)); - $i = 0; - while ($i < $min) { - $obj = $this->db->fetch_object($result); - $don_static = new Don($this->db); - if ($don_static->fetch($obj->rowid)) { - // Add external contacts ids - //$don_static->contacts_ids = $don_static->liste_contact(-1, 'external', 1); - $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($don_static), $properties); - } - $i++; - } - } else { - throw new RestException(503, 'Error when retrieve donation list : '.$this->db->lasterror()); - } - - return $obj_ret; - } - - /** - * Create donation object - * - * @param array $request_data Request data - * @return int ID of order - */ - public function post($request_data = null) - { - if (!DolibarrApiAccess::$user->rights->don->creer) { - throw new RestException(401, "Insuffisant rights"); - } - - // Check mandatory fields - $result = $this->_validate($request_data); - - foreach ($request_data as $field => $value) { - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $this->don->context['caller'] = $request_data['caller']; - continue; - } - - $this->don->$field = $value; - } - /*if (isset($request_data["lines"])) { - $lines = array(); - foreach ($request_data["lines"] as $line) { - array_push($lines, (object) $line); - } - $this->don->lines = $lines; - }*/ - - if ($this->don->create(DolibarrApiAccess::$user) < 0) { - throw new RestException(500, "Error creating donation", array_merge(array($this->don->error), $this->don->errors)); - } - - return $this->don->id; - } - - /** - * Update order general fields (won't touch lines of order) - * - * @param int $id Id of order to update - * @param array $request_data Datas - * - * @return int - */ - public function put($id, $request_data = null) - { - if (!DolibarrApiAccess::$user->rights->don->creer) { - throw new RestException(401); - } - - $result = $this->don->fetch($id); - if (!$result) { - throw new RestException(404, 'Donation not found'); - } + $result = $this->don->fetch($id); + if (!$result) { + throw new RestException(404, 'Donation not found'); + } @@ -233,29 +225,24 @@ - foreach ($request_data as $field => $value) { - if ($field == 'id') { - continue; - } - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $this->don->context['caller'] = $request_data['caller']; - continue; - } - - $this->don->$field = $value; - } - - if ($this->don->update(DolibarrApiAccess::$user) > 0) { - return $this->get($id); - } else { - throw new RestException(500, $this->don->error); - } - } - - /** - * Delete donation - * - * @param int $id Order ID - * @return array - */ - public function delete($id) - { - if (!DolibarrApiAccess::$user->rights->don->supprimer) { + foreach ($request_data as $field => $value) { + if ($field == 'id') continue; + $this->don->$field = $value; + } + + if ($this->don->update(DolibarrApiAccess::$user) > 0) + { + return $this->get($id); + } + else + { + throw new RestException(500, $this->don->error); + } + } + + /** + * Delete donation + * + * @param int $id Order ID + * @return array + */ + public function delete($id) + { + if (!DolibarrApiAccess::$user->rights->don->supprimer) { @@ -264,5 +251,4 @@ - - $result = $this->don->fetch($id); - if (!$result) { - throw new RestException(404, 'Donation not found'); - } + $result = $this->don->fetch($id); + if (!$result) { + throw new RestException(404, 'Donation not found'); + } @@ -274,15 +260,15 @@ - if (!$this->don->delete(DolibarrApiAccess::$user)) { - throw new RestException(500, 'Error when delete donation : '.$this->don->error); - } - - return array( - 'success' => array( - 'code' => 200, - 'message' => 'Donation deleted' - ) - ); - } - - /** - * Validate an donation - * + if (!$this->don->delete(DolibarrApiAccess::$user)) { + throw new RestException(500, 'Error when delete donation : '.$this->don->error); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'Donation deleted' + ) + ); + } + + /** + * Validate an donation + * @@ -290,11 +276,11 @@ - * { - * "idwarehouse": 0, - * "notrigger": 0 - * } - * - * @param int $id Order ID - * @param int $idwarehouse Warehouse ID - * @param int $notrigger 1=Does not execute triggers, 0= execute triggers - * - * @url POST {id}/validate - * + * { + * "idwarehouse": 0, + * "notrigger": 0 + * } + * + * @param int $id Order ID + * @param int $idwarehouse Warehouse ID + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers + * + * @url POST {id}/validate + * @@ -302,9 +288,9 @@ - * @throws RestException 401 - * @throws RestException 404 - * @throws RestException 500 System error - * - * @return object - */ - public function validate($id, $idwarehouse = 0, $notrigger = 0) - { - if (!DolibarrApiAccess::$user->rights->don->creer) { + * @throws RestException 401 + * @throws RestException 404 + * @throws RestException 500 + * + * @return array + */ + public function validate($id, $idwarehouse = 0, $notrigger = 0) + { + if (!DolibarrApiAccess::$user->rights->don->creer) { @@ -313,5 +299,4 @@ - - $result = $this->don->fetch($id); - if (!$result) { - throw new RestException(404, 'Donation not found'); - } + $result = $this->don->fetch($id); + if (!$result) { + throw new RestException(404, 'Donation not found'); + } @@ -323 +308 @@ - $result = $this->don->valid_promesse($id, DolibarrApiAccess::$user->id, $notrigger); + $result = $this->don->valid(DolibarrApiAccess::$user, $idwarehouse, $notrigger); @@ -325 +310 @@ - throw new RestException(304, 'Error nothing done. May be object is already validated'); + throw new RestException(304, 'Error nothing done. May be object is already validated'); @@ -328,56 +313,55 @@ - throw new RestException(500, 'Error when validating Order: '.$this->don->error); - } - $result = $this->don->fetch($id); - if (!$result) { - throw new RestException(404, 'Order not found'); - } - - if (!DolibarrApi::_checkAccessToResource('don', $this->don->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $this->don->fetchObjectLinked(); - - return $this->_cleanObjectDatas($this->don); - } - - // 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->address); - unset($object->barcode_type); - unset($object->barcode_type_code); - unset($object->barcode_type_label); - unset($object->barcode_type_coder); - - return $object; - } - - /** - * Validate fields before create or update object - * - * @param array $data Array with data to verify - * @return array - * @throws RestException - */ - private function _validate($data) - { - $don = array(); - foreach (Donations::$FIELDS as $field) { - if (!isset($data[$field])) { - throw new RestException(400, $field." field missing"); - } - $don[$field] = $data[$field]; - } - return $don; - } + throw new RestException(500, 'Error when validating Order: '.$this->don->error); + } + $result = $this->don->fetch($id); + if (!$result) { + throw new RestException(404, 'Order not found'); + } + + if (!DolibarrApi::_checkAccessToResource('don', $this->don->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $this->don->fetchObjectLinked(); + + return $this->_cleanObjectDatas($this->don); + } + + // 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->address); + unset($object->barcode_type); + unset($object->barcode_type_code); + unset($object->barcode_type_label); + unset($object->barcode_type_coder); + + return $object; + } + + /** + * Validate fields before create or update object + * + * @param array $data Array with data to verify + * @return array + * @throws RestException + */ + private function _validate($data) + { + $don = array(); + foreach (Orders::$FIELDS as $field) { + if (!isset($data[$field])) + throw new RestException(400, $field." field missing"); + $don[$field] = $data[$field]; + } + return $don; + } --- /tmp/dsg/dolibarr/htdocs/don/class/github_19.0.3_don.class.php +++ /tmp/dsg/dolibarr/htdocs/don/class/client_don.class.php @@ -9,2 +9 @@ - * Copyright (C) 2019-2020 Frédéric France - * Copyright (C) 2021 Maxime DEMAREST + * Copyright (C) 2019 Frédéric France @@ -33 +31,0 @@ -require_once DOL_DOCUMENT_ROOT.'/core/class/commonpeople.class.php'; @@ -41 +39,9 @@ - use CommonPeople; + /** + * @var string ID to identify managed object + */ + public $element = 'don'; + + /** + * @var string Name of table without prefix where object is stored + */ + public $table_element = 'don'; @@ -44,11 +50 @@ - * @var string ID to identify managed object - */ - public $element = 'don'; - - /** - * @var string Name of table without prefix where object is stored - */ - public $table_element = 'don'; - - /** - * @var string Field with ID of parent key if this field has a parent + * @var int Field with ID of parent key if this field has a parent @@ -64 +60 @@ - /** + /** @@ -72,17 +68,9 @@ - public $date; - - public $datec; - public $datem; - - /** - * amount of donation - * @var double - */ - public $amount; - - /** - * @var integer Thirdparty ID - */ - public $socid; - - /** + public $date; + + /** + * amount of donation + * @var double + */ + public $amount; + + /** @@ -91,3 +79,3 @@ - public $societe; - - /** + public $societe; + + /** @@ -98 +86 @@ - /** + /** @@ -101,3 +89,3 @@ - public $zip; - - /** + public $zip; + + /** @@ -106,3 +94,3 @@ - public $town; - - /** + public $town; + + /** @@ -111,30 +99,12 @@ - public $email; - - public $phone; - public $phone_mobile; - - - /** - * @var string - */ - public $mode_reglement; - - /** - * @var string - */ - public $mode_reglement_code; - - /** - * @var int 0 or 1 - */ - public $public; - - /** - * @var int project ID - */ - public $fk_project; - - /** - * @var int type payment ID - */ - public $fk_typepayment; + public $email; + public $public; + + /** + * @var int project ID + */ + public $fk_project; + + /** + * @var int type payment ID + */ + public $fk_typepayment; @@ -144,4 +113,0 @@ - - /** - * @var int payment mode id - */ @@ -150,4 +116 @@ - public $paid; - - - /** + /** @@ -158 +121 @@ - /** + /** @@ -170,203 +133,217 @@ - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - public function __construct($db) - { - $this->db = $db; - } - - - /** - * Returns the donation status label (draft, valid, abandoned, paid) - * - * @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 of status - */ - public function getLibStatut($mode = 0) - { - return $this->LibStatut($this->statut, $mode); - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Return the label of a given status - * - * @param int $status Id statut - * @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 of status - */ - public function LibStatut($status, $mode = 0) - { - // phpcs:enable - if (empty($this->labelStatus) || empty($this->labelStatusShort)) { - global $langs; - $langs->load("donations"); - $this->labelStatus[-1] = $langs->transnoentitiesnoconv("Canceled"); - $this->labelStatus[0] = $langs->transnoentitiesnoconv("DonationStatusPromiseNotValidated"); - $this->labelStatus[1] = $langs->transnoentitiesnoconv("DonationStatusPromiseValidated"); - $this->labelStatus[2] = $langs->transnoentitiesnoconv("DonationStatusPaid"); - $this->labelStatusShort[-1] = $langs->transnoentitiesnoconv("Canceled"); - $this->labelStatusShort[0] = $langs->transnoentitiesnoconv("DonationStatusPromiseNotValidatedShort"); - $this->labelStatusShort[1] = $langs->transnoentitiesnoconv("DonationStatusPromiseValidatedShort"); - $this->labelStatusShort[2] = $langs->transnoentitiesnoconv("DonationStatusPaidShort"); - } - - $statusType = 'status'.$status; - if ($status == self::STATUS_CANCELED) { - $statusType = 'status9'; - } - if ($status == self::STATUS_PAID) { - $statusType = 'status6'; - } - - return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); - } - - - /** - * Initialise an instance with random values. - * Used to build previews or test instances. - * id must be 0 if object instance is a specimen. - * - * @return void - */ - public function initAsSpecimen() - { - global $conf; - - $now = dol_now(); - - // Charge tableau des id de societe socids - $socids = array(); - - $sql = "SELECT rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe"; - $sql .= " WHERE client IN (1, 3)"; - $sql .= " AND entity = ".$conf->entity; - $sql .= " LIMIT 10"; - - $resql = $this->db->query($sql); - if ($resql) { - $num_socs = $this->db->num_rows($resql); - $i = 0; - while ($i < $num_socs) { - $row = $this->db->fetch_row($resql); - $socids[$i] = $row[0]; - - $i++; - } - } - - // Initialise parametres - $this->id = 0; - $this->ref = 'SPECIMEN'; - $this->specimen = 1; - $this->lastname = 'Doe'; - $this->firstname = 'John'; - $this->socid = empty($socids[0]) ? 0 : $socids[0]; - $this->date = $now; - $this->date_valid = $now; - $this->amount = 100.90; - $this->public = 1; - $this->societe = 'The Company'; - $this->address = 'Twist road'; - $this->zip = '99999'; - $this->town = 'Town'; - $this->note_private = 'Private note'; - $this->note_public = 'Public note'; - $this->email = 'email@email.com'; - $this->phone = '0123456789'; - $this->phone_mobile = '0606060606'; - $this->statut = 1; - } - - - /** - * Check params and init ->errors array. - * TODO This function seems to not be used by core code. - * - * @param int $minimum Minimum - * @return int 0 if KO, >0 if OK - */ - public function check($minimum = 0) - { - global $langs; - $langs->load('main'); - $langs->load('companies'); - - $error_string = array(); - $err = 0; - - if (dol_strlen(trim($this->societe)) == 0) { - if ((dol_strlen(trim($this->lastname)) + dol_strlen(trim($this->firstname))) == 0) { - $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Company').'/'.$langs->transnoentitiesnoconv('Firstname').'-'.$langs->transnoentitiesnoconv('Lastname')); - $err++; - } - } - - if (dol_strlen(trim($this->address)) == 0) { - $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Address')); - $err++; - } - - if (dol_strlen(trim($this->zip)) == 0) { - $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Zip')); - $err++; - } - - if (dol_strlen(trim($this->town)) == 0) { - $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Town')); - $err++; - } - - if (dol_strlen(trim($this->email)) == 0) { - $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('EMail')); - $err++; - } - - $this->amount = trim($this->amount); - - $map = range(0, 9); - $len = dol_strlen($this->amount); - for ($i = 0; $i < $len; $i++) { - if (!isset($map[substr($this->amount, $i, 1)])) { - $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Amount')); - $err++; - $amount_invalid = 1; - break; - } - } - - if (!$amount_invalid) { - if ($this->amount == 0) { - $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Amount')); - $err++; - } else { - if ($this->amount < $minimum && $minimum > 0) { - $error_string[] = $langs->trans('MinimumAmount', $langs->transnoentitiesnoconv('$minimum')); - $err++; - } - } - } - - if ($err) { - $this->errors = $error_string; - return 0; - } else { - return 1; - } - } - - /** - * Create donation record into database - * - * @param User $user User who created the donation - * @param int $notrigger Disable triggers - * @return int Return integer <0 if KO, id of created donation if OK - * TODO add numbering module for Ref - */ - public function create($user, $notrigger = 0) - { - global $conf, $langs; + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + } + + + /** + * Returns the donation status label (draft, valid, abandoned, paid) + * + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long + * @return string Libelle + */ + public function getLibStatut($mode = 0) + { + return $this->LibStatut($this->statut, $mode); + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Return the label of a given status + * + * @param int $status Id statut + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Libelle du statut + */ + public function LibStatut($status, $mode = 0) + { + // phpcs:enable + if (empty($this->labelStatus) || empty($this->labelStatusShort)) + { + global $langs; + $langs->load("donations"); + $this->labelStatus[-1] = $langs->trans("Canceled"); + $this->labelStatus[0] = $langs->trans("DonationStatusPromiseNotValidated"); + $this->labelStatus[1] = $langs->trans("DonationStatusPromiseValidated"); + $this->labelStatus[2] = $langs->trans("DonationStatusPaid"); + $this->labelStatusShort[-1] = $langs->trans("Canceled"); + $this->labelStatusShort[0] = $langs->trans("DonationStatusPromiseNotValidatedShort"); + $this->labelStatusShort[1] = $langs->trans("DonationStatusPromiseValidatedShort"); + $this->labelStatusShort[2] = $langs->trans("DonationStatusPaidShort"); + } + + $statusType = 'status'.$status; + if ($status == self::STATUS_CANCELED) $statusType = 'status9'; + if ($status == self::STATUS_PAID) $statusType = 'status6'; + + return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); + } + + + /** + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void + */ + public function initAsSpecimen() + { + global $conf, $user, $langs; + + $now = dol_now(); + + // Charge tableau des id de societe socids + $socids = array(); + + $sql = "SELECT rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe"; + $sql .= " WHERE client IN (1, 3)"; + $sql .= " AND entity = ".$conf->entity; + $sql .= " LIMIT 10"; + + $resql = $this->db->query($sql); + if ($resql) + { + $num_socs = $this->db->num_rows($resql); + $i = 0; + while ($i < $num_socs) + { + $i++; + + $row = $this->db->fetch_row($resql); + $socids[$i] = $row[0]; + } + } + + // Initialise parametres + $this->id = 0; + $this->ref = 'SPECIMEN'; + $this->specimen = 1; + $this->lastname = 'Doe'; + $this->firstname = 'John'; + $this->socid = 1; + $this->date = $now; + $this->date_valid = $now; + $this->amount = 100; + $this->public = 1; + $this->societe = 'The Company'; + $this->address = 'Twist road'; + $this->zip = '99999'; + $this->town = 'Town'; + $this->note_private = 'Private note'; + $this->note_public = 'Public note'; + $this->email = 'email@email.com'; + $this->note = ''; + $this->statut = 1; + } + + + /** + * Check params and init ->errors array. + * TODO This function seems to not be used by core code. + * + * @param int $minimum Minimum + * @return int 0 if KO, >0 if OK + */ + public function check($minimum = 0) + { + global $langs; + $langs->load('main'); + $langs->load('companies'); + + $error_string = array(); + $err = 0; + + if (dol_strlen(trim($this->societe)) == 0) + { + if ((dol_strlen(trim($this->lastname)) + dol_strlen(trim($this->firstname))) == 0) + { + $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Company').'/'.$langs->transnoentitiesnoconv('Firstname').'-'.$langs->transnoentitiesnoconv('Lastname')); + $err++; + } + } + + if (dol_strlen(trim($this->address)) == 0) + { + $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Address')); + $err++; + } + + if (dol_strlen(trim($this->zip)) == 0) + { + $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Zip')); + $err++; + } + + if (dol_strlen(trim($this->town)) == 0) + { + $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Town')); + $err++; + } + + if (dol_strlen(trim($this->email)) == 0) + { + $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('EMail')); + $err++; + } + + $this->amount = trim($this->amount); + + $map = range(0, 9); + $len = dol_strlen($this->amount); + for ($i = 0; $i < $len; $i++) + { + if (!isset($map[substr($this->amount, $i, 1)])) + { + $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Amount')); + $err++; + $amount_invalid = 1; + break; + } + } + + if (!$amount_invalid) + { + if ($this->amount == 0) + { + $error_string[] = $langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Amount')); + $err++; + } + else + { + if ($this->amount < $minimum && $minimum > 0) + { + $error_string[] = $langs->trans('MinimumAmount', $langs->transnoentitiesnoconv('$minimum')); + $err++; + } + } + } + + if ($err) + { + $this->errors = $error_string; + return 0; + } + else + { + return 1; + } + } + + /** + * Create donation record into database + * + * @param User $user User who created the donation + * @param int $notrigger Disable triggers + * @return int <0 if KO, id of created donation if OK + * TODO add numbering module for Ref + */ + public function create($user, $notrigger = 0) + { + global $conf, $langs; @@ -376,57 +353,50 @@ - $now = dol_now(); - - // Clean parameters - $this->address = ($this->address > 0 ? $this->address : $this->address); - $this->zip = ($this->zip > 0 ? $this->zip : $this->zip); - $this->town = ($this->town > 0 ? $this->town : $this->town); - $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id); - $this->country = ($this->country ? $this->country : $this->country); - $this->amount = price2num($this->amount); - - // Check parameters - if ($this->amount < 0) { - $this->error = $langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv("Amount")); - return -1; - } - - $this->db->begin(); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."don ("; - $sql .= "datec"; - $sql .= ", entity"; - $sql .= ", amount"; - $sql .= ", fk_payment"; - $sql .= ", fk_soc"; - $sql .= ", firstname"; - $sql .= ", lastname"; - $sql .= ", societe"; - $sql .= ", address"; - $sql .= ", zip"; - $sql .= ", town"; - $sql .= ", fk_country"; - $sql .= ", public"; - $sql .= ", fk_projet"; - $sql .= ", note_private"; - $sql .= ", note_public"; - $sql .= ", fk_user_author"; - $sql .= ", fk_user_valid"; - $sql .= ", datedon"; - $sql .= ", email"; - $sql .= ", phone"; - $sql .= ", phone_mobile"; - $sql .= ") VALUES ("; - $sql .= "'".$this->db->idate($this->date ? $this->date : $now)."'"; - $sql .= ", ".((int) $conf->entity); - $sql .= ", ".((float) $this->amount); - $sql .= ", ".($this->modepaymentid ? $this->modepaymentid : "null"); - $sql .= ", ".($this->socid > 0 ? $this->socid : "null"); - $sql .= ", '".$this->db->escape($this->firstname)."'"; - $sql .= ", '".$this->db->escape($this->lastname)."'"; - $sql .= ", '".$this->db->escape($this->societe)."'"; - $sql .= ", '".$this->db->escape($this->address)."'"; - $sql .= ", '".$this->db->escape($this->zip)."'"; - $sql .= ", '".$this->db->escape($this->town)."'"; - $sql .= ", ".(int) ($this->country_id > 0 ? $this->country_id : 0); - $sql .= ", ".(int) $this->public; - $sql .= ", ".($this->fk_project > 0 ? (int) $this->fk_project : "null"); - $sql .= ", ".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL"); + $now = dol_now(); + + // Clean parameters + $this->address = ($this->address > 0 ? $this->address : $this->address); + $this->zip = ($this->zip > 0 ? $this->zip : $this->zip); + $this->town = ($this->town > 0 ? $this->town : $this->town); + $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id); + $this->country = ($this->country ? $this->country : $this->country); + + $this->db->begin(); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."don ("; + $sql .= "datec"; + $sql .= ", entity"; + $sql .= ", amount"; + $sql .= ", fk_payment"; + $sql .= ", fk_soc"; + $sql .= ", firstname"; + $sql .= ", lastname"; + $sql .= ", societe"; + $sql .= ", address"; + $sql .= ", zip"; + $sql .= ", town"; + $sql .= ", fk_country"; + $sql .= ", public"; + $sql .= ", fk_projet"; + $sql .= ", note_private"; + $sql .= ", note_public"; + $sql .= ", fk_user_author"; + $sql .= ", fk_user_valid"; + $sql .= ", datedon"; + $sql .= ", email"; + $sql .= ", phone"; + $sql .= ", phone_mobile"; + $sql .= ") VALUES ("; + $sql .= "'".$this->db->idate($now)."'"; + $sql .= ", ".$conf->entity; + $sql .= ", ".price2num($this->amount); + $sql .= ", ".($this->modepaymentid ? $this->modepaymentid : "null"); + $sql .= ", ".($this->socid > 0 ? $this->socid : "null"); + $sql .= ", '".$this->db->escape($this->firstname)."'"; + $sql .= ", '".$this->db->escape($this->lastname)."'"; + $sql .= ", '".$this->db->escape($this->societe)."'"; + $sql .= ", '".$this->db->escape($this->address)."'"; + $sql .= ", '".$this->db->escape($this->zip)."'"; + $sql .= ", '".$this->db->escape($this->town)."'"; + $sql .= ", ".($this->country_id > 0 ? $this->country_id : '0'); + $sql .= ", ".((int) $this->public); + $sql .= ", ".($this->fk_project > 0 ? $this->fk_project : "null"); + $sql .= ", ".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL"); @@ -434,10 +404,11 @@ - $sql .= ", ".((int) $user->id); - $sql .= ", null"; - $sql .= ", '".$this->db->idate($this->date)."'"; - $sql .= ", '".(!empty($this->email) ? $this->db->escape(trim($this->email)) : "")."'"; - $sql .= ", '".(!empty($this->phone) ? $this->db->escape(trim($this->phone)) : "")."'"; - $sql .= ", '".(!empty($this->phone_mobile) ? $this->db->escape(trim($this->phone_mobile)) : "")."'"; - $sql .= ")"; - - $resql = $this->db->query($sql); - if ($resql) { + $sql .= ", ".$user->id; + $sql .= ", null"; + $sql .= ", '".$this->db->idate($this->date)."'"; + $sql .= ", '".$this->db->escape($this->email)."'"; + $sql .= ", '".$this->db->escape($this->phone)."'"; + $sql .= ", '".$this->db->escape($this->phone_mobile)."'"; + $sql .= ")"; + + $resql = $this->db->query($sql); + if ($resql) + { @@ -447 +418,95 @@ - if (!$notrigger) { + if (!$notrigger) + { + // Call trigger + $result = $this->call_trigger('DON_CREATE', $user); + if ($result < 0) { $error++; } + // End call triggers + } + } + else + { + $this->error = $this->db->lasterror(); + $this->errno = $this->db->lasterrno(); + $error++; + } + + // Update extrafield + if (!$error) { + if (!$error) + { + $result = $this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + } + + if (!$error && !empty($conf->global->MAIN_DISABLEDRAFTSTATUS)) + { + //$res = $this->setValid($user); + //if ($res < 0) $error++; + } + + if (!$error) + { + $this->db->commit(); + return $ret; + } + else + { + $this->db->rollback(); + return -1; + } + } + + /** + * Update a donation record + * + * @param User $user Objet utilisateur qui met a jour le don + * @param int $notrigger Disable triggers + * @return int >0 if OK, <0 if KO + */ + public function update($user, $notrigger = 0) + { + global $langs, $conf; + + $error = 0; + + // Clean parameters + $this->address = ($this->address > 0 ? $this->address : $this->address); + $this->zip = ($this->zip > 0 ? $this->zip : $this->zip); + $this->town = ($this->town > 0 ? $this->town : $this->town); + $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id); + $this->country = ($this->country ? $this->country : $this->country); + + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."don SET "; + $sql .= "amount = ".price2num($this->amount); + $sql .= ",fk_payment = ".($this->modepaymentid ? $this->modepaymentid : "null"); + $sql .= ",firstname = '".$this->db->escape($this->firstname)."'"; + $sql .= ",lastname='".$this->db->escape($this->lastname)."'"; + $sql .= ",societe='".$this->db->escape($this->societe)."'"; + $sql .= ",address='".$this->db->escape($this->address)."'"; + $sql .= ",zip='".$this->db->escape($this->zip)."'"; + $sql .= ",town='".$this->db->escape($this->town)."'"; + $sql .= ",fk_country = ".($this->country_id > 0 ? $this->country_id : '0'); + $sql .= ",public=".$this->public; + $sql .= ",fk_projet=".($this->fk_project > 0 ? $this->fk_project : 'null'); + $sql .= ",note_private=".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL"); + $sql .= ",note_public=".(!empty($this->note_public) ? ("'".$this->db->escape($this->note_public)."'") : "NULL"); + $sql .= ",datedon='".$this->db->idate($this->date)."'"; + $sql .= ",date_valid=".($this->date_valid ? "'".$this->db->idate($this->date)."'" : "null"); + $sql .= ",email='".$this->db->escape($this->email)."'"; + $sql .= ",phone='".$this->db->escape($this->phone)."'"; + $sql .= ",phone_mobile='".$this->db->escape($this->phone_mobile)."'"; + $sql .= ",fk_statut=".$this->statut; + $sql .= " WHERE rowid = ".$this->id; + + dol_syslog(get_class($this)."::Update", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + if (!$notrigger) + { @@ -449,118 +514,37 @@ - $result = $this->call_trigger('DON_CREATE', $user); - if ($result < 0) { - $error++; - } - // End call triggers - } - } else { - $this->error = $this->db->lasterror(); - $error++; - } - - // Update extrafield - if (!$error) { - $result = $this->insertExtraFields(); - if ($result < 0) { - $error++; - } - } - - if (!$error && (getDolGlobalString('MAIN_DISABLEDRAFTSTATUS') || getDolGlobalString('MAIN_DISABLEDRAFTSTATUS_DONATION'))) { - //$res = $this->setValid($user); - //if ($res < 0) $error++; - } - - if (!$error) { - $this->db->commit(); - return $ret; - } else { - $this->db->rollback(); - return -1; - } - } - - /** - * Update a donation record - * - * @param User $user Objet utilisateur qui met a jour le don - * @param int $notrigger Disable triggers - * @return int >0 if OK, <0 if KO - */ - public function update($user, $notrigger = 0) - { - global $langs; - - $error = 0; - - // Clean parameters - $this->address = ($this->address > 0 ? $this->address : $this->address); - $this->zip = ($this->zip > 0 ? $this->zip : $this->zip); - $this->town = ($this->town > 0 ? $this->town : $this->town); - $this->country_id = ($this->country_id > 0 ? $this->country_id : $this->country_id); - $this->country = ($this->country ? $this->country : $this->country); - $this->amount = price2num($this->amount); - - // Check parameters - if ($this->amount < 0) { - $this->error = $langs->trans('FieldCannotBeNegative', $langs->transnoentitiesnoconv("Amount")); - return -1; - } - - $this->db->begin(); - - $sql = "UPDATE ".MAIN_DB_PREFIX."don SET"; - $sql .= " amount = ".((float) $this->amount); - $sql .= ", fk_payment = ".($this->modepaymentid ? $this->modepaymentid : "null"); - $sql .= ", firstname = '".$this->db->escape($this->firstname)."'"; - $sql .= ", lastname='".$this->db->escape($this->lastname)."'"; - $sql .= ", societe='".$this->db->escape($this->societe)."'"; - $sql .= ", address='".$this->db->escape($this->address)."'"; - $sql .= ", zip='".$this->db->escape($this->zip)."'"; - $sql .= ", town='".$this->db->escape($this->town)."'"; - $sql .= ", fk_country = ".($this->country_id > 0 ? ((int) $this->country_id) : '0'); - $sql .= ", public=".((int) $this->public); - $sql .= ", fk_projet=".($this->fk_project > 0 ? $this->fk_project : 'null'); - $sql .= ", note_private=".(!empty($this->note_private) ? ("'".$this->db->escape($this->note_private)."'") : "NULL"); - $sql .= ", note_public=".(!empty($this->note_public) ? ("'".$this->db->escape($this->note_public)."'") : "NULL"); - $sql .= ", datedon='".$this->db->idate($this->date)."'"; - $sql .= ", date_valid=".($this->date_valid ? "'".$this->db->idate($this->date)."'" : "null"); - $sql .= ", email='".$this->db->escape(trim($this->email))."'"; - $sql .= ", phone='".$this->db->escape(trim($this->phone))."'"; - $sql .= ", phone_mobile='".$this->db->escape(trim($this->phone_mobile))."'"; - $sql .= ", fk_statut=".((int) $this->statut); - $sql .= " WHERE rowid = ".((int) $this->id); - - dol_syslog(get_class($this)."::Update", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - if (!$notrigger) { - // Call trigger - $result = $this->call_trigger('DON_MODIFY', $user); - if ($result < 0) { - $error++; - } - // End call triggers - } - - // Update extrafield - if (!$error) { - $result = $this->insertExtraFields(); - if ($result < 0) { - $error++; - } - } - - if (!$error) { - $this->db->commit(); - $result = 1; - } else { - $this->db->rollback(); - $result = -1; - } - } else { - $this->error = $this->db->lasterror(); - $this->errors[] = $this->error; - $this->db->rollback(); - dol_syslog(get_class($this)."::Update error -2 ".$this->error, LOG_ERR); - $result = -2; - } + $result = $this->call_trigger('DON_MODIFY', $user); + if ($result < 0) { $error++; } + // End call triggers + } + + // Update extrafield + if (!$error) + { + if (!$error) + { + $result = $this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + } + + if (!$error) + { + $this->db->commit(); + $result = 1; + } + else + { + $this->db->rollback(); + $result = -1; + } + } + else + { + $this->error = $this->db->lasterror(); + $this->errors[] = $this->error; + $this->db->rollback(); + dol_syslog(get_class($this)."::Update error -2 ".$this->error, LOG_ERR); + $result = -2; + } @@ -570,9 +554,10 @@ - /** - * Delete a donation from database - * - * @param User $user User - * @param int $notrigger Disable triggers - * @return int Return integer <0 if KO, 0 if not possible, >0 if OK - */ - public function delete($user, $notrigger = 0) - { + /** + * Delete a donation from database + * + * @param User $user User + * @param int $notrigger Disable triggers + * @return int <0 if KO, 0 if not possible, >0 if OK + */ + public function delete($user, $notrigger = 0) + { + global $user, $conf, $langs; @@ -585,38 +570,50 @@ - if (!$error && !$notrigger) { - // Call trigger - $result = $this->call_trigger('DON_DELETE', $user); - - if ($result < 0) { - $error++; - } - // End call triggers - } - - // Delete donation - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."don_extrafields"; - $sql .= " WHERE fk_object = ".((int) $this->id); - - $resql = $this->db->query($sql); - if (!$resql) { - $this->errors[] = $this->db->lasterror(); - $error++; - } - } - - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."don"; - $sql .= " WHERE rowid=".((int) $this->id); - - $resql = $this->db->query($sql); - if (!$resql) { - $this->errors[] = $this->db->lasterror(); - $error++; - } - } - - if (!$error) { - $this->db->commit(); - return 1; - } else { - foreach ($this->errors as $errmsg) { + if (!$error) + { + if (!$notrigger) + { + // Call trigger + $result = $this->call_trigger('DON_DELETE', $user); + + if ($result < 0) { + $error++; + } + // End call triggers + } + } + + // Delete donation + if (!$error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."don_extrafields"; + $sql .= " WHERE fk_object=".$this->id; + + $resql = $this->db->query($sql); + if (!$resql) + { + $this->errors[] = $this->db->lasterror(); + $error++; + } + } + + if (!$error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."don"; + $sql .= " WHERE rowid=".$this->id; + + $resql = $this->db->query($sql); + if (!$resql) + { + $this->errors[] = $this->db->lasterror(); + $error++; + } + } + + if (!$error) + { + $this->db->commit(); + return 1; + } + else + { + foreach ($this->errors as $errmsg) + { @@ -626,86 +623,95 @@ - dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR); - $this->db->rollback(); - return -1; - } - } - - /** - * Load donation from database - * - * @param int $id Id of donation to load - * @param string $ref Ref of donation to load - * @return int Return integer <0 if KO, >0 if OK - */ - public function fetch($id, $ref = '') - { - $sql = "SELECT d.rowid, d.datec, d.date_valid, d.tms as datem, d.datedon,"; - $sql .= " d.fk_soc as socid, d.firstname, d.lastname, d.societe, d.amount, d.fk_statut as status, d.address, d.zip, d.town, "; - $sql .= " d.fk_country, d.public, d.amount, d.fk_payment, d.paid, d.note_private, d.note_public, d.email, d.phone, "; - $sql .= " d.phone_mobile, d.fk_projet as fk_project, d.model_pdf,"; - $sql .= " p.ref as project_ref,"; - $sql .= " cp.libelle as payment_label, cp.code as payment_code,"; - $sql .= " c.code as country_code, c.label as country"; - $sql .= " FROM ".MAIN_DB_PREFIX."don as d"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = d.fk_projet"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON cp.id = d.fk_payment"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.fk_country = c.rowid"; - $sql .= " WHERE d.entity IN (".getEntity('donation').")"; - if (!empty($id)) { - $sql .= " AND d.rowid=".((int) $id); - } elseif (!empty($ref)) { - $sql .= " AND d.ref='".$this->db->escape($ref)."'"; - } - - dol_syslog(get_class($this)."::fetch", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - if ($this->db->num_rows($resql)) { - $obj = $this->db->fetch_object($resql); - - $this->id = $obj->rowid; - $this->ref = $obj->rowid; - $this->date_creation = $this->db->jdate($obj->datec); - $this->datec = $this->db->jdate($obj->datec); - $this->date_validation = $this->db->jdate($obj->date_valid); - $this->date_valid = $this->db->jdate($obj->date_valid); - $this->date_modification = $this->db->jdate($obj->datem); - $this->datem = $this->db->jdate($obj->datem); - $this->date = $this->db->jdate($obj->datedon); - $this->socid = $obj->socid; - $this->firstname = $obj->firstname; - $this->lastname = $obj->lastname; - $this->societe = $obj->societe; - $this->status = $obj->status; - $this->statut = $obj->status; - $this->address = $obj->address; - $this->zip = $obj->zip; - $this->town = $obj->town; - $this->country_id = $obj->fk_country; - $this->country_code = $obj->country_code; - $this->country = $obj->country; - $this->email = $obj->email; - $this->phone = $obj->phone; - $this->phone_mobile = $obj->phone_mobile; - $this->project = $obj->project_ref; - $this->fk_projet = $obj->fk_project; // deprecated - $this->fk_project = $obj->fk_project; - $this->public = $obj->public; - $this->mode_reglement_id = $obj->fk_payment; - $this->mode_reglement_code = $obj->payment_code; - $this->mode_reglement = $obj->payment_label; - $this->paid = $obj->paid; - $this->amount = $obj->amount; - $this->note_private = $obj->note_private; - $this->note_public = $obj->note_public; - $this->model_pdf = $obj->model_pdf; - - // Retrieve all extrafield - // fetch optionals attributes and labels - $this->fetch_optionals(); - } - return 1; - } else { - dol_print_error($this->db); - return -1; - } - } + dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR); + $this->db->rollback(); + return -1; + } + } + + /** + * Load donation from database + * + * @param int $id Id of donation to load + * @param string $ref Ref of donation to load + * @return int <0 if KO, >0 if OK + */ + public function fetch($id, $ref = '') + { + global $conf; + + $sql = "SELECT d.rowid, d.datec, d.date_valid, d.tms as datem, d.datedon,"; + $sql .= " d.fk_soc as socid,d.firstname, d.lastname, d.societe, d.amount, d.fk_statut, d.address, d.zip, d.town, "; + $sql .= " d.fk_country, d.country as country_olddata, d.public, d.amount, d.fk_payment, d.paid, d.note_private, d.note_public, d.email, d.phone, "; + $sql .= " d.phone_mobile, d.fk_projet as fk_project, d.model_pdf,"; + $sql .= " p.ref as project_ref,"; + $sql .= " cp.libelle as payment_label, cp.code as payment_code,"; + $sql .= " c.code as country_code, c.label as country"; + $sql .= " FROM ".MAIN_DB_PREFIX."don as d"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = d.fk_projet"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON cp.id = d.fk_payment"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.fk_country = c.rowid"; + $sql .= " WHERE d.entity IN (".getEntity('donation').")"; + if (!empty($id)) + { + $sql .= " AND d.rowid=".$id; + } + elseif (!empty($ref)) + { + $sql .= " AND d.ref='".$this->db->escape($ref)."'"; + } + + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + $this->date_creation = $this->db->jdate($obj->datec); + $this->datec = $this->db->jdate($obj->datec); + $this->date_validation = $this->db->jdate($obj->date_valid); + $this->date_valid = $this->db->jdate($obj->date_valid); + $this->date_modification = $this->db->jdate($obj->datem); + $this->datem = $this->db->jdate($obj->datem); + $this->date = $this->db->jdate($obj->datedon); + $this->socid = $obj->socid; + $this->firstname = $obj->firstname; + $this->lastname = $obj->lastname; + $this->societe = $obj->societe; + $this->statut = $obj->fk_statut; + $this->address = $obj->address; + $this->zip = $obj->zip; + $this->town = $obj->town; + $this->country_id = $obj->fk_country; + $this->country_code = $obj->country_code; + $this->country = $obj->country; + $this->country_olddata = $obj->country_olddata; // deprecated + $this->email = $obj->email; + $this->phone = $obj->phone; + $this->phone_mobile = $obj->phone_mobile; + $this->project = $obj->project_ref; + $this->fk_projet = $obj->fk_project; // deprecated + $this->fk_project = $obj->fk_project; + $this->public = $obj->public; + $this->mode_reglement_id = $obj->fk_payment; + $this->mode_reglement_code = $obj->payment_code; + $this->mode_reglement = $obj->payment_label; + $this->paid = $obj->paid; + $this->amount = $obj->amount; + $this->note_private = $obj->note_private; + $this->note_public = $obj->note_public; + $this->modelpdf = $obj->model_pdf; + + // Retreive all extrafield + // fetch optionals attributes and labels + $this->fetch_optionals(); + } + return 1; + } + else + { + dol_print_error($this->db); + return -1; + } + } @@ -715,5 +721,5 @@ - * - * @param User $user User that validate - * @param int $notrigger 1=Does not execute triggers, 0= execute triggers - * @return int Return integer <0 if KO, >0 if OK - */ + * + * @param User $user User that validate + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers + * @return int <0 if KO, >0 if OK + */ @@ -727,8 +733,8 @@ - * Validate a promise of donation - * - * @param int $id id of donation - * @param int $userid User who validate the donation/promise - * @param int $notrigger Disable triggers - * @return int Return integer <0 if KO, >0 if OK - */ - public function valid_promesse($id, $userid, $notrigger = 0) + * Validate a promise of donation + * + * @param int $id id of donation + * @param int $userid User who validate the donation/promise + * @param int $notrigger Disable triggers + * @return int <0 if KO, >0 if OK + */ + public function valid_promesse($id, $userid, $notrigger = 0) @@ -737 +743 @@ - global $user; + global $langs, $user; @@ -743,229 +749,205 @@ - $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 1, fk_user_valid = ".((int) $userid)." WHERE rowid = ".((int) $id)." AND fk_statut = 0"; - - $resql = $this->db->query($sql); - if ($resql) { - if ($this->db->affected_rows($resql)) { - if (!$notrigger) { - // Call trigger - $result = $this->call_trigger('DON_VALIDATE', $user); - if ($result < 0) { - $error++; - } - // End call triggers - } - } - } else { - $error++; - $this->error = $this->db->lasterror(); - } - - if (!$error) { - $this->statut = 1; - $this->db->commit(); - return 1; - } else { - $this->db->rollback(); - return -1; - } - } - - /** - * Classify the donation as paid, the donation was received - * - * @param int $id id of donation - * @param int $modepayment mode of payment - * @return int Return integer <0 if KO, >0 if OK - */ - public function setPaid($id, $modepayment = 0) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 2, paid = 1"; - if ($modepayment) { - $sql .= ", fk_payment = ".((int) $modepayment); - } - $sql .= " WHERE rowid = ".((int) $id)." AND fk_statut = 1"; - - $resql = $this->db->query($sql); - if ($resql) { - if ($this->db->affected_rows($resql)) { - $this->statut = 2; - $this->paid = 1; - return 1; - } else { - return 0; - } - } else { - dol_print_error($this->db); - return -1; - } - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Set donation to status cancelled - * - * @param int $id id of donation - * @return int Return integer <0 if KO, >0 if OK - */ - public function set_cancel($id) - { - // phpcs:enable - $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = -1 WHERE rowid = ".((int) $id); - - $resql = $this->db->query($sql); - if ($resql) { - if ($this->db->affected_rows($resql)) { - $this->statut = -1; - return 1; - } else { - return 0; - } - } else { - dol_print_error($this->db); - return -1; - } - } - - /** - * Set cancel status - * - * @param User $user Object user that modify - * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers - * @return int Return integer <0 if KO, 0=Nothing done, >0 if OK - */ - public function reopen($user, $notrigger = 0) - { - // Protection - if ($this->statut != self::STATUS_CANCELED) { - return 0; - } - - /*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->bom->write)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->bom->bom_advance->validate)))) - { - $this->error='Permission denied'; - return -1; - }*/ - - return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'DON_REOPEN'); - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Sum of donations - * - * @param string $param 1=promesses de dons validees , 2=xxx, 3=encaisses - * @return int Summ of donations - */ - public function sum_donations($param) - { - // phpcs:enable - global $conf; - - $result = 0; - - $sql = "SELECT sum(amount) as total"; - $sql .= " FROM ".MAIN_DB_PREFIX."don"; - $sql .= " WHERE fk_statut = ".((int) $param); - $sql .= " AND entity = ".$conf->entity; - - $resql = $this->db->query($sql); - if ($resql) { - $obj = $this->db->fetch_object($resql); - $result = $obj->total; - } - - return $result; - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Charge indicateurs this->nb pour le tableau de bord - * - * @return int Return integer <0 if KO, >0 if OK - */ - public function load_state_board() - { - // phpcs:enable - $this->nb = array(); - - $sql = "SELECT count(d.rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."don as d"; - $sql .= " WHERE d.fk_statut > 0"; - $sql .= " AND d.entity IN (".getEntity('donation').")"; - - $resql = $this->db->query($sql); - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { - $this->nb["donations"] = $obj->nb; - } - $this->db->free($resql); - return 1; - } else { - dol_print_error($this->db); - $this->error = $this->db->error(); - return -1; - } - } - - /** - * Return clicable name (with picto eventually) - * - * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto - * @param int $notooltip 1=Disable tooltip - * @param string $moretitle Add more text to title tooltip - * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking - * @return string Chaine avec URL - */ - public function getNomUrl($withpicto = 0, $notooltip = 0, $moretitle = '', $save_lastsearch_value = -1) - { - global $conf, $langs, $hookmanager; - - if (!empty($conf->dol_no_mouse_hover)) { - $notooltip = 1; // Force disable tooltips - } - - $result = ''; - $label = img_picto('', $this->picto).' '.$langs->trans("Donation").''; - if (isset($this->status)) { - $label .= ' '.$this->getLibStatut(5); - } - if (!empty($this->id)) { - $label .= '
'.$langs->trans('Ref').': '.$this->id; - $label .= '
'.$langs->trans('Date').': '.dol_print_date($this->date, 'day'); - } - if ($moretitle) { - $label .= ' - '.$moretitle; - } - - $url = DOL_URL_ROOT.'/don/card.php?id='.$this->id; - - $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { - $add_save_lastsearch_values = 1; - } - if ($add_save_lastsearch_values) { - $url .= '&save_lastsearch_values=1'; - } - - $linkstart = ''; - $linkend = ''; - - $result .= $linkstart; - if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - } - if ($withpicto != 2) { - $result .= $this->ref; - } - $result .= $linkend; - global $action; - $hookmanager->initHooks(array($this->element . 'dao')); - $parameters = array('id'=>$this->id, 'getnomurl' => &$result); - $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook > 0) { - $result = $hookmanager->resPrint; - } else { - $result .= $hookmanager->resPrint; - } - return $result; - } + $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 1, fk_user_valid = ".$userid." WHERE rowid = ".$id." AND fk_statut = 0"; + + $resql = $this->db->query($sql); + if ($resql) + { + if ($this->db->affected_rows($resql)) + { + if (!$notrigger) + { + // Call trigger + $result = $this->call_trigger('DON_VALIDATE', $user); + if ($result < 0) { $error++; } + // End call triggers + } + } + } + else + { + $error++; + $this->error = $this->db->lasterror(); + } + + if (!$error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Classify the donation as paid, the donation was received + * + * @param int $id id of donation + * @param int $modepayment mode of payment + * @return int <0 if KO, >0 if OK + */ + public function set_paid($id, $modepayment = 0) + { + // phpcs:enable + $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 2"; + if ($modepayment) + { + $sql .= ", fk_payment=".$modepayment; + } + $sql .= " WHERE rowid = ".$id." AND fk_statut = 1"; + + $resql = $this->db->query($sql); + if ($resql) + { + if ($this->db->affected_rows($resql)) + { + return 1; + } + else + { + return 0; + } + } + else + { + dol_print_error($this->db); + return -1; + } + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Set donation to status cancelled + * + * @param int $id id of donation + * @return int <0 if KO, >0 if OK + */ + public function set_cancel($id) + { + // phpcs:enable + $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = -1 WHERE rowid = ".$id; + + $resql = $this->db->query($sql); + if ($resql) + { + if ($this->db->affected_rows($resql)) + { + return 1; + } + else + { + return 0; + } + } + else + { + dol_print_error($this->db); + return -1; + } + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Sum of donations + * + * @param string $param 1=promesses de dons validees , 2=xxx, 3=encaisses + * @return int Summ of donations + */ + public function sum_donations($param) + { + // phpcs:enable + global $conf; + + $result = 0; + + $sql = "SELECT sum(amount) as total"; + $sql .= " FROM ".MAIN_DB_PREFIX."don"; + $sql .= " WHERE fk_statut = ".$param; + $sql .= " AND entity = ".$conf->entity; + + $resql = $this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + $result = $obj->total; + } + + return $result; + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Charge indicateurs this->nb pour le tableau de bord + * + * @return int <0 if KO, >0 if OK + */ + public function load_state_board() + { + // phpcs:enable + global $conf; + + $this->nb = array(); + + $sql = "SELECT count(d.rowid) as nb"; + $sql .= " FROM ".MAIN_DB_PREFIX."don as d"; + $sql .= " WHERE d.fk_statut > 0"; + $sql .= " AND d.entity IN (".getEntity('donation').")"; + + $resql = $this->db->query($sql); + if ($resql) + { + while ($obj = $this->db->fetch_object($resql)) + { + $this->nb["donations"] = $obj->nb; + } + $this->db->free($resql); + return 1; + } + else + { + dol_print_error($this->db); + $this->error = $this->db->error(); + return -1; + } + } + + /** + * Return clicable name (with picto eventually) + * + * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto + * @param int $notooltip 1=Disable tooltip + * @param string $moretitle Add more text to title tooltip + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @return string Chaine avec URL + */ + public function getNomUrl($withpicto = 0, $notooltip = 0, $moretitle = '', $save_lastsearch_value = -1) + { + global $conf, $langs; + + if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips + + $result = ''; + $label = ''.$langs->trans("Donation").''; + if (!empty($this->id)) { + $label .= '
'.$langs->trans('Ref').': '.$this->id; + } + if ($moretitle) $label .= ' - '.$moretitle; + + $url = DOL_URL_ROOT.'/don/card.php?id='.$this->id; + + $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; + + $linkstart = ''; + $linkend = ''; + + $result .= $linkstart; + if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + if ($withpicto != 2) $result .= $this->ref; + $result .= $linkend; + + return $result; + } @@ -982 +964 @@ - $sql .= ' d.tms as datem'; + $sql .= ' d.tms'; @@ -984 +966 @@ - $sql .= ' WHERE d.rowid = '.((int) $id); + $sql .= ' WHERE d.rowid = '.$id; @@ -989,2 +971,4 @@ - if ($result) { - if ($this->db->num_rows($result)) { + if ($result) + { + if ($this->db->num_rows($result)) + { @@ -993,3 +977,12 @@ - - $this->user_creation_id = $obj->fk_user_author; - $this->user_validation_id = $obj->fk_user_valid; + if ($obj->fk_user_author) + { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_author); + $this->user_creation = $cuser; + } + if ($obj->fk_user_valid) + { + $vuser = new User($this->db); + $vuser->fetch($obj->fk_user_valid); + $this->user_modification = $vuser; + } @@ -997 +990 @@ - $this->date_modification = (!empty($obj->tms) ? $this->db->jdate($obj->tms) : ""); + $this->date_modification = $this->db->jdate($obj->tms); @@ -1000 +993,3 @@ - } else { + } + else + { @@ -1025,3 +1020,3 @@ - if ($this->model_pdf) { - $modele = $this->model_pdf; - } elseif (getDolGlobalString('DON_ADDON_MODEL')) { + if ($this->modelpdf) { + $modele = $this->modelpdf; + } elseif (!empty($conf->global->DON_ADDON_MODEL)) { @@ -1032 +1027 @@ - //$modelpath = "core/modules/dons/"; + $modelpath = "core/modules/dons/"; @@ -1047 +1042,2 @@ - if (!empty($tmp[1])) { + if (!empty($tmp[1])) + { @@ -1053,3 +1049 @@ - $file = ''; - $classname = ''; - $filefound = 0; + $file = ''; $classname = ''; $filefound = 0; @@ -1057,5 +1051,5 @@ - if (is_array($conf->modules_parts['models'])) { - $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']); - } - foreach ($dirmodels as $reldir) { - foreach (array('html', 'doc', 'pdf') as $prefix) { + if (is_array($conf->modules_parts['models'])) $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']); + foreach ($dirmodels as $reldir) + { + foreach (array('html', 'doc', 'pdf') as $prefix) + { @@ -1066 +1060,2 @@ - if (file_exists($file)) { + if (file_exists($file)) + { @@ -1072,3 +1067 @@ - if ($filefound) { - break; - } + if ($filefound) break; @@ -1078 +1071,2 @@ - if ($filefound) { + if ($filefound) + { @@ -1089 +1083,2 @@ - if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) { + if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0) + { @@ -1096 +1091,3 @@ - } else { + } + else + { @@ -1102 +1099,3 @@ - } else { + } + else + { @@ -1107,85 +1105,0 @@ - - /** - * Function used to replace a thirdparty id with another one. - * - * @param DoliDB $dbs Database handler, because function is static we name it $dbs not $db to avoid breaking coding test - * @param int $origin_id Old thirdparty id - * @param int $dest_id New thirdparty id - * @return bool - */ - public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id) - { - $tables = array( - 'don' - ); - - return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables); - } - - /** - * Function to get reamain to pay for a donation - * - * @return int Return integer <0 if KO, > reamain to pay if OK - */ - public function getRemainToPay() - { - dol_syslog(__METHOD__, LOG_DEBUG); - - if (empty($this->id)) { - $this->error = 'Missing object id'; - $this->errors[] = $this->error; - dol_syslog(__METHOD__.' : '.$this->error, LOG_ERR); - return -1; - } - - $sql = "SELECT SUM(amount) as sum_amount FROM ".MAIN_DB_PREFIX."payment_donation WHERE fk_donation = ".((int) $this->id); - $resql = $this->db->query($sql); - if (!$resql) { - dol_print_error($this->db); - return -2; - } else { - $sum_amount = (float) $this->db->fetch_object($resql)->sum_amount; - return (float) $this->amount - $sum_amount; - } - } - - /** - * Return clicable link of object (with eventually picto) - * - * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link) - * @param array $arraydata Array of data - * @return string HTML Code for Kanban thumb. - */ - public function getKanbanView($option = '', $arraydata = null) - { - global $langs; - - $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']); - - $return = '
'; - $return .= '
'; - $return .= ''; - $return .= img_picto('', $this->picto); - $return .= ''; - $return .= '
'; - $return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).''; - if ($selected >= 0) { - $return .= ''; - } - if (property_exists($this, 'date')) { - $return .= ' | '.$langs->trans("Date").' : '.dol_print_date($this->date).''; - } - if (property_exists($this, 'societe') && !empty($this->societe)) { - $return .= '
'.$langs->trans("Company").' : '.$this->societe.''; - } - if (property_exists($this, 'amount')) { - $return .= '
'.$langs->trans("Amount").' : '.price($this->amount).''; - } - if (method_exists($this, 'LibStatut')) { - $return .= '
'.$this->getLibStatut(3).'
'; - } - $return .= '
'; - $return .= '
'; - $return .= '
'; - return $return; - } --- /tmp/dsg/dolibarr/htdocs/don/class/github_19.0.3_donstats.class.php +++ /tmp/dsg/dolibarr/htdocs/don/class/client_donstats.class.php @@ -43 +43 @@ - public $userid; + public $userid; @@ -45,4 +45,4 @@ - /** - * @var string FROM - */ - public $from; + /** + * @var string FROM + */ + public $from; @@ -50,3 +50,3 @@ - /** - * @var string field - */ + /** + * @var string field + */ @@ -58 +58 @@ - public $where; + public $where; @@ -61,4 +61,4 @@ - /** - * Constructor - * - * @param DoliDB $db Database handler + /** + * Constructor + * + * @param DoliDB $db Database handler @@ -68,4 +68,4 @@ - */ - public function __construct($db, $socid, $mode, $userid = 0) - { - global $conf; + */ + public function __construct($db, $socid, $mode, $userid = 0) + { + global $user, $conf; @@ -75 +74,0 @@ - $this->field = 'amount'; @@ -77 +76 @@ - $this->userid = $userid; + $this->userid = $userid; @@ -80 +79 @@ - $object = new Don($this->db); + $object = new Don($this->db); @@ -88,4 +87,2 @@ - if ($this->userid > 0) { - $this->where .= ' WHERE c.fk_user_author = '.((int) $this->userid); - } - } + if ($this->userid > 0) $this->where .= ' WHERE c.fk_user_author = '.$this->userid; + } @@ -93,3 +90,3 @@ - /** - * Return shipment number by month for a year - * + /** + * Return shipment number by month for a year + * @@ -97 +94 @@ - * @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 @@ -99,4 +96,6 @@ - */ - public function getNbByMonth($year, $format = 0) - { - $sql = "SELECT date_format(d.datedon,'%m') as dm, COUNT(*) as nb"; + */ + public function getNbByMonth($year, $format = 0) + { + global $user; + + $sql = "SELECT date_format(d.datedon,'%m') as dm, COUNT(*) as nb"; @@ -107 +106 @@ - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); @@ -111 +110 @@ - } + } @@ -120,0 +120,2 @@ + global $user; + @@ -125 +126 @@ - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); @@ -130,16 +131,8 @@ - /** - * Return the number of subscriptions by month for a given year - * - * @param int $year Year - * @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 of amount each month - */ - public function getAmountByMonth($year, $format = 0) - { - $sql = "SELECT date_format(d.datedon,'%m') as dm, sum(d.".$this->field.")"; - $sql .= " FROM ".$this->from; - //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql .= " WHERE ".dolSqlDateFilter('d.datedon', 0, 0, (int) $year, 1); - $sql .= " AND ".$this->where; - $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); + /** + * Return nb, total and average + * + * @return array Array of values + */ + public function getAllByYear() + { + global $user; @@ -147,2 +140,5 @@ - return $this->_getAmountByMonth($year, $sql, $format); - } + $sql = "SELECT date_format(d.datedon,'%Y') as year, COUNT(*) as nb, SUM(d.".$this->field.") as total, AVG(".$this->field.") as avg"; + $sql .= " FROM ".$this->from; + $sql .= " WHERE ".$this->where; + $sql .= " GROUP BY year"; + $sql .= $this->db->order('year', 'DESC'); @@ -150,34 +146,2 @@ - /** - * Return average amount each month - * - * @param int $year Year - * @return array Array of average each month - */ - public function getAverageByMonth($year) - { - $sql = "SELECT date_format(d.datedon,'%m') as dm, avg(d.".$this->field.")"; - $sql .= " FROM ".$this->from; - //if (empty($user->rights->societe->client->voir) && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql .= " WHERE ".dolSqlDateFilter('d.datedon', 0, 0, (int) $year, 1); - $sql .= " AND ".$this->where; - $sql .= " GROUP BY dm"; - $sql .= $this->db->order('dm', 'DESC'); - - return $this->_getAverageByMonth($year, $sql); - } - - /** - * Return nb, total and average - * - * @return array Array of values - */ - public function getAllByYear() - { - $sql = "SELECT date_format(d.datedon,'%Y') as year, COUNT(*) as nb, SUM(d.".$this->field.") as total, AVG(".$this->field.") as avg"; - $sql .= " FROM ".$this->from; - $sql .= " WHERE ".$this->where; - $sql .= " GROUP BY year"; - $sql .= $this->db->order('year', 'DESC'); - - return $this->_getAllByYear($sql); - } + return $this->_getAllByYear($sql); + } --- /tmp/dsg/dolibarr/htdocs/don/class/github_19.0.3_paymentdonation.class.php +++ /tmp/dsg/dolibarr/htdocs/don/class/client_paymentdonation.class.php @@ -42 +42 @@ - /** + /** @@ -53,2 +53,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -67,2 +67 @@ - public $fk_typepayment; // Payment mode ID - public $paymenttype; // Payment mode ID or Code. TODO Use only the code in this field. + public $typepayment; @@ -73,2 +72,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -78,2 +77,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -83,2 +82,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -95,14 +94 @@ - public $chid; - public $datepaid; - public $bank_account; - public $bank_line; - - /** - * @var string Id of external payment mode - */ - public $ext_payment_id; - - /** - * @var string Name of external payment mode - */ - public $ext_payment_site; + @@ -122,2 +108,2 @@ - * Use this->amounts to have list of lines for the payment - * + * Use this->amounts to have list of lines for the payment + * @@ -126 +112 @@ - * @return int Return integer <0 if KO, id of payment if OK + * @return int <0 if KO, id of payment if OK @@ -134,4 +120,5 @@ - $now = dol_now(); - - // Validate parameters - if (!$this->datep) { + $now = dol_now(); + + // Validate parameters + if (!$this->datepaid) + { @@ -143,44 +130,20 @@ - if (isset($this->chid)) { - $this->chid = (int) $this->chid; - } elseif (isset($this->fk_donation)) { - // NOTE : The property used in INSERT for fk_donation is not fk_donation but chid - // (keep priority to chid property) - $this->chid = (int) $this->fk_donation; - } - if (isset($this->fk_donation)) { - $this->fk_donation = (int) $this->fk_donation; - } - if (isset($this->amount)) { - $this->amount = trim($this->amount); - } - if (isset($this->fk_typepayment)) { - $this->fk_typepayment = trim($this->fk_typepayment); - } - if (isset($this->num_payment)) { - $this->num_payment = trim($this->num_payment); - } - if (isset($this->note_public)) { - $this->note_public = trim($this->note_public); - } - if (isset($this->fk_bank)) { - $this->fk_bank = (int) $this->fk_bank; - } - if (isset($this->fk_user_creat)) { - $this->fk_user_creat = (int) $this->fk_user_creat; - } - if (isset($this->fk_user_modif)) { - $this->fk_user_modif = (int) $this->fk_user_modif; - } - - $totalamount = 0; - foreach ($this->amounts as $key => $value) { // How payment is dispatch - $newvalue = price2num($value, 'MT'); - $this->amounts[$key] = $newvalue; - $totalamount += $newvalue; - } - $totalamount = price2num($totalamount); - - // Check parameters - if ($totalamount == 0) { - return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null - } + if (isset($this->fk_donation)) $this->fk_donation = (int) $this->fk_donation; + if (isset($this->amount)) $this->amount = trim($this->amount); + if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment); + if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); + if (isset($this->note_public)) $this->note_public = trim($this->note_public); + if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank; + if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat; + if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif; + + $totalamount = 0; + foreach ($this->amounts as $key => $value) // How payment is dispatch + { + $newvalue = price2num($value, 'MT'); + $this->amounts[$key] = $newvalue; + $totalamount += $newvalue; + } + $totalamount = price2num($totalamount); + + // Check parameters + if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null @@ -191 +154,2 @@ - if ($totalamount != 0) { + if ($totalamount != 0) + { @@ -193,8 +157,6 @@ - $sql .= " fk_typepayment, num_payment, note, ext_payment_id, ext_payment_site,"; - $sql .= " fk_user_creat, fk_bank)"; - $sql .= " VALUES (".((int) $this->chid).", '".$this->db->idate($now)."',"; - $sql .= " '".$this->db->idate($this->datep)."',"; - $sql .= " ".((float) price2num($totalamount)).","; - $sql .= " ".((int) $this->paymenttype).", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note_public)."', "; - $sql .= " ".($this->ext_payment_id ? "'".$this->db->escape($this->ext_payment_id)."'" : "null").", ".($this->ext_payment_site ? "'".$this->db->escape($this->ext_payment_site)."'" : "null").","; - $sql .= " ".((int) $user->id).", 0)"; + $sql .= " fk_typepayment, num_payment, note, fk_user_creat, fk_bank)"; + $sql .= " VALUES ($this->chid, '".$this->db->idate($now)."',"; + $sql .= " '".$this->db->idate($this->datepaid)."',"; + $sql .= " ".$totalamount.","; + $sql .= " ".$this->paymenttype.", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note_public)."', ".$user->id.","; + $sql .= " 0)"; @@ -204 +166,2 @@ - if ($resql) { + if ($resql) + { @@ -207 +170,3 @@ - } else { + } + else + { @@ -212 +177,2 @@ - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { @@ -215,3 +181 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } @@ -221,4 +185,5 @@ - if ($totalamount != 0 && !$error) { - $this->amount = $totalamount; - $this->total = $totalamount; // deprecated - $this->db->commit(); + if ($totalamount != 0 && !$error) + { + $this->amount = $totalamount; + $this->total = $totalamount; // deprecated + $this->db->commit(); @@ -226 +191,3 @@ - } else { + } + else + { @@ -237 +204 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -260 +227 @@ - $sql .= " WHERE t.rowid = ".((int) $id); + $sql .= " WHERE t.rowid = ".$id; @@ -264,2 +231,4 @@ - if ($resql) { - if ($this->db->num_rows($resql)) { + if ($resql) + { + if ($this->db->num_rows($resql)) + { @@ -276,2 +245 @@ - $this->fk_typepayment = $obj->fk_typepayment; // Id on type of payent - $this->paymenttype = $obj->fk_typepayment; // Id on type of payment. We should store the code into paymenttype. + $this->fk_typepayment = $obj->fk_typepayment; @@ -293 +261,3 @@ - } else { + } + else + { @@ -305 +275 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -314,24 +284,8 @@ - if (isset($this->fk_donation)) { - $this->fk_donation = (int) $this->fk_donation; - } - if (isset($this->amount)) { - $this->amount = trim($this->amount); - } - if (isset($this->fk_typepayment)) { - $this->fk_typepayment = trim($this->fk_typepayment); - } - if (isset($this->num_payment)) { - $this->num_payment = trim($this->num_payment); - } - if (isset($this->note_public)) { - $this->note_public = trim($this->note_public); - } - if (isset($this->fk_bank)) { - $this->fk_bank = (int) $this->fk_bank; - } - if (isset($this->fk_user_creat)) { - $this->fk_user_creat = (int) $this->fk_user_creat; - } - if (isset($this->fk_user_modif)) { - $this->fk_user_modif = (int) $this->fk_user_modif; - } + if (isset($this->fk_donation)) $this->fk_donation = (int) $this->fk_donation; + if (isset($this->amount)) $this->amount = trim($this->amount); + if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment); + if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); + if (isset($this->note_public)) $this->note_public = trim($this->note_public); + if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank; + if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat; + if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif; @@ -354 +308 @@ - $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif : "null"); + $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif : "null").""; @@ -362,7 +316,10 @@ - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - - if (!$error) { - if (!$notrigger) { - if (!$error && !$notrigger) { + $error++; + $this->errors[] = "Error ".$this->db->lasterror(); + } + + if (!$error) + { + if (!$notrigger) + { + if (!$error && !$notrigger) + { @@ -371,3 +328 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } @@ -380,2 +335,4 @@ - if ($error) { - foreach ($this->errors as $errmsg) { + if ($error) + { + foreach ($this->errors as $errmsg) + { @@ -387 +344,3 @@ - } else { + } + else + { @@ -399 +358 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -408,3 +367,14 @@ - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url"; - $sql .= " WHERE type='payment_donation' AND url_id=".(int) $this->id; + if (!$error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url"; + $sql .= " WHERE type='payment_donation' AND url_id=".(int) $this->id; + + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + } + + if (!$error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_donation"; + $sql .= " WHERE rowid=".$this->id; @@ -420,15 +390,6 @@ - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_donation"; - $sql .= " WHERE rowid=".((int) $this->id); - - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - } - - if (!$error) { - if (!$notrigger) { - if (!$error && !$notrigger) { + if (!$error) + { + if (!$notrigger) + { + if (!$error && !$notrigger) + { @@ -437,3 +398 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } @@ -446,2 +405,4 @@ - if ($error) { - foreach ($this->errors as $errmsg) { + if ($error) + { + foreach ($this->errors as $errmsg) + { @@ -453 +414,3 @@ - } else { + } + else + { @@ -489 +452,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -494 +458,2 @@ - if (!$error) { + if (!$error) + { @@ -500 +465,2 @@ - if (!$error) { + if (!$error) + { @@ -503 +469,3 @@ - } else { + } + else + { @@ -511,4 +479,4 @@ - * Return the label of the status - * - * @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 of status + * Retourne le libelle du statut d'un don (brouillon, validee, abandonnee, payee) + * + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long + * @return string Libelle @@ -518,26 +486,26 @@ - return ''; - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Return the label of a given status - * - * @param int $status Id status - * @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 of status - */ - public function LibStatut($status, $mode = 0) - { - // phpcs:enable - global $langs; - - return ''; - } - - - /** - * Initialise an instance with random values. - * Used to build previews or test instances. - * id must be 0 if object instance is a specimen. - * - * @return void + return ''; + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Renvoi le libelle d'un statut donne + * + * @param int $status Id status + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Libelle du statut + */ + public function LibStatut($status, $mode = 0) + { + // phpcs:enable + global $langs; + + return ''; + } + + + /** + * Initialise an instance with random values. + * Used to build previews or test instances. + * id must be 0 if object instance is a specimen. + * + * @return void @@ -555 +522,0 @@ - $this->paymenttype = ''; @@ -564,78 +531,85 @@ - /** - * Add record into bank for payment with links between this bank record and invoices of payment. - * All payment properties must have been set first like after a call to create(). - * - * @param User $user Object of user making payment - * @param string $mode 'payment_donation' - * @param string $label Label to use in bank record - * @param int $accountid Id of bank account to do link with - * @param string $emetteur_nom Name of transmitter - * @param string $emetteur_banque Name of bank - * @return int Return integer <0 if KO, >0 if OK - */ - public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque) - { - global $conf; - - $error = 0; - - if (isModEnabled("banque")) { - require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; - - $acc = new Account($this->db); - $acc->fetch($accountid); - - $total = $this->total; - if ($mode == 'payment_donation') { - $amount = $total; - } - // Insert payment into llx_bank - $bank_line_id = $acc->addline( - $this->datep, - $this->paymenttype, // Payment mode id or code ("CHQ or VIR for example") - $label, - $amount, - $this->num_payment, - '', - $user, - $emetteur_nom, - $emetteur_banque - ); - - // Update fk_bank in llx_paiement. - // On connait ainsi le paiement qui a genere l'ecriture bancaire - if ($bank_line_id > 0) { - $result = $this->update_fk_bank($bank_line_id); - if ($result <= 0) { - $error++; - dol_print_error($this->db); - } - - // Add link 'payment', 'payment_supplier', 'payment_donation' in bank_url between payment and bank transaction - $url = ''; - if ($mode == 'payment_donation') { - $url = DOL_URL_ROOT.'/don/payment/card.php?rowid='; - } - if ($url) { - $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); - if ($result <= 0) { - $error++; - dol_print_error($this->db); - } - } - } else { - $this->error = $acc->error; - $error++; - } - } - - if (!$error) { - return 1; - } else { - return -1; - } - } - - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** + /** + * Add record into bank for payment with links between this bank record and invoices of payment. + * All payment properties must have been set first like after a call to create(). + * + * @param User $user Object of user making payment + * @param string $mode 'payment_donation' + * @param string $label Label to use in bank record + * @param int $accountid Id of bank account to do link with + * @param string $emetteur_nom Name of transmitter + * @param string $emetteur_banque Name of bank + * @return int <0 if KO, >0 if OK + */ + public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque) + { + global $conf; + + $error = 0; + + if (!empty($conf->banque->enabled)) + { + require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + + $acc = new Account($this->db); + $acc->fetch($accountid); + + $total = $this->total; + if ($mode == 'payment_donation') $amount = $total; + + // Insert payment into llx_bank + $bank_line_id = $acc->addline( + $this->datepaid, + $this->paymenttype, // Payment mode id or code ("CHQ or VIR for example") + $label, + $amount, + $this->num_payment, + '', + $user, + $emetteur_nom, + $emetteur_banque + ); + + // Update fk_bank in llx_paiement. + // On connait ainsi le paiement qui a genere l'ecriture bancaire + if ($bank_line_id > 0) + { + $result = $this->update_fk_bank($bank_line_id); + if ($result <= 0) + { + $error++; + dol_print_error($this->db); + } + + // Add link 'payment', 'payment_supplier', 'payment_donation' in bank_url between payment and bank transaction + $url = ''; + if ($mode == 'payment_donation') $url = DOL_URL_ROOT.'/don/payment/card.php?rowid='; + if ($url) + { + $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode); + if ($result <= 0) + { + $error++; + dol_print_error($this->db); + } + } + } + else + { + $this->error = $acc->error; + $error++; + } + } + + if (!$error) + { + return 1; + } + else + { + return -1; + } + } + + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** @@ -649 +623 @@ - // phpcs:enable + // phpcs:enable @@ -654 +628,2 @@ - if ($result) { + if ($result) + { @@ -656 +631,3 @@ - } else { + } + else + { @@ -666,2 +643,2 @@ - * @param int $maxlen Max length - * @return string String with URL + * @param int $maxlen Longueur max libelle + * @return string Chaine avec URL @@ -671 +648 @@ - global $langs, $hookmanager; + global $langs; @@ -675,5 +652,4 @@ - $label = ''.$langs->trans("DonationPayment").''; - $label .= '
'; - $label .= ''.$langs->trans('Ref').': '.$this->ref; - - if (!empty($this->id)) { + $label = $langs->trans("ShowPayment").': '.$this->ref; + + if (!empty($this->id)) + { @@ -683,20 +659,5 @@ - if ($withpicto) { - $result .= ($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' '); - } - if ($withpicto && $withpicto != 2) { - $result .= ' '; - } - if ($withpicto != 2) { - $result .= $link.($maxlen ? dol_trunc($this->ref, $maxlen) : $this->ref).$linkend; - } - } - - global $action; - $hookmanager->initHooks(array($this->element . 'dao')); - $parameters = array('id'=>$this->id, 'getnomurl' => &$result); - $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook > 0) { - $result = $hookmanager->resPrint; - } else { - $result .= $hookmanager->resPrint; - } + if ($withpicto) $result .= ($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' '); + if ($withpicto && $withpicto != 2) $result .= ' '; + if ($withpicto != 2) $result .= $link.($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref).$linkend; + } +