mirror of
https://github.com/fspc/Yellow-Bike-Database.git
synced 2025-02-22 08:53:23 -05:00
Adds reports{js,php} for modern reporting with tabulator!
* and integration
This commit is contained in:
parent
58a3e00f70
commit
68431826f3
200
js/reports.js
Normal file
200
js/reports.js
Normal file
@ -0,0 +1,200 @@
|
||||
$(function(){
|
||||
|
||||
"use strict";
|
||||
|
||||
$.ajaxSetup({async:false});
|
||||
|
||||
var contact_id = $("#contact_id").text();
|
||||
|
||||
if (contact_id) {
|
||||
|
||||
$("table").attr("width","")
|
||||
|
||||
// name
|
||||
$.post("json/reports.php", { name: 1, contact_id: contact_id }, function (data) {
|
||||
if (data) {
|
||||
var obj = $.parseJSON(data);
|
||||
$("#name").text(obj.full_name)
|
||||
}
|
||||
|
||||
}); // name
|
||||
|
||||
// tabulator
|
||||
$.post("json/reports.php", { individual_history: 1, contact_id: contact_id }, function (data) {
|
||||
if (data) {
|
||||
var obj = $.parseJSON(data);
|
||||
|
||||
// use height:315 for 10 rows if non-pagination
|
||||
$("#individual_history").tabulator({
|
||||
pagination:"local",
|
||||
paginationSize:10,
|
||||
responsiveLayout:true,
|
||||
layout:"fitColumns",
|
||||
columns:[
|
||||
{title:"Status", field:"shop_user_role", align:"center", width:125, editor:statusEditor, headerFilter:true},
|
||||
{title:"Date", field:"date", align:"center",width:100, headerFilter:"input"},
|
||||
{title:"Day", field:"dayname", align:"center", width:100, editor:dayEditor, headerFilter:true},
|
||||
{title:"Shop", field:"shop_id", sorter:"number", headerFilter:"number", align:"center", width:85,
|
||||
formatter:function(cell, formatterParams){
|
||||
var shop_id = cell.getValue();
|
||||
return '<a href="./shop_log.php?shop_id=' + shop_id + '">' + shop_id + "</a>";
|
||||
}
|
||||
},
|
||||
{title:"Time In", field:"time_in", align:"center", width:100,
|
||||
formatter:function(cell, formatterParams){
|
||||
var time_in = cell.getValue();
|
||||
time_in = time_in.split(" ");
|
||||
return time_in[1];
|
||||
}
|
||||
},
|
||||
{title:"Time Out", field:"time_out", align:"center", width:100,
|
||||
formatter:function(cell, formatterParams){
|
||||
var time_out = cell.getValue();
|
||||
time_out = time_out.split(" ");
|
||||
return time_out[1];
|
||||
}
|
||||
},
|
||||
{title:"Total", field:"et", align:"center", width:100,
|
||||
formatter:function(cell, formatterParams){
|
||||
var hr_total = cell.getValue();
|
||||
if (hr_total) {
|
||||
return hr_total + " hrs";
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
{title:"Project", field:"project_id", align:"center", width:125, editor:projectEditor, headerFilter:true},
|
||||
{title:"Comments", field:"comment", formatter:"textarea", headerFilter:"input"}
|
||||
]
|
||||
});
|
||||
$("#individual_history").tabulator("setData", obj);
|
||||
}
|
||||
|
||||
}); // tabulator
|
||||
|
||||
} // if contact_id
|
||||
|
||||
|
||||
//cell - the cell component for the editable cell
|
||||
//onRendered - function to call when the editor has been rendered
|
||||
//success - function to call to pass the succesfully updated value to Tabulator
|
||||
//cancel - function to call to abort the edit and return to a normal cell
|
||||
//editorParams - editorParams object set in column defintion
|
||||
//var dayEditor =
|
||||
function dayEditor(cell, onRendered, success, cancel, editorParams){
|
||||
|
||||
//create and style editor
|
||||
var editor = $("<select><option value=''></option>" +
|
||||
"<option value='Monday'>Monday</option>" +
|
||||
"<option value='Tuesday'>Tuesday</option>" +
|
||||
"<option value='Wednesday'>Wednesday</option>" +
|
||||
"<option value='Thursday'>Thursday</option>" +
|
||||
"<option value='Friday'>Friday</option>" +
|
||||
"<option value='Saturday'>Saturday</option>" +
|
||||
"<option value='Sunday'>Sunday</option>" +
|
||||
"</select>"
|
||||
);
|
||||
editor.css({
|
||||
"padding":"3px",
|
||||
"width":"100%",
|
||||
"box-sizing":"border-box",
|
||||
});
|
||||
|
||||
//Set value of editor to the current value of the cell
|
||||
editor.val(cell.getValue());
|
||||
|
||||
//set focus on the select box when the editor is selected (timeout allows for editor to be added to DOM)
|
||||
onRendered(function(){
|
||||
editor.focus();
|
||||
});
|
||||
|
||||
//when the value has been set, trigger the cell to update
|
||||
editor.on("change blur", function(e){
|
||||
success(editor.val());
|
||||
});
|
||||
|
||||
//return the editor element
|
||||
return editor;
|
||||
} // date editor
|
||||
|
||||
function projectEditor(cell, onRendered, success, cancel, editorParams){
|
||||
|
||||
var projects;
|
||||
|
||||
$.post("json/reports.php", { projects: 1 }, function (data) {
|
||||
var obj = $.parseJSON(data);
|
||||
|
||||
projects = "<select>";
|
||||
$.each(obj, function(k,v) {
|
||||
projects += "<option value='" + v.project_id + "'>" + v.project_id + "</option>";
|
||||
});
|
||||
projects += "</select>";
|
||||
|
||||
});
|
||||
|
||||
//create and style editor
|
||||
var editor = $(projects);
|
||||
editor.css({
|
||||
"padding":"3px",
|
||||
"width":"100%",
|
||||
"box-sizing":"border-box",
|
||||
});
|
||||
|
||||
//Set value of editor to the current value of the cell
|
||||
editor.val(cell.getValue());
|
||||
|
||||
//set focus on the select box when the editor is selected (timeout allows for editor to be added to DOM)
|
||||
onRendered(function(){
|
||||
editor.focus();
|
||||
});
|
||||
|
||||
//when the value has been set, trigger the cell to update
|
||||
editor.on("change blur", function(e){
|
||||
success(editor.val());
|
||||
});
|
||||
|
||||
//return the editor element
|
||||
return editor;
|
||||
} // project editor
|
||||
|
||||
function statusEditor(cell, onRendered, success, cancel, editorParams){
|
||||
|
||||
var projects;
|
||||
|
||||
$.post("json/reports.php", { roles: 1 }, function (data) {
|
||||
var obj = $.parseJSON(data);
|
||||
|
||||
projects = "<select>";
|
||||
$.each(obj, function(k,v) {
|
||||
projects += "<option value='" + v.shop_user_role_id + "'>" + v.shop_user_role_id + "</option>";
|
||||
});
|
||||
projects += "</select>";
|
||||
|
||||
});
|
||||
|
||||
//create and style editor
|
||||
var editor = $(projects);
|
||||
editor.css({
|
||||
"padding":"3px",
|
||||
"width":"100%",
|
||||
"box-sizing":"border-box",
|
||||
});
|
||||
|
||||
//Set value of editor to the current value of the cell
|
||||
editor.val(cell.getValue());
|
||||
|
||||
//set focus on the select box when the editor is selected (timeout allows for editor to be added to DOM)
|
||||
onRendered(function(){
|
||||
editor.focus();
|
||||
});
|
||||
|
||||
//when the value has been set, trigger the cell to update
|
||||
editor.on("change blur", function(e){
|
||||
success(editor.val());
|
||||
});
|
||||
|
||||
//return the editor element
|
||||
return editor;
|
||||
} // project editor
|
||||
|
||||
});
|
75
json/reports.php
Normal file
75
json/reports.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
// new logic for reports
|
||||
|
||||
require_once('../Connections/database_functions.php');
|
||||
require_once('../Connections/YBDB.php');
|
||||
mysql_select_db($database_YBDB, $YBDB);
|
||||
// This resolves an issue when mysql_fetch_assoc fails (doesn't work) because of something like é in the results
|
||||
mysql_query("SET NAMES 'utf8'", $YBDB);
|
||||
|
||||
/*
|
||||
require_once('../php-console/src/PhpConsole/__autoload.php');
|
||||
$handler = PhpConsole\Handler::getInstance();
|
||||
$handler->start();
|
||||
*/
|
||||
|
||||
// Return name
|
||||
if (isset($_POST['name'])) {
|
||||
$query = "SELECT CONCAT(contacts.first_name, ' ', contacts.middle_initial, ' ',contacts.last_name) AS full_name
|
||||
FROM contacts
|
||||
WHERE contact_id=" . $_POST['contact_id'] .";";
|
||||
$sql = mysql_query($query, $YBDB) or die(mysql_error());
|
||||
$result = mysql_fetch_assoc($sql);
|
||||
echo json_encode($result);
|
||||
}
|
||||
|
||||
// Return projects
|
||||
if (isset($_POST['projects'])) {
|
||||
$query = "SELECT project_id FROM projects;";
|
||||
$sql = mysql_query($query, $YBDB) or die(mysql_error());
|
||||
while ( $result = mysql_fetch_assoc($sql) ) {
|
||||
$results[] = $result;
|
||||
}
|
||||
echo json_encode($results);
|
||||
}
|
||||
|
||||
// Return roles (statuses)
|
||||
if (isset($_POST['roles'])) {
|
||||
$query = "SELECT shop_user_role_id FROM shop_user_roles;";
|
||||
$sql = mysql_query($query, $YBDB) or die(mysql_error());
|
||||
while ( $result = mysql_fetch_assoc($sql) ) {
|
||||
$results[] = $result;
|
||||
}
|
||||
echo json_encode($results);
|
||||
}
|
||||
|
||||
// Return individual history var obj = $.parseJSON(data);
|
||||
if (isset($_POST['individual_history'])) {
|
||||
|
||||
|
||||
$query = "SELECT shop_id, shop_hours.shop_visit_id, shop_hours.contact_id, shop_hours.shop_user_role, shop_hours.project_id,
|
||||
DATE(shop_hours.time_in) AS date,
|
||||
DAYNAME(shop_hours.time_in) AS dayname,
|
||||
shop_hours.time_in, shop_hours.time_out,
|
||||
TIME_FORMAT(TIMEDIFF(time_out, time_in),'%k:%i') AS et,
|
||||
shop_hours.comment,
|
||||
CONCAT(contacts.last_name, ', ', contacts.first_name, ' ',contacts.middle_initial)
|
||||
AS full_name, contacts.first_name
|
||||
FROM shop_hours
|
||||
LEFT JOIN shop_user_roles ON shop_hours.shop_user_role=shop_user_roles.shop_user_role_id
|
||||
LEFT JOIN contacts ON shop_hours.contact_id=contacts.contact_id
|
||||
WHERE shop_hours.contact_id =" . $_POST['contact_id'] . " ORDER BY shop_id DESC;";
|
||||
|
||||
$sql = mysql_query($query, $YBDB) or die(mysql_error());
|
||||
|
||||
while ( $result = mysql_fetch_assoc($sql) ) {
|
||||
$results[] = $result;
|
||||
}
|
||||
echo json_encode($results);
|
||||
|
||||
|
||||
} // individual_history
|
||||
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user