public List <DeliveryStatusViewModel> Match(List <Delivery> _deliveries)
        {
            BranchCorpOfficeBL bcoService             = new BranchCorpOfficeBL();
            DeliveryStatusBL   status                 = new DeliveryStatusBL();
            DeliveryRemarkBL   remark                 = new DeliveryRemarkBL();
            DistributionBL     distributionService    = new DistributionBL();
            DeliveryReceiptBL  deliveryReceiptService = new DeliveryReceiptBL();
            ShipmentBL         shipmentService        = new ShipmentBL();
            PackageNumberBL    _packageNumberService  = new PackageNumberBL();

            List <DeliveryStatusViewModel> _results = new List <DeliveryStatusViewModel>();

            List <Distribution> distributions = distributionService.GetAll().ToList();

            List <DeliveryReceipt> deliveryReceipt = deliveryReceiptService.GetAll().ToList();
            UserStore _userService = new UserStore();

            foreach (Delivery delivery in _deliveries)
            {
                DeliveryStatusViewModel model = new DeliveryStatusViewModel();

                DeliveryStatusViewModel isExist = _results.Find(x => x.AirwayBillNo == delivery.Shipment.AirwayBillNo);


                if (isExist != null)
                {
                    isExist.QTY++;
                }
                else
                {
                    model.AirwayBillNo = delivery.Shipment.AirwayBillNo;
                    model.QTY          = _packageNumberService.FilterActiveBy(x => x.Shipment.AirwayBillNo == delivery.Shipment.AirwayBillNo).Count;
                    model.Status       = delivery.DeliveryStatus.DeliveryStatusName;
                    model.Remarks      = "NA";
                    model.DeliveredBy  = delivery.DeliveredBy.FullName;
                    if (delivery.DeliveryRemarkId != null)
                    {
                        model.Remarks = delivery.DeliveryRemark.DeliveryRemarkName;
                    }
                    Distribution    dis      = distributions.Find(x => x.ShipmentId == delivery.ShipmentId);
                    DeliveryReceipt dReceipt = deliveryReceipt.Find(x => x.DeliveryId == delivery.DeliveryId);
                    //List<Distribution> list = distributions.Where( x => x.ShipmentId == delivery.ShipmentId).Distinct().ToList();
                    //foreach(Distribution dis in list)
                    //{
                    //    //model.Area = dis.Area.RevenueUnitName;
                    //    model.Driver = dis.Driver;
                    //    model.Checker = dis.Checker;
                    //    model.Batch = dis.Batch.BatchName;
                    //    model.PlateNo = dis.PlateNo;
                    //    model.BCO = dis.Area.City.BranchCorpOffice.BranchCorpOfficeName;
                    //}
                    model.Area    = dis.Area.RevenueUnitName;
                    model.Driver  = dis.Driver;
                    model.Checker = dis.Checker;
                    model.Batch   = dis.Batch.BatchName;
                    model.PlateNo = dis.PlateNo;
                    model.BCO     = dis.Area.City.BranchCorpOffice.BranchCorpOfficeName;
                    //model.ScannedBy = AppUser.User.Employee.FullName;
                    model.ScannedBy = "N/A";
                    string employee = _userService.FindById(dis.CreatedBy).Employee.FullName;
                    if (employee != "")
                    {
                        model.ScannedBy = employee;
                    }
                    model.ReceivedBy = "NA";
                    if (dReceipt != null)
                    {
                        model.ReceivedBy = dReceipt.ReceivedBy;
                    }

                    _results.Add(model);
                }
            }

            //List<BranchCorpOffice> _bco= bcoService.GetAll().Where(x => x.RecordStatus == 1 && x.BranchCorpOfficeId == GlobalVars.DeviceBcoId).ToList();
            //string bcoName = bcoService.GetAll().Where(x => x.BranchCorpOfficeId == GlobalVars.DeviceBcoId).Select(x => x.BranchCorpOfficeName).ToString();
            //string bcoName = _bco.Select(x => x.BranchCorpOfficeName).ToString();
            string bcoName = bcoService.GetAll().Find(x => x.BranchCorpOfficeId == GlobalVars.DeviceBcoId).BranchCorpOfficeName;
            List <DeliveryStatusViewModel> _resultsFilter = _results.FindAll(x => x.BCO == bcoName);

            //List<DeliveryStatusViewModel> resultList = modelList.FindAll(x => x.Area == revenueUnitName);
            //return _results;
            return(_resultsFilter);
        }
