Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.wirabumi.gen.oez.porting;
- 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.dal.service.OBCriteria;
- import org.openbravo.dal.service.OBDal;
- import org.openbravo.erpCommon.utility.OBError;
- 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.wirabumi.gen.oez.event.DocumentRoutingHandlerAction;
- 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";
- /*tiko [langkah-langkah]
- 1. jika tabel null maka
- 2. seleksi list untuk ambil id requisition, dan line dari requisition yang sedang approval dengan record id
- 3. seleksi apak line memiliki product category search key "INVESTASI" atau tidak? * done
- 4. jika bernilai investasi dan tidak memiliki attachments maka OBException * done
- */
- @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){
- /*tiko*/
- Tab tab = OBDal.getInstance().get(Tab.class, adTabId);
- Table table = tab.getTable();
- String tableid = table.getId();
- Requisition requi = OBDal.getInstance().get(Requisition.class, recordId);
- List <RequisitionLine> requiL = requi.getProcurementRequisitionLineList();
- for (RequisitionLine re : requiL) {
- if (re.getProduct().getProductCategory().getSearchKey().equalsIgnoreCase("INVESTASI") ==true) {
- OBCriteria<Attachment> attachCriteria = OBDal.getInstance().createCriteria(Attachment.class);
- attachCriteria.add(Restrictions.eq(Attachment.PROPERTY_TABLE, tableid));
- attachCriteria.add(Restrictions.eq(Attachment.PROPERTY_RECORD, re.getId()));
- List<Attachment> attachList = attachCriteria.list();
- if (attachList.size()==0)
- throw new OBException("Attachment document is required for procurement of this product");
- }
- }
- /*tiko*/
- 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);
- }
- }
- @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