<?php include 'controller/pageCode.php' ?>
<!DOCTYPE html>
<html lang="en">
 <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<head>
    <meta charset="utf-8">
    <title>Income Summary</title>
    <?php include 'inc/meta_inc.php'; ?>
    <!-- base css -->
    <?php include 'inc/styles_inc.php'; ?>
    <link rel="stylesheet" media="screen, print" href="assets/css/markdown.css">
    <link rel="stylesheet" media="screen, print" href="assets/css/page-invoice.css">
    <link rel="stylesheet" media="screen, print" href="assets/css/formplugins/bootstrap-datepicker/bootstrap-datepicker.css">
</head>
    <body class="mod-bg-1 ">
        <!-- DOC: script to save and load page settings -->
        <?php include 'inc/theme_script_inc.php'; ?>
        <!-- BEGIN Page Wrapper -->
        <div class="page-wrapper" id="app">
            <div class="page-inner">
                <!-- BEGIN Left Aside -->
        <?php include 'inc/aside_inc.php'; ?>
<!-- END Left Aside -->
                <div class="page-content-wrapper">
                    <!-- BEGIN Page Header -->
        <?php include 'inc/header_inc.php'; ?>
<!-- END Page Header -->
                    <!-- BEGIN Page Content -->
                    <!-- the #js-page-content id is needed for some plugins to initialize -->
                    <main id="js-page-content" role="main" class="page-content">
                        <ol class="breadcrumb page-breadcrumb">
                            <li class="position-absolute pos-top pos-right d-none d-sm-block"><span class="js-get-date"></span></li>
                        </ol>
                        <div class="row d-print-none">
                            <div class="col-md-3"></div>
                            <div class="col-md-6">
                                <div class="form-group row">
                                    <label class="col-form-label col-12 col-lg-3 form-label text-lg-right">Range Picker</label>
                                    <div class="col-12 col-lg-12">
                                        <div class="input-daterange input-group" id="datepicker-5">
                                            <input type="text" class="form-control" value="<?php echo $frontend_start ?>" id="start">
                                            <div class="input-group-append input-group-prepend">
                                                <span class="input-group-text fs-xl"><i class="fal fa-ellipsis-h"></i></span>
                                            </div>
                                            <input type="text" class="form-control" value="<?php echo $frontend_end ?>" id="end">
                                            <button id="search" class="btn btn-info form-control">Search</button>
                                        </div>
                                    </div>
                                </div>
                                <hr>
                            </div>
                            <div class="col-md-3"></div>
                        </div>
                        <?php if($items_report_summary): ?>
                        <?php 
                        $total = 0;
                        $amount_paid = 0;
                        $profit = 0;
                        $wholesale = 0;
                        $tithe = 0;
                        // print_r($items_report_summary);
                        foreach($items_report_summary as $key){
                            $total = floatval($total)+floatval($key['amount']);
                            $amount_paid = $total;
                            $wholesale += 0;
                        }
                        $profit = $total-$wholesale;
                        $projected_tithe = $profit/10;
                        $actual_profit = $profit;
                        $tithe = $actual_profit/10;
                        $income_to_spend = $actual_profit-$tithe;
                                                    ?>
                        <div class="container">
                            <div data-size="A4">
                                <div class="row">
                                    <div class="col-sm-12">
                                        <div class="d-flex align-items-center mb-5">
                                        <h2 class="keep-print-font fw-500 mb-0 text-primary flex-1 position-relative">
                                                3f3 Training Academy
                                                <small class="text-muted mb-0 fs-xs">
                                                Kronum Kwapra Street,Kumasi, Ghana
                                                </small>
                                                
                                                <small class="text-muted mb-0 fs-xs">
                                                <b>Tel:</b> +233 (0) 559184881
                                                </small>
                                                <!-- barcode demo only -->
                                                <div  class="float-right">
                                                    <img src="assets/img/3f3logo.png" class="img img-responsive" alt="">
                                                </div>
                                            </h2>
                                        </div>
                                        <hr>
                                    </div>
                                   
                                </div>
                                <div class="row">
                                    <div class="col-sm-3"></div>
                                    <div class="col-sm-6">
                                    <center>
                                        <h3 class="fw-300 display-4 fw-500 color-primary-600 keep-print-font pt-4 l-h-n m-0">
                                            INCOME SUMMARY 
                                        </h3>
                                        <?php if($items_report_summary): ?>
                                                <h3 class="color-primary-600 keep-print-font"><?php  $newDate = strtotime($start); echo date('D M j, Y',$newDate) ?> TO <?php  $newDate = strtotime($end); echo date('D M j, Y',$newDate) ?></h3>
                                                <?php endif ?>
                                        </center>
                                        <center>
                                            <h3 class="fw-100 keep-print-font pt-4 l-h-n m-0">Expected Gross Income => Gh₵<?php echo number_format((float)$total, 2, '.', ''); ?></h3>
                                            <hr>
                                            <h3>Expected Profit => Gh₵<?php echo number_format((float)$profit, 2, '.', ''); ?></h3>
                                            <hr>
                                            <h3>Expected Tithe => Gh₵<?php echo number_format((float)$projected_tithe, 2, '.', ''); ?></h3>
                                            <hr>
                                            <h3>Actual Gross Income => Gh₵<?php echo number_format((float)$amount_paid, 2, '.', '');?></h3>
                                            <hr>
                                            <h3>Actual Profit => Gh₵<?php echo number_format((float)$actual_profit, 2, '.', ''); ?></h3>
                                            <hr>
                                            <h3>Actual Tithe => Gh₵<?php echo number_format((float)$tithe, 2, '.', ''); ?></h3>
                                            <hr>
                                            <h3>Remaining Balance => Gh₵<?php echo number_format((float)$income_to_spend, 2, '.', ''); ?></h3>
                                        </center>
                                    </div>
                                    <div class="col-sm-3"></div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <h4 class="py-5 text-primary">
                                        </h4>
                                        <p class="mt-2 text-muted mb-0">
                                            
                                        </p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php else: ?>
                        <div class="container">
                            <div data-size="A4">
                                <div class="row">
                                    <div class="col-sm-3"></div>
                                    <div class="col-sm-6">
                                    <center>
                                        <h3 class="fw-300 display-4 fw-500 color-primary-600 keep-print-font pt-4 l-h-n m-0">
                                            INCOME SUMMARY 
                                        </h3>
                                        <?php if($items_report_summary): ?>
                                        <small class="color-primary-600 keep-print-font"><?php  $newDate = strtotime($start); echo date('D,M j, Y',$newDate) ?> TO <?php  $newDate = strtotime($end); echo date('D,M j, Y',$newDate) ?></small>
                                        <?php endif ?>
                                    </center>
                                        <center>
                                            <h3 class="fw-100 keep-print-font pt-4 l-h-n m-0">No Records Found For This Period!</h3>
                                            
                                            
                                        </center>
                                    </div>
                                    <div class="col-sm-3"></div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <h4 class="py-5 text-primary">
                                        </h4>
                                        <p class="mt-2 text-muted mb-0">
                                            
                                        </p>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php endif ?>
                    <center><button id="print" class="btn btn-primary d-print-none">Print</button></center>
                    </main>
                    <!-- END Page Content -->
                    <!-- this overlay is activated only when mobile menu is triggered -->
<div class="page-content-overlay" data-action="toggle" data-class="mobile-nav-on"></div>
<!-- BEGIN Page Footer -->
<?php include 'inc/footer_inc.php' ?>
<!-- END Page Footer -->
<!-- BEGIN Shortcuts -->
<!-- modal shortcut -->
<?php //include 'inc/header_menu.php'; ?>
 <!-- END Shortcuts -->
                </div>
            </div>
        </div>
        
<!-- END Quick Menu -->
<!-- BEGIN Page Settings -->
 <!-- END Page Settings -->
<?php include 'inc/script_inc.php' ?>
        <script src="assets/js/datagrid/datatables/datatables.bundle.js"></script>
        <script src="assets/js/formplugins/bootstrap-datepicker/bootstrap-datepicker.js"></script>
        <script>
            var controls = {
            leftArrow: '<i class="fal fa-angle-left" style="font-size: 1.25rem"></i>',
            rightArrow: '<i class="fal fa-angle-right" style="font-size: 1.25rem"></i>'
            }

            var runDatePicker = function()
            {
                // range picker
                $('#datepicker-5').datepicker(
                {
                    todayHighlight: true,
                    clearBtn:true,
                    templates: controls
                });
            }
            $.fn.digits = function(){ 
                return this.each(function(){ 
                    $(this).text( $(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") ); 
                })
            }
            $(document).ready(function()
            {
                // Event Lot
                var events = $("#app-eventlog");
                runDatePicker();

                $('#print').click(function(){
                    window.print();
                })
                
                $('#search').on('click',function(){
                    start = $('#start').val();
                    end = $('#end').val();
                    window.location.replace("income_report_summary.php?summary=&&start="+start+"&&end="+end);
                });
                
            });
            
        </script>
<!-- Modal Large -->
    </body>

</html>
