public function addPayment($result) { // validate json $jsonval = new JsonValidate($this->data, '{"id":1, "method":"", "amount":1, "processdt":1}'); if (($errors = $jsonval->validate()) !== true) { $result['error'] = $errors; return $result; } // insert payment record $payMdl = new SalePaymentsModel(); if (($payid = $payMdl->create($this->data->id, $this->data->method, $this->data->amount, $this->data->processdt)) === false) { $result['error'] = "Could not insert payment record: " . $payMdl->errorInfo; return $result; } // set payment in json, add payid to data object $this->data->id = $payid; $this->invoice->payments[] = $this->data; // 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 Added"); // log data Logger::write("Invoice payment added for invoice id: " . $this->id, "INVOICE", json_encode($this->data)); } $result['data'] = $this->invoice; return $result; }
/** * Insert transaction payment records * @return bool */ private function insertTransactionPayments() { $payMdl = new SalePaymentsModel(); foreach ($this->jsonobj->payments as $key => $payment) { if (!($id = $payMdl->create($this->id, $payment->method, $payment->amount, $this->jsonobj->processdt))) { $this->paymentErr = $payMdl->errorInfo; return false; } $this->jsonobj->payments[$key]->id = $id; $this->jsonobj->payments[$key]->processdt = $this->jsonobj->processdt; } return true; }