From b2bc6d615da10b1a6bb0897a595feff2c61b170f Mon Sep 17 00:00:00 2001 From: hodianto Date: Fri, 30 Mar 2018 10:46:33 +0700 Subject: [PATCH] Update WS Complete Record ( EXCLUSIVE FOR PULSA 21 ONLY ) --- .../midsuit/process/MID_CompleteRecord.java | 88 +++++++++++++++ .../process/MID_InsertIntoAllTable.java | 102 ++++++++++-------- 2 files changed, 146 insertions(+), 44 deletions(-) create mode 100644 andromeida.midsuit.project/src/andromedia/midsuit/process/MID_CompleteRecord.java diff --git a/andromeida.midsuit.project/src/andromedia/midsuit/process/MID_CompleteRecord.java b/andromeida.midsuit.project/src/andromedia/midsuit/process/MID_CompleteRecord.java new file mode 100644 index 0000000..5bc12d0 --- /dev/null +++ b/andromeida.midsuit.project/src/andromedia/midsuit/process/MID_CompleteRecord.java @@ -0,0 +1,88 @@ +package andromedia.midsuit.process; + +import java.util.logging.Level; + +import org.compiere.model.MInOut; +import org.compiere.model.MInvoice; +import org.compiere.model.MOrder; +import org.compiere.model.MPayment; +import org.compiere.model.MRMA; +import org.compiere.model.MRequisition; +import org.compiere.process.DocAction; +import org.compiere.process.ProcessInfoParameter; +import org.compiere.process.SvrProcess; + +import andromedia.midsuit.model.MID_MRequisitionTrx; + +public class MID_CompleteRecord extends SvrProcess{ + String tableName = ""; + int record_ID = 0; + String DocAct = DocAction.ACTION_Complete; + @Override + protected void prepare() { + ProcessInfoParameter[] para = getParameter(); + for (int i = 0; i < para.length; i++) { + String name = para[i].getParameterName(); + if (para[i].getParameter() == null) + ; + if (para[i].getParameterName().equals("TableName")) + tableName = para[i].getParameterAsString(); + else if (para[i].getParameterName().equals("Record_ID")) + record_ID = para[i].getParameterAsInt(); + else + log.log(Level.SEVERE, "Unknown Parameter: " + name); + } + } + + @Override + protected String doIt() throws Exception { + switch(tableName){ + case "C_Order" : + MOrder o = new MOrder(getCtx(), record_ID, get_TrxName()); + if(!o.processIt(DocAct)) + return "Failed to Complete Document !!!"; + o.saveEx(); + break; + case "M_InOut" : + MInOut io = new MInOut(getCtx(), record_ID, get_TrxName()); + if(!io.processIt(DocAct)) + return "Failed to Complete Document !!!"; + io.saveEx(); + break; + case "C_Invoice" : + MInvoice inv = new MInvoice(getCtx(), record_ID, get_TrxName()); + if(!inv.processIt(DocAct)) + return "Failed to Complete Document !!!"; + inv.saveEx(); + break; + case "C_Payment" : + MPayment p = new MPayment(getCtx(), record_ID, get_TrxName()); + if(!p.processIt(DocAct)) + return "Failed to Complete Document !!!"; + p.saveEx(); + break; + case "MID_Requisition" : + MID_MRequisitionTrx rs = new MID_MRequisitionTrx(getCtx(), record_ID, get_TrxName()); + if(!rs.processIt(DocAct)) + return "Failed to Complete Document !!!"; + rs.saveEx(); + break; + case "M_Requisition" : + MRequisition req = new MRequisition(getCtx(), record_ID, get_TrxName()); + if(!req.processIt(DocAct)) + return "Failed to Complete Document !!!"; + req.saveEx(); + break; + case "M_RMA" : + MRMA rma = new MRMA(getCtx(), record_ID, get_TrxName()); + if(!rma.processIt(DocAct)) + return "Failed to Complete Document !!!"; + rma.saveEx(); + break; + + default : return "Table not defined by WS !!!"; + } + return "Document Process Complete !!!"; + } + +} diff --git a/andromeida.midsuit.project/src/andromedia/midsuit/process/MID_InsertIntoAllTable.java b/andromeida.midsuit.project/src/andromedia/midsuit/process/MID_InsertIntoAllTable.java index d656cd2..ba406c7 100644 --- a/andromeida.midsuit.project/src/andromedia/midsuit/process/MID_InsertIntoAllTable.java +++ b/andromeida.midsuit.project/src/andromedia/midsuit/process/MID_InsertIntoAllTable.java @@ -1,29 +1,23 @@ package andromedia.midsuit.process; import java.lang.reflect.Constructor; - +import java.lang.reflect.Method; import java.math.BigDecimal; import java.sql.ResultSet; import java.sql.Timestamp; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.logging.Level; -import javax.management.MalformedObjectNameException; -import javax.swing.JComboBox.KeySelectionManager; - import org.adempiere.base.DefaultModelFactory; import org.adempiere.exceptions.AdempiereException; import org.compiere.model.MEntityType; import org.compiere.model.MTable; import org.compiere.model.PO; import org.compiere.model.Query; -import org.compiere.process.DocAction; -import org.compiere.process.DocumentEngine; import org.compiere.process.ProcessInfoParameter; import org.compiere.process.SvrProcess; import org.compiere.util.CCache; @@ -31,7 +25,6 @@ import org.compiere.util.CLogger; import org.compiere.util.Env; import org.compiere.util.Trx; import org.compiere.util.Util; -import org.zkoss.json.JSONArray; import org.zkoss.json.JSONObject; import org.zkoss.json.parser.JSONParser; @@ -60,6 +53,7 @@ public class MID_InsertIntoAllTable extends SvrProcess{ JSONObject JSON = (JSONObject) parser.parse(jsonString); if(JSON!=null) { PO po = null; + tableName = JSON.get("TableName").toString(); JSONObject Data = (JSONObject) JSON.get("Data"); String Mode = JSON.get("Mode").toString(); @@ -68,41 +62,41 @@ public class MID_InsertIntoAllTable extends SvrProcess{ po = getPO(tableName, 0, get_TrxName()); } -// else if (Mode.equals("U")) { -// if(whereClause.length()>0) { -// JSONObject params = (JSONObject) JSON.get("Params"); -// Set whereParams = params.keySet(); -// Iterator keysWhereParams = whereParams.iterator(); -// List parameters = new ArrayList(); -// while (keysWhereParams.hasNext()){ -// parameters.add(params.get(keysWhereParams.next())); -// } -// -// Object[] paramValues = parameters.toArray(new Object[parameters.size()]); -// -// int[] IDs = new Query(getCtx(), tableName, whereClause,get_TrxName()) -// .setParameters(paramValues) -// .setOnlyActiveRecords(true) -// .getIDs(); -// -// for(int ID : IDs) { -// PO obj = null; -// obj = getPO(tableName, ID, get_TrxName()); -// Set keySetMass= Data.keySet(); -// Iterator keysMass = keySetMass.iterator(); -// while(keysMass.hasNext()) { -// String columnInsert = keysMass.next().toString(); -// obj.set_ValueNoCheck(columnInsert, Data.get(columnInsert).toString()); -// } -// if(!obj.save()) -// throw new AdempiereException("Failed to Save the Data !"); -// } -// return "Update Mass Data Success !!"; -// }else { -// int Record_ID = Integer.parseInt(Data.get("Record_ID").toString()); -// po = getPO(tableName, Record_ID, get_TrxName()); -// } -// } + else if (Mode.equals("U")) { + if(whereClause.length()>0) { + JSONObject params = (JSONObject) JSON.get("Params"); + Set whereParams = params.keySet(); + Iterator keysWhereParams = whereParams.iterator(); + List parameters = new ArrayList(); + while (keysWhereParams.hasNext()){ + parameters.add(params.get(keysWhereParams.next())); + } + + Object[] paramValues = parameters.toArray(new Object[parameters.size()]); + + int[] IDs = new Query(getCtx(), tableName, whereClause,get_TrxName()) + .setParameters(paramValues) + .setOnlyActiveRecords(true) + .getIDs(); + + for(int ID : IDs) { + PO obj = null; + obj = getPO(tableName, ID, get_TrxName()); + Set keySetMass= Data.keySet(); + Iterator keysMass = keySetMass.iterator(); + while(keysMass.hasNext()) { + String columnInsert = keysMass.next().toString(); + obj.set_ValueNoCheck(columnInsert, Data.get(columnInsert).toString()); + } + if(!obj.save()) + throw new AdempiereException("Failed to Save the Data !"); + } + return "Update Mass Data Success !!"; + }else { + int Record_ID = Integer.parseInt(Data.get("Record_ID").toString()); + po = getPO(tableName, Record_ID, get_TrxName()); + } + } Set keySet= Data.keySet(); Iterator keys = keySet.iterator(); @@ -121,18 +115,38 @@ public class MID_InsertIntoAllTable extends SvrProcess{ if(po.set_ValueOfColumnReturningBoolean(columnInsert, Data.get(columnInsert))){ } else if(po.set_ValueOfColumnReturningBoolean(columnInsert, new BigDecimal(Data.get(columnInsert).toString()))){ } else{throw new AdempiereException("Cannot Fill Column "+columnInsert);} - if(po.get_Value(columnInsert)==null) throw new AdempiereException("Cannot Fill Column "+columnInsert); + } } if(columnset.length()>0) return columnset; if(!po.save(get_TrxName())) throw new AdempiereException("Failed to Save the Data !"); + + if(po.get_Value("DocAction")!=null) { + Class clazz = getClass(tableName); + if (clazz == null) + { + return null; + } + + Constructor constructor = clazz.getDeclaredConstructor(new Class[]{Properties.class, ResultSet.class, String.class}); + Object classDocument = constructor.newInstance(new Object[] {Env.getCtx(), po.get_ID(), get_TrxName()}); + Method meth = clazz.getDeclaredMethod("processIt", String.class); + try { + meth.invoke(classDocument, po.get_ValueAsString("DocAction")); + }catch(Exception e) { + return "Failed to Process Document !!"; + } + } + if(Trx.get(get_TrxName(), false).commit()){ return String.valueOf(po.get_ID()); }else return "Failed to Save the Data !!!"; + + } }else { return "No JSON to be processed !";