Ejemplo n.º 1
0
        public IEnumerable <OrderPatternViewModel> GetPatterns(string custMainCode, string custSubCode)
        {
            var patterns = _orderPatternRepository.Query(pat => pat.CustomerMainC == custMainCode && pat.CustomerSubC == custSubCode);

            if (patterns != null)
            {
                var destination = Mapper.Map <IEnumerable <OrderPattern_M>, IEnumerable <OrderPatternViewModel> >(patterns);
                return(destination);
            }
            return(null);
        }
Ejemplo n.º 2
0
        public OrderViewModel GetOrder(string no, DateTime date)
        {
            var orders = _orderRepository.Query(o => o.OrderNo.Equals(no) && o.OrderD == date).ToList();

            if (orders.Count <= 0)
            {
                return(null);
            }
            var mOrder = Mapper.Map <Order_H, OrderViewModel>(orders.FirstOrDefault());

            var employee =
                _employeeRepository.Query(p => p.EmployeeC == mOrder.EntryClerkC)
                .Select(p => new { p.EmployeeFirstN, p.EmployeeLastN, p.RetiredD }).FirstOrDefault();

            if (employee != null)
            {
                mOrder.EntryClerkN = employee.EmployeeLastN + " " + employee.EmployeeFirstN;
                mOrder.RetiredD    = employee.RetiredD;
            }

            var customer =
                _customerRepository.Query(p => p.CustomerMainC == mOrder.CustomerMainC && p.CustomerSubC == mOrder.CustomerSubC)
                .Select(p => new { p.CustomerN, p.IsCollected }).FirstOrDefault();

            if (customer != null)
            {
                mOrder.CustomerN = customer.CustomerN;
                mOrder.IsCollectedByMasterCustomer = customer.IsCollected;
            }

            var customerPay =
                _customerRepository.Query(p => p.CustomerMainC == mOrder.CustomerPayLiftLoweredMainC && p.CustomerSubC == mOrder.CustomerPayLiftLoweredSubC)
                .Select(p => new { p.CustomerN }).FirstOrDefault();

            if (customerPay != null)
            {
                mOrder.CustomerPayLiftLoweredN = customerPay.CustomerN;
            }

            var pattern =
                _orderPatternRepository.Query(
                    p =>
                    p.CustomerMainC == mOrder.CustomerMainC && p.CustomerSubC == mOrder.CustomerSubC &&
                    p.OrderPatternC == mOrder.OrderPatternC)
                .FirstOrDefault();

            if (pattern != null)
            {
                mOrder.OrderPatternN = pattern.OrderPatternN;
            }

            mOrder.OrderIndex = FindIndex(mOrder.OrderD, mOrder.OrderNo);

            //get containers
            var containers = _containerRepository.Query(c => c.OrderNo.Equals(mOrder.OrderNo) && c.OrderD == mOrder.OrderD).ToList();

            //if (containers.Count > 0)
            //{
            //	foreach (var container in containers)
            //	{
            //		var mContainer = Mapper.Map<Order_D, ContainerViewModel>(container);
            //		mCOntainers.Add(mContainer);
            //	}
            //	mOrder.Containers = mCOntainers;
            //}
            if (containers.Any())
            {
                var mContainers = (from c in containers
                                   join t in _containerTypeRepository.GetAllQueryable() on c.ContainerTypeC equals t.ContainerTypeC into ct
                                   from t in ct.DefaultIfEmpty()
                                   select new ContainerViewModel()
                {
                    OrderD = c.OrderD,
                    OrderNo = c.OrderNo,
                    DetailNo = c.DetailNo,
                    ContainerNo = c.ContainerNo,
                    ContainerSizeI = c.ContainerSizeI,
                    ContainerTypeC = c.ContainerTypeC,
                    ContainerTypeN = t != null ? t.ContainerTypeN : "",
                    CommodityC = c.CommodityC,
                    CommodityN = c.CommodityN,
                    NetWeight = c.NetWeight,
                    GrossWeight = c.GrossWeight,
                    TotalPrice = c.TotalPrice,
                    UnitPrice = c.UnitPrice,
                    SealNo = c.SealNo,
                    Description = c.Description,
                    EstimatedWeight = c.EstimatedWeight,
                    CalculateByTon = c.CalculateByTon,
                }).ToList();

                mOrder.Containers = mContainers;
            }

            //Check min, max OrderNo
            mOrder.IsMaxOrderNo = CheckOrderNoMax(date, no);
            mOrder.IsMinOrderNo = CheckOrderNoMin(date, no);

            return(mOrder);
        }