parent
669f535363
commit
742452ead4
|
|
@ -1,11 +1,15 @@
|
|||
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;
|
||||
|
|
@ -20,12 +24,14 @@ 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 net.ucanaccess.jdbc.UcanaccessDriver;
|
||||
|
||||
public class MID_UploadPEB extends SvrProcess{
|
||||
|
||||
String p_File = "";
|
||||
int p_C_DocType_ID =0;
|
||||
@Override
|
||||
protected void prepare() {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
@ -34,6 +40,8 @@ public class MID_UploadPEB extends SvrProcess{
|
|||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -57,8 +65,73 @@ public class MID_UploadPEB extends SvrProcess{
|
|||
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;
|
||||
}
|
||||
|
||||
MOrder order = new MOrder(getCtx(), 0, get_TrxName());
|
||||
order.setAD_Org_ID(Env.getContextAsInt(getCtx(), "#AD_Org_ID"));
|
||||
order.set_ValueNoCheck("RegisterNo", row.getCell(103).getStringCellValue());
|
||||
order.setIsSOTrx(false);
|
||||
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 });
|
||||
order.set_ValueNoCheck("MID_AJUDocumentType_ID", MID_AJUDocType_ID);
|
||||
|
||||
int C_BPartner_ID = DB.getSQLValue(get_TrxName(), "SELECT C_BPartner_ID FROM C_Bpartner WHERE Name =? AND AD_Client_ID =? AND IsVendor ='Y'", new Object[] { row.getCell(3).getStringCellValue(), getAD_Client_ID()});
|
||||
if(C_BPartner_ID <=0)
|
||||
throw new AdempiereException("Business Partner Not Found "+row.getCell(3).getStringCellValue()+" !!!");
|
||||
|
||||
int C_Currency_ID = DB.getSQLValue(get_TrxName(), "SELECT C_Currency_ID FROM C_Currency WHERE ISO_Code =? ", new Object[] { row.getCell(88).getStringCellValue()});
|
||||
if(C_BPartner_ID <=0)
|
||||
throw new AdempiereException("Currency Not Found "+row.getCell(88).getStringCellValue()+" !!!");
|
||||
order.setC_BPartner_ID(C_BPartner_ID);
|
||||
order.setC_BPartner_Location_ID(MBPartnerLocation.getForBPartner(getCtx(), C_BPartner_ID, get_TrxName())[0].getC_BPartner_Location_ID());
|
||||
order.setC_DocTypeTarget_ID(p_C_DocType_ID);
|
||||
order.setSalesRep_ID(30178);
|
||||
order.setM_Warehouse_ID(30045);
|
||||
|
||||
int M_PriceList_ID = DB.getSQLValue(get_TrxName(), "SELECT M_PriceList_ID FROM M_PriceList WHERE C_Currency_ID =? AND AD_Client_ID =? AND IsSOPriceList =?", new Object[] { C_Currency_ID, getAD_Client_ID(), false });
|
||||
order.setC_Currency_ID(C_Currency_ID);
|
||||
order.setM_PriceList_ID(M_PriceList_ID);
|
||||
order.saveEx();
|
||||
|
||||
Sheet Barang = null;
|
||||
if(AJU_DocType_Value.equals("41"))
|
||||
Barang = workbook.getSheet("Barang");
|
||||
else
|
||||
Barang = workbook.getSheet("Bahan Baku");
|
||||
|
||||
Iterator<Row> rowsBarang = Barang.rowIterator();
|
||||
int rowBarangNum = 0;
|
||||
while(rowsBarang.hasNext()){
|
||||
Row rowBarang = rowsBarang.next();
|
||||
if(rowBarangNum == 0){
|
||||
rowBarangNum++;
|
||||
continue;
|
||||
}
|
||||
if(rowBarang.getCell(0).getStringCellValue().equals(row.getCell(0).getStringCellValue()))
|
||||
createOrderLine(order, rowBarang, row, AJU_DocType_Value);
|
||||
|
||||
rowBarangNum++;
|
||||
}
|
||||
rowNum++;
|
||||
|
||||
String message = Msg.parseTranslation(getCtx(), "@OrderCreated@ " + order.getDocumentNo());
|
||||
addBufferLog(order.getC_Order_ID(), order.getDateOrdered(), null, message,
|
||||
order.get_Table_ID(), order.getC_Order_ID());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void readAccess(File TPB) throws Exception{
|
||||
String msg = "";
|
||||
File f_Access = new File(p_File);
|
||||
|
|
@ -121,5 +194,62 @@ public class MID_UploadPEB extends SvrProcess{
|
|||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private MOrderLine createOrderLine(MOrder order, Row rowBarang,Row rowHeader, String aJU_DocType_Value) {
|
||||
MOrderLine retValue = new MOrderLine(order);
|
||||
int M_Product_ID =0;
|
||||
BigDecimal Qty = Env.ZERO;
|
||||
int C_UOM_ID = 0;
|
||||
BigDecimal PriceList = Env.ZERO;
|
||||
BigDecimal Discount = Env.ZERO;
|
||||
BigDecimal PriceActual = Env.ZERO;
|
||||
if(aJU_DocType_Value.equals("41")){
|
||||
M_Product_ID = DB.getSQLValue(get_TrxName(), "SELECT M_Product_ID FROM M_Product WHERE Value =?", new Object[] { rowBarang.getCell(20).getStringCellValue() });
|
||||
C_UOM_ID = DB.getSQLValue(get_TrxName(), " SELECT C_UOM_ID FROM C_UOM WHERE UOMSymbol =?", new Object[] { rowBarang.getCell(27).getStringCellValue()});
|
||||
|
||||
if(M_Product_ID <=0)
|
||||
throw new AdempiereException("Product Not Found "+rowBarang.getCell(20).getStringCellValue()+" !!!");
|
||||
if(C_UOM_ID <=0)
|
||||
throw new AdempiereException("UOM Not Found "+rowBarang.getCell(27).getStringCellValue()+" !!!");
|
||||
|
||||
}else{
|
||||
M_Product_ID = DB.getSQLValue(get_TrxName(), "SELECT M_Product_ID FROM M_Product WHERE Value =?", new Object[] { rowBarang.getCell(10).getStringCellValue() });
|
||||
C_UOM_ID = DB.getSQLValue(get_TrxName(), " SELECT C_UOM_ID FROM C_UOM WHERE UOMSymbol =?", new Object[] { rowBarang.getCell(7).getStringCellValue()});
|
||||
|
||||
if(M_Product_ID <=0)
|
||||
throw new AdempiereException("Product Not Found "+rowBarang.getCell(10).getStringCellValue()+" !!!");
|
||||
if(C_UOM_ID <=0)
|
||||
throw new AdempiereException("UOM Not Found "+rowBarang.getCell(7).getStringCellValue()+" !!!");
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(aJU_DocType_Value.equals("41")){
|
||||
Qty = new BigDecimal(rowBarang.getCell(16).getNumericCellValue());
|
||||
PriceList = new BigDecimal(rowBarang.getCell(29).getNumericCellValue());
|
||||
PriceActual = PriceList;
|
||||
}else{
|
||||
Qty = new BigDecimal(rowBarang.getCell(8).getNumericCellValue());
|
||||
PriceList = new BigDecimal(rowBarang.getCell(3).getNumericCellValue());
|
||||
if(aJU_DocType_Value.equals("25") || aJU_DocType_Value.equals("27"))
|
||||
PriceActual = new BigDecimal(rowBarang.getCell(5).getNumericCellValue());
|
||||
else
|
||||
PriceActual = PriceList;
|
||||
}
|
||||
|
||||
if(aJU_DocType_Value.equals("27")){
|
||||
Discount = new BigDecimal(rowHeader.getCell(22).getNumericCellValue());
|
||||
}
|
||||
|
||||
retValue.setM_Product_ID(M_Product_ID);
|
||||
retValue.setC_UOM_ID(C_UOM_ID);
|
||||
retValue.setQty(Qty);
|
||||
retValue.setPriceList(PriceList);
|
||||
retValue.setDiscount(Discount);
|
||||
retValue.setPrice(PriceActual);
|
||||
retValue.saveEx();
|
||||
return retValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue