diff --git a/db/changes/230401/00-ticket_canAdvance.sql b/db/changes/230401/00-ticket_canAdvance.sql
new file mode 100644
index 000000000..497defebe
--- /dev/null
+++ b/db/changes/230401/00-ticket_canAdvance.sql
@@ -0,0 +1,100 @@
+DROP PROCEDURE IF EXISTS vn.ticket_canAdvance;
+
+DELIMITER $$
+$$
+CREATE 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 vn.config;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.stock;
+ CREATE TEMPORARY TABLE tmp.stock
+ (itemFk INT PRIMARY KEY,
+ amount INT)
+ ENGINE = MEMORY;
+
+ INSERT INTO tmp.stock(itemFk, amount)
+ SELECT itemFk, SUM(quantity) amount FROM
+ (
+ SELECT itemFk, quantity
+ FROM vn.itemTicketOut
+ WHERE shipped >= vDateInventory
+ AND shipped < vDateFuture
+ AND warehouseFk = vWarehouseFk
+ UNION ALL
+ SELECT itemFk, quantity
+ FROM vn.itemEntryIn
+ WHERE landed >= vDateInventory
+ AND landed < vDateFuture
+ AND isVirtualStock = FALSE
+ AND warehouseInFk = vWarehouseFk
+ UNION ALL
+ SELECT itemFk, quantity
+ FROM vn.itemEntryOut
+ WHERE shipped >= vDateInventory
+ AND shipped < vDateFuture
+ AND warehouseOutFk = vWarehouseFk
+ ) t
+ GROUP BY itemFk HAVING amount != 0;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.filter;
+ CREATE TEMPORARY TABLE tmp.filter
+ (INDEX (id))
+ SELECT s.ticketFk futureId,
+ t2.ticketFk id,
+ sum((s.quantity <= IFNULL(st.amount,0))) hasStock,
+ count(DISTINCT s.id) saleCount,
+ t2.state,
+ t2.isNotValidated,
+ st.name futureState,
+ st.isNotValidated futureIsNotValidated,
+ GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) futureIpt,
+ t2.ipt,
+ t.workerFk,
+ CAST(sum(litros) AS DECIMAL(10,0)) liters,
+ CAST(count(*) AS DECIMAL(10,0)) `lines`,
+ t2.shipped,
+ t.shipped futureShipped,
+ t2.totalWithVat,
+ t.totalWithVat futureTotalWithVat
+ FROM vn.ticket t
+ JOIN vn.ticketState ts ON ts.ticketFk = t.id
+ JOIN vn.state st ON st.id = ts.stateFk
+ JOIN vn.saleVolume sv ON t.id = sv.ticketFk
+ JOIN (SELECT
+ t2.id ticketFk,
+ t2.addressFk,
+ st.isNotValidated,
+ st.name state,
+ GROUP_CONCAT(DISTINCT ipt.code ORDER BY ipt.code) ipt,
+ t2.shipped,
+ t2.totalWithVat
+ FROM vn.ticket t2
+ JOIN vn.sale s ON s.ticketFk = t2.id
+ JOIN vn.item i ON i.id = s.itemFk
+ JOIN vn.ticketState ts ON ts.ticketFk = t2.id
+ JOIN vn.state st ON st.id = ts.stateFk
+ LEFT JOIN vn.itemPackingType ipt ON ipt.code = i.itemPackingTypeFk
+ WHERE t2.shipped BETWEEN vDateToAdvance AND util.dayend(vDateToAdvance)
+ AND t2.warehouseFk = vWarehouseFk
+ GROUP BY t2.id) t2 ON t2.addressFk = t.addressFk
+ JOIN vn.sale s ON s.ticketFk = t.id
+ JOIN vn.item i ON i.id = s.itemFk
+ LEFT JOIN vn.itemPackingType ipt ON ipt.code = i.itemPackingTypeFk
+ LEFT JOIN tmp.stock st ON st.itemFk = s.itemFk
+ WHERE t.shipped BETWEEN vDateFuture AND util.dayend(vDateFuture)
+ AND t.warehouseFk = vWarehouseFk
+ GROUP BY t.id;
+
+ DROP TEMPORARY TABLE tmp.stock;
+END$$
+DELIMITER ;
diff --git a/modules/ticket/back/methods/ticket/getTicketsAdvance.js b/modules/ticket/back/methods/ticket/getTicketsAdvance.js
index 19571bb51..a7dea56e2 100644
--- a/modules/ticket/back/methods/ticket/getTicketsAdvance.js
+++ b/modules/ticket/back/methods/ticket/getTicketsAdvance.js
@@ -50,14 +50,14 @@ module.exports = Self => {
required: false
},
{
- arg: 'state',
- type: 'string',
+ arg: 'isNotValidated',
+ type: 'boolean',
description: 'Origin state',
required: false
},
{
- arg: 'futureState',
- type: 'string',
+ arg: 'futureIsNotValidated',
+ type: 'boolean',
description: 'Destination state',
required: false
},
@@ -95,10 +95,10 @@ module.exports = Self => {
return {'f.ipt': value};
case 'futureIpt':
return {'f.futureIpt': value};
- case 'state':
- return {'f.stateCode': {like: `%${value}%`}};
- case 'futureState':
- return {'f.futureStateCode': {like: `%${value}%`}};
+ case 'isNotValidated':
+ return {'f.isNotValidated': value};
+ case 'futureIsNotValidated':
+ return {'f.futureIsNotValidated': value};
}
});
diff --git a/modules/ticket/front/advance-search-panel/index.html b/modules/ticket/front/advance-search-panel/index.html
index e8d5dc60d..dfe1f6b08 100644
--- a/modules/ticket/front/advance-search-panel/index.html
+++ b/modules/ticket/front/advance-search-panel/index.html
@@ -39,26 +39,18 @@
-
-
- {{name}}
-
-
-
-
- {{name}}
-
-
+
+
+
+
{
- for (let state of res.data) {
- groupedStates.push({
- id: state.id,
- code: state.code,
- name: this.$t(state.code)
- });
- }
- this.groupedStates = groupedStates;
- });
- }
-
getItemPackingTypes() {
let itemPackingTypes = [];
const filter = {
diff --git a/modules/ticket/front/advance-search-panel/locale/es.yml b/modules/ticket/front/advance-search-panel/locale/es.yml
index 3dce7dae5..4ea2fc737 100644
--- a/modules/ticket/front/advance-search-panel/locale/es.yml
+++ b/modules/ticket/front/advance-search-panel/locale/es.yml
@@ -1 +1,3 @@
Advance tickets: Adelantar tickets
+Pending Origin: Pendiente origen
+Pending Destination: Pendiente destino