ttk-app-core
Version:
enterprise develop framework
807 lines (719 loc) • 29.8 kB
JavaScript
import React from 'react'
import {action as MetaAction, AppLoader} from 'edf-meta-engine'
import {List, fromJS} from 'immutable'
import moment from 'moment'
import config from './config'
import {consts} from 'edf-consts'
import utils from 'edf-utils'
import {FormDecorator} from 'edf-component'
class action {
constructor(option) {
this.metaAction = option.metaAction
this.voucherAction = option.voucherAction
this.config = config.current
this.webapi = this.config.webapi
}
onInit = ({component, injections}) => {
this.voucherAction.onInit({component, injections})
this.component = component
this.injections = injections
if (this.component.props.setOkListener) {
this.component.props.setOkListener(this.onOk)
}
injections.reduce('init', {
isPop: this.component.props.isPop
})
this.load()
}
load = async () => {
if(this.component.props.option){
//如果缓存的orgId和当前的orgId不一致,则清除缓存的账户信息
let proOrgId = localStorage.getItem('orgId'),
currentOrgId = this.metaAction.context.get("currentOrg").id
if(proOrgId != currentOrgId){
localStorage.removeItem('Income')
localStorage.removeItem('taxIncome')
localStorage.removeItem('cleanIncome')
localStorage.removeItem('orgId')
}
let ids = this.component.props.option.id+''
let option = {id: ids}
//this.metaAction.sf('data.other.loading', true)
let res = await this.webapi.asset.assetDisposeInit(option)
//this.metaAction.sf('data.other.loading', false)
if(this.component.props.response) res.form=this.component.props.response
if(this.component.props.detail) res.detail=true
if(res){
res.option = this.component.props.option
if(!this.component.props.detail){
res.diposeTime = this.getMaxTime(res)
}
this.injections.reduce('load', res, this.getNextMonth)
}
}
}
//获取三个时间最大值
getMaxTime = (res) => {
let maxVoucherPeriod = res.maxVoucherPeriod,
closeMonth = res.closeMonth,
currentOrg = this.metaAction.context.get("currentOrg"),
startTime = this.getDate(currentOrg)
//只有启用时间的时候
if(!maxVoucherPeriod && !closeMonth){
this.getStartTime()
return startTime
//只有启用时间和审核时间的时候
}else if(!closeMonth){
maxVoucherPeriod = this.getBeginUseTime(maxVoucherPeriod)
//启用时间最大
if(moment(startTime)>moment(maxVoucherPeriod)){
this.getStartTime()
return startTime
}
//审核时间最大
this.getMaxVoucherPeriodTitle(res)
return maxVoucherPeriod
//只有启用时间和月结时间的时候
}else if(!maxVoucherPeriod){
closeMonth = this.getBeginUseTime(closeMonth)
//closeMonth = this.getNextMonth(closeMonth)
//启用时间最大
if(moment(startTime)>moment(closeMonth)){
this.getStartTime()
return startTime
}
//月结时间最大
this.getCloseMonthTitle(res)
this.metaAction.sf('data.other.isCloseMonth', true)
return closeMonth
//启用时间、审核时间和月结时间都有的时候
}else{
maxVoucherPeriod = this.getBeginUseTime(maxVoucherPeriod)
closeMonth = this.getBeginUseTime(closeMonth)
//closeMonth = this.getNextMonth(closeMonth)
//启用时间最大
if(moment(startTime)>moment(maxVoucherPeriod) && moment(startTime)>moment(closeMonth)) {
this.getStartTime()
return startTime
}else if(moment(closeMonth)>=moment(startTime) && moment(closeMonth)>=moment(maxVoucherPeriod)){
//月结时间最大
this.getCloseMonthTitle(res)
this.metaAction.sf('data.other.isCloseMonth', true)
return closeMonth
}else if(moment(maxVoucherPeriod)>=moment(startTime) && moment(maxVoucherPeriod)>=moment(closeMonth)){
//审核时间最大
this.getMaxVoucherPeriodTitle(res)
return maxVoucherPeriod
}
}
}
//启用时间
getStartTime = () => {
this.injections.reduce('getStartTime', true)
}
//审核时间最大提示
getMaxVoucherPeriodTitle = (res) => {
let maxVoucherPeriod = res.maxVoucherPeriod,
system = res.systemDate,
asset2 = consts.ASSETPROPERTY_0002
system = `${system.split('-')[0]}-${system.split('-')[1]}`
maxVoucherPeriod = this.getBeginUseTime(maxVoucherPeriod)
let year = maxVoucherPeriod.split('-')[0], month = maxVoucherPeriod.split('-')[1]
if(res.option.assetPropertyId == asset2 && moment(maxVoucherPeriod) >= moment(system)){
this.metaAction.toast('warning', `${year}年${month}月凭证已经审核,不可处置资产`)
}
}
//月结时间最大提示
getCloseMonthTitle = (res) => {
let closeMonth = res.closeMonth,
system = res.systemDate,
asset1 = consts.ASSETPROPERTY_0001,
asset2 = consts.ASSETPROPERTY_0002
system = `${system.split('-')[0]}-${system.split('-')[1]}`
closeMonth = this.getBeginUseTime(closeMonth)
//closeMonth = this.getNextMonth(closeMonth)
let year = closeMonth.split('-')[0], month = closeMonth.split('-')[1]
if(moment(closeMonth) >= moment(system)){
// this.metaAction.toast('warning', `${year}年${month}月已经月结,不能保存凭证`)
this.metaAction.toast('warning', `${year}年${month}月已经月结,不可处置资产`)
if(res.option.assetPropertyId == asset1 || (res.option.assetPropertyId == asset2 && moment(closeMonth) > moment(system))){
this.metaAction.sf('data.other.isView', true)
let btn = document.getElementsByClassName('ant-modal-footer')[0]
btn = btn.getElementsByClassName('ant-btn-primary')[0]
btn.style.backgroundColor = '#f5f5f5'
btn.style.color = '#c2c2c2'
btn.style.border = '#fff'
btn.onmouseover = () => {
btn.style.border = '#fff'
btn.style.color = '#c2c2c2'
btn.style.cursor = 'not-allowed'
}
}
}
}
//处置日期控制
assetDisposeDateChange = async (path, value) => {
let form = this.metaAction.gf('data.form').toJS(),
valueStr = this.metaAction.momentToString(value, 'YYYY-MM'),
assetDisposeDate = this.metaAction.momentToString(form.assetDisposeDate, 'YYYY-MM')
this.fieldChange(path, value)
if(valueStr != assetDisposeDate){
let initData = this.metaAction.gf('data.other.initData').toJS(), option = {
endBuyData: this.metaAction.momentToString(value, 'YYYY-MM'),
cardId: initData.cardId
}
let res = await this.webapi.asset.query(option)
this.injections.reduce('assetDisposeDateChange', res)
}
}
//收入支出tab切换
assetDisposeTabChange = (path, value) => {
this.injections.reduce('assetDisposeTabChange', path, value)
}
//获取累计折旧
getAccuDepreciation = (initData, isData) => {
if(initData){
if(isData) return this.addThousandsPosition((initData.accuDepreciation).toFixed(2))
return (initData.accuDepreciation).toFixed(2)
/*if(initData.accuDepreciation && initData.initAccuDepreciation){
return initData.accuDepreciation + initData.initAccuDepreciation
}else if(!initData.accuDepreciation){
return initData.initAccuDepreciation
}else if(!initData.initAccuDepreciation){
return initData.accuDepreciation
}else{
return 0
}*/
}
return (0).toFixed(2)
}
//获取净值
getRevenue = (initData, isData) => {
if(initData){
let accuDepreciation = this.getAccuDepreciation(initData)
if(initData.origValue !== undefined){
if(isData) return this.addThousandsPosition((initData.origValue - accuDepreciation).toFixed(2))
return (initData.origValue - accuDepreciation).toFixed(2)
}
return (0).toFixed(2)
}
}
// 出售收入、保险理赔
getSaleTaxIncome = (path, name, value) => {
this.fieldChange(path, '')
if(!this.checkIsNumber(value)) value = 0
if(value < 0) value = 0
let form = this.metaAction.gf('data.form').toJS()
if(name == 'saleTaxIncome'){
this.getInitInvoiceType(form.saleTaxIncome, name, value)
this.getInitAccount(form.saleTaxIncome, name, value)
}else if(name == 'insuranceClaims'){
this.getInitAccount(form.insuranceClaims, name, value)
}
this.fieldChange(path, value)
this.saleIncome(name, value)
}
//清理费用
getCleaningTaxUp = (path, name, value) => {
this.fieldChange(path, '')
if(!this.checkIsNumber(value)) value = 0
if(value < 0) value = 0
let form = this.metaAction.gf('data.form').toJS()
this.getInitAccount(form.cleaningTaxUp, name, value)
this.getInitInvoiceType(form.cleaningTaxUp, name, value)
this.fieldChange(path, value)
this.cleaningUp(name, value)
}
checkIsNumber = (value) => {
let reg = /^(\-|\+)?\d+(\.\d+)?$/
if(value && !reg.test(value)){
return false
}
return true
}
//获取初始化账户
getInitAccount = (oldValue, name, value) => {
let path
if(name == 'saleTaxIncome'){
path = 'data.form.receivableAccount'
}else if(name == 'cleaningTaxUp'){
path = 'data.form.expenditureAccount'
}else if(name == 'insuranceClaims'){
path = 'data.form.insuranceClaimsAccount'
}
if(!oldValue && value>0){
let value,
baBankAccountSale = this.metaAction.gf('data.other.baBankAccountSale').toJS(),
baBankAccountExpend = this.metaAction.gf('data.other.baBankAccountExpend').toJS()
const isUse = baBankAccountSale.find((item) => {
if(localStorage.getItem('taxIncome')){
if(item.id == JSON.parse(localStorage.getItem('taxIncome')).id) return true
}
})
const isUseing = baBankAccountSale.find((item) => {
if(localStorage.getItem('Income')){
if(item.id == JSON.parse(localStorage.getItem('Income')).id) return true
}
})
const isCleanUseing = baBankAccountExpend.find((item) => {
if(localStorage.getItem('cleanIncome')){
if(item.id == JSON.parse(localStorage.getItem('cleanIncome')).id) return true
}
})
if(name == 'insuranceClaims' && localStorage.getItem('taxIncome') && isUse){
this.metaAction.sf(path, fromJS(JSON.parse(localStorage.getItem('taxIncome'))))
}else if(name == 'saleTaxIncome' && localStorage.getItem('Income') && isUseing){
this.metaAction.sf(path, fromJS(JSON.parse(localStorage.getItem('Income'))))
}else if(name == 'cleaningTaxUp' && localStorage.getItem('cleanIncome') && isCleanUseing){
this.metaAction.sf(path, fromJS(JSON.parse(localStorage.getItem('cleanIncome'))))
}else{
this.metaAction.sf(path, fromJS(''))
}
}else if(oldValue > 0 && !value){
this.metaAction.sf(path, fromJS(''))
}
}
//获取初始化票据类型
getInitInvoiceType = (oldValue, name, value) => {
if(!oldValue && value>0){
let value,
invoiceType = this.metaAction.gf('data.other.invoiceTypeIncome') && this.metaAction.gf('data.other.invoiceTypeIncome').toJS(),
generalTaxPayer = consts.VATTAXPAYER_generalTaxPayer,
smallScaleTaxPayer = consts.VATTAXPAYER_smallScaleTaxPayer
//一般纳税人
if (this.metaAction.context.get("currentOrg").vatTaxpayer == generalTaxPayer) {
value = invoiceType[1]
//小规模纳税人
} else if (this.metaAction.context.get("currentOrg").vatTaxpayer == smallScaleTaxPayer) {
value = invoiceType[0]
}
if(name == 'saleTaxIncome'){
this.metaAction.sf(`data.form.incomeInvoiceType`, fromJS(value))
}else if(name == 'cleaningTaxUp'){
this.getIsAuthentication(value)
this.injections.reduce('getUninvoiced', value)
this.metaAction.sf(`data.form.invoiceType`, fromJS(value))
}
}else if(oldValue > 0 && !value){
if(name == 'saleTaxIncome'){
this.metaAction.sf(`data.form.incomeInvoiceType`, fromJS(''))
}else if(name == 'cleaningTaxUp'){
this.getIsAuthentication(value)
this.injections.reduce('getUninvoiced', value)
this.metaAction.sf(`data.form.invoiceType`, fromJS(''))
}
}
}
//出售收入项计算
saleIncome = (name, value) => {
let saleTaxIncome = this.metaAction.gf('data.form.saleTaxIncome'),
taxRate = this.metaAction.gf('data.form.taxRate'),
insuranceClaims = this.metaAction.gf('data.form.insuranceClaims'),
expenditureTotal = this.metaAction.gf('data.form.expenditureTotal'),
initData = this.metaAction.gf('data.other.initData') && this.metaAction.gf('data.other.initData').toJS(),
cleaningTaxUp = this.metaAction.gf('data.form.cleaningTaxUp'),
type,saleTax,rate
saleTaxIncome = saleTaxIncome ? saleTaxIncome : 0
taxRate = taxRate ? (taxRate.size ? taxRate.toJS() : taxRate) : 0
insuranceClaims = insuranceClaims ? insuranceClaims : 0
expenditureTotal = expenditureTotal ? expenditureTotal : 0 //支出合计(不含税)
cleaningTaxUp = cleaningTaxUp ? cleaningTaxUp : 0
if(name == 'saleTaxIncome') saleTaxIncome = value //出售收入(含税)
if(name == 'taxRate') {
taxRate = value //税率
}
if(name == 'insuranceClaims') insuranceClaims = value //保险理赔
if(name == 'out') type = value
if(taxRate.taxRate !== undefined) rate = taxRate.taxRate
//if(!initData.accuDepreciation) initData.accuDepreciation = 0
let accuDepreciation = this.getAccuDepreciation(initData)
let tax = Number(saleTaxIncome/(1+rate)*rate), //税额
saleIncome = Number(saleTaxIncome-tax), //出售收入(不含税)
incomeTotal = Number(saleIncome+insuranceClaims), //收入合计(不含税)
netProfitLosse
this.getNetProfitLosse('in', type,incomeTotal,expenditureTotal,cleaningTaxUp,initData.origValue,accuDepreciation,tax,saleIncome,taxRate)
}
//清理费用项计算
cleaningUp = (name, value) => {
let cleaningTaxUp = this.metaAction.gf('data.form.cleaningTaxUp'),
inputTaxRate = this.metaAction.gf('data.form.inputTaxRate'),
incomeTotal = this.metaAction.gf('data.form.incomeTotal'),
initData = this.metaAction.gf('data.other.initData').toJS(),
type,tax,rate
cleaningTaxUp = cleaningTaxUp ? cleaningTaxUp : 0
inputTaxRate = inputTaxRate ? (inputTaxRate.size ? inputTaxRate.toJS() :inputTaxRate) : 0 //税率
incomeTotal = incomeTotal ? incomeTotal : 0 //收入合计(不含税)
if(name == 'cleaningTaxUp') cleaningTaxUp = value //清理费用(含税)
if(name == 'inputTaxRate') {
inputTaxRate = value //税率
}
if(name == 'out') type = value
if(inputTaxRate.taxRate !== undefined) rate = inputTaxRate.taxRate
//if(!initData.accuDepreciation) initData.accuDepreciation = 0
let accuDepreciation = this.getAccuDepreciation(initData)
let inputTax = Number(cleaningTaxUp/(1+rate)*rate), //税额
cleaningUp = Number(cleaningTaxUp-inputTax), //清理费用(不含税)
expenditureTotal = Number(cleaningUp), //支出合计(不含税)
netProfitLosse
this.getNetProfitLosse('out',type,incomeTotal,expenditureTotal, cleaningTaxUp,initData.origValue,accuDepreciation,inputTax,cleaningUp,inputTaxRate)
}
//判断 处置净损益时的 支出合计(含税还是不含税)
getNetProfitLosse = (v, type,incomeTotal,expenditureTotal,cleaningTaxUp,origValue,accuDepreciation,inputTax,cleaningUp,rate) => {
let noTax, //含税/不含税清理费用
isGeneralTaxPayer, //一般纳税人
isTax, //一般计税法
isInvoiceTypeIn, //收入发票
isInvoiceTypeOut, //清理发票
invoiceTypeIn, //修改票据类型时
invoiceTypeOut, //修改票据类型时
netProfitLosse,taxRate,inputTaxRate,
general = consts.TAXRATETYPE_general
let generalTaxPayer = consts.VATTAXPAYER_generalTaxPayer,
saleTaxIncome = this.metaAction.gf('data.form.saleTaxIncome') // 销售收入
saleTaxIncome = saleTaxIncome ? saleTaxIncome : 0
if(v == 'in'){
taxRate = rate
inputTaxRate = this.metaAction.gf('data.form.inputTaxRate').size ? this.metaAction.gf('data.form.inputTaxRate').toJS() : this.metaAction.gf('data.form.inputTaxRate')
}
if(v == 'out'){
inputTaxRate = rate
taxRate = this.metaAction.gf('data.form.taxRate').size ? this.metaAction.gf('data.form.taxRate').toJS() : this.metaAction.gf('data.form.taxRate')
}
if(taxRate && taxRate.type == general && inputTaxRate && inputTaxRate.type == general) isTax = true
if(v == 'in' || saleTaxIncome || v == 'out') {
invoiceTypeIn = this.metaAction.gf('data.form.incomeInvoiceType')
if(invoiceTypeIn){
invoiceTypeIn = invoiceTypeIn.size ? invoiceTypeIn.toJS() : invoiceTypeIn
type ? invoiceTypeIn = type : invoiceTypeIn
if(invoiceTypeIn && invoiceTypeIn.name == '增值税专用发票') isInvoiceTypeIn = true
}
invoiceTypeOut = this.metaAction.gf('data.form.invoiceType')
if(invoiceTypeOut){
invoiceTypeOut = invoiceTypeOut.size ? invoiceTypeOut.toJS() : invoiceTypeOut
type ? invoiceTypeOut = type : invoiceTypeOut
if(invoiceTypeOut && invoiceTypeOut.name == '增值税专用发票') isInvoiceTypeOut = true
}
}
if(this.metaAction.context.get("currentOrg").vatTaxpayer == generalTaxPayer) isGeneralTaxPayer = true
if(isGeneralTaxPayer && isTax && isInvoiceTypeIn && isInvoiceTypeOut) noTax = true
if(isGeneralTaxPayer && isInvoiceTypeOut && isTax && !incomeTotal) noTax = true
if(v == 'out'){
if(noTax){ //不含税
netProfitLosse = Number(incomeTotal-expenditureTotal-(origValue-accuDepreciation))
}else{ //含税
netProfitLosse = Number(incomeTotal-cleaningTaxUp-(origValue-accuDepreciation))
}
this.injections.reduce('cleaningUp', {inputTax, cleaningUp, expenditureTotal, netProfitLosse})
}else if(v == 'in'){
if(noTax){ //不含税
netProfitLosse = Number(incomeTotal-expenditureTotal-(origValue-accuDepreciation))
}else{ //含税
netProfitLosse = Number(incomeTotal-cleaningTaxUp-(origValue-accuDepreciation))
}
this.injections.reduce('saleIncome', {inputTax, cleaningUp, incomeTotal, netProfitLosse})
}
}
//清理费用票据类型切换
invoiceTypeChange = (path, value) => {
this.taxChange('data.form.inputTaxRate',value)
this.fieldChange(path, value)
this.cleaningUp('out',value)
this.getIsAuthentication(value)
this.injections.reduce('getUninvoiced', value)
}
// 出售收入票据类型切换
incomeInvoiceChange = (path, value) => {
this.taxChange('data.form.taxRate',value)
this.fieldChange(path, value)
this.saleIncome('in', value)
}
// 票据类型切换带出税率
taxChange = (path, v) => {
let taxRate = this.metaAction.gf('data.other.taxRate').toJS()
let form = this.metaAction.gf('data.form').toJS()
let rate, typeP = consts.INVOICETYPE_generalVATInvoice, //普通发票
generalTaxPayer = consts.VATTAXPAYER_generalTaxPayer,
smallScaleTaxPayer = consts.VATTAXPAYER_smallScaleTaxPayer,
uninvoiced = consts.INVOICETYPE_uninvoiced,
asset1 = consts.ASSETPROPERTY_0001,
asset2 = consts.ASSETPROPERTY_0002
if(path == 'data.form.inputTaxRate'){
if(v.id == uninvoiced){ // 未开具发票
taxRate.map(item => {
if(item.name == '0%' ) return this.metaAction.sf(path, fromJS(item))
})
}else{
taxRate.map(item => {
if(item.name == '3%' ) return this.metaAction.sf(path, fromJS(item))
})
}
}
if(this.metaAction.context.get("currentOrg").vatTaxpayer == generalTaxPayer && path == 'data.form.taxRate'){
// 一般纳税人
if(form.assetPropertyId == asset1 && form.assetClassId == 35){
if(v.id == typeP) {
rate = '5%'
}else{
rate = '10%'
}
}else if(form.assetPropertyId == asset1 && form.assetClassId != 35){
if(v.id == typeP) {
rate = '3%'
}else{
rate = '16%'
}
}else if(form.assetPropertyId == asset2 && form.assetClassId == 19){
if(v.id == typeP) {
rate = '5%'
}else{
rate = '10%'
}
}else if(form.assetPropertyId == asset2 && form.assetClassId != 19){
if(v.id == typeP) {
rate = '3%'
}else{
rate = '6%'
}
}
}else if(this.metaAction.context.get("currentOrg").vatTaxpayer == smallScaleTaxPayer && path == 'data.form.taxRate'){
//小规模
if(form.assetPropertyId == asset1 && form.assetClassId == 46){
rate = '5%'
}else if(form.assetPropertyId == asset2 && form.assetClassId == 24){
rate = '5%'
}else{
rate = '3%'
}
}
taxRate.map(item => {
if(item.name == rate ) {
this.metaAction.sf('data.form.taxRate', fromJS(item))
}
})
}
//获取认证显隐
getIsAuthentication = (value) => {
let generalTaxPayer = consts.VATTAXPAYER_generalTaxPayer,
smallScaleTaxPayer = consts.VATTAXPAYER_smallScaleTaxPayer
if (this.metaAction.context.get("currentOrg").vatTaxpayer == generalTaxPayer) {
this.injections.reduce('getIsAuthentication', value)
}
}
//处置类型切换
assetDisposeType = (path,value) => {
this.fieldChange(path, value)
this.injections.reduce('assetDisposeTypeChange', value)
}
//认证按钮切换, 认证按钮为true, 认证月份为当前会计期间的月份, 为false时认证月份为空
authenticationChange = (path, value) => {
if(value === undefined) return
let systemDate = this.metaAction.gf('data.systemDate')
let month = utils.moment.stringToMoment(systemDate).format('YYYY-MM')
if(!value) month = ""
this.metaAction.sf('data.form.identifyPeriod', month)
this.fieldChange(path, value)
}
//处置日期不可选控制
disabledDisposeDate = (current) => {
let isDeprEnd = this.metaAction.gf('data.isDeprEnd'),
diposeTime = this.metaAction.gf('data.other.diposeTime'),
initData = this.metaAction.gf('data.other.initData') && this.metaAction.gf('data.other.initData').toJS(),
asset1 = consts.ASSETPROPERTY_0001,
isCloseMonth = this.metaAction.gf('data.other.isCloseMonth'),
isStartTime = this.metaAction.gf('data.other.isStartTime')
//没有全部完成计提
if(!isDeprEnd){
let systemDate = this.metaAction.gf('data.systemDate'),
currentMonth = this.getNextMonth(utils.moment.stringToMoment(systemDate).format('YYYY-MM')),
nextMonth = this.getNextMonth(currentMonth)
//固定资产
if(initData.assetPropertyId == asset1){
let startTime = diposeTime
if(isCloseMonth) startTime = this.getNextMonth(diposeTime)
return current && (current > moment(currentMonth) || moment(startTime) > current)
//无形资产
}else{
let startTime = this.getNextMonth(diposeTime)
if(isStartTime) startTime = diposeTime
return current && (current > moment(nextMonth) || moment(startTime) > current)
}
//已经全部完成计提
}else{
return current && moment(diposeTime) > current
}
}
getBeginUseTime = (beginUseTime) => {
beginUseTime = beginUseTime.toString()
let year = beginUseTime.substring(0,4), mounth = beginUseTime.substring(4,6)
return `${year}-${mounth}-01`
}
onOk = async () => {
let isView = this.metaAction.gf('data.other.isView')
if(isView) {
if(this.component.props.detail) return true
return false
}else{
return await this.save()
}
}
save = async () => {
let form = this.metaAction.gf('data.form').toJS(), checkArr = [],
initData = this.metaAction.gf('data.other.initData').toJS()
if(form.saleTaxIncome>0){
checkArr.push({
path: 'data.form.receivableAccount', value: form.receivableAccount
})
}
if(form.insuranceClaims>0){
checkArr.push({
path: 'data.form.insuranceClaimsAccount', value: form.insuranceClaimsAccount
})
}
if(form.expenditureTotal>0){
checkArr.push({
path: 'data.form.expenditureAccount', value: form.expenditureAccount
})
}
const ok = await this.voucherAction.check(checkArr, this.check)
if (!ok) {
this.metaAction.toast('warning', '请按页面提示修改信息后才可提交')
return false
}
let option = {
"id": this.component.props.option && this.component.props.option.id,
"assetDisposeTypeId": form.assetDisposeType.id,
"disposeDate": form.assetDisposeDate,
"cardId": initData.cardId
}
if(form.memo) option.memo = form.memo
//出售收入
if(form.saleTaxIncome ||form.insuranceClaims) {
option.glAssetSalesIncomeDto = {
"taxRateId": form.taxRate && form.taxRate.id,
"deductTax":0,
"taxRate": form.taxRate && form.taxRate.name,
}
if(!form.saleTaxIncome) option.glAssetSalesIncomeDto = {}
if(form.saleTaxIncome) option.glAssetSalesIncomeDto.taxInclusiveAmount = form.saleTaxIncome.toFixed(2)
if(form.insuranceClaims) option.glAssetSalesIncomeDto.claimsMny = form.insuranceClaims.toFixed(2)
if(form.incomeInvoiceType) option.glAssetSalesIncomeDto.invoiceType = form.incomeInvoiceType.id
if(form.tax) option.glAssetSalesIncomeDto.tax = form.tax.toFixed(2)
if(form.receivableAccount) option.glAssetSalesIncomeDto.bankAccountId = form.receivableAccount.id
if(form.insuranceClaimsAccount) option.glAssetSalesIncomeDto.claimBankAccountId = form.insuranceClaimsAccount.id
if(form.saleIncome) option.glAssetSalesIncomeDto.amount = form.saleIncome.toFixed(2)
}
//清理费用
if(form.cleaningTaxUp) {
let isAuthentication = this.metaAction.gf('data.other.isAuthentication')
option.glAssetExpensesDto = {
"taxRateId": form.inputTaxRate && form.inputTaxRate.id,
"deductTax":0,
"taxRate": form.inputTaxRate && form.inputTaxRate.name,
}
option.glAssetExpensesDto.taxInclusiveAmount = form.cleaningTaxUp.toFixed(2)
if(form.invoiceType) option.glAssetExpensesDto.invoiceType = form.invoiceType.id
if(form.inputTax) option.glAssetExpensesDto.tax = form.inputTax.toFixed(2)
if(form.expenditureAccount) option.glAssetExpensesDto.bankAccountId = form.expenditureAccount.id
if(form.cleaningUp) option.glAssetExpensesDto.amount = form.cleaningUp.toFixed(2)
if(form.identifyPeriod && isAuthentication) {
option.glAssetExpensesDto.isIdentify = 1
option.glAssetExpensesDto.identifyPeriod = form.identifyPeriod
}
}
let isOk = this.metaAction.gf('data.other.isOk')
if(!isOk) {
return false
}
const ret = await this.metaAction.modal('confirm', {
title: '提醒',
content: '请确认需要处置资产吗?'
})
if(ret){
let data = {
fiAssetDisposeDtoList: [option],
isReturnValue: true
}
if(!isOk) {
return false
}
this.metaAction.sf('data.other.isOk', false)
this.metaAction.sf('data.other.loading', true)
let response = await this.webapi.asset.assetDispose(data)
this.metaAction.sf('data.other.loading', false)
this.metaAction.sf('data.other.isOk', true)
if (response && response.result == false) {
this.metaAction.toast('error', response.error.message)
return false
} else {
this.metaAction.toast('success', '处置成功')
if(form.receivableAccount) this.saveAccount('Income',JSON.stringify(form.receivableAccount))
if(form.insuranceClaimsAccount) this.saveAccount('taxIncome',JSON.stringify(form.insuranceClaimsAccount))
if(form.expenditureAccount) this.saveAccount('cleanIncome',JSON.stringify(form.expenditureAccount))
return response
}
}else{
return false
}
}
check = async (option) => {
if (!option || !option.path)
return
if (option.path == 'data.form.receivableAccount') {
return { errorPath: 'data.other.error.receivableAccount', message: option.value ? '' : '请选择出售收入账户' }
}
else if (option.path == 'data.form.expenditureAccount') {
return { errorPath: 'data.other.error.expenditureAccount', message: option.value ? '' : '请选择支出账户' }
}
else if (option.path == 'data.form.insuranceClaimsAccount') {
return { errorPath: 'data.other.error.insuranceClaimsAccount', message: option.value ? '' : '请选择保险理赔账户' }
}
else if (option.path == 'data.form.memo') {
return { errorPath: 'data.other.error.memo', message: option.value.length>200 ? '备注不能超过200个字' : '' }
}
}
//获取下一个月
getNextMonth = (date) => {
var arr = date.split('-')
var year = arr[0]; //获取当前日期的年份
var month = arr[1]; //获取当前日期的月份
var year2 = year;
var month2 = parseInt(month) + 1
if (month2 == 13) {
year2 = parseInt(year2) + 1
month2 = 1
}
if (month2 < 10) {
month2 = '0' + month2
}
var t2 = year2 + '-' + month2
return t2;
}
fieldChange = (path, value) => {
// 出售收入票据类型切换
this.voucherAction.fieldChange(path, value, this.check)
}
saveAccount = (name,value) => {
localStorage.setItem(name, value)
localStorage.setItem('orgId', this.metaAction.context.get("currentOrg").id)
}
//格式化启用时间
getDate = (currentOrg) => {
let enabledYear = Number(currentOrg.enabledYear),
enabledMonth = Number(currentOrg.enabledMonth)
enabledMonth = enabledMonth>9 ? enabledMonth : `0${enabledMonth}`
return `${enabledYear}-${enabledMonth}-01`
}
//添加千分位
addThousandsPosition = (value) => {
let regex = /(\d{1,3})(?=(\d{3})+(?:\.))/g
return value.replace(regex, "$1,")
}
}
export default function creator(option) {
const metaAction = new MetaAction(option),
voucherAction = FormDecorator.actionCreator({...option, metaAction}),
o = new action({...option, metaAction, voucherAction}),
ret = {...metaAction, ...voucherAction, ...o}
metaAction.config({metaHandlers: ret})
return ret
}