コード例 #1
0
        // GET: Stationeries/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //get stationery data
            var stationery = _stationeryRepo.GetById(id);

            if (stationery == null)
            {
                return(HttpNotFound());
            }

            //put stationery and the 3 suppliers into the view
            ViewBag.Stationery = stationery;
            ViewBag.Supplier1  = stationery.PrimarySupplier().SupplierName;
            ViewBag.Supplier2  = stationery.StationerySuppliers.First(x => x.Rank == 2).Supplier.SupplierName;
            ViewBag.Supplier3  = stationery.StationerySuppliers.First(x => x.Rank == 3).Supplier.SupplierName;

            //get full list of receive+disburse+adjust transactions for the stationery and put into view
            var receiveList = _poRepo.GetReceiveTransDetailByItem(id).Select(
                x => new StationeryTransactionDTO
            {
                Date      = x.ReceiveTran.ReceiveDate,
                Qty       = x.Quantity,
                Transtype = "received",
                Remarks   = x.ReceiveTran.PurchaseOrder.Supplier.SupplierName
            }).ToList();
            var disburseList = _disbursementRepo.GetAllDisbursementDetailByItem(id).Select(
                x => new StationeryTransactionDTO
            {
                Date      = x.Disbursement.CollectionDate,
                Qty       = -x.ActualQty,
                Transtype = "disburse",
                Remarks   = x.Disbursement.DeptCode
            }).ToList();
            var adjustList = _adjustmentRepo.GetApprovedAdjVoucherByItem(id).Select(
                x => new StationeryTransactionDTO
            {
                Date      = x.CreateDate,
                Qty       = x.Quantity,
                Transtype = "adjust",
                Remarks   = x.Reason
            }).ToList();

            receiveList.AddRange(disburseList);
            receiveList.AddRange(adjustList);
            var p = receiveList.Sum(x => x.Qty);

            ViewBag.InitBal          = stationery.CurrentQty - p;
            ViewBag.StationeryTxList = receiveList.OrderBy(x => x.Date);

            return(View());
        }
コード例 #2
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());
        }
コード例 #3
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" }));
        }
コード例 #4
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            StationeryRepository sr = new StationeryRepository();
            var ItemCurrentQuantity = sr.GetById(ItemNum).CurrentQty;
            var isPositive          = true;

            if (Sign != null)
            {
                isPositive = Convert.ToBoolean(Sign);
            }
            if (!isPositive && Quantity > ItemCurrentQuantity)
            {
                yield return(new ValidationResult("Number exceed current quantity", new List <string> {
                    "Quantity"
                }));
            }
        }
コード例 #5
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));
        }
コード例 #6
0
        public IHttpActionResult CreateRequisition([FromBody] RequisitionDTO requisitionDto)
        {
            var empNum   = requisitionDto.RequisitionEmpNum;
            var employee = _employeeRepo.GetById(empNum);

            var isDelegated = _delegateRepo.FindCurrentByEmpNum(empNum) != null;

            if (isDelegated)
            {
                return(BadRequest("Delegated staff cannot make request"));
            }

            var detail = requisitionDto.RequisitionDetails.First();

            var requisitionDetail = new RequisitionDetail()
            {
                ItemNum  = detail.ItemNum,
                Quantity = detail.Quantity,
            };

            var requisition = new Requisition()
            {
                RequisitionEmpNum  = requisitionDto.RequisitionEmpNum,
                DeptCode           = employee.DeptCode,
                RequestRemarks     = requisitionDto.RequestRemarks,
                RequisitionDate    = DateTime.Today,
                Status             = RequisitionStatus.Pending,
                RequisitionDetails = new List <RequisitionDetail>()
                {
                    requisitionDetail
                }
            };

            _requistionRepo.Add(requisition);

            requisition.RequisitionDetails.First().Stationery = _stationeryRepo.GetById(detail.ItemNum);
            //Send email on new thread
            var headEmail = _employeeRepo.GetDepartmentHead(employee.DeptCode).EmailAddress;
            var email     = new LUSSISEmail.Builder().From(employee.EmailAddress).To(headEmail)
                            .ForNewRequistion(employee.FullName, requisition).Build();

            new Thread(delegate() { EmailHelper.SendEmail(email); }).Start();

            return(Ok(new { Message = "Requisition created" }));
        }
コード例 #7
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));
        }
コード例 #8
0
        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 }));
            }
        }