Search in sources :

Example 6 with MTable

use of org.compiere.model.MTable 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());
    }
}
Also used : MTable(org.compiere.model.MTable) PO(org.compiere.model.PO)

Example 7 with MTable

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

the class WDelete method generateTree.

// ValueChange
private void generateTree(Object value, Integer clientID) {
    if (value == null)
        return;
    Integer selectedTableID = ((Integer) value).intValue();
    if (selectedTableID == 0 || clientId == null) {
        FDialog.error(form.getWindowNo(), "ParameterError", "Table or Client cannot be Null.");
        return;
    }
    MTable table = MTable.get(Env.getCtx(), selectedTableID);
    DeleteEntitiesModel data = new DeleteEntitiesModel();
    data.mandatoryLink = true;
    data.tableName = table.getTableName();
    data.joinColumn = table.getKeyColumns()[0];
    data.whereClause = " " + data.tableName + ".AD_Client_ID = " + clientId;
    if (table.getTableName().equals("AD_User")) {
        data.whereClause = data.whereClause + " AND NOT EXISTS (SELECT * FROM C_BPartner bp " + "WHERE AD_User.Link_BPartner_ID=bp.C_BPartner_ID " + "AND (bp.IsEmployee='Y' OR bp.IsSalesRep='Y'))";
    }
    tree.clear();
    if ((tree.getChildren()).size() > 1) {
        @SuppressWarnings("rawtypes") List treePreviousChild = tree.getChildren();
        tree.removeChild((Treechildren) treePreviousChild.get(1));
    }
    Treechildren rootTreeChild = new Treechildren();
    Treeitem rootTreeItem = new Treeitem();
    rootTreeItem.setValue(data);
    rootTreeItem.setLabel(data.tableName + "." + data.joinColumn);
    Treechildren rootTreeItemChild = new Treechildren();
    createNodes(data, rootTreeItemChild);
    rootTreeItem.appendChild(rootTreeItemChild);
    rootTreeChild.appendChild(rootTreeItem);
    tree.appendChild(rootTreeChild);
}
Also used : Treeitem(org.zkoss.zul.Treeitem) MTable(org.compiere.model.MTable) DeleteEntitiesModel(org.adempiere.util.DeleteEntitiesModel) Treechildren(org.zkoss.zul.Treechildren) List(java.util.List) ArrayList(java.util.ArrayList)

Example 8 with MTable

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

the class WGenForm method onPrint.

public void onPrint() {
    //		Loop through all items
    List<File> pdfList = new ArrayList<File>();
    for (int i = 0; i < m_ids.length; i++) {
        int RecordID = m_ids[i];
        ReportEngine re = null;
        if (genForm.getPrintFormat() != null) {
            MPrintFormat format = genForm.getPrintFormat();
            MTable table = MTable.get(Env.getCtx(), format.getAD_Table_ID());
            MQuery query = new MQuery(table.getTableName());
            query.addRestriction(table.getTableName() + "_ID", MQuery.EQUAL, RecordID);
            //	Engine
            PrintInfo info = new PrintInfo(table.getTableName(), table.get_Table_ID(), RecordID);
            re = new ReportEngine(Env.getCtx(), format, query, info);
        } else {
            re = ReportEngine.get(Env.getCtx(), genForm.getReportEngineType(), RecordID);
        }
        if (re != null)
            pdfList.add(re.getPDF());
    }
    if (pdfList.size() > 1) {
        try {
            File outFile = File.createTempFile(genForm.getClass().getName(), ".pdf");
            AEnv.mergePdf(pdfList, outFile);
            Clients.clearBusy();
            Window win = new SimplePDFViewer(getFormName(), new FileInputStream(outFile));
            SessionManager.getAppDesktop().showWindow(win, "center");
        } catch (Exception e) {
            log.log(Level.SEVERE, e.getLocalizedMessage(), e);
        }
    } else if (pdfList.size() > 0) {
        Clients.clearBusy();
        try {
            Window win = new SimplePDFViewer(getFormName(), new FileInputStream(pdfList.get(0)));
            SessionManager.getAppDesktop().showWindow(win, "center");
        } catch (Exception e) {
            log.log(Level.SEVERE, e.getLocalizedMessage(), e);
        }
    }
}
Also used : Window(org.adempiere.webui.component.Window) SimplePDFViewer(org.adempiere.webui.window.SimplePDFViewer) ArrayList(java.util.ArrayList) MQuery(org.compiere.model.MQuery) PrintInfo(org.compiere.model.PrintInfo) FileInputStream(java.io.FileInputStream) ReportEngine(org.compiere.print.ReportEngine) MPrintFormat(org.compiere.print.MPrintFormat) MTable(org.compiere.model.MTable) File(java.io.File)

