forked from timschofield/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZ_ReverseSuppPaymentRun.php
94 lines (70 loc) · 3.19 KB
/
Z_ReverseSuppPaymentRun.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/* Script to delete all supplier payments entered or created from a payment run on a specified day
*/
include ('includes/session.php');
$Title = _('Reverse and Delete Supplier Payments');
$ViewTopic = 'SpecialUtilities';
$BookMark = basename(__FILE__, '.php'); ;
include('includes/header.php');
/*Only do deletions if user hits the button */
if (isset($_POST['RevPayts']) AND Is_Date($_POST['PaytDate'])==1){
$SQLTranDate = FormatDateForSQL($_POST['PaytDate']);
$SQL = "SELECT id,
transno,
supplierno,
ovamount,
suppreference,
rate
FROM supptrans
WHERE supptrans.type = 22
AND trandate = '" . $SQLTranDate . "'";
$Result = DB_query($SQL);
prnMsg(_('The number of payments that will be deleted is') . ' :' . DB_num_rows($Result),'info');
while ($Payment = DB_fetch_array($Result)){
prnMsg(_('Deleting payment number') . ' ' . $Payment['transno'] . ' ' . _('to supplier code') . ' ' . $Payment['supplierno'] . ' ' . _('for an amount of') . ' ' . $Payment['ovamount'],'info');
$SQL = "SELECT supptrans.transno,
supptrans.type,
suppallocs.amt
FROM supptrans INNER JOIN suppallocs
ON supptrans.id=suppallocs.transid_allocto
WHERE suppallocs.transid_allocfrom = " . $Payment['id'];
$AllocsResult = DB_query($SQL);
while ($Alloc = DB_fetch_array($AllocsResult)){
$SQL= "UPDATE supptrans SET settled=0,
alloc=alloc-" . $Alloc['amt'] . ",
diffonexch = diffonexch - ((" . $Alloc['amt'] . "/rate ) - " . $Alloc['amt']/$Payment['rate'] . ")
WHERE supptrans.type='" . $Alloc['type'] . "'
AND transno='" . $Alloc['transno'] . "'";
$ErrMsg =_('The update to the suppliers charges that were settled by the payment failed because');
$UpdResult = DB_query($SQL,$ErrMsg);
}
prnMsg(' ... ' . _('reversed the allocations'),'info');
$SQL= "DELETE FROM suppallocs WHERE transid_allocfrom='" . $Payment['id'] . "'";
$DelResult = DB_query($SQL);
prnMsg(' ... ' . _('deleted the SuppAllocs records'),'info');
$SQL = "DELETE FROM supptrans
WHERE type=22
AND transno='" . $Payment['transno'] . "'
AND trandate='" . $SQLTranDate . "'";
$DelResult = DB_query($SQL);
prnMsg(_('Deleted the SuppTran record'),'success');
$SQL= "DELETE FROM gltrans WHERE typeno='" . $Payment['transno'] . "' AND type=22";
$DelResult = DB_query($SQL);
prnMsg(' .... ' . _('the GLTrans records (if any)'),'info');
$SQL= "DELETE FROM banktrans
WHERE ref='" . $Payment['suppreference'] . ' ' . $Payment['supplierno'] . "'
AND amount=" . $Payment['ovamount'] . "
AND transdate = '" . $SQLTranDate . "'";
$DelResult = DB_query($SQL);
prnMsg(' .... ' . _('and the BankTrans record'),'info');
}
}
echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">';
echo '<div class="centre">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<br />' . _('Enter the date of the payment run') . ': <input type="text" name="PaytDate" maxlength="11" size="11" value="' . $_POST['PaytDate'] . '" />';
echo '<input type="submit" name="RevPayts" value="' . _('Reverse Supplier Payments on the Date Entered') . '" />';
echo '</div>
</form>';
include('includes/footer.php');
?>