Search in sources :

Example 11 with MDocType

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

the class MPPMRP method C_Order.

/**
	 * Create MRP record based in Order 
	 * @param MOrder
	 */
public static void C_Order(MOrder o) {
    MDocType dt = MDocType.get(o.getCtx(), o.getC_DocTypeTarget_ID());
    String DocSubTypeSO = dt.getDocSubTypeSO();
    if (MDocType.DOCSUBTYPESO_StandardOrder.equals(DocSubTypeSO) || MDocType.DOCSUBTYPESO_WarehouseOrder.equals(DocSubTypeSO) || MDocType.DOCSUBTYPESO_OnCreditOrder.equals(DocSubTypeSO) || MDocType.DOCSUBTYPESO_POSOrder.equals(DocSubTypeSO) || !o.isSOTrx()) {
        if ((o.getDocStatus().equals(MOrder.DOCSTATUS_InProgress) || o.getDocStatus().equals(MOrder.DOCSTATUS_Completed)) || !o.isSOTrx()) {
            for (MOrderLine line : o.getLines()) {
                C_OrderLine(line);
            }
        }
        if (o.is_ValueChanged(MOrder.COLUMNNAME_DocStatus) || o.is_ValueChanged(MOrder.COLUMNNAME_C_BPartner_ID)) {
            List<MPPMRP> list = getQuery(o, null, null).list();
            for (MPPMRP mrp : list) {
                mrp.setC_Order(o);
                mrp.saveEx();
            }
        }
    }
}
Also used : MDocType(org.compiere.model.MDocType) MOrderLine(org.compiere.model.MOrderLine)

Example 12 with MDocType

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

the class MPPMRP method getDocType.

public static int getDocType(Properties ctx, String docBaseType, int AD_Org_ID, int Planner_ID, String trxName) {
    MDocType[] docs = MDocType.getOfDocBaseType(ctx, docBaseType);
    if (docs == null || docs.length == 0) {
        String reference = Msg.getMsg(ctx, "SequenceDocNotFound");
        String textMsg = "Not found default document type for docbasetype " + docBaseType;
        MNote note = new MNote(ctx, MMessage.getAD_Message_ID(ctx, "SequenceDocNotFound"), Planner_ID, MPPMRP.Table_ID, 0, reference, textMsg, trxName);
        note.setAD_Org_ID(AD_Org_ID);
        note.saveEx();
        throw new AdempiereException(textMsg);
    } else {
        for (MDocType doc : docs) {
            if (doc.getAD_Org_ID() == AD_Org_ID) {
                return doc.getC_DocType_ID();
            }
        }
        //log.info("Doc Type for "+docBaseType+": "+ docs[0].getC_DocType_ID());
        return docs[0].getC_DocType_ID();
    }
}
Also used : MDocType(org.compiere.model.MDocType) AdempiereException(org.adempiere.exceptions.AdempiereException) MNote(org.compiere.model.MNote)

Example 13 with MDocType

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

the class CostResult method createSalesOrder.

public MOrder createSalesOrder(Timestamp orderDate, BigDecimal qty, BigDecimal price) {
    MDocType salesType = null;
    for (MDocType dt : MDocType.getOfDocBaseType(getCtx(), MDocType.DOCBASETYPE_SalesOrder)) {
        if (MDocType.DOCSUBTYPESO_OnCreditOrder.equals(dt.getDocSubTypeSO())) {
            salesType = dt;
            break;
        }
    }
    //Create Sales Order
    MOrder salesOrder = new MOrder(getCtx(), 0, trxName);
    salesOrder.setAD_Org_ID(Env.getAD_Org_ID(getCtx()));
    salesOrder.setC_BPartner_ID(bp.getC_BPartner_ID());
    salesOrder.setIsSOTrx(true);
    salesOrder.setDateOrdered(orderDate);
    salesOrder.setDateAcct(orderDate);
    salesOrder.setM_Warehouse_ID(w.getM_Warehouse_ID());
    salesOrder.setSalesRep_ID(u.getAD_User_ID());
    salesOrder.setC_DocTypeTarget_ID(salesType.getC_DocType_ID());
    salesOrder.saveEx();
    // Create Line
    MOrderLine salesOrderLine = new MOrderLine(salesOrder);
    salesOrderLine.setM_Product_ID(product.getM_Product_ID());
    salesOrderLine.setPrice(price);
    salesOrderLine.setQtyEntered(qty);
    salesOrderLine.setQtyOrdered(qty);
    salesOrderLine.saveEx();
    // Complete Purchase Order
    salesOrder.setDocAction(DocAction.ACTION_Complete);
    salesOrder.setDocStatus(DocAction.STATUS_Drafted);
    salesOrder.processIt(DocAction.ACTION_Complete);
    salesOrder.saveEx();
    return salesOrder;
}
Also used : MDocType(org.compiere.model.MDocType) MOrder(org.compiere.model.MOrder) MOrderLine(org.compiere.model.MOrderLine)

Example 14 with MDocType

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

the class OrderServlet method processOrder.

//	getOrder
/**
	 *	Process Order
	 *	@param request request
	 *	@param order order
	 *	@return true if processed/ok
	 */
