Ejemplo n.º 1
0
        private void SaleCollectionView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SingleSale saledata = e.CurrentSelection[0] as SingleSale;

            BillItems.Clear();
            for (int i = 0; i < saledata.ItesmsSold.Count; i++)
            {
                BillItems.Add(saledata.ItesmsSold[i]);
            }
            CustommerNameEntry.Text  = saledata.Customer.Name;
            CustommerPhoneEntry.Text = saledata.Customer.PhoneNo;
            DiscountEntry.Text       = saledata.Discount;
        }
Ejemplo n.º 2
0
        public void Replace()
        {
            var sale = new SingleSale
            {
                CallbackUrl = "http://url.de.callback.com/",

                Customer = new Customer
                {
                    Name     = "Cliente de Teste",
                    Identity = RandomCNPJ(),
                    Email    = "*****@*****.**",
                    Address  = new Address
                    {
                        Street        = "Rua Tomaz Gonzaga",
                        Number        = "481",
                        District      = "Três Figueiras",
                        ZipCode       = "91340-480",
                        CityName      = "Porto Alegre",
                        StateInitials = "RS",
                        CountryName   = "Brasil"
                    }
                },
                Products = new List <Product>
                {
                    new Product {
                        Code = "001", Description = "Teste 1", UnitPrice = 150.99M, Quantity = 1M
                    },
                    new Product {
                        Code = "002", Description = "Teste 2", UnitPrice = 20.99M, Quantity = 2M
                    },
                    new Product {
                        Code = "003", Description = "Teste 3", UnitPrice = 30.99M, Quantity = 3M
                    }
                },
                DueDate        = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(1).Month, 1),
                ExpirationDate = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(1).Month, 1),
                DiscountAmount = 50m,
                InterestAmount = 2,
                PenaltyAmount  = 3,
                Instruction    = "Pagar hoje!",
                PaymentMethods = new List <PaymentMethod>
                {
                    new PaymentMethod {
                        CodePaymentMethod = "1"
                    },
                    new PaymentMethod {
                        CodePaymentMethod = "2"
                    },
                    new PaymentMethod {
                        CodePaymentMethod = "3"
                    },
                    new PaymentMethod {
                        CodePaymentMethod = "4"
                    }
                },
                Messages = new List <string> {
                    "Mensagem 1", "Mensagem 2"
                },
                Emails = new List <string> {
                    "*****@*****.**", "*****@*****.**"
                }
            };

            var response2 = safe2pay.Invoice.Replace(sale, "d2a7bab322f040639095f678066d2fdc");

            Assert.NotNull(response2);

            Console.WriteLine(response2.SingleSaleHash);
            Console.WriteLine(response2.SingleSaleUrl);
            //...
        }
Ejemplo n.º 3
0
        public void New()
        {
            var sale = new SingleSale
            {
                CallbackUrl = "http://url.de.callback.com/",

                Customer = new Customer
                {
                    Name     = "Cliente de Teste",
                    Identity = RandomCNPJ(),
                    Email    = "*****@*****.**",
                    Address  = new Address
                    {
                        Street        = "Rua Tomaz Gonzaga",
                        Number        = "481",
                        District      = "Três Figueiras",
                        ZipCode       = "91340-480",
                        CityName      = "Porto Alegre",
                        StateInitials = "RS",
                        CountryName   = "Brasil"
                    }
                },
                Products = new List <Product>
                {
                    new Product {
                        Code = "001", Description = "Teste 1", UnitPrice = 150.99M, Quantity = 1M
                    },
                    new Product {
                        Code = "002", Description = "Teste 2", UnitPrice = 20.99M, Quantity = 2M
                    },
                    new Product {
                        Code = "003", Description = "Teste 3", UnitPrice = 30.99M, Quantity = 3M
                    }
                },
                DueDate        = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(1).Month, 1),
                ExpirationDate = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(1).Month, 1),
                DiscountAmount = 50m,
                InterestAmount = 2,
                PenaltyAmount  = 3,
                Instruction    = "Pagar hoje!",
                PaymentMethods = new List <PaymentMethod>
                {
                    new PaymentMethod {
                        CodePaymentMethod = "1"
                    },
                    new PaymentMethod {
                        CodePaymentMethod = "2"
                    },
                    //new PaymentMethod { CodePaymentMethod = "3" },
                    //new PaymentMethod { CodePaymentMethod = "4" }
                },
                Splits = new List <Split>
                {
                    new Split {
                        CodeTaxType      = EnumTaxType.Percentage,
                        CodeReceiverType = EnumReceiverType.Subaccount,
                        Identity         = "78310447000154",
                        IsPayTax         = false,
                        Amount           = 2,
                    }
                },
                Messages = new List <string> {
                    "Mensagem 1", "Mensagem 2"
                },
                Emails = new List <string> {
                    "*****@*****.**", "*****@*****.**"
                }
            };

            var response = safe2pay.Invoice.New(sale);

            Assert.NotNull(response);

            Console.WriteLine(response.SingleSaleHash);
            Console.WriteLine(response.SingleSaleUrl);
            Console.WriteLine(response.DueDate);
            Console.WriteLine(response.ExpirationDate);
            Console.WriteLine(response.Amount);
            Console.WriteLine(response.CreatedDate);
            Console.WriteLine(response.CallbackUrl);
            Console.WriteLine(response.Status);
            Console.WriteLine(response.IsApplyPenalty);
            Console.WriteLine(response.PenaltyAmount);
            Console.WriteLine(response.IsApplyInterest);
            Console.WriteLine(response.InterestAmount);
            Console.WriteLine(response.DiscountAmount);
            Console.WriteLine(response.BankSlipUrl);

            Console.WriteLine(response.Products.Count);

            foreach (var products in response.Products)
            {
                Console.WriteLine(" --- ");

                Console.WriteLine(products.Description);
                Console.WriteLine(products.Quantity);
                Console.WriteLine(products.UnitPrice);

                Console.WriteLine(" --- ");
            }

            Console.WriteLine(response.Emails.Count);

            foreach (var emails in response.Emails)
            {
                Console.WriteLine(emails);
            }

            Console.WriteLine(response.Customer.Name);
            Console.WriteLine(response.Customer.Identity);
            Console.WriteLine(response.Customer.Email);
            Console.WriteLine(response.Customer.Phone);
            Console.WriteLine(response.Customer.Address.ZipCode);
            Console.WriteLine(response.Customer.Address.Street);
            Console.WriteLine(response.Customer.Address.Number);
            Console.WriteLine(response.Customer.Address.Complement);
            Console.WriteLine(response.Customer.Address.District);
            Console.WriteLine(response.Customer.Address.State);
            Console.WriteLine(response.Customer.Address.City);
            Console.WriteLine(response.Customer.Address.Country);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Substituir solicitação de cobrança.
 /// </summary>
 /// <param name="invoice">Dados da nova solicitação de cobrança, com base na classe SingleSale.</param>
 /// <param name="singleSaleHash">Hash gerado para a cobrança que deverá ser cancelada e substituída.</param>
 public InvoiceResponse Replace(SingleSale invoice, string singleSaleHash)
 {
     return(Client.Put <InvoiceResponse>(false, $"v2/SingleSale/Replace?SingleSaleHash={singleSaleHash}", invoice).GetAwaiter().GetResult());
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Nova solicitação de cobrança.
 /// </summary>
 /// <param name="invoice">Objeto com base na classe SingleSale.</param>
 public InvoiceResponse New(SingleSale invoice)
 {
     return(Client.Post <InvoiceResponse>(false, "v2/SingleSale/Add", invoice).GetAwaiter().GetResult());
 }
Ejemplo n.º 6
0
        public void CreateBillfile(SingleSale sale)
        {
            try
            {
                string Date      = RemoveSymbols(sale.date.ToString());
                string filename  = sale.Customer.Name + Date + ".html";
                string FilePath2 = Path.Combine(FileSystem.AppDataDirectory, filename);
                using (System.IO.StreamWriter file =
                           new System.IO.StreamWriter(FilePath2))
                {
                    file.WriteLine("<!DOCTYPE html>");
                    file.WriteLine("<html>");
                    file.WriteLine("<meta charset=\"utf - 8\">");
                    file.WriteLine("<head>");
                    file.WriteLine("<style>");
                    file.WriteLine("td, th {border: 1px solid #dddddd;text-align: left; padding: 1px;}");
                    file.WriteLine("table {border-collapse: collapse; width: 100%;}");
                    file.WriteLine("</style>");

                    file.WriteLine("</head>");
                    file.WriteLine("<body>");
                    file.WriteLine("<h1 style=\"text-align:center\">Estimate</h1>");
                    file.WriteLine("<p><b>Date: " + DateTime.Now + "</b></p>");
                    file.WriteLine("<p><b>Billed To: " + sale.Customer.Name + "</b></p>");
                    file.WriteLine("<br><br>");
                    file.WriteLine("<table>");
                    file.WriteLine("<tr>");
                    file.WriteLine("<td colspan=40%><b>Item</b></td> ");
                    file.WriteLine("<td colspan=20%><b>Quantity<b></td> ");
                    file.WriteLine("<td colspan=20%><b>Rate</b></td> ");
                    file.WriteLine("<td colspan=20%><b>Net Amt</b></td> ");
                    file.WriteLine("</tr>");
                    for (int i = 0; i < sale.ItesmsSold.Count; i++)
                    {
                        file.WriteLine("<tr>");
                        file.WriteLine("<td colspan=40%>" + sale.ItesmsSold[i].Name + "</td> ");
                        file.WriteLine("<td colspan=20%>" + sale.ItesmsSold[i].Quantity + "</td> ");
                        file.WriteLine("<td colspan=20%>" + "₹ " + sale.ItesmsSold[i].Price + "/-" + "</td> ");
                        file.WriteLine("<td colspan=20%>" + "₹ " + sale.ItesmsSold[i].Price * sale.ItesmsSold[i].Quantity + "/-" + "</td> ");
                        file.WriteLine("</tr>");
                    }
                    file.WriteLine("<tr>");
                    file.WriteLine("</tr>");
                    file.WriteLine("<tr>");
                    file.WriteLine("</tr>");
                    file.WriteLine("<tr>");
                    file.WriteLine("</tr>");
                    file.WriteLine("</table>");

                    file.WriteLine("<br><br>");

                    file.WriteLine("<table>");
                    file.WriteLine("<tr>");
                    file.WriteLine("<td text-align: right colspan=40%>" + "<b>Sum:</b>" + "</td> ");

                    double sum = sale.TotalAmount + Convert.ToDouble(sale.Discount);
                    file.WriteLine("<td colspan=30%> <b>" + "₹ " + sum + "/-" + "</b> </td> ");
                    file.WriteLine("</tr>");
                    file.WriteLine("<tr>");
                    file.WriteLine("<td colspan=40%>" + "<b>Discount:</b>" + "</td> ");

                    file.WriteLine("<td text-align: right colspan=30%><b>" + "₹ " + sale.Discount + "/-" + "</b> </td> ");
                    file.WriteLine("</tr>");
                    file.WriteLine("<tr>");
                    file.WriteLine("<td colspan=40%><b>" + "Grand Total:" + "</b></td> ");

                    file.WriteLine("<td text-align:right colspan=30%><b>" + "₹ " + sale.TotalAmount + "/-" + "</b></td> ");
                    file.WriteLine("</tr>");

                    file.WriteLine("</table>");

                    file.WriteLine("<p text-align:center>Thanks for shopping with us. We hope to have the pleasure of doing business with you in the future.</p>");


                    file.WriteLine("</body >");
                }
            }
            catch (Exception y)
            {
            }
        }
Ejemplo n.º 7
0
        private void CreateBillButton_Clicked(object sender, EventArgs e)
        {
            if (CustommerNameEntry.Text != "" && CustommerPhoneEntry.Text != "" && BillItems.Count > 0)
            {
                if (SelectedCustommer == null)
                {
                    Custommer custommer = new Custommer()
                    {
                        Name    = CustommerNameEntry.Text,
                        PhoneNo = CustommerPhoneEntry.Text
                    };
                    SelectedCustommer = custommer;
                    bool cont = false;

                    if (SearchCustommers.Count > 0)
                    {
                        for (int i = 0; i < SearchCustommers.Count; i++)
                        {
                            if (SearchCustommers[i].Name == custommer.Name && SearchCustommers[i].PhoneNo == custommer.PhoneNo)
                            {
                                cont = true;
                                break;
                            }
                        }
                    }

                    if (!cont)
                    {
                        Custommers.Add(custommer);
                        string cdata = JsonConvert.SerializeObject(Custommers);
                        App.Current.Properties["Custommers"] = cdata;
                        try
                        {
                            string FilePath = Path.Combine(FileSystem.AppDataDirectory, "Custommers.json");
                            File.WriteAllText(FilePath, cdata);
                        }
                        catch (Exception n)
                        {
                        }
                    }
                }
                ObservableCollection <Product> items = new ObservableCollection <Product>()
                {
                };
                for (int i = 0; i < BillItems.Count; i++)
                {
                    items.Add(BillItems[i]);
                }

                SingleSale sale = new SingleSale()
                {
                    Customer    = SelectedCustommer,
                    ItesmsSold  = items,
                    date        = DateTime.Now,
                    Discount    = DiscountEntry.Text,
                    TotalAmount = Total
                };
                SaleData.Insert(0, sale);
                CreateBillfile(sale);
                string salesdata = JsonConvert.SerializeObject(SaleData);
                App.Current.Properties["Sales"] = salesdata;
                try
                {
                    string FilePath2 = Path.Combine(FileSystem.AppDataDirectory, "Sales.json");
                    File.WriteAllText(FilePath2, salesdata);
                }
                catch (Exception t)
                {
                }
                string data = JsonConvert.SerializeObject(products);
                App.Current.Properties["Products"] = data;
                try
                {
                    string FilePath = Path.Combine(FileSystem.AppDataDirectory, "ProductsData.json");
                    File.WriteAllText(FilePath, data);
                }
                catch (Exception h)
                {
                }
                SelectedCustommer = null;

                UpdateCustommerData();
                Reset();
            }
            else
            {
                DisplayAlert("Enter Custommer Data", "Please enter custommer name and phone number", "Ok");
            }
        }