* * 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 . */ /** * \file htdocs/compta/loan/card.php * \ingroup loan * \brief Loan card */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/loan/class/loan.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; $langs->load("compta"); $langs->load("bills"); $langs->load("loan"); $id=GETPOST('id','int'); $action=GETPOST('action'); $confirm=GETPOST('confirm'); $cancel=GETPOST('cancel'); // Security check $socid = GETPOST('socid','int'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'loan', $id, '',''); /* * Actions */ // Classify paid if ($action == 'confirm_paid' && $confirm == 'yes') { $object = new Loan($db); $object->fetch($id); $result = $object->set_paid($user); } // Delete loan if ($action == 'confirm_delete' && $confirm == 'yes') { $object = new Loan($db); $object->fetch($id); $result=$object->delete($user); if ($result > 0) { header("Location: index.php"); exit; } else { setEventMessage($loan->error, 'errors'); } } // Add loan if ($action == 'add' && $user->rights->loan->write) { $datestart=@dol_mktime(12,0,0, $_POST["startmonth"], $_POST["startday"], $_POST["startyear"]); $dateend=@dol_mktime(12,0,0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]); if (! $datestart) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateStart")), 'errors'); $action = 'create'; } elseif (! $dateend) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateEnd")), 'errors'); $action = 'create'; } elseif (! $_POST["capital"]) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Capital")), 'errors'); $action = 'create'; } else { $object = new Loan($db); $object->label = $_POST["label"]; $object->fk_bank = $_POST["accountid"]; $object->capital = $_POST["capital"]; $object->datestart = $datestart; $object->dateend = $dateend; $object->nbterm = $_POST["nbterm"]; $object->rate = $_POST["rate"]; $object->account_capital = $_POST["accountancy_account_capital"]; $object->account_insurance = $_POST["accountancy_account_insurance"]; $object->account_interest = $_POST["accountancy_account_interest"]; $id=$object->create($user); if ($id <= 0) { setEventMessage($object->error, 'errors'); } } } if ($action == 'update' && ! $cancel && $user->rights->loan->write) { $datestart=dol_mktime(12,0,0, $GETPOST("startmonth"), $GETPOST("startday"), $GETPOST("startyear")); $dateend=dol_mktime(12,0,0, $GETPOST("endmonth"), $GETPOST("endday"), $GETPOST("endyear")); if (! $datestart) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateStart")), 'errors'); $action = 'edit'; } elseif (! $dateend) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateEnd")), 'errors'); $action = 'edit'; } else { $object = new Loan($db); if ($object->fetch($id)) { $object->label = $GETPOST("label"); $object->datestart = $datestart; $object->dateend = $dateend; } if ($object->update($id, $user) > 0) { $action = ''; } else { $action = 'edit'; setEventMessage($object->error, 'errors'); } } } /* * View */ $form = new Form($db); $help_url='EN:Module_Loan|FR:Module_Emprunt'; llxHeader("",$langs->trans("Loan"),$help_url); // Create mode if ($action == 'create') { //WYSIWYG Editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; print_fiche_titre($langs->trans("NewLoan")); $datec = dol_mktime(12, 0, 0, GETPOST('remonth','int'), GETPOST('reday','int'), GETPOST('reyear','int')); print '
' . "\n"; print ''; print ''; print ''; // Label print ''; // Bank account if (! empty($conf->banque->enabled)) { print ''; } else { print ''; } // Capital print ''; // Date Start print ""; print ''; // Date End print ""; print ''; // Number of terms print ''; // Rate print ''; // Note print ''; print ''; print ''; print '
'.$langs->trans("Label").'
'.$langs->trans("Account").''; $form->select_comptes($GETPOST["accountid"],"accountid",0,"courant=1",1); // Show list of bank account with courant print '
'.$langs->trans("Account").''; print $langs->trans("NoBankAccountDefined"); print '
'.$langs->trans("Capital").'
'.$langs->trans("DateStart").''; print $form->select_date($datestart?$datestart:-1,'start','','','','add',1,1); print '
'.$langs->trans("DateEnd").''; print $form->select_date($dateend?$dateend:-1,'end','','','','add',1,1); print '
'.$langs->trans("Nbterms").'
'.$langs->trans("Rate").'
'.$langs->trans('Note').''; $doleditor = new DolEditor('note', GETPOST('note', 'alpha'), '', 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, 100); print $doleditor->Create(1); print '
'; print '
'; // Accountancy print ''; if ($conf->accounting->enabled) { print ''; print ''; print ''; print ''; print ''; print ''; } else { print ''; print ''; print ''; print ''; print ''; print ''; } print '
'.$langs->trans("LoanAccountancyCapitalCode").''; print '
'.$langs->trans("LoanAccountancyInsuranceCode").''; print '
'.$langs->trans("LoanAccountancyInterestCode").''; print '
'.$langs->trans("LoanAccountancyCapitalCode").''; print '
'.$langs->trans("LoanAccountancyInsuranceCode").''; print '
'.$langs->trans("LoanAccountancyInterestCode").''; print '
'; print '
    '; print '
