forked from SecareLupus/fc_pos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopularsale.php
136 lines (120 loc) · 4.41 KB
/
popularsale.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* @file popularsale.php
* @brief popularsale.php is a page which displays two lists, one list of items which
* are out of stock, and have sold in the last 3 months, and one list of items
* which are in stock, but haven't sold in at least 6 months.
*
* This file includes:
* funcs.inc:
* - Used for the config.inc include
*
* @link http://www.worldsapartgames.org/fc/popularsale.php @endlink
*
* @author Michael Whitehouse
* @author Creidieki Crouch
* @author Desmond Duval
* @copyright 2009-2014 Pioneer Valley Gaming Collective
* @version 1.8d
* @since Project has existed since time immemorial.
*/
$title = "Popular Sale Report";
$version = "1.8d";
require_once 'funcs.inc';
require_once 'header.php';
$cxn = open_stream();
// list of items we need to reorder
$sql = "SELECT * FROM items WHERE qty=0 AND (department LIKE 'Board Games' OR department LIKE 'Card Games')";
$result = query($cxn, $sql);
while ($row = mysqli_fetch_assoc($result)) {
extract($row);
$sql = "SELECT t.whensale rawdate,
s.transactionID TID
FROM transactions t
JOIN soldItem s
ON t.ID = s.transactionID
WHERE s.itemID = $ID
AND s.onSale = 0
ORDER BY t.whensale DESC
LIMIT 0,1";
$transactionresult = query($cxn, $sql);
if ($row = mysqli_fetch_assoc($transactionresult)) {
$rawdate = $row['rawdate'];
$TID = $row['TID'];
$saledate = date_create($rawdate);
$nowdate = date_create();
for ($i = 1; $i < 4; $i++) {
$nowdate->modify("-1 month");
if ($saledate >= $nowdate) {
$monthsSinceLastSale[$ID] = $i;
break;
}
}
$itemName[$ID] = $description;
$transaction[$ID] = $TID;
$whendat[$ID] = $rawdate;
}
}
arsort($monthsSinceLastSale);
echo "Board and card games that are out of stock that sold in the last 90 days<p>
<table bgcolor=CCFFCC cellpadding=5 border><tr><td>ID#</td><td>Name</td><td>Months Since Last Sale</td><td>Sale Date</td></tr>\n";
foreach ($monthsSinceLastSale as $key => $value) {
if ($value <= 3) {
echo "<tr><td>$key</td><td><a href='edititem.php?ID=$key'>{$itemName[$key]}</a></td><td>$value</td>
<td><a href='viewreceipts.php?view={$transaction[$key]}' target='otherpage'>{$whendat[$key]}</a></td></tr>\n";
}
}
echo "</table><p>";
// List of items to put on sale
echo "<hr>";
$sql = "SELECT * FROM items WHERE qty>0 "
. "AND (department LIKE 'Board Games' OR department LIKE 'Card Games')";
$result = query($cxn, $sql);
while ($row = mysqli_fetch_assoc($result)) {
extract($row);
$sql = "SELECT t.whensale rawdate,
s.transactionID TID
FROM transactions t
JOIN soldItem s
ON t.ID = s.transactionID
WHERE s.itemID = $ID
ORDER BY t.whensale DESC
LIMIT 0,1";
$transactionresult = query($cxn, $sql);
if ($row = mysqli_fetch_assoc($transactionresult)) {
$rawdate = $row['rawdate'];
$TID = $row['TID'];
$saledate = date_create($rawdate);
$nowdate = date_create();
for ($i = 0; $i < 6; $i++) {
$nowdate->modify("-6 month");
if ($saledate < $nowdate) {
$halves[$ID] = $i;
}
}
$whendat[$ID] = $rawdate;
$transaction[$ID] = $TID;
} else {
$halves[$ID] = 6;
$whendat[$ID] = "Never Sold";
}
if ($halves[$ID] == 0) {
unset($halves[$ID]);
}
$itemName[$ID] = $description;
}
arsort($halves);
echo "Board and card games that may have thick layers of dust on them<p>
<table bgcolor=FFCCCC cellpadding=5 border><tr><td>ID#</td><td>Name</td><td>Half Years<Br>Since Last Sale</td><td>Sale Date</td></tr>\n";
foreach ($halves as $key => $value) {
if ($whendat[$key] == "Never Sold") {
echo "<tr><td>$key</td><td><a href='edititem.php?ID=$key' target='nevsol'>{$itemName[$key]}</a></td><td>$value</td>
<td>Never Sold</td></tr>\n";
} else {
echo "<tr><td>$key</td><td><a href='edititem.php?ID=$key'>{$itemName[$key]}</a></td><td>$value</td>
<td><a href='viewreceipts.php?view={$transaction[$key]}' target='otherpage'>{$whendat[$key]}</a></td></tr>\n";
}
}
echo "</table><p>";
require 'footer.php';
?>