extractContactsFromParsedCsvExcel method

List<ContactWeebi> extractContactsFromParsedCsvExcel(
  1. int nextContactId
)

bulk imports cannot deduce country dial code, avoid adding another column or a dodgy logic, nobody cares similiarly they cannot deduce check country code solidly enough

Implementation

List<ContactWeebi> extractContactsFromParsedCsvExcel(int nextContactId) {
  final contactsList = <ContactWeebi>[];
  var nextId = nextContactId; // just in case..

  for (final row in this) {
    if (row[0] != null && row[0].toString().trim() == 'firstName') {
      continue;
    }

    final street = row[4] != null ? row[4].toString().trim() : '';
    final code = row[5] != null ? row[5].toString().trim() : '';
    final city = row[6] != null ? row[6].toString().trim() : '';

    final address = (street.isNotEmpty || city.isNotEmpty || code.isNotEmpty)
        ? Address(
            street: street, city: city, code: code, country: Country.empty)
        : Address.empty;

    final now = DateTime.now();
    final herder = ContactWeebi(
      id: nextId,
      updateDate: now,
      status: true,
      statusUpdateDate: now,
      creationDate: DateTime.now(),
      firstName: row[0] != null ? row[0].toString().trim() : '',
      lastName: row[1] != null ? row[1].toString().trim() : '',
      phone: Phone(0, row[2] == null ? '' : row[2].toString().trim()),
      mail: row[3] != null ? row[3].toString().trim() : '',
      addressFull: address,
      categories:
          row[7] != null ? [row[7].toString().trim()] : const <String>[],
      // TODO handle isClient in import
      isClient: false,
      isSupplier: false,
    );
    contactsList.add(herder);
    nextId++;
  }
  // print('contactsList.length ${contactsList.length}');
  return contactsList;
}