Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.wirabumi.gen.oez.porting;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- import org.hibernate.criterion.Restrictions;
- import org.openbravo.base.exception.OBException;
- import org.openbravo.base.model.Entity;
- import org.openbravo.base.secureApp.VariablesSecureApp;
- import org.openbravo.base.structure.BaseOBObject;
- import org.openbravo.dal.service.OBCriteria;
- import org.openbravo.dal.service.OBDal;
- import org.openbravo.database.ConnectionProvider;
- import org.openbravo.erpCommon.utility.OBError;
- import org.openbravo.exception.NoConnectionAvailableException;
- import org.openbravo.model.ad.datamodel.Table;
- import org.openbravo.model.ad.ui.Tab;
- import org.openbravo.model.ad.utility.Attachment;
- import org.openbravo.model.common.plm.ProductCategory;
- import org.openbravo.model.materialmgmt.transaction.ShipmentInOut;
- import org.openbravo.model.procurement.Requisition;
- import org.openbravo.model.procurement.RequisitionLine;
- import org.openbravo.service.db.DalConnectionProvider;
- import org.wirabumi.gen.oez.event.DocumentRoutingHandlerAction;
- import com.sun.corba.se.spi.orbutil.fsm.Guard.Result;
- public class RequisitionActionHandler extends DocumentRoutingHandlerAction {
- private final String reactiveStatus="RE";
- private final String completeStatus="CO";
- private final String draftStatus="DR";
- private final String closedStatus="CL";
- private final String voidStatus="VO";
- private final String processID="1004400003";
- @Override
- public void doRouting(String adWindowId, String adTabId,
- String doc_status_to, VariablesSecureApp vars, List<String> recordId) {
- if (doc_status_to.equalsIgnoreCase(voidStatus))
- throw new OBException("@ActionNotAllowedHere@"); //requisition tidak boleh di void
- for (String requisitionID : recordId){
- //boolean isValidRequistionLine = isRequisitionLineHasAttachment(requisitionID);
- boolean isValidRequistionLine = validateRequisitionLine(requisitionID);
- if (!isValidRequistionLine) {
- throw new OBException("Attachment document is required for procurement of this product");
- }
- if (doc_status_to.equalsIgnoreCase(completeStatus)){
- Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
- //cek apakah dari CL atau VO, jika ya, maka exception
- if (requisition.getDocumentStatus().equalsIgnoreCase(closedStatus)||
- requisition.getDocumentStatus().equalsIgnoreCase(voidStatus))
- throw new OBException("@ActionNotAllowedHere@");
- //ubdah dulu docstatus menjadi DR, baru di complete
- requisition.setDocumentStatus(draftStatus);
- requisition.setDocumentAction(doc_status_to);
- OBDal.getInstance().save(requisition);
- OBDal.getInstance().flush();
- } else if (doc_status_to.equalsIgnoreCase(reactiveStatus)){
- //cek apakah doc status adalah CO, jika tidak maka exception
- Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
- if (!requisition.getDocumentStatus().equalsIgnoreCase(completeStatus))
- throw new OBException("@ActionNotAllowedHere@");
- requisition.setDocumentAction(doc_status_to);
- OBDal.getInstance().save(requisition);
- OBDal.getInstance().flush();
- }
- doExecuteProcedureCall(requisitionID, processID);
- }
- }
- //public boolean isRequisitionLineHasAttachment (String requisitionID) {
- public boolean validateRequisitionLine (String requisitionID) {
- boolean isValid = false;
- Requisition requi = OBDal.getInstance().get(Requisition.class, requisitionID);
- for (RequisitionLine re : requi.getProcurementRequisitionLineList()) {
- boolean isInvestasi = re.getProduct().getProductCategory().getSearchKey().equalsIgnoreCase("INVESTASI") ==true;
- if (isInvestasi)
- isValid = isRequisitionLineHasAttachment(re);
- }
- return isValid;
- }
- public Boolean isRequisitionLineHasAttachment(RequisitionLine re) {
- boolean isValid = false;
- String sqlquery = "select c_file_id from c_file"
- + " where ad_table_id= ? "
- + " and ad_record_id= ? " ;
- ConnectionProvider conn = new DalConnectionProvider();
- Connection connection;
- boolean hasAttachment = false;
- try {
- connection = conn.getConnection();
- PreparedStatement ps = connection.prepareStatement(sqlquery);
- ps.setString(1, "800214");
- ps.setString(2, re.getId());
- ResultSet rs = ps.executeQuery();
- while (rs.next())
- hasAttachment=true;
- } catch (NoConnectionAvailableException e) {
- e.printStackTrace();
- throw new OBException(e.getMessage());
- } catch (SQLException e) {
- e.printStackTrace();
- throw new OBException(e.getMessage());
- }
- if(!hasAttachment) // INVESTASI tidak punya attachment
- isValid = false;
- else if (hasAttachment) //INVESTASI punya attachment
- isValid = true;
- return isValid;
- }
- @Override
- public String getCoDocumentNo(String recordID, Tab tab) {
- // TODO sementara null dulu
- return null;
- }
- @Override
- public Boolean updateDocumentStatus(Entity entity, List<String> RecordId, String document_status_to,String column){
- if (document_status_to.equalsIgnoreCase(completeStatus)||
- document_status_to.equalsIgnoreCase(closedStatus))
- return true;
- else
- return super.updateDocumentStatus(entity, RecordId, document_status_to, column);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement