From e1cee96b38805bcccf48e7bcb9d296f2bc54c720 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 24 一月 2025 11:10:32 +0800
Subject: [PATCH] 2025-01-24

---
 src/tabviews/custom/components/module/invoice/index.jsx |  929 +++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 724 insertions(+), 205 deletions(-)

diff --git a/src/tabviews/custom/components/module/invoice/index.jsx b/src/tabviews/custom/components/module/invoice/index.jsx
index def7f66..5f130b2 100644
--- a/src/tabviews/custom/components/module/invoice/index.jsx
+++ b/src/tabviews/custom/components/module/invoice/index.jsx
@@ -14,8 +14,6 @@
 import SubTable from './subTable'
 import './index.scss'
 
-const { confirm } = Modal
-
 class InvoiceModule extends Component {
   static propTpyes = {
     config: PropTypes.object
@@ -56,7 +54,12 @@
     tax_type: '',
     reqfields: [],
     requireds: [],
-    timestamp: new Date().getTime() + ''
+    invoice_no: '',
+    invoice_code: '',
+    invoice_date: '',
+    read_only: false,
+    invoice_type_name: '',
+    timestamp: ''
   }
 
   UNSAFE_componentWillMount () {
@@ -81,6 +84,13 @@
 
     _config.buyer = this.formatSetting(_config.buyer, 'buyer')
     _config.detail = this.formatSetting(_config.detail, 'detail')
+    _config.detail.uuid = _config.uuid
+    _config.buyer.setting.uuid = _config.uuid + 'buyer'
+    _config.detail.setting.uuid = _config.uuid + 'detail'
+    _config.billOutBtn.uuid = _config.uuid
+    _config.billSaveBtn.uuid = _config.uuid
+    _config.billOutBtn.logLabel = _config.$menuname + '-' + _config.billOutBtn.label
+    _config.billSaveBtn.logLabel = _config.$menuname + '-' + _config.billSaveBtn.label
 
     let book = null
     let pas = {}
@@ -145,6 +155,8 @@
           cell.Hide = 'true'
         } else if (['from_to_email', 'from_to_mob'].includes(cell.field)) {
           cell.Width = 80
+        } else if (['from_to_name'].includes(cell.field)) {
+          cell.Width = 140
         }
         return cell
       })
@@ -154,7 +166,7 @@
           cell.field = 'tax_rate'
           cell.label = '绋庣巼'
         }
-        if (['Description', 'id', 'small_tax_rate', 'free_tax_mark', 'vat_special_management'].includes(cell.field)) {
+        if (['Description', 'id', 'small_tax_rate', 'free_tax_mark', 'vat_special_management', 'tax_item', 'tax_method'].includes(cell.field)) {
           cell.Hide = 'true'
         } else if (['spec'].includes(cell.field)) {
           cell.Width = 150
@@ -227,7 +239,7 @@
     item.setting.customScript = _customScript // 鏁寸悊鍚庤嚜瀹氫箟鑴氭湰
     item.setting.tailScript = _tailScript     // 鍚庣疆鑷畾涔夎剼鏈�
 
-    item.setting.custompage = /@pageSize@|@orderBy@/i.test(item.setting.dataresource + item.setting.customScript)
+    item.setting.custompage = /@pageSize@|@orderBy@|@mk_total/i.test(item.setting.dataresource + item.setting.customScript)
 
     return item
   }
@@ -340,6 +352,17 @@
         }
       })
 
