Search in sources :

Example 6 with PO

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

the class ImportHelper method importXMLDocument.

/**
	 * Import XML Document
	 * @param result
	 * @param documentToBeImported
	 * @param trxName
	 * @throws Exception
	 * @throws SQLException
	 * @throws XPathExpressionException
	 */
public void importXMLDocument(StringBuffer result, Document documentToBeImported, String trxName) throws Exception, SQLException, XPathExpressionException {
    Element rootElement = documentToBeImported.getDocumentElement();
    // Find which Export format to Load...
    String AD_Client_Value = null;
    AD_Client_Value = rootElement.getAttribute("AD_Client_Value");
    log.info("AD_Client_Value = " + AD_Client_Value);
    if (AD_Client_Value == null || Util.isEmpty(AD_Client_Value)) {
        throw new Exception(Msg.getMsg(ctx, "XMLClientValueMandatory"));
    }
    String version = null;
    version = rootElement.getAttribute("Version");
    log.info("Version = " + version);
    if (version == null || Util.isEmpty(version)) {
        throw new Exception(Msg.getMsg(ctx, "XMLVersionAttributeMandatory"));
    }
    ///Getting Attributes.
    int ReplicationMode = new Integer(rootElement.getAttribute("ReplicationMode"));
    String ReplicationType = rootElement.getAttribute("ReplicationType");
    int ReplicationEvent = new Integer(rootElement.getAttribute("ReplicationEvent"));
    MClient client = null;
    client = getAD_ClientByValue(ctx, AD_Client_Value, trxName);
    if (client == null) {
        throw new Exception(Msg.getMsg(ctx, "XMLClientNotFound"));
    }
    log.info("XML ROOT AD_Client = " + client.toString());
    String EXP_Format_Value = null;
    EXP_Format_Value = rootElement.getNodeName();
    log.info("EXP_Format_Value = " + EXP_Format_Value);
    MEXPFormat expFormat = null;
    expFormat = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(ctx, EXP_Format_Value, client.getAD_Client_ID(), version, trxName);
    if (expFormat == null || expFormat.getEXP_Format_ID() == 0) {
        // Fall back to SYSTEM Client.
        // Try to search Export format defined for SYSTEM Client!!!
        MClient systemClient = null;
        systemClient = MClient.get(ctx, 0);
        if (systemClient == null) {
            throw new Exception(Msg.getMsg(ctx, "XMLClientNotFound"));
        }
        log.info("SYSTEM Client = " + systemClient.toString());
        expFormat = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(ctx, EXP_Format_Value, systemClient.getAD_Client_ID(), version, trxName);
    }
    if (expFormat == null || expFormat.getEXP_Format_ID() == 0) {
        throw new Exception(Msg.getMsg(ctx, "EXPFormatNotFound"));
    }
    log.info("expFormat = " + expFormat.toString());
    isChanged = false;
    PO po = importElement(ctx, result, rootElement, expFormat, ReplicationType, trxName);
    if (ModelValidator.TYPE_BEFORE_DELETE == ReplicationEvent || ModelValidator.TYPE_BEFORE_DELETE_REPLICATION == ReplicationEvent || ModelValidator.TYPE_DELETE == ReplicationEvent)
        ;
    else if (!po.is_Changed() && !isChanged) {
        log.info("Object not changed = " + po.toString());
        return;
    }
    if (po != null) {
        Env.setContext(po.getCtx(), "#AD_Client_ID", po.getAD_Client_ID());
        if (MReplicationStrategy.REPLICATION_TABLE == ReplicationMode) {
            // Here must invoke other method else we get cycle...
            if (ModelValidator.TYPE_BEFORE_DELETE == ReplicationEvent || ModelValidator.TYPE_BEFORE_DELETE_REPLICATION == ReplicationEvent || ModelValidator.TYPE_DELETE == ReplicationEvent) {
                po.deleteEx(true);
            } else {
                if (X_AD_ReplicationTable.REPLICATIONTYPE_Broadcast.equals(ReplicationType)) {
                    MReplicationStrategy rplStrategy = new MReplicationStrategy(client.getCtx(), client.getAD_ReplicationStrategy_ID(), po.get_TrxName());
                    ExportHelper expHelper = new ExportHelper(client, rplStrategy);
                    expHelper.exportRecord(po, MReplicationStrategy.REPLICATION_TABLE, X_AD_ReplicationTable.REPLICATIONTYPE_Merge, ModelValidator.TYPE_AFTER_CHANGE);
                    po.saveReplica(true);
                } else if (X_AD_ReplicationTable.REPLICATIONTYPE_Merge.equals(ReplicationType) || X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(ReplicationType)) {
                    po.saveReplica(true);
                } else /*else if (X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(ReplicationType))
					{
						//Do nothing??	
					}*/
                if (X_AD_ReplicationTable.REPLICATIONTYPE_Local.equals(ReplicationType)) {
                //Do nothing??	
                } else {
                    // Replication Type is not one of the possible values...ERROR
                    throw new Exception(Msg.getMsg(ctx, "EXPReplicationTypeNonValidType"));
                }
            }
        } else if (MReplicationStrategy.REPLICATION_DOCUMENT == ReplicationMode && X_AD_ReplicationDocument.REPLICATIONTYPE_Merge.equals(ReplicationType) && po instanceof DocAction) {
            DocAction document = (DocAction) po;
            String action = document.getDocAction();
            String status = document.getDocStatus();
            log.info("Document:" + document.toString() + " DocStauts:" + status + " DocAction:" + action);
            if (ModelValidator.TIMING_AFTER_REVERSECORRECT == ReplicationEvent) {
                if (status.equals(DocAction.STATUS_Reversed) && action.equals(DocAction.ACTION_None)) {
                    po.saveEx();
                    return;
                }
            }
            if ((action.equals(DocAction.ACTION_Complete) && status.equals(DocAction.STATUS_InProgress)) || (action.equals(DocAction.ACTION_Close) && status.equals(DocAction.STATUS_Completed))) {
                if (!document.processIt(action)) {
                    log.info("PO.toString() = can not " + po.get_Value("DocAction"));
                }
                po.saveEx();
            } else {
                po.saveEx();
                return;
            }
        }
    }
    result.append("Save Successful ;");
}
Also used : MEXPFormat(org.compiere.model.MEXPFormat) DocAction(org.compiere.process.DocAction) Element(org.w3c.dom.Element) ExportHelper(org.adempiere.process.rpl.exp.ExportHelper) MReplicationStrategy(org.compiere.model.MReplicationStrategy) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SQLException(java.sql.SQLException) ParseException(java.text.ParseException) AdempiereException(org.adempiere.exceptions.AdempiereException) MClient(org.compiere.model.MClient) PO(org.compiere.model.PO)

Example 7 with PO

use of org.compiere.model.PO 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 8 with PO

use of org.compiere.model.PO 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)

Example 9 with PO

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

the class DocumentEngine method processIt.

//	process
/**
	 * 	Process actual document - do not call directly.
	 * 	Calls the individual actions which call the document action
	 *	@param action document action
	 *	@return true if performed
	 */
public boolean processIt(String action) {
    m_message = null;
    m_action = action;
    //
    if (ACTION_Unlock.equals(m_action))
        return unlockIt();
    if (ACTION_Invalidate.equals(m_action))
        return invalidateIt();
    if (ACTION_Prepare.equals(m_action))
        return STATUS_InProgress.equals(prepareIt());
    if (ACTION_Approve.equals(m_action))
        return approveIt();
    if (ACTION_Reject.equals(m_action))
        return rejectIt();
    if (ACTION_Complete.equals(m_action) || ACTION_WaitComplete.equals(m_action)) {
        String status = null;
        if (//	prepare if not prepared yet
        isDrafted() || isInvalid()) {
            status = prepareIt();
            if (!STATUS_InProgress.equals(status))
                return false;
        }
        status = completeIt();
        boolean ok = STATUS_Completed.equals(status) || STATUS_InProgress.equals(status) || STATUS_WaitingPayment.equals(status) || STATUS_WaitingConfirmation.equals(status);
        if (m_document != null && ok) {
            // PostProcess documents when invoice or inout (this is to postprocess the generated MatchPO and MatchInv if any)
            ArrayList<PO> docsPostProcess = new ArrayList<PO>();
            if (m_document instanceof MInvoice || m_document instanceof MInOut) {
                if (m_document instanceof MInvoice) {
                    docsPostProcess = ((MInvoice) m_document).getDocsPostProcess();
                }
                if (m_document instanceof MInOut) {
                    docsPostProcess = ((MInOut) m_document).getDocsPostProcess();
                }
            }
            if (m_document instanceof PO && docsPostProcess.size() > 0) {
                // Process (this is to update the ProcessedOn flag with a timestamp after the original document)
                for (PO docafter : docsPostProcess) {
                    docafter.setProcessedOn("Processed", true, false);
                    docafter.saveEx();
                }
            }
            if (STATUS_Completed.equals(status) && MClient.isClientAccountingImmediate()) {
                m_document.saveEx();
                postIt();
                if (m_document instanceof PO && docsPostProcess.size() > 0) {
                    for (PO docafter : docsPostProcess) {
                        @SuppressWarnings("unused") String ignoreError = DocumentEngine.postImmediate(docafter.getCtx(), docafter.getAD_Client_ID(), docafter.get_Table_ID(), docafter.get_ID(), true, docafter.get_TrxName());
                    }
                }
            }
        }
        return ok;
    }
    if (ACTION_ReActivate.equals(m_action))
        return reActivateIt();
    if (ACTION_Reverse_Accrual.equals(m_action))
        return reverseAccrualIt();
    if (ACTION_Reverse_Correct.equals(m_action))
        return reverseCorrectIt();
    if (ACTION_Close.equals(m_action))
        return closeIt();
    if (ACTION_Void.equals(m_action))
        return voidIt();
    if (ACTION_Post.equals(m_action))
        return postIt();
    //
    return false;
}
Also used : MInOut(org.compiere.model.MInOut) ArrayList(java.util.ArrayList) MInvoice(org.compiere.model.MInvoice) PO(org.compiere.model.PO)

Example 10 with PO

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

the class VDocAction method dynInit.

//	jbInit
/**
	 *	Dynamic Init - determine valid DocActions based on DocStatus for the different documents.
	 *  <pre>
	 *  DocStatus (131)
			??                         Unknown
			AP *                       Approved
			CH                         Changed
			CL *                       Closed
			CO *                       Completed
			DR                         Drafted
			IN                         Inactive
			NA                         Not Approved
			PE                         Posting Error
			PO *                       Posted
			PR *                       Printed
			RE                         Reversed
			TE                         Transfer Error
			TR *                       Transferred
			VO *                       Voided
			XX                         Being Processed
	 *
	 *   DocAction (135)
			--                         <None>
			AP *                       Approve
			CL *                       Close
			CO *                       Complete
			PO *                       Post
			PR *                       Print
			RA                         Reverse - Accrual
			RC                         Reverse - Correction
			RE                         RE-activate
			RJ                         Reject
			TR *                       Transfer
			VO *                       Void
			XL                         Unlock
	 *  </pre>
	 * 	@param Record_ID id
	 */
private void dynInit(int Record_ID) {
    String DocStatus = (String) m_mTab.getValue("DocStatus");
    String DocAction = (String) m_mTab.getValue("DocAction");
    //
    Object Processing = m_mTab.getValue("Processing");
    String OrderType = Env.getContext(Env.getCtx(), m_WindowNo, "OrderType");
    String IsSOTrx = Env.getContext(Env.getCtx(), m_WindowNo, "IsSOTrx");
    if (DocStatus == null) {
        message.setText("*** ERROR ***");
        return;
    }
    log.fine("DocStatus=" + DocStatus + ", DocAction=" + DocAction + ", OrderType=" + OrderType + ", IsSOTrx=" + IsSOTrx + ", Processing=" + Processing + ", AD_Table_ID=" + m_AD_Table_ID + ", Record_ID=" + Record_ID);
    //
    String[] options = new String[s_value.length];
    int index = 0;
    /**
		 * 	Check Existence of Workflow Activities
		 */
    String wfStatus = MWFActivity.getActiveInfo(Env.getCtx(), m_AD_Table_ID, Record_ID);
    if (wfStatus != null) {
        ADialog.error(m_WindowNo, this, "WFActiveForRecord", wfStatus);
        return;
    }
    //	Status Change
    if (!checkStatus(m_mTab.getTableName(), Record_ID, DocStatus)) {
        ADialog.error(m_WindowNo, this, "DocumentStatusChanged");
        return;
    }
    /*******************
		 *  General Actions
		 */
    String[] docActionHolder = new String[] { DocAction };
    index = DocumentEngine.getValidActions(DocStatus, Processing, OrderType, IsSOTrx, m_AD_Table_ID, docActionHolder, options);
    MTable table = MTable.get(Env.getCtx(), m_AD_Table_ID);
    PO po = table.getPO(Record_ID, null);
    if (po instanceof DocOptions)
        index = ((DocOptions) po).customizeValidActions(DocStatus, Processing, OrderType, IsSOTrx, m_AD_Table_ID, docActionHolder, options, index);
    Integer doctypeId = (Integer) m_mTab.getValue("C_DocType_ID");
    if (doctypeId == null || doctypeId.intValue() == 0) {
        doctypeId = (Integer) m_mTab.getValue("C_DocTypeTarget_ID");
    }
    log.fine("get doctype: " + doctypeId);
    if (doctypeId != null) {
        index = DocumentEngine.checkActionAccess(Env.getAD_Client_ID(Env.getCtx()), Env.getAD_Role_ID(Env.getCtx()), doctypeId, options, index);
    }
    DocAction = docActionHolder[0];
    /**
		 *	Fill actionCombo
		 */
    for (int i = 0; i < index; i++) {
        //	Search for option and add it
        boolean added = false;
        for (int j = 0; j < s_value.length && !added; j++) if (options[i].equals(s_value[j])) {
            actionCombo.addItem(s_name[j]);
            added = true;
        }
    }
    //	setDefault
    if (//	If None, suggest closing
    DocAction.equals("--"))
        DocAction = DocumentEngine.ACTION_Close;
    String defaultV = "";
    for (int i = 0; i < s_value.length && defaultV.equals(""); i++) if (DocAction.equals(s_value[i]))
        defaultV = s_name[i];
    if (!defaultV.equals(""))
        actionCombo.setSelectedItem(defaultV);
}
Also used : MTable(org.compiere.model.MTable) DocOptions(org.compiere.process.DocOptions) 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