<aside class="right-side">
    
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <!-- /.box -->
                
                <div class="box box-primary">
                    <?php if( !IS_KSK ) :
                        $basic = get_basic_setting();
                        $general = get_general_setting();
                        $design = get_design_setting();
                    ?>
                    <iframe name="report" id="report" src="#" style="display:none;"></iframe>
                    <!--<a class="print" style="float: right; cursor: pointer;"><img src="<?php echo base_url();?>assets/images/print.jpg" width="70px" height="35px;"/></a>-->
                    <div class="box-body table-responsive" style="clear:both;" id="print_data_container">
                        <div>
                            <table border="0" width="1000" style="border-collapse:collapse;">
                                <tr>
                                    <td width="15%">&nbsp;</td>
                                   
                                    <td width="20%" style="border-right:1px solid #FFF;">
                                        <?php  if ((!empty($design->logo)) && (file_exists(FCPATH . DIR_COMPANY_LOGO . $design->logo))) {
                                            $image_url = base_url() . DIR_COMPANY_LOGO . $design->logo;
                                            $alt = $basic->temple_name;
                                        }
                                        else {
                                            $image_url = base_url() . 'assets/images/logo.png';
                                            $alt = 'Logo not found!';
                                        } ?>
                                        <div style="font-size: 14px;">
                                            <div><span style="float:left;width:155px;height:75px; margin:2px;"><img src="<?php echo $image_url;?>" alt="<?php echo $alt;?>" width="155" height="75" /></span></div>
                                        </div>
                                    </td>
                                    <td width="40%" align="center">
                                        <span style="float:left;font-family:Arial, Helvetica, sans-serif;font-weight:bold; margin-bottom: 20px;"><span style="font-size:24px;" class="lang-tamil"><?php echo $basic->tamil_name;?></span><br/><span style="font-size:16px;"><?php echo $basic->temple_name;?></span><br/><br/><span style="font-size:14px;"><?php echo nl2br($basic->address);?></span><br/><span style="font-size:14px;">Tel: <?php echo $basic->contact_no;?>&nbsp; Fax: <?php echo $basic->fax;?></span> <br/><span style="font-size:14px;">Email: <?php echo $basic->comp_email;?></span><br/><span style="font-size:14px;"><?php echo $basic->website_url;?></span><br/></span>
                                    </td>
                                    <td width="15%">&nbsp;</td>
                                    <td width="10%">&nbsp;</td>
                                </tr>
                                <tr>
                                    <td colspan="5" align="center" style="font-size:16px; font-weight:bold;">Statistical Report</td>
                                
                                </tr>
                                <tr>
                                    <td colspan="2" align="center"><strong>Start Month & Year : <?php echo date('F Y',strtotime(('01-' . $start_month . '-' . $start_year)));?></strong></td>
                                    <td>&nbsp;</td>
                                    <td colspan="2" align="left"><strong>End Month & Year : <?php echo date('F Y',strtotime(('01-' . $end_month . '-' . $end_year)));?></strong></td>
                                </tr>
                            <?php else : ?>
                                <table border="0" width="1000" style="border-collapse:collapse;">
                                    <tr>
                                        <td align="left"><strong>Start Month & Year : <?php echo date('F Y',strtotime(('01-' . $start_month . '-' . $start_year )));?></strong></td>
                                        <td>&nbsp;</td>
                                        <td align="right"><strong>End Month & Year : <?php echo date('F Y',strtotime(('01-' . $end_month . '-' . $end_year )));?></strong></td>
                                    </tr>
                            <?php endif;?>
                            </table>
                            <br/>
                            <?php if($data_type == 'Print Summary Data') { ?>    
                                <table width="1000" border="1" cellpadding="3" cellspacing="0" style="font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; font-size:14px; width: 1000px; border-collapse:collapse;">
                                    <thead>
                                        <tr>
                                            <th style="padding:1%;">S.No</th>
                                            <th style="padding:1%;">Devotee Mobile</th>
                                            <th style="padding:1%;">Devotee Name</th>
                                            <?php $start_month2 = $start_month;
                                                for($m=$start_year; $m<=$end_year; $m++) {
                                                    for($om=$start_month2; $om<=12; $om++) {
                                                        if(($om > $end_month && $m == $end_year) || ($om < $start_month2 && $o == $start_year)) { 
                                                           continue; 
                                                        }
                                                        $start_month2 = ($om == 12) ? 1 : $start_month2;
                                                        $D = '01-'.$om .'-' . $m;?>
                                                        <th align="center" class="<?php echo str_replace(' ','_',date('F Y',strtotime($D)));?>"><?php echo date('F Y',strtotime($D));?></th>
                                              <?php }
                                                }
                                            ?>
                                            <th style="padding:1%;">Total</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $count = 4; if(count($results) > 0) { 
                                        
                                        foreach($results as $key=>$value) { $total_amt = 0; ?>
                                            <tr>
                                                <td style="padding:1%;"><?php echo ++$key;?></td>
                                                <td style="padding:1%;"><?php echo $value->bd_contact_no;?></td>
                                                <td style="padding:1%;"><?php echo $value->bd_name;?></td>
                                                <?php $start_month3 = $start_month;
                                                    for($m=$start_year; $m<=$end_year; $m++) {
                                                        for($om=$start_month3; $om<=12; $om++) {
                                                            if(($om > $end_month && $m == $end_year) || ($om < $start_month3 && $m == $start_year)) { 
                                                               continue; 
                                                            }
                                                            $start_month3 = ($om == 12) ? 1 : $start_month3;
                                                            $D = '01-'.$om .'-' . $m;
                                                            $mY = $om .'-' . $m;
                                                            $details = $this->statistical_report_model->get_monthwise_data($mY,$value->bd_contact_no,$top,1);
                                                            ?>
                                                            <td style="padding:1%;" align="right" class="<?php echo str_replace(' ','_',date('F Y',strtotime($D)));?>"><?php
                                                                $count += count($details);
                                                                if(count($details) > 0) { $month_amt = 0;
                                                                    foreach($details as $index=>$val) { 
                                                                        $total_amt +=$val->amount; 
                                                                        $month_amt +=$val->amount; 
                                                                    }
                                                                    echo number_format($month_amt,2,'.','');
                                                                } else {
                                                                    echo '0.00';
                                                                } ?>
                                                            </td>
                                                   <?php  }
                                                    }
                                                ?>
                                                <td align="right"><?php echo number_format($total_amt,2,'.','');?></td>
                                            </tr>
                                        <?php } } else {?>
                                            <tr colspan="<?php echo $count;?>"><center>No Records Found!</center></tr>
                                        <?php }?>
                                    </tbody>
                                </table>
                            <?php } elseif($data_type == 'Print Details Data'){ ?>
                                <table width="1000" border="1" cellpadding="3" cellspacing="0" style="font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; font-size:14px; width: 1000px; border-collapse:collapse;">
                                    <thead>
                                        <tr>
                                            <th style="padding:1%;">S.No</th>
                                            <th style="padding:1%;">Devotee Mobile</th>
                                            <th style="padding:1%;">Devotee Name</th>
                                            <?php $start_month4 = $start_month;
                                                for($m=$start_year; $m<=$end_year; $m++) {
                                                    for($om=$start_month4; $om<=12; $om++) {
                                                        if(($om > $end_month && $m == $end_year) || ($om < $start_month4 && $o == $start_year)) { 
                                                           continue; 
                                                        }
                                                        $start_month4 = ($om == 12) ? 1 : $start_month4;
                                                        $D = '01-'.$om .'-' . $m;?>
                                                        <th align="center" class="<?php echo str_replace(' ','_',date('F Y',strtotime($D)));?>"><?php echo date('F Y',strtotime($D));?></th>
                                              <?php }
                                                }
                                            ?>
                                            <th style="padding:1%;">Total</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $start_month5 = $start_month; 
                                        foreach($results as $key=>$value) { 
                                            $total_amt = 0; 
                                            $statistical_data = array(); 
                                            $value->count_str = FALSE;
                                            for($m=$start_year; $m<=$end_year; $m++) {
                                                for($om=$start_month5; $om<=12; $om++) {
                                                    if(($om > $end_month && $m == $end_year) || ($om < $start_month5 && $m == $start_year)) { 
                                                       continue;
                                                    }                                            
                                                    $start_month5 = ($om == 12) ? 1 : $start_month5;
                                                    $mY = $om .'-' . $m;
                                                    $details_data = $this->statistical_report_model->get_monthwise_data($mY,$value->bd_contact_no,$top,2);
                                                    array_push($statistical_data, $details_data);
                                                    if(count($details_data) > 0) {
                                                        $value->count_str = TRUE;
                                                    }
                                                } 
                                            }
                                        ?>
                                            <tr>
                                                <td style="padding:1%;"><?php echo ++$key;?></td>
                                                <td style="padding:1%;"><?php echo $value->bd_contact_no;?></td>
                                                <td style="padding:1%;"><?php echo $value->bd_name;?></td>
                                                <?php $start_month6 = $start_month;
                                                    for($m=$start_year; $m<=$end_year; $m++) {
                                                        for($om=$start_month6; $om<=12; $om++) {
                                                            if(($om > $end_month && $m == $end_year) || ($om < $start_month6 && $m == $start_year)) { 
                                                               continue; 
                                                            }
                                                            $start_month6 = ($om == 12) ? 1 : $start_month6;
                                                            $D = '01-'.$om .'-' . $m;
                                                            $mY = $om .'-' . $m;
                                                            $details = $this->statistical_report_model->get_monthwise_data($mY,$value->bd_contact_no,$top,1);
                                                            ?>
                                                            <td style="padding:1%;" align="right" class="<?php echo str_replace(' ','_',date('F Y',strtotime($D)));?>"><?php
                                                                $count += count($details);
                                                                if(count($details) > 0) { $month_amt = 0;
                                                                    foreach($details as $index=>$val) { 
                                                                        $total_amt +=$val->amount; 
                                                                        $month_amt +=$val->amount; 
                                                                    }
                                                                    echo number_format($month_amt,2,'.','');
                                                                } else {
                                                                    echo '0.00';
                                                                } ?>
                                                            </td>
                                                   <?php  }
                                                    }
                                                ?>
                                                <td align="right"><?php echo number_format($total_amt,2,'.','');?></td>
                                            </tr>
                                         
                                            <?php if($value->count_str) { ?>        
                                                <tr class="remove_container">
                                                    <td colspan="6" class="expand_container">
                                                        <div class="tbl-expand" style="color:#0B45B3;">
                                                            <table width="970" border="1" cellpadding="3" cellspacing="0" style="font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; font-size:14px; width: 970px; margin: 1.3%; border-collapse:collapse;" class="filterTable tableFilter2">
                                                               <!--<thead>-->
                                                                    <tr>
                                                                        <th width="10%" align="center" style="padding:1%;" >S.No</th>
                                                                        <th align="center" style="padding:0.8%;">Date</th>
                                                                        <th align="center" style="padding:0.8%;">Type</th>
                                                                        <th align="center" style="padding:0.8%;">Amount</th>
                                                                    </tr>
                                                                <!--</thead>-->
                                                                <tbody>
                                                                    <?php foreach($statistical_data as $k=>$val) { 
                                                                        foreach($val as $index=>$row) { ?>
                                                                            <tr class="subTable">
                                                                                <td style="padding:0.8%;"><?php echo ++$index;?></td>
                                                                                <td style="padding:0.8%;"><?php echo $row->date_str;?></td>
                                                                                <td style="padding:0.8%;"><?php echo $row->service_name;?></td>
                                                                                <td align="right" style="padding:0.8%;"><?php echo $row->amount;?></td>
                                                                            </tr>
                                                                    <?php } } ?>
                                                                </tbody>
                                                            </table>
                                                        </div>
                                                    </td>
                                                </tr>
                                            <?php } ?>
                                        <?php } } else {?>
                                            <tr colspan="<?php echo $count;?>"><center>No Records Found!</center></tr>
                                        <?php }?>
                                    </tbody>
                                </table>
                            <? } ?>
                        </div>
                    </div>
                
                    
                </div><!-- /.box -->
            </div>
        </div>
    </section><!-- /.content -->
</aside><!-- /.right-side -->
<!-- ./wrapper -->
<?php if( !IS_KSK ) : ?>
<script type="text/javascript">
    window.onload = function() {
        print_layout();
    } 
    
    $(document).ready(function(){
        $('.print').click(function(){
            print_layout();
        });
    });
    
    function print_layout() {
        var body = $('#print_data_container').html();
        var newWin = document.getElementById('report').contentWindow;
        newWin.document.write(body);
        newWin.document.close(); //important!
        newWin.focus(); //IE fix
        newWin.print();
        window.location.href = '<?php echo base_url();?>statistical_report';
    }
</script>
<?php endif;