question: public static boolean createOrder ( MAcctSchema as , int AD_Org_ID , int M_Product_ID , int M_AttributeSetInstance_ID , int C_OrderLine_ID , int M_CostElement_ID , BigDecimal Amt , BigDecimal Qty , String Description , String trxName ) { String sql = "DELETE M_CostDetail " + "WHERE Processed='N' AND COALESCE(DeltaAmt,0)=0 AND COALESCE(DeltaQty,0)=0" + " AND C_OrderLine_ID=" + C_OrderLine_ID + " AND C_AcctSchema_ID =" + as . getC_AcctSchema_ID ( ) + " AND M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID ; int no = DB . executeUpdate ( sql , trxName ) ; if ( no != 0 ) s_log . config ( "Deleted #" + no ) ; MCostDetail cd = get ( as . getCtx ( ) , "C_OrderLine_ID=?" , C_OrderLine_ID , M_AttributeSetInstance_ID , as . getC_AcctSchema_ID ( ) , trxName ) ; if ( cd == null ) { cd = new MCostDetail ( as , AD_Org_ID , M_Product_ID , M_AttributeSetInstance_ID , M_CostElement_ID , Amt , Qty , Description , trxName ) ; cd . setC_OrderLine_ID ( C_OrderLine_ID ) ; } else { cd . setDeltaAmt ( Amt . subtract ( cd . getAmt ( ) ) ) ; cd . setDeltaQty ( Qty . subtract ( cd . getQty ( ) ) ) ; if ( cd . isDelta ( ) ) { cd . setProcessed ( false ) ; cd . setAmt ( Amt ) ; cd . setQty ( Qty ) ; } else return true ; } boolean ok = cd . save ( ) ; if ( ok && ! cd . isProcessed ( ) ) { MClient client = MClient . get ( as . getCtx ( ) , as . getAD_Client_ID ( ) ) ; if ( client . isCostImmediate ( ) ) cd . process ( ) ; } s_log . config ( "(" + ok + ") " + cd ) ; return ok ; }
target:  Create New Order Cost Detail for Purchase Orders. Called from Doc_MatchPO