Exemple #1
0
        public static void AddRequest(string products, string qty, int id)
        {
            string[] productArr = products.Split(',').ToArray();
            int[]    qtyArr     = qty.Split(',').Select(n => Convert.ToInt32(n)).ToArray();
            DateTime reqTime    = DateTime.Now;

            using (LogicEntities db = new LogicEntities())
            {
                string  DeptId   = db.DepartmentStaff.Where(x => x.StaffId == id).Select(x => x.DeptId).FirstOrDefault();
                string  DeptName = db.Department.Where(x => x.DeptId == DeptId).Select(x => x.DeptName).FirstOrDefault();
                Request request  = new Request();
                request.StaffId = id;
                request.DeptId  = DeptId;
                //request.RequestFormId = DeptId + "/";
                //request.FavRequest = (save == "yes") ? true : false;
                request.ReqDate = reqTime;
                request.Status  = status.Pending.ToString();
                db.Request.Add(request);
                db.SaveChanges();
                for (int i = 0; i < productArr.Length; i++)
                {
                    string        des       = productArr[i];
                    string        productId = db.Product.Where(x => x.Description == des).Select(x => x.ProductId).SingleOrDefault();
                    RequestDetail rd        = new RequestDetail();
                    rd.ProductId = productId;
                    rd.ReqQty    = qtyArr[i];
                    rd.RequestId = request.RequestId;
                    db.RequestDetail.Add(rd);
                }
                db.SaveChanges();
                Request r = db.Request.Find(request.RequestId);
                r.RequestFormId = DeptId + "/" + "R0" + r.RequestId + "-" + DeptName;
                db.SaveChanges();
            }
        }
