207 lines
6.9 KiB
Dart
207 lines
6.9 KiB
Dart
import 'package:enaklo_pos/core/constants/colors.dart';
|
|
import 'package:enaklo_pos/core/extensions/date_time_ext.dart';
|
|
import 'package:enaklo_pos/core/extensions/int_ext.dart';
|
|
import 'package:enaklo_pos/data/models/response/order_response_model.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class SalesCard extends StatelessWidget {
|
|
final Order order;
|
|
final bool isActive;
|
|
|
|
const SalesCard({
|
|
super.key,
|
|
required this.order,
|
|
required this.isActive,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
|
decoration: BoxDecoration(
|
|
color: isActive ? AppColors.primary.withOpacity(0.1) : AppColors.white,
|
|
border:
|
|
Border.all(color: isActive ? AppColors.primary : AppColors.stroke),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
'${order.orderNumber}',
|
|
style: const TextStyle(
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
if (order.isRefund == true)
|
|
Container(
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: Colors.red.withOpacity(0.15),
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Text(
|
|
'Refund',
|
|
style: TextStyle(
|
|
color: Colors.red,
|
|
fontWeight: FontWeight.w600,
|
|
fontSize: 10,
|
|
letterSpacing: 0.5,
|
|
),
|
|
),
|
|
),
|
|
if (order.isVoid == true)
|
|
Container(
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: Colors.red.withOpacity(0.15),
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Text(
|
|
'Void',
|
|
style: TextStyle(
|
|
color: Colors.red,
|
|
fontWeight: FontWeight.w600,
|
|
fontSize: 10,
|
|
letterSpacing: 0.5,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 12),
|
|
Row(
|
|
children: [
|
|
CircleAvatar(
|
|
radius: 22,
|
|
backgroundColor: AppColors.primary,
|
|
child: Icon(Icons.person, color: Colors.white),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
order.metadata?['customer_name'] == ""
|
|
? "Anonim"
|
|
: order.metadata?['customer_name'],
|
|
style: const TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
if (order.orderType == "dineIn") ...[
|
|
const SizedBox(height: 4),
|
|
Row(
|
|
children: [
|
|
Icon(Icons.table_bar, size: 16, color: Colors.grey),
|
|
const SizedBox(width: 4),
|
|
Text(
|
|
'Meja ${order.tableNumber}',
|
|
style: TextStyle(color: Colors.grey[600]),
|
|
),
|
|
],
|
|
),
|
|
]
|
|
],
|
|
),
|
|
),
|
|
_buildStatus(),
|
|
],
|
|
),
|
|
const SizedBox(height: 16),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
order.status == 'pending'
|
|
? ((order.totalAmount ?? 0) - (order.totalPaid ?? 0))
|
|
.currencyFormatRpV2
|
|
: (order.totalAmount ?? 0).currencyFormatRpV2,
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
color: AppColors.primary,
|
|
),
|
|
),
|
|
Text(
|
|
(order.createdAt ?? DateTime.now()).toFormattedDate3(),
|
|
style: TextStyle(
|
|
color: AppColors.black,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildStatus() {
|
|
switch (order.status) {
|
|
case 'pending':
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
|
decoration: BoxDecoration(
|
|
color: Colors.amber.withOpacity(0.15),
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Text(
|
|
(order.status ?? "").toUpperCase(),
|
|
style: TextStyle(
|
|
color: Colors.amber,
|
|
fontWeight: FontWeight.w600,
|
|
fontSize: 12,
|
|
letterSpacing: 0.5,
|
|
),
|
|
),
|
|
);
|
|
case 'completed':
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
|
decoration: BoxDecoration(
|
|
color: Colors.green.withOpacity(0.15),
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Text(
|
|
(order.status ?? "").toUpperCase(),
|
|
style: TextStyle(
|
|
color: Colors.green,
|
|
fontWeight: FontWeight.w600,
|
|
fontSize: 12,
|
|
letterSpacing: 0.5,
|
|
),
|
|
),
|
|
);
|
|
default:
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey.withOpacity(0.15),
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Text(
|
|
(order.status ?? "").toUpperCase(),
|
|
style: TextStyle(
|
|
color: Colors.grey,
|
|
fontWeight: FontWeight.w600,
|
|
fontSize: 12,
|
|
letterSpacing: 0.5,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
}
|