list orders

This commit is contained in:
Phuoc Nguyen
2025-11-24 16:25:54 +07:00
parent 354df3ad01
commit 75d6507719
24 changed files with 1004 additions and 982 deletions

View File

@@ -233,7 +233,19 @@ class ApiConstants {
/// Returns: { "message": { "file_url": "...", "file_name": "...", ... } }
static const String uploadFile = '/upload_file';
/// Get user's orders
/// Get list of orders (requires sid and csrf_token)
/// POST /api/method/building_material.building_material.api.sales_order.get_list
/// Body: { "limit_start": 0, "limit_page_length": 0 }
/// Returns: { "message": [...] }
static const String getOrdersList = '/building_material.building_material.api.sales_order.get_list';
/// Get order details (requires sid and csrf_token)
/// POST /api/method/building_material.building_material.api.sales_order.get_detail
/// Body: { "name": "SAL-ORD-2025-00058-1" }
/// Returns: { "message": {...} }
static const String getOrderDetail = '/building_material.building_material.api.sales_order.get_detail';
/// Get user's orders (legacy endpoint - may be deprecated)
/// GET /orders?status={status}&page={page}&limit={limit}
static const String getOrders = '/orders';

View File

@@ -61,6 +61,9 @@ class HiveBoxNames {
static const String cityBox = 'city_box';
static const String wardBox = 'ward_box';
/// Order status list cache
static const String orderStatusBox = 'order_status_box';
/// Get all box names for initialization
static List<String> get allBoxes => [
userBox,
@@ -73,6 +76,7 @@ class HiveBoxNames {
rewardsBox,
cityBox,
wardBox,
orderStatusBox,
settingsBox,
cacheBox,
syncStateBox,
@@ -134,8 +138,9 @@ class HiveTypeIds {
static const int addressModel = 30;
static const int cityModel = 31;
static const int wardModel = 32;
static const int orderStatusModel = 62;
// Enums (33-62)
// Enums (33-61)
static const int userRole = 33;
static const int userStatus = 34;
static const int loyaltyTier = 35;

View File

@@ -168,6 +168,9 @@ class HiveService {
// Location boxes (non-sensitive) - caches cities and wards for address forms
Hive.openBox<dynamic>(HiveBoxNames.cityBox),
Hive.openBox<dynamic>(HiveBoxNames.wardBox),
// Order status box (non-sensitive) - caches order status list from API
Hive.openBox<dynamic>(HiveBoxNames.orderStatusBox),
]);
// Open potentially encrypted boxes (sensitive data)

View File

@@ -0,0 +1,141 @@
/// Status Color Enum
///
/// Defines status types with their associated color values.
/// Used for status badges, alerts, and other UI elements that need
/// consistent color coding across the app.
library;
import 'package:flutter/material.dart';
/// Status Color Enum
///
/// Each status type has an associated color value.
enum StatusColor {
/// Warning status - Yellow/Orange
/// Used for cautionary states, pending actions, or items requiring attention
warning(Color(0xFFFFC107)),
/// Info status - Primary Blue
/// Used for informational states, neutral notifications, or general information
info(Color(0xFF005B9A)),
/// Danger status - Red
/// Used for error states, critical alerts, or destructive actions
danger(Color(0xFFDC3545)),
/// Success status - Green
/// Used for successful operations, completed states, or positive confirmations
success(Color(0xFF28A745)),
/// Secondary status - Light Grey
/// Used for secondary information, disabled states, or less important elements
secondary(Color(0xFFE5E7EB));
/// Constructor
const StatusColor(this.color);
/// The color value associated with this status
final Color color;
/// Get a lighter version of the color (with opacity)
/// Useful for backgrounds and subtle highlights
Color get light => color.withValues(alpha: 0.1);
/// Get a slightly darker version for borders
/// Useful for card borders and dividers
Color get border => color.withValues(alpha: 0.3);
/// Get the color with custom opacity
Color withOpacity(double opacity) => color.withValues(alpha: opacity);
/// Convert from string name (case-insensitive)
///
/// Example:
/// ```dart
/// final status = StatusColor.fromString('warning');
/// // Returns StatusColor.warning
/// ```
static StatusColor? fromString(String name) {
try {
return StatusColor.values.firstWhere(
(e) => e.name.toLowerCase() == name.toLowerCase(),
);
} catch (e) {
return null;
}
}
/// Get status color from order status string
///
/// Maps common order status strings to appropriate colors.
/// Returns null if no mapping exists.
///
/// Example:
/// ```dart
/// final color = StatusColor.fromOrderStatus('Processing');
/// // Returns StatusColor.warning
/// ```
static StatusColor? fromOrderStatus(String status) {
final statusLower = status.toLowerCase();
// Success states
if (statusLower.contains('completed') ||
statusLower.contains('delivered') ||
statusLower.contains('paid') ||
statusLower.contains('approved')) {
return StatusColor.success;
}
// Warning/Pending states
if (statusLower.contains('pending') ||
statusLower.contains('processing') ||
statusLower.contains('shipping') ||
statusLower.contains('reviewing')) {
return StatusColor.warning;
}
// Danger/Error states
if (statusLower.contains('cancelled') ||
statusLower.contains('rejected') ||
statusLower.contains('failed') ||
statusLower.contains('expired')) {
return StatusColor.danger;
}
// Info states
if (statusLower.contains('draft') ||
statusLower.contains('sent') ||
statusLower.contains('viewed')) {
return StatusColor.info;
}
return null;
}
/// Get status color from payment status string
///
/// Maps common payment status strings to appropriate colors.
/// Returns null if no mapping exists.
static StatusColor? fromPaymentStatus(String status) {
final statusLower = status.toLowerCase();
// Success states
if (statusLower.contains('completed') || statusLower.contains('paid')) {
return StatusColor.success;
}
// Warning/Pending states
if (statusLower.contains('pending') || statusLower.contains('processing')) {
return StatusColor.warning;
}
// Danger/Error states
if (statusLower.contains('failed') ||
statusLower.contains('rejected') ||
statusLower.contains('refunded')) {
return StatusColor.danger;
}
return StatusColor.info;
}
}