public HttpResponseMessage updateStockIn(String id, Models.TrnStockIn stockIn)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                var stockIns = from d in db.TrnStockIns where d.Id == Convert.ToInt32(id) select d;
                if (stockIns.Any())
                {
                    var updateStockIn = stockIns.FirstOrDefault();
                    updateStockIn.BranchId        = stockIn.BranchId;
                    updateStockIn.INNumber        = stockIn.INNumber;
                    updateStockIn.INDate          = Convert.ToDateTime(stockIn.INDate);
                    updateStockIn.AccountId       = stockIn.AccountId;
                    updateStockIn.ArticleId       = stockIn.ArticleId;
                    updateStockIn.Particulars     = stockIn.Particulars;
                    updateStockIn.ManualINNumber  = stockIn.ManualINNumber;
                    updateStockIn.IsProduced      = stockIn.IsProduced;
                    updateStockIn.PreparedById    = stockIn.PreparedById;
                    updateStockIn.CheckedById     = stockIn.CheckedById;
                    updateStockIn.ApprovedById    = stockIn.ApprovedById;
                    updateStockIn.IsLocked        = true;
                    updateStockIn.UpdatedById     = userId;
                    updateStockIn.UpdatedDateTime = DateTime.Now;

                    db.SubmitChanges();

                    inventory.InsertStockInInventory(Convert.ToInt32(id));
                    journal.InsertStockInJournal(Convert.ToInt32(id));

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Beispiel #2
0
        // ==============================
        // Lock Stock In (CSV Integrator)
        // ==============================
        public void LockCSVIntegratorStockIn(Int32 id)
        {
            try
            {
                var stockIn = from d in db.TrnStockIns where d.Id == id select d;
                if (stockIn.Any())
                {
                    var lockStockIn = stockIn.FirstOrDefault();
                    lockStockIn.IsLocked = true;
                    db.SubmitChanges();

                    Business.Journal journal = new Business.Journal();
                    journal.InsertStockInJournal(id);

                    Business.Inventory inventory = new Business.Inventory();
                    inventory.InsertStockInInventory(id);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
Beispiel #3
0
        public HttpResponseMessage AddFolderMonitoringStockIn(List <Entities.FolderMonitoringTrnStockIn> folderMonitoringTrnStockInObjects)
        {
            try
            {
                if (folderMonitoringTrnStockInObjects.Any())
                {
                    String returnMessage = "";

                    List <Entities.FolderMonitoringTrnStockInHeader> newFolderMonitoringTrnStockInHeaders = new List <Entities.FolderMonitoringTrnStockInHeader>();
                    List <Entities.FolderMonitoringTrnStockInItem>   newFolderMonitoringTrnStockInItems   = new List <Entities.FolderMonitoringTrnStockInItem>();

                    Boolean isDataValid = false;

                    foreach (var folderMonitoringTrnStockInObject in folderMonitoringTrnStockInObjects)
                    {
                        Boolean isBranchExist   = false,
                                 isAccountExist = false,
                                 isArticleExist = false,
                                 isUserExist    = false,
                                 isItemExist    = false,
                                 isUnitExist    = false;

                        var branch = from d in db.MstBranches where d.BranchCode.Equals(folderMonitoringTrnStockInObject.BranchCode) select d;
                        if (branch.Any())
                        {
                            isBranchExist = true;
                        }

                        List <easyfis.Entities.MstArticle> listArticles = new List <easyfis.Entities.MstArticle>();
                        var account = from d in db.MstAccounts where d.AccountCode.Equals(folderMonitoringTrnStockInObject.AccountCode) select d;
                        if (account.Any())
                        {
                            isAccountExist = true;

                            var accountArticleTypes = from d in db.MstAccountArticleTypes
                                                      where d.AccountId == Convert.ToInt32(account.FirstOrDefault().Id)
                                                      group d by d.ArticleTypeId into g
                                                      select g;

                            if (accountArticleTypes.Any())
                            {
                                foreach (var accountArticleType in accountArticleTypes)
                                {
                                    var articles = from d in db.MstArticles
                                                   where d.ArticleTypeId == accountArticleType.Key &&
                                                   d.IsLocked == true
                                                   select d;

                                    if (articles.Any())
                                    {
                                        foreach (var articleObject in articles)
                                        {
                                            listArticles.Add(new easyfis.Entities.MstArticle()
                                            {
                                                Id = articleObject.Id,
                                                ManualArticleCode = articleObject.ManualArticleCode,
                                                Article           = articleObject.Article
                                            });
                                        }
                                    }
                                }
                            }
                        }

                        var article = from d in listArticles where d.ManualArticleCode.Equals(folderMonitoringTrnStockInObject.ArticleCode) select d;
                        if (article.Any())
                        {
                            isArticleExist = true;
                        }

                        var user = from d in db.MstUsers where d.UserName.Equals(folderMonitoringTrnStockInObject.UserCode) select d;
                        if (user.Any())
                        {
                            isUserExist = true;
                        }

                        var item = from d in db.MstArticles where d.ArticleTypeId == 1 && d.ManualArticleCode.Equals(folderMonitoringTrnStockInObject.ItemCode) && d.IsInventory == true && d.IsLocked == true select d;
                        if (item.Any())
                        {
                            isItemExist = true;
                        }

                        var unit = from d in db.MstUnits where d.Unit.Equals(folderMonitoringTrnStockInObject.Unit) select d;
                        if (unit.Any())
                        {
                            isUnitExist = true;
                        }

                        if (!isBranchExist)
                        {
                            returnMessage = "Invalid Branch Code: " + folderMonitoringTrnStockInObject.BranchCode; isDataValid = false; break;
                        }
                        else if (!isAccountExist)
                        {
                            returnMessage = "Invalid Account Code: " + folderMonitoringTrnStockInObject.AccountCode; isDataValid = false; break;
                        }
                        else if (!isArticleExist)
                        {
                            returnMessage = "Invalid Article Code: " + folderMonitoringTrnStockInObject.ArticleCode; isDataValid = false; break;
                        }
                        else if (!isUserExist)
                        {
                            returnMessage = "Invalid User Code: " + folderMonitoringTrnStockInObject.UserCode; isDataValid = false; break;
                        }
                        else if (!isItemExist)
                        {
                            returnMessage = "Invalid Item Code: " + folderMonitoringTrnStockInObject.ItemCode; isDataValid = false; break;
                        }
                        else if (!isUnitExist)
                        {
                            returnMessage = "Invalid Unit: " + folderMonitoringTrnStockInObject.Unit; isDataValid = false; break;
                        }
                        else
                        {
                            var currentStockIn = from d in db.TrnStockIns
                                                 where d.BranchId == branch.FirstOrDefault().Id &&
                                                 d.ManualINNumber.Equals(folderMonitoringTrnStockInObject.ManualINNumber)
                                                 select d;

                            if (currentStockIn.Any())
                            {
                                returnMessage = "This Manual IN No. " + folderMonitoringTrnStockInObject.ManualINNumber + " is already exist!";
                                isDataValid   = false;

                                break;
                            }
                            else
                            {
                                var unitConversion = from d in item.FirstOrDefault().MstArticleUnits where d.UnitId == unit.FirstOrDefault().Id select d;
                                if (unitConversion.Any())
                                {
                                    Decimal baseQuantity = folderMonitoringTrnStockInObject.Quantity * 1;
                                    if (unitConversion.FirstOrDefault().Multiplier > 0)
                                    {
                                        baseQuantity = folderMonitoringTrnStockInObject.Quantity * (1 / unitConversion.FirstOrDefault().Multiplier);
                                    }

                                    Decimal baseCost = folderMonitoringTrnStockInObject.Amount;
                                    if (baseQuantity > 0)
                                    {
                                        baseCost = folderMonitoringTrnStockInObject.Amount / baseQuantity;
                                    }

                                    var folderMonitoringTrnStockInHeader = from d in newFolderMonitoringTrnStockInHeaders
                                                                           where d.BranchId == branch.FirstOrDefault().Id &&
                                                                           d.ManualINNumber.Equals(folderMonitoringTrnStockInObject.ManualINNumber)
                                                                           select d;

                                    if (folderMonitoringTrnStockInHeader.Any())
                                    {
                                        var currentFolderMonitoringTrnStockInHeader = folderMonitoringTrnStockInHeader.FirstOrDefault();
                                        currentFolderMonitoringTrnStockInHeader.ListFolderMonitoringTrnStockInItems.Add(new Entities.FolderMonitoringTrnStockInItem()
                                        {
                                            ManualINNumber = folderMonitoringTrnStockInObject.ManualINNumber,
                                            ItemId         = item.FirstOrDefault().Id,
                                            Particulars    = folderMonitoringTrnStockInObject.Particulars,
                                            UnitId         = unit.FirstOrDefault().Id,
                                            Quantity       = folderMonitoringTrnStockInObject.Quantity,
                                            Cost           = folderMonitoringTrnStockInObject.Cost,
                                            Amount         = folderMonitoringTrnStockInObject.Amount,
                                            BaseUnitId     = item.FirstOrDefault().UnitId,
                                            BaseQuantity   = baseQuantity,
                                            BaseCost       = baseCost
                                        });
                                    }
                                    else
                                    {
                                        newFolderMonitoringTrnStockInItems = new List <Entities.FolderMonitoringTrnStockInItem>
                                        {
                                            new Entities.FolderMonitoringTrnStockInItem()
                                            {
                                                ManualINNumber = folderMonitoringTrnStockInObject.ManualINNumber,
                                                ItemId         = item.FirstOrDefault().Id,
                                                Particulars    = folderMonitoringTrnStockInObject.Particulars,
                                                UnitId         = unit.FirstOrDefault().Id,
                                                Quantity       = folderMonitoringTrnStockInObject.Quantity,
                                                Cost           = folderMonitoringTrnStockInObject.Cost,
                                                Amount         = folderMonitoringTrnStockInObject.Amount,
                                                BaseUnitId     = item.FirstOrDefault().UnitId,
                                                BaseQuantity   = baseQuantity,
                                                BaseCost       = baseCost
                                            }
                                        };

                                        if (newFolderMonitoringTrnStockInItems.Any())
                                        {
                                            newFolderMonitoringTrnStockInHeaders.Add(new Entities.FolderMonitoringTrnStockInHeader()
                                            {
                                                BranchId        = branch.FirstOrDefault().Id,
                                                INNumber        = "0000000000",
                                                INDate          = Convert.ToDateTime(folderMonitoringTrnStockInObject.INDate),
                                                AccountId       = account.FirstOrDefault().Id,
                                                ArticleId       = article.FirstOrDefault().Id,
                                                Particulars     = folderMonitoringTrnStockInObject.Remarks,
                                                ManualINNumber  = folderMonitoringTrnStockInObject.ManualINNumber,
                                                IsProduced      = folderMonitoringTrnStockInObject.IsProduce,
                                                PreparedById    = user.FirstOrDefault().Id,
                                                CheckedById     = user.FirstOrDefault().Id,
                                                ApprovedById    = user.FirstOrDefault().Id,
                                                Status          = null,
                                                IsPrinted       = false,
                                                IsLocked        = false,
                                                CreatedById     = user.FirstOrDefault().Id,
                                                CreatedDateTime = Convert.ToDateTime(folderMonitoringTrnStockInObject.CreatedDateTime),
                                                UpdatedById     = user.FirstOrDefault().Id,
                                                UpdatedDateTime = Convert.ToDateTime(folderMonitoringTrnStockInObject.CreatedDateTime),
                                                ListFolderMonitoringTrnStockInItems = newFolderMonitoringTrnStockInItems
                                            });
                                        }
                                    }

                                    isDataValid = true;
                                }
                                else
                                {
                                    returnMessage = "This item code: " + folderMonitoringTrnStockInObject.ItemCode + " has invalid unit conversion. Unit: " + folderMonitoringTrnStockInObject.Unit;
                                    isDataValid   = false;

                                    break;
                                }
                            }
                        }
                    }

                    if (isDataValid)
                    {
                        if (newFolderMonitoringTrnStockInHeaders.Any())
                        {
                            foreach (var newFolderMonitoringTrnStockInHeader in newFolderMonitoringTrnStockInHeaders)
                            {
                                Int32 INId = 0;

                                var defaultINNumber = "0000000001";
                                var lastStockIn     = from d in db.TrnStockIns.OrderByDescending(d => d.Id) where d.BranchId == newFolderMonitoringTrnStockInHeader.BranchId select d;
                                if (lastStockIn.Any())
                                {
                                    var INNumber = Convert.ToInt32(lastStockIn.FirstOrDefault().INNumber) + 0000000001;
                                    defaultINNumber = FillLeadingZeroes(INNumber, 10);
                                }

                                Data.TrnStockIn newStockIn = new Data.TrnStockIn
                                {
                                    BranchId        = newFolderMonitoringTrnStockInHeader.BranchId,
                                    INNumber        = defaultINNumber,
                                    INDate          = newFolderMonitoringTrnStockInHeader.INDate,
                                    AccountId       = newFolderMonitoringTrnStockInHeader.AccountId,
                                    ArticleId       = newFolderMonitoringTrnStockInHeader.ArticleId,
                                    Particulars     = newFolderMonitoringTrnStockInHeader.Particulars,
                                    ManualINNumber  = newFolderMonitoringTrnStockInHeader.ManualINNumber,
                                    IsProduced      = newFolderMonitoringTrnStockInHeader.IsProduced,
                                    PreparedById    = newFolderMonitoringTrnStockInHeader.PreparedById,
                                    CheckedById     = newFolderMonitoringTrnStockInHeader.CheckedById,
                                    ApprovedById    = newFolderMonitoringTrnStockInHeader.ApprovedById,
                                    Status          = newFolderMonitoringTrnStockInHeader.Status,
                                    IsPrinted       = newFolderMonitoringTrnStockInHeader.IsPrinted,
                                    IsLocked        = newFolderMonitoringTrnStockInHeader.IsLocked,
                                    CreatedById     = newFolderMonitoringTrnStockInHeader.CreatedById,
                                    CreatedDateTime = newFolderMonitoringTrnStockInHeader.CreatedDateTime,
                                    UpdatedById     = newFolderMonitoringTrnStockInHeader.UpdatedById,
                                    UpdatedDateTime = newFolderMonitoringTrnStockInHeader.UpdatedDateTime,
                                };

                                db.TrnStockIns.InsertOnSubmit(newStockIn);
                                db.SubmitChanges();

                                INId = newStockIn.Id;

                                if (newFolderMonitoringTrnStockInHeader.ListFolderMonitoringTrnStockInItems.Any())
                                {
                                    foreach (var listFolderMonitoringTrnStockInItem in newFolderMonitoringTrnStockInHeader.ListFolderMonitoringTrnStockInItems)
                                    {
                                        Data.TrnStockInItem newStockInItem = new Data.TrnStockInItem
                                        {
                                            INId         = INId,
                                            ItemId       = listFolderMonitoringTrnStockInItem.ItemId,
                                            Particulars  = listFolderMonitoringTrnStockInItem.Particulars,
                                            UnitId       = listFolderMonitoringTrnStockInItem.UnitId,
                                            Quantity     = listFolderMonitoringTrnStockInItem.Quantity,
                                            Cost         = listFolderMonitoringTrnStockInItem.Cost,
                                            Amount       = listFolderMonitoringTrnStockInItem.Amount,
                                            BaseUnitId   = listFolderMonitoringTrnStockInItem.BaseUnitId,
                                            BaseQuantity = listFolderMonitoringTrnStockInItem.BaseQuantity,
                                            BaseCost     = listFolderMonitoringTrnStockInItem.BaseCost
                                        };
                                    }
                                }

                                var stockIn = from d in db.TrnStockIns
                                              where d.Id == INId
                                              select d;

                                if (stockIn.Any())
                                {
                                    var lockStockIn = stockIn.FirstOrDefault();
                                    lockStockIn.IsLocked = true;
                                    db.SubmitChanges();

                                    journal.InsertStockInJournal(INId);
                                    inventory.InsertStockInInventory(INId);
                                }
                            }
                        }
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK, returnMessage));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "Data Source is Invalid or Empty."));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Backend Error: " + ex.Message));
            }
        }
        public HttpResponseMessage AddFolderMonitoringStockIn(List <Entities.FolderMonitoringTrnStockIn> folderMonitoringTrnStockInObjects)
        {
            try
            {
                if (folderMonitoringTrnStockInObjects.Any())
                {
                    foreach (var folderMonitoringTrnStockInObject in folderMonitoringTrnStockInObjects)
                    {
                        Boolean isBranchExist   = false,
                                 isAccountExist = false,
                                 isArticleExist = false,
                                 isUserExist    = false,
                                 isItemExist    = false;

                        var branch = from d in db.MstBranches where d.BranchCode.Equals(folderMonitoringTrnStockInObject.BranchCode) select d;
                        if (branch.Any())
                        {
                            isBranchExist = true;
                        }

                        List <easyfis.Entities.MstArticle> listArticles = new List <easyfis.Entities.MstArticle>();

                        var account = from d in db.MstAccounts where d.AccountCode.Equals(folderMonitoringTrnStockInObject.AccountCode) select d;
                        if (account.Any())
                        {
                            isAccountExist = true;

                            var accountArticleTypes = from d in db.MstAccountArticleTypes where d.AccountId == Convert.ToInt32(account.FirstOrDefault().Id) select d;
                            if (accountArticleTypes.Any())
                            {
                                foreach (var accountArticleType in accountArticleTypes)
                                {
                                    var articles = from d in db.MstArticles where d.ArticleTypeId == accountArticleType.ArticleTypeId && d.IsLocked == true select d;
                                    if (articles.Any())
                                    {
                                        foreach (var articleObject in articles)
                                        {
                                            listArticles.Add(new easyfis.Entities.MstArticle()
                                            {
                                                Id = articleObject.Id,
                                                ManualArticleCode = articleObject.ManualArticleCode,
                                                Article           = articleObject.Article
                                            });
                                        }
                                    }
                                }
                            }
                        }

                        var article = from d in listArticles where d.ManualArticleCode.Equals(folderMonitoringTrnStockInObject.ArticleCode) select d;
                        if (article.Any())
                        {
                            isArticleExist = true;
                        }

                        var user = from d in db.MstUsers where d.UserName.Equals(folderMonitoringTrnStockInObject.UserCode) select d;
                        if (user.Any())
                        {
                            isUserExist = true;
                        }

                        var item = from d in db.MstArticles where d.ArticleTypeId == 1 && d.ManualArticleCode.Equals(folderMonitoringTrnStockInObject.ItemCode) && d.IsInventory == true && d.IsLocked == true select d;
                        if (item.Any())
                        {
                            isItemExist = true;
                        }

                        if (isBranchExist && isUserExist && isAccountExist && isArticleExist && isItemExist)
                        {
                            Int32 INId = 0;

                            var currentStockIn = from d in db.TrnStockIns where d.BranchId == branch.FirstOrDefault().Id&& d.ManualINNumber.Equals(folderMonitoringTrnStockInObject.ManualINNumber) && d.IsLocked == true select d;
                            if (currentStockIn.Any())
                            {
                                INId = currentStockIn.FirstOrDefault().Id;

                                var unlockStockIn = currentStockIn.FirstOrDefault();
                                unlockStockIn.IsLocked        = false;
                                unlockStockIn.UpdatedById     = user.FirstOrDefault().Id;
                                unlockStockIn.UpdatedDateTime = Convert.ToDateTime(folderMonitoringTrnStockInObject.CreatedDateTime);
                                db.SubmitChanges();

                                journal.DeleteStockInJournal(INId);
                                inventory.DeleteStockInInventory(INId);
                            }
                            else
                            {
                                var defaultINNumber = "0000000001";
                                var lastStockIn     = from d in db.TrnStockIns.OrderByDescending(d => d.Id) where d.BranchId == branch.FirstOrDefault().Id select d;
                                if (lastStockIn.Any())
                                {
                                    var INNumber = Convert.ToInt32(lastStockIn.FirstOrDefault().INNumber) + 0000000001;
                                    defaultINNumber = FillLeadingZeroes(INNumber, 10);
                                }

                                Data.TrnStockIn newStockIn = new Data.TrnStockIn
                                {
                                    BranchId        = branch.FirstOrDefault().Id,
                                    INNumber        = defaultINNumber,
                                    INDate          = Convert.ToDateTime(folderMonitoringTrnStockInObject.INDate),
                                    AccountId       = account.FirstOrDefault().Id,
                                    ArticleId       = article.FirstOrDefault().Id,
                                    Particulars     = folderMonitoringTrnStockInObject.Remarks,
                                    ManualINNumber  = folderMonitoringTrnStockInObject.ManualINNumber,
                                    IsProduced      = folderMonitoringTrnStockInObject.IsProduce,
                                    PreparedById    = user.FirstOrDefault().Id,
                                    CheckedById     = user.FirstOrDefault().Id,
                                    ApprovedById    = user.FirstOrDefault().Id,
                                    Status          = null,
                                    IsPrinted       = false,
                                    IsLocked        = false,
                                    CreatedById     = user.FirstOrDefault().Id,
                                    CreatedDateTime = Convert.ToDateTime(folderMonitoringTrnStockInObject.CreatedDateTime),
                                    UpdatedById     = user.FirstOrDefault().Id,
                                    UpdatedDateTime = Convert.ToDateTime(folderMonitoringTrnStockInObject.CreatedDateTime)
                                };

                                db.TrnStockIns.InsertOnSubmit(newStockIn);
                                db.SubmitChanges();

                                INId = newStockIn.Id;
                            }

                            var unitConversion = from d in item.FirstOrDefault().MstArticleUnits where d.MstUnit.Unit.Equals(folderMonitoringTrnStockInObject.Unit) select d;
                            if (unitConversion.Any())
                            {
                                Decimal baseQuantity = folderMonitoringTrnStockInObject.Quantity * 1;
                                if (unitConversion.FirstOrDefault().Multiplier > 0)
                                {
                                    baseQuantity = folderMonitoringTrnStockInObject.Quantity * (1 / unitConversion.FirstOrDefault().Multiplier);
                                }

                                Decimal baseCost = folderMonitoringTrnStockInObject.Amount;
                                if (baseQuantity > 0)
                                {
                                    baseCost = folderMonitoringTrnStockInObject.Amount / baseQuantity;
                                }

                                Data.TrnStockInItem newStockInItem = new Data.TrnStockInItem
                                {
                                    INId         = INId,
                                    ItemId       = item.FirstOrDefault().Id,
                                    Particulars  = folderMonitoringTrnStockInObject.Particulars,
                                    UnitId       = unitConversion.FirstOrDefault().UnitId,
                                    Quantity     = folderMonitoringTrnStockInObject.Quantity,
                                    Cost         = folderMonitoringTrnStockInObject.Cost,
                                    Amount       = folderMonitoringTrnStockInObject.Amount,
                                    BaseUnitId   = item.FirstOrDefault().UnitId,
                                    BaseQuantity = baseQuantity,
                                    BaseCost     = baseCost
                                };

                                db.TrnStockInItems.InsertOnSubmit(newStockInItem);
                                db.SubmitChanges();

                                var stockIn = from d in db.TrnStockIns where d.Id == INId && d.IsLocked == false select d;
                                if (stockIn.Any())
                                {
                                    var lockStockIn = stockIn.FirstOrDefault();
                                    lockStockIn.IsLocked        = true;
                                    lockStockIn.UpdatedById     = user.FirstOrDefault().Id;
                                    lockStockIn.UpdatedDateTime = Convert.ToDateTime(folderMonitoringTrnStockInObject.CreatedDateTime);
                                    db.SubmitChanges();

                                    journal.InsertStockInJournal(INId);
                                    inventory.InsertStockInInventory(INId);
                                }
                            }
                        }
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, "No data found."));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server."));
            }
        }
Beispiel #5
0
        public HttpResponseMessage LockStockIn(Entities.TrnStockIn objStockIn, String id)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.UserId == User.Identity.GetUserId()
                                  select d;

                if (currentUser.Any())
                {
                    var currentUserId = currentUser.FirstOrDefault().Id;

                    var userForms = from d in db.MstUserForms
                                    where d.UserId == currentUserId &&
                                    d.SysForm.FormName.Equals("StockInDetail")
                                    select d;

                    if (userForms.Any())
                    {
                        if (userForms.FirstOrDefault().CanLock)
                        {
                            var stockIn = from d in db.TrnStockIns
                                          where d.Id == Convert.ToInt32(id)
                                          select d;

                            if (stockIn.Any())
                            {
                                if (!stockIn.FirstOrDefault().IsLocked)
                                {
                                    var lockStockIn = stockIn.FirstOrDefault();
                                    lockStockIn.INDate          = Convert.ToDateTime(objStockIn.INDate);
                                    lockStockIn.AccountId       = objStockIn.AccountId;
                                    lockStockIn.ArticleId       = objStockIn.ArticleId;
                                    lockStockIn.Particulars     = objStockIn.Particulars;
                                    lockStockIn.ManualINNumber  = objStockIn.ManualINNumber;
                                    lockStockIn.IsProduced      = objStockIn.IsProduced;
                                    lockStockIn.CheckedById     = objStockIn.CheckedById;
                                    lockStockIn.ApprovedById    = objStockIn.ApprovedById;
                                    lockStockIn.IsLocked        = true;
                                    lockStockIn.UpdatedById     = currentUserId;
                                    lockStockIn.UpdatedDateTime = DateTime.Now;

                                    db.SubmitChanges();

                                    // =====================
                                    // Journal and Inventory
                                    // =====================
                                    Business.Journal   journal   = new Business.Journal();
                                    Business.Inventory inventory = new Business.Inventory();

                                    if (lockStockIn.IsLocked)
                                    {
                                        journal.InsertStockInJournal(Convert.ToInt32(id));
                                        inventory.InsertStockInInventory(Convert.ToInt32(id));
                                    }

                                    return(Request.CreateResponse(HttpStatusCode.OK));
                                }
                                else
                                {
                                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Locking Error. These stock in details are already locked."));
                                }
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "Data not found. These stock in details are not found in the server."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to lock stockIn."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access for this stock in page."));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Theres no current user logged in."));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server."));
            }
        }