<?php

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

include('includes/session.inc');
$Title = _('Guards Billing');
$ViewTopic= 'GuardsBilling';
$BookMark = 'GuardsBilling';
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 '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/maintenance.png"> </p>';
      
	echo '<div class="col-sm-9">';
		
    include('xcrud/xcrud.php');
    $xcrud = Xcrud::get_instance();
	$xcrud->table('guards_billing');
	
	$xcrud->order_by('gbill_id','desc');
	
    $xcrud->default_tab('Billing Profile');
    $xcrud->table_name('Guards Billing Module');

    $xcrud->button('GBillingInvoice.php?bill_id={bill_id}', 'Create Invoice','glyphicon glyphicon-list-alt');

//second level table configurations
	$rostering_timesheet = $xcrud->nested_table('Guards Billing Items','gbill_id','guards_bill_items','gbill_id'); 
	       

              //$pool->relation('employeeid','employeemaster','employeeid',array('first_name','last_name','employeeid'));




	//$rostering_timesheet->relation('tues_shift2','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->relation('wed_shift','shifts','shiftid','shiftplushours');
//$rostering_timesheet->relation('wed_shift2','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->relation('thurs_shift','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->relation('thurs_shift2','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->relation('fri_shift','shifts','shiftid','shiftplushours');
//$rostering_timesheet->relation('fri_shift2','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->relation('sat_shift','shifts','shiftid','shiftplushours');
//$rostering_timesheet->relation('sat_shift2','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->relation('sun_shift','shifts','shiftid','shiftplushours');
//$rostering_timesheet->relation('sun_shift2','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->relation('mon_shift_2','shifts','shiftid','shiftplushours');
//$rostering_timesheet->relation('mon_shift_2_2','shifts','shiftid','shiftplushours');
	//$rostering_timesheet->change_type('mon_shift','select','3pm-7pm','3pm-7pm,9am-12pm');
	 
 
	
	
     //$rostering_timesheet->relation('mon_hrs','shifts','shiftid','hours','','','','','','shiftid','mon_shift');
	 
	 
	 $rostering_timesheet->before_insert('calculate_total','functiongbilling.php');
	$rostering_timesheet->before_update('calculate_total','functiongbilling.php');
	
	//$rostering_timesheet->pass_var('montime_in', 'NOW()');
    //$rostering_timesheet->no_quotes('montime_in');
	
	
	
//$rostering_timesheet->column_width('mon_hrs,tues_hrs,wed_hrs,thurs_hrs,fri_hrs,sat_hrs,sun_hrs,mon_hrs_2,mon_hrs2,tues_hrs2,wed_hrs2,thurs_hrs2,fri_hrs2,sat_hrs2,sun_hrs2,mon_hrs_2_2','5px');
	//$rostering_timesheet->column_width('mon_shift,tues_shift,wed_shift,thurs_shift,fri_shift,sat_shift,sun_shift,mon_shift_2','95px');
	//$rostering_timesheet->column_width('total_hrs','20px');
	//$rostering_timesheet->fields('mon_hrs,mon_total,tues_hrs,tues_total,wed_hrs,wed_total,thurs_hrs,thurs_total,fri_hrs,fri_total,sat_hrs,sat_total,sun_hrs,sun_total,mon_hrs_2,mon2_total,mon_hrs2,tues_hrs2,wed_hrs2,thurs_hrs2,fri_hrs2,sat_hrs2,sun_hrs2,mon_hrs_2_2', true);
	//$rostering_timesheet->validation_required('employeeid');
	
	//check whether total hours doesnt exceel employees max hours allowed to work. checking with employeemaster database.

	
	//grid coloring based on shift table
	
	



	//$rostering_timesheet->highlight('mon_hrs','=','{mon_hrs}',$mon_color);
	
	
//$rostering_timesheet->before_insert('gridcolor');
//$rostering_timesheet->before_update('gridcolor');
	
	
	//calculate total employee hours per week
//$rostering_timesheet->before_list('highlightcell');




//$rostering_timesheet->before_insert('calculate_totalhoursperweek');
//$rostering_timesheet->before_update('calculate_totalhoursperweek');

//$rostering_timesheet->field_callback('total_hrs','validate_maxhours');

//$rostering_timesheet->before_insert('validate_maxhours');
//$rostering_timesheet->before_update('validate_maxhours');

	//$rostering_timesheet->table_name('Employee Schedulling');
	
	//calculate total  hours per per each day
	
   //$rostering_timesheet->sum('mon_total,tues_total,wed_total,thurs_total,fri_total,sat_total,sun_total,mon2_total,total_hrs,normal_hours,time_half_hours,double_hours');
 //  $rostering_timesheet->change_type('uom','select','draft','draft,approved,locked');
   $rostering_timesheet->relation('uom','unitsofmeasure','unitname','unitname');
   $rostering_timesheet->sum('total');
	
	

    $xcrud->change_type('status','select','draft','draft,approved,locked');
   $xcrud->change_type('month','select','January','January,Febuary,March,April,May,June,July,August,September,October,November,December');
$xcrud->change_type('year','select','2018',',2018,2018,2019,2020,2021');
	$xcrud->disabled('modified_by');

	//$approvedby=stripslashes($_SESSION['UsersRealName']);
	//$rostering_timesheet->columns('approved_by',true);
     $xcrud->relation('customer','debtorsmaster','debtorno','name');
$xcrud->relation('branchcode','custbranch','branchcode',array('branchcode','brname'),'','','','','','debtorno','customer');
//$xcrud->relation('account_number','debtoraccount','account_number','account_number','','','','','','debtorno','customer');
	//$rostering_timesheet->fields('approved_by',true);
	
	//$rostering_timesheet->validation_required(array('period' => 1,'start_date','end_date','cl'));
	//$rostering_timesheet->duplicate_button();
	//	$rostering_timesheet->unset_print();
     //   $rostering_timesheet->unset_csv();
	//$rostering_timesheet->benchmark(true);
	
	//validate max hours for employees
	
//$rostering_timesheet->after_insert('after');
//$rostering_timesheet->after_update('after');

    $xcrud->show_primary_ai_column(true);
    $xcrud->column_pattern('gbill_id', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{gbill_id}">{value}</a>');
	//$xcrud->load_view('create','rostering.php'); 
   // $xcrud->load_view('edit','rostering.php');
	

//$xcrud->before_insert('poolguardcreation');



$userid = $_SESSION['UserID'];

	$sql = "SELECT department
			FROM www_users  
			WHERE userid ='" . $userid . "'";

	$result = DB_query($sql);
    $myrow = DB_fetch_array($result);
   $department = $myrow['department'];
$xcrud->pass_var('modified_by',$userid );
$xcrud->pass_var('department',$department );
  $xcrud->relation('department','department','departmentid','departmentname');
$xcrud->change_type('month','select','January','January,Febuary,March,April,May,June,July,August,September,October,November,December');
$xcrud->change_type('year','select','2018',',2018,2019,2020,2021,2022,2023,2024');
//$timenow = date('Y-m-d H:i:s');

	//$xcrud->pass_var('created_date',$timenow);

 $rostering_timesheet->pass_var('entered_by',$userid);

 $attachments = $xcrud->nested_table('Attachments','gbill_id','guards_bill_files','gbill_id'); 
$attachments->change_type('file', 'file', '', array('not_rename'=>true));

  $invoices = $xcrud->nested_table('Invoices','bill_id','debtortrans','bill_id'); // 3rd level
 //$invoices->where('quotation=',0);

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

 $invoices->fields('transno,bill_id,order_,trandate,ovamount,vat,total_vip,alloc,ptax',false);
 $invoices->columns('transno,bill_id,order_,trandate,ovamount,vat,total_vip,alloc,ptax',false);
$invoices->label('transno','Invoice no:');
$invoices->label('trandate','Dated:');
$invoices->label('order_','Order_no');
$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'));

$invoices->table_name('Invoices ');
$invoices->button('GBillingPrintInvoice.php?orderno={order_}&transno={transno}', 'Re-Print Invoice','glyphicon glyphicon-download-alt');

$salesorderdetails = $invoices->nested_table('Invoice Details','order_','salesorderdetails','orderno');
			  $salesorderdetails->unset_add();
			   $salesorderdetails->unset_edit();
			   $salesorderdetails->unset_remove();
$salesorderdetails->table_name('Invoice Line Item Details');
     $salesorderdetails->fields('stkcode,stock_name,qtyinvoiced,unitprice,quantity,discountpercent,narrative,total,Vat,VIP',false);
 $salesorderdetails->columns('stkcode,stock_name,qtyinvoiced,unitprice,quantity,discountpercent,narrative,total,Vat,VIP',false);
$salesorderdetails->subselect('total','{unitprice}*{quantity}');
$salesorderdetails->subselect('Vat','{total}*0.09');
$salesorderdetails->subselect('VIP','{total}*1.09');
$salesorderdetails->sum('total,Vat,VIP');
$salesorderdetails->change_type('total,unitprice,Vat,VIP', 'price', '0', array('prefix'=>'$','decimals'=>'2'));
	echo $xcrud->render();



	

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

include('includes/footer.inc'); 

?>

