Skip to content

Commit

Permalink
FIX Fatal situation if payment removed on expense report. Action
Browse files Browse the repository at this point in the history
set_unpaid was not available.
  • Loading branch information
eldy committed Aug 3, 2019
1 parent 9baf21f commit 7f42380
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
40 changes: 37 additions & 3 deletions htdocs/expensereport/card.php
Expand Up @@ -989,6 +989,34 @@
}
}

if ($action == 'set_unpaid' && $id > 0 && $user->rights->expensereport->to_paid)
{
$object = new ExpenseReport($db);
$object->fetch($id);

$result = $object->set_unpaid($user);

if ($result > 0)
{
// Define output language
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
{
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
if (! empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
$model=$object->modelpdf;
$ret = $object->fetch($id); // Reload to get new records

$object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
}
}

if ($action == 'set_paid' && $id > 0 && $user->rights->expensereport->to_paid)
{
$object = new ExpenseReport($db);
Expand Down Expand Up @@ -2373,8 +2401,8 @@
}


// If status is Appoved
// --------------------
// If status is Approved
// ---------------------

if ($user->rights->expensereport->approve && $object->fk_statut == 5)
{
Expand Down Expand Up @@ -2418,9 +2446,15 @@
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=cancel&id='.$object->id.'">'.$langs->trans('Cancel').'</a></div>';
}

if ($user->rights->expensereport->to_paid && $object->paid && $object->fk_statut == ExpenseReport::STATUS_CLOSED)
{
// Set unpaid
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=set_unpaid&id='.$object->id.'">'.$langs->trans('ClassifyUnPaid').'</a></div>';
}

// Clone
if ($user->rights->expensereport->creer) {
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&amp;action=clone">' . $langs->trans("ToClone") . '</a></div>';
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=clone">' . $langs->trans("ToClone") . '</a></div>';
}

/* If draft, validated, cancel, and user can create, he can always delete its card before it is approved */
Expand Down
4 changes: 2 additions & 2 deletions htdocs/expensereport/class/expensereport.class.php
Expand Up @@ -1381,12 +1381,12 @@ function set_unpaid($fuser, $notrigger = 0)
// phpcs:enable
$error = 0;

if ($this->fk_c_deplacement_statuts != 5)
if ($this->paid)
{
$this->db->begin();

$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
$sql.= " SET fk_statut = 5";
$sql.= " SET paid = 0";
$sql.= ' WHERE rowid = '.$this->id;

dol_syslog(get_class($this)."::set_unpaid sql=".$sql, LOG_DEBUG);
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/en_US/bills.lang
Expand Up @@ -94,6 +94,7 @@ PaymentHigherThanReminderToPay=Payment higher than reminder to pay
HelpPaymentHigherThanReminderToPay=Attention, the payment amount of one or more bills is higher than the outstanding amount to pay. <br> Edit your entry, otherwise confirm and consider creating a credit note for the excess received for each overpaid invoice.
HelpPaymentHigherThanReminderToPaySupplier=Attention, the payment amount of one or more bills is higher than the outstanding amount to pay. <br> Edit your entry, otherwise confirm and consider creating a credit note for the excess paid for each overpaid invoice.
ClassifyPaid=Classify 'Paid'
ClassifyUnPaid=Classify 'Unpaid'
ClassifyPaidPartially=Classify 'Paid partially'
ClassifyCanceled=Classify 'Abandoned'
ClassifyClosed=Classify 'Closed'
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/fr_FR/bills.lang
Expand Up @@ -95,6 +95,7 @@ HelpPaymentHigherThanReminderToPay=Attention, le montant de paiement pour une ou
HelpPaymentHigherThanReminderToPaySupplier=Attention, le montant de paiement pour une ou plusieurs factures est supérieur au reste à payer.<br>Corrigez votre saisie, sinon, confirmez et pensez à créer un avoir pour l'excédent pour chaque facture surpayée.
ClassifyPaid=Classer 'Payée'
ClassifyPaidPartially=Classer 'Payée partiellement'
ClassifyUnPaid=Classer 'Non payée'
ClassifyCanceled=Classer 'Abandonnée'
ClassifyClosed=Classer 'Fermée'
ClassifyUnBilled=Classer 'Non facturée'
Expand Down

0 comments on commit 7f42380

Please sign in to comment.