<div class="wrapper">
    <div class="container">
        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">  
                <div class="pull-left">          
                    <h4 class="page-title">Branch Requistions:</h4>
                </div>
                <div class="btn-group pull-right">
                    <a href="<?php echo base_url().'add_requisition';?>" class="btn btn-custom waves-effect waves-light m-t-15" >Add Requisition<span class="m-l-5"><i class="fa fa-plus"></i></span></a>
                </div>
            </div>
        </div>

        <div class="row" id="divselection">
            <div class="col-sm-12">
                <div class="card-box ">
                    <h4 class="header-title m-t-0 m-b-30">Filters:</h4>
                    <form id="reportform" method="Post" action="<?php echo base_url();?>branch_requisitions" >
                        <div class="row">
                            <div class="col-lg-2">
                                <div class="row">
                                    <div class="col-lg-12"> <label class="control-label">Branch</label></div>
                                </div>
                                <div class="row">
                                    <div class="col-lg-12"> 
                                        <select  class="form-control" id="business_id" name="business_id">
                                            <?php if($this->session->userdata('ho')=='Yes'){?>
                                                <option value="<?php echo 0;?>">All</option>
                                            <?php } ?>
                                            <?php foreach($businesses as $business){?>
                                            <option <?php if($selected_business==$business['id_business']){ echo "selected='selected'";}?> value="<?php echo $business['id_business']; ?>"><?php echo $business['business_name'];?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-2">
                                <div class="row">
                                    <div class="col-lg-12"> <label class="control-label">Run</label></div>
                                </div>
                                <div class="row">
                                    <div class="col-lg-12"> 
                                        <button class="btn btn-sm btn-success">Run</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="card-box table-responsive">
                    <h4 class="header-title m-t-0 m-b-30">&nbsp;</h4>
                    <table id="tblrequisitions" class="table table-striped table-bordered table-responsive nowrap" cellspacing="0" width="100%">
                        <thead>
                            <tr>
                                <th>Req. #</th>
                                <th>Branch</th>                                
                                <th>Req. Date</th>
                                <th style="text-align:right;">Required Total</th>                               
                                <th>Details</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $tot_req=0; foreach($requisitions as $req){?>
                                <tr>
                                    <td><?php echo $req['requisition_number'];?></td>
                                    <td><?php echo $req['business_name'];?></td>                                    
                                    <td><?php echo $req['requistion_date'];?></td>
                                    <td style="text-align:right;"><?php echo $req['required_qty']; $tot_req+=$req['required_qty']?></td>                                   
                                    <td>
                                        <a target="reqdetail" href="<?php echo base_url()."branch_requisition/".$req['requisition_number'];?>" class="btn btn-sm btn-info" >Open Req.# <?php echo $req['requisition_number'];?></a>
                                    </td>                                    
                                </tr>
                            <?php }?>
                        </tbody>
                        <tfoot>
                            <tr>
                                <th></th>
                                
                                <th></th>
                                <th></th>
                                <th style="text-align:right;"><?php echo $tot_req;?></th>
                                <th></th>
                            </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>

        <div id="addrequisition" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="addrequisition" aria-hidden="true" style="display: none;">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title" id="custom-width-modalLabel">Add a new Requisition</h4>
                    </div>
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-md-6 form-group">
                                <label for="id_product">Product</label>
                                <input class="form-control" placeholder="Product" name="id_product">
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">

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

<script>

$('document').ready(function (){
    $('#tblrequisitions').DataTable();
    //console.log($('#tblrequisitions tbody tr').size());
    if($("#business_id").size()==1 && $('#tblrequisitions tbody tr').size()==0){
        $("#reportform").submit();
    }
});

function openaddnew(){
    
    $("#addrequisition").modal({
        backdrop: 'static',
        keyboard: false,
        show: true
    });

}

</script>