Ejemplo n.º 1
0
        public void CreateCustomerPricing(CustomerPricingViewModel custPricingViewModel)
        {
            var custPricing = Mapper.Map <CustomerPricingViewModel, CustomerPricing_H>(custPricingViewModel);

            custPricing.CustomerPricingId = Guid.NewGuid().ToString();
            _customerPricingRepository.Add(custPricing);

            InsertCustomerPricingExpenses(custPricing.CustomerPricingId, custPricingViewModel);
            InsertSelectedReferences(custPricing.CustomerPricingId, custPricingViewModel);

            SaveCustomerPricing();
        }
Ejemplo n.º 2
0
        private void InsertSelectedReferences(string custPricingId, CustomerPricingViewModel custPricingViewModel)
        {
            var listExpense = new List <CustomerPricingDetailViewModel>();

            listExpense.AddRange(custPricingViewModel.ExpenseList);
            listExpense.AddRange(custPricingViewModel.AllowanceList);
            listExpense.AddRange(custPricingViewModel.FixedExpenseList);
            listExpense.AddRange(custPricingViewModel.OtherExpenseList);

            var expenseRouteRoot   = Convert.ToInt32(ExpenseRoot.Route).ToString();
            var referenceRouteData = (from p in listExpense
                                      where p.ExpenseRoot == expenseRouteRoot
                                      group p by new { p.RouteId, p.ExpenseRoot }
                                      into g
                                      select new CustomerPricingLocation_D()
            {
                CustomerPricingId = custPricingId,
                RouteId = g.Key.RouteId,
                ExpenseRoot = g.Key.ExpenseRoot
            }).ToList();

            if (referenceRouteData.Any())
            {
                foreach (var reference in referenceRouteData)
                {
                    _customerPricingLocationRepository.Add(reference);
                }
            }

            var expenseHistoryRoot   = Convert.ToInt32(ExpenseRoot.History).ToString();
            var referenceHistoryData = (from p in listExpense
                                        where p.ExpenseRoot == expenseHistoryRoot
                                        group p by new { p.OrderD, p.OrderNo, p.DetailNo, p.DispatchNo, p.ExpenseRoot }
                                        into g
                                        select new CustomerPricingLocation_D()
            {
                CustomerPricingId = custPricingId,
                OrderD = g.Key.OrderD,
                OrderNo = g.Key.OrderNo,
                DetailNo = g.Key.DetailNo,
                DispatchNo = g.Key.DispatchNo,
                ExpenseRoot = g.Key.ExpenseRoot,
            }).ToList();

            if (referenceHistoryData.Any())
            {
                foreach (var reference in referenceHistoryData)
                {
                    _customerPricingLocationRepository.Add(reference);
                }
            }
        }
