コード例 #1
0
        protected virtual void TaxRev_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            TaxRev taxrev = e.Row as TaxRev;

            if (taxrev == null)
            {
                return;
            }

            PXUIFieldAttribute.SetEnabled <TaxRev.nonDeductibleTaxRate>(sender, taxrev, taxrev.TaxType != TaxType.Sales);
        }
コード例 #2
0
        protected virtual void TaxRev_RowUpdating(PXCache sender, PXRowUpdatingEventArgs e)
        {
            TaxRev oldTaxRev = e.Row as TaxRev;
            TaxRev newTaxRev = e.NewRow as TaxRev;

            if (newTaxRev == null)
            {
                return;
            }

            if (Tax.Current.TaxVendorID == null)
            {
                if (oldTaxRev == null)
                {
                    return;
                }

                switch (oldTaxRev.TaxBucketID)
                {
                case -1:
                    oldTaxRev.TaxType = "P";
                    break;

                case -2:
                    oldTaxRev.TaxType = "S";
                    break;
                }
            }
            else if (newTaxRev.TaxBucketID != null)
            {
                TaxBucket bucket = (TaxBucket)
                                   PXSelect <TaxBucket,
                                             Where <TaxBucket.vendorID, Equal <Current <Tax.taxVendorID> >,
                                                    And <TaxBucket.bucketID, Equal <Required <TaxBucket.bucketID> > > > >
                                   .Select(this, newTaxRev.TaxBucketID);

                if (bucket != null)
                {
                    newTaxRev.TaxType = bucket.BucketType;
                }
            }

            var summary =
                PXSelect <TaxRev,
                          Where <TaxRev.taxID, Equal <Current <Tax.taxID> >,
                                 And <TaxRev.taxType, Equal <Required <TaxRev.taxType> >,
                                      And <TaxRev.startDate, Equal <Required <TaxRev.startDate> > > > > >
                .Select(this, newTaxRev.TaxType, newTaxRev.StartDate);

            e.Cancel = UpdateRevisions(sender, newTaxRev, summary, false);
        }
コード例 #3
0
        protected virtual void Tax_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            Tax newTax = (Tax)e.Row;
            Tax oldTax = (Tax)e.OldRow;

            ClearOldWarningsAndErrors(sender, newTax);
            CheckAndFixTaxRates(newTax);
            SetWarningsOnRowUpdate(sender, newTax, oldTax);
            ProcessTaxRevOnTaxVendorChangeOnTaxUpdate(sender, newTax, oldTax);
            VerifyTaxRevReportingGroupTypesOnTaxUpdate(newTax, oldTax);

            if (!sender.ObjectsEqual <Tax.outDate>(e.Row, e.OldRow))
            {
                PXSelectBase <TaxRev> TaxRevFiltered = new
                                                       PXSelect <TaxRev,
                                                                 Where <TaxRev.taxID, Equal <Current <Tax.taxID> >,
                                                                        And <TaxRev.startDate, Greater <Required <Tax.outDate> > > > >(this);

                if (newTax.OutDate.HasValue && TaxRevFiltered.Select(newTax.OutDate).Count > 0)
                {
                    Tax.Cache.RaiseExceptionHandling <Tax.outDate>(newTax, newTax.OutDate,
                                                                   new PXSetPropertyException(Messages.TaxOutDateTooEarly, PXErrorLevel.Warning));
                }
                else
                {
                    sender.SetValue <Tax.outdated>(e.Row, newTax.OutDate.HasValue);
                    DateTime newEndDate = newTax.OutDate ?? new DateTime(9999, 6, 6);

                    foreach (TaxRev rev in TaxRevisions.Select())
                    {
                        TaxRev revcopy = (TaxRev)TaxRevisions.Cache.CreateCopy(rev);
                        revcopy.EndDate = newEndDate;
                        TaxRevisions.Cache.Update(revcopy);
                    }
                }
            }

            if (!sender.ObjectsEqual <Tax.reportExpenseToSingleAccount>(e.Row, e.OldRow) && newTax.ReportExpenseToSingleAccount == false)
            {
                sender.SetValue <Tax.expenseAccountID>(newTax, null);
                sender.SetValue <Tax.expenseSubID>(newTax, null);
            }

            if (!sender.ObjectsEqual <Tax.reportExpenseToSingleAccount>(e.Row, e.OldRow) && newTax.ReportExpenseToSingleAccount == true)
            {
                sender.SetDefaultExt <Tax.expenseAccountID>(e.Row);
                sender.SetDefaultExt <Tax.expenseSubID>(e.Row);
            }
        }
