Example #1
0
        public void Add(FIN_Article pArticle, Guid pPlaceOid, Guid pTableOid, PriceType pPriceType, decimal pQuantity, FIN_ConfigurationVatExemptionReason pVatExemptionReason)
        {
            ArticleBagKey        articleBagKey;
            ArticleBagProperties articleBagProps;

            //Get Place Object to extract TaxSellType Normal|TakeWay
            POS_ConfigurationPlace configurationPlace = (POS_ConfigurationPlace)GlobalFramework.SessionXpo.GetObjectByKey(typeof(POS_ConfigurationPlace), pPlaceOid);
            TaxSellType            taxSellType        = (configurationPlace.MovementType.VatDirectSelling) ? TaxSellType.TakeAway : TaxSellType.Normal;

            PriceProperties priceProperties = FrameworkUtils.GetArticlePrice(pArticle, taxSellType);

            //Prepare articleBag Key and Props
            articleBagKey = new ArticleBagKey(
                pArticle.Oid,
                pArticle.Designation,
                priceProperties.PriceNet,
                priceProperties.DiscountArticle,
                priceProperties.Vat,
                pVatExemptionReason.Oid
                );
            articleBagProps = new ArticleBagProperties(
                pPlaceOid,
                pTableOid,
                pPriceType,
                pArticle.Code,
                pQuantity,
                pArticle.UnitMeasure.Acronym
                );

            //Send to Bag
            Add(articleBagKey, articleBagProps);
        }
Example #2
0
        //XpoMode
        public TreeViewConfigurationPlace(Window pSourceWindow, XPGuidObject pDefaultValue, CriteriaOperator pXpoCriteria, Type pDialogType, GenericTreeViewMode pGenericTreeViewMode = GenericTreeViewMode.Default, GenericTreeViewNavigatorMode pGenericTreeViewNavigatorMode = GenericTreeViewNavigatorMode.Default)
        {
            //Init Vars
            Type xpoGuidObjectType = typeof(POS_ConfigurationPlace);
            //Override Default Value with Parameter Default Value, this way we can have diferent Default Values for GenericTreeView
            POS_ConfigurationPlace defaultValue = (pDefaultValue != null) ? pDefaultValue as POS_ConfigurationPlace : null;
            //Override Default DialogType with Parameter Dialog Type, this way we can have diferent DialogTypes for GenericTreeView
            Type typeDialogClass = (pDialogType != null) ? pDialogType : typeof(DialogConfigurationPlace);

            //Configure columnProperties
            List <GenericTreeViewColumnProperty> columnProperties = new List <GenericTreeViewColumnProperty>();

            columnProperties.Add(new GenericTreeViewColumnProperty("Code")
            {
                Title = Resx.global_record_code, MinWidth = 100
            });
            columnProperties.Add(new GenericTreeViewColumnProperty("Designation")
            {
                Title = Resx.global_designation, Expand = true
            });
            columnProperties.Add(new GenericTreeViewColumnProperty("PriceType")
            {
                Title = Resx.global_ConfigurationPlace_PriceType, ChildName = "Designation"
            });
            columnProperties.Add(new GenericTreeViewColumnProperty("MovementType")
            {
                Title = Resx.global_ConfigurationPlace_MovementType, ChildName = "Designation"
            });
            columnProperties.Add(new GenericTreeViewColumnProperty("UpdatedAt")
            {
                Title = Resx.global_record_date_updated, MinWidth = 150, MaxWidth = 150
            });

            //Configure Criteria/XPCollection/Model
            //CriteriaOperator.Parse("Code >= 100 and Code <= 9999");
            CriteriaOperator criteria      = pXpoCriteria;
            XPCollection     xpoCollection = new XPCollection(GlobalFramework.SessionXpo, xpoGuidObjectType, criteria);

            //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
                );
        }
Example #3
0
        private bool PersistFinanceDocuments()
        {
            bool debug        = false;
            int  padLeftChars = 10;

            try
            {
                int i = 0;
                foreach (TouchButtonSplitPayment item in _splitPaymentButtons)
                {
                    i++;
                    // If have
                    if (item.ProcessFinanceDocumentParameter != null)
                    {
                        if (debug)
                        {
                            _log.Debug(string.Format("TotalFinal: [#{0}]:[{1}]", i,
                                                     FrameworkUtils.DecimalToStringCurrency(item.ProcessFinanceDocumentParameter.ArticleBag.TotalFinal).PadLeft(padLeftChars, ' ')
                                                     ));
                        }

                        // PersistFinanceDocument
                        item.DocumentFinanceMaster = FrameworkCalls.PersistFinanceDocument(this, item.ProcessFinanceDocumentParameter);
                        //Update Display
                        if (item.DocumentFinanceMaster != null)
                        {
                            FIN_ConfigurationPaymentMethod paymentMethod = (FIN_ConfigurationPaymentMethod)FrameworkUtils.GetXPGuidObject(typeof(FIN_ConfigurationPaymentMethod), item.ProcessFinanceDocumentParameter.PaymentMethod);
                            if (GlobalApp.UsbDisplay != null)
                            {
                                GlobalApp.UsbDisplay.ShowPayment(paymentMethod.Designation, item.ProcessFinanceDocumentParameter.TotalDelivery, item.ProcessFinanceDocumentParameter.TotalChange);
                            }
                        }
                    }
                }

                //If has Working Order
                if (
                    GlobalFramework.SessionApp.OrdersMain != null &&
                    GlobalFramework.SessionApp.CurrentOrderMainOid != null &&
                    GlobalFramework.SessionApp.OrdersMain.ContainsKey(GlobalFramework.SessionApp.CurrentOrderMainOid)
                    )
                {
                    // Get Current working orderMain
                    OrderMain currentOrderMain = GlobalFramework.SessionApp.OrdersMain[GlobalFramework.SessionApp.CurrentOrderMainOid];
                    if (debug)
                    {
                        _log.Debug(string.Format("Working on currentOrderMain.PersistentOid: [{0}]", currentOrderMain.PersistentOid));
                    }
                    //Get OrderDetail
                    OrderDetail currentOrderDetails = currentOrderMain.OrderTickets[currentOrderMain.CurrentTicketId].OrderDetails;

                    // Get configurationPlace to get Tax
                    POS_ConfigurationPlace configurationPlace = (POS_ConfigurationPlace)GlobalFramework.SessionXpo.GetObjectByKey(typeof(POS_ConfigurationPlace), currentOrderMain.Table.PlaceId);
                }

                return(true);
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
                return(false);
            }
        }
