uabh perhitungan tax
This commit is contained in:
@@ -121,7 +121,10 @@ class AddSalesScreenState extends ConsumerState<AddSalesScreen> {
|
||||
productPurchasePrice: detail.product?.productPurchasePrice,
|
||||
stock: detail.stock?.productCurrentStock,
|
||||
productId: detail.productId!,
|
||||
stockId: detail.stock?.id ?? 0);
|
||||
stockId: detail.stock?.id ?? 0,
|
||||
perItemTaxPercentage: 0, // Default to 0 as historical tax rate is not available
|
||||
productVatId: null, // Default to null
|
||||
);
|
||||
cart.addToCartRiverPod(
|
||||
cartItem: cartItem,
|
||||
fromEditSales: true,
|
||||
@@ -503,7 +506,7 @@ class AddSalesScreenState extends ConsumerState<AddSalesScreen> {
|
||||
const SizedBox(width: 10),
|
||||
|
||||
const Spacer(),
|
||||
taxesData.when(
|
||||
/*taxesData.when(
|
||||
data: (data) {
|
||||
List<VatModel> dataList = data.where((tax) => tax.status == true).toList();
|
||||
if (widget.transitionModel != null &&
|
||||
@@ -579,7 +582,7 @@ class AddSalesScreenState extends ConsumerState<AddSalesScreen> {
|
||||
},
|
||||
),
|
||||
|
||||
const SizedBox(width: 10),
|
||||
const SizedBox(width: 10),*/
|
||||
|
||||
// VAT Amount Input Field
|
||||
SizedBox(
|
||||
|
||||
@@ -132,11 +132,26 @@ class CartNotifier extends ChangeNotifier {
|
||||
totalPayableAmount -= discountAmount;
|
||||
}
|
||||
|
||||
// Apply VAT
|
||||
if (selectedVat?.rate != null) {
|
||||
vatAmount = (totalPayableAmount * selectedVat!.rate!) / 100;
|
||||
vatAmountController.text = vatAmount.toStringAsFixed(2);
|
||||
// Apply Item-wise VAT
|
||||
vatAmount = 0;
|
||||
for (var element in cartItemList) {
|
||||
num unitPrice = element.unitPrice ?? 0;
|
||||
num quantity = element.quantity;
|
||||
num taxRate = element.perItemTaxPercentage ?? 0;
|
||||
|
||||
// VAT Formula: (Price * Qty * Rate%)
|
||||
// Note: We are calculating VAT on the base price, not discounted price if that's the requirement.
|
||||
// But usually VAT is on the final price.
|
||||
// The user request "QTY x Harga x % dari vat_id" implies Base Price.
|
||||
// If it should be on discounted price, we would subtract productDiscount.
|
||||
// Assuming "Harga" refers to the selling price.
|
||||
|
||||
num itemVat = (unitPrice * quantity * taxRate) / 100;
|
||||
vatAmount += itemVat;
|
||||
}
|
||||
vatAmountController.text = vatAmount.toStringAsFixed(2);
|
||||
|
||||
// Add Total VAT to Payable
|
||||
totalPayableAmount += vatAmount;
|
||||
|
||||
// Apply Shipping
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:hugeicons/hugeicons.dart';
|
||||
import 'package:mobile_pos/Screens/Sales/provider/sales_cart_provider.dart';
|
||||
import 'package:mobile_pos/Screens/Sales/sales_add_to_cart_sales_widget.dart';
|
||||
import 'package:mobile_pos/constant.dart';
|
||||
import 'package:mobile_pos/currency.dart';
|
||||
import 'package:mobile_pos/generated/l10n.dart' as lang;
|
||||
|
||||
class SalesCartListWidget extends ConsumerWidget {
|
||||
@@ -50,11 +51,18 @@ class SalesCartListWidget extends ConsumerWidget {
|
||||
final double discountPerUnit = (item.discountAmount ?? 0).toDouble();
|
||||
final double totalDiscount = quantity * discountPerUnit;
|
||||
final double subTotal = quantity * unitPrice;
|
||||
final double finalTotal = subTotal - totalDiscount;
|
||||
final double originalTotal = unitPrice * quantity;
|
||||
final double itemVAT = (unitPrice * quantity * (item.perItemTaxPercentage ?? 0)) / 100;
|
||||
final double finalTotal = originalTotal + itemVAT;
|
||||
|
||||
return ListTile(
|
||||
visualDensity: VisualDensity(horizontal: -4, vertical: -4),
|
||||
contentPadding: EdgeInsetsDirectional.symmetric(horizontal: 10),
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 10.0),
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
// 1. Product Name (Clickable to Edit)
|
||||
GestureDetector(
|
||||
onTap: () => showModalBottomSheet(
|
||||
isScrollControlled: true,
|
||||
context: context,
|
||||
@@ -89,101 +97,98 @@ class SalesCartListWidget extends ConsumerWidget {
|
||||
);
|
||||
},
|
||||
),
|
||||
title: Text(
|
||||
child: SizedBox(
|
||||
width: 140,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
item.productName.toString(),
|
||||
style: _theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
subtitle: RichText(
|
||||
text: TextSpan(
|
||||
style: DefaultTextStyle.of(context).style,
|
||||
children: [
|
||||
// Qty X Price
|
||||
TextSpan(
|
||||
text: '${formatPointNumber(quantity)} X $unitPrice ',
|
||||
style: _theme.textTheme.titleSmall?.copyWith(
|
||||
color: kPeraColor,
|
||||
),
|
||||
),
|
||||
// Show Discount if exists
|
||||
if (totalDiscount > 0)
|
||||
TextSpan(
|
||||
text: '- ${formatPointNumber(totalDiscount)} (Disc) ',
|
||||
style: _theme.textTheme.titleSmall?.copyWith(
|
||||
color: kPeraColor,
|
||||
),
|
||||
),
|
||||
// Final Total
|
||||
TextSpan(
|
||||
text: '= ${formatPointNumber(finalTotal)} ',
|
||||
style: _theme.textTheme.titleSmall?.copyWith(
|
||||
color: kTitleColor,
|
||||
),
|
||||
),
|
||||
// Batch Info
|
||||
if (item.productType == 'variant')
|
||||
TextSpan(
|
||||
text: '[${item.batchName}]',
|
||||
style: const TextStyle(fontSize: 12, fontStyle: FontStyle.italic),
|
||||
Text(
|
||||
'[${item.batchName}]',
|
||||
style: const TextStyle(fontSize: 10, fontStyle: FontStyle.italic, color: Colors.grey),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 90,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => providerData.quantityDecrease(index),
|
||||
child: Container(
|
||||
height: 18,
|
||||
width: 18,
|
||||
decoration: const BoxDecoration(
|
||||
color: kMainColor,
|
||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||
),
|
||||
child: const Center(
|
||||
child: Icon(Icons.remove, size: 14, color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
SizedBox(
|
||||
width: 40,
|
||||
child: Center(
|
||||
child: Text(
|
||||
formatPointNumber(item.quantity),
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
color: kGreyTextColor,
|
||||
),
|
||||
maxLines: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
|
||||
// 2. Decrease Icon
|
||||
GestureDetector(
|
||||
onTap: () => providerData.quantityDecrease(index),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: kMainColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Icon(Icons.remove, size: 16, color: kMainColor),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
|
||||
// 3. Qty Order
|
||||
Text(
|
||||
formatPointNumber(quantity),
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
|
||||
// 4. Increase Icon
|
||||
GestureDetector(
|
||||
onTap: () => providerData.quantityIncrease(index),
|
||||
child: Container(
|
||||
height: 18,
|
||||
width: 18,
|
||||
decoration: const BoxDecoration(
|
||||
color: kMainColor,
|
||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: kMainColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Center(
|
||||
child: Icon(Icons.add, size: 14, color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
child: const Icon(Icons.add, size: 16, color: kMainColor),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
|
||||
// 5. Value Original
|
||||
Text(
|
||||
'$currency${formatPointNumber(originalTotal)}',
|
||||
style: TextStyle(
|
||||
color: kPeraColor,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
|
||||
// 6. Value VAT/Tax
|
||||
if (itemVAT > 0) ...[
|
||||
Text(
|
||||
'VAT: $currency${formatPointNumber(itemVAT)}',
|
||||
style: TextStyle(
|
||||
color: kPeraColor,
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
|
||||
// 7. Sum (Value Original + VAT/Tax)
|
||||
Text(
|
||||
'$currency${formatPointNumber(finalTotal)}',
|
||||
style: _theme.textTheme.titleSmall?.copyWith(
|
||||
color: kMainColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
|
||||
// 8. Delete Icon
|
||||
GestureDetector(
|
||||
onTap: () => providerData.deleteToCart(index),
|
||||
child: HugeIcon(
|
||||
@@ -194,6 +199,7 @@ class SalesCartListWidget extends ConsumerWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
@@ -202,6 +202,8 @@ class _SaleProductsListState extends State<SaleProductsList> {
|
||||
? 1
|
||||
: (stock?.productStock ?? 10)) // Ensure combo adds at least 1
|
||||
: 1,
|
||||
perItemTaxPercentage: product.vat?.rate ?? 0,
|
||||
productVatId: product.vatId,
|
||||
);
|
||||
providerData.addToCartRiverPod(cartItem: cartItem, fromEditSales: false);
|
||||
Navigator.pop(context);
|
||||
|
||||
@@ -588,6 +588,8 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
||||
productType: variantProduct!.productType,
|
||||
productId: variantProduct!.id ?? 0,
|
||||
quantity: 1,
|
||||
perItemTaxPercentage: variantProduct!.vat?.rate ?? 0,
|
||||
productVatId: variantProduct!.vatId,
|
||||
);
|
||||
|
||||
providerData.addToCartRiverPod(cartItem: cartItem);
|
||||
@@ -738,6 +740,8 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
||||
productType: product.productType,
|
||||
productId: product.id ?? 0,
|
||||
quantity: 1,
|
||||
perItemTaxPercentage: product.vat?.rate ?? 0,
|
||||
productVatId: product.vatId,
|
||||
);
|
||||
|
||||
providerData.addToCartRiverPod(cartItem: cartItem);
|
||||
@@ -924,14 +928,21 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
||||
Divider(color: kBorderColorTextField),
|
||||
itemBuilder: (context, index) {
|
||||
final item = providerData.cartItemList[index];
|
||||
return Row(
|
||||
final double quantity = (item.quantity ?? 0).toDouble();
|
||||
final double unitPrice = (item.unitPrice ?? 0).toDouble();
|
||||
final double itemVAT = (unitPrice * quantity * (item.perItemTaxPercentage ?? 0)) / 100;
|
||||
final double originalTotal = unitPrice * quantity;
|
||||
final double finalTotal = originalTotal + itemVAT;
|
||||
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
// 1. Product Name
|
||||
SizedBox(
|
||||
width: 140, // Fixed width to allow scrolling and wrapping
|
||||
child: Text(
|
||||
item.productName ?? '',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
@@ -940,20 +951,10 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'$currency${item.unitPrice}',
|
||||
style: TextStyle(
|
||||
color: kSubPeraColor,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Row(
|
||||
children: [
|
||||
|
||||
// 2. Decrease Icon
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
providerData.quantityDecrease(index);
|
||||
@@ -968,11 +969,15 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
|
||||
// 3. Qty Order
|
||||
Text(
|
||||
'${item.quantity}',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
|
||||
// 4. Increase Icon
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
providerData.quantityIncrease(index);
|
||||
@@ -986,11 +991,33 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
||||
child: const Icon(Icons.add, size: 16, color: kMainColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
|
||||
// 5. Value Original
|
||||
Text(
|
||||
'$currency${(item.unitPrice ?? 0) * (item.quantity ?? 0)}',
|
||||
'$currency${originalTotal.toStringAsFixed(2)}',
|
||||
style: TextStyle(
|
||||
color: kSubPeraColor,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
|
||||
// 6. Value VAT/Tax
|
||||
if (itemVAT > 0) ...[
|
||||
Text(
|
||||
'VAT: $currency${itemVAT.toStringAsFixed(2)}',
|
||||
style: TextStyle(
|
||||
color: kSubPeraColor,
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
],
|
||||
|
||||
// 7. Sum (Value Original + VAT/Tax)
|
||||
Text(
|
||||
'$currency${finalTotal.toStringAsFixed(2)}',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: kMainColor,
|
||||
@@ -998,6 +1025,8 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
|
||||
// Delete Icon (Keeping it for usability)
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
providerData.deleteToCart(index);
|
||||
@@ -1009,6 +1038,7 @@ class _PosSaleScreenState extends ConsumerState<PosSaleScreen> {
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
@@ -13,6 +13,8 @@ class SaleCartModel {
|
||||
this.productPurchasePrice,
|
||||
this.lossProfit,
|
||||
this.discountAmount,
|
||||
this.perItemTaxPercentage,
|
||||
this.productVatId,
|
||||
});
|
||||
|
||||
num productId;
|
||||
@@ -28,4 +30,6 @@ class SaleCartModel {
|
||||
num? stock;
|
||||
num? lossProfit;
|
||||
num? discountAmount;
|
||||
num? perItemTaxPercentage;
|
||||
int? productVatId;
|
||||
}
|
||||
|
||||
@@ -258,10 +258,11 @@ class SalesThermalPrinterInvoice {
|
||||
}
|
||||
|
||||
bytes += generator.row([
|
||||
PosColumn(text: 'Item', width: 4, styles: const PosStyles(align: PosAlign.left, bold: true)),
|
||||
PosColumn(text: 'Qty', width: 2, styles: const PosStyles(align: PosAlign.center, bold: true)),
|
||||
PosColumn(text: 'Price', width: 3, styles: const PosStyles(align: PosAlign.center, bold: true)),
|
||||
PosColumn(text: 'Amount', width: 3, styles: const PosStyles(align: PosAlign.right, bold: true)),
|
||||
PosColumn(text: 'SL', width: 1, styles: const PosStyles(align: PosAlign.left, bold: true)),
|
||||
PosColumn(text: 'Product', width: 4, styles: const PosStyles(align: PosAlign.left, bold: true)),
|
||||
PosColumn(text: 'Qty', width: 1, styles: const PosStyles(align: PosAlign.center, bold: true)),
|
||||
PosColumn(text: 'VAT/Tax', width: 2, styles: const PosStyles(align: PosAlign.center, bold: true)),
|
||||
PosColumn(text: 'Amount', width: 4, styles: const PosStyles(align: PosAlign.right, bold: true)),
|
||||
]);
|
||||
bytes += generator.hr();
|
||||
List.generate(productList?.length ?? 1, (index) {
|
||||
@@ -279,6 +280,13 @@ class SalesThermalPrinterInvoice {
|
||||
"${productList?[index].product?.productType == ProductType.variant.name ? ' [${productList?[index].stock?.batchNo ?? ''}]' : ''}";
|
||||
|
||||
bytes += generator.row([
|
||||
PosColumn(
|
||||
text: '${index + 1}',
|
||||
width: 1,
|
||||
styles: const PosStyles(
|
||||
align: PosAlign.left,
|
||||
),
|
||||
),
|
||||
PosColumn(
|
||||
text: name,
|
||||
width: 4,
|
||||
@@ -288,18 +296,18 @@ class SalesThermalPrinterInvoice {
|
||||
),
|
||||
PosColumn(
|
||||
text: formatPointNumber(getProductQuantity(detailsId: productList?[index].id ?? 0)),
|
||||
width: 2,
|
||||
width: 1,
|
||||
styles: const PosStyles(align: PosAlign.center),
|
||||
),
|
||||
PosColumn(
|
||||
text: '${productList?[index].price}',
|
||||
width: 3,
|
||||
text: formatPointNumber(0),
|
||||
width: 2,
|
||||
styles: const PosStyles(align: PosAlign.center),
|
||||
),
|
||||
PosColumn(
|
||||
text:
|
||||
"${((productList?[index].price ?? 0) * getProductQuantity(detailsId: productList?[index].id ?? 0)) - ((productList?[index].discount ?? 0) * getProductQuantity(detailsId: productList?[index].id ?? 0))}",
|
||||
width: 3,
|
||||
width: 4,
|
||||
styles: const PosStyles(align: PosAlign.right),
|
||||
),
|
||||
]);
|
||||
@@ -811,10 +819,10 @@ class SalesThermalPrinterInvoice {
|
||||
bytes += generator.hr();
|
||||
bytes += generator.row([
|
||||
PosColumn(text: 'SL', width: 1, styles: const PosStyles(align: PosAlign.left, bold: true)),
|
||||
PosColumn(text: 'Item', width: 5, styles: const PosStyles(align: PosAlign.left, bold: true)),
|
||||
PosColumn(text: 'Qty', width: 2, styles: const PosStyles(align: PosAlign.center, bold: true)),
|
||||
PosColumn(text: 'Price', width: 2, styles: const PosStyles(align: PosAlign.center, bold: true)),
|
||||
PosColumn(text: 'Amount', width: 2, styles: const PosStyles(align: PosAlign.right, bold: true)),
|
||||
PosColumn(text: 'Product', width: 5, styles: const PosStyles(align: PosAlign.left, bold: true)),
|
||||
PosColumn(text: 'QTY', width: 1, styles: const PosStyles(align: PosAlign.center, bold: true)),
|
||||
PosColumn(text: 'VAT/Tax', width: 2, styles: const PosStyles(align: PosAlign.center, bold: true)),
|
||||
PosColumn(text: 'Amount', width: 3, styles: const PosStyles(align: PosAlign.right, bold: true)),
|
||||
]);
|
||||
bytes += generator.hr();
|
||||
List.generate(productList?.length ?? 1, (index) {
|
||||
@@ -846,10 +854,10 @@ class SalesThermalPrinterInvoice {
|
||||
)),
|
||||
PosColumn(
|
||||
text: formatPointNumber(getProductQuantity(detailsId: productList?[index].id ?? 0), addComma: true),
|
||||
width: 2,
|
||||
width: 1,
|
||||
styles: const PosStyles(align: PosAlign.center)),
|
||||
PosColumn(
|
||||
text: formatPointNumber(productList?[index].price ?? 0, addComma: true),
|
||||
text: formatPointNumber(0, addComma: true),
|
||||
width: 2,
|
||||
styles: const PosStyles(
|
||||
align: PosAlign.center,
|
||||
@@ -858,7 +866,7 @@ class SalesThermalPrinterInvoice {
|
||||
text: formatPointNumber(
|
||||
(productList?[index].price ?? 0) * getProductQuantity(detailsId: productList?[index].id ?? 0),
|
||||
addComma: true),
|
||||
width: 2,
|
||||
width: 3,
|
||||
styles: const PosStyles(align: PosAlign.right)),
|
||||
]);
|
||||
if (warranty.isNotEmpty) {
|
||||
|
||||
Reference in New Issue
Block a user