예제 #1
0
 public function aggragate_order_new_sorf($order_id)
 {
     $order_id_array = explode("_", $order_id);
     $facility_name = array();
     $order_id = array();
     $order_total = array("", "", "", "");
     $order_total_all = 0;
     $order_total_all_items = 0;
     foreach ($order_id_array as $single_order_id) {
         //get the facility names from the orders
         if ($single_order_id > 0) {
             $test = facility_orders::get_order_($single_order_id);
             $order_id = array_merge($order_id, array($single_order_id));
             foreach ($test as $test_) {
                 $order_total = array_merge($order_total, array("", $test_->order_total));
                 $order_total_all = $order_total_all + $test_->order_total;
                 foreach ($test_->facility_detail as $facility_data) {
                     array_push($facility_name, "{$facility_data->facility_name}", '');
                 }
             }
         }
     }
     array_push($order_total, $order_total_all);
     array_push($facility_name, "TOTAL");
     //combine all of them
     $stock_data = Commodities::get_all_from_supllier(1);
     $from_stock_data = count($stock_data);
     //get items from a supplier
     $excel_data = array('doc_creator' => "HCMP", 'doc_title' => 'test ', 'file_name' => 'test');
     $row_data = array(array("Product Code", "Item description(Name/form/strength)", "Order unit size", "Price"));
     foreach ($order_id as $order_id_) {
         array_push($row_data[0], "Quantity  to Order", "Total");
         //push this to go with each facility
     }
     $column_data = array("", "", "FACILITY NAME", "");
     $column_data = array_merge($column_data, $facility_name);
     $excel_data['column_data'] = $column_data;
     for ($i = 0; $i < $from_stock_data; $i++) {
         $total_all = 0;
         $temp_array = array();
         $temp_array_ = array();
         if ($i == 0) {
             //push the first sub category
             array_push($row_data, array($stock_data[$i]["sub_category_name"], "", "", "", ""));
         } else {
             if ($stock_data[$i]['sub_category_name'] != $stock_data[$i - 1]['sub_category_name']) {
                 //push the first sub category
                 array_push($row_data, array($stock_data[$i]["sub_category_name"], "", "", "", ""));
             }
         }
         foreach ($order_id as $order_id_) {
             $total = facility_order_details::get_order_details_from_order($order_id_, $stock_data[$i]["commodity_id"]);
             if (count($total) == 0) {
                 array_push($temp_array, 0, 0);
             } else {
                 $total_ = $total[0]['total'] * str_replace(",", '', $stock_data[$i]["unit_cost"]);
                 array_push($temp_array, $total[0]['total'], $total_);
                 $total_all = $total_all + $total_;
                 $order_total_all_items = $order_total_all_items + $total_;
             }
         }
         $temp_array_ = array($stock_data[$i]["commodity_code"], $stock_data[$i]["commodity_name"], $stock_data[$i]["unit_size"], $stock_data[$i]["unit_cost"]);
         $temp_array_ = array_merge($temp_array_, $temp_array);
         array_push($temp_array_, $total_all);
         array_push($row_data, $temp_array_);
     }
     array_push($row_data, $order_total);
     $excel_data['row_data'] = $row_data;
     $this->hcmp_functions->create_excel($excel_data);
 }