Example #4
0
        private void CalculateTotalPerSplit(ArticleBag articleBag, int numberOfSplits)
        {
            bool debug = false;

            // Calculate final Total Pay per Split
            _totalPerSplit = articleBag.TotalFinal / numberOfSplits;

            try
            {
                // Always Init ArticleBags
                foreach (TouchButtonSplitPayment item in _splitPaymentButtons)
                {
                    item.ArticleBag = new ArticleBag();
                }

                // Init Object to Use priceTax on above Loop
                //Get Place Objects to extract TaxSellType Normal|TakeWay, Place, Tables etc
                OrderMain currentOrderMain = GlobalFramework.SessionApp.OrdersMain[GlobalFramework.SessionApp.CurrentOrderMainOid];
                POS_ConfigurationPlace configurationPlace = (POS_ConfigurationPlace)GlobalFramework.SessionXpo.GetObjectByKey(typeof(POS_ConfigurationPlace), currentOrderMain.Table.PlaceId);

                // Loop articleBag, and Add the quantity for Each Split (Total Article Quantity / numberOfSplits)
                foreach (var article in articleBag)
                {
                    // Default quantity to add to all Splitters, last one gets the extra Remains ex 0,0000000000001
                    decimal articleQuantity = (article.Value.Quantity / numberOfSplits);
                    // Store Remain Quantity
                    decimal articleQuantityRemain = article.Value.Quantity;
                    // Check if Total is equal to Origin
                    decimal articleQuantityCheck       = 0.0m;
                    decimal articleQuantityCheckModulo = 0.0m;
                    // Reset t
                    int t = 0;
                    foreach (TouchButtonSplitPayment touchButtonSplitPayment in _splitPaymentButtons)
                    {
                        t++;
                        // Discount articleQuantityRemain
                        articleQuantityRemain = articleQuantityRemain - articleQuantity;
                        if (t.Equals(_splitPaymentButtons.Count))
                        {
                            // Override Default split Quantity, adding extra Remain
                            articleQuantity += articleQuantityRemain;
                        }

                        // Add to articleQuantityCheck
                        articleQuantityCheck += articleQuantity;
                        // Modulo
                        articleQuantityCheckModulo = article.Value.Quantity % articleQuantityCheck;

                        if (debug)
                        {
                            _log.Debug(string.Format("#{0} Designation: [{1}], PriceFinal: [{2}], Quantity: [{3}]:[{4}]:[{5}]:[{6}]:[{7}]",
                                                     t, article.Key.Designation, article.Value.PriceFinal, article.Value.Quantity, articleQuantity, articleQuantityRemain, articleQuantityCheck, articleQuantityCheckModulo)
                                       );
                        }

                        // ArticleBagKey
                        ArticleBagKey articleBagKey = new ArticleBagKey(
                            article.Key.ArticleOid,
                            article.Key.Designation,
                            article.Key.Price,
                            article.Key.Discount,
                            article.Key.Vat
                            );
                        //Detect and Assign VatExemptionReason to ArticleBak Key
                        if (article.Key.VatExemptionReasonOid != null && article.Key.VatExemptionReasonOid != Guid.Empty)
                        {
                            articleBagKey.VatExemptionReasonOid = article.Key.VatExemptionReasonOid;
                        }
                        // ArticleBagProperties
                        ArticleBagProperties articleBagProps = articleBagProps = new ArticleBagProperties(
                            configurationPlace.Oid,
                            currentOrderMain.Table.Oid,
                            (PriceType)configurationPlace.PriceType.EnumValue,
                            article.Value.Code,
                            articleQuantity,
                            article.Value.UnitMeasure
                            );

                        // Add to ArticleBag
                        touchButtonSplitPayment.ArticleBag.Add(articleBagKey, articleBagProps);
                    }
                }

                // After have all splitPaymentButtons ArticleBags (End of arraySplit.Count Loop)
                foreach (TouchButtonSplitPayment item in _splitPaymentButtons)
                {
                    // Require to Update ProcessFinanceDocumentParameter, like when we Close Payment Window, BEFORE UpdateTouchButtonSplitPaymentLabels
                    // This is to Update UI when we Add/Remove Splits, else Already filled Payments dont Update
                    // Only change ArticleBag
                    if (item.ProcessFinanceDocumentParameter != null)
                    {
                        FIN_ConfigurationPaymentMethod paymentMethod = (FIN_ConfigurationPaymentMethod)FrameworkUtils.GetXPGuidObject(typeof(FIN_ConfigurationPaymentMethod), item.ProcessFinanceDocumentParameter.PaymentMethod);
                        decimal totalDelivery = (paymentMethod.Token.Equals("MONEY"))
                            ? item.ProcessFinanceDocumentParameter.TotalDelivery
                            : item.ArticleBag.TotalFinal;

                        item.ProcessFinanceDocumentParameter = new ProcessFinanceDocumentParameter(
                            item.ProcessFinanceDocumentParameter.DocumentType, item.ArticleBag
                            )
                        {
                            PaymentMethod    = item.ProcessFinanceDocumentParameter.PaymentMethod,
                            PaymentCondition = item.ProcessFinanceDocumentParameter.PaymentCondition,
                            Customer         = item.ProcessFinanceDocumentParameter.Customer,
                            TotalDelivery    = totalDelivery,
                            // Require to Recalculate TotalChange
                            TotalChange = totalDelivery - item.ArticleBag.TotalFinal
                        };
                    }

                    // Always Update all Buttons, with and without ProcessFinanceDocumentParameter
                    UpdateTouchButtonSplitPaymentLabels(item);

                    // Update Window Title
                    //if (WindowTitle != null) WindowTitle = string.Format(Resx.window_title_dialog_split_payment, numberOfSplits, FrameworkUtils.DecimalToStringCurrency(totalFinal));
                    if (WindowTitle != null)
                    {
                        WindowTitle = string.Format(Resx.window_title_dialog_split_payment, numberOfSplits, FrameworkUtils.DecimalToStringCurrency(_totalPerSplit));
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
            }
        }
Example #5
0
        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));
        }