Skip to content

Commit

Permalink
Start stock entry
Browse files Browse the repository at this point in the history
  • Loading branch information
mbayopanda committed Jul 9, 2022
1 parent f33b071 commit 4a68aa2
Show file tree
Hide file tree
Showing 8 changed files with 331 additions and 101 deletions.
6 changes: 6 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ PODS:
- Flutter
- ReachabilitySwift
- Flutter (1.0.0)
- flutter_keyboard_visibility (0.0.1):
- Flutter
- FMDB (2.7.5):
- FMDB/standard (= 2.7.5)
- FMDB/standard (2.7.5)
Expand All @@ -18,6 +20,7 @@ PODS:
DEPENDENCIES:
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
- Flutter (from `Flutter`)
- flutter_keyboard_visibility (from `.symlinks/plugins/flutter_keyboard_visibility/ios`)
- network_info_plus (from `.symlinks/plugins/network_info_plus/ios`)
- shared_preferences_ios (from `.symlinks/plugins/shared_preferences_ios/ios`)
- sqflite (from `.symlinks/plugins/sqflite/ios`)
Expand All @@ -32,6 +35,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/connectivity_plus/ios"
Flutter:
:path: Flutter
flutter_keyboard_visibility:
:path: ".symlinks/plugins/flutter_keyboard_visibility/ios"
network_info_plus:
:path: ".symlinks/plugins/network_info_plus/ios"
shared_preferences_ios:
Expand All @@ -42,6 +47,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
connectivity_plus: 413a8857dd5d9f1c399a39130850d02fe0feaf7e
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
network_info_plus: b78876159360f5580608c2cea620d6ceffabd0ad
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
Expand Down
88 changes: 88 additions & 0 deletions lib/models/lot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,94 @@ class Lot {
return collection;
}

// List of unique inventories
static Future<List<Lot>> inventories(
dynamic database, String depot_uuid) async {
// Get a reference to the database.
final db = await database;

// Query the table for all The lot.
final List<Map<String, dynamic>> maps = await db.rawQuery(
'SELECT * FROM lot WHERE lot.depot_uuid = ? GROUP BY lot.inventory_uuid;',
[depot_uuid]);

// Convert the List<Map<String, dynamic> into a List<Lot>.
List<Lot> collection = List.generate(maps.length, (i) {
return Lot(
uuid: maps[i]['uuid'],
label: maps[i]['label'],
lot_description: maps[i]['lot_description'],
code: maps[i]['code'],
inventory_uuid: maps[i]['inventory_uuid'],
text: maps[i]['text'],
unit_type: maps[i]['unit_type'],
group_name: maps[i]['group_name'],
depot_text: maps[i]['depot_text'],
depot_uuid: maps[i]['depot_uuid'],
is_asset: maps[i]['is_asset'],
barcode: maps[i]['barcode'],
serial_number: maps[i]['serial_number'],
reference_number: maps[i]['reference_number'],
manufacturer_brand: maps[i]['manufacturer_brand'],
manufacturer_model: maps[i]['manufacturer_model'],
unit_cost: maps[i]['unit_cost'],
quantity: maps[i]['quantity'],
avg_consumption: maps[i]['avg_consumption'],
exhausted: parseBool(maps[i]['exhausted']),
expired: parseBool(maps[i]['expired']),
near_expiration: parseBool(maps[i]['near_expiration']),
expiration_date: parseDate(maps[i]['expiration_date']),
entry_date: parseDate(maps[i]['entry_date']),
);
});

return collection;
}

// List of unique inventories
static Future<List<Lot>> inventoryLots(
dynamic database, String depot_uuid, String inventoryUuid) async {
// Get a reference to the database.
final db = await database;

// Query the table for all The lot.
final List<Map<String, dynamic>> maps = await db.rawQuery(
'SELECT * FROM lot WHERE depot_uuid = ? AND inventory_uuid = ? GROUP BY uuid;',
[depot_uuid, inventoryUuid]);

// Convert the List<Map<String, dynamic> into a List<Lot>.
List<Lot> collection = List.generate(maps.length, (i) {
return Lot(
uuid: maps[i]['uuid'],
label: maps[i]['label'],
lot_description: maps[i]['lot_description'],
code: maps[i]['code'],
inventory_uuid: maps[i]['inventory_uuid'],
text: maps[i]['text'],
unit_type: maps[i]['unit_type'],
group_name: maps[i]['group_name'],
depot_text: maps[i]['depot_text'],
depot_uuid: maps[i]['depot_uuid'],
is_asset: maps[i]['is_asset'],
barcode: maps[i]['barcode'],
serial_number: maps[i]['serial_number'],
reference_number: maps[i]['reference_number'],
manufacturer_brand: maps[i]['manufacturer_brand'],
manufacturer_model: maps[i]['manufacturer_model'],
unit_cost: maps[i]['unit_cost'],
quantity: maps[i]['quantity'],
avg_consumption: maps[i]['avg_consumption'],
exhausted: parseBool(maps[i]['exhausted']),
expired: parseBool(maps[i]['expired']),
near_expiration: parseBool(maps[i]['near_expiration']),
expiration_date: parseDate(maps[i]['expiration_date']),
entry_date: parseDate(maps[i]['entry_date']),
);
});

return collection;
}

// Define a function that inserts lot into the database
static Future<void> insertLot(dynamic database, Lot lot) async {
final db = await database;
Expand Down
17 changes: 8 additions & 9 deletions lib/providers/entry_movement.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,24 @@ class EntryMovement extends ChangeNotifier {
}

void setLot(int index, String field, dynamic value) {
if (lots[index] != null && lots[index][field] != null) {
if (lots[index] == null) {
lots[index] = {};
lots[index][field] = value;
} else {
lots[index][field] = value;
notifyListeners();
}
}

void addLot() {
lots.add({'inventory_uuid': '', 'lot_uuid': '', 'quantity': 0});
notifyListeners();
dynamic getLotValue(int index, String field) {
return lots[index] != null && lots[index][field] != null
? lots[index][field]
: '';
}

void createLots() {
lots = List.filled(totalItems, null, growable: false);
}

int lastIndex() {
return lots.length - 1;
}

void reset() {
documentReference = '';
date = DateTime.now();
Expand Down
3 changes: 3 additions & 0 deletions lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class _HomePageState extends State<HomePage> {

Future fetchLots() async {
try {
/**
* Include empty lots for having lots which are sent by not yet received
*/
const lotDataUrl = '/stock/lots/depots?includeEmptyLot=1';
List lotsRaw = await connexion.api(lotDataUrl);

Expand Down
Loading

0 comments on commit 4a68aa2

Please sign in to comment.