stowaway refactor
gitea/salix/1913-stowaway_unboarding This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-12-17 08:38:36 +01:00
parent 7a2240b595
commit ef95244d07
25 changed files with 264 additions and 220 deletions

View File

@ -0,0 +1,33 @@
DROP TRIGGER IF EXISTS `vn`.`expedition_beforeInsert`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`expedition_beforeInsert`
BEFORE INSERT ON `expedition` FOR EACH ROW
BEGIN
DECLARE intcounter INT;
DECLARE vShipFk INT;
IF NEW.isBox > 0 THEN
UPDATE ticket SET packages = nz(packages) + 1 WHERE id = NEW.ticketFk;
SELECT IFNULL(MAX(counter),0) +1 INTO intcounter
FROM expedition e
INNER JOIN ticket t1 ON e.ticketFk = t1.id
LEFT JOIN ticketState ts ON ts.ticket = t1.id
INNER JOIN ticket t2 ON t2.addressFk = t1.addressFk AND DATE(t2.shipped) = DATE(t1.shipped)
AND t1.warehouseFk = t2.warehouseFk
WHERE t2.id = NEW.ticketFk AND ts.alertLevel < 3 AND t1.companyFk = t2.companyFk
AND t1.agencyModeFk = t2.agencyModeFk;
SET NEW.`counter` = intcounter;
END IF;
SELECT shipFk INTO vShipFk FROM stowaway WHERE id = NEW.ticketFk;
IF vShipFk THEN
CALL stowaway_unboarding(vShipFk, NEW.ticketFk);
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,31 @@
USE `vn`;
DROP procedure IF EXISTS `vn`.`stowawayUnBoarding`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `stowaway_unboarding`(vShipFk INT, vStowawayFk INT)
BEGIN
DECLARE vWorker VARCHAR(255);
DELETE FROM stowaway
WHERE shipFk = vShipFk AND id = vStowawayFk;
DELETE tt FROM ticketTracking tt
JOIN state s ON s.id = tt.stateFk
WHERE code = 'BOARDING' AND ticketFk = vShipFk;
DELETE FROM sale
WHERE ticketFk = vShipFk
AND itemFk = 98
AND concept = CONCAT('POLIZÓN! ',vStowawayFk);
SELECT u.`name` INTO vWorker
FROM account.user u JOIN worker w ON w.userFk = u.id
WHERE w.id = client_getSalesPersonByTicket(vStowawayFk);
SELECT messageSend(vWorker,CONCAT('El ticket: ', vStowawayFk, ' ha dejado de ser un polizón')) INTO @a;
END$$
DELIMITER ;
;

View File

@ -7,7 +7,7 @@ Claimed ticket: Ticket reclamado
Delete claim: Eliminar reclamación
Observation: Observación
Responsible: Responsable
Remove sale: Borrar linea
Remove sale: Eliminar linea
Claim Id: Id reclamación
Created: Creado
Send Pickup order: Enviar orden de recogida

View File

@ -18,7 +18,7 @@ Sent: Enviado
Worker: Trabajador
Sample: Plantilla
Credit: Crédito
Are you sure you want to delete this expedition?: ¿Está seguro de borrar esta expedición?
Are you sure you want to delete this expedition?: ¿Está seguro de eliminar esta expedición?
Others: Otros
New order: Nuevo pedido
Client frozen: Cliente congelado

View File

@ -3,7 +3,7 @@ Volume: Volumen
Client card: Ficha del cliente
Invoice ticket list: Listado de tickets de la factura
Show invoice PDF: Ver factura en PDF
Delete Invoice: Borrar factura
Delete Invoice: Eliminar factura
InvoiceOut deleted: Factura eliminada
Are you sure you want to delete this invoice?: Estas seguro de eliminar esta factura?
Book invoice: Asentar factura

View File

@ -7,6 +7,6 @@ Items: Articulos
Agency: Agencia
Sales person: Comercial
Order ticket list: Ticket del pedido
Delete order: Borrar pedido
You are going to delete this order: El pedido se borrará
Delete order: Eliminar pedido
You are going to delete this order: El pedido se eliminará
continue anyway?: ¿Continuar de todos modos?

