function olah_csv_medmec($p) {
global $db,$ar;
//no,code,qty,tgl_pergi,med_hotel_no,bus,bus_no,mec_hotel_no,contract_no,pax
//12,UPG2,393,2026-04-30 17,507,DALLAH,1-10,204,71717,393
$data=explode(',',strtoupper(trim($p)));
$dt['no']=$data[0];
$dt['code']=trim($data[1]);
$dt['qty']=$data[2];
if(strlen(trim($data[3]))<9) {
$dt['date_med']='2026-'.$data[3].':00:00';
} else {
$dt['date_med']=$data[3].':00:00';
}
$dt['med_hotel_no']=$data[4];
$dt['bus']=$data[5];
$dt['bus_no']=$data[6];
$dt['mec_hotel_no']=$data[7];
$dt['contract_no']=$data[8];
$dt['pax']=$data[9];
if(strlen($dt['mec_hotel_no'])>3) {
$dt['mec_sektor']=substr($dt['mec_hotel_no'],0,2);
} else {
$dt['mec_sektor']=substr($dt['mec_hotel_no'],0,1);
}
echo "<br>".count($data)."<br>";
echo "<pre>"; print_r($dt); echo "</pre>";
if(count($data)!=10) {
echo "data tidak benar<br>";
} else {
//t1 cek code
$sql0="SELECT * from mykloter where code='".$dt['code']."'";
$res0=mysqli_query($db,$sql0);
if(mysqli_num_rows($res0)==1) {
$udt=array(
'out_no'=>$dt['no'],
'out_hotel_date'=>substr($dt['date_med'],0,10),
'out_hotel_time'=>strtotime($dt['date_med']),
'out_qty'=>$dt['qty'],
'update_by'=>$_SESSION['user']['petugas'],
'update_at'=>time(),
);
Update($db,"mykloter",$udt,"`code`='".$dt['code']."'",1);
$sql7="SELECT * from myhotel where code='".$dt['code']."' and hotel_no=".$dt['med_hotel_no'];
$res7=mysqli_query($db,$sql7);
if(mysqli_num_rows($res7)==1) {
$udt2=array(
'out_no'=>$dt['no'],
'out_hotel_date'=>substr($dt['date_med'],0,10),
'out_hotel_time'=>strtotime($dt['date_med']),
'out_bus'=>$dt['bus'],
'out_bus_no'=>$dt['bus_no'],
'update_by'=>$_SESSION['user']['petugas'],
'update_at'=>time(),
);
Update($db,"myhotel",$udt2,"`code`='".$dt['code']."' and hotel_no='".$dt['med_hotel_no']."'",1);
}
$udt3=array(
'out_hotel_date'=>substr($dt['date_med'],0,10),
'out_hotel_time'=>strtotime($dt['date_med']),
'update_at'=>time(),
);
Update($db,"penempatan",$udt3,"`daker`=2 and gel=1 and `emb`='".substr($dt['code'],0,3)."' and `klt`='".substr($dt['code'],3)."' and no_rumah='".$dt['med_hotel_no']."'",1);
//cek data mecca
$sql6="SELECT * from secondhotel where code='".$dt['code']."' and hotel_no=".$dt['mec_hotel_no'];
$res6=mysqli_query($db,$sql6);
if(mysqli_num_rows($res6)==0) {
$sql5 = "select id from `secondhotel` order by id desc limit 1";
$res5 = mysqli_query($db, $sql5);
$r5 = mysqli_fetch_assoc($res5);
$id5=$r5['id']+1;
$idt=array(
'id'=>$id5,
'gel'=>1,
'code'=>strtoupper($dt['code']),
'no'=>$dt['no'],
'emb'=>substr(strtoupper($dt['code']),0,3),
'klt'=>substr($dt['code'],3),
'in_hotel_date'=>date("Y-m-d",strtotime($dt['date_med'])+18000),
'in_hotel_time'=>strtotime($dt['date_med'])+18000,
'code_qty'=>$dt['qty'],
'sektor'=>$dt['mec_sektor'],
'hotel_no'=>trim($dt['mec_hotel_no']),
'contract_no'=>trim($dt['contract_no']),
'pax'=>$dt['pax'],
'create_at'=>time(),
'create_by'=>$_SESSION['user']['petugas'],
'update_by'=>$_SESSION['user']['petugas'],
'update_at'=>time(),
);
Insert($db,"secondhotel",$idt,1);
}
if(mysqli_num_rows($res6)==1) {
$udt=array(
'no'=>$dt['no'],
'emb'=>substr(strtoupper($dt['code']),0,3),
'klt'=>substr($dt['code'],3),
'in_hotel_date'=>date("Y-m-d",strtotime($dt['date_med'])+18000),
'in_hotel_time'=>strtotime($dt['date_med'])+18000,
'code_qty'=>$dt['qty'],
'sektor'=>$dt['mec_sektor'],
'contract_no'=>trim($dt['contract_no']),
'pax'=>$dt['pax'],
'update_by'=>$_SESSION['user']['petugas'],
'update_at'=>time(),
);
Update($db,"secondhotel",$udt,"`code`='".$dt['code']."' and hotel_no='".$dt['mec_hotel_no']."'",1);
}
}
}
/* */
}