Update WS Complete Record ( EXCLUSIVE FOR PULSA 21 ONLY )

This commit is contained in:
hodianto 2018-03-30 10:46:33 +07:00
parent ecd0b51fb9
commit b2bc6d615d
2 changed files with 146 additions and 44 deletions

View File

@ -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 !!!";
}
}

View File

@ -1,29 +1,23 @@
package andromedia.midsuit.process; package andromedia.midsuit.process;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import javax.management.MalformedObjectNameException;
import javax.swing.JComboBox.KeySelectionManager;
import org.adempiere.base.DefaultModelFactory; import org.adempiere.base.DefaultModelFactory;
import org.adempiere.exceptions.AdempiereException; import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.MEntityType; import org.compiere.model.MEntityType;
import org.compiere.model.MTable; import org.compiere.model.MTable;
import org.compiere.model.PO; import org.compiere.model.PO;
import org.compiere.model.Query; import org.compiere.model.Query;
import org.compiere.process.DocAction;
import org.compiere.process.DocumentEngine;
import org.compiere.process.ProcessInfoParameter; import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess; import org.compiere.process.SvrProcess;
import org.compiere.util.CCache; import org.compiere.util.CCache;
@ -31,7 +25,6 @@ import org.compiere.util.CLogger;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Trx; import org.compiere.util.Trx;
import org.compiere.util.Util; import org.compiere.util.Util;
import org.zkoss.json.JSONArray;
import org.zkoss.json.JSONObject; import org.zkoss.json.JSONObject;
import org.zkoss.json.parser.JSONParser; import org.zkoss.json.parser.JSONParser;
@ -60,6 +53,7 @@ public class MID_InsertIntoAllTable extends SvrProcess{
JSONObject JSON = (JSONObject) parser.parse(jsonString); JSONObject JSON = (JSONObject) parser.parse(jsonString);
if(JSON!=null) { if(JSON!=null) {
PO po = null; PO po = null;
tableName = JSON.get("TableName").toString(); tableName = JSON.get("TableName").toString();
JSONObject Data = (JSONObject) JSON.get("Data"); JSONObject Data = (JSONObject) JSON.get("Data");
String Mode = JSON.get("Mode").toString(); String Mode = JSON.get("Mode").toString();
@ -68,41 +62,41 @@ public class MID_InsertIntoAllTable extends SvrProcess{
po = getPO(tableName, 0, get_TrxName()); po = getPO(tableName, 0, get_TrxName());
} }
// else if (Mode.equals("U")) { else if (Mode.equals("U")) {
// if(whereClause.length()>0) { if(whereClause.length()>0) {
// JSONObject params = (JSONObject) JSON.get("Params"); JSONObject params = (JSONObject) JSON.get("Params");
// Set<Object> whereParams = params.keySet(); Set<Object> whereParams = params.keySet();
// Iterator<Object> keysWhereParams = whereParams.iterator(); Iterator<Object> keysWhereParams = whereParams.iterator();
// List<Object> parameters = new ArrayList<Object>(); List<Object> parameters = new ArrayList<Object>();
// while (keysWhereParams.hasNext()){ while (keysWhereParams.hasNext()){
// parameters.add(params.get(keysWhereParams.next())); parameters.add(params.get(keysWhereParams.next()));
// } }
//
// Object[] paramValues = parameters.toArray(new Object[parameters.size()]); Object[] paramValues = parameters.toArray(new Object[parameters.size()]);
//
// int[] IDs = new Query(getCtx(), tableName, whereClause,get_TrxName()) int[] IDs = new Query(getCtx(), tableName, whereClause,get_TrxName())
// .setParameters(paramValues) .setParameters(paramValues)
// .setOnlyActiveRecords(true) .setOnlyActiveRecords(true)
// .getIDs(); .getIDs();
//
// for(int ID : IDs) { for(int ID : IDs) {
// PO obj = null; PO obj = null;
// obj = getPO(tableName, ID, get_TrxName()); obj = getPO(tableName, ID, get_TrxName());
// Set<Object> keySetMass= Data.keySet(); Set<Object> keySetMass= Data.keySet();
// Iterator<Object> keysMass = keySetMass.iterator(); Iterator<Object> keysMass = keySetMass.iterator();
// while(keysMass.hasNext()) { while(keysMass.hasNext()) {
// String columnInsert = keysMass.next().toString(); String columnInsert = keysMass.next().toString();
// obj.set_ValueNoCheck(columnInsert, Data.get(columnInsert).toString()); obj.set_ValueNoCheck(columnInsert, Data.get(columnInsert).toString());
// } }
// if(!obj.save()) if(!obj.save())
// throw new AdempiereException("Failed to Save the Data !"); throw new AdempiereException("Failed to Save the Data !");
// } }
// return "Update Mass Data Success !!"; return "Update Mass Data Success !!";
// }else { }else {
// int Record_ID = Integer.parseInt(Data.get("Record_ID").toString()); int Record_ID = Integer.parseInt(Data.get("Record_ID").toString());
// po = getPO(tableName, Record_ID, get_TrxName()); po = getPO(tableName, Record_ID, get_TrxName());
// } }
// } }
Set<Object> keySet= Data.keySet(); Set<Object> keySet= Data.keySet();
Iterator<Object> keys = keySet.iterator(); Iterator<Object> keys = keySet.iterator();
@ -121,18 +115,38 @@ public class MID_InsertIntoAllTable extends SvrProcess{
if(po.set_ValueOfColumnReturningBoolean(columnInsert, Data.get(columnInsert))){ } if(po.set_ValueOfColumnReturningBoolean(columnInsert, Data.get(columnInsert))){ }
else if(po.set_ValueOfColumnReturningBoolean(columnInsert, new BigDecimal(Data.get(columnInsert).toString()))){ } else if(po.set_ValueOfColumnReturningBoolean(columnInsert, new BigDecimal(Data.get(columnInsert).toString()))){ }
else{throw new AdempiereException("Cannot Fill Column "+columnInsert);} else{throw new AdempiereException("Cannot Fill Column "+columnInsert);}
if(po.get_Value(columnInsert)==null) throw new AdempiereException("Cannot Fill Column "+columnInsert); if(po.get_Value(columnInsert)==null) throw new AdempiereException("Cannot Fill Column "+columnInsert);
} }
} }
if(columnset.length()>0) if(columnset.length()>0)
return columnset; return columnset;
if(!po.save(get_TrxName())) if(!po.save(get_TrxName()))
throw new AdempiereException("Failed to Save the Data !"); 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()){ if(Trx.get(get_TrxName(), false).commit()){
return String.valueOf(po.get_ID()); return String.valueOf(po.get_ID());
}else }else
return "Failed to Save the Data !!!"; return "Failed to Save the Data !!!";
} }
}else { }else {
return "No JSON to be processed !"; return "No JSON to be processed !";