Esempio n. 1
0
        public EditNewPriceRule(PriceRule priceRule)
        {
            this.priceRule = priceRule;
            priority       = priceRule.Priority;

            Initialize();
        }
Esempio n. 2
0
        /// <summary>
        /// 获取表单字段的html
        /// </summary>
        public string Build(FormField field, IDictionary <string, string> htmlAttributes)
        {
            var attribute       = (LogisticsPriceRulesEditorAttribute)field.Attribute;
            var configManager   = Application.Ioc.Resolve <GenericConfigManager>();
            var regionSettings  = configManager.GetData <RegionSettings>();
            var templateManager = Application.Ioc.Resolve <TemplateManager>();
            var translations    = new Dictionary <string, string>()
            {
                { "Default", new T("Default") },
                { "Region", new T("Region") },
                { "FirstHeavyUnit(g)", new T("FirstHeavyUnit(g)") },
                { "FirstHeavyCost", new T("FirstHeavyCost") },
                { "ContinuedHeavyUnit(g)", new T("ContinuedHeavyUnit(g)") },
                { "ContinuedHeavyCost", new T("ContinuedHeavyCost") },
                { "Currency", new T("Currency") },
                { "Disabled", new T("Disabled") }
            };

            return(templateManager.RenderTemplate("shopping.logistics/tmpl.price_rules_editor.html", new {
                name = field.Attribute.Name,
                value = JsonConvert.SerializeObject(field.Value),
                attributes = htmlAttributes,
                displayCountryDropdown = JsonConvert.SerializeObject(
                    attribute.DisplayCountryDropdown ?? regionSettings.DisplayCountryDropdown),
                currencyListItems = JsonConvert.SerializeObject(
                    new CurrencyListItemProvider().GetItems().ToList()),
                defaultPriceRule = JsonConvert.SerializeObject(PriceRule.GetDefault()),
                translations = JsonConvert.SerializeObject(translations)
            }));
        }
        private static PriceRule readRBForm(string Root, string[] sizes)
        {
            string lowNum  = "0";
            string highNum = "0";

            try
            {
                if (!String.IsNullOrEmpty(sizes[0].ToString()))
                {
                    lowNum = CleanNumbers(CleanString(sizes[0].ToString()));
                }
                if (sizes.Length > 1)
                {
                    if (!String.IsNullOrEmpty(sizes[1].ToString()))
                    {
                        highNum = CleanNumbers(CleanString(sizes[1].ToString()));
                    }
                }

                return(PriceRule.getRBRule("RB", lowNum, highNum));
            }
            catch
            {
                return(PriceRule.getRBRule("RB", lowNum, highNum));
            }
        }
Esempio n. 4
0
        protected virtual void ApplyFinalPriceRules()
        {
            if (editMode)
            {
                return;
            }

            PriceRule.ApplyOnOperationSaved(operation, PriceRules);
            PriceRule.ApplyAfterOperationSaved(operation, PriceRules);
        }
Esempio n. 5
0
 public ActionResult Edit([Bind(Include = "PriceRuleId,RuleNumber,PlantType,Description,MinUnitValue,MaxUnitValue")] PriceRule priceRule)
 {
     if (ModelState.IsValid)
     {
         db.UpdateRulePrices(priceRule);
         db.SaveRule();
         return(RedirectToAction("Index"));
     }
     return(View(priceRule));
 }
Esempio n. 6
0
        private async Task <PriceRuleDiscountCode> CreateDiscountCode(PriceRule rule, PriceRuleDiscountCode discountCode, bool skipAddToCreatedList)
        {
            var obj = await DiscountCodeService.CreateAsync(rule.Id.Value, discountCode);

            if (!skipAddToCreatedList)
            {
                CreatedDiscountCodes.Add(obj);
            }

            return(obj);
        }
Esempio n. 7
0
        private async Task <PriceRule> CreatePriceRule(PriceRule rule, bool skipAddToCreatedList)
        {
            var obj = await PriceRuleService.CreateAsync(rule);

            if (!skipAddToCreatedList)
            {
                CreatedPriceRules.Add(obj);
            }

            return(obj);
        }
Esempio n. 8
0
        public ServiceResult DeletePriceRule(PriceRule PriceRule)
        {
            if (PriceRule == null || string.IsNullOrWhiteSpace(PriceRule.UUID))
            {
                return(ServiceResponse.Error("Invalid account was sent."));
            }

            PriceManager financeManager = new PriceManager(Globals.DBConnectionKey, this.GetAuthToken(Request));

            return(financeManager.Delete(PriceRule));
        }
Esempio n. 9
0
        public ServiceResult DeletePriceRule(PriceRule PriceRule)
        {
            if (PriceRule == null || string.IsNullOrWhiteSpace(PriceRule.UUID))
            {
                return(ServiceResponse.Error("Invalid account was sent."));
            }

            PriceManager financeManager = new PriceManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);

            return(financeManager.Delete(PriceRule));
        }
Esempio n. 10
0
        public ServiceResult Insert(PriceRule PriceRule)
        {
            if (PriceRule == null || string.IsNullOrWhiteSpace(PriceRule.Name))
            {
                return(ServiceResponse.Error("Invalid PriceRule sent to server."));
            }

            string authToken = Request.Headers?.Authorization?.Parameter;

            UserSession us = SessionManager.GetSession(authToken);

            if (us == null)
            {
                return(ServiceResponse.Error("You must be logged in to access this function."));
            }

            if (string.IsNullOrWhiteSpace(us.UserData))
            {
                return(ServiceResponse.Error("Couldn't retrieve user data."));
            }

            if (CurrentUser == null)
            {
                return(ServiceResponse.Error("You must be logged in to access this function."));
            }


            if (string.IsNullOrWhiteSpace(PriceRule.AccountUUID) || PriceRule.AccountUUID == SystemFlag.Default.Account)
            {
                PriceRule.AccountUUID = CurrentUser.AccountUUID;
            }

            if (string.IsNullOrWhiteSpace(PriceRule.CreatedBy))
            {
                PriceRule.CreatedBy = CurrentUser.UUID;
            }

            if (PriceRule.DateCreated == DateTime.MinValue)
            {
                PriceRule.DateCreated = DateTime.UtcNow;
            }

            if (string.IsNullOrWhiteSpace(PriceRule.Image))
            {
                PriceRule.Image = "/Content/Default/Images/PriceRule/default.png";
            }

            PriceManager financeManager = new PriceManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);

            return(financeManager.Insert(PriceRule, false));
        }
Esempio n. 11
0
        //// GET: PriceRules/Create
        //public ActionResult Create()
        //{
        //    return View();
        //}

        //// POST: PriceRules/Create
        //// To protect from overposting attacks, enable the specific properties you want to bind to, for
        //// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        //public ActionResult Create([Bind(Include = "PriceRuleId,RuleNumber,PlantType,Description,MinUnitValue,MaxUnitValue")] PriceRule priceRule)
        //{
        //    if (ModelState.IsValid)
        //    {
        //        db.PriceRules.Add(priceRule);
        //        db.SaveChanges();
        //        return RedirectToAction("Index");
        //    }

        //    return View(priceRule);
        //}

        // GET: PriceRules/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PriceRule priceRule = db.GetPriceRuleById(Convert.ToInt32(id));

            if (priceRule == null)
            {
                return(HttpNotFound());
            }
            return(View(priceRule));
        }
Esempio n. 12
0
        private async Task <PriceRule> CreatePriceRule(bool skipAddToCreatedList)
        {
            var priceRule = new PriceRule()
            {
                Title             = "UNIT TEST",
                ValueType         = "percentage",
                Value             = -30,
                TargetType        = "line_item",
                TargetSelection   = "all",
                AllocationMethod  = "across",
                StartsAt          = DateTime.Now,
                CustomerSelection = "all"
            };

            return(await CreatePriceRule(priceRule, skipAddToCreatedList));
        }
Esempio n. 13
0
        public ServiceResult DeletePriceRuleBy(string uuid)
        {
            if (string.IsNullOrWhiteSpace(uuid))
            {
                return(ServiceResponse.Error("Invalid id."));
            }

            PriceManager fm = new PriceManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);
            PriceRule    c  = (PriceRule )fm.GetBy(uuid);

            if (c == null)
            {
                return(ServiceResponse.Error("Invalid uuid"));
            }

            return(fm.Delete(c));
        }
Esempio n. 14
0
        /// <summary>
        /// This was created for use in the bulk process..
        ///
        /// </summary>
        /// <param name="p"></param>
        /// <param name="checkName">This will check the products by name to see if they exist already. If it does an error message will be returned.</param>
        /// <returns></returns>
        public ServiceResult Insert(INode n, bool validateFirst = true)
        {
            if (!this.DataAccessAuthorized(n, "POST", false))
            {
                return(ServiceResponse.Error("You are not authorized this action."));
            }

            n.Initialize(this._requestingUser.UUID, this._requestingUser.AccountUUID, this._requestingUser.RoleWeight);

            var p = (PriceRule)n;

            if (validateFirst)
            {
                PriceRule dbU = (PriceRule)Get(p.Name);

                if (dbU != null)
                {
                    return(ServiceResponse.Error("PriceRule already exists."));
                }

                if (string.IsNullOrWhiteSpace(p.CreatedBy))
                {
                    return(ServiceResponse.Error("You must assign who the product was created by."));
                }

                if (string.IsNullOrWhiteSpace(p.AccountUUID))
                {
                    return(ServiceResponse.Error("The account id is empty."));
                }
            }

            if (p.Expires == DateTime.MinValue)
            {
                p.Expires = DateTime.UtcNow.AddYears(200);
            }

            using (var context = new TreeMonDbContext(this._connectionKey))
            {
                if (context.Insert <PriceRule>(p))
                {
                    return(ServiceResponse.OK("", p));
                }
            }
            return(ServiceResponse.Error("An error occurred inserting product " + p.Name));
        }
Esempio n. 15
0
        public ServiceResult GetPriceRule(string PriceRuleCode)
        {
            if (string.IsNullOrWhiteSpace(PriceRuleCode))
            {
                return(ServiceResponse.Error("You must provide a name for the strain."));
            }

            PriceManager financeManager = new PriceManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);

            PriceRule s = financeManager.GetPriceRuleByCode(PriceRuleCode);

            if (s == null)
            {
                return(ServiceResponse.Error("Invalid code " + PriceRuleCode));
            }

            return(ServiceResponse.OK("", s));
        }
Esempio n. 16
0
        public ServiceResult GetPriceRule(string PriceRuleCode)
        {
            if (string.IsNullOrWhiteSpace(PriceRuleCode))
            {
                return(ServiceResponse.Error("You must provide a code for the rule."));
            }

            PriceManager financeManager = new PriceManager(Globals.DBConnectionKey, this.GetAuthToken(Request));

            PriceRule s = financeManager.GetPriceRuleByCode(PriceRuleCode);

            if (s == null)
            {
                return(ServiceResponse.Error("Invalid code " + PriceRuleCode));
            }

            return(ServiceResponse.OK("", s));
        }
Esempio n. 17
0
        /// <summary>
        /// This can be replaced by Database call
        /// </summary>
        /// <returns></returns>
        public IEnumerable <PriceRule> GetPricingRules()
        {
            var result = new List <PriceRule>();

            // 3 for 2 deal on Apple TV
            var ruleAppleTV = new PriceRule
            {
                Sku       = "atv",
                Condition = new PriceRuleCondition {
                    BuyAndGetUnitDeal = 2
                },
                Result = new PriceRuleResult {
                    FreeSku = "atv", FreeSkuUnit = 1
                }
            };

            result.Add(ruleAppleTV);

            // Nexus 9 Bulk Discount if more than 4 - 499.99 each
            var ruleNexus = new PriceRule
            {
                Sku       = "nx9",
                Condition = new PriceRuleCondition {
                    TargetSkuCountExpression = "> 4"
                },
                Result = new PriceRuleResult {
                    Price = 499.99m
                }
            };

            result.Add(ruleNexus);

            // HDMI adapter bundled free with every MacBook pro
            var ruleMacbookPro = new PriceRule
            {
                Sku    = "mbp",
                Result = new PriceRuleResult {
                    FreeSku = "hdm", FreeSkuUnit = 1
                }
            };

            result.Add(ruleMacbookPro);
            return(result);
        }
Esempio n. 18
0
 private void InitializeEntries()
 {
     if (priceRule == null)
     {
         priceRule = new PriceRule();
     }
     else
     {
         txtName.Text = priceRule.Name;
         foreach (PriceRuleCondition condition in priceRule.Conditions)
         {
             TreeView treeView = condition.IsException ? treeViewExceptions : treeViewConditions;
             TreeIter row      = MarkIndication((int)condition.Type, treeView);
             treeView.Model.SetValue(row, 2, condition.ToString());
             if (condition.Error)
             {
                 treeView.Model.SetValue(row, 3, "red");
             }
         }
         foreach (PriceRuleAction action in priceRule.Actions)
         {
             TreeIter row = MarkIndication((int)action.Type, treeViewActions);
             treeViewActions.Model.SetValue(row, 2, action.ToString());
             if (action.Error)
             {
                 treeViewActions.Model.SetValue(row, 3, "red");
             }
         }
         foreach (OperationType operationType in priceRule.Operations)
         {
             OperationType type = operationType;
             treeViewOperations.Model.Foreach((model, path, row) =>
             {
                 if ((OperationType)model.GetValue(row, 2) == type)
                 {
                     model.SetValue(row, 0, true);
                 }
                 return(false);
             });
         }
         chkActive.Active = priceRule.Enabled;
         RefreshPreview();
     }
 }
Esempio n. 19
0
        protected override void SetDate(DateTime d)
        {
            bool dateChanged = !initialDate && date != d;

            initialDate = false;
            base.SetDate(d);

            if (!editMode && dateChanged)
            {
                PriceRule.ReapplyOnDateChanged(operation, (s, action) =>
                {
                    using (Message message = new Message(Translator.GetString("Price Rules"), string.Empty, s, "Icons.Question32.png")) {
                        message.Buttons = MessageButtons.YesNo;
                        if (message.Run() == ResponseType.Yes)
                        {
                            action();
                        }
                    }
                }, PriceRules);
            }
        }
Esempio n. 20
0
        public ServiceResult Update(PriceRule fat)
        {
            if (fat == null)
            {
                return(ServiceResponse.Error("Invalid PriceRule sent to server."));
            }

            PriceManager financeManager = new PriceManager(Globals.DBConnectionKey, Request.Headers?.Authorization?.Parameter);

            var dbS = (PriceRule)financeManager.GetBy(fat.UUID);

            if (dbS == null)
            {
                return(ServiceResponse.Error("PriceRule was not found."));
            }

            if (dbS.DateCreated == DateTime.MinValue)
            {
                dbS.DateCreated = DateTime.UtcNow;
            }

            dbS.Name = fat.Name;

            dbS.Image         = fat.Image;
            dbS.Deleted       = fat.Deleted;
            dbS.Status        = fat.Status;
            dbS.SortOrder     = fat.SortOrder;
            dbS.Expires       = fat.Expires;
            dbS.ReferenceType = fat.ReferenceType;
            dbS.Code          = fat.Code;
            dbS.Operand       = fat.Operand;
            dbS.Operator      = fat.Operator;
            dbS.Minimum       = fat.Minimum;
            dbS.Maximum       = fat.Maximum;
            dbS.Mandatory     = fat.Mandatory;
            dbS.MaxUseCount   = fat.MaxUseCount;

            return(financeManager.Update(dbS));
        }
Esempio n. 21
0
        protected override void SetLocation(Location newLocation)
        {
            bool locationChanged = (!initialLocation && location == null && newLocation != null) ||
                                   (location != null && newLocation != null && location.Id != newLocation.Id);

            initialLocation = false;
            base.SetLocation(newLocation);

            if (!editMode && locationChanged)
            {
                PriceRule.ReapplyOnLocationChanged(operation, (s, action) =>
                {
                    using (Message message = new Message(Translator.GetString("Price Rules"), string.Empty, s, "Icons.Question32.png")) {
                        message.Buttons = MessageButtons.YesNo;
                        if (message.Run() == ResponseType.Yes)
                        {
                            action();
                        }
                    }
                }, PriceRules);
            }
        }
Esempio n. 22
0
        protected override void SetPartner(Partner p)
        {
            bool partnerChanged = (!initialPartner && partner == null && p != null) ||
                                  (partner != null && p != null && partner.Id != p.Id);

            initialPartner = false;
            base.SetPartner(p);

            if (!editMode && partnerChanged)
            {
                PriceRule.ReapplyOnPartnerChanged(operation, (s, action) =>
                {
                    using (Message message = new Message(Translator.GetString("Price Rules"), string.Empty, s, "Icons.Question32.png")) {
                        message.Buttons = MessageButtons.YesNo;
                        if (message.Run() == ResponseType.Yes)
                        {
                            action();
                        }
                    }
                }, PriceRules);
            }
        }
Esempio n. 23
0
        public ServiceResult Update(PriceRule fat)
        {
            if (fat == null)
            {
                return(ServiceResponse.Error("Invalid PriceRule sent to server."));
            }

            PriceManager financeManager = new PriceManager(Globals.DBConnectionKey, this.GetAuthToken(Request));
            var          res            = financeManager.Get(fat.UUID);

            if (res.Code != 200)
            {
                return(res);
            }
            var dbS = (PriceRule)res.Result;

            if (dbS.DateCreated == DateTime.MinValue)
            {
                dbS.DateCreated = DateTime.UtcNow;
            }

            dbS.Name = fat.Name;

            dbS.Image         = fat.Image;
            dbS.Deleted       = fat.Deleted;
            dbS.Status        = fat.Status;
            dbS.SortOrder     = fat.SortOrder;
            dbS.Expires       = fat.Expires;
            dbS.ReferenceType = fat.ReferenceType;
            dbS.Code          = fat.Code;
            dbS.Operand       = fat.Operand;
            dbS.Operator      = fat.Operator;
            dbS.Minimum       = fat.Minimum;
            dbS.Maximum       = fat.Maximum;
            dbS.Mandatory     = fat.Mandatory;
            dbS.MaxUseCount   = fat.MaxUseCount;

            return(financeManager.Update(dbS));
        }
Esempio n. 24
0
        public ServiceResult DeletePriceRuleBy(string uuid)
        {
            if (string.IsNullOrWhiteSpace(uuid))
            {
                return(ServiceResponse.Error("Invalid id."));
            }

            PriceManager fm  = new PriceManager(Globals.DBConnectionKey, this.GetAuthToken(Request));
            var          res = fm.Get(uuid);

            if (res.Code != 200)
            {
                return(res);
            }
            PriceRule c = (PriceRule)res.Result;

            if (c == null)
            {
                return(ServiceResponse.Error("Invalid uuid"));
            }

            return(fm.Delete(c));
        }
        public bool ApplyPriceRules <T> (IEnumerable <PriceRule> priceRules, Operation <T> operation,
                                         PriceGroup partnerPriceGroup, PriceGroup locationPriceGroup) where T : OperationDetail, new ()
        {
            if (operation.PartnerId < 0 || operation.LocationId < 0 || itemId < 0)
            {
                return(false);
            }

            if (PromotionForDetailHashCode != 0)
            {
                return(false);
            }

            AppliedPriceRules = PriceRule.AppliedActions.None;
            if (!ManualDiscount)
            {
                DiscountEvaluate(0);
            }

            PriceGroup priceGroup = Operation.GetPriceGroup(partnerPriceGroup, locationPriceGroup);

            if (!ManualSalePrice && Item != null)
            {
                OriginalPriceOutEvaluate(GetItemPriceOut(Item, priceGroup));
                TotalEvaluate();
            }

            if (!ManualPurchasePrice && Item != null)
            {
                OriginalPriceInEvaluate(lotObject == null ? GetItemPriceIn(Item) : lotObject.PriceIn, operation);
                TotalEvaluate();
            }

            operation.ClearPromotionForDetail(this);
            return(PriceRule.ApplyBeforeOperationSaved(operation, null, false, priceRules));
        }
