5 /* Script to delete all supplier payments entered or created from a payment run on a specified day
8 include ('includes/session.inc');
9 $title = _('Reverse and Delete Supplier Payments');
10 include('includes/header.inc');
13 /*Only do deletions if user hits the button */
14 if (isset($_POST['RevPayts']) AND Is_Date($_POST['PaytDate'])==1){
16 $SQLTranDate = FormatDateForSQL($_POST['PaytDate']);
18 $SQL = "SELECT transno,
25 AND trandate = '" . $SQLTranDate . "'";
27 $Result = DB_query($SQL,$db);
28 prnMsg(_('The number of payments that will be deleted is') . ' :' . DB_num_rows($Result),'info');
30 while ($Payment = DB_fetch_array($Result)){
31 prnMsg(_('Deleting payment number') . ' ' . $Payment['transno'] . ' ' . _('to supplier code') . ' ' . $Payment['supplierno'] . ' ' . _('for an amount of') . ' ' . $Payment['ovamount'],'info');
33 $SQL = 'DELETE FROM supptrans
35 AND transno=' . $Payment['transno'] . "
36 AND trandate='" . $SQLTranDate . "'";
38 $DelResult = DB_query($SQL,$db);
39 prnMsg(_('Deleted the SuppTran record'),'success');
42 $SQL = "SELECT transno,
46 WHERE paytno = " . $Payment['transno'] . '
49 $AllocsResult = DB_query($SQL,$db);
50 while ($Alloc = DB_fetch_array($AllocsResult)){
52 $SQL= 'UPDATE supptrans SET settled=0,
53 alloc=alloc-' . $Alloc['amt'] . ',
54 diffonexch = diffonexch - ((' . $Alloc['Amt'] . '/rate ) - ' . $Alloc['amt']/$Payment['rate'] . ')
55 WHERE type=' . $Alloc['typeno'] . '
56 AND transno=' . $Alloc['transno'];
58 $ErrMsg =_('The update to the suppliers charges that were settled by the payment failed because');
59 $UpdResult = DB_query($SQL,$db,$ErrMsg);
63 prnMsg(' ... ' . _('reversed the allocations'),'info');
64 $SQL= 'DELETE FROM suppallocs WHERE paytno=' . $Payment['transno'] . '
66 $DelResult = DB_query($SQL,$db);
67 prnMsg(' ... ' . _('deleted the SuppAllocs records'),'info');
69 $SQL= 'DELETE FROM gltrans WHERE typeno=' . $Payment['transno'] . ' AND type=22';
70 $DelResult = DB_query($SQL,$db);
71 prnMsg(' .... ' . _('the GLTrans records (if any)'),'info');
73 $SQL= "DELETE FROM banktrans
74 WHERE ref='" . $Payment['suppreference'] . ' ' . $Payment['supplierno'] . "'
75 AND amount=" . $Payment['ovamount'] . "
76 AND transdate = '" . $SQLTranDate . "'";
77 $DelResult = DB_query($SQL,$db);
78 prnMsg(' .... ' . _('and the BankTrans record'),'info');
86 echo "<FORM METHOD=POST ACTION='" . $_SERVER['PHP_SELF'] . '?' . SID
. "'>";
87 echo '<BR>' . _('Enter the date of the payment run') . ": <INPUT TYPE=text name='PaytDate' maxlength=11 size=11 value='" . $_POST['PaytDate'] . "'>";
88 echo "<INPUT TYPE=submit name='RevPayts' value='" . _('Reverse Supplier Payments on the Date Entered') . "'>";
91 include('includes/footer.inc');