예제 #1
0
QString InspectionDetailsView::renderHTML()
{
    QString customer_id = settings->selectedCustomer();
    QString circuit_id = settings->selectedCircuit();
    QString inspection_date = settings->selectedInspection();

    QString html; MTTextStream out(&html);

    if (settings->mainWindowSettings().serviceCompanyInformationVisible()) {
        HTMLTable *service_company = writeServiceCompany();
        out << service_company->html();
        delete service_company;
        out << "<br>";
    }

    writeCustomersTable(out, customer_id);
    out << "<br>";
    writeCircuitsTable(out, customer_id, circuit_id, 8);

    QVariantMap circuit = Circuit(customer_id, circuit_id).list("*, " + circuitRefrigerantAmountQuery());

    Inspection inspection_record(customer_id, circuit_id, inspection_date);
    QVariantMap inspection = inspection_record.list();
    bool nominal = inspection.value("nominal").toInt();
    bool repair = inspection.value("repair").toInt();
    Inspection nom_inspection_record(customer_id, circuit_id, "");
    nom_inspection_record.parents().insert("nominal", "1");
    nom_inspection_record.addFilter("date <= ?", inspection_date);
    QVariantMap nominal_ins = nom_inspection_record.list("*", "date DESC");

    HTMLTable *table = new HTMLTable("cellspacing=\"0\" cellpadding=\"4\" style=\"width:100%;\" class=\"no_border\""),
        *_table;
    HTMLTableRow *header_row = table->addRow();
    HTMLTableRow *table_row = table->addRow();
    HTMLTableCell *cell;
    HTMLParentElement *el;
    HTMLDiv div;

    div << html;
    div.newLine();

    el = div.table("cellspacing=\"0\" cellpadding=\"4\" style=\"width:100%;\" class=\"no_border\"")
            ->addRow()->addHeaderCell("colspan=\"2\" style=\"font-size: medium; background-color: lightgoldenrodyellow;\"")
            ->link("customer:" + customer_id + "/circuit:" + circuit_id + (repair ? "/repair:" : "/inspection:") + inspection_date + "/edit");
    if (nominal) *el << tr("Nominal Inspection:");
    else if (repair) *el << tr("Repair:");
    else *el << tr("Inspection:");
    *el << "&nbsp;" << settings->mainWindowSettings().formatDateTime(inspection_date);
    div.newLine();

    VariableEvaluation::EvaluationContext var_evaluation(customer_id, circuit_id);
    VariableEvaluation::Variable *variable = NULL;

    var_evaluation.setNominalInspection(nominal_ins);

    Table tables_record("", QString(), MTDictionary("scope", "1"));
    MTSqlQuery tables = tables_record.select("id, variables", Qt::DescendingOrder);
    tables.setForwardOnly(true);
    tables.exec();

    QSet<QString> all_variables;

    Variables vars;
    while (vars.next()) {
        if (vars.parentID().isEmpty())
            all_variables << vars.id();
    }

    while (tables.next() || all_variables.count()) {
        QStringList table_vars;
        cell = header_row->addHeaderCell("width=\"50%\"");
        if (tables.isValid()) {
            table_vars = tables.stringValue("variables").split(";");
            all_variables.subtract(table_vars.toSet());
            *cell << tables.stringValue("id");
        }
        else {
            table_vars = all_variables.toList();
            all_variables.clear();
            *cell << tr("Other");
        }

        _table = table_row->addCell("style=\"vertical-align: top;\"")->table();

        for (int n = 0; n < table_vars.count(); ++n) {
            variable = var_evaluation.variable(table_vars.at(n));
            if (!variable) continue;
            showVariableInInspectionTable(variable, var_evaluation, inspection, _table);
        }
    }
    div << table->customHtml(2);

    InspectionsCompressor inspections_compressor_rec(QString(), MTDictionary(QStringList() << "customer_id" << "circuit_id" << "date",
                                                                             QStringList() << customer_id << circuit_id << inspection_date));
    ListOfVariantMaps inspections_compressors = inspections_compressor_rec.listAll();
    if (inspections_compressors.count()) {
        VariableEvaluation::EvaluationContext compressor_var_evaluation = VariableEvaluation::EvaluationContext(customer_id, circuit_id, Variable::Compressor);
        QList<VariableEvaluation::Variable *> compressor_vars = compressor_var_evaluation.listVariables();

        table = new HTMLTable("cellspacing=\"0\" cellpadding=\"4\" style=\"width:100%;\" class=\"no_border\"");
        header_row = table->addRow();
        table_row = table->addRow();

        for (int i = 0; i < inspections_compressors.count(); ++i) {
            QVariantMap compressor = Compressor(inspections_compressors.at(i).value("compressor_id").toString()).list();

            *(header_row->addHeaderCell("width=\"50%\"")) << compressor.value("name").toString();
            _table = table_row->addCell("style=\"vertical-align: top;\"")->table();
            for (int n = 0; n < compressor_vars.count(); ++n) {
                if (compressor_vars[n]->parentID().isEmpty())
                    showVariableInInspectionTable(compressor_vars[n], compressor_var_evaluation, inspections_compressors[i], _table);
            }
        }
        div.newLine();
        *(div.table("cellspacing=\"0\" cellpadding=\"4\" style=\"width:100%;\" class=\"no_border\"")->addRow()->addHeaderCell("style=\"font-size: medium;\""))
                << tr("Compressors");
        div.newLine();
        div << table->customHtml(2);
    }

//*** Warnings ***
    Warnings warnings(QSqlDatabase::database(), true, circuit);
    QStringList warnings_list = listWarnings(warnings, circuit, nominal_ins, inspection);
    if (warnings_list.count()) {
        div.newLine();
        _table = div.table("cellspacing=\"0\" cellpadding=\"4\" style=\"width:100%;\"");
        *(_table->addRow()->addHeaderCell("style=\"font-size: medium;\"")) << tr("Warnings");
        *(_table->addRow()->addCell()) << warnings_list.join(", ");
    }
    return viewTemplate("inspection").arg(div.html());
}
예제 #2
0
QString AgendaView::renderHTML()
{
    bool CO2_equivalent = settings->toolBarStack()->isCO2EquivalentChecked();

    QString html; MTTextStream out(&html);

    if (settings->mainWindowSettings().serviceCompanyInformationVisible()) {
        HTMLTable *service_company = writeServiceCompany();
        out << service_company->html();
        delete service_company;
        out << "<br>";
    }

    QMultiMap<QString, QList<QVariant> > next_inspections_map;

    MultiMapOfVariantMaps customers(Customer("").mapAll("id", "company"));

    MTRecord circuits_record("circuits", "id", "", MTDictionary("disused", "0"));
    if (!settings->toolBarStack()->isFilterEmpty()) {
        circuits_record.addFilter(settings->toolBarStack()->filterColumn(), settings->toolBarStack()->filterKeyword());
    }
    circuits_record.addJoin("LEFT JOIN (SELECT customer, circuit, MAX(date) AS date FROM inspections"
                            " WHERE outside_interval = 0 GROUP BY customer, circuit) AS ins"
                            " ON ins.customer = circuits.parent AND ins.circuit = circuits.id");
    circuits_record.addJoin("LEFT JOIN (SELECT i.customer, i.circuit, i.date, i.nominal, i.refr_add_am FROM inspections AS i"
                            " LEFT JOIN inspections AS j ON i.customer = j.customer AND i.circuit = j.circuit"
                            " AND i.date < j.date WHERE j.date IS NULL) AS all_ins"
                            " ON all_ins.customer = circuits.parent AND all_ins.circuit = circuits.id");
    MTSqlQuery circuits = circuits_record.select("circuits.parent, circuits.id, circuits.name, circuits.operation, circuits.refrigerant, "
                                                 + circuitRefrigerantAmountQuery()
                                                 + ", circuits.hermetic, circuits.leak_detector, circuits.inspection_interval,"
                                                 " COALESCE(ins.date, circuits.commissioning) AS last_regular_inspection,"
                                                 " COALESCE(all_ins.date, circuits.commissioning) AS last_inspection,"
                                                 " all_ins.nominal, all_ins.refr_add_am");
    circuits.setForwardOnly(true);
    circuits.exec();
    while (circuits.next()) {
        QString refrigerant = circuits.stringValue("refrigerant");
        double refrigerant_amount = circuits.doubleValue("refrigerant_amount");
        int inspection_interval = Warnings::circuitInspectionInterval(refrigerant, refrigerant_amount, CO2_equivalent,
                                                                      circuits.intValue("hermetic"),
                                                                      circuits.intValue("leak_detector"),
                                                                      circuits.intValue("inspection_interval"));
        if (inspection_interval) {
            QString last_regular_inspection_date = circuits.stringValue("last_regular_inspection");
            if (last_regular_inspection_date.isEmpty())
                continue;
            QString next_regular_inspection_date = QDate::fromString(last_regular_inspection_date.split("-").first(), DATE_FORMAT)
                    .addDays(inspection_interval).toString(DATE_FORMAT);
            QString last_inspection_date = circuits.stringValue("last_inspection");
            if (!last_inspection_date.isEmpty()) {
                QString next_inspection_date = QDate::fromString(last_inspection_date.split("-").first(), DATE_FORMAT)
                        .addDays(30).toString(DATE_FORMAT);
                if (next_inspection_date < next_regular_inspection_date &&
                        circuits.intValue("nominal") == 0 && circuits.doubleValue("refr_add_am") > 0.0)
                    next_inspections_map.insert(next_inspection_date,
                                                QList<QVariant>()
                                                    << circuits.stringValue("parent")
                                                    << circuits.stringValue("id")
                                                    << circuits.stringValue("name")
                                                    << circuits.stringValue("operation")
                                                    << refrigerant
                                                    << refrigerant_amount
                                                    << last_inspection_date
                                                    << true);
            }
            next_inspections_map.insert(next_regular_inspection_date,
                                        QList<QVariant>()
                                            << circuits.stringValue("parent")
                                            << circuits.stringValue("id")
                                            << circuits.stringValue("name")
                                            << circuits.stringValue("operation")
                                            << refrigerant
                                            << refrigerant_amount
                                            << last_regular_inspection_date
                                            << false);
        }
    }

    out << "<table cellspacing=\"0\" cellpadding=\"4\" style=\"width:100%;\"><tr>";
    out << "<th colspan=\"7\" style=\"font-size: medium;\">" << tr("Agenda") << "</th></tr>";
    out << "<tr><th>" << tr("Next inspection") << "</th><th>" << tr("Customer") << "</th>";
    out << "<th>" << tr("Circuit") << "</th><th>" << QApplication::translate("Circuit", "Place of operation") << "</th>";
    out << "<th>" << QApplication::translate("Circuit", "Refrigerant") << "</th>";
    out << "<th>" << replaceUnsupportedCharacters(QApplication::translate("MainWindow", "CO\342\202\202 equivalent")) << "</th>";
    out << "<th>" << tr("Last inspection") << "</th></tr>";

    QMapIterator<QString, QList<QVariant> > i(next_inspections_map);
    while (i.hasNext()) { i.next();
        QString customer = i.value().value(0).toString();
        QString circuit = i.value().value(1).toString();
        QString circuit_name = i.value().value(2).toString();
        QString operation = i.value().value(3).toString();
        QString refrigerant = i.value().value(4).toString();
        double refrigerant_amount = i.value().value(5).toDouble();
        QString last_inspection_date = i.value().value(6).toString();
        bool reinspection = i.value().value(7).toBool();
        int days_to = QDate::currentDate().daysTo(QDate::fromString(i.key(), DATE_FORMAT));
        QString next_inspection;
        switch (days_to) {
            case -1: next_inspection = tr("Yesterday"); break;
            case 0: next_inspection = tr("Today"); break;
            case 1: next_inspection = tr("Tomorrow"); break;
            default: next_inspection = settings->mainWindowSettings().formatDate(i.key()); break;
        }
        QString colour;
        if (days_to < 0) colour = "tomato";
        else if (days_to < 31) colour = "yellow";
        out << "<tr><td class=\"" << colour << "\">";
        if (reinspection)
            out << "<i>";
        out << next_inspection;
        if (reinspection)
            out << "*</i>";
        out << "</td><td class=\"" << colour << "\"><a href=\"customer:" << customer << "\">";
        out << formatCompanyID(customer) << " (" << escapeString(customers.value(customer).value("company").toString()) << ")</a></td>";
        out << "<td class=\"" << colour << "\"><a href=\"customer:" << customer << "/circuit:" << circuit << "\">";
        out << circuit.rightJustified(5, '0');
        if (!circuit_name.isEmpty()) { out << " (" << escapeString(circuit_name) << ")"; }
        out << "</a></td>";
        out << "<td class=\"" << colour << "\">" << escapeString(operation) << "</td>";
        out << "<td class=\"" << colour << "\">" << refrigerant_amount << "&nbsp;" << QApplication::translate("Units", "kg")
            << " " << escapeString(refrigerant) << "</td>";
        out << "<td class=\"" << colour << "\">" << CO2Equivalent(refrigerant, refrigerant_amount)
            << "&nbsp;" << QApplication::translate("Units", "t") << "</td>";
        out << "<td class=\"" << colour << "\">";
        if (last_inspection_date.contains("-"))
            out << "<a href=\"customer:" << customer << "/circuit:" << circuit << "/inspection:"
                << last_inspection_date << "\">" << settings->mainWindowSettings().formatDateTime(last_inspection_date) << "</a>";
        else
            out << settings->mainWindowSettings().formatDate(last_inspection_date);
        out << "</td></tr>";
    }
    out << "</table>";

    return viewTemplate("agenda")
            .arg(settings->isPrinterFriendlyVersionChecked() ? "/*" : "")
            .arg(settings->isPrinterFriendlyVersionChecked() ? "*/" : "")
            .arg(html);
}
예제 #3
0
QString OperatorReportView::renderHTML(bool)
{
    QString customer_uuid = settings->selectedCustomerUUID();
    int year = settings->toolBarStack()->filterSinceValue();
    int month_from = settings->toolBarStack()->filterMonthFromValue();
    int month_until = settings->toolBarStack()->filterMonthUntilValue();
    bool show_circuit_name = settings->toolBarStack()->isShowCircuitNameChecked();
    bool CO2_equivalent = settings->toolBarStack()->isCO2EquivalentChecked();
    bool min_5tCO2 = settings->toolBarStack()->isMin5tCO2EquivalentChecked();

    if (year == 0)
        year = QDate::currentDate().year() - 1;
    QString date_from = QString("%1.%2").arg(year).arg(month_from, 2, 10, QChar('0'));
    QString date_until = QString("%1.%2").arg(year).arg(month_until + 1, 2, 10, QChar('0'));

    QString interval_string = QString::number(year);
    if (month_from > 1 || month_until < 12) {
        if (month_from == month_until)
            interval_string.prepend(QString("%1 ").arg(longMonthName(month_from)));
        else
            interval_string.prepend(QString::fromUtf8("%1 \342\200\223 %2 ")
                                    .arg(longMonthName(month_from))
                                    .arg(longMonthName(month_until)));
    }

    QString html; MTTextStream out(&html);

    writeServiceCompany(out);

    Customer customer(customer_uuid);
    customer.readOperatorValues();
    out << "<table cellspacing=\"0\" cellpadding=\"4\" style=\"width:100%;\">";
    out << "<tr><th style=\"font-size: medium; background-color: floralwhite;\">";
    out << tr("Operator Report: %1").arg(interval_string) << "</th></tr></table><br>";
    out << "<table cellspacing=\"0\" cellpadding=\"4\" style=\"width:100%;\">";
    out << "<tr><th colspan=\"3\">" << tr("Owner information") << "</th></tr><tr>";
    out << "<th>" << Customer::attributes().value("id") << "</th>";
    out << "<th>" << Customer::attributes().value("company") << "</th>";
    out << "<th>" << Customer::attributes().value("address") << "</th>";
    out << "</tr><tr>";
    out << "<td>" << toolTipLink("customer", customer.companyID(), customer_uuid) << "</td>";
    out << "<td>" << MTVariant(customer.value("company")) << "</td>";
    out << "<td>" << MTVariant(customer.value("address"), MTVariant::Address) << "</td>";
    out << "</tr><tr><th colspan=\"3\">" << tr("Operator information") << "</th></tr><tr>";
    out << "<th>" << Customer::attributes().value("id") << "</th>";
    out << "<th>" << Customer::attributes().value("company") << "</th>";
    out << "<th>" << Customer::attributes().value("address") << "</th>";
    out << "</tr><tr>";
    out << "<td>" << customer.stringValue("operator_id") << "</td>";
    out << "<td>" << MTVariant(customer.value("operator_company")) << "</td>";
    out << "<td>" << MTVariant(customer.value("operator_address"), MTVariant::Address) << "</td>";
    out << "</tr></table><br>";
    out << "<table cellspacing=\"0\" cellpadding=\"4\" style=\"width:100%;\" class=\"highlight\">";
    out << "<tr><th colspan=\"" << (8 + show_circuit_name + CO2_equivalent) << "\" style=\"font-size: medium; background-color: aliceblue;\">";
    out << tr("Circuit information", "Operator report") << "</th></tr><tr>";
    out << "<th rowspan=\"2\">" << QApplication::translate("Circuit", "ID") << "</th>";
    if (show_circuit_name) {
        out << "<th rowspan=\"2\">" << QApplication::translate("Circuit", "Name") << "</th>";
    }
    out << "<th rowspan=\"2\">" << QApplication::translate("Circuit", "Refrigerant") << "</th>";
    if (CO2_equivalent)
        out << "<th rowspan=\"2\">" << QApplication::translate("MainWindow", "GWP") << "</th>";
    out << "<th rowspan=\"2\">" << QApplication::translate("Circuit", "Field of application") << "</th>";
    QString unit = CO2_equivalent ? QApplication::translate("Units", "t of CO\342\202\202 equivalent") : QApplication::translate("Units", "kg");
    out << "<th colspan=\"4\">" << QString("%1 (%2)").arg(QApplication::translate("Circuit", "Refrigerant amount")).arg(unit) << "</th>";
    out << "<th rowspan=\"2\">" << QApplication::translate("Circuit", "Place of operation") << "</th>";
    out << "</tr><tr>";
    out << "<th>" << ((month_from > 1 || month_until < 12) ?
                          tr("At the beginning of the period") :
                          tr("At the beginning of the year")) << "</th>";
    out << "<th>" << tr("Added") << "</th>";
    out << "<th>" << tr("Recovered") << "</th>";
    out << "<th>" << ((month_from > 1 || month_until < 12) ?
                          tr("At the end of the period") :
                          tr("At the end of the year")) << "</th>";
    out << "</tr>";

    MTQuery inspections = Inspection::query();
    inspections.addFilter("inspection_type <> ?", QString::number(Inspection::NominalInspection));
    if (month_from > 1)
        inspections.addFilter("date >= ?", date_from);
    if (month_until < 12)
        inspections.addFilter("date < ?", date_until);
    if (month_from <= 1 || month_until >= 12)
        inspections.addFilter("date", QString("%1%").arg(year));

    QVariantMap nominal_inspection_parents = {{"inspection_type", Inspection::NominalInspection}};

    QVariantMap sums;
    ListOfVariantMaps nominal_inspections;
    QString nominal_inspection_date, commissioning_date, decommissioning_date;
    double refrigerant_amount, refrigerant_amount_begin, refrigerant_amount_end;

    MTQuery circuits_query = Circuit::query({{"customer_uuid", customer_uuid}});
    if (!settings->toolBarStack()->isFilterEmpty()) {
        circuits_query.addFilter(settings->toolBarStack()->filterColumn(), settings->toolBarStack()->filterKeyword());
    }

    MTSqlQuery circuits = circuits_query.select("uuid, id, name, refrigerant, refrigerant_amount, field, operation, disused, hermetic, commissioning, decommissioning", "id, name");
    circuits.exec();
    while (circuits.next()) {
        QString circuit_uuid = circuits.stringValue("uuid");
        QString circuit_id = circuits.stringValue("id");

        inspections.parents().insert("circuit_uuid", circuit_uuid);
        sums = inspections.sumAll("refr_add_am, refr_reco");

        commissioning_date = circuits.stringValue("commissioning").left(7);
        if (commissioning_date >= date_until)
            continue;
        decommissioning_date = circuits.stringValue("decommissioning").left(7);
        if (circuits.intValue("disused") <= Circuit::Commissioned)
            decommissioning_date = "9999";
        else if (decommissioning_date.isEmpty())
            decommissioning_date = QString::number(QDate::currentDate().year());
        if (decommissioning_date < date_from)
            continue;
        refrigerant_amount = circuits.doubleValue("refrigerant_amount");
        refrigerant_amount_begin = 0.0;
        refrigerant_amount_end = refrigerant_amount;
        if (commissioning_date < date_from)
            refrigerant_amount_begin += refrigerant_amount;

        nominal_inspection_parents.insert("circuit_uuid", circuit_uuid);
        nominal_inspections = Inspection::query(nominal_inspection_parents).listAll("date, refr_add_am, refr_reco", "date ASC");
        foreach (const QVariantMap &nominal_inspection, nominal_inspections) {
            nominal_inspection_date = nominal_inspection.value("date", "9999").toString().left(7);
            if (nominal_inspection_date < date_from)
                refrigerant_amount_begin += nominal_inspection.value("refr_add_am", 0.0).toDouble()
                        - nominal_inspection.value("refr_reco", 0.0).toDouble();
            if (nominal_inspection_date < date_until)
                refrigerant_amount_end += nominal_inspection.value("refr_add_am", 0.0).toDouble()
                        - nominal_inspection.value("refr_reco", 0.0).toDouble();
        }

        if (decommissioning_date >= date_from && decommissioning_date < date_until)
            refrigerant_amount_end = 0.0;

        QString refrigerant = circuits.stringValue("refrigerant");
        double GWP = refrigerantGWP(refrigerant);
        if (min_5tCO2) {
            bool hermetic = circuits.boolValue("hermetic");
            if (CO2_equivalent ? (qMax(refrigerant_amount_begin, refrigerant_amount_end) * GWP < (hermetic ? 10000.0 : 5000.0))
                               : (qMax(refrigerant_amount_begin, refrigerant_amount_end) < (hermetic ? 6.0 : 3.0)))
                continue;
        }

        out << "<tr onclick=\"window.location = 'customer:" << customer_uuid
            << "/circuit:" << circuit_uuid << "'\" style=\"cursor: pointer;\">";
        out << "<td>" << toolTipLink("customer/circuit", circuit_id.rightJustified(5, '0'), customer_uuid, circuit_uuid) << "</td>";
        if (show_circuit_name) {
            out << "<td>" << MTVariant(circuits.stringValue("name")) << "</td>";
        }
        out << "<td>" << refrigerant << "</td>";
        double multiplier = CO2_equivalent ? (GWP / 1000.0) : 1.0;
        if (CO2_equivalent)
            out << "<td>" << GWP << "</td>";
        QString field = circuits.stringValue("field");
        out << "<td>" << fieldsOfApplication().value(field, field) << "</td>";
        out << "<td>" << refrigerant_amount_begin * multiplier << "</td>";
        out << "<td>" << sums.value("refr_add_am").toDouble() * multiplier << "</td>";
        out << "<td>" << sums.value("refr_reco").toDouble() * multiplier << "</td>";
        out << "<td>" << refrigerant_amount_end * multiplier << "</td>";
        out << "<td>" << MTVariant(circuits.value("operation")) << "</td>";
        out << "</tr>";
    }
예제 #4
0
 foreach (const QVariant &value, values) {
     query.addBindValue(value);
 }
예제 #5
0
QString InspectionDetailsView::renderHTML(bool)
{
    QString customer_uuid = settings->selectedCustomerUUID();
    QString circuit_uuid = settings->selectedCircuitUUID();
    QString inspection_uuid = settings->selectedInspectionUUID();

    QString html; MTTextStream out(&html);

    writeServiceCompany(out);

    writeCustomersTable(out, customer_uuid);
    out << "<br>";
    writeCircuitsTable(out, customer_uuid, circuit_uuid, 8);

    QVariantMap circuit = Circuit(circuit_uuid).list("*, " + circuitRefrigerantAmountQuery());

    Inspection inspection(inspection_uuid);
    QString inspection_date = inspection.date();
    Inspection::Type type = inspection.type();
    MTQuery nom_inspection_record = Inspection::query({{"circuit_uuid", circuit_uuid}, {"inspection_type", "1"}});
    nom_inspection_record.addFilter("date <= ?", inspection_date);
    QVariantMap nominal_ins = nom_inspection_record.list("*", "date DESC");

    HTMLTable *table = new HTMLTable("cellspacing=\"0\" cellpadding=\"4\" style=\"width:100%;\" class=\"no_border\""),
        *_table;
    HTMLTableRow *header_row = table->addRow();
    HTMLTableRow *table_row = table->addRow();
    HTMLTableCell *cell;
    HTMLParentElement *el;
    HTMLDiv div;

    div << html;
    div.newLine();

    el = div.table("cellspacing=\"0\" cellpadding=\"4\" style=\"width:100%;\" class=\"no_border\"")
            ->addRow()->addHeaderCell("colspan=\"2\" style=\"font-size: medium; background-color: lightgoldenrodyellow;\"")
            ->link("customer:" + customer_uuid + "/circuit:" + circuit_uuid + (type == Inspection::Repair ? "/repair:" : "/inspection:") + inspection_uuid + "/edit");
    *el << QApplication::translate("MainWindow", "%1:").arg(Inspection::titleForInspectionType(type));
    *el << "&nbsp;" << settings->mainWindowSettings().formatDateTime(inspection_date);
    div.newLine();

    VariableEvaluation::EvaluationContext var_evaluation(customer_uuid, circuit_uuid);
    VariableEvaluation::Variable *variable = NULL;

    var_evaluation.setNominalInspection(nominal_ins);

    MTSqlQuery tables = Table::query({{"scope", Variable::Inspection}}).select("name, variables", "position");
    tables.exec();

    QSet<QString> all_variables;

    Variables vars;
    while (vars.next()) {
        if (vars.parentUUID().isEmpty())
            all_variables << vars.id();
    }

    if (!settings->isShowNotesChecked())
        all_variables.remove("notes");

    while (tables.next() || all_variables.count()) {
        QStringList table_vars;
        cell = header_row->addHeaderCell("width=\"50%\"");
        if (tables.isValid()) {
            table_vars = tables.stringValue("variables").split(";");
            all_variables.subtract(table_vars.toSet());
            *cell << tables.stringValue("name");
        }
        else {
            table_vars = all_variables.toList();
            all_variables.clear();
            *cell << tr("Other");
        }

        _table = table_row->addCell("style=\"vertical-align: top;\"")->table();

        for (int n = 0; n < table_vars.count(); ++n) {
            variable = var_evaluation.variable(table_vars.at(n));
            if (!variable) continue;
            showVariableInInspectionTable(variable, var_evaluation, inspection.savedValues(), _table);
        }
    }
    div << table->customHtml(2);

    MTQuery inspections_compressor_query = InspectionCompressor::query({{"inspection_uuid", inspection_uuid}});
    ListOfVariantMaps inspections_compressors = inspections_compressor_query.listAll();
    if (inspections_compressors.count()) {
        VariableEvaluation::EvaluationContext compressor_var_evaluation(customer_uuid, circuit_uuid, Variable::Compressor);
        QList<VariableEvaluation::Variable *> compressor_vars = compressor_var_evaluation.listVariables();

        table = new HTMLTable("cellspacing=\"0\" cellpadding=\"4\" style=\"width:100%;\" class=\"no_border\"");
        header_row = table->addRow();
        table_row = table->addRow();

        for (int i = 0; i < inspections_compressors.count(); ++i) {
            Compressor compressor(inspections_compressors.at(i).value("compressor_uuid").toString());
            QString name = compressor.name();
            QString sn = compressor.serialNumber();

            *(header_row->addHeaderCell("width=\"50%\"")) << (sn.isEmpty() ? name : QString("%1 (%2)").arg(name).arg(sn));
            _table = table_row->addCell("style=\"vertical-align: top;\"")->table();
            for (int n = 0; n < compressor_vars.count(); ++n) {
                if (compressor_vars[n]->parentUUID().isEmpty())
                    showVariableInInspectionTable(compressor_vars[n], compressor_var_evaluation, inspections_compressors[i], _table);
            }
        }
        div.newLine();
        *(div.table("cellspacing=\"0\" cellpadding=\"4\" style=\"width:100%;\" class=\"no_border\"")->addRow()->addHeaderCell("style=\"font-size: medium;\""))
                << tr("Compressors");
        div.newLine();
        div << table->customHtml(2);
    }

//*** Warnings ***
    Warnings warnings(settings->toolBarStack()->isCO2EquivalentChecked(), true, circuit);
    QStringList warnings_list = listWarnings(warnings, circuit, nominal_ins, inspection.savedValues());
    if (warnings_list.count()) {
        div.newLine();
        _table = div.table("cellspacing=\"0\" cellpadding=\"4\" style=\"width:100%;\"");
        *(_table->addRow()->addHeaderCell("style=\"font-size: medium;\"")) << tr("Warnings");
        *(_table->addRow()->addCell()) << warnings_list.join(", ");
    }
    return viewTemplate("inspection").arg(div.html());
}