all filters tested

This commit is contained in:
Javi Gallego 2020-04-30 07:20:43 +02:00
parent bb66e578d7
commit ceb3d1f4cf
8 changed files with 270 additions and 29 deletions

View File

@ -0,0 +1,156 @@
CREATE DEFINER=`root`@`%` PROCEDURE `ekt_load`(IN `vSelf` INT)
BEGIN
DECLARE vRef INT;
DECLARE vBuy INT;
DECLARE vItem INT;
DECLARE vQty INT;
DECLARE vPackage INT;
DECLARE vIsLot BOOLEAN;
DECLARE vForceToPacking INT DEFAULT 2;
-- Carga los datos necesarios del EKT
SELECT ref, qty, package INTO vRef, vQty, vPackage
FROM ekt e
LEFT JOIN item i ON e.ref = i.id
WHERE e.id = vSelf;
-- Inserta el cubo si no existe
IF vPackage = 800
THEN
SET vPackage = 800 + vQty;
INSERT IGNORE INTO vn2008.Cubos SET
Id_Cubo = vPackage,
x = 7200 / vQty,
y = 1;
ELSE
INSERT IGNORE INTO vn2008.Cubos (Id_Cubo, X, Y, Z)
SELECT bucket_id, ROUND(x_size/10), ROUND(y_size/10), ROUND(z_size/10)
FROM bucket WHERE bucket_id = vPackage;
IF ROW_COUNT() > 0
THEN
INSERT INTO vn2008.mail SET
`subject` = 'Cubo añadido',
`text` = CONCAT('Se ha añadido el cubo: ', vPackage),
`to` = 'ekt@verdnatura.es';
END IF;
END IF;
-- Intenta obtener el artículo en base a los atributos holandeses
INSERT IGNORE INTO item_track SET
item_id = vRef;
SELECT c.Id_Compra, c.Id_Article INTO vBuy, vItem
FROM vn2008.buy_edi e
JOIN item_track t ON t.item_id = e.ref
LEFT JOIN vn2008.buy_edi l ON l.ref = e.ref
LEFT JOIN vn2008.Compres c ON c.buy_edi_id = l.id
JOIN vn2008.config cfg
WHERE e.id = vSelf
AND l.id != vSelf
AND c.Id_Article != cfg.generic_item
AND IF(t.s1, l.s1 = e.s1, TRUE)
AND IF(t.s2, l.s2 = e.s2, TRUE)
AND IF(t.s3, l.s3 = e.s3, TRUE)
AND IF(t.s4, l.s4 = e.s4, TRUE)
AND IF(t.s5, l.s5 = e.s5, TRUE)
AND IF(t.s6, l.s6 = e.s6, TRUE)
AND IF(t.kop, l.kop = e.kop, TRUE)
AND IF(t.pac, l.pac = e.pac, TRUE)
AND IF(t.cat, l.cat = e.cat, TRUE)
AND IF(t.ori, l.ori = e.ori, TRUE)
AND IF(t.pro, l.pro = e.pro, TRUE)
AND IF(t.sub, l.sub = e.sub, TRUE)
AND IF(t.package, l.package = e.package, TRUE)
AND c.Id_Article < 170000
ORDER BY l.now DESC, c.Id_Compra ASC LIMIT 1;
-- Determina si el articulo se vende por lotes
IF vItem
THEN
SELECT COUNT(*) > 0 INTO vIsLot
FROM vn2008.Articles a
LEFT JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id
WHERE a.Id_Article = vItem
AND t.`transaction`;
-- Si el articulo se vende por lotes se inserta un nuevo artículo
IF vIsLot
THEN
INSERT INTO vn2008.Articles (
Article
,Medida
,Categoria
,Id_Origen
,iva_group_id
,Foto
,Color
,Codintrastat
,tipo_id
,Tallos
)
SELECT
i.`name`
,IFNULL(e.s1, e.pac)
,e.cat
,IFNULL(o.id, 17)
,IFNULL(a.iva_group_id, 1)
,a.Foto
,a.Color
,a.Codintrastat
,IFNULL(a.tipo_id, 10)
,IF(a.tipo_id = 15, 0, 1)
FROM vn2008.buy_edi e
LEFT JOIN item i ON i.id = e.ref
LEFT JOIN vn2008.Origen o ON o.Abreviatura = e.ori
LEFT JOIN vn2008.Articles a ON a.Id_Article = vItem
WHERE e.id = vSelf;
SET vItem = LAST_INSERT_ID();
END IF;
END IF;
-- Inserta la compra asociada al EKT
INSERT INTO vn2008.Compres
(
Id_Entrada
,buy_edi_id
,Costefijo
,Id_Article
,`grouping`
,caja
,Packing
,Cantidad
,Productor
,Etiquetas
,Id_Cubo
,`weight`
)
SELECT
cfg.edi_entry
,vSelf
,(@t := IF(a.Tallos, a.Tallos, 1)) * e.pri
,IFNULL(vItem, cfg.generic_item)
,IFNULL(c.`grouping`, e.pac)
,vForceToPacking
,@pac := e.pac / @t
,@pac * e.qty
,s.company_name
,e.qty
,IFNULL(c.Id_Cubo, e.package)
,a.density * (vn.item_getVolume(a.Id_Article, IFNULL(c.Id_Cubo, e.package)) / 1000000)
FROM vn2008.buy_edi e
LEFT JOIN vn2008.Compres c ON c.Id_Compra = vBuy
LEFT JOIN vn2008.Articles a ON a.Id_Article = c.Id_Article
LEFT JOIN supplier s ON e.pro = s.supplier_id
JOIN vn2008.config cfg
WHERE e.id = vSelf
LIMIT 1;
END

View File

@ -1,5 +1,4 @@
describe('Directive dialog', () => {
let $scope;
let $element;
let element;
let compile;
@ -9,7 +8,7 @@ describe('Directive dialog', () => {
compile = _element => {
inject(($compile, $rootScope) => {
$scope = $rootScope.$new();
let $scope = $rootScope.$new();
$scope.myDialog = controller;
element = angular.element(_element);
$compile(element)($scope);
@ -17,7 +16,7 @@ describe('Directive dialog', () => {
});
};
beforeEach(angular.mock.inject(($rootScope, $compile) => {
beforeEach(inject(($rootScope, $compile) => {
$element = $compile('<vn-dialog><tpl-body></tpl-body></vn-dialog>')($rootScope);
controller = $element.controller('vnDialog');
}));

View File

@ -1,41 +1,23 @@
describe('Currency filter', () => {
let compile;
let $element;
beforeEach(ngModule('vnCore'));
compile = html => {
inject(($compile, $rootScope) => {
$element = $compile(html)($rootScope);
$rootScope.$digest();
});
};
let currencyFilter;
beforeEach(inject(_currencyFilter_ => {
currencyFilter = _currencyFilter_;
}));
it('should return a ONE decimal number as per the argument', () => {
let html = `<div id="test" >{{200 | currency: 'EUR': 1}}</div>`;
compile(html);
expect($element[0].innerHTML).toContain('200.0');
expect(currencyFilter(200, 'EUR', 1)).toContain('200.0');
});
it('should return a TWO decimals number as per the argument', () => {
let html = `<div id="test" >{{200 | currency: 'EUR': 2}}</div>`;
compile(html);
expect($element[0].innerHTML).toContain('200.00');
expect(currencyFilter(200, 'EUR', 2)).toContain('200.00');
});
it('should return a TEN decimals number as per the argument', () => {
let html = `<div id="test" >{{200 | currency: 'EUR': 10}}</div>`;
compile(html);
expect($element[0].innerHTML).toContain('200.0000000000');
expect(currencyFilter(200, 'EUR', 10)).toContain('200.0000000000');
});
it('sould return nothing when the value is not set', () => {
let html = `<div id="test" >{{null | currency: 'EUR': 2}}</div>`;
compile(html);
expect($element[0].innerHTML).toEqual('');
expect(currencyFilter(null, 'EUR', 2)).toBeUndefined();
});
});

View File

@ -0,0 +1,20 @@
'use strict';
describe('Dash-if-empty filter', () => {
beforeEach(ngModule('vnCore'));
let dashIfEmptyFilter;
beforeEach(inject(_dashIfEmptyFilter_ => {
dashIfEmptyFilter = _dashIfEmptyFilter_;
}));
it('should return a dash if input is null', () => {
expect(dashIfEmptyFilter(null)).toBe('-');
});
it('should return a dash if input is empty', () => {
expect(dashIfEmptyFilter('')).toBe('-');
});
it('should return same input is there is something', () => {
expect(dashIfEmptyFilter('something')).toBe('something');
});
});

View File

@ -0,0 +1,20 @@
'use strict';
describe('Percentage filter', () => {
beforeEach(ngModule('vnCore'));
it('should return null for input null', () => {
expect(percentageFilter(null, null)).toBeNull();
});
it('should return null for input empty', () => {
expect(percentageFilter('', 2)).toBeNull();
});
it('should return a TWO decimals number', () => {
expect(percentageFilter(0, 2)).toBe('0.00%');
});
it('should return zero decimals number', () => {
expect(percentageFilter(0.5, 0)).toBe('50%');
});
});

View File

@ -0,0 +1,20 @@
'use strict';
describe('Phone filter', () => {
beforeEach(ngModule('vnCore'));
let phoneFilter;
beforeEach(inject(_phoneFilter_ => {
phoneFilter = _phoneFilter_;
}));
it('should return empty string for input null', () => {
expect(phoneFilter(null)).toBe('');
});
it('should return empty stringfor input empty', () => {
expect(phoneFilter('')).toBe('');
});
it('should format putting a space every three digits', () => {
expect(phoneFilter('999999999')).toBe('999 999 999 ');
});
});

View File

@ -0,0 +1,20 @@
'use strict';
describe('Ucwords filter', () => {
beforeEach(ngModule('vnCore'));
let ucwordsFilter;
beforeEach(inject(_ucwordsFilter_ => {
ucwordsFilter = _ucwordsFilter_;
}));
it('should return empty string for input null', () => {
expect(ucwordsFilter(null)).toBe('');
});
it('should return empty stringfor input empty', () => {
expect(ucwordsFilter('')).toBe('');
});
it('should format a string uppercasing the first character of each word', () => {
expect(ucwordsFilter('abc def')).toBe('Abc Def');
});
});

View File

@ -0,0 +1,24 @@
'use strict';
describe('ZeroFill filter', () => {
beforeEach(ngModule('vnCore'));
let zeroFillFilter;
beforeEach(inject(_zeroFillFilter_ => {
zeroFillFilter = _zeroFillFilter_;
}));
it('should return null for a input null', () => {
expect(zeroFillFilter(null, null)).toBeNull();
});
it('should return a positive number pads a number with five zeros', () => {
expect(zeroFillFilter(1, 5)).toBe('00001');
});
it('should return negative number pads a number with five zeros', () => {
expect(zeroFillFilter(-1, 5)).toBe('-00001');
});
it('should return zero number with zero zeros', () => {
expect(zeroFillFilter(0, 1)).toBe('0');
});
});