예제 #1
0
        public ArticleBag GetArticleBag()
        {
            Decimal                             customerDiscount = FrameworkUtils.StringToDecimal(_pagePad2.EntryBoxCustomerDiscount.EntryValidation.Text);
            ArticleBag                          articleBag       = new ArticleBag(customerDiscount);
            ArticleBagKey                       articleBagKey;
            ArticleBagProperties                articleBagProps;
            FIN_Article                         article;
            FIN_ConfigurationVatRate            configurationVatRate;
            FIN_ConfigurationVatExemptionReason configurationVatExemptionReason;

            //DocumentParent/SourceDocument
            FIN_DocumentFinanceMaster sourceFinanceMaster = null;
            string referencesReason = string.Empty;

            if (
                _pagePad1.EntryBoxSelectDocumentFinanceType.Value.Oid == SettingsApp.XpoOidDocumentFinanceTypeCreditNote &&
                _pagePad1.EntryBoxSelectSourceDocumentFinance.Value != null &&
                _pagePad1.EntryBoxSelectSourceDocumentFinance.Value.Oid != new Guid()
                )
            {
                Guid guidDocumentParent = _pagePad1.EntryBoxSelectSourceDocumentFinance.Value.Oid;
                //Get Source Document
                sourceFinanceMaster = (FIN_DocumentFinanceMaster)GlobalFramework.SessionXpo.GetObjectByKey(typeof(FIN_DocumentFinanceMaster), guidDocumentParent);
                referencesReason    = _pagePad1.EntryBoxReason.EntryValidation.Text;
            }
            ;

            foreach (DataRow item in _pagePad3.TreeViewArticles.DataSource.Rows)
            {
                article = (item["Article.Code"] as FIN_Article);
                configurationVatRate            = (item["ConfigurationVatRate.Value"] as FIN_ConfigurationVatRate);
                configurationVatExemptionReason = (item["VatExemptionReason.Acronym"] as FIN_ConfigurationVatExemptionReason);

                //Prepare articleBag Key and Props
                articleBagKey = new ArticleBagKey(
                    new Guid(item["Oid"].ToString()),
                    article.Designation,
                    Convert.ToDecimal(item["Price"]),   //Always use Price in DefaultCurrency
                    Convert.ToDecimal(item["Discount"]),
                    configurationVatRate.Value,
                    //If has a Valid ConfigurationVatExemptionReason use it Else send New Guid
                    (configurationVatExemptionReason != null) ? configurationVatExemptionReason.Oid : new Guid()
                    );
                articleBagProps = new ArticleBagProperties(
                    new Guid(),       //pPlaceOid,
                    new Guid(),       //pTableOid,
                    PriceType.Price1, //pPriceType,
                    article.Code,
                    Convert.ToDecimal(item["Quantity"]),
                    article.UnitMeasure.Acronym
                    );

                // Notes
                if (!string.IsNullOrEmpty(item["Notes"].ToString()))
                {
                    articleBagProps.Notes = item["Notes"].ToString();
                }

                //Assign DocumentMaster Reference and Reason to ArticleBag item
                if (sourceFinanceMaster != null)
                {
                    articleBagProps.Reference = sourceFinanceMaster;
                    articleBagProps.Reason    = referencesReason;
                }

                articleBag.Add(articleBagKey, articleBagProps);
            }

            return(articleBag);
        }
예제 #2
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(resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "window_title_dialog_split_payment, numberOfSplits, FrameworkUtils.DecimalToStringCurrency(totalFinal));
                    if (WindowTitle != null)
                    {
                        WindowTitle = string.Format(resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "window_title_dialog_split_payment"), numberOfSplits, FrameworkUtils.DecimalToStringCurrency(_totalPerSplit));
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
            }
        }
예제 #3
0
        public static ArticleBag GetArticleBag(bool pForceErrors)
        {
            ArticleBag           articleBag = new ArticleBag(10);
            Guid                 xpoOidConfigurationPlaceDefault = new Guid(GlobalFramework.Settings["xpoOidConfigurationPlaceDefault"]);
            Guid                 xpoOidConfigurationPlaceTableDefaultOpenTable = new Guid(GlobalFramework.Settings["xpoOidConfigurationPlaceTableDefaultOpenTable"]);
            ArticleBagKey        articleBagKey;
            ArticleBagProperties articleBagProps;

            Dictionary <Guid, decimal> mockArticles = new Dictionary <Guid, decimal>();

            //P:Products
            mockArticles.Add(new Guid("133cc225-517d-4c24-88b0-cd7c08cf5727"), 2.0m);
            mockArticles.Add(new Guid("4c47be72-6174-4e63-a077-f3cdb6a15e97"), 3.0m);
            mockArticles.Add(new Guid("0f32da9c-e533-489d-8a46-d6da79fd63a0"), 3.0m);
            mockArticles.Add(new Guid("6b547918-769e-4f5b-bcd6-01af54846f73"), 4.0m);
            mockArticles.Add(new Guid("42cd7f86-97b2-44f4-b098-3c9f0ae9f4b5"), 5.0m);
            mockArticles.Add(new Guid("55892c3f-de10-4076-afde-619c54100c9b"), 6.0m);
            mockArticles.Add(new Guid("fc109711-edb0-41dc-87b6-0acb77abd341"), 7.0m);
            mockArticles.Add(new Guid("bf99351b-1556-43c4-a85c-90082fb02d05"), 8.0m);
            mockArticles.Add(new Guid("11062ec9-fed0-43eb-a23e-c6f7ed83ff72"), 9.0m);
            mockArticles.Add(new Guid("32deb30d-ffa2-45e4-bca6-03569b9e8b08"), 2.0m);
            mockArticles.Add(new Guid("78638720-e728-4e96-8643-6d6267ff817b"), 2.0m);
            mockArticles.Add(new Guid("42c327e2-4aad-41ea-b5b6-e2198c337f1c"), 3.0m);
            mockArticles.Add(new Guid("0d30bf31-ecc4-452e-9b43-ee9d5c1d7fb6"), 4.0m);
            mockArticles.Add(new Guid("7b45a01d-50ee-42d3-a4af-0dcde9397e93"), 5.0m);
            mockArticles.Add(new Guid("630ff869-e433-46bb-a53b-563c43535424"), 6.0m);
            mockArticles.Add(new Guid("f71b3648-bb41-4952-ac75-ee93ccf0ec66"), 7.0m);
            mockArticles.Add(new Guid("87ff6f3a-c858-4829-bbcb-c6ea395129da"), 8.0m);
            mockArticles.Add(new Guid("72e8bde8-d03b-4637-90f1-fcb265658af0"), 9.0m);
            //S:Services
            mockArticles.Add(new Guid("5a852060-43b9-4e71-a230-b733bb150427"), 3.0m);
            mockArticles.Add(new Guid("072db1bf-6182-43de-8065-d4bbd8c9f8c2"), 4.0m);

            foreach (var item in mockArticles)
            {
                fin_article article = (fin_article)FrameworkUtils.GetXPGuidObject(GlobalFramework.SessionXpo, typeof(fin_article), item.Key);

                articleBagKey = new ArticleBagKey(
                    article.Oid,
                    article.Designation,
                    article.Price1,
                    article.Discount,
                    article.VatOnTable.Value
                    );
                articleBagProps = new ArticleBagProperties(
                    xpoOidConfigurationPlaceDefault,
                    xpoOidConfigurationPlaceTableDefaultOpenTable,
                    PriceType.Price1,
                    article.Code,
                    item.Value,
                    article.UnitMeasure.Acronym
                    );

                if (!pForceErrors)
                {
                    //Detect and Add TaxExceptionReason if Miss to Prevent Errors
                    if (articleBagKey.Vat == 0.0m && articleBagKey.VatExemptionReasonOid == Guid.Empty)
                    {
                        articleBagKey.VatExemptionReasonOid = SettingsApp.XpoOidConfigurationVatExemptionReasonM99;
                    }

                    //Add Price to Services, else we have Error with Price 0
                    if (article.Class.Acronym == "S")
                    {
                        articleBagKey.Price = 10.28m;
                    }
                }

                //Send to Bag
                articleBag.Add(articleBagKey, articleBagProps);
            }

            if (pForceErrors)
            {
                //Add Error Article after Loop
                articleBagKey = new ArticleBagKey(
                    Guid.Empty, //Oid
                    "§",        //Designation
                    -1,         //Price
                    101,        //Discount
                    0           //VatOnTable
                    );
                articleBagProps = new ArticleBagProperties(
                    xpoOidConfigurationPlaceDefault,
                    xpoOidConfigurationPlaceTableDefaultOpenTable,
                    PriceType.Price1,
                    string.Empty,   //Code
                    -1,             //Quantity
                    "§"             //UnitMeasure.Acronym
                    );
                //Add Error Article
                articleBag.Add(articleBagKey, articleBagProps);
                //Assign Error after add To ArticleBag
                articleBagKey.Vat = -1;
            }

            return(articleBag);
        }