Я пытаюсь добавить дебетовый адж. на момент выдачи платежа.
Как вы видите мой код Debit Adj, я верю в это и освобождаю его, но он не добавляется в мои детали.
public IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
{
Base.Save.Press();
PXCache cache = Base.Document.Cache;
APPayment app = Base.Document.Current;
APAdjust apa = Base.Adjustments.Current;
xtRtnSetup xtRtn = viewRtnSetup.Select();
xtDocRetencion docRetencion = new xtDocRetencion();
bool errorOccured = false;
List<APPayment> listapa = new List<APPayment>();
foreach (APPayment apdoc in adapter.Get<APPayment>())
{
if (string.IsNullOrEmpty(apdoc.ExtRefNbr))
{
cache.RaiseExceptionHandling<APPayment.extRefNbr>(apdoc, apdoc.ExtRefNbr,
new PXRowPersistingException(typeof(APPayment.extRefNbr).Name, null, ErrorMessages.FieldIsEmpty, typeof(APPayment.extRefNbr).Name));
errorOccured = true;
}
listapa.Add(apdoc);
}
if (errorOccured)
{
throw new PXException();
}
IEnumerable facturas = baseMethod(adapter);
this.addNotaCredito();
return facturas;
}
private void CreaAjusteCargo(List<APAdjust> apDocs, xtRtnSetup xtRtn, int? vendorID, decimal? MontoRet)
{
List<string> lnrodoc = new List<string>();
foreach (APAdjust item in apDocs)
{
if (item.VendorID == vendorID)
{
if (!lnrodoc.Contains(item.AdjdRefNbr))
{
lnrodoc.Add(item.AdjdRefNbr);
}
}
}
APInvoiceEntry graphapi = PXGraph.CreateInstance<APInvoiceEntry>();
#region Cabecera
APInvoice api = PXSelect<APInvoice, Where<APInvoice.refNbr, In<Required<APInvoice.refNbr>>, And<APInvoice.docType, Equal<APInvoice.docType>>>>.Select(Base, lnrodoc.ToArray(), APDocType.Invoice);
api.CuryLineTotal = 0;
api.CuryDocBal = 0;
api.CuryOrigDocAmt = 0;
APInvoice newinvoice = PXCache<APInvoice>.CreateCopy(api);
newinvoice.DocType = APDocType.DebitAdj;
newinvoice.RefNbr = null;
newinvoice = graphapi.Document.Insert(newinvoice);
//graphapi.Document.Cache.Persist(PXDBOperation.Insert);
//graphapi.Document.Cache.Persist(PXDBOperation.Update);
newinvoice.DocDesc = "Retención del IGV";
newinvoice.LineTotal = 0;
newinvoice.CuryDiscTot = 0;
newinvoice.CuryVatTaxableTotal = 0;
newinvoice.CuryVatExemptTotal = 0;
newinvoice.CuryTaxTotal = 0;
newinvoice.CuryOrigWhTaxAmt = 0;
newinvoice.CuryRoundDiff = 0;
newinvoice.CuryOrigDocAmt = MontoRet;
newinvoice.OrigDocAmt = 0;
newinvoice.CuryOrigDiscAmt = 0;
newinvoice.TermsID = null;
newinvoice.DueDate = null;
newinvoice.DiscDate = null;
newinvoice.PaySel = true;
newinvoice.IsTaxPosted = false;
newinvoice.IsTaxValid = false;
newinvoice.CuryVatTaxableTotal = 0m;
newinvoice.CuryVatExemptTotal = 0m;
newinvoice.PendingPPD = false;
newinvoice.BatchNbr = null;
newinvoice.Released = false;
newinvoice.Status = "B";
newinvoice.CuryTaxAmt = 0;
newinvoice.TaxAmt = 0;
newinvoice.TaxZoneID = null;
newinvoice.VatTaxableTotal = 0;
newinvoice.DocBal = 0;
newinvoice.TaxTotal = 0;
newinvoice.OrigDocAmtWithRetainageTotal = 0;
newinvoice.OpenDoc = true;
newinvoice.Hold = false;
if (api.IsChildRetainageDocument())
{
newinvoice.OrigDocType = api.OrigDocType;
newinvoice.OrigRefNbr = api.OrigRefNbr;
}
else
{
newinvoice.OrigDocType = api.DocType;
newinvoice.OrigRefNbr = api.RefNbr;
}
foreach (NumberingSequence item in ARNbrSeq.Select(this, "APCERTRET"))
{
if (item.NumberingID == "APCERTRET")
{
PXCache pchCache = graphapi.Document.Cache;
XTAPInvoice xtapi = pchCache.GetExtension<XTAPInvoice>(newinvoice);
//XTAPInvoice xtapi = PXCache<APInvoice>.GetExtension<XTAPInvoice>(invoice);
var secu = NextSecuenceNumber(item);
string[] sepa = secu.Split('-');
var resul = sepa[0];
var res = sepa[1];
xtapi.Serie = resul;
xtapi.NroDocumento = res;
xtapi.TDocSunat = "20";
xtapi.TBienServ = "000";
xtapi.Detraccion = false;
break;
}
}
newinvoice = graphapi.Document.Update(newinvoice);
//graphapi.Document.Cache.Persist(PXDBOperation.Update);
//graphapi.Document.Cache.Persist(PXDBOperation.Update);
//newinvoice = graphapi.Document.Update(newinvoice);
//graphapi.Document.Cache.Persist(PXDBOperation.Insert);
#endregion
#region Detalle
APTran srcTran = PXSelect<APTran, Where<APTran.tranType, Equal<Required<APTran.tranType>>, And<APTran.refNbr, Equal<Required<APTran.refNbr>>>>>.Select(Base, api.DocType, api.RefNbr);
Account account = PXSelect<Account, Where<Account.accountCD,
In<Required<Account.accountCD>>>>.Select(Base, xtRtn.Acct.Trim());
Sub sub = PXSelect<Sub, Where<Sub.subID,
In<Required<Sub.subID>>>>.Select(Base, xtRtn.SubAcct);
APTran tran = PXCache<APTran>.CreateCopy(srcTran);
tran.TranType = APDocType.DebitAdj;
tran.RefNbr = null;
tran = graphapi.Transactions.Insert(tran);
//graphapi.Transactions.Cache.Persist(PXDBOperation.Update);
//graphapi.Transactions.Cache.Persist(PXDBOperation.Update);
tran.CuryLineAmt = MontoRet;
tran.CuryTranAmt = MontoRet;
tran.TranID = null;
string origDrCr = tran.DrCr;
tran.DrCr = null;
tran.PPVDocType = null;
tran.PPVRefNbr = null;
tran.InventoryID = null;
tran.TranDesc = "Retencion";
tran.UOM = null;
tran.AccountID = account.AccountID;
tran.SubID = sub.SubID;
tran.TaxCategoryID = "INAFECTO";
tran.BatchNbr = "";
tran.Released = false;
tran.CuryUnitCost = 0;
tran.TranAmt = 0;
tran.LineAmt = 0;
tran.DiscCost = 0;
tran.CuryDiscCost = 0;
tran.Qty = 1;
tran.Released = false;
tran.DrCr = "C";
tran = graphapi.Transactions.Update(tran);
//graphapi.Transactions.Cache.Persist(PXDBOperation.Update);
//graphapi.Transactions.Cache.Persist(PXDBOperation.Update);
//graphapi.Save.Press();
//graphapi.Actions.PressSave();
#endregion
#region Liberamos Ajuste por Debito
List<APRegister> list = new List<APRegister>();
if (!list.Contains(graphapi.Document.Current))
{
list.Add(graphapi.Document.Current);
}
if (!listview.Contains(graphapi.Document.Current))
{
listview.Add(graphapi.Document.Current);
}
if (list.Count == 0)
{
throw new PXException(Messages.Document_Status_Invalid);
}
graphapi.Actions.PressSave();
PXLongOperation.StartOperation(graphapi, delegate () { APDocumentRelease.ReleaseDoc(list, false); });
#endregion
}
protected void addNotaCredito()
{
PXCache cache = Base.Document.Cache;
APPayment app = Base.Document.Current;
APAdjust apa = Base.Adjustments.Current;
xtRtnSetup xtRtn = viewRtnSetup.Select();
xtDocRetencion docRetencion = new xtDocRetencion();
foreach (APAdjust detalle in Base.Adjustments.Select())
{
APInvoice apinv = PXSelect<APInvoice, Where<APInvoice.refNbr, In<Required<APInvoice.refNbr>>,
And<APInvoice.docType, Equal<APInvoice.docType>,
And<APInvoice.vendorID, Equal<APInvoice.vendorID>>
>>>.Select(Base, detalle.AdjdRefNbr, detalle.AdjdDocType, app.VendorID);
XTAPInvoice apicon = PXCache<APInvoice>.GetExtension<XTAPInvoice>(apinv);
if (!(apicon.Detraccion == true || apicon.AutoDetraccion == true) && apinv.CuryTaxTotal != 0)
{
docRetencion.DocType = detalle.AdjdDocType;
docRetencion.RefNbr = detalle.AdjdRefNbr;
docRetencion.VendorID = detalle.VendorID;
docRetencion.DocDesc = apinv.DocDesc;
docRetencion.DocDate = apinv.DocDate;
docRetencion.CuryAdjgAmt = detalle.AdjdDocType == APDocType.DebitAdj ? detalle.CuryAdjgAmt * -1 : detalle.CuryAdjgAmt;
docRetencion.CuryDocBal = detalle.CuryDocBal;
docRetencion.Curyid = apinv.CuryID;
docRetencion.ExchangeRate = 0;
docRetencion.PayPartial = apinv.CuryOrigDocAmt == apinv.CuryDocBal ? false : true;
docRetencion.Flag = false;
docRetencion.InvoiceNbr = apinv.InvoiceNbr;
docRetencion.PayDate = apinv.PayDate;
docRetencion = this.xtDocRetencions.Insert(docRetencion);
Base.Actions.PressSave();
}
apDocs.Add(detalle);
xtvMontoRetenido ret = PXSelect<xtvMontoRetenido, Where<xtvMontoRetenido.vendorID,
In<Required<xtvMontoRetenido.vendorID>>>>.Select(Base, app.VendorID);
if (ret != null)
{
CreaAjusteCargo(apDocs, xtRtn, app.VendorID, ret.MontoRet);
APPaymentEntry graphapay = PXGraph.CreateInstance<APPaymentEntry>();
foreach (APAdjust item in Base.Adjustments.Select())
{
foreach (APRegister apr in PXSelect<APRegister, Where<APRegister.docType, In<Required<APRegister.docType>>,
And<APRegister.origRefNbr, Equal<Required<APRegister.origRefNbr>>>>>.Select(Base, APDocType.DebitAdj, item.AdjdRefNbr))
{
if (item.AdjdRefNbr == apr.OrigRefNbr)
{
APAdjust adj = new APAdjust();
adj.AdjdDocType = apr.DocType;
adj.AdjdRefNbr = apr.RefNbr;
adj.CuryAdjgAmt = apr.CuryOrigDocAmt;
adj.CuryAdjdAmt = apr.CuryOrigDocAmt;
adj.AdjAmt = apr.OrigDocAmt;
adj.RGOLAmt = 0;
adj.AdjgDocType = APDocType.Check;
adj.AdjgRefNbr = app.RefNbr;
adj=graphapay.Adjustments.Update(adj);
break;
}
}
}
graphapay.Save.Press();
graphapay.Actions.PressSave();
graphapay.Persist();
}
}
}
Чего я хочу добиться, так это того, чтобы при деблокировании платежа дебетовый адж. должен быть создан и добавлен в строку детализации. На прикрепленном изображении документ был выпущен, создав дебетовый Adj и выпуская его по очереди. но я не добавляю это к деталям.
Пожалуйста, скажите мне, как я могу добавить дебетовый Adj. на момент выпуска.
Спасибо за вашу поддержку