def rows(self):
        rows = []
        if self.location_id:
            for location in self.get_locations:
                supply_points = self.get_supply_points(location.location_id)
                sites = supply_points.count()
                reported = StockTransaction.objects.filter(
                    case_id__in=supply_points.values_list('supply_point_id', flat=True),
                    report__date__range=[self.config['startdate'], self.config['enddate']]
                ).distinct('case_id').count()
                reporting_rates = '%.2f%%' % (reported * 100 / (float(sites) or 1.0))

                completed = 0
                for supply_point in supply_points:
                    reported_products = StockTransaction.objects.filter(
                        case_id=supply_point.supply_point_id,
                        report__date__range=[self.config['startdate'], self.config['enddate']]
                    ).distinct('product_id').values_list('product_id', flat=True)
                    if not (set(supply_point.products) - set(reported_products)):
                        completed += 1
                completed_rates = '%.2f%%' % (completed * 100 / (float(sites) or 1.0))
                url = make_url(
                    ReportingRatesReport,
                    self.config['domain'],
                    '?location_id=%s&startdate=%s&enddate=%s',
                    (location.location_id, self.config['startdate'], self.config['enddate']))

                rows.append([link_format(location.name, url), sites, reported, reporting_rates, completed_rates])
        return rows
    def rows(self):
        rows = []
        if self.config['location_id']:
            supply_points = get_supply_points(self.config['location_id'], self.config['domain']).values_list(
                'supply_point_id', flat=True
            )
            last_period_st, last_period_end = calculate_last_period(self.config['enddate'])
            reported = StockTransaction.objects.filter(case_id__in=supply_points,
                                                       report__date__range=[last_period_st,
                                                                            last_period_end]
                                                       ).values_list('case_id', flat=True)

            not_reported = SQLLocation.objects.filter(location_type__in=self.location_types,
                                                      parent__location_id=self.config['location_id'])\
                .exclude(supply_point_id__in=reported)

            for loc in not_reported:
                url = make_url(
                    StockLevelsReport,
                    self.config['domain'],
                    '?location_id=%s&startdate=%s&enddate=%s',
                    (loc.location_id, self.config['startdate'], self.config['enddate']))

                st = StockTransaction.objects.filter(case_id=loc.supply_point_id).order_by('-report__date')
                if st:
                    date = st[0].report.date
                else:
                    date = _('---')
                rows.append([link_format(loc.name, url), date])
        return rows
    def rows(self):
        rows = []
        if self.config['location_id']:
            last_period_st, last_period_end = calculate_last_period(self.config['enddate'])
            locations = SQLLocation.objects.filter(parent__location_id=self.config['location_id'],
                                                   location_type__in=self.location_types)
            for loc in locations:
                st = StockTransaction.objects.filter(case_id=loc.supply_point_id,
                                                     report__date__range=[last_period_st,
                                                                          last_period_end]
                                                     ).order_by('-report__date')
                st_count = st.distinct('product_id').count()
                if len(loc.products) != st_count:
                    if st:
                        date = st[0].report.date
                    else:
                        date = '---'

                    url = make_url(
                        StockLevelsReport,
                        self.config['domain'],
                        '?location_id=%s&startdate=%s&enddate=%s',
                        (loc.location_id, self.config['startdate'], self.config['enddate']))
                    rows.append([link_format(loc.name, url), date])
        return rows
    def rows(self):
        rows = []
        if self.location_id:
            if self.location.location_type.name == 'country':
                supply_points = self.reporting_supply_points(self.all_reporting_locations())
            else:
                supply_points = self.reporting_supply_points()
            for location in SQLLocation.objects.filter(supply_point_id__in=supply_points):
                st = StockTransaction.objects.filter(
                    case_id=location.supply_point_id,
                    report__date__range=[self.config['startdate'], self.config['enddate']]
                ).order_by('-report__date')
                products_per_location = {product.product_id for product in location.products}
                if products_per_location - set(st.values_list('product_id', flat=True)):
                    if st:
                        date = st[0].report.date.strftime("%m-%d-%Y")
                    else:
                        date = '---'

                    url = make_url(
                        StockLevelsReport,
                        self.config['domain'],
                        '?location_id=%s&startdate=%s&enddate=%s',
                        (location.location_id, self.config['startdate'], self.config['enddate']))
                    rows.append([link_format(location.name, url), date])
        return rows
    def rows(self):
        rows = []
        if self.location_id:
            supply_points = self.get_supply_points()
            with_reporters, with_in_charge = self.supply_points_users()
            for sp in supply_points:
                url = make_url(
                    StockLevelsReport, self.config['domain'], '?location_id=%s&startdate=%s&enddate=%s',
                    (sp.location_id, json_format_date(self.config['startdate']),
                     json_format_date(self.config['enddate']))
                )
                if sp.supply_point_id not in self.config['reporting_supply_points']:
                    rows.append(['<div style="background-color: rgba(255, 0, 0, 0.2)">%s has not reported last '
                                 'month. <a href="%s" target="_blank">[details]</a></div>' % (sp.name, url)])
                if sp.location_id not in with_reporters:
                    rows.append(['<div style="background-color: rgba(255, 0, 0, 0.2)">%s has no reporters'
                                 ' registered. <a href="%s" target="_blank">[details]</a></div>' % (sp.name, url)])
                if sp.location_id not in with_in_charge:
                    rows.append(['<div style="background-color: rgba(255, 0, 0, 0.2)">%s has no in-charge '
                                 'registered. <a href="%s" target="_blank">[details]</a></div>' % (sp.name, url)])

        if not rows:
            rows.append(['<div style="background-color: rgba(0, 255, 0, 0.2)">No current alerts</div>'])

        return rows
    def rows(self):
        rows = []
        if self.location_id:
            supply_points = self.get_supply_points()
            with_reporters, with_in_charge = self.supply_points_users()
            last_month_reporting_sp_ids = self.last_month_reporting_sp_ids
            for sp in supply_points:
                url = make_url(
                    ReportingRatesReport, self.config['domain'], '?location_id=%s&startdate=%s&enddate=%s',
                    (sp.location_id, json_format_date(self.config['startdate']),
                     json_format_date(self.config['enddate']))
                )
                if sp.supply_point_id not in last_month_reporting_sp_ids:
                    rows.append(['<div style="background-color: rgba(255, 0, 0, 0.2)">%s has not reported last '
                                 'month. <a href="%s" target="_blank">[details]</a></div>' % (sp.name, url)])
                if sp.location_id not in with_reporters:
                    rows.append(['<div style="background-color: rgba(255, 0, 0, 0.2)">%s has no reporters'
                                 ' registered. <a href="%s" target="_blank">[details]</a></div>' % (sp.name, url)])
                if sp.location_id not in with_in_charge:
                    rows.append(['<div style="background-color: rgba(255, 0, 0, 0.2)">%s has no in-charge '
                                 'registered. <a href="%s" target="_blank">[details]</a></div>' % (sp.name, url)])

        if not rows:
            rows.append(['<div style="background-color: rgba(0, 255, 0, 0.2)">No current alerts</div>'])

        return rows
 def rows(self):
     rows = []
     if self.location_id:
         for name, location_id, date in self.config['incomplete_table']:
             url = make_url(
                 StockLevelsReport,
                 self.config['domain'],
                 '?location_id=%s&startdate=%s&enddate=%s',
                 (location_id, self.config['startdate'], self.config['enddate'])
             )
             rows.append([link_format(name, url), ews_date_format(date)])
     return rows
