117 lines
3.6 KiB
Java
117 lines
3.6 KiB
Java
package com.amarsoft.acct.accounting.web;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import com.amarsoft.are.jbo.BizObject;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import com.amarsoft.app.base.businessobject.BusinessObject;
|
|
import com.amarsoft.app.base.businessobject.BusinessObjectManager;
|
|
import com.amarsoft.are.jbo.JBOTransaction;
|
|
import com.amarsoft.are.util.json.JSONDecoder;
|
|
import com.amarsoft.are.util.json.JSONElement;
|
|
import com.amarsoft.are.util.json.JSONObject;
|
|
|
|
public class SavePaymentSchedule {
|
|
|
|
public String psList;
|
|
|
|
public String objectNo;
|
|
|
|
public String objectType;
|
|
|
|
public String getPsList() {
|
|
return psList;
|
|
}
|
|
|
|
public void setPsList(String psList) {
|
|
this.psList = psList;
|
|
}
|
|
|
|
public String getObjectNo() {
|
|
return objectNo;
|
|
}
|
|
|
|
public void setObjectNo(String objectNo) {
|
|
this.objectNo = objectNo;
|
|
}
|
|
|
|
public String getObjectType() {
|
|
return objectType;
|
|
}
|
|
|
|
public void setObjectType(String objectType) {
|
|
this.objectType = objectType;
|
|
}
|
|
|
|
|
|
public String save(JBOTransaction tx) throws Exception{
|
|
if(psList != null && !"".equals(psList)){
|
|
psList = psList.replace("leftbrace_", "{").replace("rightbrace_", "}").replace("}comma_ {", "},{").replace("marks_", "\"");
|
|
List<BusinessObject> list = new ArrayList<BusinessObject>();
|
|
for(String psStr : psList.split(",")){
|
|
psStr = psStr.replace("comma_", ",");
|
|
psStr = psStr.substring(35, psStr.length()-2).replace("\"", "");
|
|
|
|
Map<String,Object> values = new HashMap<String, Object>();
|
|
for(String kv : psStr.split(",")){
|
|
String key = kv.split(":")[0];
|
|
String value = kv.split(":").length>1?kv.split(":")[1]:"";
|
|
values.put(key, value);
|
|
}
|
|
|
|
BusinessObject valuebo = BusinessObject.createBusinessObject(values);
|
|
BusinessObject ps = BusinessObject.createBusinessObject("jbo.acct.ACCT_PAYMENT_SCHEDULE");
|
|
ps.setAttributes(valuebo);
|
|
ps.generateKey(true);
|
|
ps.setAttributeValue("RelativeObjectNo", objectNo);
|
|
ps.setAttributeValue("RelativeObjectType", objectType);
|
|
ps.setAttributeValue("ObjectNo", objectNo);
|
|
ps.setAttributeValue("ObjectType", objectType);
|
|
list.add(ps);
|
|
}
|
|
|
|
// psList = psList.replace("leftbrace_", "{").replace("rightbrace_", "}").replace("}comma_ {", "},{").replace("marks_", "\"");
|
|
//// com.amarsoft.core.json.JSONObject json = new com.amarsoft.core.json.JSONObject();
|
|
// JSONObject json = JSONObject.createObject();
|
|
// int count=0;
|
|
// BusinessObject psbo = BusinessObject.createBusinessObject("jbo.acct.ACCT_PAYMENT_SCHEDULE");
|
|
// for(String ps : psList.split(",")){
|
|
// ps = ps.replace("comma_", ",");
|
|
// count++;
|
|
// JSONElement e = new JSONElement(ps);
|
|
// e.setValue(ps);
|
|
// json.add(count, e);
|
|
// psbo.setAttributes(BusinessObject.createBusinessObject((Element)e);
|
|
// psbo.setAttributeValue("RelativeObjectNo", objectNo);
|
|
// psbo.setAttributeValue("RelativeObjectType", objectType);
|
|
// psbo.setAttributeValue("ObjectNo", objectNo);
|
|
// psbo.setAttributeValue("ObjectType", objectType);
|
|
// psbo.generateKey();
|
|
//
|
|
// }
|
|
//
|
|
//// JSONObject psjson = JSONDecoder.decode(json.toString());
|
|
// List<BusinessObject> list = new ArrayList<BusinessObject>();
|
|
// for(int i = 0;i < json.size(); i ++){
|
|
//
|
|
// }
|
|
|
|
BusinessObjectManager bom = BusinessObjectManager.createBusinessObjectManager(tx);
|
|
|
|
List<BusinessObject> oldPSList = bom.loadBusinessObjects("jbo.acct.ACCT_PAYMENT_SCHEDULE", "ObjectNo=:ObjectNo and ObjectType=:ObjectType", "ObjectNo",objectNo,"ObjectType",objectType);
|
|
bom.deleteBusinessObjects(oldPSList);
|
|
bom.updateBusinessObjects(list);
|
|
bom.updateDB();
|
|
bom.commit();
|
|
return "success";
|
|
}else{
|
|
return "failure";
|
|
}
|
|
}
|
|
|
|
}
|