<style type="text/css">
    @media print {
        #dynamic-content-container{background: #fff;}
        .navbar-default.navbar-static-side{display: none !important;}
        #page-wrapper{margin: 0px !important; padding: 0 !important;}
        .row.border-bottom{display: none !important;}
        .footer.fixed{display: none;}
        .ibox-content{padding: 0 !important;}
        body {
        -webkit-print-color-adjust:exact;
        background: #fff;
        }
        .print-hide{display: none !important;}
        .print-show{display: flex !important;}
    }
    
</style>
<div class="row wrapper border-bottom white-bg page-heading print-hide">
    <div class="col-lg-10">
        <h2><?= print_lang($app_lang,'marketers_ins_rep_view_breadcrumb'); ?></h2>
        <ol class="breadcrumb">
            <li>
                <a class="url-elem" href="<?php echo url('/dashboard'); ?>"><?= print_lang($app_lang,'home'); ?></a>
            </li>
            <li>
                <a class="url-elem" href="<?php echo url('/reports'); ?>"><?= print_lang($app_lang,'reports'); ?></a>
            </li>
            <li class="active">
                <strong><?= print_lang($app_lang,'marketers_ins_rep_view_breadcrumb'); ?></strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2">
        
    </div>
</div>


<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">

                    <h2 class="text-center font-bold" style="margin: 10px 0 20px;"><?= print_lang($app_lang,'marketers_ins_rep_title'); ?></h2>
                    
                    <form id="marketers-income-statement-search-form" class="print-hide" action="<?= url('/marketers-income-statement'); ?>">
                    <div class="row">
                        <div class="col-md-9">
                            <div class="row">
                                <div class="col-md-2" style="padding: 2px;">
                                    <div class="form-group">
                                        <label><?= print_lang($app_lang,'select_currency'); ?></label>
                                        <select class="form-control chosen-select" name="currency">
                                            <option value="" selected="">-- <?= print_lang($app_lang,'select_currency'); ?> --</option>
                                            <?php foreach($currencies as $row){ ?>
                                                <option value="<?= $row['uid']; ?>" <?php if($search_currency == $row['uid']){ echo 'selected="selected"'; } ?>><?= $row['name']; ?> (<?= $row['symbol']; ?>)</option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>

                                <div class="col-md-2" style="padding: 2px;">
                                    <div class="form-group">
                                        <label><?= print_lang($app_lang,'convert_currency'); ?></label>
                                        <select class="form-control chosen-select" name="convert_currency">
                                            <option value="" selected="">-- <?= print_lang($app_lang,'convert_currency'); ?> --</option>
                                            <?php foreach($currencies as $row){ ?>
                                                <option value="<?= $row['uid']; ?>" <?php if($search_convert_currency == $row['uid']){ echo 'selected="selected"'; } ?>><?= $row['name']; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>

                                <div class="col-md-2" style="padding: 2px;">
                                    <div class="form-group">
                                        <label><?= print_lang($app_lang,'marketer'); ?></label>
                                        <select class="form-control chosen-select" name="marketer">
                                            <option value="" selected="">-- <?= print_lang($app_lang,'marketer'); ?> --</option>
                                            <?php foreach($marketers as $row){ ?>
                                                <option value="<?= $row['uid']; ?>" <?php if($search_marketer == $row['uid']){ echo 'selected="selected"'; } ?>><?= $row['name']." ".$row['last_name']; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>

                                <div class="col-md-2" style="padding: 2px;">
                                    <div class="form-group">
                                        <label><?= print_lang($app_lang,'expense'); ?></label>
                                        <select class="form-control chosen-select" name="expense">
                                            <option value="" selected="">-- <?= print_lang($app_lang,'expense'); ?> --</option>
                                            <?php foreach($expenses as $row){ ?>
                                                <option value="<?= $row['uid']; ?>" <?php if($search_expense == $row['uid']){ echo 'selected="selected"'; } ?>><?= $row['name']; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>

                                <div class="col-md-2" style="padding: 2px;">
                                    <div class="form-group">
                                        <label><?= print_lang($app_lang,'from'); ?></label>
                                        <?php if($branch_calander == 'persian'){ ?>
                                            <input type="text" class="form-control persian-date" value="<?= $search_from; ?>" name="from" placeholder="<?= print_lang($app_lang,'from'); ?>" readonly="" style="background: #fff;">
                                        <?php }else{ ?>
                                            <input type="date" class="form-control" name="from" value="<?= $search_from; ?>">
                                        <?php } ?>
                                    </div>
                                </div>
                                <div class="col-md-2" style="padding: 2px;">
                                    <div class="form-group">
                                        <label><?= print_lang($app_lang,'to'); ?></label>
                                        <?php if($branch_calander == 'persian'){ ?>
                                            <input type="text" class="form-control persian-date" value="<?= $search_to; ?>" name="to" placeholder="<?= print_lang($app_lang,'to'); ?>" readonly="" style="background: #fff;">
                                        <?php }else{ ?>
                                            <input type="date" class="form-control" name="to" value="<?= $search_to; ?>">
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-2 text-right" style="margin-top: 23px;">
                            <button class="btn btn-w-m btn-primary custom-font-btn-search" type="submit"><?= print_lang($app_lang,'search'); ?></button>
                        </div>
                        <div class="col-md-1 text-right" style="margin-top: 23px;">
                            <a href="javascript:void(0)" onclick="window.print()" class="btn btn-outline btn-primary dim"><i class="fa fa-print"></i></a>
                        </div>
                    </div>
                    </form>
                    <hr class="print-hide">

                    <table class="table table-bordered" cellspacing="0" style="width: 100%; margin: 0;">
                        <tr>
                            <td style="width: 65%;">
                                <table class="table table-bordered">
                                    <thead>
                                        <tr>
                                            <th style="text-align: center; background: #F5F5F6 !important;" colspan="7"><h3><?= print_lang($app_lang,'marketers_ins_rep_title_incomes'); ?></h3></th>
                                        </tr>
                                        <tr class="text-center">
                                            <th style="text-align: center;  background: #F5F5F6 !important;"><?= print_lang($app_lang,'marketers_ins_rep_thead_inc_date'); ?></th>
                                            <th style="text-align: center;  background: #F5F5F6 !important;"><?= print_lang($app_lang,'marketers_ins_rep_thead_inc_invoice'); ?></th>
                                            <th style="text-align: center;  background: #F5F5F6 !important;"><?= print_lang($app_lang,'marketers_ins_rep_thead_inc_income'); ?></th>
                                            <th style="text-align: center;  background: #F5F5F6 !important;"><?= print_lang($app_lang,'marketers_ins_rep_thead_inc_paid'); ?></th>
                                            <th style="text-align: center;  background: #F5F5F6 !important;"><?= print_lang($app_lang,'marketers_ins_rep_thead_inc_pending'); ?></th>
                                            <th style="text-align: center;  background: #F5F5F6 !important;"><?= print_lang($app_lang,'marketers_ins_rep_thead_inc_account'); ?></th>
                                            <th style="text-align: center;  background: #F5F5F6 !important;"><?= print_lang($app_lang,'marketers_ins_rep_thead_inc_incentive'); ?></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                            foreach($pageData['incomes'] as $row){
                                                $currency_data = fetch_table_where("currency","uid",$row['currency'],true);
                                                if(!empty($search_convert_currency))
                                                {
                                                    $currency_data = fetch_table_where("currency","uid",$search_convert_currency,true);
                                                }

                                                $currency_symbol = $currency_data['symbol'];
                                            ?>
                                            <tr class="text-center">
                                                <td><?= display_true_date(explode(' ',$row['date'])[0]); ?></td>
                                                <td class="print-hide"><?= $row['invoice']; ?></td>
                                                <td style="display: none;" class="print-show"><?= $row['invoice_val']; ?></td>
                                                <td><?= $currency_symbol." ".round_decimels_digits($row['income']); ?></td>
                                                <td><?= $currency_symbol." ".round_decimels_digits($row['paid']); ?></td>
                                                <td><?= $currency_symbol." ".round_decimels_digits($row['pending']); ?></td>
                                                <td><?= $row['account']; ?></td>
                                                <td><?= $currency_symbol." ".round_decimels_digits($row['incentive']); ?></td>
                                            </tr>
                                        <?php } ?>
                                    </tbody>
                                </table>
                            </td>




                            <td style="width: 35%;">
                                <table class="table table-bordered">
                                    <thead>
                                        <tr>
                                            <th style="text-align: center; background: #F5F5F6 !important;" colspan="4"><h3><?= print_lang($app_lang,'marketers_ins_rep_title_expenses'); ?></h3></th>
                                        </tr>
                                        <tr class="text-center">
                                            <th style="text-align: center; background: #F5F5F6 !important;"><?= print_lang($app_lang,'marketers_ins_rep_thead_exp_date'); ?></th>
                                            <th style="text-align: center; background: #F5F5F6 !important;"><?= print_lang($app_lang,'marketers_ins_rep_thead_exp_narration'); ?></th>
                                            <th style="text-align: center; background: #F5F5F6 !important;"><?= print_lang($app_lang,'marketers_ins_rep_thead_exp_account'); ?></th>
                                            <th style="text-align: center; background: #F5F5F6 !important;"><?= print_lang($app_lang,'marketers_ins_rep_thead_exp_amount'); ?></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                            foreach($pageData['expenses'] as $row){
                                                $currency_data = fetch_table_where("currency","uid",$row['currency'],true);
                                                if(!empty($search_convert_currency))
                                                {
                                                    $currency_data = fetch_table_where("currency","uid",$search_convert_currency,true);
                                                }

                                                $currency_symbol = $currency_data['symbol'];
                                            ?>
                                            <tr class="text-center">
                                                <td><?= display_true_date(explode(' ',$row['date'])[0]); ?></td>
                                                <td><?= $row['narration']; ?></td>
                                                <td><?= $row['account']; ?></td>
                                                <td><?= $currency_symbol." ".round_decimels_digits($row['amount']); ?></td>
                                            </tr>
                                        <?php } ?>
                                    </tbody>
                                </table>
                            </td>
                        </tr>
                    </table>

                    <div class="table-responsive">


                        <div class="col-md-12" style="padding: 0;">
                            <table class="table table-bordered">
                                <thead>
                                    <tr class="text-center">
                                        <th style="text-align: center;  background: #F5F5F6 !important;"><?= print_lang($app_lang,'marketers_ins_total_incomes'); ?></th>
                                        <th style="text-align: center;  background: #F5F5F6 !important;"><?= print_lang($app_lang,'marketers_ins_total_paid'); ?></th>
                                        <th style="text-align: center;  background: #F5F5F6 !important;"><?= print_lang($app_lang,'marketers_ins_total_pending'); ?></th>
                                        <th style="text-align: center;  background: #F5F5F6 !important;"><?= print_lang($app_lang,'marketers_ins_total_incentives'); ?></th>
                                        <th style="text-align: center;  background: #F5F5F6 !important;"><?= print_lang($app_lang,'marketers_ins_total_expenses'); ?></th>
                                        <th style="text-align: center;  background: #F5F5F6 !important;"><?= print_lang($app_lang,'marketers_ins_total_balance'); ?></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr class="text-center">
                                        <td><strong><?= round_decimels_digits($pageData['total_incomes']); ?></strong></td>
                                        <td><strong><?= round_decimels_digits($pageData['total_paid']); ?></strong></td>
                                        <td><strong><?= round_decimels_digits($pageData['total_pending']); ?></strong></td>
                                        <td><strong><?= round_decimels_digits($pageData['total_incentives']); ?></strong></td>
                                        <td><strong><?= round_decimels_digits($pageData['total_expenses']); ?></strong></td>
                                        <td><strong><?= round_decimels_digits($pageData['balance']); ?></strong></td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>



                    </div>

                </div>
            </div>
        </div>
    </div>
</div>