public RetrievalModelCollection getAllRetrievedFromDepartment(string deptCode) { //{ PENDING, APPROVED, REJECTED, DISBURSED, PART_DISBURSED, CANCELLED, UPDATED }); List <Request> efRequests = context.Requests .Where(x => (x.current_status == RequestStatus.APPROVED || x.current_status == RequestStatus.PART_DISBURSED) && x.dept_code == deptCode ).ToList(); if (efRequests.Count == 0) { //throw new ItemNotFoundException(); return(new RetrievalModelCollection(new List <RetrievalModel>())); } List <RetrievalModel> results = new List <RetrievalModel>(); foreach (var efRequest in efRequests) { RetrievalModel retrieval = null;//findLatestRetrievalsByRequestId(efRequest.request_id); if (retrieval == null) { continue; // SKIP } results.Add(retrieval); } return(new RetrievalModelCollection(results)); }
public RetrievalModelCollection getAllRetrievingByClerk(string currentUser) { List <Request> efRequests = context.Requests .Where(x => x.current_status == RequestStatus.APPROVED || x.current_status == RequestStatus.PART_DISBURSED ).ToList(); List <RetrievalModel> results = new List <RetrievalModel>(); if (efRequests.Count == 0) { //throw new ItemNotFoundException("No records exist"); return(new RetrievalModelCollection(results)); } int count = 0; foreach (var efRequest in efRequests) { count++; RetrievalModel retrieval = findLatestRetrievingByRequestId(efRequest.request_id, currentUser); if (retrieval == null) { continue; // SKIP } results.Add(retrieval); } return(new RetrievalModelCollection(results)); }
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); }
public MainPresenter(MainGridModel mainGridModel, IMainView view, IMessagesView messagesView, IViewFactory viewFactory, IMessageBoxView messageBoxView, UserStatsDataModel userStatsDataModel, IPresenterFactory presenterFactory, IClientConfiguration clientConfiguration, IProteinService proteinService, IUpdateLogic updateLogic, RetrievalModel retrievalModel, IExternalProcessStarter processStarter, IPreferenceSet prefs, IClientSettingsManager settingsManager) { _gridModel = mainGridModel; //_gridModel.BeforeResetBindings += delegate { _view.DataGridView.FreezeSelectionChanged = true; }; _gridModel.AfterResetBindings += delegate { //_view.DataGridView.FreezeSelectionChanged = false; DisplaySelectedSlotData(); _view.RefreshControlsWithTotalsData(_gridModel.SlotTotals); }; _gridModel.SelectedSlotChanged += (sender, e) => { if (e.Index >= 0 && e.Index < _view.DataGridView.Rows.Count) { _view.DataGridView.Rows[e.Index].Selected = true; DisplaySelectedSlotData(); } }; _userStatsDataModel = userStatsDataModel; // Views _view = view; _messagesView = messagesView; _messageBoxView = messageBoxView; // _viewFactory = viewFactory; _presenterFactory = presenterFactory; // Collections _clientConfiguration = clientConfiguration; _proteinService = proteinService; // Logic Services _updateLogic = updateLogic; _updateLogic.Owner = _view; _retrievalModel = retrievalModel; _processStarter = processStarter; // Data Services _prefs = prefs; _settingsManager = settingsManager; _clientConfiguration.DictionaryChanged += delegate { AutoSaveConfig(); }; }
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); }