extractArticlesCalibresFromParsedCsvExcel method

List<CalibreWeebi<ArticleRetail>> extractArticlesCalibresFromParsedCsvExcel(
  1. int nextLineId
)

Implementation

List<CalibreWeebi<ArticleRetail>> extractArticlesCalibresFromParsedCsvExcel(
    int nextLineId) {
  final linesList = <CalibreWeebi<ArticleRetail>>[];
  var nextId = nextLineId; // just in case..
  for (var i = 0; i < length; i++) {
    final now = DateTime.now();
    final table = this[i];
    final newArticle = ArticleRetail(
      calibreId: nextId,
      id: 1,
      articleCode: int.tryParse('${nextId}1'),
      creationDate: now,
      designation: table[0] != null ? table[0].toString().trim() : '',
      price: table[1] != null
          ? table[1].runtimeType == num
              ? table[1]
              : num.tryParse(table[1])
          : 0,
      cost: table[2] != null
          ? table[2].runtimeType == num
              ? table[2]
              : num.tryParse(table[2])
          : 0,
      unitsInOnePiece: 1.0,
      barcodeEAN: table[3] != null ? '${table[3]}' : '',
    );
    final newCalibre = CalibreWeebi<ArticleRetail>(
      creationDate: now,
      updateDate: now,
      id: nextId,
      kind: ArticleKind.retail,
      title: table[0] != null ? table[0].toString().trim() : '',
      status: true,
      statusUpdateDate: DateTime.now(),
      stockUnit: StockUnit.unit,
      articles: [newArticle],
    );
    linesList.add(newCalibre);
    nextId++;
  }
  return linesList;
}