0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 3.142.55.138


Current Path : /proc/thread-self/root/var/www/oasis/src/
Upload File :
Current File : //proc/thread-self/root/var/www/oasis/src/report_tool.php

<?php
/*Author : M.Srikanth   
    Date    :  2009-07-30
    Project :  Reporting tool (Frame Work)
    Description :  This class is for dynamically to create reports
*/

//Start :  'reporttool'  Class 

					
$my_aobj_context;					

	class reporttool 
	{
	  	
		public $report_setup;
		//Start :  Constructor
	           function __construct($aobj_context)
	              {
		              session_start();
		              $this->aobj_context=$aobj_context;
		              $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);
		              $this->user_id = $_SESSION['user_id'];
					  $this->save_cond_flag = 0 ;
					 $my_aobj_context = $this->aobj_context;
					   $this->setup_name = '';
		           }
		//End : Constructor 
		
		
		//Start :  createReport()
			
		        /* This function is for to get market modules names*/
			 
		        function getCompanyDetails()
				  {
				      $select_company_details = "select company_name,city from company_setup";
				  
				      $lobj_select_company_details = $this->aobj_context->mobj_db->GetRow($select_company_details);  
				      
					  return $lobj_select_company_details;
				  
				  }
				
				function excelReportPreDefineSetup()
				{		
										
					if(trim($this->report_setup['page_orientation']) == 'landscape')
						$this->worksheet->setLandscape();
					else
						$this->worksheet->setPortrait();
					
					if(!empty($this->report_setup['print_scale']))
						$this->worksheet->setPrintScale($this->report_setup['print_scale']);
					
					if(!empty($this->report_setup['header_repeat']))
						$this->worksheet->repeatRows($this->report_setup['header_repeat']['x'], $this->report_setup['header_repeat']['y']);  
					
					
					if($this->report_setup['hide_grid_lines'] == "yes")
						$this->worksheet->hideScreenGridlines(); 
					
					if(!empty($this->report_setup['freezePanes']))
						$this->worksheet->freezePanes (array($this->report_setup['freezePanes'])); 
					
					if(!empty($this->report_setup['printRowColHeaders']))
						$this->worksheet->printRowColHeaders($this->report_setup['printRowColHeaders ']); 
					
					if(!empty($this->report_setup['setPaperSize']))
						$this->worksheet->setPaper($this->report_setup['setPaperSize']); 
					
				
				// DEFULT SETTING
					if(empty($this->report_setup['page_orientation']))
						$this->worksheet->setPortrait(); 
				}
				
				function createReport()
		           {
						 					
						ini_set("memory_limit",-1);
						ini_set('max_execution_time', 1400);
						$excel_writer=$this->aobj_context->main_src."/Excel_Writer/Writer.php";
						$file_path=$this->aobj_context->main_src."/imported_files/{$this->report_name}_report_{$this->report_id}.xls";
						$logo_path=$this->aobj_context->main_src."/img/bioplus logo_bit.bmp";
						
					//	echo $file_path;
						
					//	die();
						
						
						
						include($excel_writer);
						$user_id = $_SESSION['user_id']; 
						
						if($this->save_cond_flag == 1)
                        	$workbook = new Spreadsheet_Excel_Writer($file_path);
						else
                            $workbook = new Spreadsheet_Excel_Writer();						
						$workbook->setVersion(9); // Use Excel97/2000 Format
						$tarka_format_file=$this->aobj_context->main_src."/src/TarkaFormatStyles.php";
						include_once($tarka_format_file);
						$objfrmt =& new FormatStyle();
						$Data_Center_Bold_NoBorder =& $workbook->addFormat($objfrmt->Data_Center_Bold_NoBorder);
						$Data_Left_Bold_NoBorder =& $workbook->addFormat($objfrmt->Data_Left_Bold_NoBorder);
						$Data_Right_Bold_NoBorder =& $workbook->addFormat($objfrmt->Data_Right_Bold_NoBorder);
						$Data_top_bottm_border =& $workbook->addFormat($objfrmt->Data_top_bottm_border_bold);
						$Data_border =& $workbook->addFormat($objfrmt->Data_top_bottm_border);
											
						$this->worksheet =& $workbook->addWorksheet($Type.' Summary '.$ex_cur_year);
						
                      // $this->worksheet->setPaper(9);						
						
						// report  setup
								
						
						$Data_border->setTextWrap();
						$Data_top_bottm_border->setTextWrap();
					
						
						$this->worksheet->setMarginTop(0.3);
						$this->worksheet->setMarginLeft(0.3);
						$this->worksheet->setMarginRight(0.1);
						$this->worksheet->setMarginBottom(0.7);
						$this->worksheet->setPaper(9);
						//$this->worksheet->setVersion(9);
						$this->worksheet->setZoom(100);
						$nextrow = 0;
						
						$this->excelReportPreDefineSetup();
						
                        $this->getQueries();
						
						$max_col = $this->lobj_get_max_col[maxcol];
						$min_col = $this->lobj_get_max_col[mincol];
						
						//$this->worksheet->setColumn(0,$max_col,15); 
						
						$get_company_header = $this->getCompanyDetails();	

                        $company_name_name = $get_company_header[company_name];						
                        $company_city = $get_company_header[city];	

                        $this->worksheet->insertBitmap(0, 0, $logo_path, 0, 0, 1, 1);		
                        $this->worksheet->setColumn(0,0,2); 						
						
						$this->worksheet->write(0,1,$company_name_name,$Data_Center_Bold_NoBorder);
						$this->worksheet->mergeCells(0,1,0,$max_col);
						$this->worksheet->write(1,1,$company_city,$Data_Center_Bold_NoBorder);
						$this->worksheet->mergeCells(1,1,1,$max_col);  
													
						//$worksheet->setHeader('&C'.$company_name_name."\n".'&C'.$company_city,  0.5);
						
						for($tit = 0 ; $tit < count($this->titles) ; $tit++)
						 {
						    $title_name = $this->titles[$tit]['title'];
							$this->worksheet->write($this->titles[$tit]['row'],$this->titles[$tit]['col'],$title_name,$Data_Center_Bold_NoBorder);
							$this->worksheet->mergeCells($this->titles[$tit]['row'],$this->titles[$tit]['col'],$this->titles[$tit]['row'],$max_col);
                            if($this->titles[$tit]['row'] > $next_row)	
							  $nextrow = $this->titles[$tit]['row'];
						 }
						 				
						$max_nextrow = $this->lobj_get_max_row[nextrow];
												
						$nextrow += 1;
											
                        $max_st_ctr = 0;
                      
						
                        for($hed = 0 ; $hed < count($this->lobj_get_report_setup_details); $hed++)
						 {
						      $column_name = $this->lobj_get_report_setup_details[$hed]['query_columns'];
						      $header_row = $nextrow + $this->lobj_get_report_setup_details[$hed]['row'];
							  $header_col = $this->lobj_get_report_setup_details[$hed]['col'];
							  $data_row = $this->lobj_get_report_setup_details[$hed]['row'];
							  $sub_tot_col = $this->lobj_get_report_setup_details[$hed]['sub_total'];
							  $tot = $this->lobj_get_report_setup_details[$hed]['total'];
							  $width = $this->lobj_get_report_setup_details[$hed]['width'];
							  $width = ($width=='0')?19:$width;
							  
							  if($tot > 1)
							   {
							    $check_grand_tot = $tot;
							   }	
							  $col_title = $this->lobj_get_report_setup_details[$hed]['title'];
							  if($sub_tot_col > $max_st_ctr)
								 {
								    $max_st_ctr = $sub_tot_col;
								    
								 }
							  
							  						  					  
						      $index_col[$column_name] = $header_col;
						      $index_row[$column_name] = $data_row;
							  if($col_title == 1)
							    continue;
							 
                              $this->worksheet->setColumn($header_col,$header_col,$width); 							 
							  $this->worksheet->write($header_row,$header_col,$column_name,$Data_top_bottm_border);
                              						  							   
							   
						 }
						
						$first = 1;						  					 					
						$nextrow = $nextrow+$max_nextrow;
						
						
						
                        for($data = 0 ; $data < count($this->data_set); $data++)
						 {
						     						 
							 if($first == 1)
							  {
							    $first = 0;
								for($hed = 0 ; $hed < count($this->lobj_get_report_sub_hed_details); $hed++)
							     {
							       $column_name = $this->lobj_get_report_sub_hed_details[$hed]['query_columns'];
							       $col_title = $this->lobj_get_report_sub_hed_details[$hed]['title'];
								   $value = $this->data_set[$data][$column_name];
							       $col_ind = $index_col[$column_name];
								   $title_hed = $column_name.': '.$value;
							       
								   if($col_title == 1)
								     {
									  $this->worksheet->write($nextrow+1,$min_col,$title_hed,$Data_Left_Bold_NoBorder);	
                                      $nextrow++;									 
								     }                                 									
							     }
								  
								  
							  
							  }
						 
                             for($hed = 0 ; $hed < count($this->lobj_get_report_setup_details); $hed++)
							  {
							       $column_name = $this->lobj_get_report_setup_details[$hed]['query_columns'];
							       $sub_total = $this->lobj_get_report_setup_details[$hed]['sub_total'];
							       $total = $this->lobj_get_report_setup_details[$hed]['total'];
								   $data_col_title = $this->lobj_get_report_setup_details[$hed]['title'];
								   $value = $this->data_set[$data][$column_name];
							       $col_ind = $index_col[$column_name];
							       $row_ind = $index_row[$column_name];
								   
								   if($total == 1)	
								    {
									  for($cnt = 0; $cnt <= $max_st_ctr ; $cnt++)
									   {
									     $totals[$cnt][$row_ind][$col_ind] += $value;
                                   	  
									  }
									}
                                   if($sub_total > 0)
                                    {
                                     $totals[$sub_total]['val'] = $value;   
                                     $totals[$sub_total]['check_val'] = $value;   
                                    }	
									
									if($data_col_title == 0)
								     {
 									  
                                       $value = strtr($value, array(
											    "\r\n" => "\n",
											    "\r"   => "\n",
											)); 

									  $this->worksheet->write($nextrow+$row_ind,$col_ind,$value,$Data_border);		
                                     } 
								   	  							
							  }
							  
							 $nextrow = $nextrow+$max_nextrow;  
							 $change = false;	

							 for($hed = 0 ; $hed < count($this->lobj_get_report_sub_hed_details) ; $hed++)
								  {
								   $column_name = $this->lobj_get_report_sub_hed_details[$hed]['query_columns'];
							       $sub_total = $this->lobj_get_report_sub_hed_details[$hed]['sub_total'];
								   if($change)
								    {
									  $totals[$sub_total]['check_val'] = 'changed';
									}
									else
									{
							           $next_value = $this->data_set[$data+1][$column_name];
								       if($totals[$sub_total]['check_val'] != $next_value )
									    {
								  	       $change = true;										
									    }
									}
								  }
							 
							  for($hed = 0 ; $hed < count($this->lobj_get_report_total_details) ; $hed++)
							  {
							       $column_name = $this->lobj_get_report_total_details[$hed]['query_columns'];
							       $sub_total = $this->lobj_get_report_total_details[$hed]['sub_total'];
							       $next_value = $this->data_set[$data+1][$column_name];
							       $col_ind = $index_col[$column_name];
								   $row_ind = $index_row[$column_name];
								
								   
								   if($totals[$sub_total]['check_val'] != $next_value )
                                    {
									  // $sub_tot_name = 'Total for =>'.$totals[$sub_total]['val'];
	                                  // $this->worksheet->write($nextrow+$row_ind,$col_ind,$sub_tot_name,$Data_Right_Bold_NoBorder);
									  
									   $print_sub_title = false;
									   
									  for($sub_hed = 0 ; $sub_hed < count($this->lobj_get_report_setup_details); $sub_hed++)
                                             {
											      $sub_head_name =  $this->lobj_get_report_setup_details[$sub_hed]['query_columns'];
											      $sub_col_ind = $index_col[$sub_head_name];
							                      $sub_row_ind = $index_row[$sub_head_name];
												  $sub_tot_value = $totals[$sub_total][$sub_row_ind][$sub_col_ind];
												  if(!empty($sub_tot_value))
												  {
												     $this->worksheet->write($nextrow+$sub_row_ind,$sub_col_ind,$sub_tot_value,$Data_Right_Bold_NoBorder);	
													  $totals[$sub_total][$sub_row_ind][$sub_col_ind] = 0;
												  }
                                             }
											 
										if($print_sub_title == true)	 
										{ 
										  $sub_tot_name = 'Total for =>'.$totals[$sub_total]['val'];
	                                      $worksheet->write($nextrow+$row_ind,$col_ind,$sub_tot_name,$Data_Right_Bold_NoBorder);	 
										}		 
											 
									    $nextrow = $nextrow+$max_nextrow; 
                                    }	
                                 
							  } 
							  if($data < count($this->data_set)-1)
								{
																  							
								 for($hed = 0 ; $hed < count($this->lobj_get_report_sub_hed_details) ; $hed++)
								  {
								   $column_name = $this->lobj_get_report_sub_hed_details[$hed]['query_columns'];
							       $sub_total = $this->lobj_get_report_sub_hed_details[$hed]['sub_total'];
								   $col_title = $this->lobj_get_report_sub_hed_details[$hed]['title'];
							       $next_value = $this->data_set[$data+1][$column_name];
								   $title_hed = $column_name.': '.$next_value;
							       $col_ind = $index_col[$column_name];
							       $row_ind = $index_row[$column_name];

								   if($totals[$sub_total]['check_val'] != $next_value )
									{
								  	    if($col_title == 1)
										 {
										   									 
										   $this->worksheet->write($nextrow+1,$min_col,$title_hed,$Data_Left_Bold_NoBorder);	
										   $nextrow++;									 
										 }                    									
								              
									}
								  }		
							   } 
 						 }
                        
						if(!empty($check_grand_tot))
						 {
						   $sub_tot_name = 'Grand Total =>';
											
						   $this->worksheet->write($nextrow+$row_ind,$min_col,$sub_tot_name,$Data_Right_Bold_NoBorder);						
					     }	
						for($sub_hed = 0 ; $sub_hed < count($this->lobj_get_report_setup_details); $sub_hed++)
                                             {
											      $sub_head_name =  $this->lobj_get_report_setup_details[$sub_hed]['query_columns'];
											      $sub_col_ind = $index_col[$sub_head_name];
							                      $sub_row_ind = $index_row[$sub_head_name];
												  $sub_tot_value = $totals[0][$sub_row_ind][$sub_col_ind];
												  if(!empty($sub_tot_value))
												  {
												     $this->worksheet->write($nextrow+$sub_row_ind,$sub_col_ind,$sub_tot_value,$Data_Right_Bold_NoBorder);	
													  $totals[0][$sub_row_ind][$sub_col_ind] = 0;
												  }
                                             }  
					//die();							 
				   $this->worksheet->setFooter('&LDate: &D &CPage &P of &N &R'.$this->report_setup['footerLoginName'], "0.3"); 
				   $workbook->close();
				   
				   if($this->save_cond_flag == 0)
	                   $workbook->send("{$this->report_name}_report_{$this->report_id}.xls");
                   					 
		             					
				   }
			   
		//End :  createReport()	   
		//STR_PAD_LEFT (integer) 
		//STR_PAD_RIGHT (integer) 
		
		        function createTextReport()
		           {
				        $print_file= "c:\\print_file.txt";  
											
						$fh = fopen($print_file,'w') or die("can't open file");	
													
												
						// $title_name = str_pad('-',$this->page_size,"-", STR_PAD_BOTH);
						// fputs($fh,$title_name."\r\n");		
						
						 $this->getQueries();
						 
						 $get_col_width = "select rsd.col,max(rsd.width) as wdt from report_setup_details rsd
						                   inner join report_setup_header rsh on rsh.internal_code = rsd.ref_report_setup_header_code
											where rsh.report_id = '{$this->report_id}' and ifnull(rsh.report_name,'') = '{$this->setup_name}'
											group by col
											";
											
						 $lobj_get_col_width = $this->aobj_context->mobj_db->GetAll($get_col_width);
                         						 
						
						 $max_row =  $this->lobj_get_max_row[nextrow];
						 
						$get_company_header = $this->getCompanyDetails();	

                        $this->company_name_name = $get_company_header[company_name];						
                        $this->company_city = $get_company_header[city];		
						 
											 
						 //$max_col =  $this->lobj_get_max_col[maxcol];
						 
						 for($ent = 1 ; $ent <= $max_row ; $ent++)
						  {
						     for($dt = 0 ; $dt < count($lobj_get_col_width) ; $dt++)
							  {
							      $blank_print_data[$ent][$lobj_get_col_width[$dt]['col']] = str_pad(" ",$lobj_get_col_width[$dt]['wdt']); 
						      }
						  
						  }
						 			 		  
						 $max_st_ctr =  $this->header($blank_print_data,$max_row,$fh);
						 
						 $title_name = $this->title_name;
                        					
					//start : Printing First subtotal Title	
						
						$first = 1;						  					 					
						
                        for($data = 0 ; $data < count($this->data_set); $data++)
						 {
						     							 
							 if($first == 1)
							  {
							    $first = 0;
								$print = 0;
								$print_data = $blank_print_data;
								for($hed = 0 ; $hed < count($this->lobj_get_report_sub_hed_details); $hed++)
							     {
							       $column_name = $this->lobj_get_report_sub_hed_details[$hed]['query_columns'];
							       $col_title = $this->lobj_get_report_sub_hed_details[$hed]['title'];
							       $col_width = $this->lobj_get_report_sub_hed_details[$hed]['width'];
							       $sep_txt = $this->lobj_get_report_sub_hed_details[$hed]['sep_text'];
								   
								   $bold = $this->lobj_get_report_sub_hed_details[$hed]['bold'];
							       $get_bold = $this->getBold($bold);
							       $bold_on = $get_bold['on'];
							       $bold_off = $get_bold['off'];
								   
								   $style = $this->lobj_get_report_sub_hed_details[$hed]['style'];
								   $add_style = $this->getStyle($style);
								   $style_on = $add_style['on'];
								   $style_off = $add_style['off'];
								   
								   
								   if(empty($col_width))
							          $col_width = 20;
							       $col_num = $this->lobj_get_report_sub_hed_details[$hed]['col'];
							       $row_num = $this->lobj_get_report_sub_hed_details[$hed]['row'];
								   $alignment = $this->lobj_get_report_sub_hed_details[$hed]['alignment'];
							       $pad_align = $this->getDataPad($alignment);
								   
								   $alias_name = $this->lobj_get_report_sub_hed_details[$hed]['alias_name'];
								   $nor_alias_name = strtolower($alias_name);
								   
								   $value = $this->data_set[$data][$column_name];
								   if($nor_alias_name == 'value')
								     $tit_val = $value;
								   else if($nor_alias_name == 'name')	 
								     $tit_val = $column_name;
								   else
                                     $tit_val = $alias_name; 								   
									 
							       $title_hed = $column_name.': '.$tit_val;
							       
								   if($col_title == 1)
								     {
									   $prt_val =  substr(str_pad($title_hed,$col_width,' ',$pad_align),0,$col_width) ;	
									   $print_data[$row_num][$col_num] = $bold_on.$style_on.$prt_val.$style_off.$bold_off;
                                       $print = 1;								 
								     }                                 									
							     }
								
                                $this->pageBreak($fh,$blank_print_data,$title_name,$max_row);


								if($print == 1)
								  {
								     							  
									  for($ent = 1 ; $ent <= $max_row ; $ent++)
									  {
									     $print_string = '';
									     for($dt = 1 ; $dt <= count($print_data[$ent]) ; $dt++)
										  {
										      $print_string .= $print_data[$ent][$dt];
											  
											  
									      }
										 
			                            fwrite($fh,$print_string."\r\n");	
										$this->page_count++;		
                                        $st_len = strlen(trim($print_string)); 
										$head_line = str_pad('-',$st_len,"-", STR_PAD_BOTH);
						                fputs($fh,$head_line."\r\n");	
                                        $this->page_count++;												
									  
									  }
							      }
							  }
							  
							  
						//End : Printing First subtotal Title	

                        //Strat : Printing Normal data	
						  					   				
						     
						     $print_data = $blank_print_data;
                             for($hed = 0 ; $hed < count($this->lobj_get_report_setup_details); $hed++)
							  {
							       $column_name = $this->lobj_get_report_setup_details[$hed]['query_columns'];
							       $sub_total = $this->lobj_get_report_setup_details[$hed]['sub_total'];
							       $total = $this->lobj_get_report_setup_details[$hed]['total'];
								   
								   if($total > 0)
								    {
									  $text_grand_tot = 1;
									}
								   
								   $data_col_title = $this->lobj_get_report_setup_details[$hed]['title'];
								   $col_width = $this->lobj_get_report_setup_details[$hed]['width'];
								   if(empty($col_width))
							          $col_width = 20;
							       $col_num = $this->lobj_get_report_setup_details[$hed]['col'];
							       $row_num = $this->lobj_get_report_setup_details[$hed]['row'];
								   $sep_txt = $this->lobj_get_report_setup_details[$hed]['sep_text'];
								   
								   $style = $this->lobj_get_report_setup_details[$hed]['style'];
								   $add_style = $this->getStyle($style);
								   $style_on = $add_style['on'];
								   $style_off = $add_style['off'];
								   
								   $alignment = $this->lobj_get_report_setup_details[$hed]['alignment'];
							       $pad_align = $this->getDataPad($alignment);
								   					   
								   $value = $this->data_set[$data][$column_name];
							      								   
								   if($total == 1)	
								    {
									  for($cnt = 0; $cnt <= $max_st_ctr ; $cnt++)
									   {
									     $totals[$cnt][$row_num][$col_num] +=  $value;
                                   	  
									  }
									}
                                   if($sub_total > 0)
                                    {
                                     $totals[$sub_total]['val'] = $value;   
									 $totals[$sub_total]['check_val'] = $value;   
                                    }	
									
									if($data_col_title == 0)
									 {
								       $prt_val =  substr(str_pad($value,$col_width,' ',$pad_align),0,$col_width) ;
									   $print_data[$row_num][$col_num] =  $style_on.$prt_val.$style_off;
								   	 }							
							  }
								
								$this->pageBreak($fh,$blank_print_data,$title_name,$max_row);
															
								
							   for($ent = 1 ; $ent <= $max_row ; $ent++)
									  {
									     $print_string = '';
									     for($dt = 1 ; $dt <= count($print_data[$ent]) ; $dt++)
										  {
										      $print_string .= $print_data[$ent][$dt].$sep_txt;
																				  
									      }

			                               fwrite($fh,$print_string."\r\n");
                                           $this->page_count++;	

                                     if($data == count($this->data_set)-1)
									 {
									    for($ent = 1 ; $ent <= $max_row ; $ent++)
									  {
									     $print_string = '';
									     for($dt = 1 ; $dt <= count($print_data[$ent]) ; $dt++)
										  {
										      $print_string .= $print_data[$ent][$dt].$sep_txt;
											  
											  
									      }
										                                   									 
                                         $st_len = strlen(trim($print_string)); 
										 $head_line = str_pad('-',$st_len,"-", STR_PAD_BOTH);
						                 fputs($fh,$head_line."\r\n");	
                                         $this->page_count++;										 
									  
									   }
									 }
									   
										  
										$pgbr = '';  
										  
										
									  }
							  
							//End : Printing Normal data	 
									


                            $change = false;	

							 for($hed = 0 ; $hed < count($this->lobj_get_report_sub_hed_details) ; $hed++)
								  {
								   $column_name = $this->lobj_get_report_sub_hed_details[$hed]['query_columns'];
							       $sub_total = $this->lobj_get_report_sub_hed_details[$hed]['sub_total'];
								   if($change)
								    {
									  $totals[$sub_total]['check_val'] = 'changed';
									}
									else
									{
							           $next_value = $this->data_set[$data+1][$column_name];
								       if($totals[$sub_total]['check_val'] != $next_value )
									    {
								  	       $change = true;										
									    }
									}
								  }
				
							
							//Start : Printing subtotal values
							  
													
							  
							//$print_data = $blank_print_data;
							$print = 0;
							  for($hed = 0 ; $hed < count($this->lobj_get_report_total_details) ; $hed++)
							  {
							       $column_name = $this->lobj_get_report_total_details[$hed]['query_columns'];
							       $sub_total = $this->lobj_get_report_total_details[$hed]['sub_total'];
							       $col_width = $this->lobj_get_report_total_details[$hed]['width'];
								   if(empty($col_width))
							          $col_width = 20;
							       $col_num = $this->lobj_get_report_total_details[$hed]['col'];
							       $row_num = $this->lobj_get_report_total_details[$hed]['row'];
							       $sep_txt = $this->lobj_get_report_total_details[$hed]['sep_text'];
								   
								   $bold = $this->lobj_get_report_total_details[$hed]['bold'];
							       $get_bold = $this->getBold($bold);
							       $bold_on = $get_bold['on'];
							       $bold_off = $get_bold['off'];
								   
								   $style = $this->lobj_get_report_total_details[$hed]['style'];
								   $add_style = $this->getStyle($style);
								   $style_on = $add_style['on'];
								   $style_off = $add_style['off'];
								   
								   $alignment = $this->lobj_get_report_total_details[$hed]['alignment'];
							       $pad_align = $this->getDataPad($alignment);
								   
								   							   
							       $next_value = $this->data_set[$data+1][$column_name];
							       								
								   
								   if($totals[$sub_total]['check_val'] != $next_value )
                                    {
									   fputs($fh,$title_name."\r\n");		
									   
									   $print_data = $blank_print_data;
									   $sub_tot_name = 'Total for =>'.$totals[$sub_total]['val'];
									   
									   $prt_val = substr(str_pad($sub_tot_name,$col_width,' ',$pad_align),0,$col_width) ;	
									   
	                                   $print_data[$row_num][$col_num] =  $bold_on.$style_on.$prt_val.$style_off.$bold_off;
									   
									  for($sub_hed = 0 ; $sub_hed < count($this->lobj_get_report_setup_details); $sub_hed++)
                                             {
											      $sub_head_name =  $this->lobj_get_report_setup_details[$sub_hed]['query_columns'];
											      $col_width =  $this->lobj_get_report_setup_details[$sub_hed]['width'];
												  if(empty($col_width))
							                        $col_width = 20;
											      $sub_col_ind =  $this->lobj_get_report_setup_details[$sub_hed]['col'];
											      $sub_row_ind =  $this->lobj_get_report_setup_details[$sub_hed]['row'];
												  $sep_txt = $this->lobj_get_report_setup_details[$sub_hed]['sep_text'];
												  
												  $bold = $this->lobj_get_report_setup_details[$sub_hed]['bold'];
											      $get_bold = $this->getBold($bold);
							                      $bold_on = $get_bold['on'];
							                      $bold_off = $get_bold['off'];
												  
												   $style = $this->lobj_get_report_setup_details[$sub_hed]['style'];
												   $add_style = $this->getStyle($style);
												   $style_on = $add_style['on'];
												   $style_off = $add_style['off'];
												  
								                  $alignment = $this->lobj_get_report_setup_details[$sub_hed]['alignment'];
							                      $pad_align = $this->getDataPad($alignment);
												  	  
												  $sub_tot_value = $totals[$sub_total][$sub_row_ind][$sub_col_ind];
												  		 
												  												  
												  if(!empty($sub_tot_value))
												  {
												    $prt_val = substr(str_pad($sub_tot_value,$col_width,' ',$pad_align),0,$col_width) ;	
													$print_data[$sub_row_ind][$sub_col_ind] =  $bold_on.$style_on.$prt_val.$style_off.$bold_off;
													 					 
													 
													 $totals[$sub_total][$sub_row_ind][$sub_col_ind] = 0;
													 $print = 1;
												  }
                                             }
																			 
									 
									 $this->pageBreak($fh,$blank_print_data,$title_name,$max_row);
									 
									 if($print == 1)   
									 {
									 									 									 
									 for($ent = 1 ; $ent <= $max_row ; $ent++)
									  {
									     $print_string = '';
									     for($dt = 1 ; $dt <= count($print_data[$ent]) ; $dt++)
										  {
										      $print_string .= $print_data[$ent][$dt].$sep_txt;
											 										  
									      }
										 
			                             fwrite($fh,$print_string."\r\n");	
                                         $this->page_count++;										 
									  
									   }
									 }
                                    fputs($fh,$title_name."\r\n");	
                                    $this->page_count++;									
                                    }	
                                 
							  } 
							  
							 	  
							 //End : Printing subtotal values 
							 
							 //Start : Printing Titels
							 $print_data = $blank_print_data;
							 $print = 0;  
							  if($data < count($this->data_set)-1)
								{
																  							
								 for($hed = 0 ; $hed < count($this->lobj_get_report_sub_hed_details) ; $hed++)
								  {
								   $column_name = $this->lobj_get_report_sub_hed_details[$hed]['query_columns'];
							       $sub_total = $this->lobj_get_report_sub_hed_details[$hed]['sub_total'];
								   $col_title = $this->lobj_get_report_sub_hed_details[$hed]['title'];
								   $col_width = $this->lobj_get_report_sub_hed_details[$hed]['width'];
								    if(empty($col_width))
							          $col_width = 20;
								   $col_num = $this->lobj_get_report_sub_hed_details[$hed]['col'];
								   $row_num = $this->lobj_get_report_sub_hed_details[$hed]['row'];
								   $sep_txt = $this->lobj_get_report_sub_hed_details[$hed]['sep_text'];
								   
								   $bold = $this->lobj_get_report_sub_hed_details[$hed]['bold'];
								   $get_bold = $this->getBold($bold);
							       $bold_on = $get_bold['on'];
							       $bold_off = $get_bold['off'];
								   
								   $style = $this->lobj_get_report_sub_hed_details[$hed]['style'];
								   $add_style = $this->getStyle($style);
								   $style_on = $add_style['on'];
								   $style_off = $add_style['off'];
								   
								   $alignment = $this->lobj_get_report_sub_hed_details[$hed]['alignment'];
							       $pad_align = $this->getDataPad($alignment);
								   
								   $alias_name = $this->lobj_get_report_sub_hed_details[$hed]['alias_name'];
								   $nor_alias_name = strtolower($alias_name);
								   
								    
							       $next_value = $this->data_set[$data+1][$column_name];
								   
								   if($nor_alias_name == 'value')
								     $tit_val = $next_value;
								   else if($nor_alias_name == 'name')	 
								     $tit_val = $column_name;
								   else
                                     $tit_val = $alias_name; 
								   							   
								   $title_hed = $column_name.': '.$tit_val;
							      
								   if($totals[$sub_total]['check_val'] != $next_value )
									{
								  	    if($col_title == 1)
										 {
										   $prt_val = substr(str_pad($title_hed,$col_width,' ',$pad_align),0,$col_width) ;	
										   $print_data[$row_num][$col_num] =  $bold_on.$style_on.$prt_val.$style_off.$bold_off;
                                           $print = 1;  										   
										  							 
										 }                    									
								              
									}
								  }
                                 
								 $this->pageBreak($fh,$blank_print_data,$title_name,$max_row);
								 							 
								 if($print == 1)
								 {
								    for($ent = 1 ; $ent <= $max_row ; $ent++)
									  {
									     $print_string = '';
									     for($dt = 1 ; $dt <= count($print_data[$ent]) ; $dt++)
										  {
										      $print_string .= $print_data[$ent][$dt];
																				  
									      }
										 
			                             fwrite($fh,$print_string."\r\n");
										 $this->page_count++;
										 $st_len = strlen(trim($print_string)); 
										 $head_line = str_pad('-',$st_len,"-", STR_PAD_BOTH);
						                 fputs($fh,$head_line."\r\n");	
										 $this->page_count++;
										 
									  
									   }
								} 
								 								 
							   } 
 						 }
						 
						 
						//End : Printing Titels 
						 
						//Start : Printing Grand Total  
						
                    if($text_grand_tot > 0)	
                     {					
						 
                        $sub_tot_name = 'Grand Total =>';
						
						$print_data = $blank_print_data;
						
						$print_data[1][1] =  str_pad($sub_tot_name,$col_width);					
											
						for($sub_hed = 0 ; $sub_hed < count($this->lobj_get_report_setup_details); $sub_hed++)
                             {
									  $sub_head_name =  $this->lobj_get_report_setup_details[$sub_hed]['query_columns'];
									  $col_width =  $this->lobj_get_report_setup_details[$sub_hed]['width'];
									  $col_num =  $this->lobj_get_report_setup_details[$sub_hed]['col'];
									  $row_num =  $this->lobj_get_report_setup_details[$sub_hed]['row'];
									  $sep_txt =  $this->lobj_get_report_setup_details[$sub_hed]['sep_text'];
									  
									  $bold = $this->lobj_get_report_setup_details[$sub_hed]['bold'];
									  $get_bold = $this->getBold($bold);
							          $bold_on = $get_bold['on'];
							          $bold_off = $get_bold['off'];
									  
									  $style = $this->lobj_get_report_setup_details[$sub_hed]['style'];
								      $add_style = $this->getStyle($style);
								      $style_on = $add_style['on'];
								      $style_off = $add_style['off'];
									  									  
									  $alignment = $this->lobj_get_report_setup_details[$sub_hed]['alignment'];
							          $pad_align = $this->getDataPad($alignment);
									 	  
									  $sub_tot_value = $totals[0][$row_num][$col_num];
									  if(!empty($sub_tot_value))
									  {
										  $prt_val = substr(str_pad($sub_tot_value,$col_width,' ',$pad_align),0,$col_width) ;	
										  $print_data[$row_num][$col_num] =  $bold_on.$style_on.$prt_val.$style_off.$bold_off;
										  $totals[0][$row_num][$col_num] = 0;
									  }
                              }

							$this->pageBreak($fh,$blank_print_data,$title_name,$max_row); 
							  
                            for($ent = 1 ; $ent <= $max_row ; $ent++)
									  {
									     $print_string = '';
									     for($dt = 1 ; $dt <= count($print_data[$ent]) ; $dt++)
										  {
										      $print_string .= $print_data[$ent][$dt].$sep_txt;
											  
											  
									      }
										 
			                             fwrite($fh,$print_string."\r\n");
                                         $this->page_count++;										 
                                         $st_len = strlen(trim($print_string)); 
										 $head_line = str_pad('-',$st_len,"-", STR_PAD_BOTH);
						                 fputs($fh,$head_line."\r\n");	
                                         $this->page_count++;										 
									  
									   }
                        					  
                         } 						 
						//End : Printing Grand Total   
						 			 
						  fclose($fh); 
						   						  
						  $header_value='Following Records are not inserted';
						  header("Content-type:application/txt"); 
						  header("Content-Disposition:attachment;filename=print_file.txt");
						  readfile($print_file);
										   
				   
				   }
				   
			
               function createPdfReport()
		         {
				    $pdf_writer=$this->aobj_context->main_src."/tarka_pdf/fpdf.php";
	                require_once($pdf_writer);
					
					$root_rpt_file_download="c:\\Temp\print_pdf.pdf";
					$root_rpt_file_dname="print_pdf.pdf";
					//unlink($root_rpt_file_download);
					
					$PageSetup = '';
					
					
					
					if($this->report_setup['page_orientation'] == 'landscape')
						$PageSetup_orient = 'L';
					else
						$PageSetup = 'P';
						
					if(!empty($this->report_setup['pdfPaperSize']))
						$PageSetup_size = $this->report_setup['pdfPaperSize'];
										
						//echo $PageSetup; die();
					$pdf= new myFPDF($PageSetup_orient, 'mm', $PageSetup_size);		
					//$pdf= new myFPDF($PageSetup);		
					
					$pdf->lgin_name = $this->report_setup['footerLoginName'];		
					
					$pdf->logo_path_tool = $this->aobj_context->main_src."/img/bioplus logo.jpg";
					$get_company_header = $this->getCompanyDetails();	

                    $company_name_name = $get_company_header[company_name];						
                    $company_city = $get_company_header[city];		
                       					
					 $this->getQueries();
						 
						 $get_col_width = "select rsd.col,max(rsd.width) as wdt from report_setup_details rsd
						                   inner join report_setup_header rsh on rsh.internal_code = rsd.ref_report_setup_header_code
											where rsh.report_id = '{$this->report_id}' and rsh.report_name = '{$this->setup_name}'
											group by col
											";
											
						 $lobj_get_col_width = $this->aobj_context->mobj_db->GetAll($get_col_width);
                         						 
						
						 $max_row =  $this->lobj_get_max_row[nextrow];
						 
											 
						 //$max_col =  $this->lobj_get_max_col[maxcol];
						 
						 for($ent = 1 ; $ent <= $max_row ; $ent++)
						  {
						     for($dt = 0 ; $dt < count($lobj_get_col_width) ; $dt++)
							  {
							      $blank_print_data[$ent][$lobj_get_col_width[$dt]['col']]['data'] = str_pad(" ",$lobj_get_col_width[$dt]['wdt']); 
							      $blank_print_data[$ent][$lobj_get_col_width[$dt]['col']]['algn'] = ''; 
							      $blank_print_data[$ent][$lobj_get_col_width[$dt]['col']]['width'] = ''; 
						      }
						  
						  }
					
					$pdf->company_name = $company_name_name;
					$pdf->company_city = $company_city;
					$pdf->hd_title = $this->titles;
					$pdf->hd_maxrow = $max_row;
					$pdf->hd_pdf_size = $this->pdf_page_size;
					$pdf->hd_blank_data = $blank_print_data;
					$pdf->lobj_get_report_setup_details = $this->lobj_get_report_setup_details;
					$pdf->tarka_constant_pages = 0;
					$pdf->AliasNbPages();				
					
					$pdf->SetMargins(20,14);
					$max_st_ctr = $pdf->AddPage();		
					//$pdf->SetFont('Times','B',20);
										 	                 
                    $pdf->SetFont('Times','B',10);	
					 
												
					//start : Printing First subtotal Title	
						
						$first = 1;						  					 					
						
                        for($data = 0 ; $data < count($this->data_set); $data++)
						 {
						    						
							if($first == 1)
							  {
							    $first = 0;
								$print = 0;
								$print_data = $blank_print_data;
								for($hed = 0 ; $hed < count($this->lobj_get_report_sub_hed_details); $hed++)
							     {
							       $column_name = $this->lobj_get_report_sub_hed_details[$hed]['query_columns'];
							       $col_title = $this->lobj_get_report_sub_hed_details[$hed]['title'];
							       $col_width = $this->lobj_get_report_sub_hed_details[$hed]['width'];
							       $sep_txt = $this->lobj_get_report_sub_hed_details[$hed]['sep_text'];
								   
								   $bold = $this->lobj_get_report_sub_hed_details[$hed]['bold'];
							      								   
								   $style = $this->lobj_get_report_sub_hed_details[$hed]['style'];
								   			   
								   
								   if(empty($col_width))
							          $col_width = 20;
							       $col_num = $this->lobj_get_report_sub_hed_details[$hed]['col'];
							       $row_num = $this->lobj_get_report_sub_hed_details[$hed]['row'];
								   $alignment = $this->lobj_get_report_sub_hed_details[$hed]['alignment'];
							       $pad_align = $this->getPdfDataPad($alignment);						   
								   $alias_name = $this->lobj_get_report_sub_hed_details[$hed]['alias_name'];
								   $nor_alias_name = strtolower($alias_name);
								   
								   $value = $this->data_set[$data][$column_name];
								   if($nor_alias_name == 'value')
								     $tit_val = $value;
								   else if($nor_alias_name == 'name')	 
								     $tit_val = $column_name;
								   else
                                     $tit_val = $alias_name; 								   
									 
							       $title_hed = $column_name.': '.$tit_val;
							       
								   if($col_title == 1)
								     {
									   //$prt_val =  substr(str_pad($title_hed,$col_width,' ',$pad_align),0,$col_width) ;	
									  // $print_data[$row_num][$col_num] = $prt_val;
									      $print_data[$row_num][$col_num]['data'] = $title_hed;
										  $print_data[$row_num][$col_num]['algn'] = $pad_align;
										  $print_data[$row_num][$col_num]['width'] = $col_width;
                                       $print = 1;								 
								     }                                 									
							     }
								 if($print == 1)
								  {
									  for($ent = 1 ; $ent <= $max_row ; $ent++)
									  {
									     $print_string = '';
									     for($dt = 1 ; $dt <= count($print_data[$ent]) ; $dt++)
										  {
										      $print_string = $print_data[$ent][$dt]['data'];
										      $print_align = $print_data[$ent][$dt]['algn'];
										      $print_width = $print_data[$ent][$dt]['width'];
											  
											  if(empty($print_width))
											    $print_width = strlen($print_string); 
												
											  if($ent == $max_row and $dt == count($print_data[$ent]))
                                                {
												  $pdf->Cell($print_width*2,5,$print_string,'LR',0,$print_align);												  
												}  
											  else
                                                {											  
												  if(!empty($print_align))
												    $pdf->Cell($print_width*2,5,$print_string,'LB',0,$print_align);												  
												  else
												    $pdf->Cell($print_width*2,5,$print_string,'L',0,$print_align);		
											    }
									      }
										 
			                           	$pdf->Cell(1,5,'',"",1); 
										//$st_len = strlen(trim($print_string)); 
										//$head_line = str_pad('-',$st_len,"-", STR_PAD_BOTH);
										//$pdf->Cell($st_len,5,$head_line,"",1,"R");	
						               								  
									  }
							      }
							  }
							  
							  
						//End : Printing First subtotal Title	
                        $pdf->SetFont('Times','',10);	
                        //Strat : Printing Normal data	
						  					   				
						     
						     $print_data = $blank_print_data;
                             for($hed = 0 ; $hed < count($this->lobj_get_report_setup_details); $hed++)
							  {
							       $column_name = $this->lobj_get_report_setup_details[$hed]['query_columns'];
							       $sub_total = $this->lobj_get_report_setup_details[$hed]['sub_total'];
							       $total = $this->lobj_get_report_setup_details[$hed]['total'];
								   
								   if($total > 0)
								    {
									  $pdf_gran_tot = 1;
									}
								   
								   $data_col_title = $this->lobj_get_report_setup_details[$hed]['title'];
								   $col_width = $this->lobj_get_report_setup_details[$hed]['width'];
								   if(empty($col_width))
							          $col_width = 20;
							       $col_num = $this->lobj_get_report_setup_details[$hed]['col'];
							       $row_num = $this->lobj_get_report_setup_details[$hed]['row'];
								   $sep_txt = $this->lobj_get_report_setup_details[$hed]['sep_text'];
								   
								   $style = $this->lobj_get_report_setup_details[$hed]['style'];
								   								   
								   $alignment = $this->lobj_get_report_setup_details[$hed]['alignment'];
							       $pad_align = $this->getPdfDataPad($alignment);
								   					   
								   $value = $this->data_set[$data][$column_name];
							      								   
								   if($total == 1)	
								    {
									  for($cnt = 0; $cnt <= $max_st_ctr ; $cnt++)
									   {
									     $totals[$cnt][$row_num][$col_num] +=  $value;
                                   	  
									  }
									}
                                   if($sub_total > 0)
                                    {
                                     $totals[$sub_total]['val'] = $value;   
									 $totals[$sub_total]['check_val'] = $value;   
                                    }	
									
									if($data_col_title == 0)
									 {
								      // $prt_val =  substr(str_pad($value,$col_width,' ',$pad_align),0,$col_width) ;
									   //$print_data[$row_num][$col_num] =  $prt_val;
									   $print_data[$row_num][$col_num]['data'] = $value;
									   $print_data[$row_num][$col_num]['algn'] = $pad_align;
									   $print_data[$row_num][$col_num]['width'] = $col_width;
								   	 }							
							  }
							  
							   for($ent = 1 ; $ent <= $max_row ; $ent++)
									  {
									     $print_string = '';
									     for($dt = 1 ; $dt <= count($print_data[$ent]) ; $dt++)
										  {
										      
                                              $print_string = $print_data[$ent][$dt]['data'];
										      $print_align = $print_data[$ent][$dt]['algn'];
										      $print_width = $print_data[$ent][$dt]['width'];
											  if(empty($print_width))
											    $print_width = strlen($print_string); 

                                              if($ent == $max_row and $dt == count($print_data[$ent]))
                                                {
												  if($data == count($this->data_set)-1)
												   {
												     $pdf->Cell($print_width*2,5,$print_string,'LRB',0,$print_align);	
												   }
												  else
												   {
												     $pdf->Cell($print_width*2,5,$print_string,'LR',0,$print_align);												  
												   }	 
												}  
											  else
                                                {
											      if($data == count($this->data_set)-1)
												   {
												     $pdf->Cell($print_width*2,5,$print_string,'LB',0,$print_align);	
                                                   }	
                                                  else
                                                   {
                                                     $pdf->Cell($print_width*2,5,$print_string,'L',0,$print_align);	
                                                   }												   
												}								  
									      }
										 
			                            
                                        $pdf->Cell(1,5,'',"",1);											
									  
									  }
							  
							//End : Printing Normal data	 
									


                            $change = false;	

							 for($hed = 0 ; $hed < count($this->lobj_get_report_sub_hed_details) ; $hed++)
								  {
								   $column_name = $this->lobj_get_report_sub_hed_details[$hed]['query_columns'];
							       $sub_total = $this->lobj_get_report_sub_hed_details[$hed]['sub_total'];
								   if($change)
								    {
									  $totals[$sub_total]['check_val'] = 'changed';
									}
									else
									{
							           $next_value = $this->data_set[$data+1][$column_name];
								       if($totals[$sub_total]['check_val'] != $next_value )
									    {
								  	       $change = true;										
									    }
									}
								  }
				
							
							//Start : Printing subtotal values
							  
							$pdf->SetFont('Times','B',10);							
							  
							//$print_data = $blank_print_data;
							$print = 0;
							  for($hed = 0 ; $hed < count($this->lobj_get_report_total_details) ; $hed++)
							  {
							       $column_name = $this->lobj_get_report_total_details[$hed]['query_columns'];
							       $sub_total = $this->lobj_get_report_total_details[$hed]['sub_total'];
							       $col_width = $this->lobj_get_report_total_details[$hed]['width'];
								   if(empty($col_width))
							          $col_width = 20;
							       $col_num = $this->lobj_get_report_total_details[$hed]['col'];
							       $row_num = $this->lobj_get_report_total_details[$hed]['row'];
							       $sep_txt = $this->lobj_get_report_total_details[$hed]['sep_text'];
								   
								   $bold = $this->lobj_get_report_total_details[$hed]['bold'];
							       								   
								   $style = $this->lobj_get_report_total_details[$hed]['style'];
								   								   
								   $alignment = $this->lobj_get_report_total_details[$hed]['alignment'];
							       $pad_align = $this->getPdfDataPad($alignment);
								   
								   							   
							       $next_value = $this->data_set[$data+1][$column_name];
							       								
								   
								   if($totals[$sub_total]['check_val'] != $next_value )
                                    {
									   //fputs($fh,$title_name."\r\n");
                                      // $pdf->Cell(140,5,$title_name,"",1,"R");										   
									   
									   $print_data = $blank_print_data;
									   $sub_tot_name = 'Total for =>'.$totals[$sub_total]['val'];
									   
									   //$prt_val = substr(str_pad($sub_tot_name,$col_width,' ',$pad_align),0,$col_width) ;	
									   
	                                  // $print_data[$row_num][$col_num] =  $prt_val;
									   
									   $print_data[$row_num][$col_num]['data'] = $sub_tot_name;
									   $print_data[$row_num][$col_num]['algn'] = $pad_align;
									   $print_data[$row_num][$col_num]['width'] = $col_width;
									   
									   
									  for($sub_hed = 0 ; $sub_hed < count($this->lobj_get_report_setup_details); $sub_hed++)
                                             {
											      $sub_head_name =  $this->lobj_get_report_setup_details[$sub_hed]['query_columns'];
											      $col_width =  $this->lobj_get_report_setup_details[$sub_hed]['width'];
												  if(empty($col_width))
							                        $col_width = 20;
											      $sub_col_ind =  $this->lobj_get_report_setup_details[$sub_hed]['col'];
											      $sub_row_ind =  $this->lobj_get_report_setup_details[$sub_hed]['row'];
												  $sep_txt = $this->lobj_get_report_setup_details[$sub_hed]['sep_text'];
												  
												  $bold = $this->lobj_get_report_setup_details[$sub_hed]['bold'];
											      
												  
												   $style = $this->lobj_get_report_setup_details[$sub_hed]['style'];
												  
												  
								                  $alignment = $this->lobj_get_report_setup_details[$sub_hed]['alignment'];
							                      $pad_align = $this->getPdfDataPad($alignment);
												  	  
												  $sub_tot_value = $totals[$sub_total][$sub_row_ind][$sub_col_ind];
												  		 
												  												  
												  if(!empty($sub_tot_value))
												  {
												    //$prt_val = substr(str_pad($sub_tot_value,$col_width,' ',$pad_align),0,$col_width) ;	
													//$print_data[$sub_row_ind][$sub_col_ind] =  $prt_val;
													 					 
													 $print_data[$sub_row_ind][$sub_col_ind]['data'] = $sub_tot_value;
									                 $print_data[$sub_row_ind][$sub_col_ind]['algn'] = $pad_align;
									                 $print_data[$sub_row_ind][$sub_col_ind]['width'] = $col_width;
													 
													 $totals[$sub_total][$sub_row_ind][$sub_col_ind] = 0;
													 $print = 1;
												  }
                                             }
											 
									 
																			 
									 if($print == 1)   
									 {
									 for($ent = 1 ; $ent <= $max_row ; $ent++)
									  {
									     $print_string = '';
										  $fir = 0;		
									     for($dt = 1 ; $dt <= count($print_data[$ent]) ; $dt++)
										  {
										     
											  $print_string = $print_data[$ent][$dt]['data'];
										      $print_align = $print_data[$ent][$dt]['algn'];
										      $print_width = $print_data[$ent][$dt]['width'];
											  if(empty($print_width))
											    $print_width = strlen($print_string);  	

                                              if($fir == 0)
												{
												  $grd_width = $print_width;
												  $grd_algn = $print_align;
												  
												  $pdf->Cell($print_width*2,5,$print_string,'LTB',0,$print_align);
												}
											  else if($dt == count($print_data[$ent]))
                                                {
												  $pdf->Cell($print_width*2,5,$print_string,'RTB',0,$print_align);												  
												}  
											  else
                                                {
												  $pdf->Cell($print_width*2,5,$print_string,'TB',0,$print_align);		
											    }
											   $fir = 1	;									  
									      }
										 
			                             //fwrite($fh,$print_string."\r\n");									 
									     $pdf->Cell(1,5,'',"",1);	
									   }
									 }
                                    //fputs($fh,$title_name."\r\n");	
                                     //$pdf->Cell(140,5,$title_name,"",1,"R");										
                                    }	
                                 
							  } 
							  
							 	  
							 //End : Printing subtotal values 
							 
							 //Start : Printing Titels
							 $print_data = $blank_print_data;
							 $print = 0;  
							  if($data < count($this->data_set)-1)
								{
																  							
								 for($hed = 0 ; $hed < count($this->lobj_get_report_sub_hed_details) ; $hed++)
								  {
								   $column_name = $this->lobj_get_report_sub_hed_details[$hed]['query_columns'];
							       $sub_total = $this->lobj_get_report_sub_hed_details[$hed]['sub_total'];
								   $col_title = $this->lobj_get_report_sub_hed_details[$hed]['title'];
								   $col_width = $this->lobj_get_report_sub_hed_details[$hed]['width'];
								    if(empty($col_width))
							          $col_width = 20;
								   $col_num = $this->lobj_get_report_sub_hed_details[$hed]['col'];
								   $row_num = $this->lobj_get_report_sub_hed_details[$hed]['row'];
								   $sep_txt = $this->lobj_get_report_sub_hed_details[$hed]['sep_text'];
								   
								   $bold = $this->lobj_get_report_sub_hed_details[$hed]['bold'];
								   								   
								   $style = $this->lobj_get_report_sub_hed_details[$hed]['style'];
								  								   
								   $alignment = $this->lobj_get_report_sub_hed_details[$hed]['alignment'];
							       $pad_align = $this->getPdfDataPad($alignment);
								   
								   $alias_name = $this->lobj_get_report_sub_hed_details[$hed]['alias_name'];
								   $nor_alias_name = strtolower($alias_name);
								   
								    
							       $next_value = $this->data_set[$data+1][$column_name];
								   
								   if($nor_alias_name == 'value')
								     $tit_val = $next_value;
								   else if($nor_alias_name == 'name')	 
								     $tit_val = $column_name;
								   else
                                     $tit_val = $alias_name; 
								   							   
								   $title_hed = $column_name.': '.$tit_val;
							      
								   if($totals[$sub_total]['check_val'] != $next_value )
									{
								  	    if($col_title == 1)
										 {
										  // $prt_val = substr(str_pad($title_hed,$col_width,' ',$pad_align),0,$col_width) ;	
										   //$print_data[$row_num][$col_num] =  $prt_val;
										    $print_data[$row_num][$col_num]['data'] = $title_hed;
									        $print_data[$row_num][$col_num]['algn'] = $pad_align;
									        $print_data[$row_num][$col_num]['width'] = $col_width;
                                           $print = 1;  										   
										  							 
										 }                    									
								              
									}
								  }
                                 if($print == 1)
								 {
								 for($ent = 1 ; $ent <= $max_row ; $ent++)
									  {
									     $print_string = '';
									     for($dt = 1 ; $dt <= count($print_data[$ent]) ; $dt++)
										  {
										      $print_string = $print_data[$ent][$dt]['data'];
										      $print_align = $print_data[$ent][$dt]['algn'];
										      $print_width = $print_data[$ent][$dt]['width'];
											  if(empty($print_width))
											    $print_width = strlen($print_string); 
												
												if(!empty($print_align))
											      $pdf->Cell($print_width*2,5,$print_string,'LB',0,$print_align);												  
											    else
											      $pdf->Cell($print_width*2,5,$print_string,'L',0,$print_align);
											 
																				  
									      }
										 
			                            // fwrite($fh,$print_string."\r\n");
										 $pdf->Cell(1,5,'',"",1);		
										 //$st_len = strlen(trim($print_string)); 
										// $head_line = str_pad('-',$st_len,"-", STR_PAD_BOTH);
										// $pdf->Cell(100,5,$head_line,"",1,"R");		
						                // fputs($fh,$head_line."\r\n");	
										 
									  
									   }
								} 
								 								 
							   } 
 						 }
						 
						 
						//End : Printing Titels 
						 
						//Start : Printing Grand Total  
						 
                        if($pdf_gran_tot > 0)
						 {
						   $sub_tot_name = 'Grand Total =>';
						
						  $print_data = $blank_print_data;
						
						$print_data[1][1]['data'] =  $sub_tot_name;
						$print_data[1][1]['algn'] =  $grd_algn;
						$print_data[1][1]['width'] =  $grd_width;
																
						for($sub_hed = 0 ; $sub_hed < count($this->lobj_get_report_setup_details); $sub_hed++)
                             {
									  $sub_head_name =  $this->lobj_get_report_setup_details[$sub_hed]['query_columns'];
									  $col_width =  $this->lobj_get_report_setup_details[$sub_hed]['width'];
									  $col_num =  $this->lobj_get_report_setup_details[$sub_hed]['col'];
									  $row_num =  $this->lobj_get_report_setup_details[$sub_hed]['row'];
									  $sep_txt =  $this->lobj_get_report_setup_details[$sub_hed]['sep_text'];
									  
									  $bold = $this->lobj_get_report_setup_details[$sub_hed]['bold'];
									 									  
									  $style = $this->lobj_get_report_setup_details[$sub_hed]['style'];
								     									  									  
									  $alignment = $this->lobj_get_report_setup_details[$sub_hed]['alignment'];
							          $pad_align = $this->getPdfDataPad($alignment);
									 	  
									  $sub_tot_value = $totals[0][$row_num][$col_num];
									  if(!empty($sub_tot_value))
									  {
										  //$prt_val = substr(str_pad($sub_tot_value,$col_width,' ',$pad_align),0,$col_width) ;	
										 // $print_data[$row_num][$col_num] =  $prt_val;
										  $print_data[$row_num][$col_num]['data'] = $sub_tot_value;
									      $print_data[$row_num][$col_num]['algn'] = $pad_align;
									      $print_data[$row_num][$col_num]['width'] = $col_width;
										  $totals[0][$row_num][$col_num] = 0;
									  }
                              }

                            for($ent = 1 ; $ent <= $max_row ; $ent++)
									  {
									     $print_string = '';
										 $fir = 0;
									     for($dt = 1 ; $dt <= count($print_data[$ent]) ; $dt++)
										  {
										      $print_string = $print_data[$ent][$dt]['data'];
										      $print_align = $print_data[$ent][$dt]['algn'];
										      $print_width = $print_data[$ent][$dt]['width'];
											  if(empty($print_width))
											    $print_width = strlen($print_string); 

                                               if($fir == 0)
												{
												  $pdf->Cell($print_width*2,5,$print_string,'LB',0,$print_align);
												}
											  else if($dt == count($print_data[$ent]))
                                                {
												  $pdf->Cell($print_width*2,5,$print_string,'RB',0,$print_align);												  
												}  
											  else
                                                {
				                                  $pdf->Cell($print_width*2,5,$print_string,'B',0,$print_align);		
											    }
											   $fir = 1;
									      }
										 
			                            // fwrite($fh,$print_string."\r\n");	
										// $pdf->Cell(100,5,$print_string,"",1,"R");	
                                         //$st_len = strlen(trim($print_string)); 
										// $head_line = str_pad('-',$st_len,"-", STR_PAD_BOTH);
										// $pdf->Cell(100,5,$head_line,"",1,"R");	
						                // fputs($fh,$head_line."\r\n");											 
									  
									   }
                        					  
                         } 						 
						//End : Printing Grand Total   
						 $pdf->output($root_rpt_file_download,'D');		 			 
						 				      


                 }				 
			
				   
			function getQueries()
             {
			     $get_max_col = "select max(col) as maxcol , min(col) mincol from report_setup_details rsd
														inner join report_setup_header rsh on rsh.internal_code = rsd.ref_report_setup_header_code
														where rsh.report_id = '{$this->report_id}' and ifnull(rsh.report_name,'') = '{$this->setup_name}'
														order by rsd.internal_code";
				
              				
				$this->lobj_get_max_col = $this->aobj_context->mobj_db->GetRow($get_max_col);
						
				$get_report_setup_details = "select rsd.* from report_setup_details rsd
														inner join report_setup_header rsh on rsh.internal_code = rsd.ref_report_setup_header_code
														where rsh.report_id = '{$this->report_id}' and ifnull(rsh.report_name,'') = '{$this->setup_name}'
														order by rsd.row,rsd.col";
						 
				$this->lobj_get_report_setup_details = $this->aobj_context->mobj_db->GetAll($get_report_setup_details);
						
						
						
				$get_report_total_details = "select rsd.* from report_setup_details rsd
														inner join report_setup_header rsh on rsh.internal_code = rsd.ref_report_setup_header_code
														where rsh.report_id = '{$this->report_id}' and ifnull(rsh.report_name,'') = '{$this->setup_name}'
														and sub_total > 0 order by sub_total desc";
						 
				$this->lobj_get_report_total_details = $this->aobj_context->mobj_db->GetAll($get_report_total_details);
						
						
				$get_report_sub_hed_details = "select rsd.* from report_setup_details rsd
														inner join report_setup_header rsh on rsh.internal_code = rsd.ref_report_setup_header_code
														where rsh.report_id = '{$this->report_id}' and ifnull(rsh.report_name,'') = '{$this->setup_name}'
														and sub_total > 0 order by sub_total";
						 
				$this->lobj_get_report_sub_hed_details = $this->aobj_context->mobj_db->GetAll($get_report_sub_hed_details);
						
						
						
						
						
						
				$get_max_row = "select max(row) as nextrow from report_setup_details rsd
														inner join report_setup_header rsh on rsh.internal_code = rsd.ref_report_setup_header_code
														where rsh.report_id = '{$this->report_id}' and ifnull(rsh.report_name,'') = '{$this->setup_name}'
														order by rsd.internal_code";
						 
				$this->lobj_get_max_row = $this->aobj_context->mobj_db->GetRow($get_max_row);
										
			 
			 }
			 
			 function getDataPad($alignment)
			 {
			 
				  if($alignment == 'Left')
					$pad_align  = STR_PAD_LEFT;
				  else if($alignment == 'Center')
					$pad_align  = STR_PAD_BOTH;
				  else
					$pad_align  = STR_PAD_RIGHT;
					return $pad_align;
              
		    }
			
			function getPdfDataPad($alignment)
			 {
			    if($alignment == 'Left')
					$pad_align  = "L";
				  else if($alignment == 'Center')
					$pad_align  = "C";
				  else
					$pad_align  = "R";
				
				return $pad_align;
			 
			 
			 }
			
			function getStyle($style)
			 {
			     $comppress_on = chr(15);
			     $comppress_off = chr(18);
			     $medium_on = '';
			     $medium_off = '';
			     $wide_on = chr(27).'W1';
			     $wide_off = chr(27).'W0';
				 
				 if($style == 'Compress')
				  {
				    $get_style['on'] = $comppress_on;			     
				    $get_style['off'] = $comppress_off;			     
				  
				  }
				 else if($style == 'Medium')
				  {
				    $get_style['on'] = $medium_on;			     
				    $get_style['off'] = $medium_off;			     
				  
				  }
				  else if($style == 'Wide')
				  {
				    $get_style['on'] = $wide_on;			     
				    $get_style['off'] = $wide_off;			     
				  
				  }
				  else
				   {
				     $get_style['on'] = '';			     
				     $get_style['off'] = '';			 
				   
				   }
			 
			   return $get_style;
			 
			 
			 }
		
			 function getBold($bold)
			 {
			    $bold_on = chr(27).'E1';
			    $bold_off = chr(27).'E0';
				if($bold == 1)
				 { 
				   $bold_data['on'] = $bold_on;
				   $bold_data['off'] = $bold_off;
				 } 
                else
                 {
                   $bold_data['on'] = '';
				   $bold_data['off'] = '';
                 }				 
			 
			 }
			 
			 function header($blank_print_data,$max_row,$fh)
			  {
			     $this->page_count = 0;		
				 			 		 
										 
						 $print_data = $blank_print_data;
							
                    //Getting Printing data and Length also.						
						
						 for($hed = 0 ; $hed < count($this->lobj_get_report_setup_details); $hed++)
						 {
						      $column_name = $this->lobj_get_report_setup_details[$hed]['query_columns'];
						      $header_row = $this->lobj_get_report_setup_details[$hed]['row'];
						      $header_col = $this->lobj_get_report_setup_details[$hed]['col'];
						      $col_width = $this->lobj_get_report_setup_details[$hed]['width'];
						      $sep_txt = $this->lobj_get_report_setup_details[$hed]['sep_text'];
							  
						      $bold = $this->lobj_get_report_setup_details[$hed]['bold'];
							  
							  $get_bold = $this->getBold($bold);
							  $bold_on = $get_bold['on'];
							  $bold_off = $get_bold['off'];
							  							  
						      $style = $this->lobj_get_report_setup_details[$hed]['style'];
							  $add_style = $this->getStyle($style);
							  $style_on = $add_style['on'];
							  $style_off = $add_style['off'];
							  	  
						      $alignment = $this->lobj_get_report_setup_details[$hed]['alignment'];
							  $pad_align = $this->getDataPad($alignment);

								
							  if(empty($col_width))
							    $col_width = 20;
							  
							  $sub_tot_col = $this->lobj_get_report_setup_details[$hed]['sub_total'];
							  $col_title = $this->lobj_get_report_setup_details[$hed]['title'];
							  							  						  
							  
							  if($sub_tot_col > $max_st_ctr)
								 {
								    $max_st_ctr = $sub_tot_col;
								    
								 }
													      
							  if($col_title == 1)
							    continue;
													                            																							
							  $prt_val = substr(str_pad($column_name,$col_width,' ', $pad_align),0,$col_width);	
							  $print_data[$header_row][$header_col] = $bold_on.$style_on.$prt_val.$style_off.$bold_off;
							  		 
							   
						 }
						 
				  // Start: Getting Global Line Length		
					
					$head_line = '';	 
						 
					  for($ent = 1 ; $ent <= $max_row ; $ent++)
						  {
						     $print_string = '';
						     for($dt = 1 ; $dt <= count($print_data[$ent]) ; $dt++)
							  {
							      $print_string .= $print_data[$ent][$dt].$sep_txt;
														  
						      }
							 $st_len = strlen(trim($print_string)); 
							 $gb_str_len += $st_len;
							 
							 $this->title_name .= str_pad('-',$st_len,"-", STR_PAD_BOTH);
							 
													  
						  }
     			         
						 fputs($fh,$this->title_name."\r\n");	
						 $this->page_count++;

                   // End Getting Global Line Length						 
					  					  
					 
				 //Start : Displaying Header
				 
					 $company_name_name = str_pad($this->company_name_name,$gb_str_len," ", STR_PAD_BOTH); 
					 
					  fputs($fh,$company_name_name."\r\n");	
                      $this->page_count++;
					  $company_city = str_pad($this->company_city,$gb_str_len," ", STR_PAD_BOTH);  
					  fputs($fh,$company_city."\r\n");	
					  $this->page_count++;
					  
					  
					  
					  for($tit = 0 ; $tit < count($this->titles) ; $tit++)
						 {
						    $title_name = $this->titles[$tit]['title'];
														
							$title_name = str_pad($title_name,$gb_str_len," ", STR_PAD_BOTH);
														
							fputs($fh, $title_name."\r\n");	
                            $this->page_count++;									
							
						 }
						
                         fputs($fh,$this->title_name."\r\n");	
						 $this->page_count++;	
						 											 						 						 
						 // displaying Menue Header
								 for($ent = 1 ; $ent <= $max_row ; $ent++)
								  {
								     $print_string = '';
								     for($dt = 1 ; $dt <= count($print_data[$ent]) ; $dt++)
									  {
									      $print_string .= $print_data[$ent][$dt].$sep_txt;
																  
								      }
									 
		                            fwrite($fh,$print_string."\r\n");
		                            $this->page_count++;

		                             $st_len = strlen(trim($print_string)); 
									 $head_line = str_pad('-',$st_len,"-", STR_PAD_BOTH);
									 fputs($fh,$head_line."\r\n");	
									 $this->page_count++;
								  
								  }
						 					 
				  //End : Displaying Header

                     return $max_st_ctr;					 
			  
			  }
			  
			  function pageBreak($fh,$blank_print_data,$title_name,$max_row)
			   {
			      if ($this->page_count+$max_row >= 65)
					{
								 $pgbr = chr(12);  
								 fputs($fh,$title_name."\r\n".$pgbr);		
								 $this->header($blank_print_data,$max_row,$fh);
					}
			    
			   }
			 
			 
			 
			
   }

//End :  Class file

//Start :  getModuleNames()

	/*  This function is for to get market module names*/

	function getModuleNames($aobj_context)
	{		
		
		try
		{
		     $class_obj=new marketreport($aobj_context);	
			 $class_obj->report_id = $aobj_context->mobj_data["report_id"];
		     $market_modules = $class_obj->getMarketModulesNames();
			 echo $aobj_context->mobj_output->ToJSONEnvelope($market_modules,0,"Success");
			 
		}
		
		
	   catch (Exception $aobj_exp)
		{ 
			 echo 'Caught exception: ',  $aobj_exp->getMessage(), "\n";
		}	
			
	}
	
//End:  getModuleNames()	
//print_r($my_aobj_context);
$main_src=substr($_SERVER['SCRIPT_FILENAME'],0,strlen($_SERVER['SCRIPT_FILENAME'])-7);
$pdf_writer_class =$main_src."/tarka_pdf/fpdf.php";				
include_once($pdf_writer_class);


class myFPDF extends FPDF
{
	function Header()
	{
		$this->SetFont('Times','B',12);	
		$this->Image($this->logo_path_tool, 12, 7, 22, 22, JPG);
		
		$company_name = str_pad($this->company_name, 125, " ", STR_PAD_BOTH);
		$this->Cell(0,5,$company_name,"C",1,0);
		
		$company_city = str_pad($this->company_city, 130, " ", STR_PAD_BOTH);
		$this->Cell(0,4,$company_city,"C",1,0);
		
		for($tit = 0 ; $tit < count($this->hd_title) ; $tit++)
			 {
				$title_name = $this->hd_title[$tit]['title'];
												
				$title_name = str_pad($title_name, $this->hd_pdf_size, " ", STR_PAD_BOTH);
									
				$this->Cell(0,5,$title_name,"C",1,0);
											
			 }
			
			//$title_name = str_pad('-',$this->hd_pdf_size,"-", STR_PAD_BOTH);
			
			
			
			$this->Cell(0,5,'',"",1,"");
			$this->SetFont('Times','B',10);	
			
			$print_data = $this->hd_blank_data; 
						 					 						 
						 for($hed = 0 ; $hed < count($this->lobj_get_report_setup_details); $hed++)
						 {
						      $column_name = $this->lobj_get_report_setup_details[$hed]['query_columns'];
						      $header_row = $this->lobj_get_report_setup_details[$hed]['row'];
						      $header_col = $this->lobj_get_report_setup_details[$hed]['col'];
						      $col_width = $this->lobj_get_report_setup_details[$hed]['width'];
						      $sep_txt = $this->lobj_get_report_setup_details[$hed]['sep_text'];
							  $bold = $this->lobj_get_report_setup_details[$hed]['bold'];
							  $style = $this->lobj_get_report_setup_details[$hed]['style'];
							  $alignment = $this->lobj_get_report_setup_details[$hed]['alignment'];
							  if($alignment == 'Left')
								$pad_align  = "L";
							  else if($alignment == 'Center')
								$pad_align  = "C";
							  else
								$pad_align  = "R";
							  
							  
							  if(empty($col_width))
							    $col_width = 20;
							  
							  $sub_tot_col = $this->lobj_get_report_setup_details[$hed]['sub_total'];
							  $col_title = $this->lobj_get_report_setup_details[$hed]['title'];
							  							  						  
							  
							  if($sub_tot_col > $max_st_ctr)
								 {
								    $max_st_ctr = $sub_tot_col;
								    
								 }
													      
							  if($col_title == 1)
							    continue;
													                            																							
							  //$prt_val = substr(str_pad($column_name,$col_width,' ', $pad_align),0,$col_width);	
							  $print_data[$header_row][$header_col]['data'] = $column_name;
							  $print_data[$header_row][$header_col]['algn'] = $pad_align;
							  $print_data[$header_row][$header_col]['width'] = $col_width;
							  

							  		 
							   
						 }
												 						 						 
						 for($ent = 1 ; $ent <= $this->hd_maxrow ; $ent++)
						  {
						     $print_string = '';
						     for($dt = 1 ; $dt <= count($print_data[$ent]) ; $dt++)
							  {
							      $print_string = $print_data[$ent][$dt]['data'];
							      $print_align = $print_data[$ent][$dt]['algn'];
							      $print_width = $print_data[$ent][$dt]['width'];
								  									  
								  $this->Cell($print_width*2,5,$print_string,1,0,$print_align);		
																	  
						      }
						  }
						  						 					  
						 $this->Cell(1,5,'',"",1); 
						 
						//FPDF::Header();
						
						return $max_st_ctr;
						
	
	}
	
	function Footer()
	{
		//Go to 1.5 cm from bottom
	    $this->SetY(-12);
	    //Select Arial italic 8
	    $this->SetFont('Arial','I',8);
	    //Print centered page number
		
	    $this->Cell(10,10,$this->lgin_name.' '.date("m.d.Y"),0,0,'L');
	    $this->Cell(0,10,'Page: '.$this->PageNo().'/{nb}',0,0,'R');

	}
}



?>