Compare commits

...
38 Commits
Author SHA1 Message Date
Efril 5d73f82017 fix payment struck 2026-01-13 23:41:56 +07:00
aefril 1d52f22f5f Merge pull request 'dev' (#1) from dev into main
Reviewed-on: #1
2025-08-13 17:19:46 +00:00
efrilm f87309af3f feat: update 2025-08-14 00:16:42 +07:00
efrilm 96d0b91984 feat: succes payment 2025-08-14 00:12:49 +07:00
efrilm e20dc53fb8 feat: profit loss widget 2025-08-13 23:27:52 +07:00
efrilm c09822b470 feat: success save order 2025-08-13 23:08:12 +07:00
efrilm 6a9a26f71c fix: success save order 2025-08-13 23:00:11 +07:00
efrilm b0006ee6bc fix: order and add to order 2025-08-13 22:52:37 +07:00
efrilm b34428965e fix: bug 2025-08-13 22:11:24 +07:00
efrilm 670a0b6414 feat: update split bill 2025-08-08 23:04:35 +07:00
efrilm b7ab9c6939 feat: update logo 2025-08-08 19:44:00 +07:00
efrilm 6b5af82307 feat: table 2025-08-08 14:59:49 +07:00
efrilm 2848678cdc fix: amount 2025-08-08 14:39:56 +07:00
efrilm f05347c90d feat: transfer table 2025-08-08 14:22:12 +07:00
efrilm 94725964ea fix: change position table 2025-08-08 13:45:03 +07:00
efrilm 2eceb0bc0c feat: update 2025-08-08 10:53:46 +07:00
efrilm e19d788f47 feat: update order detail 2025-08-08 10:29:17 +07:00
efrilm 3a07d2e7cc feat: fix payment 2025-08-08 00:12:10 +07:00
efrilm 2c8b1333d8 feat: order response model 2025-08-07 23:59:01 +07:00
efrilm b1a1303a40 feat: split add customer optional 2025-08-07 22:45:06 +07:00
efrilm de22251440 feat: update print 2025-08-07 22:03:05 +07:00
efrilm 203eda75e4 feat: save outlet to local 2025-08-07 21:43:13 +07:00
efrilm 49fef5afb2 fix: ui refund and sales page 2025-08-07 20:11:57 +07:00
efrilm e3da008a9a fix: customer ui 2025-08-07 19:59:54 +07:00
efrilm b5ad20eb8b feat: handler ui and update void ui 2025-08-07 19:57:59 +07:00
efrilm fbd59964c3 feat: update dashboard 2025-08-07 15:47:38 +07:00
efrilm 5a260ca3a1 feat: ticket printer 2025-08-07 15:30:05 +07:00
efrilm ffe076e120 feat: payment split 2025-08-07 14:48:59 +07:00
efrilm 9d78c9dcce fix: print 2025-08-07 14:28:52 +07:00
efrilm d0e1f9a5b6 feat: update success payment page 2025-08-07 12:49:42 +07:00
efrilm ab2a59930c feat: order search 2025-08-07 12:34:57 +07:00
efrilm fe92082ceb feat: search product and fix product 2025-08-07 12:19:25 +07:00
efrilm 5575596bfc fix: tax 2025-08-07 11:48:05 +07:00
efrilm 8022fa6b32 feat: print on receipt 2025-08-07 11:39:33 +07:00
efrilm 811ae06e58 fix: change outlet 2025-08-07 11:00:59 +07:00
efrilm 2cf5ce7ae8 feat: product is active 2025-08-07 10:56:08 +07:00
efrilm 1cd2b1778b fix: color variant 2025-08-07 10:49:38 +07:00
efrilm 7d1c3d1bd6 feat: package name 2025-08-06 23:45:15 +07:00
122 changed files with 6811 additions and 1784 deletions
+3 -3
View File
@@ -23,7 +23,7 @@ if (flutterVersionName == null) {
}
android {
namespace "com.example.enaklo_pos"
namespace "com.appscale.pos"
compileSdkVersion 35
ndkVersion flutter.ndkVersion
@@ -42,10 +42,10 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.enaklo_pos"
applicationId "com.appscale.pos"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion 21
minSdkVersion flutter.minSdkVersion
targetSdkVersion 35
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
@@ -1,4 +1,4 @@
package com.example.enaklo_pos
package com.appscale.pos
import io.flutter.embedding.android.FlutterActivity
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 983 B

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 19 KiB

+10
View File
@@ -0,0 +1,10 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_17_4760)">
<path d="M9 13.75C6.66 13.75 2 14.92 2 17.25V19H16V17.25C16 14.92 11.34 13.75 9 13.75ZM4.34 17C5.18 16.42 7.21 15.75 9 15.75C10.79 15.75 12.82 16.42 13.66 17H4.34ZM9 12C10.93 12 12.5 10.43 12.5 8.5C12.5 6.57 10.93 5 9 5C7.07 5 5.5 6.57 5.5 8.5C5.5 10.43 7.07 12 9 12ZM9 7C9.83 7 10.5 7.67 10.5 8.5C10.5 9.33 9.83 10 9 10C8.17 10 7.5 9.33 7.5 8.5C7.5 7.67 8.17 7 9 7ZM16.04 13.81C17.2 14.65 18 15.77 18 17.25V19H22V17.25C22 15.23 18.5 14.08 16.04 13.81ZM15 12C16.93 12 18.5 10.43 18.5 8.5C18.5 6.57 16.93 5 15 5C14.46 5 13.96 5.13 13.5 5.35C14.13 6.24 14.5 7.33 14.5 8.5C14.5 9.67 14.13 10.76 13.5 11.65C13.96 11.87 14.46 12 15 12Z" fill="white"/>
</g>
<defs>
<clipPath id="clip0_17_4760">
<rect width="24" height="24" fill="white"/>
</clipPath>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 892 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 KiB

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 320 B

After

Width:  |  Height:  |  Size: 666 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 804 B

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 492 B

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 804 B

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 15 KiB

+4 -4
View File
@@ -3,15 +3,15 @@
flutter_launcher_icons:
android: "launcher_icon"
ios: true
image_path: "assets/logo/ic_launcher.png"
image_path: "assets/logo/logo.png"
remove_alpha_ios: true
min_sdk_android: 21 # android min sdk min:16, default 21
adaptive_icon_background: "#ffffff"
adaptive_icon_foreground: "assets/logo/ic_launcher.png"
adaptive_icon_foreground: "assets/logo/logo.png"
web:
generate: true
image_path: "assets/logo/ic_launcher.png"
image_path: "assets/logo/logo.png"
windows:
generate: true
image_path: "assets/logo/ic_launcher.png"
image_path: "assets/logo/logo.png"
icon_size: 48
+8 -17
View File
@@ -101,6 +101,9 @@ class $AssetsIconsGen {
/// File path: assets/icons/payments.svg
SvgGenImage get payments => const SvgGenImage('assets/icons/payments.svg');
/// File path: assets/icons/people.svg
SvgGenImage get people => const SvgGenImage('assets/icons/people.svg');
/// File path: assets/icons/print.svg
SvgGenImage get print => const SvgGenImage('assets/icons/print.svg');
@@ -152,6 +155,7 @@ class $AssetsIconsGen {
orders,
pajak,
payments,
people,
print,
qrCode,
report,
@@ -300,12 +304,8 @@ class $AssetsImagesGen {
class $AssetsLogoGen {
const $AssetsLogoGen();
/// File path: assets/logo/ic_launcher.png
AssetGenImage get icLauncher =>
const AssetGenImage('assets/logo/ic_launcher.png');
/// File path: assets/logo/logo.jpeg
AssetGenImage get logo => const AssetGenImage('assets/logo/logo.jpeg');
/// File path: assets/logo/logo.png
AssetGenImage get logo => const AssetGenImage('assets/logo/logo.png');
/// File path: assets/logo/logo2.png
AssetGenImage get logo2 => const AssetGenImage('assets/logo/logo2.png');
@@ -330,17 +330,8 @@ class $AssetsLogoGen {
AssetGenImage get mylogo => const AssetGenImage('assets/logo/mylogo.png');
/// List of all assets
List<AssetGenImage> get values => [
icLauncher,
logo,
logo2,
logo3,
logo4,
logo5,
logo6,
logoAppIcon,
mylogo
];
List<AssetGenImage> get values =>
[logo, logo2, logo3, logo4, logo5, logo6, logoAppIcon, mylogo];
}
class Assets {
+149 -62
View File
@@ -1,96 +1,183 @@
import 'dart:developer';
import 'dart:typed_data';
import 'package:barcode_image/barcode_image.dart';
import 'package:enaklo_pos/core/extensions/string_ext.dart';
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/settings_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/order_response_model.dart';
import 'package:enaklo_pos/data/type/bussines_type.dart';
import 'package:enaklo_pos/presentation/home/models/product_quantity.dart';
import 'package:flutter/material.dart';
import 'package:barcode/barcode.dart';
import 'package:image/image.dart' as img;
Future<void> onPrint(
BuildContext context, {
required List<ProductQuantity> productQuantity,
required Order order,
}) async {
final checkerPrinter =
await ProductLocalDatasource.instance.getPrinterByCode('checker');
final kitchenPrinter =
await ProductLocalDatasource.instance.getPrinterByCode('kitchen');
final barPrinter =
await ProductLocalDatasource.instance.getPrinterByCode('bar');
final outlet = await OutletLocalDatasource().get();
if (outlet.businessType == BusinessType.restaurant) {
final checkerPrinter =
await ProductLocalDatasource.instance.getPrinterByCode('checker');
final kitchenPrinter =
await ProductLocalDatasource.instance.getPrinterByCode('kitchen');
final barPrinter =
await ProductLocalDatasource.instance.getPrinterByCode('bar');
log("Checker printer: ${checkerPrinter?.toMap()}");
log("Kitchen printer: ${kitchenPrinter?.toMap()}");
log("Bar printer: ${barPrinter?.toMap()}");
final authData = await AuthLocalDataSource().getAuthData();
// Checker printer
if (checkerPrinter != null) {
try {
final printValue = await PrintDataoutputs.instance.printChecker(
productQuantity
.where((e) => e.product.printerType == "checker")
.toList(),
order.tableNumber ?? "",
order.orderNumber ?? "",
'kasir',
checkerPrinter.paper.toIntegerFromText,
order.orderType ?? "",
);
// Checker printer
if (checkerPrinter != null) {
try {
final printValue = await PrintDataoutputs.instance.printChecker(
productQuantity,
order.tableNumber ?? "",
order.orderNumber ?? "",
authData.user?.name ?? "",
checkerPrinter.paper.toIntegerFromText,
order.orderType ?? "",
);
await PrinterService()
// ignore: use_build_context_synchronously
.printWithPrinter(checkerPrinter, printValue, context);
} catch (e) {
log("Error printing checker: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error printing checker: $e')),
);
await PrinterService()
// ignore: use_build_context_synchronously
.printWithPrinter(checkerPrinter, printValue, context);
} catch (e) {
log("Error printing checker: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error printing checker: $e')),
);
}
}
// Kitchen printer
if (kitchenPrinter != null) {
try {
final printValue = await PrintDataoutputs.instance.printKitchen(
productQuantity,
order.tableNumber!,
order.orderNumber ?? "",
authData.user?.name ?? "",
kitchenPrinter.paper.toIntegerFromText,
order.orderType ?? "",
);
await PrinterService()
.printWithPrinter(kitchenPrinter, printValue, context);
} catch (e) {
log("Error printing kitchen order: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error printing kitchen order: $e')),
);
}
}
// Bar printer
if (barPrinter != null) {
try {
final printValue = await PrintDataoutputs.instance.printBar(
productQuantity,
order.tableNumber ?? "",
order.orderNumber ?? "",
authData.user?.name ?? "",
barPrinter.paper.toIntegerFromText,
order.orderType ?? "",
);
await PrinterService()
.printWithPrinter(barPrinter, printValue, context);
} catch (e) {
log("Error printing bar order: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error printing bar order: $e')),
);
}
}
}
// Kitchen printer
if (kitchenPrinter != null) {
try {
final printValue = await PrintDataoutputs.instance.printKitchen(
productQuantity
.where((e) => e.product.printerType == "kitchen")
.toList(),
order.tableNumber!,
order.orderNumber ?? "",
'kasir',
kitchenPrinter.paper.toIntegerFromText,
order.orderType ?? "",
);
if (outlet.businessType == BusinessType.ticketing) {
final ticketPrinter =
await ProductLocalDatasource.instance.getPrinterByCode('ticket');
await PrinterService()
.printWithPrinter(kitchenPrinter, printValue, context);
} catch (e) {
log("Error printing kitchen order: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error printing kitchen order: $e')),
);
final barcode = await generateBarcodeAsUint8List(order.orderNumber ?? "");
if (ticketPrinter != null) {
try {
final printValue = await PrintDataoutputs.instance.printTicket(
order.totalAmount ?? 0,
barcode,
ticketPrinter.paper.toIntegerFromText,
);
await PrinterService()
// ignore: use_build_context_synchronously
.printWithPrinter(ticketPrinter, printValue, context);
} catch (e) {
log("Error printing ticket: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error printing ticket: $e')),
);
}
}
}
}
// Bar printer
if (barPrinter != null) {
Future<void> onPrintRecipt(
context, {
required Order order,
required String paymentMethod,
required int nominalBayar,
required int kembalian,
}) async {
final receiptPrinter =
await ProductLocalDatasource.instance.getPrinterByCode('receipt');
final authData = await AuthLocalDataSource().getAuthData();
final settings = await SettingsLocalDatasource().getTax();
final outlet = await OutletLocalDatasource().get();
if (receiptPrinter != null) {
try {
final printValue = await PrintDataoutputs.instance.printBar(
productQuantity.where((e) => e.product.printerType == "bar").toList(),
order.tableNumber ?? "",
order.orderNumber ?? "",
'kasir',
barPrinter.paper.toIntegerFromText,
final printValue = await PrintDataoutputs.instance.printOrderV4(
order,
authData.user?.name ?? "",
paymentMethod,
nominalBayar,
kembalian,
settings.value,
receiptPrinter.paper.toIntegerFromText,
order.orderType ?? "",
outlet,
);
await PrinterService().printWithPrinter(barPrinter, printValue, context);
await PrinterService()
.printWithPrinter(receiptPrinter, printValue, context);
} catch (e) {
log("Error printing bar order: $e");
log("Error printing receipt order: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error printing bar order: $e')),
SnackBar(content: Text('Error printing receipt order: $e')),
);
}
}
}
Future<Uint8List> generateBarcodeAsUint8List(String data) async {
// 1. Buat barcode instance (code128, qrCode, dll)
final barcode = Barcode.code128();
// 2. Siapkan canvas image dari package `image`
final image = img.Image(width: 600, height: 200);
// 3. Gambar barcode ke canvas menggunakan barcode_image
drawBarcode(
image,
barcode,
data,
);
// 4. Encode image ke Uint8List PNG
return Uint8List.fromList(img.encodePng(image));
}
+160 -1
View File
@@ -1,6 +1,9 @@
// lib/core/network/dio_client.dart
import 'package:awesome_dio_interceptor/awesome_dio_interceptor.dart';
import 'package:dio/dio.dart';
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
import 'package:enaklo_pos/presentation/auth/login_page.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class DioClient {
static final Dio _dio = Dio(BaseOptions(
@@ -10,6 +13,7 @@ class DioClient {
'Accept': 'application/json',
},
))
..interceptors.add(AuthInterceptor())
..interceptors.add(
AwesomeDioInterceptor(
logRequestTimeout: true,
@@ -20,3 +24,158 @@ class DioClient {
static Dio get instance => _dio;
}
class AuthInterceptor extends Interceptor {
static final GlobalKey<NavigatorState> navigatorKey =
GlobalKey<NavigatorState>();
@override
void onRequest(
RequestOptions options, RequestInterceptorHandler handler) async {
// Add token to request headers
final prefs = await SharedPreferences.getInstance();
final token = prefs.getString('auth_token');
if (token != null) {
options.headers['Authorization'] = 'Bearer $token';
}
handler.next(options);
}
@override
void onResponse(Response response, ResponseInterceptorHandler handler) {
handler.next(response);
}
@override
void onError(DioException err, ErrorInterceptorHandler handler) async {
// Check if error is 401 (Unauthorized) - token expired
if (err.response?.statusCode == 401) {
await _handleTokenExpired();
}
handler.next(err);
}
Future<void> _handleTokenExpired() async {
// Clear stored token
final prefs = await SharedPreferences.getInstance();
await prefs.remove('auth_token');
await prefs.remove('refresh_token');
await prefs.clear(); // Optional: clear all user data
// Navigate to login page
final context = navigatorKey.currentContext;
if (context != null) {
// Option 1: Navigate and remove all previous routes
context.pushReplacement(LoginPage());
// Option 2: If using GoRouter, uncomment below:
// GoRouter.of(context).go('/login');
// Option 3: If using custom routing, uncomment below:
// Navigator.of(context).pushAndRemoveUntil(
// MaterialPageRoute(builder: (context) => LoginPage()),
// (route) => false,
// );
}
}
}
// Alternative: Dengan Refresh Token Logic
class AuthInterceptorWithRefresh extends Interceptor {
static final GlobalKey<NavigatorState> navigatorKey =
GlobalKey<NavigatorState>();
@override
void onRequest(
RequestOptions options, RequestInterceptorHandler handler) async {
final prefs = await SharedPreferences.getInstance();
final token = prefs.getString('auth_token');
if (token != null) {
options.headers['Authorization'] = 'Bearer $token';
}
handler.next(options);
}
@override
void onError(DioException err, ErrorInterceptorHandler handler) async {
if (err.response?.statusCode == 401) {
// Try refresh token first
final success = await _tryRefreshToken();
if (success) {
// Retry the original request
final response = await _retryRequest(err.requestOptions);
handler.resolve(response);
return;
} else {
// Refresh failed, redirect to login
await _handleTokenExpired();
}
}
handler.next(err);
}
Future<bool> _tryRefreshToken() async {
try {
final prefs = await SharedPreferences.getInstance();
final refreshToken = prefs.getString('refresh_token');
if (refreshToken == null) return false;
final response = await Dio().post(
'YOUR_REFRESH_TOKEN_ENDPOINT',
data: {'refresh_token': refreshToken},
);
if (response.statusCode == 200) {
final newToken = response.data['access_token'];
final newRefreshToken = response.data['refresh_token'];
await prefs.setString('auth_token', newToken);
await prefs.setString('refresh_token', newRefreshToken);
return true;
}
} catch (e) {
print('Refresh token failed: $e');
}
return false;
}
Future<Response> _retryRequest(RequestOptions options) async {
final prefs = await SharedPreferences.getInstance();
final token = prefs.getString('auth_token');
options.headers['Authorization'] = 'Bearer $token';
return await DioClient.instance.request(
options.path,
options: Options(
method: options.method,
headers: options.headers,
),
data: options.data,
queryParameters: options.queryParameters,
);
}
Future<void> _handleTokenExpired() async {
final prefs = await SharedPreferences.getInstance();
await prefs.clear();
final context = navigatorKey.currentContext;
if (context != null) {
Navigator.of(context).pushNamedAndRemoveUntil(
'/login',
(route) => false,
);
}
}
}
+298
View File
@@ -1,5 +1,7 @@
import 'dart:math';
import 'package:enaklo_pos/data/models/response/order_response_model.dart';
import 'package:enaklo_pos/presentation/home/models/outlet_model.dart';
import 'package:esc_pos_utils_plus/esc_pos_utils_plus.dart';
import 'package:flutter/services.dart';
import 'package:enaklo_pos/core/extensions/int_ext.dart';
@@ -739,6 +741,267 @@ class PrintDataoutputs {
return bytes;
}
Future<List<int>> printOrderV4(
Order order,
String chashierName,
String paymentMethod,
int nominalBayar,
int kembalian,
int taxPercentage,
int paper,
String orderType,
Outlet outlet,
) async {
List<int> bytes = [];
final profile = await CapabilityProfile.load();
final generator =
Generator(paper == 58 ? PaperSize.mm58 : PaperSize.mm80, profile);
bytes += generator.reset();
bytes += generator.text(outlet.name ?? "",
styles: const PosStyles(
bold: true,
align: PosAlign.center,
height: PosTextSize.size1,
width: PosTextSize.size1,
));
bytes += generator.text(outlet.address ?? "",
styles: const PosStyles(bold: false, align: PosAlign.center));
bytes += generator.text(outlet.phoneNumber ?? "",
styles: const PosStyles(bold: false, align: PosAlign.center));
bytes += generator.text(
paper == 80
? '------------------------------------------------'
: '--------------------------------',
styles: const PosStyles(bold: false, align: PosAlign.center));
bytes += generator.row([
PosColumn(
text: DateFormat('dd MMM yyyy').format(DateTime.now()),
width: 6,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: DateFormat('HH:mm').format(DateTime.now()),
width: 6,
styles: const PosStyles(align: PosAlign.right),
),
]);
bytes += generator.row([
PosColumn(
text: 'Receipt Number',
width: 6,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: 'JF-${DateFormat('yyyyMMddhhmm').format(DateTime.now())}',
width: 6,
styles: const PosStyles(align: PosAlign.right),
),
]);
bytes += generator.row([
PosColumn(
text: 'Order ID',
width: 6,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: Random().nextInt(100000).toString(),
width: 6,
styles: const PosStyles(align: PosAlign.right),
),
]);
bytes += generator.row([
PosColumn(
text: 'Bill Name',
width: 6,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: order.metadata?['customer_name'] ?? '',
width: 6,
styles: const PosStyles(align: PosAlign.right),
),
]);
bytes += generator.row([
PosColumn(
text: 'Collected By',
width: 6,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: chashierName,
width: 6,
styles: const PosStyles(align: PosAlign.right),
),
]);
bytes += generator.row([
PosColumn(
text: 'Pembayaran',
width: 8,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: paymentMethod,
width: 4,
styles: const PosStyles(align: PosAlign.right),
),
]);
bytes += generator.text(
paper == 80
? '------------------------------------------------'
: '--------------------------------',
styles: const PosStyles(bold: false, align: PosAlign.center));
bytes += generator.text(orderType,
styles: const PosStyles(bold: true, align: PosAlign.center));
bytes += generator.text(
paper == 80
? '------------------------------------------------'
: '--------------------------------',
styles: const PosStyles(bold: false, align: PosAlign.center));
for (final product
in (order.orderItems?.where((item) => item.status != 'cancelled') ??
<OrderItem>[])) {
bytes += generator.row([
PosColumn(
text: '${product.quantity} x ${product.productName}',
width: 8,
styles: const PosStyles(bold: true, align: PosAlign.left),
),
PosColumn(
text: (product.totalPrice ?? 0).currencyFormatRpV2,
width: 4,
styles: const PosStyles(bold: true, align: PosAlign.right),
),
]);
}
bytes += generator.text(
paper == 80
? '------------------------------------------------'
: '--------------------------------',
styles: const PosStyles(bold: false, align: PosAlign.center));
bytes += generator.row([
PosColumn(
text: 'Subtotal ${order.orderItems?.length ?? "0"} Product',
width: 6,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: (order.subtotal ?? 0).currencyFormatRpV2,
width: 6,
styles: const PosStyles(align: PosAlign.right),
),
]);
bytes += generator.row([
PosColumn(
text: 'Discount',
width: 6,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: (order.discountAmount ?? 0).currencyFormatRpV2,
width: 6,
styles: const PosStyles(align: PosAlign.right),
),
]);
// Only show tax if it's greater than 0
if ((order.taxAmount ?? 0) > 0) {
bytes += generator.row([
PosColumn(
text: 'Tax PB1 ($taxPercentage%)',
width: 6,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: (order.taxAmount ?? 0).currencyFormatRpV2,
width: 6,
styles: const PosStyles(align: PosAlign.right),
),
]);
}
// Only show service charge if it's greater than 0
// if (serviceCharge > 0) {
// bytes += generator.row([
// PosColumn(
// text: 'Service Charge($serviceChargePercentage%)',
// width: 6,
// styles: const PosStyles(align: PosAlign.left),
// ),
// PosColumn(
// text: serviceCharge.currencyFormatRpV2,
// width: 6,
// styles: const PosStyles(align: PosAlign.right),
// ),
// ]);
// }
bytes += generator.text(
paper == 80
? '------------------------------------------------'
: '--------------------------------',
styles: const PosStyles(bold: false, align: PosAlign.center));
bytes += generator.row([
PosColumn(
text: 'Total',
width: 6,
styles: const PosStyles(bold: true, align: PosAlign.left),
),
PosColumn(
text: '${order.totalAmount ?? ""}'.currencyFormatRpV2,
width: 6,
styles: const PosStyles(bold: true, align: PosAlign.right),
),
]);
bytes += generator.row([
PosColumn(
text: 'Dibayar',
width: 6,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: nominalBayar.currencyFormatRpV2,
width: 6,
styles: const PosStyles(align: PosAlign.right),
),
]);
bytes += generator.row([
PosColumn(
text: 'Kembali',
width: 6,
styles: const PosStyles(align: PosAlign.left),
),
PosColumn(
text: kembalian.currencyFormatRpV2,
width: 6,
styles: const PosStyles(align: PosAlign.right),
),
]);
bytes += generator.text(
paper == 80
? '------------------------------------------------'
: '--------------------------------',
styles: const PosStyles(bold: false, align: PosAlign.center));
// bytes += generator.text('Notes',
// styles: const PosStyles(bold: false, align: PosAlign.center));
// bytes += generator.text('Pass Wifi: fic14jilid2',
// styles: const PosStyles(bold: false, align: PosAlign.center));
// //terima kasih
// bytes += generator.text('Terima Kasih',
// styles: const PosStyles(bold: true, align: PosAlign.center));
paper == 80 ? bytes += generator.feed(3) : bytes += generator.feed(1);
bytes += generator.cut();
return bytes;
}
Future<List<int>> printQRIS(
int totalPrice, Uint8List imageQris, int paper) async {
List<int> bytes = [];
@@ -1140,4 +1403,39 @@ class PrintDataoutputs {
return bytes;
}
Future<List<int>> printTicket(
int totalPrice, Uint8List imageQris, int paper) async {
List<int> bytes = [];
final profile = await CapabilityProfile.load();
final generator =
Generator(paper == 58 ? PaperSize.mm58 : PaperSize.mm80, profile);
final img.Image? orginalImage = img.decodeImage(imageQris);
bytes += generator.reset();
// final Uint8List bytesData = data.buffer.asUint8List();
// final img.Image? orginalImage = img.decodeImage(bytesData);
// bytes += generator.reset();
bytes += generator.text('Scan Ticket',
styles: const PosStyles(bold: false, align: PosAlign.center));
bytes += generator.feed(2);
if (orginalImage != null) {
final img.Image grayscalledImage = img.grayscale(orginalImage);
final img.Image resizedImage =
img.copyResize(grayscalledImage, width: 240);
bytes += generator.imageRaster(resizedImage, align: PosAlign.center);
bytes += generator.feed(1);
}
bytes += generator.text('Price : ${totalPrice.currencyFormatRp}',
styles: const PosStyles(bold: false, align: PosAlign.center));
bytes += generator.feed(4);
bytes += generator.cut();
return bytes;
}
}
@@ -220,7 +220,8 @@ class OrderRemoteDatasource {
return const Left('Gagal membuat pesanan');
}
} on DioException catch (e) {
final errorMessage = e.response?.data['message'] ?? 'Kesalahan jaringan';
final errorMessage =
e.response?.data['message'] ?? 'Terjadi kesalahan, coba lagi nanti.';
log("đź’Ą Dio error: ${e.message}");
log("đź’Ą Dio response: ${e.response?.data}");
return Left(errorMessage);
@@ -254,7 +255,8 @@ class OrderRemoteDatasource {
return const Left('Gagal membuat pembayaran');
}
} on DioException catch (e) {
final errorMessage = e.response?.data['message'] ?? 'Kesalahan jaringan';
final errorMessage =
e.response?.data['message'] ?? 'Terjadi kesalahan, coba lagi nanti.';
log("đź’Ą Dio error: ${e.message}");
log("đź’Ą Dio response: ${e.response?.data}");
return Left(errorMessage);
@@ -270,18 +272,26 @@ class OrderRemoteDatasource {
String status = 'completed',
required DateTime dateFrom,
required DateTime dateTo,
String? search,
}) async {
try {
final authData = await AuthLocalDataSource().getAuthData();
Map<String, dynamic> params = {
'page': page,
'limit': limit,
'status': status,
'date_from': DateFormat('dd-MM-yyyy').format(dateFrom),
'date_to': DateFormat('dd-MM-yyyy').format(dateTo),
};
if (search != null && search.isNotEmpty) {
params['search'] = search;
}
final response = await dio.get(
'${Variables.baseUrl}/api/v1/orders',
queryParameters: {
'page': page,
'limit': limit,
'status': status,
'date_from': DateFormat('dd-MM-yyyy').format(dateFrom),
'date_to': DateFormat('dd-MM-yyyy').format(dateTo),
},
queryParameters: params,
options: Options(
headers: {
'Authorization': 'Bearer ${authData.token}',
@@ -384,7 +394,8 @@ class OrderRemoteDatasource {
return const Left('Gagal membuat pesanan');
}
} on DioException catch (e) {
final errorMessage = e.response?.data['message'] ?? 'Kesalahan jaringan';
final errorMessage =
e.response?.data['message'] ?? 'Terjadi kesalahan, coba lagi nanti.';
log("đź’Ą Dio error: ${e.message}");
log("đź’Ą Dio response: ${e.response?.data}");
return Left(errorMessage);
@@ -394,7 +405,7 @@ class OrderRemoteDatasource {
}
}
Future<Either<String, OrderDetailResponseModel>> addToOrder({
Future<Either<String, bool>> addToOrder({
required String orderId,
required List<OrderItemRequest> orderItems,
}) async {
@@ -418,19 +429,19 @@ class OrderRemoteDatasource {
);
if (response.statusCode == 200) {
final data = OrderDetailResponseModel.fromMap(response.data);
return Right(data);
return Right(true);
} else {
return const Left('Gagal menambahkan pesanan pesanan');
}
} on DioException catch (e) {
final errorMessage = e.response?.data['message'] ?? 'Kesalahan jaringan';
final errorMessage =
e.response?.data['message'] ?? 'Terjadi kesalahan, coba lagi nanti.';
log("đź’Ą Dio error: ${e.message}");
log("đź’Ą Dio response: ${e.response?.data}");
return Left(errorMessage);
} catch (e) {
log("đź’Ą Unexpected error: $e");
return const Left('Terjadi kesalahan tak terduga');
return const Left('Terjadi kesalahan, coba lagi nanti.');
}
}
@@ -476,7 +487,8 @@ class OrderRemoteDatasource {
return const Left('Gagal refund');
}
} on DioException catch (e) {
final errorMessage = e.response?.data['message'] ?? 'Kesalahan jaringan';
final errorMessage =
e.response?.data['message'] ?? 'Terjadi kesalahan, coba lagi nanti.';
log("đź’Ą Dio error: ${e.message}");
log("đź’Ą Dio response: ${e.response?.data}");
return Left(errorMessage);
@@ -524,7 +536,8 @@ class OrderRemoteDatasource {
return const Left('Gagal refund');
}
} on DioException catch (e) {
final errorMessage = e.response?.data['message'] ?? 'Kesalahan jaringan';
final errorMessage =
e.response?.data['message'] ?? 'Terjadi kesalahan, coba lagi nanti.';
log("đź’Ą Dio error: ${e.message}");
log("đź’Ą Dio response: ${e.response?.data}");
return Left(errorMessage);
@@ -573,4 +586,39 @@ class OrderRemoteDatasource {
return const Left('Terjadi kesalahan tak terduga');
}
}
Future<Either<String, PaymentSuccessResponseModel>> createPaymentSplitBill(
PaymentSplitBillRequest request) async {
final authData = await AuthLocalDataSource().getAuthData();
final url = '${Variables.baseUrl}/api/v1/orders/split-bill';
try {
final response = await dio.post(
url,
data: request.toMap(),
options: Options(
headers: {
'Authorization': 'Bearer ${authData.token}',
'Accept': 'application/json',
'Content-Type': 'application/json',
},
),
);
if (response.statusCode == 200) {
return Right(PaymentSuccessResponseModel.fromMap(response.data));
} else {
return const Left('Gagal membuat pembayaran');
}
} on DioException catch (e) {
final errorMessage =
e.response?.data['message'] ?? 'Terjadi kesalahan, coba lagi nanti.';
log("đź’Ą Dio error: ${e.message}");
log("đź’Ą Dio response: ${e.response?.data}");
return Left(errorMessage);
} catch (e) {
log("đź’Ą Unexpected error: $e");
return const Left('Terjadi kesalahan tak terduga');
}
}
}
@@ -0,0 +1,30 @@
import 'dart:developer';
import 'package:enaklo_pos/presentation/home/models/outlet_model.dart';
import 'package:shared_preferences/shared_preferences.dart';
class OutletLocalDatasource {
Future<void> save(Outlet outlet) async {
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setString('outlet', outlet.toJson());
log('Outlet Local Data: ${outlet.toJson()}');
} catch (e) {
log('Error saving outlet: $e');
}
}
Future<void> remove() async {
final prefs = await SharedPreferences.getInstance();
await prefs.remove('outlet');
}
Future<Outlet> get() async {
final prefs = await SharedPreferences.getInstance();
final outlet = prefs.getString('outlet');
log('Outlet Local Data: $outlet');
return Outlet.fromJson(outlet!);
}
}
@@ -2,7 +2,10 @@ import 'dart:developer';
import 'package:dartz/dartz.dart';
import 'package:dio/dio.dart';
import 'package:enaklo_pos/core/network/dio_client.dart';
import 'package:enaklo_pos/data/datasources/outlet_local_datasource.dart';
import 'package:enaklo_pos/data/datasources/settings_local_datasource.dart';
import 'package:enaklo_pos/presentation/home/models/outlet_model.dart';
import 'package:enaklo_pos/presentation/setting/models/tax_model.dart';
import '../../core/constants/variables.dart';
import 'auth_local_datasource.dart';
@@ -12,6 +15,7 @@ class OutletRemoteDataSource {
Future<Either<String, OutletResponse>> getOutlets() async {
try {
final authData = await AuthLocalDataSource().getAuthData();
final url = '${Variables.baseUrl}/api/v1/outlets/list';
final response = await dio.get(
@@ -28,7 +32,8 @@ class OutletRemoteDataSource {
);
if (response.statusCode == 200) {
return Right(OutletResponse.fromMap(response.data));
final data = OutletResponse.fromMap(response.data);
return Right(data);
} else {
return const Left('Failed to get outlets');
}
@@ -66,7 +71,17 @@ class OutletRemoteDataSource {
);
if (response.statusCode == 200) {
return Right(OutletDetailResponse.fromMap(response.data));
final data = OutletDetailResponse.fromMap(response.data);
await SettingsLocalDatasource().saveTax(
TaxModel(
name: 'PB1',
type: TaxType.pajak,
value: data.data?.taxRate ?? 0,
),
);
await OutletLocalDatasource().save(data.data!);
return Right(data);
} else {
return const Left('Failed to get outlets');
}
@@ -17,6 +17,7 @@ class ProductRemoteDatasource {
int page = 1,
int limit = Variables.defaultLimit,
String? categoryId,
String? search,
}) async {
try {
final authData = await AuthLocalDataSource().getAuthData();
@@ -31,6 +32,10 @@ class ProductRemoteDatasource {
queryParameters['category_id'] = categoryId;
}
if (search != null && search.isNotEmpty) {
queryParameters['search'] = search;
}
final response = await dio.get(
url,
queryParameters: queryParameters,
@@ -55,7 +55,7 @@ class TableRemoteDataSource {
Future<Either<String, TableResponseModel>> getTable({
int page = 1,
int limit = 10,
int limit = 50,
String? status,
}) async {
try {
@@ -131,4 +131,40 @@ class TableRemoteDataSource {
return const Left('Unexpected error occurred');
}
}
Future<Either<String, bool>> transferTable({
required String fromTableId,
required String toTableId,
}) async {
try {
final authData = await AuthLocalDataSource().getAuthData();
final url = '${Variables.baseUrl}/api/v1/tables/transfer';
final response = await dio.put(
url,
data: {
"from_table": fromTableId,
"to_table": toTableId,
},
options: Options(
headers: {
'Authorization': 'Bearer ${authData.token}',
'Accept': 'application/json',
},
),
);
if (response.statusCode == 200 || response.statusCode == 201) {
return Right(true);
} else {
return const Left('Failed to create table');
}
} on DioException catch (e) {
log("Dio error: ${e.message}");
return Left(e.response?.data['message'] ?? 'Gagal membuat table');
} catch (e) {
log("Unexpected error: $e");
return const Left('Unexpected error occurred');
}
}
}
@@ -78,3 +78,60 @@ class PaymentOrderItemModel {
"amount": amount,
};
}
class PaymentSplitBillRequest {
final String orderId;
final String paymentMethodId;
final String customerId;
final String type; // e.g., "AMOUNT" or "ITEM"
final int amount;
final List<SplitItem> items;
PaymentSplitBillRequest({
required this.orderId,
required this.paymentMethodId,
required this.customerId,
required this.type,
required this.amount,
required this.items,
});
Map<String, dynamic> toMap() {
Map<String, dynamic> data = {
'order_id': orderId,
'payment_method_id': paymentMethodId,
'type': type,
};
if (customerId.isNotEmpty) {
data['customer_id'] = customerId;
}
if (type == "AMOUNT") {
data['amount'] = amount;
}
if (type == "ITEM") {
data['items'] = items.map((e) => e.toJson()).toList();
}
return data;
}
}
class SplitItem {
final String orderItemId;
final int quantity;
SplitItem({
required this.orderItemId,
required this.quantity,
});
Map<String, dynamic> toJson() {
return {
'order_item_id': orderItemId,
'quantity': quantity,
};
}
}
@@ -59,12 +59,18 @@ class DashboardAnalyticData {
dateFrom: map['date_from'],
dateTo: map['date_to'],
overview: DashboardOverview.fromMap(map['overview']),
topProducts: List<TopProduct>.from(
map['top_products']?.map((x) => TopProduct.fromMap(x))),
paymentMethods: List<PaymentMethodAnalytic>.from(map['payment_methods']
?.map((x) => PaymentMethodAnalytic.fromMap(x))),
recentSales: List<RecentSale>.from(
map['recent_sales']?.map((x) => RecentSale.fromMap(x))),
topProducts: map['top_products'] == null
? []
: List<TopProduct>.from(
map['top_products']?.map((x) => TopProduct.fromMap(x))),
paymentMethods: map['payment_methods'] == null
? []
: List<PaymentMethodAnalytic>.from(map['payment_methods']
?.map((x) => PaymentMethodAnalytic.fromMap(x))),
recentSales: map['recent_sales'] == null
? []
: List<RecentSale>.from(
map['recent_sales']?.map((x) => RecentSale.fromMap(x))),
);
Map<String, dynamic> toMap() => {
+276 -148
View File
@@ -1,35 +1,5 @@
import 'dart:convert';
class OrderResponseModel {
final bool? success;
final OrderData? data;
final dynamic errors;
OrderResponseModel({
this.success,
this.data,
this.errors,
});
factory OrderResponseModel.fromJson(String str) =>
OrderResponseModel.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory OrderResponseModel.fromMap(Map<String, dynamic> json) =>
OrderResponseModel(
success: json["success"],
data: json["data"] == null ? null : OrderData.fromMap(json["data"]),
errors: json["errors"],
);
Map<String, dynamic> toMap() => {
"success": success,
"data": data?.toMap(),
"errors": errors,
};
}
class OrderDetailResponseModel {
final bool? success;
final Order? data;
@@ -60,40 +30,77 @@ class OrderDetailResponseModel {
};
}
class OrderResponseModel {
final bool? success;
final OrderData? data;
OrderResponseModel({
this.success,
this.data,
});
factory OrderResponseModel.fromJson(String str) =>
OrderResponseModel.fromMap(json.decode(str));
String toJson() => json.encode(toMap());
factory OrderResponseModel.fromMap(Map<String, dynamic> map) {
return OrderResponseModel(
success: map['success'] ?? false,
data: OrderData.fromMap(map['data']),
);
}
Map<String, dynamic> toMap() {
return {
'success': success,
'data': data?.toMap(),
};
}
}
class OrderData {
final List<Order>? orders;
final List<Payment>? payments;
final int? totalCount;
final int? page;
final int? limit;
final int? totalPages;
OrderData({
this.orders,
this.totalCount,
this.page,
this.limit,
this.totalPages,
required this.orders,
required this.payments,
required this.totalCount,
required this.page,
required this.limit,
required this.totalPages,
});
factory OrderData.fromMap(Map<String, dynamic> json) => OrderData(
orders: json["orders"] == null
? []
: List<Order>.from(json["orders"].map((x) => Order.fromMap(x))),
totalCount: json["total_count"],
page: json["page"],
limit: json["limit"],
totalPages: json["total_pages"],
);
factory OrderData.fromMap(Map<String, dynamic> map) {
return OrderData(
orders: map["orders"] == null
? []
: List<Order>.from(map['orders']?.map((x) => Order.fromMap(x))),
payments: map["payments"] == null
? []
: List<Payment>.from(map['payments']?.map((x) => Payment.fromMap(x))),
totalCount: map['total_count'],
page: map['page'],
limit: map['limit'],
totalPages: map['total_pages'],
);
}
Map<String, dynamic> toMap() => {
"orders": orders == null
? []
: List<dynamic>.from(orders!.map((x) => x.toMap())),
"total_count": totalCount,
"page": page,
"limit": limit,
"total_pages": totalPages,
};
Map<String, dynamic> toMap() {
return {
'orders': orders?.map((x) => x.toMap()).toList(),
'payments': payments?.map((x) => x.toMap()).toList(),
'total_count': totalCount,
'page': page,
'limit': limit,
'total_pages': totalPages,
};
}
}
class Order {
@@ -108,11 +115,21 @@ class Order {
final int? taxAmount;
final int? discountAmount;
final int? totalAmount;
final int? totalCost;
final int? remainingAmount;
final String? paymentStatus;
final int? refundAmount;
final bool? isVoid;
final bool? isRefund;
final String? notes;
final Map<String, dynamic>? metadata;
final DateTime? createdAt;
final DateTime? updatedAt;
final List<OrderItem>? orderItems;
final List<Payment>? payments;
final int? totalPaid;
final int? paymentCount;
final String? splitType;
Order({
this.id,
@@ -126,76 +143,108 @@ class Order {
this.taxAmount,
this.discountAmount,
this.totalAmount,
this.totalCost,
this.remainingAmount,
this.paymentStatus,
this.refundAmount,
this.isVoid,
this.isRefund,
this.notes,
this.metadata,
this.createdAt,
this.updatedAt,
this.orderItems,
this.payments,
this.totalPaid,
this.paymentCount,
this.splitType,
});
factory Order.fromMap(Map<String, dynamic> json) => Order(
id: json["id"],
orderNumber: json["order_number"],
outletId: json["outlet_id"],
userId: json["user_id"],
tableNumber: json["table_number"],
orderType: json["order_type"],
status: json["status"],
subtotal: json["subtotal"],
taxAmount: json["tax_amount"],
discountAmount: json["discount_amount"],
totalAmount: json["total_amount"],
notes: json["notes"],
metadata: json["metadata"] ?? {},
createdAt: json["created_at"] == null
? null
: DateTime.parse(json["created_at"]),
updatedAt: json["updated_at"] == null
? null
: DateTime.parse(json["updated_at"]),
orderItems: json["order_items"] == null
? []
: List<OrderItem>.from(
json["order_items"].map((x) => OrderItem.fromMap(x))),
);
factory Order.fromMap(Map<String, dynamic> map) {
return Order(
id: map['id'],
orderNumber: map['order_number'],
outletId: map['outlet_id'],
userId: map['user_id'],
tableNumber: map['table_number'],
orderType: map['order_type'],
status: map['status'],
subtotal: map['subtotal'],
taxAmount: map['tax_amount'],
discountAmount: map['discount_amount'],
totalAmount: map['total_amount'],
totalCost: map['total_cost'],
remainingAmount: map['remaining_amount'],
paymentStatus: map['payment_status'],
refundAmount: map['refund_amount'],
isVoid: map['is_void'],
isRefund: map['is_refund'],
notes: map['notes'],
metadata: map['metadata'] ?? {},
createdAt: DateTime.parse(map['created_at']),
updatedAt: DateTime.parse(map['updated_at']),
orderItems: map["order_items"] == null
? []
: List<OrderItem>.from(
map['order_items'].map((x) => OrderItem.fromMap(x))),
payments: map["payments"] == null
? []
: List<Payment>.from(map['payments'].map((x) => Payment.fromMap(x))),
totalPaid: map['total_paid'],
paymentCount: map['payment_count'],
splitType: map['split_type'] ?? "",
);
}
Map<String, dynamic> toMap() => {
"id": id,
"order_number": orderNumber,
"outlet_id": outletId,
"user_id": userId,
"table_number": tableNumber,
"order_type": orderType,
"status": status,
"subtotal": subtotal,
"tax_amount": taxAmount,
"discount_amount": discountAmount,
"total_amount": totalAmount,
"notes": notes,
"metadata": metadata,
"created_at": createdAt?.toIso8601String(),
"updated_at": updatedAt?.toIso8601String(),
"order_items": orderItems == null
? []
: List<dynamic>.from(orderItems!.map((x) => x.toMap())),
};
Map<String, dynamic> toMap() {
return {
'id': id,
'order_number': orderNumber,
'outlet_id': outletId,
'user_id': userId,
'table_number': tableNumber,
'order_type': orderType,
'status': status,
'subtotal': subtotal,
'tax_amount': taxAmount,
'discount_amount': discountAmount,
'total_amount': totalAmount,
'total_cost': totalCost,
'remaining_amount': remainingAmount,
'payment_status': paymentStatus,
'refund_amount': refundAmount,
'is_void': isVoid,
'is_refund': isRefund,
'notes': notes,
'metadata': metadata,
'created_at': createdAt?.toIso8601String(),
'updated_at': updatedAt?.toIso8601String(),
'order_items': orderItems?.map((x) => x.toMap()).toList(),
'payments': payments?.map((x) => x.toMap()).toList(),
'total_paid': totalPaid,
'payment_count': paymentCount,
'split_type': splitType,
};
}
}
class OrderItem {
final String? id;
final String? orderId;
final String? productId;
final String? productName;
final String? productVariantId;
final String? productVariantName;
final int? quantity;
final int? unitPrice;
final int? totalPrice;
final List<dynamic>? modifiers;
final String? notes;
final String? status;
final DateTime? createdAt;
final DateTime? updatedAt;
String? id;
String? orderId;
String? productId;
String? productName;
String? productVariantId;
String? productVariantName;
int? quantity;
int? unitPrice;
int? totalPrice;
List<dynamic>? modifiers;
String? notes;
String? status;
DateTime? createdAt;
DateTime? updatedAt;
String? printerType;
int? paidQuantity;
OrderItem({
this.id,
@@ -212,43 +261,122 @@ class OrderItem {
this.status,
this.createdAt,
this.updatedAt,
this.printerType,
this.paidQuantity,
});
factory OrderItem.fromMap(Map<String, dynamic> json) => OrderItem(
id: json["id"],
orderId: json["order_id"],
productId: json["product_id"],
productName: json["product_name"],
productVariantId: json["product_variant_id"],
productVariantName: json["product_variant_name"],
quantity: json["quantity"],
unitPrice: json["unit_price"],
totalPrice: json["total_price"],
modifiers: json["modifiers"] ?? [],
notes: json["notes"],
status: json["status"],
createdAt: json["created_at"] == null
? null
: DateTime.parse(json["created_at"]),
updatedAt: json["updated_at"] == null
? null
: DateTime.parse(json["updated_at"]),
);
factory OrderItem.fromMap(Map<String, dynamic> map) {
return OrderItem(
id: map['id'],
orderId: map['order_id'],
productId: map['product_id'],
productName: map['product_name'],
productVariantId: map['product_variant_id'],
productVariantName: map['product_variant_name'],
quantity: map['quantity'],
unitPrice: map['unit_price'],
totalPrice: map['total_price'],
modifiers:
map['modifiers'] == null ? [] : List<dynamic>.from(map['modifiers']),
notes: map['notes'],
status: map['status'],
createdAt: DateTime.parse(map['created_at']),
updatedAt: DateTime.parse(map['updated_at']),
printerType: map['printer_type'],
paidQuantity: map['paid_quantity'],
);
}
Map<String, dynamic> toMap() => {
"id": id,
"order_id": orderId,
"product_id": productId,
"product_name": productName,
"product_variant_id": productVariantId,
"product_variant_name": productVariantName,
"quantity": quantity,
"unit_price": unitPrice,
"total_price": totalPrice,
"modifiers": modifiers,
"notes": notes,
"status": status,
"created_at": createdAt?.toIso8601String(),
"updated_at": updatedAt?.toIso8601String(),
};
Map<String, dynamic> toMap() {
return {
'id': id,
'order_id': orderId,
'product_id': productId,
'product_name': productName,
'product_variant_id': productVariantId,
'product_variant_name': productVariantName,
'quantity': quantity,
'unit_price': unitPrice,
'total_price': totalPrice,
'modifiers': modifiers,
'notes': notes,
'status': status,
'created_at': createdAt?.toIso8601String(),
'updated_at': updatedAt?.toIso8601String(),
'printer_type': printerType,
'paid_quantity': paidQuantity,
};
}
}
class Payment {
final String? id;
final String? orderId;
final String? paymentMethodId;
final String? paymentMethodName;
final String? paymentMethodType;
final int? amount;
final String? status;
final int? splitNumber;
final int? splitTotal;
final String? splitDescription;
final int? refundAmount;
final Map<String, dynamic>? metadata;
final DateTime? createdAt;
final DateTime? updatedAt;
Payment({
this.id,
this.orderId,
this.paymentMethodId,
this.paymentMethodName,
this.paymentMethodType,
this.amount,
this.status,
this.splitNumber,
this.splitTotal,
this.splitDescription,
this.refundAmount,
this.metadata,
this.createdAt,
this.updatedAt,
});
factory Payment.fromMap(Map<String, dynamic> map) {
return Payment(
id: map['id'],
orderId: map['order_id'],
paymentMethodId: map['payment_method_id'],
paymentMethodName: map['payment_method_name'],
paymentMethodType: map['payment_method_type'],
amount: map['amount'],
status: map['status'],
splitNumber: map['split_number'],
splitTotal: map['split_total'],
splitDescription: map['split_description'],
refundAmount: map['refund_amount'],
metadata: map['metadata'] ?? {},
createdAt: DateTime.parse(map['created_at']),
updatedAt: DateTime.parse(map['updated_at']),
);
}
Map<String, dynamic> toMap() {
return {
'id': id,
'order_id': orderId,
'payment_method_id': paymentMethodId,
'payment_method_name': paymentMethodName,
'payment_method_type': paymentMethodType,
'amount': amount,
'status': status,
'split_number': splitNumber,
'split_total': splitTotal,
'split_description': splitDescription,
'refund_amount': refundAmount,
'metadata': metadata,
'created_at': createdAt?.toIso8601String(),
'updated_at': updatedAt?.toIso8601String(),
};
}
}
@@ -64,9 +64,12 @@ class PaymentMethodAnalyticData {
dateTo: DateTime.parse(map['date_to']),
groupBy: map['group_by'],
summary: PaymentSummary.fromMap(map['summary']),
data: List<PaymentMethodAnalyticItem>.from(
map['data']?.map((x) => PaymentMethodAnalyticItem.fromMap(x)) ?? [],
),
data: map['data'] == null
? []
: List<PaymentMethodAnalyticItem>.from(
map['data']?.map((x) => PaymentMethodAnalyticItem.fromMap(x)) ??
[],
),
);
}
@@ -52,9 +52,11 @@ class ProductAnalyticData {
outletId: map['outlet_id'],
dateFrom: DateTime.parse(map['date_from']),
dateTo: DateTime.parse(map['date_to']),
data: List<ProductAnalyticItem>.from(
map['data'].map((x) => ProductAnalyticItem.fromMap(x)),
),
data: map['data'] == null
? []
: List<ProductAnalyticItem>.from(
map['data'].map((x) => ProductAnalyticItem.fromMap(x)),
),
);
Map<String, dynamic> toMap() => {
@@ -72,10 +72,14 @@ class ProfitLossData {
dateTo: map['date_to'],
groupBy: map['group_by'],
summary: ProfitLossSummary.fromMap(map['summary']),
data: List<ProfitLossItem>.from(
map['data'].map((x) => ProfitLossItem.fromMap(x))),
productData: List<ProfitLossProduct>.from(
map['product_data'].map((x) => ProfitLossProduct.fromMap(x))),
data: map['data'] == null
? []
: List<ProfitLossItem>.from(
map['data'].map((x) => ProfitLossItem.fromMap(x))),
productData: map['product_data'] == null
? []
: List<ProfitLossProduct>.from(
map['product_data'].map((x) => ProfitLossProduct.fromMap(x))),
);
}
+17
View File
@@ -0,0 +1,17 @@
enum BusinessType {
restaurant('restaurant'),
retail('retail'),
service('service'),
ticketing('ticketing'),
entertainment('entertainment');
final String value;
const BusinessType(this.value);
static BusinessType fromString(String value) {
return BusinessType.values.firstWhere(
(type) => type.value == value,
orElse: () => BusinessType.restaurant,
);
}
}
+10
View File
@@ -1,5 +1,6 @@
import 'dart:developer';
import 'package:enaklo_pos/core/constants/theme.dart';
import 'package:enaklo_pos/core/network/dio_client.dart';
import 'package:enaklo_pos/data/datasources/analytic_remote_datasource.dart';
import 'package:enaklo_pos/data/datasources/customer_remote_datasource.dart';
import 'package:enaklo_pos/data/datasources/file_remote_datasource.dart';
@@ -18,7 +19,9 @@ import 'package:enaklo_pos/presentation/refund/bloc/refund_bloc.dart';
import 'package:enaklo_pos/presentation/report/blocs/profit_loss/profit_loss_bloc.dart';
import 'package:enaklo_pos/presentation/sales/blocs/order_loader/order_loader_bloc.dart';
import 'package:enaklo_pos/presentation/sales/blocs/payment_form/payment_form_bloc.dart';
import 'package:enaklo_pos/presentation/setting/bloc/get_printer_ticket/get_printer_ticket_bloc.dart';
import 'package:enaklo_pos/presentation/setting/bloc/upload_file/upload_file_bloc.dart';
import 'package:enaklo_pos/presentation/table/blocs/transfer_table/transfer_table_bloc.dart';
import 'package:enaklo_pos/presentation/void/bloc/void_order_bloc.dart';
import 'package:flutter/material.dart';
import 'package:enaklo_pos/data/datasources/auth_local_datasource.dart';
@@ -279,8 +282,15 @@ class _MyAppState extends State<MyApp> {
BlocProvider(
create: (context) => CategoryLoaderBloc(CategoryRemoteDatasource()),
),
BlocProvider(
create: (context) => GetPrinterTicketBloc(),
),
BlocProvider(
create: (context) => TransferTableBloc(TableRemoteDataSource()),
),
],
child: MaterialApp(
navigatorKey: AuthInterceptor.navigatorKey,
debugShowCheckedModeBanner: false,
title: 'POS Resto App',
theme: getApplicationTheme,
@@ -30,11 +30,6 @@ class CustomerTitle extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: () => context.pop(),
icon: Icon(Icons.arrow_back, color: AppColors.black),
),
SpaceWidth(16),
Expanded(
child: Text(
title,
@@ -30,9 +30,14 @@ class CategoryLoaderBloc
updatedAt: DateTime.now(),
),
);
emit(_Loaded(categories));
emit(_Loaded(categories, null));
},
);
});
on<_SetCategoryId>((event, emit) async {
var currentState = state as _Loaded;
emit(_Loaded(currentState.categories, event.categoryId));
});
}
}
@@ -19,32 +19,38 @@ mixin _$CategoryLoaderEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() get,
required TResult Function(String categoryId) setCategoryId,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? get,
TResult? Function(String categoryId)? setCategoryId,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? get,
TResult Function(String categoryId)? setCategoryId,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Get value) get,
required TResult Function(_SetCategoryId value) setCategoryId,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Get value)? get,
TResult? Function(_SetCategoryId value)? setCategoryId,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Get value)? get,
TResult Function(_SetCategoryId value)? setCategoryId,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@@ -111,6 +117,7 @@ class _$GetImpl implements _Get {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() get,
required TResult Function(String categoryId) setCategoryId,
}) {
return get();
}
@@ -119,6 +126,7 @@ class _$GetImpl implements _Get {
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? get,
TResult? Function(String categoryId)? setCategoryId,
}) {
return get?.call();
}
@@ -127,6 +135,7 @@ class _$GetImpl implements _Get {
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? get,
TResult Function(String categoryId)? setCategoryId,
required TResult orElse(),
}) {
if (get != null) {
@@ -139,6 +148,7 @@ class _$GetImpl implements _Get {
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Get value) get,
required TResult Function(_SetCategoryId value) setCategoryId,
}) {
return get(this);
}
@@ -147,6 +157,7 @@ class _$GetImpl implements _Get {
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Get value)? get,
TResult? Function(_SetCategoryId value)? setCategoryId,
}) {
return get?.call(this);
}
@@ -155,6 +166,7 @@ class _$GetImpl implements _Get {
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Get value)? get,
TResult Function(_SetCategoryId value)? setCategoryId,
required TResult orElse(),
}) {
if (get != null) {
@@ -168,13 +180,156 @@ abstract class _Get implements CategoryLoaderEvent {
const factory _Get() = _$GetImpl;
}
/// @nodoc
abstract class _$$SetCategoryIdImplCopyWith<$Res> {
factory _$$SetCategoryIdImplCopyWith(
_$SetCategoryIdImpl value, $Res Function(_$SetCategoryIdImpl) then) =
__$$SetCategoryIdImplCopyWithImpl<$Res>;
@useResult
$Res call({String categoryId});
}
/// @nodoc
class __$$SetCategoryIdImplCopyWithImpl<$Res>
extends _$CategoryLoaderEventCopyWithImpl<$Res, _$SetCategoryIdImpl>
implements _$$SetCategoryIdImplCopyWith<$Res> {
__$$SetCategoryIdImplCopyWithImpl(
_$SetCategoryIdImpl _value, $Res Function(_$SetCategoryIdImpl) _then)
: super(_value, _then);
/// Create a copy of CategoryLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? categoryId = null,
}) {
return _then(_$SetCategoryIdImpl(
null == categoryId
? _value.categoryId
: categoryId // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
class _$SetCategoryIdImpl implements _SetCategoryId {
const _$SetCategoryIdImpl(this.categoryId);
@override
final String categoryId;
@override
String toString() {
return 'CategoryLoaderEvent.setCategoryId(categoryId: $categoryId)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$SetCategoryIdImpl &&
(identical(other.categoryId, categoryId) ||
other.categoryId == categoryId));
}
@override
int get hashCode => Object.hash(runtimeType, categoryId);
/// Create a copy of CategoryLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$SetCategoryIdImplCopyWith<_$SetCategoryIdImpl> get copyWith =>
__$$SetCategoryIdImplCopyWithImpl<_$SetCategoryIdImpl>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() get,
required TResult Function(String categoryId) setCategoryId,
}) {
return setCategoryId(categoryId);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? get,
TResult? Function(String categoryId)? setCategoryId,
}) {
return setCategoryId?.call(categoryId);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? get,
TResult Function(String categoryId)? setCategoryId,
required TResult orElse(),
}) {
if (setCategoryId != null) {
return setCategoryId(categoryId);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Get value) get,
required TResult Function(_SetCategoryId value) setCategoryId,
}) {
return setCategoryId(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Get value)? get,
TResult? Function(_SetCategoryId value)? setCategoryId,
}) {
return setCategoryId?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Get value)? get,
TResult Function(_SetCategoryId value)? setCategoryId,
required TResult orElse(),
}) {
if (setCategoryId != null) {
return setCategoryId(this);
}
return orElse();
}
}
abstract class _SetCategoryId implements CategoryLoaderEvent {
const factory _SetCategoryId(final String categoryId) = _$SetCategoryIdImpl;
String get categoryId;
/// Create a copy of CategoryLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$SetCategoryIdImplCopyWith<_$SetCategoryIdImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$CategoryLoaderState {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<CategoryModel> categories) loaded,
required TResult Function(
List<CategoryModel> categories, String? categoryId)
loaded,
required TResult Function(String message) error,
}) =>
throw _privateConstructorUsedError;
@@ -182,7 +337,8 @@ mixin _$CategoryLoaderState {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<CategoryModel> categories)? loaded,
TResult? Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult? Function(String message)? error,
}) =>
throw _privateConstructorUsedError;
@@ -190,7 +346,8 @@ mixin _$CategoryLoaderState {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<CategoryModel> categories)? loaded,
TResult Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) =>
@@ -286,7 +443,9 @@ class _$InitialImpl implements _Initial {
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<CategoryModel> categories) loaded,
required TResult Function(
List<CategoryModel> categories, String? categoryId)
loaded,
required TResult Function(String message) error,
}) {
return initial();
@@ -297,7 +456,8 @@ class _$InitialImpl implements _Initial {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<CategoryModel> categories)? loaded,
TResult? Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult? Function(String message)? error,
}) {
return initial?.call();
@@ -308,7 +468,8 @@ class _$InitialImpl implements _Initial {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<CategoryModel> categories)? loaded,
TResult Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
@@ -403,7 +564,9 @@ class _$LoadingImpl implements _Loading {
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<CategoryModel> categories) loaded,
required TResult Function(
List<CategoryModel> categories, String? categoryId)
loaded,
required TResult Function(String message) error,
}) {
return loading();
@@ -414,7 +577,8 @@ class _$LoadingImpl implements _Loading {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<CategoryModel> categories)? loaded,
TResult? Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult? Function(String message)? error,
}) {
return loading?.call();
@@ -425,7 +589,8 @@ class _$LoadingImpl implements _Loading {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<CategoryModel> categories)? loaded,
TResult Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
@@ -483,7 +648,7 @@ abstract class _$$LoadedImplCopyWith<$Res> {
_$LoadedImpl value, $Res Function(_$LoadedImpl) then) =
__$$LoadedImplCopyWithImpl<$Res>;
@useResult
$Res call({List<CategoryModel> categories});
$Res call({List<CategoryModel> categories, String? categoryId});
}
/// @nodoc
@@ -500,12 +665,17 @@ class __$$LoadedImplCopyWithImpl<$Res>
@override
$Res call({
Object? categories = null,
Object? categoryId = freezed,
}) {
return _then(_$LoadedImpl(
null == categories
? _value._categories
: categories // ignore: cast_nullable_to_non_nullable
as List<CategoryModel>,
freezed == categoryId
? _value.categoryId
: categoryId // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
@@ -513,7 +683,7 @@ class __$$LoadedImplCopyWithImpl<$Res>
/// @nodoc
class _$LoadedImpl implements _Loaded {
const _$LoadedImpl(final List<CategoryModel> categories)
const _$LoadedImpl(final List<CategoryModel> categories, this.categoryId)
: _categories = categories;
final List<CategoryModel> _categories;
@@ -524,9 +694,12 @@ class _$LoadedImpl implements _Loaded {
return EqualUnmodifiableListView(_categories);
}
@override
final String? categoryId;
@override
String toString() {
return 'CategoryLoaderState.loaded(categories: $categories)';
return 'CategoryLoaderState.loaded(categories: $categories, categoryId: $categoryId)';
}
@override
@@ -535,12 +708,14 @@ class _$LoadedImpl implements _Loaded {
(other.runtimeType == runtimeType &&
other is _$LoadedImpl &&
const DeepCollectionEquality()
.equals(other._categories, _categories));
.equals(other._categories, _categories) &&
(identical(other.categoryId, categoryId) ||
other.categoryId == categoryId));
}
@override
int get hashCode => Object.hash(
runtimeType, const DeepCollectionEquality().hash(_categories));
int get hashCode => Object.hash(runtimeType,
const DeepCollectionEquality().hash(_categories), categoryId);
/// Create a copy of CategoryLoaderState
/// with the given fields replaced by the non-null parameter values.
@@ -555,10 +730,12 @@ class _$LoadedImpl implements _Loaded {
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<CategoryModel> categories) loaded,
required TResult Function(
List<CategoryModel> categories, String? categoryId)
loaded,
required TResult Function(String message) error,
}) {
return loaded(categories);
return loaded(categories, categoryId);
}
@override
@@ -566,10 +743,11 @@ class _$LoadedImpl implements _Loaded {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<CategoryModel> categories)? loaded,
TResult? Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult? Function(String message)? error,
}) {
return loaded?.call(categories);
return loaded?.call(categories, categoryId);
}
@override
@@ -577,12 +755,13 @@ class _$LoadedImpl implements _Loaded {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<CategoryModel> categories)? loaded,
TResult Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
if (loaded != null) {
return loaded(categories);
return loaded(categories, categoryId);
}
return orElse();
}
@@ -626,9 +805,12 @@ class _$LoadedImpl implements _Loaded {
}
abstract class _Loaded implements CategoryLoaderState {
const factory _Loaded(final List<CategoryModel> categories) = _$LoadedImpl;
const factory _Loaded(
final List<CategoryModel> categories, final String? categoryId) =
_$LoadedImpl;
List<CategoryModel> get categories;
String? get categoryId;
/// Create a copy of CategoryLoaderState
/// with the given fields replaced by the non-null parameter values.
@@ -707,7 +889,9 @@ class _$ErrorImpl implements _Error {
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(List<CategoryModel> categories) loaded,
required TResult Function(
List<CategoryModel> categories, String? categoryId)
loaded,
required TResult Function(String message) error,
}) {
return error(message);
@@ -718,7 +902,8 @@ class _$ErrorImpl implements _Error {
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(List<CategoryModel> categories)? loaded,
TResult? Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult? Function(String message)? error,
}) {
return error?.call(message);
@@ -729,7 +914,8 @@ class _$ErrorImpl implements _Error {
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(List<CategoryModel> categories)? loaded,
TResult Function(List<CategoryModel> categories, String? categoryId)?
loaded,
TResult Function(String message)? error,
required TResult orElse(),
}) {
@@ -3,4 +3,6 @@ part of 'category_loader_bloc.dart';
@freezed
class CategoryLoaderEvent with _$CategoryLoaderEvent {
const factory CategoryLoaderEvent.get() = _Get;
const factory CategoryLoaderEvent.setCategoryId(String categoryId) =
_SetCategoryId;
}
@@ -4,7 +4,7 @@ part of 'category_loader_bloc.dart';
class CategoryLoaderState with _$CategoryLoaderState {
const factory CategoryLoaderState.initial() = _Initial;
const factory CategoryLoaderState.loading() = _Loading;
const factory CategoryLoaderState.loaded(List<CategoryModel> categories) =
_Loaded;
const factory CategoryLoaderState.loaded(
List<CategoryModel> categories, String? categoryId) = _Loaded;
const factory CategoryLoaderState.error(String message) = _Error;
}
@@ -77,8 +77,8 @@ class OrderFormBloc extends Bloc<OrderFormEvent, OrderFormState> {
customerName: event.customerName,
notes: '',
orderType: event.orderType.name,
tableId: event.table.id,
tableNumber: event.table.tableName,
tableId: event.table?.id ?? "",
tableNumber: event.table?.tableName ?? "",
outletId: userData.user?.outletId,
customerId: event.customer?.id ?? '',
orderItems: event.items
@@ -131,11 +131,11 @@ class OrderFormBloc extends Bloc<OrderFormEvent, OrderFormState> {
result.fold(
(error) => emit(_Error(error)),
(success) => emit(_Success(success.data!)),
(success) => emit(_SuccessMsg()),
);
} catch (e) {
log("Error in AddOrderItemsBloc: $e");
emit(_Error("Failed to add order items: $e"));
emit(_Error("Ada kesalahan. Coba lagi nanti"));
}
},
);
@@ -27,7 +27,7 @@ mixin _$OrderFormEvent {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)
createWithPayment,
required TResult Function(List<ProductQuantity> items, String orderId)
@@ -53,7 +53,7 @@ mixin _$OrderFormEvent {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult? Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -76,7 +76,7 @@ mixin _$OrderFormEvent {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -226,7 +226,7 @@ class _$StartedImpl implements _Started {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)
createWithPayment,
required TResult Function(List<ProductQuantity> items, String orderId)
@@ -255,7 +255,7 @@ class _$StartedImpl implements _Started {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult? Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -281,7 +281,7 @@ class _$StartedImpl implements _Started {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -496,7 +496,7 @@ class _$CreateImpl implements _Create {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)
createWithPayment,
required TResult Function(List<ProductQuantity> items, String orderId)
@@ -525,7 +525,7 @@ class _$CreateImpl implements _Create {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult? Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -551,7 +551,7 @@ class _$CreateImpl implements _Create {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -652,7 +652,7 @@ abstract class _$$CreateWithPaymentMethodImplCopyWith<$Res> {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod});
}
@@ -674,7 +674,7 @@ class __$$CreateWithPaymentMethodImplCopyWithImpl<$Res>
Object? customerName = null,
Object? customer = freezed,
Object? orderType = null,
Object? table = null,
Object? table = freezed,
Object? paymentMethod = null,
}) {
return _then(_$CreateWithPaymentMethodImpl(
@@ -694,10 +694,10 @@ class __$$CreateWithPaymentMethodImplCopyWithImpl<$Res>
? _value.orderType
: orderType // ignore: cast_nullable_to_non_nullable
as OrderType,
table: null == table
table: freezed == table
? _value.table
: table // ignore: cast_nullable_to_non_nullable
as TableModel,
as TableModel?,
paymentMethod: null == paymentMethod
? _value.paymentMethod
: paymentMethod // ignore: cast_nullable_to_non_nullable
@@ -733,7 +733,7 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod {
@override
final OrderType orderType;
@override
final TableModel table;
final TableModel? table;
@override
final PaymentMethod paymentMethod;
@@ -790,7 +790,7 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)
createWithPayment,
required TResult Function(List<ProductQuantity> items, String orderId)
@@ -820,7 +820,7 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult? Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -847,7 +847,7 @@ class _$CreateWithPaymentMethodImpl implements _CreateWithPaymentMethod {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -922,7 +922,7 @@ abstract class _CreateWithPaymentMethod implements OrderFormEvent {
required final String customerName,
required final Customer? customer,
required final OrderType orderType,
required final TableModel table,
required final TableModel? table,
required final PaymentMethod paymentMethod}) =
_$CreateWithPaymentMethodImpl;
@@ -930,7 +930,7 @@ abstract class _CreateWithPaymentMethod implements OrderFormEvent {
String get customerName;
Customer? get customer;
OrderType get orderType;
TableModel get table;
TableModel? get table;
PaymentMethod get paymentMethod;
/// Create a copy of OrderFormEvent
@@ -1034,7 +1034,7 @@ class _$AddToOrderImpl implements _AddToOrder {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)
createWithPayment,
required TResult Function(List<ProductQuantity> items, String orderId)
@@ -1063,7 +1063,7 @@ class _$AddToOrderImpl implements _AddToOrder {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult? Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -1089,7 +1089,7 @@ class _$AddToOrderImpl implements _AddToOrder {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -1276,7 +1276,7 @@ class _$RefundImpl implements _Refund {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)
createWithPayment,
required TResult Function(List<ProductQuantity> items, String orderId)
@@ -1305,7 +1305,7 @@ class _$RefundImpl implements _Refund {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult? Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -1331,7 +1331,7 @@ class _$RefundImpl implements _Refund {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -1520,7 +1520,7 @@ class _$VoidOrderImpl implements _VoidOrder {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)
createWithPayment,
required TResult Function(List<ProductQuantity> items, String orderId)
@@ -1549,7 +1549,7 @@ class _$VoidOrderImpl implements _VoidOrder {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult? Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -1575,7 +1575,7 @@ class _$VoidOrderImpl implements _VoidOrder {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -1737,7 +1737,7 @@ class _$ToggleItemImpl implements _ToggleItem {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)
createWithPayment,
required TResult Function(List<ProductQuantity> items, String orderId)
@@ -1766,7 +1766,7 @@ class _$ToggleItemImpl implements _ToggleItem {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult? Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -1792,7 +1792,7 @@ class _$ToggleItemImpl implements _ToggleItem {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -1951,7 +1951,7 @@ class _$ToggleSelectAllImpl implements _ToggleSelectAll {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)
createWithPayment,
required TResult Function(List<ProductQuantity> items, String orderId)
@@ -1980,7 +1980,7 @@ class _$ToggleSelectAllImpl implements _ToggleSelectAll {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult? Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -2006,7 +2006,7 @@ class _$ToggleSelectAllImpl implements _ToggleSelectAll {
String customerName,
Customer? customer,
OrderType orderType,
TableModel table,
TableModel? table,
PaymentMethod paymentMethod)?
createWithPayment,
TResult Function(List<ProductQuantity> items, String orderId)? addToOrder,
@@ -15,7 +15,7 @@ class OrderFormEvent with _$OrderFormEvent {
required String customerName,
required Customer? customer,
required OrderType orderType,
required TableModel table,
required TableModel? table,
required PaymentMethod paymentMethod,
}) = _CreateWithPaymentMethod;
const factory OrderFormEvent.addToOrder({
@@ -18,22 +18,22 @@ final _privateConstructorUsedError = UnsupportedError(
mixin _$ProductLoaderEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String? categoryId) getProduct,
required TResult Function(String? categoryId) loadMore,
required TResult Function(String? categoryId, String? search) getProduct,
required TResult Function(String? categoryId, String? search) loadMore,
required TResult Function() refresh,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String? categoryId)? getProduct,
TResult? Function(String? categoryId)? loadMore,
TResult? Function(String? categoryId, String? search)? getProduct,
TResult? Function(String? categoryId, String? search)? loadMore,
TResult? Function()? refresh,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String? categoryId)? getProduct,
TResult Function(String? categoryId)? loadMore,
TResult Function(String? categoryId, String? search)? getProduct,
TResult Function(String? categoryId, String? search)? loadMore,
TResult Function()? refresh,
required TResult orElse(),
}) =>
@@ -89,7 +89,7 @@ abstract class _$$GetProductImplCopyWith<$Res> {
_$GetProductImpl value, $Res Function(_$GetProductImpl) then) =
__$$GetProductImplCopyWithImpl<$Res>;
@useResult
$Res call({String? categoryId});
$Res call({String? categoryId, String? search});
}
/// @nodoc
@@ -106,12 +106,17 @@ class __$$GetProductImplCopyWithImpl<$Res>
@override
$Res call({
Object? categoryId = freezed,
Object? search = freezed,
}) {
return _then(_$GetProductImpl(
categoryId: freezed == categoryId
? _value.categoryId
: categoryId // ignore: cast_nullable_to_non_nullable
as String?,
search: freezed == search
? _value.search
: search // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
@@ -119,14 +124,16 @@ class __$$GetProductImplCopyWithImpl<$Res>
/// @nodoc
class _$GetProductImpl implements _GetProduct {
const _$GetProductImpl({this.categoryId});
const _$GetProductImpl({this.categoryId, this.search});
@override
final String? categoryId;
@override
final String? search;
@override
String toString() {
return 'ProductLoaderEvent.getProduct(categoryId: $categoryId)';
return 'ProductLoaderEvent.getProduct(categoryId: $categoryId, search: $search)';
}
@override
@@ -135,11 +142,12 @@ class _$GetProductImpl implements _GetProduct {
(other.runtimeType == runtimeType &&
other is _$GetProductImpl &&
(identical(other.categoryId, categoryId) ||
other.categoryId == categoryId));
other.categoryId == categoryId) &&
(identical(other.search, search) || other.search == search));
}
@override
int get hashCode => Object.hash(runtimeType, categoryId);
int get hashCode => Object.hash(runtimeType, categoryId, search);
/// Create a copy of ProductLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@@ -152,33 +160,33 @@ class _$GetProductImpl implements _GetProduct {
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String? categoryId) getProduct,
required TResult Function(String? categoryId) loadMore,
required TResult Function(String? categoryId, String? search) getProduct,
required TResult Function(String? categoryId, String? search) loadMore,
required TResult Function() refresh,
}) {
return getProduct(categoryId);
return getProduct(categoryId, search);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String? categoryId)? getProduct,
TResult? Function(String? categoryId)? loadMore,
TResult? Function(String? categoryId, String? search)? getProduct,
TResult? Function(String? categoryId, String? search)? loadMore,
TResult? Function()? refresh,
}) {
return getProduct?.call(categoryId);
return getProduct?.call(categoryId, search);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String? categoryId)? getProduct,
TResult Function(String? categoryId)? loadMore,
TResult Function(String? categoryId, String? search)? getProduct,
TResult Function(String? categoryId, String? search)? loadMore,
TResult Function()? refresh,
required TResult orElse(),
}) {
if (getProduct != null) {
return getProduct(categoryId);
return getProduct(categoryId, search);
}
return orElse();
}
@@ -219,9 +227,11 @@ class _$GetProductImpl implements _GetProduct {
}
abstract class _GetProduct implements ProductLoaderEvent {
const factory _GetProduct({final String? categoryId}) = _$GetProductImpl;
const factory _GetProduct({final String? categoryId, final String? search}) =
_$GetProductImpl;
String? get categoryId;
String? get search;
/// Create a copy of ProductLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@@ -236,7 +246,7 @@ abstract class _$$LoadMoreImplCopyWith<$Res> {
_$LoadMoreImpl value, $Res Function(_$LoadMoreImpl) then) =
__$$LoadMoreImplCopyWithImpl<$Res>;
@useResult
$Res call({String? categoryId});
$Res call({String? categoryId, String? search});
}
/// @nodoc
@@ -253,12 +263,17 @@ class __$$LoadMoreImplCopyWithImpl<$Res>
@override
$Res call({
Object? categoryId = freezed,
Object? search = freezed,
}) {
return _then(_$LoadMoreImpl(
categoryId: freezed == categoryId
? _value.categoryId
: categoryId // ignore: cast_nullable_to_non_nullable
as String?,
search: freezed == search
? _value.search
: search // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
@@ -266,14 +281,16 @@ class __$$LoadMoreImplCopyWithImpl<$Res>
/// @nodoc
class _$LoadMoreImpl implements _LoadMore {
const _$LoadMoreImpl({this.categoryId});
const _$LoadMoreImpl({this.categoryId, this.search});
@override
final String? categoryId;
@override
final String? search;
@override
String toString() {
return 'ProductLoaderEvent.loadMore(categoryId: $categoryId)';
return 'ProductLoaderEvent.loadMore(categoryId: $categoryId, search: $search)';
}
@override
@@ -282,11 +299,12 @@ class _$LoadMoreImpl implements _LoadMore {
(other.runtimeType == runtimeType &&
other is _$LoadMoreImpl &&
(identical(other.categoryId, categoryId) ||
other.categoryId == categoryId));
other.categoryId == categoryId) &&
(identical(other.search, search) || other.search == search));
}
@override
int get hashCode => Object.hash(runtimeType, categoryId);
int get hashCode => Object.hash(runtimeType, categoryId, search);
/// Create a copy of ProductLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@@ -299,33 +317,33 @@ class _$LoadMoreImpl implements _LoadMore {
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String? categoryId) getProduct,
required TResult Function(String? categoryId) loadMore,
required TResult Function(String? categoryId, String? search) getProduct,
required TResult Function(String? categoryId, String? search) loadMore,
required TResult Function() refresh,
}) {
return loadMore(categoryId);
return loadMore(categoryId, search);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String? categoryId)? getProduct,
TResult? Function(String? categoryId)? loadMore,
TResult? Function(String? categoryId, String? search)? getProduct,
TResult? Function(String? categoryId, String? search)? loadMore,
TResult? Function()? refresh,
}) {
return loadMore?.call(categoryId);
return loadMore?.call(categoryId, search);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String? categoryId)? getProduct,
TResult Function(String? categoryId)? loadMore,
TResult Function(String? categoryId, String? search)? getProduct,
TResult Function(String? categoryId, String? search)? loadMore,
TResult Function()? refresh,
required TResult orElse(),
}) {
if (loadMore != null) {
return loadMore(categoryId);
return loadMore(categoryId, search);
}
return orElse();
}
@@ -366,9 +384,11 @@ class _$LoadMoreImpl implements _LoadMore {
}
abstract class _LoadMore implements ProductLoaderEvent {
const factory _LoadMore({final String? categoryId}) = _$LoadMoreImpl;
const factory _LoadMore({final String? categoryId, final String? search}) =
_$LoadMoreImpl;
String? get categoryId;
String? get search;
/// Create a copy of ProductLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@@ -418,8 +438,8 @@ class _$RefreshImpl implements _Refresh {
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(String? categoryId) getProduct,
required TResult Function(String? categoryId) loadMore,
required TResult Function(String? categoryId, String? search) getProduct,
required TResult Function(String? categoryId, String? search) loadMore,
required TResult Function() refresh,
}) {
return refresh();
@@ -428,8 +448,8 @@ class _$RefreshImpl implements _Refresh {
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(String? categoryId)? getProduct,
TResult? Function(String? categoryId)? loadMore,
TResult? Function(String? categoryId, String? search)? getProduct,
TResult? Function(String? categoryId, String? search)? loadMore,
TResult? Function()? refresh,
}) {
return refresh?.call();
@@ -438,8 +458,8 @@ class _$RefreshImpl implements _Refresh {
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(String? categoryId)? getProduct,
TResult Function(String? categoryId)? loadMore,
TResult Function(String? categoryId, String? search)? getProduct,
TResult Function(String? categoryId, String? search)? loadMore,
TResult Function()? refresh,
required TResult orElse(),
}) {
@@ -2,8 +2,9 @@ part of 'product_loader_bloc.dart';
@freezed
class ProductLoaderEvent with _$ProductLoaderEvent {
const factory ProductLoaderEvent.getProduct({String? categoryId}) =
_GetProduct;
const factory ProductLoaderEvent.loadMore({String? categoryId}) = _LoadMore;
const factory ProductLoaderEvent.getProduct(
{String? categoryId, String? search}) = _GetProduct;
const factory ProductLoaderEvent.loadMore(
{String? categoryId, String? search}) = _LoadMore;
const factory ProductLoaderEvent.refresh() = _Refresh;
}
+27 -16
View File
@@ -69,24 +69,35 @@ class _OutletDialogState extends State<OutletDialog> {
),
),
SpaceHeight(24),
BlocBuilder<UserUpdateOutletBloc, UserUpdateOutletState>(
builder: (context, state) {
return state.maybeWhen(
orElse: () => Button.filled(
onPressed: selectedOutlet == null
? null
: () {
context.read<UserUpdateOutletBloc>().add(
UserUpdateOutletEvent.update(
selectedOutlet!.id ?? ""));
},
label: 'Terapkan',
),
loading: () => Center(
child: CircularProgressIndicator(),
),
BlocListener<UserUpdateOutletBloc, UserUpdateOutletState>(
listener: (context, state) {
state.maybeWhen(
orElse: () {},
success: () {
context.pop();
},
);
},
child:
BlocBuilder<UserUpdateOutletBloc, UserUpdateOutletState>(
builder: (context, state) {
return state.maybeWhen(
orElse: () => Button.filled(
onPressed: selectedOutlet == null
? null
: () {
context.read<UserUpdateOutletBloc>().add(
UserUpdateOutletEvent.update(
selectedOutlet!.id ?? ""));
},
label: 'Terapkan',
),
loading: () => Center(
child: CircularProgressIndicator(),
),
);
},
),
),
],
),
@@ -289,7 +289,7 @@ class _PaymentAddOrderDialogState extends State<PaymentAddOrderDialog> {
listener: (context, state) {
state.maybeWhen(
orElse: () {},
success: (data) {
successMsg: () {
context.pop();
context.pushReplacement(
SuccessSaveOrderPage(
@@ -51,7 +51,7 @@ class VariantDialog extends StatelessWidget {
Text(
(variant.priceModifier ?? 0).currencyFormatRpV2,
style: TextStyle(
color: AppColors.grey,
color: AppColors.black,
),
),
],
@@ -45,7 +45,6 @@ class OrderRequestModel {
Map<String, dynamic> data = {
"outlet_id": outletId,
"table_number": tableNumber,
"table_id": tableId,
"order_type": orderType,
"notes": notes,
"order_items": orderItems == null
@@ -58,6 +57,10 @@ class OrderRequestModel {
data["customer_id"] = customerId;
}
if (tableId != null && tableId != "") {
data["table_id"] = tableId;
}
return data;
}
}
@@ -1,5 +1,7 @@
import 'dart:convert';
import 'package:enaklo_pos/data/type/bussines_type.dart';
class OutletResponse {
final bool? success;
final OutletData? data;
@@ -101,7 +103,7 @@ class Outlet {
final String? name;
final String? address;
final String? phoneNumber;
final String? businessType;
final BusinessType? businessType;
final String? currency;
final int? taxRate;
final bool? isActive;
@@ -128,7 +130,7 @@ class Outlet {
name: json["name"],
address: json["address"],
phoneNumber: json["phone_number"],
businessType: json["business_type"],
businessType: BusinessType.fromString(json["business_type"]),
currency: json["currency"],
taxRate: json["tax_rate"],
isActive: json["is_active"],
@@ -146,7 +148,7 @@ class Outlet {
"name": name,
"address": address,
"phone_number": phoneNumber,
"business_type": businessType,
"business_type": businessType?.value,
"currency": currency,
"tax_rate": taxRate,
"is_active": isActive,
@@ -355,7 +355,10 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
(previousValue, element) =>
previousValue +
(element.product.price! *
element.quantity),
element.quantity) +
(element.variant
?.priceModifier ??
0),
));
return Text(
price.currencyFormatRp,
@@ -500,7 +503,9 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
(previousValue, element) =>
previousValue +
(element.product.price! *
element.quantity),
element.quantity) +
(element.variant?.priceModifier ??
0),
),
);
@@ -961,6 +966,23 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
) =>
products,
);
int tax = state.maybeWhen(
orElse: () => 0,
loaded: (
products,
discountModel,
discount,
discountAmount,
tax,
serviceCharge,
totalQuantity,
totalPrice,
draftName,
orderType,
deliveryType,
) =>
tax,
);
return Container(
padding: EdgeInsets.all(16),
@@ -1018,6 +1040,11 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
.pushReplacement(SuccessOrderPage(
productQuantity: items,
order: data,
paymentMethod:
selectedPaymentMethod?.name ?? "",
nominalBayar: totalPriceController
.text.toIntegerFromText,
taxPercentage: tax,
));
},
error: (message) => AppFlushbar.showError(
@@ -1043,12 +1070,15 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
}
context.read<OrderFormBloc>().add(
OrderFormEvent.create(
OrderFormEvent
.createWithPayment(
items: items,
customerName:
customerController
.text,
orderType: orderType,
paymentMethod:
selectedPaymentMethod!,
table: widget.table,
customer:
selectedCustomer,
@@ -3,6 +3,8 @@ import 'dart:async';
import 'dart:developer';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:enaklo_pos/presentation/customer/pages/customer_page.dart';
import 'package:enaklo_pos/presentation/setting/pages/setting_page.dart';
import 'package:enaklo_pos/presentation/table/pages/table_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -14,8 +16,6 @@ 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 'package:enaklo_pos/presentation/setting/pages/printer_configuration_page.dart';
import 'package:enaklo_pos/presentation/setting/pages/settings_page.dart';
import '../../../core/assets/assets.gen.dart';
import '../../auth/bloc/logout/logout_bloc.dart';
@@ -59,9 +59,8 @@ class _DashboardPageState extends State<DashboardPage> {
),
const TablePage(),
const ReportPage(),
const PrinterConfigurationPage(),
// SalesPage(),
const SettingsPage(),
const CustomerPage(),
const SettingPage(),
];
// ignore: unused_local_variable
_connectivitySubscription = Connectivity()
@@ -121,7 +120,7 @@ class _DashboardPageState extends State<DashboardPage> {
onTap: () => _onItemTapped(2),
),
NavItem(
iconPath: Assets.icons.print.path,
iconPath: Assets.icons.people.path,
isActive: _selectedIndex == 3,
onTap: () => _onItemTapped(3),
),
+57 -48
View File
@@ -103,7 +103,8 @@ class _HomePageState extends State<HomePage> {
}).toList();
}
bool _handleScrollNotification(ScrollNotification notification) {
bool _handleScrollNotification(
ScrollNotification notification, String? categoryId) {
// Check if the ScrollController is attached before accessing position
if (!scrollController.hasClients) {
return false;
@@ -111,9 +112,12 @@ class _HomePageState extends State<HomePage> {
if (notification is ScrollEndNotification &&
scrollController.position.extentAfter == 0) {
context
.read<ProductLoaderBloc>()
.add(const ProductLoaderEvent.loadMore());
context.read<ProductLoaderBloc>().add(
ProductLoaderEvent.loadMore(
categoryId: categoryId,
search: searchQuery,
),
);
return true;
}
return false;
@@ -127,7 +131,6 @@ class _HomePageState extends State<HomePage> {
orElse: () {},
loading: () {},
success: () {
context.pop();
Future.delayed(Duration(milliseconds: 300), () {
AppFlushbar.showSuccess(context, 'Outlet berhasil diubah');
context
@@ -148,42 +151,46 @@ class _HomePageState extends State<HomePage> {
flex: 3,
child: Align(
alignment: AlignmentDirectional.topStart,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
HomeTitle(
controller: searchController,
onChanged: (value) {
setState(() {
searchQuery = value;
});
},
),
BlocBuilder<ProductLoaderBloc, ProductLoaderState>(
builder: (context, state) {
return NotificationListener<ScrollNotification>(
onNotification: (notification) {
return state.maybeWhen(
orElse: () => false,
loaded: (products, hasReachedMax, currentPage,
isLoadingMore) {
return _handleScrollNotification(
notification);
},
);
},
child: Expanded(child: BlocBuilder<
CategoryLoaderBloc, CategoryLoaderState>(
builder: (contextCategory, stateCateogry) {
return stateCateogry.maybeWhen(
orElse: () => SizedBox.shrink(),
loading: () {
return const Center(
child: CircularProgressIndicator(),
child: BlocBuilder<CategoryLoaderBloc, CategoryLoaderState>(
builder: (context, state) {
return state.maybeWhen(
orElse: () => Center(
child: CircularProgressIndicator(),
),
loaded: (categories, categoryId) => Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
HomeTitle(
controller: searchController,
onChanged: (value) {
setState(() {
searchQuery = value;
});
Future.delayed(Duration(milliseconds: 600), () {
context.read<ProductLoaderBloc>().add(
ProductLoaderEvent.getProduct(
categoryId: categoryId,
search: value,
),
);
});
},
),
BlocBuilder<ProductLoaderBloc, ProductLoaderState>(
builder: (context, state) {
return NotificationListener<ScrollNotification>(
onNotification: (notification) {
return state.maybeWhen(
orElse: () => false,
loaded: (products, hasReachedMax,
currentPage, isLoadingMore) {
return _handleScrollNotification(
notification, categoryId);
},
);
},
loaded: (categories) {
return CategoryTabBar(
child: Expanded(
child: CategoryTabBar(
categories: categories,
tabViews: categories.map((category) {
return SizedBox(
@@ -229,15 +236,15 @@ class _HomePageState extends State<HomePage> {
}),
);
}).toList(),
);
},
),
),
);
},
)),
);
},
),
],
),
],
),
);
},
),
),
),
@@ -422,8 +429,10 @@ class _HomePageState extends State<HomePage> {
}
return products
.map((e) =>
e.product.price! *
e.quantity)
(e.product.price! *
e.quantity) +
(e.variant?.priceModifier ??
0))
.reduce((value, element) =>
value + element);
});
@@ -1,5 +1,6 @@
import 'package:enaklo_pos/core/constants/colors.dart';
import 'package:enaklo_pos/data/models/response/category_response_model.dart';
import 'package:enaklo_pos/presentation/home/bloc/category_loader/category_loader_bloc.dart';
import 'package:enaklo_pos/presentation/home/bloc/product_loader/product_loader_bloc.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -36,6 +37,9 @@ class _CategoryTabBarState extends State<CategoryTabBar>
context.read<ProductLoaderBloc>().add(
ProductLoaderEvent.getProduct(categoryId: selectedCategoryId),
);
context
.read<CategoryLoaderBloc>()
.add(CategoryLoaderEvent.setCategoryId(selectedCategoryId ?? ""));
}
}
});
@@ -3,7 +3,6 @@ import 'package:enaklo_pos/core/constants/colors.dart';
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
import 'package:enaklo_pos/core/extensions/string_ext.dart';
import 'package:enaklo_pos/data/models/response/table_model.dart';
import 'package:enaklo_pos/presentation/customer/pages/customer_page.dart';
import 'package:enaklo_pos/presentation/home/bloc/checkout/checkout_bloc.dart';
import 'package:enaklo_pos/presentation/home/dialog/delivery_dialog.dart';
import 'package:enaklo_pos/presentation/home/dialog/type_dialog.dart';
@@ -20,7 +19,7 @@ class HomeRightTitle extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
height: context.deviceHeight * 0.15,
height: context.deviceHeight * 0.12,
decoration: BoxDecoration(
color: AppColors.primary,
border: Border(
@@ -33,52 +32,77 @@ class HomeRightTitle extends StatelessWidget {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
children: [
Expanded(
child: Button.filled(
width: 180.0,
height: 40,
elevation: 0,
onPressed: () => context.push(SalesPage(
status: 'pending',
)),
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
icon: Icon(
Icons.list,
color: Colors.white,
size: 24,
Expanded(
child: Row(
children: [
Expanded(
child: Button.filled(
width: 180.0,
height: 40,
elevation: 0,
onPressed: () => context.push(SalesPage(
status: 'pending',
)),
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
icon: Icon(
Icons.list,
color: Colors.white,
size: 24,
),
label: 'Daftar Pesanan',
),
label: 'Daftar Pesanan',
),
),
Expanded(
child: Button.filled(
width: 180.0,
height: 40,
elevation: 0,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
icon: Icon(
Icons.person_outline,
color: Colors.white,
size: 24,
),
onPressed: () {
if (table == null) {
context.push(CustomerPage());
}
},
label: 'Pelanggan',
),
),
],
],
),
),
Row(
children: [
Expanded(
child: BlocBuilder<CheckoutBloc, CheckoutState>(
Expanded(
child: Row(
children: [
Expanded(
child: BlocBuilder<CheckoutBloc, CheckoutState>(
builder: (context, state) {
return state.maybeWhen(
orElse: () => const SizedBox.shrink(),
loaded: (
items,
discountModel,
discount,
discountAmount,
tax,
serviceCharge,
totalQuantity,
totalPrice,
draftName,
orderType,
deliveryType,
) {
return Button.filled(
width: 180.0,
height: 40,
elevation: 0,
onPressed: () {
showDialog(
context: context,
builder: (context) {
return TypeDialog();
});
},
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
icon: Icon(
Icons.dinner_dining_outlined,
color: Colors.white,
size: 24,
),
label: orderType.value.toTitleCase(),
);
},
);
},
),
),
BlocBuilder<CheckoutBloc, CheckoutState>(
builder: (context, state) {
return state.maybeWhen(
orElse: () => const SizedBox.shrink(),
@@ -95,109 +119,68 @@ class HomeRightTitle extends StatelessWidget {
orderType,
deliveryType,
) {
return Button.filled(
width: 180.0,
height: 40,
elevation: 0,
onPressed: () {
showDialog(
context: context,
builder: (context) {
return TypeDialog();
});
},
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
icon: Icon(
Icons.dinner_dining_outlined,
color: Colors.white,
size: 24,
),
label: orderType.value.toTitleCase(),
);
switch (orderType) {
case OrderType.dineIn:
return Expanded(
child: Button.filled(
width: 180.0,
height: 40,
elevation: 0,
icon: Icon(
Icons.table_restaurant_outlined,
color: Colors.white,
size: 24,
),
onPressed: () {
if (table == null) {
context.push(DashboardPage(
index: 1,
));
}
},
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
label: table == null
? 'Pilih Meja'
: '${table!.tableName}',
),
);
case OrderType.takeAway:
return const SizedBox.shrink();
case OrderType.delivery:
return Expanded(
child: Button.filled(
width: 180.0,
height: 40,
elevation: 0,
icon: Icon(
Icons.motorcycle_outlined,
color: Colors.white,
size: 24,
),
onPressed: () {
showDialog(
context: context,
builder: (context) {
return DeliveryDialog();
});
},
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
label: deliveryType == null
? 'Pilih Pengiriman'
: deliveryType.name,
),
);
default:
return const SizedBox.shrink();
}
},
);
},
),
),
BlocBuilder<CheckoutBloc, CheckoutState>(
builder: (context, state) {
return state.maybeWhen(
orElse: () => const SizedBox.shrink(),
loaded: (
items,
discountModel,
discount,
discountAmount,
tax,
serviceCharge,
totalQuantity,
totalPrice,
draftName,
orderType,
deliveryType,
) {
switch (orderType) {
case OrderType.dineIn:
return Expanded(
child: Button.filled(
width: 180.0,
height: 40,
elevation: 0,
icon: Icon(
Icons.table_restaurant_outlined,
color: Colors.white,
size: 24,
),
onPressed: () {
if (table == null) {
context.push(DashboardPage(
index: 1,
));
}
},
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
label: table == null
? 'Pilih Meja'
: '${table!.tableName}',
),
);
case OrderType.takeAway:
return const SizedBox.shrink();
case OrderType.delivery:
return Expanded(
child: Button.filled(
width: 180.0,
height: 40,
elevation: 0,
icon: Icon(
Icons.motorcycle_outlined,
color: Colors.white,
size: 24,
),
onPressed: () {
showDialog(
context: context,
builder: (context) {
return DeliveryDialog();
});
},
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
label: deliveryType == null
? 'Pilih Pengiriman'
: deliveryType.name,
),
);
default:
return const SizedBox.shrink();
}
},
);
},
),
],
],
),
),
],
),
@@ -23,15 +23,17 @@ class ProductCard extends StatelessWidget {
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
if (data.variants!.isEmpty) {
context.read<CheckoutBloc>().add(
CheckoutEvent.addItem(data, null),
);
} else {
showDialog(
context: context,
builder: (context) => VariantDialog(product: data),
);
if (data.isActive == true) {
if (data.variants!.isEmpty) {
context.read<CheckoutBloc>().add(
CheckoutEvent.addItem(data, null),
);
} else {
showDialog(
context: context,
builder: (context) => VariantDialog(product: data),
);
}
}
},
child: Container(
@@ -161,6 +163,14 @@ class ProductCard extends StatelessWidget {
);
},
),
if (data.isActive == false)
Container(
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
color: AppColors.grey.withOpacity(0.5),
),
),
],
),
),
@@ -17,7 +17,16 @@ import 'package:flutter_bloc/flutter_bloc.dart';
class PaymentPage extends StatefulWidget {
final Order order;
const PaymentPage({Key? key, required this.order}) : super(key: key);
final bool isSplit;
final String? splitType;
final String? customerId;
const PaymentPage({
super.key,
required this.order,
this.isSplit = false,
this.splitType,
this.customerId,
});
@override
State<PaymentPage> createState() => _PaymentPageState();
@@ -363,7 +372,8 @@ class _PaymentPageState extends State<PaymentPage> {
success: (data) {
context.pushReplacement(SuccessPaymentPage(
productQuantity: widget.order.orderItems
?.map(
?.where((item) => item.status == "pending")
.map(
(item) => ProductQuantity(
product: Product(
name: item.productName,
@@ -375,6 +385,8 @@ class _PaymentPageState extends State<PaymentPage> {
.toList() ??
[],
payment: data,
paymentMethod: selectedPaymentMethod?.name ?? '',
nominalBayar: totalPriceController.text.toIntegerFromText,
));
},
error: (message) {
@@ -432,23 +444,42 @@ class _PaymentPageState extends State<PaymentPage> {
final itemPending = widget.order.orderItems
?.where((item) => item.status == "pending")
.toList();
if (widget.isSplit == false) {
final request = PaymentRequestModel(
amount: widget.order.totalAmount ?? 0,
orderId: widget.order.id,
paymentMethodId: selectedPaymentMethod?.id,
splitDescription: '',
splitNumber: 1,
splitTotal: 1,
transactionId: '',
paymentOrderItems: itemPending
?.map((item) => PaymentOrderItemModel(
orderItemId: item.id,
amount: item.totalPrice,
))
.toList(),
);
final request = PaymentRequestModel(
amount: widget.order.totalAmount ?? 0,
orderId: widget.order.id,
paymentMethodId: selectedPaymentMethod?.id,
splitDescription: '',
splitNumber: 1,
splitTotal: 1,
transactionId: '',
paymentOrderItems: itemPending
?.map((item) => PaymentOrderItemModel(
orderItemId: item.id,
amount: item.totalPrice,
))
.toList(),
);
context.read<PaymentFormBloc>().add(PaymentFormEvent.create(request));
context.read<PaymentFormBloc>().add(PaymentFormEvent.create(request));
} else {
final request = PaymentSplitBillRequest(
amount: widget.order.totalAmount ?? 0,
customerId: widget.customerId ?? "",
items: itemPending
?.map((item) => SplitItem(
orderItemId: item.id ?? "",
quantity: item.quantity ?? 0,
))
.toList() ??
[],
orderId: widget.order.id ?? "",
paymentMethodId: selectedPaymentMethod?.id ?? "",
type: widget.splitType ?? "",
);
context.read<PaymentFormBloc>().add(
PaymentFormEvent.createSplitBill(request),
);
}
}
}
@@ -1,6 +1,8 @@
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/extensions/int_ext.dart';
import 'package:enaklo_pos/presentation/home/pages/dashboard_page.dart';
import 'package:flutter/material.dart';
class RefundSuccessDialog extends StatelessWidget {
@@ -102,8 +104,7 @@ class RefundSuccessDialog extends StatelessWidget {
Expanded(
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
Navigator.pop(context);
context.push(DashboardPage());
},
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.primary,
+29 -45
View File
@@ -39,7 +39,11 @@ class _RefundPageState extends State<RefundPage> with TickerProviderStateMixin {
late Animation<double> _scaleAnimation;
final List<Map<String, dynamic>> refundReasons = [
{'value': 'Barang Rusak', 'icon': Icons.broken_image, 'color': Colors.red},
{
'value': 'Barang Rusak',
'icon': Icons.broken_image,
'color': AppColors.primary
},
{'value': 'Salah Item', 'icon': Icons.swap_horiz, 'color': Colors.orange},
{
'value': 'Tidak Sesuai Pesanan',
@@ -56,7 +60,11 @@ class _RefundPageState extends State<RefundPage> with TickerProviderStateMixin {
'icon': Icons.thumb_down,
'color': Colors.purple
},
{'value': 'Lainnya', 'icon': Icons.more_horiz, 'color': Colors.grey},
{
'value': 'Lainnya',
'icon': Icons.more_horiz,
'color': Colors.red,
},
];
@override
@@ -201,13 +209,6 @@ class _RefundPageState extends State<RefundPage> with TickerProviderStateMixin {
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(24),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.08),
blurRadius: 30,
offset: Offset(0, 15),
),
],
),
child: Padding(
padding: EdgeInsets.all(20),
@@ -220,16 +221,12 @@ class _RefundPageState extends State<RefundPage> with TickerProviderStateMixin {
padding: EdgeInsets.all(12),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.green[400]!, Colors.green[600]!],
colors: [
const Color.fromARGB(255, 96, 56, 148),
AppColors.primary
],
),
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.green.withOpacity(0.3),
blurRadius: 15,
offset: Offset(0, 8),
),
],
),
child: Icon(
Icons.receipt_long,
@@ -327,13 +324,6 @@ class _RefundPageState extends State<RefundPage> with TickerProviderStateMixin {
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(24),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.08),
blurRadius: 30,
offset: Offset(0, 15),
),
],
),
child: Padding(
padding: EdgeInsets.all(20),
@@ -345,12 +335,17 @@ class _RefundPageState extends State<RefundPage> with TickerProviderStateMixin {
Container(
padding: EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.amber.withOpacity(0.2),
gradient: LinearGradient(
colors: [
const Color.fromARGB(255, 96, 56, 148),
AppColors.primary
],
),
borderRadius: BorderRadius.circular(12),
),
child: Icon(
Icons.account_balance_wallet,
color: Colors.amber[700],
Icons.account_balance_wallet_outlined,
color: AppColors.white,
size: 24,
),
),
@@ -402,13 +397,6 @@ class _RefundPageState extends State<RefundPage> with TickerProviderStateMixin {
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(24),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.08),
blurRadius: 30,
offset: Offset(0, 15),
),
],
),
child: Padding(
padding: EdgeInsets.all(20),
@@ -421,19 +409,15 @@ class _RefundPageState extends State<RefundPage> with TickerProviderStateMixin {
padding: EdgeInsets.all(12),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.red[400]!, Colors.red[600]!],
colors: [
const Color.fromARGB(255, 96, 56, 148),
AppColors.primary
],
),
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.red.withOpacity(0.3),
blurRadius: 15,
offset: Offset(0, 8),
),
],
),
child: Icon(
Icons.assignment_return,
Icons.assignment_return_outlined,
color: Colors.white,
size: 24,
),
@@ -655,14 +639,14 @@ class _RefundPageState extends State<RefundPage> with TickerProviderStateMixin {
orElse: () => false,
);
return Container(
return SizedBox(
width: double.infinity,
height: 64,
child: ElevatedButton(
onPressed:
isLoading ? null : () => _processRefund(context),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red[600],
backgroundColor: AppColors.primary,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
@@ -172,12 +172,17 @@ class ProfitLossWidget extends StatelessWidget {
break;
}
if (previous == 0) return '+0.0%';
// Handle division by zero and invalid values
if (previous == 0 || previous.isNaN || previous.isInfinite) return '+0.0%';
if (current.isNaN || current.isInfinite) return '+0.0%';
final trendPercentage = ((current - previous) / previous) * 100;
final sign = trendPercentage >= 0 ? '+' : '';
return '$sign${trendPercentage.toStringAsFixed(1)}%';
// Check if trendPercentage is valid
if (trendPercentage.isNaN || trendPercentage.isInfinite) return '+0.0%';
final sign = trendPercentage >= 0 ? '+' : '';
return '$sign${trendPercentage.round()}%';
}
Widget _buildSummaryCards() {
@@ -201,8 +206,7 @@ class ProfitLossWidget extends StatelessWidget {
{
'title': 'Laba Kotor',
'value': _formatCurrency(data.summary.grossProfit),
'subtitle':
'${data.summary.grossProfitMargin.toStringAsFixed(1)}% margin',
'subtitle': '${_safeRound(data.summary.grossProfitMargin)}% margin',
'icon': Icons.trending_up,
'color': AppColorProfitLoss.primary,
'trend': _calculateTrend('grossProfit'),
@@ -210,8 +214,7 @@ class ProfitLossWidget extends StatelessWidget {
{
'title': 'Laba Bersih',
'value': _formatCurrency(data.summary.netProfit),
'subtitle':
'${data.summary.netProfitMargin.toStringAsFixed(1)}% margin',
'subtitle': '${_safeRound(data.summary.netProfitMargin)}% margin',
'icon': Icons.account_balance,
'color': AppColorProfitLoss.info,
'trend': _calculateTrend('netProfit'),
@@ -360,13 +363,17 @@ class ProfitLossWidget extends StatelessWidget {
showTitles: true,
reservedSize: 50,
getTitlesWidget: (value, meta) {
return Text(
'${(value / 1000).toInt()}K',
style: TextStyle(
color: Colors.grey[600],
fontSize: 10,
),
);
final kValue = (value / 1000);
if (kValue.isFinite) {
return Text(
'${kValue.toInt()}K',
style: TextStyle(
color: Colors.grey[600],
fontSize: 10,
),
);
}
return const SizedBox();
},
),
),
@@ -402,8 +409,9 @@ class ProfitLossWidget extends StatelessWidget {
// Garis Pendapatan
LineChartBarData(
spots: data.data.asMap().entries.map((entry) {
final revenue = entry.value.revenue.toDouble();
return FlSpot(
entry.key.toDouble(), entry.value.revenue.toDouble());
entry.key.toDouble(), revenue.isFinite ? revenue : 0);
}).toList(),
isCurved: true,
color: AppColorProfitLoss.info,
@@ -412,8 +420,9 @@ class ProfitLossWidget extends StatelessWidget {
// Garis Biaya
LineChartBarData(
spots: data.data.asMap().entries.map((entry) {
final cost = entry.value.cost.toDouble();
return FlSpot(
entry.key.toDouble(), entry.value.cost.toDouble());
entry.key.toDouble(), cost.isFinite ? cost : 0);
}).toList(),
isCurved: true,
color: AppColorProfitLoss.danger,
@@ -422,8 +431,9 @@ class ProfitLossWidget extends StatelessWidget {
// Garis Laba Bersih
LineChartBarData(
spots: data.data.asMap().entries.map((entry) {
final netProfit = entry.value.netProfit.toDouble();
return FlSpot(entry.key.toDouble(),
entry.value.netProfit.toDouble());
netProfit.isFinite ? netProfit : 0);
}).toList(),
isCurved: true,
color: AppColorProfitLoss.success,
@@ -506,9 +516,10 @@ class ProfitLossWidget extends StatelessWidget {
}
Widget _buildProductItem(ProfitLossProduct product) {
final profitColor = product.grossProfitMargin >= 35
final profitMargin = _safeDouble(product.grossProfitMargin);
final profitColor = profitMargin >= 35
? AppColorProfitLoss.success
: product.grossProfitMargin >= 25
: profitMargin >= 25
? AppColorProfitLoss.warning
: AppColorProfitLoss.danger;
@@ -572,7 +583,7 @@ class ProfitLossWidget extends StatelessWidget {
borderRadius: BorderRadius.circular(6),
),
child: Text(
'${product.grossProfitMargin.toStringAsFixed(1)}%',
'${_safeRound(profitMargin)}%',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
@@ -710,13 +721,17 @@ class ProfitLossWidget extends StatelessWidget {
startDegreeOffset: -90,
sections: breakdownData.asMap().entries.map((entry) {
final item = entry.value;
final grossProfit = data.summary.grossProfit;
final value = item['value'] as int;
// Handle division by zero
final percentage =
(item['value'] as int) / data.summary.grossProfit * 100;
grossProfit > 0 ? (value / grossProfit * 100) : 0.0;
return PieChartSectionData(
color: item['color'] as Color,
value: (item['value'] as int).toDouble(),
title: '${percentage.toStringAsFixed(1)}%',
value: value.toDouble(),
title: '${_safeRound(percentage)}%',
radius: 40,
titleStyle: const TextStyle(
fontSize: 10,
@@ -799,7 +814,7 @@ class ProfitLossWidget extends StatelessWidget {
),
const SizedBox(height: 8),
Text(
'${(data.summary.profitabilityRatio * 100).toStringAsFixed(1)}%',
'${_safeRound(data.summary.profitabilityRatio)}%',
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
@@ -848,9 +863,7 @@ class ProfitLossWidget extends StatelessWidget {
Expanded(
child: _buildMetricCard(
'Nilai Rata-rata Pesanan',
_formatCurrency(
(data.summary.totalRevenue / data.summary.totalOrders)
.round()),
_formatCurrency(_safeCalculateAverageOrder()),
'Per transaksi',
Icons.shopping_cart_outlined,
AppColorProfitLoss.info,
@@ -870,7 +883,7 @@ class ProfitLossWidget extends StatelessWidget {
Expanded(
child: _buildMetricCard(
'Rasio Biaya',
'${((data.summary.totalCost / data.summary.totalRevenue) * 100).toStringAsFixed(1)}%',
'${_safeCalculateCostRatio()}%',
'Dari total pendapatan',
Icons.pie_chart,
AppColorProfitLoss.danger,
@@ -1026,7 +1039,7 @@ class ProfitLossWidget extends StatelessWidget {
borderRadius: BorderRadius.circular(4),
),
child: Text(
'${item.netProfitMargin.toStringAsFixed(1)}%',
'${_safeRound(item.netProfitMargin)}%',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 10,
@@ -1093,6 +1106,31 @@ class ProfitLossWidget extends StatelessWidget {
);
}
// Helper methods for safe calculations
int _safeRound(double value) {
if (value.isNaN || value.isInfinite) return 0;
return value.round();
}
double _safeDouble(double value) {
if (value.isNaN || value.isInfinite) return 0.0;
return value;
}
int _safeCalculateAverageOrder() {
if (data.summary.totalOrders == 0) return 0;
final average = data.summary.totalRevenue / data.summary.totalOrders;
if (average.isNaN || average.isInfinite) return 0;
return average.round();
}
int _safeCalculateCostRatio() {
if (data.summary.totalRevenue == 0) return 0;
final ratio = (data.summary.totalCost / data.summary.totalRevenue) * 100;
if (ratio.isNaN || ratio.isInfinite) return 0;
return ratio.round();
}
IconData _getProductIcon(String category) {
switch (category.toLowerCase()) {
case 'coffee':
@@ -1110,8 +1148,9 @@ class ProfitLossWidget extends StatelessWidget {
}
Color _getMarginColor(double margin) {
if (margin >= 25) return AppColorProfitLoss.success;
if (margin >= 15) return AppColorProfitLoss.warning;
final safeMargin = _safeDouble(margin);
if (safeMargin >= 25) return AppColorProfitLoss.success;
if (safeMargin >= 15) return AppColorProfitLoss.warning;
return AppColorProfitLoss.danger;
}
@@ -1126,7 +1165,7 @@ class ProfitLossWidget extends StatelessWidget {
String _formatCurrencyShort(int amount) {
if (amount >= 1000000) {
return 'Rp ${(amount / 1000000).toStringAsFixed(1)}M';
return 'Rp ${(amount / 1000000).round()}M';
} else if (amount >= 1000) {
return 'Rp ${(amount / 1000).toStringAsFixed(0)}K';
}
@@ -60,6 +60,7 @@ class OrderLoaderBloc extends Bloc<OrderLoaderEvent, OrderLoaderState> {
status: event.status,
dateFrom: event.dateFrom,
dateTo: event.dateTo,
search: event.search,
);
await result.fold(
@@ -108,6 +109,7 @@ class OrderLoaderBloc extends Bloc<OrderLoaderEvent, OrderLoaderState> {
status: event.status,
dateFrom: event.dateFrom,
dateTo: event.dateTo,
search: event.search,
);
await result.fold(
@@ -18,33 +18,36 @@ final _privateConstructorUsedError = UnsupportedError(
mixin _$OrderLoaderEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(
String status, DateTime dateFrom, DateTime dateTo, int? limit)
required TResult Function(String status, DateTime dateFrom, DateTime dateTo,
int? limit, String? search)
getByStatus,
required TResult Function(String id) getById,
required TResult Function(String status, DateTime dateFrom, DateTime dateTo)
required TResult Function(
String status, DateTime dateFrom, DateTime dateTo, String? search)
loadMore,
required TResult Function(String status) refresh,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(
String status, DateTime dateFrom, DateTime dateTo, int? limit)?
TResult? Function(String status, DateTime dateFrom, DateTime dateTo,
int? limit, String? search)?
getByStatus,
TResult? Function(String id)? getById,
TResult? Function(String status, DateTime dateFrom, DateTime dateTo)?
TResult? Function(
String status, DateTime dateFrom, DateTime dateTo, String? search)?
loadMore,
TResult? Function(String status)? refresh,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(
String status, DateTime dateFrom, DateTime dateTo, int? limit)?
TResult Function(String status, DateTime dateFrom, DateTime dateTo,
int? limit, String? search)?
getByStatus,
TResult Function(String id)? getById,
TResult Function(String status, DateTime dateFrom, DateTime dateTo)?
TResult Function(
String status, DateTime dateFrom, DateTime dateTo, String? search)?
loadMore,
TResult Function(String status)? refresh,
required TResult orElse(),
@@ -104,7 +107,12 @@ abstract class _$$GetByStatusImplCopyWith<$Res> {
_$GetByStatusImpl value, $Res Function(_$GetByStatusImpl) then) =
__$$GetByStatusImplCopyWithImpl<$Res>;
@useResult
$Res call({String status, DateTime dateFrom, DateTime dateTo, int? limit});
$Res call(
{String status,
DateTime dateFrom,
DateTime dateTo,
int? limit,
String? search});
}
/// @nodoc
@@ -124,6 +132,7 @@ class __$$GetByStatusImplCopyWithImpl<$Res>
Object? dateFrom = null,
Object? dateTo = null,
Object? limit = freezed,
Object? search = freezed,
}) {
return _then(_$GetByStatusImpl(
null == status
@@ -142,6 +151,10 @@ class __$$GetByStatusImplCopyWithImpl<$Res>
? _value.limit
: limit // ignore: cast_nullable_to_non_nullable
as int?,
search: freezed == search
? _value.search
: search // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
@@ -150,7 +163,7 @@ class __$$GetByStatusImplCopyWithImpl<$Res>
class _$GetByStatusImpl implements _GetByStatus {
const _$GetByStatusImpl(this.status,
{required this.dateFrom, required this.dateTo, this.limit});
{required this.dateFrom, required this.dateTo, this.limit, this.search});
@override
final String status;
@@ -160,10 +173,12 @@ class _$GetByStatusImpl implements _GetByStatus {
final DateTime dateTo;
@override
final int? limit;
@override
final String? search;
@override
String toString() {
return 'OrderLoaderEvent.getByStatus(status: $status, dateFrom: $dateFrom, dateTo: $dateTo, limit: $limit)';
return 'OrderLoaderEvent.getByStatus(status: $status, dateFrom: $dateFrom, dateTo: $dateTo, limit: $limit, search: $search)';
}
@override
@@ -175,11 +190,13 @@ class _$GetByStatusImpl implements _GetByStatus {
(identical(other.dateFrom, dateFrom) ||
other.dateFrom == dateFrom) &&
(identical(other.dateTo, dateTo) || other.dateTo == dateTo) &&
(identical(other.limit, limit) || other.limit == limit));
(identical(other.limit, limit) || other.limit == limit) &&
(identical(other.search, search) || other.search == search));
}
@override
int get hashCode => Object.hash(runtimeType, status, dateFrom, dateTo, limit);
int get hashCode =>
Object.hash(runtimeType, status, dateFrom, dateTo, limit, search);
/// Create a copy of OrderLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@@ -192,45 +209,48 @@ class _$GetByStatusImpl implements _GetByStatus {
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(
String status, DateTime dateFrom, DateTime dateTo, int? limit)
required TResult Function(String status, DateTime dateFrom, DateTime dateTo,
int? limit, String? search)
getByStatus,
required TResult Function(String id) getById,
required TResult Function(String status, DateTime dateFrom, DateTime dateTo)
required TResult Function(
String status, DateTime dateFrom, DateTime dateTo, String? search)
loadMore,
required TResult Function(String status) refresh,
}) {
return getByStatus(status, dateFrom, dateTo, limit);
return getByStatus(status, dateFrom, dateTo, limit, search);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(
String status, DateTime dateFrom, DateTime dateTo, int? limit)?
TResult? Function(String status, DateTime dateFrom, DateTime dateTo,
int? limit, String? search)?
getByStatus,
TResult? Function(String id)? getById,
TResult? Function(String status, DateTime dateFrom, DateTime dateTo)?
TResult? Function(
String status, DateTime dateFrom, DateTime dateTo, String? search)?
loadMore,
TResult? Function(String status)? refresh,
}) {
return getByStatus?.call(status, dateFrom, dateTo, limit);
return getByStatus?.call(status, dateFrom, dateTo, limit, search);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(
String status, DateTime dateFrom, DateTime dateTo, int? limit)?
TResult Function(String status, DateTime dateFrom, DateTime dateTo,
int? limit, String? search)?
getByStatus,
TResult Function(String id)? getById,
TResult Function(String status, DateTime dateFrom, DateTime dateTo)?
TResult Function(
String status, DateTime dateFrom, DateTime dateTo, String? search)?
loadMore,
TResult Function(String status)? refresh,
required TResult orElse(),
}) {
if (getByStatus != null) {
return getByStatus(status, dateFrom, dateTo, limit);
return getByStatus(status, dateFrom, dateTo, limit, search);
}
return orElse();
}
@@ -277,12 +297,14 @@ abstract class _GetByStatus implements OrderLoaderEvent {
const factory _GetByStatus(final String status,
{required final DateTime dateFrom,
required final DateTime dateTo,
final int? limit}) = _$GetByStatusImpl;
final int? limit,
final String? search}) = _$GetByStatusImpl;
String get status;
DateTime get dateFrom;
DateTime get dateTo;
int? get limit;
String? get search;
/// Create a copy of OrderLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@@ -359,11 +381,12 @@ class _$GetByIdImpl implements _GetById {
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(
String status, DateTime dateFrom, DateTime dateTo, int? limit)
required TResult Function(String status, DateTime dateFrom, DateTime dateTo,
int? limit, String? search)
getByStatus,
required TResult Function(String id) getById,
required TResult Function(String status, DateTime dateFrom, DateTime dateTo)
required TResult Function(
String status, DateTime dateFrom, DateTime dateTo, String? search)
loadMore,
required TResult Function(String status) refresh,
}) {
@@ -373,11 +396,12 @@ class _$GetByIdImpl implements _GetById {
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(
String status, DateTime dateFrom, DateTime dateTo, int? limit)?
TResult? Function(String status, DateTime dateFrom, DateTime dateTo,
int? limit, String? search)?
getByStatus,
TResult? Function(String id)? getById,
TResult? Function(String status, DateTime dateFrom, DateTime dateTo)?
TResult? Function(
String status, DateTime dateFrom, DateTime dateTo, String? search)?
loadMore,
TResult? Function(String status)? refresh,
}) {
@@ -387,11 +411,12 @@ class _$GetByIdImpl implements _GetById {
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(
String status, DateTime dateFrom, DateTime dateTo, int? limit)?
TResult Function(String status, DateTime dateFrom, DateTime dateTo,
int? limit, String? search)?
getByStatus,
TResult Function(String id)? getById,
TResult Function(String status, DateTime dateFrom, DateTime dateTo)?
TResult Function(
String status, DateTime dateFrom, DateTime dateTo, String? search)?
loadMore,
TResult Function(String status)? refresh,
required TResult orElse(),
@@ -458,7 +483,8 @@ abstract class _$$LoadMoreImplCopyWith<$Res> {
_$LoadMoreImpl value, $Res Function(_$LoadMoreImpl) then) =
__$$LoadMoreImplCopyWithImpl<$Res>;
@useResult
$Res call({String status, DateTime dateFrom, DateTime dateTo});
$Res call(
{String status, DateTime dateFrom, DateTime dateTo, String? search});
}
/// @nodoc
@@ -477,6 +503,7 @@ class __$$LoadMoreImplCopyWithImpl<$Res>
Object? status = null,
Object? dateFrom = null,
Object? dateTo = null,
Object? search = freezed,
}) {
return _then(_$LoadMoreImpl(
null == status
@@ -491,6 +518,10 @@ class __$$LoadMoreImplCopyWithImpl<$Res>
? _value.dateTo
: dateTo // ignore: cast_nullable_to_non_nullable
as DateTime,
search: freezed == search
? _value.search
: search // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
@@ -499,7 +530,7 @@ class __$$LoadMoreImplCopyWithImpl<$Res>
class _$LoadMoreImpl implements _LoadMore {
const _$LoadMoreImpl(this.status,
{required this.dateFrom, required this.dateTo});
{required this.dateFrom, required this.dateTo, this.search});
@override
final String status;
@@ -507,10 +538,12 @@ class _$LoadMoreImpl implements _LoadMore {
final DateTime dateFrom;
@override
final DateTime dateTo;
@override
final String? search;
@override
String toString() {
return 'OrderLoaderEvent.loadMore(status: $status, dateFrom: $dateFrom, dateTo: $dateTo)';
return 'OrderLoaderEvent.loadMore(status: $status, dateFrom: $dateFrom, dateTo: $dateTo, search: $search)';
}
@override
@@ -521,11 +554,13 @@ class _$LoadMoreImpl implements _LoadMore {
(identical(other.status, status) || other.status == status) &&
(identical(other.dateFrom, dateFrom) ||
other.dateFrom == dateFrom) &&
(identical(other.dateTo, dateTo) || other.dateTo == dateTo));
(identical(other.dateTo, dateTo) || other.dateTo == dateTo) &&
(identical(other.search, search) || other.search == search));
}
@override
int get hashCode => Object.hash(runtimeType, status, dateFrom, dateTo);
int get hashCode =>
Object.hash(runtimeType, status, dateFrom, dateTo, search);
/// Create a copy of OrderLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@@ -538,45 +573,48 @@ class _$LoadMoreImpl implements _LoadMore {
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(
String status, DateTime dateFrom, DateTime dateTo, int? limit)
required TResult Function(String status, DateTime dateFrom, DateTime dateTo,
int? limit, String? search)
getByStatus,
required TResult Function(String id) getById,
required TResult Function(String status, DateTime dateFrom, DateTime dateTo)
required TResult Function(
String status, DateTime dateFrom, DateTime dateTo, String? search)
loadMore,
required TResult Function(String status) refresh,
}) {
return loadMore(status, dateFrom, dateTo);
return loadMore(status, dateFrom, dateTo, search);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(
String status, DateTime dateFrom, DateTime dateTo, int? limit)?
TResult? Function(String status, DateTime dateFrom, DateTime dateTo,
int? limit, String? search)?
getByStatus,
TResult? Function(String id)? getById,
TResult? Function(String status, DateTime dateFrom, DateTime dateTo)?
TResult? Function(
String status, DateTime dateFrom, DateTime dateTo, String? search)?
loadMore,
TResult? Function(String status)? refresh,
}) {
return loadMore?.call(status, dateFrom, dateTo);
return loadMore?.call(status, dateFrom, dateTo, search);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(
String status, DateTime dateFrom, DateTime dateTo, int? limit)?
TResult Function(String status, DateTime dateFrom, DateTime dateTo,
int? limit, String? search)?
getByStatus,
TResult Function(String id)? getById,
TResult Function(String status, DateTime dateFrom, DateTime dateTo)?
TResult Function(
String status, DateTime dateFrom, DateTime dateTo, String? search)?
loadMore,
TResult Function(String status)? refresh,
required TResult orElse(),
}) {
if (loadMore != null) {
return loadMore(status, dateFrom, dateTo);
return loadMore(status, dateFrom, dateTo, search);
}
return orElse();
}
@@ -622,11 +660,13 @@ class _$LoadMoreImpl implements _LoadMore {
abstract class _LoadMore implements OrderLoaderEvent {
const factory _LoadMore(final String status,
{required final DateTime dateFrom,
required final DateTime dateTo}) = _$LoadMoreImpl;
required final DateTime dateTo,
final String? search}) = _$LoadMoreImpl;
String get status;
DateTime get dateFrom;
DateTime get dateTo;
String? get search;
/// Create a copy of OrderLoaderEvent
/// with the given fields replaced by the non-null parameter values.
@@ -703,11 +743,12 @@ class _$RefreshImpl implements _Refresh {
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(
String status, DateTime dateFrom, DateTime dateTo, int? limit)
required TResult Function(String status, DateTime dateFrom, DateTime dateTo,
int? limit, String? search)
getByStatus,
required TResult Function(String id) getById,
required TResult Function(String status, DateTime dateFrom, DateTime dateTo)
required TResult Function(
String status, DateTime dateFrom, DateTime dateTo, String? search)
loadMore,
required TResult Function(String status) refresh,
}) {
@@ -717,11 +758,12 @@ class _$RefreshImpl implements _Refresh {
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(
String status, DateTime dateFrom, DateTime dateTo, int? limit)?
TResult? Function(String status, DateTime dateFrom, DateTime dateTo,
int? limit, String? search)?
getByStatus,
TResult? Function(String id)? getById,
TResult? Function(String status, DateTime dateFrom, DateTime dateTo)?
TResult? Function(
String status, DateTime dateFrom, DateTime dateTo, String? search)?
loadMore,
TResult? Function(String status)? refresh,
}) {
@@ -731,11 +773,12 @@ class _$RefreshImpl implements _Refresh {
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(
String status, DateTime dateFrom, DateTime dateTo, int? limit)?
TResult Function(String status, DateTime dateFrom, DateTime dateTo,
int? limit, String? search)?
getByStatus,
TResult Function(String id)? getById,
TResult Function(String status, DateTime dateFrom, DateTime dateTo)?
TResult Function(
String status, DateTime dateFrom, DateTime dateTo, String? search)?
loadMore,
TResult Function(String status)? refresh,
required TResult orElse(),
@@ -2,15 +2,19 @@ part of 'order_loader_bloc.dart';
@freezed
class OrderLoaderEvent with _$OrderLoaderEvent {
const factory OrderLoaderEvent.getByStatus(String status,
{required DateTime dateFrom,
required DateTime dateTo,
int? limit}) = _GetByStatus;
const factory OrderLoaderEvent.getByStatus(
String status, {
required DateTime dateFrom,
required DateTime dateTo,
int? limit,
String? search,
}) = _GetByStatus;
const factory OrderLoaderEvent.getById(String id) = _GetById;
const factory OrderLoaderEvent.loadMore(
String status, {
required DateTime dateFrom,
required DateTime dateTo,
String? search,
}) = _LoadMore;
const factory OrderLoaderEvent.refresh(String status) = _Refresh;
}
@@ -29,5 +29,22 @@ class PaymentFormBloc extends Bloc<PaymentFormEvent, PaymentFormState> {
}
},
);
on<_CreateSplitBill>(
(event, emit) async {
emit(const _Loading());
try {
final result = await _orderRemoteDatasource
.createPaymentSplitBill(event.payment);
result.fold(
(error) => emit(_Error(error)),
(success) => emit(_Success(success.data!)),
);
} catch (e) {
emit(_Error("Failed to create payment split bill: $e"));
}
},
);
}
}
@@ -16,45 +16,45 @@ final _privateConstructorUsedError = UnsupportedError(
/// @nodoc
mixin _$PaymentFormEvent {
PaymentRequestModel get payment => throw _privateConstructorUsedError;
Object get payment => throw _privateConstructorUsedError;
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(PaymentRequestModel payment) create,
required TResult Function(PaymentSplitBillRequest payment) createSplitBill,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(PaymentRequestModel payment)? create,
TResult? Function(PaymentSplitBillRequest payment)? createSplitBill,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(PaymentRequestModel payment)? create,
TResult Function(PaymentSplitBillRequest payment)? createSplitBill,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Create value) create,
required TResult Function(_CreateSplitBill value) createSplitBill,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Create value)? create,
TResult? Function(_CreateSplitBill value)? createSplitBill,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Create value)? create,
TResult Function(_CreateSplitBill value)? createSplitBill,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
/// Create a copy of PaymentFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$PaymentFormEventCopyWith<PaymentFormEvent> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
@@ -62,8 +62,6 @@ abstract class $PaymentFormEventCopyWith<$Res> {
factory $PaymentFormEventCopyWith(
PaymentFormEvent value, $Res Function(PaymentFormEvent) then) =
_$PaymentFormEventCopyWithImpl<$Res, PaymentFormEvent>;
@useResult
$Res call({PaymentRequestModel payment});
}
/// @nodoc
@@ -78,27 +76,13 @@ class _$PaymentFormEventCopyWithImpl<$Res, $Val extends PaymentFormEvent>
/// Create a copy of PaymentFormEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? payment = null,
}) {
return _then(_value.copyWith(
payment: null == payment
? _value.payment
: payment // ignore: cast_nullable_to_non_nullable
as PaymentRequestModel,
) as $Val);
}
}
/// @nodoc
abstract class _$$CreateImplCopyWith<$Res>
implements $PaymentFormEventCopyWith<$Res> {
abstract class _$$CreateImplCopyWith<$Res> {
factory _$$CreateImplCopyWith(
_$CreateImpl value, $Res Function(_$CreateImpl) then) =
__$$CreateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({PaymentRequestModel payment});
}
@@ -163,6 +147,7 @@ class _$CreateImpl implements _Create {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(PaymentRequestModel payment) create,
required TResult Function(PaymentSplitBillRequest payment) createSplitBill,
}) {
return create(payment);
}
@@ -171,6 +156,7 @@ class _$CreateImpl implements _Create {
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(PaymentRequestModel payment)? create,
TResult? Function(PaymentSplitBillRequest payment)? createSplitBill,
}) {
return create?.call(payment);
}
@@ -179,6 +165,7 @@ class _$CreateImpl implements _Create {
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(PaymentRequestModel payment)? create,
TResult Function(PaymentSplitBillRequest payment)? createSplitBill,
required TResult orElse(),
}) {
if (create != null) {
@@ -191,6 +178,7 @@ class _$CreateImpl implements _Create {
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Create value) create,
required TResult Function(_CreateSplitBill value) createSplitBill,
}) {
return create(this);
}
@@ -199,6 +187,7 @@ class _$CreateImpl implements _Create {
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Create value)? create,
TResult? Function(_CreateSplitBill value)? createSplitBill,
}) {
return create?.call(this);
}
@@ -207,6 +196,7 @@ class _$CreateImpl implements _Create {
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Create value)? create,
TResult Function(_CreateSplitBill value)? createSplitBill,
required TResult orElse(),
}) {
if (create != null) {
@@ -224,12 +214,154 @@ abstract class _Create implements PaymentFormEvent {
/// Create a copy of PaymentFormEvent
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$CreateImplCopyWith<_$CreateImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class _$$CreateSplitBillImplCopyWith<$Res> {
factory _$$CreateSplitBillImplCopyWith(_$CreateSplitBillImpl value,
$Res Function(_$CreateSplitBillImpl) then) =
__$$CreateSplitBillImplCopyWithImpl<$Res>;
@useResult
$Res call({PaymentSplitBillRequest payment});
}
/// @nodoc
class __$$CreateSplitBillImplCopyWithImpl<$Res>
extends _$PaymentFormEventCopyWithImpl<$Res, _$CreateSplitBillImpl>
implements _$$CreateSplitBillImplCopyWith<$Res> {
__$$CreateSplitBillImplCopyWithImpl(
_$CreateSplitBillImpl _value, $Res Function(_$CreateSplitBillImpl) _then)
: super(_value, _then);
/// Create a copy of PaymentFormEvent
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? payment = null,
}) {
return _then(_$CreateSplitBillImpl(
null == payment
? _value.payment
: payment // ignore: cast_nullable_to_non_nullable
as PaymentSplitBillRequest,
));
}
}
/// @nodoc
class _$CreateSplitBillImpl implements _CreateSplitBill {
const _$CreateSplitBillImpl(this.payment);
@override
final PaymentSplitBillRequest payment;
@override
String toString() {
return 'PaymentFormEvent.createSplitBill(payment: $payment)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$CreateSplitBillImpl &&
(identical(other.payment, payment) || other.payment == payment));
}
@override
int get hashCode => Object.hash(runtimeType, payment);
/// Create a copy of PaymentFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$CreateSplitBillImplCopyWith<_$CreateSplitBillImpl> get copyWith =>
__$$CreateSplitBillImplCopyWithImpl<_$CreateSplitBillImpl>(
this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(PaymentRequestModel payment) create,
required TResult Function(PaymentSplitBillRequest payment) createSplitBill,
}) {
return createSplitBill(payment);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function(PaymentRequestModel payment)? create,
TResult? Function(PaymentSplitBillRequest payment)? createSplitBill,
}) {
return createSplitBill?.call(payment);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(PaymentRequestModel payment)? create,
TResult Function(PaymentSplitBillRequest payment)? createSplitBill,
required TResult orElse(),
}) {
if (createSplitBill != null) {
return createSplitBill(payment);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Create value) create,
required TResult Function(_CreateSplitBill value) createSplitBill,
}) {
return createSplitBill(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Create value)? create,
TResult? Function(_CreateSplitBill value)? createSplitBill,
}) {
return createSplitBill?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Create value)? create,
TResult Function(_CreateSplitBill value)? createSplitBill,
required TResult orElse(),
}) {
if (createSplitBill != null) {
return createSplitBill(this);
}
return orElse();
}
}
abstract class _CreateSplitBill implements PaymentFormEvent {
const factory _CreateSplitBill(final PaymentSplitBillRequest payment) =
_$CreateSplitBillImpl;
@override
PaymentSplitBillRequest get payment;
/// Create a copy of PaymentFormEvent
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$CreateSplitBillImplCopyWith<_$CreateSplitBillImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
mixin _$PaymentFormState {
@optionalTypeArgs
@@ -2,5 +2,10 @@ part of 'payment_form_bloc.dart';
@freezed
class PaymentFormEvent with _$PaymentFormEvent {
const factory PaymentFormEvent.create(PaymentRequestModel payment) = _Create;
const factory PaymentFormEvent.create(
PaymentRequestModel payment,
) = _Create;
const factory PaymentFormEvent.createSplitBill(
PaymentSplitBillRequest payment,
) = _CreateSplitBill;
}
@@ -343,6 +343,8 @@ class _PaymentDialogState extends State<PaymentDialog> {
.toList() ??
[],
payment: data,
paymentMethod: selectedPaymentMethod?.name ?? "",
nominalBayar: totalPriceController.text.toIntegerFromText,
));
},
error: (message) {
+48 -46
View File
@@ -6,9 +6,9 @@ import 'package:enaklo_pos/presentation/home/bloc/order_form/order_form_bloc.dar
import 'package:enaklo_pos/presentation/payment/pages/payment_page.dart';
import 'package:enaklo_pos/presentation/refund/pages/refund_page.dart';
import 'package:enaklo_pos/presentation/sales/blocs/order_loader/order_loader_bloc.dart';
import 'package:enaklo_pos/presentation/sales/widgets/sales_payment_summary.dart';
import 'package:enaklo_pos/presentation/split_bill/pages/split_bill_page.dart';
import 'package:enaklo_pos/presentation/void/pages/void_page.dart';
import 'package:enaklo_pos/presentation/sales/widgets/sales_detail.dart';
import 'package:enaklo_pos/presentation/sales/widgets/sales_list_order.dart';
import 'package:enaklo_pos/presentation/sales/widgets/sales_order_information.dart';
import 'package:enaklo_pos/presentation/sales/widgets/sales_payment.dart';
@@ -45,18 +45,6 @@ class _SalesPageState extends State<SalesPage> {
super.initState();
}
List<Order> _filterOrders(List<Order> orders) {
if (searchQuery.isEmpty) {
return orders;
}
return orders.where((order) {
final customerName = order.orderNumber?.toLowerCase() ?? "";
final queryLower = searchQuery.toLowerCase();
return customerName.contains(queryLower);
}).toList();
}
@override
Widget build(BuildContext context) {
return SafeArea(
@@ -71,8 +59,13 @@ class _SalesPageState extends State<SalesPage> {
if (notification is ScrollEndNotification &&
scrollController.position.extentAfter == 0) {
context.read<OrderLoaderBloc>().add(
OrderLoaderEvent.loadMore(widget.status,
dateFrom: startDate, dateTo: endDate));
OrderLoaderEvent.loadMore(
widget.status,
dateFrom: startDate,
dateTo: endDate,
search: searchQuery,
),
);
return true;
}
@@ -92,6 +85,16 @@ class _SalesPageState extends State<SalesPage> {
setState(() {
searchQuery = value;
});
Future.delayed(const Duration(milliseconds: 800), () {
context.read<OrderLoaderBloc>().add(
OrderLoaderEvent.getByStatus(
widget.status,
dateFrom: startDate,
dateTo: endDate,
search: searchQuery,
),
);
});
},
onDateRangeChanged: (start, end) {
setState(() {
@@ -125,8 +128,7 @@ class _SalesPageState extends State<SalesPage> {
),
loaded: (orders, totalOrder, hasReachedMax,
currentPage, isLoadingMore) {
final filtered = _filterOrders(orders);
if (filtered.isEmpty) {
if (orders.isEmpty) {
return Center(
child: Text(
"Belum ada transaksi saat ini. ",
@@ -138,17 +140,17 @@ class _SalesPageState extends State<SalesPage> {
);
} else {
return ListView.builder(
itemCount: filtered.length,
itemCount: orders.length,
controller: scrollController,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
setState(() {
orderDetail = filtered[index];
orderDetail = orders[index];
});
context.read<OrderFormBloc>().add(
OrderFormEvent.started(
filtered[index]));
orders[index]));
},
child: SalesCard(
order: orders[index],
@@ -257,35 +259,35 @@ class _SalesPageState extends State<SalesPage> {
),
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: SalesOrderInformation(
order: orderDetail,
),
),
SpaceWidth(16),
Expanded(
child: SalesDetail(
order: orderDetail,
),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Order Header
SalesOrderInformation(
order: orderDetail,
),
// Order Items
SalesListOrder(order: orderDetail),
const SpaceHeight(16),
// Payment Summary
SalesPaymentSummary(order: orderDetail),
const SpaceHeight(16),
// Payment Information
if (orderDetail?.payments != null &&
orderDetail?.payments!.isNotEmpty ==
true) ...[
SalesPayment(order: orderDetail),
const SpaceHeight(20),
],
),
SalesListOrder(
order: orderDetail,
),
SalesPayment(
order: orderDetail,
),
],
],
),
),
),
)
),
],
),
),
+121 -39
View File
@@ -29,20 +29,57 @@ class SalesCard extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Align(
alignment: Alignment.centerRight,
child: Text(
'${order.orderNumber}',
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
Row(
children: [
Expanded(
child: Text(
'${order.orderNumber}',
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
),
),
),
),
if (order.isRefund == true)
Container(
padding:
const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: Colors.red.withOpacity(0.15),
borderRadius: BorderRadius.circular(16),
),
child: Text(
'Refund',
style: TextStyle(
color: Colors.red,
fontWeight: FontWeight.w600,
fontSize: 10,
letterSpacing: 0.5,
),
),
),
if (order.isVoid == true)
Container(
padding:
const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: Colors.red.withOpacity(0.15),
borderRadius: BorderRadius.circular(16),
),
child: Text(
'Void',
style: TextStyle(
color: Colors.red,
fontWeight: FontWeight.w600,
fontSize: 10,
letterSpacing: 0.5,
),
),
),
],
),
const SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CircleAvatar(
radius: 22,
@@ -63,37 +100,23 @@ class SalesCard extends StatelessWidget {
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 4),
Row(
children: [
Icon(Icons.table_bar, size: 16, color: Colors.grey),
const SizedBox(width: 4),
Text(
'Meja ${order.tableNumber}',
style: TextStyle(color: Colors.grey[600]),
),
],
),
if (order.orderType == "dineIn") ...[
const SizedBox(height: 4),
Row(
children: [
Icon(Icons.table_bar, size: 16, color: Colors.grey),
const SizedBox(width: 4),
Text(
'Meja ${order.tableNumber}',
style: TextStyle(color: Colors.grey[600]),
),
],
),
]
],
),
),
Container(
padding:
const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: Colors.green.withOpacity(0.15),
borderRadius: BorderRadius.circular(16),
),
child: Text(
(order.status ?? "").toUpperCase(),
style: TextStyle(
color: Colors.green,
fontWeight: FontWeight.w600,
fontSize: 12,
letterSpacing: 0.5,
),
),
),
_buildStatus(),
],
),
const SizedBox(height: 16),
@@ -101,7 +124,10 @@ class SalesCard extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
(order.totalAmount ?? 0).currencyFormatRpV2,
order.status == 'pending'
? ((order.totalAmount ?? 0) - (order.totalPaid ?? 0))
.currencyFormatRpV2
: (order.totalAmount ?? 0).currencyFormatRpV2,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
@@ -121,4 +147,60 @@ class SalesCard extends StatelessWidget {
),
);
}
Widget _buildStatus() {
switch (order.status) {
case 'pending':
return Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: Colors.amber.withOpacity(0.15),
borderRadius: BorderRadius.circular(16),
),
child: Text(
(order.status ?? "").toUpperCase(),
style: TextStyle(
color: Colors.amber,
fontWeight: FontWeight.w600,
fontSize: 12,
letterSpacing: 0.5,
),
),
);
case 'completed':
return Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: Colors.green.withOpacity(0.15),
borderRadius: BorderRadius.circular(16),
),
child: Text(
(order.status ?? "").toUpperCase(),
style: TextStyle(
color: Colors.green,
fontWeight: FontWeight.w600,
fontSize: 12,
letterSpacing: 0.5,
),
),
);
default:
return Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.15),
borderRadius: BorderRadius.circular(16),
),
child: Text(
(order.status ?? "").toUpperCase(),
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.w600,
fontSize: 12,
letterSpacing: 0.5,
),
),
);
}
}
}
@@ -1,71 +0,0 @@
import 'package:enaklo_pos/core/constants/colors.dart';
import 'package:enaklo_pos/core/extensions/date_time_ext.dart';
import 'package:enaklo_pos/data/models/response/order_response_model.dart';
import 'package:flutter/material.dart';
class SalesDetail extends StatelessWidget {
final Order? order;
const SalesDetail({super.key, this.order});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: AppColors.white,
borderRadius: BorderRadius.circular(8),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Detail',
style: TextStyle(
color: AppColors.black,
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
_item(
title: 'Pelanggan',
value: order?.metadata?['customer_name'] ?? "-",
),
_item(
title: 'Waktu',
value: (order?.createdAt ?? DateTime.now()).toFormattedDate3(),
),
_item(
title: 'Status',
value: order?.status ?? "-",
),
],
),
);
}
Padding _item({
required String title,
required String value,
}) {
return Padding(
padding: const EdgeInsets.only(top: 12),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
title,
style: const TextStyle(
fontSize: 14,
),
),
Text(
value,
style: const TextStyle(
fontSize: 14,
),
),
],
),
);
}
}
@@ -63,27 +63,6 @@ class SalesListOrder extends StatelessWidget {
),
child: Row(
children: [
Container(
decoration: BoxDecoration(
color: AppColors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: isAllSelected ? AppColors.primary : Colors.grey.shade300,
width: 2,
),
),
child: Checkbox(
value: isAllSelected,
activeColor: AppColors.primary,
checkColor: AppColors.white,
onChanged: (val) {
context
.read<OrderFormBloc>()
.add(OrderFormEvent.toggleSelectAll(val ?? false));
},
),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -179,28 +158,6 @@ class SalesListOrder extends StatelessWidget {
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
decoration: BoxDecoration(
color: AppColors.white,
borderRadius: BorderRadius.circular(6),
border: Border.all(
color:
isSelected ? AppColors.primary : Colors.grey.shade300,
width: 1.5,
),
),
child: Checkbox(
value: isSelected,
activeColor: AppColors.primary,
checkColor: AppColors.white,
onChanged: (_) {
context
.read<OrderFormBloc>()
.add(OrderFormEvent.toggleItem(product));
},
),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -314,6 +271,57 @@ class SalesListOrder extends StatelessWidget {
),
],
),
if (order?.splitType == 'ITEM' && order?.status == 'pending') ...[
SpaceHeight(6),
Align(
alignment: Alignment.centerRight,
child: Container(
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: AppColors.primary.withOpacity(0.2),
borderRadius: BorderRadius.circular(8),
border: Border.all(color: AppColors.primary),
),
child: RichText(
text: TextSpan(
children: [
TextSpan(
text: '${product.paidQuantity} ',
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: AppColors.primary,
),
),
TextSpan(
text: 'dari ',
style: const TextStyle(
fontSize: 12,
color: AppColors.primary,
),
),
TextSpan(
text: '${product.quantity} ',
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: AppColors.primary,
),
),
TextSpan(
text: 'kuantiti telah dibayar.',
style: const TextStyle(
fontSize: 12,
color: AppColors.primary,
),
),
],
),
),
),
)
],
],
),
),
@@ -328,8 +336,8 @@ class SalesListOrder extends StatelessWidget {
switch (status) {
case "pending":
backgroundColor = Colors.orange.withOpacity(0.1);
textColor = Colors.orange.shade700;
backgroundColor = Colors.white;
textColor = Colors.white;
displayText = "Pending";
icon = Icons.access_time;
break;
@@ -1,3 +1,4 @@
import 'package:enaklo_pos/core/components/spaces.dart';
import 'package:enaklo_pos/core/constants/colors.dart';
import 'package:enaklo_pos/core/extensions/date_time_ext.dart';
import 'package:enaklo_pos/data/models/response/order_response_model.dart';
@@ -10,66 +11,121 @@ class SalesOrderInformation extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: AppColors.white,
color: AppColors.primary,
borderRadius: BorderRadius.circular(8),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
order?.orderNumber ?? "",
style: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
_buildStatus(),
],
),
const SizedBox(height: 8),
Row(
children: [
if (order?.orderType == 'dineIn') ...[
_buildRowItem(Icons.table_restaurant_outlined,
'Meja ${order?.tableNumber}'),
const SizedBox(width: 16),
],
_buildRowItem(Icons.restaurant_outlined, '${order?.orderType}'),
],
),
const SizedBox(height: 8),
Text(
'Informasi Pesanan',
style: TextStyle(
color: AppColors.black,
fontSize: 16,
fontWeight: FontWeight.w600,
),
'Pelanggan: ${order?.metadata?['customer_name'] ?? ""}',
style: const TextStyle(color: Colors.white, fontSize: 14),
),
_item(
title: 'No. Order',
value: "${order?.orderNumber}",
),
_item(
title: 'Tanggal',
value: (order?.createdAt ?? DateTime.now()).toFormattedDate2(),
),
_item(
title: 'No. Meja',
value: order?.tableNumber ?? "-",
),
_item(
title: 'Jenis Order',
value: order?.orderType ?? "-",
Text(
'Dibuat: ${order?.createdAt?.toFormattedDate3() ?? ""}',
style: const TextStyle(color: Colors.white70, fontSize: 12),
),
],
),
);
}
Padding _item({
required String title,
required String value,
}) {
return Padding(
padding: const EdgeInsets.only(top: 12),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
title,
style: const TextStyle(
fontSize: 14,
),
),
Text(
value,
style: const TextStyle(
fontSize: 14,
),
),
],
),
Row _buildRowItem(IconData icon, String title) {
return Row(
children: [
Icon(
icon,
color: Colors.white70,
size: 16,
),
const SpaceWidth(4),
Text(
title,
style: const TextStyle(color: Colors.white70, fontSize: 14),
),
],
);
}
Container _buildStatus() {
switch (order?.status) {
case 'pending':
return Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(12),
),
child: Text(
(order?.status ?? "").toUpperCase(),
style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
);
case 'completed':
return Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
decoration: BoxDecoration(
color: Colors.greenAccent,
borderRadius: BorderRadius.circular(12),
),
child: Text(
(order?.status ?? "").toUpperCase(),
style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
);
default:
return Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.circular(12),
),
child: Text(
(order?.status ?? "").toUpperCase(),
style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
);
}
}
}
+138 -61
View File
@@ -1,7 +1,7 @@
import 'package:enaklo_pos/core/components/dashed_divider.dart';
import 'package:enaklo_pos/core/components/spaces.dart';
import 'package:enaklo_pos/core/constants/colors.dart';
import 'package:enaklo_pos/core/extensions/int_ext.dart';
import 'package:enaklo_pos/core/extensions/string_ext.dart';
import 'package:enaklo_pos/data/models/response/order_response_model.dart';
import 'package:flutter/material.dart';
@@ -12,88 +12,165 @@ class SalesPayment extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
margin: const EdgeInsets.only(top: 16),
decoration: BoxDecoration(
color: AppColors.white,
color: Colors.white,
borderRadius: BorderRadius.circular(8),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Informasi Pesanan',
style: TextStyle(
color: AppColors.black,
fontSize: 16,
fontWeight: FontWeight.w600,
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Informasi Pembayaran',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: AppColors.primary,
),
),
_buildPaymentStatus(),
],
),
const SpaceHeight(12),
...List.generate(
order?.payments?.length ?? 0,
(index) => Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: _buildPaymentItem(order?.payments?[index] ?? Payment()),
),
),
SpaceHeight(12),
const SpaceHeight(4),
const Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Subtotal ${order?.orderItems?.length} Produk',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
'Jumlah yang Dibayar',
style: TextStyle(color: Colors.grey.shade700),
),
Text(
(order?.subtotal)?.currencyFormatRp ?? "0",
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
(order?.totalPaid ?? 0).currencyFormatRpV2,
style: TextStyle(fontWeight: FontWeight.w500),
),
],
),
SpaceHeight(12),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Pajak',
style: const TextStyle(
fontSize: 16,
if (((order?.totalAmount ?? 0) - (order?.totalPaid ?? 0)) != 0) ...[
const SpaceHeight(4),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Sisa Tagihan',
style: TextStyle(
color: Colors.red.shade700,
fontWeight: FontWeight.w500,
),
),
),
Text(
(order?.taxAmount)?.currencyFormatRp ?? "0",
style: const TextStyle(
fontSize: 16,
Text(
((order?.totalAmount ?? 0) - (order?.totalPaid ?? 0))
.currencyFormatRpV2,
style: TextStyle(
color: Colors.red.shade700,
fontWeight: FontWeight.w500,
),
),
),
],
),
SpaceHeight(12),
DashedDivider(
color: AppColors.stroke,
),
SpaceHeight(12),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Total',
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w700,
),
),
Text(
(order?.totalAmount)?.currencyFormatRp ?? "0",
style: const TextStyle(
color: AppColors.primary,
fontSize: 18,
fontWeight: FontWeight.w700,
),
),
],
),
],
),
],
],
),
);
}
Container _buildPaymentStatus() {
switch (order?.paymentStatus) {
case 'completed':
return Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: AppColors.green.withOpacity(0.2),
borderRadius: BorderRadius.circular(4),
),
child: Text(
(order?.paymentStatus ?? "").toTitleCase(),
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
color: AppColors.green,
),
),
);
default:
return Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: Colors.amber.shade100,
borderRadius: BorderRadius.circular(4),
),
child: Text(
(order?.paymentStatus ?? "").toTitleCase(),
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
color: Colors.amber.shade800,
),
),
);
}
}
Row _buildPaymentItem(Payment payment) {
return Row(
children: [
Container(
width: 32,
height: 32,
decoration: BoxDecoration(
color: Colors.green.shade100,
borderRadius: BorderRadius.circular(4),
),
child: Icon(
Icons.payments,
color: Colors.green.shade700,
size: 16,
),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
payment.paymentMethodName ?? "",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
),
),
if ((payment.splitTotal ?? 0) > 1)
Text(
'Split ${payment.splitNumber ?? 0} of ${payment.splitTotal ?? 0}',
style: TextStyle(
fontSize: 12,
color: Colors.grey.shade600,
),
),
],
),
),
Text(
(payment.amount ?? 0).currencyFormatRpV2,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: AppColors.green,
),
),
],
);
}
}
@@ -0,0 +1,94 @@
import 'package:enaklo_pos/core/components/dashed_divider.dart';
import 'package:enaklo_pos/core/components/spaces.dart';
import 'package:enaklo_pos/core/constants/colors.dart';
import 'package:enaklo_pos/core/extensions/int_ext.dart';
import 'package:enaklo_pos/data/models/response/order_response_model.dart';
import 'package:flutter/material.dart';
class SalesPaymentSummary extends StatelessWidget {
final Order? order;
const SalesPaymentSummary({super.key, this.order});
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(8),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Ringkasan Pembayaran',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: AppColors.primary,
),
),
const SpaceHeight(12),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Subtotal',
style: TextStyle(color: Colors.grey.shade700),
),
Text((order?.subtotal ?? 0).currencyFormatRpV2),
],
),
const SpaceHeight(4),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Tax',
style: TextStyle(color: Colors.grey.shade700),
),
Text((order?.taxAmount ?? 0).currencyFormatRpV2),
],
),
const SpaceHeight(4),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Discount',
style: TextStyle(color: Colors.grey.shade700),
),
Text((order?.discountAmount ?? 0).currencyFormatRpV2),
],
),
const SpaceHeight(8),
const DashedDivider(
color: AppColors.grey,
),
const SpaceHeight(8),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'Total',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
Text(
(order?.totalAmount ?? 0).currencyFormatRpV2,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: AppColors.primary,
),
),
],
),
],
),
);
}
}
@@ -0,0 +1,20 @@
import 'package:bloc/bloc.dart';
import 'package:enaklo_pos/data/datasources/product_local_datasource.dart';
import 'package:enaklo_pos/data/models/response/print_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'get_printer_ticket_event.dart';
part 'get_printer_ticket_state.dart';
part 'get_printer_ticket_bloc.freezed.dart';
class GetPrinterTicketBloc
extends Bloc<GetPrinterTicketEvent, GetPrinterTicketState> {
GetPrinterTicketBloc() : super(_Initial()) {
on<_Get>((event, emit) async {
emit(_Loading());
final result =
await ProductLocalDatasource.instance.getPrinterByCode('ticket');
emit(_Success(result));
});
}
}
@@ -0,0 +1,608 @@
// 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 'get_printer_ticket_bloc.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(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 _$GetPrinterTicketEvent {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() get,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? get,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? get,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Get value) get,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Get value)? get,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Get value)? get,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $GetPrinterTicketEventCopyWith<$Res> {
factory $GetPrinterTicketEventCopyWith(GetPrinterTicketEvent value,
$Res Function(GetPrinterTicketEvent) then) =
_$GetPrinterTicketEventCopyWithImpl<$Res, GetPrinterTicketEvent>;
}
/// @nodoc
class _$GetPrinterTicketEventCopyWithImpl<$Res,
$Val extends GetPrinterTicketEvent>
implements $GetPrinterTicketEventCopyWith<$Res> {
_$GetPrinterTicketEventCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of GetPrinterTicketEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
abstract class _$$GetImplCopyWith<$Res> {
factory _$$GetImplCopyWith(_$GetImpl value, $Res Function(_$GetImpl) then) =
__$$GetImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$GetImplCopyWithImpl<$Res>
extends _$GetPrinterTicketEventCopyWithImpl<$Res, _$GetImpl>
implements _$$GetImplCopyWith<$Res> {
__$$GetImplCopyWithImpl(_$GetImpl _value, $Res Function(_$GetImpl) _then)
: super(_value, _then);
/// Create a copy of GetPrinterTicketEvent
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$GetImpl implements _Get {
const _$GetImpl();
@override
String toString() {
return 'GetPrinterTicketEvent.get()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$GetImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() get,
}) {
return get();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? get,
}) {
return get?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? get,
required TResult orElse(),
}) {
if (get != null) {
return get();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Get value) get,
}) {
return get(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Get value)? get,
}) {
return get?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Get value)? get,
required TResult orElse(),
}) {
if (get != null) {
return get(this);
}
return orElse();
}
}
abstract class _Get implements GetPrinterTicketEvent {
const factory _Get() = _$GetImpl;
}
/// @nodoc
mixin _$GetPrinterTicketState {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(PrintModel? printer) success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(PrintModel? printer)? success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(PrintModel? printer)? success,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(_Initial value) initial,
required TResult Function(_Loading value) loading,
required TResult Function(_Success value) success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(_Initial value)? initial,
TResult Function(_Loading value)? loading,
TResult Function(_Success value)? success,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $GetPrinterTicketStateCopyWith<$Res> {
factory $GetPrinterTicketStateCopyWith(GetPrinterTicketState value,
$Res Function(GetPrinterTicketState) then) =
_$GetPrinterTicketStateCopyWithImpl<$Res, GetPrinterTicketState>;
}
/// @nodoc
class _$GetPrinterTicketStateCopyWithImpl<$Res,
$Val extends GetPrinterTicketState>
implements $GetPrinterTicketStateCopyWith<$Res> {
_$GetPrinterTicketStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of GetPrinterTicketState
/// 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 _$GetPrinterTicketStateCopyWithImpl<$Res, _$InitialImpl>
implements _$$InitialImplCopyWith<$Res> {
__$$InitialImplCopyWithImpl(
_$InitialImpl _value, $Res Function(_$InitialImpl) _then)
: super(_value, _then);
/// Create a copy of GetPrinterTicketState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$InitialImpl implements _Initial {
const _$InitialImpl();
@override
String toString() {
return 'GetPrinterTicketState.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<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(PrintModel? printer) success,
}) {
return initial();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(PrintModel? printer)? success,
}) {
return initial?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(PrintModel? printer)? success,
required TResult orElse(),
}) {
if (initial != null) {
return initial();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
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 extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success,
}) {
return initial?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
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 GetPrinterTicketState {
const factory _Initial() = _$InitialImpl;
}
/// @nodoc
abstract class _$$LoadingImplCopyWith<$Res> {
factory _$$LoadingImplCopyWith(
_$LoadingImpl value, $Res Function(_$LoadingImpl) then) =
__$$LoadingImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$LoadingImplCopyWithImpl<$Res>
extends _$GetPrinterTicketStateCopyWithImpl<$Res, _$LoadingImpl>
implements _$$LoadingImplCopyWith<$Res> {
__$$LoadingImplCopyWithImpl(
_$LoadingImpl _value, $Res Function(_$LoadingImpl) _then)
: super(_value, _then);
/// Create a copy of GetPrinterTicketState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$LoadingImpl implements _Loading {
const _$LoadingImpl();
@override
String toString() {
return 'GetPrinterTicketState.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<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(PrintModel? printer) success,
}) {
return loading();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(PrintModel? printer)? success,
}) {
return loading?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(PrintModel? printer)? success,
required TResult orElse(),
}) {
if (loading != null) {
return loading();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
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 extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success,
}) {
return loading?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
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 GetPrinterTicketState {
const factory _Loading() = _$LoadingImpl;
}
/// @nodoc
abstract class _$$SuccessImplCopyWith<$Res> {
factory _$$SuccessImplCopyWith(
_$SuccessImpl value, $Res Function(_$SuccessImpl) then) =
__$$SuccessImplCopyWithImpl<$Res>;
@useResult
$Res call({PrintModel? printer});
}
/// @nodoc
class __$$SuccessImplCopyWithImpl<$Res>
extends _$GetPrinterTicketStateCopyWithImpl<$Res, _$SuccessImpl>
implements _$$SuccessImplCopyWith<$Res> {
__$$SuccessImplCopyWithImpl(
_$SuccessImpl _value, $Res Function(_$SuccessImpl) _then)
: super(_value, _then);
/// Create a copy of GetPrinterTicketState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? printer = freezed,
}) {
return _then(_$SuccessImpl(
freezed == printer
? _value.printer
: printer // ignore: cast_nullable_to_non_nullable
as PrintModel?,
));
}
}
/// @nodoc
class _$SuccessImpl implements _Success {
const _$SuccessImpl(this.printer);
@override
final PrintModel? printer;
@override
String toString() {
return 'GetPrinterTicketState.success(printer: $printer)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$SuccessImpl &&
(identical(other.printer, printer) || other.printer == printer));
}
@override
int get hashCode => Object.hash(runtimeType, printer);
/// Create a copy of GetPrinterTicketState
/// 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<TResult extends Object?>({
required TResult Function() initial,
required TResult Function() loading,
required TResult Function(PrintModel? printer) success,
}) {
return success(printer);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? initial,
TResult? Function()? loading,
TResult? Function(PrintModel? printer)? success,
}) {
return success?.call(printer);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function()? initial,
TResult Function()? loading,
TResult Function(PrintModel? printer)? success,
required TResult orElse(),
}) {
if (success != null) {
return success(printer);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
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 extends Object?>({
TResult? Function(_Initial value)? initial,
TResult? Function(_Loading value)? loading,
TResult? Function(_Success value)? success,
}) {
return success?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
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 GetPrinterTicketState {
const factory _Success(final PrintModel? printer) = _$SuccessImpl;
PrintModel? get printer;
/// Create a copy of GetPrinterTicketState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$SuccessImplCopyWith<_$SuccessImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -0,0 +1,6 @@
part of 'get_printer_ticket_bloc.dart';
@freezed
class GetPrinterTicketEvent with _$GetPrinterTicketEvent {
const factory GetPrinterTicketEvent.get() = _Get;
}
@@ -0,0 +1,8 @@
part of 'get_printer_ticket_bloc.dart';
@freezed
class GetPrinterTicketState with _$GetPrinterTicketState {
const factory GetPrinterTicketState.initial() = _Initial;
const factory GetPrinterTicketState.loading() = _Loading;
const factory GetPrinterTicketState.success(PrintModel? printer) = _Success;
}
@@ -0,0 +1,42 @@
import 'package:enaklo_pos/presentation/home/widgets/custom_tab_bar.dart';
import 'package:enaklo_pos/presentation/setting/widgets/bar_printer_page.dart';
import 'package:enaklo_pos/presentation/setting/widgets/checker_printer_page.dart';
import 'package:enaklo_pos/presentation/setting/widgets/kitchen_printer_page.dart';
import 'package:enaklo_pos/presentation/setting/widgets/receipt_printer_page.dart';
import 'package:enaklo_pos/presentation/setting/widgets/settings_title.dart';
import 'package:enaklo_pos/presentation/setting/widgets/ticket_printer_page.dart';
import 'package:flutter/material.dart';
class SettingPrinterPage extends StatelessWidget {
const SettingPrinterPage({super.key});
@override
Widget build(BuildContext context) {
return Column(
children: [
SettingsTitle(
'Printer',
subtitle: 'Kelola printer untuk cetak struk',
),
Expanded(
child: CustomTabBarV2(
tabTitles: [
'Receipt Printer',
'Checker Printer',
'Kitchen Printer',
'Bar Printer',
'Tiket Printer',
],
tabViews: [
ReceiptPrinterPage(),
CheckerPrinterPage(),
KitchenPrinterPage(),
BarPrinterPage(),
TicketPrinterPage()
],
),
),
],
);
}
}
@@ -0,0 +1,112 @@
import 'package:enaklo_pos/core/constants/colors.dart';
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
import 'package:enaklo_pos/presentation/setting/pages/printer_page.dart';
import 'package:enaklo_pos/presentation/setting/pages/setting_tile.dart';
import 'package:flutter/material.dart';
class SettingPage extends StatefulWidget {
const SettingPage({super.key});
@override
State<SettingPage> createState() => _SettingPageState();
}
class _SettingPageState extends State<SettingPage> {
int currentIndex = 0;
String? role;
void indexValue(int index) {
currentIndex = index;
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.background,
body: Row(
children: [
Expanded(
flex: 2,
child: Align(
alignment: Alignment.topCenter,
child: Material(
color: AppColors.white,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 12.0,
),
width: double.infinity,
height: context.deviceHeight * 0.1,
decoration: const BoxDecoration(
color: AppColors.white,
border: Border(
bottom: BorderSide(
color: AppColors.background,
width: 1.0,
),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Pengaturan',
style: TextStyle(
color: AppColors.black,
fontSize: 20,
fontWeight: FontWeight.w600,
),
),
Text(
'Kelola pengaturan aplikasi',
style: TextStyle(
color: AppColors.grey,
fontSize: 14,
),
),
],
),
),
Expanded(
child: SingleChildScrollView(
child: Column(
children: [
SettingTile(
index: 0,
currentIndex: currentIndex,
title: 'Printer',
subtitle: 'Kelola printer',
icon: Icons.print_outlined,
onTap: () => indexValue(0),
),
],
),
),
),
],
),
),
),
),
Expanded(
flex: 4,
child: Align(
alignment: AlignmentDirectional.topStart,
child: IndexedStack(
index: currentIndex,
children: [
SettingPrinterPage(),
],
),
),
),
],
),
);
}
}

Some files were not shown because too many files have changed in this diff Show More