Exemplo n.º 1
0
        //Print Bill Coti
        public void PrintCotiBT_Click(object sender, RoutedEventArgs e)
        {
            if (PrintCotiBT.IsEnabled == true)
            {
                if (BillProducts.Count == 0)
                {
                    MessageBox.Show("No se puede ralizar impresion ya que no hay productos registrados");
                    return;
                }

                //Create product data object
                var Pdata = new List <NovaAPI.APITickets.ProductClass>();

                foreach (var item in BillProducts)
                {
                    var AddData = new NovaAPI.APITickets.ProductClass()
                    {
                        product_count           = item.product_count,
                        product_id              = item.product_id,
                        product_pricevalue      = item.product_value.ToString(),
                        product_tax             = item.product_tax,
                        product_h               = HStatus,
                        product_discountpercent = item.product_discount,
                        product_discountvalue   = item.product_discountvalue.ToString(),
                        product_code            = item.product_code,
                        product_name            = item.product_name,
                        product_total           = item.product_total.ToString(),
                        product_unity           = item.product_type
                    };
                    Pdata.Add(AddData);
                }

                //Create ticket data object
                var data = new NovaAPI.APITickets.TicketData
                {
                    payment_type         = "0",
                    payment_method       = "0",
                    expiration_date      = "",
                    ticket_total         = TotalValue.ToString(),
                    ticket_iva           = IvaValue.ToString(),
                    ticket_iva5          = Iva5Value.ToString(),
                    ticket_iac           = IacValue.ToString(),
                    ticket_totalpayment  = "0",
                    ticket_changepayment = "0",
                    ticket_leftpayment   = "0",
                    ticket_comment       = "",
                    ticket_h             = HStatus,
                    products             = Pdata,
                    client_name          = ClientNameLB.Content.ToString(),
                    client_documentid    = ClientDocumentLB.Content.ToString(),
                    client_address       = ClientAddressLB.Content == null ? "" : ClientAddressLB.Content.ToString(),
                    client_phones        = ClientPhonesLB.Content.ToString(),
                    ticket_subtotal      = Subtotal.ToString(),
                    ticket_coti          = "1",
                    user_realname        = DataConfig.RealName
                };

                PrintFunctions.PrintFunctions.Print(Classes.Enums.PrintPages.FinalTicket, data);
            }
        }
Exemplo n.º 2
0
        //Finish ticket
        private async void FinishBillBT_Click(object sender, RoutedEventArgs e)
        {
            //Create product data object
            var Pdata = new List <NovaAPI.APITickets.ProductClass>();

            foreach (var item in BillProducts)
            {
                var AddData = new NovaAPI.APITickets.ProductClass()
                {
                    product_count           = item.product_count,
                    product_id              = item.product_id,
                    product_pricevalue      = item.product_value.ToString(),
                    product_tax             = item.product_tax,
                    product_h               = HStatus,
                    product_discountpercent = item.product_discount,
                    product_discountvalue   = item.product_discountvalue.ToString(),
                    product_code            = item.product_code,
                    product_name            = item.product_name,
                    product_total           = item.product_total.ToString(),
                    product_unity           = item.product_type
                };
                Pdata.Add(AddData);
            }

            //Create ticket data object
            var data = new NovaAPI.APITickets.TicketData
            {
                branch_id            = DataConfig.WorkPlaceID.ToString(),
                box_id               = DataConfig.WorkPointID.ToString(),
                box_movement_id      = NovaAPI.APIBoxMovements.movement_id,
                client_id            = SelectedClientID,
                payment_type         = PaymentType.SelectedIndex.ToString(),
                payment_method       = PaymentMethodCB.SelectedIndex.ToString(),
                expiration_date      = PaymentType.SelectedIndex != 0 ? BillDatePicker.SelectedDate.Value.ToString("yyyy-MM-dd") : "",
                ticket_total         = TotalValue.ToString(),
                ticket_iva           = IvaValue.ToString(),
                ticket_iva5          = Iva5Value.ToString(),
                ticket_iac           = IacValue.ToString(),
                ticket_totalpayment  = InValue.ToString(),
                ticket_changepayment = InChangeValue.ToString(),
                ticket_leftpayment   = inLeftValue.ToString(),
                ticket_comment       = CommentTX.Text,
                ticket_h             = HStatus,
                products             = Pdata,
                client_name          = ClientNameLB.Content.ToString(),
                client_documentid    = ClientDocumentLB.Content.ToString(),
                client_address       = ClientAddressLB.Content.ToString(),
                client_phones        = ClientPhonesLB.Content.ToString(),
                ticket_subtotal      = Subtotal.ToString()
            };

            TicketData = data;

            //Create Json string request
            string requestData = JsonConvert.SerializeObject(data);

            //Create request
            bool Response = await NovaAPI.APITickets.GetValues("1", DataConfig.LocalAPI, requestData);

            if (Response)
            {
                PrintIn.Visibility     = Visibility.Visible;
                InProductBT.Visibility = Visibility.Collapsed;
                InProductBT.IsEnabled  = false;
                FinalIn.Visibility     = Visibility.Collapsed;
                FinalIn.IsEnabled      = false;

                PrintCotiBT.IsEnabled = false;

                BillFinishExitBT_Click(null, null);

                PrintIn.Focus();
            }
            else
            {
                BillFinishExitBT_Click(null, null);
                MessageBox.Show(NovaAPI.APITickets.Message);
            }
        }
