use of org.compiere.model.Query in project adempiere by adempiere.
the class SB_InvoiceGenerateFromOrderLine method doIt.
// prepare
/**
* Generate Invoices
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
StringBuffer orderClause = new StringBuffer();
m_invoices = new ArrayList<MInvoice>();
if (!p_ConsolidateDocument)
orderClause.append("C_BPartner_ID, C_Order_ID, line");
else
orderClause.append("C_BPartner_ID");
String whereClause = "EXISTS (SELECT T_Selection_ID FROM T_Selection WHERE T_Selection.AD_PInstance_ID=? " + " AND T_Selection.T_Selection_ID=c_orderLine.C_OrderLine_ID)";
m_records = new Query(getCtx(), MOrderLine.Table_Name, whereClause, get_TrxName()).setParameters(getAD_PInstance_ID()).setOrderBy(orderClause.toString()).setClient_ID().list();
ordersToInvoice = new ArrayList<MOrder>();
for (MOrderLine orderLine : m_records) {
Boolean isadded = false;
for (MOrder order : ordersToInvoice) {
if (order.getC_Order_ID() == orderLine.getC_Order_ID()) {
isadded = true;
break;
}
}
if (!isadded)
ordersToInvoice.add(orderLine.getParent());
}
for (MOrder order : ordersToInvoice) {
generate(order);
}
String result = "Fact. No";
for (MInvoice inv : m_invoices) {
Env.setContext(getCtx(), "@WhereClause@", whereClause);
result = result + ", " + inv.getDocumentInfo();
}
return result;
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class ExpenseTypesFromAccounts method doIt.
@Override
protected String doIt() throws Exception {
// Fetch price list
MPriceList priceList = new MPriceList(getCtx(), m_priceListId, get_TrxName());
// Get current client id from price list since I for some reason can't read it from
// context.
m_clientId = priceList.getAD_Client_ID();
// Get active price list version
MPriceListVersion pv = priceList.getPriceListVersion(null);
if (pv == null)
throw new Exception("Pricelist " + priceList.getName() + " has no default version.");
MProduct product;
// Read all existing applicable products into memory for quick comparison.
List<MProduct> products = new Query(getCtx(), I_M_Product.Table_Name, "ProductType=?", get_TrxName()).setParameters(MProduct.PRODUCTTYPE_ExpenseType).list();
Map<String, MProduct> productMap = new TreeMap<String, MProduct>();
for (Iterator<MProduct> it = products.iterator(); it.hasNext(); ) {
product = it.next();
productMap.put(product.getValue(), product);
}
// Read all existing valid combinations comparison
MAccount validComb;
List<MAccount> validCombs = new Query(getCtx(), I_C_ValidCombination.Table_Name, "C_AcctSchema_ID=? and AD_Client_ID=? and AD_Org_ID=0", get_TrxName()).setParameters(m_acctSchemaId, m_clientId).list();
Map<Integer, MAccount> validCombMap = new TreeMap<Integer, MAccount>();
for (Iterator<MAccount> it = validCombs.iterator(); it.hasNext(); ) {
validComb = it.next();
validCombMap.put(validComb.getAccount_ID(), validComb);
}
// Read all accounttypes that fit the given criteria.
List<MElementValue> result = new Query(getCtx(), I_C_ElementValue.Table_Name, "AccountType=? and isSummary='N' and Value>=? and Value<=? and AD_Client_ID=?", get_TrxName()).setParameters(MElementValue.ACCOUNTTYPE_Expense, m_startElement, m_endElement, m_clientId).list();
MElementValue elem;
MProductPrice priceRec;
X_M_Product_Acct productAcct;
String expenseItemValue;
BigDecimal zero = Env.ZERO;
int addCount = 0;
int skipCount = 0;
for (Iterator<MElementValue> it = result.iterator(); it.hasNext(); ) {
elem = it.next();
expenseItemValue = m_productValuePrefix + elem.getValue() + m_productValueSuffix;
// See if a product with this key already exists
product = productMap.get(expenseItemValue);
if (product == null) {
// Create a new product from the account element
product = new MProduct(getCtx(), 0, get_TrxName());
product.set_ValueOfColumn("AD_Client_ID", Integer.valueOf(m_clientId));
product.setValue(expenseItemValue);
product.setName(elem.getName());
product.setDescription(elem.getDescription());
product.setIsActive(true);
product.setProductType(MProduct.PRODUCTTYPE_ExpenseType);
product.setM_Product_Category_ID(m_productCategoryId);
product.setC_UOM_ID(m_uomId);
product.setC_TaxCategory_ID(m_taxCategoryId);
product.setIsStocked(false);
product.setIsPurchased(true);
product.setIsSold(false);
// Save the product
product.saveEx(get_TrxName());
// Add a zero product price to the price list so it shows up in the price list
priceRec = new MProductPrice(getCtx(), pv.get_ID(), product.get_ID(), get_TrxName());
priceRec.set_ValueOfColumn("AD_Client_ID", Integer.valueOf(m_clientId));
priceRec.setPrices(zero, zero, zero);
priceRec.saveEx(get_TrxName());
// Set the revenue and expense accounting of the product to the given account element
// Get the valid combination
validComb = validCombMap.get(elem.getC_ElementValue_ID());
if (validComb == null) {
// Create new valid combination
validComb = new MAccount(getCtx(), 0, get_TrxName());
validComb.set_ValueOfColumn("AD_Client_ID", Integer.valueOf(m_clientId));
validComb.setAD_Org_ID(0);
validComb.setAlias(elem.getValue());
validComb.setAccount_ID(elem.get_ID());
validComb.setC_AcctSchema_ID(m_acctSchemaId);
validComb.saveEx(get_TrxName());
}
// TODO: It might be needed to make the accounting more specific, but the purpose
// of the process now is to create general accounts so this is intentional.
productAcct = new Query(getCtx(), I_M_Product_Acct.Table_Name, "M_Product_ID=? and C_AcctSchema_ID=?", get_TrxName()).setParameters(product.get_ID(), m_acctSchemaId).first();
productAcct.setP_Expense_Acct(validComb.get_ID());
productAcct.setP_Revenue_Acct(validComb.get_ID());
productAcct.saveEx(get_TrxName());
addCount++;
} else {
skipCount++;
}
}
String returnStr = addCount + " products added.";
if (skipCount > 0)
returnStr += " " + skipCount + " products skipped.";
return (returnStr);
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class InOutGenerateRMA method createShipmentLines.
private MInOutLine[] createShipmentLines(MRMA rma, MInOut shipment) {
ArrayList<MInOutLine> shipLineList = new ArrayList<MInOutLine>();
MRMALine[] rmaLines = rma.getLines(true);
for (MRMALine rmaLine : rmaLines) {
if (rmaLine.getM_InOutLine_ID() != 0) {
MInOutLine shipLine = new MInOutLine(shipment);
shipLine.setM_RMALine_ID(rmaLine.get_ID());
shipLine.setLine(rmaLine.getLine());
shipLine.setDescription(rmaLine.getDescription());
shipLine.setM_Product_ID(rmaLine.getM_Product_ID());
shipLine.setM_AttributeSetInstance_ID(rmaLine.getM_AttributeSetInstance_ID());
shipLine.setC_UOM_ID(rmaLine.getC_UOM_ID());
shipLine.setQty(rmaLine.getQty());
shipLine.setM_Locator_ID(rmaLine.getM_Locator_ID());
shipLine.setC_Project_ID(rmaLine.getC_Project_ID());
shipLine.setC_Campaign_ID(rmaLine.getC_Campaign_ID());
shipLine.setC_Activity_ID(rmaLine.getC_Activity_ID());
shipLine.setC_ProjectPhase_ID(rmaLine.getC_ProjectPhase_ID());
shipLine.setC_ProjectTask_ID(rmaLine.getC_ProjectTask_ID());
shipLine.setUser1_ID(rmaLine.getUser1_ID());
shipLine.setUser2_ID(rmaLine.getUser2_ID());
shipLine.setUser3_ID(rmaLine.getUser3_ID());
shipLine.setUser4_ID(rmaLine.getUser4_ID());
shipLine.saveEx();
shipLineList.add(shipLine);
//
// Link to corresponding Invoice Line (if any) - teo_sarca [ 2818523 ]
// The MMatchInv records will be automatically generated on MInOut.completeIt()
MInvoiceLine invoiceLine = new Query(shipment.getCtx(), I_C_InvoiceLine.Table_Name, I_C_InvoiceLine.COLUMNNAME_M_RMALine_ID + "=?", shipment.get_TrxName()).setParameters(rmaLine.getM_RMALine_ID()).firstOnly();
if (invoiceLine != null) {
invoiceLine.setM_InOutLine_ID(shipLine.getM_InOutLine_ID());
invoiceLine.saveEx();
}
}
}
MInOutLine[] shipLines = new MInOutLine[shipLineList.size()];
shipLineList.toArray(shipLines);
return shipLines;
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class CleanUpGW method gardenWorldExists.
private Boolean gardenWorldExists() {
StringBuilder whereClause = new StringBuilder();
// #1
whereClause.append("AD_Client_ID=?");
MClient gwClient = new Query(getCtx(), MClient.Table_Name, whereClause.toString(), null).setParameters(new Object[] { gw_client_id }).first();
if (gwClient != null && gwClient.getName().equals("GardenWorld")) {
return true;
}
return false;
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class BPartnerValidate method doIt.
// prepare
/**
* Process
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("C_BPartner_ID=" + p_C_BPartner_ID + ", C_BP_Group_ID=" + p_C_BP_Group_ID);
if (p_C_BPartner_ID == 0 && p_C_BP_Group_ID == 0)
throw new AdempiereUserError("No Business Partner/Group selected");
if (p_C_BP_Group_ID == 0) {
MBPartner bp = new MBPartner(getCtx(), p_C_BPartner_ID, get_TrxName());
if (bp.get_ID() == 0)
throw new AdempiereUserError("Business Partner not found - C_BPartner_ID=" + p_C_BPartner_ID);
checkBP(bp);
} else {
final String whereClause = "C_BP_Group_ID=?";
Iterator<MBPartner> it = new Query(getCtx(), I_C_BPartner.Table_Name, whereClause, get_TrxName()).setParameters(p_C_BP_Group_ID).setOnlyActiveRecords(true).iterate();
while (it.hasNext()) {
checkBP(it.next());
}
}
//
return "OK";
}
Aggregations