Skip to content

Instantly share code, notes, and snippets.

@tmoore88
Created November 9, 2022 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmoore88/0baf1adb1eefa44fb0db3f39e90a6ab1 to your computer and use it in GitHub Desktop.
Save tmoore88/0baf1adb1eefa44fb0db3f39e90a6ab1 to your computer and use it in GitHub Desktop.
PROD_NOTES
<?php
#DISPLAYS PRODUCTION NOTES ACTIVE (prod_notes_a.php)
##################
# INCLUDED FILES #
##################
include_once("assets/auth.php"); //USER PERMISSIONS
include_once("data/config.php"); //PHP GRID CONNECTION STRING
include_once("data/connect.php"); //DATA BASE CONNECTION STRING (MINE)
include("lib/inc/jqgrid_dist.php"); //GRID INCLUDE
######################
# PHP ERROR SETTINGS #
######################
//ini_set('display_errors', 1);
//ini_set('display_startup_errors', 1);
//error_reporting(E_ALL);
#####################
# GET ADMIN STATUS #
####################
if(isset($_SESSION['user'])) { $uname = $_SESSION['user']; }
$sql = mysqli_query($conn, "SELECT * FROM tbl_users WHERE user_name = '$uname'");
$u = mysqli_fetch_array($sql);
$user_id = $u['user_id'];
$bline = $u['grid_lines'];
#####################
# CHECK PERMISSIONS #
#####################
require_once("data/dbcontroller.php");
$db_info = new DBController();
$_perm = "SELECT * FROM tbl_permissions WHERE fk_user_id = '$user_id'";
$p_row = $db_info->runSelectQuery($_perm );
##############################################
# CHECK IF USER HAS PERMISSION FOR THIS PAGE #
##############################################
if (lockedMenu('92', $p_row) == 0) {
header('Location: HTTP403.html');
}
if(isset($_GET['open'])) {
$open=$_GET['open'];
} else {
$open=0;
}
if(isset($_GET['job']))
{
$jid=$_GET['job'];
}
if(isset($_GET['unit']))
{
$uid=$_GET['unit'];
}
############
# SET INFO #
############
$desc = "<table>
<tr style='font-size: 13px; padding: 0px;'>
<td>GREEN:</td><td>ESTIMATE EXISTS AND PROPOSAL SENT DATE WAS RECORDED</td>
</tr><tr style='font-size: 13px; padding: 0px;'>
<td>ORANGE:</td> <td>ESTIMATE EXISTS BUT NO PROPOSAL SENT DATE WAS RECORDED</td>
<tr><tr style='font-size: 13px; padding: 0px;'>
<td>BLUE:</td> <td>NO ESTIMATE BUT PROPOSAL SENT DATE WAS RECORDED</td>
<tr><tr style='font-size: 13px; padding: 0px;'>
<td>RED:</td> <td>NO ESTIMATE OR PROPOSAL SENT DATE RECORDED</td>
<tr>
</table>";
#######################
# SEND DATABASE FILES #
#######################
$db_conf = array(
"type" => PHPGRID_DBTYPE,
"server" => PHPGRID_DBHOST,
"user" => PHPGRID_DBUSER,
"password" => PHPGRID_DBPASS,
"database" => PHPGRID_DBNAME
);
############
# SET PAGE #
############
$current = '';
$title = 'PRODUCTION NOTES - ACTIVE';
###################
# CREATE NEW GRID #
###################
$g = new jqgrid($db_conf);
// to use footerdata without formatter, comment above and use this
//$grid["groupingView"]["groupField"] = array("company_name"); // specify column name to group listing
################
# GRID OPTIONS #
################
$grid["rowNum"] = 500; // by default 20
$grid["caption"] = "Production Meeting Notes"; // caption of grid
$grid["multiselect"] = false; // allow you to multi-select through checkboxes
$grid["reloadedit"] = true; // auto reload after editing
$grid["footerrow"] = true; // Show footer row
//$grid["userDataOnFooter"] = true; // Fill footer row with userdata (with on_data_display event)
// $grid["scroll"] = true; // Fill footer row with userdata (with on_data_display event)
$grid["autowidth"] = false;
$grid["responsive"] = true;
$grid["forceFit"] = true;
// $grid["shrinkToFit"] = false;
$grid["sortname"] = "job_number";
$grid["cmTemplate"]["visible"] = "xs+";
$grid["cmTemplate"]["width"] = "150";
// to use footerdata without formatter, comment above and use this
//$grid["loadComplete"] = 'function(){ var userData = jQuery("#list1").jqGrid("getGridParam","userData"); jQuery("#list1").jqGrid("footerData","set",userData,false); }';
$grid["loadComplete"] = "function(ids) { grid_onload(ids); }"; //
// grouping
$grid["grouping"] = true;
$grid["groupingView"] = array();
$grid["groupingView"]["groupField"] = array("name_abbr"); // specify column name to group listing
$grid["groupingView"]["groupColumnShow"] = array(true); // either show grouped column in list or not (default: true)
$grid["groupingView"]["groupText"] = array("<b>{0} - {1} Item(s)</b>"); // {0} is grouped value, {1} is count in group
$grid["groupingView"]["groupOrder"] = array("ASC"); // show group in asc or desc order
$grid["groupingView"]["groupDataSorted"] = array(true); // show sorted data within group
$grid["groupingView"]["groupSummary"] = array(false); // work with summaryType, summaryTpl, see column: $col["name"] = "total"; (if false, set showSummaryOnHide to false)
$grid["groupingView"]["groupCollapse"] = false; // Turn true to show group collapse (default: false)
$grid["groupingView"]["showSummaryOnHide"] = true; // show summary row even if group collapsed (hide)
// to combine multiple records in same group
$grid["groupingView"]["isInTheSameGroup"] = array(
"function (x, y) { return String(x).toLowerCase() === String(y).toLowerCase(); }"
);
$grid["groupingView"]["formatDisplayField"] = array(
"function (displayValue, value, colModel, index, grp) {
// show label instead of ids for select formatter
if (colModel.formatter == 'select')
displayValue = $.fn.fmatter.select(displayValue,{'colModel':colModel});
return displayValue[0].toUpperCase() + displayValue.substring(1).toLowerCase(); }"
);
$grid["height"] = "100%";
$grid["rowList"] = array(100,200,300);
$grid["rowNum"] = 100;
$g->set_options($grid);
##############################
# SET GRID C.R.U.D. SETTINGS #
##############################
##########################
# GRID ACTIONS AVIALABLE #
##########################
$g->set_actions(array(
"delete"=>false,
"add"=>false,
"view"=>false, // Enable / Disable view operation on grid. Defaults to true.
"rowactions"=>true, // Enable / Disable inline edit/del/save option. Defaults to true.
"search" => "advance", // Search property can have 3 values, simple, advance or false to hide.
"export"=>false, // Enable / Disable export to excel option. Defaults to false.
"showhidecolumns" => true, // Enable / Disable button to hide certain columns from client side. Defaults to true.
"bulkedit"=> false, // Enable / Disable bulk edit operation on grid. Defaults to false.
"clone"=> false, // Enable / Disable clone operation on grid. Defaults to false.
"import"=> false, // Enable / Disable import data option. Defaults to false.
"autofilter"=> true // Enable / Disable autofilter toolbar for search on top. Defaults to true.
)
);
if (edtCheck('92', $p_row) == 0) { $g->set_actions(array( "inline"=>false)); } else { $g->set_actions(array( "inline"=>true)); }
if (edtCheck('92', $p_row) == 0) { $g->set_actions(array( "edit"=>false)); } else { $g->set_actions(array( "edit"=>true)); }
##############
# MAIN QUERY #
##############
if ($open == 1) {
$g->select_command = "SELECT
tbl_unit.unit_id,
tbl_unit.unit_notes,
tbl_unit.prod_unit_inv_paid,
tbl_unit.prod_unit_inv_open,
tbl_unit.ck_prod_cop,
tbl_unit.unit_percent_comp,
tbl_unit.unit_po,
tbl_unit.unit_po_status,
tbl_unit.fk_job_id,
tbl_unit.unit_closed,
tbl_unit.fk_unit_proj_id,
tbl_unit.unit_number,
tbl_unit.unit_description,
tbl_job.job_id,
tbl_job.job_number,
tbl_job.fk_customer,
tbl_job.job_description,
tbl_job.jp_date,
tbl_job.job_type,
tbl_users.name_abbr,
tbl_users.user_id,
tbl_customer.company_name,
tbl_customer.customer_id,
tbl_est_job.total_cost,
tbl_est_job.fk_job_number,
tbl_est_job.total_hours,
tbl_est_unit.unit_total_cost,
tbl_est_unit.unit_total_hours,
tbl_est_unit.est_fk_job_id,
u.thu,
j.thj
FROM tbl_unit
INNER JOIN tbl_job ON tbl_job.job_id = tbl_unit.fk_job_id
LEFT JOIN tbl_est_job ON tbl_est_job.fk_job_number = tbl_job.job_number
LEFT JOIN tbl_est_unit ON tbl_est_unit.est_fk_job_id = tbl_job.job_id
INNER JOIN tbl_customer ON tbl_customer.customer_id = tbl_job.fk_customer
LEFT JOIN tbl_users ON tbl_unit.fk_unit_proj_id = tbl_users.user_id
LEFT JOIN (
SELECT time_id, time_job_id, Time_unit_id, SUM(rt_mon + rt_tue + rt_wed + rt_thu + rt_fri + rt_sat + rt_sun + ot_mon + ot_tue + ot_wed + ot_thu + ot_fri + ot_sat + ot_sun + tv_mon + tv_tue + tv_wed + tv_thu + tv_fri + tv_sat + tv_sun) AS thu
FROM tbl_timecard
GROUP BY time_unit_id
) u ON u.time_job_id = tbl_job.job_id AND u.time_unit_id = tbl_unit.unit_id
LEFT JOIN (
SELECT time_id, time_job_id, Time_unit_id, SUM(rt_mon + rt_tue + rt_wed + rt_thu + rt_fri + rt_sat + rt_sun + ot_mon + ot_tue + ot_wed + ot_thu + ot_fri + ot_sat + ot_sun + tv_mon + tv_tue + tv_wed + tv_thu + tv_fri + tv_sat + tv_sun) AS thj
FROM tbl_timecard
GROUP BY time_job_id
) j ON (j.time_job_id = tbl_job.job_id)
WHERE
tbl_unit.unit_prod_show = 1
AND tbl_unit.unit_status = 'ACTIVE'
AND tbl_unit.unit_closed = 'C'
AND tbl_job.job_status <> 'ARCHIVED'
AND tbl_customer.customer_id <> 2
AND tbl_customer.customer_id <> 421
GROUP BY
tbl_unit.unit_id";
} else {
$g->select_command = "SELECT
tbl_unit.unit_id,
tbl_unit.unit_notes,
tbl_unit.prod_unit_inv_paid,
tbl_unit.prod_unit_inv_open,
tbl_unit.ck_prod_cop,
tbl_unit.unit_percent_comp,
tbl_unit.unit_po,
tbl_unit.unit_po_status,
tbl_unit.fk_job_id,
tbl_unit.unit_closed,
tbl_unit.fk_unit_proj_id,
tbl_unit.unit_number,
tbl_unit.unit_description,
tbl_job.job_id,
tbl_job.job_number,
tbl_job.fk_customer,
tbl_job.job_description,
tbl_job.jp_date,
tbl_job.job_type,
tbl_users.name_abbr,
tbl_users.user_id,
tbl_customer.company_name,
tbl_customer.customer_id,
tbl_est_job.total_cost,
tbl_est_job.fk_job_number,
tbl_est_job.total_hours,
tbl_est_unit.unit_total_cost,
tbl_est_unit.unit_total_hours,
tbl_est_unit.est_fk_job_id,
u.thu,
j.thj
FROM tbl_unit
INNER JOIN tbl_job ON tbl_job.job_id = tbl_unit.fk_job_id
LEFT JOIN tbl_est_job ON tbl_est_job.fk_job_number = tbl_job.job_number
LEFT JOIN tbl_est_unit ON tbl_est_unit.est_fk_job_id = tbl_job.job_id
INNER JOIN tbl_customer ON tbl_customer.customer_id = tbl_job.fk_customer
LEFT JOIN tbl_users ON tbl_unit.fk_unit_proj_id = tbl_users.user_id
LEFT JOIN (
SELECT time_id, time_job_id, Time_unit_id, SUM(rt_mon + rt_tue + rt_wed + rt_thu + rt_fri + rt_sat + rt_sun + ot_mon + ot_tue + ot_wed + ot_thu + ot_fri + ot_sat + ot_sun + tv_mon + tv_tue + tv_wed + tv_thu + tv_fri + tv_sat + tv_sun) AS thu
FROM tbl_timecard
GROUP BY time_unit_id
) u ON u.time_job_id = tbl_job.job_id AND u.time_unit_id = tbl_unit.unit_id
LEFT JOIN (
SELECT time_id, time_job_id, Time_unit_id, SUM(rt_mon + rt_tue + rt_wed + rt_thu + rt_fri + rt_sat + rt_sun + ot_mon + ot_tue + ot_wed + ot_thu + ot_fri + ot_sat + ot_sun + tv_mon + tv_tue + tv_wed + tv_thu + tv_fri + tv_sat + tv_sun) AS thj
FROM tbl_timecard
GROUP BY time_job_id
) j ON (j.time_job_id = tbl_job.job_id)
WHERE
tbl_unit.unit_prod_show = 1
AND tbl_unit.unit_status = 'ACTIVE'
AND tbl_unit.unit_closed = 'O'
AND tbl_job.job_status <> 'ARCHIVED'
AND tbl_customer.customer_id <> 2
AND tbl_customer.customer_id <> 421
GROUP BY
tbl_unit.unit_id";
}
###################################
# REMOVE BUTTONS FROM GRID HEADER #
###################################
$g->navgrid["param"]["del"] = false; // remove delete from top menu
#################
# MAIN DATABAES #
#################
$g->table = "tbl_unit";
####################################
# SETUP COLUMNS TO DISPLAY IN GRID #
####################################
/////////////
// UNIT ID //
/////////////
$col = array();
$col["title"] = "unit_id";
$col["name"] = "unit_id";
$col["width"] = "40";
$col["hidden"] = true;
$col["export"] = false;
$cols[] = $col;
////////////
// JOB ID //
////////////
$col = array();
$col["title"] = "job_id";
$col["name"] = "job_id";
$col["dbname"] = "tbl_job";
$col["width"] = "40";
$col["hidden"] = true;
$col["export"] = false;
$cols[] = $col;
////////////////
// JOB NUMBER //
////////////////
$col = array();
$col["title"] = "Job";
$col["name"] = "job_type";
$col["width"] = "30";
$col["hidden"] = true;
$col["editable"] = false;
$col["export"] = false;
$cols[] = $col;
////////////////
// JOB NUMBER //
////////////////
$col = array();
$col["title"] = "Job";
$col["name"] = "job_number";
$col["width"] = "30";
$col["hidden"] = false;
$col["editable"] = false;
$col["link"] = "unit_list.php?job={job_id}";
$col["export"] = true;
$cols[] = $col;
/////////////////
// UNIT NUMBER //
/////////////////
$col = array();
$col["title"] = "Unit";
$col["name"] = "unit_number";
$col["width"] = "30";
$col["hidden"] = false;
$col["editable"] = false;
$col["export"] = true;
$col["search"] = true;
$cols[] = $col;
//////////////////////
// UNIT DESCRIPTION //
//////////////////////
$col = array();
$col["title"] = "Unit Description";
$col["name"] = "unit_description";
$col["width"] = "100";
$col["hidden"] = false;
$col["editable"] = false;
$col["export"] = true;
$cols[] = $col;
/////////////////////
// PROJECT MANAGER //
/////////////////////
$col = array();
$col["title"] = "PM";
$col["name"] = "name_abbr";
$col["width"] = "25";
$col["hidden"] = false;
$col["editable"] = false;
$col["export"] = true;
$col["editoptions"] = array("defaultValue"=>"{unit_number}","readonly"=>"readonly", "style"=>"border:0");
$cols[] = $col;
//////////////////
// COMPANY NAME //
//////////////////
$col = array();
$col["title"] = "Customer";
$col["name"] = "company_name";
$col["width"] = "100";
$col["hidden"] = false;
$col["editable"] = false;
$col["export"] = true;
$cols[] = $col;
/////////////////////
// JOB DESCRIPTION //
/////////////////////
$col = array();
$col["title"] = "Job Description";
$col["name"] = "job_description";
$col["width"] = "100";
$col["hidden"] = true;
$col["editable"] = false;
$col["export"] = false;
$cols[] = $col;
////////////////////
// job total_cost //
////////////////////
$col = array();
$col["title"] = "total_cost";
$col["name"] = "total_cost";
$col["width"] = "100";
$col["hidden"] = true;
$col["editable"] = false;
$col["export"] = false;
$cols[] = $col;
//////////////////////
// UNIT TOTAL HOURS //
//////////////////////
$col = array();
$col["title"] = "unit_total_hours";
$col["name"] = "unit_total_hours";
$col["width"] = "100";
$col["hidden"] = true;
$col["editable"] = false;
$col["export"] = false;
$cols[] = $col;
/////////////////////
// UNIT TOTAL COST //
/////////////////////
$col = array();
$col["title"] = "unit_total_cost";
$col["name"] = "unit_total_cost";
$col["width"] = "100";
$col["hidden"] = true;
$col["editable"] = false;
$col["export"] = false;
$cols[] = $col;
//////////////////////
// UNIT TOTAL HOURS //
//////////////////////
$col = array();
$col["title"] = "total_hours";
$col["name"] = "total_hours";
$col["width"] = "100";
$col["hidden"] = true;
$col["editable"] = false;
$col["export"] = false;
$cols[] = $col;
////////////////////////////
// TIME CARD HOURS BY JOB //
////////////////////////////
$col = array();
$col["title"] = "Time Card Hours Job";
$col["name"] = "thj";
$col["width"] = "100";
$col["hidden"] = true;
$col["editable"] = false;
$col["export"] = false;
$cols[] = $col;
//////////////////////////
// TIME CARD HOURS UNIT //
//////////////////////////
$col = array();
$col["title"] = "Time Card Hours Unit";
$col["name"] = "thu";
$col["width"] = "100";
$col["hidden"] = true;
$col["editable"] = false;
$col["export"] = false;
$cols[] = $col;
///////////////
// REAL TIME //
///////////////
$col = array();
$col["title"] = "real time";
$col["name"] = "real_time";
$col["width"] = "75";
$col["editable"] = false;
$col["hidden"] = true;
$col["on_data_display"] = array("do_mathss","");
$cols[] = $col;
function do_mathss($data)
{
if ($data["unit_po_status"] != 'SEPARATE PO')
{
return $data["real_time"] = $data["thj"];
}
else
{
return $data["real_time"] = $data["thu"];
}
}
//////////////
// ESTIMATE //
//////////////
$col = array();
$col["title"] = "Estimate";
$col["name"] = "estimate";
$col["width"] = "15";
$col["hidden"] = false;
$col["editable"] = false;
$col["export"] = false;
$col["align"] = "center";
$col["template"] = "<a href='est_unit_list.php?unit={unit_id}&job={job_id}'>$</a>";
$col["formatter"] = "function(cellvalue, options, rowObject){ return '<div title=\"'+rowObject.total_hours+'\">'+cellvalue+'</div>'; }";
$cols[] = $col;
//////////////////////
// PROJECT SCHEDULE //
//////////////////////
$col = array();
$col["title"] = "Prj<br>Schd";
$col["name"] = "pschd";
$col["width"] = "20";
$col["hidden"] = false;
$col["editable"] = false;
$col["export"] = false;
$col["align"] = "center";
$col["template"] = "<a href='Scheduling_by_job.php?unit={unit_id}&job={job_id}'><i class='fa-solid fa-calendar-days'></i></a>";
$col["formatter"] = "function(cellvalue, options, rowObject){ return '<div title=\"'+rowObject.thj+'\">'+cellvalue+'</div>'; }";
$cols[] = $col;
///////////////////
// PROPOSAL DATE //
///////////////////
$col = array();
$col["title"] = "Proposal Date Sent";
$col["name"] = "jp_date";
$col["dbname"] = "tbl_job.jp_date";
$col["width"] = "140";
$col["hidden"] = true;
$col["editable"] = true;
$col["editoptions"]["defaultValue"] = date("Y/m/d");
$col["formatter"] = "date";
$col["export"] = true;
$cols[] = $col;
///////////////
// JOB NOTES //
///////////////
$col = array();
$col["title"] = "Job Notes";
$col["name"] = "unit_notes";
$col["edittype"] = "textarea";
$col["editoptions"] = array("rows"=>10, "cols"=>100);
$col["width"] = "150";
$col["hidden"] = false;
$col["editable"] = true;
$col["export"] = true;
$col["search"] = false;
$cols[] = $col;
///////////////////
// INVOICES PAID //
///////////////////
$col = array();
$col["title"] = "Invoices Paid";
$col["name"] = "prod_unit_inv_paid";
$col["edittype"] = "textarea";
$col["editoptions"] = array("rows"=>10, "cols"=>100);
$col["width"] = "150";
$col["hidden"] = false;
$col["editable"] = true;
$col["export"] = true;
$col["search"] = false;
$cols[] = $col;
///////////////////
// INVOICES OPEN //
///////////////////
$col = array();
$col["title"] = "Invoices Open";
$col["name"] = "prod_unit_inv_open";
$col["edittype"] = "textarea";
$col["editoptions"] = array("rows"=>10, "cols"=>100);
$col["width"] = "150";
$col["hidden"] = false;
$col["editable"] = true;
$col["export"] = true;
$col["search"] = false;
$cols[] = $col;
/////////////////////
// CLOSE WHEN PAID //
/////////////////////
$col = array();
$col["title"] = "CWP";
$col["name"] = "ck_prod_cop";
$col["editable"] = true;
$col["edittype"] = "checkbox";
$col["formatter"] = "checkbox";
$col["editoptions"] = array("value"=>"1:0");
$col["hidden"] = false;
$col["width"] = "25";
$col["export"] = false;
$col["search"] = false;
$cols[] = $col;
//////////////////////
// PERCENT COMPLETE //
//////////////////////
$col = array();
$col["title"] = "PCT<br>CMPLT";
$col["name"] = "unit_percent_comp";
$col["width"] = "30";
$col["hidden"] = false;
$col["editable"] = false;
$col["export"] = true;
$col["search"] = false;
$col["on_data_display"] = array("per_math","");
$cols[] = $col;
function per_math($data)
{
if ($data["unit_po_status"] != 'SEPARATE PO')
{
try {
return $data["unit_percent_comp"] = round(($data["real_time"] / $data['total_hours']) * 100, 0) . "%";
} catch (DivisionByZeroError $e) {
//echo "Caught DivisionByZeroError!\n";
}
}
else
{
try {
return $data["unit_percent_comp"] = round(($data["real_time"] / $data['unit_total_hours']) * 100, 0). "%";
} catch (DivisionByZeroError $e) {
//echo "Caught DivisionByZeroError!\n";
}
}
}
///////////////
// PO NUMBER //
///////////////
$col = array();
$col["title"] = "PO Number";
$col["name"] = "unit_po";
$col["width"] = "80";
$col["hidden"] = false;
$col["editable"] = false;
$col["export"] = true;
$cols[] = $col;
///////////////
// PO NUMBER //
///////////////
$col = array();
$col["title"] = "unit_po_status";
$col["name"] = "unit_po_status";
$col["width"] = "80";
$col["hidden"] = true;
$col["editable"] = false;
$col["export"] = true;
$cols[] = $col;
//////////////////////
// ID NUMBER OF JOB //
//////////////////////
$col = array();
$col["title"] = "fk_job_id";
$col["name"] = "fk_job_id";
$col["dbname"] = "tbl_unit.fk_job_id";
$col["width"] = "80";
$col["hidden"] = false;
$col["editable"] = false;
$col["export"] = false;
$cols[] = $col;
////////////////
// JOB STATUS //
////////////////
if (lockedMenu('9290', $p_row) == 1) {
$col = array();
$col["title"] = "Status";
$col["name"] = "unit_closed";
$col["width"] = "30";
$col["editable"] = true;
$col["edittype"] = "select";
$str = "O:O;C:C";
$col["editoptions"] = array("value"=>$str);
$col["export"] = false;
$col["search"] = false;
$col["editrules"] = array("required"=>false, "readonly"=>true, "readonly-when"=>"check_po");
$cols[] = $col;
}
////////////////////////
// ADD COOKED COLUMNS //
////////////////////////
$g->set_columns($cols);
##########
# EVENTS #
##########
$e["on_insert"] = array("add_edit_caps", null, true);
$e["on_update"] = array("add_edit_caps", null, true);
$e["on_after_insert"] = array("after_insert", null, true);
$e["on_after_update"] = array("after_insert", null, true);
$g->set_events($e);
################
# AFTER INSERT #
################
function after_insert($data)
{
global $g;
global $fkid;
global $conn;
global $jp_date;
//$row = mysqli_query($conn, "UPDATE tbl_job SET jp_date='$jp_date' WHERE job_id = '$fkid'");
//phpgrid_error($fkid);
//////////////////////
// COMPANY CONTACTS // -- ONLY IF THE CONTACT EXISTS
//////////////////////
$row = mysqli_query($conn, "SELECT * FROM tbl_unit WHERE unit_closed='O' AND unit_prod_show = '1' AND fk_job_id = '$fkid'");
$num_rows = mysqli_num_rows($row);
if(empty($num_rows)) {
//CLOSE JOB - NO UNITS OPEN
//phpgrid_error("None Open " . $num_rows);
$g->execute_query("UPDATE tbl_job SET job_open='C' WHERE job_id = '$fkid'");
} else {
//DO NOTHING -UNITS ARE STILL OPEN
//phpgrid_error("Still Open ". $num_rows);
}
}
##########################
# CALLED EVENT FUNCTIONS #
##########################
function add_edit_caps($data)
{
global $g;
global $fkid;
global $conn;
global $jp_date;
$fkid = $data['params']['fk_job_id'];
$jp_date = $data['params']['jp_date'];
phpgrid_error($data['params']['job_id']);
//if(!empty($jp_date))
//{
// $g->execute_query("UPDATE tbl_job SET jp_date='$jp_date' WHERE job_id=4860");
//}
/////////////////////////////////////////////////////////////
// UNSET ALL COLUMNS THAT DONOT BELONG TO DEFAULT DATABASE //
/////////////////////////////////////////////////////////////
unset($data["params"]["job_number"]); //UNSET JOB NUMBER
unset($data["params"]["full_name"]); //UNSET PEROJECT MANAGER
unset($data["params"]["fk_job_id"]);
unset($data["params"]["estimate"]);
unset($data["params"]["jp_date"]);
unset($data["params"]["real_time"]);
unset($data["params"]["thj"]);
unset($data["params"]["thu"]);
}
#######################
# RENDER GRID (list1) #
#######################
$out = $g->render("list1");
?>
<?php
################
# INCLUDE MENU #
################
include("assets/menu.php");
################
# DISPLAY GRID #
################
echo $out
?>
<?php if($bline == 1) { ?>
<!-- GRID LINES -->
<link rel="stylesheet" type="text/css" href="grid.css">
<?php } ?>
<!-- JAVA SCRIPT -->
<script>
//FANCYBOX
$(document).ready(function() {
$('.fancybox').fancybox();
});
//CHECKBOX + AJAX (UPDATE WITHOUT EDIT MODE)
function cboxFormatter(cellvalue, options, rowObject)
{
if ( cellvalue == 1 )
return '<input id="cbox'+options.rowId+'" type="checkbox" name="completed" value="'+options.rowId+'" onclick="updateRow('+options.rowId+',this.checked);" checked/> ';
else
return '<input id="cbox'+options.rowId+'" type="checkbox" name="completed" value="'+options.rowId+'" onclick="updateRow('+options.rowId+',this.checked);" /> ';
}
function cboxUnFormat(cellvalue, options, cell)
{
return jQuery('input', cell).attr('value');
}
function check_po(formid)
{
var cbox = jQuery("input[name=ck_prod_cop]:last, select[name=ck_prod_cop]:last",formid).is(':checked');
var text = jQuery("textarea[name=prod_unit_inv_open]:last, select[name=prod_unit_inv_open]:last",formid).val();
//var text = jQuery("[name=prod_unit_inv_open].FormElement,[name=prod_unit_inv_open].editable").val(data.customer_id);
//alert(formid.prod_unit_inv_open);
//alert(text);
//alert(cbox);
if (cbox == true) {
//if the text is empty or on has spaces in it
if(text == '' || text.trim().length === 0) {
return false;
} else {
return true;
}
} else {
return true;
}
}
function updateRow(id, checked)
{
// call ajax to update date in db
var request = {};
request['oper'] = 'edit';
request['id'] = id;
if (checked)
request['ck_prod_cop'] = 1;
else
request['ck_prod_cop'] = 0;
var grid = jQuery('#list1');
jQuery.ajax({
url: grid.jqGrid('getGridParam','url'),
dataType: 'html',
data: request,
type: 'POST',
error: function(res, status) {
jQuery.jgrid.info_dialog(jQuery.jgrid.errors.errcap,'<div class=\"ui-state-error\">'+ res.responseText +'</div>',
jQuery.jgrid.edit.bClose,{buttonalign:'right'});
},
success: function( data ) {
// reload grid for data changes
grid.jqGrid().trigger('reloadGrid',[{jqgrid_page:1}]);
}
});
}
jQuery(window).load(function()
{
// show dropdown in toolbar
jQuery('.navtable tr:first').append('<td><div style="padding-left: 5px; padding-top:0px; float:left"><select style="height:24px" class="chngroup"><?php foreach($g->options["colModel"] as $c) { if($c["title"] =='PM' OR $c["title"] =='Customer'){?><option value="<?php echo $c["name"] ?>" <?php echo ($c["name"]=="role")?"selected":"" ?>><?php echo $c["title"] ?></option><?php }} ?></select></div></td>');
var grid_id = '<?php echo $g->id ?>';
jQuery(".chngroup").change(function()
{
var vl = jQuery(this).val();
if(vl)
{
if(vl == "clear")
jQuery("#"+grid_id).jqGrid('groupingRemove',true);
else
jQuery("#"+grid_id).jqGrid('groupingGroupBy',vl);
}
});
// http://www.trirand.com/jqgridwiki/doku.php?id=wiki:grouping#methods
jQuery("#toggleGroup").click(function()
{
jQuery("."+grid_id+"ghead_0").each(function(){
jQuery("#"+grid_id).jqGrid('groupingToggle',jQuery(this).attr('id'));
});
});
jQuery(".opengroup").change(function(){
var grid_id = "list1";
var group_id = jQuery(this).val();
id = grid_id + "ghead_0" + "_" + group_id;
jQuery("#"+grid_id).jqGrid('groupingToggle',id);
})
});
jQuery(document).ready(function(){
var unit = "<?php echo $uid ?>";
var job = "<?php echo $jid ?>";
var notes = "<?php echo $open ?>";
if (notes != 0) {
setTimeout(()=>{
jQuery('#list1').jqGrid('navButtonAdd', '#list1_pager',
{
'caption' : 'Show Open',
'buttonicon' : 'ui-icon-folder-collapsed',
'onClickButton': function()
{
notes = 0;
window.location.href = "?unit=" + unit + "&job=" + job + "&open=" + notes
},
'position': 'last'
});
},10);
} else {
setTimeout(()=>{
jQuery('#list1').jqGrid('navButtonAdd', '#list1_pager',
{
'caption' : 'Show Closed',
'buttonicon' : 'ui-icon-folder-open',
'onClickButton': function()
{
notes=1;
window.location.href = "?unit=" + unit + "&job=" + job + "&open=" + notes
},
'position': 'last'
});
},10);
}
});
////////////////////////////////////////
// COLOR RED IF NO QUOTE RELEASE DATE //
////////////////////////////////////////
function grid_onload(ids)
{
if(ids.rows)
{
jQuery.each(ids.rows,function(i)
{
// used when scroll:true
var gid = "list1";
if (typeof(jQuery('#'+gid).data('jqgrid_rows')) != 'undefined')
{
i = i + jQuery('#'+gid).data('jqgrid_rows');
}
if(this.ck_prod_cop == 1)
{
jQuery('#list1 tr.jqgrow:eq('+i+')').css('background-image','inherit').css({'background-color':'#C6C6C6', 'color':'BLACK'});
}
else
{
if(this.job_type == 'T&M')
{
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_unit_percent_comp]').css({'background-color':'#8FBC8F', 'color': 'black' });
}
//REMOVE SEPARET PO FROM THIS COLOR
if(this.unit_po_status != 'SEPARATE PO')
{
//total cost is not 0, date sent is 0 : orange
if(this.total_cost != 0 && this.jp_date == '0000-00-00' || this.total_cost != 0 && this.jp_date == '')
{
jQuery('#list1 tr.jqgrow:eq('+i+')').css('background-image','inherit');
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_estimate]').css({'background-color':'orange', 'font-size': '150%' });
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_estimate] a').css({'color':'white' });
}
//no total cost, and date sent is 0 : red
else if(this.total_cost == 0 && this.jp_date == '0000-00-00' || this.total_cost == 0 && this.jp_date == '')
{
jQuery('#list1 tr.jqgrow:eq('+i+')').css('background-image','inherit');
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_estimate]').css({'background-color':'red', 'font-size': '150%' });
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_estimate] a').css({'color':'white' });
}
//no total cost, but date sent is not 0 : blue
else if(this.total_cost == 0 && this.jp_date != '0000-00-00' || this.total_cost == 0 && this.jp_date != '')
{
jQuery('#list1 tr.jqgrow:eq('+i+')').css('background-image','inherit');
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_estimate]').css({'background-color':'blue', 'font-size': '150%' });
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_estimate] a').css({'color':'white' });
}
//green
else if(this.total_cost != 0 && this.jp_date != '0000-00-00' || this.total_cost != 0 && this.jp_date != '')
{
jQuery('#list1 tr.jqgrow:eq('+i+')').css('background-image','inherit');
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_estimate]').css({'background-color':'green', 'font-size': '150%' });
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_estimate] a').css({'color':'white' });
}
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_real_time]').val(this.thj);
}
//REMOVE SEPARET PO FROM THIS COLOR
else if(this.unit_po_status == 'SEPARATE PO')
{
//total cost is not 0, date sent is 0 : orange
if(this.unit_total_cost != 0 && this.jp_date == '0000-00-00' || this.unit_total_cost != 0 && this.jp_date == '')
{
jQuery('#list1 tr.jqgrow:eq('+i+')').css('background-image','inherit');
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_estimate]').css({'background-color':'orange', 'font-size': '150%' });
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_estimate] a').css({'color':'white' });
}
//no total cost, and date sent is 0 : red
else if(this.unit_total_cost == 0 && this.jp_date == '0000-00-00' || this.unit_total_cost == 0 && this.jp_date == '')
{
jQuery('#list1 tr.jqgrow:eq('+i+')').css('background-image','inherit');
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_estimate]').css({'background-color':'red', 'font-size': '150%' });
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_estimate] a').css({'color':'white' });
}
//no total cost, but date sent is not 0 : blue
else if(this.unit_total_cost == 0 && this.jp_date != '0000-00-00' || this.unit_total_cost == 0 && this.jp_date != '')
{
jQuery('#list1 tr.jqgrow:eq('+i+')').css('background-image','inherit');
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_estimate]').css({'background-color':'blue', 'font-size': '150%' });
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_estimate] a').css({'color':'white' });
}
//green
else if(this.unit_total_cost != 0 && this.jp_date != '0000-00-00' || this.unit_total_cost != 0 && this.jp_date != '')
{
jQuery('#list1 tr.jqgrow:eq('+i+')').css('background-image','inherit');
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_estimate]').css({'background-color':'green', 'font-size': '150%' });
jQuery('#list1 tr.jqgrow:eq('+i+') td[aria-describedby=list1_estimate] a').css({'color':'white' });
}
jQuery("[name=real_time].FormElement,[name=real_time].editable").val(this.thu);
}
}
});
}
}
</script>
<!-- CSS STYLE -->
<style>
.jqgroup b {
color: navy;
line-height: 25px;
}
.jqgroup .ui-icon {
font-size: 2em;
}
.ui-jqgrid tr.jqgroup td
{
background-color: lightyellow;
}
.ui-autocomplete-loading { background:url('https://loading.io/assets/img/landing/curved-bars.svg') #FFFFFF no-repeat right center !important; }
.ui-jqgrid tr.jqgrow td
{
vertical-align: top;
white-space: normal !important;
padding:2px 5px;
}
</style>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment