diff --git a/lib/common/apifunctions/find_organisations.dart b/lib/common/apifunctions/find_organisations.dart index 772f37a..aa66ef9 100644 --- a/lib/common/apifunctions/find_organisations.dart +++ b/lib/common/apifunctions/find_organisations.dart @@ -12,13 +12,12 @@ class Organisation { var town = ""; Organisation( - this.id, - this.name, - this.postcode, - this.streetName, - this.town, - ); - + this.id, + this.name, + this.postcode, + this.streetName, + this.town, + ); } class Organisations { diff --git a/lib/common/apifunctions/submit_receipt_api.dart b/lib/common/apifunctions/submit_receipt_api.dart index 96570b2..9dbb338 100644 --- a/lib/common/apifunctions/submit_receipt_api.dart +++ b/lib/common/apifunctions/submit_receipt_api.dart @@ -37,26 +37,25 @@ Future submitReceiptAPI( 'recurring': receipt.recurring, 'street_name': receipt.street, 'postcode': receipt.postcode, - 'town': receipt.town, 'session_key': preferences.get('LastToken'), }; // debugPrint('$body'); -// debugPrint(json.encode(body)); + debugPrint(json.encode(body)); final response = await http.post( url, body: json.encode(body), ); -// debugPrint(response.body); + debugPrint(response.body); if (response.statusCode == 200) { final responseJson = json.decode(response.body); -// print(responseJson[0]); + print(responseJson[0]); showDialogSingleButton( context, diff --git a/lib/pages/receipt_page_2.dart b/lib/pages/receipt_page_2.dart index 55ab2d2..f23be12 100644 --- a/lib/pages/receipt_page_2.dart +++ b/lib/pages/receipt_page_2.dart @@ -4,6 +4,7 @@ import 'package:intl/intl.dart'; import 'package:flutter/cupertino.dart'; import 'package:local_spend/common/apifunctions/find_organisations.dart'; import 'package:local_spend/common/widgets/organisations_dialog.dart'; +import 'package:local_spend/common/apifunctions/submit_receipt_api.dart'; class Transaction { DateTime date; @@ -40,6 +41,33 @@ class ReceiptPage2State extends State { "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 _sampleRecurringOptions = new List(7); List _sampleCategories = new List(4); @@ -367,6 +395,44 @@ class ReceiptPage2State extends State { ), ), // 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: [ + 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, + ), + ), + ), ], ), );