refs #4700 arreglar filtro y traducciones
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alexandre Riera 2022-11-07 15:55:17 +01:00
parent 33c92a0f24
commit 896a7eb6f0
18 changed files with 776 additions and 2 deletions

View File

@ -0,0 +1,9 @@
DROP PROCEDURE IF EXISTS vn.ticket_canMerge;
DELIMITER $$
$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canMerge`(vDated DATE, vScopeDays INT, vLitersMax INT, vLinesMax INT, vWarehouseFk INT)
BEGIN
CALL vn.ticket_canbePostponed(vDated,TIMESTAMPADD(DAY, vScopeDays, vDated),vLitersMax,vLinesMax,vWarehouseFk);
END $$
DELIMITER ;

View File

@ -0,0 +1,75 @@
DROP PROCEDURE IF EXISTS vn.ticket_canbePostponed;
DELIMITER $$
$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canbePostponed`(vOriginDated DATE, vFutureDated DATE, vLitersMax INT, vLinesMax INT, vWarehouseFk INT)
BEGIN
/**
* Devuelve un listado de tickets susceptibles de fusionarse con otros tickets en el futuro
*
* @param vOriginDated Fecha en cuestión
* @param vFutureDated Fecha en el futuro a sondear
* @param vLitersMax Volumen máximo de los tickets a catapultar
* @param vLinesMax Número máximo de lineas de los tickets a catapultar
* @param vWarehouseFk Identificador de vn.warehouse
*/
DROP TEMPORARY TABLE IF EXISTS tmp.filter;
CREATE TEMPORARY TABLE tmp.filter
(INDEX (id))
SELECT sv.ticketFk id,
GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt,
CAST(sum(litros) AS DECIMAL(10,0)) liters,
CAST(count(*) AS DECIMAL(10,0)) `lines`,
st.name state,
sub2.id ticketFuture,
t.landed originETD,
sub2.landed destETD,
sub2.iptd tfIpt,
sub2.state tfState,
t.clientFk,
t.warehouseFk,
ts.alertLevel,
t.shipped,
sub2.shipped tfShipped,
t.workerFk
FROM vn.saleVolume sv
JOIN vn.sale s ON s.id = sv.saleFk
JOIN vn.item i ON i.id = s.itemFk
JOIN vn.ticket t ON t.id = sv.ticketFk
JOIN vn.address a ON a.id = t.addressFk
JOIN vn.province p ON p.id = a.provinceFk
JOIN vn.country c ON c.id = p.countryFk
JOIN vn.ticketState ts ON ts.ticketFk = t.id
JOIN vn.state st ON st.id = ts.stateFk
JOIN vn.alertLevel al ON al.id = ts.alertLevel
LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id
LEFT JOIN (
SELECT *
FROM (
SELECT
t.addressFk ,
t.id,
t.landed,
t.shipped,
st.name state,
GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) iptd
FROM vn.ticket t
JOIN vn.ticketState ts ON ts.ticketFk = t.id
JOIN vn.state st ON st.id = ts.stateFk
JOIN vn.sale s ON s.ticketFk = t.id
JOIN vn.item i ON i.id = s.itemFk
WHERE t.shipped BETWEEN vFutureDated
AND util.dayend(vFutureDated)
AND t.warehouseFk = vWarehouseFk
GROUP BY t.id
) sub
GROUP BY sub.addressFk
) sub2 ON sub2.addressFk = t.addressFk AND t.id != sub2.id
WHERE t.shipped BETWEEN vOriginDated AND util.dayend(vOriginDated)
AND t.warehouseFk = vWarehouseFk
AND al.code = 'FREE'
AND tp.ticketFk IS NULL
GROUP BY sv.ticketFk
HAVING liters <= IFNULL(vLitersMax, 9999) AND `lines` <= IFNULL(vLinesMax, 9999) AND ticketFuture;
END$$
DELIMITER ;

View File

@ -237,5 +237,6 @@
"Modifiable password only via recovery or by an administrator": "Contraseña modificable solo a través de la recuperación o por un administrador",
"Not enough privileges to edit a client": "No tienes suficientes privilegios para editar un cliente",
"You don't have grant privilege": "No tienes privilegios para dar privilegios",
"You don't own the role and you can't assign it to another user": "No eres el propietario del rol y no puedes asignarlo a otro usuario"
"You don't own the role and you can't assign it to another user": "No eres el propietario del rol y no puedes asignarlo a otro usuario",
"MOVE_TICKET_CONFIRMATION": "Ticket {{id}} ({{originDated}}) fusionado con {{tfId}} ({{futureDated}}) [{{fullPath}}]"
}

