<?php
$peri=$pe.'-'.$yr;
include('FetchingBudgeted.php');
?>
<div class="divscroll">
    <input type="hidden" value="<?php echo $peri; ?>" id="periodic" />
    <input type="hidden" value="<?php echo $yr; ?>" id="themwaka" />
  <h6> <u class="text-info"> Cash Equivalent report for: <strong class='text-danger'> <?php echo $pe.' '.$yr;  ?> </strong></u></h6>
  
  <table class="table tablesummary table-sm" id="tsummary">
      <thead>
          <tr>
            <th>Particular</th>
            <th>May</th>
            <th>June</th>
            <th>July</th>
            <th>August</th>
            <th>Total</th>
            <th>Budgeted</th>
            <th>Variance</th>
            <th>%</th>
            <th class="leavethis">Action</th>
          </tr>
      </thead>
      <tbody>
           <tr class="alert-success">
              <td colspan="10"><strong>Income</strong></td>
          </tr>
          <tr>
              <td style="background-color:#ffe6e6" class="cola1">School Fees</td>
              <td class="cola2"><?php echo number_format($mayfee); ?></td>
              <td class="cola3"><?php echo number_format($junfee); ?></td>
              <td class="cola4"><?php echo number_format($julyfee); ?></td>
              <td class="cola5"><?php echo number_format($augfee); ?></td>
              <td class="bg-primary cola6"><strong style="padding:5px"><?php echo number_format($totmayfee); ?></strong></td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($sfee); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmayfee !='0'  && $sfee !='0' && $sfee !='')
                 {
                   $badbal=$sfee-$totmayfee;
                   echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmayfee !='0'  && $sfee !='0' && $sfee !='')
                 {
                    $badbal=$sfee-$totmayfee;
                    $para=($badbal/$sfee)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                  <input type="hidden" value="sfee" class="textwithid" />
                  <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
              </td>
          </tr>
          
           <tr>
              <td style="background-color:#ffe6e6" class="cola1">Uniform Fee</td>
              <td><?php echo number_format($mayuni); ?></td>
              <td><?php echo number_format($jununi); ?></td>
              <td><?php echo number_format($julyuni); ?></td>
              <td><?php echo number_format($auguni); ?></td>
              <td class="bg-primary"><strong style="padding:5px"><?php echo number_format($totmayuni); ?></strong></td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($unifee); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmayuni !='0'  && $unifee !='0' && $unifee !='')
                 {
                    $badbal=$unifee-$totmayuni;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmayuni !='0'  && $unifee !='0' && $unifee !='')
                 {
                    $badbal=$unifee-$totmayuni;
                    $para=($badbal/$unifee)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                   <input type="hidden" value="unifee" class="textwithid" />
                   <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
              </td>
          </tr>
          
          <tr>
              <td style="background-color:#ffe6e6" class="cola1">Admission Fee</td>
              <td><?php echo number_format($mayadfe); ?></td>
              <td><?php echo number_format($junadfe); ?></td>
              <td><?php echo number_format($julyadfe); ?></td>
              <td><?php echo number_format($augadfe); ?></td>
              <td class="bg-primary"><strong style="padding:5px"><?php echo number_format($totmayadfee); ?></strong></td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($adfee); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmayadfee !='0'  && $adfee !='0' && $adfee !='')
                 {
                    $badbal=$adfee-$totmayadfee;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmayadfee !='0'  && $adfee !='0' && $adfee !='')
                 {
                    $badbal=$adfee-$totmayadfee;
                    $para=($badbal/$adfee)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                   <input type="hidden" value="adfee" class="textwithid" />
                   <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
              </td>
          </tr>
         
           <tr>
              <td style="background-color:#ffe6e6" class="cola1">Transport Fee</td>
              <td><?php echo number_format($maytra); ?></td>
              <td><?php echo number_format($juntra); ?></td>
              <td><?php echo number_format($julytra); ?></td>
              <td><?php echo number_format($augtra); ?></td>
              <td class="bg-primary"><strong style="padding:5px"><?php echo number_format($totmaytra); ?></strong></td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($trafee); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmaytra !='0'  && $trafee !='0' && $trafee !='')
                 {
                    $badbal=$trafee-$totmaytra;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmaytra !='0'  && $trafee !='0' && $trafee !='')
                 {
                    $badbal=$trafee-$totmaytra;
                    $para=($badbal/$trafee)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                   <input type="hidden" value="trafee" class="textwithid" />
                   <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
              </td>
          </tr>
          
           <tr>
              <td style="background-color:#ffe6e6" class="cola1">Motivation</td>
              <td><?php echo $maymoti; ?></td>
              <td><?php echo $junmoti; ?></td>
              <td><?php echo $julymoti; ?></td>
              <td><?php echo $augmoti; ?></td>
              <td class="bg-primary"><strong style="padding:5px"><?php echo number_format($totmaymoti); ?></strong> </td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($moti); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmaymoti !='0'  && $moti !='0' && $moti !='')
                 {
                    $badbal=$moti-$totmaymoti;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmaymoti !='0'  && $moti !='0' && $moti !='')
                 {
                    $badbal=$moti-$totmaymoti;
                    $para=($badbal/$moti)*100;
                    
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                  <input type="hidden" value="moti" class="textwithid" />
                  <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
             </td>
          </tr>
        
          <tr>
              <td style="background-color:#ffe6e6" class="cola1">Diaries</td>
              <td><?php echo number_format($maydia); ?></td>
              <td><?php echo number_format($jundia); ?></td>
              <td><?php echo number_format($julydia); ?></td>
              <td><?php echo number_format($augdia); ?></td>
              <td class="bg-primary"><strong style="padding:5px"><?php echo number_format($totmaydia); ?></strong></td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($diafee); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmaydia !='0'  && $diafee !='0' && $diafee !='')
                 {
                    $badbal=$diafee-$totmaydia;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmaydia !='0'  && $diafee !='0' && $diafee !='')
                 {
                    $badbal=$diafee-$totmaydia;
                    $para=($badbal/$diafee)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                   <input type="hidden" value="diafee" class="textwithid" />
                   <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
              </td>
            </tr>
     
             <tr>
              <td style="background-color:#ffe6e6" class="cola1">Assessment Books</td>
              <td><?php echo number_format($maybkf); ?></td>
              <td><?php echo number_format($junbkf); ?></td>
              <td><?php echo number_format($julybkf); ?></td>
              <td><?php echo number_format($augbkf); ?></td>
              <td class="bg-primary"><strong style="padding:5px"><?php echo number_format($totmaybkf); ?></strong></td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($bks); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmaybkf !='0'  && $bks !='0' && $bks !='')
                 {
                    $badbal=$bks-$totmaybkf;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmaybkf !='0'  && $bks !='0' && $bks !='')
                 {
                    $badbal=$bks-$totmaybkf;
                    $para=($badbal/$bks)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                   <input type="hidden" value="bks" class="textwithid" />
                   <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
              </td>
            </tr>
       
         <tr>
              <td style="background-color:#ffe6e6" class="cola1">Development</td>
              <td><?php echo number_format($maydev); ?></td>
              <td><?php echo number_format($jundev); ?></td>
              <td><?php echo number_format($julydev); ?></td>
              <td><?php echo number_format($augdev); ?></td>
              <td class="bg-primary"><strong style="padding:5px"><?php echo number_format($totmaydev); ?></strong></td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($devfee); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmaydev !='0'  && $devfee !='0' && $devfee !='')
                 {
                    $badbal=$devfee-$totmaydev;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmaydev !='0'  && $devfee !='0' && $devfee !='')
                 {
                    $badbal=$devfee-$totmaydev;
                    $para=($badbal/$devfee)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                   <input type="hidden" value="dev" class="textwithid" />
                   <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
              </td>
            </tr>
            
           <tr class="bg-secondary">
              <td><strong class="alert-success">Sub Total (CBC)</strong></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td><STRONG style="color:orange"><?php echo number_format($subtncbc); ?></STRONG></td>
              <td></td>
              <td></td>
              <td></td>
              <td class="leavethis"></td>
          </tr>
          
           <tr class="">
              <td colspan="9"></td>
              <td class="leavethis"></td>
          </tr>
          
          <tr class="">
              <td colspan="7"><strong class="text-primary">Nursery School</strong></td> <td class="leavethis"></td>
          </tr>
          
          <tr>
              <td style="background-color:#ffe6e6" class="cola1">School Fees</td>
              <td><?php echo number_format($mayfeen); ?></td>
              <td><?php echo number_format($junfeen); ?></td>
              <td><?php echo number_format($julyfeen); ?></td>
              <td><?php echo number_format($augfeen); ?></td>
              <td class="bg-primary"><strong style="padding:5px"><?php echo number_format($totmayfeen); ?></strong></td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($tufeen); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmayfeen !='0'  && $tufeen !='0' && $tufeen !='')
                 {
                    $badbal=$tufeen-$totmayfeen;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmayfeen !='0'  && $tufeen !='0' && $tufeen !='')
                 {
                    $badbal=$tufeen-$totmayfeen;
                    $para=($badbal/$tufeen)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                  <input type="hidden" value="tufeen" class="textwithid" />
                  <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
              </td>
          </tr>
          
          <tr>
              <td style="background-color:#ffe6e6" class="cola1">Transport Fee</td>
              <td><?php echo number_format($maytran); ?></td>
              <td><?php echo number_format($juntran); ?></td>
              <td><?php echo number_format($julytran); ?></td>
              <td><?php echo number_format($augtran); ?></td>
              <td class="bg-primary"><strong style="padding:5px"><?php echo number_format($totmaytran); ?></strong></td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($trafeen); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmaytran !='0'  && $trafeen !='0' && $trafeen !='')
                 {
                    $badbal=$trafeen-$totmaytran;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmaytran !='0'  && $trafeen !='0' && $trafeen !='')
                 {
                    $badbal=$trafeen-$totmaytran;
                    $para=($badbal/$trafeen)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                   <input type="hidden" value="trafeen" class="textwithid" />
                   <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
              </td>
          </tr>
          
          <tr>
              <td style="background-color:#ffe6e6" class="cola1">Uniform Fee</td>
              <td><?php echo number_format($mayunin); ?></td>
              <td><?php echo number_format($jununin); ?></td>
              <td><?php echo number_format($julyunin); ?></td>
              <td><?php echo number_format($augunin); ?></td>
              <td class="bg-primary"><strong style="padding:5px"><?php echo number_format($totmayunin); ?></strong></td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($unifeen); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmayunin !='0'  && $unifeen !='0' && $unifeen !='')
                 {
                    $badbal=$unifeen-$totmayunin;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmayunin !='0'  && $unifeen !='0' && $unifeen !='')
                 {
                    $badbal=$unifeen-$totmayunin;
                    $para=($badbal/$unifeen)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                   <input type="hidden" value="unifeen" class="textwithid" />
                   <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
              </td>
          </tr>
          
          <tr>
              <td style="background-color:#ffe6e6" class="cola1">Admission Fee</td>
              <td><?php echo number_format($mayadfel); ?></td>
              <td><?php echo number_format($junadfel); ?></td>
              <td><?php echo number_format($julyadfel); ?></td>
              <td><?php echo number_format($augadfel); ?></td>
              <td class="bg-primary"><strong style="padding:5px"><?php echo number_format($totmayadfeel); ?></strong></td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($adfee2); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmayadfeel !='0'  && $adfee2 !='0' && $adfee2 !='')
                 {
                    $badbal=$adfee2-$totmayadfeel;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmayadfeel !='0'  && $adfee2 !='0' && $adfee2 !='')
                 {
                    $badbal=$adfee2-$totmayadfeel;
                    $para=($badbal/$adfee2)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                   <input type="hidden" value="adfee2" class="textwithid" />
                   <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
              </td>
          </tr>
          <tr>
              <td style="background-color:#ffe6e6" class="cola1">Assessment Books</td>
              <td><?php echo number_format($maybkfn); ?></td>
              <td><?php echo number_format($junbkfn); ?></td>
              <td><?php echo number_format($julybkfn); ?></td>
              <td><?php echo number_format($augbkfn); ?></td>
              <td class="bg-primary"><strong style="padding:5px"><?php echo number_format($totmaybkfn); ?></strong></td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($boon); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmaybkfn !='0'  && $boon !='0' && $boon !='')
                 {
                    $badbal=$boon-$totmaybkfn;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmaybkfn !='0'  && $boon !='0' && $boon !='')
                 {
                    $badbal=$boon-$totmaybkfn;
                    $para=($badbal/$boon)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                   <input type="hidden" value="boon" class="textwithid" />
                   <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
              </td>
            </tr>
          
            <tr>
              <td style="background-color:#ffe6e6" class="cola1">Diaries</td>
              <td><?php echo number_format($maydian); ?></td>
              <td><?php echo number_format($jundian); ?></td>
              <td><?php echo number_format($julydian); ?></td>
              <td><?php echo number_format($augdian); ?></td>
              <td class="bg-primary"><strong style="padding:5px"><?php echo number_format($totmaydian); ?></strong></td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($diafeen); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmaydian !='0'  && $diafeen !='0' && $diafeen !='')
                 {
                    $badbal=$diafeen-$totmaydian;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmaydian !='0'  && $diafeen !='0' && $diafeen !='')
                 {
                    $badbal=$diafeen-$totmaydian;
                    $para=($badbal/$diafeen)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                   <input type="hidden" value="diafeen" class="textwithid" />
                   <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
              </td>
            </tr>
         
            <tr>
              <td style="background-color:#ffe6e6" class="cola1">Development</td>
              <td><?php echo number_format($maydevn); ?></td>
              <td><?php echo number_format($jundevn); ?></td>
              <td><?php echo number_format($julydevn); ?></td>
              <td><?php echo number_format($augdevn); ?></td>
              <td class="bg-primary"><strong style="padding:5px"><?php echo number_format($totmaydevn); ?></strong></td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($devn); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmaydevn !='0'  && $devn !='0' && $devn !='')
                 {
                    $badbal=$devn-$totmaydevn;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmaydevn !='0'  && $devn !='0' && $devn !='')
                 {
                    $badbal=$devn-$totmaydevn;
                    $para=($badbal/$devn)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                   <input type="hidden" value="devn" class="textwithid" />
                   <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
              </td>
            </tr>
            
           <tr class="bg-secondary">
              <td><strong class="alert-success">Sub Total (Nursery)</strong></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td><STRONG style="color:orange"><?php echo number_format($subtn); ?></STRONG></td>
              <td></td>
              <td></td>
              <td></td>
              <td class="leavethis"></td>
          </tr>
          
           <tr class="">
              <td colspan="9"><strong>OTHER INCOME</strong></td>
              <td class="leavethis"></td>
          </tr>
          <?php
          if($totmaybh==0)
          {
              
          }else{ ?>
            <tr>
              <td style="background-color:#ffe6e6" class="cola1">School Bus Hire</td>
              <td><?php echo $maybh; ?></td>
              <td><?php echo $junbh; ?></td>
              <td><?php echo $julybh; ?></td>
              <td><?php echo $augbh; ?></td>
              <td class="bg-primary"><strong style="padding:5px"><?php echo $totmaybh; ?></strong>
              </td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($bus); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmaybh !='0'  && $bus !='0' && $bus !='')
                 {
                    $badbal=$bus-$totmaybh;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmaybh !='0'  && $bus !='0' && $bus !='')
                 {
                    $badbal=$bus-$totmaybh;
                    $para=($badbal/$bus)*100;
                    
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                  <input type="hidden" value="bus" class="textwithid" />
                  <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
             </td>
          </tr>
          <?php
          }
          ?>
           <tr>
              <td style="background-color:#ffe6e6" class="cola1">Tour Payment</td>
              <td><?php echo number_format($maytour); ?></td>
              <td><?php echo number_format($juntour); ?></td>
              <td><?php echo number_format($julytour); ?></td>
              <td><?php echo number_format($augtour); ?></td>
              <td class="bg-primary"><strong style="padding:5px"><?php echo number_format($totmaytour); ?></strong></td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($tuwa); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmaytour !='0'  && $tuwa !='0' && $tuwa !='')
                 {
                    $badbal=$tuwa-$totmaytour;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmaytour !='0'  && $tuwa !='0' && $tuwa !='')
                 {
                    $badbal=$tuwa-$totmaytour;
                    $para=($badbal/$tuwa)*100;
                    
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                  <input type="hidden" value="tuwa" class="textwithid" />
                  <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
             </td>
          </tr>
       
          <tr>
              <td style="background-color:#ffe6e6" class="cola1">Farm Income</td>
              <td><?php echo number_format($mayfam); ?></td>
              <td><?php echo number_format($junfam); ?></td>
              <td><?php echo number_format($julyfam); ?></td>
              <td><?php echo number_format($augfam); ?></td>
              <td class="bg-primary"><strong  style="padding:5px"><?php echo number_format($totmayfam); ?></strong> </td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($farm1); ?></strong></td>
              <td>
                 <strong>
                 <?php
                 if($totmayfam !='0'  && $farm1 !='0' && $farm1 !='')
                 {
                    $badbal=$farm1-$totmayfam;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmayfam !='0'  && $farm1 !='0' && $farm1 !='')
                 {
                    $badbal=$farm1-$totmayfam;
                    $para=($badbal/$farm1)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                  <input type="hidden" value="farm1" class="textwithid" />
                  <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i>
                  </button>
             </td>
          </tr>
          
          <?php
            $peri='May-August-'.$yr;
            $in='in';
            $query=mysqli_query($con,"select IncomeCat.*,(SELECT SUM(Amount) FROM Otherincome where Month='May' AND Year='$yr' AND Cat=IncomeCat.count) as mayinco,
            (SELECT SUM(Amount) FROM Otherincome where Month='June' AND Year='$yr' AND Cat=IncomeCat.count) as juninco,
            (SELECT SUM(Amount) FROM Otherincome where Month='July' AND Year='$yr' AND Cat=IncomeCat.count) as julinco,
            (SELECT SUM(Amount) FROM Otherincome where Month='August' AND Year='$yr' AND Cat=IncomeCat.count) as auginco,
            (SELECT SUM(Amount) FROM Incomebudget where Period='$peri' AND ID=IncomeCat.count) as badget from IncomeCat ORDER BY Item ASC");
            while($row=mysqli_fetch_array($query))
            {
            $mayinco=$row['mayinco'];
            $juninco=$row['juninco'];
            $julinco=$row['julinco'];
            $auginco=$row['auginco'];
            $bud=$row['badget'];
            
            $toto=$juninco+$mayinco+$julinco+$auginco;
             if($toto<1)
            { }else
            {
           ?>
           ?>
           <tr>
             <td style="background-color:#ffe6e6" class="cola1"><?php echo $row['Item']; ?></td> 
             <td><?php echo number_format($mayinco); ?></td>
             <td><?php echo number_format($juninco); ?></td>
             <td><?php echo number_format($julinco); ?></td>
             <td><?php echo number_format($auginco); ?></td>
             <td class="bg-primary"><strong><?php echo number_format($toto); ?></strong></td>
             <td style="background-color:#e6ccff"><strong><?php echo number_format($bud); ?></strong></td>
             
             <td>
                 <strong>
                 <?php
                 if($toto !='0'  && $bud !='0' && $bud !='')
                 {
                    $badbal=$bud-$toto;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($toto !='0'  && $bud !='0' && $bud !='')
                 {
                    $badbal=$bud-$toto;
                    $para=($badbal/$bud)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
             <td class="leavethis">
                  <input type="hidden" value="<?php echo $row['count']; ?>" class="itemidd" />
                  <button class="btn btn-default budgettincome btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
             </td>
          </tr>
          <?php
            }
            }
            ?>

           <tr class="bg-success">
              <td><strong>TOTAL GROSS INCOME</strong></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
              <td><strong style="font-size:22px"><?php echo number_format($totincomemayaug); ?></strong></td>
              <td></td>
              <td></td>
              <td></td>
              <td class="leavethis"></td>
          </tr>
          
          
          <tr>
               <td colspan="9"></td>
          </tr>
          
           <tr class="alert-warning">
              <td colspan="10"><strong>Expenses</strong></td>
          </tr>
           <tr>
              <td style="background-color:#ffe6e6" class="cola1">Projects</td>
              <td><?php echo number_format($mpro); ?></td>
              <td><?php echo number_format($jupro); ?></td>
              <td><?php echo number_format($julpro); ?></td>
              <td><?php echo number_format($aupro); ?></td>
              <td style="background-color:#fff2cc"><strong><?php echo number_format($totmayproject); ?></strong></td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($proje); ?></strong></td>
               <td>
                 <strong>
                 <?php
                 if($totmayproject !='0'  && $proje !='0' && $proje !='')
                 {
                    $badbal=$proje-$totmayproject;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmayproject !='0'  && $proje !='0' && $proje !='')
                 {
                    $badbal=$proje-$totmayproject;
                    $para=($badbal/$proje)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              <td class="leavethis">
                  <input type="hidden" value="proje" class="textwithid" />
                  <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
              </td>
          </tr>
          <?php
          if($totmaysala==0)
          {
              
          }else{ ?>
           <tr>
              <td style="background-color:#ffe6e6" class="cola1">Salaries</td>
              <td><?php echo $msala; ?></td>
              <td><?php echo $jusala; ?></td>
              <td><?php echo $julsala; ?></td>
              <td><?php echo $ausala; ?></td>
              <td style="background-color:#fff2cc"><strong><?php echo number_format($totmaysala); ?></strong></td>
              <td style="background-color:#e6ccff"><strong><?php echo number_format($sala); ?></strong></td>
               <td>
                 <strong>
                 <?php
                 if($totmaysala !='0'  && $sala !='0' && $sala !='')
                 {
                    $badbal=$sala-$totmaysala;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($totmaysala !='0'  && $sala !='0' && $sala !='')
                 {
                    $badbal=$sala-$totmaysala;
                    $para=($badbal/$sala)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
              
              <td class="leavethis">
                  <input type="hidden" value="sala" class="textwithid" />
                  <button class="btn btn-default budget btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
                  </td>
          </tr>
            <?php
          }
            $peri='May-August-'.$yr;
            $query=mysqli_query($con,"select expenses.*,(SELECT SUM(Amount) FROM Expenses where Month='May' AND Year='$yr' AND Cat=expenses.Count) as mayyexpe,
            (SELECT SUM(Amount) FROM Imprest2 where Month='May' AND Year='$yr' AND Cate=expenses.Count) as mayyexpe2,
            (SELECT SUM(Amount) FROM Expenses where Month='June' AND Year='$yr' AND Cat=expenses.Count) as juneexpe,
            (SELECT SUM(Amount) FROM Imprest2 where Month='June' AND Year='$yr' AND Cate=expenses.Count) as juneexpe2,
            
            (SELECT SUM(Amount) FROM Expenses where Month='July' AND Year='$yr' AND Cat=expenses.Count) as julyexpe,
            (SELECT SUM(Amount) FROM Imprest2 where Month='July' AND Year='$yr' AND Cate=expenses.Count) as julyexpe2,
            
            (SELECT SUM(Amount) FROM Expenses where Month='August' AND Year='$yr' AND Cat=expenses.Count) as augaexpe,
            (SELECT SUM(Amount) FROM Imprest2 where Month='August' AND Year='$yr' AND Cate=expenses.Count) as augaexpe2,
            (SELECT SUM(Amount) FROM BudgetAmount where Period='$peri' AND ID=expenses.Count) as badget from expenses ORDER BY Item ASC");
            while($row=mysqli_fetch_array($query))
            {
            $totmaye=$row['mayyexpe']+$row['mayyexpe2'];
            $totjunee=$row['juneexpe']+$row['juneexpe2'];
            $totjulye=$row['julyexpe']+$row['julyexpe2'];
            $totaugae=$row['augaexpe']+$row['augaexpe2'];
            $badget=$row['badget'];
            
            $tot=$totmaye+$totjunee+$totjulye+$totaugae;
            if($tot<1)
            { }else
            {
           ?>
          <tr>
             <td style="background-color:#ffe6e6" class="cola1"><?php echo $row['Item']; ?></td> 
             <td><?php echo number_format($totmaye); ?></td>
             <td><?php echo number_format($totjunee); ?></td>
             <td><?php echo number_format($totjulye); ?></td>
             <td><?php echo number_format($totaugae); ?></td>
             <td style="background-color:#fff2cc"><strong><?php echo number_format($tot); ?></strong></td>
             <td style="background-color:#e6ccff"><strong><?php echo number_format($badget); ?></strong></td>
             
             <td>
                 <strong>
                 <?php
                 if($tot !='0'  && $badget !='0' && $badget !='')
                 {
                    $badbal=$badget-$tot;
                    echo number_format($badbal);
                 }
                 ?>
                 </strong>
             </td>
             <td>
                 <strong class="text-success">
                 <?php
                 if($tot !='0'  && $badget !='0' && $badget !='')
                 {
                    $badbal=$badget-$tot;
                    $para=($badbal/$badget)*100;
                    echo number_format((float)$para, 2, '.', '').'%';
                 }
                 ?>
                 </strong>
             </td>
             <td class="leavethis">
                  <input type="hidden" value="<?php echo $row['Count']; ?>" class="itemid" />
                  <button class="btn btn-default budgett btn-sm">Budgeted Amount <i class="fa fa-refresh"></i></button>
             </td>
          </tr>
          <?php
            }
            }
            ?>
          
           <tr class="alert-danger">
              <td><STRONG>TOTAL EXPENSES</STRONG></td>
              <td><?php  ?></td>
              <td><?php ?></td>
              <td><?php  ?></td>
              <td><?php  ?></td>
              <td><STRONG class=""><?php echo number_format($totalexpens); ?></STRONG></td>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
          </tr>
          
          <tr class="alert-warning">
              <td><STRONG>BALANCE (KES)</STRONG></td>
              <td><?php  ?></td>
              <td><?php ?></td>
              <td><?php  ?></td>
              <td><?php  ?></td>
              <?php
              $bala=$totincomemayaug-$totalexpens;
              if($bala>0)
              {
              ?>
              <td class="alert-success"><STRONG class=""><?php echo number_format($totincomemayaug-$totalexpens); ?></STRONG> <small>SURPLUS</small></td>
              <?php
              }else{
              ?>
              <td class="alert-warning"><STRONG class=""><?php echo number_format($totincomemayaug-$totalexpens); ?></STRONG> <small>DEFICIT</small></td>
              <?php
              } 
              ?>
              <td></td>
              <td></td>
              <td></td>
              <td></td>
          </tr>
      </tbody>
      <tfooter class="leavethis">
          <tr class="leavethis">
              <td colspan="10"><button class="btn btn-default btn-sm pull-right" id="down"> Download Excel File <i class="fa fa-cloud-download"></i></button>
              </td>
          </tr>
      </tfooter>
  </table>
  <input type="hidden" value="<?php echo $peri; ?>" id="periodicc" />
</div>