public Error InsertOrUpdateSalesOrderHeaderTemp(SalesOrderHeaderTempModel soht, UserModel user, string lockGuid, bool keyFieldsOnly)
        {
            var error = new Error();

            if (!keyFieldsOnly)
            {
                error = validateModel(soht);
            }
            if (!error.IsError)
            {
                // Check that the lock is still current
                if (!db.IsLockStillValid(typeof(SalesOrderHeaderTemp).ToString(), soht.Id, lockGuid))
                {
                    error.SetError(EvolutionResources.errRecordChangedByAnotherUser, "OrderNumber");
                }
                else
                {
                    SalesOrderHeaderTemp temp = null;
                    if (soht.Id != 0)
                    {
                        temp = db.FindSalesOrderHeaderTemp(soht.Id);
                    }
                    if (temp == null)
                    {
                        temp = new SalesOrderHeaderTemp();
                    }

                    Mapper.Map <SalesOrderHeaderTempModel, SalesOrderHeaderTemp>(soht, temp);

                    db.InsertOrUpdateSalesOrderHeaderTemp(temp);
                    soht.Id = temp.Id;
                }
            }
            return(error);
        }
        public List <ListItemModel> FindCustomerRecipients(SalesOrderHeaderTempModel soht,
                                                           CompanyModel company, UserModel user)
        {
            List <ListItemModel> recipients = new List <ListItemModel>();

            var customer = FindCustomerModel(soht.CustomerId == null ? 0 : soht.CustomerId.Value, company);

            // Add all the contacts
            recipients.AddRange(FindCustomerContactsListItemModel(customer.Id, true, false));

            // Myself
            recipients.Add(new ListItemModel(user.FullName + " (Myself)", user.Id * -1));

            // Account Manager
            foreach (var sp in FindBrandCategorySalesPersonsModel(company, customer, soht.BrandCategoryId.Value, SalesPersonType.AccountManager))
            {
                recipients.Add(new ListItemModel(sp.UserName + " (Account Manager)", sp.UserId * -1));
            }

            // Account Admin manager for brand category
            foreach (var sp in FindBrandCategorySalesPersonsModel(company, customer, soht.BrandCategoryId.Value, SalesPersonType.AccountAdmin))
            {
                recipients.Add(new ListItemModel(sp.UserName + " (Account Admin)", sp.UserId * -1));
            }

            return(recipients);
        }
Beispiel #3
0
        public CustomerModel FindCustomer(SalesOrderHeaderTempModel soht, CompanyModel company)
        {
            CustomerModel cust = null;

            if (soht != null && soht.CustomerId != null)
            {
                cust = CustomerService.FindCustomerModel(soht.CustomerId.Value, company, false);
            }
            return(cust);
        }
