public function update_order_facility($source = NULL) { //karsanrichard //security check // $dump=$this -> input -> post(); // echo '<pre>';print_r($dump); echo '</pre>';exit; $user_indicator = $this->session->userdata('user_indicator'); if ($this->input->post('commodity_id')) { //just picks values from the view and assigns them to a variable $this->load->database(); $data_array = array(); $rejected = $this->input->post('rejected'); $rejected_admin = $this->input->post('rejected_admin'); $approved_admin = $this->input->post('approved_admin'); $commodity_id = $this->input->post('commodity_id'); //order details table details $quantity_ordered_pack = $this->input->post('quantity'); $order_id = $this->input->post('order_number'); $facility_order_details_id = $this->input->post('facility_order_details_id'); $quantity_ordered_unit = $this->input->post('actual_quantity'); (int) ($price = $this->input->post('price')); $o_balance = $this->input->post('open'); $t_receipts = $this->input->post('receipts'); $t_issues = $this->input->post('issues'); $adjustpve = $this->input->post('adjustmentpve'); $adjustnve = $this->input->post('adjustmentnve'); $losses = $this->input->post('losses'); $days = $this->input->post('days'); $c_stock = $this->input->post('closing'); //$comment = array('N/A','N/A','N/A'); $s_quantity = $this->input->post('suggested'); (int) ($amc = $this->input->post('amc')); $workload = '0'; //order table details $bed_capacity = '0'; $drawing_rights = '0'; // $order_total = $this -> input -> post('total_order_value'); $order_total_ = facility_orders::get_order_cost($order_id); $order_total = $order_total_[0]['order_total']; // echo "<pre>";print_r($order_total);exit; $order_no = '0'; //$facility_code=$this -> session -> userdata('facility_id'); //$user_id=$this->session->userdata('user_id'); $order_date = date('y-m-d'); $number_of_id = count($commodity_id); $order_dates = facility_orders::get_order_($order_id); //echo '<pre>';print_r($order_dates[0]['order_date']); echo '</pre>';exit; $subject = $file_name = $title = $info = $attach_file = null; for ($i = 0; $i < $number_of_id; $i++) { if ($user_indicator == 'county') { $column_packs = 'cty_qty_packs'; $column_units = 'cty_qty_units'; $user_ind = 'county'; } else { if ($user_indicator == 'district') { $column_packs = 'scp_qty_packs'; $column_units = 'scp_qty_units'; $user_ind = 'subcounty'; } else { $column_packs = 'quantity_ordered_pack'; $column_units = 'quantity_ordered_unit'; $user_ind = 'subcounty'; } } $orders = Doctrine_Manager::getInstance()->getCurrentConnection()->execute("INSERT INTO facility_order_details ( \n\t\t\t\t\t`id`,\n\t\t\t\t\t`order_number_id`,\n\t\t\t\t\t`commodity_id`,\n\t\t\t\t\t`{$column_packs}`,\n\t\t\t\t\t`{$column_units}`,\n\t\t\t\t\t`price`,\n\t\t\t\t\t`o_balance`,\n\t\t\t\t\t`t_receipts`,\n\t\t\t\t\t`t_issues`,\n\t\t\t\t\t`adjustpve`,\n\t\t\t\t\t`losses`,\n\t\t\t\t\t`days`,\n\t\t\t\t\t`comment`,\n\t\t\t\t\t`c_stock`,\n\t\t\t\t\t`amc`,\n\t\t\t\t\t`adjustnve`,\n\t\t\t\t\t`source`)\n\t\t\t\t\tVALUES ({$facility_order_details_id[$i]},\n\t\t\t\t\t{$order_id},\n\t\t\t\t\t{$commodity_id[$i]},\n\t\t\t\t\t{$quantity_ordered_pack[$i]},\n\t\t\t\t\t{$quantity_ordered_unit[$i]},\n\t\t\t\t\t0,\n\t\t\t\t\t{$o_balance[$i]},\n\t\t\t\t\t{$t_receipts[$i]},\n\t\t\t\t\t{$t_issues[$i]},\n\t\t\t\t\t{$adjustpve[$i]},\n\t\t\t\t\t{$losses[$i]},\n\t\t\t\t\t{$days[$i]},\n\t\t\t\t\t'{$comment[$i]}',\n\t\t\t\t\t{$c_stock[$i]},\n\t\t\t\t\t{$amc[$i]},\n\t\t\t\t\t{$adjustnve[$i]},\n\t\t\t\t\t{$source}\n\t\t\t\t\t)\n\t\t\t\t\tON DUPLICATE KEY UPDATE\n\t\t\t\t\t`commodity_id`={$commodity_id[$i]},\n\t\t\t\t\t`{$column_packs}`={$quantity_ordered_pack[$i]},\n\t\t\t\t\t`{$column_units}`={$quantity_ordered_unit[$i]},\n\t\t\t\t\t`price`=0,\n\t\t\t\t\t`o_balance`={$o_balance[$i]},\n\t\t\t\t\t`t_receipts`={$t_receipts[$i]},\n\t\t\t\t\t`t_issues`={$t_issues[$i]},\n\t\t\t\t\t`adjustpve`={$adjustpve[$i]},\n\t\t\t\t\t`adjustnve`={$adjustnve[$i]},\n\t\t\t\t\t`losses`={$losses[$i]},\n\t\t\t\t\t`days`={$days[$i]},\n\t\t\t\t\t`c_stock`={$c_stock[$i]},\n\t\t\t\t\t`comment`='{$comment[$i]}',\n\t\t\t\t\t`amc`={$amc[$i]},\n\t\t\t\t\t`order_number_id`={$order_id};"); } //insert the data here // $orders = Doctrine_Manager::getInstance() -> getCurrentConnection() -> execute("UPDATE `facility_orders` SET `order_total` = $order_total,`order_no` = $order_no // ,`workload` = $workload ,`bed_capacity` = $bed_capacity WHERE `facility_orders`.`id` = $order_id;"); $myobj = Doctrine::getTable('facility_orders')->find($order_id); $myobj->workload = $workload; $myobj->bed_capacity = $bed_capacity; $myobj->order_no = $order_no; $myobj->order_total = $order_total; $facility_code = $myobj->facility_code; $myobj1 = Doctrine::getTable('Facilities')->findOneByfacility_code($facility_code); $facility_name = $myobj1->facility_name; //$pdf_body = $this -> create_order_pdf_template($order_id); $file_name = $facility_name . '_facility_order_no_' . $order_id . "_date_created_" . date('d-m-y'); //$pdf_data = array("pdf_title" => "Order Report For $facility_name", 'pdf_html_body' => $pdf_body, 'pdf_view_option' => 'save_file', 'file_name' => $file_name); //$this -> hcmp_functions -> create_pdf($pdf_data); // create pdf $this->hcmp_functions->clone_excel_order_template($order_id, 'save_file', $file_name); //create excel //$attach_file1 = './pdf/' . $file_name . '.pdf'; $attach_file = "./print_docs/excel/excel_files/" . $file_name . '.xls'; //echo $attach_file; //exit; if ($rejected == 1) { $myobj->status = 1; $status = "Updated"; $subject = 'Updated Order Report Pending Approval For ' . $facility_name; //$attach_file = './pdf/' . $file_name . '.pdf'; } if ($rejected_admin == 1) { $myobj->status = 3; $status = "Rejected"; $subject = 'Rejected Order Report For ' . $facility_name; $info = '<br> Note the order for ' . $facility_name . ' Has been rejected by ' . $approve_name1 . ' ' . $approve_name2 . '. <br> Find the attached order, correct it <br>'; } //final approval send to supplier if ($approved_admin == 1) { if ($user_indicator == 'county') { //get dates here $myobj->status = 2; $tabledata = '<thead> <tr style=""> <th>Date Ordered</th> <th>Date Approved Sub-County</th> <th>Date Approved County</th> <th>Order Value</th> </tr> </thead> <tbody > <tr> <td style="text-align:center;">' . date('M , d Y', strtotime($order_dates[0]['order_date'])) . '</td> <td style="text-align:center;">' . date('M , d Y', strtotime($order_dates[0]['approval_date'])) . '</td> <td style="text-align:center;">' . date('M , d Y') . '</td> <td style="text-align:center;" >Ksh ' . number_format("{$order_total}", 2) . '</td> </tr> </tbody>'; $subject = 'Approved Order For ' . $facility_name; $myobj->approval_county = date('y-m-d'); // echo "<pre> ".$subject." ".$tabledata;exit; } else { if ($user_indicator == 'district') { //get dates here $myobj->status = 6; $tabledata = '<thead> <tr style=""> <th>Date Ordered</th> <th>Date Approved Sub-County</th> <th>Order Value</th> </tr> </thead> <tbody > <tr> <td style="text-align:center;">' . date('M , d Y', strtotime($order_dates[0]['order_date'])) . '</td> <td style="text-align:center;">' . date('M , d Y') . '</td> <td style="text-align:center;" >Ksh ' . number_format("{$order_total}", 2) . '</td> </tr> </tbody>'; $subject = 'Order Pending Approval By County Pharmacist ' . $facility_name; $myobj->approval_date = date('y-m-d'); } } $myobj->approved_by = $this->session->userdata('user_id'); $status = "Approved"; //$subject = 'Approved Order Report For ' . $facility_name; } $myobj->save(); $message = ' <br> Please find the ' . $status . ' Order Made by ' . $facility_name . ' attached. <br> <table width="75%" style="text-align:center;" > ' . $tabledata . ' </table> <br> '; // echo $tabledata;exit; // $response = $this -> hcmp_functions -> send_order_approval_email($message, $subject, $attach_file, $facility_code, $status); if ($response) { delete_files($attach_file); } else { } //Test for sms //$this -> hcmp_functions -> order_update_sms($this -> session -> userdata('facility_id'),$status); $this->session->set_flashdata('system_success_message', "Facility Order No {$order_id} has Been {$status}"); redirect("reports/order_listing/{$user_ind}"); } }