/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Controllers.Traitement;

import java.io.File;
import java.io.IOException;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;


/**
 * @author Maher
 */
public class ParametreSystem 
{
    public static String JdbcUrl ;
    public static String JdbcDB ;
    public static String JdbcUser ;
    public static String JdbcPassword ;
    
    public static String CompanyName ;        
    public static String CompanyPlace ;
    public static String CompanyAddress ;
    public static String CompanySIREN ; //Système d’Identification du Répertoire des Entreprises
    public static String CompanyMF ; //Matricule Fiscale
    public static String CompanyIF ;  //Identité Fiscale
    public static String CompanyTele ;
    public static String CompanyFax ;
    public static String CompanyMail ;
    public static String CompanySite ;
    
    public static String NomLocalPC ;
    public static String Timbre ;
    
    public static String CurrencySign ;
    public static String CurrencyName ;
    public static String CurrencyThousandth ;
     
    public static String Bank ;
    public static String RIP ;
    public static String RIB ;
    
    public void SetParametre()
    {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        try {
            // optional, but recommended
            // process XML securely, avoid attacks like XML External Entities (XXE)
            dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);

            // parse XML file
            DocumentBuilder db = dbf.newDocumentBuilder();

            //PowerERP\conf\parametre.xml
            Document doc = db.parse(new File("./conf/parametre.xml"));

            doc.getDocumentElement().normalize();
            
            Element elementJDBC  = (Element) doc.getElementsByTagName("JDBC").item(0);
            
            String jdbc_url = elementJDBC.getElementsByTagName("Url").item(0).getTextContent();
            ParametreSystem.JdbcUrl = jdbc_url;
            
            String jdbc_db = elementJDBC.getElementsByTagName("DataBase").item(0).getTextContent();
            ParametreSystem.JdbcDB = jdbc_db;
            
            String jdbc_user = elementJDBC.getElementsByTagName("User").item(0).getTextContent();
            ParametreSystem.JdbcUser = jdbc_user;
            
            String jdbc_password = elementJDBC.getElementsByTagName("Password").item(0).getTextContent();
            ParametreSystem.JdbcPassword = jdbc_password;
            
            /****************************************/
            
            Element elementCompany  = (Element) doc.getElementsByTagName("Company").item(0);
            
            String company_name = elementCompany.getElementsByTagName("Name").item(0).getTextContent();
            ParametreSystem.CompanyName = company_name;
            
            String company_place = elementCompany.getElementsByTagName("Place").item(0).getTextContent();
            ParametreSystem.CompanyPlace = company_place;
            
            String company_address = elementCompany.getElementsByTagName("Address").item(0).getTextContent();
            ParametreSystem.CompanyAddress = company_address;
            
            String companySIREN = elementCompany.getElementsByTagName("SIREN").item(0).getTextContent();
            ParametreSystem.CompanySIREN = companySIREN; 
            
            String companyMF = elementCompany.getElementsByTagName("MF").item(0).getTextContent();
            ParametreSystem.CompanyMF =companyMF; 
            
            String companyIF = elementCompany.getElementsByTagName("IF").item(0).getTextContent();
            ParametreSystem.CompanyIF = companyIF; 
            
            String companyTele = elementCompany.getElementsByTagName("Tele").item(0).getTextContent();
            ParametreSystem.CompanyTele = companyTele;
            
            String companyFax = elementCompany.getElementsByTagName("Fax").item(0).getTextContent();
            ParametreSystem.CompanyFax = companyFax;
            
            String companyMail = elementCompany.getElementsByTagName("Mail").item(0).getTextContent();
            ParametreSystem.CompanyMail = companyMail;
            
            String companySite = elementCompany.getElementsByTagName("Site").item(0).getTextContent();
            ParametreSystem.CompanySite = companySite;
            
            /******************************/
            
            Element elementNomLocalPC  = (Element) doc.getElementsByTagName("NomLocalPC").item(0);
            ParametreSystem.NomLocalPC = elementNomLocalPC.getTextContent() ;
            
            Element elementTimbre  = (Element) doc.getElementsByTagName("Timbre").item(0);
            ParametreSystem.Timbre = elementTimbre.getTextContent() ;
            
            
            /********************************/
            
            Element elementCurrency = (Element) doc.getElementsByTagName("Currency").item(0);
            
            String currency_sign = elementCurrency.getElementsByTagName("Sign").item(0).getTextContent();
            ParametreSystem.CurrencySign = currency_sign;
            
            String currency_name = elementCurrency.getElementsByTagName("Name").item(0).getTextContent();
            ParametreSystem.CurrencyName = currency_name;
            
            String currency_thousandth = elementCurrency.getElementsByTagName("Thousandth").item(0).getTextContent();
            ParametreSystem.CurrencyThousandth = currency_thousandth;
            
            
            /*************************************/
            
            Element elementBanque = (Element) doc.getElementsByTagName("Banque").item(0);
            
            String bank = elementBanque.getElementsByTagName("Bank").item(0).getTextContent();
            ParametreSystem.Bank = bank;
            
            String rip = elementBanque.getElementsByTagName("RIP").item(0).getTextContent();
            ParametreSystem.RIP = rip;
            
            String rib = elementBanque.getElementsByTagName("RIB").item(0).getTextContent();
            ParametreSystem.RIB = rib;
        } 
        catch (ParserConfigurationException | SAXException | IOException e) {
            System.out.println("error Controllers\\Traitement\\ParametreSystem.java/SetParametre "+e.getMessage());
            System.out.println(e.getMessage());
        }
    }
}
