You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
366 lines
15 KiB
366 lines
15 KiB
<template>
|
|
<!-- 表单弹窗:添加/修改 -->
|
|
<BasicForm
|
|
ref="formRef"
|
|
:isShowButton="false"
|
|
:isShowReduceButton="false"
|
|
:isShowReduceButtonSelection="false"
|
|
:rules="CustomerSaleInvoiceMainRules"
|
|
:formAllSchemas="CustomerSaleInvoiceMain.allSchemas"
|
|
:tableAllSchemas="CustomerSaleInvoiceDetail.allSchemas"
|
|
:tableFormRules="CustomerSaleInvoiceDetailRules"
|
|
:tableData="tableData"
|
|
:showTypeList="showTypeList"
|
|
:apiUpdate="CustomerSaleInvoiceMainApi.updateCustomerSaleInvoiceMain"
|
|
:apiCreate="CustomerSaleInvoiceMainApi.createCustomerSaleInvoiceMain"
|
|
:isBusiness="true"
|
|
@handleAddTable="handleAddTable"
|
|
@handleDeleteTable="handleDeleteTable"
|
|
@tableSelectionDelete="tableSelectionDelete"
|
|
@searchTableSuccess="searchTableSuccess"
|
|
@submitForm="submitForm"
|
|
@inputNumberChange="inputNumberChange"
|
|
@onChange="onChange"
|
|
:sumFormDataByForm="
|
|
(
|
|
formRef,
|
|
formModel,
|
|
tableData,
|
|
formType,
|
|
originFormModel,
|
|
updateOriginFormModel,
|
|
sumFormDataHandle1
|
|
) => {
|
|
const {
|
|
taxRate = 0,
|
|
amount = 0,
|
|
taxAmount = 0,
|
|
beforeTaxAmount = 0,
|
|
totalTaxAmount = 0,
|
|
discountAmount1 = 0,
|
|
beforeTaxDiffAmount = 0,
|
|
taxAmountDiff = 0,
|
|
rebateTax = 0,
|
|
moldUntaxedAmount=0,
|
|
materialsUntaxedAmount=0,
|
|
alreadyMoldUntaxedAmount=0
|
|
} = formModel
|
|
// 2、系统税额:每条数据的合同价格X可开票数量,计算结果取两位小数之后*税率的计算结果,再保留2位。所有子表数据再求和
|
|
if (formType == 'update') {
|
|
// 编辑
|
|
if (taxRate != originFormModel.taxRate) {
|
|
if (originFormModel) {
|
|
sumFormDataHandle1()
|
|
}
|
|
updateOriginFormModel(formModel)
|
|
}
|
|
// 2.主数据税额 mainTaxAmount = 未税金额*税率/100 保留两位小数
|
|
let mainTaxAmount = Number(beforeTaxAmount*taxRate*0.01).toFixed(2)
|
|
formRef.value.setValues({
|
|
// 主数据税额
|
|
taxAmount:mainTaxAmount,
|
|
// 主数据价税合计金额:mainAdTaxAmount =未税金额+税额
|
|
adTaxAmount: (beforeTaxAmount + parseFloat(taxAmount)).toFixed(2),
|
|
})
|
|
}
|
|
}
|
|
"
|
|
:sumFormDataByTableCustom="
|
|
async (formRef, formModel, tableData) => {
|
|
const { taxRate = 0,moldUntaxedAmount=0 } = formModel
|
|
// 1、主数据未税金额 mainBeforeTaxAmount : 所有明细行的(品番数量 * 合计单价),先保留两位小数再求和
|
|
let mainBeforeTaxAmount = tableData.reduce((prev, item) =>prev + Number((Number(item['sumPrice'])*Number(item['qty'])).toFixed(2)),0).toFixed(2)
|
|
// 2、主数据税额 mainTaxAmount = 所有明细行的(未税金额 * 税率),先保留两位小数再求和
|
|
let mainTaxAmount = tableData.reduce((prev, item) =>prev + Number((Number(item['beforeTaxAmount'])*Number(taxRate)*0.01).toFixed(2)),0).toFixed(2)
|
|
// 5、主数据材料未税金额 materialsUntaxedAmount : 所有明细行销售单价*数量保留两位小数之后累加
|
|
let materialsUntaxedAmount = tableData.reduce((prev, item) =>prev + Number((Number(item['price'])*Number(item['qty'])).toFixed(2)),0).toFixed(2)
|
|
// 6、主数据材料税额 materialsTaxAmount = 各明细行的(未税金额 * 税率),先保留两位小数再求和
|
|
let materialsTaxAmount =tableData.reduce((prev, item) =>prev + Number((Number(item['beforeTaxAmount'])*Number(taxRate)*0.01).toFixed(2)),0).toFixed(2)
|
|
// 7、已分摊模具未税金额=各明细行的(品番数量 * 模具分摊单价),先保留两位小数再求和
|
|
let alreadyMoldUntaxedAmount = tableData.reduce((prev, item) =>prev + Number((Number(item['allocationPrice'])*Number(item['qty'])).toFixed(2)),0).toFixed(2)
|
|
// 8、主数据已分摊模具税额 alreadyMoldTaxAmount ==各明细行的(模具分摊单价 *数量 * 税率),先保留两位小数再求和
|
|
let alreadyMoldTaxAmount = tableData.reduce((prev, item) => prev + Number((Number((Number(item['allocationPrice']) * Number(item['qty'])).toFixed(2)) * Number(taxRate) * 0.01).toFixed(2)), 0).toFixed(2)
|
|
const allAmountNum = await getAllocationAmount(formModel.customerStatementNumber)
|
|
|
|
const sumObject = {
|
|
// 主数据未税金额
|
|
beforeTaxAmount:mainBeforeTaxAmount,
|
|
// 主数据税额
|
|
taxAmount:mainTaxAmount,
|
|
// 主数据价税合计金额:mainAdTaxAmount =未税金额+税额
|
|
adTaxAmount: (Number(mainBeforeTaxAmount) + Number(mainTaxAmount)).toFixed(2),
|
|
// 主数据模具未税金额
|
|
moldUntaxedAmount:allAmountNum.moldUntaxedAmount,
|
|
// 主数据模具税额
|
|
moldTaxAmount:allAmountNum.moldTaxAmount,
|
|
// 主数据模具含税金额
|
|
moldTaxTotal:allAmountNum.moldTaxTotal,
|
|
// 主数据-材料未税金额
|
|
materialsUntaxedAmount: materialsUntaxedAmount,
|
|
// 主数据-材料金额
|
|
materialsTaxAmount: materialsTaxAmount,
|
|
// 主数据-材料含税金额= 材料未税金额+材料税额
|
|
materialsTaxTotal: (Number(materialsUntaxedAmount) + Number(materialsTaxAmount)).toFixed(2),
|
|
// 主数据已分摊模具未税金额
|
|
alreadyMoldUntaxedAmount: alreadyMoldUntaxedAmount,
|
|
// 主数据已分摊模具税额
|
|
alreadyMoldTaxAmount: alreadyMoldTaxAmount,
|
|
// 主数据模具未税差异=已分摊模具未税金额-模具未税金额
|
|
moldTaxAmountDiff: (Number(alreadyMoldUntaxedAmount) - Number(allAmountNum.moldUntaxedAmount)).toFixed(2),
|
|
// 主数据已分摊价税合计=已分摊模具未税金额+已分摊模具税额
|
|
alreadyMoldTaxTotal: (Number(alreadyMoldUntaxedAmount) + Number(alreadyMoldTaxAmount)).toFixed(2),
|
|
}
|
|
formRef.value.setValues(sumObject)
|
|
}
|
|
"
|
|
/>
|
|
</template>
|
|
<script setup lang="ts">
|
|
import { CustomerSaleInvoiceMain,CustomerSaleInvoiceMainRules,CustomerSaleInvoiceDetailRules,CustomerSaleInvoiceDetail} from './customerSaleInvoiceRequestMain.data'
|
|
import * as CustomerSaleInvoiceMainApi from '@/api/wms/customerSaleInvoiceMain'
|
|
import * as CustomerStatementDetailApi from '@/api/wms/customerStatementDetail'
|
|
import Decimal from "decimal.js"
|
|
// 传递给父类
|
|
const emit = defineEmits([
|
|
'buttonBaseClick','getList'
|
|
])
|
|
const message = useMessage() // 消息弹窗
|
|
const { t } = useI18n() // 国际化
|
|
|
|
/** 添加/修改操作 */
|
|
const formRef = ref()
|
|
const openForm =async (type: string, row?: any) => {
|
|
CustomerSaleInvoiceMain.allSchemas.formSchema.forEach((item) => {
|
|
if(item.field == 'customerStatementNumber'){
|
|
item.componentProps.disabled = type=='update'
|
|
item.componentProps.isSearchList = type!='update'
|
|
item.componentProps.enterSearch = type!='update'
|
|
|
|
}
|
|
})
|
|
tableData.value = [] // 重置明细数据
|
|
formRef.value.open(type, row)
|
|
}
|
|
|
|
const openFormTable =async (type: string, row?: any, list?:any) => {
|
|
row['customerStatementNumber'] = row['number'] // 客户对账单
|
|
CustomerSaleInvoiceMain.allSchemas.formSchema.forEach((item) => {
|
|
if(item.field == 'customerStatementNumber'){
|
|
item.componentProps.disabled = true
|
|
item.componentProps.isSearchList = false
|
|
item.componentProps.enterSearch = false
|
|
|
|
}
|
|
})
|
|
tableData.value = list // 重置明细数据
|
|
formRef.value.open(type, row)
|
|
nextTick(async()=>{
|
|
initTableDataPrice()
|
|
})
|
|
}
|
|
const showTypeList = ref([])
|
|
const onChange =async (field, cur, formRef)=>{
|
|
if(field == 'taxRate'){
|
|
// 税额:taxAmount 未税价格*税率/100,四舍五入保留2位小数
|
|
tableData.value.forEach(item=>{
|
|
item['taxAmount'] = (item['beforeTaxAmount'] * cur)/100 //含税金额
|
|
// 含税金额 = 未税价格+税额,四舍五入保留2位小数
|
|
item['afterTaxAmount'] = item['beforeTaxAmount'] + item['taxAmount']
|
|
})
|
|
} else if (field == 'invoiceType') {
|
|
showTypeList.value = cur
|
|
// if (cur == '补给品') {
|
|
// tableData.value =
|
|
// }
|
|
}
|
|
}
|
|
const inputNumberChange = (field, index, row, val) => {
|
|
|
|
|
|
// 模具分摊单价 默认从模具分摊对账单带出,未税金额修改后重新计算,等于未税金额/数量-销售单价
|
|
row['allocationPrice'] = row['beforeTaxAmount']/row['qty'] - row['price']
|
|
|
|
// 合计单价 = 销售单价 + 模具分摊单价
|
|
row['sumPrice'] = (row['price'] + row['allocationPrice']).toFixed(11)
|
|
|
|
// 税额:taxAmount 未税价格*税率/100,四舍五入保留2位小数
|
|
row['taxAmount'] = (row['beforeTaxAmount'] * formRef.value.formRef.formModel['taxRate'])/100 //含税金额
|
|
|
|
// 含税金额 = 未税价格+税额,四舍五入保留2位小数
|
|
row['afterTaxAmount'] = row['beforeTaxAmount'] + row['taxAmount']
|
|
|
|
|
|
}
|
|
const flag = ref(false)
|
|
// 主子数据 提交
|
|
const submitForm = async (formType, submitData) => {
|
|
let data = {...submitData}
|
|
if(data.masterId){
|
|
data.id = data.masterId
|
|
}
|
|
data.subList = tableData.value // 拼接子表数据参数
|
|
data.subList.forEach(item=>{
|
|
item.toWarehouseCode = data.toWarehouseCode
|
|
item.toLocationCode = data.toLocationCode
|
|
})
|
|
// 判断是否重复物料
|
|
// let isExist = false
|
|
// tableData.value.forEach(item => {
|
|
// let rs = tableData.value.filter(filterItem => (filterItem.itemCode == item.itemCode))
|
|
// if(rs.length > 1) isExist = true
|
|
// })
|
|
// if (isExist) {
|
|
// formRef.value.formLoading = false
|
|
// return message.warning('品番重复')
|
|
// }
|
|
data.subList.forEach(obj => {
|
|
if(obj.qty == 0){
|
|
message.error(`数量不能为0!`)
|
|
flag.value = true
|
|
return;
|
|
}
|
|
})
|
|
if(flag.value){
|
|
return
|
|
}
|
|
var isHave =CustomerSaleInvoiceMain.allSchemas.formSchema.some(function (item) {
|
|
return item.field === 'beginTime' || item.field === 'endTime';
|
|
});
|
|
if(isHave){
|
|
if(data.beginTime && data.endTime && data.beginTime >=data.expireTime){
|
|
message.error('结束时间要大于开始时间')
|
|
return;
|
|
}
|
|
}
|
|
if(!data.beginTime)data.beginTime = null;
|
|
if(!data.planDate)data.planDate = null;
|
|
if(!data.endTime)data.endTime = null;
|
|
formRef.value.formLoading = true
|
|
try {
|
|
if (formType === 'create') {
|
|
await CustomerSaleInvoiceMainApi.createCustomerSaleInvoiceMain(data)
|
|
message.success(t('common.createSuccess'))
|
|
} else {
|
|
await CustomerSaleInvoiceMainApi.updateCustomerSaleInvoiceMain(data)
|
|
message.success(t('common.updateSuccess'))
|
|
}
|
|
formRef.value.dialogVisible = false
|
|
// 刷新当前列表
|
|
|
|
if (formType === 'create') {
|
|
emit('getList', 'refresh')
|
|
|
|
}else{
|
|
emit('buttonBaseClick', 'refresh')
|
|
}
|
|
} finally {
|
|
formRef.value.formLoading = false
|
|
}
|
|
}
|
|
// 查询页面返回
|
|
const searchTableSuccess = (formField, searchField, val, formRef, type, row ) => {
|
|
nextTick(async () => {
|
|
if (type == 'tableForm') {
|
|
if(formField == 'itemCode') {
|
|
let itemCodes = val.filter(item=>tableData.value.find(item1=>item1['itemCode']==item['itemCode']))
|
|
if(itemCodes.length>0){
|
|
itemCodes = itemCodes.map(item=>(item['itemCode']))
|
|
message.warning(`物料${itemCodes.join(',')}已经存在`)
|
|
}
|
|
val = val.filter(item=>!tableData.value.find(item1=>item1['itemCode']==item['itemCode']))
|
|
if(val.length==0) return
|
|
val.forEach(item=>{
|
|
const newRow = JSON.parse(JSON.stringify({...tableFormKeys,...item}))
|
|
row[formField] = item[searchField]
|
|
newRow['uom'] = item['customerUom']
|
|
newRow['id'] = item['id']
|
|
tableData.value.push(newRow)
|
|
})
|
|
}else{
|
|
row[formField] = val[0][searchField]
|
|
}
|
|
// if(formField == 'itemCode') {
|
|
// row['uom'] = val[0]['customerUom']
|
|
// }
|
|
// 明细查询页赋值
|
|
|
|
} else {
|
|
const setV = {}
|
|
if(formField == 'customerStatementNumber') {
|
|
//客户对账单
|
|
setV['customerCode'] = val[0]['customerCode']
|
|
setV['customerName'] = val[0]['customerName']
|
|
|
|
let detailRes = await CustomerStatementDetailApi.pageInvoice(val[0].id)
|
|
tableData.value = detailRes.list && detailRes.list.length > 0 ? detailRes.list : []
|
|
initTableDataPrice()
|
|
// CustomerStatementDetailApi.getCustomerStatementDetailPage({
|
|
// pageNo:1,
|
|
// pageSize: 50000,
|
|
// masterId:val[0]['id']
|
|
// }).then((res) => {
|
|
// console.log(55,res)
|
|
// tableData.value = res.list && res.list.length > 0 ?res.list : []
|
|
// initTableDataPrice()
|
|
|
|
// })
|
|
// tableData.value = []
|
|
|
|
}
|
|
setV[formField] = val[0][searchField]
|
|
formRef.setValues(setV)
|
|
}
|
|
})
|
|
}
|
|
|
|
// 初始化计算子表
|
|
const initTableDataPrice = ()=>{
|
|
tableData.value.forEach(item=>{
|
|
item['sumPrice'] = (item['price'] + item['allocationPrice']).toFixed(11)
|
|
// 未税金额 默认等于数量*合计单价,可修改,必填,最多可输入2位小数
|
|
item['beforeTaxAmount'] = Number(new Decimal(Number(item['sumPrice'])).mul(new Decimal(item['qty'])).toNumber().toFixed(2))
|
|
|
|
// 税额:taxAmount 未税价格*税率/100,四舍五入保留2位小数
|
|
item['taxAmount'] = (item['beforeTaxAmount'] * formRef.value.formRef.formModel['taxRate'])/100 //含税金额
|
|
|
|
// 含税金额 未税价格+税额,四舍五入保留2位小数
|
|
item['afterTaxAmount'] = item['beforeTaxAmount'] + item['taxAmount'] //含税金额
|
|
// 模具分摊单价如果没有值的话显示0
|
|
item['allocationPrice'] = item['allocationPrice'] || 0
|
|
})
|
|
|
|
}
|
|
|
|
|
|
const tableData = ref([])
|
|
const tableFormKeys = {}
|
|
CustomerSaleInvoiceDetail.allSchemas.tableFormColumns.forEach(item => {
|
|
tableFormKeys[item.field] = item.default ? item.default : ''
|
|
})
|
|
// 添加明细
|
|
const handleAddTable = () => {
|
|
tableData.value.push(JSON.parse(JSON.stringify(tableFormKeys)))
|
|
}
|
|
// 删除明细
|
|
const handleDeleteTable = (item, index) => {
|
|
let itemIndex = tableData.value.indexOf(item)
|
|
if(itemIndex>-1){
|
|
tableData.value.splice(itemIndex, 1)
|
|
}
|
|
}
|
|
const tableSelectionDelete = (selection) => {
|
|
tableData.value = tableData.value.filter(item => !selection.includes(item))
|
|
}
|
|
// 选择税率获取模具未税金额,模具税额和模具含税金额
|
|
const getAllocationAmount = async (number) => {
|
|
const res = await CustomerSaleInvoiceMainApi.getAllocationAmount(number, formRef.value.formRef.formModel.taxRate)
|
|
return {
|
|
moldUntaxedAmount:res.moldUntaxedAmount.toFixed(2),//模具未税金额(模具分摊对账单中各明细行的模具费用之和,先保留两位小数后再相加)
|
|
moldTaxAmount:res.moldTaxAmount.toFixed(2),//模具税额(所关联的模具分摊对账单中所有明细行的(模具未税金额 * 税率),先保留两位小数再求和)
|
|
moldTaxTotal:res.moldTaxTotal.toFixed(2),//模具含税金额(模具未税金额+模具税额)
|
|
}
|
|
}
|
|
defineExpose({openForm,openFormTable})
|
|
</script>
|
|
<style lang="scss" scoped>
|
|
</style>
|