Ejemplo n.º 3
0
        //CRUD
        private void InsertCustomerPricingExpenses(string custPricingId, CustomerPricingViewModel custPricingViewModel)
        {
            if (custPricingViewModel.ExpenseList != null && custPricingViewModel.ExpenseList.Count > 0)
            {
                for (var i = 0; i < custPricingViewModel.ExpenseList.Count; i++)
                {
                    var expense = Mapper.Map <CustomerPricingDetailViewModel, CustomerPricing_D>(custPricingViewModel.ExpenseList[i]);
                    expense.CustomerPricingExpenseId = Guid.NewGuid().ToString();
                    expense.CustomerPricingId        = custPricingId;
                    expense.CategoryI = Convert.ToInt32(ExpenseCategory.Expense).ToString();
                    _customerPricingDetailRepository.Add(expense);
                }
            }

            if (custPricingViewModel.AllowanceList != null && custPricingViewModel.AllowanceList.Count > 0)
            {
                for (var i = 0; i < custPricingViewModel.AllowanceList.Count; i++)
                {
                    var expense = Mapper.Map <CustomerPricingDetailViewModel, CustomerPricing_D>(custPricingViewModel.AllowanceList[i]);
                    expense.CustomerPricingExpenseId = Guid.NewGuid().ToString();
                    expense.CustomerPricingId        = custPricingId;
                    expense.CategoryI = Convert.ToInt32(ExpenseCategory.Allowance).ToString();
                    _customerPricingDetailRepository.Add(expense);
                }
            }

            if (custPricingViewModel.FixedExpenseList != null && custPricingViewModel.FixedExpenseList.Count > 0)
            {
                for (var i = 0; i < custPricingViewModel.FixedExpenseList.Count; i++)
                {
                    var expense = Mapper.Map <CustomerPricingDetailViewModel, CustomerPricing_D>(custPricingViewModel.FixedExpenseList[i]);
                    expense.CustomerPricingExpenseId = Guid.NewGuid().ToString();
                    expense.CustomerPricingId        = custPricingId;
                    expense.CategoryI = Convert.ToInt32(ExpenseCategory.Fix).ToString();
                    _customerPricingDetailRepository.Add(expense);
                }
            }

            if (custPricingViewModel.OtherExpenseList != null && custPricingViewModel.OtherExpenseList.Count > 0)
            {
                for (var i = 0; i < custPricingViewModel.OtherExpenseList.Count; i++)
                {
                    var expense = Mapper.Map <CustomerPricingDetailViewModel, CustomerPricing_D>(custPricingViewModel.OtherExpenseList[i]);
                    expense.CustomerPricingExpenseId = Guid.NewGuid().ToString();
                    expense.CustomerPricingId        = custPricingId;
                    expense.CategoryI = Convert.ToInt32(ExpenseCategory.Other).ToString();
                    _customerPricingDetailRepository.Add(expense);
                }
            }
        }
Ejemplo n.º 4
0
        public void UpdateCustomerPricing(CustomerPricingViewModel custPricingViewModel)
        {
            var custPricing = _customerPricingRepository.Query(p => p.CustomerPricingId == custPricingViewModel.CustomerPricingId).FirstOrDefault();

            if (custPricing != null)
            {
                custPricing.EstimatedPrice   = custPricingViewModel.EstimatedPrice;
                custPricing.TotalExpense     = custPricingViewModel.TotalExpense;
                custPricing.GrossProfitRatio = custPricingViewModel.GrossProfitRatio;
                _customerPricingRepository.Update(custPricing);

                //UPDATE ROUTE EXPENSES
                _customerPricingDetailRepository.Delete(p => p.CustomerPricingId == custPricingViewModel.CustomerPricingId);
                _customerPricingLocationRepository.Delete(p => p.CustomerPricingId == custPricingViewModel.CustomerPricingId);
                InsertCustomerPricingExpenses(custPricing.CustomerPricingId, custPricingViewModel);
                InsertSelectedReferences(custPricing.CustomerPricingId, custPricingViewModel);
                SaveCustomerPricing();
            }
        }
Ejemplo n.º 5
0
        public CustomerPricingViewModel GetCustomerPricing(string loc1C, string loc2C, string conSizeI, string conTypeC,
                                                           DateTime estimatedD, string customerSubC, string customerMainC)
        {
            var custPricing = _customerPricingRepository.Query(
                p => p.Location1C == loc1C & p.Location2C == loc2C & p.ContainerSizeI == conSizeI & p.ContainerTypeC == conTypeC & p.EstimatedD == estimatedD &
                (customerMainC == null || customerMainC == "null" ||
                 (p.CustomerMainC == customerMainC && p.CustomerSubC == customerSubC)
                )).FirstOrDefault();

            if (custPricing != null)
            {
                var custPricingViewModel = Mapper.Map <CustomerPricing_H, CustomerPricingViewModel>(custPricing);
                custPricingViewModel       = GetCustomerPricingExpenses(custPricingViewModel);
                custPricingViewModel.Index = FindIndex(custPricingViewModel.CustomerPricingId);
                return(custPricingViewModel);
            }
            else
            {
                var custPricingViewModel = new CustomerPricingViewModel();
                custPricingViewModel.GrossProfitRatio = 0;
                var mainCode     = customerMainC;
                var profitmarkup = (from p in _customerRepository.GetAllQueryable()
                                    join g in _customerGrossProfitRepository.GetAllQueryable() on p.CustomerMainC equals g.CustomerMainC into pg
                                    from g in pg.DefaultIfEmpty()
                                    where p.CustomerMainC == mainCode && g.ApplyD <= estimatedD
                                    select g).ToList();

                if (profitmarkup.Any())
                {
                    var customerGrossProfitM = profitmarkup.FirstOrDefault(p => p.ApplyD == profitmarkup.Max(b => b.ApplyD));
                    if (customerGrossProfitM != null)
                    {
                        custPricingViewModel.GrossProfitRatio = customerGrossProfitM.GrossProfitRatio;
                        return(custPricingViewModel);
                    }
                }
                return(null);
            }
        }
