Beispiel #1
0
        public static Stationery getStationery(String itemCode)
        {
            SSAEntities ssae       = new SSAEntities();
            Stationery  stationery = ssae.Stationeries.Where(x => x.ItemCode.Contains(itemCode)).FirstOrDefault();

            return(stationery);
        }
        public async Task <IActionResult> Edit(int id, [Bind("StationeryID,StationeryName,Price,Extension,SubCategoryID")] Stationery stationery)
        {
            if (id != stationery.StationeryID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(stationery);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StationeryExists(stationery.StationeryID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SubCategoryID"] = new SelectList(_context.SubCategories, "SubCategoryID", "SubCategoryName", stationery.SubCategoryID);
            return(View(stationery));
        }
        public Message actionCreateRequisition(Requisition objIn)
        {
            objIn.datetime_requested = DateTime.Now;
            objIn.status             = 0;

            try
            {
                data.Requisitions.AddObject(objIn);

                Stationery stationery = data.Stationeries.Where(o => o.id == objIn.stationery).SingleOrDefault();
                User       employee   = data.Users.Where(o => o.id == objIn.user_obj).SingleOrDefault();
                Department dept       = data.Departments.Where(o => o.id == objIn.department).SingleOrDefault();
                User       head       = data.Users.Where(o => o.id == dept.department_head).SingleOrDefault();

                String email_title = "Stationery Requesting from " + employee.firstname + " " + employee.lastname;
                String email_body  = "<p>Hello " + head.firstname + " " + head.lastname + ",</p>" +
                                     "<p>The following item is requested from " + employee.firstname + " " + employee.lastname + ".</p>" +
                                     "<p><b>Stationery Name : " + stationery.stationery_name + "<br />" +
                                     "Quantity : " + objIn.quantity + " " + stationery.unit_of_measure + "</b></p>" +
                                     "<p>Please click the following link to login to your account and approve.<br /> " +
                                     Configs.APP_URL_ROOT +
                                     "<br />Thank you,<br/> Logic University.<p>This is system generated mail. Please do not reply.</p>";
                Helper.sendMail(head.email, "*****@*****.**", email_title, email_body);

                return(this.getNewDefaultMessageForDBOperations(data.SaveChanges() == 1));
            }
            catch (Exception e)
            {
                return(this.getNewDefaultMessageForException(e));
            }
        }
        public Message actionRequisitionStatusChangeToRejected(int requisition_id)
        {
            try
            {
                Requisition requisition = data.Requisitions.Where(o => (o.id == requisition_id)).Single();
                requisition.status = 2;
                data.Requisitions.ApplyCurrentValues(requisition);

                Stationery stationery  = data.Stationeries.Where(o => o.id == requisition.stationery).SingleOrDefault();
                User       employee    = data.Users.Where(o => o.id == requisition.user_obj).SingleOrDefault();
                Department dept        = data.Departments.Where(o => o.id == requisition.department).SingleOrDefault();
                User       approve_usr = data.Users.Where(o => o.id == requisition.user_approved_by).SingleOrDefault();

                String email_title = "Your requested stationery is rejected.";
                String email_body  = "<p>Hello " + approve_usr.firstname + " " + approve_usr.lastname + ",</p>" +
                                     "<p>The following item your requested is rejected by " + approve_usr.firstname + " " + approve_usr.lastname + ".</p>" +
                                     "<p><b>Stationery Name : " + stationery.stationery_name + "<br />" +
                                     "Quantity : " + requisition.quantity + " " + stationery.unit_of_measure + "</b></p>" +
                                     "<p>The reason is - ." + requisition.reject_remark + "</p>" +
                                     "<br />Thank you,<br/> Logic University.<p>This is system generated mail. Please do not reply.</p>";
                Helper.sendMail(employee.email, "*****@*****.**", email_title, email_body);

                return(this.getNewDefaultMessageForDBOperations(data.SaveChanges() == 1));
            }
            catch (Exception e)
            {
                return(this.getNewDefaultMessageForException(e));
            }
        }
Beispiel #5
0
        public void NotifyClerkShortFallInStationery(Stationery s, Employee clerk)
        {
            string body    = "Dear " + clerk.Name + ",\n\nThere is insufficient incoming stock for Stationery: " + s.Description + " of Item Code: " + s.Code + ".\nPlease raise a necessary Purchase Order for the recent demand. \n\nThank you and have a great day.";
            string subject = "Shortfall in Stationery. Please raise a Purchase Order.";

            SendNotificationEmail(clerk.Email, subject, body);
        }
Beispiel #6
0
        public async Task <ActionResult <IList <StockAdjustmentDetail> > > updateInventory([FromBody] List <Stationery> stationeries)
        {
            IList <StockAdjustmentDetail> result = new List <StockAdjustmentDetail>();

            //IList<Stationery> oldStationery = await _clkService.findAllStationeriesAsync();

            foreach (Stationery s in stationeries)
            {
                //find coresponding stationery and check
                Stationery olds = await _clkService.findStationeryByIdAsync(s.Id);

                if (olds.inventoryQty != s.reOrderQty)
                {
                    int disc = s.reOrderQty - olds.inventoryQty;
                    olds.inventoryQty = s.reOrderQty;
                    _clkService.updateStationery(olds);


                    StockAdjustmentDetail sad = new StockAdjustmentDetail()
                    {
                        StationeryId = olds.Id,
                        Status       = olds.desc,
                        discpQty     = disc
                    };
                    result.Add(sad);
                }
            }
            if (result != null)
            {
                return(Ok(result));
            }

            return(null);
        }
 public ActionResult Update(StationeryDetailsDTO stationery)
 {
     if (Session["existinguser"] != null)
     {
         LoginDTO currentUser = (LoginDTO)Session["existinguser"];
         if (currentUser.RoleId != (int)Enums.Roles.StoreManager)
         {
             return(RedirectToAction("RedirectToClerkOrDepartmentView", "Login"));
         }
         if (ModelState.IsValid)
         {
             if (stationery.Supplier1 == stationery.Supplier2 || stationery.Supplier1 == stationery.Supplier3 || stationery.Supplier2 == stationery.Supplier3)
             {
                 stationery.Error          = new ErrorDTO();
                 stationery.Error.HasError = true;
                 stationery.Error.Message  = "Suppliers must be three different suppliers!";
                 stationery.Categories     = StationeryService.Instance.GetAllCategories();
                 stationery.Suppliers      = StationeryService.Instance.GetAllSuppliers();
                 return(View(stationery));
             }
             Stationery newStationery = this.generateStationery(stationery);
             StationeryService.Instance.UpdateStationery(newStationery);
             this.generateSupplierTender(stationery.Supplier1, 1, newStationery.Id, stationery.Price1);
             this.generateSupplierTender(stationery.Supplier2, 2, newStationery.Id, stationery.Price2);
             this.generateSupplierTender(stationery.Supplier3, 3, newStationery.Id, stationery.Price3);
             return(RedirectToAction("Index"));
         }
         stationery.Categories = StationeryService.Instance.GetAllCategories();
         stationery.Suppliers  = StationeryService.Instance.GetAllSuppliers();
         return(View(stationery));
     }
     return(RedirectToAction("Index", "Login"));
 }
        protected void gvStationeryCatalogue_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "AddToRequest")
            {
                requisitionDetails = Session["RequestsDetails"] as List <RequisitionDetail>;
                bool       duplicate = false;
                Stationery s         = iss.FindStationeryById(e.CommandArgument.ToString());

                foreach (RequisitionDetail rd in requisitionDetails)
                {
                    if (rd.ItemCode == s.ItemCode)
                    {
                        duplicate = true;
                        break;
                    }
                }

                if (!duplicate)
                {
                    RequisitionDetail rd = new RequisitionDetail()
                    {
                        ItemCode        = s.ItemCode,
                        QuantityRequest = 1
                    };
                    requisitionDetails.Add(rd);
                    Session["RequestsDetails"] = requisitionDetails;
                    lblItem.Text = s.Description + " is added to your Requisition Form";
                }
                else
                {
                    lblItem.Text = s.Description + " has already been added to your Requisition Form.";
                }
            }
        }
        public IHttpActionResult GetUnitFromItem(string itemId)
        {
            Stationery stationery = _context.Stationery.Single(m => m.ItemId == itemId);
            string     unit       = stationery.UnitOfMeasure;

            return(Ok(unit));
        }
        public Message actionUpdateStationery(Stationery objIn)
        {
            try
            {
                //objIn.EntityKey = data.Stationeries.Where(o => o.id == objIn.id).Single().EntityKey;
                Stationery stationery = data.Stationeries.Where(o => o.id == objIn.id).Single();
                stationery.id = objIn.id;
                stationery.stationery_name   = objIn.stationery_name;
                stationery.code              = objIn.code;
                stationery.price             = objIn.price;
                stationery.reorder_level     = objIn.reorder_level;
                stationery.reorder_quantity  = objIn.reorder_quantity;
                stationery.quantity_in_stock = objIn.quantity_in_stock;
                stationery.pending_quantity_to_distribute = objIn.pending_quantity_to_distribute;
                stationery.first_supplier  = objIn.first_supplier;
                stationery.second_supplier = objIn.second_supplier;
                stationery.third_supplier  = objIn.third_supplier;
                stationery.unit_of_measure = objIn.unit_of_measure;
                stationery.bin             = objIn.bin;

                data.Stationeries.ApplyCurrentValues(stationery);
                data.SaveChanges();
                return(this.getNewDefaultMessageForDBOperations(true));
            }
            catch (Exception e)
            {
                return(this.getNewDefaultMessageForException(e));
            }
        }
