7430_devToTest #2490
|
@ -1,3 +1,4 @@
|
|||
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
@ -12,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- (InvoiceOut -> Crear factura) Cuando falla al crear una factura, se devuelve un error
|
||||
- (Worker -> Ver albarán) Ya no aparece la página en blanco
|
||||
|
||||
### Changed
|
||||
- (InvoiceOut) Las facturas ahora muestran el ticket del cual proviene el abono
|
||||
|
||||
## [24.18.01] - 2024-05-07
|
||||
|
||||
## [24.16.01] - 2024-04-18
|
||||
|
|
|
@ -54,6 +54,12 @@ For end-to-end tests run from project's root.
|
|||
$ npm run test:e2e
|
||||
```
|
||||
|
||||
## Generate changeLog test → master
|
||||
```
|
||||
$ bash changelog.sh
|
||||
```
|
||||
|
||||
|
||||
## Visual Studio Code extensions
|
||||
|
||||
Open Visual Studio Code, press Ctrl+P and paste the following commands.
|
||||
|
|
|
@ -39,8 +39,6 @@ module.exports = Self => {
|
|||
const xmlString = response.data;
|
||||
const parser = new DOMParser();
|
||||
const xmlDoc = parser.parseFromString(xmlString, 'text/xml');
|
||||
const [resultElement] = xmlDoc.getElementsByTagName('Mensaje');
|
||||
|
||||
return resultElement.textContent;
|
||||
return xmlDoc.getElementsByTagName('Mensaje')[0].textContent;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -42,7 +42,8 @@ module.exports = Self => {
|
|||
throw new UserError(`Some mrwConfig parameters are not set`);
|
||||
|
||||
const query =
|
||||
`SELECT CASE co.code
|
||||
`SELECT
|
||||
CASE co.code
|
||||
WHEN 'ES' THEN a.postalCode
|
||||
WHEN 'PT' THEN LEFT(a.postalCode, 4)
|
||||
WHEN 'AD' THEN REPLACE(a.postalCode, 'AD', '00')
|
||||
|
@ -89,14 +90,9 @@ module.exports = Self => {
|
|||
const getLabelResponse = await sendXmlDoc('getLabel', {mrw, shipmentId}, 'text/xml');
|
||||
const file = getTextByTag(getLabelResponse, 'EtiquetaFile');
|
||||
|
||||
try {
|
||||
await models.Expedition.updateAll({id: expeditionFk}, {externalId: shipmentId}, myOptions);
|
||||
if (tx) await tx.commit();
|
||||
} catch (error) {
|
||||
if (tx) await tx.rollback();
|
||||
throw error;
|
||||
}
|
||||
return file;
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return {shipmentId, file};
|
||||
};
|
||||
|
||||
function getTextByTag(xmlDoc, tag) {
|
||||
|
|
|
@ -81,9 +81,9 @@ describe('MRWConfig createShipment()', () => {
|
|||
|
||||
spyOn(axios, 'post').and.callFake(() => Promise.resolve(mockPostResponses.pop()));
|
||||
|
||||
const base64Binary = await models.MrwConfig.createShipment(expedition1.id, options);
|
||||
const {file} = await models.MrwConfig.createShipment(expedition1.id, options);
|
||||
|
||||
expect(base64Binary).toEqual(mockBase64Binary);
|
||||
expect(file).toEqual(mockBase64Binary);
|
||||
});
|
||||
|
||||
it('should fail if mrwConfig has no data', async() => {
|
||||
|
|
|
@ -45,7 +45,7 @@ module.exports = Self => {
|
|||
{'pc.code': {like: `%${value}%`}},
|
||||
{'t.name': {like: `%${value}%`}},
|
||||
{'p.name': {like: `%${value}%`}},
|
||||
{'c.country': {like: `%${value}%`}}
|
||||
{'c.name': {like: `%${value}%`}}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ module.exports = Self => {
|
|||
pc.code,
|
||||
t.name as town,
|
||||
p.name as province,
|
||||
c.country
|
||||
c.name country
|
||||
FROM
|
||||
postCode pc
|
||||
JOIN town t on t.id = pc.townFk
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
"id": true,
|
||||
"description": "Identifier"
|
||||
},
|
||||
"country": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
features_types=(chore feat style)
|
||||
changes_types=(refactor perf)
|
||||
fix_types=(fix revert)
|
||||
file="CHANGELOG.md"
|
||||
file_tmp="temp_log.txt"
|
||||
file_current_tmp="temp_current_log.txt"
|
||||
|
||||
setType(){
|
||||
echo "### $1" >> $file_tmp
|
||||
arr=("$@")
|
||||
echo "" > $file_current_tmp
|
||||
for i in "${arr[@]}"
|
||||
do
|
||||
git log --grep="$i" --oneline --no-merges --format="- %s %d by:%an" master..test >> $file_current_tmp
|
||||
done
|
||||
# remove duplicates
|
||||
sort -o $file_current_tmp -u $file_current_tmp
|
||||
cat $file_current_tmp >> $file_tmp
|
||||
echo "" >> $file_tmp
|
||||
# remove tmp current file
|
||||
[ -e $file_current_tmp ] && rm $file_current_tmp
|
||||
}
|
||||
|
||||
echo "# Version XX.XX - XXXX-XX-XX" >> $file_tmp
|
||||
echo "" >> $file_tmp
|
||||
|
||||
setType "Added 🆕" "${features_types[@]}"
|
||||
setType "Changed 📦" "${changes_types[@]}"
|
||||
setType "Fixed 🛠️" "${fix_types[@]}"
|
||||
|
||||
cat $file >> $file_tmp
|
||||
mv $file_tmp $file
|
||||
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
},
|
||||
"vn": {
|
||||
"view": {
|
||||
"expeditionPallet_Print": "288cbd6e8289df083ed5eb1a2c808f7a82ba4c90c8ad9781104808a7a54471fb"
|
||||
"expeditionPallet_Print": "06613719475fcdba8309607c38cc78efc2e348cca7bc96b48dc3ae3c12426f54"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
const fs = require('fs');
|
||||
const {spawn} = require('child_process');
|
||||
|
||||
function watchDatabaseChanges() {
|
||||
console.log('Watching for changes in db/routines and db/versions');
|
||||
fs.watch('db', {recursive: true}, (eventType, filename) => {
|
||||
if (filename.endsWith('.sql')) {
|
||||
let command;
|
||||
if (filename.startsWith('routines')) command = 'push';
|
||||
else if (filename.startsWith('versions')) command = 'run';
|
||||
|
||||
if (command) {
|
||||
const process = spawn('myt', [command]);
|
||||
process.stdout.on('data', data => console.log(data.toString()));
|
||||
process.stderr.on('data', data => console.error(`stderr: ${data}`));
|
||||
process.on('error', error => console.error(`error: ${error.message}`));
|
||||
process.on('close', () => console.log('Watching for changes in db/routines and db/versions'));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (require.main === module) watchDatabaseChanges();
|
||||
module.exports = watchDatabaseChanges;
|
|
@ -162,7 +162,7 @@ INSERT INTO `vn`.`currency`(`id`, `code`, `name`, `ratio`)
|
|||
(4, 'JPY', 'Yen Japones', 1),
|
||||
(5, 'CNY', 'Yuan Chino', 1.2);
|
||||
|
||||
INSERT INTO `vn`.`country`(`id`, `country`, `isUeeMember`, `code`, `currencyFk`, `ibanLength`, `continentFk`, `hasDailyInvoice`, `CEE`)
|
||||
INSERT INTO `vn`.`country`(`id`, `name`, `isUeeMember`, `code`, `currencyFk`, `ibanLength`, `continentFk`, `hasDailyInvoice`, `CEE`)
|
||||
VALUES
|
||||
(1, 'España', 1, 'ES', 1, 24, 4, 0, 1),
|
||||
(2, 'Italia', 1, 'IT', 1, 27, 4, 0, 1),
|
||||
|
@ -2562,7 +2562,7 @@ REPLACE INTO `vn`.`invoiceIn`(`id`, `serialNumber`,`serial`, `supplierFk`, `issu
|
|||
(9, 1009, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1242, 0, 442, 1),
|
||||
(10, 1010, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1243, 0, 442, 1);
|
||||
|
||||
INSERT INTO `vn`.`invoiceInConfig` (`id`, `retentionRate`, `retentionName`, `sageWithholdingFk`, `daysAgo`)
|
||||
INSERT INTO `vn`.`invoiceInConfig` (`id`, `retentionRate`, `retentionName`, `sageFarmerWithholdingFk`, `daysAgo`)
|
||||
VALUES
|
||||
(1, -2, '2% retention', 2, 45);
|
||||
|
||||
|
@ -3789,4 +3789,6 @@ INSERT INTO vn.workerTeam(id, team, workerFk)
|
|||
(8, 1, 19);
|
||||
|
||||
INSERT INTO vn.workCenter (id, name, payrollCenterFk, counter, warehouseFk, street, geoFk, deliveryManAdjustment)
|
||||
VALUES(100, 'workCenterOne', 1, NULL, 1, 'gotham', NULL, NULL);
|
||||
VALUES(100, 'workCenterOne', 1, NULL, 1, 'gotham', NULL, NULL);
|
||||
|
||||
UPDATE vn.locker SET workerFk = 1110 WHERE id = 147;
|
|
@ -34,7 +34,7 @@ BEGIN
|
|||
vPrinterFk,
|
||||
IFNULL(right(`t`.`routeFk`, 3),0),
|
||||
if (@vVolume := vn.ticketTotalVolume(t.id) > 1.5, @vVolume, IFNULL( rm.beachFk, 0)),
|
||||
LEFT(IFNULL(et.description ,replace(`z`.`name`, 'ZONA ', 'Z')),14) truckName,
|
||||
LEFT(IFNULL(rs.description ,replace(`z`.`name`, 'ZONA ', 'Z')),14) truckName,
|
||||
t.clientFk ,
|
||||
ifnull(c.mobile, ifnull(a.mobile, ifnull(c.phone, a.phone))),
|
||||
LEFT(p.name, 20),
|
||||
|
@ -46,7 +46,7 @@ BEGIN
|
|||
JOIN vn.address a ON a.id = t.addressFk
|
||||
JOIN vn.province p ON p.id = a.provinceFk
|
||||
LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk
|
||||
LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk
|
||||
LEFT JOIN vn.roadmapStop rs ON rs.id = rm.expeditionTruckFk
|
||||
LEFT JOIN vn.beach b ON b.code = rm.beachFk
|
||||
LEFT JOIN vn.`zone`z ON z.id = t.zoneFk
|
||||
JOIN vn.agencyMode am ON t.agencyModeFk = am.id
|
||||
|
|
|
@ -53,7 +53,7 @@ BEGIN
|
|||
IFNULL(c.street, ''),
|
||||
c.accountingAccount,
|
||||
@fi := IF(cu.code = LEFT(TRIM(c.fi), 2) AND c.isVies, MID(TRIM(c.fi), 3, LENGTH(TRIM(c.fi))-1), TRIM(c.fi)),
|
||||
IF(c.isVies, CONCAT(cu.code, @fi ), TRIM(c.fi)),
|
||||
IF(c.isVies, CONCAT(IFNULL(cu.viesCode,cu.code), @fi ), TRIM(c.fi)),
|
||||
IFNULL(c.postcode, ''),
|
||||
IFNULL(c.city, ''),
|
||||
IFNULL(pr.CodigoProvincia, ''),
|
||||
|
@ -91,7 +91,7 @@ BEGIN
|
|||
IFNULL(s.street, ''),
|
||||
s.account,
|
||||
@nif := IF(co.code = LEFT(TRIM(s.nif), 2), MID(TRIM(s.nif), 3, LENGTH(TRIM(s.nif))-1), TRIM(s.nif)),
|
||||
IF(s.isVies, CONCAT(co.code, @nif), TRIM(s.nif)),
|
||||
IF(s.isVies, CONCAT(IFNULL(co.viesCode,co.code), @nif), TRIM(s.nif)),
|
||||
IFNULL(s.postCode,''),
|
||||
IFNULL(s.city, ''),
|
||||
IFNULL(pr.CodigoProvincia, ''),
|
||||
|
|
|
@ -15,14 +15,14 @@ BEGIN
|
|||
|
||||
DECLARE vDayMinute INT;
|
||||
|
||||
SELECT HOUR(IFNULL(et.ETD, z.`hour`)) * 60 + MINUTE(IFNULL(et.ETD, z.`hour`)) INTO vDayMinute
|
||||
SELECT HOUR(IFNULL(rs.ETD, z.`hour`)) * 60 + MINUTE(IFNULL(rs.ETD, z.`hour`)) INTO vDayMinute
|
||||
FROM vn.expedition e
|
||||
JOIN vn.ticket t ON e.ticketFk = t.id
|
||||
JOIN vn.`zone` z ON z.id = t.zoneFk
|
||||
LEFT JOIN vn.route r ON r.id = t.routeFk
|
||||
LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk
|
||||
LEFT JOIN vn.routesMonitor rm ON t.routeFk = rm.routeFk
|
||||
LEFT JOIN vn.expeditionTruck et ON rm.expeditionTruckFk = et.id
|
||||
LEFT JOIN vn.roadmapStop rs ON rm.expeditionTruckFk = rs.id
|
||||
WHERE e.id = vExpeditionFk;
|
||||
|
||||
RETURN vDayMinute;
|
||||
|
|
|
@ -296,8 +296,8 @@ BEGIN
|
|||
|
||||
SET @dm := (24 * 60) - 10;
|
||||
|
||||
UPDATE vn.expeditionTruck et
|
||||
SET et.eta = timestampadd(MINUTE ,@dm := 1 + @dm,util.VN_CURDATE())
|
||||
UPDATE vn.roadmapStop rs
|
||||
SET rs.eta = timestampadd(MINUTE ,@dm := 1 + @dm,util.VN_CURDATE())
|
||||
WHERE description LIKE 'PRU%' ;
|
||||
|
||||
DELETE FROM srt.movingLog ;
|
||||
|
|
|
@ -3,10 +3,10 @@ CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|||
VIEW `srt`.`bufferDayMinute`
|
||||
AS SELECT `b`.`id` AS `bufferFk`,
|
||||
`e`.`id` AS `expeditionFk`,
|
||||
`srt`.`dayMinute`(IFNULL(`et`.`eta`, `z`.`hour`)) AS `dayMinute`,
|
||||
`srt`.`dayMinute`(IFNULL(`rs`.`eta`, `z`.`hour`)) AS `dayMinute`,
|
||||
`e`.`position` AS `position`,
|
||||
IFNULL(
|
||||
`et`.`eta`,
|
||||
`rs`.`eta`,
|
||||
`util`.`VN_CURDATE`() + INTERVAL `srt`.`dayMinute`(`z`.`hour`) MINUTE
|
||||
) AS `ETD`,
|
||||
`e2`.`ticketFk` AS `ticketFk`,
|
||||
|
@ -34,7 +34,7 @@ FROM (
|
|||
)
|
||||
LEFT JOIN `vn`.`routesMonitor` `rm` ON(`t`.`routeFk` = `rm`.`routeFk`)
|
||||
)
|
||||
LEFT JOIN `vn`.`expeditionTruck` `et` ON(`rm`.`expeditionTruckFk` = `et`.`id`)
|
||||
LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rm`.`expeditionTruckFk` = `rs`.`id`)
|
||||
)
|
||||
LEFT JOIN `vn`.`zone` `z` ON(`z`.`id` = `t`.`zoneFk`)
|
||||
)
|
||||
|
|
|
@ -4,22 +4,22 @@ CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|||
AS SELECT `e`.`id` AS `expeditionFk`,
|
||||
`e`.`bufferFk` AS `bufferFk`,
|
||||
`e`.`position` AS `position`,
|
||||
`srt`.`dayMinute`(IFNULL(`et`.`eta`, `z`.`hour`)) AS `dayMinute`,
|
||||
`srt`.`dayMinute`(IFNULL(`rs`.`eta`, `z`.`hour`)) AS `dayMinute`,
|
||||
IFNULL(
|
||||
`et`.`eta`,
|
||||
`rs`.`eta`,
|
||||
`util`.`VN_CURDATE`() + INTERVAL `srt`.`dayMinute`(`z`.`hour`) + 120 MINUTE
|
||||
) AS `eta`,
|
||||
`ve`.`ticketFk` AS `ticketFk`,
|
||||
IFNULL(`t`.`routeFk`, `t`.`agencyModeFk`) AS `routeFk`,
|
||||
`z`.`name` AS `zonaTicket`,
|
||||
`et`.`description` AS `truck`,
|
||||
`rs`.`description` AS `truck`,
|
||||
`es`.`description` AS `expeditionState`,
|
||||
`b`.`hasWorkerWaiting` AS `hasWorkerWaiting`,
|
||||
`b`.`isActive` AS `isActive`,
|
||||
IF(
|
||||
`et`.`id` IS NULL,
|
||||
`rs`.`id` IS NULL,
|
||||
`c`.`bufferDefault`,
|
||||
`et`.`bufferFk`
|
||||
`rs`.`bufferFk`
|
||||
) AS `bufferTruck`,
|
||||
`bt`.`typeName` AS `typeName`,
|
||||
`rm`.`bufferFk` AS `routeBuffer`
|
||||
|
@ -45,7 +45,7 @@ FROM (
|
|||
)
|
||||
LEFT JOIN `vn`.`routesMonitor` `rm` ON(`t`.`routeFk` = `rm`.`routeFk`)
|
||||
)
|
||||
LEFT JOIN `vn`.`expeditionTruck` `et` ON(`rm`.`expeditionTruckFk` = `et`.`id`)
|
||||
LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rm`.`expeditionTruckFk` = `rs`.`id`)
|
||||
)
|
||||
JOIN `srt`.`config` `c`
|
||||
)
|
||||
|
|
|
@ -4,13 +4,13 @@ CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|||
AS SELECT `e`.`id` AS `expeditionFk`,
|
||||
`e`.`id` MOD 10000 AS `expedition`,
|
||||
IFNULL(
|
||||
`et`.`eta`,
|
||||
`rs`.`eta`,
|
||||
`util`.`VN_CURDATE`() + INTERVAL `srt`.`dayMinute`(`z`.`hour`) + 120 MINUTE
|
||||
) AS `ETD`,
|
||||
`ve`.`ticketFk` AS `ticketFk`,
|
||||
right(IFNULL(`t`.`routeFk`, `t`.`agencyModeFk`), 3) AS `routeFk`,
|
||||
`z`.`name` AS `zonaTicket`,
|
||||
`et`.`description` AS `truck`,
|
||||
`rs`.`description` AS `truck`,
|
||||
`epo`.`workerCode` AS `worker`,
|
||||
`p`.`name` AS `labeler`,
|
||||
`ve`.`counter` AS `expeditionCounter`,
|
||||
|
@ -32,7 +32,7 @@ FROM (
|
|||
)
|
||||
LEFT JOIN `vn`.`routesMonitor` `rm` ON(`t`.`routeFk` = `rm`.`routeFk`)
|
||||
)
|
||||
LEFT JOIN `vn`.`expeditionTruck` `et` ON(`rm`.`expeditionTruckFk` = `et`.`id`)
|
||||
LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rm`.`expeditionTruckFk` = `rs`.`id`)
|
||||
)
|
||||
JOIN `dipole`.`expedition_PrintOut` `epo` ON(`epo`.`expeditionFk` = `e`.`id`)
|
||||
)
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`client_userDisable`
|
||||
ON SCHEDULE EVERY 1 MONTH
|
||||
STARTS '2023-06-01 00:00:00.000'
|
||||
ON COMPLETION PRESERVE
|
||||
ENABLE
|
||||
DO CALL client_userDisable()$$
|
||||
DELIMITER ;
|
|
@ -1,25 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`clientsDisable`
|
||||
ON SCHEDULE EVERY 1 MONTH
|
||||
STARTS '2023-06-01 00:00:00.000'
|
||||
ON COMPLETION PRESERVE
|
||||
ENABLE
|
||||
DO BEGIN
|
||||
UPDATE account.user u
|
||||
JOIN client c ON c.id = u.id
|
||||
LEFT JOIN account.account a ON a.id = u.id
|
||||
SET u.active = FALSE
|
||||
WHERE c.typeFk = 'normal'
|
||||
AND a.id IS NULL
|
||||
AND u.active
|
||||
AND c.created < util.VN_CURDATE() - INTERVAL 12 MONTH
|
||||
AND u.id NOT IN (
|
||||
SELECT DISTINCT c.id
|
||||
FROM client c
|
||||
LEFT JOIN ticket t ON t.clientFk = c.id
|
||||
WHERE c.salesPersonFk IS NOT NULL
|
||||
OR t.created > util.VN_CURDATE() - INTERVAL 12 MONTH
|
||||
OR shipped > util.VN_CURDATE() - INTERVAL 12 MONTH
|
||||
);
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,28 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`sale_hasComponentLack`(
|
||||
vSelf INT
|
||||
)RETURNS tinyint(1)
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
/**
|
||||
* Check if a sales line has all the required components.
|
||||
*
|
||||
* @param vSelf Id de sale
|
||||
* @return BOOL
|
||||
*/
|
||||
DECLARE vHasComponentLack TINYINT(1);
|
||||
|
||||
WITH componentRequired AS(
|
||||
SELECT COUNT(*) total
|
||||
FROM vn.component
|
||||
WHERE isRequired
|
||||
)SELECT SUM(IF(c.isRequired, TRUE, FALSE)) <> cr.total INTO vHasComponentLack
|
||||
FROM vn.sale s
|
||||
JOIN componentRequired cr
|
||||
LEFT JOIN vn.saleComponent sc ON sc.saleFk = s.id
|
||||
LEFT JOIN vn.component c ON c.id = sc.componentFk
|
||||
WHERE s.id = vSelf;
|
||||
|
||||
RETURN vHasComponentLack;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,25 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`ticket_isTooLittle`(
|
||||
vSelf INT
|
||||
)
|
||||
RETURNS tinyint(1)
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
/**
|
||||
* Check if the ticket is small based on the volume and amount parameters.
|
||||
*
|
||||
* @param vSelf Id ticket
|
||||
* @return BOOL
|
||||
*/
|
||||
DECLARE vIsTooLittle TINYINT(1);
|
||||
|
||||
SELECT (SUM(IFNULL(sv.litros, 0)) < vc.minTicketVolume
|
||||
OR IFNULL(t.totalWithoutVat, 0) < vc.minTicketValue) INTO vIsTooLittle
|
||||
FROM ticket t
|
||||
LEFT JOIN saleVolume sv ON sv.ticketFk = t.id
|
||||
JOIN volumeConfig vc
|
||||
WHERE t.id = vSelf;
|
||||
|
||||
RETURN vIsTooLittle;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,5 +1,6 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`xdiario_new`(vAsiento INT,
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`xdiario_new`(
|
||||
vBookNumber INT,
|
||||
vDated DATE,
|
||||
vSubaccount VARCHAR(12),
|
||||
vAccount VARCHAR(12),
|
||||
|
@ -12,33 +13,33 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`xdiario_new`(vAsient
|
|||
vVat DOUBLE,
|
||||
vRe DOUBLE,
|
||||
vAux TINYINT,
|
||||
vCompany INT
|
||||
vCompanyFk INT
|
||||
)
|
||||
RETURNS int(11)
|
||||
NOT DETERMINISTIC
|
||||
NO SQL
|
||||
BEGIN
|
||||
IF vAsiento IS NULL THEN
|
||||
CALL vn.ledger_next(vAsiento);
|
||||
IF vBookNumber IS NULL THEN
|
||||
CALL ledger_next(YEAR(vDated), vBookNumber);
|
||||
END IF;
|
||||
|
||||
INSERT INTO XDiario
|
||||
SET ASIEN = vAsiento,
|
||||
FECHA = vDated,
|
||||
SUBCTA = vSubaccount,
|
||||
CONTRA = vAccount,
|
||||
CONCEPTO = vConcept,
|
||||
EURODEBE = vDebit,
|
||||
EUROHABER = vCredit,
|
||||
BASEEURO = vEuro,
|
||||
SERIE = vSerie,
|
||||
FACTURA = vInvoice,
|
||||
IVA = vVat,
|
||||
RECEQUIV = vRe,
|
||||
AUXILIAR = IF(vAux = FALSE, NULL, '*'),
|
||||
MONEDAUSO = 2,
|
||||
empresa_id = vCompany;
|
||||
SET ASIEN = vBookNumber,
|
||||
FECHA = vDated,
|
||||
SUBCTA = vSubaccount,
|
||||
CONTRA = vAccount,
|
||||
CONCEPTO = vConcept,
|
||||
EURODEBE = vDebit,
|
||||
EUROHABER = vCredit,
|
||||
BASEEURO = vEuro,
|
||||
SERIE = vSerie,
|
||||
FACTURA = vInvoice,
|
||||
IVA = vVat,
|
||||
RECEQUIV = vRe,
|
||||
AUXILIAR = IF(vAux = FALSE, NULL, '*'),
|
||||
MONEDAUSO = 2,
|
||||
empresa_id = vCompanyFk;
|
||||
|
||||
RETURN vAsiento;
|
||||
RETURN vBookNumber;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
DELIMITER ;
|
|
@ -9,7 +9,7 @@ BEGIN
|
|||
DECLARE vEnded DATETIME DEFAULT util.dayEnd(util.VN_CURDATE());
|
||||
|
||||
SELECT ag.id agency_id,
|
||||
CONCAT(RPAD(c.country, 16,' _') ,' ',ag.name) Agencia,
|
||||
CONCAT(RPAD(c.name, 16,' _') ,' ',ag.name) Agencia,
|
||||
COUNT(*) expediciones,
|
||||
SUM(t.packages) Bultos,
|
||||
SUM(tpe.boxes) Faltan
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`buy_clone`(vEntryFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Clone buys to an entry
|
||||
*
|
||||
* @param vEntryFk The entry id
|
||||
* @table tmp.buy(id)
|
||||
*/
|
||||
INSERT INTO buy(
|
||||
entryFk,
|
||||
itemFk,
|
||||
quantity,
|
||||
buyingValue,
|
||||
freightValue,
|
||||
isIgnored,
|
||||
stickers,
|
||||
packagingFk,
|
||||
packing,
|
||||
`grouping`,
|
||||
groupingMode,
|
||||
comissionValue,
|
||||
packageValue,
|
||||
price1,
|
||||
price2,
|
||||
price3,
|
||||
minPrice,
|
||||
isChecked,
|
||||
location,
|
||||
weight,
|
||||
itemOriginalFk)
|
||||
SELECT vEntryFk,
|
||||
b.itemFk,
|
||||
b.quantity,
|
||||
b.buyingValue,
|
||||
b.freightValue,
|
||||
b.isIgnored,
|
||||
b.stickers,
|
||||
b.packagingFk,
|
||||
b.packing,
|
||||
b.`grouping`,
|
||||
b.groupingMode,
|
||||
b.comissionValue,
|
||||
b.packageValue,
|
||||
b.price1,
|
||||
b.price2,
|
||||
b.price3,
|
||||
b.minPrice,
|
||||
b.isChecked,
|
||||
b.location,
|
||||
b.weight,
|
||||
b.itemOriginalFk
|
||||
FROM tmp.buy tb
|
||||
JOIN vn.buy b ON b.id = tb.id;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -10,7 +10,7 @@ BEGIN
|
|||
*/
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc;
|
||||
|
||||
CREATE TEMPORARY TABLE tmp.buyRecalc
|
||||
CREATE TEMPORARY TABLE tmp.buyRecalc
|
||||
SELECT vBuyFk id;
|
||||
|
||||
CALL buy_recalcPrices();
|
||||
|
|
|
@ -86,7 +86,7 @@ BEGIN
|
|||
WHERE cs.description = 'Anulado'
|
||||
AND c.created < v2Months;
|
||||
|
||||
DELETE FROM expeditionTruck WHERE eta < v3Months;
|
||||
DELETE FROM roadmapStop WHERE eta < v3Months;
|
||||
DELETE FROM XDiario WHERE FECHA < v3Months OR FECHA IS NULL;
|
||||
|
||||
-- Borrar travels sin entradas
|
||||
|
|
|
@ -22,7 +22,7 @@ BEGIN
|
|||
c.credit,
|
||||
CAST(r.risk AS DECIMAL (10,2)) risk,
|
||||
CAST(c.credit - r.risk AS DECIMAL (10,2)) difference,
|
||||
co.country
|
||||
co.name country
|
||||
FROM client c
|
||||
JOIN tmp.risk r ON r.clientFk = c.id
|
||||
JOIN country co ON co.id = c.countryFk
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_userDisable`()
|
||||
BEGIN
|
||||
/**
|
||||
* Desactiva los clientes inactivos en los últimos X meses.
|
||||
*/
|
||||
DECLARE vMonths INT;
|
||||
|
||||
SELECT monthsToDisableUser INTO vMonths
|
||||
FROM clientConfig;
|
||||
|
||||
IF vMonths IS NULL THEN
|
||||
CALL util.throw('Config parameter not set');
|
||||
END IF;
|
||||
|
||||
UPDATE account.user u
|
||||
JOIN client c ON c.id = u.id
|
||||
LEFT JOIN account.account a ON a.id = u.id
|
||||
SET u.active = FALSE
|
||||
WHERE c.typeFk = 'normal'
|
||||
AND a.id IS NULL
|
||||
AND u.active
|
||||
AND c.created < util.VN_CURDATE() - INTERVAL vMonths MONTH
|
||||
AND u.id NOT IN (
|
||||
SELECT DISTINCT c.id
|
||||
FROM client c
|
||||
LEFT JOIN ticket t ON t.clientFk = c.id
|
||||
WHERE c.salesPersonFk IS NOT NULL
|
||||
OR t.created > util.VN_CURDATE() - INTERVAL vMonths MONTH
|
||||
OR shipped > util.VN_CURDATE() - INTERVAL vMonths MONTH
|
||||
);
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -188,11 +188,12 @@ BEGIN
|
|||
FROM tPendingDuedates vp
|
||||
LEFT JOIN supplier s ON s.id = vp.supplierFk
|
||||
LEFT JOIN client c ON c.fi = s.nif
|
||||
LEFT JOIN clientRisk cr ON cr.clientFk = c.id
|
||||
LEFT JOIN clientRisk cr ON cr.clientFk = c.id
|
||||
AND cr.companyFk = vp.companyFk
|
||||
LEFT JOIN supplierAccount sa ON sa.supplierFk = s.id
|
||||
LEFT JOIN bankEntity be ON be.id = sa.bankEntityFk
|
||||
LEFT JOIN country co ON co.id = be.countryFk;
|
||||
LEFT JOIN country co ON co.id = be.countryFk
|
||||
GROUP BY vp.id;
|
||||
|
||||
DROP TEMPORARY TABLE tOpeningBalances;
|
||||
DROP TEMPORARY TABLE tPendingDuedates;
|
||||
|
|
|
@ -24,7 +24,7 @@ BEGIN
|
|||
10 * p.height as height,
|
||||
IFNULL(t.routeFk,am.agencyFk) routeFk,
|
||||
hour(e.created) * 60 + minute(e.created),
|
||||
IFNULL(et.description , a.name),
|
||||
IFNULL(rs.description , a.name),
|
||||
IFNULL(t.routeFk,am.agencyFk) criterion,
|
||||
IFNULL(p.conveyorBuildingClassFk , pc.defaultConveyorBuildingClass)
|
||||
FROM vn.expedition e
|
||||
|
@ -34,7 +34,7 @@ BEGIN
|
|||
LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk
|
||||
LEFT JOIN vn.agency a ON a.id = am.agencyFk
|
||||
LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk
|
||||
LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk
|
||||
LEFT JOIN vn.roadmapStop rs ON rs.id = rm.expeditionTruckFk
|
||||
JOIN vn.packagingConfig pc
|
||||
WHERE t.warehouseFk IN (60,1,44)
|
||||
AND e.created BETWEEN vStarted AND vEnded
|
||||
|
|
|
@ -27,7 +27,7 @@ BEGIN
|
|||
cac.invoiced billedAnnually,
|
||||
c.dueDay,
|
||||
cgd.grade,
|
||||
c2.country
|
||||
c2.name country
|
||||
FROM tmp.clientGetDebt cgd
|
||||
LEFT JOIN tmp.risk r ON r.clientFk = cgd.clientFk
|
||||
JOIN client c ON c.id = cgd.clientFk
|
||||
|
|
|
@ -2,127 +2,121 @@ DELIMITER $$
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`duaTaxBooking`(vDuaFk INT)
|
||||
BEGIN
|
||||
DECLARE vBookNumber INT;
|
||||
DECLARE vBookDated DATE;
|
||||
DECLARE vDiff DECIMAL(10,2);
|
||||
DECLARE vApunte BIGINT;
|
||||
|
||||
SELECT ASIEN, IFNULL(bookEntried, util.VN_CURDATE()) INTO vBookNumber, vBookDated
|
||||
FROM dua
|
||||
DECLARE vBookDated DATE;
|
||||
DECLARE vDiff DECIMAL(10,2);
|
||||
DECLARE vApunte BIGINT;
|
||||
|
||||
SELECT ASIEN, IFNULL(bookEntried, util.VN_CURDATE())
|
||||
INTO vBookNumber, vBookDated
|
||||
FROM dua
|
||||
WHERE id = vDuaFk;
|
||||
|
||||
|
||||
IF vBookNumber IS NULL OR NOT vBookNumber THEN
|
||||
CALL ledger_next(vBookNumber);
|
||||
CALL ledger_next(YEAR(vBookDated), vBookNumber);
|
||||
END IF;
|
||||
|
||||
-- Apunte de la aduana
|
||||
|
||||
INSERT INTO XDiario(
|
||||
ASIEN,
|
||||
FECHA,
|
||||
SUBCTA,
|
||||
CONCEPTO,
|
||||
EUROHABER,
|
||||
SERIE,
|
||||
empresa_id,
|
||||
CLAVE,
|
||||
FACTURA)
|
||||
ASIEN,
|
||||
FECHA,
|
||||
SUBCTA,
|
||||
CONCEPTO,
|
||||
EUROHABER,
|
||||
SERIE,
|
||||
empresa_id,
|
||||
CLAVE,
|
||||
FACTURA)
|
||||
SELECT vBookNumber,
|
||||
d.bookEntried,
|
||||
'4700000999',
|
||||
CONCAT('DUA ',d.`code`),
|
||||
sum(dt.base * dt.rate / 100) EUROHABER,
|
||||
'R',
|
||||
d.companyFk,
|
||||
vDuaFk,
|
||||
vDuaFk
|
||||
FROM duaTax dt
|
||||
JOIN dua d ON d.id = dt.duaFk
|
||||
WHERE dt.duaFk = vDuaFk;
|
||||
|
||||
SELECT
|
||||
vBookNumber,
|
||||
d.bookEntried,
|
||||
'4700000999',
|
||||
CONCAT('DUA ',d.`code`),
|
||||
sum(dt.base * dt.rate / 100) EUROHABER,
|
||||
'R',
|
||||
d.companyFk,
|
||||
vDuaFk,
|
||||
vDuaFk
|
||||
FROM duaTax dt
|
||||
JOIN dua d ON d.id = dt.duaFk
|
||||
WHERE dt.duaFk = vDuaFk;
|
||||
|
||||
-- Apuntes por tipo de IVA y proveedor
|
||||
|
||||
INSERT INTO XDiario(
|
||||
ASIEN,
|
||||
FECHA,
|
||||
SUBCTA,
|
||||
CONTRA,
|
||||
EURODEBE,
|
||||
BASEEURO,
|
||||
CONCEPTO,
|
||||
FACTURA,
|
||||
IVA,
|
||||
AUXILIAR,
|
||||
SERIE,
|
||||
FECHA_EX,
|
||||
FECHA_OP,
|
||||
FACTURAEX,
|
||||
NFACTICK,
|
||||
L340,
|
||||
LDIFADUAN,
|
||||
TIPOCLAVE,
|
||||
TIPOEXENCI,
|
||||
TIPONOSUJE,
|
||||
TIPOFACT,
|
||||
TIPORECTIF,
|
||||
TERIDNIF,
|
||||
TERNIF,
|
||||
TERNOM,
|
||||
empresa_id,
|
||||
FECREGCON
|
||||
)
|
||||
|
||||
SELECT
|
||||
vBookNumber ASIEN,
|
||||
vBookDated FECHA,
|
||||
tr.account SUBCTA,
|
||||
'4330002067' CONTRA,
|
||||
sum(dt.tax) EURODEBE,
|
||||
sum(dt.base) BASEEURO,
|
||||
CONCAT('DUA nº',d.code) CONCEPTO,
|
||||
d.id FACTURA,
|
||||
dt.rate IVA,
|
||||
'*' AUXILIAR,
|
||||
'D' SERIE,
|
||||
d.issued FECHA_EX,
|
||||
d.operated FECHA_OP,
|
||||
d.code FACTURAEX,
|
||||
1 NFACTICK,
|
||||
1 L340,
|
||||
TRUE LDIFADUAN,
|
||||
1 TIPOCLAVE,
|
||||
1 TIPOEXENCI,
|
||||
1 TIPONOSUJE,
|
||||
5 TIPOFACT,
|
||||
1 TIPORECTIF,
|
||||
IF(c.code = 'ES', 1, 4) TERIDNIF,
|
||||
s.nif TERNIF,
|
||||
s.name TERNOM,
|
||||
d.companyFk,
|
||||
d.booked FECREGCON
|
||||
FROM duaTax dt
|
||||
JOIN dua d ON dt.duaFk = d.id
|
||||
JOIN (SELECT account, rate
|
||||
FROM
|
||||
(SELECT rate, account
|
||||
FROM invoiceInTaxBookingAccount ta
|
||||
WHERE ta.effectived <= vBookDated
|
||||
AND taxAreaFk = 'WORLD'
|
||||
ORDER BY ta.effectived DESC
|
||||
LIMIT 10000000000000000000
|
||||
) tba
|
||||
GROUP BY rate
|
||||
-- Apuntes por tipo de IVA y proveedor
|
||||
INSERT INTO XDiario(
|
||||
ASIEN,
|
||||
FECHA,
|
||||
SUBCTA,
|
||||
CONTRA,
|
||||
EURODEBE,
|
||||
BASEEURO,
|
||||
CONCEPTO,
|
||||
FACTURA,
|
||||
IVA,
|
||||
AUXILIAR,
|
||||
SERIE,
|
||||
FECHA_EX,
|
||||
FECHA_OP,
|
||||
FACTURAEX,
|
||||
NFACTICK,
|
||||
L340,
|
||||
LDIFADUAN,
|
||||
TIPOCLAVE,
|
||||
TIPOEXENCI,
|
||||
TIPONOSUJE,
|
||||
TIPOFACT,
|
||||
TIPORECTIF,
|
||||
TERIDNIF,
|
||||
TERNIF,
|
||||
TERNOM,
|
||||
empresa_id,
|
||||
FECREGCON)
|
||||
SELECT vBookNumber ASIEN,
|
||||
vBookDated FECHA,
|
||||
tr.account SUBCTA,
|
||||
'4330002067' CONTRA,
|
||||
SUM(dt.tax) EURODEBE,
|
||||
SUM(dt.base) BASEEURO,
|
||||
CONCAT('DUA nº',d.code) CONCEPTO,
|
||||
d.id FACTURA,
|
||||
dt.rate IVA,
|
||||
'*' AUXILIAR,
|
||||
'D' SERIE,
|
||||
d.issued FECHA_EX,
|
||||
d.operated FECHA_OP,
|
||||
d.code FACTURAEX,
|
||||
1 NFACTICK,
|
||||
1 L340,
|
||||
TRUE LDIFADUAN,
|
||||
1 TIPOCLAVE,
|
||||
1 TIPOEXENCI,
|
||||
1 TIPONOSUJE,
|
||||
5 TIPOFACT,
|
||||
1 TIPORECTIF,
|
||||
IF(c.code = 'ES', 1, 4) TERIDNIF,
|
||||
s.nif TERNIF,
|
||||
s.name TERNOM,
|
||||
d.companyFk,
|
||||
d.booked FECREGCON
|
||||
FROM duaTax dt
|
||||
JOIN dua d ON dt.duaFk = d.id
|
||||
JOIN (SELECT account, rate
|
||||
FROM
|
||||
(SELECT rate, account
|
||||
FROM invoiceInTaxBookingAccount ta
|
||||
WHERE ta.effectived <= vBookDated
|
||||
AND taxAreaFk = 'WORLD'
|
||||
ORDER BY ta.effectived DESC
|
||||
LIMIT 10000000000000000000
|
||||
) tba
|
||||
GROUP BY rate
|
||||
) tr ON tr.rate = dt.rate
|
||||
JOIN supplier s ON s.id = d.companyFk
|
||||
JOIN country c ON c.id = s.countryFk
|
||||
WHERE d.id = vDuaFk
|
||||
GROUP BY dt.rate;
|
||||
JOIN supplier s ON s.id = d.companyFk
|
||||
JOIN country c ON c.id = s.countryFk
|
||||
WHERE d.id = vDuaFk
|
||||
GROUP BY dt.rate;
|
||||
|
||||
SELECT SUM(EURODEBE) -SUM(EUROHABER), MAX(id) INTO vDiff, vApunte
|
||||
FROM XDiario
|
||||
WHERE ASIEN = vBookNumber;
|
||||
|
||||
|
||||
UPDATE XDiario
|
||||
SET BASEEURO = 100 * (EURODEBE - vDiff) / IVA,
|
||||
EURODEBE = EURODEBE - vDiff
|
||||
|
@ -131,6 +125,5 @@ BEGIN
|
|||
UPDATE dua
|
||||
SET ASIEN = vBookNumber
|
||||
WHERE id = vDuaFk;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -9,8 +9,8 @@ BEGIN
|
|||
* Clones an entry header.
|
||||
*
|
||||
* @param vSelf The entry id
|
||||
* @param OUT vNewEntryFk The new entry id
|
||||
* @param vTravelFk Travel for the new entry or %NULL to use the source entry travel
|
||||
* @param vNewEntryFk The new entry id
|
||||
*/
|
||||
INSERT INTO entry(
|
||||
travelFk,
|
||||
|
|
|
@ -1,59 +1,18 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_copyBuys`(vSelf INT, vCopyTo INT)
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_copyBuys`(vSelf INT, vDestinationEntryFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Copies an entry buys to another buy.
|
||||
* Copies all buys from an entry to an entry.
|
||||
*
|
||||
* @param vSelf The entry id
|
||||
* @param vCopyTo The destination entry id
|
||||
* @param vDestinationEntryFk The destination entry id
|
||||
*/
|
||||
INSERT INTO buy(
|
||||
entryFk,
|
||||
itemFk,
|
||||
quantity,
|
||||
buyingValue,
|
||||
freightValue,
|
||||
isIgnored,
|
||||
stickers,
|
||||
packing,
|
||||
`grouping`,
|
||||
groupingMode,
|
||||
containerFk,
|
||||
comissionValue,
|
||||
packageValue,
|
||||
packagingFk,
|
||||
price1,
|
||||
price2,
|
||||
price3,
|
||||
minPrice,
|
||||
isChecked,
|
||||
location,
|
||||
weight,
|
||||
itemOriginalFk
|
||||
)
|
||||
SELECT vCopyTo,
|
||||
itemFk,
|
||||
quantity,
|
||||
buyingValue,
|
||||
freightValue,
|
||||
isIgnored,
|
||||
stickers,
|
||||
packing,
|
||||
`grouping`,
|
||||
groupingMode,
|
||||
containerFk,
|
||||
comissionValue,
|
||||
packageValue,
|
||||
packagingFk,
|
||||
price1,
|
||||
price2,
|
||||
price3,
|
||||
minPrice,
|
||||
isChecked,
|
||||
location,
|
||||
weight,
|
||||
itemOriginalFk
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.buy
|
||||
SELECT id
|
||||
FROM buy
|
||||
WHERE entryFk = vSelf;
|
||||
|
||||
CALL buy_clone(vDestinationEntryFk);
|
||||
DROP TEMPORARY TABLE tmp.buy;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -26,7 +26,6 @@ BEGIN
|
|||
packing,
|
||||
`grouping`,
|
||||
groupingMode,
|
||||
containerFk,
|
||||
comissionValue,
|
||||
packageValue,
|
||||
location,
|
||||
|
@ -46,7 +45,6 @@ BEGIN
|
|||
packing,
|
||||
`grouping`,
|
||||
groupingMode,
|
||||
containerFk,
|
||||
comissionValue,
|
||||
packageValue,
|
||||
location,
|
||||
|
|
|
@ -56,7 +56,6 @@ BEGIN
|
|||
packing,
|
||||
`grouping`,
|
||||
groupingMode,
|
||||
containerFk,
|
||||
comissionValue,
|
||||
packageValue,
|
||||
packagingFk,
|
||||
|
@ -77,7 +76,6 @@ BEGIN
|
|||
packing,
|
||||
`grouping`,
|
||||
groupingMode,
|
||||
containerFk,
|
||||
comissionValue,
|
||||
packageValue,
|
||||
packagingFk,
|
||||
|
@ -114,7 +112,6 @@ BEGIN
|
|||
packing,
|
||||
`grouping`,
|
||||
groupingMode,
|
||||
containerFk,
|
||||
comissionValue,
|
||||
packageValue,
|
||||
location,
|
||||
|
@ -133,7 +130,6 @@ BEGIN
|
|||
packing,
|
||||
`grouping`,
|
||||
groupingMode,
|
||||
containerFk,
|
||||
comissionValue,
|
||||
packageValue,
|
||||
location,
|
||||
|
|
|
@ -76,7 +76,6 @@ BEGIN
|
|||
packing,
|
||||
`grouping`,
|
||||
groupingMode,
|
||||
containerFk,
|
||||
comissionValue,
|
||||
packageValue,
|
||||
location,
|
||||
|
@ -103,7 +102,6 @@ BEGIN
|
|||
packing,
|
||||
`grouping`,
|
||||
groupingMode,
|
||||
containerFk,
|
||||
comissionValue,
|
||||
packageValue,
|
||||
location,
|
||||
|
|
|
@ -2,7 +2,7 @@ DELIMITER $$
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`expeditionTruck_Add`(vHour VARCHAR(5), vDescription VARCHAR(45))
|
||||
BEGIN
|
||||
|
||||
INSERT INTO vn.expeditionTruck(eta,description)
|
||||
INSERT INTO vn.roadmapStop(eta,description)
|
||||
VALUES(CONCAT(util.VN_CURDATE(), ' ', vHour), vDescription);
|
||||
|
||||
END$$
|
||||
|
|
|
@ -4,9 +4,9 @@ BEGIN
|
|||
|
||||
SELECT id truckFk,
|
||||
eta,
|
||||
description Destino
|
||||
FROM expeditionTruck
|
||||
WHERE eta BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE())
|
||||
ORDER BY eta;
|
||||
description Destino
|
||||
FROM roadmapStop
|
||||
WHERE eta BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE())
|
||||
ORDER BY eta;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -53,8 +53,8 @@ BEGIN
|
|||
am.name zonaRuta,
|
||||
t.routeFk ruta,
|
||||
rm.beachFk ubicacion,
|
||||
et.eta ,
|
||||
et.description camion,
|
||||
rs.eta ,
|
||||
rs.description camion,
|
||||
vTicketsPendientes AS ticketsPendientes,
|
||||
vEtiquetasTotales AS etiquetasTotales,
|
||||
vEtiquetasEscaneadas AS etiquetasEscaneadas,
|
||||
|
@ -67,7 +67,7 @@ BEGIN
|
|||
LEFT JOIN vn.route r ON r.id = t.routeFk
|
||||
LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk
|
||||
LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id
|
||||
LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk
|
||||
LEFT JOIN vn.roadmapStop rs ON rs.id = rm.expeditionTruckFk
|
||||
WHERE e.id = vExpeditionFk;
|
||||
|
||||
END$$
|
||||
|
|
|
@ -37,8 +37,8 @@ BEGIN
|
|||
am.name zonaRuta,
|
||||
t.routeFk ruta,
|
||||
rm.beachFk ubicacion,
|
||||
et.eta ,
|
||||
et.description camion,
|
||||
rs.eta ,
|
||||
rs.description camion,
|
||||
vTicketsPendientes AS ticketsPendientes,
|
||||
vEtiquetasTotales AS etiquetasTotales,
|
||||
vEtiquetasEscaneadas AS etiquetasEscaneadas
|
||||
|
@ -50,7 +50,7 @@ BEGIN
|
|||
LEFT JOIN vn.route r ON r.id = t.routeFk
|
||||
LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk
|
||||
LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id
|
||||
LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk
|
||||
LEFT JOIN vn.roadmapStop rs ON rs.id = rm.expeditionTruckFk
|
||||
WHERE e.id = vExpeditionFk;
|
||||
|
||||
END$$
|
||||
|
|
|
@ -1,101 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`fv_pca`()
|
||||
BEGIN
|
||||
|
||||
DECLARE done INT DEFAULT FALSE;
|
||||
|
||||
DECLARE vTicketFk INT;
|
||||
DECLARE vSaleFk INT;
|
||||
DECLARE vClonTicket INT DEFAULT 0;
|
||||
|
||||
DECLARE cur1 CURSOR FOR
|
||||
SELECT s.ticketFk, s.id
|
||||
FROM vn.sale s
|
||||
JOIN vn.ticket t ON t.id = s.ticketFk
|
||||
JOIN vn.item i ON i.id = s.itemFk
|
||||
JOIN vn.itemType it ON it.id = i.typeFk
|
||||
WHERE t.shipped BETWEEN '2020-10-18' AND '2020-10-31'
|
||||
AND it.code IN ('ANT','ANS','ORQ','TRO')
|
||||
and t.warehouseFk = 1;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
|
||||
|
||||
OPEN cur1;
|
||||
|
||||
FETCH cur1 INTO vTicketFk, vSaleFk;
|
||||
|
||||
WHILE done = 0 DO
|
||||
|
||||
SELECT t.id INTO vClonTicket
|
||||
FROM vn.ticket t
|
||||
JOIN (SELECT addressFk, shipped FROM vn.ticket WHERE id = vTicketFk) sub USING(addressFk, shipped)
|
||||
WHERE t.warehouseFk = 44
|
||||
LIMIT 1;
|
||||
|
||||
SELECT vTicketFk, vClonTicket;
|
||||
|
||||
IF vClonTicket = 0 THEN
|
||||
|
||||
INSERT INTO ticket (
|
||||
clientFk,
|
||||
shipped,
|
||||
addressFk,
|
||||
agencyModeFk,
|
||||
nickname,
|
||||
warehouseFk,
|
||||
companyFk,
|
||||
landed,
|
||||
zoneFk,
|
||||
zonePrice,
|
||||
zoneBonus,
|
||||
routeFk
|
||||
)
|
||||
SELECT
|
||||
clientFk,
|
||||
shipped,
|
||||
addressFk,
|
||||
agencyModeFk,
|
||||
nickname,
|
||||
44,
|
||||
companyFk,
|
||||
landed,
|
||||
zoneFk,
|
||||
zonePrice,
|
||||
zoneBonus,
|
||||
routeFk
|
||||
|
||||
FROM ticket
|
||||
WHERE id = vTicketFk;
|
||||
|
||||
SET vClonTicket = LAST_INSERT_ID();
|
||||
|
||||
SELECT 'lstID', vClonTicket;
|
||||
/*
|
||||
INSERT INTO ticketObservation(ticketFk, observationTypeFk, description)
|
||||
SELECT vTicketFk, ao.observationTypeFk, ao.description
|
||||
FROM addressObservation ao
|
||||
JOIN ticket t ON t.addressFk = ao.addressFk
|
||||
WHERE t.id = vClonTicket;
|
||||
*/
|
||||
INSERT INTO ticketLog
|
||||
SET originFk = vTicketFk, userFk = account.myUser_getId(), `action` = 'insert',
|
||||
description = CONCAT('Ha creado el ticket:', ' ', vClonTicket, ' clonando el ', vTicketFk);
|
||||
|
||||
END IF;
|
||||
|
||||
UPDATE vn.sale
|
||||
SET ticketFk = vClonTicket
|
||||
WHERE id = vSaleFk;
|
||||
|
||||
SET vClonTicket = 0;
|
||||
|
||||
SET done = 0;
|
||||
FETCH cur1 INTO vTicketFk, vSaleFk;
|
||||
|
||||
END WHILE;
|
||||
|
||||
CLOSE cur1;
|
||||
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -2,6 +2,7 @@ DELIMITER $$
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceIn_booking`(vSelf INT)
|
||||
BEGIN
|
||||
DECLARE vBookNumber INT;
|
||||
DECLARE vFiscalYear INT;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tInvoiceIn
|
||||
ENGINE = MEMORY
|
||||
|
@ -56,7 +57,8 @@ BEGIN
|
|||
LEFT JOIN sage.taxType tt ON tt.id = ti.CodigoIva
|
||||
WHERE ii.id = vSelf;
|
||||
|
||||
CALL vn.ledger_next(vBookNumber);
|
||||
SELECT YEAR(bookEntried) INTO vFiscalYear FROM tInvoiceIn LIMIT 1;
|
||||
CALL ledger_next(vFiscalYear, vBookNumber);
|
||||
|
||||
-- Apunte del proveedor
|
||||
INSERT INTO XDiario(
|
||||
|
|
|
@ -1,22 +1,24 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceOutBooking`(IN vInvoice INT)
|
||||
BEGIN
|
||||
/* Asienta la factura emitida
|
||||
*
|
||||
* param vInvoice factura_id
|
||||
*/
|
||||
/**
|
||||
* Asienta una factura emitida
|
||||
*
|
||||
* @param vInvoice Id invoiceOut
|
||||
*/
|
||||
DECLARE vBookNumber INT;
|
||||
DECLARE vExpenseConcept VARCHAR(50);
|
||||
DECLARE vSpainCountryFk INT;
|
||||
DECLARE vOldBookNumber INT;
|
||||
DECLARE vExpenseConcept VARCHAR(50);
|
||||
DECLARE vSpainCountryFk INT;
|
||||
DECLARE vOldBookNumber INT;
|
||||
DECLARE vFiscalYear INT;
|
||||
|
||||
SELECT id INTO vSpainCountryFk FROM country WHERE code = 'ES';
|
||||
SELECT id INTO vSpainCountryFk FROM country WHERE `code` = 'ES';
|
||||
|
||||
SELECT ASIEN
|
||||
SELECT ASIEN
|
||||
INTO vOldBookNumber
|
||||
FROM XDiario x
|
||||
JOIN invoiceOut io ON io.id = vInvoice
|
||||
WHERE x.SERIE = io.serial
|
||||
WHERE x.SERIE = io.serial
|
||||
AND x.FACTURA = RIGHT(io.ref, LENGTH(io.ref) - 1)
|
||||
LIMIT 1;
|
||||
|
||||
|
@ -26,140 +28,133 @@ BEGIN
|
|||
|
||||
DROP TEMPORARY TABLE IF EXISTS rs;
|
||||
CREATE TEMPORARY TABLE rs
|
||||
SELECT
|
||||
c.accountingAccount AS clientBookingAccount,
|
||||
io.amount as totalAmount,
|
||||
CONCAT('n/fra ', io.ref) as simpleConcept,
|
||||
CONCAT('n/fra ', io.ref, ' ', c.name) as Concept,
|
||||
io.serial AS SERIE,
|
||||
io.issued AS FECHA_EX,
|
||||
io.issued AS FECHA_OP,
|
||||
io.issued AS FECHA,
|
||||
1 AS NFACTICK,
|
||||
IF(ic.correctingFk,'D','') AS TIPOOPE,
|
||||
io.siiTrascendencyInvoiceOutFk AS TIPOCLAVE,
|
||||
io.cplusTaxBreakFk AS TIPOEXENCI,
|
||||
io.cplusSubjectOpFk AS TIPONOSUJE,
|
||||
io.siiTypeInvoiceOutFk AS TIPOFACT,
|
||||
ic.cplusRectificationTypeFk AS TIPORECTIF,
|
||||
SELECT c.accountingAccount clientBookingAccount,
|
||||
io.amount totalAmount,
|
||||
CONCAT('n/fra ', io.ref) simpleConcept,
|
||||
CONCAT('n/fra ', io.ref, ' ', c.name) Concept,
|
||||
io.serial SERIE,
|
||||
io.issued FECHA_EX,
|
||||
io.issued FECHA_OP,
|
||||
io.issued FECHA,
|
||||
1 NFACTICK,
|
||||
IF(ic.correctingFk,'D','') TIPOOPE,
|
||||
io.siiTrascendencyInvoiceOutFk TIPOCLAVE,
|
||||
io.cplusTaxBreakFk TIPOEXENCI,
|
||||
io.cplusSubjectOpFk TIPONOSUJE,
|
||||
io.siiTypeInvoiceOutFk TIPOFACT,
|
||||
ic.cplusRectificationTypeFk TIPORECTIF,
|
||||
io.companyFk,
|
||||
RIGHT(io.ref, LENGTH(io.ref) - 1) AS invoiceNum,
|
||||
IF(c.countryFk = vSpainCountryFk, vSpainCountryFk, IF(ct.isUeeMember,2,4)) AS TERIDNIF,
|
||||
CONCAT(IF(ct.isUeeMember AND c.countryFk <> vSpainCountryFk,ct.code,''),c.fi) AS TERNIF,
|
||||
c.socialName AS TERNOM,
|
||||
ior.serial AS SERIE_RT,
|
||||
RIGHT(ior.ref, LENGTH(ior.ref) - 1) AS FACTU_RT,
|
||||
ior.issued AS FECHA_RT,
|
||||
IF(ior.id,TRUE,FALSE) AS RECTIFICA
|
||||
RIGHT(io.ref, LENGTH(io.ref) - 1) invoiceNum,
|
||||
IF(c.countryFk = vSpainCountryFk, vSpainCountryFk, IF(ct.isUeeMember,2,4)) TERIDNIF,
|
||||
CONCAT(IF(ct.isUeeMember AND c.countryFk <> vSpainCountryFk,ct.code,''),c.fi) TERNIF,
|
||||
c.socialName TERNOM,
|
||||
ior.serial SERIE_RT,
|
||||
RIGHT(ior.ref, LENGTH(ior.ref) - 1) FACTU_RT,
|
||||
ior.issued FECHA_RT,
|
||||
IF(ior.id,TRUE,FALSE) RECTIFICA
|
||||
FROM invoiceOut io
|
||||
JOIN invoiceOutSerial ios ON ios.code = io.serial
|
||||
JOIN client c ON c.id = io.clientFk
|
||||
JOIN country ct ON ct.id = c.countryFk
|
||||
LEFT JOIN invoiceCorrection ic ON ic.correctingFk = io.id
|
||||
LEFT JOIN invoiceOut ior ON ior.id = ic.correctedFk
|
||||
LEFT JOIN invoiceOut ior ON ior.id = ic.correctedFk
|
||||
WHERE io.id = vInvoice;
|
||||
|
||||
CALL vn.ledger_next(vBookNumber);
|
||||
|
||||
SELECT YEAR(FECHA) INTO vFiscalYear FROM rs LIMIT 1;
|
||||
CALL ledger_next(vFiscalYear, vBookNumber);
|
||||
-- Linea del cliente
|
||||
INSERT INTO XDiario(
|
||||
ASIEN,
|
||||
FECHA,
|
||||
SUBCTA,
|
||||
EURODEBE,
|
||||
CONCEPTO,
|
||||
FECHA_EX,
|
||||
FECHA_OP,
|
||||
empresa_id
|
||||
)
|
||||
SELECT
|
||||
vBookNumber AS ASIEN,
|
||||
ASIEN,
|
||||
FECHA,
|
||||
SUBCTA,
|
||||
EURODEBE,
|
||||
CONCEPTO,
|
||||
FECHA_EX,
|
||||
FECHA_OP,
|
||||
empresa_id)
|
||||
SELECT vBookNumber,
|
||||
rs.FECHA,
|
||||
rs.clientBookingAccount AS SUBCTA,
|
||||
rs.totalAmount AS EURODEBE,
|
||||
rs.simpleConcept AS CONCEPTO,
|
||||
rs.clientBookingAccount,
|
||||
rs.totalAmount,
|
||||
rs.simpleConcept,
|
||||
rs.FECHA_EX,
|
||||
rs.FECHA_OP,
|
||||
rs.companyFk AS empresa_id
|
||||
rs.companyFk
|
||||
FROM rs;
|
||||
|
||||
-- Lineas de gasto
|
||||
INSERT INTO XDiario(
|
||||
ASIEN,
|
||||
FECHA,
|
||||
SUBCTA,
|
||||
CONTRA,
|
||||
EUROHABER,
|
||||
CONCEPTO,
|
||||
FECHA_EX,
|
||||
FECHA_OP,
|
||||
empresa_id
|
||||
)
|
||||
SELECT
|
||||
vBookNumber AS ASIEN,
|
||||
rs.FECHA,
|
||||
ioe.expenseFk AS SUBCTA,
|
||||
rs.clientBookingAccount AS CONTRA,
|
||||
ioe.amount AS EUROHABER,
|
||||
rs.Concept AS CONCEPTO,
|
||||
rs.FECHA_EX,
|
||||
rs.FECHA_OP,
|
||||
rs.companyFk AS empresa_id
|
||||
FROM rs
|
||||
JOIN invoiceOutExpense ioe
|
||||
WHERE ioe.invoiceOutFk = vInvoice;
|
||||
ASIEN,
|
||||
FECHA,
|
||||
SUBCTA,
|
||||
CONTRA,
|
||||
EUROHABER,
|
||||
CONCEPTO,
|
||||
FECHA_EX,
|
||||
FECHA_OP,
|
||||
empresa_id)
|
||||
SELECT vBookNumber,
|
||||
rs.FECHA,
|
||||
ioe.expenseFk,
|
||||
rs.clientBookingAccount,
|
||||
ioe.amount,
|
||||
rs.Concept,
|
||||
rs.FECHA_EX,
|
||||
rs.FECHA_OP,
|
||||
rs.companyFk
|
||||
FROM rs
|
||||
JOIN invoiceOutExpense ioe
|
||||
WHERE ioe.invoiceOutFk = vInvoice;
|
||||
|
||||
SELECT GROUP_CONCAT(`name` SEPARATOR ',')
|
||||
INTO vExpenseConcept
|
||||
FROM expense e
|
||||
JOIN invoiceOutExpense ioe ON ioe.expenseFk = e.id
|
||||
WHERE ioe.invoiceOutFk = vInvoice;
|
||||
SELECT GROUP_CONCAT(`name` SEPARATOR ',')
|
||||
INTO vExpenseConcept
|
||||
FROM expense e
|
||||
JOIN invoiceOutExpense ioe ON ioe.expenseFk = e.id
|
||||
WHERE ioe.invoiceOutFk = vInvoice;
|
||||
|
||||
-- Lineas de IVA
|
||||
-- Lineas de IVA
|
||||
INSERT INTO XDiario(
|
||||
ASIEN,
|
||||
FECHA,
|
||||
SUBCTA,
|
||||
CONTRA,
|
||||
EUROHABER,
|
||||
BASEEURO,
|
||||
CONCEPTO,
|
||||
FACTURA,
|
||||
IVA,
|
||||
RECEQUIV,
|
||||
AUXILIAR,
|
||||
SERIE,
|
||||
SERIE_RT,
|
||||
FACTU_RT,
|
||||
RECTIFICA,
|
||||
FECHA_RT,
|
||||
FECHA_OP,
|
||||
FECHA_EX,
|
||||
TIPOOPE,
|
||||
NFACTICK,
|
||||
TERIDNIF,
|
||||
TERNIF,
|
||||
TERNOM,
|
||||
L340,
|
||||
TIPOCLAVE,
|
||||
TIPOEXENCI,
|
||||
TIPONOSUJE,
|
||||
TIPOFACT,
|
||||
TIPORECTIF,
|
||||
empresa_id
|
||||
)
|
||||
SELECT
|
||||
vBookNumber AS ASIEN,
|
||||
ASIEN,
|
||||
FECHA,
|
||||
SUBCTA,
|
||||
CONTRA,
|
||||
EUROHABER,
|
||||
BASEEURO,
|
||||
CONCEPTO,
|
||||
FACTURA,
|
||||
IVA,
|
||||
RECEQUIV,
|
||||
AUXILIAR,
|
||||
SERIE,
|
||||
SERIE_RT,
|
||||
FACTU_RT,
|
||||
RECTIFICA,
|
||||
FECHA_RT,
|
||||
FECHA_OP,
|
||||
FECHA_EX,
|
||||
TIPOOPE,
|
||||
NFACTICK,
|
||||
TERIDNIF,
|
||||
TERNIF,
|
||||
TERNOM,
|
||||
L340,
|
||||
TIPOCLAVE,
|
||||
TIPOEXENCI,
|
||||
TIPONOSUJE,
|
||||
TIPOFACT,
|
||||
TIPORECTIF,
|
||||
empresa_id)
|
||||
SELECT vBookNumber ASIEN,
|
||||
rs.FECHA,
|
||||
iot.pgcFk AS SUBCTA,
|
||||
rs.clientBookingAccount AS CONTRA,
|
||||
iot.vat AS EUROHABER,
|
||||
iot.taxableBase AS BASEEURO,
|
||||
CONCAT(vExpenseConcept,' : ',rs.Concept) AS CONCEPTO,
|
||||
rs.invoiceNum AS FACTURA,
|
||||
IF(pe2.equFk,0,pgc.rate) AS IVA,
|
||||
IF(pe2.equFk,0,pgce.rate) AS RECEQUIV,
|
||||
IF(pgc.mod347,'','*') AS AUXILIAR,
|
||||
iot.pgcFk SUBCTA,
|
||||
rs.clientBookingAccount CONTRA,
|
||||
iot.vat EUROHABER,
|
||||
iot.taxableBase BASEEURO,
|
||||
CONCAT(vExpenseConcept,' : ',rs.Concept) CONCEPTO,
|
||||
rs.invoiceNum FACTURA,
|
||||
IF(pe2.equFk,0,pgc.rate) IVA,
|
||||
IF(pe2.equFk,0,pgce.rate) RECEQUIV,
|
||||
IF(pgc.mod347,'','*') AUXILIAR,
|
||||
rs.SERIE,
|
||||
rs.SERIE_RT,
|
||||
rs.FACTU_RT,
|
||||
|
@ -168,27 +163,27 @@ BEGIN
|
|||
rs.FECHA_OP,
|
||||
rs.FECHA_EX,
|
||||
rs.TIPOOPE,
|
||||
rs.NFACTICK,
|
||||
rs.NFACTICK,
|
||||
rs.TERIDNIF,
|
||||
rs.TERNIF,
|
||||
rs.TERNOM,
|
||||
pgc.mod340 AS L340,
|
||||
pgc.siiTrascendencyInvoiceOutFk AS TIPOCLAVE,
|
||||
pgc.cplusTaxBreakFk as TIPOEXENCI,
|
||||
pgc.mod340 L340,
|
||||
pgc.siiTrascendencyInvoiceOutFk TIPOCLAVE,
|
||||
pgc.cplusTaxBreakFk TIPOEXENCI,
|
||||
rs.TIPONOSUJE,
|
||||
rs.TIPOFACT,
|
||||
rs.TIPORECTIF,
|
||||
rs.companyFk AS empresa_id
|
||||
rs.companyFk
|
||||
FROM rs
|
||||
JOIN invoiceOutTax iot
|
||||
JOIN pgc ON pgc.code = iot.pgcFk
|
||||
LEFT JOIN pgcEqu pe ON pe.vatFk = iot.pgcFk -- --------------- Comprueba si la linea es de iva con rec.equiv. asociado
|
||||
LEFT JOIN pgc pgce ON pgce.code = pe.equFk
|
||||
LEFT JOIN pgcEqu pe2 ON pe2.equFk = iot.pgcFk -- --------------- Comprueba si la linea es de rec.equiv.
|
||||
LEFT JOIN pgcEqu pe2 ON pe2.equFk = iot.pgcFk -- --------------- Comprueba si la linea es de rec.equiv.
|
||||
WHERE iot.invoiceOutFk = vInvoice;
|
||||
|
||||
UPDATE invoiceOut
|
||||
SET booked = util.VN_CURDATE()
|
||||
WHERE id = vInvoice;
|
||||
|
||||
UPDATE invoiceOut
|
||||
SET booked = util.VN_CURDATE()
|
||||
WHERE id = vInvoice;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -18,11 +18,12 @@ BEGIN
|
|||
JOIN vn.parking p ON p.id = sh.parkingFk
|
||||
JOIN vn.sector sc ON sc.id = p.sectorFk
|
||||
JOIN vn.warehouse w ON w.id = sc.warehouseFk
|
||||
WHERE sc.id = vSectorFk
|
||||
AND ish.visible > 0
|
||||
WHERE ish.visible > 0
|
||||
AND ish.itemFk = vItemFk
|
||||
GROUP BY ish.id
|
||||
ORDER BY sh.priority DESC,
|
||||
ORDER BY
|
||||
(sc.id = vSectorFk) DESC,
|
||||
sh.priority DESC,
|
||||
ish.created,
|
||||
p.pickingOrder;
|
||||
END$$
|
||||
|
|
|
@ -2,7 +2,7 @@ DELIMITER $$
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelvingRadar`(
|
||||
vSectorFk INT
|
||||
)
|
||||
proc:BEGIN
|
||||
BEGIN
|
||||
/**
|
||||
* Calcula la información detallada respecto un sector.
|
||||
*
|
||||
|
@ -15,37 +15,24 @@ proc:BEGIN
|
|||
DECLARE vWarehouseFk INT DEFAULT 0;
|
||||
DECLARE vSonSectorFk INT;
|
||||
DECLARE vWorkerFk INT;
|
||||
|
||||
SELECT s.workerFk
|
||||
INTO vWorkerFk
|
||||
FROM vn.sector s
|
||||
|
||||
SELECT s.workerFk INTO vWorkerFk
|
||||
FROM sector s
|
||||
WHERE s.id = vSectorFk;
|
||||
|
||||
SELECT w.id, s.warehouseFk INTO vBuyerFk, vWarehouseFk
|
||||
FROM vn.worker w
|
||||
JOIN vn.sector s ON s.code = w.code
|
||||
WHERE s.id = vSectorFk;
|
||||
|
||||
SELECT s.id INTO vSectorFk
|
||||
FROM vn.sector s
|
||||
WHERE s.warehouseFk = vWarehouseFk
|
||||
AND s.isMain;
|
||||
|
||||
SELECT COUNT(*) INTO hasFatherSector
|
||||
FROM vn.sector
|
||||
FROM sector
|
||||
WHERE sonFk = vSectorFk;
|
||||
|
||||
|
||||
SELECT warehouseFk, sonFk INTO vWarehouseFk, vSonSectorFk
|
||||
FROM vn.sector
|
||||
FROM sector
|
||||
WHERE id = vSectorFk;
|
||||
|
||||
|
||||
CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk);
|
||||
CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE());
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.itemShelvingRadar;
|
||||
|
||||
|
||||
IF hasFatherSector THEN
|
||||
CREATE TEMPORARY TABLE tmp.itemShelvingRadar
|
||||
CREATE OR REPLACE TEMPORARY TABLE tItemShelvingRadar
|
||||
(PRIMARY KEY (itemFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT *
|
||||
|
@ -54,57 +41,77 @@ proc:BEGIN
|
|||
i.longName,
|
||||
i.size,
|
||||
i.subName producer,
|
||||
IFNULL(a.available,0) available,
|
||||
SUM(IF(s.sonFk = vSectorFk, IFNULL(iss.visible,0), 0)) upstairs,
|
||||
SUM(IF(iss.sectorFk = vSectorFk, IFNULL(iss.visible,0), 0)) downstairs,
|
||||
IF(it.isPackaging, NULL, IFNULL(v.visible,0)) as visible,
|
||||
vSectorFk sectorFk
|
||||
FROM vn.itemShelvingStock iss
|
||||
JOIN vn.sector s ON s.id = iss.sectorFk
|
||||
JOIN vn.item i on i.id = iss.itemFk
|
||||
JOIN vn.itemType it ON it.id = i.typeFk AND vBuyerFk IN (0,it.workerFk)
|
||||
LEFT JOIN cache.available a ON a.item_id = iss.itemFk AND a.calc_id = vCalcAvailableFk
|
||||
LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk
|
||||
IFNULL(a.available, 0) available,
|
||||
SUM(IF(s.sonFk = vSectorFk, IFNULL(iss.visible, 0), 0)) upstairs,
|
||||
SUM(IF(iss.sectorFk = vSectorFk, IFNULL(iss.visible, 0), 0)) downstairs,
|
||||
IF(it.isPackaging, NULL, IFNULL(v.visible, 0)) visible,
|
||||
vSectorFk sectorFk,
|
||||
ish.isChecked,
|
||||
sub.isAllChecked
|
||||
FROM itemShelvingStock iss
|
||||
JOIN itemShelving ish ON ish.shelvingFk = iss.shelvingFk
|
||||
LEFT JOIN (
|
||||
SELECT itemFk,
|
||||
IF(
|
||||
COUNT(*) = SUM(IF(isChecked >= 0, 1, 0)),
|
||||
TRUE,
|
||||
FALSE
|
||||
) isAllChecked
|
||||
FROM itemShelving is2
|
||||
GROUP BY itemFk
|
||||
) sub ON sub.itemFk = ish.itemFk
|
||||
JOIN sector s ON s.id = iss.sectorFk
|
||||
JOIN item i ON i.id = iss.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
LEFT JOIN cache.available a ON a.item_id = iss.itemFk
|
||||
AND a.calc_id = vCalcAvailableFk
|
||||
LEFT JOIN cache.visible v ON v.item_id = iss.itemFk
|
||||
AND v.calc_id = vCalcVisibleFk
|
||||
WHERE vSectorFk IN (iss.sectorFk, s.sonFk)
|
||||
GROUP BY iss.itemFk
|
||||
|
||||
UNION ALL
|
||||
|
||||
SELECT v.item_id,
|
||||
SELECT v.item_id,
|
||||
i.longName,
|
||||
i.size,
|
||||
i.subName producer,
|
||||
IFNULL(a.available,0) as available,
|
||||
0 upstairs,
|
||||
0 downstairs,
|
||||
IF(it.isPackaging, NULL, v.visible) visible,
|
||||
vSectorFk as sectorFk
|
||||
i.subName,
|
||||
IFNULL(a.available, 0),
|
||||
0,
|
||||
0,
|
||||
IF(it.isPackaging, NULL, v.visible),
|
||||
vSectorFk,
|
||||
NULL,
|
||||
NULL
|
||||
FROM cache.visible v
|
||||
JOIN vn.item i on i.id = v.item_id
|
||||
JOIN vn.itemType it ON it.id = i.typeFk AND vBuyerFk IN (0,it.workerFk)
|
||||
LEFT JOIN vn.itemShelvingStock iss ON iss.itemFk = v.item_id AND iss.warehouseFk = vWarehouseFk
|
||||
LEFT JOIN cache.available a ON a.item_id = v.item_id AND a.calc_id = vCalcAvailableFk
|
||||
JOIN item i ON i.id = v.item_id
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
LEFT JOIN itemShelvingStock iss ON iss.itemFk = v.item_id
|
||||
AND iss.warehouseFk = vWarehouseFk
|
||||
LEFT JOIN cache.available a ON a.item_id = v.item_id
|
||||
AND a.calc_id = vCalcAvailableFk
|
||||
WHERE v.calc_id = vCalcVisibleFk
|
||||
AND iss.itemFk IS NULL
|
||||
AND it.isInventory
|
||||
) sub GROUP BY itemFk;
|
||||
) sub
|
||||
GROUP BY itemFk;
|
||||
|
||||
SELECT ishr.*,
|
||||
CAST(visible - upstairs - downstairs AS DECIMAL(10,0)) AS nicho,
|
||||
CAST(downstairs - IFNULL(notPickedYed,0) AS DECIMAL(10,0)) as pendiente
|
||||
FROM tmp.itemShelvingRadar ishr
|
||||
JOIN vn.item i ON i.id = ishr.itemFk
|
||||
LEFT JOIN (SELECT s.itemFk, sum(s.quantity) as notPickedYed
|
||||
FROM vn.ticket t
|
||||
JOIN vn.ticketStateToday tst ON tst.ticketFk = t.id
|
||||
JOIN vn.sale s ON s.ticketFk = t.id
|
||||
WHERE t.warehouseFk = vWarehouseFk
|
||||
AND tst.alertLevel = 0
|
||||
GROUP BY s.itemFk
|
||||
) sub ON sub.itemFk = ishr.itemFk
|
||||
ORDER BY i.typeFk, i.longName;
|
||||
CAST(visible - upstairs - downstairs AS DECIMAL(10, 0)) nicho,
|
||||
CAST(downstairs - IFNULL(notPickedYed, 0) AS DECIMAL(10, 0)) pendiente
|
||||
FROM tItemShelvingRadar ishr
|
||||
JOIN item i ON i.id = ishr.itemFk
|
||||
LEFT JOIN (
|
||||
SELECT s.itemFk, SUM(s.quantity) notPickedYed
|
||||
FROM ticket t
|
||||
JOIN ticketStateToday tst ON tst.ticketFk = t.id
|
||||
JOIN alertLevel al ON al.id = tst.alertLevel
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
WHERE t.warehouseFk = vWarehouseFk
|
||||
AND al.code = 'FREE'
|
||||
GROUP BY s.itemFk
|
||||
) sub ON sub.itemFk = ishr.itemFk
|
||||
ORDER BY i.typeFk, i.longName;
|
||||
ELSE
|
||||
CREATE TEMPORARY TABLE tmp.itemShelvingRadar
|
||||
CREATE OR REPLACE TEMPORARY TABLE tItemShelvingRadar
|
||||
(PRIMARY KEY (itemFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT iss.itemFk,
|
||||
|
@ -115,80 +122,86 @@ proc:BEGIN
|
|||
i.size,
|
||||
i.subName producer,
|
||||
i.upToDown,
|
||||
IFNULL(a.available,0) available,
|
||||
IFNULL(v.visible - iss.visible,0) dayEndVisible,
|
||||
IFNULL(v.visible - iss.visible,0) firstNegative,
|
||||
IFNULL(v.visible - iss.visible,0) itemPlacementVisible,
|
||||
IFNULL(i.minimum * b.packing,0) itemPlacementSize,
|
||||
IFNULL(a.available, 0) available,
|
||||
IFNULL(v.visible - iss.visible, 0) dayEndVisible,
|
||||
IFNULL(v.visible - iss.visible, 0) firstNegative,
|
||||
IFNULL(v.visible - iss.visible, 0) itemPlacementVisible,
|
||||
IFNULL(i.minimum * b.packing, 0) itemPlacementSize,
|
||||
ips.onTheWay,
|
||||
iss.visible itemShelvingStock,
|
||||
IFNULL(v.visible,0) visible,
|
||||
IFNULL(v.visible, 0) visible,
|
||||
b.isPickedOff,
|
||||
iss.sectorFk
|
||||
FROM vn.itemShelvingStock iss
|
||||
JOIN vn.item i on i.id = iss.itemFk
|
||||
LEFT JOIN cache.last_buy lb ON lb.item_id = iss.itemFk AND lb.warehouse_id = vWarehouseFk
|
||||
LEFT JOIN vn.buy b ON b.id = lb.buy_id
|
||||
LEFT JOIN cache.available a ON a.item_id = iss.itemFk AND a.calc_id = vCalcAvailableFk
|
||||
LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk
|
||||
LEFT JOIN (SELECT itemFk, sum(saldo) as onTheWay
|
||||
FROM vn.itemPlacementSupplyList
|
||||
WHERE saldo > 0
|
||||
GROUP BY itemFk
|
||||
) ips ON ips.itemFk = i.id
|
||||
WHERE IFNULL(iss.sectorFk,0) IN (0, vSectorFk)
|
||||
OR iss.sectorFk = vSectorFk;
|
||||
FROM itemShelvingStock iss
|
||||
JOIN item i ON i.id = iss.itemFk
|
||||
LEFT JOIN cache.last_buy lb ON lb.item_id = iss.itemFk
|
||||
AND lb.warehouse_id = vWarehouseFk
|
||||
LEFT JOIN buy b ON b.id = lb.buy_id
|
||||
LEFT JOIN cache.available a ON a.item_id = iss.itemFk
|
||||
AND a.calc_id = vCalcAvailableFk
|
||||
LEFT JOIN cache.visible v ON v.item_id = iss.itemFk
|
||||
AND v.calc_id = vCalcVisibleFk
|
||||
LEFT JOIN (
|
||||
SELECT itemFk, SUM(saldo) onTheWay
|
||||
FROM itemPlacementSupplyList
|
||||
WHERE saldo > 0
|
||||
GROUP BY itemFk
|
||||
) ips ON ips.itemFk = i.id
|
||||
WHERE iss.sectorFk = vSectorFk
|
||||
OR iss.sectorFk IS NULL;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.itemOutTime;
|
||||
CREATE TEMPORARY TABLE tmp.itemOutTime
|
||||
SELECT *,SUM(amount) quantity
|
||||
FROM
|
||||
(SELECT io.itemFk,
|
||||
io.quantity amount,
|
||||
IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) as hours,
|
||||
IF(MINUTE(t.shipped), MINUTE(t.shipped), MINUTE(z.`hour`)) as minutes
|
||||
FROM itemTicketOut io
|
||||
JOIN tmp.itemShelvingRadar isr ON isr.itemFk = io.itemFk
|
||||
JOIN vn.ticket t on t.id= io.ticketFk
|
||||
JOIN vn.ticketState ts on ts.ticketFk = io.ticketFk
|
||||
JOIN vn.state s ON s.id = ts.stateFk
|
||||
LEFT JOIN vn.zone z ON z.id = t.zoneFk
|
||||
LEFT JOIN (SELECT DISTINCT saleFk
|
||||
FROM vn.saleTracking st
|
||||
WHERE st.created > util.VN_CURDATE()
|
||||
AND st.isChecked
|
||||
) stPrevious ON `stPrevious`.`saleFk` = io.saleFk
|
||||
WHERE t.warehouseFk = vWarehouseFk
|
||||
AND s.isPicked = 0
|
||||
AND NOT io.reserved
|
||||
AND stPrevious.saleFk IS NULL
|
||||
AND io.shipped >= util.VN_CURDATE()
|
||||
AND io.shipped < util.VN_CURDATE() + INTERVAL 1 DAY
|
||||
) sub
|
||||
GROUP BY itemFk, hours, minutes;
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.itemOutTime
|
||||
SELECT *, SUM(amount) quantity
|
||||
FROM (
|
||||
SELECT io.itemFk,
|
||||
io.quantity amount,
|
||||
IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) `hours`,
|
||||
IF(MINUTE(t.shipped), MINUTE(t.shipped), MINUTE(z.`hour`)) `minutes`
|
||||
FROM itemTicketOut `io`
|
||||
JOIN tItemShelvingRadar isr ON isr.itemFk = io.itemFk
|
||||
JOIN ticket t ON t.id= io.ticketFk
|
||||
JOIN ticketState ts ON ts.ticketFk = io.ticketFk
|
||||
JOIN `state` s ON s.id = ts.stateFk
|
||||
LEFT JOIN `zone` z ON z.id = t.zoneFk
|
||||
LEFT JOIN (
|
||||
SELECT DISTINCT saleFk
|
||||
FROM saleTracking st
|
||||
WHERE st.created > util.VN_CURDATE()
|
||||
AND st.isChecked
|
||||
) stPrevious ON stPrevious.saleFk = io.saleFk
|
||||
WHERE t.warehouseFk = vWarehouseFk
|
||||
AND NOT s.isPicked
|
||||
AND NOT io.reserved
|
||||
AND stPrevious.saleFk IS NULL
|
||||
AND io.shipped >= util.VN_CURDATE()
|
||||
AND io.shipped < util.VN_CURDATE() + INTERVAL 1 DAY
|
||||
) sub
|
||||
GROUP BY itemFk, `hours`, `minutes`;
|
||||
|
||||
INSERT INTO tmp.itemShelvingRadar (itemFk)
|
||||
INSERT INTO tItemShelvingRadar (itemFk)
|
||||
SELECT itemFk FROM tmp.itemOutTime
|
||||
ON DUPLICATE KEY UPDATE dayEndVisible = dayEndVisible + quantity,
|
||||
firstNegative = if (firstNegative < 0, firstNegative, firstNegative + quantity),
|
||||
`hour` = ifnull(if (firstNegative > 0 , `hour`, hours),0),
|
||||
`minute` = ifnull(if (firstNegative > 0, `minute`, minutes),0);
|
||||
ON DUPLICATE KEY UPDATE dayEndVisible = dayEndVisible + quantity,
|
||||
firstNegative = IF(firstNegative < 0, firstNegative, firstNegative + quantity),
|
||||
`hour` = IFNULL(IF(firstNegative > 0 , `hour`, `hours`), 0),
|
||||
`minute` = IFNULL(IF(firstNegative > 0, `minute`, `minutes`), 0);
|
||||
|
||||
UPDATE tmp.itemShelvingRadar isr
|
||||
JOIN (SELECT s.itemFk, sum(s.quantity) amount
|
||||
FROM sale s
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
JOIN ticketLastState tls ON tls.ticketFk = t.id
|
||||
WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE())
|
||||
AND tls.name = 'Prep Camara'
|
||||
GROUP BY s.itemFk) sub ON sub.itemFk = isr.itemFk
|
||||
UPDATE tItemShelvingRadar isr
|
||||
JOIN (
|
||||
SELECT s.itemFk, SUM(s.quantity) amount
|
||||
FROM sale s
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
JOIN ticketState ts ON ts.ticketFk = t.id
|
||||
WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE())
|
||||
AND ts.code = 'COOLER_PREPARATION'
|
||||
GROUP BY s.itemFk
|
||||
) sub ON sub.itemFk = isr.itemFk
|
||||
SET isr.dayEndVisible = dayEndVisible + sub.amount,
|
||||
firstNegative = firstNegative + sub.amount;
|
||||
|
||||
SELECT * FROM tmp.itemShelvingRadar;
|
||||
SELECT * FROM tItemShelvingRadar;
|
||||
END IF;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.itemShelvingRadar;
|
||||
DROP TEMPORARY TABLE tItemShelvingRadar;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_getItemDetails`(
|
||||
vBarcodeItem INT,
|
||||
vShelvingFK VARCHAR(10)
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Obtiene el precio y visible de un item
|
||||
*
|
||||
* @param vBarcodeItem barcode de artículo
|
||||
* @param vShelvingFK Ubicación actual del artículo
|
||||
*/
|
||||
DECLARE vIsItem BOOL;
|
||||
DECLARE vBuyFk INT;
|
||||
DECLARE vWarehouseFk INT;
|
||||
|
||||
SELECT COUNT(*) > 0 INTO vIsItem
|
||||
FROM item
|
||||
WHERE id = vBarcodeItem;
|
||||
|
||||
IF vIsItem THEN
|
||||
SELECT warehouseFk INTO vWarehouseFk
|
||||
FROM operator
|
||||
WHERE workerFk = account.myUser_getId();
|
||||
|
||||
CALL buyUltimate(vWarehouseFk, util.VN_CURDATE());
|
||||
|
||||
SELECT buyFk INTO vBuyFk
|
||||
FROM tmp.buyUltimate
|
||||
WHERE itemFk = vBarcodeItem
|
||||
AND warehouseFk = vWarehouseFk;
|
||||
|
||||
DELETE FROM tmp.buyUltimate;
|
||||
ELSE
|
||||
SELECT vBarcodeItem INTO vBuyFk;
|
||||
END IF;
|
||||
|
||||
WITH visible AS(
|
||||
SELECT itemFk,
|
||||
IFNULL(buyingValue, 0) +
|
||||
IFNULL(freightValue, 0) +
|
||||
IFNULL(comissionValue, 0) +
|
||||
IFNULL(packageValue, 0) itemCost
|
||||
FROM vn.buy b
|
||||
WHERE b.id = vBuyFk
|
||||
) SELECT v.itemFk,
|
||||
vShelvingFK,
|
||||
v.itemCost,
|
||||
SUM(ish.visible) visible
|
||||
FROM vn.itemShelving ish
|
||||
JOIN visible v
|
||||
WHERE ish.shelvingFK = vShelvingFK COLLATE utf8mb3_general_ci
|
||||
AND ish.itemFk = v.itemFk;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,56 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemTrash`(
|
||||
vItemFk INT,
|
||||
vWarehouseFk INT,
|
||||
vQuantity INT,
|
||||
vIsTrash BOOLEAN)
|
||||
BEGIN
|
||||
DECLARE vTicketFk INT;
|
||||
DECLARE vClientFk INT;
|
||||
DECLARE vCompanyVnlFk INT DEFAULT 442;
|
||||
DECLARE vCalc INT;
|
||||
|
||||
SELECT barcodeToItem(vItemFk) INTO vItemFk;
|
||||
|
||||
SELECT IF(vIsTrash, 200, 400) INTO vClientFk;
|
||||
|
||||
SELECT t.id INTO vTicketFk
|
||||
FROM ticket t
|
||||
JOIN address a ON a.id=t.addressFk
|
||||
WHERE t.warehouseFk = vWarehouseFk
|
||||
AND t.clientFk = vClientFk
|
||||
AND DATE(t.shipped) = util.VN_CURDATE()
|
||||
AND a.isDefaultAddress
|
||||
LIMIT 1;
|
||||
|
||||
CALL cache.visible_refresh(vCalc, TRUE, vWarehouseFk);
|
||||
|
||||
IF vTicketFk IS NULL THEN
|
||||
CALL ticket_add(
|
||||
vClientFk,
|
||||
util.VN_CURDATE(),
|
||||
vWarehouseFk,
|
||||
vCompanyVnlFk,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
util.VN_CURDATE(),
|
||||
account.myUser_getId(),
|
||||
FALSE,
|
||||
vTicketFk);
|
||||
END IF;
|
||||
|
||||
INSERT INTO sale(ticketFk, itemFk, concept, quantity)
|
||||
SELECT vTicketFk,
|
||||
vItemFk,
|
||||
CONCAT(longName,' ',worker_getCode(), ' ', LEFT(CAST(util.VN_NOW() AS TIME),5)),
|
||||
vQuantity
|
||||
FROM item
|
||||
WHERE id = vItemFk;
|
||||
|
||||
UPDATE cache.visible
|
||||
SET visible = visible - vQuantity
|
||||
WHERE calc_id = vCalc
|
||||
AND item_id = vItemFk;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,408 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_devalueA2`(
|
||||
vSelf INT,
|
||||
vShelvingFK VARCHAR(10),
|
||||
vBuyingValue DECIMAL(10,4),
|
||||
vQuantity INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Devalua un item modificando su calidad de A1 a A2.
|
||||
* Si no existe el item A2 lo crea y genera los movimientos de las entradas
|
||||
* de almacén y shelvings correspondientes
|
||||
*
|
||||
* @param vSelf Id de artículo a devaluar
|
||||
* @param vShelvingFK Ubicación actual del artículo
|
||||
* @param vBuyingValue Nuevo precio de coste
|
||||
* @param vQuantity Cantidad del ítem a pasar a A2
|
||||
*/
|
||||
DECLARE vItemA2Fk INT;
|
||||
DECLARE vLastBuyFk BIGINT;
|
||||
DECLARE vA1BuyFk INT;
|
||||
DECLARE vA2BuyFk INT;
|
||||
DECLARE vTargetEntryFk INT;
|
||||
DECLARE vTargetEntryDate DATE;
|
||||
DECLARE vTargetItemShelvingFk BIGINT;
|
||||
DECLARE vWarehouseFk INT;
|
||||
DECLARE vCacheFk INT;
|
||||
DECLARE vLastEntryFk INT;
|
||||
DECLARE vCurrentVisible INT;
|
||||
DECLARE vDevalueTravelFk INT;
|
||||
DECLARE vCurdate DATE;
|
||||
DECLARE vBuyingValueOriginal DECIMAL(10,4);
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
ROLLBACK;
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
IF (SELECT TRUE FROM item WHERE id = vSelf AND (category <> 'A1' OR category IS NULL)) THEN
|
||||
CALL util.throw('Item has not category A1');
|
||||
END IF;
|
||||
|
||||
SELECT warehouseFk INTO vWarehouseFk
|
||||
FROM userConfig
|
||||
WHERE userFk = account.myUser_getId();
|
||||
|
||||
IF NOT vWarehouseFk OR vWarehouseFk IS NULL THEN
|
||||
CALL util.throw ('Operator has not a valid warehouse');
|
||||
END IF;
|
||||
|
||||
IF vQuantity <= 0 OR vQuantity IS NULL THEN
|
||||
CALL util.throw ('The quantity is incorrect');
|
||||
END IF;
|
||||
|
||||
SELECT util.VN_CURDATE() INTO vCurdate;
|
||||
|
||||
SELECT t.id INTO vDevalueTravelFk
|
||||
FROM travel t
|
||||
JOIN travelConfig tc
|
||||
WHERE t.shipped = vCurdate
|
||||
AND t.landed = vCurdate
|
||||
AND t.warehouseInFk = vWarehouseFk
|
||||
AND t.warehouseOutFk = tc.devalueWarehouseOutFk
|
||||
AND t.agencyModeFk = tc.devalueAgencyModeFk
|
||||
LIMIT 1;
|
||||
|
||||
IF NOT vDevalueTravelFk OR vDevalueTravelFk IS NULL THEN
|
||||
INSERT INTO travel (
|
||||
shipped,
|
||||
landed,
|
||||
warehouseInFk,
|
||||
warehouseOutFk,
|
||||
`ref`,
|
||||
isReceived,
|
||||
agencyModeFk)
|
||||
SELECT vCurdate,
|
||||
vCurdate,
|
||||
vWarehouseFk,
|
||||
tc.devalueWarehouseOutFk,
|
||||
tc.devalueRef,
|
||||
TRUE,
|
||||
tc.devalueAgencyModeFk
|
||||
FROM travelConfig tc;
|
||||
SET vDevalueTravelFk = LAST_INSERT_ID();
|
||||
END IF;
|
||||
|
||||
SELECT id, DATE(dated) INTO vTargetEntryFk, vTargetEntryDate
|
||||
FROM `entry` e
|
||||
WHERE DATE(dated) = vCurdate
|
||||
AND typeFk = 'devaluation'
|
||||
AND travelFk = vDevalueTravelFk
|
||||
ORDER BY created DESC
|
||||
LIMIT 1;
|
||||
|
||||
CALL buyUltimate(vWarehouseFk, vCurdate);
|
||||
|
||||
SELECT b.entryFk, bu.buyFk,IFNULL(b.buyingValue, 0) INTO vLastEntryFk, vLastBuyFk, vBuyingValueOriginal
|
||||
FROM tmp.buyUltimate bu
|
||||
JOIN vn.buy b ON b.id = bu.buyFk
|
||||
WHERE bu.itemFk = vSelf
|
||||
AND bu.warehouseFk = vWarehouseFk;
|
||||
|
||||
IF vBuyingValue > vBuyingValueOriginal THEN
|
||||
CALL util.throw ('Price not valid');
|
||||
END IF;
|
||||
|
||||
IF vLastEntryFk IS NULL OR vLastBuyFk IS NULL THEN
|
||||
CALL util.throw ('The item has not a buy');
|
||||
END IF;
|
||||
|
||||
SELECT id,visible INTO vTargetItemShelvingFk, vCurrentVisible
|
||||
FROM itemShelving
|
||||
WHERE shelvingFk = vShelvingFK COLLATE utf8mb3_general_ci
|
||||
AND itemFk = vSelf
|
||||
LIMIT 1;
|
||||
|
||||
IF vCurrentVisible IS NULL THEN
|
||||
CALL util.throw ('The shelving has not a visible for this item');
|
||||
END IF;
|
||||
|
||||
IF vQuantity > vCurrentVisible THEN
|
||||
CALL util.throw('Quantity is greater than visible');
|
||||
END IF;
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
IF NOT vTargetEntryFk OR vTargetEntryFk IS NULL
|
||||
OR NOT vTargetEntryDate <=> vCurdate THEN
|
||||
INSERT INTO entry(
|
||||
travelFk,
|
||||
supplierFk,
|
||||
dated,
|
||||
commission,
|
||||
currencyFk,
|
||||
companyFk,
|
||||
clonedFrom,
|
||||
typeFk
|
||||
)
|
||||
SELECT vDevalueTravelFk,
|
||||
supplierFk,
|
||||
vCurdate,
|
||||
commission,
|
||||
currencyFk,
|
||||
companyFk,
|
||||
vLastEntryFk,
|
||||
'devaluation'
|
||||
FROM entry
|
||||
WHERE id = vLastEntryFk;
|
||||
|
||||
SET vTargetEntryFk = LAST_INSERT_ID();
|
||||
END IF;
|
||||
|
||||
SELECT i.id INTO vItemA2Fk
|
||||
FROM item i
|
||||
JOIN (
|
||||
SELECT i.id,
|
||||
i.name,
|
||||
i.subname,
|
||||
i.value5,
|
||||
i.value6,
|
||||
i.value7,
|
||||
i.value8,
|
||||
i.value9,
|
||||
i.value10,
|
||||
i.NumberOfItemsPerCask,
|
||||
i.EmbalageCode,
|
||||
i.quality
|
||||
FROM item i
|
||||
WHERE i.id = vSelf
|
||||
)i2 ON i2.name <=> i.name
|
||||
AND i2.subname <=> i.subname
|
||||
AND i2.value5 <=> i.value5
|
||||
AND i2.value6 <=> i.value6
|
||||
AND i2.value8 <=> i.value8
|
||||
AND i2.value9 <=> i.value9
|
||||
AND i2.value10 <=> i.value10
|
||||
AND i2.NumberOfItemsPerCask <=> i.NumberOfItemsPerCask
|
||||
AND i2.EmbalageCode <=> i.EmbalageCode
|
||||
AND i2.quality <=> i.quality
|
||||
WHERE i.id <> i2.id
|
||||
AND i.category = 'A2'
|
||||
LIMIT 1;
|
||||
|
||||
IF vItemA2Fk IS NULL THEN
|
||||
INSERT INTO item (
|
||||
equivalent,
|
||||
name,
|
||||
`size`,
|
||||
stems,
|
||||
minPrice,
|
||||
isToPrint,
|
||||
family,
|
||||
box,
|
||||
category,
|
||||
originFk,
|
||||
doPhoto,
|
||||
image,
|
||||
inkFk,
|
||||
intrastatFk,
|
||||
hasMinPrice,
|
||||
created,
|
||||
comment,
|
||||
typeFk,
|
||||
generic,
|
||||
producerFk,
|
||||
description,
|
||||
density,
|
||||
relevancy,
|
||||
expenseFk,
|
||||
isActive,
|
||||
longName,
|
||||
subName,
|
||||
minimum,
|
||||
upToDown,
|
||||
supplyResponseFk,
|
||||
hasKgPrice,
|
||||
isFloramondo,
|
||||
isFragile,
|
||||
numberOfItemsPerCask,
|
||||
embalageCode,
|
||||
quality,
|
||||
stemMultiplier,
|
||||
itemPackingTypeFk,
|
||||
packingOut,
|
||||
genericFk,
|
||||
isLaid,
|
||||
lastUsed,
|
||||
weightByPiece,
|
||||
editorFk,
|
||||
recycledPlastic,
|
||||
nonRecycledPlastic)
|
||||
SELECT equivalent,
|
||||
name,
|
||||
`size`,
|
||||
stems,
|
||||
minPrice,
|
||||
isToPrint,
|
||||
family,
|
||||
box,
|
||||
'A2',
|
||||
originFk,
|
||||
doPhoto,
|
||||
image,
|
||||
inkFk,
|
||||
intrastatFk,
|
||||
hasMinPrice,
|
||||
created,
|
||||
comment,
|
||||
typeFk,
|
||||
generic,
|
||||
producerFk,
|
||||
description,
|
||||
density,
|
||||
relevancy,
|
||||
expenseFk,
|
||||
isActive,
|
||||
longName,
|
||||
subName,
|
||||
minimum,
|
||||
upToDown,
|
||||
supplyResponseFk,
|
||||
hasKgPrice,
|
||||
isFloramondo,
|
||||
isFragile,
|
||||
numberOfItemsPerCask,
|
||||
embalageCode,
|
||||
quality,
|
||||
stemMultiplier,
|
||||
itemPackingTypeFk,
|
||||
packingOut,
|
||||
genericFk,
|
||||
isLaid,
|
||||
lastUsed,
|
||||
weightByPiece,
|
||||
editorFk,
|
||||
recycledPlastic,
|
||||
nonRecycledPlastic
|
||||
FROM item
|
||||
WHERE id = vSelf;
|
||||
|
||||
SET vItemA2Fk = LAST_INSERT_ID();
|
||||
|
||||
INSERT INTO itemTag (itemFk, tagFk, `value`, intValue, priority, editorFk)
|
||||
SELECT vItemA2Fk, tagFk, `value`, intValue, priority, editorFk
|
||||
FROM itemTag
|
||||
WHERE id = vSelf;
|
||||
|
||||
UPDATE itemTaxCountry itc
|
||||
JOIN itemTaxCountry itc2 ON itc2.itemFk = vSelf
|
||||
AND itc2.countryFk = itc.countryFk
|
||||
SET itc2.taxClassFk = itc.taxClassFk
|
||||
WHERE itc.id = vItemA2Fk;
|
||||
|
||||
INSERT INTO itemBotanical (itemFk, genusFk, specieFk)
|
||||
SELECT vItemA2Fk, genusFk, specieFk
|
||||
FROM itemBotanical
|
||||
WHERE itemFk = vSelf;
|
||||
END IF;
|
||||
|
||||
IF vQuantity = vCurrentVisible THEN
|
||||
DELETE FROM itemShelving
|
||||
WHERE id = vTargetItemShelvingFk;
|
||||
ELSE
|
||||
UPDATE itemShelving
|
||||
SET visible = vCurrentVisible - vQuantity
|
||||
WHERE id = vTargetItemShelvingFk;
|
||||
END IF;
|
||||
|
||||
INSERT INTO buy(
|
||||
entryFk,
|
||||
itemFk,
|
||||
quantity,
|
||||
buyingValue,
|
||||
freightValue,
|
||||
isIgnored,
|
||||
stickers,
|
||||
packagingFk,
|
||||
packing,
|
||||
`grouping`,
|
||||
groupingMode,
|
||||
comissionValue,
|
||||
packageValue,
|
||||
price1,
|
||||
price2,
|
||||
price3,
|
||||
minPrice,
|
||||
isChecked,
|
||||
location,
|
||||
weight,
|
||||
itemOriginalFk)
|
||||
SELECT vTargetEntryFk,
|
||||
itemFk,
|
||||
- LEAST(vQuantity, vCurrentVisible),
|
||||
buyingValue,
|
||||
freightValue,
|
||||
TRUE,
|
||||
stickers,
|
||||
packagingFk,
|
||||
packing,
|
||||
`grouping`,
|
||||
groupingMode,
|
||||
comissionValue,
|
||||
packageValue,
|
||||
price1,
|
||||
price2,
|
||||
price3,
|
||||
minPrice,
|
||||
isChecked,
|
||||
location,
|
||||
weight,
|
||||
itemOriginalFk
|
||||
FROM vn.buy
|
||||
WHERE id = vLastBuyFk
|
||||
UNION
|
||||
SELECT vTargetEntryFk,
|
||||
vItemA2Fk,
|
||||
vQuantity,
|
||||
vBuyingValue,
|
||||
freightValue,
|
||||
TRUE,
|
||||
stickers,
|
||||
packagingFk,
|
||||
packing,
|
||||
`grouping`,
|
||||
groupingMode,
|
||||
comissionValue,
|
||||
packageValue,
|
||||
price1,
|
||||
price2,
|
||||
price3,
|
||||
minPrice,
|
||||
isChecked,
|
||||
location,
|
||||
weight,
|
||||
itemOriginalFk
|
||||
FROM vn.buy
|
||||
WHERE id = vLastBuyFk;
|
||||
|
||||
INSERT IGNORE INTO itemShelving (
|
||||
itemFk,
|
||||
shelvingFk,
|
||||
visible,
|
||||
`grouping`,
|
||||
packing,
|
||||
packagingFk,
|
||||
userFk,
|
||||
isChecked)
|
||||
SELECT vItemA2Fk,
|
||||
shelvingFk,
|
||||
vQuantity ,
|
||||
`grouping`,
|
||||
packing,
|
||||
packagingFk,
|
||||
account.myUser_getId(),
|
||||
isChecked
|
||||
FROM itemShelving
|
||||
WHERE itemFK = vSelf
|
||||
AND shelvingFk = vShelvingFK COLLATE utf8mb3_general_ci
|
||||
ON DUPLICATE KEY UPDATE
|
||||
visible = vQuantity + VALUES(visible);
|
||||
|
||||
COMMIT;
|
||||
CALL cache.visible_refresh(vCacheFk, TRUE, vWarehouseFk);
|
||||
CALL cache.available_refresh(vCacheFk, TRUE, vWarehouseFk, vCurdate);
|
||||
CALL buy_recalcPricesByBuy(vA2BuyFk);
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -9,7 +9,7 @@ BEGIN
|
|||
* @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.
|
||||
* Si la fecha no es null, muestra histórico desde la fecha de vDate.
|
||||
*/
|
||||
DECLARE vDateInventory DATETIME;
|
||||
|
||||
|
@ -40,117 +40,154 @@ BEGIN
|
|||
inventorySupplierFk INT(10)
|
||||
);
|
||||
|
||||
INSERT INTO tItemDiary
|
||||
SELECT tr.landed shipped,
|
||||
b.quantity `in`,
|
||||
NULL `out`,
|
||||
st.alertLevel ,
|
||||
st.name stateName,
|
||||
s.name `name`,
|
||||
e.invoiceNumber reference,
|
||||
e.id origin,
|
||||
s.id clientFk,
|
||||
IF(st.`code` = 'DELIVERED', TRUE, FALSE) isPicked,
|
||||
FALSE isTicket,
|
||||
b.id lineFk,
|
||||
NULL `order`,
|
||||
NULL clientType,
|
||||
NULL claimFk,
|
||||
ec.inventorySupplierFk
|
||||
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 state st ON st.`code` = IF( tr.landed < util.VN_CURDATE()
|
||||
OR (util.VN_CURDATE() AND tr.isReceived),
|
||||
'DELIVERED',
|
||||
'FREE')
|
||||
JOIN entryConfig ec
|
||||
WHERE tr.landed >= vDateInventory
|
||||
AND vWarehouseFk = tr.warehouseInFk
|
||||
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
||||
AND b.itemFk = vItemFk
|
||||
AND e.isExcludedFromAvailable = FALSE
|
||||
AND e.isRaid = FALSE
|
||||
UNION ALL
|
||||
SELECT tr.shipped,
|
||||
NULL,
|
||||
b.quantity,
|
||||
st.alertLevel,
|
||||
st.name,
|
||||
s.name,
|
||||
e.invoiceNumber,
|
||||
e.id,
|
||||
s.id,
|
||||
IF(st.`code` = 'DELIVERED' , TRUE, FALSE),
|
||||
FALSE,
|
||||
b.id,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
ec.inventorySupplierFk
|
||||
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 state st ON st.`code` = IF(tr.shipped < util.VN_CURDATE()
|
||||
INSERT INTO tItemDiary
|
||||
WITH entriesIn AS (
|
||||
SELECT tr.landed shipped,
|
||||
b.quantity `in`,
|
||||
NULL `out`,
|
||||
st.alertLevel ,
|
||||
st.name stateName,
|
||||
s.name `name`,
|
||||
e.invoiceNumber reference,
|
||||
e.id origin,
|
||||
s.id clientFk,
|
||||
IF(st.`code` = 'DELIVERED', TRUE, FALSE) isPicked,
|
||||
FALSE isTicket,
|
||||
b.id lineFk,
|
||||
NULL `order`,
|
||||
NULL clientType,
|
||||
NULL claimFk,
|
||||
ec.inventorySupplierFk
|
||||
FROM vn.buy b
|
||||
JOIN vn.entry e ON e.id = b.entryFk
|
||||
JOIN vn.travel tr ON tr.id = e.travelFk
|
||||
JOIN vn.supplier s ON s.id = e.supplierFk
|
||||
JOIN vn.state st ON st.`code` = IF( tr.landed < util.VN_CURDATE()
|
||||
OR (util.VN_CURDATE() AND tr.isReceived),
|
||||
'DELIVERED',
|
||||
'FREE')
|
||||
JOIN vn.entryConfig ec
|
||||
WHERE tr.landed >= vDateInventory
|
||||
AND vWarehouseFk = tr.warehouseInFk
|
||||
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
||||
AND b.itemFk = vItemFk
|
||||
AND NOT e.isExcludedFromAvailable
|
||||
AND NOT e.isRaid
|
||||
), entriesOut AS (
|
||||
SELECT tr.shipped,
|
||||
NULL,
|
||||
b.quantity,
|
||||
st.alertLevel,
|
||||
st.name stateName,
|
||||
s.name ,
|
||||
e.invoiceNumber,
|
||||
e.id entryFk,
|
||||
s.id supplierFk,
|
||||
IF(st.`code` = 'DELIVERED' , TRUE, FALSE),
|
||||
FALSE isTicket,
|
||||
b.id,
|
||||
NULL `order`,
|
||||
NULL clientType,
|
||||
NULL claimFk,
|
||||
ec.inventorySupplierFk
|
||||
FROM vn.buy b
|
||||
JOIN vn.entry e ON e.id = b.entryFk
|
||||
JOIN vn.travel tr ON tr.id = e.travelFk
|
||||
JOIN vn.warehouse w ON w.id = tr.warehouseOutFk
|
||||
JOIN vn.supplier s ON s.id = e.supplierFk
|
||||
JOIN vn.state st ON st.`code` = IF(tr.shipped < util.VN_CURDATE()
|
||||
OR (tr.shipped = util.VN_CURDATE() AND tr.isReceived),
|
||||
'DELIVERED',
|
||||
'FREE')
|
||||
JOIN entryConfig ec
|
||||
WHERE tr.shipped >= vDateInventory
|
||||
AND vWarehouseFk = tr.warehouseOutFk
|
||||
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
||||
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,
|
||||
st2.alertLevel,
|
||||
st2.name,
|
||||
t.nickname,
|
||||
t.refFk,
|
||||
t.id,
|
||||
t.clientFk,
|
||||
stk.id,
|
||||
TRUE,
|
||||
s.id,
|
||||
st.`order`,
|
||||
c.typeFk,
|
||||
cb.claimFk,
|
||||
NULL
|
||||
FROM sale s
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
|
||||
LEFT JOIN state st ON st.`code` = ts.`code`
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
JOIN state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(),
|
||||
'DELIVERED',
|
||||
IF (t.shipped > util.dayEnd(util.VN_CURDATE()),
|
||||
'FREE',
|
||||
IFNULL(ts.code, 'FREE')))
|
||||
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,
|
||||
(inventorySupplierFk = clientFk) DESC,
|
||||
alertLevel DESC,
|
||||
isTicket,
|
||||
`order` DESC,
|
||||
isPicked DESC,
|
||||
`in` DESC,
|
||||
`out` DESC;
|
||||
'DELIVERED',
|
||||
'FREE')
|
||||
JOIN vn.entryConfig ec
|
||||
WHERE tr.shipped >= vDateInventory
|
||||
AND vWarehouseFk = tr.warehouseOutFk
|
||||
AND (s.id <> ec.inventorySupplierFk OR vDate IS NULL)
|
||||
AND b.itemFk = vItemFk
|
||||
AND NOT e.isExcludedFromAvailable
|
||||
AND NOT w.isFeedStock
|
||||
AND NOT e.isRaid
|
||||
), sales AS (
|
||||
SELECT DATE(t.shipped) shipped,
|
||||
s.quantity,
|
||||
st2.alertLevel,
|
||||
st2.name,
|
||||
t.nickname,
|
||||
t.refFk,
|
||||
t.id ticketFk,
|
||||
t.clientFk,
|
||||
s.id saleFk,
|
||||
st.`order`,
|
||||
c.typeFk,
|
||||
cb.claimFk
|
||||
FROM vn.sale s
|
||||
JOIN vn.ticket t ON t.id = s.ticketFk
|
||||
LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id
|
||||
LEFT JOIN vn.state st ON st.`code` = ts.`code`
|
||||
JOIN vn.client c ON c.id = t.clientFk
|
||||
JOIN vn.state st2 ON st2.`code` = IF(t.shipped < util.VN_CURDATE(),
|
||||
'DELIVERED',
|
||||
IF (t.shipped > util.dayEnd(util.VN_CURDATE()),
|
||||
'FREE',
|
||||
IFNULL(ts.code, 'FREE')))
|
||||
LEFT JOIN vn.claimBeginning cb ON s.id = cb.saleFk
|
||||
WHERE t.shipped >= vDateInventory
|
||||
AND s.itemFk = vItemFk
|
||||
AND vWarehouseFk = t.warehouseFk
|
||||
),sale AS (
|
||||
SELECT s.shipped,
|
||||
NULL `in`,
|
||||
s.quantity,
|
||||
s.alertLevel,
|
||||
s.name,
|
||||
s.nickname,
|
||||
s.refFk,
|
||||
s.ticketFk,
|
||||
s.clientFk,
|
||||
IF(stk.saleFk, TRUE, NULL),
|
||||
TRUE,
|
||||
s.saleFk,
|
||||
s.`order`,
|
||||
s.typeFk,
|
||||
s.claimFk,
|
||||
NULL
|
||||
FROM sales s
|
||||
LEFT JOIN vn.state stPrep ON stPrep.`code` = 'PREPARED'
|
||||
LEFT JOIN vn.saleTracking stk ON stk.saleFk = s.saleFk
|
||||
AND stk.stateFk = stPrep.id
|
||||
GROUP BY s.saleFk
|
||||
) SELECT shipped,
|
||||
`in`,
|
||||
`out`,
|
||||
alertLevel,
|
||||
stateName,
|
||||
`name`,
|
||||
reference,
|
||||
origin,
|
||||
clientFk,
|
||||
isPicked,
|
||||
isTicket,
|
||||
lineFk,
|
||||
`order`,
|
||||
clientType,
|
||||
claimFk,
|
||||
inventorySupplierFk
|
||||
FROM entriesIn
|
||||
UNION ALL
|
||||
SELECT * FROM entriesOut
|
||||
UNION ALL
|
||||
SELECT * FROM sale
|
||||
ORDER BY shipped,
|
||||
(inventorySupplierFk = clientFk) DESC,
|
||||
alertLevel DESC,
|
||||
isTicket,
|
||||
`order` DESC,
|
||||
isPicked DESC,
|
||||
`in` DESC,
|
||||
`out` DESC;
|
||||
|
||||
IF vDate IS NULL THEN
|
||||
|
||||
|
||||
SET @a := 0;
|
||||
SET @currentLineFk := 0;
|
||||
SET @shipped := '';
|
||||
|
@ -220,7 +257,7 @@ BEGIN
|
|||
FROM tItemDiary
|
||||
WHERE shipped >= vDate;
|
||||
END IF;
|
||||
|
||||
|
||||
DROP TEMPORARY TABLE tItemDiary;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_doCompensation`(vDated DATE, vCompensationAccount VARCHAR(10) , vBankFk VARCHAR(10), vConcept VARCHAR(255), vAmount DECIMAL(10,2), vCompanyFk INT, vOriginalAccount VARCHAR(10))
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_doCompensation`(
|
||||
vDated DATE,
|
||||
vCompensationAccount VARCHAR(10),
|
||||
vBankFk VARCHAR(10),
|
||||
vConcept VARCHAR(255),
|
||||
vAmount DECIMAL(10,2),
|
||||
vCompanyFk INT,
|
||||
vOriginalAccount VARCHAR(10)
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Compensa un pago o un recibo insertando en contabilidad
|
||||
|
@ -9,29 +17,31 @@ BEGIN
|
|||
* @param vBankFk banco de la compensacion
|
||||
* @param vConcept descripcion
|
||||
* @param vAmount cantidad que se compensa
|
||||
* @param vCompany empresa
|
||||
* @param vCompanyFk empresa
|
||||
* @param vOriginalAccount cuenta contable desde la cual se compensa
|
||||
*
|
||||
*/
|
||||
*/
|
||||
DECLARE vNewBookEntry INT;
|
||||
DECLARE vIsClientCompensation INT;
|
||||
DECLARE vIsClientCompensation INT;
|
||||
DECLARE vClientFk INT;
|
||||
DECLARE vSupplierFk INT;
|
||||
DECLARE vIsOriginalAClient BOOL;
|
||||
DECLARE vPayMethodCompensation INT;
|
||||
|
||||
CALL ledger_next(vNewBookEntry);
|
||||
DECLARE vSupplierFk INT;
|
||||
DECLARE vIsOriginalAClient BOOL;
|
||||
DECLARE vPayMethodCompensation INT;
|
||||
|
||||
SELECT COUNT(id) INTO vIsOriginalAClient FROM client WHERE accountingAccount LIKE vOriginalAccount COLLATE utf8_general_ci;
|
||||
CALL ledger_next(YEAR(vDated), vNewBookEntry);
|
||||
|
||||
SELECT COUNT(id) INTO vIsOriginalAClient
|
||||
FROM client
|
||||
WHERE accountingAccount LIKE vOriginalAccount COLLATE utf8_general_ci;
|
||||
|
||||
SELECT id, COUNT(id) INTO vClientFk, vIsClientCompensation
|
||||
FROM client
|
||||
WHERE accountingAccount LIKE vCompensationAccount COLLATE utf8_general_ci;
|
||||
|
||||
|
||||
SET @vAmount1:= 0.0;
|
||||
SET @vAmount2:= 0.0;
|
||||
|
||||
INSERT INTO XDiario (ASIEN, FECHA, SUBCTA, CONTRA, CONCEPTO, EURODEBE, EUROHABER, empresa_id)
|
||||
INSERT INTO XDiario (ASIEN, FECHA, SUBCTA, CONTRA, CONCEPTO, EURODEBE, EUROHABER, empresa_id)
|
||||
VALUES ( vNewBookEntry,
|
||||
vDated,
|
||||
vOriginalAccount,
|
||||
|
@ -49,30 +59,51 @@ BEGIN
|
|||
),
|
||||
vCompanyFk
|
||||
),
|
||||
( vNewBookEntry,
|
||||
vDated,
|
||||
vCompensationAccount,
|
||||
vOriginalAccount,
|
||||
vConcept,
|
||||
@vAmount2,
|
||||
( vNewBookEntry,
|
||||
vDated,
|
||||
vCompensationAccount,
|
||||
vOriginalAccount,
|
||||
vConcept,
|
||||
@vAmount2,
|
||||
@vAmount1,
|
||||
vCompanyFk);
|
||||
|
||||
IF vIsClientCompensation THEN
|
||||
IF vIsOriginalAClient THEN
|
||||
SET vAmount = -vAmount;
|
||||
END IF;
|
||||
INSERT INTO receipt(invoiceFk, amountPaid, payed, bankFk, companyFk, clientFk, isConciliate)
|
||||
VALUES (vConcept, vAmount, vDated, vBankFk, vCompanyFk, vClientFk, TRUE);
|
||||
ELSE
|
||||
IF NOT vIsOriginalAClient THEN
|
||||
SET vAmount = -vAmount;
|
||||
END IF;
|
||||
SELECT id INTO vSupplierFk FROM supplier WHERE `account` LIKE vCompensationAccount COLLATE utf8_general_ci;
|
||||
SELECT id INTO vPayMethodCompensation FROM payMethod WHERE `code` = 'compensation';
|
||||
|
||||
INSERT INTO payment (received, dueDated, supplierFk, amount, bankFk, payMethodFk, concept, companyFk, isConciliated)
|
||||
VALUES(vDated, vDated, vSupplierFk, vAmount, vBankFk, vPayMethodCompensation, vConcept, vCompanyFk, TRUE);
|
||||
END IF;
|
||||
vCompanyFk);
|
||||
|
||||
IF vIsClientCompensation THEN
|
||||
IF vIsOriginalAClient THEN
|
||||
SET vAmount = -vAmount;
|
||||
END IF;
|
||||
|
||||
INSERT INTO receipt
|
||||
SET invoiceFk = vConcept,
|
||||
amountPaid = vAmount,
|
||||
payed = vDated,
|
||||
bankFk = vBankFk,
|
||||
companyFk = vCompanyFk,
|
||||
clientFk = vClientFk,
|
||||
isConciliate = TRUE;
|
||||
ELSE
|
||||
IF NOT vIsOriginalAClient THEN
|
||||
SET vAmount = -vAmount;
|
||||
END IF;
|
||||
|
||||
SELECT id INTO vSupplierFk
|
||||
FROM supplier
|
||||
WHERE `account` LIKE vCompensationAccount COLLATE utf8_general_ci;
|
||||
|
||||
SELECT id INTO vPayMethodCompensation
|
||||
FROM payMethod
|
||||
WHERE `code` = 'compensation';
|
||||
|
||||
INSERT INTO payment
|
||||
SET received = vDated,
|
||||
dueDated = vDated,
|
||||
supplierFk = vSupplierFk,
|
||||
amount = vAmount,
|
||||
bankFk = vBankFk,
|
||||
payMethodFk = vPayMethodCompensation,
|
||||
concept = vConcept,
|
||||
companyFk = vCompanyFk,
|
||||
isConciliated = TRUE;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_next`(OUT vNewBookEntry INT)
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ledger_next`(
|
||||
IN vFiscalYear INT,
|
||||
OUT vNewBookEntry INT
|
||||
)
|
||||
BEGIN
|
||||
|
||||
UPDATE vn.ledgerConfig SET lastBookEntry = LAST_INSERT_ID(lastBookEntry + 1);
|
||||
SET vNewBookEntry = LAST_INSERT_ID();
|
||||
|
||||
UPDATE ledgerCompany
|
||||
SET bookEntry = LAST_INSERT_ID(bookEntry + 1)
|
||||
WHERE fiscalYear = vFiscalYear;
|
||||
|
||||
SET vNewBookEntry = LAST_INSERT_ID();
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -1,121 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`packageInvoicing`(
|
||||
IN vClient INT,
|
||||
IN vDate DATE,
|
||||
IN vCompany INT,
|
||||
IN vIsAllInvoiceable BOOLEAN,
|
||||
OUT vNewTicket INT(11)
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE vGraceDays INT;
|
||||
DECLARE vDateStart DATE DEFAULT '2017-11-21';
|
||||
DECLARE vIsInvoiceable BOOLEAN;
|
||||
DECLARE vWarehouse INT DEFAULT 13;
|
||||
DECLARE vComponentCost INT DEFAULT 28;
|
||||
DECLARE vGraceDate DATE;
|
||||
DECLARE vDateEnd DATE;
|
||||
|
||||
SET vGraceDays = IF(vIsAllInvoiceable ,0, 30);
|
||||
SET vGraceDate = TIMESTAMPADD(DAY, - vGraceDays, vDate);
|
||||
|
||||
/* Clientes especiales:
|
||||
3240 MADEFLOR
|
||||
992 JAVIER FELIU
|
||||
4 TONI VENDRELL
|
||||
*/
|
||||
|
||||
IF vClient IN (992, 3240, 4) THEN
|
||||
|
||||
SET vGraceDays = 365;
|
||||
|
||||
END IF;
|
||||
/* Fin clientes especiales */
|
||||
|
||||
SET vDateEnd = DATE_ADD(vDate, INTERVAL 1 DAY);
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.packageToInvoice;
|
||||
|
||||
CREATE TEMPORARY TABLE tmp.packageToInvoice
|
||||
SELECT p.itemFk,
|
||||
tp.packagingFk,
|
||||
IF(tp.quantity < 0 OR t.shipped < vGraceDate, tp.quantity, 0) quantity,
|
||||
tp.ticketFk,
|
||||
p.price
|
||||
FROM ticketPackaging tp
|
||||
JOIN packaging p ON p.id = tp.packagingFk
|
||||
JOIN ticket t ON t.id = tp.ticketFk
|
||||
WHERE t.shipped BETWEEN vDateStart AND vDateEnd
|
||||
AND t.clientFk = vClient;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.packageToInvoicePositives;
|
||||
|
||||
CREATE TEMPORARY TABLE tmp.packageToInvoicePositives
|
||||
SELECT itemFk, sum(quantity) as totalQuantity
|
||||
FROM tmp.packageToInvoice
|
||||
GROUP BY itemFk
|
||||
HAVING totalQuantity > 0;
|
||||
|
||||
SELECT COUNT(*)
|
||||
INTO vIsInvoiceable
|
||||
FROM tmp.packageToInvoicePositives;
|
||||
|
||||
IF vIsInvoiceable THEN
|
||||
|
||||
CALL ticket_add(vClient,
|
||||
vDateEnd,
|
||||
vWarehouse,
|
||||
vCompany,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
vDateEnd,
|
||||
account.myUser_getId(),
|
||||
TRUE,
|
||||
vNewTicket);
|
||||
|
||||
INSERT INTO ticketPackaging(
|
||||
ticketFk,
|
||||
packagingFk,
|
||||
quantity,
|
||||
pvp)
|
||||
SELECT vNewTicket,
|
||||
pti.packagingFk,
|
||||
- SUM(pti.quantity) AS totalQuantity,
|
||||
pti.price
|
||||
FROM tmp.packageToInvoice pti
|
||||
LEFT JOIN tmp.packageToInvoicePositives ptip ON pti.itemFk = ptip.itemFk
|
||||
WHERE ptip.itemFK IS NOT NULL
|
||||
OR vIsAllInvoiceable
|
||||
GROUP BY packagingFk
|
||||
HAVING totalQuantity;
|
||||
|
||||
INSERT INTO sale(
|
||||
ticketFk,
|
||||
itemFk,
|
||||
concept,
|
||||
quantity,
|
||||
price
|
||||
)
|
||||
SELECT vNewTicket,
|
||||
pti.itemFk,
|
||||
i.name as concept,
|
||||
sum(pti.quantity) as totalQuantity,
|
||||
pti.price
|
||||
FROM tmp.packageToInvoice pti
|
||||
JOIN item i ON i.id = pti.itemFk
|
||||
LEFT JOIN tmp.packageToInvoicePositives ptip ON pti.itemFk = ptip.itemFk
|
||||
WHERE ptip.itemFK IS NOT NULL
|
||||
OR vIsAllInvoiceable
|
||||
GROUP BY pti.itemFk
|
||||
HAVING totalQuantity;
|
||||
|
||||
INSERT INTO saleComponent(saleFk, componentFk, value)
|
||||
SELECT id, vComponentCost, price
|
||||
FROM sale
|
||||
WHERE ticketFk = vNewTicket;
|
||||
|
||||
END IF;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -20,7 +20,7 @@ BEGIN
|
|||
CONCAT(tc.collectionFk, ' ', LEFT(cc.code, 4)) color,
|
||||
CONCAT(tc.collectionFk, ' ', SUBSTRING('ABCDEFGH',tc.wagon, 1), '-', tc.level) levelV,
|
||||
tc.ticketFk,
|
||||
LEFT(COALESCE(et.description, zo.name, am.name),12) agencyDescription,
|
||||
LEFT(COALESCE(rs.description, zo.name, am.name),12) agencyDescription,
|
||||
am.name,
|
||||
t.clientFk,
|
||||
CONCAT(CAST(SUM(sv.volume) AS DECIMAL(5, 2)), 'm³') m3 ,
|
||||
|
@ -47,7 +47,7 @@ BEGIN
|
|||
LEFT JOIN ticketTrolley tt ON tt.ticket = t.id
|
||||
LEFT JOIN zone zo ON t.zoneFk = zo.id
|
||||
LEFT JOIN routesMonitor rm ON rm.routeFk = t.routeFk
|
||||
LEFT JOIN expeditionTruck et ON et.id = rm.expeditionTruckFk
|
||||
LEFT JOIN roadmapStop rs ON rs.id = rm.expeditionTruckFk
|
||||
WHERE IF(vIsCollection, tc.collectionFk = vParam, tc.ticketFk = vParam)
|
||||
GROUP BY t.id
|
||||
ORDER BY cc.code;
|
||||
|
|
|
@ -106,8 +106,8 @@ BEGIN
|
|||
SET rm.m3boxes = sub.m3boxes;
|
||||
|
||||
UPDATE routesMonitor rm
|
||||
JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk
|
||||
SET rm.etd = et.eta;
|
||||
JOIN vn.roadmapStop rs ON rs.id = rm.expeditionTruckFk
|
||||
SET rm.etd = rs.eta;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.routesMonitor;
|
||||
END$$
|
||||
|
|
|
@ -34,7 +34,7 @@ BEGIN
|
|||
ticketFk INT(11),
|
||||
saleFk INT(11),
|
||||
isFreezed INTEGER(1) DEFAULT 0,
|
||||
risk DECIMAL(10,2) DEFAULT 0,
|
||||
risk DECIMAL(10,1) DEFAULT 0,
|
||||
hasHighRisk TINYINT(1) DEFAULT 0,
|
||||
hasTicketRequest INTEGER(1) DEFAULT 0,
|
||||
itemShortage VARCHAR(255),
|
||||
|
@ -44,6 +44,7 @@ BEGIN
|
|||
hasComponentLack INTEGER(1),
|
||||
hasRounding VARCHAR(255),
|
||||
isTooLittle BOOL DEFAULT FALSE,
|
||||
isVip BOOL DEFAULT FALSE,
|
||||
PRIMARY KEY (ticketFk, saleFk)
|
||||
) ENGINE = MEMORY;
|
||||
|
||||
|
@ -79,6 +80,14 @@ BEGIN
|
|||
JOIN volumeConfig vc
|
||||
WHERE sub.litros < vc.minTicketVolume
|
||||
AND sub.totalWithoutVat < vc.minTicketValue;
|
||||
|
||||
-- VIP
|
||||
INSERT INTO tmp.sale_problems(ticketFk, isVip)
|
||||
SELECT DISTINCT tl.ticketFk, TRUE
|
||||
FROM tmp.ticket_list tl
|
||||
JOIN client c ON c.id = tl.clientFk
|
||||
WHERE c.businessTypeFk = 'VIP'
|
||||
ON DUPLICATE KEY UPDATE isVip = TRUE;
|
||||
|
||||
-- Faltan componentes
|
||||
INSERT INTO tmp.sale_problems(ticketFk, hasComponentLack, saleFk)
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblem`(
|
||||
vProblemCode VARCHAR(25)
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Update column sale.problem with a problem code
|
||||
* @param vProblemCode Code to set or unset
|
||||
* @table tmp.sale(saleFk, hasProblem)
|
||||
*/
|
||||
UPDATE sale s
|
||||
JOIN tmp.sale ts ON ts.saleFk = s.id
|
||||
SET s.problem = CONCAT(
|
||||
IF(ts.hasProblem,
|
||||
CONCAT(s.problem, ',', vProblemCode),
|
||||
REPLACE(s.problem, vProblemCode , '')));
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,21 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblemComponentLack`(
|
||||
vSelf INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Update the problems for sales lines that have or no longer have problems with components,
|
||||
* verify whether all mandatory components are present or not
|
||||
*
|
||||
* @param vSelf Id del sale
|
||||
*/
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||
(INDEX(saleFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT vSelf saleFk, sale_hasComponentLack(vSelf) hasProblem;
|
||||
|
||||
CALL sale_setProblem('hasComponentLack');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.sale;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,26 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblemComponentLackByComponent`(
|
||||
vComponentFk INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Update the issues for sales lines that have or no longer have problems with components, verify
|
||||
* whether all mandatory components are present or not resulting from changes in the table vn.component
|
||||
*
|
||||
* @param vComponentFk Id component
|
||||
*/
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||
(INDEX(saleFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT s.id saleFk, sale_hasComponentLack(s.id) hasProblem
|
||||
FROM ticket t
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
||||
WHERE t.shipped >= util.midnight()
|
||||
AND (vComponentFk IS NULL OR sc.componentFk = vComponentFk);
|
||||
|
||||
CALL sale_setProblem('hasComponentLack');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.sale;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,34 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_setProblemRounding`(
|
||||
vSelf INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Update the rounding problem for a sales line
|
||||
* @param vSelf Id sale
|
||||
*/
|
||||
DECLARE vItemFk INT;
|
||||
DECLARE vWarehouseFk INT;
|
||||
DECLARE vShipped DATE;
|
||||
DECLARE vQuantity INT;
|
||||
|
||||
SELECT s.itemFk, t.warehouseFk, t.shipped, s.quantity
|
||||
INTO vItemFk, vWarehouseFk, vShipped, vQuantity
|
||||
FROM sale s
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
WHERE s.id = vSelf;
|
||||
|
||||
CALL buyUltimate(vWarehouseFk, vShipped);
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
SELECT vSelf saleFk, MOD(vQuantity, bu.`grouping`) hasProblem
|
||||
FROM tmp.buyUltimate bu
|
||||
JOIN buy b ON b.id = bu.buyFk
|
||||
WHERE bu.itemFk = vItemFk;
|
||||
|
||||
CALL sale_setProblem('hasRounding');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.ticket;
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -43,7 +43,7 @@ BEGIN
|
|||
INSERT INTO stockBuyed(buyed, dated, description)
|
||||
SELECT SUM(ic.cm3 * ito.quantity / vc.palletM3 / 1000000),
|
||||
vDated,
|
||||
IF(c.code = 'ES', p.name, c.country) destiny
|
||||
IF(c.code = 'ES', p.name, c.name) destiny
|
||||
FROM itemTicketOut ito
|
||||
JOIN ticket t ON t.id = ito.ticketFk
|
||||
JOIN `address` a ON a.id = t.addressFk
|
||||
|
|
|
@ -35,7 +35,7 @@ BEGIN
|
|||
itemFk,
|
||||
longName,
|
||||
supplier,
|
||||
entryFk,
|
||||
CONCAT('E',entryFk) entryFk,
|
||||
landed,
|
||||
`in`,
|
||||
`out`,
|
||||
|
@ -49,16 +49,98 @@ BEGIN
|
|||
itemFk,
|
||||
longName,
|
||||
supplier,
|
||||
'previous',
|
||||
'E previous',
|
||||
vFromDated,
|
||||
SUM(`in`),
|
||||
SUM(`out`),
|
||||
NULL,
|
||||
buyingValue
|
||||
AVG(buyingValue)
|
||||
FROM supplierPackaging
|
||||
WHERE supplierFk = vSupplierFk
|
||||
AND landed < vFromDated
|
||||
GROUP BY itemFk
|
||||
UNION ALL
|
||||
SELECT vSupplierFk,
|
||||
s.itemFk,
|
||||
i.longName,
|
||||
c.name,
|
||||
CONCAT('T',s.ticketFk),
|
||||
DATE(t.shipped),
|
||||
-LEAST(s.quantity,0) `in`,
|
||||
GREATEST(s.quantity,0) `out`,
|
||||
t.warehouseFk,
|
||||
s.price * (100 - s.discount) / 100
|
||||
FROM sale s
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN packaging p ON p.itemFk = i.id
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
JOIN supplier su ON su.nif = c.fi
|
||||
WHERE su.id = vSupplierFk
|
||||
AND t.shipped >= vFromDated
|
||||
AND p.isPackageReturnable
|
||||
UNION ALL
|
||||
SELECT vSupplierFk,
|
||||
s.itemFk,
|
||||
i.longName,
|
||||
c.name,
|
||||
'T previous',
|
||||
vFromDated,
|
||||
SUM(-LEAST(s.quantity,0)) `in`,
|
||||
SUM(GREATEST(s.quantity,0)) `out`,
|
||||
NULL,
|
||||
AVG(s.price * (100 - s.discount) / 100)
|
||||
FROM sale s
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN packaging p ON p.itemFk = i.id
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
JOIN supplier su ON su.nif = c.fi
|
||||
WHERE su.id = vSupplierFk
|
||||
AND t.shipped < vFromDated
|
||||
AND p.isPackageReturnable
|
||||
GROUP BY s.itemFk
|
||||
UNION ALL
|
||||
SELECT vSupplierFk,
|
||||
p.itemFk,
|
||||
i.longName,
|
||||
c.name,
|
||||
CONCAT('TP',tp.ticketFk),
|
||||
DATE(t.shipped),
|
||||
-LEAST(tp.quantity,0) `in`,
|
||||
GREATEST(tp.quantity,0) `out`,
|
||||
t.warehouseFk,
|
||||
0
|
||||
FROM ticketPackaging tp
|
||||
JOIN packaging p ON p.id = tp.packagingFk
|
||||
JOIN item i ON i.id = p.itemFk
|
||||
JOIN ticket t ON t.id = tp.ticketFk
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
JOIN supplier su ON su.nif = c.fi
|
||||
WHERE su.id = vSupplierFk
|
||||
AND t.shipped >= vFromDated
|
||||
AND p.isPackageReturnable
|
||||
UNION ALL
|
||||
SELECT vSupplierFk,
|
||||
p.itemFk,
|
||||
i.longName,
|
||||
c.name,
|
||||
'TP previous',
|
||||
vFromDated,
|
||||
SUM(-LEAST(tp.quantity,0)) `in`,
|
||||
SUM(GREATEST(tp.quantity,0)) `out`,
|
||||
NULL,
|
||||
0
|
||||
FROM ticketPackaging tp
|
||||
JOIN packaging p ON p.id = tp.packagingFk
|
||||
JOIN item i ON i.id = p.itemFk
|
||||
JOIN ticket t ON t.id = tp.ticketFk
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
JOIN supplier su ON su.nif = c.fi
|
||||
WHERE su.id = vSupplierFk
|
||||
AND t.shipped >= vFromDated
|
||||
AND p.isPackageReturnable
|
||||
GROUP BY p.itemFk
|
||||
ORDER BY itemFk, landed, entryFk
|
||||
) sub
|
||||
WHERE `out` OR `in`;
|
||||
|
@ -69,8 +151,8 @@ BEGIN
|
|||
supplier,
|
||||
entryFk,
|
||||
landed,
|
||||
`in`,
|
||||
`out`,
|
||||
CAST(`in` AS DECIMAL(10,0)) `in`,
|
||||
CAST(`out` AS DECIMAL(10,0)) `out`,
|
||||
warehouse,
|
||||
buyingValue,
|
||||
balance
|
||||
|
|
|
@ -7,7 +7,7 @@ BEGIN
|
|||
*
|
||||
* @param vSelf El id del ticket
|
||||
*/
|
||||
DECLARE vCmrFk, vPreviousCmrFk, vCurrentCmrFk INT;
|
||||
DECLARE vCmrFk INT;
|
||||
SELECT cmrFk INTO vCmrFk
|
||||
FROM ticket
|
||||
WHERE id = vSelf;
|
||||
|
@ -44,8 +44,6 @@ BEGIN
|
|||
AND t.id = vSelf
|
||||
GROUP BY t.id;
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
IF vCmrFk THEN
|
||||
UPDATE cmr c
|
||||
JOIN tTicket t
|
||||
|
@ -57,9 +55,7 @@ BEGIN
|
|||
c.supplierFk = t.supplierFk,
|
||||
c.ead = t.landed
|
||||
WHERE id = vCmrFk;
|
||||
ELSE
|
||||
SELECT MAX(id) INTO vPreviousCmrFk FROM cmr;
|
||||
|
||||
ELSE
|
||||
INSERT INTO cmr (
|
||||
senderInstruccions,
|
||||
truckPlate,
|
||||
|
@ -70,17 +66,14 @@ BEGIN
|
|||
ead
|
||||
)
|
||||
SELECT * FROM tTicket;
|
||||
|
||||
SELECT MAX(id) INTO vCurrentCmrFk FROM cmr;
|
||||
|
||||
IF vPreviousCmrFk <> vCurrentCmrFk THEN
|
||||
IF (SELECT EXISTS(SELECT * FROM tTicket)) THEN
|
||||
UPDATE ticket
|
||||
SET cmrFk = vCurrentCmrFk
|
||||
SET cmrFk = LAST_INSERT_ID()
|
||||
WHERE id = vSelf;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
COMMIT;
|
||||
DROP TEMPORARY TABLE tTicket;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -25,6 +25,7 @@ BEGIN
|
|||
MAX(itemDelay) itemDelay,
|
||||
MAX(hasRounding) hasRounding,
|
||||
MAX(itemLost) itemLost,
|
||||
MAX(isVip) isVip,
|
||||
0 totalProblems
|
||||
FROM tmp.sale_problems
|
||||
GROUP BY ticketFk;
|
||||
|
@ -40,7 +41,8 @@ BEGIN
|
|||
(tp.isTooLittle) +
|
||||
(tp.itemLost) +
|
||||
(tp.hasRounding) +
|
||||
(tp.itemShortage)
|
||||
(tp.itemShortage) +
|
||||
(tp.isVip)
|
||||
);
|
||||
|
||||
DROP TEMPORARY TABLE tmp.sale_problems;
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblem`(
|
||||
vProblemCode VARCHAR(25)
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Update column ticket.problem with a problem code
|
||||
*
|
||||
* @param vProblemCode Code to set or unset
|
||||
* @table tmp.ticket(ticketFk, hasProblem)
|
||||
*/
|
||||
UPDATE ticket t
|
||||
JOIN tmp.ticket tt ON tt.ticketFk = t.id
|
||||
SET t.problem = CONCAT(
|
||||
IF(tt.hasProblem,
|
||||
CONCAT(problem, ',', vProblemCode),
|
||||
REPLACE(problem, vProblemCode , '')));
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,29 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemFreeze`(
|
||||
vClientFk INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Update the problem of tickets whose client is frozen or unfrozen
|
||||
*
|
||||
* @param vClientFk Id Cliente, if NULL all clients
|
||||
*/
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
(INDEX(ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT t.id ticketFk, FALSE hasProblem
|
||||
FROM ticket t
|
||||
WHERE t.shipped >= util.midnight()
|
||||
AND (vClientFk IS NULL OR t.clientFk = vClientFk);
|
||||
|
||||
UPDATE tmp.ticket t
|
||||
JOIN ticket ti ON ti.id = t.ticketFk
|
||||
JOIN client c ON c.id = ti.clientFk
|
||||
SET t.hasProblem = TRUE
|
||||
WHERE c.isFreezed;
|
||||
|
||||
CALL ticket_setProblem('hasTicketRequest');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.ticket;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,28 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemRequest`(
|
||||
vSelf INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Update the problems of tickets that have a pending ticketRequest or no longer have it
|
||||
*
|
||||
* @param vSelf Id ticket, if NULL ALL tickets
|
||||
*/
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
(INDEX(ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT t.id ticketFk, FALSE hasProblem
|
||||
FROM ticket t
|
||||
WHERE t.shipped >= util.midnight()
|
||||
AND (vSelf IS NULL OR t.id = vSelf);
|
||||
|
||||
UPDATE tmp.ticket t
|
||||
JOIN ticketRequest tr ON tr.ticketFk = t.ticketFk
|
||||
SET t.hasProblem = TRUE
|
||||
WHERE tr.isOK IS NULL;
|
||||
|
||||
CALL ticket_setProblem('hasTicketRequest');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.ticket;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,33 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemRisk`(
|
||||
vSelf INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Update the risk problem for a specific ticket
|
||||
*
|
||||
* @param vSelf Id ticket
|
||||
*/
|
||||
DECLARE vHasRisk BOOL;
|
||||
DECLARE vHasHighRisk BOOL;
|
||||
|
||||
SELECT t.risk > (c.credit + 10), ((t.risk - cc.riskTolerance) > (c.credit + 10))
|
||||
INTO vHasRisk, vHasHighRisk
|
||||
FROM client c
|
||||
JOIN ticket t ON t.clientFk = c.id
|
||||
JOIN clientConfig cc
|
||||
WHERE t.id = vSelf;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
SELECT vSelf ticketFk, vRisk hasProblem;
|
||||
|
||||
CALL ticket_setProblem('hasRisk');
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
SELECT vSelf ticketFk, vHasHighRisk hasProblem;
|
||||
|
||||
CALL ticket_setProblem('hasHighRisk');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.ticket;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,34 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemRounding`(
|
||||
vSelf INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Update the rounding problem for the sales lines of a ticket
|
||||
*
|
||||
* @param vSelf Id de ticket
|
||||
*/
|
||||
DECLARE vWarehouseFk INT;
|
||||
DECLARE vDated DATE;
|
||||
|
||||
SELECT warehouseFk, shipped
|
||||
INTO vWarehouseFk, vDated
|
||||
FROM ticket
|
||||
WHERE id = vSelf;
|
||||
|
||||
CALL buyUltimate(vWarehouseFk, vDated);
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
SELECT s.id saleFk , MOD(s.quantity, b.`grouping`) hasProblem
|
||||
FROM ticket t
|
||||
JOIN sale s ON s.ticketFk = tl.ticketFk
|
||||
JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
|
||||
JOIN buy b ON b.id = bu.buyFk
|
||||
WHERE t.id = vSelf;
|
||||
|
||||
CALL sale_setProblem('hasRounding');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.ticket;
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,24 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
PROCEDURE `vn`.`ticket_setProblemTaxDataChecked`(vClientFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Update the problem of tickets, depending on whether
|
||||
* the client taxDataCheched is verified or not
|
||||
*
|
||||
* @param vClientFk Id cliente, if NULL all clients
|
||||
*/
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
(INDEX(ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT t.id ticketFk, IF(c.isTaxDataChecked, FALSE, TRUE) hasProblem
|
||||
FROM ticket t
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
WHERE t.shipped >= util.midnight()
|
||||
AND (c.id = vClientFk OR vClientFk IS NULL);
|
||||
|
||||
CALL ticket_setProblem('isTaxDataChecked');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.ticket;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,20 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemTooLittle`(
|
||||
vSelf INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Update the problems when the ticket is too small or is no longer so
|
||||
*
|
||||
* @param vSelf Id del ticket
|
||||
*/
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
(INDEX(ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT vSelf ticketFk, ticket_isTooLittle(vSelf) hasProblem;
|
||||
|
||||
CALL ticket_setProblem('isTooLittle');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.ticket;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,29 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemTooLittleItemCost`(
|
||||
vItemFk INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Update the problems when the ticket is too small or is no longer so,
|
||||
* derived from changes in the itemCost table
|
||||
*
|
||||
* @param vItemFk Id del item, NULL ALL items
|
||||
*/
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
(INDEX(ticketFk))
|
||||
ENGINE = MEMORY
|
||||
WITH tickets AS(
|
||||
SELECT t.id ticketFk
|
||||
FROM vn.ticket t
|
||||
JOIN vn.sale s ON s.ticketFk = t.id
|
||||
WHERE t.shipped >= util.midnight()
|
||||
AND (s.itemFk = vItemFk OR vItemFk IS NULL)
|
||||
GROUP BY t.id
|
||||
)SELECT ticketFk, ticket_isTooLittle(ticketFk) hasProblem
|
||||
FROM tickets;
|
||||
|
||||
CALL ticket_setProblem('isTooLittle');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.ticket;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,87 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setRisk`(
|
||||
vClientFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Update the risk for a client with pending tickets
|
||||
*
|
||||
* @param vClientFk Id cliente
|
||||
*/
|
||||
DECLARE vHasDebt BOOL;
|
||||
|
||||
SELECT COUNT(*) INTO vHasDebt
|
||||
FROM `client`
|
||||
WHERE id = vClientFk
|
||||
AND typeFk = 'normal';
|
||||
|
||||
IF vHasDebt THEN
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tTicketRisk
|
||||
(KEY (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
WITH ticket AS(
|
||||
SELECT id ticketFk, companyFk, DATE(shipped) dated
|
||||
FROM vn.ticket t
|
||||
WHERE clientFk = vClientFk
|
||||
AND refFk IS NULL
|
||||
AND NOT isDeleted
|
||||
AND totalWithoutVat <> 0
|
||||
), dated AS(
|
||||
SELECT t.companyFk, MIN(DATE(t.dated) - INTERVAL cc.riskScope MONTH) started,
|
||||
MAX(DATE(t.dated)) ended
|
||||
FROM ticket t
|
||||
JOIN vn.clientConfig cc
|
||||
GROUP BY t.companyFk
|
||||
), balance AS(
|
||||
SELECT SUM(amount)amount, companyFk
|
||||
FROM (
|
||||
SELECT amount, companyFk
|
||||
FROM vn.clientRisk
|
||||
WHERE clientFk = vClientFk
|
||||
UNION ALL
|
||||
SELECT -(SUM(amount) / 100) amount, tm.companyFk
|
||||
FROM hedera.tpvTransaction t
|
||||
JOIN hedera.tpvMerchant tm ON t.id = t.merchantFk
|
||||
WHERE clientFk = vClientFk
|
||||
AND receiptFk IS NULL
|
||||
AND status = 'ok'
|
||||
) sub
|
||||
WHERE companyFk
|
||||
GROUP BY companyFk
|
||||
), uninvoiced AS(
|
||||
SELECT t.companyFk, DATE(t.shipped) dated, SUM(IFNULL(t.totalWithVat, 0)) amount
|
||||
FROM vn.ticket t
|
||||
JOIN dated d
|
||||
WHERE t.clientFk = vClientFk
|
||||
AND t.refFk IS NULL
|
||||
AND t.shipped BETWEEN d.started AND d.ended
|
||||
GROUP BY t.companyFk, DATE(t.shipped)
|
||||
), receipt AS(
|
||||
SELECT companyFk,DATE(payed) dated, SUM(amountPaid) amount
|
||||
FROM vn.receipt
|
||||
WHERE clientFk = vClientFk
|
||||
AND payed > util.VN_CURDATE()
|
||||
GROUP BY companyFk, DATE(payed)
|
||||
), risk AS(
|
||||
SELECT b.companyFk,
|
||||
ui.dated,
|
||||
SUM(ui.amount) OVER (PARTITION BY b.companyFk ORDER BY ui.dated ) +
|
||||
b.amount +
|
||||
SUM(IFNULL(r.amount, 0)) amount
|
||||
FROM balance b
|
||||
JOIN uninvoiced ui ON ui.companyFk = b.companyFk
|
||||
LEFT JOIN receipt r ON r.dated > ui.dated AND r.companyFk = ui.companyFk
|
||||
GROUP BY b.companyFk, ui.dated
|
||||
)
|
||||
SELECT ti.ticketFk, r.amount
|
||||
FROM ticket ti
|
||||
JOIN risk r ON r.dated = ti.dated AND r.companyFk = ti.companyFk;
|
||||
|
||||
UPDATE ticket t
|
||||
JOIN tTicketRisk tr ON tr.ticketFk = t.id
|
||||
SET t.risk = tr.amount;
|
||||
|
||||
DROP TEMPORARY TABLE tTicketRisk;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -28,5 +28,9 @@ mainLabel:BEGIN
|
|||
UPDATE `client` c
|
||||
SET c.salesPersonFk = null
|
||||
WHERE c.salesPersonFk = vUserId;
|
||||
|
||||
UPDATE locker l
|
||||
SET l.workerFk = NULL
|
||||
WHERE l.workerFk = vUserId;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_checkMultipleDevice`(
|
||||
vSelf INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Verify if a worker has multiple assigned devices,
|
||||
* except for freelancers.
|
||||
*
|
||||
* @param vUserFk worker id.
|
||||
*/
|
||||
DECLARE vHasPda BOOLEAN;
|
||||
DECLARE vIsFreelance BOOLEAN;
|
||||
DECLARE vMaxDevicesPerUser INT;
|
||||
|
||||
SELECT COUNT(*) INTO vHasPda FROM deviceProductionUser WHERE userFk = vSelf;
|
||||
SELECT IFNULL(isFreelance, FALSE) INTO vIsFreelance FROM worker WHERE id = vSelf;
|
||||
SELECT IFNULL(maxDevicesPerUser, FALSE) INTO vMaxDevicesPerUser FROM deviceProductionConfig LIMIT 1;
|
||||
|
||||
IF NOT vIsFreelance AND vHasPda > vMaxDevicesPerUser THEN
|
||||
CALL util.throw('You can only have one PDA');
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,5 +1,5 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_updateBalance`(vSelfFk INT(11), vCredit DECIMAL(10,2), vDebit DECIMAL(10,2))
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`worker_updateBalance`(vSelf INT(11), vCredit DECIMAL(10,2), vDebit DECIMAL(10,2))
|
||||
BEGIN
|
||||
/**
|
||||
* Actualiza la columna balance de worker.
|
||||
|
@ -8,6 +8,6 @@ BEGIN
|
|||
*/
|
||||
UPDATE worker
|
||||
SET balance = IFNULL(balance, 0) + IFNULL(vCredit, 0) - IFNULL(vDebit, 0)
|
||||
WHERE id = vSelfFk;
|
||||
WHERE id = vSelf;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -5,14 +5,17 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`country_afterInsert`
|
|||
BEGIN
|
||||
UPDATE sage.Naciones
|
||||
SET countryFk = NEW.id
|
||||
WHERE Nacion = NEW.country;
|
||||
WHERE Nacion = NEW.name;
|
||||
|
||||
IF ROW_COUNT() = 0 THEN
|
||||
CALL mail_insert(
|
||||
'cau@verdnatura.es',
|
||||
NULL,
|
||||
'Actualizar tabla sage.Naciones',
|
||||
CONCAT('Se ha insertado un nuevo país en la tabla vn.conuntry. Para el correcto funcionamiento del sistema \n\t\t\t\tde contabilidad es necesario actualizar la columna sage.Naciones.countryFk con el valor del nuevo país. \n\t\t\t Hay que buscar el nuevo país: ', NEW.country, ' en la tabla sage.Naciones y actualizar el campo sage.Naciones.countryFk con el valor ', NEW.id)
|
||||
CONCAT('Se ha insertado un nuevo país en la tabla vn.conuntry.
|
||||
Para el correcto funcionamiento del sistema \n\t\t\t\tde contabilidad es necesario actualizar la columna
|
||||
sage.Naciones.countryFk con el valor del nuevo país. \n\t\t\t Hay que buscar el nuevo país: ', NEW.name,
|
||||
' en la tabla sage.Naciones y actualizar el campo sage.Naciones.countryFk con el valor ', NEW.id)
|
||||
);
|
||||
END IF;
|
||||
END$$
|
||||
|
|
|
@ -3,8 +3,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`country_afterUpdate`
|
|||
AFTER UPDATE ON `country`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
IF !(OLD.country <=> NEW.country) THEN
|
||||
UPDATE zoneGeo SET `name` = NEW.country
|
||||
IF !(OLD.name <=> NEW.name) THEN
|
||||
UPDATE zoneGeo SET `name` = NEW.name
|
||||
WHERE id = NEW.geoFk;
|
||||
END IF;
|
||||
END$$
|
||||
|
|
|
@ -3,6 +3,6 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`country_beforeInsert`
|
|||
BEFORE INSERT ON `country`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
SET NEW.geoFk = zoneGeo_new('country', NEW.country, NULL);
|
||||
SET NEW.geoFk = zoneGeo_new('country', NEW.name, NULL);
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`deviceProductionUser_afterInsert`
|
||||
AFTER INSERT ON `deviceProductionUser`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
CALL worker_checkMultipleDevice(NEW.userFk);
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -3,6 +3,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`deviceProductionUser_
|
|||
BEFORE UPDATE ON `deviceProductionUser`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
|
||||
CALL worker_checkMultipleDevice(NEW.userFk);
|
||||
SET NEW.editorFk = account.myUser_getId();
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -3,92 +3,93 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`payment_beforeInsert`
|
|||
BEFORE INSERT ON `payment`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
DECLARE cuenta_banco,cuenta_proveedor DOUBLE;
|
||||
DECLARE vNewBookEntry INT;
|
||||
DECLARE bolCASH BOOLEAN;
|
||||
DECLARE isSupplierActive BOOLEAN;
|
||||
DECLARE vBankAccount DOUBLE;
|
||||
DECLARE vSupplierAccount DOUBLE;
|
||||
DECLARE vNewBookEntry INT;
|
||||
DECLARE vIsCash BOOLEAN;
|
||||
DECLARE vIsSupplierActive BOOLEAN;
|
||||
|
||||
-- PAK 10/02/15 No se asientan los pagos directamente, salvo en el caso de las cajas de CASH
|
||||
SELECT (at2.code = 'cash') INTO bolCASH
|
||||
FROM accounting a
|
||||
JOIN accountingType at2 ON at2.id = a.accountingTypeFk
|
||||
WHERE a.id = NEW.bankFk;
|
||||
-- PAK 10/02/15 No se asientan los pagos directamente, salvo en el caso de las cajas de CASH
|
||||
SELECT (at2.code = 'cash') INTO vIsCash
|
||||
FROM accounting a
|
||||
JOIN accountingType at2 ON at2.id = a.accountingTypeFk
|
||||
WHERE a.id = NEW.bankFk;
|
||||
|
||||
IF bolCASH THEN
|
||||
|
||||
SELECT account INTO cuenta_banco
|
||||
FROM accounting
|
||||
WHERE id = NEW.bankFk;
|
||||
|
||||
SELECT account INTO cuenta_proveedor
|
||||
FROM supplier
|
||||
WHERE id = NEW.supplierFk;
|
||||
IF vIsCash THEN
|
||||
SELECT account INTO vBankAccount
|
||||
FROM accounting
|
||||
WHERE id = NEW.bankFk;
|
||||
|
||||
CALL ledger_next(vNewBookEntry);
|
||||
|
||||
INSERT INTO XDiario ( ASIEN,
|
||||
FECHA,
|
||||
SUBCTA,
|
||||
CONTRA,
|
||||
CONCEPTO,
|
||||
EURODEBE,
|
||||
EUROHABER,
|
||||
empresa_id)
|
||||
SELECT vNewBookEntry,
|
||||
NEW.received,
|
||||
SUBCTA,
|
||||
CONTRA,
|
||||
NEW.concept,
|
||||
EURODEBE,
|
||||
EUROHABER,
|
||||
NEW.companyFk
|
||||
FROM ( SELECT cuenta_banco SUBCTA,
|
||||
cuenta_proveedor CONTRA,
|
||||
0 EURODEBE,
|
||||
NEW.amount + NEW.bankingFees EUROHABER
|
||||
UNION ALL
|
||||
SELECT cuenta_proveedor SUBCTA,
|
||||
cuenta_banco CONTRA,
|
||||
NEW.amount EURODEBE,
|
||||
0 EUROHABER) gf;
|
||||
|
||||
IF NEW.bankingFees <> 0 THEN
|
||||
INSERT INTO XDiario ( ASIEN,
|
||||
FECHA,
|
||||
SUBCTA,
|
||||
CONTRA,
|
||||
CONCEPTO,
|
||||
EURODEBE,
|
||||
EUROHABER,
|
||||
empresa_id)
|
||||
SELECT vNewBookEntry,
|
||||
NEW.received,
|
||||
IF(c.id = 1,6260000002,
|
||||
IF(CEE = 1,6260000003,6260000004)),
|
||||
cuenta_banco,
|
||||
NEW.concept,
|
||||
NEW.bankingFees,
|
||||
0,
|
||||
NEW.companyFk
|
||||
FROM supplier s
|
||||
JOIN country c ON s.countryFk = c.id
|
||||
WHERE s.id = NEW.supplierFk;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
SET NEW.dueDated = IFNULL(NEW.dueDated, NEW.received);
|
||||
|
||||
SELECT isActive INTO isSupplierActive
|
||||
SELECT account INTO vSupplierAccount
|
||||
FROM supplier
|
||||
WHERE id = NEW.supplierFk;
|
||||
|
||||
IF isSupplierActive = FALSE THEN
|
||||
CALL util.throw('SUPPLIER_INACTIVE');
|
||||
END IF;
|
||||
|
||||
IF ISNULL(NEW.workerFk) THEN
|
||||
SET NEW.workerFk = account.myUser_getId();
|
||||
END IF;
|
||||
|
||||
END$$
|
||||
|
||||
CALL ledger_next(YEAR(NEW.received), NEW.companyFk, vNewBookEntry);
|
||||
|
||||
INSERT INTO XDiario (
|
||||
ASIEN,
|
||||
FECHA,
|
||||
SUBCTA,
|
||||
CONTRA,
|
||||
CONCEPTO,
|
||||
EURODEBE,
|
||||
EUROHABER,
|
||||
empresa_id)
|
||||
SELECT vNewBookEntry,
|
||||
NEW.received,
|
||||
SUBCTA,
|
||||
CONTRA,
|
||||
NEW.concept,
|
||||
EURODEBE,
|
||||
EUROHABER,
|
||||
NEW.companyFk
|
||||
FROM (SELECT vBankAccount SUBCTA,
|
||||
vSupplierAccount CONTRA,
|
||||
0 EURODEBE,
|
||||
NEW.amount + NEW.bankingFees EUROHABER
|
||||
UNION ALL
|
||||
SELECT vSupplierAccount SUBCTA,
|
||||
vBankAccount CONTRA,
|
||||
NEW.amount EURODEBE,
|
||||
0 EUROHABER) gf;
|
||||
|
||||
IF NEW.bankingFees <> 0 THEN
|
||||
INSERT INTO XDiario (
|
||||
ASIEN,
|
||||
FECHA,
|
||||
SUBCTA,
|
||||
CONTRA,
|
||||
CONCEPTO,
|
||||
EURODEBE,
|
||||
EUROHABER,
|
||||
empresa_id)
|
||||
SELECT vNewBookEntry,
|
||||
NEW.received,
|
||||
IF(c.id = 1,6260000002,
|
||||
IF(CEE = 1,6260000003,6260000004)),
|
||||
vBankAccount,
|
||||
NEW.concept,
|
||||
NEW.bankingFees,
|
||||
0,
|
||||
NEW.companyFk
|
||||
FROM supplier s
|
||||
JOIN country c ON s.countryFk = c.id
|
||||
WHERE s.id = NEW.supplierFk;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
SET NEW.dueDated = IFNULL(NEW.dueDated, NEW.received);
|
||||
|
||||
SELECT isActive INTO vIsSupplierActive
|
||||
FROM supplier
|
||||
WHERE id = NEW.supplierFk;
|
||||
|
||||
IF vIsSupplierActive = FALSE THEN
|
||||
CALL util.throw('SUPPLIER_INACTIVE');
|
||||
END IF;
|
||||
|
||||
IF ISNULL(NEW.workerFk) THEN
|
||||
SET NEW.workerFk = account.myUser_getId();
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -18,11 +18,6 @@ BEGIN
|
|||
`changedModel` = 'TicketTracking',
|
||||
`changedModelId` = OLD.id,
|
||||
`userFk` = account.myUser_getId();
|
||||
|
||||
CALL util.debugAdd('deletedState',
|
||||
CONCAT('interFk: ', OLD.id,
|
||||
' ticketFk: ', OLD.ticketFk,
|
||||
' stateFk: ', OLD.stateFk));
|
||||
|
||||
SELECT i.ticketFk, i.id, s.`name`
|
||||
INTO vTicketFk, vTicketTrackingFk, vStateName
|
||||
|
|
|
@ -7,6 +7,8 @@ BEGIN
|
|||
UPDATE expedition
|
||||
SET hasNewRoute = TRUE
|
||||
WHERE ticketFk = NEW.id;
|
||||
|
||||
CALL ticket_doCmr(NEW.id);
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`exchangeReportSource`
|
||||
AS SELECT `e`.`dated` AS `dated`,
|
||||
cast(sum(`e`.`amountIn`) AS decimal(10, 2)) AS `amountIn`,
|
||||
cast(sum(`e`.`rateIn`) AS decimal(10, 4)) AS `rateIn`,
|
||||
cast(sum(`e`.`amountOut`) AS decimal(10, 2)) AS `amountOut`,
|
||||
cast(sum(`e`.`rateOut`) AS decimal(10, 4)) AS `rateOut`,
|
||||
cast(sum(`e`.`amountEntry`) AS decimal(10, 2)) AS `amountEntry`,
|
||||
cast(sum(`e`.`rateEntry`) AS decimal(10, 4)) AS `rateEntry`,
|
||||
cast(
|
||||
IFNULL(`rr`.`value`, `rrc`.`simulatedValue`) AS decimal(10, 4)
|
||||
) AS `rateECB`
|
||||
FROM (
|
||||
(
|
||||
`vn`.`exchangeReportSourcePrevious` `e`
|
||||
LEFT JOIN `vn`.`referenceRate` `rr` ON(`rr`.`dated` = `e`.`dated`)
|
||||
)
|
||||
JOIN `vn`.`referenceRateConfig` `rrc` ON(1)
|
||||
)
|
||||
GROUP BY `e`.`dated`
|
||||
ORDER BY `e`.`dated`
|
|
@ -1,29 +0,0 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`exchangeReportSourcePrevious`
|
||||
AS SELECT `exchangeInsuranceIn`.`dated` AS `dated`,
|
||||
`exchangeInsuranceIn`.`amount` AS `amountIn`,
|
||||
`exchangeInsuranceIn`.`rate` AS `rateIn`,
|
||||
0.00 AS `amountOut`,
|
||||
0.00 AS `rateOut`,
|
||||
0.00 AS `amountEntry`,
|
||||
0.00 AS `rateEntry`
|
||||
FROM `vn`.`exchangeInsuranceIn`
|
||||
UNION ALL
|
||||
SELECT `exchangeInsuranceOut`.`received` AS `received`,
|
||||
0.00 AS `amountIn`,
|
||||
0.00 AS `ratedIn`,
|
||||
`exchangeInsuranceOut`.`divisa` AS `amountOut`,
|
||||
`exchangeInsuranceOut`.`rate` AS `ratedOut`,
|
||||
0.00 AS `amountEntry`,
|
||||
0.00 AS `rateEntry`
|
||||
FROM `vn`.`exchangeInsuranceOut`
|
||||
UNION ALL
|
||||
SELECT `exchangeInsuranceEntry`.`dated` AS `dated`,
|
||||
0.00 AS `amountIn`,
|
||||
0.00 AS `ratedIn`,
|
||||
0.00 AS `amountOut`,
|
||||
0.00 AS `ratedOut`,
|
||||
`exchangeInsuranceEntry`.`Dolares` AS `amountEntry`,
|
||||
`exchangeInsuranceEntry`.`rate` AS `rateEntry`
|
||||
FROM `vn`.`exchangeInsuranceEntry`
|
|
@ -1,9 +1,9 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`expeditionCommon`
|
||||
AS SELECT `et`.`id` AS `truckFk`,
|
||||
`et`.`eta` AS `eta`,
|
||||
IFNULL(ucase(`et`.`description`), 'SIN ESCANEAR') AS `description`,
|
||||
AS SELECT `rs`.`id` AS `truckFk`,
|
||||
`rs`.`eta` AS `eta`,
|
||||
IFNULL(ucase(`rs`.`description`), 'SIN ESCANEAR') AS `description`,
|
||||
`es`.`palletFk` AS `palletFk`,
|
||||
`t`.`routeFk` AS `routeFk`,
|
||||
`es`.`id` AS `scanFk`,
|
||||
|
@ -17,8 +17,8 @@ FROM (
|
|||
(
|
||||
(
|
||||
(
|
||||
`vn`.`expeditionTruck` `et`
|
||||
LEFT JOIN `vn`.`routesMonitor` `r` ON(`et`.`id` = `r`.`expeditionTruckFk`)
|
||||
`vn`.`roadmapStop` `rs`
|
||||
LEFT JOIN `vn`.`routesMonitor` `r` ON(`rs`.`id` = `r`.`expeditionTruckFk`)
|
||||
)
|
||||
LEFT JOIN `vn`.`ticket` `t` ON(`r`.`routeFk` = `t`.`routeFk`)
|
||||
)
|
||||
|
@ -28,4 +28,4 @@ FROM (
|
|||
)
|
||||
LEFT JOIN `vn`.`expeditionPallet` `ep` ON(`es`.`palletFk` = `ep`.`id`)
|
||||
)
|
||||
WHERE `et`.`eta` >= `util`.`VN_CURDATE`()
|
||||
WHERE `rs`.`eta` >= `util`.`VN_CURDATE`()
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`expeditionPallet_Print`
|
||||
AS SELECT `et2`.`description` AS `truck`,
|
||||
AS SELECT `rs2`.`description` AS `truck`,
|
||||
`t`.`routeFk` AS `routeFk`,
|
||||
`r`.`description` AS `zone`,
|
||||
COUNT(`es`.`id`) AS `eti`,
|
||||
`ep`.`id` AS `palletFk`,
|
||||
`et`.`id` <=> `rm`.`expeditionTruckFk` AS `isMatch`,
|
||||
`rs`.`id` <=> `rm`.`expeditionTruckFk` AS `isMatch`,
|
||||
`t`.`warehouseFk` AS `warehouseFk`,
|
||||
IF(
|
||||
`r`.`created` > `util`.`VN_CURDATE`() + INTERVAL 1 DAY,
|
||||
|
@ -20,8 +20,8 @@ FROM (
|
|||
(
|
||||
(
|
||||
(
|
||||
`vn`.`expeditionTruck` `et`
|
||||
JOIN `vn`.`expeditionPallet` `ep` ON(`ep`.`truckFk` = `et`.`id`)
|
||||
`vn`.`roadmapStop` `rs`
|
||||
JOIN `vn`.`expeditionPallet` `ep` ON(`ep`.`truckFk` = `rs`.`id`)
|
||||
)
|
||||
JOIN `vn`.`expeditionScan` `es` ON(`es`.`palletFk` = `ep`.`id`)
|
||||
)
|
||||
|
@ -33,7 +33,7 @@ FROM (
|
|||
)
|
||||
LEFT JOIN `vn`.`routesMonitor` `rm` ON(`rm`.`routeFk` = `r`.`id`)
|
||||
)
|
||||
LEFT JOIN `vn`.`expeditionTruck` `et2` ON(`et2`.`id` = `rm`.`expeditionTruckFk`)
|
||||
LEFT JOIN `vn`.`roadmapStop` `rs2` ON(`rs2`.`id` = `rm`.`expeditionTruckFk`)
|
||||
)
|
||||
GROUP BY `ep`.`id`,
|
||||
`t`.`routeFk`
|
||||
|
|
|
@ -15,7 +15,7 @@ FROM (
|
|||
`vn`.`route` `r`
|
||||
LEFT JOIN `vn`.`routesMonitor` `rm` ON(`r`.`id` = `rm`.`routeFk`)
|
||||
)
|
||||
LEFT JOIN `vn`.`expeditionTruck` `et` ON(`et`.`id` = `rm`.`expeditionTruckFk`)
|
||||
LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `rm`.`expeditionTruckFk`)
|
||||
)
|
||||
JOIN `vn`.`ticket` `t` ON(`t`.`routeFk` = `r`.`id`)
|
||||
)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`expeditionScan_Monitor`
|
||||
AS SELECT `et`.`id` AS `truckFk`,
|
||||
`et`.`eta` AS `ETD`,
|
||||
`et`.`description` AS `description`,
|
||||
AS SELECT `rs`.`id` AS `truckFk`,
|
||||
`rs`.`eta` AS `ETD`,
|
||||
`rs`.`description` AS `description`,
|
||||
`ep`.`id` AS `palletFk`,
|
||||
`ep`.`position` AS `position`,
|
||||
`ep`.`built` AS `built`,
|
||||
|
@ -12,8 +12,8 @@ AS SELECT `et`.`id` AS `truckFk`,
|
|||
`es`.`scanned` AS `scanned`
|
||||
FROM (
|
||||
(
|
||||
`vn`.`expeditionTruck` `et`
|
||||
LEFT JOIN `vn`.`expeditionPallet` `ep` ON(`ep`.`truckFk` = `et`.`id`)
|
||||
`vn`.`roadmapStop` `rs`
|
||||
LEFT JOIN `vn`.`expeditionPallet` `ep` ON(`ep`.`truckFk` = `rs`.`id`)
|
||||
)
|
||||
LEFT JOIN `vn`.`expeditionScan` `es` ON(`es`.`palletFk` = `ep`.`id`)
|
||||
)
|
||||
|
|
|
@ -14,7 +14,7 @@ AS SELECT `e`.`id` AS `expeditionFk`,
|
|||
IF(
|
||||
`t`.`routeFk`,
|
||||
IFNULL(
|
||||
`et`.`description`,
|
||||
`rs`.`description`,
|
||||
REPLACE(`am`.`name`, 'ZONA ', 'Z')
|
||||
),
|
||||
`z`.`name`
|
||||
|
@ -45,7 +45,7 @@ FROM (
|
|||
)
|
||||
LEFT JOIN `vn`.`routesMonitor` `rm` ON(`rm`.`routeFk` = `t`.`routeFk`)
|
||||
)
|
||||
LEFT JOIN `vn`.`expeditionTruck` `et` ON(`et`.`id` = `rm`.`expeditionTruckFk`)
|
||||
LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `rm`.`expeditionTruckFk`)
|
||||
)
|
||||
LEFT JOIN `vn`.`beach` `b` ON(`b`.`code` = `rm`.`beachFk`)
|
||||
)
|
||||
|
|
|
@ -4,7 +4,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|||
AS SELECT `t`.`id` AS `ticketFk`,
|
||||
`t`.`warehouseFk` AS `warehouseFk`,
|
||||
`t`.`routeFk` AS `routeFk`,
|
||||
`et`.`description` AS `description`
|
||||
`rs`.`description` AS `description`
|
||||
FROM (
|
||||
(
|
||||
(
|
||||
|
@ -13,7 +13,7 @@ FROM (
|
|||
)
|
||||
JOIN `vn`.`routesMonitor` `rm` ON(`rm`.`routeFk` = `t`.`routeFk`)
|
||||
)
|
||||
JOIN `vn`.`expeditionTruck` `et` ON(`et`.`id` = `rm`.`expeditionTruckFk`)
|
||||
JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `rm`.`expeditionTruckFk`)
|
||||
)
|
||||
WHERE `e`.`id` IS NULL
|
||||
AND `et`.`eta` > `util`.`VN_CURDATE`()
|
||||
AND `rs`.`eta` > `util`.`VN_CURDATE`()
|
||||
|
|
|
@ -7,13 +7,13 @@ AS SELECT `e`.`truckFk` AS `id`,
|
|||
`e`.`palletFk` AS `pallet`,
|
||||
`e`.`routeFk` AS `route`,
|
||||
COUNT(DISTINCT `e`.`scanFk`) AS `scans`,
|
||||
`et`.`description` AS `destinos`,
|
||||
`rs`.`description` AS `destinos`,
|
||||
sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`,
|
||||
`e`.`expeditionTruckFk` AS `expeditionTruckFk`,
|
||||
max(`e`.`lastPacked`) AS `lastPacked`
|
||||
FROM (
|
||||
`vn`.`expeditionCommon` `e`
|
||||
LEFT JOIN `vn`.`expeditionTruck` `et` ON(`et`.`id` = `e`.`expeditionTruckFk`)
|
||||
LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `e`.`expeditionTruckFk`)
|
||||
)
|
||||
GROUP BY `e`.`truckFk`,
|
||||
`e`.`palletFk`,
|
||||
|
|
|
@ -6,8 +6,8 @@ AS SELECT `t`.`routeFk` AS `routeFk`,
|
|||
COUNT(`es`.`id`) AS `scanned`,
|
||||
COUNT(DISTINCT `es`.`palletFk`) AS `pallets`,
|
||||
max(`es`.`scanned`) AS `lastScanned`,
|
||||
max(`et`.`description`) AS `description`,
|
||||
max(`et`.`eta`) AS `eta`
|
||||
max(`rs`.`description`) AS `description`,
|
||||
max(`rs`.`eta`) AS `eta`
|
||||
FROM (
|
||||
(
|
||||
(
|
||||
|
@ -19,9 +19,9 @@ FROM (
|
|||
)
|
||||
LEFT JOIN `vn`.`expeditionPallet` `ep` ON(`ep`.`id` = `es`.`palletFk`)
|
||||
)
|
||||
LEFT JOIN `vn`.`expeditionTruck` `et` ON(`et`.`id` = `ep`.`truckFk`)
|
||||
LEFT JOIN `vn`.`roadmapStop` `rs` ON(`rs`.`id` = `ep`.`truckFk`)
|
||||
)
|
||||
WHERE `t`.`shipped` >= `util`.`VN_CURDATE`()
|
||||
AND `t`.`routeFk` <> 0
|
||||
GROUP BY `t`.`routeFk`
|
||||
ORDER BY max(`et`.`eta`)
|
||||
ORDER BY max(`rs`.`eta`)
|
||||
|
|
|
@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|||
VIEW `vn`.`saleVolume_Today_VNH`
|
||||
AS SELECT `t`.`nickname` AS `Cliente`,
|
||||
`p`.`name` AS `Provincia`,
|
||||
`c`.`country` AS `Pais`,
|
||||
`c`.`name` AS `Pais`,
|
||||
cast(sum(`sv`.`volume`) AS decimal(5, 1)) AS `volume`
|
||||
FROM (
|
||||
(
|
||||
|
|
|
@ -28,6 +28,5 @@ AS SELECT `c`.`id` AS `Id_Compra`,
|
|||
`c`.`workerFk` AS `Id_Trabajador`,
|
||||
`c`.`weight` AS `weight`,
|
||||
`c`.`dispatched` AS `dispatched`,
|
||||
`c`.`containerFk` AS `container_id`,
|
||||
`c`.`itemOriginalFk` AS `itemOriginalFk`
|
||||
FROM `vn`.`buy` `c`
|
||||
|
|
|
@ -2,7 +2,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost`
|
|||
SQL SECURITY DEFINER
|
||||
VIEW `vn2008`.`Paises`
|
||||
AS SELECT `c`.`id` AS `Id`,
|
||||
`c`.`country` AS `Pais`,
|
||||
`c`.`name` AS `Pais`,
|
||||
`c`.`CEE` AS `CEE`,
|
||||
`c`.`isUeeMember` AS `isUeeMember`,
|
||||
`c`.`code` AS `Codigo`,
|
||||
|
|
|
@ -6,7 +6,6 @@ AS SELECT `s`.`id` AS `Id_Proveedor`,
|
|||
`s`.`account` AS `cuenta`,
|
||||
`s`.`countryFk` AS `pais_id`,
|
||||
`s`.`nif` AS `NIF`,
|
||||
`s`.`isFarmer` AS `Agricola`,
|
||||
`s`.`phone` AS `Telefono`,
|
||||
`s`.`retAccount` AS `cuentaret`,
|
||||
`s`.`commission` AS `ComisionProveedor`,
|
||||
|
|
|
@ -14,6 +14,5 @@ AS SELECT `dn`.`id` AS `albaran_id`,
|
|||
`dn`.`workerFk` AS `Id_Trabajador`,
|
||||
`dn`.`supervisorFk` AS `Id_Responsable`,
|
||||
`dn`.`departmentFk` AS `department_id`,
|
||||
`dn`.`invoiceInFk` AS `recibida_id`,
|
||||
`dn`.`farmingFk` AS `farmingFk`
|
||||
`dn`.`invoiceInFk` AS `recibida_id`
|
||||
FROM `vn`.`deliveryNote` `dn`
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue