<style type="text/css">
    .custom-col{padding: 2px !important;}
</style>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-8">
        <h2><?= print_lang($app_lang,'cons_warehouse_details_title'); ?></h2>
        <ol class="breadcrumb">
            <li>
                <a class="url-elem" href="<?php echo url('/dashboard'); ?>"><?= print_lang($app_lang,'home'); ?></a>
            </li>
            <li class="active">
                <strong><?= print_lang($app_lang,'cons_warehouse_details_breadcrumb'); ?></strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-4">
       
    </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,'cons_warehouse_details_title_listing'); ?></h2>
                    
                    <form id="c-warehouse-details-search-form" action="<?= url('/cwarehouses/details').'/'.$warehouse_uid; ?>">
                    <div class="row">
                        <div class="col-md-10">
                            <div class="row">
                                <div class="col-md-3 custom-col">
                                    <div class="form-group">
                                        <select class="form-control chosen-select" name="item">
                                            <option value="">-- <?= print_lang($app_lang,'cons_warehouse_details_filter_item'); ?> --</option>
                                            <?php foreach($items as $row){ ?>
                                                <option <?php if($search_item == $row['uid']){echo "selected='selected'";}?> value="<?= $row['uid']; ?>"><?= $row['name']; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-md-3 custom-col">
                                    <div class="form-group">
                                        <select class="form-control chosen-select" name="project">
                                            <option value="">-- <?= print_lang($app_lang,'cons_warehouse_details_filter_project'); ?> --</option>
                                            <?php foreach($projects as $row){ ?>
                                                <option <?php if($search_project == $row['uid']){echo "selected='selected'";}?> value="<?= $row['uid']; ?>"><?= $row['name']; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-md-3 custom-col">
                                    <div class="form-group">
                                        <?php if($branch_calander == 'persian'){ ?>
                                            <input type="text" class="form-control persian-date" value="<?= true_date_for_inputs($search_from); ?>" name="from" placeholder="<?= print_lang($app_lang,'cons_warehouse_details_filter_from'); ?>" readonly="" style="background: #fff;">
                                        <?php }else{ ?>
                                            <input type="date" class="form-control" name="from" value="<?= true_date_for_inputs($search_from); ?>">
                                        <?php } ?>
                                    </div>
                                </div>
                                <div class="col-md-3 custom-col">
                                    <div class="form-group">
                                        <?php if($branch_calander == 'persian'){ ?>
                                            <input type="text" class="form-control persian-date" value="<?= true_date_for_inputs($search_to); ?>" name="to" placeholder="<?= print_lang($app_lang,'cons_warehouse_details_filter_to'); ?>" readonly="" style="background: #fff;">
                                        <?php }else{ ?>
                                            <input type="date" class="form-control" name="to" value="<?= true_date_for_inputs($search_to); ?>">
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-2 text-right">
                            <button class="btn btn-w-m btn-primary custom-font-btn-search" type="submit"><?= print_lang($app_lang,'cons_warehouse_details_filter_search'); ?></button>
                        </div>
                    </div>
                    </form>

                    <hr>

                    <div class="table-responsive">
                        <table class="table table-bordered table-hover dataTables-view">
                            <thead>
                                <tr>
                                    <th class="text-center" style="min-width:50px; max-width:50px;"><?= print_lang($app_lang,'cons_warehouse_details_thead_serial'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'cons_warehouse_details_thead_item_name'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'cons_warehouse_details_thead_unit'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'cons_warehouse_details_thead_rate'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'cons_warehouse_details_thead_total'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'cons_warehouse_details_thead_assign'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'cons_warehouse_details_thead_work_available'); ?></th>
                                    <th class="text-center"><?= print_lang($app_lang,'cons_warehouse_details_thead_damage'); ?></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php 
                                $i = 1;
                                $total_cost = array();
                                $total_purchase = array();
                                $total_assign = array();
                                $total_available = array();
                                foreach($pageData as $row){ ?>
                                    <tr class="text-center">
                                        <td><?= $i++; ?></td>
                                        <td><?= $row['name']; ?></td>
                                        <td><?= $row['unit']; ?></td>
                                        <td><?= $row['last_cost']; $total_cost[] = $row['last_cost']; ?></td>
                                        <td><?= $row['total_purchases']; $total_purchase[] = $row['total_purchases']; ?></td>
                                        <td><?= $row['total_assign']; $total_assign[] = $row['total_assign']; ?></td>
                                        <td><?= $row['available']; $total_available[] = $row['available']; ?></td>
                                        <td></td>
                                    </tr>
                                <?php } ?>
                                    <tr class="text-center">
                                        <td><?= $i++; ?></td>
                                        <td></td>
                                        <td></td>
                                        <td><strong><?= round_decimels_digits(array_sum($total_cost)); ?></strong></td>
                                        <td><strong><?= round_decimels_digits(array_sum($total_purchase)); ?></strong></td>
                                        <td><strong><?= round_decimels_digits(array_sum($total_assign)); ?></strong></td>
                                        <td><strong><?= round_decimels_digits(array_sum($total_available)); ?></strong></td>
                                        <td></td>
                                    </tr>
                            </tbody>
                        </table>    
                    </div>

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