Ejemplo n.º 6
0
        private CustomerPricingViewModel GetCustomerPricingExpenses(CustomerPricingViewModel custPricingViewModel)
        {
            //Get route expense list
            var expenseCate        = Convert.ToInt32(ExpenseCategory.Expense).ToString();
            var expensesDepartment = _customerPricingDetailRepository.Query(
                p => p.CustomerPricingId == custPricingViewModel.CustomerPricingId & p.CategoryI == expenseCate);

            var expensesDestination = Mapper.Map <IEnumerable <CustomerPricing_D>, IEnumerable <CustomerPricingDetailViewModel> >(expensesDepartment);

            //Get route allowance list
            var allowanceCate       = Convert.ToInt32(ExpenseCategory.Allowance).ToString();
            var allowancesDeparment = _customerPricingDetailRepository.Query(
                p => p.CustomerPricingId == custPricingViewModel.CustomerPricingId & p.CategoryI == allowanceCate);

            var allowancesDestination = Mapper.Map <IEnumerable <CustomerPricing_D>, IEnumerable <CustomerPricingDetailViewModel> >(allowancesDeparment);

            //Get route fixed expense list
            var fixedCate = Convert.ToInt32(ExpenseCategory.Fix).ToString();
            var fixedExpensesDeparment = _customerPricingDetailRepository.Query(
                p => p.CustomerPricingId == custPricingViewModel.CustomerPricingId & p.CategoryI == fixedCate);

            var fixedExpensesDestination = Mapper.Map <IEnumerable <CustomerPricing_D>, IEnumerable <CustomerPricingDetailViewModel> >(fixedExpensesDeparment);

            //Get route other expense list
            var otherCate = Convert.ToInt32(ExpenseCategory.Other).ToString();
            var otherExpensesDeparment = _customerPricingDetailRepository.Query(
                p => p.CustomerPricingId == custPricingViewModel.CustomerPricingId & p.CategoryI == otherCate);

            var otherExpensesDestination = Mapper.Map <IEnumerable <CustomerPricing_D>, IEnumerable <CustomerPricingDetailViewModel> >(otherExpensesDeparment);

            custPricingViewModel.ExpenseList      = expensesDestination == null ? null : expensesDestination.ToList();
            custPricingViewModel.AllowanceList    = allowancesDestination == null ? null : allowancesDestination.ToList();
            custPricingViewModel.FixedExpenseList = fixedExpensesDestination == null ? null : fixedExpensesDestination.ToList();
            custPricingViewModel.OtherExpenseList = otherExpensesDestination == null ? null : otherExpensesDestination.ToList();
            return(custPricingViewModel);
        }
 // PUT api/<controller>/5
 //[Authorize(Roles = "CustomerPricing_E")]
 public void Put(CustomerPricingViewModel routeViewModel)
 {
     _customerPricingService.UpdateCustomerPricing(routeViewModel);
 }
 // POST api/<controller>
 //[Authorize(Roles = "CustomerPricing_A")]
 public void Post(CustomerPricingViewModel custPricingViewModel)
 {
     _customerPricingService.CreateCustomerPricing(custPricingViewModel);
 }