Search in sources :

Example 36 with MClient

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

the class MWFActivity method performWork.

//	run
/**
	 * 	Perform Work.
	 * 	Set Text Msg.
	 * 	@param trx transaction
	 *	@return true if completed, false otherwise
	 *	@throws Exception if error
	 */
private boolean performWork(Trx trx) throws Exception {
    log.info(m_node + " [" + trx.getTrxName() + "]");
    m_docStatus = null;
    if (//	overwrite priority if defined
    m_node.getPriority() != 0)
        setPriority(m_node.getPriority());
    String action = m_node.getAction();
    /******	Sleep (Start/End)			******/
    if (MWFNode.ACTION_WaitSleep.equals(action)) {
        log.fine("Sleep:WaitTime=" + m_node.getWaitTime());
        if (m_node.getWaitingTime() == 0)
            //	done
            return true;
        Calendar cal = Calendar.getInstance();
        cal.add(m_node.getDurationCalendarField(), m_node.getWaitTime());
        setEndWaitTime(new Timestamp(cal.getTimeInMillis()));
        //	not done
        return false;
    } else /******	Document Action				******/
    if (MWFNode.ACTION_DocumentAction.equals(action)) {
        log.fine("DocumentAction=" + m_node.getDocAction());
        getPO(trx);
        if (m_po == null)
            throw new Exception("Persistent Object not found - AD_Table_ID=" + getAD_Table_ID() + ", Record_ID=" + getRecord_ID());
        boolean success = false;
        String processMsg = null;
        DocAction doc = null;
        if (m_po instanceof DocAction) {
            doc = (DocAction) m_po;
            //
            try {
                //	** Do the work
                success = doc.processIt(m_node.getDocAction());
                setTextMsg(doc.getSummary());
                processMsg = doc.getProcessMsg();
                // the rest of methods return boolean, so doc status must not be taken into account when not successful
                if (DocAction.ACTION_Prepare.equals(m_node.getDocAction()) || DocAction.ACTION_Complete.equals(m_node.getDocAction()) || success)
                    m_docStatus = doc.getDocStatus();
            } catch (Exception e) {
                if (m_process != null)
                    m_process.setProcessMsg(e.getLocalizedMessage());
                throw e;
            }
            if (m_process != null)
                m_process.setProcessMsg(processMsg);
        } else
            throw new IllegalStateException("Persistent Object not DocAction - " + m_po.getClass().getName() + " - AD_Table_ID=" + getAD_Table_ID() + ", Record_ID=" + getRecord_ID());
        //
        if (!m_po.save()) {
            success = false;
            processMsg = "SaveError";
        }
        if (!success) {
            if (processMsg == null || processMsg.length() == 0) {
                processMsg = "PerformWork Error - " + m_node.toStringX();
                if (//	problem: status will be rolled back
                doc != null)
                    processMsg += " - DocStatus=" + doc.getDocStatus();
            }
            throw new Exception(processMsg);
        }
        return success;
    } else /******	Report						******/
    if (MWFNode.ACTION_AppsReport.equals(action)) {
        log.fine("Report:AD_Process_ID=" + m_node.getAD_Process_ID());
        //	Process
        MProcess process = MProcess.get(getCtx(), m_node.getAD_Process_ID());
        process.set_TrxName(trx != null ? trx.getTrxName() : null);
        if (!process.isReport() || process.getAD_ReportView_ID() == 0)
            throw new IllegalStateException("Not a Report AD_Process_ID=" + m_node.getAD_Process_ID());
        //
        ProcessInfo pi = new ProcessInfo(m_node.getName(true), m_node.getAD_Process_ID(), getAD_Table_ID(), getRecord_ID());
        pi.setAD_User_ID(getAD_User_ID());
        pi.setAD_Client_ID(getAD_Client_ID());
        MPInstance pInstance = new MPInstance(process, getRecord_ID());
        pInstance.set_TrxName(trx != null ? trx.getTrxName() : null);
        fillParameter(pInstance, trx);
        pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
        //	Report
        ReportEngine re = ReportEngine.get(getCtx(), pi);
        if (re == null)
            throw new IllegalStateException("Cannot create Report AD_Process_ID=" + m_node.getAD_Process_ID());
        File report = re.getPDF();
        //	Notice
        //	HARDCODED WorkflowResult
        int AD_Message_ID = 753;
        MNote note = new MNote(getCtx(), AD_Message_ID, getAD_User_ID(), trx.getTrxName());
        note.setTextMsg(m_node.getName(true));
        note.setDescription(m_node.getDescription(true));
        note.setRecord(getAD_Table_ID(), getRecord_ID());
        note.saveEx();
        //	Attachment
        MAttachment attachment = new MAttachment(getCtx(), MNote.Table_ID, note.getAD_Note_ID(), get_TrxName());
        attachment.addEntry(report);
        attachment.setTextMsg(m_node.getName(true));
        attachment.saveEx();
        return true;
    } else /******	Process						******/
    if (MWFNode.ACTION_AppsProcess.equals(action)) {
        log.fine("Process:AD_Process_ID=" + m_node.getAD_Process_ID());
        //	Process
        MProcess process = MProcess.get(getCtx(), m_node.getAD_Process_ID());
        MPInstance pInstance = new MPInstance(process, getRecord_ID());
        fillParameter(pInstance, trx);
        //
        ProcessInfo pi = new ProcessInfo(m_node.getName(true), m_node.getAD_Process_ID(), getAD_Table_ID(), getRecord_ID());
        pi.setAD_User_ID(getAD_User_ID());
        pi.setAD_Client_ID(getAD_Client_ID());
        pi.setAD_PInstance_ID(pInstance.getAD_PInstance_ID());
        return process.processItWithoutTrxClose(pi, trx);
    } else /******	EMail						******/
    if (MWFNode.ACTION_EMail.equals(action)) {
        log.fine("EMail:EMailRecipient=" + m_node.getEMailRecipient());
        getPO(trx);
        if (m_po == null)
            throw new Exception("Persistent Object not found - AD_Table_ID=" + getAD_Table_ID() + ", Record_ID=" + getRecord_ID());
        if (m_po instanceof DocAction) {
            m_emails = new ArrayList<String>();
            sendEMail();
            setTextMsg(m_emails.toString());
        } else {
            MClient client = MClient.get(getCtx(), getAD_Client_ID());
            MMailText mailtext = new MMailText(getCtx(), getNode().getR_MailText_ID(), null);
            String subject = getNode().getDescription() + ": " + mailtext.getMailHeader();
            String message = mailtext.getMailText(true) + "\n-----\n" + getNodeHelp();
            String to = getNode().getEMail();
            client.sendEMail(to, subject, message, null);
        }
        //	done
        return true;
    } else /******	Set Variable				******/
    if (MWFNode.ACTION_SetVariable.equals(action)) {
        String value = m_node.getAttributeValue();
        log.fine("SetVariable:AD_Column_ID=" + m_node.getAD_Column_ID() + " to " + value);
        MColumn column = m_node.getColumn();
        int dt = column.getAD_Reference_ID();
        return setVariable(value, dt, null, trx);
    } else /******	TODO Start WF Instance		******/
    if (MWFNode.ACTION_SubWorkflow.equals(action)) {
        log.warning("Workflow:AD_Workflow_ID=" + m_node.getAD_Workflow_ID());
        log.warning("Start WF Instance is not implemented yet");
    } else /******	User Choice					******/
    if (MWFNode.ACTION_UserChoice.equals(action)) {
        log.fine("UserChoice:AD_Column_ID=" + m_node.getAD_Column_ID());
        //	Approval
        if (m_node.isUserApproval() && getPO(trx) instanceof DocAction) {
            DocAction doc = (DocAction) m_po;
            boolean autoApproval = false;
            //	Approval Hierarchy
            if (isInvoker()) {
                //	Set Approver
                int startAD_User_ID = Env.getAD_User_ID(getCtx());
                if (startAD_User_ID == 0)
                    startAD_User_ID = doc.getDoc_User_ID();
                int nextAD_User_ID = getApprovalUser(startAD_User_ID, doc.getC_Currency_ID(), doc.getApprovalAmt(), doc.getAD_Org_ID(), //	own doc
                startAD_User_ID == doc.getDoc_User_ID());
                //	same user = approved
                autoApproval = startAD_User_ID == nextAD_User_ID;
                if (!autoApproval)
                    setAD_User_ID(nextAD_User_ID);
            } else //	fixed Approver
            {
                MWFResponsible resp = getResponsible();
                // [ 1742751 ] Workflow: User Choice is not working
                if (resp.isHuman()) {
                    autoApproval = resp.getAD_User_ID() == Env.getAD_User_ID(getCtx());
                    if (!autoApproval && resp.getAD_User_ID() != 0)
                        setAD_User_ID(resp.getAD_User_ID());
                } else if (resp.isRole()) {
                    MUserRoles[] urs = MUserRoles.getOfRole(getCtx(), resp.getAD_Role_ID());
                    for (int i = 0; i < urs.length; i++) {
                        if (urs[i].getAD_User_ID() == Env.getAD_User_ID(getCtx())) {
                            autoApproval = true;
                            break;
                        }
                    }
                } else if (resp.isOrganization()) {
                    throw new AdempiereException("Support not implemented for " + resp);
                } else {
                    throw new AdempiereException("@NotSupported@ " + resp);
                }
            // end MZ
            }
            if (autoApproval && doc.processIt(DocAction.ACTION_Approve) && doc.save())
                //	done
                return true;
        }
        //	wait for user
        return false;
    } else /******	User Form					******/
    if (MWFNode.ACTION_UserForm.equals(action)) {
        log.fine("Form:AD_Form_ID=" + m_node.getAD_Form_ID());
        return false;
    } else if (MWFNode.ACTION_SmartBrowse.equals(action)) {
        log.fine("Form:AD_Browse_ID=" + m_node.getAD_Browse_ID());
        return false;
    } else /******	User Window					******/
    if (MWFNode.ACTION_UserWindow.equals(action)) {
        log.fine("Window:AD_Window_ID=" + m_node.getAD_Window_ID());
        return false;
    }
    //
    throw new IllegalArgumentException("Invalid Action (Not Implemented) =" + action);
}
Also used : MColumn(org.compiere.model.MColumn) MProcess(org.compiere.model.MProcess) MAttachment(org.compiere.model.MAttachment) DocAction(org.compiere.process.DocAction) MMailText(org.compiere.model.MMailText) Calendar(java.util.Calendar) MUserRoles(org.compiere.model.MUserRoles) ProcessInfo(org.compiere.process.ProcessInfo) Timestamp(java.sql.Timestamp) SQLException(java.sql.SQLException) AdempiereException(org.adempiere.exceptions.AdempiereException) Savepoint(java.sql.Savepoint) MClient(org.compiere.model.MClient) MPInstance(org.compiere.model.MPInstance) ReportEngine(org.compiere.print.ReportEngine) AdempiereException(org.adempiere.exceptions.AdempiereException) File(java.io.File) MNote(org.compiere.model.MNote)

Example 37 with MClient

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

the class Viewer method cmd_find.

//	cmd_report
/**
	 * 	Query Report
	 */
private void cmd_find() {
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    int AD_Table_ID = m_reportEngine.getPrintFormat().getAD_Table_ID();
    String title = null;
    String tableName = null;
    //	Get Find Tab Info
    String sql = "SELECT t.AD_Tab_ID " + //	,w.Name, t.Name, w.IsDefault, t.SeqNo, ABS (tt.AD_Window_ID-t.AD_Window_ID)
    "FROM AD_Tab t" + " INNER JOIN AD_Window w ON (t.AD_Window_ID=w.AD_Window_ID)" + " INNER JOIN AD_Table tt ON (t.AD_Table_ID=tt.AD_Table_ID) " + "WHERE tt.AD_Table_ID=? " + "ORDER BY w.IsDefault DESC, t.SeqNo, ABS (tt.AD_Window_ID-t.AD_Window_ID)";
    int AD_Tab_ID = DB.getSQLValue(null, sql, AD_Table_ID);
    // ASP
    MClient client = MClient.get(Env.getCtx());
    String ASPFilter = "";
    if (client.isUseASP())
        ASPFilter = "     AND (   AD_Tab_ID IN ( " + // Just ASP subscribed tabs for client "
        "              SELECT t.AD_Tab_ID " + "                FROM ASP_Tab t, ASP_Window w, ASP_Level l, ASP_ClientLevel cl " + "               WHERE w.ASP_Level_ID = l.ASP_Level_ID " + "                 AND cl.AD_Client_ID = " + client.getAD_Client_ID() + "                 AND cl.ASP_Level_ID = l.ASP_Level_ID " + "                 AND t.ASP_Window_ID = w.ASP_Window_ID " + "                 AND t.IsActive = 'Y' " + "                 AND w.IsActive = 'Y' " + "                 AND l.IsActive = 'Y' " + "                 AND cl.IsActive = 'Y' " + // Show
        "                 AND t.ASP_Status = 'S') " + "        OR AD_Tab_ID IN ( " + // + show ASP exceptions for client
        "              SELECT AD_Tab_ID " + "                FROM ASP_ClientException ce " + "               WHERE ce.AD_Client_ID = " + client.getAD_Client_ID() + "                 AND ce.IsActive = 'Y' " + "                 AND ce.AD_Tab_ID IS NOT NULL " + "                 AND ce.AD_Field_ID IS NULL " + // Show
        "                 AND ce.ASP_Status = 'S') " + "       ) " + "   AND AD_Tab_ID NOT IN ( " + // minus hide ASP exceptions for client
        "          SELECT AD_Tab_ID " + "            FROM ASP_ClientException ce " + "           WHERE ce.AD_Client_ID = " + client.getAD_Client_ID() + "             AND ce.IsActive = 'Y' " + "             AND ce.AD_Tab_ID IS NOT NULL " + "             AND ce.AD_Field_ID IS NULL " + // Hide
        "             AND ce.ASP_Status = 'H')";
    //
    sql = "SELECT Name, TableName FROM AD_Tab_v WHERE AD_Tab_ID=? " + ASPFilter;
    if (!Env.isBaseLanguage(Env.getCtx(), "AD_Tab"))
        sql = "SELECT Name, TableName FROM AD_Tab_vt WHERE AD_Tab_ID=?" + " AND AD_Language='" + Env.getAD_Language(Env.getCtx()) + "' " + ASPFilter;
    try {
        PreparedStatement pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, AD_Tab_ID);
        ResultSet rs = pstmt.executeQuery();
        //
        if (rs.next()) {
            title = rs.getString(1);
            tableName = rs.getString(2);
        }
        //
        rs.close();
        pstmt.close();
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql, e);
    }
    GridField[] findFields = null;
    if (tableName != null)
        findFields = GridField.createFields(m_ctx, m_WindowNo, 0, AD_Tab_ID);
    //	FR [ 295 ]
    if (findFields == null) {
        //	No Tab for Table exists
        if (launchProcessPara()) {
            revalidate();
        } else {
            return;
        }
    } else {
        ASearch search = new ASearch(bFind, this, title, AD_Tab_ID, AD_Table_ID, tableName, m_reportEngine, findFields, 1);
        search = null;
        revalidate();
    }
    //	setCursor
    cmd_drill();
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) GridField(org.compiere.model.GridField) ASearch(org.compiere.apps.ASearch) Point(java.awt.Point) MClient(org.compiere.model.MClient)

