
<style type="text/css">
    .print_show{display: none !important;}
    @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;}
            #sale-and-return-report-search-form{display: none;}
            .print_show{display: block !important;}
            .print_hide{display: none !important;}
            body {
            -webkit-print-color-adjust:exact;
            background: #fff;
            ::-webkit-scrollbar {
                display: none;
            }
        }
    }

</style>
<?php $item_settings = get_item_settings(); ?>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2><?= print_lang($app_lang,'mod_all_bonuses_rep_breadcrumb_title'); ?></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,'mod_all_bonuses_rep_breadcrumb_title'); ?></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,'mod_all_bonuses_rep_title'); ?></h2>

                    <form id="all-bonuses-report-search-form" action="<?= url('/reports/all-bonuses'); ?>">
                    <div class="row">
                        <div class="col-md-3 pd2">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mod_sale_and_return_rep_filter_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-3 pd2">
                            <div class="form-group">
                                <label><?= print_lang($app_lang,'mod_sale_and_return_rep_filter_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 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>
                    </form>

                    <div class="table-responsive">
                        <table class="table table-bordered table-hover dataTables-view">
                            <thead>
                                <tr>
                                    <th class="text-center"><?= print_lang($app_lang,'mod_all_bonuses_rep_thead_sr_num'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'mod_all_bonuses_rep_thead_item'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'mod_all_bonuses_rep_thead_batch'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'mod_all_bonuses_rep_thead_cost'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'mod_all_bonuses_rep_thead_sale_price'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'mod_all_bonuses_rep_thead_purchases'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'mod_all_bonuses_rep_thead_sales'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'mod_all_bonuses_rep_thead_sales_return'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'mod_all_bonuses_rep_thead_transfer_in'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'mod_all_bonuses_rep_thead_transfer_out'); ?></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                $total_purchases_bonus = [];
                                $total_sales_bonus = [];
                                $total_sales_return_bonus = [];
                                $total_transfer_in_bonus = [];
                                $total_transfer_out_bonus = [];

                                $total_purchases_bonus_amount = [];
                                $total_sales_bonus_amount = [];
                                $total_sales_return_bonus_amount = [];
                                $total_transfer_in_bonus_amount = [];
                                $total_transfer_out_bonus_amount = [];

                                $purchase_bonuses_amount = 0;
                                $sales_bonuses_amount = 0;
                                $return_bonuses_amount = 0;
                                $transfer_in_bonuses_amount = 0;
                                $transfer_out_bonuses_amount = 0;
                                $i = 1;
                                foreach($pageData as $row){
                                    $purchase_bonuses_amount = $row['purchase_bonuses'] * $row['_avg_cost']; $total_purchases_bonus_amount[] = $purchase_bonuses_amount;
                                    $sales_bonuses_amount = $row['sales_bonuses'] * $row['_avg_cost']; $total_sales_bonus_amount[] = $sales_bonuses_amount;
                                    $return_bonuses_amount = $row['return_bonuses'] * $row['_avg_cost']; $total_sales_return_bonus_amount[] = $return_bonuses_amount;
                                    $transfer_in_bonuses_amount = $row['transfer_in_bonuses'] * $row['_avg_cost']; $total_transfer_in_bonus_amount[] = $transfer_in_bonuses_amount;
                                    $transfer_out_bonuses_amount = $row['transfer_out_bonuses'] * $row['_avg_cost']; $total_transfer_out_bonus_amount[] = $transfer_out_bonuses_amount;
                                ?>
                                    <tr class="text-center">
                                        <td><?= $i++; ?></td>
                                        <td><?= $row['name']; ?></td>
                                        <td><?= $row['batch']; ?></td>
                                        <td><?= amount_number_format($row['_avg_cost']); ?></td>
                                        <td><?= amount_number_format($row['sale_price']); ?></td>
                                        <td>
                                            <?= amount_number_format($row['purchase_bonuses']);
                                            $total_purchases_bonus[] = $row['purchase_bonuses']; ?>
                                            <br><span class="text-muted" style="font-size: 11px !important; font-weight: 600 !important;"><?php echo '( '.amount_number_format($purchase_bonuses_amount).' )'; ?></span>
                                             
                                        </td>
                                        <td>
                                            <?= amount_number_format($row['sales_bonuses']); $total_sales_bonus[] = $row['sales_bonuses']; ?>
                                            <br><span class="text-muted" style="font-size: 11px !important; font-weight: 600 !important;"><?php echo '( '.amount_number_format($sales_bonuses_amount).' )'; ?></span>
                                        </td>
                                        <td>
                                            <?= amount_number_format($row['return_bonuses']); $total_sales_return_bonus[] = $row['return_bonuses']; ?>
                                            <br><span class="text-muted" style="font-size: 11px !important; font-weight: 600 !important;"><?php echo '( '.amount_number_format($return_bonuses_amount).' )'; ?></span>
                                        </td>
                                        <td><?= amount_number_format($row['transfer_in_bonuses']); $total_transfer_in_bonus[] = $row['transfer_in_bonuses']; ?>
                                            <br><span class="text-muted" style="font-size: 11px !important; font-weight: 600 !important;"><?php echo '( '.amount_number_format($transfer_in_bonuses_amount).' )'; ?></span>
                                        </td>
                                        <td><?= amount_number_format($row['transfer_out_bonuses']); $total_transfer_out_bonus[] = $row['transfer_out_bonuses']; ?>
                                            <br><span class="text-muted" style="font-size: 11px !important; font-weight: 600 !important;"><?php echo '( '.amount_number_format($transfer_out_bonuses_amount).' )'; ?></span>
                                        </td>
                                    </tr>
                                <?php } ?>

                                <tr class="text-center">
                                    <td><strong><?= $i++; ?></strong></td>
                                    <td><strong><?= print_lang($app_lang,'mod_all_bonuses_rep_thead_totals'); ?></strong></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td><strong>
                                        <?= amount_number_format(array_sum($total_purchases_bonus)); ?></strong>
                                        <br><span class="text-muted" style="font-size: 11px !important; font-weight: 600 !important;"><?php echo '( '.amount_number_format(array_sum($total_purchases_bonus_amount)).' )'; ?></span>
                                    </td>
                                    <td><strong>
                                        <?= amount_number_format(array_sum($total_sales_bonus)); ?></strong>
                                        <br><span class="text-muted" style="font-size: 11px !important; font-weight: 600 !important;"><?php echo '( '.amount_number_format(array_sum($total_sales_bonus_amount)).' )'; ?></span>
                                    </td>
                                    <td><strong>
                                        <?= amount_number_format(array_sum($total_sales_return_bonus)); ?></strong>
                                        <br><span class="text-muted" style="font-size: 11px !important; font-weight: 600 !important;"><?php echo '( '.amount_number_format(array_sum($total_sales_return_bonus_amount)).' )'; ?></span>
                                    </td>
                                    <td><strong>
                                        <?= amount_number_format(array_sum($total_transfer_in_bonus)); ?></strong>
                                        <br><span class="text-muted" style="font-size: 11px !important; font-weight: 600 !important;"><?php echo '( '.amount_number_format(array_sum($total_transfer_in_bonus_amount)).' )'; ?></span>
                                    </td>
                                    <td><strong>
                                        <?= amount_number_format(array_sum($total_transfer_out_bonus)); ?></strong>
                                        <br><span class="text-muted" style="font-size: 11px !important; font-weight: 600 !important;"><?php echo '( '.amount_number_format(array_sum($total_transfer_out_bonus_amount)).' )'; ?></span>
                                    </td>

                            </tbody>
                        </table>    
                    </div>

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