1447-updateClaim_refactor #405

Merged
joan merged 5 commits from 1447-updateClaim_refactor into dev 2020-10-13 08:10:06 +00:00
54 changed files with 587 additions and 142 deletions
Showing only changes of commit 134d1c4385 - Show all commits

View File

@ -0,0 +1,41 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => {
Self.remoteMethod('latest', {
description: 'Returns the lastest campaigns',
accessType: 'READ',
accepts: [{
arg: 'filter',
type: 'Object',
description: `Filter defining where, order, offset, and limit - must be a JSON-encoded string`
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/latest`,
verb: 'GET'
}
});
Self.latest = async filter => {
const conn = Self.dataSource.connector;
const minDate = new Date();
minDate.setFullYear(minDate.getFullYear() - 1);
minDate.setMonth(0);
minDate.setDate(1);
const where = {dated: {gte: minDate}};
filter = mergeFilters(filter, {where});
const stmt = new ParameterizedSQL(
`SELECT * FROM campaign`);
stmt.merge(conn.makeWhere(filter.where));
stmt.merge('GROUP BY code');
stmt.merge(conn.makePagination(filter));
return conn.executeStmt(stmt);
};
};

View File

@ -0,0 +1,34 @@
const app = require('vn-loopback/server/server');
describe('campaign latest()', () => {
it('should return the campaigns from the last year', async() => {
let result = await app.models.Campaign.latest();
const lastYearDate = new Date();
lastYearDate.setFullYear(lastYearDate.getFullYear() - 1);
const lastYear = lastYearDate.getFullYear();
const randomIndex = Math.floor(Math.random() * result.length);
const campaignDated = result[randomIndex].dated;
const campaignYear = campaignDated.getFullYear();
expect(result.length).toEqual(3);
expect(campaignYear).toEqual(lastYear);
});
it('should return the campaigns from the current year', async() => {
const currentDate = new Date();
const currentYear = currentDate.getFullYear();
const result = await app.models.Campaign.latest({
where: {dated: {like: `%${currentYear}%`}}
});
const randomIndex = Math.floor(Math.random() * result.length);
const campaignDated = result[randomIndex].dated;
const campaignYear = campaignDated.getFullYear();
expect(result.length).toEqual(3);
expect(campaignYear).toEqual(currentYear);
});
});

View File

@ -0,0 +1,16 @@
const app = require('vn-loopback/server/server');
describe('campaign upcoming()', () => {
it('should return the upcoming campaign but from the last year', async() => {
let response = await app.models.Campaign.upcoming();
const lastYearDate = new Date();
lastYearDate.setFullYear(lastYearDate.getFullYear() - 1);
const lastYear = lastYearDate.getFullYear();
const campaignDated = response.dated;
const campaignYear = campaignDated.getFullYear();
expect(campaignYear).toEqual(lastYear);
});
});

View File

@ -0,0 +1,29 @@
module.exports = Self => {
Self.remoteMethod('upcoming', {
description: 'Returns the upcoming campaign',
accessType: 'READ',
accepts: [],
returns: {
type: ['object'],
root: true
},
http: {
path: `/upcoming`,
verb: 'GET'
}
});
Self.upcoming = async() => {
const minDate = new Date();
minDate.setFullYear(minDate.getFullYear() - 1);
return Self.findOne({
where: {
dated: {
gte: minDate
}
},
order: 'dated ASC'
});
};
};

View File

@ -8,6 +8,9 @@
"Bank": {
"dataSource": "vn"
},
"Campaign": {
"dataSource": "vn"
},
"Country": {
"dataSource": "vn"
},

4
back/models/campaign.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = Self => {
require('../methods/campaign/latest')(Self);
require('../methods/campaign/upcoming')(Self);
};

33
back/models/campaign.json Normal file
View File

@ -0,0 +1,33 @@
{
"name": "Campaign",
"base": "VnModel",
"options": {
"mysql": {
"table": "campaign"
}
},
"properties": {
"id": {
"type": "number",
"required": true
},
"code": {
"type": "string",
"required": true
},
"dated": {
"type": "date"
},
"scopeDays": {
"type": "number"
}
},
"acls": [
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
]
}

View File

@ -4,3 +4,4 @@ ADD COLUMN `oldInstance` text CHARACTER SET utf8 COLLATE utf8_unicode_ci,
ADD COLUMN `newInstance` text CHARACTER SET utf8 COLLATE utf8_unicode_ci,
ADD COLUMN `changedModelId` int(11) DEFAULT NULL,
ADD COLUMN `changedModelValue` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL;

View File

@ -0,0 +1,9 @@
ALTER TABLE `vn`.`ticketService`
DROP FOREIGN KEY `ticketServiceIvaGroup`;
ALTER TABLE `vn`.`ticketService`
CHANGE COLUMN `taxClassFk` `taxClassFk` TINYINT(3) UNSIGNED NOT NULL DEFAULT 2 ;
ALTER TABLE `vn`.`ticketService`
ADD CONSTRAINT `ticketServiceIvaGroup`
FOREIGN KEY (`taxClassFk`)
REFERENCES `vn`.`taxClass` (`id`)
ON UPDATE CASCADE;

View File

@ -0,0 +1 @@
UPDATE salix.ACL t SET t.principalId = 'salesAssistant' WHERE t.id = 234

View File

@ -0,0 +1,37 @@
CREATE TABLE `vn`.campaign
(
id INT AUTO_INCREMENT,
code ENUM('mothersDay', 'allSaints', 'valentinesDay') NOT NULL,
dated DATE DEFAULT CURDATE() NOT NULL,
scopeDays INT NOT NULL DEFAULT '15',
CONSTRAINT campaign_pk
PRIMARY KEY (id)
);
CREATE UNIQUE INDEX campaign_dated_uindex
ON `vn`.campaign (dated);
-- TODOS SANTOS
INSERT INTO `vn`.campaign(code, dated)
SELECT 'allSaints' AS code, dated
FROM `vn`.time
WHERE dated >= CONCAT(YEAR(CURDATE()) - 1, '-01-01')
AND month = 11
AND day = 1;
-- SAN VALENTIN
INSERT INTO `vn`.campaign(code, dated)
SELECT 'valentinesDay' AS code, dated
FROM `vn`.time
WHERE dated >= CONCAT(YEAR(CURDATE()) - 1, '-01-01')
AND month = 2
AND day = 14;
-- DIA DE LA MADRE
INSERT INTO `vn`.campaign(code, dated)
SELECT 'mothersDay' AS code, dated
FROM `vn`.time
WHERE dated >= CONCAT(YEAR(CURDATE()) - 1, '-01-01')
AND month = 5
AND WEEK(dated, 5) - WEEK(DATE_SUB(dated, INTERVAL DAYOFMONTH(dated) - 1 DAY), 5) + 1 = 1 -- WEEK OF MONTH
AND DAYOFWEEK(dated) = 1;

View File

@ -0,0 +1,4 @@
ALTER TABLE `vn`.department
ADD notificationEmail VARCHAR(150) null;
UPDATE vn.department t SET t.notificationEmail = 'direccioncomercial@verdnatura.es' WHERE t.id = 43

View File

@ -42,8 +42,8 @@ INSERT INTO `vn`.`worker`(`id`,`code`, `firstName`, `lastName`, `userFk`, `bossF
FROM `vn`.`user`;
UPDATE `vn`.`worker` SET bossFk = NULL WHERE id = 20;
UPDATE `vn`.`worker` SET bossFk = 20
WHERE id = 1 OR id = 9;
UPDATE `vn`.`worker` SET bossFk = 20 WHERE id = 1 OR id = 9;
UPDATE `vn`.`worker` SET bossFk = 19 WHERE id = 18;
DELETE FROM `vn`.`worker` WHERE firstName ='customer';
@ -479,7 +479,9 @@ INSERT INTO `vn`.`expence`(`id`, `taxTypeFk`, `name`, `isWithheld`)
(4751000000, 1, 'Retenciones', 1),
(4751000000, 6, 'Retencion', 0),
(6210000567, 0, 'Alquiler VNH', 0),
(7001000000, 1, 'Mercaderia', 0);
(7001000000, 1, 'Mercaderia', 0),
(7050000000, 1, 'Prestacion de servicios', 1);
INSERT INTO `vn`.`invoiceOutExpence`(`id`, `invoiceOutFk`, `amount`, `expenceFk`, `created`)
VALUES
@ -1694,6 +1696,10 @@ UPDATE `postgresql`.`business_labour` bl
SET bl.`professional_category_id` = 31
WHERE p.`Id_trabajador` = 110;
UPDATE `postgresql`.`business_labour` bl
SET bl.`department_id` = 43
WHERE business_id IN(18, 19);
INSERT INTO `postgresql`.`media`(`media_id`, `media_type_id`, `value`, `sort`)
VALUES
(1, 10, 600123321, 0),

View File

@ -510,10 +510,8 @@ export default {
firstServiceType: 'vn-ticket-service vn-autocomplete[ng-model="service.ticketServiceTypeFk"]',
firstQuantity: 'vn-ticket-service vn-input-number[ng-model="service.quantity"]',
firstPrice: 'vn-ticket-service vn-horizontal:nth-child(1) vn-input-number[ng-model="service.price"]',
firstVatType: 'vn-ticket-service vn-autocomplete[label="Tax class"]',
fistDeleteServiceButton: 'vn-ticket-service form vn-horizontal:nth-child(1) vn-icon-button[icon="delete"]',
newServiceTypeName: '.vn-dialog.shown vn-textfield[ng-model="newServiceType.name"]',
newServiceTypeExpense: '.vn-dialog.shown vn-autocomplete[ng-model="newServiceType.expenseFk"]',
serviceLine: 'vn-ticket-service > form > vn-card > vn-one:nth-child(2) > vn-horizontal',
saveServiceButton: 'button[type=submit]',
saveServiceTypeButton: '.vn-dialog.shown tpl-buttons > button'

View File

@ -78,7 +78,6 @@ describe('Ticket services path', () => {
it('should create a new service type then add price then create the service', async() => {
await page.write(selectors.ticketService.newServiceTypeName, 'Documentos');
await page.autocompleteSearch(selectors.ticketService.newServiceTypeExpense, 'Retencion');
await page.waitToClick(selectors.ticketService.saveServiceTypeButton);
await page.write(selectors.ticketService.firstPrice, '999');
await page.waitToClick(selectors.ticketService.saveServiceButton);
@ -109,13 +108,6 @@ describe('Ticket services path', () => {
expect(result).toEqual('999');
});
it('should confirm the service VAT was created correctly', async() => {
const result = await page
.waitToGetProperty(selectors.ticketService.firstVatType, 'value');
expect(result).toEqual('General VAT');
});
it('should delete the service', async() => {
await page.waitToClick(selectors.ticketService.fistDeleteServiceButton);
await page.waitForNumberOfElements(selectors.ticketService.serviceLine, 0);

View File

@ -42,6 +42,7 @@ describe('Ticket create path', () => {
it('should again open the new ticket form', async() => {
await page.waitToClick(selectors.globalItems.returnToModuleIndexButton);
await page.waitFor(500);
await page.waitToClick(selectors.ticketsIndex.newTicketButton);
await page.waitForState('ticket.create');
});

View File

@ -20,14 +20,13 @@ describe('Entry create path', () => {
await page.waitForState('entry.create');
});
it('should fill the form to create a valid entry', async() => {
it('should fill the form to create a valid entry then redirect to basic Data', async() => {
await page.autocompleteSearch(selectors.entryIndex.newEntrySupplier, '2');
await page.autocompleteSearch(selectors.entryIndex.newEntryTravel, 'Warehouse Three');
await page.autocompleteSearch(selectors.entryIndex.newEntryCompany, 'ORN');
await page.waitToClick(selectors.entryIndex.saveNewEntry);
});
it('should be redirected to entry basic data', async() => {
await page.waitToClick(selectors.entryIndex.saveNewEntry);
await page.waitFor(500);
await page.waitForState('entry.card.basicData');
});
});

View File

@ -190,9 +190,24 @@ export default class Autocomplete extends Field {
this.input.value = display;
if (this.translateFields) {
if (this.translateFields.indexOf(this.showField) > -1)
this.input.value = this.$t(display);
if (this.translateFields && this.selection) {
const translations = [];
for (let field of this.translateFields) {
const fieldValue = this._selection[field];
translations.push({
original: fieldValue,
value: this.$t(fieldValue)
});
}
for (let translation of translations) {
const orgValue = translation.original;
const value = translation.value;
display = display.replace(orgValue, value);
}
this.input.value = display;
}
}

View File

@ -68,5 +68,7 @@
"Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member",
"Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}",
"Landing cannot be lesser than shipment": "Landing cannot be lesser than shipment",
"NOT_ZONE_WITH_THIS_PARAMETERS": "NOT_ZONE_WITH_THIS_PARAMETERS"
"NOT_ZONE_WITH_THIS_PARAMETERS": "NOT_ZONE_WITH_THIS_PARAMETERS",
"Created absence": "The worker <strong>{{author}}</strong> has added an absence of type '{{absenceType}}' to <a href='{{{workerUrl}}}'><strong>{{employee}}</strong></a> for day {{dated}}.",
"Deleted absence": "The worker <strong>{{author}}</strong> has deleted an absence of type '{{absenceType}}' to <a href='{{{workerUrl}}}'><strong>{{employee}}</strong></a> for day {{dated}}."
}

View File

@ -143,5 +143,8 @@
"Role name must be written in camelCase": "Role name must be written in camelCase",
"can't be set": "can't be set",
"Email already exists": "Email already exists",
"User already exists": "User already exists"
"User already exists": "User already exists",
"Absence change notification on the labour calendar": "Notificacion de cambio de ausencia en el calendario laboral",
"Created absence": "El empleado <strong>{{author}}</strong> ha añadido una ausencia de tipo '{{absenceType}}' a <a href='{{{workerUrl}}}'><strong>{{employee}}</strong></a> para el día {{dated}}.",
"Deleted absence": "El empleado <strong>{{author}}</strong> ha eliminado una ausencia de tipo '{{absenceType}}' a <a href='{{{workerUrl}}}'><strong>{{employee}}</strong></a> del día {{dated}}."
}

View File

@ -39,7 +39,8 @@
"url": "/index?q",
"state": "account.index",
"component": "vn-user-index",
"description": "Users"
"description": "Users",
"acl": ["hr"]
}, {
"url": "/create",
"state": "account.create",

View File

@ -7,6 +7,7 @@
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
vn-focus
panel="vn-claim-search-panel"
info="Search claim by id or client name"
model="model">

View File

@ -49,6 +49,22 @@
ng-model="filter.categoryId">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete vn-one
url="Campaigns/latest"
label="Campaign"
translate-fields="['code']"
show-field="code"
value-field="id"
ng-model="filter.campaign"
order="dated DESC"
selection="$ctrl.campaignSelection"
search-function="{dated: {like: '%'+ $search +'%'}}">
<tpl-item>
{{code}} {{dated | date: 'yyyy'}}
</tpl-item>
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-date-picker
vn-one

View File

@ -1,7 +1,39 @@
import ngModule from '../module';
import SearchPanel from 'core/components/searchbar/search-panel';
class Controller extends SearchPanel {
constructor($, $element) {
super($, $element);
this.getUpcomingCampaing();
}
getUpcomingCampaing() {
this.$http.get('Campaigns/upcoming').then(res => {
const filter = this.$.filter;
filter.campaign = res.data.id;
});
}
get campaignSelection() {
return this._campaignSelection;
}
set campaignSelection(value) {
this._campaignSelection = value;
if (!value) return;
const filter = this.$.filter;
const from = new Date(value.dated);
from.setDate(from.getDate() - value.scopeDays);
filter.to = value.dated;
filter.from = from;
}
}
ngModule.vnComponent('vnConsumptionSearchPanel', {
template: require('./index.html'),
controller: SearchPanel
controller: Controller
});

View File

@ -0,0 +1,31 @@
import './index.js';
describe('Client', () => {
describe('Component vnConsumptionSearchPanel', () => {
let $httpBackend;
let $element;
let controller;
beforeEach(ngModule('client'));
beforeEach(inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
$element = angular.element(`<div></div>`);
controller = $componentController('vnConsumptionSearchPanel', {$element});
controller.$.filter = {};
$httpBackend.expect('GET', 'Campaigns/upcoming').respond(200, {id: 1});
}));
describe('getUpcomingCampaing()', () => {
it(`should make an HTTP query and then set the campaign property`, () => {
$httpBackend.expect('GET', 'Campaigns/upcoming').respond(200, {id: 2, code: 'allSaints'});
controller.getUpcomingCampaing();
$httpBackend.flush();
const filter = controller.$.filter;
expect(filter.campaign).toEqual(2);
});
});
});
});

View File

@ -0,0 +1,3 @@
allSaints: All Saints Day
valentinesDay: Valentine's Day
mothersDay: Mother's day

View File

@ -1,3 +1,7 @@
Item id: Id artículo
From: Desde
To: Hasta
To: Hasta
Campaign: Campaña
allSaints: Día de todos los Santos
valentinesDay: Día de San Valentín
mothersDay: Día de la madre

View File

@ -7,6 +7,7 @@
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
vn-focus
panel="vn-client-search-panel"
info="Search client by id or name"
model="model"

View File

@ -99,7 +99,7 @@
"component": "ui-view",
"abstract": true
}, {
"url": "/index",
"url": "/index?q",
"state": "client.card.address.index",
"component": "vn-client-address-index",
"description": "Addresses",
@ -353,7 +353,7 @@
}
},
{
"url": "/consumption",
"url": "/consumption?q",
"state": "client.card.consumption",
"component": "vn-client-consumption",
"description": "Consumption",

View File

@ -9,30 +9,6 @@
</vn-watcher>
<form name="form" ng-submit="watcher.submit()" class="vn-w-md">
<vn-card class="vn-pa-lg">
<vn-horizontal>
<vn-textfield
vn-one
label="Reference"
ng-model="$ctrl.entry.ref"
rule
vn-focus>
</vn-textfield>
<vn-textfield
vn-one
label="Notes"
ng-model="$ctrl.entry.notes"
rule
vn-focus>
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textarea
vn-one
label="Observation"
ng-model="$ctrl.entry.observation"
rule>
</vn-textarea>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
@ -63,6 +39,30 @@
</tpl-item>
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-textfield
vn-one
label="Reference"
ng-model="$ctrl.entry.ref"
rule
vn-focus>
</vn-textfield>
<vn-textfield
vn-one
label="Notes"
ng-model="$ctrl.entry.notes"
rule
vn-focus>
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textarea
vn-one
label="Observation"
ng-model="$ctrl.entry.observation"
rule>
</vn-textarea>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one

View File

@ -6,6 +6,7 @@
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
vn-focus
panel="vn-latest-buys-search-panel"
placeholder="Search by item id or name"
info="You can search by item id or name"

View File

@ -6,6 +6,7 @@
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
vn-focus
panel="vn-entry-search-panel"
info="Search entrys by id"
model="model">

View File

@ -6,6 +6,7 @@
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
vn-focus
panel="vn-invoice-search-panel"
info="Search invoices by reference"
model="model">

View File

@ -7,25 +7,25 @@
order="landed DESC, buyFk DESC"
limit="20">
</vn-crud-model>
<vn-card class="vn-mb-md vn-w-xl vn-pa-lg">
<vn-date-picker
vn-none
label="Since"
ng-model="$ctrl.date">
</vn-date-picker>
</vn-card>
<vn-data-viewer
model="model"
class="vn-mb-xl vn-w-xl">
<vn-card class="vn-pa-lg">
<vn-vertical>
<vn-horizontal>
<vn-date-picker
vn-one
label="Since"
ng-model="$ctrl.date">
</vn-date-picker>
<!--datepicker-->
</vn-horizontal>
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th vn-tooltip="Ignored" center>Ig</vn-th>
<vn-th field="warehouseFk">Warehouse</vn-th>
<vn-th field="landed">Landed</vn-th>
<vn-th field="landed" expand>Landed</vn-th>
<vn-th number>Entry</vn-th>
<vn-th number vn-tooltip="Price Per Unit">P.P.U</vn-th>
<vn-th number vn-tooltip="Price Per Package">P.P.P</vn-th>
@ -48,8 +48,8 @@
disabled="true">
</vn-check>
</vn-td>
<vn-td>{{::entry.warehouse| dashIfEmpty}}</vn-td>
<vn-td>{{::entry.landed | date:'dd/MM/yyyy HH:mm'}}</vn-td>
<vn-td title="{{::entry.warehouse| dashIfEmpty}}">{{::entry.warehouse| dashIfEmpty}}</vn-td>
<vn-td expand>{{::entry.landed | date:'dd/MM/yyyy HH:mm'}}</vn-td>
<vn-td number>{{::entry.entryFk | dashIfEmpty}}</vn-td>
<vn-td number>{{::entry.price2 | dashIfEmpty}}</vn-td>
<vn-td number>{{::entry.price3 | dashIfEmpty}}</vn-td>
@ -69,7 +69,7 @@
<vn-td number class="expendable">{{::entry.buyingValue | dashIfEmpty}}</vn-td>
<vn-td number>{{::entry.weight | dashIfEmpty}}</vn-td>
<vn-td number>{{::entry.packageFk | dashIfEmpty}}</vn-td>
<vn-td class="expendable">{{::entry.supplier | dashIfEmpty}}</vn-td>
<vn-td class="expendable" title="{{::entry.supplier | dashIfEmpty}}">{{::entry.supplier | dashIfEmpty}}</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>

View File

@ -30,7 +30,16 @@ class Controller extends Section {
if (!value) return;
this.filter.where.date = value;
const from = new Date(value);
from.setHours(0, 0, 0, 0);
const to = new Date();
to.setDate(to.getDate() + 10);
to.setHours(23, 59, 59, 59);
this.filter.where.shipped = {
between: [from, to]
};
this.$.model.refresh();
}

View File

@ -7,6 +7,7 @@
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
vn-focus
panel="vn-item-search-panel"
info="Search items by id, name or barcode"
suggested-filter="{isActive: true}"

View File

@ -7,6 +7,7 @@
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
vn-focus
panel="vn-order-search-panel"
info="Search orders by id"
model="model"

View File

@ -7,6 +7,7 @@
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
vn-focus
panel="vn-route-search-panel"
info="Search routes by id"
filter="$ctrl.filter"

View File

@ -17,7 +17,6 @@
},
"expenseFk": {
"type": "Number",
"required": true,
"mysql": {
"columnName": "expenceFk"
}

View File

@ -6,6 +6,7 @@
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
vn-focus
panel="vn-ticket-search-panel"
info="Search ticket by id or alias"
model="model"

View File

@ -53,13 +53,6 @@
ng-model="service.price"
step="0.01">
</vn-input-number>
<vn-autocomplete vn-one
data="taxClasses"
label="Tax class"
show-field="description"
value-field="id"
ng-model="service.taxClassFk">
</vn-autocomplete>
<vn-auto>
<vn-icon-button
pointer
@ -97,17 +90,6 @@
vn-focus>
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
vn-focus
url="Expenses"
label="Expense"
show-field="name"
value-field="id"
ng-model="newServiceType.expenseFk">
</vn-autocomplete>
</vn-horizontal>
</tpl-body>
<tpl-buttons>
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>

View File

@ -10,6 +10,7 @@
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
vn-focus
placeholder="Search by weekly ticket"
info="Search weekly ticket by id or client id"
auto-state="false"

View File

@ -6,6 +6,7 @@
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
vn-focus
panel="vn-travel-search-panel"
info="Search travels by id"
model="model"

View File

@ -31,6 +31,7 @@ module.exports = Self => {
Self.createAbsence = async(ctx, id, absenceTypeId, dated) => {
const models = Self.app.models;
const $t = ctx.req.__; // $translate
const userId = ctx.req.accessToken.userId;
const isSubordinate = await models.Worker.isSubordinate(ctx, id);
const isTeamBoss = await models.Account.hasRole(userId, 'teamBoss');
@ -39,6 +40,7 @@ module.exports = Self => {
throw new UserError(`You don't have enough privileges`);
const labour = await models.WorkerLabour.findOne({
include: {relation: 'department'},
where: {
and: [
{workerFk: id},
@ -49,10 +51,42 @@ module.exports = Self => {
}
});
return models.Calendar.create({
const absence = await models.Calendar.create({
businessFk: labour.businessFk,
dayOffTypeFk: absenceTypeId,
dated: dated
});
const department = labour.department();
if (department && department.notificationEmail) {
const absenceType = await models.AbsenceType.findById(absenceTypeId);
const account = await models.Account.findById(userId);
const subordinated = await models.Account.findById(id);
const origin = ctx.req.headers.origin;
const body = $t('Created absence', {
author: account.nickname,
employee: subordinated.nickname,
absenceType: absenceType.name,
dated: formatDate(dated),
workerUrl: `${origin}/#!/worker/${id}/calendar`
});
await models.Mail.create({
subject: $t('Absence change notification on the labour calendar'),
body: body,
sender: department.notificationEmail
});
}
return absence;
};
function formatDate(date) {
let day = date.getDate();
if (day < 10) day = `0${day}`;
let month = date.getMonth();
if (month < 10) month = `0${month}`;
let year = date.getFullYear();
return `${day}-${month}-${year}`;
}
};

View File

@ -23,6 +23,7 @@ module.exports = Self => {
Self.deleteAbsence = async(ctx, id, absenceId) => {
const models = Self.app.models;
const $t = ctx.req.__; // $translate
const userId = ctx.req.accessToken.userId;
const isSubordinate = await models.Worker.isSubordinate(ctx, id);
const isTeamBoss = await models.Account.hasRole(userId, 'teamBoss');
@ -30,8 +31,46 @@ module.exports = Self => {
if (!isSubordinate || (isSubordinate && userId == id && !isTeamBoss))
throw new UserError(`You don't have enough privileges`);
const absence = await models.Calendar.findById(absenceId);
const absence = await models.Calendar.findById(absenceId, {
include: {
relation: 'labour',
scope: {
include: {relation: 'department'}
}
}
});
const result = await absence.destroy();
const labour = absence.labour();
const department = labour && labour.department();
if (department && department.notificationEmail) {
const absenceType = await models.AbsenceType.findById(absence.dayOffTypeFk);
const account = await models.Account.findById(userId);
const subordinated = await models.Account.findById(labour.workerFk);
const origin = ctx.req.headers.origin;
const body = $t('Deleted absence', {
author: account.nickname,
employee: subordinated.nickname,
absenceType: absenceType.name,
dated: formatDate(absence.dated),
workerUrl: `${origin}/#!/worker/${id}/calendar`
});
await models.Mail.create({
subject: $t('Absence change notification on the labour calendar'),
body: body,
sender: department.notificationEmail
});
}
return absence.destroy();
return result;
};
function formatDate(date) {
let day = date.getDate();
if (day < 10) day = `0${day}`;
let month = date.getMonth();
if (month < 10) month = `0${month}`;
let year = date.getFullYear();
return `${day}-${month}-${year}`;
}
};

View File

@ -1,16 +1,11 @@
const app = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context');
describe('Worker createAbsence()', () => {
const workerId = 106;
let createdAbsence;
afterAll(async() => {
const absence = await app.models.Calendar.findById(createdAbsence.id);
await absence.destroy();
});
const workerId = 18;
it('should return an error for a user without enough privileges', async() => {
const ctx = {req: {accessToken: {userId: 106}}};
const ctx = {req: {accessToken: {userId: 18}}};
const absenceTypeId = 1;
const dated = new Date();
@ -25,15 +20,29 @@ describe('Worker createAbsence()', () => {
});
it('should create a new absence', async() => {
const ctx = {req: {accessToken: {userId: 37}}};
const activeCtx = {
accessToken: {userId: 19},
headers: {origin: 'http://localhost'}
};
const ctx = {req: activeCtx};
ctx.req.__ = value => {
return value;
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
const absenceTypeId = 1;
const dated = new Date();
createdAbsence = await app.models.Worker.createAbsence(ctx, workerId, absenceTypeId, dated);
const createdAbsence = await app.models.Worker.createAbsence(ctx, workerId, absenceTypeId, dated);
const expectedBusinessId = 106;
const expectedBusinessId = 18;
const expectedAbsenceTypeId = 1;
expect(createdAbsence.businessFk).toEqual(expectedBusinessId);
expect(createdAbsence.dayOffTypeFk).toEqual(expectedAbsenceTypeId);
// Restores
await app.models.Calendar.destroyById(createdAbsence.id);
});
});

View File

@ -1,20 +1,39 @@
const app = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context');
describe('Worker deleteAbsence()', () => {
const workerId = 106;
const businessId = 18;
const workerId = 18;
const activeCtx = {
accessToken: {userId: 106},
headers: {origin: 'http://localhost'}
};
const ctx = {req: activeCtx};
ctx.req.__ = value => {
return value;
};
let createdAbsence;
it('should return an error for a user without enough privileges', async() => {
const ctx = {req: {accessToken: {userId: 106}}};
const businessId = 106;
beforeEach(async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
createdAbsence = await app.models.Calendar.create({
businessFk: businessId,
dayOffTypeFk: 1,
dated: new Date()
});
});
afterEach(async() => {
await app.models.Calendar.destroyById(createdAbsence.id);
});
it('should return an error for a user without enough privileges', async() => {
activeCtx.accessToken.userId = 106;
let error;
await app.models.Worker.deleteAbsence(ctx, workerId, createdAbsence.id).catch(e => {
await app.models.Worker.deleteAbsence(ctx, 18, createdAbsence.id).catch(e => {
error = e;
}).finally(() => {
expect(error.message).toEqual(`You don't have enough privileges`);
@ -24,8 +43,7 @@ describe('Worker deleteAbsence()', () => {
});
it('should create a new absence', async() => {
const ctx = {req: {accessToken: {userId: 37}}};
const businessId = 106;
activeCtx.accessToken.userId = 19;
expect(createdAbsence.businessFk).toEqual(businessId);

View File

@ -1,22 +1,37 @@
const app = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context');
describe('Worker updateAbsence()', () => {
const workerId = 106;
const businessId = 106;
const activeCtx = {
accessToken: {userId: 106},
headers: {origin: 'http://localhost'}
};
const ctx = {req: activeCtx};
ctx.req.__ = value => {
return value;
};
let createdAbsence;
afterAll(async() => {
const absence = await app.models.Calendar.findById(createdAbsence.id);
await absence.destroy();
});
it('should return an error for a user without enough privileges', async() => {
const ctx = {req: {accessToken: {userId: 106}}};
const expectedAbsenceTypeId = 2;
beforeEach(async() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
});
createdAbsence = await app.models.Calendar.create({
businessFk: 106,
businessFk: businessId,
dayOffTypeFk: 1,
dated: new Date()
});
});
afterEach(async() => {
await app.models.Calendar.destroyById(createdAbsence.id);
});
it('should return an error for a user without enough privileges', async() => {
activeCtx.accessToken.userId = 106;
const expectedAbsenceTypeId = 2;
let error;
await app.models.Worker.updateAbsence(ctx, workerId, createdAbsence.id, expectedAbsenceTypeId).catch(e => {
@ -29,7 +44,7 @@ describe('Worker updateAbsence()', () => {
});
it('should create a new absence', async() => {
const ctx = {req: {accessToken: {userId: 37}}};
activeCtx.accessToken.userId = 37;
const expectedAbsenceTypeId = 2;
const updatedAbsence = await app.models.Worker.updateAbsence(ctx, workerId, createdAbsence.id, expectedAbsenceTypeId);

View File

@ -1,6 +1,10 @@
{
"name": "Calendar",
"base": "VnModel",
"base": "Loggable",
"log": {
"model": "WorkerLog",
"relation": "labour"
},
"options": {
"mysql": {
"table": "calendar"
@ -23,6 +27,11 @@
"type": "belongsTo",
"model": "AbsenceType",
"foreignKey": "dayOffTypeFk"
},
"labour": {
"type": "belongsTo",
"model": "WorkerLabour",
"foreignKey": "businessFk"
}
}
}

View File

@ -28,6 +28,9 @@
},
"chatName": {
"type": "String"
},
"notificationEmail": {
"type": "String"
}
}
}

View File

@ -6,6 +6,7 @@
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
vn-focus
panel="vn-worker-search-panel"
info="Search workers by id, firstName, lastName or user name"
model="model">

View File

@ -63,7 +63,7 @@
"state": "worker.card.workerLog",
"component": "vn-worker-log",
"description": "Log",
"acl": ["hr"]
"acl": ["salesAssistant"]
}, {
"url": "/pbx",
"state": "worker.card.pbx",

View File

@ -6,6 +6,7 @@
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
vn-focus
info="Search zone by id or name"
panel="vn-zone-search-panel"
model="model"

52
package-lock.json generated
View File

@ -5835,7 +5835,7 @@
},
"util": {
"version": "0.10.3",
"resolved": "http://registry.npmjs.org/util/-/util-0.10.3.tgz",
"resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz",
"integrity": "sha1-evsa/lCAUkZInj23/g7TeTNqwPk=",
"dev": true,
"requires": {
@ -6806,7 +6806,7 @@
"base": {
"version": "0.11.2",
"resolved": "https://registry.npmjs.org/base/-/base-0.11.2.tgz",
"integrity": "sha512-5T6P4xPgpp0YDFvSWwEZ4NoE3aM4QBQXDzmVbraCkFj8zHM+mba8SyqB5DbZWyR7mYHo6Y7BdQo3MoA4m0TeQg==",
"integrity": "sha1-e95c7RRbbVUakNuH+DxVi060io8=",
"dev": true,
"requires": {
"cache-base": "^1.0.1",
@ -6916,9 +6916,9 @@
"dev": true
},
"bl": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-2.2.0.tgz",
"integrity": "sha512-wbgvOpqopSr7uq6fJrLH8EsvYMJf9gzfo2jCsL2eTy75qXPukA4pCgHamOQkZtY5vmfVtjB+P3LNlMHW5CEZXA==",
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz",
"integrity": "sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==",
"requires": {
"readable-stream": "^2.3.5",
"safe-buffer": "^5.1.1"
@ -7329,7 +7329,7 @@
"cache-base": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/cache-base/-/cache-base-1.0.1.tgz",
"integrity": "sha512-AKcdTnFSWATd5/GCPRxr2ChwIJ85CeyrEyjRHlKxQ56d4XJMGym0uAiKn0xbLOGOl3+yRpOTi484dVCEc5AUzQ==",
"integrity": "sha1-Cn9GQWgxyLZi7jb+TnxZ129marI=",
"dev": true,
"requires": {
"collection-visit": "^1.0.0",
@ -7543,7 +7543,7 @@
"class-utils": {
"version": "0.3.6",
"resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz",
"integrity": "sha512-qOhPa/Fj7s6TY8H8esGu5QNpMMQxz79h+urzrNYN6mn+9BnxlDGf5QZ+XeCDsxSjPqsSR56XOZOJmpeurnLMeg==",
"integrity": "sha1-+TNprouafOAv1B+q0MqDAzGQxGM=",
"dev": true,
"requires": {
"arr-union": "^3.1.0",
@ -9796,7 +9796,7 @@
},
"file-loader": {
"version": "1.1.11",
"resolved": "http://registry.npmjs.org/file-loader/-/file-loader-1.1.11.tgz",
"resolved": "https://registry.npmjs.org/file-loader/-/file-loader-1.1.11.tgz",
"integrity": "sha512-TGR4HU7HUsGg6GCOPJnFk06RhWgEWFLAGWiT6rcD+GRC2keU3s9RGJ+b3Z6/U73jwwNb2gKLJ7YCrp+jvU4ALg==",
"dev": true,
"requires": {
@ -10982,7 +10982,7 @@
"global-modules": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/global-modules/-/global-modules-1.0.0.tgz",
"integrity": "sha512-sKzpEkf11GpOFuw0Zzjzmt4B4UZwjOcG757PPvrfhxcLFbq0wpsgpOqxpxtxFiCG4DtG93M6XRVbF2oGdev7bg==",
"integrity": "sha1-bXcPDrUjrHgWTXK15xqIdyZcw+o=",
"dev": true,
"requires": {
"global-prefix": "^1.0.1",
@ -13207,7 +13207,7 @@
"is-plain-object": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz",
"integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==",
"integrity": "sha1-LBY7P6+xtgbZ0Xko8FwqHDjgdnc=",
"dev": true,
"requires": {
"isobject": "^3.0.1"
@ -13541,7 +13541,7 @@
"jasmine-spec-reporter": {
"version": "4.2.1",
"resolved": "https://registry.npmjs.org/jasmine-spec-reporter/-/jasmine-spec-reporter-4.2.1.tgz",
"integrity": "sha512-FZBoZu7VE5nR7Nilzy+Np8KuVIOxF4oXDPDknehCYBDE080EnlPu0afdZNmpGDBRCUBv3mj5qgqCRmk6W/K8vg==",
"integrity": "sha1-HWMq7ANBZwrTJPkrqEtLMrNeniI=",
"dev": true,
"requires": {
"colors": "1.1.2"
@ -22227,7 +22227,7 @@
"dependencies": {
"jsesc": {
"version": "0.5.0",
"resolved": "http://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz",
"integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=",
"dev": true
}
@ -22620,7 +22620,7 @@
},
"safe-regex": {
"version": "1.1.0",
"resolved": "http://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz",
"resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz",
"integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=",
"dev": true,
"requires": {
@ -22834,7 +22834,7 @@
"dependencies": {
"source-map": {
"version": "0.4.4",
"resolved": "http://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz",
"integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=",
"dev": true,
"requires": {
@ -22850,18 +22850,18 @@
"dev": true
},
"selfsigned": {
"version": "1.10.7",
"resolved": "https://registry.npmjs.org/selfsigned/-/selfsigned-1.10.7.tgz",
"integrity": "sha512-8M3wBCzeWIJnQfl43IKwOmC4H/RAp50S8DF60znzjW5GVqTcSe2vWclt7hmYVPkKPlHWOu5EaWOMZ2Y6W8ZXTA==",
"version": "1.10.8",
"resolved": "https://registry.npmjs.org/selfsigned/-/selfsigned-1.10.8.tgz",
"integrity": "sha512-2P4PtieJeEwVgTU9QEcwIRDQ/mXJLX8/+I3ur+Pg16nS8oNbrGxEso9NyYWy8NAmXiNl4dlAp5MwoNeCWzON4w==",
"dev": true,
"requires": {
"node-forge": "0.9.0"
"node-forge": "^0.10.0"
},
"dependencies": {
"node-forge": {
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.9.0.tgz",
"integrity": "sha512-7ASaDa3pD+lJ3WvXFsxekJQelBKRpne+GOVbLbtHYdd7pFspyeuJHnWfLplGf3SwKGbfs/aYl5V/JCIaHVUKKQ==",
"version": "0.10.0",
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.10.0.tgz",
"integrity": "sha512-PPmu8eEeG9saEUvI97fm4OYxXVB6bFvyNTyiUOBichBpFG8A1Ljw3bY62+5oOjDEMHRnd0Y7HQ+x7uzxOzC6JA==",
"dev": true
}
}
@ -23295,7 +23295,7 @@
"snapdragon-node": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/snapdragon-node/-/snapdragon-node-2.1.1.tgz",
"integrity": "sha512-O27l4xaMYt/RSQ5TR3vpWCAB5Kb/czIcqUFOM/C4fYcLnbZUc1PkjTAMjof2pBWaSTwOUd6qUHcFGVGj7aIwnw==",
"integrity": "sha1-bBdfhv8UvbByRWPo88GwIaKGhTs=",
"dev": true,
"requires": {
"define-property": "^1.0.0",
@ -23346,7 +23346,7 @@
"snapdragon-util": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/snapdragon-util/-/snapdragon-util-3.0.1.tgz",
"integrity": "sha512-mbKkMdQKsjX4BAL4bRYTj21edOf8cN7XHdYUJEe+Zn99hVEYcMvKPct1IqNe7+AZPirn8BCDOQBHQZknqmKlZQ==",
"integrity": "sha1-+VZHlIbyrNeXAGk/b3uAXkWrVuI=",
"dev": true,
"requires": {
"kind-of": "^3.2.0"
@ -23630,7 +23630,7 @@
"split-string": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/split-string/-/split-string-3.1.0.tgz",
"integrity": "sha512-NzNVhJDYpwceVVii8/Hu6DKfD2G+NrQHlS/V/qgv763EYudVwEcMQNxd2lh+0VrUByXN/oJkl5grOhYWvQUYiw==",
"integrity": "sha1-fLCd2jqGWFcFxks5pkZgOGguj+I=",
"dev": true,
"requires": {
"extend-shallow": "^3.0.0"
@ -24941,7 +24941,7 @@
"touch": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/touch/-/touch-3.1.0.tgz",
"integrity": "sha512-WBx8Uy5TLtOSRtIq+M03/sKDrXCLHxwDcquSP2c43Le03/9serjQBIztjRz6FkJez9D/hleyAXTBGLwwZUw9lA==",
"integrity": "sha1-/jZfX3XsntTlaCXgu3bSSrdK+Ds=",
"dev": true,
"requires": {
"nopt": "~1.0.10"
@ -26733,7 +26733,7 @@
},
"xmlbuilder": {
"version": "9.0.7",
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz",
"resolved": "http://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz",
"integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0="
},
"xmlchars": {