Merge branch 'dev' of https://git.verdnatura.es/salix into dev
This commit is contained in:
commit
2b7a561a35
|
@ -37,7 +37,7 @@ module.exports = Self => {
|
|||
c.code AS company,
|
||||
r.created,
|
||||
'' description,
|
||||
0 AS debit,
|
||||
NULL AS debit,
|
||||
r.amountPaid AS credit,
|
||||
r.bankFk,
|
||||
firstName,
|
||||
|
@ -56,7 +56,7 @@ module.exports = Self => {
|
|||
i.created,
|
||||
CONCAT(' N/FRA ', i.ref),
|
||||
i.amount,
|
||||
0 credit,
|
||||
NULL credit,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
USE `vn`;
|
||||
DROP function IF EXISTS `clientGetMana`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` FUNCTION `clientGetMana`(vClient INT) RETURNS decimal(10,2)
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve el maná del cliente.
|
||||
*
|
||||
* @param vClient Id del cliente
|
||||
* @return Maná del cliente
|
||||
*/
|
||||
|
||||
|
||||
DECLARE vMana DECIMAL(10,2);
|
||||
DECLARE vFromDated DATE;
|
||||
|
||||
SELECT max(dated) INTO vFromDated
|
||||
FROM vn.clientManaCache;
|
||||
|
||||
SELECT sum(mana) INTO vMana
|
||||
FROM
|
||||
(
|
||||
SELECT mana
|
||||
FROM vn.clientManaCache
|
||||
WHERE clientFk = vClient
|
||||
AND dated = vFromDated
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT s.quantity * Valor
|
||||
FROM vn.ticket t
|
||||
JOIN vn.address a ON a.id = t.addressFk
|
||||
JOIN vn.sale s on s.ticketFk = t.id
|
||||
JOIN vn2008.Movimientos_componentes mc on mc.Id_Movimiento = s.id
|
||||
WHERE Id_Componente IN (37, 39)
|
||||
AND t.shipped > vFromDated
|
||||
AND t.shipped < TIMESTAMPADD(DAY,1,CURDATE())
|
||||
AND a.clientFk = vClient
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT - Entregado
|
||||
FROM vn2008.Recibos r
|
||||
JOIN vn2008.Clientes c using(Id_Cliente)
|
||||
WHERE r.Id_Banco = 66
|
||||
AND r.Fechacobro > vFromDated
|
||||
AND r.Fechacobro <= CURDATE()
|
||||
AND c.Id_Cliente = vClient
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT g.Importe
|
||||
FROM vn2008.Greuges g
|
||||
JOIN vn2008.Clientes c using(Id_Cliente)
|
||||
WHERE g.Greuges_type_id = 3 -- Maná
|
||||
AND g.Fecha > vFromDated
|
||||
AND g.Fecha <= CURDATE()
|
||||
AND c.Id_Cliente = vClient
|
||||
|
||||
) sub;
|
||||
|
||||
RETURN IFNULL(vMana,0);
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
Loading…
Reference in New Issue