<mg-ajax path="InvoiceIns/{{patch.params.id}}" options="vnPatch"></mg-ajax>
<vn-watcher
    vn-id="watcher"
    data="$ctrl.invoiceIn"
    form="form"
    save="patch">
</vn-watcher>
<form name="form" ng-submit="watcher.submit()" class="vn-w-md">
    <vn-card class="vn-pa-lg">
        <vn-horizontal>
            <vn-autocomplete
                vn-one
                ng-model="$ctrl.invoiceIn.supplierFk"
                url="Suppliers"
                show-field="nickname"
                search-function="{or: [{id: $search}, {nickname: {like: '%'+ $search +'%'}}]}"
                value-field="id"
                order="nickname"
                label="Supplier"
                required="true"
                rule>
                <tpl-item>
                    {{::id}} - {{::nickname}}
                </tpl-item>
            </vn-autocomplete>
            <vn-textfield
                label="Supplier ref"
                ng-model="$ctrl.invoiceIn.supplierRef"
                rule>
            </vn-textfield>
        </vn-horizontal>
        <vn-horizontal>
            <vn-date-picker
                vn-one 
                label="Expedition date" 
                ng-model="$ctrl.invoiceIn.issued"
                vn-focus
                rule>
            </vn-date-picker>
            <vn-date-picker
                vn-one 
                label="Operation date"
                ng-model="$ctrl.invoiceIn.operated"
                rule>
            </vn-date-picker>
        </vn-horizontal>
        <vn-horizontal>
            <vn-datalist vn-one
                label="Undeductible VAT"
                ng-model="$ctrl.invoiceIn.deductibleExpenseFk"
                value-field="id"
                order="name"
                url="Expenses"
                fields="['id','name']"
                rule>
                <tpl-item>
                    {{id}} - {{name}}
                </tpl-item>
            </vn-datalist>
        </vn-horizontal>
        <vn-horizontal>
            <vn-date-picker
                vn-one 
                label="Entry date" 
                ng-model="$ctrl.invoiceIn.bookEntried"
                rule>
            </vn-date-picker>
            <vn-date-picker
                vn-one 
                label="Accounted date" 
                ng-model="$ctrl.invoiceIn.booked"
                rule>
            </vn-date-picker>
        </vn-horizontal>
        <vn-horizontal>
            <vn-autocomplete
                vn-one
                label="Currency"
                ng-model="$ctrl.invoiceIn.currencyFk"
                url="Currencies"
                show-field="code"
                value-field="id"
                rule>
            </vn-autocomplete>
            <vn-autocomplete
                url="Companies"
                label="Company"
                show-field="code"
                value-field="id"
                ng-model="$ctrl.invoiceIn.companyFk"
                rule>
            </vn-autocomplete>
        </vn-horizontal>
    </vn-card>
    <vn-button-bar>
        <vn-submit
            disabled="!watcher.dataChanged()"
            label="Save">
        </vn-submit>
        <vn-button
            class="cancel"
            label="Undo changes"
            disabled="!watcher.dataChanged()"
            ng-click="watcher.loadOriginalData()">
        </vn-button>
    </vn-button-bar>
</form>