Ejemplo n.º 1
0
        public ActionResult Details(
            [Bind(Include =
                      "RequisitionId,RequisitionEmpNum,RequisitionDate,RequestRemarks,ApprovalRemarks,Status,DeptCode")]
            Requisition requisition, string statuses)
        {
            if (requisition.Status == RequisitionStatus.Pending)
            {
                //requisition must be pending for any approval and reject
                var deptCode = Request.Cookies["Employee"]?["DeptCode"];
                var empNum   = Convert.ToInt32(Request.Cookies["Employee"]?["EmpNum"]);

                if (User.IsInRole(Role.DepartmentHead) && !HasDelegate || IsDelegate)
                {
                    //if (user is head and there is no delegate) or (user is currently delegate)
                    if (deptCode != _departmentRepo.GetDepartmentByEmpNum(requisition.RequisitionEmpNum).DeptCode)
                    {
                        //if user is trying to approve for other department
                        return(View("_unauthoriseAccess"));
                    }

                    if (empNum == requisition.RequisitionEmpNum)
                    {
                        //if user is trying to self approve (delegate's old requistion)
                        return(View("_unauthoriseAccess"));
                    }

                    if (ModelState.IsValid)
                    {
                        requisition.ApprovalEmpNum = empNum;
                        requisition.ApprovalDate   = DateTime.Today;
                        requisition.Status         = statuses;
                        _requisitionRepo.Update(requisition);
                        if (requisition.Status == "approved")
                        {
                            Requisition req = _requisitionRepo.GetById(requisition.RequisitionId);
                            foreach (var requisitionDetail in req.RequisitionDetails)
                            {
                                var stationery = _stationeryRepo.GetById(requisitionDetail.ItemNum);
                                stationery.AvailableQty = stationery.AvailableQty - requisitionDetail.Quantity;
                                _stationeryRepo.Update(stationery);
                            }
                        }

                        return(RedirectToAction("Pending"));
                    }

                    return(View(requisition));
                }

                return(View("_hasDelegate"));
            }

            return(new HttpUnauthorizedResult());
        }
Ejemplo n.º 2
0
        public IHttpActionResult Acknowledge(int id, int empnum)
        {
            var disbursement = _disbursementRepo.GetById(id);
            var employee     = _employeeRepo.GetById(empnum);

            if (employee.DeptCode != disbursement.DeptCode)
            {
                return(BadRequest("Wrong department."));
            }

            if (disbursement.Status != DisbursementStatus.InProcess)
            {
                return(BadRequest("This disbursement has already been acknowledged"));
            }

            _disbursementRepo.Acknowledge(disbursement);
            //update current quantity of stationery
            foreach (var disbursementDetail in disbursement.DisbursementDetails)
            {
                var stationery = _stationeryRepo.GetById(disbursementDetail.ItemNum);
                stationery.CurrentQty -= disbursementDetail.ActualQty;
                _stationeryRepo.Update(stationery);
            }

            return(Ok(new { Message = "Disbursement acknowledged" }));
        }