Esempio n. 26
0
        public override void OnOperationSave(bool askForConfirmation)
        {
            #region Prepare the purchase object

            if (!OperationValidate())
            {
                return;
            }

            if (!OperationDetailsValidate(true))
            {
                return;
            }

            #endregion

            if (!TryApplyRules())
            {
                return;
            }

            bool printPayment;
            using (EditNewPayment dialogFinalize = new EditNewPayment(operation)) {
                if (dialogFinalize.Run() != ResponseType.Ok)
                {
                    ClearDetailsFromPriceRules(true);
                    return;
                }
                printPayment = dialogFinalize.PrintDocument;
            }

            if (!PriceRule.ApplyOnPaymentSet(operation))
            {
                return;
            }

            try {
                var newPayments = GetAllNewPayments(printPayment);
                PrepareOpertionForSaving();
                CommitOperation();
                PrintAllNewPayments(newPayments);
            } catch (InsufficientItemAvailabilityException ex) {
                MessageError.ShowDialog(string.Format(Translator.GetString("The purchase cannot be saved due to insufficient quantities of item \"{0}\"."), ex.ItemName),
                                        ErrorSeverity.Warning, ex);
                ClearDetailsFromPriceRules();
                EditGridField(ex.ItemName);
                return;
            } catch (Exception ex) {
                MessageError.ShowDialog(Translator.GetString("An error occurred while saving purchase document!"),
                                        ErrorSeverity.Error, ex);
                ClearDetailsFromPriceRules(true);
                return;
            }

            ApplyFinalPriceRules();

            if (BusinessDomain.AppConfiguration.AutoCreateInvoiceOnPurchase && !editMode &&
                WaitForPendingOperationCompletion())
            {
                using (EditNewInvoice dlgInvoice = new EditNewInvoice(operation))
                    dlgInvoice.Run();
            }

            #region Ask to print a document

            bool printReceipt = false;

            if (BusinessDomain.AppConfiguration.IsPrintingAvailable() && BusinessDomain.WorkflowManager.AllowPurchaseReceiptPrint(operation, false))
            {
                if (BusinessDomain.AppConfiguration.AskBeforeDocumentPrint == AskDialogState.NotSaved)
                {
                    using (MessageYesNoRemember dialogPrint = new MessageYesNoRemember(
                               Translator.GetString("Print document"), string.Empty,
                               Translator.GetString("Do you want to print a stock receipt?"), "Icons.Question32.png")) {
                        ResponseType resp = dialogPrint.Run();
                        if (resp == ResponseType.Yes)
                        {
                            printReceipt = true;
                        }

                        if (dialogPrint.RememberChoice)
                        {
                            BusinessDomain.AppConfiguration.AskBeforeDocumentPrint = resp == ResponseType.Yes ? AskDialogState.Yes : AskDialogState.No;
                        }
                    }
                }
                else if (BusinessDomain.AppConfiguration.AskBeforeDocumentPrint == AskDialogState.Yes)
                {
                    printReceipt = true;
                }
            }

            if (printReceipt && WaitForPendingOperationCompletion())
            {
                try {
                    PurchaseReceipt receipt = new PurchaseReceipt(operation);
                    FormHelper.PrintPreviewObject(receipt);
                } catch (Exception ex) {
                    MessageError.ShowDialog(
                        Translator.GetString("An error occurred while generating stock receipt!"),
                        ErrorSeverity.Error, ex);
                }
            }

            #endregion

            OnOperationSaved();

            if (editMode)
            {
                OnPageClose();
            }
            else
            {
                ReInitializeForm(null);
            }
        }
Esempio n. 27
0
 public void UpdateRulePrices(PriceRule rule)
 {
     context.Entry(rule).State = EntityState.Modified;
 }
Esempio n. 28
0
        public static void Initialize(AppDbContext context)
        {
            var prices = new PriceRule[]
            {
                new PriceRule {
                    Id                 = Guid.NewGuid(),
                    Description        = "Desconto para pedidos com 2 lanches",
                    PriceRuleType      = Domain.Common.PriceRuleTypeEnum.Discount,
                    Value              = 3,
                    PriceRuleValueType = Domain.Common.PriceRuleValueTypeEnum.Percentage,
                    RuleType           = Domain.Common.RuleTypeEnum.SandwichQuantity,
                    RuleValue          = 2,
                    Created            = DateTime.Today,
                    CreatedBy          = "System"
                },
                new PriceRule {
                    Id                 = Guid.NewGuid(),
                    Description        = "Desconto para pedidos com 3 lanches",
                    PriceRuleType      = Domain.Common.PriceRuleTypeEnum.Discount,
                    Value              = 5,
                    PriceRuleValueType = Domain.Common.PriceRuleValueTypeEnum.Percentage,
                    RuleType           = Domain.Common.RuleTypeEnum.SandwichQuantity,
                    RuleValue          = 3,
                    Created            = DateTime.Today,
                    CreatedBy          = "System"
                },
                new PriceRule {
                    Id                 = Guid.NewGuid(),
                    Description        = "Desconto para pedidos acima de 5 lanches",
                    PriceRuleType      = Domain.Common.PriceRuleTypeEnum.Discount,
                    Value              = 10,
                    PriceRuleValueType = Domain.Common.PriceRuleValueTypeEnum.Percentage,
                    RuleType           = Domain.Common.RuleTypeEnum.SandwichQuantity,
                    RuleValue          = 5,
                    Created            = DateTime.Today,
                    CreatedBy          = "System"
                },
                new PriceRule {
                    Id                 = Guid.NewGuid(),
                    Description        = "Taxa de Entrega",
                    PriceRuleType      = Domain.Common.PriceRuleTypeEnum.AdditionalCharge,
                    Value              = 10,
                    PriceRuleValueType = Domain.Common.PriceRuleValueTypeEnum.Percentage,
                    RuleType           = Domain.Common.RuleTypeEnum.None,
                    RuleValue          = 10,
                    Created            = DateTime.Today,
                    CreatedBy          = "System",
                    Deleted            = true,
                    DeletedAt          = DateTime.Today,
                    DeletedBy          = "System"
                }
            };
            var ingredients = new Ingredient[]
            {
                new Ingredient
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Hamburger clássico 160g grelhado",
                    Cost      = 3M,
                    Price     = 4M,
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Ingredient
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Picles de pimenta",
                    Cost      = 0.5M,
                    Price     = 1M,
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Ingredient
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Queijo prato",
                    Cost      = 0.25M,
                    Price     = 0.5M,
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Ingredient
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Maionses especial",
                    Cost      = 0.10M,
                    Price     = 0.25M,
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Ingredient
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Alface",
                    Cost      = 0.05M,
                    Price     = 0.15M,
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Ingredient
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Hamburger de salmão grelhado",
                    Cost      = 4M,
                    Price     = 5M,
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Ingredient
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Pão de Hamburger",
                    Cost      = 0.15M,
                    Price     = 1.5M,
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Ingredient
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Cogumelo shitake",
                    Cost      = 0.50M,
                    Price     = 1.50M,
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Ingredient
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Molho shoyo",
                    Cost      = 0.05M,
                    Price     = 0.15M,
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Ingredient
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Catupiry",
                    Cost      = 0.05M,
                    Price     = 0.15M,
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Ingredient
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Cebola",
                    Cost      = 0.05M,
                    Price     = 0.15M,
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Ingredient
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Queijo Cheddar",
                    Cost      = 0.05M,
                    Price     = 0.15M,
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Ingredient
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Hamburguer de Calabresa 160g grelhado",
                    Cost      = 6M,
                    Price     = 8M,
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Ingredient
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Mussarela de búfala",
                    Cost      = 1.5M,
                    Price     = 3M,
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Ingredient
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Rúcula",
                    Cost      = 0.05M,
                    Price     = 1M,
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Ingredient
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Tomate seco",
                    Cost      = 0.05M,
                    Price     = 1M,
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Ingredient
                {
                    Id        = Guid.NewGuid(),
                    Name      = "Hamburguer Angus",
                    Cost      = 7M,
                    Price     = 9M,
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                }
            };
            var sandwiches = new Sandwich[]
            {
                new Sandwich
                {
                    Id        = Guid.NewGuid(),
                    Name      = "ALAGOAS BURGUER",
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Sandwich
                {
                    Id        = Guid.NewGuid(),
                    Name      = "ITACOLOMI BURGER",
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                },
                new Sandwich
                {
                    Id        = Guid.NewGuid(),
                    Name      = "MATHIAS BURGER",
                    Created   = DateTime.Now,
                    CreatedBy = "System"
                }
            };

            var sandwichIngredients = new SandwichIngredient[]
            {
                new SandwichIngredient
                {
                    Id           = Guid.NewGuid(),
                    Created      = DateTime.Now,
                    CreatedBy    = "System",
                    IngredientId = ingredients.First(i => i.Name == "Hamburger clássico 160g grelhado").Id,
                    Ingredient   = ingredients.First(i => i.Name == "Hamburger clássico 160g grelhado"),
                    SandwichId   = sandwiches.First(s => s.Name == "ALAGOAS BURGUER").Id,
                    //Sandwich =  sandwiches.First(s=>s.Name=="ALAGOAS BURGUER"),
                    Quantity = 1
                },
                new SandwichIngredient
                {
                    Id           = Guid.NewGuid(),
                    Created      = DateTime.Now,
                    CreatedBy    = "System",
                    IngredientId = ingredients.First(i => i.Name == "Picles de pimenta").Id,
                    Ingredient   = ingredients.First(i => i.Name == "Picles de pimenta"),
                    SandwichId   = sandwiches.First(s => s.Name == "ALAGOAS BURGUER").Id,
                    //Sandwich =  sandwiches.First(s=>s.Name=="ALAGOAS BURGUER"),
                    Quantity = 1
                },
                new SandwichIngredient
                {
                    Id           = Guid.NewGuid(),
                    Created      = DateTime.Now,
                    CreatedBy    = "System",
                    IngredientId = ingredients.First(i => i.Name == "Queijo prato").Id,
                    Ingredient   = ingredients.First(i => i.Name == "Queijo prato"),
                    SandwichId   = sandwiches.First(s => s.Name == "ALAGOAS BURGUER").Id,
                    //Sandwich =  sandwiches.First(s=>s.Name=="ALAGOAS BURGUER"),
                    Quantity = 1
                },
                new SandwichIngredient
                {
                    Id           = Guid.NewGuid(),
                    Created      = DateTime.Now,
                    CreatedBy    = "System",
                    IngredientId = ingredients.First(i => i.Name == "Maionses especial").Id,
                    Ingredient   = ingredients.First(i => i.Name == "Maionses especial"),
                    SandwichId   = sandwiches.First(s => s.Name == "ALAGOAS BURGUER").Id,
                    //Sandwich =  sandwiches.First(s=>s.Name=="ALAGOAS BURGUER"),
                    Quantity = 1
                },
                new SandwichIngredient
                {
                    Id           = Guid.NewGuid(),
                    Created      = DateTime.Now,
                    CreatedBy    = "System",
                    IngredientId = ingredients.First(i => i.Name == "Alface").Id,
                    Ingredient   = ingredients.First(i => i.Name == "Alface"),
                    SandwichId   = sandwiches.First(s => s.Name == "ALAGOAS BURGUER").Id,
                    Quantity     = 1
                },
                new SandwichIngredient
                {
                    Id           = Guid.NewGuid(),
                    Created      = DateTime.Now,
                    CreatedBy    = "System",
                    IngredientId = ingredients.First(i => i.Name == "Pão de Hamburger").Id,
                    Ingredient   = ingredients.First(i => i.Name == "Pão de Hamburger"),
                    SandwichId   = sandwiches.First(s => s.Name == "ALAGOAS BURGUER").Id,
                    Quantity     = 1
                },
                new SandwichIngredient
                {
                    Id           = Guid.NewGuid(),
                    Created      = DateTime.Now,
                    CreatedBy    = "System",
                    IngredientId = ingredients.First(i => i.Name == "Hamburger de salmão grelhado").Id,
                    Ingredient   = ingredients.First(i => i.Name == "Hamburger de salmão grelhado"),
                    SandwichId   = sandwiches.First(s => s.Name == "ITACOLOMI BURGER").Id,
                    Quantity     = 1
                },
                new SandwichIngredient
                {
                    Id           = Guid.NewGuid(),
                    Created      = DateTime.Now,
                    CreatedBy    = "System",
                    IngredientId = ingredients.First(i => i.Name == "Cogumelo shitake").Id,
                    Ingredient   = ingredients.First(i => i.Name == "Cogumelo shitake"),
                    SandwichId   = sandwiches.First(s => s.Name == "ITACOLOMI BURGER").Id,
                    Quantity     = 1
                },
                new SandwichIngredient
                {
                    Id           = Guid.NewGuid(),
                    Created      = DateTime.Now,
                    CreatedBy    = "System",
                    IngredientId = ingredients.First(i => i.Name == "Molho shoyo").Id,
                    Ingredient   = ingredients.First(i => i.Name == "Molho shoyo"),
                    SandwichId   = sandwiches.First(s => s.Name == "ITACOLOMI BURGER").Id,
                    Quantity     = 1
                },
                new SandwichIngredient
                {
                    Id           = Guid.NewGuid(),
                    Created      = DateTime.Now,
                    CreatedBy    = "System",
                    IngredientId = ingredients.First(i => i.Name == "Catupiry").Id,
                    Ingredient   = ingredients.First(i => i.Name == "Catupiry"),
                    SandwichId   = sandwiches.First(s => s.Name == "ITACOLOMI BURGER").Id,
                    Quantity     = 1
                },
                new SandwichIngredient
                {
                    Id           = Guid.NewGuid(),
                    Created      = DateTime.Now,
                    CreatedBy    = "System",
                    IngredientId = ingredients.First(i => i.Name == "Pão de Hamburger").Id,
                    Ingredient   = ingredients.First(i => i.Name == "Pão de Hamburger"),
                    SandwichId   = sandwiches.First(s => s.Name == "ITACOLOMI BURGER").Id,
                    Quantity     = 1
                },
                new SandwichIngredient
                {
                    Id           = Guid.NewGuid(),
                    Created      = DateTime.Now,
                    CreatedBy    = "System",
                    IngredientId = ingredients.First(i => i.Name == "Hamburguer Angus").Id,
                    Ingredient   = ingredients.First(i => i.Name == "Hamburguer Angus"),
                    SandwichId   = sandwiches.First(s => s.Name == "MATHIAS BURGER").Id,
                    Quantity     = 1
                },
                new SandwichIngredient
                {
                    Id           = Guid.NewGuid(),
                    Created      = DateTime.Now,
                    CreatedBy    = "System",
                    IngredientId = ingredients.First(i => i.Name == "Maionses especial").Id,
                    Ingredient   = ingredients.First(i => i.Name == "Maionses especial"),
                    SandwichId   = sandwiches.First(s => s.Name == "MATHIAS BURGER").Id,
                    Quantity     = 1
                },
                new SandwichIngredient
                {
                    Id           = Guid.NewGuid(),
                    Created      = DateTime.Now,
                    CreatedBy    = "System",
                    IngredientId = ingredients.First(i => i.Name == "Cebola").Id,
                    Ingredient   = ingredients.First(i => i.Name == "Cebola"),
                    SandwichId   = sandwiches.First(s => s.Name == "MATHIAS BURGER").Id,
                    Quantity     = 1
                },
                new SandwichIngredient
                {
                    Id           = Guid.NewGuid(),
                    Created      = DateTime.Now,
                    CreatedBy    = "System",
                    IngredientId = ingredients.First(i => i.Name == "Queijo Cheddar").Id,
                    Ingredient   = ingredients.First(i => i.Name == "Queijo Cheddar"),
                    SandwichId   = sandwiches.First(s => s.Name == "MATHIAS BURGER").Id,
                    Quantity     = 1
                },
                new SandwichIngredient
                {
                    Id           = Guid.NewGuid(),
                    Created      = DateTime.Now,
                    CreatedBy    = "System",
                    IngredientId = ingredients.First(i => i.Name == "Pão de Hamburger").Id,
                    Ingredient   = ingredients.First(i => i.Name == "Pão de Hamburger"),
                    SandwichId   = sandwiches.First(s => s.Name == "MATHIAS BURGER").Id,
                    Quantity     = 1
                }
            };

            //sandwiches.ToList().ForEach(s => s.Ingredients = sandwichIngredients.Where(si => si.SandwichId == s.Id).ToArray());
            context.PriceRules.AddRange(prices);
            context.Ingredients.AddRange(ingredients);
            context.Sandwiches.AddRange(sandwiches);
            context.SandwichIngredients.AddRange(sandwichIngredients);

            context.SaveChanges();
        }
Esempio n. 29
0
        private ConfirmPriceRules(IEnumerable <PriceRule> rulesToApply, Operation <T> operation, bool priceWithVAT = false)
        {
            this.rulesToApply = new List <PriceRule> (rulesToApply);
            Initialize();

            gridOperationDetails = new ListView {
                Name = "gridOperationDetails", WidthRequest = 600, HeightRequest = 250
            };
            ColumnController columnController = new ColumnController();

            columnController.Add(new Column(Translator.GetString("Item"), "ItemName", 1));

            CellTextQuantity cellQuantity   = new CellTextQuantity("Quantity");
            Column           columnQuantity = new Column(Translator.GetString("Qtty"), cellQuantity, 0.1)
            {
                MinWidth = 55
            };

            columnController.Add(columnQuantity);

            CellTextDouble cellPrice   = new CellTextCurrency(priceWithVAT ? "OriginalPriceOutPlusVAT" : "OriginalPriceOut");
            Column         columnPrice = new Column(Translator.GetString("Price"), cellPrice, 0.1)
            {
                MinWidth = 55
            };

            columnController.Add(columnPrice);

            CellTextDouble cellDiscount = new CellTextDouble("Discount");

            cellDiscount.FixedFaction = BusinessDomain.AppConfiguration.PercentPrecision;
            Column columnDiscount = new Column(Translator.GetString("Discount %"), cellDiscount, 0.1);

            columnDiscount.Visible  = BusinessDomain.AppConfiguration.AllowPercentDiscounts;
            columnDiscount.MinWidth = 100;
            columnController.Add(columnDiscount);

            BindingListModel <T> model     = GetChangedDetails(operation);
            PriceType            priceType = PriceType.SaleTotal;

            if (model.Count > 0)
            {
                priceType = model [0].TotalsPriceType;
            }

            CellTextDouble cellTotal   = new CellTextCurrency(priceWithVAT ? "TotalPlusVAT" : "Total", priceType);
            Column         columnTotal = new Column(Translator.GetString("Amount"), cellTotal, 0.1)
            {
                MinWidth = 55
            };

            columnController.Add(columnTotal);

            gridOperationDetails.ColumnController = columnController;

            gridOperationDetails.Model = model;
            scwOperationDetails.Add(gridOperationDetails);
            gridOperationDetails.Show();

            CellRendererToggle cellRendererToggle = new CellRendererToggle {
                Activatable = true
            };

            cellRendererToggle.Toggled += (o, args) =>
            {
                TreeIter row;
                TreePath treePath = new TreePath(args.Path);
                treeviewPriceRules.Model.GetIter(out row, treePath);
                PriceRule priceRule = (PriceRule)treeviewPriceRules.Model.GetValue(row, 2);
                bool      value     = !(bool)treeviewPriceRules.Model.GetValue(row, 0);
                if (value)
                {
                    if (treePath.Indices [0] <= this.rulesToApply.Count)
                    {
                        this.rulesToApply.Insert(treePath.Indices [0], priceRule);
                    }
                    else
                    {
                        this.rulesToApply.Add(priceRule);
                    }
                }
                else
                {
                    this.rulesToApply.Remove(priceRule);
                }
                gridOperationDetails.Model = GetChangedDetails(operation);
                treeviewPriceRules.Model.SetValue(row, 0, value);
            };
            treeviewPriceRules.AppendColumn(string.Empty, cellRendererToggle, "active", 0);
            treeviewPriceRules.AppendColumn(Translator.GetString("Price rule"), new CellRendererText(), "text", 1);
            treeviewPriceRules.AppendColumn(Translator.GetString("Price rule"), new CellRendererText(), "text", 2).Visible = false;
            TreeStore treeStore = new TreeStore(typeof(bool), typeof(string), typeof(object));

            foreach (PriceRule priceRule in this.rulesToApply)
            {
                treeStore.AppendValues(true, priceRule.Name, priceRule);
            }
            treeviewPriceRules.Model = treeStore;
        }
Esempio n. 30
0
 protected bool TryApplyRules(bool priceWithVAT = false)
 {
     return(editMode || PriceRule.ApplyBeforeOperationSaved(operation,
                                                            (rules, details) => ConfirmPriceRules <TOperDetail> .GetRulesToApply(rules, operation, priceWithVAT), true, PriceRules));
 }