<?php
if (!defined('BASEPATH')) 
	exit('No direct script access allowed');

class api extends CI_Controller{
	
	public function __construct(){
        parent::__construct();
		$this->load->helper('train');
		$this->load->model("BIZ_train_model");
		$this->load->model("train_system_model");
		$this->load->model("Sendmail_model"); 
    }
	
	public function index(){
		echo 'api manager';
	}
	
	public function checkOrderTime($coli_id=null){
		if(empty($coli_id)){
			exit('error null');
		}else{
			$orderInfo = $this->BIZ_train_model->getAllColdSn($coli_id);
			if(empty($orderInfo)){
				exit('error null');
			}else{
				$returnData = array();
				$returnData['orderList'] = array();
				foreach ($orderInfo as $items){
					$coldSn = $items->cold_sn;
					$trainOrderInfo = $this->train_system_model->get_ticketinfos($coldSn);
					if(empty($trainOrderInfo)){
						continue;
					}else{
						$data = new stdCLass();
						$htOrderInfo = $this->BIZ_train_model->biz_order_detail($coldSn);
						$data->coldSn = $coldSn;
						$data->htDepartureTime = date('Y-m-d H:i:s',strtotime($htOrderInfo->DepartureTime));
						if($trainOrderInfo->ts_channel == 'juhe'){
							$post_data=array(
								"key"=>"79f03107b921ef31310bd40a1415c1cb",
								"orderid"=>$trainOrderInfo->ts_ordernumber
							); 	
							$juheOrderDetail = json_decode(GetPost_http('http://op.juhe.cn/trainTickets/orderStatus',$post_data));
							//print_r($juheOrderDetail);
							$data->trainStartTime = $juheOrderDetail->result->start_time;
						}else{
							$data->trainStartTime = $trainOrderInfo->ts_startdate.' '.$trainOrderInfo->ts_startime;
						}
						
						array_push($returnData['orderList'],$data);
					}
				}
				print_r(json_encode($returnData));
			}
		}
	}
	
	//获取订单出票状态  
	public function isbooktickets(){
		$orderIdListStr = $this->input->get('orderIdListStr');
		if($orderIdListStr == ''){
			exit('数据为空！');
		}
		
		$orderData = explode(',',$orderIdListStr);
		
		//$orderData = ['2005075526','2004125562','2005055512','2003305598'];
		
		$returnData = new stdCLass();
		$returnData->pending = array();
		$returnData->processing = array();
		$returnData->confirmed = array();
		
		if(!empty($orderData)){
			foreach($orderData as $itemId){
				$orderInfo = new stdCLass();
				$doTicketsNum = 0;
				$orderInfo->coliId = $itemId;
				$priceInfo = $this->BIZ_train_model->get_paypal($itemId);
				$orderInfo->totalPrice = (int) $priceInfo->COLI_Price;
				
				$orderInfo->itinerary = array();
				
				$coldSnArr = $this->BIZ_train_model->getAllColdSn($itemId);
				$itineraryNums = count($coldSnArr);
				
				if(empty($priceInfo->GAI_SQJE)){
					$orderInfo->topstatus = 'pending';
					foreach ($coldSnArr as $keyColdSn=>$itemColdSn){
						$train_info = $this->BIZ_train_model->biz_order_detail($itemColdSn->cold_sn);
						
						$today = time();
						if(strtotime($itemColdSn->COLI_ApplyDate) - $today < 259200){
							$orderInfo->totalPrice = $orderInfo->totalPrice - 0;
							continue;
						}
						
						$orderInfo->itinerary[$keyColdSn] = new stdClass();
						$orderInfo->itinerary[$keyColdSn]->coldSn = $train_info->FOI_COLD_SN;
						$orderInfo->itinerary[$keyColdSn]->departureCity = $train_info->DepartureCity;
						$orderInfo->itinerary[$keyColdSn]->arrivalCity = $train_info->ArrivalCity;
						$orderInfo->itinerary[$keyColdSn]->departureDate = date('Y-m-d',strtotime($train_info->DepartureDate));
						$orderInfo->itinerary[$keyColdSn]->departureTime = date('H:i',strtotime($train_info->DepartureTime));
						$orderInfo->itinerary[$keyColdSn]->arrivalTime = date('H:i',strtotime($train_info->ArrivalTime));
						$orderInfo->itinerary[$keyColdSn]->Cabin = $train_info->Cabin;
						$orderInfo->itinerary[$keyColdSn]->FlightsNo = $train_info->FlightsNo;
						$orderInfo->itinerary[$keyColdSn]->passagerInfos = $this->BIZ_train_model->biz_people($itemColdSn->cold_sn);
						array_push($returnData->pending,$orderInfo);
					}
					
				}else{
					foreach ($coldSnArr as $keyColdSn=>$itemColdSn){
						$train_info = $this->BIZ_train_model->biz_order_detail($itemColdSn->cold_sn);
						
						$orderInfo->itinerary[$keyColdSn] = new stdClass();
						$orderInfo->itinerary[$keyColdSn]->coldSn = $train_info->FOI_COLD_SN;
						$orderInfo->itinerary[$keyColdSn]->departureCity = $train_info->DepartureCity;
						$orderInfo->itinerary[$keyColdSn]->arrivalCity = $train_info->ArrivalCity;
						$orderInfo->itinerary[$keyColdSn]->departureDate = date('Y-m-d',strtotime($train_info->DepartureDate));
						$orderInfo->itinerary[$keyColdSn]->departureTime = date('H:i',strtotime($train_info->DepartureTime));
						$orderInfo->itinerary[$keyColdSn]->arrivalTime = date('H:i',strtotime($train_info->ArrivalTime));
						$orderInfo->itinerary[$keyColdSn]->Cabin = $train_info->Cabin;
						$orderInfo->itinerary[$keyColdSn]->FlightsNo = $train_info->FlightsNo;
						$orderInfo->itinerary[$keyColdSn]->passagerInfos = $this->BIZ_train_model->biz_people($itemColdSn->cold_sn);
						$ticketinfo = $this->train_system_model->get_tickets_info($itemColdSn->cold_sn);
						
						if(!empty($ticketinfo)){
							//获取子订单出票状态
							$doTicketsNum++;
							$orderInfo->itinerary[$keyColdSn]->status = $ticketinfo->ts_status;
							$orderInfo->itinerary[$keyColdSn]->elecnumber = $ticketinfo->ts_elecnumber;
							$orderInfo->itinerary[$keyColdSn]->seatsinfo = $ticketinfo->ts_seatsinfo;
						}
					}

					if($doTicketsNum == $itineraryNums){
						$orderInfo->topstatus = 'confirmed';
						array_push($returnData->confirmed,$orderInfo);
					}elseif($doTicketsNum < $itineraryNums){
						$orderInfo->topstatus = 'processing';
						array_push($returnData->processing,$orderInfo);
					}
				}
			}
			print_r(json_encode($returnData));
		}
	}
	
	//用于自动发送确认信
	public function send_confirmmail(){
		die();
		//log_message('error','auto sendmail');
		$mailarr = $this->BIZ_train_model->auto_sendmail();
		foreach($mailarr as $obj){
			$coli_id = $this->BIZ_train_model->cold_sn_get_coli_id($obj->ts_cold_sn);
			$coli_id = $coli_id[0]->COLI_ID;
			$juhe_order = $obj->ts_ordernumber;
			$this->send_mail_to_guest($coli_id,$juhe_order);
		}
	}
	
	//发邮件给客人
    function send_mail_to_guest($coli_id,$jh_order){
		$info = $this->BIZ_train_model->get_user_info($jh_order);
        $guest = $this->BIZ_train_model->get_guest_info($coli_id);
		$operator_info = $this->BIZ_train_model->get_operatorInfo($coli_id);
		$fromName = $operator_info[0]->Name;
		$fromEmail = $operator_info[0]->OPI_Email;
        $toName = $guest[0]->GUT_LastName.$guest[0]->GUT_FirstName;
        $toEmail = $guest[0]->GUT_Email;//
		$data['coli_id'] = $coli_id;
		$data['toname'] = $toName;
		$data['adult'] = $info->COLD_PersonNum;
		$data['chlid'] = $info->COLD_ChildNum;
		$data['baby'] = $info->COLD_BabyNum;
		$data['price'] = $this->BIZ_train_model->get_paypal($coli_id);
		if($data['price']->GAI_SQJECurrency == 'CNY'){
			$data['price']->GAI_SQJECurrency == 'RMB';
		}
		$data['allpeople'] = $this->BIZ_train_model->biz_people($info->COLD_SN);
		$data['train_info'] = $this->BIZ_train_model->biz_order_detail($info->COLD_SN);
		$differtime = (strtotime($data['train_info']->DepartureTime) - time()) / 3600;
		$obj = $this->BIZ_train_model->get_biz_jol_info($info->COLD_SN,$jh_order);
		$data['elecnumber'] = $obj->ts_elecnumber;
		$status = $obj->ts_status;
		$data['operator'] = $operator_info;
		$data['emailarr'] = explode(';',$operator_info[0]->Email);

		$data['seatinfo'] = $obj->ts_seatsinfo;
		
		if($status == '4' && $differtime > 0){
			$subject = "Got payment and issued train ticket(s), Order No $coli_id";
			$body = $this->load->view('email',$data,true);
			$this->send_mail_to_wl("订单:{$coli_id} 出票成功","翰特订单号:{$coli_id};聚合订单号:{$jh_order}",$coli_id);
			//发送邮件给客人
			$flag = $this->Sendmail_model->SendMailToTable($fromName,$fromEmail,$toName,$toEmail,$subject,$body);
			$this->BIZ_train_model->update_biz_jol(array("ts_ordernumber"=>$jh_order),array("ts_sendmail"=>1,"ts_m_sn"=>$flag));
		}else if($status == '1'){
			$subject = "The train ticket(s) will be issued manually, Order No $coli_id";
			$body = $this->load->view('email_fault',$data,true);
			$this->send_mail_to_wl("订单:{$coli_id} 出票失败","翰特订单号:{$coli_id};聚合订单号:{$jh_order}",$coli_id);
			//测试阶段，将失败邮件发送一份给操作外联。
			$flag = $this->Sendmail_model->SendMailToTable($fromName,$fromEmail,$fromName,$fromEmail,$subject,$body);
			//测试阶段，将失败邮件发送一份给操作外联。
			$this->Sendmail_model->SendMailToTable($fromName,$fromEmail,$toName,$toEmail,$subject,$body);
			$this->BIZ_train_model->update_biz_jol(array("ts_ordernumber"=>$jh_order),array("ts_sendmail"=>1,"ts_m_sn"=>$flag));
		}
		
    }
	
	//发邮件给外联
    function send_mail_to_wl($subject=null,$body=null,$coli_id=null){
		header('Access-Control-Allow-Origin:*'); 
		header('Access-Control-Allow-Methods:POST, GET');
		header('Access-Control-Max-Age:0');
		header('Access-Control-Allow-Headers:x-requested-with, Content-Type');
		header('Access-Control-Allow-Credentials:true');
		$fromName  = "cyc";
		$fromEmail = "cyc@hainatravel.com";
		if(empty($coli_id)){
			$toName = 'Sharon';
			$toEmail = 'sharon@chinahighlights.com';
			$fromEmail = $this->input->get_post('concatEmail');
			$body = $this->input->get_post('addrequest');
			if(empty($fromEmail) && empty($body)){
				exit('error');
			}
		}else{
			//获取该订单的操作员的邮箱以及姓名
			$info = $this->BIZ_train_model->get_operatorInfo($coli_id);
			$toName = $info[0]->OPI_Name;
			$toEmail = $info[0]->OPI_Email;
		}

		$obj = $this->Sendmail_model->SendMailToTable($fromName,$fromEmail,$toName,$toEmail,$subject,$body);
		
		if($obj){
			exit('{"status":"200","reason":"邮件发送成功"}');
		}else{
			header("HTTP/1.1 404 Not Found");  
			exit('{"status":"404","reason":"邮件发送失败"}');
		}
    }
	
