private async void paymentDebtBtn_Click(object sender, EventArgs e) { paymentDebtBtn.Enabled = false; Cliente customer = await Task.Run(() => new Cliente(this.employee.CustomerID)); if (customer.Debt <= 0.0) { return; } FormPagar form = new FormPagar("$" + customer.Debt.ToString("n2"), false, 0.0); //DarkForm darkForm = new DarkForm(); //darkForm.Show(); if (form.ShowDialog() == DialogResult.OK) { double customerPayment = Convert.ToDouble(form.Pay); double cash = Convert.ToDouble(form.Cash); if (customerPayment > 0.0) { DataTable acountsReceivable = customer.GetAcountsReceivable(); double change = cash <= customerPayment ? 0.0 : cash - customerPayment; for (int index = 0; index < acountsReceivable.Rows.Count; ++index) { DataRow row = acountsReceivable.Rows[index]; if (customerPayment > 0.0) { double cash1 = customerPayment - Convert.ToDouble(row["Resto"]) <= 0.0 ? customerPayment : Convert.ToDouble(row["Resto"]); customer.RegisterPayment(Convert.ToInt64(row["id_ventas"]), DateTime.Now, cash1, this.User_employeeID); customer.Pay(cash1, Convert.ToInt64(row["id_ventas"])); customerPayment -= cash1; } } FormCambio formCambio = new FormCambio(change); this.customerPaymentDocument = new PrintDocument(); customerPaymentDocument.PrintController = new StandardPrintController(); this.customerPaymentDocument.PrintPage += (PrintPageEventHandler)((ss, ee) => { Graphics graphics = ee.Graphics; var ticket = new PrinterTicket(); this.customerPaymentDocument.PrinterSettings.PrinterName = ticket.printerName; this.customerPaymentDocument.DefaultPageSettings.PaperSize = new PaperSize("Custom", 200, 200); int width = (int)this.printDialog1.PrinterSettings.DefaultPageSettings.PrintableArea.Width; int y1 = 0; Size stringSize = ticket.printLogo(graphics, y1); y1 = stringSize.Height == 0 ? y1 : y1 + stringSize.Height + 10; stringSize = ticket.printHeader(graphics, y1); y1 = stringSize.Height == 0 ? y1 : y1 + stringSize.Height + 10; stringSize = ticket.printAddress(graphics, y1); y1 = stringSize.Height == 0 ? y1 : y1 + stringSize.Height + 10; stringSize = ticket.printPhone(graphics, y1); y1 = stringSize.Height == 0 ? y1 : y1 + stringSize.Height + 10; y1 += printingClass.drawLine(10, width - 10, graphics, y1) + 5; string str = "Pago de Cliente"; Font font = new Font("times new roman", 17f, FontStyle.Bold);//this.getFont(str1, width, FontStyle.Regular); y1 += printingClass.printLine(str, font, width, StringAlignment.Center, ee.Graphics, y1) + 1; font = width > 200 ? new Font("Times new Roman", 9.9f) : new Font("Times new Roman", 7f); if (customer.ID != 0) { str = "Cliente: " + customer.Name; y1 += printingClass.printLine(str, font, width, StringAlignment.Near, ee.Graphics, y1) + 1; } str = string.Format("Fecha: {0} {1}", DateTime.Now.Date.ToShortDateString(), DateTime.Now.ToShortTimeString()); y1 += printingClass.printLine(str, font, width, StringAlignment.Near, graphics, y1); y1 += printingClass.drawLine(10, width - 10, graphics, y1) + 3; customerPayment = Convert.ToDouble(form.Pay); str = string.Format("Adeudo Previo: ${0}", (customer.Debt + customerPayment).ToString("n2")); y1 += printingClass.printLine(str, font, width, StringAlignment.Near, graphics, y1) + 1; str = string.Format("Monto a pagar: ${0}", customerPayment.ToString("n2")); y1 += printingClass.printLine(str, font, width, StringAlignment.Near, graphics, y1) + 1; str = string.Format("Adeudo Actualizado: ${0}", customer.Debt.ToString("n2")); y1 += printingClass.printLine(str, new Font("times new roman", 10f, FontStyle.Bold), width, StringAlignment.Near, graphics, y1); y1 += printingClass.drawLine(10, width - 10, graphics, y1) + 3; str = string.Format("Efectivo: ${0}", cash.ToString("n2")); y1 += printingClass.printLine(str, font, width, StringAlignment.Far, graphics, y1) + 1; str = string.Format("Cambio: ${0}", change.ToString("n2")); y1 += printingClass.printLine(str, font, width, StringAlignment.Far, graphics, y1) + 1; if (ticket.footerDisplay) { printingClass.printLine(ticket.footer, ticket.footerFont, width, StringAlignment.Center, graphics, y1); } }); try { this.customerPaymentDocument.PrinterSettings.PrinterName = this.printDialog1.PrinterSettings.PrinterName; this.printDialog1.Document = this.customerPaymentDocument; this.customerPaymentDocument.Print(); } catch (InvalidPrinterException ex) { int num = (int)MessageBox.Show("Registre una impresora para poder utilizar esta opción", "No se ha registrado impresora"); } int num10 = (int)formCambio.ShowDialog(); customer.RefreshInfo(); this.debtLbl.Text = "$" + customer.Debt.ToString("n2"); } else { int num11 = (int)MessageBox.Show("El Cliente no genera ningun adeudo"); } } paymentDebtBtn.Enabled = true; //darkForm.Close(); }
private void PayBtn_Click(object sender, EventArgs e) { if (this.PO.delivered) { FormPagar formPagar = new FormPagar(this.PO.total - this.PO.pay, true); DarkForm darkForm = new DarkForm(); darkForm.Show(); if (formPagar.ShowDialog() == DialogResult.OK) { this.PO.MakePayment(Convert.ToDouble(formPagar.Pay), this.CurrentEmployeeID); this.updateValues(); if (m_Drawer != null) { try { //Open the device //Use a Logical Device Name which has been set on the SetupPOS. m_Drawer.Open(); //Get the exclusive control right for the opened device. //Then the device is disable from other application. m_Drawer.Claim(1000); //Enable the device. m_Drawer.DeviceEnabled = true; //Open the drawer by using the "OpenDrawer" method. m_Drawer.OpenDrawer(); m_Drawer.DeviceEnabled = false; m_Drawer.Release(); m_Drawer.Close(); } catch (PosControlException) { useNativePrinter(); } } else { useNativePrinter(); } //<<<step1>>>--End MessageBox.Show("Se realizó abono con exito"); if (this.PO.paid) { if (inASearch) { searchPO(); } else { this.loadPurchases(); } } } darkForm.Close(); } else { MessageBox.Show("Primero debe confirmar el pedido para realizar un abono", "No se puede realizar un abono", MessageBoxButtons.OK); } }