protected virtual void FATran_FinPeriodID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e) { FATran tran = (FATran)e.Row; if (tran == null || tran.AssetID == null || tran.BookID == null) { return; } try { FABookPeriod p = PXSelect <FABookPeriod, Where <FABookPeriod.bookID, Equal <Required <FABookPeriod.bookID> >, And <FABookPeriod.finPeriodID, Equal <Required <FABookPeriod.finPeriodID> > > > > .Select(this, tran.BookID, (string)e.NewValue); if (p == null) { throw new PXSetPropertyException(Messages.NoPeriodsDefined); } FABookBalance bal = PXSelect <FABookBalance, Where <FABookBalance.assetID, Equal <Required <FABookBalance.assetID> >, And <FABookBalance.bookID, Equal <Required <FABookBalance.bookID> > > > > .Select(this, tran.AssetID, tran.BookID); if ((tran.TranType == FATran.tranType.DepreciationPlus || tran.TranType == FATran.tranType.DepreciationMinus) && tran.Origin == FARegister.origin.Adjustment) { if (!string.IsNullOrEmpty(bal.CurrDeprPeriod) && String.Compare((string)e.NewValue, bal.CurrDeprPeriod) >= 0) { throw new PXSetPropertyException(CS.Messages.Entry_LT, FinPeriodIDFormattingAttribute.FormatForError(bal.CurrDeprPeriod)); } if (!string.IsNullOrEmpty(bal.LastDeprPeriod) && String.Compare((string)e.NewValue, bal.LastDeprPeriod) > 0) { throw new PXSetPropertyException(CS.Messages.Entry_LE, FinPeriodIDFormattingAttribute.FormatForError(bal.LastDeprPeriod)); } } } catch (PXSetPropertyException) { e.NewValue = FinPeriodSelectorAttribute.FormatForDisplay((string)e.NewValue); throw; } }
public static void ProcessPendingVATProc(List <TaxTran> list) { JournalEntry je = PXGraph.CreateInstance <JournalEntry>(); PXCache dummycache = je.Caches[typeof(TaxTran)]; dummycache = je.Caches[typeof(VATTaxTran)]; je.Views.Caches.Add(typeof(VATTaxTran)); DocumentList <Batch> created = new DocumentList <Batch>(je); foreach (TaxTran taxtran in list) { PXProcessing <TaxTran> .SetCurrentItem(taxtran); if (string.IsNullOrEmpty(taxtran.TaxInvoiceNbr) == true || taxtran.TaxInvoiceDate == null) { //PXProcessing<TaxTran>.SetWarning(Messages.CannotProcessW); PXProcessing <TaxTran> .SetError(Messages.CannotProcessW); } else { using (PXTransactionScope ts = new PXTransactionScope()) { foreach (PXResult <VATTaxTran, CurrencyInfo, Tax> res in PXSelectJoin <VATTaxTran, InnerJoin <CurrencyInfo, On <CurrencyInfo.curyInfoID, Equal <VATTaxTran.curyInfoID> >, InnerJoin <Tax, On <Tax.taxID, Equal <VATTaxTran.taxID> > > >, Where <VATTaxTran.module, Equal <Current <TaxTran.module> >, And <VATTaxTran.tranType, Equal <Current <TaxTran.tranType> >, And <VATTaxTran.refNbr, Equal <Current <TaxTran.refNbr> >, And <VATTaxTran.taxID, Equal <Current <TaxTran.taxID> > > > > > > .SelectSingleBound(je, new object[] { taxtran })) { VATTaxTran n = (VATTaxTran)res; CurrencyInfo info = (CurrencyInfo)res; Tax x = (Tax)res; string strFinPeriodID = FinPeriodSelectorAttribute.PeriodFromDate(taxtran.TaxInvoiceDate); SegregateBatch(je, info.CuryID, taxtran.TaxInvoiceDate, strFinPeriodID, created); n.TaxInvoiceNbr = taxtran.TaxInvoiceNbr; n.TaxInvoiceDate = taxtran.TaxInvoiceDate; je.Caches[typeof(VATTaxTran)].Update(n); CurrencyInfo new_info = PXCache <CurrencyInfo> .CreateCopy(info); new_info.CuryInfoID = null; new_info.ModuleCode = "GL"; new_info.BaseCalc = false; new_info = je.currencyinfo.Insert(new_info) ?? new_info; //reverse original transaction { GLTran tran = new GLTran(); tran.AccountID = n.AccountID; tran.SubID = n.SubID; tran.CuryDebitAmt = (n.TaxType == TaxType.PendingSales && ReportTaxProcess.GetMult(n) == 1m) ? n.CuryTaxAmt : 0m; tran.DebitAmt = (n.TaxType == TaxType.PendingSales && ReportTaxProcess.GetMult(n) == 1m) ? n.TaxAmt : 0m; tran.CuryCreditAmt = (n.TaxType == TaxType.PendingSales && ReportTaxProcess.GetMult(n) == 1m) ? 0m : n.CuryTaxAmt; tran.CreditAmt = (n.TaxType == TaxType.PendingSales && ReportTaxProcess.GetMult(n) == 1m) ? 0m : n.TaxAmt; tran.TranType = n.TranType; tran.TranClass = "N"; tran.RefNbr = n.RefNbr; tran.TranDesc = n.TaxInvoiceNbr; tran.TranPeriodID = strFinPeriodID; tran.FinPeriodID = strFinPeriodID; tran.TranDate = n.TaxInvoiceDate; tran.CuryInfoID = new_info.CuryInfoID; tran.Released = true; je.GLTranModuleBatNbr.Insert(tran); VATTaxTran newtran = PXCache <VATTaxTran> .CreateCopy(n); newtran.Module = "GL"; newtran.TranType = (n.TaxType == TaxType.PendingSales) ? TaxAdjustmentType.ReverseOutputVAT : TaxAdjustmentType.ReverseInputVAT; newtran.RefNbr = newtran.TaxInvoiceNbr; newtran.TranDate = newtran.TaxInvoiceDate; newtran.CuryTaxableAmt = -ReportTaxProcess.GetMult(n.Module, n.TranType, (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase, (short)1) * newtran.CuryTaxableAmt; newtran.TaxableAmt = -ReportTaxProcess.GetMult(n.Module, n.TranType, (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase, (short)1) * newtran.TaxableAmt; newtran.CuryTaxAmt = -ReportTaxProcess.GetMult(n.Module, n.TranType, (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase, (short)1) * newtran.CuryTaxAmt; newtran.TaxAmt = -ReportTaxProcess.GetMult(n.Module, n.TranType, (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase, (short)1) * newtran.TaxAmt; je.Caches[typeof(VATTaxTran)].Insert(newtran); } //reclassify to VAT account { GLTran tran = new GLTran(); tran.AccountID = (n.TaxType == TaxType.PendingSales) ? x.SalesTaxAcctID : x.PurchTaxAcctID; tran.SubID = (n.TaxType == TaxType.PendingSales) ? x.SalesTaxSubID : x.PurchTaxSubID; tran.CuryDebitAmt = (n.TaxType == TaxType.PendingSales && ReportTaxProcess.GetMult(n) == 1m) ? 0m : n.CuryTaxAmt; tran.DebitAmt = (n.TaxType == TaxType.PendingSales && ReportTaxProcess.GetMult(n) == 1m) ? 0m : n.TaxAmt; tran.CuryCreditAmt = (n.TaxType == TaxType.PendingSales && ReportTaxProcess.GetMult(n) == 1m) ? n.CuryTaxAmt : 0m; tran.CreditAmt = (n.TaxType == TaxType.PendingSales && ReportTaxProcess.GetMult(n) == 1m) ? n.TaxAmt : 0m; tran.TranType = n.TranType; tran.TranClass = "N"; tran.RefNbr = n.RefNbr; tran.TranDesc = n.TaxInvoiceNbr; tran.TranPeriodID = strFinPeriodID; tran.FinPeriodID = strFinPeriodID; tran.TranDate = n.TaxInvoiceDate; tran.CuryInfoID = new_info.CuryInfoID; tran.Released = true; je.GLTranModuleBatNbr.Insert(tran); VATTaxTran newtran = PXCache <VATTaxTran> .CreateCopy(n); newtran.Module = "GL"; newtran.TranType = (n.TaxType == TaxType.PendingSales) ? TaxAdjustmentType.OutputVAT : TaxAdjustmentType.InputVAT; newtran.TaxType = (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase; newtran.AccountID = (n.TaxType == TaxType.PendingSales) ? x.SalesTaxAcctID : x.PurchTaxAcctID; newtran.SubID = (n.TaxType == TaxType.PendingSales) ? x.SalesTaxSubID : x.PurchTaxSubID; newtran.RefNbr = newtran.TaxInvoiceNbr; newtran.TranDate = newtran.TaxInvoiceDate; newtran.CuryTaxableAmt = ReportTaxProcess.GetMult(n.Module, n.TranType, (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase, (short)1) * newtran.CuryTaxableAmt; newtran.TaxableAmt = ReportTaxProcess.GetMult(n.Module, n.TranType, (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase, (short)1) * newtran.TaxableAmt; newtran.CuryTaxAmt = ReportTaxProcess.GetMult(n.Module, n.TranType, (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase, (short)1) * newtran.CuryTaxAmt; newtran.TaxAmt = ReportTaxProcess.GetMult(n.Module, n.TranType, (n.TaxType == TaxType.PendingSales) ? TaxType.Sales : TaxType.Purchase, (short)1) * newtran.TaxAmt; je.Caches[typeof(VATTaxTran)].Insert(newtran); } } je.Save.Press(); ts.Complete(); } PXProcessing <TaxTran> .SetProcessed(); } } }