Skip to content

Instantly share code, notes, and snippets.

@tmoore88
Created October 18, 2023 16:15
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/a5268f5e3429334d177a19af371b2574 to your computer and use it in GitHub Desktop.
Save tmoore88/a5268f5e3429334d177a19af371b2574 to your computer and use it in GitHub Desktop.
<?php
#DISPLAYS MASTER JOB LIST - ACTIVE/PENDING (master_job_list_ap.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
#######################
## PHPMAILER INCLUDE ##
#######################
include_once("lib/PHPMailer/src/Exception.php");
include_once("lib/PHPMailer/src/PHPMailer.php");
include_once("lib/PHPMailer/src/SMTP.php");
//Import the PHPMailer class into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
######################
# 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('12', $p_row) == 0) {
header('Location: HTTP403.html');
}
$admin = lockedMenu('1210', $p_row);
#######################
# 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 = "MASTER JOB LIST" . "<a style='font-size: 20px; color: #ccd232; padding-left: 25px;' target='_blank' class='fancybox' data-fancybox data-type='iframe' href='http://kodiacclimate:9000/kodiacclimate/index.php/Kodiaccess#Master_Job_List'><i class='fas fa-question-circle'></i></a>";
$title = "MASTER JOB LIST" . "
<div class='button'>
<div class='dropdown'>
<a class='dropbtn' style='color: #ccd232' href='#'><i class='fas fa-question-circle fa-lg'></i></a>
<div class='dropdown-content'>
<a style='min-width: 350px; padding: 0px 15px 0px; font-size: .8em' class='various fancybox' href='https://www.youtube.com/embed/g_TxVQBsyGE?vq=hd1080&autoplay=1'><i class='fa-solid fa-film'></i> - Making a \"Sales/Pending\" Project \"Active\"</a>
</div>
</div>
</div>
";
###################
# CREATE NEW GRID #
###################
$g = new jqgrid($db_conf);
##################################
# SEE IF UNIT/JOB INFO IS PASSED #
##################################
if(isset($_GET['job']))
{
$jid=$_GET['job'];
} else { $jid='3742'; }
if(isset($_GET['unit']))
{
$uid=$_GET['unit'];
} else { $uid=0; }
if(isset($_GET['endcust'])) {
$ecust=$_GET['endcust'];
} else {
$ecust=0;
}
if(isset($_GET['arch']))
{
$arch=$_GET['arch'];
} else {
$arch=0;
}
#############################
# AUTO FIND NEXT JOB NUMBER #
#############################
if ($_POST["action"] == "get_id")
{
$rs = $g->get_one("SELECT MAX(job_number)+1 as next_id from tbl_job");
echo $rs["next_id"];
die;
}
#########################
# GET JOB AND UNIT INFO #
#########################
////////////////////////////////////////////////
// QUERY TABLE UNIT FOR JOB AND CUSTOMER INFO //
////////////////////////////////////////////////
$q_info1=mysqli_query($conn, "SELECT * FROM tbl_unit
LEFT JOIN tbl_job ON fk_job_id = job_id
LEFT JOIN tbl_customer ON fk_customer = customer_id
WHERE unit_id = '$uid'
") or die ();
////////////////////////////////////////////////////////////////////////////////////////
// IF UNIT NUMBER FROM URL IS NOT THERE - QUERY TABLE JOB FOR JOB NUMBER AND CUSTOMER //
////////////////////////////////////////////////////////////////////////////////////////
if (mysqli_num_rows($q_info1)== 0) {
$q_info1=mysqli_query($conn, "SELECT * FROM tbl_job
LEFT JOIN tbl_customer ON fk_customer = customer_id
WHERE job_id = $jid") or die();
}
IF (!empty($q_info1)) {
$q_info2=mysqli_fetch_array($q_info1);
}
############################################
# FILL DROPDOWN WITH SEED FILE INFORMATION #
############################################
$dir = '//edison02/jobs/-0_Seed';
// List of file names to exclude from output
// NOTE: This is case-sensitive
$exclude = array();
# $exclude = array( '0seed_JOBno_Chevron' );
// Check to see if $dir is a valid directory
if (is_dir($dir))
{
$contents = scandir($dir);
foreach($contents as $file)
{
// This will exclude all filenames contained within the $exclude array
// as well as hidden files that begin with '.'
if (!in_array($file, $exclude) && substr($file, 0, 1) != '.')
{
$tseed = $tseed . $file . ":" . $file . ';';
}
}
//remove last semi-colon
$seed = substr($tseed,0,-1);
} else {
exit(($dir) . '//edison02/jobs/-0_Seed -- DIRECTORY NOT FOUND -- please make sure the server is on or update the location of the seed files in the two PHP files. [Master_Job_List.php(134) and Company.php(52)]');
}
################
# SET INFO BAR #
################
if ($uid != 0) {
$desc1 = "UNIT#: " . $q_info2['unit_number'] . " - " . $q_info2['unit_description'] ." <br> " . $q_info2['company_name'] . " - " . $q_info2['job_description'] . " - KODIAK GROUP PROJECT #" . $q_info2['job_number'];
} else {
$desc1 = "SELECT UNIT NUMBER <br>" . $q_info2['company_name'] . " - " . $q_info2['job_description'] . " - KODIAK GROUP PROJECT #" . $q_info2['job_number'];
}
#############
# JOB NOTES #
#############
$qnotes = mysqli_query($conn, "SELECT * FROM job_notes WHERE fk_job_id = $jid");
if (mysqli_num_rows($qnotes)== 0) {
$desc2 = $desc1 . "<span style='float: right; padding-left: 20px;'> <a title='Job Notes' target='_blank' data-fancybox class='fancybox fas fa-comment-slash' data-type='iframe' href='assets/job/job_notes.php?job=$jid'></a></span>";
} else {
$desc2 = $desc1 . "<span style='float: right; padding-left: 20px;'> <a title='Job Notes' target='_blank' data-fancybox class='fancybox fas fa-comment' data-type='iframe' href='assets/job/job_notes.php?job=$jid'></a></span>";
}
################
# JOB CONTACTS #
################
$qcontacts = mysqli_query($conn, "SELECT * FROM job_contacts WHERE fk_job_id = $jid");
if (mysqli_num_rows($qcontacts )== 0) {
$desc3 = $desc2 . "<span style='float: right; padding-left: 80px; color: LightGray;'> <a title='Job Contacts' target='_blank' data-fancybox class='fancybox fas fa-users' data-type='iframe' href='assets/job/job_contacts.php?job=$jid'></a></span>";
} else {
$desc3 = $desc2 . "<span style='float: right; padding-left: 80px;'> <a title='Job Contacts' target='_blank' data-fancybox class='fancybox fas fa-users' data-type='iframe' href='assets/job/job_contacts.php?job=$jid'></a></span>";
}
$desc = $desc3;
if ($q_info2['job_status'] == "ARCHIVED") {
$arch = 1;
$desc = $desc . "<br> <div class='blink'> *** ARCHIVED ***</div>";
}
################
# GRID OPTIONS #
################
$grid["caption"] = $title; // GRID CAPTION NAME
$grid["sortname"] = 'job_number'; // sort by kodiak job number
$grid["sortorder"] = "DESC"; //
$grid["export"] = array("filename"=>"Master Job List"); //
$grid["loadComplete"] = "function(ids) { grid_onload(ids); }"; //
$grid["add_options"]["afterShowForm"] = 'function (form) { fill_next_id(form); }';
$grid["add_options"]["beforeSubmit"] = "function(post,form){ return validate_form_once(post,form); }";
$grid["import"]["hidefields"] = array("job_id", "ck_qb", "ck_ff", "ck_ds", "customer_name", "fk_job_id", "job_contacts", "notes", "job_notes");
$grid["edit_options"]["afterShowForm"] = 'function (form) {
var fldSrc = "";
var fldDest= "";
var wData = "";
var $btn = $(\'<a class="fancybox1" data-fancybox data-type="iframe" target="_test" href="assets/company/new_customer.php?comp=1">ADD COMPANY</a>\')
.addClass("fm-button ui-state-default")
.css({"padding": "4px", "margin":"0px 0px 3px 0px", "vertical-align": "bottom"})
var $btn1 = $btn.clone(true);
$($btn1).attr("id", "btnClient");
$("#tr_company_name > td.DataTD").append(" ").append($btn1);
$("#company_name").css("width","calc(75% - 50px)");
fill_next_id(form);
//add_dropdown_action(form);
}';
$grid["add_options"]["afterShowForm"] = $grid["edit_options"]["afterShowForm"];
if ($arch == 1) { $grid["rowNum"] = 1000; $grid["rowList"] = array(); };
$g->set_options($grid);
##########################
# GRID ACTIONS AVIALABLE #
##########################
$g->set_actions(array(
"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"=>true, // 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 (delCheck('12', $p_row) == 0) { $g->set_actions(array( "delete"=>false)); } else { $g->set_actions(array( "delete"=>true)); }
if (edtCheck('12', $p_row) == 0) { $g->set_actions(array( "edit"=>false)); } else { $g->set_actions(array( "edit"=>true)); }
if (edtCheck('12', $p_row) == 0) { $g->set_actions(array( "inline"=>false)); } else { $g->set_actions(array( "inline"=>true)); }
###############################
# MAIN QUERY (EQUIPMENT LIST) #
###############################
if ($arch == 1) {
$g->select_command = "SELECT DISTINCT (n.fk_job_id) as notes, c.fk_job_id as contacts, cs.company_name as enduser,
job_id, job_number, ck_qb, ck_ff, ck_ds, start_date, po_number, job_description, fk_customer, cn.company_name, fk_proj_id, full_name, job_type, job_status, cn.customer_folder, cn.customer_seed , w.job_open, cn.cust_date, job_comp_date, job_pending,
customer_site_id, sites_fk_customer_id, site_customer_folder, fk_site_id, site_name
FROM tbl_job w
LEFT JOIN tbl_customer cn ON cn.customer_id = fk_customer
LEFT JOIN tbl_customer cs ON cs.customer_id = fk_enduser
LEFT JOIN tbl_users ON fk_proj_id = user_id
LEFT JOIN job_contacts c ON c.fk_job_id = job_id
LEFT JOIN tbl_contacts mc ON mc.fk_customer_id = fk_customer
LEFT JOIN job_notes n ON n.fk_job_id = job_id
LEFT JOIN tbl_customer_sites ON customer_site_id = w.fk_site_id
WHERE job_status <> 'ARCHIVED' AND job_status <> 'NP'
";
} else {
$g->select_command = "SELECT DISTINCT (n.fk_job_id) as notes, c.fk_job_id as contacts, cs.company_name as enduser,
job_id, job_number, ck_qb, ck_ff, ck_ds, start_date, po_number, job_description, fk_customer, cn.company_name, fk_proj_id, full_name, job_type, job_status, cn.customer_folder, cn.customer_seed, job_comp_date, job_open, job_pending,
customer_site_id, sites_fk_customer_id, site_customer_folder, fk_site_id, site_name
FROM tbl_job w
LEFT JOIN tbl_customer cn ON cn.customer_id = fk_customer
LEFT JOIN tbl_customer cs ON cs.customer_id = fk_enduser
LEFT JOIN tbl_users ON fk_proj_id = user_id
LEFT JOIN job_contacts c ON c.fk_job_id = job_id
LEFT JOIN tbl_contacts mc ON mc.fk_customer_id = fk_customer
LEFT JOIN job_notes n ON n.fk_job_id = job_id
LEFT JOIN tbl_customer_sites ON customer_site_id = w.fk_site_id
WHERE job_status <> 'ARCHIVED' AND job_status <> 'NP'
";
}
###################################
# REMOVE BUTTONS FROM GRID HEADER #
###################################
$g->navgrid["param"]["del"] = false;
if (addCheck('12', $p_row) == 0) { $g->navgrid["param"]["add"] = false; } else { $g->navgrid["param"]["add"] = true; }
$g->navgrid["param"]["edit"] = false;
#################
# MAIN DATABAES #
#################
$g->table = "tbl_job";
####################################
# SETUP COLUMNS TO DISPLAY IN GRID #
####################################
////////////
// JOB ID // - MAIN COLUMN
////////////
$col = array();
$col["title"] = "ID";
$col["name"] = "job_id";
$col["width"] = "20";
if (lockedMenu('1004', $p_row) == 0) { $col["hidden"] = true; } else { $col["hidden"] = false; }
$col["export"] = false;
$cols[] = $col;
///////////////
// JOB NUMBER //
////////////////
$col = array();
$col["title"] = "Job Number";
$col["name"] = "job_number";
$col["link"] = "unit_list.php?job={job_id}";
$col["width"] = "50";
$col["hidden"] = false;
$col["editable"] = true;
$col["editoptions"] = array("readonly"=>"readonly", "style"=>"border:0");
$col["export"] = true;
$cols[] = $col;
///////////////////
// job_comp_date //
///////////////////
$col = array();
$col["title"] = "job_comp_date";
$col["name"] = "job_comp_date";
$col["width"] = "50";
$col["hidden"] = true;
$col["editable"] = true;
$col["export"] = false;
$cols[] = $col;
///////////////////
// JOB NUMBER TC //
///////////////////
$col = array();
$col["title"] = "Job Number TC";
$col["name"] = "job_number_tc";
$col["width"] = "50";
$col["hidden"] = true;
$col["editable"] = true;
$col["export"] = false;
$cols[] = $col;
# <!-- ABOVE NORMAL USER --> #
if (lockedMenu('1212', $p_row) == 1) {
//////////////////////////
// CHECK BOX QUICKBOOKS //
//////////////////////////
$col = array();
$col["title"] = "QB";
$col["name"] = "ck_qb";
$col["width"] = "40";
$col["edittype"] = "checkbox";
$col["formatter"] = "checkbox";
$col["editoptions"] = array("value"=>"1:0");
$col["search"] = false;
$col["hidden"] = false;
$col["export"] = false;
$col["editable"] = true;
$cols[] = $col;
} else {
$col = array();
$col["title"] = "QB";
$col["name"] = "ck_qb";
$col["width"] = "40";
$col["edittype"] = "checkbox";
$col["formatter"] = "checkbox";
$col["editoptions"] = array("value"=>"1:0");
$col["search"] = false;
$col["hidden"] = true;
$col["export"] = false;
$col["editable"] = true;
$cols[] = $col;
}
///////////////////////////
// CHECK BOX FILE FOLDER //
///////////////////////////
if (addCheck('12', $p_row) == 1) {
$col = array();
$col["title"] = "File Folder";
$col["name"] = "ck_ff";
$col["width"] = "40";
$col["edittype"] = "checkbox";
$col["formatter"] = "checkbox";
$col["editoptions"] = array("value"=>"1:0");
$col["search"] = false;
$col["hidden"] = false;
$col["export"] = false;
$col["editable"] = true;
#$col["formatter"] = "function(cellvalue, options, rowObject){ return cboxFormatter(cellvalue, options, rowObject); }";
#$col["unformat"] = "function(cellvalue, options, cell){ return cboxUnFormat(cellvalue, options, cell);}";
$cols[] = $col;
}
# <!-- END ABOVE NORMAL USER --> #
////////////////
// START DATE //
////////////////
$col = array();
$col["title"] = "Start Date";
$col["name"] = "start_date";
$col["width"] = "60";
$col["hidden"] = false;
$col["editable"] = true;
$col["editoptions"]["defaultValue"] = date("Y/m/d");
$col["formatter"] = "date";
$col["export"] = true;
//$col["editrules"] = array("date"=>true);
$cols[] = $col;
///////////////
// PO NUMBER //
///////////////
$col = array();
$col["title"] = "PO Number";
$col["name"] = "po_number";
$col["width"] = "65";
$col["hidden"] = true;
$col["editable"] = true;
$col["export"] = true;
$cols[] = $col;
/////////////////////
// JOB DESCRIPTION //
/////////////////////
$col = array();
$col["title"] = "Job Description (Directory Name)";
$col["name"] = "job_description";
$col["editoptions"]["autocomplete"] = "off";
$col["width"] = "200";
$col["hidden"] = false;
$col["editable"] = true;
$col["editoptions"]["maxlength"] = 25;
$col["editoptions"]["title"] = "some tooltip help";
$col["editrules"] = array("required"=>true);
$col["export"] = true;
$cols[] = $col;
////////////////
// FK_ENDUSER //
////////////////
$col = array();
$col["title"] = "fk_enduser";
$col["name"] = "fk_enduser";
$col["width"] = "20";
$col["hidden"] = true;
$col["editable"] = true;
$col["export"] = false;
$cols[] = $col;
//////////////////
// COMPANY NAME //
//////////////////
$col = array();
$col["title"] = "Full Company Name (tblock)";
$col["name"] = "company_name";
$col["dbname"] = "cn.company_name";
$col["link"] = "company.php?job={job_id}&list1_company_name={company_name}";
$col["width"] = "100";
$col["hidden"] = false;
$col["editable"] = true;
$col["formatter"] = "autocomplete";
$col["formatoptions"] = array( "sql"=>"SELECT *,company_name as v FROM tbl_customer WHERE company_name REGEXP '^{company_name}' AND antiquated = 0",
"search_on"=>"company_name",
"callback"=>"fill_comp");
$col["editrules"] = array("required"=>true, "readonly"=>true, "readonly-when"=>"check_pending");
$col["export"] = true;
$cols[] = $col;
//////////////
// END USER //
//////////////
$col = array();
$col["title"] = "End Customer";
$col["name"] = "enduser";
//$col["DBname"] = "cs.company_name";
$col["width"] = "100";
$col["hidden"] = false;
$col["editable"] = true;
$col["formatter"] = "autocomplete";
$col["formatoptions"] = array( "sql"=>"SELECT *,company_name as v FROM tbl_customer WHERE company_name REGEXP '^{enduser}' AND antiquated = 0",
"search_on"=>"company_name",
"callback"=>"fill_enduser");
if ($ecust == 0) {
$col["show"] = array("list"=>false, "add"=>true, "edit"=>false, "view"=>true, "bulkedit"=>false);
} else {
$col["show"] = array("list"=>true, "add"=>true, "edit"=>false, "view"=>true, "bulkedit"=>false);
}
$col["editrules"] = array("required"=>false);
$col["export"] = false;
$cols[] = $col;
////////////////
// FK_PROJ_ID //
////////////////
$col = array();
$col["title"] = "customer_id";
$col["name"] = "customer_id";
$col["width"] = "20";
$col["hidden"] = false;
$col["editable"] = true;
$col["export"] = false;
//$col["editoptions"]["onchange"]["update_field"] = "customer_site_id";
$cols[] = $col;
/////////////////
// FK_CUSTOMER //
/////////////////
$col = array();
$col["title"] = "fk_customer";
$col["name"] = "fk_customer";
$col["width"] = "20";
$col["hidden"] = false;
$col["editable"] = true;
$col["export"] = false;
$cols[] = $col;
////////////////
// FK_PROJ_ID //
////////////////
$col = array();
$col["title"] = "user_id";
$col["name"] = "user_id";
$col["width"] = "20";
$col["hidden"] = true;
$col["editable"] = true;
$col["export"] = false;
$cols[] = $col;
///////////////////////////////
// JOB OPEN FOR PENDING JOBS //
///////////////////////////////
$col = array();
$col["title"] = "Job_open";
$col["name"] = "job_open";
$col["width"] = "75";
$col["editable"] = true;
$col["export"] = false;
$col["hidden"] = true;
//$col["default"] = "O";
$cols[] = $col;
//////////////////////////
// JOB PENDING APPROVAL //
//////////////////////////
$col = array();
$col["title"] = "job_pending";
$col["name"] = "job_pending";
$col["width"] = "75";
$col["editable"] = true;
$col["hidden"] = true;
$col["export"] = false;
$cols[] = $col;
///////////////////
// CUSTOMER SITE //
///////////////////
$col = array();
$col["title"] = "Site Name";
$col["name"] = "site_name";
$col["dbname"] = "store.customer_site_id";
$str = $g->get_dropdown_values("SELECT *, site_name as v, customer_site_id as k FROM tbl_customer_sites");
$col["width"] = "55";
$col["hidden"] = true;
$col["editable"] = true;
$col["stype"] = "select";
$col["edittype"] = "select";
$col["show"] = array("list"=>true, "add"=>true, "edit"=>true, "view"=>false, "bulkedit"=>false);
$col["editoptions"] = array("value" => ":;" . $str);
$col["editoptions"]["dataInit"]["sql"] = "SELECT customer_site_id AS k, site_name AS v FROM tbl_customer_sites WHERE sites_fk_customer_id IN ({customer_id})";
$col["export"] = false;
$col["editrules"] = array("required"=>true);
$cols[] = $col;
//////////////////////
// CUSTOMER SITE ID //
//////////////////////
$col = array();
$col["title"] = "customer_site_id";
$col["name"] = "customer_site_id";
$col["width"] = "75";
$col["editable"] = true;
$col["hidden"] = false;
$col["export"] = false;
$cols[] = $col;
////////////////
// FK_SITE_ID //
////////////////
$col = array();
$col["title"] = "fk_site_id";
$col["name"] = "fk_site_id";
$col["width"] = "75";
$col["editable"] = true;
$col["hidden"] = true;
$col["export"] = false;
$cols[] = $col;
////////////////
// job folder // -----------------------------------------------------------------------------------------------------------------------------------------------------
////////////////
$col = array();
$col["title"] = "Directory Name";
$col["name"] = "site_customer_folder";
$col["width"] = "100";
$col["hidden"] = true;
$col["editable"] = true;
$col["show"] = array("list"=>false, "add"=>true, "edit"=>true, "view"=>false, "bulkedit"=>false);
$col["export"] = false;
$col["editrules"] = array("required"=>true);
$col["editoptions"]["maxlength"] = 25;
$cols[] = $col;
//////////////////
// DL LIST TYPE //
//////////////////
$DL = "KODIAK STANDARD:KODIAK STANDARD;GM:GM;WEYERHAEUSER:WEYERHAEUSER";
$col = array();
$col["title"] = "Drawing List";
$col["name"] = "customer_drawinglist";
$col["width"] = "100";
$col["hidden"] = true;
$col["editable"] = true;
$col["show"] = array("list"=>false, "add"=>true, "edit"=>true, "view"=>false, "bulkedit"=>false);
$col["export"] = false;
$col["edittype"] = "select";
$col["editoptions"] = array("value"=>$DL,"defaultValue"=>"KODIAK STANDARD");
$cols[] = $col;
///////////////
// SEED FILE //
///////////////
$col = array();
$col["title"] = "Seed File";
$col["name"] = "customer_seed";
$col["width"] = "100";
$col["hidden"] = true;
$col["editable"] = true;
$col["show"] = array("list"=>false, "add"=>true, "edit"=>true, "view"=>false, "bulkedit"=>false);
$col["export"] = false;
$col["edittype"] = "select";
$col["editrules"] = array("required"=>true);
$col["editoptions"] = array("value"=>$seed,"defaultValue"=>"0seed_JOBno_DESCRIPTION");
$cols[] = $col;
/////////////////////
// PROJECT MANAGER //
/////////////////////
$col = array();
$col["title"] = "Project Manager";
$col["name"] = "full_name";
$col["width"] = "100";
$col["hidden"] = false;
// -- READ ONLY ON EDIT FOR PEOPLE UNDER 300 PERMISSIONS --
if (lockedMenu('1211', $p_row) == 1) {
$col["editable"] = true;
$col["editrules"] = array("required"=>true);
} else {
$col["editable"] = true;
$col["editrules"] = array("required"=>true, "readonly"=>true);
}
$col["formatter"] = "autocomplete";
$col["formatoptions"] = array( "sql"=>"SELECT *, full_name as v FROM tbl_users WHERE full_name REGEXP '^{full_name}'",
"search_on"=>"full_name",
"callback"=>"fill_form");
$col["export"] = true;
$cols[] = $col;
/////////////////////
// Primary Contact // - VIEW AND EDIT
/////////////////////
$col = array();
$col["title"] = "Project Contact (REQ)";
$col["name"] = "First_name";
$col["dbname"] = "mc.First_name";
$col["width"] = "100";
$col["hidden"] = false;
$col["editable"] = true;
$col["formatter"] = "autocomplete";
$col["formatoptions"] = array( "sql"=>"SELECT *, CONCAT(First_name, ' ', Last_name) as v, contacts_id as k FROM tbl_contacts WHERE First_name REGEXP '^{First_name}'",
"search_on"=>"CONCAT(First_name, Last_name)",
"callback"=>"fill_email");
$col["export"] = false;
$col["show"] = array("list"=>false, "add"=>true, "edit"=>false, "view"=>true, "bulkedit"=>false);
$col["editrules"] = array("required"=>false);
$cols[] = $col;
///////////////////////////
// Primary Contact Email // - VIEW AND EDIT
///////////////////////////
$col = array();
$col["title"] = "Project Contact Email (REQ)";
$col["name"] = "email";
$col["dbname"] = "mc.email";
$col["width"] = "100";
$col["hidden"] = false;
$col["editable"] = true;
$col["formatter"] = "autocomplete";
$col["formatoptions"] = array( "sql"=>"SELECT *, email as v, contacts_id as k FROM tbl_contacts",
"search_on"=>"email",
"callback"=>"fill_email");
$col["show"] = array("list"=>false, "add"=>true, "edit"=>false, "view"=>true, "bulkedit"=>false);
$col["editrules"] = array("required"=>false);
$col["export"] = false;
$cols[] = $col;
/////////////////////////////
// VIRTUAL COLUMN JOB TYPE // -ADD ONLY
/////////////////////////////
$col = array();
$col["title"] = "Job Type";
$col["name"] = "job_type_1";
$col["dbname"] = "w.job_type";
$col["width"] = "75";
$col["editable"] = true;
$col["edittype"] = "select";
$str = "SALES:SALES;FAB:FAB;CRUSHER:CRUSHER;INTERNAL:INTERNAL;SPARE PARTS:SPARE PARTS;WARRANTY:WARRANTY";
$col["editoptions"] = array("value"=>$str);
$col["show"] = array("list"=>false, "add"=>true, "edit"=>false, "view"=>true, "bulkedit"=>false);
$col["export"] = false;
$cols[] = $col;
//////////////
// JOB TYPE // - VIEW AND EDIT
//////////////
$col = array();
$col["title"] = "Job Type";
$col["name"] = "job_type";
$col["width"] = "75";
$col["editable"] = true;
$col["edittype"] = "select";
$str = "FIRM BID:FIRM BID;FAB:FAB;T&M:T&M;SALES:SALES;CRUSHER:CRUSHER;INTERNAL:INTERNAL;SPARE PARTS:SPARE PARTS;WARRANTY:WARRANTY";
$col["editoptions"] = array("value"=>$str);
$col["stype"] = "select-multiple";
$col["searchoptions"]["value"] = $str;
if (lockedMenu('1213', $p_row) == 0)
{ $col["show"] = array("list"=>true, "add"=>false, "edit"=>false, "view"=>true, "bulkedit"=>false); }
else
{ $col["show"] = array("list"=>true, "add"=>false, "edit"=>true, "view"=>true, "bulkedit"=>false); }
$col["export"] = true;
$cols[] = $col;
////////////////
// JOB STATUS //
////////////////
$col = array();
$col["title"] = "Job Status";
$col["name"] = "job_status";
$col["width"] = "75";
$col["editable"] = true;
$col["edittype"] = "select";
$col["editoptions"]["dataInit"] = "function(elem){
var val1 = jQuery('input[name=job_open].editable:last').val();
var val2 = jQuery('input[name=job_comp_date].editable:last').val();
var val3 = jQuery('input[name=job_status].editable:last').val();
//If the job has been removed from the sales/production notes, then allow archived
if (val1 == 'C')
{
$(elem).empty().append(\"<option value='ACTIVE:ACTIVE'>ACTIVE</option>\").append(\"<option value='ARCHIVED'>ARCHIVED</option>\");
}
else
{
//Check if units exist if they do not remove active
if (val2 != '') {
$(elem).empty().append(\"<option value='ACTIVE'>ACTIVE</option>\").append(\"<option value='PENDING'>PENDING</option>\");
} else {
$(elem).empty()
.append(\"<option value='PENDING'>PENDING</option>\");
}
}
}";
$col["show"] = array("list"=>true, "add"=>false, "edit"=>true, "view"=>true, "bulkedit"=>false);
$col["export"] = true;
$cols[] = $col;
///////////////////////
// FK JOB ID - NOTES //
///////////////////////
$col = array();
$col["title"] = "notes_fk_job_id";
$col["name"] = "notes";
$col["width"] = "75";
$col["editable"] = false;
$col["hidden"] = true;
$col["export"] = false;
$cols[] = $col;
//////////////////////////
// FK JOB ID - CONTACTS //
//////////////////////////
$col = array();
$col["title"] = "fk_job_id";
$col["name"] = "contacts";
$col["width"] = "75";
$col["editable"] = false;
$col["hidden"] = true;
$col["export"] = false;
$cols[] = $col;
//////////////////
// JOB CONTACTS //
//////////////////
$col = array();
$col["title"] = "Job<br>Contacts";
$col["name"] = "job_contacts";
$col["fixed"] = true;
$col["width"] = "65";
$col["align"] = "center";
$col["search"] = false;
$col["sortable"] = false;
$col["export"] = false;
$col["editable"] = false;
$col["export"] = false;
$but1_html = "<a style='font-size: 20px; color: black;'
target='_blank' class='fancybox' data-fancybox data-type='iframe'
href='assets/job/job_contacts.php?job={job_id}&cust_id={fk_customer}'><i class='fas fa-users'></i></a>";
$but2_html = "<a style='font-size: 20px; color: LightGray;'
target='_blank' class='fancybox' data-fancybox data-type='iframe'
href='assets/job/job_contacts.php?job={job_id}&cust_id={fk_customer}'><i class='fas fa-users'></i></a>";
$col["condition"] = array('$row["contacts"] > 0', $but1_html, $but2_html);
$cols[] = $col;
//////////////////////
// JOB NOTES BUTTON //
//////////////////////
$col = array();
$col["title"] = "Job<br>Notes";
$col["name"] = "job_notes";
$col["fixed"] = true;
$col["width"] = "55";
$col["align"] = "center";
$col["search"] = false;
$col["sortable"] = false;
$col["export"] = false;
$col["editable"] = false;
$col["export"] = false;
$buttons1_html = "<a style='font-size: 20px; color: black;'
target='_blank' class='fancybox' data-fancybox data-type='iframe'
href='assets/job/job_notes.php?job={job_id}'><i class='fas fa-comment'></i></a>";
$buttons2_html = "<a style='font-size: 20px; color: LightGray;'
target='_blank' class='fancybox' data-fancybox data-type='iframe'
href='assets/job/job_notes.php?job={job_id}'><i class='fas fa-comment-slash'></i></a>";
$col["condition"] = array('$row["notes"] > 0', $buttons1_html, $buttons2_html);
$cols[] = $col;
////////////////
// CREATED BY //
////////////////
$col = array();
$col["title"] = "created_by";
$col["name"] = "job_created_by";
$col["width"] = "75";
$col["editable"] = true;
$col["hidden"] = true;
$col["export"] = false;
$col["editoptions"]["defaultValue"] = $uname;
$cols[] = $col;
///////////////////
// ARCHIVED DATE //
///////////////////
$col = array();
$col["title"] = "job_arch_date";
$col["name"] = "job_arch_date";
$col["width"] = "75";
$col["editable"] = true;
$col["hidden"] = true;
$col["export"] = false;
$cols[] = $col;
/////////////////
// ARCHIVED BY //
/////////////////
$col = array();
$col["title"] = "job_arch_by";
$col["name"] = "job_arch_by";
$col["width"] = "75";
$col["editable"] = true;
$col["hidden"] = true;
$col["export"] = false;
$cols[] = $col;
////////////////////////
// ADD COOKED COLUMNS //
////////////////////////
$g->set_columns($cols);
$f = array();
$f["column"] = "job_pending"; // exact column name, as defined above in set_columns or sql field name
$f["op"] = "eq"; // cn - contains, eq - equals
$f["value"] = "1";
$f["class"] = "focus-row"; // css class name
$f_conditions[] = $f;
// SET CONDITIONAL CSS
$g->set_conditional_css($f_conditions);
##########
# EVENTS #
##########
$e["on_insert"] = array("add_", null, true);
$e["on_update"] = array("edit_", null, true);
$e["on_after_insert"] = array("after_insert", null, true);
//$e["on_after_update"] = array("after_update", null, true);
$g->set_events($e);
################
# AFTER INSERT #
################
function after_insert($data)
{
global $g;
global $cc_email;
$j_id = $data['job_id'];
$job_q = $g->get_one("SELECT * FROM tbl_job WHERE job_id ='$j_id'");
$job_num = $job_q['job_number'];
$user_id = $job_q['fk_proj_id'];
####################
# COMPANY CONTACTS # -- ONLY IF THE CONTACT EXISTS
####################
$jc = $g->get_one("SELECT * FROM tbl_contacts WHERE email ='$cc_email'");
if(!empty($jc['contacts_id'])) {
//$insert_id = $g->execute_query("INSERT INTO job_contacts (fk_job_id, fk_contact_id, cont_job_description) VALUES (?,?,?)",array($data["job_id"], $jc['contacts_id'], 'MAIN CONTACT'),"insert_id");
$j_cont = $jc['contacts_id'];
$g->execute_query("INSERT INTO job_contacts (fk_job_id, fk_contact_id, cont_job_description) VALUES ('$j_id','$j_cont','MAIN CONTACT')");
}
################################
# INSERT UNIT 0000 IN ESTIMATE #
################################
$today = date('Y-m-d');
$row = $g->get_one("SELECT * FROM tbl_est_job WHERE fk_job_number='$job_num'");
$op = $row['op'];
$pm = $row['proj_manager'];
$eng = $row['eng_hrs'];
$det = $row['det_hrs'];
$exp = $row['expenses'];
$fab = $row['fabrication'];
$st1 = $row['steel_cost'];
$st2 = $row['steel_cost2'];
$st3 = $row['steel_cost3'];
$sub = $row['subcontract'];
$fre = $row['freight'];
$scn = $row['scanner'];
$mic = $row['misc'];
$cont = $row['contingency'];
$sell = $row['selling_price'];
$eng_cost = $row['eng_cost'];
$g->execute_query("INSERT INTO tbl_est_unit (est_unit, est_desc, est_unit_type, est_fk_job_id, op, proj_manager, eng_hrs, det_hrs, expenses, fabrication, steel_cost, steel_cost2, steel_cost3, subcontractor, misc, freight, selling_price, contingency, eng_cost, est_unit_notes, est_rev_date_unit, est_rev_user_unit, est_rev_flag_unit, scanner, est_diff_po) VALUES ('0000', '$desc', '1', '$j_id', '$op', '$pm', '$eng', '$det', '$exp', '$fab', '$st1', '$st2', '$st3', '$sub', '$mic', '$fre', '$sell', '$cont', '$eng_cost', '', '$today', '$user_id', 1, '$scn', 0)");
}
##########
# ON ADD #
##########
function add_($data)
{
/////////////////////////////////////
// SET COLUMN TO UPPER CASE ON ADD //
/////////////////////////////////////
$data["params"]["job_description"] = strtoupper($data["params"]["job_description"]); //TO UPPER JOB DESCRIPTION
$data["params"]["company_name"] = strtoupper($data["params"]["company_name"]); //TO UPPER COMPANY NAME
$data["params"]["full_name"] = strtoupper($data["params"]["full_name"]); //TO UPPER FULL NAME
$data["params"]["First_name"] = strtoupper($data["params"]["First_name"]); //TO UPPER FIRST NAME
$data["params"]["customer_folder"] = strtoupper($data["params"]["customer_folder"]); //TO UPPER CUSTOMER FOLDER
$data["params"]["job_created_by"] = $uname; //SET CREATED BY NAME
$data["params"]["job_number_tc"] = $data["params"]["job_number"]; //SET JOB TIMECARD = JOB NUMBER
// SET ENDUSER TO ORIGINAL CUSTOMER - NO ENDUSER SET
if (is_null($data["params"]["fk_enduser"]) or $data["params"]["fk_enduser"] == "" or $data["params"]["fk_enduser"] == null) { //
$data["params"]["fk_enduser"] = $data["params"]["fk_customer"];
}
$data["params"]["job_type"] = $data["params"]["job_type_1"]; //SET VIRTUAL COL TO REAL DB COL
unset($data["params"]["job_type_1"]); //UNSET VIRTUAL COL
/////////////////////////
// GLOBAL VARIABLE(S) //
/////////////////////////
global $g;
global $uname;
global $cc_email;
global $conn;
////////////////////////////////////
// SET COLUMN VALUES TO VARIABLES //
////////////////////////////////////
$n = $data["params"]["company_name"];
$zero = $data["params"]["customer_seed"];
$cf = $data["params"]["site_customer_folder"];
$pn = $data["params"]["full_name"];
$dl = $data["params"]["customer_drawinglist"];
$jnum = $data["params"]["job_number"];
$cc_email = $data["params"]["email"];
$fname = $data["params"]["First_name"];
$name = explode(" ", $fname);
$first = $name[0];
$last = $name[1];
$data["params"]["job_open"] = 'O';
$site = $data["params"]["site_name"];
///////////////////////////////////////////////////////
// CHANGE JOB STATUS TO ACTIVE ON WARRANTY, INTERNAL //
///////////////////////////////////////////////////////
if($data["params"]["job_type"] == 'WARRANTY' or $data["params"]["job_type"] == 'INTERNAL') {
$data["params"]["job_status"] = "ACTIVE";
} else {
$data["params"]["job_status"] = "PENDING";
}
////////////////////////////////////////////
// QUERY COMPANY AND PROJECT MANAGER NAME //
////////////////////////////////////////////
$cname = $g->get_one("SELECT * FROM tbl_customer WHERE company_name='$n'");
$cfolder = $g->get_one("SELECT * FROM tbl_customer WHERE customer_folder='$cf'");
$pp = $g->get_one("SELECT * FROM tbl_users WHERE full_name='$pn'");
# THIS IS NOT A VALID CUSTOMER NAME
if($cname['antiquated'] == 1 OR $cfolder['antiquated'] == 1) {
phpgrid_error("Customer name or/and Folder is no longer used");
}
# CHECK IF CUSTOMER EXISTS OR NOT
if (empty($cname['customer_id'])) {
phpgrid_error("customer does not exst, please create a new customer");
}
# CHECK IF THIS IS A NEW CUSTOMER WAITING FOR APPROVAL
if($cname['new_cust'] == 1)
{
phpgrid_error("new customer");
# CUSTOMER DID NOT EXIST - CREATE TEMP TASKS
$tdat = date("Y/m/d h:i:s");
$ttyp = "ONCE";
$tday = "7";
$ttim = "00:00:00";
$ttsk = "CJOB";
$tfid = $data["params"]["job_number"];
$i_id = $g->execute_query("INSERT INTO tbl_tasks_temp (task_create_date, task_type,task_days,task_time,task_task,task_fk_id) VALUES ('$tdat','$ttyp','$tday','$ttim','$ttsk','$tfid')");
$i_id = $g->execute_query("INSERT INTO tbl_tasks_temp (task_create_date, task_type,task_days,task_time,task_task,task_fk_id) VALUEs ('$tdat','ONCE','0123456','00:00:00','PEMAIL','$tfid')");
$i_id = $g->execute_query("INSERT INTO tbl_tasks_temp (task_create_date, task_type,task_days,task_time,task_task,task_fk_id) VALUEs ('$tdat','ONCE','0123456','00:00:00','OEMAIL','$tfid')");
$n_id = $g->execute_query("INSERT INTO tbl_tasks_temp (task_create_date, task_type, task_task, task_fk_id) VALUEs ('$tdat', 'ONCE', 'APPRV','$tfid')");
# ADD NEW CUSTOMER - DATE
unset($data["params"]["fk_customer"]);
$cdate = date("Y-m-d");
$sql = mysqli_query($conn, "INSERT INTO tbl_customer (company_name, new_cust_date, customer_seed, customer_drawinglist) VALUES ('$n', '$cdate', '$zero','$dl')");
$last_id = mysqli_insert_id($conn);
$data["params"]["fk_customer"] = $last_id;
# ADD NEW CUSTOMER SITE STUB
$sql = mysqli_query($conn, "INSERT INTO tbl_customer_sites (sites_fk_customer_id, site_customer_folder, site_name) VALUES ('$last_id', '$cf', '$site')");
$site_id = mysqli_insert_id($conn);
$data["params"]["fk_site_id"] = $site_id;
# IF END USER IS EMPTY
if (empty($data["params"]["enduser"]))
{
# GET COMPANY ID
$c_id = $g->get_one("SELECT * FROM tbl_customer WHERE company_name='$n'");
if(!empty($c_id['customer_id']))
{
# SET ENDUSER USING THE CUSTOMER ID
$cust_id = $c_id['customer_id'];
$data["params"]["fk_enduser"] = $cust_id;
}
}
# CREATE A TASK/CODE FOR "NEW CUSTOMER" APPROVAL WITH DIRECTORY MANAGER(S)
$data["params"]["job_pending"] = 1;
}
else
{
$data["params"]["fk_site_id"] = $data["params"]["customer_site_id"];
// EXISTING CUSTOMER - CREATE TASKS
$tdat = date("Y/m/d h:i:s");
$ttyp = "ONCE";
$tday = "7";
$ttim = "00:00:00";
$ttsk = "CJOB";
$tfid = $data["params"]["job_number"];
$i_id = $g->execute_query("INSERT INTO tbl_tasks (task_create_date, task_type,task_days,task_time,task_task,task_fk_id) VALUES ('$tdat','$ttyp','$tday','$ttim','$ttsk','$tfid')");
$i_ml = $g->execute_query("INSERT INTO tbl_tasks (task_create_date, task_type,task_days,task_time,task_task,task_fk_id) VALUEs ('$tdat','ONCE','0123456','00:00:00','PEMAIL','$tfid')");
$i_ml = $g->execute_query("INSERT INTO tbl_tasks (task_create_date, task_type,task_days,task_time,task_task,task_fk_id) VALUEs ('$tdat','ONCE','0123456','00:00:00','OEMAIL','$tfid')");
$cust_id = $cname['customer_id'];
}
if(empty($data["params"]["fk_site_id"])) {
// ADD SITE TO EXISTING COMPANY
$sql = mysqli_query($conn, "INSERT INTO tbl_customer_sites (sites_fk_customer_id, site_customer_folder, site_name) VALUES ('$cust_id', '$cf', '$site')");
$site_id = mysqli_insert_id($conn);
$data["params"]["fk_site_id"] = $site_id;
}
// --== ?? BELOW CODE NEEDED ?? ==--
////////////////////////////////////////////////////////////////////////////
// GET ID OF NOT SELECTED BUT IN DATABASE (TYPED IN AUTOCOMPLET NOT USED) //
////////////////////////////////////////////////////////////////////////////
// if(!empty($cname['customer_id']))
// {
// $data["params"]["fk_customer"] = $cname['customer_id'];
// $custid = $cname['customer_id'];
// $g->execute_query("UPDATE tbl_customer SET customer_folder='$cf', customer_seed = '$zero', customer_drawinglist = '$dl' WHERE customer_id = '$custid'");
// }
///////////////////////////////////////////
// ADD CONTACT IF CONTACT DOES NOT EXIST //
///////////////////////////////////////////
// $jc = $g->get_one("SELECT * FROM tbl_contacts WHERE email ='$cc_email'");
// if(empty($jc)) {
// $fk_cust = $data["params"]["fk_customer"];
// $g->execute_query("INSERT INTO tbl_contacts (fk_customer_id, First_name, Last_name, email) VALUE ('$fk_cust','$first','$last','$cc_email')");
// }
////////////////////////////////////////////
// INSERT DATA INTO AUTOCOMPLETE DATABASE //
////////////////////////////////////////////
if(!empty($pp['user_id'])) {
$data["params"]["fk_proj_id"] = $pp['user_id'];
}
////////////////////////////////////////////
// INSERT DATA INTO AUTOCOMPLETE DATABASE //
////////////////////////////////////////////
if (empty($pp))
{
// discard posted eq id
unset($data["params"]["fk_proj_id"]);
$sql = mysqli_query($conn, "INSERT INTO tbl_users (full_name) VALUES ('$pn')");
$last_id = mysqli_insert_id($conn);
$data["params"]["fk_proj_id"] = $last_id;
}
#############################
# ESTIMATE DEFAULTS NEW JOB # ------------------------------------------------------------------------------------------------------------------------------------------------------------------
#############################
//////////////////////////////////
// CREATE ESTIMATE JOB DEFAULTS //
//////////////////////////////////
$cidd = $data["params"]["fk_enduser"];
//CHECK IF DEFAULTS ALREADY EXIST (ESTIMATE INFO EXISTS)
$cest = $g->get_one("SELECT * FROM tbl_est_job WHERE fk_job_number='$jnum'");
//CREATE ESTIMATE FOR JOB IF ESTIMATE INFO DOES NOT EXIST
if (empty($cest))
{
//TRY TO FIND A CUSTOMER DEFAULT PRICES
$dev = $g->get_one("SELECT * FROM tbl_est_cust_default WHERE cust_id = '$cidd'");
if (empty($dev))
{
//IF NO CUSTOMER PRICE USE DEFAULT
$dev = $g->get_one("SELECT * FROM tbl_est_default WHERE est_def_id='1'");
}
$op = $dev["op"];
$pm = $dev["proj_manager"];
$eng = $dev["eng_hrs"];
$det = $dev["det_hrs"];
$expenses = $dev["expenses"];
$fab = $dev["fabrication"];
$frt = $dev['freight'];
$scn = $dev["scanner"];
$st1 = $dev["steel_cost"];
$st2 = $dev["steel_cost2"];
$st3 = $dev["steel_cost3"];
$ctr = $dev["controls"];
$sub = $dev["subcontract"];
$mis = $dev["misc"];
$ech = $dev['eng_cost'];
$spc = $dev['selling_price'];
$cnt = $dev['contingency'];
// BASE COST
$g->execute_query("INSERT INTO tbl_est_job
(fk_job_number, op, eng_cost, proj_manager, eng_hrs, det_hrs, expenses, fabrication,
steel_cost, steel_cost2, steel_cost3, controls, subcontract, misc, freight, scanner,
selling_price, contingency)
VALUES ('$jnum', '$op', '$ech', '$pm', '$eng', '$det', '$expenses', '$fab', '$st1', '$st2', '$st3', '$ctr', '$sub',
'$mis', '$frt', '$scn', '$spc', '$cnt')");
// MASTER DEFAULTS
$g->execute_query("INSERT INTO tbl_est_job_master
(fk_job_number, op, eng_cost, proj_manager, eng_hrs, det_hrs, expenses, fabrication,
steel_cost, steel_cost2, steel_cost3, controls, subcontract, misc, freight, scanner,
selling_price, contingency)
VALUES ('$jnum', '$op', '$ech', '$pm', '$eng', '$det', '$expenses', '$fab', '$st1', '$st2', '$st3', '$ctr', '$sub',
'$mis', '$frt', '$scn', '$spc', '$cnt')");
// ADD NEW CUSTOMER TO DEFAULT CUSTOMER RATES ==--
$g->execute_query("INSERT INTO tbl_est_cust_default
(cust_id, op, eng_cost, proj_manager, eng_hrs, det_hrs, expenses, fabrication,
steel_cost, steel_cost2, steel_cost3, controls, subcontract, misc, freight, scanner,
selling_price, contingency)
VALUES ('$cust_id', '$op', '$ech', '$pm', '$eng', '$det', '$expenses', '$fab', '$st1', '$st2', '$st3', '$ctr', '$sub',
'$mis', '$frt', '$scn', '$spc', '$cnt')");
}
/////////////////////////////////////////////////////////////
// UNSET ALL COLUMNS THAT DONOT BELONG TO DEFAULT DATABASE //
/////////////////////////////////////////////////////////////
unset($data["params"]["company_name"]);
unset($data["params"]["full_name"]);
unset($data["params"]["customer_seed"]);
unset($data["params"]["customer_folder"]);
unset($data["params"]["user_id"]);
unset($data["params"]["job_arch_date"]);
unset($data["params"]["enduser"]);
unset($data["params"]["customer_drawinglist"]);
unset($data["params"]["First_name"]);
unset($data["params"]["email"]);
unset($data["params"]["contacts_id"]);
unset($data["params"]["unit_closed"]);
unset($data["params"]["customer_id"]);
unset($data["params"]["site_name"]);
unset($data["params"]["customer_site_id"]);
unset($data["params"]["site_customer_folder"]);
}
##############
# EDIT EVENT #
##############
function edit_($data)
{
/////////////////////////
// GLOBAL VARIABLE(S) //
/////////////////////////
global $g;
global $uname;
global $conn;
/////////////////////////////////////
// SET COLUMN TO UPPER CASE ON ADD //
/////////////////////////////////////
$data["params"]["job_description"] = strtoupper($data["params"]["job_description"]); //TO UPPER JOB DESCRIPTION
$data["params"]["company_name"] = strtoupper($data["params"]["company_name"]); //TO UPPER COMPANY NAME
$data["params"]["full_name"] = strtoupper($data["params"]["full_name"]); //TO UPPER PROJECT MANAGER
$data["params"]["job_number_tc"] = $data["params"]["job_number"];
/////////////////////////////////////////////////////////
// CLEAR CHAR THAT DONT BELONG IN FILENMAE/DESCRIPTION //
/////////////////////////////////////////////////////////
$string = $data["params"]["job_description"];
$str = preg_replace('/[^ \w-]/', '', $string);
$data["params"]["job_description"] = $str;
////////////////////////////////////
// SET COLUMN VALUES TO VARIABLES //
////////////////////////////////////
$pn = $data["params"]["full_name"];
$id = $data["params"]["job_id"];
$pp = $g->get_one("SELECT * FROM tbl_users WHERE full_name='$pn'");
$user = $pp['user_id'];
////////////////////////////////////////////
// INSERT DATA INTO AUTOCOMPLETE DATABASE //
////////////////////////////////////////////
if(!empty($pp['user_id'])) {
$data["params"]["fk_proj_id"] = $pp['user_id'];
$g->execute_query("UPDATE tbl_unit SET fk_unit_proj_id='$user' WHERE fk_job_id='$id' AND unit_po_status='BASE JOB PO'");
}
///////////////////////////////////////////////////////
// MAKE SURE TIMECARDS WORK IF JOB STATUS IS CHANGED //
///////////////////////////////////////////////////////
if($data["params"]["job_status"] == "ACTIVE" || $data["params"]["job_status"] == "PENDING")
{
$my_job = $data["params"]["job_number"];
$g->execute_query("UPDATE tbl_job SET job_number_tc = '$job' WHERE job_id = '$id'");
}
//////////////////////////////
// SAVE ARCHIVE DATE IF SET //
//////////////////////////////
if($data["params"]["job_status"] == "ARCHIVED")
{
$data["params"]["job_arch_date"] = date("Y/m/d");
$data["params"]["job_arch_by"] = $uname;
$pUID = $data["params"]["fk_proj_id"];
//project manager info
$p = $g->get_one("SELECT * FROM tbl_users WHERE user_id = '$pUID'");
$pNmn = $p['full_name'];
$pEml = $p['user_email'];
//logged in user info
$u = $g->get_one("SELECT * FROM tbl_users WHERE user_name = '$uname'");
$aNnm = $u['full_name'];
$aUID = $u['user_id'];
$aEml = $u['user_email'];
$jobnumber = $data["params"]["job_number"];
$descript = $data["params"]["job_description"];
if($data["params"]["fk_proj_id"] != $aUID) {
// SMTP needs accurate times, and the PHP time zone MUST be set
// This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
// Create a new PHPMailer instance
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'einstein02.Kodiak.local';
$mail->Port = 25;
$mail->isHTML(true); // Set email format to HTML
$mail->setFrom('kodiaccess@kodiakgroup.us', $fanme); // Set who the message is to be sent from
$mail->addReplyTo($aEml, $aNnm); // Set an alternative reply-to address
// Send mail that directory is in approval process.
$mail->addAddress($pEml, $pNmn);
$mail->addAddress($aEml, $aNnm);
//Set the subject line
$mail->Subject = $jobnumber . ' Has been marked for archive by: ' . $aNnm . ". Please Review:";
// Message body information (HTML)
$mail->Body = "Job Number: <b>" . $jobnumber . " : " . $descript . "</b> is marked for archive by " . $aNnm . " during routine quarterly housekeeping.<br>";
$mail->Body .= "If there is a reason that this job should not be marked for archive, please let " . $aNnm . " know by replying to this email, that it needs to remain open.<br>";
$mail->Body .= "Either party can then unarchive the Project.<br>";
// Send the message, check for errors
if (!$mail->send()) {
#echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
#echo 'Message sent!';
}
}
#CHANGE ALL UNITS TO INACTIVE ON ARCHIVE
$g->execute_query("UPDATE tbl_unit SET unit_status = 'INACTIVE' WHERE fk_job_id = '$id'");
} else {
$data["params"]["job_arch_date"] = 'NULL';
$data["params"]["job_arch_by"] = 'NULL';
}
/////////////////////////////////////////////////////////////
// UNSET ALL COLUMNS THAT DONOT BELONG TO DEFAULT DATABASE //
/////////////////////////////////////////////////////////////
unset($data["params"]["job_type_1"]);
unset($data["params"]["enduser"]);
unset($data["params"]["company_name"]);
unset($data["params"]["full_name"]);
unset($data["params"]["customer_seed"]);
unset($data["params"]["customer_folder"]);
unset($data["params"]["user_id"]);
unset($data["params"]["fk_enduser"]);
unset($data["params"]["customer_drawinglist"]);
unset($data["params"]["First_name"]);
unset($data["params"]["email"]);
unset($data["params"]["contacts_id"]);
unset($data["params"]["unit_closed"]);
}
#######################
# RENDER GRID (list1) #
#######################
$out = $g->render("list1");
################
# INCLUDE MENU #
################
include("assets/menu.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>
<link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>
<script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
<script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
<!-- Add fancyBox main JS and CSS files -->
<link type="text/css" rel="stylesheet" href="//cdn.jsdelivr.net/fancybox/2.1.4/jquery.fancybox.css" />
<script type="text/javascript" src="//cdn.jsdelivr.net/fancybox/2.1.4/jquery.fancybox.js"></script>
</head>
<?php
################
# DISPLAY GRID #
################
echo $out;
?>
<?php if($bline == 1) { ?>
<!-- GRID LINES -->
<link rel="stylesheet" type="text/css" href="grid.css">
<?php } ?>
<!-- JAVA SCRIPT -->
<script>
function add_dropdown_action(formid)
{
var str = '';
str += "<a href='javascript:void(0)' style='outline:none;' onclick='fx_reload_dropdown(\"customer_site_id\");'><span style='padding:0 5px; color: green; display:inline; padding: 0 7px; margin:0 0 0 5px; top: 2px;' class='ui-icon ui-icon-refresh'></span></a>";
jQuery("#customer_site_id").after(str);
}
// readonly gender conditional function - when return true, field will be readonly
function check_pending(formid)
{
pending = jQuery("input[name=job_pending]:last, select[name=job_pending]:last",formid).val();
pending = parseInt(pending);
if (pending == 1) {
return true; }
}
window.onload = onPageLoad();
//////////////////////////////////////////
// READ COOKIES ON LOAD FOR HIDDEN ROWS //
//////////////////////////////////////////
function onPageLoad() {
$('#tg td:nth-child(3)').show();
$('#tg th:nth-child(3)').show();
};
//global variable checkbox for color ready to archive jobs
var chkbox = 0;
//FILL JOB CUSTOMER
function fill_email(data)
{
jQuery("[name=First_name].FormElement,[name=First_name].editable").val(data.First_name+ " " + data.Last_name);
jQuery("[name=contacts_id].FormElement,[name=contacts_id].editable").val(data.contacts_id);
jQuery("[name=email].FormElement,[name=email].editable").val(data.email);
}
function fill_comp(data)
{
jQuery("[name=customer_name].FormElement,[name=customer_name].editable").val(data.customer_name);
jQuery("[name=customer_id].FormElement,[name=customer_id].editable").val(data.customer_id);
jQuery("[name=fk_customer].FormElement,[name=customer_id].editable").val(data.customer_id);
jQuery("[name=customer_seed].FormElement,[name=customer_seed].editable").val(data.customer_seed);
jQuery("[name=customer_drawinglist].FormElement,[name=customer_drawinglist].editable").val(data.customer_drawinglist);
}
function fill_site(data)
{
jQuery("[name=site_customer_folder].FormElement,[name=site_customer_folder].editable").val(data.site_customer_folder);
jQuery("[name=customer_site_id].FormElement,[name=customer_site_id].editable").val(data.customer_site_id);
jQuery("[name=fk_site_id].FormElement,[name=fk_site_id].editable").val(data.customer_site_id);
}
//FILL END USER
function fill_enduser(data)
{
jQuery("[name=enduser].FormElement,[name=enduser].editable").val(data.enduser);
jQuery("[name=fk_enduser].FormElement,[name=fk_enduser].editable").val(data.customer_id);
}
//FILL PROJECT MANAGER
function fill_form(data)
{
jQuery("[name=full_name].FormElement,[name=full_name].editable").val(data.full_name);
jQuery("[name=fk_proj_id].FormElement,[name=fk_proj_id].editable").val(data.user_id);
}
//FANCYBOX
$(document).ready(function() {
$('.fancybox').fancybox({
'width': '95%',
'height': '95%',
'type': 'iframe',
'fitToView' : true
});
});
$(document).ready(function() {
$('.fancybox1').fancybox({
'autoSize' :false,
'width' :800,
'height' :'80%',
'type' :'iframe',
'iframe': {'scrolling': 'no'}
});
});
$(document).ready(function () {
$(".various").fancybox({
type: "iframe", //<--added
maxWidth: 1280,
maxHeight: 1024,
fitToView: false,
width: '70%',
height: '70%',
autoSize: false,
closeClick: false,
openEffect: 'none',
closeEffect: 'none'
});
})
//FIND NEXT JOB NUMBER (ID)
function fill_next_id(f)
{
var request = {};
request.action = "get_id";
var grid = $("#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 ) {
// fill job_number with ajax return
$("[name=job_number].FormElement").val(data);
}
});
}
function link_select2(id)
{
alert(id);
$('select[name='+id+'].editable, select[id='+id+']').select2(
{
onSelect: function()
{
jQuery(this).trigger('change');
},
templateResult: formatTemplate
});
$(document).unbind('keypress').unbind('keydown');
$('select[name='+id+'].editable, select[id='+id+']').on("select2:select", function (evt) {
var element = evt.params.data.element;
var $element = $(element);
$element.detach();
$(this).append($element);
$(this).trigger("change");
});
}
//illegal characters in filename
function validate_form_once(post,form)
{
var str=[];
var string = post.job_description
if(post.First_name == "") {
return [false, "Project Contact is Required"];
}
if (post.email == "") {
return [false, "Project Contact Email is Required"];
}
for (var i = 0; i < string.length; i++) {
var test = string.charAt(i)
if (test == "\\") {
str[str.length] = "- Illegal Character in JOB DESCRIPTION ( \\ )";
} else if (test == "/") {
str[str.length] = "- Illegal Character in JOB DESCRIPTION ( / )";
} else if (test == "<") {
str[str.length] = "- Illegal Character in JOB DESCRIPTION ( < )";
} else if (test == ">") {
str[str.length] = "- Illegal Character in JOB DESCRIPTION ( > )";
} else if (test == ":") {
str[str.length] = "- Illegal Character in JOB DESCRIPTION ( : )";
} else if (test == '"') {
str[str.length] = '- Illegal Character in JOB DESCRIPTION ( " )';
} else if (test == "|") {
str[str.length] = "- Illegal Character in JOB DESCRIPTION ( | )";
} else if (test == "?") {
str[str.length] = "- Illegal Character in JOB DESCRIPTION ( ? )";
} else if (test == "!") {
str[str.length] = "- Illegal Character in JOB DESCRIPTION ( ! )";
} else if (test == "*") {
str[str.length] = "- Illegal Character in JOB DESCRIPTION ( * )";
}
}
str = str.join("<br>");
if (str.length == 0)
return [true,""];
else
return [false,"Check following errors:<br>"+str];
}
/////////////////////////////////////////
// TOGGLE BUTTON TO SHOW/HIDE END USER //
/////////////////////////////////////////
jQuery(document).ready(function(){
var unit = "<?php echo $uid ?>";
var job = "<?php echo $jid ?>";
var notes = "<?php echo $ecust ?>";
if (notes != 0) {
setTimeout(()=>{
jQuery('#list1').jqGrid('navButtonAdd', '#list1_pager',
{
'caption' : 'Hide End Customer',
'buttonicon' : 'ui-icon-circle-check',
'onClickButton': function()
{
notes = 0;
window.location.href = "?unit=" + unit + "&job=" + job + "&endcust=" + notes
},
'position': 'last'
});
},10);
} else {
setTimeout(()=>{
jQuery('#list1').jqGrid('navButtonAdd', '#list1_pager',
{
'caption' : 'Show End Customer',
'buttonicon' : 'ui-icon-circle-close',
'onClickButton': function()
{
notes=1;
window.location.href = "?unit=" + unit + "&job=" + job + "&endcust=" + notes
},
'position': 'last'
});
},10);
}
});
//////////////////////////////////////////////////
// TOP CHECK BOX FOR SHOW READY TO ARCHIVE JOBS //
//////////////////////////////////////////////////
jQuery(document).ready(function(){
setTimeout(()=>{
var admin = "<?php echo $admin ?>";
var arch = "<?php echo $arch ?>";
var unit = "<?php echo $uid ?>";
var jid = "<?php echo $jid ?>";
// show checkbox in toolbar
if (admin != 0) {
if (arch == 1) {
jQuery('.navtable tr').append('<td><div style="padding-left: 5px; padding-top:0px; float:left"><label><input class="filtermore" type="checkbox" checked /> Archivable Jobs</label></div></td>');
chkbox = 1;
}
if (arch == 0) {
jQuery('.navtable tr').append('<td><div style="padding-left: 5px; padding-top:0px; float:left"><label><input class="filtermore" type="checkbox" /> Archivable Jobs</label></div></td>');
chkbox = 0;
}
jQuery(".filtermore").click(function(){
chkbox = ($(this)[0].checked)?1:0;
grid = jQuery("#list1");
grid[0].p.search = false;
window.location.href = "?unit=" + unit + "&job=" + jid + "&arch=" + chkbox;
});
}
},10);
});
////////////////////////////////////////////////////////////////
// COLOR RED IF JOB IS NOT OPEN IN SALES OR PRODUTION MEETING //
////////////////////////////////////////////////////////////////
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.job_open == 'C' && chkbox == 1) {
jQuery('#list1 tr.jqgrow:eq('+i+')').css('background-image','inherit').css({'background-color':'#FFA390', 'color':'BLACK'});
}
});
}
</script>
<!-- CSS STYLE -->
<style type="text/css">
.ui-jqdialog {
width: 750px !important;
}
tr.focus-row
{
background: #FEE8B0;
color: #F97B22;
}
tr.focus-row a
{
color: #F97B22;
}
/* required for add/edit dialog overlapping */
.fancybox-overlay { z-index:943 !important; }
#editmodlist1.ui-jqdialog { z-index: 942 !important; }
</style>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment