private MakeNewRequestModel _updateViewModelCategory(MakeNewRequestModel model, string itemCode)
        {
            List <Stock_Inventory> stocks = Session[SESSION_STOCKS] as List <Stock_Inventory>;

            model.DictDescriptions = stocks.Where(w => w.cat_id == model.CurrentCategory).ToDictionary(k => k.item_code, v => v.item_description);

            if (itemCode == null)
            {
                var stList = stocks.Where(w => w.cat_id == model.CurrentCategory);
                if (stList.Count() > 0)
                {
                    Stock_Inventory st = stocks.Where(w => w.cat_id == model.CurrentCategory).First();
                    model.CurrentItem = st.item_code;
                }
                else
                {
                    model.CurrentItem = null;
                }
            }
            else
            {
                model.CurrentItem = itemCode;
            }

            return(_updateViewModelItem(model));
        }
        //chnage into Item Name to item COode
        public string changeItemNametoCode(string itemName)
        {
            Stock_Inventory st       = context.Stock_Inventory.SingleOrDefault(x => x.item_description == itemName);
            string          itemCode = st.item_code;

            return(itemCode);
        }
Exemple #3
0
        public ItemModel GetItemModel(string itemCode)
        {
            SSISEntities    context  = new SSISEntities();
            Stock_Inventory iventory = context.Stock_Inventory.Where(x => x.item_code == itemCode).ToList().First();
            ItemModel       model    = new ItemModel(iventory);

            return(model);
        }
        public ItemModel(Stock_Inventory stock)
        {
            itemCode        = stock.item_code;
            description     = stock.item_description;
            category        = stock.Category;
            catName         = category.cat_name;
            unitOfMeasure   = stock.unit_of_measure;
            imagePath       = stock.image_path;
            currentQuantity = stock.current_qty;
            reorderLevel    = stock.reorder_level;
            reorderQuantity = stock.reorder_qty;
            //Changes for dashboard
            var stockItems = stock.Tender_List_Details.Where(w => w.deleted != "Y" && w.Tender_List.deleted != "Y" && w.Tender_List.tender_date.Year == DateTime.Now.Year);

            prices = new Dictionary <Supplier, double>();

            using (SSISEntities context = new SSISEntities())
            {
                // get tender list details associated with this item code

                IEnumerable <Tender_List_Details> details = context.Tender_List_Details
                                                            .Where(w => w.Tender_List.tender_date.Year == DateTime.Now.Year && w.Tender_List.deleted != "Y" &&
                                                                   w.item_code == itemCode && w.deleted != "Y")
                                                            // Get distinct
                                                            .GroupBy(d => d.Tender_List.supplier_id)
                                                            .Select(group => group.FirstOrDefault());

                Supplier sup = context.Suppliers.First();

                if (details.Count() == 0)
                {
                    // cannot find for whatever reason
                    prices.Add(sup, 0.0);
                }
                else
                {
                    // can find
                    foreach (var detail in details)
                    {
                        prices.Add(detail.Tender_List.Supplier, Convert.ToDouble(detail.price));
                    }
                }
            }


            //foreach (var stockItem in stockItems)
            //{
            //    if (! prices.ContainsKey(stockItem.Tender_List.Supplier))
            //    {
            //        prices.Add(stockItem.Tender_List.Supplier, Convert.ToDouble(stockItem.price));
            //    }
            //}

            //prices = stockItems.ToDictionary(x => x.Tender_List.Supplier, x => Convert.ToDouble(x.price));
            //prices = stock.Tender_List_Details.Where(w => w.deleted != "Y" && w.Tender_List.deleted != "Y" && w.Tender_List.tender_date.Year == DateTime.Now.Year).ToDictionary(x => x.Tender_List.Supplier, x => Convert.ToDouble(x.price));
        }