Exemple #2
0
        public static void AddRequest(string products, string qty, int id, string nameId)
        {
            string[] productArr = products.Split(',').ToArray();
            int[]    qtyArr     = qty.Split(',').Select(n => Convert.ToInt32(n)).ToArray();

            using (LogicEntities db = new LogicEntities())
            {
                string   DeptId   = db.DepartmentStaff.Where(x => x.StaffId == id).Select(x => x.DeptId).FirstOrDefault();
                string   DeptName = db.Department.Where(x => x.DeptId == DeptId).Select(x => x.DeptName).FirstOrDefault();
                FavOrder request  = new FavOrder();
                request.StaffId = id;
                request.DeptId  = DeptId;

                request.FavOrderName = nameId;
                db.FavOrder.Add(request);
                db.SaveChanges();
                for (int i = 0; i < productArr.Length; i++)
                {
                    string          des       = productArr[i];
                    string          productId = db.Product.Where(x => x.Description == des).Select(x => x.ProductId).FirstOrDefault();
                    FavOrderDetails rd        = new FavOrderDetails();
                    rd.ProductId  = productId;
                    rd.FavQty     = qtyArr[i];
                    rd.FavOrderId = request.FavOrderId;
                    db.FavOrderDetails.Add(rd);
                }
                db.SaveChanges();
                FavOrder r = db.FavOrder.Find(request.FavOrderId);
                r.FavFormId = DeptId + "/" + "F0" + r.FavOrderId + "-" + DeptName;
                db.SaveChanges();
            }
        }
        public ActionResult SetDisbursementList(int id, string status, string deptId)
        {
            string[] productIds    = Request.Form.GetValues("productId");
            string[] requestedQtys = Request.Form.GetValues("requestedQty");
            string[] receivedQtys  = Request.Form.GetValues("receivedQty");
            string[] remarks       = Request.Form.GetValues("remarks");
            int      storeStaffId  = Convert.ToInt32(Request.Form.Get("creatorId"));

            //Update the item quantities && Set Disburesment status to delivered
            disbursementDAO.SaveDisbursement(id, status, receivedQtys, remarks, storeStaffId);
            DepartmentStaff rep = departmentStaffDAO.getDeptRep(deptId);

            //Set all the orders status to Delivered. Not DAO-ed
            using (db = new LogicEntities())
            {
                var resultSet = from r in db.Request
                                where r.DeptId == deptId
                                select r;
                List <Request> requests = resultSet.ToList();
                foreach (Request req in requests)
                {
                    req.Status          = "Delivered";
                    db.Entry(req).State = EntityState.Modified;
                    db.SaveChanges();
                }
                //if Qty received < Qty Requested, Generate outstanding order in requests

                Request outstanding = new Request
                {
                    DeptId  = deptId,
                    ReqDate = DateTime.Now,
                    Remark  = "Outstanding Order, " + DateTime.Now.Date.ToString("d"),
                    Status  = "Outstanding",
                    StaffId = rep.StaffId
                };
                List <RequestDetail> outstandingDetails = new List <RequestDetail>();
                for (int x = 0; x < requestedQtys.Length; x++)
                {
                    if (requestedQtys[x] != receivedQtys[x])
                    {
                        RequestDetail rd = new RequestDetail
                        {
                            ProductId   = productIds[x],
                            RequestId   = outstanding.RequestId,
                            ReqQty      = Convert.ToInt32(requestedQtys[x]) - Convert.ToInt32(receivedQtys[x]),
                            ReceivedQty = 0, //Shouldn't be needed...
                        };
                        outstandingDetails.Add(rd);
                    }
                }
                if (outstandingDetails.Count != 0)
                {
                    db.Request.Add(outstanding);
                    db.RequestDetail.AddRange(outstandingDetails);
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("FindDisbursementList"));
        }
 public ActionResult CreateProduct([Bind(Include = "ProductId,Category,Description,Bin,Unit,Qty,ReorderLevel,ReorderQty")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Product.Add(product);
         db.SaveChanges();
         return(RedirectToAction("ProductDetails", new { category = product.Category }));
     }
     return(View(product));
 }
Exemple #5
0
 public ActionResult Edit([Bind(Include = "DeptId,DeptName,ContactName,PhNo,FaxNo,EmailAddr,HeadId,CollectionPt,RepId")] Department department)
 {
     if (ModelState.IsValid)
     {
         db.Entry(department).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CollectionPt = new SelectList(db.CollectionPoint, "CollectionPtId", "CollectionPt", department.CollectionPt);
     return(View(department));
 }
        public int SaveNewPO(string supplierId, string[] productIds, string[] requiredQty, int id)
        {
            List <PurchaseOrderDetail> purchaseOrderDetails = new List <PurchaseOrderDetail>();

            PurchaseOrder po = new PurchaseOrder
            {
                OrderDate    = DateTime.Now,
                ApprovedDate = null,
                StaffId      = id, //To get this information from the session object
                Status       = "Pending",
                SupplierId   = supplierId,
            };

            for (int x = 0; x < productIds.Length; x++)
            {
                PurchaseOrderDetail pod = new PurchaseOrderDetail
                {
                    OrderId   = po.OrderId,
                    ProductId = productIds[x],
                    ReqQty    = Convert.ToInt32(requiredQty[x]),
                };
                purchaseOrderDetails.Add(pod);
            }
            using (db = new LogicEntities())
            {
                db.PurchaseOrder.Add(po);
                db.PurchaseOrderDetail.AddRange(purchaseOrderDetails);
                db.SaveChanges();
            }
            return(po.OrderId);
        }
Exemple #7
0
        public ActionResult AppointStaff(string staffname, DateTime getStartDate, DateTime getEndDate)
        {
            var    result        = db.DepartmentStaff.SingleOrDefault(b => b.StaffName == staffname);
            var    resultStaffId = result.StaffId;
            string resultDeptId  = result.DeptId;
            var    list          = db.Authorization.Where(x => x.DeptId == resultDeptId && x.EndDate >= getStartDate && x.StartDate <= getEndDate).ToList();

            if (list.Count > 0)
            {
                return(Json(new { isok = false, message = "Authorization Unsuccessful" }));
            }
            using (LogicEntities db = new LogicEntities())
            {
                var authorization = db.Set <logicProject.Models.EF.Authorization>();
                authorization.Add(new logicProject.Models.EF.Authorization {
                    DeptId = resultDeptId, StaffId = resultStaffId, StartDate = getStartDate, EndDate = getEndDate
                });
                db.SaveChanges();
            }
            List <string> email = new List <string>();

            email.Add(result.StaffEmail);
            string message = Utility.EmailBody.HeadBody + getStartDate.ToString("dddd, dd MMMM yyyy") + " and will expired on " + getEndDate.ToString("dddd, dd MMMM yyyy");

            Utility.EmailService.SendEmail(email, Utility.EmailBody.HeadSubject, message);
            return(Json(new { isok = true, message = "Authorization Successful", redirect = "/DeptHead/AuthorizeStaff" }));
        }
Exemple #8
0
        public ActionResult AppointStaffApi(string staffname, string getStartDate, string getEndDate)
        {
            var      result        = db.DepartmentStaff.SingleOrDefault(b => b.StaffName == staffname);
            var      resultStaffId = result.StaffId;
            string   resultDeptId  = result.DeptId;
            DateTime fromDate      = DateTime.ParseExact(getStartDate, "MM/dd/yyyy HH:mm:ss",
                                                         CultureInfo.InvariantCulture);
            DateTime toDate = DateTime.ParseExact(getEndDate, "MM/dd/yyyy HH:mm:ss",
                                                  CultureInfo.InvariantCulture);

            using (LogicEntities db = new LogicEntities())
            {
                var authorization = db.Set <logicProject.Models.EF.Authorization>();
                authorization.Add(new logicProject.Models.EF.Authorization {
                    DeptId = resultDeptId, StaffId = resultStaffId, StartDate = fromDate, EndDate = toDate
                });
                db.SaveChanges();
            }
            List <string> email = new List <string>();

            email.Add(result.StaffEmail);
            string message = Utility.EmailBody.HeadBody + getStartDate + " and will expired on " + getEndDate;

            Utility.EmailService.SendEmail(email, Utility.EmailBody.HeadSubject, message);
            return(Json(new { isok = true, message = "Authorization Successful" }));
        }
        public ActionResult addnew(AdjustmentDetail form_detail_obj)
        {
            if (string.IsNullOrEmpty(form_detail_obj.ProductId))
            {
                return(RedirectToAction("addcart"));
            }

            using (LogicEntities db = new LogicEntities())
            {
                List <AdjustmentDetail> temp = db.AdjustmentDetail.ToList();

                int form_details_num = (db.AdjustmentDetail.AsEnumerable().ToList().Count == 0) ? 1 : (db.AdjustmentDetail.AsEnumerable().Max(p => p.AdjustmentDetailId)) + 1;

                AdjustmentDetail old_rec_to_update = (from f in db.AdjustmentDetail
                                                      where f.ProductId == form_detail_obj.ProductId && f.AdjustmentId == form_detail_obj.AdjustmentId
                                                      select f).FirstOrDefault();
                if (old_rec_to_update != null)
                {
                    old_rec_to_update.Qty += form_detail_obj.Qty;
                }
                else
                {
                    //Debug.WriteLine("____________" + form_details_num + "##" + form_detail_obj.AdjustmentId);
                    db.AdjustmentDetail.Add(new AdjustmentDetail {
                        AdjustmentDetailId = form_details_num, AdjustmentId = form_detail_obj.AdjustmentId, ProductId = form_detail_obj.ProductId, Qty = Convert.ToInt32(form_detail_obj.Qty), UnitPrice = form_detail_obj.UnitPrice, TotalPrice = form_detail_obj.TotalPrice, reason = form_detail_obj.reason
                    });
                }

                db.SaveChanges();
            }

            return(RedirectToAction("addcart"));
        }
Exemple #10
0
        public void WithdrawManyItems(string[] itemCodes, string[] retrievedQtys)
        {
            List <StockTransaction> stockTransactions = new List <StockTransaction>();

            using (db = new LogicEntities())
            {
                for (int x = 0; x < itemCodes.Length; x++)
                {
                    Product p = db.Product.Find(itemCodes[x]);
                    if (-1 * Convert.ToInt32(retrievedQtys[x]) > p.Qty)
                    {
                        //Throw an error    //Not used due to modification made to view validation
                    }
                    else
                    {
                        StockTransaction stockTransaction = new StockTransaction
                        {
                            ProductId    = itemCodes[x],
                            Qty          = -1 * Convert.ToInt32(retrievedQtys[x]),
                            TranDate     = DateTime.Now,
                            Remarks      = "Inventory Withdrawal, Date: " + DateTime.Now.Date.ToString("d"),
                            TotalBalance = p.Qty - Convert.ToInt32(retrievedQtys[x])
                        };
                        stockTransactions.Add(stockTransaction);
                    }
                }
                db.StockTransaction.AddRange(stockTransactions);
                db.SaveChanges();
            }
        }
Exemple #11
0
        public void SaveDisbursement(int id, string status, string[] receivedQtys, string[] remarks, int storestaffId)
        {
            using (db = new LogicEntities())
            {
                var result = from d in db.Disbursement
                             where d.DisId == id
                             select d;
                Disbursement dis = result.First();
                dis.Status       = status;
                dis.StoreStaffId = storestaffId;

                var resultSet = from dd in db.DisbursementDetail
                                where dd.DisId == id
                                select dd;

                List <DisbursementDetail> disbursementDetails = resultSet.ToList();
                int x = 0;
                foreach (DisbursementDetail disd in disbursementDetails)
                {
                    disd.ReceivedQty = Convert.ToInt32(receivedQtys[x]);
                    disd.Remarks     = remarks[x];
                    x++;
                }
                dis.DisbursementDetails = disbursementDetails;
                db.Entry(dis).State     = EntityState.Modified;
                db.SaveChanges();
            }
        }
Exemple #12
0
        public ActionResult AppointRep(string staffname)
        {
            var result = db.DepartmentStaff.SingleOrDefault(x => x.StaffName == staffname);

            if (result != null)
            {
                var        resultId = result.StaffId;
                var        deptId   = result.DeptId;
                Department d        = db.Department.Where(x => x.DeptId == deptId).SingleOrDefault();
                d.RepId = result.StaffId;
                db.SaveChanges();
                List <string> email = new List <string>();
                email.Add(result.StaffEmail);
                Utility.EmailService.SendEmail(email, Utility.EmailBody.RepresentativeSubject, Utility.EmailBody.RepresentatvieBody);
                return(Json(new { isok = true, message = "Appointment Successful.", redirect = "/DeptHead/AppointRepresentative" }));
            }
            return(Json(new { isok = false, message = "Appointment Unsuccessful.", redirect = "/DeptHead/AppointRepresentative" }));
        }
Exemple #13
0
 public void CreateDisbursements(List <Disbursement> d, List <DisbursementDetail> dd)
 {
     using (db = new LogicEntities())
     {
         db.Disbursement.AddRange(d);
         db.DisbursementDetail.AddRange(dd);
         db.SaveChanges();
     }
 }
Exemple #14
0
        public ActionResult StoreLogin(string username, string password)
        {
            string session = (string)Session["StoreSession"];

            if (session != null)
            {
                //return RedirectToAction("Index", "Inventory");
            }
            if (username == null || password == null)
            {
                return(View());
            }
            StoreStaff user = db.StoreStaff.Where(x => x.Username == username && x.Password == password).SingleOrDefault();

            if (user == null)
            {
                return(View());
            }
            string sessionId = Guid.NewGuid().ToString();

            if (user != null)
            {
                user.SessionId = sessionId;
                db.SaveChanges();
            }
            Session["StoreSession"] = sessionId;
            Session["StoreStaff"]   = user;
            if (user.StaffType == "Clerk")
            {
                return(RedirectToAction("Index", "Inventory"));
            }
            else if (user.StaffType == "Supervisor")
            {
                return(RedirectToAction("Index", "Supervisor"));
            }
            else if (user.StaffType == "Manager")
            {
                return(RedirectToAction("Index", "Manager"));
            }
            else
            {
                return(View());
            }
        }
Exemple #15
0
 public void UpdateItemQty(string productId, int qty)
 {
     using (db = new LogicEntities())
     {
         Product p = db.Product.Find(productId);
         p.Qty             = p.Qty + qty;
         db.Entry(p).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
        //public ActionResult OutstandingDisbursementList()
        //{
        //    DateTime cutoff = DateTime.Now.Date;
        //    List<Department> departments = new List<Department>();
        //    departments = departmentDAO.GetDepartmentsWithOutstandingOrders(cutoff);

        //    ViewData["departments"] = departments;

        //    return View();
        //}

        public ActionResult GenerateDisbursementLists()
        {
            DateTime          cutoff      = DateTime.Now.Date; //Ensures that orders only up to yesterday 2359 is taken into consideration
            List <Department> departments = departmentDAO.GetDepartmentsWithOutstandingOrders(cutoff);
            List <DisbursementDetailViewModel> consolidatedOrders = new List <DisbursementDetailViewModel>();

            foreach (Department d in departments)
            {
                DepartmentStaff rep = departmentStaffDAO.getDeptRep(d.DeptId);
                using (db = new LogicEntities())
                {
                    var resultSet = from rd in db.RequestDetail
                                    from r in db.Request
                                    where (r.Status.Contains("New") || r.Status.Contains("Outstanding")) &&
                                    r.RequestId == rd.RequestId && r.DeptId == d.DeptId &&
                                    r.ReqDate < cutoff
                                    group rd by new { rd.ProductId, r.DeptId } into g
                        select new DisbursementDetailViewModel            //Note to self: Groupby only works with enums or primitive data types
                    {
                        ProductId    = g.Key.ProductId,
                        DepartmentId = g.Key.DeptId,
                        Quantity     = g.Sum(x => x.ReqQty)
                    };
                    consolidatedOrders = resultSet.ToList();

                    Disbursement dis = new Disbursement
                    {
                        DisDate           = DateTime.Now,
                        Status            = "Pending",
                        DeptId            = d.DeptId,
                        StoreStaffId      = null,
                        ReceiveStaffId    = rep.StaffId,
                        CollectionPointId = d.CollectionPt
                    };
                    List <DisbursementDetail> disbursementdetails = new List <DisbursementDetail>();
                    foreach (DisbursementDetailViewModel p in consolidatedOrders)
                    {
                        DisbursementDetail dd = new DisbursementDetail
                        {
                            ProductId   = p.ProductId,
                            RequiredQty = p.Quantity,
                            ReceivedQty = 0,
                            DisId       = dis.DisId
                        };
                        disbursementdetails.Add(dd);
                    }
                    db.Disbursement.Add(dis);
                    db.DisbursementDetail.AddRange(disbursementdetails);
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("FindDisbursementList"));
        }
        public ActionResult ViewLowStock()
        {
            List <Product> items;

            using (LogicEntities db = new LogicEntities())
            {
                items = db.Product.Where(item => item.Qty < item.ReorderLevel).ToList();
                db.SaveChanges();
            }
            ViewData["items"] = items;

            return(View());
        }
Exemple #18
0
        public ActionResult ViewVoucherList()
        {
            List <Adjustment> cart_list;

            using (LogicEntities db = new LogicEntities())
            {
                cart_list = db.Database.SqlQuery <Adjustment>("select distinct a.* from Adjustments a join AdjustmentDetails ad on a.AdjustmentId=ad.AdjustmentId where (select sum(x.TotalPrice) from AdjustmentDetails x where x.AdjustmentId=a.AdjustmentId group by x.AdjustmentId) > 250").ToList();

                db.SaveChanges();
            }
            ViewData["cart_list"] = cart_list;

            return(View());
        }
        public ActionResult GetLocationAsync(int locationId)
        {
            DepartmentStaff ds     = Session["DeptStaff"] as DepartmentStaff;
            string          DeptId = ds.DeptId;
            Department      d      = db.Department.Where(x => x.DeptId == DeptId).SingleOrDefault();

            d.CollectionPt = locationId;
            db.SaveChanges();
            List <String> list    = db.StoreStaff.Select(x => x.StaffEmail).ToList();
            string        message = Utility.EmailBody.CollectionSubject + "\n" + "By " + d.DeptName;

            Utility.EmailService.SendEmail(list, Utility.EmailBody.CollectionSubject, message);
            //await e.SendEmailAsync("*****@*****.**", "hello", "das");

            return(Json(new { isok = true, message = "Collection Point is set.", redirect = "/Departments/Dashboard", locationId = locationId }));
        }
Exemple #20
0
 public ActionResult CreateSupplier([Bind(Include = "SupplierId,SupplierName,GSTRegNo,ContactName,FaxNo,PhNo,Address")] Supplier supplier)
 {
     if (ModelState.IsValid)
     {
         db.Supplier.Add(supplier);
         db.SaveChanges();
         return(RedirectToAction("SupplierList"));
     }
     return(View(supplier));
 }
        public void SetPOStatus(string status, string remarks, int id)
        {
            using (db = new LogicEntities())
            {
                var result = from po in db.PurchaseOrder
                             where po.OrderId == id
                             select po;

                PurchaseOrder p = result.First();
                p.Status          = status;
                p.ApprovedDate    = DateTime.Now;
                p.Remarks         = remarks; //Additional remarks column for po needed, must be able to be null
                db.Entry(p).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
Exemple #22
0
        //public ActionResult EditDepartmentDetails(string id)
        //{
        //    if (id == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    Department department = db.Department.Find(id);
        //    if (department == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    ViewBag.CollectionPt = new SelectList(db.CollectionPoint, "CollectionPtId", "CollectionPt", department.CollectionPt);

        //    return View(department);
        //}

        //[HttpPost]
        //[ValidateAntiForgeryToken]
        //public ActionResult EditDepartmentDetails([Bind(Include = "DeptId,DeptName,ContactName,PhNo,FaxNo,EmailAddr,HeadId,CollectionPt,RepId")] Department department)
        //{
        //    if (ModelState.IsValid)
        //    {
        //        db.Entry(department).State = EntityState.Modified;
        //        db.SaveChanges();
        //        return RedirectToAction("DepartmentDetails");
        //    }
        //    ViewBag.CollectionPt = new SelectList(db.CollectionPoint, "CollectionPtId", "CollectionPt", department.CollectionPt);
        //    return View(department);
        //}
        //Code from Antonio ends here
        //Code by Uday begins below
        public ActionResult ApproveForm(int id)
        {
            List <AdjustmentDetail> cart_list;

            using (LogicEntities db = new LogicEntities())
            {
                cart_list = db.AdjustmentDetail.Where(item => item.AdjustmentId == id).ToList();
                Adjustment req = db.Adjustment.Where(x => x.AdjustmentId == id).SingleOrDefault();

                ViewData["cart_list"]  = cart_list;
                ViewData["adjustment"] = req;
                db.SaveChanges();
            }



            return(View());
        }
        public ActionResult AppointStaff(string staffname)
        {
            //Debug.WriteLine("name=" +staffname);
            var result = db.DepartmentStaff.SingleOrDefault(x => x.StaffName == staffname);

            if (result != null)
            {
                var resultId = result.StaffId;
                var deptId   = result.DeptId;
                //Debug.WriteLine("Result/StaffId" + resultId);
                //Debug.WriteLine("DeptID" + deptId);

                Department d = db.Department.Where(x => x.DeptId == deptId).SingleOrDefault();
                d.RepId = result.StaffId;
                db.SaveChanges();
            }
            return(Json(new { isok = true, message = "Appointment Successful" }));
        }
        public ActionResult AppointStaff(string staffname, DateTime getStartDate, DateTime getEndDate)
        {
            var result        = db.DepartmentStaff.SingleOrDefault(b => b.StaffName == staffname);
            var resultStaffId = result.StaffId;
            var resultDeptId  = int.Parse(result.DeptId);

            //Debug.WriteLine("staff id is:" + resultId);

            using (LogicEntities db = new LogicEntities())
            {
                //DateTime now = DateTime.Now;
                var authorization = db.Set <Authorization>();
                authorization.Add(new Authorization {
                    AuthNo = 1, DeptId = resultDeptId, StaffId = resultStaffId, StartDate = getStartDate, EndDate = getEndDate
                });
                db.SaveChanges();
            }
            return(Json(new { isok = true, message = "Authorization Successful" }));
        }
        public ActionResult submitrequest()
        {
            int emp_id      = int.Parse(Request.Form["emp_id"]);
            int form_number = int.Parse(Request.Form["form_number"]);

            using (LogicEntities db = new LogicEntities())
            {
                Adjustment old_rec_to_update = (from f in db.Adjustment
                                                where f.StaffId == emp_id && f.AdjustmentId == form_number && f.Status == "temp"
                                                select f).FirstOrDefault();
                if (old_rec_to_update != null)
                {
                    old_rec_to_update.Status = "Pending";
                }
                db.SaveChanges();
            }
            //Send email to either manager/supervisor
            return(View("index"));
        }
Exemple #26
0
 public void UpdateItemQty(string[] productIds, string[] qtys, bool isAdd)
 {
     using (db = new LogicEntities())
     {
         for (int x = 0; x < productIds.Length; x++)
         {
             Product p = db.Product.Find(productIds[x]);
             if (isAdd)
             {
                 p.Qty = p.Qty + Convert.ToInt32(qtys[x]);
             }
             else
             {
                 p.Qty = p.Qty - Convert.ToInt32(qtys[x]);
             }
             db.Entry(p).State = EntityState.Modified;
         }
         db.SaveChanges();
     }
 }
Exemple #27
0
        public void UpdateQuantityOneItem(string itemCode, string purpose, int qty, DateTime date, string transactionDetails)
        {
            if (purpose == "Withdrawal")
            {
                qty = -qty;
            }
            using (db = new LogicEntities())
            {
                Product p = db.Product.Find(itemCode);

                StockTransaction st = new StockTransaction
                {
                    ProductId    = itemCode,
                    TranDate     = date,
                    Qty          = qty,
                    TotalBalance = p.Qty + qty,
                    Remarks      = purpose + " " + transactionDetails //Need an additional remarks field
                };
                db.StockTransaction.Add(st);
                db.SaveChanges();
            }
        }
Exemple #28
0
        public void AddManyItems(string[] itemCodes, string[] receivedQtys, DateTime date, string supplierId, string comments)
        {
            List <StockTransaction> stockTransactions = new List <StockTransaction>();

            using (db = new LogicEntities())
            {
                for (int x = 0; x < itemCodes.Length; x++)
                {
                    Product          p = db.Product.Find(itemCodes[x]);
                    StockTransaction stockTransaction = new StockTransaction
                    {
                        ProductId    = itemCodes[x],
                        Qty          = Convert.ToInt32(receivedQtys[x]),
                        TranDate     = date,
                        Remarks      = "Inventory Received, Date: " + date.Date.ToString("d") + " " + supplierId + " " + comments,
                        TotalBalance = p.Qty + Convert.ToInt32(receivedQtys[x])
                    };
                    stockTransactions.Add(stockTransaction);
                }
                db.StockTransaction.AddRange(stockTransactions);
                db.SaveChanges();
            }
        }
Exemple #29
0
        public ActionResult ApproveForm(string approve, string reject, string remarks, int id)
        {
            using (LogicEntities db = new LogicEntities())
            {
                Adjustment    rd     = db.Adjustment.Find(id);
                StoreStaff    staff  = db.StoreStaff.Find(rd.StaffId);
                List <string> emails = new List <string>();
                emails.Add(staff.StaffEmail);
                string subj = "Status - Adjustment Form: " + rd.AdjustmentId;

                if (approve == "Approve")
                {
                    rd.Status = approve;
                    rd.Remark = remarks;

                    db.SaveChanges();

                    List <AdjustmentDetail> adjustmentDetails = db.AdjustmentDetail.Where(x => x.AdjustmentId == id).ToList();
                    foreach (var detail in adjustmentDetails)
                    {
                        var res = db.Product.SingleOrDefault(p => p.ProductId == detail.ProductId);
                        //var res2 = db.StockTransaction.SingleOrDefault(p => p.ProductId == detail.ProductId);

                        if (res != null)
                        {
                            res.Qty += detail.Qty;
                            db.SaveChanges();
                        }

                        StockTransaction st = new StockTransaction
                        {
                            TranDate     = DateTime.Now,
                            ProductId    = detail.ProductId,
                            Qty          = detail.Qty,
                            Remarks      = "Inventory Adjustment: " + detail.reason,
                            TotalBalance = res.Qty
                        };

                        db.StockTransaction.Add(st);
                        db.SaveChanges();

                        //if (res2 != null)
                        //{
                        //    res2.Qty += detail.Qty;
                        //    db.SaveChanges();
                        //}
                    }
                    //Send email to notify that adjustment voucher has been approved
                    string msg = "Dear " + staff.StaffName + ",\n Your Adjustment voucher has been approved.";
                    EmailService.SendEmail(emails, subj, msg);
                }
                else if (reject == "Reject")
                {
                    rd.Status = reject;
                    rd.Remark = remarks;
                    db.SaveChanges();
                    //Send email to notify that adjustment has been rejected
                    string msg = "Dear " + staff.StaffName + ",\n Your Adjustment voucher has been rejected.";
                    EmailService.SendEmail(emails, subj, msg);
                }
            }
            return(RedirectToAction("ViewVoucherList"));
        }
        public ActionResult create_form()
        {
            StoreStaff user = new StoreStaff();

            user = (StoreStaff)Session["StoreStaff"];
            using (LogicEntities db = new LogicEntities())
            {
                db.Adjustment.RemoveRange(db.Adjustment.Where(x => x.Status == "temp").ToList());
                db.SaveChanges();
            }
            int form_number = 1;

            using (LogicEntities db = new LogicEntities())
            {
                if (db.Adjustment.AsEnumerable().ToList().Count != 0)
                {
                    form_number = db.Adjustment.AsEnumerable().Max(p => p.AdjustmentId);
                    //Debug.WriteLine("***************** before" + form_number);
                    form_number = form_number + 1;
                    //Debug.WriteLine("***************** after" + form_number);
                }
                else
                {
                    form_number = 1;
                }
            }



            //Debug.WriteLine("*****************" + form_number);
            using (LogicEntities db = new LogicEntities())
            {
                db.Adjustment.Add(new Adjustment {
                    AdjustmentId = form_number, Remark = "--", AdjustedDate = DateTime.Now.Date, StaffId = user.StaffId, Status = "temp"
                });
                db.SaveChanges();
            }

            List <ProductViewModel> items;

            int num_new;

            using (LogicEntities db = new LogicEntities())
            {
                //items = db.Product.Select(p => new Product
                //{
                //    ProductId = p.ProductId,
                //    Category = p.Category,
                //    Description = p.Description,
                //    Qty = p.Qty
                //}).ToList();

                //items = db.Product.ToList();
                items   = getProducts(db);
                num_new = db.Adjustment.AsEnumerable().Max(p => p.AdjustmentId);
            }

            ViewData["form_number"] = num_new;
            ViewData["items"]       = items;
            ViewData["msg"]         = num_new.ToString();

            return(View());
        }