Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            double Subtotal;
            double DiscountPercent;
            double DiscountAmount;
            double InvoiceTotal;

            Subtotal = double.Parse(txtSubtotal.Text);
            if (Subtotal >= 500)
            {
                DiscountPercent = 0.2;
            }
            else if (Subtotal >= 250 && Subtotal < 500)
            {
                DiscountPercent = 0.15;
            }
            else if (Subtotal >= 100 && Subtotal < 250)
            {
                DiscountPercent = 0.1;
            }
            else
            {
                DiscountPercent = 0.0;
            }
            DiscountAmount          = Subtotal * DiscountPercent;
            InvoiceTotal            = Subtotal - DiscountAmount;
            txtDiscountPercent.Text = DiscountPercent.ToString("p1"); //p1 means percentage
            txtDiscountAmount.Text  = "$" + DiscountAmount.ToString();
            txtTotal.Text           = "$" + InvoiceTotal.ToString();
            txtResult.Text          = "Dear Customer you have to pay: $" + InvoiceTotal.ToString();
        }
Exemplo n.º 2
0
        private async Task <InvoiceTotal> GetTotal(CartMessage cartMessage)
        {
            var currencies = await _currenciesService.GetCurrencies();

            var usd2brl = currencies.Single(t => string.Equals(t.CurrencyCode, "USD_TO_BRL", StringComparison.CurrentCultureIgnoreCase));
            var usd2eur = currencies.Single(t => string.Equals(t.CurrencyCode, "USD_TO_EUR", StringComparison.CurrentCultureIgnoreCase));

            var usd2brl_factor = GetFactor(usd2brl.CurrencyValue, usd2brl.Scale);
            var usd2eur_factor = GetFactor(usd2eur.CurrencyValue, usd2eur.Scale);
            var brl2usd_factor = 1 / usd2brl_factor;
            var eur2usd_factor = 1 / usd2eur_factor;

            var currencyConversionTable = new Dictionary <string, double>()
            {
                { "USD-BRL", usd2brl_factor },
                { "USD-EUR", usd2eur_factor },
                { "USD-USD", 1 },

                { "EUR-BRL", eur2usd_factor *usd2brl_factor },
                { "EUR-EUR", 1 },
                { "EUR-USD", eur2usd_factor },

                { "BRL-BRL", 1 },
                { "BRL-EUR", brl2usd_factor *usd2eur_factor },
                { "BRL-USD", brl2usd_factor }
            };

            var total = new InvoiceTotal()
            {
                Amount       = 0,
                Scale        = 2,
                CurrencyCode = cartMessage.Invoice.CurrencyCode
            };

            foreach (var item in cartMessage.Cart.Items)
            {
                var itemPrice        = item.Price / Math.Pow(10, item.Scale);
                var conversionKey    = $"{item.CurrencyCode}-{cartMessage.Invoice.CurrencyCode}".ToUpper();
                var conversionFactor = currencyConversionTable[conversionKey];
                var itemAmount       = Convert.ToInt64(itemPrice * conversionFactor * 100);

                total.Amount += itemAmount;
            }

            return(total);
        }
Exemplo n.º 3
0
 //TOSTRING (with delimitter)
 public string ToString(string delim)
 {
     return(RecordType + delim +
            VendorCode + delim +
            LocationCode + delim +
            PurchaseOrderNo + delim +
            ((Object)ExpectedDeliveryDate ?? " ") + delim +
            VendorInvoiceNo + delim +
            InvoiceDate.ToString("MM'/'dd'/'yyyy") + delim +      //11/16/2016   (forces the "/" separator)
            InvoiceTotal.ToString("0.00") + delim +               //format (two decimal places)
            (TaxGlDescription ?? " ") + delim +
            ((Object)TaxValue ?? " ") + delim +
            (FreightShippingGlDescription ?? " ") + delim +
            ((Object)FreightShippingValue ?? " ") + delim +
            Misc1GlDescription + delim +
            Misc1Value.ToString("0.00"));
 }
Exemplo n.º 4
0
 private Invoice CreateInvoiceApiPayload(CartMessage cartMessage, InvoiceTotal total)
 {
     return(new Invoice()
     {
         Id = cartMessage.Cart.Id,
         CustomerId = cartMessage.Cart.CustomerId,
         Status = cartMessage.Cart.Status,
         Total = total,
         Items = cartMessage.Cart.Items.Select(t => new InvoiceItem()
         {
             Id = t.Product.Id,
             CurrencyCode = t.CurrencyCode,
             ImageURL = t.Product.ImageURL,
             Name = t.Product.Name,
             Price = t.Price,
             Scale = t.Scale
         })
     });
 }
Exemplo n.º 5
0
        //TOSTRING OVERRIDE
        public override string ToString()
        {
            return(RecordType + "\t" +
                   VendorCode + "\t" +
                   LocationCode + "\t" +
                   PurchaseOrderNo + "\t" +
                   ((Object)ExpectedDeliveryDate ?? " ") + "\t" +
                   VendorInvoiceNo + "\t" +
                   InvoiceDate.ToString("MM'/'dd'/'yyyy") + "\t" +      //11/16/2016    (forces the "/" separator)
                   InvoiceTotal.ToString("0.00") + "\t" +               //format (two decimal places)

                   (TaxGlDescription ?? " ") + "\t" +
                   //(handle NULL value and converting (double? to double) in the correct format)
                   MyDoubleToString(TaxValue) + "\t" +
                   //((Object)TaxValue ?? " ") + "\t" +

                   (FreightShippingGlDescription ?? " ") + "\t" +
                   //(handle NULL value and converting (double? to double) in the correct format)
                   MyDoubleToString(FreightShippingValue) + "\t" +
                   //((Object)FreightShippingValue ?? " ") + "\t" +

                   Misc1GlDescription + "\t" +
                   Misc1Value.ToString("0.00"));
        }
Exemplo n.º 6
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            DateTime DateTime1 = new DateTime(2009, 12, 27);
            DateTime DateTime2 = new DateTime(2010, 1, 3);

            ReportClass invoiceT = new InvoiceTotal();

            invoiceT.DataSourceConnections[0].SetConnection(Services.get_GUI.serverName, Services.get_GUI.databaseName, true);

            invoiceT.SetParameterValue("@Store_ID", StaticClass.storeId);
            invoiceT.SetParameterValue("@DateTime1", DateTime1);
            invoiceT.SetParameterValue("@DateTime2", DateTime2);

            //ReportClass invoice = new rptItemDept();
            //string[] pa = {"@Store_ID","Report_Title_Param"};
            //string[] value = {StaticClass.storeId,"mat hang"};
            //test.FillDataReport(invoice,pa,value,true);
            //crystalReportViewer1.ReportSource = invoice;



            //ReportClass invoice = new rptInventoryByApha();
            //string[] pa = { "@Store_ID", "Report_Title_Param" };
            //string[] value = { StaticClass.storeId, "mat hang" };
            //test.FillDataReport(invoice, pa, value, true);
            //crystalReportViewer1.ReportSource = invoice;


            ReportClass invoice = new rptInvoiceTotalsDaily();

            string[] pa    = { "@Store_ID", "Report_Title_Param" };
            string[] value = { StaticClass.storeId, "mat hang" };
            test.FillDataReport(invoice, pa, value, true);
            crystalReportViewer1.ReportSource = invoice;
            ////string[] para = {"@Store_ID", "Report_Title_Param" };
            ////string[] value = {StaticClass.storeId,"Invoice Daily"};

            ////test.FillDataReport(invoiceT, para, value, true);

            ////invoiceT.SetParameterValue("@Store_ID", StaticClass.storeId);
            ////invoiceT.SetParameterValue("Report_Title_Param", "thanh report");
            //crystalReportViewer1.ReportSource = invoiceT;
            //string[] para = { "@Store_ID", "Report_Title_Param" };
            //string[] value = { StaticClass.storeId, "Invoice Daily" };
            //rptItemDept t = new rptItemDept();
            //test.FillDataReport(t, para, value, true);
            //crystalReportViewer1.ReportSource = invoiceT};
            ////crystalReportViewer1.Update();
            //invoiceT.PrintToPrinter(1, false, 1, 1);

            //string result = MessBox2Choice.ShowBox("Do you want to exit?",Color.Red);
            //if (result.Equals("1"))
            //{
            //    MessageBox.Show("OK Button was Clicked");
            //}

            //if (result.Equals("2"))
            //{
            //    MessageBox.Show("Cancel Button was Clicked");
            //}
        }
