Example #1
0
 public function InsertExt()
 {
     #solves error code fac#35 changing issuing to use commodity id that batchno
     $commodity_id = $_POST['commodity_id'];
     #///////////////////////////////////////
     $Available = $_POST['commodity_balance'];
     $ids = $_POST['drug_id'];
     $mfl = $_POST['mfl'];
     $batchN = $_POST['batchNo'];
     $Expiry = $_POST['expiry_date'];
     $qty = $_POST['Qtyissued'];
     $thedate = $_POST['date_issue'];
     $j = sizeof($ids);
     $count = 0;
     $facilityCode = $facility_c = $this->session->userdata('news');
     $usernow = $this->session->userdata('identity');
     //loop through all th donated commodities and process
     for ($me = 0; $me < $j; $me++) {
         if ($qty[$me] > 0) {
             ///update the donating facility details
             $facility_name = Facilities::get_facility_name($mfl[$me])->toArray();
             $facility_details = "inter-facility donation: MFL NO " . $mfl[$me];
             $sNo = "(-ve Adj) Stock Deduction";
             $count++;
             $issues = $qty[$me] * -1;
             ////checking if the facilility receiving the commodities is using HCMP
             $users_array = user::getUsers($mfl[$me]);
             $user_in_donated_facility = count($users_array);
             //inserting in the facility issues
             $mydata = array('facility_code' => $facilityCode, 'kemsa_code' => $ids[$me], 's11_No' => $sNo, 'batch_no' => $batchN[$me], 'expiry_date' => date('y-m-d', strtotime($Expiry[$me])), 'qty_issued' => $qty[$me], 'balanceAsof' => $Available[$me], 'date_issued' => date('y-m-d', strtotime($thedate[$me])), 'issued_to' => $facility_details, 'issued_by' => $usernow, 'receipts' => $issues);
             $u = new Facility_Issues();
             $u->fromArray($mydata);
             $u->save();
             //updating the facility stock
             $a = Doctrine_Manager::getInstance()->getCurrentConnection();
             $a->execute("UPDATE `Facility_Stock` SET `balance` = `balance`-{$qty[$me]} where id='{$commodity_id[$me]}'");
             ///updating the trascation_table
             $inserttransaction_1 = Doctrine_Manager::getInstance()->getCurrentConnection()->fetchAll("select  `adj` from `facility_transaction_table`WHERE `kemsa_code`= '{$ids[$me]}' and availability='1' and facility_code={$facility_c}; ");
             $inserttransaction_2 = Doctrine_Manager::getInstance()->getCurrentConnection()->fetchAll("SELECT (SUM(qty_issued)*-1) as update_ FROM facility_issues \n\t\t\tWHERE kemsa_code = '{$ids[$me]}' and issued_to='{$facility_details}' and availability='1'");
             $new_value = $inserttransaction_1[0]['adj'] + $inserttransaction_2[0]['update_'];
             $inserttransaction = Doctrine_Manager::getInstance()->getCurrentConnection();
             $inserttransaction->execute("UPDATE `facility_transaction_table` SET adj ={$new_value} \n                                          WHERE `kemsa_code`= '{$ids[$me]}' and availability='1' and facility_code={$facilityCode}; ");
             $inserttransaction1 = Doctrine_Manager::getInstance()->getCurrentConnection();
             $inserttransaction1->execute("UPDATE `facility_transaction_table` SET closing_stock = (SELECT SUM(balance) FROM facility_stock WHERE kemsa_code = '{$ids[$me]}'\n\t\t\tand availability='1' and facility_code='{$facilityCode}' and availability='1')\n                                          WHERE`kemsa_code`= '{$ids[$me]}' and availability='1' and facility_code={$facilityCode}; ; ");
             ///updating the receiving facility records if they are using the system
             if ($user_in_donated_facility > 0) {
                 //getting the name of the mauf of the given drug
                 $mauf = facility_stock::get_batch_details($batchN[$me], $ids[$me]);
                 $mydata = array('facility_code' => $mfl[$me], 'kemsa_code' => $ids[$me], 'batch_no' => $batchN[$me], 'manufacture' => $mauf['manufacture'], 'expiry_date' => date('y-m-d', strtotime($Expiry[$me])), 'balance' => $qty[$me], 'quantity' => $qty[$me], 'stock_date' => date('y-m-d'));
                 Facility_Stock::update_facility_stock($mydata);
                 ///checking if the receiving_facility_has_this_drug  //kemsa_code facility code
                 $receiving_facility_has_this_drug = Facility_Transaction_Table::get_if_drug_is_in_table($mfl[$me], $ids[$me]);
                 if (count($receiving_facility_has_this_drug) > 0) {
                     //if yes update their records
                     $inserttransaction = Doctrine_Manager::getInstance()->getCurrentConnection();
                     $inserttransaction->execute("UPDATE `facility_transaction_table` SET \n\t\t\tadj = (SELECT SUM(qty_issued) FROM facility_issues WHERE kemsa_code = '{$ids[$me]}' and issued_to='{$facility_details}' and availability='1')\n            WHERE `kemsa_code`= '{$ids[$me]}' and availability='1' and facility_code={$mfl[$me]}; ");
                     $inserttransaction1 = Doctrine_Manager::getInstance()->getCurrentConnection();
                     $inserttransaction1->execute("UPDATE `facility_transaction_table` \n\t\t\tSET closing_stock = (SELECT SUM(qty_issued) FROM facility_issues WHERE kemsa_code = '{$ids[$me]}' and issued_to='{$facility_details}' and availability='1')\n            WHERE`kemsa_code`= '{$ids[$me]}' and availability='1' and facility_code={$mfl[$me]};");
                 } else {
                     //if no insert the record in the transaction table
                     $mydata2 = array('Facility_Code' => $mfl[$me], 'Kemsa_Code' => $ids[$me], 'Opening_Balance' => 0, 'Total_Issues' => 0, 'Total_Receipts' => 0, 'Adj' => $qty[$me], 'Closing_Stock' => $qty[$me], 'availability' => 1);
                     Facility_Transaction_Table::update_facility_table($mydata2);
                 }
             } else {
                 //do nothing
             }
         }
     }
     $this->send_stock_donate_sms();
     $this->session->set_flashdata('system_success_message', "You have Donated {$count} item(s)");
     redirect('issues_main');
 }
Example #2
0
 public function get_county_stock_level_new($commodity_id = null, $category_id = null, $district_id = null, $option = null)
 {
     $county_id = $this->session->userdata('county_id');
     $county_name = counties::get_county_name($county_id);
     $year = date("Y");
     $month = date("m");
     $category_data = array();
     $series_data = array();
     $option_new = isset($option) ? $option : "packs";
     $district_data = isset($district_id) && $district_id > 0 ? districts::get_district_name($district_id)->toArray() : null;
     $district_name = isset($district_data) ? " :" . $district_data[0]['district'] . " subcounty" : null;
     $facility_code = isset($facility_code) && $facility_code > 0 ? facilities::get_facility_name($facility_code)->toArray() : facilities::get_facilities_which_are_online($district_id);
     $district_id = isset($district_id) && $district_id > 0 ? districts::get_district_name($district_id)->toArray() : districts::getDistrict($county_id)->toArray();
     foreach ($district_id as $district_) {
         if (count($district_id) > 1) {
             $category_data = array_merge($category_data, array($district_["district"]));
             $stock_data = facility_stock::get_county_drug_stock_level_new($county_id, $category_id, $commodity_id, $district_["id"], $option, '');
             //foreach($stock_data as $stock_data_):
             $series_data = array_merge($series_data, array(array((int) $stock_data[0]['total'])));
             //endforeach;
         } else {
             foreach ($facility_code as $facility_) {
                 $category_data = array_merge($category_data, array($facility_['facility_name']));
                 $stock_data = facility_stock::get_county_drug_stock_level_new($county_id, $category_id, $commodity_id, $district_["id"], $option, $facility_['facility_code']);
                 $series_data = array_merge($series_data, array(array((int) $stock_data[0]['total'])));
             }
         }
     }
     $data['category_data'] = stripslashes(json_encode($category_data));
     $data['series_data'] = json_encode($series_data);
     $data['year'] = $year;
     $data['month'] = date("F", strtotime(date($year . "-" . $month)));
     $data['county'] = $county_name[0]['county'] . $district_name;
     $data['consumption_option'] = $option_new;
     $this->load->view("county/ajax_view/county_stock_level_graphical_data_v", $data);
 }
 public function get_facility_stock_details($confirmation_message = NULL)
 {
     $facility_code = $this->session->userdata('news');
     $data['title'] = "Edit Stock Details";
     $data['content_view'] = "facility/facility_reports/facility_stock_detail_v";
     $data['banner_text'] = "Edit Stock Details";
     $data['confirmation_message'] = $confirmation_message;
     $data['facility_stock_details'] = facility_stock::get_facility_stock_detail($facility_code);
     $this->load->view("template", $data);
 }