public function listing() { $access_level = $this->session->userdata('user_indicator'); $source = 0; if ($access_level == "pharmacist") { $source = $this->session->userdata('facility'); } $data = array(); $drugcodes = Drugcode::getAll($source, $access_level); $tmpl = array('table_open' => '<table id="drugcode_setting" class="setting_table table table-bordered table-striped">'); $this->table->set_template($tmpl); $this->table->set_heading('id', 'Drug', 'Unit', 'Dose', 'Supplier', 'Options'); foreach ($drugcodes as $drugcode) { $array_param = array('id' => $drugcode['id'], 'role' => 'button', 'class' => 'edit_user', 'data-toggle' => 'modal'); $links = ""; if ($drugcode['Enabled'] == 1) { $links .= anchor('#edit_drugcode', 'Edit', $array_param); } $drug = $drugcode['id']; if ($drugcode['Enabled'] == 1 && $access_level == "facility_administrator") { $links .= " | "; $links .= anchor('drugcode_management/disable/' . $drugcode['id'], 'Disable', array('class' => 'disable_user')); $links .= " | "; $links .= "<a href='#' class='merge_drug' id='{$drug}'>Merge</a>"; } elseif ($access_level == "facility_administrator") { $links .= anchor('drugcode_management/enable/' . $drugcode['id'], 'Enable', array('class' => 'enable_user')); } if ($drugcode['Merged_To'] != '') { if ($access_level == "facility_administrator") { $links .= " | "; $links .= anchor('drugcode_management/unmerge/' . $drugcode['id'], 'Unmerge', array('class' => 'unmerge_drug')); } $checkbox = "<input type='checkbox' name='drugcodes' id='drugcodes' class='drugcodes' value='{$drug}' disabled/>"; } else { $checkbox = "<input type='checkbox' name='drugcodes' id='drugcodes' class='drugcodes' value='{$drug}'/>"; } $mapped = ""; if ($drugcode['map'] != 0) { $mapped = "<b>(mapped)</b>"; } $this->table->add_row($drugcode['id'], $checkbox . " " . strtoupper($drugcode['Drug']) . " " . $mapped, "<b>" . $drugcode['drug_unit'] . "</b>", "<b>" . $drugcode['Dose'] . "</b>", "<b>" . $drugcode['supplier'] . "</b>", $links); } $data['drugcodes'] = $this->table->generate(); $data['suppliers'] = Drug_Source::getAllHydrated(); $data['classifications'] = Drug_Classification::getAllHydrated($access_level, "0"); $query = $this->db->query("SELECT s.id,CONCAT_WS('] ',CONCAT_WS(' [',s.name,s.abbreviation),CONCAT_WS(' | ',s.strength,s.formulation)) as name,s.packsize\n FROM sync_drug s \n WHERE s.id NOT IN(SELECT dc.map\n FROM drugcode dc\n WHERE dc.map !='0')\n AND (s.category_id='1' or s.category_id='2' or s.category_id='3')\n ORDER BY name asc"); $data['edit_mappings'] = $query->result_array(); $data['mappings'] = Sync_Drug::getActive(); $data['instructions'] = Drug_instructions::getAllInstructions(); $this->base_params($data); }
public function stock_transaction($stock_type = 1) { $data['hide_side_menu'] = 1; $facility_code = $this->session->userdata('facility'); $user_id = $this->session->userdata('user_id'); $access_level = $this->session->userdata('user_indicator'); if ($access_level == "facility_administrator") { $transaction_type = Transaction_Type::getAll(); } else { $transaction_type = Transaction_Type::getAllNonAdjustments(); } $drug_source = Drug_Source::getAll(); $facility_detail = facilities::getSupplier($facility_code); $drug_destination = Drug_Destination::getAll(); //Check facility type(satelitte, standalone or central) $facility_type = Facilities::getType($facility_code); $get_list = array(); $data['list_facility'] = ""; if ($facility_type == 0) { //Satellite $central_code = facilities::getCentralCode($facility_code); $get_list = facilities::getCentralName($central_code); $data['list_facility'] = "Central Site"; } else { if ($facility_type == 1) { //Standalone $get_list = array(); $data['list_facility'] = ""; } else { if ($facility_type > 1) { //Central $get_list = facilities::getSatellites($facility_code); $data['list_facility'] = "Satelitte Sites"; } } } $name = CCC_store_service_point::getCCC($stock_type); $name = $name['Name']; $data['supplier_name'] = $facility_detail->supplier->name; $data['picking_lists'] = ""; $data['get_list'] = $get_list; $data['user_id'] = $user_id; $data['facility'] = $facility_code; $data['stock_type'] = $stock_type; $data['transaction_types'] = $transaction_type; $data['drug_sources'] = $drug_source; $data['drug_destinations'] = $drug_destination; $data['store'] = strtoupper($name); $data['content_view'] = "stock_transaction_v"; $this->base_params($data); }
public function getDrugsReceived_old($stock_type, $start_date = "", $end_date = "") { $data['from'] = $start_date; $data['to'] = $end_date; $start_date = date('Y-m-d', strtotime($start_date)); $end_date = date('Y-m-d', strtotime($end_date)); $facility_code = $this->session->userdata('facility'); $facilty_value = ""; $param = ""; $facilty_value = "dsm.ccc_store_sp={$stock_type}"; $ccc = CCC_store_service_point::getCCC($stock_type); $data['transaction_type'] = $ccc['Name']; $sql = "select d.id,d.drug,du.Name as unit,d.pack_size,SUM(dsm.quantity) as total from drug_stock_movement dsm \n\t\t\t\tLEFT JOIN transaction_type t ON t.id=dsm.transaction_type \n\t\t\t\tLEFT JOIN drugcode d ON d.id=dsm.drug \n\t\t\t\tLEFT JOIN drug_unit du ON du.id=d.unit \n\t\t\t\twhere dsm.transaction_date between '{$start_date}' and '{$end_date}' and {$facilty_value} and dsm.facility='{$facility_code}' \n\t\t\t\tAND t.name LIKE '%Received%' AND d.id IS NOT NULL GROUP BY d.drug"; //echo $sql;die(); $query = $this->db->query($sql); $source_array = Drug_Source::getAllHydrate(); $all_other_ccc_stores = CCC_store_service_point::getAllBut($stock_type); $dyn_table = "<table border='1' class='dataTables' cellpadding='5'>"; $dyn_table .= "<thead>\n\t\t\t\t\t\t<tr><th>Drug Name</th>\n\t\t\t\t\t"; $source_array = array_merge($all_other_ccc_stores, $source_array); //echo json_encode($dest_array);die(); foreach ($source_array as $value) { $dyn_table .= "<th>" . $value['Name'] . "</th>"; } $dyn_table .= "</tr>\n\t\t\t\t\t\t</thead>\n\t\t\t\t\t\t<tbody>"; $results = $query->result_array(); if ($results) { foreach ($results as $result) { $dyn_table .= "<tr><td>" . $result['drug'] . "</td>"; //Get all destinations for that drug $get_drugs = "\n\t\t\t \t\t\tSELECT table1.name,table1.total FROM\n\t\t\t \t\t\t(\n\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tSELECT csp.name as name,temp.total \n\t\t\t\t\t FROM ccc_store_service_point csp\n\t\t\t\t\t LEFT JOIN \n\t\t\t\t\t (SELECT source_destination,SUM(dsm.quantity) as total \n\t\t\t\t\t \t FROM drug_stock_movement dsm \n\t\t\t\t\t \t LEFT JOIN transaction_type t ON t.id=dsm.transaction_type \n\t\t\t\t\t \t LEFT JOIN drugcode d ON d.id=dsm.drug \n\t\t\t\t\t \t LEFT JOIN drug_unit du ON du.id=d.unit \n\t\t\t\t\t \t WHERE dsm.transaction_date \n\t\t\t\t\t \t BETWEEN '{$start_date}' \n\t\t\t\t\t \t AND '{$end_date}' \n\t\t\t\t\t \t AND {$facilty_value} \n\t\t\t\t\t \t AND t.name LIKE '%received%' \n\t\t\t\t\t \t AND dsm.drug='" . $result['id'] . "' \n\t\t\t\t\t \t GROUP BY source_destination) as temp ON temp.source_destination = csp.name\n\t\t\t\t\t \t \n\t\t\t\t\t WHERE csp.id !={$stock_type} AND csp.active = 1 \n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tUNION ALL\n\t\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tSELECT des.name as name,temp.total \n\t\t\t\t\t FROM drug_source des \n\t\t\t\t\t LEFT JOIN (SELECT source_destination,SUM(dsm.quantity) as total \n\t\t\t\t\t \t FROM drug_stock_movement dsm \n\t\t\t\t\t \t LEFT JOIN transaction_type t ON t.id=dsm.transaction_type \n\t\t\t\t\t \t LEFT JOIN drugcode d ON d.id=dsm.drug \n\t\t\t\t\t \t LEFT JOIN drug_unit du ON du.id=d.unit \n\t\t\t\t\t \t WHERE dsm.transaction_date \n\t\t\t\t\t \t BETWEEN '{$start_date}' \n\t\t\t\t\t \t AND '{$end_date}' \n\t\t\t\t\t \t AND {$facilty_value} \n\t\t\t\t\t \t AND t.name LIKE '%received%' \n\t\t\t\t\t \t AND dsm.drug='" . $result['id'] . "' \n\t\t\t\t\t \t GROUP BY source_destination) as temp ON temp.source_destination=des.id \n\t\t\t\t\t \t WHERE des.active=1\n\t ORDER BY des.id ASC\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t) as table1\n\t\t\t \t\t\t"; //echo $get_drugs;die(); $get_dest = $this->db->query($get_drugs); $get_des_array = $get_dest->result_array(); if ($get_des_array) { foreach ($get_des_array as $value) { $total = $value['total']; if ($value['total'] == null) { $total = 0; } $dyn_table .= "<td>" . $total . "</td>"; } } $dyn_table .= "</tr>"; } } else { //$dyn_table .= "<tr><td colspan='4'>No Data Available</td></tr>"; } $dyn_table .= "</tbody></table>"; $data['dyn_table'] = $dyn_table; $data['title'] = "webADT | Reports"; $data['hide_side_menu'] = 1; $data['banner_text'] = "Facility Reports"; $data['selected_report_type_link'] = "drug_inventory_report_row"; $data['selected_report_type'] = "Stock Consumption"; $data['report_title'] = "Stock Consumption"; $data['facility_name'] = $this->session->userdata('facility_name'); $data['content_view'] = 'reports/drugreceived_v'; $this->load->view('template', $data); }
public function disable($source_id) { $this->load->database(); $query = $this->db->query("UPDATE drug_source SET Active='0'WHERE id='{$source_id}'"); $results = Drug_Source::getSource($source_id); //$this -> session -> set_userdata('message_counter','2'); $this->session->set_userdata('msg_error', $results->Name . ' was disabled!'); $this->session->set_flashdata('filter_datatable', $results->Name); //Filter datatable redirect('settings_management'); }