Beispiel #4
0
 private void adjustDates(SalesOrderHeaderTempModel model, string tz)
 {
     model.DeliveryWindowOpen  = GetFieldValue(model.DeliveryWindowOpen, tz);
     model.DeliveryWindowClose = GetFieldValue(model.DeliveryWindowClose, tz);
     model.OARChangeDate       = GetFieldValue(model.OARChangeDate, tz);
     model.OrderHoldExpiryDate = GetFieldValue(model.OrderHoldExpiryDate, tz);
     model.NextReviewDate      = GetFieldValue(model.NextReviewDate, tz);
     model.OrderDate           = GetFieldValue(model.OrderDate, tz);
     model.DateSigned          = GetFieldValue(model.DateSigned, tz);
 }
        public SalesOrderSummaryModel CreateOrderSummary(SalesOrderHeaderTempModel soht)
        {
            var model = new SalesOrderSummaryModel();

            model.SubTotal  = 0;
            model.TaxName   = "";
            model.TaxTotal  = 0;
            model.Total     = 0;
            model.Total     = model.SubTotal + model.TaxTotal;
            model.TotalCbms = 0;

            // The tax code and currency comes from the customer
            double taxRate = 0;

            if (soht.CustomerId != null)
            {
                var customer = db.FindCustomer(soht.CustomerId.Value);
                if (customer != null)
                {
                    var taxCode = db.FindTaxCode(customer.TaxCodeId);
                    if (taxCode != null)
                    {
                        model.TaxName = taxCode.TaxCode1;
                        if (taxCode.TaxPercentageRate != null)
                        {
                            taxRate = (double)taxCode.TaxPercentageRate.Value;
                        }
                    }
                    model.CurrencySymbol = LookupService.FindCurrencySymbol(customer.CurrencyId);
                }
            }

            // Now traverse all the items on the order
            foreach (var orderLine in FindSalesOrderDetailTempsListModel(soht.CompanyId, soht.Id, 0, 1, 9999, "").Items)
            {
                double linePrice = (double)(orderLine.LinePrice == null ? 0 : orderLine.LinePrice.Value);
                model.SubTotal += linePrice;

                double gstAmount = linePrice / 100 * taxRate;
                model.TaxTotal += gstAmount;

                if (orderLine.UnitCBM != null)
                {
                    model.TotalCbms += orderLine.UnitCBM.Value * (double)orderLine.OrderQty;
                }
            }
            model.Total = model.SubTotal + model.TaxTotal;

            return(model);
        }
        SalesOrderHeaderTempModel mapToModel(SalesOrderHeaderTemp item)
        {
            SalesOrderHeaderTempModel newItem = new SalesOrderHeaderTempModel();

            Mapper.Map(item, newItem);

            newItem.CustomerName = item.Customer.Name;

            if (item.SalesOrderHeaderStatu != null)
            {
                newItem.SOStatusText  = item.SalesOrderHeaderStatu.StatusName;
                newItem.SOStatusValue = (SalesOrderHeaderStatus)item.SalesOrderHeaderStatu.StatusValue;
            }
            if (item.SalesOrderHeaderSubStatu != null)
            {
                newItem.SOSubStatusText = item.SalesOrderHeaderSubStatu.StatusName;
            }
            if (item.LOVItem_Source != null)
            {
                newItem.SourceText = item.LOVItem_Source.ItemText;
            }

            newItem.SalesPersonName = db.MakeName(item.User_SalesPerson);

            newItem.NextActionText = (item.SaleNextAction == null ? "" : item.SaleNextAction.NextActionDescription);

            newItem.IsMSQOverridable = false;
            if (!item.IsOverrideMSQ &&
                item.SalesOrderHeaderSubStatu != null &&
                item.SalesOrderHeaderSubStatu.Id == (int)SalesOrderHeaderSubStatus.Unpicked)
            {
                newItem.IsMSQOverridable = true;
            }

            if (item.BrandCategory != null)
            {
                newItem.BrandCategoryText = item.BrandCategory.CategoryName;
            }

            return(newItem);
        }
        private SalesOrderDetailTempModel createSalesOrderDetailTemp(SalesOrderHeaderTempModel soht,
                                                                     CompanyModel testCompany,
                                                                     CustomerModel testCustomer,
                                                                     UserModel testUser,
                                                                     int productId)
        {
            var prodPrice = ProductService.FindProductPrice(testCompany, productId, testCustomer.Id);

            var sodt = new SalesOrderDetailTempModel {
                CompanyId = testCompany.Id,
                SalesOrderHeaderTempId = soht.Id,
                LineNumber             = 1000,
                ProductId      = productId,
                OrderQty       = RandomInt(),
                UnitPriceExTax = (prodPrice == null ? 0 : prodPrice.SellingPrice)
                                 //ConflictFlag = false,
                                 //ConflictApproved = false,
                                 //ReallocateItem = false
            };

            return(sodt);
        }
        public SalesOrderHeaderTempModel FindSalesOrderHeaderTempModel(int id, CompanyModel company, bool bCreateEmptyIfNotfound = true)
        {
            SalesOrderHeaderTempModel model = null;

            var p = db.FindSalesOrderHeaderTemp(id);

            if (p == null)
            {
                if (bCreateEmptyIfNotfound)
                {
                    model = new SalesOrderHeaderTempModel {
                        CompanyId = company.Id
                    }
                }
                ;
            }
            else
            {
                model = mapToModel(p);
            }

            return(model);
        }
        private Error validateModel(SalesOrderHeaderTempModel model)
        {
            var error = new Error();

            if (model.CustomerId == null)
            {
                error.SetError(EvolutionResources.errCustomerRequired, "CustomerId");
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.EndUserName), 52, "EndUserName", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidRequiredString(getFieldValue(model.ShipAddress1), 255, "ShipAddress1", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.ShipAddress2), 255, "ShipAddress2", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.ShipAddress3), 255, "ShipAddress3", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.ShipAddress4), 255, "ShipAddress4", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidRequiredString(getFieldValue(model.ShipSuburb), 60, "ShipSuburb", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidRequiredString(getFieldValue(model.ShipState), 20, "ShipState", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidRequiredString(getFieldValue(model.ShipPostcode), 12, "ShipPostcode", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.WarehouseInstructions), 100, "WarehouseInstructions", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidRequiredDate(model.DeliveryWindowOpen, "DeliveryWindowOpen", EvolutionResources.errDateRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidRequiredDate(model.DeliveryWindowClose, "DeliveryWindowClose", EvolutionResources.errDateRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.DeliveryInstructions), 30, "DeliveryInstructions", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.DeliveryContact), 30, "DeliveryContact", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.CustPO), 255, "CustPO", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.ShipMethodAccount), 25, "ShipMethodAccount", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.EDI_Department), 30, "EDI_Department", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.EDI_DCCode), 30, "EDI_DCCode", EvolutionResources.errTextDataRequiredInField);
            }
            if (!error.IsError)
            {
                error = isValidNonRequiredString(getFieldValue(model.EDI_StoreNo), 30, "EDI_StoreNo", EvolutionResources.errTextDataRequiredInField);
            }

            if (!error.IsError && model.SOStatus != null)
            {
                var orderType = db.FindSalesOrderHeaderStatus(model.SOStatus.Value);
                if (orderType != null && orderType.StatusValue == (int)SalesOrderHeaderStatus.ConfirmedOrder)
                {
                    // A confirmed order must be signed
                    if (!model.IsConfirmedAddress)
                    {
                        error.SetError(EvolutionResources.errAddressMustBeConfirmedForConfirmedOrder, "IsConfirmedAddress");
                    }
                    else
                    {
                        error = isValidRequiredString(getFieldValue(model.SignedBy), 30, "SignedBy", EvolutionResources.errTextDataRequiredInField);
                        if (!error.IsError)
                        {
                            if (model.DateSigned == null)
                            {
                                error.SetError(EvolutionResources.errDateRequiredInField, "DateSigned", "Date Signed");
                            }
                        }
                    }
                }
            }

            return(error);
        }
 public string LockSalesOrderHeaderTemp(SalesOrderHeaderTempModel model)
 {
     return(db.LockRecord(typeof(SalesOrderHeaderTemp).ToString(), model.Id));
 }
