@ -5,11 +5,7 @@ include_once("./getComboNo.php");
ini_set ( 'date.timezone' , 'Asia/Taipei' );
if(isset($_POST["contractno"]) & & $_POST["contractno"] != "") {
try{
< < < < < < < HEAD
$created_at = date('Y-m-d H:i:s');
=======
>>>>>>> f6b04618 (1106)
$contractno = !empty($_POST['contractno'])? $_POST['contractno'] : null;
$total_price = !empty($_POST['total_price']) ? $_POST['total_price'] : null;
$vat = !empty($_POST['vat']) ? $_POST['vat'] : null;
@ -43,9 +39,8 @@ if(isset($_POST["contractno"]) && $_POST["contractno"] != "") {
$latitude = !empty($_POST['latitude']) ? $_POST['latitude'] : null;
$longitude = !empty($_POST['longitude']) ? $_POST['longitude'] : null;
$num = !empty($_POST['num']) ? $_POST['num'] : null;
< < < < < < < HEAD
$files = !empty($_FILES['files']) ? $_FILES['files'] : null;
$elevators = !empty($_POST['elevators']) ? json_decode($_POST['elevators'], true) : [];
// validate
$fail_arr = [];
if($contractno === '') return $fail_arr[] = '合約號為必填';
@ -53,7 +48,6 @@ if(isset($_POST["contractno"]) && $_POST["contractno"] != "") {
if($total_price == '') $fail_arr[] = '合約總價為必填';
if($vat == '') $fail_arr[] = '統一編號為必填';
if($mtype == '') $fail_arr[] = '維修型態為必填';
if($opendoor == '') $fail_arr[] = '開門方式為必填';
if($phone == '') $fail_arr[] = '客戶電話為必填';
if($email == '') $fail_arr[] = 'Email為必填';
if($mworker == '') $fail_arr[] = '保養員為必填';
@ -64,33 +58,17 @@ if(isset($_POST["contractno"]) && $_POST["contractno"] != "") {
if($address == '') $fail_arr[] = '地址為必填';
if($area == '') $fail_arr[] = '區域為必填';
if($customer == '') $fail_arr[] = '客戶為必填';
if($partyA == '') $fail_arr[] = '甲方為必填';
if($partyAaddress == '') $fail_arr[] = '甲方地址為必填';
if($partyAphone == '') $fail_arr[] = '甲方電話為必填';
if($partyAemail == '') $fail_arr[] = '甲方Email為必填';
if($spec == '') $fail_arr[] = '規格為必填';
if($weight == '') $fail_arr[] = '重量為必填';
if($numberofpassenger == '') $fail_arr[] = '乘客人數為必填';
if($numberofstop == '') $fail_arr[] = '停留站數為必填';
if($numberoffloor == '') $fail_arr[] = '停留樓層為必填';
if($speed == '') $fail_arr[] = '速度為必填';
if($takecertificatedate == '') $fail_arr[] = '取標日期為必填';
if($maintainance == '') $fail_arr[] = '保養為必填';
if($licensedate == '') $fail_arr[] = '營業員為必填';
if($latitude == '') $fail_arr[] = '緯度為必填';
if($longitude == '') $fail_arr[] = '經度為必填';
if($num == '') $fail_arr[] = '數量為必填';
if($partyA == '') $fail_arr[] = '業務聯繫人為必填';
if($partyAaddress == '') $fail_arr[] = '業務聯繫人地址為必填';
if($partyAphone == '') $fail_arr[] = '業務聯繫人電話為必填';
if($partyAemail == '') $fail_arr[] = '業務聯繫人Email為必填';
if($num == '') $fail_arr[] = '電梯數量為必填';
if(count($fail_arr) > 0) {
header("HTTP/1.1 422 Unprocessable Entity");
echo json_encode($fail_arr);
exit();
}
=======
$files = !empty($_FILES['files']) ? $_FILES['files'] : null;
>>>>>>> f6b04618 (1106)
//create account table
$accounttype = "A";
$accountid = $vat;
@ -156,60 +134,62 @@ if(isset($_POST["contractno"]) && $_POST["contractno"] != "") {
//create facility table
$createFacilityNo = new CreateFacilityNo();
$dailyNecessities = [
'MAE100'=>'X',
'MAM200'=>'W',
'MAH100'=>'H',
'MAQ100'=>'Z',
'MAF100'=>'F',
'MAZ100'=>'B',
];
$sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':accountid',$mworker);
$stmt->execute();
$worker = $stmt->fetch(PDO::FETCH_ASSOC);
'MAE100'=>'X',
'MAM200'=>'W',
'MAH100'=>'H',
'MAQ100'=>'Z',
'MAF100'=>'F',
'MAZ100'=>'B',
];
$facility_arr = [];
foreach($elevators as $elevator){
$facility_arr[] = $elevator['spec'];
}
$facilityno = $createFacilityNo->makeBFacilityNo("T", $dailyNecessities[$spec], (int)$num);
$define = "B";
$customerid = $vat;
$opentype = $opendoor;
$repairtype = "A";
$facility_kind = $spec;
$maintainance = "E";
$repairerid = $mworker;
$repairername = $worker['name'];
$facilityno = $createFacilityNo->makeBFacilityNo("T", $dailyNecessities[$elevator['spec']], (int)$num);
$sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':accountid',$mworker);
$stmt->execute();
$worker = $stmt->fetch(PDO::FETCH_ASSOC);
$customerid = $vat;
$define = "B";
$repairtype = "A";
$repairerid = $mworker;
$repairername = $worker['name'];
foreach($elevators as $idx=>$elevator){
$sql_str = "INSERT INTO facility (contractno, define, facilityno, latitude, longitude, customerid, weight, numberofpassenger, numberofstop, numberoffloor, opentype, speed, repairtype, maintainance, facility_kind, address, repairerid, repairername, creater, create_at, area, takecertificatedate, licensedate)
VALUES (:contractno, :define, :facilityno, :latitude, :longitude, :customerid, :weight, :numberofpassenger, :numberofstop, :numberoffloor, :opentype, :speed, :repairtype, :maintainance, :facility_kind, :address, :repairerid, :repairername, :creater, :create_at, :area, :takecertificatedate, :licensedate)";
$stmt = $conn -> prepare($sql_str);
$stmt -> bindParam(':contractno' ,$contractno);
$stmt -> bindParam(':define' ,$define);
$stmt -> bindParam(':facilityno' ,$facilityno[$idx]);
$stmt -> bindParam(':latitude' ,$elevator['latitude']);
$stmt -> bindParam(':longitude' ,$elevator['longitude']);
$stmt -> bindParam(':customerid' ,$customerid);
$stmt -> bindParam(':weight' ,$elevator['weight']);
$stmt -> bindParam(':numberofpassenger' ,$elevator['persons']);
$stmt -> bindParam(':numberofstop' ,$elevator['stop']);
$stmt -> bindParam(':numberoffloor' ,$elevator['floors']);
$stmt -> bindParam(':opentype' ,$elevator['opendoor']);
$stmt -> bindParam(':speed' ,$elevator['speed']);
$stmt -> bindParam(':repairtype' ,$repairtype);
$stmt -> bindParam(':maintainance' ,$maintainance);
$stmt -> bindParam(':facility_kind' ,$elevator['spec']);
$stmt -> bindParam(':address' ,$address);
$stmt -> bindParam(':repairerid' ,$repairerid);
$stmt -> bindParam(':repairername' ,$repairername);
$stmt -> bindParam(':creater' ,$creater);
$stmt -> bindParam(':create_at' ,$create_at);
$stmt -> bindParam(':area' ,$area);
$stmt -> bindParam(':takecertificatedate' ,$elevator['takecertificatedate']);
$stmt -> bindParam(':licensedate' ,$elevator['licensedateeeee']);
$result = $stmt -> execute();
}
foreach($facilityno as $fno){
$sql_str = "INSERT INTO facility (contractno, define, facilityno, latitude, longitude, customerid, weight, numberofpassenger, numberofstop, numberoffloor, opentype, speed, repairtype, maintainance, facility_kind, address, repairerid, repairername, creater, create_at, area, takecertificatedate, licensedate)
VALUES (:contractno, :define, :facilityno, :latitude, :longitude, :customerid, :weight, :numberofpassenger, :numberofstop, :numberoffloor, :opentype, :speed, :repairtype, :maintainance, :facility_kind, :address, :repairerid, :repairername, :creater, :create_at, :area, :takecertificatedate, :licensedate)";
$stmt = $conn -> prepare($sql_str);
$stmt -> bindParam(':contractno' ,$contractno);
$stmt -> bindParam(':define' ,$define);
$stmt -> bindParam(':facilityno' ,$fno);
$stmt -> bindParam(':latitude' ,$latitude);
$stmt -> bindParam(':longitude' ,$longitude);
$stmt -> bindParam(':customerid' ,$customerid);
$stmt -> bindParam(':weight' ,$weight);
$stmt -> bindParam(':numberofpassenger' ,$numberofpassenger);
$stmt -> bindParam(':numberofstop' ,$numberofstop);
$stmt -> bindParam(':numberoffloor' ,$numberoffloor);
$stmt -> bindParam(':opentype' ,$opentype);
$stmt -> bindParam(':speed' ,$speed);
$stmt -> bindParam(':repairtype' ,$repairtype);
$stmt -> bindParam(':maintainance' ,$maintainance);
$stmt -> bindParam(':facility_kind' ,$facility_kind);
$stmt -> bindParam(':address' ,$address);
$stmt -> bindParam(':repairerid' ,$repairerid);
$stmt -> bindParam(':repairername' ,$repairername);
$stmt -> bindParam(':creater' ,$creater);
$stmt -> bindParam(':create_at' ,$create_at);
$stmt -> bindParam(':area' ,$area);
$stmt -> bindParam(':takecertificatedate' ,$takecertificatedate);
$stmt -> bindParam(':licensedate' ,$licensedateeeee);
$result = $stmt -> execute();
}
//create schedule table
@ -247,62 +227,65 @@ if(isset($_POST["contractno"]) && $_POST["contractno"] != "") {
$bonus = 1000;
$max_bonus = 2000;
$englisharr = range('a', 'z');
$file = $_FILES['files'];
$file_name = $file['name'];
$file_type = $file['type'];
$tmp_name = $file['tmp_name'];
$file_size = $file['size'];
$error = $file['error'];
$newfiles = [];
foreach( $files as $file ){
$i = 0; //新陣列的索引編號
foreach( $file as $key => $val ){
$newfiles[$i]['name'] = $files['name'][$key];
$newfiles[$i]['type'] = $files['type'][$key];
$newfiles[$i]['tmp_name'] = $files['tmp_name'][$key];
$newfiles[$i]['error'] = $files['error'][$key];
$newfiles[$i]['size'] = $files['size'][$key];
$i++;
} //foreach 第2層 end
}
echo json_encode($newfiles);
$max_size = 4096*4096; //設定允許上傳檔案容量的最大值(1M)
$allow_ext = array('jpeg', 'jpg', 'png','JPG','JPEG','PNG','GIF'); //設定允許上傳檔案的類型
$path = '../images/contracts/';
if (!file_exists($path)) { mkdir($path); }
$msg_result = ''; //負責接收所有檔案檢測後的回傳訊息
$datetime = (string)date('YmdHis');
$files_id = 'c' . $datetime;
foreach( $newfiles as $key => $file ){
$randNum = rand(1000,9999);
$randEnglish = $englisharr[rand(0,25)];
$file_name = 'c' . (string)date('YmdHis') . $randNum . $randEnglish . $randNum.$file['name'];
$msg = upload_chk( $file,$path, $max_size, $allow_ext, $file_name );
if($msg==1){
$msg = '檔案傳送成功!';
$sql_str = "INSERT INTO contract_back_files (files_id, file_name, file_mime, file_size, created_at, created_by) VALUES (:files_id, :file_name, :file_mime, :file_size, :created_at, :created_by)";
$stmt = $conn -> prepare($sql_str);
$stmt -> bindParam(':files_id' ,$files_id);
$stmt -> bindParam(':file_name' ,$file_name);
$stmt -> bindParam(':file_mime' ,$file['type']);
$stmt -> bindParam(':file_size' ,$file['size']);
$stmt -> bindParam(':created_at' ,$created_at);
$stmt -> bindParam(':created_by' ,$user_id);
$stmt ->execute();
}
$msg_result .= '第' . ($key+1) . '個上傳檔案的結果:' . $msg . '< br / > ';
$src_name = $path.$file['name'];
if( file_exists($src_name) ){
//副檔名
$extname = pathinfo($src_name, PATHINFO_EXTENSION);
//主檔名
$basename = basename($src_name, '.'.$extname);
}
if(!empty($files)){
$englisharr = range('a', 'z');
$file = $_FILES['files'];
$file_name = $file['name'];
$file_type = $file['type'];
$tmp_name = $file['tmp_name'];
$file_size = $file['size'];
$error = $file['error'];
$newfiles = [];
foreach( $files as $file ){
$i = 0; //新陣列的索引編號
foreach( $file as $key => $val ){
$newfiles[$i]['name'] = $files['name'][$key];
$newfiles[$i]['type'] = $files['type'][$key];
$newfiles[$i]['tmp_name'] = $files['tmp_name'][$key];
$newfiles[$i]['error'] = $files['error'][$key];
$newfiles[$i]['size'] = $files['size'][$key];
$i++;
} //foreach 第2層 end
}
$max_size = 4096*4096; //設定允許上傳檔案容量的最大值(1M)
$allow_ext = array('jpeg', 'jpg', 'png','JPG','JPEG','PNG','GIF'); //設定允許上傳檔案的類型
$path = '../images/contracts/';
if (!file_exists($path)) { mkdir($path); }
$msg_result = ''; //負責接收所有檔案檢測後的回傳訊息
$datetime = (string)date('YmdHis');
$files_id = 'c' . $datetime;
foreach( $newfiles as $key => $file ){
$randNum = rand(1000,9999);
$randEnglish = $englisharr[rand(0,25)];
$file_name = 'c' . (string)date('YmdHis') . $randNum . $randEnglish . $randNum.$file['name'];
$msg = upload_chk( $file,$path, $max_size, $allow_ext, $file_name );
if($msg==1){
$msg = '檔案傳送成功!';
$sql_str = "INSERT INTO contract_back_files (files_id, file_name, file_mime, file_size, created_at, created_by) VALUES (:files_id, :file_name, :file_mime, :file_size, :created_at, :created_by)";
$stmt = $conn -> prepare($sql_str);
$stmt -> bindParam(':files_id' ,$files_id);
$stmt -> bindParam(':file_name' ,$file_name);
$stmt -> bindParam(':file_mime' ,$file['type']);
$stmt -> bindParam(':file_size' ,$file['size']);
$stmt -> bindParam(':created_at' ,$created_at);
$stmt -> bindParam(':created_by' ,$user_id);
$stmt ->execute();
}
$msg_result .= '第' . ($key+1) . '個上傳檔案的結果:' . $msg . '< br / > ';
$src_name = $path.$file['name'];
if( file_exists($src_name) ){
//副檔名
$extname = pathinfo($src_name, PATHINFO_EXTENSION);
//主檔名
$basename = basename($src_name, '.'.$extname);
}
}
}else{
$files = null;
}
$sql_str = "INSERT INTO contract_b_signed_back (contract_no, contract_type, company, customer_no, salesperson, contract_start_date, contract_end_date, total_price, opendoor, customer_phone, customer_email, repairman, cycle, contact_person, contact_address, contact_phone, contact_email, takecertificatedate, license_date, elevators_number, spec, weight, speed, numberofpassenger, numberofstop, numberoffloor, latitude, longitude, area, address, files_id, bonus, max_bonus, created_at, created_by)
VALUES (:contract_no, :contract_type, :company, :customer_no, :salesperson, :contract_start_date, :contract_end_date, :total_price, :opendoor, :customer_phone, :customer_email, :repairman, :cycle, :contact_person, :contact_address, :contact_phone, :contact_email, :takecertificatedate, :license_date, :elevators_number, :spec, :weight, :speed, :numberofpassenger, :numberofstop, :numberoffloor, :latitude, :longitude, :area, :address, :files_id, :bonus, :max_bonus, :created_at, :created_by)";
$sql_str = "INSERT INTO contract_b_signed_back (contract_no, contract_type, company, customer_no, salesperson, contract_start_date, contract_end_date, total_price, customer_phone, customer_email, repairman, cycle, contact_person, contact_address, contact_phone, contact_email, elevators_number, area, address, files_id, bonus, max_bonus, created_at, created_by)
VALUES (:contract_no, :contract_type, :company, :customer_no, :salesperson, :contract_start_date, :contract_end_date, :total_price, :customer_phone, :customer_email, :repairman, :cycle, :contact_person, :contact_address, :contact_phone, :contact_email, :elevators_number, :area, :address, :files_id, :bonus, :max_bonus, :created_at, :created_by)";
$stmt = $conn -> prepare($sql_str);
$stmt -> bindParam(":contract_no",$contractno);
$stmt -> bindParam(":contract_type",$contract_type);
@ -312,7 +295,6 @@ if(isset($_POST["contractno"]) && $_POST["contractno"] != "") {
$stmt -> bindParam(":contract_start_date",$contract_begin_date);
$stmt -> bindParam(":contract_end_date",$contract_end_date);
$stmt -> bindParam(":total_price",$total_price);
$stmt -> bindParam(":opendoor",$opendoor);
$stmt -> bindParam(":customer_phone",$customer_phone);
$stmt -> bindParam(":customer_email",$customer_email);
$stmt -> bindParam(":repairman",$repairman);
@ -321,17 +303,7 @@ if(isset($_POST["contractno"]) && $_POST["contractno"] != "") {
$stmt -> bindParam(":contact_address",$contact_address);
$stmt -> bindParam(":contact_phone",$contact_phone);
$stmt -> bindParam(":contact_email",$contact_email);
$stmt -> bindParam(":takecertificatedate",$takecertificatedate);
$stmt -> bindParam(":license_date",$license_date);
$stmt -> bindParam(":elevators_number",$elevators_number);
$stmt -> bindParam(":spec",$spec);
$stmt -> bindParam(":weight",$weight);
$stmt -> bindParam(":speed",$speed);
$stmt -> bindParam(":numberofpassenger",$numberofpassenger);
$stmt -> bindParam(":numberofstop",$numberofstop);
$stmt -> bindParam(":numberoffloor",$numberoffloor);
$stmt -> bindParam(":latitude",$latitude);
$stmt -> bindParam(":longitude",$longitude);
$stmt -> bindParam(":area",$area);
$stmt -> bindParam(":address",$address);
$stmt -> bindParam(":files_id",$files_id);
@ -347,8 +319,8 @@ if(isset($_POST["contractno"]) && $_POST["contractno"] != "") {
$conn->commit();
}catch(PDOException $e){
$r = $ conn->rollback();
echo $r ;
$conn->rollback();
echo $e->getMessage() ;
die('Error!:'.$e->getMessage());
}
}
@ -411,4 +383,4 @@ function upload_chk( $file, $path, $max_size, $allow_ext, $file_name ){
} //if( $error == 0 ){ ..... end
return $msg; //回傳$msg的結果
}// function end
}