Topic: Pubblico - Composto da 7 Posts di 3 Utenti.
| 04 Luglio, 2011 08:09 | #1 | ||
|---|---|---|---|
|
Ciao a tutti, Sapete darmi qualche dritta?? |
|||
| 14 Luglio, 2011 07:33 | #2 | ||
|---|---|---|---|
|
Ciao viviana bentornata.. non ho capito nulla ... i'm sorry... mi ripeti un pò tutto? grazie Un tempo ero algweb ora sono g2d |
|||
| 14 Luglio, 2011 07:45 | #3 | ||
|---|---|---|---|
|
Ciao, e grazie... Allora queste sono le tabelle 1CREATE TABLE IF NOT EXISTS `documento_vendita`( 2 `tipo_tupla` enum('0','1','2','3') NOT NULL, 3 `data_creazione` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 4 `id` int(11) NOT NULL AUTO_INCREMENT, 5 `n` int(11) NOT NULL, 6 `anno` int(4) NOT NULL, 7 `data` date NOT NULL, 8 `totale` decimal(10,2) NOT NULL, 9 `cliente` int(11) NOT NULL, 10 `differita` tinyint(1) NOT NULL DEFAULT '0', 11 `nota` tinyint(1) NOT NULL DEFAULT '0', 12 `rif_fattura` INT(11), 13 `dipendente` varchar(16) NOT NULL, 14 FOREIGN KEY ( `rif_fattura`) REFERENCES documento_vendita(`id`) , 15 PRIMARY KEY (`id`), 16 KEY `documento_vendita_ibfk_1` (`cliente`), 17 KEY `documento_vendita_ibfk_2` (`dipendente`) 18 ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 19 20CREATE TABLE IF NOT EXISTS `articolo_appartiene_a_documento_vendita` ( 21 `codice` int(11) NOT NULL, 22 `id` int(11) NOT NULL, 23 `sconto` int(11) DEFAULT '0', 24 `prezzo_vendita` decimal(10,2) NOT NULL, 25 `quantita` decimal(10,2) NOT NULL DEFAULT '1', 26 `iva` decimal(10,2) NOT NULL, 27 `in_ddt` tinyint(1) NOT NULL DEFAULT '0', 28 FOREIGN KEY (codice) references articolo(codice), 29 FOREIGN KEY (id) references documento_vendita(id), 30 PRIMARY KEY (`codice`,`id`) 31) ENGINE=InnoDB DEFAULT CHARSET=utf8; e questo il trigger (quello per l'inserimento) 1CREATE TRIGGER`totale_documento_vendita_insert` BEFORE INSERT ON `articolo_appartiene_a_documento_vendita` 2 FOR EACH ROW BEGIN 3 4 DECLARE tot_imp_articolo decimal; 5 DECLARE iva_articolo int; 6 DECLARE tot_iva_articolo decimal; 7 DECLARE sconto decimal; 8 DECLARE tipo_doc char; 9 DECLARE giacenza_attuale decimal; 10 11 SELECT IVA from articolo where codice = new.codice INTO iva_articolo; 12 SET sconto = new.prezzo_vendita*new.sconto/100; 13 SET tot_imp_articolo = new.prezzo_vendita - sconto; 14 SET tot_iva_articolo = tot_imp_articolo * iva_articolo / 100; 15 update documento_vendita 16 SET totale = totale + ((tot_imp_articolo + tot_iva_articolo))*new.quantita 17 where id = new.id; 18 SELECT tipo_tupla FROM documento_vendita WHERE id = new.id INTO tipo_doc; 19 SELECT giacenza FROM articolo WHERE codice = new.codice INTO giacenza_attuale; 20 IF tipo_doc = '2' THEN 21 UPDATE articolo SET giacenza = giacenza_attuale - new.quantita WHERE codice = new.codice; 22 ELSE 23 UPDATE articolo SET giacenza = 0 WHERE codice = new.codice; 24 END IF; 25 END; ho notato,facendo la somma dei valori con php, che pur usando valori di tipo decimal la somma fatta dal trigger viene arrotondata e ovviamente non è ciò che voglio dato che si tratta di documenti. Spero di essere stata un po' più chiara. |
|||
| 14 Luglio, 2011 10:13 | #4 | ||
|---|---|---|---|
|
ad occhio e croce, dichiarando il decimal nel trigger non dovresti indicare anche il numero di interi e decimali? Salvatore DC La mente è come un paracadute: funziona solo se si apre. A.Einstein. |
|||
| 18 Luglio, 2011 07:18 | #5 | ||
|---|---|---|---|
|
mmm sinceramente non lo so..però ora provo! |
|||
| 18 Luglio, 2011 07:47 | #6 | ||
|---|---|---|---|
|
GRAZIE..il problema sembra risolto. |
|||
| 18 Luglio, 2011 11:17 | #7 | ||
|---|---|---|---|
|
prego :) Salvatore DC La mente è come un paracadute: funziona solo se si apre. A.Einstein. |
|||
Condividi su:
Loggati o Registrati per replicare