diff --git a/wms/contract-repair/api/deleteNewContractData.php b/wms/contract-repair/api/deleteNewContractData.php index d7feb1c1..34575f0c 100644 --- a/wms/contract-repair/api/deleteNewContractData.php +++ b/wms/contract-repair/api/deleteNewContractData.php @@ -1,6 +1,25 @@ prepare($sql); + $stmt->bindParam(":id",$id); + $stmt->bindParam(":del",$del); + $stmt->bindParam(":user_id",$user_id); + $stmt->bindParam(":date",$date); + $stmt->execute(); + header("HTTP/1.1 204 NO Content"); + }catch(PDOException $e){ + die("ERROR!!!". $e->getMessage()); + } +} if(isset($_GET['contractid']) && $_GET['contractid']!=""){ try{ $id = $_GET["contractid"]; @@ -12,4 +31,5 @@ if(isset($_GET['contractid']) && $_GET['contractid']!=""){ }catch(PDOException $e){ die("ERROR!!!: ". $e->getMessage()); } -} \ No newline at end of file +} +?> \ No newline at end of file diff --git a/wms/contract-repair/api/getContractData.php b/wms/contract-repair/api/getContractData.php index aadc45cd..1352cdb1 100644 --- a/wms/contract-repair/api/getContractData.php +++ b/wms/contract-repair/api/getContractData.php @@ -57,7 +57,6 @@ if(isset($_GET['contractno']) && $_GET['contractno']!='' && isset($_GET['contrac }catch (PDOException $e ){ die("ERROR!!!: ". $e->getMessage()); } -<<<<<<< HEAD } ////////////////////////////// //// 合約簽回(修理) @@ -68,7 +67,8 @@ if(isset($_GET['contractno']) && $_GET['contractno']!='' && isset($_GET['contrac if(isset($_GET['contractno']) && $_GET['contractno']!='' && isset($_GET['contracttype']) && $_GET['contracttype'] == 'r'){ try{ $contractno = $_GET['contractno']; - $sql = "SELECT a.*,b.name FROM pricereview_repair_main AS a + $sql = "SELECT a.*,b.name,b.accountid + FROM pricereview_repair_main AS a LEFT JOIN account AS b ON a.repairerid = b.accountid WHERE a.contractno = :contractno "; @@ -87,6 +87,4 @@ if(isset($_GET['contractno']) && $_GET['contractno']!='' && isset($_GET['contrac }catch(PDOException $e){ die("ERROR!!:".$e->getMessage()); } -======= ->>>>>>> 1e6352f45c1f05ebbeb9736555124e07ff5fc958 } \ No newline at end of file diff --git a/wms/contract-repair/api/postContractData.php b/wms/contract-repair/api/postContractData.php index d7eee3cd..635d81f9 100644 --- a/wms/contract-repair/api/postContractData.php +++ b/wms/contract-repair/api/postContractData.php @@ -304,7 +304,7 @@ if(isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['co $stmt -> execute(); header('Content-Type: application/json'); - $jsonData = json_encode($files); + // $jsonData = json_encode($files); $conn->commit(); }catch(PDOException $e){ @@ -321,9 +321,87 @@ if(isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['co //// 製作人:梓誠 /// 時間 : ////////////////////////////// -if(isset($_POST['contractno']) && $_POST['contractno'] != "" && isset($_POST['contracttype']) && $_POST['contracttype'] == 'b'){ +if(isset($_POST['contractno']) && $_POST['contractno'] != "" && isset($_POST['contracttype']) && $_POST['contracttype'] == 'r'){ try{ + $created_at = date('Y-m-d H:i:s'); + $contractno = !empty($_POST['contractno']) ? $_POST['contractno'] : null; + $company = !empty($_POST['company']) ? $_POST['company'] : null; + $repairid = !empty($_POST['repairid']) ? $_POST['repairid'] : null; + $facilityno = !empty($_POST['facilityno']) ? $_POST['facilityno'] : null; + $taxid = !empty($_POST['taxid']) ? $_POST['taxid'] : null; + $invoice = !empty($_POST['invoice']) ? $_POST['invoice'] : null; + $address = !empty($_POST['address']) ? $_POST['address'] : null; + $repair_no = !empty($_POST['repair_no']) ? $_POST['repair_no'] : null; + $total_price= !empty($_POST['total_price']) ? $_POST['total_price'] : null; + $user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null; + $type = !empty($_POST['type']) ? $_POST['type'] : null; + $sign_date = !empty($_POST['sign_date']) ? $_POST['sign_date']: null; + + $fail_arr = []; + if($contractno === '') return $fail_arr[] = '合約號為必填'; + if($repair_no === '') return $fail_arr[] = '報價單編號為必填'; + if($company === '') return $fail_arr[] = '客戶名稱為必填'; + // if($taxid === '') return $fail_arr[] = '統一編號為必填'; + if($facilityno === '') return $fail_arr[] = '電梯編號為必填'; + if($address === '') return $fail_arr[] = '工程地址為必填'; + if($type === '') return $fail_arr[] = '工程類別為必填'; + if($invoice === '') return $fail_arr[] = '發票抬頭為必填'; + if(count($fail_arr)>0){ + header("HTTP/1.1 422 Unprocessable Entity"); + echo json_encode($fail_arr); + exit(); + } + // exit(); + //create contrac_r_signed_back table + $conn -> beginTransaction(); + $sql = "INSERT INTO contract_r_signed_back( + repair_no, + contractno, + company, + taxid, + facilityno, + address, + type, + invoice, + repaireid, + total_price, + sign_date, + create_userid, + create_date) VALUES( + :repair_no, + :contractno, + :company, + :taxid, + :facilityno, + :address, + :type, + :invoice, + :repaireid, + :total_price, + :sign_date, + :create_userid, + :create_date + )"; + $stmt = $conn -> prepare($sql); + $stmt -> bindParam(":repair_no",$repair_no); + $stmt -> bindParam(":contractno",$contractno); + $stmt -> bindParam(":company",$company); + $stmt -> bindParam(":taxid",$taxid); + $stmt -> bindParam(":facilityno",$facilityno); + $stmt -> bindParam(":address",$address); + $stmt -> bindParam(":type", $type); + $stmt -> bindParam(":invoice", $invoice); + $stmt -> bindParam(":repaireid",$repaireid); + $stmt -> bindParam(":total_price",$total_price); + $stmt -> bindParam(":sign_date",$sign_date); + $stmt -> bindParam(":create_userid",$user_id); + $stmt -> bindParam("create_date",$created_at); + + $stmt -> execute(); + header('Content-Type: application/json'); + // $jsonData = json_encode($files); + $conn -> commit(); }catch(PDOException $e){ $conn -> rollback(); echo $e->getMessage(); diff --git a/wms/contract-repair/api/putContractData.php b/wms/contract-repair/api/putContractData.php index f1e78164..0698a041 100644 --- a/wms/contract-repair/api/putContractData.php +++ b/wms/contract-repair/api/putContractData.php @@ -3,6 +3,45 @@ require_once("../conn.php"); include_once("./upload_chk.php"); ini_set ( 'date.timezone' , 'Asia/Taipei' ); // echo json_encode(explode(',', $_POST['deletefiles'])); +if(isset($_POST['contracttype']) && $_POST['contracttype'] == 'r' && isset($_POST["id"]) && $_POST['id']!=""){ + try{ + $create_date = date('Y-m-d H:i:s'); + $repair_no = !empty($POST['repair_no']) ? $_POST['repair_no'] : null; + $contractno = !empty($_POST['contractno']) ? $_POST['contractno'] : null; + $company = !empty($_POST['company']) ? $_POST['conpany'] : null; + $taxid = !empty($_POST['taxid']) ? $_POST['taxid'] : null; + $facilityno = !empty($_POST['facilityno']) ? $_POST['facilityno'] : null; + $address = !empty($_POST['address']) ? $_POST['address'] : null; + $type = !empty($_POST['type']) ? $_POST['type'] : null; + $invoice = !empty($_POST['invoice']) ? $_POST['invoice'] : null; + $repaireid = !empty($_POST['repaireid']) ? $_POST['repaireid'] : null; + // $total_price = !empty($_POST['total_price']) ? $_POST['total_price'] : null; + $user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null; + + $fail_arr = []; + if(empty($repair_no)) $fail_arr[] = '號為必填'; + if(empty($contractno)) $fail_arr[] = '合約號為必填'; + if(empty($company)) $fail_arr[] = '客戶名稱為必填'; + if(empty($taxid)) $fail_arr[] = '統一編號為必填'; + if(empty($facilityno)) $fail_arr[] = '電梯號為必填'; + if(empty($address)) $fail_arr[] = '工程地址為必填'; + if(empty($type)) $fail_arr[] = '工程類行為必填'; + if(empty($invoice)) $fail_arr[] = '發票抬頭為必填'; + if(empty($repaireid)) $fail_arr[] = '維修人員為必填'; + if(count($fail_arr) > 0){ + header("HTTP/1.1 442 Unprocessable Entity"); + echo json_encode($fail_arr); + exit(); + } + $conn -> beginTransaction(); + + + }catch(PDOException $e){ + $conn->rollback(); + header("HTTPP/1.1 500 Internal Server Error"); + die('Error!:' .$e->getMessage()); + } +} if(isset($_POST['contractno']) && $_POST['contractno']!="" && isset($_POST["id"]) && $_POST['id']!=""){ try{ $created_at = date('Y-m-d H:i:s'); diff --git a/wms/contract-repair/contract-repair-edit.php b/wms/contract-repair/contract-repair-edit.php new file mode 100644 index 00000000..ff8b124c --- /dev/null +++ b/wms/contract-repair/contract-repair-edit.php @@ -0,0 +1,201 @@ +prepare($sql_str); +$stmt->bindParam(':id', $id); +$stmt->execute(); +$contract= $stmt->fetch(PDO::FETCH_ASSOC); +// echo '
';
+// print_r($contract);
+// echo '
'; +// $files_id = $contract['files_id']; +// $sql_str = "SELECT * FROM contract_back_files WHERE files_id = :files_id "; +// $stmt = $conn->prepare($sql_str); +// $stmt->bindParam(':files_id', $files_id); +// $stmt->execute(); +// $files= $stmt->fetchAll(PDO::FETCH_ASSOC); +// $files = json_encode($files); +$accounttype = "M"; +$sql_str = "SELECT accountid, name FROM account WHERE accounttype = :accounttype"; +$stmt = $conn->prepare($sql_str); +$stmt->bindParam(":accounttype", $accounttype); +$stmt -> execute(); +$persons = $stmt->fetchAll(PDO::FETCH_ASSOC); +$persons = array_map(function($person){ + return [ + 'view'=>$person['accountid'] .'-'. $person['name'], + 'value'=>$person['accountid'], + 'name'=>$person['name'] + ]; +}, $persons); +?> + + + + + + + + + +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

合約管理(修理)

+
+

檢視合約

+
+ + +
立約人 + +

未填寫

+
維保人員 + +

未填寫

+
電梯編號 + +

未填寫

+
報價單編號 + +

未填寫

+
工程類別 + +

未填寫

+
簽訂時間 + +

未填寫

+
發票抬頭 + +

未填寫

+
統一編號 + +

未填寫

+
工程地址 + +

未填寫

+
+ + +
+
+
+ + + + + + + diff --git a/wms/contract-repair/contract-repair-input.php b/wms/contract-repair/contract-repair-input.php index 2925f9a6..0d598fee 100644 --- a/wms/contract-repair/contract-repair-input.php +++ b/wms/contract-repair/contract-repair-input.php @@ -95,8 +95,8 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC); 簽訂時間 - -

未填寫

+ +

未填寫

發票抬頭 @@ -124,14 +124,14 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC); - 維修人員 + 報價單編號 - +

未填寫

附件 diff --git a/wms/contract-repair/contract-repair-management.php b/wms/contract-repair/contract-repair-management.php new file mode 100644 index 00000000..bf1070a7 --- /dev/null +++ b/wms/contract-repair/contract-repair-management.php @@ -0,0 +1,119 @@ +prepare($sql_str); +$stmt->execute(); +$contracts= $stmt->fetchAll(PDO::FETCH_ASSOC); +?> + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + $contract): ?> + + + + + + + + + + + + +
項次合約號客戶名稱統編總金額建檔者建立時間操作
+

+ + + + + + +

+
+
+
+ + + + + \ No newline at end of file diff --git a/wms/contract-repair/js/alpine.js b/wms/contract-repair/js/alpine.js index 128ff2d8..46cf57ea 100644 --- a/wms/contract-repair/js/alpine.js +++ b/wms/contract-repair/js/alpine.js @@ -356,7 +356,7 @@ const contractDownload = ()=> { if (typeof obj[key] === 'object' && obj[key] !== null) { clone[key] = this.deepClone(obj[key]); if(clone[key].text != undefined){ - // clone[key].text = clone[key].text.replace(//, '___') + // clone[key].text = clone[key].text.replace(/{ contractno:'', company:'', repairer:'', + repairid:'', facilityno:'', taxid:'', invoice:'', //發票抬頭 type:'', //工程類別需新增,用 post address:'', - repaire_no:'', - total_price:'' + repair_no:'', + total_price:'', + sign_date:'' }, step:1, isLoading:false, @@ -973,7 +975,6 @@ const contractRepair = ()=>{ // 抓資料 getContractDate(){ axios.get('./api/getContractData.php?contracttype=r&contractno='+this.data.contractno).then(res=>{ - if(!res.data){ this.step = 2; this.isLoading = false; @@ -981,7 +982,7 @@ const contractRepair = ()=>{ return } if(!this.customize){ - console.log(res.data); + // console.log(res.data); this.data.contractno = res.data.contractno; this.data.company = res.data.company; this.data.repairer = res.data.name; @@ -991,11 +992,13 @@ const contractRepair = ()=>{ this.data.address = res.data.address; this.data.repair_no = res.data.repair_no; this.data.total_price= res.data.total_price; + this.data.repairid = res.data.accountid; + this.data.sign_date = res.data.sign_date; } this.step = 2; this.isLoading = false; - - console.log(this); + // console.log(user_name); + console.log(this.data.sign_date); }).catch(err=>{ console.log(err); this.isLoading = false @@ -1014,6 +1017,8 @@ const contractRepair = ()=>{ this.data.address = ''; this.data.repair_no = ''; this.data.total_price = ''; + this.data.repairid = ''; + this.data.sign_date = ''; return; } @@ -1024,23 +1029,63 @@ const contractRepair = ()=>{ const form = new FormData(); form.append('contractno', this.data.contractno); form.append('company', this.data.company); - form.append('repairer', this.data.repairer); + form.append('repairid', this.data.repairid); form.append('facilityno', this.data.facilityno); form.append('taxid', this.data.taxid); form.append('invoice', this.data.invoice); form.append('address', this.data.address); - form.append('repair_no', this.data.reapir_no); + form.append('repair_no', this.data.repair_no); form.append('total_price', this.data.total_price); - form.append('contracttype', 'b') - + form.append('sign_date', this.data.sign_date); + form.append('contracttype', 'r'); + form.append('user_id', user_id); + form.append('type', this.data.type); axios.post('./api/postContractData.php',form).then(res=>{ console.log(res.status); + if(res.status === 200){ + alert('儲存成功'); + this.step = 1; + this.data.contractno= ''; + this.data.company = ''; + this.data.repairid = ''; + this.data.facilityno= ''; + this.data.repairer = ''; + this.data.taxid = ''; + this.data.invoice = ''; + this.data.address = ''; + this.data.repair_no = ''; + this.data.total_price= ''; + this.data.user_id = ''; + this.data.type = ''; + this.data.sign_date = ''; + } + this.isLoading = false; + }).catch(error=>{ + let code = error.response.status; + if(code == 422){ + this.fail_arr = error.response.data; + this.errorFn(); + } + if(code == 500){ + alert('儲存失敗!可能為以下錯誤:\n' + error.response.data); + } + + 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; } - } -} +}; const contractInput =()=> { return{ @@ -1369,4 +1414,82 @@ const contractNewApply = ()=>{ }) } } +} + +const contract_edit = ()=>{ + return { + isLoading:false, + data:{ + id: id , + repair_no : repair_no , + contractno: contractno , + company : company , + taxid : taxid , + facilityno: facilityno , + address : address , + type : type , + invoice : invoice , + repaireid : repaireid , + total_price:total_price, + sign_date : sign_date , + // user_id : user_id, + + }, + fail_arr:[], + deleteFileFn(id){ + if(!confirm("確定要刪除嗎?")) return + this.data.files = this.data.files.filter(file=> id != file.id) + this.data.deletefiles.push(id) + console.log(this.data.deletefiles); + }, + save(){ + this.isLoading = true + const form = new FormData(); + form.append("id",this.data.id); + form.append("repair_no",this.data.repair_no); + form.append("contractno",this.data.contractno); + form.append("company",this.data.company); + form.append("taxid",this.data.taxid); + form.append("facilityno",this.data.facilityno); + form.append("address",this.data.address); + form.append("type",this.data.type); + form.append("invoice",this.data.invoice); + form.append("repaireid",this.data.repaireid); + form.append("total_price",this.data.total_price); + form.append("sign_date",this.data.sign_date); + form.append("user_id",user_id); + form.append('contracttype', 'r'); + + axios.post("./api/putContractData.php", form).then(res=>{ + console.log(res.data) + if(res.status === 200){ + alert("更新成功"); + window.location.reload(); + } + this.isLoading = false + }).catch(error=>{ + let code = error.response.status; + if(code == 422){ + this.fail_arr = error.response.data + this.errorFn() + } + if(code == 500){ + alert("更新失敗!可能為以下錯誤:\n" + error.response.data) + } + this.isLoading = false + }) + + }, + uploadFiles(e){ + this.data.newfiles = e.target.files + }, + errorFn(){ + let msg = "" + for(let i = 0; i < this.fail_arr.length; i++){ + msg += this.fail_arr[i] + "、" + } + alert(msg) + } +} + } \ No newline at end of file diff --git a/wms/database.php b/wms/database.php index ba66e089..2311059e 100644 --- a/wms/database.php +++ b/wms/database.php @@ -31,12 +31,12 @@ try { $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } } catch (PDOException $e) { - // echo "fail"; - // echo $e->getMessage(); + echo "fail"; + echo $e->getMessage(); } if ($link) { mysqli_query($link, 'SET NAMES utf8'); // echo "正確連接資料庫"; } else { echo "不正確連接資料庫
" . mysqli_connect_error(); -} +} \ No newline at end of file