first commit
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import 'package:mobile_pos/generated/l10n.dart' as lang;
|
||||
|
||||
class AmountRoundingDropdownModel {
|
||||
late String value;
|
||||
late String option;
|
||||
|
||||
AmountRoundingDropdownModel({required this.value, required this.option});
|
||||
}
|
||||
|
||||
final List<AmountRoundingDropdownModel> roundingMethods = [
|
||||
AmountRoundingDropdownModel(value: 'none', option: lang.S.current.none),
|
||||
AmountRoundingDropdownModel(value: 'round_up', option: lang.S.current.roundToWholeNumber),
|
||||
AmountRoundingDropdownModel(value: 'nearest_whole_number', option: lang.S.current.roundToNearestWholeNumber),
|
||||
AmountRoundingDropdownModel(value: 'nearest_0.05', option: lang.S.current.roundToNearnessDecimalNumber005),
|
||||
AmountRoundingDropdownModel(value: 'nearest_0.1', option: lang.S.current.roundToNearnessDecimalNumber01),
|
||||
AmountRoundingDropdownModel(value: 'nearest_0.5', option: lang.S.current.roundToNearnessDecimalNumber05),
|
||||
];
|
||||
|
||||
num roundNumber({required num value, required String roundingType}) {
|
||||
switch (roundingType) {
|
||||
case "none":
|
||||
return value;
|
||||
|
||||
case "round_up":
|
||||
return value.ceilToDouble();
|
||||
|
||||
case "nearest_whole_number":
|
||||
return value.roundToDouble();
|
||||
|
||||
case "nearest_0.05":
|
||||
return (value / 0.05).round() * 0.05;
|
||||
|
||||
case "nearest_0.1":
|
||||
return (value / 0.1).round() * 0.1;
|
||||
|
||||
case "nearest_0.5":
|
||||
return (value / 0.5).round() * 0.5;
|
||||
|
||||
default:
|
||||
return value;
|
||||
}
|
||||
}
|
||||
116
lib/Screens/Settings/sales settings/sales_settings_screen.dart
Normal file
116
lib/Screens/Settings/sales settings/sales_settings_screen.dart
Normal file
@@ -0,0 +1,116 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:mobile_pos/generated/l10n.dart' as lang;
|
||||
|
||||
import '../../../GlobalComponents/glonal_popup.dart';
|
||||
import '../../../Provider/profile_provider.dart';
|
||||
import '../../../Repository/API/business_info_update_repo.dart';
|
||||
import '../../../constant.dart';
|
||||
import 'model/amount_rounding_dropdown_model.dart';
|
||||
|
||||
class SalesSettingsScreen extends ConsumerStatefulWidget {
|
||||
const SalesSettingsScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<SalesSettingsScreen> createState() => _PrintingInvoiceScreenState();
|
||||
}
|
||||
|
||||
class _PrintingInvoiceScreenState extends ConsumerState<SalesSettingsScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
ref.read(businessInfoProvider).when(
|
||||
data: (data) {
|
||||
setState(() {
|
||||
selectedMethod = roundingMethods.firstWhere(
|
||||
(element) => element.value == data.data?.saleRoundingOption,
|
||||
);
|
||||
});
|
||||
},
|
||||
error: (error, stackTrace) {},
|
||||
loading: () {},
|
||||
);
|
||||
}
|
||||
|
||||
AmountRoundingDropdownModel? selectedMethod = roundingMethods[0];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final _lang = lang.S.of(context);
|
||||
return GlobalPopup(
|
||||
child: Scaffold(
|
||||
backgroundColor: kWhite,
|
||||
appBar: AppBar(
|
||||
iconTheme: const IconThemeData(color: Colors.black),
|
||||
title: Text(
|
||||
_lang.salesSetting,
|
||||
),
|
||||
centerTitle: true,
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0.0,
|
||||
),
|
||||
bottomNavigationBar: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: ElevatedButton(
|
||||
child: Text(lang.S.of(context).save),
|
||||
onPressed: () async {
|
||||
ref.watch(businessInfoProvider).when(
|
||||
data: (data) async {
|
||||
final businessRepository = BusinessUpdateRepository();
|
||||
final isProfileUpdated = await businessRepository.updateSalesSettings(
|
||||
id: data.data?.id.toString() ?? '',
|
||||
ref: ref,
|
||||
context: context,
|
||||
saleRoundingOption: selectedMethod?.value,
|
||||
);
|
||||
|
||||
if (isProfileUpdated) {
|
||||
ref.refresh(businessInfoProvider);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
error: (error, stackTrace) {},
|
||||
loading: () {},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(15.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 15,
|
||||
children: [
|
||||
Text(
|
||||
'${_lang.amountRoundingMethod}:',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
DropdownButtonFormField<AmountRoundingDropdownModel>(
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: _lang.amountRoundingMethod,
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
value: selectedMethod,
|
||||
items: roundingMethods.map((method) {
|
||||
return DropdownMenuItem<AmountRoundingDropdownModel>(
|
||||
value: method,
|
||||
child: Text(method.option),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
selectedMethod = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user