Example #2
0
        public List <GatewayOutboundViewModel> Match(List <GatewayInbound> _inbound, List <GatewayOutbound> _outbound)
        {
            PackageNumberBL _packageNumberService    = new PackageNumberBL();
            List <GatewayOutboundViewModel> _results = new List <GatewayOutboundViewModel>();
            PackageNumber _packageNumber             = new PackageNumber();
            List <string> listCargo     = new List <string>();
            BundleBL      bundleService = new BundleBL();
            UserStore     _userService  = new UserStore();

            foreach (GatewayOutbound outbound in _outbound)
            {
                GatewayOutboundViewModel model = new GatewayOutboundViewModel();
                string _airwaybill             = "";
                try {
                    //_airwaybill = _packageNumberService.GetAll().Find(x => x.PackageNo == outbound.Cargo).Shipment.AirwayBillNo;
                    _packageNumber = _packageNumberService.FilterActive().Where(x => x.PackageNo == outbound.Cargo).FirstOrDefault();
                    if (_packageNumber == null)
                    {
                        GatewayOutboundViewModel model1 = new GatewayOutboundViewModel();
                        listCargo = bundleService.GetAll().Where(x => x.SackNo == outbound.Cargo).Select(y => y.Cargo).ToList();
                        if (listCargo != null && listCargo.Count != 0)
                        {
                            GatewayOutboundViewModel isExist = _results.Find(x => x.AirwayBillNo == outbound.Cargo);
                            if (_inbound.Exists(x => x.Cargo == outbound.Cargo))
                            {
                                if (isExist != null)
                                {
                                    isExist.TotalRecieved++;
                                    isExist.Total = isExist.TotalRecieved;
                                }
                                else
                                {
                                    model1.AirwayBillNo  = outbound.Cargo;
                                    model1.Gateway       = outbound.Gateway;
                                    model1.Driver        = outbound.Driver;
                                    model1.PlateNo       = outbound.PlateNo;
                                    model1.Batch         = outbound.Batch.BatchName;
                                    model1.TotalRecieved = listCargo.Count;
                                    model1.Total         = model1.TotalRecieved;
                                    model1.Branch        = outbound.BranchCorpOffice.BranchCorpOfficeName;
                                    // model1.ScannedBy = AppUser.User.Employee.FullName;
                                    model1.ScannedBy = "N/A";
                                    //string employee = _userService.FilterActive().Find(x => x.UserId == _bundle.CreatedBy).Employee.FullName;
                                    string employee = _userService.FindById(outbound.CreatedBy).Employee.FullName;
                                    if (employee != "")
                                    {
                                        model1.ScannedBy = employee;
                                    }
                                    model1.CommodityTypeName = "N/A";
                                    //model1.CommodityTypeName = _packageNumberService.FilterActiveBy(x => x.PackageNo == outbound.Cargo).First().Shipment.CommodityType.CommodityTypeName;
                                    _results.Add(model1);
                                }
                            }
                            else
                            {
                                if (isExist != null)
                                {
                                    isExist.TotalDiscrepency++;
                                    isExist.Total = isExist.TotalDiscrepency;
                                }
                                else
                                {
                                    model1.AirwayBillNo     = outbound.Cargo;
                                    model1.Gateway          = outbound.Gateway;
                                    model1.Driver           = outbound.Driver;
                                    model1.PlateNo          = outbound.PlateNo;
                                    model1.Batch            = outbound.Batch.BatchName;
                                    model1.TotalDiscrepency = listCargo.Count;
                                    model1.Total            = model1.TotalDiscrepency;
                                    model1.Branch           = outbound.BranchCorpOffice.BranchCorpOfficeName;
                                    //model1.ScannedBy = "N/A";
                                    string employee = _userService.FindById(outbound.CreatedBy).Employee.FullName;
                                    if (employee != "")
                                    {
                                        model1.ScannedBy = employee;
                                    }
                                    model1.CommodityTypeName = "N/A";
                                    //model1.CommodityTypeName = _packageNumberService.FilterActiveBy(x => x.PackageNo == outbound.Cargo).First().Shipment.CommodityType.CommodityTypeName;
                                    _results.Add(model1);
                                }
                            }
                        }
                    }
                    else
                    {
                        _airwaybill = _packageNumber.Shipment.AirwayBillNo;
                        GatewayOutboundViewModel isExist = _results.Find(x => x.AirwayBillNo == _airwaybill);
                        if (_inbound.Exists(x => x.Cargo == outbound.Cargo))
                        {
                            if (isExist != null)
                            {
                                isExist.TotalRecieved++;
                                isExist.Total = isExist.TotalRecieved;
                                //model.Total = model.TotalRecieved;
                                //_results.Add(isExist);
                            }
                            else
                            {
                                model.AirwayBillNo = _airwaybill;
                                model.Gateway      = outbound.Gateway;
                                model.Driver       = outbound.Driver;
                                model.PlateNo      = outbound.PlateNo;
                                model.Batch        = outbound.Batch.BatchName;
                                model.TotalRecieved++;
                                model.Total  = model.TotalRecieved;
                                model.Branch = outbound.BranchCorpOffice.BranchCorpOfficeName;
                                //model.ScannedBy = AppUser.User.Employee.FullName;
                                string employee = _userService.FindById(outbound.CreatedBy).Employee.FullName;
                                if (employee != "")
                                {
                                    model.ScannedBy = employee;
                                }
                                //model.CommodityTypeName = _inbound.Where(x => x.Cargo == outbound.Cargo).Select(x => x.CommodityType.CommodityTypeName).ToString();
                                // model.CommodityTypeName = _inbound.Find(x => x.Cargo == outbound.Cargo).CommodityType.CommodityTypeName;
                                model.CommodityTypeName = _packageNumberService.FilterActiveBy(x => x.PackageNo == outbound.Cargo).First().Shipment.CommodityType.CommodityTypeName;
                                _results.Add(model);
                            }
                        }
                        else
                        {
                            if (isExist != null)
                            {
                                isExist.TotalDiscrepency++;
                                isExist.Total = isExist.TotalDiscrepency;
                                //model.Total = model.TotalDiscrepency;
                                //_results.Add(isExist);
                            }
                            else
                            {
                                model.AirwayBillNo = _airwaybill;
                                model.Gateway      = outbound.Gateway;
                                model.Driver       = outbound.Driver;
                                model.PlateNo      = outbound.PlateNo;
                                model.Batch        = outbound.Batch.BatchName;
                                model.TotalDiscrepency++;
                                model.Total  = model.TotalDiscrepency;
                                model.Branch = outbound.BranchCorpOffice.BranchCorpOfficeName;
                                string employee = _userService.FindById(outbound.CreatedBy).Employee.FullName;
                                if (employee != "")
                                {
                                    model.ScannedBy = employee;
                                }
                                //model.CommodityTypeName = _inbound.Find(x => x.Cargo == outbound.Cargo).CommodityType.CommodityTypeName;
                                // model.CommodityTypeName = _inbound.Where(x => x.Cargo == outbound.Cargo).Select(x => x.CommodityType.CommodityTypeName).ToString();
                                model.CommodityTypeName = _packageNumberService.FilterActiveBy(x => x.PackageNo == outbound.Cargo).First().Shipment.CommodityType.CommodityTypeName;
                                _results.Add(model);
                            }
                        }
                    }
                }
                catch (Exception) { continue; }
            }


            return(_results);
        }