2035
gitea/salix/pipeline/head Build queued... Details

This commit is contained in:
Javi Gallego 2020-06-05 10:01:21 +02:00
parent bfeef77040
commit b40be5cca9
14 changed files with 2040 additions and 360 deletions

View File

@ -45,7 +45,7 @@ proc: BEGIN
IF vLanded IS NULL OR vZoneFk IS NULL THEN
CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk);
CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE);
IF (SELECT COUNT(*) FROM tmp.zoneGetLanded LIMIT 1) = 0 THEN
CALL util.throw('There is no zone for these parameters');

View File

@ -0,0 +1,93 @@
USE `vn`;
DROP procedure IF EXISTS `ticketCalculateClon`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticketCalculateClon`(IN vTicketNew INT, vTicketOld INT)
BEGIN
/*
* Recalcula los componentes un ticket clonado,
* las lineas a precio cero fuerza para que tengan precio, el resto lo respeta
* @param vTicketNew nuevo ticket clonado
* @param vTicketOld icket original, a partir del qual se clonara el nuevo
*/
DECLARE vShipped DATE;
DECLARE vClient INT;
DECLARE vWarehouse SMALLINT;
DECLARE vAgencyMode INT;
DECLARE vAddress INT;
DECLARE vLanded DATE;
DECLARE vAgency INT;
DECLARE vZoneFk INT;
REPLACE 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, t.zoneFk
INTO vClient, vWarehouse, vShipped, vAddress, vAgencyMode, vLanded, vAgency, vZoneFk
FROM agencyMode a
JOIN ticket t ON t.agencyModeFk = a.id
WHERE t.id = vTicketNew;
IF vLanded IS NULL THEN
CALL zone_getLanded(vShipped, vAddress, vAgency, vWarehouse, TRUE);
UPDATE ticket t
JOIN tmp.zoneGetLanded zgl ON t.warehouseFk = zgl.warehouseFk
SET t.landed = zgl.landed,
t.zone = zgl.zoneFk
WHERE t.id = vTicketNew;
SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1;
DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetLanded;
END IF;
-- rellena la tabla tmp.buyUltimate con la ultima compra
CALL buyUltimate(vWarehouse, vShipped);
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
CREATE TEMPORARY TABLE tmp.ticketLot
SELECT vWarehouse warehouseFk, NULL available, s.itemFk, bu.buyFk, vZoneFk zoneFk
FROM sale s
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
WHERE s.ticketFk = vTicketOld GROUP BY s.itemFk;
CALL catalog_componentPrepare();
CALL catalog_componentCalculate(vZoneFk, vAddress, vAgencyMode, vWarehouse);
-- 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);
-- Log
CALL `logAdd`(vTicketNew, 'update', ' ticket' , 'Bioniza Ticket');
-- Limpieza
CALL catalog_componentPurge();
DROP TEMPORARY TABLE IF EXISTS
tmp.buyUltimate,
tmp.sale,
tmp.zoneGetLanded;
END$$
DELIMITER ;

View File

@ -0,0 +1,132 @@
USE `vn`;
DROP procedure IF EXISTS `ticket_cloneWeekly`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticket_cloneWeekly`(IN vWeek INT)
BEGIN
DECLARE vIsDone BOOL;
DECLARE vLanding DATE;
DECLARE vShipment DATE;
DECLARE vWarehouse INT;
DECLARE vTicket INT;
DECLARE vWeekDay INT;
DECLARE vClient INT;
DECLARE vEmpresa INT;
DECLARE vAddressFk INT;
DECLARE vAgencyModeFk INT;
DECLARE vNewTicket INT;
DECLARE vYear INT;
DECLARE rsTicket CURSOR FOR
SELECT tw.ticketFk, weekDay, t.clientFk, t.warehouseFk, t.companyFk, t.addressFk, tw.agencyModeFk
FROM ticketWeekly tw
JOIN ticket t ON tt.ticketFk = t.id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE;
SET vYear = YEAR(CURDATE()) + IF(vWeek < WEEK(CURDATE()),1, 0);
OPEN rsTicket;
myLoop: LOOP
BEGIN
DECLARE vError TEXT;
DECLARE vSalesPersonEmail VARCHAR(150);
DECLARE vMailSent BOOL;
DECLARE vSubject VARCHAR(150);
DECLARE vMessage TEXT;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
BEGIN
GET DIAGNOSTICS CONDITION 1
vError = MESSAGE_TEXT;
END;
SET vIsDone = FALSE;
FETCH rsTicket INTO vTicket, vWeekDay, vClient, vWarehouse, vEmpresa, vAddressFk, vAgencyModeFk;
IF vIsDone THEN
LEAVE myLoop;
END IF;
SELECT date INTO vShipment
FROM `time`
WHERE `year` = vYear AND `week` = vWeek
AND WEEKDAY(date) = vWeekDay;
-- busca si el ticket ya ha sido clonado
IF (SELECT COUNT(*) FROM vn.ticket tOrig
JOIN vn.sale saleOrig ON tOrig.id = saleOrig.ticketFk
JOIN vn.saleCloned sc ON sc.saleOriginalFk = saleOrig.id
JOIN vn.sale saleClon ON saleClon.id = sc.saleClonedFk
JOIN vn.ticket tClon ON tClon.id = saleClon.ticketFk
WHERE tOrig.id = vTicket AND DATE(tClon.shipped) = vShipment) > 0
THEN
ITERATE myLoop;
END IF;
CALL vn.zone_getLanded(vShipment, vAddressFk, vAgencyModeFk, vWarehouse, TRUE);
SELECT landed INTO vLanding from tmp.zoneGetLanded LIMIT 1;
CALL vn.ticketCreateWithoutZone(vClient, vShipment, vWarehouse, vEmpresa, vAddressFk, vAgencyModeFk, NULL, vLanding, account.userGetId(), vNewTicket);
IF (vLanding IS NULL) THEN
SELECT e.email INTO vSalesPersonEmail
FROM vn.client c
JOIN vn.worker sp ON sp.id = c.salesPersonFk
JOIN account.emailUser e ON e.userFk = sp.userFk
WHERE c.id = vClient;
SET vSubject = CONCAT('Turnos - No se ha podido clonar correctamente el ticket ', vTicket,
' para el dia: ', vShipment);
SET vMessage = CONCAT('No se ha podido clonar el ticket ', vTicket,
' para el dia: ', vShipment,
' porque no hay una zona de envío disponible. Se ha creado el ticket: ', vNewTicket,
' pero ha que revisar las fechas y la agencia');
SELECT COUNT(*) INTO vMailSent
FROM vn.mail
WHERE sender = vSalesPersonEmail
AND subject = vSubject;
IF NOT vMailSent THEN
INSERT INTO vn.mail (sender,`subject`,body)
VALUES (vSalesPersonEmail, vSubject, vMessage);
END IF;
CALL vn.ticketStateUpdate (vNewTicket, 'FIXING');
END IF;
INSERT INTO vn.sale (ticketFk, itemFk, concept, quantity, price, discount, priceFixed, isPriceFixed)
SELECT vNewTicket, saleOrig.itemFk , saleOrig.concept , saleOrig.quantity, saleOrig.price , saleOrig.discount, saleOrig.priceFixed, saleOrig.isPriceFixed
FROM vn.ticket tOrig
JOIN vn.sale saleOrig ON tOrig.id = saleOrig.ticketFk
LEFT JOIN vn.saleCloned sc ON sc.saleOriginalFk = saleOrig.id
LEFT JOIN vn.sale saleClon ON saleClon.id = sc.saleClonedFk
LEFT JOIN vn.ticket tClon ON tClon.id = saleClon.ticketFk AND DATE(tClon.shipped) = vShipment
WHERE tOrig.id = vTicket AND saleClon.id IS NULL;
INSERT IGNORE INTO vn.saleCloned(saleOriginalFk, saleClonedFk)
SELECT saleOriginal.id, saleClon.id
FROM vn.sale saleOriginal
JOIN vn.sale saleClon ON saleOriginal.itemFk = saleClon.itemFk AND saleOriginal.quantity = saleClon.quantity
WHERE saleOriginal.ticketFk = vTicket AND saleClon.ticketFk = vNewTicket;
INSERT INTO ticketRequest (description, ordered, shipped, salesPersonCode, buyerCode, quantity, price,
itemFk ,clientFk, response, total, buyed, saleFk)
SELECT tr.description, tr.ordered, tr.shipped, tr.salesPersonCode, tr.buyerCode, tr.quantity, tr.price,
tr.itemFk, tr.clientFk, tr.response, tr.total, tr.buyed, tr.saleFk
FROM sale s JOIN ticketRequest tr ON tr.saleFk = s.id
JOIN sale s2 ON s.concept = s2.concept AND s.quantity = s2.quantity AND m.Id_Article = m2.Id_Article
WHERE s.ticketFk = vTicket AND s2.ticketFk = vNewTicket;
CALL vn.ticketCalculateClon(vNewTicket, vTicket);
END;
END LOOP;
CLOSE rsTicket;
END$$
DELIMITER ;

