コード例 #1
0
        private void BindInvoice()
        {
            if ((_invoice != null))
            {
                var serviceInvoiceSvc = new ServiceInvoiceService(MyConfiguration,
                                                                  null,
                                                                  MyOAuthKeyService);
                ServiceInvoice serviceInvoice = serviceInvoiceSvc.Get(MyCompanyFile, _invoice.UID, MyCredentials);

                //Set the default value
                var customers =
                    CmboCustomer.DataSource as PagedCollection <Customer>;

                if (customers != null)
                {
                    for (int i = 0; i <= customers.Count; i++)
                    {
                        Customer customer = customers.Items[i];
                        if (customer.UID == serviceInvoice.Customer.UID)
                        {
                            CmboCustomer.SelectedIndex = i;
                            break;
                        }
                    }
                }
                BsServiceInvoice.DataSource = serviceInvoice;
                GrdServiceLines.DataSource  = FlattenLines(serviceInvoice.Lines);
            }
        }
コード例 #2
0
        public async Task <ActionResult <ServiceInvoiceViewModel> > PutServiceInvoice(int id,
                                                                                      ServiceInvoiceEditModel serviceInvoiceModel)
        {
            ServiceInvoice serviceInvoice = await _serviceInvoicesRepository.FindByIdAsync(id);

            if (serviceInvoice is null)
            {
                return(NotFound($"No existe ninguna factura de servicio con el código {id}."));
            }

            _mapper.Map(serviceInvoiceModel, serviceInvoice);
            _serviceInvoicesRepository.Update(serviceInvoice);

            try
            {
                await _unitWork.SaveAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ServiceInvoiceExists(id))
                {
                    return(NotFound(
                               $"Error de actualizacón. No existe ninguna factura de servicio con el código {id}."));
                }

                throw;
            }

            return(_mapper.Map <ServiceInvoiceViewModel>(serviceInvoice));
        }
コード例 #3
0
        private void GenerateInvoice(Activity activity)
        {
            if (activity is null)
            {
                return;
            }

            List <Service> services = activity.ActivitiesServices.Select(s => s.Service).ToList();

            ServiceInvoice serviceInvoice = new ServiceInvoice
            {
                Client         = activity.Client,
                ClientId       = activity.ClientId,
                PaymentMethod  = PaymentMethod.None,
                State          = InvoiceState.Generated,
                IVA            = 0.19M,
                GenerationDate = DateTime.Now
            };

            services.ForEach(service => { serviceInvoice.AddDetail(service); });

            serviceInvoice.CalculateTotal();

            _serviceInvoicesRepository.Insert(serviceInvoice);
        }
コード例 #4
0
        public void InvoiceIsCreatedWithDefaultValues()
        {
            var invoice = new ServiceInvoice();

            Assert.IsTrue(invoice.IsTaxInclusive);
            Assert.AreEqual(DocumentAction.Print, invoice.InvoiceDeliveryStatus);
        }
コード例 #5
0
 /// <summary>
 /// Print out the calculation for the Subtotal, PST and GST charged, and total cost
 /// </summary>
 /// <param name="invoice">Use as a reference for the ServiceInvoice</param>
 private void serviceCalculation(ServiceInvoice invoice)
 {
     lblSubtotal.Text = invoice.Subtotal.ToString("C");
     lblPst.Text      = invoice.PSTCharged.ToString("N2");
     lblGst.Text      = invoice.GSTCharged.ToString("N2");
     lblTotal.Text    = invoice.Total.ToString("C");
 }
コード例 #6
0
ファイル: PaymentsController.cs プロジェクト: cantte/Kaizen
        public async Task <ActionResult <ServiceInvoiceViewModel> > PayServiceInvoice(int id,
                                                                                      [FromBody] PaymentModel paymentModel)
        {
            ServiceInvoice serviceInvoice = await _serviceInvoicesRepository.FindByIdAsync(id);

            if (serviceInvoice is null)
            {
                return(NotFound($"No existe ninguna factura de servicio con el código {id}."));
            }

            serviceInvoice.CalculateTotal();

            PaymentCreateRequest paymentCreateRequest = new PaymentCreateRequest
            {
                Token             = paymentModel.Token,
                PaymentMethodId   = paymentModel.PaymentMethodId,
                TransactionAmount = serviceInvoice.Total,
                Description       = $"Pay of service invoice {serviceInvoice.Id}",
                Installments      = 1,
                Payer             = new PaymentPayerRequest
                {
                    FirstName = serviceInvoice.Client.FirstName,
                    LastName  = serviceInvoice.Client.LastName,
                    Email     = paymentModel.Email
                }
            };

            Payment payment = await _paymentClient.CreateAsync(paymentCreateRequest);

            if (payment.Status == PaymentStatus.Rejected)
            {
                return(BadRequest("El pago no pudo ser procesado."));
            }

            serviceInvoice.State         = InvoiceState.Paid;
            serviceInvoice.PaymentDate   = DateTime.Now;
            serviceInvoice.PaymentMethod = PaymentMethod.CreditCard;

            serviceInvoice.PublishEvent(new PaidInvoice(serviceInvoice));
            _serviceInvoicesRepository.Update(serviceInvoice);

            try
            {
                await _unitWork.SaveAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ServiceInvoiceExists(id))
                {
                    return(NotFound(
                               $"Error de actualizacón. No existe ninguna factura de servicio con el código {id}."));
                }

                throw;
            }

            return(_mapper.Map <ServiceInvoiceViewModel>(serviceInvoice));
        }
コード例 #7
0
        public void GoodsAndServicesTaxChanged_Test()
        {
            this.eventActual = null;
            Invoice invoice = new ServiceInvoice(0.2m, 0.2m);

            invoice.GoodsAndServicesTaxChanged += TestHandler;
            invoice.GoodsAndServicesTaxRate     = 0.3m;
            Assert.AreEqual("Event triggered.", eventActual);
        }
コード例 #8
0
        public void ServiceInvoice_Test()
        {
            ServiceInvoice serviceInvoice        = new ServiceInvoice(0.1M, 0.3M);
            PrivateObject  privateServiceInvoice = new PrivateObject(serviceInvoice);
            PrivateObject  privateInvoice        = new PrivateObject(serviceInvoice, new PrivateType(typeof(Invoice)));

            Assert.AreEqual(0.1M, (decimal)privateInvoice.GetField("provincialSalesTaxRate"));
            Assert.AreEqual(0.3M, (decimal)privateInvoice.GetField("goodsAndServicesTaxRate"));
        }
コード例 #9
0
        public void CostAdded_Test()
        {
            this.eventActual = null;
            ServiceInvoice serviceInvoice = new ServiceInvoice(0.2m, 0.2m);

            serviceInvoice.CostAdded += TestHandler;
            serviceInvoice.AddCost(CostType.Labour, 500);
            Assert.AreEqual("Event triggered.", eventActual);
        }
コード例 #10
0
        public void AddCost_LessThanZero_Test()
        {
            //Arrange
            decimal        provincialSalesTaxRate  = 0.2m;
            decimal        goodsAndServicesTaxRate = 1.1m;
            ServiceInvoice servieInvoice           = new ServiceInvoice(provincialSalesTaxRate, goodsAndServicesTaxRate);

            servieInvoice.AddCost(CostType.Labour, -1);
        }
コード例 #11
0
        public void AddCost_Equal_Exception_Test()
        {
            decimal        amount   = 0M;
            CostType       costType = CostType.Labour;
            decimal        provincialSalesTaxRate  = 0.1M;
            decimal        goodsAndServicesTaxRate = 0.3M;
            ServiceInvoice serviceInvoice          = new ServiceInvoice(provincialSalesTaxRate, goodsAndServicesTaxRate);

            serviceInvoice.AddCost(costType, amount);
        }
