You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
184 lines
9.7 KiB
184 lines
9.7 KiB
<?php
|
|
require_once("../conn.php");
|
|
include_once("./getFacilityNo.php");
|
|
include_once("./getComboNo.php");
|
|
ini_set ( 'date.timezone' , 'Asia/Taipei' );
|
|
if(isset($_POST["contractno"]) && $_POST["contractno"] != "") {
|
|
try{
|
|
|
|
$contractno = !empty($_POST['contractno'])? $_POST['contractno'] : null;
|
|
$total_price = !empty($_POST['total_price']) ? $_POST['total_price'] : null;
|
|
$vat = !empty($_POST['vat']) ? $_POST['vat'] : null;
|
|
$mtype = !empty($_POST['mtype']) ? $_POST['mtype'] :null;
|
|
$opendoor = !empty($_POST['opendoor']) ? $_POST['opendoor']: null;
|
|
$phone = !empty($_POST['phone']) ? $_POST['phone'] : null;
|
|
$email = !empty($_POST['email']) ? $_POST['email'] : null;
|
|
$mworker = !empty($_POST['mworker']) ? $_POST['mworker'] : null;
|
|
$mcycle = !empty($_POST['mcycle']) ? $_POST['mcycle'] : null;
|
|
$salesman = !empty($_POST['salesman']) ?$_POST['salesman'] : null;
|
|
$contract_begin_date = !empty($_POST['contract_begin_date']) ? $_POST['contract_begin_date'] : null;
|
|
$contract_end_date = !empty($_POST['contract_end_date']) ? $_POST['contract_end_date'] : null;
|
|
$address = !empty($_POST['address']) ? $_POST['address'] : null;
|
|
$area = !empty($_POST['area']) ? $_POST['area'] : null;
|
|
$customer = !empty($_POST['customer']) ? $_POST['customer'] : null;
|
|
$partyA = !empty($_POST['partyA']) ? $_POST['partyA'] : null;
|
|
$partyAaddress = !empty($_POST['partyAaddress']) ? $_POST['partyAaddress'] : null;
|
|
$partyAphone = !empty($_POST['partyAphone']) ? $_POST['partyAphone'] : null;
|
|
$partyAemail = !empty($_POST['partyAemail']) ? $_POST['partyAemail'] : null;
|
|
$user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null;
|
|
$user_name = !empty($_POST['user_name']) ? $_POST['user_name'] : null;
|
|
$spec = !empty($_POST['spec']) ? $_POST['spec'] : null;
|
|
$weight = !empty($_POST['weight']) ? $_POST['weight'] : null;
|
|
$numberofpassenger = !empty($_POST['numberofpassenger']) ? $_POST['numberofpassenger'] : null;
|
|
$numberofstop = !empty($_POST['numberofstop']) ? $_POST['numberofstop'] : null;
|
|
$numberoffloor = !empty($_POST['numberoffloor']) ? $_POST['numberoffloor'] : null;
|
|
$speed = !empty($_POST['speed']) ? $_POST['speed'] : null;
|
|
$takecertificatedate = !empty($_POST['takecertificatedate']) ? $_POST['takecertificatedate'] : null;
|
|
$maintainance = !empty($_POST['maintainance']) ? $_POST['maintainance'] : null;
|
|
$licensedate = !empty($_POST['licensedate']) ? $_POST['licensedate'] : null;
|
|
$latitude = !empty($_POST['latitude']) ? $_POST['latitude'] : null;
|
|
$longitude = !empty($_POST['longitude']) ? $_POST['longitude'] : null;
|
|
$num = !empty($_POST['num']) ? $_POST['num'] : null;
|
|
|
|
$files = !empty($_FILES['files']) ? $_FILES['files'] : null;
|
|
|
|
//create account table
|
|
$accounttype = "A";
|
|
$accountid = $vat;
|
|
$pwd = "123";
|
|
$name = $partyA;
|
|
$tel = $phone ?? '';
|
|
$repairerid = $mworker;
|
|
$creater = $user_id;
|
|
$create_at = date('Y-m-d H:i:s');
|
|
|
|
$sql_str = "INSERT INTO account (accounttype, accountid, pwd, name, tel, address, email, repairerid, creater, create_at) VALUES (:accounttype, :accountid, :pwd, :name, :tel, :address, :email, :repairerid, :creater, :create_at)";
|
|
$stmt = $conn -> prepare($sql_str);
|
|
$stmt -> bindParam(':accounttype' ,$accounttype);
|
|
$stmt -> bindParam(':accountid' ,$accountid);
|
|
$stmt -> bindParam(':pwd' ,$pwd);
|
|
$stmt -> bindParam(':name' ,$name);
|
|
$stmt -> bindParam(':tel' ,$tel);
|
|
$stmt -> bindParam(':address' ,$address);
|
|
$stmt -> bindParam(':email' ,$email);
|
|
$stmt -> bindParam(':repairerid' ,$repairerid);
|
|
$stmt -> bindParam(':creater' ,$creater);
|
|
$stmt -> bindParam(':create_at' ,$create_at);
|
|
$stmt -> execute();
|
|
|
|
//create contract table
|
|
|
|
$contracttype = $mtype;
|
|
$company = $partyA;
|
|
$taxid = $vat;
|
|
$tel = $phone;
|
|
$promiser = $partyA;
|
|
$contractperson = $partyA;
|
|
|
|
$contractaddress = $address;
|
|
$contracttel = $phone;
|
|
$contractemail = $email;
|
|
$contract_employee = $salesman;
|
|
$start_date = $contract_begin_date;
|
|
$end_date = $contract_end_date;
|
|
|
|
$sql_str = "INSERT INTO contract (contracttype, contractno, company, taxid, address, tel, promiser, contractperson, contractaddress, contracttel, contractemail, contract_employee, start_date, end_date, creater, create_at) VALUES (:contracttype, :contractno, :company, :taxid, :address, :tel, :promiser, :contractperson, :contractaddress, :contracttel, :contractemail, :contract_employee, :start_date, :end_date, :creater, :create_at)";
|
|
$stmt = $conn -> prepare($sql_str);
|
|
$stmt -> bindParam(':contracttype' ,$contracttype);
|
|
$stmt -> bindParam(':contractno' ,$contractno);
|
|
$stmt -> bindParam(':company' ,$company);
|
|
$stmt -> bindParam(':taxid' ,$taxid);
|
|
$stmt -> bindParam(':address' ,$address);
|
|
$stmt -> bindParam(':tel' ,$tel);
|
|
$stmt -> bindParam(':promiser' ,$promiser);
|
|
$stmt -> bindParam(':contractperson' ,$contractperson);
|
|
$stmt -> bindParam(':contractaddress' ,$contractaddress);
|
|
$stmt -> bindParam(':contracttel' ,$contracttel);
|
|
$stmt -> bindParam(':contractemail' ,$contractemail);
|
|
$stmt -> bindParam(':contract_employee' ,$contract_employee);
|
|
$stmt -> bindParam(':start_date' ,$start_date);
|
|
$stmt -> bindParam(':end_date' ,$end_date);
|
|
$stmt -> bindParam(':creater' ,$creater);
|
|
$stmt -> bindParam(':create_at' ,$create_at);
|
|
$stmt -> execute();
|
|
|
|
//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);
|
|
|
|
$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'];
|
|
|
|
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' ,$licensedate);
|
|
|
|
$result = $stmt -> execute();
|
|
}
|
|
|
|
//create schedule table
|
|
$comboMo = new CreateComboNo();
|
|
|
|
$sql_str = 'INSERT INTO schedule (contractno, facilityno, combono, repairerid, repairername, duedate, creater, create_at) VALUES (:contractno, :facilityno, :combono, :repairerid, :repairername, :duedate, :creater, :create_at)';
|
|
$stmt = $conn -> prepare($sql_str);
|
|
$stmt -> bindParam(':contractno' ,$contractno);
|
|
$stmt -> bindParam(':facilityno' ,$facilityno);
|
|
$stmt -> bindParam(':combono' ,$combono);
|
|
$stmt -> bindParam(':repairerid' ,$repairerid);
|
|
$stmt -> bindParam(':repairername' ,$repairername);
|
|
$stmt -> bindParam(':duedate' ,$duedate);
|
|
$stmt -> bindParam(':creater' ,$creater);
|
|
$stmt -> bindParam(':create_at' ,$create_at);
|
|
$result = $stmt -> execute();
|
|
|
|
header('Content-Type: application/json');
|
|
$jsonData = json_encode($files);
|
|
|
|
}catch(PDOException $e){
|
|
die('Error!:'.$e->getMessage());
|
|
}
|
|
}
|