Search in sources :

Example 66 with MBPartner

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

the class WebUser method load.

//	load
/**
	 * 	Load Contact
	 * 	@param AD_User_ID BP Contact
	 */
private void load(int AD_User_ID) {
    log.info("ID=" + AD_User_ID + ", AD_Client_ID=" + m_AD_Client_ID);
    String sql = "SELECT * " + "FROM AD_User " + "WHERE AD_Client_ID=?" + " AND AD_User_ID=?";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, m_AD_Client_ID);
        pstmt.setInt(2, AD_User_ID);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            m_bpc = new MUser(m_ctx, rs, null);
            log.fine("= found BPC=" + m_bpc);
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //	Password not entered
    m_passwordOK = false;
    m_loggedIn = false;
    //	Load BPartner
    if (m_bpc != null) {
        m_bp = new MBPartner(m_ctx, m_bpc.getC_BPartner_ID(), null);
        log.fine("= Found BP=" + m_bp);
    } else
        m_bp = null;
    //	Load Loacation
    if (m_bpc != null) {
        if (m_bpc.getC_BPartner_Location_ID() != 0) {
            m_bpl = new MBPartnerLocation(m_ctx, m_bpc.getC_BPartner_Location_ID(), null);
            log.fine("= Found BPL=" + m_bpl);
        } else {
            MBPartnerLocation[] bpls = m_bp.getLocations(false);
            if (bpls != null && bpls.length > 0) {
                m_bpl = bpls[0];
                log.fine("= Found BPL=" + m_bpl);
            }
        }
        if (m_bpl != null) {
            m_loc = MLocation.get(m_ctx, m_bpl.getC_Location_ID(), null);
            log.fine("= Found LOC=" + m_loc);
        } else
            m_loc = null;
    } else {
        m_bpl = null;
        m_loc = null;
    }
    //	Make sure that all entities exist
    if (m_bpc == null) {
        m_bpc = new MUser(m_ctx, 0, null);
        m_bpc.setEMail("?");
        m_bpc.setPassword("?");
    }
    if (m_bp == null) {
        //	template
        m_bp = new MBPartner(m_ctx);
        m_bp.setIsCustomer(true);
    }
    if (m_bpl == null)
        m_bpl = new MBPartnerLocation(m_bp);
    if (m_loc == null)
        m_loc = new MLocation(m_ctx, 0, null);
    //
    log.info("= " + m_bp + " - " + m_bpc);
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MBPartner(org.compiere.model.MBPartner) MUser(org.compiere.model.MUser) MLocation(org.compiere.model.MLocation) MBPartnerLocation(org.compiere.model.MBPartnerLocation)

Example 67 with MBPartner

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

the class InventoryUtil method getCreatePartner.

public static MBPartner getCreatePartner(String value) {
    Properties ctx = Env.getCtx();
    final String whereClause = MBPartner.COLUMNNAME_Value + "=?";
    MBPartner bp = new Query(ctx, I_C_BPartner.Table_Name, whereClause, null).setParameters(value).setClient_ID().firstOnly();
    if (bp == null) {
        bp = new MBPartner(ctx, 0, null);
    }
    bp.setValue(value);
    bp.setName(value);
    setGeneratedTag(bp);
    bp.setIsCustomer(true);
    bp.setIsVendor(true);
    bp.setC_BP_Group_ID(MBPGroup.getDefault(ctx).get_ID());
    bp.saveEx();
    //
    if (bp.getLocations(false).length == 0) {
        MLocation loc = new MLocation(ctx, 0, null);
        loc.saveEx();
        //
        MBPartnerLocation bpl = new MBPartnerLocation(bp);
        bpl.setC_Location_ID(loc.get_ID());
        bpl.saveEx();
    }
    return bp;
}
Also used : Query(org.compiere.model.Query) MBPartner(org.compiere.model.MBPartner) Properties(java.util.Properties) MLocation(org.compiere.model.MLocation) MBPartnerLocation(org.compiere.model.MBPartnerLocation)

Example 68 with MBPartner

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

the class ReplenishReportProduction 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 = getReplenish("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.save();
				//
				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.save();
    }
    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 69 with MBPartner

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

the class MHRProcess method setEmployee.

//	copyLinesFrom
/**
	 * Method use for testing setting the variables to execute rule
	 * @param partnerValue
	 * @param conceptValue
     */
public MHREmployee setEmployee(String partnerValue, String conceptValue) {
    MBPartner partner = MBPartner.get(getCtx(), partnerValue);
    if (partner == null)
        throw new AdempiereException("@C_BPartner_ID@ @NotFound@ " + partnerValue);
    partnerId = partner.get_ID();
    MHRConcept concept = MHRConcept.getByValue(getCtx(), conceptValue);
    if (concept == null)
        throw new AdempiereException("@HR_Concept_ID@ @NotFound@ " + conceptValue);
    payrollConceptId = concept.get_ID();
    columnType = concept.getColumnType();
    MHRPeriod payrollPeriod;
    employee = MHREmployee.getActiveEmployee(getCtx(), partnerId, null);
    if (getHR_Payroll_ID() > 0) {
        payrollId = getHR_Payroll_ID();
    }
    if (getHR_Department_ID() > 0) {
        departmentId = getHR_Department_ID();
    }
    if (getHR_Job_ID() > 0) {
        jobId = getHR_Job_ID();
    }
    if (getHR_Period_ID() > 0) {
        payrollPeriod = MHRPeriod.get(getCtx(), getHR_Period_ID());
    } else {
        payrollPeriod = new MHRPeriod(getCtx(), 0, null);
        MPeriod period = MPeriod.get(getCtx(), getDateAcct(), getAD_Org_ID());
        if (period != null) {
            payrollPeriod.setStartDate(period.getStartDate());
            payrollPeriod.setEndDate(period.getEndDate());
        } else {
            payrollPeriod.setStartDate(getDateAcct());
            payrollPeriod.setEndDate(getDateAcct());
        }
    }
    dateFrom = payrollPeriod.getStartDate();
    dateTo = payrollPeriod.getEndDate();
    // Setting Script context for calcualte rule
    scriptCtx.clear();
    scriptCtx.put("process", this);
    scriptCtx.put("_Process", getHR_Process_ID());
    scriptCtx.put("_Period", payrollPeriod.getHR_Period_ID());
    scriptCtx.put("_Payroll", getHR_Payroll_ID());
    scriptCtx.put("_PayrollValue", Optional.ofNullable(getHR_Payroll().getValue()).orElse(null));
    scriptCtx.put("_Department", getHR_Department_ID());
    logger.info("info data - " + Msg.parseTranslation(getCtx(), "@HR_Process_ID@ ") + getHR_Process_ID() + Msg.parseTranslation(getCtx(), ", @HR_Period_ID@ :") + getHR_Period_ID() + Msg.parseTranslation(getCtx(), ", @HR_Payroll_ID@ : ") + getHR_Payroll_ID() + Msg.parseTranslation(getCtx(), ", @HR_Department_ID@ : ") + getHR_Department_ID());
    scriptCtx.put("_From", dateFrom);
    scriptCtx.put("_To", dateTo);
    scriptCtx.put("_Period", payrollPeriod.getPeriodNo());
    scriptCtx.remove("_DateStart");
    scriptCtx.remove("_DateEnd");
    scriptCtx.remove("_Days");
    scriptCtx.remove("_C_BPartner_ID");
    scriptCtx.remove("_HR_Employee_ID");
    scriptCtx.put("_DateStart", employee.getStartDate());
    scriptCtx.put("_DateEnd", employee.getEndDate() == null ? TimeUtil.getDay(2999, 12, 31) : employee.getEndDate());
    scriptCtx.put("_Days", TimeUtil.getDaysBetween(payrollPeriod.getStartDate(), payrollPeriod.getEndDate()) + 1);
    scriptCtx.put("_C_BPartner_ID", employee.getC_BPartner_ID());
    scriptCtx.put("_HR_Employee_ID", employee.getHR_Employee_ID());
    scriptCtx.put("_Employee", employee);
    scriptCtx.remove("_HR_Concept_ID");
    scriptCtx.remove("_HR_Concept");
    scriptCtx.put("_HR_Concept_ID", concept.getHR_Concept_ID());
    scriptCtx.put("_HR_Concept", concept);
    scriptCtx.remove("_HR_PayrollConcept_ID");
    //m_scriptCtx.put("_HR_PayrollConcept_ID", payrollConcept.getHR_PayrollConcept_ID());
    //Define movement cache
    movements = new Hashtable<Integer, MHRMovement>();
    //Load Payroll Concept
    payrollConcepts = MHRPayrollConcept.getPayrollConcepts(this);
    //Load the Manual movement
    loadMovements(movements, employee.getC_BPartner_ID());
    //Remove movement if this is calculated this way can be calculated again
    if (!concept.isManual())
        movements.remove(concept.get_ID());
    return employee;
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) MPeriod(org.compiere.model.MPeriod) MBPartner(org.compiere.model.MBPartner)

Example 70 with MBPartner

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

the class WPOSActionMenu method executeCommand.

private void executeCommand(Command command) {
    BusyDialog waiting = new BusyDialog();
    try {
        CommandReceiver receiver = commandManager.getCommandReceivers(command.getEvent());
        if (command.getCommand() == CommandManager.GENERATE_IMMEDIATE_INVOICE && pos.getC_Order_ID() > 0 && pos.isCompleted() && !pos.isVoided()) {
            receiver.setCtx(pos.getCtx());
            receiver.setPartnerId(queryPartner.getRecord_ID());
            receiver.setOrderId(pos.getC_Order_ID());
            receiver.setPOSId(pos.getC_POS_ID());
            receiver.setBankAccountId(pos.getC_BankAccount_ID());
            MBPartner partner = MBPartner.get(pos.getCtx(), receiver.getPartnerId());
            Optional<String> taxId = Optional.ofNullable(partner.getTaxID());
            String processMessage = receiver.getName() + " @DisplayDocumentInfo@ : " + pos.getDocumentNo() + " @To@ @C_BPartner_ID@ : " + partner.getName() + " @TaxID@ : " + taxId.orElse("");
            if (FDialog.ask(pos.getWindowNo(), popupMenu, "StartProcess?", Msg.parseTranslation(pos.getCtx(), processMessage))) {
                waiting.setPage(pos.v_Panel.getPage());
                waiting.doHighlighted();
                command.execute(receiver);
                ProcessInfo processInfo = receiver.getProcessInfo();
                waiting.dispose();
                if (processInfo != null && processInfo.isError()) {
                    showError(processInfo);
                } else {
                    afterExecutionCommand(command);
                    showOkMessage(processInfo);
                    if (processInfo != null)
                        pos.setOrder(processInfo.getRecord_ID());
                    pos.refreshHeader();
                    //	Print Ticket
                    pos.printTicket();
                }
            }
        } else //Reverse The Sales Transaction
        if (command.getCommand() == CommandManager.GENERATE_REVERSE_SALES && pos.getC_Order_ID() > 0 && !pos.isReturnMaterial() && !pos.isVoided() && !pos.isClosed()) {
            receiver.setCtx(pos.getCtx());
            receiver.setOrderId(pos.getC_Order_ID());
            receiver.setPOSId(pos.getC_POS_ID());
            receiver.setPartnerId(pos.getC_BPartner_ID());
            receiver.setBankAccountId(pos.getC_BankAccount_ID());
            String processMessage = receiver.getName() + " @order.no@ : " + pos.getDocumentNo() + " @To@ @C_BPartner_ID@ : " + pos.getBPName();
            if (FDialog.ask(pos.getWindowNo(), popupMenu, "StartProcess?", Msg.parseTranslation(pos.getCtx(), processMessage))) {
                waiting.setPage(pos.v_Panel.getPage());
                waiting.doHighlighted();
                command.execute(receiver);
                ProcessInfo processInfo = receiver.getProcessInfo();
                waiting.dispose();
                if (processInfo != null && processInfo.isError()) {
                    showError(processInfo);
                } else {
                    afterExecutionCommand(command);
                    showOkMessage(processInfo);
                }
                pos.printTicket();
            }
        } else //Return product
        if (command.getCommand() == CommandManager.GENERATE_RETURN && pos.getC_Order_ID() > 0 && !pos.isReturnMaterial() && pos.isCompleted()) {
            receiver.setCtx(pos.getCtx());
            receiver.setOrderId(pos.getC_Order_ID());
            receiver.setPOSId(pos.getC_POS_ID());
            receiver.setPartnerId(pos.getC_BPartner_ID());
            receiver.setBankAccountId(pos.getC_BankAccount_ID());
            String processMessage = receiver.getName() + " @DisplayDocumentInfo@ : " + pos.getDocumentNo() + " @To@ @C_BPartner_ID@ : " + pos.getBPName();
            if (FDialog.ask(pos.getWindowNo(), popupMenu, "StartProcess?", Msg.parseTranslation(pos.getCtx(), processMessage))) {
                waiting.setPage(pos.v_Panel.getPage());
                waiting.doHighlighted();
                command.execute(receiver);
                ProcessInfo processInfo = receiver.getProcessInfo();
                waiting.dispose();
                if (processInfo != null && processInfo.isError()) {
                    showError(processInfo);
                } else {
                    afterExecutionCommand(command);
                    showOkMessage(processInfo);
                    //execute out transaction
                    if (processInfo != null && processInfo.getRecord_ID() > 0) {
                        pos.setOrder(processInfo.getRecord_ID());
                        pos.refreshHeader();
                    }
                }
            }
        } else if (command.getCommand() == CommandManager.GENERATE_WITHDRAWAL) {
            Env.setContext(pos.getCtx(), pos.getWindowNo(), "C_POS_ID", pos.getC_POS_ID());
            MBrowse browse = new MBrowse(Env.getCtx(), 50056, null);
            WBrowser browser = new WBrowser(true, pos.getWindowNo(), "", browse, "", true, "", true);
            CustomForm ff = browser.getForm();
            ff.setAttribute(org.adempiere.webui.component.Window.MODE_KEY, org.adempiere.webui.component.Window.MODE_EMBEDDED);
            ff.setAttribute(org.adempiere.webui.component.Window.INSERT_POSITION_KEY, org.adempiere.webui.component.Window.INSERT_NEXT);
            ff.setTitle(browse.getTitle());
            SessionManager.getAppDesktop().showWindow(ff);
        } else if (command.getCommand() == CommandManager.CLOSE_STATEMENT) {
            Env.setContext(pos.getCtx(), pos.getWindowNo(), "C_POS_ID", pos.getC_POS_ID());
            MBrowse browse = new MBrowse(Env.getCtx(), 50057, null);
            WBrowser browser = new WBrowser(true, pos.getWindowNo(), "", browse, "", true, "", true);
            CustomForm ff = browser.getForm();
            ff.setAttribute(org.adempiere.webui.component.Window.MODE_KEY, org.adempiere.webui.component.Window.MODE_EMBEDDED);
            ff.setAttribute(org.adempiere.webui.component.Window.INSERT_POSITION_KEY, org.adempiere.webui.component.Window.INSERT_NEXT);
            ff.setTitle(browse.getTitle());
            SessionManager.getAppDesktop().showWindow(ff);
        }
    } catch (Exception exception) {
        waiting.dispose();
        FDialog.error(pos.getWindowNo(), pos.getForm(), exception.getLocalizedMessage());
    } finally {
        waiting.dispose();
        waiting = null;
    }
}
Also used : CustomForm(org.adempiere.webui.panel.CustomForm) CommandReceiver(org.adempiere.pos.command.CommandReceiver) MBPartner(org.compiere.model.MBPartner) ProcessInfo(org.compiere.process.ProcessInfo) BusyDialog(org.adempiere.webui.apps.BusyDialog) MBrowse(org.adempiere.model.MBrowse) AdempiereException(org.adempiere.exceptions.AdempiereException) WBrowser(org.eevolution.form.WBrowser)

Aggregations

MBPartner (org.compiere.model.MBPartner)78 BigDecimal (java.math.BigDecimal)21 ResultSet (java.sql.ResultSet)14 MBPartnerLocation (org.compiere.model.MBPartnerLocation)14 AdempiereException (org.adempiere.exceptions.AdempiereException)13 MLocation (org.compiere.model.MLocation)13 MOrder (org.compiere.model.MOrder)13 PreparedStatement (java.sql.PreparedStatement)11 MOrderLine (org.compiere.model.MOrderLine)11 MUser (org.compiere.model.MUser)11 MInvoice (org.compiere.model.MInvoice)10 MOrg (org.compiere.model.MOrg)9 Query (org.compiere.model.Query)9 MWarehouse (org.compiere.model.MWarehouse)8 SQLException (java.sql.SQLException)7 MClient (org.compiere.model.MClient)7 MInvoiceLine (org.compiere.model.MInvoiceLine)7 AdempiereUserError (org.compiere.util.AdempiereUserError)7 Timestamp (java.sql.Timestamp)6 MDDOrder (org.eevolution.model.MDDOrder)6