View File

@ -0,0 +1,179 @@
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('getTicketsFuture', {
description: 'Find all instances of the model matched by filter from the data source.',
accessType: 'READ',
accepts: [
{
arg: 'originDated',
type: 'date',
description: 'The date in question',
required: true
},
{
arg: 'futureDated',
type: 'date',
description: 'The date to probe',
required: true
},
{
arg: 'litersMax',
type: 'number',
description: 'Maximum volume of tickets to catapult',
required: true
},
{
arg: 'linesMax',
type: 'number',
description: 'Maximum number of lines of tickets to catapult',
required: true
},
{
arg: 'warehouseFk',
type: 'number',
description: 'Warehouse identifier',
required: true
},
{
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: `/getTicketsFuture`,
verb: 'GET'
}
});
Self.getTicketsFuture = async (ctx, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const conn = Self.dataSource.connector;
const args = ctx.args;
const stmts = [];
let stmt;
stmt = new ParameterizedSQL(
`CALL vn.ticket_canbePostponed(?,?,?,?,?)`,
[args.originDated, args.futureDated, args.litersMax, args.linesMax, args.warehouseFk]);
stmts.push(stmt);
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.sale_getProblems');
stmt = new ParameterizedSQL(`
CREATE TEMPORARY TABLE tmp.sale_getProblems
(INDEX (ticketFk))
ENGINE = MEMORY
SELECT f.id ticketFk, f.clientFk, f.warehouseFk, f.shipped
FROM tmp.filter f
LEFT JOIN alertLevel al ON al.id = f.alertLevel
WHERE (al.code = 'FREE' OR f.alertLevel IS NULL)`);
stmts.push(stmt);
stmts.push('CALL ticket_getProblems(FALSE)');
stmt = new ParameterizedSQL(`
SELECT f.*, tp.*
FROM tmp.filter f
LEFT JOIN tmp.ticket_problems tp ON tp.ticketFk = f.id`);
if (args.problems != undefined && (!args.from && !args.to))
throw new UserError('Choose a date range or days forward');
const myWhere = buildFilter(ctx.args, (param, value) => {
switch (param) {
// case 'search':
// return /^\d+$/.test(value)
// ? {'t.id': {inq: value}}
// : {'t.nickname': {like: `%${value}%`}};
case 'shipped':
return {'shipped': {like: `%${value}%`}};
// case 'refFk':
// return {'t.refFk': value};
// case 'provinceFk':
// return {'t.provinceFk': value};
// case 'stateFk':
// return {'t.stateFk': value};
// case 'alertLevel':
// return {'t.alertLevel': value};
// case 'pending':
// if (value) {
// return {and: [
// {'t.alertLevel': 0},
// {'t.alertLevelCode': {nin: [
// 'OK',
// 'BOARDING',
// 'PRINTED',
// 'PRINTED_AUTO',
// 'PICKER_DESIGNED'
// ]}}
// ]};
// } else {
// return {and: [
// {'t.alertLevel': {gt: 0}}
// ]};
// }
// case 'agencyModeFk':
// case 'warehouseFk':
// param = `t.${param}`;
// return {[param]: value};
}
});
let finalFilter = {};
finalFilter = mergeFilters(finalFilter, {where: myWhere});
if (finalFilter.where)
stmt.merge(conn.makeWhere(finalFilter.where));
let condition;
let hasProblem;
let range;
let hasWhere;
switch (args.problems) {
case true:
condition = `or`;
hasProblem = true;
range = {neq: null};
hasWhere = true;
break;
case false:
condition = `and`;
hasProblem = null;
range = null;
hasWhere = true;
break;
}
const problems = {[condition]: [
{'tp.isFreezed': hasProblem},
{'tp.risk': hasProblem},
{'tp.hasTicketRequest': hasProblem},
{'tp.itemShortage': range}
]};
if (hasWhere)
stmt.merge(conn.makeWhere(problems));
const ticketsIndex = stmts.push(stmt) - 1;
stmts.push(
`DROP TEMPORARY TABLE
tmp.filter,
tmp.ticket_problems`);
const sql = ParameterizedSQL.join(stmts, ';');
const result = await conn.executeStmt(sql, myOptions);
return result[ticketsIndex];
};
};

View File

@ -0,0 +1,68 @@
const LoopBackContext = require('loopback-context');
module.exports = Self => {
Self.remoteMethodCtx('moveTicketsFuture', {
description: 'Move specified tickets to the future',
accessType: 'WRITE',
accepts: [
{
arg: 'tickets',
type: ['object'],
description: 'The array of tickets',
required: false
}
],
returns: {
type: 'string',
root: true
},
http: {
path: `/moveTicketsFuture`,
verb: 'POST'
}
});
Self.moveTicketsFuture = async (ctx, tickets, options) => {
const loopBackContext = LoopBackContext.getCurrentContext();
const httpCtx = {req: loopBackContext.active};
const models = Self.app.models;
const myOptions = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
for (let ticket of tickets) {
console.log(ticket);
try {
if(!ticket.id || !ticket.ticketFuture) continue;
await models.Sale.updateAll({ticketFk: ticket.id}, {ticketFk: ticket.ticketFuture}, myOptions);
await models.Ticket.setDeleted(ctx, ticket.id, myOptions);
if (tx)
{
const httpRequest = httpCtx.req.http.req;
const $t = httpRequest.__;
const origin = httpRequest.headers.origin;
const fullPath = `${origin}/#!/ticket/${ticket.ticketFuture}/summary`;
const message = $t('MOVE_TICKET_CONFIRMATION', {
originDated: new Date(ticket.originETD).toLocaleDateString('es-ES'),
futureDated: new Date(ticket.destETD).toLocaleDateString('es-ES'),
id: ticket.id,
tfId: ticket.ticketFuture,
fullPath
});
await tx.commit();
await models.Chat.sendCheckingPresence(httpCtx, ticket.workerFk, message);
}
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};
};

View File

@ -91,5 +91,8 @@
},
"TicketConfig": {
"dataSource": "vn"
},
"TicketFuture": {
"dataSource": "vn"
}
}

View File

@ -0,0 +1,12 @@
{
"name": "TicketFuture",
"base": "PersistedModel",
"acls": [
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
]
}

View File

