Search in sources :

Example 26 with PO

use of org.compiere.model.PO in project adempiere by adempiere.

the class ScanBar method createLine.

public void createLine() {
    int lineNo = DB.getSQLValueEx(null, "SELECT Line FROM " + tableLine.getTableName() + " WHERE " + table.getTableName() + "_ID=?", getRecord_ID());
    if (lineNo <= 0)
        lineNo = 10;
    for (Vector<Object> line : getData().values()) {
        String value = (String) line.get(0);
        String lotNo = (String) line.get(2);
        String serNo = (String) line.get(3);
        Boolean isASI = (lotNo != null && lotNo.length() > 0) || (serNo != null && serNo.length() > 0) ? true : false;
        BigDecimal qty = (BigDecimal) line.get(4);
        int id = (Integer) line.get(5);
        Integer referenceId = (Integer) line.get(6);
        PO poLine = null;
        MAttributeSetInstance asi = null;
        MProduct product = new Query(Env.getCtx(), I_M_Product.Table_Name, "Value = ? ", null).setClient_ID().setParameters(value).firstOnly();
        String desc = null;
        poLine = tableLine.getPO(id, null);
        if (product.getM_AttributeSet_ID() > 0 && isASI) {
            if (poLine != null && poLine.get_ValueAsInt(I_M_AttributeSetInstance.COLUMNNAME_M_AttributeSetInstance_ID) > 0)
                asi = new MAttributeSetInstance(Env.getCtx(), poLine.get_ValueAsInt(I_M_AttributeSetInstance.COLUMNNAME_M_AttributeSetInstance_ID), null);
            else
                asi = getAttributeSetInstance(product, lotNo, serNo, getM_Locater_ID(), null);
        }
        poLine.set_ValueOfColumn(table.getKeyColumns()[0], getRecord_ID());
        poLine.set_ValueOfColumn(I_M_Product.COLUMNNAME_M_Product_ID, product.get_ID());
        poLine.set_ValueOfColumn(I_M_Product.COLUMNNAME_C_UOM_ID, product.getC_UOM_ID());
        poLine.set_ValueOfColumn(I_M_InOutLine.COLUMNNAME_Line, lineNo);
        poLine.set_ValueOfColumn(I_M_InOutLine.COLUMNNAME_IsActive, true);
        int locatorColumnId = poLine.get_ColumnIndex(I_M_InOutLine.COLUMNNAME_M_Locator_ID);
        if (locatorColumnId > 0 && getM_Locater_ID() > 0)
            poLine.set_ValueOfColumn(I_M_InOutLine.COLUMNNAME_M_Locator_ID, getM_Locater_ID());
        if (asi == null && isASI) {
            if (asi == null && isASI) {
                asi = new MAttributeSetInstance(Env.getCtx(), 0, product.getM_AttributeSet_ID(), null);
                if (lotNo != null) {
                    asi.setLot(lotNo);
                    desc = lotNo;
                }
                if (serNo != null) {
                    asi.setSerNo(serNo);
                    if (desc != null)
                        desc = desc + " - " + serNo;
                    else
                        desc = serNo;
                }
                asi.setDescription(desc);
                asi.saveEx();
            }
        }
        if (poLine instanceof MInventoryLine) {
            MStorage storage = MStorage.get(Env.getCtx(), getM_Locater_ID(), product.getM_Product_ID(), asi == null ? 0 : asi.getM_AttributeSetInstance_ID(), null);
            poLine.set_CustomColumn(I_M_InventoryLine.COLUMNNAME_QtyCount, qty);
            poLine.set_CustomColumn(I_M_InventoryLine.COLUMNNAME_QtyBook, storage == null ? Env.ZERO : storage.getQtyOnHand());
        } else if (poLine instanceof MInOutLine) {
            MInOutLine ioLine = (MInOutLine) poLine;
            ioLine.setQty(qty);
            ioLine.setC_OrderLine_ID(referenceId);
        } else if (poLine instanceof MMovementLine) {
            MMovementLine movementLine = (MMovementLine) poLine;
            movementLine.setM_LocatorTo_ID(getM_LocaterTo_ID());
            movementLine.setMovementQty(qty);
        } else
            poLine.set_ValueOfColumn(I_M_InOutLine.COLUMNNAME_MovementQty, qty);
        poLine.set_ValueOfColumn(MAttributeSetInstance.COLUMNNAME_M_AttributeSetInstance_ID, asi == null ? 0 : asi.get_ID());
        if (poLine.is_Changed())
            poLine.saveEx();
        lineNo = lineNo + 10;
    }
}
Also used : MProduct(org.compiere.model.MProduct) Query(org.compiere.model.Query) MInventoryLine(org.compiere.model.MInventoryLine) MInOutLine(org.compiere.model.MInOutLine) MAttributeSetInstance(org.compiere.model.MAttributeSetInstance) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal) MMovementLine(org.compiere.model.MMovementLine) PO(org.compiere.model.PO)

Example 27 with PO

use of org.compiere.model.PO in project adempiere by adempiere.

the class WListbox method loadTable.

/**
	 *	Load Table from Object Array.
	 *  @param pos array of Persistent Objects
	 */
