Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 79
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
PrintLog
0.00% covered (danger)
0.00%
0 / 79
0.00% covered (danger)
0.00%
0 / 5
306
0.00% covered (danger)
0.00%
0 / 1
 gatherPrintLogArray
0.00% covered (danger)
0.00%
0 / 75
0.00% covered (danger)
0.00%
0 / 1
182
 getPrintLogArray
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setPrintLogArray
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setStoreStats
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getStoreStats
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace BuyerKiosk\Core;
4
5class PrintLog extends CompletedBuys
6{
7
8    public $printLogArray = array();
9    public $storeStats = array(
10        'storeProcessAvg' => '',
11        'storeStartDelay' => '',
12        'storePTC' => '',
13        'totalBuys' => ''
14    );
15
16
17    public function gatherPrintLogArray(Store $store, $date = null)
18    {
19        if($date !== null) {
20            $this->gatherCompletedBuys($store, $date);
21        } else {
22            $this->gatherCompletedBuys($store);
23        }
24        $totalBuys = 0;
25        $tempArray = array();
26        if(count($this->completedBuys) > 0) {
27            $completedBuysArray = $this->getCompletedBuys();
28
29
30            $totalProcessTime = 0;
31            $totalStartDelay = 0;
32            $totalContainers = 0;
33            $totalSortTime = 0;
34
35
36            foreach ($completedBuysArray as $buy) {
37
38                $timeEntered = new \DateTime($buy['timestampEntered']);
39                $timeStarted = new \DateTime($buy['timestampStarted']);
40                $timeCompleted = new \DateTime($buy['timestampCompleted']);
41                $sortStarted = new \DateTime($buy['timestampSortStart']);
42                $sortCompleted = new \DateTime($buy['timestampSortCompleted']);
43
44                $diffEnteredStarted = $timeEntered->diff($timeStarted);
45                $diffStartedCompleted = $timeCompleted->diff($timeStarted);
46                $diffSorts = $sortCompleted->diff($sortStarted);
47
48                if ((int)$diffEnteredStarted->format('%h') > 0) {
49                    $startDelay = $diffEnteredStarted->format('%hh %im %Ss');
50                } else if ((int)$diffEnteredStarted->format('%i') > 0) {
51                    $startDelay = $diffEnteredStarted->format('%im %Ss');
52                } else {
53                    $startDelay = $diffEnteredStarted->format('%Ss');
54                }
55
56                if ((int)$diffStartedCompleted->format("%h") > 0) {
57                    $processTime = $diffStartedCompleted->format('%hh %im %Ss');
58                } else if ((int)$diffStartedCompleted->format("%i") > 0) {
59                    $processTime = $diffStartedCompleted->format('%im %Ss');
60                } else {
61                    $processTime = $diffStartedCompleted->format('%Ss');
62                }
63
64                if ((int)$diffSorts->format('%h') > 0) {
65                    $sortTime = $diffSorts->format('%hh %im %Ss');
66                } else if ((int)$diffSorts->format('%i') > 0) {
67                    $sortTime = $diffSorts->format('%im %Ss');
68                } else {
69                    $sortTime = $diffSorts->format('%Ss');
70                }
71                if($buy['timestampSortStart'] !== "0000-00-00 00:00:00" && $buy['containersRemaining'] > 0) {
72                    $numContainers = $buy['containersRemaining'];
73                } else {
74                    $numContainers = $buy['numContainers'];
75                }
76
77
78                $secondsForProcessTime = ((int)$diffStartedCompleted->format('%h') * 60 * 60) + ((int)$diffStartedCompleted->format('%i') * 60) + ((int)$diffStartedCompleted->format('%s'));
79                $secondsForStartDelay = ((int)$diffEnteredStarted->format('%h')*60*60) +((int)$diffEnteredStarted->format('%i')*60) + ((int)$diffEnteredStarted->format('%s'));
80                $secondsForSortTime = ((int)$diffSorts->format('%h')*60*60) + ((int)$diffSorts->format('%i')*60) + ((int)$diffSorts->format('%s'));
81
82                $totalContainers += $numContainers;
83                $totalProcessTime += $secondsForProcessTime;
84                $totalStartDelay += $secondsForStartDelay;
85                $totalSortTime += $secondsForSortTime;
86                $processTimePerContainer = secondsToReadable(floor($secondsForProcessTime / $numContainers));
87
88
89                $tempBuy = array(
90                    'buyID' => $buy['buyID'],
91                    'buyNumber' => $buy['buyNumber'],
92                    'customerFullName' => $buy['customerFullName'],
93                    'containers' => $numContainers,
94                    'timeDroppedOff' => $buy['timeDroppedOff'],
95                    'buyerFullName' => $buy['buyerFullName'],
96                    'sorterFullName' => $buy['sorterFullName'],
97                    'startDelay' => $startDelay,
98                    'processTime' => $processTime,
99                    'sortTime' => $sortTime,
100                    'processTimePerContainer' => $processTimePerContainer,
101                    'wasToday' => $buy['wasToday'],
102                    'wasSorted' => $buy['wasSorted']
103                );
104                $totalBuys++;
105
106                $tempArray[] = $tempBuy;
107        }
108
109
110        }
111        if($totalBuys > 0) {
112            $this->storeStats['storeProcessAvg'] = secondsToReadable(floor($totalProcessTime/$totalBuys));
113            $this->storeStats['storeStartDelay'] = secondsToReadable(floor($totalStartDelay/$totalBuys));
114            $this->storeStats['storePTC'] = secondsToReadable(floor($totalProcessTime/$totalContainers));
115            $this->storeStats['storeSortTime'] = secondsToReadable(floor($totalSortTime/$totalBuys));
116            $this->storeStats['totalBuys'] = $totalBuys;
117        } else {
118            $this->storeStats['storeProcessAvg'] = secondsToReadable(0);
119            $this->storeStats['storeStartDelay'] = secondsToReadable(0);
120            $this->storeStats['storePTC'] =  secondsToReadable(0);
121            $this->storeStats['storeSortTime'] = secondsToReadable(0);
122            $this->storeStats['totalBuys'] = 0;
123        }
124
125        $this->printLogArray = $tempArray;
126    }
127
128
129
130    public function getPrintLogArray()
131    {
132        return $this->printLogArray;
133    }
134
135    public function setPrintLogArray($printLog)
136    {
137        $this->printLogArray = $printLog;
138    }
139
140    /**
141     * @param array $storeStats
142     */
143    public function setStoreStats($storeStats)
144    {
145        $this->storeStats = $storeStats;
146    }
147
148    /**
149     * @return array
150     */
151    public function getStoreStats()
152    {
153        return $this->storeStats;
154    }
155
156}