<html>
 
    <head>
        <title><?php echo $b_header['title']; ?></title>
        <style>
            @media print
            {
                * {-webkit-print-color-adjust:exact;}
                @page {margin:0in 0.10in 0in 0in; }
                .super_container
                {
                    page-break-after: always;
                    margin-top:0.25in;
                    position:relative;
                    width:100vw;
                    height:710px;
                }
            }
            body {margin: 0.25in 0.25in 0.63in 0.25in; box-sizing:border-box;width:100vw; height:100vh;padding-bottom:0.63in;}
            *{margin:0;padding:0;font-family:calibri;}
            .clear:after{content:"";clear:both;display:block;}
            .left{float:left;}
            .right{float:right;}
            .wd-10{width:10%;}
            .wd-20{width:20%;}
            .wd-30{width:30%;}
            .wd-40{width:40%;}
            .wd-50{width:50%;}
            .wd-60{width:60%;}
            .wd-70{width:70%;}
            .wd-80{width:80%;}
            .wd-90{width:90%;}
            .wd-100{width:100%;}
            .wd-15{width:15%;}
            .wd-25{width:25%;}
            .wd-35{width:35%;}
            .wd-45{width:45%;}
            .wd-55{width:55%;}
            .wd-65{width:65%;}
            .wd-75{width:75%;}
            .wd-85{width:85%;}
            .wd-95{width:95%;}
            .wd-100{width:100%;}
            .title{font-size:35px;}
            .super_container
            {
                margin-bottom:200px;
                position:relative;
                width:100vw;
                height:710px;
            }
            .wrapper{
                border:4px transparent #18a05e;
                
                outline-offset: 5px;
                box-sizing: border-box;
                padding:5px;
            }
            .super_wrapper
            {
                position:absolute;
                top:0;
                left:0;
                width:100%;
                z-index:120;
                margin:0;
                padding:0;
            }
            /*.watermark*/
            /*{*/
            /*    height:200px;*/
            /*    width:300px;*/
            /*    margin:auto;*/
            /*    padding-top:50px;*/
            /*    padding-left:100px;*/
            /*    opacity:0.1;*/
            /*    background:url("<?php echo base_url().$b_header['logo1']; ?>");*/
            /*    background-size:100% 100%;*/
            /*}*/
            /*.watermark_wrapper*/
            /*{*/
            /*    height:470px;*/
            /*    width:100%;*/
            /*    margin-top:50px;*/
            /*    display:inline-flex;*/
            /*    display:-webkit-inline-flex;*/
            /* }*/
            .wrapper.left2{
                width: calc(90vw);
                margin-right: 20px;
                margin-left: 20px;
            }
            h1,h2,h3{
                color:#191970;
                font-family:calibri;
                text-align:center;
            }
            .boxed{color:#000000;width:80%;margin:0 auto;}
            .header{
                width:100%;
                border-bottom:4px solid #191970;            
            }
            .body{
                padding:10px;
            }
            .row{
                width:100%;
                margin: 0px auto;  
            }
            .text-center{text-align:center;}
            .bold{font-weight:bold;}
            .b-u-l{
                border-bottom: 1px solid #000;
                height:inherit;
            }
            .x-small{
                font-size: 12px;
            }
            .x-x-small{
                font-size: 9px;
            }
            .page_break{
                width: 100vw;
                height: 100vh;
                padding: 10px 0px;
                box-sizing: border-box;
            }
            .tbl1
            {
                border: 1px solid #000;
                text-align:center;
                width:100%;
                min-height:20px;
            }
            th{
                font-size:10px;
                border: 1px solid #000;
                  border-right: 0px;
                border-bottom: 0px; 
                background-color:#ccccb3; 
                padding: 3px !important;
            }
            td{
                font-size:10px;
                border: 1px solid #000;
                text-align: left;
                  border-right: 0px;
                border-bottom: 0px; 
                padding: 2px !important;
            }
            .normal{
                font-weight: normal !important;
            }
            .text-right{
                text-align: right !important;
            }
            .text-left{
                text-align: left !important;
            }
            .margin-a{margin: 30px auto 0px auto;}
        </style>
    </head>
    <body >

        <div class="super_container">
        <div class="container-fluid">
          <div class="row header wd-100 clear">
                   <div class="wd-100 clear">
                                <div class=" text-left left ">
                                    <img src="<?php echo base_url().$b_header['logo1']; ?>" style="width:50px;height:50px;">
                                </div>
                                <div class=" text-left right ">
                                    <img src="<?php echo base_url().$b_header['logo2']; ?>" style="width:50px;height:50px;">
                                </div>
                                <div>
                                    <center><h1><?php echo $b_header['title']; ?></h1></center>
                                    <center><h3 style="color:#000 !important;"><i><?php echo $b_header['tagline']; ?></i></h3></center>
                                    <center><i><h3 style="color:#000 !important;font-weight:normal;"><?php echo $b_header['short_address']; ?></h3></i></center>
                                    <?php if($type=="teacher"){$t="Teacher";}else{ $t="Staff";} ?>
                                    <center><h3 class="boxed" style="margin-top:0px !important;font-size:23px;"> <h3> <?php echo $type.' '."Monthly Salary Report"; ?></h3></center>
                                </div>
                            </div>
                               <?php echo "<b>Month</b>: ".date("F- Y",strtotime($month)); ?>
          </div>
<br>

          <div class="row header">
    <div>
<?php $grosgrand=0; $incgrand=0; $adgrand=0;$daygrand=0;$provdgrand=0; $net=0;$rem=0;$provdgrand_ret=0;$t_allonce = count($allonce);$t_paid_salary = 0;$t_unpaid_salary = 0; ?>
                      <table  class="tbl1" >
                      
                    <thead >
                        <tr>
                          
                          <th>#</th>
                          <th style="text-align:center">Employee Name</th>
                          <th style="text-align:center">Designation</th>
                          <th style="text-align:center">Basic Salary</th>
                          <th style="text-align:center">Increments</th>
                           <th style="text-align:center">Attendence Bouns</th>
                          <th style="text-align:center">Advance</th>
                          <th  style="text-align:center"colspan="<?= count($allonce) ?>">Allowances</th>
                          <th style="text-align:center">Gross Salary</th>
                          <th style="text-align:center"colspan="<?= count($loan_def) ?>">Loans</th>
                          <th style="text-align:center"colspan="<?= count($deduction_def) ?>">Deduction</th>
                          <th style="text-align:center"colspan="<?= count($personal_exp) ?>">Expenses</th>
                          <th style="text-align:center">P.F</th>
                          <th style="text-align:center">Return P.F</th>
                          <th style="text-align:center">Days Deduction</th>
                          <th style="text-align:center">Net Pay</th>
                          <th style="text-align:center">Status</th>
                        </tr>
                        <tr>
                         <th>-</th>
                         <th>-</th>
                         <th>-</th>
                         <th>-</th>
                         <th>-</th>
                         <th>-</th>
                          <?php 
                          if(!empty($allonce))
                          {
                          foreach ($allonce as $key => $value) { ?>
                            <th style="font-size:9px;"><?php echo $value['name']; ?></th>
                          <?php  }
                              
                          }else{
                           echo"<th>-</th>";
                          } ?>
                            <th>-</th>
                        <!--Loan-->
                        <?php
                         if(!empty($loan_def)){
                             foreach ($loan_def as $key => $value) {?>
                           <th style="font-size:9px;"><?php echo $value['name']; ?></th>
                        <?php }}else{
                           echo"<th>-</th>";
                          }  ?>
                         <!--End Loan-->
                         <?php
                            if(!empty($deduction_def)){
                                foreach ($deduction_def as $key => $value) { ?>
                            <th style="font-size:9px;"><?php echo $value['name']; ?></th>
                        <?php  }}else{
                           echo"<th>-</th>";
                          }  ?>
                        <!--Personal Expense header-->
                        <?php
                            if(!empty($personal_exp)){
                                 foreach ($personal_exp as $key => $value) { ?>
                            <th style="font-size:9px;"><?php echo $value['name']; ?></th>
                        <?php  }}else{
                           echo"<th>-</th>";
                          }  ?>
                        <!--end personal expense header-->
                         <th>-</th>
                         <th>-</th>
                         <th>-</th>
                         <th>-</th>
                         <th>-</th>
                        </tr>
                      </thead>
                
                      <?php  
                     $i=1;
                     $sal=0;
                     $adddinc=0;
                     $tmp_bounes=0;
                     $allo=array();
                     $ded=array();
                     $per=array();
                     $ad=array();
                     $days_ded=array();
                     $incr=0;
                     $loans=array();
                   
                     foreach ($employee as $key => $emp) { 
                      
                       $gros=0;
                       ?>
                        <tr>
                        <td style="font-size:6px;"><?php echo $i++; ?></td>
                        <td><?php echo $emp['firstname']." ".$emp['lastname']; ?></td>
                        <td><?php echo $emp['designation']; ?></td>
                        <td style="text-align:right">
                            <?php 
                            $prev_inc=$this->db->select('sum(amount) as amount')
                                             ->from('increments')
                                             ->where('bothid',$emp['empid'])
                                              ->where('month <',$month)
                                              ->where('refrence',$type)
                                              ->where('is_del',0)
                                              ->get()->row_array()['amount'];
                        if(!empty($prev_inc))
                         {
                             $tmp_sal=$emp['salery']+$prev_inc;
                          
                         }else
                         {
                            $tmp_sal=$emp['salery'];
                         }  
                          echo number_format($tmp_sal);
                            $gros+=$tmp_sal;
                            $sal+=$tmp_sal; 
                            ?>
                            </td>
                        <td style="text-align:right"><?php $v=0;  foreach ($increment as $keyinc => $allinc) {
                                if($emp['empid']==$allinc['bothid']){
                                  $v = $allinc['amount'];
                                }
                            } 
                            echo $v;
                            $gros+=$v;
                            $adddinc+=$v;
                            ?></td>  
                              <td>
                        <?php 
                        
                        $att_bounes=0;
                          $att_bounes=$this->db->select('bounes')
                                             ->from('days_deduction')
                                             ->where('bothid',$emp['empid'])
                                              ->where('month',$month)
                                              ->where('type',$type)
                                              ->where('is_delete',0)
                                              ->get()->row_array()['bounes'];
                        
                         echo $att_bounes;
                         $gros+=$att_bounes;
                         $tmp_bounes+=$att_bounes;
                          ?>
                    </td>
<!--Advance Ammount start-->
    <?php 
                     
                         $adv=$this->sm->advance($emp['empid'],$type,$month);  
                         ?>
                           <td style="text-align:right">
                           <?php
                            if($adv>0)
                            { 
                              echo number_format($adv); 
                              $gros-=$adv; 
                               $adgrand+=$adv;  
                             }
                             else
                             {
                             echo 0;
                             } 
    ?></td>
                                
                                        

<!--End dvance Ammount-->
                        
    
                        <?php 
                       if(!empty($allonce))
                       {
                        foreach ($allonce as $key => $all) 
                        { 
                        $am=$this->sm->getallonce_ammount2($emp['salery'],$emp['empid'],$type,$all['id']);
                         ?>
                      <td style="text-align:right">
                      <?php 
                      if($am>0)
                      { 
                        echo number_format($am); 
                        $gros+=$am;
                          }
                      else{
                      echo 0;
                      } 
                      $am!=0?(!empty($allo[$key])?$allo[$key]+=$am:$allo[$key]=$am):(!empty($allo[$key])?$allo[$key]+=0:$allo[$key]=0); ?>
                      </td>
                                
                        <?php }}else{echo "<td>0</td>";} ?>
                      
                           <td style="text-align:right"><?php echo number_format($gros); $grosgrand+=$gros; ?></td>
                           
                            <!--Loan-->
                            <?php 
     
                           if(!empty($loan_def))
                           {
                        foreach ($loan_def as $key => $all)
                         { 
                         $loon=$this->sm->getloan_ammount2($emp['salery'],$emp['empid'],$type,$all['id'],$month);  
                         ?>
                           <td style="text-align:right">
                           <?php
                            if($loon>0)
                            { 
                              echo number_format($loon); 
                              $gros-=$loon;  
                             }
                             else
                             {
                             echo 0;
                             } 
         $loon!=0?(!empty($loans[$key])?$loans[$key]+=$loon:$loans[$key]=$loon):(!empty($loans[$key])?$loans[$key]+=0:$loans[$key]=0); ?></td>
                                
                        <?php }}else
                        {
                        echo "<td>0</td>";
                        }?> 
                        
                        <!--End Loan-->
                  
<!--Add new deductions-->

 <?php 
 
                           if(!empty($deduction_def))
                           {
                        foreach ($deduction_def as $key => $all)
                         { 
                         $pai=$this->sm->getdeduct_ammount2($emp['salery'],$emp['empid'],$type,$all['id'],$month);  
                         ?>
                           <td style="text-align:right">
                           <?php
                            if($pai>0)
                            { 
                              echo number_format($pai); 
                              $gros-=$pai;  
                             }
                             else
                             {
                             echo 0;
                             } 
         $pai!=0?(!empty($ded[$key])?$ded[$key]+=$pai:$ded[$key]=$pai):(!empty($ded[$key])?$ded[$key]+=0:$ded[$key]=0); ?></td>
                                
                        <?php }}else{echo "<td>0</td>";} ?>

<!--End new deductions-->

<!--personal expense start-->
    <?php 
      if(!empty($personal_exp))
           {
                        foreach ($personal_exp as $key => $all)
                         { 
                         $pai2=$this->sm->personal_exp($emp['empid'],$type,$all['id'],$month);  
                         ?>
                           <td style="text-align:right">
                           <?php
                            if($pai2>0)
                            { 
                              echo number_format($pai2); 
                              $gros-=$pai2;  
                             }
                             else
                             {
                             echo 0;
                             } 
         $pai2!=0?(!empty($per[$key])?$per[$key]+=$pai2:$per[$key]=$pai2):(!empty($per[$key])?$per[$key]+=0:$per[$key]=0); ?></td>
                                
                        <?php }}else{echo "<td>0</td>";} ?>                   

<!--End personal expense-->

<!--Provident fund-->

 <?php 
                         $provd=$this->sm->provident($emp['salery'],$emp['empid'],$type,$month);  
                         ?>
                           <td style="text-align:right">
                           <?php
                            if($provd>0)
                            { 
                              echo number_format($provd); 
                              $gros-=$provd; 
                              $provdgrand+=$provd;  
                             }
                             else
                             {
                             echo 0;
                             } 
                           
                              ?></td>
                        
<!--End providend fund-->

                      
                         <!--Provident fund-->

 <?php 
                         $provd_ret=$this->sm->provident_ret($emp['empid'],$type,$month);  
                         ?>
                           <td style="text-align:right">
                           <?php
                            if($provd_ret>0)
                            { 
                              echo number_format($provd_ret); 
                              $gros+=$provd_ret; 
                              $provdgrand_ret+=$provd_ret;  
                             }
                             else
                             {
                             echo 0;
                             } 
                           
                              ?></td>
                        
<!--End providend fund-->



<!--Days start-->
    <?php 
                       
                         $days=$this->sm->days_deduction($emp['empid'],$type,$month);  
                         ?>
                           <td>
                           <?php
                            if($days>0)
                            { 
                              echo $days; 
                              $gros-=$days;  
                               $daygrand+=$days;  
                             }
                             else
                             {
                             echo 0;
                             } 
    
      ?></td>
                                
                                      

<!--End Days Deduction Ammount-->
                        <td style="text-align:right"><?php echo number_format($gros); $net+=$gros; ?></td>
                          <td><?php
                              if($emp['is_paid']==0)
                              {
                                  $t_unpaid_salary += $gros;
                                   echo "Unpaid";
                              }else
                              {
                                  $t_paid_salary += $gros;
                                  echo "Paid";
                              }
                               
                               ?></td>
                        
                        
                        </tr>
                     <?php  }  
                     ?>
                     <tr>
                     <td><b>-</b></td>
                    <td colspan="2"><b>Total</b></td>
                     <td style="text-align:right"><b><?php echo number_format($sal); ?></b></td>
                     <td style="text-align:right"><b><?php echo number_format($adddinc); ?></b></td>
                      <td style="text-align:right"><b><?php echo number_format($tmp_bounes); ?></b></td>
                     <td style="text-align:right"><b>
                     <?php 
                     echo number_format($adgrand); 
                     ?>
                     </b></td>
                     <?php 
                     if(!empty($allo))
                     {
                    foreach ($allo as $key => $value){
                     
                     ?>
                       <td style="text-align:right"><b>
                           <?php 
                          echo number_format($value); 
                          
                           ?>
                           </b></td>
                     <?php } }else
                     {
                         if(!empty($allonce))
                         {
                         foreach ($allonce as $key => $value) 
                         {?>
                            <th style="text-align:right"><?php echo "0"; ?></th>
                  <?php  }}else{echo "<td>0</td>";}
                    }?>
                     <td style="text-align:right"><b>
                     <?php 
                     echo number_format($grosgrand); ?>
                     </b></td>
                      <?php 
                      if(!empty($loans))
                     {
                    foreach ($loans as $key => $value){?>
                       <td  style="text-align:right"><b><?php echo number_format($value); ?></b></td>
                     <?php }
                         
                     }else
                     {
                         if(!empty($loan_def))
                         {
                         foreach ($loan_def as $key => $value) {?>
                            <th style="text-align:right"><?php echo "0"; ?></th>
                        <?php  }}else{echo "<td>0</td>";} ?>
                       
                   <?php  }?>
                      <?php
                       if(!empty($ded))
                     {
                      foreach ($ded as $key => $value) {?>
                       <td style="text-align:right"><b><?php echo number_format($value); ?></b></td>
                       <?php }}else
                     {
                         if(!empty($deduction_def)){
                         foreach ($deduction_def as $key => $value) {?>
                            <th style="text-align:right"><?php echo "0"; ?></th>
                        <?php  }}else{ echo "<td>0</td>";} ?>
                    
                   <?php  }?>
                     <?php
                  if(!empty($per))
                     {
                     foreach ($per as $key => $value) {?>
                       <td style="text-align:right"><b><?php echo number_format($value); ?></b></td>
                     <?php }}else
                     {
                         if(!empty($personal_exp))
                         {
                         foreach ($personal_exp as $key => $value) {?>
                            <th style="text-align:right"><?php echo "0"; ?></th>
                        <?php  }}else{echo "<td>0</td>";} ?>
                   <?php  }?>

                       <td style="text-align:right"><b>
                     <?php echo number_format($provdgrand); ?>
                     </b></td>
                     <td style="text-align:right"><b>
                     <?php echo number_format($provdgrand_ret); ?>
                     </b></td>
                     

                      <td><b>
                     <?php 
                    echo number_format($daygrand); 
                     ?>
                     </b></td>
                     <td style="text-align:right"><b><?php echo number_format($net); ?></b></td>
                      <td>-</td>
                     
                     </tr>
                      </tbody>
                      </table>
                      </div >
                      <br>
                      <div class="wd-100 clear">
                          <div class="wd-40">
                              <h4>Total Paid: <?= number_format($t_paid_salary);?></h4>
                              <h4>Total UnPaid: <?= number_format($t_unpaid_salary);?></h4>
                          </div>
                          
                      </div>
                      
</div>

 <script>window.print();</script>
    </body>
</html>

