Example #1
0
        public Sale Create(Sale sale, User user, Customer customer)
        {
            sale.TransactionNumber = Guid.NewGuid().ToString();
            sale.UserId = user.Id;
            sale.CustomerId = customer.Id;

            var newSale = salesRepository.Add(sale);
            
            sale.SaleDetails.ToList().ForEach(sd =>
            {
                sd.SaleId = newSale.Id;
                salesRepository.Add(sd);
            });

            return newSale;
        }
Example #2
0
        public frmCharge(User user, Customer customer, Sale sale, decimal amount, decimal discount, decimal total)
        {
            InitializeComponent();

            this.User = user;
            this.Customer = customer;
            sale.Amount = amount;
            sale.Discount = discount;
            sale.Total = total;
            this.Sale = sale;

            this.salesService = new SalesService();
            this.productsService = new ProductsService();

            this.Load += (s, e) =>
            {
                txtTicket.Text = salesService.GetTicketNumber().ToString();
                txtDiscout.Text = this.Sale.Discount.ToString();
                txtTotal.Text = this.Sale.Total.ToString();

                cmbUser.DataSource = new List<User> { this.User };
                cmbUser.DisplayMember = "Username";
                cmbUser.ValueMember = "Id";

                cmbCustomer.DataSource = new List<Customer> { this.Customer };
                cmbCustomer.DisplayMember = "FullName";
                cmbCustomer.ValueMember = "Id";

                txtCash.Focus();
            };

            btnCharge.Click += (s, e) =>
            {
                var currentSale = this.Sale;

                salesService.Create(currentSale, this.User, this.Customer);

                //
                //PrintTicket
                //
                PrintTicket(this.Sale);

                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            };

            txtCash.KeyDown += (s, e) =>
            {
                if (e.KeyCode == Keys.Enter)
                {
                    var currentSale = this.Sale;

                    salesService.Create(currentSale, this.User, this.Customer);

                    //
                    //PrintTicket
                    //
                    PrintTicket(this.Sale);

                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    this.Close();
                }
            };

            btnCancel.Click += (s, e) =>
            {
                this.DialogResult = System.Windows.Forms.DialogResult.No;
            };
        }
Example #3
0
        public Sale Add(Sale sale)
        {
            var newSale = this.db.Sales.Upsert(sale);

            return newSale;
        }
Example #4
0
        private void PrintTicket(Sale sale)
        {
            var ticket = new Ticket();
            ticket.MaxChar = 30;
            ticket.MaxCharDescription = 15;

            ticket.AddHeaderLine("[Shop Name Here]");
            ticket.AddHeaderLine("[Taxpayer ID Here]");
            ticket.AddHeaderLine("[Shop Address Here]");
            ticket.AddHeaderLine("[Shop Phone Here]");
            ticket.AddHeaderLine("");
            ticket.AddHeaderLine("[Customer Name Here]");

            ticket.AddSubHeaderLine("[Ticket Number Here*");
            ticket.AddSubHeaderLine("[Sales User Name Here]");
            ticket.AddSubHeaderLine("[Current Date and Time Here]");

            decimal subtotal = sale.Amount;
            int productNumer = 0;

            sale.SaleDetails.ToList().ForEach(sd =>
            {
                productNumer += sd.Qty;
                var product = productsService.Find(sd.ProductId);

                ticket.AddItem(sd.Qty.ToString(), product.Name, product.Price.ToString("C"));
            });

            ticket.AddTotal("Amount : ", sale.Amount.ToString("C"));
            ticket.AddTotal("", "");
            ticket.AddTotal("Tax : ", "[Taxs Here]");
            ticket.AddTotal("", "");
            ticket.AddTotal("Dicount : ", sale.Discount.ToString("C"));
            ticket.AddTotal("", "----------");
            ticket.AddTotal("TOTAL : ", sale.Total.ToString("C"));
            ticket.AddTotal("Cash : ", string.Format(txtCash.Text, "C"));
            ticket.AddTotal("Change : ", string.Format(txtChange.Text, "C"));

            ticket.AddFooterLine("");
            ticket.AddFooterLine(string.Format("Products number: {0}", productNumer.ToString()));

            if (ticket.PrinterExists("doPDF v7"))
                ticket.PrintTicket("doPDF v7");
        }
Example #5
0
        private void Charge()
        {
            if (listView1.Items.Count == 0)
                return;

            var sale = new Sale();
            
            sale.SaleDetails = SaleDetails(listView1.Items);

            var customer = customersService.Find(txtTaxID.Text);

            var frmCharge = new frmCharge(this.User, customer, sale, Convert.ToDecimal(txtSubtotal.Text), Convert.ToDecimal(txtDiscount.Text), Convert.ToDecimal(txtTotal.Text));
            frmCharge.ShowDialog();

            if (frmCharge.DialogResult == System.Windows.Forms.DialogResult.OK)
                StartNewSale();
            else if (frmCharge.DialogResult == System.Windows.Forms.DialogResult.No)
                frmCharge.Dispose();
        }