'; print '
'; } // View if ($id > 0) { $object = new Loan($db); $result = $object->fetch($id); if ($result > 0) { $head=loan_prepare_head($object); dol_fiche_head($head, 'card', $langs->trans("Loan"),0,'bill'); // Confirm for loan if ($action == 'paid') { $text=$langs->trans('ConfirmPayLoan'); print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans('PayLoan'),$text,"confirm_paid",'','',2); } if ($action == 'delete') { $text=$langs->trans('ConfirmDeleteLoan'); print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteLoan'),$text,'confirm_delete','','',2); } if ($action == 'edit') { print '
id&action=update" method="POST">'; print ''; } print ''; // Ref print '"; // Label if ($action == 'edit') { print ''; } else { print ''; } // Capital print ''; // Date start print ""; print ""; // Date end print ""; print ""; // Nbterms print ''; // Rate print ''; // Status print ''; print '
'.$langs->trans("Ref").''; print $form->showrefnav($object,'id'); print "
'.$langs->trans("Label").''; print ''; print '
'.$langs->trans("Label").''.$object->label.'
'.$langs->trans("Capital").''.price($object->capital,0,$outputlangs,1,-1,-1,$conf->currency).'
".$langs->trans("DateStart").""; if ($action == 'edit') { print $form->select_date($object->datestart, 'start', 0, 0, 0, 'update', 1); } else { print dol_print_date($object->datestart,"day"); } print "
".$langs->trans("DateEnd").""; if ($action == 'edit') { print $form->select_date($object->dateend, 'end', 0, 0, 0, 'update', 1); } else { print dol_print_date($object->dateend,"day"); } print "
'.$langs->trans("Nbterms").''.$object->nbterm.'
'.$langs->trans("Rate").''.$object->rate.'
'.$langs->trans("Status").''.$object->getLibStatut(4, $totalpaye).'
'; if ($action == 'edit') { print '
'; print ''; print '   '; print ''; print '
'; print '
'; } dol_fiche_end(); print ''; print '"; print "
'; /* * Payments */ $sql = "SELECT p.rowid, p.num_payment, datep as dp, p.amount,"; $sql.= "c.libelle as paiement_type"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_loan as p"; $sql.= ", ".MAIN_DB_PREFIX."c_paiement as c "; $sql.= ", ".MAIN_DB_PREFIX."loan as l"; $sql.= " WHERE p.fk_loan = ".$id; $sql.= " AND p.fk_loan = l.rowid"; $sql.= " AND l.entity = ".$conf->entity; $sql.= " AND p.fk_typepayment = c.id"; $sql.= " ORDER BY dp DESC"; //print $sql; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; $total = 0; echo ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; $var=True; while ($i < $num) { $objp = $db->fetch_object($resql); $var=!$var; print "'; print '\n"; print "\n"; print '\n"; print ""; $totalpaid += $objp->amount; $i++; } if ($object->paid == 0) { print "\n"; print "\n"; $staytopay = $object->capital - $totalpaid; print ""; print "\n"; } print "
'.$langs->trans("RefPayment").''.$langs->trans("Date").''.$langs->trans("Type").''.$langs->trans("Amount").' 
"; print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''.dol_print_date($db->jdate($objp->dp),'day')."".$objp->paiement_type.' '.$objp->num_payment."'.price($objp->amount)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AlreadyPaid")." :".price($totalpaid)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("AmountExpected")." :".price($object->capital)." ".$langs->trans("Currency".$conf->currency)."
".$langs->trans("RemainderToPay")." :".price($staytopay)." ".$langs->trans("Currency".$conf->currency)."
"; $db->free($resql); } else { dol_print_error($db); } print "
"; /* * Buttons actions */ if ($action != 'edit') { print "
\n"; // Edit if ($user->rights->loan->write) { print "id&action=edit\">".$langs->trans("Modify").""; } // 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 "id&action=create\">".$langs->trans("DoPayment").""; } // Classify 'paid' if ($object->paid == 0 && round($staytopay) <=0 && $user->rights->loan->write) { print "id&action=paid\">".$langs->trans("ClassifyPaid").""; } // Delete if ($user->rights->loan->delete) { print "id&action=delete\">".$langs->trans("Delete").""; } print "
"; } } else { // Loan not find dol_print_error('',$object->error); } } llxFooter(); $db->close();