84 lines
2.2 KiB
Dart
84 lines
2.2 KiB
Dart
part of '../printer.dart';
|
|||
|
|
|
||
|
|
/// Satu tujuan cetak dalam sekali proses print.
|
||
|
|
///
|
||
|
|
/// Perhatikan kasir, void, dan split bill sengaja menumpang printer `receipt`
|
||
|
|
/// — ketiganya tidak punya printer sendiri di halaman pengaturan.
|
||
|
|
enum PrintStation {
|
||
|
|
receipt,
|
||
|
|
cashier,
|
||
|
|
checker,
|
||
|
|
kitchen,
|
||
|
|
bar,
|
||
|
|
voided,
|
||
|
|
splitBill;
|
||
|
|
|
||
|
|
String get label => switch (this) {
|
||
|
|
PrintStation.receipt => 'Struk Customer',
|
||
|
|
PrintStation.cashier => 'Struk Kasir',
|
||
|
|
PrintStation.checker => 'Checker',
|
||
|
|
PrintStation.kitchen => 'Kitchen',
|
||
|
|
PrintStation.bar => 'Bar',
|
||
|
|
PrintStation.voided => 'Struk Void',
|
||
|
|
PrintStation.splitBill => 'Struk Split Bill',
|
||
|
|
};
|
||
|
|
|
||
|
|
/// Kode printer di tabel `printers`.
|
||
|
|
String get printerCode => switch (this) {
|
||
|
|
PrintStation.receipt ||
|
||
|
|
PrintStation.cashier ||
|
||
|
|
PrintStation.voided ||
|
||
|
|
PrintStation.splitBill => 'receipt',
|
||
|
|
PrintStation.checker => 'checker',
|
||
|
|
PrintStation.kitchen => 'kitchen',
|
||
|
|
PrintStation.bar => 'bar',
|
||
|
|
};
|
||
|
|
|
||
|
|
/// Station yang hanya mencetak item dengan `printerType` tertentu.
|
||
|
|
/// Station lain mencetak seluruh item order.
|
||
|
|
String? get itemPrinterType => switch (this) {
|
||
|
|
PrintStation.kitchen => 'kitchen',
|
||
|
|
PrintStation.bar => 'bar',
|
||
|
|
_ => null,
|
||
|
|
};
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
enum PrintStationStatus {
|
||
|
|
/// Belum dijalankan.
|
||
|
|
pending,
|
||
|
|
|
||
|
|
/// Sedang dikirim ke printer.
|
||
|
|
printing,
|
||
|
|
|
||
|
|
/// Berhasil dicetak.
|
||
|
|
success,
|
||
|
|
|
||
|
|
/// Gagal — lihat `message`.
|
||
|
|
failed,
|
||
|
|
|
||
|
|
/// Sengaja dilewati, misal tidak ada item untuk station tersebut.
|
||
|
|
/// Ini bukan kegagalan dan tidak perlu dicetak ulang.
|
||
|
|
skipped,
|
||
|
|
}
|
||
|
|
|
||
|
|
@freezed
|
||
|
|
class PrintStationResult with _$PrintStationResult {
|
||
|
|
const PrintStationResult._();
|
||
|
|
|
||
|
|
const factory PrintStationResult({
|
||
|
|
required PrintStation station,
|
||
|
|
required PrintStationStatus status,
|
||
|
|
String? message,
|
||
|
|
@Default(Duration.zero) Duration elapsed,
|
||
|
|
}) = _PrintStationResult;
|
||
|
|
|
||
|
|
factory PrintStationResult.pending(PrintStation station) =>
|
||
|
|
PrintStationResult(station: station, status: PrintStationStatus.pending);
|
||
|
|
|
||
|
|
bool get isSuccess => status == PrintStationStatus.success;
|
||
|
|
bool get isFailed => status == PrintStationStatus.failed;
|
||
|
|
bool get isSkipped => status == PrintStationStatus.skipped;
|
||
|
|
bool get isFinished => isSuccess || isFailed || isSkipped;
|
||
|
|
}
|