DELIMITER $$;
CREATE TRIGGER copy_data_inserted_entetecommercials 
AFTER INSERT ON entetecommercials
    FOR EACH ROW 
        BEGIN
           INSERT INTO integration_nomadis_alpha.facturation_nomadis_alpha 
                        (
                            id, code, type, export, soussociete_code, commercial_code, user_code, 
                            creer_par, depot_code, client_code, date, tax, taux_tva, timbre, mode_paiement, 
                            montant_total_ht, montant_total_ttc, montant_total_tva, retenue_source, net_a_payer, 
                            net_a_payer_ht, remise_ht, remise, remiseEspece, remise_pied, longitude, latitude, 
                            adresse, date_prevu_livraison, solde, commentaire, deleted_at, created_at, updated_at)
            VALUES 
            (
                NEW.id, NEW.code, NEW.type, NEW.export,  NEW.soussociete_code, NEW.commercial_code, 
                NEW.user_code, NEW.creer_par, NEW.depot_code, NEW.client_code, NEW.date, NEW.tax, NEW.taux_tva, NEW.timbre, 
                NEW.mode_paiement, NEW.montant_total_ht, NEW.montant_total_ttc, NEW.montant_total_tva, NEW.retenue_source, 
                NEW.net_a_payer, NEW.net_a_payer_ht, NEW.remise_ht, NEW.remise, NEW.remiseEspece, NEW.remise_pied, NEW.longitude, 
                NEW.latitude, NEW.adresse, NEW.date_prevu_livraison, NEW.solde, NEW.commentaire, NEW.deleted_at, NEW.created_at, 
                NEW.updated_at
            );
        END;



DELIMITER $$;
CREATE TRIGGER copy_data_inserted_lignes
AFTER INSERT ON lignecommercials
    FOR EACH ROW 
        BEGIN
           INSERT INTO integration_nomadis_alpha.facturation_lignes_nomadis_alpha
           (  id, entetecommercial_code, commercial_code, depot_code, commentaire, 
                produit_code, num_lot, quantite, pu_ht, pu_ttc, p_tva, prix_achat_ht, 
                prix_achat_ttc, taux_tva, total, total_net, total_ht, total_net_ht, 
                remise, remise_client, type, export, deleted_at, created_at, updated_at) 
           VALUES
            (
            NEW.id, NEW.entetecommercial_code, NEW.commercial_code, NEW.depot_code, NEW.commentaire, 
            NEW.produit_code, NEW.num_lot, NEW.quantite, NEW.pu_ht, NEW.pu_ttc, NEW.p_tva, NEW.prix_achat_ht, 
            NEW.prix_achat_ttc, NEW.taux_tva, NEW.total, NEW.total_net, NEW.total_ht, NEW.total_net_ht, 
            NEW.remise, NEW.remise_client, NEW.type, NEW.export, NEW.deleted_at, NEW.created_at, NEW.updated_at
            );
        END;

