private function deleteInvoice() { if ($this->invMdl->remove($this->id) === false) { return false; } $itemMdl = new SaleItemsModel(); if ($itemMdl->removeBySale($this->id) === false) { return false; } $payMdl = new SalePaymentsModel(); if ($payMdl->removeBySale($this->id) === false) { return false; } $voidMdl = new SaleVoidsModel(); if ($voidMdl->removeBySale($this->id) === false) { return false; } $histMdl = new TransHistModel(); if ($histMdl->removeBySale($this->id) === false) { return false; } return true; }
/** * Remove all transaction records associated with a sale * @return bool */ private function removeTransactionRecords() { $itemsMdl = new SaleItemsModel(); $payMdl = new SalePaymentsModel(); if ($this->salesMdl->remove($this->id) !== false) { if ($payMdl->removeBySale($this->id) !== false) { if ($itemsMdl->removeBySale($this->id) !== false) { return true; } } } return false; }
/** * Get payment method totals from the current range * @param $result * @return mixed */ public function getCountTakingsStats($result) { $stats = []; $payMdl = new SalePaymentsModel(); $voidMdl = new SaleVoidsModel(); // check if params set, if not set defaults $stime = isset($this->data->stime) ? $this->data->stime : strtotime('-1 week') * 1000; $etime = isset($this->data->etime) ? $this->data->etime : time() * 1000; // get sales total for each method: actually is payment num total! There may be > one payment per sale if (is_array($payments = $payMdl->getTotals($stime, $etime, 3, false, true, $this->data->type))) { foreach ($payments as $payment) { $stats[$payment['method']] = new stdClass(); $stats[$payment['method']]->refs = $payment['refs']; $stats[$payment['method']]->saletotal = $payment['stotal']; $stats[$payment['method']]->salenum = $payment['snum']; $stats[$payment['method']]->refundrefs = ''; $stats[$payment['method']]->refundtotal = 0; // set defaults $stats[$payment['method']]->refundnum = 0; } // get refunded totals for each method if (is_array($refunds = $voidMdl->getTotals($stime, $etime, false, true, $this->data->type))) { foreach ($refunds as $refund) { if (!isset($stats[$refund['method']])) { $stats[$refund['method']] = new stdClass(); } $stats[$refund['method']]->refundrefs = $refund['refs']; $stats[$refund['method']]->refundtotal = $refund['stotal']; $stats[$refund['method']]->refundnum = $refund['snum']; if (!isset($stats[$refund['method']]->salenum)) { $stats[$refund['method']]->saletotal = 0; // set fields with default vals if none set $stats[$refund['method']]->salenum = 0; $stats[$refund['method']]->refs = ''; } } } else { $result['error'] = $voidMdl->errorInfo; } } else { $result['error'] = $payMdl->errorInfo; } // calculate unaccounted totals (unpaid; for accural accounting purposes) $transMdl = new TransactionsModel(); $totals = $transMdl->getUnaccountedTotals($stime, $etime, false, $this->data->type)[0]; if ($totals['stotal'] != 0) { $stats['Unaccounted'] = new stdClass(); $stats['Unaccounted']->refs = $totals['refs']; $stats['Unaccounted']->saletotal = $totals['stotal']; $stats['Unaccounted']->salenum = $totals['snum']; $stats['Unaccounted']->refundrefs = ''; $stats['Unaccounted']->refundtotal = 0; $stats['Unaccounted']->refundnum = 0; } // calcuate balances foreach ($stats as $key => $stat) { $stats[$key]->balance = round($stats[$key]->saletotal - $stats[$key]->refundtotal, 2); } // include totals if requested if ($this->data->totals == true) { $stats["Totals"] = $this->getOverviewStats($result)['data']; } $result['data'] = $stats; return $result; }
/** * Remove all records associated with a transaction * @return bool */ private function deleteTransactionRecords() { $transMdl = new TransactionsModel(); if ($transMdl->remove($this->data->id) === false) { return false; } $itemMdl = new SaleItemsModel(); if ($itemMdl->removeBySale($this->data->id) === false) { return false; } $payMdl = new SalePaymentsModel(); if ($payMdl->removeBySale($this->data->id) === false) { return false; } $voidMdl = new SaleVoidsModel(); if ($voidMdl->removeBySale($this->data->id) === false) { return false; } $histMdl = new TransHistModel(); if ($histMdl->removeBySale($this->data->id) === false) { return false; } return true; }
/** * Removes the transaction record and all associated records * @param $saleid * @return bool|int Returns false on failure or number of rows affected on success */ public function remove($saleid) { $sql = "DELETE FROM `sales` WHERE `id` = :saleid"; $placeholders = [":saleid" => $saleid]; // Remove associated records $saleItemsMdl = new SaleItemsModel(); $salePaymentsMdl = new SalePaymentsModel(); $saleVoidMdl = new SaleVoidsModel(); if (($result = $saleVoidMdl->removeBySale($saleid)) !== false) { if (($result = $salePaymentsMdl->removeBySale($saleid)) !== false) { $result = $saleItemsMdl->removeBySale($saleid); } } if ($result !== false) { return $this->delete($sql, $placeholders); } else { return $result; } }