+      let invoice_type_name = ''
+      if (line.read_only === 'true') {
+        let types = book.invoice_type || []
+        types.forEach(item => {
+          if (item.value === line.invoice_type) {
+            invoice_type_name = item.label
+          }
+        })
+        invoice_type_name = invoice_type_name || line.invoice_type
+      }
+
       this.setState({
         ID: line[config.setting.primaryKey] || Utils.getguid(),
         io: line.io,
@@ -365,6 +388,11 @@
         reviewer: line.reviewer,
         drawer: line.drawer,
         details: details,
+        invoice_no: line.invoice_no,
+        invoice_code: line.invoice_code,
+        invoice_date: line.read_only === 'true' ? line.invoice_date : '',
+        read_only: line.read_only === 'true',
+        invoice_type_name: invoice_type_name,
         oriDetails: fromJS(details).toJS(),
         timestamp: new Date().getTime() + '',
         loading: false
@@ -384,25 +412,22 @@
   }
 
   clearData = () => {
-    const { from_to_tax_no, oriDetails, details } = this.state
-
-    if (from_to_tax_no || oriDetails.length || details.length) {
-      this.setState({
-        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: '',
-        business_type: '',
-        details: [],
-        oriDetails: [],
-        timestamp: new Date().getTime() + '',
-      })
-    }
+    this.setState({
+      ID: Utils.getguid(),
+      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: '',
+      business_type: '',
+      details: [],
+      oriDetails: [],
+      timestamp: new Date().getTime() + '',
+    })
   }
 
   changeType = (val) => {
@@ -468,18 +493,23 @@
 
     setTimeout(() => {
       this.getBillMsg().then(() => {
-        let sql = this.getPreSql(config.billSaveBtn)
-  
-        let param = {
-          func: 'sPC_TableData_InUpDe',
-          LText: sql,
-          exec_type: window.GLOB.execType || 'y',
-          timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
-          BID: BID
+        let param = null
+        if (window.backend && window.GLOB.CacheData.has('sql_' + config.uuid + config.billSaveBtn.type)) {
+          param = this.getBackPreParam(config.billSaveBtn)
+        } else {
+          let sql = this.getPreSql(config.billSaveBtn)
+    
+          param = {
+            func: 'sPC_TableData_InUpDe',
+            LText: sql,
+            exec_type: window.GLOB.execType || 'y',
+            timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
+            BID: BID
+          }
+    
+          param.secretkey = Utils.encrypt('', param.timestamp)
+          param.LText = Utils.formatOptions(param.LText, param.exec_type)
         }
-  
-        param.secretkey = Utils.encrypt('', param.timestamp)
-        param.LText = Utils.formatOptions(param.LText, param.exec_type)
 
         this.setState({
           saveType: 'bill'
@@ -490,30 +520,16 @@
             saveType: ''
           })
           if (res.status) {
-            const that = this
-
-            confirm({
-              title: '淇濆瓨鎴愬姛銆�',
-              okText: '缁х画濉紑',
-              cancelText: '鍏抽棴',
-              onOk() {
-                if (config.billSaveBtn.reTabId) {
-                  MKEmitter.emit('reloadMenuView', config.billSaveBtn.reTabId, 'table')
-                }
-                if (config.billSaveBtn.syncComId) {
-                  MKEmitter.emit('reloadData', config.billSaveBtn.syncComId)
-                }
-                that.clearData()
-              },
-              onCancel() {
-                if (config.billSaveBtn.reTabId) {
-                  MKEmitter.emit('reloadMenuView', config.billSaveBtn.reTabId, 'table')
-                }
-                if (config.billSaveBtn.syncComId) {
-                  MKEmitter.emit('reloadData', config.billSaveBtn.syncComId)
-                }
-                MKEmitter.emit('closeTabView', config.$pageId)
-              }
+            if (config.billSaveBtn.reTabId) {
+              MKEmitter.emit('reloadMenuView', config.billSaveBtn.reTabId)
+            }
+            if (config.billSaveBtn.syncComId) {
+              MKEmitter.emit('reloadData', config.billSaveBtn.syncComId)
+            }
+            notification.success({
+              top: 92,
+              message: '淇濆瓨鎴愬姛銆�',
+              duration: 5
             })
           } else {
             notification.warning({
@@ -536,6 +552,22 @@
   outBill = () => {
     const { config, BID, saveType } = this.state
 
+    if (window.GLOB.storeFiles) {
+      if (!window.GLOB.storeDate || window.GLOB.storeDate < 0) {
+        Modal.warning({
+          title: `鐢靛瓙妗f瀛樺偍鍖呭凡杩囨湡銆俙,
+          okText: '鐭ラ亾浜�'
+        })
+        return
+      } else if (window.GLOB.storeDate < 30) {
+        notification.warning({
+          top: 92,
+          message: `鐢靛瓙妗f瀛樺偍鍖呰繕鍓�${window.GLOB.storeDate}澶┿�俙,
+          duration: 5
+        })
+      }
+    }
+
     if (window.GLOB.systemType === 'production' && !config.billOutBtn.proInterface) {
       notification.warning({
         top: 92,
@@ -549,19 +581,24 @@
 
     setTimeout(() => {
       this.getBillMsg().then(() => {
-        let sql = this.getPreSql(config.billOutBtn)
-  
-        let param = {
-          func: 'sPC_TableData_InUpDe',
-          LText: sql,
-          script_type: 'Y',
-          exec_type: window.GLOB.execType || 'y',
-          timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
-          BID: BID
+        let param = null
+        if (window.backend && window.GLOB.CacheData.has('sql_' + config.uuid + config.billOutBtn.type)) {
+          param = this.getBackPreParam(config.billOutBtn)
+        } else {
+          let sql = this.getPreSql(config.billOutBtn)
+    
+          param = {
+            func: 'sPC_TableData_InUpDe',
+            LText: sql,
+            script_type: 'Y',
+            exec_type: window.GLOB.execType || 'y',
+            timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
+            BID: BID
+          }
+    
+          param.secretkey = Utils.encrypt('', param.timestamp)
+          param.LText = Utils.formatOptions(param.LText, param.exec_type)
         }
-  
-        param.secretkey = Utils.encrypt('', param.timestamp)
-        param.LText = Utils.formatOptions(param.LText, param.exec_type)
 
         this.setState({
           saveType: 'out'
@@ -693,6 +730,7 @@
     sql = sql.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
     sql = sql.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
     sql = sql.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
+    sql = sql.replace(/@lang@/ig, `'${sessionStorage.getItem('lang')}'`)
     sql = sql.replace(/@typename@/ig, `'admin'`)
 
     if (window.GLOB.externalDatabase !== null) {
@@ -706,10 +744,202 @@
     }
 
     if (window.GLOB.debugger === true) {
-      console.info(sql.replace(/\n\s{6}/ig, '\n'))
+      window.mkInfo(sql.replace(/\n\s{6}/ig, '\n'))
     }
 
     return sql
+  }
+
+  getBackPreParam = (btn) => {
+    const { config, book, ID, BID, io, details, oriDetails, business_type, 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 ex = window.GLOB.CacheData.get('sql_' + btn.uuid + btn.type)
+    let exps = []
+
+    let values = {
+      time_id: Utils.getguid(),
+      roleid: sessionStorage.getItem('role_id') || '',
+      mk_departmentcode: sessionStorage.getItem('departmentcode') || '',
+      mk_organization: sessionStorage.getItem('organization') || '',
+      mk_user_type: sessionStorage.getItem('mk_user_type') || '',
+      mk_nation: sessionStorage.getItem('nation') || '',
+      mk_province: sessionStorage.getItem('province') || '',
+      mk_city: sessionStorage.getItem('city') || '',
+      mk_district: sessionStorage.getItem('district') || '',
+      mk_address: sessionStorage.getItem('address') || '',
+      id: ID || '',
+      bid: BID || '',
+      datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+      datam_begin: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+      datam_end: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+    }
+
+    if (window.GLOB.externalDatabase !== null) {
+      values.db = window.GLOB.externalDatabase
+    }
+
+    let options = fromJS(oriDetails).toJS()
+    let price = 0
+    let tax = 0
+
+    let lines = []
+    details.forEach(line => {
+      if (!line.productcode) return
+
+      let vals = [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.free_tax_mark || '', line.vat_special_management || '', line.invoice_lp || '', line.tax_item, line.tax_method, 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
+        })
+      }
+
+      vals.push(data_type)
+
+      lines.push(vals)
+    })
+
+    let _total = (price - tax) / 100
+    price = price / 100
+    tax = tax / 100
+
+    if (options.length) {
+      options.forEach(line => {
+        let vals = [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.free_tax_mark || '', line.vat_special_management || '', line.invoice_lp || '', line.tax_item, line.tax_method, line.uuid, 'del']
+        lines.push(vals)
+      })
+    }
+
+    ex.reps.forEach(n => {
+      let key = n.toLowerCase()
+      if (values.hasOwnProperty(key)) {
+        exps.push({
+          key: n,
+          value: values[key]
+        })
+      }
+    })
+
+    exps.push({
+      key: 'account_id',
+      value: book.account_id || ''
+    }, {
+      key: 'account_year_id',
+      value: book.account_year_id || ''
+    }, {
+      key: 'account_code',
+      value: book.account_code || ''
+    }, {
+      key: 'account_year_code',
+      value: book.account_year_code || ''
+    }, {
+      key: 'invoice_type',
+      value: invoice_type
+    }, {
+      key: 'from_to_name',
+      value: from_to_name
+    }, {
+      key: 'from_to_tax_no',
+      value: from_to_tax_no
+    }, {
+      key: 'from_to_addr',
+      value: from_to_addr
+    }, {
+      key: 'from_to_tel',
+      value: from_to_tel
+    }, {
+      key: 'from_to_bank_name',
+      value: from_to_bank_name
+    }, {
+      key: 'from_to_account_no',
+      value: from_to_account_no
+    }, {
+      key: 'from_to_mob',
+      value: from_to_mob
+    }, {
+      key: 'from_to_email',
+      value: from_to_email
+    }, {
+      key: 'from_to_code',
+      value: from_to_code
+    }, {
+      key: 'orgname',
+      value: orgname
+    }, {
+      key: 'tax_no',
+      value: tax_no
+    }, {
+      key: 'addr',
+      value: addr
+    }, {
+      key: 'tel',
+      value: tel
+    }, {
+      key: 'bank_name',
+      value: bank_name
+    }, {
+      key: 'account_no',
+      value: account_no
+    }, {
+      key: 'remark',
+      value: remark
+    }, {
+      key: 'payee',
+      value: payee
+    }, {
+      key: 'reviewer',
+      value: reviewer
+    }, {
+      key: 'drawer',
+      value: drawer
+    }, {
+      key: 'io',
+      value: io
+    }, {
+      key: 'orgcode',
+      value: book.orgcode || ''
+    }, {
+      key: 'total_net_amount',
+      value: _total
+    }, {
+      key: 'total_tax',
+      value: tax
+    }, {
+      key: 'total_amount',
+      value: price
+    }, {
+      key: 'business_type',
+      value: business_type || config.wrap.business_type || ''
+    })
+
+    exps.push({
+      key: 'mk_excel_data',
+      value: lines
+    })
+
+    let md5_id = ''
+    if (window.GLOB.probation) {
+      md5_id = md5(ex.id + JSON.stringify(exps) + Math.floor(new Date().getTime() / 600000))
+      md5_id = moment().format('YYYYMMDDHHmmss') + md5_id.slice(-18)
+    }
+
+    return {
+      $backend: true,
+      $type: 's_TableData_InUpDe',
+      data: [{
+        id: ex.id,
+        menuname: btn.logLabel || '',
+        exps: exps,
+        md5_id: md5_id
+      }]
+    }
   }
 
   getBillMsg = () => {
@@ -792,11 +1022,18 @@
 
     param.data.invoiceTypeCode = trans[param.data.invoiceTypeCode] || ''
 
+    if (window.GLOB.storeFiles) {
+      param.store = true
+    }
+
     let url = ''
     if (window.GLOB.systemType === 'production') {
       url = config.billOutBtn.proInterface
     } else {
       url = config.billOutBtn.interface
+    }
+    if (!/^http/.test(url)) {
+      url = window.location.origin + url
     }
 
     let _params = {
@@ -815,16 +1052,208 @@
   callBackBill = (result) => {
     const { config, BID, ID } = this.state
 
-    let btn = config.billOutBtn
+    let param = null
+
+    if (window.backend && window.GLOB.CacheData.has('sql_' + config.uuid + 'billback')) {
+      param = this.getCallBackendParam(config.billOutBtn, result)
+    } else {
+      let btn = config.billOutBtn
+      let lines = []
+      let pre = '@'
+  
+      let getDefaultSql = (obj, tb, bid, level) => {
+        let keys = []
+        let vals = []
+        let subObjs = []
+        let id = Utils.getuuid()
+        let tbName = pre + tb
+  
+        delete obj.$$key
+  
+        Object.keys(obj).forEach(key => {
+          let val = obj[key]
+          if (val === null || val === undefined) return
+          if (typeof(val) === 'object') {
+            if (Array.isArray(val)) {
+              val.forEach(item => {
+                if (typeof(item) !== 'object' || Array.isArray(item)) return
+                if (Object.keys(item).length === 0) return
+  
+                Object.keys(item).forEach(k => {
+                  if (item[k] === null) {
+                    item[k] = ''
+                  }
+                })
+                item.$$key = tb + '_' + key
+                subObjs.push(item)
+              })
+            } else if (Object.keys(val).length > 0) {
+              val.$$key = tb + '_' + key
+              subObjs.push(val)
+            }
+          } else {
+            if (typeof(val) === 'string') {
+              val = val.replace(/'/ig, '"')
+            }
+            keys.push('[' + key + ']')
+            vals.push(`'${val}'`)
+          }
+        })
+  
+        keys = keys.join(',')
+        vals = vals.join(',')
+  
+        lines.push({
+          table: md5(tb + keys),
+          insert: `Insert into ${tbName} (${keys ? keys + ',' : ''}[mk_level],[mk_id],[mk_bid])`,
+          select: `Select ${keys ? vals + ',' : ''}'${level}','${id}','${bid}'`
+        })
+  
+        subObjs.forEach(item => {
+          getDefaultSql(item, item.$$key, id, level + 1)
+        })
+      }
+      
+      getDefaultSql(result, btn.cbTable, '', 1)
+  
+      let lineMap = new Map()
+      lines.forEach(line => {
+        if (lineMap.has(line.table)) {
+          let _line = lineMap.get(line.table)
+          _line.selects.push(line.select)
+          lineMap.set(line.table, _line)
+        } else {
+          lineMap.set(line.table, {
+            table: line.table,
+            insert: line.insert,
+            selects: [line.select]
+          })
+        }
+      })
+  
+      param = {
+        func: 'sPC_TableData_InUpDe',
+        BID: BID,
+        menuname: config.name + '(鍥炶皟)'
+      }
+  
+      let callbacksql = this.getBackSql()
+      let _prevCustomScript = `${callbacksql}
+      `
+      let _backCustomScript = ''
+  
+      btn.cbScripts.forEach(script => {
+        if (script.status === 'false') return
+  
+        if (script.position === 'front') {
+          _prevCustomScript += `
+        /* 鑷畾涔夎剼鏈� */
+        ${script.sql}
+        `
+        } else {
+          _backCustomScript += `
+        /* 鑷畾涔夎剼鏈� */
+        ${script.sql}
+        `
+        }
+      })
+  
+      _backCustomScript += `
+        aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg`
+  
+      let sql = [...lineMap.values()].map(item => (`
+        ${item.insert}
+        ${item.selects.join(` union all
+        `)}
+      `))
+      sql = sql.join('')
+      sql = _prevCustomScript + sql
+      sql = sql + _backCustomScript
+  
+      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') || ''}'`)
+      sql = sql.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
+      sql = sql.replace(/@lang@/ig, `'${sessionStorage.getItem('lang')}'`)
+      sql = sql.replace(/@typename@/ig, `'admin'`)
+  
+      if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺
+        sql = sql.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, `'Y'`)
+      } else {
+        sql = sql.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, `''`)
+      }
+  
+      if (window.GLOB.debugger === true) {
+        window.mkInfo('%c' + config.name + '(鍥炶皟)', 'color: blue')
+        window.mkInfo(sql.replace(/\n\s{8}/ig, '\n'))
+      }
+  
+      param.LText = sql
+      param.exec_type = window.GLOB.execType || 'y' // 鍚庡彴瑙g爜
+      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+      param.secretkey = Utils.encrypt('', param.timestamp)
+      param.LText = Utils.formatOptions(param.LText, param.exec_type)
+  
+      if (window.GLOB.probation) {
+        param.s_debug_type = 'Y'
+      }
+    }
+
+    Api.genericInterface(param).then(res => {
+      this.setState({
+        saveType: ''
+      })
+      if (res.status) {
+        if (config.billOutBtn.reTabId) {
+          MKEmitter.emit('reloadMenuView', config.billOutBtn.reTabId)
+        }
+        if (config.billOutBtn.syncComId) {
+          MKEmitter.emit('reloadData', config.billOutBtn.syncComId)
+        }
+        this.clearData()
+
+        notification.success({
+          top: 92,
+          message: '寮�绁ㄦ垚鍔熴��',
+          duration: 5
+        })
+      } else {
+        notification.warning({
+          top: 92,
+          message: res.message,
+          duration: 5
+        })
+      }
+    })
+  }
+
+  getCallBackendParam = (btn, result) => {
+    const { book, BID, ID } = this.state
+
     let lines = []
-    let pre = '@'
+    let tables = []
+
+    btn.verify.cbScripts.forEach(script => {
+      if (script.status === 'false') return
+
+      if (/\s#[a-z0-9_]+(\s|\()/ig.test(script.sql)) {
+        tables.push(...script.sql.match(/\s#[a-z0-9_]+(\s|\()/ig))
+      }
+    })
+
+    tables = tables.map(tb => tb.replace(/\s|\(/g, ''))
+
+    if (result.$ErrCode) {
+      delete result.$ErrCode
+      delete result.$ErrMesg
+    }
 
     let getDefaultSql = (obj, tb, bid, level) => {
-      let keys = []
-      let vals = []
+      let vals = {}
       let subObjs = []
       let id = Utils.getuuid()
-      let tbName = pre + tb
 
       delete obj.$$key
 
@@ -835,10 +1264,15 @@
           if (Array.isArray(val)) {
             val.forEach(item => {
               if (typeof(item) !== 'object' || Array.isArray(item)) return
-              if (Object.keys(item).length > 0) {
-                item.$$key = tb + '_' + key
-                subObjs.push(item)
-              }
+              if (Object.keys(item).length === 0) return
+
+              Object.keys(item).forEach(k => {
+                if (item[k] === null) {
+                  item[k] = ''
+                }
+              })
+              item.$$key = tb + '_' + key
+              subObjs.push(item)
             })
           } else if (Object.keys(val).length > 0) {
             val.$$key = tb + '_' + key
@@ -847,19 +1281,31 @@
         } else {
           if (typeof(val) === 'string') {
             val = val.replace(/'/ig, '"')
+          } else {
+            val = val + ''
           }
-          keys.push('[' + key + ']')
-          vals.push(`'${val}'`)
+          vals[key] = val
         }
       })
 
-      keys = keys.join(',')
+      vals.mk_level = level
+      vals.mk_id = id
+      vals.mk_bid = bid
 
-      lines.push({
-        table: md5(tb + keys),
-        insert: `Insert into ${tbName} (${keys},[mk_level],[mk_id],[mk_bid])`,
-        select: `Select ${vals.join(',')},'${level}','${id}','${bid}'`
+      let isnew = true
+      lines.forEach(line => {
+        if (line.tb === tb) {
+          line.values.push(vals)
+          isnew = false
+        }
       })
+      if (isnew) {
+        lines.push({
+          tb: tb,
+          type: tables.includes('#' + tb) ? '01' : '02',
+          values: [vals]
+        })
+      }
 
       subObjs.forEach(item => {
         getDefaultSql(item, item.$$key, id, level + 1)
@@ -868,127 +1314,76 @@
     
     getDefaultSql(result, btn.cbTable, '', 1)
 
-    let lineMap = new Map()
-    lines.forEach(line => {
-      if (lineMap.has(line.table)) {
-        let _line = lineMap.get(line.table)
-        _line.selects.push(line.select)
-        lineMap.set(line.table, _line)
-      } else {
-        lineMap.set(line.table, {
-          table: line.table,
-          insert: line.insert,
-          selects: [line.select]
+    let ex = window.GLOB.CacheData.get('sql_' + btn.uuid + 'billback')
+    let exps = []
+
+    let values = {
+      time_id: Utils.getguid(),
+      roleid: sessionStorage.getItem('role_id') || '',
+      mk_departmentcode: sessionStorage.getItem('departmentcode') || '',
+      mk_organization: sessionStorage.getItem('organization') || '',
+      mk_user_type: sessionStorage.getItem('mk_user_type') || '',
+      mk_nation: sessionStorage.getItem('nation') || '',
+      mk_province: sessionStorage.getItem('province') || '',
+      mk_city: sessionStorage.getItem('city') || '',
+      mk_district: sessionStorage.getItem('district') || '',
+      mk_address: sessionStorage.getItem('address') || '',
+      id: ID || '',
+      bid: BID || '',
+      datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+      datam_begin: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+      datam_end: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
+    }
+
+    if (window.GLOB.externalDatabase !== null) {
+      values.db = window.GLOB.externalDatabase
+    }
+
+    ex.reps.forEach(n => {
+      let key = n.toLowerCase()
+      if (values.hasOwnProperty(key)) {
+        exps.push({
+          key: n,
+          value: values[key]
         })
       }
     })
 
-    let param = {
-      func: 'sPC_TableData_InUpDe',
-      BID: BID,
-      menuname: config.name + '(鍥炶皟)'
-    }
-
-    let callbacksql = this.getBackSql()
-    let _prevCustomScript = `${callbacksql}
-    `
-    let _backCustomScript = ''
-
-    btn.cbScripts.forEach(script => {
-      if (script.status === 'false') return
-
-      if (script.position === 'front') {
-        _prevCustomScript += `
-      /* 鑷畾涔夎剼鏈� */
-      ${script.sql}
-      `
-      } else {
-        _backCustomScript += `
-      /* 鑷畾涔夎剼鏈� */
-      ${script.sql}
-      `
-      }
+    exps.push({
+      key: 'account_id',
+      value: book.account_id || ''
+    }, {
+      key: 'account_year_id',
+      value: book.account_year_id || ''
+    }, {
+      key: 'account_code',
+      value: book.account_code || ''
+    }, {
+      key: 'account_year_code',
+      value: book.account_year_code || ''
     })
 
-    _backCustomScript += `
-      aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg`
+    exps.push({
+      key: 'mk_outer_params',  // 鍥炶皟鑴氭湰鐨勬暟鎹浛鎹�
+      value: lines
+    })
 
-    let sql = [...lineMap.values()].map(item => (`
-      ${item.insert}
-      ${item.selects.join(` union all
-      `)}
-    `))
-    sql = sql.join('')
-    sql = _prevCustomScript + sql
-    sql = sql + _backCustomScript
-
-    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') || ''}'`)
-    sql = sql.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
-    sql = sql.replace(/@typename@/ig, `'admin'`)
-
-    if (sessionStorage.getItem('dataM') === 'true') { // 鏁版嵁鏉冮檺
-      sql = sql.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, `'Y'`)
-    } else {
-      sql = sql.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, `''`)
-    }
-
-    if (window.GLOB.debugger === true) {
-      console.info('%c' + config.name + '(鍥炶皟)', 'color: blue')
-      console.info(sql.replace(/\n\s{8}/ig, '\n'))
-    }
-
-    param.LText = sql
-    param.exec_type = window.GLOB.execType || 'y' // 鍚庡彴瑙g爜
-    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
-    param.secretkey = Utils.encrypt('', param.timestamp)
-    param.LText = Utils.formatOptions(param.LText, param.exec_type)
-
+    let md5_id = ''
     if (window.GLOB.probation) {
-      param.s_debug_type = 'Y'
+      md5_id = md5('back_' + btn.uuid + JSON.stringify(exps) + Math.floor(new Date().getTime() / 600000))
+      md5_id = moment().format('YYYYMMDDHHmmss') + md5_id.slice(-18)
     }
 
-    Api.genericInterface(param).then(res => {
-      if (res.status) {
-        const that = this
-
-        confirm({
-          title: '淇濆瓨鎴愬姛銆�',
-          okText: '缁х画濉紑',
-          cancelText: '鍏抽棴',
-          onOk() {
-            if (config.billOutBtn.reTabId) {
-              MKEmitter.emit('reloadMenuView', config.billOutBtn.reTabId, 'table')
-            }
-            if (config.billOutBtn.syncComId) {
-              MKEmitter.emit('reloadData', config.billOutBtn.syncComId)
-            }
-            that.clearData()
-          },
-          onCancel() {
-            if (config.billOutBtn.reTabId) {
-              MKEmitter.emit('reloadMenuView', config.billOutBtn.reTabId, 'table')
-            }
-            if (config.billOutBtn.syncComId) {
-              MKEmitter.emit('reloadData', config.billOutBtn.syncComId)
-            }
-            MKEmitter.emit('closeTabView', config.$pageId)
-          }
-        })
-      } else {
-        notification.warning({
-          top: 92,
-          message: res.message,
-          duration: 5
-        })
-        this.setState({
-          saveType: ''
-        })
-      }
-    })
+    return {
+      $backend: true,
+      $type: 's_TableData_InUpDe',
+      data: [{
+        id: ex.id,
+        menuname: btn.logLabel + '(鍥炶皟)',
+        exps: exps,
+        md5_id: md5_id
+      }]
+    }
   }
 
   getBackSql = () => {
@@ -1031,16 +1426,138 @@
     })
   }
 
-  render() {
-    const { config, book, loading, invTypes, reqfields, saveType, date, timestamp, 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, orgname, tax_no, addr, tel, bank_name, account_no, remark, reviewer, drawer, payee, details, visible, tax_type } = this.state
+  addInvice = () => {
+    const { saveType } = this.state
 
-    if (!book || (config.wrap.datatype === 'dynamic' && !tax_no)) {
+    if (saveType) {
+      notification.warning({
+        top: 92,
+        message: saveType === 'bill' ? '鍗曟嵁淇濆瓨涓紝璇风◢鍚庛��' : '寮�绁ㄤ腑锛岃绋嶅悗銆�',
+        duration: 3
+      })
+      return
+    }
+
+    this.clearData()
+
+    notification.success({
+      top: 92,
+      message: '鍗曟嵁宸叉洿鏂般��',
+      duration: 3
+    })
+  }
+
+  // jumpSys = () => {
+  //   window.open(`${window.location.origin}/kgcs/thirdPlatFormLogin?userName=admin&taxCode=91120222MA07GMNW97&taxName=澶╂触鐣呬韩鏁板瓧绉戞妧鏈夐檺鍏徃`)
+  // }
+
+  render() {
+    const { config, book, loading, invTypes, reqfields, saveType, date, timestamp, 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, orgname, tax_no, addr, tel, bank_name, account_no, remark, reviewer, drawer, payee, details, visible, tax_type, invoice_no, invoice_code, invoice_date, read_only, invoice_type_name } = this.state
+
+    if (!book || (config.wrap.datatype === 'dynamic' && !timestamp)) {
       return <div className="menu-invoice-wrap" style={config.style}>
         <div className="loading-mask">
           <div className="ant-spin-blur"></div>
           <Spin />
         </div>
       </div>
+    }
+
+    if (read_only) {
+      return (
+        <div className="menu-invoice-wrap read_only" style={config.style}>
+          {loading ?
+            <div className="loading-mask">
+              <div className="ant-spin-blur"></div>
+              <Spin />
+            </div> : null
+          }
+          <div className="inv-action">
+            {config.wrap.backBtn === 'show' ? <Button className="mk-back" onClick={this.goback}><LeftOutlined />杩斿洖</Button> : null}
+          </div>
+          <div className="inv-header">
+            <div className="inv-type">{invoice_type_name}</div>
+            <div className="inv-msg">
+              {invoice_no ? <div>鍙戠エ鍙风爜锛歿invoice_no}</div> : null}
+              {invoice_code ? <div>鍙戠エ浠g爜锛歿invoice_code}</div> : null}
+              {invoice_date ? <div>寮�绁ㄦ棩鏈燂細{invoice_date}</div> : null}
+            </div>
+          </div>
+          <div className="inv-body">
+            <div className="inv-main-content">
+              <div className="inv-buyer">
+                <div className="inv-label">璐拱鏂�</div>
+                <div className="inv-content">
+                  <Form.Item className="mk-name" label={<>鍚�<span></span>绉�</>}>
+                    {from_to_name}
+                  </Form.Item>
+                  <Form.Item label="绾崇◣浜鸿瘑鍒彿">
+                    {from_to_tax_no}
+                  </Form.Item>
+                  <Form.Item label={<>鍦�<span></span>鍧�<span></span>銆�<span></span>鐢�<span></span>璇�</>}>
+                    {from_to_addr + ' ' + from_to_tel}
+                  </Form.Item>
+                  <Form.Item label="寮�鎴疯鍙婅处鍙�">
+                    {from_to_bank_name + ' ' + from_to_account_no}
+                  </Form.Item>
+                </div>
+              </div>
+              <div className="inv-notice">
+                <div className="inv-label">閫氱煡鍒�</div>
+                <div className="inv-content">
+                  <Form.Item label={<>鎵�<span></span>鏈�<span></span>鍙�</>}>
+                    {from_to_mob}
+                  </Form.Item>
+                  <Form.Item label={<>閭�<span></span>绠�</>}>
+                    {from_to_email}
+                  </Form.Item>
+                </div>
+              </div>
+            </div>
+            <div className="inv-details">
+              <InvoiceTable data={details} timestamp={timestamp} read_only={true} config={config.detail} tax_type={tax_type} onChange={(details) => this.setState({details})}/>
+            </div>
+            <div className="inv-main-content">
+              <div className="inv-buyer">
+                <div className="inv-label">閿�鍞柟</div>
+                <div className="inv-content">
+                  <Form.Item label={<>鍚�<span></span>绉�</>}>
+                    {orgname}
+                  </Form.Item>
+                  <Form.Item label="绾崇◣浜鸿瘑鍒彿">
+                    {tax_no}
+                  </Form.Item>
+                  <Form.Item label={<>鍦�<span></span>鍧�<span></span>銆�<span></span>鐢�<span></span>璇�</>}>
+                    {addr + ' ' + tel}
+                  </Form.Item>
+                  <Form.Item label="寮�鎴疯鍙婅处鍙�">
+                    {bank_name + ' ' + account_no}
+                  </Form.Item>
+                </div>
+              </div>
+              <div className="inv-notice">
+                <div className="inv-label">澶囨敞</div>
+                <div className="inv-content" style={{paddingTop: '30px'}}>
+                  <Form.Item label="">
+                    {remark}
+                  </Form.Item>
+                </div>
+              </div>
+            </div>
+          </div>
+          <div className="inv-tail">
+            <Form.Item label="鏀舵浜�">
+              {payee}
+            </Form.Item>
+            <Form.Item label="澶嶆牳浜�">
+              {reviewer}
+            </Form.Item>
+            <Form.Item label="寮�绁ㄤ汉">
+              {drawer}
+            </Form.Item>
+          </div>
+        </div>
+      )
     }
 
     return (
@@ -1053,6 +1570,8 @@
         }
         <div className="inv-action">
           {config.wrap.backBtn === 'show' ? <Button className="mk-back" onClick={this.goback}><LeftOutlined />杩斿洖</Button> : null}
+          {/* <Button className="mk-addinv" onClick={this.jumpSys}>璺宠浆</Button> */}
+          <Button className="mk-addinv" onClick={this.addInvice}>鏂板鍙戠エ</Button>
           <Button className="mk-bill" loading={saveType === 'bill'} onClick={this.saveBill}>淇濆瓨鍗曟嵁</Button>
           <Button className="mk-submit" loading={saveType === 'out'} onClick={this.outBill}>鎻愪氦寮�绁�</Button>
         </div>
@@ -1073,7 +1592,7 @@
             <div className="inv-buyer">
               <div className="inv-label">璐拱鏂�</div>
               <div className="inv-content">
-                <Form.Item required={reqfields.includes('from_to_name')} label={<>鍚�<span></span>绉�</>} extra={<EllipsisOutlined onClick={() => this.setState({visible: true})}/>}>
+                <Form.Item className="mk-name" required={reqfields.includes('from_to_name')} label={<>鍚�<span></span>绉�</>} extra={<EllipsisOutlined onClick={() => this.setState({visible: true})}/>}>
                   <Input placeholder="璇疯緭鍏ヨ喘涔版柟鍚嶇О" allowClear value={from_to_name} autoComplete="off" onChange={(e) => this.setState({from_to_name: e.target.value})}/>
                 </Form.Item>
                 <Form.Item required={reqfields.includes('from_to_tax_no')} label="绾崇◣浜鸿瘑鍒彿">
@@ -1102,7 +1621,7 @@
             </div>
           </div>
           <div className="inv-details">
-            <InvoiceTable data={details} timestamp={timestamp} config={config.detail} tax_type={tax_type} onChange={(details) => this.setState({details})}/>
+            <InvoiceTable data={details} timestamp={timestamp} read_only={false} config={config.detail} tax_type={tax_type} onChange={(details) => this.setState({details})}/>
           </div>
           <div className="inv-main-content">
             <div className="inv-buyer">
@@ -1148,7 +1667,7 @@
         <Modal
           title="瀹㈡埛淇℃伅"
           visible={visible}
-          width="70vw"
+          width="75vw"
           maskClosable={false}
           onCancel={() => { this.setState({ visible: false }) }}
           footer={null}

--
Gitblit v1.8.0