Example 38 with MClient

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

the class ReplenishReportProduction method createMovements.

//	createRequisition
/**
	 * 	Create Inventory Movements
	 */
private void createMovements() {
    int noMoves = 0;
    String info = "";
    //
    MClient client = null;
    MMovement move = null;
    int M_Warehouse_ID = 0;
    int M_WarehouseSource_ID = 0;
    MWarehouse whSource = null;
    MWarehouse wh = null;
    X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NOT NULL AND C_BPartner_ID > 0");
    for (int i = 0; i < replenishs.length; i++) {
        X_T_Replenish replenish = replenishs[i];
        if (whSource == null || whSource.getM_WarehouseSource_ID() != replenish.getM_WarehouseSource_ID())
            whSource = MWarehouse.get(getCtx(), replenish.getM_WarehouseSource_ID());
        if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID())
            wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID());
        if (client == null || client.getAD_Client_ID() != whSource.getAD_Client_ID())
            client = MClient.get(getCtx(), whSource.getAD_Client_ID());
        //
        if (move == null || M_WarehouseSource_ID != replenish.getM_WarehouseSource_ID() || M_Warehouse_ID != replenish.getM_Warehouse_ID()) {
            M_WarehouseSource_ID = replenish.getM_WarehouseSource_ID();
            M_Warehouse_ID = replenish.getM_Warehouse_ID();
            move = new MMovement(getCtx(), 0, get_TrxName());
            move.setC_DocType_ID(p_C_DocType_ID);
            move.setDescription(Msg.getMsg(getCtx(), "Replenishment") + ": " + whSource.getName() + "->" + wh.getName());
            //	Set Org
            move.setAD_Org_ID(whSource.getAD_Org_ID());
            if (!move.save())
                return;
            log.fine(move.toString());
            noMoves++;
            info += " - " + move.getDocumentNo();
        }
        //	To
        int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID();
        //	From: Look-up Storage
        MProduct product = MProduct.get(getCtx(), replenish.getM_Product_ID());
        String MMPolicy = product.getMMPolicy();
        MStorage[] storages = MStorage.getWarehouse(getCtx(), whSource.getM_Warehouse_ID(), replenish.getM_Product_ID(), 0, 0, true, null, MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
        //
        BigDecimal target = replenish.getQtyToOrder();
        for (int j = 0; j < storages.length; j++) {
            MStorage storage = storages[j];
            if (storage.getQtyOnHand().signum() <= 0)
                continue;
            BigDecimal moveQty = target;
            if (storage.getQtyOnHand().compareTo(moveQty) < 0)
                moveQty = storage.getQtyOnHand();
            //
            MMovementLine line = new MMovementLine(move);
            line.setM_Product_ID(replenish.getM_Product_ID());
            line.setMovementQty(moveQty);
            if (replenish.getQtyToOrder().compareTo(moveQty) != 0)
                line.setDescription("Total: " + replenish.getQtyToOrder());
            //	from
            line.setM_Locator_ID(storage.getM_Locator_ID());
            line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
            //	to
            line.setM_LocatorTo_ID(M_LocatorTo_ID);
            line.setM_AttributeSetInstanceTo_ID(storage.getM_AttributeSetInstance_ID());
            line.save();
            //
            target = target.subtract(moveQty);
            if (target.signum() == 0)
                break;
        }
    }
    if (replenishs.length == 0) {
        m_info = "No Source Warehouse";
        log.warning(m_info);
    } else {
        m_info = "#" + noMoves + info;
        log.info(m_info);
    }
}
Also used : MProduct(org.compiere.model.MProduct) X_T_Replenish(org.compiere.model.X_T_Replenish) MMovementLine(org.compiere.model.MMovementLine) MMovement(org.compiere.model.MMovement) MStorage(org.compiere.model.MStorage) MWarehouse(org.compiere.model.MWarehouse) BigDecimal(java.math.BigDecimal) MClient(org.compiere.model.MClient)

