public Int32 postStockIn()
        {
            try
            {
                Data.TrnStockIn newStockIn = new Data.TrnStockIn();
                newStockIn.PeriodId        = PeriodId();
                newStockIn.StockInDate     = DateTime.Today;
                newStockIn.StockInNumber   = "n/a";
                newStockIn.SupplierId      = SupplierId();
                newStockIn.Remarks         = "n/a";
                newStockIn.IsReturn        = false;
                newStockIn.CollectionId    = CollectionId();
                newStockIn.PurchaseOrderId = PurchaseOrderId();
                newStockIn.PreparedBy      = UserId();
                newStockIn.CheckedBy       = UserId();
                newStockIn.ApprovedBy      = UserId();
                newStockIn.IsLocked        = 0;
                newStockIn.EntryUserId     = UserId();
                newStockIn.EntryDateTime   = DateTime.Today;
                newStockIn.UpdateUserId    = UserId();
                newStockIn.UpdateDateTime  = DateTime.Today;
                db.TrnStockIns.InsertOnSubmit(newStockIn);
                db.SubmitChanges();

                return(newStockIn.Id);
            }
            catch (Exception e)
            {
                return(0);
            }
        }
예제 #2
0
        public Int32 insertStockIn(Models.TrnStockIn stockIn)
        {
            try
            {
                var lastINNumber = from d in db.TrnStockIns.OrderByDescending(d => d.Id)
                                   where d.BranchId == currentBranchId()
                                   select d;

                var INNumberResult = "0000000001";

                if (lastINNumber.Any())
                {
                    var INNumber = Convert.ToInt32(lastINNumber.FirstOrDefault().INNumber) + 0000000001;
                    INNumberResult = zeroFill(INNumber, 10);
                }

                var users = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d).FirstOrDefault();

                Data.TrnStockIn newStockIn = new Data.TrnStockIn();
                newStockIn.BranchId        = currentBranchId();
                newStockIn.INNumber        = INNumberResult;
                newStockIn.INDate          = DateTime.Today;
                newStockIn.AccountId       = users.IncomeAccountId;
                newStockIn.ArticleId       = (from d in db.MstArticles where d.ArticleTypeId == 6 select d.Id).FirstOrDefault();
                newStockIn.Particulars     = "NA";
                newStockIn.ManualINNumber  = "NA";
                newStockIn.IsProduced      = false;
                newStockIn.PreparedById    = users.Id;
                newStockIn.CheckedById     = users.Id;
                newStockIn.ApprovedById    = users.Id;
                newStockIn.IsLocked        = false;
                newStockIn.CreatedById     = users.Id;
                newStockIn.CreatedDateTime = DateTime.Now;
                newStockIn.UpdatedById     = users.Id;
                newStockIn.UpdatedDateTime = DateTime.Now;

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

                return(newStockIn.Id);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(0);
            }
        }
        public Int32 postTrnStockIn(Entities.TrnStockIn add)
        {
            try
            {
                var period       = from d in db.MstPeriods where d.Id > 0 select d.Id;
                var supplier     = from d in db.MstSuppliers select d;
                var collection   = from d in db.TrnCollections select d;
                var purcherOrder = from d in db.TrnPurchaseOrders select d;
                var user         = from d in db.MstUsers select d;
                var stockIn      = from d in db.TrnStockIns.OrderByDescending(m => m.StockInNumber) select d;
                var userId       = (from d in db.MstUsers where d.AspNetUserId == User.Identity.GetUserId() select d).FirstOrDefault().Id;

                Data.TrnStockIn addStock = new Data.TrnStockIn();
                addStock.PeriodId        = period.FirstOrDefault();
                addStock.StockInDate     = DateTime.Today;
                addStock.StockInNumber   = stockIn.Select(m => m.StockInNumber).FirstOrDefault();
                addStock.SupplierId      = supplier.Select(m => m.Id).FirstOrDefault();
                addStock.Remarks         = "n/a";
                addStock.IsReturn        = false;
                addStock.CollectionId    = collection.Select(m => m.Id).FirstOrDefault();
                addStock.PurchaseOrderId = purcherOrder.Select(m => m.Id).FirstOrDefault();
                addStock.PreparedBy      = user.Select(m => m.Id).FirstOrDefault();
                addStock.CheckedBy       = user.Select(m => m.Id).FirstOrDefault();
                addStock.ApprovedBy      = user.Select(m => m.Id).FirstOrDefault();
                addStock.IsLocked        = 0;
                addStock.EntryUserId     = userId;
                addStock.EntryDateTime   = DateTime.Today;
                addStock.UpdateUserId    = userId;
                addStock.UpdateDateTime  = DateTime.Today;
                db.TrnStockIns.InsertOnSubmit(addStock);
                db.SubmitChanges();

                return(addStock.Id);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(0);
            }
        }
예제 #4
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."));
            }
        }
        public HttpResponseMessage AddStockInCSVIntegrator(List <CSVIntegratorEntities.CSVIntegratorTrnStockIn> objStockIns)
        {
            try
            {
                if (objStockIns.Any())
                {
                    foreach (var objStockIn in objStockIns)
                    {
                        Boolean currentBranchExist = false;
                        var     currentBranch      = from d in db.MstBranches where d.BranchCode.Equals(objStockIn.BranchCode) select d;
                        if (currentBranch.Any())
                        {
                            currentBranchExist = true;
                        }

                        Boolean accountsExist = false;
                        var     accounts      = from d in db.MstAccounts where d.IsLocked == true select d;

                        List <Int32> listArticleIds = new List <Int32>();
                        if (accounts.Any())
                        {
                            accountsExist = true;
                            var accountArticleTypes = from d in db.MstAccountArticleTypes where d.AccountId == accounts.FirstOrDefault().Id&& d.MstAccount.IsLocked == true 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 article in articles)
                                        {
                                            listArticleIds.Add(article.Id);
                                        }
                                    }
                                }
                            }
                        }

                        Boolean articleListsExist = false;
                        var     articleLists      = from d in listArticleIds.ToList() select d;
                        if (articleLists.Any())
                        {
                            articleListsExist = true;
                        }

                        Boolean usersExist = false;
                        var     users      = from d in db.MstUsers.OrderBy(d => d.FullName) where d.IsLocked == true select d;
                        if (users.Any())
                        {
                            usersExist = true;
                        }

                        Boolean isValid = false;
                        if (currentBranchExist)
                        {
                            if (accountsExist)
                            {
                                if (articleListsExist)
                                {
                                    if (usersExist)
                                    {
                                        isValid = true;
                                    }
                                }
                            }
                        }

                        if (isValid)
                        {
                            var defaultINNumber = "0000000001";
                            var lastStockIn     = from d in db.TrnStockIns.OrderByDescending(d => d.Id)
                                                  where d.MstBranch.BranchCode.Equals(objStockIn.BranchCode)
                                                  select d;

                            if (lastStockIn.Any())
                            {
                                var INNumber = Convert.ToInt32(lastStockIn.FirstOrDefault().INNumber) + 0000000001;
                                defaultINNumber = FillLeadingZeroes(INNumber, 10);
                            }

                            Data.TrnStockIn newStockIn = new Data.TrnStockIn
                            {
                                BranchId        = currentBranch.FirstOrDefault().Id,
                                INNumber        = defaultINNumber,
                                INDate          = Convert.ToDateTime(objStockIn.INDate),
                                AccountId       = accounts.FirstOrDefault().Id,
                                ArticleId       = listArticleIds.FirstOrDefault(),
                                Particulars     = objStockIn.Particulars,
                                ManualINNumber  = objStockIn.ManualINNumber,
                                IsProduced      = objStockIn.IsProduced,
                                PreparedById    = users.FirstOrDefault().Id,
                                CheckedById     = users.FirstOrDefault().Id,
                                ApprovedById    = users.FirstOrDefault().Id,
                                IsLocked        = false,
                                CreatedById     = users.FirstOrDefault().Id,
                                CreatedDateTime = DateTime.Now,
                                UpdatedById     = users.FirstOrDefault().Id,
                                UpdatedDateTime = DateTime.Now
                            };

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

                    return(Request.CreateResponse(HttpStatusCode.OK, "Sent Successful!"));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Empty!"));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, "Something's went wrong from the server! " + e.Message));
            }
        }