	public function send_options_mail_to_wl(){
		header('Access-Control-Allow-Origin:*'); 
		header('Access-Control-Allow-Methods:POST, GET');
		header('Access-Control-Max-Age:0');
		header('Access-Control-Allow-Headers:x-requested-with, Content-Type');
		header('Access-Control-Allow-Credentials:true');
		$fromName  = "cyc";
		$fromEmail = "cyc@hainatravel.com";
		
		$order = $this->input->get_post('order');
		$person = $this->input->get_post('person');
		$type = $this->input->get_post('type');
		$request = $this->input->get_post('request');
		$body = '';
		
		$coli_id = $this->BIZ_train_model->cold_sn_get_coli_id($order);
		$trainInfos = $this->BIZ_train_model->biz_order_detail($order);
		$passager = $this->BIZ_train_model->in_bpesn_people_info($person);

		$body .= '订单号：'.$coli_id['0']->COLI_ID.'<br>';
		$body .= '车程：'.$trainInfos->DepartAirport_cn.'->'.$trainInfos->ArrivalAirport_cn.','.$trainInfos->FlightsNo.','.date('Y-m-d',strtotime($trainInfos->DepartureDate)).'<br>';
		$body .= '乘客：'.$passager['0']->BPE_FirstName.$passager['0']->BPE_MiddleName.$passager['0']->BPE_LastName.','.$passager['0']->BPE_Passport.'<br>';
		$body .= '操作：'.$type.'<br>';
		$body .= '详细信息：'.$request.'<br>';
		
		$toName = 'Sharon';
		$toEmail = 'sharon@chinahighlights.com';
		$subject = '用户中心操作';
		
		$obj = $this->Sendmail_model->SendMailToTable($fromName,$fromEmail,$toName,$toEmail,$subject,$body);
		if($obj){
			exit('{"status":"200","reason":"邮件发送成功"}');
		}
	}
	
	//导出账单api
	public function export_excel(){
		set_time_limit(0);
		//创建跟踪号
		$trackcode = $this->BIZ_train_model->getTrackingCode();
        $from_date = $this->input->post("from_date");
        $to_date = $this->input->post("to_date");
        $examine = $this->input->post("examine");
		//$operator=$this->input->post("operator");
		
        $reback=array();//返回的数据
        $reback["from_date"] = $from_date;
        $reback["to_date"] = $to_date;
        $reback["examine"] = $examine;
		$group = array();
		
        if(!empty($from_date) && !empty($to_date)){
            $from_date = date("Y-m-d H:i",strtotime($from_date));
            $to_date = date("Y-m-d H:i",strtotime($to_date));
            $r = "";//聚合返回的数据
            $string_r = "";//输出
            $coli_id = "";
            $wl_name = "";
            $arr = array();//整合完成的数组,写进excel表的数据
            $url = JUHE_TRAIN_EXPORT_API;//请求的url
            $url .= "?key=".JUHE_TRAIN_API_KEY;
            $url .= "&since=".$from_date;
            $url .= "&before=".$to_date;
            $r = GetPost_http($url);
            $r = explode("\n",$r);
            //print_r($r);
            //die();
			for($i=1;$i<count($r)-1;$i++){
                $r_info=explode(",",$r[$i]);
                $juhe_order=substr($r_info[4], 1,strlen($r_info[4])-2);
				$obj = $this->BIZ_train_model->jh_order_get_coli_id($juhe_order);
				//print_r($obj);
				if(!empty($obj)){
					$coli_id = $obj[0]->COLI_ID;
					$coli_sn = $obj[0]->COLI_SN;
					$this->BIZ_train_model->linkTrackingCode($coli_sn,$trackcode);
				}else{
					echo $juhe_order;	
				}
				
				/*if(empty($coli_sn) || empty($coli_sn)){
					print_r($juhe_order);
				}*/
				
				
				/*
				$flag = $this->BIZ_train_model->islink($coli_sn);
				if($flag){
					$this->BIZ_train_model->linkTrackingCode($coli_sn,$trackcode);
				}else{
					echo $coli_sn.'该订单还未关联财务表，不能导出账单。<br>';
					die();
				}
				*/
                //去掉数据两边的双引号
                $r_info[2]=substr($r_info[2], stripos($r_info[2],'"')+1,strrpos($r_info[2],'"')-1);
                $r_info[1]=substr($r_info[1], stripos($r_info[1],'"')+1,strrpos($r_info[1],'"')-1);
                $r_info[5]=substr($r_info[5], stripos($r_info[5],'"')+1,strrpos($r_info[5],'"')-1);
                $r_info[6]="";//储存团名
                $r_info[7] = "";//储存外联名
                $r_info[8] = "";//储存coli_id
                if($coli_id){  
                   $r_info[8] = $coli_id;  
                   $gri_no=$this->BIZ_train_model->get_gri_no($r_info[8]);//团名
                   $wl_name = $this->BIZ_train_model->get_operatorInfo($r_info[8]);					
                   if($gri_no){
                     $r_info[6] = $gri_no[0]->GRI_No;
                   }
                   if($wl_name){
                     $r_info[7] = $wl_name[0]->OPI_Name;
                   }
                }
				
                //$r_info[3]=mb_convert_encoding($r_info[3],"utf-8","gbk");
				
                if(is_numeric(mb_strpos($r_info[3],"充值"))){
                    if(is_numeric(mb_strpos($r_info[3],"扣款"))){
                    $r_info[3]="票款(有充值)";
                    } 
                    if(is_numeric(mb_strpos($r_info[3],"扣手续费"))){
                        $r_info[3]="手续费(有充值)";
                    }
                    if(is_numeric(mb_strpos($r_info[3],"线上退票成功"))){
                        $r_info[3]="退票费(有充值)";
                    }
                }    
                if(is_numeric(mb_strpos($r_info[3],"扣款"))){
                    $r_info[3]="票款";
                } 
                if(is_numeric(mb_strpos($r_info[3],"扣手续费"))){
                    $r_info[3]="手续费";
                }
                if(is_numeric(mb_strpos($r_info[3],"线上退票成功"))){
                    $r_info[3]="退票费";
                }
                // $r_info[3]=mb_convert_encoding($r_info[3],"gbk","utf-8");
				$r_info['trackcode'] = $trackcode;
                $arr[]=$r_info;
				
				/*
				//根据外联的名字创建数组来存储对应外联的订单信息
				if(!empty($r_info[7])){
					if(!isset($group[$r_info[7]])){
						$group[$r_info[7]] = array();
					}
					array_push($group[$r_info[7]],$r_info);
				}*/
				
            }
			/*
			//将存储好的分组重新循环出来。
			foreach($group as $item){
				foreach ($item as $value){
					array_push($arr,$value);
				}
			}
			*/
			//die();
            if(empty($examine)){
                header("Content-type:application/vnd.ms-excel;charset=utf-8");
                header("Content-Disposition:attachment;filename=juhe_train.xls");
                $string_r= $this->load->view("train_transaction_excel",array("arr"=>$arr),TRUE);
                echo $string_r;die;
            }else{
                krsort($arr);//数组倒序
                $reback["data"]=$arr;
            }
            
        }
	}

