use of org.compiere.model.PO in project adempiere by adempiere.
the class Export method doIt.
/**
* Process - Generate Export Format
* @return info
*/
protected String doIt() throws Exception {
outDocument = createNewDocument();
MClient client = MClient.get(getCtx(), p_AD_Client_ID);
log.info(client.toString());
// TODO - get proper Export Format!
int EXP_Format_ID = 1000000;
MTable table = MTable.get(getCtx(), AD_Table_ID);
log.info("Table = " + table);
PO po = table.getPO(p_Record_ID, get_TrxName());
if (po.get_KeyColumns().length > 1 || po.get_KeyColumns().length < 1) {
throw new Exception(Msg.getMsg(getCtx(), "ExportMultiColumnNotSupported"));
}
MEXPFormat exportFormat = new MEXPFormat(getCtx(), EXP_Format_ID, get_TrxName());
StringBuffer sql = new StringBuffer("SELECT * ").append("FROM ").append(table.getTableName()).append(" ").append("WHERE ").append(po.get_KeyColumns()[0]).append("=?");
if (exportFormat.getWhereClause() != null & !"".equals(exportFormat.getWhereClause())) {
sql.append(" AND ").append(exportFormat.getWhereClause());
}
ResultSet rs = null;
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
pstmt.setInt(1, p_Record_ID);
rs = pstmt.executeQuery();
if (rs.next()) {
HashMap<String, Integer> variableMap = new HashMap<String, Integer>();
variableMap.put(TOTAL_SEGMENTS, new Integer(1));
Element rootElement = outDocument.createElement(exportFormat.getValue());
rootElement.appendChild(outDocument.createComment(exportFormat.getDescription()));
outDocument.appendChild(rootElement);
generateExportFormat(rootElement, exportFormat, rs, po, p_Record_ID, variableMap);
}
} finally {
try {
if (rs != null)
rs.close();
if (pstmt != null)
pstmt.close();
} catch (SQLException ex) {
/*ignored*/
}
rs = null;
pstmt = null;
}
/* int C_EDIProcessorType_ID = ediProcessor.getC_EDIProcessorType_ID();
X_C_EDIProcessorType ediProcessType = new X_C_EDIProcessorType(getCtx(), C_EDIProcessorType_ID, get_TrxName() );
String javaClass = ediProcessType.getJavaClass();
try {
Class clazz = Class.forName(javaClass);
IOutbandEdiProcessor outbandProcessor = (IOutbandEdiProcessor)clazz.newInstance();
outbandProcessor.process(getCtx(), ediProcessor, result.toString(), "C_Invoice-"+p_Record_ID+".txt", Trx.get( get_TrxName(), false ));
} catch (Exception e) {
result = new StringBuffer( e.toString() );
}
*/
addLog(0, null, null, Msg.getMsg(getCtx(), "ExportProcessResult") + "\n" + outDocument.toString());
return outDocument.toString();
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class MPPMRP method getDurationDays.
/**
* Duration to have this Qty available (i.e. Lead Time + Transfer Time)
* @param qty quantity
* @param pp product planning sheet
* @return return duration [days]
*/
public static int getDurationDays(BigDecimal qty, I_PP_Product_Planning pp) {
Properties ctx = null;
if (pp instanceof PO) {
ctx = ((PO) pp).getCtx();
} else {
ctx = Env.getCtx();
}
MProduct product = MProduct.get(ctx, pp.getM_Product_ID());
BigDecimal leadtime = pp.getDeliveryTime_Promised();
if (leadtime.signum() != 0 || product.isPurchased()) {
;
} else if (pp.getS_Resource_ID() > 0 && pp.getAD_Workflow_ID() > 0) {
RoutingService routingService = RoutingServiceFactory.get().getRoutingService(ctx);
leadtime = routingService.calculateDuration(pp.getAD_Workflow(), pp.getS_Resource(), qty);
// TODO: convert to days
} else {
// TODO: translate or create notice?
throw new AdempiereException("Cannot calculate leadtime for " + pp);
}
return leadtime.add(pp.getTransferTime()).intValue();
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class DefaultRoutingServiceImpl method estimateWorkingTime.
public BigDecimal estimateWorkingTime(I_PP_Cost_Collector cc) {
final String trxName = (cc instanceof PO ? ((PO) cc).get_TrxName() : null);
final BigDecimal qty = cc.getMovementQty();
MPPOrderNode node = MPPOrderNode.get(Env.getCtx(), cc.getPP_Order_Node_ID(), trxName);
return estimateWorkingTime(node, qty);
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class ADSortTab method saveData.
// registerAPanel
/** (non-Javadoc)
* @see org.compiere.grid.APanelTab#saveData()
*/
public void saveData() {
if (!adWindowPanel.getToolbar().isSaveEnable())
return;
log.fine("");
boolean ok = true;
StringBuffer info = new StringBuffer();
MTable table = MTable.get(Env.getCtx(), m_AD_Table_ID);
// noList - Set SortColumn to null and optional YesNo Column to 'N'
for (int i = 0; i < noModel.getSize(); i++) {
ListElement pp = (ListElement) noModel.getElementAt(i);
if (!pp.isUpdateable())
continue;
if (pp.getSortNo() == 0 && (m_ColumnYesNoName == null || !pp.isYes()))
// no changes
continue;
//
PO po = table.getPO(pp.getKey(), null);
po.set_ValueOfColumn(m_ColumnSortName, 0);
po.set_ValueOfColumn(m_ColumnYesNoName, false);
if (po.save()) {
pp.setSortNo(0);
pp.setIsYes(false);
} else {
ok = false;
if (info.length() > 0)
info.append(", ");
info.append(pp.getName());
log.log(Level.SEVERE, "NoModel - Not updated: " + m_KeyColumnName + "=" + pp.getKey());
}
}
// yesList - Set SortColumn to value and optional YesNo Column to 'Y'
int index = 0;
for (int i = 0; i < yesModel.getSize(); i++) {
ListElement pp = (ListElement) yesModel.getElementAt(i);
if (!pp.isUpdateable())
continue;
index += 10;
if (pp.getSortNo() == index && (m_ColumnYesNoName == null || pp.isYes()))
// no changes
continue;
//
PO po = table.getPO(pp.getKey(), null);
po.set_ValueOfColumn(m_ColumnSortName, index);
po.set_ValueOfColumn(m_ColumnYesNoName, true);
if (po.save()) {
pp.setSortNo(index);
pp.setIsYes(true);
} else {
ok = false;
if (info.length() > 0)
info.append(", ");
info.append(pp.getName());
log.log(Level.SEVERE, "YesModel - Not updated: " + m_KeyColumnName + "=" + pp.getKey());
}
}
//
if (ok) {
setIsChanged(false);
} else {
FDialog.error(m_WindowNo, null, "SaveError", info.toString());
}
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class POWrapper method refresh.
/**
* Reload underlying PO object
*
* @param model
* @param trxName transaction to be used for reloading
* @throws IllegalArgumentException if model is null
* @throws IllegalArgumentException if there is no underlying PO object (i.e. getPO(model) return null)
*/
public static void refresh(final Object model, final String trxName) {
if (model == null)
throw new IllegalArgumentException("model is null");
final PO po = getPO(model);
if (po == null)
throw new IllegalArgumentException("Class is not supported - " + model.getClass());
po.load(trxName);
}
Aggregations