示例#1
0
        void prepareEditModel(EditSalesOrderHeaderTempViewModel model, int id)
        {
            var soht = SalesService.FindSalesOrderHeaderTempModel(id, CurrentCompany, false);

            PrepareViewModel(model, EvolutionResources.bnrAddEditSale + " - " + EvolutionResources.lblOrderNumber + ": " + model.SaleTemp.OrderNumber.ToString(), id, MakeMenuOptionFlags(0, 0, 0, soht.OriginalRowId) + MenuOptionFlag.RequiresNewSale);
            model.ParentId = id;

            model.LocationList         = LookupService.FindLocationListItemModel(model.CurrentCompany);
            model.ShippingTemplateList = LookupService.FindDocumentTemplatesListItemModel(DocumentTemplateCategory.Invoice);
            model.CountryList          = LookupService.FindCountriesListItemModel();
            model.OrderTypeList        = LookupService.FindLOVItemsListItemModel(model.CurrentCompany, LOVName.OrderType);
            model.BrandCategoryList    = ProductService.FindBrandCategoryListItemModel(model.CurrentCompany);
            model.SOStatusList         = LookupService.FindSalesOrderHeaderStatusListItemModel();
            model.UserList             = MembershipManagementService.FindUserListItemModel();
            model.PaymentTermsList     = LookupService.FindPaymentTermsListItemModel(model.CurrentCompany);
            if (model.SaleTemp.CustomerId != null)
            {
                model.CreditCardList = CustomerService.FindCreditCardsListItemModel(model.CurrentCompany, model.SaleTemp.CustomerId.Value);
            }

            model.FreightCarrierList = LookupService.FindFreightCarriersListItemModel(model.CurrentCompany);
            model.FreightTermList    = LookupService.FindLOVItemsListItemModel(model.CurrentCompany, LOVName.FreightTerm);

            model.MethodSignedList = LookupService.FindMethodSignedListItemModel();
        }
示例#2
0
        public ActionResult EditDetails(int id)
        {
            // Called when a user is on one of the sales screens and clicks the sale details option
            var model = new EditSalesOrderHeaderTempViewModel();

            // Use the data in the temp tables
            var saleTemp = SalesService.FindSalesOrderHeaderTempModel(id, CurrentCompany, true);

            saleTemp.UserId = CurrentUser.Id;

            model.SaleTemp = saleTemp;
            prepareEditModel(model, id);

            var sale = SalesService.FindSalesOrderHeaderModel(saleTemp.OriginalRowId, CurrentCompany, true);

            // If any of the items on the order are partially or fully completed, then we
            // disable adding and editing of items.
            // The ids of SalesOrderLineStatus' are the same as the enums.
            var items = SalesService.FindSalesOrderDetailTempsListModel(CurrentCompany.Id, saleTemp.Id, 0);

            foreach (var item in items.Items)
            {
                if (item.LineStatusId == (int)SalesOrderLineStatus.SentForPicking ||
                    item.LineStatusId == (int)SalesOrderLineStatus.Complete)
                {
                    model.PartiallyComplete = true;
                    break;
                }
            }

            model.LGS  = SalesService.LockSalesOrderHeader(sale);
            model.LGST = SalesService.LockSalesOrderHeaderTemp(model.SaleTemp);

            return(View("Edit", model));
        }
示例#3
0
        public ActionResult Edit(int id)
        {
            // Called when a user clicks to edit a sale
            var model = new EditSalesOrderHeaderTempViewModel();

            var sale = SalesService.FindSalesOrderHeaderModel(id, CurrentCompany, true);

            // Copy the order into temp tables for editing
            model.SaleTemp = SalesService.CopySaleToTemp(CurrentCompany, sale, CurrentUser, false);
            prepareEditModel(model, model.SaleTemp.Id);

            // If any of the items on the order are partially or fully completed, then we
            // disable ading and editing of items.
            // The ids of SalesOrderLineStatus' are the same as the enums.
            var items = SalesService.FindSalesOrderDetailTempsListModel(CurrentCompany.Id, model.SaleTemp.Id, 0);

            foreach (var item in items.Items)
            {
                if (item.LineStatusId == (int)SalesOrderLineStatus.SentForPicking ||
                    item.LineStatusId == (int)SalesOrderLineStatus.Complete)
                {
                    model.PartiallyComplete = true;
                    break;
                }
            }

            model.LGS  = SalesService.LockSalesOrderHeader(sale);
            model.LGST = SalesService.LockSalesOrderHeaderTemp(model.SaleTemp);

            return(View("Edit", model));
        }
