Browse Source

Add Z report (issue #17)

master
Skylar Ittner 11 months ago
parent
commit
217b7befd2
3 changed files with 85 additions and 7 deletions
  1. 20
    1
      action.php
  2. 1
    0
      lang/en_us.php
  3. 64
    6
      lib/generatereceipt.php

+ 20
- 1
action.php View File

@@ -433,10 +433,29 @@ switch ($VARS['action']) {
433 433
             exit(json_encode(["status" => "ERROR"]));
434 434
         }
435 435
 
436
-        $receipt = GenerateReceipt::getReceipt(GenerateReceipt::RECEIPT_TYPE_X, null, $VARS['register']);
436
+        $receipt = GenerateReceipt::getReceipt(GenerateReceipt::RECEIPT_TYPE_X, $VARS['register']);
437 437
 
438 438
         exit(GenerateReceipt::outputReceipt($receipt, $format, $width, "X Report"));
439 439
         break;
440
+    case "zreport":
441
+        require_once __DIR__ . "/lib/generatereceipt.php";
442
+        $format = "html";
443
+        $width = 64;
444
+        if (isset($VARS['width']) && preg_match("/[0-9]+/", $VARS['width']) && (int) $VARS['width'] > 0) {
445
+            $width = (int) $VARS['width'];
446
+        }
447
+        if (isset($VARS['format'])) {
448
+            $format = $VARS['format'];
449
+        }
450
+        if (!$database->has('cash_drawer', ['AND' => ['open[!]' => null, 'close[!]' => null, 'cashid' => $VARS['cash']]])) {
451
+            header("Content-Type: application/json");
452
+            exit(json_encode(["status" => "ERROR"]));
453
+        }
454
+
455
+        $receipt = GenerateReceipt::getReceipt(GenerateReceipt::RECEIPT_TYPE_Z, $VARS['cash']);
456
+
457
+        exit(GenerateReceipt::outputReceipt($receipt, $format, $width, "Z Report"));
458
+        break;
440 459
     case "session_keepalive":
441 460
         header("Content-Type: application/json");
442 461
         exit(json_encode(["status" => "OK"]));

+ 1
- 0
lang/en_us.php View File

@@ -116,4 +116,5 @@ define("STRINGS", [
116 116
     "manage register" => "Manage register",
117 117
     "manage" => "Manage",
118 118
     "x report" => "X Report",
119
+    "z report" => "Z Report",
119 120
 ]);

+ 64
- 6
lib/generatereceipt.php View File

@@ -12,7 +12,7 @@ class GenerateReceipt {
12 12
 
13 13
     const RECEIPT_TYPE_TRANSACTION = 1;
14 14
     const RECEIPT_TYPE_X = 2;
15
-    const RECEIPT_TYPE_Y = 3;
15
+    const RECEIPT_TYPE_Z = 3;
16 16
 
17 17
     static function transactionReceipt($transaction) {
18 18
         global $database;
@@ -107,6 +107,7 @@ class GenerateReceipt {
107 107
                 'transactions.cashid' => $cash['cashid'],
108 108
             ]
109 109
         ]);
110
+        $transactioncount = $database->count('transactions', ['cashid' => $cash['cashid']]);
110 111
         foreach ($paymenttypes as $t) {
111 112
             $balance[$t['type']] = 0.0;
112 113
         }
@@ -118,6 +119,7 @@ class GenerateReceipt {
118 119
 
119 120
         $receipt->appendLine(new ReceiptLine("Date:", "", date(DATETIME_FORMAT)));
120 121
         $receipt->appendLine(new ReceiptLine("Register:", "", $registername));
122
+        $receipt->appendLine(new ReceiptLine("Transactions:", "", $transactioncount));
121 123
 
122 124
         $receipt->appendBlank();
123 125
         $receipt->appendBreak();
@@ -143,16 +145,72 @@ class GenerateReceipt {
143 145
         return $receipt;
144 146
     }
145 147
 
146
-    static function getReceipt($type, $transaction = null, $register = null, $cashid = null) {
148
+    static function zReceipt($cashid) {
149
+        global $database;
150
+        $receipt = new Receipt();
151
+
152
+        $cash = $database->get('cash_drawer', ['open', 'close', 'start_amount', 'end_amount', 'cashid', 'registerid'], ['cashid' => $cashid]);
153
+        $registername = $database->get('registers', 'registername', ['registerid' => $cash['registerid']]);
154
+
155
+        $balance = [];
156
+        $paymenttypes = $database->select('payment_types', ['typename (type)', 'text']);
157
+        $payments = $database->select("payments", [
158
+            "[>]transactions" => ['txid' => 'txid'],
159
+            "[>]payment_types" => ['type' => 'typeid']
160
+                ], ['amount', 'typename (type)'], [
161
+            'AND' => [
162
+                'transactions.cashid' => $cash['cashid'],
163
+            ]
164
+        ]);
165
+        $transactioncount = $database->count('transactions', ['cashid' => $cashid]);
166
+        foreach ($paymenttypes as $t) {
167
+            $balance[$t['type']] = 0.0;
168
+        }
169
+        foreach ($payments as $p) {
170
+            $balance[$p['type']] += $p['amount'];
171
+        }
172
+
173
+        $receipt->appendHeader(new ReceiptLine(lang("z report", false), "", "", ReceiptLine::LINEFORMAT_BOLD | ReceiptLine::LINEFORMAT_CENTER));
174
+
175
+        $receipt->appendLine(new ReceiptLine("Date:", "", date(DATETIME_FORMAT)));
176
+        $receipt->appendLine(new ReceiptLine("Register:", "", $registername));
177
+        $receipt->appendLine(new ReceiptLine("Transactions:", "", $transactioncount));
178
+
179
+        $receipt->appendBlank();
180
+        $receipt->appendBreak();
181
+        $receipt->appendLine(new ReceiptLine("Opening", "", "", ReceiptLine::LINEFORMAT_CENTER));
182
+        $receipt->appendBreak();
183
+        $receipt->appendLine(new ReceiptLine("Date:", "", date(DATETIME_FORMAT, strtotime($cash['open']))));
184
+        $receipt->appendLine(new ReceiptLine("Cash:", "", '$' . number_format($cash['start_amount'], 2)));
185
+
186
+        $receipt->appendBlank();
187
+        $receipt->appendBreak();
188
+        $receipt->appendLine(new ReceiptLine("Closing", "", "", ReceiptLine::LINEFORMAT_CENTER));
189
+        $receipt->appendBreak();
190
+        $receipt->appendLine(new ReceiptLine("Date:", "", date(DATETIME_FORMAT, strtotime($cash['close']))));
191
+        $receipt->appendLine(new ReceiptLine("Cash:", "", '$' . number_format($cash['end_amount'], 2)));
192
+
193
+        $receipt->appendBlank();
194
+        $receipt->appendBreak();
195
+        $receipt->appendLine(new ReceiptLine("Sales", "", "", ReceiptLine::LINEFORMAT_CENTER));
196
+        $receipt->appendBreak();
197
+        foreach ($paymenttypes as $t) {
198
+            $receipt->appendLine(new ReceiptLine(lang($t['text'], false) . ":", "", '$' . number_format($balance[$t['type']], 2)));
199
+        }
200
+
201
+        return $receipt;
202
+    }
203
+
204
+    static function getReceipt($type, $data) {
147 205
         switch ($type) {
148 206
             case GenerateReceipt::RECEIPT_TYPE_X:
149
-                return GenerateReceipt::xReceipt($register);
207
+                return GenerateReceipt::xReceipt($data);
150 208
                 break;
151
-            case GenerateReceipt::RECEIPT_TYPE_Y:
152
-                return GenerateReceipt::Receipt($register, $cashid);
209
+            case GenerateReceipt::RECEIPT_TYPE_Z:
210
+                return GenerateReceipt::zReceipt($data);
153 211
                 break;
154 212
             case GenerateReceipt::RECEIPT_TYPE_TRANSACTION:
155
-                return GenerateReceipt::transactionReceipt($transaction);
213
+                return GenerateReceipt::transactionReceipt($data);
156 214
                 break;
157 215
             default:
158 216
                 return new Receipt();

Loading…
Cancel
Save