Search in sources :

Example 41 with AdempiereUserError

use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.

the class BankStatementPayment method createPayment.

//	createPayment - Import
/**
	 * 	Create Payment for BankStatement
	 *	@param bsl bank statement Line
	 *	@return Message
	 *  @throws Exception if not successful
	 */
private String createPayment(MBankStatementLine bsl) throws Exception {
    if (bsl == null || bsl.getC_Payment_ID() != 0)
        return "--";
    log.fine(bsl.toString());
    if (bsl.getC_Invoice_ID() == 0 && bsl.getC_BPartner_ID() == 0)
        throw new AdempiereUserError("@NotFound@ @C_Invoice_ID@ / @C_BPartner_ID@");
    //
    MBankStatement bs = new MBankStatement(getCtx(), bsl.getC_BankStatement_ID(), get_TrxName());
    //
    MPayment payment = createPayment(bsl.getC_Invoice_ID(), bsl.getC_BPartner_ID(), bsl.getC_Currency_ID(), bsl.getStmtAmt(), bsl.getTrxAmt(), bs.getC_BankAccount_ID(), bsl.getStatementLineDate(), bsl.getDateAcct(), bsl.getDescription(), bsl.getAD_Org_ID());
    if (payment == null)
        throw new AdempiereSystemError("Could not create Payment");
    //	update statement
    bsl.setPayment(payment);
    bsl.saveEx();
    //
    String retString = "@C_Payment_ID@ = " + payment.getDocumentNo();
    if (payment.getOverUnderAmt().signum() != 0)
        retString += " - @OverUnderAmt@=" + payment.getOverUnderAmt();
    return retString;
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) AdempiereSystemError(org.compiere.util.AdempiereSystemError) MPayment(org.compiere.model.MPayment) MBankStatement(org.compiere.model.MBankStatement)

Example 42 with AdempiereUserError

use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.

the class ColumnSync method doIt.

