manage fk_bank on loanschedule
This commit is contained in:
parent
db2937715d
commit
582608cc57
@ -530,6 +530,7 @@ class PaymentLoan extends CommonObject
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
$this->fk_bank = $id_bank;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
|
||||
@ -54,6 +54,9 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->loan->del
|
||||
{
|
||||
$db->begin();
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."loan_schedule SET fk_bank = 0 WHERE fk_bank = ".$payment->fk_bank;
|
||||
$db->query($sql);
|
||||
|
||||
$result = $payment->delete($user);
|
||||
if ($result > 0)
|
||||
{
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
|
||||
require '../../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/loan/class/loanschedule.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/loan/class/paymentloan.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
||||
|
||||
@ -32,6 +33,7 @@ $langs->loadLangs(array("bills","loan"));
|
||||
$chid=GETPOST('id','int');
|
||||
$action=GETPOST('action','aZ09');
|
||||
$cancel=GETPOST('cancel','alpha');
|
||||
$line_id = GETPOST('line_id', 'int');
|
||||
|
||||
// Security check
|
||||
$socid=0;
|
||||
@ -43,6 +45,17 @@ if ($user->societe_id > 0)
|
||||
$loan = new Loan($db);
|
||||
$loan->fetch($chid);
|
||||
|
||||
if (!empty($line_id))
|
||||
{
|
||||
$line = new LoanSchedule($db);
|
||||
$res = $line->fetch($line_id);
|
||||
if ($res > 0){
|
||||
$amount_capital = price($line->amount_capital);
|
||||
$amount_insurance = price($line->amount_insurance);
|
||||
$amount_interest = price($line->amount_interest);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Actions
|
||||
*/
|
||||
@ -121,6 +134,12 @@ if ($action == 'add_payment')
|
||||
setEventMessages($payment->error, $payment->errors, 'errors');
|
||||
$error++;
|
||||
}
|
||||
elseif(isset($line))
|
||||
{
|
||||
$line->fk_bank = $payment->fk_bank;
|
||||
$line->update($user);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
@ -161,6 +180,7 @@ if ($action == 'create')
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="id" value="'.$chid.'">';
|
||||
print '<input type="hidden" name="chid" value="'.$chid.'">';
|
||||
print '<input type="hidden" name="line_id" value="'.$line_id.'">';
|
||||
print '<input type="hidden" name="action" value="add_payment">';
|
||||
|
||||
dol_fiche_head();
|
||||
@ -264,7 +284,7 @@ if ($action == 'create')
|
||||
print '<td align="right">';
|
||||
if ($sumpaid < $loan->capital)
|
||||
{
|
||||
print $langs->trans("LoanCapital") .': <input type="text" size="8" name="amount_capital" value="'.GETPOST('amount_capital').'">';
|
||||
print $langs->trans("LoanCapital") .': <input type="text" size="8" name="amount_capital" value="'.$amount_capital.'">';
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -273,7 +293,7 @@ if ($action == 'create')
|
||||
print '<br>';
|
||||
if ($sumpaid < $loan->capital)
|
||||
{
|
||||
print $langs->trans("Insurance") .': <input type="text" size="8" name="amount_insurance" value="'.GETPOST('amount_insurance').'">';
|
||||
print $langs->trans("Insurance") .': <input type="text" size="8" name="amount_insurance" value="'.$amount_insurance.'">';
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -282,7 +302,7 @@ if ($action == 'create')
|
||||
print '<br>';
|
||||
if ($sumpaid < $loan->capital)
|
||||
{
|
||||
print $langs->trans("Interest") .': <input type="text" size="8" name="amount_interest" value="'.GETPOST('amount_interest').'">';
|
||||
print $langs->trans("Interest") .': <input type="text" size="8" name="amount_interest" value="'.$amount_interest.'">';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -184,6 +184,7 @@ if ($object->nbterm > 0 && count($echeance->lines)==0)
|
||||
$mens = price2num($echeance->calcMonthlyPayments($capital, $object->rate/100, $object->nbterm-$i+1), 'MT');
|
||||
$int = ($capital*($object->rate/12))/100;
|
||||
$int = price2num($int, 'MT');
|
||||
$insu = ($insurance+(($i == 1) ? $regulInsurance : 0));
|
||||
$cap_rest = price2num($capital - ($mens-$int), 'MT');
|
||||
print '<tr>';
|
||||
print '<td align="center" id="n'.$i.'">' . $i .'</td>';
|
||||
@ -204,17 +205,19 @@ elseif(count($echeance->lines)>0)
|
||||
$insurance = $object->insurance_amount/$object->nbterm;
|
||||
$insurance = price2num($insurance, 'MT');
|
||||
$regulInsurance = price2num($object->insurance_amount - ($insurance * $object->nbterm));
|
||||
$printed = false;
|
||||
foreach ($echeance->lines as $line){
|
||||
$mens = $line->amount_capital+$line->amount_insurance+$line->amount_interest;
|
||||
$int = $line->amount_interest;
|
||||
$cap_rest = price2num($capital - ($mens-$int), 'MT');
|
||||
$insu = ($insurance+(($i == 1) ? $regulInsurance : 0));
|
||||
$cap_rest = price2num($capital - ($mens-$int-$insu), 'MT');
|
||||
|
||||
print '<tr>';
|
||||
print '<td align="center" id="n'.$i.'"><input type="hidden" name="hi_rowid' .$i .'" id ="hi_rowid' .$i .'" value="' . $line->id . '">' . $i .'</td>';
|
||||
print '<td align="center" id ="date' .$i .'"><input type="hidden" name="hi_date' .$i .'" id ="hi_date' .$i .'" value="' . $line->datep . '">' . dol_print_date($line->datep,'day') . '</td>';
|
||||
print '<td align="center" id="insurance'.$i.'">'.price($insu,0,'',1).' €</td><input type="hidden" name="hi_insurance' .$i .'" id ="hi_insurance' .$i .'" value="' . $insu . '">';
|
||||
print '<td align="center" id="interets'.$i.'">'.price($int,0,'',1).' €</td><input type="hidden" name="hi_interets' .$i .'" id ="hi_interets' .$i .'" value="' . $int . '">';
|
||||
if($line->datep > dol_now()){
|
||||
if($line->datep > dol_now() && empty($line->fk_bank)){
|
||||
print '<td align="center"><input name="mens'.$i.'" id="mens'.$i.'" size="5" value="'.$mens.'" ech="'.$i.'"> €</td>';
|
||||
}else{
|
||||
print '<td align="center">' . price($mens) . ' €</td><input type="hidden" name="mens' .$i .'" id ="mens' .$i .'" value="' . $mens . '">';
|
||||
@ -222,7 +225,12 @@ elseif(count($echeance->lines)>0)
|
||||
|
||||
print '<td align="center" id="capital'.$i.'">'.price($cap_rest).' €</td><input type="hidden" name="hi_capital' .$i .'" id ="hi_capital' .$i .'" value="' . $cap_rest . '">';
|
||||
print '<td align="center">';
|
||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&action=create&amount_capital='.urlencode(price($mens-$int)).'&amount_insurance='.urlencode(price($insu)).'&amount_interest='.urlencode(price($int)).'">'.$langs->trans('DoPayment').'</a>';
|
||||
if (!empty($line->fk_bank)) print $langs->trans('Paid');
|
||||
elseif (!$printed)
|
||||
{
|
||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/loan/payment/payment.php?id='.$object->id.'&action=create&line_id='.$line->id.'">'.$langs->trans('DoPayment').'</a>';
|
||||
$printed = true;
|
||||
}
|
||||
print '</td>';
|
||||
print '</tr>'."\n";
|
||||
$i++;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user