From 44402140fb48970aa3c86aa88a1a3359d273aa73 Mon Sep 17 00:00:00 2001 From: efrilm Date: Sat, 20 Sep 2025 03:56:07 +0700 Subject: [PATCH] Printer Local data and remove unused --- lib/core/database/database_handler.dart | 40 +- lib/core/function/app_function.dart | 16 +- .../printer/printer_local_datasource.dart | 317 ++++ .../datasources/product_local_datasource.dart | 639 -------- lib/data/models/response/print_model.dart | 136 +- lib/main.dart | 23 - .../home/bloc/checkout/checkout_bloc.dart | 7 +- .../local_product/local_product_bloc.dart | 26 - .../local_product_bloc.freezed.dart | 907 ----------- .../local_product/local_product_event.dart | 7 - .../local_product/local_product_state.dart | 9 - .../home/bloc/order/order_bloc.dart | 15 +- .../bloc/status_table/status_table_bloc.dart | 19 - .../status_table_bloc.freezed.dart | 725 --------- .../bloc/status_table/status_table_event.dart | 9 - .../bloc/status_table/status_table_state.dart | 8 - .../home/dialog/payment_qris_dialog.dart | 6 +- .../home/pages/dashboard_page.dart | 5 - .../blocs/bloc/last_order_table_bloc.dart | 23 - .../bloc/last_order_table_bloc.freezed.dart | 762 ---------- .../blocs/bloc/last_order_table_event.dart | 8 - .../blocs/bloc/last_order_table_state.dart | 8 - .../sales/blocs/day_sales/day_sales_bloc.dart | 25 - .../day_sales/day_sales_bloc.freezed.dart | 947 ------------ .../blocs/day_sales/day_sales_event.dart | 13 - .../blocs/day_sales/day_sales_state.dart | 8 - .../create_printer/create_printer_bloc.dart | 8 +- .../get_printer_bar/get_printer_bar_bloc.dart | 5 +- .../get_printer_checker_bloc.dart | 5 +- .../get_printer_kitchen_bloc.dart | 4 +- .../get_printer_receipt_bloc.dart | 4 +- .../get_printer_ticket_bloc.dart | 4 +- .../bloc/sync_order/sync_order_bloc.dart | 42 - .../sync_order/sync_order_bloc.freezed.dart | 866 ----------- .../bloc/sync_order/sync_order_event.dart | 7 - .../bloc/sync_order/sync_order_state.dart | 10 - .../update_printer/update_printer_bloc.dart | 4 +- .../setting/models/printer_model.dart | 129 ++ .../setting/pages/sync_data_page.dart | 96 +- .../generate_table/generate_table_bloc.dart | 1 - .../table/blocs/get_table/get_table_bloc.dart | 1 - .../blocs/update_table/update_table_bloc.dart | 4 - .../table/pages/payment_table_page.dart.old | 1330 ----------------- .../table/pages/table_page.dart.backup | 95 -- .../table/widgets/card_table_widget.dart | 113 -- .../table/widgets/table_widget.dart.backup | 399 ----- 46 files changed, 685 insertions(+), 7150 deletions(-) create mode 100644 lib/data/datasources/printer/printer_local_datasource.dart delete mode 100644 lib/data/datasources/product_local_datasource.dart delete mode 100644 lib/presentation/home/bloc/local_product/local_product_bloc.dart delete mode 100644 lib/presentation/home/bloc/local_product/local_product_bloc.freezed.dart delete mode 100644 lib/presentation/home/bloc/local_product/local_product_event.dart delete mode 100644 lib/presentation/home/bloc/local_product/local_product_state.dart delete mode 100644 lib/presentation/home/bloc/status_table/status_table_bloc.dart delete mode 100644 lib/presentation/home/bloc/status_table/status_table_bloc.freezed.dart delete mode 100644 lib/presentation/home/bloc/status_table/status_table_event.dart delete mode 100644 lib/presentation/home/bloc/status_table/status_table_state.dart delete mode 100644 lib/presentation/sales/blocs/bloc/last_order_table_bloc.dart delete mode 100644 lib/presentation/sales/blocs/bloc/last_order_table_bloc.freezed.dart delete mode 100644 lib/presentation/sales/blocs/bloc/last_order_table_event.dart delete mode 100644 lib/presentation/sales/blocs/bloc/last_order_table_state.dart delete mode 100644 lib/presentation/sales/blocs/day_sales/day_sales_bloc.dart delete mode 100644 lib/presentation/sales/blocs/day_sales/day_sales_bloc.freezed.dart delete mode 100644 lib/presentation/sales/blocs/day_sales/day_sales_event.dart delete mode 100644 lib/presentation/sales/blocs/day_sales/day_sales_state.dart delete mode 100644 lib/presentation/setting/bloc/sync_order/sync_order_bloc.dart delete mode 100644 lib/presentation/setting/bloc/sync_order/sync_order_bloc.freezed.dart delete mode 100644 lib/presentation/setting/bloc/sync_order/sync_order_event.dart delete mode 100644 lib/presentation/setting/bloc/sync_order/sync_order_state.dart delete mode 100644 lib/presentation/table/pages/payment_table_page.dart.old delete mode 100644 lib/presentation/table/pages/table_page.dart.backup delete mode 100644 lib/presentation/table/widgets/card_table_widget.dart delete mode 100644 lib/presentation/table/widgets/table_widget.dart.backup diff --git a/lib/core/database/database_handler.dart b/lib/core/database/database_handler.dart index 361db7a..c6a7e21 100644 --- a/lib/core/database/database_handler.dart +++ b/lib/core/database/database_handler.dart @@ -23,7 +23,7 @@ class DatabaseHelper { return await openDatabase( path, - version: 1, + version: 2, // Updated version for printer table onCreate: _onCreate, onUpgrade: _onUpgrade, ); @@ -66,17 +66,49 @@ class DatabaseHelper { ) '''); + // Printer table - NEW + await db.execute(''' + CREATE TABLE printers ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + code TEXT UNIQUE NOT NULL, + name TEXT NOT NULL, + address TEXT, + paper TEXT, + type TEXT, + created_at TEXT, + updated_at TEXT + ) + '''); + // Create indexes for better performance await db.execute( 'CREATE INDEX idx_products_category_id ON products(category_id)'); await db.execute('CREATE INDEX idx_products_name ON products(name)'); await db.execute('CREATE INDEX idx_products_sku ON products(sku)'); - await db.execute( - 'CREATE INDEX idx_products_description ON products(description)'); + await db.execute('CREATE INDEX idx_printers_code ON printers(code)'); + await db.execute('CREATE INDEX idx_printers_type ON printers(type)'); } Future _onUpgrade(Database db, int oldVersion, int newVersion) async { - // Handle database upgrades here + if (oldVersion < 2) { + // Add printer table in version 2 + await db.execute(''' + CREATE TABLE printers ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + code TEXT UNIQUE NOT NULL, + name TEXT NOT NULL, + address TEXT, + paper TEXT, + type TEXT, + created_at TEXT, + updated_at TEXT + ) + '''); + + // Add indexes for printer table + await db.execute('CREATE INDEX idx_printers_code ON printers(code)'); + await db.execute('CREATE INDEX idx_printers_type ON printers(type)'); + } } Future close() async { diff --git a/lib/core/function/app_function.dart b/lib/core/function/app_function.dart index 1eccb86..1a3bd49 100644 --- a/lib/core/function/app_function.dart +++ b/lib/core/function/app_function.dart @@ -7,7 +7,7 @@ import 'package:enaklo_pos/core/utils/printer_service.dart'; import 'package:enaklo_pos/data/dataoutputs/print_dataoutputs.dart'; import 'package:enaklo_pos/data/datasources/auth_local_datasource.dart'; import 'package:enaklo_pos/data/datasources/outlet_local_datasource.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; +import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart'; import 'package:enaklo_pos/data/datasources/settings_local_datasource.dart'; import 'package:enaklo_pos/data/models/response/order_response_model.dart'; import 'package:enaklo_pos/data/type/bussines_type.dart'; @@ -28,13 +28,13 @@ Future onPrint( if (outlet.businessType == BusinessType.restaurant) { final checkerPrinter = - await ProductLocalDatasource.instance.getPrinterByCode('checker'); + await PrinterLocalDatasource.instance.getPrinterByCode('checker'); final kitchenPrinter = - await ProductLocalDatasource.instance.getPrinterByCode('kitchen'); + await PrinterLocalDatasource.instance.getPrinterByCode('kitchen'); final barPrinter = - await ProductLocalDatasource.instance.getPrinterByCode('bar'); + await PrinterLocalDatasource.instance.getPrinterByCode('bar'); final receiptPrinter = - await ProductLocalDatasource.instance.getPrinterByCode('receipt'); + await PrinterLocalDatasource.instance.getPrinterByCode('receipt'); if (receiptPrinter != null) { try { @@ -232,7 +232,7 @@ Future onPrint( if (outlet.businessType == BusinessType.ticketing) { final ticketPrinter = - await ProductLocalDatasource.instance.getPrinterByCode('ticket'); + await PrinterLocalDatasource.instance.getPrinterByCode('ticket'); final barcode = await generateBarcodeAsUint8List(order.orderNumber ?? ""); @@ -288,7 +288,7 @@ Future onPrintRecipt( required List productQuantity, }) async { final receiptPrinter = - await ProductLocalDatasource.instance.getPrinterByCode('receipt'); + await PrinterLocalDatasource.instance.getPrinterByCode('receipt'); final authData = await AuthLocalDataSource().getAuthData(); final settings = await SettingsLocalDatasource().getTax(); final outlet = await OutletLocalDatasource().get(); @@ -346,7 +346,7 @@ Future onPrinVoidRecipt( required int totalVoid, }) async { final receiptPrinter = - await ProductLocalDatasource.instance.getPrinterByCode('receipt'); + await PrinterLocalDatasource.instance.getPrinterByCode('receipt'); final authData = await AuthLocalDataSource().getAuthData(); final settings = await SettingsLocalDatasource().getTax(); final outlet = await OutletLocalDatasource().get(); diff --git a/lib/data/datasources/printer/printer_local_datasource.dart b/lib/data/datasources/printer/printer_local_datasource.dart new file mode 100644 index 0000000..eb02f79 --- /dev/null +++ b/lib/data/datasources/printer/printer_local_datasource.dart @@ -0,0 +1,317 @@ +import 'dart:developer'; +import 'package:enaklo_pos/core/database/database_handler.dart'; +import 'package:enaklo_pos/data/models/response/print_model.dart'; +import 'package:sqflite/sqflite.dart'; + +class PrinterLocalDatasource { + static PrinterLocalDatasource? _instance; + + PrinterLocalDatasource._internal(); + + static PrinterLocalDatasource get instance { + _instance ??= PrinterLocalDatasource._internal(); + return _instance!; + } + + Future get _db async => await DatabaseHelper.instance.database; + + // Create new printer + Future createPrinter(PrintModel printer) async { + final db = await _db; + + try { + log('Creating printer: ${printer.toString()}'); + + final id = await db.insert( + 'printers', + printer.toMapForInsert(), + conflictAlgorithm: + ConflictAlgorithm.abort, // Fail if code already exists + ); + + log('Successfully created printer with ID: $id'); + return id; + } catch (e) { + log('Error creating printer: $e'); + rethrow; + } + } + + // Update existing printer + Future updatePrinter(PrintModel printer, int id) async { + final db = await _db; + + try { + log('Updating printer ID $id: ${printer.toString()}'); + + final updatedRows = await db.update( + 'printers', + printer.toMapForUpdate(), + where: 'id = ?', + whereArgs: [id], + ); + + if (updatedRows == 0) { + throw Exception('Printer with ID $id not found'); + } + + log('Successfully updated printer ID: $id'); + } catch (e) { + log('Error updating printer: $e'); + rethrow; + } + } + + // Delete printer by ID + Future deletePrinter(int id) async { + final db = await _db; + + try { + log('Deleting printer ID: $id'); + + final deletedRows = await db.delete( + 'printers', + where: 'id = ?', + whereArgs: [id], + ); + + if (deletedRows == 0) { + throw Exception('Printer with ID $id not found'); + } + + log('Successfully deleted printer ID: $id'); + } catch (e) { + log('Error deleting printer: $e'); + rethrow; + } + } + + // Get printer by code + Future getPrinterByCode(String code) async { + final db = await _db; + + try { + log('Getting printer by code: $code'); + + final result = await db.query( + 'printers', + where: 'code = ?', + whereArgs: [code], + ); + + if (result.isEmpty) { + log('Printer with code $code not found'); + return null; + } + + final printer = PrintModel.fromMap(result.first); + log('Found printer: ${printer.toString()}'); + return printer; + } catch (e) { + log('Error getting printer by code: $e'); + return null; + } + } + + // Get printer by ID + Future getPrinterById(int id) async { + final db = await _db; + + try { + log('Getting printer by ID: $id'); + + final result = await db.query( + 'printers', + where: 'id = ?', + whereArgs: [id], + ); + + if (result.isEmpty) { + log('Printer with ID $id not found'); + return null; + } + + final printer = PrintModel.fromMap(result.first); + log('Found printer: ${printer.toString()}'); + return printer; + } catch (e) { + log('Error getting printer by ID: $e'); + return null; + } + } + + // Get all printers + Future> getAllPrinters() async { + final db = await _db; + + try { + log('Getting all printers'); + + final result = await db.query( + 'printers', + orderBy: 'name ASC', + ); + + final printers = result.map((map) => PrintModel.fromMap(map)).toList(); + log('Found ${printers.length} printers'); + + return printers; + } catch (e) { + log('Error getting all printers: $e'); + return []; + } + } + + // Get printers by type + Future> getPrintersByType(String type) async { + final db = await _db; + + try { + log('Getting printers by type: $type'); + + final result = await db.query( + 'printers', + where: 'type = ?', + whereArgs: [type], + orderBy: 'name ASC', + ); + + final printers = result.map((map) => PrintModel.fromMap(map)).toList(); + log('Found ${printers.length} printers with type $type'); + + return printers; + } catch (e) { + log('Error getting printers by type: $e'); + return []; + } + } + + // Search printers by name + Future> searchPrintersByName(String query) async { + final db = await _db; + + try { + log('Searching printers by name: $query'); + + final result = await db.query( + 'printers', + where: 'name LIKE ?', + whereArgs: ['%$query%'], + orderBy: 'name ASC', + ); + + final printers = result.map((map) => PrintModel.fromMap(map)).toList(); + log('Found ${printers.length} printers matching "$query"'); + + return printers; + } catch (e) { + log('Error searching printers: $e'); + return []; + } + } + + // Check if printer code exists + Future isPrinterCodeExists(String code, {int? excludeId}) async { + final db = await _db; + + try { + String whereClause = 'code = ?'; + List whereArgs = [code]; + + if (excludeId != null) { + whereClause += ' AND id != ?'; + whereArgs.add(excludeId); + } + + final result = await db.query( + 'printers', + where: whereClause, + whereArgs: whereArgs, + ); + + final exists = result.isNotEmpty; + log('Printer code "$code" exists: $exists'); + return exists; + } catch (e) { + log('Error checking printer code existence: $e'); + return false; + } + } + + // Get printer statistics + Future> getPrinterStats() async { + final db = await _db; + + try { + // Total count + final totalResult = + await db.rawQuery('SELECT COUNT(*) as total FROM printers'); + final totalCount = totalResult.first['total'] as int; + + // Count by type + final typeResult = await db.rawQuery(''' + SELECT type, COUNT(*) as count + FROM printers + WHERE type IS NOT NULL + GROUP BY type + '''); + + final typeStats = {}; + for (final row in typeResult) { + typeStats[row['type'] as String] = row['count'] as int; + } + + final stats = { + 'total_printers': totalCount, + 'by_type': typeStats, + }; + + log('Printer stats: $stats'); + return stats; + } catch (e) { + log('Error getting printer stats: $e'); + return { + 'total_printers': 0, + 'by_type': {}, + }; + } + } + + // Clear all printers (for testing/reset purposes) + Future clearAllPrinters() async { + final db = await _db; + + try { + log('Clearing all printers'); + await db.delete('printers'); + log('All printers cleared'); + } catch (e) { + log('Error clearing printers: $e'); + rethrow; + } + } + + // Batch insert printers + Future insertPrinters(List printers) async { + final db = await _db; + + try { + log('Batch inserting ${printers.length} printers'); + + await db.transaction((txn) async { + for (final printer in printers) { + await txn.insert( + 'printers', + printer.toMapForInsert(), + conflictAlgorithm: ConflictAlgorithm.replace, + ); + } + }); + + log('Successfully batch inserted ${printers.length} printers'); + } catch (e) { + log('Error batch inserting printers: $e'); + rethrow; + } + } +} diff --git a/lib/data/datasources/product_local_datasource.dart b/lib/data/datasources/product_local_datasource.dart deleted file mode 100644 index 6610f6e..0000000 --- a/lib/data/datasources/product_local_datasource.dart +++ /dev/null @@ -1,639 +0,0 @@ -import 'dart:developer'; -import 'dart:ui'; - -import 'package:enaklo_pos/data/models/response/print_model.dart'; -import 'package:enaklo_pos/data/models/response/product_response_model.dart'; -import 'package:enaklo_pos/data/models/response/table_model.dart'; -import 'package:enaklo_pos/presentation/home/models/order_model.dart'; -import 'package:enaklo_pos/presentation/table/models/draft_order_item.dart'; -import 'package:enaklo_pos/presentation/table/models/draft_order_model.dart'; -import 'package:sqflite/sqflite.dart'; - -import '../../presentation/home/models/product_quantity.dart'; - -class ProductLocalDatasource { - ProductLocalDatasource._init(); - - static final ProductLocalDatasource instance = ProductLocalDatasource._init(); - - final String tableProduct = 'products'; - final String tableOrder = 'orders'; - final String tableOrderItem = 'order_items'; - final String tableManagement = 'table_management'; - final String tablePrint = 'prints'; - static Database? _database; - - // "id": 1, - // "category_id": 1, - // "name": "Mie Ayam", - // "description": "Ipsa dolorem impedit dolor. Libero nisi quidem expedita quod mollitia ad. Voluptas ut quia nemo nisi odit fuga. Fugit autem qui ratione laborum eum.", - // "image": "https://via.placeholder.com/640x480.png/002200?text=nihil", - // "price": "2000.44", - // "stock": 94, - // "status": 1, - // "is_favorite": 1, - // "created_at": "2024-02-08T14:30:22.000000Z", - // "updated_at": "2024-02-08T15:14:22.000000Z" - - Future _createDb(Database db, int version) async { - await db.execute(''' - CREATE TABLE $tableProduct ( - id INTEGER PRIMARY KEY, - product_id INTEGER, - name TEXT, - printer_type TEXT, - categoryId INTEGER, - categoryName TEXT, - description TEXT, - image TEXT, - price TEXT, - stock INTEGER, - status INTEGER, - isFavorite INTEGER, - createdAt TEXT, - updatedAt TEXT - ) - '''); - - await db.execute(''' - CREATE TABLE $tableOrder ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - payment_amount INTEGER, - sub_total INTEGER, - tax INTEGER, - discount INTEGER, - discount_amount INTEGER, - service_charge INTEGER, - total INTEGER, - payment_method TEXT, - total_item INTEGER, - id_kasir INTEGER, - nama_kasir TEXT, - transaction_time TEXT, - table_number INTEGER, - customer_name TEXT, - status TEXT, - payment_status TEXT, - order_type TEXT DEFAULT 'DINE IN', - is_sync INTEGER DEFAULT 0 - ) - '''); - - await db.execute(''' - CREATE TABLE $tableOrderItem ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - id_order INTEGER, - id_product INTEGER, - quantity INTEGER, - price INTEGER, - notes TEXT DEFAULT '' - ) - '''); - - await db.execute(''' - CREATE TABLE $tableManagement ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - table_name Text, - start_time Text, - order_id INTEGER, - payment_amount INTEGER, - x_position REAL NOT NULL, - y_position REAL NOT NULL, - status TEXT - ) - '''); - - await db.execute(''' - CREATE TABLE draft_orders ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - total_item INTEGER, - subtotal INTEGER, - tax INTEGER, - discount INTEGER, - discount_amount INTEGER, - service_charge INTEGER, - total INTEGER, - transaction_time TEXT, - table_number INTEGER, - draft_name TEXT - ) - '''); - - await db.execute(''' - CREATE TABLE draft_order_items ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - id_draft_order INTEGER, - id_product INTEGER, - quantity INTEGER, - price INTEGER - ) - '''); - - await db.execute(''' - CREATE TABLE $tablePrint ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - code TEXT, - name TEXT, - address TEXT, - paper TEXT, - type TEXT - ) - '''); - } - - Future _initDB(String filePath) async { - final dbPath = await getDatabasesPath(); - final path = dbPath + filePath; - - // Force delete existing database to ensure new schema - try { - final dbExists = await databaseExists(path); - if (dbExists) { - log("Deleting existing database to ensure new schema with order_type column"); - // await deleteDatabase(path); - } - } catch (e) { - log("Error deleting database: $e"); - } - - return await openDatabase( - path, - version: 2, - onCreate: _createDb, - onUpgrade: _onUpgrade, - ); - } - - Future _onUpgrade(Database db, int oldVersion, int newVersion) async { - if (oldVersion < 2) { - // Add order_type column to orders table if it doesn't exist - try { - await db.execute( - 'ALTER TABLE $tableOrder ADD COLUMN order_type TEXT DEFAULT "DINE IN"'); - log("Added order_type column to orders table"); - } catch (e) { - log("order_type column might already exist: $e"); - } - } - } - - Future get database async { - if (_database != null) return _database!; - _database = await _initDB('dbresto36.db'); - return _database!; - } - - //save order - Future saveOrder(OrderModel order) async { - final db = await instance.database; - - // Since we're forcing database recreation, order_type column should exist - final orderMap = order.toMap(includeOrderType: true); - log("Final orderMap for insertion: $orderMap"); - - int id = await db.insert(tableOrder, orderMap, - conflictAlgorithm: ConflictAlgorithm.replace); - - for (var item in order.orderItems) { - log("Item: ${item.toLocalMap(id)}"); - await db.insert(tableOrderItem, item.toLocalMap(id), - conflictAlgorithm: ConflictAlgorithm.replace); - } - log("Success Order: ${order.toMap()}"); - return id; - } - - //get data order - Future> getOrderByIsNotSync() async { - final db = await instance.database; - final List> maps = - await db.query(tableOrder, where: 'is_sync = ?', whereArgs: [0]); - return List.generate(maps.length, (i) { - return OrderModel.fromMap(maps[i]); - }); - } - - Future> getAllOrder( - DateTime date, - ) async { - final db = await instance.database; - //date to iso8601 - final dateIso = date.toIso8601String(); - //get yyyy-MM-dd - final dateYYYYMMDD = dateIso.substring(0, 10); - // final formattedDate = DateFormat('yyyy-MM-dd').format(date); - final List> maps = await db.query( - tableOrder, - where: 'transaction_time like ?', - whereArgs: ['$dateYYYYMMDD%'], - // where: 'transaction_time BETWEEN ? AND ?', - // whereArgs: [ - // DateFormat.yMd().format(start), - // DateFormat.yMd().format(end) - // ], - ); - return List.generate(maps.length, (i) { - log("Save save OrderModel: ${OrderModel.fromMap(maps[i])}"); - return OrderModel.fromMap(maps[i]); - }); - } - - Future> getAllOrderByRange( - DateTime start, DateTime end) async { - final db = await instance.database; - - // Format ke ISO 8601 untuk range, hasil: yyyy-MM-ddTHH:mm:ss - final startIso = start.toIso8601String(); - final endIso = end.toIso8601String(); - - final startDateYYYYMMDD = startIso.substring(0, 10); - final endDateYYYYMMDD = endIso.substring(0, 10); - - final List> maps = await db.query( - tableOrder, - where: 'substr(transaction_time, 1, 10) BETWEEN ? AND ?', - whereArgs: [startDateYYYYMMDD, endDateYYYYMMDD], - orderBy: 'transaction_time DESC', - ); - log("Get All Order By Range: $startDateYYYYMMDD $endDateYYYYMMDD"); - - return List.generate(maps.length, (i) { - log("Save save OrderModel: ${OrderModel.fromMap(maps[i])}"); - return OrderModel.fromMap(maps[i]); - }); - } - - //get order item by order id - Future> getOrderItemByOrderId(int orderId) async { - final db = await instance.database; - final List> maps = await db - .query(tableOrderItem, where: 'id_order = ?', whereArgs: [orderId]); - return List.generate(maps.length, (i) { - log("ProductQuantity: ${ProductQuantity.fromLocalMap(maps[i])}"); - return ProductQuantity.fromLocalMap(maps[i]); - }); - } - - //update payment status by order id - Future updatePaymentStatus( - int orderId, String paymentStatus, String status) async { - final db = await instance.database; - await db.update( - tableOrder, {'payment_status': paymentStatus, 'status': status}, - where: 'id = ?', whereArgs: [orderId]); - log('update payment status success | order id: $orderId | payment status: $paymentStatus | status: $status'); - } - - //update order is sync - Future updateOrderIsSync(int orderId) async { - final db = await instance.database; - await db.update(tableOrder, {'is_sync': 1}, - where: 'id = ?', whereArgs: [orderId]); - } - - //insert data product - - Future insertProduct(Product product) async { - log("Product: ${product.toMap()}"); - final db = await instance.database; - await db.insert(tableProduct, product.toMap(), - conflictAlgorithm: ConflictAlgorithm.replace); - } - - //update product - Future updateProduct(Product product) async { - log("Update Product: ${product.toMap()}"); - final db = await instance.database; - await db.update( - tableProduct, - product.toLocalMap(), - where: 'product_id = ?', - whereArgs: [product.id], - ); - } - - //insert list of product - Future insertProducts(List products) async { - final db = await instance.database; - log("Save Products to Local"); - for (var product in products) { - await db.insert(tableProduct, product.toLocalMap(), - conflictAlgorithm: ConflictAlgorithm.replace); - log('inserted success id: ${product.id} | name: ${product.name} | price: ${product.price} '); - } - } - - //get all products - Future> getProducts() async { - final db = await instance.database; - final List> maps = await db.query(tableProduct); - return List.generate(maps.length, (i) { - return Product.fromLocalMap(maps[i]); - }); - } - - Future getProductById(int id) async { - final db = await instance.database; - final result = - await db.query(tableProduct, where: 'product_id = ?', whereArgs: [id]); - - if (result.isEmpty) { - return null; - } - - return Product.fromMap(result.first); - } - - // get Last Table Management - - Future getLastTableManagement() async { - final db = await instance.database; - final List> maps = - await db.query(tableManagement, orderBy: 'id DESC', limit: 1); - if (maps.isEmpty) { - return null; - } - return TableModel.fromMap(maps[0]); - } - - // generate table managent with count - Future createTableManagement(String tableName, Offset position) async { - // final db = await instance.database; - // TableModel newTable = TableModel( - // tableName: tableName, - // status: 'available', - // orderId: 0, - // paymentAmount: 0, - // startTime: DateTime.now().toIso8601String(), - // position: position, - // ); - // await db.insert( - // tableManagement, - // newTable.toMap(), - // ); - } - - // change position table - Future changePositionTable(int id, Offset position) async { - final db = await instance.database; - await db.update( - tableManagement, - {'x_position': position.dx, 'y_position': position.dy}, - where: 'id = ?', - whereArgs: [id], - ); - } - - // update table - Future updateTable(TableModel table) async { - final db = await instance.database; - await db.update( - tableManagement, - table.toMap(), - where: 'id = ?', - whereArgs: [table.id], - ); - } - - // get all table - Future> getAllTable() async { - final db = await instance.database; - final List> maps = await db.query(tableManagement); - log("Table Management: $maps"); - return List.generate(maps.length, (i) { - return TableModel.fromMap(maps[i]); - }); - } - - // get last order where table number - Future getLastOrderTable(int tableNumber) async { - final db = await instance.database; - final List> maps = await db.query( - tableOrder, - where: 'table_number = ?', - whereArgs: [tableNumber], - orderBy: 'id DESC', // Urutkan berdasarkan id dari yang terbesar (terbaru) - limit: 1, // Ambil hanya satu data terakhir - ); - - if (maps.isEmpty) { - return null; - } - - return OrderModel.fromMap(maps[0]); - } - - // get table by status - Future> getTableByStatus(String status) async { - final db = await instance.database; - List> maps; - - if (status == 'all') { - // Get all tables - maps = await db.query(tableManagement); - log("Getting all tables, found: ${maps.length}"); - - // If no tables exist, create some default tables - if (maps.isEmpty) { - log("No tables found, creating default tables..."); - await _createDefaultTables(); - maps = await db.query(tableManagement); - log("After creating default tables, found: ${maps.length}"); - } - } else { - // Get tables by specific status - maps = await db.query( - tableManagement, - where: 'status = ?', - whereArgs: [status], - ); - log("Getting tables with status '$status', found: ${maps.length}"); - } - - final tables = List.generate(maps.length, (i) { - return TableModel.fromMap(maps[i]); - }); - - log("Returning ${tables.length} tables"); - tables.forEach((table) { - log("Table: ${table.tableName} (ID: ${table.id}, Status: ${table.status})"); - }); - - return tables; - } - - // Create default tables if none exist - Future _createDefaultTables() async { - final db = await instance.database; - - // Create 5 default tables - for (int i = 1; i <= 5; i++) { - await db.insert(tableManagement, { - 'table_name': 'Table $i', - 'start_time': DateTime.now().toIso8601String(), - 'order_id': 0, - 'payment_amount': 0, - 'x_position': 100.0 + (i * 50.0), - 'y_position': 100.0 + (i * 50.0), - 'status': 'available', - }); - log("Created default table: Table $i"); - } - } - - // update status tabel - Future updateStatusTable(TableModel table) async { - log("Updating table status: ${table.toMap()}"); - final db = await instance.database; - await db.update(tableManagement, table.toMap(), - where: 'id = ?', whereArgs: [table.id]); - log("Success Update Status Table: ${table.toMap()}"); - - // Verify the update - final updatedTable = await db.query( - tableManagement, - where: 'id = ?', - whereArgs: [table.id], - ); - if (updatedTable.isNotEmpty) { - log("Verified table update: ${updatedTable.first}"); - } - } - - // Debug method to reset all tables to available status - Future resetAllTablesToAvailable() async { - log("Resetting all tables to available status..."); - final db = await instance.database; - await db.update( - tableManagement, - { - 'status': 'available', - 'order_id': 0, - 'payment_amount': 0, - 'start_time': DateTime.now().toIso8601String(), - }, - ); - log("All tables reset to available status"); - } - - //delete all products - Future deleteAllProducts() async { - final db = await instance.database; - await db.delete(tableProduct); - } - - Future saveDraftOrder(DraftOrderModel order) async { - log("save draft order: ${order.toMapForLocal()}"); - final db = await instance.database; - int id = await db.insert('draft_orders', order.toMapForLocal()); - log("draft order id: $id | ${order.discountAmount}"); - for (var orderItem in order.orders) { - await db.insert('draft_order_items', orderItem.toMapForLocal(id)); - log("draft order item ${orderItem.toMapForLocal(id)}"); - } - - return id; - } - - //get all draft order - Future> getAllDraftOrder() async { - final db = await instance.database; - final result = await db.query('draft_orders', orderBy: 'id ASC'); - - List results = await Future.wait(result.map((item) async { - // Your asynchronous operation here - final draftOrderItem = - await getDraftOrderItemByOrderId(item['id'] as int); - return DraftOrderModel.newFromLocalMap(item, draftOrderItem); - })); - return results; - } - - // get Darft Order by id - Future getDraftOrderById(int id) async { - final db = await instance.database; - final result = - await db.query('draft_orders', where: 'id = ?', whereArgs: [id]); - if (result.isEmpty) { - return null; - } - final draftOrderItem = - await getDraftOrderItemByOrderId(result.first['id'] as int); - log("draft order item: $draftOrderItem | ${result.first.toString()}"); - return DraftOrderModel.newFromLocalMap(result.first, draftOrderItem); - } - - //get draft order item by id order - Future> getDraftOrderItemByOrderId(int idOrder) async { - final db = await instance.database; - final result = - await db.query('draft_order_items', where: 'id_draft_order = $idOrder'); - - List results = await Future.wait(result.map((item) async { - // Your asynchronous operation here - final product = await getProductById(item['id_product'] as int); - return DraftOrderItem( - product: product!, quantity: item['quantity'] as int); - })); - return results; - } - - //remove draft order by id - Future removeDraftOrderById(int id) async { - final db = await instance.database; - await db.delete('draft_orders', where: 'id = ?', whereArgs: [id]); - await db.delete('draft_order_items', - where: 'id_draft_order = ?', whereArgs: [id]); - } - - //update draft order - Future updateDraftOrder(DraftOrderModel draftOrder) async { - final db = await instance.database; - - // Update the draft order - await db.update( - 'draft_orders', - draftOrder.toMapForLocal(), - where: 'id = ?', - whereArgs: [draftOrder.id], - ); - - // Remove existing items and add new ones - await db.delete('draft_order_items', - where: 'id_draft_order = ?', whereArgs: [draftOrder.id]); - - for (var orderItem in draftOrder.orders) { - await db.insert( - 'draft_order_items', orderItem.toMapForLocal(draftOrder.id!)); - } - } - - /// create printer - Future createPrinter(PrintModel print) async { - final db = await instance.database; - await db.insert(tablePrint, print.toMap()); - } - - Future updatePrinter(PrintModel print, int id) async { - final db = await instance.database; - log("Update Printer: ${print.toMap()} | id: $id"); - await db - .update(tablePrint, print.toMap(), where: 'id = ?', whereArgs: [id]); - } - - Future deletePrinter(int id) async { - final db = await instance.database; - await db.delete(tablePrint, where: 'id = ?', whereArgs: [id]); - } - - // get printer by code - Future getPrinterByCode(String code) async { - final db = await instance.database; - final result = - await db.query(tablePrint, where: 'code = ?', whereArgs: [code]); - if (result.isEmpty) { - return null; - } - return PrintModel.fromMap(result.first); - } -} diff --git a/lib/data/models/response/print_model.dart b/lib/data/models/response/print_model.dart index 7bdee3b..1f1db6c 100644 --- a/lib/data/models/response/print_model.dart +++ b/lib/data/models/response/print_model.dart @@ -5,6 +5,8 @@ class PrintModel { final String address; final String paper; final String type; + final DateTime? createdAt; + final DateTime? updatedAt; PrintModel({ this.id, @@ -13,26 +15,130 @@ class PrintModel { required this.address, required this.paper, required this.type, + this.createdAt, + this.updatedAt, }); - // from map + // Factory constructor from map (updated) factory PrintModel.fromMap(Map map) { return PrintModel( - id: map['id'], - code: map['code'], - name: map['name'], - address: map['address'], - paper: map['paper'], - type: map['type'], + id: map['id'] as int?, + code: map['code'] as String, + name: map['name'] as String, + address: map['address'] as String, + paper: map['paper'] as String, + type: map['type'] as String, + createdAt: map['created_at'] != null + ? DateTime.tryParse(map['created_at'] as String) + : null, + updatedAt: map['updated_at'] != null + ? DateTime.tryParse(map['updated_at'] as String) + : null, ); } - // to map - Map toMap() => { - "code": code, - "name": name, - "address": address, - "paper": paper, - "type": type, - }; + // Convert to map for database insertion (without id, with timestamps) + Map toMapForInsert() { + final now = DateTime.now().toIso8601String(); + return { + 'code': code, + 'name': name, + 'address': address, + 'paper': paper, + 'type': type, + 'created_at': now, + 'updated_at': now, + }; + } + + // Convert to map for database update (without id and created_at) + Map toMapForUpdate() { + return { + 'code': code, + 'name': name, + 'address': address, + 'paper': paper, + 'type': type, + 'updated_at': DateTime.now().toIso8601String(), + }; + } + + // Convert to complete map (original method, enhanced) + Map toMap() { + return { + if (id != null) 'id': id, + 'code': code, + 'name': name, + 'address': address, + 'paper': paper, + 'type': type, + if (createdAt != null) 'created_at': createdAt!.toIso8601String(), + if (updatedAt != null) 'updated_at': updatedAt!.toIso8601String(), + }; + } + + // Copy with method for creating modified instances + PrintModel copyWith({ + int? id, + String? code, + String? name, + String? address, + String? paper, + String? type, + DateTime? createdAt, + DateTime? updatedAt, + }) { + return PrintModel( + id: id ?? this.id, + code: code ?? this.code, + name: name ?? this.name, + address: address ?? this.address, + paper: paper ?? this.paper, + type: type ?? this.type, + createdAt: createdAt ?? this.createdAt, + updatedAt: updatedAt ?? this.updatedAt, + ); + } + + // Equality and hashCode + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + return other is PrintModel && + other.id == id && + other.code == code && + other.name == name && + other.address == address && + other.paper == paper && + other.type == type; + } + + @override + int get hashCode { + return Object.hash(id, code, name, address, paper, type); + } + + // String representation for debugging (matches datasource logging) + @override + String toString() { + return 'PrintModel(id: $id, code: $code, name: $name, address: $address, paper: $paper, type: $type, createdAt: $createdAt, updatedAt: $updatedAt)'; + } + + // Validation methods + bool get isValid { + return code.isNotEmpty && + name.isNotEmpty && + address.isNotEmpty && + paper.isNotEmpty && + type.isNotEmpty; + } + + String? get validationError { + if (code.isEmpty) return 'Printer code cannot be empty'; + if (name.isEmpty) return 'Printer name cannot be empty'; + if (address.isEmpty) return 'Printer address cannot be empty'; + if (paper.isEmpty) return 'Paper size cannot be empty'; + if (type.isEmpty) return 'Printer type cannot be empty'; + return null; + } } diff --git a/lib/main.dart b/lib/main.dart index 4c6074b..1fee13d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -38,7 +38,6 @@ import 'package:enaklo_pos/data/datasources/category_remote_datasource.dart'; import 'package:enaklo_pos/data/datasources/discount_remote_datasource.dart'; import 'package:enaklo_pos/data/datasources/midtrans_remote_datasource.dart'; import 'package:enaklo_pos/data/datasources/order_remote_datasource.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; import 'package:enaklo_pos/data/datasources/product_remote_datasource.dart'; import 'package:enaklo_pos/data/datasources/payment_methods_remote_datasource.dart'; import 'package:enaklo_pos/data/datasources/settings_local_datasource.dart'; @@ -48,14 +47,11 @@ import 'package:enaklo_pos/presentation/home/bloc/get_table_status/get_table_sta import 'package:enaklo_pos/presentation/home/bloc/online_checker/online_checker_bloc.dart'; import 'package:enaklo_pos/presentation/home/bloc/payment_methods/payment_methods_bloc.dart'; import 'package:enaklo_pos/presentation/home/bloc/qris/qris_bloc.dart'; -import 'package:enaklo_pos/presentation/home/bloc/status_table/status_table_bloc.dart'; import 'package:enaklo_pos/presentation/home/bloc/checkout/checkout_bloc.dart'; import 'package:enaklo_pos/presentation/report/blocs/item_sales_report/item_sales_report_bloc.dart'; import 'package:enaklo_pos/presentation/report/blocs/payment_method_report/payment_method_report_bloc.dart'; import 'package:enaklo_pos/presentation/report/blocs/product_sales/product_sales_bloc.dart'; import 'package:enaklo_pos/presentation/report/blocs/summary/summary_bloc.dart'; -import 'package:enaklo_pos/presentation/sales/blocs/bloc/last_order_table_bloc.dart'; -import 'package:enaklo_pos/presentation/sales/blocs/day_sales/day_sales_bloc.dart'; import 'package:enaklo_pos/presentation/setting/bloc/add_product/add_product_bloc.dart'; import 'package:enaklo_pos/presentation/setting/bloc/create_printer/create_printer_bloc.dart'; import 'package:enaklo_pos/presentation/setting/bloc/get_categories/get_categories_bloc.dart'; @@ -69,12 +65,10 @@ import 'package:enaklo_pos/presentation/setting/bloc/update_printer/update_print import 'package:enaklo_pos/presentation/table/blocs/change_position_table/change_position_table_bloc.dart'; import 'package:enaklo_pos/presentation/table/blocs/create_table/create_table_bloc.dart'; import 'package:enaklo_pos/presentation/table/blocs/get_table/get_table_bloc.dart'; -import 'package:enaklo_pos/presentation/home/bloc/local_product/local_product_bloc.dart'; import 'package:enaklo_pos/presentation/home/bloc/order/order_bloc.dart'; import 'package:enaklo_pos/presentation/report/blocs/transaction_report/transaction_report_bloc.dart'; import 'package:enaklo_pos/presentation/setting/bloc/add_discount/add_discount_bloc.dart'; import 'package:enaklo_pos/presentation/setting/bloc/discount/discount_bloc.dart'; -import 'package:enaklo_pos/presentation/setting/bloc/sync_order/sync_order_bloc.dart'; import 'package:enaklo_pos/presentation/setting/bloc/sync_product/sync_product_bloc.dart'; import 'package:enaklo_pos/presentation/setting/bloc/tax_settings/tax_settings_bloc.dart'; import 'package:enaklo_pos/presentation/table/blocs/update_table/update_table_bloc.dart'; @@ -148,10 +142,6 @@ class _MyAppState extends State { BlocProvider( create: (context) => SyncProductBloc(ProductRemoteDatasource()), ), - BlocProvider( - create: (context) => - LocalProductBloc(ProductLocalDatasource.instance), - ), BlocProvider( create: (context) => CheckoutBloc(settingsLocalDatasource: SettingsLocalDatasource()), @@ -165,9 +155,6 @@ class _MyAppState extends State { return OrderBloc(OrderRemoteDatasource()); }, ), - BlocProvider( - create: (context) => SyncOrderBloc(OrderRemoteDatasource()), - ), BlocProvider( create: (context) => DiscountBloc(DiscountRemoteDatasource()), ), @@ -189,13 +176,6 @@ class _MyAppState extends State { BlocProvider( create: (context) => UpdateTableBloc(), ), - BlocProvider( - create: (context) => StatusTableBloc(ProductLocalDatasource.instance), - ), - BlocProvider( - create: (context) => - LastOrderTableBloc(ProductLocalDatasource.instance), - ), BlocProvider( create: (context) => GetTableStatusBloc(TableRemoteDataSource()), ), @@ -227,9 +207,6 @@ class _MyAppState extends State { create: (context) => PaymentMethodReportBloc(AnalyticRemoteDatasource()), ), - BlocProvider( - create: (context) => DaySalesBloc(ProductLocalDatasource.instance), - ), BlocProvider( create: (context) => QrisBloc(MidtransRemoteDatasource()), ), diff --git a/lib/presentation/home/bloc/checkout/checkout_bloc.dart b/lib/presentation/home/bloc/checkout/checkout_bloc.dart index 0d41cd3..aad8d60 100644 --- a/lib/presentation/home/bloc/checkout/checkout_bloc.dart +++ b/lib/presentation/home/bloc/checkout/checkout_bloc.dart @@ -1,7 +1,6 @@ import 'dart:developer'; import 'package:bloc/bloc.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; import 'package:enaklo_pos/data/models/response/delivery_response_model.dart'; import 'package:enaklo_pos/data/models/response/discount_response_model.dart'; import 'package:enaklo_pos/presentation/table/models/draft_order_item.dart'; @@ -310,9 +309,9 @@ class CheckoutBloc extends Bloc { DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now()), ); log("draftOrder12: ${draftOrder.toMapForLocal()}"); - final orderDraftId = - await ProductLocalDatasource.instance.saveDraftOrder(draftOrder); - emit(_SavedDraftOrder(orderDraftId)); + // final orderDraftId = + // await ProductLocalDatasource.instance.saveDraftOrder(draftOrder); + emit(_SavedDraftOrder(0)); }); //load draft order diff --git a/lib/presentation/home/bloc/local_product/local_product_bloc.dart b/lib/presentation/home/bloc/local_product/local_product_bloc.dart deleted file mode 100644 index 2c1eac7..0000000 --- a/lib/presentation/home/bloc/local_product/local_product_bloc.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'dart:developer'; - -import 'package:bloc/bloc.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; - -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; - -import '../../../../data/models/response/product_response_model.dart'; - -part 'local_product_bloc.freezed.dart'; -part 'local_product_event.dart'; -part 'local_product_state.dart'; - -class LocalProductBloc extends Bloc { - final ProductLocalDatasource productLocalDatasource; - LocalProductBloc( - this.productLocalDatasource, - ) : super(const _Initial()) { - on<_GetLocalProduct>((event, emit) async { - emit(const _Loading()); - final result = await productLocalDatasource.getProducts(); - log("Result: ${result.length}"); - emit(_Loaded(result)); - }); - } -} diff --git a/lib/presentation/home/bloc/local_product/local_product_bloc.freezed.dart b/lib/presentation/home/bloc/local_product/local_product_bloc.freezed.dart deleted file mode 100644 index d1ecbde..0000000 --- a/lib/presentation/home/bloc/local_product/local_product_bloc.freezed.dart +++ /dev/null @@ -1,907 +0,0 @@ -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'local_product_bloc.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - -/// @nodoc -mixin _$LocalProductEvent { - @optionalTypeArgs - TResult when({ - required TResult Function() started, - required TResult Function() getLocalProduct, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? started, - TResult? Function()? getLocalProduct, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? started, - TResult Function()? getLocalProduct, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(_Started value) started, - required TResult Function(_GetLocalProduct value) getLocalProduct, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Started value)? started, - TResult? Function(_GetLocalProduct value)? getLocalProduct, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Started value)? started, - TResult Function(_GetLocalProduct value)? getLocalProduct, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $LocalProductEventCopyWith<$Res> { - factory $LocalProductEventCopyWith( - LocalProductEvent value, $Res Function(LocalProductEvent) then) = - _$LocalProductEventCopyWithImpl<$Res, LocalProductEvent>; -} - -/// @nodoc -class _$LocalProductEventCopyWithImpl<$Res, $Val extends LocalProductEvent> - implements $LocalProductEventCopyWith<$Res> { - _$LocalProductEventCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of LocalProductEvent - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc -abstract class _$$StartedImplCopyWith<$Res> { - factory _$$StartedImplCopyWith( - _$StartedImpl value, $Res Function(_$StartedImpl) then) = - __$$StartedImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$StartedImplCopyWithImpl<$Res> - extends _$LocalProductEventCopyWithImpl<$Res, _$StartedImpl> - implements _$$StartedImplCopyWith<$Res> { - __$$StartedImplCopyWithImpl( - _$StartedImpl _value, $Res Function(_$StartedImpl) _then) - : super(_value, _then); - - /// Create a copy of LocalProductEvent - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$StartedImpl implements _Started { - const _$StartedImpl(); - - @override - String toString() { - return 'LocalProductEvent.started()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$StartedImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() started, - required TResult Function() getLocalProduct, - }) { - return started(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? started, - TResult? Function()? getLocalProduct, - }) { - return started?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? started, - TResult Function()? getLocalProduct, - required TResult orElse(), - }) { - if (started != null) { - return started(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Started value) started, - required TResult Function(_GetLocalProduct value) getLocalProduct, - }) { - return started(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Started value)? started, - TResult? Function(_GetLocalProduct value)? getLocalProduct, - }) { - return started?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Started value)? started, - TResult Function(_GetLocalProduct value)? getLocalProduct, - required TResult orElse(), - }) { - if (started != null) { - return started(this); - } - return orElse(); - } -} - -abstract class _Started implements LocalProductEvent { - const factory _Started() = _$StartedImpl; -} - -/// @nodoc -abstract class _$$GetLocalProductImplCopyWith<$Res> { - factory _$$GetLocalProductImplCopyWith(_$GetLocalProductImpl value, - $Res Function(_$GetLocalProductImpl) then) = - __$$GetLocalProductImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$GetLocalProductImplCopyWithImpl<$Res> - extends _$LocalProductEventCopyWithImpl<$Res, _$GetLocalProductImpl> - implements _$$GetLocalProductImplCopyWith<$Res> { - __$$GetLocalProductImplCopyWithImpl( - _$GetLocalProductImpl _value, $Res Function(_$GetLocalProductImpl) _then) - : super(_value, _then); - - /// Create a copy of LocalProductEvent - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$GetLocalProductImpl implements _GetLocalProduct { - const _$GetLocalProductImpl(); - - @override - String toString() { - return 'LocalProductEvent.getLocalProduct()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$GetLocalProductImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() started, - required TResult Function() getLocalProduct, - }) { - return getLocalProduct(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? started, - TResult? Function()? getLocalProduct, - }) { - return getLocalProduct?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? started, - TResult Function()? getLocalProduct, - required TResult orElse(), - }) { - if (getLocalProduct != null) { - return getLocalProduct(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Started value) started, - required TResult Function(_GetLocalProduct value) getLocalProduct, - }) { - return getLocalProduct(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Started value)? started, - TResult? Function(_GetLocalProduct value)? getLocalProduct, - }) { - return getLocalProduct?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Started value)? started, - TResult Function(_GetLocalProduct value)? getLocalProduct, - required TResult orElse(), - }) { - if (getLocalProduct != null) { - return getLocalProduct(this); - } - return orElse(); - } -} - -abstract class _GetLocalProduct implements LocalProductEvent { - const factory _GetLocalProduct() = _$GetLocalProductImpl; -} - -/// @nodoc -mixin _$LocalProductState { - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function(List products) loaded, - required TResult Function(String message) error, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function(List products)? loaded, - TResult? Function(String message)? error, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function(List products)? loaded, - TResult Function(String message)? error, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Loaded value) loaded, - required TResult Function(_Error value) error, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Loaded value)? loaded, - TResult? Function(_Error value)? error, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Loaded value)? loaded, - TResult Function(_Error value)? error, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $LocalProductStateCopyWith<$Res> { - factory $LocalProductStateCopyWith( - LocalProductState value, $Res Function(LocalProductState) then) = - _$LocalProductStateCopyWithImpl<$Res, LocalProductState>; -} - -/// @nodoc -class _$LocalProductStateCopyWithImpl<$Res, $Val extends LocalProductState> - implements $LocalProductStateCopyWith<$Res> { - _$LocalProductStateCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of LocalProductState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc -abstract class _$$InitialImplCopyWith<$Res> { - factory _$$InitialImplCopyWith( - _$InitialImpl value, $Res Function(_$InitialImpl) then) = - __$$InitialImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$InitialImplCopyWithImpl<$Res> - extends _$LocalProductStateCopyWithImpl<$Res, _$InitialImpl> - implements _$$InitialImplCopyWith<$Res> { - __$$InitialImplCopyWithImpl( - _$InitialImpl _value, $Res Function(_$InitialImpl) _then) - : super(_value, _then); - - /// Create a copy of LocalProductState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$InitialImpl implements _Initial { - const _$InitialImpl(); - - @override - String toString() { - return 'LocalProductState.initial()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$InitialImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function(List products) loaded, - required TResult Function(String message) error, - }) { - return initial(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function(List products)? loaded, - TResult? Function(String message)? error, - }) { - return initial?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function(List products)? loaded, - TResult Function(String message)? error, - required TResult orElse(), - }) { - if (initial != null) { - return initial(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Loaded value) loaded, - required TResult Function(_Error value) error, - }) { - return initial(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Loaded value)? loaded, - TResult? Function(_Error value)? error, - }) { - return initial?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Loaded value)? loaded, - TResult Function(_Error value)? error, - required TResult orElse(), - }) { - if (initial != null) { - return initial(this); - } - return orElse(); - } -} - -abstract class _Initial implements LocalProductState { - const factory _Initial() = _$InitialImpl; -} - -/// @nodoc -abstract class _$$LoadingImplCopyWith<$Res> { - factory _$$LoadingImplCopyWith( - _$LoadingImpl value, $Res Function(_$LoadingImpl) then) = - __$$LoadingImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$LoadingImplCopyWithImpl<$Res> - extends _$LocalProductStateCopyWithImpl<$Res, _$LoadingImpl> - implements _$$LoadingImplCopyWith<$Res> { - __$$LoadingImplCopyWithImpl( - _$LoadingImpl _value, $Res Function(_$LoadingImpl) _then) - : super(_value, _then); - - /// Create a copy of LocalProductState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$LoadingImpl implements _Loading { - const _$LoadingImpl(); - - @override - String toString() { - return 'LocalProductState.loading()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$LoadingImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function(List products) loaded, - required TResult Function(String message) error, - }) { - return loading(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function(List products)? loaded, - TResult? Function(String message)? error, - }) { - return loading?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function(List products)? loaded, - TResult Function(String message)? error, - required TResult orElse(), - }) { - if (loading != null) { - return loading(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Loaded value) loaded, - required TResult Function(_Error value) error, - }) { - return loading(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Loaded value)? loaded, - TResult? Function(_Error value)? error, - }) { - return loading?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Loaded value)? loaded, - TResult Function(_Error value)? error, - required TResult orElse(), - }) { - if (loading != null) { - return loading(this); - } - return orElse(); - } -} - -abstract class _Loading implements LocalProductState { - const factory _Loading() = _$LoadingImpl; -} - -/// @nodoc -abstract class _$$LoadedImplCopyWith<$Res> { - factory _$$LoadedImplCopyWith( - _$LoadedImpl value, $Res Function(_$LoadedImpl) then) = - __$$LoadedImplCopyWithImpl<$Res>; - @useResult - $Res call({List products}); -} - -/// @nodoc -class __$$LoadedImplCopyWithImpl<$Res> - extends _$LocalProductStateCopyWithImpl<$Res, _$LoadedImpl> - implements _$$LoadedImplCopyWith<$Res> { - __$$LoadedImplCopyWithImpl( - _$LoadedImpl _value, $Res Function(_$LoadedImpl) _then) - : super(_value, _then); - - /// Create a copy of LocalProductState - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? products = null, - }) { - return _then(_$LoadedImpl( - null == products - ? _value._products - : products // ignore: cast_nullable_to_non_nullable - as List, - )); - } -} - -/// @nodoc - -class _$LoadedImpl implements _Loaded { - const _$LoadedImpl(final List products) : _products = products; - - final List _products; - @override - List get products { - if (_products is EqualUnmodifiableListView) return _products; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_products); - } - - @override - String toString() { - return 'LocalProductState.loaded(products: $products)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$LoadedImpl && - const DeepCollectionEquality().equals(other._products, _products)); - } - - @override - int get hashCode => - Object.hash(runtimeType, const DeepCollectionEquality().hash(_products)); - - /// Create a copy of LocalProductState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$LoadedImplCopyWith<_$LoadedImpl> get copyWith => - __$$LoadedImplCopyWithImpl<_$LoadedImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function(List products) loaded, - required TResult Function(String message) error, - }) { - return loaded(products); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function(List products)? loaded, - TResult? Function(String message)? error, - }) { - return loaded?.call(products); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function(List products)? loaded, - TResult Function(String message)? error, - required TResult orElse(), - }) { - if (loaded != null) { - return loaded(products); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Loaded value) loaded, - required TResult Function(_Error value) error, - }) { - return loaded(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Loaded value)? loaded, - TResult? Function(_Error value)? error, - }) { - return loaded?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Loaded value)? loaded, - TResult Function(_Error value)? error, - required TResult orElse(), - }) { - if (loaded != null) { - return loaded(this); - } - return orElse(); - } -} - -abstract class _Loaded implements LocalProductState { - const factory _Loaded(final List products) = _$LoadedImpl; - - List get products; - - /// Create a copy of LocalProductState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - _$$LoadedImplCopyWith<_$LoadedImpl> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class _$$ErrorImplCopyWith<$Res> { - factory _$$ErrorImplCopyWith( - _$ErrorImpl value, $Res Function(_$ErrorImpl) then) = - __$$ErrorImplCopyWithImpl<$Res>; - @useResult - $Res call({String message}); -} - -/// @nodoc -class __$$ErrorImplCopyWithImpl<$Res> - extends _$LocalProductStateCopyWithImpl<$Res, _$ErrorImpl> - implements _$$ErrorImplCopyWith<$Res> { - __$$ErrorImplCopyWithImpl( - _$ErrorImpl _value, $Res Function(_$ErrorImpl) _then) - : super(_value, _then); - - /// Create a copy of LocalProductState - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? message = null, - }) { - return _then(_$ErrorImpl( - null == message - ? _value.message - : message // ignore: cast_nullable_to_non_nullable - as String, - )); - } -} - -/// @nodoc - -class _$ErrorImpl implements _Error { - const _$ErrorImpl(this.message); - - @override - final String message; - - @override - String toString() { - return 'LocalProductState.error(message: $message)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$ErrorImpl && - (identical(other.message, message) || other.message == message)); - } - - @override - int get hashCode => Object.hash(runtimeType, message); - - /// Create a copy of LocalProductState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$ErrorImplCopyWith<_$ErrorImpl> get copyWith => - __$$ErrorImplCopyWithImpl<_$ErrorImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function(List products) loaded, - required TResult Function(String message) error, - }) { - return error(message); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function(List products)? loaded, - TResult? Function(String message)? error, - }) { - return error?.call(message); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function(List products)? loaded, - TResult Function(String message)? error, - required TResult orElse(), - }) { - if (error != null) { - return error(message); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Loaded value) loaded, - required TResult Function(_Error value) error, - }) { - return error(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Loaded value)? loaded, - TResult? Function(_Error value)? error, - }) { - return error?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Loaded value)? loaded, - TResult Function(_Error value)? error, - required TResult orElse(), - }) { - if (error != null) { - return error(this); - } - return orElse(); - } -} - -abstract class _Error implements LocalProductState { - const factory _Error(final String message) = _$ErrorImpl; - - String get message; - - /// Create a copy of LocalProductState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - _$$ErrorImplCopyWith<_$ErrorImpl> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/lib/presentation/home/bloc/local_product/local_product_event.dart b/lib/presentation/home/bloc/local_product/local_product_event.dart deleted file mode 100644 index cd293d6..0000000 --- a/lib/presentation/home/bloc/local_product/local_product_event.dart +++ /dev/null @@ -1,7 +0,0 @@ -part of 'local_product_bloc.dart'; - -@freezed -class LocalProductEvent with _$LocalProductEvent { - const factory LocalProductEvent.started() = _Started; - const factory LocalProductEvent.getLocalProduct() = _GetLocalProduct; -} \ No newline at end of file diff --git a/lib/presentation/home/bloc/local_product/local_product_state.dart b/lib/presentation/home/bloc/local_product/local_product_state.dart deleted file mode 100644 index b350e30..0000000 --- a/lib/presentation/home/bloc/local_product/local_product_state.dart +++ /dev/null @@ -1,9 +0,0 @@ -part of 'local_product_bloc.dart'; - -@freezed -class LocalProductState with _$LocalProductState { - const factory LocalProductState.initial() = _Initial; - const factory LocalProductState.loading() = _Loading; - const factory LocalProductState.loaded(List products) = _Loaded; - const factory LocalProductState.error(String message) = _Error; -} diff --git a/lib/presentation/home/bloc/order/order_bloc.dart b/lib/presentation/home/bloc/order/order_bloc.dart index 9aaa63f..50756fe 100644 --- a/lib/presentation/home/bloc/order/order_bloc.dart +++ b/lib/presentation/home/bloc/order/order_bloc.dart @@ -5,7 +5,6 @@ import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:enaklo_pos/data/datasources/auth_local_datasource.dart'; import 'package:enaklo_pos/data/datasources/order_remote_datasource.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; import '../../models/order_model.dart'; import '../../models/product_quantity.dart'; @@ -78,13 +77,13 @@ class OrderBloc extends Bloc { value = false; } int id = 0; - if (value) { - id = await ProductLocalDatasource.instance - .saveOrder(dataInput.copyWith(isSync: 1)); - } else { - id = await ProductLocalDatasource.instance - .saveOrder(dataInput.copyWith(isSync: 1)); - } + // if (value) { + // id = await ProductLocalDatasource.instance + // .saveOrder(dataInput.copyWith(isSync: 1)); + // } else { + // id = await ProductLocalDatasource.instance + // .saveOrder(dataInput.copyWith(isSync: 1)); + // } emit(_Loaded( dataInput, diff --git a/lib/presentation/home/bloc/status_table/status_table_bloc.dart b/lib/presentation/home/bloc/status_table/status_table_bloc.dart deleted file mode 100644 index 840fb4b..0000000 --- a/lib/presentation/home/bloc/status_table/status_table_bloc.dart +++ /dev/null @@ -1,19 +0,0 @@ -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; -import 'package:enaklo_pos/data/models/response/table_model.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'status_table_event.dart'; -part 'status_table_state.dart'; -part 'status_table_bloc.freezed.dart'; - -class StatusTableBloc extends Bloc { - final ProductLocalDatasource datasource; - StatusTableBloc(this.datasource) : super(StatusTableState.initial()) { - on<_StatusTable>((event, emit) async { - emit(_Loading()); - await datasource.updateStatusTable(event.table); - emit(_Success()); - }); - } -} diff --git a/lib/presentation/home/bloc/status_table/status_table_bloc.freezed.dart b/lib/presentation/home/bloc/status_table/status_table_bloc.freezed.dart deleted file mode 100644 index 65bfc1a..0000000 --- a/lib/presentation/home/bloc/status_table/status_table_bloc.freezed.dart +++ /dev/null @@ -1,725 +0,0 @@ -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'status_table_bloc.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - -/// @nodoc -mixin _$StatusTableEvent { - @optionalTypeArgs - TResult when({ - required TResult Function() started, - required TResult Function(TableModel table) statusTabel, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? started, - TResult? Function(TableModel table)? statusTabel, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? started, - TResult Function(TableModel table)? statusTabel, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(_Started value) started, - required TResult Function(_StatusTable value) statusTabel, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Started value)? started, - TResult? Function(_StatusTable value)? statusTabel, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Started value)? started, - TResult Function(_StatusTable value)? statusTabel, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $StatusTableEventCopyWith<$Res> { - factory $StatusTableEventCopyWith( - StatusTableEvent value, $Res Function(StatusTableEvent) then) = - _$StatusTableEventCopyWithImpl<$Res, StatusTableEvent>; -} - -/// @nodoc -class _$StatusTableEventCopyWithImpl<$Res, $Val extends StatusTableEvent> - implements $StatusTableEventCopyWith<$Res> { - _$StatusTableEventCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of StatusTableEvent - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc -abstract class _$$StartedImplCopyWith<$Res> { - factory _$$StartedImplCopyWith( - _$StartedImpl value, $Res Function(_$StartedImpl) then) = - __$$StartedImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$StartedImplCopyWithImpl<$Res> - extends _$StatusTableEventCopyWithImpl<$Res, _$StartedImpl> - implements _$$StartedImplCopyWith<$Res> { - __$$StartedImplCopyWithImpl( - _$StartedImpl _value, $Res Function(_$StartedImpl) _then) - : super(_value, _then); - - /// Create a copy of StatusTableEvent - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$StartedImpl implements _Started { - const _$StartedImpl(); - - @override - String toString() { - return 'StatusTableEvent.started()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$StartedImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() started, - required TResult Function(TableModel table) statusTabel, - }) { - return started(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? started, - TResult? Function(TableModel table)? statusTabel, - }) { - return started?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? started, - TResult Function(TableModel table)? statusTabel, - required TResult orElse(), - }) { - if (started != null) { - return started(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Started value) started, - required TResult Function(_StatusTable value) statusTabel, - }) { - return started(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Started value)? started, - TResult? Function(_StatusTable value)? statusTabel, - }) { - return started?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Started value)? started, - TResult Function(_StatusTable value)? statusTabel, - required TResult orElse(), - }) { - if (started != null) { - return started(this); - } - return orElse(); - } -} - -abstract class _Started implements StatusTableEvent { - const factory _Started() = _$StartedImpl; -} - -/// @nodoc -abstract class _$$StatusTableImplCopyWith<$Res> { - factory _$$StatusTableImplCopyWith( - _$StatusTableImpl value, $Res Function(_$StatusTableImpl) then) = - __$$StatusTableImplCopyWithImpl<$Res>; - @useResult - $Res call({TableModel table}); -} - -/// @nodoc -class __$$StatusTableImplCopyWithImpl<$Res> - extends _$StatusTableEventCopyWithImpl<$Res, _$StatusTableImpl> - implements _$$StatusTableImplCopyWith<$Res> { - __$$StatusTableImplCopyWithImpl( - _$StatusTableImpl _value, $Res Function(_$StatusTableImpl) _then) - : super(_value, _then); - - /// Create a copy of StatusTableEvent - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? table = null, - }) { - return _then(_$StatusTableImpl( - null == table - ? _value.table - : table // ignore: cast_nullable_to_non_nullable - as TableModel, - )); - } -} - -/// @nodoc - -class _$StatusTableImpl implements _StatusTable { - const _$StatusTableImpl(this.table); - - @override - final TableModel table; - - @override - String toString() { - return 'StatusTableEvent.statusTabel(table: $table)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$StatusTableImpl && - (identical(other.table, table) || other.table == table)); - } - - @override - int get hashCode => Object.hash(runtimeType, table); - - /// Create a copy of StatusTableEvent - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$StatusTableImplCopyWith<_$StatusTableImpl> get copyWith => - __$$StatusTableImplCopyWithImpl<_$StatusTableImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() started, - required TResult Function(TableModel table) statusTabel, - }) { - return statusTabel(table); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? started, - TResult? Function(TableModel table)? statusTabel, - }) { - return statusTabel?.call(table); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? started, - TResult Function(TableModel table)? statusTabel, - required TResult orElse(), - }) { - if (statusTabel != null) { - return statusTabel(table); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Started value) started, - required TResult Function(_StatusTable value) statusTabel, - }) { - return statusTabel(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Started value)? started, - TResult? Function(_StatusTable value)? statusTabel, - }) { - return statusTabel?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Started value)? started, - TResult Function(_StatusTable value)? statusTabel, - required TResult orElse(), - }) { - if (statusTabel != null) { - return statusTabel(this); - } - return orElse(); - } -} - -abstract class _StatusTable implements StatusTableEvent { - const factory _StatusTable(final TableModel table) = _$StatusTableImpl; - - TableModel get table; - - /// Create a copy of StatusTableEvent - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - _$$StatusTableImplCopyWith<_$StatusTableImpl> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -mixin _$StatusTableState { - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function() success, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function()? success, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function()? success, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Success value) success, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Success value)? success, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Success value)? success, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $StatusTableStateCopyWith<$Res> { - factory $StatusTableStateCopyWith( - StatusTableState value, $Res Function(StatusTableState) then) = - _$StatusTableStateCopyWithImpl<$Res, StatusTableState>; -} - -/// @nodoc -class _$StatusTableStateCopyWithImpl<$Res, $Val extends StatusTableState> - implements $StatusTableStateCopyWith<$Res> { - _$StatusTableStateCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of StatusTableState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc -abstract class _$$InitialImplCopyWith<$Res> { - factory _$$InitialImplCopyWith( - _$InitialImpl value, $Res Function(_$InitialImpl) then) = - __$$InitialImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$InitialImplCopyWithImpl<$Res> - extends _$StatusTableStateCopyWithImpl<$Res, _$InitialImpl> - implements _$$InitialImplCopyWith<$Res> { - __$$InitialImplCopyWithImpl( - _$InitialImpl _value, $Res Function(_$InitialImpl) _then) - : super(_value, _then); - - /// Create a copy of StatusTableState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$InitialImpl implements _Initial { - const _$InitialImpl(); - - @override - String toString() { - return 'StatusTableState.initial()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$InitialImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function() success, - }) { - return initial(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function()? success, - }) { - return initial?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function()? success, - required TResult orElse(), - }) { - if (initial != null) { - return initial(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Success value) success, - }) { - return initial(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Success value)? success, - }) { - return initial?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Success value)? success, - required TResult orElse(), - }) { - if (initial != null) { - return initial(this); - } - return orElse(); - } -} - -abstract class _Initial implements StatusTableState { - const factory _Initial() = _$InitialImpl; -} - -/// @nodoc -abstract class _$$LoadingImplCopyWith<$Res> { - factory _$$LoadingImplCopyWith( - _$LoadingImpl value, $Res Function(_$LoadingImpl) then) = - __$$LoadingImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$LoadingImplCopyWithImpl<$Res> - extends _$StatusTableStateCopyWithImpl<$Res, _$LoadingImpl> - implements _$$LoadingImplCopyWith<$Res> { - __$$LoadingImplCopyWithImpl( - _$LoadingImpl _value, $Res Function(_$LoadingImpl) _then) - : super(_value, _then); - - /// Create a copy of StatusTableState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$LoadingImpl implements _Loading { - const _$LoadingImpl(); - - @override - String toString() { - return 'StatusTableState.loading()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$LoadingImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function() success, - }) { - return loading(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function()? success, - }) { - return loading?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function()? success, - required TResult orElse(), - }) { - if (loading != null) { - return loading(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Success value) success, - }) { - return loading(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Success value)? success, - }) { - return loading?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Success value)? success, - required TResult orElse(), - }) { - if (loading != null) { - return loading(this); - } - return orElse(); - } -} - -abstract class _Loading implements StatusTableState { - const factory _Loading() = _$LoadingImpl; -} - -/// @nodoc -abstract class _$$SuccessImplCopyWith<$Res> { - factory _$$SuccessImplCopyWith( - _$SuccessImpl value, $Res Function(_$SuccessImpl) then) = - __$$SuccessImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$SuccessImplCopyWithImpl<$Res> - extends _$StatusTableStateCopyWithImpl<$Res, _$SuccessImpl> - implements _$$SuccessImplCopyWith<$Res> { - __$$SuccessImplCopyWithImpl( - _$SuccessImpl _value, $Res Function(_$SuccessImpl) _then) - : super(_value, _then); - - /// Create a copy of StatusTableState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$SuccessImpl implements _Success { - const _$SuccessImpl(); - - @override - String toString() { - return 'StatusTableState.success()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$SuccessImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function() success, - }) { - return success(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function()? success, - }) { - return success?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function()? success, - required TResult orElse(), - }) { - if (success != null) { - return success(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Success value) success, - }) { - return success(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Success value)? success, - }) { - return success?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Success value)? success, - required TResult orElse(), - }) { - if (success != null) { - return success(this); - } - return orElse(); - } -} - -abstract class _Success implements StatusTableState { - const factory _Success() = _$SuccessImpl; -} diff --git a/lib/presentation/home/bloc/status_table/status_table_event.dart b/lib/presentation/home/bloc/status_table/status_table_event.dart deleted file mode 100644 index 09f8b8d..0000000 --- a/lib/presentation/home/bloc/status_table/status_table_event.dart +++ /dev/null @@ -1,9 +0,0 @@ -part of 'status_table_bloc.dart'; - -@freezed -class StatusTableEvent with _$StatusTableEvent { - const factory StatusTableEvent.started() = _Started; - const factory StatusTableEvent.statusTabel( - TableModel table, - ) = _StatusTable; -} diff --git a/lib/presentation/home/bloc/status_table/status_table_state.dart b/lib/presentation/home/bloc/status_table/status_table_state.dart deleted file mode 100644 index edacb2f..0000000 --- a/lib/presentation/home/bloc/status_table/status_table_state.dart +++ /dev/null @@ -1,8 +0,0 @@ -part of 'status_table_bloc.dart'; - -@freezed -class StatusTableState with _$StatusTableState { - const factory StatusTableState.initial() = _Initial; - const factory StatusTableState.loading() = _Loading; - const factory StatusTableState.success() = _Success; -} diff --git a/lib/presentation/home/dialog/payment_qris_dialog.dart b/lib/presentation/home/dialog/payment_qris_dialog.dart index 4a6ea01..b5702f6 100644 --- a/lib/presentation/home/dialog/payment_qris_dialog.dart +++ b/lib/presentation/home/dialog/payment_qris_dialog.dart @@ -2,12 +2,12 @@ import 'dart:async'; import 'dart:developer'; +import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:enaklo_pos/data/dataoutputs/print_dataoutputs.dart'; import 'package:enaklo_pos/data/datasources/auth_local_datasource.dart'; import 'package:enaklo_pos/presentation/home/models/product_quantity.dart'; -import 'package:enaklo_pos/presentation/home/models/order_type.dart'; import 'package:intl/intl.dart'; import 'package:enaklo_pos/core/extensions/build_context_ext.dart'; @@ -18,8 +18,6 @@ import 'package:enaklo_pos/core/utils/printer_service.dart'; import '../../../core/components/spaces.dart'; import '../../../core/constants/colors.dart'; -import '../bloc/order/order_bloc.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; class PaymentQrisDialog extends StatefulWidget { final List items; @@ -236,7 +234,7 @@ class _PaymentQrisDialogState extends State { widget.price, bytes!, int.parse(sizeReceipt)); // Get the receipt printer to print QRIS - final receiptPrinter = await ProductLocalDatasource + final receiptPrinter = await PrinterLocalDatasource .instance .getPrinterByCode('receipt'); diff --git a/lib/presentation/home/pages/dashboard_page.dart b/lib/presentation/home/pages/dashboard_page.dart index 2a6c1c1..bf1c650 100644 --- a/lib/presentation/home/pages/dashboard_page.dart +++ b/lib/presentation/home/pages/dashboard_page.dart @@ -16,7 +16,6 @@ import 'package:enaklo_pos/core/extensions/build_context_ext.dart'; import 'package:enaklo_pos/data/datasources/auth_local_datasource.dart'; import 'package:enaklo_pos/presentation/auth/login_page.dart'; import 'package:enaklo_pos/presentation/report/pages/report_page.dart'; -import 'package:enaklo_pos/presentation/setting/bloc/sync_order/sync_order_bloc.dart'; import '../../../core/assets/assets.gen.dart'; import '../../auth/bloc/logout/logout_bloc.dart'; @@ -155,10 +154,6 @@ class _DashboardPageState extends State { ), ), online: () { - log("🌐 Dashboard: Internet connection detected, triggering sync"); - context.read().add( - const SyncOrderEvent.syncOrder(), - ); return Container( width: 40, margin: diff --git a/lib/presentation/sales/blocs/bloc/last_order_table_bloc.dart b/lib/presentation/sales/blocs/bloc/last_order_table_bloc.dart deleted file mode 100644 index 9cb2460..0000000 --- a/lib/presentation/sales/blocs/bloc/last_order_table_bloc.dart +++ /dev/null @@ -1,23 +0,0 @@ - -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; -import 'package:enaklo_pos/presentation/home/models/order_model.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'last_order_table_event.dart'; -part 'last_order_table_state.dart'; -part 'last_order_table_bloc.freezed.dart'; - -class LastOrderTableBloc - extends Bloc { - final ProductLocalDatasource datasource; - LastOrderTableBloc(this.datasource) - : super(const LastOrderTableState.initial()) { - on<_LastOrderTable>((event, emit) async { - emit(_Loading()); - final order = await datasource.getLastOrderTable(event.tableNumber); - - emit(_Success(order)); - }); - } -} diff --git a/lib/presentation/sales/blocs/bloc/last_order_table_bloc.freezed.dart b/lib/presentation/sales/blocs/bloc/last_order_table_bloc.freezed.dart deleted file mode 100644 index 3042d60..0000000 --- a/lib/presentation/sales/blocs/bloc/last_order_table_bloc.freezed.dart +++ /dev/null @@ -1,762 +0,0 @@ -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'last_order_table_bloc.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - -/// @nodoc -mixin _$LastOrderTableEvent { - @optionalTypeArgs - TResult when({ - required TResult Function() started, - required TResult Function(int tableNumber) lastOrderTable, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? started, - TResult? Function(int tableNumber)? lastOrderTable, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? started, - TResult Function(int tableNumber)? lastOrderTable, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(_Started value) started, - required TResult Function(_LastOrderTable value) lastOrderTable, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Started value)? started, - TResult? Function(_LastOrderTable value)? lastOrderTable, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Started value)? started, - TResult Function(_LastOrderTable value)? lastOrderTable, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $LastOrderTableEventCopyWith<$Res> { - factory $LastOrderTableEventCopyWith( - LastOrderTableEvent value, $Res Function(LastOrderTableEvent) then) = - _$LastOrderTableEventCopyWithImpl<$Res, LastOrderTableEvent>; -} - -/// @nodoc -class _$LastOrderTableEventCopyWithImpl<$Res, $Val extends LastOrderTableEvent> - implements $LastOrderTableEventCopyWith<$Res> { - _$LastOrderTableEventCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of LastOrderTableEvent - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc -abstract class _$$StartedImplCopyWith<$Res> { - factory _$$StartedImplCopyWith( - _$StartedImpl value, $Res Function(_$StartedImpl) then) = - __$$StartedImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$StartedImplCopyWithImpl<$Res> - extends _$LastOrderTableEventCopyWithImpl<$Res, _$StartedImpl> - implements _$$StartedImplCopyWith<$Res> { - __$$StartedImplCopyWithImpl( - _$StartedImpl _value, $Res Function(_$StartedImpl) _then) - : super(_value, _then); - - /// Create a copy of LastOrderTableEvent - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$StartedImpl implements _Started { - const _$StartedImpl(); - - @override - String toString() { - return 'LastOrderTableEvent.started()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$StartedImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() started, - required TResult Function(int tableNumber) lastOrderTable, - }) { - return started(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? started, - TResult? Function(int tableNumber)? lastOrderTable, - }) { - return started?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? started, - TResult Function(int tableNumber)? lastOrderTable, - required TResult orElse(), - }) { - if (started != null) { - return started(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Started value) started, - required TResult Function(_LastOrderTable value) lastOrderTable, - }) { - return started(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Started value)? started, - TResult? Function(_LastOrderTable value)? lastOrderTable, - }) { - return started?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Started value)? started, - TResult Function(_LastOrderTable value)? lastOrderTable, - required TResult orElse(), - }) { - if (started != null) { - return started(this); - } - return orElse(); - } -} - -abstract class _Started implements LastOrderTableEvent { - const factory _Started() = _$StartedImpl; -} - -/// @nodoc -abstract class _$$LastOrderTableImplCopyWith<$Res> { - factory _$$LastOrderTableImplCopyWith(_$LastOrderTableImpl value, - $Res Function(_$LastOrderTableImpl) then) = - __$$LastOrderTableImplCopyWithImpl<$Res>; - @useResult - $Res call({int tableNumber}); -} - -/// @nodoc -class __$$LastOrderTableImplCopyWithImpl<$Res> - extends _$LastOrderTableEventCopyWithImpl<$Res, _$LastOrderTableImpl> - implements _$$LastOrderTableImplCopyWith<$Res> { - __$$LastOrderTableImplCopyWithImpl( - _$LastOrderTableImpl _value, $Res Function(_$LastOrderTableImpl) _then) - : super(_value, _then); - - /// Create a copy of LastOrderTableEvent - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? tableNumber = null, - }) { - return _then(_$LastOrderTableImpl( - null == tableNumber - ? _value.tableNumber - : tableNumber // ignore: cast_nullable_to_non_nullable - as int, - )); - } -} - -/// @nodoc - -class _$LastOrderTableImpl implements _LastOrderTable { - const _$LastOrderTableImpl(this.tableNumber); - - @override - final int tableNumber; - - @override - String toString() { - return 'LastOrderTableEvent.lastOrderTable(tableNumber: $tableNumber)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$LastOrderTableImpl && - (identical(other.tableNumber, tableNumber) || - other.tableNumber == tableNumber)); - } - - @override - int get hashCode => Object.hash(runtimeType, tableNumber); - - /// Create a copy of LastOrderTableEvent - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$LastOrderTableImplCopyWith<_$LastOrderTableImpl> get copyWith => - __$$LastOrderTableImplCopyWithImpl<_$LastOrderTableImpl>( - this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() started, - required TResult Function(int tableNumber) lastOrderTable, - }) { - return lastOrderTable(tableNumber); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? started, - TResult? Function(int tableNumber)? lastOrderTable, - }) { - return lastOrderTable?.call(tableNumber); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? started, - TResult Function(int tableNumber)? lastOrderTable, - required TResult orElse(), - }) { - if (lastOrderTable != null) { - return lastOrderTable(tableNumber); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Started value) started, - required TResult Function(_LastOrderTable value) lastOrderTable, - }) { - return lastOrderTable(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Started value)? started, - TResult? Function(_LastOrderTable value)? lastOrderTable, - }) { - return lastOrderTable?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Started value)? started, - TResult Function(_LastOrderTable value)? lastOrderTable, - required TResult orElse(), - }) { - if (lastOrderTable != null) { - return lastOrderTable(this); - } - return orElse(); - } -} - -abstract class _LastOrderTable implements LastOrderTableEvent { - const factory _LastOrderTable(final int tableNumber) = _$LastOrderTableImpl; - - int get tableNumber; - - /// Create a copy of LastOrderTableEvent - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - _$$LastOrderTableImplCopyWith<_$LastOrderTableImpl> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -mixin _$LastOrderTableState { - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function(OrderModel? order) success, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function(OrderModel? order)? success, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function(OrderModel? order)? success, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Success value) success, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Success value)? success, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Success value)? success, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $LastOrderTableStateCopyWith<$Res> { - factory $LastOrderTableStateCopyWith( - LastOrderTableState value, $Res Function(LastOrderTableState) then) = - _$LastOrderTableStateCopyWithImpl<$Res, LastOrderTableState>; -} - -/// @nodoc -class _$LastOrderTableStateCopyWithImpl<$Res, $Val extends LastOrderTableState> - implements $LastOrderTableStateCopyWith<$Res> { - _$LastOrderTableStateCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of LastOrderTableState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc -abstract class _$$InitialImplCopyWith<$Res> { - factory _$$InitialImplCopyWith( - _$InitialImpl value, $Res Function(_$InitialImpl) then) = - __$$InitialImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$InitialImplCopyWithImpl<$Res> - extends _$LastOrderTableStateCopyWithImpl<$Res, _$InitialImpl> - implements _$$InitialImplCopyWith<$Res> { - __$$InitialImplCopyWithImpl( - _$InitialImpl _value, $Res Function(_$InitialImpl) _then) - : super(_value, _then); - - /// Create a copy of LastOrderTableState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$InitialImpl implements _Initial { - const _$InitialImpl(); - - @override - String toString() { - return 'LastOrderTableState.initial()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$InitialImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function(OrderModel? order) success, - }) { - return initial(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function(OrderModel? order)? success, - }) { - return initial?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function(OrderModel? order)? success, - required TResult orElse(), - }) { - if (initial != null) { - return initial(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Success value) success, - }) { - return initial(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Success value)? success, - }) { - return initial?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Success value)? success, - required TResult orElse(), - }) { - if (initial != null) { - return initial(this); - } - return orElse(); - } -} - -abstract class _Initial implements LastOrderTableState { - const factory _Initial() = _$InitialImpl; -} - -/// @nodoc -abstract class _$$LoadingImplCopyWith<$Res> { - factory _$$LoadingImplCopyWith( - _$LoadingImpl value, $Res Function(_$LoadingImpl) then) = - __$$LoadingImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$LoadingImplCopyWithImpl<$Res> - extends _$LastOrderTableStateCopyWithImpl<$Res, _$LoadingImpl> - implements _$$LoadingImplCopyWith<$Res> { - __$$LoadingImplCopyWithImpl( - _$LoadingImpl _value, $Res Function(_$LoadingImpl) _then) - : super(_value, _then); - - /// Create a copy of LastOrderTableState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$LoadingImpl implements _Loading { - const _$LoadingImpl(); - - @override - String toString() { - return 'LastOrderTableState.loading()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$LoadingImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function(OrderModel? order) success, - }) { - return loading(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function(OrderModel? order)? success, - }) { - return loading?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function(OrderModel? order)? success, - required TResult orElse(), - }) { - if (loading != null) { - return loading(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Success value) success, - }) { - return loading(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Success value)? success, - }) { - return loading?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Success value)? success, - required TResult orElse(), - }) { - if (loading != null) { - return loading(this); - } - return orElse(); - } -} - -abstract class _Loading implements LastOrderTableState { - const factory _Loading() = _$LoadingImpl; -} - -/// @nodoc -abstract class _$$SuccessImplCopyWith<$Res> { - factory _$$SuccessImplCopyWith( - _$SuccessImpl value, $Res Function(_$SuccessImpl) then) = - __$$SuccessImplCopyWithImpl<$Res>; - @useResult - $Res call({OrderModel? order}); -} - -/// @nodoc -class __$$SuccessImplCopyWithImpl<$Res> - extends _$LastOrderTableStateCopyWithImpl<$Res, _$SuccessImpl> - implements _$$SuccessImplCopyWith<$Res> { - __$$SuccessImplCopyWithImpl( - _$SuccessImpl _value, $Res Function(_$SuccessImpl) _then) - : super(_value, _then); - - /// Create a copy of LastOrderTableState - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? order = freezed, - }) { - return _then(_$SuccessImpl( - freezed == order - ? _value.order - : order // ignore: cast_nullable_to_non_nullable - as OrderModel?, - )); - } -} - -/// @nodoc - -class _$SuccessImpl implements _Success { - const _$SuccessImpl(this.order); - - @override - final OrderModel? order; - - @override - String toString() { - return 'LastOrderTableState.success(order: $order)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$SuccessImpl && - (identical(other.order, order) || other.order == order)); - } - - @override - int get hashCode => Object.hash(runtimeType, order); - - /// Create a copy of LastOrderTableState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$SuccessImplCopyWith<_$SuccessImpl> get copyWith => - __$$SuccessImplCopyWithImpl<_$SuccessImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function(OrderModel? order) success, - }) { - return success(order); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function(OrderModel? order)? success, - }) { - return success?.call(order); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function(OrderModel? order)? success, - required TResult orElse(), - }) { - if (success != null) { - return success(order); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Success value) success, - }) { - return success(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Success value)? success, - }) { - return success?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Success value)? success, - required TResult orElse(), - }) { - if (success != null) { - return success(this); - } - return orElse(); - } -} - -abstract class _Success implements LastOrderTableState { - const factory _Success(final OrderModel? order) = _$SuccessImpl; - - OrderModel? get order; - - /// Create a copy of LastOrderTableState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - _$$SuccessImplCopyWith<_$SuccessImpl> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/lib/presentation/sales/blocs/bloc/last_order_table_event.dart b/lib/presentation/sales/blocs/bloc/last_order_table_event.dart deleted file mode 100644 index a89a759..0000000 --- a/lib/presentation/sales/blocs/bloc/last_order_table_event.dart +++ /dev/null @@ -1,8 +0,0 @@ -part of 'last_order_table_bloc.dart'; - -@freezed -class LastOrderTableEvent with _$LastOrderTableEvent { - const factory LastOrderTableEvent.started() = _Started; - const factory LastOrderTableEvent.lastOrderTable(int tableNumber) = - _LastOrderTable; -} diff --git a/lib/presentation/sales/blocs/bloc/last_order_table_state.dart b/lib/presentation/sales/blocs/bloc/last_order_table_state.dart deleted file mode 100644 index e7f0651..0000000 --- a/lib/presentation/sales/blocs/bloc/last_order_table_state.dart +++ /dev/null @@ -1,8 +0,0 @@ -part of 'last_order_table_bloc.dart'; - -@freezed -class LastOrderTableState with _$LastOrderTableState { - const factory LastOrderTableState.initial() = _Initial; - const factory LastOrderTableState.loading() = _Loading; - const factory LastOrderTableState.success(OrderModel? order) = _Success; -} diff --git a/lib/presentation/sales/blocs/day_sales/day_sales_bloc.dart b/lib/presentation/sales/blocs/day_sales/day_sales_bloc.dart deleted file mode 100644 index a186f88..0000000 --- a/lib/presentation/sales/blocs/day_sales/day_sales_bloc.dart +++ /dev/null @@ -1,25 +0,0 @@ -import 'package:bloc/bloc.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; -import 'package:enaklo_pos/presentation/home/models/order_model.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; - -part 'day_sales_event.dart'; -part 'day_sales_state.dart'; -part 'day_sales_bloc.freezed.dart'; - -class DaySalesBloc extends Bloc { - final ProductLocalDatasource datasource; - DaySalesBloc(this.datasource) : super(const _Initial()) { - on<_GetDaySales>((event, emit) async { - emit(const _Loading()); - final result = await datasource.getAllOrder(event.date); - emit(_Loaded(result)); - }); - on<_GetRangeDateSales>((event, emit) async { - emit(const _Loading()); - final result = - await datasource.getAllOrderByRange(event.startDate, event.endDate); - emit(_Loaded(result)); - }); - } -} diff --git a/lib/presentation/sales/blocs/day_sales/day_sales_bloc.freezed.dart b/lib/presentation/sales/blocs/day_sales/day_sales_bloc.freezed.dart deleted file mode 100644 index 1081e35..0000000 --- a/lib/presentation/sales/blocs/day_sales/day_sales_bloc.freezed.dart +++ /dev/null @@ -1,947 +0,0 @@ -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'day_sales_bloc.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - -/// @nodoc -mixin _$DaySalesEvent { - @optionalTypeArgs - TResult when({ - required TResult Function() started, - required TResult Function(DateTime date) getDaySales, - required TResult Function(DateTime startDate, DateTime endDate) - getRangeDateSales, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? started, - TResult? Function(DateTime date)? getDaySales, - TResult? Function(DateTime startDate, DateTime endDate)? getRangeDateSales, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? started, - TResult Function(DateTime date)? getDaySales, - TResult Function(DateTime startDate, DateTime endDate)? getRangeDateSales, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(_Started value) started, - required TResult Function(_GetDaySales value) getDaySales, - required TResult Function(_GetRangeDateSales value) getRangeDateSales, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Started value)? started, - TResult? Function(_GetDaySales value)? getDaySales, - TResult? Function(_GetRangeDateSales value)? getRangeDateSales, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Started value)? started, - TResult Function(_GetDaySales value)? getDaySales, - TResult Function(_GetRangeDateSales value)? getRangeDateSales, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $DaySalesEventCopyWith<$Res> { - factory $DaySalesEventCopyWith( - DaySalesEvent value, $Res Function(DaySalesEvent) then) = - _$DaySalesEventCopyWithImpl<$Res, DaySalesEvent>; -} - -/// @nodoc -class _$DaySalesEventCopyWithImpl<$Res, $Val extends DaySalesEvent> - implements $DaySalesEventCopyWith<$Res> { - _$DaySalesEventCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of DaySalesEvent - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc -abstract class _$$StartedImplCopyWith<$Res> { - factory _$$StartedImplCopyWith( - _$StartedImpl value, $Res Function(_$StartedImpl) then) = - __$$StartedImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$StartedImplCopyWithImpl<$Res> - extends _$DaySalesEventCopyWithImpl<$Res, _$StartedImpl> - implements _$$StartedImplCopyWith<$Res> { - __$$StartedImplCopyWithImpl( - _$StartedImpl _value, $Res Function(_$StartedImpl) _then) - : super(_value, _then); - - /// Create a copy of DaySalesEvent - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$StartedImpl implements _Started { - const _$StartedImpl(); - - @override - String toString() { - return 'DaySalesEvent.started()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$StartedImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() started, - required TResult Function(DateTime date) getDaySales, - required TResult Function(DateTime startDate, DateTime endDate) - getRangeDateSales, - }) { - return started(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? started, - TResult? Function(DateTime date)? getDaySales, - TResult? Function(DateTime startDate, DateTime endDate)? getRangeDateSales, - }) { - return started?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? started, - TResult Function(DateTime date)? getDaySales, - TResult Function(DateTime startDate, DateTime endDate)? getRangeDateSales, - required TResult orElse(), - }) { - if (started != null) { - return started(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Started value) started, - required TResult Function(_GetDaySales value) getDaySales, - required TResult Function(_GetRangeDateSales value) getRangeDateSales, - }) { - return started(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Started value)? started, - TResult? Function(_GetDaySales value)? getDaySales, - TResult? Function(_GetRangeDateSales value)? getRangeDateSales, - }) { - return started?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Started value)? started, - TResult Function(_GetDaySales value)? getDaySales, - TResult Function(_GetRangeDateSales value)? getRangeDateSales, - required TResult orElse(), - }) { - if (started != null) { - return started(this); - } - return orElse(); - } -} - -abstract class _Started implements DaySalesEvent { - const factory _Started() = _$StartedImpl; -} - -/// @nodoc -abstract class _$$GetDaySalesImplCopyWith<$Res> { - factory _$$GetDaySalesImplCopyWith( - _$GetDaySalesImpl value, $Res Function(_$GetDaySalesImpl) then) = - __$$GetDaySalesImplCopyWithImpl<$Res>; - @useResult - $Res call({DateTime date}); -} - -/// @nodoc -class __$$GetDaySalesImplCopyWithImpl<$Res> - extends _$DaySalesEventCopyWithImpl<$Res, _$GetDaySalesImpl> - implements _$$GetDaySalesImplCopyWith<$Res> { - __$$GetDaySalesImplCopyWithImpl( - _$GetDaySalesImpl _value, $Res Function(_$GetDaySalesImpl) _then) - : super(_value, _then); - - /// Create a copy of DaySalesEvent - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? date = null, - }) { - return _then(_$GetDaySalesImpl( - null == date - ? _value.date - : date // ignore: cast_nullable_to_non_nullable - as DateTime, - )); - } -} - -/// @nodoc - -class _$GetDaySalesImpl implements _GetDaySales { - const _$GetDaySalesImpl(this.date); - - @override - final DateTime date; - - @override - String toString() { - return 'DaySalesEvent.getDaySales(date: $date)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$GetDaySalesImpl && - (identical(other.date, date) || other.date == date)); - } - - @override - int get hashCode => Object.hash(runtimeType, date); - - /// Create a copy of DaySalesEvent - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$GetDaySalesImplCopyWith<_$GetDaySalesImpl> get copyWith => - __$$GetDaySalesImplCopyWithImpl<_$GetDaySalesImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() started, - required TResult Function(DateTime date) getDaySales, - required TResult Function(DateTime startDate, DateTime endDate) - getRangeDateSales, - }) { - return getDaySales(date); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? started, - TResult? Function(DateTime date)? getDaySales, - TResult? Function(DateTime startDate, DateTime endDate)? getRangeDateSales, - }) { - return getDaySales?.call(date); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? started, - TResult Function(DateTime date)? getDaySales, - TResult Function(DateTime startDate, DateTime endDate)? getRangeDateSales, - required TResult orElse(), - }) { - if (getDaySales != null) { - return getDaySales(date); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Started value) started, - required TResult Function(_GetDaySales value) getDaySales, - required TResult Function(_GetRangeDateSales value) getRangeDateSales, - }) { - return getDaySales(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Started value)? started, - TResult? Function(_GetDaySales value)? getDaySales, - TResult? Function(_GetRangeDateSales value)? getRangeDateSales, - }) { - return getDaySales?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Started value)? started, - TResult Function(_GetDaySales value)? getDaySales, - TResult Function(_GetRangeDateSales value)? getRangeDateSales, - required TResult orElse(), - }) { - if (getDaySales != null) { - return getDaySales(this); - } - return orElse(); - } -} - -abstract class _GetDaySales implements DaySalesEvent { - const factory _GetDaySales(final DateTime date) = _$GetDaySalesImpl; - - DateTime get date; - - /// Create a copy of DaySalesEvent - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - _$$GetDaySalesImplCopyWith<_$GetDaySalesImpl> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class _$$GetRangeDateSalesImplCopyWith<$Res> { - factory _$$GetRangeDateSalesImplCopyWith(_$GetRangeDateSalesImpl value, - $Res Function(_$GetRangeDateSalesImpl) then) = - __$$GetRangeDateSalesImplCopyWithImpl<$Res>; - @useResult - $Res call({DateTime startDate, DateTime endDate}); -} - -/// @nodoc -class __$$GetRangeDateSalesImplCopyWithImpl<$Res> - extends _$DaySalesEventCopyWithImpl<$Res, _$GetRangeDateSalesImpl> - implements _$$GetRangeDateSalesImplCopyWith<$Res> { - __$$GetRangeDateSalesImplCopyWithImpl(_$GetRangeDateSalesImpl _value, - $Res Function(_$GetRangeDateSalesImpl) _then) - : super(_value, _then); - - /// Create a copy of DaySalesEvent - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? startDate = null, - Object? endDate = null, - }) { - return _then(_$GetRangeDateSalesImpl( - null == startDate - ? _value.startDate - : startDate // ignore: cast_nullable_to_non_nullable - as DateTime, - null == endDate - ? _value.endDate - : endDate // ignore: cast_nullable_to_non_nullable - as DateTime, - )); - } -} - -/// @nodoc - -class _$GetRangeDateSalesImpl implements _GetRangeDateSales { - const _$GetRangeDateSalesImpl(this.startDate, this.endDate); - - @override - final DateTime startDate; - @override - final DateTime endDate; - - @override - String toString() { - return 'DaySalesEvent.getRangeDateSales(startDate: $startDate, endDate: $endDate)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$GetRangeDateSalesImpl && - (identical(other.startDate, startDate) || - other.startDate == startDate) && - (identical(other.endDate, endDate) || other.endDate == endDate)); - } - - @override - int get hashCode => Object.hash(runtimeType, startDate, endDate); - - /// Create a copy of DaySalesEvent - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$GetRangeDateSalesImplCopyWith<_$GetRangeDateSalesImpl> get copyWith => - __$$GetRangeDateSalesImplCopyWithImpl<_$GetRangeDateSalesImpl>( - this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() started, - required TResult Function(DateTime date) getDaySales, - required TResult Function(DateTime startDate, DateTime endDate) - getRangeDateSales, - }) { - return getRangeDateSales(startDate, endDate); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? started, - TResult? Function(DateTime date)? getDaySales, - TResult? Function(DateTime startDate, DateTime endDate)? getRangeDateSales, - }) { - return getRangeDateSales?.call(startDate, endDate); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? started, - TResult Function(DateTime date)? getDaySales, - TResult Function(DateTime startDate, DateTime endDate)? getRangeDateSales, - required TResult orElse(), - }) { - if (getRangeDateSales != null) { - return getRangeDateSales(startDate, endDate); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Started value) started, - required TResult Function(_GetDaySales value) getDaySales, - required TResult Function(_GetRangeDateSales value) getRangeDateSales, - }) { - return getRangeDateSales(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Started value)? started, - TResult? Function(_GetDaySales value)? getDaySales, - TResult? Function(_GetRangeDateSales value)? getRangeDateSales, - }) { - return getRangeDateSales?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Started value)? started, - TResult Function(_GetDaySales value)? getDaySales, - TResult Function(_GetRangeDateSales value)? getRangeDateSales, - required TResult orElse(), - }) { - if (getRangeDateSales != null) { - return getRangeDateSales(this); - } - return orElse(); - } -} - -abstract class _GetRangeDateSales implements DaySalesEvent { - const factory _GetRangeDateSales( - final DateTime startDate, final DateTime endDate) = - _$GetRangeDateSalesImpl; - - DateTime get startDate; - DateTime get endDate; - - /// Create a copy of DaySalesEvent - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - _$$GetRangeDateSalesImplCopyWith<_$GetRangeDateSalesImpl> get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -mixin _$DaySalesState { - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function(List orders) loaded, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function(List orders)? loaded, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function(List orders)? loaded, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Loaded value) loaded, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Loaded value)? loaded, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Loaded value)? loaded, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $DaySalesStateCopyWith<$Res> { - factory $DaySalesStateCopyWith( - DaySalesState value, $Res Function(DaySalesState) then) = - _$DaySalesStateCopyWithImpl<$Res, DaySalesState>; -} - -/// @nodoc -class _$DaySalesStateCopyWithImpl<$Res, $Val extends DaySalesState> - implements $DaySalesStateCopyWith<$Res> { - _$DaySalesStateCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of DaySalesState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc -abstract class _$$InitialImplCopyWith<$Res> { - factory _$$InitialImplCopyWith( - _$InitialImpl value, $Res Function(_$InitialImpl) then) = - __$$InitialImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$InitialImplCopyWithImpl<$Res> - extends _$DaySalesStateCopyWithImpl<$Res, _$InitialImpl> - implements _$$InitialImplCopyWith<$Res> { - __$$InitialImplCopyWithImpl( - _$InitialImpl _value, $Res Function(_$InitialImpl) _then) - : super(_value, _then); - - /// Create a copy of DaySalesState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$InitialImpl implements _Initial { - const _$InitialImpl(); - - @override - String toString() { - return 'DaySalesState.initial()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$InitialImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function(List orders) loaded, - }) { - return initial(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function(List orders)? loaded, - }) { - return initial?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function(List orders)? loaded, - required TResult orElse(), - }) { - if (initial != null) { - return initial(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Loaded value) loaded, - }) { - return initial(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Loaded value)? loaded, - }) { - return initial?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Loaded value)? loaded, - required TResult orElse(), - }) { - if (initial != null) { - return initial(this); - } - return orElse(); - } -} - -abstract class _Initial implements DaySalesState { - const factory _Initial() = _$InitialImpl; -} - -/// @nodoc -abstract class _$$LoadingImplCopyWith<$Res> { - factory _$$LoadingImplCopyWith( - _$LoadingImpl value, $Res Function(_$LoadingImpl) then) = - __$$LoadingImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$LoadingImplCopyWithImpl<$Res> - extends _$DaySalesStateCopyWithImpl<$Res, _$LoadingImpl> - implements _$$LoadingImplCopyWith<$Res> { - __$$LoadingImplCopyWithImpl( - _$LoadingImpl _value, $Res Function(_$LoadingImpl) _then) - : super(_value, _then); - - /// Create a copy of DaySalesState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$LoadingImpl implements _Loading { - const _$LoadingImpl(); - - @override - String toString() { - return 'DaySalesState.loading()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$LoadingImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function(List orders) loaded, - }) { - return loading(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function(List orders)? loaded, - }) { - return loading?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function(List orders)? loaded, - required TResult orElse(), - }) { - if (loading != null) { - return loading(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Loaded value) loaded, - }) { - return loading(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Loaded value)? loaded, - }) { - return loading?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Loaded value)? loaded, - required TResult orElse(), - }) { - if (loading != null) { - return loading(this); - } - return orElse(); - } -} - -abstract class _Loading implements DaySalesState { - const factory _Loading() = _$LoadingImpl; -} - -/// @nodoc -abstract class _$$LoadedImplCopyWith<$Res> { - factory _$$LoadedImplCopyWith( - _$LoadedImpl value, $Res Function(_$LoadedImpl) then) = - __$$LoadedImplCopyWithImpl<$Res>; - @useResult - $Res call({List orders}); -} - -/// @nodoc -class __$$LoadedImplCopyWithImpl<$Res> - extends _$DaySalesStateCopyWithImpl<$Res, _$LoadedImpl> - implements _$$LoadedImplCopyWith<$Res> { - __$$LoadedImplCopyWithImpl( - _$LoadedImpl _value, $Res Function(_$LoadedImpl) _then) - : super(_value, _then); - - /// Create a copy of DaySalesState - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? orders = null, - }) { - return _then(_$LoadedImpl( - null == orders - ? _value._orders - : orders // ignore: cast_nullable_to_non_nullable - as List, - )); - } -} - -/// @nodoc - -class _$LoadedImpl implements _Loaded { - const _$LoadedImpl(final List orders) : _orders = orders; - - final List _orders; - @override - List get orders { - if (_orders is EqualUnmodifiableListView) return _orders; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_orders); - } - - @override - String toString() { - return 'DaySalesState.loaded(orders: $orders)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$LoadedImpl && - const DeepCollectionEquality().equals(other._orders, _orders)); - } - - @override - int get hashCode => - Object.hash(runtimeType, const DeepCollectionEquality().hash(_orders)); - - /// Create a copy of DaySalesState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$LoadedImplCopyWith<_$LoadedImpl> get copyWith => - __$$LoadedImplCopyWithImpl<_$LoadedImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function(List orders) loaded, - }) { - return loaded(orders); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function(List orders)? loaded, - }) { - return loaded?.call(orders); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function(List orders)? loaded, - required TResult orElse(), - }) { - if (loaded != null) { - return loaded(orders); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Loaded value) loaded, - }) { - return loaded(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Loaded value)? loaded, - }) { - return loaded?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Loaded value)? loaded, - required TResult orElse(), - }) { - if (loaded != null) { - return loaded(this); - } - return orElse(); - } -} - -abstract class _Loaded implements DaySalesState { - const factory _Loaded(final List orders) = _$LoadedImpl; - - List get orders; - - /// Create a copy of DaySalesState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - _$$LoadedImplCopyWith<_$LoadedImpl> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/lib/presentation/sales/blocs/day_sales/day_sales_event.dart b/lib/presentation/sales/blocs/day_sales/day_sales_event.dart deleted file mode 100644 index b8889fd..0000000 --- a/lib/presentation/sales/blocs/day_sales/day_sales_event.dart +++ /dev/null @@ -1,13 +0,0 @@ -part of 'day_sales_bloc.dart'; - -@freezed -class DaySalesEvent with _$DaySalesEvent { - const factory DaySalesEvent.started() = _Started; - const factory DaySalesEvent.getDaySales( - DateTime date, - ) = _GetDaySales; - const factory DaySalesEvent.getRangeDateSales( - DateTime startDate, - DateTime endDate, - ) = _GetRangeDateSales; -} diff --git a/lib/presentation/sales/blocs/day_sales/day_sales_state.dart b/lib/presentation/sales/blocs/day_sales/day_sales_state.dart deleted file mode 100644 index 698ee6a..0000000 --- a/lib/presentation/sales/blocs/day_sales/day_sales_state.dart +++ /dev/null @@ -1,8 +0,0 @@ -part of 'day_sales_bloc.dart'; - -@freezed -class DaySalesState with _$DaySalesState { - const factory DaySalesState.initial() = _Initial; - const factory DaySalesState.loading() = _Loading; - const factory DaySalesState.loaded(List orders) = _Loaded; -} diff --git a/lib/presentation/setting/bloc/create_printer/create_printer_bloc.dart b/lib/presentation/setting/bloc/create_printer/create_printer_bloc.dart index 9a17c77..a39dc08 100644 --- a/lib/presentation/setting/bloc/create_printer/create_printer_bloc.dart +++ b/lib/presentation/setting/bloc/create_printer/create_printer_bloc.dart @@ -1,7 +1,5 @@ -import 'dart:async'; - import 'package:bloc/bloc.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; +import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart'; import 'package:enaklo_pos/data/models/response/print_model.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -13,10 +11,10 @@ class CreatePrinterBloc extends Bloc { CreatePrinterBloc() : super(_Initial()) { on<_CreatePrinter>((event, emit) async { emit(_Loading()); - await ProductLocalDatasource.instance.createPrinter( + await PrinterLocalDatasource.instance.createPrinter( event.print, ); - emit(_Success('Create Table Success')); + emit(_Success('Create Printer Success')); }); } } diff --git a/lib/presentation/setting/bloc/get_printer_bar/get_printer_bar_bloc.dart b/lib/presentation/setting/bloc/get_printer_bar/get_printer_bar_bloc.dart index 08a51ae..7d13018 100644 --- a/lib/presentation/setting/bloc/get_printer_bar/get_printer_bar_bloc.dart +++ b/lib/presentation/setting/bloc/get_printer_bar/get_printer_bar_bloc.dart @@ -1,6 +1,5 @@ - import 'package:bloc/bloc.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; +import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart'; import 'package:enaklo_pos/data/models/response/print_model.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -13,7 +12,7 @@ class GetPrinterBarBloc extends Bloc { on<_Get>((event, emit) async { emit(_Loading()); final result = - await ProductLocalDatasource.instance.getPrinterByCode('bar'); + await PrinterLocalDatasource.instance.getPrinterByCode('bar'); emit(_Success(result)); }); } diff --git a/lib/presentation/setting/bloc/get_printer_checker/get_printer_checker_bloc.dart b/lib/presentation/setting/bloc/get_printer_checker/get_printer_checker_bloc.dart index 3622cd0..44de5de 100644 --- a/lib/presentation/setting/bloc/get_printer_checker/get_printer_checker_bloc.dart +++ b/lib/presentation/setting/bloc/get_printer_checker/get_printer_checker_bloc.dart @@ -1,9 +1,8 @@ import 'package:bloc/bloc.dart'; +import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart'; import 'package:enaklo_pos/data/models/response/print_model.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; -import '../../../../data/datasources/product_local_datasource.dart'; - part 'get_printer_checker_event.dart'; part 'get_printer_checker_state.dart'; part 'get_printer_checker_bloc.freezed.dart'; @@ -14,7 +13,7 @@ class GetPrinterCheckerBloc on<_Get>((event, emit) async { emit(_Loading()); final result = - await ProductLocalDatasource.instance.getPrinterByCode('checker'); + await PrinterLocalDatasource.instance.getPrinterByCode('checker'); emit(_Success(result)); }); } diff --git a/lib/presentation/setting/bloc/get_printer_kitchen/get_printer_kitchen_bloc.dart b/lib/presentation/setting/bloc/get_printer_kitchen/get_printer_kitchen_bloc.dart index 5c820de..138db2e 100644 --- a/lib/presentation/setting/bloc/get_printer_kitchen/get_printer_kitchen_bloc.dart +++ b/lib/presentation/setting/bloc/get_printer_kitchen/get_printer_kitchen_bloc.dart @@ -1,5 +1,5 @@ import 'package:bloc/bloc.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; +import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart'; import 'package:enaklo_pos/data/models/response/print_model.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -13,7 +13,7 @@ class GetPrinterKitchenBloc on<_Get>((event, emit) async { emit(_Loading()); final result = - await ProductLocalDatasource.instance.getPrinterByCode('kitchen'); + await PrinterLocalDatasource.instance.getPrinterByCode('kitchen'); emit(_Success(result)); }); } diff --git a/lib/presentation/setting/bloc/get_printer_receipt/get_printer_receipt_bloc.dart b/lib/presentation/setting/bloc/get_printer_receipt/get_printer_receipt_bloc.dart index d31516a..5d9040a 100644 --- a/lib/presentation/setting/bloc/get_printer_receipt/get_printer_receipt_bloc.dart +++ b/lib/presentation/setting/bloc/get_printer_receipt/get_printer_receipt_bloc.dart @@ -1,5 +1,5 @@ import 'package:bloc/bloc.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; +import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart'; import 'package:enaklo_pos/data/models/response/print_model.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -13,7 +13,7 @@ class GetPrinterReceiptBloc on<_Get>((event, emit) async { emit(_Loading()); final result = - await ProductLocalDatasource.instance.getPrinterByCode('receipt'); + await PrinterLocalDatasource.instance.getPrinterByCode('receipt'); emit(_Success(result)); }); } diff --git a/lib/presentation/setting/bloc/get_printer_ticket/get_printer_ticket_bloc.dart b/lib/presentation/setting/bloc/get_printer_ticket/get_printer_ticket_bloc.dart index c3101b0..42ded92 100644 --- a/lib/presentation/setting/bloc/get_printer_ticket/get_printer_ticket_bloc.dart +++ b/lib/presentation/setting/bloc/get_printer_ticket/get_printer_ticket_bloc.dart @@ -1,5 +1,5 @@ import 'package:bloc/bloc.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; +import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart'; import 'package:enaklo_pos/data/models/response/print_model.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -13,7 +13,7 @@ class GetPrinterTicketBloc on<_Get>((event, emit) async { emit(_Loading()); final result = - await ProductLocalDatasource.instance.getPrinterByCode('ticket'); + await PrinterLocalDatasource.instance.getPrinterByCode('ticket'); emit(_Success(result)); }); } diff --git a/lib/presentation/setting/bloc/sync_order/sync_order_bloc.dart b/lib/presentation/setting/bloc/sync_order/sync_order_bloc.dart deleted file mode 100644 index d1d0f1a..0000000 --- a/lib/presentation/setting/bloc/sync_order/sync_order_bloc.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'dart:developer'; - -import 'package:bloc/bloc.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; -import 'package:freezed_annotation/freezed_annotation.dart'; - -import 'package:enaklo_pos/data/datasources/order_remote_datasource.dart'; - -part 'sync_order_bloc.freezed.dart'; -part 'sync_order_event.dart'; -part 'sync_order_state.dart'; - -class SyncOrderBloc extends Bloc { - final OrderRemoteDatasource orderRemoteDatasource; - SyncOrderBloc( - this.orderRemoteDatasource, - ) : super(const _Initial()) { - on<_SyncOrder>((event, emit) async { - emit(const _Loading()); - log("🔄 SyncOrderBloc: Starting sync process"); - final dataOrderNotSynced = - await ProductLocalDatasource.instance.getOrderByIsNotSync(); - log("🔄 SyncOrderBloc: Found ${dataOrderNotSynced.length} orders to sync"); - for (var order in dataOrderNotSynced) { - final orderItem = await ProductLocalDatasource.instance - .getOrderItemByOrderId(order.id!); - - final newOrder = order.copyWith(orderItems: orderItem); - log("🔄 SyncOrderBloc: Syncing order ${order.id} to API"); - log("Order: ${newOrder.toMap()}"); - final result = await orderRemoteDatasource.saveOrder(newOrder); - if (result) { - await ProductLocalDatasource.instance.updateOrderIsSync(order.id!); - } else { - emit(const _Error('Sync Order Failed')); - return; - } - } - emit(const _Loaded()); - }); - } -} diff --git a/lib/presentation/setting/bloc/sync_order/sync_order_bloc.freezed.dart b/lib/presentation/setting/bloc/sync_order/sync_order_bloc.freezed.dart deleted file mode 100644 index 271f7e2..0000000 --- a/lib/presentation/setting/bloc/sync_order/sync_order_bloc.freezed.dart +++ /dev/null @@ -1,866 +0,0 @@ -// coverage:ignore-file -// GENERATED CODE - DO NOT MODIFY BY HAND -// ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark - -part of 'sync_order_bloc.dart'; - -// ************************************************************************** -// FreezedGenerator -// ************************************************************************** - -T _$identity(T value) => value; - -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); - -/// @nodoc -mixin _$SyncOrderEvent { - @optionalTypeArgs - TResult when({ - required TResult Function() started, - required TResult Function() syncOrder, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? started, - TResult? Function()? syncOrder, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? started, - TResult Function()? syncOrder, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(_Started value) started, - required TResult Function(_SyncOrder value) syncOrder, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Started value)? started, - TResult? Function(_SyncOrder value)? syncOrder, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Started value)? started, - TResult Function(_SyncOrder value)? syncOrder, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $SyncOrderEventCopyWith<$Res> { - factory $SyncOrderEventCopyWith( - SyncOrderEvent value, $Res Function(SyncOrderEvent) then) = - _$SyncOrderEventCopyWithImpl<$Res, SyncOrderEvent>; -} - -/// @nodoc -class _$SyncOrderEventCopyWithImpl<$Res, $Val extends SyncOrderEvent> - implements $SyncOrderEventCopyWith<$Res> { - _$SyncOrderEventCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of SyncOrderEvent - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc -abstract class _$$StartedImplCopyWith<$Res> { - factory _$$StartedImplCopyWith( - _$StartedImpl value, $Res Function(_$StartedImpl) then) = - __$$StartedImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$StartedImplCopyWithImpl<$Res> - extends _$SyncOrderEventCopyWithImpl<$Res, _$StartedImpl> - implements _$$StartedImplCopyWith<$Res> { - __$$StartedImplCopyWithImpl( - _$StartedImpl _value, $Res Function(_$StartedImpl) _then) - : super(_value, _then); - - /// Create a copy of SyncOrderEvent - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$StartedImpl implements _Started { - const _$StartedImpl(); - - @override - String toString() { - return 'SyncOrderEvent.started()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$StartedImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() started, - required TResult Function() syncOrder, - }) { - return started(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? started, - TResult? Function()? syncOrder, - }) { - return started?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? started, - TResult Function()? syncOrder, - required TResult orElse(), - }) { - if (started != null) { - return started(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Started value) started, - required TResult Function(_SyncOrder value) syncOrder, - }) { - return started(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Started value)? started, - TResult? Function(_SyncOrder value)? syncOrder, - }) { - return started?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Started value)? started, - TResult Function(_SyncOrder value)? syncOrder, - required TResult orElse(), - }) { - if (started != null) { - return started(this); - } - return orElse(); - } -} - -abstract class _Started implements SyncOrderEvent { - const factory _Started() = _$StartedImpl; -} - -/// @nodoc -abstract class _$$SyncOrderImplCopyWith<$Res> { - factory _$$SyncOrderImplCopyWith( - _$SyncOrderImpl value, $Res Function(_$SyncOrderImpl) then) = - __$$SyncOrderImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$SyncOrderImplCopyWithImpl<$Res> - extends _$SyncOrderEventCopyWithImpl<$Res, _$SyncOrderImpl> - implements _$$SyncOrderImplCopyWith<$Res> { - __$$SyncOrderImplCopyWithImpl( - _$SyncOrderImpl _value, $Res Function(_$SyncOrderImpl) _then) - : super(_value, _then); - - /// Create a copy of SyncOrderEvent - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$SyncOrderImpl implements _SyncOrder { - const _$SyncOrderImpl(); - - @override - String toString() { - return 'SyncOrderEvent.syncOrder()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$SyncOrderImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() started, - required TResult Function() syncOrder, - }) { - return syncOrder(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? started, - TResult? Function()? syncOrder, - }) { - return syncOrder?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? started, - TResult Function()? syncOrder, - required TResult orElse(), - }) { - if (syncOrder != null) { - return syncOrder(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Started value) started, - required TResult Function(_SyncOrder value) syncOrder, - }) { - return syncOrder(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Started value)? started, - TResult? Function(_SyncOrder value)? syncOrder, - }) { - return syncOrder?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Started value)? started, - TResult Function(_SyncOrder value)? syncOrder, - required TResult orElse(), - }) { - if (syncOrder != null) { - return syncOrder(this); - } - return orElse(); - } -} - -abstract class _SyncOrder implements SyncOrderEvent { - const factory _SyncOrder() = _$SyncOrderImpl; -} - -/// @nodoc -mixin _$SyncOrderState { - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function() loaded, - required TResult Function(String message) error, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function()? loaded, - TResult? Function(String message)? error, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function()? loaded, - TResult Function(String message)? error, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Loaded value) loaded, - required TResult Function(_Error value) error, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Loaded value)? loaded, - TResult? Function(_Error value)? error, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Loaded value)? loaded, - TResult Function(_Error value)? error, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $SyncOrderStateCopyWith<$Res> { - factory $SyncOrderStateCopyWith( - SyncOrderState value, $Res Function(SyncOrderState) then) = - _$SyncOrderStateCopyWithImpl<$Res, SyncOrderState>; -} - -/// @nodoc -class _$SyncOrderStateCopyWithImpl<$Res, $Val extends SyncOrderState> - implements $SyncOrderStateCopyWith<$Res> { - _$SyncOrderStateCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - /// Create a copy of SyncOrderState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc -abstract class _$$InitialImplCopyWith<$Res> { - factory _$$InitialImplCopyWith( - _$InitialImpl value, $Res Function(_$InitialImpl) then) = - __$$InitialImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$InitialImplCopyWithImpl<$Res> - extends _$SyncOrderStateCopyWithImpl<$Res, _$InitialImpl> - implements _$$InitialImplCopyWith<$Res> { - __$$InitialImplCopyWithImpl( - _$InitialImpl _value, $Res Function(_$InitialImpl) _then) - : super(_value, _then); - - /// Create a copy of SyncOrderState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$InitialImpl implements _Initial { - const _$InitialImpl(); - - @override - String toString() { - return 'SyncOrderState.initial()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$InitialImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function() loaded, - required TResult Function(String message) error, - }) { - return initial(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function()? loaded, - TResult? Function(String message)? error, - }) { - return initial?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function()? loaded, - TResult Function(String message)? error, - required TResult orElse(), - }) { - if (initial != null) { - return initial(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Loaded value) loaded, - required TResult Function(_Error value) error, - }) { - return initial(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Loaded value)? loaded, - TResult? Function(_Error value)? error, - }) { - return initial?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Loaded value)? loaded, - TResult Function(_Error value)? error, - required TResult orElse(), - }) { - if (initial != null) { - return initial(this); - } - return orElse(); - } -} - -abstract class _Initial implements SyncOrderState { - const factory _Initial() = _$InitialImpl; -} - -/// @nodoc -abstract class _$$LoadingImplCopyWith<$Res> { - factory _$$LoadingImplCopyWith( - _$LoadingImpl value, $Res Function(_$LoadingImpl) then) = - __$$LoadingImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$LoadingImplCopyWithImpl<$Res> - extends _$SyncOrderStateCopyWithImpl<$Res, _$LoadingImpl> - implements _$$LoadingImplCopyWith<$Res> { - __$$LoadingImplCopyWithImpl( - _$LoadingImpl _value, $Res Function(_$LoadingImpl) _then) - : super(_value, _then); - - /// Create a copy of SyncOrderState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$LoadingImpl implements _Loading { - const _$LoadingImpl(); - - @override - String toString() { - return 'SyncOrderState.loading()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$LoadingImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function() loaded, - required TResult Function(String message) error, - }) { - return loading(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function()? loaded, - TResult? Function(String message)? error, - }) { - return loading?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function()? loaded, - TResult Function(String message)? error, - required TResult orElse(), - }) { - if (loading != null) { - return loading(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Loaded value) loaded, - required TResult Function(_Error value) error, - }) { - return loading(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Loaded value)? loaded, - TResult? Function(_Error value)? error, - }) { - return loading?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Loaded value)? loaded, - TResult Function(_Error value)? error, - required TResult orElse(), - }) { - if (loading != null) { - return loading(this); - } - return orElse(); - } -} - -abstract class _Loading implements SyncOrderState { - const factory _Loading() = _$LoadingImpl; -} - -/// @nodoc -abstract class _$$LoadedImplCopyWith<$Res> { - factory _$$LoadedImplCopyWith( - _$LoadedImpl value, $Res Function(_$LoadedImpl) then) = - __$$LoadedImplCopyWithImpl<$Res>; -} - -/// @nodoc -class __$$LoadedImplCopyWithImpl<$Res> - extends _$SyncOrderStateCopyWithImpl<$Res, _$LoadedImpl> - implements _$$LoadedImplCopyWith<$Res> { - __$$LoadedImplCopyWithImpl( - _$LoadedImpl _value, $Res Function(_$LoadedImpl) _then) - : super(_value, _then); - - /// Create a copy of SyncOrderState - /// with the given fields replaced by the non-null parameter values. -} - -/// @nodoc - -class _$LoadedImpl implements _Loaded { - const _$LoadedImpl(); - - @override - String toString() { - return 'SyncOrderState.loaded()'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && other is _$LoadedImpl); - } - - @override - int get hashCode => runtimeType.hashCode; - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function() loaded, - required TResult Function(String message) error, - }) { - return loaded(); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function()? loaded, - TResult? Function(String message)? error, - }) { - return loaded?.call(); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function()? loaded, - TResult Function(String message)? error, - required TResult orElse(), - }) { - if (loaded != null) { - return loaded(); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Loaded value) loaded, - required TResult Function(_Error value) error, - }) { - return loaded(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Loaded value)? loaded, - TResult? Function(_Error value)? error, - }) { - return loaded?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Loaded value)? loaded, - TResult Function(_Error value)? error, - required TResult orElse(), - }) { - if (loaded != null) { - return loaded(this); - } - return orElse(); - } -} - -abstract class _Loaded implements SyncOrderState { - const factory _Loaded() = _$LoadedImpl; -} - -/// @nodoc -abstract class _$$ErrorImplCopyWith<$Res> { - factory _$$ErrorImplCopyWith( - _$ErrorImpl value, $Res Function(_$ErrorImpl) then) = - __$$ErrorImplCopyWithImpl<$Res>; - @useResult - $Res call({String message}); -} - -/// @nodoc -class __$$ErrorImplCopyWithImpl<$Res> - extends _$SyncOrderStateCopyWithImpl<$Res, _$ErrorImpl> - implements _$$ErrorImplCopyWith<$Res> { - __$$ErrorImplCopyWithImpl( - _$ErrorImpl _value, $Res Function(_$ErrorImpl) _then) - : super(_value, _then); - - /// Create a copy of SyncOrderState - /// with the given fields replaced by the non-null parameter values. - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? message = null, - }) { - return _then(_$ErrorImpl( - null == message - ? _value.message - : message // ignore: cast_nullable_to_non_nullable - as String, - )); - } -} - -/// @nodoc - -class _$ErrorImpl implements _Error { - const _$ErrorImpl(this.message); - - @override - final String message; - - @override - String toString() { - return 'SyncOrderState.error(message: $message)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$ErrorImpl && - (identical(other.message, message) || other.message == message)); - } - - @override - int get hashCode => Object.hash(runtimeType, message); - - /// Create a copy of SyncOrderState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - @override - @pragma('vm:prefer-inline') - _$$ErrorImplCopyWith<_$ErrorImpl> get copyWith => - __$$ErrorImplCopyWithImpl<_$ErrorImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() initial, - required TResult Function() loading, - required TResult Function() loaded, - required TResult Function(String message) error, - }) { - return error(message); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? initial, - TResult? Function()? loading, - TResult? Function()? loaded, - TResult? Function(String message)? error, - }) { - return error?.call(message); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? initial, - TResult Function()? loading, - TResult Function()? loaded, - TResult Function(String message)? error, - required TResult orElse(), - }) { - if (error != null) { - return error(message); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(_Initial value) initial, - required TResult Function(_Loading value) loading, - required TResult Function(_Loaded value) loaded, - required TResult Function(_Error value) error, - }) { - return error(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(_Initial value)? initial, - TResult? Function(_Loading value)? loading, - TResult? Function(_Loaded value)? loaded, - TResult? Function(_Error value)? error, - }) { - return error?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(_Initial value)? initial, - TResult Function(_Loading value)? loading, - TResult Function(_Loaded value)? loaded, - TResult Function(_Error value)? error, - required TResult orElse(), - }) { - if (error != null) { - return error(this); - } - return orElse(); - } -} - -abstract class _Error implements SyncOrderState { - const factory _Error(final String message) = _$ErrorImpl; - - String get message; - - /// Create a copy of SyncOrderState - /// with the given fields replaced by the non-null parameter values. - @JsonKey(includeFromJson: false, includeToJson: false) - _$$ErrorImplCopyWith<_$ErrorImpl> get copyWith => - throw _privateConstructorUsedError; -} diff --git a/lib/presentation/setting/bloc/sync_order/sync_order_event.dart b/lib/presentation/setting/bloc/sync_order/sync_order_event.dart deleted file mode 100644 index fedb95a..0000000 --- a/lib/presentation/setting/bloc/sync_order/sync_order_event.dart +++ /dev/null @@ -1,7 +0,0 @@ -part of 'sync_order_bloc.dart'; - -@freezed -class SyncOrderEvent with _$SyncOrderEvent { - const factory SyncOrderEvent.started() = _Started; - const factory SyncOrderEvent.syncOrder() = _SyncOrder; -} \ No newline at end of file diff --git a/lib/presentation/setting/bloc/sync_order/sync_order_state.dart b/lib/presentation/setting/bloc/sync_order/sync_order_state.dart deleted file mode 100644 index 0a17fde..0000000 --- a/lib/presentation/setting/bloc/sync_order/sync_order_state.dart +++ /dev/null @@ -1,10 +0,0 @@ -part of 'sync_order_bloc.dart'; - -@freezed -class SyncOrderState with _$SyncOrderState { - const factory SyncOrderState.initial() = _Initial; - const factory SyncOrderState.loading() = _Loading; - const factory SyncOrderState.loaded() = - _Loaded; - const factory SyncOrderState.error(String message) = _Error; -} diff --git a/lib/presentation/setting/bloc/update_printer/update_printer_bloc.dart b/lib/presentation/setting/bloc/update_printer/update_printer_bloc.dart index 214d4cd..7c62112 100644 --- a/lib/presentation/setting/bloc/update_printer/update_printer_bloc.dart +++ b/lib/presentation/setting/bloc/update_printer/update_printer_bloc.dart @@ -1,5 +1,5 @@ import 'package:bloc/bloc.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; +import 'package:enaklo_pos/data/datasources/printer/printer_local_datasource.dart'; import 'package:enaklo_pos/data/models/response/print_model.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -11,7 +11,7 @@ class UpdatePrinterBloc extends Bloc { UpdatePrinterBloc() : super(_Initial()) { on<_UpdatePrinter>((event, emit) async { emit(_Loading()); - await ProductLocalDatasource.instance.updatePrinter( + await PrinterLocalDatasource.instance.updatePrinter( event.print, event.print.id!, ); diff --git a/lib/presentation/setting/models/printer_model.dart b/lib/presentation/setting/models/printer_model.dart index 209a5ab..4fd9669 100644 --- a/lib/presentation/setting/models/printer_model.dart +++ b/lib/presentation/setting/models/printer_model.dart @@ -17,15 +17,144 @@ enum PrinterType { } class PrinterModel { + final int? id; + final String code; final String name; final String ipAddress; final String size; final PrinterType type; + final DateTime? createdAt; + final DateTime? updatedAt; PrinterModel({ + this.id, + required this.code, required this.name, required this.ipAddress, required this.size, required this.type, + this.createdAt, + this.updatedAt, }); + + // Factory constructor to create PrinterModel from database map + factory PrinterModel.fromMap(Map map) { + return PrinterModel( + id: map['id'] as int?, + code: map['code'] as String, + name: map['name'] as String, + ipAddress: map['ip_address'] as String, + size: map['size'] as String, + type: PrinterType.fromValue(map['type'] as String), + createdAt: map['created_at'] != null + ? DateTime.parse(map['created_at'] as String) + : null, + updatedAt: map['updated_at'] != null + ? DateTime.parse(map['updated_at'] as String) + : null, + ); + } + + // Convert to map for database insertion (excluding id, including timestamps) + Map toMapForInsert() { + final now = DateTime.now().toIso8601String(); + return { + 'code': code, + 'name': name, + 'ip_address': ipAddress, + 'size': size, + 'type': type.value, + 'created_at': now, + 'updated_at': now, + }; + } + + // Convert to map for database update (excluding id and created_at) + Map toMapForUpdate() { + return { + 'code': code, + 'name': name, + 'ip_address': ipAddress, + 'size': size, + 'type': type.value, + 'updated_at': DateTime.now().toIso8601String(), + }; + } + + // Convert to complete map (including id) + Map toMap() { + return { + 'id': id, + 'code': code, + 'name': name, + 'ip_address': ipAddress, + 'size': size, + 'type': type.value, + 'created_at': createdAt?.toIso8601String(), + 'updated_at': updatedAt?.toIso8601String(), + }; + } + + // Copy with method for creating modified instances + PrinterModel copyWith({ + int? id, + String? code, + String? name, + String? ipAddress, + String? size, + PrinterType? type, + DateTime? createdAt, + DateTime? updatedAt, + }) { + return PrinterModel( + id: id ?? this.id, + code: code ?? this.code, + name: name ?? this.name, + ipAddress: ipAddress ?? this.ipAddress, + size: size ?? this.size, + type: type ?? this.type, + createdAt: createdAt ?? this.createdAt, + updatedAt: updatedAt ?? this.updatedAt, + ); + } + + // Equality and hashCode for comparing instances + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + return other is PrinterModel && + other.id == id && + other.code == code && + other.name == name && + other.ipAddress == ipAddress && + other.size == size && + other.type == type; + } + + @override + int get hashCode { + return Object.hash(id, code, name, ipAddress, size, type); + } + + // String representation for debugging + @override + String toString() { + return 'PrinterModel(id: $id, code: $code, name: $name, ipAddress: $ipAddress, size: $size, type: ${type.value}, createdAt: $createdAt, updatedAt: $updatedAt)'; + } + + // Validation methods + bool get isValid { + return code.isNotEmpty && + name.isNotEmpty && + ipAddress.isNotEmpty && + size.isNotEmpty; + } + + String? get validationError { + if (code.isEmpty) return 'Printer code cannot be empty'; + if (name.isEmpty) return 'Printer name cannot be empty'; + if (ipAddress.isEmpty) return 'IP address cannot be empty'; + if (size.isEmpty) return 'Printer size cannot be empty'; + return null; + } } diff --git a/lib/presentation/setting/pages/sync_data_page.dart b/lib/presentation/setting/pages/sync_data_page.dart index e5b690c..e40c8f2 100644 --- a/lib/presentation/setting/pages/sync_data_page.dart +++ b/lib/presentation/setting/pages/sync_data_page.dart @@ -4,8 +4,6 @@ import 'package:enaklo_pos/core/constants/colors.dart'; import 'package:enaklo_pos/presentation/setting/widgets/settings_title.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; -import 'package:enaklo_pos/presentation/setting/bloc/sync_order/sync_order_bloc.dart'; import 'package:enaklo_pos/presentation/setting/bloc/sync_product/sync_product_bloc.dart'; class SyncDataPage extends StatefulWidget { @@ -114,53 +112,53 @@ class _SyncDataPageState extends State { fontWeight: FontWeight.w500, ), ), - BlocConsumer( - listener: (context, state) { - state.maybeWhen( - orElse: () {}, - error: (message) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(message), - backgroundColor: Colors.red, - ), - ); - }, - loaded: () { - // ScaffoldMessenger.of(context).showSnackBar( - // const SnackBar( - // content: Text('Sync Order Success'), - // backgroundColor: Colors.green, - // ), - // ); - }, - ); - }, - builder: (context, state) { - return state.maybeWhen( - orElse: () { - return Button.filled( - width: 100, - height: 40, - onPressed: () { - log("🔘 Sync Order button pressed"); - log("🔘 SyncOrderBloc instance: ${context.read()}"); - context - .read() - .add(const SyncOrderEvent.syncOrder()); - log("🔘 SyncOrderEvent.syncOrder dispatched"); - }, - label: 'Sinkronasikan', - ); - }, - loading: () { - return const Center( - child: CircularProgressIndicator(), - ); - }, - ); - }, - ) + // BlocConsumer( + // listener: (context, state) { + // state.maybeWhen( + // orElse: () {}, + // error: (message) { + // ScaffoldMessenger.of(context).showSnackBar( + // SnackBar( + // content: Text(message), + // backgroundColor: Colors.red, + // ), + // ); + // }, + // loaded: () { + // // ScaffoldMessenger.of(context).showSnackBar( + // // const SnackBar( + // // content: Text('Sync Order Success'), + // // backgroundColor: Colors.green, + // // ), + // // ); + // }, + // ); + // }, + // builder: (context, state) { + // return state.maybeWhen( + // orElse: () { + // return Button.filled( + // width: 100, + // height: 40, + // onPressed: () { + // log("🔘 Sync Order button pressed"); + // log("🔘 SyncOrderBloc instance: ${context.read()}"); + // context + // .read() + // .add(const SyncOrderEvent.syncOrder()); + // log("🔘 SyncOrderEvent.syncOrder dispatched"); + // }, + // label: 'Sinkronasikan', + // ); + // }, + // loading: () { + // return const Center( + // child: CircularProgressIndicator(), + // ); + // }, + // ); + // }, + // ) ], ), ), diff --git a/lib/presentation/table/blocs/generate_table/generate_table_bloc.dart b/lib/presentation/table/blocs/generate_table/generate_table_bloc.dart index ba70da5..0f00287 100644 --- a/lib/presentation/table/blocs/generate_table/generate_table_bloc.dart +++ b/lib/presentation/table/blocs/generate_table/generate_table_bloc.dart @@ -1,6 +1,5 @@ import 'package:bloc/bloc.dart'; import 'package:flutter/material.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'generate_table_event.dart'; diff --git a/lib/presentation/table/blocs/get_table/get_table_bloc.dart b/lib/presentation/table/blocs/get_table/get_table_bloc.dart index 71f35bd..e9193ba 100644 --- a/lib/presentation/table/blocs/get_table/get_table_bloc.dart +++ b/lib/presentation/table/blocs/get_table/get_table_bloc.dart @@ -1,6 +1,5 @@ import 'package:enaklo_pos/data/datasources/table_remote_datasource.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; import 'package:enaklo_pos/data/models/response/table_model.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; diff --git a/lib/presentation/table/blocs/update_table/update_table_bloc.dart b/lib/presentation/table/blocs/update_table/update_table_bloc.dart index aec6e7c..695589f 100644 --- a/lib/presentation/table/blocs/update_table/update_table_bloc.dart +++ b/lib/presentation/table/blocs/update_table/update_table_bloc.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; import 'package:enaklo_pos/data/models/response/table_model.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; @@ -13,9 +12,6 @@ class UpdateTableBloc extends Bloc { UpdateTableBloc() : super(_Initial()) { on<_UpdateTable>((event, emit) async { emit(_Loading()); - await ProductLocalDatasource.instance.updateTable( - event.table, - ); emit(_Success('Update Table Success')); }); } diff --git a/lib/presentation/table/pages/payment_table_page.dart.old b/lib/presentation/table/pages/payment_table_page.dart.old deleted file mode 100644 index d7c4ef7..0000000 --- a/lib/presentation/table/pages/payment_table_page.dart.old +++ /dev/null @@ -1,1330 +0,0 @@ -// ignore_for_file: public_member_api_docs, sort_constructors_first -import 'dart:developer'; - -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -import 'package:enaklo_pos/core/extensions/int_ext.dart'; -import 'package:enaklo_pos/core/extensions/string_ext.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; -import 'package:enaklo_pos/data/models/response/table_model.dart'; -import 'package:enaklo_pos/presentation/home/bloc/checkout/checkout_bloc.dart'; -import 'package:enaklo_pos/presentation/home/bloc/get_table_status/get_table_status_bloc.dart'; -import 'package:enaklo_pos/presentation/home/bloc/order/order_bloc.dart'; -import 'package:enaklo_pos/presentation/home/bloc/payment_methods/payment_methods_bloc.dart'; -import 'package:enaklo_pos/presentation/home/bloc/status_table/status_table_bloc.dart'; -import 'package:enaklo_pos/presentation/home/models/product_quantity.dart'; -import 'package:enaklo_pos/presentation/home/models/order_type.dart'; -import 'package:enaklo_pos/presentation/home/widgets/order_menu.dart'; -import 'package:enaklo_pos/presentation/home/widgets/success_payment_dialog.dart'; -import 'package:enaklo_pos/presentation/home/widgets/order_type_selector.dart'; -import 'package:enaklo_pos/presentation/table/models/draft_order_model.dart'; -import 'package:enaklo_pos/data/models/response/payment_methods_response_model.dart'; - -import 'package:enaklo_pos/core/extensions/build_context_ext.dart'; - -import '../../../core/components/buttons.dart'; -import '../../../core/components/spaces.dart'; -import '../../../core/constants/colors.dart'; - -class PaymentTablePage extends StatefulWidget { - final DraftOrderModel? draftOrder; - final TableModel? table; - const PaymentTablePage({ - super.key, - this.draftOrder, - this.table, - }); - - @override - State createState() => _PaymentTablePageState(); -} - -class _PaymentTablePageState extends State { - final totalPriceController = TextEditingController(); - final customerController = TextEditingController(); - PaymentMethod? selectedPaymentMethod; - int totalPriceFinal = 0; - int discountAmountFinal = 0; - - // Helper method to handle post-payment cleanup - Future _handlePostPaymentCleanup() async { - if (widget.table != null && widget.draftOrder?.id != null) { - // Update table status to available - // final newTable = TableModel( - // id: widget.table!.id, - // tableName: widget.table!.tableName, - // status: 'available', - // orderId: 0, - // paymentAmount: 0, - // startTime: DateTime.now().toIso8601String(), - // position: widget.table!.position, - // ); - - // Update table status - // await ProductLocalDatasource.instance.updateStatusTable(newTable); - - // Remove draft order - await ProductLocalDatasource.instance - .removeDraftOrderById(widget.draftOrder!.id!); - - // Refresh table status - context.read().add( - GetTableStatusEvent.getTablesStatus('all'), - ); - - log("Table ${widget.table!.tableName} freed up and draft order removed"); - } - - // Safely navigate back - pop multiple times to get to table management - // Pop the success dialog first, then the payment page - if (Navigator.of(context).canPop()) { - Navigator.of(context).pop(); // Pop success dialog - if (Navigator.of(context).canPop()) { - Navigator.of(context).pop(); // Pop payment page - } - } - } - - @override - void initState() { - context - .read() - .add(GetTableStatusEvent.getTablesStatus('available')); - context - .read() - .add(PaymentMethodsEvent.fetchPaymentMethods()); - super.initState(); - - // Set a default payment method in case API fails - selectedPaymentMethod = PaymentMethod( - id: "4b1c0d21-c98a-4fc0-a2f9-8d90a0c9d905", - organizationId: "3e8b1793-d18b-40c4-a03d-0c6480b630c7", - name: "CASH", - type: "cash", - isActive: true, - createdAt: DateTime.tryParse('2025-07-18T03:43:13.857048+07:00'), - updatedAt: DateTime.tryParse('2025-07-18T03:43:13.857048+07:00'), - ); - } - - @override - void dispose() { - totalPriceController.dispose(); - customerController.dispose(); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return SafeArea( - child: Hero( - tag: 'table_payment_screen', - child: Scaffold( - appBar: AppBar( - title: Text('Payment - Table ${widget.table?.tableName}'), - backgroundColor: AppColors.primary, - foregroundColor: Colors.white, - leading: IconButton( - icon: const Icon(Icons.arrow_back), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - actions: [ - TextButton( - onPressed: () { - showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: const Text('Kembali'), - content: const Text( - 'Apakah Anda yakin ingin kembali? Order akan tetap tersimpan.'), - actions: [ - TextButton( - onPressed: () { - Navigator.of(context).pop(); // Close dialog - }, - child: const Text('Tidak'), - ), - TextButton( - onPressed: () { - Navigator.of(context).pop(); // Close dialog - Navigator.of(context) - .pop(); // Go back to previous page - }, - child: const Text('Ya'), - ), - ], - ); - }, - ); - }, - child: const Text( - 'Kembali', - style: TextStyle( - color: Colors.white, fontWeight: FontWeight.bold), - ), - ), - ], - ), - body: Row( - children: [ - // LEFT CONTENT - Expanded( - flex: 2, - child: Align( - alignment: Alignment.topCenter, - child: SingleChildScrollView( - padding: const EdgeInsets.all(24.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'Konfirmasi', - style: TextStyle( - color: AppColors.primary, - fontSize: 20, - fontWeight: FontWeight.w600, - ), - ), - Text( - 'Orders Table ${widget.table?.tableName}', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w500, - ), - ), - ], - ), - const SpaceHeight(8.0), - const Divider(), - const SpaceHeight(24.0), - const Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - 'Item', - style: TextStyle( - color: AppColors.primary, - fontSize: 16, - fontWeight: FontWeight.w600, - ), - ), - SizedBox( - width: 160, - ), - SizedBox( - width: 50.0, - child: Text( - 'Qty', - style: TextStyle( - color: AppColors.primary, - fontSize: 16, - fontWeight: FontWeight.w600, - ), - ), - ), - SizedBox( - child: Text( - 'Price', - style: TextStyle( - color: AppColors.primary, - fontSize: 16, - fontWeight: FontWeight.w600, - ), - ), - ), - ], - ), - const SpaceHeight(8), - const Divider(), - const SpaceHeight(8), - BlocBuilder( - builder: (context, state) { - return state.maybeWhen( - orElse: () => const Center( - child: Text('No Items'), - ), - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) { - if (products.isEmpty) { - return const Center( - child: Text('No Items'), - ); - } - return ListView.separated( - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - itemBuilder: (context, index) => - OrderMenu(data: products[index]), - separatorBuilder: (context, index) => - const SpaceHeight(16.0), - itemCount: products.length, - ); - }, - ); - }, - ), - const SpaceHeight(16.0), - - const SpaceHeight(8.0), - const Divider(), - const SpaceHeight(8.0), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const Text( - 'Sub total', - style: TextStyle(color: AppColors.grey), - ), - BlocBuilder( - builder: (context, state) { - final price = state.maybeWhen( - orElse: () => 0, - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) => - products.fold( - 0, - (previousValue, element) => - previousValue + - (element.product.price! * - element.quantity), - )); - return Text( - price.currencyFormatRp, - style: const TextStyle( - color: AppColors.primary, - fontWeight: FontWeight.w600, - ), - ); - }, - ), - ], - ), - const SpaceHeight(16.0), - - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - 'Diskon', - style: TextStyle(color: AppColors.grey), - ), - BlocBuilder( - builder: (context, state) { - final discount = state.maybeWhen( - orElse: () => 0, - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) { - log("discountAmount: $discountAmount"); - return discountAmount; - }); - - discountAmountFinal = discount.toInt(); - - return Text( - discount.toInt().currencyFormatRp, - style: TextStyle( - color: AppColors.primary, - fontWeight: FontWeight.w600, - ), - ); - }, - ), - ], - ), - const SpaceHeight(16.0), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const Text( - 'Pajak PB1', - style: TextStyle(color: AppColors.grey), - ), - BlocBuilder( - builder: (context, state) { - final tax = state.maybeWhen( - orElse: () => 0, - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) => - tax, - ); - final price = state.maybeWhen( - orElse: () => 0, - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) => - products.fold( - 0, - (previousValue, element) => - previousValue + - (element.product.price! * - element.quantity), - ), - ); - - final discount = state.maybeWhen( - orElse: () => 0, - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) { - return discountAmount; - }); - - final subTotal = price - discount; - final finalTax = subTotal * (tax / 100); - return Text( - '$tax % (${finalTax.toInt().currencyFormatRp})', - style: const TextStyle( - color: AppColors.primary, - fontWeight: FontWeight.w600, - ), - ); - }, - ), - ], - ), - const SpaceHeight(16.0), - - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const Text( - 'Biaya Layanan', - style: TextStyle(color: AppColors.grey), - ), - BlocBuilder( - builder: (context, state) { - state.maybeWhen( - orElse: () => 0, - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) => - tax, - ); - final price = state.maybeWhen( - orElse: () => 0, - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) => - products.fold( - 0, - (previousValue, element) => - previousValue + - (element.product.price! * - element.quantity), - ), - ); - - final discount = state.maybeWhen( - orElse: () => 0, - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) { - return discountAmount; - }); - - final serviceCharge = state.maybeWhen( - orElse: () => 0, - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) => - serviceCharge, - ); - - final subTotal = price - discount; - final finalServiceCharge = - subTotal * (serviceCharge / 100); - - return Text( - '$serviceCharge % (${finalServiceCharge.toInt().currencyFormatRp}) ', - style: const TextStyle( - color: AppColors.primary, - fontWeight: FontWeight.w600, - ), - ); - }, - ), - ], - ), - const SpaceHeight(16.0), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const Text( - 'Total', - style: TextStyle( - color: AppColors.grey, - fontWeight: FontWeight.bold, - fontSize: 16), - ), - BlocBuilder( - builder: (context, state) { - final price = state.maybeWhen( - orElse: () => 0, - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) => - products.fold( - 0, - (previousValue, element) => - previousValue + - (element.product.price! * - element.quantity), - ), - ); - - final discount = state.maybeWhen( - orElse: () => 0, - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) { - return discountAmount; - }); - - final serviceCharge = state.maybeWhen( - orElse: () => 0, - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) => - serviceCharge, - ); - - final tax = state.maybeWhen( - orElse: () => 0, - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) => - tax, - ); - - final subTotal = price - discount; - final finalTax = subTotal * (tax / 100); - final service = - subTotal * (serviceCharge / 100); - final total = subTotal + finalTax + service; - totalPriceFinal = total.ceil(); - totalPriceController.text = - total.ceil().toString(); - return Text( - total.ceil().currencyFormatRp, - style: const TextStyle( - color: AppColors.primary, - fontWeight: FontWeight.w600, - fontSize: 16, - ), - ); - }, - ), - ], - ), - // const SpaceHeight(20.0), - // Button.filled( - // onPressed: () {}, - // label: 'Lanjutkan Pembayaran', - // ), - ], - ), - ), - ), - ), - - // RIGHT CONTENT - Expanded( - flex: 3, - child: Align( - alignment: Alignment.topCenter, - child: Stack( - children: [ - SingleChildScrollView( - padding: const EdgeInsets.all(24.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - 'Pembayaran', - style: TextStyle( - color: AppColors.primary, - fontSize: 20, - fontWeight: FontWeight.w600, - ), - ), - const SpaceHeight(16.0), - const Divider(), - const SpaceHeight(8.0), - const Text( - 'Customer', - style: TextStyle( - color: AppColors.primary, - fontSize: 16, - fontWeight: FontWeight.w500, - ), - ), - const SpaceHeight(12.0), - BlocBuilder( - builder: (context, state) { - return state.maybeWhen( - orElse: () { - return SizedBox.shrink(); - }, - loaded: ( - items, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) { - customerController.text = draftName; - return TextFormField( - readOnly: true, - controller: customerController, - decoration: InputDecoration( - border: OutlineInputBorder( - borderRadius: - BorderRadius.circular(8.0), - ), - hintText: 'Nama Customer', - ), - ); - }, - ); - }, - ), - const SpaceHeight(8.0), - const Divider(), - const SpaceHeight(8.0), - const OrderTypeSelector(), - const SpaceHeight(8.0), - const Divider(), - const SpaceHeight(8.0), - const Text( - 'Metode Bayar', - style: TextStyle( - color: AppColors.primary, - fontSize: 20, - fontWeight: FontWeight.w600, - ), - ), - const SpaceHeight(12.0), - BlocBuilder( - builder: (context, state) { - return state.maybeWhen( - orElse: () => const Center( - child: CircularProgressIndicator(), - ), - loading: () => const Center( - child: Column( - children: [ - CircularProgressIndicator(), - SizedBox(height: 8.0), - Text('Loading payment methods...'), - ], - ), - ), - error: (message) => Column( - children: [ - Center( - child: Text( - 'Error loading payment methods: $message'), - ), - const SpaceHeight(16.0), - Button.filled( - onPressed: () { - context - .read() - .add(PaymentMethodsEvent - .fetchPaymentMethods()); - }, - label: 'Retry', - ), - ], - ), - loaded: (paymentMethods) { - log("Loaded ${paymentMethods.length} payment methods"); - paymentMethods.forEach((method) { - log("Payment method: ${method.name} (ID: ${method.id})"); - }); - if (paymentMethods.isEmpty) { - return Column( - children: [ - const Center( - child: Text( - 'No payment methods available'), - ), - const SpaceHeight(16.0), - Button.filled( - onPressed: () { - context - .read() - .add(PaymentMethodsEvent - .fetchPaymentMethods()); - }, - label: 'Retry', - ), - ], - ); - } - - // Set default selected payment method if none selected or if current selection is not in the list - if (selectedPaymentMethod == null || - !paymentMethods.any((method) => - method.id == - selectedPaymentMethod?.id)) { - selectedPaymentMethod = - paymentMethods.first; - } - - return Wrap( - spacing: 12.0, - runSpacing: 8.0, - children: paymentMethods.map((method) { - final isSelected = - selectedPaymentMethod?.id == - method.id; - return Container( - constraints: const BoxConstraints( - minWidth: 120.0, - ), - decoration: isSelected - ? BoxDecoration( - border: Border.all( - color: AppColors.primary, - width: 2.0, - ), - borderRadius: - BorderRadius.circular( - 8.0), - ) - : null, - child: isSelected - ? Button.filled( - width: double.infinity, - height: 50.0, - onPressed: () { - setState(() { - selectedPaymentMethod = - method; - }); - }, - label: method.name - ?.isNotEmpty == - true - ? method.name! - : 'Unknown', - ) - : Button.outlined( - width: double.infinity, - height: 50.0, - onPressed: () { - setState(() { - selectedPaymentMethod = - method; - }); - }, - label: method.name - ?.isNotEmpty == - true - ? method.name! - : 'Unknown', - ), - ); - }).toList(), - ); - }, - ); - }, - ), - const SpaceHeight(8.0), - const Divider(), - const SpaceHeight(8.0), - const Text( - 'Total Bayar', - style: TextStyle( - color: AppColors.primary, - fontSize: 16, - fontWeight: FontWeight.w500, - ), - ), - const SpaceHeight(12.0), - TextFormField( - controller: totalPriceController, - keyboardType: TextInputType.number, - decoration: InputDecoration( - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(8.0), - ), - hintText: 'Total harga', - ), - ), - const SpaceHeight(45.0), - Row( - children: [ - Button.filled( - width: 150.0, - onPressed: () {}, - label: 'UANG PAS', - ), - const SpaceWidth(20.0), - Button.filled( - width: 150.0, - onPressed: () {}, - label: 'Rp 250.000', - ), - const SpaceWidth(20.0), - Button.filled( - width: 150.0, - onPressed: () {}, - label: 'Rp 300.000', - ), - ], - ), - const SpaceHeight(100.0), - ]), - ), - Align( - alignment: Alignment.bottomCenter, - child: ColoredBox( - color: AppColors.white, - child: Padding( - padding: const EdgeInsets.symmetric( - horizontal: 24.0, vertical: 16.0), - child: Row( - children: [ - Flexible( - child: Button.outlined( - onPressed: () => context.pop(), - label: 'Kembali', - ), - ), - const SpaceWidth(8.0), - Flexible( - child: Button.outlined( - onPressed: () { - // Show void confirmation dialog - showDialog( - context: context, - builder: (context) => AlertDialog( - title: Row( - children: [ - Icon(Icons.warning, - color: AppColors.red), - SizedBox(width: 8), - Text('Batalkan Pesanan?'), - ], - ), - content: Text( - 'Apakah anda yakin ingin membatalkan pesanan untuk meja ${widget.table?.tableName ?? "ini"}?\n\nPesanan akan dihapus secara permanen.'), - actions: [ - TextButton( - onPressed: () => - Navigator.pop(context), - child: Text('Tidak', - style: TextStyle( - color: - AppColors.primary)), - ), - BlocListener( - listener: (context, state) { - state.maybeWhen( - orElse: () {}, - success: () { - Navigator.pop( - context); // Close void dialog - Navigator.pop( - context); // Close payment page - ScaffoldMessenger.of( - context) - .showSnackBar( - const SnackBar( - content: Text( - 'Pesanan berhasil dibatalkan'), - backgroundColor: - AppColors.primary, - ), - ); - }, - ); - }, - child: ElevatedButton( - style: ElevatedButton.styleFrom( - backgroundColor: - AppColors.red, - ), - onPressed: () { - // Void the order - if (widget.table != null) { - // final newTable = TableModel( - // id: widget.table!.id, - // tableName: widget - // .table!.tableName, - // status: 'available', - // orderId: 0, - // paymentAmount: 0, - // startTime: DateTime.now() - // .toIso8601String(), - // position: widget - // .table!.position, - // ); - // context - // .read() - // .add( - // StatusTableEvent - // .statusTabel( - // newTable), - // ); - } - // Remove draft order from local storage - if (widget.draftOrder?.id != - null) { - ProductLocalDatasource - .instance - .removeDraftOrderById( - widget.draftOrder! - .id!); - } - log("Voided order from payment page"); - }, - child: const Text( - "Ya, Batalkan", - style: TextStyle( - color: Colors.white), - ), - ), - ), - ], - ), - ); - }, - label: 'Batalkan', - ), - ), - const SpaceWidth(8.0), - BlocListener( - listener: (context, state) { - // final newTable = TableModel( - // id: widget.table!.id, - // tableName: widget.table!.tableName, - // status: 'available', - // orderId: 0, - // paymentAmount: 0, - // startTime: - // DateTime.now().toIso8601String(), - // position: widget.table!.position, - // ); - // context.read().add( - // StatusTableEvent.statusTabel( - // newTable, - // ), - // ); - ProductLocalDatasource.instance - .removeDraftOrderById( - widget.draftOrder!.id!); - }, - child: - BlocBuilder( - builder: (context, state) { - final discount = state.maybeWhen( - orElse: () => 0, - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) { - if (discountModel == null) { - return 0; - } - return discountModel.value! - .replaceAll('.00', '') - .toIntegerFromText; - }); - - final price = state.maybeWhen( - orElse: () => 0, - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) => - products.fold( - 0, - (previousValue, element) => - previousValue + - (element.product.price! * - element.quantity), - ), - ); - - final tax = state.maybeWhen( - orElse: () => 0, - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) => - tax, - ); - - final subTotal = - price - (discount / 100 * price); - final totalDiscount = - discount / 100 * price; - final finalTax = subTotal * (tax / 100); - - List items = - state.maybeWhen( - orElse: () => [], - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) => - products, - ); - final totalQty = items.fold( - 0, - (previousValue, element) => - previousValue + element.quantity, - ); - - final orderType = state.maybeWhen( - orElse: () => OrderType.dineIn, - loaded: ( - products, - discountModel, - discount, - discountAmount, - tax, - serviceCharge, - totalQuantity, - totalPrice, - draftName, - orderType, - deliveryType, - ) => - orderType, - ); - - return Flexible( - child: Button.filled( - onPressed: () async { - if (selectedPaymentMethod == null) { - ScaffoldMessenger.of(context) - .showSnackBar( - const SnackBar( - content: Text( - 'Please select a payment method'), - backgroundColor: Colors.red, - ), - ); - return; - } - - final paymentMethodName = - selectedPaymentMethod?.name - ?.toLowerCase() ?? - ''; - log("Selected payment method: ${selectedPaymentMethod?.name} (normalized: $paymentMethodName)"); - - if (paymentMethodName == 'cash' || - paymentMethodName == 'tunai' || - paymentMethodName == - 'uang tunai' || - paymentMethodName == - 'cash payment') { - // context.read().add( - // OrderEvent.order( - // items, - // discount, - // discountAmountFinal, - // finalTax.toInt(), - // 0, - // totalPriceController.text - // .toIntegerFromText, - // customerController.text, - // widget.table?.id ?? 0, - // 'completed', - // 'paid', - // selectedPaymentMethod - // ?.name ?? - // 'Cash', - // totalPriceFinal, - // orderType)); - - await showDialog( - context: context, - barrierDismissible: false, - builder: (context) => - SuccessPaymentDialog( - isTablePaymentPage: true, - data: items, - totalQty: totalQty, - totalPrice: - totalPriceFinal.toInt(), - totalTax: finalTax.toInt(), - totalDiscount: - totalDiscount.toInt(), - subTotal: subTotal.toInt(), - normalPrice: price, - totalService: 0, - draftName: - customerController.text, - ), - ); - await _handlePostPaymentCleanup(); - } else { - log("Processing non-cash payment: ${selectedPaymentMethod?.name}"); - // context.read().add( - // OrderEvent.order( - // items, - // discount, - // discountAmountFinal, - // finalTax.toInt(), - // 0, - // totalPriceController.text - // .toIntegerFromText, - // customerController.text, - // widget.table?.id ?? 0, - // 'completed', - // 'paid', - // selectedPaymentMethod - // ?.name ?? - // 'Unknown Payment Method', - // totalPriceFinal, - // orderType)); - - await showDialog( - context: context, - barrierDismissible: false, - builder: (context) => - SuccessPaymentDialog( - isTablePaymentPage: true, - data: items, - totalQty: totalQty, - totalPrice: - totalPriceFinal.toInt(), - totalTax: finalTax.toInt(), - totalDiscount: - totalDiscount.toInt(), - subTotal: subTotal.toInt(), - normalPrice: price, - totalService: 0, - draftName: - customerController.text, - ), - ); - - // Handle post-payment cleanup - await _handlePostPaymentCleanup(); - } - }, - label: 'Bayar', - ), - ); - }, - ), - ), - ], - ), - ), - ), - ), - ], - ), - ), - ), - ], - ), - ), - ), - ); - } -} diff --git a/lib/presentation/table/pages/table_page.dart.backup b/lib/presentation/table/pages/table_page.dart.backup deleted file mode 100644 index 570d051..0000000 --- a/lib/presentation/table/pages/table_page.dart.backup +++ /dev/null @@ -1,95 +0,0 @@ -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flutter/material.dart'; -import 'package:enaklo_pos/core/components/components.dart'; -import 'package:enaklo_pos/core/constants/colors.dart'; -import 'package:enaklo_pos/presentation/table/blocs/get_table/get_table_bloc.dart'; -import 'package:enaklo_pos/presentation/table/dialogs/form_table_dialog.dart'; -import 'package:enaklo_pos/presentation/table/widgets/card_table_widget.dart'; - -class TablePage extends StatefulWidget { - const TablePage({super.key}); - - @override - State createState() => _TablePageState(); -} - -class _TablePageState extends State { - @override - void initState() { - context.read().add(const GetTableEvent.getTables()); - super.initState(); - } - - @override - Widget build(BuildContext context) { - return Padding( - padding: const EdgeInsets.all(24), - child: ListView( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "Table Management", - style: TextStyle( - fontSize: 24.0, - fontWeight: FontWeight.bold, - color: AppColors.primary, - ), - ), - Button.filled( - onPressed: () { - showDialog( - context: context, - builder: (context) => FormTableDialog(), - ); - }, - label: 'Generate Table', - height: 48.0, - width: 200.0, - ), - ], - ), - SpaceHeight(24.0), - BlocBuilder( - builder: (context, state) { - return state.maybeWhen( - orElse: () { - return SizedBox.shrink(); - }, - loading: () { - return const CircularProgressIndicator(); - }, - success: (tables) { - if (tables.isEmpty) { - return const Center( - child: Text('No table available'), - ); - } - return GridView.builder( - padding: EdgeInsets.zero, - gridDelegate: - const SliverGridDelegateWithFixedCrossAxisCount( - childAspectRatio: 1.0, - crossAxisCount: 4, - mainAxisSpacing: 16, - crossAxisSpacing: 16, - ), - itemCount: tables.length, - shrinkWrap: true, - physics: const ScrollPhysics(), - itemBuilder: (BuildContext context, int index) { - return CardTableWidget( - table: tables[index], - ); - }, - ); - }, - ); - }, - ), - ], - ), - ); - } -} diff --git a/lib/presentation/table/widgets/card_table_widget.dart b/lib/presentation/table/widgets/card_table_widget.dart deleted file mode 100644 index 0ffd1a8..0000000 --- a/lib/presentation/table/widgets/card_table_widget.dart +++ /dev/null @@ -1,113 +0,0 @@ -import 'dart:developer'; - -import 'package:enaklo_pos/presentation/home/models/product_quantity.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flutter/material.dart'; -import 'package:enaklo_pos/core/components/components.dart'; -import 'package:enaklo_pos/core/constants/colors.dart'; -import 'package:enaklo_pos/core/extensions/build_context_ext.dart'; -import 'package:enaklo_pos/core/extensions/date_time_ext.dart'; -import 'package:enaklo_pos/core/extensions/int_ext.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; - -import 'package:enaklo_pos/data/models/response/table_model.dart'; -import 'package:enaklo_pos/presentation/home/bloc/checkout/checkout_bloc.dart'; -import 'package:enaklo_pos/presentation/home/bloc/status_table/status_table_bloc.dart'; -import 'package:enaklo_pos/presentation/home/pages/home_page.dart'; -import 'package:enaklo_pos/presentation/table/blocs/get_table/get_table_bloc.dart'; -import 'package:enaklo_pos/presentation/table/models/draft_order_model.dart'; -import 'package:enaklo_pos/presentation/table/pages/payment_table_page.dart.old'; - -class CardTableWidget extends StatefulWidget { - final TableModel table; - final List items; - const CardTableWidget({ - super.key, - required this.table, - required this.items, - }); - - @override - State createState() => _CardTableWidgetState(); -} - -class _CardTableWidgetState extends State { - DraftOrderModel? data; - - @override - void initState() { - loadData(); - super.initState(); - } - - loadData() async { - if (widget.table.status != 'available') { - // data = await ProductLocalDatasource.instance - // .getDraftOrderById(widget.table.orderId); - } - } - - @override - Widget build(BuildContext context) { - return Container( - padding: const EdgeInsets.all(16.0), - height: 200, - width: 200, - decoration: BoxDecoration( - border: Border.all( - color: widget.table.status == 'available' - ? AppColors.primary - : AppColors.red, - width: 2), - borderRadius: BorderRadius.circular(16), - ), - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - 'Table ${widget.table.tableName}', - style: TextStyle( - color: AppColors.black, - fontSize: 24, - fontWeight: FontWeight.bold, - ), - ), - Text( - // widget.table.status == 'available' - // ? widget.table.status - // : "${widget.table.status} - ${DateTime.parse(widget.table.startTime).toFormattedTime()}", - "", - style: TextStyle( - color: AppColors.black, - fontSize: 24, - fontWeight: FontWeight.bold, - ), - ), - Button.filled( - color: widget.table.status == 'available' - ? AppColors.primary - : AppColors.red, - onPressed: () async { - if (widget.table.status == 'available') { - context.push(HomePage( - isTable: true, - table: widget.table, - items: widget.items, - )); - } else { - context.read().add( - CheckoutEvent.loadDraftOrder(data!), - ); - log("Data Draft Order: ${data!.toMap()}"); - context.push(PaymentTablePage( - table: widget.table, - draftOrder: data!, - )); - } - }, - label: widget.table.status == 'available' ? 'Open' : 'Close') - ], - ), - ); - } -} diff --git a/lib/presentation/table/widgets/table_widget.dart.backup b/lib/presentation/table/widgets/table_widget.dart.backup deleted file mode 100644 index 01f7917..0000000 --- a/lib/presentation/table/widgets/table_widget.dart.backup +++ /dev/null @@ -1,399 +0,0 @@ -// ignore_for_file: public_member_api_docs, sort_constructors_first -import 'dart:developer'; - -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:enaklo_pos/core/components/buttons.dart'; -import 'package:enaklo_pos/core/components/custom_text_field.dart'; -import 'package:enaklo_pos/core/components/spaces.dart'; -import 'package:enaklo_pos/core/constants/colors.dart'; -import 'package:enaklo_pos/core/extensions/build_context_ext.dart'; -import 'package:enaklo_pos/core/utils/date_formatter.dart'; -import 'package:enaklo_pos/data/datasources/product_local_datasource.dart'; - -import 'package:enaklo_pos/data/models/response/table_model.dart'; -import 'package:enaklo_pos/presentation/home/bloc/checkout/checkout_bloc.dart'; -import 'package:enaklo_pos/presentation/home/bloc/status_table/status_table_bloc.dart'; -import 'package:enaklo_pos/presentation/home/pages/dashboard_page.dart'; -import 'package:enaklo_pos/presentation/table/blocs/create_table/create_table_bloc.dart'; -import 'package:enaklo_pos/presentation/table/blocs/get_table/get_table_bloc.dart'; -import 'package:enaklo_pos/presentation/table/blocs/update_table/update_table_bloc.dart'; -import 'package:enaklo_pos/presentation/table/models/draft_order_model.dart'; - -import '../pages/payment_table_page.dart'; - -class TableWidget extends StatefulWidget { - final TableModel table; - const TableWidget({ - super.key, - required this.table, - }); - - @override - State createState() => _TableWidgetState(); -} - -class _TableWidgetState extends State { - TextEditingController? tableNameController; - DraftOrderModel? data; - @override - void initState() { - super.initState(); - loadData(); - tableNameController = TextEditingController(text: widget.table.tableName); - } - - @override - void dispose() { - tableNameController!.dispose(); - super.dispose(); - } - - loadData() async { - if (widget.table.status != 'available') { - // data = await ProductLocalDatasource.instance - // .getDraftOrderById(widget.table.orderId); - } - } - - @override - Widget build(BuildContext context) { - return GestureDetector( - onTap: () async { - if (widget.table.status == 'available') { - context.push(DashboardPage( - table: widget.table, - )); - } else { - // Handle occupied table click - load draft order and navigate to payment - context.read().add( - CheckoutEvent.loadDraftOrder(data!), - ); - log("Data Draft Order: ${data!.toMap()}"); - context.push(PaymentTablePage( - table: widget.table, - draftOrder: data!, - )); - } - }, - onLongPress: () { - // dialog info table - showDialog( - context: context, - builder: (context) { - return AlertDialog( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(16)), - title: Row( - children: [ - Icon(Icons.table_bar, color: AppColors.primary), - SizedBox(width: 8), - Text('Table ${widget.table.tableName}'), - Spacer(), - BlocListener( - listener: (context, state) { - state.maybeWhen( - orElse: () {}, - success: (message) { - context - .read() - .add(const GetTableEvent.getTables()); - context.pop(); - }); - }, - child: IconButton( - onPressed: () { - // show dialaog adn input table name - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text('Update Table'), - content: SingleChildScrollView( - child: ConstrainedBox( - constraints: BoxConstraints( - maxHeight: 180, - ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - CustomTextField( - controller: tableNameController!, - label: 'Table Name', - ), - SpaceHeight(16), - Row( - children: [ - Expanded( - child: Button.outlined( - onPressed: () { - context.pop(); - }, - label: 'close', - ), - ), - SpaceWidth(16), - Expanded( - child: Button.filled( - onPressed: () { - // final newData = - // TableModel( - // id: widget.table.id, - // tableName: - // tableNameController! - // .text, - // status: - // widget.table.status, - // startTime: widget - // .table.startTime, - // orderId: widget - // .table.orderId, - // paymentAmount: widget - // .table - // .paymentAmount, - // position: widget - // .table.position, - // ); - // context - // .read< - // UpdateTableBloc>() - // .add( - // UpdateTableEvent - // .updateTable( - // newData, - // ), - // ); - context - .pop(); // close dialog after adding - }, - label: 'Update', - ), - ) - ], - ) - ], - ), - ), - ), - actions: []); - }); - }, - icon: Icon(Icons.edit)), - ), - ], - ), - content: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - _buildInfoRow( - 'Status:', - widget.table.status == 'available' - ? 'Available' - : 'Occupied', - color: widget.table.status == 'available' - ? Colors.green - : Colors.red), - // widget.table.status == 'available' - // ? SizedBox.shrink() - // : _buildInfoRow( - // 'Start Time:', - // DateFormatter.formatDateTime2( - // widget.table.startTime)), - // widget.table.status == 'available' - // ? SizedBox.shrink() - // : _buildInfoRow( - // 'Order ID:', widget.table.orderId.toString()), - widget.table.status == 'available' - ? SizedBox.shrink() - : SpaceHeight(16), - widget.table.status == 'available' - ? SizedBox.shrink() - : Row( - children: [ - Expanded( - child: Button.outlined( - onPressed: () { - // Show void confirmation dialog - showDialog( - context: context, - builder: (context) => AlertDialog( - title: Row( - children: [ - Icon(Icons.warning, - color: AppColors.red), - SizedBox(width: 8), - Text('Void Order?'), - ], - ), - content: Text( - 'Apakah anda yakin ingin membatalkan pesanan untuk meja ${widget.table.tableName}?\n\nPesanan akan dihapus secara permanen.'), - actions: [ - TextButton( - onPressed: () => - Navigator.pop(context), - child: Text('Tidak', - style: TextStyle( - color: AppColors.primary)), - ), - BlocListener( - listener: (context, state) { - state.maybeWhen( - orElse: () {}, - success: () { - context - .read() - .add(const GetTableEvent - .getTables()); - Navigator.pop( - context); // Close void dialog - Navigator.pop( - context); // Close table info dialog - ScaffoldMessenger.of(context) - .showSnackBar( - const SnackBar( - content: Text( - 'Pesanan berhasil dibatalkan'), - backgroundColor: - AppColors.primary, - ), - ); - }, - ); - }, - child: ElevatedButton( - style: ElevatedButton.styleFrom( - backgroundColor: AppColors.red, - ), - onPressed: () { - // // Void the order - // final newTable = TableModel( - // id: widget.table.id, - // tableName: - // widget.table.tableName, - // status: 'available', - // orderId: 0, - // paymentAmount: 0, - // startTime: DateTime.now() - // .toIso8601String(), - // position: widget.table.position, - // ); - // context - // .read() - // .add( - // StatusTableEvent - // .statusTabel(newTable), - // ); - // // Remove draft order from local storage - // ProductLocalDatasource.instance - // .removeDraftOrderById( - // widget.table.orderId); - // log("Voided order for table: ${widget.table.tableName}"); - }, - child: const Text( - "Ya, Batalkan", - style: TextStyle( - color: Colors.white), - ), - ), - ), - ], - ), - ); - }, - label: 'Void Order', - color: AppColors.red, - textColor: AppColors.red, - ), - ), - SizedBox(width: 12), - Expanded( - child: BlocConsumer( - listener: (context, state) { - state.maybeWhen( - orElse: () {}, - success: () { - context.read().add( - const GetTableEvent.getTables()); - context.pop(); - }); - }, - builder: (context, state) { - return Button.filled( - onPressed: () { - context.pop(); - context.read().add( - CheckoutEvent.loadDraftOrder( - data!), - ); - context.push(PaymentTablePage( - table: widget.table, - draftOrder: data!, - )); - }, - label: 'Selesai'); - }, - ), - ), - ], - ), - ], - ), - actions: [ - TextButton( - child: - Text('Close', style: TextStyle(color: AppColors.primary)), - onPressed: () => Navigator.of(context).pop(), - ), - ], - ); - }, - ); - }, - child: Container( - padding: const EdgeInsets.all(16.0), - alignment: Alignment.center, - decoration: BoxDecoration( - color: widget.table.status == 'available' - ? AppColors.primary - : AppColors.red, - shape: BoxShape.rectangle, - borderRadius: BorderRadius.circular(10), - ), - child: Text('${widget.table.tableName}', - style: TextStyle( - color: Colors.white, - fontSize: 18, - fontWeight: FontWeight.w600, - )), - ), - ); - } - - Widget _buildInfoRow(String label, String value, {Color? color}) { - return Padding( - padding: const EdgeInsets.symmetric(vertical: 4.0), - child: Row( - children: [ - Text( - label, - style: TextStyle(fontWeight: FontWeight.w600), - ), - SizedBox(width: 8), - Expanded( - child: Text( - value, - style: TextStyle( - color: color ?? Colors.black87, - ), - ), - ), - ], - ), - ); - } -} - -