<vn-card class="summary">
    <h5>
        <a 
            ng-if="::$ctrl.summary.id"
            vn-tooltip="Go to the ticket"
            ui-sref="ticket.card.summary({id: {{::$ctrl.summary.id}}})"
            name="goToSummary">
            <vn-icon-button icon="launch"></vn-icon-button>
        </a>
        <span>
            Ticket #{{$ctrl.summary.id}} - {{$ctrl.summary.client.name}} 
            ({{$ctrl.summary.client.id}}) - {{$ctrl.summary.nickname}}
        </span>
        <vn-button-menu 
            disabled="!$ctrl.isEditable"
            class="message"
            label="Change state"
            value-field="code"
            url="States/editableStates"
            on-change="$ctrl.changeState(value)">
        </vn-button-menu>
        <vn-ticket-descriptor-menu 
            ng-if="!$ctrl.isOnTicketCard"
            ticket-id="$ctrl.summary.id" 
            parent-reload="$ctrl.reload()"
        />
    </h5>
    <vn-horizontal>
        <vn-one>
            <vn-label-value label="State" 
                value="{{$ctrl.summary.ticketState.state.name}}">
            </vn-label-value>
            <vn-label-value label="Salesperson">
                <span 
                    ng-click="workerDescriptor.show($event, $ctrl.summary.client.salesPersonFk)"
                    class="link">
                    {{$ctrl.summary.client.salesPersonUser.name}}
                </span>
            </vn-label-value>
            <vn-label-value label="Agency" 
                value="{{$ctrl.summary.agencyMode.name}}">
            </vn-label-value>
            <vn-label-value label="Zone">
                <span
                    ng-click="zoneDescriptor.show($event, $ctrl.summary.zoneFk)"
                    class="link">
                    {{$ctrl.summary.zone.name}}
                </span>
            </vn-label-value>
            <vn-label-value label="Warehouse" 
                value="{{$ctrl.summary.warehouse.name}}">
            </vn-label-value>
            <vn-label-value label="Route">
                <span 
                    ng-click="routeDescriptor.show($event, $ctrl.summary.routeFk)"
                    class="link">
                    {{$ctrl.summary.routeFk}}
                </span>
            </vn-label-value>
            <vn-label-value label="Invoice">
                <span
                    ng-class="{link: $ctrl.summary.refFk}"
                    ng-click="$ctrl.showInvoiceOutDescriptor($event, $ctrl.summary.refFk)">
                    {{$ctrl.summary.refFk | dashIfEmpty}}
                </span>
            </vn-label-value>
        </vn-one>
        <vn-two>
            <vn-label-value label="Shipped" 
                value="{{$ctrl.summary.shipped | date: 'dd/MM/yyyy HH:mm'}}">
            </vn-label-value>
            <vn-label-value label="Landed" 
                value="{{$ctrl.summary.landed | date: 'dd/MM/yyyy'}}">
            </vn-label-value>
            <vn-label-value label="Package size" 
                value="{{$ctrl.summary.packages}}">
            </vn-label-value>
            <vn-label-value label="Address phone"
                ng-if="$ctrl.summary.address.phone != null" 
                value="{{$ctrl.summary.address.phone}}">
            </vn-label-value>
            <vn-label-value label="Address mobile"
                ng-if="$ctrl.summary.address.mobile != null"
                value="{{$ctrl.summary.address.mobile}}">
            </vn-label-value>
            <vn-label-value label="Client phone"
                ng-if="$ctrl.summary.client.phone != null"
                value="{{$ctrl.summary.client.phone}}">
            </vn-label-value>
            <vn-label-value label="Client mobile"
                ng-if="$ctrl.summary.client.mobile != null"
                value="{{$ctrl.summary.client.mobile}}">
            </vn-label-value>
            <vn-label-value label="Address" no-ellipsize
                value="{{$ctrl.formattedAddress}}">
            </vn-label-value>
        </vn-two>
        <vn-one class="notes">
            <vn-label-value no-ellipsize
                label="{{note.observationType.description}}"
                ng-repeat="note in $ctrl.summary.notes track by note.id"
                value="{{note.description}}">
            </vn-label-value>
        </vn-one>
        <vn-one class="taxes">
            <p><vn-label translate>Subtotal</vn-label> {{$ctrl.summary.totalWithoutVat | currency: 'EUR':2}}</p>
            <p><vn-label translate>VAT</vn-label> {{$ctrl.summary.totalWithVat - $ctrl.summary.totalWithoutVat | currency: 'EUR':2}}</p>
            <p><vn-label><strong>Total</strong></vn-label> <strong>{{$ctrl.summary.totalWithVat | currency: 'EUR':2}}</strong></p>
        </vn-one>
        <vn-auto name="sales">
            <h4>
                <a 
                    ui-sref="ticket.card.sale({id:$ctrl.ticket.id})"
                    target="_self">
                    <span translate vn-tooltip="Go to">Sale</span>
                </a>
            </h4>
            <vn-table>
                <vn-thead>
                    <vn-tr>
                        <vn-th shrink></vn-th>
                        <vn-th number shrink>Item</vn-th>
                        <vn-th number shrink>Visible</vn-th>
                        <vn-th number shrink>Available</vn-th>
                        <vn-th number shrink>Quantity</vn-th>
                        <vn-th>Description</vn-th>
                        <vn-th shrink number>Price</vn-th>
                        <vn-th shrink number>Discount</vn-th>
                        <vn-th shrink number>Amount</vn-th>
                        <vn-th shrink>Packing</vn-th>
                    </vn-tr>
                </vn-thead>
                <vn-tbody>
                    <vn-tr ng-repeat="sale in $ctrl.summary.sales track by sale.id">
                        <vn-td shrink>
                            <a ui-sref="claim.card.basicData({id: sale.claim.claimFk})">
                                <vn-icon icon="icon-claims"
                                    ng-show="sale.claim.claimFk"
                                    vn-tooltip="{{::$ctrl.$t('Claim')}}: {{::sale.claim.claimFk}}">
                                </vn-icon>
                            </a>
                            <a ui-sref="claim.card.basicData({id: sale.claimBeginning.claimFk})">
                                <vn-icon
                                    ng-show="sale.claimBeginning.claimFk"
                                    icon="icon-claims"
                                    vn-tooltip="{{::$ctrl.$t('Claim')}}: {{::sale.claimBeginning.claimFk}}">
                                </vn-icon>
                            </a>
                            <vn-icon 
                                ng-show="::(sale.visible < 0)" 
                                color-main
                                icon="warning"
                                vn-tooltip="Visible: {{::sale.visible || 0}}">
                            </vn-icon>
                            <vn-icon ng-show="sale.reserved" 
                                icon="icon-reserve"
                                translate-attr="{title: 'Reserved'}">
                            </vn-icon>
                            <vn-icon
                                ng-show="::sale.itemShortage"
                                translate-attr="{title: 'Not visible'}"
                                class="bright"
                                icon="icon-unavailable">
                            </vn-icon>
                            <vn-icon
                                ng-show="::sale.hasComponentLack"
                                translate-attr="{title: 'Component lack'}"
                                class="bright"
                                icon="icon-components">
                            </vn-icon>
                        </vn-td>
                        <vn-td number shrink>
                            <span 
                                ng-click="itemDescriptor.show($event, sale.itemFk, sale.id, $ctrl.ticket.shipped)"
                                class="link">
                                {{sale.itemFk | zeroFill:6}}
                            </span>
                        </vn-td>
                        <vn-td number shrink>
                            <vn-chip 
                                class="transparent" 
                                ng-class="{'alert': sale.visible < 0}">
                                {{::sale.visible}}
                            </vn-chip>
                        </vn-td>
                        <vn-td number shrink>
                            <vn-chip 
                                class="transparent" 
                                ng-class="{'alert': sale.available < 0}">
                                {{::sale.available}}
                            </vn-chip>
                        </vn-td>
                        <vn-td number shrink>{{::sale.quantity}}</vn-td>
                        <vn-td vn-fetched-tags>
                            <div>
                                <vn-one title="{{::sale.item.name}}">{{::sale.item.name}}</vn-one>
                                <vn-one ng-if="::sale.item.subName">
                                    <h3 title="{{::sale.item.subName}}">{{::sale.item.subName}}</h3>
                                </vn-one>
                            </div>
                            <vn-fetched-tags
                                max-length="6"
                                item="::sale.item"
                                tabindex="-1">
                            </vn-fetched-tags>
                        </vn-td>
                        <vn-td shrink number>{{::sale.price | currency: 'EUR':2}}</vn-td>
                        <vn-td shrink number>{{::sale.discount}} %</vn-td>
                        <vn-td shrink number>{{::sale.quantity * sale.price * ((100 - sale.discount) / 100) | currency: 'EUR':2}}</vn-td>
                        <vn-td shrink>
                            {{::sale.item.itemPackingTypeFk | dashIfEmpty}}
                        </vn-td>
                    </vn-tr>
                </vn-tbody>
            </vn-table>
        </vn-auto>
        <vn-one ng-if="$ctrl.summary.packagings.length != 0">
            <h4>
                <a 
                    ui-sref="ticket.card.package({id:$ctrl.ticket.id})"
                    target="_self">
                    <span translate vn-tooltip="Go to">Packages</span>
                </a>
            </h4>
            <vn-table model="model">
                <vn-thead>
                    <vn-tr>
                        <vn-th number>Created</vn-th>
                        <vn-th number>Package</vn-th>
                        <vn-th number>Quantity</vn-th>
                    </vn-tr>
                </vn-thead>
                <vn-tbody>
                    <vn-tr ng-repeat="package in $ctrl.summary.packagings">
                        <vn-td number>{{package.created | date: 'dd/MM/yyyy'}}</vn-td>
                        <vn-td number>{{package.packaging.item.name}}</vn-td>
                        <vn-td number>{{package.quantity}}</vn-td>
                    </vn-tr>
                </vn-tbody>
            </vn-table>
        </vn-one>
        <vn-one class="services" ng-if="$ctrl.summary.services.length != 0">
            <h4>
                <a 
                    ui-sref="ticket.card.service({id:$ctrl.ticket.id})"
                    target="_self">
                    <span translate vn-tooltip="Go to">Service</span>
                </a>
            </h4>
            <vn-table model="model">
                <vn-thead>
                    <vn-tr>
                        <vn-th number shrink>Quantity</vn-th>
                        <vn-th expand>Description</vn-th>
                        <vn-th number shrink>Price</vn-th>
                        <vn-th class="tax-class">Tax class</vn-th>
                        <vn-th number>Amount</vn-th>
                    </vn-tr>
                </vn-thead>
                <vn-tbody>
                    <vn-tr ng-repeat="service in $ctrl.summary.services">
                        <vn-td number shrink>{{::service.quantity}}</vn-td>
                        <vn-td expand>{{::service.description}}</vn-td>
                        <vn-td number shrink>{{::service.price | currency: 'EUR':2}}</vn-td>
                        <vn-td class="tax-class">
                            <span title="{{::service.taxClass.description}}">
                                {{::service.taxClass.description}}
                            </span>
                        </vn-td>
                        <vn-td number>{{::service.quantity * service.price | currency: 'EUR':2}}</vn-td>
                    </vn-tr>
                </vn-tbody>
            </vn-table>
        </vn-one>
    </vn-horizontal>
    <vn-horizontal>
        <vn-auto ng-if="$ctrl.summary.requests.length != 0">
            <h4>
                <a 
                    ui-sref="ticket.card.request.index({id:$ctrl.ticket.id})"
                    target="_self">
                    <span translate vn-tooltip="Go to">Purchase request</span>
                </a>
            </h4>
            <vn-table model="model">
                <vn-thead>
                    <vn-tr>
                        <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>Item</vn-th>
                        <vn-th number>Ok</vn-th>
                    </vn-tr>
                </vn-thead>
                <vn-tbody>
                    <vn-tr ng-repeat="request in $ctrl.summary.requests">
                        <vn-td expand>{{::request.description}}</vn-td>
                        <vn-td number>{{::request.created | date: 'dd/MM/yyyy'}}</vn-td>
                        <vn-td>{{::request.requester.user.name}}</vn-td>
                        <vn-td>{{::request.atender.user.name}}</vn-td>
                        <vn-td number>{{::request.quantity}}</vn-td>
                        <vn-td number>{{::request.price}}</vn-td>
                        <vn-td number>
                            <span 
                                ng-show="::request.saleFk"
                                ng-click="itemDescriptor.show($event, request.sale.itemFk, request.sale.id)"
                                class="link">
                                {{request.sale.itemFk | zeroFill:6}}
                            </span>
                        </vn-td>
                        <vn-td number>
                            <vn-check vn-one
                                ng-model="::request.isOk"
                                triple-state="true"
                                title="{{$ctrl.getRequestState(request.isOk)}}"
                                disabled="true">
                            </vn-check>
                        </vn-td>
                    </vn-tr>
                </vn-tbody>
            </vn-table>
        </vn-auto>
    </vn-horizontal>
</vn-card>
<vn-route-descriptor-popover
    vn-id="route-descriptor">
</vn-route-descriptor-popover>
<vn-item-descriptor-popover
    vn-id="item-descriptor"
    warehouse-fk="$ctrl.ticket.warehouseFk",
    ticket-fk="$ctrl.ticket.id">
</vn-item-descriptor-popover>
<vn-invoice-out-descriptor-popover
    vn-id="invoice-out-descriptor">
</vn-invoice-out-descriptor-popover>
<vn-worker-descriptor-popover 
    vn-id="workerDescriptor">
</vn-worker-descriptor-popover>
<vn-zone-descriptor-popover 
    vn-id="zoneDescriptor">
</vn-zone-descriptor-popover>