From c2580fb8de3bdaabb4179b0ce0fcd2fbac802441 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 01 三月 2023 00:49:14 +0800
Subject: [PATCH] 2023-03-01

---
 src/tabviews/custom/components/module/voucher/index.jsx |  700 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 603 insertions(+), 97 deletions(-)

diff --git a/src/tabviews/custom/components/module/voucher/index.jsx b/src/tabviews/custom/components/module/voucher/index.jsx
index 6bd9900..c230975 100644
--- a/src/tabviews/custom/components/module/voucher/index.jsx
+++ b/src/tabviews/custom/components/module/voucher/index.jsx
@@ -1,18 +1,22 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Button, Select, Input, Modal, DatePicker, notification, InputNumber } from 'antd'
+import { Button, Select, Input, Modal, DatePicker, notification, InputNumber, Dropdown } from 'antd'
 import moment from 'moment'
 
 import Api from '@/api'
 import Utils from '@/utils/utils.js'
-import asyncComponent from '@/utils/asyncComponent'
 import MKEmitter from '@/utils/events.js'
+import VoucherTable from './voucherTable'
+import SaveAsTemp from './saveAsTemp'
+import ResetRemark from './resetRemark'
+import ResetAttach from './resetAttach'
+import LoadFromTemp from './loadFromTemp'
+import asyncComponent from '@/utils/asyncComponent'
 import './index.scss'
 
+const PrintVoucher = asyncComponent(() => import('./printVoucher'))
 const { confirm } = Modal
-const { TextArea } = Input
-const VoucherTable = asyncComponent(() => import('./voucherTable'))
 
 class VoucherModule extends Component {
   static propTpyes = {
@@ -34,12 +38,18 @@
     book: null,
     username: sessionStorage.getItem('User_Name'),
     remark: '',
-    remarkVisible: false,
     attachments: 0,
+    attachlist: [],
+    oriAttachs: [],
+    tempTypes: [],
+    tempTypeClass: '',
+    tempTypeName: '',
     title: '',
     orgcode: '',
     orgname: '',
-    status: '' // 鏂板缓鏃讹紝empty銆乧hange銆乻aved
+    status: '', // 鏂板缓鏃讹紝empty銆乧hange銆乻aved
+    saved: false,
+    voucherCode: ''
   }
 
   UNSAFE_componentWillMount () {
@@ -57,18 +67,43 @@
       BID = BData.$BID || ''
     }
 
+    let book = null
+    let vouDate = null
+    if (config.wrap.supBook) {
+      book = window.GLOB.CacheData.get(config.wrap.supBook) || null
+
+      if (book) {
+        let month = book.months
+        vouDate = moment()
+  
+        if (month && month < moment().format('YYYY-MM')) {
+          vouDate = moment(month, 'YYYY-MM').endOf('month')
+        }
+      }
+    }
+
+    // config.wrap.type = 'checkVoucher'
+    // BID = '20230228173542370E2F4FC1773704C29A6A4'
+
+    // config.wrap.type = 'checkTemp'
+    // BID = '20230214174458780MFR8IA576ON4VKNOLVH'
+
     window.GLOB.CacheVoucher.delete(config.uuid)
     let type = config.wrap.type || 'createVoucher'
 
-    type = 'checkVoucher'
+    if (type === 'createVoucher' || type === 'createTemp') {
+      BID = Utils.getguid()
+    }
 
     this.setState({
+      book: book,
+      vouDate: vouDate,
       config: fromJS(config).toJS(),
       type: type,
       BID: BID || '',
-      status: 'empty',
-      book: window.GLOB.CacheData.get(config.wrap.supBook) || null
+      status: 'empty'
     }, () => {
+      this.loadData()
       this.getVoucher()
     })
   }
@@ -93,7 +128,7 @@
   }
 
   resetParentParam = (MenuID, id, data) => {
-    const { config } = this.state
+    const { config, type } = this.state
 
     if (config.wrap.supBook === MenuID) {
       let month = data.months
@@ -110,7 +145,7 @@
       return
     }
 
-    if (!config.wrap.supModule || config.wrap.supModule !== MenuID) return
+    if (!config.wrap.supModule || config.wrap.supModule !== MenuID || type === 'createVoucher' || type === 'createTemp') return
     if (id !== this.state.BID || id !== '') {
       this.setState({ BID: id }, () => {
         this.getVoucher()
@@ -127,6 +162,8 @@
       func: 's_get_fcc_account_data',
       // account_code: book.account_code || '',
       fcc_date: book.months ? book.months + '-01' : moment().format('YYYY-MM-DD'),
+      account_year_code: book.account_year_code || '',
+      months: book.months ? book.months : moment().format('YYYY-MM'),
       BID: book.id
     }
 
@@ -151,10 +188,14 @@
           charInt: charInt,
           orgcode: res.orgcode,
           orgname: res.orgname,
+          tempTypes: res.temp_type || []
         })
       } else {
         this.setState({
-          typeOptions: typeOptions
+          typeOptions: typeOptions,
+          orgcode: res.orgcode,
+          orgname: res.orgname,
+          tempTypes: res.temp_type || []
         })
       }
 
@@ -225,17 +266,18 @@
   }
 
   getVoucher = () => {
-    // const { book, BID, type } = this.state
-    const { book, type } = this.state
+    const { book, BID, type } = this.state
 
-    // if (!book || !BID || type === 'createVoucher' || type === 'createTemp') return
-    if (!book || type === 'createVoucher' || type === 'createTemp') return
+    if (!book || !BID || type === 'createVoucher' || type === 'createTemp') return
 
     let param = {
       func: 's_get_fcc_voucher',
       BID: book.id,
-      // ID: BID
-      ID: '20230207175535042UOMRLECLIVPKOBU7L2N'
+      ID: BID
+    }
+
+    if (type === 'checkTemp') {
+      param.func = 's_get_fcc_voucher_temp'
     }
 
     Api.genericInterface(param).then(res => {
@@ -265,37 +307,61 @@
           line.exratecode = line.foreign_exratecode || ''
           line.exratename = line.foreign_exratename || ''
           line.local_currency = line.local_exratecode || ''
-
-          if (line.unitratio && line.foreign_amount) {
-            line.foreign_currency_type = 'Y'
-          }
-
-          if (line.net_unitprice && line.fcc_count) {
-            line.count_type = 'Y'
-          }
+          line.foreign_currency_type = line.foreign_type || ''
 
           if (line.sup) {
             line.supAccounts = line.sup.map(cell => {
               cell.uuid = cell.sup_id
               return cell
             })
+            delete line.sup
           }
 
           return line
         })
       }
 
-      this.setState({
-        data: data,
-        vouDate: res.fibvoucherdate ? moment(res.fibvoucherdate, 'YYYY-MM-DD') : null,
-        charType: res.voucher_class,
-        charName: res.voucher_char,
-        charInt: res.voucher_char_int,
-        orgcode: res.orgcode,
-        orgname: res.orgname,
-        tbdata: fromJS(data).toJS(),
-        status: 'saved'
-      })
+      if (type !== 'checkTemp') {
+        let files = []
+
+        res.fcc_files && res.fcc_files.forEach(file => {
+          file.attachments.forEach(item => {
+            item.id = item.attach_id
+            item.data_code = file.data_code
+            item.data_name = file.data_name
+            item.BID = file.id
+
+            files.push(item)
+          })
+        })
+
+        this.setState({
+          data: data,
+          attachlist: files,
+          vouDate: res.fibvoucherdate ? moment(res.fibvoucherdate, 'YYYY-MM-DD') : null,
+          charType: res.voucher_class,
+          charName: res.voucher_char,
+          charInt: res.voucher_char_int,
+          // orgcode: res.orgcode,
+          // orgname: res.orgname,
+          voucherCode: res.voucher_code || '',
+          tbdata: fromJS(data).toJS(),
+          oriAttachs: fromJS(files).toJS(),
+          attachments: res.attachments_int,
+          title: res.voucher_text || '',
+          remark: res.remark || '',
+          status: 'saved'
+        })
+      } else {
+        this.setState({
+          data: data,
+          tbdata: fromJS(data).toJS(),
+          title: res.voucher_text || '',
+          tempTypeClass: res.typechartwo || '',
+          tempTypeName: res.typecharthree || '',
+          status: 'saved'
+        })
+      }
     })
   }
 
