--- /tmp/dsg/dolibarr/htdocs/expensereport/payment/github_card.php +++ /tmp/dsg/dolibarr/htdocs/expensereport/payment/client_card.php @@ -61,10 +61,50 @@ $result = $object->delete($user); 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) + { $db->commit(); - 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); exit; - } else { + } + else + { setEventMessages($object->error, $object->errors, 'errors'); $db->rollback(); } @@ -81,7 +121,7 @@ $head = payment_expensereport_prepare_head($object); -print dol_get_fiche_head($head, 'payment', $langs->trans("ExpenseReportPayment"), -1, 'payment'); +dol_fiche_head($head, 'payment', $langs->trans("ExpenseReportPayment"), -1, 'payment'); /* * Confirm deleting of the payment @@ -89,6 +129,15 @@ if ($action == 'delete') { print $form->formconfirm('card.php?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete', '', 0, 2); +} + +/* + * 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); } $linkback = ''; @@ -120,39 +169,39 @@ // Bank account 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').''; + 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').''; print ''; print $bankline->getNomUrl(1, 0, 'showconciliated'); - print ''; - print ''; - - print ''; - print ''.$langs->trans('BankAccount').''; + print ''; + print ''; + + print ''; + print ''.$langs->trans('BankAccount').''; print ''; $accountstatic = new Account($db); $accountstatic->fetch($bankline->fk_account); - print $accountstatic->getNomUrl(1); - print ''; - print ''; - } + print $accountstatic->getNomUrl(1); + print ''; + print ''; + } } print ''; print ''; -print dol_get_fiche_end(); +dol_fiche_end(); /* @@ -231,7 +280,9 @@ print ''; $db->free($resql); -} else { +} +else +{ dol_print_error($db); } @@ -248,8 +299,10 @@ { if (!$disable_delete) { - print ''.$langs->trans('Delete').''; - } else { + print ''.$langs->trans('Delete').''; + } + else + { print ''.$langs->trans('Delete').''; } } --- /tmp/dsg/dolibarr/htdocs/expensereport/payment/github_info.php +++ /tmp/dsg/dolibarr/htdocs/expensereport/payment/client_info.php @@ -34,7 +34,7 @@ $id = GETPOST('id'); $ref = GETPOST('ref', 'alpha'); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'alpha'); $confirm = GETPOST('confirm', 'alpha'); /* @@ -56,7 +56,7 @@ $head = payment_expensereport_prepare_head($object); -print dol_get_fiche_head($head, 'info', $langs->trans("ExpenseReportPayment"), -1, 'payment'); +dol_fiche_head($head, 'info', $langs->trans("ExpenseReportPayment"), -1, 'payment'); //$linkback = '' . $langs->trans("BackToList") . ''; @@ -75,7 +75,7 @@ print ''; -print dol_get_fiche_end(); +dol_fiche_end(); // End of page llxFooter(); --- /tmp/dsg/dolibarr/htdocs/expensereport/payment/github_payment.php +++ /tmp/dsg/dolibarr/htdocs/expensereport/payment/client_payment.php @@ -80,11 +80,11 @@ setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors'); $error++; } - if (!empty($conf->banque->enabled) && !($accountid > 0)) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToDebit")), null, 'errors'); - $error++; - } + if (!empty($conf->banque->enabled) && !($accountid > 0)) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToDebit")), null, 'errors'); + $error++; + } if (!$error) { @@ -101,67 +101,69 @@ } } - 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", 'restricthtml'); - - 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(); - } - } + 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(); + } + } } $action = 'create'; @@ -194,9 +196,9 @@ var amount = $(this).data("value"); document.getElementById($(this).data(\'rowid\')).value = amount ; });'; - print "\t});\n"; - print "\n"; - } + print "\t});\n"; + print "\n"; + } print load_fiche_titre($langs->trans("DoPayment")); @@ -206,17 +208,17 @@ print ''; print ''; - 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"; print ''; print ''; @@ -224,7 +226,7 @@ $sql = "SELECT sum(p.amount) as total"; $sql .= " FROM ".MAIN_DB_PREFIX."payment_expensereport as p, ".MAIN_DB_PREFIX."expensereport as e"; $sql .= " WHERE p.fk_expensereport = e.rowid AND p.fk_expensereport = ".$id; - $sql .= ' AND e.entity IN ('.getEntity('expensereport').')'; + $sql .= ' AND e.entity IN ('.getEntity('expensereport').')'; $resql = $db->query($sql); if ($resql) { @@ -235,20 +237,20 @@ print ''; print ''; - print '
'.$langs->trans("Period").''.get_date_range($expensereport->date_debut, $expensereport->date_fin, "", $langs, 0).'
'.$langs->trans("Amount").''.price($expensereport->total_ttc, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans("AlreadyPaid").''.price($sumpaid, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'.$langs->trans("RemainderToPay").''.price($total - $sumpaid, 0, $outputlangs, 1, -1, -1, $conf->currency).'
'; - - print '
'; - - print dol_get_fiche_end(); - - print dol_get_fiche_head(); - - print ''."\n"; - - print '
'.$langs->trans("Date").''; + print '
'; + + print ''; + + dol_fiche_end(); + + dol_fiche_head(); + + print ''."\n"; + + print '"; print ''; @@ -259,11 +261,11 @@ if (!empty($conf->banque->enabled)) { - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; } // Number @@ -279,7 +281,7 @@ print '
'.$langs->trans("Date").''; $datepaid = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST("reday", 'int'), GETPOST("reyear", 'int')); - $datepayment = ($datepaid == '' ? (empty($conf->global->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); print "
'.$langs->trans('AccountToDebit').''; - $form->select_comptes(GETPOSTISSET("accountid") ? GETPOST("accountid", "int") : $expensereport->accountid, "accountid", 0, '', 2); // Show open bank account list - print '
'.$langs->trans('AccountToDebit').''; + $form->select_comptes(GETPOSTISSET("accountid") ? GETPOST("accountid", "int") : $expensereport->accountid, "accountid", 0, '', 1); // Show open bank account list + print '
'; - print dol_get_fiche_end(); + dol_fiche_end(); print '
'; @@ -319,7 +321,9 @@ $remaintopay = $objp->total_ttc - $sumpaid; // autofill remainder amount print ''; // autofill remainder amount print ''; - } else { + } + else + { print '-'; } print ""; @@ -346,9 +350,9 @@ print ""; print '
'; - print ''; + print ''; print '     '; - print ''; + print ''; print '
'; print "\n";