Пример #1
0
        public IPrinterResponse PrintFooter(ISalesDocument document)
        {
            FiscalPrinter.Document = document;

            //PRINT HEADER
            try
            {
                this.PrintHeader(document, true);
                WaitForSlip();
            }
            catch (PrinterException pe)
            {
                if (OnMessage != null)
                {
                    OnMessage(this, new OnMessageEventArgs(pe));
                }
                ;
            }

            //PRINT FISCAL ITEMS
            foreach (IFiscalItem fi in document.Items)
            {
                this.Print(fi);
            }
            WaitForSlip();

            String[]   docAdjustments = document.GetAdjustments();
            Adjustment adj            = null;

            if (docAdjustments.Length > 0)
            {
                adj = ParseAdjLine(docAdjustments[0]);

                if (adj.Type == AdjustmentType.Fee)
                {
                    document.TotalAmount -= adj.Amount;
                }
                else
                {
                    document.TotalAmount += adj.Amount;
                }
            }

            // PRINT SUBTOTAL
            WriteLine("");
            PrintSubTotal(document, true);
            WaitForSlip();
            if (adj != null)
            {
                Print(adj);

                if (adj.Type == AdjustmentType.Fee)
                {
                    document.TotalAmount += adj.Amount;
                }
                else
                {
                    document.TotalAmount -= adj.Amount;
                }
            }

            // PRINT TOTAL
            PrintTotals(document, true);
            WaitForSlip();

            // PRINT PAYMENT
            PrintPayments();
            WaitForSlip();

            // PRINT FOOTER
            List <String> footerItems = SlipPrinter.Invoicepage.FormatFooter(document);

            SlipPrinter.Invoicepage.ClearInvoice();
            IPrinterResponse response = null;

            foreach (String s in footerItems)
            {
                response = Send(SlipRequest.WriteLine(s));
            }
            WaitForSlip();
            response = PrintFiscalId();
            try
            {
                ReleaseSheet();
            }
            catch (PrinterOfflineException)
            {
                FiscalPrinter.Log.Error("Fatura kagidini printerdan zamaninda aliniz!");
            }
            finally
            {             //sp.ReadTimeout = FPU_TIMEOUT;
            }

            while (true)
            {
                if (!SlipReady())
                {
                    break;
                }
                System.Threading.Thread.Sleep(100);
            }

            if (FiscalPrinter.CanOpenDrawer(document))
            {
                OpenDrawer();
            }

            // SLIP INFO RECEIPT
            try
            {
                response = PrintSlipInfoReceipt(document);
                response = EndSlipInfoReceipt();
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(new SlipResponse());
        }
Пример #2
0
        public IPrinterResponse PrintFooter(ISalesDocument document, bool isReceipt)
        {
            FiscalPrinter.Document = document;
            decimal tempBalance = 0;

            //if document is not slip document, change printer
            if (document.DocumentTypeId < 0)
            {
                AdjustPrinter(document);
                return(Printer.PrintFooter(document, true));
            }

            // SET READY TO PRINT
            //Send(SlipRequest.InitSlipPrinter());

            //PRINT HEADER
            try
            {
                this.PrintHeader(document, document.PrintSlipInfo);
                WaitForSlip();
            }
            catch (PrinterOfflineException poe)
            {
                invoicePage.ClearInvoice();
                throw poe;
            }
            catch (PrinterException pe)
            {
                if (OnMessage != null)
                {
                    OnMessage(this, new OnMessageEventArgs(pe));
                }
            }

            //PRINT FISCAL ITEMS
            foreach (IFiscalItem fi in document.Items)
            {
                // Dont print voided items
                if (fi.Quantity > fi.VoidQuantity)
                {
                    this.Print(fi);
                }
            }
            WaitForSlip();

            String[]   docAdjustments = document.GetAdjustments();
            Adjustment adj            = null;

            if (docAdjustments.Length > 0)
            {
                adj                   = ParseAdjLine(docAdjustments[0]);
                tempBalance           = document.BalanceDue;
                document.TotalAmount -= adj.Amount;
                if (tempBalance == 0)
                {
                    document.BalanceDue = 0; // this line has been added to prevent the error( it was waiting on payment again ) while printing same invoice again.
                }
            }

            // PRINT SUBTOTAL
            WriteLine("");
            PrintSubTotal(document, true);
            WaitForSlip();
            if (adj != null)
            {
                Print(adj);
                tempBalance           = document.BalanceDue;
                document.TotalAmount += adj.Amount;

                PrintSubTotal(document, true);
                if (tempBalance == 0)
                {
                    document.BalanceDue = 0; // this line has been added to prevent the error( it was waiting on payment again ) while printing same invoice again.
                }
            }


            // PRINT TOTAL
            PrintTotals(document, true);
            WaitForSlip();

            // PRINT PAYMENT
            PrintPayments();
            WaitForSlip();

            // PRINT FOOTER
            List <String> footerItems = SlipPrinter.Invoicepage.FormatFooter(document);

            IPrinterResponse response = null;

            foreach (String s in footerItems)
            {
                response = Send(SlipRequest.WriteLine(s));
            }
            WaitForSlip();
            response = PrintFiscalId();
            SlipPrinter.Invoicepage.ClearInvoice();
            try
            {
                ReleaseSheet();
            }
            catch (PrinterOfflineException)
            {
                FiscalPrinter.Log.Error("Fatura kagidini printerdan zamaninda aliniz!");
            }
            finally
            { //sp.ReadTimeout = FPU_TIMEOUT;
            }

            while (true)
            {
                if (!SlipReady())
                {
                    break;
                }
                System.Threading.Thread.Sleep(100);
            }

            if (FiscalPrinter.CanOpenDrawer(document))
            {
                OpenDrawer();
            }

            // SLIP INFO RECEIPT
            if (document.PrintSlipInfo)
            {
                try
                {
                    response = PrintSlipInfoReceipt(document);
                    response = EndSlipInfoReceipt();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(null);
        }