<? include "top.php"; ?>
<!DOCTYPE html>
<html>
   <head>
      <?php include('include/head.php'); 
         $stdt=$_POST['stdt'];
         $enddt=$_POST['enddt'];

         $getcom=f(q("SELECT * FROM tbl_company WHERE c_id=1"));

         $title="Profit and Loss Statement from ".date("d-m-Y", strtotime($stdt))." to ".date("d-m-Y", strtotime($enddt));
         ?>
      <title>Profit and Loss Statement from <?=date("d-m-Y", strtotime($stdt))?> to <?=date("d-m-Y", strtotime($enddt))?></title>
      
      <style type="text/css" media="print">
 @page {
  size: auto;
}
</style>
   <style type="text/css">
      table{

         width: 100%;
      }
      th{

      font-size: 13px !important;
      min-width: 60px;
      padding: 4px;
      text-align: center;
      background-color: #e5eef5;
      color: #5c5c5c;
      border-right: 1px solid white;
      -webkit-print-color-adjust: exact; 
    }
    td{

      font-size: 12px !important;
      text-align: center;
      border: 1px solid gray;

    }
    tr{

      width: 100%;

    }
    .trtot{

      background-color: #e5eef5;
      color: #5c5c5c;
    }
    .noborder{

      border:0px white;
    }
   </style>
   <script type="text/javascript">
              
              function settopval(spanid,spanval){


                document.getElementById(spanid).innerHTML='&#8377; '+spanval;

              }





  </script>
   </head>
   <body style="background-color: white !important;padding-left: 5%;padding-right: 5%;">
      <table>
   <tr>
      <td style="border:0px;font-size: 14px;">
         <h3 style="font-weight: bold;color:#0a6587;line-height: 45px;vertical-align: middle; "><img src="vendors/images/logo.png"><?=$getcom['c_name']?></h3>
         <h6><?=$getcom['c_address']?></h6>
         <b>Phone:</b> <?=$getcom['c_phone']?>, <b>Mobile:</b><?=$getcom['c_mobile']?><br>
          <b>GSTN:</b> <?=$getcom['c_emailalt']?>
      </td>
   </tr>
   
</table><br>
<center><?=$title?></center>
<br>
<br>
  <table>
      <tr style="border:1px solid #c9d0cc;">
        
               
        <td class="noborder" style="width: 25%;padding: 1%;">
          
          Total Income(+)<br>
          <b><span id="topDebit"></span></b>
        </td>

        <td class="noborder" style="width: 25%;padding: 1%;">
          
          Total Expense(-)<br>
          <b><span id="topCredit"></span></b>

        </td>

        <td class="noborder" style="width: 25%;padding: 1%;">
            
            Net Balance<br>
          <b><span id="topbalance"></span></b>

        </td>

      </tr>

  </table>
<br><br>
      <table class="stripe">
         <thead>
            <tr>
               <th style="min-width: 40%">Income</th>
               <th  style="min-width: 20%"></th>
               <th  style="min-width: 40%">Expense</th>
               
                
               
            </tr>
         </thead>
         <tbody>
            
            <tr>
               <td class="noborder" style="min-width: 400px;">
                    <table>
                      <tr>
                    <td>Date</td>
                    <td>Details</td>
                    <td>Amount</td>
               </tr>
                        <?
             // echo "SELECT * FROM `tbl_trans` WHERE trn_type='DEPOSIT AC' AND trn_type='MONTHLY BILL' AND trn_date BETWEEN '$stdt' AND '$enddt'";
               $query=mysqli_query($con,"SELECT * FROM `tbl_trans` WHERE trn_type='MONTHLY BILL' AND trn_date BETWEEN '$stdt' AND '$enddt'");
               while($arrc=mysqli_fetch_array($query)){$c++;
               
                  $totalin=floatval($totalin)+floatval($arrc['trn_amt']);
                  
               ?>
              <tr>
                    <td><?=date("d-m-Y", strtotime($arrc['trn_date']))?></td>
                    <td><?=$arrc['trn_memo']?></td>
                    <td style="background-color: #e8f6ed;"><?=$arrc['trn_amt']?></td>
               </tr>




             <? } ?>
              <tr>
                    <td></td>
                    <td><b>Total Income</b></td>
                    <td><b><?=$totalin?></b></td>
               </tr>

                    </table> 


               </td>
               <td class="noborder" style="min-width: 200px;"></td>
               <td  class="noborder" style="vertical-align: top">
                    <table>
                      <tr>
                    <td>Date</td>
                    <td>Details</td>
                    <td>Amount</td>
               </tr>
                        <?
              //echo "SELECT * FROM `tbl_trans` WHERE trn_gst='1' AND trn_ac='EXPENSE AC' AND trn_date BETWEEN '$stdt' AND '$enddt'";
               $query=mysqli_query($con,"SELECT * FROM `tbl_trans` WHERE trn_type='EXPENSE AC' AND trn_date BETWEEN '$stdt' AND '$enddt'");
               while($arrc=mysqli_fetch_array($query)){$c++;
               
                  $totalout=floatval($totalout)+floatval($arrc['trn_amt']);
                  
               ?>
               

               <tr>
                    <td><?=date("d-m-Y", strtotime($arrc['trn_date']))?></td>
                    <td><?=$arrc['trn_memo']?></td>
                    <td style="background-color: #f6e9df;"><?=$arrc['trn_amt']?></td>
               </tr>


             <? } ?>
              <tr>
                    <td></td>
                    <td><b>Total Expense</b></td>
                    <td><b><?=$totalout?></b></td>
               </tr>
               <script type="text/javascript">
                 settopval('topCredit',"<?=$totalout?>");
                 settopval('topDebit',"<?=$totalin?>");
                 <?
                      $totals=floatval($totalin)-floatval($totalout);
                      $valval=number_format($totals, 2, '.', '');
                      if(floatval($totals)>0){

                        $topnetbal="<span style='color:#4b9f6b;'>".$valval." Cr</span>";
                      }else{

                        $topnetbal="<span style='color:#ea5d08;'>".$valval." Dr</span>";

                      }

                    ?>
                    settopval('topbalance',"<?=$topnetbal?>");
                  
               </script>
                    </table> 

               </td>
               
               
            </tr>
           
         </tbody>
         <tfoot>
            
            </tfoot>
      </table><br><br>
      <?php include('include/script.php'); ?>
      
   </body>
</html>

