UNPKG

ttk-app-core

Version:
397 lines (356 loc) 17.9 kB
import {Map, List, fromJS} from 'immutable' import {reducer as MetaReducer} from 'edf-meta-engine' import config from './config' import moment from 'moment' import {consts} from 'edf-consts' import {getInitState} from './data' import utils from 'edf-utils' class reducer { constructor(option) { this.metaReducer = option.metaReducer } init = (state, option) => { let initData = getInitState(option) initData.data.consts = { ASSETTYPE_fixedAssets: consts.ASSETPROPERTY_0001, ASSETTYPE_immaterialAssets: consts.ASSETPROPERTY_0002, ASSETTYPE_longtermPrepaidExpenses: consts.ASSETPROPERTY_0003, } return this.metaReducer.init(state, initData) } load = (state, res, getNextMonth) => { let initData = res.option state = this.metaReducer.sf(state, 'data.other.initData', fromJS(res.option)) state = this.metaReducer.sf(state, 'data.form.memo', fromJS(initData && ("处置资产:" + initData.name))) state = this.metaReducer.sf(state, 'data.form.assetPropertyId', fromJS(initData.assetPropertyId)) state = this.metaReducer.sf(state, 'data.form.assetClassId', fromJS(initData.assetClassId)) if(res.assetDisposeType){ state = this.metaReducer.sf(state, `data.other.assetDisposeType`, fromJS(res.assetDisposeType.enumDetails)) if(res.assetDisposeType.enumDetails.length){ state = this.metaReducer.sf(state, `data.form.assetDisposeType`, fromJS(res.assetDisposeType.enumDetails[0])) } } if(res.isDeprEnd !== undefined) state = this.metaReducer.sf(state, `data.other.isDeprEnd`, fromJS(res.isDeprEnd)) if(res.diposeTime) state = this.metaReducer.sf(state, `data.other.diposeTime`, fromJS(res.diposeTime)) if(res.systemDate && res.diposeTime){ //开始使用时间,上下文中存在会计期间的时候取上下文的,不存在的时候取系统时间 let contextDate = res.systemDate, currentOrg = this.metaReducer.context.get("currentOrg"), dateRange, currentMonth = getNextMonth(res.systemDate), nextMonth = getNextMonth(currentMonth), asset1 = consts.ASSETPROPERTY_0001, isCloseMonth = this.metaReducer.gf(state, 'data.other.isCloseMonth'), isStartTime = this.metaReducer.gf(state, 'data.other.isStartTime'), diposeTime = utils.moment.stringToMoment(res.diposeTime).format('YYYY-MM'), nextDiposeTime = utils.moment.stringToMoment(getNextMonth(res.diposeTime)).format('YYYY-MM') if(!res.isDeprEnd){ //固定资产 if(initData.assetPropertyId == asset1){ let startTime = diposeTime if(isCloseMonth) startTime = nextDiposeTime dateRange = moment(currentOrg.periodDate)>=moment(startTime) && moment(currentOrg.periodDate)<moment(currentMonth) //无形资产 }else{ let startTime = nextDiposeTime if(isStartTime) startTime = diposeTime dateRange = moment(currentOrg.periodDate)>=moment(startTime) && moment(currentOrg.periodDate)<moment(nextMonth) } }else{ dateRange = moment(currentOrg.periodDate)>=moment(diposeTime) } if(currentOrg.periodDate && dateRange){ contextDate = utils.moment.momentToString(moment(currentOrg.periodDate).endOf('month'), 'YYYY-MM-DD') } state = this.metaReducer.sf(state, 'data.form.assetDisposeDate', fromJS(contextDate)) state = this.metaReducer.sf(state, 'data.form.identifyPeriod', fromJS(res.systemDate)) state = this.metaReducer.sf(state, 'data.systemDate', fromJS(res.systemDate)) } if(res.taxRate && initData){ state = this.metaReducer.sf(state, `data.other.taxRate`, fromJS(res.taxRate)) let clearTaxRate = res.taxRate.filter(item => (item.id == 0 || item.id == 3 || item.id == 6 || item.id == 10 ||item.id == 11)), general = consts.TAXRATETYPE_general clearTaxRate.map(item => { if(item.id == 3) item.type = general }) state = this.metaReducer.sf(state, `data.other.clearTaxRate`, fromJS(clearTaxRate)) //选择分类带出税率 let rate, taxRate = res.taxRate || [], assetPropertyId = initData.assetPropertyId, assetClassId = initData.assetClassId, ASSETTYPE_fixedAssets = consts.ASSETPROPERTY_0001, ASSETTYPE_immaterialAssets = consts.ASSETPROPERTY_0002, ASSETTYPE_longtermPrepaidExpenses = consts.ASSETPROPERTY_0003, generalTaxPayer = consts.VATTAXPAYER_generalTaxPayer, smallScaleTaxPayer = consts.VATTAXPAYER_smallScaleTaxPayer //一般模纳税人 if (this.metaReducer.context.get("currentOrg").vatTaxpayer == generalTaxPayer) { //固定资产 if(assetPropertyId == ASSETTYPE_fixedAssets){ if(assetClassId == 35){ rate = '10%' }else{ rate = '16%' } //无形资产 }else if(assetPropertyId == ASSETTYPE_immaterialAssets){ if(assetClassId == 19){ rate = '10%' }else{ rate = '6%' } } //小规模纳税人 } else if (this.metaReducer.context.get("currentOrg").vatTaxpayer == smallScaleTaxPayer) { //固定资产和无形资产 if(assetPropertyId == ASSETTYPE_fixedAssets || assetPropertyId == ASSETTYPE_immaterialAssets){ if(assetClassId == 46 || assetClassId == 24){ rate = '5%' }else{ rate = '3%' } } } taxRate.map(item => { if(rate == item.name) state = this.metaReducer.sf(state, 'data.form.taxRate', fromJS(item)) if(item.name == '3%') state = this.metaReducer.sf(state, 'data.form.inputTaxRate', fromJS(item)) }) let isIntangibleAssets = true if(assetPropertyId != ASSETTYPE_immaterialAssets) isIntangibleAssets = false state = this.metaReducer.sf(state, 'data.other.isIntangibleAssets', isIntangibleAssets) } if(res.baBankAccount){ let baBankAccountSale = [], baBankAccountExpend = [] res.baBankAccount.map( (item, index) => { if(item.name != '暂未付款') baBankAccountSale.push(item) if(item.name !='暂未收款') baBankAccountExpend.push(item) }) state = this.metaReducer.sf(state, `data.other.baBankAccountSale`, fromJS(baBankAccountSale)) state = this.metaReducer.sf(state, `data.other.baBankAccountExpend`, fromJS(baBankAccountExpend)) } if(res.invoiceType){ /*let invoiceTypeIncome = [], invoiceTypeOut = [] res.invoiceType.enumDetails.map( item => { if(item.name != '无票支出' ) invoiceTypeIncome.push(item) if(item.name != '无票收入') invoiceTypeOut.push(item) })*/ state = this.metaReducer.sf(state, `data.other.invoiceTypeIncome`, fromJS(res.invoiceType.enumDetails)) state = this.metaReducer.sf(state, `data.other.invoiceTypeOut`, fromJS(res.invoiceType.enumDetails)) } if(res.detail){ state = this.metaReducer.sf(state, `data.other.isView`, true) let form = this.metaReducer.gf(state, `data.form`).toJS(), other = this.metaReducer.gf(state, `data.other`).toJS(), incomeTotal = 0, expenditureTotal = 0, generalTaxPayer = consts.VATTAXPAYER_generalTaxPayer, smallScaleTaxPayer = consts.VATTAXPAYER_smallScaleTaxPayer if(initData.disposeDate) form.assetDisposeDate = initData.disposeDate if(initData.assetReduceTypeName){ form.assetDisposeType = other.assetDisposeType.filter(o => o.name == initData.assetReduceTypeName)[0] } if(initData.memo) form.memo = initData.memo if(res.form && res.form.length){ let clearFee = res.form.filter(item => item.isClearFee), income = res.form.filter(item => !item.isClearFee) if(res.invoiceType && clearFee.length){ let invoiceType = res.invoiceType.enumDetails if(clearFee[0].billType == res.invoiceType.enumDetails[1].id && (this.metaReducer.context.get("currentOrg").vatTaxpayer == generalTaxPayer)){ state = this.metaReducer.sf(state, `data.other.isAuthentication`, true) } } //销售收入回显值 if(income.length){ let incomeObj = income[0] if(incomeObj.amount) form.saleIncome = incomeObj.amount if(incomeObj.taxInclusiveAmount) form.saleTaxIncome = incomeObj.taxInclusiveAmount if(incomeObj.tax) form.tax = incomeObj.tax if(incomeObj.claimsMny) form.insuranceClaims = incomeObj.claimsMny if(incomeObj.amount || incomeObj.claimsMny) { if(!incomeObj.amount) incomeObj.amount = 0 if(!incomeObj.claimsMny) incomeObj.claimsMny = 0 form.incomeTotal = Number(incomeObj.amount) + Number(incomeObj.claimsMny) incomeTotal = form.incomeTotal } if(incomeObj.billType) form.incomeInvoiceType = other.invoiceTypeIncome.filter(o => o.id == incomeObj.billType)[0] if(incomeObj.taxRateId !== undefined) form.taxRate = other.taxRate.filter(o => o.id == incomeObj.taxRateId)[0] //if(incomeObj.bankAccountId) form.receivableAccount = other.baBankAccountSale.filter(o => o.id == incomeObj.bankAccountId)[0] //if(incomeObj.claimBankAccountId) form.insuranceClaimsAccount = other.baBankAccountSale.filter(o => o.id == incomeObj.claimBankAccountId)[0] if(incomeObj.bankAccountId) form.receivableAccount = {id: incomeObj.bankAccountName, name: incomeObj.bankAccountName} if(incomeObj.claimBankAccountId) form.insuranceClaimsAccount = {id: incomeObj.claimBankAccountName, name: incomeObj.claimBankAccountName} }else{ form.taxRate = '' } //清理费用回显值 if(clearFee.length){ let clearFeeObj = clearFee[0], uninvoiced = consts.INVOICETYPE_uninvoiced if(clearFeeObj.identifyPeriod) form.identifyPeriod = clearFeeObj.identifyPeriod if(!clearFeeObj.identifyPeriod) { form.isAuthentication = false form.identifyPeriod = '' } if(clearFeeObj.amount) form.cleaningUp = clearFeeObj.amount if(clearFeeObj.taxInclusiveAmount) form.cleaningTaxUp = clearFeeObj.taxInclusiveAmount if(clearFeeObj.tax) form.inputTax = clearFeeObj.tax if(clearFeeObj.amount) { form.expenditureTotal = clearFeeObj.amount expenditureTotal = form.expenditureTotal } if(clearFeeObj.billType) { if(clearFeeObj.billType == uninvoiced){ state = this.metaReducer.sf(state, 'data.other.taxRateVisible', false) state = this.metaReducer.sf(state, 'data.other.inputTaxVisible', false) } form.invoiceType = other.invoiceTypeOut.filter(o => o.id == clearFeeObj.billType)[0] } if(clearFeeObj.taxRateId !== undefined) form.inputTaxRate = other.clearTaxRate.filter(o => o.id == clearFeeObj.taxRateId)[0] //f(clearFeeObj.bankAccountId) form.expenditureAccount = other.baBankAccountExpend.filter(o => o.id == clearFeeObj.bankAccountId)[0] if(clearFeeObj.bankAccountId) form.expenditureAccount = {id: clearFeeObj.bankAccountName, name: clearFeeObj.bankAccountName} }else{ form.isAuthentication = false form.inputTaxRate = '' } } if(initData.origValue){ let isGeneralTaxPayer,isTax,isInvoiceTypeIn,isInvoiceTypeOut,noTax, incomeForm = res.form.filter(item => !item.isClearFee), outForm = res.form.filter(item => item.isClearFee),taxRate1,taxRate2, general = consts.TAXRATETYPE_general, specialVATInvoice = consts.INVOICETYPE_specialVATInvoice if(this.metaReducer.context.get("currentOrg").vatTaxpayer == generalTaxPayer) isGeneralTaxPayer = true if(incomeForm) incomeForm = incomeForm[0] if(outForm) outForm = outForm[0] if(res.form && res.form.length){ if(incomeForm && outForm){ other.taxRate.map(item => { if(item.id == incomeForm.taxRateId && item.type == general) taxRate1 = true }) other.clearTaxRate.map(item => { if(item.id == outForm.taxRateId && item.type == general) taxRate2 = true }) }else if(incomeForm && !outForm){ other.taxRate.map(item => { if(item.id == incomeForm.taxRateId && item.type == general) taxRate1 = true }) }else if(!incomeForm && outForm){ other.clearTaxRate.map(item => { if(item.id == outForm.taxRateId && item.type == general) taxRate2 = true }) } if(taxRate1 == true && taxRate2 == true) isTax = true if(incomeForm && incomeForm.billType){ if(incomeForm.billType == specialVATInvoice) isInvoiceTypeIn = true } if(outForm && outForm.billType){ if(outForm.billType == specialVATInvoice) isInvoiceTypeOut = true } } if(isGeneralTaxPayer && isTax && isInvoiceTypeIn && isInvoiceTypeOut) noTax = true if(isGeneralTaxPayer && isInvoiceTypeOut && isTax && !incomeForm) noTax = true let outFormFormAmount = outForm ? outForm.amount : 0, outFormTaxInclusiveAmount = outForm ? outForm.taxInclusiveAmount : 0, incomeFormAmount = incomeForm ? incomeForm.amount : 0, incomeFormClaimsMny = incomeForm ? incomeForm.claimsMny : 0 if(noTax){ form.netProfitLosse = Number(incomeFormAmount + incomeFormClaimsMny-(initData.origValue - initData.accuDepreciation) - outFormFormAmount) }else{ form.netProfitLosse = Number(incomeFormAmount + incomeFormClaimsMny-(initData.origValue - initData.accuDepreciation) - outFormTaxInclusiveAmount) } } state = this.metaReducer.sf(state, 'data.form', fromJS(form)) }else{ if(initData.origValue){ if(!initData.accuDepreciation) initData.accuDepreciation = 0 let netProfitLosse = 0-(initData.origValue-initData.accuDepreciation) state = this.metaReducer.sf(state, 'data.form.netProfitLosse', fromJS(netProfitLosse)) } } return state } //处置日期切换更新折旧摊销 assetDisposeDateChange = (state, res) => { if(res.assetList && res.assetList.length && res.assetList[0].queryPeriodDepreciation !== undefined){ let queryPeriodDepreciation = res.assetList[0].queryPeriodDepreciation state = this.metaReducer.sf(state, 'data.other.initData.accuDepreciation', fromJS(queryPeriodDepreciation)) }else if(res.assetList){ state = this.metaReducer.sf(state, 'data.other.initData.accuDepreciation', fromJS(0)) } return state } saleIncome = (state, option) => { state = this.metaReducer.sf(state, 'data.form.tax', fromJS(option.inputTax)) state = this.metaReducer.sf(state, 'data.form.saleIncome', fromJS(option.cleaningUp)) state = this.metaReducer.sf(state, 'data.form.incomeTotal', fromJS(option.incomeTotal)) state = this.metaReducer.sf(state, 'data.form.netProfitLosse', fromJS(option.netProfitLosse)) return state } cleaningUp = (state, option) => { state = this.metaReducer.sf(state, 'data.form.inputTax', fromJS(option.inputTax)) state = this.metaReducer.sf(state, 'data.form.cleaningUp', fromJS(option.cleaningUp)) state = this.metaReducer.sf(state, 'data.form.expenditureTotal', fromJS(option.expenditureTotal)) state = this.metaReducer.sf(state, 'data.form.netProfitLosse', fromJS(option.netProfitLosse)) return state } assetDisposeTypeChange = (state, value) => { let assetDisposeType = this.metaReducer.gf(state, `data.other.assetDisposeType`), ASSETTYPE_fixedAssets = consts.ASSETPROPERTY_0001, initData = this.metaReducer.gf(state, 'data.other.initData').toJS(), form = this.metaReducer.gf(state, 'data.form').toJS(), netProfitLosse = 0 if(assetDisposeType && value.id == assetDisposeType.toJS()[1].id){ //debugger //处置类型切换时处置净损益计算 if(initData.origValue === undefined) initData.origValue = 0 if(initData.accuDepreciation === undefined) initData.accuDepreciation = 0 //固定资产有支出或者保险理赔的情况下 if(initData.assetPropertyId == ASSETTYPE_fixedAssets && (form.cleaningTaxUp || form.insuranceClaims)){ netProfitLosse = form.netProfitLosse-(form.saleTaxIncome-form.tax) //固定资产没有支出和无形资产 }else{ netProfitLosse = 0-(initData.origValue-initData.accuDepreciation) } state = this.metaReducer.sf(state, 'data.form.tax', '') state = this.metaReducer.sf(state, 'data.form.saleIncome', '') state = this.metaReducer.sf(state, 'data.form.incomeTotal', '') state = this.metaReducer.sf(state, 'data.form.saleTaxIncome', '') state = this.metaReducer.sf(state, 'data.form.receivableAccount', '') state = this.metaReducer.sf(state, 'data.form.incomeInvoiceType', '') state = this.metaReducer.sf(state, 'data.form.netProfitLosse', netProfitLosse) } return state } getIsAuthentication = (state, value) => { let specialVATInvoice = consts.INVOICETYPE_specialVATInvoice if(value && value.id && value.id == specialVATInvoice){ state = this.metaReducer.sf(state, 'data.other.isAuthentication', true) }else{ state = this.metaReducer.sf(state, 'data.other.isAuthentication', false) } return state } //清理费用 未开具发票,隐藏税率税额 getUninvoiced = (state, value) => { let uninvoiced = consts.INVOICETYPE_uninvoiced if(value && value.id && value.id == uninvoiced){ state = this.metaReducer.sf(state, 'data.other.taxRateVisible', false) state = this.metaReducer.sf(state, 'data.other.inputTaxVisible', false) }else{ state = this.metaReducer.sf(state, 'data.other.taxRateVisible', true) state = this.metaReducer.sf(state, 'data.other.inputTaxVisible', true) } return state } assetDisposeTabChange = (state, path, value) => { state = this.metaReducer.sf(state, 'data.other.tabType', value) state = this.metaReducer.sf(state, path, value+'') return state } //启用时间最大的时候 getStartTime = (state, value) => { state = this.metaReducer.sf(state, 'data.other.isStartTime', value) return state } } export default function creator(option) { const metaReducer = new MetaReducer(option), o = new reducer({...option, metaReducer}) return {...metaReducer, ...o} }