Skip to content

Commit

Permalink
Merge pull request #366 from lahirulakruwan/main
Browse files Browse the repository at this point in the history
Consumable get by organization bff changes added
  • Loading branch information
YujithIsura authored Jul 9, 2024
2 parents 85e734c + d5cc3b7 commit f7efe43
Show file tree
Hide file tree
Showing 14 changed files with 606 additions and 20 deletions.
6 changes: 3 additions & 3 deletions campus/bffs/asset/api/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ public isolated client class GraphqlClient {
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetAvinyaTypesResponse> 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 quantity quantity_in quantity_out resource_property {id property value}}}`;
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 resource_property {id property value}}}`;
map<anydata> variables = {"date": date, "organization_id": organization_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetInventoryDataByOrganizationResponse> check performDataBinding(graphqlResponse, GetInventoryDataByOrganizationResponse);
return <GetInventoryDataByOrganizationResponse>check performDataBinding(graphqlResponse, GetInventoryDataByOrganizationResponse);
}

remote isolated function consumableReplenishment(int person_id,int organization_id,string date,Inventory[] inventories) returns json|graphql:ClientError {
Expand Down
4 changes: 4 additions & 0 deletions campus/bffs/asset/api/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,10 @@ public type GetInventoryDataByOrganizationResponse record {|
int? id;
int? avinya_type_id;
int? consumable_id;
record {|
int? id;
string? name;
|}? consumable;
anydata? quantity;
anydata? quantity_in;
anydata? quantity_out;
Expand Down
6 changes: 5 additions & 1 deletion campus/bffs/asset/graphql_client/asset.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -644,9 +644,13 @@ query getAvinyaTypes {

query getInventoryDataByOrganization($organization_id: Int!,$date: String!) {
inventory_data_by_organization(organization_id:$organization_id,date:$date) {
id
id
avinya_type_id
consumable_id
consumable{
id
name
}
quantity
quantity_in
quantity_out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public isolated client class GraphqlClient {
return <GetAvinyaTypesResponse> 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 quantity quantity_in quantity_out resource_property {id property value}}}`;
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 resource_property {id property value}}}`;
map<anydata> variables = {"date": date, "organization_id": organization_id};
json graphqlResponse = check self.graphqlClient->executeWithType(query, variables);
return <GetInventoryDataByOrganizationResponse> check performDataBinding(graphqlResponse, GetInventoryDataByOrganizationResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,10 @@ public type GetInventoryDataByOrganizationResponse record {|
int? id;
int? avinya_type_id;
int? consumable_id;
record {|
int? id;
string? name;
|}? consumable;
anydata? quantity;
anydata? quantity_in;
anydata? quantity_out;
Expand Down
6 changes: 6 additions & 0 deletions campus/frontend/lib/avinya/asset_admin/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class _AssetAdminSystemState extends State<AssetAdminSystem> {
'/consumable_dashboard',
'/stock_replenishment',
'/consumable_monthly_report',
'/consumable_weekly_report',
// '/assets/new',
// '/assets/all',
// '/assets/popular',
Expand Down Expand Up @@ -123,6 +124,9 @@ class _AssetAdminSystemState extends State<AssetAdminSystem> {

final consumableMonthlyReportRoute =
ParsedRoute('/consumable_monthly_report', '/consumable_monthly_report', {}, {});

final consumableWeeklyReportRoute = ParsedRoute(
'/consumable_weekly_report', '/consumable_weekly_report', {}, {});

// // Go to /apply if the user is not signed in
log("_guard signed in $signedIn");
Expand All @@ -139,6 +143,8 @@ class _AssetAdminSystemState extends State<AssetAdminSystem> {
return stockReplenishmentRoute;
} else if (signedIn && from == consumableMonthlyReportRoute){
return consumableMonthlyReportRoute;
} else if (signedIn && from == consumableWeeklyReportRoute) {
return consumableWeeklyReportRoute;
}
// Go to /application if the user is signed in and tries to go to /signin.
else if (signedIn && from == signInRoute) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,25 @@ Future<List<StockReplenishment>> getConsumableMonthlyReport(
throw Exception('Failed to get Consumable Monthly Summary Data');
}
}

Future<List<StockReplenishment>> getConsumableWeeklyReport(
int organization_id, String from_date, String to_date) async {
final response = await http.get(
Uri.parse(
'${AppConfig.campusAssetsBffApiUrl}/consumable_weekly_report/$organization_id/$from_date/$to_date'),
headers: <String, String>{
'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<Map<String, dynamic>>();
List<StockReplenishment> consumableWeeklySummaryData = await resultsJson
.map<StockReplenishment>((json) => StockReplenishment.fromJson(json))
.toList();
return consumableWeeklySummaryData;
} else {
throw Exception('Failed to get Consumable Weekly Summary Data');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@


import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import '../widgets/consumable_weekly_report.dart';

class ConsumableWeeklyReportScreen extends StatefulWidget {
const ConsumableWeeklyReportScreen({super.key});

@override
State<ConsumableWeeklyReportScreen> createState() => _ConsumableWeeklyReportScreenState();
}

class _ConsumableWeeklyReportScreenState extends State<ConsumableWeeklyReportScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: Text("Consumable Weekly Report"),
),
body: SingleChildScrollView(
child: Container(
child: ConsumableWeeklyReport(),
),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class _SMSScaffoldState extends State<SMSScaffold> {
];

consumableReportDestinations = [
SideNavigationSectionTile(
tileName: "Consumable Weekly Report",
route: "/consumable_weekly_report",
icon: Icons.summarize_outlined),
SideNavigationSectionTile(
tileName: "Consumable Monthly Report",
route: "/consumable_monthly_report",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:gallery/avinya/asset_admin/lib/screens/asset_dashboard_screen.da
import 'package:gallery/avinya/asset_admin/lib/screens/consumable_dashboard_screen.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/widgets/resource_allocation_report.dart';

import '../routing.dart';
Expand Down Expand Up @@ -55,6 +56,11 @@ class SMSScaffoldBody extends StatelessWidget {
key: ValueKey('consumable_monthly_report'),
child: ConsumableMonthlyReportScreen(),
)
else if (currentRoute.pathTemplate.startsWith('/consumable_weekly_report'))
const FadeTransitionPage<void>(
key: ValueKey('consumable_weekly_report'),
child: ConsumableWeeklyReportScreen(),
)
// Avoid building a Navigator with an empty `pages` list when the
// RouteState is set to an unexpected path, such as /signin.
//
Expand Down
52 changes: 52 additions & 0 deletions campus/frontend/lib/avinya/asset_admin/lib/utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2019 Aleksander Woźniak
// SPDX-License-Identifier: Apache-2.0

import 'dart:collection';

import 'package:table_calendar/table_calendar.dart';

/// Example event class.
class Event {
final String title;

const Event(this.title);

@override
String toString() => title;
}

/// Example events.
///
/// Using a [LinkedHashMap] is highly recommended if you decide to use a map.
final kEvents = LinkedHashMap<DateTime, List<Event>>(
equals: isSameDay,
hashCode: getHashCode,
)..addAll(_kEventSource);

final _kEventSource = Map.fromIterable(List.generate(50, (index) => index),
key: (item) => DateTime.utc(kFirstDay.year, kFirstDay.month, item * 5),
value: (item) => List.generate(
item % 4 + 1, (index) => Event('Event $item | ${index + 1}')))
..addAll({
kToday: [
Event('Today\'s Event 1'),
Event('Today\'s Event 2'),
],
});

int getHashCode(DateTime key) {
return key.day * 1000000 + key.month * 10000 + key.year;
}

/// Returns a list of [DateTime] objects from [first] to [last], inclusive.
List<DateTime> daysInRange(DateTime first, DateTime last) {
final dayCount = last.difference(first).inDays + 1;
return List.generate(
dayCount,
(index) => DateTime.utc(first.year, first.month, first.day + index),
);
}

final kToday = DateTime.now();
final kFirstDay = DateTime(kToday.year, kToday.month - 3, kToday.day);
final kLastDay = DateTime(kToday.year, kToday.month + 3, kToday.day);
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class _ConsumableMonthlyReportState extends State<ConsumableMonthlyReport> {
),
if (_selected == null)
Container(
margin: EdgeInsets.only(left: 10.0),
child: const Text(
'No month & year selected.',
style: TextStyle(
Expand All @@ -157,7 +158,7 @@ class _ConsumableMonthlyReportState extends State<ConsumableMonthlyReport> {
),
),
SizedBox(
height: 10,
height: 30,
),
Wrap(children: [
if (_isFetching)
Expand All @@ -170,7 +171,8 @@ class _ConsumableMonthlyReportState extends State<ConsumableMonthlyReport> {
),
)
else if (_fetchedConsumableMonthlySummaryData.length > 0)
Center(
Container(
margin: EdgeInsets.only(left: 10.0,top: 20.0),
child: ScrollConfiguration(
behavior:
ScrollConfiguration.of(context).copyWith(dragDevices: {
Expand Down Expand Up @@ -210,14 +212,7 @@ class MyData extends DataTableSource {

@override
DataRow? getRow(int index) {
if (index == 0) {

List<DataCell> cells = List<DataCell>.filled(
6, DataCell.empty);
return DataRow(
cells: cells,
);
}

if(_fetchedConsumableMonthlySummaryData.length > 0){

Expand All @@ -226,20 +221,20 @@ class MyData extends DataTableSource {

cells[0] = DataCell(Text(''));
cells[1] = DataCell(
Center(child: Text(_fetchedConsumableMonthlySummaryData[index - 1].consumable!.name.toString())));
Center(child: Text(_fetchedConsumableMonthlySummaryData[index].consumable!.name.toString())));
cells[2] = DataCell(
Center(child: Text(_fetchedConsumableMonthlySummaryData[index - 1].quantity_in!.toStringAsFixed(2))));
Center(child: Text(_fetchedConsumableMonthlySummaryData[index].quantity_in!.toStringAsFixed(2))));
cells[3] = DataCell(
Center(child: Text(_fetchedConsumableMonthlySummaryData[index - 1].quantity_out!.toStringAsFixed(2))));
Center(child: Text(_fetchedConsumableMonthlySummaryData[index].quantity_out!.toStringAsFixed(2))));

double? closingStock = (_fetchedConsumableMonthlySummaryData[index - 1].quantity_in!) -
(_fetchedConsumableMonthlySummaryData[index - 1].quantity_out!);
double? closingStock = (_fetchedConsumableMonthlySummaryData[index].quantity_in!) -
(_fetchedConsumableMonthlySummaryData[index].quantity_out!);

cells[4] = DataCell(Center(
child: Text(closingStock.toStringAsFixed(2))));

cells[5] = DataCell(
Center(child: Text(_fetchedConsumableMonthlySummaryData[index - 1].resource_property!.value.toString())));
Center(child: Text(_fetchedConsumableMonthlySummaryData[index].resource_property!.value.toString())));

return DataRow(cells: cells);
}
Expand Down
Loading

0 comments on commit f7efe43

Please sign in to comment.