Commit 6dd4cfb5 authored by Dio Maulana's avatar Dio Maulana

pickup info dan datetimepicker

parent f95c5dae
......@@ -18,6 +18,7 @@ import 'package:byod/ui/viewbill/view_bill_new.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:intl/intl.dart';
import 'package:uuid/uuid.dart';
import '../bloc/order_bloc.dart';
import '../helper/widget/open_url.dart';
......@@ -158,6 +159,8 @@ class Api {
setLongOutlet(jsonObject['data']['long']);
setIsDelivery(jsonObject['data']['is_delivery']);
setIsPickup(jsonObject['data']['is_pickup']);
setOpenTime(jsonObject['data']['open_time']);
setCloseTime(jsonObject['data']['close_time']);
if (jsonObject['data']['payment_mode'] != null) {
setPaymentMode(jsonObject['data']['payment_mode']);
}
......@@ -1327,6 +1330,23 @@ class Api {
var jsonObject = await httpPost(apiUrl, bodies, 'checkOut');
if (jsonObject != false) {
if (jsonObject['status'].toString().toLowerCase() == 'ok') {
int typeUrl = getUrlType();
//hanya ketika delivery pickup, set pickup time
if (typeUrl == typeUrlTiga) {
DateTime dateTime = DateTime.now().toLocal();
String hourTime = DateFormat.H().format(dateTime);
String minuteTime = DateFormat.m().format(dateTime);
TimeOfDay timeOfDayPickup = TimeOfDay(
hour: int.parse(hourTime) + 1, minute: int.parse(minuteTime));
// String timeToset = timeOfDayPickup.format(context);
final hourString = timeOfDayPickup.hour.toString().padLeft(2, '0');
final minuteString =
timeOfDayPickup.minute.toString().padLeft(2, '0');
// String amPM = timeToset.split(' ')[1];
String setPickup = "$hourString:$minuteString";
setPickupTime(setPickup);
}
setStatusOrderCreated(true);
await EasyLoading.dismiss();
// Navigator.pushAndRemoveUntil(
......@@ -2000,9 +2020,11 @@ class Api {
if (jsonObject != false) {
if (jsonObject['status'].toString().toLowerCase() == 'ok') {
setBranch(newBranch);
setBranchName(jsonObject['data']['branch_name']);
setBranchName(jsonObject['data']['code']);
setLatOutlet(jsonObject['data']['lat']);
setLongOutlet(jsonObject['data']['long']);
setOpenTime(jsonObject['data']['open_time']);
setCloseTime(jsonObject['data']['close_time']);
return true;
}
return false;
......@@ -2061,4 +2083,63 @@ class Api {
return defaultResult;
}
}
static Future<bool> addCancelPromotion(bool isAdd) async {
await EasyLoading.show(
status: 'Please wait...',
maskType: EasyLoadingMaskType.none,
);
String baseUrl = prefs.getString('baseUrl') ?? '';
String apiUrl;
if (isAdd) {
apiUrl = "${baseUrl}romi/api/byod/add_promotions";
} else {
apiUrl = "${baseUrl}romi/api/byod/cancel_promotions";
}
String branchCode = getBranchPref();
String brandCode = getBrand();
String role = getRole();
String cashierName = getCashierName();
String orderID = getOrderId();
try {
Map data = {
"branch_code": branchCode,
"brand_code": brandCode,
"role": role,
"cashier_name": cashierName,
"from": fromByod,
"order_id": orderID,
};
var bodies = jsonEncode(data);
var jsonObject = await httpPost(apiUrl, bodies, 'addPromotion');
if (jsonObject != false) {
if (jsonObject['status'].toString().toLowerCase() == 'ok') {
if (isAdd) {
await prefs.setBool('isPromoActive', true);
EasyLoading.showToast('Promosi aktif');
} else {
await prefs.setBool('isPromoActive', false);
EasyLoading.showToast('Promosi tidak aktif');
}
return true;
} else {
EasyLoading.showToast(jsonObject['msg']);
return false;
}
} else {
EasyLoading.showToast('Something went wrong');
return false;
}
} catch (e) {
if (debug) {
logd('API CLASS ON API.DART, FUNGSI: addPromotion, URL : $apiUrl',
'ERROR CONNECT TO SERVER, ERROR CATCH : $e');
}
EasyLoading.showToast('Cant connect to server');
return false;
}
}
}
......@@ -30,7 +30,7 @@ class OrderVariantValueBloc extends Cubit<List<OrderVariant>> {
'price': orderVariants[z].price,
'name': orderVariants[z].name,
'type': type,
'caption': caption
'caption': orderVariants[z].caption
};
orderVariantResult.add(OrderVariant.createVariant(x));
}
......@@ -45,7 +45,9 @@ class OrderVariantValueBloc extends Cubit<List<OrderVariant>> {
'type': type,
'caption': caption
};
orderVariantResult.add(OrderVariant.createVariant(x));
orderVariantResult.add(
OrderVariant.createVariant(x),
);
}
} else if (type == typeOptional) {
if (orderVariants.isNotEmpty) {
......@@ -67,7 +69,7 @@ class OrderVariantValueBloc extends Cubit<List<OrderVariant>> {
'price': orderVariants[x].price,
'name': orderVariants[x].name,
'type': type,
'caption': caption
'caption': orderVariants[x].caption
};
orderVariantResult.add(OrderVariant.createVariant(l));
}
......@@ -96,7 +98,7 @@ class OrderVariantValueBloc extends Cubit<List<OrderVariant>> {
'price': orderVariants[x].price,
'name': orderVariants[x].name,
'type': type,
'caption': caption
'caption': orderVariants[x].caption
};
orderVariantResult.add(OrderVariant.createVariant(l));
}
......
......@@ -325,7 +325,7 @@ bool isVisibleAddRemoveQuantityButtonCheckout(bool isHistory, int orderStatus) {
String textButtonCheckout(int orderState) {
int paymentMethod = getPaymentMode();
if (paymentMethod == closebill && orderState == orderStateCreated) {
return 'Pesan';
return 'Kirim Pesanan';
} else if (paymentMethod == closebill &&
(orderState == orderStatePending ||
orderState == orderStateApproved) ||
......
// ignore_for_file: unused_catch_clause
import 'dart:io';
import 'dart:js';
import 'package:byod/bloc/view_bill.dart';
import 'package:byod/helper/logger.dart';
import 'package:byod/helper/prefs.dart';
import 'package:byod/main.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:mqtt_client/mqtt_browser_client.dart';
import 'package:mqtt_client/mqtt_client.dart';
import 'package:uuid/uuid.dart';
......@@ -80,14 +83,19 @@ Future<int> runMqTT(BuildContext context) async {
// print('');
if (c[0].topic == topic && pt == queueMessage) {
// update bill disini
context.read<ViewBillBloc>().getBill();
if (debug) {
logd('CHECK TOPIC', 'TOPIC MASUK::$topic , MESSAGE::$queueMessage');
}
}
if (debug) {
logd('CHECK TOPIC',
'TOPIC TIDAK SAMA YANG -> MASUK::$topic , MESSAGE::$pt');
} else {
if (debug) {
logd('CHECK TOPIC',
'TOPIC TIDAK SAMA, YANG MASUK::$topic , MESSAGE::$pt');
}
}
});
// final builder = MqttClientPayloadBuilder();
// builder.addString('Hello from mqtt_client');
// mqClient.publishMessage(topic, MqttQos.exactlyOnce, builder.payload!);
return 0;
}
......@@ -36,6 +36,9 @@ const String _branchName = 'bN';
const String _orderCreated = 'oC';
const String _latOutlet = 'latO';
const String _longOutlet = 'longO';
const String _openTime = 'oT';
const String _closeTime = 'cT';
const String _pickupTime = 'puT';
String getBaseUrl() {
return prefs.getString(_baseUrl) ?? '';
......@@ -312,3 +315,27 @@ String getLongOutlet() {
Future<void> setLongOutlet(String value) async {
prefs.setString(_longOutlet, value);
}
String getOpenTime() {
return prefs.getString(_openTime) ?? '';
}
Future<void> setOpenTime(String value) async {
prefs.setString(_openTime, value);
}
String getCloseTime() {
return prefs.getString(_closeTime) ?? '';
}
Future<void> setCloseTime(String value) async {
prefs.setString(_closeTime, value);
}
String getPickupTime() {
return prefs.getString(_pickupTime) ?? '';
}
Future<void> setPickupTime(String value) async {
prefs.setString(_pickupTime, value);
}
This diff is collapsed.
......@@ -98,6 +98,28 @@ class _CustomizeVariantNewState extends State<CustomizeVariantNew> {
int totalItem =
widget.orders.orderDetail[i].totalItem.toInt();
int satuanHarga = totalHarga ~/ totalItem;
List<String> variantCaption = [''];
List<String> variantName = [''];
for (int y = 0;
y <
widget.orders.orderDetail[i].orderVariant
.length;
y++) {
int indexCaption = variantCaption.indexWhere(
(element) =>
element ==
widget.orders.orderDetail[i]
.orderVariant[y].caption);
if (indexCaption == -1) {
variantCaption.add(widget.orders.orderDetail[i]
.orderVariant[y].caption);
variantName.add(widget.orders.orderDetail[i]
.orderVariant[y].name);
} else {
variantName[indexCaption] +=
", ${widget.orders.orderDetail[i].orderVariant[y].name}";
}
}
return Column(
children: [
Row(
......@@ -128,17 +150,31 @@ class _CustomizeVariantNewState extends State<CustomizeVariantNew> {
CrossAxisAlignment.start,
children: [
for (int d = 0;
d <
widget.orders.orderDetail[i]
.orderVariant.length;
d < variantCaption.length;
d++)
defaultText(
context,
widget.orders.orderDetail[i]
.orderVariant[d].name,
maxLines: 1,
overFlow: TextOverflow.ellipsis,
)
if (variantCaption[d] != '')
Row(
children: [
defaultText(
context,
"${variantCaption[d]} : ",
maxLines: 2,
overFlow:
TextOverflow.ellipsis,
style:
textStyleVariantModal(),
),
defaultText(
context,
variantName[d],
maxLines: 2,
overFlow:
TextOverflow.ellipsis,
style:
textStyleVariantModal(),
),
],
)
],
),
(widget.orders.orderDetail[i].note !=
......
......@@ -212,72 +212,18 @@ class CoreVariant extends StatelessWidget {
child: ListView(
children: [
ListView.builder(
physics:
const NeverScrollableScrollPhysics(), // to disable GridView's scrolling
shrinkWrap: true,
itemCount: widget.variantCategories.length,
itemBuilder: ((context, index) {
return Container(
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.only(
bottom:
MediaQuery.of(context).size.height *
0.01,
top:
MediaQuery.of(context).size.height *
0.01),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
defaultText(
context,
widget
.variantCategories[index].caption,
style: variantStyleText(),
),
defaultText(
context,
(widget.variantCategories[index]
.type ==
typeMandatory)
? 'Pilih Salah Satu'
: (widget.variantCategories[index]
.type ==
typeAutoInsert)
? 'Sudah termasuk'
: 'Optional',
style: variantStyleText(
font: 12,
fontWeight: FontWeight.w300,
),
)
],
),
),
const Divider(
thickness: 0.5,
color: textColorBlack,
),
VariantNew(
variants:
widget.variantCategories[index].variant,
captioncategories:
widget.variantCategories[index].caption,
type: widget.variantCategories[index].type,
initPrice: widget.initPrice,
idCategory:
widget.variantCategories[index].id,
orderDetail: orderDetail,
),
],
),
);
})),
physics:
const NeverScrollableScrollPhysics(), // to disable GridView's scrolling
shrinkWrap: true,
itemCount: widget.variantCategories.length,
itemBuilder: ((context, index) {
return VariantDetail(
widget: widget,
orderDetail: orderDetail,
index: index,
);
}),
),
const SizedBox(
height: 74,
),
......@@ -292,28 +238,6 @@ class CoreVariant extends StatelessWidget {
const SizedBox(
height: 12,
),
// TextField(
// maxLength: maxLengthTextField,
// maxLines: 2,
// autofocus: false,
// keyboardType: TextInputType.text,
// controller: noteCatController,
// style: textStyleNormalFont(context),
// decoration: InputDecoration(
// prefixIcon: Image(
// image: const AssetImage('assets/icons/search.png'),
// color: Colors.grey.withOpacity(0.8),
// height: 20,
// width: 20,
// ),
// hintText: placeHolderNote,
// hintStyle: TextStyle(
// color: Colors.grey,
// fontSize:
// MediaQuery.of(context).size.height * normalFont,
// ),
// ),
// ),
Container(
height: 35,
child: TextField(
......@@ -464,3 +388,67 @@ class CoreVariant extends StatelessWidget {
);
}
}
class VariantDetail extends StatelessWidget {
const VariantDetail({
Key? key,
required this.widget,
required this.orderDetail,
required this.index,
}) : super(key: key);
final VariantCatNew widget;
final OrderDetail orderDetail;
final int index;
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.only(
bottom: MediaQuery.of(context).size.height * 0.01,
top: MediaQuery.of(context).size.height * 0.01),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
defaultText(
context,
widget.variantCategories[index].caption,
style: variantStyleText(),
),
defaultText(
context,
(widget.variantCategories[index].type == typeMandatory)
? 'Pilih Salah Satu'
: (widget.variantCategories[index].type == typeAutoInsert)
? 'Sudah termasuk'
: 'Optional',
style: variantStyleText(
font: 12,
fontWeight: FontWeight.w300,
),
)
],
),
),
const Divider(
thickness: 0.5,
color: textColorBlack,
),
VariantNew(
variants: widget.variantCategories[index].variant,
captioncategories: widget.variantCategories[index].caption,
type: widget.variantCategories[index].type,
initPrice: widget.initPrice,
idCategory: widget.variantCategories[index].id,
orderDetail: orderDetail,
),
],
),
);
}
}
......@@ -32,7 +32,10 @@ class ListOrder extends StatelessWidget {
itemBuilder: (ctx, d) {
return OrderViewBillNew(
billDetail: bill[i].billDetail[d],
lastItem: (i + 1 == bill[i].billDetail.length) ? true : false,
lastItem:
(i + 1 == bill.length && d + 1 == bill[i].billDetail.length)
? true
: false,
isHistory: isHistory,
tableStatus: tableStatus,
);
......
This diff is collapsed.
......@@ -15,6 +15,7 @@ import 'package:dotted_line/dotted_line.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:intl/intl.dart';
import 'package:uuid/uuid.dart';
import '../../api/api.dart';
......@@ -1438,6 +1439,11 @@ class DeliveryPickupDetail extends StatelessWidget {
}
Row pickupOption(BuildContext context) {
DateTime dateTime = DateTime.now().toLocal();
String hourTime = DateFormat.H().format(dateTime);
String minuteTime = DateFormat.m().format(dateTime);
TimeOfDay timeOfDayPickup =
TimeOfDay(hour: int.parse(hourTime) + 1, minute: int.parse(minuteTime));
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
......@@ -1453,6 +1459,7 @@ class DeliveryPickupDetail extends StatelessWidget {
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
defaultText(
context,
......@@ -1463,6 +1470,44 @@ class DeliveryPickupDetail extends StatelessWidget {
const SizedBox(
height: 5,
),
Row(
children: [
defaultText(
context,
"Close: ",
maxLines: 1,
overFlow: TextOverflow.ellipsis,
),
defaultText(
context,
getCloseTime(),
maxLines: 1,
overFlow: TextOverflow.ellipsis,
),
],
),
const SizedBox(
height: 5,
),
Row(
children: [
defaultText(
context,
"Pickup: ",
maxLines: 1,
overFlow: TextOverflow.ellipsis,
),
defaultText(
context,
getPickupTime(),
maxLines: 1,
overFlow: TextOverflow.ellipsis,
),
],
),
const SizedBox(
height: 5,
),
GestureDetector(
onTap: () {
htmlOpenLink(
......@@ -1506,62 +1551,161 @@ class DeliveryPickupDetail extends StatelessWidget {
width: 12,
),
const Spacer(),
GestureDetector(
onTap: () {
void ontapOkeChange() {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (_) => const SelectBranch(
isFormBill: true,
),
),
);
}
Column(
children: [
GestureDetector(
onTap: () {
void ontapOkeChange() {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (_) => const SelectBranch(
isFormBill: true,
),
),
);
}
void onTapCancelChange() {
Navigator.pop(context);
}
void onTapCancelChange() {
Navigator.pop(context);
}
String textOnOk = 'OK';
String textOnCancel = 'Batal';
String title = 'Ganti Outlet';
String description = '''
String textOnOk = 'OK';
String textOnCancel = 'Batal';
String title = 'Ganti Outlet';
String description = '''
Ganti outlet akan menyebabkan orderan anda saat ini hilang.
Apakah ingin melanjutkan ?''';
buttonDialogGlobal(
context,
title,
description,
textOnOk,
textOnCancel,
ontapOkeChange,
onTapCancelChange,
okButtonColor: buttonColor,
);
},
child: Container(
width: 98,
height: 30,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(40),
color: backgroundWhite,
border: Border.all(
color: buttonColor,
buttonDialogGlobal(
context,
title,
description,
textOnOk,
textOnCancel,
ontapOkeChange,
onTapCancelChange,
okButtonColor: buttonColor,
);
},
child: Container(
width: 98,
height: 30,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(40),
color: backgroundWhite,
border: Border.all(
color: buttonColor,
),
),
child: Center(
child: defaultText(
context,
'Ganti Outlet',
style: addButton(
font: 8,
color: buttonColor,
),
),
),
),
),
child: Center(
child: defaultText(
context,
'Ganti Outlet',
style: addButton(
font: 8,
color: buttonColor,
const SizedBox(
height: 5,
),
GestureDetector(
onTap: () {
showTimePicker(
context: context,
initialTime: timeOfDayPickup,
).then((value) {
if (value == null) {
return;
} else {
void ontapClose() {
Navigator.pop(context);
}
String closeOutlet = getCloseTime();
String hourClose = closeOutlet.split(':')[0];
String minuteClose = closeOutlet.split(':')[1];
// TimeOfDay timeClose = TimeOfDay(
// hour: int.parse(hourClose),
// minute: int.parse(minuteClose),
// );
var now = DateTime.now().toLocal();
var dateNow = DateFormat('yyyy-MM-dd').format(now);
String dateTimeCloseOutletString =
"$dateNow $hourClose:$minuteClose:00";
DateTime dateTimeCloseOutlet =
DateTime.parse(dateTimeCloseOutletString);
DateTime dateSelectedPickupTime = DateTime(
now.year, now.month, now.day, value.hour, value.minute);
final difference =
dateTimeCloseOutlet.difference(dateSelectedPickupTime);
final differenceFromNow =
dateSelectedPickupTime.difference(now);
if (differenceFromNow.inMinutes < 0) {
buttonDialogGlobal(
context,
'Informasi',
'Pickup time tidak dapat dipilih pada waktu yang sudah berlalu',
'OK',
'Close',
ontapClose,
ontapClose,
isOkeButtonShow: false,
);
return;
}
if (difference.inMinutes < 59) {
buttonDialogGlobal(
context,
'Informasi',
'Pickup Hanya Bisa Dilakukan 1 Jam sebelum outlet tutup',
'OK',
'Close',
ontapClose,
ontapClose,
isOkeButtonShow: false,
);
return;
}
// String timeToset = value.format(context);
final hourString = value.hour.toString().padLeft(2, '0');
final minuteString =
value.minute.toString().padLeft(2, '0');
// String amPM = timeToset.split(' ')[1];
String setPickup = "$hourString:$minuteString";
setPickupTime(setPickup);
context.read<ViewBillBloc>().getBill();
}
});
// ketika user click OK
},
child: Container(
width: 98,
height: 30,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(40),
color: backgroundWhite,
border: Border.all(
color: buttonColor,
),
),
child: Center(
child: defaultText(
context,
'Pickup Time',
style: addButton(
font: 8,
color: buttonColor,
),
),
),
),
),
),
)
],
)
],
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment