public TcpService() { try { String tcpIp = PosConfiguration.Get("TCPIp"); int port = int.Parse(PosConfiguration.Get("TCPPort")); String[] split = tcpIp.Split('.'); if (split.Length != 4) { throw new Exception("IP not accepted"); } byte[] ip = new byte[4]; for (int i = 0; i < split.Length; i++) { ip[i] = Convert.ToByte(split[i].Trim()); } System.Net.IPAddress addr = new System.Net.IPAddress(ip); listener = new TcpListener(addr, port); listener.Start(); //wait for client System.Threading.ThreadStart ts = new System.Threading.ThreadStart(AccepClient); threadClient = new System.Threading.Thread(ts); threadClient.Start(); } catch { } }
public HYDisplay() { try { String portName = PosConfiguration.Get("DisplayComPort"); serialPort = new SerialPort(portName); if (!serialPort.IsOpen) { serialPort.ReadTimeout = 2048; serialPort.Open(); Write(ledsOff, 0, 6); Write(initializeDisplay, 0, 3); serialPort.Write(horizontalScrollMode, 0, horizontalScrollMode.Length); System.Threading.Thread.Sleep(100); serialPort.Write(normalMode, 0, normalMode.Length); } } catch (UnauthorizedAccessException ex) { throw ex; } catch { Display.Log.Fatal("HYDisplay:HyDisplay - Exception {0} is {1}", serialPort.PortName, serialPort.IsOpen ? "Open" : "Closed"); } }
internal static string GetAutoOrderKey() { string pwd = PosConfiguration.Get("FiscalId") + "HUGIN YAZILIM TEKNOLOJILERI"; string hashkey = PosConfiguration.Get("FiscalId").Substring(2); return(Encrypt(hashkey, pwd)); }
internal SQLPointAdapter(String connString) { try { sqlConnection = new SqlConnection(connString); string timeout = PosConfiguration.Get("PromotionClientTimeout"); if (timeout == null || !Parser.TryInt(timeout.Trim(), out connectionTimeout)) { connectionTimeout = 2000; } //Test connection GetSqlDbValue("SELECT Count(CustomerCode) FROM TblDaily"); } catch (Exception ex) { if (HasOfflineRecords) { StartDBController(); } } finally { if (sqlConnection.State == ConnectionState.Open) { sqlConnection.Close(); } } }
public ExternalDisplay() { String portName = PosConfiguration.Get("DisplayComPort"); serialPort = new SerialPort(portName); if (!serialPort.IsOpen) { serialPort.ReadTimeout = 2048; try { serialPort.Open(); } catch (System.IO.IOException ex) { if (!serialPort.IsOpen) { throw ex; } } //Write(initializeDisplay, 0, 3); //serialPort.Write(horizontalScrollMode, 0, horizontalScrollMode.Length); //System.Threading.Thread.Sleep(100); //serialPort.Write(normalMode, 0, normalMode.Length); } }
protected override void PreProcess() { try { lastKeyPressed = DateTime.Now; KeyMap.Load(); Debugger.Instance().AppendLine("Started Display: " + DateTime.Now.ToLongTimeString()); DisplayAdapter.Instance(); DisplayAdapter.Both.Show(PosMessage.PLEASE_WAIT); Application.DoEvents(); Debugger.Instance().AppendLine("Finished Display" + DateTime.Now.ToLongTimeString()); if (PosConfiguration.Get("BarcodeComPort") != "") { ConnectBarcode(); } //Console.CancelKeyPress += new ConsoleCancelEventHandler(pos_OnClosed); CashRegister.Instance(); CashRegister.Printer.DateTimeChanged += new EventHandler(Printer_DateTimeChanged); Debugger.Instance().AppendLine("Started BackgroundWorker: " + DateTime.Now.ToLongTimeString()); Thread thread = new Thread(new ThreadStart(BackgroundWorker.Start)); thread.Name = "BackgroundWorker"; thread.IsBackground = true; thread.Priority = ThreadPriority.BelowNormal; thread.Start(); } catch (UnauthorizedAccessException ex) { throw ex; } }
protected override Boolean BlockRemoved() { try { attemptCount++; cr.Printer.CheckPrinterStatus(); return(true); } catch (ServiceRequiredException sre) { Login.LogoutManager(); //cr.State = ServiceMenu.Instance(); States.AlertCashier.Instance(new Confirm(sre.Message)); return(true); } catch (Exception ex) { if (ex.Message == PosMessage.PRINTER_CONNETTION_ERROR || ex is System.Net.Sockets.SocketException || (attemptCount == 1 && ex is TimeoutException)) { DisplayAdapter.Cashier.Show(PosMessage.PLEASE_WAIT); cr.SetPrinterPort(PosConfiguration.Get("PrinterComPort")); Login.LogoutManager(); cr.State = States.Start.Instance(); attemptCount = 0; return(true); } return(false); } }
private static IState ExitService(String password) { try { cr.Printer.ExitServiceMode(password); cr.SetPrinterPort(PosConfiguration.Get("PrinterComPort")); CashRegister.LoadCurrentSettings(); cr.State = States.Start.Instance(); } catch (CashierAutorizeException cae) { cr.State = AlertCashier.Instance(new Error(cae, new StateInstance(Continue), new StateInstance(Continue))); cr.Log.Error("CashierAutorizeException occured. {0}", cae.Message); } catch (CmdSequenceException ex) { cr.State = AlertCashier.Instance(new Error(ex, new StateInstance(Continue), new StateInstance(Continue))); cr.Log.Error("CmdSequenceException occured. {0}", ex.Message); } catch (SVCPasswordOrPointException ex) { cr.State = ConfirmCashier.Instance(new Error(ex, new StateInstance(Continue), new StateInstance(Continue))); cr.Log.Error("SVCPasswordOrPointException occured. {0}", ex); } return(cr.State); }
private Display(Target mode) { this.mode = mode; // Screens screens = Screen.AllScreens; primaryScreenId = 0; secondaryScreenId = 1; if (screens.Length > 1 && PosConfiguration.ScreenIdentity == 2) { primaryScreenId = 1; secondaryScreenId = 0; } // Font pfc = new PrivateFontCollection(); pfc.AddFontFile(@"Resources/MATRS.TTF"); // Primary Screen touchForm = new CashierForm(); System.Drawing.Rectangle boundsP = screens[primaryScreenId].Bounds; touchForm.SetBounds(boundsP.X, boundsP.Y, boundsP.Width, boundsP.Height); touchForm.StartPosition = FormStartPosition.Manual; touchForm.Show(); touchForm.Focus(); touchForm.ConsumeKey += new ConsumeKeyHandler(touchForm_ConsumeKey); touchForm.DisplayClosed += new EventHandler(touchForm_DisplayClosed); touchForm.SaleSelected += new SalesSelectedHandler(touchForm_SaleSelected); touchForm.SalesFocusLost += new EventHandler(touchForm_SalesFocusLost); // Secondary Screen if (screens.Length > 1) { try { customerForm = new CustomerForm(); System.Drawing.Rectangle bounds = screens[secondaryScreenId].Bounds; customerForm.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height); customerForm.StartPosition = FormStartPosition.Manual; customerForm.Show(); } catch { } } // External Display if (PosConfiguration.Get("DisplayComPort") != "") { try { external = new ExternalDisplay(); } catch { } } }
public SerialDisplay() { try { String portName = PosConfiguration.Get("DisplayComPort"); serialPort = new SerialPort(portName); serialPort.Handshake = Handshake.RequestToSend; stack = new List <string>(); if (!serialPort.IsOpen) { serialPort.Open(); //try //{ // serialPort.Open(); //} //catch (IOException ioe) //{ // // To circumvent WindowsCE 6.0 bug // if (ioe.StackTrace.IndexOf("SerialStream.SetBufferSizes") == -1) // throw ioe; //} TrySerial(); serialPort.Encoding = PosConfiguration.DefaultEncoding; //serialPort.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived); } System.Threading.Thread serialThread = new System.Threading.Thread(delegate() { KeyUp(); }); serialThread.IsBackground = true; serialThread.Start(); } catch (NotSerialException nse) { if (serialPort.IsOpen) { serialPort.Close(); } throw nse; } catch (UnauthorizedAccessException ex) { throw ex; } catch (System.IO.IOException) { throw new Exception("DÝSPLAY PORTU ARIZALI"); } catch (Exception) { if (Display.Log == null) { return; } Display.Log.Fatal("HYDisplay:HyDisplay - Exception {0} is {1}", serialPort.PortName, serialPort.IsOpen ? "Open" : "Closed"); //if (cr.Printer == null) return; //cr.Printer.PrintRemark(PosMessage.CAN_NOT_ACCESS_TO_DISPLAYS); //CashRegister.Void(); } }
public PromotionClient() { string timeout = PosConfiguration.Get("PromotionClientTimeout"); if (timeout == null || !Parser.TryInt(timeout.Trim(), out connectionTimeout)) { connectionTimeout = 2000; } PromotionServer.Settings.Load(); }
private FiscalPrinter() { RegisterId = PosConfiguration.Get("RegisterId"); guiDocument = new GuiPrinterForm(); Formatter.SetCoordinates(); toResponse = new PrinterResponse(); lastz = LastZReportNo; lastZReportDate = LastZReportDate; currentDocumentId = CurrentDocumentId; }
protected override bool BlockRemoved() { Exception exPrinter = null; try { cr.Printer.CheckPrinterStatus(); if (cr.Printer.GetLastDocumentInfo(false).Type == ReceiptTypes.VOID) { cr.Document.Void(); } else { cr.Document.CloseWithoutPrint(); } return(true); } catch (IncompletePaymentException ipe) { throw ipe; } catch (Exception ex) { exPrinter = ex; } if (exPrinter != null) { try { if (exPrinter.Message == PosMessage.PRINTER_CONNETTION_ERROR || exPrinter is System.Net.Sockets.SocketException) { DisplayAdapter.Cashier.Show(PosMessage.PLEASE_WAIT); cr.SetPrinterPort(PosConfiguration.Get("PrinterComPort")); // After established new connection, re-login manager Login.LogoutManager(); // Check if ECR voided or completed last document, if document is not closed on CEPOS already cr.CheckDocumentAfterReConnected(); //cr.State = States.Start.Instance(); return(true); } } catch { } } return(false); }
private static IState ShutdownPOS(string pass) { if (PosConfiguration.Get("ServicePassword") == pass) { DisplayAdapter.Cashier.Show(PosMessage.PROGRAM_CLOSING); System.Threading.Thread.Sleep(2500); Chassis.CloseApplication(); return(cr.State); } else { return(cr.State = AlertCashier.Instance(new Confirm(PosMessage.INVALID_PASS_ENTRY, Instance, Instance))); } }
public static void Start() { System.Threading.Thread.Sleep(200); DocumentFileHelper[] orders = null; int sleepTime = 500; if (!Parser.TryInt(PosConfiguration.Get("SleepTime"), out sleepTime)) { sleepTime = 500; } while (true) { if (Chassis.Engine.Terminate) { break; } try { orders = DocumentFileHelper.GetOpenOrders(); } catch (Exception ex) { Debugger.Instance().AppendLine("Order Error: " + ex.Message); } if (orders != null && orders.Length > 0) { try { AutoLoadOrders(orders); } catch (Exception ex) { Debugger.Instance().AppendLine("Order Error: " + ex.Message); } } else { DisplayAdapter.Instance().LedOff(Leds.Order); } Thread.Sleep(sleepTime); while (cr.State == null) { Thread.Sleep(200); //I wish this had a comment } } }
//private static readonly String alertTimeoutStr = PosConfiguration.Get("CashierAlertTimeout"); #region Instance public static void SetTimeouts() { if (alertTimeout == -1) { try { String alertTimeoutStr = PosConfiguration.Get("CashierAlertTimeout"); alertTimeout = (int)(decimal.Parse(alertTimeoutStr) * 1000m); } catch { alertTimeout = 1000; } } }
public HuginDisplay() { try { String portName = PosConfiguration.Get("DisplayComPort").Substring(1); serialPort = new SerialPort(portName, 19200); stack = new List <string>(); if (!serialPort.IsOpen) { serialPort.Open(); TrySerial(); serialPort.Encoding = PosConfiguration.DefaultEncoding; Clear(); } System.Threading.Thread serialThread = new System.Threading.Thread(delegate() { KeyUp(); }); serialThread.IsBackground = true; serialThread.Start(); } catch (NotSerialException nse) { if (serialPort.IsOpen) { serialPort.Close(); } throw nse; } catch (UnauthorizedAccessException ex) { throw ex; } catch (System.IO.IOException ex) { throw new Exception("DÝSPLAY PORTU ARIZALI"); } catch (Exception ex) { if (Display.Log == null) { return; } Display.Log.Fatal("HYDisplay:HyDisplay - Exception {0} is {1}", serialPort.PortName, serialPort.IsOpen ? "Open" : "Closed"); //if (cr.Printer == null) return; //cr.Printer.PrintRemark(PosMessage.CAN_NOT_ACCESS_TO_DISPLAYS); //CashRegister.Void(); } }
public static IDisplay Instance() { if (display == null) { String vga = PosConfiguration.Get("VGA"); if (vga == "Customer") { display = new Display(new GuiDisplay(), new GraphicalDisplay(), Target.Both); } else { display = display = new GuiDisplay(); } } return(display); }
public void Reset() { try { if (IsPaused) { return; } serialPort.Close(); serialPort.PortName = PosConfiguration.Get("DisplayComPort"); serialPort.Open(); serialPort.Write(initializeDisplay, 0, 3); } catch (Exception) { Display.Log.Fatal("HyDisplay.Reset Exception occurred. {0} is {1}", serialPort.PortName, serialPort.IsOpen ? "Open" : "Closed"); //TODO: printerdan Hata mesaji ver? } }
public void Reset() { try { if (IsPaused) { return; } serialPort.Close(); serialPort.PortName = PosConfiguration.Get("DisplayComPort").Substring(1); serialPort.Open(); messageDisplaying = "".PadLeft(20, placer); } catch (Exception) { Display.Log.Fatal("HuginDisplay.Reset Exception occurred. {0} is {1}", serialPort.PortName, serialPort.IsOpen ? "Open" : "Closed"); //TODO: printerdan Hata mesaji ver? } }
public void LoadTemplate() { //not to break initialization, try-catch blocks added to LoadLabel(), LoadCell() and twice in LoadTemplate() //LoadCell(XPath.SALE_COLUMNCELL, dgSales.ColumnHeadersDefaultCellStyle); //LoadCell(XPath.SALE_ROWCELL, dgSales.RowsDefaultCellStyle); LoadLabel(XPath.CURRENT_CUST1, lblFirstMessage); LoadLabel(XPath.CURRENT_CUST2, lblSecondMessage); try { if (PosConfiguration.Get("AdvertisementPath") != "") { string adsPath = PosConfiguration.Get("AdvertisementPath"); string[] ads = adsPath.Split(','); string path = ads[0]; adsTimeout = long.Parse(ads[1]); EnableAdvertisementPanel(path); } } catch { } }
public void Connect() { string[] scaleParams = PosConfiguration.Get("ScaleComPort").Split(','); string portName = scaleParams[0]; if (scaleParams.Length > 1) { request = scaleParams[1]; } serialPort = new SerialPort(portName); serialPort.ReadTimeout = 1500; serialPort.WriteTimeout = 1500; if (serialPort.IsOpen) { serialPort.Close(); } serialPort.Open(); }
internal static void ConnectBarcode() { try { String newLine = PosConfiguration.BarcodeTerminator; if (newLine == "") { newLine = "\r\n"; } String barcodeComPortName = PosConfiguration.Get("BarcodeComPort"); barcodeComPort = new SerialPort(barcodeComPortName); barcodeComPort.NewLine = newLine; barcodeComPort.ReadTimeout = 3000; if (!barcodeComPort.IsOpen) { barcodeComPort.Open(); } barcodeComPort.DataReceived += new SerialDataReceivedEventHandler(serial_DataReceived); } catch { } //log not ready }
public static IDisplay Instance() { if (display == null) { try { if (String.IsNullOrEmpty(PosConfiguration.Get("DisplayComPort"))) { display = GUI.Display.Instance(); return(display); } IDisplay d; d = new SerialDisplay(); String vga = PosConfiguration.Get("VGA"); if (vga == "Customer") { display = new Display(d, GUI.Display.Instance(Target.Customer), Target.Both); } else if (vga == "Cashier") { display = new Display(d, GUI.Display.Instance(Target.Cashier), Target.Both); } else { display = new SerialDisplay(); } } catch (NotSerialException) { display = new HYDisplay(); } } return(display); }
public void LoadTemplate() { //not to break initialization, try-catch blocks added to LoadLabel(), LoadCell() and twice in LoadTemplate() LoadLabel(XPath.HEAD_FIRM, lblLogo); LoadCell(XPath.SALE_COLUMNCELL, dgSales.ColumnHeadersDefaultCellStyle); LoadCell(XPath.SALE_ROWCELL, dgSales.RowsDefaultCellStyle); LoadLabel(XPath.CURRENT_CUST1, lblFirstMessage); LoadLabel(XPath.CURRENT_CUST2, lblSecondMessage); LoadLabel(XPath.CUST_INFO, lblCustomer); LoadLabel(XPath.ADJ_TITLE, lblAdjustment); LoadLabel(XPath.ADJ_PRODUCT_TITLE, lblProductAdjustment); LoadLabel(XPath.ADJ_PRODUCT_VAL, lblProductAdjustAmount); LoadLabel(XPath.ADJ_SUB_TITLE, lblSubtotalAdjustment); LoadLabel(XPath.ADJ_SUB_VAL, lblSubtotalAdjustAmount); LoadLabel(XPath.ADJ_TOTAL_TITLE, lblTotalAdjustment); LoadLabel(XPath.ADJ_TOTAL_VAL, lblTotalAdjustAmount); LoadLabel(XPath.DOC_ID_TITLE, lblDocument); LoadLabel(XPath.DOC_ID_VAL, lblDocumentId); LoadLabel(XPath.DOC_DATE_TITLE, lblDate); LoadLabel(XPath.DOC_DATE_VAL, lblDocumentDate); LoadLabel(XPath.DOC_TIME_TITLE, lblTime); LoadLabel(XPath.DOC_TIME_VAL, lblDocumentTime); LoadLabel(XPath.DOC_SUBTOTAL_TITLE, lblSubTotal); LoadLabel(XPath.DOC_SUBTOTAL_VAL, lblSubtotalValue); try { if (PosConfiguration.Get("AdvertisementPath") != "") { string adsPath = PosConfiguration.Get("AdvertisementPath"); string[] ads = adsPath.Split(','); string path = ads[0]; adsTimeout = long.Parse(ads[1]); EnableAdvertisementPanel(path); } } catch { } }
protected override Boolean BlockRemoved() { try { DisplayAdapter.Cashier.Show(PosMessage.CONNECTING_TO_PRINTER); String port = PosConfiguration.Get("PrinterComPort"); cr.SetPrinterPort(port); if (cr.State is PrinterConnectionError) { return(false); } cr.Log.Success("Connected to printer. {0}", port); cr.CheckDocumentAfterReConnected(); return(true); } catch (BlockingException) { cr.State = PrinterBlockingError.Instance(); return(false); } catch (PowerFailureException) { cr.Void(); } catch (EJException ej) { cr.State = ElectronicJournalError.Instance(ej); } catch (Exception e) { errorMessage = new Error(e).Message; DisplayAdapter.Cashier.Show(errorMessage); cr.Log.Error("Error in PrinterConnectionError: {0}", errorMessage); } return(false); }
internal Logger(LogType type) { this.logType = type; switch (type) { case LogType.Main: this.mainLogPath = PosConfiguration.ArchivePath + MainLogName; this.dailyLogPrefix = MainLogPrefix; break; case LogType.Void: this.mainLogPath = PosConfiguration.ArchivePath + VoidedLogName; this.dailyLogPrefix = VoidedLogPrefix; break; case LogType.Return: this.mainLogPath = PosConfiguration.ArchivePath + ReturnsLogName; this.dailyLogPrefix = ReturnsLogPrefix; break; case LogType.LastDocument: this.mainLogPath = PosConfiguration.ArchivePath + DocumentLogName; break; } sequenceNumber = GetSequenceNumber(mainLogPath + suffix) + 1; if (PosConfiguration.Get("Logger") == "1" && type != LogType.LastDocument) { logFormatter = new InterLoger(); } else { logFormatter = new HuginLogger(); } defaultFormatter = new HuginLogger(); }
public override void Process(PosKey key) { if (isProcessing) { return; //occurs if pressed key when seral data is executing. } lock (serialLock) { lastKeyPressed = DateTime.Now; isProcessing = true; #region parse user input try { switch (key) { case PosKey.D0: case PosKey.D1: case PosKey.D2: case PosKey.D3: case PosKey.D4: case PosKey.D5: case PosKey.D6: case PosKey.D7: case PosKey.D8: case PosKey.D9: cr.State.Numeric((char)key); break; case PosKey.DoubleZero: cr.State.Numeric((char)PosKey.D0); cr.State.Numeric((char)PosKey.D0); break; case PosKey.Decimal: cr.State.Seperator(); break; case PosKey.Document: cr.State.Document(); break; case PosKey.Customer: cr.State.Customer(); break; case PosKey.Report: cr.State.Report(); break; case PosKey.Program: cr.State.Program(); break; case PosKey.Command: ISalesDocument doc = cr.Document; cr.State.Command(); break; case PosKey.CashDrawer: cr.State.CashDrawer(); break; case PosKey.Void: cr.State.Void(); break; case PosKey.PercentDiscount: cr.State.Adjust(AdjustmentType.PercentDiscount); break; case PosKey.Discount: cr.State.Adjust(AdjustmentType.Discount); break; case PosKey.PercentFee: cr.State.Adjust(AdjustmentType.PercentFee); break; case PosKey.Fee: cr.State.Adjust(AdjustmentType.Fee); break; case PosKey.ReceiveOnAcct: cr.State.ReceiveOnAcct(); break; case PosKey.PayOut: cr.State.PayOut(); break; case PosKey.PriceLookup: cr.State.PriceLookup(); break; case PosKey.Price: cr.State.Price(); break; case PosKey.Total: cr.State.TotalAmount(); break; case PosKey.Repeat: cr.State.Repeat(); break; case PosKey.UpArrow: cr.State.UpArrow(); break; case PosKey.DownArrow: cr.State.DownArrow(); break; case PosKey.Escape: cr.State.Escape(); break; case PosKey.Quantity: cr.State.Quantity(); break; case PosKey.Cash: cr.State.Pay(new CashPaymentInfo()); break; case PosKey.Credit: if (KeyMap.CreditBuffer == -1) { Thread.Sleep(20); //wait some for Console.KeyAvailable if (Console.In.Peek() > -1) { KeyMap.CreditBuffer = Console.In.Read() - 48; } else { cr.State.Alpha('C'); return; } } try { if (KeyMap.CreditBuffer == 0) { cr.State.Pay(new CreditPaymentInfo()); } else { Dictionary <int, ICredit> credits = cr.DataConnector.GetCredits(); if (credits.Count > (KeyMap.CreditBuffer - 1)) //?-1 { cr.State.Pay(new CreditPaymentInfo(credits[KeyMap.CreditBuffer])); } } } finally { KeyMap.CreditBuffer = -1; } break; case PosKey.Payment: cr.State.ShowPaymentList(); break; case PosKey.Check: cr.State.Pay(new CheckPaymentInfo()); break; case PosKey.ForeignCurrency: cr.State.Pay(new CurrencyPaymentInfo()); break; case PosKey.SubTotal: cr.State.SubTotal(); break; case PosKey.Enter: cr.State.Enter(); break; case PosKey.SalesPerson: cr.State.SalesPerson(); break; case PosKey.Correction: cr.State.Correction(); break; case PosKey.LabelStx: if (KeyMap.LabelBuffer == -1) { Thread.Sleep(20); //wait some for Console.KeyAvailable //Console.In.ReadLine() is changed as Console.In.Read() //because Readline command opens the text editor in WindowsCE int label = Console.In.Read(); if (label == -1) { cr.State.Alpha('L'); break; } KeyMap.LabelBuffer = label; } try { cr.State.LabelKey(KeyMap.LabelBuffer); } finally { KeyMap.LabelBuffer = -1; } break; case PosKey.Help: MessageBox.Show(cr.State.GetType().ToString()); break; case PosKey.MagstripeStx: cr.State.CardPrefix(); break; case PosKey.KeyStx: if (KeyMap.KeyLockBuffer == -1) { Thread.Sleep(20); //wait some for Console.KeyAvailable String label = Console.ReadLine(); KeyMap.KeyLockBuffer = int.Parse(label); } try { cr.State.End(KeyMap.KeyLockBuffer - 1); } finally { KeyMap.KeyLockBuffer = -1; } break; case PosKey.BarcodePrefix: cr.State.BarcodePrefix(); break; case PosKey.UndefinedKey: //do nothing break; case PosKey.SendOrder: cr.State.SendOrder(); break; default: switch (key) { case (PosKey)17: cr.State.Alpha('|'); break; case PosKey.MagstripeStx: cr.State.Alpha('\"'); break; case (PosKey)214: cr.State.Alpha('ж'); break; case (PosKey)286: cr.State.Alpha('а'); break; case (PosKey)199: cr.State.Alpha('Ч'); break; case (PosKey)220: cr.State.Alpha('м'); break; case (PosKey)304: cr.State.Alpha('н'); break; case (PosKey)350: cr.State.Alpha('о'); break; case (PosKey)221: break; case (PosKey)46: cr.State.Alpha('.'); break; case (PosKey)47: cr.State.Alpha('/'); break; default: if (char.IsLetter((char)key) || key == (PosKey)ConsoleKey.Spacebar || char.IsPunctuation((char)key)) { cr.State.Alpha((char)key); } else { cr.State.UndefinedKey(); } break; } break; } } #endregion #region handle errors catch (CmdSequenceException csex) { SoundManager.Sound(SoundType.FAILED); cr.State = States.AlertCashier.Instance(new Error(csex)); cr.Log.Error("CmdSequenceException occured. Last command: {0}", csex.LastCommand); cr.Log.Error(csex); //to do : cr.State = ex.Recover(); } catch (PowerFailureException pfex) { SoundManager.Sound(SoundType.FATAL_ERROR); try { Recover.RecoverPowerFailure(pfex); } catch (EJException eje) { cr.State = States.ElectronicJournalError.Instance(eje); } cr.Log.Warning(pfex); } catch (UnfixedSlipException ex) { try { cr.State = States.BlockOnPaper.Instance(); //Recover.RecoverUnfixedSlip(ex); } catch (EJException) { cr.State = States.ElectronicJournalError.Instance(); } cr.Log.Warning(ex); } catch (EJException eje) { SoundManager.Sound(SoundType.FATAL_ERROR); cr.State = States.ElectronicJournalError.Instance(eje); cr.Log.Warning(eje); } catch (SVCPasswordOrPointException ex) { SoundManager.Sound(SoundType.FAILED); //cr.State = States.ServiceMenu.Instance(); States.AlertCashier.Instance(new Confirm(ex.Message)); cr.Log.Warning(ex); } catch (FiscalIdException fie) { SoundManager.Sound(SoundType.FATAL_ERROR); cr.State = States.FiscalIdBlock.Instance(); cr.Log.Warning(fie); } catch (BlockingException bex) { SoundManager.Sound(SoundType.FATAL_ERROR); cr.State = States.PrinterBlockingError.Instance(new Error(bex)); } catch (NoReceiptRollException nrre) { SoundManager.Sound(SoundType.NEED_PROCESS); cr.State = States.PrinterStatusError.Instance(new Error(nrre)); cr.Log.Error(nrre); } catch (PrinterStatusException pse) { SoundManager.Sound(SoundType.FAILED); cr.State = States.PrinterStatusError.Instance(pse); cr.Log.Error(pse); } catch (MissingCashierException mcex) { SoundManager.Sound(SoundType.FAILED); cr.CurrentCashier = null; cr.State = States.AlertCashier.Instance(new Error(mcex, States.Login.Instance)); cr.Log.Warning(mcex); } catch (AssignedCashierLimitExeedException aclee) { SoundManager.Sound(SoundType.FAILED); cr.CurrentCashier = null; cr.State = States.AlertCashier.Instance(new Error(aclee, States.Login.Instance)); cr.Log.Warning(aclee); } catch (SlipRowCountExceedException srceex) { SoundManager.Sound(SoundType.FAILED); States.AlertCashier.Instance(new Error(srceex)); cr.State = States.ConfirmSlip.Instance(new Error(srceex)); cr.Log.Warning(srceex); } catch (CashierAlreadyAssignedException caaex) { States.AlertCashier.Instance(new Error(caaex)); ICashier assignedCashier = cr.DataConnector.FindCashierById(caaex.CashierId); if (assignedCashier != null) { cr.Log.Debug("Kasiyer zaten atanmis: {1} ({0})", assignedCashier.Id, assignedCashier.Name); } else { cr.Log.Error("Kasiyer girisi yapilmali"); } States.Login.LoginCashier(); } catch (ProductNotWeighableException pnwex) { SoundManager.Sound(SoundType.FAILED); cr.State = States.AlertCashier.Instance(new Error(pnwex)); } catch (DirectoryNotFoundException dnfex) { SoundManager.Sound(SoundType.FAILED); cr.Log.Fatal(dnfex); cr.State = States.AlertCashier.Instance(new Error(dnfex)); } catch (InvalidOperationException ioex) { SoundManager.Sound(SoundType.FAILED); cr.State = States.AlertCashier.Instance(new Error(ioex)); } catch (NegativeResultException nrex) { SoundManager.Sound(SoundType.FAILED); cr.State = States.AlertCashier.Instance(new Error(nrex)); cr.Log.Error(nrex); } catch (IncompleteXReportException ixrex) { SoundManager.Sound(SoundType.FATAL_ERROR); cr.State = States.XReportPE.Instance(ixrex); cr.Log.Warning("Printer exception occured during the x report", ixrex.Message); } catch (IncompleteEJSummaryReportException iejsex) { SoundManager.Sound(SoundType.FATAL_ERROR); cr.State = States.EJSummaryReportPE.Instance(iejsex); cr.Log.Warning("Printer exception occured during the ej summary report", iejsex.Message); } catch (IncompletePaymentException ipe) { SoundManager.Sound(SoundType.NEED_PROCESS); cr.State = States.PaymentAfterPE.Instance(ipe); cr.Log.Warning(ipe.Message); } catch (PrintDocumentException pde) { SoundManager.Sound(SoundType.FAILED); cr.State = States.DocumentPE.Instance(pde); cr.Log.Warning("Printer exception occured during the document printing ", pde.Message); } catch (FMFullException fmfe) { SoundManager.Sound(SoundType.FATAL_ERROR); cr.State = States.PrinterStatusError.Instance(new Error(fmfe)); cr.Log.Fatal(fmfe); } catch (FMLimitWarningException fmlwe) { SoundManager.Sound(SoundType.FATAL_ERROR); cr.State = States.PrinterStatusError.Instance(new Error(fmlwe)); cr.Log.Fatal(fmlwe); } catch (ZRequiredException zre) { SoundManager.Sound(SoundType.NEED_PROCESS); cr.State = States.PrinterStatusError.Instance(new Error(zre)); cr.Log.Error(zre); } catch (CashierAutorizeException cae) { SoundManager.Sound(SoundType.FAILED); cr.State = States.AlertCashier.Instance(new Error(cae)); cr.Log.Error(cae); } catch (FMNewException fmne) { SoundManager.Sound(SoundType.NEED_PROCESS); int fiscalId = int.Parse(PosConfiguration.Get("FiscalId").Substring(2, 8)); cr.State = States.EnterInteger.Instance(PosMessage.START_FM, fiscalId, new StateInstance <int>(States.Login.AcceptFiscalId), new StateInstance(Start.Instance)); cr.Log.Error(fmne); } catch (PrinterTimeoutException pte) { SoundManager.Sound(SoundType.FAILED); cr.State = States.PrinterConnectionError.Instance(pte); cr.Log.Warning(pte); } catch (System.Net.Sockets.SocketException ex) { SoundManager.Sound(SoundType.FAILED); cr.State = States.PrinterConnectionError.Instance(new PrinterException(PosMessage.CANNOT_ACCESS_PRINTER, ex)); cr.Log.Warning(new PrinterException(PosMessage.CANNOT_ACCESS_PRINTER, ex)); } catch (InvalidPaymentException ipe) { SoundManager.Sound(SoundType.FAILED); Confirm con = new Confirm(String.Format("{0}\n{1}", PosMessage.PAYMENT_INVALID, "жDEME нPTAL?(GнRно)"), new StateInstance(VoidPayment.Instance)); cr.State = States.ConfirmCashier.Instance(con); cr.Log.Error(ipe); } catch (OperationCanceledException oce) { SoundManager.Sound(SoundType.FAILED); cr.State = States.PrinterConnectionError.Instance(new PrinterException(PosMessage.CANNOT_ACCESS_PRINTER, oce)); cr.Log.Warning(new PrinterException(PosMessage.CANNOT_ACCESS_PRINTER, oce)); } catch (EftPosException epe) { SoundManager.Sound(SoundType.FAILED); cr.State = AlertCashier.Instance(new Error(epe)); cr.Log.Error(epe); } catch (Exception ex) { SoundManager.Sound(SoundType.FAILED); cr.State = States.AlertCashier.Instance(new Error(ex)); cr.Log.Error(ex); } finally { isProcessing = false; } #endregion } }
internal override StringWriter LogItems(ISalesDocument document, int docStatus, ref int number) { StringWriter logWriter = new StringWriter(); string[] subLines = null; //if (document.Id == 0 || document.IsEmpty) : Not possible, The function which calls LogItems checks that condition. String documentId = document.Id.ToString().PadLeft(6, '0'); if (!String.IsNullOrEmpty(document.SlipSerialNo)) { String seriNo = document.SlipSerialNo; if (seriNo.Length > 2) { seriNo = seriNo.Substring(0, 2); } String orderNo = document.SlipOrderNo; if (orderNo.Length > 6) { orderNo = orderNo.Substring(0, 6); } documentId = String.Format("{0} {1}", seriNo.PadLeft(2, ' '), orderNo.PadLeft(6, '0')); } else if (document.DocumentTypeId >= 0) { #if WindowsCE int lastSlipNo = Document.GetLastSlipNo(PosConfiguration.Get("RegisterId")); lastSlipNo++; documentId = lastSlipNo.ToString().PadLeft(6, '0'); #endif } logWriter.WriteLine("1,{0:D5},{1},{2},{3} {4},{5,-12}", number++, (document.DocumentTypeId < 0) ? "01" : "02", //DOcument name ve document shortname gibi iki ayri property olsa //daha guzel olur document.Code, PosConfiguration.Get("RegisterId"), (currentCashier == null) ? "0000" : currentCashier.Id, documentId); logWriter.WriteLine("1,{0},03,TAR,{1:dd}/{1:MM}/{1:yyyy} ,{1:HH:mm:ss} ", number++.ToString().PadLeft(5, '0'), DateTime.Now); /********** INFO RECEIPTS ****************/ // Tckn/Vkn if (document.Code == PosMessage.HR_CODE_INVOICE || document.Code == PosMessage.HR_CODE_E_INVOICE || document.Code == PosMessage.HR_CODE_E_ARCHIVE || document.Code == PosMessage.HR_CODE_ADVANCE || document.Code == PosMessage.HR_CODE_CURRENT_ACCOUNT_COLLECTION) { String tcknVkn = ""; if (!String.IsNullOrEmpty(document.TcknVkn)) { tcknVkn = document.TcknVkn.Trim(); } else if (document.Customer != null) { tcknVkn = document.Customer.Contact[4].Trim(); } if (tcknVkn.Trim().Length == 10) { logWriter.WriteLine("1,{0:D5},60,VKN,{1},{2}", number++, tcknVkn.PadLeft(12), " ".PadLeft(12)); } else if (tcknVkn.Trim().Length == 11) { logWriter.WriteLine("1,{0:D5},61,TKN,{1},{2}", number++, tcknVkn.PadLeft(12), " ".PadLeft(12)); } } // Issue Datetime if (document.IssueDate != null) { if (document.Code == PosMessage.HR_CODE_INVOICE || document.Code == PosMessage.HR_CODE_COLLECTION_INVOICE || document.Code == PosMessage.HR_CODE_CURRENT_ACCOUNT_COLLECTION) { logWriter.WriteLine("1,{0:D5},62,BDT,{1:dd}/{1:MM}/{1:yyyy} ,{2}", number++, document.IssueDate, " ".PadLeft(12)); } else if (document.Code == PosMessage.HR_CODE_CAR_PARKING) { logWriter.WriteLine("1,{0:D5},62,BDT,{1:dd}/{1:MM}/{1:yyyy} ,{1:HH:mm:ss} ", number++, document.IssueDate); } } // Car Plate if (!String.IsNullOrEmpty(document.CustomerTitle)) { if (document.Code == PosMessage.HR_CODE_CAR_PARKING) { logWriter.WriteLine("1,{0:D5},63,PLK,{1},{2}", number++, document.CustomerTitle.PadLeft(12), " ".PadLeft(12)); } } // Customer Name if (document.Code == PosMessage.HR_CODE_ADVANCE || document.Code == PosMessage.HR_CODE_COLLECTION_INVOICE || document.Code == PosMessage.HR_CODE_CURRENT_ACCOUNT_COLLECTION) { string title = ""; if (document.Customer != null) { title = document.Customer.Name; } else { title = document.CustomerTitle; } if (!String.IsNullOrEmpty(title)) { logWriter.WriteLine("1,{0:D5},64,MAD,{1}", number++, title.Trim().PadLeft(25)); } } if (document.Code == PosMessage.HR_CODE_COLLECTION_INVOICE) { // Instution Name if (!String.IsNullOrEmpty(document.ReturnReason)) { logWriter.WriteLine("1,{0:D5},65,KAD,{1}", number++, document.ReturnReason.PadLeft(25)); } // Amount- Comission decimal comission = document.ComissionAmount; decimal amount = document.TotalAmount - comission; decimal total = document.TotalAmount; logWriter.WriteLine("1,{0:D5},66,KMS, {1:D10}, {2:D10}", number++, (long)Math.Round(100m * amount, 0), (long)Math.Round(100m * comission, 0)); } /********** E-INVOICE/E-ARCHIVE ****************/ if (document.Code == PosMessage.HR_CODE_E_ARCHIVE || document.Code == PosMessage.HR_CODE_E_INVOICE) { #region SUPPLIER PARTY /* Accounting Supplier Party */ if (Connector.Instance().CurrentSettings.SupplierInfo != null) { AccountingParty supplier = Connector.Instance().CurrentSettings.SupplierInfo; // Tckn/Vkn if (!String.IsNullOrEmpty(supplier.TCKN_VKN)) { logWriter.WriteLine("1,{0:D5},70,ASP,{1},{2}", number++, supplier.TCKN_VKN.PadLeft(12), " ".PadLeft(12)); } // Title if (!String.IsNullOrEmpty(supplier.Title)) { subLines = GetSubStringsAsLen(supplier.Title, 25); foreach (string str in subLines) { logWriter.WriteLine("1,{0:D5},71,ASP,{1}", number++, str.PadLeft(25)); } } // First Name & Family Name if (!String.IsNullOrEmpty(supplier.FirstName) && !String.IsNullOrEmpty(supplier.FamilyName)) { string fName = supplier.FirstName; if (supplier.FirstName.Length > 12) { fName = supplier.FirstName.Substring(0, 12); } string famName = supplier.FamilyName; if (supplier.FamilyName.Length > 12) { famName = supplier.FamilyName.Substring(0, 12); } logWriter.WriteLine("1,{0:D5},72,ASP,{1},{2}", number++, fName.PadLeft(12), famName.PadLeft(12)); } // PostalCode & Room string postal = ""; string room = ""; if (!String.IsNullOrEmpty(supplier.PostalCode)) { postal = supplier.PostalCode; } if (!String.IsNullOrEmpty(supplier.Room)) { room = supplier.Room; } if (postal.Length > 0 || room.Length > 0) { logWriter.WriteLine("1,{0:D5},73,ASP,{1},{2}", number++, postal.PadLeft(12), room.PadLeft(12)); } // Building No & Building Name string buildingNo = ""; if (!String.IsNullOrEmpty(supplier.BuildingNo)) { buildingNo = supplier.BuildingNo; } string buildingName = ""; if (!String.IsNullOrEmpty(supplier.BuildingName)) { buildingName = supplier.BuildingName; if (supplier.BuildingName.Length > 12) { buildingName = supplier.BuildingName.Substring(0, 12); } } if (buildingNo.Length > 0 || buildingName.Length > 0) { logWriter.WriteLine("1,{0:D5},74,ASP,{1},{2}", number++, buildingNo.PadLeft(12), buildingName.PadLeft(12)); } // Street if (!String.IsNullOrEmpty(supplier.Street)) { subLines = GetSubStringsAsLen(supplier.Street, 25); foreach (string str in subLines) { logWriter.WriteLine("1,{0:D5},75,ASP,{1}", number++, str.PadLeft(25)); } } // District if (!String.IsNullOrEmpty(supplier.District)) { subLines = GetSubStringsAsLen(supplier.District, 25); foreach (string str in subLines) { logWriter.WriteLine("1,{0:D5},76,ASP,{1}", number++, str.PadLeft(25)); } } // Village if (!String.IsNullOrEmpty(supplier.Village)) { subLines = GetSubStringsAsLen(supplier.Village, 25); foreach (string str in subLines) { logWriter.WriteLine("1,{0:D5},77,ASP,{1}", number++, str.PadLeft(25)); } } // Subcity if (!String.IsNullOrEmpty(supplier.SubCity)) { subLines = GetSubStringsAsLen(supplier.SubCity, 25); foreach (string str in subLines) { logWriter.WriteLine("1,{0:D5},78,ASP,{1}", number++, str.PadLeft(25)); } } // City & Country string city = ""; string country = ""; if (!String.IsNullOrEmpty(supplier.City)) { city = supplier.City; if (supplier.City.Length > 12) { city = supplier.City.Substring(0, 12); } } if (!String.IsNullOrEmpty(supplier.Country)) { country = supplier.Country; if (supplier.Country.Length > 12) { country = supplier.Country.Substring(0, 12); } } if (city.Length > 0 || country.Length > 0) { logWriter.WriteLine("1,{0:D5},79,ASP,{1},{2}", number++, city.PadLeft(12), country.PadLeft(12)); } // Telephone if (!String.IsNullOrEmpty(supplier.Telephone)) { string tel = supplier.Telephone; if (tel.Length > 25) { tel = supplier.Telephone.Substring(0, 25); } logWriter.WriteLine("1,{0:D5},80,ASP,{1}", number++, tel.PadLeft(25)); } // Fax if (!String.IsNullOrEmpty(supplier.Fax)) { string fax = supplier.Fax; if (fax.Length > 25) { fax = supplier.Fax.Substring(0, 25); } logWriter.WriteLine("1,{0:D5},81,ASP,{1}", number++, fax.PadLeft(25)); } // EMail if (!String.IsNullOrEmpty(supplier.EMail)) { subLines = GetSubStringsAsLen(supplier.EMail, 25); foreach (string str in subLines) { logWriter.WriteLine("1,{0:D5},82,ASP,{1}", number++, str.PadLeft(25)); } } // WebPage if (!String.IsNullOrEmpty(supplier.WebPage)) { subLines = GetSubStringsAsLen(supplier.WebPage, 25); foreach (string str in subLines) { logWriter.WriteLine("1,{0:D5},83,ASP,{1}", number++, str.PadLeft(25)); } } // TaxScheme if (!String.IsNullOrEmpty(supplier.TaxScheme)) { subLines = GetSubStringsAsLen(supplier.TaxScheme, 25); foreach (string str in subLines) { logWriter.WriteLine("1,{0:D5},84,ASP,{1}", number++, str.PadLeft(25)); } } } #endregion /* Accounting Customer Party */ if (document.AdditionalInfo != null) { #region CUSTOMER PARTY // Customer info if (document.AdditionalInfo.CustomerParty != null) { AccountingParty customer = document.AdditionalInfo.CustomerParty; // Tckn/Vkn if (String.IsNullOrEmpty(customer.TCKN_VKN)) { if (document.Customer != null) { customer.SetValue(AccountingPartyTag.TCKN_VKN, document.Customer.Contact[4].Trim()); } else { customer.SetValue(AccountingPartyTag.TCKN_VKN, document.TcknVkn); } } if (!String.IsNullOrEmpty(customer.TCKN_VKN)) { logWriter.WriteLine("1,{0:D5},70,ACP,{1},{2}", number++, customer.TCKN_VKN.Trim().PadLeft(12), "".PadLeft(12)); } // Title if (!String.IsNullOrEmpty(customer.Title)) { subLines = GetSubStringsAsLen(customer.Title, 25); foreach (string str in subLines) { logWriter.WriteLine("1,{0:D5},71,ACP,{1}", number++, str.PadLeft(25)); } } // First Name & Family Name if (!String.IsNullOrEmpty(customer.FirstName) && !String.IsNullOrEmpty(customer.FamilyName)) { string cName = customer.FirstName; if (cName.Length > 12) { cName = customer.FirstName.Substring(0, 12); } string cFamName = customer.FamilyName; if (cFamName.Length > 12) { cFamName = customer.FamilyName.Substring(0, 12); } logWriter.WriteLine("1,{0:D5},72,ACP,{1},{2}", number++, cName.PadLeft(12), cFamName.PadLeft(12)); } // PostalCode & Room string postal = ""; string room = ""; if (!String.IsNullOrEmpty(customer.PostalCode)) { postal = customer.PostalCode; } if (!String.IsNullOrEmpty(customer.Room)) { room = customer.Room; } if (postal.Length > 0 || room.Length > 0) { logWriter.WriteLine("1,{0:D5},73,ACP,{1},{2}", number++, postal.PadLeft(12), room.PadLeft(12)); } // Building No & Building Name string buildingNo = ""; if (!String.IsNullOrEmpty(customer.BuildingNo)) { buildingNo = customer.BuildingNo; } string buildingName = ""; if (!String.IsNullOrEmpty(customer.BuildingName)) { buildingName = customer.BuildingName; if (buildingName.Length > 12) { buildingName = customer.BuildingName.Substring(0, 12); } } if (buildingNo.Length > 0 || buildingName.Length > 0) { logWriter.WriteLine("1,{0:D5},74,ACP,{1},{2}", number++, buildingNo.PadLeft(12), buildingName.PadLeft(12)); } // Street if (!String.IsNullOrEmpty(customer.Street)) { subLines = GetSubStringsAsLen(customer.Street, 25); foreach (string str in subLines) { logWriter.WriteLine("1,{0:D5},75,ACP,{1}", number++, str.PadLeft(25)); } } // District if (!String.IsNullOrEmpty(customer.District)) { subLines = GetSubStringsAsLen(customer.District, 25); foreach (string str in subLines) { logWriter.WriteLine("1,{0:D5},76,ACP,{1}", number++, str.PadLeft(25)); } } // Village if (!String.IsNullOrEmpty(customer.Village)) { subLines = GetSubStringsAsLen(customer.Village, 25); foreach (string str in subLines) { logWriter.WriteLine("1,{0:D5},77,ACP,{1}", number++, str.PadLeft(25)); } } // Subcity if (!String.IsNullOrEmpty(customer.SubCity)) { subLines = GetSubStringsAsLen(customer.SubCity, 25); foreach (string str in subLines) { logWriter.WriteLine("1,{0:D5},78,ACP,{1}", number++, str.PadLeft(25)); } } // City & Country string city = ""; string country = ""; if (!String.IsNullOrEmpty(customer.City)) { city = customer.City; if (city.Length > 12) { city = customer.City.Substring(0, 12); } } if (!String.IsNullOrEmpty(customer.Country)) { country = customer.Country; if (country.Length > 12) { country = customer.Country.Substring(0, 12); } } if (city.Length > 0 || country.Length > 0) { logWriter.WriteLine("1,{0:D5},79,ACP,{1},{2}", number++, city.PadLeft(12), country.PadLeft(12)); } // Telephone if (!String.IsNullOrEmpty(customer.Telephone)) { string cTel = customer.Telephone; if (cTel.Length > 25) { cTel = customer.Telephone.Substring(0, 25); } logWriter.WriteLine("1,{0:D5},80,ACP,{1}", number++, customer.Telephone.PadLeft(25)); } // Fax if (!String.IsNullOrEmpty(customer.Fax)) { string cFax = customer.Fax; if (cFax.Length > 25) { cFax = customer.Fax.Substring(0, 25); } logWriter.WriteLine("1,{0:D5},81,ACP,{1}", number++, customer.Fax.PadLeft(25)); } // EMail if (!String.IsNullOrEmpty(customer.EMail)) { subLines = GetSubStringsAsLen(customer.EMail, 25); foreach (string str in subLines) { logWriter.WriteLine("1,{0:D5},82,ACP,{1}", number++, str.PadLeft(25)); } } // WebPage if (!String.IsNullOrEmpty(customer.WebPage)) { subLines = GetSubStringsAsLen(customer.WebPage, 25); foreach (string str in subLines) { logWriter.WriteLine("1,{0:D5},83,ACP,{1}", number++, str.PadLeft(25)); } } // TaxScheme if (!String.IsNullOrEmpty(customer.TaxScheme)) { subLines = GetSubStringsAsLen(customer.TaxScheme, 25); foreach (string str in subLines) { logWriter.WriteLine("1,{0:D5},84,ACP,{1}", number++, str.PadLeft(25)); } } } #endregion // Profil ID string profID = ""; switch (document.AdditionalInfo.ProfilID) { case DocProfilID.TEMEL_FATURA: profID = "TEMELFATURA"; break; case DocProfilID.TICARI_FATURA: profID = "TÝCARÝFATURA"; break; } logWriter.WriteLine("1,{0:D5},90,PID,{1},{2}", number++, profID.PadLeft(12), "".PadLeft(12)); // Currency Code string ccode = ""; switch (document.AdditionalInfo.CurrencyCode) { case DocCurrencyCode.DOLLAR: ccode = "USD"; break; case DocCurrencyCode.EURO: ccode = "EUR"; break; case DocCurrencyCode.LIRA: ccode = "TRL"; break; case DocCurrencyCode.POUND: ccode = "GBP"; break; } logWriter.WriteLine("1,{0:D5},91,FCC,{1},{2}", number++, ccode.PadLeft(12), "".PadLeft(12)); } } /********** ITEMS ****************/ decimal totalAmount = 0; decimal documentTotalAmount = document.TotalAmount; decimal documentTotalVAT = document.TotalVAT; foreach (IFiscalItem item in document.Items) { try { Decimal lineQuantity = 0m; Decimal remainQuantity = Math.Abs(item.Quantity); List <decimal> appliedAdjTotals = new List <decimal>(); while (remainQuantity > 0) { logWriter.Write("1,{0:D5},", number++); if (docStatus != Connector.TEMP_DOCUMENT_STATUS) { lineQuantity = (Math.Min(remainQuantity, 99)); } else { lineQuantity = remainQuantity; } int quantity = (int)lineQuantity; int rem = (int)Math.Round((lineQuantity - quantity) * 1000, 0); remainQuantity -= Math.Abs(lineQuantity); totalAmount = Math.Round((item.TotalAmount / item.Quantity) * lineQuantity, 2); if (item.Quantity >= 0) { logWriter.Write("04,SAT,"); } else { logWriter.Write("05,IPT,"); } string[] itemAdjustments = item.GetAdjustments(); foreach (string adjustment in itemAdjustments) { totalAmount -= Decimal.Parse(adjustment.Split('|')[0]) / item.Quantity * lineQuantity; } totalAmount = Math.Round(totalAmount, 2); logWriter.WriteLine("{0:D2}.{1:D3}{2:D6},{3:D2}{4:D10}", Math.Abs(quantity), Math.Abs(rem), item.Product.Id, item.Product.Department.Id, (long)Math.Round(100m * totalAmount, 0)); //Barcode 1,rrrrr,20,BKD,bbbbbbbbbbbb,bbbbbbbbbbbb if (Connector.Instance().CurrentSettings.GetProgramOption(Setting.BarcodeLineInMainLogFile) == PosConfiguration.ON) { string barcode = item.Product.Barcode.PadRight(20, ' '); string BKDLine = string.Format("1,{0},", number++.ToString().PadLeft(5, '0')); BKDLine += string.Format("38,BKD,{0},{1}", barcode.Substring(0, 12), barcode.Substring(12)); logWriter.WriteLine(BKDLine.PadRight(40, ' ')); } // It means fiscal printer is Vx675 if (!String.IsNullOrEmpty(PosConfiguration.Get("VxOrderPath"))) { string remarkLine = string.Format("1,{0},", number++.ToString().PadLeft(5, '0')); remarkLine += string.Format("22,NOT,{0}", item.Name); logWriter.WriteLine(remarkLine.PadRight(40, ' ')); } //Satici 1,rrrrr,20,STC,kkk nnnn, if (item.SalesPerson != null) { logWriter.WriteLine("1,{0},20,STC,{1} {2},{3,12}", number++.ToString().PadLeft(5, '0'), PosConfiguration.Get("RegisterId"), item.SalesPerson.Id, " "); } //Seri no veya IMEI numaralarý //1,rrrrr,36,SNO,bbbbbbbbbbbb,bbbbbbbbbbbb if (!String.IsNullOrEmpty(item.SerialNo)) { string serialNo = item.SerialNo.PadRight(24, ' '); logWriter.WriteLine("1,{0},36,SNO,{1},{2}", number++.ToString().PadLeft(5, '0'), serialNo.Substring(0, 12), serialNo.Substring(12).PadRight(12, ' ')); } if (!String.IsNullOrEmpty(item.BatchNumber)) {//PNO , parti no string batchNumber = item.BatchNumber.PadRight(24, ' '); logWriter.WriteLine("1,{0},37,PNO,{1},{2}", number++.ToString().PadLeft(5, '0'), batchNumber.Substring(0, 12), batchNumber.Substring(12).PadRight(12, ' ')); } if (!String.IsNullOrEmpty(item.ExpiryDate.ToString()) && item.ExpiryDate > DateTime.MinValue) { string expiryDate = item.ExpiryDate.Day.ToString() + "/"; if (item.ExpiryDate.Month < 10) { expiryDate += "0"; } expiryDate += item.ExpiryDate.Month + "/" + item.ExpiryDate.Year.ToString(); expiryDate = expiryDate.PadRight(24, ' '); logWriter.WriteLine("1,{0},39,SKT,{1},{2}", number++.ToString().PadLeft(5, '0'), expiryDate.Substring(0, 12), expiryDate.Substring(12).PadRight(12, ' ')); } int index = 0; foreach (string adjustment in itemAdjustments) { string[] detail = adjustment.Split('|');// Amount | Percentage | CashierId decimal itemAdjAmount = decimal.Parse(detail[0]); string direction = itemAdjAmount > 0 ? "ART" : "IND"; itemAdjAmount = Math.Abs(itemAdjAmount); decimal lineAdjAmount = Math.Round((itemAdjAmount / item.Quantity) * lineQuantity, 2); if (appliedAdjTotals.Count <= index) { appliedAdjTotals.Add(0); } if (appliedAdjTotals[index] < itemAdjAmount) { appliedAdjTotals[index] += lineAdjAmount; decimal adjustmentDifference = itemAdjAmount - appliedAdjTotals[index]; if (adjustmentDifference < 0) { lineAdjAmount += adjustmentDifference; } logWriter.WriteLine("1,{0:D5},06,{1},SNS {2} %{3}, {4:D10}", number++, direction, detail[2], detail[1], (long)Math.Round(lineAdjAmount * 100m, 0) ); } index++; } } } catch { } } /********** DOCUMENT ADJUSTMENTS ****************/ Decimal usedPointPrice = 0m; String pointCreditValue = Connector.Instance().CurrentSettings.GetProgramOption(Setting.ConnectPointToCredit).ToString(); Boolean convertPointToPayment = false; if (pointCreditValue[0] == '1' && pointCreditValue.Length == 4) { convertPointToPayment = true; } totalAmount = documentTotalAmount; string[] documentAdjustments = document.GetAdjustments(); foreach (string adjustment in documentAdjustments) { string[] detail = adjustment.Split('|');// Amount | Percentage | CashierId decimal amount = decimal.Parse(detail[0]); string direction = amount > 0 ? "ART" : "IND"; if (convertPointToPayment && detail[2] == "9998") { usedPointPrice = Math.Abs(amount); documentTotalAmount -= amount; continue; } totalAmount -= amount; amount = Math.Abs(amount); logWriter.WriteLine("1,{0:D5},06,{1},TOP {2} %{3}, {4:D10}", number++, direction, detail[2], detail[1], (long)Math.Round(amount * 100m, 0)); } docStatus -= 3; //Belge toplami 1,rrrrr,08,TOP, , tttttttttt logWriter.WriteLine("1,{0:D5},08,TOP, {1}, {2:D10}", number++, (docStatus >= 0) ? docStatus.ToString() : " ", (long)Math.Round(documentTotalAmount * 100m, 0)); //Kasiyer 1,rrrrr,20,STC,kkk nnnn, if (document.SalesPerson != null) { logWriter.WriteLine("1,{0:D5},20,STC,{1} {2}, ", number++, PosConfiguration.Get("RegisterId"), document.SalesPerson.Id); } if (convertPointToPayment && usedPointPrice > 0) { String paymentType = pointCreditValue[1] == '0' ? "KRD" : "CHK"; logWriter.WriteLine("1,{0:D5},10,{1}, {2:D2}, {3:D10}", number++, paymentType, pointCreditValue.Substring(2, 2), (long)Math.Round(usedPointPrice * 100m, 0)); } /***** PAYMENTS *******/ decimal documentBalance = document.TotalAmount; String[] checkpayments = document.GetCheckPayments(); foreach (String checkpayment in checkpayments) { String[] detail = checkpayment.Split('|');// Amount | RefNumber | SequenceNo if (detail[1].Length > 12) { detail[1] = detail[1].Substring(0, 12); } decimal amount = Math.Min(Decimal.Parse(detail[0]), documentBalance); logWriter.WriteLine("1,{0:D5},09,CEK,{1,12}, {2:D10}", number++, detail[1], (long)Math.Round(amount * 100m, 0)); documentBalance = documentBalance - amount; } String[] currencypayments = document.GetCurrencyPayments(); foreach (String currencypayment in currencypayments) { String[] detail = currencypayment.Split('|');// Amount | Exchange Rate | Name | SequenceNo decimal amount = Math.Min(Decimal.Parse(detail[0]), documentBalance); long quantity = (long)Math.Round(amount * 100m / decimal.Parse(detail[1]), 0); int id = 0; foreach (ICurrency cur in Connector.Instance().GetCurrencies().Values) { if (cur.Name != detail[2]) { continue; } id = cur.Id; break; } logWriter.WriteLine("1,{0:D5},09,DVZ,{1} {2:D9}, {3:D10}", number++, (char)id, quantity, (long)Math.Round(amount * 100m, 0)); documentBalance = documentBalance - amount; } String[] creditpayments = document.GetCreditPayments(); foreach (String creditypayment in creditpayments) { String[] detail = creditypayment.Split('|');// Amount | Installments | Id | ViaByEFT | SequenceNo decimal amount = Math.Min(Decimal.Parse(detail[0]), documentBalance); int installments = 0; Parser.TryInt(detail[1], out installments); if (installments > 0) { logWriter.WriteLine("1,{0:D5},10,KRD,{1:D2} {2:D2}, {3:D10}", number++, installments, int.Parse(detail[2]), (long)Math.Round(amount * 100m, 0) ); } else { logWriter.WriteLine("1,{0:D5},10,KRD, {1:D2}, {2:D10}", number++, int.Parse(detail[2]), (long)Math.Round(amount * 100m, 0) ); } documentBalance = documentBalance - amount; } //cash payments must be at lasti because customerchanges always cash String[] cashpayments = document.GetCashPayments(); foreach (String cashpayment in cashpayments) { String[] detail = cashpayment.Split('|');// Amount | SequenceNo decimal amount = Math.Min(Decimal.Parse(detail[0]), documentBalance); logWriter.WriteLine("1,{0:D5},09,NAK, , {1:D10}", number++, (long)Math.Round(amount * 100m, 0)); documentBalance = documentBalance - amount; } foreach (PointObject po in document.Points) { logWriter.WriteLine("1,{0},22,PRM,{1:D2} {2:D9},{3,12:D10}", number++.ToString().PadLeft(5, '0'), 0, 0, po.Value); } if (Connector.Instance().CurrentSettings.GetProgramOption(Setting.WriteDocumentID) == PosConfiguration.ON) { //After power shutdown on POS side. if Doc loaded from file if (lastZNo == 0 && document.DocumentFileZNo != 0) { lastZNo = document.DocumentFileZNo - 1; } string BIDLine = PosConfiguration.Get("FiscalId") + (lastZNo + 1).ToString().PadLeft(4, '0') + document.Id.ToString().PadLeft(4, '0'); BIDLine = string.Format("1,{0:D5},24,BID,{1},{2}", number++, BIDLine.Substring(0, 10).PadRight(12, ' '), BIDLine.Substring(10, BIDLine.Length - 10)).PadRight(40, ' '); logWriter.WriteLine(BIDLine); } //Special Promotion Lines produced by promotion server foreach (string promoLog in document.PromoLogLines) { logWriter.WriteLine("1,{0:D5},{1}", number++, promoLog); } //GSM NUMBER OF CUSTOMER if (document.Customer != null) { if (document.Customer.GsmNumber != String.Empty) { string gsmNumber = document.Customer.GsmNumber.PadRight(24, ' '); logWriter.WriteLine("1,{0:D5},50,GSM,{1},{2}", number++, gsmNumber.Substring(0, 12), gsmNumber.Substring(12, 12)); } } //RETURN REASON OF THE DOCUMENT if (!String.IsNullOrEmpty(document.ReturnReason)) { string returnReason = document.ReturnReason.PadRight(24, ' '); logWriter.WriteLine("1,{0:D5},51,IAN,{1},{2}", number++, returnReason.Substring(0, 12), returnReason.Substring(12, 12)); } //TODO Belge sonu 1,rrrrr,11,SON,mmmmmmmmmmmm,mmmmmmmmssss logWriter.Write("1,{0:D5},11,SON,", number++); if (document.Customer != null) { string code = document.Customer.Code.PadRight(20); logWriter.Write("{0},{1}", code.Substring(0, 12), code.Substring(12, 8)); } else { logWriter.Write(" , "); } logWriter.Write(document.IsOpenDocument ? " A" : " "); return(logWriter); }
internal override StringWriter LogItems(ISalesDocument document, int docStatus, ref int number) { StringWriter logWriter = new StringWriter(); String registerId = PosConfiguration.Get("RegisterId"); //if (document.Id == 0 || document.IsEmpty) : Not possible, The function which calls LogItems checks that condition. String documentId = document.Id.ToString().PadLeft(6, '0') + " "; if (!String.IsNullOrEmpty(document.SlipSerialNo)) { String seriNo = document.SlipSerialNo; if (seriNo.Length > 2) { seriNo = seriNo.Substring(0, 2); } String orderNo = document.SlipOrderNo; if (orderNo.Length > 6) { orderNo = orderNo.Substring(0, 6); } documentId = String.Format( "{0}{1}", seriNo.PadLeft(2, ' '), orderNo.PadLeft(6, '0')); } else if (document.DocumentTypeId >= 0) { #if WindowsCE int lastSlipNo = Document.GetLastSlipNo(PosConfiguration.Get("RegisterId")); lastSlipNo++; documentId = lastSlipNo.ToString().PadLeft(6, '0') + " "; #endif } String docTypeId, docCode, saleCode; if (document.Code == PosMessage.HR_CODE_RETURN) { docTypeId = "24"; docCode = PosMessage.HR_INTER_CODE_RETURN; saleCode = "25,GAL"; } else { docTypeId = document.DocumentTypeId < 0 ? "01" : "02"; docCode = document.Code; saleCode = "04,SAT"; } String cashierId = "0000"; if (currentCashier != null) { cashierId = currentCashier.Id; } logWriter.WriteLine("1,{0:D5},{1},{2},{3} {4},{5:D6}{6:D4}", number++, docTypeId, docCode, registerId, cashierId, documentId, (lastZNo + 1)); logWriter.WriteLine("1,{0:D5},03,TAR,{1:dd}/{1:MM}/{1:yyyy} ,{1:HH:mm:ss} ", number++, DateTime.Now); decimal totalAmount = 0; decimal documentTotalAmount = document.TotalAmount; decimal documentTotalVAT = document.TotalVAT; foreach (IFiscalItem item in document.Items) { try { Decimal lineQuantity = 0m; Decimal remainQuantity = Math.Abs(item.Quantity); while (remainQuantity > 0) { logWriter.Write("1,{0:D5},", number++); lineQuantity = (Math.Min(remainQuantity, 99)); int quantity = (int)lineQuantity; int rem = (int)Math.Round((lineQuantity - quantity) * 1000, 0); remainQuantity -= Math.Abs(lineQuantity); totalAmount = Math.Round((item.TotalAmount / item.Quantity) * lineQuantity, 2); if (item.Quantity >= 0) { logWriter.Write(saleCode + ","); } else { logWriter.Write("05,IPT,"); } string[] itemAdjustments = item.GetAdjustments(); foreach (string adjustment in itemAdjustments) { totalAmount -= Math.Round((Decimal.Parse(adjustment.Split('|')[0]) / item.Quantity) * lineQuantity, 2); } logWriter.WriteLine("{0:D2}.{1:D3}{2:D6},{3:D2}{4,10}", Math.Abs(quantity), Math.Abs(rem), item.Product.Id, item.Product.Department.Id, FormatDecimal(Math.Abs(totalAmount), 10)); //Barcode 1,rrrrr,20,BKD,bbbbbbbbbbbb,bbbbbbbbbbbb if (Connector.Instance().CurrentSettings.GetProgramOption(Setting.BarcodeLineInMainLogFile) == PosConfiguration.ON) { string barcode = item.Product.Barcode.PadRight(20, ' '); string BKDLine = string.Format("1,{0},", number++.ToString().PadLeft(5, '0')); BKDLine += string.Format("38,BKD,{0},{1}", barcode.Substring(0, 12), barcode.Substring(12)); logWriter.WriteLine(BKDLine.PadRight(40, ' ')); } //Satici 1,rrrrr,22,STC,kkk nnnn, if (item.SalesPerson != null) { logWriter.WriteLine("1,{0:D5},22,STC,{1,4}{2,8},{2,12}", number++, item.SalesPerson.Id, " "); } //Seri no veya IMEI numaralarý //1,rrrrr,36,SNO,bbbbbbbbbbbb,bbbbbbbbbbbb if (!String.IsNullOrEmpty(item.SerialNo)) { string serialNo = item.SerialNo.PadRight(24, ' '); logWriter.WriteLine("1,{0},36,SNO,{1},{2}", number++.ToString().PadLeft(5, '0'), serialNo.Substring(0, 12), serialNo.Substring(12).PadRight(12, ' ')); } /******* ITEM ADJUSTMENTS *********/ foreach (string adjustment in itemAdjustments) { string[] detail = adjustment.Split('|');// Amount | Percentage | CashierId decimal amount = decimal.Parse(detail[0]); string adjCode = amount > 0 ? "39" : "06"; string direction = amount > 0 ? "ART" : "IND"; amount = Math.Abs(Math.Round((amount / item.Quantity) * lineQuantity, 2)); logWriter.WriteLine("1,{0:D5},{1},{2},SNS {3} %{4}, {5:D10}", number++, adjCode, direction, detail[2], detail[1], FormatDecimal(amount, 10)); } } } catch { } } /********** DOCUMENT ADJUSTMENTS ****************/ Decimal usedPointPrice = 0m; String pointCreditValue = Connector.Instance().CurrentSettings.GetProgramOption(Setting.ConnectPointToCredit).ToString(); Boolean convertPointToPayment = false; if (pointCreditValue[0] == '1' && pointCreditValue.Length == 4) { convertPointToPayment = true; } totalAmount = documentTotalAmount; string[] documentAdjustments = document.GetAdjustments(); foreach (string adjustment in documentAdjustments) { string[] detail = adjustment.Split('|');// Amount | Percentage | CashierId decimal amount = decimal.Parse(detail[0]); string adjCode = amount > 0 ? "39" : "06"; string direction = amount > 0 ? "ART" : "IND"; if (convertPointToPayment && detail[2] == "9998") { usedPointPrice = Math.Abs(amount); documentTotalAmount -= amount; continue; } totalAmount -= amount; amount = Math.Abs(amount); logWriter.WriteLine("1,{0:D5},{1},{2},TOP {3} %{4}, {5:D10}", number++, adjCode, direction, detail[2], detail[1], FormatDecimal(amount, 10)); } string totalLineCode = "08,TOP"; string statusCode = " "; if (docStatus != 0) { docStatus -= 3; totalLineCode = "30,FIP"; statusCode = docStatus.ToString(); } //Belge toplami 1,rrrrr,08,TOP, , tttttttttt logWriter.WriteLine("1,{0:D5},{1}, {2}, {3:D10}", number++, totalLineCode, statusCode, FormatDecimal(document.TotalAmount, 10)); if (document.DocumentTypeId > -1) { decimal[,] taxRateTotals = document.TaxRateTotals; for (int i = 0; i < taxRateTotals.GetLength(0); i++) { int taxRate = (int)(Math.Round(Department.TaxRates[(int)(taxRateTotals[i, 0])] * 100, 0)); logWriter.WriteLine("1,{0:D5},07,KDV, {1:D2}, {2,10}", number++, taxRate, FormatDecimal(taxRateTotals[i, 1], 10)); } } //Kasiyer 1,rrrrr,22,STC,kkk nnnn, if (document.SalesPerson != null) { logWriter.WriteLine("1,{0:D5},22,STC,{1,4}{2,8},{2,12}", number++, document.SalesPerson.Id, " "); } if (convertPointToPayment && usedPointPrice > 0) { String paymentType = pointCreditValue[1] == '0' ? "KRD" : "CHK"; logWriter.WriteLine("1,{0:D5},10,{1}, {2:D2}, {3:D10}", number++, paymentType, pointCreditValue.Substring(2, 2), FormatDecimal(usedPointPrice, 10)); } /***** PAYMENTS *******/ decimal documentBalance = document.TotalAmount; String[] checkpayments = document.GetCheckPayments(); foreach (String checkpayment in checkpayments) { String[] detail = checkpayment.Split('|');// Amount | RefNumber detail[1] = detail[1].PadRight(14, ' '); decimal amount = Math.Min(Decimal.Parse(detail[0]), documentBalance); logWriter.WriteLine("1,{0:D5},20,CEK,{1,12},{2}{3,8}", number++, detail[1].Substring(0, 12), detail[1].Substring(12, 2), FormatDecimal(amount, 10)); documentBalance = documentBalance - amount; } String[] currencypayments = document.GetCurrencyPayments(); foreach (String currencypayment in currencypayments) { String[] detail = currencypayment.Split('|');// Amount | Exchange Rate | Name decimal amount = Math.Min(Decimal.Parse(detail[0]), documentBalance); long quantity = (long)Math.Round(amount * 100m / decimal.Parse(detail[1]), 0); int id = 0; foreach (ICurrency cur in Connector.Instance().GetCurrencies().Values) { if (cur.Name != detail[2]) { continue; } id = cur.Id; break; } logWriter.WriteLine("1,{0:D5},21,DVZ,{1:D} {2,10}, {3,10}", number++, (char)id, quantity, FormatDecimal(amount, 10)); documentBalance = documentBalance - amount; } String[] creditpayments = document.GetCreditPayments(); foreach (String creditypayment in creditpayments) { String[] detail = creditypayment.Split('|');// Amount | Installments | Id decimal amount = Math.Min(Decimal.Parse(detail[0]), documentBalance); logWriter.WriteLine("1,{0:D5},10,KRD,{1,10}{2:D2},{3:D2}{4,10}", number++, " ", int.Parse(detail[2]), int.Parse(detail[1]), FormatDecimal(amount, 10)); documentBalance = documentBalance - amount; } //cash payments must be at lasti because customerchanges always cash String[] cashpayments = document.GetCashPayments(); foreach (String cashpayment in cashpayments) { decimal amount = Math.Min(Decimal.Parse(cashpayment), documentBalance); logWriter.WriteLine("1,{0:D5},09,NAK, , {1,10}", number++, FormatDecimal(amount, 10)); documentBalance = documentBalance - amount; } foreach (PointObject po in document.Points) { logWriter.WriteLine("1,{0:D5},31,BNS,{1,12},{2,12:D10}", number++, Connector.Instance().PointAdapter != null && Connector.Instance().PointAdapter.Online ? 1 : 0, po.Value); } if (Connector.Instance().CurrentSettings.GetProgramOption(Setting.WriteDocumentID) == PosConfiguration.ON) { string BIDLine = PosConfiguration.Get("FiscalId") + (lastZNo + 1).ToString().PadLeft(4, '0') + document.Id.ToString().PadLeft(4, '0'); BIDLine = string.Format("1,{0:D5},24,BID,{1},{2}", number++, BIDLine.Substring(0, 12), BIDLine.Substring(12, BIDLine.Length - 12)).PadRight(40, ' '); logWriter.WriteLine(BIDLine); } //Special Promotion Lines produced by promotion server foreach (string promoLog in document.PromoLogLines) { logWriter.WriteLine("1,{0:D5},{1}", number++, promoLog); } //TODO Belge sonu 1,rrrrr,11,SON,mmmmmmmmmmmm,mmmmmmmmssss logWriter.Write("1,{0:D5},11,SON,", number++); if (document.Customer != null) { string code = document.Customer.Code.PadRight(20); logWriter.Write("{0},{1}", code.Substring(0, 12), code.Substring(12, 8)); } else { logWriter.Write(" , "); } logWriter.Write(document.IsOpenDocument ? " A" : " "); return(logWriter); }