Example #1
0
 private static void deleteLots(List <long> lotNoIds)
 {
     foreach (var lotNoId in lotNoIds)
     {
         LotNumberHelper.Delete(lotNoId.ToString());
     }
 }
Example #2
0
 private static void deleteSerials(List <string> serials, long lotNoId)
 {
     foreach (var serial in serials)
     {
         SerialNumber savedSerial = LotNumberHelper.GetSerialNo(serial, lotNoId);
         LotNumberHelper.DeleteSerialNumber(savedSerial.Id.ToString());
     }
 }
Example #3
0
        private static string updateLots(Shipment model)
        {
            if (model.Id > 0)
            {
                if (model.LotNoId != null && model.LotNoId > 0)
                {
                    LotNumber savedLot = LotNumberHelper.GetLotNumber(model.LotNoId.Value);
                    if (savedLot != null && savedLot.SourceId == model.Id)
                    {
                        //Lot is already saved..
                        return("");
                    }
                    else
                    {
                        savedLot = LotNumberHelper.GetLotBySourceId(model.Id);
                        if (savedLot != null)
                        {
                            LotNumberHelper.Delete(savedLot.Id.ToString());
                        }

                        savedLot.SourceId   = savedLot.Id;
                        savedLot.SourceType = "Shipment";
                        return(LotNumberHelper.SaveLot(savedLot));
                    }
                }
            }
            else
            {
                if (model.LotNoId != null && model.LotNoId > 0)
                {
                    LotNumber newLot = LotNumberHelper.GetLotNumber(model.LotNoId.Value);
                    newLot.SourceId   = 0; //Temporary..
                    newLot.SourceType = "Shipment";
                    return(LotNumberHelper.SaveLot(newLot));
                }
            }

            return("");
        }
Example #4
0
        public static void Save(MoveOrderModel moveOrderModel)
        {
            MoveOrder entity = GetEntityByModel(moveOrderModel);

            string result = string.Empty;

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

                if (!string.IsNullOrEmpty(result))
                {
                    var savedDetail = GetMoveOrderLines(result);
                    if (savedDetail.Count() > moveOrderModel.MoveOrderDetail.Count())
                    {
                        var tobeDeleted = savedDetail.Take(savedDetail.Count() - moveOrderModel.MoveOrderDetail.Count());
                        foreach (var item in tobeDeleted)
                        {
                            service.Delete(item.Id);
                            IEnumerable <LotNumber> lotNum = lotNumService.CheckLotNumAvailability(AuthenticationHelper.CompanyId.Value, item.LotNo, item.ItemId, SessionHelper.SOBId);
                            if (lotNum.Any())
                            {
                                LotNumberHelper.Delete(lotNum.FirstOrDefault().Id.ToString());
                            }

                            //IEnumerable<SerialNumber> serialNum = lotNumService.CheckSerialNumAvailability(AuthenticationHelper.CompanyId.Value, item.LotNo, item.SerialNo);
                            //if (serialNum.Any())
                            //{
                            //    LotNumberHelper.DeleteSerialNumber(serialNum.FirstOrDefault().Id.ToString());
                            //}
                        }
                        savedDetail = GetMoveOrderLines(result);
                    }

                    foreach (var detail in moveOrderModel.MoveOrderDetail)
                    {
                        MoveOrderDetail detailEntity = GetEntityByModel(detail, savedDetail.Count());
                        if (detailEntity.IsValid())
                        {
                            detailEntity.MoveOrderId = Convert.ToInt64(result);
                            if (savedDetail.Count() > 0)
                            {
                                detailEntity.Id = savedDetail.FirstOrDefault().Id;
                                savedDetail.Remove(savedDetail.FirstOrDefault(rec => rec.Id == detailEntity.Id));
                                service.Update(detailEntity);
                                IEnumerable <LotNumber> lotNum = lotNumService.CheckLotNumAvailability(AuthenticationHelper.CompanyId.Value, detailEntity.LotNo, detailEntity.ItemId, SessionHelper.SOBId);
                                if (lotNum.Any())
                                {
                                    LotNumberHelper.Update(lotNum.FirstOrDefault());
                                }

                                //IEnumerable<SerialNumber> serialNum = lotNumService.CheckSerialNumAvailability(AuthenticationHelper.CompanyId.Value, detailEntity.LotNo, detailEntity.SerialNo);
                                //if (serialNum.Any())
                                //{
                                //    LotNumberHelper.UpdateSerialNumber(serialNum.FirstOrDefault());
                                //}
                            }
                            else
                            {
                                service.Insert(detailEntity);
                                IEnumerable <LotNumber> lotNum = lotNumService.CheckLotNumAvailability(AuthenticationHelper.CompanyId.Value, detailEntity.LotNo, detailEntity.ItemId, SessionHelper.SOBId);
                                if (!lotNum.Any())
                                {
                                    LotNumberHelper.Insert(new MoveOrderDetailModel(detailEntity));
                                }

                                //IEnumerable<SerialNumber> serialNum = lotNumService.CheckSerialNumAvailability(AuthenticationHelper.CompanyId.Value, detailEntity.LotNo, detailEntity.SerialNo);
                                //if (!serialNum.Any())
                                //{
                                //    LotNumberHelper.InsertSerialNumber(new MoveOrderDetailModel(detailEntity));
                                //}
                            }
                        }
                    }
                }
            }
        }
