Merge branch 'dev' of http://git.verdnatura.es/salix into dev

This commit is contained in:
Carlos Jimenez 2018-10-02 11:33:40 +02:00
commit 8d60b3c1bc
16 changed files with 304 additions and 20 deletions

View File

@ -81,8 +81,7 @@
},
"menu": {
"icon": "icon-actions"
},
"acl": ["salesAssistant"]
}
}
]
}

View File

@ -18,11 +18,16 @@
<vn-horizontal>
<vn-tool-bar margin-medium-bottom>
<vn-button
vn-acl="salesAssistant"
label="Import claim"
ng-click="$ctrl.importToNewRefundTicket()"
vn-tooltip="Imports claim details">
</vn-button>
<vn-button
label="Import ticket"
ng-click="$ctrl.showLastTickets($event)"
vn-tooltip="Imports ticket lines">
</vn-button>
</vn-tool-bar>
</vn-horizontal>
<vn-table model="model">
@ -123,4 +128,38 @@
</vn-empty-rows>
</vn-table>
</tpl-body>
</vn-dialog>
</vn-dialog>
<vn-crud-model
vn-id="lastTicketsModel"
url="/claim/api/Tickets"
filter="{}"
data="lastTickets" auto-load="false">
</vn-crud-model>
<!-- Transfer Popover -->
<vn-popover class="lastTicketsPopover" vn-id="lastTicketsPopover">
<div class="ticketList" pad-medium>
<vn-table model="lastTicketsModel" class="vn-grid">
<vn-thead>
<vn-tr>
<vn-th field="id" number>ID</vn-th>
<vn-th field="shipped" default-order="DESC">F. envio</vn-th>
<vn-th>Agencia</vn-th>
<vn-th>Almacen</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr
class="clickable"
ng-repeat="ticket in lastTickets"
ng-click="$ctrl.importTicketLines(ticket.id)">
<vn-td number>{{::ticket.id}}</vn-td>
<vn-td>{{::ticket.shipped | date: 'dd/MM/yyyy'}}</vn-td>
<vn-td>{{::ticket.agencyMode.name}}</vn-td>
<vn-td>{{::ticket.warehouse.name}}</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</div>
</vn-popover>

View File