View File

@ -0,0 +1,93 @@
USE `vn`;
DROP procedure IF EXISTS `ticket_recalcComponents`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticket_recalcComponents`(IN vTicketFk BIGINT, vIsTicketEditable BOOLEAN)
proc: BEGIN
/**
* Este procedimiento recalcula los componentes de un ticket,
* eliminando los componentes existentes e insertandolos de nuevo
*
* @param vTicketFk Id del ticket
* @param vIsTicketEditable si no se quiere forzar llamar con NULL
*/
DECLARE vShipped DATE;
DECLARE vWarehouseFk SMALLINT;
DECLARE vAgencyModeFk INT;
DECLARE vAddressFk INT;
DECLARE vLanded DATE;
DECLARE vZoneFk INTEGER;
IF vIsTicketEditable IS NULL THEN
SELECT IFNULL(ts.alertLevel,0) = 0 AND IFNULL(t.refFk,'') = ''
INTO vIsTicketEditable
FROM ticket t LEFT JOIN ticketState ts ON t.id = ts.ticket
WHERE id = vTicketFk;
END IF;
SELECT t.warehouseFk,
t.shipped,
t.addressFk,
t.agencyModeFk,
t.landed,
t.zoneFk
INTO vWarehouseFk, vShipped, vAddressFk, vAgencyModeFk, vLanded, vZoneFk
FROM ticket t LEFT JOIN ticketState ts ON t.id = ts.ticket
WHERE t.id = vTicketFk;
IF vLanded IS NULL OR vZoneFk IS NULL THEN
CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE);
IF (SELECT COUNT(*) FROM tmp.zoneGetLanded LIMIT 1) = 0 THEN
CALL util.throw('There is no zone for these parameters');
END IF;
UPDATE ticket t
SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1)
WHERE t.id = vTicketFk AND t.landed IS NULL;
IF vZoneFk IS NULL THEN
SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1;
UPDATE ticket t
SET t.zoneFk = vZoneFk
WHERE t.id = vTicketFk AND t.zoneFk IS NULL;
END IF;
DROP TEMPORARY TABLE tmp.zoneGetLanded;
END IF;
-- rellena la tabla buyUltimate con la ultima compra
CALL buyUltimate (vWarehouseFk, vShipped);
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
CREATE TEMPORARY TABLE tmp.ticketLot
SELECT vWarehouseFk warehouseFk, NULL available,
s.itemFk, bu.buyFk, vZoneFk zoneFk
FROM sale s
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
WHERE s.ticketFk = vTicketFk
GROUP BY s.itemFk;
CALL catalog_componentPrepare();
CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk);
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
CREATE TEMPORARY TABLE tmp.sale
(PRIMARY KEY (saleFk)) ENGINE = MEMORY
SELECT id saleFk, vWarehouseFk warehouseFk
FROM sale s
WHERE s.ticketFk = vTicketFk;
-- si el ticket esta facturado, respeta los precios
CALL ticketComponentUpdateSale(IF(vIsTicketEditable, 1, 6));
CALL catalog_componentPurge();
DROP TEMPORARY TABLE
tmp.buyUltimate,
tmp.sale;
END$$
DELIMITER ;

View File

@ -0,0 +1,40 @@
USE `vn`;
DROP procedure IF EXISTS `zone_getLanded`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `zone_getLanded`(vShipped DATE, vAddressFk INT, vAgencyModeFk INT, vWarehouseFk INT, vShowExpiredZones BOOLEAN)
BEGIN
/**
* Devuelve una tabla temporal con el dia de recepcion para vShipped.
*
* @param vShipped Fecha de preparacion de mercancia
* @param vAddressFk Id de consignatario, %NULL para recogida
* @param vAgencyModeFk Id agencia
* @param vWarehouseFk vWarehouseFk
* @table tmp.zoneGetLanded Datos de recepción
*/
CALL zone_getFromGeo(address_getGeo(vAddressFk));
CALL zone_getOptionsForShipment(vShipped, vShowExpiredZones);
DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetLanded;
CREATE TEMPORARY TABLE tmp.zoneGetLanded
ENGINE = MEMORY
SELECT vWarehouseFk warehouseFk,
TIMESTAMPADD(DAY,zo.travelingDays, vShipped) landed,
zo.zoneFk
FROM tmp.zoneOption zo
JOIN zone z ON z.id = zo.zoneFk
JOIN zoneWarehouse zw ON zw.zoneFk = z.id
WHERE agencyModeFk = vAgencyModeFk
AND zw.warehouseFk = vWarehouseFk;
DROP TEMPORARY TABLE
tmp.zone,
tmp.zoneOption;
END$$
DELIMITER ;

View File

@ -11,12 +11,14 @@ describe('zone zone_getLanded()', () => {
let params = {
addressFk: 121,
agencyModeFk: 7,
warehouseFk: 1};
warehouseFk: 1,
showExpiredZones: true};
stmt = new ParameterizedSQL('CALL zone_getLanded(DATE_ADD(CURDATE(), INTERVAL -1 DAY), ?, ?, ?)', [
stmt = new ParameterizedSQL('CALL zone_getLanded(DATE_ADD(CURDATE(), INTERVAL -1 DAY), ?, ?, ?, ?)', [
params.addressFk,
params.agencyModeFk,
params.warehouseFk
params.warehouseFk,
params.showExpiredZones
]);
stmts.push(stmt);
@ -42,12 +44,14 @@ describe('zone zone_getLanded()', () => {
let params = {
addressFk: 121,
agencyModeFk: 7,
warehouseFk: 1};
warehouseFk: 1,
showExpiredZones: false};
stmt = new ParameterizedSQL('CALL zone_getLanded(DATE_ADD(CURDATE(), INTERVAL +2 DAY), ?, ?, ?)', [
stmt = new ParameterizedSQL('CALL zone_getLanded(DATE_ADD(CURDATE(), INTERVAL +2 DAY), ?, ?, ?, ?)', [
params.addressFk,
params.agencyModeFk,
params.warehouseFk
params.warehouseFk,
params.showExpiredZones
]);
stmts.push(stmt);

View File

@ -105,7 +105,7 @@ module.exports = Self => {
if (shipped && !landed) {
const landedResult = await models.Agency.getLanded(shipped,
address.id, agencyModeId, warehouseId);
address.id, agencyModeId, warehouseId, false);
landed = landedResult && landedResult.landed;
}

View File

@ -75,7 +75,8 @@ class Controller extends Component {
shipped: value,
addressFk: this.ticket.addressFk,
agencyModeFk: this.ticket.agencyModeFk,
warehouseFk: this.ticket.warehouseFk
warehouseFk: this.ticket.warehouseFk,
showExpiredZones: false
});
}
@ -104,7 +105,8 @@ class Controller extends Component {
shipped: this.ticket.shipped,
addressFk: this.ticket.addressFk,
agencyModeFk: value,
warehouseFk: this.ticket.warehouseFk
warehouseFk: this.ticket.warehouseFk,
showExpiredZones: false
});
}
}

View File

@ -2,15 +2,13 @@ import './index.js';
describe('Ticket', () => {
describe('Component vnTicketBasicDataStepOne', () => {
let $state;
let controller;
let $httpBackend;
let $httpParamSerializer;
beforeEach(ngModule('ticket'));
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, _$httpParamSerializer_) => {
$state = _$state_;
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => {
$httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
const $element = angular.element('<vn-ticket-basic-data-step-one></vn-ticket-basic-data-step-one>');
@ -127,6 +125,7 @@ describe('Ticket', () => {
shipped: shipped,
addressFk: 121,
agencyModeFk: 7,
showExpiredZones: false,
warehouseFk: 1
};
controller.shipped = shipped;
@ -177,7 +176,8 @@ describe('Ticket', () => {
shipped: shipped,
addressFk: 121,
agencyModeFk: agencyModeId,
warehouseFk: 1
warehouseFk: 1,
showExpiredZones: false,
};
controller.ticket.shipped = shipped;
controller.agencyModeId = 8;

View File

@ -3,7 +3,7 @@
data="ticketUpdateActions"
auto-load="true">
</vn-crud-model>
<vn-card class="vn-w-lg vn-pa-md vn-mb-md">
<vn-card ng-show="$ctrl.totalPriceDifference" class="vn-w-lg vn-pa-md vn-mb-md">
<h6
class="text-secondary"
style="font-weight: normal;"

View File

@ -23,6 +23,11 @@ module.exports = Self => {
arg: 'warehouseFk',
type: 'number',
required: true
},
{
arg: 'showExpiredZones',
type: 'boolean',
required: true
}],
returns: {
type: 'object',
@ -34,14 +39,15 @@ module.exports = Self => {
}
});
Self.getLanded = async(shipped, addressFk, agencyModeFk, warehouseFk) => {
Self.getLanded = async(shipped, addressFk, agencyModeFk, warehouseFk, showExpiredZones) => {
let stmts = [];
stmts.push(new ParameterizedSQL(
`CALL vn.zone_getLanded(?, ?, ?, ?)`, [
`CALL vn.zone_getLanded(?, ?, ?, ?, ?)`, [
shipped,
addressFk,
agencyModeFk,
warehouseFk
warehouseFk,
showExpiredZones
]
));

View File

@ -7,7 +7,8 @@ describe('agency getLanded()', () => {
const addressFk = 121;
const agencyModeFk = 7;
const warehouseFk = 1;
let result = await app.models.Agency.getLanded(shipped, addressFk, agencyModeFk, warehouseFk);
const showExpiredZones = true;
let result = await app.models.Agency.getLanded(shipped, addressFk, agencyModeFk, warehouseFk, showExpiredZones);
expect(result.landed).toBeDefined();
});

1981
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -56,9 +56,9 @@
"gulp-install": "^1.1.0",
"gulp-jasmine": "^4.0.0",
"gulp-merge-json": "^1.3.1",
"gulp-nodemon": "^2.4.2",
"gulp-nodemon": "^2.5.0",
"gulp-print": "^2.0.1",
"gulp-wrap": "^0.13.0",
"gulp-wrap": "^0.15.0",
"gulp-yaml": "^1.0.1",
"html-loader": "^0.4.5",
"html-loader-jest": "^0.2.1",
@ -71,9 +71,9 @@
"jest-junit": "^8.0.0",
"json-loader": "^0.5.7",
"merge-stream": "^1.0.1",
"minimist": "^1.2.0",
"minimist": "^1.2.5",
"mysql2": "^1.7.0",
"node-sass": "^4.13.0",
"node-sass": "^4.14.1",
"nodemon": "^1.19.4",
"plugin-error": "^1.0.1",
"puppeteer": "^2.0.0",
@ -82,7 +82,7 @@
"style-loader": "^0.23.1",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.10.1",
"webpack-dev-server": "^3.11.0",
"webpack-merge": "^4.2.2",
"yaml-loader": "^0.5.0"
},