Exemple #5
0
        public void UpdateFileDiscrepancies(List <WCF_FileDiscrepancy> fileDiscrepancies, string username)
        {
            Inventory_Adjustment invAdjustmentSup = new Inventory_Adjustment();

            invAdjustmentSup.deleted     = "N";
            invAdjustmentSup.clerk_user  = username;
            invAdjustmentSup.status      = "Pending";
            invAdjustmentSup.date        = DateTime.Today;
            invAdjustmentSup.status_date = DateTime.Today;

            Inventory_Adjustment invAdjustmentMan = new Inventory_Adjustment();

            invAdjustmentMan.deleted     = "N";
            invAdjustmentMan.clerk_user  = username;
            invAdjustmentMan.status      = "Pending";
            invAdjustmentMan.date        = DateTime.Today;
            invAdjustmentMan.status_date = DateTime.Today;

            foreach (WCF_FileDiscrepancy i in fileDiscrepancies)
            {
                int adjusted = int.Parse(i.adjustedQty);

                Stock_Inventory inventory = context.Stock_Inventory.Where(x => x.item_code == i.itemCode).ToList().First();
                inventory.current_qty += adjusted;

                MonthlyCheckModel itemModel = new MonthlyCheckModel(inventory);
                double            cost      = Math.Abs(adjusted) * itemModel.AveragePrice;

                Adjustment_Details adjDetails = new Adjustment_Details();
                adjDetails.deleted           = "N";
                adjDetails.item_code         = inventory.item_code;
                adjDetails.quantity_adjusted = adjusted;
                adjDetails.reason            = i.reason;

                if (cost < 250)
                {
                    invAdjustmentSup.Adjustment_Details.Add(adjDetails);
                }
                if (cost >= 250)
                {
                    invAdjustmentMan.Adjustment_Details.Add(adjDetails);
                }
                context.Adjustment_Details.Add(adjDetails);
            }

            if (invAdjustmentSup.Adjustment_Details.Count != 0)
            {
                context.Inventory_Adjustment.Add(invAdjustmentSup);
                context.SaveChanges();
            }
            if (invAdjustmentMan.Adjustment_Details.Count != 0)
            {
                context.Inventory_Adjustment.Add(invAdjustmentMan);
                context.SaveChanges();
            }
        }
        protected void CreateOrder(object sender, EventArgs e)
        {
            Button      btn       = (Button)sender;
            GridViewRow gvr       = (GridViewRow)btn.NamingContainer;
            bool        duplicate = false;


            string itemcode = ((Label)gvr.FindControl("Label_ItemCode")).Text;

            SSISEntities    context = new SSISEntities();
            Stock_Inventory item    = context.Stock_Inventory.Where(x => x.item_code == itemcode).First();

            HashSet <Stock_Inventory> itemList = (HashSet <Stock_Inventory>)Session["item"];

            if (itemList == null)
            {
                itemList = new HashSet <Stock_Inventory>();
                itemList.Add(item);
                lblResult.Visible    = true;
                lblduplicate.Visible = false;
                lblResult.Text       = "Added Item Code (" + itemcode + ") Successfully";
                Session["item"]      = itemList;
            }

            else
            {
                foreach (Stock_Inventory s in itemList)
                {
                    if (s.item_code == item.item_code)
                    {
                        duplicate = true;
                        break;
                    }
                }

                if (!duplicate)
                {
                    itemList.Add(item);
                    lblResult.Visible    = true;
                    lblduplicate.Visible = false;
                    lblResult.Text       = "Added Item Code (" + itemcode + ") Successfully";
                    Session["item"]      = itemList;
                }
                else
                {
                    lblduplicate.Visible = true;
                    lblResult.Visible    = false;
                    lblduplicate.Text    = "Duplicate item!";
                    Session["item"]      = itemList;
                }
            }
        }
        private void fillFields(Tender_List_Details order)
        {
            using (SSISEntities context = new SSISEntities())
            {
                Stock_Inventory item = context.Stock_Inventory.Where(x => x.item_code == order.item_code).First();//Find(order.ISBN);

                itemDesc     = item.item_description;
                supplierName = context.Suppliers.Where(x => x.supplier_id == order.Tender_List.supplier_id).Select(x => x.name).First();
                price        = order.price;
                tenderId     = order.tender_id;
                quantity     = item.reorder_qty;
                supplierId   = order.Tender_List.supplier_id;
            }
        }
Exemple #8
0
        public MonthlyCheckModel(Stock_Inventory stock)
        {
            ItemModel item = new ItemModel(stock);

            this.category        = item.Category;
            this.itemCode        = item.ItemCode;
            this.catName         = item.CatName;
            this.description     = item.Description;
            this.unitOfMeasure   = item.UnitOfMeasure;
            this.imagePath       = item.ImagePath;
            this.currentQuantity = item.CurrentQuantity;
            this.reorderQuantity = item.ReorderQuantity;
            this.reorderLevel    = item.ReorderLevel;
            this.prices          = item.Prices;
            this.actualQuantity  = item.CurrentQuantity;
            this.reason          = "";
            this.averagePrice    = AveragePrice;
        }