Example 39 with MClient

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

the class ReplenishReportProduction method createDO.

//	Create Inventory Movements
/**
	 * 	Create Distribution Order
	 */
private void createDO() throws Exception {
    int noMoves = 0;
    String info = "";
    //
    MClient client = null;
    MDDOrder order = null;
    int M_Warehouse_ID = 0;
    int M_WarehouseSource_ID = 0;
    MWarehouse whSource = null;
    MWarehouse wh = null;
    X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NOT NULL");
    for (X_T_Replenish replenish : replenishs) {
        if (whSource == null || whSource.getM_WarehouseSource_ID() != replenish.getM_WarehouseSource_ID())
            whSource = MWarehouse.get(getCtx(), replenish.getM_WarehouseSource_ID());
        if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID())
            wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID());
        if (client == null || client.getAD_Client_ID() != whSource.getAD_Client_ID())
            client = MClient.get(getCtx(), whSource.getAD_Client_ID());
        //
        if (order == null || M_WarehouseSource_ID != replenish.getM_WarehouseSource_ID() || M_Warehouse_ID != replenish.getM_Warehouse_ID()) {
            M_WarehouseSource_ID = replenish.getM_WarehouseSource_ID();
            M_Warehouse_ID = replenish.getM_Warehouse_ID();
            order = new MDDOrder(getCtx(), 0, get_TrxName());
            order.setC_DocType_ID(p_C_DocType_ID);
            order.setDescription(Msg.getMsg(getCtx(), "Replenishment") + ": " + whSource.getName() + "->" + wh.getName());
            //	Set Org
            order.setAD_Org_ID(whSource.getAD_Org_ID());
            // Set Org Trx
            MOrg orgTrx = MOrg.get(getCtx(), wh.getAD_Org_ID());
            order.setAD_OrgTrx_ID(orgTrx.getAD_Org_ID());
            int C_BPartner_ID = orgTrx.getLinkedC_BPartner_ID(get_TrxName());
            if (C_BPartner_ID == 0)
                throw new AdempiereUserError(Msg.translate(getCtx(), "C_BPartner_ID") + " @FillMandatory@ ");
            MBPartner bp = new MBPartner(getCtx(), C_BPartner_ID, get_TrxName());
            // Set BPartner Link to Org
            order.setBPartner(bp);
            order.setDateOrdered(new Timestamp(System.currentTimeMillis()));
            //order.setDatePromised(DatePromised);
            order.setDeliveryRule(MDDOrder.DELIVERYRULE_Availability);
            order.setDeliveryViaRule(MDDOrder.DELIVERYVIARULE_Delivery);
            order.setPriorityRule(MDDOrder.PRIORITYRULE_Medium);
            order.setIsInDispute(false);
            order.setIsApproved(false);
            order.setIsDropShip(false);
            order.setIsDelivered(false);
            order.setIsInTransit(false);
            order.setIsPrinted(false);
            order.setIsSelected(false);
            order.setIsSOTrx(false);
            // Warehouse in Transit
            MWarehouse[] whsInTransit = MWarehouse.getForOrg(getCtx(), whSource.getAD_Org_ID());
            for (MWarehouse whInTransit : whsInTransit) {
                if (whInTransit.isInTransit())
                    order.setM_Warehouse_ID(whInTransit.getM_Warehouse_ID());
            }
            if (order.getM_Warehouse_ID() == 0)
                throw new AdempiereUserError("Warehouse inTransit is @FillMandatory@ ");
            if (!order.save())
                return;
            log.fine(order.toString());
            noMoves++;
            info += " - " + order.getDocumentNo();
        }
        //	To
        int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID();
        int M_Locator_ID = whSource.getDefaultLocator().getM_Locator_ID();
        if (M_LocatorTo_ID == 0 || M_Locator_ID == 0)
            throw new AdempiereUserError(Msg.translate(getCtx(), "M_Locator_ID") + " @FillMandatory@ ");
        //	From: Look-up Storage
        /*MProduct product = MProduct.get(getCtx(), replenish.getM_Product_ID());
			MProductCategory pc = MProductCategory.get(getCtx(), product.getM_Product_Category_ID());
			String MMPolicy = pc.getMMPolicy();
			if (MMPolicy == null || MMPolicy.length() == 0)
				MMPolicy = client.getMMPolicy();
			//
			MStorage[] storages = MStorage.getWarehouse(getCtx(), 
				whSource.getM_Warehouse_ID(), replenish.getM_Product_ID(), 0, 0,
				true, null, 
				MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
			
			
			BigDecimal target = replenish.getQtyToOrder();
			for (int j = 0; j < storages.length; j++)
			{
				MStorage storage = storages[j];
				if (storage.getQtyOnHand().signum() <= 0)
					continue;
				BigDecimal moveQty = target;
				if (storage.getQtyOnHand().compareTo(moveQty) < 0)
					moveQty = storage.getQtyOnHand();
				//
				MDDOrderLine line = new MDDOrderLine(order);
				line.setM_Product_ID(replenish.getM_Product_ID());
				line.setQtyEntered(moveQty);
				if (replenish.getQtyToOrder().compareTo(moveQty) != 0)
					line.setDescription("Total: " + replenish.getQtyToOrder());
				line.setM_Locator_ID(storage.getM_Locator_ID());		//	from
				line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
				line.setM_LocatorTo_ID(M_LocatorTo_ID);					//	to
				line.setM_AttributeSetInstanceTo_ID(storage.getM_AttributeSetInstance_ID());
				line.setIsInvoiced(false);
				line.save();
				//
				target = target.subtract(moveQty);
				if (target.signum() == 0)
					break;
			}*/
        MDDOrderLine line = new MDDOrderLine(order);
        line.setM_Product_ID(replenish.getM_Product_ID());
        line.setQty(replenish.getQtyToOrder());
        if (replenish.getQtyToOrder().compareTo(replenish.getQtyToOrder()) != 0)
            line.setDescription("Total: " + replenish.getQtyToOrder());
        //	from
        line.setM_Locator_ID(M_Locator_ID);
        line.setM_AttributeSetInstance_ID(0);
        //	to
        line.setM_LocatorTo_ID(M_LocatorTo_ID);
        line.setM_AttributeSetInstanceTo_ID(0);
        line.setIsInvoiced(false);
        line.save();
    }
    if (replenishs.length == 0) {
        m_info = "No Source Warehouse";
        log.warning(m_info);
    } else {
        m_info = "#" + noMoves + info;
        log.info(m_info);
    }
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) MBPartner(org.compiere.model.MBPartner) Timestamp(java.sql.Timestamp) MWarehouse(org.compiere.model.MWarehouse) MClient(org.compiere.model.MClient) MDDOrderLine(org.eevolution.model.MDDOrderLine) MOrg(org.compiere.model.MOrg) X_T_Replenish(org.compiere.model.X_T_Replenish) MDDOrder(org.eevolution.model.MDDOrder)

