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