示例#1
0
 /**
  * Add any new void records for the transaction
  * @param $hasrefund
  * @param $hasvoid
  * @param $result
  * @return mixed
  */
 private function insertVoidRecords($hasrefund, $hasvoid, $result)
 {
     $voidMdl = new SaleVoidsModel();
     // update new refund records
     if ($hasrefund) {
         $saleItemsMdl = new SaleItemsModel();
         foreach ($this->refunddata as $refund) {
             // Check if record has already been processed
             if (!$voidMdl->recordExists($this->id, $refund->processdt)) {
                 $this->deviceid = $refund->deviceid;
                 // set device id for the broadcast function
                 $voidMdl->create($this->id, $refund->userid, $refund->deviceid, $refund->locationid, $refund->reason, $refund->method, $refund->amount, json_encode($refund->items), 0, $refund->processdt);
                 // Increment refunded quantities in the sale_items table
                 foreach ($refund->items as $item) {
                     $saleItemsMdl->incrementQtyRefunded($this->id, $item->ref, $item->numreturned);
                 }
                 // Create transaction history record
                 WposTransactions::addTransactionHistory($this->id, isset($_SESSION['userId']) ? $_SESSION['userId'] : 0, "Refunded", "Sale refunded");
                 // log data
                 Logger::write("Refund processed with ref: " . $this->ref, "REFUND", json_encode($refund));
             }
         }
     }
     if ($hasvoid) {
         // Check if record has already been processed
         if (!$voidMdl->recordExists($this->id, $this->voiddata->processdt)) {
             $this->deviceid = $this->voiddata->deviceid;
             // set device id for the broadcast function
             $id = $voidMdl->create($this->id, $this->voiddata->userid, $this->voiddata->deviceid, $this->voiddata->locationid, $this->voiddata->reason, "", 0, 0, 1, $this->voiddata->processdt);
             if (!$id > 0) {
                 $result["error"] .= $voidMdl->errorInfo;
             } else {
                 // return stock to original sale location
                 if (sizeof($this->jsonobj->items) > 0) {
                     $wposStock = new WposAdminStock();
                     foreach ($this->jsonobj->items as $item) {
                         if ($item->sitemid > 0) {
                             $wposStock->incrementStockLevel($item->sitemid, $this->jsonobj->locid, $item->qty, false);
                         }
                     }
                 }
                 // Create transaction history record
                 WposTransactions::addTransactionHistory($this->id, isset($_SESSION['userId']) ? $_SESSION['userId'] : 0, "Voided", "Sale voided");
                 // log data
                 Logger::write("Sale voided with ref: " . $this->ref, "VOID", json_encode($this->voiddata));
             }
         }
     }
     return $result;
 }
示例#2
0
 public function removePayment($result)
 {
     // validate json
     if (!isset($this->data->id) || !isset($this->data->paymentid)) {
         $result['error'] = "Sale & item id must be provided";
         return $result;
     }
     // delete payment record
     $payMdl = new SalePaymentsModel();
     if ($payMdl->removeById($this->data->paymentid) === false) {
         $result['error'] = "Could not remove payment record: " . $payMdl->errorInfo;
         return $result;
     }
     // delete item in json
     foreach ($this->invoice->payments as $key => $item) {
         if ($this->data->paymentid == $item->id) {
             unset($this->invoice->payments[$key]);
             $this->invoice->payments = array_values($this->invoice->payments);
             break;
         }
     }
     // Update invoice totals
     $this->calculateInvoice();
     // update invoice data
     if ($this->saveInvoiceData() === false) {
         $result['error'] = "Could not commit invoice data: " . $this->invMdl->errorInfo;
         return $result;
     } else {
         // Create transaction history record
         WposTransactions::addTransactionHistory($this->id, $_SESSION['userId'], "Modified", "Payment Removed");
         // log data
         Logger::write("Invoice payment removed for invoice id: " . $this->id, "INVOICE", json_encode($this->data));
     }
     $result['data'] = $this->invoice;
     return $result;
 }
 /**
  * Generate invoice for the specified transaction
  * @param $result
  * @return mixed
  */
 public function emailInvoice($result)
 {
     // validate json
     $jsonval = new JsonValidate($this->data, '{"id":1, "to":""}');
     if (($errors = $jsonval->validate()) !== true) {
         $result['error'] = $errors;
         return $result;
     }
     if (!$this->trans) {
         if ($this->loadTransaction() === false) {
             die("Failed to load the transaction!");
         }
     }
     // Generate Invoice PDF
     $html = $this->generateInvoiceHtml();
     $pdf = $this->convertToPdf($html, 0);
     $attachment = [$pdf, "Invoice #" . $this->trans->ref . ".pdf"];
     $subject = isset($this->data->subject) ? $this->data->subject : "Invoice #" . $this->trans->ref . " Attached";
     $message = isset($this->data->message) && $this->data->message !== "" ? $this->data->message : "Please find the attached invoice";
     $cc = isset($this->data->cc) ? $this->data->cc : null;
     $bcc = isset($this->data->bcc) ? $this->data->bcc : null;
     // Constuct & send email
     $email = new WposMail();
     $emlresult = $email->sendHtmlEmail($this->data->to, $subject, $message, $cc, $bcc, $attachment);
     if ($emlresult !== true) {
         $result['error'] = $emlresult;
     } else {
         // Create transaction history record
         WposTransactions::addTransactionHistory($this->trans->id, $_SESSION['userId'], "Emailed", "Invoice emailed to: " . $this->data->to . ($cc != null ? "," . $cc : "") . ($bcc != null ? "," . $bcc : ""));
     }
     return $result;
 }