Beispiel #11
0
        public SalesOrderHeaderTempModel CopySaleToTemp(CompanyModel company,
                                                        SalesOrderHeaderModel salesOrderHeader,
                                                        UserModel user,
                                                        bool createCopyOfOrder)
        {
            SalesOrderHeaderTempModel result = new SalesOrderHeaderTempModel();
            SalesOrderHeaderTemp      soht   = new SalesOrderHeaderTemp();

            if (salesOrderHeader.Id > 0)
            {
                // Editing an existing sale
                var soh = db.FindSalesOrderHeader(salesOrderHeader.Id);
                if (soh != null)
                {
                    if (createCopyOfOrder)
                    {
                        // Copying/duplicating an order
                        Mapper.Map <SalesOrderHeader, SalesOrderHeaderTemp>(soh, soht);
                        soht.Id             = 0;
                        soht.OriginalRowId  = null;
                        soht.UserId         = user.Id;
                        soht.OrderNumber    = (int)LookupService.GetNextSequenceNumber(company, SequenceNumberType.SalesOrderNumber);
                        soht.OrderDate      = DateTimeOffset.Now;
                        soht.SaleNextAction = db.FindSaleNextActions()
                                              .Where(sna => sna.Id == (int)Enumerations.SaleNextAction.None)
                                              .FirstOrDefault();

                        db.InsertOrUpdateSalesOrderHeaderTemp(soht);
                        result = mapToModel(soht);
                    }
                    else
                    {
                        // Editing an existing order
                        // Copy the header
                        soht = db.FindSalesOrderHeaderTemps(company.Id)
                               .Where(p => p.UserId == user.Id &&
                                      p.OriginalRowId == salesOrderHeader.Id)
                               .FirstOrDefault();
                        if (soht != null)
                        {
                            // Already exists in the temp tables so update it with the latest data
                            int tempId = soht.Id;
                            Mapper.Map <SalesOrderHeader, SalesOrderHeaderTemp>(soh, soht);
                            soht.Id            = tempId;
                            soht.OriginalRowId = (createCopyOfOrder ? 0 : salesOrderHeader.Id);
                            soht.UserId        = user.Id;

                            db.InsertOrUpdateSalesOrderHeaderTemp(soht);
                            result = mapToModel(soht);
                        }
                        else
                        {
                            // Doesn't exist, so copy
                            soht               = Mapper.Map <SalesOrderHeader, SalesOrderHeaderTemp>(soh);
                            soht.Id            = 0;
                            soht.OriginalRowId = (createCopyOfOrder ? 0 : salesOrderHeader.Id);
                            soht.UserId        = user.Id;

                            db.InsertOrUpdateSalesOrderHeaderTemp(soht);
                            result = mapToModel(soht);
                        }
                    }

                    // Now copy/merge the details
                    db.CopySaleToTemp(company.Id, user.Id, salesOrderHeader.Id, soht.Id, (createCopyOfOrder ? 1 : 0));
                }
            }
            else
            {
                // New sale
                soht.CompanyId        = company.Id;
                soht.UserId           = user.Id;
                soht.OrderNumber      = salesOrderHeader.OrderNumber;
                soht.OrderDate        = salesOrderHeader.OrderDate;
                soht.SalespersonId    = salesOrderHeader.SalespersonId;
                soht.BrandCategoryId  = salesOrderHeader.BrandCategoryId;
                soht.LocationId       = salesOrderHeader.LocationId;
                soht.ShipCountryId    = salesOrderHeader.ShipCountryId;
                soht.FreightCarrierId = salesOrderHeader.FreightCarrierId;
                soht.FreightTermId    = salesOrderHeader.FreightTermId;
                soht.NextActionId     = salesOrderHeader.NextActionId;

                db.InsertOrUpdateSalesOrderHeaderTemp(soht);
                result = Mapper.Map <SalesOrderHeaderTemp, SalesOrderHeaderTempModel>(soht);
            }

            return(result);
        }