use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class VBPartner method actionSave.
// actionPerformed
/**
* Save.
* Checks mandatory fields and saves Partner, Contact and Location
* @return true if saved
*/
private boolean actionSave() {
log.config("");
// Check Mandatory fields
if (fName.getText().equals("")) {
fName.setBackground(AdempierePLAF.getFieldBackground_Error());
return false;
} else
fName.setBackground(AdempierePLAF.getFieldBackground_Mandatory());
if (fAddress.getC_Location_ID() == 0) {
fAddress.setBackground(AdempierePLAF.getFieldBackground_Error());
return false;
} else
fAddress.setBackground(AdempierePLAF.getFieldBackground_Mandatory());
// ***** Business Partner *****
if (m_partner == null) {
int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
m_partner = MBPartner.getTemplate(Env.getCtx(), AD_Client_ID);
// Elaine 2009/07/03
m_partner.setAD_Org_ID(Env.getAD_Org_ID(Env.getCtx()));
boolean isSOTrx = !"N".equals(Env.getContext(Env.getCtx(), m_WindowNo, "IsSOTrx"));
m_partner.setIsCustomer(isSOTrx);
m_partner.setIsVendor(!isSOTrx);
}
// Check Value
String value = fValue.getText();
if (value == null || value.length() == 0) {
// get Table Documet No
value = DB.getDocumentNo(Env.getAD_Client_ID(Env.getCtx()), "C_BPartner", null, m_partner);
fValue.setText(value);
}
m_partner.setValue(fValue.getText());
//
m_partner.setName(fName.getText());
m_partner.setName2(fName2.getText());
m_partner.setTaxID(fTaxId.getText());
KeyNamePair p = (KeyNamePair) fGreetingBP.getSelectedItem();
if (p != null && p.getKey() > 0)
m_partner.setC_Greeting_ID(p.getKey());
else
m_partner.setC_Greeting_ID(0);
if (m_partner.save())
log.fine("C_BPartner_ID=" + m_partner.getC_BPartner_ID());
else
ADialog.error(m_WindowNo, this, "BPartnerNotSaved");
// ***** Business Partner - Location *****
if (m_pLocation == null)
m_pLocation = new MBPartnerLocation(m_partner);
m_pLocation.setC_Location_ID(fAddress.getC_Location_ID());
m_pLocation.setEMail(fEMail.getText());
m_pLocation.setPhone(fPhone.getText());
m_pLocation.setPhone2(fPhone2.getText());
m_pLocation.setFax(fFax.getText());
if (m_pLocation.save())
log.fine("C_BPartner_Location_ID=" + m_pLocation.getC_BPartner_Location_ID());
else
ADialog.error(m_WindowNo, this, "BPartnerNotSaved", Msg.translate(Env.getCtx(), "C_BPartner_Location_ID"));
// ***** Business Partner - User *****
String contact = fContact.getText();
String email = fEMail.getText();
if (m_user == null && (contact.length() > 0 || email.length() > 0))
m_user = new MUser(m_partner);
if (m_user != null) {
if (contact.length() == 0)
contact = fName.getText();
m_user.setName(contact);
m_user.setEMail(email);
m_user.setTitle(fTitle.getText());
p = (KeyNamePair) fGreetingC.getSelectedItem();
if (p != null && p.getKey() > 0)
m_user.setC_Greeting_ID(p.getKey());
else
m_user.setC_Greeting_ID(0);
//
m_user.setPhone(fPhone.getText());
m_user.setPhone2(fPhone2.getText());
m_user.setFax(fFax.getText());
if (m_user.save())
log.fine("AD_User_ID=" + m_user.getAD_User_ID());
else
ADialog.error(m_WindowNo, this, "BPartnerNotSaved", Msg.translate(Env.getCtx(), "AD_User_ID"));
}
return true;
}
use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class MinuteModel method loadData.
// processWindowEvent
/**************************************************************************
* Load Data.
* - Years
* - Month names
* - Day Names
* @param startTS time stamp
*/
private void loadData(Timestamp startTS) {
// BUG:3075946 KTU - Fix Thai Date
//m_calendar = new GregorianCalendar(Language.getLoginLanguage().getLocale());
m_calendar = java.util.Calendar.getInstance(Language.getLoginLanguage().getLocale());
// KTU
if (startTS == null)
m_calendar.setTimeInMillis(System.currentTimeMillis());
else
m_calendar.setTime(startTS);
// [ 1948445 ] Time field problem on daylight
if (m_displayType == DisplayType.Time)
m_calendar.set(1970, 1, 1);
m_firstDay = m_calendar.getFirstDayOfWeek();
//
Locale loc = Language.getLoginLanguage().getLocale();
SimpleDateFormat formatDate = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.LONG, loc);
// Short: h:mm a - HH:mm Long: h:mm:ss a z - HH:mm:ss z
SimpleDateFormat formatTime = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT, loc);
m_hasAM_PM = formatTime.toPattern().indexOf('a') != -1;
if (m_hasAM_PM)
cbPM.setText(formatTime.getDateFormatSymbols().getAmPmStrings()[1]);
else
cbPM.setVisible(false);
// Years
m_currentYear = m_calendar.get(java.util.Calendar.YEAR);
cYear.setEditor(new JSpinner.NumberEditor(cYear, "0000"));
cYear.setValue(new Integer(m_currentYear));
// Months -> 0=Jan 12=_
String[] months = formatDate.getDateFormatSymbols().getMonths();
for (int i = 0; i < months.length; i++) {
KeyNamePair p = new KeyNamePair(i + 1, months[i]);
if (!months[i].equals(""))
cMonth.addItem(p);
}
// Jan=0
m_currentMonth = m_calendar.get(java.util.Calendar.MONTH) + 1;
cMonth.setSelectedIndex(m_currentMonth - 1);
// Week Days -> 0=_ 1=Su .. 7=Sa
// 0 is blank, 1 is Sunday
String[] days = formatDate.getDateFormatSymbols().getShortWeekdays();
for (int i = m_firstDay; i < 7 + m_firstDay; i++) {
int index = i > 7 ? i - 7 : i;
dayPanel.add(createWeekday(days[index]), null);
}
// Days
m_days = new CButton[6 * 7];
m_currentDay = m_calendar.get(java.util.Calendar.DATE);
for (// six weeks a month maximum
int i = 0; // six weeks a month maximum
i < 6; // six weeks a month maximum
i++) for (// seven days
int j = 0; // seven days
j < 7; // seven days
j++) {
int index = i * 7 + j;
m_days[index] = createDay();
dayPanel.add(m_days[index], null);
}
// Today button
m_days[m_days.length - 1].setBackground(Color.green);
m_days[m_days.length - 1].setText("*");
m_days[m_days.length - 1].setToolTipText(Msg.getMsg(Env.getCtx(), "Today"));
// Cancel
m_days[m_days.length - 2].setBackground(Color.red);
m_days[m_days.length - 2].setText("x");
m_days[m_days.length - 2].setToolTipText(Msg.getMsg(Env.getCtx(), "Cancel"));
// Clear
m_days[m_days.length - 3].setBackground(Color.yellow);
m_days[m_days.length - 3].setText(Msg.getMsg(Env.getCtx(), "Key_Clear"));
m_days[m_days.length - 3].setToolTipText(Msg.getMsg(Env.getCtx(), "Clear"));
// Date/Time
m_current24Hour = m_calendar.get(java.util.Calendar.HOUR_OF_DAY);
m_currentMinute = m_calendar.get(java.util.Calendar.MINUTE);
// What to show
timePanel.setVisible(m_displayType == DisplayType.DateTime || m_displayType == DisplayType.Time);
monthPanel.setVisible(m_displayType != DisplayType.Time);
dayPanel.setVisible(m_displayType != DisplayType.Time);
// update UI from m_current...
m_setting = false;
setCalendar();
userTime = false;
}
use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class OrderReceiptIssue method executeQuery.
/**
* Query Info
*/
public void executeQuery(IMiniTable issue) {
final String sql = "SELECT " + // 1
"obl.PP_Order_BOMLine_ID," + // 2
"obl.IsCritical," + // 3
"p.Value," + // 4,5
"obl.M_Product_ID,p.Name," + // 6,7
"p.C_UOM_ID,u.Name," + // 8
"obl.QtyRequired," + // 9
"obl.QtyReserved," + // 10
"bomQtyAvailable(obl.M_Product_ID,obl.M_Warehouse_ID,0 ) AS QtyAvailable," + // 11
"bomQtyOnHand(obl.M_Product_ID,obl.M_Warehouse_ID,0) AS QtyOnHand," + // 12
"p.M_Locator_ID," + // 13,14
"obl.M_Warehouse_ID,w.Name," + // 15
"obl.QtyBom," + // 16
"obl.isQtyPercentage," + // 17
"obl.QtyBatch," + // 18
"obl.ComponentType," + // 19
"obl.QtyRequired - QtyDelivered AS QtyOpen," + // 20
"obl.QtyDelivered" + " FROM PP_Order_BOMLine obl" + " INNER JOIN M_Product p ON (obl.M_Product_ID = p.M_Product_ID) " + " INNER JOIN C_UOM u ON (p.C_UOM_ID = u.C_UOM_ID) " + " INNER JOIN M_Warehouse w ON (w.M_Warehouse_ID = obl.M_Warehouse_ID) " + " WHERE obl.PP_Order_ID = ?" + " ORDER BY obl." + MPPOrderBOMLine.COLUMNNAME_Line;
// reset table
int row = 0;
issue.setRowCount(row);
// Execute
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, getPP_Order_ID());
rs = pstmt.executeQuery();
while (rs.next()) {
// extend table
issue.setRowCount(row + 1);
// set values
// issue.
IDColumn id = new IDColumn(rs.getInt(1));
BigDecimal qtyBom = rs.getBigDecimal(15);
Boolean isQtyPercentage = rs.getString(16).equals("Y");
Boolean isCritical = rs.getString(2).equals("Y");
BigDecimal qtyBatch = rs.getBigDecimal(17);
BigDecimal qtyRequired = rs.getBigDecimal(8);
BigDecimal qtyOnHand = rs.getBigDecimal(11);
BigDecimal qtyOpen = rs.getBigDecimal(19);
BigDecimal qtyDelivered = rs.getBigDecimal(20);
String componentType = rs.getString(18);
BigDecimal toDeliverQty = getToDeliverQty();
BigDecimal openQty = getOpenQty();
BigDecimal scrapQty = getScrapQty();
BigDecimal componentToDeliverQty = Env.ZERO;
BigDecimal componentScrapQty = Env.ZERO;
BigDecimal componentQtyReq = Env.ZERO;
BigDecimal componentQtyToDel = Env.ZERO;
id.setSelected(isOnlyReceipt());
// PP_OrderBOMLine_ID
issue.setValueAt(id, row, 0);
// IsCritical
issue.setValueAt(isCritical, row, 1);
// Product's Search
issue.setValueAt(rs.getString(3), row, 2);
// key
// Product
issue.setValueAt(new KeyNamePair(rs.getInt(4), rs.getString(5)), row, 3);
// UOM
issue.setValueAt(new KeyNamePair(rs.getInt(6), rs.getString(7)), row, 4);
// ... 5 - ASI
// QtyRequired
issue.setValueAt(qtyRequired, row, 6);
// QtyDelivered
issue.setValueAt(qtyDelivered, row, 7);
// ... 8, 9, 10 - QtyToDeliver, QtyScrap, QtyOnHand
// OnHand
issue.setValueAt(qtyOnHand, row, 10);
// QtyReserved
issue.setValueAt(rs.getBigDecimal(9), row, 11);
// QtyAvailable
issue.setValueAt(rs.getBigDecimal(10), row, 12);
// ... 13 - M_Locator_ID
// Warehouse
issue.setValueAt(new KeyNamePair(rs.getInt(13), rs.getString(14)), row, 14);
// QtyBom
issue.setValueAt(qtyBom, row, 15);
// isQtyPercentage
issue.setValueAt(isQtyPercentage, row, 16);
// QtyBatch
issue.setValueAt(qtyBatch, row, 17);
if (componentType.equals(MPPProductBOMLine.COMPONENTTYPE_Component) || componentType.equals(MPPProductBOMLine.COMPONENTTYPE_Packing)) {
// If the there is product on hand and product is required
// the product should be selected
id.setSelected(qtyOnHand.signum() > 0 && qtyRequired.signum() > 0);
// PP_OrderBOMLine_ID
issue.setValueAt(id, row, 0);
if (isQtyPercentage) {
// If the quantity of product is calculated as a
// percentage
BigDecimal qtyBatchPerc = qtyBatch.divide(Env.ONEHUNDRED, 8, RoundingMode.HALF_UP);
if (isBackflush()) {
// Component from Qty To Deliver
if (qtyRequired.signum() == 0 || qtyOpen.signum() == 0) {
componentToDeliverQty = Env.ZERO;
} else {
componentToDeliverQty = toDeliverQty.multiply(qtyBatchPerc);
if (qtyRequired.subtract(qtyDelivered).signum() < 0 | componentToDeliverQty.signum() == 0)
componentToDeliverQty = qtyRequired.subtract(qtyDelivered);
}
if (componentToDeliverQty.signum() != 0) {
// TODO: arhipac: teo_sarca: is this a bug ?
// ...instead of toDeliverQty, qtyRequired
// should be used!
// componentQtyReq =
// toDeliverQty.multiply(qtyBatchPerc); // TODO:
// set scale 4
componentQtyToDel = componentToDeliverQty.setScale(4, BigDecimal.ROUND_HALF_UP);
// issue.setValueAt(toDeliverQty.multiply(qtyBatchPerc),
// row, 6); // QtyRequired
// QtyToDelivery
issue.setValueAt(componentToDeliverQty, row, 8);
}
} else {
// Only Issue - Calculate Component from Open
// Qty
componentToDeliverQty = qtyOpen;
if (componentToDeliverQty.signum() != 0) {
// scale 4
componentQtyReq = openQty.multiply(qtyBatchPerc);
componentQtyToDel = componentToDeliverQty.setScale(4, BigDecimal.ROUND_HALF_UP);
// QtyToDelivery
issue.setValueAt(componentToDeliverQty.setScale(8, BigDecimal.ROUND_HALF_UP), row, 8);
// QtyRequired
issue.setValueAt(openQty.multiply(qtyBatchPerc), row, 6);
}
}
if (scrapQty.signum() != 0) {
componentScrapQty = scrapQty.multiply(qtyBatchPerc);
if (componentScrapQty.signum() != 0) {
// QtyScrap
issue.setValueAt(componentScrapQty, row, 9);
}
} else
// QtyScrap
issue.setValueAt(componentScrapQty, row, 9);
} else {
// Absolute Qtys (not Percentage)
if (isBackflush()) {
// Component from Qty To Deliver
if (componentType.equals(MPPProductBOMLine.COMPONENTTYPE_Packing))
componentToDeliverQty = qtyRequired.subtract(qtyDelivered);
else
// TODO: set Number scale
componentToDeliverQty = toDeliverQty.multiply(qtyBom);
if (componentToDeliverQty.signum() != 0) {
if (componentType.equals(MPPProductBOMLine.COMPONENTTYPE_Packing))
componentQtyReq = qtyRequired.subtract(qtyDelivered);
else
componentQtyReq = toDeliverQty.multiply(qtyBom);
componentQtyToDel = componentToDeliverQty;
// QtyRequired
issue.setValueAt(componentQtyReq, row, 6);
// QtyToDelivery
issue.setValueAt(componentToDeliverQty, row, 8);
}
} else {
// Only Issue - Calculate Component from Open
// Qty
componentToDeliverQty = qtyOpen;
if (componentToDeliverQty.signum() != 0) {
if (componentType.equals(MPPProductBOMLine.COMPONENTTYPE_Packing))
componentQtyReq = qtyOpen;
else
componentQtyReq = openQty.multiply(qtyBom);
componentQtyToDel = componentToDeliverQty;
// QtyRequired
issue.setValueAt(componentQtyReq, row, 6);
// QtyToDelivery
issue.setValueAt(componentToDeliverQty, row, 8);
}
}
if (scrapQty.signum() != 0) {
// TODO:
componentScrapQty = scrapQty.multiply(qtyBom);
// scale
if (componentScrapQty.signum() != 0) {
// ScrapQty
issue.setValueAt(componentScrapQty, row, 9);
}
} else
// ScrapQty
issue.setValueAt(componentScrapQty, row, 9);
}
} else if (componentType.equals(MPPProductBOMLine.COMPONENTTYPE_Tools)) {
// TODO; set Number scale
componentToDeliverQty = qtyBom;
if (componentToDeliverQty.signum() != 0) {
componentQtyReq = qtyBom;
componentQtyToDel = componentToDeliverQty;
// QtyRequired
issue.setValueAt(qtyBom, row, 6);
// QtyToDelivery
issue.setValueAt(componentToDeliverQty, row, 8);
}
} else {
// QtyRequired
issue.setValueAt(Env.ZERO, row, 6);
//issue.setValueAt(Env.ZERO, row, 8); // QtyToDelivery
}
row++;
if (isOnlyIssue() || isBackflush()) {
int warehouse_id = rs.getInt(13);
int product_id = rs.getInt(4);
row += lotes(row, id, warehouse_id, product_id, componentQtyReq, componentQtyToDel, issue);
}
}
// while
} catch (SQLException e) {
throw new DBException(e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
issue.autoSize();
}
use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class VMRPDetailed method setMRP.
/**
* Fill header MRP information
*/
private void setMRP() {
int M_Product_ID = getM_Product_ID();
int M_AttributeSetInstance_ID = getM_AttributeSetInstance_ID();
int M_Warehouse_ID = getM_Warehouse_ID();
// Check Product (mandatory):
if (M_Product_ID <= 0)
return;
// Set Quantities
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
StringBuffer sql = new StringBuffer("SELECT ").append("BOMQtyOnHandASI(M_Product_ID,?,?,?) as qtyonhand, ").append("BOMQtyReservedASI(M_Product_ID,?,?,?) as qtyreserved, ").append("BOMQtyAvailableASI(M_Product_ID,?,?,?) as qtyavailable, ").append("BOMQtyOrderedASI(M_Product_ID,?,?,?) as qtyordered").append(" FROM M_Product WHERE M_Product_ID=?");
pstmt = DB.prepareStatement(sql.toString(), null);
DB.setParameters(pstmt, new Object[] { getM_AttributeSetInstance_ID(), getM_Warehouse_ID(), 0, getM_AttributeSetInstance_ID(), getM_Warehouse_ID(), 0, getM_AttributeSetInstance_ID(), getM_Warehouse_ID(), 0, getM_AttributeSetInstance_ID(), getM_Warehouse_ID(), 0, getM_Product_ID() });
rs = pstmt.executeQuery();
while (rs.next()) {
fOnhand.setValue(rs.getBigDecimal(1));
fReserved.setValue(rs.getBigDecimal(2));
fAvailable.setValue(rs.getBigDecimal(3));
fOrdered.setValue(rs.getBigDecimal(4));
}
} catch (SQLException ex) {
throw new DBException(ex);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
//
// Set UOM:
int uom_id = MProduct.get(getCtx(), M_Product_ID).getC_UOM_ID();
MUOM um = MUOM.get(getCtx(), uom_id);
KeyNamePair kum = new KeyNamePair(um.getC_UOM_ID(), um.get_Translation(MUOM.COLUMNNAME_Name));
fUOM.setText(kum.toString());
//
// Set Replenish Min Level:
BigDecimal replenishLevelMin = Env.ZERO;
if (getM_Warehouse_ID() > 0) {
String sql = "SELECT Level_Min FROM M_Replenish" + " WHERE AD_Client_ID=? AND M_Product_ID=? AND M_Warehouse_ID=?";
replenishLevelMin = DB.getSQLValueBD(null, sql, AD_Client_ID, M_Product_ID, M_Warehouse_ID);
}
fReplenishMin.setValue(replenishLevelMin);
}
use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class WAcctViewerData method fillOrg.
// fillTable
/**
* Fill Org
*
* @param cb Listbox to be filled
*/
protected void fillOrg(Listbox cb) {
KeyNamePair pp = new KeyNamePair(0, "");
cb.appendItem(pp.getName(), pp);
String sql = "SELECT AD_Org_ID, Name FROM AD_Org WHERE AD_Client_ID=? ORDER BY Value";
try {
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, AD_Client_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
KeyNamePair key = new KeyNamePair(rs.getInt(1), rs.getString(2));
cb.appendItem(key.getName(), key);
}
rs.close();
pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
}
}
Aggregations