Package sn.unitech.stock.dao

Source Code of sn.unitech.stock.dao.CommandeDao

package sn.unitech.stock.dao;

import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

import sn.unitech.stock.dao.iface.ICommandeDao;
import sn.unitech.stock.entity.Commande;
import sn.unitech.stock.entity.DetailCommand;
import sn.unitech.stock.entity.DetailCommandId;
import sn.unitech.stock.entity.Fournisseur;
import sn.unitech.stock.entity.SysUsers;
import sn.unitech.stock.entity.SysUsersId;
import sn.unitech.stock.modal.Resultat;



public class CommandeDao extends DataAccess implements ICommandeDao{
   
  public CommandeDao() {
   
  }

  public boolean saveCommande(List<DetailCommand> listDetailCommand,Commande commande){
    EntityManager em=getEntityManager();
    EntityTransaction tx= em.getTransaction();
    try{
    tx.begin();
    DetailCommand detailCommand=new DetailCommand();
    detailCommand= listDetailCommand.get(0);
    commande.setFournisseur( new Fournisseur(detailCommand.getCodFourn()));
    SysUsers sysUsers=new SysUsers();
    sysUsers.setId(new SysUsersId(detailCommand.getCodUser(),detailCommand.getSysProduit().getSysAdherent().getIdAdherent()));
    commande.setSysDate(new Date());
    commande.setSysUsers(sysUsers);
    this.persist(commande, em);
    for(int i=0;i<listDetailCommand.size();i++){
        detailCommand=new DetailCommand();
      detailCommand=(DetailCommand)listDetailCommand.get(i);
      detailCommand.setCommande(commande);
      detailCommand.setPrixTotc(detailCommand.getPrixUnitc()*detailCommand.getQteContenant());
      detailCommand.setPrixTotd(detailCommand.getPrixUnitd()*detailCommand.getQteDetail());
      detailCommand.setPrixTot(detailCommand.getPrixTotc()+detailCommand.getPrixTotd());
        detailCommand.setId(new DetailCommandId(commande.getIdCommand(),i));
        detailCommand.setIsLivre("False");
        detailCommand.setSysDate(new Date());
        this.persist(detailCommand,em);
    }
    tx.commit();
    return true;
    }
    catch(Exception ex){
    if((tx!=null)&&(tx.isActive()))tx.rollback();
    ex.printStackTrace();
    return false;
    }
    finally{
    em.close()
    }
  } 

 
 
  public static void main (String arg[]){
    CommandeDao commandeDao=new CommandeDao();
  }
}
TOP

Related Classes of sn.unitech.stock.dao.CommandeDao

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.