#1022 ticket.create

This commit is contained in:
Gerard 2019-01-25 11:58:50 +01:00
parent e55bcaecfd
commit 6e6b646978
9 changed files with 91 additions and 11 deletions

View File

@ -43,7 +43,7 @@ class Controller {
set warehouseFk(value) { set warehouseFk(value) {
this.warehouse = value; this.warehouse = value;
if (!window.localStorage.defaultWarehouseFk) if (value && !window.localStorage.localWarehouseFk)
window.localStorage.defaultWarehouseFk = value; window.localStorage.defaultWarehouseFk = value;
this.setUserConfig('warehouseFk', value); this.setUserConfig('warehouseFk', value);
} }
@ -54,7 +54,7 @@ class Controller {
set companyFk(value) { set companyFk(value) {
this.company = value; this.company = value;
if (!window.localStorage.defaultCompanyFk) if (value && !window.localStorage.localCompanyFk)
window.localStorage.defaultCompanyFk = value; window.localStorage.defaultCompanyFk = value;
this.setUserConfig('companyFk', value); this.setUserConfig('companyFk', value);
} }
@ -80,13 +80,13 @@ class Controller {
.then(res => { .then(res => {
if (res.data && res.data.warehouseFk) { if (res.data && res.data.warehouseFk) {
this.warehouse = res.data.warehouseFk; this.warehouse = res.data.warehouseFk;
if (!window.localStorage.defaultWarehouseFk || window.localStorage.defaultWarehouseFk === 'null') if (res.data.warehouseFk && !window.localStorage.localWarehouseFk)
window.localStorage.defaultWarehouseFk = res.data.warehouseFk; window.localStorage.defaultWarehouseFk = res.data.warehouseFk;
} }
if (res.data && res.data.companyFk) { if (res.data && res.data.companyFk) {
this.company = res.data.companyFk; this.company = res.data.companyFk;
if (!window.localStorage.defaultCompanyFk || window.localStorage.defaultCompanyFk === 'null') if (res.data.companyFk && !window.localStorage.localCompanyFk)
window.localStorage.defaultCompanyFk = res.data.companyFk; window.localStorage.defaultCompanyFk = res.data.companyFk;
} }
}); });

View File

@ -0,0 +1,28 @@
module.exports = Self => {
Self.remoteMethod('getLanded', {
description: 'Returns the first shipped and landed possible for params',
accessType: 'READ',
accepts: [{
arg: 'params',
type: 'object',
required: true,
description: 'shipped, addressFk, agencyModeFk, warehouseFk'
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/getLanded`,
verb: 'get'
}
});
Self.getLanded = async params => {
let query = `CALL vn.agencyHourGetLanded(?, ?, ?, ?);
SELECT * FROM tmp.agencyHourGetLanded`;
let result = await Self.rawSql(query, [params.shipped, params.addressFk || null, params.agencyModeFk, params.warehouseFk]);
return result[1][0].landed;
};
};

View File

@ -0,0 +1,28 @@
module.exports = Self => {
Self.remoteMethod('getShipped', {
description: 'Returns the first shipped possible for params',
accessType: 'READ',
accepts: [{
arg: 'params',
type: 'object',
required: true,
description: 'landed, addressFk, agencyModeFk'
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/getShipped`,
verb: 'get'
}
});
Self.getShipped = async params => {
let query = `CALL vn.agencyHourGetShipped(?, ?, ?);
SELECT * FROM tmp.agencyHourGetShipped`;
let result = await Self.rawSql(query, [params.landed, params.addressFk, params.agencyModeFk]);
return result[1][0].shipped;
};
};

View File

@ -2,4 +2,6 @@ module.exports = Self => {
require('../methods/agency/landsThatDay')(Self); require('../methods/agency/landsThatDay')(Self);
require('../methods/agency/getFirstShipped')(Self); require('../methods/agency/getFirstShipped')(Self);
require('../methods/agency/getAgenciesWithWarehouse')(Self); require('../methods/agency/getAgenciesWithWarehouse')(Self);
require('../methods/agency/getLanded')(Self);
require('../methods/agency/getShipped')(Self);
}; };

View File

@ -23,9 +23,8 @@ class Controller {
if (this.$stateParams.amountPaid) if (this.$stateParams.amountPaid)
this.receipt.amountPaid = this.$stateParams.amountPaid; this.receipt.amountPaid = this.$stateParams.amountPaid;
if (this.$stateParams.companyFk) { if (this.$stateParams.companyFk)
this.receipt.companyFk = this.$stateParams.companyFk; this.receipt.companyFk = this.$stateParams.companyFk;
}
} }
$onInit() { $onInit() {

View File

@ -57,6 +57,24 @@ module.exports = Self => {
throw new UserError(`You can't create a ticket for a client that has a debt`); throw new UserError(`You can't create a ticket for a client that has a debt`);
} }
if (!params.shipped && params.landed) {
params.shipped = await Self.app.models.Agency.getShipped({
landed: params.landed,
addressFk: address.id,
agencyModeFk: params.agencyModeFk
});
}
if (params.shipped && !params.landed) {
params.landed = await Self.app.models.Agency.getLanded({
shipped: params.shipped,
addressFk: address.id,
agencyModeFk: params.agencyModeFk,
warehouseFk: params.warehouseFk
});
}
if (!params.userId && ctx.req && ctx.req.accessToken.userId) if (!params.userId && ctx.req && ctx.req.accessToken.userId)
params.userId = ctx.req.accessToken.userId; params.userId = ctx.req.accessToken.userId;

View File

@ -1,7 +1,7 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
describe('ticket filter()', () => { describe('ticket filter()', () => {
it('should call the filter method', async () => { it('should call the filter method', async() => {
let ctx = {req: {accessToken: {userId: 9}}}; let ctx = {req: {accessToken: {userId: 9}}};
let filter = {order: 'shipped DESC'}; let filter = {order: 'shipped DESC'};

View File

@ -27,7 +27,7 @@
ini-options="{enableTime: false}"> ini-options="{enableTime: false}">
</vn-date-picker> </vn-date-picker>
<vn-autocomplete <vn-autocomplete
disabled="!$ctrl.clientFk || !$ctrl.landed" disabled="!$ctrl.warehouseFk && (!$ctrl.clientFk || !$ctrl.landed)"
field="$ctrl.warehouseFk" field="$ctrl.warehouseFk"
url="/agency/api/Warehouses" url="/agency/api/Warehouses"
show-field="name" show-field="name"

View File

@ -14,6 +14,9 @@ class Controller {
$onInit() { $onInit() {
if (this.$stateParams && this.$stateParams.clientFk) if (this.$stateParams && this.$stateParams.clientFk)
this.clientFk = this.$stateParams.clientFk; this.clientFk = this.$stateParams.clientFk;
if (window.localStorage && window.localStorage.defaultWarehouseFk)
this.warehouseFk = parseInt(window.localStorage.defaultWarehouseFk);
} }
set ticket(value) { set ticket(value) {
@ -37,6 +40,7 @@ class Controller {
}); });
} else } else
this.addressFk = null; this.addressFk = null;
this.getAvailableAgencies();
} }
get clientFk() { get clientFk() {
@ -45,6 +49,7 @@ class Controller {
set addressFk(value) { set addressFk(value) {
this.ticket.addressFk = value; this.ticket.addressFk = value;
this.getAvailableAgencies();
} }
get addressFk() { get addressFk() {
@ -53,6 +58,7 @@ class Controller {
set landed(value) { set landed(value) {
this.ticket.landed = value; this.ticket.landed = value;
this.getAvailableAgencies();
} }
get landed() { get landed() {
@ -67,10 +73,9 @@ class Controller {
return this.ticket.warehouseFk; return this.ticket.warehouseFk;
} }
getAvailableAgencies() { getAvailableAgencies() {
this.ticket.agencyModeFk = null; if (this.ticket.warehouseFk && this.ticket.addressFk && this.ticket.landed && this.ticket.clientFk) {
if (this.ticket.landed && this.ticket.addressFk) { this.ticket.agencyModeFk = null;
let filter = {warehouseFk: this.ticket.warehouseFk, addressFk: this.ticket.addressFk, landed: this.ticket.landed}; let filter = {warehouseFk: this.ticket.warehouseFk, addressFk: this.ticket.addressFk, landed: this.ticket.landed};
filter = encodeURIComponent(JSON.stringify(filter)); filter = encodeURIComponent(JSON.stringify(filter));
let query = `/api/Agencies/getAgenciesWithWarehouse?filter=${filter}`; let query = `/api/Agencies/getAgenciesWithWarehouse?filter=${filter}`;