@@ -416,12 +482,21 @@
   }
 
   voucherSave = (list, t) => {
-    const { data, config, charInt, charType, vouDate, book, remark, charName, attachments, title, orgcode, orgname } = this.state
+    const { type, BID, data, config, voucherCode, charInt, charType, vouDate, book, remark, charName, attachments, title, orgcode, orgname, attachlist, oriAttachs } = this.state
 
+    let err = ''
     if (!book) {
+      err = '璇烽�夋嫨璐﹀锛�'
+    } else if (!vouDate) {
+      err = '璇烽�夋嫨鏃ユ湡锛�'
+    } else if (!charName || !charInt) {
+      err = '璇烽�夋嫨鍑瘉鍙凤紒'
+    }
+
+    if (err) {
       notification.warning({
         top: 92,
-        message: '璇烽�夋嫨璐﹀锛�',
+        message: err,
         duration: 5
       })
       return
@@ -430,8 +505,8 @@
     let param = {
       func: 's_fcc_voucher_addupt',
       BID: book.id,
-      ID: Utils.getguid(),
-      voucher_code: '',
+      ID: BID,
+      voucher_code: voucherCode || '',
       voucher_text: title,
       remark: remark,
       account_year_code: book.account_year_code || '',
@@ -441,6 +516,7 @@
       orgname: orgname || '',
       voucher_class: charType,
       years: book.years,
+      months: moment(vouDate).format('YYYY-MM'),
       business_type: config.wrap.businessType || '',
       voucher_sign: config.wrap.voucherSign || '',
       voucher_char: charName,
@@ -467,6 +543,8 @@
     let sup_data = []
     let voucherMap = new Map()
     let supMap = new Map()
+    let extract = localStorage.getItem(window.GLOB.host + '_voucher_extract')
+    extract = extract ? JSON.parse(extract) : []
 
     data.forEach(item => {
       voucherMap.set(item.uuid, item)
@@ -494,6 +572,10 @@
       let count = item.count_type === 'Y'
       let curr = item.foreign_currency_type === 'Y'
       let direct = item.debit ? 'debit' : 'credit'
+      
+      if (type === 'createVoucher' && item.subject_voucher_text && item.subject_voucher_text.length < 20) {
+        extract.unshift(item.subject_voucher_text)
+      }
 
       if (voucherMap.has(item.uuid)) {
         voucherMap.delete(item.uuid)
@@ -507,15 +589,291 @@
           sup_data.push(`'${n.uuid}','${item.subject_voucher_code || ''}','${item.voucher_lp || ''}','${n.voucher_sup_lp || ''}','${item.subject_code}','${item.subject_name}','${n.sup_voucher_text || ''}','${direct}',${item.debit || item.credit},'${n.customercode || ''}','${n.customername || ''}','${n.suppliercode || ''}','${n.suppliername || ''}','${n.co_pro_code || ''}','${n.co_pro_name || ''}','${n.workercode || ''}','${n.workername || ''}','${n.project_code || ''}','${n.project_name || ''}','${n.productcode || ''}','${n.productname || ''}','${n.cash_flow_code || ''}','${n.cash_flow_name || ''}','${n.sup_acc_code || ''}','${n.sup_acc_name || ''}','${n.sup_acc_type || ''}','${item.uuid}',0`)
         })
       }
-      return `'${item.uuid}','${item.subject_voucher_code || ''}','${item.voucher_lp || ''}','${item.subject_code}','${item.subject_name}','${item.subject_voucher_text || ''}',${count ? item.fcc_count || 0 : 0},${count ? item.net_unitprice || 0 : 0},'${item.unit}',${item.debit || item.credit},'${direct}','${curr ? item.exratecode : '01010001'}','${curr ? item.exratename : 'CNY'}',${curr ? item.unitratio || 0 : 0},'${item.sup_accounting}',${item.debit ? 1 : -1},${curr ? item.foreign_amount || 0 : 0},0,'${item.local_currency || ''}'`
+      return `'${item.uuid}','${item.subject_voucher_code || ''}','${item.voucher_lp || ''}','${item.subject_code}','${item.subject_name}','${item.subject_voucher_text || ''}',${count ? item.fcc_count || 0 : 0},${count ? item.net_unitprice || 0 : 0},'${item.unit}',${item.debit || item.credit},'${direct}','${curr ? item.exratecode : '01010001'}','${curr ? item.exratename : 'CNY'}',${curr ? item.unitratio || 0 : 0},'${item.sup_accounting}',${item.debit ? 1 : -1},${curr ? item.foreign_amount || 0 : 0},0,'${item.local_currency || ''}','${count ? 'Y' : ''}','${curr ? 'Y' : ''}'`
     })
+
+    if (type === 'createVoucher') {
+      extract = Array.from(new Set(extract))
+      if (extract.length > 20) {
+        extract.length = 20
+      }
+      localStorage.setItem(window.GLOB.host + '_voucher_extract', JSON.stringify(extract))
+    }
 
     voucherMap.forEach(item => {
       let count = item.count_type === 'Y'
       let curr = item.foreign_currency_type === 'Y'
       let direct = item.debit ? 'debit' : 'credit'
 
-      subject_data.push(`'${item.uuid}','${item.subject_voucher_code || ''}','${item.voucher_lp || ''}','${item.subject_code}','${item.subject_name}','${item.subject_voucher_text || ''}',${count ? item.fcc_count || 0 : 0},${count ? item.net_unitprice || 0 : 0},'${item.unit}',${item.debit || item.credit},'${direct}','${curr ? item.exratecode : '01010001'}','${curr ? item.exratename : 'CNY'}',${curr ? item.unitratio || 0 : 0},'${item.sup_accounting}',${item.debit ? 1 : -1},${curr ? item.foreign_amount || 0 : 0},1,'${item.local_currency || ''}'`)
+      subject_data.push(`'${item.uuid}','${item.subject_voucher_code || ''}','${item.voucher_lp || ''}','${item.subject_code}','${item.subject_name}','${item.subject_voucher_text || ''}',${count ? item.fcc_count || 0 : 0},${count ? item.net_unitprice || 0 : 0},'${item.unit}',${item.debit || item.credit},'${direct}','${curr ? item.exratecode : '01010001'}','${curr ? item.exratename : 'CNY'}',${curr ? item.unitratio || 0 : 0},'${item.sup_accounting}',${item.debit ? 1 : -1},${curr ? item.foreign_amount || 0 : 0},1,'${item.local_currency || ''}','${count ? 'Y' : ''}','${curr ? 'Y' : ''}'`)
+    })
+
+    supMap.forEach(n => {
+      sup_data.push(`'${n.uuid}','${n.sup_voucher_code}','${n.sup_voucher_lp}','${n.voucher_sup_lp || ''}','${n.sup_subject_code}','${n.sup_subject_name}','${n.sup_voucher_text || ''}','${n.sup_direct}',${n.sup_net_amount},'${n.customercode || ''}','${n.customername || ''}','${n.suppliercode || ''}','${n.suppliername || ''}','${n.co_pro_code || ''}','${n.co_pro_name || ''}','${n.workercode || ''}','${n.workername || ''}','${n.project_code || ''}','${n.project_name || ''}','${n.productcode || ''}','${n.productname || ''}','${n.cash_flow_code || ''}','${n.cash_flow_name || ''}','${n.sup_acc_code || ''}','${n.sup_acc_name || ''}','${n.sup_acc_type || ''}','${n.sup_bid}',1`)
+    })
+
+    let attachments_data = []
+    let ids = []
+
+    attachlist.forEach(item => {
+      ids.push(item.id)
+
+      attachments_data.push(`'${item.id}',0`)
+    })
+
+    if (oriAttachs.length > 0) {
+      oriAttachs.forEach(item => {
+        if (!ids.includes(item.id)) {
+          attachments_data.push(`'${item.id}',1`)
+        }
+      })
+    }
+
+    param.subject_data = window.btoa(window.encodeURIComponent(subject_data.join(';un')))
+    param.sup_data = window.btoa(window.encodeURIComponent(sup_data.join(';un')))
+    param.attachments_data = window.btoa(window.encodeURIComponent(attachments_data.join(';un')))
+
+    Api.genericInterface(param).then(res => {
+      if (!res.status) {
+        notification.warning({
+          top: 92,
+          message: res.message,
+          duration: 5
+        })
+        return
+      }
+
+      notification.success({
+        top: 92,
+        message: '淇濆瓨鎴愬姛锛�' + (res.voucher_char_int !== charInt ? charInt + '鍙峰嚟璇佸彿宸茬粡瀛樺湪锛屽凡涓烘偍鏇存柊涓�' + res.voucher_char_int + '鍙峰嚟璇併��'  : ''),
+        duration: 5
+      })
+
+      if (t === 'add') {
+        this.setState({
+          status: 'empty',
+          remark: '',
+          tbdata: [],
+          oriAttachs: fromJS(attachlist).toJS(),
+          charInt: res.voucher_char_int + 1,
+          BID: Utils.getguid(),
+          saved: false
+        })
+        MKEmitter.emit('cleartable', config.uuid)
+      } else {
+        this.setState({
+          status: 'saved',
+          charInt: res.voucher_char_int || charInt,
+          data: fromJS(list).toJS(),
+          oriAttachs: fromJS(attachlist).toJS(),
+          saved: true
+        })
+      }
+    })
+  }
+
+  triggerTempsave = (name, typeChar, typeName) => {
+    const { tbdata } = this.state
+
+    let err = ''
+    let list = []
+
+    tbdata.forEach((line, index) => {
+      if (err) return
+
+      let _index = index + 1
+
+      if (!line.subject_voucher_text && !line.subject_code) {
+        if (_index === 1) {
+          err = '绗�1琛屼笉鍙负绌恒��'
+        }
+
+        return
+      }
+
+      if (!line.subject_voucher_text) {
+        err = `绗�${_index}琛岋紝鎽樿涓嶅彲涓虹┖銆俙
+      } else if (!line.subject_code) {
+        err = `绗�${_index}琛岋紝绉戠洰涓嶅彲涓虹┖銆俙
+      } else if (line.sup_accounting && !line.supAccounts) {
+        err = `绗�${_index}琛岋紝璇烽�夋嫨杈呭姪鏍哥畻銆俙
+      } else if (line.sup_accounting && line.supAccounts) {
+        line.supAccounts.forEach(item => {
+          if (item.sup_acc_type === 'supplier') {
+            if (!item.suppliercode || !item.suppliername) {
+              err = `绗�${_index}琛岋紝璇烽�夋嫨杈呭姪鏍哥畻銆俙
+            }
+          } else if (item.sup_acc_type === 'customer') {
+            if (!item.customercode || !item.customername) {
+              err = `绗�${_index}琛岋紝璇烽�夋嫨杈呭姪鏍哥畻銆俙
+            }
+          } else if (item.sup_acc_type === 'department') {
+            if (!item.co_pro_code || !item.co_pro_name) {
+              err = `绗�${_index}琛岋紝璇烽�夋嫨杈呭姪鏍哥畻銆俙
+            }
+          } else if (item.sup_acc_type === 'project') {
+            if (!item.projectcode || !item.projectname) {
+              err = `绗�${_index}琛岋紝璇烽�夋嫨杈呭姪鏍哥畻銆俙
+            }
+          } else if (item.sup_acc_type === 'inventory') {
+            if (!item.productcode || !item.productname) {
+              err = `绗�${_index}琛岋紝璇烽�夋嫨杈呭姪鏍哥畻銆俙
+            }
+          } else if (item.sup_acc_type === 'employee') {
+            if (!item.workercode || !item.workername) {
+              err = `绗�${_index}琛岋紝璇烽�夋嫨杈呭姪鏍哥畻銆俙
+            }
+          } else if (item.sup_acc_type === 'cash_flow') {
+            if (!item.cash_flow_code || !item.cash_flow_name) {
+              err = `绗�${_index}琛岋紝璇烽�夋嫨杈呭姪鏍哥畻銆俙
+            }
+          } else if (!item.sup_acc_type || !item.sup_acc_code || !item.sup_acc_name) {
+            err = `绗�${_index}琛岋紝璇烽�夋嫨杈呭姪鏍哥畻銆俙
+          }
+        })
+      }
+
+      list.push(line)
+    })
+
+    if (!err && list.length === 0) {
+      err = '绗�1琛屼笉鍙负绌恒��'
+    }
+
+    if (err) {
+      notification.warning({
+        top: 92,
+        message: err,
+        duration: 5
+      })
+      return
+    }
+    
+    this.voucherTempSave(list, name, typeChar, typeName)
+  }
+
+  voucherTempSave = (list, name, typeChar, typeName) => {
+    const { type, BID, data, book, title, orgcode, orgname, tempTypeClass, tempTypeName } = this.state
+
+    if (!book) {
+      notification.warning({
+        top: 92,
+        message: '璇烽�夋嫨璐﹀锛�',
+        duration: 5
+      })
+      return
+    } else if (type !== 'createVoucher' && !title) {
+      notification.warning({
+        top: 92,
+        message: '璇峰~鍐欐ā鏉垮悕绉帮紒',
+        duration: 5
+      })
+      return
+    } else if (type !== 'createVoucher' && !tempTypeClass) {
+      notification.warning({
+        top: 92,
+        message: '璇烽�夋嫨妯℃澘绫诲瀷锛�',
+        duration: 5
+      })
+      return
+    }
+
+    let id = BID
+    let _name = title
+    let _typeChar = tempTypeClass
+    let _typeName = tempTypeName
+
+    if (type === 'createVoucher') {
+      id = Utils.getguid()
+      _name = name
+      _typeChar = typeChar
+      _typeName = typeName
+    }
+
+    let param = {
+      func: 's_fcc_voucher_addupt_temp',
+      BID: book.id,
+      ID: id,
+      voucher_code: '',
+      voucher_text: _name,
+      remark: '',
+      account_year_code: book.account_year_code || '',
+      voucher_type: 'fcc_temp',
+      voucher_type_text: '鍑瘉妯℃澘',
+      orgcode: orgcode || '',
+      orgname: orgname || '',
+      voucher_class: 'temp',
+      years: book.years,
+      months: moment().format('YYYY-MM'),
+      business_type: '',
+      voucher_sign: 'temp',
+      voucher_char: '',
+      voucher_char_int: 0,
+      account_code: book.account_code || '',
+      fibvoucherdate: moment().format('YYYY-MM-DD'),
+      UserName: sessionStorage.getItem('User_Name') || '',
+      FullName: sessionStorage.getItem('Full_Name') || '',
+      attachments_int: 0,
+      typechartwo: _typeChar,
+      typecharthree: _typeName,
+      sup_data: '',
+      subject_data: ''
+    }
+
+    let sup_data = []
+    let voucherMap = new Map()
+    let supMap = new Map()
+
+    if (type !== 'createVoucher') {
+      data.forEach(item => {
+        voucherMap.set(item.uuid, item)
+  
+        if (item.sup_accounting && item.supAccounts) {
+          item.supAccounts.forEach(cell => {
+            if (!cell.sup_acc_type) return
+  
+            let _cell = {...cell}
+  
+            _cell.sup_voucher_code = item.subject_voucher_code || ''
+            _cell.sup_voucher_lp = item.voucher_lp || ''
+            _cell.sup_subject_code = item.subject_code || ''
+            _cell.sup_subject_name = item.subject_name || ''
+            _cell.sup_bid = item.uuid || ''
+            _cell.sup_direct = !item.credit ? 'debit' : 'credit'
+            _cell.sup_net_amount = item.debit || item.credit || 0
+  
+            supMap.set(item.uuid + cell.sup_acc_type, _cell)
+          })
+        }
+      })
+    }
+    
+    let subject_data = list.map(item => {
+      let count = item.count_type === 'Y'
+      let curr = item.foreign_currency_type === 'Y'
+      let direct = !item.credit ? 'debit' : 'credit'
+
+      if (voucherMap.has(item.uuid)) {
+        voucherMap.delete(item.uuid)
+      }
+      if (item.sup_accounting && item.supAccounts) {
+        item.supAccounts.forEach(n => {
+          if (supMap.has(item.uuid + n.sup_acc_type)) {
+            supMap.delete(item.uuid + n.sup_acc_type)
+          }
+
+          sup_data.push(`'${n.uuid}','${item.subject_voucher_code || ''}','${item.voucher_lp || ''}','${n.voucher_sup_lp || ''}','${item.subject_code}','${item.subject_name}','${n.sup_voucher_text || ''}','${direct}',${item.debit || item.credit || 0},'${n.customercode || ''}','${n.customername || ''}','${n.suppliercode || ''}','${n.suppliername || ''}','${n.co_pro_code || ''}','${n.co_pro_name || ''}','${n.workercode || ''}','${n.workername || ''}','${n.project_code || ''}','${n.project_name || ''}','${n.productcode || ''}','${n.productname || ''}','${n.cash_flow_code || ''}','${n.cash_flow_name || ''}','${n.sup_acc_code || ''}','${n.sup_acc_name || ''}','${n.sup_acc_type || ''}','${item.uuid}',0`)
+        })
+      }
+      return `'${item.uuid}','${item.subject_voucher_code || ''}','${item.voucher_lp || ''}','${item.subject_code}','${item.subject_name}','${item.subject_voucher_text || ''}',${count ? item.fcc_count || 0 : 0},${count ? item.net_unitprice || 0 : 0},'${item.unit}',${item.debit || item.credit || 0},'${direct}','${curr ? item.exratecode : '01010001'}','${curr ? item.exratename : 'CNY'}',${curr ? item.unitratio || 0 : 0},'${item.sup_accounting}',${item.direct ? 1 : -1},${curr ? item.foreign_amount || 0 : 0},0,'${item.local_currency || ''}','${count ? 'Y' : ''}','${curr ? 'Y' : ''}'`
+    })
+
+    voucherMap.forEach(item => {
+      let count = item.count_type === 'Y'
+      let curr = item.foreign_currency_type === 'Y'
+      let direct = !item.credit ? 'debit' : 'credit'
+
+      subject_data.push(`'${item.uuid}','${item.subject_voucher_code || ''}','${item.voucher_lp || ''}','${item.subject_code}','${item.subject_name}','${item.subject_voucher_text || ''}',${count ? item.fcc_count || 0 : 0},${count ? item.net_unitprice || 0 : 0},'${item.unit}',${item.debit || item.credit || 0},'${direct}','${curr ? item.exratecode : '01010001'}','${curr ? item.exratename : 'CNY'}',${curr ? item.unitratio || 0 : 0},'${item.sup_accounting}',${item.direct ? 1 : -1},${curr ? item.foreign_amount || 0 : 0},1,'${item.local_currency || ''}','${count ? 'Y' : ''}','${curr ? 'Y' : ''}'`)
     })
 
     supMap.forEach(n => {
@@ -535,41 +893,19 @@
         return
       }
 
-      if (t === 'add') {
-        this.setState({
-          status: 'empty',
-          remark: '',
-          tbdata: [],
-          charInt: charInt + 1
-        })
-        MKEmitter.emit('cleartable', config.uuid)
-      } else {
+      notification.success({
+        top: 92,
+        message: '淇濆瓨鎴愬姛锛�',
+        duration: 5
+      })
+
+      if (type !== 'createVoucher') {
         this.setState({
           status: 'saved',
-          data: fromJS(list).toJS()
+          data: fromJS(list).toJS(),
         })
       }
     })
-  }
-
-  triggerprint = () => {
-    this.setState({remarkVisible: true})
-  }
-
-  remarkSubmit = () => {
-    const { config } = this.state
-    let node = document.getElementById(config.uuid + 'remark')
-    let val = node.value
-
-    if (val && val.length > 512) {
-      notification.warning({
-        top: 92,
-        message: '褰撳墠鍐呭瓒呴暱锛屽娉ㄦ渶澶�512涓瓧绗︺��',
-        duration: 5
-      })
-      return
-    }
-    this.setState({remark: val, remarkVisible: false})
   }
 
   dataChange = (data) => {
@@ -588,7 +924,93 @@
       _val = parseInt(val)
     }
     
-    this.setState({attachments: _val})
+    this.setState({attachments: _val, status: 'change'})
+  }
+
+  changeVouDate = (val) => {
+    const { type, status, saved } = this.state
+
+    this.setState({vouDate: val, status: 'change'})
+
+    if (type === 'createVoucher' && val && !saved && (status === 'empty' || status === 'change')) {
+      this.updateVoucherChar(val)
+    }
+  }
+
+  updateVoucherChar = (val) => {
+    const { book, config } = this.state
+
+    if (!book) return
+
+    let param = {
+      func: 's_get_fcc_account_data',
+      search_type: 'Y',
+      fcc_date: book.months ? book.months + '-01' : moment().format('YYYY-MM-DD'),
+      account_year_code: book.account_year_code || '',
+      months: moment(val).format('YYYY-MM'),
+      BID: book.id
+    }
+
+    Api.genericInterface(param).then(res => {
+      if (!res.status) {
+        notification.warning({
+          top: 92,
+          message: res.message,
+          duration: 5
+        })
+        return
+      }
+
+      let typeOptions = res.char || []
+
+      if (typeOptions.length > 0) {
+        let charType = this.state.charType
+        let charName = this.state.charName
+        let charInt = this.state.charInt
+  
+        if (charType && typeOptions.filter(n => n.voucher_class === charType) > 0) {
+          typeOptions.forEach(n => {
+            if (n.voucher_class === charType) {
+              charName = n.voucher_char
+              charInt = n.voucher_char_int + 1
+            }
+          })
+        } else {
+          charType = typeOptions[0].voucher_class
+          charName = typeOptions[0].voucher_char
+          charInt = typeOptions[0].voucher_char_int + 1
+        }
+
+        this.setState({
+          typeOptions: typeOptions,
+          charType: charType,
+          charName: charName,
+          charInt: charInt
+        })
+      }
+
+      let msg = window.GLOB.CacheVoucher.get(config.uuid) || {}
+      msg.currency = res.currency || []
+
+      window.GLOB.CacheVoucher.set(config.uuid, msg)
+    })
+  }
+
+  resetAttachList = (vals) => {
+    const { attachlist } = this.state
+    let num = this.state.attachments
+    
+    if (num) {
+      num = num + (vals.length - attachlist.length)
+    } else {
+      num = vals.length
+    }
+
+    if (num < 0) {
+      num = 0
+    }
+
+    this.setState({status: 'change', attachlist: vals, attachments: num})
   }
 
   triggermore = () => {
@@ -596,61 +1018,145 @@
   }
 
   triggerclose = () => {
+    const { config, status } = this.state
 
+    if (status === 'change') {
+      confirm({
+        content: '鍐呭宸插彉鏇达紝纭畾瑕佸叧闂悧锛�',
+        onOk() {
+          MKEmitter.emit('closeTabView', config.$pageId)
+        },
+        onCancel() {}
+      })
+    } else {
+      MKEmitter.emit('closeTabView', config.$pageId)
+    }
+  }
+
+  triggerTempLoad = (id) => {
+    const { book } = this.state
+
+    if (!book) return
+
+    let param = {
+      func: 's_get_fcc_voucher_temp',
+      BID: book.id,
+      ID: id
+    }
+
+    Api.genericInterface(param).then(res => {
+      if (!res.status) {
+        notification.warning({
+          top: 92,
+          message: res.message,
+          duration: 5
+        })
+        return
+      }
+
+      let data = []
+      if (res.voucher) {
+        data = res.voucher.map(line => {
+          line.uuid = line.subject_id || ''
+
+          if (line.direction_type === 'credit') {
+            line.credit = line.net_amount || 0
+            line.debit = ''
+          } else {
+            line.debit = line.net_amount || 0
+            line.credit = ''
+          }
+
+          line.unitratio = line.foreign_unitratio || 0
+          line.exratecode = line.foreign_exratecode || ''
+          line.exratename = line.foreign_exratename || ''
+          line.local_currency = line.local_exratecode || ''
+          line.foreign_currency_type = line.foreign_type || ''
+
+          if (line.sup) {
+            line.supAccounts = line.sup.map(cell => {
+              cell.uuid = cell.sup_id
+              return cell
+            })
+            delete line.sup
+          }
+
+          return line
+        })
+      }
+
+      this.setState({
+        data: data,
+        tbdata: fromJS(data).toJS(),
+        status: 'change'
+      })
+    })
   }
 
   render() {
-    const { type, status, loading, config, typeOptions, charType, charInt, data, vouDate, username, remark, remarkVisible, attachments, title } = this.state
+    const { type, status, loading, config, orgcode, orgname, typeOptions, tempTypes, charType, charName, charInt, data, vouDate, username, remark, attachments, title, attachlist, tempTypeClass } = this.state
 
     return (
       <div className="menu-voucher-wrap" style={config.style}>
         {type === 'createVoucher' ? <div className="voucher-header">
           <Button className="add-background header-btn" disabled={status === 'empty'} onClick={() => this.triggersave('add')}>淇濆瓨骞舵柊澧�</Button>
           <Button className="add-background header-btn" disabled={status === 'empty' || status === 'saved'} onClick={() => this.triggersave()}>淇濆瓨</Button>
-          <Button className="print-background header-btn" disabled={status !== 'saved'} onClick={this.triggerprint}>鎵撳嵃</Button>
-          <Button className="out-background header-btn" onClick={this.triggermore}>鏇村</Button>
+          <PrintVoucher ID={config.uuid + 'print'} data={data} orgname={orgname} vouDate={vouDate} charName={charName} charInt={charInt} attachments={attachments} disabled={status !== 'saved'}/>
+          <Dropdown overlay={<div className="mk-voucher-dropdown-wrap">
+            <SaveAsTemp tempTypes={tempTypes} onChange={this.triggerTempsave}/>
+            <div className="split"></div>
+            <LoadFromTemp tempTypes={tempTypes} onChange={this.triggerTempLoad}/>
+          </div>} trigger={['click']}>
+            <Button className="out-background header-btn" onClick={this.triggermore}>鏇村</Button>
+          </Dropdown>
         </div> : null}
         {type === 'checkVoucher' ? <div className="voucher-header">
           <Button className="add-background header-btn" disabled={status === 'empty' || status === 'saved'} onClick={() => this.triggersave()}>淇濆瓨</Button>
-          <Button className="print-background header-btn" disabled={status !== 'saved'} onClick={this.triggerprint}>鎵撳嵃</Button>
+          <PrintVoucher ID={config.uuid + 'print'} data={data} orgname={orgname} vouDate={vouDate} charName={charName} charInt={charInt} attachments={attachments} disabled={status !== 'saved'}/>
           <Button className="out-background header-btn" onClick={this.triggerclose}>鍏抽棴</Button>
         </div> : null}
-        <div className="voucher-body">
+        <div className="voucher-body" style={{padding: `0px ${config.wrap.space || 0}px`}}>
           {type === 'createVoucher' || type === 'checkVoucher' ? <div className="pre-wrap">
             <div className="voucher-code">
-              <Select value={charType} dropdownClassName="mk-vcode-dropdown" onChange={(val, option) => this.setState({charType: val, charName: option.props.charName, charInt: option.props.charint})}>
+              <Select value={charType} dropdownClassName="mk-vcode-dropdown" onChange={(val, option) => this.setState({status: 'change', charType: val, charName: option.props.charName, charInt: option.props.charint})}>
                 {typeOptions.map(option =>
                   <Select.Option key={option.voucher_char_int} value={option.voucher_class} charName={option.voucher_char} charint={option.voucher_char_int}>{option.voucher_char}</Select.Option>
                 )}
               </Select>
-              <InputNumber precision={0} min={1} value={charInt} autoComplete="off" onChange={(val) => this.setState({charInt: val})}/> 鍙�
+              <InputNumber precision={0} min={1} value={charInt} autoComplete="off" onChange={(val) => this.setState({status: 'change', charInt: val})}/> 鍙�
             </div>
             <div className="voucher-date">
-              鏃ユ湡锛�<DatePicker value={vouDate} onChange={(val) => this.setState({vouDate: val})}/>
+              鏃ユ湡锛�<DatePicker value={vouDate} onChange={this.changeVouDate}/>
             </div>
             <div className="voucher-text">
-              <Input value={title} placeholder="鍑瘉鏂囨湰" autoComplete="off" onChange={(e) => this.setState({title: e.target.value})}/>
+              <Input value={title} placeholder="鍑瘉鏂囨湰" autoComplete="off" onChange={(e) => this.setState({status: 'change', title: e.target.value})}/>
             </div>
             <div className="voucher-affix">
               闄勫崟鎹� <InputNumber precision={0} value={attachments || 0} autoComplete="off" onChange={this.changeAttach}/> 寮�
-              <Button type="link" className="" onClick={this.triggerprint}>闄勪欢</Button>
-              <Button type="link" className="" onClick={this.triggerprint}>澶囨敞</Button>
+              <ResetAttach config={config} orgcode={orgcode} voucherCode={this.state.voucherCode} attachlist={attachlist} onChange={this.resetAttachList}/>
+              <ResetRemark remark={remark} ID={config.uuid + 'remark'} onChange={(val) => this.setState({status: 'change', remark: val})}/>
+            </div>
+          </div> : null}
+          {type === 'createTemp' || type === 'checkTemp' ? <div className="pre-temp-wrap">
+            <div className="temp-text">
+              <span>妯℃澘鍚嶇О锛�</span><Input value={title} placeholder="妯℃澘鍚嶇О" autoComplete="off" onChange={(e) => this.setState({title: e.target.value})}/>
+            </div>
+            <div className="temp-text">
+              <span>妯℃澘绫诲瀷锛�</span>
+              <Select value={tempTypeClass} dropdownClassName="mk-vcode-dropdown" onChange={(val, option) => this.setState({tempTypeClass: val, tempTypeName: option.props.children})}>
+                {tempTypes.map(option =>
+                  <Select.Option key={option.data_code} value={option.data_code}>{option.data_name}</Select.Option>
+                )}
+              </Select>
+            </div>
+            <div className="temp-action">
+              <Button className="add-background header-btn" onClick={() => this.triggerTempsave()}>淇濆瓨</Button>
+              <Button className="out-background header-btn" onClick={this.triggerclose}>鍏抽棴</Button>
             </div>
           </div> : null}
           <VoucherTable config={config} loading={loading} data={data} onChange={this.dataChange}/>
         </div>
-        <div className="user">鍒跺崟浜猴細{username}</div>
-        <Modal
-          title="澶囨敞"
-          visible={remarkVisible}
-          width={700}
-          maskClosable={false}
-          onOk={this.remarkSubmit}
-          onCancel={() => { this.setState({ remarkVisible: false })}}
-          destroyOnClose
-        >
-          <TextArea id={config.uuid + 'remark'} defaultValue={remark} rows={6}/>
-        </Modal>
+        {type === 'createVoucher' || type === 'checkVoucher' ? <div className="user">鍒跺崟浜猴細{username}</div> : null}
       </div>
     )
   }

--
Gitblit v1.8.0