Browse Source

合約書申請 暫存成功

gary
10994015 1 year ago
parent
commit
2ccb0f743f
  1. 68
      wms/contract/api/postContractNewApplyData.php
  2. 14
      wms/contract/contract-new-apply.php
  3. 26
      wms/contract/js/alpine.js

68
wms/contract/api/postContractNewApplyData.php

@ -0,0 +1,68 @@
<?php
require_once("../conn.php");
ini_set ( 'date.timezone' , 'Asia/Taipei' );
if(isset($_POST['vol_no']) && !empty($_POST['vol_no'])){
$mid = $_POST['mid'];
$vol_no = $_POST['vol_no'];
$salesman = $_POST['salesman'];
$apply_date = $_POST['apply_date'];
$apply_type = $_POST['apply_type'];
$case_name = $_POST['case_name'];
$customer = $_POST['company'];
$manager = $_POST['manager'];
$vat = $_POST['vat'];
$total_price = $_POST['total_price'];
$buy_fee = $_POST['price_a'];
$install_fee = $_POST['price_b'];
$contact_address = $_POST['address'];
$workdeadline_a = $_POST['workdeadline_a'];
$workdeadline_b = $_POST['workdeadline_b'];
$test_time = $_POST['regulations'];
$freedeadline = $_POST['freedeadline'];
$trade_address = $_POST['tradeaddress'];
$tradedeadline = $_POST['tradedeadline'];
$progress = 0;
$status = 0;
$created_at = date('Y-m-d H:i:s');
$created_by = $_POST['user_id'];
$isFirst = $_POST['isFirst'];
$conn->beginTransaction();
try{
if($isFirst == 1){
$sql_str = "INSERT INTO contract_new_apply (mid, contractno, sales_man, apply_date, apply_type, case_name, customer, manager, vat, total_price, buy_fee, install_fee, contact_address, workdeadline_a, workdeadline_b, test_time, freedeadline, trade_address, tradedeadline, progress, status, created_at, created_by) VALUES (:mid, :contractno, :sales_man, :apply_date, :apply_type, :case_name, :customer, :manager, :vat, :total_price, :buy_fee, :install_fee, :contact_address, :workdeadline_a, :workdeadline_b, :test_time, :freedeadline, :trade_address, :tradedeadline, :progress, :status, :created_at, :created_by)";
$stmt = $conn -> prepare($sql_str);
$stmt ->bindParam(':mid', $mid);
$stmt ->bindParam(':contractno', $vol_no);
$stmt ->bindParam(':sales_man', $salesman);
$stmt ->bindParam(':apply_date', $apply_date);
$stmt ->bindParam(':apply_type', $apply_type);
$stmt ->bindParam(':case_name', $case_name);
$stmt ->bindParam(':customer', $customer);
$stmt ->bindParam(':manager', $manager);
$stmt ->bindParam(':vat', $vat);
$stmt ->bindParam(':total_price', $total_price);
$stmt ->bindParam(':buy_fee', $buy_fee);
$stmt ->bindParam(':install_fee', $install_fee);
$stmt ->bindParam(':contact_address', $contact_address);
$stmt ->bindParam(':workdeadline_a', $workdeadline_a);
$stmt ->bindParam(':workdeadline_b', $workdeadline_b);
$stmt ->bindParam(':test_time', $test_time);
$stmt ->bindParam(':freedeadline', $freedeadline);
$stmt ->bindParam(':trade_address', $trade_address);
$stmt ->bindParam(':tradedeadline', $tradedeadline);
$stmt ->bindParam(':progress', $progress);
$stmt ->bindParam(':status', $status);
$stmt ->bindParam(':created_at', $created_at);
$stmt ->bindParam(':created_by', $created_by);
$stmt ->execute();
header("HTTP/1.1 201 success!");
$conn->commit();
}
}catch(PDOException $e){
$conn->rollback();
echo $e->getMessage();
die('Error!:'.$e->getMessage());
}
}

14
wms/contract/contract-new-apply.php