Exemple #9
0
        public RetrievalModel findLatestRetrievingByRequestId(int requestId, string currentUser)
        { // For at the warehouse
          // Get all allocated: depending on:
          // Determine there's any latest retrieval
          // Find the difference with the previous retrieval, to see how much to fulfill

            //{ PENDING, APPROVED, REJECTED, DISBURSED, PART_DISBURSED, CANCELLED, UPDATED });
            Request efRequest = context.Requests
                                .Where(x => x.request_id == requestId &&
                                       (x.current_status == RequestStatus.APPROVED ||
                                        x.current_status == RequestStatus.PART_DISBURSED) &&
                                       x.deleted != "Y"
                                       ).First();

            if (efRequest == null)
            {
                throw new ItemNotFoundException("No records exist");
            }

            Dictionary <ItemModel, int> itemsToFulfill = new Dictionary <ItemModel, int>();

            List <Request_Details> details = efRequest.Request_Details.ToList();

            foreach (var detail in details)
            {
                if (detail.deleted == "Y")
                {
                    continue;
                }

                List <Request_Event> events = detail.Request_Event.Where(w => w.deleted != "Y").ToList();

                // If there are no events for some reason, SKIP
                if (events.Count == 0)
                {
                    continue;
                }

                Request_Event eventItem = events.First();

                // If the event does not have anything allocated to it, SKIP
                if (eventItem.allocated == 0)
                {
                    continue;
                }

                // Only add if it's retrieving AND it was by the currentUser
                if (eventItem.status == EventStatus.RETRIEVING && eventItem.username == currentUser && eventItem.allocated.HasValue)
                {
                    Stock_Inventory s = detail.Stock_Inventory;
                    itemsToFulfill.Add(new ItemModel(s), eventItem.allocated.Value);
                }
            }

            if (itemsToFulfill.Count == 0)
            {
                return(null);
            }

            RetrievalModel retrieval = new RetrievalModel(efRequest, itemsToFulfill);

            return(retrieval);
        }
Exemple #10
0
        private DisbursementModel _findLatestBetweenStatuses(int requestId, string fromStatus, string toStatus, string currentUser)
        { // For signing off forms (all disbursing ones)
            Request efRequest = context.Requests
                                .Where(x => x.request_id == requestId &&
                                       (x.current_status == RequestStatus.APPROVED ||
                                        x.current_status == RequestStatus.PART_DISBURSED)
                                       ).First();

            if (efRequest == null)
            {
                throw new ItemNotFoundException("No records exist");
            }

            Dictionary <ItemModel, int> itemsToFulfill = new Dictionary <ItemModel, int>();

            List <Request_Details> details = efRequest.Request_Details.ToList();

            foreach (var detail in details)
            {
                //int itemQty = 0;
                if (detail.deleted == "Y")
                {
                    continue;
                }

                List <Request_Event> events = detail.Request_Event.Where(w => w.deleted != "Y").ToList();

                // If there are no events for some reason, SKIP
                if (events.Count == 0)
                {
                    continue;
                }

                Request_Event eventItem = events.First();

                // If the event does not have anything allocated to it, SKIP
                if (eventItem.allocated.HasValue && eventItem.allocated.Value == 0)
                {
                    continue;
                }



                // Only add if it's retrieving AND it was by the currentUser
                if (eventItem.status == fromStatus && eventItem.allocated.HasValue)
                {
                    // currentUser was specified, skip if it's not by them
                    if (currentUser != null &&
                        eventItem.username != currentUser)
                    {
                        continue;
                    }

                    Stock_Inventory s = detail.Stock_Inventory;
                    itemsToFulfill.Add(new ItemModel(s), eventItem.allocated.Value);
                }
            }

            if (itemsToFulfill.Count == 0)
            {
                return(null);
            }

            DisbursementModel retrieved = new DisbursementModel(efRequest, itemsToFulfill);

            return(retrieved);
        }
