Beispiel #1
0
 public CalculateTransactionResult Calculate(TransactionCalculatorArgs args)
 {
     try
     {
         ValidateArguments(args);
         CommonTaxHelper            helper = new CommonTaxHelper(args.Lines, args.GlobalDiscountAmount, args.GlobalDiscountPct, m_calculationStratagy.TaxMethod);
         CalculateTransactionResult res    = processDocument(helper);
         res.Success = true;
         return(res);
     }
     catch (Exception ex)
     {
         return(new CalculateTransactionResult {
             Success = false, Exception = ex
         });
     }
 }
Beispiel #2
0
        private void ValidateArguments(TransactionCalculatorArgs args)
        {
            if (m_calculationStratagy.TaxMethod == TaxMethods.NotSet)
            {
                throw new Exception("Tax Method not set properly");
            }
            if (args.GlobalDiscountPct != 0 && args.GlobalDiscountAmount != 0)
            {
                throw new Exception("Set eather Global discount percent or Global discount amount, Not both");
            }

            var invalidGroup = args.Lines.GroupBy(line => line.TaxCode).Select(group => new
            {
                Code  = group.Key,
                Count = group.Select(line => line.TaxRate).Distinct().Count()
            }).FirstOrDefault(tc => tc.Count > 1);

            if (invalidGroup != null)
            {
                throw new Exception(string.Format("Group '{0}' has multiple tax rates", invalidGroup.Code));
            }
        }