private static OrderShipmentLine fromOrderDetailtoShipment(OrderDetailModel model, List <ShipmentModel> shipments) { return(new OrderShipmentLine { LineId = model.Id, OrderQuantity = model.Quantity, BalanceQuantity = model.Quantity - shipments.Sum(rec => rec.Quantity), ShipedQuantity = shipments.Sum(rec => rec.Quantity), ThisShipQuantity = model.Quantity - shipments.Sum(rec => rec.Quantity), ItemName = ItemHelper.GetItem(model.ItemId.ToString()).ItemName, ItemId = model.ItemId, OrderId = model.OrderId }); }
public static OrderShipmentModel GetShipmentEdit(string deliveryNo, DateTime date) { List <ShipmentModel> shipmentDetail = service.GetDelivery(AuthenticationHelper.CompanyId.Value, SessionHelper.SOBId, deliveryNo, date).Select(x => new ShipmentModel(x)).ToList(); OrderModel order = OrderHelper.GetOrder(shipmentDetail.First().OrderId.ToString()); //Can be multiple, showing the first one on the header.. OrderShipmentModel orderShipment = new OrderShipmentModel(shipmentDetail.First()); orderShipment.CreateBy = shipmentDetail.First().CreateBy; orderShipment.CreateDate = shipmentDetail.First().CreateDate; orderShipment.CustomerId = order.CustomerId; orderShipment.CustomerSiteId = order.CustomerSiteId; orderShipment.UpdateBy = shipmentDetail.First().UpdateBy; orderShipment.UpdateDate = shipmentDetail.First().UpdateDate; orderShipment.OrderShipments = new List <OrderShipmentLine>(); foreach (var item in shipmentDetail) { OrderDetailModel orderDetail = OrderHelper.GetSingleOrderDetail(item.LineId); OrderShipmentLine shipmentLine = new OrderShipmentLine(item); decimal shippedQty = GetShipments(item.LineId).Where(rec => rec.Id < item.Id).Sum(x => x.Quantity); shipmentLine.BalanceQuantity = orderDetail.Quantity - (shippedQty + item.Quantity); shipmentLine.OrderQuantity = orderDetail.Quantity; shipmentLine.ShipedQuantity = shippedQty; shipmentLine.ThisShipQuantity = item.Quantity; shipmentLine.ItemName = ItemHelper.GetItem(orderDetail.ItemId.ToString()).ItemName; shipmentLine.CustomerId = OrderHelper.GetSingleOrder(item.OrderId.ToString()).CustomerId; shipmentLine.CustomerName = OrderHelper.GetSingleOrder(item.OrderId.ToString()).CustomerName; shipmentLine.CustomerSiteId = OrderHelper.GetSingleOrder(item.OrderId.ToString()).CustomerSiteId; shipmentLine.CustomerSiteName = OrderHelper.GetSingleOrder(item.OrderId.ToString()).CustomerSiteName; orderShipment.OrderShipments.Add(shipmentLine); } return(orderShipment); }
private static string checkLotandSerials(OrderShipmentLine model) { //Selection check.. if (model.LotNoId == null || model.LotNoId == 0) { ItemModel item = ItemHelper.GetItem(model.ItemId.ToString()); if (item.LotControl) { return("Please provide item lot!"); } if (!string.IsNullOrEmpty(model.SerialNo)) { return("Serial no. can not be defined without its lot!"); } else { return(""); } } else { List <SerialNumber> serialExist = LotNumberHelper.GetSerialsbyLotNo(model.LotNoId.Value).ToList(); List <SerialNumber> availableSerials = LotNumberHelper.GetAvailableSerials(model.LotNoId.Value); List <string> serialonGrid = SessionHelper.Shipment.OrderShipments.Where(rec => rec.LotNoId == model.LotNoId && rec.LineId != model.LineId).Select(x => x.SerialNo).ToList(); if (!string.IsNullOrEmpty(model.SerialNo)) { List <string> serials = model.SerialNo.Split(new char[] { ',' }).ToList(); //Check duplication within the same record.. if (serials.GroupBy(rec => rec).Any(d => d.Count() > 1)) { return("Serial can not be duplicate!"); } //Quantity check.. if (serials.Count() < model.ThisShipQuantity || serials.Count() > model.ThisShipQuantity) { return("Serials are not matching with the quantity!"); } //Serial availablity within shipment.. if (serialonGrid != null && serialonGrid.Count() > 0) { foreach (var unsaved in serialonGrid) { if (!string.IsNullOrEmpty(unsaved)) { //Check by another entries on grid.. List <string> unsavedSerial = unsaved.Split(new char[] { ',' }).ToList(); if (serials.Any(rec => rec == unsavedSerial.FirstOrDefault(x => x == rec))) { return("One of your serial no is already defined!"); } } } } //Lot serial existence check.. if (serialExist != null && serialExist.Count() > 0) { if (serials.Count() > availableSerials.Count()) { return("Lot is exceeding the available qty!"); } } else { return("This lot does not support serial."); } //Serial availablity within db.. foreach (var serial in serials) { bool isAvailable = LotNumberHelper.CheckSerialNumAvailability(model.LotNoId.Value, serial); if (isAvailable) { continue; } else { if (model.Id > 0) { LotNumber savedLot = LotNumberHelper.GetLotNumber(LotNumberHelper.GetSerialNo(serial, model.LotNoId.Value).LotNoId); if (savedLot.SourceId == model.Id) { continue; } else { return("Serial No. " + serial + " does not exist or may have been already shipped"); } } else { return("Serial No. " + serial + " does not exist or may have been already shipped"); } } } } else { //Lot serial existence check.. if (serialExist != null && serialExist.Count() > 0) { //Serial Generation if (model.ThisShipQuantity > availableSerials.Count() - serialonGrid.Count()) { return("Quantity is exceeding!"); } else { //Generate from available serials.. //Qty can not be decimal.. List <SerialNumber> useAvailable = new List <SerialNumber>(); if (serialonGrid != null && serialonGrid.Count() > 0) { List <string> gridSerial = new List <string>(); foreach (var serial in serialonGrid) { List <string> currentLine = serial.Split(new char[] { ',' }).ToList(); gridSerial.AddRange(currentLine); } useAvailable = availableSerials.Where(rec => rec.SerialNo != gridSerial.FirstOrDefault(x => x == rec.SerialNo)).Take(Convert.ToInt32(model.ThisShipQuantity)).ToList(); } else { useAvailable = availableSerials.Take(Convert.ToInt32(model.ThisShipQuantity)).ToList(); } List <string> autoGeneratedSerial = useAvailable.Select(rec => rec.SerialNo).ToList(); string newSerial = string.Join(",", autoGeneratedSerial.ToArray()); SessionHelper.Shipment.OrderShipments.FirstOrDefault(x => x.LineId == model.LineId && x.Id == model.Id).SerialNo = newSerial; } } else { //Lot can be used only one time.. if (SessionHelper.Shipment.OrderShipments.Any(re => re.LotNoId == model.LotNoId && re.LineId != model.LineId)) { return("Lot is in use in the current shipment"); } } } } return(""); }