Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
CashBalancer
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 5
132
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 balance
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 calculateTotalCashIn
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
20
 calculateTotalCashOut
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
20
 calculateVariance
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace BuyerKiosk\Cash;
4
5use BuyerKiosk\DailyReport\SalesReport;
6
7class CashBalancer {
8
9    private $cashActivityArray;
10    private $salesReport;
11    /**
12     * Validates daily cash activity against sales report
13     * Compares register transactions with sales report totals
14     * for cashPaidIn and cashPaidOut values
15     *
16     * @param array $cashActivityArray Daily cash transactions
17     * @param SalesReport $salesReport Daily sales report
18     */
19    public function __construct( $cashActivityArray, SalesReport $salesReport) {
20       $this->cashActivityArray = $cashActivityArray;
21       $this->salesReport = $salesReport;
22
23    }
24
25
26    public function balance() {
27        return $this->calculateVariance();
28    }
29
30    private function calculateTotalCashIn() {
31        $total = 0;
32        foreach ($this->cashActivityArray as $activity) {
33            if ($activity['transType'] === 'PaidIn' || $activity['transType'] === 'S2R') {
34                $total += $activity['total'];
35            }
36        }
37        return $total;
38    }
39
40    private function calculateTotalCashOut() {
41        $total = 0;
42        foreach ($this->cashActivityArray as $activity) {
43            if ($activity['transType'] === 'PaidOut' || $activity['transType'] === 'R2S') {
44                $total += $activity['total'];
45            }
46        }
47        return $total;
48    }
49
50
51    public function calculateVariance() {
52        $reportedCashIn = $this->salesReport->cashPaidIn;
53        $reportedCashOut = $this->salesReport->cashPaidOut;
54
55        $calculatedCashIn = $this->calculateTotalCashIn();
56        $calculatedCashOut = $this->calculateTotalCashOut();
57
58        $varianceCashIn = $calculatedCashIn - $reportedCashIn;
59        $varianceCashOut = $calculatedCashOut - $reportedCashOut;
60
61        return [
62            'cashIn' => $varianceCashIn,
63            'cashOut' => $varianceCashOut,
64            'reportedCashIn' => $reportedCashIn,
65            'reportedCashOut' => $reportedCashOut,
66            'calculatedCashIn' => $calculatedCashIn,
67            'calculatedCashOut' => $calculatedCashOut
68        ];
69    }
70
71}