private boolean processOrder(HttpServletRequest request, MOrder order) {
    //	Doc Action
    String DocAction = WebUtil.getParameter(request, "DocAction");
    if (DocAction == null || DocAction.length() == 0)
        return false;
    MDocType dt = MDocType.get(order.getCtx(), order.getC_DocType_ID());
    if (!order.isSOTrx() || order.getGrandTotal().compareTo(Env.ZERO) <= 0 || !MDocType.DOCBASETYPE_SalesOrder.equals(dt.getDocBaseType())) {
        log.warning("Not a valid Sales Order " + order);
        return true;
    }
    //	We have a Order No & DocAction
    log.fine("DocAction=" + DocAction);
    if (!MOrder.DOCACTION_Void.equals(DocAction)) {
        //	Do not complete Prepayment
        if (MOrder.STATUS_WaitingPayment.equals(order.getDocStatus()))
            return false;
        if (MDocType.DOCSUBTYPESO_PrepayOrder.equals(dt.getDocSubTypeSO()))
            return false;
        if (!MOrder.DOCACTION_Complete.equals(DocAction)) {
            log.warning("Invalid DocAction=" + DocAction);
            return true;
        }
    }
    //	force creation
    order.setDocAction(DocAction, true);
    boolean ok = order.processIt(DocAction);
    order.saveEx();
    return ok;
}
Also used : MDocType(org.compiere.model.MDocType)

Example 15 with MDocType

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

the class CostEngine method clearAccounting.

/**
     * Clear Accounting
     * @param accountSchema
     * @param costType
     * @param model
	 * @param productId
     * @param dateAcct
     * @return true clean
     */
public boolean clearAccounting(MAcctSchema accountSchema, I_M_CostType costType, PO model, int productId, Timestamp dateAcct) {
    // check if costing type need reset accounting 
    if (!accountSchema.getCostingMethod().equals(costType.getCostingMethod())) {
        MProduct product = MProduct.get(accountSchema.getCtx(), productId);
        MProductCategoryAcct productCategoryAcct = MProductCategoryAcct.get(accountSchema.getCtx(), product.getM_Product_Category_ID(), accountSchema.get_ID(), model.get_TrxName());
        if (productCategoryAcct == null || !costType.getCostingMethod().equals(productCategoryAcct.getCostingMethod()))
            return false;
    }
    final String docBaseType;
    // check if account period is open
    if (model instanceof MMatchInv)
        docBaseType = MPeriodControl.DOCBASETYPE_MatchInvoice;
    else if (model instanceof MMatchPO)
        docBaseType = MPeriodControl.DOCBASETYPE_MatchPO;
    else if (model instanceof MProduction)
        docBaseType = MPeriodControl.DOCBASETYPE_MaterialProduction;
    else {
        MDocType docType = MDocType.get(model.getCtx(), model.get_ValueAsInt(MDocType.COLUMNNAME_C_DocType_ID));
        docBaseType = docType.getDocBaseType();
    }
    Boolean openPeriod = MPeriod.isOpen(model.getCtx(), dateAcct, docBaseType, model.getAD_Org_ID());
    if (!openPeriod) {
        System.out.println("Period closed.");
        return false;
    }
    final String sqlUpdate = "UPDATE " + model.get_TableName() + " SET Posted = 'N' WHERE " + model.get_TableName() + "_ID=?";
    DB.executeUpdate(sqlUpdate, new Object[] { model.get_ID() }, false, model.get_TrxName());
    //Delete account
    final String sqldelete = "DELETE FROM Fact_Acct WHERE Record_ID =? AND AD_Table_ID=?";
    DB.executeUpdate(sqldelete, new Object[] { model.get_ID(), model.get_Table_ID() }, false, model.get_TrxName());
    return true;
}
Also used : MProduct(org.compiere.model.MProduct) MDocType(org.compiere.model.MDocType) MMatchPO(org.compiere.model.MMatchPO) MMatchInv(org.compiere.model.MMatchInv) MProductCategoryAcct(org.compiere.model.MProductCategoryAcct) MProduction(org.compiere.model.MProduction)

Aggregations

MDocType (org.compiere.model.MDocType)29 MInvoice (org.compiere.model.MInvoice)5 ResultSet (java.sql.ResultSet)4 Timestamp (java.sql.Timestamp)4 MBPartner (org.compiere.model.MBPartner)4 BigDecimal (java.math.BigDecimal)3 PreparedStatement (java.sql.PreparedStatement)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 MClient (org.compiere.model.MClient)3 MInvoiceLine (org.compiere.model.MInvoiceLine)3 MLocation (org.compiere.model.MLocation)3 MOrder (org.compiere.model.MOrder)3 Query (org.compiere.model.Query)3 MInOutLine (org.compiere.model.MInOutLine)2 MMatchInv (org.compiere.model.MMatchInv)2 MOrderLine (org.compiere.model.MOrderLine)2 MProduct (org.compiere.model.MProduct)2 MWarehouse (org.compiere.model.MWarehouse)2 ProcessInfo (org.compiere.process.ProcessInfo)2 AdempiereSystemError (org.compiere.util.AdempiereSystemError)2