Exemple #8
0
 def _ils_make_url(self, cls):
     params = '?location_id=%s&filter_by_program=%s&datespan_type=%s&datespan_first=%s&datespan_second=%s'
     return make_url(cls, self.domain, params, (
         self.request.GET.get(
             'location_id',
             get_object_or_404(SQLLocation,
                               domain=self.domain,
                               location_type__name='MOHSW').location_id),
         self.request.GET.get('filter_by_program', ''),
         self.request.GET.get('datespan_type', ''),
         self.request.GET.get('datespan_first', ''),
         self.request.GET.get('datespan_second', ''),
     ))
Exemple #9
0
 def _ils_make_url(self, cls):
     params = '?location_id=%s&filter_by_program=%s&datespan_type=%s&datespan_first=%s&datespan_second=%s'
     return make_url(cls, self.domain, params, (
         self.request.GET.get(
             'location_id', get_object_or_404(
                 SQLLocation, domain=self.domain, location_type__name='MOHSW'
             ).location_id
         ),
         self.request.GET.get('filter_by_program', ''),
         self.request.GET.get('datespan_type', ''),
         self.request.GET.get('datespan_first', ''),
         self.request.GET.get('datespan_second', ''),
     ))
Exemple #10
0
 def rows(self):
     rows = []
     if self.location_id:
         for name, location_id, date in self.config['incomplete_table']:
             url = make_url(ReportingRatesReport, self.config['domain'],
                            '?location_id=%s&startdate=%s&enddate=%s',
                            (location_id, self.config['startdate'],
                             self.config['enddate']))
             rows.append([
                 link_format(name, url)
                 if not self.config['is_rendered_as_email'] else name,
                 ews_date_format(date)
             ])
     return rows
