Merge branch 'dev' of https://git.verdnatura.es/salix into dev
This commit is contained in:
commit
ec7e52190a
|
@ -0,0 +1,98 @@
|
||||||
|
USE `vn`;
|
||||||
|
DROP procedure IF EXISTS `clientGetDebtDiary`;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
USE `vn`$$
|
||||||
|
CREATE DEFINER=`root`@`%` PROCEDURE `clientGetDebtDiary`(vClientFK INT, vCompanyFk INT)
|
||||||
|
BEGIN
|
||||||
|
/**
|
||||||
|
* Devuelve el registro de deuda
|
||||||
|
*
|
||||||
|
* @param vClientFK Id del cliente
|
||||||
|
* @param vCompanyFk Id de la empresa
|
||||||
|
*/
|
||||||
|
DECLARE vDate DATETIME DEFAULT CURDATE();
|
||||||
|
|
||||||
|
SET @balance:= 0;
|
||||||
|
|
||||||
|
SELECT MAX(issued) INTO vDate FROM
|
||||||
|
(SELECT
|
||||||
|
created,
|
||||||
|
issued,
|
||||||
|
@balance:= ROUND(amount, 2) + @balance AS balance
|
||||||
|
FROM invoiceOut
|
||||||
|
WHERE clientFk = vClientFk AND companyFk = vCompanyFk
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
created,
|
||||||
|
payed,
|
||||||
|
@balance:= ROUND(-1 * amountPaid, 2) + @balance AS balance
|
||||||
|
FROM receipt
|
||||||
|
WHERE clientFk = vClientFk AND companyFk = vCompanyFk
|
||||||
|
ORDER BY issued, created) balance
|
||||||
|
WHERE balance = 0;
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
issued,
|
||||||
|
CAST(debtOut AS DECIMAL(10,2)) debtOut,
|
||||||
|
CAST(debtIn AS DECIMAL(10,2)) debtIn,
|
||||||
|
ref,
|
||||||
|
companyFk,
|
||||||
|
priority
|
||||||
|
FROM
|
||||||
|
(SELECT
|
||||||
|
NULL AS issued,
|
||||||
|
SUM(amountUnpaid) AS debtOut,
|
||||||
|
NULL AS debtIn,
|
||||||
|
'Saldo Anterior' AS ref,
|
||||||
|
companyFk,
|
||||||
|
0 as priority
|
||||||
|
FROM
|
||||||
|
(SELECT SUM(amount) AS amountUnpaid, companyFk, 0
|
||||||
|
FROM invoiceOut
|
||||||
|
WHERE clientFk = vClientFK
|
||||||
|
AND issued < vDate
|
||||||
|
GROUP BY companyFk
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT SUM(-1 * amountPaid), companyFk, 0
|
||||||
|
FROM receipt
|
||||||
|
WHERE clientFk = vClientFK
|
||||||
|
AND payed < vDate
|
||||||
|
GROUP BY companyFk) AS transactions
|
||||||
|
GROUP BY companyFk
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
issued,
|
||||||
|
amount as debtOut,
|
||||||
|
NULL AS debtIn,
|
||||||
|
id AS ref,
|
||||||
|
companyFk,
|
||||||
|
1
|
||||||
|
FROM invoiceOut
|
||||||
|
WHERE clientFk = vClientFK
|
||||||
|
AND issued >= vDate
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
r.payed,
|
||||||
|
NULL as debtOut,
|
||||||
|
r.amountPaid,
|
||||||
|
r.id,
|
||||||
|
r.companyFk,
|
||||||
|
0
|
||||||
|
FROM receipt r
|
||||||
|
WHERE r.clientFk = vClientFK
|
||||||
|
AND r.payed >= vDate) t
|
||||||
|
INNER JOIN `client` c ON c.id = vClientFK
|
||||||
|
HAVING debtOut <> 0 OR debtIn <> 0
|
||||||
|
ORDER BY issued, priority DESC, debtIn;
|
||||||
|
END$$
|
||||||
|
|
||||||
|
DELIMITER ;
|
||||||
|
|
|
@ -10,21 +10,16 @@
|
||||||
<!-- Header block end -->
|
<!-- Header block end -->
|
||||||
|
|
||||||
<!-- Body block -->
|
<!-- Body block -->
|
||||||
<div class="body">
|
<main>
|
||||||
|
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="size50">
|
<div class="size50">
|
||||||
<div class="size50">
|
<div class="size50">
|
||||||
<h1 style="margin-top:0" class="font extraLarge">EXTRACTO</h1>
|
<h1 style="margin-top:0" class="font extraLarge">EXTRACTO</h1>
|
||||||
<div class="row inline font small">
|
<div class="row inline font normal">
|
||||||
<div class="text font gray">CLIENTE:</div>
|
<div class="text font gray">CLIENTE:</div>
|
||||||
<div class="control">{{clientId}}</div>
|
<div class="control">{{clientId}}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row inline font small">
|
<div class="row inline font normal">
|
||||||
<div class="text font gray">FACTURA:</div>
|
|
||||||
<div class="control">x</div>
|
|
||||||
</div>
|
|
||||||
<div class="row inline font small">
|
|
||||||
<div class="text font gray">FECHA:</div>
|
<div class="text font gray">FECHA:</div>
|
||||||
<div class="control">{{currentDate}}</div>
|
<div class="control">{{currentDate}}</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -32,49 +27,48 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="size50">
|
<div class="size50">
|
||||||
<div class="panel">
|
<div class="panel">
|
||||||
|
<div class="header">Datos de cliente</div>
|
||||||
<p>
|
<p>
|
||||||
<strong>{{supplierName}}</strong>
|
<strong>{{clientName}}</strong>
|
||||||
</p>
|
</p>
|
||||||
<div>
|
<div>
|
||||||
{{supplierStreet}}
|
{{street}}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{{supplierPostCode}}, {{supplierCity}} ({{supplierProvince}})
|
{{postcode}}, {{city}} ({{province}})
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{{supplierCountry}}
|
{{country}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="grid" style="margin-top:30px">
|
<div class="grid" style="margin-top:20px">
|
||||||
<div class="row header inline">
|
<div class="row header inline">
|
||||||
<div style="width: 20%">Fecha</div>
|
<div style="width: 15%">Fecha</div>
|
||||||
<div style="width: 50%">Concepto</div>
|
<div style="width: 40%">Concepto</div>
|
||||||
<div style="width: 10%">Debe</div>
|
<div style="width: 15%">Facturado</div>
|
||||||
<div style="width: 10%">Haber</div>
|
<div style="width: 15%">Pagado</div>
|
||||||
<div stlye="width: 10%">Saldo</div>
|
<div style="width: 15%">Saldo</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{#lines}}
|
||||||
<div class="row inline">
|
<div class="row inline">
|
||||||
<div style="width: 20%">Fecha</div>
|
<div class="font bold" style="width: 15%">{{issued}} </div>
|
||||||
<div style="width: 50%">Concepto</div>
|
<div class="font bold" style="width: 40%">{{ref}} </div>
|
||||||
<div style="width: 10%">Debe</div>
|
<div class="font bold" style="width: 15%">{{debtOut}} </div>
|
||||||
<div style="width: 10%">Haber</div>
|
<div class="font bold" style="width: 15%">{{debtIn}} </div>
|
||||||
<div stlye="width: 10%">Saldo</div>
|
<div class="font bold" style="width: 15%">{{balance}} </div>
|
||||||
|
</div>
|
||||||
|
{{/lines}}
|
||||||
|
<div class="row last inline">
|
||||||
|
<div style="width: 55%"><strong>Total</strong></div>
|
||||||
|
<div style="width: 15%">{{totalDebtOut}}</div>
|
||||||
|
<div style="width: 15%">{{totalDebtIn}}</div>
|
||||||
|
<div style="width: 15%">{{totalBalance}}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</main>
|
||||||
<div class="pull-right">
|
|
||||||
|
|
||||||
<div class="row inline">
|
|
||||||
<div class="text">
|
|
||||||
Subtotal
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<!-- Body block end -->
|
<!-- Body block end -->
|
||||||
|
|
||||||
<!-- Footer block -->
|
<!-- Footer block -->
|
||||||
|
|
|
@ -1,59 +1,89 @@
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var database = require(path.join(__dirname, '../../database.js'));
|
var database = require(path.join(__dirname, '../../database.js'));
|
||||||
var format = require(path.join(__dirname, '../../util/format.js'));
|
let strftime = require('strftime');
|
||||||
|
|
||||||
module.exports = class LetterDebtor {
|
module.exports = class LetterDebtor {
|
||||||
async getData(params, cb) {
|
async getData(params, cb) {
|
||||||
let query = `SELECT
|
let qryData = `SELECT
|
||||||
c.id clientId,
|
c.id clientId,
|
||||||
m.code mandateCode,
|
|
||||||
LOWER(ct.code) AS countryCode,
|
LOWER(ct.code) AS countryCode,
|
||||||
c.email AS recipient,
|
c.email AS recipient,
|
||||||
c.socialName AS clientName,
|
c.socialName AS clientName,
|
||||||
c.street AS clientStreet,
|
c.street,
|
||||||
c.postcode AS clientPostCode,
|
c.postcode,
|
||||||
c.city AS clientCity,
|
c.city,
|
||||||
p.name AS clientProvince,
|
c.fi,
|
||||||
ct.country AS clientCountry,
|
p.name AS province,
|
||||||
s.name AS supplierName,
|
ct.country
|
||||||
s.street AS supplierStreet,
|
|
||||||
sc.country AS supplierCountry,
|
|
||||||
s.postCode AS supplierPostCode,
|
|
||||||
s.city AS supplierCity,
|
|
||||||
sp.name AS supplierProvince
|
|
||||||
FROM client c
|
FROM client c
|
||||||
JOIN country ct ON ct.id = c.countryFk
|
JOIN country ct ON ct.id = c.countryFk
|
||||||
LEFT JOIN province p ON p.id = c.provinceFk
|
LEFT JOIN province p ON p.id = c.provinceFk
|
||||||
LEFT JOIN mandate m ON m.clientFk = c.id AND m.finished IS NULL
|
|
||||||
LEFT JOIN supplier s ON s.id = m.companyFk
|
|
||||||
LEFT JOIN country sc ON sc.id = s.countryFk
|
|
||||||
LEFT JOIN province sp ON sp.id = s.provinceFk
|
|
||||||
WHERE c.id = ?`;
|
WHERE c.id = ?`;
|
||||||
try {
|
|
||||||
let [result] = await database.pool.query(query, [params.clientId]);
|
|
||||||
|
|
||||||
if (!result)
|
let qryLines = `CALL vn.clientGetDebtDiary(?, ?)`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let [data] = await database.pool.query(qryData, [params.clientId]);
|
||||||
|
|
||||||
|
if (!data)
|
||||||
throw new Error('No body data found');
|
throw new Error('No body data found');
|
||||||
|
|
||||||
Object.assign(this, result);
|
let [lines] = await database.pool.query(qryLines, [params.clientId, params.companyId]);
|
||||||
|
|
||||||
|
Object.assign(this, data[0]);
|
||||||
|
|
||||||
|
this.lines = lines[0];
|
||||||
|
this.formatLines();
|
||||||
|
this.getBalance();
|
||||||
cb();
|
cb();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
cb(e);
|
cb(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Swift BIC fields
|
|
||||||
get swiftFields() {
|
|
||||||
return new Array(11);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Account number fields
|
|
||||||
get accountNumberFields() {
|
|
||||||
return new Array(23);
|
|
||||||
}
|
|
||||||
|
|
||||||
get currentDate() {
|
get currentDate() {
|
||||||
return format.date(new Date(), '/');
|
return strftime('%d-%m-%Y', new Date());
|
||||||
|
}
|
||||||
|
|
||||||
|
formatLines() {
|
||||||
|
this.lines.forEach(line => {
|
||||||
|
if (line.issued)
|
||||||
|
line.issued = strftime('%d-%m-%Y', line.issued);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getBalance() {
|
||||||
|
let balance = 0.00;
|
||||||
|
this.lines.forEach(line => {
|
||||||
|
if (line.debtOut)
|
||||||
|
balance += parseFloat(line.debtOut);
|
||||||
|
|
||||||
|
if (line.debtIn)
|
||||||
|
balance -= parseFloat(line.debtIn);
|
||||||
|
|
||||||
|
line.balance = parseFloat(balance.toFixed(2));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
totalDebtOut() {
|
||||||
|
let debtOut = 0.00;
|
||||||
|
this.lines.forEach(line => {
|
||||||
|
debtOut += line.debtOut ? parseFloat(line.debtOut) : 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
return debtOut.toFixed(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
totalDebtIn() {
|
||||||
|
let debtIn = 0.00;
|
||||||
|
this.lines.forEach(line => {
|
||||||
|
debtIn += line.debtIn ? parseFloat(line.debtIn) : 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
return debtIn.toFixed(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
totalBalance() {
|
||||||
|
return this.totalDebtOut() - this.totalDebtIn();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue