public void TestServiceTaxCalculation()
        {
            //In real world applications moq is used.
            var taxSummary=new TaxSummary();

            var testOutput=new TaxModel[2];
            testOutput[0]=new TaxModel
            {
                DateTime = Convert.ToDateTime(null),
                Invoice = 13000,
                ServiceTax = 0,
                EducationalCess = 0,
                ForeignRemittanceTax = 0
            };
            testOutput[1]=new TaxModel
            {
                DateTime = Convert.ToDateTime(null),
                Invoice = 1500,
                ServiceTax = 0,
                EducationalCess = 0,
                ForeignRemittanceTax = 0
            };

            var educationCess = new EducationCess();

            var result=educationCess.RetrieveResults(testOutput);

            foreach (var taxModel in result)
            {
                Assert.AreEqual(taxModel.ServiceTax,testOutput[0].ServiceTax,"The values are null");
            }
        }
 private SujetaType Convert(TaxSummary summary)
 {
     return(new SujetaType
     {
         Exenta = summary.TaxExempt.Map(items => items.Select(i => Convert(i)).ToArray()).GetOrNull(),
         NoExenta = summary.Taxed.Map(taxRateSummaries => new SujetaTypeNoExenta
         {
             TipoNoExenta = TipoOperacionSujetaNoExentaType.S1,
             DesgloseIVA = taxRateSummaries.Select(s => Convert(s)).ToArray()
         }).GetOrNull()
     });
 }
Пример #3
0
        private SimplifiedInvoice GetInvoice(LocalCompany issuingCompany, LocalCompany payingCompany, int invoiceIndex = 1)
        {
            var taxRateSummaries = new[] { GetTaxRateSummary(21m, 42.07M) };
            var taxExemptItems   = new[] { new TaxExemptItem(Amount.Create(20m).Success.Get(), CauseOfExemption.OtherGrounds) };

            var nowUtc        = DateTime.UtcNow;
            var issueDateUtc  = nowUtc.Date;
            var invoiceNumber = $"Bill-{nowUtc:yyyy-MM-dd-HH-mm-ss}-{invoiceIndex}";

            return(new SimplifiedInvoice(
                       taxPeriod: new TaxPeriod(Year.Create(issueDateUtc.Year).Success.Get(), (Month)(issueDateUtc.Month - 1)),
                       id: new InvoiceId(issuingCompany.TaxpayerIdentificationNumber, String1To60.CreateUnsafe(invoiceNumber), issueDateUtc),
                       schemeOrEffect: SchemeOrEffect.GeneralTaxRegimeActivity,
                       description: String0To500.CreateUnsafe("This is a test invoice."),
                       taxBreakdown: new TaxBreakdown(TaxSummary.Create(taxExempt: taxExemptItems, taxed: taxRateSummaries).Success.Get()),
                       issuedByThirdParty: true
                       ));
        }
Пример #4
0
        public InvoiceDocument()
        {
            container = DI_Container.Config();

            mainWorkFrame           = container.Resolve <MainWorkFrame>();
            invoiceHeader           = container.Resolve <InvoiceHeader>();
            invoiceNumber           = container.Resolve <InvoiceNumber>();
            vendorAndBuyerHeader    = container.Resolve <VendorAndBuyerHeader>();
            vendorAndBuyerDetail    = container.Resolve <VendorAndBuyerDetail>();
            invoiceDetailHeader     = container.Resolve <InvoiceDetailHeader>();
            totalAmountProcessor    = container.Resolve <TotalAmountProcessor>();
            paymentDetails          = container.Resolve <PaymentDetails>();
            bankDetails             = container.Resolve <BankDetails>();
            commentSpace            = container.Resolve <CommentSpace>();
            signatureSpace          = container.Resolve <SignatureSpace>();
            productSignature        = container.Resolve <ProductSignature>();
            invoiceSummaryProcessor = container.Resolve <InvoiceSummaryProcessor>();
            taxSummary = container.Resolve <TaxSummary>();
            drawRow    = container.Resolve <DrawRow>();

            InitializeComponent();
        }
