<?php
function updateaccountnumber($postdata,$xcrud){
	$ac = $postdata->get('account_number');
	$sysac = $postdata->get('sys_account_number');
	
	if (!isset($ac) OR $ac =='') {
	$postdata->set('account_number', $sysac);
	
	}


	
}
function AddGLBalance($postdata,$xcrud){
	
	
	$id = $postdata->get('calendar_id');
		$glmonth = $postdata->get('gl_month');
		$glcode = $postdata->get('glcode');
		$totalgl = $postdata->get('amount');
	
	
	
			//update ytd balances in gl balance table
		if ($glmonth  =='jan'){
						
						
						$sql399 = "UPDATE ytd_glbalances SET  
												  jan= jan + '".$totalgl."'
						WHERE gl_code= '" . $glcode . "'
						AND calendar_id = '".$id."'";

			  

			$ErrMsg = _('The customer could not be updated because');
			$result399 = DB_query($sql399,$ErrMsg);

					}
		if ($glmonth  =='feb'){
						
						
						$sql399 = "UPDATE ytd_glbalances SET  
												  feb= feb +'".$totalgl."'
						WHERE gl_code= '" . $glcode . "'
						AND calendar_id = '".$id."'";

			  

			$ErrMsg = _('The customer could not be updated because');
			$result399 = DB_query($sql399,$ErrMsg);

					}
		if ($glmonth  =='mar'){
						
						
						$sql399 = "UPDATE ytd_glbalances SET  
												  mar= mar +'".$totalgl."'
						WHERE gl_code= '" . $glcode . "'
						AND calendar_id = '".$id."'";

			  

			$ErrMsg = _('The customer could not be updated because');
			$result399 = DB_query($sql399,$ErrMsg);

					}
		
		if ($glmonth  =='apr'){
						
						
						$sql399 = "UPDATE ytd_glbalances SET  
												  apr= apr +'".$totalgl."'
						WHERE gl_code= '" . $glcode . "'
						AND calendar_id = '".$id."'";

			  

			$ErrMsg = _('The customer could not be updated because');
			$result399 = DB_query($sql399,$ErrMsg);

					}
		if ($glmonth  =='may'){
						
						
						$sql399 = "UPDATE ytd_glbalances SET  
												  may= may + '".$totalgl."'
						WHERE gl_code= '" . $glcode . "'
						AND calendar_id = '".$id."'";

			  

			$ErrMsg = _('The customer could not be updated because');
			$result399 = DB_query($sql399,$ErrMsg);

					}
		
		if ($glmonth  =='june'){
						
						
						$sql399 = "UPDATE ytd_glbalances SET  
												  june= june +'".$totalgl."'
						WHERE gl_code= '" . $glcode . "'
						AND calendar_id = '".$id."'";

			  

			$ErrMsg = _('The customer could not be updated because');
			$result399 = DB_query($sql399,$ErrMsg);

					}
		if ($glmonth  =='july'){
						
						
						$sql399 = "UPDATE ytd_glbalances SET  
												  july= july + '".$totalgl."'
						WHERE gl_code= '" . $glcode . "'
						AND calendar_id = '".$id."'";

			  

			$ErrMsg = _('The customer could not be updated because');
			$result399 = DB_query($sql399,$ErrMsg);

					}
		
		if ($glmonth  =='aug'){
						
						
						$sql399 = "UPDATE ytd_glbalances SET  
												  aug= aug + '".$totalgl."'
						WHERE gl_code= '" . $glcode . "'
						AND calendar_id = '".$id."'";

			  

			$ErrMsg = _('The customer could not be updated because');
			$result399 = DB_query($sql399,$ErrMsg);

					}
		if ($glmonth  =='sept'){
						
						
						$sql399 = "UPDATE ytd_glbalances SET  
												  sept= sept + '".$totalgl."'
						WHERE gl_code= '" . $glcode . "'
						AND calendar_id = '".$id."'";

			  

			$ErrMsg = _('The customer could not be updated because');
			$result399 = DB_query($sql399,$ErrMsg);

					}

		if ($glmonth  =='oct'){
						
						
						$sql399 = "UPDATE ytd_glbalances SET  
												  oct= oct + '".$totalgl."'
						WHERE gl_code= '" . $glcode . "'
						AND calendar_id = '".$id."'";

			  

			$ErrMsg = _('The customer could not be updated because');
			$result399 = DB_query($sql399,$ErrMsg);

					}
		if ($glmonth  =='nov'){
						
						
						$sql399 = "UPDATE ytd_glbalances SET  
												  nov= nov + '".$totalgl."'
						WHERE gl_code= '" . $glcode . "'
						AND calendar_id = '".$id."'";

			  

			$ErrMsg = _('The customer could not be updated because');
			$result399 = DB_query($sql399,$ErrMsg);

					}
		if ($glmonth  =='dec'){
						
						
						$sql399 = "UPDATE ytd_glbalances SET  
												  dec= dec + '".$totalgl."'
						WHERE gl_code= '" . $glcode . "'
						AND calendar_id = '".$id."'";

			  

			$ErrMsg = _('The customer could not be updated because');
			$result399 = DB_query($sql399,$ErrMsg);

					}
		

	
}
function calculatetotalhours($postdata,$xcrud){
	
	$montime_in = $postdata->get('time_in');
	$montime_out = $postdata->get('time_out');
	
	
	
	
	
	$monhours = abs(strtotime($montime_in) - strtotime($montime_out)) / 3600;
		
    $postdata->set('hrs_worked', $monhours);
	
	  $postdata->set('billable_hrs', $monhours);
	
}