@ -2,14 +2,14 @@ import ngModule from '../module';
import './style.scss';
class Controller {
constructor($state, $scope, $http, $translate, vnApp) {
this.$state = $state;
constructor($stateParams, $scope, $http, $translate, vnApp) {
this.$stateParams = $stateParams;
this.$ = $scope;
this.$http = $http;
this.$translate = $translate;
this.vnApp = vnApp;
this.filter = {
where: {claimFk: $state.params.id},
where: {claimFk: $stateParams.id},
include: [
{relation: 'sale',
scope: {
@ -60,7 +60,7 @@ class Controller {
}
importToNewRefundTicket() {
let query = `claim/api/ClaimBeginnings/${this.$state.params.id}/importToNewRefundTicket`;
let query = `claim/api/ClaimBeginnings/${this.$stateParams.id}/importToNewRefundTicket`;
this.$http.post(query).then(() => {
this.$.model.refresh();
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
@ -88,9 +88,39 @@ class Controller {
this.claimedTotal += (sale.sale.quantity * sale.sale.price) - ((sale.sale.discount * (sale.sale.quantity * sale.sale.price)) / 100);
});
}
showLastTickets(event) {
let pastWeek = new Date();
pastWeek.setDate(-7);
let filter = {
include: [
{relation: 'agencyMode', fields: ['name']},
{relation: 'warehouse', fields: ['name']}
],
where: {
created: {gt: pastWeek}
}
};
this.$.lastTicketsModel.filter = filter;
this.$.lastTicketsModel.refresh();
this.$.lastTicketsPopover.parent = event.target;
this.$.lastTicketsPopover.show();
}
importTicketLines(ticketFk) {
let data = {claimFk: this.$stateParams.id, ticketFk: ticketFk};
let query = `/claim/api/ClaimEnds/importTicketSales`;
this.$http.post(query, data).then(() => {
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
this.$.lastTicketsPopover.hide();
this.$.model.refresh();
});
}
}
Controller.$inject = ['$state', '$scope', '$http', '$translate', 'vnApp'];
Controller.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp'];
ngModule.component('vnClaimAction', {
template: require('./index.html'),

View File

@ -1,4 +1,5 @@
import './index.js';
import {crudModel} from '../../../helpers/crudModelHelper';
describe('claim', () => {
describe('Component vnClaimAction', () => {
@ -25,6 +26,11 @@ describe('claim', () => {
hide: () => {},
show: () => {}
};
controller.$.lastTicketsModel = crudModel;
controller.$.lastTicketsPopover = {
hide: () => {},
show: () => {}
};
}));
describe('openAddSalesDialog()', () => {
@ -116,5 +122,32 @@ describe('claim', () => {
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
describe('showLastTickets()', () => {
it('should get a list of tickets and call lastTicketsPopover show() method', () => {
spyOn(controller.$.lastTicketsModel, 'refresh');
spyOn(controller.$.lastTicketsPopover, 'show');
controller.showLastTickets({});
expect(controller.$.lastTicketsModel.refresh).toHaveBeenCalledWith();
expect(controller.$.lastTicketsPopover.show).toHaveBeenCalledWith();
});
});
describe('importTicketLines()', () => {
it('should perform a post quer', () => {
spyOn(controller.$.model, 'refresh');
spyOn(controller.vnApp, 'showSuccess');
spyOn(controller.$.lastTicketsPopover, 'hide');
let data = {claimFk: 1, ticketFk: 1};
$httpBackend.expect('POST', `/claim/api/ClaimEnds/importTicketSales`, data).respond({});
controller.importTicketLines(1);
$httpBackend.flush();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.$.lastTicketsPopover.hide).toHaveBeenCalledWith();
});
});
});
});

View File

@ -2,4 +2,6 @@ Destination: Destino
Action: Actuaciones
Total claimed: Total Reclamado
Import claim: Importar reclamacion
Imports claim details: Importa detalles de la reclamacion
Imports claim details: Importa detalles de la reclamacion
Import ticket: Importar ticket
Imports ticket lines: Importa las lineas de un ticket

View File

@ -12,4 +12,16 @@ vn-claim-action {
}
}
}
vn-popover.lastTicketsPopover {
vn-table {
min-width: 650px;
overflow: auto
}
div.ticketList {
overflow: auto;
max-height: 350px
}
}
}

View File

@ -0,0 +1,42 @@
const UserError = require('vn-loopback/common/helpers').UserError;
module.exports = Self => {
Self.remoteMethodCtx('importTicketSales', {
description: 'Imports lines from claimBeginning to a new ticket with specific shipped, landed dates, agency and company',
accessType: 'WRITE',
accepts: [{
arg: 'params',
type: 'object',
http: {source: 'body'}
}],
returns: {
type: ['Object'],
root: true
},
http: {
path: `/importTicketSales`,
verb: 'POST'
}
});
Self.importTicketSales = async(ctx, params) => {
let models = Self.app.models;
let userId = ctx.req.accessToken.userId;
let worker = await models.Worker.findOne({where: {userFk: userId}});
let ticketSales = await models.Sale.find({
where: {ticketFk: params.ticketFk}
});
let claimEnds = [];
ticketSales.forEach(sale => {
claimEnds.push({
saleFk: sale.id,
claimFk: params.claimFk,
workerFk: worker.id
});
});
return await Self.create(claimEnds);
};
};

View File

@ -0,0 +1,23 @@
const app = require(`${servicesDir}/claim/server/server`);
describe('Claim importTicketSales()', () => {
let claimEnds;
afterAll(async() => {
claimEnds.forEach(async line => {
await line.destroy();
});
});
it('should import sales to a claim actions from an specific ticket', async() => {
let ctx = {req: {accessToken: {userId: 5}}};
claimEnds = await app.models.ClaimEnd.importTicketSales(ctx, {
claimFk: 1,
ticketFk: 1
});
expect(claimEnds.length).toEqual(4);
expect(claimEnds[0].saleFk).toEqual(1);
expect(claimEnds[2].saleFk).toEqual(3);
});
});

View File

@ -1,5 +1,6 @@
module.exports = Self => {
require('../methods/claim-beginning/importToNewRefundTicket')(Self);
Self.validatesUniquenessOf('saleFk', {
message: `A claim with that sale already exists`
});

View File

@ -0,0 +1,3 @@
module.exports = Self => {
require('../methods/claim-end/importTicketSales')(Self);
};

View File

@ -0,0 +1,2 @@
ALTER TABLE `vn`.`clientLog`
CHANGE COLUMN `newInstance` `newInstance` TEXT NULL DEFAULT NULL ;

View File

@ -0,0 +1,11 @@
DROP TRIGGER IF EXISTS `vn`.`clientLog_BEFORE_INSERT`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` TRIGGER `vn`.`clientLog_BEFORE_INSERT` BEFORE INSERT ON `clientLog` FOR EACH ROW
BEGIN
IF NEW.newInstance is NULL THEN
SET NEW.newInstance = NEW.description;
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,89 @@
USE `vn`;
DROP procedure IF EXISTS `ticketCalculateClon`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticketCalculateClon`(IN vTicketNew INT, vTicketOld INT)
BEGIN
/*
* @vTicketNew id del nuevo ticket clonado
* @vTicketOld id ticket original, a partir del qual se clonara el nuevo
* Este procedimiento "rebioniza" una linea, eliminando los componentes existentes e insertandolos de nuevo
*/
DECLARE vShipped DATE;
DECLARE vClient INT;
DECLARE vWarehouse SMALLINT;
DECLARE vAgencyMode INT;
DECLARE vAddress INT;
DECLARE vLanded DATE;
DECLARE vAgency INT;
INSERT INTO orderTicket(orderFk,ticketFk)
SELECT orderFk, vTicketNew
FROM orderTicket
WHERE ticketFk = vTicketOld;
SELECT t.clientFk , t.warehouseFk, date(t.shipped), t.addressFk, t.agencyModeFk, t.landed, a.agencyFk
INTO vClient, vWarehouse, vShipped, vAddress, vAgencyMode, vLanded, vAgency
FROM vn.agencyMode a
JOIN vn.ticket t ON t.agencyModeFk = a.id
WHERE t.id = vTicketNew;
DROP TEMPORARY TABLE IF EXISTS tmp.agencyHourGetShipped;
CREATE TEMPORARY TABLE tmp.agencyHourGetShipped ENGINE = MEMORY
SELECT vWarehouse warehouseFk, vShipped shipped, vLanded landed;
CALL buyUltimate(vWarehouse, vShipped); -- rellena la tabla tmp.buyUltimate con la ultima compra
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
CREATE TEMPORARY TABLE tmp.ticketLot
SELECT vWarehouse warehouseFk,NULL available,s.itemFk, bu.buyFk
FROM sale s
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
WHERE s.ticketFk = vTicketNew GROUP BY s.itemFk;
CALL ticketComponentCalculate(vAddress,vAgencyMode);
-- Bionizamos lineas con Preu = 0
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
CREATE TEMPORARY TABLE tmp.sale
(PRIMARY KEY (saleFk)) ENGINE = MEMORY
SELECT s.id saleFk, vWarehouse warehouseFk
FROM sale s
JOIN ticket t on t.id = s.ticketFk WHERE s.ticketFk = vTicketNew AND s.price = 0;
CALL ticketComponentUpdateSale(1);
-- Bionizamos lineas con Preu > 0
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
CREATE TEMPORARY TABLE tmp.sale
(PRIMARY KEY (saleFk)) ENGINE = MEMORY
SELECT s.id saleFk, vWarehouse warehouseFk
FROM sale s
JOIN ticket t on t.id = s.ticketFk WHERE s.ticketFk = vTicketNew
AND s.price > 0;
CALL ticketComponentUpdateSale(6);
IF vLanded IS NULL THEN
CALL agencyHourGetLanded(vShipped, vAddress, vAgency,vWarehouse);
UPDATE ticket t
JOIN tmp.agencyHourGetLanded ah ON t.warehouseFk = ah.warehouseFk
SET t.landed = ah.landed
WHERE t.id = vTicketNew;
END IF;
-- Log
CALL `logAdd`(vTicketNew, 'update', ' ticket' , 'Bioniza Ticket');
-- Limpieza
DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate;
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
DROP TEMPORARY TABLE IF EXISTS agencyHourGetShipped;
END$$
DELIMITER ;

View File

@ -850,16 +850,16 @@ INSERT INTO `vn`.`clientSample`(`id`, `clientFk`, `typeFk`, `created`, `workerFk
INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `observation`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created` )
VALUES
( 1, CURDATE(), 1, 'observation one' , 101, 18, 1, 0, CURDATE()),
( 2, CURDATE(), 2, 'observation two' , 101, 18, 2, 0, CURDATE()),
( 3, CURDATE(), 3, 'observation three' , 101, 18, 3, 0, CURDATE());
( 1, CURDATE(), 1, 'observation one' , 101, 18, 1, 0, CURDATE()),
( 2, CURDATE(), 2, 'observation two' , 101, 18, 2, 0, CURDATE()),
( 3, DATE_ADD(CURDATE(), INTERVAL -5 DAY), 3, 'observation three' , 101, 18, 3, 0, CURDATE());
INSERT INTO `vn`.`claimBeginning`(`id`, `claimFk`, `saleFk`, `quantity`)
VALUES
( 1, 1, 1, 5),
( 2, 1, 2, 4),
( 3, 2, 5, 10),
( 4, 3, 6, 5);
( 1, 1, 7, 5),
( 2, 1, 8, 4),
( 3, 2, 10, 10),
( 4, 3, 6, 5);
INSERT INTO `vn`.`claimDevelopment`(`id`, `claimFk`, `claimResponsibleFk`, `workerFk`, `claimReasonFk`, `claimResultFk`, `claimRedeliveryFk`, `claimDestinationFk`)
VALUES
@ -873,8 +873,6 @@ INSERT INTO `hedera`.`tpvMerchant`(`id`, `description`, `companyFk`, `bankFk`, `
( 1, 'Arkham Bank', 442, 1, 'h12387193H10238'),
( 2, 'NewYork Bank', 442, 1, '7981ugsgd1hsdad');
INSERT INTO `hedera`.`tpvTransaction`(`id`,`merchantFk`, `clientFk`,`receiptFk`, `amount`, `response`, `errorCode`, `status`, `created`)
VALUES
(1, 1, 101, NULL, 2000, NULL, 'SIS0042', 'ok', CURDATE()),

View File

@ -5,6 +5,6 @@ describe('sale getClaimableFromTicket()', () => {
let claimableFromTicket = await app.models.Sale.getClaimableFromTicket(16);
expect(claimableFromTicket[0].concept).toBe('Gem of Time');
expect(claimableFromTicket.length).toBe(4);
expect(claimableFromTicket.length).toBe(3);
});
});