From c10025720b276fc2d99460d5156a752020d41af8 Mon Sep 17 00:00:00 2001 From: Ramkrishna-egov Date: Thu, 2 Feb 2023 23:47:25 +0530 Subject: [PATCH 1/4] PFM-2305 --- .../android/app/src/main/AndroidManifest.xml | 5 + .../ConsumerBillPayments.dart | 43 +- .../NewConsumerBill.dart | 6 +- .../lib/providers/collect_payment.dart | 425 +++++++++--------- .../lib/screeens/common/collect_payment.dart | 4 +- .../mgramseva/lib/utils/print_bluetooth.dart | 105 +++++ frontend/mgramseva/pubspec.lock | 16 +- frontend/mgramseva/pubspec.yaml | 2 + 8 files changed, 373 insertions(+), 233 deletions(-) create mode 100644 frontend/mgramseva/lib/utils/print_bluetooth.dart diff --git a/frontend/mgramseva/android/app/src/main/AndroidManifest.xml b/frontend/mgramseva/android/app/src/main/AndroidManifest.xml index 0b56321f4..a07cacafc 100644 --- a/frontend/mgramseva/android/app/src/main/AndroidManifest.xml +++ b/frontend/mgramseva/android/app/src/main/AndroidManifest.xml @@ -5,6 +5,11 @@ + + + + + { SizedBox( height: 8, ), - getprinterlabel(i18.consumerReciepts.CONSUMER_ACTUAL_DUE_AMOUNT, + getprinterlabel( + i18.consumerReciepts.CONSUMER_ACTUAL_DUE_AMOUNT, ('₹' + (item.totalDue).toString())), getprinterlabel(i18.consumerReciepts.RECEIPT_AMOUNT_PAID, ('₹' + (item.totalAmountPaid).toString())), @@ -227,8 +226,11 @@ class ConsumerBillPaymentsState extends State { .convert('en-in', item.totalAmountPaid!.toInt()) .toString()) + ' only')), - getprinterlabel(i18.consumerReciepts.CONSUMER_PENDING_AMOUNT, - ('₹' + ((item.totalDue ?? 0) - (item.totalAmountPaid ?? 0)).toString())), + getprinterlabel( + i18.consumerReciepts.CONSUMER_PENDING_AMOUNT, + ('₹' + + ((item.totalDue ?? 0) - (item.totalAmountPaid ?? 0)) + .toString())), SizedBox( height: 8, ), @@ -254,7 +256,7 @@ class ConsumerBillPaymentsState extends State { kIsWeb ? js.onButtonClick( value, stateProvider.stateInfo!.stateLogoURL.toString()) - : CommonPrinter.printTicket( + : PrintBluetooth.printTicket( img.decodeImage(value), navigatorKey.currentContext!) }); } @@ -346,7 +348,7 @@ class ConsumerBillPaymentsState extends State { context), ])), Padding( - padding: const EdgeInsets.only(bottom : 8.0), + padding: const EdgeInsets.only(bottom: 8.0), child: Row(children: [ Container( padding: EdgeInsets.only(left: 8), @@ -362,15 +364,15 @@ class ConsumerBillPaymentsState extends State { 'Metered' ? "ws-receipt" : "ws-receipt-nm", - "tenantId": - commonProvider.userDetails!.selectedtenant!.code, + "tenantId": commonProvider + .userDetails!.selectedtenant!.code, }, item.mobileNumber, item, "Share"), style: ButtonStyle( alignment: Alignment.center, padding: MaterialStateProperty.all( EdgeInsets.symmetric(vertical: 8)), - shape: - MaterialStateProperty.all(RoundedRectangleBorder( + shape: MaterialStateProperty.all( + RoundedRectangleBorder( side: BorderSide( width: 2, color: Theme.of(context).primaryColor), @@ -399,7 +401,8 @@ class ConsumerBillPaymentsState extends State { icon: Icon(Icons.print), label: Text( ApplicationLocalizations.of(context).translate( - i18.consumerReciepts.CONSUMER_RECEIPT_PRINT), + i18.consumerReciepts + .CONSUMER_RECEIPT_PRINT), style: Theme.of(context) .textTheme .subtitle1! diff --git a/frontend/mgramseva/lib/components/HouseConnectionandBill/NewConsumerBill.dart b/frontend/mgramseva/lib/components/HouseConnectionandBill/NewConsumerBill.dart index 729fbb8e3..df0f2c3cb 100644 --- a/frontend/mgramseva/lib/components/HouseConnectionandBill/NewConsumerBill.dart +++ b/frontend/mgramseva/lib/components/HouseConnectionandBill/NewConsumerBill.dart @@ -206,9 +206,9 @@ class NewConsumerBillState extends State { context), if(CommonProvider.getPenaltyOrAdvanceStatus(widget.waterConnection?.mdmsData, true) && houseHoldProvider.isfirstdemand) getLabelText( i18.common.CORE_ADVANCE_ADJUSTED, - (((CommonProvider.getAdvanceAdjustedAmount(widget.demandList)) != '0.0' - ? '- ' + '₹' + (CommonProvider.getAdvanceAdjustedAmount(widget.demandList)).toString() - : '- ' + '₹' +(CommonProvider.getAdvanceAdjustedAmount(widget.demandList)).toString())), + ((double.parse(CommonProvider.getAdvanceAdjustedAmount(widget.demandList)).abs() != 0.0 + ? '- ₹' + (CommonProvider.getAdvanceAdjustedAmount(widget.demandList)).toString() + : '₹' +(CommonProvider.getAdvanceAdjustedAmount(widget.demandList)).toString())), context), if(CommonProvider.getPenaltyOrAdvanceStatus(widget.waterConnection?.mdmsData, false, true) && houseHoldProvider.isfirstdemand && penalty.isDueDateCrossed) getLabelText( diff --git a/frontend/mgramseva/lib/providers/collect_payment.dart b/frontend/mgramseva/lib/providers/collect_payment.dart index 211f84a0c..f4f095fa1 100644 --- a/frontend/mgramseva/lib/providers/collect_payment.dart +++ b/frontend/mgramseva/lib/providers/collect_payment.dart @@ -1,42 +1,41 @@ import 'dart:async'; import 'dart:typed_data'; -import 'package:mgramseva/model/demand/update_demand_list.dart'; -import 'package:mgramseva/model/mdms/payment_type.dart'; -import 'package:mgramseva/providers/language.dart'; -import '../components/HouseConnectionandBill/jsconnnector.dart' as js; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:mgramseva/Env/app_config.dart'; +import 'package:image/image.dart' as img; import 'package:mgramseva/model/bill/bill_payments.dart'; +import 'package:mgramseva/model/bill/billing.dart'; import 'package:mgramseva/model/common/fetch_bill.dart'; +import 'package:mgramseva/model/demand/demand_list.dart'; +import 'package:mgramseva/model/demand/update_demand_list.dart'; +import 'package:mgramseva/model/mdms/payment_type.dart'; import 'package:mgramseva/model/success_handler.dart'; import 'package:mgramseva/providers/household_details_provider.dart'; +import 'package:mgramseva/providers/language.dart'; +import 'package:mgramseva/repository/billing_service_repo.dart'; import 'package:mgramseva/repository/consumer_details_repo.dart'; import 'package:mgramseva/repository/core_repo.dart'; import 'package:mgramseva/routers/Routers.dart'; import 'package:mgramseva/services/MDMS.dart'; +import 'package:mgramseva/utils/Constants/I18KeyConstants.dart'; import 'package:mgramseva/utils/Locilization/application_localizations.dart'; -import 'package:mgramseva/utils/common_printer.dart'; import 'package:mgramseva/utils/constants.dart'; import 'package:mgramseva/utils/custom_exception.dart'; import 'package:mgramseva/utils/date_formats.dart'; import 'package:mgramseva/utils/error_logging.dart'; -import 'package:mgramseva/utils/Constants/I18KeyConstants.dart'; import 'package:mgramseva/utils/global_variables.dart'; import 'package:mgramseva/utils/loaders.dart'; import 'package:mgramseva/utils/models.dart'; import 'package:mgramseva/utils/notifyers.dart'; +import 'package:mgramseva/utils/print_bluetooth.dart'; import 'package:mgramseva/widgets/CommonSuccessPage.dart'; import 'package:number_to_words/number_to_words.dart'; import 'package:provider/provider.dart'; import 'package:screenshot/screenshot.dart'; -import 'package:image/image.dart' as img; -import '../model/localization/language.dart'; + +import '../components/HouseConnectionandBill/jsconnnector.dart' as js; import 'common_provider.dart'; -import 'package:mgramseva/repository/billing_service_repo.dart'; -import 'package:mgramseva/model/bill/billing.dart'; -import 'package:mgramseva/model/demand/demand_list.dart'; class CollectPaymentProvider with ChangeNotifier { var paymentStreamController = StreamController.broadcast(); @@ -52,20 +51,22 @@ class CollectPaymentProvider with ChangeNotifier { } Future getBillDetails( - BuildContext context, Map query, List? bill, List? demandList, PaymentType? mdmsData, List? updateDemandList ) async { + BuildContext context, + Map query, + List? bill, + List? demandList, + PaymentType? mdmsData, + List? updateDemandList) async { try { - - List? paymentDetails; // if(bill == null) { - paymentDetails = await ConsumerRepository().getBillDetails(query); + paymentDetails = await ConsumerRepository().getBillDetails(query); // }else{ // paymentDetails = (bill.map((e)=> e.toJson()).toList()).map((e)=> FetchBill.fromJson(e)).toList(); // } - - if(demandList == null) { + if (demandList == null) { var demand = await BillingServiceRepository().fetchdDemand({ "tenantId": query['tenantId'], "consumerCode": query['consumerCode'], @@ -76,67 +77,72 @@ class CollectPaymentProvider with ChangeNotifier { demandList = demand.demands; if (demandList != null && demandList.length > 0) { - demandList.sort((a, b) => - b - .demandDetails!.first.auditDetails!.createdTime! - .compareTo( - a.demandDetails!.first.auditDetails!.createdTime!)); + demandList.sort((a, b) => b + .demandDetails!.first.auditDetails!.createdTime! + .compareTo(a.demandDetails!.first.auditDetails!.createdTime!)); } } - if (query['status'] != Constants.CONNECTION_STATUS.first){ + if (query['status'] != Constants.CONNECTION_STATUS.first) { if (updateDemandList == null) { var demand = await BillingServiceRepository().fetchUpdateDemand({ "tenantId": query['tenantId'], "consumerCodes": query['consumerCode'], "isGetPenaltyEstimate": "true" - }, - { - "GetBillCriteria": { - "tenantId": query['tenantId'], - "billId": null, - "isGetPenaltyEstimate": true, - "consumerCodes": [query['consumerCode']] - } - }); + }, { + "GetBillCriteria": { + "tenantId": query['tenantId'], + "billId": null, + "isGetPenaltyEstimate": true, + "consumerCodes": [query['consumerCode']] + } + }); updateDemandList = demand.demands; updateDemand?.totalApplicablePenalty = demand.totalApplicablePenalty; updateDemandList?.forEach((e) { e.totalApplicablePenalty = demand.totalApplicablePenalty; }); - if (updateDemandList != null && updateDemandList.length > 0) { - updateDemandList.sort((a, b) => - b - .demandDetails!.first.auditDetails!.createdTime! - .compareTo( - a.demandDetails!.first.auditDetails!.createdTime!)); + updateDemandList.sort((a, b) => b + .demandDetails!.first.auditDetails!.createdTime! + .compareTo(a.demandDetails!.first.auditDetails!.createdTime!)); } } - } - else{} + } else {} if (paymentDetails != null) { - if(mdmsData == null){ + if (mdmsData == null) { mdmsData = await CommonProvider.getMdmsBillingService(); paymentDetails.first.mdmsData = mdmsData; } - - paymentDetails.first.billDetails + paymentDetails.first.billDetails ?.sort((a, b) => b.fromPeriod!.compareTo(a.fromPeriod!)); - demandList = demandList?.where((element) => element.status != 'CANCELLED').toList(); - updateDemandList = updateDemandList?.where((element) => element.status != 'CANCELLED').toList(); + demandList = demandList + ?.where((element) => element.status != 'CANCELLED') + .toList(); + updateDemandList = updateDemandList + ?.where((element) => element.status != 'CANCELLED') + .toList(); // var demandDetails = await ConsumerRepository().getDemandDetails(query); // if (demandDetails != null) // paymentDetails.first.demand = demandDetails.first; getPaymentModes(paymentDetails.first); - paymentDetails.first.customAmountCtrl.text = paymentDetails.first.totalAmount!.toInt() > 0 ? paymentDetails.first.totalAmount!.toInt().toString() : ''; - paymentDetails.first.billDetails?.first.billAccountDetails?.last.advanceAdjustedAmount = double.parse(CommonProvider.getAdvanceAdjustedAmount(demandList ?? [])); - paymentDetails.first.billDetails?.first.billAccountDetails?.last.arrearsAmount = CommonProvider.getArrearsAmount(demandList ?? []); - paymentDetails.first.billDetails?.first.billAccountDetails?.last.totalBillAmount = CommonProvider.getTotalBillAmount(demandList ?? []); + paymentDetails.first.customAmountCtrl.text = + paymentDetails.first.totalAmount!.toInt() > 0 + ? paymentDetails.first.totalAmount!.toInt().toString() + : ''; + paymentDetails.first.billDetails?.first.billAccountDetails?.last + .advanceAdjustedAmount = + double.parse( + CommonProvider.getAdvanceAdjustedAmount(demandList ?? [])); + paymentDetails.first.billDetails?.first.billAccountDetails?.last + .arrearsAmount = CommonProvider.getArrearsAmount(demandList ?? []); + paymentDetails.first.billDetails?.first.billAccountDetails?.last + .totalBillAmount = + CommonProvider.getTotalBillAmount(demandList ?? []); paymentDetails.first.demands = demandList?.first; paymentDetails.first.demandList = demandList; paymentDetails.first.updateDemands = updateDemandList?.first; @@ -211,170 +217,175 @@ class CollectPaymentProvider with ChangeNotifier { screenshotController .captureFromWidget( - Container( - width: kIsWeb ? 375 : 150, - margin: EdgeInsets.zero, - padding: EdgeInsets.zero, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, + Container( + width: kIsWeb ? 375 : 150, + margin: EdgeInsets.zero, + padding: EdgeInsets.zero, + child: Column( + mainAxisSize: MainAxisSize.min, children: [ - kIsWeb - ? SizedBox( - width: 70, - height: 70, - ) - : Image( - width: 40, - height: 40, - image: NetworkImage(stateProvider - .stateInfo!.stateLogoURL - .toString())), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + kIsWeb + ? SizedBox( + width: 70, + height: 70, + ) + : Image( + width: 40, + height: 40, + image: NetworkImage(stateProvider + .stateInfo!.stateLogoURL + .toString())), + Container( + width: kIsWeb ? 290 : 90, + margin: EdgeInsets.all(5), + child: Text( + ApplicationLocalizations.of( + navigatorKey.currentContext!) + .translate(i18.consumerReciepts + .GRAM_PANCHAYAT_WATER_SUPPLY_AND_SANITATION), + textScaleFactor: kIsWeb ? 3 : 1, + maxLines: 3, + style: TextStyle( + color: Colors.blue, + fontSize: 10, + height: 1, + fontWeight: FontWeight.bold, + fontStyle: FontStyle.italic), + textAlign: TextAlign.left, + ), + ) + ], + ), + SizedBox( + height: 8, + ), Container( - width: kIsWeb ? 290 : 90, - margin: EdgeInsets.all(5), - child: Text( - ApplicationLocalizations.of( - navigatorKey.currentContext!) - .translate(i18.consumerReciepts - .GRAM_PANCHAYAT_WATER_SUPPLY_AND_SANITATION), + width: kIsWeb ? 375 : 90, + margin: EdgeInsets.all(5), + child: Text( + ApplicationLocalizations.of( + navigatorKey.currentContext!) + .translate(i18.consumerReciepts.WATER_RECEIPT), + textScaleFactor: kIsWeb ? 3 : 1, + style: TextStyle( + color: Colors.blue, + fontSize: 10, + height: 1, + fontWeight: FontWeight.bold, + ))), + SizedBox( + height: 8, + ), + getprinterlabel( + i18.consumerReciepts.RECEIPT_GPWSC_NAME, + ApplicationLocalizations.of(navigatorKey.currentContext!) + .translate(commonProvider + .userDetails!.selectedtenant!.code!)), + getprinterlabel(i18.consumerReciepts.RECEIPT_CONSUMER_NO, + '${fetchBill.consumerCode}'), + getprinterlabel( + i18.consumerReciepts.RECEIPT_CONSUMER_NAME, + '${item.paidBy}', + ), + getprinterlabel( + i18.consumerReciepts.RECEIPT_CONSUMER_MOBILE_NO, + item.mobileNumber), + getprinterlabel( + i18.consumerReciepts.RECEIPT_CONSUMER_ADDRESS, + ApplicationLocalizations.of(navigatorKey.currentContext!) + .translate(houseHoldProvider + .waterConnection!.additionalDetails!.doorNo + .toString()) + + " " + + ApplicationLocalizations.of( + navigatorKey.currentContext!) + .translate( + '${houseHoldProvider.waterConnection?.additionalDetails?.street.toString()}') + + " " + + ApplicationLocalizations.of( + navigatorKey.currentContext!) + .translate( + '${houseHoldProvider.waterConnection?.additionalDetails?.locality.toString()}') + + " " + + ApplicationLocalizations.of( + navigatorKey.currentContext!) + .translate(commonProvider + .userDetails!.selectedtenant!.code!)), + SizedBox( + height: 10, + ), + getprinterlabel(i18.consumer.SERVICE_TYPE, + '${houseHoldProvider.waterConnection!.connectionType.toString()}'), + getprinterlabel(i18.consumerReciepts.CONSUMER_RECEIPT_NO, + item.paymentDetails!.first.receiptNumber), + getprinterlabel( + i18.consumerReciepts.RECEIPT_ISSUE_DATE, + DateFormats.timeStampToDate(item.transactionDate, + format: "dd/MM/yyyy") + .toString()), + getprinterlabel( + i18.consumerReciepts.RECEIPT_BILL_PERIOD, + DateFormats.timeStampToDate( + item.paymentDetails?.last.bill!.billDetails!.first + .fromPeriod, + format: "dd/MM/yyyy") + + '-' + + DateFormats.timeStampToDate( + item.paymentDetails?.last.bill?.billDetails! + .first.toPeriod, + format: "dd/MM/yyyy") + .toString()), + SizedBox( + height: 8, + ), + getprinterlabel( + i18.consumerReciepts.CONSUMER_ACTUAL_DUE_AMOUNT, + ('₹' + (item.totalDue).toString())), + getprinterlabel(i18.consumerReciepts.RECEIPT_AMOUNT_PAID, + ('₹' + (item.totalAmountPaid).toString())), + getprinterlabel( + i18.consumerReciepts.RECEIPT_AMOUNT_IN_WORDS, + ('Rupees ' + + (NumberToWord() + .convert('en-in', item.totalAmountPaid!.toInt()) + .toString()) + + ' only')), + getprinterlabel( + i18.consumerReciepts.CONSUMER_PENDING_AMOUNT, + ('₹' + + ((item.totalDue ?? 0) - (item.totalAmountPaid ?? 0)) + .toString())), + SizedBox( + height: 8, + ), + Text('- - *** - -', textScaleFactor: kIsWeb ? 3 : 1, - maxLines: 3, + textAlign: TextAlign.start, style: TextStyle( - color: Colors.blue, - fontSize: 10, - height: 1, - fontWeight: FontWeight.bold, - fontStyle: FontStyle.italic), - textAlign: TextAlign.left, - ), - ) - ], - ), - SizedBox( - height: 8, - ), - Container( - width: kIsWeb ? 375 : 90, - margin: EdgeInsets.all(5), - child: Text( - ApplicationLocalizations.of( - navigatorKey.currentContext!) - .translate(i18.consumerReciepts.WATER_RECEIPT), + color: Colors.red, + fontSize: kIsWeb ? 5 : 6, + fontWeight: FontWeight.bold)), + Text( + "${ApplicationLocalizations.of(navigatorKey.currentContext!).translate(i18.common.RECEIPT_FOOTER)}", textScaleFactor: kIsWeb ? 3 : 1, + textAlign: TextAlign.start, style: TextStyle( - color: Colors.blue, - fontSize: 10, - height: 1, - fontWeight: FontWeight.bold, - ))), - SizedBox( - height: 8, - ), - getprinterlabel( - i18.consumerReciepts.RECEIPT_GPWSC_NAME, - ApplicationLocalizations.of(navigatorKey.currentContext!) - .translate(commonProvider - .userDetails!.selectedtenant!.code!)), - getprinterlabel(i18.consumerReciepts.RECEIPT_CONSUMER_NO, - '${fetchBill.consumerCode}'), - getprinterlabel( - i18.consumerReciepts.RECEIPT_CONSUMER_NAME, - '${item.paidBy}', - ), - getprinterlabel( - i18.consumerReciepts.RECEIPT_CONSUMER_MOBILE_NO, - item.mobileNumber), - getprinterlabel( - i18.consumerReciepts.RECEIPT_CONSUMER_ADDRESS, - ApplicationLocalizations.of(navigatorKey.currentContext!) - .translate(houseHoldProvider.waterConnection!.additionalDetails! - .doorNo - .toString()) + - " " + - ApplicationLocalizations.of(navigatorKey.currentContext!) - .translate('${houseHoldProvider.waterConnection?.additionalDetails?.street - .toString()}') + - " " + - ApplicationLocalizations.of(navigatorKey.currentContext!) - .translate('${houseHoldProvider - .waterConnection?.additionalDetails?.locality - .toString()}') + - " " + - ApplicationLocalizations.of(navigatorKey.currentContext!) - .translate(commonProvider - .userDetails!.selectedtenant!.code!)), - SizedBox( - height: 10, - ), - getprinterlabel(i18.consumer.SERVICE_TYPE, - '${houseHoldProvider.waterConnection!.connectionType - .toString()}'), - getprinterlabel(i18.consumerReciepts.CONSUMER_RECEIPT_NO, - item.paymentDetails!.first.receiptNumber), - getprinterlabel( - i18.consumerReciepts.RECEIPT_ISSUE_DATE, - DateFormats.timeStampToDate(item.transactionDate, - format: "dd/MM/yyyy") - .toString()), - getprinterlabel( - i18.consumerReciepts.RECEIPT_BILL_PERIOD, - DateFormats.timeStampToDate( - item.paymentDetails?.last.bill!.billDetails!.first - .fromPeriod, - format: "dd/MM/yyyy") + - '-' + - DateFormats.timeStampToDate( - item.paymentDetails?.last.bill?.billDetails! - .first.toPeriod, - format: "dd/MM/yyyy") - .toString()), - SizedBox( - height: 8, - ), - getprinterlabel(i18.consumerReciepts.CONSUMER_ACTUAL_DUE_AMOUNT, - ('₹' + (item.totalDue).toString())), - getprinterlabel(i18.consumerReciepts.RECEIPT_AMOUNT_PAID, - ('₹' + (item.totalAmountPaid).toString())), - getprinterlabel( - i18.consumerReciepts.RECEIPT_AMOUNT_IN_WORDS, - ('Rupees ' + - (NumberToWord() - .convert('en-in', item.totalAmountPaid!.toInt()) - .toString()) + - ' only')), - getprinterlabel(i18.consumerReciepts.CONSUMER_PENDING_AMOUNT, - ('₹' + ((item.totalDue ?? 0) - (item.totalAmountPaid ?? 0)).toString())), - SizedBox( - height: 8, - ), - Text('- - *** - -', - textScaleFactor: kIsWeb ? 3 : 1, - textAlign: TextAlign.start, - style: TextStyle( - color: Colors.red, - fontSize: kIsWeb ? 5 : 6, - fontWeight: FontWeight.bold)), - Text( - "${ApplicationLocalizations.of(navigatorKey.currentContext!).translate(i18.common.RECEIPT_FOOTER)}", - textScaleFactor: kIsWeb ? 3 : 1, - textAlign: TextAlign.start, - style: TextStyle( - color: Colors.red, - fontSize: kIsWeb ? 5 : 6, - fontWeight: FontWeight.bold)), - ], - )), - ) + color: Colors.red, + fontSize: kIsWeb ? 5 : 6, + fontWeight: FontWeight.bold)), + ], + )), + ) .then((value) => { - kIsWeb - ? js.onButtonClick( - value, stateProvider.stateInfo!.stateLogoURL.toString()) - : CommonPrinter.printTicket( - img.decodeImage(value), navigatorKey.currentContext!) - }); + kIsWeb + ? js.onButtonClick( + value, stateProvider.stateInfo!.stateLogoURL.toString()) + : PrintBluetooth.printTicket( + img.decodeImage(value), navigatorKey.currentContext!) + }); } Future getPaymentModes(FetchBill fetchBill) async { diff --git a/frontend/mgramseva/lib/screeens/common/collect_payment.dart b/frontend/mgramseva/lib/screeens/common/collect_payment.dart index 3d84995fd..1eb5fc374 100644 --- a/frontend/mgramseva/lib/screeens/common/collect_payment.dart +++ b/frontend/mgramseva/lib/screeens/common/collect_payment.dart @@ -22,7 +22,6 @@ import 'package:mgramseva/widgets/FormWrapper.dart'; import 'package:mgramseva/widgets/HomeBack.dart'; import 'package:mgramseva/widgets/RadioButtonFieldBuilder.dart'; import 'package:mgramseva/widgets/SideBar.dart'; -import 'package:mgramseva/widgets/TextFieldBuilder.dart'; import 'package:provider/provider.dart'; import '../../components/HouseConnectionandBill/NewConsumerBill.dart'; @@ -30,6 +29,7 @@ import '../../model/demand/update_demand_list.dart'; import '../../providers/common_provider.dart'; import '../../utils/models.dart'; import '../../widgets/CustomDetails.dart'; +import '../../widgets/TextFieldBuilder.dart'; import '../../widgets/customAppbar.dart'; class ConnectionPaymentView extends StatefulWidget { @@ -427,7 +427,7 @@ class _ConnectionPaymentViewState extends State { 0.0 ? '- ₹ ' + '${(fetchBill.billDetails?.first.billAccountDetails?.last.advanceAdjustedAmount)}' - : '- ₹ ' + + : '₹ ' + '${(fetchBill.billDetails?.first.billAccountDetails?.last.advanceAdjustedAmount)}')), if (CommonProvider.getPenaltyOrAdvanceStatus( fetchBill.mdmsData, false, true) && diff --git a/frontend/mgramseva/lib/utils/print_bluetooth.dart b/frontend/mgramseva/lib/utils/print_bluetooth.dart new file mode 100644 index 000000000..2dfee1382 --- /dev/null +++ b/frontend/mgramseva/lib/utils/print_bluetooth.dart @@ -0,0 +1,105 @@ +import 'package:esc_pos_utils/esc_pos_utils.dart'; +import 'package:flutter/material.dart'; +import 'package:nearby_connections/nearby_connections.dart'; +import 'package:print_bluetooth_thermal/print_bluetooth_thermal.dart'; + +class PrintBluetooth { + static bool connected = false; + + static setConnect(String mac, value, context) async { + if (connected) { + PrintBluetooth.printTicket(value, context); + Navigator.of(context).pop(); + } else { + final result = + await PrintBluetoothThermal.connect(macPrinterAddress: mac); + + print("state conneected $result"); + if (result) { + connected = true; + PrintBluetooth.printTicket(value, context); + Navigator.of(context).pop(); + } + } + } + + static Future showMyDialog(context, value) async { + connected = false; + Widget setupAlertDialogContainer( + List availableBluetoothDevices, context) { + return Container( + height: 300.0, // Change as per your requirement + width: 300.0, + child: ListView.builder( + shrinkWrap: true, + itemCount: availableBluetoothDevices.length > 0 + ? availableBluetoothDevices.length + : 0, + itemBuilder: (context, index) { + return ListTile( + onTap: () { + String select = availableBluetoothDevices[index].macAdress; + setConnect(select, value, context); + }, + title: Text('${availableBluetoothDevices[index].name}'), + subtitle: Text("Click to connect"), + ); + }, + ), + ); + } + + final List availableBluetoothDevices = + await PrintBluetoothThermal.pairedBluetooths; + return showDialog( + context: context, + barrierDismissible: false, // user must tap button! + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Connect to Device'), + content: + setupAlertDialogContainer(availableBluetoothDevices, context), + actions: [ + TextButton( + child: const Text('Close'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); + } + + static Future printTicket(value, context) async { + print(double.parse('-0.0').abs()); + bool? isPermissionGranted = + await PrintBluetoothThermal.isPermissionBluetoothGranted; + print(isPermissionGranted); + if (!isPermissionGranted) { + Nearby().askBluetoothPermission(); + } + bool? isConnected = await PrintBluetoothThermal.connectionStatus; + if (isConnected) { + List bytes = await getTicket(value); + final result = await PrintBluetoothThermal.writeBytes(bytes); + print("Print $result"); + } else { + PrintBluetooth.showMyDialog(context, value); + print("connection not established"); + } + } + + static Future> getTicket(value) async { + print(value); + List bytes = []; + CapabilityProfile profile = await CapabilityProfile.load(); + final generator = Generator(PaperSize.mm80, profile); + bytes += generator.image(value); + + // ticket.feed(2); + bytes += generator.cut(); + return bytes; + } +} diff --git a/frontend/mgramseva/pubspec.lock b/frontend/mgramseva/pubspec.lock index 1823cce40..2d09ce9eb 100644 --- a/frontend/mgramseva/pubspec.lock +++ b/frontend/mgramseva/pubspec.lock @@ -595,7 +595,7 @@ packages: name: json_annotation url: "https://pub.dartlang.org" source: hosted - version: "4.0.1" + version: "4.1.0" json_serializable: dependency: "direct dev" description: @@ -645,6 +645,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.1" + nearby_connections: + dependency: "direct main" + description: + name: nearby_connections + url: "https://pub.dartlang.org" + source: hosted + version: "3.2.0" nested: dependency: transitive description: @@ -841,6 +848,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.5.0" + print_bluetooth_thermal: + dependency: "direct main" + description: + name: print_bluetooth_thermal + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.5" printing: dependency: "direct main" description: diff --git a/frontend/mgramseva/pubspec.yaml b/frontend/mgramseva/pubspec.yaml index c5bbfcd72..fc4f09859 100644 --- a/frontend/mgramseva/pubspec.yaml +++ b/frontend/mgramseva/pubspec.yaml @@ -69,6 +69,8 @@ dependencies: package_info_plus: ^1.3.0 open_file_safe: ^3.2.3 syncfusion_flutter_xlsio: ^20.3.59-beta + print_bluetooth_thermal: ^1.0.5 + nearby_connections: ^3.2.0 dev_dependencies: flutter_launcher_icons: "^0.9.2" From 98ce840197cb9d7ae1919ac86dffcc7eda22244c Mon Sep 17 00:00:00 2001 From: Ramkrishna-egov Date: Fri, 3 Feb 2023 00:03:17 +0530 Subject: [PATCH 2/4] Upgraded App and build version --- frontend/mgramseva/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/mgramseva/pubspec.yaml b/frontend/mgramseva/pubspec.yaml index fc4f09859..daba1a8ca 100644 --- a/frontend/mgramseva/pubspec.yaml +++ b/frontend/mgramseva/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.2.1+19 +version: 1.2.2+20 environment: sdk: ">=2.12.0 <3.0.0" From 544c522af978b504a938747c61e4e55f0d0dcf6d Mon Sep 17 00:00:00 2001 From: Ramkrishna-egov Date: Mon, 6 Feb 2023 15:33:54 +0530 Subject: [PATCH 3/4] PFM-2309:: Logic update for CurrentYTD Months dropdown, Arrow icon in Dashboard fixes --- frontend/mgramseva/docker/Dockerfile | 2 +- frontend/mgramseva/lib/main.dart | 2 +- .../bill_generation_details_provider.dart | 16 ++++++++++++++-- .../lib/providers/consumer_details_provider.dart | 16 ++++++++++++++-- .../lib/providers/dashboard_provider.dart | 3 ++- .../utils/ExcelDownload/save_file_mobile.dart | 2 +- frontend/mgramseva/pubspec.lock | 6 +++--- frontend/mgramseva/pubspec.yaml | 5 +++-- 8 files changed, 39 insertions(+), 13 deletions(-) diff --git a/frontend/mgramseva/docker/Dockerfile b/frontend/mgramseva/docker/Dockerfile index f411bd1d7..de68da74f 100644 --- a/frontend/mgramseva/docker/Dockerfile +++ b/frontend/mgramseva/docker/Dockerfile @@ -1,6 +1,6 @@ # Docker flutter tags https://hub.docker.com/r/cirrusci/flutter/tags?page=1&name=1.16 -FROM cirrusci/flutter:3.0.2 AS build +FROM cirrusci/flutter:3.3.8 AS build ARG WORK_DIR WORKDIR /app # copy the project files diff --git a/frontend/mgramseva/lib/main.dart b/frontend/mgramseva/lib/main.dart index 5e9cd63c9..b67d4f2b6 100644 --- a/frontend/mgramseva/lib/main.dart +++ b/frontend/mgramseva/lib/main.dart @@ -43,7 +43,7 @@ import 'package:mgramseva/utils/error_logging.dart'; import 'package:mgramseva/utils/global_variables.dart'; import 'package:mgramseva/utils/loaders.dart'; import 'package:mgramseva/utils/notifyers.dart'; -import 'package:open_file_safe/open_file_safe.dart'; +import 'package:open_file/open_file.dart'; import 'package:provider/provider.dart'; import 'package:url_strategy/url_strategy.dart'; diff --git a/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart b/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart index 27b5a9ab1..a53abcbea 100644 --- a/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart +++ b/frontend/mgramseva/lib/providers/bill_generation_details_provider.dart @@ -481,8 +481,20 @@ class BillGenerationProvider with ChangeNotifier { /// Get months based on selected billing year var months = CommonMethods.getPastMonthUntilFinancialYear(date1.year); - /// if its current ytd year means removing current month - if(isCurrentYtdSelected) months.removeAt(0); + /// if its current ytd year means removing till current month + if (isCurrentYtdSelected) { + switch (DateTime.now().month) { + case 1: + months.removeRange(0, 3); + break; + case 2: + months.removeRange(0, 2); + break; + case 3: + months.removeRange(0, 1); + break; + } + } /// if selected year is future year means all the months will be removed if(date1.year >= ytd.endDate.year) months.clear(); diff --git a/frontend/mgramseva/lib/providers/consumer_details_provider.dart b/frontend/mgramseva/lib/providers/consumer_details_provider.dart index 778a241f5..2d45f6b4c 100644 --- a/frontend/mgramseva/lib/providers/consumer_details_provider.dart +++ b/frontend/mgramseva/lib/providers/consumer_details_provider.dart @@ -608,8 +608,20 @@ class ConsumerProvider with ChangeNotifier { /// Get months based on selected billing year var months = CommonMethods.getPastMonthUntilFinancialYear(date1.year); - /// if its current ytd year means removing current month - if(isCurrentYtdSelected) months.removeAt(0); + /// if its current ytd year means removing till current month + if (isCurrentYtdSelected) { + switch (DateTime.now().month) { + case 1: + months.removeRange(0, 3); + break; + case 2: + months.removeRange(0, 2); + break; + case 3: + months.removeRange(0, 1); + break; + } + } for (var i = 0; i < months.length; i++) { var prevMonth = months[i].startDate; diff --git a/frontend/mgramseva/lib/providers/dashboard_provider.dart b/frontend/mgramseva/lib/providers/dashboard_provider.dart index e715c04b6..cd6563fb0 100644 --- a/frontend/mgramseva/lib/providers/dashboard_provider.dart +++ b/frontend/mgramseva/lib/providers/dashboard_provider.dart @@ -97,6 +97,7 @@ class DashBoardProvider with ChangeNotifier { fetchExpenseDashBoardDetails(context, limit, offset, true); } else { + sortBy = SortBy('connectionNumber', false); waterConnectionsDetails?.waterConnection = []; waterConnectionsDetails?.totalCount = null; @@ -419,7 +420,7 @@ class DashBoardProvider with ChangeNotifier { sortBy != null && sortBy!.key == 'connectionNumber' ? sortBy!.isAscending : null, - apiKey: 'connectionNumber ', + apiKey: 'connectionNumber', callBack: onExpenseSort), TableHeader(i18.common.NAME, isSortingRequired: true, diff --git a/frontend/mgramseva/lib/utils/ExcelDownload/save_file_mobile.dart b/frontend/mgramseva/lib/utils/ExcelDownload/save_file_mobile.dart index c7580c7e1..c7ddbff8b 100644 --- a/frontend/mgramseva/lib/utils/ExcelDownload/save_file_mobile.dart +++ b/frontend/mgramseva/lib/utils/ExcelDownload/save_file_mobile.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:open_file_safe/open_file_safe.dart' as open_file; +import 'package:open_file/open_file.dart' as open_file; import 'package:path_provider/path_provider.dart' as path_provider; // ignore: depend_on_referenced_packages import 'package:path_provider_platform_interface/path_provider_platform_interface.dart'; diff --git a/frontend/mgramseva/pubspec.lock b/frontend/mgramseva/pubspec.lock index 2d09ce9eb..3c06016a5 100644 --- a/frontend/mgramseva/pubspec.lock +++ b/frontend/mgramseva/pubspec.lock @@ -673,13 +673,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.0" - open_file_safe: + open_file: dependency: "direct main" description: - name: open_file_safe + name: open_file url: "https://pub.dartlang.org" source: hosted - version: "3.2.3" + version: "3.2.1" package_config: dependency: transitive description: diff --git a/frontend/mgramseva/pubspec.yaml b/frontend/mgramseva/pubspec.yaml index daba1a8ca..a51989a8f 100644 --- a/frontend/mgramseva/pubspec.yaml +++ b/frontend/mgramseva/pubspec.yaml @@ -30,7 +30,7 @@ dependencies: flutter_secure_storage: ^4.2.0 flutter_svg: ^0.22.0 datetime_picker_formfield: ^2.0.0 - horizontal_data_table: ^4.1.4 + horizontal_data_table: ^4.1.3 file_picker: ^4.0.0 http: ^0.13.3 provider: ^6.0.0 @@ -67,7 +67,8 @@ dependencies: sdk: flutter firebase_analytics: ^8.3.4 package_info_plus: ^1.3.0 - open_file_safe: ^3.2.3 + open_file: ^3.2.1 #use for web + #open_file_safe: ^3.2.3 #use for mobiles syncfusion_flutter_xlsio: ^20.3.59-beta print_bluetooth_thermal: ^1.0.5 nearby_connections: ^3.2.0 From 749bfd9a6fce38d0ea234b9ffc87e3143aed60ec Mon Sep 17 00:00:00 2001 From: Ramkrishna-egov Date: Mon, 6 Feb 2023 16:27:48 +0530 Subject: [PATCH 4/4] Localization for Bluetooth connectivity --- .../lib/utils/Constants/I18KeyConstants.dart | 4 ++++ .../mgramseva/lib/utils/print_bluetooth.dart | 18 +++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/frontend/mgramseva/lib/utils/Constants/I18KeyConstants.dart b/frontend/mgramseva/lib/utils/Constants/I18KeyConstants.dart index 0932ca8dd..425c745a4 100644 --- a/frontend/mgramseva/lib/utils/Constants/I18KeyConstants.dart +++ b/frontend/mgramseva/lib/utils/Constants/I18KeyConstants.dart @@ -507,6 +507,10 @@ class ConsumerReciepts { String get CONSUMER_RECEIPT_PRINT => 'CONSUMER_RECEIPT_PRINT'; String get CONSUMER_ACTUAL_DUE_AMOUNT => 'CONSUMER_ACTUAL_DUE_AMOUNT'; String get CONSUMER_PENDING_AMOUNT => 'CONSUMER_PENDING_AMOUNT'; + String get CONNECT_TO_DEVICE => 'CONNECT_TO_DEVICE'; + String get CLICK_TO_CONNECT => 'CLICK_TO_CONNECT'; + String get CONNECTION_NOT_ESTABLISHED => 'CONNECTION_NOT_ESTABLISHED'; + String get CLOSE => 'CLOSE'; } class _NetWorkException { diff --git a/frontend/mgramseva/lib/utils/print_bluetooth.dart b/frontend/mgramseva/lib/utils/print_bluetooth.dart index 2dfee1382..b8c5e163c 100644 --- a/frontend/mgramseva/lib/utils/print_bluetooth.dart +++ b/frontend/mgramseva/lib/utils/print_bluetooth.dart @@ -1,8 +1,11 @@ import 'package:esc_pos_utils/esc_pos_utils.dart'; import 'package:flutter/material.dart'; +import 'package:mgramseva/utils/Constants/I18KeyConstants.dart'; import 'package:nearby_connections/nearby_connections.dart'; import 'package:print_bluetooth_thermal/print_bluetooth_thermal.dart'; +import 'Locilization/application_localizations.dart'; + class PrintBluetooth { static bool connected = false; @@ -14,7 +17,6 @@ class PrintBluetooth { final result = await PrintBluetoothThermal.connect(macPrinterAddress: mac); - print("state conneected $result"); if (result) { connected = true; PrintBluetooth.printTicket(value, context); @@ -42,7 +44,8 @@ class PrintBluetooth { setConnect(select, value, context); }, title: Text('${availableBluetoothDevices[index].name}'), - subtitle: Text("Click to connect"), + subtitle: Text(ApplicationLocalizations.of(context) + .translate(i18.consumerReciepts.CLICK_TO_CONNECT)), ); }, ), @@ -56,12 +59,14 @@ class PrintBluetooth { barrierDismissible: false, // user must tap button! builder: (BuildContext context) { return AlertDialog( - title: const Text('Connect to Device'), + title: Text(ApplicationLocalizations.of(context) + .translate(i18.consumerReciepts.CONNECT_TO_DEVICE)), content: setupAlertDialogContainer(availableBluetoothDevices, context), actions: [ TextButton( - child: const Text('Close'), + child: Text(ApplicationLocalizations.of(context) + .translate(i18.consumerReciepts.CLOSE)), onPressed: () { Navigator.of(context).pop(); }, @@ -73,7 +78,6 @@ class PrintBluetooth { } static Future printTicket(value, context) async { - print(double.parse('-0.0').abs()); bool? isPermissionGranted = await PrintBluetoothThermal.isPermissionBluetoothGranted; print(isPermissionGranted); @@ -84,10 +88,10 @@ class PrintBluetooth { if (isConnected) { List bytes = await getTicket(value); final result = await PrintBluetoothThermal.writeBytes(bytes); - print("Print $result"); } else { PrintBluetooth.showMyDialog(context, value); - print("connection not established"); + print(ApplicationLocalizations.of(context) + .translate(i18.consumerReciepts.CONNECTION_NOT_ESTABLISHED)); } }