Example 9 with MTable

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

the class ExportHelper method generateExportFormat.

/**
	 * Trifon Generate Export Format process; result =
	 * <C_Invoice>
	 *   <DocumentNo>101</DocumentNo>
	 * </C_Invoice>
	 * @param rootElement
	 * @param exportFormat
	 * @param masterPO
	 * @param masterID
	 * @param variableMap
	 * @throws SQLException
     * @throws Exception
     */
private void generateExportFormat(Element rootElement, MEXPFormat exportFormat, PO masterPO, int masterID, HashMap<String, Integer> variableMap) throws SQLException, Exception {
    Collection<MEXPFormatLine> formatLines = exportFormat.getFormatLines();
    @SuppressWarnings("unused") boolean elementHasValue = false;
    //for (int i = 0; i < formatLines.length; i++) {
    for (MEXPFormatLine formatLine : formatLines) {
        if (formatLine.getType().equals(X_EXP_FormatLine.TYPE_XMLElement)) {
            // process single XML Attribute
            // Create new element
            Element newElement = outDocument.createElement(formatLine.getValue());
            log.info("Format Line Seach key: " + formatLine.getValue());
            if (formatLine.getAD_Column_ID() == 0) {
                throw new Exception(Msg.getMsg(masterPO.getCtx(), "EXPColumnMandatory"));
            }
            MColumn column = MColumn.get(masterPO.getCtx(), formatLine.getAD_Column_ID());
            if (column == null) {
                throw new Exception(Msg.getMsg(masterPO.getCtx(), "EXPColumnMandatory"));
            }
            if (column.isVirtualColumn()) {
                log.info("This is Virtual Column!");
            } else {
            }
            //log.info("["+column.getColumnName()+"]");
            Object value = masterPO.get_Value(column.getColumnName());
            String valueString = null;
            if (value != null) {
                valueString = value.toString();
            } else {
                //  Could remove this exception and create empty XML Element when column do not have value. 
                if (formatLine.isMandatory()) {
                //throw new Exception(Msg.getMsg (masterPO.getCtx(), "EXPFieldMandatory"));
                }
            }
            if (column.getAD_Reference_ID() == DisplayType.Date) {
                if (valueString != null) {
                    if (formatLine.getDateFormat() != null && !"".equals(formatLine.getDateFormat())) {
                        // "MM/dd/yyyy"
                        customDateFormat = new SimpleDateFormat(formatLine.getDateFormat());
                        valueString = customDateFormat.format(Timestamp.valueOf(valueString));
                        // Add "DateForamt attribute"
                        newElement.setAttribute("DateFormat", customDateFormat.toPattern());
                    } else {
                        newElement.setAttribute("DateFormat", valueString);
                    }
                }
            } else if (column.getAD_Reference_ID() == DisplayType.DateTime) {
                if (valueString != null) {
                    if (formatLine.getDateFormat() != null && !"".equals(formatLine.getDateFormat())) {
                        // "MM/dd/yyyy"
                        customDateFormat = new SimpleDateFormat(formatLine.getDateFormat());
                        valueString = customDateFormat.format(Timestamp.valueOf(valueString));
                        // Add "DateForamt attribute"
                        newElement.setAttribute("DateFormat", customDateFormat.toPattern());
                    } else {
                        newElement.setAttribute("DateFormat", valueString);
                    }
                }
            }
            log.info("EXP Field - column=[" + column.getColumnName() + "]; value=" + value);
            if (valueString != null && !"".equals(valueString) && !"null".equals(valueString)) {
                Text newText = outDocument.createTextNode(valueString);
                newElement.appendChild(newText);
                rootElement.appendChild(newElement);
                elementHasValue = true;
            } else {
                // Empty field.
                if (formatLine.isMandatory()) {
                    Text newText = outDocument.createTextNode("");
                    newElement.appendChild(newText);
                    rootElement.appendChild(newElement);
                    elementHasValue = true;
                }
            }
        } else if (formatLine.getType().equals(X_EXP_FormatLine.TYPE_XMLAttribute)) {
            // process single XML Attribute
            if (formatLine.getAD_Column_ID() == 0) {
                throw new Exception(Msg.getMsg(masterPO.getCtx(), "EXPColumnMandatory"));
            }
            MColumn column = MColumn.get(masterPO.getCtx(), formatLine.getAD_Column_ID());
            if (column == null) {
                throw new Exception(Msg.getMsg(masterPO.getCtx(), "EXPColumnMandatory"));
            }
            if (column.isVirtualColumn()) {
                log.info("This is Virtual Column!");
            } else {
            }
            //log.info("["+column.getColumnName()+"]");
            Object value = masterPO.get_Value(column.getColumnName());
            String valueString = null;
            if (value != null) {
                valueString = value.toString();
            } else {
                if (formatLine.isMandatory()) {
                    throw new Exception(Msg.getMsg(masterPO.getCtx(), "EXPFieldMandatory"));
                }
            }
            /*				if (column.getAD_Reference_ID() == DisplayType.Date) {
					if (valueString != null) {
						if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) {
							m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy"
							//Date date = m_customDateFormat.parse ( valueString );
							valueString = m_customDateFormat.format(Timestamp.valueOf (valueString));
						} else {
							valueString = m_dateFormat.format (Timestamp.valueOf (valueString));
						}
								
					}
				} else if (column.getAD_Reference_ID() == DisplayType.DateTime) {
					if (valueString != null) {
						if (formatLines[i].getDateFormat() != null && !"".equals(formatLines[i].getDateFormat())) {
							m_customDateFormat = new SimpleDateFormat( formatLines[i].getDateFormat() ); // "MM/dd/yyyy"
							//Date date = m_customDateFormat.parse ( valueString );
							valueString = m_customDateFormat.format(Timestamp.valueOf (valueString));
						} else {
							valueString = m_dateTimeFormat.format (Timestamp.valueOf (valueString));
						}
					}
				}*/
            log.info("EXP Field - column=[" + column.getColumnName() + "]; value=" + value);
            if (valueString != null && !"".equals(valueString) && !"null".equals(valueString)) {
                rootElement.setAttribute(formatLine.getValue(), valueString);
                elementHasValue = true;
            } else {
            // Empty field.
            }
        } else if (formatLine.getType().equals(X_EXP_FormatLine.TYPE_EmbeddedEXPFormat)) {
            // process Embedded Export Format
            int embeddedFormat_ID = formatLine.getEXP_EmbeddedFormat_ID();
            //get from cache
            MEXPFormat embeddedFormat = MEXPFormat.get(masterPO.getCtx(), embeddedFormat_ID, masterPO.get_TrxName());
            MTable tableEmbedded = MTable.get(masterPO.getCtx(), embeddedFormat.getAD_Table_ID());
            log.info("Table Embedded = " + tableEmbedded);
            final StringBuffer whereClause = new StringBuffer(masterPO.get_KeyColumns()[0] + "=?");
            if (embeddedFormat.getWhereClause() != null & !"".equals(embeddedFormat.getWhereClause())) {
                whereClause.append(" AND ").append(embeddedFormat.getWhereClause());
            }
            Collection<PO> instances = new Query(masterPO.getCtx(), tableEmbedded.getTableName(), whereClause.toString(), masterPO.get_TrxName()).setClient_ID().setParameters(new Object[] { masterID }).list();
            for (PO instance : instances) {
                Element embeddedElement = outDocument.createElement(formatLine.getValue());
                if (formatLine.getDescription() != null && !"".equals(formatLine.getDescription())) {
                    embeddedElement.appendChild(outDocument.createComment(formatLine.getDescription()));
                }
                generateExportFormat(embeddedElement, embeddedFormat, instance, instance.get_ID(), variableMap);
                rootElement.appendChild(embeddedElement);
            }
        } else if (formatLine.getType().equals(X_EXP_FormatLine.TYPE_ReferencedEXPFormat)) {
            // process Referenced Export Format
            int embeddedFormat_ID = formatLine.getEXP_EmbeddedFormat_ID();
            //get from cache
            MEXPFormat embeddedFormat = MEXPFormat.get(masterPO.getCtx(), embeddedFormat_ID, masterPO.get_TrxName());
            MTable tableEmbedded = MTable.get(masterPO.getCtx(), embeddedFormat.getAD_Table_ID());
            log.info("Table Embedded = " + tableEmbedded);
            final StringBuffer whereClause = new StringBuffer(tableEmbedded.getTableName() + "_ID =?");
            if (embeddedFormat.getWhereClause() != null & !"".equals(embeddedFormat.getWhereClause())) {
                whereClause.append(" AND ").append(embeddedFormat.getWhereClause());
            }
            String columnName = "";
            if (formatLine.getAD_Reference_ID() == DisplayType.Table | formatLine.getAD_Reference_ID() == DisplayType.Search) {
                MColumn column = MColumn.get(masterPO.getCtx(), formatLine.getAD_Column_ID());
                columnName = column.getColumnName();
            } else {
                columnName = tableEmbedded.getTableName() + "_ID";
            }
            Object value = masterPO.get_Value(columnName);
            if (value == null) {
                continue;
            }
            Collection<PO> instances = new Query(masterPO.getCtx(), tableEmbedded.getTableName(), whereClause.toString(), masterPO.get_TrxName()).setClient_ID().setParameters(value).list();
            for (PO instance : instances) {
                Element embeddedElement = outDocument.createElement(formatLine.getValue());
                if (formatLine.getDescription() != null && !"".equals(formatLine.getDescription())) {
                    embeddedElement.appendChild(outDocument.createComment(formatLine.getDescription()));
                }
                generateExportFormat(embeddedElement, embeddedFormat, instance, instance.get_ID(), variableMap);
                rootElement.appendChild(embeddedElement);
            }
        } else {
            throw new Exception(Msg.getMsg(masterPO.getCtx(), "EXPUnknownLineType"));
        }
    }
}
Also used : MColumn(org.compiere.model.MColumn) MEXPFormat(org.compiere.model.MEXPFormat) Query(org.compiere.model.Query) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) SQLException(java.sql.SQLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) MEXPFormatLine(org.compiere.model.MEXPFormatLine) MTable(org.compiere.model.MTable) Collection(java.util.Collection) SimpleDateFormat(java.text.SimpleDateFormat) PO(org.compiere.model.PO)

