Пример #1
0
        public HttpResponseMessage UpdateStockInItem(Entities.TrnStockInItem objStockInItem, String id, String INId)
        {
            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().CanEdit)
                        {
                            var stockIn = from d in db.TrnStockIns
                                          where d.Id == Convert.ToInt32(INId)
                                          select d;

                            if (stockIn.Any())
                            {
                                if (!stockIn.FirstOrDefault().IsLocked)
                                {
                                    var stockInItem = from d in db.TrnStockInItems
                                                      where d.Id == Convert.ToInt32(id)
                                                      select d;

                                    if (stockInItem.Any())
                                    {
                                        var item = from d in db.MstArticles
                                                   where d.Id == objStockInItem.ItemId &&
                                                   d.ArticleTypeId == 1 &&
                                                   d.IsLocked == true
                                                   select d;

                                        if (item.Any())
                                        {
                                            var conversionUnit = from d in db.MstArticleUnits
                                                                 where d.ArticleId == objStockInItem.ItemId &&
                                                                 d.UnitId == objStockInItem.UnitId &&
                                                                 d.MstArticle.IsLocked == true
                                                                 select d;

                                            if (conversionUnit.Any())
                                            {
                                                Decimal baseQuantity = objStockInItem.Quantity * 1;
                                                if (conversionUnit.FirstOrDefault().Multiplier > 0)
                                                {
                                                    baseQuantity = objStockInItem.Quantity * (1 / conversionUnit.FirstOrDefault().Multiplier);
                                                }

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

                                                var updateStockInItem = stockInItem.FirstOrDefault();
                                                updateStockInItem.INId         = Convert.ToInt32(INId);
                                                updateStockInItem.ItemId       = objStockInItem.ItemId;
                                                updateStockInItem.Particulars  = objStockInItem.Particulars;
                                                updateStockInItem.Quantity     = objStockInItem.Quantity;
                                                updateStockInItem.UnitId       = objStockInItem.UnitId;
                                                updateStockInItem.Cost         = objStockInItem.Cost;
                                                updateStockInItem.Amount       = objStockInItem.Amount;
                                                updateStockInItem.BaseUnitId   = item.FirstOrDefault().UnitId;
                                                updateStockInItem.BaseQuantity = baseQuantity;
                                                updateStockInItem.BaseUnitId   = item.FirstOrDefault().UnitId;
                                                updateStockInItem.BaseCost     = baseCost;

                                                db.SubmitChanges();

                                                return(Request.CreateResponse(HttpStatusCode.OK));
                                            }
                                            else
                                            {
                                                return(Request.CreateResponse(HttpStatusCode.BadRequest, "The selected item has no unit conversion."));
                                            }
                                        }
                                        else
                                        {
                                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "The selected item was not found in the server."));
                                        }
                                    }
                                    else
                                    {
                                        return(Request.CreateResponse(HttpStatusCode.NotFound, "This stock in item detail is no longer exist in the server."));
                                    }
                                }
                                else
                                {
                                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "You cannot update stock in item if the current stock in detail is locked."));
                                }
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "These current stock in details are not found in the server. Please add new stock in first before proceeding."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to edit and update stock in item in this stock in detail page."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access in this stock in detail 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."));
            }
        }
Пример #2
0
        public HttpResponseMessage AddStockInItem(Entities.TrnStockInItem objStockInItem, String INId)
        {
            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().CanAdd)
                        {
                            var stockIn = from d in db.TrnStockIns
                                          where d.Id == Convert.ToInt32(INId)
                                          select d;

                            if (stockIn.Any())
                            {
                                if (!stockIn.FirstOrDefault().IsLocked)
                                {
                                    var item = from d in db.MstArticles
                                               where d.Id == objStockInItem.ItemId &&
                                               d.ArticleTypeId == 1 &&
                                               d.IsLocked == true
                                               select d;

                                    if (item.Any())
                                    {
                                        var conversionUnit = from d in db.MstArticleUnits
                                                             where d.ArticleId == objStockInItem.ItemId &&
                                                             d.UnitId == objStockInItem.UnitId &&
                                                             d.MstArticle.IsLocked == true
                                                             select d;

                                        if (conversionUnit.Any())
                                        {
                                            Decimal baseQuantity = objStockInItem.Quantity * 1;
                                            if (conversionUnit.FirstOrDefault().Multiplier > 0)
                                            {
                                                baseQuantity = objStockInItem.Quantity * (1 / conversionUnit.FirstOrDefault().Multiplier);
                                            }

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

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

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

                                            String newObject = at.GetObjectString(newStockInItem);
                                            at.InsertAuditTrail(currentUser.FirstOrDefault().Id, GetType().Name, MethodBase.GetCurrentMethod().Name, "NA", newObject);

                                            return(Request.CreateResponse(HttpStatusCode.OK));
                                        }
                                        else
                                        {
                                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "The selected item has no unit conversion."));
                                        }
                                    }
                                    else
                                    {
                                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "The selected item was not found in the server."));
                                    }
                                }
                                else
                                {
                                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "You cannot add new stock in item if the current stock in detail is locked."));
                                }
                            }
                            else
                            {
                                return(Request.CreateResponse(HttpStatusCode.NotFound, "These current stock in details are not found in the server. Please add new stock in first before proceeding."));
                            }
                        }
                        else
                        {
                            return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no rights to add new stock in item in this stock in detail page."));
                        }
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, "Sorry. You have no access in this stock in detail 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."));
            }
        }