大家好,我正在使用 AP 批量发布,我正在插入一个现有的文档行,同时创建一个新的信用调整。
但是,您没有插入信用调整细节,只是标题。
这是我的代码。
namespace PX.Objects.AP
{
public class APDocumentRelease_Extension : PXGraphExtension<APDocumentRelease>
{
public class APReleaseProcessNewExt : PXGraphExtension<APReleaseProcess>
{
public delegate List<APRegister> ReleaseDocProcDel(JournalEntry je, ref APRegister doc, PXResult<APInvoice, CurrencyInfo, Terms, Vendor> res, bool isPrebooking, out List<INRegister> inDocs);
[PXOverride]
public virtual List<APRegister> ReleaseDocProc(JournalEntry je, APRegister doc, bool isPrebooking, out List<INRegister> inDocs)
{
List<APRegister> ret = null;
inDocs = null;
if (doc.CreatedByScreenID == "AP501000" || doc.LastModifiedByScreenID == "AP501000")
{
APInvoice api = Base.APInvoice_DocType_RefNbr.Current;
CurrencyInfo curren = (CurrencyInfo)PXSelect<CurrencyInfo, Where<CurrencyInfo.curyInfoID, Equal<Current<APInvoice.curyInfoID>>>>.Select(Base, doc.CuryInfoID);
var apiExt = api.GetExtension<XTAPInvoice>();
TaxRev trRow = PXSelectJoin<TaxRev,
InnerJoin<xtb08Sunat, On<xtb08Sunat.taxCD, Equal<TaxRev.taxID>>>,
Where<xtb08Sunat.tGdsSvcsCD, Equal<Required<xtb08Sunat.tGdsSvcsCD>>>>.Select(Base, apiExt.TBienServ);
APPayment aPInvoice = Base.APPayment_DocType_RefNbr.Current;
decimal tipocambio = curren.CuryMultDiv == "M" ? (decimal)curren.CuryRate : (decimal)curren.RecipRate;
decimal p_AmtDetrac = 0;
decimal CuryLineAmt = 0;
using (PXTransactionScope ts = new PXTransactionScope())
{
APInvoiceEntry graph = PXGraph.CreateInstance<APInvoiceEntry>();
if (doc != null && doc.Released == true && doc.DocType == APDocType.Invoice &&
doc != null && item != null && doc.LastModifiedByScreenID == "AP501000" && doc.Hold == false && apiExt.Detraccion == true)
{
#region Create detraction record in the APtran table
APTran row = ViewAPTran.Insert();
row.TranDesc = "Detraccion";
row.CuryLineAmt = api.CuryID == "USD" ? Math.Round((decimal)((api.CuryDocBal) * (trRow.TaxRate / 100)) * -1, 2) : Math.Round((decimal)((api.CuryDocBal) * (trRow.TaxRate / 100)) * -1 * tipocambio, 0);
Base.APTran_TranType_RefNbr.SetValueExt<APTran.curyLineAmt>(row, row.CuryLineAmt);
CuryLineAmt = (decimal)row.CuryLineAmt;
row.AccountID = item.AccountID;
row.TaxCategoryID = null;
row.Released = true;
row.SubID = tax.SalesTaxSubID;
row.UnitCost = 0m;
Base.APTran_TranType_RefNbr.Current.GetExtension<APTranExt>().UsrTipoTransaccion = "AFEC3";
ViewAPTran.Update(row);
ViewAPTran.Cache.Persist(PXDBOperation.Insert);
#endregion
#region Crear Detraccion en la tabla xAcDetrac
xAcDetrac xad = detracInv.Select(api.DocType, api.RefNbr);
if (xad == null)
{
p_AmtDetrac = api.CuryID == "USD" ? Math.Round((decimal)((api.CuryDocBal) * (trRow.TaxRate / 100)) * -1, 2) * tipocambio : Math.Round((decimal)((api.CuryDocBal) * (trRow.TaxRate / 100)) * -1, 2);
xAcDetrac xa = ViewxAcDetrac.Insert();
xa.DocType = api.DocType;
xa.RefNbr = api.RefNbr;
xa.BatchAutoNbr = "";
xa.DocAmt = Math.Round(p_AmtDetrac * -1, 0);
xa.Status = "DR";
xa.TranDate = api.DocDate;
ViewxAcDetrac.Update(xa);
ViewxAcDetrac.Cache.Persist(xa, PXDBOperation.Insert);
//ViewxAcDetrac.Cache.Persist(xa, PXDBOperation.Update);
}
#endregion
#region Modifying APInvoice Values - INV
APRegister xapreg = doc;
APRegister apreg = PXSelect<APRegister,
Where<APRegister.refNbr,
Equal<Required<APRegister.refNbr>>,
And<APRegister.docType, Equal<Required<APRegister.docType>>>>>.Select(Base, xapreg.RefNbr, xapreg.DocType);
APInvoice apin = Base.APInvoice_DocType_RefNbr.Current;
apin.CuryLineTotal = apin.CuryLineTotal - (apin.CuryID == "USD" ?
Math.Round((decimal)((apin.CuryDocBal) * (trRow.TaxRate / 100)), 2) :
Math.Round((decimal)((apin.CuryDocBal) * (trRow.TaxRate / 100)) * tipocambio, 0));
apreg.CuryDocBal = apreg.CuryDocBal - (apin.CuryID == "USD" ?
Math.Round((decimal)((apin.CuryDocBal) * (trRow.TaxRate / 100)), 2) :
Math.Round((decimal)((apin.CuryDocBal) * (trRow.TaxRate / 100)) * tipocambio, 0));
apreg.CuryOrigDocAmt = apreg.CuryOrigDocAmt - (apin.CuryID == "USD" ?
Math.Round((decimal)((apin.CuryDocBal) * (trRow.TaxRate / 100)), 2) :
Math.Round((decimal)((apin.CuryDocBal) * (trRow.TaxRate / 100)) * tipocambio, 0));
apreg.DocBal = apin.CuryID == "USD" ?
Math.Round((decimal)apreg.CuryDocBal * tipocambio, 2) :
Math.Round((decimal)apreg.CuryDocBal, 2);
apreg.NoteID = apin.NoteID;
graph.Caches[typeof(APRegister)].Update(apreg);
graph.Caches[typeof(APRegister)].Persist(PXDBOperation.Update);
#endregion
#region Create Record in CurrencyInfo Table
CurrencyInfo info1 = ViewCurrencyInfo.Insert();
info1.CuryID = "PEN";
info1.CuryRateTypeID = "VENTA";
info1.CuryEffDate = DateTime.Today;
info1.CuryMultDiv = "M";
info1.CuryRate = 1;
info1.BaseCuryID = "PEN";
info1.RecipRate = 1;
info1.BaseCalc = true;
ViewCurrencyInfo.Update(info1);
ViewCurrencyInfo.Cache.Persist(PXDBOperation.Insert);
#endregion
#region New document header, credit adjustment
APInvoiceEntry docgraph = PXGraph.CreateInstance<APInvoiceEntry>();
APInvoice xdoc = (APInvoice)api;
APInvoice invoice = PXCache<APInvoice>.CreateCopy(xdoc);
invoice.DocType = APDocType.CreditAdj;
invoice.RefNbr = null;
invoice.DocDesc = "Detracci\u00F3n del IGV";
invoice.CuryLineTotal = Math.Round(p_AmtDetrac * -1, 0);
invoice.CuryDiscTot = 0;
invoice.CuryVatTaxableTotal = 0;
invoice.CuryVatExemptTotal = 0;
invoice.CuryTaxTotal = 0;
invoice.CuryOrigWhTaxAmt = 0;
invoice.CuryDocBal = Math.Round(p_AmtDetrac * -1, 0);
invoice.CuryRoundDiff = 0;
invoice.CuryOrigDocAmt = Math.Round(p_AmtDetrac * -1, 0);
invoice.CuryOrigDiscAmt = 0;
invoice.CuryInfoID = ViewCurrencyInfo.Current.CuryInfoID;
invoice.CuryID = ViewCurrencyInfo.Current.CuryID;
invoice.PaySel = true;
invoice.IsTaxPosted = false;
invoice.IsTaxValid = false;
invoice.CuryVatTaxableTotal = 0m;
invoice.CuryVatExemptTotal = 0m;
invoice.PendingPPD = false;
invoice.NoteID = null;
invoice = docgraph.Document.Insert(invoice);
XTDETSetup xtSetup = PXSelect<XTDETSetup>.Select(Base);
if (xtSetup != null)
{
invoice.PayTypeID = xtSetup.PaymentMethodID;
}
BAccount2 bAccount2 = PXSelectJoin<BAccount2, LeftJoin<Branch, On<Branch.bAccountID, Equal<BAccount2.bAccountID>>>,
Where<Branch.branchID, Equal<Required<Branch.branchID>>>>.Select(Base, PXAccess.GetBranchID());
if (bAccount2 != null)
{
var bAccountExt = bAccount2.GetExtension<BAccountExt>();
if (bAccountExt != null && bAccountExt.UsrCashAccountCD != null)
{
CashAccount Cash = PXSelect<CashAccount, Where<CashAccount.cashAccountCD, In<Required<CashAccount.cashAccountCD>>>>.Select(Base, bAccountExt.UsrCashAccountCD);
if (Cash != null)
{
invoice.PayAccountID = Cash.CashAccountID;
}
}
}
if (doc.IsChildRetainageDocument())
{
invoice.OrigDocType = doc.OrigDocType;
invoice.OrigRefNbr = doc.OrigRefNbr;
}
else
{
invoice.OrigDocType = doc.DocType;
invoice.OrigRefNbr = doc.RefNbr;
}
XTAPInvoice xtapi = PXCache<APInvoice>.GetExtension<XTAPInvoice>(invoice);
xtb04Sunat sunat = PXSelect<xtb04Sunat, Where<xtb04Sunat.codigo, Equal<Required<xtb04Sunat.codigo>>>>.Select(Base, "D1");
if (sunat != null)
{
NumberingSequence sequence = PXSelect<NumberingSequence,
Where<NumberingSequence.numberingID, Equal<Required<NumberingSequence.numberingID>>>>.Select(Base, sunat.NroSecuencia);
if (sequence != null)
{
var secu = PEFEHelper.NextSecuenceNumber(sequence);
string[] sepa = secu.Split('-');
var serie = sepa[0];
var Nrodocumento = sepa[1];
xtapi.Serie = serie;
xtapi.NroDocumento = Nrodocumento;
xtapi.TBienServ = "000";
xtapi.TDocSunat = sunat.Codigo;
xtapi.Detraccion = false;
}
}
/*Modificado Fin*/
if (tDETSetup.APAccountID != null)
{
invoice.APAccountID = tDETSetup.APAccountID;
}
docgraph.Document.Update(invoice);
#endregion
#region New document detail, credit adjustment
APTran xtran = PXSelect<APTran,
Where<APTran.tranType,
Equal<Required<APTran.tranType>>, And<APTran.refNbr, Equal<Required<APTran.refNbr>>,
And<APTran.tranDesc, Equal<Required<APTran.tranDesc>>>>>>.Select(Base, api.DocType, api.RefNbr, "Detraccion");
APTran tran = PXCache<APTran>.CreateCopy(xtran);
if (xtran != null)
{
APTran tranx = new APTran();
tranx.TranType = invoice.DocType;
tranx.RefNbr = invoice.RefNbr;
var extnew = tran.GetExtension<APTranExt>();
tranx.CuryLineAmt = Math.Round(p_AmtDetrac * -1, 0);
tranx.CuryTranAmt = Math.Round(p_AmtDetrac * -1, 0);
tranx.TranID = null;
tranx.DrCr = "D";
tranx.Released = true;
tranx.CuryInfoID = invoice.CuryInfoID;
tranx.PPVDocType = null;
tranx.PPVRefNbr = null;
extnew.UsrTipoTransaccion = "AFEC3";
docgraph.Transactions.Update(tranx);
}
#endregion
docgraph.Save.Press();
}
ts.Complete(Base);
}
}
return ret;
}
}
}
}
这是插入、换行和修改金额的结果,但总的细节没有减少。 你能告诉我我失败了吗?
这是我要在新行上创建的文档。
AP发布和结果。
第三步
第四步
信用调整结果
文件头,我创建了,但是细节还没有创建
步骤 5
我希望我的要求很清楚。
不胜感激,苦了我太多了,版本是2022R2
请务必在设置行值后调用 ViewAPTran.Update(row)。当 AP Tran View 的 Update() 方法运行时,您显示的标题字段将更新为正确的值。