uploading receipt

This commit is contained in:
Felix 2019-08-12 11:37:59 +01:00
parent 4e67bfbbec
commit 405a037a15
3 changed files with 75 additions and 11 deletions

View file

@ -12,13 +12,12 @@ class Organisation {
var town = ""; var town = "";
Organisation( Organisation(
this.id, this.id,
this.name, this.name,
this.postcode, this.postcode,
this.streetName, this.streetName,
this.town, this.town,
); );
} }
class Organisations { class Organisations {

View file

@ -37,26 +37,25 @@ Future<LoginModel> submitReceiptAPI(
'recurring': receipt.recurring, 'recurring': receipt.recurring,
'street_name': receipt.street, 'street_name': receipt.street,
'postcode': receipt.postcode, 'postcode': receipt.postcode,
'town': receipt.town, 'town': receipt.town,
'session_key': preferences.get('LastToken'), 'session_key': preferences.get('LastToken'),
}; };
// debugPrint('$body'); // debugPrint('$body');
// debugPrint(json.encode(body)); debugPrint(json.encode(body));
final response = await http.post( final response = await http.post(
url, url,
body: json.encode(body), body: json.encode(body),
); );
// debugPrint(response.body); debugPrint(response.body);
if (response.statusCode == 200) { if (response.statusCode == 200) {
final responseJson = json.decode(response.body); final responseJson = json.decode(response.body);
// print(responseJson[0]); print(responseJson[0]);
showDialogSingleButton( showDialogSingleButton(
context, context,

View file

@ -4,6 +4,7 @@ import 'package:intl/intl.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:local_spend/common/apifunctions/find_organisations.dart'; import 'package:local_spend/common/apifunctions/find_organisations.dart';
import 'package:local_spend/common/widgets/organisations_dialog.dart'; import 'package:local_spend/common/widgets/organisations_dialog.dart';
import 'package:local_spend/common/apifunctions/submit_receipt_api.dart';
class Transaction { class Transaction {
DateTime date; DateTime date;
@ -40,6 +41,33 @@ class ReceiptPage2State extends State<ReceiptPage2> {
"Uncategorised", "Uncategorised",
); );
_submitReceipt(Transaction transaction) {
DateTime dt = new DateTime.now();
// sample transaction:
// {
// "transaction_type":1,
// "transaction_value":33,
// "purchase_time":"2019-08-12T11:06:00.000+01:00",
// "organisation_id":59661,
// "essential":false,
// "session_key":"C438432A-B775-11E9-8EE8-147589E69626"
// }
Receipt receipt = new Receipt();
receipt.organisationName = transaction.organisation.name;
receipt.street = transaction.organisation.streetName;
receipt.postcode = transaction.organisation.postcode;
receipt.town = transaction.organisation.town;
receipt.recurring = transaction.recurring;
receipt.category = transaction.category;
receipt.amount = transaction.amount.text.toString();
receipt.time = DateFormat("yyyy-MM-dd'T'hh:mm':00.000+01:00'").format(transaction.date).toString();
receipt.essential = transaction.isEssential.toString();
// receipt.time = dt.format(transaction.date);
submitReceiptAPI(context, receipt);
}
List<String> _sampleRecurringOptions = new List<String>(7); List<String> _sampleRecurringOptions = new List<String>(7);
List<String> _sampleCategories = new List<String>(4); List<String> _sampleCategories = new List<String>(4);
@ -367,6 +395,44 @@ class ReceiptPage2State extends State<ReceiptPage2> {
), ),
), // Amount picker ), // Amount picker
Padding(
padding: EdgeInsets.fromLTRB(20.0, 20.0, 20.0, 0.0),
child: Container(
height: 65.0,
child: RaisedButton(
onPressed: () {
try {
_submitReceipt(transaction);
}
catch (_) {
showDialog(
context: context,
builder: (BuildContext context) {
// return object of type Dialog
return AlertDialog(
title: new Text("Invalid data"),
content: new Text(
"We couldn't process your request because some of the data entered is invalid."),
actions: <Widget>[
new FlatButton(
child: new Text("OK"),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
},
child: Text("GO",
style:
TextStyle(color: Colors.white, fontSize: 22.0)),
color: Colors.blue,
),
),
),
], ],
), ),
); );