Upload PEB On Sales Order & Asset Addition
--HG-- branch : EDII
This commit is contained in:
parent
499cf24ba7
commit
2479ccabda
|
|
@ -7,6 +7,7 @@ import java.util.Properties;
|
||||||
import org.adempiere.exceptions.AdempiereException;
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
import org.compiere.model.MAsset;
|
import org.compiere.model.MAsset;
|
||||||
import org.compiere.model.MAssetAddition;
|
import org.compiere.model.MAssetAddition;
|
||||||
|
import org.compiere.model.MDepreciationEntry;
|
||||||
import org.compiere.model.MDepreciationExp;
|
import org.compiere.model.MDepreciationExp;
|
||||||
import org.compiere.model.MFactAcct;
|
import org.compiere.model.MFactAcct;
|
||||||
import org.compiere.model.MInvoiceLine;
|
import org.compiere.model.MInvoiceLine;
|
||||||
|
|
@ -64,6 +65,17 @@ public class MID_MAssetAddition extends MAssetAddition implements DocOptions{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean closeIt() {
|
public boolean closeIt() {
|
||||||
|
|
||||||
|
int draftAdditionCount = new Query(getCtx(), MDepreciationExp.Table_Name, " ade.DocStatus =? and A_Depreciation_Exp.A_Asset_ID =?", get_TrxName())
|
||||||
|
.addJoinClause(" JOIN A_Depreciation_Entry ade ON ade.A_Depreciation_Entry_ID = A_Depreciation_Exp.A_Depreciation_Entry_ID ")
|
||||||
|
.setOnlyActiveRecords(true)
|
||||||
|
.setParameters(new Object[] { DocAction.STATUS_Drafted, getA_Asset_ID() })
|
||||||
|
.count();
|
||||||
|
|
||||||
|
if(draftAdditionCount > 0) {
|
||||||
|
throw new AdempiereException(" Pastikan tidak ada Asset Addition yang draft !!!");
|
||||||
|
}
|
||||||
|
|
||||||
final String whereClause = MDepreciationExp.COLUMNNAME_A_Asset_ID+" =? AND "+MDepreciationExp.COLUMNNAME_PostingType+"=? AND A_Depreciation_Entry_ID IS NULL";
|
final String whereClause = MDepreciationExp.COLUMNNAME_A_Asset_ID+" =? AND "+MDepreciationExp.COLUMNNAME_PostingType+"=? AND A_Depreciation_Entry_ID IS NULL";
|
||||||
List<MDepreciationExp>
|
List<MDepreciationExp>
|
||||||
list = new Query(getCtx(), MDepreciationExp.Table_Name, whereClause, get_TrxName())
|
list = new Query(getCtx(), MDepreciationExp.Table_Name, whereClause, get_TrxName())
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,125 @@
|
||||||
|
package andromedia.midsuit.process;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||||
|
import org.compiere.model.MBPartnerLocation;
|
||||||
|
import org.compiere.model.MOrder;
|
||||||
|
import org.compiere.model.MOrderLine;
|
||||||
|
import org.compiere.process.ProcessInfoParameter;
|
||||||
|
import org.compiere.process.SvrProcess;
|
||||||
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
import org.compiere.util.Msg;
|
||||||
|
|
||||||
|
import andromedia.midsuit.model.MID_MOrder;
|
||||||
|
import net.ucanaccess.jdbc.UcanaccessDriver;
|
||||||
|
|
||||||
|
public class MID_UploadPEBOrder extends SvrProcess{
|
||||||
|
|
||||||
|
String p_File = "";
|
||||||
|
int p_C_DocType_ID =0;
|
||||||
|
MID_MOrder order = null;
|
||||||
|
@Override
|
||||||
|
protected void prepare() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
ProcessInfoParameter[] para = getParameter();
|
||||||
|
for (int i = 0; i < para.length; i++)
|
||||||
|
{
|
||||||
|
if(para[i].getParameterName().equals("FileName"))
|
||||||
|
p_File = para[i].getParameterAsString();
|
||||||
|
else if(para[i].getParameterName().equals("C_DocType_ID"))
|
||||||
|
p_C_DocType_ID = para[i].getParameterAsInt();
|
||||||
|
}
|
||||||
|
order = new MID_MOrder(getCtx(), getRecord_ID(), get_TrxName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String doIt() throws Exception {
|
||||||
|
File TPB = new File(p_File);
|
||||||
|
int formatIndex = TPB.getName().lastIndexOf(".");
|
||||||
|
if(TPB.getName().substring(formatIndex+1).equalsIgnoreCase("xlsx") ||
|
||||||
|
TPB.getName().substring(formatIndex+1).equalsIgnoreCase("xls")){
|
||||||
|
readExcel(TPB, order);
|
||||||
|
}else{
|
||||||
|
readAccess(TPB, order);
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void readExcel(File TPB, MID_MOrder order) throws Exception{
|
||||||
|
Workbook workbook = WorkbookFactory.create(TPB);
|
||||||
|
Sheet header = workbook.getSheet("Header");
|
||||||
|
Iterator<Row> rows = header.rowIterator();
|
||||||
|
int rowNum = 0;
|
||||||
|
|
||||||
|
while(rows.hasNext()){
|
||||||
|
Row row = rows.next();
|
||||||
|
if(rowNum==0) {
|
||||||
|
rowNum++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
order.set_ValueNoCheck("RegisterNo", row.getCell(103).getStringCellValue());
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy");
|
||||||
|
Date parsedDate = dateFormat.parse(row.getCell(117).getStringCellValue());
|
||||||
|
Timestamp registerDate = new Timestamp(parsedDate.getTime());
|
||||||
|
order.set_ValueNoCheck("RegisterDate", registerDate);
|
||||||
|
order.set_ValueNoCheck("NoAju1", row.getCell(0).getStringCellValue());
|
||||||
|
String AJU_DocType_Value = row.getCell(5).getStringCellValue();
|
||||||
|
int MID_AJUDocType_ID = DB.getSQLValue(get_TrxName(), "SELECT MID_AJUDocumentType_ID FROM MID_AjuDocumentType WHERE Value =?", new Object[] { AJU_DocType_Value });
|
||||||
|
if(MID_AJUDocType_ID <=0)
|
||||||
|
throw new AdempiereException("AJU Document For "+AJU_DocType_Value+" !!!");
|
||||||
|
order.set_ValueNoCheck("MID_AJUDocumentType_ID", MID_AJUDocType_ID);
|
||||||
|
order.saveEx();
|
||||||
|
|
||||||
|
DB.executeUpdateEx("UPDATE C_OrderLine SET NoAju =? WHERE C_Order_ID =?", new Object[] { order.get_ValueAsString("NoAju1"), order.get_ID()}, get_TrxName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void readAccess(File TPB, MID_MOrder order) throws Exception{
|
||||||
|
String msg = "";
|
||||||
|
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
|
||||||
|
String databaseURL = "jdbc:ucanaccess://" + TPB.getPath() + ";jackcessOpener=andromedia.midsuit.process.CryptCodecOpener";
|
||||||
|
try (Connection conn = DriverManager.getConnection(databaseURL)) {
|
||||||
|
|
||||||
|
String sql = "SELECT * FROM tblPebHdr";
|
||||||
|
|
||||||
|
Statement statement = conn.createStatement();
|
||||||
|
ResultSet rs = statement.executeQuery(sql);
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
if (msg != "") throw new AdempiereException(msg);
|
||||||
|
int MID_AJUDocumentType_ID = DB.getSQLValue(get_TrxName(), "SELECT MID_AJUDocumentType_ID FROM MID_AJUDocumentType WHERE Value =? AND AD_Client_ID =?", new Object[] { "30", getAD_Client_ID() });
|
||||||
|
String no_aju = rs.getString("CAR");
|
||||||
|
|
||||||
|
order.set_ValueNoCheck("RegisterNo", rs.getString("NODAFT"));
|
||||||
|
order.set_ValueNoCheck("MID_AJUDocumentType_ID", MID_AJUDocumentType_ID);
|
||||||
|
order.set_ValueNoCheck("RegisterDate", rs.getTimestamp("TGDAFT"));
|
||||||
|
order.set_ValueNoCheck("NoAju1", no_aju);
|
||||||
|
order.saveEx();
|
||||||
|
|
||||||
|
DB.executeUpdateEx("UPDATE C_OrderLine SET NoAju =? WHERE C_Order_ID =?", new Object[] { no_aju, order.get_ID()}, get_TrxName());
|
||||||
|
}
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue