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);
}
}
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;
}
use of org.compiere.model.MBPartner in project adempiere by adempiere.
the class ImportPayrollMovements method fillIdValues.
// doIt
/**
* Fill mandatory information
*
* @param importPayrollMovement
*/
private void fillIdValues(X_I_HR_Movement importPayrollMovement) {
StringBuilder messageError = new StringBuilder();
importPayrollMovement.setI_ErrorMsg("");
Integer processId = getId(MHRProcess.Table_Name, MHRProcess.COLUMNNAME_Name + "=?", importPayrollMovement.getProcessName());
if (processId < 0)
messageError.append("@HR_Process_ID@ @NotFound@ ");
else {
MHRProcess process = new MHRProcess(getCtx(), processId, importPayrollMovement.get_TrxName());
if (MHRProcess.DOCSTATUS_Drafted.equals(process.getDocStatus()) && MHRProcess.DOCSTATUS_InProgress.equals(process.getDocStatus()))
messageError.append("@DocStatus@ @NotValid@");
}
Integer partnerId = getId(MBPartner.Table_Name, MBPartner.COLUMNNAME_Value + "=?", importPayrollMovement.getBPartner_Value());
if (partnerId < 0)
messageError.append(", ").append("@C_BPartner_ID@ @NotFound@");
else {
MBPartner partner = new MBPartner(getCtx(), partnerId, importPayrollMovement.get_TrxName());
if (!partner.isEmployee())
messageError.append(", ").append("@IsEmployee@ @NotValid@ @C_BPartner_ID@ " + partner.getName());
}
StringBuilder whereClause = new StringBuilder("");
whereClause.append(MHRConcept.COLUMNNAME_Value).append("=? AND ").append(MHRConcept.COLUMNNAME_IsManual).append("=? AND ").append(MHRConcept.COLUMNNAME_IsActive).append("=? ");
Integer conceptId = getId(MHRConcept.Table_Name, whereClause.toString(), importPayrollMovement.getConceptValue().trim(), true, true);
if (conceptId < 0)
setImportError(importPayrollMovement, "@HR_Concept_ID@ " + importPayrollMovement.getConceptValue() + " @NotFound@").saveEx(importPayrollMovement.get_TrxName());
else {
MHRConcept concept = new MHRConcept(getCtx(), conceptId, importPayrollMovement.get_TrxName());
if (MHRConcept.TYPE_RuleEngine.equals(concept.getType()))
messageError.append(", ").append("@HR_Concept_ID@ " + concept.getName() + " @NotValid@ ");
}
if (importPayrollMovement.getValidFrom() == null)
messageError.append(", ").append("@ValidFrom@ @FillMandatory@ ");
if (importPayrollMovement.getValidTo() == null)
importPayrollMovement.setValidTo(importPayrollMovement.getValidFrom());
if (messageError != null && messageError.length() > 0)
setImportError(importPayrollMovement, messageError.toString()).saveEx(importPayrollMovement.get_TrxName());
importPayrollMovement.setHR_Process_ID(processId);
importPayrollMovement.setHR_Concept_ID(conceptId);
importPayrollMovement.setC_BPartner_ID(partnerId);
importPayrollMovement.saveEx(importPayrollMovement.get_TrxName());
}
Aggregations