public void loadTable(PO[] pos) {
    int row = 0;
    int col = 0;
    // index into the PO array
    int poIndex = 0;
    String columnName;
    Object data;
    Class columnClass;
    if (m_layout == null) {
        throw new UnsupportedOperationException("Layout not defined");
    }
    //  Clear Table
    clearTable();
    for (poIndex = 0; poIndex < pos.length; poIndex++) {
        PO myPO = pos[poIndex];
        row = getRowCount();
        setRowCount(row + 1);
        for (col = 0; col < m_layout.length; col++) {
            columnName = m_layout[col].getColSQL();
            data = myPO.get_Value(columnName);
            if (data != null) {
                columnClass = m_layout[col].getColClass();
                if (isColumnClassMismatch(col, columnClass)) {
                    throw new ApplicationException("Cannot enter a " + columnClass.getName() + " in column " + col + ". " + "An object of type " + m_modelHeaderClass.get(col).getSimpleName() + " was expected.");
                }
                if (columnClass == IDColumn.class) {
                    data = new IDColumn(((Integer) data).intValue());
                } else if (columnClass == Double.class) {
                    data = new Double(((BigDecimal) data).doubleValue());
                }
            }
            //  store
            getModel().setDataAt(data, row, col);
        }
    }
    autoSize();
    if (getShowTotals())
        addTotals(m_layout);
    // repaint the table
    this.repaint();
    logger.config("Row(array)=" + getRowCount());
    return;
}
Also used : IDColumn(org.compiere.minigrid.IDColumn) ApplicationException(org.adempiere.webui.exception.ApplicationException) PO(org.compiere.model.PO)

Example 28 with PO

use of org.compiere.model.PO in project adempiere by adempiere.

the class PrintPaperElementHandler method create.

public void create(Properties ctx, TransformerHandler document) throws SAXException {
    final int id = getExportItem_ID(ctx);
    if (list.contains(id))
        return;
    list.add(id);
    final PO po = getCreatePO(ctx, id, null);
    final AttributesImpl atts = new AttributesImpl();
    createMessageBinding(atts, po);
    document.startElement("", "", getTagName(), atts);
    document.endElement("", "", getTagName());
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) PO(org.compiere.model.PO)

Example 29 with PO

use of org.compiere.model.PO in project adempiere by adempiere.

the class PrintPaperElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    final String elementValue = element.getElementValue();
    final Attributes atts = element.attributes;
    final String strIdentifier = atts.getValue(getIdentifierColumnName());
    final int id = get_IDWithColumn(ctx, getTableName(), getIdentifierColumnName(), strIdentifier);
    final PO po = getCreatePO(ctx, id, getTrxName(ctx));
    final String keyColumnName = getKeyColumnName();
    log.info(elementValue + " " + strIdentifier + "[" + id + "]");
    if (id <= 0 && keyColumnName != null && getIntValue(atts, keyColumnName, 0) <= PackOut.MAX_OFFICIAL_ID) {
        po.set_ValueOfColumn(keyColumnName, getIntValue(atts, keyColumnName, 0));
    }
    final int AD_Backup_ID;
    final String Object_Status;
    if (id > 0) {
        AD_Backup_ID = copyRecord(ctx, getTableName(), po);
        Object_Status = "Update";
    } else {
        Object_Status = "New";
        AD_Backup_ID = 0;
    }
    for (String attributeName : getAttributeNames()) {
        loadAttribute(atts, attributeName, po);
    }
    if (po.save(getTrxName(ctx)) == true) {
        record_log(ctx, 1, strIdentifier, getTagName(), po.get_ID(), AD_Backup_ID, Object_Status, getTableName(), getTable_ID());
    } else {
        record_log(ctx, 0, strIdentifier, getTagName(), po.get_ID(), AD_Backup_ID, Object_Status, getTableName(), getTable_ID());
        throw new POSaveFailedException("Failed to save message.");
    }
}
Also used : Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) PO(org.compiere.model.PO)

Example 30 with PO

use of org.compiere.model.PO in project adempiere by adempiere.

the class MiniTable method loadTable.

//	loadTable
/**
	 *	Load Table from Object Array
	 *  @param pos array of POs 
	 */
public void loadTable(PO[] pos) {
    if (m_layout == null)
        throw new UnsupportedOperationException("Layout not defined");
    //  Clear Table
    setRowCount(0);
    //
    for (int i = 0; i < pos.length; i++) {
        PO myPO = pos[i];
        int row = getRowCount();
        setRowCount(row + 1);
        for (int col = 0; col < m_layout.length; col++) {
            String columnName = m_layout[col].getColSQL();
            Object data = myPO.get_Value(columnName);
            if (data != null) {
                Class<?> c = m_layout[col].getColClass();
                if (c == IDColumn.class)
                    data = new IDColumn(((Integer) data).intValue());
                else if (c == Double.class)
                    data = new Double(((BigDecimal) data).doubleValue());
            }
            //  store
            setValueAt(data, row, col);
        }
    }
    if (getShowTotals())
        addTotals(m_layout);
    autoSize();
    log.config("Row(array)=" + getRowCount());
}
Also used : BigDecimal(java.math.BigDecimal) PO(org.compiere.model.PO)

Aggregations

PO (org.compiere.model.PO)75 MTable (org.compiere.model.MTable)18 AdempiereException (org.adempiere.exceptions.AdempiereException)17 SQLException (java.sql.SQLException)16 Properties (java.util.Properties)13 BigDecimal (java.math.BigDecimal)11 Query (org.compiere.model.Query)8 Element (org.w3c.dom.Element)7 ArrayList (java.util.ArrayList)6 MEXPFormat (org.compiere.model.MEXPFormat)6 ADLoginRequest (pl.x3E.adInterface.ADLoginRequest)6 POInfo (org.compiere.model.POInfo)5 Trx (org.compiere.util.Trx)5 ModelCRUD (pl.x3E.adInterface.ModelCRUD)5 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 XFireFault (org.codehaus.xfire.fault.XFireFault)4 DataField (pl.x3E.adInterface.DataField)4 DataRow (pl.x3E.adInterface.DataRow)4 ParseException (java.text.ParseException)3