refs #4823 Added view supplyOffer

This commit is contained in:
Guillermo Bonet 2023-05-31 12:53:21 +02:00
parent af488b4cd6
commit 7498886b43
4 changed files with 33 additions and 3 deletions

View File

@ -59,7 +59,7 @@ class Floriday {
await utils.syncSupplyLines();
// Deshabilitado porque no hay de momento
// await utils.syncClockPresalesSupply();
// await utils.syncClockPresaleSupply();
} catch (err) {
if (err.name === 'SequelizeConnectionRefusedError') throw err;

View File

@ -2,6 +2,7 @@ import { Sequelize } from 'sequelize';
import dotenv from 'dotenv';
import chalk from 'chalk';
import ora from 'ora';
import fs from 'fs';
import { criticalError } from '../utils.js';
dotenv.config();
@ -78,8 +79,9 @@ let models = {
package: packageModel(sequelize),
};
// Foreign Keys
try {
// Foreign Keys
/* TODO: Aplicar dependiendo de cada caso
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
@ -156,6 +158,10 @@ try {
foreignKey: 'organizationId',
targetKey: 'organizationId',
});
// Views
sequelize.query(fs.readFileSync('views//supplyOffer.sql', 'utf-8'));
} catch (err) {
criticalError(err);
}

View File

@ -316,7 +316,7 @@ export async function syncSupplyLines() {
/**
* Sync the lock presales supply for supply lines of today.
*/
export async function syncClockPresalesSupply() {
export async function syncClockPresaleSupply() {
const spinner = ora(`Syncing clock presales supply...`).start();
const supplyLines = await models.supplyLine.findAll({
attributes: ['supplyLineId'],

24
views/supplyOffer.sql Normal file
View File

@ -0,0 +1,24 @@
CREATE OR REPLACE VIEW supplyOffer AS
SELECT sl.supplyLineId,
ti.name tradeItemName,
o.commercialName organizationName,
sl.type,
sl.salesUnit,
slvp.pricePerPiece,
sl.numberOfPieces,
sl.deliveryPeriodStartDateTime ,
sl.deliveryPeriodEndDateTime,
sl.orderPeriodStartDateTime,
sl.orderPeriodEndDateTime,
tip.url,
sl.lastSync
FROM supplyLine sl
JOIN supplyLineVolumePrice slvp ON slvp.supplyLineId = sl.supplyLineId
JOIN organization o ON o.organizationId = sl.organizationId
JOIN tradeItem ti ON ti.tradeItemId = sl.tradeItemId
JOIN tradeItemPhoto tip ON tip.tradeItemId = ti.tradeItemId
AND tip.primary
WHERE sl.status = 'AVAILABLE'
AND NOT sl.isDeleted
AND NOW() BETWEEN sl.orderPeriodStartDateTime AND sl.orderPeriodEndDateTime
GROUP BY sl.supplyLineId