Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 40
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Sale
0.00% covered (danger)
0.00%
0 / 40
0.00% covered (danger)
0.00%
0 / 4
132
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 insert
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 1
12
 getType
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
30
 checkDuplicatePointsPerDate
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace BuyerKiosk\FiveStars;
4
5class Sale {
6
7    private $id;
8    private $storeDB;
9    private $store;
10    private $log;
11
12    public $date;
13    public $phone;
14    public $firstName;
15    public $lastName;
16    public $salesAmount;
17    public $buyAmount;
18    public $taxAmount;
19    public $type;
20    public $points;
21    public $transID;
22    public $employee;
23
24    public function __construct(\Store $store, $storeDB = null)
25    {
26        $this->store = $store;
27        if($storeDB == null) {
28            $this->storeDB = dbConnectByName($this->store->getDbName());
29        } else {
30            $this->storeDB = $storeDB;
31        }
32        $this->log = new \KLogger($_ENV['LOG_DIR']."fiveStars.log", \KLogger::DEBUG);
33    }
34
35    public function insert($date) {
36        //Call Check Duplicate Points
37        $this->storeDB->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
38        $this->storeDB->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
39        $this->type = $this->getType($this->transID);
40        try {
41            $stmt = $this->storeDB->prepare("INSERT INTO dailySalesData (transID,date,phoneNum, firstName, lastName, employee,salesAmount,buyAmount,taxAmount,type) VALUES (:transID,:date,:phone,:firstName, :lastName,:employee,:sale,:buy,:tax,:type)");
42            $stmt->bindValue(":phone", $this->phone);
43            $stmt->bindValue(":firstName", $this->firstName);
44            $stmt->bindValue(":lastName", $this->lastName);
45            $stmt->bindValue(":employee", $this->employee);
46            $stmt->bindValue(":sale", floatval($this->salesAmount));
47            $stmt->bindValue(":buy", floatval($this->buyAmount));
48            $stmt->bindValue(":tax", floatval($this->taxAmount));
49            $stmt->bindValue(":transID", $this->transID);
50            $stmt->bindValue(":type", $this->type);
51            $stmt->bindValue(":date", $date->format("Y-m-d"));
52            if($stmt->execute()) {
53                $this->id = $this->storeDB->lastInsertId();
54                return true;
55            } else {
56                $this->log->LogError($this->storeDB->errorInfo());
57            }
58        } catch (\PDOException $e) {
59            $this->log->LogError($e->getMessage());
60        }
61        return false;
62    }
63    private function getType($transID) {
64        switch($transID[0]) {
65            case "S":
66                $type = 0;
67                break;
68            case "B":
69                $type = 1;
70                break;
71            case "R":
72                $type = 2;
73                break;
74            default:
75                $type = 99;
76                break;
77        }
78        return $type;
79    }
80    private function checkDuplicatePointsPerDate() {
81        //check to see if we have a similar points transaction for a particular date
82    }
83}