Ejemplo n.º 3
0
        public ActionResult Acknowledge(DisbursementDetailDTO disbursementDto, string update)
        {
            if (disbursementDto == null)
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                var disbursement = _disbursementRepo.GetById(disbursementDto.CurrentDisbursement.DisbursementId);

                //set the actual qty of its detail list items to the updated qty, and update it in database
                foreach (var disbursementDetail in disbursement.DisbursementDetails)
                {
                    disbursementDetail.ActualQty = disbursementDto.DisDetailList
                                                   .First(ddEdited => ddEdited.ItemNum == disbursementDetail.ItemNum)
                                                   .ActualQty;
                }

                _disbursementRepo.Update(disbursement);

                switch (update)
                {
                //case 1: confirm items disbursed and update stationery qty
                case "Acknowledge Manually":
                    _disbursementRepo.Acknowledge(disbursement);
                    foreach (var dd in disbursement.DisbursementDetails)
                    {
                        var stationery = _stationeryRepo.GetById(dd.Stationery.ItemNum);
                        stationery.CurrentQty -= dd.ActualQty;
                        _stationeryRepo.Update(stationery);
                    }

                    return(RedirectToAction("Upcoming"));

                //case 2: only updates actual qty and leave changing status and deduct stock qty to WebAPI
                case "Generate QR Code":
                    break;
                }

                return(Json("Ok"));
            }

            return(View("Details", disbursementDto));
        }
        public ActionResult Edit(StationeryDTO stationeryDto) //Edit in MVC architecture
        {
            if (ModelState.IsValid)
            {
                var theList = new List <string>
                {
                    stationeryDto.SupplierName1,
                    stationeryDto.SupplierName2,
                    stationeryDto.SupplierName3
                };
                var isUnique = theList.Distinct().Count() == theList.Count();
                if (isUnique == false)
                {
                    //Check Supplier is different
                    ViewBag.DistinctError      = "Please select different suppliers";
                    stationeryDto.CategoryList = _categoryRepo.GetCategories();
                    stationeryDto.SupplierList = _supplierRepo.GetSupplierList();
                    return(View(stationeryDto));
                }

                var stationery = _stationeryRepo.GetById(stationeryDto.ItemNum);
                stationery.CategoryId    = stationeryDto.CategoryId;
                stationery.Description   = stationeryDto.Description;
                stationery.ReorderLevel  = stationeryDto.ReorderLevel;
                stationery.ReorderQty    = stationeryDto.ReorderQty;
                stationery.UnitOfMeasure = stationeryDto.UnitOfMeasure;
                stationery.BinNum        = stationeryDto.BinNum;
                _stationeryRepo.Update(stationery);
                _stationerySupplierRepo.DeleteStationerySupplier(stationeryDto.ItemNum);

                var sp1 = new StationerySupplier
                {
                    ItemNum    = stationeryDto.ItemNum,
                    SupplierId = Int32.Parse(stationeryDto.SupplierName1),
                    Price      = stationeryDto.Price1,
                    Rank       = 1
                };
                _stationerySupplierRepo.Add(sp1);

                var sp2 = new StationerySupplier
                {
                    ItemNum    = stationeryDto.ItemNum,
                    SupplierId = int.Parse(stationeryDto.SupplierName2),
                    Price      = stationeryDto.Price2,
                    Rank       = 2
                };
                _stationerySupplierRepo.Add(sp2);

                var sp3 = new StationerySupplier
                {
                    ItemNum    = stationeryDto.ItemNum,
                    SupplierId = Int32.Parse(stationeryDto.SupplierName3),
                    Price      = stationeryDto.Price3,
                    Rank       = 3
                };
                _stationerySupplierRepo.Add(sp3);

                return(RedirectToAction("Index"));
            }

            stationeryDto.CategoryList = _categoryRepo.GetCategories();
            stationeryDto.SupplierList = _supplierRepo.GetSupplierList();
            return(View(stationeryDto));
        }
