2014-09-21 17:42:38 +02:00
< ? php
2017-12-10 07:00:46 +01:00
/* Copyright ( C ) 2014 - 2017 Alexandre Spangaro < aspangaro @ zendsi . com >
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 >
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
* along with this program . If not , see < http :// www . gnu . org / licenses />.
*/
/**
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' ;
2016-06-05 15:21:11 +02:00
if ( ! empty ( $conf -> accounting -> enabled )) require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php' ;
2017-05-25 06:57:28 +02:00
if ( ! empty ( $conf -> accounting -> enabled )) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.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
$langs -> load ( " compta " );
$langs -> load ( " bills " );
$langs -> load ( " loan " );
$id = GETPOST ( 'id' , 'int' );
2017-05-16 13:27:32 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2014-09-21 17:42:38 +02:00
$confirm = GETPOST ( 'confirm' );
2014-11-10 06:08:50 +01:00
$cancel = GETPOST ( 'cancel' , 'alpha' );
2014-09-21 17:42:38 +02:00
2017-07-29 00:28:41 +02:00
$projectid = GETPOST ( 'projectid' , 'int' );
2014-09-21 17:42:38 +02:00
// Security check
$socid = GETPOST ( 'socid' , 'int' );
if ( $user -> societe_id ) $socid = $user -> societe_id ;
$result = restrictedArea ( $user , 'loan' , $id , '' , '' );
2014-11-10 06:08:50 +01:00
$object = new Loan ( $db );
2016-11-14 19:25:50 +01:00
$hookmanager -> initHooks ( array ( 'loancard' , 'globalcard' ));
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
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
if ( empty ( $reshook ))
2014-09-21 17:42:38 +02:00
{
2017-12-10 07:00:46 +01:00
// Classify paid
if ( $action == 'confirm_paid' && $confirm == 'yes' )
{
$object -> fetch ( $id );
$result = $object -> set_paid ( $user );
if ( $result > 0 )
{
setEventMessages ( $langs -> trans ( 'LoanPaid' ), null , 'mesgs' );
}
else
{
setEventMessages ( $loan -> error , null , 'errors' );
}
}
2017-06-02 17:48:29 +02:00
2017-12-10 07:00:46 +01:00
// Delete loan
if ( $action == 'confirm_delete' && $confirm == 'yes' )
{
$object -> fetch ( $id );
$result = $object -> delete ( $user );
if ( $result > 0 )
{
setEventMessages ( $langs -> trans ( 'LoanDeleted' ), null , 'mesgs' );
header ( " Location: index.php " );
exit ;
}
else
{
setEventMessages ( $loan -> error , null , 'errors' );
}
}
2017-06-02 17:48:29 +02:00
2017-12-10 07:00:46 +01:00
// Add loan
if ( $action == 'add' && $user -> rights -> loan -> write )
{
if ( ! $cancel )
{
$datestart = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'startmonth' , 'int' ), GETPOST ( 'startday' , 'int' ), GETPOST ( 'startyear' , 'int' ));
$dateend = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'endmonth' , 'int' ), GETPOST ( 'endday' , 'int' ), GETPOST ( 'endyear' , 'int' ));
$capital = price2num ( GETPOST ( 'capital' ));
$rate = GETPOST ( 'rate' );
2017-06-02 17:48:29 +02:00
2017-12-10 07:00:46 +01:00
if ( ! $capital )
{
$error ++ ; $action = 'create' ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " LoanCapital " )), null , 'errors' );
}
if ( ! $datestart )
{
$error ++ ; $action = 'create' ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " DateStart " )), null , 'errors' );
}
if ( ! $dateend )
{
$error ++ ; $action = 'create' ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " DateEnd " )), null , 'errors' );
}
if ( $rate == '' )
{
$error ++ ; $action = 'create' ;
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " Rate " )), null , 'errors' );
}
2017-06-02 17:48:29 +02:00
2017-04-01 12:46:47 +02:00
if ( ! $error )
2017-01-07 17:45:05 +01:00
{
$object -> label = GETPOST ( 'label' );
$object -> fk_bank = GETPOST ( 'accountid' );
$object -> capital = $capital ;
$object -> datestart = $datestart ;
$object -> dateend = $dateend ;
$object -> nbterm = GETPOST ( 'nbterm' );
2017-04-01 12:46:47 +02:00
$object -> rate = $rate ;
2017-09-25 00:16:52 +02:00
$object -> note_private = GETPOST ( 'note_private' , 'none' );
$object -> note_public = GETPOST ( 'note_public' , 'none' );
2017-07-29 00:28:41 +02:00
$object -> fk_project = GETPOST ( 'projectid' , 'int' );
2017-06-02 17:48:29 +02:00
2017-01-07 17:45:05 +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
2017-01-07 17:45:05 +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-06-02 17:48:29 +02:00
2017-01-07 17:45:05 +01:00
$id = $object -> create ( $user );
if ( $id <= 0 )
{
2017-04-01 12:46:47 +02:00
$error ++ ;
2017-01-07 17:45:05 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2017-04-01 12:46:47 +02:00
$action = 'create' ;
2017-01-07 17:45:05 +01:00
}
}
}
else
{
header ( " Location: index.php " );
exit ();
}
}
2017-06-02 17:48:29 +02:00
2017-12-10 07:00:46 +01:00
// Update record
else if ( $action == 'update' && $user -> rights -> loan -> write )
{
if ( ! $cancel )
{
$result = $object -> fetch ( $id );
2017-01-11 05:25:57 +01:00
2017-12-10 07:00:46 +01:00
$datestart = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'startmonth' , 'int' ), GETPOST ( 'startday' , 'int' ), GETPOST ( 'startyear' , 'int' ));
$dateend = dol_mktime ( 12 , 0 , 0 , GETPOST ( 'endmonth' , 'int' ), GETPOST ( 'endday' , 'int' ), GETPOST ( 'endyear' , 'int' ));
$capital = price2num ( GETPOST ( 'capital' ));
2017-06-02 17:48:29 +02:00
2017-12-10 07:00:46 +01:00
if ( ! $capital )
{
setEventMessages ( $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentities ( " LoanCapital " )), null , 'errors' );
$action = 'edit' ;
}
else
{
2017-01-11 05:25:57 +01:00
$object -> datestart = $datestart ;
$object -> dateend = $dateend ;
$object -> capital = $capital ;
2017-12-10 07:00:46 +01:00
$object -> nbterm = GETPOST ( " nbterm " );
$object -> rate = GETPOST ( " rate " );
2017-01-11 05:25:57 +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
2017-01-11 05:25:57 +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 );
if ( $result > 0 )
{
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id );
exit ;
}
else
{
2017-12-10 21:46:23 +01:00
$error ++ ;
2017-12-10 07:00:46 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
}
else
{
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . " ?id= " . $id );
exit ;
}
}
2017-06-02 17:48:29 +02:00
2017-01-07 17:45:05 +01:00
// Link to a project
if ( $action == 'classin' && $user -> rights -> loan -> write )
2014-09-21 17:42:38 +02:00
{
2017-12-10 07:00:46 +01:00
$object -> fetch ( $id );
$result = $object -> setProject ( $projectid );
2017-01-07 17:45:05 +01:00
if ( $result < 0 )
2017-12-10 07:00:46 +01:00
setEventMessages ( $object -> error , $object -> errors , 'errors' );
2014-09-21 17:42:38 +02:00
}
2017-12-10 07:00:46 +01:00
if ( $action == 'setlabel' && $user -> rights -> loan -> write )
{
$object -> fetch ( $id );
$result = $object -> setValueFrom ( 'label' , GETPOST ( 'label' ), '' , '' , 'text' , '' , $user , 'LOAN_MODIFY' );
if ( $result < 0 )
setEventMessages ( $object -> error , $object -> errors , 'errors' );
}
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 );
2017-05-25 06:57:28 +02:00
if ( ! empty ( $conf -> accounting -> enabled )) $formaccounting = New FormAccounting ( $db );
2014-09-21 17:42:38 +02:00
2016-12-20 07:29:49 +01:00
$title = $langs -> trans ( " Loan " ) . ' - ' . $langs -> trans ( " Card " );
$help_url = 'EN:Module_Loan|FR:Module_Emprunt' ;
llxHeader ( " " , $title , $help_url );
2014-09-21 17:42:38 +02:00
// Create mode
if ( $action == 'create' )
{
//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
2017-12-10 07:00:46 +01:00
print load_fiche_titre ( $langs -> trans ( " NewLoan " ), '' , 'title_accountancy.png' );
2014-09-21 17:42:38 +02:00
2017-12-10 07:00:46 +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
2017-12-10 07:00:46 +01:00
print '<form name="loan" action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST">' . " \n " ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="add">' ;
2014-09-21 17:42:38 +02:00
2015-05-20 07:03:17 +02:00
dol_fiche_head ();
2017-12-10 07:00:46 +01:00
print '<table class="border" width="100%">' ;
2015-03-27 17:13:52 +01:00
2014-09-21 17:42:38 +02:00
// Label
2016-12-20 07:29:49 +01:00
print '<tr><td class="fieldrequired titlefieldcreate">' . $langs -> trans ( " Label " ) . '</td><td><input name="label" size="40" maxlength="255" value="' . dol_escape_htmltag ( GETPOST ( 'label' )) . '"></td></tr>' ;
2014-09-21 17:42:38 +02:00
// Bank account
if ( ! empty ( $conf -> banque -> enabled ))
{
print '<tr><td class="fieldrequired">' . $langs -> trans ( " Account " ) . '</td><td>' ;
2016-04-06 11:21:55 +02: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>' ;
}
else
{
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
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>' ;
print $form -> select_date ( $datestart ? $datestart :- 1 , 'start' , '' , '' , '' , 'add' , 1 , 1 , 1 );
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>' ;
print $form -> select_date ( $dateend ? $dateend :- 1 , 'end' , '' , '' , '' , 'add' , 1 , 1 , 1 );
print '</td></tr>' ;
2015-03-27 17:13:52 +01:00
2014-09-21 17:42:38 +02:00
// Number of terms
2017-03-26 01:57:09 +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
2017-12-10 07:00:46 +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
2017-12-10 07:00:46 +01:00
// Project
if ( ! empty ( $conf -> projet -> enabled ))
{
2016-11-14 19:25:50 +01:00
$formproject = new FormProjets ( $db );
// Projet associe
$langs -> load ( " projects " );
2017-12-10 07:00:46 +01:00
print '<tr><td>' . $langs -> trans ( " Project " ) . '</td><td>' ;
2017-06-02 17:48:29 +02:00
2017-12-10 07:00:46 +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
2017-12-10 07:00:46 +01:00
$doleditor = new DolEditor ( 'note_private' , GETPOST ( 'note_private' , 'alpha' ), '' , 160 , 'dolibarr_notes' , 'In' , false , true , true , ROWS_6 , '90%' );
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>' ;
$doleditor = new DolEditor ( 'note_public' , GETPOST ( 'note_public' , 'alpha' ), '' , 160 , 'dolibarr_notes' , 'In' , false , true , true , ROWS_6 , '90%' );
print $doleditor -> Create ( 1 );
print '</td></tr>' ;
2015-03-27 17:13:52 +01:00
2017-12-10 07:00:46 +01:00
// Accountancy
2016-06-05 15:21:11 +02:00
if ( ! empty ( $conf -> accounting -> enabled ))
2014-09-21 17:42:38 +02:00
{
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>' ;
2017-05-25 06:57:28 +02:00
print $formaccounting -> select_account ( $object -> accountancy_account_capital , 'accountancy_account_capital' , 1 , '' , 0 , 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>' ;
2017-05-25 06:57:28 +02:00
print $formaccounting -> select_account ( $object -> accountancy_account_insurance , 'accountancy_account_insurance' , 1 , '' , 0 , 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>' ;
2017-05-25 06:57:28 +02:00
print $formaccounting -> select_account ( $object -> accountancy_account_interest , 'accountancy_account_interest' , 1 , '' , 0 , 1 );
2017-12-10 07:00:46 +01:00
print '</td></tr>' ;
2016-12-20 07:29:49 +01:00
}
2017-06-02 17:48:29 +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
2015-05-20 07:03:17 +02:00
dol_fiche_end ();
2016-12-20 07:29:49 +01:00
print '<div class="center">' ;
print '<input type="submit" class="button" value="' . $langs -> trans ( " Add " ) . '">' ;
print ' ' ;
print '<input type="button" class="button" value="' . $langs -> trans ( " Cancel " ) . '" onClick="javascript:history.go(-1)">' ;
print '</div>' ;
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
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
if ( $result > 0 )
{
$head = loan_prepare_head ( $object );
2016-12-20 07:29:49 +01:00
$totalpaid = $object -> getSumPayment ();
2014-09-21 17:42:38 +02:00
// Confirm for loan
if ( $action == 'paid' )
{
$text = $langs -> trans ( 'ConfirmPayLoan' );
2016-03-25 15:53:44 +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
}
if ( $action == 'delete' )
{
$text = $langs -> trans ( 'ConfirmDeleteLoan' );
2016-03-25 15:53:44 +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
}
if ( $action == 'edit' )
{
2014-11-10 06:08:50 +01:00
print '<form name="update" action="' . $_SERVER [ " PHP_SELF " ] . '" method="POST">' . " \n " ;
2017-12-10 07:00:46 +01:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="update">' ;
print '<input type="hidden" name="id" value="' . $id . '">' ;
2014-09-21 17:42:38 +02:00
}
2017-07-01 14:18:09 +02:00
dol_fiche_head ( $head , 'card' , $langs -> trans ( " Loan " ), - 1 , 'bill' );
2016-04-06 11:21:55 +02:00
2017-06-02 17:48:29 +02:00
print '<script type="text/javascript">' . " \n " ;
print ' function popEcheancier() {' . " \n " ;
print ' $div = $(\'<div id="popCalendar"><iframe width="100%" height="100%" frameborder="0" src="createschedule.php?loanid=' . $object -> id . '"></iframe></div>\');' . " \n " ;
print ' $div.dialog({' . " \n " ;
print ' modal:true' . " \n " ;
print ' ,width:"90%"' . " \n " ;
print ' ,height:$(window).height() - 150' . " \n " ;
print ' });' . " \n " ;
print ' }' . " \n " ;
print '</script>' ;
2017-01-07 17:45:05 +01:00
// Loan card
2017-06-02 17:48:29 +02:00
2017-01-07 17:45:05 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/loan/index.php">' . $langs -> trans ( " BackToList " ) . '</a>' ;
2017-06-02 17:48:29 +02:00
2016-12-20 07:29:49 +01:00
$morehtmlref = '<div class="refidno">' ;
// Ref loan
$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
2017-12-10 07:00:46 +01:00
if ( ! empty ( $conf -> projet -> enabled ))
{
$langs -> load ( " projects " );
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' ) . ' ' ;
if ( $user -> rights -> loan -> write )
{
if ( $action != 'classify' )
$morehtmlref .= '<a href="' . $_SERVER [ 'PHP_SELF' ] . '?action=classify&id=' . $object -> id . '">' . img_edit ( $langs -> transnoentitiesnoconv ( 'SetProject' )) . '</a> : ' ;
if ( $action == 'classify' ) {
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
$morehtmlref .= '<form method="post" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '">' ;
$morehtmlref .= '<input type="hidden" name="action" value="classin">' ;
$morehtmlref .= '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
$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>' ;
} else {
$morehtmlref .= $form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , 'none' , 0 , 0 , 0 , 1 );
}
} else {
if ( ! empty ( $object -> fk_project )) {
$proj = new Project ( $db );
$proj -> fetch ( $object -> fk_project );
$morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $object -> fk_project . '" title="' . $langs -> trans ( 'ShowProject' ) . '">' ;
$morehtmlref .= $proj -> ref ;
$morehtmlref .= '</a>' ;
} else {
$morehtmlref .= '' ;
}
}
}
$morehtmlref .= '</div>' ;
$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>' ;
2014-09-21 17:42:38 +02:00
print '<table class="border" width="100%">' ;
2014-09-22 08:25:39 +02:00
// Capital
2016-12-20 07:29:49 +01:00
if ( $action == 'edit' )
{
2017-01-11 05:12:48 +01:00
print '<tr><td class="fieldrequired titlefield">' . $langs -> trans ( " LoanCapital " ) . '</td><td>' ;
2016-12-20 07:29:49 +01:00
print '<input name="capital" size="10" value="' . $object -> capital . '"></td></tr>' ;
print '</td></tr>' ;
}
else
{
print '<tr><td class="titlefield">' . $langs -> trans ( " LoanCapital " ) . '</td><td>' . price ( $object -> capital , 0 , $outputlangs , 1 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
}
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> " ;
if ( $action == 'edit' )
2014-09-21 17:42:38 +02:00
{
2016-03-25 15:53:44 +01:00
print $form -> select_date ( $object -> datestart , 'start' , 0 , 0 , 0 , 'update' , 1 , 0 , 1 );
2014-09-21 17:42:38 +02:00
}
else
{
2014-09-22 08:25:39 +02: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> " ;
if ( $action == 'edit' )
{
2016-03-25 15:53:44 +01:00
print $form -> select_date ( $object -> dateend , 'end' , 0 , 0 , 0 , 'update' , 1 , 0 , 1 );
2014-09-21 17:42:38 +02:00
}
else
{
2014-09-22 08:25:39 +02: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>' ;
if ( $action == 'edit' )
{
print '<input name="nbterm" size="4" value="' . $object -> nbterm . '">' ;
}
else
{
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>' ;
if ( $action == 'edit' )
{
print '<input name="rate" size="4" value="' . $object -> rate . '">%' ;
}
else
{
print $object -> rate . '%' ;
}
print '</td></tr>' ;
2014-09-21 17:42:38 +02:00
2017-12-10 07:00:46 +01:00
// Accountancy account capital
2016-06-05 15:39:41 +02:00
print '<tr><td class="nowrap">' ;
2017-12-10 07:00:46 +01:00
print $langs -> trans ( " LoanAccountancyCapitalCode " );
print '</td><td>' ;
2017-01-11 05:12:48 +01:00
if ( $action == 'edit' )
{
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 );
2017-01-11 05:12:48 +01:00
}
else
{
print '<input name="accountancy_account_capital" size="16" value="' . $object -> account_capital . '">' ;
}
}
else
{
if ( ! empty ( $conf -> accounting -> enabled )) {
print length_accountg ( $object -> account_capital );
} else {
print $object -> account_capital ;
}
2016-06-05 15:39:41 +02:00
}
print '</td></tr>' ;
2017-12-10 07:00:46 +01:00
// Accountancy account insurance
2016-06-05 15:39:41 +02:00
print '<tr><td class="nowrap">' ;
2017-12-10 07:00:46 +01:00
print $langs -> trans ( " LoanAccountancyInsuranceCode " );
print '</td><td>' ;
2017-01-11 05:12:48 +01:00
if ( $action == 'edit' )
{
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 );
2017-01-11 05:12:48 +01:00
}
else
{
print '<input name="accountancy_account_insurance" size="16" value="' . $object -> account_insurance . '">' ;
}
}
else
{
if ( ! empty ( $conf -> accounting -> enabled )) {
print length_accountg ( $object -> account_insurance );
} else {
print $object -> account_insurance ;
}
2016-06-05 15:39:41 +02:00
}
print '</td></tr>' ;
// Accountancy account interest
print '<tr><td class="nowrap">' ;
2017-12-10 07:00:46 +01:00
print $langs -> trans ( " LoanAccountancyInterestCode " );
print '</td><td>' ;
2017-01-11 05:12:48 +01:00
if ( $action == 'edit' )
{
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 );
2017-01-11 05:12:48 +01:00
}
else
{
print '<input name="accountancy_account_interest" size="16" value="' . $object -> account_interest . '">' ;
}
}
else
{
if ( ! empty ( $conf -> accounting -> enabled )) {
print length_accountg ( $object -> account_interest );
} else {
print $object -> account_interest ;
}
2016-06-05 15:39:41 +02:00
}
print '</td></tr>' ;
2014-09-21 17:42:38 +02:00
print '</table>' ;
2016-12-20 07:29:49 +01:00
print '</div>' ;
print '<div class="fichehalfright">' ;
print '<div class="ficheaddleft">' ;
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, " ;
$sql .= " p.amount_capital, p.amount_insurance, p.amount_interest, " ;
$sql .= " c.libelle as paiement_type " ;
2014-09-22 08:25:39 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " payment_loan as p " ;
2017-11-23 15:06:16 +01:00
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " c_paiement as c ON p.fk_typepayment = c.id AND c.entity IN ( " . getEntity ( 'c_paiement' ) . " ) " ;
2014-09-22 08:25:39 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " loan as l " ;
$sql .= " WHERE p.fk_loan = " . $id ;
$sql .= " AND p.fk_loan = l.rowid " ;
2017-11-23 15:06:16 +01:00
$sql .= " AND l.entity IN ( " . getEntity ( 'loan' ) . " ) " ;
2014-09-22 08:25:39 +02:00
$sql .= " ORDER BY dp DESC " ;
//print $sql;
$resql = $db -> query ( $sql );
if ( $resql )
{
$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 ;
2016-12-20 07:29:49 +01: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>' ;
2016-12-20 07:29:49 +01:00
print '<td align="right">' . $langs -> trans ( " Insurance " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " Interest " ) . '</td>' ;
2017-12-10 07:00:46 +01:00
print '<td align="right">' . $langs -> trans ( " LoanCapital " ) . '</td>' ;
print '</tr>' ;
2014-09-22 08:25:39 +02:00
$var = True ;
while ( $i < $num )
{
$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">' ;
2015-04-10 18:26:28 +02: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>' ;
2014-09-22 08:25:39 +02:00
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 " ;
2017-12-10 07:00:46 +01:00
print '<td align="right">' . price ( $objp -> amount_insurance , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " </td> \n " ;
print '<td align="right">' . price ( $objp -> amount_interest , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . " </td> \n " ;
print '<td align="right">' . price ( $objp -> amount_capital , 0 , $langs , 0 , 0 , - 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
2014-09-29 20:37:51 +02:00
if ( $object -> paid == 0 )
2014-09-22 08:25:39 +02:00
{
2016-12-20 07:29:49 +01:00
print '<tr><td colspan="5" align="right">' . $langs -> trans ( " AlreadyPaid " ) . ' :</td><td align="right">' . price ( $totalpaid , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . '</td></tr>' ;
print '<tr><td colspan="5" align="right">' . $langs -> trans ( " AmountExpected " ) . ' :</td><td align="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
2015-04-10 18:26:28 +02:00
print '<tr><td colspan="5" align="right">' . $langs -> trans ( " RemainderToPay " ) . ' :</td>' ;
2016-12-20 07:29:49 +01:00
print '<td align="right"><b>' . price ( $staytopay , 0 , $langs , 0 , 0 , - 1 , $conf -> currency ) . '</b></td></tr>' ;
2014-09-22 08:25:39 +02:00
}
print " </table> " ;
$db -> free ( $resql );
}
else
{
dol_print_error ( $db );
}
2016-12-20 07:29:49 +01:00
print '</div>' ;
print '</div>' ;
print '</div>' ;
print '<div class="clearboth"></div>' ;
dol_fiche_end ();
if ( $action == 'edit' )
{
print '<div class="center">' ;
print '<input type="submit" class="button" name="save" value="' . $langs -> trans ( " Save " ) . '">' ;
print ' ' ;
print '<input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
print '</div>' ;
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
*/
2014-09-29 20:37:51 +02: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
if ( empty ( $reshook ))
2017-12-10 07:00:46 +01:00
{
print '<div class="tabsAction">' ;
// Edit
if ( $user -> rights -> loan -> write )
{
print '<a href="javascript:popEcheancier()" class="butAction">' . $langs -> trans ( 'CreateCalcSchedule' ) . '</a>' ;
print '<a class="butAction" href="' . DOL_URL_ROOT . '/loan/card.php?id=' . $object -> id . '&action=edit">' . $langs -> trans ( " Modify " ) . '</a>' ;
}
// Emit payment
if ( $object -> paid == 0 && (( price2num ( $object -> capital ) > 0 && round ( $staytopay ) < 0 ) || ( price2num ( $object -> capital ) > 0 && round ( $staytopay ) > 0 )) && $user -> rights -> loan -> write )
{
print '<a class="butAction" href="' . DOL_URL_ROOT . '/loan/payment/payment.php?id=' . $object -> id . '&action=create">' . $langs -> trans ( " DoPayment " ) . '</a>' ;
}
// Classify 'paid'
if ( $object -> paid == 0 && round ( $staytopay ) <= 0 && $user -> rights -> loan -> write )
{
print '<a class="butAction" href="' . DOL_URL_ROOT . '/loan/card.php?id=' . $object -> id . '&action=paid">' . $langs -> trans ( " ClassifyPaid " ) . '</a>' ;
}
// Delete
if ( $user -> rights -> loan -> delete )
{
print '<a class="butActionDelete" href="' . DOL_URL_ROOT . '/loan/card.php?id=' . $object -> id . '&action=delete">' . $langs -> trans ( " Delete " ) . '</a>' ;
}
print " </div> " ;
}
2014-09-29 20:37:51 +02:00
}
2014-09-21 17:42:38 +02:00
}
else
{
2016-12-20 07:29:49 +01:00
// Loan not found
2014-09-21 17:42:38 +02:00
dol_print_error ( '' , $object -> error );
}
}
llxFooter ();
2015-03-27 17:13:52 +01:00
$db -> close ();