From 2e5fe5427d6db393e0495598ff43d90a052f4791 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 28 四月 2024 14:06:42 +0800
Subject: [PATCH] 2024-04-28

---
 src/tabviews/custom/components/module/invoice/index.jsx |   65 ++++++++++++++++++++++++++------
 1 files changed, 53 insertions(+), 12 deletions(-)

diff --git a/src/tabviews/custom/components/module/invoice/index.jsx b/src/tabviews/custom/components/module/invoice/index.jsx
index 17eda8d..e0ca568 100644
--- a/src/tabviews/custom/components/module/invoice/index.jsx
+++ b/src/tabviews/custom/components/module/invoice/index.jsx
@@ -20,6 +20,8 @@
 
   state = {
     BID: '',
+    ID: Utils.getuuid(),
+    io: '',
     invTypes: [
       {value: '1', label: '鐢靛瓙鍙戠エ锛堝鍊肩◣涓撶敤鍙戠エ锛�'},
       {value: '2', label: '鐢靛瓙鍙戠エ锛堟櫘閫氬彂绁級'},
@@ -50,6 +52,7 @@
     reviewer: '',
     drawer: '',
     details: [],
+    oriDetails: [],
     book: null,
     loading: false,
     saveType: '',
@@ -146,7 +149,7 @@
           cell.field = 'tax_rate'
           cell.label = '绋庣巼'
         }
-        if (['Description', 'id', 'small_tax_rate'].includes(cell.field)) {
+        if (['Description', 'id', 'small_tax_rate', 'free_tax_mark', 'vat_special_management'].includes(cell.field)) {
           cell.Hide = 'true'
         } else if (['spec'].includes(cell.field)) {
           cell.Width = 150
@@ -292,6 +295,10 @@
     if (result.status) {
 
       this.setState({
+        ID: result.data[0][config.setting.primaryKey] || Utils.getuuid(),
+        io: '',
+        details: [],
+        oriDetails: [],
         loading: false
       })
 
@@ -357,7 +364,7 @@
   }
 
   saveBill = () => {
-    const { config, saveType } = this.state
+    const { config, book, saveType } = this.state
 
     if (saveType) return
 
@@ -370,6 +377,7 @@
           LText: sql,
           exec_type: window.GLOB.execType || 'y',
           timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
+          BID: book.id
         }
   
         param.secretkey = Utils.encrypt('', param.timestamp)
@@ -409,7 +417,7 @@
   }
 
   outBill = () => {
-    const { config, saveType } = this.state
+    const { config, book, saveType } = this.state
 
     if (saveType) return
 
@@ -419,11 +427,11 @@
   
         let param = {
           func: 'sPC_TableData_InUpDe',
-          // BID: BID || '',
           LText: sql,
           key_back_type: 'Y',
           exec_type: window.GLOB.execType || 'y',
           timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
+          BID: book.id
         }
   
         param.secretkey = Utils.encrypt('', param.timestamp)
@@ -442,8 +450,9 @@
   }
 
   getPreSql = (btn) => {
-    const { book, details, invoice_type, from_to_name, from_to_tax_no, from_to_addr, from_to_tel, from_to_bank_name, from_to_account_no, from_to_mob, from_to_email, from_to_code, orgname, tax_no, addr, tel, bank_name, account_no, remark, reviewer, drawer, payee } = this.state
+    const { book, ID, io, details, oriDetails, invoice_type, from_to_name, from_to_tax_no, from_to_addr, from_to_tel, from_to_bank_name, from_to_account_no, from_to_mob, from_to_email, from_to_code, orgname, tax_no, addr, tel, bank_name, account_no, remark, reviewer, drawer, payee } = this.state
 
+    let BID = book.id
     let userName = sessionStorage.getItem('User_Name') || '' 
     let fullName = sessionStorage.getItem('Full_Name') || ''
     let RoleID = sessionStorage.getItem('role_id') || ''
@@ -455,8 +464,40 @@
     let city = sessionStorage.getItem('city') || ''
     let district = sessionStorage.getItem('district') || ''
     let address = sessionStorage.getItem('address') || ''
+    let options = fromJS(oriDetails).toJS()
+    let price = 0
+    let tax = 0
 
-    let lines = details.map(line => `Select '${line.productcode}', '${line.productname}', '${line.spec}', '${line.unit}', ${line.bill_count}, ${line.unitprice}, ${line.amount_line}, '${line.tax_classify_code}', '${line.tax_classify_name}', ${line.tax_rate}, ${line.tax_amount}`)
+    let lines = details.map(line => {
+      let _sql = `Select '${line.productcode}', '${line.productname}', '${line.spec}', '${line.unit}', ${line.bill_count}, ${line.unitprice}, ${line.amount_line}, '${line.tax_classify_code}', '${line.tax_classify_name}', ${line.tax_rate}, ${line.tax_amount}, '${line.invoice_lp || ''}', '${line.uuid}'`
+      let data_type = 'add'
+
+      price += line.amount_line * 100
+      tax += line.tax_amount * 100
+
+      if (options.length) {
+        options = options.filter(option => {
+          if (option.uuid === line.uuid) {
+            data_type = 'upt'
+            return false
+          }
+          return true
+        })
+      }
+
+      return _sql + `, '${data_type}'`
+    })
+
+    let _total = (price - tax) / 100
+    price = price / 100
+    tax = tax / 100
+
+    if (options.length) {
+      options.forEach(line => {
+        lines.push(`Select '${line.productcode}', '${line.productname}', '${line.spec}', '${line.unit}', ${line.bill_count}, ${line.unitprice}, ${line.amount_line}, '${line.tax_classify_code}', '${line.tax_classify_name}', ${line.tax_rate}, ${line.tax_amount}, '${line.invoice_lp || ''}', '${line.uuid}', 'del'`)
+      })
+    }
+
     lines = lines.join(' union all ')
 
     let _script = ''
@@ -473,15 +514,15 @@
       Select @UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_organization='${organization}', @mk_user_type='${mk_user_type}', @mk_nation='${nation}', @mk_province='${province}', @mk_city='${city}', @mk_district='${district}', @mk_address='${address}', @ErrorCode='', @retmsg='', @account_id='${book.account_id || ''}', @account_year_id='${book.account_year_id || ''}', @account_code='${book.account_code || ''}', @account_year_code='${book.account_year_code || ''}', @bid=''
 
       /* 鍙戠エ涓昏〃瀛楁 */
-      Declare @invoice_type Nvarchar(50), @from_to_name Nvarchar(50), @from_to_tax_no Nvarchar(50), @from_to_addr Nvarchar(100), @from_to_tel Nvarchar(50), @from_to_bank_name Nvarchar(50), @from_to_account_no Nvarchar(50), @from_to_mob Nvarchar(50), @from_to_email Nvarchar(50), @from_to_code Nvarchar(50), @orgname Nvarchar(50), @tax_no Nvarchar(50), @addr Nvarchar(100), @tel Nvarchar(50), @bank_name Nvarchar(50), @account_no Nvarchar(50), @remark Nvarchar(512), @payee Nvarchar(50), @reviewer Nvarchar(50), @drawer Nvarchar(50)
+      Declare @invoice_type Nvarchar(50), @from_to_name Nvarchar(50), @from_to_tax_no Nvarchar(50), @from_to_addr Nvarchar(100), @from_to_tel Nvarchar(50), @from_to_bank_name Nvarchar(50), @from_to_account_no Nvarchar(50), @from_to_mob Nvarchar(50), @from_to_email Nvarchar(50), @from_to_code Nvarchar(50), @orgname Nvarchar(50), @tax_no Nvarchar(50), @addr Nvarchar(100), @tel Nvarchar(50), @bank_name Nvarchar(50), @account_no Nvarchar(50), @remark Nvarchar(512), @payee Nvarchar(50), @reviewer Nvarchar(50), @drawer Nvarchar(50), @io Nvarchar(50), @orgcode Nvarchar(50), @total_net_amount Decimal(18,2), @total_tax Decimal(18,2), @total_amount Decimal(18,2)
 
-      Select @invoice_type='${invoice_type}', @from_to_name='${from_to_name}', @from_to_tax_no='${from_to_tax_no}', @from_to_addr='${from_to_addr}', @from_to_tel='${from_to_tel}', @from_to_bank_name='${from_to_bank_name}', @from_to_account_no='${from_to_account_no}', @from_to_mob='${from_to_mob}', @from_to_email='${from_to_email}', @from_to_code='${from_to_code}', @orgname='${orgname}', @tax_no='${tax_no}', @addr='${addr}', @tel='${tel}', @bank_name='${bank_name}', @account_no='${account_no}', @remark='${remark}', @payee='${payee}', @reviewer='${reviewer}', @drawer='${drawer}'
+      Select @invoice_type='${invoice_type}', @from_to_name='${from_to_name}', @from_to_tax_no='${from_to_tax_no}', @from_to_addr='${from_to_addr}', @from_to_tel='${from_to_tel}', @from_to_bank_name='${from_to_bank_name}', @from_to_account_no='${from_to_account_no}', @from_to_mob='${from_to_mob}', @from_to_email='${from_to_email}', @from_to_code='${from_to_code}', @orgname='${orgname}', @tax_no='${tax_no}', @addr='${addr}', @tel='${tel}', @bank_name='${bank_name}', @account_no='${account_no}', @remark='${remark}', @payee='${payee}', @reviewer='${reviewer}', @drawer='${drawer}', @io='${io}', @orgcode='${book.orgcode || ''}', @total_net_amount=${_total}, @total_tax=${tax}, @total_amount=${price}
 
       /* 鍙戠エ鏄庣粏涓存椂琛� */
 
-      Declare @details_list table (productcode Nvarchar(50), productname Nvarchar(50), spec Nvarchar(50), unit Nvarchar(50), bill_count Decimal(18,10), unitprice Decimal(18,10), amount_line Decimal(18,2), tax_classify_code Nvarchar(50), tax_classify_name Nvarchar(50), tax_rate Decimal(18,2), tax_amount Decimal(18,2))
+      Declare @details_list table (productcode Nvarchar(50), productname Nvarchar(50), spec Nvarchar(50), unit Nvarchar(50), bill_count Decimal(18,10), unitprice Decimal(18,10), amount_line Decimal(18,2), tax_classify_code Nvarchar(50), tax_classify_name Nvarchar(50), tax_rate Decimal(18,2), tax_amount Decimal(18,2), invoice_lp Nvarchar(50), jskey Nvarchar(50), data_type Nvarchar(50))
 
-      Insert into @details_list (productcode, productname, spec, unit, bill_count, unitprice, amount_line, tax_classify_code, tax_classify_name, tax_rate, tax_amount)
+      Insert into @details_list (productcode, productname, spec, unit, bill_count, unitprice, amount_line, tax_classify_code, tax_classify_name, tax_rate, tax_amount, invoice_lp, jskey, data_type)
 
       ${lines}
 
@@ -490,8 +531,8 @@
 
       aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg`
 
-    sql = sql.replace(/@ID@/ig, `''`)
-    sql = sql.replace(/@BID@/ig, `''`)
+    sql = sql.replace(/@ID@/ig, `'${ID}'`)
+    sql = sql.replace(/@BID@/ig, `'${BID}'`)
     sql = sql.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
     sql = sql.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
     sql = sql.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)

--
Gitblit v1.8.0