Example #5
0
        public static void Save(MiscellaneousTransactionModel miscellaneousTransactionModel)
        {
            var savedDetail = getMiscellaneousTransaction(miscellaneousTransactionModel.SOBId, miscellaneousTransactionModel.TransactionType, miscellaneousTransactionModel.CodeCombinationId, miscellaneousTransactionModel.TransactionDate);

            if (SessionHelper.MiscellaneousTransaction != null)
            {
                if (savedDetail.Count() > miscellaneousTransactionModel.MiscellaneousTransactionDetail.Count())
                {
                    var tobeDeleted = savedDetail.Take(savedDetail.Count() - miscellaneousTransactionModel.MiscellaneousTransactionDetail.Count());
                    foreach (var item in tobeDeleted)
                    {
                        service.Delete(item.Id.ToString(), AuthenticationHelper.CompanyId.Value);
                        IEnumerable <LotNumber> lotNum = lotNumService.CheckLotNumAvailability(AuthenticationHelper.CompanyId.Value, item.LotNo, item.ItemId, SessionHelper.SOBId);
                        if (lotNum.Any())
                        {
                            LotNumberHelper.Delete(lotNum.FirstOrDefault().Id.ToString());
                        }

                        //IEnumerable<SerialNumber> serialNum = lotNumService.CheckSerialNumAvailability(AuthenticationHelper.CompanyId.Value, item.LotNo, item.SerialNo);
                        //if (serialNum.Any())
                        //{
                        //    LotNumberHelper.DeleteSerialNumber(serialNum.FirstOrDefault().Id.ToString());
                        //}
                    }
                    savedDetail = getMiscellaneousTransaction(miscellaneousTransactionModel.SOBId, miscellaneousTransactionModel.TransactionType, miscellaneousTransactionModel.CodeCombinationId, miscellaneousTransactionModel.TransactionDate);
                }

                foreach (var detail in miscellaneousTransactionModel.MiscellaneousTransactionDetail)
                {
                    MiscellaneousTransaction detailEntity = GetEntityByModel(detail, savedDetail.Count());
                    if (detailEntity.IsValid())
                    {
                        if (savedDetail.Count() > 0)
                        {
                            detailEntity.Id = savedDetail.FirstOrDefault().Id;
                            savedDetail.Remove(savedDetail.FirstOrDefault(rec => rec.Id == detailEntity.Id));
                            service.Update(detailEntity);
                            IEnumerable <LotNumber> lotNum = lotNumService.CheckLotNumAvailability(AuthenticationHelper.CompanyId.Value, detailEntity.LotNo, detailEntity.ItemId, SessionHelper.SOBId);
                            if (lotNum.Any())
                            {
                                LotNumberHelper.Update(lotNum.FirstOrDefault());
                            }

                            //IEnumerable<SerialNumber> serialNum = lotNumService.CheckSerialNumAvailability(AuthenticationHelper.CompanyId.Value, detailEntity.LotNo, detailEntity.SerialNo);
                            //if (serialNum.Any())
                            //{
                            //    LotNumberHelper.UpdateSerialNumber(serialNum.FirstOrDefault());
                            //}
                        }
                        else
                        {
                            service.Insert(detailEntity);
                            IEnumerable <LotNumber> lotNum = lotNumService.CheckLotNumAvailability(AuthenticationHelper.CompanyId.Value, detailEntity.LotNo, detailEntity.ItemId, SessionHelper.SOBId);
                            if (!lotNum.Any())
                            {
                                LotNumberHelper.Insert(new MiscellaneousTransactionDetailModel(detailEntity));
                            }

                            //IEnumerable<SerialNumber> serialNum = lotNumService.CheckSerialNumAvailability(AuthenticationHelper.CompanyId.Value, detailEntity.LotNo, detailEntity.SerialNo);
                            //if (!serialNum.Any())
                            //{
                            //    LotNumberHelper.InsertSerialNumber(new MiscellaneousTransactionDetailModel(detailEntity));
                            //}
                        }
                    }
                }
            }
        }