コード例 #12
0
        public void AddCost_InvalidCostType_Exception()
        {
            // Arrange
            CostType type = (CostType)99;
            decimal  amount = 40M, provincialSalesTaxRate = 0.5M, goodsAndServicesTaxRate = 0.8M;

            ServiceInvoice serviceInvoice = new ServiceInvoice(provincialSalesTaxRate, goodsAndServicesTaxRate);

            // Act
            serviceInvoice.AddCost(type, amount);
        }
コード例 #13
0
        public async Task <ActionResult <ServiceInvoiceViewModel> > GetServiceInvoice(int id)
        {
            ServiceInvoice serviceInvoice = await _serviceInvoicesRepository.FindByIdAsync(id);

            if (serviceInvoice == null)
            {
                return(NotFound($"No existe ninguna factura de servicio con el código {id}."));
            }

            return(_mapper.Map <ServiceInvoiceViewModel>(serviceInvoice));
        }
コード例 #14
0
        public void AddCost_NegativeAmount_Exception()
        {
            // Arrange
            CostType type = CostType.Labour;
            decimal  amount = -40M, provincialSalesTaxRate = 0.5M, goodsAndServicesTaxRate = 0.8M;

            ServiceInvoice serviceInvoice = new ServiceInvoice(provincialSalesTaxRate, goodsAndServicesTaxRate);

            // Act
            serviceInvoice.AddCost(type, amount);
        }
コード例 #15
0
        public void MaterialCost_Test()
        {
            decimal        provincialSalesTaxRate  = 0.1M;
            decimal        goodsAndServicesTaxRate = 0.3M;
            ServiceInvoice serviceInvoice          = new ServiceInvoice(provincialSalesTaxRate, goodsAndServicesTaxRate);
            decimal        expectedMaterialCost    = 0.3M;

            serviceInvoice.AddCost(CostType.Material, expectedMaterialCost);
            decimal actualMaterialCost = serviceInvoice.MaterialCost;

            Assert.AreEqual(expectedMaterialCost, actualMaterialCost);
        }
コード例 #16
0
        public void ProvincialSalesTaxCharged_Test()
        {
            decimal        provincialSalesTaxRate  = 0.1M;
            decimal        goodsAndServicesTaxRate = 0.3M;
            ServiceInvoice serviceInvoice          = new ServiceInvoice(provincialSalesTaxRate, goodsAndServicesTaxRate);

            serviceInvoice.AddCost(CostType.Material, 0.2M);
            decimal expectedProvincialSalesTaxCharged = 0.02M;
            decimal actualProvincialSalesTaxCharged   = serviceInvoice.ProvincialSalesTaxCharged;

            Assert.AreEqual(expectedProvincialSalesTaxCharged, actualProvincialSalesTaxCharged);
        }
コード例 #17
0
        public void ServiceInvoiceConstructor_GreaterThanOneGSTRate_Exception()
        {
            // Arrange
            decimal provincialSalesTaxRate = 0.5M, goodsAndServicesTaxRate = 1.8M;

            ServiceInvoice serviceInvoice = new ServiceInvoice(provincialSalesTaxRate, goodsAndServicesTaxRate);

            PrivateObject target = new PrivateObject(serviceInvoice);

            // Act
            decimal actual = (decimal)target.GetField("goodsAndServicesTaxRate");
        }
コード例 #18
0
        public void Constructor_GoodsAndServicesTaxRateMoreThanOne_Test()
        {
            //Arrange
            decimal provincialSalesTaxRate  = 0.2m;
            decimal goodsAndServicesTaxRate = 1.1m;

            ServiceInvoice servieInvoice = new ServiceInvoice(provincialSalesTaxRate, goodsAndServicesTaxRate);
            PrivateObject  target        = new PrivateObject(servieInvoice, new PrivateType(typeof(Invoice)));

            //Act
            //Assert
        }
コード例 #19
0
        public void AddCost_CostTypeMaterial_Test()
        {
            //Arrange
            ServiceInvoice servieInvoice = new ServiceInvoice(0.2m, 0.1m);

            //Act
            decimal actualAmount = 300;

            servieInvoice.AddCost(CostType.Material, actualAmount);

            //Assert
            Assert.AreEqual(300, servieInvoice.MaterialCost);
        }
コード例 #20
0
        public void GetGoodsAndServicesTaxRate_Test()
        {
            //Arrange
            ServiceInvoice serviceInvoice = new ServiceInvoice(0.2m, 0.1m);

            //Act
            decimal expectedGoodsAndServicesTaxRate = 0.1m;

            //Assert
            PrivateObject target = new PrivateObject(serviceInvoice, new PrivateType(typeof(Invoice)));
            decimal       actualGoodsAndServicesTaxRate = (decimal)target.GetField("goodsAndServicesTaxRate");

            Assert.AreEqual(expectedGoodsAndServicesTaxRate, actualGoodsAndServicesTaxRate);
        }
コード例 #21
0
        /// <summary>
        /// Retrieves the invoice values which are passed to the labels in the service invoice form.
        /// </summary>
        /// <param name="serviceInvoice">For referencing the calculated values</param>
        public frmServiceInvoice(ServiceInvoice invoice)
        {
            InitializeComponent();

            // Sets the values of each individual label
            lblInvoiceTitle.Text  = "Service Invoice";
            lblLabourCost.Text    = invoice.LabourCost.ToString("C");
            lblPartsCost.Text     = invoice.PartsCost.ToString("N2");
            lblMaterialsCost.Text = invoice.MaterialsCost.ToString("N2");
            lblSubtotal.Text      = invoice.Subtotal.ToString("C");
            lblPst.Text           = invoice.PSTCharged.ToString("N2");
            lblGst.Text           = invoice.GSTCharged.ToString("N2");
            lblTotal.Text         = invoice.Total.ToString("C");
        }
コード例 #22
0
        public void GetProvincialSalesTaxCharged_Test()
        {
            //Arrange
            ServiceInvoice servieInvoice = new ServiceInvoice(0.2m, 0.1m);

            servieInvoice.AddCost(CostType.Labour, 500);
            servieInvoice.AddCost(CostType.Part, 500);

            //Act
            decimal salesTax = (servieInvoice.LabourCost + servieInvoice.PartsCost) * 0.2m;

            //Assert
            Assert.AreEqual(200m, salesTax);
        }
コード例 #23
0
        public void Total_Test()
        {
            //Arrange
            ServiceInvoice servieInvoice = new ServiceInvoice(0.2m, 0.1m);

            servieInvoice.AddCost(CostType.Labour, 500);
            servieInvoice.AddCost(CostType.Part, 500);
            servieInvoice.AddCost(CostType.Material, 500);
            //Act
            decimal expectedTotal = (500 + 500 + 500) + (500 + 500) * 0.2m + (500 + 500 + 500) * 0.1m;
            decimal actualTotal   = servieInvoice.SubTotal + servieInvoice.ProvincialSalesTaxCharged + servieInvoice.GoodAndServicesTaxCharged;

            //Assert
            Assert.AreEqual(expectedTotal, actualTotal);
        }
コード例 #24
0
        public void SubTotal_Test()
        {
            //Arrange
            ServiceInvoice servieInvoice = new ServiceInvoice(0.2m, 0.1m);

            servieInvoice.AddCost(CostType.Labour, 500);
            servieInvoice.AddCost(CostType.Part, 500);
            servieInvoice.AddCost(CostType.Material, 500);

            //Act
            decimal subTotal = servieInvoice.LabourCost + servieInvoice.PartsCost + servieInvoice.MaterialCost;

            //Assert
            Assert.AreEqual(1500, subTotal);
        }
コード例 #25
0
        public void GetGoodsAndServicesTaxCharged_Test()
        {
            //Arrange
            ServiceInvoice servieInvoice = new ServiceInvoice(0.2m, 0.1m);

            servieInvoice.AddCost(CostType.Labour, 500);
            servieInvoice.AddCost(CostType.Part, 500);
            servieInvoice.AddCost(CostType.Material, 500);

            //Act
            decimal salesTax = (servieInvoice.LabourCost + servieInvoice.PartsCost + servieInvoice.MaterialCost) * 0.1m;

            //Assert
            Assert.AreEqual(150m, salesTax);
        }
コード例 #26
0
        public void SetProvincialSalesTaxRate_Test()
        {
            //Arrange
            ServiceInvoice serviceInvoice = new ServiceInvoice(0.2m, 0.1m);

            //Act
            decimal expectedProvincialSalesTaxRate = 0.3m;

            serviceInvoice.ProvincialSalesTaxRate = 0.3m;

            //Assert
            PrivateObject target = new PrivateObject(serviceInvoice, new PrivateType(typeof(Invoice)));
            decimal       actualprovincialSalesTaxRate = (decimal)target.GetField("provincialSalesTaxRate");

            Assert.AreEqual(expectedProvincialSalesTaxRate, actualprovincialSalesTaxRate);
        }
コード例 #27
0
        public void ServiceInvoiceConstructor_ZeroGSTRate_ReturnZero()
        {
            // Arrange
            decimal provincialSalesTaxRate = 0M, goodsAndServicesTaxRate = 0M;

            ServiceInvoice serviceInvoice = new ServiceInvoice(provincialSalesTaxRate, goodsAndServicesTaxRate);

            PrivateObject target = new PrivateObject(serviceInvoice);

            // Act
            decimal actual = (decimal)target.GetProperty("GoodsAndServicesTaxRate");

            // Assert
            decimal expected = 0M;

            Assert.AreEqual(expected, actual);
        }
コード例 #28
0
        /// <summary>
        /// Clears the form
        /// </summary>
        private void clearForm()
        {
            defaultState();

            dgvServiceItems.Rows.Clear();
            lblSubtotal.Text = string.Empty;
            lblGst.Text      = string.Empty;
            lblPst.Text      = string.Empty;
            lblTotal.Text    = string.Empty;
            mnuServiceGenerateInvoice.Enabled = false;
            mnuContextClear.Enabled           = false;
            errorProvider.Clear();

            // Creates a new service invoice.
            invoice = new ServiceInvoice(decimal.Parse(ConfigurationManager.AppSettings["PST"]) / 100,
                                         decimal.Parse(ConfigurationManager.AppSettings["GST"]) / 100);
        }
コード例 #29
0
        /// <summary>
        /// when click add button, add a list of the information input to the data grid view
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btnAdd_Click(object sender, EventArgs e)
        {
            //when validate
            if (this.ValidateChildren())
            {
                //invoke ServiceInvoice constructor
                ServiceInvoice serviceInvoice = new ServiceInvoice(Decimal.Parse(ConfigurationManager.AppSettings.Get("Provincial Sales Tax (PST) Rate")),
                                                                   Decimal.Parse(ConfigurationManager.AppSettings.Get("Government Sales Tax (GST) Rate")));

                CostType costType = (CostType)(cboType.SelectedIndex);

                serviceInvoice.AddCost(costType, Decimal.Parse(txtCost.Text));

                //add new row to the data grid view
                dgvServiceList.Rows.Add(new[] { rowNumber.ToString(),
                                                txtDescription.Text,
                                                cboType.SelectedItem.ToString(),
                                                Decimal.Parse(txtCost.Text).ToString("c") });

                rowNumber++;

                //calculate display values
                this.LabourCost     = this.LabourCost + serviceInvoice.LabourCost;
                this.PartsCost      = this.PartsCost + serviceInvoice.PartsCost;
                this.MatericalsCost = this.MatericalsCost + serviceInvoice.MaterialsCost;

                //calculate the total values
                this.SubtotalDisplay += serviceInvoice.SubTotal;
                this.PstDisplay      += serviceInvoice.PSTCharged;
                this.GstDisplay      += serviceInvoice.GSTCharged;
                this.TotalDisplay    += serviceInvoice.Total;

                //display the values
                lblSubtotal.Text = this.SubtotalDisplay.ToString("c");
                lblPst.Text      = this.PstDisplay.ToString("F2");
                lblGst.Text      = this.GstDisplay.ToString("F2");
                lblTotal.Text    = this.TotalDisplay.ToString("c");

                clearForm();

                mnuDescriptionGenerate.Enabled = true;
                //enable context mune strip
                mnuContextClear.Enabled = true;
            }
        }
コード例 #30
0
        public void MaterialCostGet_ReturnState()
        {
            // Arrange
            decimal provincialSalesTaxRate = 0.5M, goodsAndServicesTaxRate = 0.8M;

            ServiceInvoice serviceInvoice = new ServiceInvoice(provincialSalesTaxRate, goodsAndServicesTaxRate);

            // Act
            PrivateObject target = new PrivateObject(serviceInvoice);

            target.SetProperty("MaterialCost", 40M);

            // Assert
            decimal expected = 40M;
            decimal actual   = (decimal)target.GetProperty("MaterialCost");

            Assert.AreEqual(expected, actual);
        }
 public void DisplayInvoices(ServiceInvoice[] collection)
 {
     Invoices.Clear();
     foreach (var invoice in collection.Maybe(_ => _, new Invoice[0]))
     {
         Invoices.Add(invoice);
     }
 }
コード例 #32
0
        private void BtnRecordClick(Object sender, EventArgs e)
        {
            var serviceInvoiceSvc = new ServiceInvoiceService(MyConfiguration, null,
                                                              MyOAuthKeyService);
            var serviceInvoice = new ServiceInvoice();

            if ((_invoice == null))
            {
                var customerLnk = new CustomerLink {UID = (Guid) CmboCustomer.SelectedValue};
                serviceInvoice.Customer = customerLnk;
                serviceInvoice.ShipToAddress = TxtAddress.Text;
                serviceInvoice.Number = TxtInvoiceNo.Text;
                serviceInvoice.Date = DtDate.Value;
                serviceInvoice.IsTaxInclusive = ChkTaxInclusive.Checked;

                var lines = new List<ServiceInvoiceLine>();

                foreach (DataGridViewRow row in GrdServiceLines.Rows)
                {
                    if (!row.IsNewRow)
                    {
                        var line = new ServiceInvoiceLine
                                       {
                                           Type = InvoiceLineType.Transaction,
                                           Description = (string) row.Cells["ColDescription"].Value,
                                           Total = Convert.ToDecimal(row.Cells["ColAmount"].Value)
                                       };

                        if ((row.Cells["ColAccount"].Value == null))
                        {
                            MessageBox.Show("you must select an account on each row");
                            return;
                        }
                        var accountlnk = new AccountLink {UID = (Guid) row.Cells["ColAccount"].Value};
                        line.Account = accountlnk;

                        if ((row.Cells["ColTax"].Value == null))
                        {
                            MessageBox.Show("you must select a taxcode on each row");
                            return;
                        }
                        var taxcodelnk = new TaxCodeLink {UID = (Guid) row.Cells["ColTax"].Value};
                        line.TaxCode = taxcodelnk;

                        if ((row.Cells["ColJob"].Value != null))
                        {
                            var joblnk = new JobLink {UID = (Guid) row.Cells["ColJob"].Value};
                            line.Job = joblnk;
                        }

                        lines.Add(line);
                    }
                }

                serviceInvoice.Lines = lines;
                serviceInvoiceSvc.Insert(MyCompanyFile, serviceInvoice, MyCredentials, OnSaveComplete, OnError);
                ShowSpinner();
            }
        }