Merge pull request 'fixes #3628 item historical absoluto' (!1539) from 3628-item-historical-absoluto into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #1539
Reviewed-by: Javi Gallego <jgallego@verdnatura.es>
This commit is contained in:
Alexandre Riera 2023-05-25 05:05:06 +00:00
commit 0d223bb443
8 changed files with 246 additions and 147 deletions

View File

@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- (Tickets -> Crear Factura) Al facturar se envia automáticamente el pdf al cliente
- (Artículos -> Histórico) Filtro para mostrar lo anterior al inventario
### Changed

View File

@ -61943,141 +61943,205 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getBalance`(IN vItemId int, IN vWarehouse int)
CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_getBalance`(vItemFk int, vWarehouseFk int, vDate DATETIME)
BEGIN
DECLARE vDateInventory DATETIME;
DECLARE vCurdate DATE DEFAULT util.VN_CURDATE();
DECLARE vDayEnd DATETIME DEFAULT util.dayEnd(vCurdate);
/**
* @vItemFk item a buscar
* @vWarehouseFk almacen donde buscar
* @vDate Si la fecha es null, muestra el histórico desde el inventario. Si la fecha no es null, muestra histórico desde la fecha pasada.
*/
SELECT inventoried INTO vDateInventory FROM config;
SET @a = 0;
SET @currentLineFk = 0;
SET @shipped = '';
DECLARE vDateInventory DATETIME;
DECLARE vInvCalculated INT;
SELECT DATE(@shipped:= shipped) shipped,
alertLevel,
stateName,
origin,
reference,
clientFk,
name,
`in` AS invalue,
`out`,
@a := @a + IFNULL(`in`,0) - IFNULL(`out`,0) as balance,
@currentLineFk := IF (@shipped < util.VN_CURDATE()
OR (@shipped = util.VN_CURDATE() AND (isPicked OR alertLevel >= 2)),
lineFk,@currentLineFk) lastPreparedLineFk,
isTicket,
lineFk,
isPicked,
clientType,
claimFk
FROM
( SELECT tr.landed AS shipped,
b.quantity AS `in`,
NULL AS `out`,
al.id AS alertLevel,
st.name AS stateName,
s.name AS name,
e.invoiceNumber AS reference,
e.id AS origin,
s.id AS clientFk,
IF(al.id = 3, TRUE, FALSE) isPicked,
FALSE AS isTicket,
b.id lineFk,
NULL `order`,
NULL AS clientType,
NULL AS claimFk
FROM buy b
JOIN entry e ON e.id = b.entryFk
JOIN travel tr ON tr.id = e.travelFk
JOIN supplier s ON s.id = e.supplierFk
JOIN alertLevel al ON al.id =
CASE
WHEN tr.landed < util.VN_CURDATE() THEN 3
WHEN tr.landed = util.VN_CURDATE() AND tr.isReceived = TRUE THEN 3
ELSE 0
END
JOIN state st ON st.code = al.code
WHERE tr.landed >= vDateInventory
AND vWarehouse = tr.warehouseInFk
AND b.itemFk = vItemId
AND e.isExcludedFromAvailable = FALSE
AND e.isRaid = FALSE
UNION ALL
IF vDate IS NULL THEN
SELECT inventoried INTO vDateInventory
FROM config;
ELSE
SELECT mockUtcTime INTO vDateInventory
FROM util.config;
END IF;
SELECT tr.shipped,
NULL,
b.quantity,
al.id,
st.name,
s.name,
e.invoiceNumber,
e.id,
s.id,
IF(al.id = 3, TRUE, FALSE),
FALSE,
b.id,
NULL,
NULL,
NULL
FROM buy b
JOIN entry e ON e.id = b.entryFk
JOIN travel tr ON tr.id = e.travelFk
JOIN warehouse w ON w.id = tr.warehouseOutFk
JOIN supplier s ON s.id = e.supplierFk
JOIN alertLevel al ON al.id =
CASE
WHEN tr.shipped < util.VN_CURDATE() THEN 3
WHEN tr.shipped = util.VN_CURDATE() AND tr.isReceived = TRUE THEN 3
ELSE 0
END
JOIN state st ON st.code = al.code
WHERE tr.shipped >= vDateInventory
AND vWarehouse =tr.warehouseOutFk
AND s.id <> 4
AND b.itemFk = vItemId
AND e.isExcludedFromAvailable = FALSE
AND w.isFeedStock = FALSE
AND e.isRaid = FALSE
UNION ALL
CREATE OR REPLACE TEMPORARY TABLE itemDiary(
shipped DATE,
`in` INT(11),
`out` INT(11),
alertLevel INT(11),
stateName VARCHAR(20),
`name` VARCHAR(50),
reference VARCHAR(50),
origin INT(11),
clientFk INT(11),
isPicked INT(11),
isTicket TINYINT(1),
lineFk INT(11),
`order` TINYINT(3) UNSIGNED,
clientType VARCHAR(20),
claimFk INT(10) UNSIGNED
);
SELECT DATE(t.shipped),
NULL,
s.quantity,
al.id,
st.name,
t.nickname,
t.refFk,
t.id,
t.clientFk,
stk.id,
TRUE,
s.id,
st.`order`,
ct.code,
cb.claimFk
FROM sale s
JOIN ticket t ON t.id = s.ticketFk
LEFT JOIN ticketState ts ON ts.ticket = t.id
LEFT JOIN state st ON st.code = ts.code
JOIN client c ON c.id = t.clientFk
JOIN clientType ct ON ct.id = c.clientTypeFk
JOIN alertLevel al ON al.id =
CASE
WHEN t.shipped < util.VN_CURDATE() THEN 3
WHEN t.shipped > util.dayEnd(util.VN_CURDATE()) THEN 0
ELSE IFNULL(ts.alertLevel, 0)
END
LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED'
LEFT JOIN saleTracking stk ON stk.saleFk = s.id AND stk.stateFk = stPrep.id
LEFT JOIN claimBeginning cb ON s.id = cb.saleFk
WHERE t.shipped >= vDateInventory
AND s.itemFk = vItemId
AND vWarehouse =t.warehouseFk
ORDER BY shipped, alertLevel DESC, isTicket, `order` DESC, isPicked DESC, `in` DESC, `out` DESC
) AS itemDiary;
INSERT INTO itemDiary
SELECT tr.landed shipped,
b.quantity `in`,
NULL `out`,
al.id alertLevel,
st.name stateName,
s.name `name`,
e.invoiceNumber reference,
e.id origin,
s.id clientFk,
IF(al.code = 'DELIVERED', TRUE, FALSE) isPicked,
FALSE isTicket,
b.id lineFk,
NULL `order`,
NULL clientType,
NULL claimFk
FROM buy b
JOIN entry e ON e.id = b.entryFk
JOIN travel tr ON tr.id = e.travelFk
JOIN supplier s ON s.id = e.supplierFk
JOIN alertLevel al ON al.code =
CASE
WHEN tr.landed < util.VN_CURDATE() THEN 'DELIVERED'
WHEN tr.landed = util.VN_CURDATE() AND tr.isReceived = TRUE THEN 'DELIVERED'
ELSE 'FREE'
END
JOIN state st ON st.code = al.code
WHERE tr.landed >= vDateInventory
AND vWarehouseFk = tr.warehouseInFk
AND b.itemFk = vItemFk
AND e.isExcludedFromAvailable = FALSE
AND e.isRaid = FALSE
UNION ALL
SELECT tr.shipped,
NULL,
b.quantity,
al.id,
st.name,
s.name,
e.invoiceNumber,
e.id,
s.id,
IF(al.code = 'DELIVERED', TRUE, FALSE),
FALSE,
b.id,
NULL,
NULL,
NULL
FROM buy b
JOIN entry e ON e.id = b.entryFk
JOIN travel tr ON tr.id = e.travelFk
JOIN warehouse w ON w.id = tr.warehouseOutFk
JOIN supplier s ON s.id = e.supplierFk
JOIN alertLevel al ON al.code =
CASE
WHEN tr.shipped < util.VN_CURDATE() THEN 'DELIVERED'
WHEN tr.shipped = util.VN_CURDATE() AND tr.isReceived = TRUE THEN 'DELIVERED'
ELSE 'FREE'
END
JOIN state st ON st.code = al.code
JOIN entryConfig ec
WHERE tr.shipped >= vDateInventory
AND vWarehouseFk =tr.warehouseOutFk
AND s.id <> ec.inventorySupplierFk
AND b.itemFk = vItemFk
AND e.isExcludedFromAvailable = FALSE
AND w.isFeedStock = FALSE
AND e.isRaid = FALSE
UNION ALL
SELECT DATE(t.shipped),
NULL,
s.quantity,
al3.id,
st.name,
t.nickname,
t.refFk,
t.id,
t.clientFk,
stk.id,
TRUE,
s.id,
st.`order`,
ct.code,
cb.claimFk
FROM sale s
JOIN ticket t ON t.id = s.ticketFk
LEFT JOIN ticketState ts ON ts.ticket = t.id
LEFT JOIN state st ON st.code = ts.code
JOIN client c ON c.id = t.clientFk
JOIN clientType ct ON ct.id = c.clientTypeFk
JOIN alertLevel al ON al.code = 'DELIVERED'
JOIN alertLevel al2 ON al2.code = 'FREE'
JOIN alertLevel al3 ON al3.id =
CASE
WHEN t.shipped < util.VN_CURDATE() THEN al.code
WHEN t.shipped > util.dayEnd(util.VN_CURDATE()) THEN al2.code
ELSE IFNULL(ts.alertLevel, al2.code)
END
LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED'
LEFT JOIN saleTracking stk ON stk.saleFk = s.id AND stk.stateFk = stPrep.id
LEFT JOIN claimBeginning cb ON s.id = cb.saleFk
WHERE t.shipped >= vDateInventory
AND s.itemFk = vItemFk
AND vWarehouseFk =t.warehouseFk
ORDER BY shipped, alertLevel DESC, isTicket, `order` DESC, isPicked DESC, `in` DESC, `out` DESC;
IF vDate IS NULL THEN
SET @a = 0;
SET @currentLineFk = 0;
SET @shipped = '';
SELECT DATE(@shipped:= shipped) shipped,
alertLevel,
stateName,
origin,
reference,
clientFk,
name,
`in` AS invalue,
`out`,
@a := @a + IFNULL(`in`,0) - IFNULL(`out`,0) as balance,
@currentLineFk := IF (@shipped < util.VN_CURDATE()
OR (@shipped = util.VN_CURDATE() AND (isPicked OR a.code >= 'ON_PREPARATION')),
lineFk, @currentLineFk) lastPreparedLineFk,
isTicket,
lineFk,
isPicked,
clientType,
claimFk
FROM itemDiary
JOIN alertLevel a ON a.id = itemDiary.alertLevel;
ELSE
SELECT sum(`in`) - sum(`out`) INTO vInvCalculated
FROM itemDiary
WHERE shipped < vDate;
SELECT p1.*
FROM(
SELECT vDate shipped,
0 alertLevel,
0 stateName,
0 origin,
'' reference,
0 clientFk,
'Inventario calculado',
vInvCalculated invalue,
NULL `out`,
0 balance,
0 lastPreparedLineFk,
0 isTicket,
0 lineFk,
0 isPicked,
0 clientType,
0 claimFk
UNION ALL
SELECT shipped, alertlevel, stateName, origin, reference, clientFk, name, `in`, `out`, 0,0, isTicket, lineFk, isPicked, clientType, claimFk
FROM itemDiary
WHERE shipped >= vDate
)as p1;
END IF;
DROP TEMPORARY TABLE itemDiary;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;

View File

@ -26,8 +26,8 @@ module.exports = Self => {
Object.assign(myOptions, options);
const where = filter.where;
const query = 'CALL vn.item_getBalance(?, ?)';
const [diary] = await Self.rawSql(query, [where.itemFk, where.warehouseFk], myOptions);
const query = 'CALL vn.item_getBalance(?, ?, ?)';
const [diary] = await Self.rawSql(query, [where.itemFk, where.warehouseFk, where.date], myOptions);
for (const entry of diary)
if (entry.clientType === 'loses') entry.highlighted = true;

View File

@ -21,7 +21,8 @@ describe('item getBalance()', () => {
const filter = {
where: {
itemFk: 1,
warehouseFk: 1
warehouseFk: 1,
date: null
}
};
const results = await models.Item.getBalance(filter, options);
@ -45,14 +46,16 @@ describe('item getBalance()', () => {
const firstFilter = {
where: {
itemFk: 1,
warehouseFk: 1
warehouseFk: 1,
date: null
}
};
const secondFilter = {
where: {
itemFk: 2,
warehouseFk: 1
warehouseFk: 1,
date: null
}
};

View File

@ -25,6 +25,16 @@
ng-model="$ctrl.warehouseFk"
label="Select warehouse">
</vn-autocomplete>
<vn-check
ng-class="{'table-check':$ctrl.showOld}"
label="Show what's before the inventory"
ng-model="$ctrl.showOld">
</vn-check>
<vn-date-picker
label="Since"
ng-model="$ctrl.date"
ng-show="$ctrl.showOld">
</vn-date-picker>
</vn-horizontal>
<vn-table model="model">
<vn-thead>
@ -44,7 +54,7 @@
<vn-tr
ng-class="::{
'isIn': sale.invalue,
'balanceNegative': sale.balance < 0}"
'balanceNegative': sale.balance < 0}"
ng-repeat="sale in sales"
vn-repeat-last
on-last="$ctrl.scrollToLine(sale.lastPreparedLineFk)"
@ -58,7 +68,7 @@
</a>
</vn-td>
<vn-td expand>
<span class="chip"
<span class="chip"
ng-class="::{warning: $ctrl.today == sale.shipped}">
{{::sale.shipped | date:'dd/MM/yyyy' }}
</span>
@ -99,13 +109,13 @@
</vn-vertical>
</vn-card>
</vn-vertical>
<vn-ticket-descriptor-popover
<vn-ticket-descriptor-popover
vn-id="ticket-descriptor">
</vn-ticket-descriptor-popover>
<vn-client-descriptor-popover
<vn-client-descriptor-popover
vn-id="clientDescriptor">
</vn-client-descriptor-popover>
<vn-entry-descriptor-popover
<vn-entry-descriptor-popover
vn-id="entryDescriptor">
</vn-entry-descriptor-popover>

View File

@ -38,12 +38,8 @@ class Controller extends Section {
if (value && value != this._warehouseFk) {
this._warehouseFk = value;
this.card.warehouseFk = value;
this.filter.where.warehouseFk = this.warehouseFk;
this.$state.go(this.$state.current.name, {
warehouseFk: value
});
this.filter.where.warehouseFk = value;
this.$.model.refresh();
}
}
@ -52,6 +48,28 @@ class Controller extends Section {
return this._warehouseFk;
}
set date(value) {
this._date = value;
this.filter.where.date = value;
this.filter.where.warehouseFk = this.warehouseFk;
this.$.model.refresh();
}
get date() {
return this._date;
}
set showOld(value) {
this._showOld = value;
if (!this._showOld) this.date = null;
else this.date = new Date();
}
get showOld() {
return this._showOld;
}
scrollToLine(lineFk) {
this.$.$applyAsync(() => {
const hashFk = this.lineFk || lineFk;

View File

@ -1,4 +1,5 @@
In: Entrada
Out: Salida
Visible quantity: Cantidad visible
Ticket/Entry: Ticket/Entrada
Ticket/Entry: Ticket/Entrada
Show what's before the inventory: Mostrar lo anterior al inventario

View File

@ -27,4 +27,7 @@ vn-item-diary {
overflow: hidden;
text-overflow: ellipsis;
}
}
.table-check{
justify-content: center;
}
}