Package StaffManagedBeans

Source Code of StaffManagedBeans.StaffManagedBean

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

import accounts.Usracc;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.EJB;
import javax.ejb.Stateful;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import person.*;
import sessionBeans.StaffSessionBeanLocal;



/**
*
* @author HP
*/
@Stateful
@Named(value = "staffManagedBean")
@ConversationScoped
public class StaffManagedBean {

    /**
     * Creates a new instance of StaffManagedBean
     */
    public StaffManagedBean() {
    }
    private Staff staffEntity = new Staff();
   
    private Usracc account = new Usracc();
   
    private Appointment appointmentEntity = new Appointment();
    private Contract contractEntity = new Contract();
   
   
   
    @EJB
    private StaffSessionBeanLocal ssbl;
   
    private Vacation vacation;
    private Dismissal dismissal;
    private IllList ill;
    private Staff staff;
    private Appointment appointment;
    private Contract contract;
    private List<Staff> list;
    private List<Staff> listbyname;
    private List<IllList> illlist;
    private List<Vacation> vacationlist;
    private DateFormat date = new SimpleDateFormat("yyyy.MM.dd");
    @Inject Conversation conv;
   
    private String group;
    private String login;
    private String password;
    private String surname;
    private String name;
    private String middlename;
    private String placeOfBirth;
    private String dateOfBirth;
    private String passportSn;
    private String education;
    private String contactTelephone;
    private String qualification;
    private String orderDate;
    private String app;
    private String startVacationDate;
    private String endVacationDate;
    private int salary;
   
   
    private int illday;
    private int ills;
    private int vacday;
    private int vacs;
    private int allday;
    private int alls;

   
    @PostConstruct
    private void postConstract() {
        conv.begin();
    }

   
    @PreDestroy
    private void preDestroy() {
        conv.end();
    }
   
   
    /**
     * @return the staff
     */
    public Staff getStaff() {
        return staff;
    }

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

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

    /**
     * @param contract the contract to set
     */
    public void setContract(Contract contract) {
        this.contract = contract;
    }
   
   /* public String allStaff()
    {
        return ssbl.listOfStaff();
    }*/
   
