public static void Print(SYS_ConfigurationPrinters pPrinter) { try { FIN_DocumentOrderTicket orderTicket = (FIN_DocumentOrderTicket)GlobalFramework.SessionXpo.GetObjectByKey(typeof(FIN_DocumentOrderTicket), SettingsApp.XpoPrintDocumentOrderTicket); //Print Document if (orderTicket != null) { //Test Print Document ThermalPrinterInternalDocumentOrderRequest thermalPrinterInternalDocumentOrderRequest = new ThermalPrinterInternalDocumentOrderRequest(pPrinter, orderTicket); thermalPrinterInternalDocumentOrderRequest.Print(); Console.WriteLine(string.Format("ThermalPrinterInternalDocumentOrderRequest Printed: {0}", orderTicket.Oid)); //Call PrintArticlePrinters PrintArticlePrinters(orderTicket); } else { Console.WriteLine(string.Format("ERROR: ThermalPrinterInternalDocumentOrderRequest NULL: {0}", orderTicket.Oid)); } } catch (Exception ex) { throw ex; } }
private static void PrintArticlePrinters(FIN_DocumentOrderTicket pOrderTicket) { //Initialize printerArticleQueue to Store Articles > Printer Queue List <SYS_ConfigurationPrinters> printerArticles = new List <SYS_ConfigurationPrinters>(); foreach (FIN_DocumentOrderDetail item in pOrderTicket.OrderDetail) { if (item.Article.Printer != null && item.Article.Printer.PrinterType.ThermalPrinter) { //Add Printer if (!printerArticles.Contains(item.Article.Printer)) { printerArticles.Add(item.Article.Printer); } } } //Print Tickets for Article Printers if (printerArticles.Count > 0) { foreach (SYS_ConfigurationPrinters item in printerArticles) { ThermalPrinterInternalDocumentOrderRequest thermalPrinterInternalDocumentOrderRequest = new ThermalPrinterInternalDocumentOrderRequest(item, pOrderTicket, true); thermalPrinterInternalDocumentOrderRequest.Print(); Console.WriteLine(string.Format("ThermalPrinterInternalDocumentOrderRequest Printed for {1}: {0}", pOrderTicket.Oid, item.Designation)); } } }
public ThermalPrinterInternalDocumentOrderRequest(SYS_ConfigurationPrinters pPrinter, FIN_DocumentOrderTicket pOrderTicket, bool pEnableArticlePrinter) : base(pPrinter) { try { //Parameters _orderTicket = pOrderTicket; _enableArticlePrinter = pEnableArticlePrinter; //Order Request #1/3 _ticketTitle = string.Format("{0} : #{1}" , Resx.global_order_request , _orderTicket.TicketId ); //Table|Order #2|Name/Zone _ticketSubTitle = string.Format("{0} : #{1}/{2}" , Resx.ResourceManager.GetString(string.Format("global_table_appmode_{0}", _appOperationModeToken).ToLower()) , _orderTicket.OrderMain.PlaceTable.Designation , _orderTicket.OrderMain.PlaceTable.Place.Designation ); } catch (Exception ex) { throw ex; } }
//Finish Order void _buttonKeyFinishOrder_Clicked(object sender, EventArgs e) { try { //Call Framework FinishOrder OrderMain orderMain = GlobalFramework.SessionApp.OrdersMain[GlobalFramework.SessionApp.CurrentOrderMainOid]; FIN_DocumentOrderTicket orderTicket = orderMain.FinishOrder(GlobalFramework.SessionXpo); // If OrderTicket and has a ThermalPrinter connected if (orderTicket != null && GlobalFramework.LoggedTerminal.Printer != null && GlobalFramework.LoggedTerminal.Printer.PrinterType.ThermalPrinter) { //public static bool PrintOrderRequest(Window pSourceWindow, SYS_ConfigurationPrinters pPrinter, OrderMain pDocumentOrderMain, FIN_DocumentOrderTicket pOrderTicket) FrameworkCalls.PrintOrderRequest(_sourceWindow, GlobalFramework.LoggedTerminal.Printer, orderMain, orderTicket); FrameworkCalls.PrintArticleRequest(_sourceWindow, orderTicket); } //Change Mode _listMode = TicketListMode.OrderMain; //Reset TicketList TotalItems Counter _listStoreModelTotalItemsTicketListMode = 0; UpdateOrderStatusBar(); UpdateModel(); } catch (Exception ex) { _log.Error(ex.Message, ex); } }
void buttonPrintOrder_Clicked(object sender, EventArgs e) { if (Utils.ShowMessageTouchRequiredValidPrinter(this)) { return; } string sql = string.Empty; OrderMain currentOrderMain = GlobalFramework.SessionApp.OrdersMain[GlobalFramework.SessionApp.CurrentOrderMainOid]; Guid orderTicketOid = new Guid(); sql = string.Format(@"SELECT COUNT(*) AS Count FROM fin_documentorderticket WHERE OrderMain = '{0}';", currentOrderMain.PersistentOid); var countTickets = GlobalFramework.SessionXpo.ExecuteScalar(sql); //If has more than one ticket show requestTicket dialog if (countTickets != null && Convert.ToInt16(countTickets) > 1) { CriteriaOperator criteria = CriteriaOperator.Parse(string.Format("OrderMain = '{0}'", currentOrderMain.PersistentOid)); PosSelectRecordDialog <XPCollection, XPGuidObject, TreeViewDocumentOrderTicket> dialog = new PosSelectRecordDialog <XPCollection, XPGuidObject, TreeViewDocumentOrderTicket>( this.SourceWindow, DialogFlags.DestroyWithParent, Resx.window_title_select_ticket, //TODO:THEME GlobalApp.MaxWindowSize, null, //XpoDefaultValue criteria, GenericTreeViewMode.Default, null //pActionAreaButtons ); int response = dialog.Run(); if (response == (int)ResponseType.Ok) { orderTicketOid = dialog.GenericTreeView.DataSourceRow.Oid; } dialog.Destroy(); } //Else Print Unique Ticket else { sql = string.Format(@"SELECT Oid FROM fin_documentorderticket WHERE OrderMain = '{0}';", currentOrderMain.PersistentOid); //_log.Debug(string.Format("sql: [{0}]", sql)); orderTicketOid = FrameworkUtils.GetGuidFromQuery(sql); } if (orderTicketOid != new Guid()) { FIN_DocumentOrderTicket orderTicket = (FIN_DocumentOrderTicket)GlobalFramework.SessionXpo.GetObjectByKey(typeof(FIN_DocumentOrderTicket), orderTicketOid); ThermalPrinterInternalDocumentOrderRequest thermalPrinterInternalDocumentOrderRequest = new ThermalPrinterInternalDocumentOrderRequest(GlobalFramework.LoggedTerminal.Printer, orderTicket); thermalPrinterInternalDocumentOrderRequest.Print(); } }
//XpoMode public TreeViewDocumentOrderTicket(Window pSourceWindow, XPGuidObject pDefaultValue, CriteriaOperator pXpoCriteria, Type pDialogType, GenericTreeViewMode pGenericTreeViewMode = GenericTreeViewMode.Default, GenericTreeViewNavigatorMode pGenericTreeViewNavigatorMode = GenericTreeViewNavigatorMode.Default) { //Init Vars Type xpoGuidObjectType = typeof(FIN_DocumentOrderTicket); //Override Default Value with Parameter Default Value, this way we can have diferent Default Values for GenericTreeView FIN_DocumentOrderTicket defaultValue = (pDefaultValue != null) ? pDefaultValue as FIN_DocumentOrderTicket : null; //Override Default DialogType with Parameter Dialog Type, this way we can have diferent DialogTypes for GenericTreeView Type typeDialogClass = (pDialogType != null) ? pDialogType : null; //Configure columnProperties List <GenericTreeViewColumnProperty> columnProperties = new List <GenericTreeViewColumnProperty>(); columnProperties.Add(new GenericTreeViewColumnProperty("TicketId") { Title = Resx.global_ticket_number, MinWidth = 50 }); columnProperties.Add(new GenericTreeViewColumnProperty("DateStart") { Title = Resx.global_date, MinWidth = 100 }); columnProperties.Add(new GenericTreeViewColumnProperty("UpdatedBy") { Title = Resx.global_user_name, ChildName = "Name", MinWidth = 100 }); columnProperties.Add(new GenericTreeViewColumnProperty("UpdatedWhere") { Title = Resx.global_terminal_name, ChildName = "Designation", MinWidth = 100 }); //Sort Order SortProperty[] sortProperty = new SortProperty[1]; sortProperty[0] = new SortProperty("TicketId", SortingDirection.Ascending); //Configure Criteria/XPCollection/Model //CriteriaOperator.Parse("Code >= 100 and Code <= 9999"); CriteriaOperator criteria = pXpoCriteria; XPCollection xpoCollection = new XPCollection(GlobalFramework.SessionXpo, xpoGuidObjectType, criteria, sortProperty); //Call Base Initializer base.InitObject( pSourceWindow, //Pass parameter defaultValue, //Pass parameter pGenericTreeViewMode, //Pass parameter pGenericTreeViewNavigatorMode, //Pass parameter columnProperties, //Created Here xpoCollection, //Created Here typeDialogClass //Created Here ); }
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //PrintArticleRequest public static bool PrintArticleRequest(Window pSourceWindow, FIN_DocumentOrderTicket pOrderTicket) { bool result = false; try { //Removed: Printer is always NULL, is defined in Ticket Article //if (SharedPrintTicket(pSourceWindow, null, TicketType.ArticleOrder)) //{ result = PrintRouter.PrintArticleRequest(pOrderTicket); //} } catch (Exception ex) { Utils.ShowMessageTouchErrorPrintingTicket(pSourceWindow, null, ex); } return(result); }
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: public static bool PrintArticleRequest(FIN_DocumentOrderTicket pOrderTicket) { bool result = false; try { //Initialize printerArticleQueue to Store Articles > Printer Queue List <SYS_ConfigurationPrinters> printerArticles = new List <SYS_ConfigurationPrinters>(); foreach (FIN_DocumentOrderDetail item in pOrderTicket.OrderDetail) { if (item.Article.Printer != null && item.Article.Printer.PrinterType.ThermalPrinter) { //Add Printer if (!printerArticles.Contains(item.Article.Printer)) { printerArticles.Add(item.Article.Printer); } } } //Print Tickets for Article Printers if (printerArticles.Count > 0) { foreach (SYS_ConfigurationPrinters item in printerArticles) { ThermalPrinterInternalDocumentOrderRequest thermalPrinterInternalDocumentOrderRequest = new ThermalPrinterInternalDocumentOrderRequest(item, pOrderTicket, true); thermalPrinterInternalDocumentOrderRequest.Print(); } } result = true; } catch (Exception ex) { _log.Warn(ex.Message, ex); throw new Exception(ex.Message); } return(result); }
public ThermalPrinterInternalDocumentOrderRequest(SYS_ConfigurationPrinters pPrinter, FIN_DocumentOrderTicket pOrderTicket) : this(pPrinter, pOrderTicket, false) { }
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //Used to Remove Articles from DocumentOrder ex when we Delete Article From TicketList.OrderMain Details public decimal DeleteFromDocumentOrder(ArticleBagKey pKey, decimal pRemoveQuantity) { bool isDone = false; decimal resultRemainQuantity = 0; string where = string.Empty; //Store Reference to Future delete Object (After foreach Loop) FIN_DocumentOrderMain deleteOrderMain = null; FIN_DocumentOrderTicket deleteOrderTicket = null; FIN_DocumentOrderDetail deleteOrderDetail = null; string articleDesignation = string.Empty; //Start UnitOfWork using (UnitOfWork uowSession = new UnitOfWork()) { OrderMain orderMain = GlobalFramework.SessionApp.OrdersMain[GlobalFramework.SessionApp.CurrentOrderMainOid]; FIN_DocumentOrderMain xDocumentOrderMain = (FIN_DocumentOrderMain)FrameworkUtils.GetXPGuidObject(uowSession, typeof(FIN_DocumentOrderMain), orderMain.PersistentOid); if (xDocumentOrderMain != null && xDocumentOrderMain.OrderTicket != null) { foreach (FIN_DocumentOrderTicket ticket in xDocumentOrderMain.OrderTicket) { foreach (FIN_DocumentOrderDetail detail in ticket.OrderDetail) { try { //Check Equal Key if (pKey.ArticleOid == detail.Article.Oid && pKey.Price == detail.Price && pKey.Discount == detail.Discount && pKey.Vat == detail.Vat) { articleDesignation = pKey.Designation; resultRemainQuantity += detail.Quantity; if (!isDone) { detail.Quantity -= pRemoveQuantity; //Assign references to Future Deletes if (detail.Quantity <= 0) { deleteOrderDetail = detail; } isDone = true; } else { where += string.Format(" OR Oid = '{0}'", detail.Oid); } } } catch (Exception ex) { _log.Error(ex.Message, ex); } } } } //Debug //string sql = @"SELECT * FROM fin_documentorderdetail WHERE 1=0{0};"; //_log.Debug(string.Format("Delete(): sql [{0}]", string.Format(sql, where))); //Audit FrameworkUtils.Audit("ORDER_ARTICLE_REMOVED", string.Format( Resx.audit_message_order_article_removed, articleDesignation, 1, resultRemainQuantity - 1, GlobalFramework.LoggedUser.Name ) ); if (isDone) { //Update xDocumentOrderMain UpdatedAt, Required for RealTime Update xDocumentOrderMain.UpdatedAt = FrameworkUtils.CurrentDateTimeAtomic(); //Remove Quantity resultRemainQuantity -= pRemoveQuantity; //Delete Records, OrderMain, OrderTicket and OrderDetails if (deleteOrderDetail != null) { deleteOrderTicket = deleteOrderDetail.OrderTicket; deleteOrderMain = deleteOrderTicket.OrderMain; //Delete Details deleteOrderDetail.Delete(); //Check if OrderTicket in Empty, If so Delete it, its not required anymore if (deleteOrderTicket.OrderDetail.Count <= 0) { deleteOrderTicket.Delete(); } ; //Check if OrderMain in Empty, If so Delete it, its not required anymore if (deleteOrderMain.OrderTicket.Count <= 0) { //Before Delete OrderMain, we must UnAssign DocumentMaster SourceOrderMain else we have a CONSTRAINT ERROR on FK_DocumentFinanceMaster_SourceOrderMain trying to delete used OrderMain string sql = string.Format(@"UPDATE fin_documentfinancemaster SET SourceOrderMain = NULL WHERE SourceOrderMain = '{0}';", deleteOrderMain.Oid); uowSession.ExecuteScalar(sql); //Open Table deleteOrderMain.PlaceTable.TableStatus = TableStatus.Free; //Audit FrameworkUtils.Audit("TABLE_OPEN", string.Format(Resx.audit_message_table_open, deleteOrderMain.PlaceTable.Designation)); //Delete OrderMain deleteOrderMain.Delete(); } ; } ; } ; try { //Commit UOW Changes uowSession.CommitChanges(); //Update OrderMain UpdatedAt, Required to Sync Terminals orderMain.UpdatedAt = FrameworkUtils.CurrentDateTimeAtomic(); //Update ArticleBag Price Properties this[pKey].Quantity = resultRemainQuantity; UpdateKeyProperties(pKey); //SEARCH#001 //Require to Remove PartialPayed Items Quantity return(resultRemainQuantity - FrameworkUtils.GetPartialPaymentPayedItems(uowSession, xDocumentOrderMain.Oid, pKey.ArticleOid)); } catch (Exception ex) { _log.Error(ex.Message, ex); uowSession.RollbackTransaction(); return(-1); } } }
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //PrintTableTicket public static bool PrintOrderRequest(Window pSourceWindow, SYS_ConfigurationPrinters pPrinter, OrderMain pDocumentOrderMain, FIN_DocumentOrderTicket pOrderTicket) { bool result = false; try { if (SharedPrintTicket(pSourceWindow, pPrinter, TicketType.TableOrder)) { ThermalPrinterInternalDocumentOrderRequest thermalPrinterInternalDocumentOrderRequest = new ThermalPrinterInternalDocumentOrderRequest(pPrinter, pOrderTicket); thermalPrinterInternalDocumentOrderRequest.Print(); } } catch (Exception ex) { Utils.ShowMessageTouchErrorPrintingTicket(pSourceWindow, pPrinter, ex); } return(result); }
public FIN_DocumentOrderTicket FinishOrder(Session pSession, bool pPrintTicket) { //Local Vars DateTime currentDateTime = DateTime.Now; FIN_DocumentOrderMain xOrderMain; Session _sessionXpo = pSession; bool isInUOW = (_sessionXpo.GetType() == typeof(UnitOfWork)); //Result FIN_DocumentOrderTicket xOrderTicket = null; //Get current Working Order from SessionApp OrderMain currentOrderMain = GlobalFramework.SessionApp.OrdersMain[GlobalFramework.SessionApp.CurrentOrderMainOid]; OrderTicket currentOrderTicket = currentOrderMain.OrderTickets[currentOrderMain.CurrentTicketId]; //Get Place Object to extract TaxSellType Normal|TakeWay POS_ConfigurationPlace configurationPlace = (POS_ConfigurationPlace)GlobalFramework.SessionXpo.GetObjectByKey(typeof(POS_ConfigurationPlace), currentOrderMain.Table.PlaceId); //Use VatDirectSelling if in Retail or in TakeWay mode TaxSellType taxSellType = (configurationPlace.MovementType.VatDirectSelling || SettingsApp.AppMode == AppOperationMode.Retail) ? TaxSellType.TakeAway : TaxSellType.Normal; //Open Table on First Finish OrderTicket POS_ConfigurationPlaceTable xTable = (POS_ConfigurationPlaceTable)FrameworkUtils.GetXPGuidObject(_sessionXpo, typeof(POS_ConfigurationPlaceTable), _table.Oid); xTable.Reload(); if (xTable.TableStatus != TableStatus.Open) { xTable.TableStatus = TableStatus.Open; FrameworkUtils.Audit("TABLE_OPEN", string.Format(Resx.audit_message_table_open, xTable.Designation)); xTable.DateTableOpen = FrameworkUtils.CurrentDateTimeAtomic(); if (!isInUOW) { xTable.Save(); } } //Get Current _persistentOid and _from Database _persistentOid = GetOpenTableFieldValueGuid(_table.Oid, "Oid"); _orderStatus = (OrderStatus)GetOpenTableFieldValue(_table.Oid, "OrderStatus"); _UpdatedAt = FrameworkUtils.CurrentDateTimeAtomic(); //Insert if (_persistentOid == Guid.Empty) { //OrderMain xOrderMain = new FIN_DocumentOrderMain(_sessionXpo) { //Always assign New date to Persistent Date DateStart = currentDateTime,//currentOrderMain.DateStart, OrderStatus = OrderStatus.Open, PlaceTable = xTable, UpdatedAt = FrameworkUtils.CurrentDateTimeAtomic() }; if (!isInUOW) { xOrderMain.Save(); } //After Save, Get Oid _persistentOid = xOrderMain.Oid; //Change to Open Status _orderStatus = OrderStatus.Open; } //Update else { xOrderMain = (FIN_DocumentOrderMain)FrameworkUtils.GetXPGuidObject(_sessionXpo, typeof(FIN_DocumentOrderMain), _persistentOid); if (xOrderMain.PlaceTable != xTable) { xOrderMain.PlaceTable = xTable; } //Force Changes in Record, else UpdatedAt dont Update xOrderMain.UpdatedAt = FrameworkUtils.CurrentDateTimeAtomic(); //TODO: Check if User was Automatically Updated //if (xOrderMain.UpdatedBy != GlobalFramework.LoggedUser) xOrderMain.UpdatedBy = GlobalFramework.LoggedUser; if (!isInUOW) { xOrderMain.Save(); } } //Create OrderTicket xOrderTicket = new FIN_DocumentOrderTicket(_sessionXpo) { TicketId = currentOrderMain.CurrentTicketId, DateStart = currentOrderTicket.DateStart, PriceType = currentOrderTicket.PriceType, Discount = xTable.Discount, OrderMain = xOrderMain, PlaceTable = xTable }; if (!isInUOW) { xOrderTicket.Save(); } //Create OrderDetail FIN_DocumentOrderDetail xOrderDetailLine; FIN_Article xArticle; uint itemOrd = 0; decimal priceTax = 0; foreach (OrderDetailLine line in currentOrderTicket.OrderDetails.Lines) { //Use Order in print tickets etc itemOrd++; xArticle = (FIN_Article)FrameworkUtils.GetXPGuidObject(_sessionXpo, typeof(FIN_Article), line.ArticleOid); //Get PriceTax from TaxSellType priceTax = (taxSellType == TaxSellType.Normal) ? xArticle.VatOnTable.Value : xArticle.VatDirectSelling.Value; xOrderDetailLine = new FIN_DocumentOrderDetail(_sessionXpo) { //Values Ord = itemOrd, Code = xArticle.Code, Designation = line.Designation, Quantity = line.Properties.Quantity, UnitMeasure = xArticle.UnitMeasure.Acronym, Price = line.Properties.PriceNet, Discount = (xArticle.Discount > 0) ? xArticle.Discount : 0.0m, TotalGross = line.Properties.TotalGross, TotalDiscount = line.Properties.TotalDiscount, TotalTax = line.Properties.TotalTax, TotalFinal = line.Properties.TotalFinal, //Use PriceTax Normal|TakeAway Vat = priceTax, //XPGuidObjects Article = xArticle, OrderTicket = xOrderTicket }; //Detect VatExemptionReason if (line.Properties.VatExemptionReason != Guid.Empty) { xOrderDetailLine.VatExemptionReason = line.Properties.VatExemptionReason; } if (!isInUOW) { xOrderDetailLine.Save(); } } ; //Clean Details and Open a New Blank Ticket in Session //Increment Terminal SessionApp CurrentTicketId _currentTicketId += 1; currentOrderMain.OrderTickets = new Dictionary <int, OrderTicket>(); currentOrderMain.OrderTickets.Add(currentOrderMain.CurrentTicketId, new OrderTicket(this, _table.PriceType)); //Finish Writing Session GlobalFramework.SessionApp.Write(); return(xOrderTicket); //Debug //_log.Debug(string.Format("FinishOrder(): xOrderMain.Oid [{0}]", xOrderMain.Oid)); //_log.Debug(string.Format("FinishOrder(): _table.OrderMainId [{0}], _currentTicketId [{1}], _table.Name [{2}]", _table.OrderMainId, _currentTicketId, _table.Name)); }