<?php

/* $Id: SelectCustomer.php 7133 2015-02-07 03:23:51Z daintree $*/

include('includes/session.inc');
$Title = _('Project Management/Job Costing');
include('includes/header.inc');
include('includes/SQL_CommonFunctions.inc');
echo '<link href="' . $RootPath . '/css/evergreen2'.'/default.css" rel="stylesheet" type="text/css" media="screen"/>';

 
	echo '<div class="col-sm-9">';
		//echo '<div class="aflpanel" style="margin-bottom:10px">';
		$userid = $_SESSION['UserID'];

if ($userid == 'admin' || $userid == 'ravinesh' || $userid == 'riga' ) { 
	
	
    include('xcrud/xcrud.php');
    $xcrud = Xcrud::get_instance();
    $xcrud->table('projectdetails');

    $xcrud->default_tab('Project info');
	$xcrud->table_name('Project Management/Job Costing/WIP Processing');
	//Xcrud_config::$editor_url = dirname($_SERVER["SCRIPT_NAME"]).'/editors/ckeditor/ckeditor.js'; 
	$xcrud->disabled('age');
	//$xcrud->column_name('budgeted_total_price','Contract Value(VEP)');
	//$xcrud->label('budgeted_total_price','Contract Value(VEP)');
	$xcrud->unset_numbers();
	$xcrud->show_primary_ai_column(true);
	$xcrud->order_by('projectid','desc');
	//$xcrud->columns('projectid',false);
	$xcrud->column_name('projectid','Projectid/jobno');
	$xcrud->change_type('project_type','select','Small Jobs','Small Jobs,Contract');
	
	//$xcrud->set_attr('project_type',array('onfocus'=>'alert("Hello Man!"'));
	//$xcrud->relation('divisionid','division','divisionid','name');
	//$xcrud->relation('department','department','departmentid','departmentname');
	$xcrud->relation('customer','debtorsmaster','debtorno','name');
$xcrud->relation('branch','custbranch','debtorno','brname','','','','','','debtorno','customer');
   $xcrud->relation('sys_account_number','debtoraccount','account_number','account_number','','','','','','debtorno','customer');
	$xcrud->column_pattern('projectid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{projectid}">{value}</a>');
	$xcrud->relation('project_manager','employeemaster','employeeid','full_name');
	$xcrud->relation('sales_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Sales'));
$xcrud->relation('cogs_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Cost of Goods Sold'));
	//$xcrud->column_name('margin','Margin-(Percentage)');
    $xcrud->change_type('status','select','Setup','Setup,Tender Yet to be Awarded,Quoted,Approved,Cancelled,Lost bid, Won Bid,Project Started');
$xcrud->relation('department','department','departmentname','departmentname');
$xcrud->before_insert('updateaccountnumber','functionsproject.php');
$xcrud->before_update('updateaccountnumber','functionsproject.php');
$userid = $_SESSION['UserID'];
$xcrud->pass_var('managed_by',$userid);

//$xcrud->before_update('getdepartment','functionsprojectbudget.php');
	//$xcrud->before_insert('getdepartment','functionsprojectbudget.php');
	//$xcrud->columns('budgeted_profit',true);
	//$xcrud->subselect('Budgeted Profit','{budgeted_total_price}-{budgeted_total_cost}');
	//$totalprice = $xcrud->subselect('profit','{budgeted_total_price}-{budgeted_total_cost}');
	//$xcrud->highlight('Budgeted Profit','>','0','yellow');
	//$xcrud->highlight('Budgeted Profit','<','0','red');
	
	//$xcrud->column_callback('budgeted_profit','profit','functionsprojectbudget.php');
	//		$db8000 = Xcrud_db::get_instance();
	 //   $query = "SELECT projectid, budgeted_total_cost,budgeted_total_price,budgeted_profit
				   			  
		//          FROM projectdetails";
				  
				  
				  	 	   
        
    //    $db8000 ->query($query);
     //   $out8000  = $db8000 ->result();
      //  foreach($out8000  as $output8000){
       //     $totalbudgetedcost = $output8000 ['budgeted_total_cost'];
		//	$totalbudgetedprice = $output8000 ['budgeted_total_price'];
			
		//	$profit = $totalbudgetedprice - $totalbudgetedcost;
			
			
	
	
	//$query2 = "UPDATE projectdetails SET budgeted_profit = '" . $profit."'";
	//$db8000->query($query2);
			
	//	} 
	
	
	
	
	//1.5 level
	$projectattachment = $xcrud->nested_table('Project/Contract Attachements','projectid','projectattachments','projectid');
	
	$projectattachment->change_type('file', 'file', '', array('not_rename'=>true));
	
    $projectcosting = $xcrud->nested_table('Project Costing/Budgeting','projectid','projectcosting','projectid'); // 2nd level
	
	//$projectcosting->unset_numbers();
	$projectcosting->table_name('Project/Contract Budget Costing');
	$projectcosting->disabled('projectid');
     $projectcosting->show_primary_ai_column(true);
 
$projectcosting->column_name('projectid','Job No:');
$projectcosting->label('projectid','Job No:');
$projectcosting->column_name('pcid','Costing No:');
//$projectcosting->fields('budgeted_material,budgeted_labor,budgeted_others,budgeted_total_cost,contractvalue1,contractvalue2,contract_value,contract_vip',true);
//$projectcosting->columns('budgeted_material,budgeted_labor,budgeted_others,budgeted_total_cost,contractvalue1,contractvalue2,contract_value,contract_vip',true);
$projectcosting->label('pcid','Costing No:');
 //$projectcosting->before_insert('getprojectname','functionsprojectbudget.php');
//$projectcosting->before_update('getprojectname','functionsprojectbudget.php');
//$projectcosting->before_list('getbudgetedtotals','functionsprojectbudget.php');
$projectcosting->column_pattern('pcid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{pcid}">{value}</a>');
//$projectcosting->change_type('GL_category','select','All','All,Access Systems,Alarm,Annual Survey,Brigade,CCTV,Fire Extinguisher,ID Card,Metabilt Door,Service Fees,Others,Sprinkler');


$projectcosting->change_type('status','select','drafting','drafting,approved costing,cancelled costing,sent quotation,quote accepted by customer,quote not accepted,job started, job completed');

//$projectcosting->change_type('contract_vip,budgeted_material,budgeted_others,budgeted_labor,contract_value, budgeted_total_cost,estimated_profit', 'price', '0', array('prefix'=>'$'));
//$projectcosting->subselect('Budgeted Profit','{contract_value}-{budgeted_total_cost}');
//$projectcosting->load_view('edit','projectcosting.php');
//$projectcosting->load_view('create','projectcosting.php');
$projectcosting->order_by('pcid','desc');

 $projectcosting->button('JCAutoCreateQuote1.php?pcid={pcid}&projectid={projectid}', 'Create Quote','glyphicon glyphicon-list-alt');
    $projectcostingdetail = $projectcosting->nested_table('Job Costing','pcid','projectcostingdetail','pcid');
   $projectcostingdetail->table_name('Costing and Pricing For Materials, Labour & Other Expenses');
$projectcostingdetail->relation('sales_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Sales'));
$projectcostingdetail->relation('cogs_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Cost of Goods Sold'));
$projectcostingdetail->column_pattern('projectcostingid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{projectcostingid}">{value}</a>');
//$projectcostingdetail->relation('job_costing_sheet_category','jc_stockcat','jsstockcatid','name');
//	$projectcostingdetail->relation('product_details_nonstock','jobcostingsheet','id',array('code','description'),'','','','','','jsstockcatid','job_costing_sheet_category');
//$projectcostingdetail->relation('unit_price','jobcostingsheet','id','landing_cost','','','','','','id','product_details_nonstock');
$projectcostingdetail->unset_csv();
$projectcostingdetail->unset_print();
$projectcostingdetail->show_primary_ai_column(true);
//stock

//$projectcostingdetail->relation('stock_details','stockmaster','stockid',array('stockid','description'),'','','','','','categoryid','job_costing_sheet_category');
//$projectcostingdetail->relation('stock_unit_cost','stockmaster','stockid','materialcost','','','','','','stockid','stock_details');

//$projectcostingdetail->fields('nonstockprice,stockprice,nonstockname,stockname',true);
//$projectcostingdetail->columns('nonstockprice,stockprice,nonstockname,stockname',true);
	$projectcosting->column_width('projectid','200px');
    $projectcostingdetail->change_type('cost_type','select','materials','materials,labour,others');
	//$projectcostingdetail->before_update('calculateprices','functionsprojectbudget.php');
	//$projectcostingdetail->before_insert('calculateprices','functionsprojectbudget.php');
	//$projectquote->set_attr('uom',array('onfocus'=>'myFunction()'));
	$projectcostingdetail->sum('total_cost,price');
	$projectcostingdetail->fields('entered_by',true);
$projectcostingdetail->label('price','Price VEP');
$projectcostingdetail->column_name('price','Price VEP');
$projectcostingdetail->column_name('pcid','Costing No:');
$projectcostingdetail->label('pcid','Costing No:');
 $projectcostingdetail->fields('pcid',true);
 $projectcostingdetail->columns('pcid',true);
//$projectcostingdetail->disabled('total_cost,price');
//$projectcostingdetail->column_name('unit_price','Non-Stock Unit Cost:');
//$projectcostingdetail->label('unit_price','Non-Stock Unit Cost:');
//$projectcostingdetail->change_type('other_description','select','CONTINGENCY','CONTINGENCY,BOARD/COUNTRY,MEALS,AIR/TRAVEL,VEHICLE,OTHER,A.T.S FEES,SCAFFOLDING,SHROULD,INDEX ENGRAVING,SHEDS,FREIGHT,CONCRETE CUT/BUILDERS,COMPRESSOR,SITE WELDING,12 MONTHS MAINTENANCE,BONDS,FPIS INSPECTION/ICONZ,AS BUILTS/MANUALS');

//$projectcostingdetail->column_name('stockprice','Stock Unit Sales Price:');
//$projectcostingdetail->label('stockprice','Stock Unit Sales Price:');

///$projectcostingdetail->column_name('nonstockprice','Non Stock Unit Sales Price:');
////$projectcostingdetail->label('nonstockprice','Non Stock Unit Sales Price:');
//$projectcostingdetail->column_name('nonstocknarrative','Non Stock Narration:');
//$projectcostingdetail->label('nonstocknarrative','Non Stock Narration:');

//$projectcostingdetail->column_name('stocknarrative','Stock Narration:');
//$projectcostingdetail->label('stocknarrative','Stock Narration:');


$projectcostingdetail->label('margin','Margin %');
$projectcostingdetail->pass_default('margin','40');
$projectcostingdetail->column_name('margin','Margin %');
$projectcostingdetail->change_type('total_cost,price,unit_price', 'price', '0', array('prefix'=>'$'));
//$projectcostingdetail->change_type('uom','select','each','each,hours,carton,bag,kg,litre,length,metres,feet');
$projectcostingdetail->before_update('updatebudgettotals','functionsprojectbudget.php'); 
$projectcostingdetail->before_insert('updatebudgettotals','functionsprojectbudget.php');
	



//$projectcostingdetail->relation('labor_type','jc_labortype','labortypeid','name');
//$projectcostingdetail->relation('labor_rate','jc_labortype','rate','rate','','','','','','labortypeid','labor_type');

$projectcostingdetail->show_primary_ai_column(true);
      //$projectquote->load_view('list','projectcosting.php');
	//$xcrud->pass_var('budgeted_total_cost', $sum);
	
	//$totalcostoverall = $projectcosting->sum('total_cost');
	
	
	
	
     // $xcrud->pass_var('budgeted_total_cost', $totalcostoverall);
	 
   // $xcrud->pass_var('budgeted_total_cost', $sum);
	
	
   //$projectactualperiod= $xcrud->nested_table('Actual Periods','projectid','projectactualperiod','projectid'); // 2nd level 2
  // $projectactualperiod->default_tab('Actual Period');
	//$projectactualperiod->table_name('Actual Project Costing');
	//$projectactualperiod->disabled('projectid,actual_material_cost,actual_labor_cost,actual_total_cost,sales_ratio,sales_revenue,margin');
	//$projectactualperiod->change_type('status','select','Setup','Setup,Quoted,Approved,Cancelled,Lost bid, Won Bid,Project Started');
	//$projectactualperiod->unset_numbers();
	//$projectactualperiod->show_primary_ai_column(true);

	
	//project stock

