--- /tmp/dsg/dolibarr/htdocs/loan/payment/github_19.0.3_card.php
+++ /tmp/dsg/dolibarr/htdocs/loan/payment/client_card.php
@@ -24 +23,0 @@
-// Load Dolibarr environment
@@ -28,3 +27 @@
-if (isModEnabled("banque")) {
- require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
-}
+if (!empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
@@ -39,3 +36 @@
-if ($user->socid) {
- $socid = $user->socid;
-}
+if ($user->socid) $socid = $user->socid;
@@ -46 +41,2 @@
-if ($id > 0) {
+if ($id > 0)
+{
@@ -48,3 +44 @@
- if (!$result) {
- dol_print_error($db, 'Failed to get payment id '.$id);
- }
+ if (!$result) dol_print_error($db, 'Failed to get payment id '.$id);
@@ -59 +53,2 @@
-if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('loan', 'delete')) {
+if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->loan->delete)
+{
@@ -62 +57 @@
- $sql = "UPDATE ".MAIN_DB_PREFIX."loan_schedule SET fk_bank = 0 WHERE fk_bank = ".((int) $payment->fk_bank);
+ $sql = "UPDATE ".MAIN_DB_PREFIX."loan_schedule SET fk_bank = 0 WHERE fk_bank = ".$payment->fk_bank;
@@ -65,2 +59,0 @@
- $fk_loan = $payment->fk_loan;
-
@@ -68 +61,2 @@
- if ($result > 0) {
+ if ($result > 0)
+ {
@@ -70 +64 @@
- header("Location: ".DOL_URL_ROOT."/loan/card.php?id=".urlencode($fk_loan));
+ header("Location: ".DOL_URL_ROOT."/loan/list.php");
@@ -72 +66,41 @@
- } else {
+ }
+ else
+ {
+ setEventMessages($payment->error, $payment->errors, 'errors');
+ $db->rollback();
+ }
+}
+
+// Create payment
+if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->loan->write)
+{
+ $db->begin();
+
+ $result = $payment->valide();
+
+ if ($result > 0)
+ {
+ $db->commit();
+
+ $factures = array(); // TODO Get all id of invoices linked to this payment
+ foreach ($factures as $id)
+ {
+ $fac = new Facture($db);
+ $fac->fetch($id);
+
+ $outputlangs = $langs;
+ if (!empty($_REQUEST['lang_id']))
+ {
+ $outputlangs = new Translate("", $conf);
+ $outputlangs->setDefaultLang($_REQUEST['lang_id']);
+ }
+ if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
+ $fac->generateDocument($fac->modelpdf, $outputlangs);
+ }
+ }
+
+ header('Location: card.php?id='.$payment->id);
+ exit;
+ }
+ else
+ {
@@ -95 +129 @@
-print dol_get_fiche_head($head, $hselected, $langs->trans("PaymentLoan"), -1, 'payment');
+dol_fiche_head($head, $hselected, $langs->trans("PaymentLoan"), 0, 'payment');
@@ -100 +134,2 @@
-if ($action == 'delete') {
+if ($action == 'delete')
+{
@@ -104,8 +139,9 @@
-$linkback = '';
-$morehtmlref = '';
-$morehtmlright = '';
-
-dol_banner_tab($payment, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
-
-print '
';
-print '
';
+/*
+ * Confirm validation of the payment
+ */
+if ($action == 'valide')
+{
+ $facid = $_GET['facid'];
+ print $form->formconfirm('card.php?id='.$payment->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide', '', 0, 2);
+}
+
@@ -113,0 +150,6 @@
+
+// Ref
+print '
'.$langs->trans('Ref').' | ';
+print '';
+print $form->showrefnav($payment, 'id', '', 1, 'rowid', 'id');
+print ' |
';
@@ -133,2 +175,4 @@
-if (isModEnabled("banque")) {
- if ($payment->bank_account) {
+if (!empty($conf->banque->enabled))
+{
+ if ($payment->bank_account)
+ {
@@ -149,5 +193,3 @@
-print '
';
-
-
-/*
- * List of loans paid
+
+/*
+ * List of loans payed
@@ -160,2 +202,2 @@
-$sql .= ' AND l.entity = '.((int) $conf->entity);
-$sql .= ' AND pl.rowid = '.((int) $payment->id);
+$sql .= ' AND l.entity = '.$conf->entity;
+$sql .= ' AND pl.rowid = '.$payment->id;
@@ -165 +207,2 @@
-if ($resql) {
+if ($resql)
+{
@@ -179,2 +222,4 @@
- if ($num > 0) {
- while ($i < $num) {
+ if ($num > 0)
+ {
+ while ($i < $num)
+ {
@@ -195 +240 @@
- // Amount paid
+ // Amount payed
@@ -200 +245,2 @@
- if ($objp->paid == 1) { // If at least one invoice is paid, disable delete
+ if ($objp->paid == 1) // If at least one invoice is paid, disable delete
+ {
@@ -211 +257,3 @@
-} else {
+}
+else
+{
@@ -221 +268,0 @@
-
@@ -224,5 +271,22 @@
-if (empty($action) && $user->hasRight('loan', 'delete')) {
- if (!$disable_delete) {
- print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$id.'&action=delete&token='.newToken(), 'delete', 1);
- } else {
- print dolGetButtonAction($langs->trans("CantRemovePaymentWithOneInvoicePaid"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
+/*
+if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
+{
+ if ($user->socid == 0 && $payment->statut == 0 && $_GET['action'] == '')
+ {
+ if ($user->rights->facture->paiement)
+ {
+ print ''.$langs->trans('Valid').'';
+ }
+ }
+}
+*/
+
+if (empty($action) && !empty($user->rights->loan->delete))
+{
+ if (!$disable_delete)
+ {
+ print ''.$langs->trans('Delete').'';
+ }
+ else
+ {
+ print ''.$langs->trans('Delete').'';
--- /tmp/dsg/dolibarr/htdocs/loan/payment/github_19.0.3_payment.php
+++ /tmp/dsg/dolibarr/htdocs/loan/payment/client_payment.php
@@ -4 +3,0 @@
- * Copyright (C) 2020 Maxime DEMAREST
@@ -26 +24,0 @@
-// Load Dolibarr environment
@@ -32 +29,0 @@
-require_once DOL_DOCUMENT_ROOT.'/core/lib/loan.lib.php';
@@ -39 +36,2 @@
-$datepaid = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
+$line_id = GETPOST('line_id', 'int');
+$last = GETPOST('last');
@@ -43 +41,2 @@
-if ($user->socid > 0) {
+if ($user->socid > 0)
+{
@@ -45,5 +43,0 @@
-} elseif (GETPOSTISSET('socid')) {
- $socid = GETPOST('socid', 'int');
-}
-if (!$user->hasRight('loan', 'write')) {
- accessforbidden();
@@ -55,30 +49,28 @@
-$echance = 0;
-$ls = new LoanSchedule($db);
-// grab all loanschedule
-$res = $ls->fetchAll($chid);
-if ($res > 0) {
- foreach ($ls->lines as $l) {
- $echance++; // Count term pos
- // last unpaid term
- if (empty($l->fk_bank)) {
- $line_id = $l->id;
- break;
- } elseif ($line_id == $l->id) {
- // If line_id provided, only count temp pos
- break;
- }
- }
-}
-
-// Set current line with last unpaid line (only if shedule is used)
-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);
- if (empty($datepaid)) {
- $ts_temppaid = $line->datep;
- }
- }
+if ($last)
+{
+ $ls = new LoanSchedule($db);
+ // grab all loanschedule
+ $res = $ls->fetchAll($chid);
+ if ($res > 0)
+ {
+ foreach ($ls->lines as $l)
+ {
+ // get the last unpaid loanschedule
+ if (empty($l->fk_bank))
+ {
+ $line_id = $l->id;
+ break;
+ }
+ }
+ }
+}
+
+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);
+ }
@@ -92 +84,2 @@
-if ($action == 'add_payment') {
+if ($action == 'add_payment')
+{
@@ -95 +88,2 @@
- if ($cancel) {
+ if ($cancel)
+ {
@@ -101 +95,4 @@
- if (!GETPOST('paymenttype', 'int') > 0) {
+ $datepaid = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
+
+ if (!GETPOST('paymenttype', 'int') > 0)
+ {
@@ -105 +102,2 @@
- if ($datepaid == '') {
+ if ($datepaid == '')
+ {
@@ -109 +107,2 @@
- if (isModEnabled("banque") && !GETPOST('accountid', 'int') > 0) {
+ if (!empty($conf->banque->enabled) && !GETPOST('accountid', 'int') > 0)
+ {
@@ -114 +113,2 @@
- if (!$error) {
+ if (!$error)
+ {
@@ -117,23 +117,3 @@
- $pay_amount_capital = (float) price2num(GETPOST('amount_capital'));
- $pay_amount_insurance = (float) price2num(GETPOST('amount_insurance'));
- // User can't set interest him self if schedule is set (else value in schedule can be incoherent)
- if (!empty($line)) {
- $pay_amount_interest = $line->amount_interest;
- } else {
- $pay_amount_interest = (float) price2num(GETPOST('amount_interest'));
- }
- $remaindertopay = (float) price2num(GETPOST('remaindertopay'));
- $amount = (float) price2num($pay_amount_capital + $pay_amount_insurance + $pay_amount_interest, 'MT');
-
- // This term is allready paid
- if (!empty($line) && !empty($line->fk_bank)) {
- setEventMessages($langs->trans('TermPaidAllreadyPaid'), null, 'errors');
- $error++;
- }
-
- if (empty($remaindertopay)) {
- setEventMessages('Empty sumpaid', null, 'errors');
- $error++;
- }
-
- if ($amount == 0) {
+ $amount = GETPOST('amount_capital') + GETPOST('amount_insurance') + GETPOST('amount_interest');
+ if ($amount == 0)
+ {
@@ -144 +124,2 @@
- if (!$error) {
+ if (!$error)
+ {
@@ -149,13 +130,13 @@
- $payment->chid = $chid;
- $payment->datep = $datepaid;
- $payment->label = $loan->label;
- $payment->amount_capital = $pay_amount_capital;
- $payment->amount_insurance = $pay_amount_insurance;
- $payment->amount_interest = $pay_amount_interest;
- $payment->fk_bank = GETPOST('accountid', 'int');
- $payment->paymenttype = GETPOST('paymenttype', 'int');
- $payment->num_payment = GETPOST('num_payment');
- $payment->note_private = GETPOST('note_private', 'restricthtml');
- $payment->note_public = GETPOST('note_public', 'restricthtml');
-
- if (!$error) {
+ $payment->chid = $chid;
+ $payment->datep = $datepaid;
+ $payment->label = $loan->label;
+ $payment->amount_capital = GETPOST('amount_capital');
+ $payment->amount_insurance = GETPOST('amount_insurance');
+ $payment->amount_interest = GETPOST('amount_interest');
+ $payment->paymenttype = GETPOST('paymenttype', 'int');
+ $payment->num_payment = GETPOST('num_payment');
+ $payment->note_private = GETPOST('note_private', 'none');
+ $payment->note_public = GETPOST('note_public', 'none');
+
+ if (!$error)
+ {
@@ -163 +144,2 @@
- if ($paymentid < 0) {
+ if ($paymentid < 0)
+ {
@@ -169,3 +151,5 @@
- if (!$error) {
- $result = $payment->addPaymentToBank($user, $chid, 'payment_loan', '(LoanPayment)', $payment->fk_bank, '', '');
- if (!($result > 0)) {
+ if (!$error)
+ {
+ $result = $payment->addPaymentToBank($user, $chid, 'payment_loan', '(LoanPayment)', GETPOST('accountid', 'int'), '', '');
+ if (!$result > 0)
+ {
@@ -175,25 +159,2 @@
- }
-
- // Update loan schedule with payment value
- if (!$error && !empty($line)) {
- // If payment values are modified, recalculate schedule
- if (($line->amount_capital != $pay_amount_capital) || ($line->amount_insurance != $pay_amount_insurance) || ($line->amount_interest != $pay_amount_interest)) {
- $arr_term = loanCalcMonthlyPayment(($pay_amount_capital + $pay_amount_interest), $remaindertopay, ($loan->rate / 100), $echance, $loan->nbterm);
- foreach ($arr_term as $k => $v) {
- // Update fk_bank for current line
- if ($k == $echance) {
- $ls->lines[$k - 1]->fk_bank = $payment->fk_bank;
- $ls->lines[$k - 1]->fk_payment_loan = $payment->id;
- }
- $ls->lines[$k - 1]->amount_capital = $v['mens'] - $v['interet'];
- $ls->lines[$k - 1]->amount_interest = $v['interet'];
- $ls->lines[$k - 1]->tms = dol_now();
- $ls->lines[$k - 1]->fk_user_modif = $user->id;
- $result = $ls->lines[$k - 1]->update($user, 0);
- if ($result < 1) {
- setEventMessages(null, $ls->errors, 'errors');
- $error++;
- break;
- }
- }
- } else { // Only add fk_bank bank to schedule line (mark as paid)
+ elseif (isset($line))
+ {
@@ -201,6 +162 @@
- $line->fk_payment_loan = $payment->id;
- $result = $line->update($user, 0);
- if ($result < 1) {
- setEventMessages(null, $line->errors, 'errors');
- $error++;
- }
+ $line->update($user);
@@ -210 +166,2 @@
- if (!$error) {
+ if (!$error)
+ {
@@ -215 +172,3 @@
- } else {
+ }
+ else
+ {
@@ -235 +194,2 @@
-if ($action == 'create') {
+if ($action == 'create')
+{
@@ -239,10 +198,0 @@
-
- $sql = "SELECT SUM(amount_capital) as total";
- $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan";
- $sql .= " WHERE fk_loan = ".((int) $chid);
- $resql = $db->query($sql);
- if ($resql) {
- $obj = $db->fetch_object($resql);
- $sumpaid = $obj->total;
- $db->free($resql);
- }
@@ -255 +204,0 @@
- print '';
@@ -258,4 +207,5 @@
- print dol_get_fiche_head();
-
- /*
- print '';
+ dol_fiche_head();
+
+ print '';
+
+ print ''.$langs->trans("Loan").' | ';
@@ -264,4 +213,0 @@
- if ($echance > 0)
- {
- print '
'.$langs->trans("Term").' | '.$echance.' |
'."\n";
- }
@@ -271,0 +218,10 @@
+ $sql = "SELECT SUM(amount_capital) as total";
+ $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan";
+ $sql .= " WHERE fk_loan = ".$chid;
+ $resql = $db->query($sql);
+ if ($resql)
+ {
+ $obj = $db->fetch_object($resql);
+ $sumpaid = $obj->total;
+ $db->free();
+ }
@@ -277,3 +233,7 @@
- */
-
- print '';
+
+ print '
';
+
+ print '';
+ print '';
+ print ''.$langs->trans("Payment").' | ';
+ print '
';
@@ -282,9 +242,2 @@
- if (empty($datepaid)) {
- if (empty($ts_temppaid)) {
- $datepayment = !getDolGlobalString('MAIN_AUTOFILL_DATE') ? -1 : dol_now();
- } else {
- $datepayment = $ts_temppaid;
- }
- } else {
- $datepayment = $datepaid;
- }
+ $datepaid = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
+ $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE) ? (empty($_POST["remonth"]) ?-1 : $datepaye) : 0;
@@ -296,2 +249 @@
- print img_picto('', 'money-bill-alt', 'class="pictofixedwidth"');
- $form->select_types_paiements(GETPOSTISSET("paymenttype") ? GETPOST("paymenttype", 'alphanohtml') : $loan->fk_typepayment, "paymenttype");
+ $form->select_types_paiements(isset($_POST["paymenttype"]) ? $_POST["paymenttype"] : $loan->paymenttype, "paymenttype");
@@ -304,2 +256 @@
- print img_picto('', 'bank_account', 'class="pictofixedwidth"');
- $form->select_comptes(GETPOSTISSET("accountid") ? GETPOST("accountid", 'int') : $loan->accountid, "accountid", 0, 'courant = '.Account::TYPE_CURRENT, 1); // Show opend bank account list
+ $form->select_comptes(isset($_POST["accountid"]) ? $_POST["accountid"] : $loan->accountid, "accountid", 0, '', 1); // Show opend bank account list
@@ -312,2 +263 @@
- print ' | '."\n";
- print "";
+ print ' | '."\n";
@@ -327,2 +277 @@
- print dol_get_fiche_end();
-
+ dol_fiche_end();
@@ -341 +290,2 @@
- if ($loan->datestart > 0) {
+ if ($loan->datestart > 0)
+ {
@@ -343 +293,3 @@
- } else {
+ }
+ else
+ {
@@ -354,3 +306,6 @@
- if ($sumpaid < $loan->capital) {
- print $langs->trans("LoanCapital").': ';
- } else {
+ if ($sumpaid < $loan->capital)
+ {
+ print $langs->trans("LoanCapital").': ';
+ }
+ else
+ {
@@ -360,3 +315,6 @@
- if ($sumpaid < $loan->capital) {
- print $langs->trans("Insurance").': ';
- } else {
+ if ($sumpaid < $loan->capital)
+ {
+ print $langs->trans("Insurance").': ';
+ }
+ else
+ {
@@ -366,3 +324,6 @@
- if ($sumpaid < $loan->capital) {
- print $langs->trans("Interest").': ';
- } else {
+ if ($sumpaid < $loan->capital)
+ {
+ print $langs->trans("Interest").': ';
+ }
+ else
+ {
@@ -377 +338,5 @@
- print $form->buttonsSaveCancel();
+ print '
';
+ print '';
+ print ' ';
+ print '';
+ print '
';