add barcode quick add
This commit is contained in:
parent
fcecb5aad5
commit
0e2ccb9e54
8 changed files with 58 additions and 23 deletions
22
lib/api.dart
22
lib/api.dart
|
@ -286,8 +286,6 @@ class API {
|
|||
var resp = jsonDecode(await postRequest("$instance/flow/$id/end",
|
||||
{"produced": produced?.map((x) => x.json()).toList()}));
|
||||
|
||||
print(resp);
|
||||
|
||||
if (produced != null) {
|
||||
var produced = resp["produced"] as Map<String, dynamic>;
|
||||
return produced.map(
|
||||
|
@ -385,6 +383,7 @@ class ItemVariant {
|
|||
late String name;
|
||||
int? min;
|
||||
int? expiry;
|
||||
List<int>? barcodes;
|
||||
|
||||
ItemVariant(Map<String, dynamic> json) {
|
||||
item = json["item"];
|
||||
|
@ -392,6 +391,9 @@ class ItemVariant {
|
|||
name = json["name"];
|
||||
min = json["min"];
|
||||
expiry = json["expiry"];
|
||||
barcodes = json["barcodes"] != null
|
||||
? (json["barcodes"] as List<dynamic>).cast<int>()
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -549,14 +551,14 @@ class FlowNote {
|
|||
}
|
||||
|
||||
class GlobalItemStat {
|
||||
late int item_count;
|
||||
late int total_transactions;
|
||||
late double total_price;
|
||||
late int itemCount;
|
||||
late int totalTransactions;
|
||||
late double totalPrice;
|
||||
|
||||
GlobalItemStat(Map<String, dynamic> json) {
|
||||
item_count = json["item_count"];
|
||||
total_transactions = json["total_transactions"];
|
||||
total_price = json["total_price"];
|
||||
itemCount = json["item_count"];
|
||||
totalTransactions = json["total_transactions"];
|
||||
totalPrice = json["total_price"];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -581,11 +583,11 @@ class FullItemVariantStat {
|
|||
}
|
||||
|
||||
class OriginStat {
|
||||
late double average_price;
|
||||
late double averagePrice;
|
||||
late int inventory;
|
||||
|
||||
OriginStat(Map<String, dynamic> json) {
|
||||
average_price = json["average_price"];
|
||||
averagePrice = json["average_price"];
|
||||
inventory = json["inventory"];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ class _ActiveFlowPageState extends State<ActiveFlowPage> {
|
|||
],
|
||||
),
|
||||
body: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 18.0),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 18.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
|
|
|
@ -94,7 +94,7 @@ class _CreateFlowPageState extends State<CreateFlowPage> {
|
|||
child: Text(API.API().getFlowInfo(widget.previousFlow!.kind).name),
|
||||
),
|
||||
),
|
||||
Card(child: Icon(Icons.arrow_right)),
|
||||
const Card(child: Icon(Icons.arrow_right)),
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
|
|
|
@ -7,11 +7,40 @@ import 'package:flutter/material.dart';
|
|||
class ItemsPage extends StatelessWidget {
|
||||
const ItemsPage({super.key});
|
||||
|
||||
_scanBarcodeSupply(BuildContext context) async {
|
||||
var code =
|
||||
int.parse(await scanQRCode(context, title: "Scan Barcode") ?? "0");
|
||||
|
||||
var items = API().getItems();
|
||||
for (var item in items) {
|
||||
for (var variant in item.variants.keys) {
|
||||
for (var barcode in item.variants[variant]!.barcodes ?? []) {
|
||||
if (code == barcode) {
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) => SupplyPage(
|
||||
item,
|
||||
() {},
|
||||
onlyVariants: [variant],
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Items"),
|
||||
// todo : add barcode scan
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
_scanBarcodeSupply(context);
|
||||
},
|
||||
child: const Icon(Icons.add_box))
|
||||
],
|
||||
),
|
||||
body: ListView(
|
||||
children: API().getItems().map((x) {
|
||||
|
|
|
@ -2,7 +2,6 @@ import 'package:cdb_ui/api.dart';
|
|||
import 'package:cdb_ui/pages/stats.dart';
|
||||
import 'package:cdb_ui/pages/transaction.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'supply.dart';
|
||||
|
||||
// todo : show est. time remaining until inventory gets empty (based on demand)
|
||||
|
@ -33,7 +32,7 @@ class _ItemViewState extends State<ItemView> {
|
|||
builder: (context) => ItemStatPage(widget.item),
|
||||
));
|
||||
},
|
||||
icon: Icon(Icons.bar_chart))
|
||||
icon: const Icon(Icons.bar_chart))
|
||||
],
|
||||
),
|
||||
body: Column(children: [
|
||||
|
|
|
@ -107,7 +107,7 @@ class _LocationViewState extends State<LocationView> {
|
|||
title: Text(widget.location.name),
|
||||
),
|
||||
body: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10.0),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Card(
|
||||
|
|
|
@ -24,7 +24,9 @@ class StatsPage extends StatelessWidget {
|
|||
// global origin / destinations
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text("Home"),),
|
||||
appBar: AppBar(
|
||||
title: const Text("Home"),
|
||||
),
|
||||
body: FutureBuilder(
|
||||
future: _fetchData(),
|
||||
builder: (context, snapshot) {
|
||||
|
@ -47,11 +49,11 @@ class StatsPage extends StatelessWidget {
|
|||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
IconText(Icons.data_object,
|
||||
"Items: ${globalStat.item_count}"),
|
||||
"Items: ${globalStat.itemCount}"),
|
||||
IconText(Icons.list_alt,
|
||||
"Inventory: ${globalStat.total_transactions}"),
|
||||
"Inventory: ${globalStat.totalTransactions}"),
|
||||
IconText(Icons.money,
|
||||
"Price: ${globalStat.total_price.toStringAsFixed(2)} €")
|
||||
"Price: ${globalStat.totalPrice.toStringAsFixed(2)} €")
|
||||
],
|
||||
),
|
||||
)),
|
||||
|
@ -110,7 +112,7 @@ class ItemStatPage extends StatelessWidget {
|
|||
return Column(children: [
|
||||
Text("Inventory: ${originStat.inventory}"),
|
||||
Text(
|
||||
"Average Price: ${originStat.average_price.toStringAsFixed(2)} €"),
|
||||
"Average Price: ${originStat.averagePrice.toStringAsFixed(2)} €"),
|
||||
]);
|
||||
}).toList()
|
||||
],
|
||||
|
|
|
@ -132,12 +132,15 @@ class _TransactionPageState extends State<TransactionPage> {
|
|||
children: [
|
||||
// todo : human names
|
||||
Text(
|
||||
"${API().getItem(transaction.item).name}",
|
||||
API().getItem(transaction.item).name,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold, fontSize: 28),
|
||||
),
|
||||
Text(
|
||||
"${API().getItem(transaction.item).variants[transaction.variant]!.name}",
|
||||
API()
|
||||
.getItem(transaction.item)
|
||||
.variants[transaction.variant]!
|
||||
.name,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20,
|
||||
|
@ -355,7 +358,7 @@ class TransactionSelectPage extends StatelessWidget {
|
|||
body: ListView(
|
||||
children: selectionList.isEmpty
|
||||
? [
|
||||
ListTile(
|
||||
const ListTile(
|
||||
title: Center(child: Text("No Transactions available")),
|
||||
)
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue