Browse Source

rebase

gary
10994015 1 year ago
parent
commit
6342bcd477
  1. 59
      wms/contract/api/getComboNo.php
  2. 4
      wms/contract/api/getContractData.php
  3. 0
      wms/contract/api/getFacilityNo.php
  4. 371
      wms/contract/api/postContractData.php
  5. 258
      wms/contract/contract-input.php

59
wms/contract/api/getComboNo.php

@ -0,0 +1,59 @@
<?php
class CreateComboNo{
private $comboarr = [
'week'=>'BW002',
'month'=>'EM002',
'quarter'=>'EQ002',
'half'=>'HY002',
'year'=>'EY002'
];
private $bwarr = [
'week','month','week','month','week','quarter',
'week','month','week','month','week','half',
'week','month','week','month','week','quarter',
'week','month','week','month','week','year'
];
private $emarr = [
'month','month','quarter','month','month','half',
'month','month','quarter','month','month','year'
];
private $combo;
private $startdate;
private $enddate;
public function __construct($combo, $startdate, $enddate){
$this->combo = $combo;
$this->startdate = $startdate;
$this->enddate = $enddate;
}
public function getComboNo(){
$comboarr = (array) $this->combo === 'bw' ? $this->bwarr : $this->emarr;
$startdate = new DateTime($this->startdate);
$enddate = new DateTime($this->enddate);
$interval = date_diff($startdate, $enddate);
$months = $interval->y * 12 + $interval->m;
$months = $this->combo === 'bw' ? $months*2 : $months;
$newarr = [];
$idx = 0;
$ori_first_month = date('m', strtotime($this->startdate));
$first_day = date('Y-m-d', strtotime($this->startdate. ' + 3 days'));
$new_first_month = date('m', strtotime($first_day));
if($ori_first_month != $new_first_month){
$first_day = date('Y-m-t', strtotime($this->startdate));
}
$scheduleDate = new DateTime($first_day);
for ($i = 0; $i < $months; $i++){
$newarr[] = [$this->comboarr[$comboarr[$idx]], $scheduleDate->format("Y-m-d")];
$idx ++;
$scheduleDate = $startdate->modify("+1 month");
if($idx >= count($comboarr)){
$idx = 0;
}
}
return json_encode($newarr);
}
}

4
wms/contract/api/getContractData.php

