<div class="content-header">
    <div class="row">
        <div class="col-md-6">
            <h2>{{::vm.translate.get('Orders')}}</h2>
        </div>
        <div class="col-md-6 text-right">
            <a ui-sref="order-create" class="btn btn-success"><span class="fa fa-plus"></span> {{::vm.translate.get('Create Order')}}</a>
            <button ng-click="vm.getOrdersExport()" class="btn btn-info">{{::vm.translate.get('Export Orders')}}</button>
            <button ng-click="vm.getOrderLinesExport()" class="btn btn-info">{{::vm.translate.get('Export Orders with Order Lines')}}</button>
        </div>
    </div>
</div>

<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
                <div class="card" st-pipe="vm.getOrders" st-table="vm.orders">
                    <div class="card-header">
                        <div class="card-tools">
                            <st-date-range predicate="CreatedOn" before="query.before" after="query.after"></st-date-range>
                        </div>
                    </div>
                    <div class="card-body p-0 table-responsive">
                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th st-sort="Id" class="sortable">{{::vm.translate.get('Id')}}</th>
                                    <th>{{::vm.translate.get('Order Status')}}</th>
                                    <th>{{::vm.translate.get('Customer')}}</th>
                                    <th st-sort="CreatedOn" class="sortable">{{::vm.translate.get('Created On')}}</th>
                                    <th st-sort="SubTotal" class="sortable">{{::vm.translate.get('Order Total')}}</th>
                                    <th>{{::vm.translate.get('Actions')}}</th>
                                </tr>
                                <tr>
                                    <th>
                                        <div class="form-group">
                                            <input type="number" class="form-control" st-search="Id" />
                                        </div>
                                    </th>
                                    <th>
                                        <div class="form-group">
                                            <select class="form-control" st-search="Status">
                                                <option value="">All</option>
                                                <option ng-repeat="status in vm.orderStatus" value="{{status.id}}">{{status.name}}</option>
                                            </select>
                                        </div>
                                    </th>
                                    <th>
                                        <div class="form-group">
                                            <input class="form-control" st-search="CustomerName" />
                                        </div>
                                    </th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody ng-show="!vm.isLoading">
                                <tr ng-repeat="order in vm.orders">
                                    <td>{{order.id}}</td>
                                    <td>{{order.orderStatus}}</td>
                                    <td>{{order.customerName}}</td>
                                    <td>{{order.createdOn | date:'medium'}}</td>
                                    <td>{{order.orderTotalString }}</td>
                                    <td><a ui-sref="order-detail({id: order.id})" title="View" class="btn btn-primary btn-xs"> <span class="fa fa-eye"></span></a></td>
                                </tr>
                            </tbody>
                            <tbody ng-show="vm.isLoading">
                                <tr>
                                    <td colspan="6" class="text-center">Loading ... </td>
                                </tr>
                            </tbody>
                            <tfoot>
                                <tr>
                                    <td class="text-center" st-pagination="" st-items-by-content="50" st-displayed-contents="10" colspan="6"></td>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                    <div class="card-footer">
                        <div>
                            <div ng-show="!vm.isLoading" colspan="3">{{vm.tableStateRef.pagination.totalItemCount | number:0}} {{::vm.translate.get('records found')}}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
    </div>
</section>