Beispiel #11
0
        protected void btnNotCollected_Click(object sender, EventArgs e)
        {
            //return stock, update stock management, update DD
            foreach (DisbursementDetail dd in ddList)
            {
                Stationery stat = myBz.FindStationeryByItemCode(dd.ItemCode);
                stat.QuantityInStock += dd.QuantityReceived;
                myBz.UpdateStationery(stat);
                StockManagement sm = new StockManagement();
                sm.Date         = DateTime.Today;
                sm.ItemCode     = dd.ItemCode;
                sm.StoreClerkId = storeClerkId;
                sm.Source       = "DIS";
                sm.QtyAdjusted  = dd.QuantityReceived;
                sm.Balance      = stat.QuantityInStock;
                myBz.AddNewStockManagement(sm);

                dd.QuantityReceived = 0;
                myBz.UpdateDisbursementDetail(dd);
            }

            //update disbursement status
            currentDisb.Status = "Not Collected";
            myBz.UpdateDisbursement(currentDisb);
            DisplayForAllocated(false);
            Response.Redirect("~/Store/DisbursementDetails.aspx");
        }
Beispiel #12
0
        public void updateStationeryPendingQty(int itemId, int affordAbleQty)
        {
            Stationery stationery = data.Stationeries.Where(s => (s.id == itemId)).Single();

            stationery.pending_quantity_to_distribute += affordAbleQty;
            Console.WriteLine("Updating stationery qty successful !" + data.SaveChanges());
        }
        public void Plus_FoodAndFood_Equal()
        {
            // arrange
            string  name1  = "Scissors";
            decimal price1 = 3.4m;
            string  type1  = "stationery";

            Stationery stationery1 = new Stationery(name1, type1, price1);

            string  name2  = "Pencil";
            decimal price2 = 2.2m;
            string  type2  = "stationery";

            Stationery stationery2 = new Stationery(name2, type2, price2);

            string  name3  = "Scissors-Pencil";
            decimal price3 = 2.8m;
            string  type3  = "stationery";

            Stationery stationery3Expected = new Stationery(name3, type3, price3);

            // act
            Stationery actual = stationery1 + stationery2;

            // assert;
            Assert.Equal(stationery3Expected, actual);
        }
        public IHttpActionResult GetSupplierAndPriceFromItem(string itemId)
        {
            List <TopSupplierAndPriceDTO> spObj = new List <TopSupplierAndPriceDTO>();

            Stationery stationery = _context.Stationery.FirstOrDefault(x => x.ItemId == itemId);

            TopSupplierAndPriceDTO firstSup = new TopSupplierAndPriceDTO();

            firstSup.Id       = stationery.FirstSupplierId;
            firstSup.Price    = stationery.FirstSuppPrice;
            firstSup.Supplier = stationery.Supplier.SupplierName;
            spObj.Add(firstSup);

            TopSupplierAndPriceDTO secondSup = new TopSupplierAndPriceDTO();

            secondSup.Id       = stationery.SecondSupplierId;
            secondSup.Price    = stationery.SecondSuppPrice;
            secondSup.Supplier = stationery.Supplier1.SupplierName;
            spObj.Add(secondSup);

            TopSupplierAndPriceDTO thirdSup = new TopSupplierAndPriceDTO();

            thirdSup.Id       = stationery.ThirdSupplierId;
            thirdSup.Price    = stationery.ThirdSuppPrice;
            thirdSup.Supplier = stationery.Supplier2.SupplierName;
            spObj.Add(thirdSup);


            return(Ok(spObj));
        }
        public string UpdateRetrieval(WCFRetrievalForm wcfr)
        {
            try
            {
                List <RetrieveForm> list = (List <RetrieveForm>)HttpContext.Current.Application["retrieveForm"];
                RetrieveForm        rf   = list.Where(x => x.ItemCode == wcfr.ItemCode).First();

                Stationery item = stationeryService.FindStationeryByItemCode(wcfr.ItemCode);
                if (wcfr.QtyRetrieved.Value > item.stockQty)
                {
                    return("Value of Retrieved Qty cannot exceed Stock Qty.");
                }

                if (wcfr.QtyRetrieved > rf.Qty)
                {
                    return("Value of Retrieved Qty cannot exceed requested qty.");
                }

                var index = list.FindIndex(x => x.description == wcfr.Description);
                list[index].retrieveQty = wcfr.QtyRetrieved;
                /*  list[index].Qty -= wcfr.QtyRetrieved;*/ //reduce amount that is still pending retrieval

                HttpContext.Current.Application["retrieveForm"] = list;
                return("true");
            }

            catch (Exception e)
            {
                String error = e.Message;

                return(error);
            }
        }
Beispiel #16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Context.User.IsInRole("Store Clerk"))
            {
                Response.Redirect("~/ErrorPages/Unauthorised");
            }
            else
            {
                lblMessage.Text = "";

                if (!IsPostBack)
                {
                    if (Request.QueryString["code"] != null)
                    {
                        string     itemCode   = Request.QueryString["code"];
                        Stationery stationery = StockManagementBizLogic.getStationery(itemCode);
                        if (stationery != null)
                        {
                            PopulateData(stationery);
                        }
                        else
                        {
                            lblMessage.Text = "No stationery found";
                        }
                    }
                    else
                    {
                        gvMaintainStockCard.DataSource = null;
                        gvMaintainStockCard.DataBind();
                        lblMessage.Text = "Please search for an item to display its stock card.";
                    }
                }
            }
        }
Beispiel #17
0
        public IHttpActionResult getItem(string itemId)
        {
            Stationery           item   = context.Stationery.Single(x => x.ItemId == itemId);
            AdjustmentItemDetail result = new AdjustmentItemDetail(item.ItemId, item.Category, item.Description, item.UnitOfMeasure, item.QuantityWarehouse, item.FirstSuppPrice);

            return(Ok(result));
        }
        //only call AFTER GENERATING NEW RD FOR UNFULFILLED ITEMS
        public void CheckRequisitionCompletenessAfterDisbursement(int disbursementId, Models.MobileDTOs.DisbursementDTO dDto)
        {
            List <Requisition> uniqueReqs = requisitionDetailRepo.GetUniqueRequisitionsForDisbursement(disbursementId);

            foreach (Requisition r in uniqueReqs)
            {
                int rowsReqDets   = requisitionDetailRepo.FindBy(x => x.RequisitionId == r.Id).Count();
                int rowsFulfilled = requisitionDetailRepo.FindBy(x => x.RequisitionId == r.Id &&
                                                                 x.Status.Equals("COLLECTED")).Count();
                if (rowsReqDets == rowsFulfilled)
                {
                    //update r to completed
                    Requisition req = requisitionRepo.FindById(r.Id);
                    req.Status = RequisitionStatusEnum.COMPLETED.ToString();
                    requisitionRepo.Update(req);
                    emailNotificationService.NotifyEmployeeCompletedRequisition(req, req.Employee);
                }
            }
            Disbursement d = disbursementRepo.FindById(disbursementId);

            d.DeliveryDateTime = DateTime.Now;
            byte[] bytes = Convert.FromBase64String(dDto.Signature);
            d.Signature = bytes;
            d.OnRoute   = false;
            disbursementRepo.Update(d);
            foreach (RequisitionDetail rd in d.RequisitionDetails)
            {
                Stationery s = stationeryRepo.FindById(rd.Stationery.Id);
                s.Quantity -= (int)rd.QuantityDelivered;
                stationeryRepo.Update(s);
            }
        }
Beispiel #19
0
        public void ApproveAdjustmentList(List <int> listAdjustmentId, string remarks, int approvedByEmployeeId)
        {
            // Generate voucherNumber
            int newVoucherNumber = saService.FindLastVoucherNumber() + 1;

            foreach (int id in listAdjustmentId)
            {
                // 1. ADJUSTMENT
                StockAdjustment s = saService.FindAdjustmentById(id); // Associated adjustment object

                // Check if negative adjustments exceeded stock quantity
                // Modify adjusted quantity and add remarks for user
                int currentQty = FindCurrentQuantityByItemCode(s.ItemCode);
                if ((currentQty + s.QuantityAdjusted) < 0)
                {
                    s.QuantityAdjusted = -currentQty;
                    remarks           += " SYSTEM GENERATED-As user input negative adjustment exceeded " +
                                         "current quantity, adjusted quantity would be modified to reduce current quantity to zero.";
                }

                s.ApproverRemarks      = remarks;
                s.DateApproved         = DateTime.Today;
                s.ApprovedByEmployeeId = approvedByEmployeeId;
                s.VoucherNumber        = newVoucherNumber;

                // 2. STATIONERY
                Stationery sta = stService.FindStationeryById(s.ItemCode);
                sta.QuantityInStock += s.QuantityAdjusted;

                // 3. BOTH
                saService.ApproveAdjustment(s);
                stService.UpdateStationery(sta);
            }
        }
        private AdjustmentVoucherViewModel ConvertDetailToViewModel(Voucher_Detail detail)
        {
            Stationery stationery         = stationeryService.FindStationeryByItemCode(detail.itemCode);
            AdjustmentVoucherViewModel vm = new AdjustmentVoucherViewModel();

            // Stationery information
            vm.ItemCode = detail.itemCode;
            vm.StationeryDescription = stationery.description;
            vm.UOM   = stationery.unitOfMeasure;
            vm.Price = stationery.price;

            // Voucher Record information
            vm.VoucherNo          = detail.voucherID;
            vm.Requester          = userService.FindNameByID(detail.Adjustment_Voucher_Record.handlingStaffID);
            vm.VoucherTotalAmount = 0.00M;
            vm.IssueDate          = detail.Adjustment_Voucher_Record.issueDate;
            vm.ApprovalDate       = detail.Adjustment_Voucher_Record.approvalDate;
            if (!String.IsNullOrEmpty(detail.Adjustment_Voucher_Record.authorisingStaffID))
            {
                vm.Approver = userService.FindNameByID(detail.Adjustment_Voucher_Record.authorisingStaffID);
            }
            vm.Causes = detail.Adjustment_Voucher_Record.remarks;
            vm.Status = detail.Adjustment_Voucher_Record.status;


            // Voucher Detail information
            vm.Quantity = detail.adjustedQty;
            vm.Reason   = detail.remarks;

            return(vm);
        }
 public JsonResult ConfirmPO(int poId, string reply, string remark)
 {
     if (Session["existinguser"] != null)
     {
         LoginDTO currentUser = (LoginDTO)Session["existinguser"];
         if (currentUser.RoleId == (int)Enums.Roles.StoreSupervisor || currentUser.RoleId == (int)Enums.Roles.StoreManager)
         {
             PurchaseOrder purchaseOrder = PurchaseOrderService.Instance.getPurchaseOrderById(poId);
             if (purchaseOrder != null)
             {
                 if (purchaseOrder.Status == Enum.GetName(typeof(Enums.POStatus), Enums.POStatus.PENDING))
                 {
                     purchaseOrder.Status = reply;
                     purchaseOrder.Remark = remark;
                     PurchaseOrderService.Instance.UpdatePO(purchaseOrder);
                     if (reply != "REJECTED")
                     {
                         string supplierName = purchaseOrder.Supplier.Name;//SupplierService.Instance.getSupplierById(purchaseOrder.SupplierId);
                         string itemlist     = "";
                         foreach (PurchaseOrderDetail po in purchaseOrder.PurchaseOrderDetails)
                         {
                             Stationery s = StationeryService.Instance.GetStationeryById(po.StationeryId);
                             itemlist += s.Description + " : " + po.QuantityOrdered + "\n";
                         }
                         EmailNotificationService.Instance.SendNotificationEmail(receipient: "*****@*****.**", subject: "New Purchase Order" + DateTime.Now.ToString("dd/MM/yyyy"), body: "Dear " + supplierName + ",\n\nWe want to order these items. Please delivery the listed items by " + ((DateTime)purchaseOrder.EstDeliveryDate).ToString("dd/MM/yyyy") + "\n\n" + itemlist + "\n\nThanks You");
                     }
                     return(Json(new object[] { true, "" }, JsonRequestBehavior.AllowGet));
                 }
                 return(Json(new object[] { false, "This purchase order is not in PENDING status." }, JsonRequestBehavior.AllowGet));
             }
             return(Json(new object[] { false, "This purchase order does not exist." }, JsonRequestBehavior.AllowGet));
         }
     }
     return(Json(new object[] { false, "You don't have permission." }, JsonRequestBehavior.AllowGet));
 }
