manuelle und automatische Fakturierung
This commit is contained in:
parent
6b63816738
commit
290c075016
17
MySQL/LFitze/1-Erweiterung DDL + DML-LFI.txt
Normal file
17
MySQL/LFitze/1-Erweiterung DDL + DML-LFI.txt
Normal file
@ -0,0 +1,17 @@
|
||||
//Erweiterung Abrechnung
|
||||
ALTER TABLE abrechnung
|
||||
ADD date TIMESTAMP DEFAULT NOW();
|
||||
|
||||
ALTER TABLE abrechnung
|
||||
ADD isFakturiert bool DEFAULT false;
|
||||
|
||||
|
||||
//neue Tabelle Rechnung_kunde
|
||||
CREATE TABLE rechnung_kunde
|
||||
(
|
||||
rgId INT AUTO_INCREMENT PRIMARY KEY,
|
||||
fkAbrechnung INT UNSIGNED ,
|
||||
FOREIGN KEY (fkAbrechnung) REFERENCES abrechnung(abrechnung_id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
|
40
MySQL/LFitze/2-SoreProcedur-PodBill-und-Triggerl-LFI.txt
Normal file
40
MySQL/LFitze/2-SoreProcedur-PodBill-und-Triggerl-LFI.txt
Normal file
@ -0,0 +1,40 @@
|
||||
//Store Procedure PodBill
|
||||
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE PodBill
|
||||
(
|
||||
_abrechnungsId INT
|
||||
)
|
||||
|
||||
BEGIN
|
||||
|
||||
IF EXISTS(SELECT isFakturiert FROM abrechnung WHERE abrechnung_id = _abrechnungsId AND isFakturiert = 1) THEN
|
||||
SIGNAL SQLSTATE '45000'
|
||||
SET MESSAGE_TEXT = 'Fehler: Bestellung bereits verrechnet';
|
||||
END IF;
|
||||
|
||||
INSERT INTO rechnung_kunde(fkAbrechnung)
|
||||
VALUE(_abrechnungsId);
|
||||
|
||||
END //
|
||||
DELIMITER ;
|
||||
|
||||
|
||||
//trigger wo 0 zu 1 macht!
|
||||
|
||||
DELIMITER //
|
||||
CREATE TRIGGER tr_createRgKunde_after
|
||||
AFTER INSERT
|
||||
ON rechnung_kunde
|
||||
FOR EACH ROW
|
||||
|
||||
BEGIN
|
||||
UPDATE abrechnung
|
||||
SET isFakturiert = 1
|
||||
WHERE abrechnung_id = new.fkAbrechnung
|
||||
;
|
||||
|
||||
END //
|
||||
DELIMITER ;
|
||||
|
||||
|
42
MySQL/LFitze/3-StoreProcedur-CheckHasBill-und-Event-LFI.txt
Normal file
42
MySQL/LFitze/3-StoreProcedur-CheckHasBill-und-Event-LFI.txt
Normal file
@ -0,0 +1,42 @@
|
||||
DELIMITER //
|
||||
CREATE EVENT IF NOT EXISTS create_rg_kunde
|
||||
ON SCHEDULE EVERY DAY
|
||||
|
||||
DO
|
||||
CALL CheckHasBillProcedure();
|
||||
;
|
||||
DELIMITER ;
|
||||
|
||||
|
||||
DELIMITER //
|
||||
CREATE PROCEDURE CheckHasBillProcedure
|
||||
(
|
||||
|
||||
)
|
||||
|
||||
BEGIN
|
||||
DECLARE currentID INT;
|
||||
DECLARE hasNext BOOL DEFAULT TRUE;
|
||||
|
||||
DECLARE myRows CURSOR FOR
|
||||
SELECT abrechnung_id From abrechnung
|
||||
WHERE isFakturiert = 0
|
||||
GROUP BY kundenkonto_fk, date
|
||||
HAVING SUM(betrag) > 100 OR (datediff(now(), abrechnung.date) > 90);
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND
|
||||
SET hasNext = false;
|
||||
|
||||
OPEN myRows;
|
||||
|
||||
processingLoop : LOOP
|
||||
FETCH myRows INTO currentId;
|
||||
IF hasNExt = FALSE THEN
|
||||
LEAVE processingLoop;
|
||||
END IF;
|
||||
CALL PodBill(currentId);
|
||||
|
||||
END LOOP;
|
||||
|
||||
END //
|
||||
DELIMITER ;
|
Loading…
Reference in New Issue
Block a user