makeChanges method

Future<FirestoreErrors?> makeChanges({
  1. String? newName,
  2. int? newRate,
  3. int? newDefaultDiscount,
  4. Map<String, int>? newCustomerDiscount,
  5. Map<int, int>? newSellerRate,
  6. int? newDefaultBoughtRate,
  7. int? newRankOrderValue,
})

Implementation

Future<FirestoreErrors?> makeChanges({
  String? newName,
  int? newRate,
  int? newDefaultDiscount,
  Map<String, int>? newCustomerDiscount,
  Map<int, int>? newSellerRate,
  int? newDefaultBoughtRate,
  int? newRankOrderValue,
}) async {
  if (id == -1) return null;
  final compneyID = B2bAuthUser.inUse?.compneyIdInUse;
  if (compneyID == null) return null;
  if (B2bAuthUser.inUse?.hasOwnerPermission != true) return null;
  return await firestore.updateDoc(
    docPath: "B2B/$compneyID/DATA/PRODUCTS",
    data: {
      if (isNew) "avalable.$id.pIB": pckInBox?.quntity,
      "avalable.$id.n": newName ?? name,
      "avalable.$id.r": newRate ?? rate.money,
      "avalable.$id.dD": newDefaultDiscount ?? defaultDiscount.money,
      "avalable.$id.cD": newCustomerDiscount ??
          customerDiscount.map((key, value) => MapEntry(key, value.money)),
      "avalable.$id.rOV": newRankOrderValue ?? rankOrderValue,
      "avalable.$id.sR": newSellerRate
              ?.map((key, value) => MapEntry(key.toString(), value)) ??
          sellerRate.map((key, value) => MapEntry(key, value.money)),
      "avalable.$id.dBR": newDefaultBoughtRate ?? defaultBoughtRate.money,
      if (isNew == true) "nextUsableID": FieldValue.increment(1),
    },
  );
}