From 7b517163d2d3990aef5dbfa25787453540c0ece3 Mon Sep 17 00:00:00 2001 From: lahirulakruwan Date: Mon, 5 Aug 2024 18:08:34 +0530 Subject: [PATCH 1/7] consumable dashboard changes added --- campus/bffs/asset/api/Dependencies.toml | 2 +- campus/bffs/asset/api/client.bal | 7 + campus/bffs/asset/api/service.bal | 24 + campus/bffs/asset/api/types.bal | 19 + .../bffs/asset/graphql_client/asset.graphql | 17 + .../graphql_client_cg_src/client.bal | 6 + .../graphql_client_cg_src/types.bal | 21 +- .../bffs/asset/graphql_client/schema.graphql | 5 +- campus/bffs/asset/graphql_client/schema.json | 81 ++- .../lib/avinya/asset_admin/lib/app.dart | 4 +- .../lib/data/stock_repenishment.dart | 22 + .../screens/consumable_dashboard_screen.dart | 4 +- .../asset_admin/lib/screens/scaffold.dart | 47 ++ .../lib/widgets/consumable_bar_chart.dart | 460 ++++++++++++++++++ .../lib/widgets/consumable_dashboard.dart | 37 ++ .../lib/widgets/latest_consumable_data.dart | 241 +++++++++ .../lib/avinya/asset_admin/pubspec.yaml | 1 + campus/frontend/lib/pages/home.dart | 2 +- 18 files changed, 984 insertions(+), 16 deletions(-) create mode 100644 campus/frontend/lib/avinya/asset_admin/lib/widgets/consumable_bar_chart.dart create mode 100644 campus/frontend/lib/avinya/asset_admin/lib/widgets/consumable_dashboard.dart create mode 100644 campus/frontend/lib/avinya/asset_admin/lib/widgets/latest_consumable_data.dart diff --git a/campus/bffs/asset/api/Dependencies.toml b/campus/bffs/asset/api/Dependencies.toml index ba28474..ec2c1d6 100644 --- a/campus/bffs/asset/api/Dependencies.toml +++ b/campus/bffs/asset/api/Dependencies.toml @@ -10,7 +10,7 @@ distribution-version = "2201.5.0" [[package]] org = "avinyafoundation" name = "asset_bff" -version = "0.1.0" +version = "1.1.0" dependencies = [ {org = "ballerina", name = "graphql"}, {org = "ballerina", name = "http"}, diff --git a/campus/bffs/asset/api/client.bal b/campus/bffs/asset/api/client.bal index db9d085..9593653 100644 --- a/campus/bffs/asset/api/client.bal +++ b/campus/bffs/asset/api/client.bal @@ -372,4 +372,11 @@ public isolated client class GraphqlClient { json graphqlResponse = check self.graphqlClient->executeWithType(query, variables); return check performDataBinding(graphqlResponse, GetConsumableMonthlyReportResponse); } + + remote isolated function getConsumableYearlyReport(int consumable_id, int year, int organization_id) returns GetConsumableYearlyReportResponse|graphql:ClientError { + string query = string `query getConsumableYearlyReport($organization_id:Int!,$consumable_id:Int!,$year:Int!) {consumable_yearly_report(organization_id:$organization_id,consumable_id:$consumable_id,year:$year) {consumable {id name} month_name quantity_in quantity_out resource_property {id property value}}}`; + map variables = {"consumable_id": consumable_id, "year": year, "organization_id": organization_id}; + json graphqlResponse = check self.graphqlClient->executeWithType(query, variables); + return check performDataBinding(graphqlResponse, GetConsumableYearlyReportResponse); + } } diff --git a/campus/bffs/asset/api/service.bal b/campus/bffs/asset/api/service.bal index 7a4372f..c5346c7 100644 --- a/campus/bffs/asset/api/service.bal +++ b/campus/bffs/asset/api/service.bal @@ -855,4 +855,28 @@ service / on new http:Listener(9094) { ":: Detail: " + getConsumableMonthlyReportResponse.detail().toString()); } } + + resource function get consumable_yearly_report/[int organization_id]/[int consumable_id]/[int year]() returns Inventory[]|error { + GetConsumableYearlyReportResponse|graphql:ClientError getConsumableYearlyReportResponse = globalDataClient->getConsumableYearlyReport(consumable_id,year,organization_id); + if (getConsumableYearlyReportResponse is GetConsumableYearlyReportResponse) { + Inventory[] yearly_summary_consumable_datas = []; + foreach var yearly_summary_consumable_data in getConsumableYearlyReportResponse.consumable_yearly_report { + Inventory|error yearly_summary_consumable_data_record = yearly_summary_consumable_data.cloneWithType(Inventory); + if (yearly_summary_consumable_data_record is Inventory) { + yearly_summary_consumable_datas.push(yearly_summary_consumable_data_record); + } else { + log:printError("Error while processing Application record received", yearly_summary_consumable_data_record); + return error("Error while processing Application record received: " + yearly_summary_consumable_data_record.message() + + ":: Detail: " + yearly_summary_consumable_data_record.detail().toString()); + } + } + + return yearly_summary_consumable_datas; + + } else { + log:printError("Error while getting application", getConsumableYearlyReportResponse); + return error("Error while getting application: " + getConsumableYearlyReportResponse.message() + + ":: Detail: " + getConsumableYearlyReportResponse.detail().toString()); + } + } } diff --git a/campus/bffs/asset/api/types.bal b/campus/bffs/asset/api/types.bal index 911a11e..568085c 100644 --- a/campus/bffs/asset/api/types.bal +++ b/campus/bffs/asset/api/types.bal @@ -234,6 +234,7 @@ public type EvaluationMetadata record { // int? person_id?; // }; public type Inventory record { + string? month_name?; int? consumable_id?; anydata? quantity?; string? created?; @@ -1149,4 +1150,22 @@ public type GetConsumableMonthlyReportResponse record {| string? value; |}? resource_property; |}[] consumable_monthly_report; +|}; + +public type GetConsumableYearlyReportResponse record {| + map __extensions?; + record {| + record {| + int? id; + string? name; + |}? consumable; + string? month_name; + anydata? quantity_in; + anydata? quantity_out; + record {| + int? id; + string? property; + string? value; + |}? resource_property; + |}[] consumable_yearly_report; |}; \ No newline at end of file diff --git a/campus/bffs/asset/graphql_client/asset.graphql b/campus/bffs/asset/graphql_client/asset.graphql index 0b09ec8..c243b52 100644 --- a/campus/bffs/asset/graphql_client/asset.graphql +++ b/campus/bffs/asset/graphql_client/asset.graphql @@ -708,4 +708,21 @@ query getConsumableMonthlyReport($organization_id: Int!,$year: Int!,$month: Int! value } } +} + +query getConsumableYearlyReport($organization_id: Int!,$consumable_id: Int!,$year: Int!) { + consumable_yearly_report(organization_id: $organization_id,consumable_id: $consumable_id,year: $year) { + consumable{ + id + name + } + month_name + quantity_in + quantity_out + resource_property{ + id + property + value + } + } } \ No newline at end of file diff --git a/campus/bffs/asset/graphql_client/graphql_client_cg_src/client.bal b/campus/bffs/asset/graphql_client/graphql_client_cg_src/client.bal index 5c5b63f..2611265 100644 --- a/campus/bffs/asset/graphql_client/graphql_client_cg_src/client.bal +++ b/campus/bffs/asset/graphql_client/graphql_client_cg_src/client.bal @@ -249,4 +249,10 @@ public isolated client class GraphqlClient { json graphqlResponse = check self.graphqlClient->executeWithType(query, variables); return check performDataBinding(graphqlResponse, GetConsumableMonthlyReportResponse); } + remote isolated function getConsumableYearlyReport(int consumable_id, int year, int organization_id) returns GetConsumableYearlyReportResponse|graphql:ClientError { + string query = string `query getConsumableYearlyReport($organization_id:Int!,$consumable_id:Int!,$year:Int!) {consumable_yearly_report(organization_id:$organization_id,consumable_id:$consumable_id,year:$year) {consumable {id name} month_name quantity_in quantity_out resource_property {id property value}}}`; + map variables = {"consumable_id": consumable_id, "year": year, "organization_id": organization_id}; + json graphqlResponse = check self.graphqlClient->executeWithType(query, variables); + return check performDataBinding(graphqlResponse, GetConsumableYearlyReportResponse); + } } diff --git a/campus/bffs/asset/graphql_client/graphql_client_cg_src/types.bal b/campus/bffs/asset/graphql_client/graphql_client_cg_src/types.bal index 2ddd270..3810d55 100644 --- a/campus/bffs/asset/graphql_client/graphql_client_cg_src/types.bal +++ b/campus/bffs/asset/graphql_client/graphql_client_cg_src/types.bal @@ -238,6 +238,7 @@ public type EvaluationMetadata record { }; public type Inventory record { + string? month_name?; int? consumable_id?; anydata? quantity?; string? created?; @@ -557,7 +558,7 @@ public type GetConsumablesResponse record {| string? manufacturer; string? model; string? serial_number; - |}[] consumables; + |}[]? consumables; |}; public type AddConsumableResponse record {| @@ -1156,3 +1157,21 @@ public type GetConsumableMonthlyReportResponse record {| |}? resource_property; |}[]? consumable_monthly_report; |}; + +public type GetConsumableYearlyReportResponse record {| + map __extensions?; + record {| + record {| + int? id; + string? name; + |}? consumable; + string? month_name; + anydata? quantity_in; + anydata? quantity_out; + record {| + int? id; + string? property; + string? value; + |}? resource_property; + |}[]? consumable_yearly_report; +|}; diff --git a/campus/bffs/asset/graphql_client/schema.graphql b/campus/bffs/asset/graphql_client/schema.graphql index cd95500..bb27c3a 100644 --- a/campus/bffs/asset/graphql_client/schema.graphql +++ b/campus/bffs/asset/graphql_client/schema.graphql @@ -547,6 +547,7 @@ input Inventory { asset_id: Int consumable_id: Int name: String + month_name: String description: String manufacturer: String organization_id: Int @@ -576,6 +577,7 @@ type InventoryData { prev_quantity: Decimal resource_property: ResourcePropertyData name: String + month_name: String description: String manufacturer: String created: String @@ -872,7 +874,7 @@ type Query { suppliers: [SupplierData!]! consumable(id: Int!): ConsumableData consumableByUpdate(updated: String, avinya_type_id: Int): [ConsumableData!] - consumables: [ConsumableData!]! + consumables: [ConsumableData!] activeActivityInstance: [ActivityInstanceData!]! resource_property(id: Int!): ResourcePropertyData resource_properties: [ResourcePropertyData!]! @@ -899,6 +901,7 @@ type Query { inventory_data_by_organization(organization_id: Int, date: String = ""): [InventoryData!] consumable_weekly_report(organization_id: Int, from_date: String = "", to_date: String = ""): [InventoryData!] consumable_monthly_report(organization_id: Int, year: Int, month: Int): [InventoryData!] + consumable_yearly_report(organization_id: Int, consumable_id: Int, year: Int): [InventoryData!] } input ResourceAllocation { diff --git a/campus/bffs/asset/graphql_client/schema.json b/campus/bffs/asset/graphql_client/schema.json index 78f3d62..220c6cf 100644 --- a/campus/bffs/asset/graphql_client/schema.json +++ b/campus/bffs/asset/graphql_client/schema.json @@ -1993,19 +1993,15 @@ "name": "consumables", "args": [], "type": { - "kind": "NON_NULL", + "kind": "LIST", "name": null, "ofType": { - "kind": "LIST", + "kind": "NON_NULL", "name": null, "ofType": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "OBJECT", - "name": "ConsumableData", - "ofType": null - } + "kind": "OBJECT", + "name": "ConsumableData", + "ofType": null } } }, @@ -2911,6 +2907,53 @@ }, "isDeprecated": false, "deprecationReason": null + }, + { + "name": "consumable_yearly_report", + "args": [ + { + "name": "organization_id", + "type": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + }, + "defaultValue": null + }, + { + "name": "consumable_id", + "type": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + }, + "defaultValue": null + }, + { + "name": "year", + "type": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + }, + "defaultValue": null + } + ], + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "InventoryData", + "ofType": null + } + } + }, + "isDeprecated": false, + "deprecationReason": null } ], "inputFields": null, @@ -6189,6 +6232,17 @@ "isDeprecated": false, "deprecationReason": null }, + { + "name": "month_name", + "args": [], + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, { "name": "description", "args": [], @@ -8970,6 +9024,15 @@ }, "defaultValue": null }, + { + "name": "month_name", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "defaultValue": null + }, { "name": "description", "type": { diff --git a/campus/frontend/lib/avinya/asset_admin/lib/app.dart b/campus/frontend/lib/avinya/asset_admin/lib/app.dart index b98fe80..76756fd 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/app.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/app.dart @@ -51,7 +51,7 @@ class _AssetAdminSystemState extends State { ], guard: _guard, // initialRoute: '/signin', - initialRoute: '/asset_dashboard', + initialRoute: '/consumable_dashboard', ); _routeState = RouteState(_routeParser); @@ -172,7 +172,7 @@ class _AssetAdminSystemState extends State { bool signedIn = await _auth.getSignedIn(); if (!signedIn) { // _routeState.go('/signin'); - _routeState.go('/asset_dashboard'); + _routeState.go('/consumable_dashboard'); } } diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/stock_repenishment.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/stock_repenishment.dart index a486620..218fd3a 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/stock_repenishment.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/stock_repenishment.dart @@ -235,3 +235,25 @@ Future> getConsumableWeeklyReport( throw Exception('Failed to get Consumable Weekly Summary Data'); } } + +Future> getConsumableYearlyReport( + int organization_id, int consumable_id, int year) async { + final response = await http.get( + Uri.parse( + '${AppConfig.campusAssetsBffApiUrl}/consumable_yearly_report/$organization_id/$consumable_id/$year'), + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + 'accept': 'application/json', + 'Authorization': 'Bearer ${AppConfig.campusBffApiKey}', + }, + ); + if (response.statusCode > 199 && response.statusCode < 300) { + var resultsJson = json.decode(response.body).cast>(); + List consumableYearlySummaryData = await resultsJson + .map((json) => StockReplenishment.fromJson(json)) + .toList(); + return consumableYearlySummaryData; + } else { + throw Exception('Failed to get Consumable Yearly Summary Data'); + } +} diff --git a/campus/frontend/lib/avinya/asset_admin/lib/screens/consumable_dashboard_screen.dart b/campus/frontend/lib/avinya/asset_admin/lib/screens/consumable_dashboard_screen.dart index 0dddc88..f6e19ad 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/screens/consumable_dashboard_screen.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/screens/consumable_dashboard_screen.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; +import '../widgets/consumable_dashboard.dart'; + class ConsumableDashboardScreen extends StatefulWidget { const ConsumableDashboardScreen({super.key}); @@ -11,7 +13,7 @@ class _ConsumableDashboardScreenState extends State { @override Widget build(BuildContext context) { return const Center( - child: Text('Consumable Dashboard Screen'), + child: ConsumableDashboard(), ); } } \ No newline at end of file diff --git a/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold.dart b/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold.dart index 2c89e2e..0f562fa 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold.dart @@ -15,6 +15,7 @@ class SMSScaffold extends StatefulWidget { class _SMSScaffoldState extends State { bool isAssetDashboardSectionHovered = false; + bool isConsumableDashboardSectionHovered = false; bool isAssetSectionHovered = false; bool isAssetReportSectionHovered = false; bool isConsumableSectionHovered = false; @@ -207,6 +208,52 @@ class _SMSScaffoldState extends State { //), ), ), + MouseRegion( + onEnter: (_) { + setState(() { + isConsumableDashboardSectionHovered = true; + }); + }, + onExit: (_) { + setState(() { + isConsumableDashboardSectionHovered = false; + }); + }, + child: Container( + decoration: BoxDecoration( + color: isConsumableDashboardSectionHovered + ? Colors.white.withOpacity(0.3) + : null, + borderRadius: BorderRadius.circular(15.0), + ), + margin: EdgeInsets.all(8.0), + child: Material( + type: MaterialType.transparency, + child: Container( + child: ListTile( + leading: Icon(Icons.space_dashboard_rounded, + color: Colors.white, size: 20.0), + title: Container( + margin: EdgeInsets.only(left: 12.0), + transform: Matrix4.translationValues(-25, 0.0, 0.0), + child: Text( + "Consumable Dashboard", + style: TextStyle( + color: Colors.white, + fontSize: 12, + ), + ), + ), + onTap: () { + Navigator.pop(context); // Close the drawer + routeState.go('/consumable_dashboard'); + }, + ), + ), + ), + // ), + ), + ), MouseRegion( onEnter: (_) { setState(() { diff --git a/campus/frontend/lib/avinya/asset_admin/lib/widgets/consumable_bar_chart.dart b/campus/frontend/lib/avinya/asset_admin/lib/widgets/consumable_bar_chart.dart new file mode 100644 index 0000000..89823c9 --- /dev/null +++ b/campus/frontend/lib/avinya/asset_admin/lib/widgets/consumable_bar_chart.dart @@ -0,0 +1,460 @@ +import 'dart:ui'; + +import 'package:fl_chart/fl_chart.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; +import 'package:flutter_spinkit/flutter_spinkit.dart'; +import 'package:gallery/avinya/asset_admin/lib/data/consumable.dart'; +import 'package:gallery/avinya/asset_admin/lib/data/stock_repenishment.dart'; +import 'package:gallery/constants.dart'; +import 'package:gallery/data/campus_apps_portal.dart'; +import 'package:intl/intl.dart'; + +class ConsumableBarChart extends StatefulWidget { + const ConsumableBarChart({super.key}); + + @override + State createState() => _ConsumableBarChartState(); +} + +class _ConsumableBarChartState extends State { + Consumable? _selectedConsumableValue; + late Future> _fetchConsumableData; + DateTime _selectedYear = DateTime.now(); + bool _isFetching = false; + String? _selectedConsumableUnitValue; + + List _fetchedConsumableYearlySummaryData = []; + List _consumableItemQuantityInForYear = []; + List _consumableItemQuantityOutForYear = []; + + @override + void initState() { + super.initState(); + _fetchConsumableData = _loadConsumableData(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + } + + Future> _loadConsumableData() async { + return await fetchConsumables(); + } + + void _showPicker(BuildContext context) { + showDialog( + context: context, + builder: ((context) { + return AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(10.0))), + title: Row( + children: [ + Icon(Icons.calendar_today), + SizedBox(width: 8), + Text('Select a Year'), + ], + ), + content: Container( + width: 300, + height: 300, + child: YearPicker( + firstDate: DateTime(DateTime.now().year - 100), + lastDate: DateTime(DateTime.now().year + 120), + initialDate: DateTime.now(), + selectedDate: _selectedYear, + onChanged: (DateTime dateTime) async { + Navigator.pop(context); + setState(() { + _selectedYear = dateTime; + _isFetching = true; + }); + + if (_selectedYear != null && + _selectedConsumableValue != null) { + int? parentOrgId = campusAppsPortalInstance + .getUserPerson() + .organization! + .id; + + _fetchedConsumableYearlySummaryData = + await getConsumableYearlyReport(parentOrgId!, + _selectedConsumableValue!.id!, _selectedYear.year); + + _selectedConsumableUnitValue = + _fetchedConsumableYearlySummaryData + .first.resource_property!.value; + + _consumableItemQuantityInForYear = + _fetchedConsumableYearlySummaryData + .map((consumableMonthObject) => + consumableMonthObject.quantity_in!) + .toList(); + _consumableItemQuantityOutForYear = + _fetchedConsumableYearlySummaryData + .map((consumableMonthObject) => + consumableMonthObject.quantity_out!) + .toList(); + + setState(() { + _fetchedConsumableYearlySummaryData; + _consumableItemQuantityInForYear; + _consumableItemQuantityOutForYear; + _isFetching = false; + }); + } + }, + ), + ), + ); + })); + } + + List _getBarGroups() { + return List.generate(12, (i) { + return BarChartGroupData( + barsSpace: 5, + x: i, + barRods: [ + BarChartRodData( + borderSide: BorderSide(width: 2.0), + borderRadius: BorderRadius.zero, + width: 20, + toY: _getQuantityInValue(i), + color: Colors.green, + backDrawRodData: BackgroundBarChartRodData( + show: true, + color: Colors.green.withOpacity(0.2), + ), + rodStackItems: [ + BarChartRodStackItem(0, _getQuantityInValue(i), Colors.green), + ], + ), + BarChartRodData( + borderSide: BorderSide(width: 2.0), + borderRadius: BorderRadius.zero, + width: 20, + toY: _getQuantityOutValue(i), + color: Colors.red, + backDrawRodData: BackgroundBarChartRodData( + show: true, + color: Colors.red.withOpacity(0.2), + ), + rodStackItems: [ + BarChartRodStackItem(0, _getQuantityOutValue(i), Colors.red), + ], + ), + ], + ); + }); + } + + double _getQuantityInValue(int month) { + return _consumableItemQuantityInForYear[month]; + } + + double _getQuantityOutValue(int month) { + return _consumableItemQuantityOutForYear[month]; + } + + Widget getTitles(double value, TitleMeta meta) { + const style = TextStyle( + color: Colors.black, + fontWeight: FontWeight.bold, + fontSize: 14, + ); + Widget text; + switch (value.toInt()) { + case 0: + text = Center(child: const Text('Jan', style: style)); + break; + case 1: + text = Center(child: const Text('Feb', style: style)); + break; + case 2: + text = Center(child: const Text('Mar', style: style)); + break; + case 3: + text = Center(child: const Text('Apr', style: style)); + break; + case 4: + text = Center(child: const Text('May', style: style)); + break; + case 5: + text = Center(child: const Text('Jun', style: style)); + break; + case 6: + text = Center(child: const Text('Jul', style: style)); + break; + case 7: + text = Center(child: const Text('Aug', style: style)); + break; + case 8: + text = Center(child: const Text('Sep', style: style)); + break; + case 9: + text = Center(child: const Text('Oct', style: style)); + break; + case 10: + text = Center(child: const Text('Nov', style: style)); + break; + default: + text = Center(child: const Text('Dec', style: style)); + break; + } + return SideTitleWidget( + axisSide: meta.axisSide, + space: 0, + child: text, + ); + } + + @override + Widget build(BuildContext context) { + return AspectRatio( + aspectRatio: 16 / 9, + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Center( + child: Text( + 'Consumable Yearly Report', + style: TextStyle( + fontSize: 24, + fontWeight: FontWeight.bold, + color: Colors.purple, // Matches yellow[700] + ), + ), + ), + Flexible( + flex: 2, + child: Row( + children: [ + Text( + 'Select a Consumable :', + style: TextStyle( + fontStyle: FontStyle.normal, + fontWeight: FontWeight.bold), + ), + FutureBuilder>( + future: _fetchConsumableData, + builder: (context, snapshot) { + if (snapshot.connectionState == + ConnectionState.waiting) { + return Container( + margin: EdgeInsets.only(top: 10), + child: SpinKitCircle( + color: (Colors.yellow[700]), + size: 70, + ), + ); + } else if (snapshot.hasError) { + return const Center( + child: Text('Something went wrong...'), + ); + } else if (!snapshot.hasData) { + return const Center( + child: Text('No consumable data found'), + ); + } + final consumableData = snapshot.data!; + return DropdownButton( + value: _selectedConsumableValue, + items: consumableData.map((Consumable consumable) { + return DropdownMenuItem( + value: consumable, + child: Text(consumable.name! ?? '')); + }).toList(), + onChanged: (Consumable? newValue) async { + if (newValue == null) { + return; + } + + int consumableId = newValue.id!; + + int? parentOrgId = campusAppsPortalInstance + .getUserPerson() + .organization! + .id; + + _fetchedConsumableYearlySummaryData = + await getConsumableYearlyReport(parentOrgId!, + consumableId, _selectedYear.year); + + _selectedConsumableUnitValue = + _fetchedConsumableYearlySummaryData + .first.resource_property!.value; + + _consumableItemQuantityInForYear = + _fetchedConsumableYearlySummaryData + .map((consumableMonthObject) => + consumableMonthObject.quantity_in!) + .toList(); + _consumableItemQuantityOutForYear = + _fetchedConsumableYearlySummaryData + .map((consumableMonthObject) => + consumableMonthObject.quantity_out!) + .toList(); + + setState(() { + _fetchedConsumableYearlySummaryData; + _selectedConsumableValue = newValue; + _consumableItemQuantityInForYear; + _consumableItemQuantityOutForYear; + }); + }); + }), + const SizedBox( + width: 20.0, + ), + Text( + 'Select a Year:', + style: TextStyle( + fontStyle: FontStyle.normal, + fontWeight: FontWeight.bold), + ), + SizedBox( + width: 5, + ), + TextButton( + onPressed: () => _showPicker(context), + child: Icon(Icons.calendar_month), + ), + if (_selectedYear == null) + Container( + margin: EdgeInsets.only(left: 10.0), + child: const Text( + 'No year selected.', + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.normal, + ), + ), + ) + else + Container( + child: Text( + _selectedYear.year.toString(), + style: TextStyle( + fontSize: 14, fontWeight: FontWeight.normal), + ), + ), + SizedBox( + width: 20.0, + ), + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + width: 70.0, + height: 30.0, + child: Text( + 'Quantity In', + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.normal, + ), + ), + ), + SizedBox( + width: 5, + ), + SizedBox( + child: Container( + width: 20, + height: 20, + color: Colors.green, + ), + ), + ], + ), + SizedBox( + width: 5, + ), + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + width: 80.0, + height: 30.0, + child: Text( + 'Quantity Out', + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.normal, + ), + ), + ), + SizedBox( + width: 5, + ), + SizedBox( + child: Container( + width: 20, + height: 20, + color: Colors.red, + ), + ), + ], + ), + ], + ), + ), + const SizedBox( + height: 5.0, + ), + Center( + child: Text( + 'Unit - ${_selectedConsumableUnitValue ?? ''}', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + ), + const SizedBox( + height: 20.0, + ), + if (_consumableItemQuantityInForYear.length > 0 && + _consumableItemQuantityOutForYear.length > 0) + Flexible( + flex: 3, + child: BarChart( + BarChartData( + groupsSpace: 30.0, + alignment: BarChartAlignment.spaceAround, + barGroups: _getBarGroups(), + titlesData: FlTitlesData( + show: true, + topTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false)), + bottomTitles: AxisTitles( + sideTitles: SideTitles( + getTitlesWidget: getTitles, + showTitles: true, + reservedSize: 50))), + gridData: FlGridData( + show: true, + drawHorizontalLine: true, + drawVerticalLine: false), + ), + ), + ) + else + Container( + margin: EdgeInsets.only(left: 10.0), + child: const Text( + 'No data', + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.normal, + ), + ), + ) + ], + ), + ); + } +} diff --git a/campus/frontend/lib/avinya/asset_admin/lib/widgets/consumable_dashboard.dart b/campus/frontend/lib/avinya/asset_admin/lib/widgets/consumable_dashboard.dart new file mode 100644 index 0000000..e964804 --- /dev/null +++ b/campus/frontend/lib/avinya/asset_admin/lib/widgets/consumable_dashboard.dart @@ -0,0 +1,37 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; + +import 'consumable_bar_chart.dart'; +import 'latest_consumable_data.dart'; + +class ConsumableDashboard extends StatefulWidget { + const ConsumableDashboard({super.key}); + + @override + State createState() => _ConsumableDashboardState(); +} + +class _ConsumableDashboardState extends State { + @override + Widget build(BuildContext context) { + return Row( + children: [ + Flexible( + flex: 2, + child: Padding( + padding: const EdgeInsets.only(left: 20, top: 25.0), + child: LatestConsumableData(), + ), + ), + Flexible( + flex: 3, + child: Padding( + padding: const EdgeInsets.only(left: 20, top: 25.0), + child: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: ConsumableBarChart()), + )) + ], + ); + } +} diff --git a/campus/frontend/lib/avinya/asset_admin/lib/widgets/latest_consumable_data.dart b/campus/frontend/lib/avinya/asset_admin/lib/widgets/latest_consumable_data.dart new file mode 100644 index 0000000..4d57172 --- /dev/null +++ b/campus/frontend/lib/avinya/asset_admin/lib/widgets/latest_consumable_data.dart @@ -0,0 +1,241 @@ +import 'dart:ui'; + +import 'package:flutter/material.dart'; +import 'package:flutter_spinkit/flutter_spinkit.dart'; +import 'package:gallery/avinya/asset_admin/lib/data/stock_repenishment.dart'; +import 'package:gallery/data/campus_apps_portal.dart'; +import 'package:intl/intl.dart'; + +class LatestConsumableData extends StatefulWidget { + const LatestConsumableData({super.key}); + + @override + State createState() => _LatestConsumableDataState(); +} + +class _LatestConsumableDataState extends State { + + List _fetchedLatestConsumableData = []; + bool _isFetching = false; + DateTime? _selected; + + late DataTableSource _data; + + List dataTablecolumnNames = []; + late int parentOrgId; + + @override + void initState() { + super.initState(); + _fetchInitialData(); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _data = MyData(_fetchedLatestConsumableData,isQuantityBelowThreshold, + getThresholdValue); + } + + Future _fetchInitialData() async { + int? parentOrgId = + campusAppsPortalInstance.getUserPerson().organization?.id; + if (parentOrgId != null) { + setState(() { + _isFetching = true; // Show loading indicator + }); + try { + _fetchedLatestConsumableData = await getStockListforReplenishment(parentOrgId, + DateFormat('yyyy-MM-dd').format(DateTime.now())); + + setState(() { + _isFetching = false; + _data = MyData(_fetchedLatestConsumableData, isQuantityBelowThreshold, + getThresholdValue); + }); + } catch (error) { + // Handle any errors that occur during the fetch + // You can show an error message or take appropriate actions here + } finally { + setState(() { + _isFetching = false; // Hide loading indicator + }); + } + } + } + + bool isQuantityBelowThreshold(String unit,double quantity){ + + const Map thresholds = { + 'kg': 2.0, + 'g': 500.0, + 'packet': 2.0, + 'cup': 10.0, + 'bags': 10.0, + 'rolls': 1.0, + 'litre': 2.0, + 'ml': 100.0, + 'piece': 20.0, + }; + + if(thresholds.containsKey(unit)){ + return quantity < thresholds[unit]!; + } + return false; + } + + double getThresholdValue(String unit){ + + const Map thresholds = { + 'kg': 2.0, + 'g': 500.0, + 'packet': 2.0, + 'cup': 10.0, + 'bags': 10.0, + 'rolls': 1.0, + 'litre': 2.0, + 'ml': 100.0, + 'piece': 20.0, + }; + + return thresholds.containsKey(unit) ? thresholds[unit]! : 0.0; + } + + List _buildDataColumns() { + List columnNames = []; + + columnNames.add(DataColumn( + label: Center( + child: Text('Product Name', + style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)), + ))); + + columnNames.add(DataColumn( + label: Center( + child: Text('On Hand(QTY)', + style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)), + ))); + + columnNames.add(DataColumn( + label: Center( + child: Text('Unit', + style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)), + ))); + + columnNames.add(DataColumn( + label: Center( + child: Text('Threshold', + style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)), + ))); + + return columnNames; + } + + @override + Widget build(BuildContext context) { + return SingleChildScrollView( + child: Wrap(children: [ + Center( + child: Text( + 'Latest Consumable Data', + style: TextStyle( + fontSize: 24, + fontWeight: FontWeight.bold, + color: Colors.purple, + ), + ), + ), + if (_isFetching) + Container( + margin: EdgeInsets.only(top: 180), + child: SpinKitCircle( + color: (Colors + .yellow[700]), + size: 50, + ), + ) + else if (_fetchedLatestConsumableData.length > 0) + Container( + margin: EdgeInsets.only(left: 10.0, top: 20.0), + child: ScrollConfiguration( + behavior: ScrollConfiguration.of(context) + .copyWith(dragDevices: { + PointerDeviceKind.touch, + PointerDeviceKind.mouse, + }), + child: PaginatedDataTable( + showCheckboxColumn: false, + source: _data, + columns: _buildDataColumns(), + columnSpacing:35, + horizontalMargin: 30, + rowsPerPage: 10, + ), + ), + ) + else + Container( + margin: EdgeInsets.all(20), + child: Text('No latest consumable data found'), + ), + ]), + ); + } +} + +class MyData extends DataTableSource { + MyData(this._fetchedLatestConsumableData,this.isQuantityBelowThreshold,this.getThresholdValue); + + final List _fetchedLatestConsumableData; + final Function(String,double) isQuantityBelowThreshold; + final Function(String) getThresholdValue; + + @override + DataRow? getRow(int index) { + + var consumableItem = _fetchedLatestConsumableData[index]; + + bool isBelowThreshold = isQuantityBelowThreshold( + consumableItem.resource_property!.value.toString(), + consumableItem.quantity! + ); + + double threshold = getThresholdValue(consumableItem.resource_property!.value!); + + List cells = List.filled(4, DataCell.empty); + + cells[0] = DataCell(Center( + child: Text(consumableItem.consumable!.name.toString()))); + cells[1] = DataCell( + Center(child: Text(consumableItem.quantity.toString()))); + cells[2] = + DataCell( + Center(child: Text(consumableItem.resource_property!.value.toString()))); + cells[3] = + DataCell( + Center(child: Text(threshold.toString()))); + + + return DataRow( + color: MaterialStateProperty.resolveWith((Set states){ + return isBelowThreshold ?Colors.red[300]:null; + }), + cells: cells + ); + } + + @override + bool get isRowCountApproximate => false; + + @override + int get rowCount { + int count = 0; + if (_fetchedLatestConsumableData.length > 0) { + count = _fetchedLatestConsumableData.length; + } + return count; + } + + @override + int get selectedRowCount => 0; +} diff --git a/campus/frontend/lib/avinya/asset_admin/pubspec.yaml b/campus/frontend/lib/avinya/asset_admin/pubspec.yaml index 7ed9fa9..8366eb0 100644 --- a/campus/frontend/lib/avinya/asset_admin/pubspec.yaml +++ b/campus/frontend/lib/avinya/asset_admin/pubspec.yaml @@ -35,6 +35,7 @@ dependencies: path: plugins/window_size month_year_picker: ^0.3.0+1 oktoast: ^3.4.0 + fl_chart: ^0.60.0 dev_dependencies: flutter_lints: ^2.0.1 diff --git a/campus/frontend/lib/pages/home.dart b/campus/frontend/lib/pages/home.dart index 70fa47c..40263fe 100644 --- a/campus/frontend/lib/pages/home.dart +++ b/campus/frontend/lib/pages/home.dart @@ -156,7 +156,7 @@ class HomePage extends StatelessWidget { studyRoute: asset_admin_routes.assetadminRoute, ), ), - // //2023-04-19 commented for prod and stag branches + //2023-04-19 commented for prod and stag branches // Padding( // padding: const EdgeInsets.all(10.0), // child: _CarouselCard( From 8dcb7f7eb5bbc06adba73710265c176592faf336 Mon Sep 17 00:00:00 2001 From: YujithIsura Date: Thu, 8 Aug 2024 15:12:54 +0530 Subject: [PATCH 2/7] debug log added --- campus/bffs/asset/api/service.bal | 426 +++++++++++++++--------------- 1 file changed, 215 insertions(+), 211 deletions(-) diff --git a/campus/bffs/asset/api/service.bal b/campus/bffs/asset/api/service.bal index 7a4372f..dff36fd 100644 --- a/campus/bffs/asset/api/service.bal +++ b/campus/bffs/asset/api/service.bal @@ -2,21 +2,27 @@ import ballerina/http; import ballerina/graphql; import ballerina/log; -public function initClientConfig() returns ConnectionConfig{ +public function initClientConfig() returns ConnectionConfig { ConnectionConfig _clientConig = {}; if (GLOBAL_DATA_USE_AUTH) { - _clientConig.oauth2ClientCredentialsGrantConfig = { + _clientConig.oauth2ClientCredentialsGrantConfig = { tokenUrl: CHOREO_TOKEN_URL, - clientId:GLOBAL_DATA_CLIENT_ID, - clientSecret:GLOBAL_DATA_CLIENT_SECRET + clientId: GLOBAL_DATA_CLIENT_ID, + clientSecret: GLOBAL_DATA_CLIENT_SECRET }; - } else { + } else { _clientConig = {}; } + log:printDebug("debug log"); + log:printError("error log"); + log:printInfo("info log"); + log:printWarn("warn log"); + log:printInfo("CHOREO_TOKEN_URL: " + CHOREO_TOKEN_URL); + log:printInfo("GLOBAL_DATA_CLIENT_ID: " + GLOBAL_DATA_CLIENT_ID); + log:printInfo("GLOBAL_DATA_CLIENT_SECRET: " + GLOBAL_DATA_CLIENT_SECRET); return _clientConig; } - final GraphqlClient globalDataClient = check new (GLOBAL_DATA_API_URL, config = initClientConfig() ); @@ -28,713 +34,711 @@ final GraphqlClient globalDataClient = check new (GLOBAL_DATA_API_URL, } service / on new http:Listener(9094) { - resource function get asset (int assetId) returns Asset|error { + resource function get asset(int assetId) returns Asset|error { GetAssetResponse|graphql:ClientError getAssetResponse = globalDataClient->getAsset(assetId); - if(getAssetResponse is GetAssetResponse) { + if (getAssetResponse is GetAssetResponse) { Asset|error asset = getAssetResponse.asset.cloneWithType(Asset); - if(asset is Asset) { + if (asset is Asset) { return asset; } else { log:printError("Error while processing Application record received", asset); - return error("Error while processing Application record received: " + asset.message() + + return error("Error while processing Application record received: " + asset.message() + ":: Detail: " + asset.detail().toString()); } } else { log:printError("Error while getting application", getAssetResponse); - return error("Error while getting application: " + getAssetResponse.message() + + return error("Error while getting application: " + getAssetResponse.message() + ":: Detail: " + getAssetResponse.detail().toString()); } } - resource function get assets () returns Asset[]|error { + resource function get assets() returns Asset[]|error { GetAssetsResponse|graphql:ClientError getAssetsResponse = globalDataClient->getAssets(); - if(getAssetsResponse is GetAssetsResponse) { + if (getAssetsResponse is GetAssetsResponse) { Asset[] assets = []; foreach var asset in getAssetsResponse.assets { Asset|error asset_record = asset.cloneWithType(Asset); - if(asset_record is Asset) { + if (asset_record is Asset) { assets.push(asset_record); } else { log:printError("Error while processing Application record received", asset_record); - return error("Error while processing Application record received: " + asset_record.message() + + return error("Error while processing Application record received: " + asset_record.message() + ":: Detail: " + asset_record.detail().toString()); } } return assets; - + } else { log:printError("Error while getting application", getAssetsResponse); - return error("Error while getting application: " + getAssetsResponse.message() + + return error("Error while getting application: " + getAssetsResponse.message() + ":: Detail: " + getAssetsResponse.detail().toString()); } } - resource function post asset (@http:Payload Asset asset) returns Asset|error { + resource function post asset(@http:Payload Asset asset) returns Asset|error { CreateAssetResponse|graphql:ClientError createAssetResponse = globalDataClient->createAsset(asset); - if(createAssetResponse is CreateAssetResponse) { + if (createAssetResponse is CreateAssetResponse) { Asset|error asset_record = createAssetResponse.add_asset.cloneWithType(Asset); - if(asset_record is Asset) { + if (asset_record is Asset) { return asset_record; } else { log:printError("Error while processing Application record received", asset_record); - return error("Error while processing Application record received: " + asset_record.message() + + return error("Error while processing Application record received: " + asset_record.message() + ":: Detail: " + asset_record.detail().toString()); } } else { log:printError("Error while creating application", createAssetResponse); - return error("Error while creating application: " + createAssetResponse.message() + + return error("Error while creating application: " + createAssetResponse.message() + ":: Detail: " + createAssetResponse.detail().toString()); } } - resource function put asset (@http:Payload Asset asset) returns Asset|error { + resource function put asset(@http:Payload Asset asset) returns Asset|error { UpdateAssetResponse|graphql:ClientError updateAssetResponse = globalDataClient->updateAsset(asset); - if(updateAssetResponse is UpdateAssetResponse) { + if (updateAssetResponse is UpdateAssetResponse) { Asset|error asset_record = updateAssetResponse.update_asset.cloneWithType(Asset); - if(asset_record is Asset) { + if (asset_record is Asset) { return asset_record; } else { log:printError("Error while processing Application record received", asset_record); - return error("Error while processing Application record received: " + asset_record.message() + + return error("Error while processing Application record received: " + asset_record.message() + ":: Detail: " + asset_record.detail().toString()); } } else { log:printError("Error while updating application", updateAssetResponse); - return error("Error while updating application: " + updateAssetResponse.message() + + return error("Error while updating application: " + updateAssetResponse.message() + ":: Detail: " + updateAssetResponse.detail().toString()); } } - resource function get supplier (int supplierId) returns Supplier|error { + resource function get supplier(int supplierId) returns Supplier|error { GetSupplierResponse|graphql:ClientError getSupplierResponse = globalDataClient->getSupplier(supplierId); - if(getSupplierResponse is GetSupplierResponse) { + if (getSupplierResponse is GetSupplierResponse) { Supplier|error supplier = getSupplierResponse.supplier.cloneWithType(Supplier); - if(supplier is Supplier) { + if (supplier is Supplier) { return supplier; } else { log:printError("Error while processing Application record received", supplier); - return error("Error while processing Application record received: " + supplier.message() + + return error("Error while processing Application record received: " + supplier.message() + ":: Detail: " + supplier.detail().toString()); } } else { log:printError("Error while getting application", getSupplierResponse); - return error("Error while getting application: " + getSupplierResponse.message() + + return error("Error while getting application: " + getSupplierResponse.message() + ":: Detail: " + getSupplierResponse.detail().toString()); } } - resource function get suppliers () returns Supplier[]|error { + resource function get suppliers() returns Supplier[]|error { GetSuppliersResponse|graphql:ClientError getSuppliersResponse = globalDataClient->getSuppliers(); - if(getSuppliersResponse is GetSuppliersResponse) { + if (getSuppliersResponse is GetSuppliersResponse) { Supplier[] suppliers = []; foreach var supplier in getSuppliersResponse.suppliers { Supplier|error supplier_record = supplier.cloneWithType(Supplier); - if(supplier_record is Supplier) { + if (supplier_record is Supplier) { suppliers.push(supplier_record); } else { log:printError("Error while processing Application record received", supplier_record); - return error("Error while processing Application record received: " + supplier_record.message() + + return error("Error while processing Application record received: " + supplier_record.message() + ":: Detail: " + supplier_record.detail().toString()); } } return suppliers; - + } else { log:printError("Error while getting application", getSuppliersResponse); - return error("Error while getting application: " + getSuppliersResponse.message() + + return error("Error while getting application: " + getSuppliersResponse.message() + ":: Detail: " + getSuppliersResponse.detail().toString()); } } - resource function post supplier (@http:Payload Supplier supplier) returns Supplier|error { + resource function post supplier(@http:Payload Supplier supplier) returns Supplier|error { AddSupplierResponse|graphql:ClientError createSupplierResponse = globalDataClient->addSupplier(supplier); - if(createSupplierResponse is AddSupplierResponse) { + if (createSupplierResponse is AddSupplierResponse) { Supplier|error supplier_record = createSupplierResponse.add_supplier.cloneWithType(Supplier); - if(supplier_record is Supplier) { + if (supplier_record is Supplier) { return supplier_record; } else { log:printError("Error while processing Application record received", supplier_record); - return error("Error while processing Application record received: " + supplier_record.message() + + return error("Error while processing Application record received: " + supplier_record.message() + ":: Detail: " + supplier_record.detail().toString()); } } else { log:printError("Error while creating application", createSupplierResponse); - return error("Error while creating application: " + createSupplierResponse.message() + + return error("Error while creating application: " + createSupplierResponse.message() + ":: Detail: " + createSupplierResponse.detail().toString()); } } - resource function put supplier (@http:Payload Supplier supplier) returns Supplier|error { + resource function put supplier(@http:Payload Supplier supplier) returns Supplier|error { UpdateSupplierResponse|graphql:ClientError updateSupplierResponse = globalDataClient->updateSupplier(supplier); - if(updateSupplierResponse is UpdateSupplierResponse) { + if (updateSupplierResponse is UpdateSupplierResponse) { Supplier|error supplier_record = updateSupplierResponse.update_supplier.cloneWithType(Supplier); - if(supplier_record is Supplier) { + if (supplier_record is Supplier) { return supplier_record; } else { log:printError("Error while processing Application record received", supplier_record); - return error("Error while processing Application record received: " + supplier_record.message() + + return error("Error while processing Application record received: " + supplier_record.message() + ":: Detail: " + supplier_record.detail().toString()); } } else { log:printError("Error while updating application", updateSupplierResponse); - return error("Error while updating application: " + updateSupplierResponse.message() + + return error("Error while updating application: " + updateSupplierResponse.message() + ":: Detail: " + updateSupplierResponse.detail().toString()); } } - resource function get consumable (int consumableId) returns Consumable|error { + resource function get consumable(int consumableId) returns Consumable|error { GetConsumableResponse|graphql:ClientError getConsumableResponse = globalDataClient->getConsumable(consumableId); - if(getConsumableResponse is GetConsumableResponse) { + if (getConsumableResponse is GetConsumableResponse) { Consumable|error consumable = getConsumableResponse.consumable.cloneWithType(Consumable); - if(consumable is Consumable) { + if (consumable is Consumable) { return consumable; } else { log:printError("Error while processing Application record received", consumable); - return error("Error while processing Application record received: " + consumable.message() + + return error("Error while processing Application record received: " + consumable.message() + ":: Detail: " + consumable.detail().toString()); } } else { log:printError("Error while getting application", getConsumableResponse); - return error("Error while getting application: " + getConsumableResponse.message() + + return error("Error while getting application: " + getConsumableResponse.message() + ":: Detail: " + getConsumableResponse.detail().toString()); } } - resource function get consumables () returns Consumable[]|error { + resource function get consumables() returns Consumable[]|error { GetConsumablesResponse|graphql:ClientError getConsumablesResponse = globalDataClient->getConsumables(); - if(getConsumablesResponse is GetConsumablesResponse) { + if (getConsumablesResponse is GetConsumablesResponse) { Consumable[] consumables = []; foreach var consumable in getConsumablesResponse.consumables { Consumable|error consumable_record = consumable.cloneWithType(Consumable); - if(consumable_record is Consumable) { + if (consumable_record is Consumable) { consumables.push(consumable_record); } else { log:printError("Error while processing Application record received", consumable_record); - return error("Error while processing Application record received: " + consumable_record.message() + + return error("Error while processing Application record received: " + consumable_record.message() + ":: Detail: " + consumable_record.detail().toString()); } } return consumables; - + } else { log:printError("Error while getting application", getConsumablesResponse); - return error("Error while getting application: " + getConsumablesResponse.message() + + return error("Error while getting application: " + getConsumablesResponse.message() + ":: Detail: " + getConsumablesResponse.detail().toString()); } } - resource function post consumable (@http:Payload Consumable consumable) returns Consumable|error { + resource function post consumable(@http:Payload Consumable consumable) returns Consumable|error { AddConsumableResponse|graphql:ClientError createConsumableResponse = globalDataClient->addConsumable(consumable); - if(createConsumableResponse is AddConsumableResponse) { + if (createConsumableResponse is AddConsumableResponse) { Consumable|error consumable_record = createConsumableResponse.add_consumable.cloneWithType(Consumable); - if(consumable_record is Consumable) { + if (consumable_record is Consumable) { return consumable_record; } else { log:printError("Error while processing Application record received", consumable_record); - return error("Error while processing Application record received: " + consumable_record.message() + + return error("Error while processing Application record received: " + consumable_record.message() + ":: Detail: " + consumable_record.detail().toString()); } } else { log:printError("Error while creating application", createConsumableResponse); - return error("Error while creating application: " + createConsumableResponse.message() + + return error("Error while creating application: " + createConsumableResponse.message() + ":: Detail: " + createConsumableResponse.detail().toString()); } } - resource function put consumable (@http:Payload Consumable consumable) returns Consumable|error { + resource function put consumable(@http:Payload Consumable consumable) returns Consumable|error { UpdateConsumableResponse|graphql:ClientError updateConsumableResponse = globalDataClient->updateConsumable(consumable); - if(updateConsumableResponse is UpdateConsumableResponse) { + if (updateConsumableResponse is UpdateConsumableResponse) { Consumable|error consumable_record = updateConsumableResponse.update_consumable.cloneWithType(Consumable); - if(consumable_record is Consumable) { + if (consumable_record is Consumable) { return consumable_record; } else { log:printError("Error while processing Application record received", consumable_record); - return error("Error while processing Application record received: " + consumable_record.message() + + return error("Error while processing Application record received: " + consumable_record.message() + ":: Detail: " + consumable_record.detail().toString()); } } else { log:printError("Error while updating application", updateConsumableResponse); - return error("Error while updating application: " + updateConsumableResponse.message() + + return error("Error while updating application: " + updateConsumableResponse.message() + ":: Detail: " + updateConsumableResponse.detail().toString()); } } - resource function get resource_property (int resourcePropertyId) returns ResourceProperty|error { + resource function get resource_property(int resourcePropertyId) returns ResourceProperty|error { GetResourcePropertyResponse|graphql:ClientError getResourcePropertyResponse = globalDataClient->getResourceProperty(resourcePropertyId); - if(getResourcePropertyResponse is GetResourcePropertyResponse) { + if (getResourcePropertyResponse is GetResourcePropertyResponse) { ResourceProperty|error resource_property = getResourcePropertyResponse.resource_property.cloneWithType(ResourceProperty); - if(resource_property is ResourceProperty) { + if (resource_property is ResourceProperty) { return resource_property; } else { log:printError("Error while processing Application record received", resource_property); - return error("Error while processing Application record received: " + resource_property.message() + + return error("Error while processing Application record received: " + resource_property.message() + ":: Detail: " + resource_property.detail().toString()); } } else { log:printError("Error while getting application", getResourcePropertyResponse); - return error("Error while getting application: " + getResourcePropertyResponse.message() + + return error("Error while getting application: " + getResourcePropertyResponse.message() + ":: Detail: " + getResourcePropertyResponse.detail().toString()); } } - resource function get resource_properties () returns ResourceProperty[]|error { + resource function get resource_properties() returns ResourceProperty[]|error { GetResourcePropertiesResponse|graphql:ClientError getResourcePropertiesResponse = globalDataClient->getResourceProperties(); - if(getResourcePropertiesResponse is GetResourcePropertiesResponse) { + if (getResourcePropertiesResponse is GetResourcePropertiesResponse) { ResourceProperty[] resource_properties = []; foreach var resource_property in getResourcePropertiesResponse.resource_properties { ResourceProperty|error resource_property_record = resource_property.cloneWithType(ResourceProperty); - if(resource_property_record is ResourceProperty) { + if (resource_property_record is ResourceProperty) { resource_properties.push(resource_property_record); } else { log:printError("Error while processing Application record received", resource_property_record); - return error("Error while processing Application record received: " + resource_property_record.message() + + return error("Error while processing Application record received: " + resource_property_record.message() + ":: Detail: " + resource_property_record.detail().toString()); } } return resource_properties; - + } else { log:printError("Error while getting application", getResourcePropertiesResponse); - return error("Error while getting application: " + getResourcePropertiesResponse.message() + + return error("Error while getting application: " + getResourcePropertiesResponse.message() + ":: Detail: " + getResourcePropertiesResponse.detail().toString()); } } - resource function post resource_property (@http:Payload ResourceProperty resourceProperty) returns ResourceProperty|error { + resource function post resource_property(@http:Payload ResourceProperty resourceProperty) returns ResourceProperty|error { AddResourcePropertyResponse|graphql:ClientError createResourcePropertyResponse = globalDataClient->addResourceProperty(resourceProperty); - if(createResourcePropertyResponse is AddResourcePropertyResponse) { + if (createResourcePropertyResponse is AddResourcePropertyResponse) { ResourceProperty|error resource_property_record = createResourcePropertyResponse.add_resource_property.cloneWithType(ResourceProperty); - if(resource_property_record is ResourceProperty) { + if (resource_property_record is ResourceProperty) { return resource_property_record; } else { log:printError("Error while processing Application record received", resource_property_record); - return error("Error while processing Application record received: " + resource_property_record.message() + + return error("Error while processing Application record received: " + resource_property_record.message() + ":: Detail: " + resource_property_record.detail().toString()); } } else { log:printError("Error while creating application", createResourcePropertyResponse); - return error("Error while creating application: " + createResourcePropertyResponse.message() + + return error("Error while creating application: " + createResourcePropertyResponse.message() + ":: Detail: " + createResourcePropertyResponse.detail().toString()); } } - resource function put resource_property (@http:Payload ResourceProperty resourceProperty) returns ResourceProperty|error { + resource function put resource_property(@http:Payload ResourceProperty resourceProperty) returns ResourceProperty|error { UpdateResourcePropertyResponse|graphql:ClientError updateResourcePropertyResponse = globalDataClient->updateResourceProperty(resourceProperty); - if(updateResourcePropertyResponse is UpdateResourcePropertyResponse) { + if (updateResourcePropertyResponse is UpdateResourcePropertyResponse) { ResourceProperty|error resource_property_record = updateResourcePropertyResponse.update_resource_property.cloneWithType(ResourceProperty); - if(resource_property_record is ResourceProperty) { + if (resource_property_record is ResourceProperty) { return resource_property_record; } else { log:printError("Error while processing Application record received", resource_property_record); - return error("Error while processing Application record received: " + resource_property_record.message() + + return error("Error while processing Application record received: " + resource_property_record.message() + ":: Detail: " + resource_property_record.detail().toString()); } } else { log:printError("Error while updating application", updateResourcePropertyResponse); - return error("Error while updating application: " + updateResourcePropertyResponse.message() + + return error("Error while updating application: " + updateResourcePropertyResponse.message() + ":: Detail: " + updateResourcePropertyResponse.detail().toString()); } } - resource function get supply (int supplyId) returns Supply|error { + resource function get supply(int supplyId) returns Supply|error { GetSupplyResponse|graphql:ClientError getSupplyResponse = globalDataClient->getSupply(supplyId); - if(getSupplyResponse is GetSupplyResponse) { + if (getSupplyResponse is GetSupplyResponse) { Supply|error supply = getSupplyResponse.supply.cloneWithType(Supply); - if(supply is Supply) { + if (supply is Supply) { return supply; } else { log:printError("Error while processing Application record received", supply); - return error("Error while processing Application record received: " + supply.message() + + return error("Error while processing Application record received: " + supply.message() + ":: Detail: " + supply.detail().toString()); } } else { log:printError("Error while getting application", getSupplyResponse); - return error("Error while getting application: " + getSupplyResponse.message() + + return error("Error while getting application: " + getSupplyResponse.message() + ":: Detail: " + getSupplyResponse.detail().toString()); } } - resource function get supplies () returns Supply[]|error { + resource function get supplies() returns Supply[]|error { GetSuppliesResponse|graphql:ClientError getSuppliesResponse = globalDataClient->getSupplies(); - if(getSuppliesResponse is GetSuppliesResponse) { + if (getSuppliesResponse is GetSuppliesResponse) { Supply[] supplies = []; foreach var supply in getSuppliesResponse.supplies { Supply|error supply_record = supply.cloneWithType(Supply); - if(supply_record is Supply) { + if (supply_record is Supply) { supplies.push(supply_record); } else { log:printError("Error while processing Application record received", supply_record); - return error("Error while processing Application record received: " + supply_record.message() + + return error("Error while processing Application record received: " + supply_record.message() + ":: Detail: " + supply_record.detail().toString()); } } return supplies; - + } else { log:printError("Error while getting application", getSuppliesResponse); - return error("Error while getting application: " + getSuppliesResponse.message() + + return error("Error while getting application: " + getSuppliesResponse.message() + ":: Detail: " + getSuppliesResponse.detail().toString()); } } - resource function post supply (@http:Payload Supply supply) returns Supply|error { + resource function post supply(@http:Payload Supply supply) returns Supply|error { AddSupplyResponse|graphql:ClientError createSupplyResponse = globalDataClient->addSupply(supply); - if(createSupplyResponse is AddSupplyResponse) { + if (createSupplyResponse is AddSupplyResponse) { Supply|error supply_record = createSupplyResponse.add_supply.cloneWithType(Supply); - if(supply_record is Supply) { + if (supply_record is Supply) { return supply_record; } else { log:printError("Error while processing Application record received", supply_record); - return error("Error while processing Application record received: " + supply_record.message() + + return error("Error while processing Application record received: " + supply_record.message() + ":: Detail: " + supply_record.detail().toString()); } } else { log:printError("Error while creating application", createSupplyResponse); - return error("Error while creating application: " + createSupplyResponse.message() + + return error("Error while creating application: " + createSupplyResponse.message() + ":: Detail: " + createSupplyResponse.detail().toString()); } } - resource function put supply (@http:Payload Supply supply) returns Supply|error { + resource function put supply(@http:Payload Supply supply) returns Supply|error { UpdateSupplyResponse|graphql:ClientError updateSupplyResponse = globalDataClient->updateSupply(supply); - if(updateSupplyResponse is UpdateSupplyResponse) { + if (updateSupplyResponse is UpdateSupplyResponse) { Supply|error supply_record = updateSupplyResponse.update_supply.cloneWithType(Supply); - if(supply_record is Supply) { + if (supply_record is Supply) { return supply_record; } else { log:printError("Error while processing Application record received", supply_record); - return error("Error while processing Application record received: " + supply_record.message() + + return error("Error while processing Application record received: " + supply_record.message() + ":: Detail: " + supply_record.detail().toString()); } } else { log:printError("Error while updating application", updateSupplyResponse); - return error("Error while updating application: " + updateSupplyResponse.message() + + return error("Error while updating application: " + updateSupplyResponse.message() + ":: Detail: " + updateSupplyResponse.detail().toString()); } } - resource function get resource_allocation (int resourceAllocationId) returns ResourceAllocation[]|error { + resource function get resource_allocation(int resourceAllocationId) returns ResourceAllocation[]|error { GetResourceAllocationResponse|graphql:ClientError getResourceAllocationResponse = globalDataClient->getResourceAllocation(resourceAllocationId); - if(getResourceAllocationResponse is GetResourceAllocationResponse) { + if (getResourceAllocationResponse is GetResourceAllocationResponse) { ResourceAllocation[] resource_allocations = []; foreach var resource_allocation in getResourceAllocationResponse.resource_allocation { ResourceAllocation|error resource_allocation_record = resource_allocation.cloneWithType(ResourceAllocation); - if(resource_allocation_record is ResourceAllocation) { + if (resource_allocation_record is ResourceAllocation) { resource_allocations.push(resource_allocation_record); } else { log:printError("Error while processing Application record received", resource_allocation_record); - return error("Error while processing Application record received: " + resource_allocation_record.message() + + return error("Error while processing Application record received: " + resource_allocation_record.message() + ":: Detail: " + resource_allocation_record.detail().toString()); } } return resource_allocations; - + } else { log:printError("Error while getting application", getResourceAllocationResponse); - return error("Error while getting application: " + getResourceAllocationResponse.message() + + return error("Error while getting application: " + getResourceAllocationResponse.message() + ":: Detail: " + getResourceAllocationResponse.detail().toString()); } } - resource function get resource_allocation_by_person (int personId) returns ResourceAllocation[]|error { + resource function get resource_allocation_by_person(int personId) returns ResourceAllocation[]|error { GetResourceAllocationByPersonResponse|graphql:ClientError getResourceAllocationByPersonResponse = globalDataClient->getResourceAllocationByPerson(personId); - if(getResourceAllocationByPersonResponse is GetResourceAllocationByPersonResponse) { + if (getResourceAllocationByPersonResponse is GetResourceAllocationByPersonResponse) { ResourceAllocation[] resource_allocations = []; foreach var resource_allocation in getResourceAllocationByPersonResponse.resource_allocation { ResourceAllocation|error resource_allocation_record = resource_allocation.cloneWithType(ResourceAllocation); - if(resource_allocation_record is ResourceAllocation) { + if (resource_allocation_record is ResourceAllocation) { resource_allocations.push(resource_allocation_record); } else { log:printError("Error while processing Application record received", resource_allocation_record); - return error("Error while processing Application record received: " + resource_allocation_record.message() + + return error("Error while processing Application record received: " + resource_allocation_record.message() + ":: Detail: " + resource_allocation_record.detail().toString()); } } return resource_allocations; - + } else { log:printError("Error while getting application", getResourceAllocationByPersonResponse); - return error("Error while getting application: " + getResourceAllocationByPersonResponse.message() + + return error("Error while getting application: " + getResourceAllocationByPersonResponse.message() + ":: Detail: " + getResourceAllocationByPersonResponse.detail().toString()); } } - resource function get resource_allocations () returns ResourceAllocation[]|error { + resource function get resource_allocations() returns ResourceAllocation[]|error { GetResourceAllocationsResponse|graphql:ClientError getResourceAllocationsResponse = globalDataClient->getResourceAllocations(); - if(getResourceAllocationsResponse is GetResourceAllocationsResponse) { + if (getResourceAllocationsResponse is GetResourceAllocationsResponse) { ResourceAllocation[] resource_allocations = []; foreach var resource_allocation in getResourceAllocationsResponse.resource_allocations { ResourceAllocation|error resource_allocation_record = resource_allocation.cloneWithType(ResourceAllocation); - if(resource_allocation_record is ResourceAllocation) { + if (resource_allocation_record is ResourceAllocation) { resource_allocations.push(resource_allocation_record); } else { log:printError("Error while processing Application record received", resource_allocation_record); - return error("Error while processing Application record received: " + resource_allocation_record.message() + + return error("Error while processing Application record received: " + resource_allocation_record.message() + ":: Detail: " + resource_allocation_record.detail().toString()); } } return resource_allocations; - + } else { log:printError("Error while getting application", getResourceAllocationsResponse); - return error("Error while getting application: " + getResourceAllocationsResponse.message() + + return error("Error while getting application: " + getResourceAllocationsResponse.message() + ":: Detail: " + getResourceAllocationsResponse.detail().toString()); } } - resource function post resource_allocation (@http:Payload ResourceAllocation resourceAllocation) returns ResourceAllocation|error { + resource function post resource_allocation(@http:Payload ResourceAllocation resourceAllocation) returns ResourceAllocation|error { AddResourceAllocationResponse|graphql:ClientError createResourceAllocationResponse = globalDataClient->addResourceAllocation(resourceAllocation); - if(createResourceAllocationResponse is AddResourceAllocationResponse) { + if (createResourceAllocationResponse is AddResourceAllocationResponse) { ResourceAllocation|error resource_allocation_record = createResourceAllocationResponse.add_resource_allocation.cloneWithType(ResourceAllocation); - if(resource_allocation_record is ResourceAllocation) { + if (resource_allocation_record is ResourceAllocation) { return resource_allocation_record; } else { log:printError("Error while processing Application record received", resource_allocation_record); - return error("Error while processing Application record received: " + resource_allocation_record.message() + + return error("Error while processing Application record received: " + resource_allocation_record.message() + ":: Detail: " + resource_allocation_record.detail().toString()); } } else { log:printError("Error while creating application", createResourceAllocationResponse); - return error("Error while creating application: " + createResourceAllocationResponse.message() + + return error("Error while creating application: " + createResourceAllocationResponse.message() + ":: Detail: " + createResourceAllocationResponse.detail().toString()); } } - resource function put resource_allocation (@http:Payload ResourceAllocation resourceAllocation) returns ResourceAllocation|error { + resource function put resource_allocation(@http:Payload ResourceAllocation resourceAllocation) returns ResourceAllocation|error { UpdateResourceAllocationResponse|graphql:ClientError updateResourceAllocationResponse = globalDataClient->updateResourceAllocation(resourceAllocation); - if(updateResourceAllocationResponse is UpdateResourceAllocationResponse) { + if (updateResourceAllocationResponse is UpdateResourceAllocationResponse) { ResourceAllocation|error resource_allocation_record = updateResourceAllocationResponse.update_resource_allocation.cloneWithType(ResourceAllocation); - if(resource_allocation_record is ResourceAllocation) { + if (resource_allocation_record is ResourceAllocation) { return resource_allocation_record; } else { log:printError("Error while processing Application record received", resource_allocation_record); - return error("Error while processing Application record received: " + resource_allocation_record.message() + + return error("Error while processing Application record received: " + resource_allocation_record.message() + ":: Detail: " + resource_allocation_record.detail().toString()); } } else { log:printError("Error while updating application", updateResourceAllocationResponse); - return error("Error while updating application: " + updateResourceAllocationResponse.message() + + return error("Error while updating application: " + updateResourceAllocationResponse.message() + ":: Detail: " + updateResourceAllocationResponse.detail().toString()); } } - resource function get inventory (int inventoryId) returns Inventory|error { + resource function get inventory(int inventoryId) returns Inventory|error { GetInventoryResponse|graphql:ClientError getInventoryResponse = globalDataClient->getInventory(inventoryId); - if(getInventoryResponse is GetInventoryResponse) { + if (getInventoryResponse is GetInventoryResponse) { Inventory|error inventory = getInventoryResponse.inventory.cloneWithType(Inventory); - if(inventory is Inventory) { + if (inventory is Inventory) { return inventory; } else { log:printError("Error while processing Application record received", inventory); - return error("Error while processing Application record received: " + inventory.message() + + return error("Error while processing Application record received: " + inventory.message() + ":: Detail: " + inventory.detail().toString()); } } else { log:printError("Error while getting application", getInventoryResponse); - return error("Error while getting application: " + getInventoryResponse.message() + + return error("Error while getting application: " + getInventoryResponse.message() + ":: Detail: " + getInventoryResponse.detail().toString()); } } - resource function get inventories () returns Inventory[]|error { + resource function get inventories() returns Inventory[]|error { GetInventoriesResponse|graphql:ClientError getInventoriesResponse = globalDataClient->getInventories(); - if(getInventoriesResponse is GetInventoriesResponse) { + if (getInventoriesResponse is GetInventoriesResponse) { Inventory[] inventories = []; foreach var inventory in getInventoriesResponse.inventories { Inventory|error inventory_record = inventory.cloneWithType(Inventory); - if(inventory_record is Inventory) { + if (inventory_record is Inventory) { inventories.push(inventory_record); } else { log:printError("Error while processing Application record received", inventory_record); - return error("Error while processing Application record received: " + inventory_record.message() + + return error("Error while processing Application record received: " + inventory_record.message() + ":: Detail: " + inventory_record.detail().toString()); } } return inventories; - + } else { log:printError("Error while getting application", getInventoriesResponse); - return error("Error while getting application: " + getInventoriesResponse.message() + + return error("Error while getting application: " + getInventoriesResponse.message() + ":: Detail: " + getInventoriesResponse.detail().toString()); } } - resource function post inventory (@http:Payload Inventory inventory) returns Inventory|error { + resource function post inventory(@http:Payload Inventory inventory) returns Inventory|error { AddInventoryResponse|graphql:ClientError createInventoryResponse = globalDataClient->addInventory(inventory); - if(createInventoryResponse is AddInventoryResponse) { + if (createInventoryResponse is AddInventoryResponse) { Inventory|error inventory_record = createInventoryResponse.add_inventory.cloneWithType(Inventory); - if(inventory_record is Inventory) { + if (inventory_record is Inventory) { return inventory_record; } else { log:printError("Error while processing Application record received", inventory_record); - return error("Error while processing Application record received: " + inventory_record.message() + + return error("Error while processing Application record received: " + inventory_record.message() + ":: Detail: " + inventory_record.detail().toString()); } } else { log:printError("Error while creating application", createInventoryResponse); - return error("Error while creating application: " + createInventoryResponse.message() + + return error("Error while creating application: " + createInventoryResponse.message() + ":: Detail: " + createInventoryResponse.detail().toString()); } } - resource function put inventory (@http:Payload Inventory inventory) returns Inventory|error { + resource function put inventory(@http:Payload Inventory inventory) returns Inventory|error { UpdateInventoryResponse|graphql:ClientError updateInventoryResponse = globalDataClient->updateInventory(inventory); - if(updateInventoryResponse is UpdateInventoryResponse) { + if (updateInventoryResponse is UpdateInventoryResponse) { Inventory|error inventory_record = updateInventoryResponse.update_inventory.cloneWithType(Inventory); - if(inventory_record is Inventory) { + if (inventory_record is Inventory) { return inventory_record; } else { log:printError("Error while processing Application record received", inventory_record); - return error("Error while processing Application record received: " + inventory_record.message() + + return error("Error while processing Application record received: " + inventory_record.message() + ":: Detail: " + inventory_record.detail().toString()); } } else { log:printError("Error while updating application", updateInventoryResponse); - return error("Error while updating application: " + updateInventoryResponse.message() + + return error("Error while updating application: " + updateInventoryResponse.message() + ":: Detail: " + updateInventoryResponse.detail().toString()); } } - resource function get assetByAvinyaType (int avinyaType) returns Asset[]|error { + resource function get assetByAvinyaType(int avinyaType) returns Asset[]|error { GetAssetByAvinyaTypeResponse|graphql:ClientError getAssetByAvinyaTypeResponse = globalDataClient->getAssetByAvinyaType(avinyaType); - if(getAssetByAvinyaTypeResponse is GetAssetByAvinyaTypeResponse) { + if (getAssetByAvinyaTypeResponse is GetAssetByAvinyaTypeResponse) { Asset[] assets = []; foreach var asset in getAssetByAvinyaTypeResponse.asset_by_avinya_type { Asset|error asset_record = asset.cloneWithType(Asset); - if(asset_record is Asset) { + if (asset_record is Asset) { assets.push(asset_record); } else { log:printError("Error while processing Application record received", asset_record); - return error("Error while processing Application record received: " + asset_record.message() + + return error("Error while processing Application record received: " + asset_record.message() + ":: Detail: " + asset_record.detail().toString()); } } return assets; - + } else { log:printError("Error while getting application", getAssetByAvinyaTypeResponse); - return error("Error while getting application: " + getAssetByAvinyaTypeResponse.message() + + return error("Error while getting application: " + getAssetByAvinyaTypeResponse.message() + ":: Detail: " + getAssetByAvinyaTypeResponse.detail().toString()); } } resource function get avinyaTypesByAsset() returns AvinyaType[]|error { GetAvinyaTypeByAssetResponse|graphql:ClientError getAvinyaTypesByAssetResponse = globalDataClient->getAvinyaTypeByAsset(); - if(getAvinyaTypesByAssetResponse is GetAvinyaTypeByAssetResponse) { + if (getAvinyaTypesByAssetResponse is GetAvinyaTypeByAssetResponse) { AvinyaType[] avinyaTypes = []; foreach var avinyaType in getAvinyaTypesByAssetResponse.avinya_types_by_asset { AvinyaType|error avinyaType_record = avinyaType.cloneWithType(AvinyaType); - if(avinyaType_record is AvinyaType) { + if (avinyaType_record is AvinyaType) { avinyaTypes.push(avinyaType_record); } else { log:printError("Error while processing Application record received", avinyaType_record); - return error("Error while processing Application record received: " + avinyaType_record.message() + + return error("Error while processing Application record received: " + avinyaType_record.message() + ":: Detail: " + avinyaType_record.detail().toString()); } } return avinyaTypes; - + } else { log:printError("Error while getting application", getAvinyaTypesByAssetResponse); - return error("Error while getting application: " + getAvinyaTypesByAssetResponse.message() + + return error("Error while getting application: " + getAvinyaTypesByAssetResponse.message() + ":: Detail: " + getAvinyaTypesByAssetResponse.detail().toString()); } } resource function get resource_allocations_report/[int organization_id]/[int avinya_type_id]() returns ResourceAllocation[]|error { - GetResourceAllocationReportResponse|graphql:ClientError getResourceAllocationsReportResponse = globalDataClient->getResourceAllocationReport(organization_id,avinya_type_id); - if(getResourceAllocationsReportResponse is GetResourceAllocationReportResponse) { + GetResourceAllocationReportResponse|graphql:ClientError getResourceAllocationsReportResponse = globalDataClient->getResourceAllocationReport(organization_id, avinya_type_id); + if (getResourceAllocationsReportResponse is GetResourceAllocationReportResponse) { ResourceAllocation[] resource_allocations = []; foreach var resource_allocation in getResourceAllocationsReportResponse.resource_allocations_report { ResourceAllocation|error resource_allocation_record = resource_allocation.cloneWithType(ResourceAllocation); - if(resource_allocation_record is ResourceAllocation) { + if (resource_allocation_record is ResourceAllocation) { resource_allocations.push(resource_allocation_record); } else { log:printError("Error while processing Application record received", resource_allocation_record); - return error("Error while processing Application record received: " + resource_allocation_record.message() + + return error("Error while processing Application record received: " + resource_allocation_record.message() + ":: Detail: " + resource_allocation_record.detail().toString()); } } - + return resource_allocations; - + } else { log:printError("Error while getting application", getResourceAllocationsReportResponse); - return error("Error while getting application: " + getResourceAllocationsReportResponse.message() + - ":: Detail: " +getResourceAllocationsReportResponse.detail().toString()); + return error("Error while getting application: " + getResourceAllocationsReportResponse.message() + + ":: Detail: " + getResourceAllocationsReportResponse.detail().toString()); } } resource function get organizations_by_avinya_type(int avinya_type) returns Organization[]|error { - - - + GetOrganizationsByAvinyaTypeResponse|graphql:ClientError getOrganizationsByAvinyaTypeResponse = globalDataClient->getOrganizationsByAvinyaType(avinya_type); - - if(getOrganizationsByAvinyaTypeResponse is GetOrganizationsByAvinyaTypeResponse) { - - Organization[] organizations_by_avinya_type_record = []; - + + if (getOrganizationsByAvinyaTypeResponse is GetOrganizationsByAvinyaTypeResponse) { + + Organization[] organizations_by_avinya_type_record = []; + foreach var organization_by_avinya_type in getOrganizationsByAvinyaTypeResponse.organizations_by_avinya_type { - + Organization|error organization_by_avinya_type_record = organization_by_avinya_type.cloneWithType(Organization); - - if(organization_by_avinya_type_record is Organization) { - organizations_by_avinya_type_record .push(organization_by_avinya_type_record); + if (organization_by_avinya_type_record is Organization) { + + organizations_by_avinya_type_record.push(organization_by_avinya_type_record); } else { log:printError("Error while processing Application record received", organization_by_avinya_type_record); - return error("Error while processing Application record received: " + organization_by_avinya_type_record.message() + + return error("Error while processing Application record received: " + organization_by_avinya_type_record.message() + ":: Detail: " + organization_by_avinya_type_record.detail().toString()); } } - + return organizations_by_avinya_type_record; - + } else { log:printError("Error while getting application", getOrganizationsByAvinyaTypeResponse); - return error("Error while getting application: " + getOrganizationsByAvinyaTypeResponse.message() + - ":: Detail: " +getOrganizationsByAvinyaTypeResponse.detail().toString()); + return error("Error while getting application: " + getOrganizationsByAvinyaTypeResponse.message() + + ":: Detail: " + getOrganizationsByAvinyaTypeResponse.detail().toString()); } } resource function get all_avinya_types() returns AvinyaType[]|error { GetAvinyaTypesResponse|graphql:ClientError getAvinyaTypesResponse = globalDataClient->getAvinyaTypes(); - if(getAvinyaTypesResponse is GetAvinyaTypesResponse) { + if (getAvinyaTypesResponse is GetAvinyaTypesResponse) { AvinyaType[] avinyaTypes = []; foreach var avinya_type in getAvinyaTypesResponse.avinya_types { AvinyaType|error avinyaType = avinya_type.cloneWithType(AvinyaType); - if(avinyaType is AvinyaType) { + if (avinyaType is AvinyaType) { avinyaTypes.push(avinyaType); } else { log:printError("Error while processing Application record received", avinyaType); - return error("Error while processing Application record received: " + avinyaType.message() + + return error("Error while processing Application record received: " + avinyaType.message() + ":: Detail: " + avinyaType.detail().toString()); } } return avinyaTypes; - + } else { log:printError("Error while getting application", getAvinyaTypesResponse); - return error("Error while getting application: " + getAvinyaTypesResponse.message() + + return error("Error while getting application: " + getAvinyaTypesResponse.message() + ":: Detail: " + getAvinyaTypesResponse.detail().toString()); } } resource function get inventory_data_by_organization/[int organization_id]/[string date]() returns Inventory[]|error { - GetInventoryDataByOrganizationResponse|graphql:ClientError getInventoryDataByOrganizationResponse = globalDataClient->getInventoryDataByOrganization(date,organization_id); + GetInventoryDataByOrganizationResponse|graphql:ClientError getInventoryDataByOrganizationResponse = globalDataClient->getInventoryDataByOrganization(date, organization_id); if (getInventoryDataByOrganizationResponse is GetInventoryDataByOrganizationResponse) { Inventory[] inventory_datas = []; foreach var inventory_data in getInventoryDataByOrganizationResponse.inventory_data_by_organization { @@ -757,9 +761,9 @@ service / on new http:Listener(9094) { } } resource function post consumable_replenishment/[int person_id]/[int organization_id]/[string date](@http:Payload Inventory[] inventories) returns json|error { - - json|graphql:ClientError createInventoryResponse = globalDataClient->consumableReplenishment(person_id,organization_id,date,inventories); - if(createInventoryResponse is json) { + + json|graphql:ClientError createInventoryResponse = globalDataClient->consumableReplenishment(person_id, organization_id, date, inventories); + if (createInventoryResponse is json) { log:printInfo("Inventories created successfully: " + createInventoryResponse.toString()); return createInventoryResponse; } else { @@ -770,9 +774,9 @@ service / on new http:Listener(9094) { } resource function post consumable_depletion/[int person_id]/[int organization_id]/[string date](@http:Payload Inventory[] inventories) returns json|error { - - json|graphql:ClientError inventoryDepletionResponse = globalDataClient->consumableDepletion(person_id,organization_id,date,inventories); - if(inventoryDepletionResponse is json) { + + json|graphql:ClientError inventoryDepletionResponse = globalDataClient->consumableDepletion(person_id, organization_id, date, inventories); + if (inventoryDepletionResponse is json) { log:printInfo("Inventories depleted successfully: " + inventoryDepletionResponse.toString()); return inventoryDepletionResponse; } else { @@ -783,7 +787,7 @@ service / on new http:Listener(9094) { } resource function get consumable_weekly_report/[int organization_id]/[string from_date]/[string to_date]() returns Inventory[]|error { - GetConsumableWeeklyReportResponse|graphql:ClientError getConsumableWeeklyReportResponse = globalDataClient->getConsumableWeeklyReport(from_date,to_date,organization_id); + GetConsumableWeeklyReportResponse|graphql:ClientError getConsumableWeeklyReportResponse = globalDataClient->getConsumableWeeklyReport(from_date, to_date, organization_id); if (getConsumableWeeklyReportResponse is GetConsumableWeeklyReportResponse) { Inventory[] weekly_summary_inventory_datas = []; foreach var weekly_summary_inventory_data in getConsumableWeeklyReportResponse.consumable_weekly_report { @@ -807,7 +811,7 @@ service / on new http:Listener(9094) { } resource function put consumable_replenishment(@http:Payload Inventory[] inventories) returns json|error { - + json|graphql:ClientError updateConsumableReplenishmentResponse = globalDataClient->updateConsumableReplenishment(inventories); if (updateConsumableReplenishmentResponse is json) { log:printInfo("Consumables updated successfully: " + updateConsumableReplenishmentResponse.toString()); @@ -833,7 +837,7 @@ service / on new http:Listener(9094) { } resource function get consumable_monthly_report/[int organization_id]/[int year]/[int month]() returns Inventory[]|error { - GetConsumableMonthlyReportResponse|graphql:ClientError getConsumableMonthlyReportResponse = globalDataClient->getConsumableMonthlyReport(month,year,organization_id); + GetConsumableMonthlyReportResponse|graphql:ClientError getConsumableMonthlyReportResponse = globalDataClient->getConsumableMonthlyReport(month, year, organization_id); if (getConsumableMonthlyReportResponse is GetConsumableMonthlyReportResponse) { Inventory[] monthly_summary_consumable_datas = []; foreach var monthly_summary_consumable_data in getConsumableMonthlyReportResponse.consumable_monthly_report { From d7f398cb81c8fb9bddbe07a94963283c6cb9a446 Mon Sep 17 00:00:00 2001 From: lahirulakruwan Date: Thu, 8 Aug 2024 18:51:06 +0530 Subject: [PATCH 3/7] Vehicle fuel consumption frontend changes added --- .../lib/avinya/asset_admin/lib/app.dart | 7 + .../asset_admin/lib/screens/scaffold.dart | 42 +++ .../lib/screens/scaffold_body.dart | 7 + .../lib/screens/vehicle_fuel_consumption.dart | 26 ++ .../lib/widgets/vehicle_fuel_consumption.dart | 333 ++++++++++++++++++ 5 files changed, 415 insertions(+) create mode 100644 campus/frontend/lib/avinya/asset_admin/lib/screens/vehicle_fuel_consumption.dart create mode 100644 campus/frontend/lib/avinya/asset_admin/lib/widgets/vehicle_fuel_consumption.dart diff --git a/campus/frontend/lib/avinya/asset_admin/lib/app.dart b/campus/frontend/lib/avinya/asset_admin/lib/app.dart index 76756fd..bbfa96c 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/app.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/app.dart @@ -41,6 +41,7 @@ class _AssetAdminSystemState extends State { '/stock_depletion', '/consumable_monthly_report', '/consumable_weekly_report', + '/vehicle_fuel_consumption', // '/assets/new', // '/assets/all', // '/assets/popular', @@ -136,6 +137,10 @@ class _AssetAdminSystemState extends State { final consumableWeeklyReportRoute = ParsedRoute( '/consumable_weekly_report', '/consumable_weekly_report', {}, {}); + + final vehicleFuelConsumptionRoute = ParsedRoute( + '/vehicle_fuel_consumption', '/vehicle_fuel_consumption', {}, {}); + // // Go to /apply if the user is not signed in log("_guard signed in $signedIn"); @@ -156,6 +161,8 @@ class _AssetAdminSystemState extends State { return consumableMonthlyReportRoute; } else if (signedIn && from == consumableWeeklyReportRoute) { return consumableWeeklyReportRoute; + } else if (signedIn && from == vehicleFuelConsumptionRoute) { + return vehicleFuelConsumptionRoute; } // Go to /application if the user is signed in and tries to go to /signin. else if (signedIn && from == signInRoute) { diff --git a/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold.dart b/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold.dart index 0f562fa..2caa9ae 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold.dart @@ -22,6 +22,7 @@ class _SMSScaffoldState extends State { bool isConsumableReportSectionHovered = false; bool isStockReplenishmentSectionHovered = false; bool isStockDepletionSectionHovered = false; + bool isVehicleFuelConsumptionSectionHovered = false; @override Widget build(BuildContext context) { @@ -380,6 +381,47 @@ class _SMSScaffoldState extends State { ), ), ), + MouseRegion( + onEnter: (_) { + setState(() { + isVehicleFuelConsumptionSectionHovered = true; + }); + }, + onExit: (_) { + setState(() { + isVehicleFuelConsumptionSectionHovered = false; + }); + }, + child: Container( + decoration: BoxDecoration( + color: isVehicleFuelConsumptionSectionHovered + ? Colors.white.withOpacity(0.3) + : null, + borderRadius: BorderRadius.circular(15.0), + ), + margin: EdgeInsets.all(8.0), + child: ListTile( + leading: Icon(Icons.local_gas_station_sharp, + color: Colors.white, size: 20.0), + title: Container( + margin: EdgeInsets.only(left: 12.0), + transform: + Matrix4.translationValues(-25, 0.0, 0.0), + child: Text( + "Vehicle Fuel Consumption", + style: TextStyle( + color: Colors.white, + fontSize: 12, + ), + ), + ), + onTap: () { + Navigator.pop(context); // Close the drawer + routeState.go('/vehicle_fuel_consumption'); + }, + ), + ), + ), SideNavigationSection( initialSectionHoveredValue: isConsumableReportSectionHovered, diff --git a/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold_body.dart b/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold_body.dart index cee6026..cb4415b 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold_body.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold_body.dart @@ -8,6 +8,7 @@ import 'package:gallery/avinya/asset_admin/lib/screens/stock_depletion.dart'; import 'package:gallery/avinya/asset_admin/lib/screens/stock_replenishment.dart'; import 'package:gallery/avinya/asset_admin/lib/screens/consumable_monthly_report.dart'; import 'package:gallery/avinya/asset_admin/lib/screens/consumable_weekly_report.dart'; +import 'package:gallery/avinya/asset_admin/lib/screens/vehicle_fuel_consumption.dart'; import 'package:gallery/avinya/asset_admin/lib/widgets/resource_allocation_report.dart'; import '../routing.dart'; @@ -69,6 +70,12 @@ class SMSScaffoldBody extends StatelessWidget { key: ValueKey('consumable_weekly_report'), child: ConsumableWeeklyReportScreen(), ) + else if (currentRoute.pathTemplate + .startsWith('/vehicle_fuel_consumption')) + const FadeTransitionPage( + key: ValueKey('vehicle_fuel_consumption'), + child: VehicleFuelConsumptionScreen(), + ) // Avoid building a Navigator with an empty `pages` list when the // RouteState is set to an unexpected path, such as /signin. // diff --git a/campus/frontend/lib/avinya/asset_admin/lib/screens/vehicle_fuel_consumption.dart b/campus/frontend/lib/avinya/asset_admin/lib/screens/vehicle_fuel_consumption.dart new file mode 100644 index 0000000..90081a9 --- /dev/null +++ b/campus/frontend/lib/avinya/asset_admin/lib/screens/vehicle_fuel_consumption.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; +import 'package:gallery/avinya/asset_admin/lib/widgets/vehicle_fuel_consumption.dart'; + +class VehicleFuelConsumptionScreen extends StatefulWidget { + const VehicleFuelConsumptionScreen({super.key}); + + @override + State createState() => _VehicleFuelConsumptionScreenState(); +} + +class _VehicleFuelConsumptionScreenState extends State { + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + automaticallyImplyLeading: false, + title: Text("Vehicle Fuel Consumption"), + ), + body: SingleChildScrollView( + child: Container( + child: VehicleFuelConsumption(), + ), + ), + ); + } +} \ No newline at end of file diff --git a/campus/frontend/lib/avinya/asset_admin/lib/widgets/vehicle_fuel_consumption.dart b/campus/frontend/lib/avinya/asset_admin/lib/widgets/vehicle_fuel_consumption.dart new file mode 100644 index 0000000..6691892 --- /dev/null +++ b/campus/frontend/lib/avinya/asset_admin/lib/widgets/vehicle_fuel_consumption.dart @@ -0,0 +1,333 @@ +import 'package:flutter/material.dart'; + +class VehicleFuelConsumption extends StatefulWidget { + const VehicleFuelConsumption({super.key}); + + @override + State createState() => _VehicleFuelConsumptionState(); +} + +class _VehicleFuelConsumptionState extends State { + DateTime? _selectedDate; + String reasonValue = 'Student Shuttle-Morning'; + final List reasonValues = [ + 'Student Shuttle-Morning', + 'Student Shuttle-Evening', + 'Other' + ]; + String vehicleNoValue = 'QL-9904'; + final List vehicleNoValues = ['QL-9904', 'PB-2010', 'KV-1892']; + final _starting_meter_controller = TextEditingController(); + final _ending_meter_controller = TextEditingController(); + final _comment_controller = TextEditingController(); + + Future _selectDate(BuildContext context) async { + final DateTime? pickedDate = await showDatePicker( + context: context, + initialDate: DateTime.now(), + firstDate: DateTime(2020), + lastDate: DateTime(2101), + ); + + if (pickedDate != null && pickedDate != _selectedDate) { + setState(() { + _selectedDate = pickedDate; + }); + } + } + + @override + void dispose() { + _starting_meter_controller.dispose(); + _ending_meter_controller.dispose(); + _comment_controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + var screenWidth = MediaQuery.of(context).size.width; + var screenHeight = MediaQuery.of(context).size.height; + + return Flexible( + child: Padding( + padding: const EdgeInsets.only(left: 20.0, top: 30.0), + child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ + Row( + children: [ + Flexible( + flex: 1, + child: Text( + 'Select a Date :', + style: TextStyle( + fontStyle: FontStyle.normal, fontWeight: FontWeight.bold), + ), + ), + SizedBox( + width: 20.0, + ), + Flexible( + flex: 2, + child: Container( + margin: EdgeInsets.only(left: 30.0), + width: screenWidth * 0.05, + height: screenHeight * 0.06, + child: TextField( + readOnly: true, + decoration: InputDecoration( + prefixIcon: Icon(Icons.calendar_month), + border: InputBorder.none), + onTap: () => _selectDate(context), + ), + ), + ), + if (_selectedDate != null) + Flexible( + flex: 1, + child: Text('${_selectedDate!.toLocal()}'.split(' ')[0])) + else + Flexible( + flex: 1, + child: Container( + margin: EdgeInsets.only(left: 20.0), + child: const Text( + 'No date selected.', + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.normal, + ), + ), + ), + ) + ], + ), + const SizedBox( + height: 10, + ), + Row( + children: [ + Flexible( + flex: 1, + child: Text( + 'Select a Reason :', + style: TextStyle( + fontStyle: FontStyle.normal, fontWeight: FontWeight.bold), + ), + ), + SizedBox( + width: 20.0, + ), + Flexible( + flex: 2, + child: Container( + margin: EdgeInsets.only(left: 20.0), + width: screenWidth * 0.17, + height: screenHeight * 0.06, + decoration: BoxDecoration( + border: Border.all(color: Colors.grey, width: 1.0), + borderRadius: BorderRadius.circular(5.0)), + child: DropdownButton( + isExpanded: true, + underline: SizedBox.shrink(), + value: reasonValue, + items: reasonValues.map((String? reason) { + return DropdownMenuItem( + value: reason, child: Text(reason ?? '')); + }).toList(), + onChanged: (String? newValue) async { + if (newValue == null) { + return; + } + setState(() { + reasonValue = newValue; + }); + }), + ), + ), + ], + ), + const SizedBox( + height: 10, + ), + Row( + children: [ + Flexible( + flex: 1, + child: Text( + 'Vehicle No :', + style: TextStyle( + fontStyle: FontStyle.normal, fontWeight: FontWeight.bold), + ), + ), + SizedBox( + width: 20.0, + ), + Flexible( + flex: 2, + child: Container( + margin: EdgeInsets.only(left: 50.0), + width: screenWidth * 0.08, + height: screenHeight * 0.06, + decoration: BoxDecoration( + border: Border.all(color: Colors.grey, width: 1.0), + borderRadius: BorderRadius.circular(5.0)), + child: DropdownButton( + isExpanded: true, + underline: SizedBox.shrink(), + value: vehicleNoValue, + items: vehicleNoValues.map((String? vehicleNo) { + return DropdownMenuItem( + value: vehicleNo, child: Text(vehicleNo ?? '')); + }).toList(), + onChanged: (String? newValue) async { + if (newValue == null) { + return; + } + setState(() { + vehicleNoValue = newValue; + }); + }), + ), + ), + ], + ), + const SizedBox( + height: 10, + ), + Row( + children: [ + Flexible( + flex: 1, + child: Text( + 'Starting Meter :', + style: TextStyle( + fontStyle: FontStyle.normal, fontWeight: FontWeight.bold), + ), + ), + SizedBox( + width: 20.0, + ), + Flexible( + flex: 2, + child: Container( + margin: EdgeInsets.only(left: 30.0), + width: screenWidth * 0.2, + height: screenHeight * 0.08, + child: TextField( + maxLength: 20, + keyboardType: TextInputType.number, + controller: _starting_meter_controller, + decoration: InputDecoration( + counterText: '', + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(4.0))), + ), + ), + ), + ], + ), + const SizedBox( + height: 10, + ), + Row( + children: [ + Flexible( + flex: 1, + child: Text( + 'Ending Meter :', + style: TextStyle( + fontStyle: FontStyle.normal, fontWeight: FontWeight.bold), + ), + ), + SizedBox( + width: 20.0, + ), + Flexible( + flex: 2, + child: Container( + margin: EdgeInsets.only(left: 35.0), + width: screenWidth * 0.2, + height: screenHeight * 0.08, + child: TextField( + maxLength: 20, + keyboardType: TextInputType.number, + controller: _ending_meter_controller, + decoration: InputDecoration( + counterText: '', + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(4.0))), + ), + ), + ), + ], + ), + const SizedBox( + height: 10, + ), + Row( + children: [ + Flexible( + flex: 1, + child: Text( + 'Comment :', + style: TextStyle( + fontStyle: FontStyle.normal, fontWeight: FontWeight.bold), + ), + ), + SizedBox( + width: 20.0, + ), + Flexible( + flex: 2, + child: Container( + margin: EdgeInsets.only(left: 55.0), + width: screenWidth * 0.2, + height: screenHeight * 0.2, + child: TextField( + keyboardType: TextInputType.multiline, + maxLines: null, + minLines: 3, + controller: _comment_controller, + decoration: InputDecoration( + counterText: '', + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(4.0))), + ), + ), + ), + ], + ), + Row( + children: [ + Flexible( + child: Container( + width: screenWidth * 0.2, + height: screenHeight * 0.1, + child: OutlinedButton( + style: OutlinedButton.styleFrom( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(5.0)), + backgroundColor: Colors.yellow[700], + side: BorderSide( + color: Colors.grey.shade500, + width: 0.5, + style: BorderStyle.solid, + ), + ), + onPressed: (() {}), + child: Text( + 'Save', + style: TextStyle( + color: Colors.white, + fontSize: 16, + fontWeight: FontWeight.w400), + )), + ), + ), + ], + ) + ]), + ), + ); + } +} From 03c8ab504af06cf6e8271f535532fdfec5901538 Mon Sep 17 00:00:00 2001 From: YujithIsura Date: Fri, 9 Aug 2024 14:30:30 +0530 Subject: [PATCH 4/7] auth issue fixed --- campus/bffs/asset/api/client.bal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/campus/bffs/asset/api/client.bal b/campus/bffs/asset/api/client.bal index db9d085..138e196 100644 --- a/campus/bffs/asset/api/client.bal +++ b/campus/bffs/asset/api/client.bal @@ -3,7 +3,7 @@ import ballerina/graphql; public isolated client class GraphqlClient { final graphql:Client graphqlClient; public isolated function init(string serviceUrl, ConnectionConfig config = {}) returns graphql:ClientError? { - graphql:ClientConfiguration graphqlClientConfig = {timeout: config.timeout, forwarded: config.forwarded, poolConfig: config.poolConfig, compression: config.compression, circuitBreaker: config.circuitBreaker, retryConfig: config.retryConfig, validation: config.validation}; + graphql:ClientConfiguration graphqlClientConfig = {auth: config.oauth2ClientCredentialsGrantConfig,timeout: config.timeout, forwarded: config.forwarded, poolConfig: config.poolConfig, compression: config.compression, circuitBreaker: config.circuitBreaker, retryConfig: config.retryConfig, validation: config.validation}; do { if config.http1Settings is ClientHttp1Settings { ClientHttp1Settings settings = check config.http1Settings.ensureType(ClientHttp1Settings); From 43efe3aba7df75eeb361dd285dffaee17d03180c Mon Sep 17 00:00:00 2001 From: lahirulakruwan Date: Tue, 13 Aug 2024 11:55:21 +0530 Subject: [PATCH 5/7] Consumable dashboard UI fixes changes added --- campus/bffs/asset/api/client.bal | 2 +- campus/bffs/asset/api/types.bal | 3 + .../bffs/asset/graphql_client/asset.graphql | 1 + .../graphql_client_cg_src/client.bal | 2 +- .../graphql_client_cg_src/types.bal | 3 + .../bffs/asset/graphql_client/schema.graphql | 4 + campus/bffs/asset/graphql_client/schema.json | 40 ++ .../lib/avinya/asset_admin/lib/app.dart | 6 + .../lib/data/stock_repenishment.dart | 5 + .../asset_admin/lib/screens/scaffold.dart | 4 + .../lib/screens/scaffold_body.dart | 9 +- ...hicle_fuel_consumption_monthly_report.dart | 16 + .../lib/widgets/consumable_bar_chart.dart | 477 +++++++++--------- .../lib/widgets/consumable_dashboard.dart | 46 +- .../lib/widgets/latest_consumable_data.dart | 215 +++----- ...hicle_fuel_consumption_monthly_report.dart | 17 + 16 files changed, 470 insertions(+), 380 deletions(-) create mode 100644 campus/frontend/lib/avinya/asset_admin/lib/screens/vehicle_fuel_consumption_monthly_report.dart create mode 100644 campus/frontend/lib/avinya/asset_admin/lib/widgets/vehicle_fuel_consumption_monthly_report.dart diff --git a/campus/bffs/asset/api/client.bal b/campus/bffs/asset/api/client.bal index 9593653..4737757 100644 --- a/campus/bffs/asset/api/client.bal +++ b/campus/bffs/asset/api/client.bal @@ -233,7 +233,7 @@ public isolated client class GraphqlClient { } remote isolated function getInventoryDataByOrganization(string date, int organization_id) returns GetInventoryDataByOrganizationResponse|graphql:ClientError { - string query = string `query getInventoryDataByOrganization($organization_id:Int!,$date:String!) {inventory_data_by_organization(organization_id:$organization_id,date:$date) {id avinya_type_id consumable_id consumable {id name} quantity quantity_in quantity_out prev_quantity resource_property {id property value} created updated}}`; + string query = string `query getInventoryDataByOrganization($organization_id:Int!,$date:String!) {inventory_data_by_organization(organization_id:$organization_id,date:$date) {id avinya_type_id consumable_id consumable {id name} quantity quantity_in quantity_out prev_quantity is_below_threshold resource_property {id property value} created updated}}`; map variables = {"date": date, "organization_id": organization_id}; json graphqlResponse = check self.graphqlClient->executeWithType(query, variables); return check performDataBinding(graphqlResponse, GetInventoryDataByOrganizationResponse); diff --git a/campus/bffs/asset/api/types.bal b/campus/bffs/asset/api/types.bal index 568085c..7ae6365 100644 --- a/campus/bffs/asset/api/types.bal +++ b/campus/bffs/asset/api/types.bal @@ -141,6 +141,7 @@ public type Consumable record { string? description?; string? model?; string? serial_number?; + anydata? threshold?; int? id?; string? updated?; string? record_type?; @@ -242,6 +243,7 @@ public type Inventory record { int? avinya_type_id?; string? description?; int? asset_id?; + int? is_below_threshold?; string? record_type?; string? manufacturer?; anydata? quantity_out?; @@ -1095,6 +1097,7 @@ public type GetInventoryDataByOrganizationResponse record {| anydata? quantity_in; anydata? quantity_out; anydata? prev_quantity; + int? is_below_threshold; record {| int? id; string? property; diff --git a/campus/bffs/asset/graphql_client/asset.graphql b/campus/bffs/asset/graphql_client/asset.graphql index c243b52..54bd555 100644 --- a/campus/bffs/asset/graphql_client/asset.graphql +++ b/campus/bffs/asset/graphql_client/asset.graphql @@ -655,6 +655,7 @@ query getInventoryDataByOrganization($organization_id: Int!,$date: String!) { quantity_in quantity_out prev_quantity + is_below_threshold resource_property{ id property diff --git a/campus/bffs/asset/graphql_client/graphql_client_cg_src/client.bal b/campus/bffs/asset/graphql_client/graphql_client_cg_src/client.bal index 2611265..e406b94 100644 --- a/campus/bffs/asset/graphql_client/graphql_client_cg_src/client.bal +++ b/campus/bffs/asset/graphql_client/graphql_client_cg_src/client.bal @@ -232,7 +232,7 @@ public isolated client class GraphqlClient { return check performDataBinding(graphqlResponse, GetAvinyaTypesResponse); } remote isolated function getInventoryDataByOrganization(string date, int organization_id) returns GetInventoryDataByOrganizationResponse|graphql:ClientError { - string query = string `query getInventoryDataByOrganization($organization_id:Int!,$date:String!) {inventory_data_by_organization(organization_id:$organization_id,date:$date) {id avinya_type_id consumable_id consumable {id name} quantity quantity_in quantity_out prev_quantity resource_property {id property value} created updated}}`; + string query = string `query getInventoryDataByOrganization($organization_id:Int!,$date:String!) {inventory_data_by_organization(organization_id:$organization_id,date:$date) {id avinya_type_id consumable_id consumable {id name} quantity quantity_in quantity_out prev_quantity is_below_threshold resource_property {id property value} created updated}}`; map variables = {"date": date, "organization_id": organization_id}; json graphqlResponse = check self.graphqlClient->executeWithType(query, variables); return check performDataBinding(graphqlResponse, GetInventoryDataByOrganizationResponse); diff --git a/campus/bffs/asset/graphql_client/graphql_client_cg_src/types.bal b/campus/bffs/asset/graphql_client/graphql_client_cg_src/types.bal index 3810d55..2191c62 100644 --- a/campus/bffs/asset/graphql_client/graphql_client_cg_src/types.bal +++ b/campus/bffs/asset/graphql_client/graphql_client_cg_src/types.bal @@ -144,6 +144,7 @@ public type Consumable record { string? description?; string? model?; string? serial_number?; + anydata? threshold?; int? id?; string? updated?; string? record_type?; @@ -246,6 +247,7 @@ public type Inventory record { int? avinya_type_id?; string? description?; int? asset_id?; + int? is_below_threshold?; string? record_type?; string? manufacturer?; anydata? quantity_out?; @@ -1101,6 +1103,7 @@ public type GetInventoryDataByOrganizationResponse record {| anydata? quantity_in; anydata? quantity_out; anydata? prev_quantity; + int? is_below_threshold; record {| int? id; string? property; diff --git a/campus/bffs/asset/graphql_client/schema.graphql b/campus/bffs/asset/graphql_client/schema.graphql index bb27c3a..3dcfb4e 100644 --- a/campus/bffs/asset/graphql_client/schema.graphql +++ b/campus/bffs/asset/graphql_client/schema.graphql @@ -327,6 +327,7 @@ input Consumable { manufacturer: String model: String serial_number: String + threshold: Decimal created: String updated: String } @@ -339,6 +340,7 @@ type ConsumableData { manufacturer: String model: String serial_number: String + threshold: Decimal created: String updated: String } @@ -558,6 +560,7 @@ input Inventory { prev_quantity: Decimal resource_property_id: Int resource_property_value: String + is_below_threshold: Int created: String updated: String } @@ -580,6 +583,7 @@ type InventoryData { month_name: String description: String manufacturer: String + is_below_threshold: Int created: String updated: String } diff --git a/campus/bffs/asset/graphql_client/schema.json b/campus/bffs/asset/graphql_client/schema.json index 220c6cf..d86212c 100644 --- a/campus/bffs/asset/graphql_client/schema.json +++ b/campus/bffs/asset/graphql_client/schema.json @@ -6265,6 +6265,17 @@ "isDeprecated": false, "deprecationReason": null }, + { + "name": "is_below_threshold", + "args": [], + "type": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, { "name": "created", "args": [], @@ -9123,6 +9134,15 @@ }, "defaultValue": null }, + { + "name": "is_below_threshold", + "type": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + }, + "defaultValue": null + }, { "name": "created", "type": { @@ -11313,6 +11333,17 @@ "isDeprecated": false, "deprecationReason": null }, + { + "name": "threshold", + "args": [], + "type": { + "kind": "SCALAR", + "name": "Decimal", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null + }, { "name": "created", "args": [], @@ -11599,6 +11630,15 @@ }, "defaultValue": null }, + { + "name": "threshold", + "type": { + "kind": "SCALAR", + "name": "Decimal", + "ofType": null + }, + "defaultValue": null + }, { "name": "created", "type": { diff --git a/campus/frontend/lib/avinya/asset_admin/lib/app.dart b/campus/frontend/lib/avinya/asset_admin/lib/app.dart index bbfa96c..38203f1 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/app.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/app.dart @@ -42,6 +42,7 @@ class _AssetAdminSystemState extends State { '/consumable_monthly_report', '/consumable_weekly_report', '/vehicle_fuel_consumption', + '/vehicle_fuel_consumption_monthly_report', // '/assets/new', // '/assets/all', // '/assets/popular', @@ -140,6 +141,9 @@ class _AssetAdminSystemState extends State { final vehicleFuelConsumptionRoute = ParsedRoute( '/vehicle_fuel_consumption', '/vehicle_fuel_consumption', {}, {}); + + final vehicleFuelConsumptionMonthlyReportRoute = ParsedRoute( + '/vehicle_fuel_consumption_monthly_report', '/vehicle_fuel_consumption_monthly_report', {}, {}); // // Go to /apply if the user is not signed in @@ -163,6 +167,8 @@ class _AssetAdminSystemState extends State { return consumableWeeklyReportRoute; } else if (signedIn && from == vehicleFuelConsumptionRoute) { return vehicleFuelConsumptionRoute; + } else if (signedIn && from == vehicleFuelConsumptionMonthlyReportRoute) { + return vehicleFuelConsumptionMonthlyReportRoute; } // Go to /application if the user is signed in and tries to go to /signin. else if (signedIn && from == signInRoute) { diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/stock_repenishment.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/stock_repenishment.dart index 218fd3a..9087094 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/stock_repenishment.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/stock_repenishment.dart @@ -22,6 +22,7 @@ class StockReplenishment { double? quantity_in; double? quantity_out; double? total_quantity; + int? is_below_threshold; ResourceProperty? resource_property; Consumable? consumable; @@ -39,6 +40,7 @@ class StockReplenishment { this.quantity_in, this.quantity_out, this.total_quantity, + this.is_below_threshold, this.resource_property, this.consumable}); @@ -61,6 +63,8 @@ class StockReplenishment { prev_quantity: json["prev_quantity"] == null ? null : json["prev_quantity"], total_quantity: json["quantity"] == null ? null : json["quantity"], + is_below_threshold: + json["is_below_threshold"] == null ? null : json["is_below_threshold"], quantity_in: json["quantity_in"] == null ? null : json["quantity_in"], quantity_out: json["quantity_out"] == null ? null : json["quantity_out"], @@ -85,6 +89,7 @@ class StockReplenishment { "total_quantity": quantity == null ? null : quantity, "quantity_in": quantity_in == null ? null : quantity_in, "quantity_out": quantity_out == null ? null : quantity_out, + "is_below_threshold":is_below_threshold == null ? null : is_below_threshold, "resource_property": resource_property == null ? null : resource_property, "consumable": consumable == null ? null : consumable, diff --git a/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold.dart b/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold.dart index 2caa9ae..3305609 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold.dart @@ -47,6 +47,10 @@ class _SMSScaffoldState extends State { tileName: "Consumable Monthly Report", route: "/consumable_monthly_report", icon: Icons.summarize_sharp), + SideNavigationSectionTile( + tileName: "Vehicle Fuel Consumption Monthly Report", + route: "/vehicle_fuel_consumption_monthly_report", + icon: Icons.local_gas_station_outlined), ]; return Scaffold( diff --git a/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold_body.dart b/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold_body.dart index cb4415b..29af18c 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold_body.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/screens/scaffold_body.dart @@ -10,6 +10,7 @@ import 'package:gallery/avinya/asset_admin/lib/screens/consumable_monthly_report import 'package:gallery/avinya/asset_admin/lib/screens/consumable_weekly_report.dart'; import 'package:gallery/avinya/asset_admin/lib/screens/vehicle_fuel_consumption.dart'; import 'package:gallery/avinya/asset_admin/lib/widgets/resource_allocation_report.dart'; +import 'package:gallery/avinya/asset_admin/lib/screens/vehicle_fuel_consumption_monthly_report.dart'; import '../routing.dart'; import '../widgets/fade_transition_page.dart'; @@ -70,12 +71,18 @@ class SMSScaffoldBody extends StatelessWidget { key: ValueKey('consumable_weekly_report'), child: ConsumableWeeklyReportScreen(), ) - else if (currentRoute.pathTemplate + else if (currentRoute.pathTemplate .startsWith('/vehicle_fuel_consumption')) const FadeTransitionPage( key: ValueKey('vehicle_fuel_consumption'), child: VehicleFuelConsumptionScreen(), ) + else if (currentRoute.pathTemplate + .startsWith('/vehicle_fuel_consumption_monthly_report')) + const FadeTransitionPage( + key: ValueKey('vehicle_fuel_consumption_monthly_report'), + child: VehicleFuelConsumptionMonthlyReportScreen(), + ) // Avoid building a Navigator with an empty `pages` list when the // RouteState is set to an unexpected path, such as /signin. // diff --git a/campus/frontend/lib/avinya/asset_admin/lib/screens/vehicle_fuel_consumption_monthly_report.dart b/campus/frontend/lib/avinya/asset_admin/lib/screens/vehicle_fuel_consumption_monthly_report.dart new file mode 100644 index 0000000..8a3d668 --- /dev/null +++ b/campus/frontend/lib/avinya/asset_admin/lib/screens/vehicle_fuel_consumption_monthly_report.dart @@ -0,0 +1,16 @@ +import 'package:flutter/material.dart'; +import 'package:gallery/avinya/asset_admin/lib/widgets/vehicle_fuel_consumption_monthly_report.dart'; + +class VehicleFuelConsumptionMonthlyReportScreen extends StatefulWidget { + const VehicleFuelConsumptionMonthlyReportScreen({super.key}); + + @override + State createState() => _VehicleFuelConsumptionMonthlyReportScreenState(); +} + +class _VehicleFuelConsumptionMonthlyReportScreenState extends State { + @override + Widget build(BuildContext context) { + return const VehicleFuelConsumptionMonthlyReport(); + } +} \ No newline at end of file diff --git a/campus/frontend/lib/avinya/asset_admin/lib/widgets/consumable_bar_chart.dart b/campus/frontend/lib/avinya/asset_admin/lib/widgets/consumable_bar_chart.dart index 89823c9..7c6a277 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/widgets/consumable_bar_chart.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/widgets/consumable_bar_chart.dart @@ -213,248 +213,271 @@ class _ConsumableBarChartState extends State { @override Widget build(BuildContext context) { - return AspectRatio( - aspectRatio: 16 / 9, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Center( - child: Text( - 'Consumable Yearly Report', + var screenWidth = MediaQuery.of(context).size.width; + var screenHeight = MediaQuery.of(context).size.height; + return Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Center( + child: Text( + 'Consumable Yearly Report', + style: TextStyle( + fontSize: 24, + fontWeight: FontWeight.bold, + ), + ), + ), + Row( + //mainAxisSize: MainAxisSize.min, + children: [ + Text( + 'Select a Consumable :', + style: TextStyle( + fontStyle: FontStyle.normal, fontWeight: FontWeight.bold), + ), + SizedBox( + width: 5.0, + ), + FutureBuilder>( + future: _fetchConsumableData, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return Container( + margin: EdgeInsets.only(top: 10), + child: SpinKitCircle( + color: (Colors.yellow[700]), + size: 70, + ), + ); + } else if (snapshot.hasError) { + return const Center( + child: Text('Something went wrong...'), + ); + } else if (!snapshot.hasData) { + return const Center( + child: Text('No consumable data found'), + ); + } + final consumableData = snapshot.data!; + return DropdownButton( + value: _selectedConsumableValue, + items: consumableData.map((Consumable consumable) { + return DropdownMenuItem( + value: consumable, + child: Text(consumable.name! ?? '')); + }).toList(), + onChanged: (Consumable? newValue) async { + if (newValue == null) { + return; + } + + int consumableId = newValue.id!; + + int? parentOrgId = campusAppsPortalInstance + .getUserPerson() + .organization! + .id; + + _fetchedConsumableYearlySummaryData = + await getConsumableYearlyReport( + parentOrgId!, consumableId, _selectedYear.year); + + _selectedConsumableUnitValue = + _fetchedConsumableYearlySummaryData + .first.resource_property!.value; + + _consumableItemQuantityInForYear = + _fetchedConsumableYearlySummaryData + .map((consumableMonthObject) => + consumableMonthObject.quantity_in!) + .toList(); + _consumableItemQuantityOutForYear = + _fetchedConsumableYearlySummaryData + .map((consumableMonthObject) => + consumableMonthObject.quantity_out!) + .toList(); + + setState(() { + _fetchedConsumableYearlySummaryData; + _selectedConsumableValue = newValue; + _consumableItemQuantityInForYear; + _consumableItemQuantityOutForYear; + }); + }); + }), + const SizedBox( + width: 20.0, + ), + Text( + 'Select a Year:', + style: TextStyle( + fontStyle: FontStyle.normal, fontWeight: FontWeight.bold), + ), + SizedBox( + width: 5, + ), + TextButton( + onPressed: () => _showPicker(context), + child: Icon(Icons.calendar_month), + ), + if (_selectedYear == null) + Container( + margin: EdgeInsets.only(left: 10.0), + child: const Text( + 'No year selected.', style: TextStyle( - fontSize: 24, - fontWeight: FontWeight.bold, - color: Colors.purple, // Matches yellow[700] + fontSize: 14, + fontWeight: FontWeight.normal, ), ), + ) + else + Container( + child: Text( + _selectedYear.year.toString(), + style: TextStyle(fontSize: 14, fontWeight: FontWeight.normal), + ), ), - Flexible( - flex: 2, - child: Row( - children: [ - Text( - 'Select a Consumable :', - style: TextStyle( - fontStyle: FontStyle.normal, - fontWeight: FontWeight.bold), - ), - FutureBuilder>( - future: _fetchConsumableData, - builder: (context, snapshot) { - if (snapshot.connectionState == - ConnectionState.waiting) { - return Container( - margin: EdgeInsets.only(top: 10), - child: SpinKitCircle( - color: (Colors.yellow[700]), - size: 70, - ), - ); - } else if (snapshot.hasError) { - return const Center( - child: Text('Something went wrong...'), - ); - } else if (!snapshot.hasData) { - return const Center( - child: Text('No consumable data found'), - ); - } - final consumableData = snapshot.data!; - return DropdownButton( - value: _selectedConsumableValue, - items: consumableData.map((Consumable consumable) { - return DropdownMenuItem( - value: consumable, - child: Text(consumable.name! ?? '')); - }).toList(), - onChanged: (Consumable? newValue) async { - if (newValue == null) { - return; - } - - int consumableId = newValue.id!; - - int? parentOrgId = campusAppsPortalInstance - .getUserPerson() - .organization! - .id; - - _fetchedConsumableYearlySummaryData = - await getConsumableYearlyReport(parentOrgId!, - consumableId, _selectedYear.year); - - _selectedConsumableUnitValue = - _fetchedConsumableYearlySummaryData - .first.resource_property!.value; - - _consumableItemQuantityInForYear = - _fetchedConsumableYearlySummaryData - .map((consumableMonthObject) => - consumableMonthObject.quantity_in!) - .toList(); - _consumableItemQuantityOutForYear = - _fetchedConsumableYearlySummaryData - .map((consumableMonthObject) => - consumableMonthObject.quantity_out!) - .toList(); - - setState(() { - _fetchedConsumableYearlySummaryData; - _selectedConsumableValue = newValue; - _consumableItemQuantityInForYear; - _consumableItemQuantityOutForYear; - }); - }); - }), - const SizedBox( - width: 20.0, - ), - Text( - 'Select a Year:', + SizedBox( + width: 20.0, + ), + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [], + ), + SizedBox( + width: 5, + ), + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [], + ), + ], + ), + const SizedBox( + height: 15.0, + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Center( + child: Text( + 'Unit - ${_selectedConsumableUnitValue ?? ''}', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + ), + SizedBox( + width: 20, + ), + Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + SizedBox( + width: 70.0, + height: 30.0, + child: Padding( + padding: const EdgeInsets.only(top: 5.0), + child: Text( + 'Quantity In', style: TextStyle( - fontStyle: FontStyle.normal, - fontWeight: FontWeight.bold), - ), - SizedBox( - width: 5, - ), - TextButton( - onPressed: () => _showPicker(context), - child: Icon(Icons.calendar_month), - ), - if (_selectedYear == null) - Container( - margin: EdgeInsets.only(left: 10.0), - child: const Text( - 'No year selected.', - style: TextStyle( - fontSize: 14, - fontWeight: FontWeight.normal, - ), - ), - ) - else - Container( - child: Text( - _selectedYear.year.toString(), - style: TextStyle( - fontSize: 14, fontWeight: FontWeight.normal), - ), + fontSize: 14, + fontWeight: FontWeight.normal, ), - SizedBox( - width: 20.0, - ), - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - width: 70.0, - height: 30.0, - child: Text( - 'Quantity In', - style: TextStyle( - fontSize: 14, - fontWeight: FontWeight.normal, - ), - ), - ), - SizedBox( - width: 5, - ), - SizedBox( - child: Container( - width: 20, - height: 20, - color: Colors.green, - ), - ), - ], - ), - SizedBox( - width: 5, - ), - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox( - width: 80.0, - height: 30.0, - child: Text( - 'Quantity Out', - style: TextStyle( - fontSize: 14, - fontWeight: FontWeight.normal, - ), - ), - ), - SizedBox( - width: 5, - ), - SizedBox( - child: Container( - width: 20, - height: 20, - color: Colors.red, - ), - ), - ], ), - ], + ), ), - ), - const SizedBox( - height: 5.0, - ), - Center( - child: Text( - 'Unit - ${_selectedConsumableUnitValue ?? ''}', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, + SizedBox( + width: 5, + ), + SizedBox( + child: Container( + width: 20, + height: 20, + color: Colors.green, ), ), - ), - const SizedBox( - height: 20.0, - ), - if (_consumableItemQuantityInForYear.length > 0 && - _consumableItemQuantityOutForYear.length > 0) - Flexible( - flex: 3, - child: BarChart( - BarChartData( - groupsSpace: 30.0, - alignment: BarChartAlignment.spaceAround, - barGroups: _getBarGroups(), - titlesData: FlTitlesData( - show: true, - topTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false)), - bottomTitles: AxisTitles( - sideTitles: SideTitles( - getTitlesWidget: getTitles, - showTitles: true, - reservedSize: 50))), - gridData: FlGridData( - show: true, - drawHorizontalLine: true, - drawVerticalLine: false), + ], + ), + SizedBox( + width: 15.0, + ), + Padding( + padding: const EdgeInsets.only(top: 8.0), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + width: 80.0, + height: 30.0, + child: Text( + 'Quantity Out', + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.normal, + ), ), ), - ) - else - Container( - margin: EdgeInsets.only(left: 10.0), - child: const Text( - 'No data', - style: TextStyle( - fontSize: 14, - fontWeight: FontWeight.normal, + SizedBox( + width: 5, + ), + SizedBox( + child: Container( + width: 20, + height: 20, + color: Colors.red, ), ), - ) - ], + ], + ), + ), + ], + ), + const SizedBox( + height: 20.0, + ), + if (_consumableItemQuantityInForYear.length > 0 && + _consumableItemQuantityOutForYear.length > 0) + Container( + height: screenHeight * 0.5, + child: BarChart( + BarChartData( + groupsSpace: 30.0, + alignment: BarChartAlignment.spaceAround, + barGroups: _getBarGroups(), + titlesData: FlTitlesData( + show: true, + rightTitles: + AxisTitles(sideTitles: SideTitles(showTitles: false)), + topTitles: + AxisTitles(sideTitles: SideTitles(showTitles: false)), + bottomTitles: AxisTitles( + sideTitles: SideTitles( + getTitlesWidget: getTitles, + showTitles: true, + reservedSize: 50))), + gridData: FlGridData( + show: true, + drawHorizontalLine: true, + drawVerticalLine: false), + ), + ), + ) + else + Container( + margin: EdgeInsets.only(left: 10.0), + child: const Text( + 'No data', + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.normal, + ), + ), ), + ], ); + // ); } } diff --git a/campus/frontend/lib/avinya/asset_admin/lib/widgets/consumable_dashboard.dart b/campus/frontend/lib/avinya/asset_admin/lib/widgets/consumable_dashboard.dart index e964804..ec53f7a 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/widgets/consumable_dashboard.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/widgets/consumable_dashboard.dart @@ -14,24 +14,38 @@ class ConsumableDashboard extends StatefulWidget { class _ConsumableDashboardState extends State { @override Widget build(BuildContext context) { - return Row( - children: [ - Flexible( - flex: 2, - child: Padding( - padding: const EdgeInsets.only(left: 20, top: 25.0), - child: LatestConsumableData(), - ), - ), - Flexible( - flex: 3, + var screenWidth = MediaQuery.of(context).size.width; + var screenHeight = MediaQuery.of(context).size.height; + + return Container( + color: Colors.grey[200], + child: Row( + children: [ + Flexible( + flex: 2, child: Padding( padding: const EdgeInsets.only(left: 20, top: 25.0), - child: SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: ConsumableBarChart()), - )) - ], + child: Container( + decoration: + BoxDecoration(borderRadius: BorderRadius.circular(5.0)), + // color: Colors.white, + child: LatestConsumableData()), + ), + ), + Flexible( + flex: 3, + child: Padding( + padding: const EdgeInsets.only(left: 15, top: 25.0, right: 5.0), + child: Container( + decoration: + BoxDecoration(borderRadius: BorderRadius.circular(5.0)), + //color: Colors.white, + width: screenWidth * 0.8, + height: screenHeight * 0.8, + child: ConsumableBarChart()), + )) + ], + ), ); } } diff --git a/campus/frontend/lib/avinya/asset_admin/lib/widgets/latest_consumable_data.dart b/campus/frontend/lib/avinya/asset_admin/lib/widgets/latest_consumable_data.dart index 4d57172..1089280 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/widgets/latest_consumable_data.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/widgets/latest_consumable_data.dart @@ -14,7 +14,6 @@ class LatestConsumableData extends StatefulWidget { } class _LatestConsumableDataState extends State { - List _fetchedLatestConsumableData = []; bool _isFetching = false; DateTime? _selected; @@ -33,8 +32,7 @@ class _LatestConsumableDataState extends State { @override void didChangeDependencies() { super.didChangeDependencies(); - _data = MyData(_fetchedLatestConsumableData,isQuantityBelowThreshold, - getThresholdValue); + _data = MyData(_fetchedLatestConsumableData); } Future _fetchInitialData() async { @@ -45,14 +43,13 @@ class _LatestConsumableDataState extends State { _isFetching = true; // Show loading indicator }); try { - _fetchedLatestConsumableData = await getStockListforReplenishment(parentOrgId, - DateFormat('yyyy-MM-dd').format(DateTime.now())); + _fetchedLatestConsumableData = await getStockListforReplenishment( + parentOrgId, DateFormat('yyyy-MM-dd').format(DateTime.now())); - setState(() { - _isFetching = false; - _data = MyData(_fetchedLatestConsumableData, isQuantityBelowThreshold, - getThresholdValue); - }); + setState(() { + _isFetching = false; + _data = MyData(_fetchedLatestConsumableData); + }); } catch (error) { // Handle any errors that occur during the fetch // You can show an error message or take appropriate actions here @@ -64,164 +61,114 @@ class _LatestConsumableDataState extends State { } } - bool isQuantityBelowThreshold(String unit,double quantity){ - - const Map thresholds = { - 'kg': 2.0, - 'g': 500.0, - 'packet': 2.0, - 'cup': 10.0, - 'bags': 10.0, - 'rolls': 1.0, - 'litre': 2.0, - 'ml': 100.0, - 'piece': 20.0, - }; - - if(thresholds.containsKey(unit)){ - return quantity < thresholds[unit]!; - } - return false; - } - - double getThresholdValue(String unit){ - - const Map thresholds = { - 'kg': 2.0, - 'g': 500.0, - 'packet': 2.0, - 'cup': 10.0, - 'bags': 10.0, - 'rolls': 1.0, - 'litre': 2.0, - 'ml': 100.0, - 'piece': 20.0, - }; - - return thresholds.containsKey(unit) ? thresholds[unit]! : 0.0; - } - List _buildDataColumns() { List columnNames = []; columnNames.add(DataColumn( label: Center( - child: Text('Product Name', - style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)), - ))); - - columnNames.add(DataColumn( - label: Center( - child: Text('On Hand(QTY)', - style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)), - ))); + child: Text('Product Name', + textAlign: TextAlign.center, + style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)), + ))); columnNames.add(DataColumn( label: Center( - child: Text('Unit', - style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)), - ))); + child: Text('On Hand(QTY)', + textAlign: TextAlign.center, + style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)), + ))); columnNames.add(DataColumn( label: Center( - child: Text('Threshold', + child: Text('Unit', + textAlign: TextAlign.center, style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold)), - ))); + ))); return columnNames; } @override Widget build(BuildContext context) { + var screenWidth = MediaQuery.of(context).size.width; + var screenHeight = MediaQuery.of(context).size.height; + return SingleChildScrollView( child: Wrap(children: [ - Center( - child: Text( - 'Latest Consumable Data', - style: TextStyle( - fontSize: 24, - fontWeight: FontWeight.bold, - color: Colors.purple, - ), - ), - ), - if (_isFetching) - Container( - margin: EdgeInsets.only(top: 180), - child: SpinKitCircle( - color: (Colors - .yellow[700]), - size: 50, - ), - ) - else if (_fetchedLatestConsumableData.length > 0) - Container( - margin: EdgeInsets.only(left: 10.0, top: 20.0), - child: ScrollConfiguration( - behavior: ScrollConfiguration.of(context) - .copyWith(dragDevices: { - PointerDeviceKind.touch, - PointerDeviceKind.mouse, - }), - child: PaginatedDataTable( - showCheckboxColumn: false, - source: _data, - columns: _buildDataColumns(), - columnSpacing:35, - horizontalMargin: 30, - rowsPerPage: 10, - ), - ), - ) - else - Container( - margin: EdgeInsets.all(20), - child: Text('No latest consumable data found'), - ), - ]), + Center( + child: Text( + 'Latest Consumable Data', + style: TextStyle( + fontSize: 24, + fontWeight: FontWeight.bold, + ), + ), + ), + if (_isFetching) + Container( + margin: EdgeInsets.only(top: 180), + child: SpinKitCircle( + color: (Colors.yellow[700]), + size: 50, + ), + ) + else if (_fetchedLatestConsumableData.length > 0) + Container( + margin: EdgeInsets.only(left: 10.0, top: 20.0), + child: ScrollConfiguration( + behavior: ScrollConfiguration.of(context).copyWith(dragDevices: { + PointerDeviceKind.touch, + PointerDeviceKind.mouse, + }), + child: Container( + width: screenWidth * 0.95, + height: screenHeight * 1.2, + child: PaginatedDataTable( + showCheckboxColumn: false, + source: _data, + columns: _buildDataColumns(), + columnSpacing: 50, + rowsPerPage: 10, + ), + ), + ), + ) + else + Container( + margin: EdgeInsets.all(20), + child: Text('No latest consumable data found'), + ), + ]), ); } } class MyData extends DataTableSource { - MyData(this._fetchedLatestConsumableData,this.isQuantityBelowThreshold,this.getThresholdValue); + MyData(this._fetchedLatestConsumableData); final List _fetchedLatestConsumableData; - final Function(String,double) isQuantityBelowThreshold; - final Function(String) getThresholdValue; @override DataRow? getRow(int index) { - var consumableItem = _fetchedLatestConsumableData[index]; - bool isBelowThreshold = isQuantityBelowThreshold( - consumableItem.resource_property!.value.toString(), - consumableItem.quantity! - ); - - double threshold = getThresholdValue(consumableItem.resource_property!.value!); - - List cells = List.filled(4, DataCell.empty); - - cells[0] = DataCell(Center( - child: Text(consumableItem.consumable!.name.toString()))); - cells[1] = DataCell( - Center(child: Text(consumableItem.quantity.toString()))); - cells[2] = - DataCell( - Center(child: Text(consumableItem.resource_property!.value.toString()))); - cells[3] = - DataCell( - Center(child: Text(threshold.toString()))); - + List cells = List.filled(3, DataCell.empty); + + cells[0] = DataCell( + Center(child: Text(consumableItem.consumable!.name.toString()))); + cells[1] = + DataCell(Center(child: Text(consumableItem.quantity.toString()))); + cells[2] = DataCell(Center( + child: Text(consumableItem.resource_property!.value.toString()))); return DataRow( - color: MaterialStateProperty.resolveWith((Set states){ - return isBelowThreshold ?Colors.red[300]:null; - }), - cells: cells - ); + color: MaterialStateProperty.resolveWith( + (Set states) { + return consumableItem.is_below_threshold == 1 + ? Colors.red[300] + : null; + }), + cells: cells); } @override diff --git a/campus/frontend/lib/avinya/asset_admin/lib/widgets/vehicle_fuel_consumption_monthly_report.dart b/campus/frontend/lib/avinya/asset_admin/lib/widgets/vehicle_fuel_consumption_monthly_report.dart new file mode 100644 index 0000000..1f5fc90 --- /dev/null +++ b/campus/frontend/lib/avinya/asset_admin/lib/widgets/vehicle_fuel_consumption_monthly_report.dart @@ -0,0 +1,17 @@ +import 'package:flutter/material.dart'; + +class VehicleFuelConsumptionMonthlyReport extends StatefulWidget { + const VehicleFuelConsumptionMonthlyReport({super.key}); + + @override + State createState() => _VehicleFuelConsumptionMonthlyReportState(); +} + +class _VehicleFuelConsumptionMonthlyReportState extends State { + @override + Widget build(BuildContext context) { + return Text( + 'VehicleFuelConsumptionMonthlyReport' + ); + } +} \ No newline at end of file From 94fac776954f41ea94f0749d7e6e4de4249f1cba Mon Sep 17 00:00:00 2001 From: YujithIsura Date: Tue, 13 Aug 2024 14:57:54 +0530 Subject: [PATCH 6/7] asset config file changed. flutter version updated in prod --- .../main_avinyawebapp-production.yml | 16 ++-- .../avinya/asset_admin/assets/config/dev.json | 3 - .../asset_admin/lib/config/app_config.dart | 42 ---------- .../avinya/asset_admin/lib/data/address.dart | 3 +- .../asset_admin/lib/data/address_type.dart | 3 +- .../lib/data/applicant_consent.dart | 3 +- .../asset_admin/lib/data/application.dart | 3 +- .../avinya/asset_admin/lib/data/asset.dart | 3 +- .../asset_admin/lib/data/avinya_type.dart | 3 +- .../asset_admin/lib/data/consumable.dart | 3 +- .../avinya/asset_admin/lib/data/employee.dart | 3 +- .../asset_admin/lib/data/evaluation.dart | 3 +- .../lib/data/evaluation_criteria.dart | 3 +- .../evaluation_criteria_answer_option.dart | 3 +- .../asset_admin/lib/data/inventory.dart | 3 +- .../asset_admin/lib/data/organization.dart | 19 ++--- .../avinya/asset_admin/lib/data/person.dart | 6 +- .../avinya/asset_admin/lib/data/prospect.dart | 3 +- .../lib/data/resource_allocation.dart | 77 +++++++++---------- .../avinya/asset_admin/lib/data/supplier.dart | 3 +- .../avinya/asset_admin/lib/data/supply.dart | 3 +- .../avinya/asset_admin/lib/screens/apply.dart | 2 +- .../lib/screens/preconditions.dart | 2 +- .../asset_admin/lib/screens/subscribe.dart | 3 +- campus/frontend/lib/config/app_config.dart | 2 + 25 files changed, 74 insertions(+), 143 deletions(-) delete mode 100644 campus/frontend/lib/avinya/asset_admin/assets/config/dev.json delete mode 100644 campus/frontend/lib/avinya/asset_admin/lib/config/app_config.dart diff --git a/.github/workflows/main_avinyawebapp-production.yml b/.github/workflows/main_avinyawebapp-production.yml index 61fd64f..d417fcf 100644 --- a/.github/workflows/main_avinyawebapp-production.yml +++ b/.github/workflows/main_avinyawebapp-production.yml @@ -21,13 +21,13 @@ jobs: uses: subosito/flutter-action@v2 with: channel: stable - flutter-version: '3.16.8' + flutter-version: "3.13.1" - run: flutter doctor -v - name: Set up Node.js version uses: actions/setup-node@v1 with: - node-version: '16.x' + node-version: "16.x" - run: npm install -g firebase-tools@11.0.1 # Get dependencies and build Flutter web app @@ -37,7 +37,7 @@ jobs: flutter clean flutter pub outdated flutter pub get - + - name: Build Flutter app run: | cd campus/frontend @@ -53,7 +53,7 @@ jobs: - name: Move Flutter build contents to node-app artifact run: | cp -R campus/frontend/build/web/* campus/deployment/node-app/public-flutter - + - name: npm install, build, and test run: | cd campus/deployment/node-app @@ -71,7 +71,7 @@ jobs: runs-on: ubuntu-latest needs: build environment: - name: 'Production' + name: "Production" url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} steps: @@ -80,11 +80,11 @@ jobs: with: name: node-app - - name: 'Deploy to Azure Web App' + - name: "Deploy to Azure Web App" id: deploy-to-webapp uses: azure/webapps-deploy@v2 with: - app-name: 'avinyawebapp-production' - slot-name: 'Production' + app-name: "avinyawebapp-production" + slot-name: "Production" publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_87F56F6F4C724B4E91DFBC9BEF075487 }} package: . diff --git a/campus/frontend/lib/avinya/asset_admin/assets/config/dev.json b/campus/frontend/lib/avinya/asset_admin/assets/config/dev.json deleted file mode 100644 index a86af7a..0000000 --- a/campus/frontend/lib/avinya/asset_admin/assets/config/dev.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "campusAssetBffApiUrl": "http://localhost:9090" -} diff --git a/campus/frontend/lib/avinya/asset_admin/lib/config/app_config.dart b/campus/frontend/lib/avinya/asset_admin/lib/config/app_config.dart deleted file mode 100644 index 058abd3..0000000 --- a/campus/frontend/lib/avinya/asset_admin/lib/config/app_config.dart +++ /dev/null @@ -1,42 +0,0 @@ -import 'dart:convert'; - -import 'package:flutter/services.dart'; - -class AppConfig { - static String apiUrl = 'http://localhost:8080'; - static String campusAssetBffApiUrl = 'http://localhost:9094'; - static String campusConfigBffApiKey = ''; - static String choreoSTSEndpoint = "https://sts.choreo.dev/oauth2/token"; - static String choreoSTSClientID = ""; - static String asgardeoTokenEndpoint = - "https://api.asgardeo.io/t/avinyafoundation/oauth2/token"; - static String asgardeoClientId = ""; - static var apiTokens = null; - static String applicationName = 'Avinya Academy Campus - Assets Portal'; - static String applicationVersion = '0.1.0'; - - //AppConfig({required this.apiUrl}); - - static Future forEnvironment(String env) async { - // load the json file - String contents = "{}"; - try { - contents = await rootBundle.loadString( - 'assets/config/$env.json', - ); - } catch (e) { - print(e); - } - - // decode our json - final json = jsonDecode(contents); - campusAssetBffApiUrl = json['campusAssetBffApiUrl']; - - // convert our JSON into an instance of our AppConfig class - return AppConfig(); - } - - String getApiUrl() { - return apiUrl; - } -} diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/address.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/address.dart index 1828b7f..f63ce4e 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/address.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/address.dart @@ -1,10 +1,9 @@ import 'dart:developer'; +import 'package:gallery/config/app_config.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import '../config/app_config.dart'; - class Address { String? record_type; int? id; diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/address_type.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/address_type.dart index fd7f16a..5fc5aa5 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/address_type.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/address_type.dart @@ -1,8 +1,7 @@ +import 'package:gallery/config/app_config.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import '../config/app_config.dart'; - class AddressType { int? id; String? name; diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/applicant_consent.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/applicant_consent.dart index 1e56aa9..4d1dcef 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/applicant_consent.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/applicant_consent.dart @@ -1,8 +1,7 @@ +import 'package:gallery/config/app_config.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import '../config/app_config.dart'; - class ApplicantConsent { int? id; String? date_of_birth; diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/application.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/application.dart index 1fb0219..a8505ad 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/application.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/application.dart @@ -1,8 +1,7 @@ +import 'package:gallery/config/app_config.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import '../config/app_config.dart'; - class ApplicationStatus { int? id; int? application_id; diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/asset.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/asset.dart index a7c1c6e..bcd0225 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/asset.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/asset.dart @@ -1,10 +1,9 @@ //import 'package:ShoolManagementSystem/src/data/avinya_type.dart'; import 'package:gallery/avinya/asset_admin/lib/data.dart'; +import 'package:gallery/config/app_config.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import '../config/app_config.dart'; - class Asset { int? id; String? name; diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/avinya_type.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/avinya_type.dart index f9c6607..47f1c29 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/avinya_type.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/avinya_type.dart @@ -1,8 +1,7 @@ +import 'package:gallery/config/app_config.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import '../config/app_config.dart'; - class AvinyaType { int? id; bool? active; diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/consumable.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/consumable.dart index da95010..cb60cc9 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/consumable.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/consumable.dart @@ -1,8 +1,7 @@ +import 'package:gallery/config/app_config.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import '../config/app_config.dart'; - class Consumable { int? id; String? name; diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/employee.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/employee.dart index 48927ac..def70b9 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/employee.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/employee.dart @@ -1,8 +1,7 @@ +import 'package:gallery/config/app_config.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import '../config/app_config.dart'; - class Employee { final int employee_id; final String first_name; diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/evaluation.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/evaluation.dart index fc5d94f..48016f7 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/evaluation.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/evaluation.dart @@ -1,8 +1,7 @@ +import 'package:gallery/config/app_config.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import '../config/app_config.dart'; - class Evaluation { int? id; int? evaluatee_id; diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/evaluation_criteria.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/evaluation_criteria.dart index 2e69a33..5945e9a 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/evaluation_criteria.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/evaluation_criteria.dart @@ -1,7 +1,6 @@ +import 'package:gallery/config/app_config.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; - -import '../config/app_config.dart'; import 'evaluation_criteria_answer_option.dart'; class EvaluationCriteria { diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/evaluation_criteria_answer_option.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/evaluation_criteria_answer_option.dart index 36de447..f37d3c6 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/evaluation_criteria_answer_option.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/evaluation_criteria_answer_option.dart @@ -1,8 +1,7 @@ +import 'package:gallery/config/app_config.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import '../config/app_config.dart'; - class EvaluationCriteriaAnswerOption { int? id; int? evaluation_criteria_id; diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/inventory.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/inventory.dart index d31089c..77eb1ba 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/inventory.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/inventory.dart @@ -1,8 +1,7 @@ +import 'package:gallery/config/app_config.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import '../config/app_config.dart'; - class Inventory { int? id; int? asset_id; diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/organization.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/organization.dart index dd45182..5f7fe1d 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/organization.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/organization.dart @@ -2,12 +2,11 @@ import 'dart:developer'; import 'package:flutter/src/material/data_table.dart'; import 'package:gallery/avinya/attendance/lib/data.dart'; +import 'package:gallery/config/app_config.dart'; import 'package:gallery/data/address.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import '../config/app_config.dart'; - class Name { String? name_en; String? name_si; @@ -85,15 +84,15 @@ class Organization { 'people': List.from(people.map((x) => x.toJson())), // if (employees != null) 'employees': List.from(employees!.map((x) => x.toJson())), }; - - } -Future> fetchOrganizationsByAvinyaType(int avinya_type) async { - final uri = Uri.parse(AppConfig.campusAssetBffApiUrl + '/organizations_by_avinya_type') +Future> fetchOrganizationsByAvinyaType( + int avinya_type) async { + final uri = Uri.parse( + AppConfig.campusAssetBffApiUrl + '/organizations_by_avinya_type') .replace(queryParameters: {'avinya_type': avinya_type.toString()}); - final response = await http.get( + final response = await http.get( uri, headers: { 'Content-Type': 'application/json; charset=UTF-8', @@ -103,11 +102,9 @@ Future> fetchOrganizationsByAvinyaType(int avinya_type) async ); if (response.statusCode == 200) { - var resultsJson = json.decode(response.body).cast>(); - List organization = - await resultsJson + List organization = await resultsJson .map((json) => Organization.fromJson(json)) .toList(); @@ -116,5 +113,3 @@ Future> fetchOrganizationsByAvinyaType(int avinya_type) async throw Exception('Failed to load organizations'); } } - - diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/person.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/person.dart index 1c58170..c62603e 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/person.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/person.dart @@ -2,11 +2,10 @@ import 'dart:developer'; //import 'package:ShoolManagementSystem/src/data/address.dart'; import 'package:gallery/avinya/asset/lib/data/address.dart'; +import 'package:gallery/config/app_config.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import '../config/app_config.dart'; - class Person { int? id; String? record_type; @@ -97,8 +96,7 @@ class Person { if (passport_no != null) 'passport_no': passport_no, if (permanent_address_id != null) 'permanent_address_id': permanent_address_id, - if(digital_id !=null) - 'digital_id' : digital_id, + if (digital_id != null) 'digital_id': digital_id, if (mailing_address_id != null) 'mailing_address_id': mailing_address_id, if (nic_no != null) 'nic_no': nic_no, diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/prospect.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/prospect.dart index 84e8fde..553cca6 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/prospect.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/prospect.dart @@ -1,8 +1,7 @@ +import 'package:gallery/config/app_config.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import '../config/app_config.dart'; - class Prospect { int? id; String? created; diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/resource_allocation.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/resource_allocation.dart index f7f41f1..e83eadf 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/resource_allocation.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/resource_allocation.dart @@ -1,8 +1,7 @@ import 'dart:developer'; +import 'package:gallery/config/app_config.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; - -import '../config/app_config.dart'; import '../data.dart'; class ResourceAllocation { @@ -31,32 +30,31 @@ class ResourceAllocation { this.consumable, this.organization, this.person, - this.resource_properties = const[], + this.resource_properties = const [], }); factory ResourceAllocation.fromJson(Map json) { return ResourceAllocation( - id: json['id'], - startDate: json['start_date'] != null - ? DateTime.parse(json['start_date']) - : null, - endDate: - json['end_date'] != null ? DateTime.parse(json['end_date']) : null, - quantity: json['quantity'], - requested: json['requested'], - approved: json['approved'], - allocated: json['allocated'], - asset: json['asset'] != null ? Asset.fromJson(json['asset']) : null, - consumable: json['consumable'], - organization: json['organization'] != null - ? Organization.fromJson(json['organization']) - : null, - person: json['person'] != null ? Person.fromJson(json['person']) : null, - resource_properties: json['resource_properties'] !=null - ? List.from( - json['resource_properties'].map((x)=>ResourceProperty.fromJson(x))) - :[] - ); + id: json['id'], + startDate: json['start_date'] != null + ? DateTime.parse(json['start_date']) + : null, + endDate: + json['end_date'] != null ? DateTime.parse(json['end_date']) : null, + quantity: json['quantity'], + requested: json['requested'], + approved: json['approved'], + allocated: json['allocated'], + asset: json['asset'] != null ? Asset.fromJson(json['asset']) : null, + consumable: json['consumable'], + organization: json['organization'] != null + ? Organization.fromJson(json['organization']) + : null, + person: json['person'] != null ? Person.fromJson(json['person']) : null, + resource_properties: json['resource_properties'] != null + ? List.from(json['resource_properties'] + .map((x) => ResourceProperty.fromJson(x))) + : []); } Map toJson() => { @@ -71,7 +69,8 @@ class ResourceAllocation { if (consumable != null) 'consumable': consumable, if (organization != null) 'organization': organization, if (person != null) 'person': person, - if(resource_properties != null) 'resource_properties' : resource_properties, + if (resource_properties != null) + 'resource_properties': resource_properties, }; } @@ -170,22 +169,21 @@ Future fetchAssetByAvinyaType(int id) async { } } -Future> getResourceAllocationReport(int organization_id,int avinya_type_id) async{ - - final response = await http.get( - Uri.parse( - '${AppConfig.campusAssetBffApiUrl}/resource_allocations_report/$organization_id/$avinya_type_id'), - headers: { - 'Content-Type': 'application/json; charset=UTF-8', - 'accept': 'application/json', - 'Authorization': 'Bearer ${AppConfig.campusConfigBffApiKey}', +Future> getResourceAllocationReport( + int organization_id, int avinya_type_id) async { + final response = await http.get( + Uri.parse( + '${AppConfig.campusAssetBffApiUrl}/resource_allocations_report/$organization_id/$avinya_type_id'), + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + 'accept': 'application/json', + 'Authorization': 'Bearer ${AppConfig.campusConfigBffApiKey}', }, - ); - if(response.statusCode > 199 && response.statusCode < 300 ){ - - var resultsJson = json.decode(response.body).cast>(); + ); + if (response.statusCode > 199 && response.statusCode < 300) { + var resultsJson = json.decode(response.body).cast>(); List resourceAllocations = await resultsJson - .map((json) => ResourceAllocation.fromJson(json)) + .map((json) => ResourceAllocation.fromJson(json)) .toList(); print("Resource Allocations report" + "$resourceAllocations"); return resourceAllocations; @@ -193,7 +191,6 @@ Future> getResourceAllocationReport(int organization_id throw Exception( 'Failed to get Resource Allocations report for organization ID $organization_id and avinya type ID $avinya_type_id for result limit.'); } - } diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/supplier.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/supplier.dart index d867423..1104e74 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/supplier.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/supplier.dart @@ -1,8 +1,7 @@ +import 'package:gallery/config/app_config.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import '../config/app_config.dart'; - class Supplier { int? id; String? name; diff --git a/campus/frontend/lib/avinya/asset_admin/lib/data/supply.dart b/campus/frontend/lib/avinya/asset_admin/lib/data/supply.dart index 0b09fb5..9af3cd0 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/data/supply.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/data/supply.dart @@ -1,8 +1,7 @@ +import 'package:gallery/config/app_config.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import '../config/app_config.dart'; - class Supply { int? id; int? asset_id; diff --git a/campus/frontend/lib/avinya/asset_admin/lib/screens/apply.dart b/campus/frontend/lib/avinya/asset_admin/lib/screens/apply.dart index 05983be..0e5e27c 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/screens/apply.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/screens/apply.dart @@ -9,9 +9,9 @@ import 'package:flutter/services.dart'; import 'package:email_validator/email_validator.dart'; import 'package:gallery/avinya/asset_admin/lib/data.dart'; import 'package:gallery/avinya/asset_admin/lib/data/address.dart'; +import 'package:gallery/config/app_config.dart'; import 'package:mask_text_input_formatter/mask_text_input_formatter.dart'; import 'package:url_launcher/url_launcher.dart'; -import '../config/app_config.dart'; import '../routing.dart'; class CityNearBandaragama { diff --git a/campus/frontend/lib/avinya/asset_admin/lib/screens/preconditions.dart b/campus/frontend/lib/avinya/asset_admin/lib/screens/preconditions.dart index 82bdc15..f65d730 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/screens/preconditions.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/screens/preconditions.dart @@ -1,5 +1,6 @@ import 'dart:developer'; import 'package:flutter/gestures.dart'; +import 'package:gallery/config/app_config.dart'; import 'package:intl/intl.dart'; // import 'package:ShoolManagementSystem/src/data.dart'; // import 'package:ShoolManagementSystem/src/data/applicant_consent.dart'; @@ -12,7 +13,6 @@ import 'package:mask_text_input_formatter/mask_text_input_formatter.dart'; import 'package:url_launcher/url_launcher.dart'; import '../../../asset/lib/data/campus_config_system.dart'; import '../../../asset/lib/data/applicant_consent.dart'; -import '../config/app_config.dart'; import '../routing.dart'; class PreconditionsScreen extends StatefulWidget { diff --git a/campus/frontend/lib/avinya/asset_admin/lib/screens/subscribe.dart b/campus/frontend/lib/avinya/asset_admin/lib/screens/subscribe.dart index 2d0e72a..b91a168 100644 --- a/campus/frontend/lib/avinya/asset_admin/lib/screens/subscribe.dart +++ b/campus/frontend/lib/avinya/asset_admin/lib/screens/subscribe.dart @@ -8,10 +8,10 @@ import 'package:email_validator/email_validator.dart'; import 'package:flutter/services.dart'; import 'package:gallery/avinya/asset/lib/data/campus_config_system.dart'; import 'package:gallery/avinya/asset/lib/data/prospect.dart'; +import 'package:gallery/config/app_config.dart'; import 'package:intl/intl.dart'; import 'package:mask_text_input_formatter/mask_text_input_formatter.dart'; import 'package:url_launcher/url_launcher.dart'; -import '../config/app_config.dart'; import '../routing.dart'; class SubscribeScreen extends StatefulWidget { @@ -478,7 +478,6 @@ class _SubscribeScreenState extends State { log(createProspectResponse.body.toString()); return true; //Navigator.of(context).pop(true); - } else { log('addProspect form invalid'); return false; diff --git a/campus/frontend/lib/config/app_config.dart b/campus/frontend/lib/config/app_config.dart index cf19082..875b7fa 100644 --- a/campus/frontend/lib/config/app_config.dart +++ b/campus/frontend/lib/config/app_config.dart @@ -6,7 +6,9 @@ class AppConfig { static String apiUrl = ''; static String campusAttendanceBffApiUrl = ''; static String campusProfileBffApiUrl = ''; + static String campusAssetBffApiUrl = ''; static String campusBffApiKey = ''; + static String campusConfigBffApiKey = ''; static String refreshToken = ''; static String choreoSTSEndpoint = ""; static String choreoSTSClientID = "x23_1tY7kAUtLUH9il9I3YwyrJca"; From 1635caec60bf70a125956e9b3c0b4f64816bca25 Mon Sep 17 00:00:00 2001 From: YujithIsura Date: Tue, 13 Aug 2024 15:11:43 +0530 Subject: [PATCH 7/7] sebug log removed --- campus/bffs/asset/api/service.bal | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/campus/bffs/asset/api/service.bal b/campus/bffs/asset/api/service.bal index 327dc27..e63dd1c 100644 --- a/campus/bffs/asset/api/service.bal +++ b/campus/bffs/asset/api/service.bal @@ -13,13 +13,13 @@ public function initClientConfig() returns ConnectionConfig { } else { _clientConig = {}; } - log:printDebug("debug log"); - log:printError("error log"); - log:printInfo("info log"); - log:printWarn("warn log"); - log:printInfo("CHOREO_TOKEN_URL: " + CHOREO_TOKEN_URL); - log:printInfo("GLOBAL_DATA_CLIENT_ID: " + GLOBAL_DATA_CLIENT_ID); - log:printInfo("GLOBAL_DATA_CLIENT_SECRET: " + GLOBAL_DATA_CLIENT_SECRET); + // log:printDebug("debug log"); + // log:printError("error log"); + // log:printInfo("info log"); + // log:printWarn("warn log"); + // log:printInfo("CHOREO_TOKEN_URL: " + CHOREO_TOKEN_URL); + // log:printInfo("GLOBAL_DATA_CLIENT_ID: " + GLOBAL_DATA_CLIENT_ID); + // log:printInfo("GLOBAL_DATA_CLIENT_SECRET: " + GLOBAL_DATA_CLIENT_SECRET); return _clientConig; } @@ -861,7 +861,7 @@ service / on new http:Listener(9094) { } resource function get consumable_yearly_report/[int organization_id]/[int consumable_id]/[int year]() returns Inventory[]|error { - GetConsumableYearlyReportResponse|graphql:ClientError getConsumableYearlyReportResponse = globalDataClient->getConsumableYearlyReport(consumable_id,year,organization_id); + GetConsumableYearlyReportResponse|graphql:ClientError getConsumableYearlyReportResponse = globalDataClient->getConsumableYearlyReport(consumable_id, year, organization_id); if (getConsumableYearlyReportResponse is GetConsumableYearlyReportResponse) { Inventory[] yearly_summary_consumable_datas = []; foreach var yearly_summary_consumable_data in getConsumableYearlyReportResponse.consumable_yearly_report {