-
-
Save SecheronSA/8ee23bf87543330034db73e1b487a4a1 to your computer and use it in GitHub Desktop.
Timesheetcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include_once("conf/config.php"); | |
include_once('lib/oracle.php'); | |
include(PHPGRID_LIBPATH . "inc/jqgrid_dist.php"); | |
// master grid | |
// Database config file to be passed in phpgrid constructor | |
$db_conf = array( | |
"type" => PHPGRID_DBTYPE, | |
"server" => PHPGRID_DBHOST, | |
"user" => PHPGRID_DBUSER, | |
"password" => PHPGRID_DBPASS, | |
"database" => PHPGRID_DBNAME | |
); | |
$cur_org = $_SESSION['user']->org_id; | |
$employee_id = $_SESSION['user']->user_id; | |
if (isset($_GET['EMPLOYEE_ID'])) | |
{ | |
$employee_id = $_GET['EMPLOYEE_ID']; | |
} | |
if (isset($_GET['PERIOD_NAME'])) | |
{ | |
$period_name = $_GET['PERIOD_NAME']; | |
$period_status = substr($period_name, strpos($period_name, ">") + 1); | |
$period = substr($period_name, 0, strpos($period_name, ">")); | |
} | |
else | |
{ | |
$reqq = "SELECT v.period_name period, v.period_name || '>' || v.status period_name, v.status FROM org_acct_periods_v v,(SELECT MAX (start_date) st_date FROM org_acct_periods_v p WHERE p.organization_id = '" . $cur_org . "' AND p.status = 'Open') o WHERE v.organization_id = '" . $cur_org . "' AND v.start_date = o.st_date "; | |
$defper_req = oracle_query_array($reqq); | |
foreach ($defper_req as $defper_req) | |
{ | |
$period_name = $defper_req["PERIOD_NAME"]; | |
$period_status = $defper_req["STATUS"]; | |
$period = $defper_req["PERIOD"]; | |
} | |
} | |
$_GET['ORG_ID'] = $cur_org; | |
$_GET['PERIOD'] = $period; | |
$_GET['EMPLOYEE_ID'] = $employee_id; | |
if (($_SESSION['admin'] == True) || ($_SESSION['review'] == True)) | |
{ | |
$emplist = "<option value=''></option>"; | |
$reqq = "SELECT person_id,global_name FROM xsech_per_people_v7 e where e.current_employee_flag='Y' and org_id=apps.xxx_utils_sql.get_org_id_from_inv_id (" . $cur_org . ") order by global_name"; | |
$emp_req = oracle_query_array($reqq); | |
foreach ($emp_req as $emp_req) | |
{ | |
$outp = "<option value='" . $emp_req["PERSON_ID"]; | |
if ($emp_req["PERSON_ID"] == $employee_id) | |
{ | |
$outp = $outp . "' selected>"; | |
} | |
else | |
{ | |
$outp = $outp . "'>"; | |
} | |
$emplist = $emplist . $outp . $emp_req["GLOBAL_NAME"] . "</option>"; | |
} | |
$emplist = $emplist . "</select>"; | |
} | |
else | |
{ | |
$emplist = "<option value='" . $employee_id . "' selected>"; | |
$emplist = $emplist . $_SESSION['user']->fullname . "</select>"; | |
} | |
$reqq = "SELECT v.period_name, v.period_name||'>'||p.status per_status FROM apps.org_acct_periods_v p,(SELECT p.period_name FROM apps.org_acct_periods_v p WHERE p.organization_id = " . $cur_org . " AND p.status = 'Open' UNION SELECT distinct h.transaction_period FROM xxx_co_time.projtime_data h where h.employee_id=" . $employee_id . ") v WHERE v.period_name = p.period_name AND p.organization_id = " . $cur_org . " order by (p.period_year * 100 + p.period_number) * DECODE (p.status, 'Open', 10, 1) desc"; | |
$perlist = ""; | |
$outp = ""; | |
$per_req = oracle_query_array($reqq); | |
foreach ($per_req as $per_req) | |
{ | |
$outp = "<option value='" . $per_req["PER_STATUS"]; | |
if ($per_req["PERIOD_NAME"] == $period) | |
{ | |
$outp = $outp . "' selected>"; | |
} | |
else | |
{ | |
$outp = $outp . "'>"; | |
} | |
$perlist = $perlist . $outp . $per_req["PERIOD_NAME"] . "</option>"; | |
} | |
$perlist = $perlist . "</select>"; | |
if ($period_status != 'Open') | |
{ | |
$perlist = $perlist . ' Period closed'; | |
} | |
$g = new jqgrid($db_conf); | |
// set few params | |
$opt = array(); | |
$opt["caption"] = "Time Sheet"; | |
$opt["height"] = ""; | |
$opt["width"] = "760"; | |
$opt["footerrow"] = true; | |
$opt["reloadedit"] = true; // reload after inline edit | |
$opt["multiselect"] = false; | |
$opt["autoid"] = true; | |
$opt["clone"] = false; | |
$opt["rowList"] = array(); | |
$opt["pgbuttons"] = false; | |
$opt["pgtext"] = null; | |
$opt["altRows"] = true; | |
$opt["scroll"] = true; | |
$opt["viewrecords"] = false; | |
$opt["sortname"] = 'WIP_NAME'; | |
$opt["altRows"] = true; | |
$opt["altclass"] = "myAltRowClass"; | |
$opt["globalsearch"] = false; | |
$opt["form"]["position"] = "center"; | |
$opt["footerrow"] = true; | |
// JS events | |
$opt["ondblClickRow"] = "function (id) { grid_dblclick(id); }"; | |
$opt["loadComplete"] = "function (id) { grid_load(id); }"; | |
$opt["onSelectRow"] = "function (id) { grid_select(id); }"; | |
$g->set_options($opt); | |
$g->navgrid["param"]["edit"] = false; | |
$g->navgrid["param"]["add"] = false; | |
// $g->navgrid["param"]["del"] = false; | |
// set database table for CRUD operations | |
$g->select_command = "SELECT record_id, org_id, employee_id,transaction_period, wip_name,wip_op_res_id, transaction_qty, decode(interfaced_flg,'N',decode(p.status ,'Open','Edit','NoEdit'),'E',decode(p.status ,'Open','Edit','NoEdit'),'NoEdit') editflag,decode(interfaced_flg,'N',DECODE (p.status, 'Open', 'Editable', 'NoEdit'),'Y','Interfaced','R','Interfaced','Error') status, interfaced_flg,last_updated_by,created_by FROM projtime_data,org_acct_periods_v p where p.organization_id='" . $cur_org . "' and p.period_name= transaction_period and employee_id=" . $employee_id . " and transaction_period='" . $period . "'"; | |
$g->table = "PROJTIME_DATA"; | |
$col = array(); | |
$col["title"] = "record_ID"; | |
$col["name"] = "RECORD_ID"; | |
$col["width"] = "4"; | |
$col["editable"] = false; | |
$col["hidden"] = true; | |
$col["export"] = false; | |
$col["autoid"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "created_by"; | |
$col["name"] = "CREATED_BY"; | |
$col["width"] = "4"; | |
$col["editable"] = true; | |
$col["hidden"] = true; | |
$col["export"] = false; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "last_updated_by"; | |
$col["name"] = "LAST_UPDATED_BY"; | |
$col["width"] = "4"; | |
$col["editable"] = true; | |
$col["hidden"] = true; | |
$col["export"] = false; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "org code"; | |
$col["name"] = "ORG_ID"; | |
$col["width"] = "4"; | |
$col["editable"] = true; | |
$col["hidden"] = true; | |
$col["export"] = false; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "editflag"; | |
$col["name"] = "EDITFLAG"; | |
$col["editable"] = false; | |
$col["hidden"] = true; | |
$col["edittype"] = "checkbox"; | |
$col["editoptions"] = array( | |
"value" => "Edit:NoEdit" | |
); | |
//$col["show"] = array("list"=>true, "add"=>true, "edit"=>true, "view"=>false); | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "InterfacedFLG"; | |
$col["name"] = "INTERFACED_FLG"; | |
$col["editable"] = true; | |
$col["hidden"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "ID"; | |
$col["name"] = "EMPLOYEE_ID"; | |
$col["width"] = "4"; | |
$col["editable"] = true; | |
$col["hidden"] = true; | |
$col["export"] = false; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "transaction_period"; | |
$col["name"] = "TRANSACTION_PERIOD"; | |
$col["width"] = "15"; | |
$col["editable"] = true; | |
$col["hidden"] = true; | |
$col["export"] = false; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Discrete Job"; | |
$col["name"] = "WIP_NAME"; | |
$col["width"] = "40"; | |
$col["editable"] = true; | |
$col["search"] = true; | |
$col["editrules"] = array( | |
"required" => true, | |
"readonly" => true, | |
"readonly-when" => array( | |
"EDITFLAG", | |
"==", | |
"NoEdit" | |
) | |
); | |
$col["edittype"] = "select"; | |
// $col["formatter"] = "select"; | |
$cur = $g->get_dropdown_values("select wip_name as k, upper(wip_name) as v from xsech_projtime_wip where organization_id='" . $cur_org . "' and status_type in (3,4) order by 2"); | |
$col["editoptions"] = array( | |
"value" => ":;" . $cur, | |
"onchange" => array( | |
"update_field" => "WIP_OP_RES_ID", | |
"sql" => "select WIP_OP_RES_ID as k, OP_RESOURCE as v from xsech_projtime_res where xsech_projtime_res.organization_id='" . $cur_org . "' and WIP_OP_RES_ID in (select WIP_OP_RES_ID from xsech_projtime_wip_resources where organization_id='" . $cur_org . "' and wip_name='{WIP_NAME}') " | |
) | |
); | |
$col["searchoptions"]["sopt"] = array( | |
"cn" | |
); | |
$col["formatoptions"] = array( | |
"value" => ":;" . $cur | |
); | |
$col["export"] = false; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Resource"; | |
$col["name"] = "WIP_OP_RES_ID"; | |
$col["width"] = "80"; | |
$col["editable"] = true; | |
$col["search"] = false; | |
$col["editrules"] = array( | |
"required" => true, | |
"readonly" => true, | |
"readonly-when" => array( | |
"EDITFLAG", | |
"==", | |
"NoEdit" | |
) | |
); | |
$col["edittype"] = "select"; | |
$col["formatter"] = "select"; | |
$cur = $g->get_dropdown_values("select WIP_OP_RES_ID as k, OP_RESOURCE as v from xsech_projtime_res where organization_id='" . $cur_org . "' "); | |
$col["editoptions"] = array( | |
"value" => $cur | |
); | |
$col["searchoptions"]["sopt"] = array( | |
"cn" | |
); | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "# Min"; | |
$col["name"] = "TRANSACTION_QTY"; | |
$col["width"] = "30"; | |
$col["editable"] = true; | |
$col["search"] = false; | |
// $col["formatter"] = "number"; | |
// $col["formatoptions"] = array("thousandsSeparator" => "", | |
// "decimalSeparator" => ".", | |
// "decimalPlaces" => 0); | |
$col["editrules"] = array( | |
"required" => true, | |
"readonly" => true, | |
"readonly-when" => array( | |
"EDITFLAG", | |
"==", | |
"NoEdit" | |
) | |
); | |
$col["align"] = "right"; | |
$col["export"] = false; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Status"; | |
$col["name"] = "STATUS"; | |
$col["search"] = false; | |
$col["align"] = "center"; | |
$col["width"] = "30"; | |
$col["editable"] = false; | |
$col["editrules"] = array( | |
"required" => true, | |
"readonly" => true | |
); | |
$col["hidden"] = false; | |
$cols[] = $col; | |
$g->set_columns($cols); | |
if ($period_status != 'Open') | |
{ | |
$g->set_actions(array( | |
"add" => false, // allow/disallow add | |
"edit" => true, // allow/disallow edit | |
"inlineadd" => false, // allow/disallow edit | |
"clone" => false, // allow/disallow delete | |
"delete" => true, // allow/disallow delete | |
"view" => true, // allow/disallow view | |
"rowactions" => true, // show/hide row wise edit/del/save option | |
"export" => false, // show/hide export to excel option | |
"autofilter" => false, // show/hide autofilter for search | |
"search" => "advanced" | |
)); | |
} | |
else | |
{ | |
$g->set_actions(array( | |
"add" => true, // allow/disallow add | |
"edit" => true, // allow/disallow edit | |
"inlineadd" => true, // allow/disallow edit | |
"clone" => false, // allow/disallow delete | |
"delete" => true, // allow/disallow delete | |
"view" => true, // allow/disallow view | |
"rowactions" => true, // show/hide row wise edit/del/save option | |
"export" => false, // show/hide export to excel option | |
"autofilter" => false, // show/hide autofilter for search | |
"search" => "advanced" | |
)); | |
} | |
$e = array(); | |
$e["on_insert"] = array( | |
"add_row", | |
null, | |
true | |
); | |
$e["on_update"] = array( | |
"update_delete_row", | |
null, | |
true | |
); | |
$e["on_delete"] = array( | |
"update_delete_row", | |
null, | |
true | |
); | |
$g->set_events($e); | |
function add_row(&$data) | |
{ | |
$qty = $data["params"]["TRANSACTION_QTY"]; | |
if ( is_numeric ($qty) == false ){ | |
phpgrid_error("#Min: Invalid Number "); | |
} | |
$id = intval($_GET["rowid"]); | |
$data["params"]["EMPLOYEE_ID"] = intval($_GET["EMPLOYEE_ID"]); | |
$data["params"]["TRANSACTION_PERIOD"] = addslashes($_GET["PERIOD"]); | |
$data["params"]["ORG_ID"] = intval($_GET["ORG_ID"]); | |
$data["params"]["INTERFACED_FLG"] = 'N'; | |
$data["params"]["CREATED_BY"] = intval($_SESSION['user']->user_id); | |
$data["params"]["LAST_UPDATED_BY"] = intval($_SESSION['user']->user_id); | |
} | |
function update_delete_row(&$data) | |
{ | |
$qty = $data["params"]["TRANSACTION_QTY"]; | |
if ( is_numeric ($qty) == false && $data["params"]["TRANSACTION_QTY"] <> "" ){ | |
phpgrid_error("#Min: Invalid Number "); | |
} | |
$check_sql="SELECT interfaced_flg as st FROM projtime_data where record_id=".$data["params"]["RECORD_ID"]; | |
$check_res= oracle_query_array($check_sql); | |
if (!empty($check_res)) { | |
$chk_status = $check_res[0]["C"]; | |
} | |
if ( $data["params"]["INTERFACED_FLG"] == 'Y' || $data["params"]["INTERFACED_FLG"] == 'R') | |
phpgrid_error("Update not allowed: Data already interfaced to Oracle."); | |
$check_sql="SELECT NVL (status, 'Closed') as c FROM org_acct_periods_v v, (SELECT ".intval($_GET["ORG_ID"])." as org_id FROM DUAL) d WHERE v.organization_id(+) = d.org_id AND v.period_name(+) = '".addslashes($_GET["PERIOD"])."'"; | |
$check_res= oracle_query_array($check_sql); | |
if (!empty($check_res)) { | |
$chk_status = $check_res[0]["C"]; | |
} | |
if ( $chk_status != 'Open') | |
phpgrid_error("Update not allowed: Period specified is not opened."); | |
$id = intval($_GET["rowid"]); | |
$data["params"]["LAST_UPDATED_BY"] = intval($_SESSION['user']->user_id); | |
} | |
// render grid | |
$out = $g->render("list1"); | |
?> | |
<?php | |
include(MYLIB . 'header.php'); | |
?> | |
<script> | |
function resubmit() | |
{ | |
document.timesheet.action="index.php?page=timesheet"; | |
document.timesheet.submit(); | |
} | |
</script> | |
<div style="float:left; width:100%;"> | |
<form name=timesheet > | |
<h3>Employee : <select name=EMPLOYEE_ID onchange="resubmit()"> | |
<?php | |
echo $emplist; | |
?> | |
Period: <select name="PERIOD_NAME" onchange="resubmit()"> | |
<?php | |
echo $perlist; | |
?> | |
</h3></form> | |
<style> | |
/* alternate row color */ | |
.myAltRowClass { background-color: #F1F1F1 !important; background-image: url('') !important; } | |
/* adjust highlight row option */ | |
.ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight | |
{ | |
background: #fbec88 url("images/ui-bg_flat_55_fbec88_40x100.png") repeat-x scroll 50% 50% !important; | |
} | |
</style> | |
<?php | |
echo $out; | |
?> | |
<script> | |
function grid_dblclick(id) | |
{ | |
var grid = $('#list1'); | |
var data = grid.getRowData(id); | |
if (data.EDITFLAG == 'NoEdit') // view only | |
{ | |
return; | |
} | |
else | |
jQuery(this).jqGrid('editGridRow', id, <?php | |
echo json_encode_jsfunc($g->options["edit_options"]); | |
?>); | |
} | |
function grid_load() | |
{ | |
var grid = $('#list1'); | |
var sum = grid.jqGrid('getCol', 'TRANSACTION_QTY', false, 'sum'); | |
// set in footer under another column 'id' | |
grid.jqGrid('footerData','set', {TRANSACTION_QTY: 'Total: ' + sum}); | |
var rowids = grid.getDataIDs(); | |
var columnModels = grid.getGridParam().colModel; | |
// check each visible row | |
for (var i = 0; i < rowids.length; i++) | |
{ | |
var rowid = rowids[i]; | |
var data = grid.getRowData(rowid); | |
if (data.EDITFLAG == 'NoEdit') // view only | |
{ | |
jQuery("tr#"+rowid).addClass("not-editable-row"); | |
jQuery("tr#"+rowid+" td[aria-describedby$='_act']").html("-"); | |
} | |
} | |
// for multiselect check all, list1 is grid id | |
$("#cb_list1").click(function(){ | |
var selr_one = grid.getGridParam('selrow'); | |
var selr = []; | |
selr = grid.jqGrid('getGridParam','selarrrow'); // array of id's of the selected rows when multiselect options is true. Empty array if not selection | |
if (selr.length < 2 && selr_one) | |
selr[0] = selr_one; | |
for (var x=0;x < selr.length;x++) | |
{ | |
rowid = selr[x]; | |
var data = grid.getRowData(rowid); | |
if (data.EDITFLAG == 'NoEdit') // view only | |
{ | |
jQuery("#list1_pager #edit_list1, #list1_toppager #edit_list1").addClass("ui-state-disabled"); | |
jQuery("#list1_pager #del_list1, #list1_toppager #del_list1").addClass("ui-state-disabled"); | |
} | |
} | |
}); | |
} | |
function grid_select(id) | |
{ | |
var grid = $('#list1'); | |
var rowid = grid.getGridParam('selrow'); | |
if (rowid) | |
{ | |
var data = grid.getRowData(rowid); | |
if (data.EDITFLAG == 'NoEdit') // view only | |
{ | |
jQuery("#list1_pager #edit_list1, #list1_toppager #edit_list1").addClass("ui-state-disabled"); | |
jQuery("#list1_pager #del_list1, #list1_toppager #del_list1").addClass("ui-state-disabled"); | |
} | |
else | |
{ | |
jQuery("#list1_pager #edit_list1, #list1_toppager #edit_list1").removeClass("ui-state-disabled"); | |
jQuery("#list1_pager #del_list1, #list1_toppager #del_list1").removeClass("ui-state-disabled"); | |
} | |
} | |
} | |
</script> | |
<?php | |
include(MYLIB . 'footer.php'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment