public IHttpActionResult GetInboundLog([FromUri] int masterOrderId)
        {
            var masterOrderInDb = _context.FBAMasterOrders.Find(masterOrderId);

            var log = new InboundLog {
                InboundDate      = masterOrderInDb.InboundDate,
                UnloadFinishTime = masterOrderInDb.UnloadFinishTime,
                AvailableTime    = masterOrderInDb.AvailableTime,
                OutTime          = masterOrderInDb.OutTime,
                DockNumber       = masterOrderInDb.DockNumber,
                VerifiedBy       = masterOrderInDb.VerifiedBy
            };

            return(Ok(log));
        }
        public IHttpActionResult GetAllProcessingMasterOrders()
        {
            //获取FBA部门的所有待收货主单
            var masterOrders = _context.FBAMasterOrders
                               .Include(x => x.Customer)
                               .Include(x => x.FBAOrderDetails.Select(c => c.FBACartonLocations))
                               .Include(x => x.FBAPallets)
                               .Where(x => x.Status != FBAStatus.NewCreated && x.Status != "Old Order")
                               .ToList();

            var inboundLogList = new List <InboundLog>();

            foreach (var m in masterOrders)
            {
                var newLog = new InboundLog {
                    Id               = m.Id,
                    Status           = m.Status,
                    Department       = DepartmentCode.FBA,
                    Customer         = m.Customer.CustomerCode,
                    InboundType      = m.InboundType,
                    ETA              = m.ETA,
                    InboundDate      = m.InboundDate,
                    DockNumber       = m.DockNumber,
                    Container        = m.Container,
                    Ctns             = m.FBAOrderDetails.Sum(x => x.Quantity),
                    SKU              = m.FBAOrderDetails.GroupBy(x => x.ShipmentId).Count(),
                    OriginalPlts     = m.OriginalPlts,
                    Carrier          = m.Carrier,
                    Lumper           = m.Lumper,
                    Instruction      = m.Instruction,
                    PushTime         = m.PushTime,
                    AvailableTime    = m.AvailableTime,
                    OutTime          = m.OutTime,
                    UnloadFinishTime = m.UnloadFinishTime,
                    UnloadStartTime  = m.UnloadStartTime,
                    UpdateLog        = m.UpdateLog,
                    VerifiedBy       = m.VerifiedBy
                };

                inboundLogList.Add(newLog);
            }

            //获取所有服装部待收货主单
            //

            return(Ok(inboundLogList));
        }
        public void UpdateMasterOrderFromWarehouse([FromUri] int masterOrderId, [FromUri] string operation, [FromBody] InboundLog log)
        {
            var orderInDb = _context.FBAMasterOrders
                            .Include(x => x.FBAOrderDetails)
                            .Include(x => x.ChargingItemDetails)
                            .SingleOrDefault(x => x.Id == masterOrderId);

            orderInDb.InboundDate      = log.InboundDate;
            orderInDb.UnloadFinishTime = log.UnloadFinishTime;
            orderInDb.AvailableTime    = log.AvailableTime;
            orderInDb.OutTime          = log.OutTime;
            orderInDb.DockNumber       = log.DockNumber;
            orderInDb.VerifiedBy       = log.VerifiedBy;

            if (operation == "Report")
            {
                //以上5个信息是都填了且收货数量大于0且所有命令都被执行才能被完整确认收货
                if (CheckIfAllFieldsAreFilled(orderInDb) && CheckIfCanBeReceived(orderInDb) && CheckIfAllOrdersAreFinished(orderInDb))
                {
                    orderInDb.Status = FBAStatus.Received;
                }
                else
                {
                    throw new Exception("Inbound date, Finish time, Dock # and Verified by must be updated before submit unloading report.");
                }
            }

            _context.SaveChanges();
        }