feat: dukung penjualan produk per timbangan
Produk kini punya cara jual `unit` (cacah) atau `weight` (timbangan), mengikuti kontrak backend di docs/integration-weight-based-products.md. - tipe SellBy, domain/infrastructure unit baru, dan endpoint /api/v1/units - dialog input berat saat produk timbangan ditambahkan ke keranjang - tiap penimbangan jadi baris keranjang sendiri; total baris dihitung berat x harga satuan, sedangkan produk cacah tetap digabung - request ke backend mengirim quantity 1 dan membawa berat - migrasi DB v3: kolom sell_by, unit_id, unit_name, unit_abbreviation di tabel products supaya satuan tetap tampil saat offline - tampilan keranjang, struk, split bill, void, dan refund memakai berat - test/weight_based_products_test.dart menutup perilaku di atas (9 test) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -17,18 +17,35 @@ class ProductCard extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (product.isActive == true) {
|
||||
if (product.variants.isEmpty) {
|
||||
context.read<CheckoutFormBloc>().add(
|
||||
CheckoutFormEvent.addItem(product, null),
|
||||
);
|
||||
} else {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => VariantDialog(product: product),
|
||||
);
|
||||
}
|
||||
if (product.isActive != true) return;
|
||||
|
||||
if (product.variants.isNotEmpty) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => VariantDialog(product: product),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Produk timbangan tidak bisa langsung masuk keranjang — kasir harus
|
||||
// menimbang dulu, dan tiap penimbangan jadi barisnya sendiri.
|
||||
if (product.isSoldByWeight) {
|
||||
final bloc = context.read<CheckoutFormBloc>();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => WeightInputDialog(
|
||||
product: product,
|
||||
onSubmit: (weight) => bloc.add(
|
||||
CheckoutFormEvent.addWeightedItem(product, null, weight),
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
context.read<CheckoutFormBloc>().add(
|
||||
CheckoutFormEvent.addItem(product, null),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
@@ -75,7 +92,11 @@ class ProductCard extends StatelessWidget {
|
||||
Align(
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
product.price.currencyFormatRp,
|
||||
product.isSoldByWeight
|
||||
? '${product.price.currencyFormatRp} ${product.priceUnitLabel}'
|
||||
.trim()
|
||||
: product.price.currencyFormatRp,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 12,
|
||||
@@ -89,31 +110,39 @@ class ProductCard extends StatelessWidget {
|
||||
|
||||
BlocBuilder<CheckoutFormBloc, CheckoutFormState>(
|
||||
builder: (context, state) {
|
||||
final totalQuantity = state.items
|
||||
final lines = state.items
|
||||
.where((item) => item.product.id == product.id)
|
||||
.map((item) => item.quantity)
|
||||
.fold(0, (sum, qty) => sum + qty);
|
||||
.toList();
|
||||
|
||||
if (lines.isEmpty) return const SizedBox.shrink();
|
||||
|
||||
// Untuk produk timbangan, jumlah baris tidak berarti apa-apa
|
||||
// (selalu 1 per penimbangan) — yang informatif adalah total
|
||||
// berat yang sudah masuk keranjang.
|
||||
final label = product.isSoldByWeight
|
||||
? '${lines.fold<double>(0, (sum, item) => sum + (item.weight ?? 0)).weightFormat} ${product.unitLabel}'
|
||||
.trim()
|
||||
: lines
|
||||
.fold<int>(0, (sum, item) => sum + item.quantity)
|
||||
.toString();
|
||||
|
||||
if (totalQuantity == 0) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return Positioned(
|
||||
top: 4,
|
||||
right: 4,
|
||||
child: Container(
|
||||
width: 40,
|
||||
constraints: const BoxConstraints(minWidth: 40),
|
||||
height: 40,
|
||||
padding: const EdgeInsets.all(6),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
decoration: const BoxDecoration(
|
||||
borderRadius: BorderRadius.all(Radius.circular(9.0)),
|
||||
color: AppColor.primary,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
totalQuantity.toString(),
|
||||
style: const TextStyle(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 20,
|
||||
fontSize: product.isSoldByWeight ? 13 : 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user