Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 6861-Pasar-modo-trabajo-de-previa-a-reservas
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
commit
64f71e0f9d
|
@ -1,3 +1,4 @@
|
|||
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
|
11
README.md
11
README.md
|
@ -11,11 +11,16 @@ Required applications.
|
|||
* Node.js
|
||||
* Docker
|
||||
* Git
|
||||
* MYT
|
||||
|
||||
You will need to install globally the following items.
|
||||
```
|
||||
$ sudo npm install -g jest gulp-cli
|
||||
```
|
||||
After installing MYT you will need the following item.
|
||||
```
|
||||
$ apt install libkrb5-dev libssl-dev
|
||||
```
|
||||
|
||||
## Installing dependencies and launching
|
||||
|
||||
|
@ -54,6 +59,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.
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
const isProduction = require('vn-loopback/server/boot/isProduction');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('sendCheckingPresence', {
|
||||
description: 'Creates a message in the chat model checking the user status',
|
||||
|
@ -37,7 +39,7 @@ module.exports = Self => {
|
|||
if (!recipient)
|
||||
throw new Error(`Could not send message "${message}" to worker id ${recipientId} from user ${userId}`);
|
||||
|
||||
if (process.env.NODE_ENV == 'test')
|
||||
if (!isProduction())
|
||||
message = `[Test:Environment to user ${userId}] ` + message;
|
||||
|
||||
const chat = await models.Chat.create({
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
const axios = require('axios');
|
||||
const isProduction = require('vn-loopback/server/boot/isProduction');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('sendQueued', {
|
||||
description: 'Send a RocketChat message',
|
||||
|
@ -94,7 +96,7 @@ module.exports = Self => {
|
|||
* @return {Promise} - The request promise
|
||||
*/
|
||||
Self.sendMessage = async function sendMessage(senderFk, recipient, message) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (!isProduction(false)) {
|
||||
return new Promise(resolve => {
|
||||
return resolve({
|
||||
statusCode: 200,
|
||||
|
@ -149,7 +151,7 @@ module.exports = Self => {
|
|||
* @return {Promise} - The request promise
|
||||
*/
|
||||
Self.getUserStatus = async function getUserStatus(username) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (!isProduction(false)) {
|
||||
return new Promise(resolve => {
|
||||
return resolve({
|
||||
data: {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const isProduction = require('vn-loopback/server/boot/isProduction');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('deleteTrashFiles', {
|
||||
|
@ -22,7 +23,7 @@ module.exports = Self => {
|
|||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (process.env.NODE_ENV == 'test')
|
||||
if (!isProduction())
|
||||
throw new UserError(`Action not allowed on the test environment`);
|
||||
|
||||
const models = Self.app.models;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
const axios = require('axios');
|
||||
const isProduction = require('vn-loopback/server/boot/isProduction');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('upload', {
|
||||
|
@ -119,7 +120,7 @@ module.exports = Self => {
|
|||
]
|
||||
};
|
||||
|
||||
if (process.env.NODE_ENV != 'production')
|
||||
if (!isProduction(false))
|
||||
throw new UserError('Action not allowed on the test environment');
|
||||
|
||||
// delete old
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const UserError = require('vn-loopback/util/user-error');
|
||||
const isProduction = require('vn-loopback/server/boot/isProduction');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('scrub', {
|
||||
|
@ -43,8 +44,7 @@ module.exports = Self => {
|
|||
Self.scrub = async function(collection, remove, limit, dryRun, skipLock) {
|
||||
const $ = Self.app.models;
|
||||
|
||||
const env = process.env.NODE_ENV;
|
||||
dryRun = dryRun || (env && env !== 'production');
|
||||
dryRun = dryRun || !isProduction(false);
|
||||
|
||||
const instance = await $.ImageCollection.findOne({
|
||||
fields: ['id'],
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
const fs = require('fs/promises');
|
||||
const path = require('path');
|
||||
const isProduction = require('vn-loopback/server/boot/isProduction');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('upload', {
|
||||
|
@ -41,7 +42,7 @@ module.exports = Self => {
|
|||
if (!hasWriteRole)
|
||||
throw new UserError(`You don't have enough privileges`);
|
||||
|
||||
if (process.env.NODE_ENV == 'test')
|
||||
if (!isProduction())
|
||||
throw new UserError(`Action not allowed on the test environment`);
|
||||
|
||||
// Upload file to temporary path
|
||||
|
|
|
@ -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() => {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const {Email} = require('vn-print');
|
||||
const isProduction = require('vn-loopback/server/boot/isProduction');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('send', {
|
||||
|
@ -70,7 +71,7 @@ module.exports = Self => {
|
|||
const newParams = Object.assign({}, queueParams, sendParams);
|
||||
const email = new Email(queueName, newParams);
|
||||
|
||||
if (process.env.NODE_ENV != 'test')
|
||||
if (isProduction())
|
||||
await email.send();
|
||||
|
||||
await queue.updateAttribute('status', statusSent);
|
||||
|
|
|
@ -186,5 +186,8 @@
|
|||
},
|
||||
"AgencyWorkCenter": {
|
||||
"dataSource": "vn"
|
||||
},
|
||||
"RouteConfig": {
|
||||
"dataSource": "vn"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "RouteConfig",
|
||||
"base": "VnModel",
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "routeConfig"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "number",
|
||||
"description": "Identifier"
|
||||
},
|
||||
"kmMax": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1205,11 +1205,11 @@ INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`)
|
|||
(32, 36, -92.324),
|
||||
(32, 39, 0.994);
|
||||
|
||||
INSERT INTO `vn`.`itemShelving` (`itemFk`, `shelvingFk`, `visible`, `grouping`, `packing`, `userFk`)
|
||||
INSERT INTO `vn`.`itemShelving` (`itemFk`, `shelvingFk`, `visible`, `grouping`, `packing`,`buyFk`, `userFk`)
|
||||
VALUES
|
||||
(2, 'GVC', 1, 1, 1, 1106),
|
||||
(4, 'HEJ', 1, 1, 1, 1106),
|
||||
(1, 'UXN', 2, 12, 12, 1106);
|
||||
(2, 'GVC', 1, 1, 1, 2,1106),
|
||||
(4, 'HEJ', 1, 1, 1, NULL,1106),
|
||||
(1, 'UXN', 2, 12, 12, NULL,1106);
|
||||
|
||||
INSERT INTO `vn`.`itemShelvingSale` (`itemShelvingFk`, `saleFk`, `quantity`, `created`, `userFk`)
|
||||
VALUES
|
||||
|
@ -2549,18 +2549,18 @@ INSERT INTO `vn`.`duaEntry` (`duaFk`, `entryFk`, `value`, `customsValue`, `euroV
|
|||
(7, 7, 1.00, 1.00, 1.00),
|
||||
(8, 8, 1.00, 1.00, 1.00);
|
||||
|
||||
REPLACE INTO `vn`.`invoiceIn`(`id`, `serialNumber`,`serial`, `supplierFk`, `issued`, `created`, `supplierRef`, `isBooked`, `companyFk`, `docFk`)
|
||||
REPLACE INTO `vn`.`invoiceIn`(`id`, `serialNumber`,`serial`, `supplierFk`, `issued`, `created`, `supplierRef`, `isBooked`, `companyFk`, `docFk`, `bookEntried`)
|
||||
VALUES
|
||||
(1, 1001, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1234, 0, 442, 1),
|
||||
(2, 1002, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1235, 0, 442, 1),
|
||||
(3, 1003, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1236, 0, 442, 1),
|
||||
(4, 1004, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1237, 0, 442, 1),
|
||||
(5, 1005, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1238, 0, 442, 1),
|
||||
(6, 1006, 'R', 2, util.VN_CURDATE(), util.VN_CURDATE(), 1239, 0, 442, 1),
|
||||
(7, 1007, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1240, 0, 442, 1),
|
||||
(8, 1008, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1241, 0, 442, 1),
|
||||
(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);
|
||||
(1, 1001, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1234, 0, 442, 1,util.VN_CURDATE()),
|
||||
(2, 1002, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1235, 0, 442, 1,util.VN_CURDATE()),
|
||||
(3, 1003, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1236, 0, 442, 1,util.VN_CURDATE()),
|
||||
(4, 1004, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1237, 0, 442, 1,util.VN_CURDATE()),
|
||||
(5, 1005, 'R', 1, util.VN_CURDATE(), util.VN_CURDATE(), 1238, 0, 442, 1,util.VN_CURDATE()),
|
||||
(6, 1006, 'R', 2, util.VN_CURDATE(), util.VN_CURDATE(), 1239, 0, 442, 1,util.VN_CURDATE()),
|
||||
(7, 1007, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1240, 0, 442, 1,util.VN_CURDATE()),
|
||||
(8, 1008, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1241, 0, 442, 1,util.VN_CURDATE()),
|
||||
(9, 1009, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1242, 0, 442, 1,util.VN_CURDATE()),
|
||||
(10, 1010, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1243, 0, 442, 1,util.VN_CURDATE());
|
||||
|
||||
INSERT INTO `vn`.`invoiceInConfig` (`id`, `retentionRate`, `retentionName`, `sageFarmerWithholdingFk`, `daysAgo`)
|
||||
VALUES
|
||||
|
@ -3792,3 +3792,10 @@ INSERT INTO vn.workCenter (id, name, payrollCenterFk, counter, warehouseFk, stre
|
|||
VALUES(100, 'workCenterOne', 1, NULL, 1, 'gotham', NULL, NULL);
|
||||
|
||||
UPDATE vn.locker SET workerFk = 1110 WHERE id = 147;
|
||||
|
||||
INSERT INTO `vn`.`ledgerCompany` SET
|
||||
fiscalYear = YEAR(util.VN_CURDATE()),
|
||||
bookEntry = 2;
|
||||
|
||||
INSERT INTO `vn`.`ledgerConfig` SET
|
||||
maxTolerance = 0.01;
|
||||
|
|
|
@ -23,22 +23,19 @@ BEGIN
|
|||
DECLARE vXtraLongAgj INT;
|
||||
DECLARE vDefaultKlo INT;
|
||||
|
||||
SELECT
|
||||
ec.usefulAuctionLeftSegmentLength,
|
||||
ec.standardBarcodeLength,
|
||||
ec.floridayBarcodeLength,
|
||||
ec.floramondoBarcodeLength,
|
||||
ec.defaultKlo
|
||||
INTO
|
||||
vUsefulAuctionLeftSegmentLength,
|
||||
SELECT usefulAuctionLeftSegmentLength,
|
||||
standardBarcodeLength,
|
||||
floridayBarcodeLength,
|
||||
floramondoBarcodeLength,
|
||||
defaultKlo
|
||||
INTO vUsefulAuctionLeftSegmentLength,
|
||||
vStandardBarcodeLength,
|
||||
vFloridayBarcodeLength,
|
||||
vFloramondoBarcodeLength,
|
||||
vDefaultKlo
|
||||
FROM edi.ektConfig ec;
|
||||
FROM ektConfig;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ekt;
|
||||
CREATE TEMPORARY TABLE tmp.ekt
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ekt
|
||||
ENGINE = MEMORY
|
||||
SELECT id ektFk FROM ekt LIMIT 0;
|
||||
|
||||
|
@ -46,19 +43,19 @@ BEGIN
|
|||
WHEN LENGTH(vBarcode) <= vFloridayBarcodeLength THEN
|
||||
INSERT INTO tmp.ekt
|
||||
SELECT id
|
||||
FROM edi.ektRecent e
|
||||
FROM ektRecent e
|
||||
WHERE e.cps = vBarcode
|
||||
OR e.batchNumber = vBarcode;
|
||||
|
||||
WHEN LENGTH(vBarcode) = vFloramondoBarcodeLength THEN
|
||||
INSERT INTO tmp.ekt
|
||||
SELECT e.id
|
||||
FROM edi.ektRecent e
|
||||
FROM ektRecent e
|
||||
WHERE e.pro = MID(vBarcode,2,6)
|
||||
AND CAST(e.ptd AS SIGNED) = MID(vBarcode,8,5);
|
||||
AND CAST(e.ptd AS SIGNED) = MID(vBarcode, 8, 5);
|
||||
|
||||
ELSE
|
||||
SET vBarcode = LPAD(vBarcode,vStandardBarcodeLength,'0');
|
||||
SET vBarcode = LPAD(vBarcode, vStandardBarcodeLength, '0');
|
||||
SET vAuction = MID(vBarcode, 1, 3);
|
||||
SET vKlo = MID(vBarcode, 4, 2);
|
||||
SET vFec = MAKEDATE(YEAR(util.VN_CURDATE()), MID(vBarcode, 6, 3));
|
||||
|
@ -74,16 +71,18 @@ BEGIN
|
|||
SELECT id
|
||||
FROM ekt
|
||||
WHERE fec >= vFec - INTERVAL 1 DAY
|
||||
AND ((
|
||||
vKlo = vDefaultKlo
|
||||
AND (
|
||||
(vKlo = vDefaultKlo
|
||||
AND (klo = vKlo OR klo IS NULL OR klo = 0)
|
||||
AND agj IN (vShortAgj, vLongAgj, vXtraLongAgj))
|
||||
OR (klo = vKlo
|
||||
AND agj IN (vShortAgj, vLongAgj, vXtraLongAgj)
|
||||
) OR (
|
||||
klo = vKlo
|
||||
AND auction = vAuction
|
||||
AND agj = vShortAgj)
|
||||
AND agj = vShortAgj
|
||||
)
|
||||
)
|
||||
ORDER BY agj DESC, fec DESC
|
||||
LIMIT 1;
|
||||
ORDER BY agj DESC, fec DESC
|
||||
LIMIT 1;
|
||||
|
||||
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
|
||||
|
||||
|
@ -91,9 +90,11 @@ BEGIN
|
|||
IF NOT vIsFound THEN
|
||||
INSERT INTO tmp.ekt
|
||||
SELECT id
|
||||
FROM edi.ektRecent e
|
||||
WHERE e.batchNumber
|
||||
= LEFT(vBarcode,vUsefulAuctionLeftSegmentLength)
|
||||
FROM ektRecent e
|
||||
WHERE e.batchNumber = LEFT(
|
||||
vBarcode,
|
||||
vUsefulAuctionLeftSegmentLength
|
||||
)
|
||||
AND e.batchNumber > 0;
|
||||
|
||||
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
|
||||
|
@ -103,7 +104,7 @@ BEGIN
|
|||
IF NOT vIsFound THEN
|
||||
INSERT INTO tmp.ekt
|
||||
SELECT id
|
||||
FROM edi.ektRecent e
|
||||
FROM ektRecent e
|
||||
WHERE e.putOrderFk = vBarcode;
|
||||
|
||||
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
|
||||
|
@ -113,18 +114,28 @@ BEGIN
|
|||
IF NOT vIsFound THEN
|
||||
INSERT INTO tmp.ekt
|
||||
SELECT id
|
||||
FROM edi.ektRecent e
|
||||
WHERE e.deliveryNumber
|
||||
= MID(vBarcode, 4, 13)
|
||||
FROM ektRecent e
|
||||
WHERE e.deliveryNumber = MID(vBarcode, 4, 13)
|
||||
AND e.deliveryNumber > 0;
|
||||
|
||||
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
|
||||
END IF;
|
||||
|
||||
-- Solo campo agj
|
||||
IF NOT vIsFound THEN
|
||||
INSERT INTO tmp.ekt
|
||||
SELECT id
|
||||
FROM ektRecent
|
||||
WHERE agj = vShortAgj;
|
||||
|
||||
SELECT COUNT(*) FROM tmp.ekt INTO vIsFound;
|
||||
END IF;
|
||||
|
||||
END CASE;
|
||||
|
||||
IF vIsFound THEN
|
||||
UPDATE ekt e
|
||||
JOIN tmp.ekt t ON t.ektFk = e.id
|
||||
JOIN tmp.ekt t ON t.ektFk = e.id
|
||||
SET e.scanned = TRUE;
|
||||
END IF;
|
||||
END$$
|
||||
|
|
|
@ -40,18 +40,25 @@ proc:BEGIN
|
|||
postalCode,
|
||||
`type`,
|
||||
image,
|
||||
description
|
||||
description,
|
||||
addressFk
|
||||
)
|
||||
SELECT i.name,
|
||||
i.`size`,
|
||||
SELECT CONCAT(i.name, ' by ',a.nickname),
|
||||
i.minPrice + apc.deliveryCost,
|
||||
i.id,
|
||||
vLanded,
|
||||
vPostalCode,
|
||||
it.name,
|
||||
CONCAT('https://cdn.verdnatura.es/image/catalog/1600x900/', i.image),
|
||||
i.description
|
||||
i.description,
|
||||
apc.addressFk
|
||||
FROM vn.item i
|
||||
JOIN vn.itemType it ON it.id = i.typeFk
|
||||
JOIN addressPostCode apc
|
||||
ON apc.dayOfWeek = dayOfWeek(vLanded)
|
||||
AND NOW() < vLanded - INTERVAL apc.hoursInAdvance HOUR
|
||||
AND apc.postCode = vPostalCode
|
||||
JOIN vn.address a ON a.id = apc.addressFk
|
||||
WHERE it.code IN ('FNR','FNP');
|
||||
|
||||
SELECT *
|
||||
|
|
|
@ -13,8 +13,17 @@ BEGIN
|
|||
/**
|
||||
* Set actions for contact request
|
||||
*
|
||||
* @param vPostalCode Delivery address postal code
|
||||
* @param vName Name
|
||||
* @param vPhone Phone number
|
||||
* @param vEmail e-mail
|
||||
* @param vMessage text of the message
|
||||
*/
|
||||
|
||||
CALL vn.mail_insert(
|
||||
'floranet@verdnatura.es',
|
||||
vEmail,
|
||||
'Contact request',
|
||||
CONCAT('Phone: ',vPhone, ' Message: ', vMessage)
|
||||
);
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -21,7 +21,7 @@ BEGIN
|
|||
apc.dayOfWeek - vCurrentDayOfWeek,
|
||||
7 - apc.dayOfWeek
|
||||
) DAY nextDay,
|
||||
NOW() + INTERVAL apc.hoursInAdvance - 12 HOUR minDeliveryTime
|
||||
NOW() + INTERVAL apc.hoursInAdvance HOUR minDeliveryTime
|
||||
FROM addressPostCode apc
|
||||
WHERE apc.postCode = vPostalCode
|
||||
HAVING nextDay > minDeliveryTime) sub;
|
||||
|
|
|
@ -1,24 +1,127 @@
|
|||
DROP PROCEDURE IF EXISTS floranet.order_confirm;
|
||||
|
||||
DELIMITER $$
|
||||
$$
|
||||
|
||||
CREATE DEFINER=`root`@`localhost`PROCEDURE floranet.order_confirm(vCatalogueFk INT)
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost`PROCEDURE floranet.order_confirm(vCatalogueFk INT)
|
||||
READS SQL DATA
|
||||
|
||||
BEGIN
|
||||
/** Update order.isPaid field.
|
||||
proc:BEGIN
|
||||
/** Update order.isPaid field, and makes the ticket
|
||||
*
|
||||
* @param vCatalogueFk floranet.catalogue.id
|
||||
*
|
||||
* @returns floranet.order.isPaid
|
||||
*/
|
||||
DECLARE vNewTicketFk INT;
|
||||
DECLARE vCustomerEmail VARCHAR(255);
|
||||
DECLARE vFloranetEmail VARCHAR(255);
|
||||
DECLARE vSubjectEmail VARCHAR(100);
|
||||
DECLARE vBodyEmail TEXT;
|
||||
DECLARE vZoneFk INT;
|
||||
|
||||
IF (SELECT isPaid FROM `order` WHERE catalogueFk = vCatalogueFk) THEN
|
||||
CALL util.throw('Esta orden ya está confirmada');
|
||||
END IF;
|
||||
|
||||
UPDATE `order`
|
||||
SET isPaid = TRUE,
|
||||
payed = NOW()
|
||||
WHERE catalogueFk = vCatalogueFk;
|
||||
|
||||
SELECT isPaid
|
||||
SELECT zoneFk
|
||||
INTO vZoneFk
|
||||
FROM (
|
||||
SELECT zoneFk, COUNT(*) totalCount
|
||||
FROM vn.ticket t
|
||||
JOIN catalogue c ON c.id = vCatalogueFk
|
||||
WHERE t.shipped > util.VN_CURDATE() - INTERVAL 1 YEAR
|
||||
AND t.addressFk = c.addressFk
|
||||
GROUP BY zoneFk
|
||||
ORDER BY totalCount DESC
|
||||
LIMIT 10000000000000000000
|
||||
) sub
|
||||
LIMIT 1;
|
||||
|
||||
INSERT INTO vn.ticket (
|
||||
clientFk,
|
||||
shipped,
|
||||
addressFk,
|
||||
agencyModeFk,
|
||||
nickname,
|
||||
warehouseFk,
|
||||
routeFk,
|
||||
companyFk,
|
||||
landed,
|
||||
zoneFk
|
||||
)
|
||||
SELECT a.clientFk,
|
||||
c.dated - INTERVAL 1 DAY,
|
||||
c.addressFk,
|
||||
a.agencyModeFk,
|
||||
a.nickname,
|
||||
ag.warehouseFk,
|
||||
NULL,
|
||||
co.id,
|
||||
c.dated,
|
||||
vZoneFk
|
||||
FROM vn.address a
|
||||
JOIN vn.agencyMode am ON am.id = a.agencyModeFk
|
||||
JOIN vn.agency ag ON ag.id = am.agencyFk
|
||||
JOIN catalogue c ON c.addressFk = a.id
|
||||
JOIN vn.company co ON co.code = 'VNL'
|
||||
WHERE c.id = vCatalogueFk;
|
||||
|
||||
SET vNewTicketFk = LAST_INSERT_ID();
|
||||
|
||||
INSERT INTO vn.sale(
|
||||
ticketFk,
|
||||
itemFk,
|
||||
concept,
|
||||
price,
|
||||
quantity)
|
||||
SELECT
|
||||
vNewTicketFk,
|
||||
c.itemFk,
|
||||
CONCAT('Entrega: ',c.name),
|
||||
- c.price,
|
||||
1
|
||||
FROM catalogue c
|
||||
JOIN addressPostCode apc
|
||||
ON apc.addressFk = c.addressFk
|
||||
AND apc.dayOfWeek = dayOfWeek(c.dated)
|
||||
WHERE c.id = vCatalogueFk;
|
||||
|
||||
SELECT cl.email,
|
||||
cf.email,
|
||||
CONCAT('Nuevo pedido FLORANET para entrega el ',c.dated),
|
||||
CONCAT_WS('\n',
|
||||
CONCAT('Producto: ', c.name),
|
||||
CONCAT('Fecha de entrega: ',c.dated),
|
||||
CONCAT('Destinatario: ', o.deliveryName),
|
||||
CONCAT('Dirección: ', o.address),
|
||||
CONCAT('CP: ', c.postalCode),
|
||||
CONCAT('Foto: ', c.image),
|
||||
CONCAT('Mensaje: ', IFNULL(o.message,"Ninguno.")),
|
||||
CONCAT('Teléfono: ',IFNULL(o.deliveryPhone,"--")),
|
||||
CONCAT('Observaciones: ', IFNULL(o.observations,"No hay."))
|
||||
)
|
||||
INTO vCustomerEmail,
|
||||
vFloranetEmail,
|
||||
vSubjectEmail,
|
||||
vBodyEmail
|
||||
FROM vn.client cl
|
||||
JOIN vn.address a ON a.clientFk = cl.id
|
||||
JOIN catalogue c ON c.addressFk = a.id
|
||||
JOIN `order` o ON o.catalogueFk = c.id
|
||||
JOIN config cf
|
||||
WHERE c.id = vCatalogueFk;
|
||||
|
||||
CALL vn.mail_insert(
|
||||
vCustomerEmail,
|
||||
vFloranetEmail,
|
||||
vSubjectEmail,
|
||||
vBodyEmail);
|
||||
|
||||
SELECT isPaid, vNewTicketFk
|
||||
FROM `order`
|
||||
WHERE catalogueFk = vCatalogueFk;
|
||||
END$$
|
||||
|
|
|
@ -7,7 +7,7 @@ BEGIN
|
|||
*
|
||||
* @param vJsonData The order data in json format
|
||||
*/
|
||||
INSERT INTO `order`
|
||||
REPLACE `order`
|
||||
SET catalogueFk = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.products[0].id')),
|
||||
customerName = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.customerName')),
|
||||
email = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.email')),
|
||||
|
@ -15,7 +15,8 @@ BEGIN
|
|||
message= JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.message')),
|
||||
deliveryName = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.deliveryName')),
|
||||
address = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.address')),
|
||||
deliveryPhone = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.deliveryPhone'));
|
||||
deliveryPhone = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.deliveryPhone')),
|
||||
observations = JSON_UNQUOTE(JSON_EXTRACT(vJsonData, '$.customer.customerData.observations'));
|
||||
|
||||
SELECT LAST_INSERT_ID() orderFk;
|
||||
END$$
|
||||
|
|
|
@ -9,12 +9,11 @@ BEGIN
|
|||
* Returns list of url for sliders.
|
||||
*/
|
||||
SELECT
|
||||
CONCAT('https://cdn.verdnatura.es/image/catalog/1600x900/', i.image) url,
|
||||
i.longName
|
||||
FROM vn.item i
|
||||
JOIN vn.itemType it ON it.id = i.typeFk
|
||||
WHERE it.code IN ('FNR','FNP')
|
||||
LIMIT 3;
|
||||
|
||||
CONCAT('https://cdn.verdnatura.es/image/catalog/1600x900/', i.image) url,
|
||||
i.longName
|
||||
FROM vn.item i
|
||||
JOIN vn.itemType it ON it.id = i.typeFk
|
||||
WHERE it.code IN ('FNR','FNP')
|
||||
LIMIT 3;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -81,7 +81,7 @@ BEGIN
|
|||
|
||||
-- Código redundante
|
||||
|
||||
DO vn.till_new(
|
||||
CALL vn.till_new(
|
||||
vCustomer
|
||||
,vBank
|
||||
,vAmount / 100
|
||||
|
|
|
@ -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 ;
|
|
@ -1,79 +1,73 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`till_new`(vClient INT
|
||||
,vBank INT
|
||||
,vAmount DOUBLE
|
||||
,vConcept VARCHAR(25)
|
||||
,vDated DATE
|
||||
,vSerie CHAR(1)
|
||||
,vBatch TINYINT
|
||||
,vNumber INT
|
||||
,vCompany SMALLINT
|
||||
,vWorker INT
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`till_new`(
|
||||
vClient INT,
|
||||
vBank INT,
|
||||
vAmount DOUBLE,
|
||||
vConcept VARCHAR(25),
|
||||
vDated DATE,
|
||||
vSerie CHAR(1),
|
||||
vBatch TINYINT,
|
||||
vNumber INT,
|
||||
vCompany SMALLINT,
|
||||
vWorker INT
|
||||
)
|
||||
RETURNS int(11)
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
DECLARE vAccount VARCHAR(12);
|
||||
DECLARE vSubaccount VARCHAR(12);
|
||||
DECLARE vAsiento INT DEFAULT NULL;
|
||||
|
||||
-- Inserta el registro en cajas
|
||||
|
||||
INSERT INTO till
|
||||
SET
|
||||
workerFk = vWorker
|
||||
,bankFk = vBank
|
||||
,`in` = vAmount
|
||||
,concept = vConcept
|
||||
,dated = vDated
|
||||
,serie = vSerie
|
||||
,isAccountable = vBatch
|
||||
,`number` = vNumber
|
||||
,companyFk = vCompany;
|
||||
workerFk = vWorker,
|
||||
bankFk = vBank,
|
||||
`in` = vAmount,
|
||||
concept = vConcept,
|
||||
dated = vDated,
|
||||
serie = vSerie,
|
||||
isAccountable = vBatch,
|
||||
`number` = vNumber,
|
||||
companyFk = vCompany;
|
||||
|
||||
-- Inserta los asientos contables
|
||||
|
||||
SELECT account INTO vAccount
|
||||
FROM accounting WHERE id = vBank;
|
||||
|
||||
SELECT accountingAccount INTO vSubaccount
|
||||
FROM `client` WHERE id = vClient;
|
||||
|
||||
SET vAsiento = xdiario_new
|
||||
(
|
||||
vAsiento
|
||||
,vDated
|
||||
,vAccount
|
||||
,vSubaccount
|
||||
,vConcept
|
||||
,vAmount
|
||||
,0
|
||||
,0
|
||||
,NULL -- Serie
|
||||
,NULL -- Factura
|
||||
,NULL -- IVA
|
||||
,NULL -- Recargo
|
||||
,FALSE -- Auxiliar
|
||||
,vCompany
|
||||
);
|
||||
DO xdiario_new
|
||||
(
|
||||
vAsiento
|
||||
,vDated
|
||||
,vSubaccount
|
||||
,vAccount
|
||||
,vConcept
|
||||
,0
|
||||
,vAmount
|
||||
,0
|
||||
,NULL -- Serie
|
||||
,NULL -- Factura
|
||||
,NULL -- IVA
|
||||
,NULL -- Recargo
|
||||
,FALSE -- Auxiliar
|
||||
,vCompany
|
||||
);
|
||||
CALL xdiario_new(
|
||||
vAsiento,
|
||||
vDated,
|
||||
vAccount,
|
||||
vSubaccount,
|
||||
vConcept,
|
||||
vAmount,
|
||||
0,
|
||||
0,
|
||||
NULL, -- Serie
|
||||
NULL, -- Factura
|
||||
NULL, -- IVA
|
||||
NULL, -- Recargo
|
||||
FALSE, -- Auxiliar
|
||||
vCompany,
|
||||
vAsiento);
|
||||
|
||||
RETURN NULL;
|
||||
CALL xdiario_new(
|
||||
vAsiento,
|
||||
vDated,
|
||||
vSubaccount,
|
||||
vAccount,
|
||||
vConcept,
|
||||
0,
|
||||
vAmount,
|
||||
0,
|
||||
NULL, -- Serie
|
||||
NULL, -- Factura
|
||||
NULL, -- IVA
|
||||
NULL, -- Recargo
|
||||
FALSE, -- Auxiliar
|
||||
vCompany,
|
||||
vAsiento);
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`xdiario_new`(vAsiento INT,
|
||||
vDated DATE,
|
||||
vSubaccount VARCHAR(12),
|
||||
vAccount VARCHAR(12),
|
||||
vConcept VARCHAR(25),
|
||||
vDebit DOUBLE,
|
||||
vCredit DOUBLE,
|
||||
vEuro DOUBLE,
|
||||
vSerie CHAR(1),
|
||||
vInvoice VARCHAR(8),
|
||||
vVat DOUBLE,
|
||||
vRe DOUBLE,
|
||||
vAux TINYINT,
|
||||
vCompany INT
|
||||
)
|
||||
RETURNS int(11)
|
||||
NOT DETERMINISTIC
|
||||
NO SQL
|
||||
BEGIN
|
||||
IF vAsiento IS NULL THEN
|
||||
CALL vn.ledger_next(vAsiento);
|
||||
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;
|
||||
|
||||
RETURN vAsiento;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -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 ;
|
|
@ -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 ;
|
|
@ -2,122 +2,116 @@ 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;
|
||||
DECLARE vBookDated DATE;
|
||||
DECLARE vDiff DECIMAL(10,2);
|
||||
DECLARE vApunte BIGINT;
|
||||
|
||||
SELECT ASIEN, IFNULL(bookEntried, util.VN_CURDATE()) INTO vBookNumber, vBookDated
|
||||
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
|
||||
|
@ -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,
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceInTax_getFromEntries`(IN vInvoiceInFk INT)
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceInTax_getFromEntries`(
|
||||
IN vInvoiceInFk INT
|
||||
)
|
||||
BEGIN
|
||||
DECLARE vRate DOUBLE DEFAULT 1;
|
||||
DECLARE vDated DATE;
|
||||
DECLARE vExpenseFk VARCHAR(10);
|
||||
|
||||
SELECT MAX(rr.dated) INTO vDated
|
||||
FROM referenceRate rr
|
||||
JOIN invoiceIn ii ON ii.id = vInvoiceInFk
|
||||
WHERE rr.dated <= ii.issued
|
||||
AND rr.currencyFk = ii.currencyFk ;
|
||||
|
||||
IF vDated THEN
|
||||
SELECT `value` INTO vRate
|
||||
FROM referenceRate
|
||||
WHERE dated = vDated;
|
||||
END IF;
|
||||
WITH rate AS(
|
||||
SELECT MAX(rr.dated) dated, ii.currencyFk
|
||||
FROM vn.invoiceIn ii
|
||||
JOIN vn.referenceRate rr ON rr.currencyFk = ii.currencyFk
|
||||
WHERE ii.id = vInvoiceInFk
|
||||
AND rr.dated <= ii.issued
|
||||
) SELECT `value` INTO vRate
|
||||
FROM vn.referenceRate rr
|
||||
JOIN rate r ON r.dated = rr.dated
|
||||
AND r.currencyFk = rr.currencyFk;
|
||||
|
||||
SELECT id INTO vExpenseFk
|
||||
FROM vn.expense
|
||||
FROM expense
|
||||
WHERE `name` = 'Adquisición mercancia Extracomunitaria'
|
||||
GROUP BY id
|
||||
LIMIT 1;
|
||||
|
@ -26,19 +26,25 @@ BEGIN
|
|||
DELETE FROM invoiceInTax
|
||||
WHERE invoiceInFk = vInvoiceInFk;
|
||||
|
||||
INSERT INTO invoiceInTax(invoiceInFk, taxableBase, expenseFk, foreignValue, taxTypeSageFk, transactionTypeSageFk)
|
||||
SELECT ii.id,
|
||||
SUM(b.buyingValue * b.quantity) / IFNULL(vRate,1) taxableBase,
|
||||
vExpenseFk,
|
||||
IF(ii.currencyFk = 1,NULL,SUM(b.buyingValue * b.quantity )) divisa,
|
||||
INSERT INTO invoiceInTax(
|
||||
invoiceInFk,
|
||||
taxableBase,
|
||||
expenseFk,
|
||||
foreignValue,
|
||||
taxTypeSageFk,
|
||||
transactionTypeSageFk
|
||||
)SELECT ii.id,
|
||||
SUM(b.buyingValue * b.quantity) / vRate taxableBase,
|
||||
vExpenseFk,
|
||||
IF(ii.currencyFk = 1,
|
||||
NULL,
|
||||
SUM(b.buyingValue * b.quantity )),
|
||||
taxTypeSageFk,
|
||||
transactionTypeSageFk
|
||||
FROM invoiceIn ii
|
||||
JOIN entry e ON e.invoiceInFk = ii.id
|
||||
JOIN supplier s ON s.id = e.supplierFk
|
||||
JOIN buy b ON b.entryFk = e.id
|
||||
LEFT JOIN referenceRate rr ON rr.currencyFk = ii.currencyFk
|
||||
AND rr.dated = ii.issued
|
||||
WHERE ii.id = vInvoiceInFk
|
||||
HAVING taxableBase IS NOT NULL;
|
||||
END$$
|
||||
|
|
|
@ -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,
|
||||
|
@ -172,23 +167,23 @@ BEGIN
|
|||
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$$
|
||||
|
|
|
@ -16,14 +16,17 @@ BEGIN
|
|||
INTO vNewItemShelvingFk
|
||||
FROM itemShelving ish
|
||||
JOIN (
|
||||
SELECT itemFk,
|
||||
packing,
|
||||
created
|
||||
SELECT
|
||||
itemFk,
|
||||
packing,
|
||||
created,
|
||||
buyFk
|
||||
FROM itemShelving
|
||||
WHERE id = vItemShelvingFk
|
||||
) ish2 ON ish2.itemFk = ish.itemFk
|
||||
AND ish2.packing = ish.packing
|
||||
AND DATE(ish2.created) = DATE(ish.created)
|
||||
AND date(ish2.created) = date(ish.created)
|
||||
AND ish2.buyFk = ish.buyFk
|
||||
WHERE ish.shelvingFk = vShelvingFk COLLATE utf8_unicode_ci;
|
||||
|
||||
IF vNewItemShelvingFk THEN
|
||||
|
|
|
@ -2,7 +2,6 @@ DELIMITER $$
|
|||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT)
|
||||
BEGIN
|
||||
|
||||
|
||||
/**
|
||||
* Añade registro o lo actualiza si ya existe.
|
||||
*
|
||||
|
@ -15,11 +14,23 @@ BEGIN
|
|||
* @param vWarehouseFk indica el sector
|
||||
*
|
||||
**/
|
||||
|
||||
DECLARE vItemFk INT;
|
||||
DECLARE vBuyFk INT;
|
||||
|
||||
SELECT id INTO vBuyFk
|
||||
FROM buy WHERE id = vBarcode;
|
||||
|
||||
SELECT barcodeToItem(vBarcode) INTO vItemFk;
|
||||
|
||||
IF vBuyFk IS NULL THEN
|
||||
CALL cache.last_buy_refresh(FALSE);
|
||||
|
||||
SELECT buy_id INTO vBuyFk
|
||||
FROM cache.last_buy
|
||||
WHERE item_id = vItemFk
|
||||
AND warehouse_id = vWarehouseFk;
|
||||
END IF;
|
||||
|
||||
IF vPacking IS NULL
|
||||
THEN
|
||||
SET vPacking = itemPacking(vBarcode, vWarehouseFk);
|
||||
|
@ -29,31 +40,32 @@ BEGIN
|
|||
IF (SELECT COUNT(*) FROM itemShelving
|
||||
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk
|
||||
AND itemFk = vItemFk
|
||||
AND packing = vPacking) = 1 THEN
|
||||
AND packing = vPacking
|
||||
AND buyFk = vBuyFk) THEN
|
||||
|
||||
UPDATE itemShelving
|
||||
SET visible = visible+vQuantity
|
||||
SET visible = visible + vQuantity
|
||||
WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk AND itemFk = vItemFk AND packing = vPacking;
|
||||
|
||||
ELSE
|
||||
CALL cache.last_buy_refresh(FALSE);
|
||||
INSERT INTO itemShelving( itemFk,
|
||||
shelvingFk,
|
||||
visible,
|
||||
grouping,
|
||||
packing,
|
||||
packagingFk)
|
||||
|
||||
SELECT vItemFk,
|
||||
vShelvingFk,
|
||||
vQuantity,
|
||||
IFNULL(vGrouping, b.grouping),
|
||||
IFNULL(vPacking, b.packing),
|
||||
IFNULL(vPackagingFk, b.packagingFk)
|
||||
FROM item i
|
||||
LEFT JOIN cache.last_buy lb ON i.id = lb.item_id AND lb.warehouse_id = vWarehouseFk
|
||||
LEFT JOIN buy b ON b.id = lb.buy_id
|
||||
WHERE i.id = vItemFk;
|
||||
INSERT INTO itemShelving(
|
||||
itemFk,
|
||||
shelvingFk,
|
||||
visible,
|
||||
grouping,
|
||||
packing,
|
||||
packagingFk,
|
||||
buyFk)
|
||||
SELECT vItemFk,
|
||||
vShelvingFk,
|
||||
vQuantity,
|
||||
IFNULL(vGrouping, b.grouping),
|
||||
IFNULL(vPacking, b.packing),
|
||||
IFNULL(vPackagingFk, b.packagingFk),
|
||||
id
|
||||
FROM buy b
|
||||
WHERE id = vBuyFk;
|
||||
END IF;
|
||||
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 ;
|
|
@ -6,7 +6,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_comparative`(
|
|||
vAvailableSince DATE,
|
||||
vBuyerFk INT,
|
||||
vIsFloramondo BOOL,
|
||||
vCountryFk INT
|
||||
vCountryFk INT
|
||||
)
|
||||
proc: BEGIN
|
||||
/**
|
||||
|
@ -23,7 +23,6 @@ proc: BEGIN
|
|||
* @param tmp.comparativeFilterType(filterFk INT ,itemTypeFk INT)
|
||||
* @return tmp.comparative
|
||||
*/
|
||||
|
||||
DECLARE vDayRangeStart DATE;
|
||||
DECLARE vDayRangeEnd DATE;
|
||||
DECLARE w1, w2, w3, w4, w5, w6, w7 INT;
|
||||
|
@ -59,14 +58,14 @@ proc: BEGIN
|
|||
END IF;
|
||||
|
||||
SELECT MIN(dated) INTO vDayRangeStart
|
||||
FROM vn.time
|
||||
FROM `time`
|
||||
WHERE dated <= vDate
|
||||
GROUP BY period
|
||||
ORDER BY dated desc
|
||||
LIMIT 1 OFFSET vWeekRange;
|
||||
|
||||
SELECT MAX(dated) INTO vDayRangeEnd
|
||||
FROM vn.time
|
||||
FROM `time`
|
||||
WHERE dated >= vDate
|
||||
GROUP BY period
|
||||
ORDER BY dated ASC
|
||||
|
@ -83,12 +82,11 @@ proc: BEGIN
|
|||
JOIN itemType t ON t.id = i.typeFk
|
||||
JOIN itemCategory c ON c.id = t.categoryFk
|
||||
LEFT JOIN worker w ON w.id = t.workerFk
|
||||
WHERE (NOT vHasTypeFilter
|
||||
OR t.id IN (SELECT itemTypeFk FROM tmp.comparativeFilterType))
|
||||
AND (vBuyerFk IS NULL
|
||||
OR t.workerFk = vBuyerFk)
|
||||
AND (vIsFloramondo IS NULL
|
||||
OR i.isFloramondo = vIsFloramondo);
|
||||
WHERE (NOT vHasTypeFilter OR t.id IN (
|
||||
SELECT itemTypeFk FROM tmp.comparativeFilterType
|
||||
))
|
||||
AND (vBuyerFk IS NULL OR t.workerFk = vBuyerFk)
|
||||
AND (vIsFloramondo IS NULL OR i.isFloramondo = vIsFloramondo);
|
||||
|
||||
IF vDate < util.VN_CURDATE() THEN
|
||||
ALTER TABLE tmp.itemInventory
|
||||
|
@ -115,10 +113,11 @@ proc: BEGIN
|
|||
SET i = i + 1;
|
||||
|
||||
SELECT t.period INTO vPeriod
|
||||
FROM vn.`time` t
|
||||
FROM `time` t
|
||||
WHERE t.dated = vDayRangeStart + INTERVAL (vWeekCount * (i - 1)) DAY;
|
||||
|
||||
INSERT IGNORE INTO tTable(cy, ly, zy) VALUES(vPeriod, vPeriod - 100, vPeriod - 200);
|
||||
INSERT IGNORE INTO tTable(cy, ly, zy)
|
||||
VALUES(vPeriod, vPeriod - 100, vPeriod - 200);
|
||||
UNTIL i = vWeekCount END REPEAT;
|
||||
|
||||
SELECT cy, ly, zy INTO w1, y1, z1 FROM tTable LIMIT 1;
|
||||
|
@ -130,7 +129,6 @@ proc: BEGIN
|
|||
SELECT cy, ly, zy INTO w7, y7, z7 FROM tTable WHERE cy > w6 LIMIT 1;
|
||||
|
||||
-- Genera una tabla con los datos del año pasado.
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tLastYear
|
||||
(KEY (lItemFk))
|
||||
ENGINE = MEMORY
|
||||
|
@ -151,15 +149,14 @@ proc: BEGIN
|
|||
SUM(IF(c.timePeriod = y7, c.price, 0)) lprice7
|
||||
FROM tmp.itemInventory ai
|
||||
JOIN comparative c ON c.itemFk = ai.id
|
||||
JOIN warehouse w on w.id = c.warehouseFk
|
||||
JOIN warehouse w ON w.id = c.warehouseFk
|
||||
JOIN tTable wt ON c.timePeriod = wt.ly
|
||||
WHERE IFNULL(vWarehouseFk, c.warehouseFk) = c.warehouseFk
|
||||
WHERE (vWarehouseFk IS NULL OR vWarehouseFk = c.warehouseFk)
|
||||
AND w.isComparative
|
||||
AND (vCountryFk IS NULL OR c.countryFk = vCountryFk)
|
||||
GROUP BY ai.id;
|
||||
|
||||
-- Genera una tabla con los datos de hace DOS años.
|
||||
|
||||
-- Genera una tabla con los datos de hace 2 años
|
||||
CREATE OR REPLACE TEMPORARY TABLE tTwoYearsAgo
|
||||
(KEY (tItemFk))
|
||||
ENGINE = MEMORY
|
||||
|
@ -180,59 +177,58 @@ proc: BEGIN
|
|||
SUM(IF(c.timePeriod = z7, c.price, 0)) vlprice7
|
||||
FROM tmp.itemInventory ai
|
||||
JOIN comparative c ON c.itemFk = ai.id
|
||||
JOIN warehouse w on w.id = c.warehouseFk
|
||||
JOIN warehouse w ON w.id = c.warehouseFk
|
||||
JOIN tTable wt ON c.timePeriod = wt.zy
|
||||
WHERE IFNULL(vWarehouseFk, c.warehouseFk) = c.warehouseFk
|
||||
WHERE (vWarehouseFk IS NULL OR vWarehouseFk = c.warehouseFk)
|
||||
AND w.isComparative
|
||||
AND (vCountryFk IS NULL OR c.countryFk = vCountryFk)
|
||||
GROUP BY ai.id;
|
||||
|
||||
-- Genera una tabla con los datos de este año.ss
|
||||
|
||||
-- Genera una tabla con los datos de este año
|
||||
CREATE OR REPLACE TEMPORARY TABLE tCurrentYear
|
||||
(KEY (cItemFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT t.itemFk cItemFk,
|
||||
SUM(IF(week = w1, total, 0)) cweek1,
|
||||
SUM(IF(week = w2, total, 0)) cweek2,
|
||||
SUM(IF(week = w3, total, 0)) cweek3,
|
||||
SUM(IF(week = w4, total, 0)) cweek4,
|
||||
SUM(IF(week = w5, total, 0)) cweek5,
|
||||
SUM(IF(week = w6, total, 0)) cweek6,
|
||||
SUM(IF(week = w7, total, 0)) cweek7,
|
||||
SUM(IF(week = w1, price, 0)) cprice1,
|
||||
SUM(IF(week = w2, price, 0)) cprice2,
|
||||
SUM(IF(week = w3, price, 0)) cprice3,
|
||||
SUM(IF(week = w4, price, 0)) cprice4,
|
||||
SUM(IF(week = w5, price, 0)) cprice5,
|
||||
SUM(IF(week = w6, price, 0)) cprice6,
|
||||
SUM(IF(week = w7, price, 0)) cprice7
|
||||
SUM(IF(`week` = w1, total, 0)) cweek1,
|
||||
SUM(IF(`week` = w2, total, 0)) cweek2,
|
||||
SUM(IF(`week` = w3, total, 0)) cweek3,
|
||||
SUM(IF(`week` = w4, total, 0)) cweek4,
|
||||
SUM(IF(`week` = w5, total, 0)) cweek5,
|
||||
SUM(IF(`week` = w6, total, 0)) cweek6,
|
||||
SUM(IF(`week` = w7, total, 0)) cweek7,
|
||||
SUM(IF(`week` = w1, price, 0)) cprice1,
|
||||
SUM(IF(`week` = w2, price, 0)) cprice2,
|
||||
SUM(IF(`week` = w3, price, 0)) cprice3,
|
||||
SUM(IF(`week` = w4, price, 0)) cprice4,
|
||||
SUM(IF(`week` = w5, price, 0)) cprice5,
|
||||
SUM(IF(`week` = w6, price, 0)) cprice6,
|
||||
SUM(IF(`week` = w7, price, 0)) cprice7
|
||||
FROM (
|
||||
SELECT s.itemFk,
|
||||
ti.period `week`,
|
||||
SUM(s.quantity) total,
|
||||
TRUNCATE(SUM(s.quantity * s.priceFixed),0) price
|
||||
FROM ticket t
|
||||
TRUNCATE(SUM(s.quantity * s.priceFixed), 0) price
|
||||
FROM ticket t FORCE INDEX (Fecha)
|
||||
JOIN sale s ON t.id = s.ticketFk
|
||||
JOIN tmp.itemInventory it ON it.id = s.itemFk
|
||||
JOIN time ti ON ti.dated = DATE(t.shipped)
|
||||
JOIN tmp.itemInventory it ON it.id = s.itemFk
|
||||
JOIN `time` ti ON ti.dated = DATE(t.shipped)
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN itemType tp ON tp.id = i.typeFk
|
||||
JOIN itemCategory ic ON ic.id = tp.categoryFk
|
||||
JOIN warehouse w ON w.id = t.warehouseFk
|
||||
STRAIGHT_JOIN address ad ON ad.id = t.addressFk
|
||||
JOIN province p ON p.id = ad.provinceFk
|
||||
JOIN `address` ad ON ad.id = t.addressFk
|
||||
JOIN province p ON p.id = ad.provinceFk
|
||||
JOIN `client` c ON c.id = ad.clientFk
|
||||
WHERE t.shipped BETWEEN vDayRangeStart AND util.dayEnd(vDayRangeEnd)
|
||||
AND c.typeFk IN ('Normal','handMaking')
|
||||
AND w.id = COALESCE(vWarehouseFk, w.id)
|
||||
AND c.typeFk IN ('normal', 'handMaking')
|
||||
AND (vWarehouseFk IS NULL OR vWarehouseFk = w.id)
|
||||
AND (vCountryFk IS NULL OR p.countryFk = vCountryFk)
|
||||
AND w.isComparative
|
||||
AND (vCountryFk IS NULL OR p.countryFk = vCountryFk)
|
||||
GROUP BY i.id, week
|
||||
GROUP BY i.id, `week`
|
||||
) t
|
||||
GROUP BY t.itemFk;
|
||||
|
||||
-- Genera la tabla con la comparativa.
|
||||
-- Genera la tabla con la comparativa
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.comparative
|
||||
ENGINE = MEMORY
|
||||
SELECT it.subName productor,
|
||||
|
@ -240,13 +236,13 @@ proc: BEGIN
|
|||
b.buyingValue costefijo,
|
||||
b.groupingMode caja,
|
||||
it.image ArticleImage,
|
||||
IFNULL(it.inkFk,"?") color,
|
||||
IFNULL(it.inkFk, '?') color,
|
||||
tp.code tipo,
|
||||
it.typeFk tipo_id,
|
||||
o.code origen,
|
||||
it.category categoria,
|
||||
it.stems tallos,
|
||||
it.size medida,
|
||||
it.`size` medida,
|
||||
it.name article,
|
||||
w.code codigoTrabajador,
|
||||
tp.categoryFk reino_id,
|
||||
|
@ -257,24 +253,27 @@ proc: BEGIN
|
|||
it.id Id_Article,
|
||||
i.buy_id,
|
||||
tp.life,
|
||||
IFNULL(i.sd,0) sd,
|
||||
IFNULL(i.sd, 0) sd,
|
||||
i.avalaible,
|
||||
i.visible,
|
||||
i.buy_date,
|
||||
e.id provider_id,
|
||||
it.comment comments,
|
||||
it.description itemDescription,
|
||||
IF(cy.cItemFk IS NULL AND i.visible = 0 AND i.avalaible = 0
|
||||
AND IFNULL(i.sd, 0) = 0, FALSE, TRUE) filtret,
|
||||
IF(cy.cItemFk IS NULL AND i.visible = 0
|
||||
AND i.avalaible = 0 AND (i.sd IS NULL OR i.sd = 0),
|
||||
FALSE,
|
||||
TRUE
|
||||
) filtret,
|
||||
IF(it.hasMinPrice, FORMAT(it.minPrice, 2), "") pvp,
|
||||
s.company_name
|
||||
FROM tmp.itemInventory i
|
||||
JOIN item it ON it.id = i.id
|
||||
LEFT JOIN itemType tp ON tp.id = it.typeFk
|
||||
LEFT JOIN worker w ON w.id = tp.workerFk
|
||||
JOIN itemType tp ON tp.id = it.typeFk
|
||||
JOIN worker w ON w.id = tp.workerFk
|
||||
LEFT JOIN buy b ON b.id = i.buy_id
|
||||
LEFT JOIN entry e ON e.id = b.entryFk
|
||||
LEFT JOIN origin o ON o.id = it.originFk
|
||||
LEFT JOIN `entry` e ON e.id = b.entryFk
|
||||
JOIN origin o ON o.id = it.originFk
|
||||
LEFT JOIN tLastYear ly ON ly.lItemFk = it.id
|
||||
LEFT JOIN tCurrentYear cy ON cy.cItemFk = it.id
|
||||
LEFT JOIN tTwoYearsAgo zy ON zy.tItemFk = it.id
|
||||
|
@ -287,8 +286,8 @@ proc: BEGIN
|
|||
OR ly.lweek1 OR ly.lweek2 OR ly.lweek3 OR ly.lweek4 OR ly.lweek5 OR ly.lweek6 OR ly.lweek7
|
||||
OR zy.vlweek1 OR zy.vlweek2 OR zy.vlweek3 OR zy.vlweek4 OR zy.vlweek5 OR zy.vlweek6 OR zy.vlweek7;
|
||||
|
||||
-- Elimina las tablas temporales creadas...
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.itemInventory,
|
||||
DROP TEMPORARY TABLE IF EXISTS
|
||||
tmp.itemInventory,
|
||||
tTwoYearsAgo,
|
||||
tLastYear,
|
||||
tCurrentYear,
|
||||
|
|
|
@ -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 ;
|
|
@ -1,5 +1,7 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_ValuateInventory`(vDated DATE, vIsDetailed BOOLEAN)
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_valuateInventory`(
|
||||
vDated DATE
|
||||
)
|
||||
BEGIN
|
||||
DECLARE vInventoried DATE;
|
||||
DECLARE vHasNotInventory BOOLEAN DEFAULT FALSE;
|
||||
|
@ -15,8 +17,7 @@ BEGIN
|
|||
SELECT tr.landed INTO vInventoried
|
||||
FROM travel tr
|
||||
JOIN `entry` e ON e.travelFk = tr.id
|
||||
JOIN entryConfig ec
|
||||
WHERE landed <= vDateDayEnd
|
||||
WHERE tr.landed <= vDateDayEnd
|
||||
AND e.supplierFk = vInventorySupplierFk
|
||||
ORDER BY tr.landed DESC
|
||||
LIMIT 1;
|
||||
|
@ -27,8 +28,7 @@ BEGIN
|
|||
SELECT landed INTO vInventoryClone
|
||||
FROM travel tr
|
||||
JOIN `entry` e ON e.travelFk = tr.id
|
||||
JOIN entryConfig ec
|
||||
WHERE landed >= vDated
|
||||
WHERE tr.landed >= vDated
|
||||
AND e.supplierFk = vInventorySupplierFk
|
||||
ORDER BY landed ASC
|
||||
LIMIT 1;
|
||||
|
@ -38,13 +38,14 @@ BEGIN
|
|||
END IF;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tInventory(
|
||||
warehouseFk SMALLINT,
|
||||
itemFk BIGINT,
|
||||
quantity INT,
|
||||
cost DOUBLE DEFAULT 0,
|
||||
total DOUBLE DEFAULT 0,
|
||||
warehouseInventory VARCHAR(20),
|
||||
PRIMARY KEY (warehouseInventory, itemFk) USING HASH
|
||||
warehouseFk SMALLINT,
|
||||
itemFk BIGINT,
|
||||
quantity INT,
|
||||
volume DECIMAL(10,2),
|
||||
cost DOUBLE DEFAULT 0,
|
||||
total DOUBLE DEFAULT 0,
|
||||
warehouseInventory VARCHAR(20),
|
||||
PRIMARY KEY (warehouseInventory, itemFk) USING HASH
|
||||
)
|
||||
ENGINE = MEMORY;
|
||||
|
||||
|
@ -60,9 +61,8 @@ BEGIN
|
|||
JOIN `entry` e ON e.id = b.entryFk
|
||||
JOIN travel tr ON tr.id = e.travelFk
|
||||
JOIN itemType t ON t.id = i.typeFk
|
||||
JOIN warehouse w ON w.id = warehouseInFk
|
||||
JOIN entryConfig ec
|
||||
WHERE landed = vDateDayEnd
|
||||
JOIN warehouse w ON w.id = tr.warehouseInFk
|
||||
WHERE tr.landed = vDateDayEnd
|
||||
AND e.supplierFk = vInventorySupplierFk
|
||||
AND w.valuatedInventory
|
||||
AND t.isInventory
|
||||
|
@ -78,9 +78,8 @@ BEGIN
|
|||
JOIN `entry` e ON e.id = b.entryFk
|
||||
JOIN travel tr ON tr.id = e.travelFk
|
||||
JOIN itemType t ON t.id = i.typeFk
|
||||
JOIN warehouse w ON w.id = warehouseInFk
|
||||
JOIN entryConfig ec
|
||||
WHERE landed = vInventoried
|
||||
JOIN warehouse w ON w.id = tr.warehouseInFk
|
||||
WHERE tr.landed = vInventoried
|
||||
AND e.supplierFk = vInventorySupplierFk
|
||||
AND w.valuatedInventory
|
||||
AND t.isInventory
|
||||
|
@ -99,7 +98,6 @@ BEGIN
|
|||
JOIN travel tr ON tr.id = e.travelFk
|
||||
JOIN itemType t ON t.id = i.typeFk
|
||||
JOIN warehouse w ON w.id = tr.warehouseInFk
|
||||
JOIN entryConfig ec
|
||||
WHERE tr.landed BETWEEN vInventoried AND vDateDayEnd
|
||||
AND IF(tr.landed = util.VN_CURDATE(), tr.isReceived, TRUE)
|
||||
AND NOT e.isRaid
|
||||
|
@ -183,52 +181,37 @@ BEGIN
|
|||
AND e.isConfirmed
|
||||
ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity);
|
||||
|
||||
CALL vn.buyUltimate(NULL, vDateDayEnd);
|
||||
CALL buyUltimate(NULL, vDateDayEnd);
|
||||
|
||||
DELETE FROM tInventory WHERE quantity IS NULL OR NOT quantity;
|
||||
|
||||
UPDATE tInventory i
|
||||
JOIN tmp.buyUltimate bu ON i.warehouseFk = bu.warehouseFk AND i.itemFk = bu.itemFk
|
||||
JOIN buy b ON b.id = bu.buyFk
|
||||
SET total = i.quantity * (IFNULL(b.buyingValue, 0) + IFNULL(b.packageValue, 0) + IFNULL(b.freightValue, 0) + IFNULL(b.comissionValue, 0)),
|
||||
cost = IFNULL(b.buyingValue, 0) + IFNULL(b.packageValue, 0) + IFNULL(b.freightValue, 0) + IFNULL(b.comissionValue, 0)
|
||||
WHERE i.quantity;
|
||||
LEFT JOIN itemCost ic ON ic.itemFk = i.itemFk
|
||||
AND ic.warehouseFk = i.warehouseFk
|
||||
SET i.total = i.quantity * (IFNULL(b.buyingValue, 0) + IFNULL(b.packageValue, 0) + IFNULL(b.freightValue, 0) + IFNULL(b.comissionValue, 0)),
|
||||
i.cost = IFNULL(b.buyingValue, 0) + IFNULL(b.packageValue, 0) + IFNULL(b.freightValue, 0) + IFNULL(b.comissionValue, 0),
|
||||
i.volume = i.quantity * ic.cm3delivery / 1000000;
|
||||
|
||||
DELETE FROM tInventory
|
||||
WHERE quantity IS NULL OR NOT quantity;
|
||||
|
||||
IF vIsDetailed THEN
|
||||
SELECT ti.warehouseFk,
|
||||
i.id itemFk,
|
||||
i.longName,
|
||||
i.size,
|
||||
ti.quantity,
|
||||
tp.name Tipo,
|
||||
ic.name Reino,
|
||||
ti.cost,
|
||||
CAST(ti.total AS DECIMAL(10, 2)) total,
|
||||
ti.warehouseInventory almacen
|
||||
FROM tInventory ti
|
||||
JOIN warehouse w ON w.id = warehouseFk
|
||||
JOIN item i ON i.id = ti.itemFk
|
||||
JOIN itemType tp ON tp.id = i.typeFk
|
||||
JOIN itemCategory ic ON ic.id = tp.categoryFk
|
||||
WHERE w.valuatedInventory
|
||||
AND ti.total > 0
|
||||
ORDER BY ti.total DESC;
|
||||
ELSE
|
||||
SELECT i.warehouseInventory Almacen,
|
||||
ic.name Reino,
|
||||
CAST(i.total AS DECIMAL(10, 2)) Euros,
|
||||
w.code Comprador,
|
||||
it.id
|
||||
FROM tInventory i
|
||||
JOIN warehouse wh ON wh.id = warehouseFk
|
||||
JOIN item it ON it.id = i.itemFk
|
||||
JOIN itemType itp ON itp.id = it.typeFk
|
||||
LEFT JOIN worker w ON w.id = itp.workerFk
|
||||
JOIN itemCategory ic ON ic.id = itp.categoryFk
|
||||
WHERE wh.valuatedInventory
|
||||
AND i.total > 0;
|
||||
END IF;
|
||||
SELECT ti.warehouseFk,
|
||||
i.id,
|
||||
i.longName,
|
||||
i.size,
|
||||
ti.quantity,
|
||||
ti.volume,
|
||||
tp.name itemTypeName,
|
||||
ic.name itemCategoryName,
|
||||
ti.cost,
|
||||
ti.total,
|
||||
ti.warehouseInventory
|
||||
FROM tInventory ti
|
||||
JOIN warehouse w ON w.id = warehouseFk
|
||||
JOIN item i ON i.id = ti.itemFk
|
||||
JOIN itemType tp ON tp.id = i.typeFk
|
||||
JOIN itemCategory ic ON ic.id = tp.categoryFk
|
||||
WHERE w.valuatedInventory
|
||||
AND ti.total > 0;
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.buyUltimate,
|
|
@ -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,20 +17,22 @@ 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;
|
||||
DECLARE vSupplierFk INT;
|
||||
DECLARE vIsOriginalAClient BOOL;
|
||||
DECLARE vPayMethodCompensation INT;
|
||||
|
||||
CALL ledger_next(vNewBookEntry);
|
||||
CALL ledger_next(YEAR(vDated), vNewBookEntry);
|
||||
|
||||
SELECT COUNT(id) INTO vIsOriginalAClient FROM client WHERE accountingAccount LIKE vOriginalAccount COLLATE utf8_general_ci;
|
||||
SELECT COUNT(id) INTO vIsOriginalAClient
|
||||
FROM client
|
||||
WHERE accountingAccount LIKE vOriginalAccount COLLATE utf8_general_ci;
|
||||
|
||||
SELECT id, COUNT(id) INTO vClientFk, vIsClientCompensation
|
||||
FROM client
|
||||
|
@ -31,7 +41,7 @@ BEGIN
|
|||
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);
|
||||
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';
|
||||
IF vIsClientCompensation THEN
|
||||
IF vIsOriginalAClient THEN
|
||||
SET vAmount = -vAmount;
|
||||
END IF;
|
||||
|
||||
INSERT INTO payment (received, dueDated, supplierFk, amount, bankFk, payMethodFk, concept, companyFk, isConciliated)
|
||||
VALUES(vDated, vDated, vSupplierFk, vAmount, vBankFk, vPayMethodCompensation, vConcept, vCompanyFk, TRUE);
|
||||
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,55 @@
|
|||
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 vLastBookEntry INT
|
||||
)
|
||||
BEGIN
|
||||
DECLARE vHasStartTransaction BOOLEAN;
|
||||
|
||||
UPDATE vn.ledgerConfig SET lastBookEntry = LAST_INSERT_ID(lastBookEntry + 1);
|
||||
SET vNewBookEntry = LAST_INSERT_ID();
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
|
||||
IF vHasStartTransaction THEN
|
||||
ROLLBACK TO sp;
|
||||
RESIGNAL;
|
||||
ELSE
|
||||
ROLLBACK;
|
||||
CALL util.throw ('It has not been possible to generate a new ledger');
|
||||
END IF;
|
||||
END;
|
||||
|
||||
IF vFiscalYear IS NULL THEN
|
||||
CALL util.throw('Fiscal year is required');
|
||||
END IF;
|
||||
|
||||
SELECT @@in_transaction INTO vHasStartTransaction;
|
||||
|
||||
IF NOT vHasStartTransaction THEN
|
||||
START TRANSACTION;
|
||||
ELSE
|
||||
SAVEPOINT sp;
|
||||
END IF;
|
||||
|
||||
SELECT bookEntry + 1 INTO vLastBookEntry
|
||||
FROM ledgerCompany
|
||||
WHERE fiscalYear = vFiscalYear
|
||||
FOR UPDATE;
|
||||
|
||||
IF vLastBookEntry IS NULL THEN
|
||||
INSERT INTO ledgerCompany
|
||||
SET fiscalYear = vFiscalYear,
|
||||
bookEntry = 1;
|
||||
SET vLastBookEntry = 1;
|
||||
END IF;
|
||||
|
||||
UPDATE ledgerCompany
|
||||
SET bookEntry = vLastBookEntry
|
||||
WHERE fiscalYear = vFiscalYear;
|
||||
|
||||
IF vHasStartTransaction THEN
|
||||
RELEASE SAVEPOINT sp;
|
||||
ELSE
|
||||
COMMIT;
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -12,12 +12,15 @@ BEGIN
|
|||
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);
|
||||
SELECT saleFk, sale_hasComponentLack(saleFk)hasProblem
|
||||
FROM (
|
||||
SELECT s.id saleFk
|
||||
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)
|
||||
GROUP BY s.id) sub;
|
||||
|
||||
CALL sale_setProblem('hasComponentLack');
|
||||
|
||||
|
|
|
@ -20,15 +20,15 @@ BEGIN
|
|||
|
||||
CALL buyUltimate(vWarehouseFk, vShipped);
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
SELECT vSelf saleFk, MOD(vQuantity, bu.`grouping`) hasProblem
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||
SELECT vSelf saleFk, MOD(vQuantity, b.`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.sale;
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -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
|
||||
|
|
|
@ -27,7 +27,10 @@ BEGIN
|
|||
SELECT DISTINCT clientFk
|
||||
FROM (
|
||||
SELECT clientFk, SUM(quantity) totalQuantity
|
||||
FROM tmp.packagingToInvoice
|
||||
FROM tmp.packagingToInvoice tpi
|
||||
JOIN client c ON c.id = tpi.clientFk
|
||||
LEFT JOIN supplier s ON s.nif = c.fi
|
||||
WHERE s.id IS NULL
|
||||
GROUP BY itemFk, clientFk
|
||||
HAVING totalQuantity > 0)sub;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ BEGIN
|
|||
SET t.hasProblem = TRUE
|
||||
WHERE c.isFreezed;
|
||||
|
||||
CALL ticket_setProblem('hasTicketRequest');
|
||||
CALL ticket_setProblem('isFreezed');
|
||||
|
||||
DROP TEMPORARY TABLE tmp.ticket;
|
||||
END$$
|
||||
|
|
|
@ -19,7 +19,7 @@ BEGIN
|
|||
WHERE t.id = vSelf;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
SELECT vSelf ticketFk, vRisk hasProblem;
|
||||
SELECT vSelf ticketFk, vHasRisk hasProblem;
|
||||
|
||||
CALL ticket_setProblem('hasRisk');
|
||||
|
||||
|
|
|
@ -18,17 +18,17 @@ BEGIN
|
|||
|
||||
CALL buyUltimate(vWarehouseFk, vDated);
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.sale
|
||||
SELECT s.id saleFk , MOD(s.quantity, b.`grouping`) hasProblem
|
||||
FROM ticket t
|
||||
JOIN sale s ON s.ticketFk = tl.ticketFk
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
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.sale;
|
||||
DROP TEMPORARY TABLE tmp.buyUltimate;
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -15,7 +15,7 @@ BEGIN
|
|||
WITH tickets AS(
|
||||
SELECT t.id ticketFk
|
||||
FROM vn.ticket t
|
||||
JOIN vn.sale s ON s.ticketFk = t.id
|
||||
LEFT 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
|
||||
|
|
|
@ -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 ;
|
|
@ -0,0 +1,64 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`xdiario_new`(
|
||||
vBookNumber INT,
|
||||
vDated DATE,
|
||||
vSubaccount VARCHAR(12),
|
||||
vAccount VARCHAR(12),
|
||||
vConcept VARCHAR(25),
|
||||
vDebit DOUBLE,
|
||||
vCredit DOUBLE,
|
||||
vEuro DOUBLE,
|
||||
vSerie CHAR(1),
|
||||
vInvoice VARCHAR(8),
|
||||
vVat DOUBLE,
|
||||
vRe DOUBLE,
|
||||
vAux TINYINT,
|
||||
vCompanyFk INT,
|
||||
OUT vNewBookNumber INT
|
||||
)
|
||||
/**
|
||||
* Este procedimiento se encarga de la inserción de registros en la tabla XDiario.
|
||||
* Si el número de asiento (vBookNumber) no está definido, se genera uno nuevo utilizando
|
||||
* vn.ledger_next.
|
||||
*
|
||||
* @param vBookNumber Número de asiento. Si es NULL, se generará uno nuevo.
|
||||
* @param vDated Fecha utilizada para generar un nuevo número de libro si vBookNumber es NULL.
|
||||
* @param vSubaccount Subcuenta para la transacción.
|
||||
* @param vAccount Cuenta para la transacción.
|
||||
* @param vConcept Concepto de la transacción.
|
||||
* @param vDebit Monto del débito para la transacción.
|
||||
* @param vCredit Monto del crédito para la transacción.
|
||||
* @param vEuro Monto en euros para la transacción.
|
||||
* @param vSerie Serie para la transacción.
|
||||
* @param vInvoice Número de factura para la transacción.
|
||||
* @param vVat Monto del IVA para la transacción.
|
||||
* @param vRe Monto del RE para la transacción.
|
||||
* @param vAux Variable auxiliar para la transacción.
|
||||
* @param vCompanyFk Clave foránea de la compañía para la transacción.
|
||||
* @return No retorna un valor, pero realiza una inserción en la tabla XDiario.
|
||||
*/
|
||||
BEGIN
|
||||
IF vBookNumber IS NULL THEN
|
||||
CALL ledger_next(YEAR(vDated), vBookNumber);
|
||||
END IF;
|
||||
|
||||
INSERT INTO XDiario
|
||||
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;
|
||||
|
||||
SET vNewBookNumber = vBookNumber;
|
||||
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
|
||||
IF vIsCash THEN
|
||||
SELECT account INTO vBankAccount
|
||||
FROM accounting
|
||||
WHERE id = NEW.bankFk;
|
||||
|
||||
SELECT account INTO cuenta_banco
|
||||
FROM accounting
|
||||
WHERE id = NEW.bankFk;
|
||||
|
||||
SELECT account INTO cuenta_proveedor
|
||||
FROM supplier
|
||||
WHERE id = NEW.supplierFk;
|
||||
|
||||
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;
|
||||
CALL ledger_next(YEAR(NEW.received), NEW.companyFk, vNewBookEntry);
|
||||
|
||||
IF ISNULL(NEW.workerFk) THEN
|
||||
SET NEW.workerFk = account.myUser_getId();
|
||||
END IF;
|
||||
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;
|
||||
|
||||
END$$
|
||||
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 ;
|
||||
|
|
|
@ -19,11 +19,6 @@ BEGIN
|
|||
`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
|
||||
FROM ticketTracking i
|
||||
|
|
|
@ -37,7 +37,7 @@ FROM (
|
|||
)
|
||||
JOIN `vn`.`volumeConfig` `vc`
|
||||
)
|
||||
JOIN `vn`.`itemCost` `ic` ON(
|
||||
JOIN `vn`.`itemCost` `ic` FORCE INDEX (`PRIMARY`) ON(
|
||||
`ic`.`itemFk` = `s`.`itemFk`
|
||||
AND `ic`.`warehouseFk` = `t`.`warehouseFk`
|
||||
)
|
||||
|
|
|
@ -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`
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
INSERT IGNORE INTO vn.entryType (code, description)
|
||||
VALUES ('devaluation', 'Devaluación');
|
||||
|
||||
ALTER TABLE vn.travelConfig ADD IF NOT EXISTS devalueWarehouseOutFk SMALLINT(6) UNSIGNED NULL
|
||||
COMMENT 'Datos del travel para las entradas generadas al devaluar artículos de A1 a A2';
|
||||
|
||||
ALTER TABLE vn.travelConfig ADD IF NOT EXISTS devalueAgencyModeFk INT(11) NULL;
|
||||
ALTER TABLE vn.travelConfig ADD IF NOT EXISTS devalueRef varchar(20) NULL;
|
||||
|
||||
ALTER TABLE vn.travelConfig DROP FOREIGN KEY IF EXISTS travelConfig_agencyMode_FK;
|
||||
|
||||
ALTER TABLE vn.travelConfig ADD CONSTRAINT travelConfig_agencyMode_FK
|
||||
FOREIGN KEY (devalueAgencyModeFk) REFERENCES vn.agencyMode(id) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE vn.travelConfig DROP FOREIGN KEY IF EXISTS travelConfig_warehouse_FK;
|
||||
ALTER TABLE vn.travelConfig ADD CONSTRAINT travelConfig_warehouse_FK
|
||||
FOREIGN KEY (devalueWarehouseOutFk) REFERENCES vn.warehouse(id) ON DELETE SET NULL ON UPDATE CASCADE;
|
|
@ -0,0 +1,4 @@
|
|||
-- Place your SQL code here
|
||||
INSERT INTO salix.defaultViewConfig
|
||||
(tableCode, `columns`)
|
||||
VALUES('routesList', '{"ID":true,"worker":true,"agency":true,"vehicle":true,"date":true,"volume":true,"description":true,"started":true,"finished":true,"actions":true}');
|
|
@ -0,0 +1,21 @@
|
|||
ALTER TABLE vn.deviceProductionUser DROP INDEX IF EXISTS deviceProductionUser_UN;
|
||||
|
||||
ALTER TABLE vn.deviceProductionUser DROP FOREIGN KEY IF EXISTS deviceProductionUser_FK;
|
||||
|
||||
ALTER TABLE vn.deviceProductionUser DROP PRIMARY KEY;
|
||||
|
||||
ALTER TABLE vn.deviceProductionUser ADD IF NOT EXISTS id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY FIRST;
|
||||
|
||||
ALTER TABLE vn.deviceProductionUser ADD CONSTRAINT deviceProductionUser_deviceProduction_FK FOREIGN KEY IF NOT EXISTS (deviceProductionFk) REFERENCES vn.deviceProduction(id);
|
||||
|
||||
ALTER TABLE vn.deviceProductionUser ADD CONSTRAINT deviceProductionUser_unique UNIQUE KEY IF NOT EXISTS (deviceProductionFk);
|
||||
|
||||
ALTER TABLE vn.deviceProductionUser ADD IF NOT EXISTS simSerialNumber TEXT NULL;
|
||||
|
||||
ALTER TABLE vn.deviceProductionConfig ADD IF NOT EXISTS maxDevicesPerUser INT UNSIGNED NULL;
|
||||
|
||||
UPDATE vn.deviceProductionConfig SET maxDevicesPerUser=1 WHERE id=1;
|
||||
|
||||
INSERT IGNORE INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
|
||||
VALUES ('Worker','getAvailablePda','READ','ALLOW','ROLE','hr');
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
UPDATE vn.route
|
||||
SET vehicleFk = NULL
|
||||
WHERE vehicleFk NOT IN (SELECT id FROM vn.vehicle);
|
||||
|
||||
ALTER TABLE vn.route
|
||||
ADD CONSTRAINT route_vehicleFk FOREIGN KEY (vehicleFk) REFERENCES vn.vehicle(id);
|
||||
|
||||
ALTER TABLE vn.route
|
||||
MODIFY COLUMN firstEditorFk int(10) unsigned NULL;
|
||||
|
||||
UPDATE vn.route
|
||||
SET firstEditorFk = NULL
|
||||
WHERE firstEditorFk NOT IN (SELECT id FROM account.user);
|
||||
|
||||
ALTER TABLE vn.route
|
||||
ADD CONSTRAINT route_firstEditorFk FOREIGN KEY (firstEditorFk) REFERENCES account.user(id);
|
|
@ -0,0 +1,4 @@
|
|||
-- Place your SQL code here
|
||||
|
||||
ALTER TABLE floranet.catalogue ADD addressFk int(11) NOT NULL;
|
||||
ALTER TABLE floranet.catalogue ADD CONSTRAINT catalogue_address_FK FOREIGN KEY (addressFk) REFERENCES vn.address(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@ -0,0 +1,6 @@
|
|||
ALTER TABLE floranet.builder DROP FOREIGN KEY builder_FK_1;
|
||||
ALTER TABLE floranet.`element` DROP PRIMARY KEY;
|
||||
ALTER TABLE floranet.`element` ADD id INT NOT NULL;
|
||||
ALTER TABLE floranet.`element` ADD CONSTRAINT element_pk PRIMARY KEY (id);
|
||||
ALTER TABLE floranet.builder ADD CONSTRAINT builder_element_FK FOREIGN KEY (elementFk) REFERENCES floranet.`element`(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
ALTER TABLE pbx.sipConfig
|
||||
CHANGE incomingLimit `call-limit` varchar(10)
|
||||
CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL;
|
||||
CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL;
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
CREATE OR REPLACE TABLE vn.ledgerCompany (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`fiscalYear` int(10) unsigned NOT NULL COMMENT 'Año del ejercicio contable',
|
||||
`bookEntry` int(10) unsigned NOT NULL DEFAULT 1 COMMENT 'Contador asiento contable',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `ledgerCompany_unique` (`fiscalYear`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci
|
||||
COMMENT='Contador para asientos contables';
|
||||
|
||||
INSERT IGNORE INTO vn.ledgerCompany (fiscalYear, bookEntry)
|
||||
SELECT YEAR(util.VN_CURDATE()), lastBookEntry
|
||||
FROM vn.ledgerConfig;
|
||||
|
||||
ALTER TABLE vn.ledgerConfig CHANGE IF EXISTS lastBookEntry lastBookEntry__ int(11) NOT NULL
|
||||
COMMENT '@deprecated 2024-05-28 refs #7400 Modificar contador asientos contables';
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
ALTER TABLE vn.clientConfig
|
||||
ADD monthsToDisableUser int(10) unsigned DEFAULT NULL NULL;
|
||||
|
||||
UPDATE IGNORE vn.clientConfig
|
||||
SET monthsToDisableUser = 12;
|
|
@ -0,0 +1,26 @@
|
|||
DROP TABLE IF EXISTS vn2008.scanTree__;
|
||||
DROP TABLE IF EXISTS vn2008.payroll_embargos__;
|
||||
DROP TABLE IF EXISTS vn2008.unary_source__;
|
||||
DROP TABLE IF EXISTS vn2008.unary_scan_line_buy__;
|
||||
DROP TABLE IF EXISTS vn2008.unary_scan_line__;
|
||||
DROP TABLE IF EXISTS vn2008.unary_scan__;
|
||||
DROP TABLE IF EXISTS vn2008.scan_line__;
|
||||
DROP TABLE IF EXISTS vn2008.Familias__;
|
||||
DROP TABLE IF EXISTS vn2008.language__;
|
||||
DROP TABLE IF EXISTS vn2008.Clientes_dits__;
|
||||
DROP TABLE IF EXISTS vn2008.unary_scan_line_expedition__;
|
||||
DROP TABLE IF EXISTS vn2008.warehouse_group__;
|
||||
DROP TABLE IF EXISTS vn2008.Espionajes__;
|
||||
DROP TABLE IF EXISTS vn2008.jerarquia__;
|
||||
DROP TABLE IF EXISTS vn2008.wks__;
|
||||
DROP TABLE IF EXISTS vn2008.Proveedores_comunicados__;
|
||||
DROP TABLE IF EXISTS vn2008.integra2_escala__;
|
||||
DROP TABLE IF EXISTS vn2008.cp__;
|
||||
DROP TABLE IF EXISTS vn2008.unary__;
|
||||
DROP TABLE IF EXISTS vn2008.Estados__;
|
||||
DROP TABLE IF EXISTS vn2008.agency_hour__;
|
||||
DROP TABLE IF EXISTS vn2008.Reservas__;
|
||||
DROP TABLE IF EXISTS vn2008.cyc_declaration__;
|
||||
DROP TABLE IF EXISTS vn2008.route__;
|
||||
DROP TABLE IF EXISTS vn2008.Proveedores_escritos__;
|
||||
DROP TABLE IF EXISTS vn2008.config__;
|
|
@ -0,0 +1,41 @@
|
|||
DROP TABLE IF EXISTS vn2008.form_query__;
|
||||
DROP TABLE IF EXISTS vn2008.filtros__;
|
||||
DROP TABLE IF EXISTS vn2008.Objetivos__;
|
||||
UPDATE IGNORE vn.province
|
||||
SET zoneFk = NULL
|
||||
WHERE zoneFk IN (
|
||||
SELECT zoneFk
|
||||
FROM vn.province
|
||||
WHERE zoneFk IS NOT NULL AND zoneFk NOT IN (SELECT id FROM vn.`zone`)
|
||||
);
|
||||
ALTER TABLE vn.province DROP FOREIGN KEY province_zone_fk;
|
||||
ALTER TABLE vn.province MODIFY COLUMN zoneFk int(11) DEFAULT NULL NULL;
|
||||
ALTER TABLE vn.province ADD CONSTRAINT
|
||||
province_zone_FK FOREIGN KEY (zoneFk) REFERENCES vn.`zone`(id) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
DROP TABLE IF EXISTS vn2008.zones__;
|
||||
DROP TABLE IF EXISTS vn2008.rec_translator__;
|
||||
DROP TABLE IF EXISTS vn2008.warehouse_joined__;
|
||||
DROP TABLE IF EXISTS vn2008.warehouse_filtro__;
|
||||
DROP TABLE IF EXISTS vn2008.viaxpress__;
|
||||
DROP TABLE IF EXISTS vn2008.cl_que__;
|
||||
DROP TABLE IF EXISTS vn2008.Recibos_recorded__;
|
||||
RENAME TABLE vn.coolerPathDetail TO vn.coolerPathDetail__;
|
||||
ALTER TABLE vn.coolerPathDetail__ DROP FOREIGN KEY coolerPathDetail_FK;
|
||||
DROP TABLE IF EXISTS vn2008.cooler_path__;
|
||||
DROP TABLE IF EXISTS vn2008.payrroll_apEmpresarial__;
|
||||
DROP TABLE IF EXISTS vn2008.Compres_ok__;
|
||||
DROP TABLE IF EXISTS vn2008.Movimientos_avisar__;
|
||||
DROP TABLE IF EXISTS vn2008.Clases__;
|
||||
DROP TABLE IF EXISTS vn2008.payroll_basess__;
|
||||
DROP TABLE IF EXISTS vn2008.payroll_tipobasess__;
|
||||
DROP TABLE IF EXISTS vn2008.guillen__;
|
||||
DROP TABLE IF EXISTS vn2008.guillen_carry__;
|
||||
DROP TABLE IF EXISTS vn2008.Series__;
|
||||
DROP TABLE IF EXISTS vn2008.Permisos__;
|
||||
ALTER TABLE vn.buy DROP FOREIGN KEY buy_FK_1;
|
||||
DROP TABLE IF EXISTS vn2008.container__;
|
||||
DROP TABLE IF EXISTS vn2008.travel_reserve__;
|
||||
DROP TABLE IF EXISTS vn2008.tmpNEWTARIFAS__;
|
||||
DROP TABLE IF EXISTS vn2008.Clientes_potenciales__;
|
||||
DROP TABLE IF EXISTS vn2008.duaDismissed__;
|
||||
DROP TABLE IF EXISTS vn2008.cl_pet__;
|
|
@ -0,0 +1,27 @@
|
|||
DROP TABLE IF EXISTS vn2008.expeditions_deleted__;
|
||||
DROP TABLE IF EXISTS vn2008.Tipos_f11__;
|
||||
DROP TABLE IF EXISTS vn2008.commission__;
|
||||
DROP TABLE IF EXISTS vn2008.Movimientos_revisar__;
|
||||
DROP TABLE IF EXISTS vn2008.recibida_agricola__;
|
||||
DROP TABLE IF EXISTS vn2008.tipsa__;
|
||||
DROP TABLE IF EXISTS vn2008.rounding__;
|
||||
DROP TABLE IF EXISTS vn2008.Informes__;
|
||||
DROP TABLE IF EXISTS vn2008.Monitoring__;
|
||||
DROP TABLE IF EXISTS vn2008.Forms__;
|
||||
DROP TABLE IF EXISTS vn2008.Clientes_event__;
|
||||
DROP TABLE IF EXISTS vn2008.wh_selection__;
|
||||
DROP TABLE IF EXISTS vn2008.template_bionic_component__;
|
||||
DROP TABLE IF EXISTS vn2008.Agencias_province__;
|
||||
DROP TABLE IF EXISTS vn2008.travel_pattern__;
|
||||
DROP TABLE IF EXISTS vn2008.sort_merge_results_ernesto__;
|
||||
DROP TABLE IF EXISTS vn2008.Conteo__;
|
||||
DROP TABLE IF EXISTS vn2008.Consignatarios_devices__;
|
||||
DROP TABLE IF EXISTS vn2008.link__;
|
||||
DROP TABLE IF EXISTS vn2008.agency_warehouse__;
|
||||
DROP TABLE IF EXISTS vn2008.warehouse_lc__;
|
||||
DROP TABLE IF EXISTS vn2008.emp_day_pay__;
|
||||
DROP TABLE IF EXISTS vn2008.Entradas_kop__;
|
||||
DROP TABLE IF EXISTS vn2008.dock__;
|
||||
DROP TABLE IF EXISTS vn2008.unaryScanFilter__;
|
||||
DROP TABLE IF EXISTS vn2008.Grupos__;
|
||||
DROP TABLE IF EXISTS vn2008.nichos__;
|
|
@ -0,0 +1,26 @@
|
|||
DROP TABLE IF EXISTS vn2008.preparation_exception__;
|
||||
DROP TABLE IF EXISTS vn2008.Clientes_empresa__;
|
||||
DROP TABLE IF EXISTS vn2008.call_information__;
|
||||
DROP TABLE IF EXISTS vn2008.template_bionic_price__;
|
||||
DROP TABLE IF EXISTS vn2008.invoice_observation__;
|
||||
DROP TABLE IF EXISTS vn2008.edi_testigos__;
|
||||
DROP TABLE IF EXISTS vn2008.cl_dep__;
|
||||
DROP TABLE IF EXISTS vn2008.agencia_descuadre__;
|
||||
DROP TABLE IF EXISTS vn2008.payroll_datos__;
|
||||
DROP TABLE IF EXISTS vn2008.tblIVA__;
|
||||
DROP TABLE IF EXISTS vn2008.cyc__;
|
||||
DROP TABLE IF EXISTS vn2008.Tickets_stack__;
|
||||
DROP TABLE IF EXISTS vn2008.config_host_forms__;
|
||||
DROP TABLE IF EXISTS vn2008.template_bionic_lot__;
|
||||
DROP TABLE IF EXISTS vn2008.payroll_bonificaciones__;
|
||||
DROP TABLE IF EXISTS vn2008.widget__;
|
||||
DROP TABLE IF EXISTS vn2008.accion_dits__;
|
||||
DROP TABLE IF EXISTS vn2008.credit_card__;
|
||||
DROP TABLE IF EXISTS vn2008.Brasa__;
|
||||
DROP TABLE IF EXISTS vn2008.Jefes__;
|
||||
DROP TABLE IF EXISTS vn2008.call_option__;
|
||||
DROP TABLE IF EXISTS vn2008.expeditions_pictures__;
|
||||
DROP TABLE IF EXISTS vn2008.scan__;
|
||||
DROP TABLE IF EXISTS vn2008.trolley__;
|
||||
DROP TABLE IF EXISTS vn2008.transport__;
|
||||
DROP TABLE IF EXISTS vn2008.Baldas__;
|
|
@ -0,0 +1,2 @@
|
|||
-- Place your SQL code here
|
||||
ALTER TABLE floranet.`order` ADD IF NOT EXISTS observations TEXT NULL;
|
|
@ -0,0 +1,3 @@
|
|||
-- Place your SQL code here
|
||||
INSERT INTO salix.ACL (model,property,accessType,permission,principalType,principalId)
|
||||
VALUES ('RouteConfig','*','READ','ALLOW','ROLE','employee');
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE vn.buy CHANGE containerFk containerFk__ smallint(5) unsigned DEFAULT NULL NULL;
|
|
@ -0,0 +1,9 @@
|
|||
-- Place your SQL code here
|
||||
CREATE OR REPLACE TABLE floranet.config (
|
||||
email varchar(255) DEFAULT 'floranet@verdnatura.es' NOT NULL
|
||||
)
|
||||
ENGINE=InnoDB
|
||||
DEFAULT CHARSET=utf8mb3
|
||||
COLLATE=utf8mb3_unicode_ci;
|
||||
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
-- Place your SQL code here
|
||||
DROP TABLE IF EXISTS floranet.builder;
|
||||
|
||||
CREATE OR REPLACE TABLE floranet.`element` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(30) NOT NULL,
|
||||
`itemFk` int(11) DEFAULT NULL,
|
||||
`longNameFilter` varchar(30) DEFAULT NULL,
|
||||
`typeFk` smallint(5) unsigned DEFAULT NULL,
|
||||
`minSize` int(10) unsigned DEFAULT NULL,
|
||||
`maxSize` int(10) unsigned DEFAULT NULL,
|
||||
`inkFk` char(3) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL,
|
||||
`originFk` tinyint(2) unsigned DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `element_FK` (`itemFk`),
|
||||
KEY `element_FK_1` (`typeFk`),
|
||||
KEY `element_FK_2` (`inkFk`),
|
||||
KEY `element_FK_3` (`originFk`),
|
||||
CONSTRAINT `element_FK` FOREIGN KEY (`itemFk`) REFERENCES `vn`.`item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `element_FK_1` FOREIGN KEY (`typeFk`) REFERENCES `vn`.`itemType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `element_FK_2` FOREIGN KEY (`inkFk`) REFERENCES `vn`.`ink` (`id`) ON UPDATE CASCADE,
|
||||
CONSTRAINT `element_FK_3` FOREIGN KEY (`originFk`) REFERENCES `vn`.`origin` (`id`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Filtro para localizar posibles items que coincidan con la descripción';
|
||||
|
||||
CREATE OR REPLACE TABLE floranet.`recipe` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`itemFk` int(11) NOT NULL,
|
||||
`elementFk` int(11) NOT NULL,
|
||||
`quantity` int(10) unsigned NOT NULL DEFAULT 1,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `recipe_FK` (`itemFk`),
|
||||
KEY `recipe_FK_1` (`elementFk`),
|
||||
CONSTRAINT `recipe_FK` FOREIGN KEY (`itemFk`) REFERENCES `vn`.`item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `recipe_element_FK` FOREIGN KEY (`elementFk`) REFERENCES `element` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Links handmade products with their elements';
|
|
@ -51,7 +51,7 @@ describe('Client Add address path', () => {
|
|||
await page.waitToClick(selectors.clientAddresses.saveButton);
|
||||
const message = await page.waitForSnackbar();
|
||||
|
||||
expect(message.text).toContain('Incoterms is required for a non UEE member');
|
||||
expect(message.text).toContain('Incoterms and Customs agent are required for a non UEE member');
|
||||
});
|
||||
|
||||
it(`should receive an error after clicking save button as customsAgent is empty`, async() => {
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
import selectors from '../../helpers/selectors.js';
|
||||
import getBrowser from '../../helpers/puppeteer';
|
||||
|
||||
describe('Worker pda path', () => {
|
||||
let browser;
|
||||
let page;
|
||||
beforeAll(async() => {
|
||||
browser = await getBrowser();
|
||||
page = browser.page;
|
||||
await page.loginAndModule('hr', 'worker');
|
||||
await page.accessToSearchResult('employeeNick');
|
||||
await page.accessToSection('worker.card.pda');
|
||||
});
|
||||
|
||||
afterAll(async() => {
|
||||
await browser.close();
|
||||
});
|
||||
|
||||
it('should check if worker has already a PDA allocated', async() => {
|
||||
expect(await page.waitToGetProperty(selectors.workerPda.currentPDA, 'value')).toContain('serialNumber1');
|
||||
});
|
||||
|
||||
it('should deallocate the PDA', async() => {
|
||||
await page.waitToClick(selectors.workerPda.delete);
|
||||
let message = await page.waitForSnackbar();
|
||||
|
||||
expect(message.text).toContain('PDA deallocated');
|
||||
});
|
||||
|
||||
it('should allocate a new PDA', async() => {
|
||||
await page.autocompleteSearch(selectors.workerPda.newPDA, 'serialNumber2');
|
||||
await page.waitToClick(selectors.workerPda.submit);
|
||||
let message = await page.waitForSnackbar();
|
||||
|
||||
expect(message.text).toContain('PDA allocated');
|
||||
});
|
||||
|
||||
it('should check if a new PDA has been allocated', async() => {
|
||||
expect(await page.waitToGetProperty(selectors.workerPda.currentPDA, 'value')).toContain('serialNumber2');
|
||||
});
|
||||
});
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
module.exports = function(Self) {
|
||||
require('../methods/application/status')(Self);
|
||||
require('../methods/application/post')(Self);
|
||||
|
|
|
@ -223,7 +223,11 @@
|
|||
"printerNotExists": "The printer does not exist",
|
||||
"There are not picking tickets": "There are not picking tickets",
|
||||
"ticketCommercial": "The ticket {{ ticket }} for the salesperson {{ salesMan }} is in preparation. (automatically generated message)",
|
||||
"This password can only be changed by the user themselves": "This password can only be changed by the user themselves",
|
||||
"They're not your subordinate": "They're not your subordinate",
|
||||
"InvoiceIn is already booked": "InvoiceIn is already booked"
|
||||
"This password can only be changed by the user themselves": "This password can only be changed by the user themselves",
|
||||
"They're not your subordinate": "They're not your subordinate",
|
||||
"InvoiceIn is already booked": "InvoiceIn is already booked",
|
||||
"This workCenter is already assigned to this agency": "This workCenter is already assigned to this agency",
|
||||
"You can only have one PDA": "You can only have one PDA",
|
||||
"Incoterms and Customs agent are required for a non UEE member": "Incoterms and Customs agent are required for a non UEE member"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -355,6 +355,10 @@
|
|||
"No results found": "No se han encontrado resultados",
|
||||
"InvoiceIn is already booked": "La factura recibida está contabilizada",
|
||||
"This workCenter is already assigned to this agency": "Este centro de trabajo ya está asignado a esta agencia",
|
||||
"Select ticket or client": "Elija un ticket o un client",
|
||||
"It was not able to create the invoice": "No se pudo crear la factura"
|
||||
"Select ticket or client": "Elija un ticket o un client",
|
||||
"It was not able to create the invoice": "No se pudo crear la factura",
|
||||
"ticketCommercial": "El ticket {{ ticket }} para el vendedor {{ salesMan }} está en preparación. (mensaje generado automáticamente)",
|
||||
"This PDA is already assigned to another user": "Este PDA ya está asignado a otro usuario",
|
||||
"You can only have one PDA": "Solo puedes tener un PDA",
|
||||
"Incoterms and Customs agent are required for a non UEE member": "Se requieren Incoterms y agente de aduanas para un no miembro de la UEE"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = (localAsProduction = true) => {
|
||||
return (!process.env.NODE_ENV && localAsProduction) || process.env.NODE_ENV == 'production';
|
||||
};
|
|
@ -3,9 +3,10 @@ const app = require('vn-loopback/server/server');
|
|||
const ldap = require('../util/ldapjs-extra');
|
||||
const crypto = require('crypto');
|
||||
const nthash = require('smbhash').nthash;
|
||||
const isProduction = require('vn-loopback/server/boot/isProduction');
|
||||
|
||||
module.exports = Self => {
|
||||
const shouldSync = process.env.NODE_ENV !== 'test';
|
||||
const shouldSync = isProduction();
|
||||
|
||||
Self.getLinker = async function() {
|
||||
return await Self.findOne({
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
const ldap = require('../util/ldapjs-extra');
|
||||
const execFile = require('child_process').execFile;
|
||||
const isProduction = require('vn-loopback/server/boot/isProduction');
|
||||
|
||||
/**
|
||||
* Summary of userAccountControl flags:
|
||||
|
@ -12,7 +13,7 @@ const UserAccountControlFlags = {
|
|||
};
|
||||
|
||||
module.exports = Self => {
|
||||
const shouldSync = process.env.NODE_ENV !== 'test';
|
||||
const shouldSync = isProduction();
|
||||
|
||||
Self.getLinker = async function() {
|
||||
return await Self.findOne({
|
||||
|
|
|
@ -92,11 +92,8 @@ module.exports = function(Self) {
|
|||
}, myOptions);
|
||||
|
||||
const isUeeMember = province.country().isUeeMember;
|
||||
if (!isUeeMember && !args.incotermsFk)
|
||||
throw new UserError(`Incoterms is required for a non UEE member`);
|
||||
|
||||
if (!isUeeMember && !args.customsAgentFk)
|
||||
throw new UserError(`Customs agent is required for a non UEE member`);
|
||||
if (!isUeeMember && (!args.incotermsFk || !args.customsAgentFk))
|
||||
throw new UserError(`Incoterms and Customs agent are required for a non UEE member`);
|
||||
|
||||
delete args.ctx; // Remove unwanted properties
|
||||
const newAddress = await models.Address.create(args, myOptions);
|
||||
|
|
|
@ -95,9 +95,11 @@ module.exports = function(Self) {
|
|||
myOptions
|
||||
);
|
||||
} else if (accountingType.isAutoConciliated == true) {
|
||||
const description = `${originalClient.id} : ${originalClient.socialName} - ${accountingType.receiptDescription}`;
|
||||
const [xdiarioNew] = await Self.rawSql(
|
||||
`SELECT xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ledger;`,
|
||||
const description =
|
||||
`${originalClient.id} : ${originalClient.socialName} - ${accountingType.receiptDescription}`;
|
||||
const [, [xdiarioNew]] = await Self.rawSql(
|
||||
`CALL xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @xdiarioNew);
|
||||
SELECT @xdiarioNew ledger;`,
|
||||
[
|
||||
null,
|
||||
date,
|
||||
|
@ -118,7 +120,7 @@ module.exports = function(Self) {
|
|||
);
|
||||
|
||||
await Self.rawSql(
|
||||
`SELECT xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`,
|
||||
`CALL xdiario_new(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @xdiarioNew);`,
|
||||
[
|
||||
xdiarioNew.ledger,
|
||||
date,
|
||||
|
|
|
@ -50,7 +50,7 @@ describe('Address createAddress', () => {
|
|||
}
|
||||
|
||||
expect(error).toBeDefined();
|
||||
expect(error.message).toEqual('Incoterms is required for a non UEE member');
|
||||
expect(error.message).toEqual('Incoterms and Customs agent are required for a non UEE member');
|
||||
});
|
||||
|
||||
it('should throw a non uee member error if no customsAgent is defined', async() => {
|
||||
|
@ -81,7 +81,7 @@ describe('Address createAddress', () => {
|
|||
}
|
||||
|
||||
expect(error).toBeDefined();
|
||||
expect(error.message).toEqual('Customs agent is required for a non UEE member');
|
||||
expect(error.message).toEqual('Incoterms and Customs agent are required for a non UEE member');
|
||||
});
|
||||
|
||||
it('should create a new address and set as a client default address', async() => {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const got = require('got');
|
||||
const UserError = require('vn-loopback/util/user-error');
|
||||
const isProduction = require('vn-loopback/server/boot/isProduction');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('send', {
|
||||
|
@ -47,7 +48,7 @@ module.exports = Self => {
|
|||
|
||||
let response;
|
||||
try {
|
||||
if (process.env.NODE_ENV !== 'production')
|
||||
if (!isProduction(false))
|
||||
response = {result: [{status: 'ok'}]};
|
||||
else {
|
||||
const jsonTest = {
|
||||
|
|
|
@ -76,7 +76,6 @@ module.exports = Self => {
|
|||
packing: buyUltimate.packing,
|
||||
grouping: buyUltimate.grouping,
|
||||
groupingMode: buyUltimate.groupingMode,
|
||||
containerFk: buyUltimate.containerFk,
|
||||
comissionValue: buyUltimate.comissionValue,
|
||||
packageValue: buyUltimate.packageValue,
|
||||
location: buyUltimate.location,
|
||||
|
|
|
@ -63,9 +63,6 @@
|
|||
"isIgnored": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"containerFk": {
|
||||
"type": "number"
|
||||
},
|
||||
"location": {
|
||||
"type": "number"
|
||||
},
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const isProduction = require('vn-loopback/server/boot/isProduction');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('download', {
|
||||
|
@ -66,7 +67,7 @@ module.exports = Self => {
|
|||
console.error(err);
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV == 'test') {
|
||||
if (!isProduction()) {
|
||||
try {
|
||||
await fs.access(file.path);
|
||||
} catch (error) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const print = require('vn-print');
|
||||
const path = require('path');
|
||||
const UserError = require('vn-loopback/util/user-error');
|
||||
const isProduction = require('vn-loopback/server/boot/isProduction');
|
||||
|
||||
module.exports = Self => {
|
||||
require('../methods/invoiceOut/filter')(Self);
|
||||
|
@ -59,7 +60,7 @@ module.exports = Self => {
|
|||
hasPdf: true
|
||||
}, options);
|
||||
|
||||
if (process.env.NODE_ENV !== 'test') {
|
||||
if (isProduction()) {
|
||||
await print.storage.write(buffer, {
|
||||
type: 'invoice',
|
||||
path: pdfFile.path,
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<vn-autocomplete
|
||||
url="Tickets"
|
||||
label="Ticket"
|
||||
search-function="{or: [{id: $search}, {nickname: {like: '%'+$search+'%'}}]}"
|
||||
search-function="{refFk: null, or: [{id: $search}, {nickname: {like: '%'+$search+'%'}}]}"
|
||||
show-field="id"
|
||||
value-field="id"
|
||||
fields="['nickname']"
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue