Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into dev
This commit is contained in:
commit
5a8afa19a3
|
@ -0,0 +1,76 @@
|
|||
|
||||
DROP function IF EXISTS `vn`.`clientGetSalesPerson`;
|
||||
DELIMITER $$
|
||||
CREATE DEFINER=`root`@`%` FUNCTION `vn`.`clientGetSalesPerson`(vClientFk INT, vDated DATE) RETURNS int(11)
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
/**
|
||||
* Dado un id cliente y una fecha, devuelve su comercial para ese dia, teniendo
|
||||
* en cuenta la jerarquía de las tablas: 1º la de sharingClient, 2º la de
|
||||
* sharingCart y tercero la de clientes.
|
||||
*
|
||||
* @param vClientFk El id del cliente
|
||||
* @param vDated Fecha a comprobar
|
||||
* @return El id del comercial para la fecha dada
|
||||
**/
|
||||
DECLARE vSalesperson INT DEFAULT NULL;
|
||||
DECLARE vSubstitute INT DEFAULT NULL;
|
||||
DECLARE vLoop BOOLEAN;
|
||||
|
||||
-- Obtiene el comercial original y el de sharingClient
|
||||
|
||||
SELECT c.salesPersonFk, s.workerFk
|
||||
INTO vSalesperson, vSubstitute
|
||||
FROM client c
|
||||
LEFT JOIN sharingClient s
|
||||
ON c.id = s.clientFk
|
||||
AND vDated BETWEEN s.started AND s.ended
|
||||
WHERE c.id = vClientFk
|
||||
ORDER BY s.id
|
||||
LIMIT 1;
|
||||
|
||||
-- Si no hay ninguno en sharingClient busca en sharingCart
|
||||
|
||||
IF vSubstitute IS NOT NULL
|
||||
THEN
|
||||
SET vSalesperson = vSubstitute;
|
||||
ELSEIF vSalesperson IS NOT NULL
|
||||
THEN
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.stack;
|
||||
CREATE TEMPORARY TABLE tmp.stack
|
||||
(INDEX (substitute))
|
||||
ENGINE = MEMORY
|
||||
SELECT vSalesperson substitute;
|
||||
|
||||
l: LOOP
|
||||
SELECT workerSubstitute INTO vSubstitute
|
||||
FROM sharingCart
|
||||
WHERE vDated BETWEEN started AND ended
|
||||
AND workerFk = vSalesperson
|
||||
ORDER BY id
|
||||
LIMIT 1;
|
||||
|
||||
IF vSubstitute IS NULL THEN
|
||||
LEAVE l;
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(*) > 0 INTO vLoop
|
||||
FROM tmp.stack WHERE substitute = vSubstitute;
|
||||
|
||||
IF vLoop THEN
|
||||
LEAVE l;
|
||||
END IF;
|
||||
|
||||
INSERT INTO tmp.stack SET
|
||||
substitute = vSubstitute;
|
||||
|
||||
SET vSalesperson = vSubstitute;
|
||||
END LOOP;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.stack;
|
||||
END IF;
|
||||
|
||||
RETURN vSalesperson;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -0,0 +1,14 @@
|
|||
CREATE
|
||||
ALGORITHM = UNDEFINED
|
||||
DEFINER = `root`@`%`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`sharingCart` AS
|
||||
SELECT
|
||||
`s`.`id` AS `id`,
|
||||
`s`.`Id_Trabajador` AS `workerFk`,
|
||||
`s`.`datSTART` AS `started`,
|
||||
`s`.`datEND` AS `ended`,
|
||||
`s`.`Id_Suplente` AS `workerSubstitute`,
|
||||
`s`.`odbc_date` AS `created`
|
||||
FROM
|
||||
`vn2008`.`sharingcart` `s`
|
|
@ -0,0 +1,13 @@
|
|||
CREATE
|
||||
OR REPLACE ALGORITHM = UNDEFINED
|
||||
DEFINER = `root`@`%`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`sharingClient` AS
|
||||
SELECT
|
||||
`s`.`id` AS `id`,
|
||||
`s`.`Id_Trabajador` AS `workerFk`,
|
||||
`s`.`datSTART` AS `started`,
|
||||
`s`.`datEND` AS `ended`,
|
||||
`s`.`Id_Cliente` AS `clientFk`
|
||||
FROM
|
||||
`vn2008`.`sharingclient` `s`;
|
|
@ -1317,3 +1317,11 @@ INSERT INTO `vn`.`smsConfig` (`id`, `uri`, `user`, `password`, `title`)
|
|||
VALUES
|
||||
('1', 'https://websms.xtratelecom.es/api_php/server.wsdl', 'VERDINATURA', '182wbOKu', 'Verdnatura');
|
||||
|
||||
INSERT INTO `vn`.`sharingClient`(`id`, `workerFk`, `started`, `ended`, `clientFk`)
|
||||
VALUES
|
||||
(1, 19, DATE_ADD(CURDATE(), INTERVAL -5 DAY), DATE_ADD(CURDATE(), INTERVAL +15 DAY), 101),
|
||||
(2, 18, DATE_ADD(CURDATE(), INTERVAL -5 DAY), DATE_ADD(CURDATE(), INTERVAL +15 DAY), 106);
|
||||
|
||||
INSERT INTO `vn`.`sharingCart`(`id`, `workerFk`, `started`, `ended`, `workerSubstitute`, `created`)
|
||||
VALUES
|
||||
(1, 18, DATE_ADD(CURDATE(), INTERVAL -5 DAY), DATE_ADD(CURDATE(), INTERVAL +15 DAY), 19, DATE_ADD(CURDATE(), INTERVAL -5 DAY));
|
|
@ -3,9 +3,16 @@
|
|||
vn-td-editable {
|
||||
text {
|
||||
border-bottom: 1px solid rgba(0,0,0,.12);
|
||||
min-height: 15px;
|
||||
cursor: pointer;
|
||||
display: block
|
||||
}
|
||||
|
||||
text::after {
|
||||
overflow: hidden;
|
||||
content: '';
|
||||
clear: both;
|
||||
}
|
||||
|
||||
outline: none;
|
||||
position: relative;
|
||||
|
|
|
@ -80,5 +80,6 @@
|
|||
"We weren't able to send this SMS": "No hemos podido enviar el SMS",
|
||||
"This client can't be invoiced": "Este cliente no puede ser facturado",
|
||||
"This ticket can't be invoiced": "Este ticket no puede ser facturado",
|
||||
"That item is not available on that day": "That item is not available on that day"
|
||||
"That item is not available on that day": "That item is not available on that day",
|
||||
"That item doesn't exists": "That item doesn't exists"
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
<form name="form" ng-submit="$ctrl.onSubmit()" compact>
|
||||
<vn-card pad-large>
|
||||
<vn-horizontal>
|
||||
<vn-input-number vn-one min="1"
|
||||
<vn-input-number vn-one min="0"
|
||||
label="Credit"
|
||||
model="$ctrl.creditClassification.credit",
|
||||
rule="creditInsurance.credit"
|
||||
|
|
|
@ -31,15 +31,16 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.confirm = async ctx => {
|
||||
const models = Self.app.models;
|
||||
let transaction = await Self.beginTransaction({});
|
||||
let options = {transaction: transaction};
|
||||
|
||||
try {
|
||||
let item = await Self.app.models.Item.findById(ctx.args.itemFk);
|
||||
let item = await models.Item.findById(ctx.args.itemFk);
|
||||
if (!item)
|
||||
throw new UserError(`That item doesn't exists`);
|
||||
|
||||
let request = await Self.app.models.TicketRequest.findById(ctx.args.id, {
|
||||
let request = await models.TicketRequest.findById(ctx.args.id, {
|
||||
include: {relation: 'ticket'}
|
||||
});
|
||||
|
||||
|
@ -60,15 +61,19 @@ module.exports = Self => {
|
|||
|
||||
|
||||
if (request.saleFk) {
|
||||
let sale = await Self.app.models.Sale.findById(request.saleFk);
|
||||
sale.updateAttributes({itemFk: ctx.args.itemFk, quantity: ctx.args.quantity, description: item.description}, options);
|
||||
let sale = await models.Sale.findById(request.saleFk);
|
||||
sale.updateAttributes({
|
||||
itemFk: ctx.args.itemFk,
|
||||
quantity: ctx.args.quantity,
|
||||
description: item.description
|
||||
}, options);
|
||||
} else {
|
||||
params = {
|
||||
ticketFk: request.ticketFk,
|
||||
itemFk: ctx.args.itemFk,
|
||||
quantity: ctx.args.quantity
|
||||
};
|
||||
sale = await Self.app.models.Sale.create(params, options);
|
||||
sale = await models.Sale.create(params, options);
|
||||
request.updateAttributes({saleFk: sale.id, itemFk: sale.itemFk}, options);
|
||||
}
|
||||
|
||||
|
@ -76,6 +81,14 @@ module.exports = Self => {
|
|||
params = [sale.id];
|
||||
await Self.rawSql(query, params, options);
|
||||
|
||||
const message = `Se ha comprado ${params.quantity} unidades de "${item.description}" (#${params.itemFk}) `
|
||||
+ `para el ticket #${params.ticketFk}`;
|
||||
|
||||
await models.Message.send(ctx, {
|
||||
recipientFk: request.requesterFk,
|
||||
message: message
|
||||
}, options);
|
||||
|
||||
await transaction.commit();
|
||||
} catch (error) {
|
||||
await transaction.rollback();
|
||||
|
|
Loading…
Reference in New Issue