//$projectstock= $xcrud->nested_table('Project Stock Usage','projectid','project_stock','projectid'); // 2nd level 2
   //$projectstock->table_name('Stock Transfered to this Project');
	 
    $quotation = $xcrud->nested_table('Quotations','projectid','salesorders','job_no'); // 3rd level
 //$quotation->where('quotation=',1);
$quotation->label('orderno','Quote No');

$quotation->column_pattern('orderno', '<a href="#" class="xcrud-action" data-task="view" data-primary="{orderno}">{value}</a>');

$quotation->unset_add();
		 $quotation->unset_edit();
			    $quotation->unset_remove();

 $quotation->fields('orderno,amount,quotedate,preparedby,status',false);
 $quotation->columns('orderno,amount,quotedate,preparedby,status',false);
$quotation->table_name('Quotations');
$quotation->button('JCPrintQuote.php?orderno={orderno}', 'Re-Print Quote','glyphicon glyphicon-download-alt','approve');
$quotation->button('JCEmailQuote.php?orderno={orderno}', 'Email Quote','glyphicon glyphicon-envelope','payslipemail');
$quotation->button('JCAutoCreateInvoice.php?orderno={orderno}', 'Convert to Invoice','glyphicon glyphicon-list-alt','payslip');

	      $salesorderdetails = $quotation->nested_table('Salesdetails','orderno','salesorderdetails','orderno');
			  $salesorderdetails->unset_add();
			   $salesorderdetails->unset_edit();
			   $salesorderdetails->unset_remove();
$salesorderdetails->table_name('Quotation Line item Details');
     $salesorderdetails->fields('stkcode,stock_name,qtyinvoiced,unitprice,quantity,discountpercent,narrative,total',false);
 $salesorderdetails->columns('stkcode,stock_name,qtyinvoiced,unitprice,quantity,discountpercent,narrative,total',false);
$salesorderdetails->subselect('total','{unitprice}*{quantity}');
$salesorderdetails->sum('total');
$salesorderdetails->change_type('total,unitprice', 'price', '0', array('prefix'=>'$','decimals'=>'2'));

//invoices for reprinting
  $invoices = $xcrud->nested_table('Invoices from Quotes','projectid','debtortrans','projectid'); // 3rd level
 //$invoices->where('quotation=',0);

//$invoices->column_pattern('orderno', '<a href="#" class="xcrud-action" data-task="view" data-primary="{orderno}">{value}</a>');
$invoices->unset_add();
		 $invoices->unset_edit();
			    $invoices->unset_remove();

 $invoices->fields('transno,order_,trandate,ovamount,vat,total_vip,alloc,ptax,retention',false);
 $invoices->columns('transno,order_,trandate,ovamount,vat,total_vip,alloc,ptax,retention',false);
$invoices->label('transno','Invoice no:');
$invoices->label('trandate','Dated:');
$invoices->label('order_','Quote No');
$invoices->table_name('Invoiced ');
$invoices->button('JCPrintInvoice.php?orderno={order_}&transno={transno}', 'Re-Print Invoice','glyphicon glyphicon-download-alt','westpac');
$invoices->button('JCEmailInvoice.php?orderno={order_}&transno={transno}', 'Email Invoice','glyphicon glyphicon-envelope','payslipemail');
$invoices->subselect('vat','{ovamount}*0.09');
	      
$invoices->subselect('total_vip','{ovamount}*1.09');

$invoices->sum('ovamount,vat,total_vip');
$invoices->change_type('ovamount,vat,total_vip', 'price', '0', array('prefix'=>'$','decimals'=>'2'));


    $purchaseorders = $xcrud->nested_table('Actual Material Cost Info','projectid','contractcharges','contractref'); // 3rd level
	        
			   $purchaseorders->unset_add();
			    $purchaseorders->unset_edit();
			    $purchaseorders->unset_remove();
				$purchaseorders->show_primary_ai_column(false);
 $purchaseorders->change_type('amount', 'price', '0', array('prefix'=>'$'));
			  $purchaseorders->sum('amount');
$purchaseorders->fields('transtype,transno',true);
 $purchaseorders->columns('transtype,transno',true);
$purchaseorders->label('contractref','Project/Job No');
$purchaseorders->column_name('contractref','Project/Job No');

//$purchaseorders->column_width('contractref','10%'); 
//$purchaseorders->column_width('date','20%'); 
//$purchaseorders->column_width('amount','10%'); 
$purchaseorders->column_width('narrative','80%'); 
//$purchaseorders->column_width('anticipated','10%'); 

    $timesheet = $xcrud->nested_table('Actual Labour Cost Info','projectid','techniciantimesheet','job_no'); // 4th level
	
	 $timesheet->unset_add();
			$timesheet->unset_edit();
			 $timesheet->unset_remove();
$timesheet->show_primary_ai_column(true);
     $timesheetdetails = $timesheet ->nested_table('Employee Timesheet','techtimeid','techniciantimesheetdetails','techtimeid');

$timesheetdetails->unset_add();
			$timesheetdetails->unset_edit();
			 $timesheetdetails->unset_remove();

$timesheetdetails->table_name('Technician Scheduling hours');
    $timesheetdetails->relation('employeeid','employeemaster','employeeid',array('employeeid','full_name'));
	
	//$techtimesheetdetails->show_primary_ai_column(true);
	
	//$techtimesheetdetails->after_insert('checkpublicholiday','functionstechtimesheet.php');
	//$techtimesheetdetails->after_update('checkpublicholiday','functionstechtimesheet.php');
	$progressive = $xcrud->nested_table('Progressive Billing','projectid','progressive_billing','projectid'); // 6th level
	$progressive->change_type('actual_material,actual_labor,actual_others,total_actual_cost,billing_amount_vep,billing_amount_vip', 'price', '0', array('prefix'=>'$'));

 $progressive->change_type('status','select','drafting','drafting,approved,invoiced,sent email,paid');
//$progressive->pass_default('margin','40');
$progressive->disabled('actual_material,actual_labor');
$progressive->relation('costing_no','projectcosting','pcid',array('pcid','name' ),array('projectid' => '{projectid}'));
$progressive->before_update('actualcosting','functionsprojectbudget.php'); 
$progressive->before_insert('actualcosting','functionsprojectbudget.php');
	$progressive->button('ProgressiveInvoicing.php?id={pgid}&projectid={projectid}', 'Raise Invoice','glyphicon glyphicon-list-alt');
$progressive->column_pattern('pgid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{pgid}">{value}</a>');

$adjustments = $progressive->nested_table('Cost Adjustments','pgid','projectadjustments','pgid'); // 6th level
	 //$adjustments->unset_add();
			$adjustments->unset_edit();
			$adjustments->unset_remove();
$adjustments->change_type('sector','select','Project Manager','Project Manager,Finance Team');
$adjustments->change_type('amount', 'price', '0', array('prefix'=>'$'));
$adjustments->disabled('costed_by');
   $adjustments->pass_var('costed_by',$userid);
$adjustments->before_update('actualcostadjustments','functionsprojectbudget.php'); 
$adjustments->before_insert('actualcostadjustments','functionsprojectbudget.php');

$stock = $xcrud->nested_table('Stock Usage','projectid','project_stock','projectid'); // 6th level
$stock->unset_edit();
$stock->unset_remove();
$stock->unset_add();
    echo $xcrud->render();
	
	

}
elseif ($userid == 'schand' || $userid == 'losa' || $userid == 'sachin' ) {
 include('xcrud/xcrud.php');
    $xcrud = Xcrud::get_instance();
    $xcrud->table('projectdetails');
$xcrud->where('department', 'Fire-Suva');
    $xcrud->default_tab('Project info');
	$xcrud->table_name('Project Management/Job Costing/WIP Processing');
	//Xcrud_config::$editor_url = dirname($_SERVER["SCRIPT_NAME"]).'/editors/ckeditor/ckeditor.js'; 
	$xcrud->disabled('age,department');
$userid = $_SESSION['UserID'];
$xcrud->pass_default('department','Fire-Suva');
$xcrud->pass_var('department','Fire-Suva');
$xcrud->pass_var('managed_by',$userid);
	$xcrud->unset_numbers();
	$xcrud->show_primary_ai_column(true);
	$xcrud->order_by('projectid','desc');
	//$xcrud->columns('projectid',false);
	$xcrud->column_name('projectid','Projectid/jobno');
	$xcrud->change_type('project_type','select','Small Jobs','Small Jobs,Contract');
	
	//$xcrud->set_attr('project_type',array('onfocus'=>'alert("Hello Man!"'));
	//$xcrud->relation('divisionid','division','divisionid','name');
	//$xcrud->relation('department','department','departmentid','departmentname');
	$xcrud->relation('customer','debtorsmaster','debtorno','name');
$xcrud->relation('branch','custbranch','debtorno','brname','','','','','','debtorno','customer');
   $xcrud->relation('sys_account_number','debtoraccount','account_number','account_number','','','','','','debtorno','customer');
	$xcrud->column_pattern('projectid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{projectid}">{value}</a>');
	$xcrud->relation('project_manager','employeemaster','employeeid','full_name');
	$xcrud->relation('sales_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Sales'));
$xcrud->relation('cogs_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Cost of Goods Sold'));
	//$xcrud->column_name('margin','Margin-(Percentage)');
    $xcrud->change_type('status','select','Setup','Setup,Tender Yet to be Awarded,Quoted,Approved,Cancelled,Lost bid, Won Bid,Project Started');
$xcrud->relation('department','department','departmentname','departmentname');
$xcrud->before_insert('updateaccountnumber','functionsproject.php');
$xcrud->before_update('updateaccountnumber','functionsproject.php');
$userid = $_SESSION['UserID'];
$xcrud->pass_var('managed_by',$userid);

//$xcrud->before_update('getdepartment','functionsprojectbudget.php');
	//$xcrud->before_insert('getdepartment','functionsprojectbudget.php');
	//$xcrud->columns('budgeted_profit',true);
	//$xcrud->subselect('Budgeted Profit','{budgeted_total_price}-{budgeted_total_cost}');
	//$totalprice = $xcrud->subselect('profit','{budgeted_total_price}-{budgeted_total_cost}');
	//$xcrud->highlight('Budgeted Profit','>','0','yellow');
	//$xcrud->highlight('Budgeted Profit','<','0','red');
	
	//$xcrud->column_callback('budgeted_profit','profit','functionsprojectbudget.php');
	//		$db8000 = Xcrud_db::get_instance();
	 //   $query = "SELECT projectid, budgeted_total_cost,budgeted_total_price,budgeted_profit
				   			  
		//          FROM projectdetails";
				  
				  
				  	 	   
        
    //    $db8000 ->query($query);
     //   $out8000  = $db8000 ->result();
      //  foreach($out8000  as $output8000){
       //     $totalbudgetedcost = $output8000 ['budgeted_total_cost'];
		//	$totalbudgetedprice = $output8000 ['budgeted_total_price'];
			
		//	$profit = $totalbudgetedprice - $totalbudgetedcost;
			
			
	
	
	//$query2 = "UPDATE projectdetails SET budgeted_profit = '" . $profit."'";
	//$db8000->query($query2);
			
	//	} 
	
	
	
	
	//1.5 level
	$projectattachment = $xcrud->nested_table('Project/Contract Attachements','projectid','projectattachments','projectid');
	
	$projectattachment->change_type('file', 'file', '', array('not_rename'=>true));
	
    $projectcosting = $xcrud->nested_table('Project Costing/Budgeting','projectid','projectcosting','projectid'); // 2nd level
	
	//$projectcosting->unset_numbers();
	$projectcosting->table_name('Project/Contract Budget Costing');
	$projectcosting->disabled('projectid,budgeted_material,budgeted_labor,budgeted_others,budgeted_total_cost,contract_value,contract_vip');
     $projectcosting->show_primary_ai_column(true);
 $projectcosting->fields('budgeted_material,budgeted_labor,budgeted_others,budgeted_total_cost,contractvalue1,contract_value,contract_vip,estimated_profit,contractvalue2',true);
 $projectcosting->columns('budgeted_material,budgeted_labor,budgeted_others,budgeted_total_cost,contractvalue1,contract_value,contract_vip,estimated_profit,contractvalue2',true);
$projectcosting->label('contract_value','Contract Value(VEP)');
$projectcosting->column_name('projectid','Job No:');
$projectcosting->label('projectid','Job No:');
$projectcosting->column_name('pcid','Costing No:');
//$projectcosting->fields('budgeted_material,budgeted_labor,budgeted_others,budgeted_total_cost,contractvalue1,contractvalue2,contract_value,contract_vip',true);
//$projectcosting->columns('budgeted_material,budgeted_labor,budgeted_others,budgeted_total_cost,contractvalue1,contractvalue2,contract_value,contract_vip',true);
$projectcosting->label('pcid','Costing No:');
 //$projectcosting->before_insert('getprojectname','functionsprojectbudget.php');
//$projectcosting->before_update('getprojectname','functionsprojectbudget.php');
//$projectcosting->before_list('getbudgetedtotals','functionsprojectbudget.php');
$projectcosting->column_pattern('pcid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{pcid}">{value}</a>');
//$projectcosting->change_type('GL_category','select','All','All,Access Systems,Alarm,Annual Survey,Brigade,CCTV,Fire Extinguisher,ID Card,Metabilt Door,Service Fees,Others,Sprinkler');


$projectcosting->change_type('status','select','drafting','drafting,approved costing,cancelled costing,sent quotation,quote accepted by customer,quote not accepted,job started, job completed');

//$projectcosting->change_type('contract_vip,budgeted_material,budgeted_others,budgeted_labor,contract_value, budgeted_total_cost,estimated_profit', 'price', '0', array('prefix'=>'$'));
//$projectcosting->subselect('Budgeted Profit','{contract_value}-{budgeted_total_cost}');
//$projectcosting->load_view('edit','projectcosting.php');
//$projectcosting->load_view('create','projectcosting.php');
$projectcosting->order_by('pcid','desc');

 $projectcosting->button('JCAutoCreateQuote1.php?pcid={pcid}&projectid={projectid}', 'Create Quote','glyphicon glyphicon-list-alt');
    $projectcostingdetail = $projectcosting->nested_table('Job Costing','pcid','projectcostingdetail','pcid');
   $projectcostingdetail->table_name('Costing and Pricing For Materials, Labour & Other Expenses');
$projectcostingdetail->relation('sales_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Sales'));
$projectcostingdetail->relation('cogs_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Cost of Goods Sold'));
$projectcostingdetail->column_pattern('projectcostingid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{projectcostingid}">{value}</a>');
//$projectcostingdetail->relation('job_costing_sheet_category','jc_stockcat','jsstockcatid','name');
//	$projectcostingdetail->relation('product_details_nonstock','jobcostingsheet','id',array('code','description'),'','','','','','jsstockcatid','job_costing_sheet_category');
//$projectcostingdetail->relation('unit_price','jobcostingsheet','id','landing_cost','','','','','','id','product_details_nonstock');
$projectcostingdetail->unset_csv();
$projectcostingdetail->unset_print();
$projectcostingdetail->show_primary_ai_column(true);
//stock

//$projectcostingdetail->relation('stock_details','stockmaster','stockid',array('stockid','description'),'','','','','','categoryid','job_costing_sheet_category');
//$projectcostingdetail->relation('stock_unit_cost','stockmaster','stockid','materialcost','','','','','','stockid','stock_details');

//$projectcostingdetail->fields('nonstockprice,stockprice,nonstockname,stockname',true);
//$projectcostingdetail->columns('nonstockprice,stockprice,nonstockname,stockname',true);
	$projectcosting->column_width('projectid','200px');
    $projectcostingdetail->change_type('cost_type','select','materials','materials,labour,others');
	//$projectcostingdetail->before_update('calculateprices','functionsprojectbudget.php');
	//$projectcostingdetail->before_insert('calculateprices','functionsprojectbudget.php');
	//$projectquote->set_attr('uom',array('onfocus'=>'myFunction()'));
	$projectcostingdetail->sum('total_cost,price');
	$projectcostingdetail->fields('entered_by',true);
$projectcostingdetail->label('price','Price VEP');
$projectcostingdetail->column_name('price','Price VEP');
$projectcostingdetail->column_name('pcid','Costing No:');
$projectcostingdetail->label('pcid','Costing No:');
 $projectcostingdetail->fields('pcid',true);
 $projectcostingdetail->columns('pcid',true);
//$projectcostingdetail->disabled('total_cost,price');
//$projectcostingdetail->column_name('unit_price','Non-Stock Unit Cost:');
//$projectcostingdetail->label('unit_price','Non-Stock Unit Cost:');
//$projectcostingdetail->change_type('other_description','select','CONTINGENCY','CONTINGENCY,BOARD/COUNTRY,MEALS,AIR/TRAVEL,VEHICLE,OTHER,A.T.S FEES,SCAFFOLDING,SHROULD,INDEX ENGRAVING,SHEDS,FREIGHT,CONCRETE CUT/BUILDERS,COMPRESSOR,SITE WELDING,12 MONTHS MAINTENANCE,BONDS,FPIS INSPECTION/ICONZ,AS BUILTS/MANUALS');

//$projectcostingdetail->column_name('stockprice','Stock Unit Sales Price:');
//$projectcostingdetail->label('stockprice','Stock Unit Sales Price:');

///$projectcostingdetail->column_name('nonstockprice','Non Stock Unit Sales Price:');
////$projectcostingdetail->label('nonstockprice','Non Stock Unit Sales Price:');
//$projectcostingdetail->column_name('nonstocknarrative','Non Stock Narration:');
//$projectcostingdetail->label('nonstocknarrative','Non Stock Narration:');

//$projectcostingdetail->column_name('stocknarrative','Stock Narration:');
//$projectcostingdetail->label('stocknarrative','Stock Narration:');


$projectcostingdetail->label('margin','Margin %');
$projectcostingdetail->pass_default('margin','40');
$projectcostingdetail->column_name('margin','Margin %');
$projectcostingdetail->change_type('total_cost,price,unit_price', 'price', '0', array('prefix'=>'$'));
//$projectcostingdetail->change_type('uom','select','each','each,hours,carton,bag,kg,litre,length,metres,feet');
$projectcostingdetail->before_update('updatebudgettotals','functionsprojectbudget.php'); 
$projectcostingdetail->before_insert('updatebudgettotals','functionsprojectbudget.php');
	



//$projectcostingdetail->relation('labor_type','jc_labortype','labortypeid','name');
//$projectcostingdetail->relation('labor_rate','jc_labortype','rate','rate','','','','','','labortypeid','labor_type');

$projectcostingdetail->show_primary_ai_column(true);
      //$projectquote->load_view('list','projectcosting.php');
	//$xcrud->pass_var('budgeted_total_cost', $sum);
	
	//$totalcostoverall = $projectcosting->sum('total_cost');
	
	
	
	
     // $xcrud->pass_var('budgeted_total_cost', $totalcostoverall);
	 
   // $xcrud->pass_var('budgeted_total_cost', $sum);
	
	
   //$projectactualperiod= $xcrud->nested_table('Actual Periods','projectid','projectactualperiod','projectid'); // 2nd level 2
  // $projectactualperiod->default_tab('Actual Period');
	//$projectactualperiod->table_name('Actual Project Costing');
	//$projectactualperiod->disabled('projectid,actual_material_cost,actual_labor_cost,actual_total_cost,sales_ratio,sales_revenue,margin');
	//$projectactualperiod->change_type('status','select','Setup','Setup,Quoted,Approved,Cancelled,Lost bid, Won Bid,Project Started');
	//$projectactualperiod->unset_numbers();
	//$projectactualperiod->show_primary_ai_column(true);

	
	//project stock

//$projectstock= $xcrud->nested_table('Project Stock Usage','projectid','project_stock','projectid'); // 2nd level 2
   //$projectstock->table_name('Stock Transfered to this Project');
	 
    $quotation = $xcrud->nested_table('Quotations','projectid','salesorders','job_no'); // 3rd level
 //$quotation->where('quotation=',1);
$quotation->label('orderno','Quote No');

$quotation->column_pattern('orderno', '<a href="#" class="xcrud-action" data-task="view" data-primary="{orderno}">{value}</a>');

$quotation->unset_add();
		 $quotation->unset_edit();
			    $quotation->unset_remove();

 $quotation->fields('orderno,amount,quotedate,preparedby,status',false);
 $quotation->columns('orderno,amount,quotedate,preparedby,status',false);
$quotation->table_name('Quotations');
$quotation->button('JCPrintQuote.php?orderno={orderno}', 'Re-Print Quote','glyphicon glyphicon-download-alt','approve');
$quotation->button('JCEmailQuote.php?orderno={orderno}', 'Email Quote','glyphicon glyphicon-envelope','payslipemail');
$quotation->button('JCAutoCreateInvoice.php?orderno={orderno}', 'Convert to Invoice','glyphicon glyphicon-list-alt','payslip');

	      $salesorderdetails = $quotation->nested_table('Salesdetails','orderno','salesorderdetails','orderno');
			  $salesorderdetails->unset_add();
			   $salesorderdetails->unset_edit();
			   $salesorderdetails->unset_remove();
$salesorderdetails->table_name('Quotation Line item Details');
     $salesorderdetails->fields('stkcode,stock_name,qtyinvoiced,unitprice,quantity,discountpercent,narrative,total',false);
 $salesorderdetails->columns('stkcode,stock_name,qtyinvoiced,unitprice,quantity,discountpercent,narrative,total',false);
$salesorderdetails->subselect('total','{unitprice}*{quantity}');
$salesorderdetails->sum('total');
$salesorderdetails->change_type('total,unitprice', 'price', '0', array('prefix'=>'$','decimals'=>'2'));

//invoices for reprinting
  $invoices = $xcrud->nested_table('Invoice','projectid','debtortrans','projectid'); // 3rd level
 //$invoices->where('quotation=',0);

//$invoices->column_pattern('orderno', '<a href="#" class="xcrud-action" data-task="view" data-primary="{orderno}">{value}</a>');
$invoices->unset_add();
		 $invoices->unset_edit();
			    $invoices->unset_remove();

 $invoices->fields('transno,order_,trandate,ovamount,vat,total_vip,alloc,ptax,retention',false);
 $invoices->columns('transno,order_,trandate,ovamount,vat,total_vip,alloc,ptax,retention',false);
$invoices->label('transno','Invoice no:');
$invoices->label('trandate','Dated:');
$invoices->label('order_','Quote No');
$invoices->table_name('Invoiced ');
$invoices->button('JCPrintInvoice.php?orderno={order_}&transno={transno}', 'Re-Print Invoice','glyphicon glyphicon-download-alt','westpac');
$invoices->button('JCEmailInvoice.php?orderno={order_}&transno={transno}', 'Email Invoice','glyphicon glyphicon-envelope','payslipemail');
$invoices->subselect('vat','{ovamount}*0.09');
	      
$invoices->subselect('total_vip','{ovamount}*1.09');

$invoices->sum('ovamount,vat,total_vip');
$invoices->change_type('ovamount,vat,total_vip', 'price', '0', array('prefix'=>'$','decimals'=>'2'));

    $purchaseorders = $xcrud->nested_table('Actual Material Cost Info','projectid','contractcharges','contractref'); // 3rd level
	        
			   $purchaseorders->unset_add();
			    $purchaseorders->unset_edit();
			    $purchaseorders->unset_remove();
				$purchaseorders->show_primary_ai_column(false);
 $purchaseorders->change_type('amount', 'price', '0', array('prefix'=>'$'));
			  $purchaseorders->sum('amount');
$purchaseorders->fields('transtype,transno',true);
 $purchaseorders->columns('transtype,transno',true);
$purchaseorders->label('contractref','Project/Job No');
$purchaseorders->column_name('contractref','Project/Job No');

//$purchaseorders->column_width('contractref','10%'); 
//$purchaseorders->column_width('date','20%'); 
//$purchaseorders->column_width('amount','10%'); 
$purchaseorders->column_width('narrative','80%'); 
//$purchaseorders->column_width('anticipated','10%'); 

    $timesheet = $xcrud->nested_table('Actual Labour Cost Info','projectid','techniciantimesheet','job_no'); // 4th level
	
	 $timesheet->unset_add();
			$timesheet->unset_edit();
			 $timesheet->unset_remove();
