refs #5768 incoterms addressFk
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Satorres 2023-10-03 10:15:16 +02:00
parent 5b22314b07
commit bd46a77cb7
7 changed files with 95 additions and 15 deletions

View File

@ -13,6 +13,7 @@
'description',
'model',
'hasCompany',
'hasAddress',
'hasPreview',
'datepickerEnabled'
]"
@ -69,15 +70,31 @@
ng-if="sampleType.selection.hasCompany"
required="true">
</vn-autocomplete>
<!-- <vn-autocomplete
ng-model="$ctrl.addressId"
<vn-autocomplete
vn-one
required="true"
data="$ctrl.addresses"
label="Address"
show-field="nickname"
value-field="id"
label="Consignatario"
ng-if="sampleType.selection.hasCompany"
required="true">
</vn-autocomplete> -->
ng-model="$ctrl.addressId"
model="ClientSample.addressFk"
order="isActive DESC">
<tpl-item class="address" ng-class="::{inactive: !isActive}">
<span class="inactive" translate>{{::!isActive ? '(Inactive)' : ''}}</span>
{{::nickname}}
<span ng-show="city || province || street">
, {{::street}}, {{::city}}, {{::province.name}} - {{::agencyMode.name}}
</span>
</tpl-item>
<append>
<vn-icon-button
ui-sref="client.card.address.edit({id: $ctrl.clientId, addressId: $ctrl.addressId})"
icon="edit"
vn-tooltip="Edit address">
</vn-icon-button>
</append>
</vn-autocomplete>
<vn-date-picker
vn-one
label="From"

View File

@ -15,8 +15,10 @@ class Controller extends Section {
set client(value) {
this._client = value;
if (value)
if (value) {
this.setClientSample(value);
this.clientAddressesList(value.id);
}
}
get companyId() {
@ -29,6 +31,16 @@ class Controller extends Section {
this.clientSample.companyFk = value;
}
get addressId() {
if (!this.clientSample.addressId)
this.clientSample.addressId = this.client.defaultAddressFk;
return this.clientSample.addressId;
}
set addressId(value) {
this.clientSample.addressId = value;
}
onSubmit() {
this.$.watcher.check();
@ -65,6 +77,11 @@ class Controller extends Section {
if (sampleType.datepickerEnabled)
params.from = this.clientSample.from;
if (this.clientSample.addressId)
params.addressId = this.clientSample.addressId;
console.log(this.clientSample);
}
preview() {
@ -126,6 +143,43 @@ class Controller extends Section {
};
});
}
/*
* Autocompletes address on client change
*/
clientAddressesList(value) {
let filter = {
include: [
{
relation: 'province',
scope: {
fields: ['name']
}
},
{
relation: 'agencyMode',
scope: {
fields: ['name']
}
}
]
};
filter = encodeURIComponent(JSON.stringify(filter));
let query = `Clients/${value}/addresses?filter=${filter}`;
this.$http.get(query).then(res => {
if (res.data)
this.addresses = res.data;
});
}
getClientDefaultAddress(value) {
let query = `Clients/${value}`;
this.$http.get(query).then(res => {
if (res.data)
this.addressId = res.data.defaultAddressFk;
});
}
}
Controller.$inject = ['$element', '$scope', 'vnEmail'];

View File

@ -5,7 +5,7 @@
v-html="$t('description', {
socialName: client.socialName,
name: client.name,
address: client.street,
addressId: address.street,
country: client.country,
fiscalID: client.fi
})"
@ -21,8 +21,7 @@
companyName: company.name,
companyCity: company.city,
socialName: client.socialName,
destinationCountry: client.country,
incotermsFk: address.incotermsFk
destinationCountry: client.country
})"
></p>

View File

@ -7,6 +7,7 @@ module.exports = {
this.client = await this.findOneFromDef('client', [this.id]);
this.checkMainEntity(this.client);
this.company = await this.findOneFromDef('company', [this.companyId]);
this.address = await this.findOneFromDef('address', [this.addressId]);
},
props: {
id: {
@ -18,8 +19,8 @@ module.exports = {
type: Number,
required: true
},
address: {
type: String
addressId: {
type: Number
}
}
};

View File

@ -6,7 +6,7 @@ issued: 'En {0}, a {1} de {2} de {3}'
client: 'Cliente {0}'
declaration: '<em>{socialName}</em> declara por la presente que:'
declarations:
- 'Todas las compras realizadas por {socialName} con {companyName} se entregan según las condiciones definidas en el incoterm {incotermsFk} ({Incoterm description}).'
- 'Todas las compras realizadas por {socialName} con {companyName} se entregan según las condiciones definidas en el incoterm.'
- '{socialName} reconoce que es importante para {companyName} tener
comprobante de la entrega intracomunitaria de la mercancía a {destinationCountry} para
poder facturar con 0% de IVA.'

View File

@ -0,0 +1,9 @@
SELECT
a.nickname,
a.street,
a.postalCode,
a.city,
p.name province
FROM address a
LEFT JOIN province p ON p.id = a.provinceFk
WHERE a.id = ?