public function commodity_listing() { $data['title'] = "Commodity Listing"; $data['banner_text'] = "Commodity Listing"; $data['content_view'] = "shared_files/commodities/commodity_list_v"; $data['commodity_list'] = commodities::get_all_with_suppliers(); $this->load->view('shared_files/template/template', $data); }
public function set_up_facility_stock() { $facility_code = $this->session->userdata('facility_id'); $data['title'] = "Set up facility stock"; $data['content_view'] = "facility/facility_stock_data/set_up_facility_stock_v"; $data['banner_text'] = "Set up facility stock"; $data['commodities'] = commodities::set_facility_stock_data_amc($facility_code); $this->load->view("shared_files/template/template", $data); }
public function update_stock_prices() { $inputFileName = 'print_docs/excel/excel_template/KEMSA Customer Order Form.xls'; // echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory to identify the format<br />'; $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); $commodities = commodities::get_all_2(); $system_commodity_details = array(); $excel_commodity_details = array(); $ate_hwat = array(); $temp = array(); $keys_na_si_alishia = array(); // echo "<pre>";print_r($commodities);echo "</pre>";exit; foreach ($commodities as $commodity) { $system_commodity_details[] = array('id' => $commodity['id'], 'commodity_code' => $commodity['commodity_code'], 'commodity_name' => $commodity['commodity_name']); } //end of foreach $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true); $sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); $highestColumn = $sheet->getHighestColumn(); // echo "<pre>";print_r($sheetData);echo "</pre>";exit; for ($row = 17; $row < $highestRow; $row++) { $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE); $excel_commodity_details[] = array('commodity_name' => $rowData[0][3], 'price' => $rowData[0][6], 'commodity_code' => $rowData[0][2]); } // echo "<pre>";print_r($excel_commodity_details);echo "</pre>";exit; // echo "<pre>";print_r($system_commodity_details);echo "</pre>";exit; $synthesised = array(); $unsynthesised = array(); foreach ($excel_commodity_details as $excels) { foreach ($system_commodity_details as $systems) { if ($excels['commodity_name'] == $systems['commodity_name']) { $synthesised[] = array('id' => $systems['id'], 'commodity_name' => $excels['name'], 'new_unit_price' => $excels['price'], 'commodity_code' => $excels['commodity_code']); } } } //end of foreach // echo "<pre>";print_r($synthesised);echo "</pre>";exit; $counter = 0; foreach ($synthesised as $synthesis) { if (isset($synthesis['commodity_code']) && $synthesis['commodity_code'] != '') { $details = array('commodity_code' => $synthesis['commodity_code']); $this->db->where('commodity_name', $synthesis['commodity_name']); $result = $this->db->update('commodities', $details); $counter = $counter + 1; echo "<pre>Commodity: " . $synthesis['id'] . " " . $synthesis['commodity_name'] . " Price: " . $synthesis['new_unit_price'] . " updated successfully</pre>"; } } $handler = array('unit_cost' => 0); $this->db->where('unit_cost', 'N/A'); $result = $this->db->update('commodities', $handler); echo "Total Queries: " . $counter; }
public function confirm_offline_issue() { $today = date('Y-m-d h:i:s'); $count = count($this->input->post('commodity_id')); $commodity_name = $this->input->post('commodity_name'); $commodity_id = $this->input->post('commodity_id'); $expiry_date = $this->input->post('expiry_date'); $manufacturer = $this->input->post('manufacturer'); $batch_no = $this->input->post('batch_no'); $total_commodity_units = $this->input->post('total_commodity_units'); $facility_code = $this->session->userdata('facility_id'); for ($i = 0; $i < $count; $i++) { $commodity_details = commodities::get_details_name($commodity_name[$i]); foreach ($commodity_details as $key => $value) { $new_commodity_id = $value['id']; $commodity_code = $value['commodity_code']; $unit_size = $value['pack_size']; $commodity_source_id = $value['commodity_source_id']; //Convert the Packs to Units $received_quantity = $total_commodity_units[$i]; //Check if batch exists in the facility stocks table $batch_details = facility_stocks::get_batch_details($batch_no[$i], $facility_code); //If the batch does not exits if (count($batch_details) <= 0) { $facility_stocks_data = array(array('facility_code' => $facility_code, 'commodity_id' => $new_commodity_id, 'batch_no' => $batch_no[$i], 'manufacture' => $manufacturer[$i], 'initial_quantity' => $received_quantity, 'current_balance' => $received_quantity, 'date_added' => $today, 'date_modified' => $today, 'source_of_commodity' => $commodity_source_id, 'status' => 1, 'expiry_date' => $expiry_date[$i])); // echo "<pre>";print_r($facility_stocks_data);die; $this->db->insert_batch('facility_stocks', $facility_stocks_data); } else { // echo "<pre>";print_r($batch_details);die; $current_balance = intval($batch_details[0]['current_balance']); $quantity_units = $total_commodity_units[$i]; $current_balance = $current_balance + intval($quantity_units); $facility_stocks_data_update = array('batch_no' => $batch_no[$i], 'current_balance' => $current_balance, 'date_modified' => $today, 'expiry_date' => $expiry_date[$i]); // echo "<pre>";print_r($facility_stocks_data_update);die; $this->db->where('batch_no', $batch_no[$i]); $this->db->where('facility_code', $facility_code); $this->db->update('facility_stocks', $facility_stocks_data_update); //Above code updates the facility Stocks table if the batch exists } } $receive_redistribution_data_update = array('batch_no' => $batch_no[$i], 'status' => 0); $this->db->where('batch_no', $batch_no[$i]); $this->db->where('status', 1); $this->db->where('facility_code', $facility_code); $this->db->update('receive_redistributions', $receive_redistribution_data_update); } $this->session->set_flashdata('system_success_message', "Redistribution Data Has Been Updated"); redirect('home'); }
public function clone_redistribution_template($file_name = null) { $inputFileName = 'print_docs/excel/excel_template/Facility_redistributions.xlsx'; $commodities = commodities::get_all(); $excel2 = PHPExcel_IOFactory::createReader('Excel2007'); $excel2 = $excel2->load($inputFileName); // Empty Sheet $excel2->setActiveSheetIndex(1); $count = 1; foreach ($commodities as $key => $value) { $count++; $row = 'A' . $count; $commodity = $value['commodity_name']; $excel2->getActiveSheet()->setCellValue($row, $commodity); } $file_name = isset($file_name) ? $file_name : time() . '.xlsx'; $objWriter = PHPExcel_IOFactory::createWriter($excel2, 'Excel2007'); $excel2->setActiveSheetIndex(0); for ($i = 12; $i < 2000; $i++) { $cell = 'B' . $i; // Set data validation $objValidation = $excel2->getActiveSheet()->getCell($cell)->getDataValidation(); $objValidation->setType(PHPExcel_Cell_DataValidation::TYPE_LIST); $objValidation->setErrorStyle(PHPExcel_Cell_DataValidation::STYLE_INFORMATION); $objValidation->setAllowBlank(false); $objValidation->setShowInputMessage(true); $objValidation->setShowErrorMessage(true); $objValidation->setShowDropDown(true); $objValidation->setErrorTitle('Input error'); $objValidation->setError('Commodity is not In the List'); $objValidation->setPromptTitle('Pick from list'); $objValidation->setPrompt('Please pick a Commodity from the drop-down list'); $objValidation->setFormula1('\'Commodities\'!$A$2:$A$5000'); } ob_end_clean(); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); header("Content-Disposition: attachment; filename={$file_name}"); $objWriter->save('php://output'); $excel2->disconnectWorksheets(); unset($excel2); }
public function setup_commodities() { $facility_code = $this->session->userdata('facility_id'); $data['title'] = "Dispensing - Set up Service Point stock"; $data['content_view'] = "facility/facility_dispensing/setup_facility_stock_v"; $data['banner_text'] = "Set up service point stock"; $data['commodities'] = commodities::set_facility_service_data($facility_code, 2); $this->load->view("shared_files/template/template", $data); }