<mg-ajax path="/client/api/Clients/{{patch.params.id}}/updateFiscalData" options="vnPatch"></mg-ajax>
<vn-watcher
    vn-id="watcher"
    data="$ctrl.client"
    form="form"
    save="patch">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()" compact>
    <vn-card pad-large>
        <vn-horizontal>
            <vn-textfield
                vn-two
                vn-focus
                label="Social name"
                model="$ctrl.client.socialName"
                rule="client.socialName"
                info="You can use letters and spaces">
            </vn-textfield>
            <vn-textfield
                vn-one
                label="Tax number"
                field="$ctrl.client.fi">
            </vn-textfield>
        </vn-horizontal>
        <vn-horizontal>
            <vn-textfield
                vn-two
                label="Street"
                field="$ctrl.client.street">
            </vn-textfield>
        </vn-horizontal>
        <vn-horizontal>
            <vn-autocomplete vn-id="country" vn-one
                field="$ctrl.client.countryFk"
                url="/api/Countries"
                show-field="country"
                value-field="id"
                label="Country">
            </vn-autocomplete>
            <vn-autocomplete vn-id="province" vn-one
                field="$ctrl.client.provinceFk"
                url="/api/Provinces"
                where="{countryFk: country.selection.id}"
                show-field="name"
                value-field="id"
                label="Province">
            </vn-autocomplete>
        </vn-horizontal>
        <vn-horizontal>
            <vn-textfield vn-one
                label="City"
                field="$ctrl.client.city">
            </vn-textfield>
            <vn-textfield vn-one
                label="Postcode"
                field="$ctrl.client.postcode">
            </vn-textfield>
            <!-- <vn-autocomplete vn-id="town" vn-one 
                label="City"
                url="/api/Towns"
                fields="['id', 'name']"
                where="{provinceFk: province.selection.id}"
                show-field="name"
                value-field="name"
                field="$ctrl.client.city">
            </vn-autocomplete>
            <vn-autocomplete vn-id="postcode" vn-one
                url="/api/Postcodes/location"
                fields="['code', 'townFk']"
                field="$ctrl.client.postcode"
                search-function="{code: $search}"
                where="{townFk: town.selection.id}"
                order="code, townFk"
                show-field="code"
                value-field="code"
                label="Postcode">         
            </vn-autocomplete> -->
        </vn-horizontal>
        <vn-horizontal pad-small-v>
            <vn-check
                vn-one
                label="Active"
                field="$ctrl.client.isActive">
            </vn-check>
            <vn-check
                vn-one
                label="Frozen"
                field="$ctrl.client.isFreezed">
            </vn-check>
        </vn-horizontal>
        <vn-horizontal pad-small-v>
            <vn-check
                vn-one
                label="Has to invoice"
                field="$ctrl.client.hasToInvoice">
            </vn-check>
            <vn-check
                vn-one
                label="Vies"
                field="$ctrl.client.isVies">
            </vn-check>
        </vn-horizontal>
        <vn-horizontal pad-small-v>
            <vn-check
                vn-one
                label="Invoice by mail"
                field="$ctrl.client.isToBeMailed">
            </vn-check>
            <vn-check
                vn-one
                label="Invoice by address"
                field="$ctrl.client.hasToInvoiceByAddress">
            </vn-check>
        </vn-horizontal>
        <vn-horizontal pad-small-v>
            <vn-check
                vn-one
                label="Is equalizated"
                field="$ctrl.client.isEqualizated"
                info="In order to invoice, this field is not consulted, but the consignee's ET. When modifying this field if the invoice by address option is not checked, the change will be automatically propagated to all addresses, otherwise the user will be asked if he wants to propagate it or not.">
            </vn-check>
            <vn-check
                vn-one
                label="Verified data"
                field="$ctrl.client.isTaxDataChecked"
                vn-acl="salesAssistant">
            </vn-check>
        </vn-horizontal>
    </vn-card>
    <vn-button-bar>
        <vn-submit label="Save"></vn-submit>
        <vn-button label="Undo changes" ng-if="$ctrl.$.form.$dirty" ng-click="watcher.loadOriginalData()"></vn-button>
    </vn-button-bar>
</form>
<vn-confirm 
    vn-id="propagate-isEqualizated"
    question="You changed the equalization tax"
    message="Do you want to spread the change?"
    on-response="$ctrl.returnDialogEt(response)">
</vn-confirm>