예제 #7
0
        public HttpResponseMessage AddStockIn()
        {
            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 currentBranchId = currentUser.FirstOrDefault().BranchId;

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

                    if (userForms.Any())
                    {
                        if (userForms.FirstOrDefault().CanAdd)
                        {
                            var defaultINNumber = "0000000001";
                            var lastStockIn     = from d in db.TrnStockIns.OrderByDescending(d => d.Id)
                                                  where d.BranchId == currentBranchId
                                                  select d;

                            if (lastStockIn.Any())
                            {
                                var INNumber = Convert.ToInt32(lastStockIn.FirstOrDefault().INNumber) + 0000000001;
                                defaultINNumber = FillLeadingZeroes(INNumber, 10);
                            }

                            var accounts = from d in db.MstAccounts
                                           where d.IsLocked == true
                                           select d;

                            if (accounts.Any())
                            {
                                List <Int32> listArticleIds = new List <Int32>();

                                var accountArticleTypes = from d in db.MstAccountArticleTypes
                                                          where d.AccountId == accounts.FirstOrDefault().Id &&
                                                          d.MstAccount.IsLocked == true
                                                          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 article in articles)
                                            {
                                                listArticleIds.Add(article.Id);
                                            }
                                        }
                                    }
                                }

                                if (listArticleIds.Any())
                                {
                                    var articleLists = from d in listArticleIds.ToList()
                                                       select d;

                                    if (articleLists.Any())
                                    {
                                        var users = from d in db.MstUsers.OrderBy(d => d.FullName)
                                                    where d.IsLocked == true
                                                    select d;

                                        if (users.Any())
                                        {
                                            Data.TrnStockIn newStockIn = new Data.TrnStockIn
                                            {
                                                BranchId        = currentBranchId,
                                                INNumber        = defaultINNumber,
                                                INDate          = DateTime.Today,
                                                AccountId       = accounts.FirstOrDefault().Id,
                                                ArticleId       = listArticleIds.FirstOrDefault(),
                                                Particulars     = "NA",
                                                ManualINNumber  = "NA",
                                                IsProduced      = false,
                                                PreparedById    = currentUserId,
                                                CheckedById     = currentUserId,
                                                ApprovedById    = currentUserId,
                                                IsLocked        = false,
                                                CreatedById     = currentUserId,
                                                CreatedDateTime = DateTime.Now,
                                                UpdatedById     = currentUserId,
                                                UpdatedDateTime = DateTime.Now
                                            };

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

                                            return(Request.CreateResponse(HttpStatusCode.OK, newStockIn.Id));
                                        }
                                        else
                                        {
                                            return(Request.CreateResponse(HttpStatusCode.NotFound, "No user found. Please setup more users for all transactions."));
                                        }
                                    }
                                    else
                                    {
                                        return(Request.CreateResponse(HttpStatusCode.NotFound, "No pay type found. Please setup more pay types for all transactions."));
                                    }
                                }
                                else
                                {
                                    return(Request.CreateResponse(HttpStatusCode.NotFound, "No article found. Please setup more articles for all transactions."));
                                }
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "No supplier found. Please setup more suppliers for all transactions."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add 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."));
            }
        }
예제 #8
0
        public int Post(Models.TrnStockIn stockIn)
        {
            try
            {
                var isLocked = 1;
                var identityUserId = User.Identity.GetUserId();
                var mstUserId = (from d in db.MstUsers where "" + d.Id == identityUserId select d.Id).SingleOrDefault();
                var date = DateTime.Now;

                Data.TrnStockIn newstockIn = new Data.TrnStockIn();

                newstockIn.PeriodId = stockIn.PeriodId;
                newstockIn.StockInDate = Convert.ToDateTime(stockIn.StockInDate);
                newstockIn.StockInNumber = stockIn.StockInNumber;
                newstockIn.Remarks = stockIn.Remarks;
                newstockIn.IsReturn = stockIn.IsReturn;
                newstockIn.CollectionId = stockIn.CollectionId;
                newstockIn.PurchaseOrderId = stockIn.PurchaseOrderId;
                newstockIn.PreparedBy = stockIn.PreparedBy;
                newstockIn.CheckedBy = stockIn.CheckedBy;
                newstockIn.ApprovedBy = stockIn.ApprovedBy;
                newstockIn.IsLocked = isLocked;
                newstockIn.EntryUserId = mstUserId;
                newstockIn.EntryDateTime = date;
                newstockIn.UpdateUserId = mstUserId;
                newstockIn.UpdateDateTime = date;

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

                return newstockIn.Id;
            }
            catch
            {
                return 0;
            }
        }
예제 #9
0
        public Int32 insertStockIn(Models.TrnStockIn stockIn)
        {
            try
            {
                var lastINNumber = from d in db.TrnStockIns.OrderByDescending(d => d.Id) select d;
                var INNumberResult = "0000000001";

                if (lastINNumber.Any())
                {
                    var INNumber = Convert.ToInt32(lastINNumber.FirstOrDefault().INNumber) + 0000000001;
                    INNumberResult = zeroFill(INNumber, 10);
                }

                var users = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d).FirstOrDefault();

                Data.TrnStockIn newStockIn = new Data.TrnStockIn();
                newStockIn.BranchId = currentBranchId();
                newStockIn.INNumber = INNumberResult;
                newStockIn.INDate = DateTime.Today;
                newStockIn.AccountId = users.IncomeAccountId;
                newStockIn.ArticleId = (from d in db.MstArticles where d.ArticleTypeId == 6 select d.Id).FirstOrDefault();
                newStockIn.Particulars = "NA";
                newStockIn.ManualINNumber = "NA";
                newStockIn.IsProduced = false;
                newStockIn.PreparedById = users.Id;
                newStockIn.CheckedById = users.Id;
                newStockIn.ApprovedById = users.Id;
                newStockIn.IsLocked = false;
                newStockIn.CreatedById = users.Id;
                newStockIn.CreatedDateTime = DateTime.Now;
                newStockIn.UpdatedById = users.Id;
                newStockIn.UpdatedDateTime = DateTime.Now;

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

                return newStockIn.Id;
            }
            catch(Exception e)
            {
                Debug.WriteLine(e);
                return 0;
            }
        }