public HttpResponseMessage putStockIn(String id, Entities.TrnStockIn stockIn)
        {
            try
            {
                var stockIns = from d in db.TrnStockIns where d.Id == Convert.ToInt32(id) select d;
                if (stockIns.Any())
                {
                    var updateStockIn = stockIns.FirstOrDefault();
                    updateStockIn.PeriodId        = stockIn.PeriodId;
                    updateStockIn.StockInDate     = stockIn.StockInDate;
                    updateStockIn.StockInNumber   = stockIn.StockInNumber;
                    updateStockIn.SupplierId      = stockIn.SupplierId;
                    updateStockIn.Remarks         = stockIn.Remarks;
                    updateStockIn.IsReturn        = stockIn.IsReturn;
                    updateStockIn.CollectionId    = stockIn.CollectionId;
                    updateStockIn.PurchaseOrderId = stockIn.PurchaseOrderId;
                    updateStockIn.PreparedBy      = stockIn.PreparedBy;
                    updateStockIn.CheckedBy       = stockIn.CheckedBy;
                    updateStockIn.ApprovedBy      = stockIn.ApprovedBy;
                    updateStockIn.IsLocked        = -1;
                    updateStockIn.EntryUserId     = UserId();
                    updateStockIn.EntryDateTime   = DateTime.Today;
                    updateStockIn.UpdateUserId    = UserId();
                    updateStockIn.UpdateDateTime  = DateTime.Today;
                    db.SubmitChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }
            }
            catch (Exception e)
            {
                // Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Exemplo n.º 2
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."));
            }
        }