26 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 public $element =
'payment_loan';
42 public $table_element =
'payment_loan';
47 public $picto =
'money-bill-alt';
66 public $amounts = array();
68 public $amount_capital;
70 public $amount_insurance;
72 public $amount_interest;
77 public $fk_typepayment;
92 public $fk_user_creat;
97 public $fk_user_modif;
122 global $conf, $langs;
131 $this->error =
'ErrorBadValueForParameter';
136 if (isset($this->fk_loan)) $this->fk_loan = (int) $this->fk_loan;
137 if (isset($this->amount_capital)) $this->amount_capital =
price2num($this->amount_capital ? $this->amount_capital : 0);
138 if (isset($this->amount_insurance)) $this->amount_insurance =
price2num($this->amount_insurance ? $this->amount_insurance : 0);
139 if (isset($this->amount_interest)) $this->amount_interest =
price2num($this->amount_interest ? $this->amount_interest : 0);
140 if (isset($this->fk_typepayment)) $this->fk_typepayment = (
int) $this->fk_typepayment;
141 if (isset($this->num_payment)) $this->num_payment = (
int) $this->num_payment;
142 if (isset($this->note_private)) $this->note_private = trim($this->note_private);
143 if (isset($this->note_public)) $this->note_public = trim($this->note_public);
144 if (isset($this->fk_bank)) $this->fk_bank = (
int) $this->fk_bank;
145 if (isset($this->fk_user_creat)) $this->fk_user_creat = (
int) $this->fk_user_creat;
146 if (isset($this->fk_user_modif)) $this->fk_user_modif = (
int) $this->fk_user_modif;
148 $totalamount = $this->amount_capital + $this->amount_insurance + $this->amount_interest;
152 if ($totalamount == 0)
return -1;
157 if ($totalamount != 0)
159 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_loan (fk_loan, datec, datep, amount_capital, amount_insurance, amount_interest,";
160 $sql .=
" fk_typepayment, num_payment, note_private, note_public, fk_user_creat, fk_bank)";
161 $sql .=
" VALUES (".$this->chid.
", '".$this->
db->idate($now).
"',";
162 $sql .=
" '".$this->db->idate($this->datep).
"',";
163 $sql .=
" ".$this->amount_capital.
",";
164 $sql .=
" ".$this->amount_insurance.
",";
165 $sql .=
" ".$this->amount_interest.
",";
166 $sql .=
" ".$this->paymenttype.
", '".$this->
db->escape($this->num_payment).
"', '".$this->
db->escape($this->note_private).
"', '".$this->
db->escape($this->note_public).
"', ".$user->id.
",";
169 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
173 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"payment_loan");
175 $this->error = $this->
db->lasterror();
180 if ($totalamount != 0 && !$error)
182 $this->amount_capital = $totalamount;
186 $this->error = $this->
db->lasterror();
187 $this->
db->rollback();
203 $sql .=
" t.fk_loan,";
207 $sql .=
" t.amount_capital,";
208 $sql .=
" t.amount_insurance,";
209 $sql .=
" t.amount_interest,";
210 $sql .=
" t.fk_typepayment,";
211 $sql .=
" t.num_payment,";
212 $sql .=
" t.note_private,";
213 $sql .=
" t.note_public,";
214 $sql .=
" t.fk_bank,";
215 $sql .=
" t.fk_user_creat,";
216 $sql .=
" t.fk_user_modif,";
217 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
218 $sql .=
' b.fk_account';
219 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_loan as t";
220 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepayment = pt.id";
221 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
222 $sql .=
" WHERE t.rowid = ".$id;
224 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
230 $obj = $this->
db->fetch_object(
$resql);
232 $this->
id = $obj->rowid;
233 $this->ref = $obj->rowid;
235 $this->fk_loan = $obj->fk_loan;
236 $this->datec = $this->
db->jdate($obj->datec);
237 $this->tms = $this->
db->jdate($obj->tms);
238 $this->datep = $this->
db->jdate($obj->datep);
239 $this->amount_capital = $obj->amount_capital;
240 $this->amount_insurance = $obj->amount_insurance;
241 $this->amount_interest = $obj->amount_interest;
242 $this->fk_typepayment = $obj->fk_typepayment;
243 $this->num_payment = $obj->num_payment;
244 $this->note_private = $obj->note_private;
245 $this->note_public = $obj->note_public;
246 $this->fk_bank = $obj->fk_bank;
247 $this->fk_user_creat = $obj->fk_user_creat;
248 $this->fk_user_modif = $obj->fk_user_modif;
250 $this->type_code = $obj->type_code;
251 $this->type_label = $obj->type_label;
253 $this->bank_account = $obj->fk_account;
254 $this->bank_line = $obj->fk_bank;
260 $this->error =
"Error ".$this->db->lasterror();
273 public function update($user = 0, $notrigger = 0)
275 global $conf, $langs;
279 if (isset($this->fk_loan)) $this->fk_loan = (int) $this->fk_loan;
280 if (isset($this->amount_capital)) $this->amount_capital = trim($this->amount_capital);
281 if (isset($this->amount_insurance)) $this->amount_insurance = trim($this->amount_insurance);
282 if (isset($this->amount_interest)) $this->amount_interest = trim($this->amount_interest);
283 if (isset($this->fk_typepayment)) $this->fk_typepayment = (
int) $this->fk_typepayment;
284 if (isset($this->num_payment)) $this->num_payment = (
int) $this->num_payment;
285 if (isset($this->note_private)) $this->
note = trim($this->note_private);
286 if (isset($this->note_public)) $this->
note = trim($this->note_public);
287 if (isset($this->fk_bank)) $this->fk_bank = (
int) $this->fk_bank;
288 if (isset($this->fk_user_creat)) $this->fk_user_creat = (
int) $this->fk_user_creat;
289 if (isset($this->fk_user_modif)) $this->fk_user_modif = (
int) $this->fk_user_modif;
294 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_loan SET";
296 $sql .=
" fk_loan=".(isset($this->fk_loan) ? $this->fk_loan :
"null").
",";
297 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
298 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
299 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
300 $sql .=
" amount_capital=".(isset($this->amount_capital) ? $this->amount_capital :
"null").
",";
301 $sql .=
" amount_insurance=".(isset($this->amount_insurance) ? $this->amount_insurance :
"null").
",";
302 $sql .=
" amount_interest=".(isset($this->amount_interest) ? $this->amount_interest :
"null").
",";
303 $sql .=
" fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment :
"null").
",";
304 $sql .=
" num_payment=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
305 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
306 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
307 $sql .=
" fk_bank=".(isset($this->fk_bank) ? $this->fk_bank :
"null").
",";
308 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat :
"null").
",";
309 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif :
"null").
"";
311 $sql .=
" WHERE rowid=".$this->id;
315 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
317 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
322 foreach ($this->errors as $errmsg)
324 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
325 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
327 $this->
db->rollback();
343 public function delete($user, $notrigger = 0)
345 global $conf, $langs;
352 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url";
353 $sql .=
" WHERE type='payment_loan' AND url_id=".$this->id;
355 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
357 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
362 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_loan";
363 $sql .=
" WHERE rowid=".$this->id;
365 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
367 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
373 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
374 $loan =
new Loan($this->
db);
375 $loan->fetch($this->fk_loan);
376 $sum_payment = $loan->getSumPayment();
377 if ($sum_payment == 0)
379 dol_syslog(get_class($this).
"::delete : set loan to unpaid", LOG_DEBUG);
380 if ($loan->set_unpaid($user) < 1)
407 foreach ($this->errors as $errmsg)
409 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
410 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
412 $this->
db->rollback();
458 public function addPaymentToBank($user, $fk_loan, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
465 if (!empty($conf->banque->enabled))
467 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
470 $acc->fetch($accountid);
472 $total = $this->amount_capital;
473 if ($mode ==
'payment_loan') $total = -$total;
476 $bank_line_id = $acc->addline(
490 if ($bank_line_id > 0)
501 if ($mode ==
'payment_loan') $url = DOL_URL_ROOT.
'/loan/payment/card.php?id=';
504 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(payment)', $mode);
514 if ($mode ==
'payment_loan')
516 $result = $acc->add_url_line($bank_line_id, $fk_loan, DOL_URL_ROOT.
'/loan/card.php?id=', ($this->label ? $this->label :
''),
'loan');
520 $this->error = $acc->error;
529 require_once DOL_DOCUMENT_ROOT.
'/loan/class/loan.class.php';
530 $loan =
new Loan($this->
db);
531 $loan->fetch($fk_loan);
532 if ($loan->paid == $loan::STATUS_UNPAID)
534 dol_syslog(get_class($this).
"::addPaymentToBank : set loan payment to started", LOG_DEBUG);
535 if ($loan->set_started($user) < 1)
549 $this->
db->rollback();
565 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_loan SET fk_bank = ".$id_bank.
" WHERE rowid = ".$this->id;
567 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
568 $result = $this->
db->query($sql);
571 $this->fk_bank = $id_bank;
574 $this->error = $this->
db->error();
589 public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $moretitle =
'', $save_lastsearch_value = -1)
591 global $langs, $conf;
593 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
596 $label =
'<u>'.$langs->trans(
"Loan").
'</u>';
597 if (!empty($this->
id)) {
598 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->id;
600 if ($moretitle) $label .=
' - '.$moretitle;
602 $url = DOL_URL_ROOT.
'/loan/payment/card.php?id='.$this->id;
604 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
605 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
606 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
608 $linkstart =
'<a href="'.$url.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
611 $result .= $linkstart;
612 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
613 if ($withpicto != 2) $result .= $this->ref;
addPaymentToBank($user, $fk_loan, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
Add record into bank for payment with links between this bank record and invoices of payment...
__construct($db)
Constructor.
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
update_fk_bank($id_bank)
Update link between loan's payment and the line generate in llx_bank.
create($user)
Create payment of loan into database.
dol_now($mode= 'auto')
Return date for now.
getNomUrl($withpicto=0, $maxlen=0, $notooltip=0, $moretitle= '', $save_lastsearch_value=-1)
Return clicable name (with eventually a picto)
fetch($id)
Load object in memory from database.
$conf db
API class for accounts.
Class to manage bank accounts.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
Class to manage payments of loans.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
update($user=0, $notrigger=0)
Update database.
print $_SERVER["PHP_SELF"]
Edit parameters.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
getLibStatut($mode=0)
Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) ...
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
if(!empty($search_group)) natural_search(array("g.nom"g note
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...