registerSales method
Implementation
Future<void> registerSales({
required String productName,
required int taxCode,
required double price,
double? quantity,
DiscountType? discountType,
double? discountValue,
required int department,
String? unit,
}) async {
assert(productName.isNotEmpty, 'Product name must not be empty');
assert(
taxCode >= 1 && taxCode <= 8,
'taxCode must be in range 1..8 (vat group A-H)',
);
assert(price > 0, 'Price must be greater than 0');
assert(
quantity == null || quantity > 0,
'Quantity must be greater than 0 or null',
);
assert(
discountValue == null || discountValue >= 0,
'discountValue must be greater than or equal to 0',
);
assert(
department >= 0 && department <= 99,
'department must be in range 0..99. 0 is for no department',
);
assert(
unit == null || unit.length <= 6 && unit.isNotEmpty,
'unit must be 6 characters or less and not empty',
);
final message = await execute(
Commands.registrationOfSale.code,
data: [
productName,
taxCode,
price,
quantity?.cleanDouble(),
discountType?.index,
discountValue?.cleanDouble(),
department,
if (unit != null) unit,
].toCommand(),
);
final [$e, ...rest] = message.data.response;
final error = int.tryParse($e) ?? 0;
if (error != 0) {
throw FiscalCodeException('Error register sales', error);
}
}