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 } }