updateSellThruOrder method
Implementation
Future<void> updateSellThruOrder(CartModel model) async {
var totalAmount = model.data!.totalRetailPrice; // subTotal
var totalNetAmount = model.data!.totalNetPrice; // strike through
double totalTax = model.data!.overallSaleTax ?? 0.0; //
double ctw = model.data!.totalWHT ?? 0.0; // - value
discountAmount.value = model.data?.totalDiscount ?? "";
var salesTax = "";
var ctwNegativeTax = ""; // red color
var localCurrency = model.data!.grandTotalInLocalCurrency!.price!.currency;
var currency = model.data!.currency;
var localGrandTotal = model.data!.grandTotalInLocalCurrency!.price!.amount;
// model.data?.taxes?.forEach((tax) {
// if (tax.name == "SalesTax") {
// salesTax = tax.name!;
// totalTax = double.parse(tax.totalPrice!);
// }
// if (tax.name!.toLowerCase() == "ctw") {
// ctwNegativeTax = tax.name!;
// ctw = double.parse(tax.totalPrice!);
// }
// });
// double overallSaleTaxPercentage = 0.0; //
// overallSaleTaxPercentage = model.data?.overallSaleTaxPercentage ?? 0.0;
double? ctwPercentage;
var totalDiscount = 0.0;
var netCommission = 0.0;
if (model.data?.taxes != null) {
// total discount
model.data?.taxes?.forEach((element) {
if (element.name! == "COMMISSION" || element.name! == "Commission") {
totalDiscount = element.totalPrice != null
? double.parse(element.totalPrice!)
: 0.0;
}
if (element.name! == "WHT" || element.name! == "CTW") {
ctwPercentage = element.percentage;
var sign = 1;
if (element.whtBearer != null &&
element.whtBearer!.isNotEmpty &&
element.whtBearer! == "DEALER") {
sign = -1;
}
ctw = element.totalPrice != null
? double.parse(element.totalPrice!) * sign
: 0.0;
}
if (element.name! == "Net Commission") {
netCommission = element.totalPrice != null
? double.parse(element.totalPrice!)
: 0.0;
}
});
}
var totalAmountPaid = model.data!.grandTotal ?? "0.0";
int overallSaleTaxPercentage = 0; //
// overallSaleTaxPercentage = model.data?.overallSaleTaxPercentage ?? 0.0;
List<SaleTaxes>? saleTaxes = model.data?.saleTaxes;
overallSaleTaxPercentage = saleTaxes?.firstOrNull?.taxPercentageValue ?? 0;
totalTax = double.parse(saleTaxes?.firstOrNull?.totalPrice ?? "0.0");
var products = model.data!.products;
ConditionalLogs().customLog('products${products}');
RxList<ProductContentModel> temp = <ProductContentModel>[].obs;
for (var product in products!) {
ConditionalLogs().customLog('product :: ==> ${product.name}');
ProductContentModel productModel = ProductContentModel();
productModel.id = int.parse(product.id!);
productModel.productId = product.productId;
productModel.productName = product.name;
productModel.productCode = product.productCode;
productModel.productImage = product.productImage;
productModel.totalOrderedQuantity = 0;
productModel.itemAmount = double.parse(product.unitPrice!);
productModel.itemTax = double.parse(product.unitTax!);
productModel.unitDiscount = double.parse(product.unitDiscount!);
productModel.sellingPrice = double.parse(product.sellingPrice!);
productModel.unitSellingPrice = double.parse(product.sellingUnitPrice!);
productModel.scannedQty = product.quantity!;
temp.add(productModel);
// if (temp.isNotEmpty) {
// for (int i = 0; i < temp.length; i++) {
// print('temp product :: ==> ${temp[i].toJson()}');
// if (product.name == temp[i].productName) {
// ProductContentModel productModel = ProductContentModel();
// productModel = temp[i].copyWith(
// id: int.parse(product.productId!),
// productName: product.name,
// productCode: product.productCode,
// productImage: product.productImage,
// scannedQty: product.quantity!,
// itemAmount: double.parse(product.unitPrice!),
// itemTax: double.parse(product.unitTax!),
// );
// temp[i] = productModel; // updating existing product on temp
// }
// // else {
// // // new product
// // ProductContentModel productModel = ProductContentModel();
// // productModel.id = int.parse(product.productId!);
// // productModel.productName = product.name;
// // productModel.productCode = product.productCode;
// // productModel.productImage = product.productImage;
// // productModel.totalOrderedQuantity = 0;
// // productModel.itemAmount = double.parse(product.unitPrice!);
// // productModel.itemTax = double.parse(product.unitTax!);
// // productModel.scannedQty = product.quantity!;
// // temp.add(productModel); // adding new product on temp
// // }
// }
// } else {
// // new product
// ProductContentModel productModel = ProductContentModel();
// productModel.id = int.parse(product.productId!);
// productModel.productName = product.name;
// productModel.productCode = product.productCode;
// productModel.productImage = product.productImage;
// productModel.totalOrderedQuantity = 0;
// productModel.itemAmount = double.parse(product.unitPrice!);
// productModel.itemTax = double.parse(product.unitTax!);
// productModel.scannedQty = product.quantity!;
// temp.add(productModel); // adding new product on temp
// }
}
ConditionalLogs().customLog('temp-->$temp');
selectedProduct.value = [...temp]; // assigning product list
sellThruOrder.value = sellThruOrder.value.copyWith(
currency: currency,
localCurrency: localCurrency,
localCurrencyGrandTotal: double.parse(localGrandTotal!),
ctwNegativeTax: ctwNegativeTax,
ctw: ctw,
salesTax: salesTax,
content: selectedProduct,
totalAmount: double.parse(totalAmount.toString()),
totalNetAmount: totalNetAmount,
totalTax: totalTax,
taxPercentage: ctwPercentage?.toString(),
overallSaleTaxPercentage: overallSaleTaxPercentage.toDouble(),
stockOrderOverallSaleTaxPercentage: overallSaleTaxPercentage,
totalDiscount: totalDiscount,
totalAmountPaid: double.parse(totalAmountPaid),
netCommission: netCommission,
);
}