--- /tmp/dsg/dolibarr/htdocs/compta/bank/class/github_19.0.3_account.class.php +++ /tmp/dsg/dolibarr/htdocs/compta/bank/class/client_account.class.php @@ -11,2 +10,0 @@ - * Copyright (C) 2019 JC Prieto - * Copyright (C) 2022-2023 Frédéric France @@ -33 +30,0 @@ - @@ -53,6 +49,0 @@ - * @var int Does this object support multicompany module ? - * 0=No test on entity, 1=Test with field entity, 'field@table'=Test with link by field@table - */ - public $ismultientitymanaged = 1; - - /** @@ -143 +134 @@ - * IBAN number (International Bank Account Number). Stored into iban_prefix field into database (TODO Rename field in database) + * IBAN number (International Bank Account Number). Stored into iban_prefix field into database @@ -147,14 +137,0 @@ - - /** - * IBAN number - * - * @var string - * @deprecated see $iban - */ - public $iban_prefix; - - /** - * XML SEPA format: place Payment Type Information (PmtTpInf) in Credit Transfer Transaction Information (CdtTrfTxInf) - * @var int - */ - public $pti_in_ctti = 0; @@ -173,11 +150 @@ - public $owner_zip; - public $owner_town; - public $owner_country_id; - public $owner_country_code; - - /** - * Address of the bank account - * @var string - */ - public $domiciliation; // deprecated, use now address - public $address; + @@ -187 +153,0 @@ - public $country_id; @@ -210,2 +176,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -213,4 +178,0 @@ - /** - * @var string Label of journal - */ - public $accountancy_journal; @@ -254,31 +215,0 @@ - - /** - * Balance. Used in Account::create - * @var float - * @deprecated - * @see $balance - */ - public $solde; - - /** - * Balance. Used in Account::create - * @var float - */ - public $balance; - - /** - * Creditor Identifier CI. Some banks use different ICS for direct debit and bank tranfer - * @var string - */ - public $ics; - - /** - * Creditor Identifier for Bank Transfer. - * @var string - */ - public $ics_transfer; - - /** - * @var string The previous ref in case of rename on update to rename attachment folders - */ - public $oldref; @@ -305 +236 @@ - * 'arrayofkeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel") + * 'arraykeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel") @@ -330,2 +261,2 @@ - 'state_id' =>array('type'=>'integer', 'label'=>'StateId', 'enabled'=>1, 'visible'=>-1, 'position'=>90), - 'fk_pays' =>array('type'=>'integer', 'label'=>'Country', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>95), + 'state_id' =>array('type'=>'integer', 'label'=>'State id', 'enabled'=>1, 'visible'=>-1, 'position'=>90), + 'fk_pays' =>array('type'=>'integer', 'label'=>'Fk pays', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>95), @@ -333,4 +264 @@ - 'owner_address' =>array('type'=>'varchar(255)', 'label'=>'Owner address', 'enabled'=>1, 'visible'=>-1, 'position'=>105), - 'owner_zip' =>array('type'=>'varchar(25)', 'label'=>'Owner zip', 'enabled'=>1, 'visible'=>-1, 'position'=>106), - 'owner_town' =>array('type'=>'varchar(50)', 'label'=>'Owner town', 'enabled'=>1, 'visible'=>-1, 'position'=>107), - 'owner_country_id' =>array('type'=>'integer', 'label'=>'Owner country', 'enabled'=>1, 'visible'=>-1, 'position'=>108), + 'owner_address' =>array('type'=>'text', 'label'=>'Owner address', 'enabled'=>1, 'visible'=>-1, 'position'=>105), @@ -342 +269,0 @@ - 'fk_accountancy_journal' =>array('type'=>'integer', 'label'=>'Accountancy journal ID', 'enabled'=>1, 'visible'=>-1, 'position'=>132), @@ -352 +279 @@ - 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>170), + 'note_public' =>array('type'=>'text', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>170), @@ -355,0 +283 @@ + 'fk_accountancy_journal' =>array('type'=>'integer', 'label'=>'Fk accountancy journal', 'enabled'=>1, 'visible'=>-1, 'position'=>190), @@ -372 +299,0 @@ - @@ -376 +302,0 @@ - @@ -382 +308 @@ - public function __construct(DoliDB $db) + public function __construct(DoliDB $db) @@ -419 +345 @@ - } elseif ($val == 'BIC') { + }elseif ($val == 'BIC') { @@ -421 +347 @@ - } elseif ($val == 'IBAN') { + }elseif ($val == 'IBAN') { @@ -435 +361 @@ - public function canBeConciliated() + public function canBeConciliated() @@ -439,9 +365,3 @@ - if (empty($this->rappro)) { - return -1; - } - if ($this->courant == Account::TYPE_CASH && !getDolGlobalString('BANK_CAN_RECONCILIATE_CASHACCOUNT')) { - return -2; - } - if ($this->clos) { - return -3; - } + if (empty($this->rappro)) return -1; + if ($this->courant == Account::TYPE_CASH && empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) return -2; + if ($this->clos) return -3; @@ -452 +372 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -456,3 +376,3 @@ - * @param int $line_id Id of bank entry - * @param int $url_id Id of object related to link - * @param string $url Url (deprecated, we use now 'url_id' and 'type' instead) + * @param int $line_id Id ecriture bancaire + * @param int $url_id Id parametre url + * @param string $url Url @@ -461,5 +381,5 @@ - * @return int Return integer <0 if KO, id line if OK - */ - public function add_url_line($line_id, $url_id, $url, $label, $type) - { - // phpcs:enable + * @return int <0 if KO, id line if OK + */ + public function add_url_line($line_id, $url_id, $url, $label, $type) + { + // phpcs:enable @@ -469 +389 @@ - $sql .= ", url"; // deprecated + $sql .= ", url"; @@ -473,3 +393,3 @@ - $sql .= " ".((int) $line_id); - $sql .= ", ".((int) $url_id); - $sql .= ", '".$this->db->escape($url)."'"; // dperecated + $sql .= "'".$line_id."'"; + $sql .= ", '".$url_id."'"; + $sql .= ", '".$url."'"; @@ -477 +397 @@ - $sql .= ", '".$this->db->escape($type)."'"; + $sql .= ", '".$type."'"; @@ -481 +401,2 @@ - if ($this->db->query($sql)) { + if ($this->db->query($sql)) + { @@ -484 +405,3 @@ - } else { + } + else + { @@ -490 +413 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -500,3 +423,3 @@ - public function get_url($fk_bank = 0, $url_id = 0, $type = '') - { - // phpcs:enable + public function get_url($fk_bank = '', $url_id = '', $type = '') + { + // phpcs:enable @@ -506 +429,2 @@ - if (!empty($fk_bank) && (!empty($url_id) || !empty($type))) { + if (!empty($fk_bank) && (!empty($url_id) || !empty($type))) + { @@ -514,3 +438,3 @@ - $sql .= " WHERE fk_bank = ".((int) $fk_bank); - } else { - $sql .= " WHERE url_id = ".((int) $url_id)." AND type = '".$this->db->escape($type)."'"; + $sql .= " WHERE fk_bank = ".$fk_bank; + } + else { $sql .= " WHERE url_id = ".$url_id." AND type = '".$type."'"; @@ -522 +446,2 @@ - if ($result) { + if ($result) + { @@ -525 +450,2 @@ - while ($i < $num) { + while ($i < $num) + { @@ -540,3 +466,2 @@ - } else { - dol_print_error($this->db); - } + } + else dol_print_error($this->db); @@ -551 +476 @@ - * @param string $oper 'VIR','PRE','LIQ','VAD','CB','CHQ'... + * @param string $oper 1,2,3,4... (deprecated) or 'TYP','VIR','PRE','LIQ','VAD','CB','CHQ'... @@ -554 +479 @@ - * @param string $num_chq Numero cheque or transfer + * @param string $num_chq Numero cheque ou virement @@ -561,2 +485,0 @@ - * @param string $num_releve Label of bank receipt for reconciliation - * @param float $amount_main_currency Amount @@ -565,4 +488,2 @@ - public function addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur = '', $banque = '', $accountancycode = '', $datev = null, $num_releve = '', $amount_main_currency = null) - { - global $langs; - + public function addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur = '', $banque = '', $accountancycode = '', $datev = null) + { @@ -574,4 +494,0 @@ - if (empty($this->id) && !empty($this->rowid)) { // For backward compatibility - $this->id = $this->rowid; - } - @@ -581 +497,0 @@ - $label = trim($label); @@ -585 +501,2 @@ - if (is_numeric($oper)) { // Clean operation to have a code instead of a rowid + if (is_numeric($oper)) // Clean operation to have a code instead of a rowid + { @@ -587 +504 @@ - $sql .= " WHERE id = ".((int) $oper); + $sql .= " WHERE id=".$oper; @@ -590 +507,2 @@ - if ($resql) { + if ($resql) + { @@ -593 +511,3 @@ - } else { + } + else + { @@ -600,2 +520,3 @@ - if (!$oper) { - $this->error = $langs->trans("OperNotDefined"); + if (!$oper) + { + $this->error = "oper not defined"; @@ -604,2 +525,3 @@ - if (!$this->id) { - $this->error = $langs->trans("ThisIdNotDefined"); + if (!$this->rowid) + { + $this->error = "this->rowid not defined"; @@ -608 +530,2 @@ - if ($this->courant == Account::TYPE_CASH && $oper != 'LIQ') { + if ($this->courant == Account::TYPE_CASH && $oper != 'LIQ') + { @@ -615,3 +538 @@ - if (is_null($datev) || empty($datev)) { - $datev = $date; - } + if (is_null($datev) || empty($datev)) $datev = $date; @@ -625 +545,0 @@ - $accline->amount_main_currency = $amount_main_currency; @@ -627 +547 @@ - $accline->fk_account = $this->id; + $accline->fk_account = $this->rowid; @@ -630 +549,0 @@ - $accline->num_releve = $num_releve; @@ -646 +565 @@ - $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class("; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class ("; @@ -649 +568 @@ - $sql .= ((int) $accline->id).", '".$this->db->escape($categorie)."'"; + $sql .= $accline->id.", ".$categorie; @@ -656,2 +575 @@ - - return -4; + return -3; @@ -662 +579,0 @@ - @@ -665,2 +582 @@ - $this->error = $accline->error; - $this->errors = $accline->errors; + $this->error = $this->db->lasterror(); @@ -668,2 +584 @@ - - return -5; + return -2; @@ -678,5 +593,5 @@ - * @return int Return integer < 0 if KO, > 0 if OK - */ - public function create(User $user, $notrigger = 0) - { - global $langs, $conf; + * @return int < 0 if KO, > 0 if OK + */ + public function create(User $user, $notrigger = 0) + { + global $langs, $conf, $hookmanager; @@ -687,6 +602,4 @@ - if (!$this->min_allowed) { - $this->min_allowed = 0; - } - if (!$this->min_desired) { - $this->min_desired = 0; - } + if (!$this->min_allowed) $this->min_allowed = 0; + if (!$this->min_desired) $this->min_desired = 0; + $this->state_id = ($this->state_id ? $this->state_id : $this->state_id); + $this->country_id = ($this->country_id ? $this->country_id : $this->country_id); @@ -695 +608,2 @@ - if (empty($this->country_id)) { + if (empty($this->country_id)) + { @@ -700 +614,2 @@ - if (empty($this->ref)) { + if (empty($this->ref)) + { @@ -705 +620,2 @@ - if (empty($this->date_solde)) { + if (empty($this->date_solde)) + { @@ -711,10 +627 @@ - // Load librairies to check BAN - $balance = $this->balance; - if (empty($balance) && !empty($this->solde)) { - $balance = $this->solde; - } - if (empty($balance)) { - $balance = 0; - } - - // Load the library to validate/check a BAN account + // Chargement librairie pour acces fonction controle RIB @@ -742 +648,0 @@ - $sql .= ", pti_in_ctti"; @@ -745,3 +650,0 @@ - $sql .= ", owner_zip"; - $sql .= ", owner_town"; - $sql .= ", owner_country_id"; @@ -755,2 +657,0 @@ - $sql .= ", ics"; - $sql .= ", ics_transfer"; @@ -761 +662 @@ - $sql .= ", ".((int) $conf->entity); + $sql .= ", ".$conf->entity; @@ -763 +664 @@ - $sql .= ", ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) : "null"); + $sql .= ", ".($this->fk_accountancy_journal > 0 ? $this->db->escape($this->fk_accountancy_journal) : "null"); @@ -772 +672,0 @@ - $sql .= ", ".((int) $this->pti_in_ctti); @@ -775,3 +674,0 @@ - $sql .= ", '".$this->db->escape($this->owner_zip)."'"; - $sql .= ", '".$this->db->escape($this->owner_town)."'"; - $sql .= ", ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) : "null"); @@ -779,3 +676,3 @@ - $sql .= ", ".((int) $this->rappro); - $sql .= ", ".price2num($this->min_allowed, 'MT'); - $sql .= ", ".price2num($this->min_desired, 'MT'); + $sql .= ", ".$this->rappro; + $sql .= ", ".price2num($this->min_allowed); + $sql .= ", ".price2num($this->min_desired); @@ -783,4 +680,2 @@ - $sql .= ", ".($this->state_id > 0 ? ((int) $this->state_id) : "null"); - $sql .= ", ".($this->country_id > 0 ? ((int) $this->country_id) : "null"); - $sql .= ", '".$this->db->escape($this->ics)."'"; - $sql .= ", '".$this->db->escape($this->ics_transfer)."'"; + $sql .= ", ".($this->state_id > 0 ? $this->state_id : "null"); + $sql .= ", ".$this->country_id; @@ -791 +686,2 @@ - if ($resql) { + if ($resql) + { @@ -795 +691,2 @@ - if ($result > 0) { + if ($result > 0) + { @@ -797 +694 @@ - $accline->datec = $now; + $accline->datec = $this->db->idate($now); @@ -799 +696 @@ - $accline->amount = price2num($balance); + $accline->amount = price2num($this->solde); @@ -802,2 +699,2 @@ - $accline->datev = $this->date_solde; - $accline->dateo = $this->date_solde; + $accline->datev = $this->db->idate($this->date_solde); + $accline->dateo = $this->db->idate($this->date_solde); @@ -812 +709,2 @@ - if (!$error) { + if (!$error) + { @@ -814,3 +712 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -819 +715,2 @@ - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { @@ -822,3 +719 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -827 +722,3 @@ - } else { + } + else + { @@ -830,2 +727,5 @@ - } else { - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + } + else + { + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { @@ -834 +734,2 @@ - } else { + } + else { @@ -840 +741,2 @@ - if (!$error) { + if (!$error) + { @@ -843 +745,3 @@ - } else { + } + else + { @@ -854,5 +758,5 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function update(User $user, $notrigger = 0) - { - global $langs, $conf; + * @return int <0 if KO, >0 if OK + */ + public function update(User $user, $notrigger = 0) + { + global $langs, $conf, $hookmanager; @@ -863,0 +768,4 @@ + // Clean parameters + $this->state_id = ($this->state_id ? $this->state_id : $this->state_id); + $this->country_id = ($this->country_id ? $this->country_id : $this->country_id); + @@ -865 +773,2 @@ - if (empty($this->country_id)) { + if (empty($this->country_id)) + { @@ -870 +779,2 @@ - if (empty($this->ref)) { + if (empty($this->ref)) + { @@ -875,3 +785 @@ - if (!$this->label) { - $this->label = "???"; - } + if (!$this->label) $this->label = "???"; @@ -884,3 +792,3 @@ - $sql .= ",courant = ".((int) $this->courant); - $sql .= ",clos = ".((int) $this->clos); - $sql .= ",rappro = ".((int) $this->rappro); + $sql .= ",courant = ".$this->courant; + $sql .= ",clos = ".$this->clos; + $sql .= ",rappro = ".$this->rappro; @@ -889 +797 @@ - $sql .= ",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? ((int) $this->fk_accountancy_journal) : "null"); + $sql .= ",fk_accountancy_journal = ".($this->fk_accountancy_journal > 0 ? $this->db->escape($this->fk_accountancy_journal) : "null"); @@ -898 +805,0 @@ - $sql .= ",pti_in_ctti=".((int) $this->pti_in_ctti); @@ -901,3 +807,0 @@ - $sql .= ",owner_zip = '".$this->db->escape($this->owner_zip)."'"; - $sql .= ",owner_town = '".$this->db->escape($this->owner_town)."'"; - $sql .= ",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) : "null"); @@ -909,8 +813,6 @@ - $sql .= ",comment = '".$this->db->escape($this->comment)."'"; - - $sql .= ",state_id = ".($this->state_id > 0 ? ((int) $this->state_id) : "null"); - $sql .= ",fk_pays = ".($this->country_id > 0 ? ((int) $this->country_id) : "null"); - $sql .= ",ics = '".$this->db->escape($this->ics)."'"; - $sql .= ",ics_transfer = '".$this->db->escape($this->ics_transfer)."'"; - - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= ",comment = '".$this->db->escape($this->comment)."'"; + + $sql .= ",state_id = ".($this->state_id > 0 ? $this->state_id : "null"); + $sql .= ",fk_pays = ".$this->country_id; + + $sql .= " WHERE rowid = ".$this->id; @@ -920 +822,2 @@ - if ($result) { + if ($result) + { @@ -922 +825,2 @@ - if (!$error) { + if (!$error) + { @@ -924,28 +828,5 @@ - if ($result < 0) { - $error++; - } - } - - if (!$error && !empty($this->oldref) && $this->oldref !== $this->ref) { - $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filepath = 'bank/".$this->db->escape($this->ref)."'"; - $sql .= " WHERE filepath = 'bank/".$this->db->escape($this->oldref)."' and src_object_type='bank_account' and entity = ".((int) $conf->entity); - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->error = $this->db->lasterror(); - } - - // We rename directory in order not to lose the attachments - $oldref = dol_sanitizeFileName($this->oldref); - $newref = dol_sanitizeFileName($this->ref); - $dirsource = $conf->bank->dir_output.'/'.$oldref; - $dirdest = $conf->bank->dir_output.'/'.$newref; - if (file_exists($dirsource)) { - dol_syslog(get_class($this)."::update rename dir ".$dirsource." into ".$dirdest, LOG_DEBUG); - if (@rename($dirsource, $dirdest)) { - dol_syslog("Rename ok", LOG_DEBUG); - } - } - } - - if (!$error && !$notrigger) { + if ($result < 0) $error++; + } + + if (!$error && !$notrigger) + { @@ -953,4 +834,2 @@ - $result = $this->call_trigger('BANKACCOUNT_MODIFY', $user); - if ($result < 0) { - $error++; - } + $result = $this->call_trigger('BANKACCOUNT_UPDATE', $user); + if ($result < 0) $error++; @@ -959 +838,3 @@ - } else { + } + else + { @@ -965 +846,2 @@ - if (!$error) { + if (!$error) + { @@ -968 +850,3 @@ - } else { + } + else + { @@ -975 +859 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -979,6 +863,6 @@ - * @param User|null $user Object user making update - * @return int Return integer <0 if KO, >0 if OK - */ - public function update_bban(User $user = null) - { - // phpcs:enable + * @param User $user Object user making update + * @return int <0 if KO, >0 if OK + */ + public function update_bban(User $user = null) + { + // phpcs:enable @@ -987 +871,5 @@ - // Load library to get BAN control function + // Clean parameters + $this->state_id = ($this->state_id ? $this->state_id : $this->state_id); + $this->country_id = ($this->country_id ? $this->country_id : $this->country_id); + + // Chargement librairie pour acces fonction controle RIB @@ -993 +881,2 @@ - if (!$this->ref) { + if (!$this->ref) + { @@ -1009,3 +897,0 @@ - $sql .= ",owner_zip = '".$this->db->escape($this->owner_zip)."'"; - $sql .= ",owner_town = '".$this->db->escape($this->owner_town)."'"; - $sql .= ",owner_country_id = ".($this->owner_country_id > 0 ? ((int) $this->owner_country_id) : "null"); @@ -1013,3 +899,3 @@ - $sql .= ",fk_pays = ".($this->country_id > 0 ? $this->country_id : "null"); - $sql .= " WHERE rowid = ".((int) $this->id); - $sql .= " AND entity = ".((int) $conf->entity); + $sql .= ",fk_pays = ".$this->country_id; + $sql .= " WHERE rowid = ".$this->id; + $sql .= " AND entity = ".$conf->entity; @@ -1020 +906,2 @@ - if ($result) { + if ($result) + { @@ -1022 +909,3 @@ - } else { + } + else + { @@ -1035,5 +924,8 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function fetch($id, $ref = '') - { - if (empty($id) && empty($ref)) { + * @return int <0 if KO, >0 if OK + */ + public function fetch($id, $ref = '') + { + global $conf; + + if (empty($id) && empty($ref)) + { @@ -1046 +938 @@ - $sql .= " ba.domiciliation as address, ba.pti_in_ctti, ba.proprio, ba.owner_address, ba.owner_zip, ba.owner_town, ba.owner_country_id, ba.state_id, ba.fk_pays as country_id,"; + $sql .= " ba.domiciliation, ba.proprio, ba.owner_address, ba.state_id, ba.fk_pays as country_id,"; @@ -1049 +941 @@ - $sql .= " ba.datec as date_creation, ba.tms as date_modification, ba.ics, ba.ics_transfer,"; + $sql .= " ba.datec as date_creation, ba.tms as date_update,"; @@ -1051,2 +943,2 @@ - $sql .= ' d.code_departement as state_code, d.nom as state,'; - $sql .= ' aj.code as accountancy_journal'; + $sql .= ' d.code_departement as state_code, d.nom as state'; + $sql .= ' , aj.code as accountancy_journal'; @@ -1056 +948 @@ - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'accounting_journal as aj ON aj.rowid=ba.fk_accountancy_journal'; @@ -1058,6 +950,2 @@ - if ($id) { - $sql .= " AND ba.rowid = ".((int) $id); - } - if ($ref) { - $sql .= " AND ba.ref = '".$this->db->escape($ref)."'"; - } + if ($id) $sql .= " AND ba.rowid = ".$id; + if ($ref) $sql .= " AND ba.ref = '".$this->db->escape($ref)."'"; @@ -1067,2 +955,4 @@ - if ($result) { - if ($this->db->num_rows($result)) { + if ($result) + { + if ($this->db->num_rows($result)) + { @@ -1088,3 +978 @@ - $this->domiciliation = $obj->address; - $this->address = $obj->address; - $this->pti_in_ctti = $obj->pti_in_ctti; + $this->domiciliation = $obj->domiciliation; @@ -1093,3 +980,0 @@ - $this->owner_zip = $obj->owner_zip; - $this->owner_town = $obj->owner_town; - $this->owner_country_id = $obj->owner_country_id; @@ -1116,7 +1001,3 @@ - $this->date_modification = $this->db->jdate($obj->date_modification); - $this->date_update = $this->date_modification; // For compatibility - - $this->ics = $obj->ics; - $this->ics_transfer = $obj->ics_transfer; - - // Retrieve all extrafield + $this->date_update = $this->db->jdate($obj->date_update); + + // Retreive all extrafield @@ -1127 +1008,3 @@ - } else { + } + else + { @@ -1130,2 +1013,4 @@ - } else { - $this->error = $this->db->lasterror(); + } + else + { + $this->error = $this->db->lasterror; @@ -1144,5 +1029,11 @@ - * @param int[]|int $categories Category or categories IDs - * @return int Return integer <0 if KO, >0 if OK - */ - public function setCategories($categories) - { + * @param int[]|int $categories Category or categories IDs + * @return void + */ + public function setCategories($categories) + { + // Handle single category + if (!is_array($categories)) { + $categories = array($categories); + } + + // Get current categories @@ -1150 +1041,25 @@ - return parent::setCategoriesCommon($categories, Categorie::TYPE_ACCOUNT); + $c = new Categorie($this->db); + $existing = $c->containing($this->id, Categorie::TYPE_ACCOUNT, 'id'); + + // Diff + if (is_array($existing)) { + $to_del = array_diff($existing, $categories); + $to_add = array_diff($categories, $existing); + } else { + $to_del = array(); // Nothing to delete + $to_add = $categories; + } + + // Process + foreach ($to_del as $del) { + if ($c->fetch($del) > 0) { + $c->del_type($this, Categorie::TYPE_ACCOUNT); + } + } + foreach ($to_add as $add) { + if ($c->fetch($add) > 0) { + $c->add_type($this, Categorie::TYPE_ACCOUNT); + } + } + + return; @@ -1156,5 +1071,7 @@ - * @param User|null $user User deleting - * @return int Return integer <0 if KO, >0 if OK - */ - public function delete(User $user = null) - { + * @param User $user User deleting + * @return int <0 if KO, >0 if OK + */ + public function delete(User $user = null) + { + global $conf; + @@ -1165,2 +1081,0 @@ - // @TODO Check there is no child into llx_payment_various, ... to allow deletion ? - @@ -1168 +1083,2 @@ - if (!$error) { + if (!$error) + { @@ -1170 +1086 @@ - $sql .= " WHERE fk_account = ".((int) $this->id); + $sql .= " WHERE fk_account = ".$this->id; @@ -1173 +1089,2 @@ - if (!$resql) { + if (!$resql) + { @@ -1179,3 +1096,4 @@ - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; - $sql .= " WHERE rowid = ".((int) $this->id); + if (!$error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_account"; + $sql .= " WHERE rowid = ".$this->rowid; @@ -1185 +1103,2 @@ - if ($result) { + if ($result) + { @@ -1187 +1106,2 @@ - if (!$error) { + if (!$error) + { @@ -1189 +1109,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -1194 +1115,3 @@ - } else { + } + else + { @@ -1200 +1123,2 @@ - if (!$error) { + if (!$error) + { @@ -1203 +1127,3 @@ - } else { + } + else + { @@ -1216 +1142 @@ - public function getLibStatut($mode = 0) + public function getLibStatut($mode = 0) @@ -1221 +1147 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -1229,3 +1155,3 @@ - public function LibStatut($status, $mode = 0) - { - // phpcs:enable + public function LibStatut($status, $mode = 0) + { + // phpcs:enable @@ -1236,2 +1162,2 @@ - $label = $langs->transnoentitiesnoconv("StatusAccountOpened"); - $labelshort = $langs->transnoentitiesnoconv("StatusAccountOpened"); + $label = $langs->trans("StatusAccountOpened"); + $labelshort = $langs->trans("StatusAccountOpened"); @@ -1240,2 +1166,2 @@ - $label = $langs->transnoentitiesnoconv("StatusAccountClosed"); - $labelshort = $langs->transnoentitiesnoconv("StatusAccountClosed"); + $label = $langs->trans("StatusAccountClosed"); + $labelshort = $langs->trans("StatusAccountClosed"); @@ -1249 +1175 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -1255,3 +1181,3 @@ - public function can_be_deleted() - { - // phpcs:enable + public function can_be_deleted() + { + // phpcs:enable @@ -1262 +1188 @@ - $sql .= " WHERE fk_account = ".((int) $this->id); + $sql .= " WHERE fk_account=".$this->id; @@ -1267,4 +1193,3 @@ - if ($obj->nb <= 1) { - $can_be_deleted = true; // Juste le solde - } - } else { + if ($obj->nb <= 1) $can_be_deleted = true; // Juste le solde + } + else { @@ -1282 +1207 @@ - public function error() + public function error() @@ -1291,5 +1216,3 @@ - * @param int|string $date_end Date until we want to get bank account sold - * @param string $field dateo or datev - * @return int current sold (value date <= today) - */ - public function solde($option = 0, $date_end = '', $field = 'dateo') + * @return int Current sold (value date <= today) + */ + public function solde($option = 0) @@ -1301,4 +1224,2 @@ - $sql .= " WHERE fk_account = ".((int) $this->id); - if ($option == 1) { - $sql .= " AND ".$this->db->escape($field)." <= '".(!empty($date_end) ? $this->db->idate($date_end) : $this->db->idate(dol_now()))."'"; - } + $sql .= " WHERE fk_account = ".$this->id; + if ($option == 1) $sql .= " AND dateo <= '".$this->db->idate(dol_now())."'"; @@ -1307,2 +1228,4 @@ - if ($resql) { - if ($this->db->num_rows($resql)) { + if ($resql) + { + if ($this->db->num_rows($resql)) + { @@ -1321 +1244 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -1327,5 +1250,5 @@ - * @return WorkboardResponse|int Return integer <0 if KO, WorkboardResponse if OK - */ - public function load_board(User $user, $filteraccountid = 0) - { - // phpcs:enable + * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK + */ + public function load_board(User $user, $filteraccountid = 0) + { + // phpcs:enable @@ -1334,3 +1257 @@ - if ($user->socid) { - return -1; // protection pour eviter appel par utilisateur externe - } + if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe @@ -1346,3 +1267 @@ - if ($filteraccountid) { - $sql .= " AND ba.rowid = ".((int) $filteraccountid); - } + if ($filteraccountid) $sql .= " AND ba.rowid = ".$filteraccountid; @@ -1351 +1270,2 @@ - if ($resql) { + if ($resql) + { @@ -1364 +1284,2 @@ - while ($obj = $this->db->fetch_object($resql)) { + while ($obj = $this->db->fetch_object($resql)) + { @@ -1372 +1293,3 @@ - } else { + } + else + { @@ -1379 +1302 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -1382 +1304,0 @@ - * @@ -1384,5 +1306,5 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function load_state_board($filteraccountid = 0) - { - // phpcs:enable + * @return int <0 if ko, >0 if ok + */ + public function load_state_board($filteraccountid = 0) + { + // phpcs:enable @@ -1391,3 +1313 @@ - if ($user->socid) { - return -1; // protection pour eviter appel par utilisateur externe - } + if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe @@ -1402,3 +1322 @@ - if ($filteraccountid) { - $sql .= " AND ba.rowid = ".((int) $filteraccountid); - } + if ($filteraccountid) $sql .= " AND ba.rowid = ".$filteraccountid; @@ -1407,2 +1325,4 @@ - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { + if ($resql) + { + while ($obj = $this->db->fetch_object($resql)) + { @@ -1412,2 +1332,3 @@ - return 1; - } else { + } + else + { @@ -1426 +1347 @@ - public function countAccountToReconcile() + public static function countAccountToReconcile() @@ -1441,6 +1362,5 @@ - if (!getDolGlobalString('BANK_CAN_RECONCILIATE_CASHACCOUNT')) { - $sql .= " AND ba.courant != 2"; - } - $resql = $this->db->query($sql); - if ($resql) { - $obj = $this->db->fetch_object($resql); + if (empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) $sql .= " AND ba.courant != 2"; + $resql = $db->query($sql); + if ($resql) + { + $obj = $db->fetch_object($resql); @@ -1448,3 +1368,2 @@ - } else { - dol_print_error($this->db); - } + } + else dol_print_error($db); @@ -1453,43 +1371,0 @@ - } - - /** - * getTooltipContentArray - * - * @param array $params Params to construct tooltip data - * @since v18 - * @return array - */ - public function getTooltipContentArray($params) - { - global $langs; - $langs->loadLangs(['banks', 'compta']); - include_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; - - $datas = array(); - - $nofetch = !empty($params['nofetch']); - $pictos = img_picto('', $this->picto).' '.$langs->trans("BankAccount").''; - if (isset($this->status)) { - $pictos .= ' '.$this->getLibStatut(5); - } - $datas['picto'] = $pictos; - $datas['label'] = '
'.$langs->trans('Label').': '.$this->label; - $datas['accountnumber'] = '
'.$langs->trans('AccountNumber').': '.$this->number; - $datas['iban'] = '
'.$langs->trans('IBAN').': '.getIbanHumanReadable($this); - $datas['bic'] = '
'.$langs->trans('BIC').': '.$this->bic; - $datas['accountcurrency'] = '
'.$langs->trans("AccountCurrency").': '.$this->currency_code; - - if (isModEnabled('accounting')) { - include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; - $langs->load("accountancy"); - $datas['accountaccounting'] = '
'.$langs->trans('AccountAccounting').': '.length_accountg($this->account_number); - $datas['accountancyjournal'] = '
'.$langs->trans('AccountancyJournal').': '.$this->accountancy_journal; - } - // show categories for this record only in ajax to not overload lists - if (isModEnabled('categorie') && !$nofetch) { - require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; - $form = new Form($this->db); - $datas['categories'] = '
' . $form->showCategories($this->id, Categorie::TYPE_ACCOUNT, 1); - } - - return $datas; @@ -1505,2 +1381 @@ - * @param int $notooltip 1=Disable tooltip - * @param string $morecss Add more css on link + * @param int $notooltip 1=Disable tooltip @@ -1509,9 +1384,3 @@ - public function getNomUrl($withpicto = 0, $mode = '', $option = '', $save_lastsearch_value = -1, $notooltip = 0, $morecss = '') - { - global $conf, $langs; - - if (!empty($conf->dol_no_mouse_hover)) { - $notooltip = 1; // Force disable tooltips - } - - include_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; + public function getNomUrl($withpicto = 0, $mode = '', $option = '', $save_lastsearch_value = -1, $notooltip = 0) + { + global $conf, $langs, $user; @@ -1520,15 +1389,24 @@ - $classfortooltip = 'classfortooltip'; - $dataparams = ''; - $params = [ - 'id' => $this->id, - 'objecttype' => $this->element, - 'option' => $option, - 'nofetch' => 1, - ]; - if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) { - $classfortooltip = 'classforajaxtooltip'; - $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"'; - $label = ''; - } else { - $label = implode($this->getTooltipContentArray($params)); - } + $label = ''.$langs->trans("BankAccount").''; + $label .= '
'.$langs->trans('Label').': '.$this->label; + $label .= '
'.$langs->trans('AccountNumber').': '.$this->number; + $label .= '
'.$langs->trans('IBAN').': '.$this->iban; + $label .= '
'.$langs->trans('BIC').': '.$this->bic; + $label .= '
'.$langs->trans("AccountCurrency").': '.$this->currency_code; + + if (empty($user->rights->banque->lire) || !empty($user->socid)) + { + $option = 'nolink'; + } + + if (!empty($conf->accounting->enabled)) + { + include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; + $langs->load("accountancy"); + $label .= '
'.$langs->trans('AccountAccounting').': '.length_accountg($this->account_number); + $label .= '
'.$langs->trans('AccountancyJournal').': '.$this->accountancy_journal; + } + if (isset($this->status)) { + $label .= '
'.$langs->trans("Status").": ".$this->getLibStatut(5); + } + + $linkclose = '" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; @@ -1537 +1415,2 @@ - if ($mode == 'transactions') { + if ($mode == 'transactions') + { @@ -1539 +1418,3 @@ - } elseif ($mode == 'receipts') { + } + elseif ($mode == 'receipts') + { @@ -1543 +1424,2 @@ - if ($option != 'nolink') { + if ($option != 'nolink') + { @@ -1546,31 +1428,11 @@ - 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'; - } - } - - $linkclose = ''; - if (empty($notooltip)) { - if (getDolGlobalInt('MAIN_OPTIMIZEFORTEXTBROWSER')) { - $label = $langs->trans("BankAccount"); - $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; - } - $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"'); - $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"'; - } else { - $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); - } - - if ($option == 'nolink' || empty($url)) { - $linkstart = ''; - if ($option == 'nolink' || empty($url)) { - $linkend = ''; - } else { - $linkend = ''; - } + 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 = 'ref.($option == 'reflabel' && $this->label ? ' - '.$this->label : ''); - } + 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.($option == 'reflabel' && $this->label ? ' - '.$this->label : ''); @@ -1600 +1457 @@ - public function verif() + public function verif() @@ -1604,13 +1461,17 @@ - $error = 0; - - // Call functions to check BAN - if (!checkIbanForAccount($this)) { - $error++; - $this->error = 'IBANNotValid'; - } - if (!checkSwiftForAccount($this)) { - $error++; - $this->error = 'SwiftNotValid'; - } - - if (! $error) { + $this->error_number = 0; + + // Call function to check BAN + + if (!checkIbanForAccount($this) || !checkSwiftForAccount($this)) + { + $this->error_number = 12; + $this->error_message = 'IBANSWIFTControlError'; + } + /*if (! checkBanForAccount($this)) + { + $this->error_number = 12; + $this->error_message = 'BANControlError'; + }*/ + + if ($this->error_number == 0) + { @@ -1618 +1479,3 @@ - } else { + } + else + { @@ -1628 +1491 @@ - public function getCountryCode() + public function getCountryCode() @@ -1633,3 +1496 @@ - if (!empty($this->country_code)) { - return $this->country_code; - } + if (!empty($this->country_code)) return $this->country_code; @@ -1638 +1499,2 @@ - if (!empty($this->iban)) { + if (!empty($this->iban)) + { @@ -1641,3 +1503 @@ - if (preg_match("/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) { - return $reg[1]; - } + if (preg_match("/^([a-zA-Z][a-zA-Z])/i", $this->iban, $reg)) return $reg[1]; @@ -1647 +1507,2 @@ - if (!empty($this->socid)) { + if (!empty($this->socid)) + { @@ -1651,3 +1512 @@ - if (!empty($company->country_code)) { - return $company->country_code; - } + if (!empty($company->country_code)) return $company->country_code; @@ -1657,3 +1516 @@ - if (!empty($mysoc->country_code)) { - return $mysoc->country_code; - } + if (!empty($mysoc->country_code)) return $mysoc->country_code; @@ -1663,34 +1519,0 @@ - - /** - * Return full address for banner - * - * @param string $htmlkey HTML id to make banner content unique - * @param Object $object Object (thirdparty, thirdparty of contact for contact, null for a member) - * @return string Full address string - */ - public function getBannerAddress($htmlkey, $object) - { - global $conf, $langs; - - $out = ''; - - $outdone = 0; - $coords = $this->getFullAddress(1, ', ', getDolGlobalInt('MAIN_SHOW_REGION_IN_STATE_SELECT')); - if ($coords) { - if (!empty($conf->use_javascript_ajax)) { - // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile - $out .= ''; - $out .= img_picto($langs->trans("Address"), 'map-marker-alt'); - $out .= ' '; - } - $address = dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); - if ($address) { - $out .= $address; - $outdone++; - } - $outdone++; - } - - return $out; - } - @@ -1706 +1529 @@ - public function useDetailedBBAN() + public function useDetailedBBAN() @@ -1710,6 +1533,2 @@ - if (in_array($country_code, array('FR', 'ES', 'GA', 'IT', 'NC'))) { - return 1; // France, Spain, Gabon, ... - Not valid for CH - } - if (in_array($country_code, array('AD', 'AU', 'BE', 'CA', 'DE', 'DK', 'GR', 'GB', 'ID', 'IE', 'IR', 'KR', 'NL', 'NZ', 'UK', 'US'))) { - return 2; // Australia, England... - } + if (in_array($country_code, array('FR', 'ES', 'GA', 'IT', 'NC'))) return 1; // France, Spain, Gabon, ... - Not valid for CH + if (in_array($country_code, array('AU', 'BE', 'CA', 'DE', 'DK', 'GR', 'GB', 'ID', 'IE', 'IR', 'KR', 'NL', 'NZ', 'UK', 'US'))) return 2; // Australia, England... @@ -1724,8 +1543,2 @@ - public function needIBAN() - { - global $conf; - - if (getDolGlobalString('MAIN_IBAN_IS_NEVER_MANDATORY')) { - return 0; - } - + public function needIBAN() + { @@ -1770,3 +1583 @@ - if (in_array($country_code, $country_code_in_EEC)) { - return 1; // France, Spain, ... - } + if (in_array($country_code, $country_code_in_EEC)) return 1; // France, Spain, ... @@ -1782 +1593 @@ - public function info($id) + public function info($id) @@ -1819 +1630,2 @@ - if ($includeibanbic) { + if ($includeibanbic) + { @@ -1850 +1662 @@ - if (getDolGlobalString('BANK_SHOW_ORDER_OPTION')) { + if (!empty($conf->global->BANK_SHOW_ORDER_OPTION)) { @@ -1852 +1664 @@ - if (getDolGlobalString('BANK_SHOW_ORDER_OPTION') == '1') { + if ($conf->global->BANK_SHOW_ORDER_OPTION == '1') { @@ -1864 +1676 @@ - preg_replace('/ ?[^Bank]AccountNumber ?/', 'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION) + preg_replace('/ ?[^Bank]AccountNumber ?/', 'BankAccountNumber', $conf->global->BANK_SHOW_ORDER_OPTION) @@ -1880,3 +1692,2 @@ - public function initAsSpecimen() - { - // Example of IBAN FR7630001007941234567890185 + public function initAsSpecimen() + { @@ -1889,4 +1700,4 @@ - $this->code_banque = '30001'; - $this->code_guichet = '00794'; - $this->number = '12345678901'; - $this->cle_rib = '85'; + $this->code_banque = '123'; + $this->code_guichet = '456'; + $this->number = 'ABC12345'; + $this->cle_rib = '50'; @@ -1894,2 +1705,2 @@ - $this->iban = 'FR7630001007941234567890185'; - $this->domiciliation = 'Banque de France'; + $this->iban = 'FR999999999'; + $this->domiciliation = 'My bank address'; @@ -1898,3 +1708,0 @@ - $this->owner_zip = 'Owner zip'; - $this->owner_town = 'Owner town'; - $this->owner_country_id = 'Owner country_id'; @@ -1903,60 +1710,0 @@ - - /** - * Function used to replace a thirdparty id with another one. - * - * @param DoliDB $dbs Database handler - * @param int $origin_id Old thirdparty id - * @param int $dest_id New thirdparty id - * @return bool True=SQL success, False=SQL error - */ - public static function replaceThirdparty($dbs, $origin_id, $dest_id) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."bank_url SET url_id = ".((int) $dest_id)." WHERE url_id = ".((int) $origin_id)." AND type='company'"; - - if ($dbs->query($sql)) { - return true; - } else { - //if ($ignoreerrors) return true; // TODO Not enough. If there is A-B on kept thirdparty and B-C on old one, we must get A-B-C after merge. Not A-B. - //$this->errors = $dbs->lasterror(); - return false; - } - } - - /** - * Return clicable link of object (with eventually picto) - * - * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link) - * @param array $arraydata Array of data - * @return string HTML Code for Kanban thumb. - */ - public function getKanbanView($option = '', $arraydata = null) - { - global $langs; - - $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']); - - $return = '
'; - $return .= '
'; - $return .= ''; - $return .= img_picto('', $this->picto); - $return .= ''; - $return .= '
'; - $return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).''; - if ($selected >= 0) { - $return .= ''; - } - if (property_exists($this, 'type_lib')) { - $return .= '
'.substr($this->type_lib[$this->type], 0, 24).'...'; - } - if (method_exists($this, 'solde')) { - $return .= '
'; - $return .= ''.$langs->trans("Balance").' : '.price(price2num($this->solde(1), 'MT'), 0, $langs, 1, -1, -1, $this->currency_code).''; - } - if (method_exists($this, 'getLibStatut')) { - $return .= '
'.$this->getLibStatut(3).'
'; - } - $return .= '
'; - $return .= '
'; - $return .= '
'; - return $return; - } @@ -1965,2 +1712,0 @@ - -require_once DOL_DOCUMENT_ROOT.'/core/class/commonobjectline.class.php'; @@ -1971 +1717 @@ -class AccountLine extends CommonObjectLine +class AccountLine extends CommonObject @@ -1978,4 +1724,4 @@ - /** - * @var DoliDB Database handler. - */ - public $db; + /** + * @var DoliDB Database handler. + */ + public $db; @@ -1996 +1742 @@ - public $picto = 'accountline'; + public $picto = 'generic'; @@ -2003,17 +1749,17 @@ - /** - * @var string Ref - */ - public $ref; - - /** - * Date creation record (datec) - * - * @var integer - */ - public $datec; - - /** - * Date (dateo) - * - * @var integer - */ + /** + * @var string Ref + */ + public $ref; + + /** + * Date creation record (datec) + * + * @var integer + */ + public $datec; + + /** + * Date (dateo) + * + * @var integer + */ @@ -2023,4 +1769,4 @@ - * Date value (datev) - * - * @var integer - */ + * Date value (datev) + * + * @var integer + */ @@ -2029,6 +1775,12 @@ - public $amount; /* Amount of payment in the bank account currency */ - public $amount_main_currency; /* Amount in the currency of company if bank account use another currency */ - - /** - * @var int ID - */ + public $amount; + + /** + * @var string bank transaction lines label + */ + public $label; + + public $note; + + /** + * @var int ID + */ @@ -2038,2 +1790,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -2043,2 +1795,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -2046,30 +1797,0 @@ - - /** - * @var int ID of cheque receipt - */ - public $fk_bordereau; - - /** - * @var int ID of bank account - */ - public $fk_account; - - /** - * @var string Ref of bank account - */ - public $bank_account_ref; - - /** - * @var string Label of bank account - */ - public $bank_account_label; - - /** - * @var string Bank account numero - */ - public $numero_compte; - - /** - * @var string Name of check issuer - */ - public $emetteur; @@ -2083,11 +1805,18 @@ - * @var string bank transaction lines label - */ - public $label; - - public $note; - - /** - * User author of the rapprochement. - */ - public $user_rappro; - + * @var int ID of cheque receipt + */ + public $fk_bordereau; + + /** + * @var int ID of bank account + */ + public $fk_account; + + /** + * @var string Label of bank account + */ + public $bank_account_label; + + /** + * @var string Name of check issuer + */ + public $emetteur; @@ -2100 +1829 @@ - public function __construct(DoliDB $db) + public function __construct(DoliDB $db) @@ -2111,4 +1840,6 @@ - * @return int Return integer <0 if KO, 0 if OK but not found, >0 if OK and found - */ - public function fetch($rowid, $ref = '', $num = '') - { + * @return int <0 if KO, 0 if OK but not found, >0 if OK and found + */ + public function fetch($rowid, $ref = '', $num = '') + { + global $conf; + @@ -2116,3 +1847 @@ - if (empty($rowid) && empty($ref) && empty($num)) { - return -1; - } + if (empty($rowid) && empty($ref) && empty($num)) return -1; @@ -2123,0 +1853 @@ + //$sql.= " b.author"; // Is this used ? @@ -2129,7 +1859,3 @@ - if ($num) { - $sql .= " AND b.num_chq = '".$this->db->escape($num)."'"; - } elseif ($ref) { - $sql .= " AND b.rowid = '".$this->db->escape($ref)."'"; - } else { - $sql .= " AND b.rowid = ".((int) $rowid); - } + if ($num) $sql .= " AND b.num_chq='".$this->db->escape($num)."'"; + elseif ($ref) $sql .= " AND b.rowid='".$this->db->escape($ref)."'"; + else $sql .= " AND b.rowid=".$rowid; @@ -2139 +1865,2 @@ - if ($result) { + if ($result) + { @@ -2143 +1870,2 @@ - if ($obj) { + if ($obj) + { @@ -2145 +1873 @@ - $this->rowid = $obj->rowid; + $this->rowid = $obj->rowid; @@ -2148,3 +1876,3 @@ - $this->datec = $this->db->jdate($obj->datec); - $this->datev = $this->db->jdate($obj->datev); - $this->dateo = $this->db->jdate($obj->dateo); + $this->datec = $obj->datec; + $this->datev = $obj->datev; + $this->dateo = $obj->dateo; @@ -2152,5 +1880,5 @@ - $this->label = $obj->label; - $this->note = $obj->note; - - $this->fk_user_author = $obj->fk_user_author; - $this->fk_user_rappro = $obj->fk_user_rappro; + $this->label = $obj->label; + $this->note = $obj->note; + + $this->fk_user_author = $obj->fk_user_author; + $this->fk_user_rappro = $obj->fk_user_rappro; @@ -2159 +1887 @@ - $this->rappro = (int) $obj->rappro; + $this->rappro = $obj->rappro; @@ -2167 +1895 @@ - $this->bank_account_ref = $obj->bank_account_ref; + $this->bank_account_ref = $obj->bank_account_ref; @@ -2169,4 +1896,0 @@ - - // Retrieve all extrafield - // fetch optionals attributes and labels - $this->fetch_optionals(); @@ -2178 +1902,3 @@ - } else { + } + else + { @@ -2186 +1912 @@ - * @return int Return integer <0 if KO, rowid of the line if OK + * @return int <0 if KO, rowid of the line if OK @@ -2190,4 +1915,0 @@ - $error = 0; - - $this->db->begin(); - @@ -2200 +1921,0 @@ - $sql .= ", amount_main_currency"; @@ -2208 +1928,0 @@ - $sql .= ", num_releve"; @@ -2215,2 +1935 @@ - $sql .= ", ".(empty($this->amount_main_currency) ? "NULL" : price2num($this->amount_main_currency)); - $sql .= ", ".($this->fk_user_author > 0 ? ((int) $this->fk_user_author) : "null"); + $sql .= ", ".($this->fk_user_author > 0 ? $this->fk_user_author : "null"); @@ -2224 +1942,0 @@ - $sql .= ", ".($this->num_releve ? "'".$this->db->escape($this->num_releve)."'" : "null"); @@ -2226 +1943,0 @@ - @@ -2230,9 +1947,2 @@ - if ($resql) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank'); - // Actions on extra fields (by external module or standard code) - $result = $this->insertExtraFields(); - if ($result < 0) { - $error++; - } - } else { - $error++; + + if (!$resql) { @@ -2240,21 +1950,18 @@ - dol_print_error($this->db); - } - - if (!$error) { - $this->db->commit(); - return $this->id; - } else { - $this->db->rollback(); - return -1 * $error; - } - } - - /** - * Delete bank transaction record - * - * @param User|null $user User object that delete - * @param int $notrigger 1=Does not execute triggers, 0= execute triggers - * @return int Return integer <0 if KO, >0 if OK - */ - public function delete(User $user = null, $notrigger = 0) - { + return -1; + } + + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank'); + + return $this->id; + } + + /** + * Delete bank transaction record + * + * @param User $user User object that delete + * @return int <0 if KO, >0 if OK + */ + public function delete(User $user = null) + { + global $conf; + @@ -2263 +1970,2 @@ - if ($this->rappro) { + if ($this->rappro) + { @@ -2271,10 +1978,0 @@ - if (!$notrigger) { - // Call trigger - $result = $this->call_trigger('BANKACCOUNTLINE_DELETE', $user); - if ($result < 0) { - $this->db->rollback(); - return -1; - } - // End call triggers - } - @@ -2282,2 +1980,3 @@ - if (!getDolGlobalString('BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING')) { - $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type = 'bank' AND fk_doc = ".((int) $this->id); + if (empty($conf->global->BANK_ALLOW_TRANSACTION_DELETION_EVEN_IF_IN_ACCOUNTING)) + { + $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type = 'bank' AND fk_doc = ".$this->id; @@ -2292 +1991,2 @@ - } else { + } + else { @@ -2301 +2001,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -2308,9 +2009 @@ - if (!$result) { - $nbko++; - } - - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_extrafields WHERE fk_object=".(int) $this->rowid; - $result = $this->db->query($sql); - if (!$result) { - $nbko++; - } + if (!$result) $nbko++; @@ -2321,5 +2014,4 @@ - if (!$result) { - $nbko++; - } - - if (!$nbko) { + if (!$result) $nbko++; + + if (!$nbko) + { @@ -2328 +2020,3 @@ - } else { + } + else + { @@ -2335,10 +2029,10 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Delete bank line records - * - * @param User|null $user User object that delete - * @return int Return integer <0 if KO, >0 if OK - */ - public function delete_urls(User $user = null) - { - // phpcs:enable + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Delete bank line records + * + * @param User $user User object that delete + * @return int <0 if KO, >0 if OK + */ + public function delete_urls(User $user = null) + { + // phpcs:enable @@ -2347 +2041,2 @@ - if ($this->rappro) { + if ($this->rappro) + { @@ -2358,5 +2053,4 @@ - if (!$result) { - $nbko++; - } - - if (!$nbko) { + if (!$result) $nbko++; + + if (!$nbko) + { @@ -2365 +2059,3 @@ - } else { + } + else + { @@ -2377,3 +2073,3 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function update(User $user, $notrigger = 0) + * @return int <0 if KO, >0 if OK + */ + public function update(User $user, $notrigger = 0) @@ -2387 +2083 @@ - $sql .= " WHERE rowid = ".((int) $this->rowid); + $sql .= " WHERE rowid = ".$this->rowid; @@ -2391 +2087,2 @@ - if ($resql) { + if ($resql) + { @@ -2394 +2091,3 @@ - } else { + } + else + { @@ -2402 +2101 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2409,5 +2108,5 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function update_conciliation(User $user, $cat, $conciliated = 1) - { - // phpcs:enable + * @return int <0 if KO, >0 if OK + */ + public function update_conciliation(User $user, $cat, $conciliated = 1) + { + // phpcs:enable @@ -2419,2 +2118,4 @@ - if (getDolGlobalString('BANK_STATEMENT_REGEX_RULE')) { - if (!preg_match('/' . getDolGlobalString('BANK_STATEMENT_REGEX_RULE').'/', $this->num_releve)) { + if (!empty($conf->global->BANK_STATEMENT_REGEX_RULE)) + { + if (!preg_match('/'.$conf->global->BANK_STATEMENT_REGEX_RULE.'/', $this->num_releve)) + { @@ -2427 +2128 @@ - $sql .= " rappro = ".((int) $conciliated); + $sql .= " rappro = ".$conciliated; @@ -2429,4 +2130,2 @@ - if ($conciliated) { - $sql .= ", fk_user_rappro = ".$user->id; - } - $sql .= " WHERE rowid = ".((int) $this->id); + if ($conciliated) $sql .= ", fk_user_rappro = ".$user->id; + $sql .= " WHERE rowid = ".$this->id; @@ -2436,2 +2135,4 @@ - if ($resql) { - if (!empty($cat) && $cat > 0) { + if ($resql) + { + if (!empty($cat)) + { @@ -2443 +2144 @@ - $sql .= ", ".((int) $cat); + $sql .= ", ".$cat; @@ -2450 +2150,0 @@ - // TODO Do no try the insert if link already exists @@ -2457 +2157,3 @@ - } else { + } + else + { @@ -2464 +2166 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2472,4 +2174,4 @@ - public function datev_change($rowid, $sign = 1) - { - // phpcs:enable - $sql = "SELECT datev FROM ".MAIN_DB_PREFIX."bank WHERE rowid = ".((int) $rowid); + public function datev_change($rowid, $sign = 1) + { + // phpcs:enable + $sql = "SELECT datev FROM ".MAIN_DB_PREFIX."bank WHERE rowid = ".$rowid; @@ -2477 +2179,2 @@ - if ($resql) { + if ($resql) + { @@ -2483 +2186 @@ - $sql .= " WHERE rowid = ".((int) $rowid); + $sql .= " WHERE rowid = ".$rowid; @@ -2486,2 +2189,4 @@ - if ($result) { - if ($this->db->affected_rows($result)) { + if ($result) + { + if ($this->db->affected_rows($result)) + { @@ -2490 +2195,3 @@ - } else { + } + else + { @@ -2494,3 +2201,2 @@ - } else { - dol_print_error($this->db); - } + } + else dol_print_error($this->db); @@ -2500 +2206 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2507,3 +2213,3 @@ - public function datev_next($id) - { - // phpcs:enable + public function datev_next($id) + { + // phpcs:enable @@ -2513 +2219 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2520,3 +2226,3 @@ - public function datev_previous($id) - { - // phpcs:enable + public function datev_previous($id) + { + // phpcs:enable @@ -2527 +2233 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2535,4 +2241,4 @@ - public function dateo_change($rowid, $sign = 1) - { - // phpcs:enable - $sql = "SELECT dateo FROM ".MAIN_DB_PREFIX."bank WHERE rowid = ".((int) $rowid); + public function dateo_change($rowid, $sign = 1) + { + // phpcs:enable + $sql = "SELECT dateo FROM ".MAIN_DB_PREFIX."bank WHERE rowid = ".$rowid; @@ -2540 +2246,2 @@ - if ($resql) { + if ($resql) + { @@ -2546 +2253 @@ - $sql .= " WHERE rowid = ".((int) $rowid); + $sql .= " WHERE rowid = ".$rowid; @@ -2549,2 +2256,4 @@ - if ($result) { - if ($this->db->affected_rows($result)) { + if ($result) + { + if ($this->db->affected_rows($result)) + { @@ -2553 +2262,3 @@ - } else { + } + else + { @@ -2557,3 +2268,2 @@ - } else { - dol_print_error($this->db); - } + } + else dol_print_error($this->db); @@ -2563 +2273 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2570,3 +2280,3 @@ - public function dateo_next($id) - { - // phpcs:enable + public function dateo_next($id) + { + // phpcs:enable @@ -2576 +2286 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2583,3 +2293,3 @@ - public function dateo_previous($id) - { - // phpcs:enable + public function dateo_previous($id) + { + // phpcs:enable @@ -2596 +2306 @@ - public function info($id) + public function info($id) @@ -2601 +2311 @@ - $sql .= ' WHERE b.rowid = '.((int) $id); + $sql .= ' WHERE b.rowid = '.$id; @@ -2604,2 +2314,4 @@ - if ($result) { - if ($this->db->num_rows($result)) { + if ($result) + { + if ($this->db->num_rows($result)) + { @@ -2607 +2318,0 @@ - @@ -2610,2 +2321,13 @@ - $this->user_creation_id = $obj->fk_user_author; - $this->user_rappro = $obj->fk_user_rappro; + if ($obj->fk_user_author) + { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_author); + $this->user_creation = $cuser; + } + if ($obj->fk_user_rappro) + { + $ruser = new User($this->db); + $ruser->fetch($obj->fk_user_rappro); + $this->user_rappro = $ruser; + } + @@ -2617 +2339,3 @@ - } else { + } + else + { @@ -2632,3 +2356,3 @@ - public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0) - { - global $conf, $langs; + public function getNomUrl($withpicto = 0, $maxlen = 0, $option = '', $notooltip = 0) + { + global $langs; @@ -2637,8 +2361,2 @@ - - $label = img_picto('', $this->picto).' '.$langs->trans("BankTransactionLine").':
'; - $label .= ''.$langs->trans("Ref").': '.$this->ref; - if ($this->amount) { - $label .= '
'.$langs->trans("Amount").': '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency); - } - - $linkstart = '
'; + $label = $langs->trans("ShowTransaction").': '.$this->rowid; + $linkstart = ''; @@ -2648,7 +2366,2 @@ - if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'account'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - } - if ($withpicto != 2) { - $result .= ($this->ref ? $this->ref : $this->id); - } - + if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'account'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + if ($withpicto != 2) $result .= ($this->ref ? $this->ref : $this->rowid); @@ -2657,4 +2370,3 @@ - if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') { - $result .= ' ('; - } - if ($option == 'showall') { + if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') $result .= ' ('; + if ($option == 'showall') + { @@ -2668 +2380,2 @@ - if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') { + if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') + { @@ -2672,3 +2385,3 @@ - if (isModEnabled('accounting') && ($option == 'showall' || $option == 'showconciliatedandaccounted')) { - $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping"; - $sql .= " WHERE doc_type = 'bank' AND fk_doc = ".((int) $this->id); + if ($option == 'showall' || $option == 'showconciliatedandaccounted') + { + $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping WHERE doc_type = 'bank' AND fk_doc = ".$this->id; @@ -2685,3 +2398 @@ - if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') { - $result .= ')'; - } + if ($option == 'showall' || $option == 'showconciliated' || $option == 'showconciliatedandaccounted') $result .= ')'; @@ -2694,6 +2405,6 @@ - * 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 - */ - public function getLibStatut($mode = 0) + * Return label of status (activity, closed) + * + * @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) @@ -2704,13 +2415,12 @@ - // 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; - + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Renvoi le libelle d'un statut donne + * + * @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 + global $langs; @@ -2719,33 +2429,32 @@ - if ($mode == 0) - { - if ($status==0) return $langs->trans("ActivityCeased"); - if ($status==1) return $langs->trans("InActivity"); - } - if ($mode == 1) - { - if ($status==0) return $langs->trans("ActivityCeased"); - if ($status==1) return $langs->trans("InActivity"); - } - if ($mode == 2) - { - if ($status==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased"); - if ($status==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity"); - } - if ($mode == 3) - { - if ($status==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"'); - if ($status==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"'); - } - if ($mode == 4) - { - if ($status==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased"); - if ($status==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity"); - } - if ($mode == 5) - { - if ($status==0) return $langs->trans("ActivityCeased").' '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"'); - if ($status==1) return $langs->trans("InActivity").' '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"'); - }*/ - - return ''; - } + if ($mode == 0) + { + if ($status==0) return $langs->trans("ActivityCeased"); + if ($status==1) return $langs->trans("InActivity"); + } + if ($mode == 1) + { + if ($status==0) return $langs->trans("ActivityCeased"); + if ($status==1) return $langs->trans("InActivity"); + } + if ($mode == 2) + { + if ($status==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased"); + if ($status==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity"); + } + if ($mode == 3) + { + if ($status==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"'); + if ($status==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"'); + } + if ($mode == 4) + { + if ($status==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased"); + if ($status==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity"); + } + if ($mode == 5) + { + if ($status==0) return $langs->trans("ActivityCeased").' '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"'); + if ($status==1) return $langs->trans("InActivity").' '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"'); + }*/ + } + @@ -2756 +2465 @@ - * @return int Return integer <0 if KO, 0=no, 1=yes + * @return int <0 if KO, 0=no, 1=yes @@ -2764 +2473 @@ - $sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type)."' AND ab.fk_doc = ".((int) $this->id); + $sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$type."' AND ab.fk_doc = ".$this->id; @@ -2766 +2475,2 @@ - if ($resql) { + if ($resql) + { @@ -2768 +2478,2 @@ - if ($obj) { + if ($obj) + { @@ -2771 +2482,3 @@ - } else { + } + else + { @@ -2776 +2489,2 @@ - if ($alreadydispatched) { + if ($alreadydispatched) + { --- /tmp/dsg/dolibarr/htdocs/compta/bank/class/github_19.0.3_api_bankaccounts.class.php +++ /tmp/dsg/dolibarr/htdocs/compta/bank/class/client_api_bankaccounts.class.php @@ -26 +26 @@ - * @property DoliDB $db + * @property DoliDB db @@ -32,28 +32,390 @@ - /** - * array $FIELDS Mandatory fields, checked when creating an object - */ - public static $FIELDS = array( - 'ref', - 'label', - 'type', - 'currency_code', - 'country_id' - ); - - /** - * Constructor - */ - public function __construct() - { - global $db; - $this->db = $db; - } - - /** - * Get the list of accounts. - * - * @param string $sortfield Sort field - * @param string $sortorder Sort order - * @param int $limit Limit for list - * @param int $page Page number - * @param int $category Use this param to filter list by category + + /** + * array $FIELDS Mandatory fields, checked when creating an object + */ + static $FIELDS = array( + 'ref', + 'label', + 'type', + 'currency_code', + 'country_id' + ); + + /** + * Constructor + */ + public function __construct() + { + global $db; + $this->db = $db; + } + + /** + * Get the list of accounts. + * + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * @param int $category Use this param to filter list by category + * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.import_key:<:'20160101')" + * @return array List of account objects + * + * @throws RestException + */ + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $category = 0, $sqlfilters = '') + { + $list = array(); + + if (!DolibarrApiAccess::$user->rights->banque->lire) { + throw new RestException(401); + } + + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."bank_account as t"; + if ($category > 0) { + $sql .= ", ".MAIN_DB_PREFIX."categorie_account as c"; + } + $sql .= ' WHERE t.entity IN ('.getEntity('bank_account').')'; + // Select accounts of given category + if ($category > 0) { + $sql .= " AND c.fk_categorie = ".$this->db->escape($category)." AND c.fk_account = t.rowid "; + } + // Add sql filters + if ($sqlfilters) + { + if (!DolibarrApi::_checkFilters($sqlfilters)) + { + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); + } + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; + } + + $sql .= $this->db->order($sortfield, $sortorder); + if ($limit) { + if ($page < 0) + { + $page = 0; + } + $offset = $limit * $page; + + $sql .= $this->db->plimit($limit + 1, $offset); + } + + dol_syslog("API Rest request"); + $result = $this->db->query($sql); + + if ($result) { + $num = $this->db->num_rows($result); + $min = min($num, ($limit <= 0 ? $num : $limit)); + for ($i = 0; $i < $min; $i++) { + $obj = $this->db->fetch_object($result); + $account = new Account($this->db); + if ($account->fetch($obj->rowid) > 0) { + $list[] = $this->_cleanObjectDatas($account); + } + } + } else { + throw new RestException(503, 'Error when retrieving list of accounts: '.$this->db->lasterror()); + } + + return $list; + } + + /** + * Get account by ID. + * + * @param int $id ID of account + * @return array Account object + * + * @throws RestException + */ + public function get($id) + { + if (!DolibarrApiAccess::$user->rights->banque->lire) { + throw new RestException(401); + } + + $account = new Account($this->db); + $result = $account->fetch($id); + if (!$result) { + throw new RestException(404, 'account not found'); + } + + return $this->_cleanObjectDatas($account); + } + + /** + * Create account object + * + * @param array $request_data Request data + * @return int ID of account + */ + public function post($request_data = null) + { + if (!DolibarrApiAccess::$user->rights->banque->configurer) { + throw new RestException(401); + } + // Check mandatory fields + $result = $this->_validate($request_data); + + $account = new Account($this->db); + foreach ($request_data as $field => $value) { + $account->$field = $value; + } + // Date of the initial balance (required to create an account). + $account->date_solde = time(); + // courant and type are the same thing but the one used when + // creating an account is courant + $account->courant = $account->type; + + if ($account->create(DolibarrApiAccess::$user) < 0) { + throw new RestException(500, 'Error creating bank account', array_merge(array($account->error), $account->errors)); + } + return $account->id; + } + + /** + * Create an internal wire transfer between two bank accounts + * + * @param int $bankaccount_from_id BankAccount ID to use as the source of the internal wire transfer {@from body}{@required true} + * @param int $bankaccount_to_id BankAccount ID to use as the destination of the internal wire transfer {@from body}{@required true} + * @param string $date Date of the internal wire transfer (UNIX timestamp) {@from body}{@required true}{@type timestamp} + * @param string $description Description of the internal wire transfer {@from body}{@required true} + * @param float $amount Amount to transfer from the source to the destination BankAccount {@from body}{@required true} + * @param float $amount_to Amount to transfer to the destination BankAccount (only when accounts does not share the same currency) {@from body}{@required false} + * + * @url POST /transfer + * + * @return array + * + * @status 201 + * + * @throws RestException 401 Unauthorized: User does not have permission to configure bank accounts + * @throws RestException 404 Not Found: Either the source or the destination bankaccount for the provided id does not exist + * @throws RestException 422 Unprocessable Entity: Refer to detailed exception message for the cause + * @throws RestException 500 Internal Server Error: Error(s) returned by the RDBMS + */ + public function transfer($bankaccount_from_id = 0, $bankaccount_to_id = 0, $date = null, $description = "", $amount = 0.0, $amount_to = 0.0) + { + if (!DolibarrApiAccess::$user->rights->banque->configurer) { + throw new RestException(401); + } + + if ($bankaccount_from_id === $bankaccount_to_id) { + throw new RestException(422, 'bankaccount_from_id and bankaccount_to_id must be different !'); + } + + require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + + $accountfrom = new Account($this->db); + $resultAccountFrom = $accountfrom->fetch($bankaccount_from_id); + + if ($resultAccountFrom === 0) { + throw new RestException(404, 'The BankAccount for bankaccount_from_id provided does not exist.'); + } + + $accountto = new Account($this->db); + $resultAccountTo = $accountto->fetch($bankaccount_to_id); + + if ($resultAccountTo === 0) { + throw new RestException(404, 'The BankAccount for bankaccount_to_id provided does not exist.'); + } + + if ($accountto->currency_code == $accountfrom->currency_code) + { + $amount_to = $amount; + } + else + { + if (!$amount_to || empty($amount_to)) + { + throw new RestException(422, 'You must provide amount_to value since bankaccount_from and bankaccount_to does not share the same currency.'); + } + } + + $this->db->begin(); + + $error = 0; + $bank_line_id_from = 0; + $bank_line_id_to = 0; + $result = 0; + $user = DolibarrApiAccess::$user; + + // By default, electronic transfert from bank to bank + $typefrom = 'PRE'; + $typeto = 'VIR'; + + if ($accountto->courant == Account::TYPE_CASH || $accountfrom->courant == Account::TYPE_CASH) + { + // This is transfer of change + $typefrom = 'LIQ'; + $typeto = 'LIQ'; + } + + /** + * Creating bank line records + */ + + if (!$error) { + $bank_line_id_from = $accountfrom->addline($date, $typefrom, $description, -1 * price2num($amount), '', '', $user); + } + if (!($bank_line_id_from > 0)) { + $error++; + } + + if (!$error) { + $bank_line_id_to = $accountto->addline($date, $typeto, $description, price2num($amount_to), '', '', $user); + } + if (!($bank_line_id_to > 0)) { + $error++; + } + + /** + * Creating links between bank line record and its source + */ + + $url = DOL_URL_ROOT.'/compta/bank/line.php?rowid='; + $label = '(banktransfert)'; + $type = 'banktransfert'; + + if (!$error) { + $result = $accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, $url, $label, $type); + } + if (!($result > 0)) { + $error++; + } + + if (!$error) { + $result = $accountto->add_url_line($bank_line_id_to, $bank_line_id_from, $url, $label, $type); + } + if (!($result > 0)) { + $error++; + } + + if (!$error) + { + $this->db->commit(); + + return array( + 'success' => array( + 'code' => 201, + 'message' => 'Internal wire transfer created successfully.' + ) + ); + } + else + { + $this->db->rollback(); + throw new RestException(500, $accountfrom->error.' '.$accountto->error); + } + } + + /** + * Update account + * + * @param int $id ID of account + * @param array $request_data data + * @return int + */ + public function put($id, $request_data = null) + { + if (!DolibarrApiAccess::$user->rights->banque->configurer) { + throw new RestException(401); + } + + $account = new Account($this->db); + $result = $account->fetch($id); + if (!$result) { + throw new RestException(404, 'account not found'); + } + + foreach ($request_data as $field => $value) { + if ($field == 'id') continue; + $account->$field = $value; + } + + if ($account->update(DolibarrApiAccess::$user) > 0) + { + return $this->get($id); + } + else + { + throw new RestException(500, $account->error); + } + } + + /** + * Delete account + * + * @param int $id ID of account + * @return array + */ + public function delete($id) + { + if (!DolibarrApiAccess::$user->rights->banque->configurer) { + throw new RestException(401); + } + $account = new Account($this->db); + $result = $account->fetch($id); + if (!$result) { + throw new RestException(404, 'account not found'); + } + + if ($account->delete(DolibarrApiAccess::$user) < 0) { + throw new RestException(401, 'error when deleting account'); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'account deleted' + ) + ); + } + + /** + * Validate fields before creating an object + * + * @param array|null $data Data to validate + * @return array + * + * @throws RestException + */ + private function _validate($data) + { + $account = array(); + foreach (BankAccounts::$FIELDS as $field) { + if (!isset($data[$field])) + throw new RestException(400, "$field field missing"); + $account[$field] = $data[$field]; + } + return $account; + } + + // 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->rowid); + + return $object; + } + + /** + * Get the list of lines of the account. + * + * @param int $id ID of account + * @return array Array of AccountLine objects + * + * @throws RestException + * + * @url GET {id}/lines @@ -61,11 +423,27 @@ - * @param string $properties Restrict the data returned to theses properties. Ignored if empty. Comma separated list of properties names - * @return array List of account objects - * - * @throws RestException - */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $category = 0, $sqlfilters = '', $properties = '') - { - $list = array(); - - if (!DolibarrApiAccess::$user->rights->banque->lire) { - throw new RestException(401); + */ + public function getLines($id, $sqlfilters = '') + { + $list = array(); + + if (!DolibarrApiAccess::$user->rights->banque->lire) { + throw new RestException(401); + } + + $account = new Account($this->db); + $result = $account->fetch($id); + if (!$result) { + throw new RestException(404, 'account not found'); + } + + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."bank "; + $sql .= " WHERE fk_account = ".$id; + + // 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).")"; @@ -74,540 +452,101 @@ - $sql = "SELECT t.rowid FROM ".MAIN_DB_PREFIX."bank_account AS t LEFT JOIN ".MAIN_DB_PREFIX."bank_account_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields - if ($category > 0) { - $sql .= ", ".MAIN_DB_PREFIX."categorie_account as c"; - } - $sql .= ' WHERE t.entity IN ('.getEntity('bank_account').')'; - // Select accounts of given category - if ($category > 0) { - $sql .= " AND c.fk_categorie = ".((int) $category)." AND c.fk_account = t.rowid"; - } - // 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)); - for ($i = 0; $i < $min; $i++) { - $obj = $this->db->fetch_object($result); - $account = new Account($this->db); - if ($account->fetch($obj->rowid) > 0) { - $list[] = $this->_filterObjectProperties($this->_cleanObjectDatas($account), $properties); - } - } - } else { - throw new RestException(503, 'Error when retrieving list of accounts: '.$this->db->lasterror()); - } - - return $list; - } - - /** - * Get account by ID. - * - * @param int $id ID of account - * @return Object Object with cleaned properties - * - * @throws RestException - */ - public function get($id) - { - if (!DolibarrApiAccess::$user->rights->banque->lire) { - throw new RestException(401); - } - - $account = new Account($this->db); - $result = $account->fetch($id); - if (!$result) { - throw new RestException(404, 'account not found'); - } - - return $this->_cleanObjectDatas($account); - } - - /** - * Create account object - * - * @param array $request_data Request data - * @return int ID of account - */ - public function post($request_data = null) - { - if (!DolibarrApiAccess::$user->rights->banque->configurer) { - throw new RestException(401); - } - // Check mandatory fields - $result = $this->_validate($request_data); - - $account = new Account($this->db); - 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 - $account->context['caller'] = $request_data['caller']; - continue; - } - - $account->$field = $this->_checkValForAPI($field, $value, $account); - } - // Date of the initial balance (required to create an account). - $account->date_solde = time(); - // courant and type are the same thing but the one used when - // creating an account is courant - $account->courant = $account->type; - - if ($account->create(DolibarrApiAccess::$user) < 0) { - throw new RestException(500, 'Error creating bank account', array_merge(array($account->error), $account->errors)); - } - return $account->id; - } - - /** - * Create an internal wire transfer between two bank accounts - * - * @param int $bankaccount_from_id BankAccount ID to use as the source of the internal wire transfer {@from body}{@required true} - * @param int $bankaccount_to_id BankAccount ID to use as the destination of the internal wire transfer {@from body}{@required true} - * @param string $date Date of the internal wire transfer (UNIX timestamp) {@from body}{@required true}{@type timestamp} - * @param string $description Description of the internal wire transfer {@from body}{@required true} - * @param float $amount Amount to transfer from the source to the destination BankAccount {@from body}{@required true} - * @param float $amount_to Amount to transfer to the destination BankAccount (only when accounts does not share the same currency) {@from body}{@required false} - * - * @url POST /transfer - * - * @return array - * - * @status 201 - * - * @throws RestException 401 Unauthorized: User does not have permission to configure bank accounts - * @throws RestException 404 Not Found: Either the source or the destination bankaccount for the provided id does not exist - * @throws RestException 422 Unprocessable Entity: Refer to detailed exception message for the cause - * @throws RestException 500 Internal Server Error: Error(s) returned by the RDBMS - */ - public function transfer($bankaccount_from_id = 0, $bankaccount_to_id = 0, $date = null, $description = "", $amount = 0.0, $amount_to = 0.0) - { - if (!DolibarrApiAccess::$user->rights->banque->configurer) { - throw new RestException(401); - } - - require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; - - $accountfrom = new Account($this->db); - $resultAccountFrom = $accountfrom->fetch($bankaccount_from_id); - - if ($resultAccountFrom === 0) { - throw new RestException(404, 'The BankAccount for bankaccount_from_id provided does not exist.'); - } - - $accountto = new Account($this->db); - $resultAccountTo = $accountto->fetch($bankaccount_to_id); - - if ($resultAccountTo === 0) { - throw new RestException(404, 'The BankAccount for bankaccount_to_id provided does not exist.'); - } - - if ($accountto->currency_code == $accountfrom->currency_code) { - $amount_to = $amount; - } else { - if (!$amount_to || empty($amount_to)) { - throw new RestException(422, 'You must provide amount_to value since bankaccount_from and bankaccount_to does not share the same currency.'); - } - } - - if ($amount_to < 0) { - throw new RestException(422, 'You must provide a positive value for amount.'); - } - - if ($accountto->id == $accountfrom->id) { - throw new RestException(422, 'bankaccount_from_id and bankaccount_to_id must be different !'); - } - - $this->db->begin(); - - $error = 0; - $bank_line_id_from = 0; - $bank_line_id_to = 0; - $result = 0; - $user = DolibarrApiAccess::$user; - - // By default, electronic transfert from bank to bank - $typefrom = 'PRE'; - $typeto = 'VIR'; - - if ($accountto->courant == Account::TYPE_CASH || $accountfrom->courant == Account::TYPE_CASH) { - // This is transfer of change - $typefrom = 'LIQ'; - $typeto = 'LIQ'; - } - - // Clean data - $description = sanitizeVal($description, 'alphanohtml'); - - - /** - * Creating bank line records - */ - - if (!$error) { - $bank_line_id_from = $accountfrom->addline($date, $typefrom, $description, -1 * price2num($amount), '', '', $user); - } - if (!($bank_line_id_from > 0)) { - $error++; - } - - if (!$error) { - $bank_line_id_to = $accountto->addline($date, $typeto, $description, price2num($amount_to), '', '', $user); - } - if (!($bank_line_id_to > 0)) { - $error++; - } - - /** - * Creating links between bank line record and its source - */ - - $url = DOL_URL_ROOT.'/compta/bank/line.php?rowid='; - $label = '(banktransfert)'; - $type = 'banktransfert'; - - if (!$error) { - $result = $accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, $url, $label, $type); - } - if (!($result > 0)) { - $error++; - } - - if (!$error) { - $result = $accountto->add_url_line($bank_line_id_to, $bank_line_id_from, $url, $label, $type); - } - if (!($result > 0)) { - $error++; - } - - if (!$error) { - $this->db->commit(); - - return array( - 'success' => array( - 'code' => 201, - 'message' => 'Internal wire transfer created successfully.', - 'bank_id_from' => $bank_line_id_from, - 'bank_id_to' => $bank_line_id_to, - ) - ); - } else { - $this->db->rollback(); - throw new RestException(500, $accountfrom->error.' '.$accountto->error); - } - } - - /** - * Update account - * - * @param int $id ID of account - * @param array $request_data data - * @return Object Object with cleaned properties - */ - public function put($id, $request_data = null) - { - if (!DolibarrApiAccess::$user->rights->banque->configurer) { - throw new RestException(401); - } - - $account = new Account($this->db); - $result = $account->fetch($id); - if (!$result) { - throw new RestException(404, 'account not found'); - } - - 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 - $account->context['caller'] = $request_data['caller']; - continue; - } - - $account->$field = $this->_checkValForAPI($field, $value, $account); - } - - if ($account->update(DolibarrApiAccess::$user) > 0) { - return $this->get($id); - } else { - throw new RestException(500, $account->error); - } - } - - /** - * Delete account - * - * @param int $id ID of account - * @return array - */ - public function delete($id) - { - if (!DolibarrApiAccess::$user->rights->banque->configurer) { - throw new RestException(401); - } - $account = new Account($this->db); - $result = $account->fetch($id); - if (!$result) { - throw new RestException(404, 'account not found'); - } - - if ($account->delete(DolibarrApiAccess::$user) < 0) { - throw new RestException(401, 'error when deleting account'); - } - - return array( - 'success' => array( - 'code' => 200, - 'message' => 'account deleted' - ) - ); - } - - /** - * Validate fields before creating an object - * - * @param array|null $data Data to validate - * @return array - * - * @throws RestException - */ - private function _validate($data) - { - $account = array(); - foreach (BankAccounts::$FIELDS as $field) { - if (!isset($data[$field])) { - throw new RestException(400, "$field field missing"); - } - $account[$field] = $data[$field]; - } - return $account; - } - - // 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->rowid); - - return $object; - } - - /** - * Get the list of lines of the account. - * - * @param int $id ID of account - * @return array Array of AccountLine objects - * - * @throws RestException - * - * @url GET {id}/lines - * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.import_key:<:'20160101')" - */ - public function getLines($id, $sqlfilters = '') - { - $list = array(); - - if (!DolibarrApiAccess::$user->rights->banque->lire) { - throw new RestException(401); - } - - $account = new Account($this->db); - $result = $account->fetch($id); - if (!$result) { - throw new RestException(404, 'account not found'); - } - - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."bank "; - $sql .= " WHERE fk_account = ".((int) $id); - - // Add sql filters - if ($sqlfilters) { - $errormessage = ''; - $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage); - if ($errormessage) { - throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage); - } - } - - $sql .= " ORDER BY rowid"; - - $result = $this->db->query($sql); - - if ($result) { - $num = $this->db->num_rows($result); - for ($i = 0; $i < $num; $i++) { - $obj = $this->db->fetch_object($result); - $accountLine = new AccountLine($this->db); - if ($accountLine->fetch($obj->rowid) > 0) { - $list[] = $this->_cleanObjectDatas($accountLine); - } - } - } else { - throw new RestException(503, 'Error when retrieving list of account lines: '.$this->db->lasterror()); - } - - return $list; - } - - /** - * Add a line to an account - * - * @param int $id ID of account - * @param string $date Payment date (timestamp) {@from body} {@type timestamp} - * @param string $type Payment mode (TYP,VIR,PRE,LIQ,VAD,CB,CHQ...) {@from body} - * @param string $label Label {@from body} - * @param float $amount Amount (may be 0) {@from body} - * @param int $category Category - * @param string $cheque_number Cheque numero {@from body} - * @param string $cheque_writer Name of cheque writer {@from body} - * @param string $cheque_bank Bank of cheque writer {@from body} - * @param string $accountancycode Accountancy code {@from body} - * @param string $datev Payment date value (timestamp) {@from body} {@type timestamp} - * @param string $num_releve Bank statement numero {@from body} - * @return int ID of line - * - * @url POST {id}/lines - */ - public function addLine($id, $date, $type, $label, $amount, $category = 0, $cheque_number = '', $cheque_writer = '', $cheque_bank = '', $accountancycode = '', $datev = null, $num_releve = '') - { - if (!DolibarrApiAccess::$user->rights->banque->modifier) { - throw new RestException(401); - } - - $account = new Account($this->db); - $result = $account->fetch($id); - if (!$result) { - throw new RestException(404, 'account not found'); - } - - $type = sanitizeVal($type); - $label = sanitizeVal($label); - $cheque_number = sanitizeVal($cheque_number); - $cheque_writer = sanitizeVal($cheque_writer); - $cheque_bank = sanitizeVal($cheque_bank); - $accountancycode = sanitizeVal($accountancycode); - $num_releve = sanitizeVal($num_releve); - - $result = $account->addline( - $date, - $type, - $label, - $amount, - $cheque_number, - $category, - DolibarrApiAccess::$user, - $cheque_writer, - $cheque_bank, - $accountancycode, - $datev, - $num_releve - ); - if ($result < 0) { - throw new RestException(503, 'Error when adding line to account: '.$account->error); - } - return $result; - } - - /** - * Add a link to an account line - * - * @param int $id ID of account - * @param int $line_id ID of account line - * @param int $url_id ID to set in the URL {@from body} - * @param string $url URL of the link {@from body} - * @param string $label Label {@from body} - * @param string $type Type of link ('payment', 'company', 'member', ...) {@from body} - * @return int ID of link - * - * @url POST {id}/lines/{line_id}/links - */ - public function addLink($id, $line_id, $url_id, $url, $label, $type) - { - if (!DolibarrApiAccess::$user->rights->banque->modifier) { - throw new RestException(401); - } - - $account = new Account($this->db); - $result = $account->fetch($id); - if (!$result) { - throw new RestException(404, 'account not found'); - } - - $accountLine = new AccountLine($this->db); - $result = $accountLine->fetch($line_id); - if (!$result) { - throw new RestException(404, 'account line not found'); - } - - $url = sanitizeVal($url); - $label = sanitizeVal($label); - $type = sanitizeVal($type); - - $result = $account->add_url_line($line_id, $url_id, $url, $label, $type); - if ($result < 0) { - throw new RestException(503, 'Error when adding link to account line: '.$account->error); - } - return $result; - } - - /** - * Get the list of links for a line of the account. - * - * @param int $id ID of account - * @param int $line_id ID of account line - * @return array Array of links - * - * @throws RestException - * - * @url GET {id}/lines/{line_id}/links - * - */ - public function getLinks($id, $line_id) - { - $list = array(); - - if (!DolibarrApiAccess::$user->rights->banque->lire) { - throw new RestException(401); - } - - $account = new Account($this->db); - $result = $account->fetch($id); - if (!$result) { - throw new RestException(404, 'account not found'); - } - $links = $account->get_url($line_id); // Get an array('url'=>, 'url_id'=>, 'label'=>, 'type'=> 'fk_bank'=> ) - foreach ($links as &$link) { - unset($link[0], $link[1], $link[2], $link[3]); // Remove the numeric keys - } - - return $links; - } + $sql .= " ORDER BY rowid"; + + $result = $this->db->query($sql); + + if ($result) { + $num = $this->db->num_rows($result); + for ($i = 0; $i < $num; $i++) { + $obj = $this->db->fetch_object($result); + $accountLine = new AccountLine($this->db); + if ($accountLine->fetch($obj->rowid) > 0) { + $list[] = $this->_cleanObjectDatas($accountLine); + } + } + } else { + throw new RestException(503, 'Error when retrieving list of account lines: '.$accountLine->error); + } + + return $list; + } + + /** + * Add a line to an account + * + * @param int $id ID of account + * @param int $date Payment date (timestamp) {@from body} {@type timestamp} + * @param string $type Payment mode (TYP,VIR,PRE,LIQ,VAD,CB,CHQ...) {@from body} + * @param string $label Label {@from body} + * @param float $amount Amount (may be 0) {@from body} + * @param int $category Category + * @param string $cheque_number Cheque numberl {@from body} + * @param string $cheque_writer Name of cheque writer {@from body} + * @param string $cheque_bank Bank of cheque writer {@from body} + * @return int ID of line + * + * @url POST {id}/lines + */ + public function addLine($id, $date, $type, $label, $amount, $category = 0, $cheque_number = '', $cheque_writer = '', $cheque_bank = '') + { + if (!DolibarrApiAccess::$user->rights->banque->modifier) { + throw new RestException(401); + } + + $account = new Account($this->db); + $result = $account->fetch($id); + if (!$result) { + throw new RestException(404, 'account not found'); + } + + $result = $account->addline( + $date, + $type, + $label, + $amount, + $cheque_number, + $category, + DolibarrApiAccess::$user, + $cheque_writer, $cheque_bank + ); + if ($result < 0) { + throw new RestException(503, 'Error when adding line to account: '.$account->error); + } + return $result; + } + + /** + * Add a link to an account line + * + * @param int $id ID of account + * @param int $line_id ID of account line + * @param int $url_id ID to set in the URL {@from body} + * @param string $url URL of the link {@from body} + * @param string $label Label {@from body} + * @param string $type Type of link ('payment', 'company', 'member', ...) {@from body} + * @return int ID of link + * + * @url POST {id}/lines/{line_id}/links + */ + public function addLink($id, $line_id, $url_id, $url, $label, $type) + { + if (!DolibarrApiAccess::$user->rights->banque->modifier) { + throw new RestException(401); + } + + $account = new Account($this->db); + $result = $account->fetch($id); + if (!$result) { + throw new RestException(404, 'account not found'); + } + + $accountLine = new AccountLine($this->db); + $result = $accountLine->fetch($line_id); + if (!$result) { + throw new RestException(404, 'account line not found'); + } + + $result = $account->add_url_line($line_id, $url_id, $url, $label, $type); + if ($result < 0) { + throw new RestException(503, 'Error when adding link to account line: '.$account->error); + } + return $result; + } --- /tmp/dsg/dolibarr/htdocs/compta/bank/class/github_19.0.3_bankcateg.class.php +++ /tmp/dsg/dolibarr/htdocs/compta/bank/class/client_bankcateg.class.php @@ -33 +33 @@ - /** + /** @@ -39,28 +39,8 @@ - * @var int ID - */ - public $id; - - /** - * @var string bank categories label - */ - public $label; - - /** - * @var DoliDB - */ - protected $db; - - /** - * @var string error - */ - public $error; - - /** - * @var array errors - */ - public $errors; - - /** - * @var array context - */ - public $context; + * @var int ID + */ + public $id; + + /** + * @var string bank categories label + */ + public $label; @@ -85 +65 @@ - * @return int Return integer <0 if KO, Id of created object if OK + * @return int <0 if KO, Id of created object if OK @@ -103,2 +83,2 @@ - $sql .= " ".(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'"); - $sql .= ", ".((int) $conf->entity); + $sql .= " ".(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'").""; + $sql .= ", ".$conf->entity; @@ -139 +119 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -149 +129 @@ - $sql .= " WHERE t.rowid = ".((int) $id); + $sql .= " WHERE t.rowid = ".$id; @@ -173,3 +153,3 @@ - * @param User|null $user User that modify - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @return int Return integer <0 if KO, >0 if OK + * @param User $user User that modify + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK @@ -192,2 +172,2 @@ - $sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null"); - $sql .= " WHERE rowid=".((int) $this->id); + $sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").""; + $sql .= " WHERE rowid=".$this->id; @@ -224 +204 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -234,9 +214,11 @@ - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account"; - $sql .= " WHERE fk_categorie = ".((int) $this->id); - - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } + if (!$error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account"; + $sql .= " WHERE fk_categorie = ".$this->id; + + $resql = $this->db->query($sql); + if (!$resql) + { + $error++; + $this->errors[] = "Error ".$this->db->lasterror(); + } @@ -246,9 +228,11 @@ - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class"; - $sql .= " WHERE fk_categ = ".((int) $this->id); - - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } + if (!$error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class"; + $sql .= " WHERE fk_categ = ".$this->id; + + $resql = $this->db->query($sql); + if (!$resql) + { + $error++; + $this->errors[] = "Error ".$this->db->lasterror(); + } @@ -258,12 +242,14 @@ - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_categ"; - $sql .= " WHERE rowid=".((int) $this->id); - - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - } - - // Commit or rollback + if (!$error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_categ"; + $sql .= " WHERE rowid=".$this->id; + + $resql = $this->db->query($sql); + if (!$resql) + { + $error++; + $this->errors[] = "Error ".$this->db->lasterror(); + } + } + + // Commit or rollback @@ -301 +287 @@ - // $object->statut = 0; + $object->statut = 0; --- /tmp/dsg/dolibarr/htdocs/compta/bank/class/github_19.0.3_paymentvarious.class.php +++ /tmp/dsg/dolibarr/htdocs/compta/bank/class/client_paymentvarious.class.php @@ -2,2 +2,2 @@ -/* Copyright (C) 2017-2021 Alexandre Spangaro - * Copyright (C) 2018-2023 Frédéric France +/* Copyright (C) 2017-2019 Alexandre Spangaro + * Copyright (C) 2018 Frédéric France @@ -37 +37 @@ - public $element = 'payment_various'; + public $element = 'variouspayment'; @@ -59,3 +58,0 @@ - /** - * @var int timestamp - */ @@ -65,4 +61,0 @@ - - /** - * @var int sens of operation - */ @@ -73,12 +66,7 @@ - public $chqemetteur; - public $chqbank; - public $category_transaction; - - /** - * @var string various payments label - */ - public $label; - - /** - * @var string accountancy code - */ + public $category_transaction; + + /** + * @var string various payments label + */ + public $label; + @@ -87,8 +75,5 @@ - /** - * @var string subledger account - */ - public $subledger_account; - - /** - * @var int ID - */ + public $subledger_account; + + /** + * @var int ID + */ @@ -98,13 +83,2 @@ - * @var int Bank account ID - */ - public $fk_account; - - /** - * @var int Bank account ID - * @deprecated See fk_account - */ - public $accountid; - - /** - * @var int ID record into llx_bank - */ + * @var int ID + */ @@ -114,7 +88,2 @@ - * @var int transaction category - */ - public $categorie_transaction; - - /** - * @var int ID - */ + * @var int ID + */ @@ -124,2 +93,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -130,56 +98,0 @@ - * @var int Type of bank account if the payment is on a bank account - */ - public $fk_type; - - /** - * @var int 1 if the payment is on a bank account line that is conciliated - */ - public $rappro; - - /** - * @var string ID of bank receipt - */ - public $bank_num_releve; - - - /** - * 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password') - * Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)" - * 'label' the translation key. - * 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM) - * 'position' is the sort order of field. - * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). - * 'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only, 3=Visible on create/update/view form only (not list), 4=Visible on list and update/view form only (not create). 5=Visible on list and view only (not create/not update). Using a negative value means field is not shown by default on list but can be selected for viewing) - * 'noteditable' says if field is not editable (1 or 0) - * 'default' is a default value for creation (can still be overwrote by the Setup of Default Values if field is editable in creation form). Note: If default is set to '(PROV)' and field is 'ref', the default value will be set to '(PROVid)' where id is rowid when a new record is created. - * 'index' if we want an index in database. - * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...). - * 'searchall' is 1 if we want to search in this field when making a search from the quick search button. - * 'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8). - * 'css' is the CSS style to use on field. For example: 'maxwidth200' - * 'help' is a string visible as a tooltip on field - * 'showoncombobox' if value of the field must be visible into the label of the combobox that list record - * 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute. In most cases, this is never set into the definition of $fields into class, but is set dynamically by some part of code. - * 'arrayofkeyval' to set list of value if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel") - * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1. - * 'comment' is not used. You can store here any text of your choice. It is not used by application. - * - * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor. - */ - - // BEGIN MODULEBUILDER PROPERTIES - /** - * @var array fields definition - */ - public $fields = array( - // TODO: fill this array - ); - // END MODULEBUILDER PROPERTIES - - /** - * Draft status - */ - const STATUS_DRAFT = 0; - - - /** @@ -190 +103 @@ - public function __construct(DoliDB $db) + public function __construct($db) @@ -192,0 +106,2 @@ + $this->element = 'payment_various'; + $this->table_element = 'payment_various'; @@ -200,3 +115,3 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function update($user = null, $notrigger = 0) + * @return int <0 if KO, >0 if OK + */ + public function update($user = null, $notrigger = 0) @@ -220,3 +135 @@ - if ($this->tms) { - $sql .= " tms='".$this->db->idate($this->tms)."',"; - } + if ($this->tms) $sql .= " tms='".$this->db->idate($this->tms)."',"; @@ -227 +140 @@ - $sql .= " fk_typepayment=".(int) $this->type_payment.","; + $sql .= " fk_typepayment=".(int) $this->fk_typepayment.","; @@ -232 +145 @@ - $sql .= " subledger_account='".$this->db->escape($this->subledger_account)."',"; + $sql .= " subledger_account='".$this->db->escape($this->subledger_account)."',"; @@ -237 +150 @@ - $sql .= " WHERE rowid=".((int) $this->id); + $sql .= " WHERE rowid=".$this->id; @@ -241 +154,2 @@ - if (!$resql) { + if (!$resql) + { @@ -246 +160,2 @@ - if (!$notrigger) { + if (!$notrigger) + { @@ -249,3 +164 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -255 +168,2 @@ - if (!$error) { + if (!$error) + { @@ -258 +172,3 @@ - } else { + } + else + { @@ -270,4 +186,5 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function fetch($id, $user = null) - { + * @return int <0 if KO, >0 if OK + */ + public function fetch($id, $user = null) + { + global $langs; @@ -284 +201 @@ - $sql .= " v.note as note_private,"; + $sql .= " v.note,"; @@ -293,2 +210 @@ - $sql .= " b.rappro,"; - $sql .= " b.num_releve as bank_num_releve"; + $sql .= " b.rappro"; @@ -297 +213 @@ - $sql .= " WHERE v.rowid = ".((int) $id); + $sql .= " WHERE v.rowid = ".$id; @@ -301,2 +217,4 @@ - if ($resql) { - if ($this->db->num_rows($resql)) { + if ($resql) + { + if ($this->db->num_rows($resql)) + { @@ -315,2 +233 @@ - $this->note = $obj->note_private; // For backward compatibility - $this->note_private = $obj->note_private; + $this->note = $obj->note; @@ -326 +242,0 @@ - $this->bank_num_releve = $obj->bank_num_releve; @@ -331 +247,3 @@ - } else { + } + else + { @@ -342,3 +260,3 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function delete($user) + * @return int <0 if KO, >0 if OK + */ + public function delete($user) @@ -352,3 +270 @@ - if ($result < 0) { - return -1; - } + if ($result < 0) return -1; @@ -359 +275 @@ - $sql .= " WHERE rowid=".((int) $this->id); + $sql .= " WHERE rowid=".$this->id; @@ -363 +279,2 @@ - if (!$resql) { + if (!$resql) + { @@ -379 +296 @@ - public function initAsSpecimen() + public function initAsSpecimen() @@ -390 +307 @@ - $this->subledger_account = ''; + $this->subledger_account = ''; @@ -398,17 +314,0 @@ - * Check if a miscellaneous payment can be created into database - * - * @return boolean True or false - */ - public function check() - { - $newamount = price2num($this->amount, 'MT'); - - // Validation of parameters - if (!($newamount) > 0 || empty($this->datep)) { - return false; - } - - return true; - } - - /** @@ -418,3 +318,3 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function create($user) + * @return int <0 if KO, >0 if OK + */ + public function create($user) @@ -434,4 +333,0 @@ - $this->fk_account = (int) $this->fk_account; - if (empty($this->fk_account) && isset($this->accountid)) { // For compatibility - $this->fk_account = $this->accountid; - } @@ -440 +336,2 @@ - if (!$this->label) { + if (!$this->label) + { @@ -444 +341,2 @@ - if ($this->amount < 0 || $this->amount == '') { + if ($this->amount < 0 || $this->amount == '') + { @@ -448,2 +346,3 @@ - if (isModEnabled("banque") && (empty($this->fk_account) || $this->fk_account <= 0)) { - $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("BankAccount")); + if (!empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0)) + { + $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Account")); @@ -452 +351,2 @@ - if (isModEnabled("banque") && (empty($this->type_payment) || $this->type_payment <= 0)) { + if (!empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0)) + { @@ -467,3 +367 @@ - if ($this->note) { - $sql .= ", note"; - } + if ($this->note) $sql .= ", note"; @@ -486,3 +384 @@ - if ($this->note) { - $sql .= ", '".$this->db->escape($this->note)."'"; - } + if ($this->note) $sql .= ", '".$this->db->escape($this->note)."'"; @@ -492,2 +388,2 @@ - $sql .= ", ".($this->fk_project > 0 ? ((int) $this->fk_project) : 0); - $sql .= ", ".((int) $user->id); + $sql .= ", ".($this->fk_project > 0 ? $this->fk_project : 0); + $sql .= ", ".$user->id; @@ -495,2 +391,2 @@ - $sql .= ", NULL"; // Filled later - $sql .= ", ".((int) $conf->entity); + $sql .= ", NULL"; + $sql .= ", ".$conf->entity; @@ -501 +397,2 @@ - if ($result) { + if ($result) + { @@ -505,2 +402,4 @@ - if ($this->id > 0) { - if (isModEnabled("banque") && !empty($this->amount)) { + if ($this->id > 0) + { + if (!empty($conf->banque->enabled) && !empty($this->amount)) + { @@ -511,4 +410,2 @@ - $result = $acc->fetch($this->fk_account); - if ($result <= 0) { - dol_print_error($this->db); - } + $result = $acc->fetch($this->accountid); + if ($result <= 0) dol_print_error($this->db); @@ -519,5 +416,3 @@ - if ($this->sens == '0') { - $sign = -1; - } - - $bank_line_id = $acc->addline( + if ($this->sens == '0') $sign = -1; + + $bank_line_id = $acc->addline( @@ -529 +424 @@ - ($this->category_transaction > 0 ? $this->category_transaction : 0), + ($this->category_transaction > 0 ? $this->category_transaction : 0), @@ -531,2 +426,2 @@ - $this->chqemetteur, - $this->chqbank, + '', + '', @@ -537 +432 @@ - // Update fk_bank into llx_payment_various + // Update fk_bank into llx_paiement. @@ -539 +434,2 @@ - if ($bank_line_id > 0) { + if ($bank_line_id > 0) + { @@ -541 +437,3 @@ - } else { + } + else + { @@ -546 +444,2 @@ - if (!$error) { + if (!$error) + { @@ -551 +450,2 @@ - if ($result <= 0) { + if ($result <= 0) + { @@ -557 +457,2 @@ - if ($result <= 0) { + if ($result <= 0) + { @@ -565,3 +466 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -569,2 +467,0 @@ - } else { - $error++; @@ -572,2 +469,4 @@ - - if (!$error) { + else $error++; + + if (!$error) + { @@ -576 +475,3 @@ - } else { + } + else + { @@ -580 +481,3 @@ - } else { + } + else + { @@ -587 +490 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -592,7 +495,7 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function update_fk_bank($id_bank) - { - // phpcs:enable - $sql = 'UPDATE '.MAIN_DB_PREFIX.'payment_various SET fk_bank = '.((int) $id_bank); - $sql .= " WHERE rowid = ".((int) $this->id); + * @return int <0 if KO, >0 if OK + */ + public function update_fk_bank($id_bank) + { + // phpcs:enable + $sql = 'UPDATE '.MAIN_DB_PREFIX.'payment_various SET fk_bank = '.$id_bank; + $sql .= ' WHERE rowid = '.$this->id; @@ -600 +503,2 @@ - if ($result) { + if ($result) + { @@ -602 +506,3 @@ - } else { + } + else + { @@ -610,6 +516,6 @@ - * 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 - */ - public function getLibStatut($mode = 0) + * Retourne le libelle du statut + * + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto + * @return string Libelle + */ + public function getLibStatut($mode = 0) @@ -620,11 +526,11 @@ - // 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 + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Renvoi le libelle d'un statut donne + * + * @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 + * @return string Libelle + */ + public function LibStatut($status, $mode = 0) + { + // phpcs:enable @@ -633,16 +539,32 @@ - if (empty($status)) { - $status = 0; - } - - if (empty($this->labelStatus) || empty($this->labelStatusShort)) { - $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft'); - //$this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled'); - //$this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled'); - $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft'); - //$this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Enabled'); - //$this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Disabled'); - } - - $statusType = 'status'.$status; - - return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); + if ($mode == 0) + { + return $langs->trans($this->statuts[$status]); + } + elseif ($mode == 1) + { + return $langs->trans($this->statuts_short[$status]); + } + elseif ($mode == 2) + { + if ($status == 0) return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts_short[$status]); + elseif ($status == 1) return img_picto($langs->trans($this->statuts_short[$status]), 'statut4').' '.$langs->trans($this->statuts_short[$status]); + elseif ($status == 2) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts_short[$status]); + } + elseif ($mode == 3) + { + if ($status == 0 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut0'); + elseif ($status == 1 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut4'); + elseif ($status == 2 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6'); + } + elseif ($mode == 4) + { + if ($status == 0 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut0').' '.$langs->trans($this->statuts[$status]); + elseif ($status == 1 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut4').' '.$langs->trans($this->statuts[$status]); + elseif ($status == 2 && !empty($this->statuts_short[$status])) return img_picto($langs->trans($this->statuts_short[$status]), 'statut6').' '.$langs->trans($this->statuts[$status]); + } + elseif ($mode == 5) + { + if ($status == 0 && !empty($this->statuts_short[$status])) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut0'); + elseif ($status == 1 && !empty($this->statuts_short[$status])) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut4'); + elseif ($status == 2 && !empty($this->statuts_short[$status])) return $langs->trans($this->statuts_short[$status]).' '.img_picto($langs->trans($this->statuts_short[$status]), 'statut6'); + } @@ -658,2 +580 @@ - * @param int $notooltip 1=Disable tooltip - * @param string $morecss morecss string + * @param int $notooltip 1=Disable tooltip @@ -662 +583 @@ - public function getNomUrl($withpicto = 0, $option = '', $save_lastsearch_value = -1, $notooltip = 0, $morecss = '') + public function getNomUrl($withpicto = 0, $option = '', $save_lastsearch_value = -1, $notooltip = 0) @@ -667,3 +588 @@ - if (!empty($conf->dol_no_mouse_hover)) { - $notooltip = 1; // Force disable tooltips - } + if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips @@ -679 +598,2 @@ - if ($option != 'nolink') { + if ($option != 'nolink') + { @@ -682,6 +602,2 @@ - if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { - $add_save_lastsearch_values = 1; - } - if ($add_save_lastsearch_values) { - $url .= '&save_lastsearch_values=1'; - } + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; @@ -691,2 +607,4 @@ - if (empty($notooltip)) { - if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { + if (empty($notooltip)) + { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { @@ -698,3 +616,9 @@ - } else { - $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); - } + + /* + $hookmanager->initHooks(array('myobjectdao')); + $parameters=array('id'=>$this->id); + $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if ($reshook > 0) $linkclose = $hookmanager->resPrint; + */ + } + else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); @@ -707,6 +631,2 @@ - if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - } - if ($withpicto != 2) { - $result .= $this->ref; - } + if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + if ($withpicto != 2) $result .= $this->ref; @@ -718 +638 @@ - $parameters = array('id'=>$this->id, 'getnomurl' => &$result); + $parameters = array('id'=>$this->id, 'getnomurl'=>$result); @@ -720,5 +640,2 @@ - if ($reshook > 0) { - $result = $hookmanager->resPrint; - } else { - $result .= $hookmanager->resPrint; - } + if ($reshook > 0) $result = $hookmanager->resPrint; + else $result .= $hookmanager->resPrint; @@ -735,2 +652,2 @@ - public function info($id) - { + public function info($id) + { @@ -739 +656 @@ - $sql .= ' WHERE v.rowid = '.((int) $id); + $sql .= ' WHERE v.rowid = '.$id; @@ -744,2 +661,4 @@ - if ($result) { - if ($this->db->num_rows($result)) { + if ($result) + { + if ($this->db->num_rows($result)) + { @@ -747 +665,0 @@ - @@ -749,2 +667,6 @@ - $this->user_creation = $obj->fk_user_author; - $this->user_modification_id = $obj->fk_user_modif; + if ($obj->fk_user_author) + { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_author); + $this->user_creation = $cuser; + } @@ -752 +674,7 @@ - $this->date_modification = $this->db->jdate($obj->tms); + if ($obj->fk_user_modif) + { + $muser = new User($this->db); + $muser->fetch($obj->fk_user_modif); + $this->user_modif = $muser; + } + $this->date_modif = $this->db->jdate($obj->tms); @@ -755 +683,3 @@ - } else { + } + else + { @@ -763 +693 @@ - * @return int Return integer <0 if KO, 0=no, 1=yes + * @return int <0 if KO, 0=no, 1=yes @@ -773 +703 @@ - $sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type)."' AND ab.fk_doc = ".((int) $banklineid); + $sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$type."' AND ab.fk_doc = ".$banklineid; @@ -775 +705,2 @@ - if ($resql) { + if ($resql) + { @@ -777 +708,2 @@ - if ($obj) { + if ($obj) + { @@ -780 +712,3 @@ - } else { + } + else + { @@ -785 +719,2 @@ - if ($alreadydispatched) { + if ($alreadydispatched) + { @@ -790,76 +724,0 @@ - - /** - * Return clicable link of object (with eventually picto) - * - * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link) - * @param array $arraydata Array of data - * @return string HTML Code for Kanban thumb. - */ - public function getKanbanView($option = '', $arraydata = null) - { - global $langs; - - $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, 'fk_bank')) { - $return .= ' | '.$this->fk_bank.''; - } - if (property_exists($this, 'datep')) { - $return .= '
'.$langs->trans("Date").' : '.dol_print_date($this->db->jdate($this->datep), 'day').''; - } - if (property_exists($this, 'type_payment') && !empty($this->type_payment)) { - $return .= '
'.$langs->trans("Payment", $this->type_payment).' : '.$this->type_payment.''; - } - if (property_exists($this, 'accountancy_code')) { - $return .= '
'.$langs->trans("Account").' : '.$this->accountancy_code.''; - } - if (property_exists($this, 'amount')) { - $return .= '
'.$langs->trans("Debit").' : '.price($this->amount).''; - } - $return .= '
'; - $return .= '
'; - $return .= '
'; - return $return; - } - - /** - * Return General accounting account with defined length (used for product and miscellaneous) - * - * @param string $account General accounting account - * @return string String with defined length - */ - public function lengthAccountg($account) - { - include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; - - /* - if (isModEnabled('accounting')) { - $accountingaccount = new AccountingAccount($db); - $accountingaccount->fetch('', $valuetoshow, 1); - }*/ - - return length_accountg($account); - } - - /** - * Return Auxiliary accounting account of thirdparties with defined length - * - * @param string $account Auxiliary accounting account - * @return string String with defined length - */ - public function lengthAccounta($account) - { - include_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; - - return length_accounta($account); - }