function olah_csv_idmed($p) {
global $db,$ar;
//2,JKG5,ABRAJ SAADAH,522,66225,445,NOH
//$col = explode("n", $_POST['csv']);
//$data = str_getcsv($p);
//echo "<pre>"; print_r($data); echo "</pre>";
$data=explode(',',strtoupper(trim($p)));
$dt['no']=$data[0];
$dt['code']=trim($data[1]);
$dt['majmuah']=trim(to_char_space($data[2]));
$dt['med_hotel_no']=trim($data[3]);
$dt['contract_no']=trim($data[4]);
$dt['pax']=trim($data[5]);
$dt['kitchen_code']=trim(to_char_space($data[6]));
//echo count($data)."<br>";
//echo "<pre>"; print_r($dt); echo "</pre>";
if(count($data)!=7) {
echo "<pre>"; print_r($dt); echo "</pre>";
}
if(count($data)==7) {
$sql1 = "select * from `berangkat` where code='".$dt['code']."'";
$res1 = mysqli_query($db, $sql1);
//echo $sql;
$r1 = mysqli_fetch_assoc($res1);
//t1 cek code
$sql0="SELECT * from mykloter where code='".$dt['code']."'";
$res0=mysqli_query($db,$sql0);
if(mysqli_num_rows($res0)==0) {
$sql4 = "select id from `mykloter` order by id desc limit 1";
$res4 = mysqli_query($db, $sql4);
if(mysqli_num_rows($res4)>0) {
$rw4 = mysqli_fetch_assoc($res4);
$id2=$rw4['id']+1;
} else {
$id2=1;
}
$sql5 = "select id from `myhotel` order by id desc limit 1";
$res5 = mysqli_query($db, $sql5);
if(mysqli_num_rows($res4)>0) {
$r5 = mysqli_fetch_assoc($res5);
$id5=$r5['id']+1;
} else {
$id5=1;
}
$udt=array(
'id'=>$id2,
'code'=>strtoupper($dt['code']),
'no'=>$dt['no'],
'sa_arrival_port'=>'MED',
'flight_no'=>$r1['flight'],
'id_takeoff_date'=>date("Y-m-d",$r1['rpergi_jam']),
'id_takeoff_time'=>$r1['rpergi_jam'],
'sa_arrival_date'=>date("Y-m-d",$r1['rtiba_jam']),
'sa_arrival_time'=>$r1['rtiba_jam'],
'in_hotel_date'=>date("Y-m-d",$r1['rtiba_jam']+7200),
'in_hotel_time'=>$r1['rtiba_jam']+7200,
'jhi'=>$r1['rjhi'],
'tphi'=>$r1['rtphi'],
'tpihi'=>$r1['rtpihi'],
'tkhi'=>$r1['rtkhi'],
'ptg'=>$r1['rtphi']+$r1['rtpihi']+$r1['rtkhi'],
'total'=>$r1['rtotal'],
'code_qty'=>$r1['rtotal'],
'gel'=>1,
'daker'=>$_SESSION['user']['daker'],
'emb'=>strtoupper(substr($dt['code'],0,3)),
'klt'=>substr($dt['code'],3),
'syarikah'=>$ar['emb2syarikah'][substr($dt['code'],0,3)],
'create_at'=>time(),
'create_by'=>$_SESSION['user']['petugas'],
'update_by'=>$_SESSION['user']['petugas'],
'update_at'=>time(),
);
Insert($db,"mykloter",$udt,1);
$idt=array(
'id'=>$id5,
'code'=>strtoupper($dt['code']),
'no'=>$dt['no'],
'gel'=>1,
'emb'=>substr(strtoupper($dt['code']),0,3),
'klt'=>substr($dt['code'],3),
'in_hotel_date'=>date("Y-m-d",$r1['rtiba_jam']+7200),
'in_hotel_time'=>$r1['rtiba_jam']+7200,
'jhi'=>$r1['rjhi'],
'tphi'=>$r1['rtphi'],
'tpihi'=>$r1['rtpihi'],
'tkhi'=>$r1['rtkhi'],
'ptg'=>$r1['rtphi']+$r1['rtpihi']+$r1['rtkhi'],
'total'=>$r1['rtotal'],
'code_qty'=>$r1['rtotal'],
'majmuah'=>$dt['majmuah'],
'sektor'=>substr($dt['med_hotel_no'],0,1),
'hotel_no'=>trim($dt['med_hotel_no']),
'contract_no'=>trim($dt['contract_no']),
'pax'=>$dt['pax'],
'kitchen_code'=>trim($dt['kitchen_code']),
'daker'=>$_SESSION['user']['daker'],
'create_by'=>$_SESSION['user']['petugas'],
'update_by'=>$_SESSION['user']['petugas'],
'create_at'=>time(),
'update_at'=>time(),
);
Insert($db,"myhotel",$idt,1);
} else {
$udt3=array(
'no'=>$dt['no'],
'sa_arrival_port'=>'MED',
'flight_no'=>$r1['flight'],
'id_takeoff_date'=>date("Y-m-d",$r1['rpergi_jam']),
'id_takeoff_time'=>$r1['rpergi_jam'],
'sa_arrival_date'=>date("Y-m-d",$r1['rtiba_jam']),
'sa_arrival_time'=>$r1['rtiba_jam'],
'in_hotel_date'=>date("Y-m-d",$r1['rtiba_jam']+7200),
'in_hotel_time'=>$r1['rtiba_jam']+7200,
'jhi'=>$r1['rjhi'],
'tphi'=>$r1['rtphi'],
'tpihi'=>$r1['rtpihi'],
'tkhi'=>$r1['rtkhi'],
'ptg'=>$r1['rtphi']+$r1['rtpihi']+$r1['rtkhi'],
'total'=>$r1['rtotal'],
'code_qty'=>$r1['rtotal'],
'gel'=>1,
'emb'=>strtoupper(substr($dt['code'],0,3)),
'klt'=>substr($dt['code'],3),
'syarikah'=>$ar['emb2syarikah'][substr($dt['code'],0,3)],
'update_by'=>$_SESSION['user']['petugas'],
'update_at'=>time(),
);
Update($db,"mykloter",$udt3,"`code`='".$dt['code']."'",1);
$sql6="SELECT * from myhotel where code='".$dt['code']."' and hotel_no=".$dt['med_hotel_no']." and kitchen_code='".$dt['kitchen_code']."'";
$res6=mysqli_query($db,$sql6);
if(mysqli_num_rows($res6)==0) {
$sql5 = "select id from `myhotel` order by id desc limit 1";
$res5 = mysqli_query($db, $sql5);
$r5 = mysqli_fetch_assoc($res5);
$id5=$r5['id']+1;
$idt=array(
'id'=>$id5,
'code'=>strtoupper($dt['code']),
'no'=>$dt['no'],
'gel'=>1,
'emb'=>substr(strtoupper($dt['code']),0,3),
'klt'=>substr($dt['code'],3),
'in_hotel_date'=>date("Y-m-d",$r1['rtiba_jam']+7200),
'in_hotel_time'=>$r1['rtiba_jam']+7200,
'jhi'=>$r1['rjhi'],
'tphi'=>$r1['rtphi'],
'tpihi'=>$r1['rtpihi'],
'tkhi'=>$r1['rtkhi'],
'ptg'=>$r1['rtphi']+$r1['rtpihi']+$r1['rtkhi'],
'total'=>$r1['rtotal'],
'code_qty'=>$r1['rtotal'],
'majmuah'=>$dt['majmuah'],
'sektor'=>substr($dt['med_hotel_no'],0,1),
'hotel_no'=>trim($dt['med_hotel_no']),
'contract_no'=>trim($dt['contract_no']),
'pax'=>$dt['pax'],
'kitchen_code'=>trim($dt['kitchen_code']),
'daker'=>$_SESSION['user']['daker'],
'create_by'=>$_SESSION['user']['petugas'],
'update_by'=>$_SESSION['user']['petugas'],
'create_at'=>time(),
'update_at'=>time(),
);
Insert($db,"myhotel",$idt,1);
} else {
$udt=array(
'ptg'=>$r1['rtphi']+$r1['rtpihi']+$r1['rtkhi'],
'total'=>$r1['rtotal'],
'code_qty'=>$r1['rtotal'],
'no'=>$dt['no'],
'in_hotel_date'=>date("Y-m-d",$r1['rtiba_jam']+7200),
'in_hotel_time'=>$r1['rtiba_jam']+7200,
'majmuah'=>$dt['majmuah'],
'sektor'=>substr($dt['med_hotel_no'],0,1),
'hotel_no'=>trim($dt['med_hotel_no']),
'contract_no'=>trim($dt['contract_no']),
'pax'=>$dt['pax'],
'kitchen_code'=>trim($dt['kitchen_code']),
'update_by'=>$_SESSION['user']['petugas'],
'update_at'=>time(),
);
Update($db,"myhotel",$udt,"`code`='".$dt['code']."' and hotel_no='".$dt['med_hotel_no']."' and kitchen_code='".$dt['kitchen_code']."'",1);
}
$udt3=array(
'in_hotel_date'=>date("Y-m-d",$r1['rtiba_jam']+7200),
'in_hotel_time'=>$r1['rtiba_jam']+7200,
'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);
}
}
/* */
}