public function add_more_stock_level_store_external() { //seth // echo "<pre>";print_r($this->input->post());echo "</pre>"; //random change for pushmentation if ($this->input->post('facility_stock_id')) { $district_id = $this->session->userdata('district_id'); $commodity_id = array_values($this->input->post('commodity_id')); $id = array_values($this->input->post('id')); $expiry_date = array_values($this->input->post('clone_datepicker')); $batch_no = array_values($this->input->post('commodity_batch_no')); $manu = array_values($this->input->post('commodity_manufacture')); $total_unit_count = array_values($this->input->post('actual_quantity')); $service_point = array_values($this->input->post('service_point')); $source_of_item = array_values($this->input->post('source_of_item')); $actual_quantity = array_values($this->input->post('actual_quantity')); $date_issued = array_values($this->input->post('clone_datepicker')); // $count=count($commodity_id); $count = count(array_filter($actual_quantity)); $date_of_entry = date('y-m-d H:i:s'); $new_drug_store_entry = array(); //collect n set the data in the array // print_r(array_filter($actual_quantity));exit; for ($i = 0; $i < $count; $i++) { if ($total_unit_count[$i] > 0) { //check if the balance is more than 0 ie they recieved something // echo "RUNNING";exit; // if($this -> session -> userdata('user_indicator')=='district'): //check if the user is district if so the facility which was given the item is not using HCMP // else: // echo "ELSE RUNNING";exit; // TOTALs UPDATING $existence = drug_store_issues::check_drug_existence($commodity_id[$i], $district_id); echo "<pre>"; print_r($existence[0]['present']); echo "</pre>"; if ($existence[0]['present'] > 0) { echo $commodity_id[$i]; // echo "Update RUNNING"; $update_totals = Doctrine_Manager::getInstance()->getCurrentConnection(); $update_totals->execute("UPDATE `drug_store_totals` SET `total_balance` = `total_balance`+{$total_unit_count[$i]}\n WHERE `commodity_id`= '{$commodity_id[$i]}' and `district_id`={$district_id}"); // echo "UPDATE `drug_store_totals` SET `total_balance` = `total_balance`+$total_unit_count[$i] // WHERE `commodity_id`= '$commodity_id[$i]' and district_id=$district_id"; // echo $update_totals;exit; } else { // echo "Entry RUNNING"; $new_entry_details = array('district_id' => $district_id, 'commodity_id' => $commodity_id[$i], 'total_balance' => $total_unit_count[$i], 'expiry_date' => date('y-m-d', strtotime(str_replace(",", " ", $expiry_date[$i]))), 'status' => 1); array_push($new_drug_store_entry, $new_entry_details); $data = $this->db->insert_batch('drug_store_totals', $new_drug_store_entry); //echo $data;exit; } //end of existence update/entry if // echo $clone_datepicker[$i];exit; $new_store_issue_entry = array(); $mydata = array('facility_code' => $service_point[$i], 'district_id' => $district_id[$i], 'commodity_id' => $commodity_id[$i], 's11_No' => '(+ve Adj) Stock Addition', 'batch_no' => $batch_no[$i], 'expiry_date' => date('y-m-d', strtotime(str_replace(",", " ", $expiry_date[$i]))), 'balance_as_of' => $total_unit_count[$i], 'adjustmentpve' => 0, 'adjustmentnve' => 0, 'qty_issued' => $total_unit_count[$i], 'date_issued' => $date_issued[$i], 'created_at' => NULL, 'issued_by' => $this->session->userdata('user_id'), 'status' => 1); array_push($new_store_issue_entry, $mydata); $sth = $this->db->insert_batch('drug_store_issues', $new_store_issue_entry); $update_redistribution = Doctrine_Manager::getInstance()->getCurrentConnection(); $update_redistribution->execute("UPDATE `redistribution_data` SET `status` = 1\n WHERE `id`= '{$id[$i]}' and `source_district_id`={$district_id}"); // echo $sth;exit; // //get the closing stock of the given item // $district_stock=drug_store_issues::get_store_commodity_total($district_id,$commodity_id[$i]); // //update the facility stock table // $sth = drug_store_issues::update_drug_store_issues_table($mydata); // echo $sth;exit; // save this infor in the issues table } } // echo "<pre>Successful";print_r($mydata);echo "</pre>";exit; //set the notifications //$this->hcmp_functions->send_stock_update_sms(); $this->session->set_flashdata('system_success_message', "Stock Levels Have Been Updated"); redirect('issues/store_home'); } }
public function district_store_drug_recieval() { //security check if ($this->input->post('mfl')) { $facility_code = $this->session->userdata('facility_id'); $district_id = $this->session->userdata('district_id'); $service_point = array_values($this->input->post('mfl')); $commodity_id = array_values($this->input->post('desc')); $commodity_balance_before = array_values($this->input->post('commodity_balance')); $facility_stock_id = array_values($this->input->post('facility_stock_id')); $batch_no = array_values($this->input->post('batch_no')); $expiry_date = array_values($this->input->post('expiry_date')); $commodity_unit_of_issue = array_values($this->input->post('commodity_unit_of_issue')); $quantity_issued = array_values($this->input->post('quantity_issued')); $clone_datepicker_normal_limit_today = array_values($this->input->post('clone_datepicker_normal_limit_today')); $manufacture = array_values($this->input->post('manufacture')); $total_units = array_values($this->input->post('total_units')); $total_items = count($facility_stock_id); //var_dump($total_units);exit; $data_array_issues_table = array(); $data_array_redistribution_table = array(); $new_drug_store_entry = array(); $digested_expiry = $expiry_date[0]; for ($i = 0; $i < $total_items; $i++) { //compute the actual stock $total_items_issues = $commodity_unit_of_issue[$i] == 'Pack_Size' ? $quantity_issued[$i] * $total_units[$i] : $quantity_issued[$i]; //prepare the issues data $facility_name = isset($service_point[$i]) ? Facilities::get_facility_name2($service_point[$i]) : null; $facility_name = isset($facility_name) ? $facility_name['facility_name'] : 'N/A'; $mydata = array('facility_code' => $facility_code, 's11_No' => '(-ve Adj) Stock Deduction', 'batch_no' => $batch_no[$i], 'commodity_id' => $commodity_id[$i], 'expiry_date' => date('y-m-d', strtotime($expiry_date[$i])), 'qty_issued' => $total_items_issues, 'issued_to' => "inter-facility donation:" . $facility_name, 'balance_as_of' => $commodity_balance_before[$i], 'date_issued' => date('y-m-d', strtotime($clone_datepicker_normal_limit_today[$i])), 'issued_by' => $this->session->userdata('user_id')); $mydata_2 = array('manufacturer' => $manufacture[$i], 'source_district_id' => $district_id, 'source_facility_code' => $facility_code, 'batch_no' => $batch_no[$i], 'commodity_id' => $commodity_id[$i], 'expiry_date' => date('y-m-d', strtotime($expiry_date[$i])), 'quantity_sent' => $total_items_issues, 'receive_facility_code' => $service_point[$i], 'facility_stock_ref_id' => $facility_stock_id[$i], 'date_sent' => date('y-m-d'), 'sender_id' => $this->session->userdata('user_id')); // update the issues table array_push($data_array_issues_table, $mydata); array_push($data_array_redistribution_table, $mydata_2); // reduce the stock levels //var_dump($mydata);exit; $a = Doctrine_Manager::getInstance()->getCurrentConnection(); $a->execute("UPDATE `facility_stocks` SET `current_balance` = `current_balance`-{$total_items_issues} where id='{$facility_stock_id[$i]}'"); //update the transaction table here $inserttransaction = Doctrine_Manager::getInstance()->getCurrentConnection(); $inserttransaction->execute("UPDATE `facility_transaction_table` SET `total_issues` = `total_issues`+{$total_items_issues},\n\t\t\t`closing_stock`=`closing_stock`-{$total_items_issues}\n WHERE `commodity_id`= '{$commodity_id[$i]}' and status='1' and facility_code='{$facility_code}';"); $existence = drug_store_issues::check_drug_existence($commodity_id[$i], $district_id); // echo "<pre>"; print_r($existence);echo "</pre>";;exit; if ($existence[0]['present'] >= 0) { $update_totals = Doctrine_Manager::getInstance()->getCurrentConnection(); $update_totals->execute("UPDATE `drug_store_totals` SET `total_balance` = `total_balance`+{$total_items_issues}\n\t\t WHERE `commodity_id`= '{$commodity_id[$i]}' and district_id='{$district_id}';"); //echo $update_totals;exit; } else { $new_entry_details = array('district_id' => $district_id, 'commodity_id' => $commodity_id[$i], 'total_balance' => $total_items_issues, 'expiry_date' => $digested_expiry); array_push($new_drug_store_entry, $new_entry_details); $data = $this->db->insert_batch('drug_store_totals', $new_drug_store_entry); //echo $data;exit; } //end of existence update/entry if } $user = $this->session->userdata('user_id'); $user_action = "redistribute"; //updates the log table accordingly based on the action carried out by the user involved $update = Doctrine_Manager::getInstance()->getCurrentConnection(); $update->execute("update log set {$user_action} = 1 \n\t\t\twhere `user_id`= {$user} \n\t\t\tAND action = 'Logged In' \n\t\t\tand UNIX_TIMESTAMP( `end_time_of_event`) = 0"); $this->db->insert_batch('facility_issues', $data_array_issues_table); $this->db->insert_batch('redistribution_data', $data_array_redistribution_table); $this->session->set_flashdata('system_success_message', "You have issued {$total_items} item(s)"); redirect(home); } // redirect(home); }