Пример #1
0
 public function create_order($type = "cdrr", $order_type, $content_array = array())
 {
     $data['hide_generate'] = 0;
     $data['hide_save'] = 0;
     $data['hide_btn'] = 0;
     $data['stand_alone'] = 0;
     if ($type == "cdrr") {
         $this->session->set_userdata("order_go_back", "cdrr");
         $data['hide_side_menu'] = 0;
         $data['options'] = "none";
         if ($order_type == 0) {
             //satellite
             $data['page_title'] = "Satellite Facility(F-CDRR)";
             $data['banner_text'] = "Satellite Facility(F-CDRR)";
             $facility = $this->input->post("satellite_facility", TRUE);
             if ($facility == null) {
                 $facility = $this->session->userdata("facility");
             } else {
                 $data['hide_generate'] = 1;
             }
         } else {
             if ($order_type == 1) {
                 //standalone
                 $data['page_title'] = "Stand-alone(F-CDRR)";
                 $data['banner_text'] = "Stand-alone(F-CDRR)";
                 $facility = $this->session->userdata("facility");
                 $data['stand_alone'] = 1;
             } else {
                 if ($order_type == 2) {
                     //dispensing_point
                     $data['page_title'] = "Central Dispensing Point(F-CDRR)";
                     $data['banner_text'] = "Central Dispensing Point(F-CDRR)";
                     $facility = $this->session->userdata("facility");
                     $order_type = 0;
                 } else {
                     //aggregate
                     $data['page_title'] = "Central Aggregate(D-CDRR)";
                     $data['banner_text'] = "Central Aggregate(D-CDRR)";
                     $data['hide_generate'] = 2;
                     $facility = $this->session->userdata("facility");
                 }
             }
         }
         if (!empty($content_array)) {
             $cdrr_array = $content_array;
             $data['cdrr_array'] = $cdrr_array['cdrr_array'];
             $data['status_name'] = strtolower($cdrr_array['cdrr_array'][0]['status_name']);
             $facility_id = $cdrr_array['cdrr_array'][0]['facility_id'];
             $data['facility_id'] = $facility_id;
             $facilities = Sync_Facility::getCode($facility_id, $order_type);
             $facility = $facilities['code'];
             $code = $cdrr_array['cdrr_array'][0]['code'];
             $code = $this->getDummyCode($code, $order_type);
             $data['options'] = $cdrr_array['options'];
             if ($data['options'] == "view") {
                 $data['hide_save'] = 1;
             }
             $data['hide_btn'] = 1;
             $cdrr_id = $cdrr_array['cdrr_array'][0]['cdrr_id'];
             $data['cdrr_id'] = $cdrr_id;
             $data['logs'] = Cdrr_Log::getLogs($cdrr_id);
             if ($data['options'] == "view" || $data['options'] == "update") {
                 if ($data['status_name'] == "prepared" || $data['status_name'] == "review") {
                     $data['option_links'] = "<li class='active'><a href='" . site_url("order/view_order/cdrr/" . $cdrr_id) . "'>view</a></li><li><a href='" . site_url("order/update_order/cdrr/" . $cdrr_id) . "'>update</a></li><li><a class='delete' href='" . site_url("order/delete_order/cdrr/" . $cdrr_id) . "'>delete</a></li>";
                 } else {
                     $data['option_links'] = "<li class='active'><a href='" . site_url("order/view_order/cdrr/" . $cdrr_id) . "'>view</a></li>";
                 }
             }
             if ($code == 0) {
                 $and = "";
             } else {
                 $and = "AND ci.resupply !='0'";
             }
             if ($cdrr_array['options'] == "update") {
                 $data['commodities'] = Sync_Drug::getActiveList();
             } else {
                 $sql = "SELECT sd.id,CONCAT_WS('] ',CONCAT_WS(' [',name,abbreviation),CONCAT_WS(' ',strength,formulation)) as Drug,unit as Unit_Name,packsize as Pack_Size,category_id as Category\n\t\t\t        FROM cdrr_item ci\n\t\t\t        LEFT JOIN sync_drug sd ON sd.id=ci.drug_id\n\t\t\t        WHERE ci.cdrr_id='{$cdrr_id}'\n\t\t\t        AND(sd.category_id='1' OR sd.category_id='2' OR sd.category_id='3')";
                 $query = $this->db->query($sql);
                 $data['commodities'] = $query->result();
             }
         } else {
             $period_start = date('Y-m-01', strtotime(date('Y-m-d') . "-1 month"));
             $period_end = date('Y-m-t', strtotime(date('Y-m-d') . "-1 month"));
             $code = $this->getActualCode($order_type, $type);
             $facilities = Sync_Facility::getId($facility, $order_type);
             $duplicate = $this->check_duplicate($code, $period_start, $period_end, $facilities['id'], $type);
             $data['commodities'] = Sync_Drug::getActiveList();
             $data['duplicate'] = $duplicate;
         }
         $facilities = Sync_Facility::getId($facility, $order_type);
         $data['facility_id'] = $facilities['id'];
         $data['facility_object'] = Facilities::getCodeFacility($facility);
         $data['content_view'] = "orders/cdrr_template";
         $data['report_type'] = $order_type;
         $data['stores'] = CCC_store_service_point::getStoreGroups();
         $this->base_params($data);
     } else {
         if ($type == "maps") {
             $this->session->set_userdata("order_go_back", "fmaps");
             $data['o_type'] = "FMAP";
             $data['options'] = "none";
             $data["is_update"] = 0;
             $data["is_view"] = 0;
             if ($order_type == 0) {
                 //satellite
                 $facility_code = $this->input->post("satellite_facility", TRUE);
                 $data['page_title'] = "Satellite Facility(F-MAPS)";
                 $data['banner_text'] = "Satellite Facility(F-MAPS)";
                 if ($facility_code == null) {
                     $facility_code = $this->session->userdata("facility");
                 } else {
                     $data['hide_generate'] = 1;
                 }
             } else {
                 if ($order_type == 1) {
                     //standalone
                     $facility_code = $this->session->userdata('facility');
                     $facility_id = $this->session->userdata('facility_id');
                     $data['commodities'] = Sync_Drug::getActiveList();
                     $data['page_title'] = "Stand-Alone MAPS";
                     $data['banner_text'] = "Maps Form";
                 } else {
                     if ($order_type == 2) {
                         //dispensing_point
                         $facility_code = $this->session->userdata('facility');
                         $facility_id = $this->session->userdata('facility_id');
                         $data['commodities'] = Sync_Drug::getActiveList();
                         $data['page_title'] = "Central Dispensing Point";
                         $data['banner_text'] = "Maps Form";
                         $order_type = 0;
                     } else {
                         //aggregate
                         $facility_code = $this->session->userdata('facility');
                         $data['page_title'] = "Aggregate Maps List";
                         $facility = Facilities::getParent($facility_code);
                         $parent_code = $facility['parent'];
                         if ($parent_code == $facility_code) {
                             //Check if button was clicked to start new aggregate order
                             $data['hide_generate'] = 2;
                         }
                         $data['banner_text'] = "Aggregate Maps List";
                     }
                 }
             }
             if (!empty($content_array)) {
                 $fmaps_array = $content_array;
                 $data['fmaps_array'] = $fmaps_array['fmaps_array'];
                 $facility_id = $fmaps_array['fmaps_array'][0]['facility_id'];
                 $data['facility_id'] = $facility_id;
                 $facilities = Sync_Facility::getCode($facility_id, $order_type);
                 $facility_code = $facilities['code'];
                 $code = $fmaps_array['fmaps_array'][0]['code'];
                 $code = $this->getDummyCode($code, $order_type);
                 //Central or Satellite or Aggregate
                 $data['status'] = strtolower($fmaps_array['fmaps_array'][0]['status_name']);
                 $data['created'] = $fmaps_array['fmaps_array'][0]['created'];
                 // Pending, Approved, ...
                 $data['options'] = $fmaps_array['options'];
                 $data['hide_btn'] = 1;
                 $maps_id = $fmaps_array['fmaps_array'][0]['maps_id'];
                 //Complet id with #
                 $map_id = $fmaps_array['fmaps_array'][0]['map_id'];
                 //Id from DB
                 $data['maps_id'] = $maps_id;
                 $data['map_id'] = $map_id;
                 $data['logs'] = Maps_Log::getMapLogs($map_id);
                 if ($data['options'] == "view") {
                     $data['hide_save'] = 1;
                     $regimen_table = 'sync_regimen';
                     $regimen_cat_table = 'sync_regimen_category';
                     $regimen_code = 'r.code';
                     $regimen_desc = 'r.name as description';
                     $regimen_cat_join = 'r.category_id';
                     $regimen_join = 'mi.regimen_id=r.id';
                     $sql_regimen = "SELECT rc.id,r.id as reg_id,rc.Name as name,{$regimen_code},{$regimen_desc},{$regimen_cat_join},mi.total\n\t\t\t\t\t\t\t\t\tFROM {$regimen_table} r\n\t\t\t\t\t\t\t\t\tLEFT JOIN {$regimen_cat_table} rc ON rc.id = {$regimen_cat_join}\n\t\t\t\t\t\t\t\t\tLEFT JOIN maps_item mi ON {$regimen_join}\n\t\t\t\t\t\t\t\t\tWHERE maps_id='{$map_id}'";
                     $query_regimen = $this->db->query($sql_regimen);
                     $regimen_array = $query_regimen->result_array();
                     $regimen_categories = array();
                     foreach ($regimen_array as $value) {
                         $regimen_categories[] = $value['name'];
                     }
                     $regimen_categories = array_unique($regimen_categories);
                     $data['regimen_categories'] = $regimen_categories;
                     $data['regimen_array'] = $regimen_array;
                 }
                 if ($data['options'] == "update") {
                     $data["is_update"] = 1;
                     $data['regimen_categories'] = Sync_Regimen_Category::getAll();
                 } else {
                     $data["is_view"] = 1;
                     $data['regimens'] = Maps_Item::getOrderItems($maps_id);
                 }
             } else {
                 $data['regimen_categories'] = Sync_Regimen_Category::getAll();
                 $period_start = date('Y-m-01', strtotime(date('Y-m-d') . "-1 month"));
                 $period_end = date('Y-m-t', strtotime(date('Y-m-d') . "-1 month"));
                 $code = $this->getActualCode($order_type, $type);
                 $facilities = Sync_Facility::getId($facility_code, $order_type);
                 $duplicate = $this->check_duplicate($code, $period_start, $period_end, $facilities['id'], $type);
                 $data['duplicate'] = $duplicate;
             }
             $facilities = Sync_Facility::getId($facility_code, $order_type);
             $data['facility_id'] = $facilities['id'];
             $data['content_view'] = "orders/fmap_template";
             $data['report_type'] = $order_type;
             $data['facility_object'] = Facilities::getCodeFacility($facility_code);
             $this->base_params($data);
         }
     }
 }
