public PrinterInfo Bill(Invoice invoice) { this.PrintTicketHeader( invoice.Name, invoice.TaxCategory, invoice.Address, invoice.Id, invoice.IdType ); foreach (var item in invoice.Items) { this.PrintTicketItem( item.Description, item.Quantity, item.Price, item.Tax ); } this.PrintTicketDiscounts( invoice.Discount ); foreach (var payments in invoice.PaymentMethods) { this.PrintPaymentMethod( payments.Description, payments.PaymentType, payments.Ammount ); } return this.CloseTicket(invoice.TaxCategory); }
public Result Bill(Invoice invoice) { try { var info = _billingService.Bill(invoice); return Result.OK(info.Voucher); } catch (Exception ex) { return Result.Error(ex.Message); } }
private void Print() { var invoice = new Invoice { Name = txtName.Text.Trim(), Address = txtAddress.Text.Trim(), TaxCategory = cmbTaxCategory.SelectedValue.ToString(), Id = txtID.Text.Trim(), IdType = cmbIDType.SelectedValue.ToString(), Discount = Convert.ToDecimal((txtDiscount.Text.Trim() != "") ? txtDiscount.Text : "0"), Items = dgItems.Rows.Cast<DataGridViewRow>().Where(r => r.Cells[1].Value != null && r.Cells[1].Value.ToString().Trim() != "") .Select(r => new InvoiceItem { Description = r.Cells[1].Value.ToString().Trim(), Quantity = Convert.ToInt32(r.Cells[0].Value), Price = Convert.ToDecimal(r.Cells[2].Value), Tax = Configuration.Tax, }), }; var paymentMethods = new List<PaymentMethod>(); if (txtAmmount1.Text.Trim().Length > 0) { var description1 = string.Join(" ", new[] { cmbCard1.Enabled ? cmbCard1.Text.Trim() : null, txtMovementNumber1.Text.Trim().Length > 0 ? txtMovementNumber1.Text.Trim() : null, dtpMovementDate1.Enabled && dtpMovementDate1.Checked ? dtpMovementDate1.Value.ToString("dd/MM/yyyy") : null }.Where(i => !string.IsNullOrEmpty(i))); paymentMethods.Add(new PaymentMethod { Description = description1, PaymentType = cmbPaymentType1.Text, Ammount = Convert.ToDecimal(txtAmmount1.Text.Trim()), }); if (txtAmmount2.Text.Trim().Length > 0) { var description2 = string.Join(" ", new[] { cmbCard2.Enabled ? cmbCard2.Text.Trim() : null, txtMovementNumber2.Text.Trim().Length > 0 ? txtMovementNumber2.Text.Trim() : null, dtpMovementDate2.Enabled && dtpMovementDate2.Checked ? dtpMovementDate2.Value.ToString("dd/MM/yyyy") : null }.Where(i => !string.IsNullOrEmpty(i))); paymentMethods.Add(new PaymentMethod { Description = description2, PaymentType = cmbPaymentType2.Text, Ammount = Convert.ToDecimal(txtAmmount2.Text.Trim()), }); } } invoice.PaymentMethods = paymentMethods; var info = _billingService.Bill(invoice); using (StreamWriter outfile = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + @"\facturas.txt", true)) { outfile.Write(DateTime.Now.ToString() + ", " + info.Voucher + ", " + lblTotalGeneral.Text + ", " + cmbIDType.Text + ", " + txtID.Text + ", " + txtName.Text); } Clear(); }