Delete of payment

This commit is contained in:
Laurent Destailleur 2017-12-03 11:59:16 +01:00
parent 9f1eba6b75
commit 11286dee4a
3 changed files with 56 additions and 13 deletions

View File

@ -788,6 +788,24 @@ if (empty($reshook))
} }
} }
// Delete payment
elseif ($action == 'confirm_delete_paiement' && $confirm == 'yes' && $user->rights->facture->creer)
{
$object->fetch($id);
if ($object->statut == Facture::STATUS_VALIDATED && $object->paye == 0)
{
$paiement = new Paiement($db);
$result=$paiement->fetch(GETPOST('paiement_id'));
if ($result > 0) {
$result=$paiement->delete(); // If fetch ok and found
header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
}
if ($result < 0) {
setEventMessages($paiement->error, $paiement->errors, 'errors');
}
}
}
/* /*
* Insert new invoice in database * Insert new invoice in database
*/ */
@ -3148,6 +3166,13 @@ else if ($id > 0 || ! empty($ref))
} }
} }
if ($action == 'deletepaiement')
{
$payment_id = GETPOST('paiement_id');
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&paiement_id='.$payment_id, $langs->trans('DeletePayment'), $langs->trans('ConfirmDeletePayment'), 'confirm_delete_paiement', '', 0, 1);
}
// Confirmation de la suppression d'une ligne produit // Confirmation de la suppression d'une ligne produit
if ($action == 'ask_deleteline') { if ($action == 'ask_deleteline') {
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?facid=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 'no', 1); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?facid=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 'no', 1);
@ -3791,6 +3816,7 @@ else if ($id > 0 || ! empty($ref))
// List of payments already done // List of payments already done
print '<div class="div-table-responsive-no-min">'; print '<div class="div-table-responsive-no-min">';
print '<table class="noborder paymenttable" width="100%">'; print '<table class="noborder paymenttable" width="100%">';
@ -3862,7 +3888,15 @@ else if ($id > 0 || ! empty($ref))
print '</td>'; print '</td>';
} }
print '<td align="right">' . price($sign * $objp->amount) . '</td>'; print '<td align="right">' . price($sign * $objp->amount) . '</td>';
print '<td>&nbsp;</td>'; // TODO Add link to delete payment
print '<td align="center">';
if ($object->statut == Facture::STATUS_VALIDATED && $object->paye == 0 && $user->societe_id == 0)
{
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deletepaiement&paiement_id='.$objp->rowid.'">';
print img_delete();
print '</a>';
}
print '</td>';
print '</tr>'; print '</tr>';
$i ++; $i ++;
} }

View File

@ -42,6 +42,7 @@ $id=GETPOST('id','int');
$ref=GETPOST('ref', 'alpha'); $ref=GETPOST('ref', 'alpha');
$action=GETPOST('action','alpha'); $action=GETPOST('action','alpha');
$confirm=GETPOST('confirm','alpha'); $confirm=GETPOST('confirm','alpha');
$backtopage=GETPOST('backtopage','alpha');
// Security check // Security check
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
@ -82,8 +83,17 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->
if ($result > 0) if ($result > 0)
{ {
$db->commit(); $db->commit();
header("Location: list.php");
exit; if ($backtopage)
{
header("Location: ".$backtopage);
exit;
}
else
{
header("Location: list.php");
exit;
}
} }
else else
{ {

View File

@ -148,8 +148,7 @@ else
{ {
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
} }
$sql.= " WHERE "; $sql.= " WHERE p.entity IN (" . getEntity('facture') . ")";
$sql.= " AND p.entity IN (" . getEntity('facture') . ")";
if (! $user->rights->societe->client->voir && ! $socid) if (! $user->rights->societe->client->voir && ! $socid)
{ {
$sql.= " AND sc.fk_user = " .$user->id; $sql.= " AND sc.fk_user = " .$user->id;