# Work Log

## Friday, December 5, 2025

### Features & UI Updates
- **Scan Result User Screen (`scan_result_user.dart`)**
  - **Refactoring**:
    - Redesigned the UI to match the style of the Admin `ScanResultScreen`.
    - Implemented a `DefaultTabController` with "Item Movement" and "Item Information" tabs.
    - Adopted the "framed image" style and consistent Key-Value pair styling with icons.
  - **Data & Display**:
    - Added a **"Station"** field to both the "Item Movement" and "Item Information" tabs.
    - Renamed "Current Information" container to **"Sender Information"** in the Item Movement tab.
    - Cleaned up the "Sender Information" container to display **only the "User"**, removing the redundant "Store" and "Station" fields in that specific context.
  - **Actions**:
    - Integrated user-specific actions (Receive, Return, Deploy Station, Cancel) into the new `_buildDynamicActionSection` within the Item Movement tab.
  - **Verification**:
    - Successfully built the APK (`flutter build apk --debug`) to verify the changes.

## Thursday, December 4, 2025

### Features & Logic Updates
- **Dashboard Reporting (Admin & User)**
  - **Service Layer**:
    - Created `lib/services/report_service.dart` to interface with the `/InvMainAPI/GetInventoryReport/{deptId}` endpoint.
  - **Admin Dashboard (`home_screen.dart`)**:
    - Integrated `ReportService` to fetch real-time inventory statistics.
    - Implemented logic to determine the correct department context:
      - Fetches data for "All" (0) if the user is SuperAdmin/SystemAdmin.
      - Fetches data for the specific department ID for other admin roles.
    - Replaced the placeholder "Inventory Report" table with a dynamic table displaying:
      - Total Items Registered
      - Current Stock
      - New Items (This/Last Month)
      - Stock Out (This/Last Month)
  - **User Dashboard (`home_screen_user.dart`)**:
    - Integrated `ReportService` to fetch inventory statistics specific to the user's department.
    - Updated the "INFORMATION" card (orange gradient) to display fetched data:
      - Total Items
      - Current Stock
      - New (Month)
      - Stock Out (Month)
    - Added loading indicators (`...`) for data fields while fetching.

## Wednesday, December 3, 2025

### Features & Logic Updates
- **QR Scanning & Item Movement (User Side)**
  - **New Screens**:
    - Created `lib/screens/user/scan/scan_user.dart`: Dedicated camera scanning screen for users.
    - Created `lib/screens/user/scan/scan_result_user.dart`: Implements user-specific scanning logic based on `QrUser.txt`.
  - **Logic Implementation**:
    - **Receive Item**: Only allowed if the item is "On Delivery" and assigned to the current user.
    - **Return Item**: Allowed if the user currently holds the item.
    - **Deploy Station**: Enables assigning an item to a station managed by the user.
    - **Cancel Movement**: Implemented cancellation logic specific to user movements (similar to Admin but tailored for user context).
    - **Status Handling**: Added logic to handle "Request Again" (already returned) and "Not Assigned to You" scenarios.
    - **Type Safety**: Fixed type comparison bugs (User ID string vs int) to ensuring accurate permission checks.
  - **Navigation**:
    - Updated `BottomNavBar` to route non-admin users to `/scan-user` and admins to `/scan`.
    - Registered `/scan-user` route in `main.dart`.
    - Configured all actions (Receive, Return, Cancel, Deploy) to redirect back to the scanner screen upon success.

- **QR Scanning (Admin Side)**
  - **Redirect Logic**: Updated `lib/screens/admin/scan/scan_result.dart` to redirect back to the scanner screen (`Navigator.pop`) instead of the Home Dashboard after successful actions (Receive, Add Movement, Cancel).
  - **Modal Handling**: Fixed the "Add Movement" flow to correctly close both the modal and the result screen (double pop) on success.

- **Service Updates**
  - **`ItemMovementService`**: Added endpoints for user actions: `updateItemMovementUser`, `returnItemMovementUser`, and `stationItemMovementUser`.

## Tuesday, December 2, 2025

