Untitled
unknown
plain_text
7 months ago
180 kB
5
Indexable
import 'dart:convert';
import 'dart:core';
import 'dart:io';
import 'package:collection/collection.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:frigg/core/config/router.dart';
import 'package:frigg/core/config/theme.dart';
import 'package:frigg/core/entities/dropdown_item.dart';
import 'package:frigg/core/platform/sources.dart';
import 'package:frigg/core/provider/localization.dart';
import 'package:frigg/core/service/constants.dart';
import "package:frigg/core/service/extension.dart";
import 'package:frigg/core/service/utilities.dart';
import 'package:frigg/core/widget/alert_notification.dart';
import 'package:frigg/core/widget/attachment_document.dart';
import 'package:frigg/core/widget/button_add_label.dart';
import 'package:frigg/core/widget/confirmation_bottom_sheet.dart';
import 'package:frigg/core/widget/datetime_picker.dart';
import 'package:frigg/core/widget/label_card_item.dart';
import 'package:frigg/core/widget/loading_overlay.dart';
import 'package:frigg/core/widget/shimmer_widget.dart';
import 'package:frigg/core/widget/skelton.dart';
import 'package:frigg/core/widget/table_row_spacer.dart';
import 'package:frigg/features/order/presentation/fragments/purchase_order_form_payment_fragment.dart';
import 'package:frigg/features/order/presentation/widgets/purchase_order_form_dropdown_group.dart';
import 'package:frigg/features/order/presentation/widgets/purchase_order_form_payment_card.dart';
import 'package:frigg/features/order/presentation/widgets/purchase_order_form_product_card.dart';
import 'package:frigg/features/order/presentation/widgets/purchase_order_form_select_address_bottom_sheet.dart';
import 'package:frigg/features/order/presentation/widgets/purchase_order_form_total_info.dart';
import 'package:frigg/features/order/presentation/widgets/purchase_order_quotation_card.dart';
import 'package:frigg/features/order/presentation/widgets/purchase_order_revise_form_bottom_sheet.dart';
import 'package:frigg/features/order/provider/add_attachment_provider.dart';
import 'package:frigg/features/order/provider/apply_quotation_provider.dart';
import 'package:frigg/features/order/provider/assign_project_provider.dart';
import 'package:frigg/features/order/provider/change_company_provider.dart';
import 'package:frigg/features/order/provider/change_delivery_amount_provider.dart';
import 'package:frigg/features/order/provider/change_delivery_type_provider.dart';
import 'package:frigg/features/order/provider/change_payment_type_provider.dart';
import 'package:frigg/features/order/provider/change_shipping_address_provider.dart';
import 'package:frigg/features/order/provider/change_type_provider.dart';
import 'package:frigg/features/order/provider/dismiss_quotation_provider.dart';
import 'package:frigg/features/order/provider/get_delivery_types.dart';
import 'package:frigg/features/order/provider/get_order_types_provider.dart';
import 'package:frigg/features/order/provider/get_purchase_order_provider.dart';
import 'package:frigg/features/order/provider/list/sales_order.dart';
import 'package:frigg/features/order/provider/list_item_order_provider.dart';
import 'package:frigg/features/order/provider/list_purchase_order_type_provider.dart';
import 'package:frigg/features/order/provider/list_revise_category_provider.dart';
import 'package:frigg/features/order/provider/purchase_order_form_provider.dart';
import 'package:frigg/features/order/provider/purchase_order_revise_reason_provider.dart';
import 'package:frigg/features/order/provider/refresh_validation_purchase_order.dart';
import 'package:frigg/features/order/provider/remove_attachment_provider.dart';
import 'package:frigg/features/order/provider/remove_company_provider.dart';
import 'package:frigg/features/order/provider/remove_item_provider.dart';
import 'package:frigg/features/order/provider/remove_project_provider.dart';
import 'package:frigg/features/order/provider/save_as_draft_provider.dart';
import 'package:frigg/features/order/provider/submit_purchase_order_provider.dart';
import 'package:frigg/features/order/provider/update_date_provider.dart';
import 'package:frigg/features/order/provider/update_item_provider.dart';
import 'package:frigg/features/order/provider/update_revise_purchase_order_provider.dart';
import 'package:frigg/features/profile/provider/get_list_permission_by_role_provider.dart';
import 'package:frigg/protos/google/type/date.pb.dart';
import 'package:frigg/protos/thor/endpoints/delivery_type.pb.dart';
import 'package:frigg/protos/thor/endpoints/item.pb.dart';
import 'package:frigg/protos/thor/endpoints/order_address.pbenum.dart';
import 'package:frigg/protos/thor/endpoints/order_type.pb.dart';
import 'package:frigg/protos/thor/endpoints/purchase_order_type.pb.dart';
import 'package:frigg/protos/thor/endpoints/revise_purchase_order_category.pb.dart';
import 'package:frigg/protos/thor/endpoints/sales_order.pb.dart';
import 'package:frigg/protos/thor/entities/company.pb.dart';
import 'package:frigg/protos/thor/entities/delivery.pb.dart';
import 'package:frigg/protos/thor/entities/delivery_type.pb.dart';
import 'package:frigg/protos/thor/entities/discount_type.pbenum.dart';
import 'package:frigg/protos/thor/entities/file.pb.dart' as document;
import 'package:frigg/protos/thor/entities/order_address.pb.dart';
import 'package:frigg/protos/thor/entities/project.pb.dart';
import 'package:frigg/protos/thor/entities/purchase_order.pb.dart';
import 'package:frigg/protos/thor/entities/purchase_order_item.pb.dart';
import 'package:frigg/protos/thor/entities/purchase_order_payment_type.pb.dart';
import 'package:frigg/protos/thor/entities/purchase_order_type.pb.dart';
import 'package:frigg/protos/thor/entities/quotation.pb.dart';
import 'package:frigg/protos/thor/entities/revise_purchase_order_category.pb.dart';
import 'package:frigg/protos/thor/entities/tax.pbenum.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path/path.dart' as pathFile;
import 'package:uuid/uuid.dart';
class PurchaseOrderFormFragment extends HookConsumerWidget {
final ValueNotifier paymentTypeState;
final ValueNotifier<int?> paymentTypeIndex;
const PurchaseOrderFormFragment({
super.key,
required this.paymentTypeState,
required this.paymentTypeIndex,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
ref.watch(listSalesOrderProvider);
ref.watch(useCaseGetListPurchaseOrderType(UseCaseParams(
context: context, request: ListPurchaseOrderTypeRequest())));
ref.watch(
useCaseGetListOrderType(
UseCaseParams(context: context, request: ListOrderTypeRequest()),
),
);
ref.watch(
useCaseGetListDeliveryType(
UseCaseParams(context: context, request: ListDeliveryTypeRequest()),
),
);
final languageCode = ref.watch(localizationProvider).locale.languageCode;
final purchaseOrderFormState = ref.watch(purchaseOrderFormProvider)!;
final purchaseOrderReviseReasonState =
purchaseOrderFormState.status == PurchaseOrderFormStatus.Revise
? ref.watch(purchaseOrderReviseReasonProvider)
: PurchaseOrderReviseReason();
final viewPurchaseOrderState = ref.watch(viewPurchaseOrderProvider);
final deliveryTypeState = ref.watch(listDeliveryTypeProvider);
final listPurchaseOrderTypeState = ref.watch(listPurchaseOrderTypeProvider);
final notesDebouncer = Debouncer(const Duration(seconds: 1));
final deliveryTypeEditableValueState = useState(false);
final paymentEditableValueState = useState(false);
final onChangeTypeState = ref.watch(changeTypeProvider);
final onChangeCustomerState = ref.watch(changeCompanyProvider);
final onRemoveCustomerState = ref.watch(removeCompanyProvider);
final onAssignProjectState = ref.watch(assignProjectProvider);
final onRemoveProjectState = ref.watch(removeProjectProvider);
final onRefreshValidation = ref.watch(refreshValidationProvider);
final onChangeShippingAddressState =
ref.watch(changeShippingAddressProvider);
final onChangeDateState = ref.watch(updateDateProvider);
final onChangeDeliveryTypeState = ref.watch(changeDeliveryTypeProvider);
final onChangePaymentTypeState = ref.watch(changePaymentTypeProvider);
final onAddAttachmentState = ref.watch(addAttachmentProvider);
final onRemoveAttachmentState = ref.watch(removeAttachmentProvider);
final onRemoveItemState = ref.watch(removeItemProvider);
final onUpdateItemState = ref.watch(updateItemProvider);
final onApplyQuotationState = ref.watch(applyQuotationProvider);
final onDismissQuotationState = ref.watch(dismissQuotationProvider);
final onSaveAsDraftState = ref.watch(savePurchaseOrderAsDraftProvider);
final onSubmitOrderState = ref.watch(submitPurchaseOrderProvider);
final onUpdateRevisePurchaseOrderState =
ref.watch(updateRevisePurchaseOrderProvider);
final onChangeDeliveryAmount = ref.watch(updateDeliveryProvider);
final purchaseOrderPaymentTypeState =
useState(viewPurchaseOrderState.value.purchaseOrder.paymentType);
final listPermissionByRole = ref.watch(listPermissionByRoleProvider);
final labelValidation = {
Company_OrderState.ORDER_STATE_INVALID_COMPANY_USER:
AppLocalizations.of(context)!.orderValidationCompanyInvalidUser,
Project_OrderState.ORDER_STATE_INVALID_PROJECT_USER:
AppLocalizations.of(context)!.orderValidationProjectInvalidUser,
OrderAddress_OrderState.ORDER_STATE_INVALID_ADDRESS: AppLocalizations.of(
context)!
.orderValidationCompanyAddressInvalid(viewPurchaseOrderState
.value.purchaseOrder.type.name ==
'regular'
? AppLocalizations.of(context)!.textCompany
: "${AppLocalizations.of(context)!.textCompany}/${AppLocalizations.of(context)!.textProject}"),
PurchaseOrder_OrderState.ORDER_STATE_INVALID_DATE_BASED_ON_COMPANY:
AppLocalizations.of(context)!.orderValidationDateInvalidCompany,
PurchaseOrder_OrderState.ORDER_STATE_INVALID_DATE_BASED_ON_PROJECT:
AppLocalizations.of(context)!.orderValidationDateInvalidProject,
PurchaseOrderPaymentType_OrderState.ORDER_STATE_INVALID_QUOTATION:
AppLocalizations.of(context)!
.orderValidationPaymentTypeInvalidQuotation,
Quotation_OrderState.ORDER_STATE_INVALID_COMPANY:
AppLocalizations.of(context)!.orderValidationQuotationInvalidCompany,
Quotation_OrderState.ORDER_STATE_INVALID_PURCHASE_ORDER_PROJECT:
AppLocalizations.of(context)!.orderValidationQuotationInvalidProject,
Quotation_OrderState.ORDER_STATE_INVALID_PURCHASE_ORDER_ITEM:
AppLocalizations.of(context)!.orderValidationQuotationInvalidItem,
Quotation_OrderState.ORDER_STATE_INVALID_PURCHASE_ORDER_TYPE:
AppLocalizations.of(context)!.orderValidationQuotationInvalidType,
Quotation_OrderState.ORDER_STATE_INVALID_QUOTATION_DATE:
AppLocalizations.of(context)!.orderValidationQuotationInvalidDate,
PurchaseOrderItem_OrderState.ORDER_STATE_INVALID_COMPANY:
AppLocalizations.of(context)!.orderValidationItemInvalidCompany,
PurchaseOrderItem_OrderState.ORDER_STATE_INVALID_PROJECT:
AppLocalizations.of(context)!.orderValidationItemInvalidProject,
PurchaseOrderItem_OrderState.ORDER_STATE_INVALID_PRICE:
AppLocalizations.of(context)!.orderValidationItemInvalidPrice,
Tax_OrderState.ORDER_STATE_INVALID_PERIOD_TAX:
AppLocalizations.of(context)!.orderValidationTaxInvalidPeriod,
};
final addressWidgetConditions = [
{
"title": AppLocalizations.of(context)!.textAddressDelivery,
"type":
ListOrderAddressFilter_AddressType.ADDRESS_TYPE_SHIPPING_ADDRESS,
"address": viewPurchaseOrderState.value.purchaseOrder.shipTo,
"action": (ListOrderAddressFilter_AddressType type) =>
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (ctx) => PurchaseOrderFormSelectAddressBottomSheet(
type: utils.convert<ListOrderAddressFilter_AddressType>(type),
onSelected: (_) => purchaseOrderFormState
.onChangeShippingAddress(ref, context, _),
),
)
},
{
"title": AppLocalizations.of(context)!.textAddressInvoice,
"type": ListOrderAddressFilter_AddressType.ADDRESS_TYPE_BILLING_ADDRESS,
"address": viewPurchaseOrderState.value.purchaseOrder.billingTo,
"action": (ListOrderAddressFilter_AddressType type) =>
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (ctx) => PurchaseOrderFormSelectAddressBottomSheet(
type: utils.convert<ListOrderAddressFilter_AddressType>(type),
onSelected: (_) => purchaseOrderFormState
.onChangeBillingAddress(ref, context, _),
),
)
},
];
bool getLoadingFormState() =>
onChangeCustomerState.loading.data ||
onAssignProjectState.loading.data ||
onRemoveProjectState.loading.data ||
onChangeShippingAddressState.loading.data ||
onChangeDateState.loading.data ||
onChangeDeliveryTypeState.loading.data ||
onAddAttachmentState.loading.data ||
onRemoveAttachmentState.loading.data ||
onRemoveItemState.loading.data ||
onUpdateItemState.loading.data ||
onRefreshValidation.loading.data ||
onApplyQuotationState.loading.data ||
onDismissQuotationState.loading.data ||
onSaveAsDraftState.loading.data ||
onSubmitOrderState.loading.data ||
onChangeDeliveryTypeState.loading.data ||
onChangeDeliveryAmount.loading.data ||
onUpdateRevisePurchaseOrderState.loading.data;
Future<void> pickFileFromStorage() async {
try {
PlatformFile? file =
(await FilePicker.platform.pickFiles(allowMultiple: false))
?.files
.first;
if (file != null && file.path != null) {
purchaseOrderFormState.onAddAttachment(
ref,
context,
viewPurchaseOrderState.value.purchaseOrder.id,
document.File(
fileName:
"${const Uuid().v1()}.${pathFile.extension(file.path!).replaceAll('.', '').toLowerCase()}",
extension_3: pathFile
.extension(file.path!)
.replaceAll('.', '')
.toLowerCase(),
base64: base64Encode(File(["jpeg", "jpg", "png"].contains(pathFile
.extension(file.path!)
.replaceAll('.', '')
.toLowerCase()
.trim())
? (await compressImage(file.path!)).path
: file.path!)
.readAsBytesSync()),
),
);
}
} catch (_) {
_.runtimeType;
}
}
Future<void> pickImageFromStorage(ImageSource source) async {
try {
final XFile? file = await ImagePicker().pickImage(
source: source,
);
if (file != null) {
File resultFile = await compressImage(file.path);
purchaseOrderFormState.onAddAttachment(
ref,
context,
viewPurchaseOrderState.value.purchaseOrder.id,
document.File(
fileName:
"${const Uuid().v1()}.${pathFile.extension(resultFile.path).replaceAll('.', '').toLowerCase()}",
extension_3: pathFile
.extension(resultFile.path)
.replaceAll('.', '')
.toLowerCase(),
base64: base64Encode(File(resultFile.path).readAsBytesSync()),
),
);
}
} catch (_) {
_.runtimeType;
}
}
useEffect(() {
if (ref.read(purchaseOrderFormProvider)!.status ==
PurchaseOrderFormStatus.Revise) {
ref.read(
useCaseListSalesOrder(
UseCaseParams(
context: context,
request: ListSalesOrderRequest(
filter: ListSalesOrderFilter(
purchaseOrderId: ref
.read(viewPurchaseOrderProvider)
.value
.purchaseOrder
.id,
),
),
),
),
);
ref.watch(useCaseGetListRevisePurchaseOrderCategory(UseCaseParams(
context: context,
request: ListRevisePurchaseOrderCategoryRequest())));
}
return null;
}, []);
useEffect(() {
if (ref.read(viewPurchaseOrderLocalStateProvider).value) {
Future.delayed(Duration.zero, () {
purchaseOrderFormState.onRefreshPurchaseOrderValidation(ref, context);
});
}
return null;
}, []);
return SafeArea(
child: Stack(
children: [
Positioned.fill(
child: RefreshIndicator(
onRefresh: () async {
ref
.read(listPurchaseOrderTypeProvider.notifier)
.setLoading(ResponseLoading(data: true));
ref
.read(listDeliveryTypeProvider.notifier)
.setLoading(ResponseLoading(data: true));
ref.invalidate(useCaseGetListPurchaseOrderType);
ref.invalidate(useCaseGetListDeliveryType);
purchaseOrderFormState.onRefreshPurchaseOrderValidation(ref, context);
},
child: ScrollConfiguration(
behavior: const ScrollBehavior().copyWith(overscroll: false),
child: ListView(
padding: const EdgeInsets.all(20).copyWith(top: 10),
physics: const AlwaysScrollableScrollPhysics(),
children: [
ConstrainedBox(
constraints: BoxConstraints(
minHeight: utils.getFullHeight(context) - 130,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
...(purchaseOrderFormState.status ==
PurchaseOrderFormStatus.Revise
? [
Container(
padding: const EdgeInsets.all(10),
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: Colors.black12, width: 2),
),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.stretch,
children: [
Row(
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Expanded(
child: Text(
AppLocalizations.of(context)!
.orderReasonRevision,
style: Theme.of(context)
.textTheme
.subHead2,
),
),
const SizedBox(width: 10),
TextButton(
onPressed: () {
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (_) => Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(_)
.viewInsets
.bottom,
),
child:
PurchaseOrderReviseFormBottomSheetWidget(
defaultValue:
purchaseOrderReviseReasonState,
),
),
);
},
style: ElevatedButton.styleFrom(
tapTargetSize:
MaterialTapTargetSize
.shrinkWrap,
visualDensity:
const VisualDensity(
horizontal: -4,
vertical: -4),
minimumSize: Size.zero,
padding: EdgeInsets.zero,
),
child: Text(
AppLocalizations.of(context)!
.buttonChange,
style: Theme.of(
context,
).textTheme.subHead3.copyWith(
decoration: TextDecoration
.underline,
color: Theme.of(context)
.primaryColor,
),
),
),
],
),
const SizedBox(height: 5),
Text(
(purchaseOrderReviseReasonState
.category ??
RevisePurchaseOrderCategory(
name: "-"))
.name
.toTitleCase(),
style: Theme.of(context)
.textTheme
.paragraph2,
),
const SizedBox(height: 20),
...(purchaseOrderReviseReasonState
.attachment !=
null
? [
Text(
AppLocalizations.of(context)!
.textAttachment,
style: Theme.of(context)
.textTheme
.subHead2,
),
const SizedBox(height: 5),
AttachmentDocumentWidget(
loading: false,
disablePadding: true,
file:
purchaseOrderReviseReasonState
.attachment!,
),
]
: purchaseOrderReviseReasonState
.remarks !=
null
? [
Text(
AppLocalizations.of(
context)!
.textRemarks,
style: Theme.of(context)
.textTheme
.subHead2,
),
const SizedBox(height: 5),
Text(
purchaseOrderReviseReasonState
.remarks!,
style: Theme.of(context)
.textTheme
.paragraph2,
),
]
: []),
],
),
),
const SizedBox(height: 20)
]
: []),
Text(
AppLocalizations.of(context)!.orderTypeTitle,
style: Theme.of(context).textTheme.subHead2,
),
ShimmerWidget(
isActive: onChangeTypeState.loading.data ||
listPurchaseOrderTypeState.loading.data ||
listPurchaseOrderTypeState.value.types.isEmpty,
child: Column(
children: (listPurchaseOrderTypeState
.loading.data ||
listPurchaseOrderTypeState
.value.types.isEmpty
? List.generate(
2,
(_) => PurchaseOrderType(
id: _.toString(),
name: _.toString()))
: listPurchaseOrderTypeState.value.types)
.mapIndexed(
(_, __) => Theme(
data: Theme.of(context).copyWith(
listTileTheme: const ListTileThemeData(
horizontalTitleGap: 5,
),
),
child: RadioListTile<PurchaseOrderType?>(
toggleable: true,
contentPadding: EdgeInsets.zero,
materialTapTargetSize:
MaterialTapTargetSize.shrinkWrap,
visualDensity: const VisualDensity(
horizontal: -4,
vertical: -4,
),
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(3)),
title: listPurchaseOrderTypeState
.loading.data ||
listPurchaseOrderTypeState
.value.types.isEmpty
? const Skeleton(height: 12)
: Text(
__.name.toTitleCase(),
style: Theme.of(context)
.textTheme
.paragraph3,
),
value: __,
groupValue: viewPurchaseOrderState
.value.purchaseOrder.type,
onChanged: (value) => value != null
? purchaseOrderFormState
.onChangeType(
ref, context, value)
: null,
),
),
)
.toList(),
),
),
const SizedBox(height: 20),
AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
transitionBuilder: (child, animation) =>
FadeTransition(
opacity: animation,
child: SizeTransition(
sizeFactor: animation,
child: child,
),
),
child: viewPurchaseOrderState
.value.purchaseOrder.type.name
.toLowerCase() ==
"project"
? Column(
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Expanded(
child: Text(
AppLocalizations.of(context)!
.textProject,
style: Theme.of(context)
.textTheme
.subHead2,
),
),
const SizedBox(width: 20),
viewPurchaseOrderState
.value
.purchaseOrder
.project
.id
.isNotEmpty
? ShimmerWidget(
isActive: onAssignProjectState
.loading.data ||
onRemoveProjectState
.loading.data,
child: Row(
children: [
TextButton(
onPressed: () =>
purchaseOrderFormState
.onRemoveProject(
ref,
context),
style: ElevatedButton
.styleFrom(
tapTargetSize:
MaterialTapTargetSize
.shrinkWrap,
visualDensity:
const VisualDensity(
horizontal: -4,
vertical: -4,
),
minimumSize:
Size.zero,
padding:
EdgeInsets.zero,
),
child: Text(
AppLocalizations.of(
context)!
.textDelete,
style: Theme.of(
context,
)
.textTheme
.subHead3
.copyWith(
decoration:
TextDecoration
.underline,
color: Theme.of(
context)
.colorRed,
),
),
),
const SizedBox(width: 10),
TextButton(
onPressed: () =>
purchaseOrderFormState
.onAssignProject(
ref,
context),
style: ElevatedButton
.styleFrom(
tapTargetSize:
MaterialTapTargetSize
.shrinkWrap,
visualDensity:
const VisualDensity(
horizontal: -4,
vertical: -4,
),
minimumSize:
Size.zero,
padding:
EdgeInsets.zero,
),
child: Text(
AppLocalizations.of(
context)!
.buttonChange,
style: Theme.of(
context,
)
.textTheme
.subHead3
.copyWith(
decoration:
TextDecoration
.underline,
color: Theme.of(
context)
.primaryColor,
),
),
)
],
),
)
: const SizedBox.shrink(),
],
),
...(![
Company_OrderState
.ORDER_STATE_UNSPECIFIED,
Company_OrderState.ORDER_STATE_VALID
].contains(viewPurchaseOrderState.value
.purchaseOrder.project.orderState)
? [
const SizedBox(height: 5),
Text(
labelValidation[
viewPurchaseOrderState
.value
.purchaseOrder
.project
.orderState] ??
"",
style: Theme.of(context)
.textTheme
.paragraph3
.copyWith(
color: Colors.red),
),
]
: []),
const SizedBox(height: 10),
viewPurchaseOrderState.value.purchaseOrder
.project.id.isEmpty
? ShimmerWidget(
isActive: onAssignProjectState
.loading.data,
child: SizedBox(
width: double.infinity,
child: GestureDetector(
onTap: () =>
purchaseOrderFormState
.onAssignProject(
ref, context),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Theme.of(context)
.colorBorder,
width: 1,
),
borderRadius:
BorderRadius.circular(
10),
),
padding:
const EdgeInsets.all(
10),
child: Row(
crossAxisAlignment:
CrossAxisAlignment
.center,
children: [
Expanded(
child: Text(
AppLocalizations.of(
context)!
.textSelect,
style: Theme.of(
context)
.textTheme
.paragraph3
.copyWith(
color: Colors
.black54),
),
),
Icon(
color:
Theme.of(context)
.colorBlack,
FontAwesomeIcons
.chevronRight,
size: 15,
),
const SizedBox(
width: 5),
],
),
),
),
),
)
: ShimmerWidget(
isActive: onAssignProjectState
.loading.data,
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Theme.of(context)
.colorBorder,
width: 1,
),
borderRadius:
BorderRadius.circular(10),
),
padding:
const EdgeInsets.all(10),
child: Text(
viewPurchaseOrderState
.value
.purchaseOrder
.project
.name
.toString()
.toTitleCase(),
style: Theme.of(context)
.textTheme
.paragraph3
.copyWith(
fontWeight:
FontWeight.w500),
),
),
),
const SizedBox(height: 20),
],
)
: const SizedBox.shrink(),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Text(
AppLocalizations.of(context)!.textCompany,
style: Theme.of(context).textTheme.subHead2,
),
),
const SizedBox(width: 20),
viewPurchaseOrderState
.value.purchaseOrder.company.id.isNotEmpty
? ShimmerWidget(
isActive: onChangeCustomerState
.loading.data ||
onRemoveCustomerState.loading.data,
child: Row(
children: [
TextButton(
onPressed: () =>
purchaseOrderFormState
.onRemoveCustomer(
ref, context),
style: ElevatedButton.styleFrom(
tapTargetSize:
MaterialTapTargetSize
.shrinkWrap,
visualDensity:
const VisualDensity(
horizontal: -4,
vertical: -4,
),
minimumSize: Size.zero,
padding: EdgeInsets.zero,
),
child: Text(
AppLocalizations.of(context)!
.textDelete,
style: Theme.of(
context,
).textTheme.subHead3.copyWith(
decoration: TextDecoration
.underline,
color: Theme.of(context)
.colorRed,
),
),
),
const SizedBox(width: 10),
TextButton(
onPressed: () =>
purchaseOrderFormState
.onChangeCustomer(
ref, context),
style: ElevatedButton.styleFrom(
tapTargetSize:
MaterialTapTargetSize
.shrinkWrap,
visualDensity:
const VisualDensity(
horizontal: -4,
vertical: -4,
),
minimumSize: Size.zero,
padding: EdgeInsets.zero,
),
child: Text(
AppLocalizations.of(context)!
.buttonChange,
style: Theme.of(
context,
).textTheme.subHead3.copyWith(
decoration: TextDecoration
.underline,
color: Theme.of(context)
.primaryColor,
),
),
),
],
),
)
: const SizedBox.shrink(),
],
),
...(![
Company_OrderState.ORDER_STATE_UNSPECIFIED,
Company_OrderState.ORDER_STATE_VALID
].contains(viewPurchaseOrderState
.value.purchaseOrder.company.orderState)
? [
const SizedBox(height: 5),
Text(
labelValidation[viewPurchaseOrderState
.value.purchaseOrder.orderState] ??
"",
style: Theme.of(context)
.textTheme
.paragraph3
.copyWith(color: Colors.red),
),
]
: []),
const SizedBox(height: 10),
viewPurchaseOrderState
.value.purchaseOrder.company.id.isEmpty
? ShimmerWidget(
isActive: onChangeCustomerState.loading.data,
child: SizedBox(
width: double.infinity,
child: GestureDetector(
onTap: () => purchaseOrderFormState
.onChangeCustomer(ref, context),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color:
Theme.of(context).colorBorder,
width: 1,
),
borderRadius:
BorderRadius.circular(10),
),
padding: const EdgeInsets.all(10),
child: Row(
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Expanded(
child: Text(
AppLocalizations.of(context)!
.textSelect,
style: Theme.of(context)
.textTheme
.paragraph3
.copyWith(
color: Colors.black54),
),
),
Icon(
color:
Theme.of(context).colorBlack,
FontAwesomeIcons.chevronRight,
size: 15,
),
const SizedBox(width: 5),
],
),
),
),
),
)
: ShimmerWidget(
isActive: onChangeCustomerState.loading.data,
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Theme.of(context).colorBorder,
width: 1,
),
borderRadius: BorderRadius.circular(10),
),
padding: const EdgeInsets.all(10),
child: Text(
viewPurchaseOrderState
.value.purchaseOrder.company.name
.toString(),
style: Theme.of(context)
.textTheme
.paragraph3
.copyWith(
fontWeight: FontWeight.w500),
),
),
),
const SizedBox(height: 20),
Text(
AppLocalizations.of(context)!.orderTextDate,
style: Theme.of(context).textTheme.subHead2,
),
...(![
PurchaseOrder_OrderState.ORDER_STATE_UNSPECIFIED,
PurchaseOrder_OrderState.ORDER_STATE_VALID
].contains(viewPurchaseOrderState
.value.purchaseOrder.orderState)
? [
Text(
labelValidation[viewPurchaseOrderState
.value.purchaseOrder.orderState] ??
"",
style: Theme.of(context)
.textTheme
.paragraph3
.copyWith(color: Colors.red),
),
]
: []),
const SizedBox(height: 5),
ShimmerWidget(
isActive: onChangeDateState.loading.data,
child: SizedBox(
width: double.infinity,
child: DateTimePickerWidget(
hint:
"${AppLocalizations.of(context)!.textSelect} ${AppLocalizations.of(context)!.textDate}",
dateTime: viewPurchaseOrderState
.value.purchaseOrder.date.year +
viewPurchaseOrderState.value
.purchaseOrder.date.month +
viewPurchaseOrderState
.value.purchaseOrder.date.day >
3
? (utils.converter<Date>(
viewPurchaseOrderState.value
.purchaseOrder.date) ??
Date())
.toDateTime()
: null,
value:
viewPurchaseOrderState.value.purchaseOrder
.date.year +
viewPurchaseOrderState.value
.purchaseOrder.date.month +
viewPurchaseOrderState.value
.purchaseOrder.date.day >
3
? utils.dateFormatter(
(utils.converter<Date>(
viewPurchaseOrderState
.value
.purchaseOrder
.date) ??
Date())
.toDateTime(),
"dd/LL/yyyy",
languageCode,
)
: null,
onSelected: (_) => purchaseOrderFormState
.onChangeDate(ref, context, _),
),
),
),
const SizedBox(height: 30),
SizedBox(
width: double.infinity,
child: Wrap(
direction: Axis.horizontal,
runSpacing: 10,
alignment: WrapAlignment.spaceBetween,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.textProduct,
style: Theme.of(context).textTheme.subHead2,
),
ShimmerWidget(
isActive: onUpdateItemState.loading.data ||
onRefreshValidation.loading.data ||
onRemoveItemState.loading.data,
child: ButtonAddLabel(
label:
AppLocalizations.of(context)!.textAdd,
onPressed: () {
ref
.refresh(
useCaseListItemOrder(
UseCaseParams(
context: context,
request: ListItemOrderRequest(
filter: ListItemOrderFilter(
companyId:
viewPurchaseOrderState
.value
.purchaseOrder
.project
.id
.isEmpty
? viewPurchaseOrderState
.value
.purchaseOrder
.company
.id
: "",
projectId:
viewPurchaseOrderState
.value
.purchaseOrder
.project
.id,
date: viewPurchaseOrderState
.value
.purchaseOrder
.date,
),
),
),
),
)
.ignore();
Set.from(
GoRouter.of(context)
.routerDelegate
.currentConfiguration
.matches
.map((_) =>
_.matchedLocation.split('/'))
.reduce((_, __) => [..._, ...__]),
).contains(
RouterPath.purchaseOrderProduct.path,
)
? utils.popUntil(
context: context,
route: RouterPath
.purchaseOrderProduct,
)
: context.pushNamed(
RouterPath
.purchaseOrderProduct.name,
);
},
),
),
],
),
),
const SizedBox(height: 10),
...(viewPurchaseOrderState
.value.purchaseOrder.itemsByItem.isNotEmpty
? [
...viewPurchaseOrderState
.value.purchaseOrder.itemsByItem
.map(
(_) => Container(
width: double.infinity,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(15),
border: Border.all(
width: 1,
color:
Theme.of(context).colorBorder,
),
),
padding: const EdgeInsets.all(10),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.stretch,
children: [
Container(
padding:
const EdgeInsets.all(10),
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(10),
color: Theme.of(context)
.backgroundSecondary,
),
child: Text(
_.item.name,
style: Theme.of(context)
.textTheme
.subHead2
.copyWith(
fontWeight:
FontWeight.w600,
),
),
),
...((_.items.isNotEmpty
? _.items.any((_) => ![
PurchaseOrderItem_OrderState
.ORDER_STATE_UNSPECIFIED,
PurchaseOrderItem_OrderState
.ORDER_STATE_VALID
].contains(
_.orderState))
: false)
? [
const SizedBox(
height: 10),
Text(
labelValidation[(_.items
.firstWhereOrNull((_) =>
![
PurchaseOrderItem_OrderState.ORDER_STATE_UNSPECIFIED,
PurchaseOrderItem_OrderState.ORDER_STATE_VALID
].contains(_.orderState)) ??
PurchaseOrderItem())
.orderState] ??
"",
style: Theme.of(context)
.textTheme
.paragraph3
.copyWith(
color:
Colors.red),
),
]
: []),
const SizedBox(height: 10),
Container(
height: 1,
color: Theme.of(context)
.colorBorder,
),
const SizedBox(height: 10),
...List.from(_.items)
.mapIndexed(
(_, __) =>
PurchaseOrderFormProductCardWidget(
item: __,
loading: onUpdateItemState
.loading.data ||
onRefreshValidation
.loading.data ||
onRemoveItemState
.loading.data,
onRemoveItem: (_) =>
purchaseOrderFormState
.onRemoveItem(ref,
context, _),
),
)
.toList()
.expand(
(_) => [
_,
const SizedBox(
height: 10),
],
)
.toList()
..removeLast(),
],
),
),
)
.expand(
(_) => [_, const SizedBox(height: 10)],
)
.toList()
..removeLast(),
]
: [
ShimmerWidget(
isActive: onUpdateItemState.loading.data ||
onRefreshValidation.loading.data ||
onRemoveItemState.loading.data,
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Theme.of(context)
.highlightColorShimmer,
borderRadius: BorderRadius.circular(5),
),
padding: const EdgeInsets.all(10),
child: Row(
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
const Icon(
Icons.info_rounded,
color: Colors.black54,
size: 18,
),
const SizedBox(width: 10),
Expanded(
child: Text(
AppLocalizations.of(context)!
.textNotifySelectProduct,
style: Theme.of(context)
.textTheme
.subHead2
.copyWith(
color: Colors.black54,
fontSize: 12,
),
),
)
],
),
),
)
]),
const SizedBox(height: 20),
Text(
AppLocalizations.of(context)!.quotation,
style: Theme.of(context).textTheme.subHead2,
),
const SizedBox(height: 10),
ShimmerWidget(
isActive: onApplyQuotationState.loading.data ||
onDismissQuotationState.loading.data,
child: Container(
width: double.infinity,
decoration: viewPurchaseOrderState.value
.purchaseOrder.appliedQuotation.isNotEmpty
? BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(
width: 1,
color: Theme.of(context).colorBorder,
),
)
: null,
padding: EdgeInsets.all(
viewPurchaseOrderState.value.purchaseOrder
.appliedQuotation.isNotEmpty
? 10
: 0,
).copyWith(
bottom: viewPurchaseOrderState
.value
.purchaseOrder
.appliedQuotation
.isNotEmpty
? 5
: 0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
GestureDetector(
onTap: () {
if (deliveryTypeEditableValueState
.value) {
AlertNotification(context)
.showNotificationWarning(
AppLocalizations.of(context)!
.textNotifySaveDeliveryTypeFirst);
return;
}
purchaseOrderFormState
.onValidateQuotation(ref, context);
},
child: Container(
decoration: BoxDecoration(
color: Theme.of(
context,
).backgroundSecondary,
borderRadius: BorderRadius.circular(10),
),
padding: const EdgeInsets.all(10),
child: Row(
children: [
Expanded(
child: Text(
AppLocalizations.of(context)!
.orderQuotationAvailable,
style: Theme.of(
context,
).textTheme.subHead2.copyWith(
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(width: 10),
const Icon(
Icons.chevron_right_rounded,
),
],
),
),
),
...(![
Quotation_OrderState
.ORDER_STATE_UNSPECIFIED,
Quotation_OrderState.ORDER_STATE_VALID
].contains((viewPurchaseOrderState
.value
.purchaseOrder
.appliedQuotation
.firstOrNull ??
Quotation())
.orderState)
? [
const SizedBox(height: 5),
Text(
labelValidation[
(viewPurchaseOrderState
.value
.purchaseOrder
.appliedQuotation
.firstOrNull ??
Quotation())
.orderState] ??
"",
style: Theme.of(context)
.textTheme
.paragraph3
.copyWith(color: Colors.red),
),
]
: []),
...(viewPurchaseOrderState.value.purchaseOrder
.appliedQuotation.isNotEmpty
? [
const SizedBox(height: 10),
...viewPurchaseOrderState.value
.purchaseOrder.appliedQuotation
.map(
(_) => Container(
decoration: BoxDecoration(
border: Border.all(
width: 1,
color: Theme.of(context)
.colorBorder,
),
borderRadius:
BorderRadius.circular(
10),
),
padding:
const EdgeInsets.all(10),
child:
PurchaseOrderQuotationCardValue(
_,
isSmallSize: true,
extra: [
const SizedBox(
height: 10),
Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
crossAxisAlignment:
CrossAxisAlignment
.center,
children: [
TextButton(
onPressed: () =>
context
.pushNamed(
RouterPath
.quotationDetail
.name,
pathParameters: {
'id': _.id
},
),
style:
ElevatedButton
.styleFrom(
tapTargetSize:
MaterialTapTargetSize
.shrinkWrap,
visualDensity:
const VisualDensity(
horizontal: -4,
vertical: -4,
),
minimumSize:
Size.zero,
padding:
EdgeInsets
.zero,
),
child: Text(
"${AppLocalizations.of(context)!.textView} Detail",
style: Theme.of(
context,
)
.textTheme
.subHead3
.copyWith(
color: Theme.of(
context)
.primaryColor,
),
),
),
const SizedBox(
width: 10),
ElevatedButton(
onPressed: () {
showModalBottomSheet(
isScrollControlled:
true,
context:
context,
builder: (_) =>
ConfirmationBottomSheet(
text: AppLocalizations.of(
context)!
.textAlertRemoveDelivery,
textButtonLeft:
AppLocalizations.of(
context)!
.textNo,
textButtonRight:
AppLocalizations.of(
context)!
.textYes,
onCancel:
() async {
Navigator.of(
context)
.pop();
purchaseOrderFormState.onDismissQuotation(
ref,
context,
Delivery(
amount:
viewPurchaseOrderState.value.purchaseOrder.delivery.amount,
type: viewPurchaseOrderState.value.purchaseOrder.deliveryType));
},
onConfirmed:
() {
Navigator.of(
context)
.pop();
purchaseOrderFormState.onDismissQuotation(
ref,
context,
Delivery());
},
),
);
},
style:
ElevatedButton
.styleFrom(
minimumSize:
Size.zero,
tapTargetSize:
MaterialTapTargetSize
.shrinkWrap,
fixedSize:
const Size(
90, 25),
backgroundColor:
Colors
.transparent,
shadowColor: Colors
.transparent,
shape:
RoundedRectangleBorder(
borderRadius:
BorderRadius
.circular(
1000),
side:
BorderSide(
color: Theme.of(
context)
.colorRedSoft,
),
),
),
child: Text(
AppLocalizations.of(
context)!
.textRemove,
style: Theme.of(
context)
.textTheme
.subHead3
.copyWith(
color: Theme.of(
context)
.colorRedSoft,
),
),
),
],
),
],
),
),
)
.expand(
(_) => [
_,
const SizedBox(height: 5)
],
)
.toList(),
]
: []),
],
),
),
),
const SizedBox(height: 20),
Row(
children: [
Expanded(
child: Text(
AppLocalizations.of(context)!.textPayment,
style: Theme.of(context).textTheme.subHead2,
),
),
const SizedBox(width: 20),
...(listPermissionByRole.value.permissions.any(
(_) =>
_.name ==
"Update Payment Type Purchase Order")
? [
ShimmerWidget(
isActive: onChangePaymentTypeState
.loading.data ||
onApplyQuotationState
.loading.data ||
onDismissQuotationState
.loading.data,
child: GestureDetector(
onTap: paymentEditableValueState.value
? () {
if ((purchaseOrderPaymentTypeState
.value
.downPayment
.value +
purchaseOrderPaymentTypeState
.value
.cash
.value +
purchaseOrderPaymentTypeState
.value
.credit
.value) !=
100) {
AlertNotification(context)
.showNotificationWarning(
AppLocalizations.of(
context)!
.quotationNotifyPaymentTypeWrong,
);
return;
}
purchaseOrderFormState.onChangePaymentType(
ref,
context,
PurchaseOrderPaymentType(
credit: purchaseOrderPaymentTypeState
.value
.credit
.value ==
0
? null
: purchaseOrderPaymentTypeState
.value.credit,
downPayment: purchaseOrderPaymentTypeState
.value
.downPayment
.value ==
0
? null
: purchaseOrderPaymentTypeState
.value
.downPayment,
cash: purchaseOrderPaymentTypeState
.value
.cash
.value ==
0
? null
: purchaseOrderPaymentTypeState
.value.cash));
paymentEditableValueState
.value = false;
}
: () {
purchaseOrderPaymentTypeState
.value =
viewPurchaseOrderState
.value
.purchaseOrder
.paymentType;
paymentEditableValueState
.value = true;
},
child: LabelCardItemWidget(
paddingHorizontal: 10,
text: paymentEditableValueState
.value
? AppLocalizations.of(context)!
.textSave
: AppLocalizations.of(context)!
.textEdit,
textStyle: Theme.of(context)
.textTheme
.titleLarge!
.copyWith(color: Colors.white),
backgroundColor: Theme.of(
context,
).primaryColor,
),
),
),
]
: []),
],
),
...(![
PurchaseOrderPaymentType_OrderState
.ORDER_STATE_UNSPECIFIED,
PurchaseOrderPaymentType_OrderState
.ORDER_STATE_VALID
].contains(viewPurchaseOrderState
.value.purchaseOrder.paymentType.orderState)
? [
Text(
labelValidation[viewPurchaseOrderState
.value
.purchaseOrder
.paymentType
.orderState] ??
"",
style: Theme.of(context)
.textTheme
.paragraph3
.copyWith(color: Colors.red),
),
]
: []),
const SizedBox(height: 10),
(viewPurchaseOrderState.value.purchaseOrder
.paymentType !=
PurchaseOrderPaymentType.create() ||
viewPurchaseOrderState.value.purchaseOrder
.appliedQuotation.isNotEmpty) &&
!paymentEditableValueState.value
? PurchaseOrderFormPaymentCardWidget(
context: context,
loading: onApplyQuotationState.loading.data ||
onDismissQuotationState.loading.data ||
onChangePaymentTypeState.loading.data,
paymentType: viewPurchaseOrderState
.value.purchaseOrder.paymentType,
)
: paymentEditableValueState.value
? PurchaseOrderFormPaymentFragment(
paymentType: viewPurchaseOrderState
.value.purchaseOrder.paymentType,
onChanged: (paymentType) {
purchaseOrderPaymentTypeState.value =
paymentType;
},
)
: ShimmerWidget(
isActive: onApplyQuotationState
.loading.data ||
onDismissQuotationState
.loading.data ||
onChangePaymentTypeState.loading.data,
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Theme.of(context)
.highlightColorShimmer,
borderRadius:
BorderRadius.circular(5),
),
padding: const EdgeInsets.all(10),
child: Row(
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
const Icon(
Icons.info_rounded,
color: Colors.black54,
size: 18,
),
const SizedBox(width: 10),
Expanded(
child: Text(
"${AppLocalizations.of(context)!.textNotifySelectQuotation} ${listPermissionByRole.value.permissions.any((_) => _.name == "Update Payment Type Purchase Order") ? "${AppLocalizations.of(context)!.textOr} ${AppLocalizations.of(context)!.textEdit}" : ""}",
style: Theme.of(context)
.textTheme
.subHead2
.copyWith(
color: Colors.black54,
fontSize: 13,
),
),
)
],
),
),
),
const SizedBox(height: 20),
(listPermissionByRole.value.permissions.any((_) =>
_.name ==
"Update Delivery Purchase Order") ||
(viewPurchaseOrderState.value.purchaseOrder
.appliedQuotation.isNotEmpty ||
viewPurchaseOrderState.value.purchaseOrder
.deliveryType !=
DeliveryType.getDefault()))
? PurchaseOrderFormDropdownGroup(
loading:
onChangeDeliveryTypeState.loading.data ||
onChangeDeliveryAmount.loading.data ||
onDismissQuotationState.loading.data,
editableValue:
deliveryTypeEditableValueState.value,
onEditableValueChanged: (_) =>
deliveryTypeEditableValueState.value = _,
deliveryAmount: viewPurchaseOrderState
.value.purchaseOrder.delivery.amount,
value: viewPurchaseOrderState
.value
.purchaseOrder
.deliveryType
.id
.isNotEmpty
? DropdownItem(
id: viewPurchaseOrderState.value
.purchaseOrder.deliveryType.id,
name: viewPurchaseOrderState.value
.purchaseOrder.deliveryType.name,
)
: null,
onChanged: (_, __) {
deliveryTypeEditableValueState.value =
false;
return _ != null &&
deliveryTypeState
.value.deliveryTypes
.any((__) => __.id == _.id)
? purchaseOrderFormState
.onChangeDeliveryAmount(
ref,
context,
Delivery(
type: deliveryTypeState
.value.deliveryTypes
.firstWhere(
(__) => __.id == _.id,
),
amount: __))
: null;
},
)
: ShimmerWidget(
isActive:
onApplyQuotationState.loading.data ||
onDismissQuotationState.loading.data,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.stretch,
children: [
Text(
AppLocalizations.of(context)!
.textDeliveryType,
style: Theme.of(context)
.textTheme
.subHead2,
),
const SizedBox(height: 10),
Container(
width: double.infinity,
decoration: BoxDecoration(
color: Theme.of(context)
.highlightColorShimmer,
borderRadius:
BorderRadius.circular(5),
),
padding: const EdgeInsets.all(10),
child: Row(
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
const Icon(
Icons.info_rounded,
color: Colors.black54,
size: 18,
),
const SizedBox(width: 10),
Expanded(
child: Text(
AppLocalizations.of(context)!
.textNotifySelectQuotation,
style: Theme.of(context)
.textTheme
.subHead2
.copyWith(
color: Colors.black54,
fontSize: 13,
),
),
)
],
),
),
],
),
),
...addressWidgetConditions
.map((_) => [
const SizedBox(height: 20),
SizedBox(
width: double.infinity,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Expanded(
child: SizedBox(
width: double.infinity,
child: Text(
_["title"]!.toString(),
style: Theme.of(context)
.textTheme
.subHead2,
),
),
),
const SizedBox(width: 20),
(utils
.convert<OrderAddress>(
_["address"])
.projectLocation
.address
.id
.isNotEmpty ||
utils
.convert<OrderAddress>(
_["address"])
.companyAddress
.address
.id
.isNotEmpty)
? ShimmerWidget(
isActive: onChangeCustomerState
.loading.data ||
onChangeShippingAddressState
.loading.data,
child: TextButton(
onPressed: () => utils.convert<
Function(
ListOrderAddressFilter_AddressType)>(_[
"action"])(
utils.convert<
ListOrderAddressFilter_AddressType>(
_["type"]!),
),
style: ElevatedButton
.styleFrom(
tapTargetSize:
MaterialTapTargetSize
.shrinkWrap,
visualDensity:
const VisualDensity(
horizontal: -4,
vertical: -4,
),
minimumSize: Size.zero,
padding: EdgeInsets.zero,
),
child: Text(
AppLocalizations.of(
context)!
.buttonChange,
style: Theme.of(
context,
)
.textTheme
.subHead3
.copyWith(
decoration:
TextDecoration
.underline,
color: Theme.of(
context,
).primaryColor,
),
),
),
)
: const SizedBox.shrink()
],
),
),
...((viewPurchaseOrderState.value
.purchaseOrder.type.name
.toLowerCase()
.trim() ==
'regular' &&
viewPurchaseOrderState
.value
.purchaseOrder
.company
.id
.isNotEmpty) ||
(viewPurchaseOrderState.value
.purchaseOrder.type.name
.toLowerCase()
.trim() ==
'project' &&
viewPurchaseOrderState
.value
.purchaseOrder
.project
.id
.isNotEmpty &&
viewPurchaseOrderState
.value
.purchaseOrder
.company
.id
.isNotEmpty)
? [
...(![
OrderAddress_OrderState
.ORDER_STATE_UNSPECIFIED,
OrderAddress_OrderState
.ORDER_STATE_VALID
].contains(utils
.convert<OrderAddress>(
_["address"])
.orderState)
? [
const SizedBox(height: 5),
Text(
labelValidation[utils
.convert<
OrderAddress>(
_["address"])
.orderState] ??
"",
style: Theme.of(context)
.textTheme
.paragraph3
.copyWith(
color:
Colors.red),
),
]
: []),
const SizedBox(height: 10),
utils
.convert<OrderAddress>(
_["address"])
.projectLocation
.address
.id
.isEmpty &&
utils
.convert<OrderAddress>(
_["address"])
.companyAddress
.address
.id
.isEmpty
? ShimmerWidget(
isActive: onChangeCustomerState
.loading.data ||
onChangeShippingAddressState
.loading.data,
child: SizedBox(
width: double.infinity,
child: GestureDetector(
onTap: () => utils.convert<
Function(
ListOrderAddressFilter_AddressType)>(_[
"action"])(
utils.convert<
ListOrderAddressFilter_AddressType>(
_["type"]!),
),
child: Container(
decoration:
BoxDecoration(
border: Border.all(
color: Theme.of(
context)
.colorBorder,
width: 1,
),
borderRadius:
BorderRadius
.circular(
10),
),
padding:
const EdgeInsets
.all(10),
child: Row(
crossAxisAlignment:
CrossAxisAlignment
.center,
children: [
Expanded(
child: Text(
AppLocalizations.of(
context)!
.textSelect,
style: Theme.of(
context)
.textTheme
.paragraph3
.copyWith(
color:
Colors.black54),
),
),
Icon(
color: Theme.of(
context)
.colorBlack,
FontAwesomeIcons
.chevronRight,
size: 15,
),
const SizedBox(
width: 5),
],
),
),
),
),
)
: ShimmerWidget(
isActive: onChangeCustomerState
.loading.data ||
onChangeShippingAddressState
.loading.data,
child: Container(
width: double.infinity,
padding:
const EdgeInsets.all(
10),
decoration: BoxDecoration(
border: Border.all(
color:
Theme.of(context)
.colorBorder,
width: 1,
),
borderRadius:
BorderRadius
.circular(10),
),
child: Text(
utils
.convert<OrderAddress>(_[
"address"])
.companyAddress
.address
.id
.isNotEmpty
? utils
.convert<OrderAddress>(_[
"address"])
.companyAddress
.address
.street
: utils
.convert<
OrderAddress>(
_["address"])
.projectLocation
.address
.street,
style: Theme.of(context)
.textTheme
.paragraph3
.copyWith(
fontWeight:
FontWeight
.w500,
),
),
),
),
]
: [
const SizedBox(height: 10),
Container(
width: double.infinity,
decoration: BoxDecoration(
color: Theme.of(context)
.highlightColorShimmer,
borderRadius:
BorderRadius.circular(5),
),
padding: const EdgeInsets.all(10),
child: Row(
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
const Icon(
Icons.info_rounded,
color: Colors.black54,
size: 18,
),
const SizedBox(width: 10),
Expanded(
child: Text(
AppLocalizations.of(
context)!
.textNotifySelectSubject(viewPurchaseOrderState
.value
.purchaseOrder
.type
.name
.toLowerCase()
.trim() ==
'regular'
? AppLocalizations
.of(context)!
.textCompany
.toLowerCase()
: "${AppLocalizations.of(context)!.textProject.toLowerCase()} & ${AppLocalizations.of(context)!.textCompany.toLowerCase()}"),
style: Theme.of(context)
.textTheme
.subHead2
.copyWith(
color:
Colors.black54,
fontSize: 13,
),
),
)
],
),
),
]),
])
.fold([], (_, __) => [..._, ...__]),
const SizedBox(height: 30),
SizedBox(
width: double.infinity,
child: Wrap(
direction: Axis.horizontal,
runSpacing: 10,
alignment: WrapAlignment.spaceBetween,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.textAttachment,
style: Theme.of(context).textTheme.subHead2,
),
ShimmerWidget(
isActive: onAddAttachmentState.loading.data ||
onRemoveAttachmentState.loading.data,
child: ButtonAddLabel(
label:
AppLocalizations.of(context)!.textAdd,
onPressed: () => showModalBottomSheet(
context: context,
builder: (context) => Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: const Icon(
Icons.camera_alt),
title: Text(
AppLocalizations.of(
context)!
.textCamera,
style: Theme.of(context)
.textTheme
.subHead2),
onTap: () =>
Navigator.of(context).pop(
pickImageFromStorage(
ImageSource.camera),
),
),
ListTile(
leading:
const Icon(Icons.image),
title: Text(
AppLocalizations.of(
context)!
.textGallery,
style: Theme.of(context)
.textTheme
.subHead2),
onTap: () =>
Navigator.of(context).pop(
pickImageFromStorage(
ImageSource.gallery),
),
),
ListTile(
leading: const Icon(
Icons.upload_rounded),
title: Text(
AppLocalizations.of(
context)!
.textBrowseFile,
style: Theme.of(context)
.textTheme
.subHead2),
onTap: () =>
Navigator.of(context).pop(
pickFileFromStorage()),
),
],
)),
),
),
],
),
),
const SizedBox(height: 10),
ShimmerWidget(
isActive: onAddAttachmentState.loading.data ||
onRemoveAttachmentState.loading.data,
child: SizedBox(
width: double.infinity,
child: viewPurchaseOrderState.value.purchaseOrder
.attachments.isNotEmpty
? Wrap(
direction: Axis.vertical,
spacing: 5,
children: List.from(viewPurchaseOrderState
.value.purchaseOrder.attachments)
.map(
(_) => SizedBox(
width:
utils.getFullWidth(context) -
(20 * 2),
child: Container(
decoration: BoxDecoration(
color: Theme.of(context)
.baseColorShimmer,
borderRadius:
BorderRadius.circular(10),
),
child: Stack(
children: [
Row(
children: [
Expanded(
child:
AttachmentDocumentWidget(
loading: false,
disablePadding:
true,
file: _.file,
),
),
const SizedBox(
width: 40),
],
),
Positioned(
top: 0,
bottom: 0,
right: 0,
child: GestureDetector(
onTap: () =>
purchaseOrderFormState
.onRemoveAttachment(
ref,
context,
_.id),
child: Container(
width: 40,
decoration:
BoxDecoration(
color: Theme.of(
context)
.baseColorShimmer,
borderRadius:
BorderRadius
.circular(
10),
),
child: const Center(
child: Padding(
padding: EdgeInsets
.only(
right: 2),
child: Icon(
Icons.delete,
color:
Colors.red,
shadows: [
Shadow(
color: Colors
.white,
blurRadius:
10,
),
],
),
),
),
),
),
),
],
),
),
),
)
.toList(),
)
: Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Theme.of(context)
.highlightColorShimmer,
borderRadius: BorderRadius.circular(5),
),
child: Center(
child: Column(
key: const ValueKey<bool>(
false,
),
mainAxisAlignment:
MainAxisAlignment.center,
children: [
const Icon(
Icons.file_present_rounded,
color: Colors.black54,
size: 54,
),
const SizedBox(height: 10),
Text(
AppLocalizations.of(context)!
.textNotifySelectFile,
style: Theme.of(context)
.textTheme
.subHead2
.copyWith(
color: Colors.black54,
),
)
],
),
),
),
),
),
const SizedBox(height: 30),
Text(
AppLocalizations.of(context)!.textNotes,
style: Theme.of(context).textTheme.subHead2,
),
const SizedBox(height: 5),
TextFormField(
initialValue: viewPurchaseOrderState
.value.purchaseOrder.notes
.toString(),
onTapOutside: (_) =>
FocusManager.instance.primaryFocus?.unfocus(),
onChanged: (_) => notesDebouncer.call(
() => purchaseOrderFormState.onChangeNotes(
ref, context, _),
),
style: Theme.of(context).textTheme.paragraph3,
minLines: 1,
maxLines: 5,
keyboardType: TextInputType.multiline,
textInputAction: TextInputAction.newline,
decoration: InputDecoration(
hintText:
AppLocalizations.of(context)!.orderNoteHint,
isDense: true,
contentPadding: const EdgeInsets.symmetric(
horizontal: 10,
vertical: 12,
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(
color: Theme.of(context).colorBorder,
width: 1,
),
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(
color: Theme.of(context).colorBorder,
width: 1,
),
),
),
),
const SizedBox(height: 30),
ShimmerWidget(
isActive: onChangeTypeState.loading.data ||
onChangeCustomerState.loading.data ||
onRemoveCustomerState.loading.data ||
onApplyQuotationState.loading.data ||
onDismissQuotationState.loading.data ||
onUpdateItemState.loading.data ||
onRemoveItemState.loading.data ||
onRefreshValidation.loading.data ||
onChangeDeliveryTypeState.loading.data ||
onChangeDateState.loading.data,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
AppLocalizations.of(context)!.orderTotal,
style:
Theme.of(context).textTheme.subHead2,
),
],
),
const SizedBox(height: 10),
Container(
color: Colors.black12,
width: double.infinity,
height: 2,
),
const SizedBox(height: 10),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const PurchaseOrderFormTotalInfo(
"Subtotal", ''),
Table(
columnWidths: const {
0: IntrinsicColumnWidth(),
1: FlexColumnWidth(),
2: FixedColumnWidth(5),
3: IntrinsicColumnWidth(),
},
defaultVerticalAlignment:
TableCellVerticalAlignment.middle,
children: List.from(viewPurchaseOrderState
.value.purchaseOrder.items)
.map(
(_) => TableRow(
children: [
TableCell(
child: Padding(
padding:
const EdgeInsets.symmetric(
horizontal: 5,
),
child: Icon(
Icons.circle,
size: 8,
color: Colors.black
.withOpacity(0.75),
),
),
),
TableCell(
child: Text(
_.itemVariant.sku,
style: Theme.of(context)
.textTheme
.paragraph2,
),
),
const TableCell(
child: SizedBox.shrink()),
TableCell(
child: Text(
utils.moneyFormatter(
double.parse(double.parse(_
.finalPrice
.toString())
.toStringAsFixed(3))),
style: Theme.of(context)
.textTheme
.paragraph2,
textAlign: TextAlign.end,
),
),
],
),
)
.expandIndexed((_, __) {
return [
__,
TableRow(
children: [
const TableCell(
child: SizedBox.shrink()),
TableCell(
child: viewPurchaseOrderState
.value
.purchaseOrder
.items[_]
.quotationItemDiscount
.value >
0
? Text(
viewPurchaseOrderState
.value
.purchaseOrder
.items[_]
.quotationItemDiscount
.type ==
DiscountType
.DISCOUNT_TYPE_PERCENTAGE
? '${AppLocalizations.of(context)!.textDiscount} ${viewPurchaseOrderState.value.purchaseOrder.items[_].quotationItemDiscount.value}%'
: "${AppLocalizations.of(context)!.textFinalUnitPrice} ${utils.moneyFormatter(viewPurchaseOrderState.value.purchaseOrder.items[_].quotationItemDiscount.value)}${viewPurchaseOrderState.value.purchaseOrder.items[_].quotationItemDiscount.uom.name.isNotEmpty ? "/${viewPurchaseOrderState.value.purchaseOrder.items[_].quotationItemDiscount.uom.name}" : ""}",
style: Theme.of(
context,
)
.textTheme
.paragraph3
.copyWith(
color: Theme.of(
context)
.labelOrangeText,
),
)
: const SizedBox.shrink(),
),
const TableCell(
child: SizedBox.shrink()),
TableCell(
child: utils.moneyFormatter(
viewPurchaseOrderState
.value
.purchaseOrder
.items[_]
.finalPrice /
viewPurchaseOrderState
.value
.purchaseOrder
.items[_]
.quantity) !=
utils.moneyFormatter(
viewPurchaseOrderState
.value
.purchaseOrder
.items[_]
.itemVariant
.currentPrice
.sell)
? Text(
utils.moneyFormatter(double.parse(
viewPurchaseOrderState
.value
.purchaseOrder
.items[_]
.subTotal
.toStringAsFixed(
3))),
style: Theme.of(context)
.textTheme
.paragraph3
.copyWith(
color: Colors
.black87,
decoration:
TextDecoration
.lineThrough,
),
textAlign:
TextAlign.end,
)
: const SizedBox.shrink(),
),
],
),
TableRowSpacerWidget(
length: 4, size: 2)
];
}).toList(),
),
...(viewPurchaseOrderState.value
.purchaseOrder.delivery.amount
.floor() !=
0
? [
const SizedBox(height: 10),
PurchaseOrderFormTotalInfo(
AppLocalizations.of(context)!
.textDeliveryCost,
utils.moneyFormatter(
double.parse(
viewPurchaseOrderState
.value
.purchaseOrder
.delivery
.amount
.toStringAsFixed(3)),
),
),
]
: []),
...(viewPurchaseOrderState
.value.purchaseOrder.taxCost
.floor() >
0
? [
const SizedBox(height: 5),
PurchaseOrderFormTotalInfo(
"PPN (${viewPurchaseOrderState.value.purchaseOrder.tax.value}%)",
utils.moneyFormatter(double.parse(
viewPurchaseOrderState.value
.purchaseOrder.taxCost
.toStringAsFixed(3))),
),
...(![
Tax_OrderState
.ORDER_STATE_UNSPECIFIED,
Tax_OrderState.ORDER_STATE_VALID
].contains(viewPurchaseOrderState
.value
.purchaseOrder
.tax
.orderState)
? [
Text(
labelValidation[
viewPurchaseOrderState
.value
.purchaseOrder
.tax
.orderState] ??
"",
style: Theme.of(context)
.textTheme
.paragraph3
.copyWith(
color:
Colors.red),
),
]
: []),
]
: []),
const SizedBox(height: 10),
PurchaseOrderFormTotalInfo(
AppLocalizations.of(context)!
.orderTotalPrice,
utils.moneyFormatter(double.parse(
viewPurchaseOrderState
.value.purchaseOrder.total
.toStringAsFixed(3))),
large: true,
),
],
),
const SizedBox(height: 30),
],
),
)
],
),
),
...(purchaseOrderFormState.onSaveAsDraft != null
? [
ElevatedButton(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.all(12),
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: BorderSide(
color: Theme.of(context).primaryColor,
width: 2,
),
),
),
onPressed: () {
if (deliveryTypeEditableValueState.value) {
AlertNotification(context)
.showNotificationWarning(
AppLocalizations.of(context)!
.textNotifySaveDeliveryTypeFirst);
return;
}
purchaseOrderFormState.onSaveAsDraft!(
ref, context);
},
child: getLoadingFormState()
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator())
: Text(
AppLocalizations.of(context)!
.textSaveDraft,
style: TextStyle(
color:
Theme.of(context).primaryColor),
),
),
const SizedBox(height: 10),
]
: []),
SizedBox(
width: double.infinity,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.all(12)),
onPressed: () {
if (deliveryTypeEditableValueState.value) {
AlertNotification(context).showNotificationWarning(
AppLocalizations.of(context)!
.textNotifySaveDeliveryTypeFirst);
return;
}
purchaseOrderFormState.onSubmitOrder(ref, context);
},
child: getLoadingFormState()
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
color: Colors.white,
))
: Text(
purchaseOrderFormState.status ==
PurchaseOrderFormStatus.Revise
? "Submit ${AppLocalizations.of(context)!.textRevision}"
: AppLocalizations.of(context)!
.orderButtonSubmit,
),
),
),
],
),
),
),
),
Positioned.fill(
child: LoadingOverlayWidget(
isActive: onSubmitOrderState.loading.data ||
onSaveAsDraftState.loading.data ||
onUpdateRevisePurchaseOrderState.loading.data,
),
)
],
),
);
}
}
Editor is loading...
Leave a Comment