third commit

This commit is contained in:
2026-07-31 17:06:52 +05:30
parent d9886880cc
commit 9891a69a5f
32 changed files with 2083 additions and 557 deletions

View File

@@ -36,15 +36,19 @@ class CatalogueSyncException implements Exception {
/// The real implementation would issue an HTTP request; the contract is the
/// same, so only this class changes.
class RemoteCatalogueSource {
RemoteCatalogueSource() {
RemoteCatalogueSource({required this.isOffline}) {
LocalStore.registerSeed(
products: SeedData.products,
customers: SeedData.customers,
);
}
/// Flipped from Settings to exercise the offline path.
bool simulateOffline = false;
/// Reads the Settings switch on every call.
///
/// Deliberately a callback rather than a stored bool: a copied flag can fall
/// out of step with the switch, which makes the terminal behave as offline
/// while showing that it is not.
final bool Function() isOffline;
/// Streams progress so the import screen can show a real bar rather than an
/// indeterminate spinner.
@@ -62,10 +66,10 @@ class RemoteCatalogueSource {
for (final (progress, stage) in stages) {
await Future<void>.delayed(const Duration(milliseconds: 320));
if (simulateOffline) {
if (isOffline()) {
throw const CatalogueSyncException(
'No connection to the catalogue server. '
'Check the network and try again.',
'Simulate offline is ON in Settings, so the catalogue pull was '
'failed on purpose. Turn it off to import.',
);
}
@@ -83,9 +87,9 @@ class RemoteCatalogueSource {
/// Stands in for the back-office order intake API.
class RemoteOrderSink {
RemoteOrderSink();
RemoteOrderSink({required this.isOffline});
bool simulateOffline = false;
final bool Function() isOffline;
/// Uploads a batch of orders and returns the ids the server accepted.
///
@@ -96,10 +100,10 @@ class RemoteOrderSink {
Duration(milliseconds: 400 + orders.length * 60),
);
if (simulateOffline) {
if (isOffline()) {
throw const CatalogueSyncException(
'Could not reach the order server. Every bill is still stored on '
'this terminal and will upload on the next attempt.',
'Simulate offline is ON in Settings, so the upload was failed on '
'purpose. Every bill is still stored on this terminal.',
);
}

View File

@@ -22,6 +22,7 @@ class SeedData {
emoji: '🥛',
unit: UnitOfMeasure.litre,
gstRate: 0.05,
hsnCode: '0401',
brand: 'Amul',
),
Product(
@@ -35,6 +36,7 @@ class SeedData {
stock: 30,
emoji: '🧈',
gstRate: 0.12,
hsnCode: '0405',
brand: 'Amul',
),
Product(
@@ -48,6 +50,7 @@ class SeedData {
stock: 40,
emoji: '🥣',
gstRate: 0.05,
hsnCode: '0403',
brand: 'Nandini',
),
Product(
@@ -60,6 +63,7 @@ class SeedData {
stock: 20,
emoji: '🧀',
gstRate: 0.05,
hsnCode: '0406',
brand: 'Milky Mist',
),
Product(
@@ -73,6 +77,7 @@ class SeedData {
stock: 25,
emoji: '🧀',
gstRate: 0.12,
hsnCode: '0406',
brand: 'Britannia',
),
@@ -89,6 +94,7 @@ class SeedData {
emoji: '🍚',
unit: UnitOfMeasure.kilogram,
gstRate: 0.05,
hsnCode: '1006',
brand: 'India Gate',
),
Product(
@@ -103,6 +109,7 @@ class SeedData {
emoji: '🛢️',
unit: UnitOfMeasure.litre,
gstRate: 0.05,
hsnCode: '1507',
brand: 'Fortune',
),
Product(
@@ -115,6 +122,7 @@ class SeedData {
stock: 45,
emoji: '🫘',
gstRate: 0.05,
hsnCode: '0713',
brand: 'Tata Sampann',
),
Product(
@@ -129,6 +137,7 @@ class SeedData {
emoji: '🌾',
unit: UnitOfMeasure.kilogram,
gstRate: 0.05,
hsnCode: '1101',
brand: 'Aashirvaad',
),
Product(
@@ -142,6 +151,7 @@ class SeedData {
emoji: '🍬',
unit: UnitOfMeasure.kilogram,
gstRate: 0.05,
hsnCode: '1701',
),
Product(
id: 'p015',
@@ -153,6 +163,7 @@ class SeedData {
stock: 120,
emoji: '🍜',
gstRate: 0.12,
hsnCode: '1902',
brand: 'Nestlé',
),
Product(
@@ -166,6 +177,7 @@ class SeedData {
emoji: '🧂',
unit: UnitOfMeasure.kilogram,
gstRate: 0.05,
hsnCode: '2501',
brand: 'Tata',
),
@@ -181,6 +193,7 @@ class SeedData {
emoji: '🥤',
unit: UnitOfMeasure.millilitre,
gstRate: 0.28,
hsnCode: '2202',
brand: 'Coca-Cola',
),
Product(
@@ -193,6 +206,7 @@ class SeedData {
stock: 100,
emoji: '🥭',
gstRate: 0.12,
hsnCode: '2202',
brand: 'Parle Agro',
),
Product(
@@ -206,6 +220,7 @@ class SeedData {
emoji: '💧',
unit: UnitOfMeasure.litre,
gstRate: 0.18,
hsnCode: '2201',
brand: 'Bisleri',
),
Product(
@@ -218,6 +233,7 @@ class SeedData {
stock: 40,
emoji: '🔋',
gstRate: 0.28,
hsnCode: '2202',
brand: 'Red Bull',
),
Product(
@@ -231,6 +247,7 @@ class SeedData {
stock: 30,
emoji: '',
gstRate: 0.18,
hsnCode: '2101',
brand: 'Bru',
),
@@ -245,6 +262,7 @@ class SeedData {
stock: 90,
emoji: '🍪',
gstRate: 0.18,
hsnCode: '1905',
brand: 'Parle',
),
Product(
@@ -257,6 +275,7 @@ class SeedData {
stock: 110,
emoji: '🥔',
gstRate: 0.18,
hsnCode: '2005',
brand: "Lay's",
),
Product(
@@ -269,6 +288,7 @@ class SeedData {
stock: 75,
emoji: '🍫',
gstRate: 0.18,
hsnCode: '1806',
brand: 'Cadbury',
),
Product(
@@ -281,6 +301,7 @@ class SeedData {
stock: 85,
emoji: '🍪',
gstRate: 0.18,
hsnCode: '1905',
brand: 'Britannia',
),
Product(
@@ -293,6 +314,7 @@ class SeedData {
stock: 60,
emoji: '🥜',
gstRate: 0.12,
hsnCode: '2106',
brand: 'Haldiram',
),
@@ -308,6 +330,7 @@ class SeedData {
stock: 55,
emoji: '🪥',
gstRate: 0.18,
hsnCode: '3306',
brand: 'Colgate',
),
Product(
@@ -320,6 +343,7 @@ class SeedData {
stock: 70,
emoji: '🧼',
gstRate: 0.18,
hsnCode: '3401',
brand: 'Dove',
),
Product(
@@ -333,6 +357,7 @@ class SeedData {
stock: 25,
emoji: '🧴',
gstRate: 0.18,
hsnCode: '3305',
brand: 'P&G',
),
Product(
@@ -345,6 +370,7 @@ class SeedData {
stock: 30,
emoji: '🧴',
gstRate: 0.18,
hsnCode: '3304',
brand: 'Nivea',
),
@@ -361,6 +387,7 @@ class SeedData {
emoji: '🧺',
unit: UnitOfMeasure.kilogram,
gstRate: 0.18,
hsnCode: '3402',
brand: 'Surf Excel',
),
Product(
@@ -373,6 +400,7 @@ class SeedData {
stock: 90,
emoji: '🧽',
gstRate: 0.18,
hsnCode: '3401',
brand: 'Vim',
),
Product(
@@ -385,6 +413,7 @@ class SeedData {
stock: 40,
emoji: '🧴',
gstRate: 0.18,
hsnCode: '3402',
brand: 'Harpic',
),
Product(
@@ -397,6 +426,7 @@ class SeedData {
stock: 35,
emoji: '🗑️',
gstRate: 0.18,
hsnCode: '3923',
),
// ----------------------------------------------------------- Fruits
@@ -411,6 +441,7 @@ class SeedData {
emoji: '🍌',
unit: UnitOfMeasure.kilogram,
gstRate: 0,
hsnCode: '0803',
),
Product(
id: 'p061',
@@ -423,6 +454,7 @@ class SeedData {
emoji: '🍎',
unit: UnitOfMeasure.kilogram,
gstRate: 0,
hsnCode: '0808',
),
Product(
id: 'p062',
@@ -435,6 +467,7 @@ class SeedData {
emoji: '🥭',
unit: UnitOfMeasure.kilogram,
gstRate: 0,
hsnCode: '0804',
),
// ------------------------------------------------------- Vegetables
@@ -449,6 +482,7 @@ class SeedData {
emoji: '🍅',
unit: UnitOfMeasure.kilogram,
gstRate: 0,
hsnCode: '0702',
),
Product(
id: 'p071',
@@ -461,6 +495,7 @@ class SeedData {
emoji: '🧅',
unit: UnitOfMeasure.kilogram,
gstRate: 0,
hsnCode: '0703',
),
Product(
id: 'p072',
@@ -473,6 +508,7 @@ class SeedData {
emoji: '🥔',
unit: UnitOfMeasure.kilogram,
gstRate: 0,
hsnCode: '0701',
),
Product(
id: 'p073',
@@ -484,6 +520,7 @@ class SeedData {
stock: 8,
emoji: '🥕',
gstRate: 0,
hsnCode: '0706',
),
];