public static function update_facility_stock($data_array) { $o = new facility_stocks(); $o->fromArray($data_array); $o->save(); return TRUE; }
public function index($checker = NULL) { $facility_code = $this->session->userdata('facility_id'); switch ($checker) { case 'internal': $data['content_view'] = "facility/facility_issues/facility_issues_service_points_v"; $data['title'] = "Issues to service points"; $data['banner_text'] = "Issues to service points"; break; case 'external': $data['content_view'] = "facility/facility_issues/facility_redistribute_items_v"; $data['subcounties'] = districts::getAll(); $data['banner_text'] = "Redistribute Commodities"; $data['title'] = "Redistribute Commodities"; break; default: } $data['service_point'] = service_points::get_all_active($facility_code); $data['commodities'] = facility_stocks::get_distinct_stocks_for_this_facility($facility_code, 1); $data_ = facility_stocks::get_distinct_stocks_for_this_facility($facility_code, "batch_data"); foreach ($data_ as $key => $data_1) { $data_[$key]['commodity_name'] = preg_replace('/[^A-Za-z0-9\\-]/', ' ', $data_1['commodity_name']); } $data['facility_stock_data'] = json_encode($data_); $this->load->view("shared_files/template/template", $data); }
public function index() { $facility_code = $this->session->userdata('facility_id'); $data['banner_text'] = "Commodity Dispensing"; $data['sidebar'] = "facility/facility_dispensing/sidebar_dispensing"; // $data['report_view'] = "facility/facility_dispensing/"; // $commodities = Commodities::get_all(); $data['content_view'] = "facility/facility_dispensing/dispensing_home"; $view = 'shared_files/template/template'; $data['active_panel'] = 'dispensing'; $data['title'] = "Dispensing"; $patients = patients::get_all(); $commodities_in_facility = facility_stocks::get_facility_stock_amc($facility_code); $data['commodities'] = $commodities_in_facility; // echo "<pre>";print_r($commodities_in_facility);exit; $data['patients'] = $patients; $this->load->view($view, $data); }
public function notification_dashboard() { $facility_code = !$this->session->userdata('facility_id') ? null : $this->session->userdata('facility_id'); $district_id = !$this->session->userdata('district_id') ? null : $this->session->userdata('district_id'); $county_id = !$this->session->userdata('county_id') ? null : $this->session->userdata('county_id'); //compute stocked out items $items_stocked_out_in_facility = count(facility_stocks::get_items_that_have_stock_out_in_facility($facility_code, $district_id, $county_id)); //get order information from the db $facility_order_count_ = facility_orders::get_facility_order_summary_count($facility_code, $district_id, $county_id); $facility_order_count = array(); foreach ($facility_order_count_ as $facility_order_count_) { $facility_order_count[$facility_order_count_['status']] = $facility_order_count_['total']; } //get potential expiries infor here $potential_expiries = count(Facility_stocks::get_potential_expiry_summary($county_id, 6, $district_id, $facility_code)); //get actual Expiries infor here $actual_expiries = count(Facility_stocks::get_county_expiries($county_id, date('Y'), $district_id, $facility_code)); //get items they have been donated for $facility_donations = count(redistribution_data::get_redistribution_data($facility_code, $district_id, $county_id, date('Y'))); $identifier = $this->session->userdata('user_indicator'); //get the roll out status here $facility_roll_out_status = Facilities::get_tragetted_rolled_out_facilities($facility_code, $district_id, $county_id, $identifier); $data['county_dashboard_notifications'] = array('items_stocked_out_in_facility' => $items_stocked_out_in_facility, 'facility_order_count' => $facility_order_count, 'potential_expiries' => $potential_expiries, 'actual_expiries' => $actual_expiries, 'facility_donations' => $facility_donations, 'facility_roll_out_status' => $facility_roll_out_status); return $this->load->view("subcounty/ajax/county_notification_v", $data); }
public function get_facility_dashboard_notifications_graph_data() { //format the graph here $facility_code = $this->session->userdata('facility_id'); $facility_stock_ = facility_stocks::get_facility_stock_amc($facility_code); $facility_stock_count = count($facility_stock_); $graph_data = array(); $graph_data = array_merge($graph_data, array("graph_id" => 'container')); $graph_data = array_merge($graph_data, array("graph_title" => 'Facility stock level')); $graph_data = array_merge($graph_data, array("color" => "['#4b0082','#FFF263', '#6AF9C4']")); $graph_data = array_merge($graph_data, array("graph_type" => 'bar')); $graph_data = array_merge($graph_data, array("graph_yaxis_title" => 'Total stock level (values in packs)')); $graph_data = array_merge($graph_data, array("graph_categories" => array())); $graph_data = array_merge($graph_data, array("series_data" => array("Current Balance" => array(), "AMC" => array()))); $graph_data['stacking'] = 'normal'; foreach ($facility_stock_ as $facility_stock_) { $graph_data['graph_categories'] = array_merge($graph_data['graph_categories'], array($facility_stock_['commodity_name'])); $graph_data['series_data']['Current Balance'] = array_merge($graph_data['series_data']['Current Balance'], array((double) $facility_stock_['pack_balance'])); $graph_data['series_data']['AMC'] = array_merge($graph_data['series_data']['AMC'], array((double) $facility_stock_['amc'])); } //echo "<pre>";print_r($facility_stock_);echo "</pre>";exit; //create the graph here $faciliy_stock_data = $this->hcmp_functions->create_high_chart_graph($graph_data); $loading_icon = base_url('assets/img/no-record-found.png'); $faciliy_stock_data = $facility_stock_count > 0 ? $faciliy_stock_data : "\$('#container').html('<img src={$loading_icon}>');"; //compute stocked out items $items_stocked_out_in_facility = count(facility_stocks::get_items_that_have_stock_out_in_facility($facility_code)); //get order information from the db $facility_order_count_ = facility_orders::get_facility_order_summary_count($facility_code); //echo "<pre>";print_r($facility_order_count_);echo "<pre>";exit; $facility_order_count = array(); foreach ($facility_order_count_ as $facility_order_count_) { $facility_order_count[$facility_order_count_['status']] = $facility_order_count_['total']; } //get potential expiries infor here $potential_expiries = Facility_stocks::potential_expiries($facility_code)->count(); //get actual Expiries infor here $actual_expiries = count(Facility_stocks::All_expiries($facility_code)); //get items they have been donated for $facility_donations = redistribution_data::get_all_active($facility_code, "to-me")->count(); //get items they have been donated and are pending $facility_donations_pending = redistribution_data::get_all_active($facility_code)->count(); //get stocks from v1 $stocks_from_v1 = 0; if ($facility_stock_count == 0 && $facility_donations == 0 && $facility_donations_pending == 0) { $stocks_from_v1 = count(facility_stocks::import_stock_from_v1($facility_code)); } return array('facility_stock_count' => $facility_stock_count, 'faciliy_stock_graph' => $faciliy_stock_data, 'items_stocked_out_in_facility' => $items_stocked_out_in_facility, 'facility_order_count' => $facility_order_count, 'potential_expiries' => $potential_expiries, 'actual_expiries' => $actual_expiries, 'facility_donations' => $facility_donations, 'facility_donations_pending' => $facility_donations_pending, 'stocks_from_v1' => $stocks_from_v1); }
public function fix() { // get the facility_codes $facility_codes = Doctrine_Manager::getInstance()->getCurrentConnection()->fetchAll("select distinct `facility_code` from `facility_issues` WHERE status=1"); foreach ($facility_codes as $key => $facility_code) { //step one reset refrence table $facility_code = $facility_code['facility_code']; $min_date = Doctrine_Manager::getInstance()->getCurrentConnection()->fetchAll("select min(date_issued) as min_date,issued_by from `facility_issues` WHERE facility_code={$facility_code} and status=1"); $reset_facility_transaction_table = Doctrine_Manager::getInstance()->getCurrentConnection(); $reset_facility_transaction_table->execute("DELETE FROM `facility_transaction_table` WHERE facility_code={$facility_code}; "); $reset_facility_transaction_table->execute("DELETE FROM `facility_issues` WHERE facility_code={$facility_code} and s11_No='initial stock update'\n and status=1"); //step two get the facility stocks $facility_stocks = facility_stocks::get_facility_commodity_total($facility_code); $data_array_facility_transaction = $data_array_facility_issues = array(); foreach ($facility_stocks as $facility_stock) { $commodity_id = $facility_stock['commodity_id']; if ($commodity_id > 0) { $total = Doctrine_Manager::getInstance()->getCurrentConnection()->fetchAll("select ifnull(sum(qty_issued),0) as total from `facility_issues` WHERE facility_code={$facility_code} and status=1 and commodity_id={$commodity_id}"); $mydata2 = array('facility_code' => $facility_code, 'commodity_id' => $facility_stock['commodity_id'], 'opening_balance' => $facility_stock['commodity_balance'], 'total_issues' => $total[0]['total'], 'total_receipts' => 0, 'adjustmentpve' => 0, 'adjustmentnve' => 0, 'date_added' => $min_date[0]['min_date'], 'closing_stock' => $facility_stock['commodity_balance'], 'status' => 1); //send the data to the facility_transaction_table array_push($data_array_facility_transaction, $mydata2); $total_unit_count_ = $facility_stock['commodity_balance'] * -1; $mydata_ = array('facility_code' => $facility_code, 's11_No' => 'initial stock update', 'commodity_id' => $facility_stock['commodity_id'], 'batch_no' => "N/A", 'expiry_date' => "N/A", 'balance_as_of' => 0, 'qty_issued' => $total_unit_count_, 'date_issued' => $min_date[0]['min_date'], 'issued_to' => 'N/A', 'issued_by' => $min_date[0]['issued_by']); //create the array to push to the db array_push($data_array_facility_issues, $mydata_); } } $this->db->insert_batch('facility_transaction_table', $data_array_facility_transaction); $this->db->insert_batch('facility_issues', $data_array_facility_issues); echo "<br>{$key} fixed facility code " . $facility_code; } }
public function undo_reverse_issue($facility_code, $raw_date, $issued_by, $type) { $current_time = date("Y-m-d H:i:s", time()); $created_at = date("Y-m-d H:i:s", $raw_date); $issue_details = Facility_issues::get_undo_issue_details_for_reversals($facility_code, $created_at, $issued_by); if ($type == 'view') { foreach ($issue_details as $key => $value) { $facility_code = $value['facility_code']; $facility_name = $value['facility_name']; $commodity_name = $value['commodity_name']; $batch_no = $value['batch_no']; $qty_issued = $value['qty_issued']; $date_issued_raw = $value['date_issued']; $issued_by = $value['issued_by']; $date_issued = date('d F Y', strtotime($date_issued_raw)); $output[] = array($facility_name, $facility_code, $commodity_name, $batch_no, $qty_issued, $date_issued); } echo json_encode($output); } else { if ($type == 'reverse') { foreach ($issue_details as $key => $value) { $undo_reversed_data = array('facility_code' => $value['facility_code'], 's11_No' => $value['s11'], 'commodity_id' => $value['commodity_id'], 'batch_no' => $value['batch_no'], 'expiry_date' => $value['expiry_date'], 'balance_as_of' => $value['balance_as_of'], 'adjustmentpve' => $value['adjustmentpve'], 'adjustmentnve' => $value['adjustmentnve'], 'qty_issued' => $value['qty_issued'], 'date_issued' => $value['date_issued'], 'issued_to' => $value['issued_to'], 'created_at' => $value['created_at'], 'issued_by' => $value['issued_by'], 'status' => $value['status']); $this->db->insert('facility_issues', $undo_reversed_data); $facility_stocks_data = facility_stocks::get_current_stock_for_reversal($value['facility_code'], $value['commodity_id'], $value['batch_no']); foreach ($facility_stocks_data as $keys => $values) { $id = $values['id']; $initial_quantity = $values['initial_quantity']; $current_balance = intval($values['current_balance']); $new_balance = $current_balance - intval($value['qty_issued']); $update_data = array('current_balance' => $new_balance); $this->db->where('id', $id); $this->db->update('facility_stocks', $update_data); } $this->db->where('id', $value['id']); $this->db->delete('reversals'); } redirect('admin/reversals'); } } }
public function get_service_point_graph_data() { // $graph_id = "container"; $facility_code = $this->session->userdata('facility_id'); $service_point = 2; //hard coded for pharmacy,until requested for :] $service_point_stock = facility_stocks::get_service_point_stocks($facility_code, $service_point); $service_point_name = $service_point_stock[0]['service_point_name']; // echo "<pre> Here";print_r($service_point_stock);exit; $service_point_stock_count = count($service_point_stock); $graph_id = "sp_graph"; $graph_data = array(); $graph_data = array_merge($graph_data, array("graph_id" => $graph_id)); $graph_data = array_merge($graph_data, array("graph_title" => "{$service_point_name} Stock Level")); $graph_data = array_merge($graph_data, array("graph_type" => "bar")); $graph_data = array_merge($graph_data, array("graph_yaxis_title" => "Total Stock Level")); $graph_data = array_merge($graph_data, array("graph_categories" => array())); $graph_data = array_merge($graph_data, array("series_data" => array("Current Pack Balance" => array(), "Current Unit Balance" => array()))); $graph_data['stacking'] = 'normal'; foreach ($service_point_stock as $service_point_stock) { $pack_balance = $service_point_stock['current_balance'] / $service_point_stock['total_commodity_units']; $graph_data['graph_categories'] = array_merge($graph_data['graph_categories'], array($service_point_stock['commodity_name'])); $graph_data['series_data']['Current Pack Balance'] = array_merge($graph_data['series_data']['Current Pack Balance'], array((double) $pack_balance)); $graph_data['series_data']['Current Unit Balance'] = array_merge($graph_data['series_data']['Current Unit Balance'], array((double) $service_point_stock['total_commodity_units'])); } $service_point_stock_data = $this->hcmp_functions->create_high_chart_graph($graph_data); // echo "<pre>"; print_r($service_point_stock_data); echo "</pre>"; exit; $loading_icon = base_url('assets/img/no-record-found.png'); $service_point_stock_data = $service_point_stock_count > 0 ? $service_point_stock_data : "\$('#container').html('<img src={$loading_icon}>');"; $actual_expiries = count(facility_stocks::get_service_point_stocks($facility_code, $service_point, NULL, 1)); $potential_expiries = count(facility_stocks::get_service_point_stocks($facility_code, $service_point, 1, NULL)); // echo "<pre>";print_r($potential_expiries);exit; return array("service_point_stock_count" => $service_point_stock_count, "service_point_stock_graph" => $service_point_stock_data, "service_point_name" => $service_point_name, "potential_expiries" => $potential_expiries, "actual_expiries" => $actual_expiries); }
public function district_store_issue() { //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); $data_array_issues_table = array(); $data_array_redistribution_table = array(); $commodity_ids = facility_stocks::get_district_store_commodities($district_id); $commodity_total = facility_stocks::get_district_store_total_commodities($district_id); $comm_count = count($commodity_total); // echo "<pre>";print_r($commodity_total);echo "</pre>";exit; // insertion of data to totals table $totals_data = array(); $totals_data_ = array(); // update the issues table for ($i = 0; $i < $total_items; $i++) { //compute the actual stock $updated_ckecker = 1; foreach ($commodity_total as $comm) { if (in_array($district_id, $comm)) { if (in_array($commodity_id[$i], $comm)) { $b = Doctrine_Manager::getInstance()->getCurrentConnection(); $b->execute("UPDATE `drug_store_totals` SET `total_amount` = `total_amount`+{$quantity_issued[$i]} where commodity_id ='{$commodity_id[$i]}' and district_id = '{$district_id}'"); $updated_ckecker = 2; } } //end of dist if } switch ($updated_ckecker) { case 1: $totals_data = array(); $totals_data_ = array(); $totals_data_ = array('district_id' => $district_id, 'commodity_id' => $commodity_id[$i], 'total_amount' => $quantity_issued[$i]); array_push($totals_data, $totals_data_); $this->db->insert_batch('drug_store_totals', $totals_data); break; case 2: break; default: break; } $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], '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 $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\t`closing_stock`=`closing_stock`-{$total_items_issues}\n\t WHERE `commodity_id`= '{$commodity_id[$i]}' and status='1' and facility_code='{$facility_code}';"); } $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\t\twhere `user_id`= {$user} \n\t\t\t\tAND action = 'Logged In' \n\t\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(); } redirect(); }
public function delete_redistribution($id) { $redistribution_data = redistribution_data::get_one($id); foreach ($redistribution_data as $key => $value) { $quantity_sent = intval($value['quantity_sent']); $stock_id = $value['stock_id']; $stock_data = facility_stocks::get_facilty_stock_id($stock_id); foreach ($stock_data as $keys => $values) { $current_balance = intval($values['current_balance']); $new_balance = $current_balance + $quantity_sent; $update_array = array('id' => $stock_id, 'current_balance' => $new_balance); $inserttransaction = Doctrine_Manager::getInstance()->getCurrentConnection(); $inserttransaction->execute("UPDATE `facility_stocks` SET `current_balance` = '{$new_balance}' WHERE id= '{$stock_id}'"); $inserttransaction->execute("UPDATE `redistribution_data` SET `status` = '5' WHERE id= '{$id}'"); $this->session->set_flashdata('system_success_message', "The Issue has been Deleted"); redirect('issues/confirm_external_issue_edit'); } } }
public function get_consumption_chart_ajax_all($sub_category = null) { $commodity_id = $this->input->post('commodity_id'); $from = $this->input->post('from'); $to = $this->input->post('to'); $total = 0; $to = $to == "NULL" || !isset($to) ? date('Y-m-d 23:59:59') : date('Y-m-d 23:59:59', strtotime(urldecode($to))); $from = $from == "NULL" || !isset($from) ? date('Y-m-d 00:00:00') : date('Y-m-d 00:00:00', strtotime(urldecode($from))); $consumption = facility_stocks::get_dispensing_consumption_by_commodity($from, $to, $sub_category); // echo "<pre>"; // print_r($consumption);die; // $commodity_details = Commodities::get_commodity_name($commodity_id); $graph_id = 'dem_graph_'; $data['graph_id'] = 'dem_graph_'; // $commodity_name = $commodity_details[0]['commodity_name']; $text_title = 'Top 10 Highest Consumption by Commodity between ' . date('F d Y', strtotime($from)) . ' and ' . date('F d Y', strtotime($to)); $result_chart = " \$('#{$graph_id}').highcharts({\n chart: {\n plotBackgroundColor: null,\n plotBorderWidth: null,\n plotShadow: false,\n type: 'pie'\n },\n title: {\n text: '{$text_title}'\n },\n tooltip: {\n pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'\n },\n plotOptions: {\n pie: {\n allowPointSelect: false,\n cursor: 'pointer',\n dataLabels: {\n enabled: true\n },\n showInLegend: true\n }\n },\n series: [{\n name: 'Test',\n colorByPoint: true,\n data:["; foreach ($consumption as $key => $raw_data) { $name = $raw_data['commodity_name']; $val = intval($raw_data['total']); $result_chart .= "{ name: '{$name} ({$val} units)', y:{$val}"; $result_chart .= "},"; } // series: [{ // name: '$commodity_name', // colorByPoint: true, // data: [{ // name: 'Under 5 years ($val1 units)', // y: $val1 // }, { // name: 'Over 5 Years ($val2 units)', // y:$val2, // selected: true // }] // }] // });"; $result_chart .= "] }] })"; $data['high_graph'] = $result_chart; return $this->load->view("shared_files/report_templates/high_charts_template_v", $data); // echo $result_chart; }
public static function update_facility_stock($data_array) { $o = new facility_stocks(); $o -> fromArray($data_array); $o -> save(); return TRUE; }// get the total balance of a specific item within a balance