Package sessionBeans

Source Code of sessionBeans.StaffSessionBean

/*
* 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 sessionBeans;

import accounts.*;
import buhi.Consumption;
import buhi.Document;
import buhi.Income;
import java.security.acl.Group;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit;
import javax.persistence.Query;
import person.*;

/**
*
* @author HP
*/
@Stateless
public class StaffSessionBean implements StaffSessionBeanLocal {

private Staff staff;


private Contract contract;

private Usracc userAccount;

private Usrgroup userGroup;

@PersistenceContext(unitName = "Person")
private EntityManager entityManagerPersondb;
@PersistenceContext(unitName = "AccountUnit")
private EntityManager entityManagerAccountDb;

@PersistenceContext(unitName = "Buhi")
private EntityManager entityManagerBuhDb;

private List<Staff> listOfStaff;

    @Override
    public void CreateStaff(Staff staff, Contract contract, Usracc account) {
        entityManagerPersondb.persist(staff);
        entityManagerPersondb.persist(contract);
        entityManagerAccountDb.persist(account);
        entityManagerPersondb.flush();
        entityManagerAccountDb.flush();
    }
   
   

    /**
     * @return the staff
     */
    public Staff getStaff() {
        return staff;
    }

    /**
     * @param staff the staff to set
     */
    public void setStaff(Staff staff) {
        this.staff = staff;
    }

    /**
     * @return the listOfStaff
     */
    public List<Staff> getListOfStaff() {
        return listOfStaff;
    }

    /**
     * @param listOfStaff the listOfStaff to set
     */
    public void setListOfStaff(List<Staff> listOfStaff) {
        this.listOfStaff = listOfStaff;
    }

    /**
     * @return the contract
     */
    public Contract getContract() {
        return contract;
    }

    /**
     * @param contract the contract to set
     */
    public void setContract(Contract contract) {
        this.contract = contract;
    }

@Override
public List<Staff> listOfStaff()
{
        Query query = entityManagerPersondb.createQuery("SELECT p FROM Staff p");
        return query.getResultList();
  
}


@Override
public Appointment SelectAppointment(String app) {
        Query query = entityManagerPersondb.createQuery("SELECT p from Appointment p WHERE p.appointment = '" + app + "'");
        return (Appointment) query.getSingleResult();
   
    }

@Override
public Usrgroup SelectGroup(String name){
    Query query = entityManagerAccountDb.createQuery("SELECT p from Group p WHERE p.name = '" + name + "'");
    return (Usrgroup) query.getSingleResult();
   
}

@Override
public Appointment SelectAppointmentById(int id) {
        Query query = entityManagerPersondb.createQuery("SELECT p from Appointment p WHERE p.id = '" + id + "'");
        return (Appointment) query.getSingleResult();
   
}

@Override
public List<Staff> findStaffbyName(Staff staff){
    Query query = entityManagerPersondb.createQuery("SELECT p FROM Staff p WHERE p.name like '" + staff.getName() + "' or p.surname like '" + staff.getSurname() + "' or p.middlename like '" + staff.getMiddlename() +"'");
    return query.getResultList();
}

    @Override
    public void CreateVacation(Vacation vacation) {
        Document document = new Document();
        document.setName("consumption_vacation");
        document.setDate(vacation.getOrderDate());
        Consumption consumption = new Consumption();
        consumption.setDocumentFk(document);
        entityManagerBuhDb.persist(document);
        consumption.setTotal(vacation.getSalary());
        consumption.setTypeOfConsumption("vacation");
        entityManagerBuhDb.persist(consumption);
        entityManagerPersondb.persist(vacation);   
    }

@Override
public Staff SelectStaff(Staff staff) {
        Query query = entityManagerPersondb.createQuery("SELECT p from Staff p WHERE p.name like '" + staff.getName() + "' and p.surname like '" + staff.getSurname() + "'");
        return (Staff) query.getSingleResult();
   
    }

    @Override
    public void CreateIll(IllList ill) {
        Document document = new Document();
        document.setName("consumption_ill");
        document.setDate(ill.getOrderDate());
        Consumption consumption = new Consumption();
        consumption.setDocumentFk(document);
        entityManagerBuhDb.persist(document);
        consumption.setTotal(ill.getSalary());
        consumption.setTypeOfConsumption("ill");
        entityManagerBuhDb.persist(consumption);
        entityManagerPersondb.persist(ill);
    }

    @Override
    public void Dismissal(Dismissal dismissal, Usracc useraccount) {
        Document document = new Document();
        document.setName("consumption_dismissal");
        document.setDate(dismissal.getOrderDate());
        Consumption consumption = new Consumption();
        consumption.setDocumentFk(document);
        entityManagerBuhDb.persist(document);
        consumption.setTotal(dismissal.getSalary());
        consumption.setTypeOfConsumption("dismissal");
        entityManagerBuhDb.persist(consumption);
       
        entityManagerAccountDb.remove(useraccount);
        entityManagerPersondb.persist(dismissal);
       
       
    }

   

    @Override
    public ArrayList<IllList> SelectIll(int id) {
        Query query = entityManagerPersondb.createQuery("SELECT p from ill_list p WHERE p.staff_fk = '" + id + "'");
        return (ArrayList<IllList>) query.getResultList();
    }

    @Override
    public ArrayList<Vacation> SelectVacation(int id) {
        Query query = entityManagerPersondb.createQuery("SELECT p from vacation p WHERE p.staff_fk = '" + id + "'");
        return (ArrayList<Vacation>) query.getResultList();   
    }

    @Override
    public Contract SelectContractById(int id) {
        Query query = entityManagerPersondb.createQuery("SELECT p from contract p WHERE p.staff_fk = '" + id + "'");
        return (Contract) query.getResultList()
    }

}
TOP

Related Classes of sessionBeans.StaffSessionBean

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.