コード例 #4
0
        protected virtual void TaxRev_RowInserting(PXCache sender, PXRowInsertingEventArgs e)
        {
            TaxRev taxRevision = e.Row as TaxRev;

            if (taxRevision == null)
            {
                return;
            }

            if (Tax.Current.TaxVendorID == null)
            {
                switch (taxRevision.TaxBucketID)
                {
                case -1:
                    taxRevision.TaxType = CSTaxType.Use;
                    break;

                case -2:
                    taxRevision.TaxType = CSTaxType.Sales;
                    break;
                }
            }
            else if (taxRevision.TaxBucketID != null)
            {
                TaxBucket bucket = (TaxBucket)
                                   PXSelect <TaxBucket,
                                             Where <TaxBucket.vendorID, Equal <Current <Tax.taxVendorID> >,
                                                    And <TaxBucket.bucketID, Equal <Required <TaxBucket.bucketID> > > > >
                                   .Select(this, taxRevision.TaxBucketID);

                if (bucket != null)
                {
                    taxRevision.TaxType = bucket.BucketType;
                }
            }

            object StartDate = taxRevision.StartDate;
            object TaxType   = taxRevision.TaxType;
            var    summary   =
                PXSelect <TaxRev,
                          Where <TaxRev.taxID, Equal <Current <Tax.taxID> >,
                                 And <TaxRev.taxType, Equal <Required <TaxRev.taxType> >,
                                      And <TaxRev.startDate, Equal <Required <TaxRev.startDate> > > > > >
                .Select(this, TaxType, StartDate);

            e.Cancel = UpdateRevisions(sender, taxRevision, summary, true);
        }
コード例 #5
0
        protected virtual void TaxTranDefaulting(PXCache sender, TaxTran tran)
        {
            _Tax = SalesTax_Select.Select(tran.TaxID);

            sender.SetDefaultExt <TaxTran.accountID>(tran);
            sender.SetDefaultExt <TaxTran.subID>(tran);
            sender.SetDefaultExt <TaxTran.taxType>(tran);
            SetTaxTranTranDate(tran);

            _TaxRev = SalesTaxRev_Select.Select(tran.TaxID, tran.TaxType, tran.TranDate);

            sender.SetDefaultExt <TaxTran.taxBucketID>(tran);
            sender.SetDefaultExt <TaxTran.taxRate>(tran);

            _Tax    = null;
            _TaxRev = null;
        }
コード例 #6
0
 private bool UpdateRevisions(PXCache sender, TaxRev item, PXResultset <TaxRev> summary, bool PerformUpdate)
 {
     foreach (TaxRev summ_item in summary)
     {
         if (!sender.ObjectsEqual(summ_item, item))
         {
             if (PerformUpdate)
             {
                 summ_item.TaxBucketID = item.TaxBucketID;
                 summ_item.TaxableMax  = item.TaxableMax;
                 summ_item.TaxableMin  = item.TaxableMin;
                 summ_item.TaxRate     = item.TaxRate;
                 summ_item.Outdated    = item.Outdated;
                 TaxRevisions.Cache.Update(summ_item);
             }
             return(true);
         }
     }
     return(false);
 }
コード例 #7
0
		protected virtual void Tax_CuryTaxableAmt_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
		{
			TaxDetail taxdetOrig = e.Row as TaxDetail;
			if (taxdetOrig == null) return;

			decimal newValue = (decimal)(sender.GetValue(e.Row, _CuryTaxableAmt) ?? 0m);
			decimal oldValue = (decimal)(e.OldValue ?? 0m);

			if (_TaxCalc != TaxCalc.NoCalc && e.ExternalCall &&
				newValue != oldValue)
			{
				foreach (object taxrow in SelectTaxes<
					Where<Tax.taxID, Equal<Required<Tax.taxID>>>>(sender.Graph, null, PXTaxCheck.RecalcTotals, taxdetOrig.TaxID))
				{
					TaxDetail taxdet = (TaxDetail)((PXResult)taxrow)[0];
					Tax tax = PXResult.Unwrap<Tax>(taxrow);
					TaxRev taxrev = PXResult.Unwrap<TaxRev>(taxrow);

					CalculateTaxSumTaxAmt(sender, taxdet, tax, taxrev);
				}
			}
		}
コード例 #8
0
ファイル: TaxImport.cs プロジェクト: Vialythen/AcumaticaTest
        private static List <TaxRev> GetRevisions(TaxRecord tr)
        {
            List <TaxRev> list = new List <TaxRev>();

            //TODO:
            //split into 2 revisions if rateovermax is specified;
            //split into 2 revisions if previosRate is specified;
            int cx = 1;

            //outdated:
            if (tr.PreviousRate > 0 && tr.EffectiveDate != null)
            {
                TaxRev rev1 = new TaxRev();
                rev1.TaxID       = tr.TaxID;
                rev1.RevisionID  = cx++;
                rev1.IsImported  = true;
                rev1.Outdated    = true;
                rev1.TaxBucketID = SalesTaxBucketID;
                rev1.StartDate   = DateTime.Parse(TaxRev.DefaultStartDate, CultureInfo.InvariantCulture);
                rev1.EndDate     = tr.EffectiveDate ?? DateTime.Parse(TaxRev.DefaultEndDate, CultureInfo.InvariantCulture);
                rev1.TaxType     = CSTaxType.Sales;
                rev1.TaxRate     = tr.Rate * 100;
                list.Add(rev1);
            }

            //current:
            if (tr.TaxableMax != null && tr.TaxableMax > 0)
            {
                //split into 2:
                TaxRev rev1 = new TaxRev();
                rev1.TaxID       = tr.TaxID;
                rev1.RevisionID  = cx++;
                rev1.IsImported  = true;
                rev1.Outdated    = false;
                rev1.TaxBucketID = SalesTaxBucketID;
                rev1.StartDate   = tr.EffectiveDate ?? DateTime.Parse(TaxRev.DefaultStartDate, CultureInfo.InvariantCulture);
                rev1.EndDate     = tr.EffectiveDate ?? DateTime.Parse(TaxRev.DefaultEndDate, CultureInfo.InvariantCulture);
                rev1.TaxType     = CSTaxType.Sales;
                rev1.TaxRate     = tr.Rate * 100;
                rev1.TaxableMax  = tr.TaxableMax;
                list.Add(rev1);

                TaxRev rev2 = new TaxRev();
                rev2.TaxID       = tr.TaxID;
                rev2.RevisionID  = cx++;
                rev2.IsImported  = true;
                rev2.Outdated    = false;
                rev2.TaxBucketID = SalesTaxBucketID;
                rev2.StartDate   = tr.EffectiveDate ?? DateTime.Parse(TaxRev.DefaultStartDate, CultureInfo.InvariantCulture);
                rev2.EndDate     = tr.EffectiveDate ?? DateTime.Parse(TaxRev.DefaultEndDate, CultureInfo.InvariantCulture);
                rev2.TaxType     = CSTaxType.Sales;
                rev2.TaxRate     = tr.RateOverMax * 100;
                rev2.TaxableMin  = tr.TaxableMax;
                list.Add(rev2);
            }
            else
            {
                TaxRev rev1 = new TaxRev();
                rev1.TaxID       = tr.TaxID;
                rev1.RevisionID  = cx++;
                rev1.IsImported  = true;
                rev1.Outdated    = false;
                rev1.TaxBucketID = SalesTaxBucketID;
                rev1.StartDate   = tr.EffectiveDate ?? DateTime.Parse(TaxRev.DefaultStartDate, CultureInfo.InvariantCulture);
                rev1.EndDate     = DateTime.Parse(TaxRev.DefaultEndDate, CultureInfo.InvariantCulture);
                rev1.TaxType     = CSTaxType.Sales;
                rev1.TaxRate     = tr.Rate * 100;
                list.Add(rev1);
            }
            return(list);
        }
