first commit
This commit is contained in:
161
lib/Provider/add_to_cart_purchase.dart
Normal file
161
lib/Provider/add_to_cart_purchase.dart
Normal file
@@ -0,0 +1,161 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:nb_utils/nb_utils.dart';
|
||||
|
||||
import '../Screens/Purchase/Repo/purchase_repo.dart';
|
||||
import '../Screens/vat_&_tax/model/vat_model.dart';
|
||||
|
||||
final cartNotifierPurchaseNew = ChangeNotifierProvider((ref) => CartNotifierPurchase());
|
||||
|
||||
class CartNotifierPurchase extends ChangeNotifier {
|
||||
List<CartProductModelPurchase> cartItemList = [];
|
||||
TextEditingController discountTextControllerFlat = TextEditingController();
|
||||
TextEditingController vatAmountController = TextEditingController();
|
||||
TextEditingController shippingChargeController = TextEditingController();
|
||||
|
||||
///_________NEW_________________________________
|
||||
num totalAmount = 0;
|
||||
num discountAmount = 0;
|
||||
num discountPercent = 0;
|
||||
num totalPayableAmount = 0;
|
||||
VatModel? selectedVat;
|
||||
num vatAmount = 0;
|
||||
bool isFullPaid = false;
|
||||
num receiveAmount = 0;
|
||||
num changeAmount = 0;
|
||||
num dueAmount = 0;
|
||||
num finalShippingCharge = 0;
|
||||
|
||||
void changeSelectedVat({VatModel? data}) {
|
||||
if (data != null) {
|
||||
selectedVat = data;
|
||||
} else {
|
||||
selectedVat = null;
|
||||
vatAmount = 0;
|
||||
vatAmountController.clear();
|
||||
}
|
||||
|
||||
calculatePrice();
|
||||
}
|
||||
|
||||
void calculateDiscount({
|
||||
required String value,
|
||||
bool? rebuilding,
|
||||
String? selectedTaxType,
|
||||
}) {
|
||||
if (value.isEmpty) {
|
||||
discountAmount = 0;
|
||||
discountPercent = 0;
|
||||
discountTextControllerFlat.clear();
|
||||
} else {
|
||||
num discountValue = num.tryParse(value) ?? 0;
|
||||
|
||||
if (selectedTaxType == null) {
|
||||
EasyLoading.showError('Please select a discount type');
|
||||
discountAmount = 0;
|
||||
discountPercent = 0;
|
||||
} else if (selectedTaxType == "Flat") {
|
||||
discountAmount = discountValue;
|
||||
|
||||
if (discountAmount > totalAmount) {
|
||||
discountTextControllerFlat.clear();
|
||||
discountAmount = 0;
|
||||
EasyLoading.showError('Enter a valid discount');
|
||||
}
|
||||
} else if (selectedTaxType == "Percent") {
|
||||
discountPercent = discountValue;
|
||||
discountAmount = (totalAmount * discountPercent) / 100;
|
||||
|
||||
if (discountAmount > totalAmount) {
|
||||
discountAmount = totalAmount;
|
||||
}
|
||||
} else {
|
||||
EasyLoading.showError('Invalid discount type selected');
|
||||
discountAmount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (rebuilding == false) return;
|
||||
calculatePrice();
|
||||
}
|
||||
|
||||
void updateProduct({required int index, required CartProductModelPurchase newProduct}) {
|
||||
cartItemList[index] = newProduct;
|
||||
calculatePrice();
|
||||
}
|
||||
|
||||
void calculatePrice({String? receivedAmount, String? shippingCharge, bool? stopRebuild}) {
|
||||
totalAmount = 0;
|
||||
totalPayableAmount = 0;
|
||||
dueAmount = 0;
|
||||
for (var element in cartItemList) {
|
||||
totalAmount += (element.quantities ?? 0) * (element.productPurchasePrice ?? 0);
|
||||
}
|
||||
totalPayableAmount = totalAmount;
|
||||
|
||||
if (discountAmount > totalAmount) {
|
||||
calculateDiscount(value: discountAmount.toString(), rebuilding: false);
|
||||
}
|
||||
if (discountAmount >= 0) {
|
||||
totalPayableAmount -= discountAmount;
|
||||
}
|
||||
if (selectedVat?.rate != null) {
|
||||
vatAmount = (totalPayableAmount * selectedVat!.rate!) / 100;
|
||||
vatAmountController.text = vatAmount.toStringAsFixed(2);
|
||||
}
|
||||
|
||||
totalPayableAmount += vatAmount;
|
||||
if (shippingCharge != null) {
|
||||
finalShippingCharge = num.tryParse(shippingCharge) ?? 0;
|
||||
}
|
||||
totalPayableAmount += finalShippingCharge;
|
||||
if (receivedAmount != null) {
|
||||
receiveAmount = num.tryParse(receivedAmount) ?? 0;
|
||||
}
|
||||
changeAmount = totalPayableAmount < receiveAmount ? receiveAmount - totalPayableAmount : 0;
|
||||
dueAmount = totalPayableAmount < receiveAmount ? 0 : totalPayableAmount - receiveAmount;
|
||||
if (dueAmount <= 0) isFullPaid = true;
|
||||
if (stopRebuild ?? false) return;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
double getTotalAmount() {
|
||||
double totalAmountOfCart = 0;
|
||||
for (var element in cartItemList) {
|
||||
totalAmountOfCart = totalAmountOfCart + ((element.productPurchasePrice ?? 0) * (element.quantities ?? 0));
|
||||
}
|
||||
|
||||
return totalAmountOfCart;
|
||||
}
|
||||
|
||||
void quantityIncrease(int index) {
|
||||
cartItemList[index].quantities = (cartItemList[index].quantities ?? 0) + 1;
|
||||
calculatePrice();
|
||||
}
|
||||
|
||||
void quantityDecrease(int index) {
|
||||
if ((cartItemList[index].quantities ?? 0) > 1) {
|
||||
cartItemList[index].quantities = (cartItemList[index].quantities ?? 0) - 1;
|
||||
}
|
||||
calculatePrice();
|
||||
}
|
||||
|
||||
void addToCartRiverPod({required CartProductModelPurchase cartItem, bool? fromEditSales, required bool isVariation}) {
|
||||
if (!cartItemList
|
||||
.any((element) => isVariation ? (element.productId == cartItem.productId && element.batchNumber == cartItem.batchNumber) : element.productId == cartItem.productId)) {
|
||||
cartItemList.add(cartItem);
|
||||
} else {
|
||||
int index = cartItemList.indexWhere(
|
||||
(element) => isVariation ? (element.productId == cartItem.productId && element.batchNumber == cartItem.batchNumber) : element.productId == cartItem.productId,
|
||||
);
|
||||
cartItemList[index] = cartItem;
|
||||
}
|
||||
(fromEditSales ?? false) ? null : calculatePrice();
|
||||
}
|
||||
|
||||
void deleteToCart(int index) {
|
||||
cartItemList.removeAt(index);
|
||||
calculatePrice();
|
||||
}
|
||||
}
|
||||
10
lib/Provider/product_provider.dart
Normal file
10
lib/Provider/product_provider.dart
Normal file
@@ -0,0 +1,10 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:mobile_pos/Screens/Products/Model/product_model.dart';
|
||||
|
||||
import '../Screens/Products/Repo/product_repo.dart';
|
||||
|
||||
ProductRepo productRepo = ProductRepo();
|
||||
final productProvider = FutureProvider.autoDispose<List<Product>>((ref) => productRepo.fetchAllProducts());
|
||||
final fetchProductDetails = FutureProvider.family.autoDispose<Product, String>((ref, id) {
|
||||
return productRepo.fetchProductDetails(productID: id);
|
||||
});
|
||||
20
lib/Provider/profile_provider.dart
Normal file
20
lib/Provider/profile_provider.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:mobile_pos/model/business_info_model.dart';
|
||||
import 'package:mobile_pos/model/dashboard_overview_model.dart';
|
||||
|
||||
import '../Repository/API/business_info_repo.dart';
|
||||
import '../service/check_user_role_permission_provider.dart';
|
||||
import '../model/todays_summary_model.dart';
|
||||
|
||||
final BusinessRepository businessRepository = BusinessRepository();
|
||||
final businessInfoProvider = FutureProvider<BusinessInformationModel>((ref) async {
|
||||
return await BusinessRepository().fetchBusinessData();
|
||||
});
|
||||
|
||||
final getExpireDateProvider = FutureProvider.family<void, WidgetRef>(
|
||||
(ref, widgetRef) => businessRepository.fetchSubscriptionExpireDate(ref: widgetRef));
|
||||
final summaryInfoProvider = FutureProvider<TodaysSummaryModel>((ref) => businessRepository.fetchTodaySummaryData());
|
||||
final dashboardInfoProvider = FutureProvider.family<DashboardOverviewModel, String>((ref, type) {
|
||||
return businessRepository.dashboardData(type);
|
||||
});
|
||||
7
lib/Provider/shop_category_provider.dart
Normal file
7
lib/Provider/shop_category_provider.dart
Normal file
@@ -0,0 +1,7 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../Repository/API/business_category_repo.dart';
|
||||
import '../model/business_category_model.dart';
|
||||
|
||||
BusinessCategoryRepository businessCategoryRepository = BusinessCategoryRepository();
|
||||
final businessCategoryProvider = FutureProvider<List<BusinessCategory>>((ref) => businessCategoryRepository.getBusinessCategories());
|
||||
203
lib/Provider/transactions_provider.dart
Normal file
203
lib/Provider/transactions_provider.dart
Normal file
@@ -0,0 +1,203 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:mobile_pos/Screens/Purchase/Model/purchase_transaction_model.dart';
|
||||
import 'package:mobile_pos/Screens/Purchase/Repo/purchase_repo.dart';
|
||||
import 'package:mobile_pos/Screens/Sales/Repo/sales_repo.dart';
|
||||
import 'package:mobile_pos/model/sale_transaction_model.dart';
|
||||
|
||||
import '../model/balance_sheet_model.dart' as bs;
|
||||
import '../model/bill_wise_loss_profit_report_model.dart' as bwlprm;
|
||||
import '../model/cashflow_model.dart' as cf;
|
||||
import '../model/loss_profit_model.dart' as lpmodel;
|
||||
import '../model/product_history_model.dart' as phlm;
|
||||
import '../model/subscription_report_model.dart' as srm;
|
||||
import '../model/tax_report_model.dart' as trm;
|
||||
|
||||
//------------sales-------------------------------------
|
||||
final saleRepo = Provider<SaleRepo>((ref) => SaleRepo());
|
||||
|
||||
final salesTransactionProvider = FutureProvider.autoDispose<List<SalesTransactionModel>>((ref) {
|
||||
final repo = ref.read(saleRepo);
|
||||
return repo.fetchSalesList();
|
||||
});
|
||||
|
||||
final filteredSaleProvider = FutureProvider.family.autoDispose<List<SalesTransactionModel>, FilterModel>(
|
||||
(ref, filter) {
|
||||
final repo = ref.read(saleRepo);
|
||||
return repo.fetchSalesList(
|
||||
type: filter.duration,
|
||||
fromDate: filter.fromDate,
|
||||
toDate: filter.toDate,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final filteredSaleReturnedProvider = FutureProvider.family.autoDispose<List<SalesTransactionModel>, FilterModel>(
|
||||
(ref, filter) {
|
||||
final repo = ref.read(saleRepo);
|
||||
return repo.fetchSalesList(
|
||||
type: filter.duration,
|
||||
fromDate: filter.fromDate,
|
||||
toDate: filter.toDate,
|
||||
salesReturn: true,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
//------------------purchase----------------------------------------
|
||||
final purchaseRepo = Provider<PurchaseRepo>((ref) => PurchaseRepo());
|
||||
|
||||
final purchaseTransactionProvider = FutureProvider.autoDispose<List<PurchaseTransaction>>((ref) {
|
||||
final repo = ref.read(purchaseRepo);
|
||||
return repo.fetchPurchaseList();
|
||||
});
|
||||
|
||||
final filterPurchaseProvider = FutureProvider.family.autoDispose<List<PurchaseTransaction>, FilterModel>(
|
||||
(ref, filter) {
|
||||
final repo = ref.read(purchaseRepo);
|
||||
return repo.fetchPurchaseList(
|
||||
type: filter.duration,
|
||||
fromDate: filter.fromDate,
|
||||
toDate: filter.toDate,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final filterPurchaseReturnProvider = FutureProvider.family.autoDispose<List<PurchaseTransaction>, FilterModel>(
|
||||
(ref, filter) {
|
||||
final repo = ref.read(purchaseRepo);
|
||||
return repo.fetchPurchaseList(
|
||||
type: filter.duration,
|
||||
fromDate: filter.fromDate,
|
||||
toDate: filter.toDate,
|
||||
salesReturn: true,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final filteredLossProfitProvider = FutureProvider.family.autoDispose<lpmodel.LossProfitModel, FilterModel>(
|
||||
(ref, filter) {
|
||||
final repo = ref.read(saleRepo);
|
||||
return repo.getLossProfit(
|
||||
type: filter.duration,
|
||||
fromDate: filter.fromDate,
|
||||
toDate: filter.toDate,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final filteredCashflowProvider = FutureProvider.family.autoDispose<cf.CashflowModel, FilterModel>(
|
||||
(ref, filter) {
|
||||
final repo = ref.read(saleRepo);
|
||||
return repo.getCashflow(
|
||||
type: filter.duration,
|
||||
fromDate: filter.fromDate,
|
||||
toDate: filter.toDate,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final filteredBalanceSheetProvider = FutureProvider.family.autoDispose<bs.BalanceSheetModel, FilterModel>(
|
||||
(ref, filter) {
|
||||
final repo = ref.read(saleRepo);
|
||||
return repo.getBalanceSheet(
|
||||
type: filter.duration,
|
||||
fromDate: filter.fromDate,
|
||||
toDate: filter.toDate,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final filteredSubscriptionReportProvider =
|
||||
FutureProvider.family.autoDispose<List<srm.SubscriptionReportModel>, FilterModel>(
|
||||
(ref, filter) {
|
||||
final repo = ref.read(saleRepo);
|
||||
return repo.getSubscriptionReport(
|
||||
type: filter.duration,
|
||||
fromDate: filter.fromDate,
|
||||
toDate: filter.toDate,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final filteredTaxReportReportProvider = FutureProvider.family.autoDispose<trm.TaxReportModel, FilterModel>(
|
||||
(ref, filter) {
|
||||
final repo = ref.read(saleRepo);
|
||||
return repo.getTaxReport(
|
||||
type: filter.duration,
|
||||
fromDate: filter.fromDate,
|
||||
toDate: filter.toDate,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final filteredBillWiseLossProfitReportProvider =
|
||||
FutureProvider.family.autoDispose<bwlprm.BillWiseLossProfitReportModel, FilterModel>(
|
||||
(ref, filter) {
|
||||
final repo = ref.read(saleRepo);
|
||||
return repo.getBillWiseLossProfitReport(
|
||||
type: filter.duration,
|
||||
fromDate: filter.fromDate,
|
||||
toDate: filter.toDate,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final filteredProductSaleHistoryReportProvider =
|
||||
FutureProvider.family.autoDispose<phlm.ProductHistoryListModel, FilterModel>(
|
||||
(ref, filter) {
|
||||
final repo = ref.read(saleRepo);
|
||||
return repo.getProductSaleHistoryReport(
|
||||
type: filter.duration,
|
||||
fromDate: filter.fromDate,
|
||||
toDate: filter.toDate,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final filteredProductSaleHistoryReportDetailsProvider =
|
||||
FutureProvider.family.autoDispose<phlm.ProductHistoryDetailsModel, ({int productId, FilterModel filter})>(
|
||||
(ref, arg) {
|
||||
final repo = ref.read(saleRepo);
|
||||
return repo.getProductSaleHistoryReportDetails(
|
||||
productId: arg.productId,
|
||||
type: arg.filter.duration,
|
||||
fromDate: arg.filter.fromDate,
|
||||
toDate: arg.filter.toDate,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final filteredProductPurchaseHistoryReportDetailsProvider =
|
||||
FutureProvider.family.autoDispose<phlm.ProductHistoryDetailsModel, ({int productId, FilterModel filter})>(
|
||||
(ref, arg) {
|
||||
final repo = ref.read(saleRepo);
|
||||
return repo.getProductPurchaseHistoryReportDetails(
|
||||
productId: arg.productId,
|
||||
type: arg.filter.duration,
|
||||
fromDate: arg.filter.fromDate,
|
||||
toDate: arg.filter.toDate,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
class FilterModel {
|
||||
final String? duration;
|
||||
final String? fromDate;
|
||||
final String? toDate;
|
||||
|
||||
FilterModel({
|
||||
this.duration,
|
||||
this.fromDate,
|
||||
this.toDate,
|
||||
});
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is FilterModel && other.duration == duration && other.fromDate == fromDate && other.toDate == toDate;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => duration.hashCode ^ fromDate.hashCode ^ toDate.hashCode;
|
||||
}
|
||||
Reference in New Issue
Block a user