示例#4
0
        public ActionResult Add()
        {
            // Called when the user clicks 'Create' to create a new sale
            var editModel = new EditSalesOrderHeaderTempViewModel();

            var sale = SalesService.FindSalesOrderHeaderModel(0, CurrentCompany, true);

            sale.OrderDate       = DateTimeOffset.Now;
            sale.SalespersonId   = CurrentUser.Id;
            sale.BrandCategoryId = CurrentUser.DefaultBrandCategoryId;
            var freightCarrier = LookupService.FindFreightCarriersListItemModel(CurrentCompany)
                                 .Where(fc => fc.Text.ToLower() == "unspecified")
                                 .FirstOrDefault();

            if (freightCarrier != null)
            {
                sale.FreightCarrierId = Convert.ToInt32(freightCarrier.Id);
            }
            sale.ShipCountryId = CurrentCompany.DefaultCountryID;
            sale.NextActionId  = LookupService.FindSaleNextActionId(SaleNextAction.None);

            // Copy the order into temp tables for editing
            editModel.SaleTemp = SalesService.CopySaleToTemp(CurrentCompany, sale, CurrentUser, false);

            return(EditDetails(editModel.SaleTemp.Id));
        }
示例#5
0
        public ActionResult CopyOrder(int id)
        {
            // Called to copy an order
            var model = new EditSalesOrderHeaderTempViewModel();

            var sale = SalesService.FindSalesOrderHeaderModel(id, CurrentCompany, true);

            // Copy the order into temp tables for editing
            model.SaleTemp = SalesService.CopySaleToTemp(CurrentCompany, sale, CurrentUser, true);
            prepareEditModel(model, model.SaleTemp.Id);

            model.LGS  = SalesService.LockSalesOrderHeader(sale);
            model.LGST = SalesService.LockSalesOrderHeaderTemp(model.SaleTemp);

            return(View("Edit", model));
        }
示例#6
0
        public ActionResult Save(EditSalesOrderHeaderTempViewModel model, string command)
        {
            switch (command.ToLower())
            {
            case "save":
                // Save the screen data back to the temp tables, then copy to live tables and exit
                if (ModelState.IsValid)
                {
                    adjustDates(model.SaleTemp, model.TZ);

                    var modelError = new Error();

                    var items = SalesService.FindSalesOrderDetailTempsListModel(CurrentCompany.Id, model.SaleTemp.Id, 0, 1, 9999, "");
                    if (items.Items.Count() == 0)
                    {
                        prepareEditModel(model, model.SaleTemp.Id);
                        model.SetErrorOnField(ErrorIcon.Error,
                                              EvolutionResources.errCantSaveSaleWithNoLines,
                                              "SaleTemp_EndUserName");
                        return(View("Edit", model));
                    }
                    else
                    {
                        modelError = SalesService.InsertOrUpdateSalesOrderHeaderTemp(model.SaleTemp, CurrentUser, model.LGST, false);
                        if (modelError.IsError)
                        {
                            prepareEditModel(model, model.SaleTemp.Id);
                            model.SetErrorOnField(ErrorIcon.Error,
                                                  modelError.Message,
                                                  "SaleTemp_" + modelError.FieldName);
                            return(View("Edit", model));
                        }
                        else
                        {
                            // Copy the temp tables back to the main tables
                            modelError = SalesService.CopyTempToSalesOrderHeader(model.SaleTemp.Id, CurrentUser, model.LGS);
                            if (modelError.IsError)
                            {
                                prepareEditModel(model, model.SaleTemp.Id);
                                model.SetErrorOnField(ErrorIcon.Error,
                                                      modelError.Message,
                                                      "SaleTemp_" + modelError.FieldName);
                            }
                            else
                            {
                                if (model.SaleTemp.OverrideApproverId != null)
                                {
                                    // Send override approbal notification
                                    var sohm = SalesService.FindSalesOrderHeaderModel(modelError.Id, CurrentCompany, false);

                                    SalesService.SendMSQOverrideEMail(CurrentCompany,
                                                                      CurrentUser,
                                                                      MembershipManagementService.FindUserModel(model.SaleTemp.OverrideApproverId.Value),
                                                                      sohm);

                                    // Update the temp record so that we don't send a second approval email
                                    model.SaleTemp.OverrideApproverId = null;
                                    SalesService.InsertOrUpdateSalesOrderHeaderTemp(model.SaleTemp, CurrentUser,
                                                                                    SalesService.LockSalesOrderHeaderTemp(model.SaleTemp),
                                                                                    false);
                                }

                                return(RedirectToAction("Sales"));
                            }
                        }
                    }
                }
                prepareEditModel(model, model.SaleTemp.Id);
                return(View("Edit", model));

            default:
                return(RedirectToAction("Sales"));
            }
        }