$timesheet->show_primary_ai_column(true);
     $timesheetdetails = $timesheet ->nested_table('Employee Timesheet','techtimeid','techniciantimesheetdetails','techtimeid');

$timesheetdetails->unset_add();
			$timesheetdetails->unset_edit();
			 $timesheetdetails->unset_remove();

$timesheetdetails->table_name('Technician Scheduling hours');
    $timesheetdetails->relation('employeeid','employeemaster','employeeid',array('employeeid','full_name'));
	
	//$techtimesheetdetails->show_primary_ai_column(true);
	
	//$techtimesheetdetails->after_insert('checkpublicholiday','functionstechtimesheet.php');
	//$techtimesheetdetails->after_update('checkpublicholiday','functionstechtimesheet.php');
	$progressive = $xcrud->nested_table('Progressive Billing','projectid','progressive_billing','projectid'); // 6th level
	$progressive->change_type('actual_material,actual_labor,actual_others,total_actual_cost,billing_amount_vep,billing_amount_vip', 'price', '0', array('prefix'=>'$'));

 $progressive->change_type('status','select','drafting','drafting,approved,invoiced,sent email,paid');
//$progressive->pass_default('margin','40');
$progressive->disabled('actual_material,actual_labor');
$progressive->relation('costing_no','projectcosting','pcid',array('pcid','name'),array('projectid' => '{projectid}'));
$progressive->before_update('actualcosting','functionsprojectbudget.php'); 
$progressive->before_insert('actualcosting','functionsprojectbudget.php');
	$progressive->button('ProgressiveInvoicing.php?id={pgid}&projectid={projectid}', 'Raise Invoice','glyphicon glyphicon-list-alt');
$progressive->column_pattern('pgid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{pgid}">{value}</a>');

$adjustments = $progressive->nested_table('Cost Adjustments','pgid','projectadjustments','pgid'); // 6th level
	 //$adjustments->unset_add();
			$adjustments->unset_edit();
			$adjustments->unset_remove();
$adjustments->change_type('sector','select','Project Manager','Project Manager,Finance Team');
$adjustments->change_type('amount', 'price', '0', array('prefix'=>'$'));
$adjustments->disabled('costed_by');
   $adjustments->pass_var('costed_by',$userid);
$adjustments->before_update('actualcostadjustments','functionsprojectbudget.php'); 
$adjustments->before_insert('actualcostadjustments','functionsprojectbudget.php');


$stock = $xcrud->nested_table('Stock Usage','projectid','project_stock','projectid'); // 6th level
$stock->unset_edit();
$stock->unset_remove();
$stock->unset_add();
    echo $xcrud->render();
}
//installs
elseif ($userid == 'elina' || $userid == 'filo' ) { 
	
	 include('xcrud/xcrud.php');
    $xcrud = Xcrud::get_instance();
    $xcrud->table('projectdetails');
$xcrud->where('department', 'SecurityInstalls-Suva');
    $xcrud->default_tab('Project info');
	$xcrud->table_name('Project Management/Job Costing/WIP Processing');
	//Xcrud_config::$editor_url = dirname($_SERVER["SCRIPT_NAME"]).'/editors/ckeditor/ckeditor.js'; 
	$xcrud->disabled('age,department');
$userid = $_SESSION['UserID'];
$xcrud->pass_default('department','SecurityInstalls-Suva');
$xcrud->pass_var('department','SecurityInstalls-Suva');
$xcrud->pass_var('managed_by',$userid);
	$xcrud->unset_numbers();
	$xcrud->show_primary_ai_column(true);
	$xcrud->order_by('projectid','desc');
	//$xcrud->columns('projectid',false);
	$xcrud->column_name('projectid','Projectid/jobno');
	$xcrud->change_type('project_type','select','Small Jobs','Small Jobs,Contract');
	
	//$xcrud->set_attr('project_type',array('onfocus'=>'alert("Hello Man!"'));
	//$xcrud->relation('divisionid','division','divisionid','name');
	//$xcrud->relation('department','department','departmentid','departmentname');
	$xcrud->relation('customer','debtorsmaster','debtorno','name');
$xcrud->relation('branch','custbranch','debtorno','brname','','','','','','debtorno','customer');
   $xcrud->relation('sys_account_number','debtoraccount','account_number','account_number','','','','','','debtorno','customer');
	$xcrud->column_pattern('projectid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{projectid}">{value}</a>');
	$xcrud->relation('project_manager','employeemaster','employeeid','full_name');
	$xcrud->relation('sales_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Sales'));
$xcrud->relation('cogs_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Cost of Goods Sold'));
	//$xcrud->column_name('margin','Margin-(Percentage)');
    $xcrud->change_type('status','select','Setup','Setup,Tender Yet to be Awarded,Quoted,Approved,Cancelled,Lost bid, Won Bid,Project Started');
$xcrud->relation('department','department','departmentname','departmentname');
$xcrud->before_insert('updateaccountnumber','functionsproject.php');
$xcrud->before_update('updateaccountnumber','functionsproject.php');
$userid = $_SESSION['UserID'];
$xcrud->pass_var('managed_by',$userid);

//$xcrud->before_update('getdepartment','functionsprojectbudget.php');
	//$xcrud->before_insert('getdepartment','functionsprojectbudget.php');
	//$xcrud->columns('budgeted_profit',true);
	//$xcrud->subselect('Budgeted Profit','{budgeted_total_price}-{budgeted_total_cost}');
	//$totalprice = $xcrud->subselect('profit','{budgeted_total_price}-{budgeted_total_cost}');
	//$xcrud->highlight('Budgeted Profit','>','0','yellow');
	//$xcrud->highlight('Budgeted Profit','<','0','red');
	
	//$xcrud->column_callback('budgeted_profit','profit','functionsprojectbudget.php');
	//		$db8000 = Xcrud_db::get_instance();
	 //   $query = "SELECT projectid, budgeted_total_cost,budgeted_total_price,budgeted_profit
				   			  
		//          FROM projectdetails";
				  
				  
				  	 	   
        
    //    $db8000 ->query($query);
     //   $out8000  = $db8000 ->result();
      //  foreach($out8000  as $output8000){
       //     $totalbudgetedcost = $output8000 ['budgeted_total_cost'];
		//	$totalbudgetedprice = $output8000 ['budgeted_total_price'];
			
		//	$profit = $totalbudgetedprice - $totalbudgetedcost;
			
			
	
	
	//$query2 = "UPDATE projectdetails SET budgeted_profit = '" . $profit."'";
	//$db8000->query($query2);
			
	//	} 
	
	
	
	
	//1.5 level
	$projectattachment = $xcrud->nested_table('Project/Contract Attachements','projectid','projectattachments','projectid');
	
	$projectattachment->change_type('file', 'file', '', array('not_rename'=>true));
	
    $projectcosting = $xcrud->nested_table('Project Costing/Budgeting','projectid','projectcosting','projectid'); // 2nd level
	
	//$projectcosting->unset_numbers();
	$projectcosting->table_name('Project/Contract Budget Costing');
	$projectcosting->disabled('projectid,budgeted_material,budgeted_labor,budgeted_others,budgeted_total_cost,contract_value,contract_vip');
     $projectcosting->show_primary_ai_column(true);
 $projectcosting->fields('contractvalue1,contractvalue2',true);
 $projectcosting->columns('contractvalue1,contractvalue2',true);
$projectcosting->label('contract_value','Contract Value(VEP)');
$projectcosting->column_name('projectid','Job No:');
$projectcosting->label('projectid','Job No:');
$projectcosting->column_name('pcid','Costing No:');
//$projectcosting->fields('budgeted_material,budgeted_labor,budgeted_others,budgeted_total_cost,contractvalue1,contractvalue2,contract_value,contract_vip',true);
//$projectcosting->columns('budgeted_material,budgeted_labor,budgeted_others,budgeted_total_cost,contractvalue1,contractvalue2,contract_value,contract_vip',true);
$projectcosting->label('pcid','Costing No:');
 //$projectcosting->before_insert('getprojectname','functionsprojectbudget.php');
//$projectcosting->before_update('getprojectname','functionsprojectbudget.php');
//$projectcosting->before_list('getbudgetedtotals','functionsprojectbudget.php');
$projectcosting->column_pattern('pcid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{pcid}">{value}</a>');
//$projectcosting->change_type('GL_category','select','All','All,Access Systems,Alarm,Annual Survey,Brigade,CCTV,Fire Extinguisher,ID Card,Metabilt Door,Service Fees,Others,Sprinkler');


$projectcosting->change_type('status','select','drafting','drafting,approved costing,cancelled costing,sent quotation,quote accepted by customer,quote not accepted,job started, job completed');

//$projectcosting->change_type('contract_vip,budgeted_material,budgeted_others,budgeted_labor,contract_value, budgeted_total_cost,estimated_profit', 'price', '0', array('prefix'=>'$'));
//$projectcosting->subselect('Budgeted Profit','{contract_value}-{budgeted_total_cost}');
//$projectcosting->load_view('edit','projectcosting.php');
//$projectcosting->load_view('create','projectcosting.php');
$projectcosting->order_by('pcid','desc');

 $projectcosting->button('JCAutoCreateQuote1.php?pcid={pcid}&projectid={projectid}', 'Create Quote','glyphicon glyphicon-list-alt');
    $projectcostingdetail = $projectcosting->nested_table('Job Costing','pcid','projectcostingdetail','pcid');
   $projectcostingdetail->table_name('Costing and Pricing For Materials, Labour & Other Expenses');
$projectcostingdetail->relation('sales_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Sales'));
$projectcostingdetail->relation('cogs_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Cost of Goods Sold'));
$projectcostingdetail->column_pattern('projectcostingid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{projectcostingid}">{value}</a>');
//$projectcostingdetail->relation('job_costing_sheet_category','jc_stockcat','jsstockcatid','name');
//	$projectcostingdetail->relation('product_details_nonstock','jobcostingsheet','id',array('code','description'),'','','','','','jsstockcatid','job_costing_sheet_category');
//$projectcostingdetail->relation('unit_price','jobcostingsheet','id','landing_cost','','','','','','id','product_details_nonstock');
$projectcostingdetail->unset_csv();
$projectcostingdetail->unset_print();
$projectcostingdetail->show_primary_ai_column(true);
//stock

//$projectcostingdetail->relation('stock_details','stockmaster','stockid',array('stockid','description'),'','','','','','categoryid','job_costing_sheet_category');
//$projectcostingdetail->relation('stock_unit_cost','stockmaster','stockid','materialcost','','','','','','stockid','stock_details');

//$projectcostingdetail->fields('nonstockprice,stockprice,nonstockname,stockname',true);
//$projectcostingdetail->columns('nonstockprice,stockprice,nonstockname,stockname',true);
	$projectcosting->column_width('projectid','200px');
    $projectcostingdetail->change_type('cost_type','select','materials','materials,labour,others');
	//$projectcostingdetail->before_update('calculateprices','functionsprojectbudget.php');
	//$projectcostingdetail->before_insert('calculateprices','functionsprojectbudget.php');
	//$projectquote->set_attr('uom',array('onfocus'=>'myFunction()'));
	$projectcostingdetail->sum('total_cost,price');
	$projectcostingdetail->fields('entered_by',true);
$projectcostingdetail->label('price','Price VEP');
$projectcostingdetail->column_name('price','Price VEP');
$projectcostingdetail->column_name('pcid','Costing No:');
$projectcostingdetail->label('pcid','Costing No:');
 $projectcostingdetail->fields('pcid',true);
 $projectcostingdetail->columns('pcid',true);
//$projectcostingdetail->disabled('total_cost,price');
//$projectcostingdetail->column_name('unit_price','Non-Stock Unit Cost:');
//$projectcostingdetail->label('unit_price','Non-Stock Unit Cost:');
//$projectcostingdetail->change_type('other_description','select','CONTINGENCY','CONTINGENCY,BOARD/COUNTRY,MEALS,AIR/TRAVEL,VEHICLE,OTHER,A.T.S FEES,SCAFFOLDING,SHROULD,INDEX ENGRAVING,SHEDS,FREIGHT,CONCRETE CUT/BUILDERS,COMPRESSOR,SITE WELDING,12 MONTHS MAINTENANCE,BONDS,FPIS INSPECTION/ICONZ,AS BUILTS/MANUALS');

//$projectcostingdetail->column_name('stockprice','Stock Unit Sales Price:');
//$projectcostingdetail->label('stockprice','Stock Unit Sales Price:');

///$projectcostingdetail->column_name('nonstockprice','Non Stock Unit Sales Price:');
////$projectcostingdetail->label('nonstockprice','Non Stock Unit Sales Price:');
//$projectcostingdetail->column_name('nonstocknarrative','Non Stock Narration:');
//$projectcostingdetail->label('nonstocknarrative','Non Stock Narration:');

//$projectcostingdetail->column_name('stocknarrative','Stock Narration:');
//$projectcostingdetail->label('stocknarrative','Stock Narration:');


$projectcostingdetail->label('margin','Margin %');
$projectcostingdetail->pass_default('margin','40');
$projectcostingdetail->column_name('margin','Margin %');
$projectcostingdetail->change_type('total_cost,price,unit_price', 'price', '0', array('prefix'=>'$'));
//$projectcostingdetail->change_type('uom','select','each','each,hours,carton,bag,kg,litre,length,metres,feet');
$projectcostingdetail->before_update('updatebudgettotals','functionsprojectbudget.php'); 
$projectcostingdetail->before_insert('updatebudgettotals','functionsprojectbudget.php');
	



//$projectcostingdetail->relation('labor_type','jc_labortype','labortypeid','name');
//$projectcostingdetail->relation('labor_rate','jc_labortype','rate','rate','','','','','','labortypeid','labor_type');

$projectcostingdetail->show_primary_ai_column(true);
      //$projectquote->load_view('list','projectcosting.php');
	//$xcrud->pass_var('budgeted_total_cost', $sum);
	
	//$totalcostoverall = $projectcosting->sum('total_cost');
	
	
	
	
     // $xcrud->pass_var('budgeted_total_cost', $totalcostoverall);
	 
   // $xcrud->pass_var('budgeted_total_cost', $sum);
	
	
   //$projectactualperiod= $xcrud->nested_table('Actual Periods','projectid','projectactualperiod','projectid'); // 2nd level 2
  // $projectactualperiod->default_tab('Actual Period');
	//$projectactualperiod->table_name('Actual Project Costing');
	//$projectactualperiod->disabled('projectid,actual_material_cost,actual_labor_cost,actual_total_cost,sales_ratio,sales_revenue,margin');
	//$projectactualperiod->change_type('status','select','Setup','Setup,Quoted,Approved,Cancelled,Lost bid, Won Bid,Project Started');
	//$projectactualperiod->unset_numbers();
	//$projectactualperiod->show_primary_ai_column(true);

	
	//project stock

//$projectstock= $xcrud->nested_table('Project Stock Usage','projectid','project_stock','projectid'); // 2nd level 2
   //$projectstock->table_name('Stock Transfered to this Project');
	 
    $quotation = $xcrud->nested_table('Quotations','projectid','salesorders','job_no'); // 3rd level
 //$quotation->where('quotation=',1);
$quotation->label('orderno','Quote No');

$quotation->column_pattern('orderno', '<a href="#" class="xcrud-action" data-task="view" data-primary="{orderno}">{value}</a>');

$quotation->unset_add();
		 $quotation->unset_edit();
			    $quotation->unset_remove();

 $quotation->fields('orderno,amount,quotedate,preparedby,status',false);
 $quotation->columns('orderno,amount,quotedate,preparedby,status',false);
$quotation->table_name('Quotations');
$quotation->button('JCPrintQuote.php?orderno={orderno}', 'Re-Print Quote','glyphicon glyphicon-download-alt','approve');
$quotation->button('JCEmailQuote.php?orderno={orderno}', 'Email Quote','glyphicon glyphicon-envelope','payslipemail');
$quotation->button('JCAutoCreateInvoice.php?orderno={orderno}', 'Convert to Invoice','glyphicon glyphicon-list-alt','payslip');

	      $salesorderdetails = $quotation->nested_table('Salesdetails','orderno','salesorderdetails','orderno');
			  $salesorderdetails->unset_add();
			   $salesorderdetails->unset_edit();
			   $salesorderdetails->unset_remove();
$salesorderdetails->table_name('Quotation Line item Details');
     $salesorderdetails->fields('stkcode,stock_name,qtyinvoiced,unitprice,quantity,discountpercent,narrative,total',false);
 $salesorderdetails->columns('stkcode,stock_name,qtyinvoiced,unitprice,quantity,discountpercent,narrative,total',false);
$salesorderdetails->subselect('total','{unitprice}*{quantity}');
$salesorderdetails->sum('total');
$salesorderdetails->change_type('total,unitprice', 'price', '0', array('prefix'=>'$','decimals'=>'2'));

//invoices for reprinting
  $invoices = $xcrud->nested_table('Invoice','projectid','debtortrans','projectid'); // 3rd level
 //$invoices->where('quotation=',0);

//$invoices->column_pattern('orderno', '<a href="#" class="xcrud-action" data-task="view" data-primary="{orderno}">{value}</a>');
$invoices->unset_add();
		 $invoices->unset_edit();
			    $invoices->unset_remove();

 $invoices->fields('transno,order_,trandate,ovamount,vat,total_vip,alloc,ptax,retention',false);
 $invoices->columns('transno,order_,trandate,ovamount,vat,total_vip,alloc,ptax,retention',false);
$invoices->label('transno','Invoice no:');
$invoices->label('trandate','Dated:');
$invoices->label('order_','Quote No');
$invoices->table_name('Invoiced ');
$invoices->button('JCPrintInvoice.php?orderno={order_}&transno={transno}', 'Re-Print Invoice','glyphicon glyphicon-download-alt','westpac');
$invoices->button('JCEmailInvoice.php?orderno={order_}&transno={transno}', 'Email Invoice','glyphicon glyphicon-envelope','payslipemail');
$invoices->subselect('vat','{ovamount}*0.09');
	      
$invoices->subselect('total_vip','{ovamount}*1.09');

$invoices->sum('ovamount,vat,total_vip');
$invoices->change_type('ovamount,vat,total_vip', 'price', '0', array('prefix'=>'$','decimals'=>'2'));

    $purchaseorders = $xcrud->nested_table('Actual Material Cost Info','projectid','contractcharges','contractref'); // 3rd level
	        
			   $purchaseorders->unset_add();
			    $purchaseorders->unset_edit();
			    $purchaseorders->unset_remove();
				$purchaseorders->show_primary_ai_column(false);
 $purchaseorders->change_type('amount', 'price', '0', array('prefix'=>'$'));
			  $purchaseorders->sum('amount');
$purchaseorders->fields('transtype,transno',true);
 $purchaseorders->columns('transtype,transno',true);
$purchaseorders->label('contractref','Project/Job No');
$purchaseorders->column_name('contractref','Project/Job No');

//$purchaseorders->column_width('contractref','10%'); 
//$purchaseorders->column_width('date','20%'); 
//$purchaseorders->column_width('amount','10%'); 
$purchaseorders->column_width('narrative','80%'); 
//$purchaseorders->column_width('anticipated','10%'); 

    $timesheet = $xcrud->nested_table('Actual Labour Cost Info','projectid','techniciantimesheet','job_no'); // 4th level
	
	 $timesheet->unset_add();
			$timesheet->unset_edit();
			 $timesheet->unset_remove();
$timesheet->show_primary_ai_column(true);
     $timesheetdetails = $timesheet ->nested_table('Employee Timesheet','techtimeid','techniciantimesheetdetails','techtimeid');

$timesheetdetails->unset_add();
			$timesheetdetails->unset_edit();
			 $timesheetdetails->unset_remove();

$timesheetdetails->table_name('Technician Scheduling hours');
    $timesheetdetails->relation('employeeid','employeemaster','employeeid',array('employeeid','full_name'));
	
	//$techtimesheetdetails->show_primary_ai_column(true);
	
	//$techtimesheetdetails->after_insert('checkpublicholiday','functionstechtimesheet.php');
	//$techtimesheetdetails->after_update('checkpublicholiday','functionstechtimesheet.php');
	$progressive = $xcrud->nested_table('Progressive Billing','projectid','progressive_billing','projectid'); // 6th level
	$progressive->change_type('actual_material,actual_labor,actual_others,total_actual_cost,billing_amount_vep,billing_amount_vip', 'price', '0', array('prefix'=>'$'));

 $progressive->change_type('status','select','drafting','drafting,approved,invoiced,sent email,paid');
//$progressive->pass_default('margin','40');
$progressive->disabled('actual_material,actual_labor');
$progressive->relation('costing_no','projectcosting','pcid',array('pcid','name'),array('projectid' => '{projectid}'));
$progressive->before_update('actualcosting','functionsprojectbudget.php'); 
$progressive->before_insert('actualcosting','functionsprojectbudget.php');
	$progressive->button('ProgressiveInvoicing.php?id={pgid}&projectid={projectid}', 'Raise Invoice','glyphicon glyphicon-list-alt');
$progressive->column_pattern('pgid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{pgid}">{value}</a>');

$adjustments = $progressive->nested_table('Cost Adjustments','pgid','projectadjustments','pgid'); // 6th level
	 //$adjustments->unset_add();
			$adjustments->unset_edit();
			$adjustments->unset_remove();
$adjustments->change_type('sector','select','Project Manager','Project Manager,Finance Team');
$adjustments->change_type('amount', 'price', '0', array('prefix'=>'$'));
$adjustments->disabled('costed_by');
   $adjustments->pass_var('costed_by',$userid);
$adjustments->before_update('actualcostadjustments','functionsprojectbudget.php'); 
$adjustments->before_insert('actualcostadjustments','functionsprojectbudget.php');
$stock = $xcrud->nested_table('Stock Usage','projectid','project_stock','projectid'); // 6th level
$stock->unset_edit();
$stock->unset_remove();
$stock->unset_add();


    echo $xcrud->render();
}
elseif ($userid == 'akumar'  ) { 
	
	 include('xcrud/xcrud.php');
    $xcrud = Xcrud::get_instance();
    $xcrud->table('projectdetails');
$xcrud->where('department', 'SecurityInstalls-North');
    $xcrud->default_tab('Project info');
	$xcrud->table_name('Project Management/Job Costing/WIP Processing');
	//Xcrud_config::$editor_url = dirname($_SERVER["SCRIPT_NAME"]).'/editors/ckeditor/ckeditor.js'; 
	$xcrud->disabled('age,department');
$userid = $_SESSION['UserID'];
$xcrud->pass_default('department','SecurityInstalls-North');
$xcrud->pass_var('department','SecurityInstalls-North');
$xcrud->pass_var('managed_by',$userid);
	$xcrud->unset_numbers();
	$xcrud->show_primary_ai_column(true);
	$xcrud->order_by('projectid','desc');
	//$xcrud->columns('projectid',false);
	$xcrud->column_name('projectid','Projectid/jobno');
	$xcrud->change_type('project_type','select','Small Jobs','Small Jobs,Contract');
	
	//$xcrud->set_attr('project_type',array('onfocus'=>'alert("Hello Man!"'));
	//$xcrud->relation('divisionid','division','divisionid','name');
	//$xcrud->relation('department','department','departmentid','departmentname');
	$xcrud->relation('customer','debtorsmaster','debtorno','name');
$xcrud->relation('branch','custbranch','debtorno','brname','','','','','','debtorno','customer');
   $xcrud->relation('sys_account_number','debtoraccount','account_number','account_number','','','','','','debtorno','customer');
	$xcrud->column_pattern('projectid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{projectid}">{value}</a>');
	$xcrud->relation('project_manager','employeemaster','employeeid','full_name');
	$xcrud->relation('sales_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Sales'));
$xcrud->relation('cogs_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Cost of Goods Sold'));
	//$xcrud->column_name('margin','Margin-(Percentage)');
    $xcrud->change_type('status','select','Setup','Setup,Tender Yet to be Awarded,Quoted,Approved,Cancelled,Lost bid, Won Bid,Project Started');
$xcrud->relation('department','department','departmentname','departmentname');
$xcrud->before_insert('updateaccountnumber','functionsproject.php');
$xcrud->before_update('updateaccountnumber','functionsproject.php');
$userid = $_SESSION['UserID'];
$xcrud->pass_var('managed_by',$userid);

//$xcrud->before_update('getdepartment','functionsprojectbudget.php');
	//$xcrud->before_insert('getdepartment','functionsprojectbudget.php');
	//$xcrud->columns('budgeted_profit',true);
	//$xcrud->subselect('Budgeted Profit','{budgeted_total_price}-{budgeted_total_cost}');
	//$totalprice = $xcrud->subselect('profit','{budgeted_total_price}-{budgeted_total_cost}');
	//$xcrud->highlight('Budgeted Profit','>','0','yellow');
	//$xcrud->highlight('Budgeted Profit','<','0','red');
	
	//$xcrud->column_callback('budgeted_profit','profit','functionsprojectbudget.php');
	//		$db8000 = Xcrud_db::get_instance();
	 //   $query = "SELECT projectid, budgeted_total_cost,budgeted_total_price,budgeted_profit
				   			  
		//          FROM projectdetails";
				  
				  
				  	 	   
        
    //    $db8000 ->query($query);
     //   $out8000  = $db8000 ->result();
      //  foreach($out8000  as $output8000){
       //     $totalbudgetedcost = $output8000 ['budgeted_total_cost'];
		//	$totalbudgetedprice = $output8000 ['budgeted_total_price'];
			
		//	$profit = $totalbudgetedprice - $totalbudgetedcost;
			
			
	
	
	//$query2 = "UPDATE projectdetails SET budgeted_profit = '" . $profit."'";
	//$db8000->query($query2);
			
	//	} 
	
	
	
	
	//1.5 level
	$projectattachment = $xcrud->nested_table('Project/Contract Attachements','projectid','projectattachments','projectid');
	
	$projectattachment->change_type('file', 'file', '', array('not_rename'=>true));
	
    $projectcosting = $xcrud->nested_table('Project Costing/Budgeting','projectid','projectcosting','projectid'); // 2nd level
	
	//$projectcosting->unset_numbers();
	$projectcosting->table_name('Project/Contract Budget Costing');
	$projectcosting->disabled('projectid,budgeted_material,budgeted_labor,budgeted_others,budgeted_total_cost,contract_value,contract_vip');
     $projectcosting->show_primary_ai_column(true);
 $projectcosting->fields('contractvalue1,contractvalue2',true);
 $projectcosting->columns('contractvalue1,contractvalue2',true);
$projectcosting->label('contract_value','Contract Value(VEP)');
$projectcosting->column_name('projectid','Job No:');
$projectcosting->label('projectid','Job No:');
$projectcosting->column_name('pcid','Costing No:');
//$projectcosting->fields('budgeted_material,budgeted_labor,budgeted_others,budgeted_total_cost,contractvalue1,contractvalue2,contract_value,contract_vip',true);
//$projectcosting->columns('budgeted_material,budgeted_labor,budgeted_others,budgeted_total_cost,contractvalue1,contractvalue2,contract_value,contract_vip',true);
$projectcosting->label('pcid','Costing No:');
 //$projectcosting->before_insert('getprojectname','functionsprojectbudget.php');
//$projectcosting->before_update('getprojectname','functionsprojectbudget.php');
//$projectcosting->before_list('getbudgetedtotals','functionsprojectbudget.php');
$projectcosting->column_pattern('pcid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{pcid}">{value}</a>');
//$projectcosting->change_type('GL_category','select','All','All,Access Systems,Alarm,Annual Survey,Brigade,CCTV,Fire Extinguisher,ID Card,Metabilt Door,Service Fees,Others,Sprinkler');


$projectcosting->change_type('status','select','drafting','drafting,approved costing,cancelled costing,sent quotation,quote accepted by customer,quote not accepted,job started, job completed');

//$projectcosting->change_type('contract_vip,budgeted_material,budgeted_others,budgeted_labor,contract_value, budgeted_total_cost,estimated_profit', 'price', '0', array('prefix'=>'$'));
//$projectcosting->subselect('Budgeted Profit','{contract_value}-{budgeted_total_cost}');
//$projectcosting->load_view('edit','projectcosting.php');
//$projectcosting->load_view('create','projectcosting.php');
$projectcosting->order_by('pcid','desc');

 $projectcosting->button('JCAutoCreateQuote1.php?pcid={pcid}&projectid={projectid}', 'Create Quote','glyphicon glyphicon-list-alt');
    $projectcostingdetail = $projectcosting->nested_table('Job Costing','pcid','projectcostingdetail','pcid');
   $projectcostingdetail->table_name('Costing and Pricing For Materials, Labour & Other Expenses');
$projectcostingdetail->relation('sales_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Sales'));
$projectcostingdetail->relation('cogs_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Cost of Goods Sold'));
$projectcostingdetail->column_pattern('projectcostingid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{projectcostingid}">{value}</a>');
//$projectcostingdetail->relation('job_costing_sheet_category','jc_stockcat','jsstockcatid','name');
//	$projectcostingdetail->relation('product_details_nonstock','jobcostingsheet','id',array('code','description'),'','','','','','jsstockcatid','job_costing_sheet_category');
//$projectcostingdetail->relation('unit_price','jobcostingsheet','id','landing_cost','','','','','','id','product_details_nonstock');
$projectcostingdetail->unset_csv();
$projectcostingdetail->unset_print();
$projectcostingdetail->show_primary_ai_column(true);
//stock

//$projectcostingdetail->relation('stock_details','stockmaster','stockid',array('stockid','description'),'','','','','','categoryid','job_costing_sheet_category');
//$projectcostingdetail->relation('stock_unit_cost','stockmaster','stockid','materialcost','','','','','','stockid','stock_details');

//$projectcostingdetail->fields('nonstockprice,stockprice,nonstockname,stockname',true);
//$projectcostingdetail->columns('nonstockprice,stockprice,nonstockname,stockname',true);
	$projectcosting->column_width('projectid','200px');
    $projectcostingdetail->change_type('cost_type','select','materials','materials,labour,others');
	//$projectcostingdetail->before_update('calculateprices','functionsprojectbudget.php');
	//$projectcostingdetail->before_insert('calculateprices','functionsprojectbudget.php');
	//$projectquote->set_attr('uom',array('onfocus'=>'myFunction()'));
	$projectcostingdetail->sum('total_cost,price');
	$projectcostingdetail->fields('entered_by',true);
$projectcostingdetail->label('price','Price VEP');
$projectcostingdetail->column_name('price','Price VEP');
$projectcostingdetail->column_name('pcid','Costing No:');
$projectcostingdetail->label('pcid','Costing No:');
 $projectcostingdetail->fields('pcid',true);
 $projectcostingdetail->columns('pcid',true);
//$projectcostingdetail->disabled('total_cost,price');
//$projectcostingdetail->column_name('unit_price','Non-Stock Unit Cost:');
//$projectcostingdetail->label('unit_price','Non-Stock Unit Cost:');
//$projectcostingdetail->change_type('other_description','select','CONTINGENCY','CONTINGENCY,BOARD/COUNTRY,MEALS,AIR/TRAVEL,VEHICLE,OTHER,A.T.S FEES,SCAFFOLDING,SHROULD,INDEX ENGRAVING,SHEDS,FREIGHT,CONCRETE CUT/BUILDERS,COMPRESSOR,SITE WELDING,12 MONTHS MAINTENANCE,BONDS,FPIS INSPECTION/ICONZ,AS BUILTS/MANUALS');

//$projectcostingdetail->column_name('stockprice','Stock Unit Sales Price:');
//$projectcostingdetail->label('stockprice','Stock Unit Sales Price:');

///$projectcostingdetail->column_name('nonstockprice','Non Stock Unit Sales Price:');
////$projectcostingdetail->label('nonstockprice','Non Stock Unit Sales Price:');
//$projectcostingdetail->column_name('nonstocknarrative','Non Stock Narration:');
//$projectcostingdetail->label('nonstocknarrative','Non Stock Narration:');

//$projectcostingdetail->column_name('stocknarrative','Stock Narration:');
//$projectcostingdetail->label('stocknarrative','Stock Narration:');


$projectcostingdetail->label('margin','Margin %');
$projectcostingdetail->pass_default('margin','40');
$projectcostingdetail->column_name('margin','Margin %');
$projectcostingdetail->change_type('total_cost,price,unit_price', 'price', '0', array('prefix'=>'$'));
//$projectcostingdetail->change_type('uom','select','each','each,hours,carton,bag,kg,litre,length,metres,feet');
$projectcostingdetail->before_update('updatebudgettotals','functionsprojectbudget.php'); 
$projectcostingdetail->before_insert('updatebudgettotals','functionsprojectbudget.php');
	



//$projectcostingdetail->relation('labor_type','jc_labortype','labortypeid','name');
//$projectcostingdetail->relation('labor_rate','jc_labortype','rate','rate','','','','','','labortypeid','labor_type');

$projectcostingdetail->show_primary_ai_column(true);
      //$projectquote->load_view('list','projectcosting.php');
	//$xcrud->pass_var('budgeted_total_cost', $sum);
	
	//$totalcostoverall = $projectcosting->sum('total_cost');
	
	
	
	
     // $xcrud->pass_var('budgeted_total_cost', $totalcostoverall);
	 
   // $xcrud->pass_var('budgeted_total_cost', $sum);
	
	
   //$projectactualperiod= $xcrud->nested_table('Actual Periods','projectid','projectactualperiod','projectid'); // 2nd level 2
  // $projectactualperiod->default_tab('Actual Period');
	//$projectactualperiod->table_name('Actual Project Costing');
	//$projectactualperiod->disabled('projectid,actual_material_cost,actual_labor_cost,actual_total_cost,sales_ratio,sales_revenue,margin');
	//$projectactualperiod->change_type('status','select','Setup','Setup,Quoted,Approved,Cancelled,Lost bid, Won Bid,Project Started');
	//$projectactualperiod->unset_numbers();
	//$projectactualperiod->show_primary_ai_column(true);

	
	//project stock

//$projectstock= $xcrud->nested_table('Project Stock Usage','projectid','project_stock','projectid'); // 2nd level 2
   //$projectstock->table_name('Stock Transfered to this Project');
	 
    $quotation = $xcrud->nested_table('Quotations','projectid','salesorders','job_no'); // 3rd level
 //$quotation->where('quotation=',1);
$quotation->label('orderno','Quote No');

$quotation->column_pattern('orderno', '<a href="#" class="xcrud-action" data-task="view" data-primary="{orderno}">{value}</a>');

$quotation->unset_add();
		 $quotation->unset_edit();
			    $quotation->unset_remove();

 $quotation->fields('orderno,amount,quotedate,preparedby,status',false);
 $quotation->columns('orderno,amount,quotedate,preparedby,status',false);
$quotation->table_name('Quotations');
$quotation->button('JCPrintQuote.php?orderno={orderno}', 'Re-Print Quote','glyphicon glyphicon-download-alt','approve');
$quotation->button('JCEmailQuote.php?orderno={orderno}', 'Email Quote','glyphicon glyphicon-envelope','payslipemail');
$quotation->button('JCAutoCreateInvoice.php?orderno={orderno}', 'Convert to Invoice','glyphicon glyphicon-list-alt','payslip');

	      $salesorderdetails = $quotation->nested_table('Salesdetails','orderno','salesorderdetails','orderno');
			  $salesorderdetails->unset_add();
			   $salesorderdetails->unset_edit();
			   $salesorderdetails->unset_remove();
$salesorderdetails->table_name('Quotation Line item Details');
     $salesorderdetails->fields('stkcode,stock_name,qtyinvoiced,unitprice,quantity,discountpercent,narrative,total',false);
 $salesorderdetails->columns('stkcode,stock_name,qtyinvoiced,unitprice,quantity,discountpercent,narrative,total',false);
$salesorderdetails->subselect('total','{unitprice}*{quantity}');
$salesorderdetails->sum('total');
$salesorderdetails->change_type('total,unitprice', 'price', '0', array('prefix'=>'$','decimals'=>'2'));

//invoices for reprinting
  $invoices = $xcrud->nested_table('Invoice','projectid','debtortrans','projectid'); // 3rd level
 //$invoices->where('quotation=',0);

//$invoices->column_pattern('orderno', '<a href="#" class="xcrud-action" data-task="view" data-primary="{orderno}">{value}</a>');
$invoices->unset_add();
		 $invoices->unset_edit();
			    $invoices->unset_remove();

 $invoices->fields('transno,order_,trandate,ovamount,vat,total_vip,alloc,ptax,retention',false);
 $invoices->columns('transno,order_,trandate,ovamount,vat,total_vip,alloc,ptax,retention',false);
$invoices->label('transno','Invoice no:');
$invoices->label('trandate','Dated:');
$invoices->label('order_','Quote No');
$invoices->table_name('Invoiced ');
$invoices->button('JCPrintInvoice.php?orderno={order_}&transno={transno}', 'Re-Print Invoice','glyphicon glyphicon-download-alt','westpac');
$invoices->button('JCEmailInvoice.php?orderno={order_}&transno={transno}', 'Email Invoice','glyphicon glyphicon-envelope','payslipemail');
$invoices->subselect('vat','{ovamount}*0.09');
	      
$invoices->subselect('total_vip','{ovamount}*1.09');

$invoices->sum('ovamount,vat,total_vip');
$invoices->change_type('ovamount,vat,total_vip', 'price', '0', array('prefix'=>'$','decimals'=>'2'));

    $purchaseorders = $xcrud->nested_table('Actual Material Cost Info','projectid','contractcharges','contractref'); // 3rd level
	        
			   $purchaseorders->unset_add();
			    $purchaseorders->unset_edit();
			    $purchaseorders->unset_remove();
				$purchaseorders->show_primary_ai_column(false);
 $purchaseorders->change_type('amount', 'price', '0', array('prefix'=>'$'));
			  $purchaseorders->sum('amount');
$purchaseorders->fields('transtype,transno',true);
 $purchaseorders->columns('transtype,transno',true);
$purchaseorders->label('contractref','Project/Job No');
$purchaseorders->column_name('contractref','Project/Job No');

//$purchaseorders->column_width('contractref','10%'); 
//$purchaseorders->column_width('date','20%'); 
//$purchaseorders->column_width('amount','10%'); 
$purchaseorders->column_width('narrative','80%'); 
//$purchaseorders->column_width('anticipated','10%'); 

    $timesheet = $xcrud->nested_table('Actual Labour Cost Info','projectid','techniciantimesheet','job_no'); // 4th level
	
	 $timesheet->unset_add();
			$timesheet->unset_edit();
			 $timesheet->unset_remove();
$timesheet->show_primary_ai_column(true);
     $timesheetdetails = $timesheet ->nested_table('Employee Timesheet','techtimeid','techniciantimesheetdetails','techtimeid');

$timesheetdetails->unset_add();
			$timesheetdetails->unset_edit();
			 $timesheetdetails->unset_remove();

$timesheetdetails->table_name('Technician Scheduling hours');
    $timesheetdetails->relation('employeeid','employeemaster','employeeid',array('employeeid','full_name'));
	
	//$techtimesheetdetails->show_primary_ai_column(true);
	
	//$techtimesheetdetails->after_insert('checkpublicholiday','functionstechtimesheet.php');
	//$techtimesheetdetails->after_update('checkpublicholiday','functionstechtimesheet.php');
	$progressive = $xcrud->nested_table('Progressive Billing','projectid','progressive_billing','projectid'); // 6th level
	$progressive->change_type('actual_material,actual_labor,actual_others,total_actual_cost,billing_amount_vep,billing_amount_vip', 'price', '0', array('prefix'=>'$'));

 $progressive->change_type('status','select','drafting','drafting,approved,invoiced,sent email,paid');
//$progressive->pass_default('margin','40');
$progressive->disabled('actual_material,actual_labor');
$progressive->relation('costing_no','projectcosting','pcid',array('pcid','name'),array('projectid' => '{projectid}'));
$progressive->before_update('actualcosting','functionsprojectbudget.php'); 
$progressive->before_insert('actualcosting','functionsprojectbudget.php');
	$progressive->button('ProgressiveInvoicing.php?id={pgid}&projectid={projectid}', 'Raise Invoice','glyphicon glyphicon-list-alt');
$progressive->column_pattern('pgid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{pgid}">{value}</a>');

$adjustments = $progressive->nested_table('Cost Adjustments','pgid','projectadjustments','pgid'); // 6th level
	 //$adjustments->unset_add();
			$adjustments->unset_edit();
			$adjustments->unset_remove();
$adjustments->change_type('sector','select','Project Manager','Project Manager,Finance Team');
$adjustments->change_type('amount', 'price', '0', array('prefix'=>'$'));
$adjustments->disabled('costed_by');
   $adjustments->pass_var('costed_by',$userid);
$adjustments->before_update('actualcostadjustments','functionsprojectbudget.php'); 
$adjustments->before_insert('actualcostadjustments','functionsprojectbudget.php');
$stock = $xcrud->nested_table('Stock Usage','projectid','project_stock','projectid'); // 6th level
$stock->unset_edit();
$stock->unset_remove();
$stock->unset_add();


    echo $xcrud->render();
}
elseif ($userid == 'charles'  ) { 
	
	 include('xcrud/xcrud.php');
    $xcrud = Xcrud::get_instance();
    $xcrud->table('projectdetails');
$xcrud->where('department', 'SecurityInstalls-West');
    $xcrud->default_tab('Project info');
	$xcrud->table_name('Project Management/Job Costing/WIP Processing');
	//Xcrud_config::$editor_url = dirname($_SERVER["SCRIPT_NAME"]).'/editors/ckeditor/ckeditor.js'; 
	$xcrud->disabled('age,department');
$userid = $_SESSION['UserID'];
$xcrud->pass_default('department','SecurityInstalls-West');
$xcrud->pass_var('department','SecurityInstalls-West');
$xcrud->pass_var('managed_by',$userid);
	$xcrud->unset_numbers();
	$xcrud->show_primary_ai_column(true);
	$xcrud->order_by('projectid','desc');
	//$xcrud->columns('projectid',false);
	$xcrud->column_name('projectid','Projectid/jobno');
	$xcrud->change_type('project_type','select','Small Jobs','Small Jobs,Contract');
	
	//$xcrud->set_attr('project_type',array('onfocus'=>'alert("Hello Man!"'));
	//$xcrud->relation('divisionid','division','divisionid','name');
	//$xcrud->relation('department','department','departmentid','departmentname');
	$xcrud->relation('customer','debtorsmaster','debtorno','name');
$xcrud->relation('branch','custbranch','debtorno','brname','','','','','','debtorno','customer');
   $xcrud->relation('sys_account_number','debtoraccount','account_number','account_number','','','','','','debtorno','customer');
	$xcrud->column_pattern('projectid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{projectid}">{value}</a>');
	$xcrud->relation('project_manager','employeemaster','employeeid','full_name');
	$xcrud->relation('sales_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Sales'));
$xcrud->relation('cogs_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Cost of Goods Sold'));
	//$xcrud->column_name('margin','Margin-(Percentage)');
    $xcrud->change_type('status','select','Setup','Setup,Tender Yet to be Awarded,Quoted,Approved,Cancelled,Lost bid, Won Bid,Project Started');
$xcrud->relation('department','department','departmentname','departmentname');
$xcrud->before_insert('updateaccountnumber','functionsproject.php');
$xcrud->before_update('updateaccountnumber','functionsproject.php');
$userid = $_SESSION['UserID'];
$xcrud->pass_var('managed_by',$userid);

//$xcrud->before_update('getdepartment','functionsprojectbudget.php');
	//$xcrud->before_insert('getdepartment','functionsprojectbudget.php');
	//$xcrud->columns('budgeted_profit',true);
	//$xcrud->subselect('Budgeted Profit','{budgeted_total_price}-{budgeted_total_cost}');
	//$totalprice = $xcrud->subselect('profit','{budgeted_total_price}-{budgeted_total_cost}');
	//$xcrud->highlight('Budgeted Profit','>','0','yellow');
	//$xcrud->highlight('Budgeted Profit','<','0','red');
	
	//$xcrud->column_callback('budgeted_profit','profit','functionsprojectbudget.php');
	//		$db8000 = Xcrud_db::get_instance();
	 //   $query = "SELECT projectid, budgeted_total_cost,budgeted_total_price,budgeted_profit
				   			  
		//          FROM projectdetails";
				  
				  
				  	 	   
        
    //    $db8000 ->query($query);
     //   $out8000  = $db8000 ->result();
      //  foreach($out8000  as $output8000){
       //     $totalbudgetedcost = $output8000 ['budgeted_total_cost'];
		//	$totalbudgetedprice = $output8000 ['budgeted_total_price'];
			
		//	$profit = $totalbudgetedprice - $totalbudgetedcost;
			
			
	
	
	//$query2 = "UPDATE projectdetails SET budgeted_profit = '" . $profit."'";
	//$db8000->query($query2);
			
	//	} 
	
	
	
	
	//1.5 level
	$projectattachment = $xcrud->nested_table('Project/Contract Attachements','projectid','projectattachments','projectid');
	
	$projectattachment->change_type('file', 'file', '', array('not_rename'=>true));
	
    $projectcosting = $xcrud->nested_table('Project Costing/Budgeting','projectid','projectcosting','projectid'); // 2nd level
	
	//$projectcosting->unset_numbers();
	$projectcosting->table_name('Project/Contract Budget Costing');
	$projectcosting->disabled('projectid,budgeted_material,budgeted_labor,budgeted_others,budgeted_total_cost,contract_value,contract_vip');
     $projectcosting->show_primary_ai_column(true);
 $projectcosting->fields('contractvalue1,contractvalue2',true);
 $projectcosting->columns('contractvalue1,contractvalue2',true);
$projectcosting->label('contract_value','Contract Value(VEP)');
$projectcosting->column_name('projectid','Job No:');
$projectcosting->label('projectid','Job No:');
$projectcosting->column_name('pcid','Costing No:');
//$projectcosting->fields('budgeted_material,budgeted_labor,budgeted_others,budgeted_total_cost,contractvalue1,contractvalue2,contract_value,contract_vip',true);
//$projectcosting->columns('budgeted_material,budgeted_labor,budgeted_others,budgeted_total_cost,contractvalue1,contractvalue2,contract_value,contract_vip',true);
$projectcosting->label('pcid','Costing No:');
 //$projectcosting->before_insert('getprojectname','functionsprojectbudget.php');
//$projectcosting->before_update('getprojectname','functionsprojectbudget.php');
//$projectcosting->before_list('getbudgetedtotals','functionsprojectbudget.php');
$projectcosting->column_pattern('pcid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{pcid}">{value}</a>');
//$projectcosting->change_type('GL_category','select','All','All,Access Systems,Alarm,Annual Survey,Brigade,CCTV,Fire Extinguisher,ID Card,Metabilt Door,Service Fees,Others,Sprinkler');


$projectcosting->change_type('status','select','drafting','drafting,approved costing,cancelled costing,sent quotation,quote accepted by customer,quote not accepted,job started, job completed');

//$projectcosting->change_type('contract_vip,budgeted_material,budgeted_others,budgeted_labor,contract_value, budgeted_total_cost,estimated_profit', 'price', '0', array('prefix'=>'$'));
//$projectcosting->subselect('Budgeted Profit','{contract_value}-{budgeted_total_cost}');
//$projectcosting->load_view('edit','projectcosting.php');
//$projectcosting->load_view('create','projectcosting.php');
$projectcosting->order_by('pcid','desc');

 $projectcosting->button('JCAutoCreateQuote1.php?pcid={pcid}&projectid={projectid}', 'Create Quote','glyphicon glyphicon-list-alt');
    $projectcostingdetail = $projectcosting->nested_table('Job Costing','pcid','projectcostingdetail','pcid');
   $projectcostingdetail->table_name('Costing and Pricing For Materials, Labour & Other Expenses');
$projectcostingdetail->relation('sales_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Sales'));
$projectcostingdetail->relation('cogs_gl','chartmaster','accountcode',array('accountcode','accountname'),array('group_' => 'Cost of Goods Sold'));
$projectcostingdetail->column_pattern('projectcostingid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{projectcostingid}">{value}</a>');
//$projectcostingdetail->relation('job_costing_sheet_category','jc_stockcat','jsstockcatid','name');
//	$projectcostingdetail->relation('product_details_nonstock','jobcostingsheet','id',array('code','description'),'','','','','','jsstockcatid','job_costing_sheet_category');
//$projectcostingdetail->relation('unit_price','jobcostingsheet','id','landing_cost','','','','','','id','product_details_nonstock');
$projectcostingdetail->unset_csv();
$projectcostingdetail->unset_print();
$projectcostingdetail->show_primary_ai_column(true);
//stock

//$projectcostingdetail->relation('stock_details','stockmaster','stockid',array('stockid','description'),'','','','','','categoryid','job_costing_sheet_category');
//$projectcostingdetail->relation('stock_unit_cost','stockmaster','stockid','materialcost','','','','','','stockid','stock_details');

//$projectcostingdetail->fields('nonstockprice,stockprice,nonstockname,stockname',true);
//$projectcostingdetail->columns('nonstockprice,stockprice,nonstockname,stockname',true);
	$projectcosting->column_width('projectid','200px');
    $projectcostingdetail->change_type('cost_type','select','materials','materials,labour,others');
	//$projectcostingdetail->before_update('calculateprices','functionsprojectbudget.php');
	//$projectcostingdetail->before_insert('calculateprices','functionsprojectbudget.php');
	//$projectquote->set_attr('uom',array('onfocus'=>'myFunction()'));
	$projectcostingdetail->sum('total_cost,price');
	$projectcostingdetail->fields('entered_by',true);
$projectcostingdetail->label('price','Price VEP');
$projectcostingdetail->column_name('price','Price VEP');
$projectcostingdetail->column_name('pcid','Costing No:');
$projectcostingdetail->label('pcid','Costing No:');
 $projectcostingdetail->fields('pcid',true);
 $projectcostingdetail->columns('pcid',true);
//$projectcostingdetail->disabled('total_cost,price');
//$projectcostingdetail->column_name('unit_price','Non-Stock Unit Cost:');
//$projectcostingdetail->label('unit_price','Non-Stock Unit Cost:');
//$projectcostingdetail->change_type('other_description','select','CONTINGENCY','CONTINGENCY,BOARD/COUNTRY,MEALS,AIR/TRAVEL,VEHICLE,OTHER,A.T.S FEES,SCAFFOLDING,SHROULD,INDEX ENGRAVING,SHEDS,FREIGHT,CONCRETE CUT/BUILDERS,COMPRESSOR,SITE WELDING,12 MONTHS MAINTENANCE,BONDS,FPIS INSPECTION/ICONZ,AS BUILTS/MANUALS');

//$projectcostingdetail->column_name('stockprice','Stock Unit Sales Price:');
//$projectcostingdetail->label('stockprice','Stock Unit Sales Price:');

///$projectcostingdetail->column_name('nonstockprice','Non Stock Unit Sales Price:');
////$projectcostingdetail->label('nonstockprice','Non Stock Unit Sales Price:');
//$projectcostingdetail->column_name('nonstocknarrative','Non Stock Narration:');
//$projectcostingdetail->label('nonstocknarrative','Non Stock Narration:');

//$projectcostingdetail->column_name('stocknarrative','Stock Narration:');
//$projectcostingdetail->label('stocknarrative','Stock Narration:');


$projectcostingdetail->label('margin','Margin %');
$projectcostingdetail->pass_default('margin','40');
$projectcostingdetail->column_name('margin','Margin %');
$projectcostingdetail->change_type('total_cost,price,unit_price', 'price', '0', array('prefix'=>'$'));
//$projectcostingdetail->change_type('uom','select','each','each,hours,carton,bag,kg,litre,length,metres,feet');
$projectcostingdetail->before_update('updatebudgettotals','functionsprojectbudget.php'); 
$projectcostingdetail->before_insert('updatebudgettotals','functionsprojectbudget.php');
	



//$projectcostingdetail->relation('labor_type','jc_labortype','labortypeid','name');
//$projectcostingdetail->relation('labor_rate','jc_labortype','rate','rate','','','','','','labortypeid','labor_type');

$projectcostingdetail->show_primary_ai_column(true);
      //$projectquote->load_view('list','projectcosting.php');
	//$xcrud->pass_var('budgeted_total_cost', $sum);
	
	//$totalcostoverall = $projectcosting->sum('total_cost');
	
	
	
	
     // $xcrud->pass_var('budgeted_total_cost', $totalcostoverall);
	 
   // $xcrud->pass_var('budgeted_total_cost', $sum);
	
	
   //$projectactualperiod= $xcrud->nested_table('Actual Periods','projectid','projectactualperiod','projectid'); // 2nd level 2
  // $projectactualperiod->default_tab('Actual Period');
	//$projectactualperiod->table_name('Actual Project Costing');
	//$projectactualperiod->disabled('projectid,actual_material_cost,actual_labor_cost,actual_total_cost,sales_ratio,sales_revenue,margin');
	//$projectactualperiod->change_type('status','select','Setup','Setup,Quoted,Approved,Cancelled,Lost bid, Won Bid,Project Started');
	//$projectactualperiod->unset_numbers();
	//$projectactualperiod->show_primary_ai_column(true);

	
	//project stock

//$projectstock= $xcrud->nested_table('Project Stock Usage','projectid','project_stock','projectid'); // 2nd level 2
   //$projectstock->table_name('Stock Transfered to this Project');
	 
    $quotation = $xcrud->nested_table('Quotations','projectid','salesorders','job_no'); // 3rd level
 //$quotation->where('quotation=',1);
$quotation->label('orderno','Quote No');

$quotation->column_pattern('orderno', '<a href="#" class="xcrud-action" data-task="view" data-primary="{orderno}">{value}</a>');

$quotation->unset_add();
		 $quotation->unset_edit();
			    $quotation->unset_remove();

 $quotation->fields('orderno,amount,quotedate,preparedby,status',false);
 $quotation->columns('orderno,amount,quotedate,preparedby,status',false);
$quotation->table_name('Quotations');
$quotation->button('JCPrintQuote.php?orderno={orderno}', 'Re-Print Quote','glyphicon glyphicon-download-alt','approve');
$quotation->button('JCEmailQuote.php?orderno={orderno}', 'Email Quote','glyphicon glyphicon-envelope','payslipemail');
$quotation->button('JCAutoCreateInvoice.php?orderno={orderno}', 'Convert to Invoice','glyphicon glyphicon-list-alt','payslip');

	      $salesorderdetails = $quotation->nested_table('Salesdetails','orderno','salesorderdetails','orderno');
			  $salesorderdetails->unset_add();
			   $salesorderdetails->unset_edit();
			   $salesorderdetails->unset_remove();
$salesorderdetails->table_name('Quotation Line item Details');
     $salesorderdetails->fields('stkcode,stock_name,qtyinvoiced,unitprice,quantity,discountpercent,narrative,total',false);
 $salesorderdetails->columns('stkcode,stock_name,qtyinvoiced,unitprice,quantity,discountpercent,narrative,total',false);
$salesorderdetails->subselect('total','{unitprice}*{quantity}');
$salesorderdetails->sum('total');
$salesorderdetails->change_type('total,unitprice', 'price', '0', array('prefix'=>'$','decimals'=>'2'));

//invoices for reprinting
  $invoices = $xcrud->nested_table('Invoice','projectid','debtortrans','projectid'); // 3rd level
 //$invoices->where('quotation=',0);

//$invoices->column_pattern('orderno', '<a href="#" class="xcrud-action" data-task="view" data-primary="{orderno}">{value}</a>');
$invoices->unset_add();
		 $invoices->unset_edit();
			    $invoices->unset_remove();

 $invoices->fields('transno,order_,trandate,ovamount,vat,total_vip,alloc,ptax,retention',false);
 $invoices->columns('transno,order_,trandate,ovamount,vat,total_vip,alloc,ptax,retention',false);
$invoices->label('transno','Invoice no:');
$invoices->label('trandate','Dated:');
$invoices->label('order_','Quote No');
$invoices->table_name('Invoiced ');
$invoices->button('JCPrintInvoice.php?orderno={order_}&transno={transno}', 'Re-Print Invoice','glyphicon glyphicon-download-alt','westpac');
$invoices->button('JCEmailInvoice.php?orderno={order_}&transno={transno}', 'Email Invoice','glyphicon glyphicon-envelope','payslipemail');
$invoices->subselect('vat','{ovamount}*0.09');
	      
$invoices->subselect('total_vip','{ovamount}*1.09');

$invoices->sum('ovamount,vat,total_vip');
$invoices->change_type('ovamount,vat,total_vip', 'price', '0', array('prefix'=>'$','decimals'=>'2'));

    $purchaseorders = $xcrud->nested_table('Actual Material Cost Info','projectid','contractcharges','contractref'); // 3rd level
	        
			   $purchaseorders->unset_add();
			    $purchaseorders->unset_edit();
			    $purchaseorders->unset_remove();
				$purchaseorders->show_primary_ai_column(false);
 $purchaseorders->change_type('amount', 'price', '0', array('prefix'=>'$'));
			  $purchaseorders->sum('amount');
$purchaseorders->fields('transtype,transno',true);
 $purchaseorders->columns('transtype,transno',true);
$purchaseorders->label('contractref','Project/Job No');
$purchaseorders->column_name('contractref','Project/Job No');

//$purchaseorders->column_width('contractref','10%'); 
//$purchaseorders->column_width('date','20%'); 
//$purchaseorders->column_width('amount','10%'); 
$purchaseorders->column_width('narrative','80%'); 
//$purchaseorders->column_width('anticipated','10%'); 

    $timesheet = $xcrud->nested_table('Actual Labour Cost Info','projectid','techniciantimesheet','job_no'); // 4th level
	
	 $timesheet->unset_add();
			$timesheet->unset_edit();
			 $timesheet->unset_remove();
$timesheet->show_primary_ai_column(true);
     $timesheetdetails = $timesheet ->nested_table('Employee Timesheet','techtimeid','techniciantimesheetdetails','techtimeid');

$timesheetdetails->unset_add();
			$timesheetdetails->unset_edit();
			 $timesheetdetails->unset_remove();

$timesheetdetails->table_name('Technician Scheduling hours');
    $timesheetdetails->relation('employeeid','employeemaster','employeeid',array('employeeid','full_name'));
	
	//$techtimesheetdetails->show_primary_ai_column(true);
	
	//$techtimesheetdetails->after_insert('checkpublicholiday','functionstechtimesheet.php');
	//$techtimesheetdetails->after_update('checkpublicholiday','functionstechtimesheet.php');
	$progressive = $xcrud->nested_table('Progressive Billing','projectid','progressive_billing','projectid'); // 6th level
	$progressive->change_type('actual_material,actual_labor,actual_others,total_actual_cost,billing_amount_vep,billing_amount_vip', 'price', '0', array('prefix'=>'$'));

 $progressive->change_type('status','select','drafting','drafting,approved,invoiced,sent email,paid');
//$progressive->pass_default('margin','40');
$progressive->disabled('actual_material,actual_labor');
$progressive->relation('costing_no','projectcosting','pcid',array('pcid','name'),array('projectid' => '{projectid}'));
$progressive->before_update('actualcosting','functionsprojectbudget.php'); 
$progressive->before_insert('actualcosting','functionsprojectbudget.php');
	$progressive->button('ProgressiveInvoicing.php?id={pgid}&projectid={projectid}', 'Raise Invoice','glyphicon glyphicon-list-alt');
$progressive->column_pattern('pgid', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{pgid}">{value}</a>');

$adjustments = $progressive->nested_table('Cost Adjustments','pgid','projectadjustments','pgid'); // 6th level
	 //$adjustments->unset_add();
			$adjustments->unset_edit();
			$adjustments->unset_remove();
$adjustments->change_type('sector','select','Project Manager','Project Manager,Finance Team');
$adjustments->change_type('amount', 'price', '0', array('prefix'=>'$'));
$adjustments->disabled('costed_by');
   $adjustments->pass_var('costed_by',$userid);
$adjustments->before_update('actualcostadjustments','functionsprojectbudget.php'); 
$adjustments->before_insert('actualcostadjustments','functionsprojectbudget.php');
$stock = $xcrud->nested_table('Stock Usage','projectid','project_stock','projectid'); // 6th level
$stock->unset_edit();
$stock->unset_remove();
$stock->unset_add();


    echo $xcrud->render();
}
else 
	echo "Not Authorised";

echo '</div>';
echo '</div>';

include('includes/footer.inc'); 

?>