//	prepare
/**
	 * 	Process
	 *	@return message
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("C_Column_ID=" + p_AD_Column_ID);
    if (p_AD_Column_ID == 0)
        throw new AdempiereUserError("@No@ @AD_Column_ID@");
    MColumn column = new MColumn(getCtx(), p_AD_Column_ID, get_TrxName());
    if (column.get_ID() == 0)
        throw new AdempiereUserError("@NotFound@ @AD_Column_ID@ " + p_AD_Column_ID);
    String sql = column.syncDatabase();
    addLog(sql);
    return sql;
}
Also used : MColumn(org.compiere.model.MColumn) AdempiereUserError(org.compiere.util.AdempiereUserError)

Example 43 with AdempiereUserError

use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.

the class ReplenishReport 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 = getReplenishDO("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.saveEx();
				//
				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.saveEx();
    }
    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 44 with AdempiereUserError

use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.

the class RegisterSystem method doIt.

//	prepare
/**
	 * 	DoIt
	 *	@return Message
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    int AD_Registration_ID = getRecord_ID();
    log.info("doIt - AD_Registration_ID=" + AD_Registration_ID);
    //	Check Ststem
    MSystem sys = MSystem.get(getCtx());
    if (sys.getName().equals("?") || sys.getName().length() < 2)
        throw new AdempiereUserError("Set System Name in System Record");
    if (sys.getUserName().equals("?") || sys.getUserName().length() < 2)
        throw new AdempiereUserError("Set User Name (as in Web Store) in System Record");
    if (sys.getPassword().equals("?") || sys.getPassword().length() < 2)
        throw new AdempiereUserError("Set Password (as in Web Store) in System Record");
    //	Registration
    M_Registration reg = new M_Registration(getCtx(), AD_Registration_ID, get_TrxName());
    //	Location
    MLocation loc = null;
    if (reg.getC_Location_ID() > 0) {
        loc = new MLocation(getCtx(), reg.getC_Location_ID(), get_TrxName());
        if (loc.getCity() == null || loc.getCity().length() < 2)
            throw new AdempiereUserError("No City in Address");
    }
    if (loc == null)
        throw new AdempiereUserError("Please enter Address with City");
    //	Create Query String
    String enc = WebEnv.ENCODING;
    //	Send GET Request
    StringBuffer urlString = new StringBuffer("http://www.adempiere.net").append("/wstore/registrationServlet?");
    //	System Info
    urlString.append("Name=").append(URLEncoder.encode(sys.getName(), enc)).append("&UserName=").append(URLEncoder.encode(sys.getUserName(), enc)).append("&Password=").append(URLEncoder.encode(sys.getPassword(), enc));
    //	Registration Info
    if (reg.getDescription() != null && reg.getDescription().length() > 0)
        urlString.append("&Description=").append(URLEncoder.encode(reg.getDescription(), enc));
    urlString.append("&IsInProduction=").append(reg.isInProduction() ? "Y" : "N");
    if (reg.getStartProductionDate() != null)
        urlString.append("&StartProductionDate=").append(URLEncoder.encode(String.valueOf(reg.getStartProductionDate()), enc));
    urlString.append("&IsAllowPublish=").append(reg.isAllowPublish() ? "Y" : "N").append("&NumberEmployees=").append(URLEncoder.encode(String.valueOf(reg.getNumberEmployees()), enc)).append("&C_Currency_ID=").append(URLEncoder.encode(String.valueOf(reg.getC_Currency_ID()), enc)).append("&SalesVolume=").append(URLEncoder.encode(String.valueOf(reg.getSalesVolume()), enc));
    if (reg.getIndustryInfo() != null && reg.getIndustryInfo().length() > 0)
        urlString.append("&IndustryInfo=").append(URLEncoder.encode(reg.getIndustryInfo(), enc));
    if (reg.getPlatformInfo() != null && reg.getPlatformInfo().length() > 0)
        urlString.append("&PlatformInfo=").append(URLEncoder.encode(reg.getPlatformInfo(), enc));
    urlString.append("&IsRegistered=").append(reg.isRegistered() ? "Y" : "N").append("&Record_ID=").append(URLEncoder.encode(String.valueOf(reg.getRecord_ID()), enc));
    //	Address
    urlString.append("&City=").append(URLEncoder.encode(loc.getCity(), enc)).append("&C_Country_ID=").append(URLEncoder.encode(String.valueOf(loc.getC_Country_ID()), enc));
    //	Statistics
    if (reg.isAllowStatistics()) {
        urlString.append("&NumClient=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM AD_Client")), enc)).append("&NumOrg=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM AD_Org")), enc)).append("&NumBPartner=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM C_BPartner")), enc)).append("&NumUser=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM AD_User")), enc)).append("&NumProduct=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM M_Product")), enc)).append("&NumInvoice=").append(URLEncoder.encode(String.valueOf(DB.getSQLValue(null, "SELECT Count(*) FROM C_Invoice")), enc));
    }
    log.fine(urlString.toString());
    //	Send it
    URL url = new URL(urlString.toString());
    StringBuffer sb = new StringBuffer();
    try {
        URLConnection uc = url.openConnection();
        InputStreamReader in = new InputStreamReader(uc.getInputStream());
        int c;
        while ((c = in.read()) != -1) sb.append((char) c);
        in.close();
    } catch (Exception e) {
        log.log(Level.SEVERE, "Connect - " + e.toString());
        throw new IllegalStateException("Cannot connect to Server - Please try later");
    }
    //
    String info = sb.toString();
    log.info("Response=" + info);
    //	Record at the end
    int index = sb.indexOf("Record_ID=");
    if (index != -1) {
        try {
            int Record_ID = Integer.parseInt(sb.substring(index + 10));
            reg.setRecord_ID(Record_ID);
            reg.setIsRegistered(true);
            reg.saveEx();
            //
            info = info.substring(0, index);
        } catch (Exception e) {
            log.log(Level.SEVERE, "Record - ", e);
        }
    }
    return info;
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) InputStreamReader(java.io.InputStreamReader) MSystem(org.compiere.model.MSystem) MLocation(org.compiere.model.MLocation) URL(java.net.URL) URLConnection(java.net.URLConnection) M_Registration(org.compiere.model.M_Registration)

Example 45 with AdempiereUserError

use of org.compiere.util.AdempiereUserError in project adempiere by adempiere.

the class ReplenishReport method fillTable.

//	prepareTable
/**
	 * 	Fill Table
	 * 	@param wh warehouse
	 */
private void fillTable(MWarehouse wh) throws Exception {
    String sql = "INSERT INTO T_Replenish " + "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, AD_Client_ID, AD_Org_ID," + " ReplenishType, Level_Min, Level_Max," + " C_BPartner_ID, Order_Min, Order_Pack, QtyToOrder, ReplenishmentCreate) " + "SELECT " + getAD_PInstance_ID() + ", r.M_Warehouse_ID, r.M_Product_ID, r.AD_Client_ID, r.AD_Org_ID," + " r.ReplenishType, r.Level_Min, r.Level_Max," + " po.C_BPartner_ID, po.Order_Min, po.Order_Pack, 0, ";
    if (p_ReplenishmentCreate == null)
        sql += "null";
    else
        sql += "'" + p_ReplenishmentCreate + "'";
    sql += " FROM M_Replenish r" + " INNER JOIN M_Product_PO po ON (r.M_Product_ID=po.M_Product_ID) " + //	Only Current Vendor
    "WHERE po.IsCurrentVendor='Y'" + " AND r.ReplenishType<>'0'" + " AND po.IsActive='Y' AND r.IsActive='Y'" + " AND r.M_Warehouse_ID=" + p_M_Warehouse_ID;
    if (p_C_BPartner_ID != 0)
        sql += " AND po.C_BPartner_ID=" + p_C_BPartner_ID;
    int no = DB.executeUpdate(sql, get_TrxName());
    log.finest(sql);
    log.fine("Insert (1) #" + no);
    if (p_C_BPartner_ID == 0) {
        sql = "INSERT INTO T_Replenish " + "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, AD_Client_ID, AD_Org_ID," + " ReplenishType, Level_Min, Level_Max," + " C_BPartner_ID, Order_Min, Order_Pack, QtyToOrder, ReplenishmentCreate) " + "SELECT " + getAD_PInstance_ID() + ", r.M_Warehouse_ID, r.M_Product_ID, r.AD_Client_ID, r.AD_Org_ID," + " r.ReplenishType, r.Level_Min, r.Level_Max," + " 0, 1, 1, 0, ";
        if (p_ReplenishmentCreate == null)
            sql += "null";
        else
            sql += "'" + p_ReplenishmentCreate + "'";
        sql += " FROM M_Replenish r " + "WHERE r.ReplenishType<>'0' AND r.IsActive='Y'" + " AND r.M_Warehouse_ID=" + p_M_Warehouse_ID + " AND NOT EXISTS (SELECT * FROM T_Replenish t " + "WHERE r.M_Product_ID=t.M_Product_ID" + " AND AD_PInstance_ID=" + getAD_PInstance_ID() + ")";
        no = DB.executeUpdate(sql, get_TrxName());
        log.fine("Insert (BP) #" + no);
    }
    sql = "UPDATE T_Replenish t SET " + "QtyOnHand = (SELECT COALESCE(SUM(QtyOnHand),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID" + " AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID)," + "QtyReserved = (SELECT COALESCE(SUM(QtyReserved),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID" + " AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID)," + "QtyOrdered = (SELECT COALESCE(SUM(QtyOrdered),0) FROM M_Storage s, M_Locator l WHERE t.M_Product_ID=s.M_Product_ID" + " AND l.M_Locator_ID=s.M_Locator_ID AND l.M_Warehouse_ID=t.M_Warehouse_ID)";
    if (p_C_DocType_ID != 0)
        sql += ", C_DocType_ID=" + p_C_DocType_ID;
    sql += " WHERE AD_PInstance_ID=" + getAD_PInstance_ID();
    no = DB.executeUpdate(sql, get_TrxName());
    if (no != 0)
        log.fine("Update #" + no);
    //	Delete inactive products and replenishments
    sql = "DELETE T_Replenish r " + "WHERE (EXISTS (SELECT * FROM M_Product p " + "WHERE p.M_Product_ID=r.M_Product_ID AND p.IsActive='N')" + " OR EXISTS (SELECT * FROM M_Replenish rr " + " WHERE rr.M_Product_ID=r.M_Product_ID AND rr.IsActive='N'" + " AND rr.M_Warehouse_ID=" + p_M_Warehouse_ID + " ))" + " AND AD_PInstance_ID=" + getAD_PInstance_ID();
    no = DB.executeUpdate(sql, get_TrxName());
    if (no != 0)
        log.fine("Delete Inactive=" + no);
    //	Ensure Data consistency
    sql = "UPDATE T_Replenish SET QtyOnHand = 0 WHERE QtyOnHand IS NULL";
    no = DB.executeUpdate(sql, get_TrxName());
    sql = "UPDATE T_Replenish SET QtyReserved = 0 WHERE QtyReserved IS NULL";
    no = DB.executeUpdate(sql, get_TrxName());
    sql = "UPDATE T_Replenish SET QtyOrdered = 0 WHERE QtyOrdered IS NULL";
    no = DB.executeUpdate(sql, get_TrxName());
    //	Set Minimum / Maximum Maintain Level
    //	X_M_Replenish.REPLENISHTYPE_ReorderBelowMinimumLevel
    sql = "UPDATE T_Replenish" + " SET QtyToOrder = CASE WHEN QtyOnHand - QtyReserved + QtyOrdered <= Level_Min " + " THEN Level_Max - QtyOnHand + QtyReserved - QtyOrdered " + " ELSE 0 END " + "WHERE ReplenishType='1'" + " AND AD_PInstance_ID=" + getAD_PInstance_ID();
    no = DB.executeUpdate(sql, get_TrxName());
    if (no != 0)
        log.fine("Update Type-1=" + no);
    //
    //	X_M_Replenish.REPLENISHTYPE_MaintainMaximumLevel
    sql = "UPDATE T_Replenish" + " SET QtyToOrder = Level_Max - QtyOnHand + QtyReserved - QtyOrdered " + "WHERE ReplenishType='2'" + " AND AD_PInstance_ID=" + getAD_PInstance_ID();
    no = DB.executeUpdate(sql, get_TrxName());
    if (no != 0)
        log.fine("Update Type-2=" + no);
    //	Minimum Order Quantity
    sql = "UPDATE T_Replenish" + " SET QtyToOrder = Order_Min " + "WHERE QtyToOrder < Order_Min" + " AND QtyToOrder > 0" + " AND AD_PInstance_ID=" + getAD_PInstance_ID();
    no = DB.executeUpdate(sql, get_TrxName());
    if (no != 0)
        log.fine("Set MinOrderQty=" + no);
    //	Even dividable by Pack
    sql = "UPDATE T_Replenish" + " SET QtyToOrder = QtyToOrder - MOD(QtyToOrder, Order_Pack) + Order_Pack " + "WHERE MOD(QtyToOrder, Order_Pack) <> 0" + " AND QtyToOrder > 0" + " AND AD_PInstance_ID=" + getAD_PInstance_ID();
    no = DB.executeUpdate(sql, get_TrxName());
    if (no != 0)
        log.fine("Set OrderPackQty=" + no);
    //	Source from other warehouse
    if (wh.getM_WarehouseSource_ID() != 0) {
        sql = "UPDATE T_Replenish" + " SET M_WarehouseSource_ID=" + wh.getM_WarehouseSource_ID() + " WHERE AD_PInstance_ID=" + getAD_PInstance_ID();
        no = DB.executeUpdate(sql, get_TrxName());
        if (no != 0)
            log.fine("Set Source Warehouse=" + no);
    }
    //	Check Source Warehouse
    sql = "UPDATE T_Replenish" + " SET M_WarehouseSource_ID = NULL " + "WHERE M_Warehouse_ID=M_WarehouseSource_ID" + " AND AD_PInstance_ID=" + getAD_PInstance_ID();
    no = DB.executeUpdate(sql, get_TrxName());
    if (no != 0)
        log.fine("Set same Source Warehouse=" + no);
    //	Custom Replenishment
    String className = wh.getReplenishmentClass();
    if (className != null && className.length() > 0) {
        //	Get Replenishment Class
        ReplenishInterface custom = null;
        try {
            Class<?> clazz = Class.forName(className);
            custom = (ReplenishInterface) clazz.newInstance();
        } catch (Exception e) {
            throw new AdempiereUserError("No custom Replenishment class " + className + " - " + e.toString());
        }
        X_T_Replenish[] replenishs = getReplenish("ReplenishType='9'");
        for (int i = 0; i < replenishs.length; i++) {
            X_T_Replenish replenish = replenishs[i];
            if (replenish.getReplenishType().equals(X_T_Replenish.REPLENISHTYPE_Custom)) {
                BigDecimal qto = null;
                try {
                    qto = custom.getQtyToOrder(wh, replenish);
                } catch (Exception e) {
                    log.log(Level.SEVERE, custom.toString(), e);
                }
                if (qto == null)
                    qto = Env.ZERO;
                replenish.setQtyToOrder(qto);
                replenish.saveEx();
            }
        }
    }
    //	Delete rows where nothing to order
    sql = "DELETE T_Replenish " + "WHERE QtyToOrder < 1" + " AND AD_PInstance_ID=" + getAD_PInstance_ID();
    no = DB.executeUpdate(sql, get_TrxName());
    if (no != 0)
        log.fine("Delete No QtyToOrder=" + no);
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) ReplenishInterface(org.compiere.util.ReplenishInterface) X_T_Replenish(org.compiere.model.X_T_Replenish) BigDecimal(java.math.BigDecimal)

Aggregations

AdempiereUserError (org.compiere.util.AdempiereUserError)62 PreparedStatement (java.sql.PreparedStatement)9 BigDecimal (java.math.BigDecimal)8 Timestamp (java.sql.Timestamp)8 AdempiereSystemError (org.compiere.util.AdempiereSystemError)8 ResultSet (java.sql.ResultSet)7 MBPartner (org.compiere.model.MBPartner)7 MClient (org.compiere.model.MClient)5 MWarehouse (org.compiere.model.MWarehouse)5 MProduct (org.compiere.model.MProduct)4 ValueNamePair (org.compiere.util.ValueNamePair)4 MUser (org.compiere.model.MUser)3 X_T_Replenish (org.compiere.model.X_T_Replenish)3 MPrintFormat (org.compiere.print.MPrintFormat)3 File (java.io.File)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 MAcctSchema (org.compiere.model.MAcctSchema)2 MBPartnerLocation (org.compiere.model.MBPartnerLocation)2 MColumn (org.compiere.model.MColumn)2 MCommission (org.compiere.model.MCommission)2