Beispiel #1
0
 public function new_return(array $return_data)
 {
     $return_id_from_branch = $return_data['id'];
     $branch_id = $return_data['branch_id'];
     $main_id = $return_data['main_id'];
     $settings_repo = new Settings_Repository($this->db);
     $branches_repo = new Branches_Repository($this->db);
     if ($settings_repo->get_settings()->app_id != $main_id) {
         return -2;
         // invalid main
     } else {
         if (!$branches_repo->branch_exists($branch_id)) {
             return -1;
             // invalid branch
         } else {
             if (!$this->return_exists_via_return_id_from_branch($return_id_from_branch, $branch_id)) {
                 $this->db->insert('returns', array('branch_id' => $branch_id, 'return_id_from_branch' => $return_id_from_branch, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')));
                 $return_id = $this->db->insert_id();
                 $items = $return_data['items'];
                 foreach ($items as $item) {
                     $this->db->insert('returned_items', array('return_id' => $return_id, 'item_id' => $item['item_id'], 'quantity' => $item['quantity']));
                 }
                 return $return_id;
             } else {
                 return 0;
                 // return exists
             }
         }
     }
 }
 public function new_sales_report(array $sales_report_data)
 {
     $sales_report_id_from_branch = $sales_report_data['id'];
     $branch_id = $sales_report_data['branch_id'];
     $main_id = $sales_report_data['main_id'];
     $settings_repo = new Settings_Repository($this->db);
     $branches_repo = new Branches_Repository($this->db);
     if ($settings_repo->get_settings()->app_id != $main_id) {
         return -2;
         // invalid main
     } else {
         if (!$branches_repo->branch_exists($branch_id)) {
             return -1;
             // invalid branch
         } else {
             if (!$this->sales_report_exists_via_sales_report_id_from_branch($sales_report_id_from_branch, $branch_id)) {
                 $this->db->insert('sales_reports', array('branch_id' => $branch_id, 'sales_report_id_from_branch' => $sales_report_id_from_branch, '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();
                 $users_repo = new Users_Repository($this->db);
                 foreach ($sales_report_data['sales'] as $sale) {
                     $this->db->insert('receipts', array('receipt_id_from_branch' => $sale['receipt_id'], 'sales_report_id_from_branch' => $sales_report_id_from_branch, 'created_at_from_branch' => $sale['created_at'], 'updated_at_from_branch' => $sale['updated_at'], 'sales_report_id' => $sales_report_id, 'user_id' => $users_repo->get_user_via_username($sale['username'])->id, 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')));
                     $receipt_id = $this->db->insert_id();
                     foreach ($sale['items'] as $item) {
                         $this->db->insert('receipt_items', array('item_id' => $item['item_id'], 'receipt_id' => $receipt_id, 'price' => $item['price'], 'quantity' => $item['quantity']));
                     }
                 }
                 return $sales_report_id;
             } else {
                 return 0;
                 // sales report exists
             }
         }
     }
 }
Beispiel #3
0
 public function branch_exists_post()
 {
     $branches_repo = new Branches_Repository($this->base_model->get_db_instance());
     echo $branches_repo->branch_exists($this->input->post('branchId'));
 }
 public function is_transaction_valid_post()
 {
     $main_id = $this->input->post('mainId');
     $branch_id = $this->input->post('branchId');
     $return_id_from_branch = $this->input->post('returnIdFromBranch');
     $transaction = $this->input->post('transaction');
     $settings_repo = new Settings_Repository($this->base_model->get_db_instance());
     $branches_repo = new Branches_Repository($this->base_model->get_db_instance());
     $returns_repo = new Returns_Repository($this->base_model->get_db_instance());
     if ($transaction != Transaction_Type::Return_Items) {
         echo 1;
     } else {
         if ($settings_repo->get_settings()->app_id != $main_id) {
             echo -2;
         } else {
             if (!$branches_repo->branch_exists($branch_id)) {
                 echo -1;
             } else {
                 if ($returns_repo->return_exists_via_return_id_from_branch($return_id_from_branch, $branch_id)) {
                     echo 0;
                 } else {
                     echo 2;
                 }
             }
         }
     }
     // valid return
 }