Exemplo n.º 3
0
        //Print ticket
        private static void PrintTicket(object sender, PrintPageEventArgs e, NovaAPI.APITickets.TicketData TicketData)
        {
            try
            {
                //Get values
                int maxPageSize = e.PageBounds.Height;
                int XPosition   = 0;

                //Set values
                var g = e.Graphics;
                int LineHeightValue = 14;

                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
                g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.None;


                string Header = TicketData.ticket_coti == "1" ? $"{DataConfig.PrintHeader}{Environment.NewLine}{Environment.NewLine}COTIZACIÓN" : TicketData.ticket_h == "0" ? DataConfig.PrintHeader : "RECIBO DE VENTA";

                //PRINT HEADER
                int       HeaderLines     = Header.Split('\n').Length;
                Rectangle HeaderRectangle = new Rectangle(0, 0, PagwWith, 20 * HeaderLines);

                //Header TEXT print
                using (StringFormat sf = new StringFormat())
                {
                    sf.Alignment = StringAlignment.Center;
                    g.DrawString(Header, printHeaderFont, Brushes.Black, HeaderRectangle, sf);
                }

                XPosition = HeaderRectangle.Height + 30; //SET POSITION

                if (TicketData.ticket_copy == "1")
                {
                    Rectangle CopyRectangle = new Rectangle(0, XPosition, PagwWith, (LineHeightValue * 2));

                    //Header TEXT print
                    using (StringFormat sf = new StringFormat())
                    {
                        sf.Alignment = StringAlignment.Center;
                        g.DrawString("---- COPIA ----", printHeaderFont, Brushes.Black, CopyRectangle, sf);
                    }

                    XPosition += LineHeightValue * 2; //SET POSITION
                }

                string ExpireDate = "";

                if (TicketData.expiration_date != "")
                {
                    ExpireDate = $"VENCE: {TicketData.expiration_date}{Environment.NewLine}";
                }

                //PRINT TICKET INFO
                string TicketInfo = $"RECIBO DE CAJA: {TicketData.ticketid}{Environment.NewLine}FECHA: {DateTime.Now.ToString()}{Environment.NewLine}{ExpireDate}{Environment.NewLine}" +
                                    $"CLIENTE: {TicketData.client_name}{Environment.NewLine}IDENTIFICACIÓN: {TicketData.client_documentid}{Environment.NewLine}" +
                                    $"DIRECCIÓN: {TicketData.client_address}{Environment.NewLine}TELEFONOS: {TicketData.client_phones}";

                if (TicketData.ticket_h == "1")
                {
                    TicketInfo = $"FECHA: {DateTime.Now.ToString()}{Environment.NewLine}{ExpireDate}{Environment.NewLine}" +
                                 $"CLIENTE: {TicketData.client_name}{Environment.NewLine}IDENTIFICACIÓN: {TicketData.client_documentid}{Environment.NewLine}" +
                                 $"DIRECCIÓN: {TicketData.client_address}{Environment.NewLine}TELEFONOS: {TicketData.client_phones}";
                }

                if (TicketData.ticket_coti == "1")
                {
                    TicketInfo = $"FECHA: {DateTime.Now.ToString()}{Environment.NewLine}{ExpireDate}{Environment.NewLine}" +
                                 $"CLIENTE: {TicketData.client_name}{Environment.NewLine}IDENTIFICACIÓN: {TicketData.client_documentid}{Environment.NewLine}" +
                                 $"DIRECCIÓN: {TicketData.client_address}{Environment.NewLine}TELEFONOS: {TicketData.client_phones}";
                }

                int TicketInfoLines = TicketInfo.Split('\n').Length;

                Rectangle TicketInfoRectangle = new Rectangle(0, XPosition, PagwWith, LineHeightValue * TicketInfoLines);

                using (StringFormat sf = new StringFormat())
                {
                    g.DrawString(TicketInfo, printFontBold, Brushes.Black, TicketInfoRectangle, sf);
                }

                XPosition += TicketInfoRectangle.Height + 20; //SET POSITION


                //TICKET INFO BOX VALUES

                string PaymentCondition = TicketData.payment_type == "0" ? "CONTADO" : "CREDITO";
                string PaymentMethod    = TicketData.payment_method == "0" ? "EFECTIVO" : "";

                string PlusInfo      = $"CAJERO: {TicketData.user_realname}{Environment.NewLine}CONDICIONES DE PAGO: {PaymentCondition}{Environment.NewLine}FORMA DE PAGO: {PaymentMethod}";
                int    PlusInfoLines = PlusInfo.Split('\n').Length;

                Rectangle PlusInfoRectangle = new Rectangle(0, XPosition, PagwWith, LineHeightValue * PlusInfoLines);

                using (StringFormat sf = new StringFormat())
                {
                    g.DrawString(PlusInfo, printFont, Brushes.Black, PlusInfoRectangle, sf);
                }

                XPosition += PlusInfoRectangle.Height + 20; //SET POSITION

                //PRINT TICKET PRODUCTS HEADER
                g.DrawString("COD.", printHeaderFont, Brushes.Black, 0, XPosition);
                g.DrawString("DESCRIPCIÓN", printHeaderFont, Brushes.Black, 100, XPosition);
                g.DrawString("CANT.", printHeaderFont, Brushes.Black, 0, XPosition + LineHeightValue);
                g.DrawString("VLR. UNITARIO.", printHeaderFont, Brushes.Black, 100, XPosition + LineHeightValue);
                g.DrawString("TOTAL", printHeaderFont, Brushes.Black, 220, XPosition + LineHeightValue);
                g.DrawString("DESCUENTO", printHeaderFont, Brushes.Black, 100, XPosition + (LineHeightValue * 2));

                XPosition += PlusInfoRectangle.Height + 10; //SET POSITION

                //PRINT TICKET PRODUCTS
                for (int i = 0; i < TicketData.products.Count; i++)
                {
                    bool Discount = false;

                    g.DrawString(TicketData.products[i].product_code, printFont, Brushes.Black, 0, XPosition);                                                                                                            //COD
                    g.DrawString(TicketData.products[i].product_name, printFontBold, Brushes.Black, 100, XPosition);                                                                                                      //DESCRIPCION
                    g.DrawString($"{TicketData.products[i].product_count} \t {GeneralFunctions.GetUnityTypeString(TicketData.products[i].product_unity)}", printFontBold, Brushes.Black, 0, XPosition + LineHeightValue); //CANT
                    g.DrawString(string.Format("{0:C0}", Convert.ToInt32(TicketData.products[i].product_pricevalue)), printFontBold, Brushes.Black, 100, XPosition + LineHeightValue);                                    //V UNITARIO
                    using (StringFormat sf = new StringFormat())
                    {
                        sf.Alignment = StringAlignment.Far;
                        Rectangle TotalRectangle = new Rectangle(180, XPosition + LineHeightValue, PagwWith - 180, LineHeightValue);
                        g.DrawString(string.Format("{0,10:C0}", Convert.ToInt32(TicketData.products[i].product_total)), printFontBold, Brushes.Black, TotalRectangle, sf); //TOTAL
                    }

                    //DISCOUNT PRINT
                    if (TicketData.products[i].product_discountpercent != "0")
                    {
                        g.DrawString(string.Format("{0}% {1:C0}", TicketData.products[i].product_discountpercent, Convert.ToInt32(TicketData.products[i].product_discountvalue)), printFont, Brushes.Black, 100, XPosition + (LineHeightValue * 2)); //DESCUENTO
                        Discount = true;
                    }


                    XPosition += Discount == false ? LineHeightValue * 2 : LineHeightValue * 3;
                    XPosition += 5;
                }

                //PRINT TICKET VALUE INFO
                XPosition += LineHeightValue * 2; //SET POSITION

                Rectangle TicketValuesRectangle = new Rectangle(0, XPosition, PagwWith, LineHeightValue);

                using (StringFormat sf = new StringFormat())
                {
                    sf.Alignment = StringAlignment.Far;

                    if (TicketData.ticket_h == "0" && TicketData.ticket_coti == "0")
                    {
                        g.DrawString("SUBTOTAL:", printFont, Brushes.Black, TicketValuesRectangle); //SUBTOTAL VALUE
                        g.DrawString(string.Format("{0:C0}", Convert.ToInt32(TicketData.ticket_subtotal)), printFont, Brushes.Black, TicketValuesRectangle, sf);

                        TicketValuesRectangle.Y += LineHeightValue;

                        g.DrawString($"IVA ({DataConfig.ivaValue}%):", printFont, Brushes.Black, TicketValuesRectangle); //IVA VALUE
                        g.DrawString(string.Format("{0:C0}", Convert.ToInt32(TicketData.ticket_iva)), printFont, Brushes.Black, TicketValuesRectangle, sf);

                        TicketValuesRectangle.Y += LineHeightValue;

                        g.DrawString($"IVA ({DataConfig.iva5Value}%):", printFont, Brushes.Black, TicketValuesRectangle); //IVA 5% VALUE
                        g.DrawString(string.Format("{0:C0}", Convert.ToInt32(TicketData.ticket_iva5)), printFont, Brushes.Black, TicketValuesRectangle, sf);

                        TicketValuesRectangle.Y += LineHeightValue;

                        g.DrawString($"IMPOCONSUMO ({DataConfig.iacValue}%):", printFont, Brushes.Black, TicketValuesRectangle); //IAC VALUE
                        g.DrawString(string.Format("{0:C0}", Convert.ToInt32(TicketData.ticket_iac)), printFont, Brushes.Black, TicketValuesRectangle, sf);

                        TicketValuesRectangle.Y += LineHeightValue;
                    }

                    g.DrawString("TOTAL:", printFontBold, Brushes.Black, TicketValuesRectangle); //IAC VALUE
                    g.DrawString(string.Format("{0:C0}", Convert.ToInt32(TicketData.ticket_total)), printFont, Brushes.Black, TicketValuesRectangle, sf);
                }

                XPosition += TicketData.ticket_h == "0" ? LineHeightValue * 6 : LineHeightValue * 2; //SET POSITION

                Rectangle TicketMoneyRectangle = new Rectangle(0, XPosition, PagwWith, LineHeightValue);

                if (TicketData.ticket_coti != "1")
                {
                    using (StringFormat sf = new StringFormat())
                    {
                        sf.Alignment = StringAlignment.Far;
                        g.DrawString("RECIBIDO:", printFont, Brushes.Black, TicketMoneyRectangle); //SUBTOTAL VALUE
                        g.DrawString(string.Format("{0:C0}", Convert.ToInt32(TicketData.ticket_totalpayment)), printFont, Brushes.Black, TicketMoneyRectangle, sf);

                        TicketMoneyRectangle.Y += LineHeightValue;

                        g.DrawString($"CAMBIO :", printFont, Brushes.Black, TicketMoneyRectangle); //IVA VALUE
                        g.DrawString(string.Format("{0:C0}", Convert.ToInt32(TicketData.ticket_changepayment)), printFont, Brushes.Black, TicketMoneyRectangle, sf);

                        TicketMoneyRectangle.Y += LineHeightValue;

                        g.DrawString($"SALDO :", printFont, Brushes.Black, TicketMoneyRectangle); //IAC VALUE
                        g.DrawString(string.Format("{0:C0}", Convert.ToInt32(TicketData.ticket_leftpayment)), printFont, Brushes.Black, TicketMoneyRectangle, sf);
                    }
                }


                //PRINT TICKET FOOTER
                XPosition += TicketData.ticket_coti == "1" ? 0 : TicketData.ticket_h == "0" ? LineHeightValue * 6 : LineHeightValue * 2; //SET POSITION

                int FooterLines = DataConfig.PrintFooter.Split('\n').Length;

                if (TicketData.ticket_h == "0" && TicketData.ticket_coti == "0")
                {
                    Rectangle PFooterRectangle = new Rectangle(0, XPosition, PagwWith, LineHeightValue * FooterLines);

                    using (StringFormat sf = new StringFormat())
                    {
                        sf.Alignment = StringAlignment.Center;
                        g.DrawString(DataConfig.PrintFooter, printTinyFont, Brushes.Black, PFooterRectangle, sf);
                    }

                    //PRINT TICKET WATERMARK
                    XPosition += (LineHeightValue * (FooterLines)); //SET POSITION

                    int       WaterMarkLines     = DataConfig.PrintWaterMark.Split('\n').Length;
                    Rectangle WaterMarkRectangle = new Rectangle(0, XPosition, PagwWith, LineHeightValue * WaterMarkLines);
                    using (StringFormat sf = new StringFormat())
                    {
                        sf.Alignment = StringAlignment.Center;
                        g.DrawString(DataConfig.PrintWaterMark, printTinyFont, Brushes.Black, WaterMarkRectangle, sf);
                    }
                }
                else
                {
                    Rectangle WaterMarkRectangle = new Rectangle(0, XPosition + (LineHeightValue * 2), PagwWith, LineHeightValue);

                    using (StringFormat sf = new StringFormat())
                    {
                        sf.Alignment = StringAlignment.Center;
                        g.DrawString("...", printTinyFont, Brushes.Black, WaterMarkRectangle, sf);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }