<div class="content-header">
    <div class="row">
        <div class="col-md-6">
            <h2>{{::vm.translate.get('Stock management')}}</h2>
        </div>
        <div class="col-md-6 text-right">
            <a class="btn btn-info" ui-sref="warehouse-manage-products({warehouseId: vm.selectedWarehouse.id})">{{::vm.translate.get('Manage products in warehouse')}}</a>
            
        </div>
    </div>
</div>

<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">{{::vm.translate.get('Stock management for warehouse')}} <strong>{{ vm.selectedWarehouse.name }}</strong></h3>
                        <div class="card-tools">
                            <div class="row">
                                <div class="col">
                                    <select class="form-control" ng-change="vm.wareHouseSelectChange()" ng-model="vm.selectedWarehouse"
                                            ng-options="warehouse as warehouse.name for warehouse in vm.warehouses"></select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="card-body p-0 table-responsive">
                        <table ng-if="vm.selectedWarehouse" class="table table-striped" st-pipe="vm.getStocks" st-table="vm.stocks">
                            <thead>
                                <tr>
                                    <th>Id</th>
                                    <th>{{::vm.translate.get('Product Name')}}</th>
                                    <th>{{::vm.translate.get('Product Sku')}}</th>
                                    <th class="text-right">{{::vm.translate.get('Current Quantity')}}</th>
                                    <th class="text-right">(+/-) {{::vm.translate.get('Adjusted Quantity')}}</th>
                                    <th>{{::vm.translate.get('Note')}}</th>
                                    <th>{{::vm.translate.get('Stock History')}}</th>
                                </tr>
                                <tr>
                                    <th></th>
                                    <th>
                                        <div class="form-group">
                                            <input class="form-control" st-search="ProductName" />
                                        </div>
                                    </th>
                                    <th>
                                        <div class="form-group">
                                            <input class="form-control" st-search="ProductSku" />
                                        </div>
                                    </th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody ng-show="!vm.isLoading">
                                <tr ng-repeat="item in vm.stocks">
                                    <td>{{item.id}}</td>
                                    <td>{{item.productName}}</td>
                                    <td>{{item.productSku}}</td>
                                    <td class="text-right">{{item.quantity}}</td>
                                    <td>
                                        <input class="form-control text-right" ng-model="item.adjustedQuantity" />
                                    </td>
                                    <td>
                                        <input class="form-control" ng-model="item.note" />
                                    </td>
                                    <td>
                                        <a ui-sref="stock-history({warehouseId: vm.selectedWarehouse.id, productId : item.productId})">{{::vm.translate.get('View History')}}</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-page="50" st-displayed-pages="10" colspan="6"></td>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                    <div class="card-footer">
                        <div class="row">
                            <div class="col">
                                <div ng-show="!vm.isLoading" colspan="3">{{vm.tableStateRef.pagination.totalItemCount | number:0}} {{::vm.translate.get('records found')}}</div>
                            </div>
                            <div class="col">
                                <button class="btn btn-success float-right" ng-click="vm.save()"><span class="fa fa-save"></span> {{::vm.translate.get('Save')}}</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>