forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZ_DeleteOldPrices.php
49 lines (42 loc) · 1.71 KB
/
Z_DeleteOldPrices.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
<?php
include ('includes/session.php');
$Title = _('UTILITY PAGE To Delete All Old Prices');
include('includes/header.php');
$result=DB_query("UPDATE prices SET enddate='9999-12-31' WHERE enddate='0000-00-00'"); //convert old data to use end date of 9999-12-31 rather than SQL mode specific end date
if (isset($_POST['DeleteOldPrices'])){
DB_Txn_Begin();
$result=DB_query("DELETE FROM prices WHERE enddate<'" . Date('Y-m-d') . "'",'','',true);
$result=DB_query("SELECT stockid,
typeabbrev,
currabrev,
debtorno,
branchcode,
MAX(startdate) as lateststart
FROM prices
WHERE startdate<'" . Date('Y-m-d') . "'
GROUP BY stockid,
typeabbrev,
currabrev,
debtorno,
branchcode");
while ($myrow = DB_fetch_array($result)){
$DelResult = DB_query("DELETE FROM prices WHERE stockid='" . $myrow['stockid'] . "'
AND debtorno='" . $myrow['debtorno'] . "'
AND branchcode='" . $myrow['branchcode'] . "'
AND currabrev='" . $myrow['currabrev'] . "'
AND typeabbrev='" . $myrow['typeabbrev'] . "'
AND enddate='9999-12-31'
AND startdate<'" . $myrow['lateststart'] . "'",'','',true);
}
prnMsg(_('All old prices have been deleted'),'success');
DB_Txn_Commit();
}
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">
<div class="centre">
<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />
<br />
<input type="submit" name="DeleteOldPrices" value="' . _('Purge Old Prices') . '" onclick="return confirm(\'' . _('Are You Sure you wish to delete all old prices?') . '\');" />
</div>
</form>';
include('includes/footer.php');
?>