Th refactor

This commit is contained in:
Joan Sanchez 2020-11-13 09:30:40 +01:00
parent 785453fab3
commit 4acdfd6d4e
11 changed files with 400 additions and 41 deletions

View File

@ -0,0 +1,94 @@
drop procedure `vn2008`.travelDetail;
create definer = root@`%` procedure `vn2008`.travelDetail__()
BEGIN
DECLARE vDateFrom DATE DEFAULT TIMESTAMPADD(WEEK,-12,CURDATE());
SELECT IFNULL(CONCAT(" ",Entrada),travel) travelAndEntry,
travel,
Entrada,
IsTravel,
Agencia,
ref,
shipment,
OrigenCajas,
landing,
Destino,
Etiquetas,
Notas_Eva,
kg,
loadedKg,
volumeKg,
loadPriority,
Notas,
Carguera
FROM(SELECT
1 as IsTravel,
tr.id as travel,
NULL as Entrada,
ag.Agencia,
tr.ref,
tr.shipment,
wo.name as OrigenCajas,
tr.landing,
w.name as Destino,
sum(c.Etiquetas) as Etiquetas,
NULL as Notas_Eva,
kg,
cast(sum(a.density * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as loadedKg,
cast(sum(167.5 * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as volumeKg,
NULL as loadPriority,
NULL as Notas,
pc.Alias as Carguera
FROM travel tr
LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk
LEFT JOIN Entradas e ON e.travel_id = tr.id
LEFT JOIN Compres c ON c.Id_Entrada = e.Id_Entrada
LEFT JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo
LEFT JOIN Articles a ON a.Id_Article = c.Id_Article
LEFT JOIN Tipos tp ON tp.tipo_id = a.tipo_id
JOIN warehouse w ON w.id = tr.warehouse_id
JOIN warehouse wo ON wo.id = tr.warehouse_id_out
JOIN Agencias ag ON ag.Id_Agencia = tr.agency_id
WHERE tr.landing >= vDateFrom AND (wo.name="Colombia" OR wo.name="Ecuador")
GROUP BY tr.id
UNION ALL
SELECT
0 as IsTravel,
e.travel_id as travel,
e.Id_Entrada,
p.Proveedor,
e.Referencia,
tr.shipment,
wo.name as OrigenCajas,
tr.landing,
w.name as Destino,
sum(Etiquetas) as Etiquetas,
e.Notas_Eva,
NULL as kg,
cast(sum(a.density * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as loadedkg,
cast(sum(167.5 * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as volumeKg,
loadPriority,
e.Notas,
pc.Alias as carguera
FROM Entradas e
JOIN Compres c ON c.Id_Entrada = e.Id_Entrada
JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo
JOIN Articles a ON a.Id_Article = c.Id_Article
JOIN Tipos tp ON tp.tipo_id = a.tipo_id
JOIN Proveedores p ON p.Id_Proveedor = e.Id_Proveedor
JOIN travel tr ON tr.id = e.travel_id
LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk
JOIN warehouse w ON w.id = tr.warehouse_id
JOIN warehouse wo ON wo.id = tr.warehouse_id_out
WHERE tr.landing >= vDateFrom AND (wo.name="Colombia" OR wo.name="Ecuador")
GROUP BY e.Id_Entrada
) sub
ORDER BY landing ASC, shipment ASC,travel, IsTravel DESC, (loadPriority > 0) DESC,loadPriority, Agencia, Notas_Eva ;
END;

View File

@ -22,28 +22,7 @@ vn-table {
& > * > vn-th[field] {
position: relative;
overflow: visible;
cursor: pointer;
&.active > :after {
color: $color-font;
opacity: 1;
}
&.desc > :after {
content: 'arrow_drop_down';
}
&.asc > :after {
content: 'arrow_drop_up';
}
& > :after {
font-family: 'Material Icons';
content: 'arrow_drop_down';
position: absolute;
color: $color-spacer;
opacity: 0;
}
&:hover > :after {
opacity: 1;
}
cursor: pointer
}
}
& > vn-tbody,

View File

@ -1,3 +1 @@
<div translate>
<ng-transclude></ng-transclude>
</div>
<div></div>

View File

@ -1,10 +1,19 @@
import ngModule from '../../module';
import Component from '../../lib/component';
import './style.scss';
export default class Th extends Component {
constructor($element, $, $transclude) {
super($element, $);
export default class Th {
constructor($element) {
this._order = 'ASC';
this.column = $element[0];
$element.on('click', () => this.onToggleOrder());
$transclude($clone => {
const text = this.$t($clone.text()); // Not updating translations
$element.append(text ? text : $clone);
});
}
/**
@ -54,7 +63,6 @@ export default class Th {
else
this.table.setOrder(this.field, this.order);
this.updateArrow();
this.table.applyOrder(this.field, this.order);
@ -73,10 +81,9 @@ export default class Th {
}
}
Th.$inject = ['$element'];
Th.$inject = ['$element', '$scope', '$transclude'];
ngModule.vnComponent('vnTh', {
template: require('./index.html'),
transclude: true,
controller: Th,
bindings: {

View File

@ -0,0 +1,33 @@
@import "effects";
@import "variables";
vn-th {
font-weight: normal;
}
vn-th[field] {
&.active:after {
color: $color-font;
opacity: 1;
}
&.desc:after {
content: 'arrow_drop_down';
}
&.asc:after {
content: 'arrow_drop_up';
}
&:after {
font-family: 'Material Icons';
content: 'arrow_drop_down';
position: absolute;
color: $color-spacer;
font-size: 1.5em;
margin-top: -2px;
opacity: 0
}
&:hover:after {
opacity: 1;
}
}

View File

@ -34,9 +34,6 @@
"stickers": {
"type": "number"
},
"packageFk": {
"type": "number"
},
"groupingMode": {
"type": "number"
},
@ -68,6 +65,11 @@
"model": "Item",
"foreignKey": "itemFk",
"required": true
}
},
"package": {
"type": "belongsTo",
"model": "Packaging",
"foreignKey": "packageFk"
}
}
}

View File

@ -0,0 +1,227 @@
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('extraCommunityFilter', {
description: 'Find all instances of the model matched by filter from the data source.',
accessType: 'READ',
accepts: [
{
arg: 'filter',
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 travel by id',
http: {source: 'query'}
}, {
arg: 'id',
type: 'Integer',
description: 'The travel id',
http: {source: 'query'}
}, {
arg: 'shippedFrom',
type: 'Date',
description: 'The shipped from date filter',
http: {source: 'query'}
}, {
arg: 'shippedTo',
type: 'Date',
description: 'The shipped to date filter',
http: {source: 'query'}
}, {
arg: 'landedFrom',
type: 'Date',
description: 'The landed from date filter',
http: {source: 'query'}
}, {
arg: 'landedTo',
type: 'Date',
description: 'The landed to date filter',
http: {source: 'query'}
}, {
arg: 'agencyFk',
type: 'Number',
description: 'The agencyModeFk id',
http: {source: 'query'}
}, {
arg: 'warehouseOutFk',
type: 'Number',
description: 'The warehouseOutFk filter',
http: {source: 'query'}
}, {
arg: 'warehouseInFk',
type: 'Number',
description: 'The warehouseInFk filter',
http: {source: 'query'}
}, {
arg: 'totalEntries',
type: 'Number',
description: 'The totalEntries filter',
http: {source: 'query'}
}, {
arg: 'ref',
type: 'string',
description: 'The reference'
}
],
returns: {
type: ['Object'],
root: true
},
http: {
path: `/extraCommunityFilter`,
verb: 'GET'
}
});
Self.extraCommunityFilter = async(ctx, filter) => {
let conn = Self.dataSource.connector;
let where = buildFilter(ctx.args, (param, value) => {
switch (param) {
case 'search':
return /^\d+$/.test(value)
? {'t.id': value}
: {'t.ref': {like: `%${value}%`}};
case 'ref':
return {'t.ref': {like: `%${value}%`}};
case 'shippedFrom':
return {'t.shipped': {gte: value}};
case 'shippedTo':
return {'t.shipped': {lte: value}};
case 'landedFrom':
return {'t.landed': {gte: value}};
case 'landedTo':
return {'t.landed': {lte: value}};
case 'id':
case 'agencyFk':
case 'warehouseOutFk':
case 'warehouseInFk':
case 'totalEntries':
param = `t.${param}`;
return {[param]: value};
}
});
filter = mergeFilters(ctx.args.filter, {where});
let stmts = [];
let stmt;
stmt = new ParameterizedSQL(
`SELECT
tr.id,
tr.ref,
tr.shipped,
tr.landed,
tr.kg,
am.id AS agencyModeFk,
am.name AS agencyModeName,
wo.id AS warehouseOutFk,
wo.name AS warehouseOutName,
w.name AS warehouseInFk,
w.name AS warehouseInName,
SUM(b.stickers) AS stickers,
s.id AS supplierFk,
s.nickname AS supplierNickname
FROM travel tr
LEFT JOIN supplier s ON s.id = tr.cargoSupplierFk
LEFT JOIN entry e ON e.travelFk = tr.id
LEFT JOIN buy b ON b.entryFk = e.id
LEFT JOIN packaging p ON p.id = b.packageFk
LEFT JOIN item i ON i.id = b.itemFk
LEFT JOIN itemType it ON it.id = i.typeFk
JOIN warehouse w ON w.id = tr.warehouseInFk
JOIN warehouse wo ON wo.id = tr.warehouseOutFk
JOIN agencyMode am ON am.id = tr.agencyFk`
);
/* cast(sum(a.density * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as loadedKg,
cast(sum(167.5 * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as volumeKg,
pc.Alias as Carguera */
// WHERE tr.landing >= @vDateFrom AND (wo.name="Colombia" OR wo.name="Ecuador")
stmt.merge('GROUP BY tr.id');
// stmt.merge(conn.makeSuffix(filter));
const itemsIndex = stmts.push(stmt) - 1;
const sql = ParameterizedSQL.join(stmts, ';');
const result = await conn.executeStmt(sql);
return itemsIndex === 0 ? result : result[itemsIndex];
/*
SET @vDateFrom:= TIMESTAMPADD(WEEK,-12,CURDATE());
SELECT
1 as IsTravel,
tr.id as travel,
NULL as Entrada,
ag.Agencia,
tr.ref,
tr.shipment,
wo.name as OrigenCajas,
tr.landing,
w.name as Destino,
sum(c.Etiquetas) as Etiquetas,
NULL as Notas_Eva,
kg,
cast(sum(a.density * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as loadedKg,
cast(sum(167.5 * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as volumeKg,
NULL as loadPriority,
NULL as Notas,
pc.Alias as Carguera
FROM travel tr
LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk
LEFT JOIN Entradas e ON e.travel_id = tr.id
LEFT JOIN Compres c ON c.Id_Entrada = e.Id_Entrada
LEFT JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo
LEFT JOIN Articles a ON a.Id_Article = c.Id_Article
LEFT JOIN Tipos tp ON tp.tipo_id = a.tipo_id
JOIN warehouse w ON w.id = tr.warehouse_id
JOIN warehouse wo ON wo.id = tr.warehouse_id_out
JOIN Agencias ag ON ag.Id_Agencia = tr.agency_id
WHERE tr.landing >= @vDateFrom AND (wo.name="Colombia" OR wo.name="Ecuador")
GROUP BY tr.id
UNION ALL
SELECT
0 as IsTravel,
e.travel_id as travel,
e.Id_Entrada,
p.Proveedor,
e.Referencia,
tr.shipment,
wo.name as OrigenCajas,
tr.landing,
w.name as Destino,
sum(Etiquetas) as Etiquetas,
e.Notas_Eva,
NULL as kg,
cast(sum(a.density * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as loadedkg,
cast(sum(167.5 * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as volumeKg,
loadPriority,
e.Notas,
pc.Alias as carguera
FROM Entradas e
JOIN Compres c ON c.Id_Entrada = e.Id_Entrada
JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo
JOIN Articles a ON a.Id_Article = c.Id_Article
JOIN Tipos tp ON tp.tipo_id = a.tipo_id
JOIN Proveedores p ON p.Id_Proveedor = e.Id_Proveedor
JOIN travel tr ON tr.id = e.travel_id
LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk
JOIN warehouse w ON w.id = tr.warehouse_id
JOIN warehouse wo ON wo.id = tr.warehouse_id_out
WHERE tr.landing >= @vDateFrom AND (wo.name="Colombia" OR wo.name="Ecuador")
GROUP BY e.Id_Entrada
) sub
ORDER BY landing ASC, shipment ASC,travel, IsTravel DESC, (loadPriority > 0) DESC,loadPriority, Agencia, Notas_Eva ; */
};
};

View File

@ -7,6 +7,7 @@ module.exports = Self => {
require('../methods/travel/createThermograph')(Self);
require('../methods/travel/deleteThermograph')(Self);
require('../methods/travel/updateThermograph')(Self);
require('../methods/travel/extraCommunityFilter')(Self);
Self.rewriteDbError(function(err) {
if (err.code === 'ER_DUP_ENTRY')

View File

@ -1,15 +1,32 @@
<vn-crud-model auto-load="true"
vn-id="model"
url="Items/getWasteDetail"
data="details">
url="Travels/extraCommunityFilter"
data="travels">
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
vn-focus
placeholder="Search by travel id"
info="Search by travel id"
auto-state="false"
model="model">
</vn-searchbar>
</vn-portal>
<vn-data-viewer model="model">
<vn-card>
<section ng-repeat="detail in details" class="vn-pa-md">
<section ng-repeat="travel in travels" class="vn-pa-md">
<vn-horizontal class="header">
<h5><span translate>{{detail.buyer}}</span></h5>
<vn-table>
<vn-thead>
<vn-tr>
<vn-th>{{travel.id}}</vn-th>
<vn-th>{{travel.supplierNickname}}</vn-th>
</vn-tr>
</vn-thead>
</vn-table>
<!-- <h5><span></span></h5> -->
</vn-horizontal>
<vn-table>
<!-- <vn-table>
<vn-thead>
<vn-tr>
<vn-th class="waste-family">Family</vn-th>
@ -26,7 +43,7 @@
<vn-td number>{{::waste.total | currency: 'EUR'}}</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-table> -->
</section>
</vn-card>
</vn-data-viewer>

View File

@ -1,6 +1,6 @@
@import "variables";
vn-item-waste {
vn-travel-extra-community {
.header {
margin-bottom: 16px;
text-transform: uppercase;

View File

@ -13,3 +13,4 @@ import './thermograph/index/';
import './thermograph/create/';
import './thermograph/edit/';
import './descriptor-popover';
import './extra-community';