### Features & Logic Updates
- **Item Movement User Pages (Refactoring to match Web App)**
  - **Item View (`item_movement_item_user.dart`)**:
    - Implemented filtering logic to truncate history at the point of a completed "Return" or "Ready To Deploy" status.
    - Corrected data mapping for "Start" (formerly `last...`) and "End" (formerly `to...`) fields.
    - Added **Status Headings** (Receive, Return, Change, Assign) with specific color coding.
    - Added **Completion Status** (Complete, Incomplete, Canceled) indicators.
    - Replaced the timeline visualization with a detailed list of movement cards for full history visibility.
    - Updated Icon logic for Start/End locations.
  - **Station View (`item_movement_station_user.dart`)**:
    - Integrated `ItemMovementService` to fetch real data (removed mock data).
    - Implemented grouping logic: Group by Station -> Group by Item -> History.
    - Applied the same history filtering/truncation logic as the Item View.
    - Updated UI components to be consistent with the detailed movement cards in Item View.
  - **All View (`item_movement_all_user.dart`)**:
    - Updated `_fetchInitialData` to group movements by `uniqueID` and select only the latest valid movement.
    - Implemented filtering to **exclude** items from the main view if their latest status is "Return" or "Ready To Deploy" and they are completed.
    - Restored missing state variables and fixed import issues during refactoring.

## Monday, December 1, 2025

### Features & Logic Updates
- **QR Scanning & Item Movement (`scan_result.dart`)**
  - Completely rewrote `ScanResultScreen` to match the web application's logic (`QrMaster.txt`).
  - Implemented dynamic UI tabs:
    - **Item Information**: Displays read-only item details (Image, Name, Part/Serial No, Quantity, PIC).
    - **Item Movement**: Displays current status and context-aware action buttons (Receive, Cancel, Add Movement).
  - **Actions & Logic**:
    - **Assigning**: Implemented a modal form to assign items to User, Station, Store, Supplier, or mark as Faulty.
    - **Consignment Note**: Added functionality to upload Consignment Notes via Camera or File Gallery (converted to Base64).
    - **Receiving**: Added logic to receive items based on their current status (e.g., "On Delivery" -> "Delivered", "Repair" -> "Ready To Deploy").
    - **Cancellation**: Implemented a complex cancellation flow that updates the movement status to "Cancelled", creates a new "Register" movement to restore stock, and updates the item quantity.
    - **Redirect**: Configured automatic redirection to the Dashboard (`/home`) upon successful completion of any action.

- **Service Updates**
  - **`ItemService`**: Added `getItem` (fetch by ID) and `updateItemQuantity`.
  - **`ItemMovementService`**: Added `addItemMovement`, `updateItemMovementMaster`, and `getItemMovementById`.

## Wednesday, November 26, 2025

### Features & Logic Updates
- **Admin Filtering (Item Movement & Product Request)**
  - Implemented client-side department-based filtering for "Inventory Master" role in `item_movement_service.dart` and `product_request_service.dart`.
  - Logic now ensures Inventory Masters only see requests/movements involving users from their own department (combined with existing store management logic).
  - Fetched user lists to map User IDs to Department IDs dynamically.

- **UI Updates**
  - **Navigation Bar (`nav_bar.dart`)**: Updated the Drawer Header to display the logged-in user's **Department Name** below their role.
  - **Dashboard Experiments**: Briefly implemented and then reverted Department Name displays on Admin and User Dashboards and Title Bars based on user preference.

## Tuesday, November 25, 2025

### Features & UI Updates
- **Product Request User Page (`product_request_user.dart`)**
  - Removed section headers ("Pending Request", "Complete Request", "Rejected Request").
  - Updated "Requested" and "Rejected" details layout to a 3-column grid.
  - Increased animation speed for expanding/collapsing details.
  - Added "Pull to Refresh" functionality.
  - Added a "Show" button for documents/pictures to view them in a dialog.
  - Implemented "Delete Request" functionality connected to the API.

- **Item Movement User Pages**
  - Added "Pull to Refresh" to:
    - `item_movement_all_user.dart`
    - `item_movement_item_user.dart`
    - `item_movement_station_user.dart`
  - **Item Movement Item User (`item_movement_item_user.dart`)**
    - Removed product image from the main card.
    - Simplified title to show only Item ID (matching Admin style).
    - Confirmed usage of `timeline_tile`.

- **Product Request Form (`product_request_user_form.dart`)**
  - Integrated `file_picker` package.
  - Implemented file selection for documents/pictures.
  - Added Base64 conversion for file upload payload.

- **Admin & Technician Pages**
  - **Inventory Master (`invMaster_to_invMaster.dart`)**: Added "Show" button for documents/pictures.
  - **Technician (`technician_to_invMaster.dart`)**: Added "Show" button for documents/pictures.

### Fixes
- Fixed a compilation error in `product_request_service.dart` (missing closing brace).