Example #1
0
        public HttpResponseMessage unlockStockOut(String id, Models.TrnStockOut stockOut)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                var stockOuts = from d in db.TrnStockOuts where d.Id == Convert.ToInt32(id) select d;
                if (stockOuts.Any())
                {
                    var updateStockOut = stockOuts.FirstOrDefault();

                    updateStockOut.IsLocked        = false;
                    updateStockOut.UpdatedById     = userId;
                    updateStockOut.UpdatedDateTime = DateTime.Now;

                    db.SubmitChanges();

                    inventory.deleteOTInventory(Convert.ToInt32(id));
                    journal.deleteOTJournal(Convert.ToInt32(id));

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Example #2
0
        public Int32 insertStockOut(Models.TrnStockOut stockOut)
        {
            try
            {
                var lastOTNumber = from d in db.TrnStockOuts.OrderByDescending(d => d.Id)
                                   where d.BranchId == currentBranchId()
                                   select d;

                var OTNumberResult = "0000000001";

                if (lastOTNumber.Any())
                {
                    var OTNumber = Convert.ToInt32(lastOTNumber.FirstOrDefault().OTNumber) + 0000000001;
                    OTNumberResult = zeroFill(OTNumber, 10);
                }

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

                Data.TrnStockOut newStockOut = new Data.TrnStockOut();
                newStockOut.BranchId        = currentBranchId();
                newStockOut.OTNumber        = OTNumberResult;
                newStockOut.OTDate          = DateTime.Today;
                newStockOut.AccountId       = users.IncomeAccountId;
                newStockOut.ArticleId       = (from d in db.MstArticles where d.ArticleTypeId == 6 select d.Id).FirstOrDefault();
                newStockOut.Particulars     = "NA";
                newStockOut.ManualOTNumber  = "NA";
                newStockOut.PreparedById    = users.Id;
                newStockOut.CheckedById     = users.Id;
                newStockOut.ApprovedById    = users.Id;
                newStockOut.IsLocked        = false;
                newStockOut.CreatedById     = users.Id;
                newStockOut.CreatedDateTime = DateTime.Now;
                newStockOut.UpdatedById     = users.Id;
                newStockOut.UpdatedDateTime = DateTime.Now;

                db.TrnStockOuts.InsertOnSubmit(newStockOut);
                db.SubmitChanges();

                return(newStockOut.Id);
            }
            catch
            {
                return(0);
            }
        }
Example #3
0
        public HttpResponseMessage updateStockOut(String id, Models.TrnStockOut stockOut)
        {
            try
            {
                var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault();

                var stockOuts = from d in db.TrnStockOuts where d.Id == Convert.ToInt32(id) select d;
                if (stockOuts.Any())
                {
                    var updateStockOut = stockOuts.FirstOrDefault();
                    updateStockOut.BranchId        = stockOut.BranchId;
                    updateStockOut.OTNumber        = stockOut.OTNumber;
                    updateStockOut.OTDate          = Convert.ToDateTime(stockOut.OTDate);
                    updateStockOut.AccountId       = stockOut.AccountId;
                    updateStockOut.ArticleId       = stockOut.ArticleId;
                    updateStockOut.Particulars     = stockOut.Particulars;
                    updateStockOut.ManualOTNumber  = stockOut.ManualOTNumber;
                    updateStockOut.PreparedById    = stockOut.PreparedById;
                    updateStockOut.CheckedById     = stockOut.CheckedById;
                    updateStockOut.ApprovedById    = stockOut.ApprovedById;
                    updateStockOut.IsLocked        = true;
                    updateStockOut.UpdatedById     = userId;
                    updateStockOut.UpdatedDateTime = DateTime.Now;
                    db.SubmitChanges();

                    inventory.InsertOTInventory(Convert.ToInt32(id));
                    journal.insertOTJournal(Convert.ToInt32(id));

                    // Check for negative inventory
                    bool foundNegativeQuantity = false;
                    if (updateStockOut.TrnStockOutItems.Any())
                    {
                        foreach (var stockOutItem in updateStockOut.TrnStockOutItems)
                        {
                            if (stockOutItem.MstArticle.IsInventory)
                            {
                                var mstArticleInventory = from d in db.MstArticleInventories
                                                          where d.TrnStockOutItems.Contains(stockOutItem)
                                                          select d;

                                if (mstArticleInventory.Any())
                                {
                                    if (stockOutItem.MstArticleInventory.Quantity < 0)
                                    {
                                        foundNegativeQuantity = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if (!foundNegativeQuantity)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                    else
                    {
                        inventory.deleteOTInventory(Convert.ToInt32(id));
                        journal.deleteOTJournal(Convert.ToInt32(id));

                        updateStockOut.IsLocked = false;
                        db.SubmitChanges();

                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Negative Inventory Found!"));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }