This commit is contained in:
parent
3eacb4dbd9
commit
78eba23d12
|
@ -0,0 +1,128 @@
|
|||
CREATE TABLE IF NOT EXISTS `vn`.`ticketCanAdvanceConfig` (
|
||||
`id` INT auto_increment NULL,
|
||||
`destinationOrder` INT NULL,
|
||||
CONSTRAINT `ticketCanAdvanceConfig_PK` PRIMARY KEY (id)
|
||||
)
|
||||
ENGINE=InnoDB
|
||||
DEFAULT CHARSET=utf8mb3
|
||||
COLLATE=utf8mb3_unicode_ci;
|
||||
|
||||
INSERT INTO `vn`.`ticketCanAdvanceConfig`
|
||||
SET `destinationOrder` = 5;
|
||||
|
||||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_canAdvance`(vDateFuture DATE, vDateToAdvance DATE, vWarehouseFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve los tickets y la cantidad de lineas de venta que se pueden adelantar.
|
||||
*
|
||||
* @param vDateFuture Fecha de los tickets que se quieren adelantar.
|
||||
* @param vDateToAdvance Fecha a cuando se quiere adelantar.
|
||||
* @param vWarehouseFk Almacén
|
||||
*/
|
||||
DECLARE vDateInventory DATE;
|
||||
|
||||
SELECT inventoried INTO vDateInventory FROM config;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tStock
|
||||
(itemFk INT PRIMARY KEY, amount INT)
|
||||
ENGINE = MEMORY;
|
||||
|
||||
INSERT INTO tStock(itemFk, amount)
|
||||
SELECT itemFk, SUM(quantity) amount FROM
|
||||
(
|
||||
SELECT itemFk, quantity
|
||||
FROM itemTicketOut
|
||||
WHERE shipped >= vDateInventory
|
||||
AND shipped < vDateFuture
|
||||
AND warehouseFk = vWarehouseFk
|
||||
UNION ALL
|
||||
SELECT itemFk, quantity
|
||||
FROM itemEntryIn
|
||||
WHERE landed >= vDateInventory
|
||||
AND landed < vDateFuture
|
||||
AND isVirtualStock = FALSE
|
||||
AND warehouseInFk = vWarehouseFk
|
||||
UNION ALL
|
||||
SELECT itemFk, quantity
|
||||
FROM itemEntryOut
|
||||
WHERE shipped >= vDateInventory
|
||||
AND shipped < vDateFuture
|
||||
AND warehouseOutFk = vWarehouseFk
|
||||
) t
|
||||
GROUP BY itemFk HAVING amount != 0;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
||||
(INDEX (id))
|
||||
SELECT dest.*,
|
||||
origin.*
|
||||
FROM (
|
||||
SELECT s.ticketFk futureId,
|
||||
t.workerFk,
|
||||
t.shipped futureShipped,
|
||||
t.totalWithVat futureTotalWithVat,
|
||||
st.name futureState,
|
||||
t.addressFk futureAddressFk,
|
||||
am.name futureAgency,
|
||||
count(s.id) futureLines,
|
||||
GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt,
|
||||
CAST(SUM(litros) AS DECIMAL(10,0)) futureLiters,
|
||||
SUM((s.quantity <= IFNULL(tst.amount,0))) hasStock,
|
||||
st.classColor futureClassColor,
|
||||
(
|
||||
count(s.id) -
|
||||
SUM((s.quantity <= IFNULL(tst.amount,0)))
|
||||
) notMovableLines,
|
||||
(
|
||||
count(s.id) =
|
||||
SUM((s.quantity <= IFNULL(tst.amount,0)))
|
||||
) isFullMovable
|
||||
FROM ticket t
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN saleVolume sv ON sv.saleFk = s.id
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN ticketState ts ON ts.ticketFk = t.id
|
||||
JOIN `state` st ON st.id = ts.stateFk
|
||||
JOIN agencyMode am ON t.agencyModeFk = am.id
|
||||
LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk
|
||||
LEFT JOIN tStock tst ON tst.itemFk = i.id
|
||||
WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture)
|
||||
AND t.warehouseFk = vWarehouseFk
|
||||
GROUP BY t.id
|
||||
) origin
|
||||
JOIN (
|
||||
SELECT t.id,
|
||||
t.addressFk,
|
||||
st.name state,
|
||||
GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt,
|
||||
t.shipped,
|
||||
t.totalWithVat,
|
||||
am.name agency,
|
||||
CAST(SUM(litros) AS DECIMAL(10,0)) liters,
|
||||
CAST(COUNT(*) AS DECIMAL(10,0)) `lines`,
|
||||
st.classColor,
|
||||
IF(HOUR(t.shipped),
|
||||
HOUR(t.shipped),
|
||||
COALESCE(HOUR(zc.hour),HOUR(z.hour))
|
||||
) preparation
|
||||
FROM ticket t
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN saleVolume sv ON sv.saleFk = s.id
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN ticketState ts ON ts.ticketFk = t.id
|
||||
JOIN `state` st ON st.id = ts.stateFk
|
||||
JOIN agencyMode am ON t.agencyModeFk = am.id
|
||||
JOIN ticketCanAdvanceConfig
|
||||
LEFT JOIN itemPackingType ipt ON ipt.code = i.itemPackingTypeFk
|
||||
LEFT JOIN `zone` z ON z.id = t.zoneFk
|
||||
LEFT JOIN zoneClosure zc ON zc.zoneFk = t.zoneFk
|
||||
WHERE t.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance)
|
||||
AND t.warehouseFk = vWarehouseFk
|
||||
AND st.order <= destinationOrder
|
||||
GROUP BY t.id
|
||||
) dest ON dest.addressFk = origin.futureAddressFk
|
||||
WHERE origin.hasStock != 0;
|
||||
|
||||
DROP TEMPORARY TABLE tStock;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -110,13 +110,12 @@ module.exports = Self => {
|
|||
|
||||
stmt = new ParameterizedSQL(
|
||||
`CALL vn.ticket_canAdvance(?,?,?)`,
|
||||
[args.dateFuture, args.dateToAdvance, args.warehouseFk]);
|
||||
[args.dateFuture, args.dateToAdvance, args.warehouseFk]
|
||||
);
|
||||
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
SELECT f.*
|
||||
FROM tmp.filter f`);
|
||||
stmt = new ParameterizedSQL(`SELECT f.* FROM tmp.filter f`);
|
||||
|
||||
stmt.merge(conn.makeWhere(filter.where));
|
||||
|
||||
|
@ -124,9 +123,7 @@ module.exports = Self => {
|
|||
stmt.merge(conn.makeLimit(filter));
|
||||
const ticketsIndex = stmts.push(stmt) - 1;
|
||||
|
||||
stmts.push(
|
||||
`DROP TEMPORARY TABLE
|
||||
tmp.filter`);
|
||||
stmts.push(`DROP TEMPORARY TABLE tmp.filter`);
|
||||
|
||||
const sql = ParameterizedSQL.join(stmts, ';');
|
||||
const result = await conn.executeStmt(sql, myOptions);
|
||||
|
|
|
@ -32,8 +32,8 @@
|
|||
<thead>
|
||||
<tr second-header>
|
||||
<td></td>
|
||||
<th colspan="7" translate>Destination</th>
|
||||
<th colspan="9" translate>Origin</th>
|
||||
<th colspan="9" translate>Destination</th>
|
||||
<th colspan="11" translate>Origin</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th shrink>
|
||||
|
@ -43,8 +43,7 @@
|
|||
check-field="checked">
|
||||
</vn-multi-check>
|
||||
</th>
|
||||
<th shrink>
|
||||
</th>
|
||||
<th shrink></th>
|
||||
<th field="id">
|
||||
<span translate>ID</span>
|
||||
</th>
|
||||
|
@ -54,6 +53,9 @@
|
|||
<th field="ipt" title="{{'Item Packing Type' | translate}}">
|
||||
<span>IPT</span>
|
||||
</th>
|
||||
<th field="preparation">
|
||||
<span translate>Preparation</span>
|
||||
</th>
|
||||
<th field="state">
|
||||
<span translate>State</span>
|
||||
</th>
|
||||
|
@ -120,6 +122,7 @@
|
|||
</span>
|
||||
</td>
|
||||
<td>{{::ticket.ipt | dashIfEmpty}}</td>
|
||||
<td>{{::ticket.preparation | dashIfEmpty}}</td>
|
||||
<td>
|
||||
<span
|
||||
class="chip {{ticket.classColor}}">
|
||||
|
@ -164,7 +167,6 @@
|
|||
{{::(ticket.futureTotalWithVat ? ticket.futureTotalWithVat : 0) | currency: 'EUR': 2}}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
@ -14,3 +14,4 @@ Success: Tickets movidos correctamente
|
|||
IPT: Encajado
|
||||
Origin Date: Fecha origen
|
||||
Destination Date: Fecha destino
|
||||
Preparation: Preparación
|
||||
|
|
Loading…
Reference in New Issue