merge
This commit is contained in:
commit
539be92e39
|
@ -10,7 +10,7 @@ module.component(NAME, COMPONENT);
|
||||||
vnAppInterceptor.$inject = ['$q', '$rootScope', '$document'];
|
vnAppInterceptor.$inject = ['$q', '$rootScope', '$document'];
|
||||||
function vnAppInterceptor($q, $rootScope, $document) {
|
function vnAppInterceptor($q, $rootScope, $document) {
|
||||||
$rootScope.loading = false;
|
$rootScope.loading = false;
|
||||||
function showMessage (message) {
|
function showMessage(message) {
|
||||||
let snackbar = $document.find('vn-snackbar').controller('vnSnackbar');
|
let snackbar = $document.find('vn-snackbar').controller('vnSnackbar');
|
||||||
snackbar.show({message: message});
|
snackbar.show({message: message});
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,7 @@ function vnAppInterceptor($q, $rootScope, $document) {
|
||||||
return $q.reject(rejection);
|
return $q.reject(rejection);
|
||||||
},
|
},
|
||||||
response: function(response) {
|
response: function(response) {
|
||||||
switch(response.config.method)
|
switch (response.config.method) {
|
||||||
{
|
|
||||||
case 'PUT':
|
case 'PUT':
|
||||||
case 'POST':
|
case 'POST':
|
||||||
showMessage('Data saved!');
|
showMessage('Data saved!');
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-combo vn-one label="Comercial" field="basicData.client.salesPerson">
|
<vn-combo vn-one label="Comercial" field="basicData.client.salesPerson">
|
||||||
|
<option value=""></option>
|
||||||
<option ng-repeat="p in basicData.sales" value="{{p.id}}">{{p.name}}</ng-repeat>
|
<option ng-repeat="p in basicData.sales" value="{{p.id}}">{{p.name}}</ng-repeat>
|
||||||
</vn-combo>
|
</vn-combo>
|
||||||
<vn-two></vn-two>
|
<vn-two></vn-two>
|
||||||
|
|
|
@ -8,42 +8,54 @@ export const COMPONENT = {
|
||||||
bindings: {
|
bindings: {
|
||||||
client: '<'
|
client: '<'
|
||||||
},
|
},
|
||||||
controller: function($http, copyObject, equalsObject, $transitions, $state) {
|
controller: function($http, copyObject, equalsObject, $transitions, $element) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var deregister = $transitions.onStart({ }, callback);
|
var deregister = $transitions.onStart({ }, callback);
|
||||||
|
|
||||||
this.$onChanges = function (changes) {
|
this.$onChanges = function(changes) {
|
||||||
if(this.client){
|
if (this.client) {
|
||||||
this.clientOld = copyObject(this.client);
|
this.copyClient();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.$onDestroy = function(){
|
this.$onDestroy = function() {
|
||||||
deregister();
|
deregister();
|
||||||
}
|
};
|
||||||
|
|
||||||
$http.get('/client/api/SalesPeople').then(
|
$http.get('/client/api/SalesPeople').then(
|
||||||
json => this.sales = json.data
|
json => {
|
||||||
|
this.sales = json.data;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
function callback(transition) {
|
function callback(transition) {
|
||||||
if(!equalsObject(self.client, self.clientOld)){
|
if (!equalsObject(self.client, self.clientOld)) {
|
||||||
self.state = transition.to().name;
|
self.state = transition.to().name;
|
||||||
var dialog = document.querySelector('dialog');
|
var dialog = $element[0].querySelector('dialog');
|
||||||
dialog.showModal();
|
dialog.showModal();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.submit = function() {
|
this.submit = function() {
|
||||||
if(!equalsObject(this.client, this.clientOld)){
|
if (!equalsObject(this.client, this.clientOld)) {
|
||||||
this.client.modify = "BasicData";
|
this.client.modify = "BasicData";
|
||||||
$http.put('/client/api/Clients', this.client);
|
$http.put('/client/api/Clients', this.client).then(
|
||||||
|
json => {
|
||||||
|
this.client = json.data;
|
||||||
|
this.copyClient();
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.copyClient = function() {
|
||||||
|
this.clientOld = {};
|
||||||
|
copyObject(this.client, this.clientOld);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
COMPONENT.controller.$inject = ['$http', 'copyObject', 'equalsObject', '$transitions', '$state'];
|
|
||||||
|
COMPONENT.controller.$inject = ['$http', 'copyObject', 'equalsObject', '$transitions', '$element'];
|
||||||
module.component(NAME, COMPONENT);
|
module.component(NAME, COMPONENT);
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<dialog class="mdl-dialog">
|
<dialog class="mdl-dialog">
|
||||||
<div class="mdl-dialog__content">
|
<div class="mdl-dialog__content">
|
||||||
<p>
|
<p>
|
||||||
Allow this site to collect usage data to improve your experience?
|
¿Desea salir sin guardar?
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="mdl-dialog__actions mdl-dialog__actions--full-width">
|
<div class="mdl-dialog__actions mdl-dialog__actions--full-width">
|
||||||
<button type="button" class="mdl-button" ng-click="clientConfirm.accept()">Agree</button>
|
<button type="button" class="mdl-button" ng-click="clientConfirm.accept()">Aceptar</button>
|
||||||
<button type="button" class="mdl-button close" ng-click="clientConfirm.cancel()">Disagree</button>
|
<button type="button" class="mdl-button close" ng-click="clientConfirm.cancel()">Cancelar</button>
|
||||||
</div>
|
</div>
|
||||||
</dialog>
|
</dialog>
|
|
@ -1,6 +1,6 @@
|
||||||
<form ng-submit="create.submit()" pad-large style="max-width: 67em; margin: 0 auto;">
|
<form ng-submit="create.submit()" pad-large style="max-width: 67em; margin: 0 auto;">
|
||||||
<vn-card>
|
<vn-card>
|
||||||
<vn-vertical pad-large>
|
<vn-vertical pad-large>
|
||||||
<vn-title>Crear Cliente</vn-title>
|
<vn-title>Crear Cliente</vn-title>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-textfield vn-one label="Nombre" field="create.model.name" focus></vn-textfield>
|
<vn-textfield vn-one label="Nombre" field="create.model.name" focus></vn-textfield>
|
||||||
|
@ -15,6 +15,7 @@
|
||||||
<vn-submit label="Crear" id="create"></vn-submit>
|
<vn-submit label="Crear" id="create"></vn-submit>
|
||||||
</vn-one>
|
</vn-one>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
</vn-vertical>
|
</vn-vertical>
|
||||||
</vn-card>
|
</vn-card>
|
||||||
</form>
|
</form>
|
||||||
|
<vn-confirm-client client="create.model" client-old="create.model" state="create.state"></vn-confirm-client>
|
||||||
|
|
|
@ -5,8 +5,8 @@ export const NAME = "vnClientCreate";
|
||||||
export const COMPONENT = {
|
export const COMPONENT = {
|
||||||
template: template,
|
template: template,
|
||||||
controllerAs: "create",
|
controllerAs: "create",
|
||||||
controller: function($http, $state){
|
controller: function($http, $state) {
|
||||||
this.submit = function(){
|
this.submit = function() {
|
||||||
$http.post('/client/api/Clients', this.model).then(
|
$http.post('/client/api/Clients', this.model).then(
|
||||||
json => $state.go('clientCard.basicData',{id: json.data.id})
|
json => $state.go('clientCard.basicData',{id: json.data.id})
|
||||||
);
|
);
|
||||||
|
|
|
@ -32,17 +32,17 @@
|
||||||
<vn-vertical pad-large>
|
<vn-vertical pad-large>
|
||||||
<vn-title>Información de facturación</vn-title>
|
<vn-title>Información de facturación</vn-title>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
|
<vn-textfield vn-two label="IBAN" field="fiscal.client.iban"></vn-textfield>
|
||||||
<vn-combo vn-two label="Forma de pago" field="fiscal.client.payMethod">
|
<vn-combo vn-two label="Forma de pago" field="fiscal.client.payMethod">
|
||||||
<option ng-repeat="p in fiscal.payments" value="{{p.id}}">{{p.name}}</option>
|
<option ng-repeat="p in fiscal.payments" value="{{p.id}}">{{p.name}}</option>
|
||||||
</vn-combo>
|
</vn-combo>
|
||||||
<vn-textfield vn-one label="Vencimiento" field="fiscal.client.dueDay"></vn-textfield>
|
<vn-textfield vn-one label="Vencimiento" field="fiscal.client.dueDay"></vn-textfield>
|
||||||
<vn-check vn-three label="Recargo de equivalencia" field="fiscal.client.surcharge"></vn-check>
|
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-textfield vn-one label="Crédito" field="fiscal.client.credit"></vn-textfield>
|
<vn-textfield vn-one label="Crédito" field="fiscal.client.credit"></vn-textfield>
|
||||||
<vn-textfield vn-one label="CyC" field="fiscal.client.cyc"></vn-textfield>
|
<vn-textfield vn-one label="CyC" field="fiscal.client.cyc"></vn-textfield>
|
||||||
<vn-textfield vn-one label="IAE" field="fiscal.client.gestdoc"></vn-textfield>
|
<vn-textfield vn-one label="IAE" field="fiscal.client.gestdoc"></vn-textfield>
|
||||||
<vn-textfield vn-three label="IBAN" field="fiscal.client.iban"></vn-textfield>
|
<vn-check vn-two label="Recargo de equivalencia" field="fiscal.client.surcharge"></vn-check>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
</vn-vertical>
|
</vn-vertical>
|
||||||
</vn-card>
|
</vn-card>
|
||||||
|
@ -62,3 +62,4 @@
|
||||||
</vn-vertical>
|
</vn-vertical>
|
||||||
<vn-card>
|
<vn-card>
|
||||||
</form>
|
</form>
|
||||||
|
<vn-confirm-client client="fiscal.client" client-old="fiscal.clientOld" state="fiscal.state"></vn-confirm-client>
|
|
@ -8,22 +8,60 @@ export const COMPONENT = {
|
||||||
bindings: {
|
bindings: {
|
||||||
client: '<'
|
client: '<'
|
||||||
},
|
},
|
||||||
controller: function($http) {
|
controller: function($http, copyObject, equalsObject, $transitions, $element) {
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
var deregister = $transitions.onStart({ }, callback);
|
||||||
|
|
||||||
$http.get('/client/api/Countries').then(
|
$http.get('/client/api/Countries').then(
|
||||||
json => this.countries = json.data
|
json => this.countries = json.data
|
||||||
);
|
);
|
||||||
|
|
||||||
$http.get('/client/api/Provinces').then(
|
$http.get('/client/api/Provinces').then(
|
||||||
json => this.provinces = json.data
|
json => this.provinces = json.data
|
||||||
);
|
);
|
||||||
|
|
||||||
$http.get('/client/api/PaymentMethods').then(
|
$http.get('/client/api/PaymentMethods').then(
|
||||||
json => this.payments = json.data
|
json => this.payments = json.data
|
||||||
);
|
);
|
||||||
|
|
||||||
this.submit = function() {
|
this.submit = function() {
|
||||||
$http.put('/client/api/Clients', this.client);
|
if (!equalsObject(this.client, this.clientOld)) {
|
||||||
|
this.client.modify = "FiscalData";
|
||||||
|
$http.put('/client/api/Clients', this.client).then(
|
||||||
|
json => {
|
||||||
|
this.client = json.data;
|
||||||
|
this.copyClient();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$onChanges = function(changes) {
|
||||||
|
if (this.client) {
|
||||||
|
this.copyClient();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$onDestroy = function() {
|
||||||
|
deregister();
|
||||||
|
};
|
||||||
|
|
||||||
|
function callback(transition) {
|
||||||
|
if (!equalsObject(self.client, self.clientOld)) {
|
||||||
|
self.state = transition.to().name;
|
||||||
|
var dialog = $element[0].querySelector('dialog');
|
||||||
|
dialog.showModal();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.copyClient = function() {
|
||||||
|
this.clientOld = {};
|
||||||
|
copyObject(this.client, this.clientOld);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
COMPONENT.controller.$inject = ['$http'];
|
COMPONENT.controller.$inject = ['$http', 'copyObject', 'equalsObject', '$transitions', '$element'];
|
||||||
module.component(NAME, COMPONENT);
|
module.component(NAME, COMPONENT);
|
||||||
|
|
||||||
|
|
|
@ -8,3 +8,4 @@
|
||||||
</vn-vertical>
|
</vn-vertical>
|
||||||
</vn-card>
|
</vn-card>
|
||||||
</form>
|
</form>
|
||||||
|
<vn-confirm-client client="web.client" client-old="web.clientOld" state="web.state"></vn-confirm-client>
|
|
@ -8,11 +8,47 @@ export const COMPONENT = {
|
||||||
bindings: {
|
bindings: {
|
||||||
client: '<'
|
client: '<'
|
||||||
},
|
},
|
||||||
controller: function($http) {
|
controller: function($http, copyObject, equalsObject, $transitions, $element) {
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
var deregister = $transitions.onStart({ }, callback);
|
||||||
|
|
||||||
this.submit = function() {
|
this.submit = function() {
|
||||||
$http.put('/client/api/Clients', this.client);
|
if (!equalsObject(this.client, this.clientOld)) {
|
||||||
|
this.client.modify = "WebAccess";
|
||||||
|
$http.put('/client/api/Clients', this.client).then(
|
||||||
|
json => {
|
||||||
|
this.client = json.data;
|
||||||
|
this.copyClient();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$onChanges = function(changes) {
|
||||||
|
if (this.client) {
|
||||||
|
this.copyClient();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.$onDestroy = function() {
|
||||||
|
deregister();
|
||||||
|
};
|
||||||
|
|
||||||
|
function callback(transition) {
|
||||||
|
if (!equalsObject(self.client, self.clientOld)) {
|
||||||
|
self.state = transition.to().name;
|
||||||
|
var dialog = $element[0].querySelector('dialog');
|
||||||
|
dialog.showModal();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.copyClient = function() {
|
||||||
|
this.clientOld = {};
|
||||||
|
copyObject(this.client, this.clientOld);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
COMPONENT.controller.$inject = ['$http'];
|
COMPONENT.controller.$inject = ['$http', 'copyObject', 'equalsObject', '$transitions', '$element'];
|
||||||
module.component(NAME, COMPONENT);
|
module.component(NAME, COMPONENT);
|
||||||
|
|
11
db.json
11
db.json
|
@ -2,7 +2,7 @@
|
||||||
"ids": {
|
"ids": {
|
||||||
"User": 2,
|
"User": 2,
|
||||||
"AccessToken": 2,
|
"AccessToken": 2,
|
||||||
"Client": 15,
|
"Client": 16,
|
||||||
"PaymentMethod": 4,
|
"PaymentMethod": 4,
|
||||||
"SalesPerson": 4,
|
"SalesPerson": 4,
|
||||||
"Address": 58,
|
"Address": 58,
|
||||||
|
@ -18,8 +18,9 @@
|
||||||
"NUf7o684TmteojFX9KmPOpaDLthjP5Def4wuy83Yjv31i43HHiWgV3FyBp6pX8Ue": "{\"id\":\"NUf7o684TmteojFX9KmPOpaDLthjP5Def4wuy83Yjv31i43HHiWgV3FyBp6pX8Ue\",\"ttl\":1209600,\"created\":\"2016-11-21T11:06:11.113Z\",\"userId\":1}"
|
"NUf7o684TmteojFX9KmPOpaDLthjP5Def4wuy83Yjv31i43HHiWgV3FyBp6pX8Ue": "{\"id\":\"NUf7o684TmteojFX9KmPOpaDLthjP5Def4wuy83Yjv31i43HHiWgV3FyBp6pX8Ue\",\"ttl\":1209600,\"created\":\"2016-11-21T11:06:11.113Z\",\"userId\":1}"
|
||||||
},
|
},
|
||||||
"Client": {
|
"Client": {
|
||||||
"12": "{\"name\":\"Verdnatura\",\"id\":12,\"fi\":\"B97367486\",\"salesPerson\":\"2\",\"telefono\":\"963242100\",\"socialName\":\"Verdnatura Levante SL\",\"active\":true,\"user\":\"verdnatura\",\"fax\":\"963242100\",\"phone\":\"963242100\",\"email\":\"informatica@verdnatura.es\",\"surcharge\":true,\"cyc\":2345,\"credit\":1000,\"iban\":\"2352345234523452345\",\"street\":\"Avenida Espioca, 100\",\"city\":\"Silla\",\"postcode\":\"46013\",\"mobile\":\"654654654\",\"dueDay\":4,\"gestdoc\":23452343,\"province\":1,\"country\":\"1\",\"modify\":\"BasicData\",\"navigate\":true}",
|
"12": "{\"name\":\"Verdnatura\",\"id\":12,\"fi\":\"B97367486\",\"salesPerson\":\"1\",\"telefono\":\"963242100\",\"socialName\":\"Verdnatura Levante SL\",\"active\":true,\"user\":\"verdnatura\",\"fax\":\"963242100\",\"phone\":\"963242101\",\"email\":\"informatica@verdnatura.es\",\"surcharge\":true,\"cyc\":2345,\"credit\":1000,\"iban\":\"456\",\"street\":\"Avenida Espioca, 100\",\"city\":\"Silla\",\"postcode\":\"46013\",\"mobile\":\"654654654\",\"dueDay\":10,\"gestdoc\":23452343,\"province\":\"2\",\"country\":\"1\",\"modify\":\"BasicData\",\"navigate\":true,\"payMethod\":\"1\"}",
|
||||||
"14": "{\"name\":\"Cliente 1\",\"id\":14,\"street\":\"Aaaaaaaaaa\",\"fi\":\"1234567890A\",\"socialName\":\"Cliente 1\",\"fax\":\"963242100\",\"dischargeDate\":\"01/01/2017\",\"telefono\":\"963242100\",\"salesPerson\":\"2\",\"email\":\"informatica@verdnatura.es\",\"city\":\"asdf\",\"postcode\":\"asdf\",\"phone\":\"asdf\",\"mobile\":\"asdf\",\"credit\":2345,\"cyc\":123,\"iban\":\"asdf\",\"dueDay\":345,\"gestdoc\":2435,\"surcharge\":true,\"navigate\":true}"
|
"14": "{\"name\":\"Cliente 1\",\"id\":14,\"street\":\"Aaaaaaaaaa\",\"fi\":\"1234567890A\",\"socialName\":\"Cliente 1\",\"fax\":\"963242100\",\"dischargeDate\":\"01/01/2017\",\"telefono\":\"963242100\",\"salesPerson\":\"2\",\"email\":\"informatica@verdnatura.es\",\"city\":\"asdf\",\"postcode\":\"asdf\",\"phone\":\"asdf\",\"mobile\":\"asdf\",\"credit\":2345,\"cyc\":123,\"iban\":\"asdf\",\"dueDay\":345,\"gestdoc\":2435,\"surcharge\":true,\"navigate\":true}",
|
||||||
|
"15": "{\"name\":\"afsdf\",\"fi\":\"12341234rasf\",\"socialName\":\"asdfasd\",\"dueDay\":5,\"id\":15,\"payMethod\":\"2\",\"salesPerson\":\"1\",\"modify\":\"BasicData\",\"iban\":\"sdfgsdfgsdfg\"}"
|
||||||
},
|
},
|
||||||
"PaymentMethod": {
|
"PaymentMethod": {
|
||||||
"1": "{\"name\":\"Tarjeta\",\"id\":1}",
|
"1": "{\"name\":\"Tarjeta\",\"id\":1}",
|
||||||
|
@ -32,8 +33,8 @@
|
||||||
"3": "{\"name\":\"Carlos Zambrano\",\"id\":3}"
|
"3": "{\"name\":\"Carlos Zambrano\",\"id\":3}"
|
||||||
},
|
},
|
||||||
"Address": {
|
"Address": {
|
||||||
"57": "{\"street\":\"Avda Espioca\",\"consignee\":\"Vicente\",\"city\":\"Silla\",\"postcode\":\"46900\",\"phone\":\"963242100\",\"province\":\"1\",\"agency\":\"3\",\"id\":57,\"enabled\":false,\"default\":true}",
|
"57": "{\"street\":\"Avda Espioca\",\"consignee\":\"Vicente\",\"city\":\"Silla\",\"postcode\":\"46900\",\"phone\":\"963242100\",\"province\":\"1\",\"agency\":\"3\",\"id\":57,\"enabled\":true,\"default\":true}",
|
||||||
"63": "{\"street\":\"Avd. Espioca nº 100\",\"consignee\":\"Verndatura Silla\",\"city\":\"Silla\",\"postcode\":\"46460\",\"phone\":\"66666666\",\"mobile\":\"989898888\",\"id\":63,\"province\":\"2\",\"agency\":\"3\",\"default\":false,\"enabled\":true}",
|
"63": "{\"street\":\"Avd. Espioca nº 100\",\"consignee\":\"Verndatura Silla\",\"city\":\"Silla\",\"postcode\":\"46460\",\"phone\":\"66666666\",\"mobile\":\"989898888\",\"id\":63,\"province\":\"2\",\"agency\":\"3\",\"default\":false,\"enabled\":false}",
|
||||||
"64": "{\"street\":\"Aaa\",\"consignee\":\"aaa\",\"city\":\"121212\",\"postcode\":\"11111\",\"phone\":\"963242100\",\"mobile\":\"11231241423\",\"id\":64,\"default\":false,\"province\":\"1\",\"agency\":\"2\",\"enabled\":false}"
|
"64": "{\"street\":\"Aaa\",\"consignee\":\"aaa\",\"city\":\"121212\",\"postcode\":\"11111\",\"phone\":\"963242100\",\"mobile\":\"11231241423\",\"id\":64,\"default\":false,\"province\":\"1\",\"agency\":\"2\",\"enabled\":false}"
|
||||||
},
|
},
|
||||||
"Country": {
|
"Country": {
|
||||||
|
|
|
@ -1,14 +1,36 @@
|
||||||
module.exports = function(Client) {
|
module.exports = function(Client) {
|
||||||
|
//validations
|
||||||
|
Client.validatesUniquenessOf('name', {message: 'el nombre debe ser unico'});
|
||||||
|
Client.validatesUniquenessOf('fi', {message: 'el nif/cif debe ser unico'});
|
||||||
|
|
||||||
// prueba uno
|
Client.validate('payMethod',hasCC,{message: 'Introduzca el iban del cliente'});
|
||||||
// Client.validatesUniquenessOf('name', {message: 'el nombre debe ser unico'});
|
|
||||||
|
|
||||||
// prueba dos
|
|
||||||
Client.validate('name',hasCC,{message: 'Introducir cuenta bancaria'});
|
|
||||||
|
|
||||||
function hasCC(err) {
|
function hasCC(err) {
|
||||||
if (this.payMethod == 2) err();
|
if (this.payMethod == 2 && !this.iban) err();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Client.validate('payMethod',hasSalesMan,{message: 'No se puede cambiar la forma de pago si no hay comercial asignado'});
|
||||||
|
function hasSalesMan(err) {
|
||||||
|
if (this.payMethod && !this.salesPerson) err();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks
|
||||||
|
Client.observe('before save', function (ctx, next) {
|
||||||
|
if (ctx.instance) {
|
||||||
|
if (!ctx.instance.dueDay){
|
||||||
|
ctx.instance.dueDay = 5;
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
} else {
|
||||||
|
Client.findById(ctx.where.id,
|
||||||
|
function(err, item) {
|
||||||
|
if (!err) {
|
||||||
|
if (item.payMethod != ctx.data.payMethod && item.dueDay == ctx.data.dueDay) {
|
||||||
|
ctx.data.dueDay = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
Loading…
Reference in New Issue