2024-07-11 01:27:35 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2024-02-08 00:52:29 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
|
|
|
import 'package:form_builder_validators/form_builder_validators.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
import 'package:searchfield/searchfield.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'package:unit2/bloc/offline/offline_passo/admin/unit_construction/unit_construction_admin_bloc.dart';
|
|
|
|
import 'package:unit2/bloc/offline/offline_passo/building/building_and_structure/building_and_structure_bloc.dart';
|
|
|
|
import 'package:unit2/model/offline/offline_profile.dart';
|
|
|
|
import 'package:unit2/model/passo/building_and_structure.dart';
|
|
|
|
|
|
|
|
import '../../../../../model/passo/unit_construct.dart';
|
|
|
|
import '../../../../../theme-data.dart/form-style.dart';
|
|
|
|
import '../../../../../widgets/passo/custom_formBuilder_fields.dart';
|
|
|
|
|
2024-07-11 01:27:35 +00:00
|
|
|
// Function to get stored building type
|
|
|
|
Future<UnitConstruct> getStoredBldgType() async {
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
String? jsonString = prefs.getString('selected_bldg_type');
|
|
|
|
if (jsonString != null) {
|
|
|
|
Map<String, dynamic> json = jsonDecode(jsonString);
|
|
|
|
return UnitConstruct.fromJson(json);
|
|
|
|
}
|
|
|
|
// Return a default UnitConstruct if no data is found
|
|
|
|
return UnitConstruct.defaultConstruct();
|
|
|
|
}
|
|
|
|
|
2024-02-08 00:52:29 +00:00
|
|
|
class AddBuildingAndStructureOffline extends StatefulWidget {
|
|
|
|
final OfflineProfile offlineProfile;
|
|
|
|
AddBuildingAndStructureOffline(this.offlineProfile);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_AddBuildingAndStructureOffline createState() =>
|
|
|
|
_AddBuildingAndStructureOffline();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AddBuildingAndStructureOffline
|
|
|
|
extends State<AddBuildingAndStructureOffline> {
|
|
|
|
GlobalKey<FormBuilderState> formKey = GlobalKey<FormBuilderState>();
|
|
|
|
final focus = FocusNode();
|
|
|
|
|
|
|
|
final DateTime now;
|
|
|
|
final String formatter;
|
|
|
|
|
|
|
|
_AddBuildingAndStructureOffline()
|
|
|
|
: now = DateTime.now(),
|
2024-07-11 01:27:35 +00:00
|
|
|
formatter = DateFormat.yMMMMd('en_US').format(DateTime.now()),
|
|
|
|
_unitConstruct = UnitConstruct.defaultConstruct();
|
2024-02-08 00:52:29 +00:00
|
|
|
|
|
|
|
final actual_use = [
|
|
|
|
"Residential",
|
|
|
|
"Agricultural",
|
|
|
|
"Commercial",
|
|
|
|
"Industrial",
|
|
|
|
"Mineral",
|
|
|
|
"Timberland",
|
|
|
|
];
|
|
|
|
double _unitBase = 0;
|
|
|
|
String _structureType = "";
|
|
|
|
double _areaValue = 0;
|
|
|
|
double _depRate = 0;
|
2024-07-11 01:27:35 +00:00
|
|
|
UnitConstruct _unitConstruct;
|
|
|
|
bool _isLoading = true;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_loadData();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _loadData() async {
|
|
|
|
UnitConstruct unitConstruct = await getStoredBldgType();
|
|
|
|
setState(() {
|
|
|
|
_unitConstruct = unitConstruct;
|
|
|
|
_isLoading = false;
|
|
|
|
});
|
|
|
|
}
|
2024-02-08 00:52:29 +00:00
|
|
|
|
|
|
|
double _totalMarketValue(unitBase, bldgArea) {
|
|
|
|
return unitBase * bldgArea;
|
|
|
|
}
|
|
|
|
|
|
|
|
double _amountofDepreciation(unitBase, area, depreciation) {
|
|
|
|
return (unitBase * area) * depreciation;
|
|
|
|
}
|
|
|
|
|
|
|
|
double _adjustedMarketValue(unitBase, area, depreciation) {
|
|
|
|
double marketVal = unitBase * area;
|
|
|
|
double depAmount = (unitBase * area) * depreciation;
|
|
|
|
return marketVal - depAmount;
|
|
|
|
}
|
|
|
|
|
2024-07-11 01:27:35 +00:00
|
|
|
void assignSelectedBldgValues() async {
|
|
|
|
UnitConstruct? storedBldgType = await getStoredBldgType();
|
|
|
|
_unitBase = double.parse(storedBldgType!.unitValue);
|
|
|
|
_structureType = '${storedBldgType.bldgType} - ${storedBldgType.building}';
|
|
|
|
|
|
|
|
formKey.currentState!.patchValue({'unit_value': storedBldgType.unitValue});
|
|
|
|
}
|
|
|
|
|
2024-02-08 00:52:29 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return BlocConsumer<BuildingAndStructureBloc, BuildingAndStructureState>(
|
|
|
|
listener: (context, state) {
|
|
|
|
// TODO: implement listener
|
|
|
|
},
|
|
|
|
builder: (context, state) {
|
|
|
|
print(state);
|
|
|
|
if (state is ShowBldgAndStructuresScreen) {
|
|
|
|
return BlocConsumer<UnitConstructionAdminBloc,
|
|
|
|
UnitConstructionAdminState>(
|
|
|
|
listener: (context, state) {
|
|
|
|
// TODO: implement listener
|
|
|
|
},
|
|
|
|
builder: (context, state) {
|
|
|
|
if (state is UnitConstructLoaded) {
|
|
|
|
return FormBuilder(
|
|
|
|
key: formKey,
|
|
|
|
onChanged: () {
|
|
|
|
formKey.currentState?.save();
|
|
|
|
},
|
|
|
|
autovalidateMode: AutovalidateMode.disabled,
|
2024-03-21 05:47:57 +00:00
|
|
|
child: SingleChildScrollView(
|
|
|
|
padding: const EdgeInsets.all(2.0),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
2024-07-11 01:27:35 +00:00
|
|
|
Container(
|
|
|
|
margin: const EdgeInsets.only(
|
|
|
|
left: 0, top: 10, right: 0, bottom: 0),
|
|
|
|
child: FormBuilderDropdown<String?>(
|
|
|
|
name: 'actual_use',
|
|
|
|
autofocus: false,
|
|
|
|
decoration: normalTextFieldStyle("Actual Use", ""),
|
|
|
|
items: actual_use
|
|
|
|
.map((item) => DropdownMenuItem(
|
|
|
|
value: item,
|
|
|
|
child: Text(item),
|
|
|
|
))
|
|
|
|
.toList(),
|
|
|
|
onChanged: (value) {
|
|
|
|
assignSelectedBldgValues();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
2024-03-21 05:47:57 +00:00
|
|
|
Container(
|
|
|
|
margin: const EdgeInsets.only(
|
|
|
|
left: 0, top: 10, right: 0, bottom: 0),
|
|
|
|
child: SizedBox(
|
|
|
|
height: 45,
|
|
|
|
child: SearchField(
|
2024-07-11 01:27:35 +00:00
|
|
|
enabled: false,
|
2024-03-21 05:47:57 +00:00
|
|
|
itemHeight: 70,
|
|
|
|
suggestions: state.unit
|
|
|
|
.map((UnitConstruct unit) =>
|
|
|
|
SearchFieldListItem(
|
|
|
|
'${unit.bldgType} - ${unit.building}',
|
|
|
|
item: unit,
|
|
|
|
child: ListTile(
|
|
|
|
title: Text(
|
|
|
|
'${unit.bldgType} - ${unit.building!.toUpperCase()}',
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
)))
|
|
|
|
.toList(),
|
2024-02-08 00:52:29 +00:00
|
|
|
|
2024-03-21 05:47:57 +00:00
|
|
|
validator: FormBuilderValidators.required(
|
|
|
|
errorText: "This field is required"),
|
2024-02-08 00:52:29 +00:00
|
|
|
|
2024-03-21 05:47:57 +00:00
|
|
|
searchInputDecoration: normalTextFieldStyle(
|
2024-07-11 01:27:35 +00:00
|
|
|
_unitConstruct!.bldgType +
|
|
|
|
' - ' +
|
|
|
|
_unitConstruct!.building,
|
|
|
|
"")
|
2024-03-21 05:47:57 +00:00
|
|
|
.copyWith(
|
|
|
|
suffixIcon:
|
|
|
|
const Icon(Icons.arrow_drop_down)),
|
|
|
|
////agency suggestion tap
|
|
|
|
focusNode: focus,
|
|
|
|
suggestionState: Suggestion.expand,
|
|
|
|
onSuggestionTap: (unit) {
|
2024-07-11 01:27:35 +00:00
|
|
|
setState(() {});
|
2024-03-21 05:47:57 +00:00
|
|
|
focus.unfocus();
|
|
|
|
},
|
2024-02-08 00:52:29 +00:00
|
|
|
),
|
2024-03-21 05:47:57 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
child: FormBuilderTextField(
|
|
|
|
name: 'unit_value',
|
|
|
|
decoration: normalTextFieldStyle("Unit Value", ""),
|
|
|
|
validator: FormBuilderValidators.compose([]),
|
2024-07-11 01:27:35 +00:00
|
|
|
keyboardType: TextInputType.phone,
|
2024-03-21 05:47:57 +00:00
|
|
|
onChanged: (value) {
|
|
|
|
// setState(() {
|
|
|
|
// _areaValue = int.parse(value!);
|
|
|
|
// });
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: FormBuilderTextField(
|
|
|
|
name: 'dep_rate',
|
|
|
|
decoration: normalTextFieldStyle(
|
|
|
|
"Depreciation Rate", ""),
|
2024-07-11 01:27:35 +00:00
|
|
|
keyboardType: TextInputType.phone,
|
2024-03-21 05:47:57 +00:00
|
|
|
validator: FormBuilderValidators.compose([]),
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_depRate = double.parse(value!);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
2024-02-08 00:52:29 +00:00
|
|
|
),
|
|
|
|
const SizedBox(
|
2024-03-21 05:47:57 +00:00
|
|
|
width: 5,
|
2024-02-08 00:52:29 +00:00
|
|
|
),
|
2024-03-21 05:47:57 +00:00
|
|
|
Expanded(
|
2024-02-08 00:52:29 +00:00
|
|
|
child: FormBuilderTextField(
|
2024-03-21 05:47:57 +00:00
|
|
|
name: 'bldg_area',
|
|
|
|
decoration: normalTextFieldStyle("Area", ""),
|
2024-02-08 00:52:29 +00:00
|
|
|
validator: FormBuilderValidators.compose([]),
|
2024-07-11 01:27:35 +00:00
|
|
|
keyboardType: TextInputType.phone,
|
2024-02-08 00:52:29 +00:00
|
|
|
onChanged: (value) {
|
2024-03-21 05:47:57 +00:00
|
|
|
setState(() {
|
|
|
|
_areaValue = double.parse(value!);
|
|
|
|
});
|
2024-02-08 00:52:29 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2024-03-21 05:47:57 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
const Text('Market Value'),
|
|
|
|
const SizedBox(height: 5),
|
|
|
|
Container(
|
|
|
|
height: 45.0,
|
|
|
|
width: double.infinity,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.white,
|
|
|
|
border: Border.all(
|
|
|
|
color: Colors.grey,
|
|
|
|
width: 1.0,
|
2024-02-08 00:52:29 +00:00
|
|
|
),
|
2024-03-21 05:47:57 +00:00
|
|
|
borderRadius: BorderRadius.circular(5.0),
|
|
|
|
),
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(NumberFormat.currency(
|
|
|
|
locale: 'en-PH', symbol: "₱")
|
|
|
|
.format(_totalMarketValue(
|
|
|
|
_unitBase, _areaValue)))),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
const Text('Amount of Depreciation'),
|
|
|
|
const SizedBox(height: 5),
|
|
|
|
Container(
|
|
|
|
height: 45.0,
|
|
|
|
width: double.infinity,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.white,
|
|
|
|
border: Border.all(
|
|
|
|
color: Colors.grey,
|
|
|
|
width: 1.0,
|
2024-02-08 00:52:29 +00:00
|
|
|
),
|
2024-03-21 05:47:57 +00:00
|
|
|
borderRadius: BorderRadius.circular(5.0),
|
|
|
|
),
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(NumberFormat.currency(
|
|
|
|
locale: 'en-PH', symbol: "₱")
|
|
|
|
.format(_amountofDepreciation(
|
|
|
|
_unitBase, _areaValue, _depRate)))),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
const Text('Adjusted Market Value'),
|
|
|
|
const SizedBox(height: 5),
|
|
|
|
Container(
|
|
|
|
height: 45.0,
|
|
|
|
width: double.infinity,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.white,
|
|
|
|
border: Border.all(
|
|
|
|
color: Colors.grey,
|
|
|
|
width: 1.0,
|
2024-02-08 00:52:29 +00:00
|
|
|
),
|
2024-03-21 05:47:57 +00:00
|
|
|
borderRadius: BorderRadius.circular(5.0),
|
|
|
|
),
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Text(NumberFormat.currency(
|
|
|
|
locale: 'en-PH', symbol: "₱")
|
|
|
|
.format(_adjustedMarketValue(
|
|
|
|
_unitBase, _areaValue, _depRate)))),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
2024-02-08 00:52:29 +00:00
|
|
|
Container(
|
2024-03-21 05:47:57 +00:00
|
|
|
width: 120,
|
|
|
|
height: 60,
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: ElevatedButton(
|
|
|
|
onPressed: () async {
|
|
|
|
try {
|
|
|
|
final tempID =
|
|
|
|
await SharedPreferences.getInstance();
|
|
|
|
var bldgStructure = BldgAndStructure(
|
|
|
|
id: 1,
|
|
|
|
bldgapprDetailsId: tempID.getInt(
|
|
|
|
'tempid')!,
|
|
|
|
// assessedById: widget
|
|
|
|
// .offlineProfile.id
|
|
|
|
// .toString(),
|
|
|
|
// assessedByName: widget
|
|
|
|
// .offlineProfile.firstName,
|
|
|
|
// dateCreated: formatter,
|
|
|
|
// dateModified: 'none',
|
|
|
|
bldgType: _structureType,
|
|
|
|
structType: _structureType,
|
|
|
|
description: 'None',
|
|
|
|
buccPercentage: '1',
|
|
|
|
actualUse: formKey.currentState?.value[
|
|
|
|
'actual_use'] ??
|
|
|
|
"",
|
|
|
|
floorCount: '1',
|
|
|
|
bldgArea: _areaValue.toString(),
|
|
|
|
unitValue: _unitBase.toString(),
|
|
|
|
depRate: _depRate.toString(),
|
|
|
|
marketValue: _totalMarketValue(
|
|
|
|
_unitBase, _areaValue)
|
|
|
|
.toString(),
|
|
|
|
depAmount: _amountofDepreciation(
|
|
|
|
_unitBase, _areaValue, _depRate)
|
|
|
|
.toString(),
|
|
|
|
adjustedMarketValue:
|
|
|
|
_adjustedMarketValue(_unitBase,
|
|
|
|
_areaValue, _depRate)
|
|
|
|
.toString(),
|
|
|
|
genCode: "5TH");
|
|
|
|
context
|
|
|
|
.read<BuildingAndStructureBloc>()
|
|
|
|
.add(AddBuildingAndStructure(
|
|
|
|
bldgAndStructure: bldgStructure));
|
|
|
|
} catch (e) {
|
|
|
|
print(e);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
style: ElevatedButton.styleFrom(
|
2024-07-11 01:27:35 +00:00
|
|
|
backgroundColor: Colors.black,
|
2024-02-08 00:52:29 +00:00
|
|
|
),
|
2024-03-21 05:47:57 +00:00
|
|
|
child: const Text("Submit"),
|
2024-02-08 00:52:29 +00:00
|
|
|
),
|
|
|
|
),
|
2024-03-21 05:47:57 +00:00
|
|
|
const SizedBox(
|
|
|
|
width:
|
|
|
|
5), // Use SizedBox for horizontal spacing in a Row
|
2024-02-08 00:52:29 +00:00
|
|
|
Container(
|
2024-03-21 05:47:57 +00:00
|
|
|
width: 120,
|
|
|
|
height: 60,
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: ElevatedButton(
|
|
|
|
onPressed: () {
|
|
|
|
context
|
|
|
|
.read<BuildingAndStructureBloc>()
|
|
|
|
.add(const LoadBuildingAndStructure());
|
|
|
|
},
|
|
|
|
style: ElevatedButton.styleFrom(
|
2024-07-11 01:27:35 +00:00
|
|
|
backgroundColor: Colors.black,
|
2024-02-08 00:52:29 +00:00
|
|
|
),
|
2024-03-21 05:47:57 +00:00
|
|
|
child: const Text("Cancel"),
|
2024-02-08 00:52:29 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2024-03-21 05:47:57 +00:00
|
|
|
)
|
|
|
|
],
|
2024-02-08 00:52:29 +00:00
|
|
|
),
|
|
|
|
),
|
2024-07-11 01:27:35 +00:00
|
|
|
); // Use your actual widget
|
2024-02-08 00:52:29 +00:00
|
|
|
}
|
|
|
|
return Container();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return Container();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|