From af27759cefa0aeba9cddcbad8c449218026585f0 Mon Sep 17 00:00:00 2001 From: 10994015 Date: Wed, 15 Nov 2023 17:59:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E6=A2=AF=E5=90=88=E7=B4=84=E7=B0=BD?= =?UTF-8?q?=E5=9B=9E1115?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wms/contract/api/deleteNewContractData.php | 15 + wms/contract/api/postContractData.php | 109 - wms/contract/api/postNewContractData.php | 136 ++ wms/contract/api/putContractData.php | 21 +- wms/contract/contract-download.php | 2 +- wms/contract/contract-input.php | 249 +-- wms/contract/contract-newelevator-edit.php | 28 +- wms/contract/contract-newelevator-input.php | 352 ++- .../contract-newelevator-management.php | 20 +- wms/contract/js/alpine.js | 1903 ++++++++++------- 10 files changed, 1490 insertions(+), 1345 deletions(-) create mode 100644 wms/contract/api/deleteNewContractData.php create mode 100644 wms/contract/api/postNewContractData.php diff --git a/wms/contract/api/deleteNewContractData.php b/wms/contract/api/deleteNewContractData.php new file mode 100644 index 00000000..d7feb1c1 --- /dev/null +++ b/wms/contract/api/deleteNewContractData.php @@ -0,0 +1,15 @@ +prepare($sql_str); + $stmt->bindParam(":contractid", $id); + $stmt->execute(); + header("HTTP/1.1 204 No Content"); + }catch(PDOException $e){ + die("ERROR!!!: ". $e->getMessage()); + } +} \ No newline at end of file diff --git a/wms/contract/api/postContractData.php b/wms/contract/api/postContractData.php index cafe8333..69e7d859 100644 --- a/wms/contract/api/postContractData.php +++ b/wms/contract/api/postContractData.php @@ -315,114 +315,5 @@ if(isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['co } -if(isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['contracttype']) && $_POST['contracttype'] == 'm') { - try{ - $created_at = date('Y-m-d H:i:s'); - $created_by = $_POST["user_id"]; - $contractno = $_POST["contractno"]; - $customer = $_POST["customer"]; - $manager = $_POST["manager"]; - $vat = $_POST["vat"]; - $case_name = $_POST["case_name"]; - $linkman = $_POST["linkman"]; - $lm_tel = $_POST["lm_tel"]; - $address = $_POST["address"]; - $salesman = $_POST["salesman"]; - $contracttype = $_POST["contracttype"]; - $files = !empty($_FILES['files']) ? $_FILES['files'] : null; - $files_id = null; - - $conn->beginTransaction(); - - $sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid ORDER BY create_at DESC"; - $stmt = $conn -> prepare($sql_str); - $stmt -> bindParam(":accountid",$salesman); - $stmt -> execute(); - $saleman = $stmt->fetch(PDO::FETCH_ASSOC); - $salesman_name = $saleman['name']; - if(!empty($files)){ - $englisharr = range('a', 'z'); - $files = $_FILES['files']; - $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 = 'm' . $datetime; // 保養=>b + 日期時間 - echo json_encode($newfiles); - foreach( $newfiles as $key => $file ){ - $randNum = rand(1000,9999); - $randEnglish = $englisharr[rand(0,25)]; - $file_name = 'm' . (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' ,$created_by); - $stmt ->execute(); - } - $msg_result .= '第' . ($key+1) . '個上傳檔案的結果:' . $msg . '
'; - $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_m_signed_back (contract_no, customer, manager, vat, case_name, linkman, lm_tel, address, salesman, salesman_name, files_id, created_at, created_by) VALUES (:contract_no, :customer, :manager, :vat, :case_name, :linkman, :lm_tel, :address, :salesman, :salesman_name, :files_id, :created_at, :created_by)"; - $stmt = $conn -> prepare($sql_str); - $stmt -> bindParam(":contract_no",$contractno); - $stmt -> bindParam(":customer",$customer); - $stmt -> bindParam(":manager",$manager); - $stmt -> bindParam(":vat",$vat); - $stmt -> bindParam(":case_name",$case_name); - $stmt -> bindParam(":linkman",$linkman); - $stmt -> bindParam(":lm_tel",$lm_tel); - $stmt -> bindParam(":address",$address); - $stmt -> bindParam(":salesman",$salesman); - $stmt -> bindParam(":salesman_name",$salesman_name); - $stmt -> bindParam(":files_id",$files_id); - $stmt -> bindParam(":created_at",$created_at); - $stmt -> bindParam(":created_by",$created_by); - $stmt -> execute(); - - - $result = $conn->commit(); - if($result){ - header("HTTP/1.1 201 Created"); - } - - }catch(PDOException $e){ - $conn->rollback(); - echo $e->getMessage(); - die('Error!:'.$e->getMessage()); - } -} diff --git a/wms/contract/api/postNewContractData.php b/wms/contract/api/postNewContractData.php new file mode 100644 index 00000000..dc08c30c --- /dev/null +++ b/wms/contract/api/postNewContractData.php @@ -0,0 +1,136 @@ + 0) { + header("HTTP/1.1 422 Unprocessable Entity"); + echo json_encode($fail_arr); + exit(); + } + + + $conn->beginTransaction(); + + $sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid ORDER BY create_at DESC"; + $stmt = $conn -> prepare($sql_str); + $stmt -> bindParam(":accountid",$salesman); + $stmt -> execute(); + $saleman = $stmt->fetch(PDO::FETCH_ASSOC); + $salesman_name = $saleman['name']; + if(!empty($files)){ + $englisharr = range('a', 'z'); + $files = $_FILES['files']; + $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 = 'm' . $datetime; // 保養=>b + 日期時間 + foreach( $newfiles as $key => $file ){ + $randNum = rand(1000,9999); + $randEnglish = $englisharr[rand(0,25)]; + $file_name = 'm' . (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' ,$created_by); + $stmt ->execute(); + }else{ + throw new PDOException('檔案上傳失敗:' . $msg); + } + $msg_result .= '第' . ($key+1) . '個上傳檔案的結果:' . $msg . '
'; + $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_m_signed_back (contract_no, customer, manager, vat, case_name, linkman, lm_tel, address, salesman, salesman_name, files_id, created_at, created_by) VALUES (:contract_no, :customer, :manager, :vat, :case_name, :linkman, :lm_tel, :address, :salesman, :salesman_name, :files_id, :created_at, :created_by)"; + $stmt = $conn -> prepare($sql_str); + $stmt -> bindParam(":contract_no",$contractno); + $stmt -> bindParam(":customer",$customer); + $stmt -> bindParam(":manager",$manager); + $stmt -> bindParam(":vat",$vat); + $stmt -> bindParam(":case_name",$case_name); + $stmt -> bindParam(":linkman",$linkman); + $stmt -> bindParam(":lm_tel",$lm_tel); + $stmt -> bindParam(":address",$address); + $stmt -> bindParam(":salesman",$salesman); + $stmt -> bindParam(":salesman_name",$salesman_name); + $stmt -> bindParam(":files_id",$files_id); + $stmt -> bindParam(":created_at",$created_at); + $stmt -> bindParam(":created_by",$created_by); + $stmt -> execute(); + + + $result = $conn->commit(); + if($result){ + header("HTTP/1.1 201 Created"); + } + + }catch(PDOException $e){ + $conn->rollback(); + header("HTTP/1.1 500 Internal Server Error"); + die('Error!:'.$e->getMessage()); + } + } \ No newline at end of file diff --git a/wms/contract/api/putContractData.php b/wms/contract/api/putContractData.php index 1c910bd8..63694e83 100644 --- a/wms/contract/api/putContractData.php +++ b/wms/contract/api/putContractData.php @@ -23,6 +23,22 @@ if(isset($_POST['contractno']) && $_POST['contractno']!="" && isset($_POST["id"] $deletefilesArr = explode(',', $_POST['deletefiles']); + $fail_arr = []; + if(empty($contract_no)) $fail_arr[] = '合約號為必填'; + if(empty($customer)) $fail_arr[] = '客戶名稱為必填'; + if(empty($manager)) $fail_arr[] = '負責人為必填'; + if(empty($vat)) $fail_arr[] = '統編/身分證為必填'; + if(empty($case_name)) $fail_arr[] = '案名為必填'; + if(empty($linkman)) $fail_arr[] = '聯絡人為必填'; + if(empty($lm_tel)) $fail_arr[] = '聯絡人電話為必填'; + if(empty($address)) $fail_arr[] = '地址為必填'; + if(empty($salesman)) $fail_arr[] = '營業員為必填'; + if(count($fail_arr) > 0) { + header("HTTP/1.1 422 Unprocessable Entity"); + echo json_encode($fail_arr); + exit(); + } + $conn->beginTransaction(); $sql_str = "UPDATE contract_m_signed_back SET contract_no=:contract_no, customer=:customer, manager=:manager, vat=:vat, case_name=:case_name, linkman=:linkman, lm_tel=:lm_tel, address=:address, salesman=:salesman WHERE id = :id"; @@ -66,7 +82,6 @@ if(isset($_POST['contractno']) && $_POST['contractno']!="" && isset($_POST["id"] $msg_result = ''; //負責接收所有檔案檢測後的回傳訊息 $datetime = (string)date('YmdHis'); $files_id = ($files_id !== null ) ? $files_id : 'm' . $datetime; // 新梯=>m + 日期時間 - echo json_encode($newfiles); foreach( $newfiles as $key => $file ){ $randNum = rand(1000,9999); $randEnglish = $englisharr[rand(0,25)]; @@ -83,6 +98,8 @@ if(isset($_POST['contractno']) && $_POST['contractno']!="" && isset($_POST["id"] $stmt -> bindParam(':created_at' ,$created_at); $stmt -> bindParam(':created_by' ,$created_by); $stmt ->execute(); + }else{ + throw new PDOException('檔案上傳失敗:' . $msg); } $msg_result .= '第' . ($key+1) . '個上傳檔案的結果:' . $msg . '
'; $src_name = $path.$file['name']; @@ -100,7 +117,7 @@ if(isset($_POST['contractno']) && $_POST['contractno']!="" && isset($_POST["id"] $conn->commit(); }catch(PDOException $e) { $conn->rollback(); - echo $e->getMessage(); + header("HTTP/1.1 500 Internal Server Error"); die('Error!:'.$e->getMessage()); } diff --git a/wms/contract/contract-download.php b/wms/contract/contract-download.php index 9370728e..2bab2ce4 100644 --- a/wms/contract/contract-download.php +++ b/wms/contract/contract-download.php @@ -81,7 +81,7 @@ if(isset($_GET['id']) && $_GET['id']!=""){ -
+