Example 40 with MClient

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

the class MPrintFormat method createFromReportView.

//	createFromTable
/**
	 * 	Create MPrintFormat for ReportView
	 *  @param ctx context
	 * 	@param AD_ReportView_ID ReportView
	 *  @param ReportName - optional Report Name
	 * 	@return print format
	 */
public static MPrintFormat createFromReportView(Properties ctx, int AD_ReportView_ID, String ReportName) {
    MClient company = MClient.get(ctx);
    s_log.info("AD_ReportView_ID=" + AD_ReportView_ID + " - AD_Client_ID=" + company.get_ID() + " - " + ReportName);
    MPrintFormat pf = new MPrintFormat(ctx, 0, null);
    pf.setAD_ReportView_ID(AD_ReportView_ID);
    //	Get Info
    String sql = "SELECT t.TableName," + " (SELECT COUNT(*) FROM AD_PrintFormat x WHERE x.AD_ReportView_ID=rv.AD_ReportView_ID AND x.AD_Client_ID=c.AD_Client_ID) AS Count," + " COALESCE (cpc.AD_PrintColor_ID, pc.AD_PrintColor_ID) AS AD_PrintColor_ID," + " COALESCE (cpf.AD_PrintFont_ID, pf.AD_PrintFont_ID) AS AD_PrintFont_ID," + " COALESCE (cpp.AD_PrintPaper_ID, pp.AD_PrintPaper_ID) AS AD_PrintPaper_ID," + " t.AD_Table_ID " + "FROM AD_ReportView rv" + " INNER JOIN AD_Table t ON (rv.AD_Table_ID=t.AD_Table_ID)," + " AD_Client c" + " LEFT OUTER JOIN AD_PrintColor cpc ON (cpc.AD_Client_ID=c.AD_Client_ID AND cpc.IsDefault='Y')" + " LEFT OUTER JOIN AD_PrintFont cpf ON (cpf.AD_Client_ID=c.AD_Client_ID AND cpf.IsDefault='Y')" + " LEFT OUTER JOIN AD_PrintPaper cpp ON (cpp.AD_Client_ID=c.AD_Client_ID AND cpp.IsDefault='Y')," + " AD_PrintColor pc, AD_PrintFont pf, AD_PrintPaper pp " + "WHERE rv.AD_ReportView_ID=? AND c.AD_Client_ID=?" + " AND pc.IsDefault='Y' AND pf.IsDefault='Y' AND pp.IsDefault='Y'";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    boolean error = true;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, AD_ReportView_ID);
        pstmt.setInt(2, company.get_ID());
        rs = pstmt.executeQuery();
        if (rs.next()) {
            //	Name
            String name = ReportName;
            if (name == null || name.length() == 0)
                //	TableName
                name = rs.getString(1);
            int count = rs.getInt(2);
            if (count > 0)
                name += "_" + count;
            pf.setName(company.getValue() + " -> " + name);
            //
            pf.setAD_PrintColor_ID(rs.getInt(3));
            pf.setAD_PrintFont_ID(rs.getInt(4));
            pf.setAD_PrintPaper_ID(rs.getInt(5));
            //
            pf.setAD_Table_ID(rs.getInt(6));
            error = false;
        } else
            s_log.log(Level.SEVERE, "Not found: AD_ReportView_ID=" + AD_ReportView_ID);
    } catch (SQLException e) {
        s_log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    if (error)
        return null;
    //	Save & complete
    if (!pf.save())
        return null;
    //	pf.dump();
    pf.setItems(createItems(ctx, pf));
    //
    return pf;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) CPreparedStatement(org.compiere.util.CPreparedStatement) MClient(org.compiere.model.MClient)

Aggregations

MClient (org.compiere.model.MClient)50 SQLException (java.sql.SQLException)11 ResultSet (java.sql.ResultSet)9 Timestamp (java.sql.Timestamp)9 Properties (java.util.Properties)9 PreparedStatement (java.sql.PreparedStatement)8 File (java.io.File)7 MBPartner (org.compiere.model.MBPartner)7 MUser (org.compiere.model.MUser)6 AdempiereException (org.adempiere.exceptions.AdempiereException)5 MWarehouse (org.compiere.model.MWarehouse)5 AdempiereUserError (org.compiere.util.AdempiereUserError)5 Enumeration (java.util.Enumeration)4 MInvoice (org.compiere.model.MInvoice)4 MMailText (org.compiere.model.MMailText)4 PO (org.compiere.model.PO)4 Query (org.compiere.model.Query)4 ReportEngine (org.compiere.print.ReportEngine)4 Element (org.w3c.dom.Element)4 BigDecimal (java.math.BigDecimal)3