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.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";
- @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 [langkah-langkah]
- 1. jika tabel null maka
- 2. seleksi list untuk ambil id requisition, dan line dari requisition
- 3. seleksi apak line memiliki product category search key "INVESTASI" atau tidak?
- 4. jika bernilai investasi dan tidak memiliki attachments maka OBException
- */
- Tab tab = OBDal.getInstance().get(Tab.class, adTabId);
- Table table = tab.getTable();
- if (table!=null) {
- String tableid = table.getId();
- OBCriteria<Requisition> resLineCriteria= OBDal.getInstance().createCriteria(Requisition.class);
- OBCriteria<Attachment> attachCriteria = OBDal.getInstance().createCriteria(Attachment.class);
- attachCriteria.add(Restrictions.eq(Attachment.PROPERTY_TABLE, tableid));
- attachCriteria.add(Restrictions.eq(Attachment.PROPERTY_RECORD, requisitionID));
- OBCriteria<ProductCategory> pcCriteria = OBDal.getInstance().createCriteria(ProductCategory.class);
- List<ProductCategory> pcList = pcCriteria.list();
- List<Requisition> resLineList = resLineCriteria.list();
- List<RequisitionLine> RiList = new ArrayList<RequisitionLine>();
- for (Requisition re :resLineList )
- {
- RiList.add((RequisitionLine) re.getProcurementRequisitionLineList());
- }
- List<Attachment> attachList = attachCriteria.list();
- for (RequisitionLine re : RiList) {
- for (ProductCategory pc : pcList) {
- if ((attachList.size()==0) && (pc.getSearchKey() == "INVESTASI"))
- throw new OBException("requisition tidak memiliki atatchments");
- }
- }
- } /*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