You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
278 lines
13 KiB
Dart
278 lines
13 KiB
Dart
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
|
|
import 'package:diplomaticquarterapp/models/Appointments/DoctorListResponse.dart';
|
|
import 'package:diplomaticquarterapp/models/MyInvoices/DentalInvoiceDetailResponse.dart';
|
|
import 'package:diplomaticquarterapp/models/MyInvoices/GetDentalAppointmentsResponse.dart';
|
|
import 'package:diplomaticquarterapp/pages/BookAppointment/widgets/DoctorView.dart';
|
|
import 'package:diplomaticquarterapp/services/my_invoice_service/my_invoice_services.dart';
|
|
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
|
|
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
|
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
|
|
import 'package:diplomaticquarterapp/widgets/dialogs/confirm_send_email_dialog.dart';
|
|
import 'package:diplomaticquarterapp/widgets/others/app_expandable_notifier.dart';
|
|
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:diplomaticquarterapp/extensions/list_extension.dart';
|
|
|
|
class InvoiceDetail extends StatelessWidget {
|
|
final DoctorList doctor;
|
|
final ListDentalAppointments listDentalAppointments;
|
|
final DentalInvoiceDetailResponse dentalInvoiceDetailResponse;
|
|
final BuildContext context;
|
|
|
|
dynamic totalServiceRate = 0;
|
|
dynamic totalDiscount = 0;
|
|
dynamic totalVAT = 0;
|
|
dynamic subTotal = 0;
|
|
dynamic grandTotal = 0;
|
|
|
|
InvoiceDetail(this.doctor, this.listDentalAppointments, this.dentalInvoiceDetailResponse, this.context);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
ProjectViewModel projectViewModel = Provider.of(context);
|
|
generateInvoiceDetails();
|
|
return AppScaffold(
|
|
appBarTitle: TranslationBase.of(context).myInvoice,
|
|
isShowAppBar: true,
|
|
isShowDecPage: false,
|
|
showNewAppBar: true,
|
|
showNewAppBarTitle: true,
|
|
body: SingleChildScrollView(
|
|
child: Container(
|
|
child: Column(
|
|
children: [
|
|
DoctorView(doctor: doctor, isLiveCareAppointment: false, isShowFlag: false),
|
|
Container(
|
|
margin: EdgeInsets.only(left: 10.0, right: 10.0),
|
|
padding: EdgeInsets.only(top: 10.0, left: 10.0, right: 10.0, bottom: 10.0),
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey[800],
|
|
borderRadius: BorderRadius.only(
|
|
topLeft: Radius.circular(8),
|
|
topRight: Radius.circular(8),
|
|
),
|
|
),
|
|
child: Table(
|
|
children: [
|
|
TableRow(children: [
|
|
Text(TranslationBase.of(context).description, textAlign: TextAlign.center, style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
|
Text(TranslationBase.of(context).quantity, textAlign: TextAlign.center, style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
|
Text(TranslationBase.of(context).price, textAlign: TextAlign.center, style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
|
Text(TranslationBase.of(context).total, textAlign: TextAlign.center, style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
|
]),
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 0.0, left: 10.0, right: 10.0),
|
|
padding: EdgeInsets.only(top: 10.0, left: 10.0, right: 10.0, bottom: 15.0),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.only(
|
|
bottomLeft: Radius.circular(8),
|
|
bottomRight: Radius.circular(8),
|
|
)),
|
|
child: Table(children: fullData(context)),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 3.0, left: 12.0, right: 12.0),
|
|
child: Divider(
|
|
color: Colors.grey[400],
|
|
thickness: 0.7,
|
|
),
|
|
),
|
|
Container(
|
|
child: AppExpandableNotifier(
|
|
title: TranslationBase.of(context).patientShareTotal.toString() + " " + this.grandTotal.toString() + " " + TranslationBase.of(context).sar,
|
|
isExpand: true,
|
|
bodyWidget: Column(crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
|
Table(
|
|
children: [
|
|
TableRow(children: [
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: Text(TranslationBase.of(context).discount, textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: Text(this.totalDiscount.toString() + " " + TranslationBase.of(context).sar,
|
|
textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
|
|
),
|
|
]),
|
|
TableRow(children: [
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: Text(
|
|
TranslationBase.of(context).totalVAT.toString() + " (" + dentalInvoiceDetailResponse.listEInvoiceForDental[0].listConsultation[0].vATPercentage.toString() + "%): ",
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: Text(num.tryParse(this.totalVAT.toString()).toStringAsFixed(2) + " " + TranslationBase.of(context).sar,
|
|
textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
|
|
),
|
|
]),
|
|
TableRow(children: [
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: Text(TranslationBase.of(context).total.toString() + ": ", textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child:
|
|
Text(this.subTotal.toString() + " " + TranslationBase.of(context).sar, textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
|
|
),
|
|
]),
|
|
TableRow(children: [
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: Text(TranslationBase.of(context).paid.toString() + ": ", textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0, bottom: 10.0),
|
|
child: Text(this.grandTotal.toString() + " " + TranslationBase.of(context).sar,
|
|
textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
|
|
),
|
|
]),
|
|
],
|
|
),
|
|
]),
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 3.0, left: 12.0, right: 12.0),
|
|
child: Divider(
|
|
color: Colors.grey[400],
|
|
thickness: 0.7,
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 0.0, left: 10.0, right: 10.0),
|
|
padding: EdgeInsets.only(top: 10.0, left: 10.0, right: 10.0, bottom: 15.0),
|
|
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(8))),
|
|
child: Table(children: [
|
|
TableRow(children: [
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: Text(TranslationBase.of(context).dentalInsurance + ": ", textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0, bottom: 5.0),
|
|
child: Text(dentalInvoiceDetailResponse.listEInvoiceForDental[0].companyName, textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
|
|
),
|
|
]),
|
|
TableRow(children: [
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: Text(TranslationBase.of(context).insuranceID + ": ", textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0, bottom: 10.0),
|
|
child: Text(dentalInvoiceDetailResponse.listEInvoiceForDental[0].insuranceID != null ? dentalInvoiceDetailResponse.listEInvoiceForDental[0].insuranceID : "N/A", textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
|
|
),
|
|
]),
|
|
]),
|
|
),
|
|
SizedBox(
|
|
height: 100.0,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
bottomSheet: Container(
|
|
width: MediaQuery.of(context).size.width,
|
|
color: Theme.of(context).scaffoldBackgroundColor,
|
|
margin: EdgeInsets.only(left: 15.0, right: 15.0, top: 10.0, bottom: 20.0),
|
|
child: DefaultButton(TranslationBase.of(context).sendEmail, () {
|
|
showDialog(
|
|
context: context,
|
|
child: ConfirmSendEmailDialog(
|
|
email: projectViewModel.user.emailAddress,
|
|
onTapSendEmail: () {
|
|
sendInvoiceEmail();
|
|
},
|
|
),
|
|
);
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
|
|
void generateInvoiceDetails() {
|
|
totalServiceRate = 0;
|
|
totalDiscount = 0;
|
|
totalVAT = 0;
|
|
subTotal = 0;
|
|
grandTotal = 0;
|
|
|
|
List<ListConsultation> listConsultations = new List();
|
|
|
|
dentalInvoiceDetailResponse.listEInvoiceForDental[0].listConsultation.forEach((item) {
|
|
var i = listConsultations.indexWhere((x) => x.procedureID == item.procedureID);
|
|
if (i <= -1) {
|
|
listConsultations.add(item);
|
|
}
|
|
});
|
|
|
|
listConsultations.forEach((element) {
|
|
print(element.procedureID);
|
|
this.totalServiceRate += element.total;
|
|
this.totalDiscount += element.discountAmount;
|
|
this.totalVAT += element.totalVATAmount;
|
|
});
|
|
|
|
this.subTotal = this.totalServiceRate - this.totalDiscount;
|
|
this.grandTotal = this.subTotal + this.totalVAT;
|
|
}
|
|
|
|
sendInvoiceEmail() {
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
MyInvoicesService myInvoicesService = new MyInvoicesService();
|
|
|
|
myInvoicesService.sendDentalAppointmentInvoiceEmail(listDentalAppointments.projectID, listDentalAppointments.appointmentNo, context).then((res) {
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
if (res['MessageStatus'] == 1) {
|
|
AppToast.showSuccessToast(message: TranslationBase.of(context).emailSentSuccessfully);
|
|
} else {
|
|
AppToast.showErrorToast(message: res['ErrorEndUserMessage']);
|
|
}
|
|
}).catchError((err) {
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
print(err);
|
|
AppToast.showErrorToast(message: err);
|
|
Navigator.of(context).pop();
|
|
});
|
|
}
|
|
|
|
List<TableRow> fullData(context) {
|
|
List<TableRow> tableRow = [];
|
|
dentalInvoiceDetailResponse.listEInvoiceForDental[0].listConsultation.forEach((lab) {
|
|
tableRow.add(
|
|
TableRow(children: [
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: Text(lab.procedureName, textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontWeight: FontWeight.w400)),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: Text(lab.quantity.toString(), textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontWeight: FontWeight.w400)),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: Text(lab.price.toString() + " " + TranslationBase.of(context).sar, textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontWeight: FontWeight.w400)),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 10.0),
|
|
child: Text(lab.total.toString() + " " + TranslationBase.of(context).sar, textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontWeight: FontWeight.w400)),
|
|
),
|
|
]),
|
|
);
|
|
});
|
|
return tableRow;
|
|
}
|
|
}
|