From efd5a2bc936029be5c24b7eb12e26ec03182b55b Mon Sep 17 00:00:00 2001 From: ZhangAo Date: Mon, 3 Aug 2026 17:33:57 +0800 Subject: [PATCH] 20260803173356 --- .../cw/assistance/daily-expenses/detail.vue | 238 ++++ .../cw/assistance/daily-expenses/list.vue | 490 +++++++ .../cw/assistance/payment-account/detail.vue | 220 ++++ .../cw/assistance/payment-account/list.vue | 485 +++++++ code/新建文件夹/cw/components/hldlg.vue | 204 +++ code/新建文件夹/cw/components/index.js | 999 +++++++++++++++ code/新建文件夹/cw/components/link.vue | 234 ++++ code/新建文件夹/cw/yf/detailbill.vue | 1082 ++++++++++++++++ code/新建文件夹/cw/yf/detailfkd.vue | 1128 +++++++++++++++++ code/新建文件夹/cw/yf/detailinvoice.vue | 975 ++++++++++++++ code/新建文件夹/cw/yf/list.vue | 829 ++++++++++++ code/新建文件夹/cw/yf/listbill.vue | 664 ++++++++++ code/新建文件夹/cw/yf/listfkd.vue | 576 +++++++++ code/新建文件夹/cw/yf/listinvoice.vue | 571 +++++++++ code/新建文件夹/cw/ys/detailbill.vue | 979 ++++++++++++++ code/新建文件夹/cw/ys/detailinvoice.vue | 1002 +++++++++++++++ code/新建文件夹/cw/ys/detailskd.vue | 1126 ++++++++++++++++ code/新建文件夹/cw/ys/list.vue | 826 ++++++++++++ code/新建文件夹/cw/ys/listbill.vue | 542 ++++++++ code/新建文件夹/cw/ys/listinvoice.vue | 568 +++++++++ code/新建文件夹/cw/ys/listskd.vue | 576 +++++++++ 21 files changed, 14314 insertions(+) create mode 100644 code/新建文件夹/cw/assistance/daily-expenses/detail.vue create mode 100644 code/新建文件夹/cw/assistance/daily-expenses/list.vue create mode 100644 code/新建文件夹/cw/assistance/payment-account/detail.vue create mode 100644 code/新建文件夹/cw/assistance/payment-account/list.vue create mode 100644 code/新建文件夹/cw/components/hldlg.vue create mode 100644 code/新建文件夹/cw/components/index.js create mode 100644 code/新建文件夹/cw/components/link.vue create mode 100644 code/新建文件夹/cw/yf/detailbill.vue create mode 100644 code/新建文件夹/cw/yf/detailfkd.vue create mode 100644 code/新建文件夹/cw/yf/detailinvoice.vue create mode 100644 code/新建文件夹/cw/yf/list.vue create mode 100644 code/新建文件夹/cw/yf/listbill.vue create mode 100644 code/新建文件夹/cw/yf/listfkd.vue create mode 100644 code/新建文件夹/cw/yf/listinvoice.vue create mode 100644 code/新建文件夹/cw/ys/detailbill.vue create mode 100644 code/新建文件夹/cw/ys/detailinvoice.vue create mode 100644 code/新建文件夹/cw/ys/detailskd.vue create mode 100644 code/新建文件夹/cw/ys/list.vue create mode 100644 code/新建文件夹/cw/ys/listbill.vue create mode 100644 code/新建文件夹/cw/ys/listinvoice.vue create mode 100644 code/新建文件夹/cw/ys/listskd.vue diff --git a/code/新建文件夹/cw/assistance/daily-expenses/detail.vue b/code/新建文件夹/cw/assistance/daily-expenses/detail.vue new file mode 100644 index 00000000..946707e8 --- /dev/null +++ b/code/新建文件夹/cw/assistance/daily-expenses/detail.vue @@ -0,0 +1,238 @@ + + + + + diff --git a/code/新建文件夹/cw/assistance/daily-expenses/list.vue b/code/新建文件夹/cw/assistance/daily-expenses/list.vue new file mode 100644 index 00000000..50733155 --- /dev/null +++ b/code/新建文件夹/cw/assistance/daily-expenses/list.vue @@ -0,0 +1,490 @@ + + + + diff --git a/code/新建文件夹/cw/assistance/payment-account/detail.vue b/code/新建文件夹/cw/assistance/payment-account/detail.vue new file mode 100644 index 00000000..769ffab5 --- /dev/null +++ b/code/新建文件夹/cw/assistance/payment-account/detail.vue @@ -0,0 +1,220 @@ + + + + + diff --git a/code/新建文件夹/cw/assistance/payment-account/list.vue b/code/新建文件夹/cw/assistance/payment-account/list.vue new file mode 100644 index 00000000..0f4ab32d --- /dev/null +++ b/code/新建文件夹/cw/assistance/payment-account/list.vue @@ -0,0 +1,485 @@ + + + + diff --git a/code/新建文件夹/cw/components/hldlg.vue b/code/新建文件夹/cw/components/hldlg.vue new file mode 100644 index 00000000..ca6a9648 --- /dev/null +++ b/code/新建文件夹/cw/components/hldlg.vue @@ -0,0 +1,204 @@ + + + + diff --git a/code/新建文件夹/cw/components/index.js b/code/新建文件夹/cw/components/index.js new file mode 100644 index 00000000..f43dd05f --- /dev/null +++ b/code/新建文件夹/cw/components/index.js @@ -0,0 +1,999 @@ +import { app } from "@/main"; +import { createVNode, render, ref } from "vue"; +import { ElMessage } from "element-plus"; +import { handleMappingConfig } from "@/utils/dodata.js"; +import { getDefaultValue, getFieldString, getMoneyExRate } from "@/utils/g3Funlib.js"; +import { useUserStore } from "@/store/user.js"; +import { getDate, getDateAfter, getDateTime } from "@/utils/time.js"; +import { getSFId } from "@/utils/common.js"; +import { diffData } from "@/utils/dataDiffUtils.js"; +import { + getobjectApi, + saveobjtlockApi, + loaddatabysqlApi, + saveobjtApi, + saveobjtV5Api, + loaddataApi, +} from "@/utils/doSql.js"; +import math from "@/utils/math.js"; +import router from "@/router/index.js"; +import axios from "@/utils/axios"; +import Link from "./link.vue"; + +export function openFeeLink(subid, type) { + const container = document.createElement("div"); + document.body.appendChild(container); + + let visible = true; + + const vnode = createVNode(Link, { + subid, + type, + + modelValue: visible, + "onUpdate:modelValue": (val) => { + visible = val; + }, + + onClose() { + render(null, container); + container.remove(); + }, + }); + + vnode.appContext = app._context; + + render(vnode, container); +} + +/** + * 生成账单 + * @export + * @param {*} rows 选中行 + * @param {*} type 类型 + */ +export async function generateBill_old(subids, type) { + if (!Array.isArray(subids) || subids.length === 0) { + throw new Error("请选择操作行"); + } + + const userStore = useUserStore(); + + const sqlcondition = `AND subid IN (${subids.map((id) => `'${id}'`).join(",")})`; + + const mappingid = type === "应收" ? "cwtoysbill" : "cwtoyfbill"; + const viewname_main = type === "应收" ? "v_cw_ysbill" : "v_cw_yfbill"; + const viewname_sub = type === "应收" ? "v_cw_ysbillsub" : "v_cw_yfbillsub"; + + const maindata = ref({}); + const maindataorg = ref({}); + const subdata = ref([]); + const subdataorg = ref([]); + const subdatacw = ref([]); + + await handleMappingConfig(mappingid, sqlcondition, subdata); + + if (subdata.value.length === 0) { + throw new Error("无有效数据"); + } + + // // 数据库再次校验,防止并发重复生成账单 + // const subdatas = await loaddataApi( + // viewname_sub, + // `mx_fee_id IN (${subdata.value.map((x) => `'${x.mx_fee_id}'`).join(",")})`, + // ); + + // if (subdatas.length > 0) { + // throw new Error("选中数据已制单,请检查!"); + // } + + // 结算单位一致性校验 + const tmpdwid = subdata.value[0].mx_dw_id || ""; + + for (const row of subdata.value) { + if ((row.mx_dw_id || "") !== tmpdwid) { + throw new Error("结算单位不一致,请检查!"); + } + } + + await getDefaultValue(maindata, viewname_main); + + const mainid = await getSFId(); + + maindata.value = { + ...maindata.value, + b_id: mainid, + b_state: "草拟", + b_module_id: type, + }; + + // const userid = userStore.getUserId(); + // const updatetime = getDateTime(); + + for (const [index, item] of subdata.value.entries()) { + item.mx_xh = index; + item.father = mainid; + + // subdatacw.value.push({ + // subid: item.mx_fee_id, + // mx_bill_id: mainid, + // mx_bill_updatedatetime: updatetime, + // mx_bill_updateuser_id: userid, + // }); + } + + const first = subdata.value[0]; + + // maindata.value.v_dw_name = first.mx_dw_name; + let today = getDate(); + maindata.value.b_dw_id = first.mx_dw_id; + maindata.value.b_amount = math + .add( + ...subdata.value.map((row) => { + const amount = Number(row.mx_amount_rmb || 0); + if (type === "应收") { + return row.mx_type_id === "应收" ? amount : -amount; + } + return row.mx_type_id === "应付" ? amount : -amount; + }), + ) + .toFixed(3); + maindata.value.b_date = today; + + // 币种 desc + const amountData = subdata.value.reduce( + (result, row) => { + const moneytype = row.mx_fee_money_id || ""; + + const sign = type === row.mx_type_id ? 1 : -1; + + const billAmount = math.multiply(row.mx_fee_amount || 0, sign); + + const rmbAmount = math.multiply(row.mx_amount_rmb || 0, sign); + + result.moneyMap[moneytype] = math.add(result.moneyMap[moneytype] || 0, billAmount); + + result.rmbTotal = math.add(result.rmbTotal, rmbAmount); + + return result; + }, + { + moneyMap: {}, + rmbTotal: 0, + }, + ); + + maindata.value.b_amount_desc = [ + ...Object.entries(amountData.moneyMap).map(([type, amount]) => `${type}:${amount.toFixed(2)}`), + `本币种合计:${amountData.rmbTotal.toFixed(2)}`, + ].join(";"); + + // 获取该合作伙伴的账龄、合同收款日、开票信息 + const companydata = await getobjectApi("v_b_othercompany_all", "b_id", maindata.value.b_dw_id); + let zl = companydata.b_zl || 0; + maindata.value.b_zl = zl; + maindata.value.b_plandate = getDateAfter(today, zl); + maindata.value.b_dw_invaccount = companydata.b_invaccount; + maindata.value.b_dw_bankacount = companydata.b_bankacount; + + const maindataChanges = diffData(maindata.value, maindataorg.value, "b_id", { + isSingle: true, + }); + + const subdataChanges = diffData(subdata.value, subdataorg.value, "subid"); + + if (!maindataChanges.hasChanges && !subdataChanges.hasChanges) { + return; + } + + const requestData = [ + { + tableName: "cw_bill", + keyField: "b_id", + inserts: maindataChanges.insertdata, + updates: [], + deletes: [], + }, + { + tableName: "cw_billsub", + keyField: "subid", + inserts: subdataChanges.insertdata, + updates: [], + deletes: [], + }, + ]; + + await saveobjtV5Api(requestData); + + const params = { + b_id: maindata.value.b_id, + }; + + try { + const response = await axios.post("fee/billconfirm", params); + + if (response.data.success === true) { + ElMessage.success(response.data.message || "核销成功"); + } else { + ElMessage.warning(response.data.message || "核销失败"); + } + } catch (error) { + ElMessage.error("请求失败:" + error.message); + } + + router.push({ + name: type === "应收" ? "ysdetailbill" : "yfdetailbill", + query: { + id: mainid, + op: "mod", + }, + }); +} + +/** + * 生成账单 + * @export + * @param {*} rows 选中行 + * @param {*} type 类型 + */ +export async function generateBill(subids, configid) { + if (!Array.isArray(subids) || subids.length === 0) { + throw new Error("请选择操作行"); + } + + if (!configid) { + throw new Error("请传入有效数据"); + } + + const configs = await loaddataApi("s_module_config", `b_id = '${configid}'`); + if (configs.length === 0) { + throw new Error("配置无效,请检查配置!"); + } + + const moduleConfig = configs[0]; + + const sqlcondition = `AND subid IN (${subids.map((id) => `'${id}'`).join(",")})`; + + const mappingid = moduleConfig.b_mapid; + const viewname_main = moduleConfig.b_viewtable; + + const maindata = ref({}); + const maindataorg = ref({}); + const subdata = ref([]); + const subdataorg = ref([]); + + await handleMappingConfig(mappingid, sqlcondition, subdata); + + if (subdata.value.length === 0) { + throw new Error("无有效数据"); + } + + // 结算单位一致性校验 + const tmpdwid = subdata.value[0].mx_dw_id || ""; + + for (const row of subdata.value) { + if ((row.mx_dw_id || "") !== tmpdwid) { + throw new Error("结算单位不一致,请检查!"); + } + } + + await getDefaultValue(maindata, viewname_main); + + const mainid = await getSFId(); + const type = moduleConfig.b_cwtype; + + maindata.value = { + ...maindata.value, + b_id: mainid, + b_state: "草拟", + b_cwtype: type, + b_module_id: moduleConfig.b_moduleid, + }; + + for (const [index, item] of subdata.value.entries()) { + item.mx_xh = index; + item.father = mainid; + } + + const first = subdata.value[0]; + + // maindata.value.v_dw_name = first.mx_dw_name; + let today = getDate(); + maindata.value.b_dw_id = first.mx_dw_id; + maindata.value.b_amount = math + .add( + ...subdata.value.map((row) => { + const amount = Number(row.mx_amount_rmb || 0); + if (type === "应收") { + return row.mx_type_id === "应收" ? amount : -amount; + } + return row.mx_type_id === "应付" ? amount : -amount; + }), + ) + .toFixed(3); + maindata.value.b_date = today; + + // 币种 desc + const amountData = subdata.value.reduce( + (result, row) => { + const moneytype = row.mx_fee_money_id || ""; + + const sign = type === row.mx_type_id ? 1 : -1; + + const billAmount = math.multiply(row.mx_fee_amount || 0, sign); + + const rmbAmount = math.multiply(row.mx_amount_rmb || 0, sign); + + result.moneyMap[moneytype] = math.add(result.moneyMap[moneytype] || 0, billAmount); + + result.rmbTotal = math.add(result.rmbTotal, rmbAmount); + + return result; + }, + { + moneyMap: {}, + rmbTotal: 0, + }, + ); + + maindata.value.b_amount_desc = [ + ...Object.entries(amountData.moneyMap).map(([type, amount]) => `${type}:${amount.toFixed(2)}`), + `本币种合计:${amountData.rmbTotal.toFixed(2)}`, + ].join(";"); + + // 获取该合作伙伴的账龄、合同收款日、开票信息 + const companydata = await getobjectApi("v_b_othercompany_all", "b_id", maindata.value.b_dw_id); + let zl = companydata.b_zl || 0; + maindata.value.b_zl = zl; + maindata.value.b_plandate = getDateAfter(today, zl); + maindata.value.b_dw_invaccount = companydata.b_invaccount; + maindata.value.b_dw_bankacount = companydata.b_bankacount; + + const maindataChanges = diffData(maindata.value, maindataorg.value, "b_id", { + isSingle: true, + }); + + const subdataChanges = diffData(subdata.value, subdataorg.value, "subid"); + + if (!maindataChanges.hasChanges && !subdataChanges.hasChanges) { + return; + } + + const requestData = [ + { + tableName: "cw_bill", + keyField: "b_id", + inserts: maindataChanges.insertdata, + updates: [], + deletes: [], + }, + { + tableName: "cw_billsub", + keyField: "subid", + inserts: subdataChanges.insertdata, + updates: [], + deletes: [], + }, + ]; + + await saveobjtV5Api(requestData); + + // 保存成功,开始核销,异常交给外部自己处理 + const feeids = subdata.value + .map((item) => item.mx_fee_id) + .filter(Boolean) + .join(","); + + const params = { + b_id: maindata.value.b_id, + fee_ids: feeids, + }; + + try { + const response = await axios.post("fee/billconfirm", params); + + if (response.data.success === true) { + ElMessage.success(response.data.message || "核销成功"); + } else { + ElMessage.warning(response.data.message || "核销失败"); + } + } catch (error) { + ElMessage.error("请求失败:" + error.message); + } + + router.push({ + name: type === "应收" ? "ysdetailbill" : "yfdetailbill", + query: { + id: mainid, + op: "mod", + }, + }); +} + +// 发票 +export async function generateInvoice_old(subids, type) { + if (!Array.isArray(subids) || subids.length === 0) { + throw new Error("请选择操作行"); + } + + const userStore = useUserStore(); + + const sqlcondition = `AND subid IN (${subids.map((id) => `'${id}'`).join(",")})`; + + const mappingid = type === "应收" ? "cwtoysinvoice" : "cwtoyfinvoice"; + const viewname_main = type === "应收" ? "v_cw_ysinvoice" : "v_cw_yfinvoice"; + const viewname_sub = type === "应收" ? "v_cw_ysinvoicesub" : "v_cw_yfinvoicesub"; + + const maindata = ref({}); + const maindataorg = ref({}); + const subdata = ref([]); + const subdataorg = ref([]); + const subdatacw = ref([]); + + await handleMappingConfig(mappingid, sqlcondition, subdata); + + if (subdata.value.length === 0) { + throw new Error("无有效数据"); + } + + // 数据库再次校验,防止并发重复生成发票 + // const subdatas = await loaddataApi( + // viewname_sub, + // `mx_fee_id IN (${subdata.value.map((x) => `'${x.mx_fee_id}'`).join(",")})`, + // ); + + // if (subdatas.length > 0) { + // throw new Error("选中数据已开发票,请检查!"); + // } + + // 不同币种 不同结算单位 + const tmpdwid = subdata.value[0].mx_dw_id || ""; + const moneyid = subdata.value[0].mx_fee_money_id || ""; + + for (const row of subdata.value) { + if ((row.mx_dw_id || "") !== tmpdwid) { + throw new Error("结算单位不一致,请检查!"); + } + if ((row.mx_fee_money_id || "") !== moneyid) { + throw new Error("币种不一致,请检查!"); + } + } + + await getDefaultValue(maindata, viewname_main); + + const mainid = await getSFId(); + + maindata.value = { + ...maindata.value, + b_id: mainid, + b_state: "草拟", + b_module_id: type, + }; + + const userid = userStore.getUserId(); + const updatetime = getDateTime(); + + for (const [index, item] of subdata.value.entries()) { + const subid = await getSFId(); + + item.subid = subid; + item.mx_xh = index; + item.father = maindata.value.b_id; + + // subdatacw.value.push({ + // subid: item.mx_fee_id, + // mx_version: item.mx_version, + // mx_invoice_id: mainid, + // mx_invoice_updatedatetime: updatetime, + // mx_invoice_updateuser_id: userid, + // }); + } + + const first = subdata.value[0]; + maindata.value.v_dw_name = first.mx_dw_name; + maindata.value.b_dw_id = first.mx_dw_id; + maindata.value.b_money_id = first.mx_fee_money_id; + maindata.value.b_amount = math + .add(...subdata.value.map((row) => row.mx_invoice_amount || 0)) + .toFixed(2); + maindata.value.b_yw_ids = getFieldString(subdata.value, "b_ywno"); + maindata.value.b_date = getDate(); + + const maindataChanges = diffData(maindata.value, maindataorg.value, "b_id", { isSingle: true }); + const subdataChanges = diffData(subdata.value, subdataorg.value, "subid"); + if (!maindataChanges.hasChanges && !subdataChanges.hasChanges) { + return; + } + + const requestData = [ + { + tableName: "cw_invoice", + keyField: "b_id", + inserts: maindataChanges.insertdata, + updates: [], + deletes: [], + }, + { + tableName: "cw_invoicesub", + keyField: "subid", + inserts: subdataChanges.insertdata, + updates: [], + deletes: [], + }, + ]; + + await saveobjtV5Api(requestData); + + const params = { + b_id: maindata.value.b_id, + }; + + try { + const response = await axios.post("fee/invoiceconfirm", params); + + if (response.data.success === true) { + ElMessage.success(response.data.message || "核销成功"); + } else { + ElMessage.warning(response.data.message || "核销失败"); + } + } catch (error) { + ElMessage.error("请求失败:" + error.message); + } + + router.push({ + name: type === "应收" ? "ysdetailinvoice" : "yfdetailinvoice", + query: { + id: mainid, + op: "mod", + }, + }); +} + +export async function generateInvoice(subids, configid) { + if (!Array.isArray(subids) || subids.length === 0) { + throw new Error("请选择操作行"); + } + + if (!configid) { + throw new Error("请传入有效数据"); + } + + const configs = await loaddataApi("s_module_config", `b_id = '${configid}'`); + if (configs.length === 0) { + throw new Error("配置无效,请检查配置!"); + } + + const moduleConfig = configs[0]; + + const sqlcondition = `AND subid IN (${subids.map((id) => `'${id}'`).join(",")})`; + + const mappingid = moduleConfig.b_mapid; + const viewname_main = moduleConfig.b_viewtable; + + const maindata = ref({}); + const maindataorg = ref({}); + const subdata = ref([]); + const subdataorg = ref([]); + + await handleMappingConfig(mappingid, sqlcondition, subdata); + + if (subdata.value.length === 0) { + throw new Error("无有效数据"); + } + + // 不同币种 不同结算单位 + const tmpdwid = subdata.value[0].mx_dw_id || ""; + const moneyid = subdata.value[0].mx_fee_money_id || ""; + + for (const row of subdata.value) { + if ((row.mx_dw_id || "") !== tmpdwid) { + throw new Error("结算单位不一致,请检查!"); + } + if ((row.mx_fee_money_id || "") !== moneyid) { + throw new Error("币种不一致,请检查!"); + } + } + + await getDefaultValue(maindata, viewname_main); + + const mainid = await getSFId(); + const type = moduleConfig.b_cwtype; + + maindata.value = { + ...maindata.value, + b_id: mainid, + b_state: "草拟", + b_cwtype: type, + b_module_id: moduleConfig.b_moduleid, + }; + + for (const [index, item] of subdata.value.entries()) { + const subid = await getSFId(); + + item.subid = subid; + item.mx_xh = index; + item.father = maindata.value.b_id; + } + + const first = subdata.value[0]; + maindata.value.v_dw_name = first.mx_dw_name; + maindata.value.b_dw_id = first.mx_dw_id; + maindata.value.b_money_id = first.mx_fee_money_id; + maindata.value.b_amount = math + .add(...subdata.value.map((row) => row.mx_invoice_amount || 0)) + .toFixed(2); + maindata.value.b_yw_ids = getFieldString(subdata.value, "b_ywno"); + maindata.value.b_date = getDate(); + + const maindataChanges = diffData(maindata.value, maindataorg.value, "b_id", { isSingle: true }); + const subdataChanges = diffData(subdata.value, subdataorg.value, "subid"); + if (!maindataChanges.hasChanges && !subdataChanges.hasChanges) { + return; + } + + const requestData = [ + { + tableName: "cw_invoice", + keyField: "b_id", + inserts: maindataChanges.insertdata, + updates: [], + deletes: [], + }, + { + tableName: "cw_invoicesub", + keyField: "subid", + inserts: subdataChanges.insertdata, + updates: [], + deletes: [], + }, + ]; + + await saveobjtV5Api(requestData); + + // 保存成功,开始核销,异常交给外部自己处理 + const feeids = subdata.value + .map((item) => item.mx_fee_id) + .filter(Boolean) + .join(","); + + const params = { + b_id: maindata.value.b_id, + fee_ids: feeids, + }; + + try { + const response = await axios.post("fee/invoiceconfirm", params); + + if (response.data.success === true) { + ElMessage.success(response.data.message || "核销成功"); + } else { + ElMessage.warning(response.data.message || "核销失败"); + } + } catch (error) { + ElMessage.error("请求失败:" + error.message); + } + + router.push({ + name: type === "应收" ? "ysdetailinvoice" : "yfdetailinvoice", + query: { + id: mainid, + op: "mod", + }, + }); +} + +// 收付单 +export async function generateSfd_old(subids, type) { + if (!Array.isArray(subids) || subids.length === 0) { + throw new Error("请选择操作行"); + } + + const userStore = useUserStore(); + + const sqlcondition = `AND subid IN (${subids.map((id) => `'${id}'`).join(",")})`; + + const mappingid = type === "应收" ? "cwtoskd" : "cwtofkd"; + const viewname_main = type === "应收" ? "v_cw_skd" : "v_cw_fkd"; + const viewname_sub = type === "应收" ? "v_cw_skdsub" : "v_cw_fkdsub"; + + const maindata = ref({}); + const maindataorg = ref({}); + const subdata = ref([]); + const subdataorg = ref([]); + + await handleMappingConfig(mappingid, sqlcondition, subdata); + + if (subdata.value.length === 0) { + throw new Error("无有效数据"); + } + + // 不同币种 不同结算单位 + const tmpdwid = subdata.value[0].mx_dw_id || ""; + const moneyid = subdata.value[0].mx_moneytype_id || ""; + + for (const row of subdata.value) { + if ((row.mx_dw_id || "") !== tmpdwid) { + throw new Error("结算单位不一致,请检查!"); + } + // if ((row.mx_moneytype_id || "") !== moneyid) { + // throw new Error("币种不一致,请检查!"); + // } + } + + await getDefaultValue(maindata, viewname_main); + + const mainid = await getSFId(); + + maindata.value = { + ...maindata.value, + b_id: mainid, + b_state: "草拟", + b_module_id: type === "应收" ? "实收" : "实付", + }; + + for (const [index, item] of subdata.value.entries()) { + const subid = await getSFId(); + + item.subid = subid; + item.mx_xh = index; + item.father = maindata.value.b_id; + } + + const first = subdata.value[0]; + maindata.value.v_dw_name = first.mx_dw_name; + maindata.value.b_dw_id = first.mx_dw_id; + maindata.value.b_money_id = first.mx_fee_money_id; + maindata.value.b_exrate = await getMoneyExRate({ + rows: subdata.value, + }); + + // let amount = math.add(...subdata.value.map((row) => row.mx_sfd_totalamount_not || 0)).toFixed(3); + + // maindata.value.b_amount_sj = amount; + // maindata.value.b_amount_hx = amount; + // maindata.value.b_amount = amount; + + maindata.value.b_amount_sj = 0; + maindata.value.b_amount_hx = 0; + maindata.value.b_amount = 0; + maindata.value.b_amount_nothx = 0; + + maindata.value.b_date = getDate(); + + maindata.value.b_yw_ids = getFieldString(subdata.value, "b_ywno"); + maindata.value.b_bill_ids = getFieldString(subdata.value, "mx_bill_ywno"); + maindata.value.b_inv_ids = getFieldString(subdata.value, "mx_invoice_ywno"); + + const maindataChanges = diffData(maindata.value, maindataorg.value, "b_id", { isSingle: true }); + const subdataChanges = diffData(subdata.value, subdataorg.value, "subid"); + if (!maindataChanges.hasChanges && !subdataChanges.hasChanges) { + return; + } + + const requestData = [ + { + tableName: "cw_sfd", + keyField: "b_id", + inserts: maindataChanges.insertdata, + updates: [], + deletes: [], + }, + { + tableName: "cw_sfdsub", + keyField: "subid", + inserts: subdataChanges.insertdata, + updates: [], + deletes: [], + }, + ]; + + await saveobjtV5Api(requestData); + + // 保存成功,开始核销,异常交给外部自己处理 + const feeids = subdata.value + .map((item) => item.mx_fee_id) + .filter(Boolean) + .join(","); + + const params = { + b_id: maindata.value.b_id, + fee_ids: feeids, + }; + + try { + const response = await axios.post("fee/feewriteoffbatch", params); + + if (response.data.success === true) { + ElMessage.success(response.data.message || "核销成功"); + } else { + ElMessage.warning(response.data.message || "核销失败"); + } + } catch (error) { + ElMessage.error("请求失败:" + error.message); + } + + router.push({ + name: type === "应收" ? "ysdetailskd" : "yfdetailfkd", + query: { + id: mainid, + op: "mod", + }, + }); +} + +export async function generateSfd(subids, configid) { + if (!Array.isArray(subids) || subids.length === 0) { + throw new Error("请选择操作行"); + } + + if (!configid) { + throw new Error("请传入有效数据"); + } + + const configs = await loaddataApi("s_module_config", `b_id = '${configid}'`); + if (configs.length === 0) { + throw new Error("配置无效,请检查配置!"); + } + + const moduleConfig = configs[0]; + + const sqlcondition = `AND subid IN (${subids.map((id) => `'${id}'`).join(",")})`; + + const mappingid = moduleConfig.b_mapid; + const viewname_main = moduleConfig.b_viewtable; + + const maindata = ref({}); + const maindataorg = ref({}); + const subdata = ref([]); + const subdataorg = ref([]); + + await handleMappingConfig(mappingid, sqlcondition, subdata); + + if (subdata.value.length === 0) { + throw new Error("无有效数据"); + } + + // 不同币种 不同结算单位 + const tmpdwid = subdata.value[0].mx_dw_id || ""; + + for (const row of subdata.value) { + if ((row.mx_dw_id || "") !== tmpdwid) { + throw new Error("结算单位不一致,请检查!"); + } + } + + await getDefaultValue(maindata, viewname_main); + + const mainid = await getSFId(); + const type = moduleConfig.b_cwtype; + + maindata.value = { + ...maindata.value, + b_id: mainid, + b_state: "草拟", + b_cwtype: type, + b_module_id: moduleConfig.b_moduleid, + }; + + for (const [index, item] of subdata.value.entries()) { + const subid = await getSFId(); + + item.subid = subid; + item.mx_xh = index; + item.father = maindata.value.b_id; + } + + const first = subdata.value[0]; + maindata.value.v_dw_name = first.mx_dw_name; + maindata.value.b_dw_id = first.mx_dw_id; + maindata.value.b_money_id = first.mx_fee_money_id; + maindata.value.b_exrate = await getMoneyExRate({ + rows: subdata.value, + }); + + // let amount = math.add(...subdata.value.map((row) => row.mx_sfd_totalamount_not || 0)).toFixed(3); + + // maindata.value.b_amount_sj = amount; + // maindata.value.b_amount_hx = amount; + // maindata.value.b_amount = amount; + + maindata.value.b_amount_sj = 0; + maindata.value.b_amount_hx = 0; + maindata.value.b_amount = 0; + maindata.value.b_amount_nothx = 0; + + maindata.value.b_date = getDate(); + + maindata.value.b_yw_ids = getFieldString(subdata.value, "b_ywno"); + maindata.value.b_bill_ids = getFieldString(subdata.value, "mx_bill_ywno"); + maindata.value.b_inv_ids = getFieldString(subdata.value, "mx_invoice_ywno"); + + const maindataChanges = diffData(maindata.value, maindataorg.value, "b_id", { isSingle: true }); + const subdataChanges = diffData(subdata.value, subdataorg.value, "subid"); + if (!maindataChanges.hasChanges && !subdataChanges.hasChanges) { + return; + } + + const requestData = [ + { + tableName: "cw_sfd", + keyField: "b_id", + inserts: maindataChanges.insertdata, + updates: [], + deletes: [], + }, + { + tableName: "cw_sfdsub", + keyField: "subid", + inserts: subdataChanges.insertdata, + updates: [], + deletes: [], + }, + ]; + + await saveobjtV5Api(requestData); + + // 保存成功,开始核销,异常交给外部自己处理 + const feeids = subdata.value + .map((item) => item.mx_fee_id) + .filter(Boolean) + .join(","); + + const params = { + b_id: maindata.value.b_id, + fee_ids: feeids, + }; + + try { + const response = await axios.post("fee/feewriteoffbatch", params); + + if (response.data.success === true) { + ElMessage.success(response.data.message || "核销成功"); + } else { + ElMessage.warning(response.data.message || "核销失败"); + } + } catch (error) { + ElMessage.error("请求失败:" + error.message); + } + + router.push({ + name: type === "应收" ? "ysdetailskd" : "yfdetailfkd", + query: { + id: mainid, + op: "mod", + }, + }); +} + +function showSaveResultMessage(response) { + const data = response.data?.data || {}; + const { insert, update, delete: del, insertBlocked, updateBlocked, deleteBlocked } = data; + + const totalSuccess = (insert || 0) + (update || 0) + (del || 0); + const totalBlocked = (insertBlocked || 0) + (updateBlocked || 0) + (deleteBlocked || 0); + + // 完全没有成功,也没有拦截(一般不会走到) + if (totalSuccess === 0 && totalBlocked === 0) { + ElMessage.info("没有数据发生变化"); + return; + } + + // ✅ 完全成功 + if (totalBlocked === 0) { + ElMessage.success(`保存成功(新增 ${insert || 0},更新 ${update || 0},删除 ${del || 0})`); + return; + } + + // ⚠️ 有拦截(重点) + let msg = "保存成功,但部分数据被业务规则拦截"; + + const parts = []; + if (insertBlocked > 0) parts.push(`新增 ${insertBlocked} 条`); + if (updateBlocked > 0) parts.push(`更新 ${updateBlocked} 条`); + if (deleteBlocked > 0) parts.push(`删除 ${deleteBlocked} 条`); + + msg += `(${parts.join(",")})`; + + // ✅ 用 warning 而不是 error + ElMessage.warning(msg); +} \ No newline at end of file diff --git a/code/新建文件夹/cw/components/link.vue b/code/新建文件夹/cw/components/link.vue new file mode 100644 index 00000000..d087403b --- /dev/null +++ b/code/新建文件夹/cw/components/link.vue @@ -0,0 +1,234 @@ + + + + + diff --git a/code/新建文件夹/cw/yf/detailbill.vue b/code/新建文件夹/cw/yf/detailbill.vue new file mode 100644 index 00000000..70ead130 --- /dev/null +++ b/code/新建文件夹/cw/yf/detailbill.vue @@ -0,0 +1,1082 @@ + + + + diff --git a/code/新建文件夹/cw/yf/detailfkd.vue b/code/新建文件夹/cw/yf/detailfkd.vue new file mode 100644 index 00000000..a1b6542a --- /dev/null +++ b/code/新建文件夹/cw/yf/detailfkd.vue @@ -0,0 +1,1128 @@ + + + + + diff --git a/code/新建文件夹/cw/yf/detailinvoice.vue b/code/新建文件夹/cw/yf/detailinvoice.vue new file mode 100644 index 00000000..425ca6a2 --- /dev/null +++ b/code/新建文件夹/cw/yf/detailinvoice.vue @@ -0,0 +1,975 @@ + + + + + \ No newline at end of file diff --git a/code/新建文件夹/cw/yf/list.vue b/code/新建文件夹/cw/yf/list.vue new file mode 100644 index 00000000..8d2c5758 --- /dev/null +++ b/code/新建文件夹/cw/yf/list.vue @@ -0,0 +1,829 @@ + + + + + \ No newline at end of file diff --git a/code/新建文件夹/cw/yf/listbill.vue b/code/新建文件夹/cw/yf/listbill.vue new file mode 100644 index 00000000..45b50634 --- /dev/null +++ b/code/新建文件夹/cw/yf/listbill.vue @@ -0,0 +1,664 @@ + + + + diff --git a/code/新建文件夹/cw/yf/listfkd.vue b/code/新建文件夹/cw/yf/listfkd.vue new file mode 100644 index 00000000..72527cc7 --- /dev/null +++ b/code/新建文件夹/cw/yf/listfkd.vue @@ -0,0 +1,576 @@ + + + + + \ No newline at end of file diff --git a/code/新建文件夹/cw/yf/listinvoice.vue b/code/新建文件夹/cw/yf/listinvoice.vue new file mode 100644 index 00000000..2386b498 --- /dev/null +++ b/code/新建文件夹/cw/yf/listinvoice.vue @@ -0,0 +1,571 @@ + + + + + diff --git a/code/新建文件夹/cw/ys/detailbill.vue b/code/新建文件夹/cw/ys/detailbill.vue new file mode 100644 index 00000000..76a009ed --- /dev/null +++ b/code/新建文件夹/cw/ys/detailbill.vue @@ -0,0 +1,979 @@ + + + + + \ No newline at end of file diff --git a/code/新建文件夹/cw/ys/detailinvoice.vue b/code/新建文件夹/cw/ys/detailinvoice.vue new file mode 100644 index 00000000..bab14528 --- /dev/null +++ b/code/新建文件夹/cw/ys/detailinvoice.vue @@ -0,0 +1,1002 @@ + + + + \ No newline at end of file diff --git a/code/新建文件夹/cw/ys/detailskd.vue b/code/新建文件夹/cw/ys/detailskd.vue new file mode 100644 index 00000000..fb5debd1 --- /dev/null +++ b/code/新建文件夹/cw/ys/detailskd.vue @@ -0,0 +1,1126 @@ + + + + \ No newline at end of file diff --git a/code/新建文件夹/cw/ys/list.vue b/code/新建文件夹/cw/ys/list.vue new file mode 100644 index 00000000..cd989b5e --- /dev/null +++ b/code/新建文件夹/cw/ys/list.vue @@ -0,0 +1,826 @@ + + + + + diff --git a/code/新建文件夹/cw/ys/listbill.vue b/code/新建文件夹/cw/ys/listbill.vue new file mode 100644 index 00000000..27b5f767 --- /dev/null +++ b/code/新建文件夹/cw/ys/listbill.vue @@ -0,0 +1,542 @@ + + + + diff --git a/code/新建文件夹/cw/ys/listinvoice.vue b/code/新建文件夹/cw/ys/listinvoice.vue new file mode 100644 index 00000000..f590da7d --- /dev/null +++ b/code/新建文件夹/cw/ys/listinvoice.vue @@ -0,0 +1,568 @@ + + + + + \ No newline at end of file diff --git a/code/新建文件夹/cw/ys/listskd.vue b/code/新建文件夹/cw/ys/listskd.vue new file mode 100644 index 00000000..a0487e27 --- /dev/null +++ b/code/新建文件夹/cw/ys/listskd.vue @@ -0,0 +1,576 @@ + + + + +