Пример #2
0
 public function data_upload()
 {
     if ($_POST['btn_save']) {
         $objReader = new PHPExcel_Reader_Excel2007();
         if ($_FILES['file']['tmp_name']) {
             $objPHPExcel = $objReader->load($_FILES['file']['tmp_name']);
         } else {
             $this->session->set_userdata('upload_counter', '1');
             redirect("fcdrr_management/index");
         }
         $arr = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
         $highestColumm = $objPHPExcel->setActiveSheetIndex(0)->getHighestColumn();
         $highestRow = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
         //Top Details
         $facility_name = $arr[5]['B'] . $arr[5]['C'] . $arr[5]['D'] . $arr[5]['E'];
         $province = $arr[6]['B'] . $arr[6]['C'] . $arr[6]['D'] . $arr[6]['E'];
         $facility_code = $arr[5]['R'] . $arr[5]['S'] . $arr[5]['T'];
         $district = $arr[6]['R'] . $arr[6]['S'] . $arr[6]['T'];
         $type_of_service_art = $arr[8]['C'];
         $type_of_service_pmtct = $arr[8]['E'];
         $type_of_service_pep = $arr[8]['H'];
         if ($type_of_service_art && $type_of_service_pmtct && $type_of_service_pep) {
             $services_offered = "ART,PMTCT,PEP";
         } else {
             if ($type_of_service_pmtct && $type_of_service_art) {
                 $services_offered = "ART,PMTCT";
             } else {
                 if ($type_of_service_pep && $type_of_service_art) {
                     $services_offered = "ART,PEP";
                 } else {
                     if ($type_of_service_pmtct && $type_of_service_pep) {
                         $services_offered = "PMTCT,PEP";
                     } else {
                         if ($type_of_service_art) {
                             $services_offered = "ART";
                         }
                         if ($type_of_service_pmtct) {
                             $services_offered = "PMTCT";
                         }
                         if ($type_of_service_pep) {
                             $services_offered = "PEP";
                         }
                     }
                 }
             }
         }
         @$services_offered;
         $programme_sponsor_gok = $arr[4]['D'];
         $programme_sponsor_pepfar = $arr[4]['G'];
         $programme_sponsor_msf = $arr[4]['L'];
         $programme_sponsor = "";
         if ($programme_sponsor_gok) {
             $programme_sponsor = "GOK";
         }
         if ($programme_sponsor_pepfar) {
             $programme_sponsor = "PEPFAR";
         }
         if ($programme_sponsor_msf) {
             $programme_sponsor = "MSF";
         }
         $updated_on = date("U");
         //Reporting Period
         @($beginning = trim($arr[10]['D'] . $arr[10]['E']));
         @($ending = $arr[10]['R'] . $arr[10]['S'] . $arr[10]['T']);
         $start = explode("-", $beginning);
         $day = $start[0];
         $month = $start[1];
         $year = $start[2];
         $beginning = "20" . $year . "-" . $month . "-" . $day;
         $beginning = date('Y-m-d', strtotime($beginning));
         $ending = str_replace('/', '-', $ending);
         $old_ending = strtotime($ending);
         $ending = date('Y-m-d', $old_ending);
         $central_facility = $this->session->userdata('facility');
         $parent = Facilities::getParent($central_facility);
         $central_site = $parent->parent;
         //Comments
         for ($i = 105; $i <= 109; $i++) {
             for ($j = 1; $j <= $highestColumm; $j++) {
             }
             @($comments .= $arr[$i]['A'] . $arr[$i]['B'] . $arr[$i]['C'] . $arr[$i]['D'] . $arr[$i]['E'] . $arr[$i]['G'] . $arr[$i]['H'] . $arr[$i]['L']);
         }
         $unique_id = 0;
         $this->load->database();
         $facility_order_query = $this->db->query("SELECT MAX(id) AS id FROM facility_order");
         $facility_order_results = $facility_order_query->result_array();
         $facility_id = $facility_order_results[0]['id'];
         $order_number = $facility_id + 1;
         $unique_id = md5($order_number . $facility_code);
         $query = $this->db->query("INSERT INTO facility_order (`id`, `status`, `created`, `updated`, `code`, `period_begin`, `period_end`, `comments`, `reports_expected`, `reports_actual`, `services`, `sponsors`, `delivery_note`, `order_id`, `facility_id`,`central_facility`,`unique_id`) VALUES ('{$order_number}', '0', CURDATE(), '{$updated_on}', '2', '{$beginning}', '{$ending}', '{$comments}', NULL, NULL, '{$services_offered}', '{$programme_sponsor}', NULL, NULL, '{$facility_code}','{$central_site}','{$unique_id}');");
         $facility_id = $unique_id;
         $user_id = $this->session->userdata('full_name');
         $query = $this->db->query("SELECT MAX(id) AS id FROM order_comment");
         $results = $query->result_array();
         $last_id = $results[0]['id'];
         $last_id = $last_id + 1;
         $last_id = md5($last_id . $facility_code);
         //Adding comments
         $order_comment = new Order_Comment();
         $order_comment->Order_Number = $facility_id;
         $order_comment->Timestamp = date('U');
         $order_comment->User = $user_id;
         $order_comment->Comment = $comments;
         $order_comment->Unique_Id = $last_id;
         $order_comment->save();
         //Adult ARV Preparations
         for ($i = 18; $i <= 42; $i++) {
             for ($j = 1; $j <= $highestColumm; $j++) {
             }
             $quantity_required_for_supply = $arr[$i]['L'];
             $drug_name = $arr[$i]['A'];
             if ($quantity_required_for_supply != 0) {
                 $drug_id = $drug_name;
                 $basic_unit = $arr[$i]['B'];
                 $beginning_balance = $arr[$i]['C'];
                 $quantity_received_in_period = $arr[$i]['D'];
                 $quantity_dispensed_in_period = $arr[$i]['E'];
                 $adjustments_to_other_facilities = $arr[$i]['G'];
                 $end_of_month_physical_count = $arr[$i]['H'];
                 $quantity_required_for_supply = $arr[$i]['L'];
                 $query = $this->db->query("SELECT MAX(id) AS id FROM cdrr_item");
                 $results = $query->result_array();
                 $last_id = $results[0]['id'];
                 $last_id++;
                 $last_id = md5($last_id . $facility_code);
                 $cdrr_query = $this->db->query("INSERT INTO cdrr_item (`id`, `balance`, `received`, `dispensed_units`, `dispensed_packs`, `losses`, `adjustments`, `count`, `resupply`, `aggr_consumed`, `aggr_on_hand`, `publish`, `cdrr_id`, `drug_id`,`unique_id`) VALUES (NULL, '{$beginning_balance}', '{$quantity_received_in_period}', '{$quantity_dispensed_in_period}', NULL, NULL, '{$adjustments_to_other_facilities}', '{$end_of_month_physical_count}', '{$quantity_required_for_supply}', NULL, NULL, '0', '{$facility_id}', '{$drug_id}','{$last_id}');");
             }
         }
         //Paediatric Preparations
         for ($i = 44; $i <= 76; $i++) {
             for ($j = 1; $j <= $highestColumm; $j++) {
             }
             $quantity_required_for_supply = $arr[$i]['L'];
             $drug_name = $arr[$i]['A'];
             if ($quantity_required_for_supply != 0) {
                 $drug_id = $drug_name;
                 $basic_unit = $arr[$i]['B'];
                 $beginning_balance = $arr[$i]['C'];
                 $quantity_received_in_period = $arr[$i]['D'];
                 $quantity_dispensed_in_period = $arr[$i]['E'];
                 $adjustments_to_other_facilities = $arr[$i]['G'];
                 $end_of_month_physical_count = $arr[$i]['H'];
                 $quantity_required_for_supply = $arr[$i]['L'];
                 $query = $this->db->query("SELECT MAX(id) AS id FROM cdrr_item");
                 $results = $query->result_array();
                 $last_id = $results[0]['id'];
                 $last_id++;
                 $last_id = md5($last_id . $facility_code);
                 $cdrr_query = $this->db->query("INSERT INTO cdrr_item (`id`, `balance`, `received`, `dispensed_units`, `dispensed_packs`, `losses`, `adjustments`, `count`, `resupply`, `aggr_consumed`, `aggr_on_hand`, `publish`, `cdrr_id`, `drug_id`,`unique_id`) VALUES (NULL, '{$beginning_balance}', '{$quantity_received_in_period}', '{$quantity_dispensed_in_period}', NULL, NULL, '{$adjustments_to_other_facilities}', '{$end_of_month_physical_count}', '{$quantity_required_for_supply}', NULL, NULL, '0', '{$facility_id}', '{$drug_id}','{$last_id}');");
             }
         }
         //Drugs for IOs
         for ($i = 78; $i <= 99; $i++) {
             for ($j = 1; $j <= $highestColumm; $j++) {
             }
             $quantity_required_for_supply = $arr[$i]['L'];
             $drug_name = $arr[$i]['A'];
             if ($quantity_required_for_supply != 0) {
                 $drug_id = $drug_name;
                 $basic_unit = $arr[$i]['B'];
                 $beginning_balance = $arr[$i]['C'];
                 $quantity_received_in_period = $arr[$i]['D'];
                 $quantity_dispensed_in_period = $arr[$i]['E'];
                 $adjustments_to_other_facilities = $arr[$i]['G'];
                 $end_of_month_physical_count = $arr[$i]['H'];
                 $quantity_required_for_supply = $arr[$i]['L'];
                 $query = $this->db->query("SELECT MAX(id) AS id FROM cdrr_item");
                 $results = $query->result_array();
                 $last_id = $results[0]['id'];
                 $last_id++;
                 $last_id = md5($last_id . $facility_code);
                 $cdrr_query = $this->db->query("INSERT INTO cdrr_item (`id`, `balance`, `received`, `dispensed_units`, `dispensed_packs`, `losses`, `adjustments`, `count`, `resupply`, `aggr_consumed`, `aggr_on_hand`, `publish`, `cdrr_id`, `drug_id`,`unique_id`) VALUES (NULL, '{$beginning_balance}', '{$quantity_received_in_period}', '{$quantity_dispensed_in_period}', NULL, NULL, '{$adjustments_to_other_facilities}', '{$end_of_month_physical_count}', '{$quantity_required_for_supply}', NULL, NULL, '0', '{$facility_id}', '{$drug_id}','{$last_id}');");
             }
         }
         //PMTCT Regimen 1.Pregnant Women
         for ($i = 19; $i <= 21; $i++) {
             for ($j = 19; $j <= $highestColumm; $j++) {
             }
             $regimen_code = $arr[$i]['S'];
             $regimen_desc = $arr[$i]['T'];
             $no_of_clients_dispensed_in_period = $arr[$i]['V'] . $arr[$i]['W'];
             if ($no_of_clients_dispensed_in_period) {
                 $regimen_id = $regimen_code . " | " . $regimen_desc;
                 $query = $this->db->query("SELECT MAX(id) AS id FROM maps_item");
                 $results = $query->result_array();
                 $last_id = $results[0]['id'];
                 $last_id++;
                 $last_id = md5($last_id . $facility_code);
                 $next_query = $this->db->query("INSERT INTO maps_item (`id`, `total`, `regimen_id`, `maps_id`,`unique_id`) VALUES (NULL, '{$no_of_clients_dispensed_in_period}', '{$regimen_id}', '{$facility_id}','{$last_id}');");
             }
         }
         //PMTCT Regimen 2.Infants
         for ($i = 23; $i <= 27; $i++) {
             for ($j = 19; $j <= $highestColumm; $j++) {
             }
             $regimen_code = $arr[$i]['S'];
             $regimen_desc = $arr[$i]['T'];
             $no_of_clients_dispensed_in_period = $arr[$i]['V'] . $arr[$i]['W'];
             if ($no_of_clients_dispensed_in_period) {
                 $this->load->database();
                 $regimen_id = $regimen_code . " | " . $regimen_desc;
                 $query = $this->db->query("SELECT MAX(id) AS id FROM maps_item");
                 $results = $query->result_array();
                 $last_id = $results[0]['id'];
                 $last_id++;
                 $last_id = md5($last_id . $facility_code);
                 $next_query = $this->db->query("INSERT INTO maps_item (`id`, `total`, `regimen_id`, `maps_id`,`unique_id`) VALUES (NULL, '{$no_of_clients_dispensed_in_period}', '{$regimen_id}', '{$facility_id}','{$last_id}');");
             }
         }
         //Adult ART First Line Regimens
         for ($i = 33; $i <= 43; $i++) {
             for ($j = 19; $j <= $highestColumm; $j++) {
             }
             $regimen_code = $arr[$i]['S'];
             $regimen_desc = $arr[$i]['T'];
             $no_of_clients_dispensed_in_period = $arr[$i]['V'] . $arr[$i]['W'];
             if ($no_of_clients_dispensed_in_period) {
                 $regimen_id = $regimen_code . " | " . $regimen_desc;
                 $query = $this->db->query("SELECT MAX(id) AS id FROM maps_item");
                 $results = $query->result_array();
                 $last_id = $results[0]['id'];
                 $last_id++;
                 $last_id = md5($last_id . $facility_code);
                 $next_query = $this->db->query("INSERT INTO maps_item (`id`, `total`, `regimen_id`, `maps_id`,`unique_id`) VALUES (NULL, '{$no_of_clients_dispensed_in_period}', '{$regimen_id}', '{$facility_id}','{$last_id}');");
             }
         }
         //Adult ART Second Line Regimens
         for ($i = 45; $i <= 58; $i++) {
             for ($j = 19; $j <= $highestColumm; $j++) {
             }
             $regimen_code = $arr[$i]['S'];
             $regimen_desc = $arr[$i]['T'];
             $no_of_clients_dispensed_in_period = $arr[$i]['V'] . $arr[$i]['W'];
             if ($no_of_clients_dispensed_in_period) {
                 $regimen_id = $regimen_code . " | " . $regimen_desc;
                 $query = $this->db->query("SELECT MAX(id) AS id FROM maps_item");
                 $results = $query->result_array();
                 $last_id = $results[0]['id'];
                 $last_id++;
                 $last_id = md5($last_id . $facility_code);
                 $next_query = $this->db->query("INSERT INTO maps_item (`id`, `total`, `regimen_id`, `maps_id`,`unique_id`) VALUES (NULL, '{$no_of_clients_dispensed_in_period}', '{$regimen_id}', '{$facility_id}','{$last_id}');");
             }
         }
         //Other Adult ART regimens
         for ($i = 60; $i <= 62; $i++) {
             for ($j = 19; $j <= $highestColumm; $j++) {
             }
             $regimen_code = $arr[$i]['S'];
             $regimen_desc = $arr[$i]['T'];
             $no_of_clients_dispensed_in_period = $arr[$i]['V'] . $arr[$i]['W'];
             if ($no_of_clients_dispensed_in_period) {
                 $regimen_id = $regimen_code . " | " . $regimen_desc;
                 $query = $this->db->query("SELECT MAX(id) AS id FROM maps_item");
                 $results = $query->result_array();
                 $last_id = $results[0]['id'];
                 $last_id++;
                 $last_id = md5($last_id . $facility_code);
                 $next_query = $this->db->query("INSERT INTO maps_item (`id`, `total`, `regimen_id`, `maps_id`,`unique_id`) VALUES (NULL, '{$no_of_clients_dispensed_in_period}', '{$regimen_id}', '{$facility_id}','{$last_id}');");
             }
         }
         //Paediatric ART First Line Regimens
         for ($i = 64; $i <= 74; $i++) {
             for ($j = 19; $j <= $highestColumm; $j++) {
             }
             $regimen_code = $arr[$i]['S'];
             $regimen_desc = $arr[$i]['T'];
             $no_of_clients_dispensed_in_period = $arr[$i]['V'] . $arr[$i]['W'];
             if ($no_of_clients_dispensed_in_period) {
                 $regimen_id = $regimen_code . " | " . $regimen_desc;
                 $query = $this->db->query("SELECT MAX(id) AS id FROM maps_item");
                 $results = $query->result_array();
                 $last_id = $results[0]['id'];
                 $last_id++;
                 $last_id = md5($last_id . $facility_code);
                 $next_query = $this->db->query("INSERT INTO maps_item (`id`, `total`, `regimen_id`, `maps_id`,`unique_id`) VALUES (NULL, '{$no_of_clients_dispensed_in_period}', '{$regimen_id}', '{$facility_id}','{$last_id}');");
             }
         }
         //Paediatric ART Second Line Regimens
         for ($i = 76; $i <= 84; $i++) {
             for ($j = 19; $j <= $highestColumm; $j++) {
             }
             $regimen_code = $arr[$i]['S'];
             $regimen_desc = $arr[$i]['T'];
             $no_of_clients_dispensed_in_period = $arr[$i]['V'] . $arr[$i]['W'];
             if ($no_of_clients_dispensed_in_period) {
                 $regimen_id = $regimen_code . " | " . $regimen_desc;
                 $query = $this->db->query("SELECT MAX(id) AS id FROM maps_item");
                 $results = $query->result_array();
                 $last_id = $results[0]['id'];
                 $last_id++;
                 $last_id = md5($last_id . $facility_code);
                 $next_query = $this->db->query("INSERT INTO maps_item (`id`, `total`, `regimen_id`, `maps_id`,`unique_id`) VALUES (NULL, '{$no_of_clients_dispensed_in_period}', '{$regimen_id}', '{$facility_id}','{$last_id}');");
             }
         }
         //Other Paediatric ART regimens
         for ($i = 86; $i <= 87; $i++) {
             for ($j = 19; $j <= $highestColumm; $j++) {
             }
             $regimen_code = $arr[$i]['S'];
             $regimen_desc = $arr[$i]['T'];
             $no_of_clients_dispensed_in_period = $arr[$i]['V'] . $arr[$i]['W'];
             if ($no_of_clients_dispensed_in_period) {
                 $regimen_id = $regimen_code . " | " . $regimen_desc;
                 $query = $this->db->query("SELECT MAX(id) AS id FROM maps_item");
                 $results = $query->result_array();
                 $last_id = $results[0]['id'];
                 $last_id++;
                 $last_id = md5($last_id . $facility_code);
                 $next_query = $this->db->query("INSERT INTO maps_item (`id`, `total`, `regimen_id`, `maps_id`,`unique_id`) VALUES (NULL, '{$no_of_clients_dispensed_in_period}', '{$regimen_id}', '{$facility_id}','{$last_id}');");
             }
         }
         //POST Exposure Prophylaxis(PEP)
         for ($i = 91; $i <= 99; $i++) {
             for ($j = 19; $j <= $highestColumm; $j++) {
             }
             $regimen_code = $arr[$i]['S'];
             $regimen_desc = $arr[$i]['T'];
             $no_of_clients_dispensed_in_period = $arr[$i]['V'] . $arr[$i]['W'];
             if ($no_of_clients_dispensed_in_period) {
                 $regimen_id = $regimen_code . " | " . $regimen_desc;
                 $query = $this->db->query("SELECT MAX(id) AS id FROM maps_item");
                 $results = $query->result_array();
                 $last_id = $results[0]['id'];
                 $last_id++;
                 $last_id = md5($last_id . $facility_code);
                 $next_query = $this->db->query("INSERT INTO maps_item (`id`, `total`, `regimen_id`, `maps_id`,`unique_id`) VALUES (NULL, '{$no_of_clients_dispensed_in_period}', '{$regimen_id}', '{$facility_id}','{$last_id}');");
             }
         }
         //ARV Data collection and Reporting Tools
         //1.Name of Data-DAR
         //a.ARVS Collection Tool
         $fifty_arv_page_requested = $arr[116]['D'];
         $three_hundred_arv_page_requested = $arr[116]['E'];
         if ($fifty_arv_page_requested) {
             $dar_arv_quantity_requested = $fifty_arv_page_requested;
         }
         if ($three_hundred_arv_page_requested) {
             $dar_arv_quantity_requested = $three_hundred_arv_page_requested;
         }
         //a.OIs Collection Tool
         $fifty_oi_page_requested = $arr[116]['G'];
         $three_hundred_oi_page_requested = $arr[116]['H'];
         if ($fifty_oi_page_requested) {
             $dar_oi_quantity_requested = $fifty_oi_page_requested;
         }
         if ($three_hundred_oi_page_requested) {
             $dar_oi_quantity_requested = $three_hundred_oi_page_requested;
         }
         //2.Name of Data-FCDRR
         $fcdrr_quantity_requested = $arr[116]['L'];
         //Prepared By details
         $report_prepared_by = $arr[119]['B'] . $arr[119]['C'] . $arr[119]['D'];
         $prepared_by_contact_telephone = $arr[121]['B'] . $arr[121]['C'] . $arr[121]['D'];
         $signature_prepared_by = $arr[119]['G'] . $arr[119]['H'] . $arr[119]['L'];
         $date_prepared_by_signature = $arr[121]['G'] . $arr[121]['H'];
         //Approved By details
         $report_approved_by = $arr[123]['B'] . $arr[123]['C'] . $arr[123]['D'];
         $approved_by_contact_telephone = $arr[126]['B'] . $arr[126]['C'] . $arr[126]['D'];
         $signature_approved_by = $arr[123]['G'] . $arr[123]['H'] . $arr[123]['L'];
         $date_approved_by_signature = $arr[126]['G'] . $arr[126]['H'];
         //$this -> session -> set_userdata('upload_counter','2');
         redirect("order_management/edit_order/{$order_number}");
     }
 }