/// <summary> /// To add the line tax based on ZCRMTax class instance. /// </summary> /// <param name="lineTax">ZCRMTax class instance</param> public void AddLineTax(ZCRMTax lineTax) { LineTax.Add(lineTax); }
private InvoiceTran AddTaxes <TAPDocument, TInvoiceMapping, TGraph, TAPDocumentGraphExtension> (TAPDocumentGraphExtension apDocumentGraphExtension, TGraph docgraph, ExpenseClaimEntry expenseClaimGraph, TAPDocument invoice, decimal signOperation, EPExpenseClaimDetails claimdetail, InvoiceTran tran, bool isTipTran) where TGraph : PXGraph, new() where TAPDocument : InvoiceBase, new() where TInvoiceMapping : IBqlMapping where TAPDocumentGraphExtension : PX.Objects.Common.GraphExtensions.Abstract.InvoiceBaseGraphExtension <TGraph, TAPDocument, TInvoiceMapping> { var cmdEPTaxTran = new PXSelect <EPTaxTran, Where <EPTaxTran.claimDetailID, Equal <Required <EPTaxTran.claimDetailID> > > >(docgraph); var cmdEPTax = new PXSelect <EPTax, Where <EPTax.claimDetailID, Equal <Required <EPTax.claimDetailID> >, And <EPTax.taxID, Equal <Required <EPTax.taxID> > > > >(docgraph); if (isTipTran) { cmdEPTaxTran.WhereAnd <Where <EPTaxTran.isTipTax, Equal <True> > >(); cmdEPTax.WhereAnd <Where <EPTax.isTipTax, Equal <True> > >(); } else { cmdEPTaxTran.WhereAnd <Where <EPTaxTran.isTipTax, Equal <False> > >(); cmdEPTax.WhereAnd <Where <EPTax.isTipTax, Equal <False> > >(); } CurrencyInfo expenseCuriInfo = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <EPExpenseClaimDetails.curyInfoID> > > > .SelectSingleBound(docgraph, null, claimdetail.CuryInfoID); CurrencyInfo currencyinfo = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <EPExpenseClaimDetails.curyInfoID> > > > .SelectSingleBound(docgraph, null, claimdetail.ClaimCuryInfoID); foreach (EPTaxTran epTaxTran in cmdEPTaxTran.Select(claimdetail.ClaimDetailID)) { #region Add taxes GenericTaxTran new_aptax = apDocumentGraphExtension.TaxTrans.Search <GenericTaxTran.taxID>(epTaxTran.TaxID); if (new_aptax == null) { new_aptax = new GenericTaxTran(); new_aptax.TaxID = epTaxTran.TaxID; TaxAttribute.SetTaxCalc <InvoiceTran.taxCategoryID>(apDocumentGraphExtension.InvoiceTrans.Cache, null, TaxCalc.NoCalc); new_aptax = apDocumentGraphExtension.TaxTrans.Insert(new_aptax); if (new_aptax != null) { new_aptax = (GenericTaxTran)apDocumentGraphExtension.TaxTrans.Cache.CreateCopy(new_aptax); new_aptax.CuryTaxableAmt = 0m; new_aptax.CuryTaxAmt = 0m; new_aptax.CuryExpenseAmt = 0m; new_aptax = apDocumentGraphExtension.TaxTrans.Update(new_aptax); } } if (new_aptax != null) { EPTax epTax = cmdEPTax.Select(claimdetail.ClaimDetailID, new_aptax.TaxID); new_aptax = (GenericTaxTran)apDocumentGraphExtension.TaxTrans.Cache.CreateCopy(new_aptax); new_aptax.TaxRate = epTaxTran.TaxRate; new_aptax.CuryTaxableAmt = (new_aptax.CuryTaxableAmt ?? 0m) + epTaxTran.ClaimCuryTaxableAmt * signOperation; new_aptax.CuryTaxAmt = (new_aptax.CuryTaxAmt ?? 0m) + epTaxTran.ClaimCuryTaxAmt * signOperation; new_aptax.CuryTaxAmtSumm = new_aptax.CuryTaxAmt; new_aptax.CuryExpenseAmt = (new_aptax.CuryExpenseAmt ?? 0m) + epTaxTran.ClaimCuryExpenseAmt * signOperation; new_aptax.NonDeductibleTaxRate = epTaxTran.NonDeductibleTaxRate; TaxAttribute.SetTaxCalc <InvoiceTran.taxCategoryID>(apDocumentGraphExtension.InvoiceTrans.Cache, null, TaxCalc.ManualCalc); new_aptax = apDocumentGraphExtension.TaxTrans.Update(new_aptax); //On first inserting APTaxTran APTax line will be created automatically. //However, new APTax will not be inserted on APTaxTran line update, even if we already have more lines. //So, we have to do it manually. LineTax aptax = apDocumentGraphExtension.LineTaxes.Search <LineTax.lineNbr, LineTax.taxID>(tran.LineNbr, new_aptax.TaxID); if (aptax == null) { decimal ClaimCuryTaxableAmt = 0m; decimal ClaimCuryTaxAmt = 0m; decimal ClaimCuryExpenseAmt = 0m; if (CurrencyHelper.IsSameCury(claimdetail.CuryInfoID, claimdetail.ClaimCuryInfoID, expenseCuriInfo, currencyinfo)) { ClaimCuryTaxableAmt = epTax.CuryTaxableAmt ?? 0m; ClaimCuryTaxAmt = epTax.CuryTaxAmt ?? 0m; ClaimCuryExpenseAmt = epTax.CuryExpenseAmt ?? 0m; } else if (currencyinfo?.CuryRate != null) { PXCurrencyAttribute.CuryConvCury <EPExpenseClaimDetails.claimCuryInfoID>(expenseClaimGraph.ExpenseClaimDetails.Cache, claimdetail, epTax.TaxableAmt ?? 0m, out ClaimCuryTaxableAmt); PXCurrencyAttribute.CuryConvCury <EPExpenseClaimDetails.claimCuryInfoID>(expenseClaimGraph.ExpenseClaimDetails.Cache, claimdetail, epTax.TaxAmt ?? 0m, out ClaimCuryTaxAmt); PXCurrencyAttribute.CuryConvCury <EPExpenseClaimDetails.claimCuryInfoID>(expenseClaimGraph.ExpenseClaimDetails.Cache, claimdetail, epTax.ExpenseAmt ?? 0m, out ClaimCuryExpenseAmt); } aptax = apDocumentGraphExtension.LineTaxes.Insert(new LineTax() { LineNbr = tran.LineNbr, TaxID = new_aptax.TaxID, TaxRate = epTax.TaxRate, CuryTaxableAmt = ClaimCuryTaxableAmt * signOperation, CuryTaxAmt = ClaimCuryTaxAmt * signOperation, CuryExpenseAmt = ClaimCuryExpenseAmt * signOperation }); } Tax taxRow = PXSelect <Tax, Where <Tax.taxID, Equal <Required <Tax.taxID> > > > .Select(docgraph, new_aptax.TaxID); if ((taxRow.TaxCalcLevel == CSTaxCalcLevel.Inclusive || (invoice.TaxCalcMode == TaxCalculationMode.Gross && taxRow.TaxCalcLevel == CSTaxCalcLevel.CalcOnItemAmt)) && (tran.CuryTaxableAmt == null || tran.CuryTaxableAmt == 0m)) { tran.CuryTaxableAmt = epTaxTran.ClaimCuryTaxableAmt * signOperation; tran.CuryTaxAmt = epTaxTran.ClaimCuryTaxAmt * signOperation; tran = apDocumentGraphExtension.InvoiceTrans.Update(tran); } } #endregion } return(tran); }