Beispiel #22
0
        public ActionResult GetDescrpAndPrice(string itemcode)
        {
            Dictionary <Purchase_Detail, string> details = new Dictionary <Purchase_Detail, string>();
            List <Purchase_Detail> model = new List <Purchase_Detail>();

            ViewBag.itemCodeList = new SelectList(ss.GetAllStationery(), "itemCode", "description");
            if (Session["detailsBundle"] != null)
            {
                details = (Dictionary <Purchase_Detail, string>)Session["detailsBundle"];
                model   = details.Keys.ToList <Purchase_Detail>();
            }
            if (itemcode == "")
            {
                //do nothing, just return to view
            }
            else
            {
                Stationery s = ss.FindStationeryByItemCode(itemcode);
                ViewBag.supplierList = new SelectList(supplierService.FindSuppliersForStationery(s), "supplierCode", "supplierName");


                ViewBag.price         = s.price;
                ViewBag.descrp        = s.description;
                ViewBag.itemcode      = itemcode;
                ViewBag.firstSupplier = s.Supplier.supplierName;
                ViewBag.qty           = s.reorderQty;
            }
            return(View("RaisePurchaseOrder", model));
        }
        public Stationery FindStationeryById(string code)
        {
            SSAEntities context    = new SSAEntities();
            Stationery  stationery = context.Stationeries.Where(x => x.ItemCode == code).FirstOrDefault();

            return(stationery);
        }
        public Message actionCreateNewDiscrepancy(Discrepancy discrepancy)
        {
            discrepancy.datetime_reported = DateTime.Now;
            data.Discrepancies.AddObject(discrepancy);

            Stationery stationery = data.Stationeries.Where(o => o.id == discrepancy.stationery).Single();

            stationery.quantity_in_stock = stationery.quantity_in_stock - discrepancy.quantity;

            StockTransaction stockTransaction = new StockTransaction();

            stockTransaction.stationery        = stationery.id;
            stockTransaction.quantity          = "-" + discrepancy.quantity;
            stockTransaction.description       = discrepancy.remark;
            stockTransaction.balance           = stationery.quantity_in_stock.ToString();
            stockTransaction.datetime_inserted = DateTime.Now;
            data.StockTransactions.AddObject(stockTransaction);

            try
            {
                if (data.SaveChanges() == 3)
                {
                    return(new Message(true));
                }
                else
                {
                    return(new Message(false));
                }
            }
            catch (Exception e)
            {
                return(new Message(false, Helper.getExceptionMessage(e)));
            }
        }
        public string FindLastStationeryId()
        {
            SSAEntities s          = new SSAEntities();
            Stationery  stationery = s.Stationeries.OrderByDescending(x => x.ItemCode).FirstOrDefault();

            return(stationery.ItemCode);
        }
        private List <OwedItemDTO> GetListOfOwedItemDTOs(List <RequisitionDetail> requisitionDetails)
        {
            List <OwedItemDTO> owedItems = new List <OwedItemDTO>();
            List <IGrouping <int, RequisitionDetail> > groups = requisitionDetails.GroupBy(x => x.StationeryId).ToList();

            foreach (var group in groups)
            {
                int sum = 0;
                List <RequisitionDetail> rds = group.ToList();
                foreach (RequisitionDetail rd in rds)
                {
                    int diff = rd.QuantityOrdered - (int)rd.QuantityDelivered;
                    sum += diff;
                }
                //get stationery
                Stationery s = rds.First().Stationery;
                if (sum > 0)
                {
                    owedItems.Add(new OwedItemDTO {
                        Stationery = s, QtyOwed = sum
                    });
                }
            }
            return(owedItems);
        }
        public CatalogueItemDTO AddCartDetail(int employeeId, int stationeryId, int inputQty)
        {
            Stationery s           = stationeryRepo.FindById(stationeryId);
            int        currBalance = getCurrentBalance(s);
            int        reserved    = 0;
            int        waitlist    = 0;

            if (inputQty > currBalance)
            {
                reserved = currBalance;
                waitlist = inputQty - currBalance;
            }
            else
            {
                reserved = inputQty;
            }
            CartDetail cd = new CartDetail {
                DateTime = DateTime.Now, EmployeeId = employeeId, Quantity = inputQty, StationeryId = stationeryId
            };

            cartDetailRepo.Create(cd); //persist new cart detail

            //can abstract into a method and share with above bbut must instantiate a new DTO first
            CatalogueItemDTO catalogueItemDTO = new CatalogueItemDTO()
            {
                ReservedCount = reserved, WaitlistCount = waitlist
            };

            getCatalogueItemAvailability(catalogueItemDTO, s);
            return(catalogueItemDTO);
        }
        public ActionResult ItemRequestTrend(string categoryID, string itemCode, int[] years)
        {
            years = years.OrderBy(x => x).ToArray();
            List <ReportViewModel> vmList = reportService.GetItemRequestTrend(categoryID, itemCode, years);

            var results = (from vm in vmList
                           group vm by new { vm.Year, vm.Month } into g
                           select new { Year = g.Key.Year, Month = g.Key.Month, Sum = g.Sum(v => v.RequestQuantity) });

            Dictionary <string, int[]> dataset = new Dictionary <string, int[]>();

            foreach (var y in years)
            {
                string key   = y.ToString(); // use year for dict key
                int[]  value = new int[12];  // 12 months
                dataset.Add(key, value);
            }

            foreach (var r in results)
            {
                string key   = r.Year.ToString();
                var    value = dataset[key]; // get values based on year
                value[r.Month - 1] = r.Sum;  // put sum into corresponding month
            }


            if (categoryID != "-1") // prepare display title for chart
            {
                ViewBag.Category = stationeryService.GetAllCategory().Find(x => x.categoryID.ToString() == categoryID).categoryName;
            }
            else
            {
                ViewBag.Category = "";
            }

            if (itemCode != "-1") // prepare display title for chart
            {
                Stationery s = stationeryService.FindStationeryByItemCode(itemCode);
                ViewBag.ItemCode = String.Format("{0} ({1})", itemCode, s.description);
            }
            else
            {
                ViewBag.ItemCode = "All Items";
            }


            ViewBag.XLabels = monthsArray;

            for (int i = 1; i <= years.Length; i++) // create data array based on # of years
            {
                string labelName = String.Format("Label{0}", i);
                string dataName  = String.Format("Data{0}", i);

                string key = dataset.Keys.ToArray()[i - 1];
                ViewData[labelName] = key;
                ViewData[dataName]  = dataset[key];
            }

            return(PartialView("_ItemRequestTrend"));
        }
        //tuan

        public void EditST_RQ(int id, int Quantity)
        {
            Stationery sta = dct.Stationeries.Where(st => st.ProductId == id).ToList().First();

            sta.Quantity = Convert.ToInt32(Quantity);

            dct.SubmitChanges();
        }
        public async Task <Stationery> getItemByDesc(String desc)
        {
            Stationery sta = unitOfWork
                             .GetRepository <Stationery>()
                             .GetAllIncludeIQueryable(filter: x => x.desc == desc).FirstOrDefault();

            return(sta);
        }
 public Message actionCreateStationery(Stationery objIn)
 {
     try
     {
         data.Stationeries.AddObject(objIn);
         return this.getNewDefaultMessageForDBOperations(data.SaveChanges() == 1);
     }
     catch (Exception e)
     {
         return this.getNewDefaultMessageForException(e);
     }
 }
        public static StationeryModel Copy(Stationery objIn)
        {
            StationeryModel stationery = new StationeryModel();
            stationery.id = objIn.id;
            stationery.code = objIn.code;
            stationery.stationery_name = objIn.stationery_name;
            stationery.category = objIn.category;
            stationery.price = objIn.price;
            stationery.reorder_level = objIn.reorder_level;
            stationery.reorder_quantity = objIn.reorder_quantity;
            stationery.quantity_in_stock = objIn.quantity_in_stock;
            stationery.pending_quantity_to_distribute = objIn.pending_quantity_to_distribute;
            stationery.first_supplier = objIn.first_supplier.Value;
            stationery.second_supplier = objIn.second_supplier.Value;
            stationery.third_supplier = objIn.third_supplier.Value;

            return stationery;
        }
        public Message actionUpdateStationery(Stationery objIn)
        {
            try
            {
                //objIn.EntityKey = data.Stationeries.Where(o => o.id == objIn.id).Single().EntityKey;
                Stationery stationery = data.Stationeries.Where(o => o.id == objIn.id).Single();
                stationery.id = objIn.id;
                stationery.stationery_name = objIn.stationery_name;
                stationery.code = objIn.code;
                stationery.price = objIn.price;
                stationery.reorder_level = objIn.reorder_level;
                stationery.reorder_quantity = objIn.reorder_quantity;
                stationery.quantity_in_stock = objIn.quantity_in_stock;
                stationery.pending_quantity_to_distribute = objIn.pending_quantity_to_distribute;
                stationery.first_supplier = objIn.first_supplier;
                stationery.second_supplier = objIn.second_supplier;
                stationery.third_supplier = objIn.third_supplier;
                stationery.unit_of_measure = objIn.unit_of_measure;
                stationery.bin = objIn.bin;

                data.Stationeries.ApplyCurrentValues(stationery);
                data.SaveChanges();
                return this.getNewDefaultMessageForDBOperations(true);
            }
            catch (Exception e)
            {
                return this.getNewDefaultMessageForException(e);
            }
        }