	//澜海账单导出api
	public function lanhai_export_excel(){
		set_time_limit(0);

		//参数
		$from_date = $this->input->post("from_date");
        $to_date = $this->input->post("to_date");
		$examine = $this->input->post("examine");
		$importht = $this->input->post("importht");

		$reback=array();//返回的数据
        $reback["from_date"] = $from_date;
        $reback["to_date"] = $to_date;
        $reback["examine"] = $examine;
		$reback["importht"] = $importht;

		if(!empty($from_date) && !empty($to_date)){
			//拼接发送的报文
			$PostData = new stdClass();
			$bodyInfo = new stdclass();
			$bodyInfo->startTime = $from_date." 00:00:00";
			$bodyInfo->endTime = $to_date." 23:59:59";
			$bodyInfo->pageNum = 1;
			$bodyInfo->pageSize = 20000;

			$authentication = new stdClass();  //需加密的数据			
			$authentication->appId = LANHAI_appId;

			//加密
			$this->load->library("aesLanhai");
			$aesUnit = new Security();
			$resultData = $aesUnit->encryptData(json_encode($bodyInfo));

			$PostData->bodyInfo = $resultData;
			$PostData->authentication = $authentication;

			//echo (json_encode($PostData));

			$url = LANHAI_URL."api/open/bill";
			$ResponseJson = GetPost_http($url,json_encode($PostData,JSON_UNESCAPED_UNICODE),'json');		
			$ResponseData = json_decode($ResponseJson);
			if($ResponseData->code == 0 && $ResponseData->success){
				
				$string_r = "";//输出
				$arr = array();//整合完成的数组,写进excel表的数据

				//账单导入到汉特。	先删除同一编码的数据，防止重复				
				if (!empty($importht)){
					$BillSn = date('Ymd',strtotime($from_date)).date('Ymd',strtotime($to_date)); //这是获取开始结束日期作为编码，一定要和下面获取代码一样。
					$this->BIZ_train_model->del_lanhai_bill($BillSn);
				}
				
				foreach ($ResponseData->data->records as $record) {
					# code...
					$arrRecord = array();
					$arrRecord["saveDay"] = $record->saveDay;
					$arrRecord["type"] = $record->type; //类型 包括：出票、低改高、出票退票、改签退票、退票
					$arrRecord["mainOrderId"] = $record->mainOrderId; //订单号
					$arrRecord["passengerName"] = $record->passengerName; //乘车人
					$arrRecord["price"] = $record->price ;//金额，整数是支付票款，负数是退回金额
					$arrRecord["wl"] = "";  //外联
					$arrRecord["griName"]=""; //团号
					$orderData = $this->train_system_model->get_OPIName($record->mainOrderId);
					if (!empty($orderData)){
						$arrRecord["wl"] = $orderData->OPIName;
						$arrRecord["griName"] = $orderData->griName;
					}				

					$arr[] = $arrRecord;

					//账单导入到汉特。					
					if (!empty($importht)){
						$AddHt_data = new stdClass(); //账单保存到汉特
						$AddHt_data->BillSn = date('Ymd',strtotime($from_date)).date('Ymd',strtotime($to_date));
						$AddHt_data->BillDate =  $record->saveDay;
						$AddHt_data->OrderId = $record->mainOrderId; 
						$AddHt_data->VEIName = LANHAI_appId;
						$AddHt_data->From = "桂林海纳国际旅行社有限公司";
						$AddHt_data->BillType = $record->type;
						$AddHt_data->OrderType = null;
						$AddHt_data->Cost = -($record->price);
						$AddHt_data->Memo = $record->handleTime;
						//入库
						$this->BIZ_train_model->add_lanhai_bill($AddHt_data);
					}
				}

				//print_r($arr);

				if(empty($examine)){
				//写入excel模板
					header("Content-type:application/vnd.ms-excel;charset=utf-8");
					header("Content-Disposition:attachment;filename=lanhai_train.xls");
					$string_r= $this->load->view("lanhai_transaction_excel",array("arr"=>$arr),TRUE);
					echo $string_r;die;
				}else{
					krsort($arr);//数组倒序
					$reback["data"]=$arr;
					$this->load->view('header');
					$this->load->view('export_lanhai',$reback);
					$this->load->view('footer'); 
				}

			}

		}

	}
	
