|
@@ -1,5 +1,6 @@
|
|
|
<?php
|
|
|
-/* Copyright (C) 2017 Florian HENRY <florian.henry@atm-consulting.fr>
|
|
|
+/* Copyright (C) 2017 Florian HENRY <florian.henry@atm-consulting.fr>
|
|
|
+ * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
|
|
|
*
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
@@ -39,20 +40,53 @@ class LoanSchedule extends CommonObject
|
|
|
*/
|
|
|
public $table_element='loan_schedule';
|
|
|
|
|
|
- var $fk_loan;
|
|
|
- var $datec='';
|
|
|
- var $tms='';
|
|
|
- var $datep='';
|
|
|
- var $amounts=array(); // Array of amounts
|
|
|
- var $amount_capital; // Total amount of payment
|
|
|
- var $amount_insurance;
|
|
|
- var $amount_interest;
|
|
|
- var $fk_typepayment;
|
|
|
- var $num_payment;
|
|
|
- var $fk_bank;
|
|
|
- var $fk_user_creat;
|
|
|
- var $fk_user_modif;
|
|
|
- var $lines=array();
|
|
|
+ /**
|
|
|
+ * @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 Bank ID
|
|
|
+ */
|
|
|
+ public $fk_user_creat;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var int User ID
|
|
|
+ */
|
|
|
+ public $fk_user_modif;
|
|
|
+
|
|
|
+ public $lines=array();
|
|
|
|
|
|
/**
|
|
|
* @deprecated
|
|
@@ -65,7 +99,7 @@ class LoanSchedule extends CommonObject
|
|
|
*
|
|
|
* @param DoliDB $db Database handler
|
|
|
*/
|
|
|
- function __construct($db)
|
|
|
+ public function __construct($db)
|
|
|
{
|
|
|
$this->db = $db;
|
|
|
}
|
|
@@ -77,7 +111,7 @@ class LoanSchedule extends CommonObject
|
|
|
* @param User $user User making payment
|
|
|
* @return int <0 if KO, id of payment if OK
|
|
|
*/
|
|
|
- function create($user)
|
|
|
+ public function create($user)
|
|
|
{
|
|
|
global $conf, $langs;
|
|
|
|
|
@@ -86,21 +120,21 @@ class LoanSchedule extends CommonObject
|
|
|
$now=dol_now();
|
|
|
|
|
|
// Validate parameters
|
|
|
- if (! $this->datepaid)
|
|
|
+ if (! $this->datep)
|
|
|
{
|
|
|
$this->error='ErrorBadValueForParameter';
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
// Clean parameters
|
|
|
- if (isset($this->fk_loan)) $this->fk_loan = trim($this->fk_loan);
|
|
|
+ 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 = trim($this->fk_typepayment);
|
|
|
- if (isset($this->fk_bank)) $this->fk_bank = trim($this->fk_bank);
|
|
|
- if (isset($this->fk_user_creat)) $this->fk_user_creat = trim($this->fk_user_creat);
|
|
|
- if (isset($this->fk_user_modif)) $this->fk_user_modif = trim($this->fk_user_modif);
|
|
|
+ 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);
|
|
@@ -119,7 +153,7 @@ class LoanSchedule extends CommonObject
|
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." (fk_loan, datec, datep, amount_capital, amount_insurance, amount_interest,";
|
|
|
$sql.= " fk_typepayment, fk_user_creat, fk_bank)";
|
|
|
$sql.= " VALUES (".$this->fk_loan.", '".$this->db->idate($now)."',";
|
|
|
- $sql.= " '".$this->db->idate($this->datepaid)."',";
|
|
|
+ $sql.= " '".$this->db->idate($this->datep)."',";
|
|
|
$sql.= " ".$this->amount_capital.",";
|
|
|
$sql.= " ".$this->amount_insurance.",";
|
|
|
$sql.= " ".$this->amount_interest.",";
|
|
@@ -162,7 +196,7 @@ class LoanSchedule extends CommonObject
|
|
|
* @param int $id Id object
|
|
|
* @return int <0 if KO, >0 if OK
|
|
|
*/
|
|
|
- function fetch($id)
|
|
|
+ public function fetch($id)
|
|
|
{
|
|
|
global $langs;
|
|
|
$sql = "SELECT";
|
|
@@ -215,8 +249,8 @@ class LoanSchedule extends CommonObject
|
|
|
$this->type_code = $obj->type_code;
|
|
|
$this->type_libelle = $obj->type_libelle;
|
|
|
|
|
|
- $this->bank_account = $obj->fk_account;
|
|
|
- $this->bank_line = $obj->fk_bank;
|
|
|
+ $this->bank_account = $obj->fk_account;
|
|
|
+ $this->bank_line = $obj->fk_bank;
|
|
|
}
|
|
|
$this->db->free($resql);
|
|
|
|
|
@@ -237,7 +271,7 @@ class LoanSchedule extends CommonObject
|
|
|
* @param int $notrigger 0=launch triggers after, 1=disable triggers
|
|
|
* @return int <0 if KO, >0 if OK
|
|
|
*/
|
|
|
- function update($user=0, $notrigger=0)
|
|
|
+ public function update($user=0, $notrigger=0)
|
|
|
{
|
|
|
global $conf, $langs;
|
|
|
$error=0;
|
|
@@ -321,7 +355,7 @@ class LoanSchedule extends CommonObject
|
|
|
* @param int $notrigger 0=launch triggers after, 1=disable triggers
|
|
|
* @return int <0 if KO, >0 if OK
|
|
|
*/
|
|
|
- function delete($user, $notrigger=0)
|
|
|
+ public function delete($user, $notrigger=0)
|
|
|
{
|
|
|
global $conf, $langs;
|
|
|
$error=0;
|
|
@@ -372,18 +406,16 @@ class LoanSchedule extends CommonObject
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
|
|
|
/**
|
|
|
- * Calculate mensuality
|
|
|
+ * Calculate Monthly Payments
|
|
|
*
|
|
|
* @param double $capital Capital
|
|
|
* @param double $rate rate
|
|
|
* @param int $nbterm nb term
|
|
|
* @return double mensuality
|
|
|
*/
|
|
|
- function calc_mens($capital, $rate, $nbterm)
|
|
|
+ public function calcMonthlyPayments($capital, $rate, $nbterm)
|
|
|
{
|
|
|
- // phpcs:enable
|
|
|
$result='';
|
|
|
|
|
|
if (!empty($capital) && !empty($rate) && !empty($nbterm)) {
|
|
@@ -400,7 +432,7 @@ class LoanSchedule extends CommonObject
|
|
|
* @param int $loanid Id object
|
|
|
* @return int <0 if KO, >0 if OK
|
|
|
*/
|
|
|
- function fetchAll($loanid)
|
|
|
+ public function fetchAll($loanid)
|
|
|
{
|
|
|
global $langs;
|
|
|
|
|
@@ -461,15 +493,13 @@ class LoanSchedule extends CommonObject
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
|
|
|
/**
|
|
|
- * trans_paiment
|
|
|
+ * transPayment
|
|
|
*
|
|
|
* @return void
|
|
|
*/
|
|
|
- function trans_paiment()
|
|
|
+ private function transPayment()
|
|
|
{
|
|
|
- // phpcs:enable
|
|
|
require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php';
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
|
@@ -505,12 +535,12 @@ class LoanSchedule extends CommonObject
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * trans_paiment
|
|
|
+ * transPayment
|
|
|
*
|
|
|
* @param int $loanid Loan id
|
|
|
* @return int < 0 if KO, Date > 0 if OK
|
|
|
*/
|
|
|
- function lastpaiment($loanid)
|
|
|
+ public function lastpaiment($loanid)
|
|
|
{
|
|
|
$sql = "SELECT p.datep";
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as p ";
|
|
@@ -535,7 +565,7 @@ class LoanSchedule extends CommonObject
|
|
|
* @param int $datemax Date max
|
|
|
* @return array Array of id
|
|
|
*/
|
|
|
- function paimenttorecord($loanid, $datemax)
|
|
|
+ public function paimenttorecord($loanid, $datemax)
|
|
|
{
|
|
|
$sql = "SELECT p.rowid";
|
|
|
$sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as p ";
|