@ -1,3 +1,4 @@
<?php <?php
include_once("../header.php"); include_once("../header.php");
require_once("./conn.php"); require_once("./conn.php");
@ -8,6 +9,15 @@ if(!(isset($_GET['id']) && !empty($_GET['id']))){
exit; exit;
} }
$id = $_GET["id"]; $id = $_GET["id"];
$sql_str = "SELECT * FROM contract_new_apply WHERE mid = :mid";
$stmt = $conn->prepare($sql_str);
$stmt->bindParam(':mid',$id);
$stmt->execute();
$contract_new_apply = $stmt->fetch(PDO::FETCH_ASSOC);
if(empty($contract_new_apply)){
$sql_str = "SELECT pricereview_main.*, pricereview_main.id as mainid, account.name as accountname $sql_str = "SELECT pricereview_main.*, pricereview_main.id as mainid, account.name as accountname
FROM pricereview_main FROM pricereview_main
JOIN account ON pricereview_main.person = account.accountid JOIN account ON pricereview_main.person = account.accountid
@ -49,13 +59,13 @@ $stmt = $conn->prepare($sql_str);
$stmt->bindParam(':mid', $mid); $stmt->bindParam(':mid', $mid);
$stmt->execute(); $stmt->execute();
$items = $stmt->fetchAll(PDO::FETCH_ASSOC); $items = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
?> ?>
<link rel="stylesheet" href="./styles/style.css"> <link rel="stylesheet" href="./styles/style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" integrity="sha512-z3gLpd7yknf1YoNbCzqRKc4qyor8gaKU1qmn+CShxbuBusANI9QpRohGBreCFkKxLhei6S9CQXFEbbKuqLg0DA==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css" integrity="sha512-z3gLpd7yknf1YoNbCzqRKc4qyor8gaKU1qmn+CShxbuBusANI9QpRohGBreCFkKxLhei6S9CQXFEbbKuqLg0DA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="semantic/dist/semantic.min.css"> <link rel="stylesheet" href="semantic/dist/semantic.min.css">
<script defer src="./js/alpinejs/cdn.min.js"></script> <script defer src="./js/alpinejs/cdn.min.js"></script>
<script src="./js/axios/axios.min.js"></script> <script src="./js/axios/axios.min.js"></script>
<div class="contract-new-apply-component" x-data="contractNewApply"> <div class="contract-new-apply-component" x-data="contractNewApply">
<div class="form" method="post" id="form" enctype="multipart/form-data" > <div class="form" method="post" id="form" enctype="multipart/form-data" >
<input type="hidden" name='form_name' value="main_form" /> <input type="hidden" name='form_name' value="main_form" />
@ -460,5 +470,7 @@ $items = $stmt->fetchAll(PDO::FETCH_ASSOC);
const price_a = <?php echo $price_a; ?>; const price_a = <?php echo $price_a; ?>;
const price_b = <?php echo $price_b; ?>; const price_b = <?php echo $price_b; ?>;
const items = [...<?php echo json_encode($items); ?>]; const items = [...<?php echo json_encode($items); ?>];
const user_id = '<?php echo $user_id ?>';
const mid = '<?php echo $_GET['id']; ?>';
console.log(items) console.log(items)
</script> </script>

26
wms/contract/js/alpine.js

@ -1177,6 +1177,7 @@ const contractNewApply = ()=>{
step:1, step:1,
isLoading:false, isLoading:false,
data:{ data:{
mid: mid,
vol_no: contractno, vol_no: contractno,
salesman: salesman, salesman: salesman,
salesmanname:salesmanname, salesmanname:salesmanname,
@ -1221,10 +1222,33 @@ const contractNewApply = ()=>{
}, },
storageFn(){ storageFn(){
this.isLoading = true this.isLoading = true
const isFirst = 1;
const form = new FormData(); const form = new FormData();
axios.post('postContractNewApplyData.php', form).then(res=>{ form.append('mid', this.data.mid);
form.append('vol_no', this.data.vol_no);
form.append('salesman', this.data.salesman);
form.append('apply_date', this.data.apply_date);
form.append('apply_type', this.data.apply_type);
form.append('case_name', this.data.case_name);
form.append('company', this.data.company);
form.append('manager', this.data.manager);
form.append('vat', this.data.vat);
form.append('total_price', this.data.total_price);
form.append('price_a', this.data.price_a);
form.append('price_b', this.data.price_b);
form.append('address', this.data.address);
form.append('workdeadline_a', this.data.workdeadline_a);
form.append('workdeadline_b', this.data.workdeadline_b);
form.append('regulations', this.data.regulations);
form.append('freedeadline', this.data.freedeadline);
form.append('tradeaddress', this.data.tradeaddress);
form.append('tradedeadline', this.data.tradedeadline);
form.append('isFirst', isFirst);
form.append('user_id', user_id);
axios.post('./api/postContractNewApplyData.php', form).then(res=>{
if(res.status === 200){ if(res.status === 200){
alert('暫存成功'); alert('暫存成功');
console.log(res.data);
} }
this.isLoading = false this.isLoading = false
}).catch(error=>{ }).catch(error=>{

Loading…
Cancel
Save