public function get_all_receipts_to_report_post() { $receipts_repo = new Receipts_Repository($this->base_model->get_db_instance()); $data = array(); $receipts = array(); $grand_total = 0; foreach ($receipts_repo->get_all_unreported_receipts() as $receipt) { $total_amount = 0; foreach ($receipts_repo->get_all_items_from_receipt($receipt->id) as $receipt_item) { $total_amount += $receipt_item->price * $receipt_item->quantity; } $grand_total += $total_amount; array_push($receipts, array('id' => $receipt->id, 'total_amount' => $total_amount)); } array_push($data, array('grand_total' => $grand_total, 'receipts' => $receipts)); echo json_encode($data); }
public function new_sales_report() { $receipts_repo = new Receipts_Repository($this->db); $unreported_receipts = $receipts_repo->get_all_unreported_receipts(); if (count($unreported_receipts) >= 1) { $this->db->insert('sales_reports', array('status' => Sales_Report_Status::Failed, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s'))); $sales_report_id = $this->db->insert_id(); $receipts = array(); foreach ($unreported_receipts as $unreported_receipt) { $receipts_repo->update_sales_report_info($unreported_receipt->id, $sales_report_id); } return $sales_report_id; // returns the sales_report_id } else { return 0; // there are no new sales to report } }