Ejemplo n.º 5
0
        public ActionResult CreateAdjustments(AdjVoucherColView adjVoucherColView)
        {
            var empNum = Convert.ToInt32(Request.Cookies["Employee"]?["EmpNum"]);
            var self   = _employeeRepo.GetById(empNum);

            if (ModelState.IsValid)
            {
                if (adjVoucherColView.MyList != null)
                {
                    var vouchers = new List <AdjVoucher>();
                    foreach (var adjVoucherDto in adjVoucherColView.MyList)
                    {
                        if (adjVoucherDto.Sign == false)
                        {
                            adjVoucherDto.Quantity = adjVoucherDto.Quantity * -1;
                        }

                        var stationery = _stationeryRepo.GetById(adjVoucherDto.ItemNum);
                        stationery.AvailableQty = stationery.AvailableQty + adjVoucherDto.Quantity;
                        stationery.CurrentQty   = stationery.CurrentQty + adjVoucherDto.Quantity;
                        _stationeryRepo.Update(stationery);

                        var adjustment = new AdjVoucher
                        {
                            ItemNum       = adjVoucherDto.ItemNum,
                            Quantity      = adjVoucherDto.Quantity,
                            Reason        = adjVoucherDto.Reason,
                            Status        = Pending,
                            RequestEmpNum = empNum,
                            CreateDate    = DateTime.Today
                        };

                        adjustment.Stationery = _stockAdjustmentRepo.AddStockAdjustment(adjustment);
                        vouchers.Add(adjustment);
                    }

                    //Although there is a threshold of $250, both supervisor and manager will be informed of all adjustments regardless of price
                    //If desired, the threshold can be applied by getting price * quantity and setting if (total price > 250)
                    foreach (AdjVoucher av in vouchers)
                    {
                        av.Stationery = _stationeryRepo.GetById(av.ItemNum);
                    }

                    var managerEmail    = _employeeRepo.GetStoreManager().EmailAddress;
                    var supervisorEmail = _employeeRepo.GetStoreSupervisor().EmailAddress;
                    var email1          = new LUSSISEmail.Builder().From(self.EmailAddress)
                                          .To(managerEmail).ForNewStockAdjustments(self.FullName, vouchers).Build();
                    var email2 = new LUSSISEmail.Builder().From(self.EmailAddress)
                                 .To(supervisorEmail).ForNewStockAdjustments(self.FullName, vouchers).Build();

                    new System.Threading.Thread(delegate() { EmailHelper.SendEmail(email1); }).Start();
                    new System.Threading.Thread(delegate() { EmailHelper.SendEmail(email2); }).Start();

                    return(RedirectToAction("History"));
                }

                return(View(adjVoucherColView));
            }

            return(View(adjVoucherColView));
        }
        public ActionResult Create(PurchaseOrderDTO purchaseOrderDto)
        {
            try
            {
                //validate PO
                if (purchaseOrderDto.SupplierContact == null)
                {
                    throw new Exception("Please input the supplier contact");
                }

                else if (!ModelState.IsValid)
                {
                    throw new Exception("IT Error: please contact your administrator");
                }

                //fill any missing data with default values
                var empNum   = Convert.ToInt32(Request.Cookies["Employee"]?["EmpNum"]);
                var fullName = Request.Cookies["Employee"]?["Name"];
                purchaseOrderDto.OrderEmpNum = empNum;
                if (purchaseOrderDto.CreateDate == new DateTime())
                {
                    purchaseOrderDto.CreateDate = DateTime.Today;
                }

                //create PO
                purchaseOrderDto.CreatePurchaseOrder(out var purchaseOrder);

                //save to database po and the updated available qty
                _poRepo.Add(purchaseOrder);
                foreach (PurchaseOrderDetail pdetail in purchaseOrder.PurchaseOrderDetails)
                {
                    Stationery stationery = _stationeryRepo.GetById(pdetail.ItemNum);
                    stationery.AvailableQty += pdetail.OrderQty;
                    _stationeryRepo.Update(stationery);
                }

                //send email to supervisor
                var supervisorEmail = new EmployeeRepository().GetStoreSupervisor().EmailAddress;
                var email           = new LUSSISEmail.Builder().From(User.Identity.Name)
                                      .To(supervisorEmail).ForNewPo(purchaseOrder, fullName).Build();
                //start new thread to send email
                new Thread(delegate() { EmailHelper.SendEmail(email); }).Start();


                //send email if using non=primary supplier
                var stationerys = purchaseOrder.PurchaseOrderDetails
                                  .Select(orderDetail => _stationeryRepo.GetById(orderDetail.ItemNum))
                                  .Where(stationery => stationery.PrimarySupplier().SupplierId != purchaseOrder.SupplierId).ToList();
                if (stationerys.Count > 0)
                {
                    var supplierName = _supplierRepo.GetById(purchaseOrder.SupplierId).SupplierName;
                    var email2       = new LUSSISEmail.Builder().From(User.Identity.Name).To(supervisorEmail)
                                       .ForNonPrimaryNewPo(supplierName, purchaseOrder, stationerys).Build();
                    new Thread(delegate() { EmailHelper.SendEmail(email2); }).Start();
                }


                return(RedirectToAction("Summary"));
            }
            catch (Exception e)
            {
                return(RedirectToAction("Create",
                                        new { supplierId = purchaseOrderDto.SupplierId.ToString(), error = e.Message }));
            }
        }