diff --git a/wms/T8_Authorization_from_bpm.php b/wms/T8_Authorization_from_bpm.php index 7c206023..b862a81d 100644 --- a/wms/T8_Authorization_from_bpm.php +++ b/wms/T8_Authorization_from_bpm.php @@ -3,10 +3,7 @@ // $user_id = "M0000"; // $user_password = "M012290493119"; -$user_id = "M0117"; -$user_password = "90493119"; - -echo $validation = get_Auth($user_id, $user_password); +// echo $validation = get_Auth($user_id, $user_password); function get_Auth($user_id = "M0000", $user_password = "M012290493119") { @@ -16,8 +13,9 @@ function get_Auth($user_id = "M0000", $user_password = "M012290493119") // $now = gmdate("YmdHis"); $now = gmdate("YmdHis", strtotime("-2 minutes")); $data = "$user_id." . $now; - $sign = hash_hmac('SHA256', $data, 'B2D6395D2883E26C', false); + $sign = hash_hmac('SHA256', $data, 'A21181F1EE4966D3', false); + // echo $sign; // $apiurl = 'https://erp.masada.com.tw:780/twWebAPI/GetAuth'; $apiurl = 'http://60.244.87.101:880//twWebAPI/GetAuth'; @@ -30,7 +28,7 @@ function get_Auth($user_id = "M0000", $user_password = "M012290493119") "Pwd: $user_password", "TimestampUTC: $now", "Sign: $sign", - "GroupId: TEST" + "GroupId:TEST" ]; $ch = curl_init(); @@ -53,4 +51,4 @@ function get_Auth($user_id = "M0000", $user_password = "M012290493119") curl_close($ch); } // $data = []; -get_Auth(); +// get_Auth(); diff --git a/wms/bonus/api/postStatus.php b/wms/bonus/api/postStatus.php index a7abb7b8..86f9f88d 100644 --- a/wms/bonus/api/postStatus.php +++ b/wms/bonus/api/postStatus.php @@ -2,32 +2,44 @@ require_once("../../contract/conn.php"); if (!empty($_POST['id']) && !empty($_POST['postType']) && $_POST['postType'] == 'a') { - $id = empty($_POST['id']) ? '' : $_POST['id']; - $user_id = empty($_POST['user_id']) ? '' : $_POST['user_id']; - $pay_day = empty($_POST['pay_day']) ? '' : $_POST['pay_day']; - $review_at = date("Y-m-d"); - $sql = "UPDATE bonus SET status = 2 ,review_hr = '$user_id' ,review_at = '$review_at',pay_day ='$pay_day' WHERE id = $id"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - - echo 'Success'; -} -// 獎金確認發放,並更新獎金 OR 實際發放時間 -if (!empty($_POST['postType']) && $_POST['postType'] == 'b') { - - $id = empty($_POST['id']) ? '' : $_POST['id']; - $pay_day = empty($_POST['pay_day']) ? '' : $_POST['pay_day']; - $bonus_actual = empty($_POST['bonus_issue']) ? '' : $_POST['bonus_issue']; - $note = empty($_POST['note']) ? '' : $_POST['note']; - $user_id = empty($_POST['user_id']) ? '' : $_POST['user_id']; - $review_at = date("Y-m-d"); try { - $sql = "UPDATE bonus SET status = 2,review_hr='$user_id',review_at='$review_at',pay_day='$pay_day',note='$note' WHERE id = $id"; + $id = empty($_POST['id']) ? '' : $_POST['id']; + $user_id = empty($_POST['user_id']) ? '' : $_POST['user_id']; + $amount = empty($_POST['amount']) ? '' : $_POST['amount']; + $pay_day = empty($_POST['pay_day']) ? '' : $_POST['pay_day']; + $review_at = date("Y-m-d H:i:s"); + $sql = "UPDATE bonus SET status = 2 ,bonus_actual='$amount',review_hr = '$user_id' ,review_at = '$review_at',pay_day ='$pay_day',update_id='$user_id',update_at='$review_at' WHERE id = $id"; $stmt = $conn->prepare($sql); $stmt->execute(); + header("HTTP/1.1 200 success!"); + echo 'Success'; } catch (PDOException $e) { - header("HTTP/1.1 500 failed!"); + header("HTTP/1.1 404 failed!"); + echo $e->getMessage(); + die('Error!:' . $e->getMessage()); + } +} +// 獎金確認發放,並更新獎金 OR 實際發放時間 +if (!empty($_POST['postType']) && $_POST['postType'] == 'b') { + try { + $id = empty($_POST['id']) ? '' : $_POST['id']; + $pay_day = empty($_POST['pay_day']) ? '' : $_POST['pay_day']; + $bonus_actual = empty($_POST['bonus_actual']) ? '' : $_POST['bonus_actual']; + $note = empty($_POST['note']) ? '' : $_POST['note']; + $user_id = empty($_POST['user_id']) ? '' : $_POST['user_id']; + $review_at = date("Y-m-d H:i:s"); + if ($pay_day != '' && $bonus_actual != '') { + $sql = "UPDATE bonus SET status = 2,review_hr='$user_id',review_at='$review_at',bonus_actual='$bonus_actual',pay_day='$pay_day',note='$note' WHERE id = $id"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + header("HTTP/1.1 200 success!"); + } else { + header("HTTP/1.1 400"); + echo '請填寫發放時間和實發獎金'; + } + } catch (PDOException $e) { + header("HTTP/1.1 404 failed!"); echo $e->getMessage(); die('Error!:' . $e->getMessage()); } @@ -36,25 +48,64 @@ if (!empty($_POST['postType']) && $_POST['postType'] == 'b') { // 獎金暫不發放 if (!empty($_POST['postType']) && $_POST['postType'] == 'c') { // echo 'cccccc'; - $id = empty($_POST['id']) ? '' : $_POST['id']; - $pay_day = empty($_POST['pay_day']) ? '' : $_POST['pay_day']; - $bonus_actual = empty($_POST['bonus_issue']) ? '' : $_POST['bonus_issue']; - $user_id = empty($_POST['user_id']) ? '' : $_POST['user_id']; - $note = empty($_POST['note']) ? '' : $_POST['note']; try { - $sql = "UPDATE bonus SET status = 4,review_hr='$user_id',review_at='$review_at',pay_day='$pay_day',note='$note' WHERE id = $id"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - header("HTTP/1.1 200 success!"); + $id = empty($_POST['id']) ? '' : $_POST['id']; + $pay_day = empty($_POST['pay_day']) ? '' : $_POST['pay_day']; + $bonus_actual = empty($_POST['bonus_issue']) ? '' : $_POST['bonus_issue']; + $user_id = empty($_POST['user_id']) ? '' : $_POST['user_id']; + $note = empty($_POST['note']) ? '' : $_POST['note']; + $review_at = date("Y-m-d H:i:s"); + + if ($note != '') { + $sql = "UPDATE bonus SET status = 4,review_hr='$user_id',review_at='$review_at',pay_day='$pay_day',note='$note' WHERE id = $id"; + echo $sql; + $stmt = $conn->prepare($sql); + $stmt->execute(); + header("HTTP/1.1 200 success!"); + } else { + echo '請填寫備註!!'; + header("HTTP/1.1 400!"); + } } catch (PDOException $e) { - header("HTTP/1.1 500 failed!"); + header("HTTP/1.1 404 failed!"); echo $e->getMessage(); die('Error!:' . $e->getMessage()); } } if (!empty($_POST['postType']) && $_POST['postType'] == 'd') { - $id = empty($_POST['id']) ? '' : $_POST['id']; - print_r($id); + try { + $id = empty($_POST['id']) ? '' : $_POST['id']; + $review_at = date("Y-m-d H:i:s"); + $user_id = empty($_POST['user_id']) ? '' : $_POST['user_id']; + + $sql = "SELECT * FROM bonus WHERE id IN ($id)"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + $results = $stmt->fetchAll(PDO::FETCH_ASSOC); + + $conn->beginTransaction(); + foreach ($results as $result) { + // echo '
'; + // print_r($result); + // echo ''; + // exit(); + $amount = $result['amount']; + $id = $result['id']; + $pay_day = $result['pay_day_due']; + + $sql = "UPDATE bonus SET status = 5 ,bonus_actual='$amount',review_hr = '$user_id' ,review_at = '$review_at',pay_day ='$pay_day' WHERE id = $id"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + } + + $conn->commit(); + header("HTTP/1.1 200 success!"); + } catch (PDOException $e) { + $conn->rollBack(); + header("HTTP/1.1 404 failed!"); + echo $e->getMessage(); + die('Error!:' . $e->getMessage()); + } // echo 'ddddd'; } diff --git a/wms/bonus/bonus.php b/wms/bonus/bonus.php index 4e5b3f8d..f7462641 100644 --- a/wms/bonus/bonus.php +++ b/wms/bonus/bonus.php @@ -2,7 +2,7 @@ include_once("../header.php"); // require_once('./connT8.php'); require("../contract/conn.php"); - +$now = date("Y-m-d"); $contract_type = [ '1' => '新梯', @@ -30,15 +30,16 @@ if ($user_id != 'M0225') { if (!empty($_GET['check'])) { // 人事發放作業,應為一個月內 if ($_GET['check'] == 4) { - $clause .= "AND pay_day_due > DATE_SUB(NOW(), INTERVAL 1 MONTH)"; + $oneMonthAgo = date("Y-m-d", strtotime("$now +1 months")); + $clause .= "AND pay_day_due >= '$now' AND pay_day_due <= '$oneMonthAgo'"; } else if ($_GET['check'] == 2) { $clause .= "AND status = 1"; } else if ($_GET['check'] == 3) { - $clause .= "AND status = 2"; + $clause .= "AND status IN (2,5)"; } } -$sql = "SELECT * FROM bonus WHERE 1=1 $clause LIMIT 50"; +$sql = "SELECT * FROM bonus WHERE 1=1 $clause"; $stmt = $conn->prepare($sql); $stmt->execute(); $datas = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -47,14 +48,13 @@ $datas = $stmt->fetchAll(PDO::FETCH_ASSOC); $now = new DateTime(); $oneMonthAgo = $now->modify('+1 month'); + $id = []; foreach ($datas as $data) { $id[] = $data['id']; } $id_str = implode(',', $id); -echo "
"; -print_r($id_str); -echo ''; + // 查看 T8 是否有收款明細 // require("./api/get.php"); function isPay($contract_no, $connT8) @@ -121,9 +121,9 @@ function isPay($contract_no, $connT8)
項次 | @@ -142,12 +143,13 @@ function isPay($contract_no, $connT8)作番號 | 獎金類別 | 獎金版本 | -作番總價 | +作番金額(月) | 牌價 | 服務費 | 應發人員 | 預計發放時間 | -獎金水庫 | +應發獎金水庫 | +實發金額 | 狀態 | 實際發放時間發放 / 詳情 | - + +詳情 | += $data['facility_no'] ?> | = $bonus_type[$data['bonus_type']] ?> | = $data['bonus_verson'] ?> | -= $total ?> | = $fee_per_st ?> | += $total ?> | = $commission_fee ?> | = $data['receiver'] ?> | = $data['pay_day_due'] ?> | = $data['amount'] ?> | += $data['bonus_actual'] ?> | = $bonus_status[$data['status']] ?> @@ -193,11 +198,9 @@ function isPay($contract_no, $connT8) | -- | - + | = $data['pay_day'] ?> | -+ | 查看詳情 | - + +查看詳情 | + const datas = ; - function issue(id, user_id, pay_day) { + function issue(id, user_id, pay_day, amount) { // console.log(id); const form = new FormData(); form.append('id', id) form.append('user_id', user_id); form.append('pay_day', pay_day) + form.append('amount', amount); + form.append('postType', 'a'); axios.post('./api/postStatus.php', form).then((res) => { if (res.data == 'Success') { alert('更新成功'); @@ -334,15 +341,20 @@ function isPay($contract_no, $connT8) function All(data) { let arr = data.split(","); - console.log(arr); const form = new FormData(); form.append('id', arr); + form.append('user_id', '= $user_id ?>') form.append('postType', 'd'); - axios.post('./api/postStatus.php', form).then((res) => { - console.log(res); - }).catch((err) => { - - }); + if (confirm('是否發放全部獎金')) { + axios.post('./api/postStatus.php', form).then((res) => { + if (res.status == 200) { + alert('更新成功'); + location.reload(); + } + }).catch((err) => { + + }); + } } // $(function() { // $("button[name=issuePay]").click(function() { diff --git a/wms/bonus/bonus_check.php b/wms/bonus/bonus_check.php new file mode 100644 index 00000000..82eb1ea9 --- /dev/null +++ b/wms/bonus/bonus_check.php @@ -0,0 +1,199 @@ +prepare($sql); +$stmt->bindParam(':id', $_GET['id']); +$stmt->execute(); +$result = $stmt->fetch(PDO::FETCH_ASSOC); +// echo '
---|
+ 獎金計算+ |
+ |||||||
+ 獎金確認項+ |
+ + + + | +||||||
合約號 | ++ + | +合約類別 | +
+
+ 未填寫 + |
+ 作番號 | ++ + | + +獎金適用版本 | ++ + | +
保養類別 | ++ + | +付款方式 | ++ + | +合約付款日 | ++ + | +應發獎金 | ++ + | +
作番總價 | ++ + | +牌價 | ++ + | +服務費 | ++ + | +價率 | ++ + | + +
實發獎金 | ++ + | +實發時間 | ++ | +備註 | ++ | + | + |
'; - // print_r(json_encode($data)); - // echo ''; $api_url = 'https://erp.masada.com.tw:780/twWebAPI/V1/SALINCOMEAPPLY/PostERPData'; $validation = get_Auth(); + echo '
'; + print_r(json_encode($data)); + echo ''; $header = [ - "CHI_Authorization :" . $validation + "CHI_Authorization :" . $validation, + "GroupId:TEST" ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $api_url); // 设置请求的URL @@ -20,6 +21,7 @@ function T8API($data) curl_setopt($ch, CURLOPT_POST, 1); // 使用 POST curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); $response = curl_exec($ch); + if ($response === false) { echo 'Curl error: ' . curl_error($ch); } else { @@ -32,6 +34,7 @@ function T8API($data) // print_r($result); return $result; } + return $result; } curl_close($ch); diff --git a/wms/contract/api/postContractData.php b/wms/contract/api/postContractData.php index 6612368b..d9f61baf 100644 --- a/wms/contract/api/postContractData.php +++ b/wms/contract/api/postContractData.php @@ -36,10 +36,36 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $elevators = !empty($_POST['elevators']) ? json_decode($_POST['elevators'], true) : []; $payType = !empty($_POST['payType']) ? $_POST['payType'] : null; // validate + //create facility table + $createFacilityNo = new CreateFacilityNo(); + $dailyNecessities = [ + 'MAE100' => 'X', + 'MAM200' => 'W', + 'MAH100' => 'H', + 'MAQ100' => 'Z', + 'MAF100' => 'F', + 'MAZ100' => 'B', + ]; + $maintain_times = [ + '1' => 'em', //月保 + '2' => 'bw' // 雙周保 + ]; + $facility_arr = []; + foreach ($elevators as $elevator) { + $facility_arr[] = $dailyNecessities[$elevator['spec']]; + } + echo json_encode($facility_arr); + // 電梯做番號 + $facilityno = $createFacilityNo->makeBFacilityNo("T", $facility_arr, (int)$num); + // if ($user_id == 'M0225') { + // echo '
'; + // print_r($facilityno); + // echo ''; + // exit(); + // } + echo json_encode($facilityno); /// 獎金計算 - bonusCreate($elevators); - $fail_arr = []; if ($contractno === '') return $fail_arr[] = '合約號為必填'; if ($total_price == '') $fail_arr[] = '合約總價為必填'; @@ -66,7 +92,8 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c echo json_encode($fail_arr); exit(); } - + T8insert($_POST, $facilityno); + bonusCreate($_POST, $facilityno, $conn); //create account table $accounttype = "A"; $accountid = $vat; @@ -78,6 +105,8 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $create_at = date('Y-m-d H:i:s'); $conn->beginTransaction(); + // bonusCreate($_POST, $facilityno, $conn); + // exit(); $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); @@ -130,35 +159,35 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c $stmt->execute(); //create facility table - $createFacilityNo = new CreateFacilityNo(); - $dailyNecessities = [ - 'MAE100' => 'X', - 'MAM200' => 'W', - 'MAH100' => 'H', - 'MAQ100' => 'Z', - 'MAF100' => 'F', - 'MAZ100' => 'B', - ]; - - $maintain_times = [ - '1' => 'em', //月保 - '2' => 'bw' // 雙周保 - ]; - $facility_arr = []; - foreach ($elevators as $elevator) { - $facility_arr[] = $dailyNecessities[$elevator['spec']]; - } - echo json_encode($facility_arr); - // 電梯做番號 - $facilityno = $createFacilityNo->makeBFacilityNo("T", $facility_arr, (int)$num); - // if ($user_id == 'M0225') { - // echo '
'; - // print_r($facilityno); - // echo ''; - // exit(); + // $createFacilityNo = new CreateFacilityNo(); + // $dailyNecessities = [ + // 'MAE100' => 'X', + // 'MAM200' => 'W', + // 'MAH100' => 'H', + // 'MAQ100' => 'Z', + // 'MAF100' => 'F', + // 'MAZ100' => 'B', + // ]; + + // $maintain_times = [ + // '1' => 'em', //月保 + // '2' => 'bw' // 雙周保 + // ]; + // $facility_arr = []; + // foreach ($elevators as $elevator) { + // $facility_arr[] = $dailyNecessities[$elevator['spec']]; // } - echo json_encode($facilityno); - echo '-------'; + // echo json_encode($facility_arr); + // // 電梯做番號 + // $facilityno = $createFacilityNo->makeBFacilityNo("T", $facility_arr, (int)$num); + // // if ($user_id == 'M0225') { + // // echo '
'; + // // print_r($facilityno); + // // echo ''; + // // exit(); + // // } + // echo json_encode($facilityno); + // echo '-------'; $sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid"; $stmt = $conn->prepare($sql_str); $stmt->bindParam(':accountid', $mworker); @@ -204,7 +233,7 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c // $comboNo = new CreateComboNo($mcycle, $contract_begin_date, $contract_end_date); // $comboArr = json_decode($comboNo->getComboNo(), true); foreach ($facilityno as $no) { - // $comboNo = new CreateComboNo($maintain_times[$elevator['maintain_times']], $contract_begin_date, $contract_end_date); + $comboNo = new CreateComboNo($maintain_times[$elevator['maintain_times']], $contract_begin_date, $contract_end_date); $comboArr = json_decode($comboNo->getComboNo(), true); 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)'; @@ -328,7 +357,6 @@ if (isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['c // T8insert($_POST, $facilityno); - header('Content-Type: application/json'); $jsonData = json_encode($files); @@ -362,7 +390,6 @@ function T8insert($data, $facilityno) $elevators = !empty($data['elevators']) ? json_decode($data['elevators'], true) : []; //電梯 $area = !empty($data['area']) ? $data['area'] : null; //縣市 Ex. A->台北 , B-> ..。 $payType = !empty($data['payType']) ? $data['payType'] : null; - $user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : null; @@ -373,8 +400,8 @@ function T8insert($data, $facilityno) $stmt->bindParam(':BizPartnerId', $contractno); $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); - $date = date('Y-m-sH-s-i'); - $date_1 = date('Y-m-s'); + $date = date('Y-m-dH-s-i'); + $date_1 = date('Y-m-d'); $createTime = str_replace("-", '', $date); $insertTime = str_replace('-', '', $date_1); $beginDate = str_replace("-", '', $contract_begin_date); @@ -493,12 +520,12 @@ function T8insert($data, $facilityno) // echo '
'; // print_r($elevator); // echo ''; - + $facility_no = $facilityno[$index]; $sql = "INSERT INTO comMaterial (FOrgid,MaterialId,MaterialTypeId,MaterialCategoryId,CreatorId,CreateTime) VALUES ('1000',:MaterialId,'10','E',:CreatorId,:CreateTime)"; $stmt = $connT8->prepare($sql); - $stmt->bindParam(':MaterialId', $facilityno[$index]); + $stmt->bindParam(':MaterialId', $facility_no); $stmt->bindParam(':CreatorId', $user_id); $stmt->bindParam(':CreateTime', $createTime); $stmt->execute(); @@ -507,7 +534,7 @@ function T8insert($data, $facilityno) (MaterialTypeId,MaterialId,MaterialName,MaterialCategoryId,IsInUsed,UnitId,CreatorId,CreateTime) VALUES ('10',:MaterialId,:MaterialName,'E',1,'SET',:CreatorId,:CreateTime)"; $stmt = $connT8->prepare($sql); - $stmt->bindParam(':MaterialId', $facilityno[$index]); + $stmt->bindParam(':MaterialId', $facility_no); $stmt->bindParam(':MaterialName', $customer); $stmt->bindParam(':CreatorId', $user_id); $stmt->bindParam(':CreateTime', $createTime); @@ -517,7 +544,7 @@ function T8insert($data, $facilityno) (Orgid,MaterialTypeId,MaterialId,CurrId,SUnitId,TaxId,CreatorId,CreateTime) VALUES ('1000','10',:MaterialId,'TWD','SET','ST005',:CreatorId,:CreateTime)"; $stmt = $connT8->prepare($sql); - $stmt->bindParam(':MaterialId', $facilityno[$index]); + $stmt->bindParam(':MaterialId', $facility_no); $stmt->bindParam(':CreatorId', $user_id); $stmt->bindParam(':CreateTime', $createTime); $stmt->execute(); @@ -533,6 +560,9 @@ function T8insert($data, $facilityno) //分幾期 => 總共保養月 / 分期月 $SQuantity = $elevator['maintain_months'] / $IncomeId[$payType]; + $date_1 = getNext25thDate($contract_begin_date); + + // 依每台電梯去加入各個的付款項 for ($i = 0; $i < $IncomeId[$payType]; $i++) { $row++; @@ -547,14 +577,16 @@ function T8insert($data, $facilityno) "RowCode" => $row, "RowNo" => $row, "ItemType" => 1, - "SPrice" => $elevator['sold_price'], + "SPrice" => intval($elevator['sold_price']), "SQuantity" => $SQuantity, "ProjectId" => "$contractno", - "FromSourceTag" => 0, - "CU_MaterialId" => "$facilityno[$index]", - "CU_EstPayDate" => "$payDay" + "CU_MaterialId" => "$facility_no", + "CU_EstPayDate" => intval($payDay) ]; $salIncomeApplyDetail_rows[] = $rows_data; + // echo '
'; + // print_r($salIncomeApplyDetail_rows); + // echo ''; } } @@ -564,7 +596,7 @@ function T8insert($data, $facilityno) // $insertime = settype($insertTime, 'integer'); $salIncomeApplyMaster_rows = [ "BillNo" => "$contractno", - "BillDate" => $insertTime, + "BillDate" => intval($insertTime), "OrgId" => "1000", "FOrgId" => "1000", "TypeId" => "RAS", @@ -578,7 +610,8 @@ function T8insert($data, $facilityno) "DueToId" => "$contractno", "TaxId" => "ST005", "CompId" => "1001", - "CreatorId" => "$user_id" + "CreatorId" => "$user_id", + "CreateTime" => intval($insertTime) ]; $salIncomeApplyMaster = [ @@ -593,6 +626,9 @@ function T8insert($data, $facilityno) $API_body[] = $salIncomeApplyMaster; $API_body[] = $salIncomeApplyDetail; // 呼叫 API + // echo '
'; + // print_r($API_body); + // echo ''; $result = T8API($API_body); if ($result['Status'] == 'Error' || $result['Status'] == 'Fails') { @@ -603,15 +639,100 @@ function T8insert($data, $facilityno) } -function bonusCreate($elevators) +function bonusCreate($data, $facilityno, $conn) { - require_once("../../bonus/other/maintenance_contract_bonus_v2_1.php"); - $elevators = !empty($elevators) ? $elevators : ''; + try { + require_once("../../bonus/other/maintenance_contract_bonus_v2_1.php"); + $elevators = !empty($_POST['elevators']) ? json_decode($_POST['elevators'], true) : []; + $contract_begin_date = !empty($data['contract_begin_date']) ? $data['contract_begin_date'] : ''; + $salesman = !empty($data['salesman']) ? $data['salesman'] : ''; + $payType = !empty($data['payType']) ? $data['payType'] : ''; + $status = 1; + $bonus_json = []; + $create_id = $data['user_id']; + $create_at = date('Y-m-d'); + $contract_no = !empty($data['contractno']) ? $data['contractno'] : ''; + $contract_kind = 3; + + $payment = [ + 'A40006' => 'annually', //年繳 + 'A40007' => 'quarterly', //季繳 + 'A40004' => 'bimonthly', // 雙月繳 + 'A40005' => 'semiannually', // 半年繳 + 'A40003' => 'monthly' //月繳 + ]; - foreach ($elevators as $elevator) { - echo '
'; - print_r($elevator); - echo ''; - exit; + $payDay = getNext25thDate($contract_begin_date); + foreach ($elevators as $key => $elevator) { + // print_r($payDay); + // echo '
'; + // print_r($elevator); + // echo ''; + // exit; + $facility_no = $facilityno[$key]; + $ver = $elevator['bonus_verson']; //獎金版本 + $contract_type = $elevator['contract_type']; //合約類別 + $payment_period = $payment[$payType]; //付款方式 + $elevator_list_price = $elevator['stand_price']; //牌價 + $fee_per_st = $elevator['contract_price']; //作翻契約金額 + $commission_fee = $elevator['service_expense']; //服務費(月) + $receivable_date_due = $payDay; //第一筆保養款項收回日 + $sales_id = $salesman; //營業人員 + $discount = $elevator['discount']; + $region_director_id = $elevator['manager']; + $regular_contract_manger_id = !empty($elevator['regular_contract_manger_id']) ? $elevator['regular_contract_manger_id'] : ''; + $results = maintenance_contract_bonus_v2_1($ver, $contract_type, $payment_period, $elevator_list_price, $fee_per_st, $commission_fee, $receivable_date_due, $sales_id, $region_director_id, $regular_contract_manger_id); + + $bonus_json = [ + 'contract_type' => $contract_type, + 'total' => $elevator_list_price, + 'fee_per_st' => $fee_per_st, + 'commission_fee' => $commission_fee, + 'paykind' => $payment_period, + 'receivable_date_due' => $receivable_date_due, + 'discount' => $discount + ]; + if ($results['result_status'] != 'error') { + foreach ($results['bonus_array'] as $i => $result) { + + $bonus_type = $result['bonus_type']; + $pay_day = $result['pay_day_due']; + $amount = $result['bonus_amount']; + $receiver = $result['bonus_receiver']; + $a = json_encode($bonus_json); + $sql = "INSERT INTO bonus + (bonus_type,bonus_verson,contract_no,contract_type,facility_no,amount,receiver,pay_day_due,status,bonus_json,create_id,create_at) VALUES + ($bonus_type,'$ver','$contract_no',$contract_kind,'$facility_no',$amount,'$receiver','$pay_day',$status,'$a','$create_id','$create_at')"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + } + } + } + // exit(); + } catch (PDOException $e) { + http_response_code(404); + echo $e->getMessage(); + die('Error!:' . $e->getMessage()); + } +} + +// 計算保養開始日期的當月25號 +function getNext25thDate($dateString) +{ + // 將傳入的日期字串轉換成 Unix 時間戳記 + $timestamp = strtotime($dateString); + + // 取得該日期的日期 + $day = date('d', $timestamp); + + // 如果日期大於 25,則回傳下個月的 25 號日期 + if ($day > 25) { + // 增加一個月 + $timestamp = strtotime('+1 month', $timestamp); } + + // 設定日期為 25 號 + $targetDate = date('Y-m-25', $timestamp); + + return $targetDate; } diff --git a/wms/contract/api/testT8API.php b/wms/contract/api/testT8API.php index 59730e98..d2f2f4e4 100644 --- a/wms/contract/api/testT8API.php +++ b/wms/contract/api/testT8API.php @@ -1,21 +1,28 @@ '; -// print_r($countDay); -// echo ''; -// exit(); -$SQuantity = 2; -// $b = 24 / $a; -for ($i = 0; $i < 12; $i++) { - $paymonth = $i * $SQuantity; - $countDay = date('Y-m-d', strtotime("$date + $paymonth months")); - $payDay = str_replace('-', '', $countDay); - echo '
'; - print_r($payDay); - echo ''; +function getNext25thDate($dateString) +{ + // 將傳入的日期字串轉換成 Unix 時間戳記 + $timestamp = strtotime($dateString); + + // 取得該日期所在月份的天數 + $daysInMonth = date('t', $timestamp); + + // 取得該日期的日期 + $day = date('d', $timestamp); + + // 如果日期大於 25,則回傳下個月的 25 號日期 + if ($day > 25) { + // 增加一個月 + $timestamp = strtotime('+1 month', $timestamp); + } + + // 設定日期為 25 號 + $targetDate = date('Y-m-25', $timestamp); + + return $targetDate; } + +// 測試函數 +$dateString = '2024-05-1'; +$next25thDate = getNext25thDate($dateString); +echo "傳入日期的下個 25 號日期是:$next25thDate"; diff --git a/wms/contract/contract-input.php b/wms/contract/contract-input.php index 5a2f4f68..04a783f1 100644 --- a/wms/contract/contract-input.php +++ b/wms/contract/contract-input.php @@ -374,7 +374,7 @@ $contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);