-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshelflife_header2.php
266 lines (250 loc) · 8.69 KB
/
shelflife_header2.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<!-- TWO FUNCTIONS: ONE THAT RETURNs THE BEST SHELF LIFE STYLE FOR THAT YEAR AND THE OTHER PER SEASONS FOR THAT YEAR -->
<?php
function routineYearly($year, $store, $division, $orderType, $status, $salesRep, $shelf_date)
{
$connection = new sqlCONNECTION;
$holderArr = array();
$order_noArr = array();
$style_noArr = array();
if ($shelf_date)
{
$q_uery = $connection->newQuery("SELECT style_no, inout_date FROM chastestdb.warehouses_inventory_inout");
while ($row = mysql_fetch_assoc($q_uery))
{
$key = $row["style_no"];
$val = $row["inout_date"];
if(array_key_exists($key, $holderArr))
{
if(calcDays($val, $holderArr[$key] > 0))
{
$holderArr[$key] = $val;
}
}
else
{
$holderArr[$key] = $val;
}
}
}
else
{
$q_uery = $connection->newQuery("SELECT style_no, date_added FROM chastestdb.style");
while ($row = mysql_fetch_assoc($q_uery))
{
$key = $row["style_no"];
$val = $row["date_added"];
if(array_key_exists($key, $holderArr))
{
if(calcDays($val, $holderArr[$key] > 0))
{
$holderArr[$key] = $val;
}
}
else
{
$holderArr[$key] = $val;
}
}
}
$q_uery = $connection->newQuery(stringRunner($store, $division, $orderType, $status, $salesRep));
while ($row = mysql_fetch_assoc($q_uery))
{
$key = (string)$row["order_no"];
$date_t = (string)$row["order_date"];
if ((int)substr($date_t, 0,4) != $year)
{
continue;
}
array_push($order_noArr, $key);
}
if (empty($order_noArr))
{
exit("No results with the given filters.");
}
foreach($order_noArr as $index_order => $orderNo)
{
$order_date = mysql_fetch_assoc($connection->newQuery("SELECT order_no, order_date FROM chastestdb.xorder WHERE order_no = '$orderNo'"))["order_date"];
$i_query = $connection->newQuery("SELECT order_no, style_no, color FROM chastestdb.xorder_tech_pack WHERE order_no = '$orderNo'");
while ($row = mysql_fetch_assoc($i_query))
{
//check for cancellations in colors double space no color then a cancellation has occured?
$keyColor = (string)$row["color"];
if(!strcmp($keyColor,""))
{
continue;
}
$keyStyleNo = (string)$row["style_no"];
if (array_key_exists($keyStyleNo, $holderArr))
{
$_date = $holderArr[$keyStyleNo];
}
else
{
continue;
}
$dayVar = calcDays($_date, $order_date);
if ($dayVar < 0)
{
continue;
}
if (array_key_exists($keyStyleNo, $style_noArr))
{
$style_noArr[$keyStyleNo]['styleCount']++;
$style_noArr[$keyStyleNo]['days'] += $dayVar;
}
else
{
$temp = Array();
$temp['styleCount'] = 1;
$temp['days'] = $dayVar;
$style_noArr[$keyStyleNo] = $temp;
}
}
}
$min = 1000;
foreach($style_noArr as $style => $styleInfo)
{
$style_noArr[$style] = round($style_noArr[$style]['days'] / $style_noArr[$style]['styleCount']);
if ($style_noArr[$style] < $min)
{
$min = $style_noArr[$style];
$minStyle = $style;
}
}
return [$minStyle , $min, $connection->getCategoryInfo($minStyle)];
}
function routineSeasonly($year, $store, $division, $orderType, $status, $salesRep, $shelf_date)
{
$connection = new sqlCONNECTION;
$seasonsArr = new seasons();
$returnArr = [
"winterArr" => array(),
"springArr" => array(),
"summerArr" => array(),
"fallArr" => array()
];
$holderArr = array();
if ($shelf_date)
{
$q_uery = $connection->newQuery("SELECT style_no, inout_date FROM chastestdb.warehouses_inventory_inout");
while ($row = mysql_fetch_assoc($q_uery))
{
$key = $row["style_no"];
$val = $row["inout_date"];
if(array_key_exists($key, $holderArr))
{
if(calcDays($val, $holderArr[$key] > 0))
{
$holderArr[$key] = $val;
}
}
else
{
$holderArr[$key] = $val;
}
}
}
else
{
$q_uery = $connection->newQuery("SELECT style_no, date_added FROM chastestdb.style");
while ($row = mysql_fetch_assoc($q_uery))
{
$key = $row["style_no"];
$val = $row["date_added"];
if(array_key_exists($key, $holderArr))
{
if(calcDays($val, $holderArr[$key] > 0))
{
$holderArr[$key] = $val;
}
}
else
{
$holderArr[$key] = $val;
}
}
}
$q_uery = $connection->newQuery(stringRunner($store, $division, $orderType, $status, $salesRep));
while ($row = mysql_fetch_assoc($q_uery))
{
$key = (string)$row["order_no"];
$date_t = (string)$row["order_date"];
if ((int)substr($date_t, 0,4) != $year)
{
continue;
}
$month_date = (int)substr($date_t,5,2);
$seasonsArr->categorizeOrder($month_date,$key);
}
$boolTester = true;
foreach($seasonsArr->seasonalArraysOrder as $seaArr => $orderArr)
{
if(!empty($seasonsArr->seasonalArraysOrder[$seaArr]))
{
$boolTester = false;
}
}
if ($boolTester)
{
exit("No results with the given filters.");
}
foreach($seasonsArr->seasonalArraysOrder as $seaArr => $orderArr)
{
foreach($orderArr as $index_order => $orderNo)
{
$order_date = mysql_fetch_assoc($connection->newQuery("SELECT order_no, order_date FROM chastestdb.xorder WHERE order_no = '$orderNo'"))["order_date"];
$i_query = $connection->newQuery("SELECT order_no, style_no, color FROM chastestdb.xorder_tech_pack WHERE order_no = '$orderNo'");
while ($row = mysql_fetch_assoc($i_query))
{
$keyColor = (string)$row["color"];
if(!strcmp($keyColor,""))
{
continue;
}
$keyStyleNo = (string)$row["style_no"];
if (array_key_exists($keyStyleNo, $holderArr))
{
$_date = $holderArr[$keyStyleNo];
}
else
{
continue;
}
$dayVar = calcDays($_date, $order_date);
if ($dayVar < 0)
{
continue;
}
if (array_key_exists($keyStyleNo, $seasonsArr->seasonalArraysStyle[$seaArr]))
{
$seasonsArr->seasonalArraysStyle[$seaArr][$keyStyleNo]['styleCount']++;
$seasonsArr->seasonalArraysStyle[$seaArr][$keyStyleNo]['days']+= $dayVar;
}
else
{
$temp = Array();
$temp['styleCount'] = 1;
$temp['days'] = $dayVar;
$seasonsArr->seasonalArraysStyle[$seaArr][$keyStyleNo] = $temp;
}
}
}
}
foreach ($seasonsArr->seasonalArraysStyle as $seaArr => $styleArr)
{
$min = 1000;
foreach($styleArr as $style => $styleInfo)
{
$seasonsArr->seasonalArraysStyle[$seaArr][$style]
= round($seasonsArr->seasonalArraysStyle[$seaArr][$style]['days']/$seasonsArr->seasonalArraysStyle[$seaArr][$style]['styleCount']);
if ($seasonsArr->seasonalArraysStyle[$seaArr][$style] < $min)
{
$min = $seasonsArr->seasonalArraysStyle[$seaArr][$style];
$minStyle = $style;
}
}
$returnArr[$seaArr] = [$minStyle , $min, $connection->getCategoryInfo($minStyle)];
}
return $returnArr;
}
?>