feat: refs #4948 Added ticket_doSelfConsumptionPackaging proc & event #2262

Closed
guillermo wants to merge 15 commits from 4948-procTicketSelfConsumption into dev
Member
No description provided.
guillermo added 1 commit 2024-04-05 10:27:52 +00:00
guillermo added 1 commit 2024-04-05 10:34:38 +00:00
gitea/salix/pipeline/pr-dev This commit looks good Details
bdc202b145
feat: refs #4948 Minor change
guillermo requested review from carlosap 2024-04-05 10:37:21 +00:00
carlosap requested review from jgallego 2024-04-05 12:24:06 +00:00
jgallego requested changes 2024-04-06 05:22:39 +00:00
Dismissed
@ -0,0 +31,4 @@
JOIN packaging p ON p.id = e.packagingFk
JOIN item i ON i.id = p.itemFk
WHERE e.created BETWEEN vDateFrom AND util.dayEnd(vDateTo)
GROUP BY e.packagingFk;
Owner

@pako creà el cau, hi ha que valorar si es llança en un rango de una semana o un mes, si volem que es cree sols un ticket amb tots els embalatges, o que faça un ticket per dia.
Hi haurà casos que fallarà el procés, per tant, el seguen dia que es llance posaria els dos dies junts en un ticket, lo cual per a fer revisions o comprobacions serà molt confús.
Cal també saber si s'ha llançat o no, per a que no torne a insertar els mateixos embalatges, pe mirar que no existisca previament un ticket i si hi ha borrar el contingut y insertar de nou.

@pako creà el cau, hi ha que valorar si es llança en un rango de una semana o un mes, si volem que es cree sols un ticket amb tots els embalatges, o que faça un ticket per dia. Hi haurà casos que fallarà el procés, per tant, el seguen dia que es llance posaria els dos dies junts en un ticket, lo cual per a fer revisions o comprobacions serà molt confús. Cal també saber si s'ha llançat o no, per a que no torne a insertar els mateixos embalatges, pe mirar que no existisca previament un ticket i si hi ha borrar el contingut y insertar de nou.
Member

Jo voldría un ticket per dia. Es podría fer un consignatari en el client 450 que fora el dels embalatges, i així es podría comprovar si existeix el ticket o no. El proc deuria de revisar i fer, si cal, els tickets de la última setmana, cada nit

Jo voldría un ticket per dia. Es podría fer un consignatari en el client 450 que fora el dels embalatges, i així es podría comprovar si existeix el ticket o no. El proc deuria de revisar i fer, si cal, els tickets de la última setmana, cada nit
guillermo marked this conversation as resolved
guillermo added 1 commit 2024-04-09 07:01:31 +00:00
gitea/salix/pipeline/pr-dev This commit looks good Details
03b06b906e
Merge branch 'dev' into 4948-procTicketSelfConsumption
Member

He marcat sense voler el crear commit....

He marcat sense voler el crear commit....
carlosap refused to review 2024-04-18 11:32:03 +00:00
guillermo added 1 commit 2024-10-29 12:55:09 +00:00
gitea/salix/pipeline/pr-dev This commit looks good Details
4db04f93d4
Merge branch 'dev' into 4948-procTicketSelfConsumption
guillermo added 2 commits 2024-10-29 13:25:11 +00:00
guillermo added 1 commit 2024-11-07 11:21:55 +00:00
guillermo added 1 commit 2024-11-07 11:22:08 +00:00
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
005b698bbd
Merge branch 'dev' into 4948-procTicketSelfConsumption
guillermo added 2 commits 2024-11-07 11:24:45 +00:00
guillermo added 1 commit 2024-11-07 11:57:36 +00:00
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
ad3b9ce365
feat: refs #4948 Version expedition_undoSelfConsumptionPackaging
guillermo requested review from jgallego 2024-11-07 11:57:44 +00:00
jgallego requested changes 2024-11-08 07:59:24 +00:00
Dismissed
jgallego left a comment
Owner

CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`expedition_selfConsumptionPackaging`(
    vSelf INT,
    vAction ENUM('add', 'remove')
)
BEGIN
/**
* Maneja el consumo de cajas para autoconsumo, permitiendo añadir o quitar cajas utilizadas
* según la acción indicada.
*
* @param vSelf Id de expedición
* @param vAction Acción a realizar ('add' para añadir, 'remove' para quitar)
*/
    DECLARE vClientFk INT;
    DECLARE vAddressFk INT;
    DECLARE vItemFk INT;
    DECLARE vItemName VARCHAR(50);
    DECLARE vWarehouseFk INT;
    DECLARE vCurdate DATE;
    DECLARE vTicketFk INT;
    DECLARE vSaleFk INT;
    DECLARE vQuantity INT;

    -- Obtiene datos básicos para el autoconsumo
    SELECT pc.clientSelfConsumptionFk,
           pc.addressSelfConsumptionFk,
           i.id,
           i.name,
           t.warehouseFk
    INTO vClientFk,
         vAddressFk,
         vItemFk,
         vItemName,
         vWarehouseFk
    FROM expedition e
         JOIN packaging p ON p.id = e.packagingFk
         JOIN item i ON i.id = p.itemFk
         JOIN ticket t ON t.id = e.ticketFk
         JOIN productionConfig pc
    WHERE e.id = vSelf;

    -- Verifica si los parámetros necesarios están configurados
    IF vClientFk IS NULL OR vAddressFk IS NULL THEN
        CALL util.throw('Some config parameters are not set');
    END IF;

    SET vCurdate = util.VN_CURDATE();

    -- Busca un ticket existente para autoconsumo en la fecha y ubicación actuales
    SELECT id INTO vTicketFk
    FROM ticket
    WHERE shipped BETWEEN vCurdate AND util.dayEnd(vCurdate)
          AND clientFk = vClientFk
          AND addressFk = vAddressFk
          AND warehouseFk = vWarehouseFk;

    IF vTicketFk IS NULL AND vAction = 'add' THEN
        -- Crea un nuevo ticket si no existe y la acción es "add"
        INSERT INTO ticket(clientFk, warehouseFk, shipped, nickname, addressFk)
        VALUES (vClientFk, vWarehouseFk, vCurdate, 'CAJAS AUTOCONSUMO', vAddressFk);

        SET vTicketFk = LAST_INSERT_ID();
    END IF;

    -- Verifica si ya existe una venta de la caja en el ticket de autoconsumo
    SELECT id, quantity INTO vSaleFk, vQuantity
    FROM sale
    WHERE itemFk = vItemFk
          AND ticketFk = vTicketFk
    LIMIT 1;

    IF vAction = 'add' THEN
        IF vSaleFk IS NOT NULL THEN
            -- Actualiza la cantidad si ya existe la venta
            UPDATE sale
            SET quantity = quantity + 1
            WHERE id = vSaleFk;
        ELSE
            -- Inserta una nueva venta si no existe
            INSERT INTO sale(itemFk, ticketFk, concept, quantity)
            VALUES (vItemFk, vTicketFk, vItemName, 1);
        END IF;

    ELSEIF vAction = 'remove' THEN
        IF vSaleFk IS NOT NULL THEN
            IF vQuantity <= 1 THEN
                -- Elimina la venta si la cantidad es 1 o menor
                DELETE FROM sale WHERE id = vSaleFk;
            ELSE
                -- Decrementa la cantidad si es mayor a 1
                UPDATE sale
                SET quantity = quantity - 1
                WHERE id = vSaleFk;
            END IF;
        END IF;
    END IF;

END$$

DELIMITER ;

Jo crearia sols un perque hi ha molt de codi repetit en els dos i qualsevol canvia haurem de replicarlo, açò es una proposta de chatGpt

```DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`expedition_selfConsumptionPackaging`( vSelf INT, vAction ENUM('add', 'remove') ) BEGIN /** * Maneja el consumo de cajas para autoconsumo, permitiendo añadir o quitar cajas utilizadas * según la acción indicada. * * @param vSelf Id de expedición * @param vAction Acción a realizar ('add' para añadir, 'remove' para quitar) */ DECLARE vClientFk INT; DECLARE vAddressFk INT; DECLARE vItemFk INT; DECLARE vItemName VARCHAR(50); DECLARE vWarehouseFk INT; DECLARE vCurdate DATE; DECLARE vTicketFk INT; DECLARE vSaleFk INT; DECLARE vQuantity INT; -- Obtiene datos básicos para el autoconsumo SELECT pc.clientSelfConsumptionFk, pc.addressSelfConsumptionFk, i.id, i.name, t.warehouseFk INTO vClientFk, vAddressFk, vItemFk, vItemName, vWarehouseFk FROM expedition e JOIN packaging p ON p.id = e.packagingFk JOIN item i ON i.id = p.itemFk JOIN ticket t ON t.id = e.ticketFk JOIN productionConfig pc WHERE e.id = vSelf; -- Verifica si los parámetros necesarios están configurados IF vClientFk IS NULL OR vAddressFk IS NULL THEN CALL util.throw('Some config parameters are not set'); END IF; SET vCurdate = util.VN_CURDATE(); -- Busca un ticket existente para autoconsumo en la fecha y ubicación actuales SELECT id INTO vTicketFk FROM ticket WHERE shipped BETWEEN vCurdate AND util.dayEnd(vCurdate) AND clientFk = vClientFk AND addressFk = vAddressFk AND warehouseFk = vWarehouseFk; IF vTicketFk IS NULL AND vAction = 'add' THEN -- Crea un nuevo ticket si no existe y la acción es "add" INSERT INTO ticket(clientFk, warehouseFk, shipped, nickname, addressFk) VALUES (vClientFk, vWarehouseFk, vCurdate, 'CAJAS AUTOCONSUMO', vAddressFk); SET vTicketFk = LAST_INSERT_ID(); END IF; -- Verifica si ya existe una venta de la caja en el ticket de autoconsumo SELECT id, quantity INTO vSaleFk, vQuantity FROM sale WHERE itemFk = vItemFk AND ticketFk = vTicketFk LIMIT 1; IF vAction = 'add' THEN IF vSaleFk IS NOT NULL THEN -- Actualiza la cantidad si ya existe la venta UPDATE sale SET quantity = quantity + 1 WHERE id = vSaleFk; ELSE -- Inserta una nueva venta si no existe INSERT INTO sale(itemFk, ticketFk, concept, quantity) VALUES (vItemFk, vTicketFk, vItemName, 1); END IF; ELSEIF vAction = 'remove' THEN IF vSaleFk IS NOT NULL THEN IF vQuantity <= 1 THEN -- Elimina la venta si la cantidad es 1 o menor DELETE FROM sale WHERE id = vSaleFk; ELSE -- Decrementa la cantidad si es mayor a 1 UPDATE sale SET quantity = quantity - 1 WHERE id = vSaleFk; END IF; END IF; END IF; END$$ DELIMITER ; ``` Jo crearia sols un perque hi ha molt de codi repetit en els dos i qualsevol canvia haurem de replicarlo, açò es una proposta de chatGpt
@ -0,0 +57,4 @@
SELECT id INTO vSaleFk
FROM sale
WHERE itemFk = vItemFk
AND ticketFk = vTicketFk;
Owner

ací podrien haver varies linies i donaria fallo, posat limit 1

ací podrien haver varies linies i donaria fallo, posat limit 1
guillermo marked this conversation as resolved
guillermo added 1 commit 2024-11-08 08:40:33 +00:00
gitea/salix/pipeline/pr-dev There was a failure building this commit Details
927e837a29
feat: refs #4948 Requested changes
guillermo requested review from jgallego 2024-11-08 08:40:33 +00:00
jgallego approved these changes 2024-11-08 09:00:40 +00:00
juan closed this pull request 2024-11-11 06:33:56 +00:00
juan reopened this pull request 2024-11-11 06:34:01 +00:00
guillermo closed this pull request 2024-11-11 06:36:56 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: verdnatura/salix#2262
No description provided.