Exemple #11
0
        public RetrievalModel findLatestRetrievalsByRequestId(int requestId)
        {
            // Get all allocated: depending on:
            // Determine there's any latest retrieval
            // Find the difference with the previous retrieval, to see how much to fulfill

            //{ PENDING, APPROVED, REJECTED, DISBURSED, PART_DISBURSED, CANCELLED, UPDATED });
            Request efRequest = context.Requests
                                .Where(x => x.request_id == requestId &&
                                       (x.current_status == RequestStatus.APPROVED ||
                                        x.current_status == RequestStatus.PART_DISBURSED)
                                       ).First();

            if (efRequest == null)
            {
                throw new ItemNotFoundException("No records exist");
            }

            IEnumerable <IGrouping <string, Request_Event> > events = efRequest.Request_Details.SelectMany(x => x.Request_Event).GroupBy(g => g.Request_Details.item_code).ToList();

            Dictionary <ItemModel, int> itemsToFulfill = new Dictionary <ItemModel, int>();

            foreach (IGrouping <string, Request_Event> eventItem in events)
            {
                // Grouping:
                // A101
                // - Approved, 10
                // - Allocated, 9
                // A102
                // - Approved, 10
                List <Request_Event> latestRetrieval = eventItem.Where(x => x.status == EventStatus.RETRIEVED).OrderBy(o => o.date_time).ToList();
                if (latestRetrieval.Count == 0)
                {
                    continue;
                }

                int quantityToFulfil = 0;

                if (latestRetrieval.Count > 1)
                {
                    Request_Event last       = latestRetrieval.Last();
                    Request_Event secondLast = latestRetrieval[latestRetrieval.Count - 2];

                    quantityToFulfil = last.quantity - secondLast.quantity;
                }
                else
                {
                    quantityToFulfil = latestRetrieval.Last().quantity;
                }

                Stock_Inventory inv = context.Stock_Inventory.Find(eventItem.Key);
                itemsToFulfill.Add(new ItemModel(inv), quantityToFulfil);
            }

            if (itemsToFulfill.Count == 0)
            {
                return(null);
            }

            RetrievalModel retrieval = new RetrievalModel(efRequest, itemsToFulfill);

            return(retrieval);
        }
Exemple #12
0
        public AllocatedModel findLatestAllocatedByRequestId(int requestId)
        {
            // This NOW ALLOCATES UPON FINDING
            // Get all allocated: depending on:
            // Determine there's any latest allocation
            // Find the difference with the previous allocation, to see how much to fulfill

            //{ PENDING, APPROVED, REJECTED, DISBURSED, PART_DISBURSED, CANCELLED, UPDATED });
            Request efRequest = context.Requests
                                .Where(x => x.request_id == requestId &&
                                       (x.current_status == RequestStatus.APPROVED ||
                                        x.current_status == RequestStatus.PART_DISBURSED)
                                       ).First();

            if (efRequest == null)
            {
                throw new ItemNotFoundException("No records exist");
            }

            IEnumerable <IGrouping <string, Request_Event> > events = efRequest.Request_Details.SelectMany(x => x.Request_Event).GroupBy(g => g.Request_Details.item_code).ToList();

            Dictionary <ItemModel, int> itemsToFulfill = new Dictionary <ItemModel, int>();

            foreach (IGrouping <string, Request_Event> eventItem in events)
            {
                Request_Event item = eventItem.Where(w => w.deleted != "Y").DefaultIfEmpty(null).FirstOrDefault();

                if (item == null)
                {
                    continue;
                }

                // If neither approved nor disbursed, skip it.
                if (item.status != EventStatus.APPROVED &&
                    item.status != EventStatus.DISBURSED &&
                    item.status != EventStatus.ALLOCATED)
                {
                    continue;
                }

                Stock_Inventory inv       = context.Stock_Inventory.Find(eventItem.Key);
                ItemModel       itemModel = new ItemModel(inv);

                // Already allocated, just add it
                if (item.status == EventStatus.ALLOCATED && item.allocated.HasValue)
                {
                    itemsToFulfill.Add(itemModel, item.allocated.Value);
                    continue;
                }

                // Fully allocated, can skip
                if (item.status == EventStatus.DISBURSED && item.not_allocated == 0)
                {
                    continue;
                }

                int qtyToAllocate;

                if (item.status == EventStatus.APPROVED)
                {
                    // Take the whole quantity
                    qtyToAllocate = item.quantity;
                }
                else
                {
                    // Disbursed. Take just the not-allocated
                    qtyToAllocate = item.not_allocated.HasValue ? item.not_allocated.Value : 0;
                }

                // if for some reason it's still zero, just skip.
                if (qtyToAllocate == 0)
                {
                    continue;
                }


                int canAllocateQty = 0;
                int availableQty   = itemModel.AvailableQuantity;

                if (availableQty > 0)
                {
                    // There is available stock
                    if (availableQty >= qtyToAllocate)
                    {
                        // Lots of stock
                        canAllocateQty = qtyToAllocate;
                    }
                    else
                    {
                        // Only some stock
                        canAllocateQty = availableQty;
                    }
                }
                else
                {
                    // Cannot allocate at all, cannot retrieve, SKIP
                    continue;
                }

                // At this point, there is some qtyToAllocate
                context.Request_Event.Find(item.request_event_id).allocated = canAllocateQty;

                if (item.status == EventStatus.DISBURSED)
                {
                    context.Request_Event.Find(item.request_event_id).quantity       = qtyToAllocate;
                    context.Request_Event.Find(item.request_event_id).not_allocated -= canAllocateQty;
                }
                else
                {
                    // Approved only
                    // it.quantity doesn't change
                    //context.Request_Event.Find(item.request_event_id).quantity = //doesn't change;
                    context.Request_Event.Find(item.request_event_id).not_allocated = item.quantity - canAllocateQty;
                }
                context.Request_Event.Find(item.request_event_id).status = EventStatus.ALLOCATED;

                itemsToFulfill.Add(itemModel, canAllocateQty);
            }

            if (itemsToFulfill.Count == 0)
            {
                // Nothing to allocate, or cannot allocate anything at all.
                return(null);
            }

            AllocatedModel alloc = new AllocatedModel(efRequest, itemsToFulfill);

            // Save changes to update Available Qty
            context.SaveChanges();
            return(alloc);
        }
Exemple #13
0
        public int reAllocateRequest(RequestModel toAllocate, string currentUser)
        {
            int      added     = 0;
            DateTime timestamp = DateTime.Now;

            using (var transaction = context.Database.BeginTransaction())
            {
                try
                {
                    // For each item:
                    // - Get the latest status (e.g. retrieved or disbursed)
                    // - Compare this latest status to the approved amount
                    // - If there is a difference, try to reallocate it

                    // Get a list of details (items)
                    List <Request_Details> details = context.Requests.Find(toAllocate.RequestId).Request_Details.ToList();
                    if (details.Count == 0)
                    {
                        throw new ItemNotFoundException("Request could not be found");
                    }

                    // For each of these, get the latest status, and approved event
                    foreach (var detail in details)
                    {
                        Request_Event latest = detail.Request_Event.OrderBy(o => o.date_time).Last();
                        if (latest == null)
                        {
                            throw new ItemNotFoundException("event item could not be found");
                        }

                        Request_Event approved = detail.Request_Event.Where(e => e.status == EventStatus.APPROVED).OrderBy(o => o.date_time).Last();
                        if (approved == null)
                        {
                            throw new ItemNotFoundException("event item could not be found");
                        }

                        // Get the difference in quantity
                        int difference = approved.quantity - latest.quantity;

                        if (difference < 0)
                        {
                            throw new RequestDataIntegrityFailureException(
                                      string.Format("Request id ({0}) has quantities that don't match up!\n==>Request_Event id: {1}\n==>Request_Event id: {2}", toAllocate.RequestId, latest.request_event_id, approved.request_event_id)
                                      );
                        }

                        if (difference > 0)
                        {
                            // There is a difference, so reAllocate it, using the difference quantity
                            // Get the item model
                            Stock_Inventory stock = context.Stock_Inventory.Find(detail.item_code);
                            if (stock == null)
                            {
                                throw new ItemNotFoundException("Could not find stock_inventory for itemCode: " + detail.item_code);
                            }

                            ItemModel item = new ItemModel(stock);

                            // First, make sure each item can be allocated in its entirety. If it can, allocate it.
                            if (item.AvailableQuantity >= difference)
                            {
                                // For each item, add a new event that is allocated
                                Request_Event newEvent = new Request_Event();
                                newEvent.request_detail_id = detail.request_detail_id;

                                // get the quantity from the provided item quantity in the method arguments
                                newEvent.quantity  = toAllocate.Items.Where(i => i.Key.ItemCode == item.ItemCode).First().Value;
                                newEvent.status    = EventStatus.ALLOCATED;
                                newEvent.username  = currentUser;
                                newEvent.date_time = timestamp;
                                newEvent.deleted   = "N";

                                context.Request_Event.Add(newEvent);
                                added++;
                            }
                        }
                    }
                }
                catch (Exception exec)
                {
                    transaction.Rollback();
                    throw exec;
                }

                transaction.Commit();
            }
            return(added);
        }
        protected void Confirm(object sender, EventArgs e)
        {
            int orderID = Convert.ToInt32(Session["order"]);

            Delivery_Orders d = new Delivery_Orders();

            d.clerk_user   = User.Identity.Name;
            d.deleted      = "N";
            d.order_id     = orderID;
            d.receive_date = DateTime.Parse(deliverydate.Text);

            context.Delivery_Orders.Add(d);
            context.SaveChanges();

            List <Purchase_Order_Details> podList = context.Purchase_Order_Details.Where(x => x.order_id == orderID).ToList <Purchase_Order_Details>();

            foreach (Purchase_Order_Details pod in podList)
            {
                pod.status = "Completed";
                context.SaveChanges();
            }


            //Get DeliveryOrderID
            Delivery_Orders order = context.Delivery_Orders.Where(x => x.clerk_user == User.Identity.Name).OrderBy(x => x.delivery_id).ToList().Last();



            foreach (GridViewRow rows in GridView1.Rows)
            {
                TextBox qty = (TextBox)rows.FindControl("quantity");
                TextBox r   = (TextBox)rows.FindControl("remark");

                Label exp_quantity = (Label)rows.FindControl("Label_quantity");

                int exp_qty = Convert.ToInt32(exp_quantity.Text);

                Label itemdesc      = (Label)rows.FindControl("Label_itemDesc");
                Label orderdetailid = (Label)rows.FindControl("Label_OrderDetailId");

                string itemName = itemdesc.Text;
                int    quantity = Convert.ToInt32(qty.Text);


                string remarks     = r.Text;
                int    orderDetail = Convert.ToInt32(orderdetailid.Text);

                Stock_Inventory item            = context.Stock_Inventory.Where(x => x.item_description == itemName).First();
                int             currentQuantity = item.current_qty;
                item.current_qty = currentQuantity + quantity;
                context.SaveChanges();

                Purchase_Order_Details pod = context.Purchase_Order_Details.Where(x => x.order_details_id == orderDetail).First();

                Delivery_Details dd = new Delivery_Details();
                dd.delivery_id = order.delivery_id;
                dd.deleted     = "N";
                dd.tender_id   = pod.tender_id;
                dd.quantity    = quantity;
                dd.remarks     = remarks;

                context.Delivery_Details.Add(dd);
                context.SaveChanges();
            }


            Response.Redirect("~/views/storeclerk/viewpendingorder.aspx");
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            _checkQtyRows();

            UserModel currentUserModel;

            List <MakeNewRequestModel> models = _getModelsFromSession();

            using (SSISEntities context = new SSISEntities())
            {
                currentUserModel = new UserModel(User.Identity.Name);

                Dictionary <string, int> items = new Dictionary <string, int>();
                foreach (var model in models)
                {
                    // If the user didn't add a quantity, just SKIP
                    if (model.Quantity == 0)
                    {
                        continue;
                    }

                    if (items.ContainsKey(model.CurrentItem))
                    {
                        int qty = items[model.CurrentItem];
                        items.Remove(model.CurrentItem);

                        items.Add(model.CurrentItem, model.Quantity + qty);
                    }
                    else
                    {
                        items.Add(model.CurrentItem, model.Quantity);
                    }
                }

                Dictionary <ItemModel, int> itemModels = new Dictionary <ItemModel, int>();
                foreach (var item in items)
                {
                    Stock_Inventory stock = context.Stock_Inventory.Find(item.Key);
                    ItemModel       im    = new ItemModel(stock);
                    itemModels.Add(im, item.Value);
                }

                UserModel    user   = (UserModel)Session[SESSION_USER_MODEL];
                RequestModel newReq = new RequestModel();
                newReq.Items      = itemModels;
                newReq.Reason     = tbReason.Text;
                newReq.Department = user.Department;
                newReq.Status     = RequestStatus.PENDING;
                newReq.UserModel  = user;

                bool isEditing = (Session[SESSION_IS_EDITING] as bool?).Value;

                if (isEditing)
                {
                    newReq.RequestId = (int)Session[SESSION_REQ_EDIT_ID];
                    FacadeFactory.getRequestService(context).updateRequestChanges(newReq);
                }
                else
                {
                    FacadeFactory.getRequestService(context).saveNewRequest(newReq);
                }

                context.SaveChanges();
            }

            /* Email logic */
            string    fromEmail = currentUserModel.Email;
            string    fromName  = currentUserModel.Fullname;
            UserModel deptHead  = currentUserModel.FindDelegateOrDeptHead();
            string    toEmail   = deptHead.Email;
            string    toName    = deptHead.Fullname;

            string        subject = string.Format("New pending request from {0}", fromName);
            StringBuilder sb      = new StringBuilder();

            sb.AppendLine("Dear " + toName + ",");
            sb.AppendLine("<br />");
            sb.AppendLine("<br />");
            sb.AppendLine(string.Format("{0} has requested for some items, pending your approval.", fromName));
            sb.AppendLine("<br />");
            sb.AppendLine(string.Format("The request's reason is: {0}", tbReason.Text));
            sb.AppendLine("<br />");
            sb.AppendLine(string.Format("Please <a href=\"{0}\">follow this link to view the request</a>.", "https://rebrand.ly/ssis-mgr-viewpending"));
            sb.AppendLine("<br />");
            sb.AppendLine("<br />");
            sb.AppendLine("Thank you.");
            sb.AppendLine("<br />");
            sb.AppendLine("<br />");
            sb.AppendLine("<i>This message was auto-generated by the Stationery Store Inventory System.</i>");

            string body = sb.ToString();

            new Emailer(fromEmail, fromName).SendEmail(toEmail, toName, subject, body);
            /* End of email logic */

            //Response.Redirect(Request.Url.ToString(), false);
            Response.Redirect("EmpRequestHistory.aspx", false);
        }
Exemple #16
0
        public bool UpdateMonthlyCheck(List <WCF_MonthlyCheck> monthlyChecks, string username)
        {
            Inventory_Adjustment invAdjustmentSup = new Inventory_Adjustment();

            invAdjustmentSup.deleted     = "N";
            invAdjustmentSup.clerk_user  = username;
            invAdjustmentSup.status      = "Pending";
            invAdjustmentSup.date        = DateTime.Today;
            invAdjustmentSup.status_date = DateTime.Today;

            Inventory_Adjustment invAdjustmentMan = new Inventory_Adjustment();

            invAdjustmentMan.deleted     = "N";
            invAdjustmentMan.clerk_user  = username;
            invAdjustmentMan.status      = "Pending";
            invAdjustmentMan.date        = DateTime.Today;
            invAdjustmentMan.status_date = DateTime.Today;

            foreach (WCF_MonthlyCheck i in monthlyChecks)
            {
                int actual   = int.Parse(i.actualQuantity);
                int current  = int.Parse(i.CurrentQuantity);
                int adjusted = current - actual;

                if (adjusted == 0)
                {
                    continue;
                }

                Stock_Inventory inventory = context.Stock_Inventory.Where(x => x.item_code == i.ItemCode).ToList().First();
                inventory.current_qty = actual;

                MonthlyCheckModel itemModel = new MonthlyCheckModel(inventory);
                double            cost      = Math.Abs(adjusted) * itemModel.AveragePrice;

                Adjustment_Details adjDetails = new Adjustment_Details();
                adjDetails.deleted           = "N";
                adjDetails.item_code         = i.ItemCode;
                adjDetails.quantity_adjusted = adjusted;
                adjDetails.reason            = i.Reason;

                if (cost < 250)
                {
                    invAdjustmentSup.Adjustment_Details.Add(adjDetails);
                }
                if (cost >= 250)
                {
                    invAdjustmentMan.Adjustment_Details.Add(adjDetails);
                }
                context.Adjustment_Details.Add(adjDetails);
            }

            if (invAdjustmentSup.Adjustment_Details.Count != 0)
            {
                context.Inventory_Adjustment.Add(invAdjustmentSup);
                context.SaveChanges();
            }
            if (invAdjustmentMan.Adjustment_Details.Count != 0)
            {
                context.Inventory_Adjustment.Add(invAdjustmentMan);
                context.SaveChanges();
            }

            if (invAdjustmentSup.Adjustment_Details.Count != 0 || invAdjustmentMan.Adjustment_Details.Count != 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }