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
*/
@ -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
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);
@ -3791,6 +3816,7 @@ else if ($id > 0 || ! empty($ref))
// List of payments already done
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder paymenttable" width="100%">';
@ -3862,7 +3888,15 @@ else if ($id > 0 || ! empty($ref))
print '</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>';
$i ++;
}

View File

@ -42,6 +42,7 @@ $id=GETPOST('id','int');
$ref=GETPOST('ref', 'alpha');
$action=GETPOST('action','alpha');
$confirm=GETPOST('confirm','alpha');
$backtopage=GETPOST('backtopage','alpha');
// Security check
if ($user->societe_id) $socid=$user->societe_id;
@ -82,8 +83,17 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->
if ($result > 0)
{
$db->commit();
header("Location: list.php");
exit;
if ($backtopage)
{
header("Location: ".$backtopage);
exit;
}
else
{
header("Location: list.php");
exit;
}
}
else
{
@ -263,7 +273,7 @@ if (! empty($conf->banque->enabled))
print '</td>';
print '</tr>';
if ($object->type_code == 'CHQ' && $bankline->fk_bordereau > 0)
if ($object->type_code == 'CHQ' && $bankline->fk_bordereau > 0)
{
dol_include_once('/compta/paiement/cheque/class/remisecheque.class.php');
$bordereau = new RemiseCheque($db);
@ -303,14 +313,14 @@ if ($resql)
$i = 0;
$total = 0;
$moreforfilter='';
print '<br>';
print '<div class="div-table-responsive">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans('Bill').'</td>';
print '<td>'.$langs->trans('Company').'</td>';
@ -327,7 +337,7 @@ if ($resql)
while ($i < $num)
{
$objp = $db->fetch_object($resql);
print '<tr class="oddeven">';
$invoice=new Facture($db);
@ -372,11 +382,11 @@ if ($resql)
$i++;
}
}
print "</table>\n";
print '</div>';
$db->free($resql);
}
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.= " WHERE ";
$sql.= " AND p.entity IN (" . getEntity('facture') . ")";
$sql.= " WHERE p.entity IN (" . getEntity('facture') . ")";
if (! $user->rights->societe->client->voir && ! $socid)
{
$sql.= " AND sc.fk_user = " .$user->id;