Consumption fix
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
7069fbc6b2
commit
6c5acc75eb
|
@ -18,50 +18,50 @@ module.exports = Self => {
|
|||
Self.consumptionSendQueued = async() => {
|
||||
const queues = await Self.rawSql(`
|
||||
SELECT
|
||||
ccq.id,
|
||||
c.id AS clientFk,
|
||||
c.email AS clientEmail,
|
||||
eu.email salesPersonEmail,
|
||||
REPLACE(json_extract(params, '$.from'), '"', '') AS fromDate,
|
||||
REPLACE(json_extract(params, '$.to'), '"', '') AS toDate
|
||||
FROM clientConsumptionQueue ccq
|
||||
JOIN client c ON (
|
||||
JSON_SEARCH(
|
||||
JSON_ARRAY(
|
||||
json_extract(params, '$.clients')
|
||||
)
|
||||
, 'all', c.id) IS NOT NULL)
|
||||
JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
|
||||
JOIN ticket t ON t.clientFk = c.id
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
WHERE status = ''
|
||||
AND it.isPackaging = FALSE
|
||||
AND DATE(t.shipped) BETWEEN
|
||||
REPLACE(json_extract(params, '$.from'), '"', '') AND
|
||||
REPLACE(json_extract(params, '$.to'), '"', '')
|
||||
GROUP BY c.id`);
|
||||
id,
|
||||
params
|
||||
FROM clientConsumptionQueue
|
||||
WHERE status = ''`);
|
||||
|
||||
for (const queue of queues) {
|
||||
try {
|
||||
const args = {
|
||||
id: queue.clientFk,
|
||||
recipient: queue.clientEmail,
|
||||
replyTo: queue.salesPersonEmail,
|
||||
from: queue.fromDate,
|
||||
to: queue.toDate
|
||||
};
|
||||
const params = JSON.parse(queue.params);
|
||||
|
||||
const email = new Email('campaign-metrics', args);
|
||||
await email.send();
|
||||
const clients = await Self.rawSql(`
|
||||
SELECT
|
||||
c.id AS clientFk,
|
||||
c.email AS clientEmail,
|
||||
eu.email salesPersonEmail
|
||||
FROM client c
|
||||
JOIN account.emailUser eu ON eu.userFk = c.salesPersonFk
|
||||
JOIN ticket t ON t.clientFk = c.id
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
WHERE c.id IN(?)
|
||||
AND it.isPackaging = FALSE
|
||||
AND DATE(t.shipped) BETWEEN ? AND ?
|
||||
GROUP BY c.id`, [params.clients, params.from, params.to]);
|
||||
|
||||
await Self.rawSql(`
|
||||
UPDATE clientConsumptionQueue
|
||||
SET status = 'printed',
|
||||
printed = ?
|
||||
WHERE id = ?`,
|
||||
[new Date(), queue.id]);
|
||||
for (const client of clients) {
|
||||
const args = {
|
||||
id: client.clientFk,
|
||||
recipient: client.clientEmail,
|
||||
replyTo: client.salesPersonEmail,
|
||||
from: params.from,
|
||||
to: params.to
|
||||
};
|
||||
|
||||
const email = new Email('campaign-metrics', args);
|
||||
await email.send();
|
||||
|
||||
await Self.rawSql(`
|
||||
UPDATE clientConsumptionQueue
|
||||
SET status = 'printed',
|
||||
printed = ?
|
||||
WHERE id = ?`,
|
||||
[new Date(), queue.id]);
|
||||
}
|
||||
} catch (error) {
|
||||
await Self.rawSql(`
|
||||
UPDATE clientConsumptionQueue
|
||||
|
@ -69,7 +69,7 @@ module.exports = Self => {
|
|||
WHERE id = ?`,
|
||||
[error.message, queue.id]);
|
||||
|
||||
throw e;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -77,12 +77,13 @@ export default class Controller extends Section {
|
|||
|
||||
onSendClientConsumption() {
|
||||
const clientIds = this.checked.map(client => client.id);
|
||||
const params = {
|
||||
const data = {
|
||||
clients: clientIds,
|
||||
from: this.campaign.from,
|
||||
to: this.campaign.to
|
||||
};
|
||||
|
||||
const params = JSON.stringify(data);
|
||||
this.$http.post('ClientConsumptionQueues', {params})
|
||||
.then(() => this.$.filters.hide())
|
||||
.then(() => this.vnApp.showSuccess(this.$t('Notifications sent!')));
|
||||
|
|
Loading…
Reference in New Issue