Пример #5
0
        private static TaxSummary MessageToTaxSummary(Message msg)
        {
            TaxSummary ts   = new TaxSummary();
            double     temp = 0.0;

            //For sanity...
            //If its ok to parse...
            if (msg != null)
            {
                if (msg.Segments[0].Elements[1] == SOAOkElement)
                {
                    if (msg.Segments[1].Elements[2].Equals("NetAmount") &&
                        msg.Segments[2].Elements[2].Equals("PstAmount") &&
                        msg.Segments[3].Elements[2].Equals("HstAmount") &&
                        msg.Segments[4].Elements[2].Equals("GstAmount") &&
                        msg.Segments[5].Elements[2].Equals("TotalAmount"))
                    {
                        double.TryParse(msg.Segments[1].Elements[4], out temp);
                        ts.NetAmount = temp;

                        double.TryParse(msg.Segments[2].Elements[4], out temp);
                        ts.PstAmount = temp;

                        double.TryParse(msg.Segments[3].Elements[4], out temp);
                        ts.HstAmount = temp;

                        double.TryParse(msg.Segments[4].Elements[4], out temp);
                        ts.GstAmount = temp;

                        double.TryParse(msg.Segments[5].Elements[4], out temp);
                        ts.TotalAmount = temp;
                    }
                }
            }

            return(ts);
        }
        /// <summary>
        /// This method calculates all taxes for each region 
        /// </summary>
        /// <param name="region">code of the province in the format of "ON"</param>
        /// <param name="amount">the value to calculate taxes on</param>
        /// <returns>an TaxSummary objec, which contains the NetAmount, PST, HST, GST and total after taxes</returns>
        private Models.TaxSummary CalculateTaxByRegion(string region, double amount)
        {
            string codePattern = @"^(NL|NS|NB|PE|QC|ON|MB|SK|AB|BC|YT|NT|NU)$";
            Regex rg = new Regex(codePattern, RegexOptions.IgnoreCase);
            Match mch = rg.Match(region);
            if(!mch.Success)
            {
                throw new ArgumentException("The region code is not in a valid format, Format should be NL|NS|NB|PE|QC|ON|MB|SK|AB|BC|YT|NT|NU");
            }
            if (amount < 0)
            {
                throw new ArgumentException("The amount cannot be negative.");
            }
            #region method Initializers
            TaxSummary ts = new TaxSummary();
            ts.NetAmount = amount;
            string getRegionName = ChooseRegion(region);
            string taxType = GetSaleTaxByRegion(region);
            string pst = string.Empty;
            string gst = string.Empty;
            const double qcPstTaxRate = 9.5d;

           

            //get tax type pst and gst to be applied where available
            if (taxType.Contains('-'))
            {
                pst = GetPst(taxType);
                gst = GetGst(taxType);
            }
            #endregion
            #region Hst
            //calculates HST tax for regions that have this tax 
            if (taxType.Equals("HST"))
            {
                switch (region.ToUpper())
                {
                    case "NL":
                        ts.HstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.HSTRates.HSTMedium));
                        ts.TotalAmount = CalculateTax(ConvertToPercent((double)Enums.HSTRates.HSTMedium), amount);
                        break;
                    case "NS":
                        ts.HstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.HSTRates.HSTHigh));
                        ts.TotalAmount = CalculateTax(ConvertToPercent((double)Enums.HSTRates.HSTHigh), amount);
                        break;
                    case "NB":
                        ts.HstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.HSTRates.HSTMedium));
                        ts.TotalAmount = CalculateTax(ConvertToPercent((double)Enums.HSTRates.HSTMedium), amount);
                        break;
                    case "ON":
                        ts.HstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.HSTRates.HSTMedium));
                        ts.TotalAmount = CalculateTax(ConvertToPercent((double)Enums.HSTRates.HSTMedium), amount);
                        break;
                    case "BC":
                        ts.HstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.HSTRates.HSTLow));
                        ts.TotalAmount = CalculateTax(ConvertToPercent((double)Enums.HSTRates.HSTLow), amount);
                        break;
                    default:
                        break;
                }
            }
            #endregion
            #region Pst-Gst
            //calculates the PST and GST for the regions that have these types of taxes
            if (taxType.Equals("PST-GST"))
            {
                switch (region.ToUpper())
                {
                    case "PE":
                        ts.GstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.GSTRate.GSTRate));
                        ts.PstAmount = CalculateTaxAmount(CalculateTax(ConvertToPercent((double)Enums.GSTRate.GSTRate), amount), ConvertToPercent((double)Enums.PSTRates.PSTHigh));
                        ts.TotalAmount = CalculateTax(ConvertToPercent((double)Enums.PSTRates.PSTHigh), CalculateTax(ConvertToPercent((double)Enums.GSTRate.GSTRate), amount));
                        break;
                    case "QC":
                        ts.GstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.GSTRate.GSTRate));
                        ts.PstAmount = CalculateTaxAmount(CalculateTax(ConvertToPercent((double)Enums.GSTRate.GSTRate), amount), ConvertToPercent(qcPstTaxRate));
                        ts.TotalAmount = CalculateTax(ConvertToPercent(qcPstTaxRate), CalculateTax(ConvertToPercent((double)Enums.GSTRate.GSTRate), amount));
                        break;
                    case "MB":
                        ts.GstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.GSTRate.GSTRate));
                        ts.PstAmount = Math.Round(CalculateTaxAmount(amount, ConvertToPercent((double)Enums.PSTRates.PSTMedium)), 2);
                        ts.TotalAmount = CalculateTax((ConvertToPercent((double)Enums.GSTRate.GSTRate) + ConvertToPercent((double)Enums.PSTRates.PSTMedium)), amount);
                        break;
                    case "SK":
                        ts.GstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.GSTRate.GSTRate));
                        ts.PstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.PSTRates.PSTLow));
                        ts.TotalAmount = CalculateTax((ConvertToPercent((double)Enums.GSTRate.GSTRate) + ConvertToPercent((double)Enums.PSTRates.PSTLow)), amount);
                        break;
                    case "AB":
                        ts.GstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.GSTRate.GSTRate));
                        ts.PstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.PSTRates.PSTZero));
                        ts.TotalAmount = CalculateTax((ConvertToPercent((double)Enums.GSTRate.GSTRate) + ConvertToPercent((double)Enums.PSTRates.PSTZero)), amount);
                        break;
                    case "YT":
                        ts.GstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.GSTRate.GSTRate));
                        ts.PstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.PSTRates.PSTZero));
                        ts.TotalAmount = CalculateTax((ConvertToPercent((double)Enums.GSTRate.GSTRate) + ConvertToPercent((double)Enums.PSTRates.PSTZero)), amount);
                        break;
                    case "NT":
                        ts.GstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.GSTRate.GSTRate));
                        ts.PstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.PSTRates.PSTZero));
                        ts.TotalAmount = CalculateTax((ConvertToPercent((double)Enums.GSTRate.GSTRate) + ConvertToPercent((double)Enums.PSTRates.PSTZero)), amount);
                        break;
                    case "NU":
                        ts.GstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.GSTRate.GSTRate));
                        ts.PstAmount = CalculateTaxAmount(amount, ConvertToPercent((double)Enums.PSTRates.PSTZero));
                        ts.TotalAmount = CalculateTax((ConvertToPercent((double)Enums.GSTRate.GSTRate) + ConvertToPercent((double)Enums.PSTRates.PSTZero)), amount);
                        break;
                    default:
                        break;
                }
            }
            return ts;
            #endregion
        }
Пример #7
0
        internal static string ToSignatureString(this TaxSummary taxSummary)
        {
            var parts = taxSummary.Data.OrderByDescending(d => d.Key).Select(d => $"{d.Key.ToSignatureString()}:{d.Value.ToSignatureString()}");

            return(String.Join("|", parts));
        }
Пример #8
0
        private int CreateInvoiceSummary(PrintPageEventArgs e, int y, string _totalAmount, TaxSummary taxSummary)
        {
            //String inputText = text;
            Font         drawFont    = new System.Drawing.Font("Arial", 10, FontStyle.Regular);
            StringFormat digitFormat = new StringFormat();

            digitFormat.Alignment = StringAlignment.Far;

            //--podsumowanie Brutto
            RectangleF summaryRectangle = new RectangleF(667, y, 108, 20);

            e.Graphics.DrawRectangle(blackPen, 667, y, 108, 20);
            e.Graphics.DrawString(_totalAmount, drawFont, drawBrush, summaryRectangle, digitFormat);

            //--podsumowanie Brutto
            RectangleF h1 = new RectangleF(499, y + 20, 276, 20);

            e.Graphics.FillRectangle(new SolidBrush(Color.LightGray), 499, y + 20, 276, 20);

            e.Graphics.DrawRectangle(blackPen, 499, y + 20, 276, 20);
            e.Graphics.DrawString("Podsumowanie według stawek VAT", drawFont, drawBrush, h1, digitFormat);
            y = y + 20;

            string[] vatPercentLabel = { "5", "8", "23", "zw" };
            string[] netLabel        = { taxSummary._netPrice5summary.ToString("F"), taxSummary._netPrice8summary.ToString("F"), taxSummary._netPrice23summary.ToString("F"), taxSummary._netPriceFreeSummary.ToString("F") };
            string[] grossLabel      = { taxSummary._grossPrice5summary.ToString("F"), taxSummary._grossPrice8summary.ToString("F"), taxSummary._grossPrice23summary.ToString("F"), taxSummary._grossPriceFreeSummary.ToString("F") };
            string[] taxLabel        = { taxSummary._tax5summary.ToString("F"), taxSummary._tax8summary.ToString("F"), taxSummary._tax23summary.ToString("F"), taxSummary._taxFreeSummary.ToString("F") };
            for (int i = 0; i <= 3; i++)
            {
                //--tabela summary
                // wNet
                RectangleF r6 = new RectangleF(499, y + 20, 72, 20);
                e.Graphics.DrawRectangle(blackPen, 499, y + 20, 72, 20);
                e.Graphics.DrawString(netLabel[i], drawFont, drawBrush, r6, digitFormat);
                // %
                RectangleF r7 = new RectangleF(571, y + 20, 24, 20);
                e.Graphics.DrawRectangle(blackPen, 571, y + 20, 24, 20);
                e.Graphics.DrawString(vatPercentLabel[i], drawFont, drawBrush, r7, digitFormat);
                // taxVal
                RectangleF r8 = new RectangleF(595, y + 20, 72, 20);
                e.Graphics.DrawRectangle(blackPen, 595, y + 20, 72, 20);
                e.Graphics.DrawString(taxLabel[i], drawFont, drawBrush, r8, digitFormat);
                //GrossPr
                RectangleF r9 = new RectangleF(667, y + 20, 108, 20);
                e.Graphics.DrawRectangle(blackPen, 667, y + 20, 108, 20);
                e.Graphics.DrawString(grossLabel[i], drawFont, drawBrush, r9, digitFormat);
                y = y + 20;
            }

            return(y);
        }
Пример #9
0
 public void CreateInvoiceSummaryProcessor(int?tax, decimal taxValue, decimal netPrice, decimal grossPrice, ref TaxSummary taxSummary)
 {
     if (tax == 5)
     {
         taxSummary._tax5summary        += taxValue;
         taxSummary._netPrice5summary   += netPrice;
         taxSummary._grossPrice5summary += grossPrice;
     }
     else if (tax == 8)
     {
         taxSummary._tax8summary        += taxValue;
         taxSummary._netPrice8summary   += netPrice;
         taxSummary._grossPrice8summary += grossPrice;
     }
     else if (tax == 23)
     {
         taxSummary._tax23summary        += taxValue;
         taxSummary._netPrice23summary   += netPrice;
         taxSummary._grossPrice23summary += grossPrice;
     }
     else
     {
         taxSummary._taxFreeSummary        += taxValue;
         taxSummary._netPriceFreeSummary   += netPrice;
         taxSummary._grossPriceFreeSummary += grossPrice;
     }
 }