<style>
table, th, td {
 
  border-collapse: collapse;
}
th, td {
  padding: 15px;
}
</style>

<div class="wrapper">
    <div class="container">
        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">
                <div class="pull-right m-t-15">                    
                    <form method="Post" action="<?php echo base_url()."account_reports";?>">
                        <div id="reportrange" name="reportrange" class="form-control" style="display:inline">
                           <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
                           <span></span>
                        </div>
                        <input type="hidden" name="startdate" id="startdate" value="<?php echo $startdate;?>"><input type="hidden" name="enddate" id="enddate" value="<?php echo $enddate;?>">
                        <button type="submit" class="btn btn-sm btn-pink btn-bordred waves-effect w-md waves-light m-l-5">Run</button>   
                    </form>
                </div>
                <h4 class="page-title">Accounting Module Reports - (<?php echo $business[0]['business_name'];?>):</h4>
            </div>
        </div>
        
        <div class="row">
             <div class="col-md-4">
                <div class="card-box">
                    <div class="row">
                        <div class="col-md-12">
                            <h4 class="card-title">
                                Taxed Invoices Recorded Revenue:
                            <h4>
                        </div>
                    </div>
                    <table>
                        <thead>
                            <tr>
                                <th></th>
                                <th style="text-align: right;">
                                    Revenue Recorded
                                </th>
                                <th style="text-align: right;">
                                    Sale Discount:
                                </th>
                                <th style="text-align: right;">
                                    Sales Tax Payable:
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            
                            <?php if(isset($servicetaxcal )){if(sizeof($servicetaxcal)>0){
                            foreach($servicetaxcal as $item){?>
                            <tr>
                                <td>Taxed Service Invoices:</td>
                                <td style="text-align: right;">
                                    <?php echo number_format($item['Total']);?>
                                </td>
                                <td style="text-align: right;">
                                    <?php echo number_format($item['Discount']);?>
                                </td>
                                <td style="text-align: right;">
                                    <?php echo number_format($item['SalesTax']);?>
                                </td>
                            </tr>
                            
                            <?php }}} ?>
                            <?php if(isset($retailtaxcal )){if(sizeof($retailtaxcal)>0){
                            foreach($retailtaxcal as $item){?>
                            <tr>
                                <td>Taxed Retail Invoices:</td>
                                <td style="text-align: right;">
                                    <?php echo number_format($item['Total']);?>
                                </td>
                                <td style="text-align: right;">
                                    <?php echo number_format($item['Discount']);?>
                                </td>
                                <td style="text-align: right;">
                                    <?php echo number_format($item['SalesTax']);?>
                                </td>
                            </tr>
                            
                             <?php }}} ?>
                            <?php if(isset($trainingtaxcal )){if(sizeof($trainingtaxcal)>0){
                                foreach($trainingtaxcal as $item){?>
                            <tr>
                                <td>Taxed Training Program Invoices:</td>
                                <td style="text-align: right;">
                                    <?php echo number_format($item['Total']);?>
                                </td>
                                <td></td>
                                <td style="text-align: right;">
                                    <?php echo number_format($item['SalesTax']);?>
                                </td>
                            </tr>
                            
                            <?php }}} ?>
                            <?php if(isset($franchisetaxcal )){if(sizeof($franchisetaxcal)>0){
                            foreach($franchisetaxcal as $item){?>
                            <tr>
                                <td>Taxed Franchise Invoices:</td>
                                <td style="text-align: right;">
                                    <?php echo number_format($item['Total']);?>
                                </td>
                                <td></td>
                                <td style="text-align: right;">
                                    <?php echo number_format($item['SalesTax']);?>
                                </td>
                            </tr>
                            
                            <?php }}} ?>
                        <tbody>
                    </table>
                </div>
            </div>
            <div class="col-sm-4">
                <div class="card-box ">
                    <div class="row">
                        <div class="col-md-12">
                            <h4 class="card-title">Over All Collection</h4>
                        </div>
                    </div>
                    <table class="table " width="100%" >
                        <thead>
                            <th style="width: 75%">Item</th>
                            <th style="text-align: right;">Debit</th>
                        </thead>
                        <tbody>
                            
                            <tr><td colspan="2"><h4>From Services</h4></td></tr>    
                                <?php $totalservice=0;  foreach($account_details as $index => $account){ ?>   
                                    <?php if($index == 'paid_cashservice'){ ?>
                                    <tr>
                                        <td><?php if(strpos($account['account_head'], 'Cash') !==false){echo "<i class='fa fa-money text-success m-r-10'></i> "; }  echo $account['account_head'];?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['debit'],2);  $totalservice=$totalservice+$account['debit'];?></td>
                                    </tr>
                                   <?php } ?>
                                    <?php if($index == 'paid_cardservice'){ ?>
                                    <tr>
                                        <td><?php if(strpos($account['account_head'], 'Card') !==false){echo "<i class='fa fa-credit-card text-warning m-r-10'></i> "; }  echo $account['account_head']; ?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['debit'],2); $totalservice=$totalservice+$account['debit']; ?></td>
                                    </tr>
                                   <?php } ?>
                                    <?php if($index == 'paid_checkservice'){ ?>
                                    <tr>
                                        <td><?php if(strpos($account['account_head'], 'Check') !==false){echo "<i class='fa fa-pencil-square-o text-primary m-r-10'></i> "; }  echo $account['account_head']; ?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['debit'],2);  $totalservice=$totalservice+$account['debit'];?></td>
                                    </tr>
                                   <?php } ?>
                                <?php } ?>
                                <tr><td style="text-align: right; font-weight: bold;">Total:</td><td style="text-align: right; font-weight: bold;"><?php echo number_format($totalservice,2);?></td></tr>
                                
                                <tr><td colspan="4"><h4>From Retail</h4></td></tr>
                                <?php  $totalretail =0;  foreach($account_details as $index => $account){?>
                                    <?php if($index == 'paid_cashsale'){ ?>
                                    <tr>
                                        <td ><?php if(strpos($account['account_head'], 'Cash') !==false){echo "<i class='fa fa-money text-success m-r-10'></i> "; } echo $account['account_head']; ?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['debit'],2);  $totalretail=$totalretail+$account['debit'];?></td>
                                    </tr>
                                    <?php } ?>
                                    <?php if($index == 'paid_cardsale'){ ?>
                                    <tr>
                                        <td ><?php if(strpos($account['account_head'], 'Card') !==false){echo "<i class='fa fa-credit-card text-warning m-r-10'></i> "; }  echo $account['account_head']; ?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['debit'],2);  $totalretail=$totalretail+$account['debit'];?></td>
                                    </tr>
                                    <?php } ?>
                                    <?php if($index == 'paid_checksale'){ ?>
                                    <tr>
                                        <td ><?php if(strpos($account['account_head'], 'Card') !==false){echo "<i class='fa fa-pencil-square-o text-primary m-r-10'></i> "; } echo $account['account_head']; ?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['debit'],2);  $totalretail=$totalretail+$account['debit'];?></td>
                                    </tr>
                                   <?php } ?>
                                    
                                <?php } ?>   
                                <tr><td style="text-align: right; font-weight: bold;">Total:</td><td style="text-align: right; font-weight: bold;"><?php echo number_format($totalretail,2);?></td></tr>
                                
                                <tr><td colspan="4"><h4>User Posted Sale BreakUp</h4></td></tr>
                                <?php  $totaluser =0;  foreach($account_details as $index => $account){?>
                                    <?php if($index == 'paid_cash'){ ?>
                                    <tr>
                                        <td ><?php if(strpos($account['account_head'], 'Cash') !==false){echo "<i class='fa fa-money text-success m-r-10'></i> "; } echo $account['account_head']; ?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['debit'],2);  $totaluser=$totaluser+$account['debit'];?></td>
                                    </tr>
                                    <?php } ?>
                                    <?php if($index == 'paid_card'){ ?>
                                    <tr>
                                        <td ><?php if(strpos($account['account_head'], 'Card') !==false){echo "<i class='fa fa-credit-card text-warning m-r-10'></i> "; }  echo $account['account_head']; ?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['debit'],2);  $totaluser=$totaluser+$account['debit'];?></td>
                                    </tr>
                                    <?php } ?>
                                    <?php if($index == 'paid_check'){ ?>
                                    <tr>
                                        <td ><?php if(strpos($account['account_head'], 'Card') !==false){echo "<i class='fa fa-pencil-square-o text-primary m-r-10'></i> "; } echo $account['account_head']; ?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['debit'],2);  $totaluser=$totaluser+$account['debit'];?></td>
                                    </tr>
                                   <?php } ?>
                                    
                                <?php } ?>   
                                <tr><td style="text-align: right; font-weight: bold;">Total:</td><td style="text-align: right; font-weight: bold;"><?php echo number_format($totaluser,2);?></td></tr>
                                
                                <!--Totals-->
                                <tr ><td style="border-top:1px solid #808080;"><h4>Total Sale From <?php echo date_format(date_create($startdate),'d-m-Y')." To ".date_format(date_create($enddate),'d-m-Y').":";?></h4></td><td style="text-align: right; border-top:1px solid #808080;"><h4><?php echo number_format($totalretail+$totalservice+$totaluser,2);?></h4></td></tr>
                        </tbody>
                    </table>
                </div>
            </div>
            
            
             <div class="col-sm-4">
                <div class="card-box ">
                    <div class="row">
                        <div class="col-md-12">
                            <h4 class="card-title">Payable</h4>
                        </div>
                    </div>
                    <table class="table " width="100%" >
                        <thead>
                            <th style="width: 75%">Item</th>
                            <th style="text-align: right;">Debit</th>
                        </thead>
                        <tbody>
                            
                            <tr><td colspan="2"><h4>For Services Invoices</h4></td></tr>    
                                <?php $totalservice=0;  foreach($account_details as $index => $account){ ?>   
                                    <?php if($index == 'grosstotal_serviceservice'){ ?>
                                    <tr>
                                        <td><?php if(strpos($account['account_head'], 'Income') !==false){echo "<i class='fa fa-money text-success m-r-10'></i> "; }  echo $account['account_head'];?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['credit'],2);  $totalservice=$totalservice+$account['credit'];?></td>
                                    </tr>
                                   <?php } ?>
                                    <?php if($index == 'cc_feeservice'){ ?>
                                    <tr>
                                        <td><?php if(strpos($account['account_head'], 'Fee') !==false){echo "<i class='fa fa-money text-success m-r-10'></i> "; }  echo $account['account_head'];?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['credit'],2);  $totalservice=$totalservice+$account['credit'];?></td>
                                    </tr>
                                   <?php } ?>
                                    <?php if($index == 'cc_tipservice'){ ?>
                                    <tr>
                                        <td><?php if(strpos($account['account_head'], 'Tip') !==false){echo "<i class='fa fa-credit-card text-warning m-r-10'></i> "; }  echo $account['account_head']; ?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['credit'],2); $totalservice=$totalservice+$account['credit']; ?></td>
                                    </tr>
                                   <?php } ?>
                                    <?php if($index == 'sales_taxservice'){ ?>
                                    <tr>
                                        <td><?php if(strpos($account['account_head'], 'Tax') !==false){echo "<i class='fa fa-pencil-square-o text-primary m-r-10'></i> "; }  echo $account['account_head']; ?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['credit'],2);  $totalservice=$totalservice+$account['credit'];?></td>
                                    </tr>
                                   <?php } ?>
                                <?php } ?>
                                <tr><td style="text-align: right; font-weight: bold;">Total:</td><td style="text-align: right; font-weight: bold;"><?php echo number_format($totalservice,2);?></td></tr>
                                
                                <tr><td colspan="4"><h4>For Retail Invoices</h4></td></tr>
                                <?php  $totalretail =0;  foreach($account_details as $index => $account){?>
                                    <?php if($index == 'grosstotal_retailsale'){ ?>
                                    <tr>
                                        <td><?php if(strpos($account['account_head'], 'Income') !==false){echo "<i class='fa fa-money text-success m-r-10'></i> "; }  echo $account['account_head'];?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['credit'],2);  $totalretail=$totalretail+$account['credit'];?></td>
                                    </tr>
                                   <?php } ?>
                                    <?php if($index == 'cc_feesale'){ ?>
                                    <tr>
                                        <td ><?php if(strpos($account['account_head'], 'Cash') !==false){echo "<i class='fa fa-money text-success m-r-10'></i> "; } echo $account['account_head']; ?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['credit'],2);  $totalretail=$totalretail+$account['credit'];?></td>
                                    </tr>
                                    <?php } ?>
                                    <?php if($index == 'cc_tipsale'){ ?>
                                    <tr>
                                        <td ><?php if(strpos($account['account_head'], 'Card') !==false){echo "<i class='fa fa-credit-card text-warning m-r-10'></i> "; }  echo $account['account_head']; ?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['credit'],2);  $totalretail=$totalretail+$account['credit'];?></td>
                                    </tr>
                                    <?php } ?>
                                    <?php if($index == 'sales_taxsale'){ ?>
                                    <tr>
                                        <td ><?php if(strpos($account['account_head'], 'Card') !==false){echo "<i class='fa fa-pencil-square-o text-primary m-r-10'></i> "; } echo $account['account_head']; ?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['credit'],2);  $totalretail=$totalretail+$account['credit'];?></td>
                                    </tr>
                                   <?php } ?>
                                    
                                <?php } ?>   
                                <tr><td style="text-align: right; font-weight: bold;">Total:</td><td style="text-align: right; font-weight: bold;"><?php echo number_format($totalretail,2);?></td></tr>
                                
                                <tr><td colspan="4"><h4>User Posted Sale BreakUp</h4></td></tr>
                                <?php  $totaluser =0;  foreach($account_details as $index => $account){?>
                                    <?php if($index == 'grosstotal_service'){ ?>
                                    <tr>
                                        <td><?php if(strpos($account['account_head'], 'Income') !==false){echo "<i class='fa fa-money text-success m-r-10'></i> "; }  echo $account['account_head'];?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['credit'],2);  $totaluser=$totaluser+$account['credit'];?></td>
                                    </tr>
                                   <?php } ?>
                                    <?php if($index == 'cc_fee'){ ?>
                                    <tr>
                                        <td ><?php if(strpos($account['account_head'], 'Cash') !==false){echo "<i class='fa fa-money text-success m-r-10'></i> "; } echo $account['account_head']; ?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['credit'],2);  $totaluser=$totaluser+$account['credit'];?></td>
                                    </tr>
                                    <?php } ?>
                                    <?php if($index == 'cc_tip'){ ?>
                                    <tr>
                                        <td ><?php if(strpos($account['account_head'], 'Card') !==false){echo "<i class='fa fa-credit-card text-warning m-r-10'></i> "; }  echo $account['account_head']; ?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['credit'],2);  $totaluser=$totaluser+$account['credit'];?></td>
                                    </tr>
                                    <?php } ?>
                                    <?php if($index == 'sales_tax'){ ?>
                                    <tr>
                                        <td ><?php if(strpos($account['account_head'], 'Card') !==false){echo "<i class='fa fa-pencil-square-o text-primary m-r-10'></i> "; } echo $account['account_head']; ?></td>                            
                                        <td style="text-align: right;"><?php echo number_format($account['credit'],2);  $totaluser=$totaluser+$account['credit'];?></td>
                                    </tr>
                                   <?php } ?>
                                    
                                <?php } ?>   
                                <tr><td style="text-align: right; font-weight: bold;">Total:</td><td style="text-align: right; font-weight: bold;"><?php echo number_format($totaluser,2);?></td></tr>
                                
                                <tr ><td style="border-top:1px solid #808080;"><h4>Total Sale From <?php echo date_format(date_create($startdate),'d-m-Y')." To ".date_format(date_create($enddate),'d-m-Y').":";?></h4></td><td style="text-align: right; border-top:1px solid #808080;"><h4><?php echo number_format($totalretail+$totalservice+$totaluser,2);?></h4></td></tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="row">
           
        </div>
        
        <script>
   
   
     
    $(document).ready(function() {
         
        var startdate = '<?php echo date('F j, Y', strtotime($startdate)); //->format('F j, Y');    ?>';
        var enddate = '<?php echo date('F j, Y', strtotime($enddate)); //->format('F j, Y');    ?>';
        $('#reportrange span').html(startdate + ' - ' + enddate);
        
        $('#reportrange').daterangepicker({
            format: 'MM/DD/YYYY',
            startDate: moment().subtract(15, 'days'),
            endDate: moment(),
            minDate: '01/01/2012',
            maxDate: '12/31/2090',
//                    dateLimit: {
//                        days: 60
//                    },
            showDropdowns: true,
            showWeekNumbers: true,
            timePicker: false,
            timePickerIncrement: 1,
            timePicker12Hour: true,
            ranges: {
                'Today': [moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment().add(1, 'days')],
                'Last 30 Days': [moment().subtract(29, 'days'), moment().add(1, 'days')],
                'This Month': [moment().startOf('month'), moment().endOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
            },
            opens: 'left',
            drops: 'down',
            buttonClasses: ['btn', 'btn-sm'],
            applyClass: 'btn-success',
            cancelClass: 'btn-default',
            separator: ' to ',
            locale: {
                applyLabel: 'Submit',
                cancelLabel: 'Cancel',
                fromLabel: 'From',
                toLabel: 'To',
                customRangeLabel: 'Custom',
                daysOfWeek: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
                monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
                firstDay: 1
            }
        }, function(start, end, label) {
            //console.log(start.toISOString(), end.toISOString(), label);
            startdate = start;
            enddate = end;
            $("#startdate").val(startdate.format('YYYY-MM-DD'));
            $("#enddate").val(enddate.format('YYYY-MM-DD'));
            $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
        });
        
       
    });
    
    
    </script>