    public String showStatistics(){
        Date date1 = null;
        Date date2 = null;
        staff = new Staff();
        staff.setName(name);
        staff.setSurname(surname);
        staff = ssbl.SelectStaff(staff);
        int id = staff.getId();
        vacationlist = new ArrayList<Vacation>();
        vacationlist = ssbl.SelectVacation(id);
        illlist = new ArrayList<IllList>();
        illlist = ssbl.SelectIll(id);
        contract = new Contract();
        contract = ssbl.SelectContractById(id);
        appointment = new Appointment();
        //int summ = contract.getAppointmentFk().getId();
        ills=0;
        illday=0;
        vacs=0;
        vacday=0;
        alls=0;
        allday=0;
        SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
        for (IllList il: illlist){
            ills += il.getSalary();
            try {
                date1 = format.parse(il.getStartIllDate());
                date2 = format.parse(il.getEndIllDate());
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
            long difference =  date2.getTime() - date1.getTime();
            illday +=  difference / (24 * 60 * 60 * 1000);
        }
        vacationlist=ssbl.SelectVacation(id);
        for (Vacation vac: vacationlist){
            vacs += vac.getSalary();
            try {
                date1 = format.parse(vac.getStartVacationDate());
                date2 = format.parse(vac.getEndVacationDate());
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
            long difference =  date2.getTime() - date1.getTime();
            vacday +=  difference / (24 * 60 * 60 * 1000);
        }
       
        long curTime = System.currentTimeMillis();
        Date curDate = new Date(curTime);
        try {
                date1 = format.parse(contract.getOrderDate());
                date2 = format.parse(curDate.toString());
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
        long difference =  date2.getTime() - date1.getTime();
        allday += difference / (24 * 60 * 60 * 1000);
        alls += allday/30*contract.getAppointmentFk().getSalary();
        return "ShowStat.xhtml";
    }
   
   
   
    public String createIll(){
        staff = new Staff();
        staff.setName(name);
        staff.setSurname(surname);
        ill = new IllList();
        ill.setOrderDate(orderDate);
        ill.setStartIllDate(startVacationDate);
        ill.setEndIllDate(endVacationDate);
        ill.setSalary(salary);
        ill.setStaffFk(ssbl.SelectStaff(staff));
        ssbl.CreateIll(ill);
        return "SuccessAddIll.xhtml";
    }
   
   
    public String dismissal(){
        staff= new Staff();
        staff.setName(name);
        staff.setSurname(surname);
        dismissal = new Dismissal();
        dismissal.setOrderDate(orderDate);
        dismissal.setSalary(salary);
        dismissal.setDateOfLeave(startVacationDate);
        ssbl.Dismissal(dismissal,account);
        return "SuccessDel.xhtml";
    }
   
   
    public String createVacation(){
        staff = new Staff();
        staff.setName(name);
        staff.setSurname(surname);
        vacation = new Vacation();
        vacation.setOrderDate(orderDate);
        vacation.setStartVacationDate(startVacationDate);
        vacation.setEndVacationDate(endVacationDate);
        vacation.setSalary(salary);
        vacation.setStaffFk(ssbl.SelectStaff(staff));
        ssbl.CreateVacation(vacation);
        return "SuccessAddVac.xhtml";
    }
   
   
    public String createStaff()
    {
        staff = new Staff();
        staff.setName(name);
        staff.setSurname(surname);
        staff.setMiddlename(middlename);
        staff.setDateOfBirth(dateOfBirth);
        staff.setPlaceOfBirth(placeOfBirth);
        staff.setPassportSn(passportSn);
        staff.setEducation(education);
        staff.setContactTelephone(contactTelephone);
        staff.setQualification(qualification);
        contract = new Contract();
        contract.setOrderDate(orderDate);
        contract.setAppointmentFk(ssbl.SelectAppointment(app));
        contract.setStaffFk(staff);
        account = new Usracc();
        account.setLogin(login);
        account.setPassword(password);
        account.setStaff(name+surname+middlename);
        account.setGroupFk(ssbl.SelectGroup(group));
        ssbl.CreateStaff(staff, contract, account);
        return "SuccessAddStaff.xhtml";
    }
   
    public String searchStaff(){
        staff = new Staff();
        staff.setName(name);
        staff.setSurname(surname);
        staff.setMiddlename(middlename);
        listbyname=ssbl.findStaffbyName(staff);
        return "SearchStaffResult.xhtml";
    }

    /**
     * @return the list
     */
    public List<Staff> getList() {
        setList(ssbl.listOfStaff());
        return list;
    }

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

    /**
     * @return the appointment
     */
    public Appointment getAppointment() {
        return appointment;
    }

    /**
     * @param appointment the appointment to set
     */
    public void setAppointment(Appointment appointment) {
        this.appointment = appointment;
    }

    /**
     * @return the surname
     */
    public String getSurname() {
        return surname;
    }

    /**
     * @param surname the surname to set
     */
    public void setSurname(String surname) {
        this.surname = surname;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the middlename
     */
    public String getMiddlename() {
        return middlename;
    }

    /**
     * @param middlename the middlename to set
     */
    public void setMiddlename(String middlename) {
        this.middlename = middlename;
    }

    /**
     * @return the placeOfBirth
     */
    public String getPlaceOfBirth() {
        return placeOfBirth;
    }

    /**
     * @param placeOfBirth the placeOfBirth to set
     */
    public void setPlaceOfBirth(String placeOfBirth) {
        this.placeOfBirth = placeOfBirth;
    }

    /**
     * @return the dateOfBirth
     */
    public String getDateOfBirth() {
        return dateOfBirth;
    }

    /**
     * @param dateOfBirth the dateOfBirth to set
     */
    public void setDateOfBirth(String dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }

    /**
     * @return the passportSn
     */
    public String getPassportSn() {
        return passportSn;
    }

    /**
     * @param passportSn the passportSn to set
     */
    public void setPassportSn(String passportSn) {
        this.passportSn = passportSn;
    }

    /**
     * @return the education
     */
    public String getEducation() {
        return education;
    }

    /**
     * @param education the education to set
     */
    public void setEducation(String education) {
        this.education = education;
    }

    /**
     * @return the contactTelephone
     */
    public String getContactTelephone() {
        return contactTelephone;
    }

    /**
     * @param contactTelephone the contactTelephone to set
     */
    public void setContactTelephone(String contactTelephone) {
        this.contactTelephone = contactTelephone;
    }

    /**
     * @return the qualification
     */
    public String getQualification() {
        return qualification;
    }

    /**
     * @param qualification the qualification to set
     */
    public void setQualification(String qualification) {
        this.qualification = qualification;
    }

    /**
     * @return the orderDate
     */
    public String getOrderDate() {
        return orderDate;
    }

    /**
     * @param orderDate the orderDate to set
     */
    public void setOrderDate(String orderDate) {
        this.orderDate = orderDate;
    }

    /**
     * @return the app
     */
    public String getApp() {
        return app;
    }

    /**
     * @param app the app to set
     */
    public void setApp(String app) {
        this.app = app;
    }

    /**
     * @return the listbyname
     */
    public List<Staff> getListbyname() {
        return listbyname;
    }

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

    /**
     * @return the startVacationDate
     */
    public String getStartVacationDate() {
        return startVacationDate;
    }

    /**
     * @param startVacationDate the startVacationDate to set
     */
    public void setStartVacationDate(String startVacationDate) {
        this.startVacationDate = startVacationDate;
    }

    /**
     * @return the endVacationDate
     */
    public String getEndVacationDate() {
        return endVacationDate;
    }

    /**
     * @param endVacationDate the endVacationDate to set
     */
    public void setEndVacationDate(String endVacationDate) {
        this.endVacationDate = endVacationDate;
    }

    /**
     * @return the salary
     */
    public int getSalary() {
        return salary;
    }

    /**
     * @param salary the salary to set
     */
    public void setSalary(int salary) {
        this.salary = salary;
    }

    /**
     * @return the vacation
     */
    public Vacation getVacation() {
        return vacation;
    }

    /**
     * @param vacation the vacation to set
     */
    public void setVacation(Vacation vacation) {
        this.vacation = vacation;
    }

    /**
     * @return the ill
     */
    public IllList getIll() {
        return ill;
    }

    /**
     * @param ill the ill to set
     */
    public void setIll(IllList ill) {
        this.ill = ill;
    }

    /**
     * @return the dismissal
     */
    public Dismissal getDismissal() {
        return dismissal;
    }

    /**
     * @param dismissal the dismissal to set
     */
    public void setDismissal(Dismissal dismissal) {
        this.dismissal = dismissal;
    }

    /**
     * @return the illday
     */
    public int getIllday() {
        return illday;
    }

    /**
     * @param illday the illday to set
     */
    public void setIllday(int illday) {
        this.illday = illday;
    }

    /**
     * @return the ills
     */
    public int getIlls() {
        return ills;
    }

    /**
     * @param ills the ills to set
     */
    public void setIlls(int ills) {
        this.ills = ills;
    }

    /**
     * @return the vacday
     */
    public int getVacday() {
        return vacday;
    }

    /**
     * @param vacday the vacday to set
     */
    public void setVacday(int vacday) {
        this.vacday = vacday;
    }

    /**
     * @return the vacs
     */
    public int getVacs() {
        return vacs;
    }

    /**
     * @param vacs the vacs to set
     */
    public void setVacs(int vacs) {
        this.vacs = vacs;
    }

    /**
     * @return the allday
     */
    public int getAllday() {
        return allday;
    }

    /**
     * @param allday the allday to set
     */
    public void setAllday(int allday) {
        this.allday = allday;
    }

    /**
     * @return the alls
     */
    public int getAlls() {
        return alls;
    }

    /**
     * @param alls the alls to set
     */
    public void setAlls(int alls) {
        this.alls = alls;
    }

    /**
     * @return the illlist
     */
    public List<IllList> getIlllist() {
        return illlist;
    }

    /**
     * @param illlist the illlist to set
     */
    public void setIlllist(List<IllList> illlist) {
        this.illlist = illlist;
    }

    /**
     * @return the vacationlist
     */
    public List<Vacation> getVacationlist() {
        return vacationlist;
    }

    /**
     * @param vacationlist the vacationlist to set
     */
    public void setVacationlist(List<Vacation> vacationlist) {
        this.vacationlist = vacationlist;
    }

    /**
     * @return the staffEntity
     */
    public Staff getStaffEntity() {
        return staffEntity;
    }

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

    /**
     * @return the account
     */
    public Usracc getAccount() {
        return account;
    }

    /**
     * @param account the account to set
     */
    public void setAccount(Usracc account) {
        this.account = account;
    }

    /**
     * @return the contractEntity
     */
    public Contract getContractEntity() {
        return contractEntity;
    }

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

    /**
     * @return the appointmentEntity
     */
    public Appointment getAppointmentEntity() {
        return appointmentEntity;
    }

    /**
     * @param appointmentEntity the appointmentEntity to set
     */
    public void setAppointmentEntity(Appointment appointmentEntity) {
        this.appointmentEntity = appointmentEntity;
    }

    /**
     * @return the login
     */
    public String getLogin() {
        return login;
    }

    /**
     * @param login the login to set
     */
    public void setLogin(String login) {
        this.login = login;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the group
     */
    public String getGroup() {
        return group;
    }

    /**
     * @param group the group to set
     */
    public void setGroup(String group) {
        this.group = group;
    }
}
TOP

Related Classes of StaffManagedBeans.StaffManagedBean

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.