/*
* $RCSfile: HrExpensesEJB.java,v $ $Revision: 1.1.1.1 $ $Date: 2005/04/28 20:22:25 $ - $Author: mking_cv $
*
* The contents of this file are subject to the Open Software License
* Version 2.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.centraview.com/opensource/license.html
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is: CentraView Open Source.
*
* The developer of the Original Code is CentraView. Portions of the
* Original Code created by CentraView are Copyright (c) 2004 CentraView,
* LLC; All Rights Reserved. The terms "CentraView" and the CentraView
* logos are trademarks and service marks of CentraView, LLC.
*/
package com.centraview.hr.hrexpenses;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import javax.ejb.CreateException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.FinderException;
import javax.naming.Context;
import javax.naming.InitialContext;
import com.centraview.administration.authorization.AuthorizationLocal;
import com.centraview.administration.authorization.AuthorizationLocalHome;
import com.centraview.common.AuthorizationFailedException;
import com.centraview.common.CVDal;
import com.centraview.common.CVUtility;
import com.centraview.common.DateMember;
import com.centraview.common.FloatMember;
import com.centraview.common.IntMember;
import com.centraview.common.StringMember;
import com.centraview.hr.expenses.HrExpenseLineElement;
import com.centraview.hr.expenses.HrExpenseLines;
import com.centraview.hr.helper.ExpenseFormVO;
public class HrExpensesEJB implements EntityBean
{
protected javax.ejb.EntityContext ctx;
protected Context environment;
int userID = 0;
private ExpenseFormVO expenseFormVO;
private boolean isDirty = false; //update data if isDirty is true (ejbStore)
private String dataSource = "MySqlDS";
public void ejbActivate() { }
public void ejbPassivate() { }
/**
* Creates a new ExpenseForm record in Database
* @param expenseFormVO A populated ExpenseFormVO representing
* the Expense Form record to be added.
* @param userID The <code>individualID</code> of the user who is adding the record.
* @param ds The <code>dataSource</code> which should be used to connect to the database.
*/
public ExpenseFormPK ejbCreate(ExpenseFormVO expenseFormVO, int userID, String ds)
{
this.dataSource = ds;
int expenseFormID = 0;
int expenseID = 0;
this.userID = userID;
CVDal cvdal = new CVDal(ds);
try
{
HrExpenseLines hrexpenseLines = expenseFormVO.getHrExpenseLines();
if (hrexpenseLines != null)
{
hrexpenseLines.calculate();
}
cvdal.setSql("hr.expense.addexpenseform");
cvdal.setDate(1,expenseFormVO.getFrom()); //FromDate
cvdal.setDate(2,expenseFormVO.getTo()); //ToDate
cvdal.setString(3,expenseFormVO.getNotes());//Note
cvdal.setInt(4,expenseFormVO.getReportingId()); //ReportingTo
cvdal.setInt(5,expenseFormVO.getEmployeeId()); //Employee Id
cvdal.setInt(6,userID); //Owner
cvdal.setInt(7,userID);//Creator
cvdal.setInt(8,expenseFormVO.getModifiedBy());//ModifiedBy
cvdal.setString(9,expenseFormVO.getDescription());//Description
cvdal.executeUpdate();
this.expenseFormVO = expenseFormVO;
expenseFormID = cvdal.getAutoGeneratedKey();
this.expenseFormVO.setExpenseFormID(expenseFormID);
cvdal.clearParameters();
if (hrexpenseLines != null)
{
Set listkey = hrexpenseLines.keySet();
Iterator it = listkey.iterator();
while (it.hasNext())
{
Integer str = ( Integer )it.next();
HrExpenseLineElement ele = (HrExpenseLineElement)hrexpenseLines.get( str );
this.addExpenseItem(ele,expenseFormID,userID);
}
} // end if (hrexpenseLines != null)
InitialContext ic = CVUtility.getInitialContext();
AuthorizationLocalHome authorizationHome = (AuthorizationLocalHome)ic.lookup("local/Authorization");
AuthorizationLocal authorizationLocal = authorizationHome.create();
authorizationLocal.setDataSource(this.dataSource);
authorizationLocal.saveCurrentDefaultPermission("Expense", expenseFormID, userID);
}catch(Exception e){
System.out.println("[Exception][HrExpensesEJB.ejbCreate] Exception Thrown: "+e);
e.printStackTrace();
}finally{
cvdal.destroy();
cvdal = null;
}
return new ExpenseFormPK(expenseFormID, ds);
} // end ejbCreate() method
public void ejbLoad()
{
ExpenseFormPK expenseFormPK = (ExpenseFormPK)(ctx.getPrimaryKey());
this.setDataSource(expenseFormPK.getDataSource());
HashMap hm = getBasic(expenseFormPK); //this will get data from the table
// so check the fields
if (hm == null)
{
return;
}else{
setBasicForm(hm);
}
} // end ejbLoad() method
/**
* Creates an Expense record in the Expense Table
*/
private void addExpenseItem(HrExpenseLineElement ele ,int expenseFormID, int userID)
{
CVDal cvdal = new CVDal(this.dataSource);
try
{
Set s = ele.keySet();
Iterator temp = s.iterator();
//Reference is the description in expense table
//fields from expenseitem table start
//before this expenseid has to be generated
IntMember lineid = ( IntMember )ele.get("LineId");
IntMember itemid = ( IntMember )ele.get("ExpenseItemID");
StringMember sku = ( StringMember )ele.get("SKU");
FloatMember qty = ( FloatMember )ele.get("Quantity");
FloatMember priceEach = ( FloatMember )ele.get("PriceEach");
StringMember desc = ( StringMember )ele.get("Description");
String status = ele.getLineStatus();
//fields from expenceitem table end
//fields from expense table start what about created & modified?
IntMember typeID = (IntMember)ele.get("ReferenceType");
IntMember referenceID = (IntMember)ele.get("ReferenceId");
//IntMember type = (IntMember)ele.get("ReferenceType");//typeID
StringMember reference = (StringMember)ele.get("Reference");
FloatMember Amount = (FloatMember)ele.get("PriceExtended");
DateMember createdDate = (DateMember)ele.get("CreatedDate");
DateMember modifiedDate = (DateMember)ele.get("Modified");
//fields from expense table end
cvdal.setSql("hr.expense.addexpense");
int iProject=0;
int iTicket =0;
int opportunity =0;
if (reference== null)
{
cvdal.setString(1,new String("NotFound"));
}else{
cvdal.setString(1,(String)reference.getMemberValue());
}
int iType = ((Integer)typeID.getMemberValue()).intValue();
int iReferenceId = ((Integer)referenceID.getMemberValue()).intValue();
if (iType == 1) //ticket
{
cvdal.setInt(2,0);
cvdal.setInt(3,iReferenceId);
cvdal.setInt(4,0);
}else if (iType == 2){
// Project
cvdal.setInt(2,iReferenceId);
cvdal.setInt(3,0);
cvdal.setInt(4,0);
}else if (iType == 3){
//opportunity
cvdal.setInt(2,0);
cvdal.setInt(3,0);
cvdal.setInt(4,iReferenceId);
}else{
cvdal.setInt(2,0);
cvdal.setInt(3,0);
cvdal.setInt(4,0);
}
cvdal.setInt(5,userID);//owner
cvdal.setInt(6,userID);//creator
cvdal.setInt(7,expenseFormVO.getModifiedBy());//modifiedby
cvdal.setInt(8,((Integer)lineid.getMemberValue()).intValue());//LineId
cvdal.setFloat(9,((Float)Amount.getMemberValue()).floatValue());//Amount
cvdal.setInt(10,expenseFormID);
cvdal.executeUpdate();
int expenseID = cvdal.getAutoGeneratedKey();
cvdal.clearParameters();
cvdal.setSql("hr.expense.addexpenseitem");
cvdal.setInt(1,expenseID);
cvdal.setInt(2,((Integer)itemid.getMemberValue()).intValue() );
cvdal.setString(3,(String)sku.getMemberValue());
cvdal.setString(4,(String)desc.getMemberValue());
cvdal.setFloat(5,((Float)priceEach.getMemberValue()).floatValue());
cvdal.setFloat(6,((Float)qty.getMemberValue()).floatValue());
cvdal.executeUpdate();
int lineID = cvdal.getAutoGeneratedKey();//cw
cvdal.clearParameters();
cvdal.setSql("hr.expense.updateexpenselineid");
cvdal.setInt(1,lineID);
cvdal.setInt(2,expenseID);
cvdal.executeUpdate();
cvdal.clearParameters();
}catch(Exception e){
e.printStackTrace();
}finally{
cvdal.destroy();
cvdal = null;
}
}// end of addExpenseItem
/*
* Update ExpenseItem record in Database
*/
private void updateExpenseItem(HrExpenseLineElement ele ,int expenseFormID)
{
//CW there should be no requirement here
//if(!CVUtility.isModuleVisible("ExpenseForms",expenseFormID))
//throw new AuthorizationFailedException("ExpenseForms - updateExpenseItem");
CVDal dl = new CVDal(this.dataSource);
try
{
IntMember lineid = ( IntMember )ele.get("LineId");
IntMember itemid = ( IntMember )ele.get("ExpenseItemID");
StringMember sku = ( StringMember )ele.get("SKU");
FloatMember qty = ( FloatMember )ele.get("Quantity");
FloatMember priceEach = ( FloatMember )ele.get("PriceEach");
StringMember desc = ( StringMember )ele.get("Description");
String status =(String) ele.getLineStatus();
//fields from expense table start what about created & modified?
IntMember typeID = (IntMember)ele.get("ReferenceType");
IntMember referenceID = (IntMember)ele.get("ReferenceId");
//IntMember type = (IntMember)ele.get("ReferenceType");//typeID
StringMember reference = (StringMember)ele.get("Reference");
FloatMember Amount = (FloatMember)ele.get("PriceExtended");
DateMember createdDate = (DateMember)ele.get("CreatedDate");
DateMember modifiedDate = (DateMember)ele.get("Modified");
//This is to update expense table.
dl.setSql("hr.expense.updateexpense"); //here it should be expenseformid
//ALLSQL.put("hr.expense.updateexpense","update expense Description=? , Project=?,Ticket=?,Opportunity=?, ModifiedBy = ?, Modified=CURRENT_DATE where ExpenseFormID = ? and lineid = ?");
//sql = "update expense Description=? , Project=?,Ticket=?,Opportunity=?, ModifiedBy = ?, Modified=CURRENT_DATE where ExpenseFormID = ? and lineid = ?"
dl.setString(1,(String)reference.getMemberValue());
int iType = ((Integer)typeID.getMemberValue()).intValue();
int iReferenceId = ((Integer)referenceID.getMemberValue()).intValue();
if (iType == 1) //ticket
{
dl.setInt(2,0);
dl.setInt(3,iReferenceId);
dl.setInt(4,0);
}
else if (iType == 2)//project
{
dl.setInt(2,iReferenceId);
dl.setInt(3,0);
dl.setInt(4,0);
}
else if (iType == 3) //opportunity
{
dl.setInt(2,0);
dl.setInt(3,0);
dl.setInt(4,iReferenceId);
}
else//cw
{
dl.setInt(2,0);
dl.setInt(3,0);
dl.setInt(4,0);
}
dl.setInt(5,expenseFormVO.getModifiedBy());//modifiedby
int iLineid = ((Integer)lineid.getMemberValue()).intValue();
dl.setInt(6,expenseFormID);
dl.setInt(7,iLineid); //check the lineid
dl.executeUpdate();
//get the expense id for above form id & line id
String sql = new String("select expenseid from expense where expenseformid=? and lineid = ?");
dl.setSqlQuery(sql);
dl.setInt(1,expenseFormID);
dl.setInt(2,((Integer)lineid.getMemberValue()).intValue());
Collection colid = dl.executeQuery();
int iexpenseId = 0;
if(colid != null)
{
Iterator it = colid.iterator();
while (it.hasNext())
{
HashMap hm = (HashMap)it.next();
Long idLong = (Long)hm.get("expenseid");
iexpenseId = idLong.intValue();
}
}
//This is to update expenseitem table.
dl.setSql("hr.expense.updateexpenseitem");
//ALLSQL.put("hr.expense.updateexpenseitem","update expenseitem set expenseitemid = ?,sku = ?,description = ?,price = ?,quantity = ? linestatus=? where expenseid = ? ");
dl.setInt(1,((Integer)itemid.getMemberValue()).intValue() );
dl.setString(2,(String)sku.getMemberValue());
dl.setString(3,(String)desc.getMemberValue());
dl.setFloat(4,((Float)priceEach.getMemberValue()).floatValue());
dl.setFloat(5,((Float)qty.getMemberValue()).floatValue());
//dl.setString(6,status); check status
dl.setInt(6,iexpenseId); //here it should be expenseid get it
//not required dl.setInt(8,((Integer)lineid.getMemberValue()).intValue());
dl.executeUpdate();
dl.clearParameters();
//This is to update expenseitem table ends.
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
dl.destroy();
dl = null;
}
}// end of updateExpenseItem
/*
* Update ExpenseItem record in Database
* Mark as delete
*/
private void markDeletedExpenseItem(HrExpenseLineElement ele ,int expenseFormID)
{
CVDal dl = new CVDal(this.dataSource);
try
{
//dl.setSql("hr.expense.markdeletedexpenseitem");
//ALLSQL.put("hr.expense.markdeletedexpenseitem","update expenseform set Status ='Deleted' where expenseformid = ?");
/*
dl.setSqlQuery("update expenseform set Status ='Deleted' where expenseformid = ?");
dl.setInt(1,expenseFormID);
dl.executeUpdate();
dl.clearParameters();
*/
IntMember lineid = ( IntMember )ele.get("LineId");
IntMember expenseID = ( IntMember )ele.get("ExpenseID");
//IntMember itemid = ( IntMember )ele.get("ExpenseItemID");
dl.setSqlQuery("update expense set LineStatus ='Deleted' where ExpenseFormID = ? and LineID= ?");
dl.setInt(1, expenseFormID);
dl.setInt(2,((Integer)lineid.getMemberValue()).intValue());
dl.executeUpdate();
dl.clearParameters();
dl.setSqlQuery("update expenseitem set LineStatus ='Deleted' where LineID=?");
dl.setInt(1,((Integer)lineid.getMemberValue()).intValue());
dl.executeUpdate();
dl.clearParameters();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
dl.destroy();
dl = null;
}
}// end of markDeleatedExpenseItem
/**
* EJB Container callback method
*/
public void ejbPostCreate (ExpenseFormVO expenseFormVO,int userID, String ds) throws CreateException
{
}
public ExpenseFormVO getExpenseFormVO()
{
ejbLoad();
setExpenseItemData();
//expenseFormVO.setCreator(iOwner.intValue());
return this.expenseFormVO;
}
public void setHrExpenseVO(ExpenseFormVO expenseFormVO,int expenseID) throws AuthorizationFailedException
{
if(!CVUtility.isModuleVisible("ExpenseForms",expenseID, this.dataSource))
throw new AuthorizationFailedException("ExpenseForms - setHrExpenseVO");
this.expenseFormVO = expenseFormVO ;
this.isDirty = true;
}
/*
* get Basic Expense
*/
private HashMap getBasic(ExpenseFormPK primaryKey)
{
CVDal dl = new CVDal(primaryKey.getDataSource());
// "select * from expenseform where ExpenseFormID = ?;"
dl.setSql("hr.expense.getexpenseform");
dl.setInt(1,primaryKey.getId());
Collection col = dl.executeQuery();
dl.destroy();
dl = null;
Iterator it = col.iterator();
if (!it.hasNext())
return null;
else
return (HashMap)it.next();
}// end of getBasic
/*
* This method set the basicform for
*
*/
private void setBasicForm(HashMap hm)
{
this.expenseFormVO = new ExpenseFormVO();
Long tmp = (Long)(hm.get("ExpenseFormID"));
if(tmp!=null)
this.expenseFormVO.setExpenseFormID(tmp.intValue());
//Long tmpExpenseid = (Long)(hm.get("expenseId"));
//if(tmpExpenseid != null)
// this.expenseFormVO.setExpenseID(tmpExpenseid.intValue());
//String reportingto = (String)(hm.get("reportingto"));
//if(reportingto != null)
// this.expenseFormVO.setReportTo(Longreportingto);
//String tmpemployee = (String)(hm.get("employee"));
//if(tmpemployee != null)
// this.expenseFormVO.setEmployee(tmpemployee);
//Double amt;
//amt = (Double)(hm.get("amount"));
//if(amt!=null)
// this.expenseVO.setAmount(amt.floatValue());
Long tmpreportId = (Long)(hm.get("ReportingTo"));
if(tmpreportId != null)
this.expenseFormVO.setReportingId(tmpreportId.intValue());
Long tmpemployeeId = (Long)(hm.get("employeeID"));
if(tmpemployeeId != null)
this.expenseFormVO.setEmployeeId(tmpemployeeId.intValue());
if(hm.get("Description") != null)
this.expenseFormVO.setDescription((String)hm.get("Description"));
if(hm.get("Note") != null)
this.expenseFormVO.setNotes((String)hm.get("Note"));
if(hm.get("Created") != null)
this.expenseFormVO.setCreatedDate((java.sql.Timestamp)hm.get("Created"));
if(hm.get("FromDate") != null)
this.expenseFormVO.setFrom((java.sql.Date)hm.get("FromDate"));
if(hm.get("ToDate") != null)
this.expenseFormVO.setTo((java.sql.Date)hm.get("ToDate"));
if(hm.get("Modified") != null)
this.expenseFormVO.setModifiedDate((java.sql.Timestamp)hm.get("Modified"));
this.expenseFormVO.setStatus(hm.get("Status").toString());
//get all ids
int iReportingTo = tmpreportId.intValue();
Long CreatorLong = (Long)hm.get("Creator");
int iCreator = CreatorLong.intValue();
int employeeID = this.expenseFormVO.getEmployeeId();
Long ModifiedLong = (Long)hm.get("ModifiedBy");
int iModifiedBy = ModifiedLong.intValue();
CVDal cvdl = new CVDal(this.dataSource);
String strQuery = "";
strQuery = "select firstname,lastname from individual where individualid = " + iReportingTo;
cvdl.setSqlQuery(strQuery);
Collection col1 = cvdl.executeQuery();
if (col1 != null)
{
Iterator it = col1.iterator();
while( it.hasNext() )
{
HashMap hm1 = ( HashMap )it.next();
String sUserFirstName = (String)hm1.get("firstname");
String sUserLastName = (String)hm1.get("lastname");
if (sUserFirstName != null && sUserLastName != null)
{
String sName = sUserFirstName+" "+sUserLastName;
this.expenseFormVO.setReportingTo(sName);
}
}
}
strQuery = "select firstname,lastname from individual where individualid = " + iCreator;
cvdl.setSqlQuery(strQuery);
col1 = cvdl.executeQuery();
if (col1 != null)
{
Iterator it = col1.iterator();
while( it.hasNext() )
{
HashMap hm1 = ( HashMap )it.next();
String sUserFirstName = (String)hm1.get("firstname");
String sUserLastName = (String)hm1.get("lastname");
if (sUserFirstName != null && sUserLastName != null)
{
String sName = sUserFirstName+" "+sUserLastName;
this.expenseFormVO.setCreatorName(sName);
}
}
}
strQuery = "select firstname,lastname from individual where individualid = " + employeeID;
cvdl.setSqlQuery(strQuery);
col1 = cvdl.executeQuery();
if (col1 != null)
{
Iterator it = col1.iterator();
while( it.hasNext() )
{
HashMap hm1 = ( HashMap )it.next();
String sUserFirstName = (String)hm1.get("firstname");
String sUserLastName = (String)hm1.get("lastname");
if (sUserFirstName != null && sUserLastName != null)
{
String sName = sUserFirstName+" "+sUserLastName;
this.expenseFormVO.setEmployee(sName);
}
}
}
strQuery = "select firstname,lastname from individual where individualid = " + iModifiedBy;
cvdl.setSqlQuery(strQuery);
col1 = cvdl.executeQuery();
if (col1 != null)
{
Iterator it = col1.iterator();
while( it.hasNext() )
{
HashMap hm1 = ( HashMap )it.next();
String sUserFirstName = (String)hm1.get("firstname");
String sUserLastName = (String)hm1.get("lastname");
if (sUserFirstName != null && sUserLastName != null)
{
String sName = sUserFirstName+" "+sUserLastName;
this.expenseFormVO.setModifiedByName(sName);
}
}
}
}//end of setBasicForm
/*
* Set the ExpenseItem Data in ExpenseVO Object
*/
private void setExpenseItemData()
{
//hashmap fields are database fields
CVDal dl = new CVDal(this.dataSource);
try
{
//select expenseitem.ExpenseID,ExpenseItemID,SKU,Description,Price,Quantity,expenseitem.LineID,Amount,Ticket,Project,Opportunity,Description,expense.ExpenseFormID from expenseitem,expense,expenseform where (expenseform.ExpenseFormID = expense.ExpenseFormID AND expense.ExpenseID= expenseitem.ExpenseID AND expenseform.ExpenseFormID = ?)
dl.setSql("hr.expense.getexpenseitem");
//ALLSQL.put("hr.expense.getexpenseitem","select expenseitem.ExpenseID ExpenseID,ExpenseItemID,SKU,expense.Description reference ,Price,Quantity,expenseitem.LineID LineID,Amount,Ticket,Project,Opportunity,expenseitem.Description Description,expense.ExpenseFormID ExpenseFormID,Quantity*Price priceextended from expenseitem,expense,expenseform where (expenseform.ExpenseFormID = expense.ExpenseFormID AND expense.ExpenseID= expenseitem.ExpenseID AND expenseform.ExpenseFormID = ?)");
dl.setInt(1,this.expenseFormVO.getExpenseFormID());
Collection col = dl.executeQuery();
if (col != null)
{
HrExpenseLines hrexpenseLines= new HrExpenseLines();
Iterator it = col.iterator();
int count = 1;
while (it.hasNext())
{
HashMap hm =(HashMap)it.next();
Iterator stemp = hm.keySet().iterator();
Long tmp;
//LineID
tmp = (Long)(hm.get("LineID"));
IntMember LineId = new IntMember("LineID",tmp.intValue(),'D',"",'T',false,20);
//ExpenseItemID
tmp = (Long)(hm.get("ExpenseItemID"));
IntMember ItemId = new IntMember("ExpenseItemID",tmp.intValue(),'D',"",'T',false,20);
//Quantity
tmp = (Long)(hm.get("Quantity"));
FloatMember Quantity = new FloatMember("Quantity",new Float(tmp.floatValue()),'D',"",'T',false,20);
//Price
Double doubleTmp = new Double(hm.get("Price").toString());
FloatMember PriceEach = new FloatMember("Price",new Float(doubleTmp.floatValue()),'D',"",'T',false,20);
//priceextended
doubleTmp = (Double)(hm.get("priceextended"));
FloatMember PriceExtended = new FloatMember("PriceExtended",new Float(doubleTmp.floatValue()),'D',"",'T',false,20);
//project
Long project = (Long)(hm.get("Project"));
IntMember ProjectId = new IntMember("Project",project.intValue(),'D',"",'T',false,20);
//ticket
Long ticket = (Long)(hm.get("Ticket"));
IntMember TicketId = new IntMember("Ticket",project.intValue(),'D',"",'T',false,20);
//opportunity
Long Opportunity = (Long)(hm.get("Opportunity"));
IntMember OpportunityId = new IntMember("Opportunity",project.intValue(),'D',"",'T',false,20);
//sku
StringMember SKU = new StringMember("SKU",(String)(hm.get("SKU")),'D',"",'T',false);
//expenseitem.Description
StringMember Description = new StringMember("Description",(String)(hm.get("Description")),'D',"",'T',false);
IntMember typeID = null;
IntMember ReferenceID = null;
if((project.intValue()) != 0)
{
typeID = new IntMember("TypeId", 2 ,'D',"",'T',false,20);
ReferenceID = new IntMember("ReferenceID",project.intValue(),'D',"",'T',false,20);
}
else if ((ticket.intValue()) !=0)
{
typeID = new IntMember("TypeId", 1 ,'D',"",'T',false,20);
ReferenceID = new IntMember("ReferenceID",ticket.intValue(),'D',"",'T',false,20);
}
else if ((Opportunity.intValue()) != 0)
{
typeID = new IntMember("TypeId", 3 ,'D',"",'T',false,20);
ReferenceID = new IntMember("ReferenceID",Opportunity.intValue(),'D',"",'T',false,20);
}
else
{
typeID = new IntMember("TypeId", 4 ,'D',"",'T',false,20);
ReferenceID = new IntMember("ReferenceID",0,'D',"",'T',false,20);
}
//ExpenseFormID
Integer expenseformid = (Integer)(hm.get("ExpenseFormID"));
IntMember ExpenseFormID = new IntMember("ExpenseFormID",expenseformid.intValue(),'D',"",'T',false,20);
//ExpenseID
Long expenseid = (Long)(hm.get("ExpenseID"));
IntMember ExpenseID = new IntMember("ExpenseID",expenseid.intValue(),'D',"",'T',false,20);
//referenceId
//Long referenceid = (Long)(hm.get("ReferenceId"));
//IntMember ReferenceID = new IntMember("ReferenceID",referenceid.intValue(),'D',"",'T',false,20);
//expense.Description reference
StringMember reference = new StringMember("reference",(String)(hm.get("reference")),'D',"",'T',false);
//Amount
Double amount = new Double(hm.get("Amount").toString());
FloatMember Amount = new FloatMember("Amount",new Float(amount.floatValue()),'D',"",'T',false,20);
HrExpenseLineElement ie = new HrExpenseLineElement(11);
ie.put ("LineId",LineId);
ie.put ("ExpenseFormID",ExpenseFormID);
ie.put ("ExpenseID",ExpenseID);
ie.put ("ExpenseItemID",ItemId);
ie.put ("SKU",SKU);
ie.put ("Description",Description);
ie.put ("Reference",reference);
ie.put ("Quantity",Quantity);
ie.put ("PriceEach",PriceEach);
ie.put ("ReferenceType",typeID);
ie.put ("ReferenceId",ReferenceID);
ie.put ("PriceExtended",PriceExtended);
ie.put ("Amount",Amount);
ie.setLineStatus((String)(hm.get("linestatus")));
//ie.put ("UnitTax",UnitTax);
//ie.put ("UnitTaxrate",TaxRate);
//ie.put ("OrderQuantity",OrderQuantity);
//ie.put ("PendingQuantity",PendingQuantity);
//cw hrexpenseLines.put(""+count,ie);
hrexpenseLines.put(new Integer(count),ie);
count ++;
}
this.expenseFormVO.setHrExpenseLines(hrexpenseLines);
}// end of if
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
dl.destroy();
dl = null;
}
}// end of setExpenseItemData
/**
* A container invokes this method before it ends the life of the entity object. This
* happens as a result of a client's invoking a remove operation, or when a container
* decides to terminate the entity object after a timeout. This method is called with
* no transaction context.
*/
public void ejbRemove ()
{
CVDal dl = new CVDal(this.dataSource);
try
{
//required dl.setSql("hr.expense.markdeletedexpenseitem");
//ALLSQL.put("hr.expense.markdeletedexpenseitem","update expenseform set Status ='Deleted' where expenseformid = 10");
dl.setSqlQuery("update expense set linestatus = 'Deleted' where expenseformid = ?");
dl.setInt(1,expenseFormVO.getExpenseFormID());
dl.executeUpdate();
String sStat = new String("Deleted");
dl.setSqlQuery("update expenseform set Status ='Deleted' where expenseformid =? ");
dl.setInt(1,expenseFormVO.getExpenseFormID());
//dl.setString(1,sStat);
//dl.setInt(2,expenseFormVO.getExpenseFormID());
// dl.executeUpdate();
// dl.clearParameters();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
dl.destroy();
dl = null;
}
}
/*
* Set the associated entity context. The container calls this method after the instance
* creation. The enterprise Bean instance should store the reference to the context
* object in an instance variable. This method is called with no transaction context.
*/
public void setEntityContext(EntityContext ctx)
{
this.ctx = ctx;
}
public void unsetEntityContext()
{
this.ctx = null;
}
public void ejbStore()
{
this.dataSource = dataSource;
if (isDirty)
{
CVDal dl = new CVDal(this.dataSource);
try
{
HrExpenseLines itemLines = expenseFormVO.getHrExpenseLines();
itemLines.calculate();
//ALLSQL.put("hr.expense.updateexpenseform","update expenseform set FromDate = ?,ToDate = ?,Note = ?,Description = ?,ReportingTo = ?,Owner = ?,Creator = ? ,ModifiedBy = ?,created = CONCAT(CURRENT_DATE), Modified =CONCAT(CURRENT_DATE) where expenseformid = ?");
dl.setSql("hr.expense.updateexpenseform");
dl.setDate(1,expenseFormVO.getFrom());//fromdate
dl.setDate(2,expenseFormVO.getTo());//todate
dl.setString(3,expenseFormVO.getNotes());//note
dl.setString(4,expenseFormVO.getDescription());//description
dl.setInt(5,expenseFormVO.getReportingId());//reportingto
dl.setInt(6,expenseFormVO.getEmployeeId());//EmployeeId
dl.setInt(7,expenseFormVO.getModifiedBy());//modifiedby
dl.setString(8,expenseFormVO.getStatus());//status
dl.setInt(9,expenseFormVO.getExpenseFormID());//modifiedby
dl.executeUpdate();
dl.clearParameters();
//Insert,Update Order Lines. as per status.
Set listkey = itemLines.keySet();
Iterator it = listkey.iterator();
while (it.hasNext())
{
//Object str = ( Object)it.next();
Integer str = ( Integer)it.next();
HrExpenseLineElement ele = ( HrExpenseLineElement)itemLines.get( str );
String status = ele.getLineStatus();
if(status == null)
status = "";
status = status.trim();
if (status.equals("Active"))
{
updateExpenseItem(ele,this.expenseFormVO.getExpenseFormID());
}
else if (status.equals("Deleted"))
{
markDeletedExpenseItem(ele,this.expenseFormVO.getExpenseFormID());
}
else if (status.equals("New") || status.equals(""))
{
//cw
addExpenseItem(ele,this.expenseFormVO.getExpenseFormID(),userID);
//addExpenseItem(ele,this.expenseFormVO.getExpenseID(),userID);
//checking with expensid???????????
//addExpenseItem(ele,this.expenseFormVO.getExpenseFormID());
}
}// end of while
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
dl.destroy();
dl = null;
this.isDirty = false;
}
}// end of if
}// end of ejbStore
public ExpenseFormPK ejbFindByPrimaryKey(ExpenseFormPK primaryKey) throws FinderException
{
HashMap hm = getBasic(primaryKey);
if (hm == null)
{
throw new FinderException("Could not find Expense: " + primaryKey);
}
else
{
return primaryKey;
}
}// end of ejbFindByPrimaryKey
public void deleteExpenseForm(int formId)
{
CVDal dl = new CVDal(this.dataSource);
try
{
dl.setSqlQuery("update expense set linestatus = 'Deleted' where expenseformid = ?");
dl.setInt(1,expenseFormVO.getExpenseFormID());
dl.executeUpdate();
dl.clearParameters();
String sStat = new String("Deleted");
dl.setSqlQuery("update expenseform set lineStatus ='Deleted' where expenseformid =? ");
dl.setInt(1,expenseFormVO.getExpenseFormID());
dl.executeUpdate();
dl.clearParameters();
//dl.setString(1,sStat);
//dl.setInt(2,expenseFormVO.getExpenseFormID());
// dl.executeUpdate();
// dl.clearParameters();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
dl.destroy();
dl = null;
}
}
/**
* @author Kevin McAllister <kevin@centraview.com>
* This simply sets the target datasource to be used for DB interaction
* @param ds A string that contains the cannonical JNDI name of the datasource
*/
public void setDataSource(String ds) {
this.dataSource = ds;
}
}