	//订单同步到trainsystem
	public function sync_orders(){
		die();
		//获取聚合订单
		$juhe_orders = $this->train_system_model->getallorders();
		
		$add_data = new stdClass();
		foreach ($juhe_orders as $items){
			$add_data->ordernumber = $items->JOL_JuheOrder;
			$add_data->cold_sn = $items->JOL_COLD_SN;
			$add_data->status = $items->JOL_Status;
			$add_data->returncode = '';
			$add_data->errormsg = $items->JOL_RebackMsg;
			$add_data->checi = $items->JOL_TrainCode;
			$add_data->fromstationame = $items->JOL_FromStation;
			$add_data->fromstationcode = $items->JOL_FromStationCode;
			$add_data->tostationame = $items->JOL_ToStation;
			$add_data->tostationcode = $items->JOL_ToStationCode;
			
			$trains = json_decode($items->JOL_BackTxt);
			//print_r($trains->passengers);
			if(isset($trains->train_date)){
				$add_data->startdate = $trains->train_date;
			}else{
				$add_data->startdate = '';
			}
			
			foreach ($trains->passengers as $passengers){
				//对订票乘客进行存储
				$data_passager->ordernumber = $items->JOL_JuheOrder;
				$data_passager->realname = $passengers->passengersename;
				$data_passager->identitytype = $passengers->passporttypeseidname;
				$data_passager->numberid = $passengers->passportseno;
				$data_passager->ticketype = $passengers->piaotypename;
				$data_passager->ticketprice = $passengers->price;
				$data_passager->seatype = $passengers->zwname;
				$data_passager->seatdetail = $passengers->cxin;
				$data_passager->status = $items->JOL_Status;
				//print_r($data_passager);
				$this->train_system_model->add_passagers($data_passager);
			}
			
			$add_data->startime = '';
			$add_data->endtime = '';
			$add_data->runtime = '';
			 
			$add_data->channel = 'juhe';
			$add_data->isauto = $items->JOL_IsAuto;
			$this->train_system_model->add_orders($add_data);
			//print_r($add_data);
		}
	}
}