From a30b8f79fe5583fdcc82af710dcb1629499747f7 Mon Sep 17 00:00:00 2001 From: xiongshuai <873144595@qq.com> Date: Fri, 12 Dec 2025 09:42:30 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=80=E5=94=AE=E5=A2=9E=E5=80=BC=E7=A8=8E?= =?UTF-8?q?=E5=8F=91=E7=A5=A8=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ServicePlugIn/AfterSave.cs | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/Gatedge.K3.Pilot.PlugIn/BOSPlugIn/AR_SalesVATInvoice/ServicePlugIn/AfterSave.cs b/Gatedge.K3.Pilot.PlugIn/BOSPlugIn/AR_SalesVATInvoice/ServicePlugIn/AfterSave.cs index 5bdf242..1a4822d 100644 --- a/Gatedge.K3.Pilot.PlugIn/BOSPlugIn/AR_SalesVATInvoice/ServicePlugIn/AfterSave.cs +++ b/Gatedge.K3.Pilot.PlugIn/BOSPlugIn/AR_SalesVATInvoice/ServicePlugIn/AfterSave.cs @@ -57,20 +57,38 @@ namespace Gatedge.K3.Pilot.PlugIn.BOSPlugIn.AR_SalesVATInvoice.ServicePlugIn // 判断条件:FIDD != 当前行ID 且 源单编号为空 if (fiddValue != entryId && string.IsNullOrWhiteSpace(srcBillNo)) { - // 从当前单据主表获取单据编号(实体属性名:BILLNO) - var billNo = billObj["BILLNO"]?.ToString() ?? ""; + // 通过源分录ID(FIDD)查询源单据的单据编号 + string srcBillNoFromSource = ""; + try + { + var querySql = $@"/*dialect*/ +SELECT A.FBILLNO +FROM T_IV_SALESIC A +INNER JOIN T_IV_SALESICENTRY B ON A.FID = B.FID +WHERE B.FENTRYID = {fiddValue}"; + + var result = DBServiceHelper.ExecuteDynamicObject(this.Context, querySql); + if (result != null && result.Count > 0) + { + srcBillNoFromSource = result[0]["FBILLNO"]?.ToString() ?? ""; + } + } + catch (Exception ex) + { + Logger.Error($"查询源单据编号失败,FIDD={fiddValue}", ex); + } + // 固定源单类型为"销售增值税专用发票" var srcBillType = "IV_SALESIC"; - // 回写当前单据体:源单类型、源单编号 + // 回写当前单据体:源单类型、源单编号(使用源单据的编号) // 这里使用数据库字段名(带F前缀) var updateSql = $@"/*dialect*/ UPDATE T_IV_SALESICENTRY SET FSRCBILLTYPEID = '{srcBillType.Replace("'", "''")}', - FSRCBILLNO = '{billNo.Replace("'", "''")}' + FSRCBILLNO = '{srcBillNoFromSource.Replace("'", "''")}' WHERE FENTRYID = {entryId}"; - Logger.Error("销售增值税专用发票", updateSql, new Exception()); - Logger.Error("销售增值税专用发票", "78", new Exception()); + Logger.Error($"销售增值税专用发票_回写源单信息: {updateSql}"); DBServiceHelper.Execute(this.Context, updateSql); } } @@ -83,12 +101,12 @@ UPDATE T_IV_SALESICENTRY SET FIDD = {entryId}, FSEQQ = '{seq.Replace("'", "''")}' WHERE FENTRYID = {entryId}"; - Logger.Error("销售增值税专用发票", updateSql, new Exception()); - Logger.Error("销售增值税专用发票", "78", new Exception()); + Logger.Error($"销售增值税专用发票: {updateSql}"); DBServiceHelper.Execute(this.Context, updateSql); } } } } } -} \ No newline at end of file +} +