--- /tmp/dsg/dolibarr/htdocs/expensereport/payment/github_19.0.3_card.php
+++ /tmp/dsg/dolibarr/htdocs/expensereport/payment/client_card.php
@@ -24 +23,0 @@
-// Load Dolibarr environment
@@ -30,3 +29 @@
-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';
@@ -37 +34 @@
-$id = GETPOST('rowid') ? GETPOST('rowid', 'int') : GETPOST('id', 'int');
+$id = GETPOST('rowid') ?GETPOST('rowid', 'int') : GETPOST('id', 'int');
@@ -42,3 +39 @@
-if ($user->socid) {
- $socid = $user->socid;
-}
+if ($user->socid) $socid = $user->socid;
@@ -50 +45,2 @@
-if ($id > 0) {
+if ($id > 0)
+{
@@ -52,3 +48 @@
- if (!$result) {
- dol_print_error($db, 'Failed to get payment id '.$id);
- }
+ if (!$result) dol_print_error($db, 'Failed to get payment id '.$id);
@@ -63 +57,2 @@
-if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('expensereport', 'supprimer')) {
+if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expensereport->supprimer)
+{
@@ -67 +62,22 @@
- if ($result > 0) {
+ if ($result > 0)
+ {
+ $db->commit();
+ header("Location: ".DOL_URL_ROOT."/expensereport/index.php");
+ exit;
+ }
+ else
+ {
+ setEventMessages($object->error, $object->errors, 'errors');
+ $db->rollback();
+ }
+}
+
+// Create payment
+if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->expensereport->creer)
+{
+ $db->begin();
+
+ $result = $object->valide();
+
+ if ($result > 0)
+ {
@@ -69 +85,19 @@
- header("Location: ".DOL_URL_ROOT."/expensereport/index.php");
+
+ $factures = array(); // TODO Get all id of invoices linked to this payment
+ foreach ($factures as $invoiceid)
+ {
+ $fac = new Facture($db);
+ $fac->fetch($invoiceid);
+
+ $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='.$object->id);
@@ -71 +105,3 @@
- } else {
+ }
+ else
+ {
@@ -88 +124 @@
-print dol_get_fiche_head($head, 'payment', $langs->trans("ExpenseReportPayment"), -1, 'payment');
+dol_fiche_head($head, 'payment', $langs->trans("ExpenseReportPayment"), -1, 'payment');
@@ -93 +129,2 @@
-if ($action == 'delete') {
+if ($action == 'delete')
+{
@@ -94,0 +132,9 @@
+}
+
+/*
+ * Confirm validation of the payment
+ */
+if ($action == 'valide')
+{
+ $facid = $_GET['facid'];
+ print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide', '', 0, 2);
@@ -108 +154 @@
-print '
'.$langs->trans('Date').' | '.dol_print_date($object->datep, 'day').' |
';
+print ''.$langs->trans('Date').' | '.dol_print_date($object->datep, 'day').' |
';
@@ -111 +157 @@
-print ''.$langs->trans('PaymentMode').' | '.$langs->trans("PaymentType".$object->type_code).' |
';
+print ''.$langs->trans('PaymentMode').' | '.$langs->trans("PaymentType".$object->type_code).' |
';
@@ -114 +160 @@
-print ''.$langs->trans('Numero').' | '.dol_escape_htmltag($object->num_payment).' |
';
+print ''.$langs->trans('Numero').' | '.$object->num_payment.' |
';
@@ -117 +163 @@
-print ''.$langs->trans('Amount').' | '.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).' |
';
+print ''.$langs->trans('Amount').' | '.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).' |
';
@@ -120 +166 @@
-print ''.$langs->trans('Note').' | '.dol_string_onlythesehtmltags(dol_htmlentitiesbr($object->note_public)).' |
';
+print ''.$langs->trans('Note').' | '.nl2br($object->note_public).' |
';
@@ -124,11 +170,14 @@
-if (isModEnabled("banque")) {
- if ($object->bank_account) {
- $bankline = new AccountLine($db);
- $bankline->fetch($object->bank_line);
- if ($bankline->rappro) {
- $disable_delete = 1;
- $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
- }
-
- print '';
- print ''.$langs->trans('BankTransactionLine').' | ';
+if (!empty($conf->banque->enabled))
+{
+ if ($object->bank_account)
+ {
+ $bankline = new AccountLine($db);
+ $bankline->fetch($object->bank_line);
+ if ($bankline->rappro)
+ {
+ $disable_delete = 1;
+ $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
+ }
+
+ print '
';
+ print ''.$langs->trans('BankTransactionLine').' | ';
@@ -137,5 +186,5 @@
- print '';
- print '
';
-
- print '';
- print ''.$langs->trans('BankAccount').' | ';
+ print '';
+ print '
';
+
+ print '';
+ print ''.$langs->trans('BankAccount').' | ';
@@ -145,4 +194,4 @@
- print $accountstatic->getNomUrl(1);
- print '';
- print '
';
- }
+ print $accountstatic->getNomUrl(1);
+ print '';
+ print '';
+ }
@@ -155 +204 @@
-print dol_get_fiche_end();
+dol_fiche_end();
@@ -166 +215 @@
-$sql .= ' AND per.rowid = '.((int) $id);
+$sql .= ' AND per.rowid = '.$id;
@@ -170 +219,2 @@
-if ($resql) {
+if ($resql)
+{
@@ -188,2 +238,4 @@
- if ($num > 0) {
- while ($i < $num) {
+ if ($num > 0)
+ {
+ while ($i < $num)
+ {
@@ -212 +264 @@
- print ''.$expensereport->getLibStatut(4).' | ';
+ print ''.$expensereport->getLibStatut(4, $objp->amount).' | ';
@@ -216 +268,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
+ {
@@ -230 +283,3 @@
-} else {
+}
+else
+{
@@ -241,7 +296,11 @@
-// Delete
-if ($action == '') {
- if ($user->hasRight('expensereport', 'supprimer')) {
- if (!$disable_delete) {
- print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 1);
- } else {
- print dolGetButtonAction($title_button, $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), 'delete', 0);
+if ($action == '')
+{
+ if ($user->rights->expensereport->supprimer)
+ {
+ if (!$disable_delete)
+ {
+ print ''.$langs->trans('Delete').'';
+ }
+ else
+ {
+ print ''.$langs->trans('Delete').'';
--- /tmp/dsg/dolibarr/htdocs/expensereport/payment/github_19.0.3_info.php
+++ /tmp/dsg/dolibarr/htdocs/expensereport/payment/client_info.php
@@ -27 +26,0 @@
-// Load Dolibarr environment
@@ -38 +37 @@
-$action = GETPOST('action', 'aZ09');
+$action = GETPOST('action', 'alpha');
@@ -55 +54 @@
-$object->fetch($id);
+$object->fetch($id, $ref);
@@ -60 +59 @@
-print dol_get_fiche_head($head, 'info', $langs->trans("ExpenseReportPayment"), -1, 'payment');
+dol_fiche_head($head, 'info', $langs->trans("ExpenseReportPayment"), -1, 'payment');
@@ -79 +78 @@
-print dol_get_fiche_end();
+dol_fiche_end();
--- /tmp/dsg/dolibarr/htdocs/expensereport/payment/github_19.0.3_payment.php
+++ /tmp/dsg/dolibarr/htdocs/expensereport/payment/client_payment.php
@@ -26 +25,0 @@
-// Load Dolibarr environment
@@ -40 +38,0 @@
-$cancel = GETPOST('cancel');
@@ -44 +42,2 @@
-if ($user->socid > 0) {
+if ($user->socid > 0)
+{
@@ -53 +52,2 @@
-if ($action == 'add_payment') {
+if ($action == 'add_payment')
+{
@@ -56 +56,2 @@
- if ($cancel) {
+ if ($_POST["cancel"])
+ {
@@ -64 +65,2 @@
- if (!$result) {
+ if (!$result)
+ {
@@ -69,3 +71,4 @@
- $datepaid = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST("reday", 'int'), GETPOST("reyear", 'int'));
-
- if (!(GETPOST("fk_typepayment", 'int') > 0)) {
+ $datepaid = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
+
+ if (!($_POST["fk_typepayment"] > 0))
+ {
@@ -75 +78,2 @@
- if ($datepaid == '') {
+ if ($datepaid == '')
+ {
@@ -79,7 +83,8 @@
-
- if (isModEnabled("banque") && !($accountid > 0)) {
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToDebit")), null, 'errors');
- $error++;
- }
-
- if (!$error) {
+ if (!empty($conf->banque->enabled) && !($accountid > 0))
+ {
+ setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToDebit")), null, 'errors');
+ $error++;
+ }
+
+ if (!$error)
+ {
@@ -90,6 +95,6 @@
- foreach ($_POST as $key => $value) {
- if (substr($key, 0, 7) == 'amount_') {
- if (GETPOST($key)) {
- $amounts[$expensereport->fk_user_author] = price2num(GETPOST($key));
- $total += price2num(GETPOST($key));
- }
+ foreach ($_POST as $key => $value)
+ {
+ if (substr($key, 0, 7) == 'amount_')
+ {
+ $amounts[$expensereport->fk_user_author] = price2num($_POST[$key]);
+ $total += price2num($_POST[$key]);
@@ -99,55 +104,63 @@
- if (count($amounts) <= 0) {
- $error++;
- setEventMessages('ErrorNoPaymentDefined', null, 'errors');
- }
-
- if (!$error) {
- $db->begin();
-
- // Create a line of payments
- $payment = new PaymentExpenseReport($db);
- $payment->fk_expensereport = $expensereport->id;
- $payment->datep = $datepaid;
- $payment->amounts = $amounts; // Tableau de montant
- $payment->total = $total;
- $payment->fk_typepayment = GETPOST("fk_typepayment", 'int');
- $payment->num_payment = GETPOST("num_payment", 'alphanohtml');
- $payment->note_public = GETPOST("note_public", 'restricthtml');
- $payment->fk_bank = $accountid;
-
- if (!$error) {
- $paymentid = $payment->create($user);
- if ($paymentid < 0) {
- setEventMessages($payment->error, $payment->errors, 'errors');
- $error++;
- }
- }
-
- if (!$error) {
- $result = $payment->addPaymentToBank($user, 'payment_expensereport', '(ExpenseReportPayment)', $accountid, '', '');
- if ($result <= 0) {
- setEventMessages($payment->error, $payment->errors, 'errors');
- $error++;
- }
- }
-
- if (!$error) {
- $payment->fetch($paymentid);
- if ($expensereport->total_ttc - $payment->amount == 0) {
- $result = $expensereport->setPaid($expensereport->id, $user);
- if (!($result > 0)) {
- setEventMessages($payment->error, $payment->errors, 'errors');
- $error++;
- }
- }
- }
-
- if (!$error) {
- $db->commit();
- $loc = DOL_URL_ROOT.'/expensereport/card.php?id='.$id;
- header('Location: '.$loc);
- exit;
- } else {
- $db->rollback();
- }
- }
+ if (count($amounts) <= 0)
+ {
+ $error++;
+ $errmsg = 'ErrorNoPaymentDefined';
+ }
+
+ if (!$error)
+ {
+ $db->begin();
+
+ // Create a line of payments
+ $payment = new PaymentExpenseReport($db);
+ $payment->fk_expensereport = $expensereport->id;
+ $payment->datepaid = $datepaid;
+ $payment->amounts = $amounts; // Tableau de montant
+ $payment->total = $total;
+ $payment->fk_typepayment = GETPOST("fk_typepayment", 'int');
+ $payment->num_payment = GETPOST("num_payment", 'alphanothtml');
+ $payment->note_public = GETPOST("note_public", 'none');
+
+ if (!$error)
+ {
+ $paymentid = $payment->create($user);
+ if ($paymentid < 0)
+ {
+ setEventMessages($payment->error, $payment->errors, 'errors');
+ $error++;
+ }
+ }
+
+ if (!$error)
+ {
+ $result = $payment->addPaymentToBank($user, 'payment_expensereport', '(ExpenseReportPayment)', $accountid, '', '');
+ if (!$result > 0)
+ {
+ setEventMessages($payment->error, $payment->errors, 'errors');
+ $error++;
+ }
+ }
+
+ if (!$error) {
+ $payment->fetch($paymentid);
+ if ($expensereport->total_ttc - $payment->amount == 0) {
+ $result = $expensereport->set_paid($expensereport->id, $user);
+ if (!$result > 0) {
+ setEventMessages($payment->error, $payment->errors, 'errors');
+ $error++;
+ }
+ }
+ }
+
+ if (!$error)
+ {
+ $db->commit();
+ $loc = DOL_URL_ROOT.'/expensereport/card.php?id='.$id;
+ header('Location: '.$loc);
+ exit;
+ }
+ else
+ {
+ $db->rollback();
+ }
+ }
@@ -170 +183,2 @@
-if ($action == 'create' || empty($action)) {
+if ($action == 'create' || empty($action))
+{
@@ -178 +192 @@
- print "\n".'\n";
- }
+ print "\t});\n";
+ print "\n";
+ }
@@ -197,11 +211,11 @@
- print dol_get_fiche_head(null, '0', '', -1);
-
- $linkback = '';
- // $linkback = '' . $langs->trans("BackToList") . '';
-
- dol_banner_tab($expensereport, 'ref', $linkback, 1, 'ref', 'ref', '');
-
- print '';
- print '
';
-
- print '
'."\n";
+ dol_fiche_head(null, '0', '', -1);
+
+ $linkback = '';
+ // $linkback = '' . $langs->trans("BackToList") . '';
+
+ dol_banner_tab($expensereport, 'ref', $linkback, 1, 'ref', 'ref', '');
+
+ print '';
+ print '
';
+
+ print '
'."\n";
@@ -210 +224 @@
- print ''.$langs->trans("Amount").' | '.price($expensereport->total_ttc, 0, $langs, 1, -1, -1, $conf->currency).' |
';
+ print ''.$langs->trans("Amount").' | '.price($expensereport->total_ttc, 0, $outputlangs, 1, -1, -1, $conf->currency).' |
';
@@ -214,2 +228,2 @@
- $sql .= " WHERE p.fk_expensereport = e.rowid AND p.fk_expensereport = ".((int) $id);
- $sql .= ' AND e.entity IN ('.getEntity('expensereport').')';
+ $sql .= " WHERE p.fk_expensereport = e.rowid AND p.fk_expensereport = ".$id;
+ $sql .= ' AND e.entity IN ('.getEntity('expensereport').')';
@@ -217 +231,2 @@
- if ($resql) {
+ if ($resql)
+ {
@@ -220,18 +235,16 @@
- $db->free($resql);
- }
- print ''.$langs->trans("AlreadyPaid").' | '.price($sumpaid, 0, $langs, 1, -1, -1, $conf->currency).' |
';
- print ''.$langs->trans("RemainderToPay").' | '.price($total - $sumpaid, 0, $langs, 1, -1, -1, $conf->currency).' |
';
-
- print '
';
-
- print '
';
-
- print dol_get_fiche_end();
-
- print '
';
-
- print dol_get_fiche_head();
-
- print ''."\n";
-
- print ''.$langs->trans("Date").' | ';
+ $db->free();
+ }
+ print ' |
'.$langs->trans("AlreadyPaid").' | '.price($sumpaid, 0, $outputlangs, 1, -1, -1, $conf->currency).' |
';
+ print ''.$langs->trans("RemainderToPay").' | '.price($total - $sumpaid, 0, $outputlangs, 1, -1, -1, $conf->currency).' |
';
+
+ print '
';
+
+ print '';
+
+ dol_fiche_end();
+
+ dol_fiche_head();
+
+ print ''."\n";
+
+ print ''.$langs->trans("Date").' | ';
@@ -239,2 +252,2 @@
- $datepayment = ($datepaid == '' ? (!getDolGlobalString('MAIN_AUTOFILL_DATE') ? -1 : '') : $datepaid);
- print $form->selectDate($datepayment, '', '', '', 0, "add_payment", 1, 1);
+ $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE) ? (empty($_POST["remonth"]) ?-1 : $datepaid) : 0;
+ print $form->selectDate($datepayment, '', '', '', '', "add_payment", 1, 1);
@@ -249,7 +262,7 @@
- if (isModEnabled("banque")) {
- print ' |
';
- print ''.$langs->trans('AccountToDebit').' | ';
- print '';
- print img_picto('', 'bank_account', 'class="pictofixedwidth"');
- $form->select_comptes(GETPOSTISSET("accountid") ? GETPOST("accountid", "int") : 0, "accountid", 0, '', 2); // Show open bank account list
- print ' |
';
+ if (!empty($conf->banque->enabled))
+ {
+ print '';
+ print ''.$langs->trans('AccountToDebit').' | ';
+ print '';
+ $form->select_comptes(GETPOSTISSET("accountid") ? GETPOST("accountid", "int") : $expensereport->accountid, "accountid", 0, '', 1); // Show open bank account list
+ print ' |
';
@@ -271 +284 @@
- print dol_get_fiche_end();
+ dol_fiche_end();
@@ -288 +301 @@
- $total_ttc = 0;
+ $total = 0;
@@ -291 +304,2 @@
- while ($i < $num) {
+ while ($i < $num)
+ {
@@ -301 +315,2 @@
- if ($sumpaid < $objp->total_ttc) {
+ if ($sumpaid < $objp->total_ttc)
+ {
@@ -304 +319 @@
- if (!empty($conf->use_javascript_ajax)) { // autofill remainder amount
+ if (!empty($conf->use_javascript_ajax)) // autofill remainder amount
@@ -306 +320,0 @@
- }
@@ -309,2 +323,4 @@
- print '';
- } else {
+ print '';
+ }
+ else
+ {
@@ -316,0 +333 @@
+ $total += $objp->total;
@@ -318 +335 @@
- $totalrecu += $sumpaid;
+ $totalrecu += $objp->am;
@@ -321 +338,2 @@
- if ($i > 1) {
+ if ($i > 1)
+ {
@@ -334 +352,5 @@
- print $form->buttonsSaveCancel();
+ print '
';
+ print '';
+ print ' ';
+ print '';
+ print '
';