예제 #1
0
        private static string validateShipment(OrderShipmentLine model)
        {
            decimal          totalQty    = model.ThisShipQuantity;
            OrderDetailModel orderDetail = OrderHelper.GetSingleOrderDetail(model.LineId);
            List <Shipment>  shiped      = new List <Shipment>();

            if (model.Id > 0)
            {
                shiped = service.GetAllByLineId(AuthenticationHelper.CompanyId.Value, SessionHelper.SOBId, model.LineId)
                         .Where(rec => rec.Id < model.Id).ToList();
            }
            else
            {
                shiped = service.GetAllByLineId(AuthenticationHelper.CompanyId.Value, SessionHelper.SOBId, model.LineId).ToList();
            }

            if (shiped != null && shiped.Count() > 0)
            {
                totalQty += shiped.Sum(rec => rec.Quantity);
            }
            if (totalQty > orderDetail.Quantity)
            {
                return("Quantity is exceeding than order!");
            }

            string lotAndSerialValidation = checkLotandSerials(model);

            if (!string.IsNullOrEmpty(lotAndSerialValidation))
            {
                return(lotAndSerialValidation);
            }

            //Other validations if any..

            OrderShipmentModel orderShipment = SessionHelper.Shipment;

            if (model.Id > 0)
            {
                orderShipment.OrderShipments.First(x => x.LineId == model.LineId).BalanceQuantity = orderDetail.Quantity - (shiped.Sum(rec => rec.Quantity) + model.ThisShipQuantity);
                orderShipment.OrderShipments.First(x => x.LineId == model.LineId).Id               = model.Id;
                orderShipment.OrderShipments.First(x => x.LineId == model.LineId).LocatorId        = model.LocatorId;
                orderShipment.OrderShipments.First(x => x.LineId == model.LineId).LotNoId          = model.LotNoId;
                orderShipment.OrderShipments.First(x => x.LineId == model.LineId).OrderQuantity    = orderDetail.Quantity;
                orderShipment.OrderShipments.First(x => x.LineId == model.LineId).SerialNo         = model.SerialNo;
                orderShipment.OrderShipments.First(x => x.LineId == model.LineId).ShipedQuantity   = shiped.Sum(rec => rec.Quantity);
                orderShipment.OrderShipments.First(x => x.LineId == model.LineId).ThisShipQuantity = model.ThisShipQuantity;
            }
            else
            {
                if (orderShipment.OrderShipments.Any(x => x.LineId == model.LineId))
                {
                    orderShipment.OrderShipments.First(x => x.LineId == model.LineId).BalanceQuantity = orderDetail.Quantity - (shiped.Sum(rec => rec.Quantity) + model.ThisShipQuantity);
                    orderShipment.OrderShipments.First(x => x.LineId == model.LineId).Id               = model.Id;
                    orderShipment.OrderShipments.First(x => x.LineId == model.LineId).LocatorId        = model.LocatorId;
                    orderShipment.OrderShipments.First(x => x.LineId == model.LineId).LotNoId          = model.LotNoId;
                    orderShipment.OrderShipments.First(x => x.LineId == model.LineId).OrderQuantity    = orderDetail.Quantity;
                    orderShipment.OrderShipments.First(x => x.LineId == model.LineId).SerialNo         = model.SerialNo;
                    orderShipment.OrderShipments.First(x => x.LineId == model.LineId).ShipedQuantity   = shiped.Sum(rec => rec.Quantity);
                    orderShipment.OrderShipments.First(x => x.LineId == model.LineId).ThisShipQuantity = model.ThisShipQuantity;
                }
                else
                {
                    //Never be in this case..
                    orderShipment.OrderShipments.Add(new OrderShipmentLine
                    {
                        BalanceQuantity = orderDetail.Quantity - (shiped.Sum(rec => rec.Quantity) + model.ThisShipQuantity),
                        Id               = model.Id,
                        ItemName         = model.ItemName,
                        LineId           = model.LineId,
                        LocatorId        = model.LocatorId,
                        LotNoId          = model.LotNoId,
                        OrderQuantity    = orderDetail.Quantity,
                        SerialNo         = model.SerialNo,
                        ShipedQuantity   = shiped.Sum(rec => rec.Quantity),
                        ThisShipQuantity = model.ThisShipQuantity
                    });
                }
            }
            return("");
        }
예제 #2
0
        public static string Save(OrderShipmentModel model)
        {
            List <long> orderIds = new List <long>();
            string      result   = "";

            if (model.OrderShipments != null && model.OrderShipments.Count() > 0)
            {
                model.OrderShipments = model.OrderShipments.Where(rec => rec.LocatorId > 0).ToList();
            }

            List <Shipment> currentShipments = getEntitiesByModel(model);

            if (currentShipments != null && currentShipments.Count() > 0)
            {
                if (model.DeliveryNo != "New")
                {
                    List <Shipment> savedShipment = service.GetDelivery(AuthenticationHelper.CompanyId.Value, SessionHelper.SOBId, model.DeliveryNo, model.DeliveryDate).ToList();
                    if (savedShipment != null && savedShipment.Count() > 0)
                    {
                        if (savedShipment.Count() > currentShipments.Count())
                        {
                            List <Shipment> tobeDeleted = savedShipment.Take(savedShipment.Count() - currentShipments.Count()).ToList();
                            foreach (var deleteSingle in tobeDeleted)
                            {
                                if (!string.IsNullOrEmpty(deleteSingle.SerialNo))
                                {
                                    List <string> serials = deleteSingle.SerialNo.Split(new char[] { ',' }).ToList();
                                    deleteSerials(serials, deleteSingle.LotNoId.Value);
                                }

                                orderIds.Add(deleteSingle.OrderId);
                                service.Delete(deleteSingle.Id.ToString(), AuthenticationHelper.CompanyId.Value);
                            }
                        }
                    }
                }
                foreach (var item in currentShipments)
                {
                    List <ShipmentModel> shipments   = GetShipments(item.LineId);
                    OrderDetailModel     orderDetail = OrderHelper.GetSingleOrderDetail(item.LineId);
                    decimal savedQty = 0;
                    if (shipments != null && shipments.Count() > 0)
                    {
                        savedQty = shipments.Sum(x => x.Quantity);
                    }

                    orderIds.Add(item.OrderId);

                    if (item.LotNoId != null && item.LotNoId > 0)
                    {
                        long   lotNoId      = 0;
                        string lotNumResult = updateLots(item);
                        int    outVal;
                        bool   isNumeric = int.TryParse(lotNumResult, out outVal);
                        if (isNumeric)
                        {
                            lotNoId = int.Parse(lotNumResult);
                        }

                        item.LotNoId = lotNoId;
                    }

                    updateSerials(item);

                    if (item.Id > 0)
                    {
                        result = service.Update(item);
                    }
                    else
                    {
                        result = service.Insert(item);
                    }

                    //Update lot num to set the sourceId..
                    if (item.LotNoId != null && item.LotNoId > 0)
                    {
                        LotNumber tobeUpdated = LotNumberHelper.GetLotNumber(item.LotNoId.Value);
                        tobeUpdated.SourceId = item.Id;
                        LotNumberHelper.Update(tobeUpdated);
                    }
                }

                updateOrders(orderIds);
            }
            else
            {
                result = "Please select order to ship!";
            }
            return(result);
        }