Exemple #11
0
 def rows(self):
     rows = []
     if self.location_id:
         for name, location_id, date in self.config["incomplete_table"]:
             url = make_url(
                 ReportingRatesReport,
                 self.config["domain"],
                 "?location_id=%s&startdate=%s&enddate=%s",
                 (location_id, self.config["startdate"], self.config["enddate"]),
             )
             rows.append(
                 [link_format(name, url) if not self.config["is_rendered_as_email"] else name, ews_date_format(date)]
             )
     return rows
 def rows(self):
     rows = []
     if self.location_id:
         for name, location_id, date in self.config['incomplete_table']:
             url = make_url(
                 ReportingRatesReport,
                 self.config['domain'],
                 '?location_id=%s&startdate=%s&enddate=%s',
                 (location_id, self.config['startdate'], self.config['enddate'])
             )
             rows.append(
                 [
                     link_format(name, url) if not self.config['is_rendered_as_email'] else name,
                     ews_date_format(date)
                 ]
             )
     return rows
    def rows(self):
        rows = []
        if self.location_id:
            for name, location_id, date, supply_point_id in self.config['non_reporting_table']:
                url = make_url(
                    ReportingRatesReport,
                    self.config['domain'],
                    '?location_id=%s&startdate=%s&enddate=%s',
                    (location_id, self.config['startdate'], self.config['enddate'])
                )

                st = StockTransaction.objects.filter(
                    case_id=supply_point_id,
                    report__date__lte=self.config['startdate']
                ).select_related('report').order_by('-report__date')
                if st:
                    date = ews_date_format(st[0].report.date)
                else:
                    date = '---'
                rows.append([link_format(name, url) if not self.config['is_rendered_as_email'] else name, date])
        return rows
Exemple #14
0
 def rows(self):
     rows = []
     if self.location_id and self.locations:
         for location_name, values in self.config["summary_reporting_rates"].iteritems():
             url = make_url(
                 ReportingRatesReport,
                 self.config["domain"],
                 "?location_id=%s&startdate=%s&enddate=%s",
                 (values["location_id"], self.config["startdate"], self.config["enddate"]),
             )
             is_rendered_as_email = self.config["is_rendered_as_email"]
             rows.append(
                 [
                     link_format(location_name, url) if not is_rendered_as_email else location_name,
                     values["all"],
                     values["complete"] + values["incomplete"],
                     "%d%%" % (100 * (values["complete"] + values["incomplete"]) / (values["all"] or 1)),
                     "%d%%" % (100 * values["complete"] / ((values["complete"] + values["incomplete"]) or 1)),
                 ]
             )
     return rows
Exemple #15
0
 def rows(self):
     rows = []
     if self.location_id:
         for location_name, values in self.config[
                 'summary_reporting_rates'].iteritems():
             url = make_url(
                 ReportingRatesReport, self.config['domain'],
                 '?location_id=%s&startdate=%s&enddate=%s',
                 (values['location_id'], self.config['startdate'],
                  self.config['enddate']))
             is_rendered_as_email = self.config['is_rendered_as_email']
             rows.append([
                 link_format(location_name, url)
                 if not is_rendered_as_email else location_name,
                 values['all'], values['complete'] + values['incomplete'],
                 '%d%%' % (100 *
                           (values['complete'] + values['incomplete']) /
                           (values['all'] or 1)),
                 '%d%%' % (100 * values['complete'] / (values['all'] or 1))
             ])
     return rows
    def rows(self):
        rows = []
        if self.location_id:
            for name, location_id, date, supply_point_id in self.config['non_reporting_table']:
                url = make_url(
                    StockLevelsReport,
                    self.config['domain'],
                    '?location_id=%s&startdate=%s&enddate=%s',
                    (location_id, self.config['startdate'], self.config['enddate'])
                )

                st = StockTransaction.objects.filter(
                    case_id=supply_point_id,
                    report__date__lte=self.config['startdate']
                ).select_related('report__date').order_by('-report__date')
                if st:
                    date = ews_date_format(st[0].report.date)
                else:
                    date = '---'
                rows.append([link_format(name, url), date])
        return rows
    def rows(self):
        rows = []
        if self.location_id:
            for location_name, values in self.config['summary_reporting_rates'].iteritems():
                url = make_url(
                    ReportingRatesReport,
                    self.config['domain'],
                    '?location_id=%s&startdate=%s&enddate=%s',
                    (values['location_id'], self.config['startdate'], self.config['enddate'])
                )

                rows.append(
                    [
                        link_format(location_name, url),
                        values['all'],
                        values['complete'] + values['incomplete'],
                        '%d%%' % (100 * (values['complete'] + values['incomplete']) / (values['all'] or 1)),
                        '%d%%' % (100 * values['complete'] / (values['all'] or 1))
                    ]
                )
        return rows
Exemple #18
0
    def rows(self):
        rows = []
        if self.location_id:
            for name, location_id, date, supply_point_id in self.config["non_reporting_table"]:
                url = make_url(
                    ReportingRatesReport,
                    self.config["domain"],
                    "?location_id=%s&startdate=%s&enddate=%s",
                    (location_id, self.config["startdate"], self.config["enddate"]),
                )

                st = (
                    StockTransaction.objects.filter(case_id=supply_point_id, report__date__lte=self.config["startdate"])
                    .select_related("report__date")
                    .order_by("-report__date")
                )
                if st:
                    date = ews_date_format(st[0].report.date)
                else:
                    date = "---"
                rows.append([link_format(name, url) if not self.config["is_rendered_as_email"] else name, date])
        return rows
 def rows(self):
     rows = []
     if self.location_id and self.locations:
         for location_name, values in self.config['summary_reporting_rates'].iteritems():
             url = make_url(
                 ReportingRatesReport,
                 self.config['domain'],
                 '?location_id=%s&startdate=%s&enddate=%s',
                 (values['location_id'], self.config['startdate'].strftime('%Y-%m-%d'),
                  self.config['enddate'].strftime('%Y-%m-%d'))
             )
             is_rendered_as_email = self.config['is_rendered_as_email']
             rows.append(
                 [
                     link_format(location_name, url) if not is_rendered_as_email else location_name,
                     values['all'],
                     values['complete'] + values['incomplete'],
                     '%d%%' % (100 * (values['complete'] + values['incomplete']) / (values['all'] or 1)),
                     '%d%%' % (100 * values['complete'] / ((values['complete'] + values['incomplete']) or 1))
                 ]
             )
     return rows
Exemple #20
0
    def rows(self):
        rows = []
        if self.config['location_id']:
            last_period_st, last_period_end = calculate_last_period(self.config['enddate'])
            for loc in self.get_locations:
                supply_points = get_supply_points(loc.location_id, loc.domain).values_list('supply_point_id',
                                                                                           flat=True)
                sites = len(supply_points)

                reported = StockTransaction.objects.filter(case_id__in=supply_points,
                                                           report__date__range=[last_period_st,
                                                                                last_period_end]
                                                           ).distinct('case_id').count()
                reporting_rates = '%.2f%%' % (reported * 100 / (float(sites) or 1.0))

                url = make_url(
                    ReportingRatesReport,
                    self.config['domain'],
                    '?location_id=%s&startdate=%s&enddate=%s',
                    (loc.location_id, self.config['startdate'], self.config['enddate']))

                rows.append([link_format(loc.name, url), sites, reported, reporting_rates])
        return rows
    def rows(self):
        rows = []
        if self.location_id:
            supply_points = self.get_supply_points()
            not_reported = supply_points.exclude(supply_point_id__in=self.reporting_supply_points())

            for location in not_reported:
                url = make_url(
                    StockLevelsReport,
                    self.config['domain'],
                    '?location_id=%s&startdate=%s&enddate=%s',
                    (location.location_id, self.config['startdate'], self.config['enddate'])
                )

                st = StockTransaction.objects.filter(
                    case_id=location.supply_point_id,
                    report__date__lte=self.config['startdate']
                ).order_by('-report__date')
                if st:
                    date = ews_date_format(st[0].report.date)
                else:
                    date = '---'
                rows.append([link_format(location.name, url), date])
        return rows