protected void _(Events.RowInserting <APInvoice> e) { if (e.Row == null || Base.vendor.Current == null || activateGUI.Equals(false)) { return; } APRegisterExt regisExt = PXCache <APRegister> .GetExtension <APRegisterExt>(e.Row); string vATIncode = regisExt.UsrVATInCode ?? string.Empty; if (string.IsNullOrEmpty(vATIncode)) { CSAnswers cSAnswers = SelectCSAnswers(Base, Base.vendor.Current.NoteID); vATIncode = (e.Row.IsRetainageDocument == true || cSAnswers == null) ? null : cSAnswers.Value; } regisExt.UsrVATInCode = e.Row.DocType.Equals(APDocType.DebitAdj, System.StringComparison.CurrentCulture) && !string.IsNullOrEmpty(vATIncode) ? TWGUIFormatCode.vATInCode23 /*(int.Parse(vATIncode) + 2).ToString()*/ : vATIncode; }
public void Persist(PersistDelegate baseMethod) { baseMethod(); APRegister doc = Base.APDocument.Current; APRegisterExt docExt = PXCache <APRegister> .GetExtension <APRegisterExt>(doc); // Check for document and released flag if (TWNGUIValidation.ActivateTWGUI(Base) == true && doc != null && doc.Released == true && doc.DocType.IsIn(APDocType.Invoice, APDocType.DebitAdj)) { //if (Base.APTaxTran_TranType_RefNbr.Current == null) //{ // throw new PXException(TWMessages.NoInvTaxDtls); //} foreach (TWNManualGUIAPBill row in SelectFrom <TWNManualGUIAPBill> .Where <TWNManualGUIAPBill.docType.IsEqual <@P.AsString> .And <TWNManualGUIAPBill.refNbr.IsEqual <@P.AsString> > > .View.Select(Base, doc.DocType, doc.RefNbr)) { // Avoid standard logic calling this method twice and inserting duplicate records into TWNGUITrans. if (CountExistedRec(Base, row.GUINbr, row.VATInCode, doc.RefNbr) >= 1) { return; } if (Tax.PK.Find(Base, row.TaxID).GetExtension <TaxExt>().UsrTWNGUI != true) { continue; } Vendor vendor = Vendor.PK.Find(Base, row.VendorID); using (PXTransactionScope ts = new PXTransactionScope()) { TWNReleaseProcess rp = PXGraph.CreateInstance <TWNReleaseProcess>(); TWNGUITrans tWNGUITrans = rp.InitAndCheckOnAP(row.GUINbr, row.VATInCode); rp.CreateGUITrans(new STWNGUITran() { VATCode = row.VATInCode, GUINbr = row.GUINbr, GUIStatus = TWNGUIStatus.Used, BranchID = Base.APTran_TranType_RefNbr.Current.BranchID, GUIDirection = TWNGUIDirection.Receipt, GUIDate = row.GUIDate, GUITitle = vendor?.AcctName, TaxZoneID = row.TaxZoneID, TaxCategoryID = row.TaxCategoryID, TaxID = row.TaxID, TaxNbr = row.TaxNbr, OurTaxNbr = row.OurTaxNbr, NetAmount = row.NetAmt, TaxAmount = row.TaxAmt, AcctCD = vendor?.AcctCD, AcctName = vendor?.AcctName, DeductionCode = row.Deduction, Remark = row.Remark, BatchNbr = doc.BatchNbr, OrderNbr = doc.RefNbr }); if (tWNGUITrans != null) { if (tWNGUITrans.NetAmtRemain < row.NetAmt) { throw new PXException(TWMessages.RemainAmt); } ViewGUITrans.SetValueExt <TWNGUITrans.netAmtRemain>(tWNGUITrans, (tWNGUITrans.NetAmtRemain -= row.NetAmt)); ViewGUITrans.SetValueExt <TWNGUITrans.taxAmtRemain>(tWNGUITrans, (tWNGUITrans.TaxAmtRemain -= row.TaxAmt)); tWNGUITrans = ViewGUITrans.Update(tWNGUITrans); } // Manually Saving as base code will not call base graph persis. ViewGUITrans.Cache.Persist(PXDBOperation.Insert); ViewGUITrans.Cache.Persist(PXDBOperation.Update); ts.Complete(Base); } } } // Triggering after save events. ViewGUITrans.Cache.Persisted(false); }