--- /tmp/dsg/dolibarr/htdocs/loan/class/github_19.0.3_loan.class.php +++ /tmp/dsg/dolibarr/htdocs/loan/class/client_loan.class.php @@ -3 +3 @@ - * Copyright (C) 2015-2023 Frédéric France + * Copyright (C) 2015-2018 Frédéric France @@ -57,4 +57,4 @@ - /** - * @var string Loan label - */ - public $label; + /** + * @var string Loan label + */ + public $label; @@ -69,7 +69,4 @@ - public $accountancy_account_capital; - public $accountancy_account_insurance; - public $accountancy_account_interest; - - /** - * @var integer|string date_creation - */ + + /** + * @var integer|string date_creation + */ @@ -91,2 +88,2 @@ - * @var int Bank ID - */ + * @var int Bank ID + */ @@ -96,2 +93,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -101,2 +98,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -106,2 +103,2 @@ - * @var int ID - */ + * @var int ID + */ @@ -110,4 +106,0 @@ - /** - * @var int totalpaid - */ - public $totalpaid; @@ -117 +109,0 @@ - const STATUS_STARTED = 2; @@ -134 +126 @@ - * @return int Return integer <0 error , >=0 no error + * @return int <0 error , >=0 no error @@ -139 +131 @@ - $sql .= " l.paid, l.fk_bank, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest, l.fk_projet as fk_project"; + $sql .= " l.paid, l.accountancy_account_capital, l.accountancy_account_insurance, l.accountancy_account_interest, l.fk_projet as fk_project"; @@ -141 +133 @@ - $sql .= " WHERE l.rowid = ".((int) $id); + $sql .= " WHERE l.rowid = ".$id; @@ -145,2 +137,4 @@ - if ($resql) { - if ($this->db->num_rows($resql)) { + if ($resql) + { + if ($this->db->num_rows($resql)) + { @@ -161 +154,0 @@ - $this->fk_bank = $obj->fk_bank; @@ -170 +163,3 @@ - } else { + } + else + { @@ -174 +169,3 @@ - } else { + } + else + { @@ -185 +182 @@ - * @return int Return integer <0 if KO, id if OK + * @return int <0 if KO, id if OK @@ -197,3 +194 @@ - if (empty($this->insurance_amount)) { - $this->insurance_amount = 0; - } + if (empty($this->insurance_amount)) $this->insurance_amount = 0; @@ -201,27 +196,9 @@ - if (isset($this->note_private)) { - $this->note_private = trim($this->note_private); - } - if (isset($this->note_public)) { - $this->note_public = trim($this->note_public); - } - if (isset($this->account_capital)) { - $this->account_capital = trim($this->account_capital); - } - if (isset($this->account_insurance)) { - $this->account_insurance = trim($this->account_insurance); - } - if (isset($this->account_interest)) { - $this->account_interest = trim($this->account_interest); - } - if (isset($this->fk_bank)) { - $this->fk_bank = (int) $this->fk_bank; - } - if (isset($this->fk_user_creat)) { - $this->fk_user_creat = (int) $this->fk_user_creat; - } - if (isset($this->fk_user_modif)) { - $this->fk_user_modif = (int) $this->fk_user_modif; - } - if (isset($this->fk_project)) { - $this->fk_project = (int) $this->fk_project; - } + if (isset($this->note_private)) $this->note_private = trim($this->note_private); + if (isset($this->note_public)) $this->note_public = trim($this->note_public); + if (isset($this->account_capital)) $this->account_capital = trim($this->account_capital); + if (isset($this->account_insurance)) $this->account_insurance = trim($this->account_insurance); + if (isset($this->account_interest)) $this->account_interest = trim($this->account_interest); + if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank; + if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat; + if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif; + if (isset($this->fk_project)) $this->fk_project = (int) $this->fk_project; @@ -230 +207,2 @@ - if (!($newcapital > 0) || empty($this->datestart) || empty($this->dateend)) { + if (!$newcapital > 0 || empty($this->datestart) || empty($this->dateend)) + { @@ -234 +212,2 @@ - if (isModEnabled('accounting') && empty($this->account_capital)) { + if (($conf->accounting->enabled) && empty($this->account_capital)) + { @@ -238 +217,2 @@ - if (isModEnabled('accounting') && empty($this->account_insurance)) { + if (($conf->accounting->enabled) && empty($this->account_insurance)) + { @@ -242 +222,2 @@ - if (isModEnabled('accounting') && empty($this->account_interest)) { + if (($conf->accounting->enabled) && empty($this->account_interest)) + { @@ -273 +254,2 @@ - if ($resql) { + if ($resql) + { @@ -279 +261,3 @@ - } else { + } + else + { @@ -291 +275 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -305,2 +289,4 @@ - foreach ($lines_url as $line_url) { - if (!$error) { + foreach ($lines_url as $line_url) + { + if (!$error) + { @@ -310 +296,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -317,2 +304,3 @@ - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan where fk_loan=".((int) $this->id); + if (!$error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_loan where fk_loan=".$this->id; @@ -321 +309,2 @@ - if (!$resql) { + if (!$resql) + { @@ -327,2 +316,3 @@ - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."loan where rowid=".((int) $this->id); + if (!$error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."loan where rowid=".$this->id; @@ -331 +321,2 @@ - if (!$resql) { + if (!$resql) + { @@ -337 +328,2 @@ - if (!$error) { + if (!$error) + { @@ -340 +332,3 @@ - } else { + } + else + { @@ -351 +345 @@ - * @return int Return integer <0 if error, >0 if ok + * @return int <0 if error, >0 if ok @@ -357 +351,2 @@ - if (!is_numeric($this->nbterm)) { + if (!is_numeric($this->nbterm)) + { @@ -367,2 +362,2 @@ - $sql .= " nbterm=".((float) $this->nbterm).","; - $sql .= " rate=".((float) $this->rate).","; + $sql .= " nbterm=".$this->nbterm.","; + $sql .= " rate=".$this->db->escape($this->rate).","; @@ -372 +367 @@ - $sql .= " fk_projet=".(empty($this->fk_project) ? 'NULL' : ((int) $this->fk_project)).","; + $sql .= " fk_projet=".(empty($this->fk_project) ? 'NULL' : $this->fk_project).","; @@ -375 +370 @@ - $sql .= " WHERE rowid=".((int) $this->id); + $sql .= " WHERE rowid=".$this->id; @@ -379 +374,2 @@ - if ($resql) { + if ($resql) + { @@ -382 +378,3 @@ - } else { + } + else + { @@ -389,2 +387,3 @@ - /** - * Tag loan as paid completely + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Tag loan as payed completely @@ -393,4 +392,5 @@ - * @return int Return integer <0 if KO, >0 if OK - */ - public function setPaid($user) - { + * @return int <0 if KO, >0 if OK + */ + public function set_paid($user) + { + // phpcs:enable @@ -398,3 +398,2 @@ - $sql .= " paid = ".$this::STATUS_PAID; - $sql .= " WHERE rowid = ".((int) $this->id); - + $sql .= " paid = 1"; + $sql .= " WHERE rowid = ".$this->id; @@ -402 +400,0 @@ - @@ -404 +401,0 @@ - $this->paid = $this::STATUS_PAID; @@ -412,62 +408,0 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Tag loan as payment started - * - * @deprecated - * @see setStarted() - * @param User $user Object user making change - * @return int Return integer <0 if KO, >0 if OK - */ - public function set_started($user) - { - // phpcs:enable - dol_syslog(get_class($this)."::set_started is deprecated, use setStarted instead", LOG_NOTICE); - return $this->setStarted($user); - } - - /** - * Tag loan as payment started - * - * @param User $user Object user making change - * @return int Return integer <0 if KO, >0 if OK - */ - public function setStarted($user) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."loan SET"; - $sql .= " paid = ".$this::STATUS_STARTED; - $sql .= " WHERE rowid = ".((int) $this->id); - - $return = $this->db->query($sql); - - if ($return) { - $this->paid = $this::STATUS_STARTED; - return 1; - } else { - $this->error = $this->db->lasterror(); - return -1; - } - } - - /** - * Tag loan as payment as unpaid - * - * @param User $user Object user making change - * @return int Return integer <0 if KO, >0 if OK - */ - public function setUnpaid($user) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."loan SET"; - $sql .= " paid = ".$this::STATUS_UNPAID; - $sql .= " WHERE rowid = ".((int) $this->id); - - $return = $this->db->query($sql); - - if ($return) { - $this->paid = $this::STATUS_UNPAID; - return 1; - } else { - $this->error = $this->db->lasterror(); - return -1; - } - } - @@ -478 +413 @@ - * @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount paid if you have it, 1 otherwise) + * @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise) @@ -486 +421 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -492 +427 @@ - * @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount paid if you have it, 1 otherwise) + * @param integer $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise) @@ -504 +439,2 @@ - if (empty($this->labelStatus) || empty($this->labelStatusShort)) { + if (empty($this->labelStatus) || empty($this->labelStatusShort)) + { @@ -506,12 +442,7 @@ - $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('Unpaid'); - $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv('Paid'); - $this->labelStatus[self::STATUS_STARTED] = $langs->transnoentitiesnoconv("BillStatusStarted"); - if ($status == 0 && $alreadypaid > 0) { - $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted"); - } - $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('Unpaid'); - $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv('Paid'); - $this->labelStatusShort[self::STATUS_STARTED] = $langs->transnoentitiesnoconv("BillStatusStarted"); - if ($status == 0 && $alreadypaid > 0) { - $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted"); - } + //$langs->load("mymodule"); + $this->labelStatus[self::STATUS_UNPAID] = $langs->trans('Unpaid'); + $this->labelStatus[self::STATUS_PAID] = $langs->trans('Paid'); + if ($status == 0 && $alreadypaid > 0) $this->labelStatus[self::STATUS_UNPAID] = $langs->trans("BillStatusStarted"); + $this->labelStatusShort[self::STATUS_UNPAID] = $langs->trans('Unpaid'); + $this->labelStatusShort[self::STATUS_PAID] = $langs->trans('Enabled'); + if ($status == 0 && $alreadypaid > 0) $this->labelStatusShort[self::STATUS_UNPAID] = $langs->trans("BillStatusStarted"); @@ -521,6 +452,2 @@ - if (($status == 0 && $alreadypaid > 0) || $status == self::STATUS_STARTED) { - $statusType = 'status3'; - } - if ($status == 1) { - $statusType = 'status6'; - } + if ($status == 0 && $alreadypaid > 0) $statusType = 'status3'; + if ($status == 1) $statusType = 'status6'; @@ -537,4 +464,4 @@ - * @param string $option On what the link point to ('nolink', ...) - * @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 string $option On what the link point to ('nolink', ...) + * @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 @@ -545 +472 @@ - global $conf, $langs, $hookmanager; + global $conf, $langs; @@ -559 +486,2 @@ - if ($option != 'nolink') { + if ($option != 'nolink') + { @@ -562,6 +490,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'; @@ -571,2 +495,4 @@ - if (empty($notooltip)) { - if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { + if (empty($notooltip)) + { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { @@ -578,3 +504,2 @@ - } else { - $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); - } + } + else $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); @@ -587,6 +512,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 .= ($maxlen ? dol_trunc($this->ref, $maxlen) : $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 .= ($maxlen ?dol_trunc($this->ref, $maxlen) : $this->ref); @@ -595,9 +515,0 @@ - global $action; - $hookmanager->initHooks(array($this->element . 'dao')); - $parameters = array('id'=>$this->id, 'getnomurl' => &$result); - $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook > 0) { - $result = $hookmanager->resPrint; - } else { - $result .= $hookmanager->resPrint; - } @@ -616,18 +528,19 @@ - global $user, $langs, $conf; - - $now = dol_now(); - - // Initialise parameters - $this->id = 0; - $this->fk_bank = 1; - $this->label = 'SPECIMEN'; - $this->specimen = 1; - $this->account_capital = 16; - $this->account_insurance = 616; - $this->account_interest = 518; - $this->datestart = $now; - $this->dateend = $now + (3600 * 24 * 365); - $this->note_public = 'SPECIMEN'; - $this->capital = 20000; - $this->nbterm = 48; - $this->rate = 4.3; + global $user, $langs, $conf; + + $now = dol_now(); + + // Initialise parameters + $this->id = 0; + $this->fk_bank = 1; + $this->label = 'SPECIMEN'; + $this->specimen = 1; + $this->socid = 1; + $this->account_capital = 16; + $this->account_insurance = 616; + $this->account_interest = 518; + $this->datestart = $now; + $this->dateend = $now + (3600 * 24 * 365); + $this->note_public = 'SPECIMEN'; + $this->capital = 20000; + $this->nbterm = 48; + $this->rate = 4.3; @@ -648 +561 @@ - $sql .= " WHERE ".$field." = ".((int) $this->id); + $sql .= ' WHERE '.$field.' = '.$this->id; @@ -652 +565,2 @@ - if ($resql) { + if ($resql) + { @@ -656,3 +570 @@ - if ($obj) { - $amount = $obj->amount ? $obj->amount : 0; - } + if ($obj) $amount = $obj->amount ? $obj->amount : 0; @@ -662 +574,3 @@ - } else { + } + else + { @@ -677,2 +591,2 @@ - $sql .= ' l.tms as datem'; - $sql .= ' WHERE l.rowid = '.((int) $id); + $sql .= ' l.tms'; + $sql .= ' WHERE l.rowid = '.$id; @@ -683,2 +597,4 @@ - if ($result) { - if ($this->db->num_rows($result)) { + if ($result) + { + if ($this->db->num_rows($result)) + { @@ -686 +601,0 @@ - @@ -688,5 +603,15 @@ - - $this->user_creation_id = $obj->fk_user_author; - $this->user_modification_id = $obj->fk_user_modif; - $this->date_creation = $this->db->jdate($obj->datec); - $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem); + if ($obj->fk_user_author) + { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_author); + $this->user_creation = $cuser; + } + if ($obj->fk_user_modif) + { + $muser = new User($this->db); + $muser->fetch($obj->fk_user_modif); + $this->user_modification = $muser; + } + $this->date_creation = $this->db->jdate($obj->datec); + if (empty($obj->fk_user_modif)) $obj->tms = ""; + $this->date_modification = $this->db->jdate($obj->tms); @@ -696 +621,3 @@ - } else { + } + else + { @@ -700 +627,3 @@ - } else { + } + else + { @@ -704,43 +633 @@ - } - - /** - * 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, 'capital')) { - $return .= ' | '.$langs->trans("Amount").' : '.price($this->capital).''; - } - if (property_exists($this, 'datestart')) { - $return .= '
'.$langs->trans("DateStart").' : '.dol_print_date($this->db->jdate($this->datestart), 'day').''; - } - if (property_exists($this, 'dateend')) { - $return .= '
'.$langs->trans("DateEnd").' : '.dol_print_date($this->db->jdate($this->dateend), 'day').''; - } - - if (method_exists($this, 'LibStatut')) { - $return .= '
'.$this->getLibStatut(3, $this->alreadypaid).'
'; - } - $return .= '
'; - $return .= '
'; - $return .= '
'; - return $return; - } + } --- /tmp/dsg/dolibarr/htdocs/loan/class/github_19.0.3_loanschedule.class.php +++ /tmp/dsg/dolibarr/htdocs/loan/class/client_loanschedule.class.php @@ -3 +3 @@ - * Copyright (C) 2018-2023 Frédéric France + * Copyright (C) 2018 Frédéric France @@ -43,11 +43,9 @@ - /** - * @var int Loan ID - */ - public $fk_loan; - - public $bank_account; - public $bank_line; - /** - * @var string Create date - */ - public $datec; + /** + * @var int Loan ID + */ + public $fk_loan; + + /** + * @var string Create date + */ + public $datec; @@ -56,7 +54,7 @@ - /** - * @var string Payment date - */ - public $datep; - - public $amounts = array(); // Array of amounts - public $amount_capital; // Total amount of payment + /** + * @var string Payment date + */ + public $datep; + + public $amounts = array(); // Array of amounts + public $amount_capital; // Total amount of payment @@ -66,34 +64,25 @@ - /** - * @var int Payment Type ID - */ - public $fk_typepayment; - - /** - * @var int Payment ID - */ - public $num_payment; - - /** - * @var int Bank ID - */ - public $fk_bank; - - /** - * @var int Loan Payment ID - */ - public $fk_payment_loan; - - /** - * @var int Bank ID - */ - public $fk_user_creat; - - /** - * @var int User ID - */ - public $fk_user_modif; - - /** - * @var LoanSchedule[] - * @see LoanSchedule::fetchAll() - */ + /** + * @var int Payment Type ID + */ + public $fk_typepayment; + + /** + * @var int Payment ID + */ + public $num_payment; + + /** + * @var int Bank ID + */ + public $fk_bank; + + /** + * @var int Bank ID + */ + public $fk_user_creat; + + /** + * @var int User ID + */ + public $fk_user_modif; + @@ -124,2 +113,2 @@ - * Use this->amounts to have list of lines for the payment - * + * Use this->amounts to have list of lines for the payment + * @@ -127 +116 @@ - * @return int Return integer <0 if KO, id of payment if OK + * @return int <0 if KO, id of payment if OK @@ -135,4 +124,5 @@ - $now = dol_now(); - - // Validate parameters - if (!$this->datep) { + $now = dol_now(); + + // Validate parameters + if (!$this->datep) + { @@ -144,33 +134,17 @@ - if (isset($this->fk_loan)) { - $this->fk_loan = (int) $this->fk_loan; - } - if (isset($this->amount_capital)) { - $this->amount_capital = trim($this->amount_capital ? $this->amount_capital : 0); - } - if (isset($this->amount_insurance)) { - $this->amount_insurance = trim($this->amount_insurance ? $this->amount_insurance : 0); - } - if (isset($this->amount_interest)) { - $this->amount_interest = trim($this->amount_interest ? $this->amount_interest : 0); - } - if (isset($this->fk_typepayment)) { - $this->fk_typepayment = (int) $this->fk_typepayment; - } - if (isset($this->fk_bank)) { - $this->fk_bank = (int) $this->fk_bank; - } - if (isset($this->fk_user_creat)) { - $this->fk_user_creat = (int) $this->fk_user_creat; - } - if (isset($this->fk_user_modif)) { - $this->fk_user_modif = (int) $this->fk_user_modif; - } - - $totalamount = $this->amount_capital + $this->amount_insurance + $this->amount_interest; - $totalamount = price2num($totalamount); - - // Check parameters - if ($totalamount == 0) { - $this->errors[] = 'step1'; - return -1; // Negative amounts are accepted for reject prelevement but not null - } + if (isset($this->fk_loan)) $this->fk_loan = (int) $this->fk_loan; + if (isset($this->amount_capital)) $this->amount_capital = trim($this->amount_capital ? $this->amount_capital : 0); + if (isset($this->amount_insurance)) $this->amount_insurance = trim($this->amount_insurance ? $this->amount_insurance : 0); + if (isset($this->amount_interest)) $this->amount_interest = trim($this->amount_interest ? $this->amount_interest : 0); + if (isset($this->fk_typepayment)) $this->fk_typepayment = (int) $this->fk_typepayment; + if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank; + if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat; + if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif; + + $totalamount = $this->amount_capital + $this->amount_insurance + $this->amount_interest; + $totalamount = price2num($totalamount); + + // Check parameters + if ($totalamount == 0) { + $this->errors[] = 'step1'; + return -1; // Negative amounts are accepted for reject prelevement but not null + } @@ -181 +155,2 @@ - if ($totalamount != 0) { + if ($totalamount != 0) + { @@ -186,6 +161,6 @@ - $sql .= " ".price2num($this->amount_capital).","; - $sql .= " ".price2num($this->amount_insurance).","; - $sql .= " ".price2num($this->amount_interest).","; - $sql .= " ".price2num($this->fk_typepayment).", "; - $sql .= " ".((int) $user->id).","; - $sql .= " ".((int) $this->fk_bank).")"; + $sql .= " ".$this->amount_capital.","; + $sql .= " ".$this->amount_insurance.","; + $sql .= " ".$this->amount_interest.","; + $sql .= " ".$this->fk_typepayment.", "; + $sql .= " ".$user->id.","; + $sql .= " ".$this->fk_bank.")"; @@ -195 +170,2 @@ - if ($resql) { + if ($resql) + { @@ -197,2 +173,4 @@ - } else { - $this->error = $this->db->lasterror(); + } + else + { + $this->error = $this->db->lasterror(); @@ -203,3 +181,4 @@ - if ($totalamount != 0 && !$error) { - $this->amount_capital = $totalamount; - $this->db->commit(); + if ($totalamount != 0 && !$error) + { + $this->amount_capital = $totalamount; + $this->db->commit(); @@ -207 +186,3 @@ - } else { + } + else + { @@ -218 +199 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -222,0 +204,200 @@ + $sql = "SELECT"; + $sql .= " t.rowid,"; + $sql .= " t.fk_loan,"; + $sql .= " t.datec,"; + $sql .= " t.tms,"; + $sql .= " t.datep,"; + $sql .= " t.amount_capital,"; + $sql .= " t.amount_insurance,"; + $sql .= " t.amount_interest,"; + $sql .= " t.fk_typepayment,"; + $sql .= " t.num_payment,"; + $sql .= " t.note_private,"; + $sql .= " t.note_public,"; + $sql .= " t.fk_bank,"; + $sql .= " t.fk_user_creat,"; + $sql .= " t.fk_user_modif,"; + $sql .= " pt.code as type_code, pt.libelle as type_label,"; + $sql .= ' b.fk_account'; + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pt ON t.fk_typepayment = pt.id"; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; + $sql .= " WHERE t.rowid = ".$id; + + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + if ($this->db->num_rows($resql)) { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + + $this->fk_loan = $obj->fk_loan; + $this->datec = $this->db->jdate($obj->datec); + $this->tms = $this->db->jdate($obj->tms); + $this->datep = $this->db->jdate($obj->datep); + $this->amount_capital = $obj->amount_capital; + $this->amount_insurance = $obj->amount_insurance; + $this->amount_interest = $obj->amount_interest; + $this->fk_typepayment = $obj->fk_typepayment; + $this->num_payment = $obj->num_payment; + $this->note_private = $obj->note_private; + $this->note_public = $obj->note_public; + $this->fk_bank = $obj->fk_bank; + $this->fk_user_creat = $obj->fk_user_creat; + $this->fk_user_modif = $obj->fk_user_modif; + + $this->type_code = $obj->type_code; + $this->type_label = $obj->type_label; + + $this->bank_account = $obj->fk_account; + $this->bank_line = $obj->fk_bank; + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error = "Error ".$this->db->lasterror(); + return -1; + } + } + + + /** + * Update database + * + * @param User $user User that modify + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + public function update($user = 0, $notrigger = 0) + { + global $conf, $langs; + $error = 0; + + // Clean parameters + if (isset($this->amount_capital)) $this->amount_capital = trim($this->amount_capital); + if (isset($this->amount_insurance)) $this->amount_insurance = trim($this->amount_insurance); + if (isset($this->amount_interest)) $this->amount_interest = trim($this->amount_interest); + if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment); + if (isset($this->note_private)) $this->note_private = trim($this->note_private); + if (isset($this->note_public)) $this->note_public = trim($this->note_public); + if (isset($this->fk_bank)) $this->fk_bank = trim($this->fk_bank); + + // Check parameters + // Put here code to add control on parameters values + + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + + $sql .= " fk_loan=".(isset($this->fk_loan) ? $this->fk_loan : "null").","; + $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; + $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; + $sql .= " datep=".(dol_strlen($this->datep) != 0 ? "'".$this->db->idate($this->datep)."'" : 'null').","; + $sql .= " amount_capital=".(isset($this->amount_capital) ? $this->amount_capital : "null").","; + $sql .= " amount_insurance=".(isset($this->amount_insurance) ? $this->amount_insurance : "null").","; + $sql .= " amount_interest=".(isset($this->amount_interest) ? $this->amount_interest : "null").","; + $sql .= " fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment : "null").","; + $sql .= " num_payment=".(isset($this->num_payment) ? "'".$this->db->escape($this->num_payment)."'" : "null").","; + $sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").","; + $sql .= " note_public=".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").","; + $sql .= " fk_bank=".(isset($this->fk_bank) ? $this->fk_bank : "null").","; + $sql .= " fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat : "null").","; + $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif : "null").""; + + $sql .= " WHERE rowid=".$this->id; + + $this->db->begin(); + + dol_syslog(get_class($this)."::update", LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + + // Commit or rollback + if ($error) + { + $this->db->rollback(); + return -1 * $error; + } + else + { + $this->db->commit(); + return 1; + } + } + + + /** + * Delete object in database + * + * @param User $user User that delete + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + public function delete($user, $notrigger = 0) + { + global $conf, $langs; + $error = 0; + + $this->db->begin(); + + if (!$error) { + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " WHERE rowid=".$this->id; + + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql = $this->db->query($sql); + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + } + + // Commit or rollback + if ($error) + { + foreach ($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->error .= ($this->error ? ', '.$errmsg : $errmsg); + } + $this->db->rollback(); + return -1 * $error; + } + else + { + $this->db->commit(); + return 1; + } + } + + /** + * Calculate Monthly Payments + * + * @param double $capital Capital + * @param double $rate rate + * @param int $nbterm nb term + * @return double mensuality + */ + public function calcMonthlyPayments($capital, $rate, $nbterm) + { + $result = ''; + + if (!empty($capital) && !empty($rate) && !empty($nbterm)) { + $result = ($capital * ($rate / 12)) / (1 - pow((1 + ($rate / 12)), ($nbterm * -1))); + } + + return $result; + } + + + /** + * Load all object in memory from database + * + * @param int $loanid Id object + * @return int <0 if KO, >0 if OK + */ + public function fetchAll($loanid) + { + global $langs; + @@ -237,218 +417,0 @@ - $sql .= " t.fk_payment_loan,"; - $sql .= " t.fk_user_creat,"; - $sql .= " t.fk_user_modif,"; - $sql .= " pt.code as type_code, pt.libelle as type_label,"; - $sql .= ' b.fk_account'; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pt ON t.fk_typepayment = pt.id"; - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid'; - $sql .= " WHERE t.rowid = ".((int) $id); - - dol_syslog(get_class($this)."::fetch", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - if ($this->db->num_rows($resql)) { - $obj = $this->db->fetch_object($resql); - - $this->id = $obj->rowid; - $this->ref = $obj->rowid; - - $this->fk_loan = $obj->fk_loan; - $this->datec = $this->db->jdate($obj->datec); - $this->tms = $this->db->jdate($obj->tms); - $this->datep = $this->db->jdate($obj->datep); - $this->amount_capital = $obj->amount_capital; - $this->amount_insurance = $obj->amount_insurance; - $this->amount_interest = $obj->amount_interest; - $this->fk_typepayment = $obj->fk_typepayment; - $this->num_payment = $obj->num_payment; - $this->note_private = $obj->note_private; - $this->note_public = $obj->note_public; - $this->fk_bank = $obj->fk_bank; - $this->fk_payment_loan = $obj->fk_payment_loan; - $this->fk_user_creat = $obj->fk_user_creat; - $this->fk_user_modif = $obj->fk_user_modif; - - $this->type_code = $obj->type_code; - $this->type_label = $obj->type_label; - - $this->bank_account = $obj->fk_account; - $this->bank_line = $obj->fk_bank; - } - $this->db->free($resql); - - return 1; - } else { - $this->error = "Error ".$this->db->lasterror(); - return -1; - } - } - - - /** - * Update database - * - * @param User $user User that modify - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @return int Return integer <0 if KO, >0 if OK - */ - public function update($user = 0, $notrigger = 0) - { - global $conf, $langs; - $error = 0; - - // Clean parameters - if (isset($this->amount_capital)) { - $this->amount_capital = trim($this->amount_capital); - } - if (isset($this->amount_insurance)) { - $this->amount_insurance = trim($this->amount_insurance); - } - if (isset($this->amount_interest)) { - $this->amount_interest = trim($this->amount_interest); - } - if (isset($this->num_payment)) { - $this->num_payment = trim($this->num_payment); - } - if (isset($this->note_private)) { - $this->note_private = trim($this->note_private); - } - if (isset($this->note_public)) { - $this->note_public = trim($this->note_public); - } - if (isset($this->fk_bank)) { - $this->fk_bank = trim($this->fk_bank); - } - if (isset($this->fk_payment_loan)) { - $this->fk_payment_loan = (int) $this->fk_payment_loan; - } - - // Check parameters - // Put here code to add control on parameters values - - // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; - - $sql .= " fk_loan=".(isset($this->fk_loan) ? $this->fk_loan : "null").","; - $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; - $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; - $sql .= " datep=".(dol_strlen($this->datep) != 0 ? "'".$this->db->idate($this->datep)."'" : 'null').","; - $sql .= " amount_capital=".(isset($this->amount_capital) ? $this->amount_capital : "null").","; - $sql .= " amount_insurance=".(isset($this->amount_insurance) ? $this->amount_insurance : "null").","; - $sql .= " amount_interest=".(isset($this->amount_interest) ? $this->amount_interest : "null").","; - $sql .= " fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment : "null").","; - $sql .= " num_payment=".(isset($this->num_payment) ? "'".$this->db->escape($this->num_payment)."'" : "null").","; - $sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").","; - $sql .= " note_public=".(isset($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null").","; - $sql .= " fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) : "null").","; - $sql .= " fk_payment_loan=".(isset($this->fk_payment_loan) ? ((int) $this->fk_payment_loan) : "null").","; - $sql .= " fk_user_creat=".(isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) : "null").","; - $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) : "null"); - - $sql .= " WHERE rowid=".((int) $this->id); - - $this->db->begin(); - - dol_syslog(get_class($this)."::update", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - - // Commit or rollback - if ($error) { - $this->db->rollback(); - return -1 * $error; - } else { - $this->db->commit(); - return 1; - } - } - - - /** - * Delete object in database - * - * @param User $user User that delete - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @return int Return integer <0 if KO, >0 if OK - */ - public function delete($user, $notrigger = 0) - { - global $conf, $langs; - $error = 0; - - $this->db->begin(); - - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; - $sql .= " WHERE rowid=".((int) $this->id); - - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - } - - // Commit or rollback - if ($error) { - foreach ($this->errors as $errmsg) { - dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); - $this->error .= ($this->error ? ', '.$errmsg : $errmsg); - } - $this->db->rollback(); - return -1 * $error; - } else { - $this->db->commit(); - return 1; - } - } - - /** - * Calculate Monthly Payments - * - * @param double $capital Capital - * @param double $rate rate - * @param int $nbterm nb term - * @return double mensuality - */ - public function calcMonthlyPayments($capital, $rate, $nbterm) - { - $result = ''; - - if (!empty($capital) && !empty($rate) && !empty($nbterm)) { - $result = ($capital * ($rate / 12)) / (1 - pow((1 + ($rate / 12)), ($nbterm * -1))); - } - - return $result; - } - - - /** - * Load all object in memory from database - * - * @param int $loanid Id object - * @return int Return integer <0 if KO, >0 if OK - */ - public function fetchAll($loanid) - { - global $langs; - - $sql = "SELECT"; - $sql .= " t.rowid,"; - $sql .= " t.fk_loan,"; - $sql .= " t.datec,"; - $sql .= " t.tms,"; - $sql .= " t.datep,"; - $sql .= " t.amount_capital,"; - $sql .= " t.amount_insurance,"; - $sql .= " t.amount_interest,"; - $sql .= " t.fk_typepayment,"; - $sql .= " t.num_payment,"; - $sql .= " t.note_private,"; - $sql .= " t.note_public,"; - $sql .= " t.fk_bank,"; - $sql .= " t.fk_payment_loan,"; @@ -458 +421 @@ - $sql .= " WHERE t.fk_loan = ".((int) $loanid); + $sql .= " WHERE t.fk_loan = ".$loanid; @@ -463,2 +426,4 @@ - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { + if ($resql) + { + while ($obj = $this->db->fetch_object($resql)) + { @@ -481 +445,0 @@ - $line->fk_payment_loan = $obj->fk_payment_loan; @@ -489 +453,3 @@ - } else { + } + else + { @@ -509 +475 @@ - $sql .= " FROM ".MAIN_DB_PREFIX."loan as l"; + $sql .= " FROM ".MAIN_DB_PREFIX."loan as l "; @@ -522,2 +488 @@ - $sql .= "SELECT fk_loan,datec,tms,datep,amount_capital,amount_insurance,amount_interest,fk_typepayment,num_payment,note_private,note_public,fk_bank,fk_user_creat,fk_user_modif"; - $sql .= " FROM ".MAIN_DB_PREFIX."loan_schedule WHERE rowid =".((int) $echid); + $sql .= "SELECT fk_loan,datec,tms,datep,amount_capital,amount_insurance,amount_interest,fk_typepayment,num_payment,note_private,note_public,fk_bank,fk_user_creat,fk_user_modif FROM ".MAIN_DB_PREFIX."loan_schedule WHERE rowid =".$echid; @@ -541 +506 @@ - * @return int Return integer < 0 if KO, Date > 0 if OK + * @return int < 0 if KO, Date > 0 if OK @@ -547 +512 @@ - $sql .= " WHERE p.fk_loan = ".((int) $loanid); + $sql .= " WHERE p.fk_loan = ".$loanid; @@ -569,0 +535 @@ + @@ -574,4 +540,2 @@ - $sql .= " WHERE p.fk_loan = ".((int) $loanid); - if (!empty($datemax)) { - $sql .= " AND p.datep > '".$this->db->idate($datemax)."'"; - } + $sql .= " WHERE p.fk_loan = ".$loanid; + if (!empty($datemax)) { $sql .= " AND p.datep > '".$this->db->idate($datemax)."'"; } @@ -583 +547,2 @@ - while ($obj = $this->db->fetch_object($resql)) { + while ($obj = $this->db->fetch_object($resql)) + { --- /tmp/dsg/dolibarr/htdocs/loan/class/github_19.0.3_paymentloan.class.php +++ /tmp/dsg/dolibarr/htdocs/loan/class/client_paymentloan.class.php @@ -3,2 +3 @@ - * Copyright (C) 2015-2023 Frederic France - * Copyright (C) 2020 Maxime DEMAREST + * Copyright (C) 2015-2020 Frederic France @@ -44,62 +43,57 @@ - /** - * @var string String with name of icon for PaymentLoan - */ - public $picto = 'money-bill-alt'; - - /** - * @var int Loan ID - */ - public $fk_loan; - - /** - * @var string Create date - */ - public $datec = ''; - - public $tms = ''; - - /** - * @var string Payment date - */ - public $datep = ''; - - public $amounts = array(); // Array of amounts - - public $amount_capital; // Total amount of payment - - public $amount_insurance; - - public $amount_interest; - - /** - * @var int Payment mode ID - */ - public $fk_typepayment; - - /** - * @var int Payment ID - */ - public $num_payment; - - /** - * @var int Bank ID - */ - public $fk_bank; - - /** - * @var int User ID - */ - public $fk_user_creat; - - /** - * @var int user ID - */ - public $fk_user_modif; - - public $type_code; - public $type_label; - public $chid; - public $label; - public $paymenttype; - public $bank_account; - public $bank_line; + /** + * @var string String with name of icon for PaymentLoan + */ + public $picto = 'money-bill-alt'; + + /** + * @var int Loan ID + */ + public $fk_loan; + + /** + * @var string Create date + */ + public $datec = ''; + + public $tms = ''; + + /** + * @var string Payment date + */ + public $datep = ''; + + public $amounts = array(); // Array of amounts + + public $amount_capital; // Total amount of payment + + public $amount_insurance; + + public $amount_interest; + + /** + * @var int Payment type ID + */ + public $fk_typepayment; + + /** + * @var int Payment ID + */ + public $num_payment; + + /** + * @var int Bank ID + */ + public $fk_bank; + + /** + * @var int User ID + */ + public $fk_user_creat; + + /** + * @var int user ID + */ + public $fk_user_modif; + + public $type_code; + public $type_label; @@ -123 +117 @@ - * @return int Return integer <0 if KO, id of payment if OK + * @return int <0 if KO, id of payment if OK @@ -134 +128,2 @@ - if (!$this->datep) { + if (!$this->datep) + { @@ -140,33 +135,11 @@ - if (isset($this->fk_loan)) { - $this->fk_loan = (int) $this->fk_loan; - } - if (isset($this->amount_capital)) { - $this->amount_capital = price2num($this->amount_capital ? $this->amount_capital : 0); - } - if (isset($this->amount_insurance)) { - $this->amount_insurance = price2num($this->amount_insurance ? $this->amount_insurance : 0); - } - if (isset($this->amount_interest)) { - $this->amount_interest = price2num($this->amount_interest ? $this->amount_interest : 0); - } - if (isset($this->fk_typepayment)) { - $this->fk_typepayment = (int) $this->fk_typepayment; - } - if (isset($this->num_payment)) { - $this->num_payment = (int) $this->num_payment; - } - if (isset($this->note_private)) { - $this->note_private = trim($this->note_private); - } - if (isset($this->note_public)) { - $this->note_public = trim($this->note_public); - } - if (isset($this->fk_bank)) { - $this->fk_bank = (int) $this->fk_bank; - } - if (isset($this->fk_user_creat)) { - $this->fk_user_creat = (int) $this->fk_user_creat; - } - if (isset($this->fk_user_modif)) { - $this->fk_user_modif = (int) $this->fk_user_modif; - } + if (isset($this->fk_loan)) $this->fk_loan = (int) $this->fk_loan; + if (isset($this->amount_capital)) $this->amount_capital = price2num($this->amount_capital ? $this->amount_capital : 0); + if (isset($this->amount_insurance)) $this->amount_insurance = price2num($this->amount_insurance ? $this->amount_insurance : 0); + if (isset($this->amount_interest)) $this->amount_interest = price2num($this->amount_interest ? $this->amount_interest : 0); + if (isset($this->fk_typepayment)) $this->fk_typepayment = (int) $this->fk_typepayment; + if (isset($this->num_payment)) $this->num_payment = (int) $this->num_payment; + if (isset($this->note_private)) $this->note_private = trim($this->note_private); + if (isset($this->note_public)) $this->note_public = trim($this->note_public); + if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank; + if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat; + if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif; @@ -178,3 +151 @@ - if ($totalamount == 0) { - return -1; // Negative amounts are accepted for reject prelevement but not null - } + if ($totalamount == 0) return -1; // Negative amounts are accepted for reject prelevement but not null @@ -185 +156,2 @@ - if ($totalamount != 0) { + if ($totalamount != 0) + { @@ -190,4 +162,4 @@ - $sql .= " ".price2num($this->amount_capital).","; - $sql .= " ".price2num($this->amount_insurance).","; - $sql .= " ".price2num($this->amount_interest).","; - $sql .= " ".((int) $this->paymenttype).", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note_private)."', '".$this->db->escape($this->note_public)."', ".$user->id.","; + $sql .= " ".$this->amount_capital.","; + $sql .= " ".$this->amount_insurance.","; + $sql .= " ".$this->amount_interest.","; + $sql .= " ".$this->paymenttype.", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note_private)."', '".$this->db->escape($this->note_public)."', ".$user->id.","; @@ -198 +170,2 @@ - if ($resql) { + if ($resql) + { @@ -200 +173,3 @@ - } else { + } + else + { @@ -206 +181,2 @@ - if ($totalamount != 0 && !$error) { + if ($totalamount != 0 && !$error) + { @@ -210 +186,3 @@ - } else { + } + else + { @@ -221 +199 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -247 +225 @@ - $sql .= " WHERE t.rowid = ".((int) $id); + $sql .= " WHERE t.rowid = ".$id; @@ -251,2 +229,4 @@ - if ($resql) { - if ($this->db->num_rows($resql)) { + if ($resql) + { + if ($this->db->num_rows($resql)) + { @@ -282 +262,3 @@ - } else { + } + else + { @@ -294,3 +276,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 = 0, $notrigger = 0) @@ -302,33 +284,11 @@ - if (isset($this->fk_loan)) { - $this->fk_loan = (int) $this->fk_loan; - } - if (isset($this->amount_capital)) { - $this->amount_capital = trim($this->amount_capital); - } - if (isset($this->amount_insurance)) { - $this->amount_insurance = trim($this->amount_insurance); - } - if (isset($this->amount_interest)) { - $this->amount_interest = trim($this->amount_interest); - } - if (isset($this->fk_typepayment)) { - $this->fk_typepayment = (int) $this->fk_typepayment; - } - if (isset($this->num_payment)) { - $this->num_payment = (int) $this->num_payment; - } - if (isset($this->note_private)) { - $this->note = trim($this->note_private); - } - if (isset($this->note_public)) { - $this->note = trim($this->note_public); - } - if (isset($this->fk_bank)) { - $this->fk_bank = (int) $this->fk_bank; - } - if (isset($this->fk_user_creat)) { - $this->fk_user_creat = (int) $this->fk_user_creat; - } - if (isset($this->fk_user_modif)) { - $this->fk_user_modif = (int) $this->fk_user_modif; - } + if (isset($this->fk_loan)) $this->fk_loan = (int) $this->fk_loan; + if (isset($this->amount_capital)) $this->amount_capital = trim($this->amount_capital); + if (isset($this->amount_insurance)) $this->amount_insurance = trim($this->amount_insurance); + if (isset($this->amount_interest)) $this->amount_interest = trim($this->amount_interest); + if (isset($this->fk_typepayment)) $this->fk_typepayment = (int) $this->fk_typepayment; + if (isset($this->num_payment)) $this->num_payment = (int) $this->num_payment; + if (isset($this->note_private)) $this->note = trim($this->note_private); + if (isset($this->note_public)) $this->note = trim($this->note_public); + if (isset($this->fk_bank)) $this->fk_bank = (int) $this->fk_bank; + if (isset($this->fk_user_creat)) $this->fk_user_creat = (int) $this->fk_user_creat; + if (isset($this->fk_user_modif)) $this->fk_user_modif = (int) $this->fk_user_modif; @@ -339,0 +300 @@ + @@ -351,4 +312,5 @@ - $sql .= " fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) : "null").","; - $sql .= " fk_user_creat=".(isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) : "null").","; - $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) : "null"); - $sql .= " WHERE rowid=".((int) $this->id); + $sql .= " fk_bank=".(isset($this->fk_bank) ? $this->fk_bank : "null").","; + $sql .= " fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat : "null").","; + $sql .= " fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif : "null").""; + + $sql .= " WHERE rowid=".$this->id; @@ -360,4 +322 @@ - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } @@ -366,2 +325,4 @@ - if ($error) { - foreach ($this->errors as $errmsg) { + if ($error) + { + foreach ($this->errors as $errmsg) + { @@ -373 +334,3 @@ - } else { + } + else + { @@ -385 +348 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -394 +357,2 @@ - if (!$error) { + if (!$error) + { @@ -396 +360 @@ - $sql .= " WHERE type='payment_loan' AND url_id=".((int) $this->id); + $sql .= " WHERE type='payment_loan' AND url_id=".$this->id; @@ -400,7 +364,5 @@ - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - } - - if (!$error) { + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + } + + if (!$error) + { @@ -408 +370 @@ - $sql .= " WHERE rowid=".((int) $this->id); + $sql .= " WHERE rowid=".$this->id; @@ -412,36 +374,2 @@ - if (!$resql) { - $error++; - $this->errors[] = "Error ".$this->db->lasterror(); - } - } - - // Set loan unpaid if loan has no other payment - if (!$error) { - require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; - $loan = new Loan($this->db); - $loan->fetch($this->fk_loan); - $sum_payment = $loan->getSumPayment(); - if ($sum_payment == 0) { - dol_syslog(get_class($this)."::delete : set loan to unpaid", LOG_DEBUG); - if ($loan->setUnpaid($user) < 1) { - $error++; - dol_print_error($this->db); - } - } - } - - //if (! $error) - //{ - // if (! $notrigger) - // { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action call a trigger. - - //// Call triggers - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - //$interface=new Interfaces($this->db); - //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); - //if ($result < 0) { $error++; $this->errors=$interface->errors; } - //// End call triggers - // } - //} + if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + } @@ -450,2 +378,4 @@ - if ($error) { - foreach ($this->errors as $errmsg) { + if ($error) + { + foreach ($this->errors as $errmsg) + { @@ -457 +387,3 @@ - } else { + } + else + { @@ -461,25 +392,0 @@ - } - - /** - * 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 $this->LibStatut($this->statut, $mode); - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Renvoi le libelle d'un statut donne - * - * @param int $status 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 - return ''; @@ -499 +406 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -506,3 +413,3 @@ - $this->db->begin(); - - if (isModEnabled("banque")) { + + if (!empty($conf->banque->enabled)) + { @@ -515,3 +422 @@ - if ($mode == 'payment_loan') { - $total = -$total; - } + if ($mode == 'payment_loan') $total = -$total; @@ -520 +425 @@ - $bank_line_id = $acc->addline( + $bank_line_id = $acc->addline( @@ -522 +427 @@ - $this->paymenttype, // Payment mode ID or code ("CHQ or VIR for example") + $this->paymenttype, // Payment mode id or code ("CHQ or VIR for example") @@ -534 +439,2 @@ - if ($bank_line_id > 0) { + if ($bank_line_id > 0) + { @@ -536 +442,2 @@ - if ($result <= 0) { + if ($result <= 0) + { @@ -543,4 +450,3 @@ - if ($mode == 'payment_loan') { - $url = DOL_URL_ROOT.'/loan/payment/card.php?id='; - } - if ($url) { + if ($mode == 'payment_loan') $url = DOL_URL_ROOT.'/loan/payment/card.php?id='; + if ($url) + { @@ -548 +454,2 @@ - if ($result <= 0) { + if ($result <= 0) + { @@ -554 +460,0 @@ - @@ -556 +462,2 @@ - if ($mode == 'payment_loan') { + if ($mode == 'payment_loan') + { @@ -558,3 +465 @@ - if ($result <= 0) { - dol_print_error($this->db); - } + if ($result <= 0) dol_print_error($this->db); @@ -562 +467,3 @@ - } else { + } + else + { @@ -568,17 +475,2 @@ - - // Set loan payment started if no set - if (!$error) { - require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php'; - $loan = new Loan($this->db); - $loan->fetch($fk_loan); - if ($loan->paid == $loan::STATUS_UNPAID) { - dol_syslog(get_class($this)."::addPaymentToBank : set loan payment to started", LOG_DEBUG); - if ($loan->setStarted($user) < 1) { - $error++; - dol_print_error($this->db); - } - } - } - - if (!$error) { - $this->db->commit(); + if (!$error) + { @@ -586,2 +478,3 @@ - } else { - $this->db->rollback(); + } + else + { @@ -593 +486 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -602,2 +495,2 @@ - // phpcs:enable - $sql = "UPDATE ".MAIN_DB_PREFIX."payment_loan SET fk_bank = ".((int) $id_bank)." WHERE rowid = ".((int) $this->id); + // phpcs:enable + $sql = "UPDATE ".MAIN_DB_PREFIX."payment_loan SET fk_bank = ".$id_bank." WHERE rowid = ".$this->id; @@ -607,2 +500,3 @@ - if ($result) { - $this->fk_bank = ((int) $id_bank); + if ($result) + { + $this->fk_bank = $id_bank; @@ -610 +504,3 @@ - } else { + } + else + { @@ -621,3 +517,3 @@ - * @param int $notooltip 1=Disable tooltip - * @param string $moretitle Add more text to title tooltip - * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @param int $notooltip 1=Disable tooltip + * @param string $moretitle Add more text to title tooltip + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking @@ -628,5 +524,3 @@ - global $langs, $conf, $hookmanager; - - if (!empty($conf->dol_no_mouse_hover)) { - $notooltip = 1; // Force disable tooltips - } + global $langs, $conf; + + if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips @@ -639,3 +533 @@ - if ($moretitle) { - $label .= ' - '.$moretitle; - } + if ($moretitle) $label .= ' - '.$moretitle; @@ -646,6 +538,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'; @@ -657,6 +545,2 @@ - 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; - } + 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; @@ -665,9 +548,0 @@ - global $action; - $hookmanager->initHooks(array($this->element . 'dao')); - $parameters = array('id'=>$this->id, 'getnomurl' => &$result); - $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook > 0) { - $result = $hookmanager->resPrint; - } else { - $result .= $hookmanager->resPrint; - }