This commit is contained in:
Carlos Jimenez Ruiz 2019-11-18 12:35:30 +01:00
commit 3c2ad2df48
27 changed files with 67 additions and 424 deletions

View File

@ -28,7 +28,7 @@ BEGIN
JOIN zone z ON z.id = zo.zoneFk
JOIN zoneWarehouse zw ON zw.zoneFk = z.id
WHERE agencyModeFk = vAgencyModeFk
AND warehouseFk = vWarehouseFk;
AND zw.warehouseFk = vWarehouseFk;
DROP TEMPORARY TABLE
tmp.zone,

View File

@ -0,0 +1,3 @@
USE `vn`;
CREATE DEFINER=`root`@`%` EVENT `department_doCalc` ON SCHEDULE EVERY 15 SECOND STARTS '2019-11-15 00:00:00' ON COMPLETION PRESERVE ENABLE DO CALL vn.department_doCalc

View File

@ -47,6 +47,7 @@ module.exports = Self => {
let rsIndex = stmts.push(
`SELECT * FROM tmp.zoneGetLanded`) - 1;
stmts.push(`DROP TEMPORARY TABLE tmp.zoneGetLanded`);
let sql = ParameterizedSQL.join(stmts, ';');
let landed = await Self.rawStmt(sql);

View File

@ -1,8 +1,9 @@
const app = require('vn-loopback/server/server');
// Petición #1848
xdescribe('agency getLanded()', () => {
describe('agency getLanded()', () => {
it('should return a landing date', async() => {
const shipped = new Date();
shipped.setDate(shipped.getDate() + 1);
const addressFk = 121;
const agencyModeFk = 7;
const warehouseFk = 1;

View File

@ -1,10 +1,9 @@
const app = require('vn-loopback/server/server');
// Petición #1848
xdescribe('agency getShipped()', () => {
describe('agency getShipped()', () => {
it('should return a shipment date', async() => {
const landed = new Date();
landed.setDate(landed.getDate() + 1);
const addressFk = 121;
const agencyModeFk = 7;
const warehouseFk = 1;

View File

@ -1,6 +1,6 @@
const app = require('vn-loopback/server/server');
// Petición #1848
xdescribe('Agency landsThatDay()', () => {
describe('Agency landsThatDay()', () => {
const today = new Date();
it('should return a list of agencies that can land a shipment on a day for an address', async() => {
let agencies = await app.models.Agency.landsThatDay(101, today);

View File

@ -1,28 +0,0 @@
module.exports = Self => {
Self.remoteMethod('removeByDate', {
description: 'Removes one or more delivery dates for a zone',
accessType: 'WRITE',
accepts: [{
arg: 'zoneFk',
type: 'Number',
required: true,
},
{
arg: 'dates',
type: ['Date'],
required: true,
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/removeByDate`,
verb: 'POST'
}
});
Self.removeByDate = (zoneFk, dates) => {
return Self.destroyAll({zoneFk, delivered: {inq: dates}});
};
};

View File

@ -31,7 +31,6 @@ module.exports = Self => {
fields: [
'name',
'hour',
'warehouseFk',
'agencyModeFk',
'travelingDays',
'price',
@ -47,7 +46,8 @@ module.exports = Self => {
}, options);
// Find all original selected days
const calendarDays = await models.ZoneCalendar.find({
const calendarDays = await models.ZoneEvent.find({
fields: {id: false},
where: {zoneFk: id}
}, options);
@ -62,7 +62,7 @@ module.exports = Self => {
});
await models.ZoneIncluded.create(newIncludedGeo, options);
await models.ZoneCalendar.create(newCalendayDays, options);
await models.ZoneEvent.create(newCalendayDays, options);
await tx.commit();
return newZone;

View File

@ -1,81 +0,0 @@
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => {
Self.remoteMethod('editPrices', {
description: 'Changes the price and bonus of a delivery day',
accessType: 'WRITE',
accepts: [{
arg: 'id',
type: 'Number',
description: 'The zone id',
http: {source: 'path'}
},
{
arg: 'delivered',
type: 'Date',
required: true,
},
{
arg: 'price',
type: 'Number',
required: true,
},
{
arg: 'bonus',
type: 'Number',
required: true,
},
{
arg: 'option',
type: 'String',
required: true,
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/:id/editPrices`,
verb: 'POST'
}
});
Self.editPrices = async(id, delivered, price, bonus, option) => {
const models = Self.app.models;
let filter = {
where: {
zoneFk: id
}
};
let where;
let shouldPropagate = true;
if (option == 'Only this day') {
shouldPropagate = false;
where = {delivered};
} else if (option == 'From this day') {
where = {
delivered: {
gte: delivered
}
};
}
filter = mergeFilters(filter, {where});
const days = await models.ZoneCalendar.find(filter);
const areAllFromSameZone = days.every(day => day.zoneFk === id);
if (!areAllFromSameZone)
throw new UserError('All delivery days must belong to the same zone');
if (shouldPropagate) {
const zone = await models.Zone.findById(id);
zone.updateAttributes({price, bonus});
}
return models.ZoneCalendar.updateAll(filter.where, {price, bonus});
};
};

View File

@ -1,81 +0,0 @@
const app = require('vn-loopback/server/server');
// Petición #1848
xdescribe('agency editPrices()', () => {
const zoneId = 1;
let originalZone;
beforeAll(async done => {
originalZone = await app.models.Zone.findById(zoneId);
done();
});
afterAll(async done => {
await await app.models.ZoneCalendar.updateAll({zoneFk: zoneId}, {
price: originalZone.price,
bonus: originalZone.bonus
});
done();
});
it('should apply price and bonus for a selected day', async() => {
const delivered = new Date();
delivered.setHours(0, 0, 0, 0);
await app.models.Zone.editPrices(zoneId, delivered, 4.00, 2.00, 'Only this day');
const editedDays = await app.models.ZoneCalendar.find({
where: {
zoneFk: zoneId,
delivered: delivered
}
});
const firstEditedDay = editedDays[0];
expect(editedDays.length).toEqual(1);
expect(firstEditedDay.price).toEqual(4.00);
expect(firstEditedDay.bonus).toEqual(2.00);
});
it('should apply price and bonus for all delivery days starting from selected day', async() => {
const delivered = new Date();
delivered.setHours(0, 0, 0, 0);
await app.models.Zone.editPrices(1, delivered, 5.50, 1.00, 'From this day');
const editedDays = await app.models.ZoneCalendar.find({
where: {
zoneFk: zoneId,
delivered: {
gte: delivered
}
}
});
const firstEditedDay = editedDays[0];
const lastEditedDay = editedDays[editedDays.length - 1];
expect(editedDays.length).toEqual(5);
expect(firstEditedDay.price).toEqual(5.50);
expect(firstEditedDay.bonus).toEqual(1.00);
expect(lastEditedDay.price).toEqual(5.50);
expect(lastEditedDay.bonus).toEqual(1.00);
});
it('should apply price and bonus for all delivery days', async() => {
const delivered = new Date();
delivered.setHours(0, 0, 0, 0);
await app.models.Zone.editPrices(1, delivered, 7.00, 0.00, 'All days');
const editedDays = await app.models.ZoneCalendar.find({
where: {
zoneFk: zoneId
}
});
const firstEditedDay = editedDays[0];
const lastEditedDay = editedDays[editedDays.length - 1];
expect(editedDays.length).toEqual(5);
expect(firstEditedDay.price).toEqual(7.00);
expect(firstEditedDay.bonus).toEqual(0.00);
expect(lastEditedDay.price).toEqual(7.00);
expect(lastEditedDay.bonus).toEqual(0.00);
});
});

View File

@ -20,9 +20,6 @@
"ZoneExclusion": {
"dataSource": "vn"
},
"ZoneCalendar": {
"dataSource": "vn"
},
"ZoneIncluded": {
"dataSource": "vn"
},

View File

@ -1,3 +0,0 @@
module.exports = Self => {
require('../methods/zone-calendar/removeByDate')(Self);
};

View File

@ -1,32 +0,0 @@
{
"name": "ZoneCalendar",
"base": "VnModel",
"options": {
"mysql": {
"table": "zoneCalendar"
}
},
"properties": {
"zoneFk": {
"id": true,
"type": "Number"
},
"delivered": {
"id": true,
"type": "Date"
},
"price": {
"type": "Number"
},
"bonus": {
"type": "Number"
}
},
"relations": {
"zone": {
"type": "belongsTo",
"model": "Zone",
"foreignKey": "zoneFk"
}
}
}

View File

@ -1,6 +1,5 @@
module.exports = Self => {
require('../methods/zone/clone')(Self);
require('../methods/zone/editPrices')(Self);
require('../methods/zone/getLeaves')(Self);
require('../methods/zone/getEvents')(Self);
require('../methods/zone/toggleIsIncluded')(Self);

View File

@ -1,80 +0,0 @@
<mg-ajax path="Zones/{{patch.params.id}}" options="vnPatch"></mg-ajax>
<vn-watcher
vn-id="watcher"
data="$ctrl.zone"
form="form"
save="patch">
</vn-watcher>
<form
name="form"
ng-submit="$ctrl.onSubmit()">
<vn-card class="vn-pa-lg">
<vn-horizontal>
<vn-textfield
vn-one
vn-focus
label="Name"
ng-model="$ctrl.zone.name"
rule>
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
ng-model="$ctrl.zone.warehouseFk"
url="Warehouses"
show-field="name"
value-field="id"
label="Warehouse"
rule>
</vn-autocomplete>
<vn-autocomplete
vn-one
ng-model="$ctrl.zone.agencyModeFk"
url="AgencyModes/isActive"
show-field="name"
value-field="id"
label="Agency"
rule>
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-input-number
vn-one
min="0"
step="1"
label="Traveling days"
ng-model="$ctrl.zone.travelingDays"
rule>
</vn-input-number>
<vn-input-time
vn-one
label="Estimated hour (ETD)"
ng-model="$ctrl.zone.hour"
rule>
</vn-input-time>
</vn-horizontal>
<vn-horizontal>
<vn-input-number
vn-one
label="Price"
ng-model="$ctrl.zone.price"
min="0.00"
step="0.50"
rule>
</vn-input-number>
<vn-input-number
vn-one
label="Bonus"
ng-model="$ctrl.zone.bonus"
min="0.00"
step="0.50"
rule>
</vn-input-number>
</vn-horizontal>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
<vn-button ui-sref="zone.card.location" label="Cancel"></vn-button>
</vn-button-bar>
</form>

View File

@ -1,40 +0,0 @@
<div class="search-panel">
<form ng-submit="$ctrl.onSearch()">
<vn-horizontal>
<vn-textfield
vn-one
label="General search"
ng-model="filter.search"
vn-focus>
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield
vn-one
label="Name"
ng-model="filter.name">
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="Agency"
ng-model="filter.agencyModeFk"
url="AgencyModes/isActive"
show-field="name"
value-field="id">
</vn-autocomplete>
<vn-autocomplete
vn-one
label="Warehouse"
ng-model="filter.warehouseFk"
url="Warehouses"
show-field="name"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal class="vn-mt-lg">
<vn-submit label="Search"></vn-submit>
</vn-horizontal>
</form>
</div>

View File

@ -1,7 +0,0 @@
import ngModule from '../module';
import SearchPanel from 'core/components/searchbar/search-panel';
ngModule.component('vnLocationSearchPanel', {
template: require('./index.html'),
controller: SearchPanel
});

View File

@ -1,6 +1,6 @@
const app = require('vn-loopback/server/server');
// Petición #1848
xdescribe('claimBeginning', () => {
describe('claimBeginning', () => {
let ticket;
let refundTicketSales;
let salesInsertedInClaimEnd;

View File

@ -1,7 +1,6 @@
const app = require('vn-loopback/server/server');
// Petición #1848
xdescribe('order catalogFilter()', () => {
describe('order catalogFilter()', () => {
it('should return an array of items', async() => {
let filter = {
where: {

View File

@ -1,7 +1,6 @@
const app = require('vn-loopback/server/server');
// Petición #1848
xdescribe('order getItemTypeAvailable()', () => {
describe('order getItemTypeAvailable()', () => {
it('should call the getItemTypeAvailable method with a valid order and item category', async() => {
let orderId = 11;
let itemCategoryId = 1;

View File

@ -1,6 +1,6 @@
const app = require('vn-loopback/server/server');
// Petición #1848
xdescribe('ticket componentUpdate()', () => {
describe('ticket componentUpdate()', () => {
const ticketId = 11;
const today = new Date();
const tomorrow = new Date();

View File

@ -2,7 +2,7 @@ const app = require('vn-loopback/server/server');
let UserError = require('vn-loopback/util/user-error');
xdescribe('ticket new()', () => {
describe('ticket new()', () => {
let ticket;
let today = new Date();
let ctx = {req: {accessToken: {userId: 1}}};

View File

@ -1,7 +1,7 @@
const app = require('vn-loopback/server/server');
let UserError = require('vn-loopback/util/user-error');
xdescribe('sale priceDifference()', () => {
describe('sale priceDifference()', () => {
it('should return ticket price differences', async() => {
let tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);

View File

@ -46,7 +46,8 @@ class Controller {
this.getShipped({
landed: this.ticket.landed,
addressFk: value,
agencyModeFk: this.ticket.agencyModeFk
agencyModeFk: this.ticket.agencyModeFk,
warehouseFk: this.ticket.warehouseFk
});
}
}
@ -77,7 +78,8 @@ class Controller {
this.getLanded({
shipped: value,
addressFk: this.ticket.addressFk,
agencyModeFk: this.ticket.agencyModeFk
agencyModeFk: this.ticket.agencyModeFk,
warehouseFk: this.ticket.warehouseFk
});
}
@ -90,7 +92,8 @@ class Controller {
this.getShipped({
landed: value,
addressFk: this.ticket.addressFk,
agencyModeFk: this.ticket.agencyModeFk
agencyModeFk: this.ticket.agencyModeFk,
warehouseFk: this.ticket.warehouseFk
});
}
@ -104,7 +107,8 @@ class Controller {
this.getLanded({
shipped: this.ticket.shipped,
addressFk: this.ticket.addressFk,
agencyModeFk: value
agencyModeFk: value,
warehouseFk: this.ticket.warehouseFk
});
}
}
@ -197,7 +201,6 @@ class Controller {
this.$http.get(query, {params}).then(res => {
if (res.data) {
this.ticket.zoneFk = res.data.zoneFk;
this.ticket.agencyModeFk = res.data.agencyModeFk;
this.ticket.landed = res.data.landed;
this.ticket.shipped = params.shipped;
} else {
@ -217,7 +220,6 @@ class Controller {
this.$http.get(query, {params}).then(res => {
if (res.data) {
this.ticket.zoneFk = res.data.zoneFk;
this.ticket.agencyModeFk = res.data.agencyModeFk;
this.ticket.landed = params.landed;
this.ticket.shipped = res.data.shipped;
} else {

View File

@ -108,10 +108,18 @@ module.exports = Self => {
}
});
// Get number of total holidays
// Get number of worked days
let workedDays = 0;
contracts.forEach(contract => {
calendar.totalHolidays += getHolidaysByContract(contract, yearEnded);
const started = contract.started;
const ended = contract.ended;
const startedTime = started.getTime();
const endedTime = ended && ended.getTime() || yearEnded;
const dayTimestamp = 1000 * 60 * 60 * 24;
workedDays += Math.floor((endedTime - startedTime) / dayTimestamp);
// Workcenter holidays
let holidayList = contract.workCenter().holidays();
for (let day of holidayList) {
day.dated = new Date(day.dated);
@ -120,26 +128,19 @@ module.exports = Self => {
holidays.push(day);
}
});
const currentContract = contracts.find(contract => {
return contract.started <= new Date()
&& (contract.ended >= new Date() || contract.ended == null);
});
if (currentContract) {
const maxDays = currentContract.holidays().days;
calendar.totalHolidays = maxDays;
if (workedDays < 365)
calendar.totalHolidays = Math.round(2 * maxDays * (workedDays + 1) / 365) / 2;
}
return [calendar, absences, holidays];
};
function getHolidaysByContract(contract, endOfYear) {
const dayTimestamp = 1000 * 60 * 60 * 24;
const started = contract.started;
const ended = contract.ended;
const startedTime = started.getTime();
const endedTime = ended && ended.getTime() || endOfYear;
const contractDays = Math.floor((endedTime - startedTime) / dayTimestamp);
if (contractDays < 365) {
let holidays = Math.round(2 * contract.holidays().days * (contractDays + 1) / 365) / 2;
return holidays;
}
return contract.holidays().days;
}
};

View File

@ -43,13 +43,13 @@ describe('Worker absences()', () => {
expect(sixthType).toEqual('Holidays');
});
it(`should fire the worker 106 on Juny and see he/she has 14`, async() => {
it(`should see he/she has 26.5`, async() => {
let workerFk = 106;
const firedWorker = await app.models.WorkerLabour.findById(workerFk);
const endedDate = new Date();
endedDate.setDate(30);
endedDate.setMonth(5);
endedDate.setDate(endedDate.getDate() + 1);
endedDate.setMonth(endedDate.getMonth() + 1);
endedDate.setHours(0, 0, 0, 0);
await firedWorker.updateAttributes({ended: endedDate});
@ -71,7 +71,7 @@ describe('Worker absences()', () => {
let calendar = result[0];
let absences = result[1];
expect(calendar.totalHolidays).toEqual(13.5);
expect(calendar.totalHolidays).toEqual(26.5);
expect(calendar.holidaysEnjoyed).toEqual(5);
let firstType = absences[0].absenceType().name;
@ -81,13 +81,13 @@ describe('Worker absences()', () => {
expect(sixthType).toEqual('Holidays');
});
it(`should fire the worker 106 on March and see he/she has 7`, async() => {
it(`should see he/she has 26.5`, async() => {
const firedWorker = await app.models.WorkerLabour.findById(106);
const endedDate = new Date();
endedDate.setDate(endedDate.getDate() + 1);
endedDate.setMonth(endedDate.getMonth() + 1);
endedDate.setHours(0, 0, 0, 0);
endedDate.setMonth(2);
endedDate.setDate(31);
await firedWorker.updateAttributes({ended: endedDate});
@ -109,7 +109,7 @@ describe('Worker absences()', () => {
let calendar = result[0];
let absences = result[1];
expect(calendar.totalHolidays).toEqual(7);
expect(calendar.totalHolidays).toEqual(26.5);
expect(calendar.holidaysEnjoyed).toEqual(5);
let firstType = absences[0].absenceType().name;
@ -119,19 +119,13 @@ describe('Worker absences()', () => {
expect(sixthType).toEqual('Holidays');
});
it(`should fire the worker 106 on january and see he/she has x`, async() => {
const firedWorker = await app.models.WorkerLabour.findById(106);
const endedDate = new Date();
endedDate.setHours(0, 0, 0, 0);
endedDate.setMonth(0);
endedDate.setDate(28);
await firedWorker.updateAttributes({ended: endedDate});
it(`should see he/she has 27.5`, async() => {
let ctx = {req: {accessToken: {userId: 106}}};
let workerFk = 106;
const firedWorker = await app.models.WorkerLabour.findById(106);
await firedWorker.updateAttributes({ended: null});
const started = new Date();
started.setHours(0, 0, 0, 0);
started.setMonth(0);
@ -147,7 +141,7 @@ describe('Worker absences()', () => {
let calendar = result[0];
let absences = result[1];
expect(calendar.totalHolidays).toEqual(2);
expect(calendar.totalHolidays).toEqual(27.5);
expect(calendar.holidaysEnjoyed).toEqual(5);
let firstType = absences[0].absenceType().name;

View File

@ -100,7 +100,7 @@ class Controller {
let dayNumber = element.firstElementChild;
dayNumber.title = event.name;
dayNumber.style.backgroundColor = event.color;
dayNumber.style.color = 'white';
dayNumber.style.color = 'rgba(0, 0, 0, 0.7)';
}
}
Controller.$inject = ['$element', '$http'];