Example 10 with MTable

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

the class ExportHelper method exportRecord.

/**
	 * 	 * 	Process - Generate Export Format
	 * @param exportFormat
	 * @param where
	 * @param replicationMode
	 * @param replicationType
	 * @param replicationEvent
	 * @return
     * @throws Exception
     */
public Document exportRecord(MEXPFormat exportFormat, String where, Integer replicationMode, String replicationType, Integer replicationEvent) throws Exception {
    MClient client = MClient.get(exportFormat.getCtx(), clientId);
    MTable table = MTable.get(exportFormat.getCtx(), exportFormat.getAD_Table_ID());
    log.info("Table = " + table);
    Collection<PO> records = new Query(exportFormat.getCtx(), table.getTableName(), exportFormat.getWhereClause(), exportFormat.get_TrxName()).setOnlyActiveRecords(true).list();
    for (PO po : records) {
        log.info("Client = " + client.toString());
        log.finest("po.getAD_Org_ID() = " + po.getAD_Org_ID());
        log.finest("po.get_TrxName() = " + po.get_TrxName());
        if (po.get_TrxName() == null || po.get_TrxName().equals("")) {
            po.set_TrxName("exportRecord");
        }
        if (po.get_KeyColumns().length < 1) {
            //TODO: Create Mesagge.
            throw new Exception(Msg.getMsg(po.getCtx(), "ExportNoneColumnKeyNotSupported"));
        }
        outDocument = createNewDocument();
        HashMap<String, Integer> variableMap = new HashMap<String, Integer>();
        Element rootElement = outDocument.createElement(exportFormat.getValue());
        if (exportFormat.getDescription() != null && !"".equals(exportFormat.getDescription())) {
            rootElement.appendChild(outDocument.createComment(exportFormat.getDescription()));
        }
        rootElement.setAttribute("AD_Client_Value", client.getValue());
        rootElement.setAttribute("Version", exportFormat.getVersion());
        rootElement.setAttribute("ReplicationMode", replicationMode.toString());
        rootElement.setAttribute("ReplicationType", replicationType);
        rootElement.setAttribute("ReplicationEvent", replicationEvent.toString());
        outDocument.appendChild(rootElement);
        generateExportFormat(rootElement, exportFormat, po, po.get_ID(), variableMap);
    }
    // finish record read
    return outDocument;
}
Also used : MTable(org.compiere.model.MTable) Query(org.compiere.model.Query) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) SQLException(java.sql.SQLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) MClient(org.compiere.model.MClient) PO(org.compiere.model.PO)

Aggregations

MTable (org.compiere.model.MTable)67 PO (org.compiere.model.PO)18 ResultSet (java.sql.ResultSet)16 SQLException (java.sql.SQLException)16 PreparedStatement (java.sql.PreparedStatement)15 MColumn (org.compiere.model.MColumn)15 Query (org.compiere.model.Query)13 ArrayList (java.util.ArrayList)10 Properties (java.util.Properties)9 AdempiereException (org.adempiere.exceptions.AdempiereException)7 ADLoginRequest (pl.x3E.adInterface.ADLoginRequest)7 XFireFault (org.codehaus.xfire.fault.XFireFault)5 POInfo (org.compiere.model.POInfo)5 Trx (org.compiere.util.Trx)5 DataField (pl.x3E.adInterface.DataField)5 DataRow (pl.x3E.adInterface.DataRow)5 ModelCRUD (pl.x3E.adInterface.ModelCRUD)5 List (java.util.List)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)4