diff --git a/wms/account-receivable-renovate-excel.php b/wms/account-receivable-renovate-excel.php index 77341d5a..36463a97 100644 --- a/wms/account-receivable-renovate-excel.php +++ b/wms/account-receivable-renovate-excel.php @@ -13,30 +13,51 @@ $Bill = json_decode(file_get_contents("php://input"), true); $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); // file_put_contents('account-receivable.txt', json_encode($Bill)); +if ($type == 'repair') { + $colomnHeader = [ + '合約號', '合約日期', '客戶編號', '客戶名稱', + '部門', '契約人員工號', '契約人員名稱', + '主管工號', '主管名稱', + '合約總金額', '應收金額', + '已開金額', '未開金額', + '已收金額', '催收金額', '催收次數' + ]; + $sheet->fromArray($colomnHeader, NULL, 'A1'); + $rowIndex = 2; + foreach ($Bill as $key => $value) { -$colomnHeader = [ - '合約號', '作番號', '部門編號', '部門名稱', '主管工號','主管名稱', '營業員工號', '營業員名稱', '客戶名稱', '抬頭', '統編', '通訊地址', - '收款階段名稱', '應收日期','是否應收', '應收金額', '已開金額','未開金額', '已收金額','催收金額', '催收次數' -]; -$sheet->fromArray($colomnHeader, NULL, 'A1'); -$rowIndex = 2; -foreach ($Bill as $key => $value) { - - $sheet->fromArray($value, NULL, 'A' . $rowIndex); - $column = [ - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R','S','T' + $sheet->fromArray($value, NULL, 'A' . $rowIndex); + $column = [ + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q' + ]; + foreach ($column as $col) { + $sheet->getColumnDimension($col)->setAutoSize(true); + } + $rowIndex++; + } + $writer = new Xlsx($spreadsheet); + $excelFileName = 'account-receivable-repair.xlsx'; +} else { + $colomnHeader = [ + '合約號', '作番號', '部門編號', '部門名稱', '主管工號', '主管名稱', '營業員工號', '營業員名稱', '客戶名稱', '抬頭', '統編', '通訊地址', + '收款階段名稱', '應收日期', '是否應收', '應收金額', '已開金額', '未開金額', '已收金額', '催收金額', '催收次數' ]; - foreach ($column as $col) { - $sheet->getColumnDimension($col)->setAutoSize(true); + $sheet->fromArray($colomnHeader, NULL, 'A1'); + $rowIndex = 2; + foreach ($Bill as $key => $value) { + + $sheet->fromArray($value, NULL, 'A' . $rowIndex); + $column = [ + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T' + ]; + foreach ($column as $col) { + $sheet->getColumnDimension($col)->setAutoSize(true); + } + $rowIndex++; } - $rowIndex++; + $writer = new Xlsx($spreadsheet); + $excelFileName = 'account-receivable-renovate.xlsx'; } -$writer = new Xlsx($spreadsheet); -$excelFileName = 'account-receivable-renovate.xlsx'; $writer->save($excelFileName); echo $excelFileName; -?> - \ No newline at end of file diff --git a/wms/account-receivable-renovate.xlsx b/wms/account-receivable-renovate.xlsx index 3c8c5dcf..0228fc23 100644 Binary files a/wms/account-receivable-renovate.xlsx and b/wms/account-receivable-renovate.xlsx differ diff --git a/wms/account-receivable-repair-index.php b/wms/account-receivable-repair-index.php new file mode 100644 index 00000000..bd1d7acc --- /dev/null +++ b/wms/account-receivable-repair-index.php @@ -0,0 +1,483 @@ += $start_date "; +} +if (!is_null($end_date)) { + $end_date = (int)date('Ymd', strtotime($end_date)); + $sql_contractNumber .= " AND MainAll.BillDate <= $end_date "; +} +if ((in_array($user_id, array('M0008', 'M0012'))) || (in_array(accountidToDepartId($user_id), array('220', '210', '501')))) { +} else { + $sql_contractNumber .= " AND (MainAll.PersonId = '$user_id'"; + if (count($follower) > 0) { + $column_str = "('$user_id'" . ",'"; + $column_str .= implode("','", $follower); + $column_str .= "')"; + $sql_contractNumber .= " OR MainAll.PersonId IN $column_str)"; + } else { + $sql_contractNumber .= ")"; + }; +} + +$contractNumbers = array(); +$query_contract_number = $conn->query($sql_contractNumber); +if (is_iterable($query_contract_number)) { + foreach ($query_contract_number as $contract_numbers) { + array_push($contractNumbers, $contract_numbers['BillNo']); + $arrayData[$contract_numbers['BillNo']]['BillNo'] = isset($contract_numbers['BillNo']) ? $contract_numbers['BillNo'] : '--'; + $arrayData[$contract_numbers['BillNo']]['BillDate'] = isset($contract_numbers['BillDate']) ? $contract_numbers['BillDate'] : '--'; + $arrayData[$contract_numbers['BillNo']]['CustomerId'] = isset($contract_numbers['BizPartnerId']) ? $contract_numbers['BizPartnerId'] : '--'; + $arrayData[$contract_numbers['BillNo']]['CustomerName'] = isset($contract_numbers['BizPartnerName']) ? $contract_numbers['BizPartnerName'] : '--'; + $arrayData[$contract_numbers['BillNo']]['CustomerAddress'] = isset($contract_numbers['ContactAddress']) ? $contract_numbers['ContactAddress'] : '--'; + $arrayData[$contract_numbers['BillNo']]['OAmountWithTax'] = isset($contract_numbers['OAmountWithTax']) ? $contract_numbers['OAmountWithTax'] : 0; + $arrayData[$contract_numbers['BillNo']]['PersonId'] = isset($contract_numbers['PersonId']) ? $contract_numbers['PersonId'] : '--'; + $arrayData[$contract_numbers['BillNo']]['DeptId'] = isset($contract_numbers['DeptId']) ? $contract_numbers['DeptId'] : '--'; + $arrayData[$contract_numbers['BillNo']]['PersonName'] = isset($contract_numbers['PersonName']) ? $contract_numbers['PersonName'] : '--'; + $arrayData[$contract_numbers['BillNo']]['DeptName'] = isset($contract_numbers['DeptName']) ? $contract_numbers['DeptName'] : '--'; + $arrayData[$contract_numbers['BillNo']]['ShortName'] = isset($contract_numbers['ShortName']) ? $contract_numbers['ShortName'] : '--'; + $arrayData[$contract_numbers['BillNo']]['ManagerId'] = !empty($find_manager[$contract_numbers['PersonId']]['manager']) ? $find_manager[$contract_numbers['PersonId']]['manager'] : '--'; + $arrayData[$contract_numbers['BillNo']]['ManagerName'] = !empty($find_manager[$contract_numbers['PersonId']]['manager_name']) ? $find_manager[$contract_numbers['PersonId']]['manager_name'] : '--'; + $arrayData[$contract_numbers['BillNo']]['invoice_budget'] = 0; + $arrayData[$contract_numbers['BillNo']]['received_budget'] = 0; + $arrayData[$contract_numbers['BillNo']]['receivable_budget'] = 0; + $sum_total_budget += $contract_numbers['OAmountWithTax']; + } + $str_numbers = "('" . implode("','", $contractNumbers) . "')"; +} + +// T8發票 +$sql_invoice = "SELECT +Detail.BillNo AS InvoiceBillNo, +Detail.MaterialId, +Detail.LAmountWithTax, +Main.InvoiceNo, +CheckAll.FromSalSalesOrder AS BillNo + FROM arSellInvoiceMaterial AS Detail + LEFT JOIN arSellInvoice AS Main ON Detail.BillNo=Main.BillNo + LEFT JOIN ( + SELECT CheckDetail.BillNo, CheckDetail.FromSalSalesOrder, CheckDetail.RowNo + FROM arCheckBillDetail AS CheckDetail ) + AS CheckAll ON CheckAll.BillNo= Detail.FromBillNo AND Detail.FromRowCode = CheckAll.RowNo + WHERE Detail.ItemType=0 AND Main.InvoiceState!=2"; + +// T8核銷 +$sql_received = "SELECT +CheckDetail.OrderBillNo, +arWriteOffBillDetail.FromBillNo AS CheckBillNo, +arWriteOffBillDetail.FromRowCode AS CheckRowCode, +arWriteOffBillDetail.CurrStandOffOAmount +FROM arWriteOffBillDetail + LEFT JOIN + (SELECT + arCheckBillDetail.BillNo, + arCheckBillDetail.RowCode, + arCheckBillDetail.FromSalSalesOrder AS OrderBillNo, + salSalesOrder.TypeId + FROM arCheckBillDetail + LEFT JOIN salSalesOrder + ON salSalesOrder.BillNo =arCheckBillDetail.FromSalSalesOrder ) + AS CheckDetail + ON CheckDetail.BillNo=arWriteOffBillDetail.FromBillNo AND arWriteOffBillDetail.FromRowCode = CheckDetail.RowCode +WHERE CheckDetail.TypeId = 'SP'"; + + +//T8 銷售訂單 階段收款計畫 +$sql_paystage = "SELECT * from salOrderStagePay"; +if (isset($str_numbers)) { + $sql_paystage .= " WHERE BillNo IN $str_numbers "; + $sql_invoice .= " AND CheckAll.FromSalSalesOrder IN $str_numbers "; +} + +$PayStage = $conn->query($sql_paystage); +$received_array = $conn->query($sql_received); +$invoice_data = $conn->query($sql_invoice); + +$allPayStages = array(); +foreach ($PayStage as $stage) { + $allPayStages[$stage['BillNo']][$stage['PayStage']]['PlanPayAmt'] = $stage['PlanPayAmt']; + $allPayStages[$stage['BillNo']][$stage['PayStage']]['PlanPayDate'] = $stage['PlanPayDate']; + $month = collect_month(strtotime($stage['PlanPayDate'])); + if (strtotime($stage['PlanPayDate']) > strtotime(date('Y-m-t', strtotime('now')))) { + $allPayStages[$stage['BillNo']][$stage['PayStage']]['receivable_ornot'] = '--'; + } else { + $allPayStages[$stage['BillNo']][$stage['PayStage']]['receivable_ornot'] = 'Y'; + } + $allPayStages[$stage['BillNo']][$stage['PayStage']]['month'] = $month; + $allPayStages[$stage['BillNo']][$stage['PayStage']]['received'] = 0; + $allPayStages[$stage['BillNo']][$stage['PayStage']]['invoice'] = 0; +} +foreach ($allPayStages as $paykey => $pay) { + uasort($allPayStages[$paykey], 'comparePlanPayDate'); +} + +foreach ($allPayStages as &$payStage) { + $sequenceNumber = 1; + foreach ($payStage as $tk => &$pstage) { + $pstage['sequenceNumber'] = $sequenceNumber; + $sequenceNumber += 1; + } +} +// 整理好的收款階段 +$final_paystage = array(); +foreach ($allPayStages as $key => &$payStage) { + if (is_iterable($payStage)) { + foreach ($payStage as $key2 => $pstage) { + if (isset($arrayData[$key])) { + $arrayData[$key]['PayStage'][$pstage['sequenceNumber']] = $pstage; + if (isset($pstage['receivable_ornot']) && $pstage['receivable_ornot'] == 'Y') { + $arrayData[$key]['receivable_budget'] += $pstage['PlanPayAmt']; + } + } + } + } +} + +foreach ($invoice_data as $inv) { + if (isset($arrayData[$inv['BillNo']])) { + + $arrayData[$inv['BillNo']]['invoice_budget'] += $inv['LAmountWithTax']; + + if (isset($arrayData[$inv['BillNo']]['invoice'][$inv['InvoiceNo']])) { + $arrayData[$inv['BillNo']]['invoice'][$inv['InvoiceNo']] += $inv['LAmountWithTax']; + } else { + $arrayData[$inv['BillNo']]['invoice'][$inv['InvoiceNo']] = $inv['LAmountWithTax']; + } + } +} +foreach ($received_array as $received) { + if (isset($arrayData[$received['OrderBillNo']]) && isset($received['CurrStandOffOAmount']) && $received['CurrStandOffOAmount'] > 0) { + $arrayData[$received['OrderBillNo']]['received_budget'] += $received['CurrStandOffOAmount']; + } +} + + +foreach ($arrayData as $key => &$value) { + if (!isset($value['PayStage'])) { + $value['receivable_budget'] = $value['OAmountWithTax']; + } else { + $tmpReceived = $value['received_budget']; + $tmpInvoice = $value['invoice_budget']; + if (is_iterable($value['PayStage'])) { + for ($sequence = 1; $sequence <= count($value['PayStage']); $sequence++) { + if ($value['PayStage'][$sequence]['PlanPayAmt'] > $tmpInvoice) { + $value['PayStage'][$sequence]['invoice'] = $tmpInvoice; + $tmpInvoice = 0; + } else { + $value['PayStage'][$sequence]['invoice'] = $value['PayStage'][$sequence]['PlanPayAmt']; + $tmpInvoice -= $value['PayStage'][$sequence]['PlanPayAmt']; + } + if ($value['PayStage'][$sequence]['PlanPayAmt'] > $tmpReceived) { + $value['PayStage'][$sequence]['received'] = $tmpReceived; + $tmpReceived = 0; + } else { + $value['PayStage'][$sequence]['received'] = $value['PayStage'][$sequence]['PlanPayAmt']; + $tmpReceived -= $value['PayStage'][$sequence]['PlanPayAmt']; + } + } + } + $value['received_budget'] = $tmpReceived; + } + if ($value['receivable_budget'] > 0 && $value['received_budget'] < $value['receivable_budget']) { + $value['month'] = collect_month(strtotime($value['BillDate'])); + } else { + $value['month'] = 0; + } +} + +$excel_aray = array(); + +foreach ($arrayData as $key => $value) { + $uninvoice_budget = $value['OAmountWithTax'] - $value['invoice_budget']; + $unreceive_budget = $value['receivable_budget'] - $value['received_budget']; + + $excel_aray[$key] = [ + $value['BillNo'], date('Y-m-d', strtotime($value['BillDate'])), $value['CustomerId'], $value['CustomerName'], + $value['DeptName'], $value['PersonId'], $value['PersonName'], + $value['ManagerId'], $value['ManagerName'], + number_format(round($value['OAmountWithTax'])), number_format(round($value['receivable_budget'])), + number_format(round($value['invoice_budget'])), number_format(round($uninvoice_budget)), + number_format(round($value['received_budget'])), $unreceive_budget, $value['month'] + ]; +} + +$total_data = json_encode($excel_aray); + +?> + + +
+
+ +
+
+
+
+

零件 & 維修 應收帳款

+
+
+ + + + + + + + + + + +
合約日期 + + ~ + + +
合約總金額 + +
+
+
+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ +
+
+ +
+
+
+ +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + $row) { ?> + + + + + + + + + + + + + + + + + + + +
合約號合約日期客戶編號客戶名稱部門主管契約員合約總金額應收金額已開金額未開金額已收金額催收金額催收次數
" . $row[8]; ?>" . $row[6]; ?>
+
+ + \ No newline at end of file diff --git a/wms/account-receivable-repair.xlsx b/wms/account-receivable-repair.xlsx new file mode 100644 index 00000000..5a68dac9 Binary files /dev/null and b/wms/account-receivable-repair.xlsx differ diff --git a/wms/bons/api/get.php b/wms/bons/api/get.php deleted file mode 100644 index b50687a3..00000000 --- a/wms/bons/api/get.php +++ /dev/null @@ -1,75 +0,0 @@ -prepare($sql); -$stmt->execute(); -$data = $stmt->fetch(PDO::FETCH_ASSOC); -$data['amount'] = intval($data['amount']); -$checkBillNo = $data['CBno']; - - -$sql = "SELECT - c.BillDate AS CheckBillDate - FROM arWriteOffBill AS a - LEFT JOIN arWriteOffBillRec AS b ON a.BillNo=b.BillNo - LEFT JOIN - (SELECT temp1.*,arWriteOffBillDetail.* FROM arWriteOffBillDetail - LEFT JOIN - (SELECT - arCheckBill.BillNo AS checkBillNo, arCheckBill.BillDate,arCheckBillInvInfo.InvoiceNo - FROM arCheckBill - LEFT JOIN arCheckBillInvInfo - ON arCheckBill.InvoiceBillNo=arCheckBillInvInfo.InvoiceBillNo) AS temp1 - ON temp1.checkBillNo = arWriteOffBillDetail.FromBillNo) AS c - ON a.BillNo=c.BillNo - WHERE c.checkBillNo = '$checkBillNo' - "; - -$stmt = $connT8->prepare($sql); -$stmt->execute(); -$check = $stmt->fetch(PDO::FETCH_ASSOC); - - - -$CU_MaterialId = $data['facility']; -$sql = "SELECT SQuantity FROM salIncomeApplyDetail WHERE BillNo = :contract_no AND CU_MaterialId = :CU_MaterialId"; -$stmt = $connT8->prepare($sql); -$stmt->bindParam(':contract_no', $contract_no); -$stmt->bindParam(':CU_MaterialId', $CU_MaterialId); -$stmt->execute(); -$result = $stmt->fetchAll(PDO::FETCH_ASSOC); -$count = COUNT($result); -$data['maintain_month'] = intval($count * $result[0]['SQuantity']); - - - - -if (!empty($check['CheckBillDate'])) { - header('Content-Type: application/json'); - echo json_encode($data); -} else { - echo false; - exit; -} -// } diff --git a/wms/bons/maintainance_contract_payment_status.php b/wms/bons/maintainance_contract_payment_status.php deleted file mode 100644 index ed76f046..00000000 --- a/wms/bons/maintainance_contract_payment_status.php +++ /dev/null @@ -1,399 +0,0 @@ -query($sql); - -function getContractnoDetails($link, $user_id, $contractno = null) -{ - $sql = " - SELECT - c.contractno - FROM contract AS c - LEFT JOIN con_maintance_examine_apply AS cmea - ON c.contractno = cmea.vol_no - WHERE 1 = 1 - AND cmea.salesman IN (" . getAccountids($link, $user_id) . ") - "; - if (!empty($contractno)) { - $sql .= " - AND c.contractno = '$contractno' - "; - } - $result = mysqli_query($link, $sql); - $data = []; - foreach ($result as $row) { - array_push($data, $row['contractno']); - } - return "'" . implode("','", $data) . "'"; -} - -function getSalesmanNo($link, $contractno) -{ - $sql = " - SELECT - cmea.salesman - FROM contract AS c - LEFT JOIN con_maintance_examine_apply AS cmea - ON c.contractno = cmea.vol_no - WHERE 1 = 1 - AND c.contractno IN ('$contractno') - "; - $result = mysqli_query($link, $sql); - $data = []; - foreach ($result as $row) - return $row['salesman']; - return ""; -} -function getSalesmanName($link, $contractno) -{ - $sql = " - SELECT - a.name - FROM contract AS c - LEFT JOIN con_maintance_examine_apply AS cmea - ON c.contractno = cmea.vol_no - LEFT JOIN account AS a - ON cmea.salesman = a.accountid - WHERE 1 = 1 - AND c.contractno IN ('$contractno') - "; - $result = mysqli_query($link, $sql); - $data = []; - foreach ($result as $row) - return $row['name']; - return ""; -} - -function getAccountids($link, $user_id) -{ - $sql = " - SELECT - accountid - FROM account - WHERE 1 = 1 - AND (accountid = '$user_id' - OR accountid IN ( - SELECT - accountid - FROM account - WHERE 1 = 1 - AND manager = '$user_id' - AND accounttype IN ('B','E','M','W') - ) - ) - "; - $result = mysqli_query($link, $sql); - $data = []; - foreach ($result as $row) { - array_push($data, $row['accountid']); - } - return "'" . implode("','", $data) . "'"; -} - -function checkArCheckBillStatus($row) -{ - $CU_EstPayDate = $row['CU_EstPayDate']; - $BillNo2 = $row['BillNo2']; - if (substr($CU_EstPayDate, 0, 6) <= date("Ym")) { - if (empty($BillNo2)) { - return "未轉應收確認單"; - } else { - return "已轉應收確認單"; - } - } else { - return "時間未到"; - } -} - -function arSellInvoiceMaterial($row) -{ - - $CU_EstPayDate = $row['CU_EstPayDate']; - $InvoiceName = $row['InvoiceName']; - - if (substr($CU_EstPayDate, 0, 6) <= date("Ym")) { - if (empty($InvoiceName)) { - return "未開發票"; - } else { - return "已開發票"; - } - } else { - return "時間未到"; - } -} - -function checkArWriteOffBill($conn, $row) -{ - $BillNo = $row['BillNo2']; - - $sql = " - SELECT - * - -- a.BillNo, - -- a.WriteOffBizPartnerId, - -- a.PayWriteOffOAmount, - -- b.FromBillDate AS ReceivedDate, - -- b.CurrWOFeeOAmt AS Fee, - -- c.OrderBillNo, - -- c.checkBillNo, - -- c.InvoiceNo, - -- c.BillDate AS CheckBillDate - FROM arWriteOffBill AS a - LEFT JOIN arWriteOffBillRec AS b ON a.BillNo=b.BillNo - LEFT JOIN - (SELECT temp1.*,arWriteOffBillDetail.* FROM arWriteOffBillDetail - LEFT JOIN - (SELECT - arCheckBill.BillNo AS checkBillNo, arCheckBill.BillDate,arCheckBillInvInfo.InvoiceNo - FROM arCheckBill - LEFT JOIN arCheckBillInvInfo - ON arCheckBill.InvoiceBillNo=arCheckBillInvInfo.InvoiceBillNo) AS temp1 - ON temp1.checkBillNo = arWriteOffBillDetail.FromBillNo) AS c - ON a.BillNo=c.BillNo - WHERE c.checkBillNo = '$BillNo' - "; - - $del = $conn->query($sql); - $i = 0; - foreach ($del as $row) - $i++; - if (empty($i)) { - return "未收款"; - } else { - return "已收款"; - } -} - -?> - - - - - - - - -
-
- - - - - - - - - - - - - -
-

保養合約-應收款項明細

-
合約號 - - - -
-
-
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
營業人員/契約人員合約號標示號電梯編號預計請款日催收次數應收申請單狀態請款金額(未轉應收)請款金額(已轉應收)應收申請單號發票狀態發票單標示號發票單號發票明細發票金額發票號碼核銷
- "; - echo getSalesmanName($link, $row['BillNo']); - ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- -There is no record!"; -endif; - -#代表結束連線 -mysqli_close($link); - -include "footer.php"; -?> \ No newline at end of file diff --git a/wms/bonus/api/get.php b/wms/bonus/api/get.php new file mode 100644 index 00000000..6b391c62 --- /dev/null +++ b/wms/bonus/api/get.php @@ -0,0 +1,87 @@ + +prepare($sql); + $stmt->execute(); + $data = $stmt->fetch(PDO::FETCH_ASSOC); + // $data['amount'] = intval($data['amount']); + if (!empty($data['CBno']) && $data['CBno'] != '') { + $checkBillNo = $data['CBno']; + + $sql = "SELECT + c.BillDate AS CheckBillDate + FROM arWriteOffBill AS a + LEFT JOIN arWriteOffBillRec AS b ON a.BillNo=b.BillNo + LEFT JOIN + (SELECT temp1.*,arWriteOffBillDetail.* FROM arWriteOffBillDetail + LEFT JOIN + (SELECT + arCheckBill.BillNo AS checkBillNo, arCheckBill.BillDate,arCheckBillInvInfo.InvoiceNo + FROM arCheckBill + LEFT JOIN arCheckBillInvInfo + ON arCheckBill.InvoiceBillNo=arCheckBillInvInfo.InvoiceBillNo) AS temp1 + ON temp1.checkBillNo = arWriteOffBillDetail.FromBillNo) AS c + ON a.BillNo=c.BillNo + WHERE c.checkBillNo = '$checkBillNo' + "; + + $stmt = $connT8->prepare($sql); + $stmt->execute(); + $check = $stmt->fetch(PDO::FETCH_ASSOC); + + + + // $CU_MaterialId = $data['facility']; + // $sql = "SELECT SQuantity FROM salIncomeApplyDetail WHERE BillNo = :contract_no AND CU_MaterialId = :CU_MaterialId"; + // $stmt = $connT8->prepare($sql); + // $stmt->bindParam(':contract_no', $contract_no); + // $stmt->bindParam(':CU_MaterialId', $CU_MaterialId); + // $stmt->execute(); + // $result = $stmt->fetchAll(PDO::FETCH_ASSOC); + // $count = COUNT($result); + // $data['maintain_month'] = intval($count * $result[0]['SQuantity']); + $reult = true; + echo '1'; + // return true; + } else { + $result = false; + echo '2'; + // return false; + } + } catch (PDOException $e) { + echo '111'; + return false; + // exit; + } + // if (($check['CheckBillDate']) !== '') { + // header('Content-Type: application/json'); + // echo $check['CheckBillDate']; + // } else { + // echo false; + // exit; + // } +} else { + exit(); +} diff --git a/wms/bonus/api/getAccount.php b/wms/bonus/api/getAccount.php new file mode 100644 index 00000000..e60e2626 --- /dev/null +++ b/wms/bonus/api/getAccount.php @@ -0,0 +1,11 @@ +prepare($sql); +$stmt->bindParam(':accountid', $accountid); +$stmt->execute(); +$result = $stmt->fetch(PDO::FETCH_ASSOC); + +header('Content-Type: application/json'); +echo json_encode($result); diff --git a/wms/bonus/api/postCalBouns.php b/wms/bonus/api/postCalBouns.php new file mode 100644 index 00000000..8a8f0a54 --- /dev/null +++ b/wms/bonus/api/postCalBouns.php @@ -0,0 +1,111 @@ + 0) { + header("HTTP/1.1 422 Unprocessable Entity"); + echo json_encode($fail_arr); + exit(); + } + + + + // 合約類型 + $clientType = [ + '1' => 'new', + '2' => 'free_to_charge', + '3' => 'renew_priceissue' + ]; + + // 分期方式 + $paykind = [ + '1' => 'monthly', + '2' => 'bimonthly', + '3' => 'quarterly', + '6' => 'semiannually', + '12' => 'annually' + ]; + + // 應付日期 + $day = DateTime::createFromFormat('Ymd', $payDay); + $pay_day = $day->format('Y-m-d'); + + $years = $maintain_month / 12; + $contract_years = ($years >= 2) ? 'above_two' : 'one'; + + + if ($checkbox == 13) { + // 保養獎金計算 + $results = maintenance_contract_bonus_v2_1( + $bonuns_verson, + $clientType[$client_type], + $paykind[$pay_kind], + $maintain_price_month, + $maintain_price_total, + $commission_fee, + $pay_day, + $receiver, + $manager, + $contract_manger + ); + if ($results['result_status'] != 'error') { + array_push($bonus_json, [ + 'maintain_type' => $maintain_type, + 'total' => $maintain_price_month, + 'fee_per_st' => $maintain_price_total, + 'commission_fee' => $commission_fee, + 'paykind' => $paykind[$pay_kind], + 'receivable_date_due' => $pay_day, + ]); + } + if (!empty($_POST['status']) && $_POST['status'] == 'save') { + foreach ($results['bonus_array'] as $i => $result) { + // echo '
';
+                // print_r($result);
+                // echo '
'; + $bonus_type = $result['bonus_type']; + $pay_day = $result['pay_day_due']; + $amount = $result['bonus_amount']; + $receiver = $result['bonus_receiver']; + $discount = $result['discount']; + foreach ($bonus_json as $json) { + $json['discount'] = "$discount"; + $a = json_encode($json); + } + echo '
';
+                print_r($a);
+                echo '
'; + // exit(); + // $sql = "INSERT INTO bonus + // (bonus_type,bonus_verson,contract_no,contract_type,facility_no,amount,receiver,pay_day,status,bonus_json,create_id,create_at) VALUES + // ($bonus_type,'$bonus_verson','$contract_no',$contract_type,'$facility_no',$amount,'$receiver','$pay_day',$status,'$a','$create_id','$create_at')"; + // $stmt = $conn->prepare($sql); + // $stmt->execute(); + // $count++; + // echo '
';
+                // print_r($count . '-- > Success');
+                // echo '
'; + + // exit; + } + } else { + header('Content-Type: application/json'); + echo json_encode($results); + } + } +} diff --git a/wms/bonus/api/updateBonus.php b/wms/bonus/api/updateBonus.php new file mode 100644 index 00000000..2748a91d --- /dev/null +++ b/wms/bonus/api/updateBonus.php @@ -0,0 +1,27 @@ +;prepare($sql); + $stmt->bindParam(':bonus_type', $bonus_type); + $stmt->bindParam(':bonus_verson', $bonus_verson); + $stmt->bindParam('conreact_no', $contract_no); + $stmt->bindParam(':contract_type', $contract_type); + } + } diff --git a/wms/bonus/bonus.php b/wms/bonus/bonus.php new file mode 100644 index 00000000..eb1959a2 --- /dev/null +++ b/wms/bonus/bonus.php @@ -0,0 +1,301 @@ + '新梯', + '2' => '汰改', + '3' => '保養' +]; + +$bonus_type = [ + '1' => '契約人獎金', + '2' => '區經理獎金', + '3' => '專任契約經理獎金' +]; +$clause = ''; +if (!empty($_GET['check'])) { + if ($_GET['check'] == 1) { + $clause .= "AND pay_day > DATE_SUB(NOW(), INTERVAL 1 MONTH)"; + } else if ($_GET['check'] == 2) { + $clause .= "AND status = 1"; + } else if ($_GET['check'] == 3) { + $clause .= "AND status = 2"; + } +} + +$sql = "SELECT * FROM bonus WHERE 1=1 $clause LIMIT 50"; +$stmt = $conn->prepare($sql); +$stmt->execute(); +$datas = $stmt->fetchAll(PDO::FETCH_ASSOC); + + +$now = new DateTime(); +$oneMonthAgo = $now->modify('+1 month'); + +// 查看 T8 是否有收款明細 +// require("./api/get.php"); +function isPay($contract_no, $connT8) +{ + // echo $contract_no; + $sql = "SELECT + a.BillNo, + b.OTaxAmt as amount, + a.CU_EstPayDate as createDate, + b.PersonId as personId, + c.BillNo as CBno, + c.CU_MaterialId as facility + FROM salIncomeApplyDetail as a + LEFT JOIN salIncomeApplyMaster as b ON a.BillNo = b.BillNo + LEFT JOIN ( + SELECT aMaster.BillNo,aMaster.BizPartnerId,aDetail.CU_MaterialId FROM arCheckBill as aMaster + LEFT JOIN arCheckBillDetail as aDetail ON aMaster.BizPartnerId = aDetail.FromBillNo + WHERE aMaster.BizPartnerId = '$contract_no' AND aMaster.TypeId = 'RVS' + ) AS c ON a.BillNo = c.BizPartnerId + WHERE a.BillNo = '$contract_no' + AND a.RowNo = '1' + "; + $stmt = $connT8->prepare($sql); + $stmt->execute(); + $data = $stmt->fetch(PDO::FETCH_ASSOC); + // $data['amount'] = intval($data['amount']); + if (!empty($data['CBno']) && $data['CBno'] != '') { + $checkBillNo = $data['CBno']; + + $sql = "SELECT + c.BillDate AS CheckBillDate + FROM arWriteOffBill AS a + LEFT JOIN arWriteOffBillRec AS b ON a.BillNo=b.BillNo + LEFT JOIN + (SELECT temp1.*,arWriteOffBillDetail.* FROM arWriteOffBillDetail + LEFT JOIN + (SELECT + arCheckBill.BillNo AS checkBillNo, arCheckBill.BillDate,arCheckBillInvInfo.InvoiceNo + FROM arCheckBill + LEFT JOIN arCheckBillInvInfo + ON arCheckBill.InvoiceBillNo=arCheckBillInvInfo.InvoiceBillNo) AS temp1 + ON temp1.checkBillNo = arWriteOffBillDetail.FromBillNo) AS c + ON a.BillNo=c.BillNo + WHERE c.checkBillNo = '$checkBillNo' + "; + + $stmt = $connT8->prepare($sql); + $stmt->execute(); + + return '1'; + } else { + return '2'; + } +} +?> + + + + + + + + +
+ + +
+ + + + btn-sm categoryBtn"> 所有獎金 + btn-sm categoryBtn"> 應發獎金 + btn-sm categoryBtn"> 未發獎金 + btn-sm categoryBtn"> 已發獎金 + + + + + + + + + + + + + + + + + + + + + + + $data) : + + $contract_no = $data['contract_no']; + $json = json_decode($data['bonus_json']); + + $total = empty($json->total) ? 0 : $json->total; + $fee_per_st = empty($json->fee_per_st) ? 0 : $json->fee_per_st; + $commission_fee = empty($json->commission_fee) ? 0 : $json->commission_fee; + $isPay = isPay($data['contract_no'], $connT8); + + ?> + + + + + + + + + + + + + + + + + + + + +
項次合約類別合約號作番號獎金類別獎金版本作番總價牌價服務費應發人員預計發放時間獎金水庫狀態檢視/發放
+ + + + + 發放獎金 + + 查看詳情 + +
+
+
+ + + + \ No newline at end of file diff --git a/wms/bons/bons_index.php b/wms/bonus/bonus_detail.php similarity index 56% rename from wms/bons/bons_index.php rename to wms/bonus/bonus_detail.php index 0ee7058a..93762ac3 100644 --- a/wms/bons/bons_index.php +++ b/wms/bonus/bonus_detail.php @@ -1,6 +1,30 @@ prepare($sql); +$stmt->bindParam(':id', $_GET['id']); +$stmt->execute(); +$result = $stmt->fetch(PDO::FETCH_ASSOC); +// echo '
';
+// print_r($result['bonus_json']);
+// echo '
'; +$bonus_json = json_decode($result['bonus_json']); + +$paykind = [ + 'monthly' => '月繳', + 'bimonthly' => '雙月繳', + 'quarterly' => '季繳', + 'semiannually' => '半年繳', + 'annually' => '年繳' +]; + +$maintain_type = [ + 'new' => '新簽約', + 'free_to_charge' => '免保轉有費', + 'renew_priceissue' => '續簽約' +]; ?> @@ -12,7 +36,7 @@ require_once('../contract-repair/conn.php'); -
+
@@ -24,7 +48,7 @@ require_once('../contract-repair/conn.php'); -