update fixtures and refactor ticketVolume and backend test

This commit is contained in:
Bernat 2018-04-18 13:40:09 +02:00
parent 228239b027
commit 78b79b6fde
4 changed files with 39 additions and 3 deletions

View File

@ -151,6 +151,13 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city
(109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'BruceBanner@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 0, 1, NULL, 0, 0, 19, 0, 1), (109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'BruceBanner@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 0, 1, NULL, 0, 0, 19, 0, 1),
(110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'JessicaJones@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 0, 1, NULL, 0, 0, NULL, 0, 1); (110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'JessicaJones@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 0, 1, NULL, 0, 0, NULL, 0, 1);
INSERT INTO `vn`.`clientManaCache`(`clientFk`, `mana`, `dated`)
VALUES
( 101, 50, CURDATE()),
( 102, 100, CURDATE()),
( 103, 0, CURDATE()),
( 104, -30, CURDATE());
INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `phone`, `mobile`, `isActive`, `isDefaultAddress`, `clientFk`, `agencyModeFk`, `longitude`, `latitude`, `isEqualizated`) INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `phone`, `mobile`, `isActive`, `isDefaultAddress`, `clientFk`, `agencyModeFk`, `longitude`, `latitude`, `isEqualizated`)
VALUES VALUES
(101, '01', 'Somewhere in Thailand', 'Silla', 46460, 1, NULL, NULL, 1, 0, 109, 2, NULL, NULL, 0), (101, '01', 'Somewhere in Thailand', 'Silla', 46460, 1, NULL, NULL, 1, 0, 109, 2, NULL, NULL, 0),
@ -537,7 +544,7 @@ INSERT INTO `bi`.`rotacion`(`Id_Article`, `warehouse_id`, `total`, `rotacion`, `
INSERT INTO `vn`.`annualAverageInvoiced`(`clientFk`, `invoiced`) INSERT INTO `vn`.`annualAverageInvoiced`(`clientFk`, `invoiced`)
VALUES VALUES
( 101, 0), ( 101, 1500),
( 102, 100), ( 102, 100),
( 103, 1000), ( 103, 1000),
( 104, 500), ( 104, 500),

View File

@ -0,0 +1,29 @@
USE `vn`;
DROP procedure IF EXISTS `ticketVolume`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticketVolume`(IN vTicketId INT)
BEGIN
DECLARE vWarehouseId INTEGER;
DECLARE vShippedDate DATE;
DROP TEMPORARY TABLE IF EXISTS ticketVolume;
SELECT warehouseFk, shipped INTO vWarehouseId,vShippedDate FROM vn.ticket WHERE id = vTicketId;
CREATE TEMPORARY TABLE IF NOT EXISTS ticketVolume ENGINE MEMORY
SELECT itemFk, saleFk, quantity, concept, VolUd as m3_uni, volume as m3, volume * quantity as volumeTimesQuantity, @m3:= @m3 + ifnull(volume,0) as m3_total
FROM
(
SELECT round(r.cm3 / 1000000,3) as VolUd ,s.quantity, round(r.cm3 * s.quantity / 1000000,3) as volume,
s.itemFk, s.id AS saleFk, s.concept, @m3:= 0, @vol:=0, t.agencyModeFk
FROM sale s
JOIN vn.ticket t on t.id = s.ticketFk
JOIN bi.rotacion r ON r.Id_Article = s.itemFk AND r.warehouse_id = t.warehouseFk
WHERE s.ticketFk = vTicketId
) sub;
END$$
DELIMITER ;

View File

@ -11,7 +11,7 @@ describe('client getAverageInvoiced()', () => {
it('should call the getAverageInvoiced method', done => { it('should call the getAverageInvoiced method', done => {
model.getAverageInvoiced(101) model.getAverageInvoiced(101)
.then(response => { .then(response => {
expect(response.invoiced).toEqual(0); expect(response.invoiced).toEqual(1500);
done(); done();
}); });
}); });

View File

@ -11,7 +11,7 @@ describe('client getMana()', () => {
it('should call the getMana method', done => { it('should call the getMana method', done => {
model.getMana(101) model.getMana(101)
.then(response => { .then(response => {
expect(response.mana).toEqual(0); expect(response.mana).toEqual(30.02);
done(); done();
}); });
}); });