8032-devToTest_2440 #3009

Merged
alexm merged 262 commits from 8032-devToTest_2440 into test 2024-09-24 09:34:49 +00:00
4 changed files with 140 additions and 12 deletions
Showing only changes of commit 78eba23d12 - Show all commits

View File

@ -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 ;

View File

@ -110,13 +110,12 @@ module.exports = Self => {
stmt = new ParameterizedSQL( stmt = new ParameterizedSQL(
`CALL vn.ticket_canAdvance(?,?,?)`, `CALL vn.ticket_canAdvance(?,?,?)`,
[args.dateFuture, args.dateToAdvance, args.warehouseFk]); [args.dateFuture, args.dateToAdvance, args.warehouseFk]
);
stmts.push(stmt); stmts.push(stmt);
stmt = new ParameterizedSQL(` stmt = new ParameterizedSQL(`SELECT f.* FROM tmp.filter f`);
SELECT f.*
FROM tmp.filter f`);
stmt.merge(conn.makeWhere(filter.where)); stmt.merge(conn.makeWhere(filter.where));
@ -124,9 +123,7 @@ module.exports = Self => {
stmt.merge(conn.makeLimit(filter)); stmt.merge(conn.makeLimit(filter));
const ticketsIndex = stmts.push(stmt) - 1; const ticketsIndex = stmts.push(stmt) - 1;
stmts.push( stmts.push(`DROP TEMPORARY TABLE tmp.filter`);
`DROP TEMPORARY TABLE
tmp.filter`);
const sql = ParameterizedSQL.join(stmts, ';'); const sql = ParameterizedSQL.join(stmts, ';');
const result = await conn.executeStmt(sql, myOptions); const result = await conn.executeStmt(sql, myOptions);

View File

@ -32,8 +32,8 @@
<thead> <thead>
<tr second-header> <tr second-header>
<td></td> <td></td>
<th colspan="7" translate>Destination</th> <th colspan="9" translate>Destination</th>
<th colspan="9" translate>Origin</th> <th colspan="11" translate>Origin</th>
</tr> </tr>
<tr> <tr>
<th shrink> <th shrink>
@ -43,8 +43,7 @@
check-field="checked"> check-field="checked">
</vn-multi-check> </vn-multi-check>
</th> </th>
<th shrink> <th shrink></th>
</th>
<th field="id"> <th field="id">
<span translate>ID</span> <span translate>ID</span>
</th> </th>
@ -54,6 +53,9 @@
<th field="ipt" title="{{'Item Packing Type' | translate}}"> <th field="ipt" title="{{'Item Packing Type' | translate}}">
<span>IPT</span> <span>IPT</span>
</th> </th>
<th field="preparation">
<span translate>Preparation</span>
</th>
<th field="state"> <th field="state">
<span translate>State</span> <span translate>State</span>
</th> </th>
@ -120,6 +122,7 @@
</span> </span>
</td> </td>
<td>{{::ticket.ipt | dashIfEmpty}}</td> <td>{{::ticket.ipt | dashIfEmpty}}</td>
<td>{{::ticket.preparation | dashIfEmpty}}</td>
<td> <td>
<span <span
class="chip {{ticket.classColor}}"> class="chip {{ticket.classColor}}">
@ -164,7 +167,6 @@
{{::(ticket.futureTotalWithVat ? ticket.futureTotalWithVat : 0) | currency: 'EUR': 2}} {{::(ticket.futureTotalWithVat ? ticket.futureTotalWithVat : 0) | currency: 'EUR': 2}}
</span> </span>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -14,3 +14,4 @@ Success: Tickets movidos correctamente
IPT: Encajado IPT: Encajado
Origin Date: Fecha origen Origin Date: Fecha origen
Destination Date: Fecha destino Destination Date: Fecha destino
Preparation: Preparación