--- /tmp/dsg/dolibarr/htdocs/compta/paiement/cheque/class/github_remisecheque.class.php +++ /tmp/dsg/dolibarr/htdocs/compta/paiement/cheque/class/client_remisecheque.class.php @@ -74,12 +74,12 @@ * * @param DoliDB $db Database handler */ - public function __construct($db) - { + public function __construct($db) + { $this->db = $db; $this->next_id = 0; $this->previous_id = 0; - } + } /** * Load record @@ -88,8 +88,8 @@ * @param string $ref Ref record * @return int <0 if KO, > 0 if OK */ - public function fetch($id, $ref = '') - { + public function fetch($id, $ref = '') + { global $conf; $sql = "SELECT bc.rowid, bc.datec, bc.fk_user_author, bc.fk_bank_account, bc.amount, bc.ref, bc.statut, bc.nbcheque, bc.ref_ext"; @@ -98,7 +98,7 @@ $sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON bc.fk_bank_account = ba.rowid"; $sql .= " WHERE bc.entity = ".$conf->entity; - if ($id) $sql .= " AND bc.rowid = ".((int) $id); + if ($id) $sql .= " AND bc.rowid = ".$id; if ($ref) $sql .= " AND bc.ref = '".$this->db->escape($ref)."'"; dol_syslog("RemiseCheque::fetch", LOG_DEBUG); @@ -120,18 +120,22 @@ if ($this->statut == 0) { $this->ref = "(PROV".$this->id.")"; - } else { + } + else + { $this->ref = $obj->ref; } } $this->db->free($resql); return 1; - } else { - $this->error = $this->db->lasterror(); + } + else + { + $this->error = $this->db->lasterror(); return -1; } - } + } /** * Create a receipt to send cheques @@ -142,8 +146,8 @@ * @param array $toRemise array with cheques to remise * @return int <0 if KO, >0 if OK */ - public function create($user, $account_id, $limit, $toRemise) - { + public function create($user, $account_id, $limit, $toRemise) + { global $conf; $this->errno = 0; @@ -211,7 +215,7 @@ $sql .= " WHERE b.fk_type = 'CHQ'"; $sql .= " AND b.amount > 0"; $sql .= " AND b.fk_bordereau = 0"; - $sql .= " AND b.fk_account = ".((int) $account_id); + $sql .= " AND b.fk_account='".$account_id."'"; if ($limit) $sql .= $this->db->plimit($limit); dol_syslog("RemiseCheque::Create", LOG_DEBUG); @@ -223,7 +227,9 @@ array_push($lines, $row[0]); } $this->db->free($resql); - } else { + } + else + { $this->errno = -1026; dol_syslog("RemiseCheque::Create Error ".$this->errno, LOG_ERR); } @@ -263,28 +269,32 @@ dol_syslog("RemiseCheque::Create Error update amount ".$this->errno, LOG_ERR); } } - } else { + } + else + { $this->errno = -1; $this->error = $this->db->lasterror(); $this->errno = $this->db->lasterrno(); } - if (!$this->errno && !empty($conf->global->MAIN_DISABLEDRAFTSTATUS)) - { - $res = $this->validate($user); - //if ($res < 0) $error++; - } - - if (!$this->errno) - { - $this->db->commit(); - dol_syslog("RemiseCheque::Create end", LOG_DEBUG); - return $this->id; - } else { - $this->db->rollback(); - dol_syslog("RemiseCheque::Create end", LOG_DEBUG); - return $this->errno; - } + if (!$this->errno && !empty($conf->global->MAIN_DISABLEDRAFTSTATUS)) + { + $res = $this->validate($user); + //if ($res < 0) $error++; + } + + if (!$this->errno) + { + $this->db->commit(); + dol_syslog("RemiseCheque::Create end", LOG_DEBUG); + return $this->id; + } + else + { + $this->db->rollback(); + dol_syslog("RemiseCheque::Create end", LOG_DEBUG); + return $this->errno; + } } /** @@ -293,8 +303,8 @@ * @param User $user Utilisateur qui effectue l'operation * @return int */ - public function delete($user = '') - { + public function delete($user = '') + { global $conf; $this->errno = 0; @@ -315,15 +325,15 @@ } if ($this->errno === 0) { - $sql = "UPDATE ".MAIN_DB_PREFIX."bank"; - $sql .= " SET fk_bordereau = 0"; - $sql .= " WHERE fk_bordereau = ".$this->id; - - $resql = $this->db->query($sql); - if (!$resql) - { - $this->errno = -1028; - dol_syslog("RemiseCheque::Delete ERREUR UPDATE ($this->errno)"); + $sql = "UPDATE ".MAIN_DB_PREFIX."bank"; + $sql .= " SET fk_bordereau = 0"; + $sql .= " WHERE fk_bordereau = ".$this->id; + + $resql = $this->db->query($sql); + if (!$resql) + { + $this->errno = -1028; + dol_syslog("RemiseCheque::Delete ERREUR UPDATE ($this->errno)"); } } } @@ -331,7 +341,9 @@ if ($this->errno === 0) { $this->db->commit(); - } else { + } + else + { $this->db->rollback(); dol_syslog("RemiseCheque::Delete ROLLBACK ($this->errno)"); } @@ -345,8 +357,8 @@ * @param User $user User * @return int <0 if KO, >0 if OK */ - public function validate($user) - { + public function validate($user) + { global $langs, $conf; $this->errno = 0; @@ -358,7 +370,7 @@ if ($this->errno == 0 && $numref) { $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque"; - $sql .= " SET statut = 1, ref = '".$this->db->escape($numref)."'"; + $sql .= " SET statut = 1, ref = '".$numref."'"; $sql .= " WHERE rowid = ".$this->id; $sql .= " AND entity = ".$conf->entity; $sql .= " AND statut = 0"; @@ -371,13 +383,17 @@ if ($num == 1) { - $this->ref = $numref; + $this->ref = $numref; $this->statut = 1; - } else { + } + else + { $this->errno = -1029; dol_syslog("Remisecheque::Validate Error ".$this->errno, LOG_ERR); } - } else { + } + else + { $this->errno = -1033; dol_syslog("Remisecheque::Validate Error ".$this->errno, LOG_ERR); } @@ -388,10 +404,12 @@ { $this->db->commit(); return 1; - } else { + } + else + { $this->db->rollback(); dol_syslog("RemiseCheque::Validate ".$this->errno, LOG_ERR); - return $this->errno; + return $this->errno; } } @@ -402,8 +420,8 @@ * @param string $mode 'next' for next value or 'last' for last value * @return string free ref or last ref */ - public function getNextNumRef($mode = 'next') - { + public function getNextNumRef($mode = 'next') + { global $conf, $db, $langs, $mysoc; $langs->load("bills"); @@ -470,24 +488,26 @@ } return $numref; - } else { + } + else + { $langs->load("errors"); print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Bank")); return ""; } - } - - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + } + + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Load indicators for dashboard (this->nbtodo and this->nbtodolate) * * @param User $user Objet user * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK */ - public function load_board($user) - { - // phpcs:enable + public function load_board($user) + { + // phpcs:enable global $conf, $langs; if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe @@ -524,23 +544,25 @@ } return $response; - } else { + } + else + { dol_print_error($this->db); $this->error = $this->db->error(); return -1; } - } - - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + } + + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Charge indicateurs this->nb de tableau de bord * * @return int <0 if ko, >0 if ok */ - public function load_state_board() - { - // phpcs:enable + public function load_state_board() + { + // phpcs:enable global $user; if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe @@ -562,12 +584,14 @@ } $this->db->free($resql); return 1; - } else { + } + else + { dol_print_error($this->db); $this->error = $this->db->error(); return -1; } - } + } /** @@ -577,8 +601,8 @@ * @param Translate $outputlangs Object langs * @return int <0 if KO, >0 if OK */ - public function generatePdf($model, $outputlangs) - { + public function generatePdf($model, $outputlangs) + { global $langs, $conf; if (empty($model)) $model = 'blochet'; @@ -640,29 +664,32 @@ { //$outputlangs->charset_output=$sav_charset_output; return 1; - } else { + } + else + { //$outputlangs->charset_output=$sav_charset_output; dol_syslog("Error"); dol_print_error($this->db, $docmodel->error); return 0; } - } else { + } + else + { $this->error = $langs->trans("ErrorFileDoesNotExists", $dir.$file); return -1; } - } + } /** * Mets a jour le montant total * * @return int 0 en cas de succes */ - public function updateAmount() - { + public function updateAmount() + { global $conf; $this->errno = 0; - $this->db->begin(); $total = 0; $nb = 0; @@ -682,8 +709,8 @@ $this->db->free($resql); $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque"; - $sql .= " SET amount = ".price2num($total); - $sql .= ", nbcheque = ".((int) $nb); + $sql .= " SET amount = '".price2num($total)."'"; + $sql .= ", nbcheque = ".$nb; $sql .= " WHERE rowid = ".$this->id; $sql .= " AND entity = ".$conf->entity; @@ -693,7 +720,9 @@ $this->errno = -1030; dol_syslog("RemiseCheque::updateAmount ERREUR UPDATE ($this->errno)"); } - } else { + } + else + { $this->errno = -1031; dol_syslog("RemiseCheque::updateAmount ERREUR SELECT ($this->errno)"); } @@ -701,13 +730,15 @@ if ($this->errno === 0) { $this->db->commit(); - } else { + } + else + { $this->db->rollback(); dol_syslog("RemiseCheque::updateAmount ROLLBACK ($this->errno)"); } return $this->errno; - } + } /** * Insere la remise en base @@ -715,28 +746,30 @@ * @param int $account_id Compte bancaire concerne * @return int */ - public function removeCheck($account_id) - { + public function removeCheck($account_id) + { $this->errno = 0; if ($this->id > 0) { $sql = "UPDATE ".MAIN_DB_PREFIX."bank"; $sql .= " SET fk_bordereau = 0"; - $sql .= " WHERE rowid = ".((int) $account_id); - $sql .= " AND fk_bordereau = ".((int) $this->id); + $sql .= " WHERE rowid = '".$account_id."'"; + $sql .= " AND fk_bordereau = ".$this->id; $resql = $this->db->query($sql); if ($resql) { $this->updateAmount(); - } else { + } + else + { $this->errno = -1032; dol_syslog("RemiseCheque::removeCheck ERREUR UPDATE ($this->errno)"); } } return 0; - } + } /** * Check return management @@ -746,8 +779,8 @@ * @param integer $rejection_date Date to use on the negative payment * @return int Id of negative payment line created */ - public function rejectCheck($bank_id, $rejection_date) - { + public function rejectCheck($bank_id, $rejection_date) + { global $db, $user; $payment = new Paiement($db); @@ -775,18 +808,18 @@ $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf'; $sql .= ' WHERE pf.fk_paiement = '.$payment->id; - $resql = $this->db->query($sql); + $resql = $db->query($sql); if ($resql) { - $rejectedPayment = new Paiement($this->db); + $rejectedPayment = new Paiement($db); $rejectedPayment->amounts = array(); $rejectedPayment->datepaye = $rejection_date; $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement', 'code', 'id', 1); $rejectedPayment->num_payment = $payment->num_payment; - while ($obj = $this->db->fetch_object($resql)) - { - $invoice = new Facture($this->db); + while ($obj = $db->fetch_object($resql)) + { + $invoice = new Facture($db); $invoice->fetch($obj->fk_facture); $invoice->set_unpaid($user); @@ -796,47 +829,55 @@ $result = $rejectedPayment->create($user); if ($result > 0) { - // We created a negative payment, we also add the line as bank transaction - $result = $rejectedPayment->addPaymentToBank($user, 'payment', '(CheckRejected)', $bankaccount, '', ''); + // We created a negative payment, we also add the line as bank transaction + $result = $rejectedPayment->addPaymentToBank($user, 'payment', '(CheckRejected)', $bankaccount, '', ''); if ($result > 0) { - $result = $payment->reject(); + $result = $payment->reject(); if ($result > 0) { - $this->db->commit(); - return $rejectedPayment->id; - } else { - $this->db->rollback(); - return -1; + $this->db->commit(); + return $rejectedPayment->id; } - } else { - $this->error = $rejectedPayment->error; - $this->errors = $rejectedPayment->errors; - $this->db->rollback(); + else + { + $this->db->rollback(); + return -1; + } + } + else + { + $this->error = $rejectedPayment->error; + $this->errors = $rejectedPayment->errors; + $this->db->rollback(); return -1; } - } else { + } + else + { $this->error = $rejectedPayment->error; $this->errors = $rejectedPayment->errors; - $this->db->rollback(); + $this->db->rollback(); return -1; } - } else { + } + else + { $this->error = $this->db->lasterror(); $this->db->rollback(); return -1; } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Charge les proprietes ref_previous et ref_next * * @return int <0 if KO, 0 if OK */ - public function load_previous_next_id() - { - // phpcs:enable + public function load_previous_next_id() + { + // phpcs:enable global $conf; $this->errno = 0; @@ -871,39 +912,43 @@ } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Set the creation date - * - * @param User $user Object user - * @param int $date Date creation - * @return int <0 if KO, >0 if OK - */ - public function set_date($user, $date) - { - // phpcs:enable - if ($user->rights->banque->cheque) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque"; - $sql .= " SET date_bordereau = ".($date ? "'".$this->db->idate($date)."'" : 'null'); - $sql .= " WHERE rowid = ".$this->id; - - dol_syslog("RemiseCheque::set_date", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) - { - $this->date_bordereau = $date; - return 1; - } else { - $this->error = $this->db->error(); - return -1; - } - } else { - return -2; - } - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Set the creation date + * + * @param User $user Object user + * @param int $date Date creation + * @return int <0 if KO, >0 if OK + */ + public function set_date($user, $date) + { + // phpcs:enable + if ($user->rights->banque->cheque) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque"; + $sql .= " SET date_bordereau = ".($date ? "'".$this->db->idate($date)."'" : 'null'); + $sql .= " WHERE rowid = ".$this->id; + + dol_syslog("RemiseCheque::set_date", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + $this->date_bordereau = $date; + return 1; + } + else + { + $this->error = $this->db->error(); + return -1; + } + } + else + { + return -2; + } + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set the ref of bordereau * @@ -911,9 +956,9 @@ * @param int $ref ref of bordereau * @return int <0 if KO, >0 if OK */ - public function set_number($user, $ref) - { - // phpcs:enable + public function set_number($user, $ref) + { + // phpcs:enable if ($user->rights->banque->cheque) { $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque"; @@ -925,11 +970,15 @@ if ($resql) { return 1; - } else { + } + else + { $this->error = $this->db->error(); return -1; } - } else { + } + else + { return -2; } } @@ -942,8 +991,8 @@ * @param string $option ''=Create a specimen invoice with lines, 'nolines'=No lines * @return void */ - public function initAsSpecimen($option = '') - { + public function initAsSpecimen($option = '') + { global $user, $langs, $conf; $now = dol_now(); @@ -955,20 +1004,20 @@ $this->ref = 'SPECIMEN'; $this->specimen = 1; $this->date_bordereau = $nownotime; - } + } /** * Return clicable name (with picto eventually) * * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto * @param string $option Sur quoi pointe le lien - * @param int $notooltip 1=Disable tooltip - * @param string $morecss Add more css on link - * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @param int $notooltip 1=Disable tooltip + * @param string $morecss Add more css on link + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking * @return string Chaine avec URL */ - public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) - { + public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) + { global $conf, $langs; $result = ''; @@ -977,27 +1026,28 @@ $label .= '
'; $label .= ''.$langs->trans('Ref').': '.$this->ref; - $url = DOL_URL_ROOT.'/compta/paiement/cheque/card.php?id='.$this->id; - - if ($option != 'nolink') - { - // Add param to save lastsearch_values or not - $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; - if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; - } - - $linkclose = ''; - if (empty($notooltip)) - { - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { - $label = $langs->trans("ShowCheckReceipt"); - $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; - } - $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; - } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); + $url = DOL_URL_ROOT.'/compta/paiement/cheque/card.php?id='.$this->id; + + if ($option != 'nolink') + { + // Add param to save lastsearch_values or not + $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; + } + + $linkclose = ''; + if (empty($notooltip)) + { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { + $label = $langs->trans("ShowCheckReceipt"); + $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; + } + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; + } + else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); $linkstart = ''; @@ -1009,7 +1059,7 @@ $result .= $linkend; return $result; - } + } /** * Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) @@ -1017,12 +1067,12 @@ * @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 */ - public function getLibStatut($mode = 0) - { - return $this->LibStatut($this->statut, $mode); - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + public function getLibStatut($mode = 0) + { + return $this->LibStatut($this->statut, $mode); + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Return label of a status * @@ -1030,22 +1080,22 @@ * @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 Libelle du statut */ - public function LibStatut($status, $mode = 0) - { - // phpcs:enable - if (empty($this->labelStatus) || empty($this->labelStatusShort)) - { - global $langs; - $langs->load('compta'); - $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('ToValidate'); - $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated'); - $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('ToValidate'); - $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Validated'); - } - - $statusType = 'status'.$status; - if ($status == self::STATUS_VALIDATED) $statusType = 'status4'; - - return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); - } + public function LibStatut($status, $mode = 0) + { + // phpcs:enable + if (empty($this->labelStatus) || empty($this->labelStatusShort)) + { + global $langs; + $langs->load('compta'); + $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('ToValidate'); + $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated'); + $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('ToValidate'); + $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Validated'); + } + + $statusType = 'status'.$status; + if ($status == self::STATUS_VALIDATED) $statusType = 'status4'; + + return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); + } }