List of usage examples for org.hibernate.criterion Restrictions isNotNull
public static Criterion isNotNull(String propertyName)
From source file:org.openbravo.advpaymentmngt.ad_actionbutton.AddOrderOrInvoice.java
License:Open Source License
private void printGrid(HttpServletResponse response, VariablesSecureApp vars, String strBusinessPartnerId, String strPaymentId, String strOrgId, String strExpectedDateFrom, String strExpectedDateTo, String strDocumentType, String strSelectedPaymentDetails, boolean isReceipt, boolean showAlternativePM) throws IOException, ServletException { log4j.debug("Output: Grid with pending payments"); dao = new AdvPaymentMngtDao(); String[] discard = { "" }; if (!"".equals(vars.getRequestGlobalVariable("inpBusinessPartnerId", ""))) { discard[0] = "businessPartnerName"; }/*from w w w. j a va 2 s . co m*/ XmlDocument xmlDocument = xmlEngine .readXmlTemplate("org/openbravo/advpaymentmngt/ad_actionbutton/AddPaymentGrid", discard) .createXmlDocument(); FIN_Payment payment = dao.getObject(FIN_Payment.class, strPaymentId); List<FIN_PaymentScheduleDetail> storedScheduledPaymentDetails = new ArrayList<FIN_PaymentScheduleDetail>(); // This is to identify first load of the grid String strFirstLoad = vars.getStringParameter("isFirstLoad"); if (payment.getFINPaymentDetailList().size() > 0) { // Add payment schedule details related to orders or invoices to storedSchedulePaymentDetails OBContext.setAdminMode(); try { OBCriteria<FIN_PaymentScheduleDetail> obc = OBDal.getInstance() .createCriteria(FIN_PaymentScheduleDetail.class); obc.add(Restrictions.in(FIN_PaymentScheduleDetail.PROPERTY_PAYMENTDETAILS, payment.getFINPaymentDetailList())); obc.add(Restrictions.or( Restrictions.isNotNull(FIN_PaymentScheduleDetail.PROPERTY_INVOICEPAYMENTSCHEDULE), Restrictions.isNotNull(FIN_PaymentScheduleDetail.PROPERTY_ORDERPAYMENTSCHEDULE))); storedScheduledPaymentDetails = obc.list(); } finally { OBContext.restorePreviousMode(); } } // Pending Payments from invoice final List<FIN_PaymentScheduleDetail> selectedScheduledPaymentDetails = FIN_AddPayment .getSelectedPaymentDetails("true".equals(strFirstLoad) ? new ArrayList<FIN_PaymentScheduleDetail>(storedScheduledPaymentDetails) : null, strSelectedPaymentDetails); // filtered scheduled payments list final List<FIN_PaymentScheduleDetail> filteredScheduledPaymentDetails = dao .getFilteredScheduledPaymentDetails(dao.getObject(Organization.class, strOrgId), dao.getObject(BusinessPartner.class, strBusinessPartnerId), payment.getCurrency(), null, null, FIN_Utility.getDate(strExpectedDateFrom), FIN_Utility.getDate(DateTimeData.nDaysAfter(this, strExpectedDateTo, "1")), null, null, strDocumentType, "", showAlternativePM ? null : payment.getPaymentMethod(), selectedScheduledPaymentDetails, isReceipt); // Remove related outstanding schedule details related to those ones being edited as amount will // be later added to storedScheduledPaymentDetails for (FIN_PaymentScheduleDetail psd : storedScheduledPaymentDetails) { filteredScheduledPaymentDetails.removeAll(FIN_AddPayment.getOutstandingPSDs(psd)); } // Get stored not selected PSDs List<FIN_PaymentScheduleDetail> storedNotSelectedPSDs = new ArrayList<FIN_PaymentScheduleDetail>( storedScheduledPaymentDetails); storedNotSelectedPSDs.removeAll(selectedScheduledPaymentDetails); // Add stored but not selected details which maps documenttype filteredScheduledPaymentDetails.addAll(filterDocumenttype(storedNotSelectedPSDs, strDocumentType)); FieldProvider[] data = FIN_AddPayment.getShownScheduledPaymentDetails(vars, selectedScheduledPaymentDetails, filteredScheduledPaymentDetails, false, null, strSelectedPaymentDetails); for (FIN_PaymentScheduleDetail psd : storedScheduledPaymentDetails) { // Calculate pending amount BigDecimal outstandingAmount = BigDecimal.ZERO; List<FIN_PaymentScheduleDetail> outStandingPSDs = FIN_AddPayment.getOutstandingPSDs(psd); if (outStandingPSDs.size() != 0) { for (FIN_PaymentScheduleDetail outPSD : outStandingPSDs) { outstandingAmount = outstandingAmount.add(outPSD.getAmount()); } } for (int i = 0; i < data.length; i++) { if (data[i].getField("finScheduledPaymentDetailId").equals(psd.getId())) { FieldProviderFactory.setField(data[i], "outstandingAmount", psd.getAmount().add(outstandingAmount).toPlainString()); if ("true".equals(strFirstLoad)) { FieldProviderFactory.setField(data[i], "difference", outstandingAmount.toPlainString()); FieldProviderFactory.setField(data[i], "paymentAmount", psd.getAmount().toPlainString()); } } } } data = groupPerDocumentType(data, strDocumentType); xmlDocument.setData("structure", (data == null) ? set() : data); response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); out.println(xmlDocument.print()); out.close(); }
From source file:org.openbravo.advpaymentmngt.ad_actionbutton.Reconciliation.java
License:Open Source License
private boolean isAutomaticReconciliation(FIN_Reconciliation reconciliation) { OBContext.setAdminMode();/*from w w w . jav a 2s. co m*/ try { final OBCriteria<FIN_ReconciliationLine_v> obc = OBDal.getInstance() .createCriteria(FIN_ReconciliationLine_v.class); obc.add(Restrictions.eq(FIN_ReconciliationLine_v.PROPERTY_RECONCILIATION, reconciliation)); obc.add(Restrictions.isNotNull(FIN_ReconciliationLine_v.PROPERTY_BANKSTATEMENTLINE)); obc.setMaxResults(1); final List<FIN_ReconciliationLine_v> rec = obc.list(); return (rec.size() != 0); } finally { OBContext.restorePreviousMode(); } }
From source file:org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao.java
License:Open Source License
public List<FIN_PaymentScheduleDetail> getFilteredScheduledPaymentDetails(Organization organization, BusinessPartner businessPartner, Currency currency, Date dueDateFrom, Date dueDateTo, Date expectedDateFrom, Date expectedDateTo, Date transactionDateFrom, Date transactionDateTo, String strTransactionType, String strDocumentNo, FIN_PaymentMethod paymentMethod, List<FIN_PaymentScheduleDetail> selectedScheduledPaymentDetails, boolean isReceipt, String strAmountFrom, String strAmountTo) { final StringBuilder whereClause = new StringBuilder(); final List<Object> parameters = new ArrayList<Object>(); // FIXME: added to access the FIN_PaymentSchedule and FIN_PaymentScheduleDetail tables to be // removed when new security implementation is done OBContext.setAdminMode();/*from w w w . j a va 2 s . c o m*/ try { whereClause.append(" as psd "); // pending scheduled payments // whereClause.append(" left outer join psd.orderPaymentSchedule as ops "); whereClause.append(" left outer join ops.order as ord"); whereClause.append(" left outer join ops.fINPaymentPriority as opriority"); whereClause.append(" left outer join psd.invoicePaymentSchedule as ips "); whereClause.append(" left outer join ips.invoice as inv"); whereClause.append(" left outer join ips.fINPaymentPriority as ipriority"); whereClause.append(" left outer join psd.organization as org"); whereClause.append(" left outer join org.organizationInformationList as oinfo"); whereClause.append(" where psd."); whereClause.append(FIN_PaymentScheduleDetail.PROPERTY_PAYMENTDETAILS); whereClause.append(" is null"); whereClause.append(" and psd."); whereClause.append(FIN_PaymentSchedule.PROPERTY_ORGANIZATION); whereClause.append(".id in ("); whereClause.append(Utility.getInStrSet(OBContext.getOBContext().getOrganizationStructureProvider() .getNaturalTree(organization.getId()))); whereClause.append(")"); whereClause.append(" and (oinfo is null or oinfo.active = true)"); // remove selected payments if (selectedScheduledPaymentDetails != null && selectedScheduledPaymentDetails.size() > 0) { String strSelectedPaymentDetails = Utility.getInStrList(selectedScheduledPaymentDetails); whereClause.append(" and psd not in ("); whereClause.append(strSelectedPaymentDetails); whereClause.append(")"); } // block schedule payments in other payment proposal final OBCriteria<FIN_PaymentPropDetail> obc = OBDal.getInstance() .createCriteria(FIN_PaymentPropDetail.class); obc.add(Restrictions.isNotNull(FIN_PaymentPropDetail.PROPERTY_FINPAYMENTSCHEDULEDETAIL)); if (obc.list() != null && obc.list().size() > 0) { List<FIN_PaymentScheduleDetail> aux = new ArrayList<FIN_PaymentScheduleDetail>(); for (FIN_PaymentPropDetail ppd : obc.list()) { aux.add(ppd.getFINPaymentScheduledetail()); } whereClause.append(" and psd.id not in (" + Utility.getInStrList(aux) + ")"); } if (!StringUtils.isEmpty(strAmountFrom)) { whereClause.append(" and psd."); whereClause.append(FIN_PaymentScheduleDetail.PROPERTY_AMOUNT); whereClause.append(" >= "); whereClause.append(strAmountFrom); whereClause.append(" "); } if (!StringUtils.isEmpty(strAmountTo)) { whereClause.append(" and psd."); whereClause.append(FIN_PaymentScheduleDetail.PROPERTY_AMOUNT); whereClause.append(" <= "); whereClause.append(strAmountTo); whereClause.append(" "); } // Transaction type filter whereClause.append(" and ("); if (strTransactionType.equals("I") || strTransactionType.equals("B")) { whereClause.append(" (inv is not null"); if (businessPartner != null) { whereClause.append(" and inv."); whereClause.append(Invoice.PROPERTY_BUSINESSPARTNER); whereClause.append(".id = '"); whereClause.append(businessPartner.getId()); whereClause.append("'"); } if (paymentMethod != null) { whereClause.append(" and inv."); whereClause.append(Invoice.PROPERTY_PAYMENTMETHOD); whereClause.append(".id = '"); whereClause.append(paymentMethod.getId()); whereClause.append("'"); } if (transactionDateFrom != null) { whereClause.append(" and inv."); whereClause.append(Invoice.PROPERTY_INVOICEDATE); whereClause.append(" >= ?"); parameters.add(transactionDateFrom); } if (transactionDateTo != null) { whereClause.append(" and inv."); whereClause.append(Invoice.PROPERTY_INVOICEDATE); whereClause.append(" < ?"); parameters.add(transactionDateTo); } whereClause.append(" and inv."); whereClause.append(Invoice.PROPERTY_SALESTRANSACTION); whereClause.append(" = "); whereClause.append(isReceipt); // Invoice Document No. filter if (!StringUtils.isEmpty(strDocumentNo)) { whereClause.append(" and (case when"); whereClause.append(" (inv."); whereClause.append(Invoice.PROPERTY_SALESTRANSACTION); whereClause.append(" = false"); whereClause.append(" and oinfo is not null"); whereClause.append(" and oinfo."); whereClause.append(OrganizationInformation.PROPERTY_APRMPAYMENTDESCRIPTION); whereClause.append(" like 'Supplier Reference')"); whereClause.append(" then "); // When the Organization of the Invoice sets that the Invoice Document No. is the // supplier's whereClause.append(" inv."); whereClause.append(Invoice.PROPERTY_ORDERREFERENCE); whereClause.append(" else "); // When the Organization of the Invoice sets that the Invoice Document No. is the default // Invoice Number whereClause.append(" inv."); whereClause.append(Invoice.PROPERTY_DOCUMENTNO); whereClause.append(" end) "); whereClause.append(" like '%"); whereClause.append(strDocumentNo); whereClause.append("%' "); } whereClause.append(" and inv."); whereClause.append(Invoice.PROPERTY_CURRENCY); whereClause.append(".id = '"); whereClause.append(currency.getId()); whereClause.append("')"); } if (strTransactionType.equals("B")) whereClause.append(" or "); if (strTransactionType.equals("O") || strTransactionType.equals("B")) { whereClause.append(" (ord is not null"); if (businessPartner != null) { whereClause.append(" and ord."); whereClause.append(Order.PROPERTY_BUSINESSPARTNER); whereClause.append(".id = '"); whereClause.append(businessPartner.getId()); whereClause.append("'"); } if (paymentMethod != null) { whereClause.append(" and ord."); whereClause.append(Order.PROPERTY_PAYMENTMETHOD); whereClause.append(".id = '"); whereClause.append(paymentMethod.getId()); whereClause.append("'"); } if (transactionDateFrom != null) { whereClause.append(" and ord."); whereClause.append(Order.PROPERTY_ORDERDATE); whereClause.append(" >= ?"); parameters.add(transactionDateFrom); } if (transactionDateTo != null) { whereClause.append(" and ord."); whereClause.append(Order.PROPERTY_ORDERDATE); whereClause.append(" < ?"); parameters.add(transactionDateTo); } if (!StringUtils.isEmpty(strDocumentNo)) { whereClause.append(" and ord."); whereClause.append(Order.PROPERTY_DOCUMENTNO); whereClause.append(" like '%"); whereClause.append(strDocumentNo); whereClause.append("%' "); } whereClause.append(" and ord."); whereClause.append(Order.PROPERTY_SALESTRANSACTION); whereClause.append(" = "); whereClause.append(isReceipt); whereClause.append(" and ord."); whereClause.append(Order.PROPERTY_CURRENCY); whereClause.append(".id = '"); whereClause.append(currency.getId()); whereClause.append("')"); } whereClause.append(")"); // dateFrom if (dueDateFrom != null) { whereClause.append(" and COALESCE(ips."); whereClause.append(FIN_PaymentSchedule.PROPERTY_DUEDATE); whereClause.append(", ops."); whereClause.append(FIN_PaymentSchedule.PROPERTY_DUEDATE); whereClause.append(") >= ?"); parameters.add(dueDateFrom); } // dateTo if (dueDateTo != null) { whereClause.append(" and COALESCE(ips."); whereClause.append(FIN_PaymentSchedule.PROPERTY_DUEDATE); whereClause.append(", ops."); whereClause.append(FIN_PaymentSchedule.PROPERTY_DUEDATE); whereClause.append(") < ?"); parameters.add(dueDateTo); } // expecteddateFrom if (expectedDateFrom != null) { whereClause.append(" and COALESCE(ips."); whereClause.append(FIN_PaymentSchedule.PROPERTY_EXPECTEDDATE); whereClause.append(", ops."); whereClause.append(FIN_PaymentSchedule.PROPERTY_EXPECTEDDATE); whereClause.append(") >= ?"); parameters.add(expectedDateFrom); } // expecteddateTo if (expectedDateTo != null) { whereClause.append(" and COALESCE(ips."); whereClause.append(FIN_PaymentSchedule.PROPERTY_EXPECTEDDATE); whereClause.append(", ops."); whereClause.append(FIN_PaymentSchedule.PROPERTY_EXPECTEDDATE); whereClause.append(") < ?"); parameters.add(expectedDateTo); } // TODO: Add order to show first scheduled payments from invoices and later scheduled payments // from not invoiced orders. whereClause.append(" order by"); whereClause.append(" COALESCE(ipriority."); whereClause.append(PaymentPriority.PROPERTY_PRIORITY); whereClause.append(", opriority."); whereClause.append(PaymentPriority.PROPERTY_PRIORITY); whereClause.append(")"); whereClause.append(", "); whereClause.append(" COALESCE(ips."); whereClause.append(FIN_PaymentSchedule.PROPERTY_EXPECTEDDATE); whereClause.append(", ops."); whereClause.append(FIN_PaymentSchedule.PROPERTY_EXPECTEDDATE); whereClause.append(")"); whereClause.append(", COALESCE(inv."); whereClause.append(Invoice.PROPERTY_DOCUMENTNO); whereClause.append(", ord."); whereClause.append(Order.PROPERTY_DOCUMENTNO); whereClause.append(")"); whereClause.append(", psd."); whereClause.append(FIN_PaymentScheduleDetail.PROPERTY_AMOUNT); final OBQuery<FIN_PaymentScheduleDetail> obqPSD = OBDal.getInstance() .createQuery(FIN_PaymentScheduleDetail.class, whereClause.toString()); obqPSD.setParameters(parameters); return obqPSD.list(); } finally { OBContext.restorePreviousMode(); } }
From source file:org.openbravo.advpaymentmngt.process.FIN_AddPayment.java
License:Open Source License
public static List<FIN_PaymentScheduleDetail> getGLItemScheduleDetails(FIN_Payment payment) { if (payment.getFINPaymentDetailList().size() > 0) { OBContext.setAdminMode();//from w ww . java2 s . c om try { OBCriteria<FIN_PaymentScheduleDetail> selectedGLItems = OBDal.getInstance() .createCriteria(FIN_PaymentScheduleDetail.class); selectedGLItems.createAlias(FIN_PaymentScheduleDetail.PROPERTY_PAYMENTDETAILS, "pd"); selectedGLItems.add(Restrictions.in(FIN_PaymentScheduleDetail.PROPERTY_PAYMENTDETAILS, payment.getFINPaymentDetailList())); selectedGLItems.add(Restrictions.isNotNull("pd." + FIN_PaymentDetail.PROPERTY_GLITEM)); return selectedGLItems.list(); } finally { OBContext.restorePreviousMode(); } } else { return new ArrayList<FIN_PaymentScheduleDetail>(); } }
From source file:org.openbravo.advpaymentmngt.utility.FIN_Utility.java
License:Open Source License
/** * Generic OBCriteria.//from w w w . j av a 2 s . c o m * * @param clazz * Class (entity). * @param setFilterClient * If true then only objects from readable clients are returned, if false then objects * from all clients are returned * @param setFilterOrg * If true then when querying (for example call list()) a filter on readable * organizations is added to the query, if false then this is not done * @param values * Value. Property, value and operator. * @return All the records that satisfy the conditions. */ public static <T extends BaseOBObject> List<T> getAllInstances(Class<T> clazz, boolean setFilterClient, boolean setFilterOrg, Value... values) { OBCriteria<T> obc = OBDal.getInstance().createCriteria(clazz); obc.setFilterOnReadableClients(setFilterClient); obc.setFilterOnReadableOrganization(setFilterOrg); for (Value value : values) { if (value.getValue() == null && "==".equals(value.getOperator())) { obc.add(Restrictions.isNull(value.getField())); } else if (value.getValue() == null && "!=".equals(value.getOperator())) { obc.add(Restrictions.isNotNull(value.getField())); } else if ("==".equals(value.getOperator())) { obc.add(Restrictions.eq(value.getField(), value.getValue())); } else if ("!=".equals(value.getOperator())) { obc.add(Restrictions.ne(value.getField(), value.getValue())); } else if ("<".equals(value.getOperator())) { obc.add(Restrictions.lt(value.getField(), value.getValue())); } else if (">".equals(value.getOperator())) { obc.add(Restrictions.gt(value.getField(), value.getValue())); } else if ("<=".equals(value.getOperator())) { obc.add(Restrictions.le(value.getField(), value.getValue())); } else if (">=".equals(value.getOperator())) { obc.add(Restrictions.ge(value.getField(), value.getValue())); } else { obc.add(Restrictions.eq(value.getField(), value.getValue())); } } return obc.list(); }
From source file:org.openbravo.advpaymentmngt.utility.FIN_Utility.java
License:Open Source License
/** * Generic OBCriteria.// www . ja v a 2 s. c o m * * @param clazz * Class (entity). * @param values * Value. Property, value and operator. * @return One record that satisfies the conditions. */ public static <T extends BaseOBObject> T getOneInstance(Class<T> clazz, Value... values) { OBCriteria<T> obc = OBDal.getInstance().createCriteria(clazz); obc.setFilterOnReadableClients(false); obc.setFilterOnReadableOrganization(false); obc.add(Restrictions.ne(Client.PROPERTY_ID, "0")); for (Value value : values) { if (value.getValue() == null && "==".equals(value.getOperator())) { obc.add(Restrictions.isNull(value.getField())); } else if (value.getValue() == null && "!=".equals(value.getOperator())) { obc.add(Restrictions.isNotNull(value.getField())); } else if ("==".equals(value.getOperator())) { obc.add(Restrictions.eq(value.getField(), value.getValue())); } else if ("!=".equals(value.getOperator())) { obc.add(Restrictions.ne(value.getField(), value.getValue())); } else if ("<".equals(value.getOperator())) { obc.add(Restrictions.lt(value.getField(), value.getValue())); } else if (">".equals(value.getOperator())) { obc.add(Restrictions.gt(value.getField(), value.getValue())); } else if ("<=".equals(value.getOperator())) { obc.add(Restrictions.le(value.getField(), value.getValue())); } else if (">=".equals(value.getOperator())) { obc.add(Restrictions.ge(value.getField(), value.getValue())); } else { obc.add(Restrictions.eq(value.getField(), value.getValue())); } } final List<T> listt = obc.list(); if (listt != null && listt.size() > 0) { return listt.get(0); } else { return null; } }
From source file:org.openbravo.client.application.event.AcctSchemaEventHandler.java
License:Open Source License
private Element getAccountElement(AcctSchema acctSchema) { final String ELEMENTTYPE_ACCOUNT = "AC"; OBCriteria<AcctSchemaElement> aee = OBDal.getInstance().createCriteria(AcctSchemaElement.class); aee.add(Restrictions.eq(AcctSchemaElement.PROPERTY_ACCOUNTINGSCHEMA, acctSchema)); aee.add(Restrictions.isNotNull(AcctSchemaElement.PROPERTY_ACCOUNTINGELEMENT)); aee.add(Restrictions.eq(AcctSchemaElement.PROPERTY_TYPE, ELEMENTTYPE_ACCOUNT)); aee.setMaxResults(1);//from w w w . ja va 2 s. c o m List<AcctSchemaElement> aees = aee.list(); if (aees.size() > 0) { return aees.get(0).getAccountingElement(); } else { return null; } }
From source file:org.openbravo.costing.CostingUtils.java
License:Open Source License
/** * Calculates the standard cost definition of a product on the given date and cost dimensions. * //from w w w .j ava2 s .co m * @param product * The Product to get its Standard Cost * @param date * The Date to get the Standard Cost * @param costDimensions * The cost dimensions to get the Standard Cost if it is defined by some of them. * @param recheckWithoutDimensions * boolean flag to force a recall the method to get the Standard Cost at client level if * no cost is found in the given cost dimensions. * @return the Standard Cost. Null when no definition is found. */ public static Costing getStandardCostDefinition(Product product, Organization org, Date date, HashMap<CostDimension, BaseOBObject> costDimensions, boolean recheckWithoutDimensions, String costtype) { // Get cost from M_Costing for given date. OBCriteria<Costing> obcCosting = OBDal.getInstance().createCriteria(Costing.class); obcCosting.add(Restrictions.eq(Costing.PROPERTY_PRODUCT, product)); obcCosting.add(Restrictions.le(Costing.PROPERTY_STARTINGDATE, date)); obcCosting.add(Restrictions.gt(Costing.PROPERTY_ENDINGDATE, date)); obcCosting.add(Restrictions.eq(Costing.PROPERTY_COSTTYPE, costtype)); obcCosting.add(Restrictions.isNotNull(Costing.PROPERTY_COST)); if (costDimensions.get(CostDimension.Warehouse) != null) { obcCosting .add(Restrictions.eq(Costing.PROPERTY_WAREHOUSE, costDimensions.get(CostDimension.Warehouse))); } obcCosting.add(Restrictions.eq(Costing.PROPERTY_ORGANIZATION, org)); obcCosting.setFilterOnReadableOrganization(false); if (obcCosting.count() > 0) { if (obcCosting.count() > 1) { log4j.warn("More than one cost found for same date: " + OBDateUtils.formatDate(date) + " for product: " + product.getName() + " (" + product.getId() + ")"); } return obcCosting.list().get(0); } else if (recheckWithoutDimensions) { return getStandardCostDefinition(product, org, date, getEmptyDimensions(), false); } return null; }
From source file:org.openbravo.erpCommon.ad_actionButton.CreateStandards.java
License:Open Source License
private void copyAttributes(ConnectionProvider conn, VariablesSecureApp vars, ProductionPlan productionPlan) throws Exception { try {// w w w . java 2 s. c o m OBContext.setAdminMode(true); // if phase does not exist do nothing. if (productionPlan.getWRPhase() == null || productionPlan.getWRPhase().getMASequence() == null) { return; } // loop production lines for (OperationProduct opProduct : productionPlan.getWRPhase().getMASequence() .getManufacturingOperationProductList()) { // only production type + and has attset and has attlist if (opProduct.getProductionType() == null || !opProduct.getProductionType().equals("+") || opProduct.getManufacturingOperationProductAttributeList().isEmpty() || opProduct.getProduct() == null || opProduct.getProduct().getAttributeSet() == null) { continue; } // new Attribute AttributeSetInstanceValue attSetInstanceTo = new AttributeSetInstanceValue(); HashMap<String, String> attValues = new HashMap<String, String>(); // loop attributes for (OperationProductAttribute opProductAtt : opProduct .getManufacturingOperationProductAttributeList()) { // check attFrom exists AttributeSetInstance attSetInstanceFrom = null; OBCriteria<ProductionLine> productionLineCriteria = OBDal.getInstance() .createCriteria(ProductionLine.class); productionLineCriteria .add(Restrictions.eq(ProductionLine.PROPERTY_PRODUCTIONPLAN, productionPlan)); productionLineCriteria.add(Restrictions.isNotNull(ProductionLine.PROPERTY_ATTRIBUTESETVALUE)); productionLineCriteria.createAlias(ProductionLine.PROPERTY_WRPRODUCTPHASE, "wrpp"); productionLineCriteria .add(Restrictions.eq("wrpp." + WorkRequirementProduct.PROPERTY_SEQUENCEPRODUCT, opProductAtt.getProductFrom())); List<ProductionLine> plinesToCopyFrom = productionLineCriteria.list(); if (!plinesToCopyFrom.isEmpty()) { attSetInstanceFrom = plinesToCopyFrom.get(0).getAttributeSetValue(); } if (attSetInstanceFrom != null && !attSetInstanceFrom.getId().equals("0")) { if (opProductAtt.isSpecialatt()) { // special att // lot if (opProductAtt.getSpecialatt().equals(lotSearchKey)) { if (opProductAtt.isCopySpecialIntoNormal()) { attValues.put( replace(opProductAtt.getAttributeuseto().getAttribute().getName()), attSetInstanceFrom.getLotName()); } else { attSetInstanceTo.setLot(attSetInstanceFrom.getLotName()); } } // serNo if (opProductAtt.getSpecialatt().equals(serialNoSearchKey)) { if (opProductAtt.isCopySpecialIntoNormal()) { attValues.put( replace(opProductAtt.getAttributeuseto().getAttribute().getName()), attSetInstanceFrom.getSerialNo()); } else { attSetInstanceTo.setSerialNumber(attSetInstanceFrom.getSerialNo()); } } // gDate if (opProductAtt.getSpecialatt().equals(expirationDateSearchKey)) { attSetInstanceTo .setGuaranteeDate(dateToString(attSetInstanceFrom.getExpirationDate())); } } else { // normal att // check attTo exists if (opProductAtt.getAttributeuseto() != null && opProductAtt.getAttributeuseto().getAttribute() != null) { // getValue from OBCriteria<AttributeInstance> attributeInstanceCriteria = OBDal.getInstance() .createCriteria(AttributeInstance.class); attributeInstanceCriteria.add(Restrictions .eq(AttributeInstance.PROPERTY_ATTRIBUTESETVALUE, attSetInstanceFrom)); attributeInstanceCriteria.add(Restrictions.eq(AttributeInstance.PROPERTY_ATTRIBUTE, opProductAtt.getAttributeUse().getAttribute())); List<AttributeInstance> AttributeInstanceList = attributeInstanceCriteria.list(); // add value if (!AttributeInstanceList.isEmpty()) { if (AttributeInstanceList.get(0).getAttributeValue() == null) { attValues.put( replace(opProductAtt.getAttributeuseto().getAttribute().getName()), AttributeInstanceList.get(0).getSearchKey()); } else { attValues.put( replace(opProductAtt.getAttributeuseto().getAttribute().getName()), AttributeInstanceList.get(0).getAttributeValue().getId()); } } } } } } // end loop attributes // update lines OBCriteria<ProductionLine> ProductionLineCriteria = OBDal.getInstance() .createCriteria(ProductionLine.class); ProductionLineCriteria.add(Restrictions.eq(ProductionLine.PROPERTY_PRODUCTIONPLAN, productionPlan)); ProductionLineCriteria.add(Restrictions.eq(ProductionLine.PROPERTY_PRODUCTIONTYPE, "+")); ProductionLineCriteria.createAlias(ProductionLine.PROPERTY_WRPRODUCTPHASE, "wrpp"); ProductionLineCriteria .add(Restrictions.eq("wrpp." + WorkRequirementProduct.PROPERTY_SEQUENCEPRODUCT, opProduct)); List<ProductionLine> plinesToCopyTo = ProductionLineCriteria.list(); for (ProductionLine pline : plinesToCopyTo) { AttributeSet attrSet = pline.getProduct().getAttributeSet(); // create attribute if (attrSet.isExpirationDate() && (attSetInstanceTo.getGuaranteeDate() == null || attSetInstanceTo.getGuaranteeDate().equals("")) && attrSet.getGuaranteedDays() != null && attrSet.getGuaranteedDays() != 0L) { // set guaranteeDate if is not copied Date movementdate = ((productionPlan.getProductionplandate() != null) ? productionPlan.getProductionplandate() : productionPlan.getProduction().getMovementDate()); int days = attrSet.getGuaranteedDays().intValue(); attSetInstanceTo.setGuaranteeDate(dateToString(addDays(movementdate, days))); } OBError createAttributeInstanceError = attSetInstanceTo.setAttributeInstance(conn, vars, opProduct.getProduct().getAttributeSet().getId(), "", "", "Y", opProduct.getProduct().getId(), attValues); if (!createAttributeInstanceError.getType().equals("Success")) { throw new OBException(createAttributeInstanceError.getMessage()); } OBDal.getInstance().flush(); AttributeSetInstance newAttSetinstance = OBDal.getInstance().get(AttributeSetInstance.class, attSetInstanceTo.getAttSetInstanceId()); pline.setAttributeSetValue(newAttSetinstance); OBDal.getInstance().save(pline); } OBDal.getInstance().flush(); } } finally { OBContext.restorePreviousMode(); } }
From source file:org.openbravo.erpCommon.ad_forms.ModuleManagement.java
License:Open Source License
/** * Returns an HTML with the available notifications which can be: *Unapplied changes: rebuild * system *Available updates: install them *///w w w .j a v a2s .c o m private JSONObject getNotificationsJSON(String lang) { String updatesRebuildHTML = ""; JSONArray upgrades = new JSONArray(); try { String restartTomcat = ModuleManagementData.selectRestartTomcat(this); String totalToBeRebuilt = ModuleManagementData.selectRebuild(this); /* * Set rebuild now option if System is under Maintenance. Refer * https://issues.openbravo.com/view.php?id=13212 */ Boolean lastBuildFailed = false; SystemInformation sysInfo = OBDal.getInstance().get(SystemInformation.class, "0"); if (sysInfo.getSystemStatus() != null && !sysInfo.getSystemStatus().equals("RB70")) { lastBuildFailed = true; } // Check if last build was done but Tomcat wasn't restarted, // but dont show the restart tomcat message is a rebuild need to be done if (!restartTomcat.equals("0") && totalToBeRebuilt.equals("0")) { updatesRebuildHTML = "<a class=\"LabelLink_noicon\" href=\"#\" onclick=\"openServletNewWindow('TOMCAT', false, '../ad_process/ApplyModules.html', 'BUTTON', null, true, 650, 900, null, null, null, null, true);return false;\">" + Utility.messageBD(this, "Restart_Tomcat", lang) + "</a>"; } else { // Check for rebuild system if (!totalToBeRebuilt.equals("0") || lastBuildFailed) { updatesRebuildHTML = totalToBeRebuilt + " " + Utility.messageBD(this, "ApplyModules", lang) + ", <a id=\"rebuildNow\" class=\"LabelLink_noicon\" href=\"#\" onclick=\"openServletNewWindow('DEFAULT', false, '../ad_process/ApplyModules.html', 'BUTTON', null, true, 700, 900, null, null, null, null, true);return false;\">" + Utility.messageBD(this, "RebuildNow", lang) + "</a>"; } // Check for updates String message = ""; String total = ModuleManagementData.selectUpdate(this); if (!total.equals("0")) { if (!updatesRebuildHTML.isEmpty()) { updatesRebuildHTML += " / "; } if (total.equals("1")) { message = Utility.messageBD(this, "UpdateAvailable", lang).toLowerCase(); } else { message = Utility.messageBD(this, "UpdatesAvailable", lang); } updatesRebuildHTML += total + " " + message + " " + "<a class=\"LabelLink_noicon\" href=\"#\" onclick=\"installUpdate('all'); return false;\">" + Utility.messageBD(this, "InstallUpdatesNow", lang) + "</a>"; } } OBCriteria<org.openbravo.model.ad.module.Module> qUpgr = OBDal.getInstance() .createCriteria(org.openbravo.model.ad.module.Module.class); qUpgr.add(Restrictions.isNotNull(org.openbravo.model.ad.module.Module.PROPERTY_UPGRADEAVAILABLE)); for (org.openbravo.model.ad.module.Module upgr : qUpgr.list()) { JSONObject upgrade = new JSONObject(); upgrade.put("moduleId", upgr.getId()); upgrade.put("version", new JSONArray(upgr.getUpgradeAvailable())); upgrade.put("moduleName", upgr.getName()); upgrades.put(upgrade); } } catch (final Exception e) { log4j.error(e.getMessage(), e); } JSONObject rt = new JSONObject(); try { if (!updatesRebuildHTML.isEmpty()) { rt.put("updatesRebuildHTML", updatesRebuildHTML); } if (upgrades.length() != 0) { rt.put("upgrades", upgrades); } } catch (JSONException e) { log4j.error("Error genrating updates notifications", e); } return rt; }