Example #6
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);
        }
Example #7
0
        private static void updateSerials(Shipment model)
        {
            List <string> modelSerials = string.IsNullOrEmpty(model.SerialNo) ? new List <string>() : model.SerialNo.Split(new char[] { ',' }).ToList();

            if (model.Id > 0)
            {
                Shipment savedShipment = service.GetSingle(model.Id.ToString(), AuthenticationHelper.CompanyId.Value);
                if (!string.IsNullOrEmpty(savedShipment.SerialNo))
                {
                    List <string> savedSerials = model.SerialNo.Split(new char[] { ',' }).ToList();
                    if (savedSerials.Count() > modelSerials.Count())
                    {
                        savedSerials = savedSerials.Take(savedSerials.Count() - modelSerials.Count()).ToList();
                        deleteSerials(savedSerials, model.LotNoId.Value);
                    }
                }
                foreach (var updateSerial in modelSerials)
                {
                    SerialNumber savedSerial = LotNumberHelper.GetSerialNo(updateSerial, model.LotNoId.Value);
                    if (savedSerial != null)
                    {
                        savedSerial.UpdateDate = DateTime.Now;
                        savedSerial.UpdateBy   = AuthenticationHelper.UserId;
                        savedSerial.SerialNo   = updateSerial;
                        LotNumberHelper.UpdateSerialNumber(savedSerial);
                    }
                    else
                    {
                        LotNumberHelper.SaveSerial(new SerialNumber
                        {
                            CompanyId  = AuthenticationHelper.CompanyId.Value,
                            SerialNo   = updateSerial,
                            UpdateDate = null,
                            UpdateBy   = null,
                            LotNoId    = model.LotNoId.Value,
                            LotNo      = "",
                            CreateBy   = AuthenticationHelper.UserId,
                            CreateDate = DateTime.Now
                        });
                    }
                }
            }
            else
            {
                if (modelSerials.Count() > 0)
                {
                    foreach (var serial in modelSerials)
                    {
                        LotNumberHelper.SaveSerial(new SerialNumber
                        {
                            CompanyId  = AuthenticationHelper.CompanyId.Value,
                            CreateBy   = AuthenticationHelper.UserId,
                            CreateDate = DateTime.Now,
                            LotNo      = "",
                            LotNoId    = model.LotNoId.Value,
                            SerialNo   = serial,
                            UpdateBy   = null,
                            UpdateDate = null
                        });
                    }
                }
            }
        }
Example #8
0
        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("");
        }