diff --git a/Pilot_KD_Parino/AR_SalesVATInvoice/Bill.cs b/Pilot_KD_Parino/AR_SalesVATInvoice/Bill.cs new file mode 100644 index 0000000..1562abf --- /dev/null +++ b/Pilot_KD_Parino/AR_SalesVATInvoice/Bill.cs @@ -0,0 +1,28 @@ +using Kingdee.BOS.Core.Bill.PlugIn; +using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; +using Kingdee.BOS.Util; +using System.ComponentModel; + +namespace Pilot_KD_Parino.AR_SalesVATInvoice +{ + [HotUpdate, Description("销售增值税专用发票_表单插件")] + public class Bill : AbstractBillPlugIn + { + public override void AfterDoOperation(AfterDoOperationEventArgs e) + { + base.AfterDoOperation(e); + + string opt = e.Operation.Operation; + + // 保存成功后刷新界面(参考收款核销5的刷新方式) + if (opt == "Save" && e.OperationResult.IsSuccess) + { + // 刷新单据体视图 + this.View.UpdateView("SALESICENTRY"); + // 刷新整个界面 + this.View.Refresh(); + } + } + } +} + diff --git a/Pilot_KD_Parino/AR_SalesVATInvoice/ServicePlugIn/AfterSave.cs b/Pilot_KD_Parino/AR_SalesVATInvoice/ServicePlugIn/AfterSave.cs index 8f412d2..5d98033 100644 --- a/Pilot_KD_Parino/AR_SalesVATInvoice/ServicePlugIn/AfterSave.cs +++ b/Pilot_KD_Parino/AR_SalesVATInvoice/ServicePlugIn/AfterSave.cs @@ -2,15 +2,14 @@ using Kingdee.BOS; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Log; +using Kingdee.BOS.Orm; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; -using Pilot_KD_Parino.Common; using System; using System.ComponentModel; -using System.Linq; -namespace Pilot_KD_Parino.AR_SalesVATInvoice.ServicePlugIn +namespace Gatedge.K3.Pilot.PlugIn.BOSPlugIn.AR_SalesVATInvoice.ServicePlugIn { [HotUpdate, Description("销售增值税专用发票_保存后事件")] public class AfterSave : AbstractOperationServicePlugIn @@ -18,26 +17,24 @@ namespace Pilot_KD_Parino.AR_SalesVATInvoice.ServicePlugIn public override void OnPreparePropertys(PreparePropertysEventArgs e) { base.OnPreparePropertys(e); - // 添加需要加载的字段 - e.FieldKeys.Add("FENTRYID"); + // 根据日志中的实际实体属性名来添加 e.FieldKeys.Add("FIDD"); e.FieldKeys.Add("FSEQQ"); - e.FieldKeys.Add("FSRCBILLTYPEID"); - e.FieldKeys.Add("FSRCBILLNO"); + e.FieldKeys.Add("SRCBILLTYPEID"); // 实体属性名(没有F前缀) + e.FieldKeys.Add("SRCBILLNO"); // 实体属性名(没有F前缀) + e.FieldKeys.Add("SEQ"); } - public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e) + + public override void EndOperationTransaction(EndOperationTransactionArgs e) { - base.AfterExecuteOperationTransaction(e); - - + base.EndOperationTransaction(e); foreach (var dataEntity in e.DataEntitys) { var billObj = dataEntity as DynamicObject; if (billObj == null) continue; - var sdsas = JsonHelper.ToJson(billObj); - Logger.Error("销售增值税专用发票", sdsas, new Exception()); + // 获取单据体 var entrys = billObj["SALESICENTRY"] as DynamicObjectCollection; if (entrys == null || entrys.Count == 0) @@ -45,58 +42,63 @@ namespace Pilot_KD_Parino.AR_SalesVATInvoice.ServicePlugIn foreach (var entry in entrys) { - var entryId = Convert.ToInt64(entry["FENTRYID"]); + // 使用 Id 获取主键值 + var entryId = Convert.ToInt64(entry.GetPrimaryKeyValue()); var fidd = entry["FIDD"]; var fiddValue = fidd == null ? 0 : Convert.ToInt64(fidd); if (fiddValue > 0) { // FIDD > 0 时,判断是否需要回写 - var srcBillNo = entry["FSRCBILLNO"]?.ToString() ?? ""; - Logger.Error("销售增值税专用发票", "56", new Exception()); - // FIDD != 当前行FENTRYID 且 源单编号为空 时才回写 + var srcBillNo = entry["SRCBILLNO"]?.ToString() ?? ""; + + // 判断条件:FIDD != 当前行ID 且 源单编号为空 if (fiddValue != entryId && string.IsNullOrWhiteSpace(srcBillNo)) { - // 查询源单据体信息(主键=FIDD的明细行) + // 查询源单据体信息(FID = fiddValue的明细行) + // 这里使用数据库字段名(带F前缀) var sql = $@"/*dialect*/ SELECT FSRCBILLTYPEID, FSRCBILLNO, FSEQ FROM T_IV_SALESICENTRY WHERE FENTRYID = {fiddValue}"; Logger.Error("销售增值税专用发票", sql, new Exception()); + Logger.Error("销售增值税专用发票", "78", new Exception()); var result = DBServiceHelper.ExecuteDynamicObject(this.Context, sql); if (result == null || result.Count == 0) continue; - Logger.Error("销售增值税专用发票", "69", new Exception()); + var srcData = result[0]; - var srcBillTypeId = srcData["FSRCBILLTYPEID"]; - var srcBillNoValue = srcData["FSRCBILLNO"]; + // 注意:SQL查询返回的是数据库字段名(带F前缀) + var srcBillTypeId = srcData["FSRCBILLTYPEID"]?.ToString() ?? ""; + var srcBillNoValue = srcData["FSRCBILLNO"]?.ToString() ?? ""; // 回写当前单据体:源单类型、源单编号 + // 这里使用数据库字段名(带F前缀) var updateSql = $@"/*dialect*/ UPDATE T_IV_SALESICENTRY -SET FSRCBILLTYPEID = '{srcBillTypeId}', - FSRCBILLNO = '{srcBillNoValue}' +SET FSRCBILLTYPEID = '{srcBillTypeId.Replace("'", "''")}', + FSRCBILLNO = '{srcBillNoValue.Replace("'", "''")}' WHERE FENTRYID = {entryId}"; Logger.Error("销售增值税专用发票", updateSql, new Exception()); - Logger.Error("销售增值税专用发票", "80", new Exception()); + Logger.Error("销售增值税专用发票", "78", new Exception()); DBServiceHelper.Execute(this.Context, updateSql); } } else { - Logger.Error("销售增值税专用发票", "", new Exception()); - // FIDD <= 0 时,把当前行FENTRYID赋值给FIDD,同时把FSEQ赋值给FSEQQ + // FIDD <= 0 时,把当前行FID赋值给FIDD,同时把FSEQ赋值给FSEQQ + var seq = entry["SEQ"]?.ToString() ?? "0"; var updateSql = $@"/*dialect*/ UPDATE T_IV_SALESICENTRY -SET FIDD = FENTRYID, - FSEQQ = FSEQ +SET FIDD = {entryId}, + FSEQQ = '{seq.Replace("'", "''")}' WHERE FENTRYID = {entryId}"; - Logger.Error("销售增值税专用发票", "93", new Exception()); + Logger.Error("销售增值税专用发票", updateSql, new Exception()); + Logger.Error("销售增值税专用发票", "78", new Exception()); DBServiceHelper.Execute(this.Context, updateSql); } } } } } -} - +} \ No newline at end of file diff --git a/Pilot_KD_Parino/Pilot_KD_Parino.csproj b/Pilot_KD_Parino/Pilot_KD_Parino.csproj index ce960a0..47db624 100644 --- a/Pilot_KD_Parino/Pilot_KD_Parino.csproj +++ b/Pilot_KD_Parino/Pilot_KD_Parino.csproj @@ -322,6 +322,7 @@ + diff --git a/Pilot_KD_Parino/bin/Debug/GZ_KD_Parino.dll b/Pilot_KD_Parino/bin/Debug/GZ_KD_Parino.dll new file mode 100644 index 0000000..141360e Binary files /dev/null and b/Pilot_KD_Parino/bin/Debug/GZ_KD_Parino.dll differ