コード例 #9
0
        protected virtual void Tax_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
        {
            Tax  tax                 = (Tax)e.Row;
            bool AlreadyWarned       = false;
            bool isDeductibleSet     = ((Tax)e.Row).DeductibleVAT == true && ((Tax)e.Row).DeductibleVAT != ((Tax)e.OldRow).DeductibleVAT;
            bool isDeductibleRemoved = ((Tax)e.Row).DeductibleVAT == false && ((Tax)e.Row).DeductibleVAT != ((Tax)e.OldRow).DeductibleVAT;

            sender.RaiseExceptionHandling <Tax.taxType>(e.Row, tax.TaxType, null);
            sender.RaiseExceptionHandling <Tax.taxCalcRule>(e.Row, tax.TaxCalcRule, null);
            sender.RaiseExceptionHandling <Tax.taxCalcLevel2Exclude>(e.Row, tax.TaxCalcLevel2Exclude, null);
            sender.RaiseExceptionHandling <Tax.reverseTax>(e.Row, tax.ReverseTax, null);
            sender.RaiseExceptionHandling <Tax.pendingTax>(e.Row, tax.PendingTax, null);
            sender.RaiseExceptionHandling <Tax.exemptTax>(e.Row, tax.ExemptTax, null);
            sender.RaiseExceptionHandling <Tax.statisticalTax>(e.Row, tax.StatisticalTax, null);
            sender.RaiseExceptionHandling <Tax.directTax>(e.Row, tax.DirectTax, null);
            sender.RaiseExceptionHandling <Tax.includeInTaxable>(e.Row, tax.IncludeInTaxable, null);

            CheckAndFixTaxRates(e);

            if (AlreadyWarned == false && tax.TaxType != CSTaxType.VAT && tax.DirectTax == true)
            {
                sender.RaiseExceptionHandling <Tax.taxType>(e.Row, tax.TaxType, new PXSetPropertyException(Messages.ThisOptionCanOnlyBeUsedWithTaxTypeVAT));
                sender.RaiseExceptionHandling <Tax.directTax>(e.Row, tax.DirectTax, new PXSetPropertyException(Messages.ThisOptionCanOnlyBeUsedWithTaxTypeVAT));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.ExemptTax == true && tax.DirectTax == true)
            {
                sender.RaiseExceptionHandling <Tax.exemptTax>(e.Row, tax.ExemptTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.directTax>(e.Row, tax.DirectTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.StatisticalTax == true && tax.DirectTax == true)
            {
                sender.RaiseExceptionHandling <Tax.statisticalTax>(e.Row, tax.StatisticalTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.directTax>(e.Row, tax.DirectTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }


            if (AlreadyWarned == false && tax.PendingTax == true && tax.DirectTax == true)
            {
                sender.RaiseExceptionHandling <Tax.pendingTax>(e.Row, tax.PendingTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.directTax>(e.Row, tax.DirectTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.TaxType != CSTaxType.VAT && tax.PendingTax == true)
            {
                sender.RaiseExceptionHandling <Tax.taxType>(e.Row, tax.TaxType, new PXSetPropertyException(Messages.ThisOptionCanOnlyBeUsedWithTaxTypeVAT));
                sender.RaiseExceptionHandling <Tax.pendingTax>(e.Row, tax.PendingTax, new PXSetPropertyException(Messages.ThisOptionCanOnlyBeUsedWithTaxTypeVAT));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.ReverseTax == true && tax.ExemptTax == true)
            {
                sender.RaiseExceptionHandling <Tax.reverseTax>(e.Row, tax.ReverseTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.exemptTax>(e.Row, tax.ExemptTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.ReverseTax == true && tax.StatisticalTax == true)
            {
                sender.RaiseExceptionHandling <Tax.reverseTax>(e.Row, tax.ReverseTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.statisticalTax>(e.Row, tax.StatisticalTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.PendingTax == true && tax.StatisticalTax == true)
            {
                sender.RaiseExceptionHandling <Tax.pendingTax>(e.Row, tax.PendingTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.statisticalTax>(e.Row, tax.StatisticalTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.PendingTax == true && tax.ExemptTax == true)
            {
                sender.RaiseExceptionHandling <Tax.pendingTax>(e.Row, tax.PendingTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.exemptTax>(e.Row, tax.ExemptTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.StatisticalTax == true && tax.ExemptTax == true)
            {
                sender.RaiseExceptionHandling <Tax.statisticalTax>(e.Row, tax.StatisticalTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.exemptTax>(e.Row, tax.ExemptTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.TaxCalcLevel == "0" && tax.TaxCalcLevel2Exclude == true)
            {
                sender.RaiseExceptionHandling <Tax.taxCalcRule>(e.Row, tax.TaxCalcRule, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.taxCalcLevel2Exclude>(e.Row, tax.TaxCalcLevel2Exclude, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.TaxType == CSTaxType.Use && tax.TaxCalcLevel2Exclude == false)
            {
                sender.RaiseExceptionHandling <Tax.taxType>(e.Row, tax.TaxType, new PXSetPropertyException(Messages.TheseTwoOptionsShouldBeCombined));
                sender.RaiseExceptionHandling <Tax.taxCalcLevel2Exclude>(e.Row, tax.TaxCalcLevel2Exclude, new PXSetPropertyException(Messages.TheseTwoOptionsShouldBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.TaxType == CSTaxType.Use && tax.TaxCalcLevel == "0")
            {
                sender.RaiseExceptionHandling <Tax.taxType>(e.Row, tax.TaxType, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.taxCalcRule>(e.Row, tax.TaxCalcRule, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.TaxType == CSTaxType.Withholding && tax.TaxCalcLevel != "0")
            {
                sender.RaiseExceptionHandling <Tax.taxType>(e.Row, tax.TaxType, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.taxCalcRule>(e.Row, tax.TaxCalcRule, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.ReverseTax == true && tax.TaxCalcLevel == "0")
            {
                sender.RaiseExceptionHandling <Tax.reverseTax>(e.Row, tax.ReverseTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.taxCalcRule>(e.Row, tax.TaxCalcRule, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.ExemptTax == true && tax.IncludeInTaxable == true)
            {
                sender.RaiseExceptionHandling <Tax.exemptTax>(e.Row, tax.ExemptTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.includeInTaxable>(e.Row, tax.IncludeInTaxable, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.StatisticalTax == true && tax.IncludeInTaxable == true)
            {
                sender.RaiseExceptionHandling <Tax.statisticalTax>(e.Row, tax.StatisticalTax, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.includeInTaxable>(e.Row, tax.IncludeInTaxable, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false && tax.DeductibleVAT == true && tax.ReportExpenseToSingleAccount == false && tax.TaxCalcType != CSTaxCalcType.Item)
            {
                sender.RaiseExceptionHandling <Tax.taxCalcRule>(e.Row, tax.TaxCalcRule, new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                sender.RaiseExceptionHandling <Tax.reportExpenseToSingleAccount>(e.Row, tax.ReportExpenseToSingleAccount,
                                                                                 new PXSetPropertyException(Messages.TheseTwoOptionsCantBeCombined));
                AlreadyWarned = true;
            }

            if (AlreadyWarned == false)
            {
                if (((Tax)e.Row).TaxType != CSTaxType.VAT)
                {
                    sender.SetValue <Tax.purchTaxAcctID>(e.Row, null);
                    sender.SetValue <Tax.purchTaxSubID>(e.Row, null);
                    sender.SetValue <Tax.reverseTax>(e.Row, false);
                    sender.SetValue <Tax.pendingTax>(e.Row, false);
                    sender.SetValue <Tax.exemptTax>(e.Row, false);
                    sender.SetValue <Tax.statisticalTax>(e.Row, false);
                    sender.SetValue <Tax.deductibleVAT>(e.Row, false);
                }

                if (((Tax)e.Row).PendingTax != true)
                {
                    sender.SetValue <Tax.pendingSalesTaxAcctID>(e.Row, null);
                    sender.SetValue <Tax.pendingSalesTaxSubID>(e.Row, null);
                    sender.SetValue <Tax.pendingPurchTaxAcctID>(e.Row, null);
                    sender.SetValue <Tax.pendingPurchTaxSubID>(e.Row, null);
                }

                if (((Tax)e.Row).TaxType != CSTaxType.Use && isDeductibleRemoved)
                {
                    sender.SetValue <Tax.expenseAccountID>(e.Row, null);
                    sender.SetValue <Tax.expenseSubID>(e.Row, null);
                }

                if (isDeductibleRemoved)
                {
                    sender.SetValue <Tax.reportExpenseToSingleAccount>(e.Row, true);
                }

                if (isDeductibleSet)
                {
                    sender.SetDefaultExt <Tax.expenseAccountID>(e.Row);
                    sender.SetDefaultExt <Tax.expenseSubID>(e.Row);
                }
            }

            if (sender.ObjectsEqual <Tax.taxVendorID>(e.Row, e.OldRow) == false)
            {
                foreach (TaxRev rev in TaxRevisions.Select())
                {
                    if (((Tax)e.Row).TaxVendorID == null)
                    {
                        if (rev.TaxType == TaxType.Sales)
                        {
                            rev.TaxBucketID = -2;
                        }
                        else
                        {
                            rev.TaxBucketID = -1;
                        }
                    }
                    else
                    {
                        rev.TaxBucketID = null;
                        TaxRevisions.Cache.RaiseExceptionHandling <TaxRev.taxBucketID>(rev, null, new PXSetPropertyException(ErrorMessages.FieldIsEmpty));
                    }

                    if (TaxRevisions.Cache.GetStatus(rev) == PXEntryStatus.Notchanged)
                    {
                        TaxRevisions.Cache.SetStatus(rev, PXEntryStatus.Updated);
                    }
                }
                PopulateBucketList(e.Row);
            }
            if (!sender.ObjectsEqual <Tax.outDate>(e.Row, e.OldRow))
            {
                PXSelectBase <TaxRev> TaxRevFiltered = new PXSelect <TaxRev, Where <TaxRev.taxID, Equal <Current <Tax.taxID> >, And <TaxRev.startDate, Greater <Required <Tax.outDate> > > > >(this);
                if (tax.OutDate.HasValue && TaxRevFiltered.Select(tax.OutDate).Count > 0)
                {
                    Tax.Cache.RaiseExceptionHandling <Tax.outDate>(tax, tax.OutDate, new PXException(Messages.TaxOutDateTooEarly));
                }
                else
                {
                    sender.SetValue <Tax.outdated>(e.Row, tax.OutDate.HasValue);
                    DateTime newEndDate = tax.OutDate.HasValue ? tax.OutDate.Value : new DateTime(9999, 6, 6);
                    foreach (TaxRev rev in TaxRevisions.Select())
                    {
                        TaxRev revcopy = (TaxRev)TaxRevisions.Cache.CreateCopy(rev);
                        revcopy.EndDate = newEndDate;
                        TaxRevisions.Cache.Update(revcopy);
                    }
                }
            }

            if (!sender.ObjectsEqual <Tax.reportExpenseToSingleAccount>(e.Row, e.OldRow) && tax.ReportExpenseToSingleAccount == false)
            {
                sender.SetValue <Tax.expenseAccountID>(tax, null);
                sender.SetValue <Tax.expenseSubID>(tax, null);
            }

            if (!sender.ObjectsEqual <Tax.reportExpenseToSingleAccount>(e.Row, e.OldRow) && tax.ReportExpenseToSingleAccount == true)
            {
                sender.SetDefaultExt <Tax.expenseAccountID>(e.Row);
                sender.SetDefaultExt <Tax.expenseSubID>(e.Row);
            }
        }
コード例 #10
0
        private void PrepareRevisions()
        {
            Tax taxrow = (Tax)Tax.Current;

            if (Tax.Current == null)
            {
                return;
            }

            if (taxrow.OutDate != null && !(bool)taxrow.Outdated)
            {
                {
                    TaxRev rev = new TaxRev();
                    rev.StartDate = taxrow.OutDate;
                    rev.TaxType   = "S";
                    TaxRevisions.Insert(rev);
                }

                if (taxrow.TaxType == "V")
                {
                    TaxRev rev = new TaxRev();
                    rev.StartDate = taxrow.OutDate;
                    rev.TaxType   = "P";
                    TaxRevisions.Insert(rev);
                }

                taxrow.Outdated = true;
                Tax.Update(taxrow);
            }

            DateTime?lastSalesDate = null;
            DateTime?lastPurchDate = null;

            //Assumes that taxRevisions are sorted in the descending order (latest first);
            foreach (TaxRev iRev in this.TaxRevisions.Select())
            {
                if (iRev.TaxType == "S" && lastSalesDate == null ||
                    iRev.TaxType == "P" && lastPurchDate == null)
                {
                    if (taxrow.OutDate.HasValue)
                    {
                        iRev.EndDate = taxrow.OutDate.Value;
                        TaxRevisions.Update(iRev);
                    }
                    else if (iRev.EndDate != iRev.GetDefaultEndDate())
                    {
                        TaxRevisions.Cache.SetDefaultExt <TaxRev.endDate>(iRev);
                        TaxRevisions.Update(iRev);
                    }
                }

                if (((Tax)Tax.Current).OutDate != null)
                {
                    if (((DateTime)((Tax)Tax.Current).OutDate).CompareTo(iRev.StartDate) <= 0)
                    {
                        iRev.Outdated = true;
                        TaxRevisions.Update(iRev);
                    }
                }

                if (iRev.TaxType == "S")
                {
                    if (lastSalesDate != null && iRev.EndDate != lastSalesDate)
                    {
                        iRev.EndDate = lastSalesDate;
                        TaxRevisions.Update(iRev);
                    }
                    lastSalesDate = ((DateTime)iRev.StartDate).AddDays(-1);
                }
                else if (iRev.TaxType == "P")
                {
                    if (lastPurchDate != null && iRev.EndDate != lastPurchDate)
                    {
                        iRev.EndDate = lastPurchDate;
                        TaxRevisions.Update(iRev);
                    }
                    lastPurchDate = ((DateTime)iRev.StartDate).AddDays(-1);
                }
            }
        }
コード例 #11
0
			public Decimal CalcTaxableFromTotalAmount(
				PXCache cache,
				object row,
				HashSet<string> taxList,
				DateTime aDocDate,
				Decimal aCuryTotal)
			{
				IComparer<Tax> taxComparer = GetTaxComparer();
				taxComparer.ThrowOnNull(nameof(taxComparer));

				Decimal result = Decimal.Zero;
				PXGraph graph = cache.Graph;
				Dictionary<string, PXResult<Tax, TaxRev>> taxRates = GetTaxRevisionList(graph, aDocDate);
				List<PXResult<Tax, TaxRev>> orderedTaxList = new List<PXResult<Tax, TaxRev>>(taxList.Count);

				foreach (string taxID in taxList)
				{
					if (taxRates.TryGetValue(taxID, out PXResult<Tax, TaxRev> line))
					{
						int idx;
						for (idx = orderedTaxList.Count;
							(idx > 0) && taxComparer.Compare(orderedTaxList[idx - 1], line) > 0;
							idx--)
							;

						var tax = (Tax)line;
						if (_taxCalcMode != null && tax.TaxCalcLevel != CSTaxCalcLevel.CalcOnItemAmtPlusTaxAmt)
						{
							switch (_taxCalcMode)
							{
								case TaxCalculationMode.Net:
									tax.TaxCalcLevel = CSTaxCalcLevel.CalcOnItemAmt;
									break;

								case TaxCalculationMode.Gross:
									tax.TaxCalcLevel = CSTaxCalcLevel.Inclusive;
									break;
							}
						}
						orderedTaxList.Insert(idx, new PXResult<Tax, TaxRev>(tax, (TaxRev)line));
					}
				}

				Decimal rateInclusive = Decimal.Zero;
				Decimal rateLvl1 = Decimal.Zero;
				Decimal rateLvl2 = Decimal.Zero;

				foreach (PXResult<Tax, TaxRev> iRes in orderedTaxList)
				{
					Tax tax = iRes;
					TaxRev taxRev = iRes;
					Decimal multiplier = tax.ReverseTax == true ? Decimal.MinusOne : Decimal.One;

					if (tax.TaxType == CSTaxType.PerUnit)
					{
						PXTrace.WriteError(Messages.PerUnitTaxesNotSupportedOperation);
						throw new PXException(Messages.PerUnitTaxesNotSupportedOperation);
					}

					switch (tax.TaxCalcLevel)
					{
						case CSTaxCalcLevel.Inclusive:
							rateInclusive += multiplier * taxRev.TaxRate.Value;
							break;
						case CSTaxCalcLevel.CalcOnItemAmt:
							rateLvl1 += multiplier * taxRev.TaxRate.Value;
							break;
						case CSTaxCalcLevel.CalcOnItemAmtPlusTaxAmt:
							rateLvl2 += multiplier * taxRev.TaxRate.Value;
							break;
					}
				}

				decimal baseLvl2 = PXDBCurrencyAttribute.RoundCury(cache, row, aCuryTotal / (1 + rateLvl2 / 100), _precision);
				decimal baseLvl1 = PXDBCurrencyAttribute.RoundCury(cache, row, baseLvl2 / (1 + (rateLvl1 + rateInclusive) / 100), _precision);
				Decimal curyTaxTotal = decimal.Zero;
				Decimal curyTax2Total = decimal.Zero;

				foreach (PXResult<Tax, TaxRev> iRes in orderedTaxList)
				{
					Tax tax = iRes;
					TaxRev taxRev = iRes;
					Decimal multiplier = tax.ReverseTax == true ? Decimal.MinusOne : Decimal.One;
					switch (tax.TaxCalcLevel)
					{
						case CSTaxCalcLevel.Inclusive:
							break;
						case CSTaxCalcLevel.CalcOnItemAmt:
							curyTaxTotal += multiplier * PXDBCurrencyAttribute.RoundCury(cache, row, (baseLvl1 * taxRev.TaxRate / 100m) ?? 0m, _precision);
							break;
						case CSTaxCalcLevel.CalcOnItemAmtPlusTaxAmt:
							curyTax2Total += multiplier * PXDBCurrencyAttribute.RoundCury(cache, row, (baseLvl2 * taxRev.TaxRate / 100m) ?? 0m, _precision);
							break;
					}
				}
				result = aCuryTotal - curyTaxTotal - curyTax2Total;
				return result;
			}