Skip to content

Commit

Permalink
feature(product): add expired field for create function
Browse files Browse the repository at this point in the history
  • Loading branch information
sheenazien8 committed Jun 26, 2024
1 parent 84f9dd6 commit 5b24cdf
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 122 deletions.
3 changes: 3 additions & 0 deletions lib/api/requests/product_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ProductRequest {
bool isNonStock;
String? sku;
String? barcode;
String? expired;

ProductRequest({
this.name,
Expand All @@ -25,6 +26,7 @@ class ProductRequest {
this.isNonStock = false,
this.sku,
this.barcode,
this.expired,
});

Map<String, dynamic> toJson() {
Expand All @@ -39,6 +41,7 @@ class ProductRequest {
'is_non_stock': isNonStock,
'sku': sku,
'barcode': barcode ?? '',
'expired': expired ?? ''
};
if (photoUrl != '') {
data['hero_images_url'] = photoUrl;
Expand Down
32 changes: 20 additions & 12 deletions lib/api/responses/products/produect_error_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ProductErrorResponse {
String? isNotStock;
String? sku;
String? barcode;
String? expired;

ProductErrorResponse({
this.name,
Expand All @@ -23,19 +24,26 @@ class ProductErrorResponse {
this.isNotStock,
this.sku,
this.barcode,
this.expired,
});

ProductErrorResponse.fromJson(Map<String, dynamic> json) {
name = json['name'] == null ? '' : json['name'][0];
category = json['category'] == null ? '' : json['category'][0];
stock = json['stock'] == null ? '' : json['stock'][0];
initialPrice = json['initial_price'] == null ? '' : json['initial_price'][0];
sellingPrice = json['selling_price'] == null ? '' : json['selling_price'][0];
type = json['type'] == null ? '' : json['type'][0];
unit = json['unit'] == null ? '' : json['unit'][0];
photoUrl = json['hero_images_url'] == null ? '' : json['hero_images_url'][0];
isNotStock = json['is_not_stock'] == null ? '' : json['is_not_stock'][0];
sku = json['sku'] == null ? '' : json['sku'][0];
barcode = json['barcode'] == null ? '' : json['barcode'][0];
factory ProductErrorResponse.fromJson(Map<String, dynamic> json) {
return ProductErrorResponse(
name: json['name'] == null ? '' : json['name'][0],
category: json['category'] == null ? '' : json['category'][0],
stock: json['stock'] == null ? '' : json['stock'][0],
initialPrice:
json['initial_price'] == null ? '' : json['initial_price'][0],
sellingPrice:
json['selling_price'] == null ? '' : json['selling_price'][0],
type: json['type'] == null ? '' : json['type'][0],
unit: json['unit'] == null ? '' : json['unit'][0],
photoUrl:
json['hero_images_url'] == null ? '' : json['hero_images_url'][0],
isNotStock: json['is_not_stock'] == null ? '' : json['is_not_stock'][0],
sku: json['sku'] == null ? '' : json['sku'][0],
barcode: json['barcode'] == null ? '' : json['barcode'][0],
expired: json['expired'] == null ? '' : json['expired'][0],
);
}
}
2 changes: 2 additions & 0 deletions lib/controllers/products/product_add_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ProductAddEditController extends GetxController {
initialValue: 0.0,
);
final TextEditingController unitInputController = TextEditingController();
final TextEditingController expiredController = TextEditingController();
final TextEditingController skuInputController = TextEditingController();
final TextEditingController barcodeInputController = TextEditingController();
String? photoUrl = '';
Expand Down Expand Up @@ -62,6 +63,7 @@ class ProductAddEditController extends GetxController {
type: typeController.selectedOption,
unit: unitInputController.text,
photoUrl: photoUrl,
expired: expiredController.text,
));
isLoading(false);
_productController.getProducts();
Expand Down
2 changes: 2 additions & 0 deletions lib/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class Messages extends Translations {
'field_select_category': 'Select Category',
'field_type': 'Type',
'field_unit': 'Unit',
'field_expired': 'Expired',
'global_camera': 'Camera',
'global_gallery': 'Gallery',
'global_select_image_source': 'Select Image Source',
Expand Down Expand Up @@ -439,6 +440,7 @@ class Messages extends Translations {
'field_select_category': 'Pilih Kategori',
'field_type': 'Tipe',
'field_unit': 'Satuan',
'field_expired': 'Kadaluarsa',
'global_camera': 'Kamera',
'global_gallery': 'Galeri',
'global_select_image_source': 'Pilih Sumber Gambar',
Expand Down
57 changes: 34 additions & 23 deletions lib/screens/products/product_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'package:lakasir/controllers/category_controller.dart';
import 'package:lakasir/controllers/products/product_add_controller.dart';
import 'package:lakasir/controllers/products/unit_controller.dart';
import 'package:lakasir/utils/colors.dart';
import 'package:lakasir/utils/utils.dart';
import 'package:lakasir/widgets/date_picker.dart';
import 'package:lakasir/widgets/filled_button.dart';
import 'package:lakasir/widgets/image_picker.dart';
import 'package:lakasir/widgets/select_input_feld.dart';
Expand Down Expand Up @@ -52,6 +54,7 @@ class _ProductFormState extends State<ProductForm> {
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
var errorResponse = widget.controller.productErrorResponse;

return ListView(
shrinkWrap: true,
Expand All @@ -76,8 +79,7 @@ class _ProductFormState extends State<ProductForm> {
controller: widget.controller.nameInputController,
label: 'field_product_name'.tr,
mandatory: true,
errorText:
widget.controller.productErrorResponse.value.name ?? '',
errorText: errorResponse.value.name ?? '',
),
),
),
Expand All @@ -95,9 +97,7 @@ class _ProductFormState extends State<ProductForm> {
mandatory: true,
controller: widget.controller.categoryController,
label: 'field_category'.tr,
errorText:
widget.controller.productErrorResponse.value.category ??
'',
errorText: errorResponse.value.category ?? '',
options: _categoryController.categories
.map(
(e) => Option(
Expand All @@ -121,9 +121,7 @@ class _ProductFormState extends State<ProductForm> {
() => SelectInputWidget(
controller: widget.controller.typeController,
label: 'field_type'.tr,
errorText:
widget.controller.productErrorResponse.value.type ??
'',
errorText: errorResponse.value.type ?? '',
options: [
Option(
name: "option_product".tr,
Expand Down Expand Up @@ -182,8 +180,7 @@ class _ProductFormState extends State<ProductForm> {
controller: widget.controller.stockInputController,
label: 'field_stock'.tr,
keyboardType: TextInputType.number,
errorText:
widget.controller.productErrorResponse.value.stock ?? '',
errorText: errorResponse.value.stock ?? '',
),
),
),
Expand All @@ -204,9 +201,7 @@ class _ProductFormState extends State<ProductForm> {
controller: widget.controller.initialPriceInputController,
label: 'field_initial_price'.tr,
keyboardType: TextInputType.number,
errorText: widget.controller.productErrorResponse.value
.initialPrice ??
'',
errorText: errorResponse.value.initialPrice ?? '',
),
),
),
Expand All @@ -224,15 +219,35 @@ class _ProductFormState extends State<ProductForm> {
controller: widget.controller.sellingPriceInputController,
label: 'field_selling_price'.tr,
keyboardType: TextInputType.number,
errorText: widget.controller.productErrorResponse.value
.sellingPrice ??
'',
errorText: errorResponse.value.sellingPrice ?? '',
),
),
),
],
),
),
if (_authController.feature(feature: 'product-expired'))
Visibility(
visible: Get.currentRoute != '/menu/product/edit',
child: Container(
margin: const EdgeInsets.only(top: 20),
child: Obx(
() {
DateTime now = DateTime.now();

return MyDatePicker(
mandatory: true,
initialDate: now,
firstDate: now,
lastDate: DateTime(now.year + 3, now.month, now.day),
controller: widget.controller.expiredController,
label: 'field_expired'.tr,
errorText: errorResponse.value.expired,
);
},
),
),
),
Container(
margin: const EdgeInsets.only(top: 20),
child: Obx(
Expand All @@ -241,8 +256,7 @@ class _ProductFormState extends State<ProductForm> {
label: 'field_unit'.tr,
textCapitalization: TextCapitalization.words,
mandatory: true,
errorText:
widget.controller.productErrorResponse.value.unit ?? '',
errorText: errorResponse.value.unit ?? '',
),
),
),
Expand Down Expand Up @@ -330,8 +344,7 @@ class _ProductFormState extends State<ProductForm> {
() => MyTextField(
controller: widget.controller.skuInputController,
label: 'field_sku'.tr,
errorText:
widget.controller.productErrorResponse.value.sku ?? '',
errorText: errorResponse.value.sku ?? '',
info: 'field_sku_info'.tr,
),
),
Expand All @@ -342,9 +355,7 @@ class _ProductFormState extends State<ProductForm> {
() => MyTextField(
controller: widget.controller.barcodeInputController,
label: 'field_barcode'.tr,
errorText: widget
.controller.productErrorResponse.value.barcode ??
'',
errorText: errorResponse.value.barcode ?? '',
info: 'field_sku_info'.tr,
),
),
Expand Down
Loading

0 comments on commit 5b24cdf

Please sign in to comment.