Where I’m at
Portal - Development
Onward - Finishing up the Stocktake Form - Initialisation, Completion and Submission
Status update - update in bold (14 / 11 / 2023)
- Initialisation - nearly complete - done
 - Completion - about halfway - underway
 - Submission - not much progress — have psuedocode for submission logic
 
Tasks for completion for today:
- Finish off initialisation - this is the requirements:
- Allows user to use the button on the right conditions - done
- Understands the context - by calculating the week and reading the database for existing records. - done
 - For the future - getting context from a custom claim JWT (Auth token) - that will be how we determine the users associated location, role, etc. - later
 
 - When pressed it does three actions:
- Writes a new blank stocktake - done
 - Opens the stocktake widget - done
 - Locks the stocktake for the other user - done and also allows resumption of incomplete stocktakes
 
 
 - Allows user to use the button on the right conditions - done
 
Onto Stocktake Management Proper - Figuring out Stock Item, and Stock Count state management.
General Flow of State Management for Stock Item and Stock Counts
Models
| Component | Item | Stock Item | Stock Count | 
|---|---|---|---|
| Object | - | class StockItem {  String stockItemId; required String productId; // This is really a concrete SKU, not a relational ID String name; required String description; required bool isSelected = false;  | class StockCount {  int quantity; required // Matches to the “newQuantity” in the Adjustment model int lastCount; // Matches to the “oldQuantity” in the Adjustment model bool hasChanged = false;  | 
| Methods | - | - To = JSON  - From = fromFirestore factory method  | - To = JSON  - From = JSON  | 
State
| Component | Stock Item State | Count State | 
|---|---|---|
| Object | class StockItemState {  final List final bool isLoading; final String? error;  | class CountState {  final int quantity; final int lastCount; final bool hasChanged;  | 
| Methods | - copyWith method | - copyWith method | 
Notifiers
| Component | Stock Item Notifier | Counter Notifier | 
|---|---|---|
| Object | class StockItemNotifier extends StateNotifier final StockRepository stockRepository; StockItemNotifier(this.stockRepository) : super(StockItemState());  | class CounterNotifier extends StateNotifier CounterNotifier(CountState initialState) : super(initialState);  | 
| Methods | - fetchStockItems()  - addStockItem(StockItem item) - updateStockItem(StockItem item) - deleteStockItem(StockItem item) // TODO - Remove interface and refactor  | - incrementCount()  - decrementCount() - setCount(int newCount)  | 
Repository
| Methods | 
|---|
| - fetchStockItems() | 
| - addStockItem(StockItem item) | 
| // TODO - Remove interface and refactor | 
| - fetchStockCounts() // TODO - Complete | 
| - updateStockCount(StockCount count) // TODO - Complete | 
Providers
Not yet completed
final counterProvider =
StateNotifierProvider.family<CounterNotifier, CountState, int>(
(ref, initialCount) => CounterNotifier(CountState(
quantity: initialCount,
hasChanged: false,
Consumers - UI
Not yet completed
class Counter extends ConsumerWidget {
  final int initialCount;
  const Counter({
    super.key,
    required this.initialCount,
  });
  // Much more to do with the widget build
Mutation Matrix - Mapping the flow of change of the data / UI
Key:
- Bold – State - Local
 - Underline – Data - Firestore or Cache
 
| Mutation | Carousel | Stocktake List | Stock Item | Stock Count | Dots Decorator / Indicator | 
|---|---|---|---|---|---|
| Initialisation | displayLocationName  displaySublocation(init) getPageNumber(init)  | populateList(init) | fetchStockItems(init)  mapStockItems(init) cacheStockItems displayStockItems(init)  | fetchStockCounts(init)  mapStockCounts(init) cacheStockCounts displayStockCounts(init)  | buildDot(init) | 
| onPageChange | getPageNumber(new)  updateSublocation(new) displaySublocation(new)  | populateList(new) | cache.fetchStockItems(new)  displayStockItems(new)  | cache.fetchStockCounts(new)  displayStockCounts(new)  | buildDot(new) | 
| onCountChange | No action | No action | No action | updateStockCount()  updateStockCounts(change) displayStockCounts(change)  | No action |