Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 52 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| SalesItem | |
0.00% |
0 / 52 |
|
0.00% |
0 / 6 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| create | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
6 | |||
| createFromData | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
2 | |||
| readByStore | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| readByDateRange | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
| readByIndexedField | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\Sales; |
| 4 | |
| 5 | class SalesItem extends Base { |
| 6 | private $store; |
| 7 | private $table = 'sales'; |
| 8 | public $description; |
| 9 | public $code; |
| 10 | public $buyDate; |
| 11 | public $salesDate; |
| 12 | public $quantity; |
| 13 | public $price; |
| 14 | public $cost; |
| 15 | public $deptID; |
| 16 | public $catID; |
| 17 | public $subCatID; |
| 18 | public $sizeID; |
| 19 | public $brandID; |
| 20 | public $typeNum; |
| 21 | |
| 22 | public function __construct($store) { |
| 23 | $this->store = $store; |
| 24 | $this->typeNum = $this->store->getTypeNum(); |
| 25 | parent::__construct(); |
| 26 | } |
| 27 | |
| 28 | public function create() { |
| 29 | $query = 'INSERT INTO ' . $this->table . ' |
| 30 | SET |
| 31 | code = :code, |
| 32 | buyDate = :buyDate, |
| 33 | salesDate = :salesDate, |
| 34 | description = :description, |
| 35 | quantity = :quantity, |
| 36 | price = :price, |
| 37 | cost = :cost, |
| 38 | deptID = :deptID, |
| 39 | catID = :catID, |
| 40 | subCatID = :subCatID, |
| 41 | sizeID = :sizeID, |
| 42 | brandID = :brandID, |
| 43 | typeNum = :typeNum |
| 44 | ON DUPLICATE KEY UPDATE |
| 45 | buyDate = VALUES(buyDate), |
| 46 | salesDate = VALUES(salesDate), |
| 47 | description = VALUES(description), |
| 48 | quantity = VALUES(quantity), |
| 49 | price = VALUES(price), |
| 50 | cost = VALUES(cost), |
| 51 | deptID = VALUES(deptID), |
| 52 | catID = VALUES(catID), |
| 53 | subCatID = VALUES(subCatID), |
| 54 | sizeID = VALUES(sizeID), |
| 55 | brandID = VALUES(brandID), |
| 56 | typeNum = VALUES(typeNum)'; |
| 57 | |
| 58 | $stmt = $this->conn->prepare($query); |
| 59 | |
| 60 | $stmt->bindParam(':code', $this->code); |
| 61 | $stmt->bindParam(':buyDate', $this->buyDate); |
| 62 | $stmt->bindParam(':salesDate', $this->salesDate); |
| 63 | $stmt->bindParam(':description', $this->description); |
| 64 | $stmt->bindParam(':quantity', $this->quantity); |
| 65 | $stmt->bindParam(':price', $this->price); |
| 66 | $stmt->bindParam(':cost', $this->cost); |
| 67 | $stmt->bindParam(':deptID', $this->deptID); |
| 68 | $stmt->bindParam(':catID', $this->catID); |
| 69 | $stmt->bindParam(':subCatID', $this->subCatID); |
| 70 | $stmt->bindParam(':sizeID', $this->sizeID); |
| 71 | $stmt->bindParam(':brandID', $this->brandID); |
| 72 | $stmt->bindParam(':typeNum', $this->typeNum); |
| 73 | |
| 74 | if ($stmt->execute()) { |
| 75 | //error_log("Insert successful. Last inserted ID: " . $this->conn->lastInsertId()); |
| 76 | return true; |
| 77 | } else { |
| 78 | error_log("Insert failed. Error: " . print_r($stmt->errorInfo(), true)); |
| 79 | return false; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | |
| 84 | public function createFromData($data, $salesDate) |
| 85 | { |
| 86 | $this->code = $data->code; |
| 87 | $this->description = $data->Description; |
| 88 | $this->quantity = $data->quantity; |
| 89 | $this->price = $data->price; |
| 90 | $this->cost = $data->cost; |
| 91 | $this->deptID = $data->deptID; |
| 92 | $this->catID = $data->catID; |
| 93 | $this->subCatID = $data->subCatID; |
| 94 | $this->sizeID = $data->sizeID; |
| 95 | $this->brandID = $data->brandID; |
| 96 | $this->buyDate = $data->buyDate; |
| 97 | $this->salesDate = $salesDate; |
| 98 | return $this->create(); |
| 99 | } |
| 100 | |
| 101 | public function readByStore($typeNum) { |
| 102 | $query = 'SELECT * FROM ' . $this->table . ' WHERE typeNum = :typeNum'; |
| 103 | $stmt = $this->conn->prepare($query); |
| 104 | $stmt->bindParam(':typeNum', $typeNum); |
| 105 | $stmt->execute(); |
| 106 | return $stmt; |
| 107 | } |
| 108 | |
| 109 | public function readByDateRange($startDate, $endDate) { |
| 110 | $query = 'SELECT * FROM ' . $this->table . ' WHERE salesDate BETWEEN :startDate AND :endDate'; |
| 111 | $stmt = $this->conn->prepare($query); |
| 112 | $stmt->bindParam(':startDate', $startDate); |
| 113 | $stmt->bindParam(':endDate', $endDate); |
| 114 | $stmt->execute(); |
| 115 | return $stmt; |
| 116 | } |
| 117 | |
| 118 | public function readByIndexedField($field, $value) { |
| 119 | $query = 'SELECT * FROM ' . $this->table . ' WHERE ' . $field . ' = :value'; |
| 120 | $stmt = $this->conn->prepare($query); |
| 121 | $stmt->bindParam(':value', $value); |
| 122 | $stmt->execute(); |
| 123 | return $stmt; |
| 124 | } |
| 125 | } |
| 126 | ?> |