Skip to content

Commit

Permalink
All order statistics now uses timeFinished instead of timeCreated
Browse files Browse the repository at this point in the history
  • Loading branch information
David Slater committed Sep 1, 2022
1 parent f375a0b commit 682d540
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
3 changes: 2 additions & 1 deletion admin/previousOrders.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@


</table>
Monthly Total: $<?php echo $stats->pretty_cost(); ?>
<br>Monthly Total: $<?php echo $stats->pretty_cost(); ?>
<br>Total Orders: <?php echo $stats->orders(); ?>
<br />
<br />
<form action='reports.php' method='post'>
Expand Down
36 changes: 18 additions & 18 deletions libs/statistics.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function cost() {

$sql = "SELECT SUM(orders_totalCost) AS totalCost ";
$sql .= "FROM tbl_orders LEFT JOIN tbl_status ON tbl_orders.orders_statusId=tbl_status.status_id ";
$sql .= "WHERE DATE(orders_timeCreated) BETWEEN '" . $this->startDate . "' AND '" . $this->endDate . "' ";
$sql .= "WHERE DATE(orders_timeFinished) BETWEEN '" . $this->startDate . "' AND '" . $this->endDate . "' ";
$sql .= "AND status_name='Completed' ";
$sql .= "GROUP BY status_name";
$result = $this->db->query($sql);
Expand All @@ -39,7 +39,7 @@ public function popularPaperTypes() {
$sql = "SELECT paperTypes_id,paperTypes_name,COUNT(*) AS count ";
$sql .= "FROM tbl_orders LEFT JOIN tbl_status ON tbl_orders.orders_statusId=tbl_status.status_id ";
$sql .= "LEFT JOIN tbl_paperTypes ON tbl_orders.orders_paperTypesId=tbl_paperTypes.paperTypes_id ";
$sql .= "WHERE (orders_timeCreated >= '" . $this->startDate . "' AND orders_timeCreated <= '" . $this->endDate . "') ";
$sql .= "WHERE (orders_timeFinished >= '" . $this->startDate . "' AND orders_timeFinished <= '" . $this->endDate . "') ";
$sql .= "AND status_name='Completed' ";
$sql .= "GROUP BY paperTypes_name ORDER BY count DESC";
return $this->db->query($sql);
Expand All @@ -52,7 +52,7 @@ public function paperTypesTotalInches() {
$sql = "SELECT paperTypes_name,SUM(tbl_orders.orders_length) AS totalLength ";
$sql .= "FROM tbl_orders LEFT JOIN tbl_status ON tbl_orders.orders_statusId=tbl_status.status_id ";
$sql .= "LEFT JOIN tbl_paperTypes ON tbl_orders.orders_paperTypesId=tbl_paperTypes.paperTypes_id ";
$sql .= "WHERE (orders_timeCreated >= '" . $this->startDate . "' AND orders_timeCreated <= '" . $this->endDate . "') ";
$sql .= "WHERE (orders_timeFinished >= '" . $this->startDate . "' AND orders_timeFinished <= '" . $this->endDate . "') ";
$sql .= "AND status_name='Completed' ";
$sql .= "GROUP BY paperTypes_name ORDER BY totalLength DESC";
return $this->db->query($sql);
Expand All @@ -64,7 +64,7 @@ public function popularFinishOptions() {
$sql = "SELECT finishOptions_id,finishOptions_name,COUNT(*) AS count ";
$sql .= "FROM tbl_orders LEFT JOIN tbl_status ON tbl_orders.orders_statusId=tbl_status.status_id ";
$sql .= "LEFT JOIN tbl_finishOptions ON tbl_orders.orders_finishOptionsId=tbl_finishOptions.finishOptions_id ";
$sql .= "WHERE (orders_timeCreated >= '" . $this->startDate . "' AND orders_timeCreated <= '" . $this->endDate . "') ";
$sql .= "WHERE (orders_timeFinished >= '" . $this->startDate . "' AND orders_timeFinished <= '" . $this->endDate . "') ";
$sql .= "AND status_name='Completed' ";
$sql .= "GROUP BY finishOptions_name ORDER BY count DESC";
return $this->db->query($sql);
Expand All @@ -77,15 +77,15 @@ public function finishOptionsTotalInches() {
$sql = "SELECT finishOptions_name,SUM(tbl_orders.orders_length) AS totalLength ";
$sql .= "FROM tbl_orders LEFT JOIN tbl_status ON tbl_orders.orders_statusId=tbl_status.status_id ";
$sql .= "LEFT JOIN tbl_finishOptions ON tbl_orders.orders_finishOptionsId=tbl_finishOptions.finishOptions_id ";
$sql .= "WHERE (orders_timeCreated >= '" . $this->startDate . "' AND orders_timeCreated <= '" . $this->endDate . "')";
$sql .= "WHERE (orders_timeFinished >= '" . $this->startDate . "' AND orders_timeFinished <= '" . $this->endDate . "')";
return $this->db->query($sql);

}

public function totalInches() {
$sql = "SELECT SUM(tbl_orders.orders_length) AS total ";
$sql .= "FROM tbl_orders LEFT JOIN tbl_status ON tbl_orders.orders_statusId=tbl_status.status_id ";
$sql .= "WHERE (orders_timeCreated >= '" . $this->startDate . "' AND orders_timeCreated <= '" . $this->endDate . "') ";
$sql .= "WHERE (orders_timeFinished >= '" . $this->startDate . "' AND orders_timeFinished <= '" . $this->endDate . "') ";
$sql .= "AND status_name='Completed'";
$result = $this->db->query($sql);
$total = $result[0]['total'];
Expand All @@ -105,32 +105,32 @@ public function orders() {

$sql = "SELECT COUNT(1) As count ";
$sql .= "FROM tbl_orders LEFT JOIN tbl_status ON tbl_orders.orders_statusId=tbl_status.status_id ";
$sql .= "WHERE DATE(orders_timeCreated) BETWEEN '" . $this->startDate . "' AND '" . $this->endDate . "' ";
$sql .= "WHERE DATE(orders_timeFinished) BETWEEN '" . $this->startDate . "' AND '" . $this->endDate . "' ";
$sql .= "AND status_name='Completed'";
$ordersData = $this->db->query($sql);
$count = $ordersData[0]['count'];
return $count;
}

public function ordersPerMonth($year) {
$sql = "SELECT orders_timeCreated,COUNT(1) AS count ";
$sql = "SELECT orders_timeFinished,COUNT(1) AS count ";
$sql .= "FROM tbl_orders LEFT JOIN tbl_status ON tbl_orders.orders_statusId=tbl_status.status_id ";
$sql .= "LEFT JOIN tbl_rushOrder ON tbl_orders.orders_rushOrderId=tbl_rushOrder.rushOrder_id ";
$sql .= "WHERE YEAR(orders_timeCreated)='" . $year . "' ";
$sql .= "WHERE YEAR(orders_timeFinished)='" . $year . "' ";
$sql .= "AND status_name='Completed' ";
$sql .= "GROUP BY MONTH(orders_timeCreated)";
$sql .= "GROUP BY MONTH(orders_timeFinished)";
$ordersData = $this->db->query($sql);
$newOrdersData;
for($i=1;$i<=12;$i++){
$exists = false;

if (count($ordersData) > 0) {
foreach($ordersData as $row) {
$timeCreated = strtotime($row['orders_timeCreated']);
$month = date('m',$timeCreated);
$timeFinished = strtotime($row['orders_timeFinished']);
$month = date('m',$timeFinished);

if ($month == $i) {
$monthName = date('F',$timeCreated);
$monthName = date('F',$timeFinished);
$newOrdersData[$monthName] = $row['count'];

$exists = true;
Expand All @@ -152,13 +152,13 @@ public function ordersPerMonth($year) {
return $newOrdersData;
}
public function avgOrdersPerMonth() {
$sql = "SELECT MONTH(a.timeCreated) as month, MONTHNAME(a.timeCreated) as month_name, AVG(a.count) as avg FROM ( ";
$sql .= "SELECT orders_timeCreated as timeCreated,COUNT(1) AS count ";
$sql = "SELECT MONTH(a.timeFinished) as month, MONTHNAME(a.timeFinished) as month_name, AVG(a.count) as avg FROM ( ";
$sql .= "SELECT orders_timeFinished as timeFinished,COUNT(1) AS count ";
$sql .= "FROM tbl_orders LEFT JOIN tbl_status ON tbl_orders.orders_statusId=tbl_status.status_id ";
$sql .= "LEFT JOIN tbl_rushOrder ON tbl_orders.orders_rushOrderId=tbl_rushOrder.rushOrder_id ";
$sql .= "WHERE ";
$sql .= "status_name='Completed' ";
$sql .= "GROUP BY MONTH(orders_timeCreated),YEAR(orders_timeCreated)) a ";
$sql .= "GROUP BY MONTH(orders_timeFinished),YEAR(orders_timeFinished)) a ";
$sql .= "GROUP BY month ORDER BY month ASC";
return $this->db->query($sql);
}
Expand All @@ -167,7 +167,7 @@ public function percentRushOrder() {
$sql = "SELECT tbl_rushOrder.rushOrder_name,COUNT(1) AS count ";
$sql .= "FROM tbl_orders LEFT JOIN tbl_status ON tbl_orders.orders_statusId=tbl_status.status_id ";
$sql .= "LEFT JOIN tbl_rushOrder ON tbl_orders.orders_rushOrderId=tbl_rushOrder.rushOrder_id ";
$sql .= "WHERE (orders_timeCreated >= '" . $this->startDate . "' AND orders_timeCreated <= '" . $this->endDate . "') ";
$sql .= "WHERE (orders_timeFinished >= '" . $this->startDate . "' AND orders_timeFinished <= '" . $this->endDate . "') ";
$sql .= "AND status_name='Completed' ";
$sql .= "GROUP BY rushOrder_name";
$result = $this->db->query($sql);
Expand Down Expand Up @@ -198,7 +198,7 @@ public function percentPosterTube() {
$sql = "SELECT tbl_posterTube.posterTube_name,COUNT(1) AS count ";
$sql .= "FROM tbl_orders LEFT JOIN tbl_status ON tbl_orders.orders_statusId=tbl_status.status_id ";
$sql .= "LEFT JOIN tbl_posterTube ON tbl_orders.orders_posterTubeId=tbl_posterTube.posterTube_id ";
$sql .= "WHERE (orders_timeCreated >= '" . $this->startDate . "' AND orders_timeCreated <= '" . $this->endDate . "') ";
$sql .= "WHERE (orders_timeFinished >= '" . $this->startDate . "' AND orders_timeFinished <= '" . $this->endDate . "') ";
$sql .= "AND status_name='Completed' ";
$sql .= "GROUP BY posterTube_name";
$result = $this->db->query($sql);
Expand Down

0 comments on commit 682d540

Please sign in to comment.