public InvLeatherTransferRecieve SetToBussinessObject(Inv_LeatherTransferRecieve Entity)
        {
            InvLeatherTransferRecieve Model = new InvLeatherTransferRecieve();

            Model.ReceiveID           = Entity.ReceiveID;
            Model.IssueID             = Entity.IssueID;
            Model.ReceiveDate         = Entity.ReceiveDate.ToString("dd/MM/yyyy");
            Model.ReceiveLocation     = Entity.ReceiveLocation;
            Model.ReceiveLocationName = Entity.ReceiveLocation == null ? "" : _context.SYS_Store.Where(m => m.StoreID == Entity.ReceiveLocation).FirstOrDefault().StoreName;
            Model.PurchaseYear        = Entity.PurchaseYear;
            Model.RecordStatus        = Entity.RecordStatus;

            return(Model);
        }
        public Inv_LeatherTransferRecieve SetToModelObject(InvLeatherTransferRecieve model)
        {
            Inv_LeatherTransferRecieve Entity = new Inv_LeatherTransferRecieve();

            Entity.ReceiveID       = model.ReceiveID;
            Entity.IssueID         = model.IssueID;
            Entity.ReceiveDate     = DalCommon.SetDate(model.ReceiveDate);
            Entity.ReceiveLocation = model.ReceiveLocation;
            Entity.PurchaseYear    = model.PurchaseYear;
            Entity.RecordStatus    = "NCF";
            Entity.SetOn           = DateTime.Now;
            Entity.SetBy           = model.SetBy;
            Entity.IPAddress       = string.Empty;

            return(Entity);
        }
        public ValidationMsg Save(InvLeatherTransferRecieve model, int userid)
        {
            _vmMsg = new ValidationMsg();
            try
            {
                using (var tx = new TransactionScope())
                {
                    using (_context)
                    {
                        model.SetBy = userid;
                        Inv_LeatherTransferRecieve tblLeatherTransferRecieve = SetToModelObject(model);
                        _context.Inv_LeatherTransferRecieve.Add(tblLeatherTransferRecieve);
                        _context.SaveChanges();

                        #region Save Detail Records

                        if (model.LeatherTransferReceiveItemList != null)
                        {
                            foreach (InvLeatherTransferReceiveItem objInvLeatherTransferReceiveItem in model.LeatherTransferReceiveItemList)
                            {
                                objInvLeatherTransferReceiveItem.SetBy     = userid;
                                objInvLeatherTransferReceiveItem.ReceiveID = tblLeatherTransferRecieve.ReceiveID;
                                Inv_LeatherTransferReceiveItem tblPurchaseYearPeriod =
                                    SetToModelObject(objInvLeatherTransferReceiveItem);
                                _context.Inv_LeatherTransferReceiveItem.Add(tblPurchaseYearPeriod);
                            }
                        }
                        _context.SaveChanges();

                        #endregion

                        tx.Complete();
                        ReceiveID   = tblLeatherTransferRecieve.ReceiveID;
                        _vmMsg.Type = Enums.MessageType.Success;
                        _vmMsg.Msg  = "Save Successfully.";
                    }
                }
            }
            catch
            {
                ReceiveID   = 0;
                _vmMsg.Type = Enums.MessageType.Error;
                _vmMsg.Msg  = "Failed to save.";
            }
            return(_vmMsg);
        }
        public ValidationMsg Update(InvLeatherTransferRecieve model, int userid)
        {
            _vmMsg = new ValidationMsg();
            try
            {
                using (var tx = new TransactionScope())
                {
                    using (_context)
                    {
                        Inv_LeatherTransferRecieve CurrentEntity = SetToModelObject(model);
                        var OriginalEntity = _context.Inv_LeatherTransferRecieve.First(m => m.ReceiveID == model.ReceiveID);

                        OriginalEntity.ReceiveDate     = CurrentEntity.ReceiveDate;// Convert.ToDateTime(Convert.ToDateTime(CurrentEntity.ReceiveDate).ToString("dd/MM/yyyy"));
                        OriginalEntity.ReceiveLocation = CurrentEntity.ReceiveLocation;
                        OriginalEntity.SetBy           = userid;
                        OriginalEntity.SetOn           = DateTime.Now;

                        #region Save Detail Records

                        if (model.LeatherTransferReceiveItemList != null)
                        {
                            foreach (InvLeatherTransferReceiveItem objInvLeatherTransferReceiveItem in model.LeatherTransferReceiveItemList)
                            {
                                if (objInvLeatherTransferReceiveItem.ItemReceiveID == 0)
                                {
                                    objInvLeatherTransferReceiveItem.ReceiveID = model.ReceiveID;
                                    objInvLeatherTransferReceiveItem.SetBy     = userid;
                                    Inv_LeatherTransferReceiveItem tblPurchaseYearPeriod =
                                        SetToModelObject(objInvLeatherTransferReceiveItem);
                                    _context.Inv_LeatherTransferReceiveItem.Add(tblPurchaseYearPeriod);
                                }
                                else
                                {
                                    Inv_LeatherTransferReceiveItem CurEntity = SetToModelObject(objInvLeatherTransferReceiveItem);
                                    var OrgEntity = _context.Inv_LeatherTransferReceiveItem.First(m => m.ItemReceiveID == objInvLeatherTransferReceiveItem.ItemReceiveID);

                                    OrgEntity.ReceiveQty  = CurEntity.ReceiveQty;
                                    OrgEntity.ReceiveSide = CurEntity.ReceiveSide;
                                    OrgEntity.SetBy       = userid;
                                    OrgEntity.SetOn       = DateTime.Now;
                                }
                            }
                        }
                        _context.SaveChanges();

                        #endregion

                        tx.Complete();
                        _vmMsg.Type = Enums.MessageType.Update;
                        _vmMsg.Msg  = "Updated Successfully.";
                    }
                }
            }
            catch
            {
                ReceiveID   = 0;
                _vmMsg.Type = Enums.MessageType.Error;
                _vmMsg.Msg  = "Failed to Update.";
            }
            return(_vmMsg);
        }
        public ValidationMsg StoreTransferReceiveConfirmed(InvLeatherTransferRecieve model, int userid)
        {
            _vmMsg = new ValidationMsg();
            try
            {
                using (var tx = new TransactionScope())
                {
                    using (_context)
                    {
                        var OriginalEntityRecieve = _context.Inv_LeatherTransferRecieve.First(m => m.ReceiveID == model.ReceiveID);

                        OriginalEntityRecieve.ApprovedBy     = userid;
                        OriginalEntityRecieve.ApproveComment = model.ApproveComment;
                        OriginalEntityRecieve.RecordStatus   = "CNF";

                        var OriginalEntityIssue = _context.Inv_LeatherIssue.First(m => m.IssueID == model.IssueID);

                        OriginalEntityIssue.ApprovedBy     = userid;
                        OriginalEntityIssue.ApproveComment = model.ApproveComment;
                        OriginalEntityIssue.RecordStatus   = "RCV";

                        #region Save Detail Records

                        if (model.LeatherTransferReceiveItemList != null)
                        {
                            foreach (InvLeatherTransferReceiveItem objLeatherIssueItem in model.LeatherTransferReceiveItemList)
                            {
                                objLeatherIssueItem.StoreID = model.ReceiveLocation;

                                #region storeReceive

                                #region Supplier_Stock_Update

                                var CheckSupplierStockForRec = (from i in _context.Inv_StockSupplier
                                                                where i.SupplierID == objLeatherIssueItem.SupplierID &&
                                                                i.ItemTypeID == objLeatherIssueItem.ItemType &&
                                                                i.LeatherType == objLeatherIssueItem.LeatherType &&
                                                                i.LeatherStatusID == objLeatherIssueItem.LeatherStatus &&
                                                                i.StoreID == objLeatherIssueItem.StoreID &&
                                                                i.PurchaseID == objLeatherIssueItem.PurchaseID
                                                                select i).Any();

                                if (!CheckSupplierStockForRec)
                                {
                                    Inv_StockSupplier Entity = new Inv_StockSupplier();

                                    Entity.SupplierID      = objLeatherIssueItem.SupplierID;
                                    Entity.StoreID         = Convert.ToByte(objLeatherIssueItem.StoreID);
                                    Entity.RefChallanID    = objLeatherIssueItem.ChallanID;
                                    Entity.PurchaseID      = objLeatherIssueItem.PurchaseID;
                                    Entity.ItemTypeID      = objLeatherIssueItem.ItemType;
                                    Entity.LeatherType     = objLeatherIssueItem.LeatherType;
                                    Entity.LeatherStatusID = objLeatherIssueItem.LeatherStatus;
                                    Entity.UnitID          = objLeatherIssueItem.UnitID;

                                    Entity.OpeningQty = 0;
                                    Entity.ReceiveQty = objLeatherIssueItem.ReceiveQty;
                                    Entity.IssueQty   = 0;
                                    Entity.ClosingQty = objLeatherIssueItem.ReceiveQty;

                                    Entity.UpdateReason = "Store Transfer Receive";
                                    _context.Inv_StockSupplier.Add(Entity);
                                    _context.SaveChanges();
                                }
                                else
                                {
                                    var LastSupplierStock = (from i in _context.Inv_StockSupplier
                                                             where i.SupplierID == objLeatherIssueItem.SupplierID &&
                                                             i.ItemTypeID == objLeatherIssueItem.ItemType &&
                                                             i.LeatherType == objLeatherIssueItem.LeatherType &&
                                                             i.LeatherStatusID == objLeatherIssueItem.LeatherStatus &&
                                                             i.StoreID == objLeatherIssueItem.StoreID &&
                                                             i.PurchaseID == objLeatherIssueItem.PurchaseID
                                                             orderby i.TransectionID descending
                                                             select i).FirstOrDefault();


                                    Inv_StockSupplier objStockSupplier = new Inv_StockSupplier();

                                    objStockSupplier.SupplierID      = objLeatherIssueItem.SupplierID;
                                    objStockSupplier.StoreID         = Convert.ToByte(objLeatherIssueItem.StoreID);
                                    objStockSupplier.RefChallanID    = objLeatherIssueItem.ChallanID;
                                    objStockSupplier.PurchaseID      = objLeatherIssueItem.PurchaseID;
                                    objStockSupplier.ItemTypeID      = objLeatherIssueItem.ItemType;
                                    objStockSupplier.LeatherType     = objLeatherIssueItem.LeatherType;
                                    objStockSupplier.LeatherStatusID = objLeatherIssueItem.LeatherStatus;
                                    objStockSupplier.UnitID          = objLeatherIssueItem.UnitID;

                                    objStockSupplier.OpeningQty = LastSupplierStock.ClosingQty;
                                    objStockSupplier.ReceiveQty = objLeatherIssueItem.ReceiveQty;
                                    objStockSupplier.IssueQty   = 0;
                                    objStockSupplier.ClosingQty = LastSupplierStock.ClosingQty + objLeatherIssueItem.ReceiveQty;

                                    objStockSupplier.UpdateReason = "Store Transfer Receive";

                                    _context.Inv_StockSupplier.Add(objStockSupplier);
                                    _context.SaveChanges();
                                }

                                #endregion

                                #region Item_Stock_Update

                                var CheckItemStockForRec = (from i in _context.Inv_StockItem
                                                            where i.ItemTypeID == objLeatherIssueItem.ItemType &&
                                                            i.LeatherType == objLeatherIssueItem.LeatherType &&
                                                            i.LeatherStatus == objLeatherIssueItem.LeatherStatus &&
                                                            i.StoreID == objLeatherIssueItem.StoreID
                                                            select i).Any();

                                if (!CheckItemStockForRec)
                                {
                                    Inv_StockItem objStockItem = new Inv_StockItem();

                                    objStockItem.ItemTypeID    = objLeatherIssueItem.ItemType;
                                    objStockItem.LeatherType   = objLeatherIssueItem.LeatherType;
                                    objStockItem.LeatherStatus = objLeatherIssueItem.LeatherStatus;
                                    objStockItem.StoreID       = Convert.ToByte(objLeatherIssueItem.StoreID);
                                    objStockItem.UnitID        = objLeatherIssueItem.UnitID;

                                    objStockItem.OpeningQty = 0;
                                    objStockItem.ReceiveQty = objLeatherIssueItem.ReceiveQty;
                                    objStockItem.IssueQty   = 0;
                                    objStockItem.ClosingQty = objLeatherIssueItem.ReceiveQty;

                                    _context.Inv_StockItem.Add(objStockItem);
                                    _context.SaveChanges();
                                }
                                else
                                {
                                    var LastItemInfo = (from i in _context.Inv_StockItem
                                                        where i.ItemTypeID == objLeatherIssueItem.ItemType &&
                                                        i.LeatherType == objLeatherIssueItem.LeatherType &&
                                                        i.LeatherStatus == objLeatherIssueItem.LeatherStatus &&
                                                        i.StoreID == objLeatherIssueItem.StoreID
                                                        orderby i.TransectionID descending
                                                        select i).FirstOrDefault();

                                    Inv_StockItem objStockItem = new Inv_StockItem();

                                    objStockItem.ItemTypeID    = LastItemInfo.ItemTypeID;
                                    objStockItem.LeatherType   = LastItemInfo.LeatherType;
                                    objStockItem.LeatherStatus = LastItemInfo.LeatherStatus;
                                    objStockItem.StoreID       = LastItemInfo.StoreID;
                                    objStockItem.UnitID        = objLeatherIssueItem.UnitID;

                                    objStockItem.OpeningQty = LastItemInfo.ClosingQty;
                                    objStockItem.ReceiveQty = objLeatherIssueItem.ReceiveQty;
                                    objStockItem.IssueQty   = 0;
                                    objStockItem.ClosingQty = LastItemInfo.ClosingQty + objLeatherIssueItem.ReceiveQty;

                                    _context.Inv_StockItem.Add(objStockItem);
                                    _context.SaveChanges();
                                }

                                #endregion

                                #region Daily_Stock_Update

                                var currentDate = System.DateTime.Now.Date;

                                var CheckDateForRec = (from ds in _context.Inv_StockDaily
                                                       where ds.ItemTypeID == objLeatherIssueItem.ItemType &&
                                                       ds.StoreID == objLeatherIssueItem.StoreID &&
                                                       ds.LeatherStatus == objLeatherIssueItem.LeatherStatus &&
                                                       ds.LeatherType == objLeatherIssueItem.LeatherType && ds.StockDate == currentDate
                                                       select ds).Any();

                                if (CheckDateForRec)
                                {
                                    var CurrentItem = (from ds in _context.Inv_StockDaily
                                                       where ds.ItemTypeID == objLeatherIssueItem.ItemType &&
                                                       ds.StoreID == objLeatherIssueItem.StoreID &&
                                                       ds.LeatherStatus == objLeatherIssueItem.LeatherStatus &&
                                                       ds.LeatherType == objLeatherIssueItem.LeatherType && ds.StockDate == currentDate
                                                       select ds).FirstOrDefault();

                                    CurrentItem.DailyReceiveQty = CurrentItem.DailyReceiveQty + objLeatherIssueItem.ReceiveQty;
                                    CurrentItem.ClosingQty      = CurrentItem.ClosingQty + objLeatherIssueItem.ReceiveQty;
                                    _context.SaveChanges();
                                }
                                else
                                {
                                    var PreviousRecord = (from ds in _context.Inv_StockDaily
                                                          where ds.ItemTypeID == objLeatherIssueItem.ItemType &&
                                                          ds.StoreID == objLeatherIssueItem.StoreID &&
                                                          ds.LeatherStatus == objLeatherIssueItem.LeatherStatus &&
                                                          ds.LeatherType == objLeatherIssueItem.LeatherType
                                                          orderby ds.TransectionID descending
                                                          select ds).FirstOrDefault();

                                    Inv_StockDaily objStockDaily = new Inv_StockDaily();

                                    objStockDaily.ItemTypeID    = objLeatherIssueItem.ItemType;
                                    objStockDaily.StoreID       = Convert.ToByte(objLeatherIssueItem.StoreID);
                                    objStockDaily.UnitID        = objLeatherIssueItem.UnitID;
                                    objStockDaily.LeatherStatus = objLeatherIssueItem.LeatherStatus;
                                    objStockDaily.LeatherType   = objLeatherIssueItem.LeatherType;

                                    objStockDaily.OpeningQty      = (PreviousRecord == null ? 0 : PreviousRecord.ClosingQty);
                                    objStockDaily.DailyReceiveQty = objLeatherIssueItem.ReceiveQty;
                                    objStockDaily.DailyIssueQty   = 0;
                                    objStockDaily.ClosingQty      = objStockDaily.OpeningQty + objLeatherIssueItem.ReceiveQty;

                                    objStockDaily.StockDate = currentDate;

                                    _context.Inv_StockDaily.Add(objStockDaily);
                                    _context.SaveChanges();
                                }

                                #endregion

                                #endregion
                            }
                        }

                        #endregion

                        _context.SaveChanges();

                        tx.Complete();
                        _vmMsg.Type = Enums.MessageType.Success;
                        _vmMsg.Msg  = "Confirmed Successfully.";
                    }
                }
            }
            catch
            {
                _vmMsg.Type = Enums.MessageType.Error;
                _vmMsg.Msg  = "Failed to Confirmed.";
            }
            return(_vmMsg);
        }
Beispiel #6
0
 public ActionResult StoreTransferReceiveConfirmed(InvLeatherTransferRecieve model)
 {
     _vmMsg = DalObj.StoreTransferReceiveConfirmed(model, Convert.ToInt32(Session["UserID"]));
     return(Json(new { msg = _vmMsg }));
 }
Beispiel #7
0
 public ActionResult TransferReceive(InvLeatherTransferRecieve model)
 {
     _vmMsg = model.ReceiveID == 0 ? DalObj.Save(model, Convert.ToInt32(Session["UserID"])) : DalObj.Update(model, Convert.ToInt32(Session["UserID"]));
     return(Json(new { ReceiveID = DalObj.GetReceiveID(), msg = _vmMsg }));
 }