<div class="row"><div class="col-sm-12"><div class="page-title-box"><h2 class="page-title">Work Order (Indent) Wise Report</h2><p class="text-muted">"Work Order" in this ERP maps to GRN Indents (inventory_indent).</p></div></div></div>
<div class="row"><div class="col-sm-12"><div class="card"><div class="card-body">
    <div class="form-group">
        <?php echo $this->Form->create('Search', ['url'=>'work_order_report']); ?>
        <div class="row">
            <div class="col-md-4"><?php echo $this->Form->input('store', ['div'=>false,'label'=>'Store','class'=>'form-control','options'=>(['' => 'All Stores'] + Hash::combine($stores, '{n}.Location.id', '{n}.Location.name')),'id'=>'store']); ?></div>
            <div class="col-md-4"><?php echo $this->Form->input('daterange_h', ['div'=>false,'label'=>'Date Range','class'=>'form-control calendarmultiple','id'=>'startdate','name'=>'daterange','required'=>true,'value'=>$startdate]); ?></div>
        </div>
        <div class="mt-2"><?php echo $this->Form->button('View', ['class'=>'btn btn-info','type'=>'submit']); ?>&nbsp;<button type="button" class="btn btn-success" id="exportBtn">CSV Export</button></div>
        <?php echo $this->Form->end(); ?>
    </div>
    <div class="table-responsive mt-3">
        <table class="display table table-hover table-condensed">
            <thead><tr><th>#</th><th>Indent/WO ID</th><th>Store</th><th>Created By</th><th>Status</th><th>Total Amt</th><th>Approved Amt</th><th>Processed Amt</th><th>Stocked In Amt</th><th>Date</th></tr></thead>
            <tbody>
                <?php $i=1; foreach($workOrders as $w): ?>
                <tr>
                    <td><?= $i++ ?></td><td><?= h($w['indent_id']) ?></td><td><?= h($w['store']) ?></td>
                    <td><?= h($w['created_by']) ?></td><td><?= h($w['status']) ?></td>
                    <td><?= number_format($w['total_amount'],2) ?></td><td><?= number_format($w['approved_amount'],2) ?></td>
                    <td><?= number_format($w['processed_amount'],2) ?></td><td><?= number_format($w['stockin_amount'],2) ?></td>
                    <td><?= h($w['created']) ?></td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <script>$("#exportBtn").click(function(){ window.open('<?= $this->base ?>/dashboard/work_order_report_export?sdate='+$("#startdate").val()+'&store='+$("#store").val(),'_blank'); });</script>
</div></div></div></div>
