Beispiel #1
0
$date_to = fCRUD::getSearchValue('date_to');
/**
 * Default action - show report of consumable installation
 */
if ($action == 'list') {
    // Set the users to be sortable by name or email, defaulting to name
    $sort = fCRUD::getSortColumn(array('events.date', 'models.name', 'printers.name', 'consumables.name', 'events.cost'));
    // Set the sorting to default to ascending
    $dir = fCRUD::getSortDirection('desc');
    // Redirect the user if one of the values was loaded from the session
    fCRUD::redirectWithLoadedValues();
    // Determine search parameters
    $sql_where = '';
    if ($printer_id) {
        $printer = new Printer($printer_id);
        $sql_where .= ' AND events.printer_id = ' . $db->escape('integer', $printer_id);
    }
    if ($date_from) {
        $sql_where .= ' AND DATE(events.date) >= ' . $db->escape('date', $date_from);
    }
    if ($date_to) {
        $sql_where .= ' AND DATE(events.date) <= ' . $db->escape('date', $date_to);
    }
    // Get recordset object from tables
    $sql = "SELECT\n\t\t\t\tCAST(CONCAT(manufacturers.name, ' ', models.name) AS CHAR) AS model,\n\t\t\t\tprinters.name AS printer_name,\n\t\t\t\tprinters.ipaddress,\n\t\t\t\tconsumables.name AS consumable_name,\n\t\t\t\tconsumables.col_c, consumables.col_y, consumables.col_m, consumables.col_k,\n\t\t\t\tconsumables.chargeback,\n\t\t\t\tevents.*\n\t\t\tFROM events\n\t\t\tLEFT JOIN consumables ON events.consumable_id = consumables.id\n\t\t\tLEFT JOIN printers ON events.printer_id = printers.id\n\t\t\tLEFT JOIN models ON printers.model_id = models.id\n\t\t\tLEFT JOIN manufacturers ON models.manufacturer_id = manufacturers.id\n\t\t\tWHERE 1 = 1\n\t\t\t{$sql_where}\n\t\t\tORDER BY {$sort} {$dir}";
    $events = $db->query($sql)->asObjects();
    // Get list of printers for dropdown box
    $printers = Printer::getSimple($db);
    // Include page to show table
    include 'views/reports/index.php';
}