@ -3,9 +3,9 @@ require_once('../conn.php');
if(isset($_GET['contractno']) && $_GET['contractno']!=''){
try{
$contractno = $_GET['contractno'];
$sql_str = "SELECT * FROM con_maintance_examine_apply
$sql_str = "SELECT COUNT(con_maintance_examine_clear.apply_key) as count,con_maintance_examine_apply.*, con_maintance_examine_clear.* FROM con_maintance_examine_apply
LEFT JOIN con_maintance_examine_clear on con_maintance_examine_apply.apply_key=con_maintance_examine_clear.apply_key
WHERE con_maintance_examine_apply.vol_no = :vol_no";
WHERE con_maintance_examine_apply.vol_no = :vol_no GROUP BY con_maintance_examine_apply.apply_key;";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':vol_no', $contractno);
$stmt->execute();

0
wms/contract/api/createFacilityNo.php → wms/contract/api/getFacilityNo.php

371
wms/contract/api/postContractData.php

@ -1,45 +1,85 @@
<?php
require_once("../conn.php");
include_once("./createFacilityNo.php");
include_once("./getFacilityNo.php");
include_once("./getComboNo.php");
ini_set ( 'date.timezone' , 'Asia/Taipei' );
if(isset($_POST["contractno"]) && $_POST["contractno"] != "") {
try{
$created_at = date('Y-m-d H:i:s');
$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;
$contractno = $_POST['contractno'] ?? '';
$total_price = $_POST['total_price'] ?? '';
$vat = $_POST['vat'] ?? '';
$mtype = $_POST['mtype'] ?? '';
$opendoor = $_POST['opendoor'] ?? '';
$phone = $_POST['phone'] ?? '';
$email = $_POST['email'] ?? '';
$mworker = $_POST['mworker'] ?? '';
$mcycle = $_POST['mcycle'] ?? '';
$salesman = $_POST['salesman'] ?? '';
$contract_begin_date = $_POST['contract_begin_date'] ?? '';
$contract_end_date = $_POST['contract_end_date'] ?? '';
$address = $_POST['address'] ?? '';
$area = $_POST['area'] ?? '';
$customer = $_POST['customer'] ?? '';
$partyA = $_POST['partyA'] ?? '';
$partyAaddress = $_POST['partyAaddress'] ?? '';
$partyAphone = $_POST['partyAphone'] ?? '';
$partyAemail = $_POST['partyAemail'] ?? '';
$user_id = $_POST['user_id'] ?? '';
$user_name = $_POST['user_name'] ?? '';
$spec = $_POST['spec'] ??'';
$weight = $_POST['weight'] ??'';
$numberofpassenger = $_POST['numberofpassenger'] ??'';
$numberofstop = $_POST['numberofstop'] ??'';
$numberoffloor = $_POST['numberoffloor'] ??'';
$speed = $_POST['speed'] ??'';
$takecertificatedate = $_POST['takecertificatedate'] ??'';
$maintainance = $_POST['maintainance'] ??'';
$licensedate = $_POST['licensedate'] ??'';
$latitude = $_POST['latitude'] ??'';
$longitude = $_POST['longitude'] ??'';
$num = $_POST['num'] ??'';
$files = $_FILES['files'] ?? '';
// validate
$fail_arr = [];
if($contractno === '') return $fail_arr[] = '合約號為必填';
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[] = '保養員為必填';
if($mcycle == '') $fail_arr[] = '保養頻率為必填';
if($salesman == '') $fail_arr[] = '營業員為必填';
if($contract_begin_date == '') $fail_arr[] = '合約開始時間為必填';
if($contract_end_date == '') $fail_arr[] = '合約結束時間為必填';
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(count($fail_arr) > 0) {
header("HTTP/1.1 422 Unprocessable Entity");
echo json_encode($fail_arr);
exit();
}
//create account table
$accounttype = "A";
@ -51,6 +91,8 @@ if(isset($_POST["contractno"]) && $_POST["contractno"] != "") {
$creater = $user_id;
$create_at = date('Y-m-d H:i:s');
$conn->beginTransaction();
$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);
@ -80,8 +122,6 @@ if(isset($_POST["contractno"]) && $_POST["contractno"] != "") {
$contract_employee = $salesman;
$start_date = $contract_begin_date;
$end_date = $contract_end_date;
$creater = $user_id;
$create_at = date('Y-m-d H:i:s');
$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);
@ -119,9 +159,8 @@ if(isset($_POST["contractno"]) && $_POST["contractno"] != "") {
$stmt->execute();
$worker = $stmt->fetch(PDO::FETCH_ASSOC);
$facilityno = $createFacilityNo->makeBFacilityNo("T", $dailyNecessities[$spec], (int)$num);
$define = "B";
$facilityno = $createFacilityNo->makeTFacilityNo("T", $dailyNecessities[$spec], $num)[0];
echo $facilityno;
$customerid = $vat;
$opentype = $opendoor;
$repairtype = "A";
@ -129,41 +168,237 @@ if(isset($_POST["contractno"]) && $_POST["contractno"] != "") {
$maintainance = "E";
$repairerid = $mworker;
$repairername = $worker['name'];
$creater = $user_id;
$create_at = date("Y-m-d H:i:s");
$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)";
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
$comboNo = new CreateComboNo($mcycle, $contract_begin_date, $contract_end_date);
$comboArr = json_decode($comboNo->getComboNo(), true);
foreach($facilityno as $no){
foreach($comboArr as $combo){
$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' ,$no);
$stmt -> bindParam(':combono' ,$combo[0]);
$stmt -> bindParam(':repairerid' ,$repairerid);
$stmt -> bindParam(':repairername' ,$repairername);
$stmt -> bindParam(':duedate' ,$combo[1]);
$stmt -> bindParam(':creater' ,$creater);
$stmt -> bindParam(':create_at' ,$create_at);
$result = $stmt -> execute();
}
}
// create contract_b_signed_back table
$contract_type = $mtype;
$company = $customer;
$customer_no = $vat;
$salesperson = $salesman;
$customer_phone = $phone;
$customer_email = $email;
$repairman = $mworker;
$cycle = $mcycle;
$contact_person = $partyA;
$contact_address = $partyAaddress;
$contact_phone = $partyAphone;
$contract_email = $partyAemail;
$elevators_number = $num;
$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);
}
}
$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)";
$stmt = $conn -> prepare($sql_str);
$stmt -> bindParam(':contractno' ,$contractno);
$stmt -> bindParam(':define' ,$define);
$stmt -> bindParam(':facilityno' ,$facilityno);
$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);
$stmt -> bindParam(":contract_no",$contractno);
$stmt -> bindParam(":contract_type",$contract_type);
$stmt -> bindParam(":company",$company);
$stmt -> bindParam(":customer_no",$customer_no);
$stmt -> bindParam(":salesperson",$salesperson);
$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);
$stmt -> bindParam(":cycle",$cycle);
$stmt -> bindParam(":contact_person",$contact_person);
$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);
$stmt -> bindParam(":bonus",$bonus);
$stmt -> bindParam(":max_bonus",$max_bonus);
$stmt -> bindParam(":created_at", $created_at);
$stmt -> bindParam(":created_by",$user_id);
$result = $stmt -> execute();
$stmt -> execute();
header('Content-Type: application/json');
$jsonData = json_encode($files);
$conn->commit();
}catch(PDOException $e){
$r = $conn->rollback();
echo $r;
die('Error!:'.$e->getMessage());
}
}
function upload_chk( $file, $path, $max_size, $allow_ext, $file_name ){
$source_file_name = $file['name']; //上傳檔案的原來檔案名稱
$file_type = $file['type']; //上傳檔案的類型(副檔名)
$tmp_name = $file['tmp_name']; //上傳到暫存空間的路徑/檔名
$file_size = $file['size']; //上傳檔案的檔案大小(容量)
$error = $file['error']; //上傳工作傳回的錯誤訊息編號
$msg = ''; //負責記錄回傳的訊息
//1.判斷錯誤編號只有為0時表示沒有錯誤發生,才表示上傳成功 =================
if( $error == 0 ){
//取得檔案延伸的副檔名, 以下函數可以取得檔案延伸的副檔名
//pathinfo(上傳檔案的原來檔案名稱, PATHINFO_EXTENSION)
$ext = pathinfo($source_file_name, PATHINFO_EXTENSION);
$ext = strtolower($ext); //將延伸的副檔名轉小寫
//2.判斷上傳檔案的大小 ====================================
if( $file_size > $max_size ){
//當目前檔案容量超過容量限制時, 以下準備顯示的資訊
if( $max_size >= 4096*4096 ){
$max_size /= (4096*4096);
$max_size .= 'M';
}elseif( $max_size >= 4096 ){
$max_size /= 4096;
$max_size .= 'K';
}
$msg ='上傳檔案過大,請選擇容量小於 '.$max_size.' 的檔案';
//3.判斷檔案類型 ===========================================
//in_array($ext, $allow_ext) 判斷 $ext變數的值 是否在 $allow_ext 這個陣列變數中
}elseif( !in_array( $ext, $allow_ext ) ){
$allow_str = ''; //準備將允許檔案類型的陣列內容, 組合成字串
foreach( $allow_ext as $key=>$value ){
//if的縮寫語法:條件?成立執行的工作:不成立執行的工作;
$key==0? $allow_str.= $value : $allow_str.=', '.$value;
}
$msg = '檔案類型不符合,請選擇 '.$allow_str.' 檔案';
//4.以上條件都沒問題的話, 則進行最後else中的工作===============
}else{
//搬移檔案 move_uploaded_file(要搬移的檔案, 目的地位置及目的檔案名稱), 成功傳回true(1)
$msg = @move_uploaded_file($tmp_name, $path.$file_name);
}
}else{
//這裡表示上傳有錯誤, 匹配錯誤編號顯示對應的訊息 ======================================
switch ($error) {
case 1: $msg = '上傳檔案超過 upload_max_filesize 容量最大值'; break;
case 2: $msg = '上傳檔案超過 post_max_size 總容量最大值'; break;
case 3: $msg = '檔案只有部份被上傳'; break;
case 4: $msg = '沒有檔案被上傳'; break;
case 6: $msg = '找不到主機端暫存檔案的目錄位置'; break;
case 7: $msg = '檔案寫入失敗'; break;
case 8: $msg = '上傳檔案被PHP程式中斷,表示主機端系統錯誤'; break;
}
} //if( $error == 0 ){ ..... end
return $msg; //回傳$msg的結果
}// function end

258
wms/contract/contract-input.php

@ -1,6 +1,7 @@
<?php
include("../header.php");
require_once("./conn.php");
include_once("./api/getFacilityNo.php");
$accounttype = "B";
$sql_str = "SELECT accountid, name FROM account WHERE accounttype = :accounttype";
$stmt = $conn->prepare($sql_str);
@ -13,6 +14,9 @@ $stmt = $conn->prepare($sql_str);
$stmt->bindParam(':accounttype',$accounttype);
$stmt->execute();
$contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
$createFacilityNo = new CreateFacilityNo();
$facilityno = $createFacilityNo->makeTFacilityNo("T", 'X', 5);
?>
<link rel="stylesheet" href="./styles/style.css">
<link rel="stylesheet" href="semantic/dist/semantic.min.css">
@ -20,17 +24,16 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.5.0/axios.min.js" integrity="sha512-aoTNnqZcT8B4AmeCFmiSnDlc4Nj/KPaZyB5G7JnOnUEkdNpCZs1LCankiYi01sLTyWy+m2P+W4XM+BuQ3Q4/Dg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<div class="contract-input-component" x-data="{
async init(){
$('select.dropdown')
.dropdown();
await axios.get('./twzip.json').then(res=>{
init(){
$('.contract-input-component .form .dropdown').dropdown();
axios.get('./twzip.json').then(res=>{
this.cities = res.data.cities
console.log(this.cities);
})
},
cities:[],
data:{
contractno:'',
contractno:'Q23080026',
total_price:'', //合約總價
vat:'', //統一編號
mtype:'A', //維修型態
@ -51,7 +54,8 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
partyAphone:'', //業務聯繫人電話
partyAemail:'', //業務聯繫人email
files:[], //附件檔案
spec:'', //規格
spec:'', //機種
brand:'', //廠牌
weight: '', //載重
numberofpassenger: '', //人乘
numberofstop:'', //樓停
@ -61,56 +65,36 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
takecertificatedate:'', //交車日、竣檢日
licensedate:'', //許可證有效日期
num:'', //電梯數量
latitude:'', //緯度
longitude:'', //經度
},
customize:false,
step:1,
isLoading:false,
fail_arr:[],
nextStepFn(){
this.isLoading = true
axios.get('./api/getContractData.php?contractno=' + this.data.contractno).then(res=>{
console.log(res)
if(!this.customize){
this.data.total_price = res.data.sold_price
this.data.salesman = res.data.salesman
this.data.contract_begin_date = res.data.contract_begin_date
this.data.contract_end_date = res.data.contract_end_date
this.data.address = res.data.address
this.data.customer = res.data.customer
this.data.partyA = res.data.customer
this.data.partyAaddress = res.data.address
this.data.spec = res.data.spec
this.data.weight = res.data.weight
this.data.numberofpassenger = res.data.persons
this.data.numberofstop = res.data.stop
this.data.numberoffloor = res.data.floors
this.data.speed = res.data.speed
this.data.takecertificatedate = res.data.contract_begin_date
let cityIndex = this.data.address.indexOf('市');
if (cityIndex > 1) {
// 獲取''市''前面的兩個字
let city = this.data.address.substring(cityIndex - 2, cityIndex + 1);
this.data.area = city;
console.log(this.data.area);
} else {
this.data.area = ''
console.log('沒有找到或者格式不正確');
}
}
this.step = 2
this.isLoading = false
}).catch(err=>{
console.error(err)
this.isLoading = false
})
if(this.step==1){
if(this.data.contractno == '') return alert('請輸入合約號');
this.isLoading = true
this.getContractDate();
}else if(this.step == 2){
this.step = 3
}
},
nextStepKeyupFn(e){
if(e.keyCode !== 13) return
this.isLoading = true
if(this.step==1){
if(this.data.contractno == '') return alert('請輸入合約號');
this.isLoading = true
this.getContractDate();
}else if(this.step == 2){
this.step = 3
}
},
getContractDate(){
axios.get('./api/getContractData.php?contractno=' + this.data.contractno).then(res=>{
console.log(res)
if(!this.customize){
console.log(res.data);
this.data.total_price = res.data.sold_price
this.data.salesman = res.data.salesman
this.data.contract_begin_date = res.data.contract_begin_date
@ -131,10 +115,8 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
// 獲取''市''前面的兩個字
let city = this.data.address.substring(cityIndex - 2, cityIndex + 1);
this.data.area = city;
console.log(this.data.area);
} else {
this.data.area = ''
console.log('沒有找到或者格式不正確');
}
}
this.step = 2
@ -145,26 +127,33 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
})
},
preStepFn(){
this.data.total_price = ''
this.data.salesman = ''
this.data.contract_begin_date = ''
this.data.contract_end_date = ''
this.data.address = ''
this.data.customer = ''
this.data.partyA = ''
this.data.partyAaddress = ''
this.data.spec = ''
this.data.weight = ''
this.data.numberofpassenger = ''
this.data.numberofstop = ''
this.data.numberoffloor = ''
this.data.speed = ''
this.data.takecertificatedate = ''
this.step = 1
if(this.step==2){
if(confirm('回到上一頁會將本頁資料清空,確定返回嗎?')){
this.step = 1
this.data.total_price = ''
this.data.salesman = ''
this.data.contract_begin_date = ''
this.data.contract_end_date = ''
this.data.address = ''
this.data.customer = ''
this.data.partyA = ''
this.data.partyAaddress = ''
this.data.spec = ''
this.data.weight = ''
this.data.numberofpassenger = ''
this.data.numberofstop = ''
this.data.numberoffloor = ''
this.data.speed = ''
this.data.takecertificatedate = ''
this.step = 1
return;
}
}else if(this.step == 3){
this.step = 2
}
},
save(){
this.isLoading = true
console.log(this.data.files[0] instanceof File);
const form = new FormData();
form.append('contractno', this.data.contractno);
form.append('total_price', this.data.total_price);
@ -198,6 +187,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
form.append('longitude', this.data.longitude);
form.append('user_id', '<?php echo $user_id; ?>');
form.append('user_name', '<?php echo $user_name; ?>');
form.append('num', this.data.num);
// 如果有附件檔案,可以逐一加入
for (var i = 0; i < this.data.files.length; i++) {
@ -207,15 +197,26 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
console.log(res);
this.isLoading = false
}).catch(error=>{
console.log(error);
let code = error.response.status;
if(code == 422){
this.fail_arr = error.response.data
this.errorFn();
}
this.isLoading = false
})
},
errorFn(){
let msg = ''
for(let i = 0; i < this.fail_arr.length; i++){
msg += this.fail_arr[i] + '、'
}
alert(msg)
},
uploadFiles(e){
this.data.files = e.target.files
}
},
}">
<div class="form" method="post" id="form" enctype="multipart/form-data" >
<input type="hidden" name='form_name' value="main_form" />
<div>
@ -259,35 +260,40 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
<td style="vertical-align: middle">立約人</td>
<td>
<input type="text" x-model="data.customer" />
<p class="alerttext" x-show="data.customer==''">未填寫</p>
</td>
<td style="vertical-align: middle">營業員</td>
<td>
<select class="ui search dropdown" name="promiser" x-model="data.salesman">
<select class="ui fluid search dropdown" name="promiser" x-model="data.salesman">
<option value="">選擇營業員</option>
<?php foreach($contractpersons as $person){ ?>
<option value="<?php echo $person['accountid'] ?>"><?php echo $person['name'] ?></option>
<?php } ?>
</select>
<p class="alerttext" x-show="data.salesman==''">未填寫</p>
</td>
<td style="vertical-align: middle">合約開始時間</td>
<td>
<input class="form-control disabled_select" type="date" name="start_date" x-model="data.contract_begin_date" >
<p class="alerttext" x-show="data.contract_begin_date==''">未填寫</p>
</td>
<td style="vertical-align: middle">合約終止時間</td>
<td>
<input class="form-control disabled_select" type="date" name="end_date" x-model="data.contract_end_date" >
<p class="alerttext" x-show="data.contract_end_date==''">未填寫</p>
</td>
</tr>
<tr>
<td style="vertical-align: middle">合約總價</td>
<td style="vertical-align: middle">電梯台數</td>
<td>
<input class="form-control " type="number" name="total_pirce" x-model="data.total_price" >
<input class="form-control disabled_select" type="number" x-model="data.num">
<p class="alerttext" x-show="data.num==''">未填寫</p>
</td>
<td style="vertical-align: middle">統一編號/身分證</td>
<td>
<input class="form-control disabled_select" type="text" name="uscc" x-model="data.vat" >
<p class="alerttext" x-show="data.vat==''">未填寫</p>
</td>
<td style="vertical-align: middle">維修型態</td>
<td style="vertical-align: middle">
@ -295,6 +301,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
<option value="" >選擇維修型態</option>
<option value="A">定期保養</option>
</select>
<p class="alerttext" x-show="data.mtype==''">未填寫</p>
</td>
<td style="vertical-align: middle">
開門方式
@ -312,16 +319,19 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
<option value="6PCO">6PCO</option>
<option value="CO">CO</option>
</select>
<p class="alerttext" x-show="data.opendoor==''">未填寫</p>
</td>
</tr>
<tr>
<td style="vertical-align: middle">客戶電話</td>
<td>
<input class="form-control disabled_select" type="text" name="tel" x-model="data.phone" >
<p class="alerttext" x-show="data.phone==''">未填寫</p>
</td>
<td style="vertical-align: middle">Email</td>
<td style="vertical-align: middle">
<input class="form-control disabled_select" type="text" name="email" x-model="data.email" >
<p class="alerttext" x-show="data.email==''">未填寫</p>
</td>
<td style="vertical-align: middle">保養員</td>
<td>
@ -331,32 +341,60 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
<option value="<?php echo $worker['accountid']; ?>"><?php echo $worker['name'] ?></option>
<?php } ?>
</select>
<p class="alerttext" x-show="data.mworker==''">未填寫</p>
</td>
<td style="vertical-align: middle">保養頻率</td>
<td>
<select class="ui search dropdown" name="repairer_name" x-model="data.mcycle">
<option value="">選擇保養頻率</option>
<option value="A">雙週保</option>
<option value="B">月保</option>
<option value="bw">雙週保</option>
<option value="em">月保</option>
</select>
<p class="alerttext" x-show="data.mcycle==''">未填寫</p>
</td>
</tr>
<tr>
<td style="vertical-align: middle">業務聯繫人</td>
<td>
<input type="text" x-model="data.partyA" name="partyA" />
<p class="alerttext" x-show="data.partyA==''">未填寫</p>
</td>
<td style="vertical-align: middle">業務聯繫人地址</td>
<td>
<input class="form-control disabled_select" x-model="data.partyAaddress" type="text" name="contractaddress" value="" >
<p class="alerttext" x-show="data.partyAaddress==''">未填寫</p>
</td>
<td style="vertical-align: middle">業務聯繫人電話</td>
<td>
<input class="form-control disabled_select" type="text" name="contracttel" x-model="data.partyAphone" >
<p class="alerttext" x-show="data.partyAphone==''">未填寫</p>
</td>
<td style="vertical-align: middle">業務聯繫人Email</td>
<td>
<input class="form-control disabled_select" type="text" name="contracttel" x-model="data.partyAemail" >
<p class="alerttext" x-show="data.partyAemail==''">未填寫</p>
</td>
</tr>
<tr>
<td style="vertical-align: middle">廠牌</td>
<td>
<input type="text" x-model="data.brand" class="form-control" />
<p class="alerttext" x-show="data.brand==''">未填寫</p>
</td>
<td style="vertical-align: middle">區域</td>
<td>
<select class="ui search dropdown" x-model="data.area">
<option value="">選擇區域</option>
<template x-for="city in cities" :key="city.code">
<option x-bind:selected="city.name === data.area" x-text="city.name" :value="city.name"></option>
</template>
</select>
<p class="alerttext" x-show="data.area==''">未填寫</p>
</td>
<td style="vertical-align: middle">詳細地址</td>
<td colspan="3">
<input type="text" x-model="data.address" />
<p class="alerttext" x-show="data.address==''">未填寫</p>
</td>
</tr>
<tr>
@ -367,27 +405,34 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
<option value="A">全包</option>
<option value="B">半包</option>
<option value="C">清包</option>
<option value="D">半包:2個月保養一次</option>
<option value="E">半包:1個月保養兩次 </option>
</select>
<p class="alerttext" x-show="data.maintainance==''">未填寫</p>
</td>
<td style="vertical-align: middle">竣檢日</td>
<td>
<input class="form-control disabled_select" type="date" x-model="data.takecertificatedate">
<p class="alerttext" x-show="data.takecertificatedate==''">未填寫</p>
</td>
<td style="vertical-align: middle">許可證有效時間</td>
<td>
<input class="form-control disabled_select" type="date" x-model="data.licensedate">
<p class="alerttext" x-show="data.licensedate==''">未填寫</p>
</td>
<td style="vertical-align: middle">電梯數量</td>
<td>
<input class="form-control " type="number" x-model="data.num">
<td style="vertical-align: middle">附件</td>
<td >
<input type="file" name="file[]" multiple draggable="true" @change="uploadFiles($event)" />
<p class="alerttext" x-show="data.files==''">未填寫</p>
</td>
</tr>
<tr>
<td style="vertical-align: middle">規格</td>
</tr>
</tbody>
</template>
<template x-if="step==3">
<tbody style="font-weight: bolder;margin-bottom: 20px" x-show="step==3">
<tr>
<td style="vertical-align: middle">機種</td>
<td>
<select class="ui search dropdown" name="spec" x-model="data.spec">
<option value="">選擇規格</option>
@ -398,80 +443,70 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
<option value="MAF100">MAF100</option>
<option value="MAZ100">MAZ100</option>
</select>
<p class="alerttext" x-show="data.spec==''">未填寫</p>
</td>
<td style="vertical-align: middle">載重</td>
<td>
<input type="text" x-model="data.weight" />
<p class="alerttext" x-show="data.weight==''">未填寫</p>
</td>
<td style="vertical-align: middle">速度</td>
<td>
<input type="text" x-model="data.speed" />
<p class="alerttext" x-show="data.speed==''">未填寫</p>
</td>
<td style="vertical-align: middle">人乘</td>
<td>
<input type="text" x-model="data.numberofpassenger" />
<p class="alerttext" x-show="data.numberofpassenger==''">未填寫</p>
</td>
</tr>
<tr>
<td style="vertical-align: middle">樓停</td>
<td>
<input type="text" x-model="data.numberofstop" />
<input type="number" class="form-control" x-model="data.numberofstop" />
<p class="alerttext" x-show="data.numberofstop==''">未填寫</p>
</td>
<td style="vertical-align: middle">樓層</td>
<td>
<input type="text" x-model="data.numberoffloor" />
<p class="alerttext" x-show="data.numberoffloor==''">未填寫</p>
</td>
<td style="vertical-align: middle">緯度</td>
<td>
<input type="text" x-model="data.latitude" />
<p class="alerttext" x-show="data.latitude==''">未填寫</p>
</td>
<td style="vertical-align: middle">經度</td>
<td>
<input type="text" x-model="data.longitude" />
<p class="alerttext" x-show="data.longitude==''">未填寫</p>
</td>
</tr>
<tr>
<td style="vertical-align: middle">區域</td>
<td>
<select class="ui search dropdown" x-model="data.area">
<option value="">選擇區域</option>
<template x-for="city in cities" :key="city.code">
<option x-bind:selected="city.name === data.area" x-text="city.name" :value="city.name"></option>
</template>
</select>
</td>
<td style="vertical-align: middle">詳細地址</td>
<td colspan="3">
<input type="text" x-model="data.address" />
</td>
<td style="vertical-align: middle">附件</td>
<td>
<input type="file" name="file[]" multiple draggable="true" @change="uploadFiles($event)" />
</td>
</tr>
</tbody>
</tbody>
</template>
</table>
<button x-show="step==1" @click="nextStepFn()" type="button" class="btn btn-primary btn-lg pull-right savebtn" :disabled="isLoading ? true : false">
<button x-show="step==3" @click="save()" :disabled="isLoading" type="button" class="btn btn-primary btn-lg pull-right savebtn">
<template x-if="!isLoading">
<span>下一步</span>
<span>存檔</span>
</template>
<template x-if="isLoading">
<div class="loader"></div>
</template>
</button>
<button x-show="step==2" @click="save()" :disabled="isLoading ? true : false" type="button" class="btn btn-primary btn-lg pull-right savebtn">
<button x-show="step<=2" @click="nextStepFn()" type="button" class="btn btn-primary btn-lg pull-right savebtn" :disabled="isLoading">
<template x-if="!isLoading">
<span>存檔</span>
<span>下一步</span>
</template>
<template x-if="isLoading">
<div class="loader"></div>
</template>
</button>
<button x-show="step>1" @click="preStepFn()" :disabled="isLoading ? true : false" type="button" class="btn btn-primary btn-lg pull-right savebtn">
<button x-show="step>1" @click="preStepFn()" :disabled="isLoading" type="button" class="btn btn-primary btn-lg pull-right savebtn">
<template x-if="!isLoading">
<span>上一步</span>
</template>
@ -488,3 +523,6 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
<script src="semantic/dist/semantic.min.js" ></script>
<script>
</script>
Loading…
Cancel
Save