181186 - Criar PDV Android para rodar em maquinas P.O.S.
This commit is contained in:
commit
c9983cbad5
204 files changed
+11453
No files matched your search
@@ -0,0 +1,13 @@
|
||||
class AppSession {
|
||||
const AppSession({
|
||||
required this.userId,
|
||||
required this.userName,
|
||||
this.companyId,
|
||||
this.companyName,
|
||||
});
|
||||
|
||||
final int userId;
|
||||
final String userName;
|
||||
final int? companyId;
|
||||
final String? companyName;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
class AppSettings {
|
||||
const AppSettings({
|
||||
required this.serverUrl,
|
||||
required this.companyIdentifier,
|
||||
});
|
||||
|
||||
final String serverUrl;
|
||||
final String companyIdentifier;
|
||||
|
||||
bool get isConfigured => serverUrl.isNotEmpty && companyIdentifier.isNotEmpty;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
other is AppSettings &&
|
||||
other.serverUrl == serverUrl &&
|
||||
other.companyIdentifier == companyIdentifier;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(serverUrl, companyIdentifier);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import 'product.dart';
|
||||
|
||||
class CartItem {
|
||||
const CartItem({required this.product, required this.quantity});
|
||||
|
||||
final Product product;
|
||||
final int quantity;
|
||||
|
||||
int? get subtotalMinorUnits {
|
||||
final unitPrice = product.priceMinorUnits;
|
||||
return unitPrice == null ? null : unitPrice * quantity;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
class Customer {
|
||||
const Customer({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.documentMasked,
|
||||
});
|
||||
|
||||
final int id;
|
||||
final String name;
|
||||
final String documentMasked;
|
||||
|
||||
factory Customer.fromJson(Map<String, dynamic> json) {
|
||||
final id = json['id'];
|
||||
final name = json['name'];
|
||||
if (id is! num || name is! String) {
|
||||
throw const FormatException('Resposta de cliente inválida.');
|
||||
}
|
||||
return Customer(
|
||||
id: id.toInt(),
|
||||
name: name,
|
||||
documentMasked: json['document_masked']?.toString() ?? '',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
class Department {
|
||||
const Department({required this.id, required this.name});
|
||||
|
||||
final int id;
|
||||
final String name;
|
||||
|
||||
factory Department.fromJson(Map<String, dynamic> json) {
|
||||
final id = json['id'];
|
||||
final name = json['name'];
|
||||
if (id is! num || name is! String) {
|
||||
throw const FormatException('Resposta de departamento inválida.');
|
||||
}
|
||||
return Department(id: id.toInt(), name: name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
class HistoricalSale {
|
||||
const HistoricalSale({
|
||||
required this.orderNumber,
|
||||
required this.issueDate,
|
||||
required this.customerName,
|
||||
required this.totalMinorUnits,
|
||||
required this.state,
|
||||
});
|
||||
|
||||
final String orderNumber;
|
||||
final String issueDate;
|
||||
final String customerName;
|
||||
final int totalMinorUnits;
|
||||
final String state;
|
||||
|
||||
factory HistoricalSale.fromJson(Map<String, dynamic> json) {
|
||||
final orderNumber = json['order_number'];
|
||||
final issueDate = json['issue_date'];
|
||||
final customerName = json['customer_name'];
|
||||
final total = json['total'];
|
||||
final state = json['state'];
|
||||
if (orderNumber is! String ||
|
||||
issueDate is! String ||
|
||||
customerName is! String ||
|
||||
total is! num ||
|
||||
state is! String) {
|
||||
throw const FormatException('Pedido inválido no histórico de vendas.');
|
||||
}
|
||||
return HistoricalSale(
|
||||
orderNumber: orderNumber,
|
||||
issueDate: issueDate,
|
||||
customerName: customerName,
|
||||
totalMinorUnits: (total * 100).round(),
|
||||
state: state,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
class PaymentMethod {
|
||||
const PaymentMethod({
|
||||
required this.id,
|
||||
required this.name,
|
||||
this.paymentType,
|
||||
this.conditionId,
|
||||
this.conditionType,
|
||||
this.installments,
|
||||
});
|
||||
|
||||
final int id;
|
||||
final String name;
|
||||
final String? paymentType;
|
||||
final int? conditionId;
|
||||
final String? conditionType;
|
||||
final int? installments;
|
||||
|
||||
factory PaymentMethod.fromJson(Map<String, dynamic> json) {
|
||||
final id = json['id'];
|
||||
final name = json['name'];
|
||||
if (id is! num || name is! String) {
|
||||
throw const FormatException('Resposta de forma de pagamento inválida.');
|
||||
}
|
||||
return PaymentMethod(
|
||||
id: id.toInt(),
|
||||
name: name,
|
||||
paymentType: json['payment_type']?.toString(),
|
||||
conditionId: _asInt(json['condition_id']),
|
||||
conditionType: json['condition_type']?.toString(),
|
||||
installments: _asInt(json['installments']),
|
||||
);
|
||||
}
|
||||
|
||||
static int? _asInt(dynamic value) => value is num ? value.toInt() : null;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
class PosDevice {
|
||||
const PosDevice({
|
||||
required this.platform,
|
||||
this.serial,
|
||||
this.model,
|
||||
this.brand,
|
||||
});
|
||||
|
||||
final String platform;
|
||||
final String? serial;
|
||||
final String? model;
|
||||
final String? brand;
|
||||
|
||||
bool get requiresLicense => platform.toLowerCase() == 'android';
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
class Product {
|
||||
const Product({
|
||||
required this.id,
|
||||
this.gradeId = 0,
|
||||
required this.code,
|
||||
required this.grade,
|
||||
required this.name,
|
||||
required this.departmentCode,
|
||||
required this.writeDate,
|
||||
this.priceMinorUnits,
|
||||
this.stock,
|
||||
this.imageBase64,
|
||||
});
|
||||
|
||||
final int id;
|
||||
final int gradeId;
|
||||
final String code;
|
||||
final String grade;
|
||||
final String name;
|
||||
final int departmentCode;
|
||||
final String writeDate;
|
||||
final int? priceMinorUnits;
|
||||
final num? stock;
|
||||
final String? imageBase64;
|
||||
|
||||
String get cartKey => '$id:$grade';
|
||||
|
||||
factory Product.fromJson(Map<String, dynamic> json) {
|
||||
final id = json['id'];
|
||||
final departmentCode = json['departamento_id'];
|
||||
if (id is! num || departmentCode is! num) {
|
||||
throw const FormatException('Resposta de produto inválida.');
|
||||
}
|
||||
|
||||
return Product(
|
||||
id: id.toInt(),
|
||||
gradeId: json['grade_id'] is num ? (json['grade_id'] as num).toInt() : 0,
|
||||
code: json['codigo']?.toString() ?? '',
|
||||
grade: json['grade']?.toString() ?? '',
|
||||
name: json['descricao']?.toString() ?? '',
|
||||
departmentCode: departmentCode.toInt(),
|
||||
writeDate: json['write_date']?.toString() ?? '',
|
||||
priceMinorUnits: _toMinorUnits(json['preco']),
|
||||
stock: _number(json['qtdEmEstoque']),
|
||||
imageBase64: json['foto'] is String && (json['foto'] as String).isNotEmpty
|
||||
? json['foto'] as String
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
static int? _toMinorUnits(dynamic value) {
|
||||
if (value == null || value is bool) return null;
|
||||
final normalized = value.toString().replaceAll(',', '.');
|
||||
final match = RegExp(r'^(-?)(\d+)(?:\.(\d+))?$').firstMatch(normalized);
|
||||
if (match == null) return null;
|
||||
|
||||
final isNegative = match.group(1) == '-';
|
||||
final whole = int.tryParse(match.group(2)!);
|
||||
if (whole == null) return null;
|
||||
|
||||
final fraction = match.group(3) ?? '';
|
||||
final centsText = fraction.padRight(2, '0');
|
||||
var minorUnits = whole * 100 + int.parse(centsText.substring(0, 2));
|
||||
if (fraction.length > 2 && int.parse(fraction[2]) >= 5) minorUnits++;
|
||||
return isNegative ? -minorUnits : minorUnits;
|
||||
}
|
||||
|
||||
static num? _number(dynamic value) {
|
||||
if (value is num) return value;
|
||||
if (value is String) return num.tryParse(value.replaceAll(',', '.'));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
class SaleCompletion {
|
||||
const SaleCompletion({
|
||||
required this.orderNumber,
|
||||
required this.invoiceId,
|
||||
required this.invoiceNumber,
|
||||
required this.invoiceSeries,
|
||||
this.invoiceState = '',
|
||||
this.invoiceContingency = false,
|
||||
this.invoiceMessage = '',
|
||||
});
|
||||
|
||||
final String orderNumber;
|
||||
final int invoiceId;
|
||||
final String invoiceNumber;
|
||||
final String invoiceSeries;
|
||||
final String invoiceState;
|
||||
final bool invoiceContingency;
|
||||
final String invoiceMessage;
|
||||
|
||||
factory SaleCompletion.fromJson(Map<String, dynamic> json) {
|
||||
final orderNumber = json['order_number'];
|
||||
final invoiceId = json['invoice_id'];
|
||||
final invoiceNumber = json['invoice_number'];
|
||||
final invoiceSeries = json['invoice_series'];
|
||||
final invoiceState = json['invoice_state'];
|
||||
final invoiceContingency = json['invoice_contingency'];
|
||||
final invoiceMessage = json['invoice_message'];
|
||||
if (orderNumber is! String ||
|
||||
invoiceId is! num ||
|
||||
invoiceNumber == null ||
|
||||
invoiceSeries == null) {
|
||||
throw const FormatException('Resposta de finalização inválida.');
|
||||
}
|
||||
return SaleCompletion(
|
||||
orderNumber: orderNumber,
|
||||
invoiceId: invoiceId.toInt(),
|
||||
invoiceNumber: invoiceNumber.toString(),
|
||||
invoiceSeries: invoiceSeries.toString(),
|
||||
invoiceState: invoiceState?.toString() ?? '',
|
||||
invoiceContingency: invoiceContingency == true,
|
||||
invoiceMessage: invoiceMessage?.toString() ?? '',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class SalePayment {
|
||||
const SalePayment({
|
||||
required this.conditionFormId,
|
||||
required this.amountMinorUnits,
|
||||
required this.paymentType,
|
||||
});
|
||||
|
||||
final int conditionFormId;
|
||||
final int amountMinorUnits;
|
||||
final String paymentType;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
enum SaleViewMode { list, kanban }
|
||||
@@ -0,0 +1,28 @@
|
||||
import '../entities/app_settings.dart';
|
||||
import '../entities/app_session.dart';
|
||||
import '../entities/pos_device.dart';
|
||||
|
||||
abstract interface class AuthRepository {
|
||||
bool get isAuthenticated;
|
||||
|
||||
AppSession? get currentSession;
|
||||
|
||||
Future<AppSession> authenticate({
|
||||
required String username,
|
||||
required String password,
|
||||
required AppSettings settings,
|
||||
required PosDevice device,
|
||||
required String appVersion,
|
||||
});
|
||||
|
||||
Future<void> logout();
|
||||
}
|
||||
|
||||
class AuthUnavailableException implements Exception {
|
||||
const AuthUnavailableException(this.message);
|
||||
|
||||
final String message;
|
||||
|
||||
@override
|
||||
String toString() => message;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../entities/cart_item.dart';
|
||||
import '../entities/product.dart';
|
||||
|
||||
abstract interface class CartRepository implements Listenable {
|
||||
List<CartItem> get items;
|
||||
|
||||
int get itemCount;
|
||||
|
||||
int? get totalMinorUnits;
|
||||
|
||||
void addProduct(Product product);
|
||||
|
||||
void increaseQuantity(Product product);
|
||||
|
||||
void decreaseQuantity(Product product);
|
||||
|
||||
void removeProduct(Product product);
|
||||
|
||||
void clear();
|
||||
}
|
||||
|
||||
class InMemoryCartRepository extends ChangeNotifier implements CartRepository {
|
||||
final Map<String, CartItem> _items = {};
|
||||
|
||||
@override
|
||||
List<CartItem> get items => List.unmodifiable(_items.values);
|
||||
|
||||
@override
|
||||
int get itemCount =>
|
||||
_items.values.fold(0, (count, item) => count + item.quantity);
|
||||
|
||||
@override
|
||||
int? get totalMinorUnits {
|
||||
if (_items.values.any((item) => item.product.priceMinorUnits == null)) {
|
||||
return null;
|
||||
}
|
||||
return _items.values.fold<int>(
|
||||
0,
|
||||
(total, item) => total + item.product.priceMinorUnits! * item.quantity,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void addProduct(Product product) {
|
||||
increaseQuantity(product);
|
||||
}
|
||||
|
||||
@override
|
||||
void increaseQuantity(Product product) {
|
||||
final key = product.cartKey;
|
||||
final existing = _items[key];
|
||||
_items[key] = CartItem(
|
||||
product: product,
|
||||
quantity: (existing?.quantity ?? 0) + 1,
|
||||
);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void decreaseQuantity(Product product) {
|
||||
final key = product.cartKey;
|
||||
final existing = _items[key];
|
||||
if (existing == null || existing.quantity <= 1) return;
|
||||
_items[key] = CartItem(
|
||||
product: existing.product,
|
||||
quantity: existing.quantity - 1,
|
||||
);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void removeProduct(Product product) {
|
||||
if (_items.remove(product.cartKey) != null) notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void clear() {
|
||||
if (_items.isEmpty) return;
|
||||
_items.clear();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import '../entities/department.dart';
|
||||
import '../entities/product.dart';
|
||||
|
||||
abstract interface class CatalogRepository {
|
||||
Future<List<Department>> fetchDepartments();
|
||||
|
||||
Future<List<Product>> fetchProductsByDepartment(int departmentId);
|
||||
|
||||
Future<Product?> fetchProductByBarcode(String barcode);
|
||||
}
|
||||
|
||||
class CatalogException implements Exception {
|
||||
const CatalogException(this.message);
|
||||
|
||||
final String message;
|
||||
|
||||
@override
|
||||
String toString() => message;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
class ConnectionTestResult {
|
||||
const ConnectionTestResult({
|
||||
required this.isAvailable,
|
||||
required this.message,
|
||||
});
|
||||
|
||||
final bool isAvailable;
|
||||
final String message;
|
||||
}
|
||||
|
||||
abstract interface class ConnectionTester {
|
||||
Future<ConnectionTestResult> test(Uri serverUri);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import '../entities/customer.dart';
|
||||
|
||||
abstract interface class CustomerRepository {
|
||||
Future<List<Customer>> search(String query);
|
||||
}
|
||||
|
||||
class CustomerSearchException implements Exception {
|
||||
const CustomerSearchException(this.message);
|
||||
|
||||
final String message;
|
||||
|
||||
@override
|
||||
String toString() => message;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import '../entities/payment_method.dart';
|
||||
|
||||
abstract interface class PaymentMethodsRepository {
|
||||
Future<List<PaymentMethod>> loadAvailable();
|
||||
}
|
||||
|
||||
class PaymentMethodsException implements Exception {
|
||||
const PaymentMethodsException(this.message);
|
||||
|
||||
final String message;
|
||||
|
||||
@override
|
||||
String toString() => message;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import '../entities/cart_item.dart';
|
||||
import '../entities/customer.dart';
|
||||
import '../entities/sale_completion.dart';
|
||||
import '../entities/sale_payment.dart';
|
||||
|
||||
abstract interface class SaleCheckoutRepository {
|
||||
Future<SaleCompletion> finalizeCashSale({
|
||||
required List<CartItem> items,
|
||||
required List<SalePayment> payments,
|
||||
Customer? customer,
|
||||
String? customerCpf,
|
||||
required String checkoutKey,
|
||||
});
|
||||
}
|
||||
|
||||
class SaleCheckoutException implements Exception {
|
||||
const SaleCheckoutException(this.code, this.message);
|
||||
|
||||
final String code;
|
||||
final String message;
|
||||
|
||||
@override
|
||||
String toString() => message;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import '../entities/sale_view_mode.dart';
|
||||
|
||||
abstract interface class SaleViewPreferenceRepository {
|
||||
Future<SaleViewMode> loadForUser(int userId);
|
||||
|
||||
Future<void> saveForUser(int userId, SaleViewMode mode);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import '../entities/historical_sale.dart';
|
||||
|
||||
abstract interface class SalesHistoryRepository {
|
||||
Future<List<HistoricalSale>> fetchSales();
|
||||
}
|
||||
|
||||
class SalesHistoryException implements Exception {
|
||||
const SalesHistoryException(this.message);
|
||||
|
||||
final String message;
|
||||
|
||||
@override
|
||||
String toString() => message;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import '../entities/app_settings.dart';
|
||||
|
||||
abstract interface class SettingsRepository {
|
||||
Future<AppSettings?> load();
|
||||
|
||||
Future<void> save(AppSettings settings);
|
||||
}
|
||||
Reference in new issue
Block a user