Exemple #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());
}
Exemple #2
0
QString InspectorDetailsView::renderHTML()
{
    QString inspector_id = settings->selectedInspector();

    HTMLDiv div;

    if (settings->mainWindowSettings().serviceCompanyInformationVisible()) {
        div << writeServiceCompany();
        div.newLine();
    }

    div << writeInspectorsTable(QString(), inspector_id);
    div.newLine();

    HTMLTable *table;
    HTMLTableRow *_tr;
    HTMLTableCell *_td;
    HTMLParentElement *elem;

    bool is_nominal, is_repair, is_outside_interval;
    bool show_acquisition_price = DBInfo::isOperationPermitted("access_assembly_record_acquisition_price") > 0;
    bool show_list_price = DBInfo::isOperationPermitted("access_assembly_record_list_price") > 0;

    double absolute_total = 0.0, total = 0.0, acquisition_total = 0.0;

    AssemblyRecordItemByInspector ar_item_record(inspector_id);
    if (!settings->toolBarStack()->isFilterEmpty()) {
        ar_item_record.addFilter(settings->toolBarStack()->filterColumn(), settings->toolBarStack()->filterKeyword());
    }
    ListOfVariantMaps ar_items(ar_item_record.listAll("inspections.customer, inspections.circuit, inspections.date, assembly_record_items.*"));

    table = div.table("cellspacing=\"0\" cellpadding=\"4\" style=\"width:100%;\" class=\"highlight\"");
    *(table->addRow()->addHeaderCell("colspan=\"10\" style=\"font-size: medium;\"")) << tr("Assembly Records");
    _tr = table->addRow();
    *(_tr->addHeaderCell()) << tr("Date");
    *(_tr->addHeaderCell()) << tr("Customer ID");
    *(_tr->addHeaderCell()) << tr("Circuit ID");
    *(_tr->addHeaderCell()) << tr("Assembly record");
    *(_tr->addHeaderCell()) << tr("Value");
    if (show_acquisition_price)
        *(_tr->addHeaderCell()) << tr("Acquisition price");
    if (show_list_price) {
        *(_tr->addHeaderCell()) << tr("List price");
        *(_tr->addHeaderCell()) << tr("Discount");
        *(_tr->addHeaderCell()) << tr("Total");
    }

    for (int i = 0; i < ar_items.count(); ++i) {
        QString id = ar_items.at(i).value("date").toString();
        QString customer_id = ar_items.at(i).value("customer").toString();
        QString circuit_id = ar_items.at(i).value("circuit").toString();
        is_nominal = ar_items.at(i).value("nominal").toInt();
        is_repair = ar_items.at(i).value("repair").toInt();
        is_outside_interval = ar_items.at(i).value("outside_interval").toInt();

        _tr = table->addRow(QString("onclick=\"window.location = 'customer:%1/circuit:%2/%3:%4/assemblyrecord'\" style=\"cursor: pointer;\"")
                            .arg(customer_id)
                            .arg(circuit_id)
                            .arg(is_repair ? "repair" : "inspection")
                            .arg(id));
        _td = _tr->addCell();

        if (is_nominal) elem = _td->bold();
        else if (is_repair) elem = _td->italics();
        else elem = _td;
        *elem << toolTipLink(is_repair ? "customer/circuit/repair" : "customer/circuit/inspection", id, customer_id, circuit_id, id);
        if (is_outside_interval) { *elem << "*"; }

        *(_tr->addCell()) << ar_items.at(i).value("customer").toString();
        *(_tr->addCell()) << ar_items.at(i).value("circuit").toString();
        *(_tr->addCell()) << ar_items.at(i).value("arno").toString();
        *(_tr->addCell()) << ar_items.at(i).value("value").toDouble();
        if (show_acquisition_price) {
            acquisition_total += ar_items.at(i).value("value").toDouble() * ar_items.at(i).value("acquisition_price").toDouble();

            *(_tr->addCell()) << ar_items.at(i).value("acquisition_price").toDouble();
        }
        if (show_list_price) {
            total = ar_items.at(i).value("value").toDouble();
            total *= ar_items.at(i).value("list_price").toDouble();
            double total_discount = ar_items.at(i).value("discount").toDouble();
            total *= 1 - total_discount / 100;
            absolute_total += total;

            *(_tr->addCell()) << ar_items.at(i).value("list_price").toDouble();
            *(_tr->addCell()) << total_discount << " %";
            *(_tr->addCell()) << total;
        }
    }
    if (show_list_price || show_acquisition_price) {
        _tr = table->addRow();
        *(_tr->addHeaderCell("colspan=\"5\"")) << tr("Total");
        _td = _tr->addCell();
        if (show_acquisition_price) *_td << acquisition_total;
        _td = _tr->addCell("colspan=\"3\"");
        if (show_list_price) *_td << absolute_total;
    }
    div.newLine();

    table = div.table("cellspacing=\"0\" cellpadding=\"4\" style=\"width:100%;\" class=\"highlight\"");
    *(table->addRow()->addHeaderCell("colspan=\"5\" style=\"font-size: medium;\"")) << tr("Inspections and Repairs");
    _tr = table->addRow();
    *(_tr->addHeaderCell()) << tr("Date");
    *(_tr->addHeaderCell()) << tr("Customer ID");
    *(_tr->addHeaderCell()) << tr("Customer");
    *(_tr->addHeaderCell()) << tr("Circuit ID");
    *(_tr->addHeaderCell()) << tr("Circuit name");

    InspectionByInspector inspection_record(inspector_id);
    if (!settings->toolBarStack()->isFilterEmpty()) {
        inspection_record.addFilter(settings->toolBarStack()->filterColumn(), settings->toolBarStack()->filterKeyword());
    }
    ListOfVariantMaps inspections(inspection_record.listAll("date, customer, customers.company, circuit, circuits.name AS circuit_name, repair, nominal"));

    for (int i = 0; i < inspections.count(); ++i) {
        QString id = inspections.at(i).value("date").toString();
        QString customer_id = inspections.at(i).value("customer").toString();
        QString circuit_id = inspections.at(i).value("circuit").toString();
        is_nominal = inspections.at(i).value("nominal").toInt();
        is_repair = inspections.at(i).value("repair").toInt();
        is_outside_interval = inspections.at(i).value("outside_interval").toInt();

        QString inspection_link = "onclick=\"window.location = 'customer:" + customer_id + "/circuit:" + circuit_id;
        inspection_link.append((is_repair ? "/repair:" : "/inspection:") + id + "'\" style=\"cursor: pointer;\"");

        _tr = table->addRow(inspection_link);
        _td = _tr->addCell();

        if (is_nominal) elem = _td->bold();
        else if (is_repair) elem = _td->italics();
        else elem = _td;
        *elem << toolTipLink(is_repair ? "customer/circuit/repair" : "customer/circuit/inspection", id, customer_id, circuit_id, id);
        if (is_outside_interval) { *elem << "*"; }

        *(_tr->addCell()) << inspections.at(i).value("customer").toString();
        *(_tr->addCell()) << inspections.at(i).value("company").toString();
        *(_tr->addCell()) << inspections.at(i).value("circuit").toString();
        *(_tr->addCell()) << inspections.at(i).value("circuit_name").toString();
    }

    return viewTemplate("inspector").arg(div.html());
}
Exemple #3
0
QString AssemblyRecordItemsView::renderHTML()
{
    QString highlighted_category_id = settings->selectedAssemblyRecordItemCategory();
    QString highlighted_type_id = settings->selectedAssemblyRecordItemType();

    QString order_by = settings->mainWindowSettings().orderByForView(LinkParser::AllAssemblyRecordItems);
    order_by = AssemblyRecordItemCategory::attributes().contains(order_by) ? order_by : "name";

    AssemblyRecordItemCategory all_item_categories("");
    ListOfVariantMaps item_categories = all_item_categories.listAll("*", order_by);

    HTMLDiv div;

    if (settings->mainWindowSettings().serviceCompanyInformationVisible()) {
        div << writeServiceCompany();
        div.newLine();
    }

    HTMLTable *table = div.table("cellspacing=\"0\" cellpadding=\"4\" style=\"width:100%;\" class=\"highlight\"");
    int thead_colspan = 5;
    HTMLTableRow *row = new HTMLTableRow();
    for (int n = 0; n < AssemblyRecordItemCategory::attributes().count(); ++n) {
        *(row->addHeaderCell("rowspan=\"2\"")->link("allassemblyrecorditems:/order_by:"
                                  + AssemblyRecordItemCategory::attributes().key(n)))
                << AssemblyRecordItemCategory::attributes().value(n);
        thead_colspan++;
    }
    *(row->addHeaderCell("colspan=\"5\"")) << tr("Show");
    *(table->addRow()->addHeaderCell("colspan=\"" + QString::number(thead_colspan) + "\" style=\"font-size: medium;\""))
        << tr("Assembly Record Item Categories and Types");
    *table << row;
    row = table->addRow();
    *(row->addHeaderCell()) << tr("Value");
    *(row->addHeaderCell()) << tr("Acquisition price");
    *(row->addHeaderCell()) << tr("List price");
    *(row->addHeaderCell()) << tr("Discount");
    *(row->addHeaderCell()) << tr("Total");

    QMap<int, HTMLTableCell *> category_cells;

    for (int i = 0; i < item_categories.count(); ++i) {
        QString category_id = item_categories.at(i).value("id").toString();
        row = table->addRow(QString("id=\"%1\" onclick=\"executeLink(this, '%1');\"%2 style=\"cursor: pointer;\"")
                            .arg("assemblyrecorditemcategory:" + category_id)
                            .arg(highlighted_category_id == category_id ? " class=\"selected\"" : ""));

        *(row->addCell()->link(""))
                << category_id;

        for (int n = 1; n < AssemblyRecordItemCategory::attributes().count(); ++n) {
            *(row->addCell("style=\"font-size: small;\"")->bold())
                    << escapeString(item_categories.at(i).value(AssemblyRecordItemCategory::attributes().key(n)).toString());
        }

        addDisplayOptionsCellToCategoriesTable(row, item_categories.at(i).value("display_options").toInt(), AssemblyRecordItemCategory::ShowValue);
        addDisplayOptionsCellToCategoriesTable(row, item_categories.at(i).value("display_options").toInt(), AssemblyRecordItemCategory::ShowAcquisitionPrice);
        addDisplayOptionsCellToCategoriesTable(row, item_categories.at(i).value("display_options").toInt(), AssemblyRecordItemCategory::ShowListPrice);
        addDisplayOptionsCellToCategoriesTable(row, item_categories.at(i).value("display_options").toInt(), AssemblyRecordItemCategory::ShowDiscount);
        addDisplayOptionsCellToCategoriesTable(row, item_categories.at(i).value("display_options").toInt(), AssemblyRecordItemCategory::ShowTotal);

        category_cells.insert(item_categories.at(i).value("id").toInt(),
                              table->addRow("class=\"no_highlight\"")->addCell(QString("colspan=\"%1\" style=\"padding: 15px;\"")
                                                                               .arg(row->childCount())));
    }

    AssemblyRecordItemType all_item_types("");
    if (!settings->toolBarStack()->isFilterEmpty()) {
        all_item_types.addFilter(settings->toolBarStack()->filterColumn(), settings->toolBarStack()->filterKeyword());
    }

    order_by = settings->mainWindowSettings().orderByForView(LinkParser::AllAssemblyRecordItems);
    order_by = order_by.isEmpty() ? "category_id, name" : QString("category_id, %1").arg(order_by);

    ListOfVariantMaps item_types = all_item_types.listAll("*", order_by);

    for (int i = 0; i < item_types.count();) {
        int category_id = item_types.at(i).value("category_id").toInt();

        if (!category_cells.contains(category_id)) {
            i++;
            continue;
        }

        QString html; MTTextStream out(&html);

        out << "<table cellspacing=\"0\" cellpadding=\"4\" class=\"highlight\">";
        out << "<tr>";
        for (int n = 0; n < AssemblyRecordItemType::attributes().count(); ++n) {
            if (AssemblyRecordItemType::attributes().key(n) == "category_id")
                continue;

            out << "<th><a href=\"allassemblyrecorditems:/order_by:"
                << AssemblyRecordItemType::attributes().key(n) << "\">"
                << AssemblyRecordItemType::attributes().value(n) << "</a></th>";
        }
        out << "</tr>";

        for (; i < item_types.count() && item_types.at(i).value("category_id").toInt() == category_id; ++i) {
            QString type_id = item_types.at(i).value("id").toString();
            out << QString("<tr id=\"%1\" onclick=\"executeLink(this, '%1');\"").arg("assemblyrecorditemtype:" + type_id);
            if (highlighted_type_id == type_id)
                out << " class=\"selected\"";
            out << " style=\"cursor: pointer;\"><td><a href=\"\">" << type_id << "</a></td>";

            for (int n = 1; n < AssemblyRecordItemType::attributes().count(); ++n) {
                QString key = AssemblyRecordItemType::attributes().key(n);
                if (key != "category_id") {
                    if (key.endsWith("_price")) {
                        out << "<td>" << item_types.at(i).value(key).toDouble() << "</td>";
                    } else {
                        out << "<td>" << escapeString(item_types.at(i).value(key).toString()) << "</td>";
                    }
                }
            }
            out << "</tr>";
        }
        out << "</table>";

        *(category_cells.value(category_id)) << html;
    }

    return viewTemplate("assembly_record_items").arg(div.html());
}
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());
}