<mg-ajax path="dms/upload" options="vnPost"></mg-ajax>
<vn-watcher
    vn-id="watcher"
    data="$ctrl.dms">
</vn-watcher>
<form
    name="form"
    ng-submit="$ctrl.onSubmit()"
    class="vn-ma-md">
    <div class="vn-w-md">
        <vn-card class="vn-pa-lg">
           <!--  <vn-horizontal>
                <vn-textfield
                    vn-one
                    vn-focus
                    label="Reference" 
                    ng-model="$ctrl.dms.reference"
                    rule>
                </vn-textfield>
                <vn-autocomplete vn-one
                    label="Company"
                    ng-model="$ctrl.dms.companyId"
                    url="Companies"
                    show-field="code"
                    value-field="id">
                </vn-autocomplete>
            </vn-horizontal>
            <vn-horizontal>
                <vn-autocomplete vn-one
                    label="Warehouse"
                    ng-model="$ctrl.dms.warehouseId"
                    url="Warehouses"
                    show-field="name"
                    value-field="id">
                </vn-autocomplete>
                <vn-autocomplete vn-one
                    label="Type"
                    ng-model="$ctrl.dms.dmsTypeId"
                    url="DmsTypes"
                    show-field="name"
                    value-field="id">
                </vn-autocomplete>
            </vn-horizontal>
            <vn-horizontal>
                <vn-textarea
                    vn-one
                    label="Description" 
                    ng-model="$ctrl.dms.description"
                    rule>
                </vn-textarea>
            </vn-horizontal> -->
            <vn-horizontal>
                <vn-textfield
                    vn-one
                    label="Invoice" 
                    ng-model="$ctrl.import.invoice">
                </vn-textfield>
            </vn-horizontal>
            <vn-horizontal>
                <vn-textarea
                    vn-one
                    label="Observation" 
                    ng-model="$ctrl.import.observation">
                </vn-textarea>
            </vn-horizontal>
            <vn-horizontal>
                <vn-input-file
                    vn-one 
                    label="File" 
                    ng-model="$ctrl.import.file"
                    on-change="$ctrl.onFileChange($event)"
                    required="true"
                    multiple="true">
                    <append>
                        <vn-icon vn-none
                            color-marginal
                            title="{{$ctrl.contentTypesInfo}}"
                            icon="info">
                        </vn-icon>
                    </append>
                </vn-input-file>
            </vn-horizontal>
            <vn-horizontal>
                <table class="vn-table">
                    <thead>
                        <tr>
                            <th translate center>Item ID</th>
                            <th translate expand>Description</th>
                            <th translate center>Size</th>
                            <th translate center>Packing</th>
                            <th translate center>Grouping</th>
                            <th translate center>Buying value</th>
                            <th translate center>Box</th>
                            <th translate center>Volume</th>
                        </tr>
                    </thead>
                    <tbody ng-repeat="buy in $ctrl.import.buys">
                        <tr>
                            <td title="{{::buy.itemFk}}">
                                <vn-autocomplete
                                    class="dense"
                                    vn-focus
                                    url="Items"
                                    ng-model="buy.itemFk"
                                    show-field="name"
                                    value-field="id"
                                    search-function="$ctrl.itemSearchFunc($search)"
                                    order="id DESC"
                                    tabindex="1">
                                    <tpl-item>
                                        {{::id}} - {{::name}}
                                    </tpl-item>
                                </vn-autocomplete>
                            </td>
                            <td title="{{::buy.description}}" expand>{{::buy.description | dashIfEmpty}}</td>
                            <td center title="{{::buy.size}}">{{::buy.size | dashIfEmpty}}</td>
                            <td center>
                                <vn-chip translate-attr="line.groupingMode == 2 ? {title: 'Minimun amount'} : {title: 'Packing'}" ng-class="{'message': line.groupingMode == 2}"> 
                                    <span translate>{{::buy.packing | dashIfEmpty}}</span>
                                </vn-chip>
                            </td>
                            <td center>
                                <vn-chip translate-attr="line.groupingMode == 1 ? {title: 'Minimun amount'} : {title: 'Grouping'}" ng-class="{'message': line.groupingMode == 1}"> 
                                    <span translate>{{::buy.grouping | dashIfEmpty}}</span>
                                </vn-chip>
                            </vn-td>
                            <td>{{::buy.buyingValue | currency: 'EUR':2}}</td>
                            <td center title="{{::buy.packageFk | dashIfEmpty}}">
                                <vn-autocomplete
                                    vn-one
                                    url="Packagings"
                                    show-field="id"
                                    value-field="id"
                                    where="{isBox: true}"
                                    ng-model="buy.packageFk">
                                </vn-autocomplete>
                            </td>
                            <td center title="{{::buy.volume}}">{{::buy.volume | number}}</td>
                        </tr>
                    </tbody>
                </table>
            </vn-horizontal>
        </vn-card>
        <vn-button-bar>
            <vn-submit
                label="Upload">
            </vn-submit>
            <vn-button
                class="cancel"
                label="Cancel"
                ui-sref="entry.card.buy.index"></vn-button>
            </vn-button>
        </vn-button-bar>
    </div>
</form>