<vn-auto-search
    model="model">
</vn-auto-search>
<vn-data-viewer
    model="model"
    class="vn-mb-xl">
    <vn-card>
    <vn-table model="model">
        <vn-thead>
            <vn-tr>
                <vn-th field="id" number>Id</vn-th>
                <vn-th field="salesPersonFk">Sales person</vn-th>
                <vn-th field="clientFk">Client</vn-th>
                <vn-th field="isConfirmed" center>Confirmed</vn-th>
                <vn-th field="created" center expand>Created</vn-th>
                <vn-th field="landed" shrink-date>Landed</vn-th>
                <vn-th field="created" center>Hour</vn-th>
                <vn-th field="agencyName" center>Agency</vn-th>
                <vn-th field="total" center>Total</vn-th>
            </vn-tr>
        </vn-thead>
        <vn-tbody>
            <a
                ng-repeat="order in model.data"
                class="clickable search-result vn-tr"
                ui-sref="order.card.summary({id: {{::order.id}}})">
                <vn-td number>{{::order.id}}</vn-td>
                <vn-td expand>
                    <span
                        vn-click-stop="workerDescriptor.show($event, order.salesPersonFk)"
                        class="link" >
                        {{::order.name | dashIfEmpty}}
                    </span>
                </vn-td>
                <vn-td>
                    <span
                        vn-click-stop="clientDescriptor.show($event, order.clientFk)"
                        class="link">
                        {{::order.clientName}}
                    </span>
                </vn-td>
                <vn-td center>
                    <vn-check
                        ng-model="order.isConfirmed"
                        disabled="true">
                    </vn-check>
                </vn-td>
                <vn-td shrink-datetime>{{::order.created | date: 'dd/MM/yyyy HH:mm'}}</vn-td>
                <vn-td shrink-date>
                    <span class="chip {{$ctrl.compareDate(order.landed)}}">
                        {{::order.landed | date:'dd/MM/yyyy'}}
                    </span>
                </vn-td>
                <vn-td shrink>{{::(order.hourTheoretical 
                        ? order.hourTheoretical
                        : order.hourEffective) | dashIfEmpty
                        }}</vn-td>
                <vn-td expand>{{::order.agencyName}}</vn-td>
                <vn-td number>{{::order.total | currency: 'EUR': 2 | dashIfEmpty}}</vn-td>
                <vn-td shrink>
                    <vn-icon-button
                        vn-click-stop="$ctrl.preview(order)"
                        icon="preview"
                        vn-tooltip="Preview">
                    </vn-icon-button>
                </vn-td>
            </a>
        </vn-tbody>
    </vn-table>
    </vn-card>
</vn-data-viewer>
<a
    ui-sref="order.create"
    vn-bind="+"
    vn-tooltip="New order"
    fixed-bottom-right>
    <vn-float-button icon="add"></vn-float-button>
</a>
<vn-client-descriptor-popover
    vn-id="clientDescriptor">
</vn-client-descriptor-popover>
<vn-worker-descriptor-popover 
    vn-id="workerDescriptor">
</vn-worker-descriptor-popover>
<vn-popup vn-id="summary">
    <vn-order-summary
        order="$ctrl.selectedOrder">
    </vn-order-summary>
</vn-popup>