private bool SlipReady() { IPrinterResponse response = Send(SlipRequest.CheckStatus(Part.SlipPaper)); if (response.Detail == null) { throw new PrinterOfflineException(); } if (response.Detail[6] == '1')//Slip is not detected by TOF sensor { response.Data = "Slip is not detected by TOF sensor"; return(false); } if (response.Detail[5] == '1')//Slip is not detected by BOF sensor { response.Data = "Slip is not detected by BOF sensor"; return(false); } if (response.Detail[3] == '1')//Waits for slip insertion { response.Data = "Waits for slip insertion"; return(false); } return(true); }
private void Initialize() { Send(SlipRequest.Initialize()); Send(SlipRequest.InitSlipPrinter()); Send(SlipRequest.ChangeFont(Printmode.Font7x7)); Send(SlipRequest.SetReverseEject(true)); }
private IPrinterResponse PrintFiscalId() { IPrinterResponse response = null; string fiscalNo = String.Format(" {0} {1}", FiscalPrinter.FiscalRegisterNo.Substring(0, 2), FiscalPrinter.FiscalRegisterNo.Substring(2)); response = Send(SlipRequest.WriteLine(" ")); System.Threading.Thread.Sleep(100); response = Send(SlipRequest.WriteLine(fiscalNo)); System.Threading.Thread.Sleep(100); return(response); }
private IPrinterResponse PrintFiscalId() { IPrinterResponse response = null; string fiscalNo = String.Format("{0}{1} {2}", " ".PadRight((InvoicePage.MaxCharsInLine - FiscalPrinter.FiscalRegisterNo.Length) / 2, ' '), FiscalPrinter.FiscalRegisterNo.Substring(0, 2), FiscalPrinter.FiscalRegisterNo.Substring(2)); response = Send(SlipRequest.WriteLine(" ")); System.Threading.Thread.Sleep(100); response = Send(SlipRequest.WriteLine(fiscalNo)); System.Threading.Thread.Sleep(100); return(response); }
internal static IPrinterRequest WriteLine(String line) { char[] chars = new char[2]; chars[0] = '²'; chars[1] = '³'; if (line.IndexOfAny(chars) > -1) { line = line.Replace(chars[0] + "", strPrintmode + (char)Printmode.DoubleHeight); line = line.Replace(chars[1] + "", strPrintmode + (char)Printmode.Font7x7); } line = FixTurkish(line); IPrinterRequest tempReqst = new SlipRequest(line + strLineFeed); checkEJ = true; return(tempReqst); }
private IPrinterResponse Print(Decimal amount, String label) { List <String> paymentItems = SlipPrinter.Invoicepage.FormatPayment(amount, label); IPrinterResponse response = null; foreach (String row in paymentItems) { response = Send(SlipRequest.WriteLine(row)); } //ReceiptPrinter prn = receiptPrinter as ReceiptPrinter; //prn.ShowPayment(amount); return(response); }
internal bool CheckConnection() { if (sp == null) { return(true); } //asking slip is not for slip request, //it is only for to reach printer IPrinterResponse response = Send(SlipRequest.CheckStatus(Part.SlipPaper)); if (response.Detail == null) { return(false); } return(true); }
private IPrinterResponse PrintSubTotal(ISalesDocument document, bool hardcopy) { IPrinterResponse response = null; FiscalPrinter.Document = document; List <String> subtotalItems = Invoicepage.FormatSubTotal(document); if (hardcopy) { foreach (String s in subtotalItems) { response = Send(SlipRequest.WriteLine(s)); } } return(response); }
private IPrinterResponse Print(IAdjustment[] ai) { if ((ai == null || ai.Length == 0)) { return(new SlipResponse()); } List <String> adjustmentItems = SlipPrinter.Invoicepage.Format(ai); IPrinterResponse response = null; foreach (String row in adjustmentItems) { response = Send(SlipRequest.WriteLine(row)); } foreach (IAdjustment adj in ai) { SlipPrinter.Invoicepage.SubTotal += adj.NetAmount; } return(response); }
private IPrinterResponse PrintTotals(ISalesDocument document, bool hardcopy) { SlipPrinter.Document = document; if (totalLines == null) { totalLines = SlipPrinter.Invoicepage.FormatTotals(document); line_index_of_totals_to_print = 0; } IPrinterResponse response = null; int start = line_index_of_totals_to_print; for (int i = start; i < totalLines.Count; i++) { response = Send(SlipRequest.WriteLine(totalLines[i])); line_index_of_totals_to_print++; } return(response); }
private IPrinterResponse WriteLine(string line) { IPrinterResponse responseOffline = Send(SlipRequest.CheckStatus(Part.Offline)); if (sp == null) { return(responseOffline); } if (responseOffline.Data == null && responseOffline.Detail == null) { throw new PowerFailureException(); } if (!SlipReady()) { DocumentRequested(new RequestSlipException(), new EventArgs()); WaitForSlip(); } return(Send(SlipRequest.WriteLine(line))); }
private new IPrinterResponse Print(IFiscalItem fi) { if (SlipPrinter.Document.Id == 0) { SlipPrinter.Document.Id = FiscalPrinter.Printer.CurrentDocumentId; throw new DocumentIdNotSetException(); } List <String> fiscalItems = SlipPrinter.Invoicepage.Format(fi); IPrinterResponse response = null; foreach (String row in fiscalItems) { if (!SlipReady()) { DocumentRequested(new RequestSlipException(), new EventArgs()); WaitForSlip(); } response = Send(SlipRequest.WriteLine(row)); } SlipPrinter.Invoicepage.SubTotal += fi.TotalAmount; // adjustment on item Adjustment adj = new Adjustment(); decimal totalAdjAmount = 0; foreach (string adjOnItem in fi.GetAdjustments()) { string[] values = adjOnItem.Split('|'); totalAdjAmount += decimal.Parse(values[0]); } if (totalAdjAmount != 0) { adj = ParseAdjLine(fi.GetAdjustments()[0]); Print(adj); } return(response); }
private IPrinterResponse Print(Adjustment ai) { List <String> adjustmentItems = SlipPrinter.Invoicepage.Format(ai); IPrinterResponse response = null; foreach (String row in adjustmentItems) { response = Send(SlipRequest.WriteLine(row)); } SlipPrinter.Invoicepage.SubTotal += ai.Amount; //ReceiptPrinter prn = receiptPrinter as ReceiptPrinter; //if (ai.NetAmount < 0) //{ // prn.ShowDiscount(Math.Abs(ai.NetAmount)); //} //else //{ // prn.ShowFee(Math.Abs(ai.NetAmount)); //} return(response); }
private IPrinterResponse Send(IPrinterRequest irequest) { //if (irequest is FPURequest) return base.Send((FPURequest)irequest); SlipResponse response = new SlipResponse(); if (sp == null) { response.Detail = "serial port has not been initialized yet"; return(response); } SlipRequest request = (SlipRequest)irequest; byte[] b = StringToByteArray(request.ToString()); sp.Write(b, 0, b.Length); if (request.StatusCheck) { System.Threading.Thread.Sleep(100); } else { TimeSpan ts = DateTime.Now.Subtract(lastWRTime); if (ts.TotalMilliseconds < SLIP_DELAY) { System.Threading.Thread.Sleep(SLIP_DELAY - (int)ts.TotalMilliseconds); } } lastWRTime = DateTime.Now; if (sp.BytesToRead > 0) { response = new SlipResponse(sp.ReadByte().ToString()); } return(response); }
internal void RequestSlip() { List <String> postedPage = new List <string>(); //Format sub totals, page number if (line_index_of_totals_to_print == 0) { postedPage = SlipPrinter.Invoicepage.FormatPageDeposit(SlipPrinter.Invoicepage.SubTotal); } postedPage.AddRange(SlipPrinter.Invoicepage.FormatPageNo(line_index_of_totals_to_print == 0)); IPrinterResponse response = null; foreach (String row in postedPage) { response = Send(SlipRequest.WriteLine(row)); System.Threading.Thread.Sleep(100); } try { response = PrintFiscalId(); System.Threading.Thread.Sleep(500); ReleaseSheet(); System.Threading.Thread.Sleep(1000); while (SlipReady()) { } } catch { } DocumentRequested(new RequestSlipException(), new EventArgs()); WaitForSlip(); PrintHeader(FiscalPrinter.Document, false); System.Threading.Thread.Sleep(5000); }
private IPrinterResponse Print(IFiscalItem fi) { if (SlipPrinter.Document.Id == 0) { SlipPrinter.Document.Id = FiscalPrinter.Printer.CurrentDocumentId; throw new DocumentIdNotSetException(); } List <String> fiscalItems = SlipPrinter.Invoicepage.Format(fi); IPrinterResponse response = null; foreach (String row in fiscalItems) { if (!SlipReady()) { DocumentRequested(new RequestSlipException(), new EventArgs()); WaitForSlip(); } response = Send(SlipRequest.WriteLine(row)); } SlipPrinter.Invoicepage.SubTotal += fi.TotalAmount; return(response); }
private IPrinterResponse PrintHeader(ISalesDocument document, bool startSlipInfo) { IPrinterResponse response = null; //if document is not slip document, change printer if (document.DocumentTypeId < 0) { AdjustPrinter(document); return(Printer.PrintHeader(document)); } try { if (Invoicepage.Id == 0) { SlipPrinter.Document.Id = FiscalPrinter.Printer.CurrentDocumentId; Invoicepage.SubTotal = 0; totalLines = null; line_index_of_totals_to_print = 0; } } catch (NullReferenceException ex) { if (Invoicepage != null) { Invoicepage = new InvoicePage(); return(PrintHeader(document, false)); } throw ex; } if (startSlipInfo) { try { //Send data to start document as the following format response = StartSlipInfoReceipt(document); //get document id from response data if (!response.HasError) { document.Id = 0; } } catch (CmdSequenceException cse) { //if command sequence exception occurs switch ((Command)cse.LastCommand) { //if last command is 37, initialize invoice page case Command.START_SLİP: if (SlipPrinter.Invoicepage.SubTotal == 0 && Invoicepage.Id == 0) { SlipPrinter.Invoicepage.ClearInvoice(); //after page request } break; case Command.X_DAILY: //if x report has not been ended yet PrintXReport(true); //print x report return(PrintHeader(document, false)); //then start to print document case Command.START_RCPT: //if custom report has not been ended yet //case Command.CustomReportLine: // RecoverCustomReport();//print do required processes // return PrintHeader(document);//then start to print document default: throw cse; } } catch (NoReceiptRollException nrre) { throw nrre; } catch (Exception ex) { //store the data (write to a log file) FiscalPrinter.Log.Error(ex.Message); } finally { //if some error occured during the receive document id, get current document id if (document.Id == 0) { while (true) { try { document.Id = FiscalPrinter.Printer.CurrentDocumentId; break; } catch { System.Threading.Thread.Sleep(100); } } } } } FiscalPrinter.Document = document; List <String> rowList = Invoicepage.FormatHeader(document); if (!SlipReady()) { DocumentRequested(new RequestSlipException(), new EventArgs()); WaitForSlip(); } for (int lineCount = 0; lineCount < rowList.Count; lineCount++) { response = Send(SlipRequest.WriteLine(rowList[lineCount])); } return(response); }
private IPrinterResponse WriteLine(string line) { return(Send(SlipRequest.WriteLine(line))); }
public IPrinterResponse Suspend() { Send(SlipRequest.WriteLine(" BEKLETMEYE ALINAN")); return(Void()); }
private void ReleaseSheet() { Send(SlipRequest.SetReverseEject(true)); Send(SlipRequest.EjectSheet()); Send(SlipRequest.Release()); }
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()); }
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); }