reportStockArtCalibres property

List<ReportStockArtCalibre> get reportStockArtCalibres

Implementation

List<ReportStockArtCalibre> get reportStockArtCalibres {
  // reset
  for (final r in emptyReportStockArtCalibres) {
    r.initialQtCl = 0.0;
    r.finalQtCl = 0.0;

    //r.initialQtTickets = 0.0; // used in extension keep it
    r.varQtTickets = 0.0; // used in extension keep it

    for (final a in r.articles) {
      a.qtIn = 0.0;
      a.qtOut = 0.0;
    }
  }

  //print('startDate $startDate  endDate $endDate');
  final dateRange = DateRange(start, end);

  emptyReportStockArtCalibres = tickets.shopTicketsStock(
      objectId, dateRange, articlesC, emptyReportStockArtCalibres);

  if (closingsObjects.isNotEmpty) {
    for (final c in closingsObjects) {
      if (c.boutiqueId == objectId && c.closingRange.isInRange(start, end)) {
        articlesC
            .where((p) => p.id != 0) // not including product 0
            .forEach((p) {
          if (c.articleCalibres.any((i) => i.id == p.id)) {
            // find the one matching the time filter
            final clStPrd = c.articleCalibres
                .firstWhere((closingStockP) => closingStockP.id == p.id);

            var rP = emptyReportStockArtCalibres
                .firstWhere((reportStockP) => reportStockP.id == p.id);
            // * here one way only thanks to final Quantity
            rP.initialQtCl += clStPrd.initialQtCl;
            rP.finalQtCl += clStPrd.finalQtCl;

            if (p.articles.length > 1) {
              for (final article in p.articles) {
                // find the one matching the time filter
                if (clStPrd.articles.any((a) =>
                    a.id == article.id && a.calibreId == article.calibreId)) {
                  final cSArticle = clStPrd.articles.firstWhere((a) =>
                      a.id == article.id && a.calibreId == article.calibreId);

                  var aR = rP.articles.firstWhere((a) =>
                      a.id == article.id && a.calibreId == article.calibreId);

                  aR.qtIn += cSArticle.quantityIn;
                  aR.qtOut += cSArticle.quantityOut;
                }
              }
            }
          }
        });
      }
    }
  }
  return emptyReportStockArtCalibres;
}