Exemplo n.º 7
0
        internal static string AddEditInvoice(InvoiceVm invoiceVm)
        {
            string isSaved = "true";

            AccountingEntities db = new AccountingEntities();
            int  invoiceId        = invoiceVm.InvoiceId;
            byte invoiceType      = invoiceVm.InvoiceType;
            // int hbId = invoiceVm.HouseBillId;

            Invoice invDb;

            if (invoiceId == 0)
            {
                invDb = new Invoice();
            }
            else
            {
                invDb = db.Invoices.Include("InvoiceDetails").Include("InvoiceTotals")
                        .Where(x => x.InvoiceId == invoiceId).FirstOrDefault();
                //Delete Invoice details and totals .. will insert it again
                var invDbTotals  = invDb.InvoiceTotals;
                var invDbDetails = invDb.InvoiceDetails;
                foreach (var item in invDbDetails)
                {
                    invDb.InvoiceDetails.Remove(item);
                }
                foreach (var item in invDbTotals)
                {
                    invDb.InvoiceTotals.Remove(item);
                }
            }


            Mapper.CreateMap <InvoiceVm, Invoice>()
            .ForMember(x => x.InvoiceTotals, y => y.Ignore())
            .ForMember(x => x.InvoiceDetails, y => y.Ignore())
            .IgnoreAllNonExisting();
            Mapper.Map(invoiceVm, invDb);

            InvoiceDetail invDetail;

            Mapper.CreateMap <InvoiceDetailVm, InvoiceDetail>().IgnoreAllNonExisting();
            foreach (var item in invoiceVm.InvoiceDetails)
            {
                if (item.IsSelected == true)
                {
                    invDetail = new InvoiceDetail();
                    Mapper.Map(item, invDetail);
                    invDb.InvoiceDetails.Add(invDetail);
                }
            }

            InvoiceTotal invTotalDb;

            foreach (var item in invoiceVm.InvoiceTotals)
            {
                invTotalDb = new InvoiceTotal()
                {
                    CurrencyId       = item.CurrencyId,
                    TotalAmount      = item.TotalAmount,
                    CurrencySign     = item.CurrencySign,
                    TaxDepositAmount = item.TaxDepositAmount,
                    TotalBeforeTax   = item.TotalBeforeTax,
                    VatTaxAmount     = item.VatTaxAmount
                };

                invDb.InvoiceTotals.Add(invTotalDb);
            }



            using (TransactionScope transaction = new TransactionScope())
            {
                try
                {
                    //Add shipper or consignee to accounting chart
                    string accountId = GetAccountId(invoiceVm.OrderFrom, invoiceVm.ShipperId, invoiceVm.ConsigneeId);

                    if (invoiceId == 0)
                    {
                        invDb.InvoiceCode = AdminHelper.GeneratePrefixCode(PrefixForEnum.AccountingInvoice, true);
                        db.Invoices.Add(invDb);
                    }

                    db.SaveChanges();

                    invoiceVm.InvoiceId   = invDb.InvoiceId;
                    invoiceVm.InvoiceCode = invDb.InvoiceCode;


                    //Change HB status
                    if (invoiceId == 0)
                    {
                        //Add invoice to accounting transactions table
                        AddInvToTransTable(accountId, invoiceVm);

                        HouseBillHelper.ChangeHBStatus(invDb.HouseBillId, (byte)StatusEnum.InvoiceIssued);
                        OperationHelper.ChangeOperationStatus(invDb.OperationId, (byte)StatusEnum.InvoiceIssued);
                    }

                    transaction.Complete();
                }
                catch (DbEntityValidationException e)
                {
                    isSaved = "false " + e.Message;

                    //AdminHelper.LastIdRemoveOne(PrefixForEnum.AccountingInvoice);
                }
                catch (Exception e)
                {
                    isSaved = "false " + e.Message;
                    //AdminHelper.LastIdRemoveOne(PrefixForEnum.AccountingInvoice);
                }
            }

            return(isSaved);
        }