diff --git a/db/changes/10420-valentines/00-aclAgency.sql b/db/changes/10420-valentines/00-aclAgency.sql
new file mode 100644
index 000000000..2134285cb
--- /dev/null
+++ b/db/changes/10420-valentines/00-aclAgency.sql
@@ -0,0 +1,2 @@
+INSERT INTO salix.ACL (id, model, property, accessType, permission, principalType, principalId)
+VALUES(301, 'Agency', '*', 'READ', 'ALLOW', 'ROLE', 'employee');
diff --git a/db/changes/10420-valentines/00-agencyTerm.sql b/db/changes/10420-valentines/00-agencyTerm.sql
new file mode 100644
index 000000000..9822b160b
--- /dev/null
+++ b/db/changes/10420-valentines/00-agencyTerm.sql
@@ -0,0 +1,10 @@
+CREATE TABLE `vn`.`agencyTermConfig` (
+ `expenceFk` varchar(10) DEFAULT NULL,
+ `vatAccountSupported` varchar(15) DEFAULT NULL,
+ `vatPercentage` decimal(28,10) DEFAULT NULL,
+ `transaction` varchar(50) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+INSERT INTO `vn`.`agencyTermConfig`
+(`expenceFk`, `vatAccountSupported`, `vatPercentage`, `transaction`)
+VALUES('6240000000', '4721000015', 21.0000000000, 'Adquisiciones intracomunitarias de servicios');
\ No newline at end of file
diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql
index 35013b35b..52d267e00 100644
--- a/db/dump/fixtures.sql
+++ b/db/dump/fixtures.sql
@@ -167,9 +167,11 @@ INSERT INTO `vn`.`accountingType`(`id`, `description`, `receiptDescription`,`cod
INSERT INTO `vn`.`bank`(`id`, `bank`, `account`, `cash`, `entityFk`, `isActive`, `currencyFk`)
VALUES
- (1, 'Pay on receipt', '5720000001', 3, 0, 1, 1),
- (2, 'Cash', '5700000001', 2, 0, 1, 1),
- (3, 'Compensation', '4000000000', 8, 0, 1, 1);
+ (1, 'Pay on receipt', '5720000001', 3, 0, 1, 1),
+ (2, 'Cash', '5700000001', 2, 0, 1, 1),
+ (3, 'Compensation', '4000000000', 8, 0, 1, 1),
+ (3117, 'Caixa Rural d''Algemesi', '5720000000', 8, 3117, 1, 1);
+
INSERT INTO `vn`.`deliveryMethod`(`id`, `code`, `description`)
VALUES
@@ -522,6 +524,8 @@ INSERT INTO `vn`.`expence`(`id`, `taxTypeFk`, `name`, `isWithheld`)
(4751000000, 1, 'Retenciones', 1),
(4751000000, 6, 'Retencion', 0),
(6210000567, 0, 'Alquiler VNH', 0),
+ (6240000000, 1, 'Transportes de ventas rutas', 0),
+ (6240000000, 4, 'Transportes de ventas rutas', 0),
(7001000000, 1, 'Mercaderia', 0),
(7050000000, 1, 'Prestacion de servicios', 1);
@@ -2465,4 +2469,4 @@ SET `invoiceInFk`=1
WHERE `id`=1;
UPDATE `vn`.`route`
SET `invoiceInFk`=2
-WHERE `id`=2;
\ No newline at end of file
+WHERE `id`=2;
diff --git a/modules/route/back/methods/agency-term/createInvoiceIn.js b/modules/route/back/methods/agency-term/createInvoiceIn.js
new file mode 100644
index 000000000..82e4437c0
--- /dev/null
+++ b/modules/route/back/methods/agency-term/createInvoiceIn.js
@@ -0,0 +1,85 @@
+module.exports = Self => {
+ Self.remoteMethod('createInvoiceIn', {
+ description: 'create a invoce in from a agency terms',
+ accessType: 'WRITE',
+ accepts: [{
+ arg: 'rows',
+ type: ['object'],
+ required: true,
+ description: `the rows from which the invoice in will be created`,
+ },
+ {
+ arg: 'dms',
+ type: ['object'],
+ required: true,
+ description: 'The dms files'
+ }],
+ returns: {
+ },
+ http: {
+ path: `/createInvoiceIn`,
+ verb: 'POST'
+ }
+ });
+
+ Self.createInvoiceIn = async(rows, dms, options) => {
+ const models = Self.app.models;
+ const myOptions = {};
+
+ if (typeof options == 'object')
+ Object.assign(myOptions, options);
+
+ const [firstRow] = rows;
+ const [firstDms] = dms;
+
+ const [reference] = await Self.rawSql(`SELECT reference FROM vn.dms WHERE id = ?`, [firstDms.id]);
+
+ const newInvoiceIn = await models.InvoiceIn.create({
+ supplierFk: firstRow.supplierFk,
+ supplierRef: reference.value,
+ issued: firstRow.created,
+ booked: firstRow.created,
+ operated: firstRow.created,
+ bookEntried: firstRow.created,
+ gestdoc_id: firstDms.id
+ });
+
+ const [expence] = await Self.rawSql(`SELECT expenceFk value FROM vn.agencyTermConfig`);
+
+ const [taxTypeSage] = await Self.rawSql(`
+ SELECT IFNULL(s.taxTypeSageFk, CodigoIva) value
+ FROM vn.supplier s
+ JOIN sage.TiposIva ti ON TRUE
+ JOIN vn.agencyTermConfig atg
+ WHERE s.id = ?
+ AND ti.CuentaIvaSoportado = atg.vatAccountSupported
+ AND ti.PorcentajeIva = atg.vatPercentage
+ `, [firstRow.supplierFk]);
+
+ const [transactionTypeSage] = await Self.rawSql(`
+ SELECT IFNULL(s.transactionTypeSageFk, tt.CodigoTransaccion) value
+ FROM vn.supplier s
+ JOIN sage.TiposTransacciones tt ON TRUE
+ JOIN vn.agencyTermConfig atg
+ WHERE s.id = ?
+ AND tt.Transaccion = atg.transaction
+ `, [firstRow.supplierFk]);
+
+ await models.InvoiceInTax.create({
+ invoiceInFk: newInvoiceIn.id,
+ taxableBase: firstRow.totalPrice,
+ expenseFk: expence.value,
+ taxTypeSageFk: taxTypeSage.value,
+ transactionTypeSageFk: transactionTypeSage.value
+ });
+
+ await Self.rawSql(`CALL invoiceInDueDay_calculate(?)`, [newInvoiceIn.id]);
+
+ for (let agencyTerm of rows) {
+ const route = await models.Route.findById(agencyTerm.routeFk);
+ await Self.rawSql(`
+ UPDATE vn.route SET invoiceInFk = ? WHERE id = ?
+ `, [newInvoiceIn.id, route.id]);
+ }
+ };
+};
diff --git a/modules/route/back/methods/agency-term/filter.js b/modules/route/back/methods/agency-term/filter.js
index 94ed7fc91..0b6e2635a 100644
--- a/modules/route/back/methods/agency-term/filter.js
+++ b/modules/route/back/methods/agency-term/filter.js
@@ -1,7 +1,4 @@
-
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
-const buildFilter = require('vn-loopback/util/filter').buildFilter;
-const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => {
Self.remoteMethodCtx('filter', {
@@ -13,54 +10,6 @@ module.exports = Self => {
type: 'object',
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
http: {source: 'query'}
- },
- {
- arg: 'search',
- type: 'string',
- description: 'Searchs the route by id',
- http: {source: 'query'}
- },
- {
- arg: 'agencyModeFk',
- type: 'integer',
- description: 'The agencyMode id',
- http: {source: 'query'}
- },
- {
- arg: 'to',
- type: 'date',
- description: 'The to date filter',
- http: {source: 'query'}
- },
- {
- arg: 'from',
- type: 'date',
- description: 'The to date filter',
- http: {source: 'query'}
- },
- {
- arg: 'vehicleFk',
- type: 'integer',
- description: 'The vehicle id',
- http: {source: 'query'}
- },
- {
- arg: 'm3',
- type: 'number',
- description: 'The m3 filter',
- http: {source: 'query'}
- },
- {
- arg: 'warehouseFk',
- type: 'number',
- description: 'The warehouse filter',
- http: {source: 'query'}
- },
- {
- arg: 'description',
- type: 'string',
- description: 'The description filter',
- http: {source: 'query'}
}
],
returns: {
@@ -73,70 +22,52 @@ module.exports = Self => {
}
});
- Self.filter = async(ctx, filter) => {
- let conn = Self.dataSource.connector;
-
- let where = buildFilter(ctx.args, (param, value) => {
- switch (param) {
- case 'search':
- return {'r.id': value};
- case 'from':
- return {'r.created': {gte: value}};
- case 'to':
- return {'r.created': {lte: value}};
- case 'm3':
- return {'r.m3': value};
- case 'description':
- return {'r.description': {like: `%${value}%`}};
- case 'warehouseFk':
- param = `v.${param}`;
- return {[param]: value};
- case 'vehicleFk':
- case 'agencyModeFk':
- param = `r.${param}`;
- return {[param]: value};
- }
- });
-
- filter = mergeFilters(ctx.args.filter, {where});
+ Self.filter = async(ctx, filter, options) => {
+ const conn = Self.dataSource.connector;
let stmts = [];
let stmt;
-
stmt = new ParameterizedSQL(
- `SELECT
- r.id routeFk,
- r.created,
- r.agencyModeFk,
- am.name agencyModeName,
- am.agencyFk,
- a.name agencyAgreement,
- SUM(t.packages) packages,
- r.m3,
- r.kmEnd - r.kmStart kmTotal,
- CAST(IFNULL(ate.routePrice,
- (ate.kmPrice * (GREATEST(r.kmEnd - r.kmStart , ate.minimumKm))
- + GREATEST(r.m3 , ate.minimumM3) * ate.m3Price)
- + ate.packagePrice * SUM(t.packages) )
- AS DECIMAL(10,2)) price,
- r.invoiceInFk,
- a.supplierFk,
- s.name supplierName
- FROM vn.route r
- LEFT JOIN vn.agencyMode am ON r.agencyModeFk = am.id
- LEFT JOIN vn.agency a ON am.agencyFk = a.id
- LEFT JOIN vn.ticket t ON t.routeFk = r.id
- LEFT JOIN vn.agencyTerm ate ON ate.agencyFk = a.id
- LEFT JOIN vn.supplier s ON s.id = a.supplierFk
- WHERE r.created > DATE_ADD(CURDATE(), INTERVAL -2 MONTH) AND a.supplierFk IS NOT NULL
- GROUP BY r.id;`
+ `SELECT *
+ FROM (
+ SELECT r.id routeFk,
+ r.created,
+ r.agencyModeFk,
+ am.name agencyModeName,
+ am.agencyFk,
+ a.name agencyAgreement,
+ SUM(t.packages) packages,
+ r.m3,
+ r.kmEnd - r.kmStart kmTotal,
+ CAST(IFNULL(ate.routePrice,
+ (ate.kmPrice * (GREATEST(r.kmEnd - r.kmStart , ate.minimumKm))
+ + GREATEST(r.m3 , ate.minimumM3) * ate.m3Price)
+ + ate.packagePrice * SUM(t.packages) )
+ AS DECIMAL(10,2)) price,
+ r.invoiceInFk,
+ a.supplierFk,
+ s.name supplierName
+ FROM vn.route r
+ LEFT JOIN vn.agencyMode am ON r.agencyModeFk = am.id
+ LEFT JOIN vn.agency a ON am.agencyFk = a.id
+ LEFT JOIN vn.ticket t ON t.routeFk = r.id
+ LEFT JOIN vn.agencyTerm ate ON ate.agencyFk = a.id
+ LEFT JOIN vn.supplier s ON s.id = a.supplierFk
+ WHERE r.created > DATE_ADD(CURDATE(), INTERVAL -2 MONTH) AND a.supplierFk IS NOT NULL
+ GROUP BY r.id
+ ) a`
);
stmt.merge(conn.makeSuffix(filter));
- let agencyTerm = stmts.push(stmt) - 1;
+ let agencyTerm = stmts.push(stmt) - 1;
let sql = ParameterizedSQL.join(stmts, ';');
let result = await conn.executeStmt(sql);
+
+ const models = Self.app.models;
+ for (let agencyTerm of result)
+ agencyTerm.route = await models.Route.findById(agencyTerm.routeFk);
+
return agencyTerm === 0 ? result : result[agencyTerm];
};
};
diff --git a/modules/route/back/models/agency-term.js b/modules/route/back/models/agency-term.js
index 14fe76d28..8a0eea655 100644
--- a/modules/route/back/models/agency-term.js
+++ b/modules/route/back/models/agency-term.js
@@ -1,3 +1,4 @@
module.exports = Self => {
require('../methods/agency-term/filter')(Self);
+ require('../methods/agency-term/createInvoiceIn')(Self);
};
diff --git a/modules/route/front/agency-term/createInvoiceIn/index.html b/modules/route/front/agency-term/createInvoiceIn/index.html
new file mode 100644
index 000000000..8f270378f
--- /dev/null
+++ b/modules/route/front/agency-term/createInvoiceIn/index.html
@@ -0,0 +1,108 @@
+
+ | Id | @@ -82,7 +93,6 @@ {{::agencyTerm.invoiceInFk}} - |
+
diff --git a/modules/route/front/agency-term/index/index.js b/modules/route/front/agency-term/index/index.js
new file mode 100644
index 000000000..c1089e1a7
--- /dev/null
+++ b/modules/route/front/agency-term/index/index.js
@@ -0,0 +1,127 @@
+import ngModule from '../../module';
+import Section from 'salix/components/section';
+import './style.scss';
+
+class Controller extends Section {
+ constructor($element, $) {
+ super($element, $);
+
+ this.smartTableOptions = {
+ activeButtons: {
+ search: true
+ },
+ columns: [
+ {
+ field: 'agencyFk',
+ autocomplete: {
+ url: 'AgencyModes',
+ showField: 'name',
+ valueField: 'name'
+ }
+ },
+ {
+ field: 'agencyAgreement',
+ autocomplete: {
+ url: 'Agencies',
+ showField: 'name',
+ valueField: 'name'
+ }
+ },
+ {
+ field: 'supplierFk',
+ autocomplete: {
+ url: 'Suppliers',
+ showField: 'name',
+ valueField: 'name',
+ }
+ }
+ ]
+ };
+ }
+
+ exprBuilder(param, value) {
+ switch (param) {
+ case 'routeFk':
+ return {'a.routeFk': value};
+ case 'created':
+ return {'a.created': value};
+ case 'agencyFk':
+ return {'a.agencyModeName': value};
+ case 'agencyAgreement':
+ return {'a.agencyAgreement': value};
+ case 'packages':
+ return {'a.packages': value};
+ case 'm3':
+ return {'a.m3': value};
+ case 'kmTotal':
+ return {'a.kmTotal': value};
+ case 'price':
+ return {'a.price': value};
+ case 'invoiceInFk':
+ return {'a.invoiceInFk': value};
+ case 'supplierFk':
+ return {'a.supplierName': value};
+ }
+ }
+
+ get checked() {
+ const agencyTerms = this.$.model.data || [];
+ const checkedAgencyTerms = [];
+ for (let agencyTerm of agencyTerms) {
+ if (agencyTerm.checked)
+ checkedAgencyTerms.push(agencyTerm);
+ }
+
+ return checkedAgencyTerms;
+ }
+
+ get totalChecked() {
+ return this.checked.length;
+ }
+
+ get totalPrice() {
+ let totalPrice = 0;
+
+ if (this.checked.length > 0) {
+ for (let agencyTerm of this.checked)
+ totalPrice += agencyTerm.price;
+
+ return totalPrice;
+ }
+
+ return totalPrice;
+ }
+
+ preview(route) {
+ this.routeSelected = route;
+ this.$.summary.show();
+ }
+
+ createInvoiceIn() {
+ const rowsToCreateInvoiceIn = [];
+ const supplier = this.checked[0].supplierFk;
+
+ for (let agencyTerm of this.checked) {
+ if (supplier == agencyTerm.supplierFk) {
+ rowsToCreateInvoiceIn.push({
+ routeFk: agencyTerm.routeFk,
+ supplierFk: agencyTerm.supplierFk,
+ created: agencyTerm.created,
+ totalPrice: this.totalPrice});
+ } else {
+ this.vnApp.showError(this.$t('Two autonomous cannot be counted at the same time'));
+ return false;
+ }
+ }
+ const params = JSON.stringify({
+ supplierName: this.checked[0].supplierName,
+ rows: rowsToCreateInvoiceIn
+ });
+ this.$state.go('route.agencyTerm.createInvoiceIn', {q: params});
+ }
+}
+
+ngModule.vnComponent('vnAgencyTermIndex', {
+ template: require('./index.html'),
+ controller: Controller
+});
diff --git a/modules/route/front/agency-term/index.spec.js b/modules/route/front/agency-term/index/index.spec.js
similarity index 100%
rename from modules/route/front/agency-term/index.spec.js
rename to modules/route/front/agency-term/index/index.spec.js
diff --git a/modules/route/front/agency-term/style.scss b/modules/route/front/agency-term/index/style.scss
similarity index 100%
rename from modules/route/front/agency-term/style.scss
rename to modules/route/front/agency-term/index/style.scss
diff --git a/modules/route/front/agency-term/preview.svg b/modules/route/front/agency-term/preview.svg
deleted file mode 100644
index 5d56b5f34..000000000
--- a/modules/route/front/agency-term/preview.svg
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
diff --git a/modules/route/front/index.js b/modules/route/front/index.js
index 206c97953..6a6518a43 100644
--- a/modules/route/front/index.js
+++ b/modules/route/front/index.js
@@ -11,4 +11,5 @@ import './create';
import './basic-data';
import './log';
import './tickets';
-import './agency-term';
+import './agency-term/index';
+import './agency-term/createInvoiceIn';
diff --git a/modules/route/front/routes.json b/modules/route/front/routes.json
index 307d0e941..1e7d94765 100644
--- a/modules/route/front/routes.json
+++ b/modules/route/front/routes.json
@@ -3,11 +3,11 @@
"name": "Routes",
"icon": "icon-delivery",
"validations" : true,
- "dependencies": ["client", "worker", "ticket"],
+ "dependencies": ["client", "worker", "ticket", "supplier", "invoiceIn"],
"menus": {
"main": [
{"state": "route.index", "icon": "icon-delivery"},
- {"state": "route.agencyTerm", "icon": "icon-delivery"}
+ {"state": "route.agencyTerm.index", "icon": "icon-delivery"}
],
"card": [
{"state": "route.card.basicData", "icon": "settings"},
@@ -39,11 +39,25 @@
"abstract": true,
"component": "vn-route-card"
}, {
- "url" : "/agency-term?q",
+ "url": "/agency-term",
+ "abstract": true,
"state": "route.agencyTerm",
- "component": "vn-agency-term",
+ "component": "ui-view"
+ }, {
+ "url": "/index",
+ "state": "route.agencyTerm.index",
+ "component": "vn-agency-term-index",
"description": "Autonomous",
"acl": ["administrative"]
+ },{
+ "url": "/createInvoiceIn?q",
+ "state": "route.agencyTerm.createInvoiceIn",
+ "component": "vn-agency-term-create-invoice-in",
+ "description": "Create invoiceIn",
+ "params": {
+ "route": "$ctrl.route"
+ },
+ "acl": ["administrative"]
}, {
"url": "/summary",
"state": "route.card.summary",
|
---|