<vn-crud-model
    auto-load="false"
    vn-id="model"
    url="/ticket/api/TicketRequests"
    fields="['id', 'description', 'created', 'requesterFk', 'atenderFk', 'quantity', 'price', 'saleFk', 'isOk']"
    order="created ASC"
    link="{ticketFk: $ctrl.$stateParams.id}"
    filter="::$ctrl.filter"
    data="purchaseRequests">
</vn-crud-model>
<vn-watcher
    vn-id="watcher"
    data="purchaseRequests"
    form="form">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()">
    <vn-card pad-large>
    <vn-horizontal>
    <vn-table model="model">
        <vn-thead>
            <vn-tr>
                <vn-th number>Id</vn-th>
                <vn-th>Description</vn-th>
                <vn-th number>Created</vn-th>
                <vn-th>Requester</vn-th>
                <vn-th>Atender</vn-th>
                <vn-th number>Quantity</vn-th>
                <vn-th number>Price</vn-th>
                <vn-th number>Sale id</vn-th>
                <vn-th number>Ok</vn-th>
            </vn-tr>
        </vn-thead>
        <vn-tbody>
            <vn-tr ng-repeat="request in purchaseRequests">
                <vn-td number>{{::request.id}}</vn-td>
                <vn-td expand>{{::request.description}}</vn-td>
                <vn-td number>{{::request.created | dateTime: 'dd/MM/yyyy'}}</vn-td>
                <vn-td expand>
                    <span 
                        class="link" 
                        ng-click="$ctrl.showWorkerDescriptor($event, request.requesterFk)">
                        {{::request.requester.user.nickname | dashIfEmpty}}
                    </span>
                </vn-td>
                <vn-td expand>
                    <span
                        class="link" 
                        ng-click="$ctrl.showWorkerDescriptor($event, request.atenderFk)">
                        {{::request.atender.user.nickname | dashIfEmpty}}
                    </span>
                </vn-td>
                <vn-td number>{{::request.quantity}}</vn-td>
                <vn-td number>{{::request.price | currency: 'EUR': 2}}</vn-td>
                <vn-td number>
                    <span 
                        ng-show="::request.saleFk"
                        ng-click="$ctrl.showItemDescriptor($event, request.sale.itemFk)"
                        class="link">
                        {{request.saleFk | zeroFill:6}}
                    </span>
                </vn-td>
                <vn-td number>
                    <vn-check vn-one
                        field="::request.isOk"
                        triple-state="true"
                        title="{{$ctrl.getRequestState(request.isOk)}}"
                        disabled="true">
                    </vn-check>
                </vn-td>
                <vn-td number>
                    <vn-icon-button 
                        disabled="::request.saleFk"
                        icon="delete"
                        ng-click="$ctrl.removeLine($index)"
                        vn-tooltip="Remove request"
                        tabindex="-1">
                    </vn-icon-button>
                </vn-td>
            </vn-tr>
        </vn-tbody>
    </vn-table>
    </vn-horizontal>
    </vn-card>
</form>
<vn-item-descriptor-popover
    vn-id="itemDescriptor"
    quicklinks="$ctrl.quicklinks">
</vn-item-descriptor-popover>
<vn-worker-descriptor-popover 
    vn-id="workerDescriptor"
    worker-fk="$ctrl.selectedWorker">
</vn-worker-descriptor-popover>
<a ui-sref="ticket.card.request.create"
    vn-tooltip="New request"
    vn-bind="+"
    fixed-bottom-right>
    <vn-float-button icon="add"></vn-float-button>
</a>