<!-- begin:: Subheader -->
<div class="kt-subheader   kt-grid__item" id="kt_subheader">
<div class="kt-container  kt-container--fluid ">
    <div class="kt-subheader__main">
        <div class="kt-subheader__breadcrumbs">
            <a class="kt-subheader__breadcrumbs-link">
                Reports </a>
            <span class="kt-subheader__breadcrumbs-separator"></span>
            <a  class="kt-subheader__breadcrumbs-link">
                All Sales Reports </a>
            <span class="kt-subheader__breadcrumbs-separator"></span>
            
        </div>
    </div>
    <div class="kt-subheader__toolbar">        
         <a href="<?=base_url();?>reports/export_center_report?center_name=0&year=<?=(isset($_GET['year']) && $_GET['year'] !=''? $_GET['year']:CURRENT_SESSION);?>" class="btn btn-label-brand btn-bold">
            <i class="flaticon-download"></i> Export to Excel</a>
    </div>                                        
</div>
</div>
<!-- end:: Subheader -->
<!-- begin:: Content -->
<div class="kt-container  kt-container--fluid  kt-grid__item kt-grid__item--fluid">
   <div class="kt-portlet">
      <div class="kt-portlet__body kt-portlet__body--fit">
       <div class="kt-portlet__body">
            <form name="filter" method="get">          
                <div class="row justify-content-between">                
                    <div class="col-sm-3" style="margin-bottom: 10px;">
                        <input type="text" name="cdate_from" class="form-control" placeholder="Sales Date From" aria-controls="kt_table_1" id="datepicker" value="<?=(isset($_GET['cdate_from']) && $_GET['cdate_from']!='' ? $_GET['cdate_from']:'');?>"autocomplete="off" >
                    </div>
                    <div class="col-sm-3" style="margin-bottom: 10px;">
                        <input type="text" name="cdate_to" class="form-control" placeholder="Sales Date To" aria-controls="kt_table_1" id="datepicker1" value="<?=(isset($_GET['cdate_to']) && $_GET['cdate_to']!='' ? $_GET['cdate_to']:'');?>" autocomplete="off">
                    </div>
                    <div class="col-sm-3" style="margin-bottom: 10px;">
                        <select name="page" aria-controls="kt_table_1" class="custom-select form-control form-control-sm">
                            <option value="">Show Entries</option>
                            <option value="10" <?=(isset($_GET['page']) && $_GET['page']=='30' ?'selected':'');?>>30</option>
                            <option value="25" <?=(isset($_GET['page']) && $_GET['page']=='60' ?'selected':'');?>>60</option>
                            <option value="50" <?=(isset($_GET['page']) && $_GET['page']=='90' ?'selected':'');?>>90</option>
                        </select>
                    </div>
                    <div class="col-sm-3" style="margin-bottom: 10px;">
                        <button type="submit" class="btn btn-info" style="width: 100%;">Apply</button>
                    </div>
                </div>
            </form>
            <div class="row">
                <div class="col-sm-12 table-scrollable">
                    <!--begin: Datatable -->
                    <table class="table table-striped- table-bordered table-hover table-checkable" id="kt_table_1">
                        <thead>
                            <tr>                                           
                                <th> Sales Date </th>
                                <th> Owner Name </th>   
                                <th> Total Lead </th>
                                <?php $lead_source = get_lead_source_list();?>  
                                <?php foreach($lead_source as $value){ ?>
                                    <th> <?=$value['name'];?> </th>
                                <?php } ?>  
                                <?php foreach(UNIVERSITY as $value) { ?>                                                   
                                <th> <?=$value; ?> </th>
                                <?php } ?>                                  
                            </tr>
                        </thead>
                        <tbody>
                        <?php
                            foreach ($report_data as $key=>$value){
                            if(empty($value) ===FALSE){
                                foreach($value as $user_id=>$report){
                                    $lsource = array_count_values(array_column($report, 'lead_source'));
                                    $university = array_count_values(array_column($report, 'university'));
                                ?>
                                    <tr>                        
                                        <td><?=$key;?></td>
                                        <td><?php $center_details    = get_center_by_id($user_id); ?>
                                            <?=ucfirst($center_details[0]['user_name'] ?? '');?>
                                        </td>
                                        <td><?=count($report);?></td>
                                       <?php foreach($lead_source as $value){ ?>
                                        <td> <?=(isset($lsource[$value['name']]) && $lsource[$value['name']]!='')?$lsource[$value['name']]:'';?></th>
                                        <?php } ?> 
                                        <?php foreach(UNIVERSITY as $value) { ?>                             
                                            <td> <?=(isset($university[$value]) && $university[$value]!='')?$university[$value]:'';?></th>
                                       <?php } ?>                
                                    </tr>
                            <?php  }}} ?>                                        
                        </tbody>
                    </table>
                </div>
            </div>

            <!--end: Datatable -->
        </div>
      </div>
   </div>
</div>
