2014-09-21 17:42:38 +02:00
< ? php
2019-01-28 21:39:22 +01:00
/* Copyright ( C ) 2014 - 2018 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2015-03-27 17:13:52 +01:00
* Copyright ( C ) 2015 Frederic France < frederic . france @ free . fr >
2017-07-01 14:18:09 +02:00
* Copyright ( C ) 2017 Laurent Destailleur < eldy @ users . sourceforge . net >
2020-06-02 14:42:57 +02:00
* Copyright ( C ) 2020 Maxime DEMAREST < maxime @ indelog . fr >
2014-09-21 17:42:38 +02:00
*
* 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
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2014-09-21 17:42:38 +02:00
*/
/**
2017-12-10 07:00:46 +01:00
* \file htdocs / loan / card . php
* \ingroup loan
* \brief Loan card
2014-09-21 17:42:38 +02:00
*/
2015-03-22 20:19:22 +01:00
require '../main.inc.php' ;
require_once DOL_DOCUMENT_ROOT . '/loan/class/loan.class.php' ;
2014-09-21 17:42:38 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/loan.lib.php' ;
2014-09-21 21:38:33 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2021-02-26 18:20:21 +01:00
if ( ! empty ( $conf -> accounting -> enabled )) {
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php' ;
}
if ( ! empty ( $conf -> accounting -> enabled )) {
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php' ;
}
2017-01-07 17:45:05 +01:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php' ;
2014-09-21 17:42:38 +02:00
2018-05-26 21:11:25 +02:00
// Load translation files required by the page
2020-04-10 10:59:32 +02:00
$langs -> loadLangs ( array ( " compta " , " bills " , " loan " ));
2014-09-21 17:42:38 +02:00
2020-04-10 10:59:32 +02:00
$id = GETPOST ( 'id' , 'int' );
$action = GETPOST ( 'action' , 'aZ09' );
$confirm = GETPOST ( 'confirm' );
$cancel = GETPOST ( 'cancel' , 'alpha' );
2014-09-21 17:42:38 +02:00
2019-01-27 11:55:16 +01:00
$projectid = GETPOST ( 'projectid' , 'int' );
2017-07-29 00:28:41 +02:00
2014-09-21 17:42:38 +02:00
// Security check
2019-01-27 11:55:16 +01:00
$socid = GETPOST ( 'socid' , 'int' );
2021-02-26 18:20:21 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2019-01-27 11:55:16 +01:00
$result = restrictedArea ( $user , 'loan' , $id , '' , '' );
2014-09-21 17:42:38 +02:00
2014-11-10 06:08:50 +01:00
$object = new Loan ( $db );
2020-04-10 10:59:32 +02:00
$hookmanager -> initHooks ( array ( 'loancard' , 'globalcard' ));
2016-11-14 19:25:50 +01:00
2020-10-15 10:15:37 +02:00
$error = 0 ;
2017-01-07 17:45:05 +01:00
2014-09-21 17:42:38 +02:00
/*
* Actions
*/
2015-07-12 12:50:24 +02:00
2016-11-14 19:25:50 +01:00
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 18:20:21 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
if ( empty ( $reshook )) {
2017-12-10 07:00:46 +01:00
// Classify paid
2021-02-26 18:20:21 +01:00
if ( $action == 'confirm_paid' && $confirm == 'yes' && $user -> rights -> loan -> write ) {
2017-12-10 07:00:46 +01:00
$object -> fetch ( $id );
2021-02-09 10:26:17 +01:00
$result = $object -> setPaid ( $user );
2021-02-26 18:20:21 +01:00
if ( $result > 0 ) {
2017-12-10 07:00:46 +01:00
setEventMessages ( $langs -> trans ( 'LoanPaid' ), null , 'mesgs' );
2020-05-21 15:05:19 +02:00
} else {
2017-12-10 07:00:46 +01:00
setEventMessages ( $loan -> error , null , 'errors' );
}
}
2017-06-02 17:48:29 +02:00
2017-12-10 07:00:46 +01:00
// Delete loan
2021-02-26 18:20:21 +01:00
if ( $action == 'confirm_delete' && $confirm == 'yes' && $user -> rights -> loan -> write ) {
2017-12-10 07:00:46 +01:00
$object -> fetch ( $id );
2019-11-13 19:35:39 +01:00
$result = $object -> delete ( $user );
2021-02-26 18:20:21 +01:00
if ( $result > 0 ) {
2017-12-10 07:00:46 +01:00
setEventMessages ( $langs -> trans ( 'LoanDeleted' ), null , 'mesgs' );
2020-06-02 14:42:57 +02:00
header ( " Location: list.php " );
2017-12-10 07:00:46 +01:00
exit ;
2020-05-21 15:05:19 +02:00
} else {
2017-12-10 07:00:46 +01:00
setEventMessages ( $loan -> error , null , 'errors' );
}
}
2017-06-02 17:48:29 +02:00
2017-12-10 07:00:46 +01:00
// Add loan
2021-02-26 18:20:21 +01:00
if ( $action == 'add' && $user -> rights -> loan -> write ) {
if ( ! $cancel ) {
2019-11-13 19:35:39 +01:00
$datestart = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'startmonth' , 'int' ), GETPOST ( 'startday' , 'int' ), GETPOST ( 'startyear' , 'int' ));
2019-01-27 11:55:16 +01:00
$dateend = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'endmonth' , 'int' ), GETPOST ( 'endday' , 'int' ), GETPOST ( 'endyear' , 'int' ));
2019-11-13 19:35:39 +01:00
$capital = price2num ( GETPOST ( 'capital' ));
2023-01-18 22:50:13 +01:00
$rate = price2num ( GETPOST ( 'rate' ));
2017-06-02 17:48:29 +02:00
2021-02-26 18:20:21 +01:00
if ( ! $capital ) {
2017-12-10 07:00:46 +01:00
$error ++ ; $action = 'create' ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " LoanCapital " )), null , 'errors' );
}
2021-02-26 18:20:21 +01:00
if ( ! $datestart ) {
2017-12-10 07:00:46 +01:00
$error ++ ; $action = 'create' ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " DateStart " )), null , 'errors' );
}
2021-02-26 18:20:21 +01:00
if ( ! $dateend ) {
2017-12-10 07:00:46 +01:00
$error ++ ; $action = 'create' ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " DateEnd " )), null , 'errors' );
}
2021-02-26 18:20:21 +01:00
if ( $rate == '' ) {
2017-12-10 07:00:46 +01:00
$error ++ ; $action = 'create' ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Rate " )), null , 'errors' );
}
2017-06-02 17:48:29 +02:00
2021-02-26 18:20:21 +01:00
if ( ! $error ) {
2019-11-13 19:35:39 +01:00
$object -> label = GETPOST ( 'label' );
2021-02-26 18:20:21 +01:00
$object -> fk_bank = GETPOST ( 'accountid' );
$object -> capital = $capital ;
2019-11-13 19:35:39 +01:00
$object -> datestart = $datestart ;
2021-02-26 18:20:21 +01:00
$object -> dateend = $dateend ;
$object -> nbterm = GETPOST ( 'nbterm' );
2019-11-13 19:35:39 +01:00
$object -> rate = $rate ;
2020-09-18 01:29:17 +02:00
$object -> note_private = GETPOST ( 'note_private' , 'restricthtml' );
$object -> note_public = GETPOST ( 'note_public' , 'restricthtml' );
2019-11-13 19:35:39 +01:00
$object -> fk_project = GETPOST ( 'projectid' , 'int' );
$object -> insurance_amount = GETPOST ( 'insurance_amount' , 'int' );
2017-12-14 06:57:17 +01:00
2019-11-13 19:35:39 +01:00
$accountancy_account_capital = GETPOST ( 'accountancy_account_capital' );
$accountancy_account_insurance = GETPOST ( 'accountancy_account_insurance' );
$accountancy_account_interest = GETPOST ( 'accountancy_account_interest' );
2017-12-14 06:57:17 +01:00
2021-02-26 18:20:21 +01:00
if ( $accountancy_account_capital <= 0 ) {
$object -> account_capital = '' ;
} else {
$object -> account_capital = $accountancy_account_capital ;
}
if ( $accountancy_account_insurance <= 0 ) {
$object -> account_insurance = '' ;
} else {
$object -> account_insurance = $accountancy_account_insurance ;
}
if ( $accountancy_account_interest <= 0 ) {
$object -> account_interest = '' ;
} else {
$object -> account_interest = $accountancy_account_interest ;
}
2017-12-14 06:57:17 +01:00
2019-11-13 19:35:39 +01:00
$id = $object -> create ( $user );
2021-02-26 18:20:21 +01:00
if ( $id <= 0 ) {
2017-12-14 06:57:17 +01:00
$error ++ ;
2020-10-15 10:15:37 +02:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2017-12-14 06:57:17 +01:00
$action = 'create' ;
}
}
2020-05-21 15:05:19 +02:00
} else {
2020-10-09 15:37:27 +02:00
header ( " Location: list.php " );
2017-12-14 06:57:17 +01:00
exit ();
}
2021-02-26 18:20:21 +01:00
} elseif ( $action == 'update' && $user -> rights -> loan -> write ) {
// Update record
if ( ! $cancel ) {
2017-12-10 07:00:46 +01:00
$result = $object -> fetch ( $id );
2017-01-11 05:25:57 +01:00
2019-11-13 19:35:39 +01:00
$datestart = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'startmonth' , 'int' ), GETPOST ( 'startday' , 'int' ), GETPOST ( 'startyear' , 'int' ));
2019-01-27 11:55:16 +01:00
$dateend = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'endmonth' , 'int' ), GETPOST ( 'endday' , 'int' ), GETPOST ( 'endyear' , 'int' ));
2017-12-10 07:00:46 +01:00
$capital = price2num ( GETPOST ( 'capital' ));
2017-06-02 17:48:29 +02:00
2021-02-26 18:20:21 +01:00
if ( ! $capital ) {
2017-12-10 07:00:46 +01:00
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " LoanCapital " )), null , 'errors' );
$action = 'edit' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$object -> datestart = $datestart ;
2019-08-26 12:10:19 +02:00
$object -> dateend = $dateend ;
$object -> capital = $capital ;
$object -> nbterm = GETPOST ( " nbterm " , 'int' );
2019-11-13 19:35:39 +01:00
$object -> rate = price2num ( GETPOST ( " rate " , 'alpha' ));
2020-10-31 14:32:18 +01:00
$object -> insurance_amount = price2num ( GETPOST ( 'insurance_amount' , 'int' ));
2017-01-11 05:25:57 +01:00
2019-11-13 19:35:39 +01:00
$accountancy_account_capital = GETPOST ( 'accountancy_account_capital' );
$accountancy_account_insurance = GETPOST ( 'accountancy_account_insurance' );
$accountancy_account_interest = GETPOST ( 'accountancy_account_interest' );
2017-06-02 17:48:29 +02:00
2021-02-26 18:20:21 +01:00
if ( $accountancy_account_capital <= 0 ) {
$object -> account_capital = '' ;
} else {
$object -> account_capital = $accountancy_account_capital ;
}
if ( $accountancy_account_insurance <= 0 ) {
$object -> account_insurance = '' ;
} else {
$object -> account_insurance = $accountancy_account_insurance ;
}
if ( $accountancy_account_interest <= 0 ) {
$object -> account_interest = '' ;
} else {
$object -> account_interest = $accountancy_account_interest ;
}
2017-12-10 07:00:46 +01:00
}
2017-06-02 17:48:29 +02:00
2017-12-10 07:00:46 +01:00
$result = $object -> update ( $user );
2021-02-26 18:20:21 +01:00
if ( $result > 0 ) {
2019-11-13 19:35:39 +01:00
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id );
2017-12-10 07:00:46 +01:00
exit ;
2020-05-21 15:05:19 +02:00
} else {
2017-12-10 21:46:23 +01:00
$error ++ ;
2017-12-10 07:00:46 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id );
2017-12-10 07:00:46 +01:00
exit ;
}
}
2017-06-02 17:48:29 +02:00
2017-01-07 17:45:05 +01:00
// Link to a project
2021-02-26 18:20:21 +01:00
if ( $action == 'classin' && $user -> rights -> loan -> write ) {
2017-12-10 07:00:46 +01:00
$object -> fetch ( $id );
$result = $object -> setProject ( $projectid );
2021-02-26 18:20:21 +01:00
if ( $result < 0 ) {
2017-12-10 07:00:46 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2021-02-26 18:20:21 +01:00
}
2014-09-21 17:42:38 +02:00
}
2021-02-26 18:20:21 +01:00
if ( $action == 'setlabel' && $user -> rights -> loan -> write ) {
2017-12-10 07:00:46 +01:00
$object -> fetch ( $id );
$result = $object -> setValueFrom ( 'label' , GETPOST ( 'label' ), '' , '' , 'text' , '' , $user , 'LOAN_MODIFY' );
2021-02-26 18:20:21 +01:00
if ( $result < 0 ) {
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
2017-12-10 07:00:46 +01:00
}
2014-11-10 06:08:50 +01:00
}
2014-09-21 17:42:38 +02:00
2016-12-20 07:29:49 +01:00
2014-09-21 17:42:38 +02:00
/*
* View
*/
$form = new Form ( $db );
2017-01-07 17:45:05 +01:00
$formproject = new FormProjets ( $db );
2021-02-26 18:20:21 +01:00
if ( ! empty ( $conf -> accounting -> enabled )) {
$formaccounting = new FormAccounting ( $db );
}
2014-09-21 17:42:38 +02:00
2019-11-13 19:35:39 +01:00
$title = $langs -> trans ( " Loan " ) . ' - ' . $langs -> trans ( " Card " );
2016-12-20 07:29:49 +01:00
$help_url = 'EN:Module_Loan|FR:Module_Emprunt' ;
2019-01-27 11:55:16 +01:00
llxHeader ( " " , $title , $help_url );
2014-09-21 17:42:38 +02:00
// Create mode
2022-07-11 00:05:50 +02:00
if ( $action == 'create' ) {
2014-09-21 17:42:38 +02:00
//WYSIWYG Editor
2017-12-10 07:00:46 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2014-09-21 17:42:38 +02:00
2020-04-20 18:38:25 +02:00
print load_fiche_titre ( $langs -> trans ( " NewLoan " ), '' , 'money-bill-alt' );
2014-09-21 17:42:38 +02:00
2019-01-27 11:55:16 +01:00
$datec = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'remonth' , 'int' ), GETPOST ( 'reday' , 'int' ), GETPOST ( 'reyear' , 'int' ));
2014-09-21 17:42:38 +02:00
2019-11-13 19:35:39 +01:00
print '<form name="loan" action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST">' . " \n " ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-12-10 07:00:46 +01:00
print '<input type="hidden" name="action" value="add">' ;
2014-09-21 17:42:38 +02:00
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ();
2015-05-20 07:03:17 +02:00
2019-11-05 21:24:41 +01:00
print '<table class="border centpercent">' ;
2015-03-27 17:13:52 +01:00
2014-09-21 17:42:38 +02:00
// Label
2018-11-07 13:04:43 +01:00
print '<tr><td class="fieldrequired titlefieldcreate">' . $langs -> trans ( " Label " ) . '</td><td><input name="label" class="minwidth300" maxlength="255" value="' . dol_escape_htmltag ( GETPOST ( 'label' )) . '" autofocus="autofocus"></td></tr>' ;
2014-09-21 17:42:38 +02:00
// Bank account
2021-02-26 18:20:21 +01:00
if ( ! empty ( $conf -> banque -> enabled )) {
2014-09-21 17:42:38 +02:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " Account " ) . '</td><td>' ;
2019-11-13 19:35:39 +01:00
$form -> select_comptes ( GETPOST ( " accountid " ), " accountid " , 0 , " courant=1 " , 1 ); // Show list of bank account with courant
2014-09-21 17:42:38 +02:00
print '</td></tr>' ;
2020-05-21 15:05:19 +02:00
} else {
2014-09-21 17:42:38 +02:00
print '<tr><td>' . $langs -> trans ( " Account " ) . '</td><td>' ;
print $langs -> trans ( " NoBankAccountDefined " );
print '</td></tr>' ;
}
2015-03-27 17:13:52 +01:00
2017-12-10 07:00:46 +01:00
// Capital
2019-11-13 19:35:39 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " LoanCapital " ) . '</td><td><input name="capital" size="10" value="' . dol_escape_htmltag ( GETPOST ( " capital " )) . '"></td></tr>' ;
2014-09-21 17:42:38 +02:00
// Date Start
print " <tr> " ;
2017-12-10 07:00:46 +01:00
print '<td class="fieldrequired">' . $langs -> trans ( " DateStart " ) . '</td><td>' ;
2019-11-13 19:35:39 +01:00
print $form -> selectDate ( $datestart ? $datestart : - 1 , 'start' , '' , '' , '' , 'add' , 1 , 1 );
2017-12-10 07:00:46 +01:00
print '</td></tr>' ;
2015-03-27 17:13:52 +01:00
2014-09-21 17:42:38 +02:00
// Date End
print " <tr> " ;
2017-12-10 07:00:46 +01:00
print '<td class="fieldrequired">' . $langs -> trans ( " DateEnd " ) . '</td><td>' ;
2019-11-13 19:35:39 +01:00
print $form -> selectDate ( $dateend ? $dateend : - 1 , 'end' , '' , '' , '' , 'add' , 1 , 1 );
2017-12-10 07:00:46 +01:00
print '</td></tr>' ;
2015-03-27 17:13:52 +01:00
2014-09-21 17:42:38 +02:00
// Number of terms
2019-11-13 19:35:39 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " Nbterms " ) . '</td><td><input name="nbterm" size="5" value="' . dol_escape_htmltag ( GETPOST ( 'nbterm' )) . '"></td></tr>' ;
2015-03-27 17:13:52 +01:00
2014-09-21 17:42:38 +02:00
// Rate
2019-11-13 19:35:39 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " Rate " ) . '</td><td><input name="rate" size="5" value="' . dol_escape_htmltag ( GETPOST ( " rate " )) . '"> %</td></tr>' ;
2014-09-21 17:42:38 +02:00
2019-05-29 12:56:11 +02:00
// Insurance amount
2019-11-13 19:35:39 +01:00
print '<tr><td>' . $langs -> trans ( " Insurance " ) . '</td><td><input name="insurance_amount" size="10" value="' . dol_escape_htmltag ( GETPOST ( " insurance_amount " )) . '" placeholder="' . $langs -> trans ( 'Amount' ) . '"></td></tr>' ;
2019-03-03 08:55:27 +01:00
2017-12-10 07:00:46 +01:00
// Project
2022-06-14 17:53:17 +02:00
if ( ! empty ( $conf -> project -> enabled )) {
2019-11-13 19:35:39 +01:00
$formproject = new FormProjets ( $db );
2016-11-14 19:25:50 +01:00
// Projet associe
2018-05-19 08:06:52 +02:00
$langs -> loadLangs ( array ( " projects " ));
2016-11-14 19:25:50 +01:00
2017-12-10 07:00:46 +01:00
print '<tr><td>' . $langs -> trans ( " Project " ) . '</td><td>' ;
2017-06-02 17:48:29 +02:00
2019-11-13 19:35:39 +01:00
$numproject = $formproject -> select_projects ( - 1 , $projectid , 'projectid' , 16 , 0 , 1 , 1 );
2017-06-02 17:48:29 +02:00
2017-12-10 07:00:46 +01:00
print '</td></tr>' ;
}
2017-06-02 17:48:29 +02:00
2017-12-10 07:00:46 +01:00
// Note Private
print '<tr>' ;
print '<td class="tdtop">' . $langs -> trans ( 'NotePrivate' ) . '</td>' ;
print '<td>' ;
2014-09-21 17:42:38 +02:00
2020-11-30 14:54:44 +01:00
$doleditor = new DolEditor ( 'note_private' , GETPOST ( 'note_private' , 'alpha' ), '' , 160 , 'dolibarr_notes' , 'In' , false , true , empty ( $conf -> global -> FCKEDITOR_ENABLE_NOTE_PUBLIC ) ? 0 : 1 , ROWS_6 , '90%' );
2017-12-10 07:00:46 +01:00
print $doleditor -> Create ( 1 );
2014-09-21 17:42:38 +02:00
2017-12-10 07:00:46 +01:00
print '</td></tr>' ;
2015-03-27 17:13:52 +01:00
2017-12-10 07:00:46 +01:00
// Note Public
print '<tr>' ;
print '<td class="tdtop">' . $langs -> trans ( 'NotePublic' ) . '</td>' ;
print '<td>' ;
2020-11-30 14:54:44 +01:00
$doleditor = new DolEditor ( 'note_public' , GETPOST ( 'note_public' , 'alpha' ), '' , 160 , 'dolibarr_notes' , 'In' , false , true , empty ( $conf -> global -> FCKEDITOR_ENABLE_NOTE_PRIVATE ) ? 0 : 1 , ROWS_6 , '90%' );
2017-12-10 07:00:46 +01:00
print $doleditor -> Create ( 1 );
print '</td></tr>' ;
2015-03-27 17:13:52 +01:00
2017-12-10 07:00:46 +01:00
// Accountancy
2021-02-26 18:20:21 +01:00
if ( ! empty ( $conf -> accounting -> enabled )) {
2016-06-05 15:21:11 +02:00
// Accountancy_account_capital
2017-12-10 07:00:46 +01:00
print '<tr><td class="titlefieldcreate fieldrequired">' . $langs -> trans ( " LoanAccountancyCapitalCode " ) . '</td>' ;
print '<td>' ;
2019-11-13 19:35:39 +01:00
print $formaccounting -> select_account ( GETPOST ( 'accountancy_account_capital' ) ? GETPOST ( 'accountancy_account_capital' ) : $conf -> global -> LOAN_ACCOUNTING_ACCOUNT_CAPITAL , 'accountancy_account_capital' , 1 , '' , 1 , 1 );
2017-12-10 07:00:46 +01:00
print '</td></tr>' ;
2016-06-05 15:21:11 +02:00
// Accountancy_account_insurance
2017-12-10 07:00:46 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " LoanAccountancyInsuranceCode " ) . '</td>' ;
print '<td>' ;
2019-11-13 19:35:39 +01:00
print $formaccounting -> select_account ( GETPOST ( 'accountancy_account_insurance' ) ? GETPOST ( 'accountancy_account_insurance' ) : $conf -> global -> LOAN_ACCOUNTING_ACCOUNT_INSURANCE , 'accountancy_account_insurance' , 1 , '' , 1 , 1 );
2017-12-10 07:00:46 +01:00
print '</td></tr>' ;
2016-06-05 15:21:11 +02:00
// Accountancy_account_interest
2017-12-10 07:00:46 +01:00
print '<tr><td class="fieldrequired">' . $langs -> trans ( " LoanAccountancyInterestCode " ) . '</td>' ;
print '<td>' ;
2019-11-13 19:35:39 +01:00
print $formaccounting -> select_account ( GETPOST ( 'accountancy_account_interest' ) ? GETPOST ( 'accountancy_account_interest' ) : $conf -> global -> LOAN_ACCOUNTING_ACCOUNT_INTEREST , 'accountancy_account_interest' , 1 , '' , 1 , 1 );
2017-12-10 07:00:46 +01:00
print '</td></tr>' ;
2020-05-21 15:05:19 +02:00
} else // For external software
2016-06-05 15:21:11 +02:00
{
2017-12-10 07:00:46 +01:00
// Accountancy_account_capital
print '<tr><td class="titlefieldcreate">' . $langs -> trans ( " LoanAccountancyCapitalCode " ) . '</td>' ;
print '<td><input name="accountancy_account_capital" size="16" value="' . $object -> accountancy_account_capital . '">' ;
print '</td></tr>' ;
2016-06-05 15:21:11 +02:00
// Accountancy_account_insurance
2017-12-10 07:00:46 +01:00
print '<tr><td>' . $langs -> trans ( " LoanAccountancyInsuranceCode " ) . '</td>' ;
print '<td><input name="accountancy_account_insurance" size="16" value="' . $object -> accountancy_account_insurance . '">' ;
print '</td></tr>' ;
2016-06-05 15:21:11 +02:00
// Accountancy_account_interest
2017-12-10 07:00:46 +01:00
print '<tr><td>' . $langs -> trans ( " LoanAccountancyInterestCode " ) . '</td>' ;
print '<td><input name="accountancy_account_interest" size="16" value="' . $object -> accountancy_account_interest . '">' ;
print '</td></tr>' ;
2014-09-21 17:42:38 +02:00
}
2016-06-05 15:21:11 +02:00
print '</table>' ;
2016-12-20 07:29:49 +01:00
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2015-05-20 07:03:17 +02:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ( " Add " );
2014-09-21 17:42:38 +02:00
2017-12-10 07:00:46 +01:00
print '</form>' ;
2014-09-21 17:42:38 +02:00
}
// View
2021-02-26 18:20:21 +01:00
if ( $id > 0 ) {
2016-12-20 07:29:49 +01:00
$object = new Loan ( $db );
2017-12-10 07:00:46 +01:00
$result = $object -> fetch ( $id );
2014-09-21 17:42:38 +02:00
2021-02-26 18:20:21 +01:00
if ( $result > 0 ) {
2019-11-13 19:35:39 +01:00
$head = loan_prepare_head ( $object );
2014-09-21 17:42:38 +02:00
2016-12-20 07:29:49 +01:00
$totalpaid = $object -> getSumPayment ();
2014-09-21 17:42:38 +02:00
// Confirm for loan
2021-02-26 18:20:21 +01:00
if ( $action == 'paid' ) {
2019-11-13 19:35:39 +01:00
$text = $langs -> trans ( 'ConfirmPayLoan' );
2019-01-27 11:55:16 +01:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . " ?id= " . $object -> id , $langs -> trans ( 'PayLoan' ), $text , " confirm_paid " , '' , '' , 2 );
2014-09-21 17:42:38 +02:00
}
2021-02-26 18:20:21 +01:00
if ( $action == 'delete' ) {
2019-11-13 19:35:39 +01:00
$text = $langs -> trans ( 'ConfirmDeleteLoan' );
2019-01-27 11:55:16 +01:00
print $form -> formconfirm ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $langs -> trans ( 'DeleteLoan' ), $text , 'confirm_delete' , '' , '' , 2 );
2014-09-21 17:42:38 +02:00
}
2021-02-26 18:20:21 +01:00
if ( $action == 'edit' ) {
2019-11-13 19:35:39 +01:00
print '<form name="update" action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST">' . " \n " ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-12-10 07:00:46 +01:00
print '<input type="hidden" name="action" value="update">' ;
print '<input type="hidden" name="id" value="' . $id . '">' ;
2014-09-21 17:42:38 +02:00
}
2020-10-22 22:50:03 +02:00
print dol_get_fiche_head ( $head , 'card' , $langs -> trans ( " Loan " ), - 1 , 'bill' );
2016-04-06 11:21:55 +02:00
2017-01-07 17:45:05 +01:00
// Loan card
2017-06-02 17:48:29 +02:00
2019-12-14 14:53:49 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/loan/list.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-06-02 17:48:29 +02:00
2019-11-13 19:35:39 +01:00
$morehtmlref = '<div class="refidno">' ;
2016-12-20 07:29:49 +01:00
// Ref loan
2019-11-13 19:35:39 +01:00
$morehtmlref .= $form -> editfieldkey ( " Label " , 'label' , $object -> label , $object , $user -> rights -> loan -> write , 'string' , '' , 0 , 1 );
$morehtmlref .= $form -> editfieldval ( " Label " , 'label' , $object -> label , $object , $user -> rights -> loan -> write , 'string' , '' , null , null , '' , 1 );
2017-01-11 05:25:57 +01:00
// Project
2022-06-14 17:53:17 +02:00
if ( ! empty ( $conf -> project -> enabled )) {
2018-05-19 08:06:52 +02:00
$langs -> loadLangs ( array ( " projects " ));
2019-11-13 19:35:39 +01:00
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' ) . ' ' ;
2021-02-26 18:20:21 +01:00
if ( $user -> rights -> loan -> write ) {
if ( $action != 'classify' ) {
2021-09-18 22:09:55 +02:00
$morehtmlref .= '<a class="editfielda" href="' . $_SERVER [ 'PHP_SELF' ] . '?action=classify&token=' . newToken () . '&id=' . $object -> id . '">' . img_edit ( $langs -> transnoentitiesnoconv ( 'SetProject' )) . '</a> : ' ;
2021-02-26 18:20:21 +01:00
}
2017-12-10 07:00:46 +01:00
if ( $action == 'classify' ) {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
2019-11-13 19:35:39 +01:00
$morehtmlref .= '<form method="post" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '">' ;
$morehtmlref .= '<input type="hidden" name="action" value="classin">' ;
2019-12-18 23:12:31 +01:00
$morehtmlref .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-11-13 19:35:39 +01:00
$morehtmlref .= $formproject -> select_projects ( $object -> socid , $object -> fk_project , 'projectid' , $maxlength , 0 , 1 , 0 , 1 , 0 , 0 , '' , 1 );
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
$morehtmlref .= '</form>' ;
2017-12-10 07:00:46 +01:00
} else {
2019-11-13 19:35:39 +01:00
$morehtmlref .= $form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , 'none' , 0 , 0 , 0 , 1 );
2017-12-10 07:00:46 +01:00
}
} else {
2019-11-13 19:35:39 +01:00
if ( ! empty ( $object -> fk_project )) {
2017-12-10 07:00:46 +01:00
$proj = new Project ( $db );
$proj -> fetch ( $object -> fk_project );
2021-10-29 09:40:38 +02:00
$morehtmlref .= ' : ' . $proj -> getNomUrl ( 1 );
if ( $proj -> title ) {
$morehtmlref .= ' - ' . $proj -> title ;
}
2017-12-10 07:00:46 +01:00
} else {
2019-11-13 19:35:39 +01:00
$morehtmlref .= '' ;
2017-12-10 07:00:46 +01:00
}
}
}
2019-11-13 19:35:39 +01:00
$morehtmlref .= '</div>' ;
2017-12-10 07:00:46 +01:00
2019-11-13 19:35:39 +01:00
$object -> totalpaid = $totalpaid ; // To give a chance to dol_banner_tab to use already paid amount to show correct status
2016-12-20 07:29:49 +01:00
dol_banner_tab ( $object , 'id' , $linkback , 1 , 'rowid' , 'ref' , $morehtmlref , '' , 0 , '' , $morehtmlright );
print '<div class="fichecenter">' ;
print '<div class="fichehalfleft">' ;
print '<div class="underbanner clearboth"></div>' ;
2020-04-23 13:41:51 +02:00
print '<table class="border centpercent tableforfield">' ;
2014-09-21 17:42:38 +02:00
2014-09-22 08:25:39 +02:00
// Capital
2021-02-26 18:20:21 +01:00
if ( $action == 'edit' ) {
2017-01-11 05:12:48 +01:00
print '<tr><td class="fieldrequired titlefield">' . $langs -> trans ( " LoanCapital " ) . '</td><td>' ;
2019-11-13 19:35:39 +01:00
print '<input name="capital" size="10" value="' . $object -> capital . '"></td></tr>' ;
2016-12-20 07:29:49 +01:00
print '</td></tr>' ;
2020-05-21 15:05:19 +02:00
} else {
2022-07-26 11:58:47 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " LoanCapital " ) . '</td><td><span class="amount">' . price ( $object -> capital , 0 , $outputlangs , 1 , - 1 , - 1 , $conf -> currency ) . '</span></td></tr>' ;
2016-12-20 07:29:49 +01:00
}
2019-03-03 08:55:27 +01:00
2018-10-18 17:03:49 +02:00
// Insurance
2021-02-26 18:20:21 +01:00
if ( $action == 'edit' ) {
2020-10-31 14:32:18 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( " Insurance " ) . '</td><td>' ;
print '<input name="insurance_amount" size="10" value="' . $object -> insurance_amount . '"></td></tr>' ;
print '</td></tr>' ;
2020-05-21 15:05:19 +02:00
} else {
2022-07-26 11:58:47 +02:00
print '<tr><td class="titlefield">' . $langs -> trans ( " Insurance " ) . '</td><td><span class="amount">' . price ( $object -> insurance_amount , 0 , $outputlangs , 1 , - 1 , - 1 , $conf -> currency ) . '</span></td></tr>' ;
2018-10-18 17:03:49 +02:00
}
2014-09-21 17:42:38 +02:00
2017-12-10 07:00:46 +01:00
// Date start
2017-04-01 12:46:47 +02:00
print '<tr><td>' . $langs -> trans ( " DateStart " ) . " </td> " ;
2014-09-22 08:25:39 +02:00
print " <td> " ;
2021-02-26 18:20:21 +01:00
if ( $action == 'edit' ) {
2018-09-08 13:00:39 +02:00
print $form -> selectDate ( $object -> datestart , 'start' , 0 , 0 , 0 , 'update' , 1 , 0 );
2020-05-21 15:05:19 +02:00
} else {
2019-01-27 11:55:16 +01:00
print dol_print_date ( $object -> datestart , " day " );
2014-09-21 17:42:38 +02:00
}
2014-09-22 08:25:39 +02:00
print " </td></tr> " ;
2014-09-21 17:42:38 +02:00
2014-09-22 08:25:39 +02:00
// Date end
2017-04-01 12:46:47 +02:00
print '<tr><td>' . $langs -> trans ( " DateEnd " ) . " </td> " ;
2014-09-21 17:42:38 +02:00
print " <td> " ;
2021-02-26 18:20:21 +01:00
if ( $action == 'edit' ) {
2018-09-08 13:00:39 +02:00
print $form -> selectDate ( $object -> dateend , 'end' , 0 , 0 , 0 , 'update' , 1 , 0 );
2020-05-21 15:05:19 +02:00
} else {
2019-01-27 11:55:16 +01:00
print dol_print_date ( $object -> dateend , " day " );
2014-09-21 17:42:38 +02:00
}
print " </td></tr> " ;
2015-03-27 17:13:52 +01:00
2014-09-22 08:25:39 +02:00
// Nbterms
2017-03-25 23:48:30 +01:00
print '<tr><td>' . $langs -> trans ( " Nbterms " ) . '</td>' ;
2017-01-11 05:12:48 +01:00
print '<td>' ;
2021-02-26 18:20:21 +01:00
if ( $action == 'edit' ) {
2019-11-13 19:35:39 +01:00
print '<input name="nbterm" size="4" value="' . $object -> nbterm . '">' ;
2020-05-21 15:05:19 +02:00
} else {
2017-01-11 05:12:48 +01:00
print $object -> nbterm ;
}
print '</td></tr>' ;
2015-03-27 17:13:52 +01:00
2014-09-22 08:25:39 +02:00
// Rate
2017-03-25 23:48:30 +01:00
print '<tr><td>' . $langs -> trans ( " Rate " ) . '</td>' ;
2017-01-11 05:12:48 +01:00
print '<td>' ;
2021-02-26 18:20:21 +01:00
if ( $action == 'edit' ) {
2019-11-13 19:35:39 +01:00
print '<input name="rate" size="4" value="' . $object -> rate . '">%' ;
2020-05-21 15:05:19 +02:00
} else {
2019-12-01 10:50:56 +01:00
print price ( $object -> rate ) . '%' ;
2017-01-11 05:12:48 +01:00
}
print '</td></tr>' ;
2014-09-21 17:42:38 +02:00
2017-12-10 07:00:46 +01:00
// Accountancy account capital
2017-12-14 06:57:17 +01:00
print '<tr>' ;
2021-02-26 18:20:21 +01:00
if ( $action == 'edit' ) {
2017-12-14 06:57:17 +01:00
print '<td class="nowrap fieldrequired">' ;
print $langs -> trans ( " LoanAccountancyCapitalCode " );
print '</td><td>' ;
2021-02-26 18:20:21 +01:00
if ( ! empty ( $conf -> accounting -> enabled )) {
2017-12-10 07:00:46 +01:00
print $formaccounting -> select_account ( $object -> account_capital , 'accountancy_account_capital' , 1 , '' , 1 , 1 );
2020-05-21 15:05:19 +02:00
} else {
2017-01-11 05:12:48 +01:00
print '<input name="accountancy_account_capital" size="16" value="' . $object -> account_capital . '">' ;
}
2017-12-14 06:57:17 +01:00
print '</td>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-12-14 06:57:17 +01:00
print '<td class="nowrap">' ;
print $langs -> trans ( " LoanAccountancyCapitalCode " );
print '</td><td>' ;
2021-02-26 18:20:21 +01:00
if ( ! empty ( $conf -> accounting -> enabled )) {
2017-12-14 06:57:17 +01:00
$accountingaccount = new AccountingAccount ( $db );
2019-01-27 11:55:16 +01:00
$accountingaccount -> fetch ( '' , $object -> account_capital , 1 );
2017-12-14 06:57:17 +01:00
2019-01-27 11:55:16 +01:00
print $accountingaccount -> getNomUrl ( 0 , 1 , 1 , '' , 1 );
2017-01-11 05:12:48 +01:00
} else {
print $object -> account_capital ;
}
2017-12-14 06:57:17 +01:00
print '</td>' ;
2016-06-05 15:39:41 +02:00
}
2017-12-14 06:57:17 +01:00
print '</tr>' ;
2016-06-05 15:39:41 +02:00
2017-12-10 07:00:46 +01:00
// Accountancy account insurance
2017-12-14 06:57:17 +01:00
print '<tr>' ;
2021-02-26 18:20:21 +01:00
if ( $action == 'edit' ) {
2017-12-14 06:57:17 +01:00
print '<td class="nowrap fieldrequired">' ;
print $langs -> trans ( " LoanAccountancyInsuranceCode " );
print '</td><td>' ;
2021-02-26 18:20:21 +01:00
if ( ! empty ( $conf -> accounting -> enabled )) {
2017-12-10 07:00:46 +01:00
print $formaccounting -> select_account ( $object -> account_insurance , 'accountancy_account_insurance' , 1 , '' , 1 , 1 );
2020-05-21 15:05:19 +02:00
} else {
2017-01-11 05:12:48 +01:00
print '<input name="accountancy_account_insurance" size="16" value="' . $object -> account_insurance . '">' ;
}
2017-12-14 06:57:17 +01:00
print '</td>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-12-14 06:57:17 +01:00
print '<td class="nowrap">' ;
2020-01-03 14:38:25 +01:00
print $langs -> trans ( " LoanAccountancyInsuranceCode " );
2017-12-14 06:57:17 +01:00
print '</td><td>' ;
2021-02-26 18:20:21 +01:00
if ( ! empty ( $conf -> accounting -> enabled )) {
2017-12-14 06:57:17 +01:00
$accountingaccount = new AccountingAccount ( $db );
2019-01-27 11:55:16 +01:00
$accountingaccount -> fetch ( '' , $object -> account_insurance , 1 );
2017-12-14 06:57:17 +01:00
2019-01-27 11:55:16 +01:00
print $accountingaccount -> getNomUrl ( 0 , 1 , 1 , '' , 1 );
2017-01-11 05:12:48 +01:00
} else {
print $object -> account_insurance ;
}
2017-12-14 06:57:17 +01:00
print '</td>' ;
2016-06-05 15:39:41 +02:00
}
2017-12-14 06:57:17 +01:00
print '</tr>' ;
2016-06-05 15:39:41 +02:00
// Accountancy account interest
2017-12-14 06:57:17 +01:00
print '<tr>' ;
2021-02-26 18:20:21 +01:00
if ( $action == 'edit' ) {
2017-12-14 06:57:17 +01:00
print '<td class="nowrap fieldrequired">' ;
print $langs -> trans ( " LoanAccountancyInterestCode " );
print '</td><td>' ;
2021-02-26 18:20:21 +01:00
if ( ! empty ( $conf -> accounting -> enabled )) {
2017-12-10 07:00:46 +01:00
print $formaccounting -> select_account ( $object -> account_interest , 'accountancy_account_interest' , 1 , '' , 1 , 1 );
2020-05-21 15:05:19 +02:00
} else {
2017-01-11 05:12:48 +01:00
print '<input name="accountancy_account_interest" size="16" value="' . $object -> account_interest . '">' ;
}
2017-12-14 06:57:17 +01:00
print '</td>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-12-14 06:57:17 +01:00
print '<td class="nowrap">' ;
print $langs -> trans ( " LoanAccountancyInterestCode " );
print '</td><td>' ;
2021-02-26 18:20:21 +01:00
if ( ! empty ( $conf -> accounting -> enabled )) {
2017-12-14 06:57:17 +01:00
$accountingaccount = new AccountingAccount ( $db );
2019-01-27 11:55:16 +01:00
$accountingaccount -> fetch ( '' , $object -> account_interest , 1 );
2017-12-14 06:57:17 +01:00
2019-01-27 11:55:16 +01:00
print $accountingaccount -> getNomUrl ( 0 , 1 , 1 , '' , 1 );
2017-01-11 05:12:48 +01:00
} else {
print $object -> account_interest ;
}
2017-12-14 06:57:17 +01:00
print '</td>' ;
2016-06-05 15:39:41 +02:00
}
2017-12-14 06:57:17 +01:00
print '</tr>' ;
2016-06-05 15:39:41 +02:00
2022-02-18 08:23:12 +01:00
// Other attributes
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'formObjectOptions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
print $hookmanager -> resPrint ;
2014-09-21 17:42:38 +02:00
print '</table>' ;
2016-12-20 07:29:49 +01:00
print '</div>' ;
print '<div class="fichehalfright">' ;
2014-09-22 08:25:39 +02:00
/*
* Payments
*/
2014-11-10 06:08:50 +01:00
$sql = " SELECT p.rowid, p.num_payment, datep as dp, " ;
2019-11-13 19:35:39 +01:00
$sql .= " p.amount_capital, p.amount_insurance, p.amount_interest, " ;
$sql .= " c.libelle as paiement_type " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " payment_loan as p " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_paiement as c ON p.fk_typepayment = c.id " ;
$sql .= " , " . MAIN_DB_PREFIX . " loan as l " ;
2021-03-30 19:12:07 +02:00
$sql .= " WHERE p.fk_loan = " . (( int ) $id );
2019-11-13 19:35:39 +01:00
$sql .= " AND p.fk_loan = l.rowid " ;
$sql .= " AND l.entity IN ( " . getEntity ( 'loan' ) . " ) " ;
$sql .= " ORDER BY dp DESC " ;
2014-09-22 08:25:39 +02:00
//print $sql;
$resql = $db -> query ( $sql );
2021-02-26 18:20:21 +01:00
if ( $resql ) {
2014-09-22 08:25:39 +02:00
$num = $db -> num_rows ( $resql );
2015-04-10 18:26:28 +02:00
$i = 0 ;
2017-12-10 07:00:46 +01:00
$total_insurance = 0 ;
$total_interest = 0 ;
$total_capital = 0 ;
2019-05-29 12:56:11 +02:00
2019-11-13 19:35:39 +01:00
print '<div class="div-table-responsive-no-min">' ; // You can use div-table-responsive-no-min if you dont need reserved height for your table
2019-05-29 12:56:11 +02:00
print '<table class="noborder paymenttable">' ;
2014-09-22 08:25:39 +02:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " RefPayment " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Date " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Type " ) . '</td>' ;
2019-03-03 08:55:27 +01:00
print '<td class="right">' . $langs -> trans ( " Insurance " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " Interest " ) . '</td>' ;
print '<td class="right">' . $langs -> trans ( " LoanCapital " ) . '</td>' ;
2018-05-20 07:46:02 +02:00
print '</tr>' ;
2014-09-22 08:25:39 +02:00
2021-02-26 18:20:21 +01:00
while ( $i < $num ) {
2014-09-22 08:25:39 +02:00
$objp = $db -> fetch_object ( $resql );
2017-06-02 17:48:29 +02:00
2017-04-14 11:22:48 +02:00
print '<tr class="oddeven">' ;
2019-01-27 11:55:16 +01:00
print '<td><a href="' . DOL_URL_ROOT . '/loan/payment/card.php?id=' . $objp -> rowid . '">' . img_object ( $langs -> trans ( " Payment " ), " payment " ) . ' ' . $objp -> rowid . '</a></td>' ;
print '<td>' . dol_print_date ( $db -> jdate ( $objp -> dp ), 'day' ) . " </td> \n " ;
2014-09-29 20:37:51 +02:00
print " <td> " . $objp -> paiement_type . ' ' . $objp -> num_payment . " </td> \n " ;
2020-01-13 21:19:32 +01:00
print '<td class="nowrap right">' . price ( $objp -> amount_insurance , 0 , $outputlangs , 1 , - 1 , - 1 , $conf -> currency ) . " </td> \n " ;
print '<td class="nowrap right">' . price ( $objp -> amount_interest , 0 , $outputlangs , 1 , - 1 , - 1 , $conf -> currency ) . " </td> \n " ;
print '<td class="nowrap right">' . price ( $objp -> amount_capital , 0 , $outputlangs , 1 , - 1 , - 1 , $conf -> currency ) . " </td> \n " ;
2014-09-22 08:25:39 +02:00
print " </tr> " ;
2017-12-10 07:00:46 +01:00
$total_capital += $objp -> amount_capital ;
2014-09-22 08:25:39 +02:00
$i ++ ;
}
2016-06-05 16:15:04 +02:00
$totalpaid = $total_capital ;
2015-04-10 18:26:28 +02:00
2021-02-26 18:20:21 +01:00
if ( $object -> paid == 0 || $object -> paid == 2 ) {
2020-01-13 21:19:32 +01:00
print '<tr><td colspan="5" class="right">' . $langs -> trans ( " AlreadyPaid " ) . ' :</td><td class="nowrap right">' . price ( $totalpaid , 0 , $langs , 0 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
print '<tr><td colspan="5" class="right">' . $langs -> trans ( " AmountExpected " ) . ' :</td><td class="nowrap right">' . price ( $object -> capital , 0 , $outputlangs , 1 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
2014-09-22 08:25:39 +02:00
2014-09-29 20:37:51 +02:00
$staytopay = $object -> capital - $totalpaid ;
2014-09-22 08:25:39 +02:00
2019-03-03 08:55:27 +01:00
print '<tr><td colspan="5" class="right">' . $langs -> trans ( " RemainderToPay " ) . ' :</td>' ;
2020-01-13 21:19:32 +01:00
print '<td class="nowrap right' . ( $staytopay ? ' amountremaintopay' : ' amountpaymentcomplete' ) . '">' ;
print price ( $staytopay , 0 , $langs , 0 , - 1 , - 1 , $conf -> currency );
2018-03-12 20:11:34 +01:00
print '</td></tr>' ;
2014-09-22 08:25:39 +02:00
}
print " </table> " ;
2019-05-29 12:56:11 +02:00
print '</div>' ;
2014-09-22 08:25:39 +02:00
$db -> free ( $resql );
2020-05-21 15:05:19 +02:00
} else {
2014-09-22 08:25:39 +02:00
dol_print_error ( $db );
}
2016-12-20 07:29:49 +01:00
print '</div>' ;
print '</div>' ;
print '<div class="clearboth"></div>' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2016-12-20 07:29:49 +01:00
2021-02-26 18:20:21 +01:00
if ( $action == 'edit' ) {
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ();
2016-12-20 07:29:49 +01:00
2017-12-10 07:00:46 +01:00
print '</form>' ;
2017-07-01 14:18:09 +02:00
}
2015-03-27 17:13:52 +01:00
2014-09-29 20:37:51 +02:00
/*
2017-12-10 07:00:46 +01:00
* Buttons actions
2014-10-02 19:56:41 +02:00
*/
2021-02-26 18:20:21 +01:00
if ( $action != 'edit' ) {
2017-01-07 17:45:05 +01:00
$reshook = $hookmanager -> executeHooks ( 'addMoreActionsButtons' , $parameters , $object , $action ); // Note that $action and $object may have been modified by hook
2021-02-26 18:20:21 +01:00
if ( empty ( $reshook )) {
2017-12-10 07:00:46 +01:00
print '<div class="tabsAction">' ;
// Edit
2021-02-26 18:20:21 +01:00
if (( $object -> paid == 0 || $object -> paid == 2 ) && $user -> rights -> loan -> write ) {
2021-09-27 12:24:01 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/loan/card.php?id=' . $object -> id . '&action=edit&token=' . newToken () . '">' . $langs -> trans ( " Modify " ) . '</a></div>' ;
2017-12-10 07:00:46 +01:00
}
// Emit payment
2021-02-26 18:20:21 +01:00
if (( $object -> paid == 0 || $object -> paid == 2 ) && (( price2num ( $object -> capital ) > 0 && round ( $staytopay ) < 0 ) || ( price2num ( $object -> capital ) > 0 && round ( $staytopay ) > 0 )) && $user -> rights -> loan -> write ) {
2021-09-27 12:24:01 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/loan/payment/payment.php?id=' . $object -> id . '&action=create&token=' . newToken () . '">' . $langs -> trans ( " DoPayment " ) . '</a></div>' ;
2017-12-10 07:00:46 +01:00
}
// Classify 'paid'
2021-02-26 18:20:21 +01:00
if (( $object -> paid == 0 || $object -> paid == 2 ) && round ( $staytopay ) <= 0 && $user -> rights -> loan -> write ) {
2021-09-18 22:04:41 +02:00
print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/loan/card.php?id=' . $object -> id . '&action=paid&token=' . newToken () . '">' . $langs -> trans ( " ClassifyPaid " ) . '</a></div>' ;
2017-12-10 07:00:46 +01:00
}
// Delete
2021-02-26 18:20:21 +01:00
if (( $object -> paid == 0 || $object -> paid == 2 ) && $user -> rights -> loan -> delete ) {
2021-09-18 22:04:41 +02:00
print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . DOL_URL_ROOT . '/loan/card.php?id=' . $object -> id . '&action=delete&token=' . newToken () . '">' . $langs -> trans ( " Delete " ) . '</a></div>' ;
2017-12-10 07:00:46 +01:00
}
print " </div> " ;
}
2014-09-29 20:37:51 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2016-12-20 07:29:49 +01:00
// Loan not found
2019-01-27 11:55:16 +01:00
dol_print_error ( '' , $object -> error );
2014-09-21 17:42:38 +02:00
}
}
2018-08-13 11:25:48 +02:00
// End of page
2014-09-21 17:42:38 +02:00
llxFooter ();
2015-03-27 17:13:52 +01:00
$db -> close ();