View File

@ -1,3 +1,3 @@
Delete row: Eliminar linea
Order confirmed: Pedido confirmado
Are you sure you want to delete this row?: ¿Estas seguro de que quieres borrar esta línea?
Are you sure you want to delete this row?: ¿Estas seguro de que quieres eliminar esta línea?

View File

@ -1,8 +1,8 @@
Remove ticket: Borrar ticket
Remove ticket: Eliminar ticket
Open buscaman: Abrir buscaman
Ticket removed from route: Ticket borrado de la ruta
Ticket removed from route: Ticket quitado de la ruta
Order changed: Orden cambiado
Delete ticket from route?: ¿Borrar ticket de la ruta?
Delete ticket from route?: ¿Quitar el ticket de la ruta?
Sort routes: Ordenar rutas
Add ticket: Añadir ticket
Tickets to add: Tickets a añadir

View File

@ -21,10 +21,17 @@ module.exports = Self => {
Self.canHaveStowaway = async id => {
const models = Self.app.models;
const ticket = await models.Ticket.findById(id);
const ticket = await models.Ticket.findById(id, {
include: {
relation: 'ship',
scope: {
fields: ['id']
}
}
});
const warehouse = await models.Warehouse.findById(ticket.warehouseFk);
if (warehouse && warehouse.hasStowaway)
const hasStowaway = ticket.ship() ? true : false;
if (warehouse && warehouse.hasStowaway && !hasStowaway)
return true;
return false;

View File

@ -0,0 +1,39 @@
module.exports = Self => {
Self.remoteMethod('deleteStowaway', {
description: 'Deletes an stowaway',
accessType: 'WRITE',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'The ticket id',
http: {source: 'path'}
}],
returns: {
root: true
},
http: {
path: `/:id/deleteStowaway`,
verb: 'POST'
}
});
Self.deleteStowaway = async id => {
const ticket = await Self.findById(id, {
include: [{
relation: 'ship'
}, {
relation: 'stowaway'
}]
});
let params;
if (ticket.stowaway())
params = [ticket.stowaway().shipFk, ticket.stowaway().id];
else if (ticket.ship())
params = [ticket.ship().shipFk, ticket.ship().id];
return Self.rawSql(`CALL vn.stowaway_unboarding(?, ?)`, params);
};
};

View File

@ -0,0 +1,42 @@
const app = require('vn-loopback/server/server');
fdescribe('ticket deleteStowaway()', () => {
const shipId = 16;
const stowawayId = 17;
it('should create an stowaway', async() => {
await app.models.Stowaway.rawSql(`
INSERT INTO stowaway (id, shipFk) VALUES (?, ?)
`, [stowawayId, shipId]);
const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId});
expect(stowawayExists).toEqual(1);
});
it('should delete the stowaway from the ship ticket', async() => {
await app.models.Ticket.deleteStowaway(shipId);
const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId});
expect(stowawayExists).toEqual(0);
});
it('should create again an stowaway', async() => {
await app.models.Stowaway.rawSql(`
INSERT INTO stowaway (id, shipFk) VALUES (?, ?)
`, [stowawayId, shipId]);
const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId});
expect(stowawayExists).toEqual(1);
});
it('should delete the stowaway from the stowaway ticket', async() => {
await app.models.Ticket.deleteStowaway(stowawayId);
const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId});
expect(stowawayExists).toEqual(0);
});
});

View File

@ -27,6 +27,7 @@ module.exports = Self => {
require('../methods/ticket/transferSales')(Self);
require('../methods/ticket/canHaveStowaway')(Self);
require('../methods/ticket/recalculateComponents')(Self);
require('../methods/ticket/deleteStowaway')(Self);
Self.observe('before save', async function(ctx) {
if (ctx.isNewInstance) return;

View File

@ -51,7 +51,7 @@
"foreignKey": "clientFk"
},
"ship": {
"type": "hasMany",
"type": "hasOne",
"model": "Stowaway",
"foreignKey": "shipFk"
},

View File

@ -7,10 +7,10 @@
class="modal-form"
on-open="model.refresh()">
<tpl-body>
<section class="header vn-pa-md">
<section class="add-stowaway header vn-pa-md">
<h5><span translate>Stowaways to add</span></h5>
</section>
<vn-horizontal class="vn-pa-md">
<vn-horizontal class="add-stowaway vn-pa-md">
<vn-data-viewer model="model">
<vn-table model="model" auto-load="false">
<vn-thead>

View File

@ -139,11 +139,12 @@
card-reload="$ctrl.cardReload()"
ticket="$ctrl.ticket">
</vn-add-stowaway>
<vn-remove-stowaway
vn-id="removeStowaway"
card-reload="$ctrl.cardReload()"
ticket="$ctrl.ticket">
</vn-remove-stowaway>
<vn-confirm
vn-id="deleteStowaway"
on-accept="$ctrl.deleteStowaway()"
question="Delete stowaway"
message="Are you sure you want to delete this stowaway?">
</vn-confirm>
<vn-confirm
vn-id="confirm-dialog"
on-response="$ctrl.returnDialog($response)"

View File

@ -20,8 +20,8 @@ class Controller extends Component {
},
{
name: 'Remove stowaway',
callback: this.showRemoveStowaway,
show: () => this.shouldShowRemoveStowaway()
callback: this.showDeleteStowaway,
show: () => this.shouldShowDeleteStowaway()
},
{
name: 'Make invoice',
@ -43,6 +43,54 @@ class Controller extends Component {
];
}
get ticket() {
return this._ticket;
}
set ticket(value) {
this._ticket = value;
if (!value) return;
if (this.$params.sendSMS)
this.showSMSDialog();
this.canStowaway();
let links = {
btnOne: {
icon: 'person',
state: `client.card.summary({id: ${value.clientFk}})`,
tooltip: 'Client card'
}};
if (value.stowaway) {
links.btnTwo = {
icon: 'icon-stowaway',
state: `ticket.card.summary({id: ${value.stowaway.shipFk}})`,
tooltip: 'Ship stowaways'
};
}
if (value.ship) {
links.btnThree = {
icon: 'icon-stowaway',
state: `ticket.card.summary({id: ${value.ship.id}})`,
tooltip: 'Stowaway'
};
}
this._quicklinks = links;
}
get quicklinks() {
return this._quicklinks;
}
set quicklinks(value = {}) {
this._quicklinks = Object.assign(value, this._quicklinks);
}
showChangeShipped() {
if (!this.isEditable) {
this.vnApp.showError(this.$translate.instant(`This ticket can't be modified`));
@ -72,24 +120,6 @@ class Controller extends Component {
return false;
}
canStowaway() {
if (!this.isTicketModule()) return;
this.$http.get(`Tickets/${this.ticket.id}/canHaveStowaway`).then(response => {
if (response.data === true)
return this.canShowStowaway = true;
return this.canShowStowaway = false;
});
}
shouldShowRemoveStowaway() {
if (!this._ticket || !this.isTicketModule())
return false;
return (this._ticket.stowaway || (this._ticket.ship && this._ticket.ship.length > 0));
}
onMoreChange(callback) {
callback.call(this);
}
@ -149,61 +179,38 @@ class Controller extends Component {
}
}
canStowaway() {
if (!this.isTicketModule()) return;
this.$http.get(`Tickets/${this.ticket.id}/canHaveStowaway`).then(response => {
if (response.data === true)
return this.canShowStowaway = true;
return this.canShowStowaway = false;
});
}
shouldShowDeleteStowaway() {
if (!this._ticket || !this.isTicketModule())
return false;
return this._ticket.stowaway || this._ticket.ship;
}
showAddStowaway() {
this.$.addStowaway.show();
}
showRemoveStowaway() {
this.$.removeStowaway.show();
showDeleteStowaway() {
this.$.deleteStowaway.show();
}
get ticket() {
return this._ticket;
}
set ticket(value) {
this._ticket = value;
if (!value) return;
if (this.$params.sendSMS)
this.showSMSDialog();
this.canStowaway();
let links = {
btnOne: {
icon: 'person',
state: `client.card.summary({id: ${value.clientFk}})`,
tooltip: 'Client card'
}};
if (value.stowaway) {
links.btnTwo = {
icon: 'icon-stowaway',
state: `ticket.card.summary({id: ${value.stowaway.shipFk}})`,
tooltip: 'Ship stowaways'
};
}
if (value.ship && value.ship.length == 1) {
links.btnThree = {
icon: 'icon-stowaway',
state: `ticket.card.summary({id: ${value.ship[0].id}})`,
tooltip: 'Stowaway'
};
} else if (value.ship && value.ship.length > 1)
this.shipStowaways = value.ship;
this._quicklinks = links;
}
set quicklinks(value = {}) {
this._quicklinks = Object.assign(value, this._quicklinks);
}
get quicklinks() {
return this._quicklinks;
deleteStowaway() {
const query = `Tickets/${this.ticket.id}/deleteStowaway`;
this.$http.post(query).then(res => {
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
this.cardReload();
});
}
showDeliveryNote() {

View File

@ -174,11 +174,11 @@ describe('Ticket Component vnTicketDescriptor', () => {
describe('showRemoveStowaway()', () => {
it('should show a dialog for an stowaway removal', () => {
controller.$.removeStowaway = {};
controller.$.removeStowaway.show = jasmine.createSpy('show');
controller.showRemoveStowaway();
controller.$.deleteStowaway = {};
controller.$.deleteStowaway.show = jasmine.createSpy('show');
controller.showDeleteStowaway();
expect(controller.$.removeStowaway.show).toHaveBeenCalledWith();
expect(controller.$.deleteStowaway.show).toHaveBeenCalledWith();
});
});

View File

@ -5,8 +5,8 @@ Ship stowaways: Polizones del barco
Stowaways to add: Polizones a añadir
Stowaways of the ticket: Polizones del ticket
Add stowaway: Añadir polizón
Remove stowaway: Borrar polizón
Are you sure you want to delete this stowaway?: ¿Seguro que quieres borrar este polizón?
Remove stowaway: Eliminar polizón
Are you sure you want to delete this stowaway?: ¿Seguro que quieres eliminar este polizón?
Are you sure you want to send it?: ¿Seguro que quieres enviarlo?
Show Delivery Note: Ver albarán
Send Delivery Note: Enviar albarán

View File

@ -1,38 +0,0 @@
<vn-dialog
class="modal-form"
vn-id="dialog">
<tpl-body>
<vn-horizontal class="header vn-pa-md">
<h5><span translate>Stowaways of the ticket</span> {{$ctrl.ticket.id}}</h5>
</vn-horizontal>
<vn-horizontal class="vn-pa-md">
<vn-table>
<vn-thead>
<vn-tr>
<vn-th number>Ticket id</vn-th>
<vn-th number>Shipped</vn-th>
<vn-th number>Agency</vn-th>
<vn-th number>Warehouse</vn-th>
<vn-th number>State</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="stowaway in $ctrl.ticketStowaways" class="clickable" ng-click="$ctrl.showDeleteConfirm($index)">
<vn-td number>{{stowaway.id}}</vn-td>
<vn-td number>{{stowaway.ticket.landed | date: 'dd/MM/yyyy'}}</vn-td>
<vn-td number>{{stowaway.ticket.agencyMode.name}}</vn-td>
<vn-td number>{{stowaway.ticket.warehouse.name}}</vn-td>
<vn-td number>{{stowaway.ticket.state.state.name}}</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-horizontal>
</tpl-body>
</vn-dialog>
<vn-confirm
vn-id="confirmation-dialog"
on-response="$ctrl.deleteStowaway($response)"
question="Delete stowaway"
message="Are you sure you want to delete this stowaway?">
</vn-confirm>

View File

@ -1,78 +0,0 @@
import ngModule from '../module';
class Controller {
constructor($state, $scope, $http, vnApp, $translate) {
this.vnApp = vnApp;
this.$translate = $translate;
this.$scope = $scope;
this.$state = $state;
this.$http = $http;
}
getTicketStowaways() {
if (this.ticket.stowaway) {
this.ticketStowaways = [this.ticket.stowaway];
this.showDeleteConfirm(0);
} else if (this.ticket.ship.length > 1) {
let filter = {
where: {shipFk: this.ticket.id},
include: {
relation: 'ticket',
scope: {
include: [
{relation: 'agencyMode'},
{relation: 'warehouse'},
{relation: 'state',
scope: {
fields: ['stateFk'],
include: {
relation: 'state'
}
},
},
]
}
}
};
let json = encodeURIComponent(JSON.stringify(filter));
this.$http.get(`Stowaways?filter=${json}`).then(res => {
this.ticketStowaways = res.data;
this.$scope.dialog.show();
});
}
}
deleteStowaway(response) {
if (response === 'accept') {
this.$http.delete(`Stowaways/${this.stowawayToDelete.id}`).then(res => {
this.cardReload();
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
});
}
}
showDeleteConfirm(index) {
this.stowawayToDelete = this.ticketStowaways[index];
this.$scope.confirmationDialog.show();
}
show() {
this.getTicketStowaways();
}
hide() {
this.$scope.dialog.hide();
}
}
Controller.$inject = ['$state', '$scope', '$http', 'vnApp', '$translate'];
ngModule.component('vnRemoveStowaway', {
template: require('./removeStowaway.html'),
controller: Controller,
bindings: {
ticket: '<',
cardReload: '&?'
}
});

View File

@ -1,6 +1,6 @@
@import "variables";
vn-add-stowaway {
.add-stowaway {
vn-data-viewer {
width: 40em
}

View File

@ -6,7 +6,6 @@ import './search-panel';
import './card';
import './descriptor';
import './descriptor/addStowaway';
import './descriptor/removeStowaway';
import './descriptor-popover';
import './create/card';
import './create/index';

View File

@ -14,8 +14,8 @@ Counter: Contador
Created : Añadido
Date : Fecha
Delay: Retraso
Delete: Borrar
Delete expedition: Borrar expedición
Delete: Eliminar
Delete expedition: Eliminar expedición
Description: Descripción
Discount: Descuento
Employee : Empleado
@ -42,7 +42,7 @@ PPU: Ud.
Price: Precio
Price gap: Diferencia de precio
Quantity: Cantidad
Remove lines: Borrar lineas
Remove lines: Eliminar lineas
Route: Ruta
SET OK: PONER OK
Shipment: Salida

View File

@ -1,7 +1,7 @@
New price: Nuevo precio
Add item: Añadir artículo
Add turn: Añadir a turno
Delete ticket: Borrar ticket
Delete ticket: Eliminar ticket
Mark as reserved: Marcar como reservado
Unmark as reserved: Desmarcar como reservado
Update discount: Actualizar descuento
@ -10,7 +10,7 @@ Edit discount: Editar descuento
Transfer to ticket: Transferir a ticket
New ticket: Nuevo ticket
Edit price: Editar precio
You are going to delete lines of the ticket: Vas a borrar lineas del ticket
You are going to delete lines of the ticket: Vas a eliminar lineas del ticket
This ticket will be removed from current route! Continue anyway?: ¡Se eliminará el ticket de la ruta actual! ¿Continuar de todas formas?
You have to allow pop-ups in your web browser to use this functionality:
Debes permitir los pop-pups en tu navegador para que esta herramienta funcione correctamente
@ -29,5 +29,5 @@ SMSAvailability: >-
{{notAvailables}} no disponible/s. Disculpe las molestias.
Continue anyway?: ¿Continuar de todas formas?
This ticket is now empty: El ticket ha quedado vacio
Do you want to delete it?: ¿Quieres borrarlo?
Do you want to delete it?: ¿Quieres eliminarlo?
Recalculate price: Recalcular precio

View File

@ -5,7 +5,7 @@ Hours: Horas
Add time: Añadir hora
Week total: Total semana
Current week: Semana actual
This time entry will be deleted: Se borrará la hora fichada
This time entry will be deleted: Se eliminará la hora fichada
Are you sure you want to delete this entry?: ¿Seguro que quieres eliminarla?
Finish at: Termina a las
Entry removed: Fichada borrada