private function get_all_sales_report()
 {
     $sales_reports_repo = new Sales_Reports_Repository($this->base_model->get_db_instance());
     $receipts_repo = new Receipts_Repository($this->base_model->get_db_instance());
     $data = array();
     foreach ($sales_reports_repo->get_all_sales_reports() as $sales_report) {
         $total_amount = 0;
         foreach ($receipts_repo->get_all_receipts_via_sales_report_id($sales_report->id) as $receipt) {
             foreach ($receipts_repo->get_all_items_from_receipt($receipt->id) as $receipt_item) {
                 $total_amount += $receipt_item->price;
             }
         }
         array_push($data, array('id' => $sales_report->id, 'total_amount' => $total_amount, 'created_at' => $sales_report->created_at, 'updated_at' => $sales_report->updated_at));
     }
     echo json_encode($data);
 }
Example #2
0
 public function get_all_sales_reports_from_this_branch_post()
 {
     $sales_reports_repo = new Sales_Reports_Repository($this->base_model->get_db_instance());
     $receipts_repo = new Receipts_Repository($this->base_model->get_db_instance());
     $branch_id = $this->input->post('branchId');
     $data = array();
     foreach ($sales_reports_repo->get_all_sales_reports_from_branch($branch_id) as $sales_report) {
         $total_amount = 0;
         foreach ($receipts_repo->get_all_receipts_via_sales_report_id($sales_report->id) as $receipt) {
             foreach ($receipts_repo->get_all_items_from_receipt($receipt->id) as $receipt_item) {
                 $total_amount += $receipt_item->price * $receipt_item->quantity;
             }
         }
         array_push($data, array('id' => $sales_report->id, 'branch_id' => $sales_report->branch_id, 'sales_report_id_from_branch' => $sales_report->sales_report_id_from_branch, 'total_amount' => $total_amount, 'created_at' => $sales_report->created_at, 'updated_at' => $sales_report->updated_at));
     }
     echo json_encode($data);
 }