<?php 
session_start();
ob_start(); 
include "header.php";
//$objIms->Semifinisheditem_alter();
?>
<script type="text/javascript">

window.addEventListener("keyup", function(e){ if(e.keyCode == 27) history.back(); }, false);

</script>
<style type="text/css">
    
        tr:hover {background-color:#bcd1cd;}

</style>
      <div class="page-wrapper">
            <!-- Container fluid  -->
            <div class="container-fluid">
                <!-- Start Page Content -->
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div class="card-body" id="printableArea">
 

<form method="post">
        <div class="panel">
            <div class="panel-heading" style="font-style: bold; font-size: 20px"><h3>Ledger Monthly Summary</h3></div>
                <p>&nbsp;</p>
                
                    <table width="100%" class="table table-bordered">
                     <tr height="32" align="left">
                        <th nowrap="nowrap" width="50%" rowspan="2">Particular</th>
                        <th nowrap="nowrap" width="17%" colspan="2" style="text-align: center;">Closing Balance</th>
                        <th nowrap="nowrap" width="50%" rowspan="2">Closing Balance</th>
                    </tr>
                    <tr>
                        
                        <th nowrap="nowrap" width="18%" colspan="1">Debit</th>
                        <th nowrap="nowrap" width="18%" colspan="1">Credit</th>
                        
                    </tr>
					 <tr height="32">
                        <td nowrap="nowrap" width="6%">Opening Balance</td>
                        <td nowrap="nowrap" width="6%"></td>
                        <td nowrap="nowrap" width="6%"></td>
                        <td nowrap="nowrap" width="6%"></td>
                    </tr>
<?php
    $cur_fy = '01-04-'.date('Y');
 $next_fy ='31-03-'.(date('Y')+1);
 

$start    = new DateTime($cur_fy);
$start->modify('first day of this month');
$end      = new DateTime($next_fy);
$end->modify('first day of next month');
$interval = DateInterval::createFromDateString('1 month');
$period   = new DatePeriod($start, $interval, $end);
$cdamt=0;
foreach ($period as $dt) {
     $dateString= $dt->format("d-m-Y");
	$mn = explode('-',$dateString );
	 $lastDateOfMonth = date("t-m-Y", strtotime($dateString));
	$month_name = date('F', mktime(0, 0, 0, $mn[1], 1)).'<br>';

    $startdate=$dateString;
    $enddate=$lastDateOfMonth;
	
  $sdt = date('d-m-Y', strtotime("$startdate"));
  $s_date=$objIms->DateToInt($sdt);
  $edt = date('d-m-Y', strtotime("$enddate"));
  $end_date=$objIms->DateToInt($edt);
// captial amount from first investement
    $sql_sal_r = "SELECT sum(Dr_Amt) as  Dr_Amt FROM tbl_account where session_login_id = '".$_SESSION['login_id']."' and  sales_type='Sales Return' and trans_date>='$s_date' and trans_date<='$end_date'";
    $res_sal_r = mysql_query($sql_sal_r);
    $rowsal_r = mysql_fetch_assoc($res_sal_r);
    $cashsal_r = $rowsal_r["Dr_Amt"];
?>
                   
                <tr height="32">
                        <td nowrap="nowrap" width="6%"><?php echo $month_name; ?></td>
                        <td nowrap="nowrap" width="6%"></td>
                        <td nowrap="nowrap" width="6%"><?php echo $cashsal_r; ?></td>
                        <td nowrap="nowrap" width="6%"><?php echo $cashsal_r; ?></td>
                    </tr>

<?php
$cdamt+=$cashsal_r;
}
?>

</table>
<br /><br /><br /><br />
            <table class="table">
                    <tr height="32">
                        <td nowrap="nowrap" width="9%" style="font-weight: bold">Grand Total</td>
                        <td nowrap="nowrap" width="10%"></td>

                        <th nowrap="nowrap" width="1%"><?php echo $cdamt; ?></th>
                        <td nowrap="nowrap" width="6%"><?php echo round($cdamt); ?></td>
                    </tr>
                </table
                ></div>
</form>
<?php
 
$dataPoints = array(
    array("label"=> "Apr", "y"=> $cashsal_r),
    array("label"=> "May", "y"=> $cashsal_r1),
    array("label"=> "Jun", "y"=> $cashsal_r2),
    array("label"=> "Jul", "y"=> $cashsal_r3),
    array("label"=> "Aug", "y"=> $cashsal_r4),
    array("label"=> "Sep", "y"=> $cashsal_r5),
    array("label"=> "Oct", "y"=> $cashsal_r6),
    array("label"=> "Nov", "y"=> $cashsal_r7),
    array("label"=> "Dec ", "y"=> $cashsal_r8),
    array("label"=> "Jan", "y"=> $cashsal_r9),
    array("label"=> "Feb", "y"=> $cashsal_r10),
    array("label"=> "Mar", "y"=> $cashsal_r11)
);
    
?>

<!--<div id="chartContainer" style="height: 370px; width: 100%;"></div>-->


                                         </div>
                        </div>
                    </div>
                </div>
                <!-- End PAge Content -->
            </div>
            <!-- End Container fluid  -->
      </div>
      
 <?php include 'footer.php' ?>
 <script src="../js/lib/datatables/datatables.min.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/dataTables.buttons.min.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/buttons.flash.min.js"></script>
    <script src="../js/lib/datatables/cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
    <script src="../js/lib/datatables/cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script>
    <script src="../js/lib/datatables/cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/buttons.html5.min.js"></script>
    <script src="../js/lib/datatables/cdn.datatables.net/buttons/1.2.2/js/buttons.print.min.js"></script>
    <script src="../js/lib/datatables/datatables-init.js"></script>
    <script src="../js/canvasjs.min.js"></script>
<script>
window.onload = function () {
 
var chart = new CanvasJS.Chart("chartContainer", {
    animationEnabled: true,
    theme: "light2", // "light1", "light2", "dark1", "dark2"
    title: {
        text: "Total Months Summary Stocks"
    },
    axisY: {
        title: "Amount",
        includeZero: false
    },
    data: [{
        type: "column",
        dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
    }]
});
chart.render();
 
}
</script>