/*
 * 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 Models.Stock;

import Controllers.Traitement.ParametreSystem;
import Models.connexion;
import javafx.collections.ObservableList;
import Models.User.User;

/**
 *
 * @author Maher
 */
public class StockDetailDB {
    
    connexion cnx = new connexion();
    
    public boolean InsertStockDetail(ObservableList<StockDetail> ListStockDetail){
        
        String Query = "INSERT INTO stock_detail (`local_nom`, `reference_produit`, `quantite`, `date_add`, `id_profile`, `id_bon_entre`, `id_bon_sortie`, `id_bon_livraison`, `id_bon_reception`, `id_facture_frs`, `id_vente_sans_facture`) VALUES ";
        
        for(StockDetail ValStockDetail : ListStockDetail){
            
            String ReferenceProduit = ValStockDetail.getReference_produit();
            Float Quantite = ValStockDetail.getQuantite();
            String IdBonEntre = ValStockDetail.getId_bon_entre();
            String IdBonSortie = ValStockDetail.getId_bon_sortie();
            String IdBonLivraison = ValStockDetail.getId_bon_livraison();
            String IdBonReception = ValStockDetail.getId_bon_reception();
            String IdFactureFrs = ValStockDetail.getId_facture_frs();
            String IdVenteSansFacture = ValStockDetail.getId_vente_sans_facture();
            
            if( (IdBonEntre == null) || (IdBonEntre.isEmpty()) ){
                IdBonEntre = "NULL";
            }
            
            if( (IdBonSortie == null)  ||  (IdBonSortie.isEmpty()) ){
                IdBonSortie = "NULL";
            }
            
            if( (IdBonLivraison == null) || (IdBonLivraison.isEmpty() ) ){
                IdBonLivraison = "NULL";
            }
            
            if( (IdBonReception == null) ||(IdBonReception.isEmpty()) ){
                IdBonReception = "NULL";
            }
            
            if( (IdFactureFrs == null) ||(IdFactureFrs.isEmpty()) ){
                IdFactureFrs = "NULL";
            }
            
            if( (IdVenteSansFacture == null) ||(IdVenteSansFacture.isEmpty()) ){
                IdVenteSansFacture = "NULL";
            }
            
            Query = Query + "(\""+ParametreSystem.NomLocalPC+"\", \""+ReferenceProduit+"\", '"+Quantite+"', CURTIME(), '"+User.idprofile+"', "+IdBonEntre+", "+IdBonSortie+", "+IdBonLivraison+", "+IdBonReception+", "+IdFactureFrs+", "+IdVenteSansFacture+" ),";
        }
        
        Query = Query.substring(0, Query.length()-1)+";";
        
        return cnx.insertion(Query);
    }
   
}