@ -4,6 +4,8 @@ const LoopBackContext = require('loopback-context');
module.exports = Self => {
// Methods
require('./ticket-methods')(Self);
require('../methods/ticket-future/getTicketsFuture')(Self);
require('../methods/ticket-future/moveTicketsFuture')(Self);
Self.observe('before save', async function(ctx) {
const loopBackContext = LoopBackContext.getCurrentContext();

View File

@ -0,0 +1,86 @@
<div class="search-panel">
<form id="manifold-form" ng-submit="$ctrl.onSearch()">
<vn-horizontal class="vn-px-lg vn-pt-lg">
<vn-date-picker
vn-one
label="Origin date"
ng-model="filter.shipped"
on-change="$ctrl.from = value">
</vn-date-picker>
<vn-date-picker
vn-one
label="Destination date"
ng-model="filter.tfShipped">
</vn-date-picker>
</vn-horizontal>
<vn-horizontal class="vn-px-lg">
<vn-date-picker
vn-one
label="Origin ETD"
ng-model="filter.originDated"
required="true">
</vn-date-picker>
<vn-date-picker
vn-one
label="Destination ETD"
ng-model="filter.futureDated"
required="true">
</vn-date-picker>
</vn-horizontal>
<vn-horizontal class="vn-px-lg">
<vn-textfield
vn-one
label="Max Lines Origin"
ng-model="filter.linesMax"
required="true">
</vn-textfield>
<vn-textfield
vn-one
label="Max Liters Origin"
ng-model="filter.litersMax"
required="true">
</vn-textfield>
</vn-horizontal>
<vn-horizontal class="vn-px-lg">
<vn-textfield
vn-one
label="Origin ITP"
ng-model="filter.ITP">
</vn-textfield>
<vn-textfield
vn-one
label="Destination ITP"
ng-model="filter.tfITP">
</vn-textfield>
</vn-horizontal>
<vn-horizontal class="vn-px-lg">
<vn-textfield
vn-one
label="Origin Agrupated State"
ng-model="filter.state">
</vn-textfield>
<vn-textfield
vn-one
label="Destination Agrupated State"
ng-model="filter.tfState">
</vn-textfield>
</vn-horizontal>
<vn-horizontal class="vn-px-lg">
<vn-check
vn-one
label="With problems"
ng-model="filter.problems"
triple-state="true">
</vn-check>
<vn-textfield
vn-one
label="Warehouse"
ng-model="filter.warehouseFk"
required="true">
</vn-textfield>
</vn-horizontal>
<vn-horizontal class="vn-px-lg vn-pb-lg vn-mt-lg">
<vn-submit label="Search"></vn-submit>
</vn-horizontal>
</form>
</div>

View File

@ -0,0 +1,30 @@
import ngModule from '../module';
import SearchPanel from 'core/components/searchbar/search-panel';
class Controller extends SearchPanel {
constructor($, $element) {
super($, $element);
this.filter = this.$.filter;
}
get from() {
return this._from;
}
set from(value) {
this._from = value;
}
get to() {
return this._to;
}
set to(value) {
this._to = value;
}
}
ngModule.vnComponent('vnFutureTicketSearchPanel', {
template: require('./index.html'),
controller: Controller
});

View File

@ -0,0 +1 @@
Future tickets: Tickets a futuro

View File

@ -0,0 +1,13 @@
Future tickets: Tickets a futuro
Origin date: Fecha origen
Destination date: Fecha destino
Origin ETD: ETD origen
Destination ETD: ETD destino
Max Lines Origin: Líneas máx. origen
Max Liters Origin: Litros máx. origen
Origin ITP: ITP origen
Destination ITP: ITP destino
With problems: Con problemas
Warehouse: Almacén
Origin Agrupated State: Estado agrupado origen
Destination Agrupated State: Estado agrupado destino

View File

@ -0,0 +1,164 @@
<vn-crud-model
vn-id="model"
url="Tickets/getTicketsFuture"
filter="::$ctrl.filter"
limit="20">
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
vn-focus
panel="vn-future-ticket-search-panel"
placeholder="Search tickets"
info="Search future tickets by date"
auto-state="false"
model="model"
filter="$ctrl.defaultFilter">
</vn-searchbar>
</vn-portal>
<vn-card>
<smart-table
model="model"
options="$ctrl.smartTableOptions"
>
<slot-actions>
<vn-button disabled="$ctrl.checked.length === 0"
icon="double_arrow"
ng-click="moveTicketsFuture.show($event)"
vn-tooltip="Future tickets">
</vn-button>
</slot-actions>
<slot-table>
<table>
<thead>
<tr>
<th shrink>
<vn-multi-check
model="model"
checked="$ctrl.checkAll"
check-field="checked">
</vn-multi-check>
</th>
<th field="problems">
<span translate>Problems</span>
</th>
<th field="id">
<span translate>Origin ID</span>
</th>
<th field="originDated">
<span translate>Origin ETD</span>
</th>
<th field="state">
<span translate>Origin State</span>
</th>
<th field="ipt">
<span>IPT</span>
</th>
<th field="liters">
<span translate>Liters</span>
</th>
<th field="lines">
<span translate>Available Lines</span>
</th>
<th field="ticketFuture">
<span translate>Destination ID</span>
</th>
<th field="tfETD">
<span translate>Destination ETD</span>
</th>
<th field="tfState">
<span translate>Destination State</span>
</th>
<th field="tfIpt">
<span>IPT</span>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="ticket in model.data">
<td>
<vn-check
ng-model="ticket.checked"
vn-click-stop>
</vn-check>
</td>
<td class="icon-field">
<vn-icon
ng-show="::ticket.isTaxDataChecked === 0"
translate-attr="{title: 'No verified data'}"
class="bright"
icon="icon-no036">
</vn-icon>
<vn-icon
ng-show="::ticket.hasTicketRequest"
translate-attr="{title: 'Purchase request'}"
class="bright"
icon="icon-buyrequest">
</vn-icon>
<vn-icon
ng-show="::ticket.itemShortage"
translate-attr="{title: 'Not visible'}"
class="bright"
icon="icon-unavailable">
</vn-icon>
<vn-icon
ng-show="::ticket.isFreezed"
translate-attr="{title: 'Client frozen'}"
class="bright"
icon="icon-frozen">
</vn-icon>
<vn-icon
ng-show="::ticket.risk"
title="{{::$ctrl.$t('Risk')}}: {{ticket.risk}}"
class="bright"
icon="icon-risk">
</vn-icon>
<vn-icon
ng-show="::ticket.hasComponentLack"
translate-attr="{title: 'Component lack'}"
class="bright"
icon="icon-components">
</vn-icon>
</td>
<td><span
ng-click="ticketDescriptor.show($event, ticket.id)"
class="link">
{{::ticket.id}}
</span></td>
<td shrink-date>
<span class="chip {{$ctrl.compareDate(ticket.originETD)}}">{{::ticket.originETD | date: 'dd/MM/yyyy'}}</span>
</td>
<td><span
class="chip {{$ctrl.stateColor(ticket.state)}}">
{{::ticket.state}}
</span></td>
<td>{{::ticket.ipt}}</td>
<td>{{::ticket.liters}}</td>
<td>{{::ticket.lines}}</td>
<td><span
ng-click="ticketDescriptor.show($event, ticket.ticketFuture)"
class="link">
{{::ticket.ticketFuture}}
</span></td>
<td shrink-date>
<span class="chip {{$ctrl.compareDate(ticket.destETD)}}">{{::ticket.destETD | date: 'dd/MM/yyyy'}}</span>
</td>
<td><span
class="chip {{$ctrl.stateColor(ticket.tfState)}}">
{{::ticket.tfState}}
</span></td>
<td>{{::ticket.tfIpt}}</td>
</tr>
</tbody>
</table>
</slot-table>
</smart-table>
</vn-card>
<vn-confirm
vn-id="moveTicketsFuture"
on-accept="$ctrl.moveTicketsFuture()"
question="Do you want to move {{$ctrl.checked.length}} ticket to the future?"
message="Move tickets">
</vn-confirm>
<vn-ticket-descriptor-popover
vn-id="ticketDescriptor">
</vn-ticket-descriptor-popover>

View File

@ -0,0 +1,107 @@
import ngModule from '../module';
import Section from 'salix/components/section';
export default class Controller extends Section {
constructor($element, $) {
super($element, $);
this.$checkAll = false;
const originDated = new Date();
const futureDated = new Date();
const warehouseFk = 1;
const litersMax = 9999;
const linesMax = 9999;
this.defaultFilter = {
originDated,
futureDated,
warehouseFk,
litersMax,
linesMax
};
this.smartTableOptions = {
activeButtons: {
search: true
},
columns: [{
field:'problems',
searchable: false
},
{
field:'ETD',
searchable: false
},
{
field:'tfETD',
searchable: false
}]
};
}
get checked() {
const tickets = this.$.model.data || [];
const checkedLines = [];
for (let ticket of tickets) {
if (ticket.checked)
checkedLines.push(ticket);
}
return checkedLines;
}
moveTicketsFuture()
{
let params = {
tickets: this.checked
};
this.$http.post('Tickets/moveTicketsFuture', params);
this.reload();
}
compareDate(date) {
let today = new Date();
today.setHours(0, 0, 0, 0);
let timeTicket = new Date(date);
timeTicket.setHours(0, 0, 0, 0);
let comparation = today - timeTicket;
if (comparation == 0)
return 'warning';
if (comparation < 0)
return 'success';
}
stateColor(state) {
if (state === 'OK')
return 'success';
else if (state === 'FREE')
return 'notice';
}
exprBuilder(param, value) {
switch (param) {
case 'shipped':
return {'shipped': {like: `%${value}%`}};
}
}
dateRange(value) {
const minHour = new Date(value);
minHour.setHours(0, 0, 0, 0);
const maxHour = new Date(value);
maxHour.setHours(23, 59, 59, 59);
return [minHour, maxHour];
}
reload() {
this.$.model.refresh();
}
}
ngModule.vnComponent('vnTicketFuture', {
template: require('./index.html'),
controller: Controller
});

View File

@ -0,0 +1,15 @@
Future tickets: Tickets a futuro
Search tickets: Buscar tickets
Search future tickets by date: Buscar tickets por fecha
Problems: Problemas
Origin ID: ID origen
Closing: Cierre
Origin State: Estado origen
Destination State: Estado destino
Liters: Litros
Available Lines: Líneas disponibles
Destination ID: ID destino
Destination ETD: ETD Destino
Origin ETD: ETD Origen
Move tickets: Mover tickets
Move confirmation: ¿Desea mover {0} tickets hacia el futuro?

View File

View File

@ -34,3 +34,5 @@ import './dms/create';
import './dms/edit';
import './sms';
import './boxing';
import './future';
import './future-search-panel';

View File

@ -7,7 +7,8 @@
"menus": {
"main": [
{"state": "ticket.index", "icon": "icon-ticket"},
{"state": "ticket.weekly.index", "icon": "schedule"}
{"state": "ticket.weekly.index", "icon": "schedule"},
{"state": "ticket.future", "icon": "double_arrow"}
],
"card": [
{"state": "ticket.card.basicData.stepOne", "icon": "settings"},
@ -283,6 +284,12 @@
"params": {
"ticket": "$ctrl.ticket"
}
},
{
"url": "/future",
"state": "ticket.future",
"component": "vn-ticket-future",
"description": "Future tickets"
}
]
}