use of org.compiere.model.MOrg in project adempiere by adempiere.
the class ImportEmployeeAttributes method fillIdValues.
// doIt
/**
* Fill mandatory information
*
* @param importEmployeeAttribute
*/
private void fillIdValues(X_I_HR_Attribute importEmployeeAttribute) {
StringBuilder messageError = new StringBuilder();
importEmployeeAttribute.setI_ErrorMsg("");
final String partnerQuery = "SELECT C_BPartner_ID FROM C_BPartner WHERE TRIM(Value) = TRIM(?)";
int partnerId = DB.getSQLValue(null, partnerQuery, importEmployeeAttribute.getValue());
if (partnerId < 0)
messageError.append("@HR_Employee_ID@ @NotFound@");
final String conceptQuery = "SELECT HR_Concept_ID FROM HR_Concept WHERE TRIM(Value) = TRIM(?)";
int conceptId = DB.getSQLValue(importEmployeeAttribute.get_TrxName(), conceptQuery, importEmployeeAttribute.getConceptValue());
if (conceptId < 0)
messageError.append(", ").append("@HR_Concept_ID@ @NotFound@");
if (importEmployeeAttribute.getValidFrom() == null)
messageError.append(", ").append("@Invalid@ @ValidFrom@");
if (messageError.length() > 0)
setImportError(importEmployeeAttribute, messageError.toString()).saveEx(importEmployeeAttribute.get_TrxName());
importEmployeeAttribute.setC_BPartner_ID(partnerId);
importEmployeeAttribute.setHR_Concept_ID(conceptId);
// For Reference
//Set Race
MHRRace race = null;
if (importEmployeeAttribute.getHR_Race_ID() > 0)
race = MHRRace.getById(getCtx(), importEmployeeAttribute.getHR_Race_ID());
if (race != null && race.getHR_Race_ID() < 0 && importEmployeeAttribute.getRaceValue() != null)
race = MHRRace.getByValue(getCtx(), importEmployeeAttribute.getRaceValue());
if (race != null && race.getHR_Race_ID() > 0)
importEmployeeAttribute.setHR_Race_ID(race.getHR_Race_ID());
//Set Organization Trx
MOrg orgTrx = null;
if (importEmployeeAttribute.getAD_OrgTrx_ID() > 0)
orgTrx = MOrg.get(getCtx(), importEmployeeAttribute.getAD_OrgTrx_ID());
if (orgTrx == null && importEmployeeAttribute.getOrgTrxValue() != null) {
int orgTrxId = getId(MOrg.Table_Name, MOrg.COLUMNNAME_Value + "=?", get_TrxName(), importEmployeeAttribute.getOrgTrxValue());
orgTrx = MOrg.get(getCtx(), orgTrxId);
}
if (orgTrx != null && orgTrx.getAD_Org_ID() > 0)
importEmployeeAttribute.setAD_OrgTrx_ID(orgTrx.getAD_Org_ID());
//Set Project
MProject project = null;
if (importEmployeeAttribute.getC_Project_ID() > 0)
project = MProject.getById(getCtx(), importEmployeeAttribute.getC_Project_ID());
if (project == null && importEmployeeAttribute.getProjectValue() != null)
project = MProject.getByValue(getCtx(), importEmployeeAttribute.getProjectValue());
if (project != null && project.getC_Project_ID() > 0)
importEmployeeAttribute.setC_Project_ID(project.getC_Project_ID());
//Set Department
MHRDepartment department = null;
if (importEmployeeAttribute.getHR_Department_ID() > 0)
department = MHRDepartment.getById(getCtx(), importEmployeeAttribute.getHR_Department_ID());
if (department == null && importEmployeeAttribute.getDepartmentValue() != null)
department = MHRDepartment.getByValue(getCtx(), importEmployeeAttribute.getDepartmentValue());
if (department != null && department.getHR_Department_ID() > 0)
importEmployeeAttribute.setHR_Department_ID(department.getHR_Department_ID());
//Set Job
MHRJob job = null;
if (importEmployeeAttribute.getHR_Job_ID() > 0)
job = MHRJob.getById(getCtx(), importEmployeeAttribute.getHR_Job_ID());
if (job == null && importEmployeeAttribute.getJobValue() != null)
job = MHRJob.getByValue(getCtx(), importEmployeeAttribute.getJobValue());
if (job != null && job.getHR_Job_ID() > 0)
importEmployeeAttribute.setHR_Job_ID(job.getHR_Job_ID());
//Set Job Education
MHRJobEducation jobEducation = null;
if (importEmployeeAttribute.getHR_JobEducation_ID() > 0)
jobEducation = new MHRJobEducation(getCtx(), importEmployeeAttribute.getHR_JobEducation_ID(), importEmployeeAttribute.get_TrxName());
if (jobEducation == null && importEmployeeAttribute.getJobEducationValue() != null)
jobEducation = MHRJobEducation.getByValue(getCtx(), importEmployeeAttribute.getJobEducationValue());
if (jobEducation != null && jobEducation.getHR_JobEducation_ID() > 0)
importEmployeeAttribute.setHR_JobEducation_ID(jobEducation.getHR_JobEducation_ID());
// Set Carrer Level
MHRCareerLevel careerLevel = null;
if (importEmployeeAttribute.getHR_CareerLevel_ID() > 0)
careerLevel = new MHRCareerLevel(getCtx(), importEmployeeAttribute.getHR_CareerLevel_ID(), importEmployeeAttribute.get_TrxName());
if (careerLevel == null && importEmployeeAttribute.getCareerLevelValue() != null)
careerLevel = MHRCareerLevel.getByValue(getCtx(), importEmployeeAttribute.getCareerLevelValue());
if (careerLevel != null && careerLevel.getHR_CareerLevel_ID() > 0)
importEmployeeAttribute.setHR_CareerLevel_ID(careerLevel.getHR_CareerLevel_ID());
// Set Job Type
MHRJobType jobType = null;
if (importEmployeeAttribute.getHR_JobType_ID() > 0)
jobType = MHRJobType.getById(getCtx(), importEmployeeAttribute.getHR_JobType_ID());
if (jobType == null && importEmployeeAttribute.getJobTypeValue() != null)
jobType = MHRJobType.getByValue(getCtx(), importEmployeeAttribute.getJobTypeValue());
if (jobType != null && jobType.getHR_JobType_ID() > 0)
importEmployeeAttribute.setHR_JobType_ID(jobType.getHR_JobType_ID());
// Set Payroll
MHRPayroll payroll = null;
if (importEmployeeAttribute.getHR_Payroll_ID() > 0)
payroll = MHRPayroll.getById(getCtx(), importEmployeeAttribute.getHR_Job_ID());
if (payroll == null && importEmployeeAttribute.getPayrollValue() != null)
payroll = MHRPayroll.getByValue(getCtx(), importEmployeeAttribute.getPayrollValue());
if (payroll != null && payroll.getHR_Payroll_ID() > 0)
importEmployeeAttribute.setHR_Payroll_ID(payroll.getHR_Payroll_ID());
// Set Activity
MActivity activity = null;
if (importEmployeeAttribute.getC_Activity_ID() > 0)
activity = MActivity.getById(getCtx(), importEmployeeAttribute.getC_Activity_ID());
if (activity == null && importEmployeeAttribute.getActivityValue() != null)
activity = MActivity.getByValue(getCtx(), importEmployeeAttribute.getActivityValue());
if (activity != null && activity.getC_Activity_ID() > 0)
importEmployeeAttribute.setC_Activity_ID(activity.getC_Activity_ID());
// Set Campaign
MCampaign campaign = null;
if (importEmployeeAttribute.getC_Campaign_ID() > 0)
campaign = MCampaign.getById(getCtx(), importEmployeeAttribute.getC_Campaign_ID());
if (campaign == null && importEmployeeAttribute.getCampaignValue() != null)
campaign = MCampaign.getByValue(getCtx(), importEmployeeAttribute.getCampaignValue());
if (campaign != null && campaign.getC_Campaign_ID() > 0)
importEmployeeAttribute.setC_Campaign_ID(campaign.getC_Campaign_ID());
// Set Work Group
MHRWorkGroup workGroup = null;
if (importEmployeeAttribute.getHR_WorkGroup_ID() > 0)
workGroup = MHRWorkGroup.getById(getCtx(), importEmployeeAttribute.getHR_WorkGroup_ID());
if (workGroup == null && importEmployeeAttribute.getWorkGroupValue() != null)
workGroup = MHRWorkGroup.getByValue(getCtx(), importEmployeeAttribute.getWorkGroupValue());
if (workGroup != null && workGroup.getHR_WorkGroup_ID() > 0)
importEmployeeAttribute.setHR_WorkGroup_ID(workGroup.getHR_WorkGroup_ID());
// Set Shift Group
MHRShiftGroup shiftGroup = null;
if (importEmployeeAttribute.getHR_ShiftGroup_ID() > 0)
shiftGroup = MHRShiftGroup.getById(getCtx(), importEmployeeAttribute.getHR_WorkGroup_ID());
if (shiftGroup == null && importEmployeeAttribute.getShiftGroupValue() != null)
shiftGroup = MHRShiftGroup.getByValue(getCtx(), importEmployeeAttribute.getWorkGroupValue());
if (shiftGroup != null && shiftGroup.getHR_ShiftGroup_ID() > 0)
importEmployeeAttribute.setHR_ShiftGroup_ID(shiftGroup.getHR_ShiftGroup_ID());
// Set Degree
MHRDegree degree = null;
if (importEmployeeAttribute.getHR_Degree_ID() > 0)
degree = MHRDegree.getById(getCtx(), importEmployeeAttribute.getHR_Degree_ID());
if (degree == null && importEmployeeAttribute.getDegreeValue() != null)
degree = MHRDegree.getByValue(getCtx(), importEmployeeAttribute.getDegreeValue());
// Set it
if (degree != null && degree.getHR_Degree_ID() > 0)
importEmployeeAttribute.setHR_Degree_ID(degree.getHR_Degree_ID());
// Set Grade
MHRGrade grade = null;
if (importEmployeeAttribute.getHR_Grade_ID() > 0)
grade = MHRGrade.getById(getCtx(), importEmployeeAttribute.getHR_Grade_ID());
if (grade == null && importEmployeeAttribute.getGradeValue() != null)
grade = MHRGrade.getByValue(getCtx(), importEmployeeAttribute.getGradeValue());
if (grade != null && grade.getHR_Grade_ID() > 0)
importEmployeeAttribute.setHR_Grade_ID(grade.getHR_Grade_ID());
//Set Designation
MHRDesignation designation = null;
if (importEmployeeAttribute.getHR_Designation_ID() > 0)
designation = MHRDesignation.getById(getCtx(), importEmployeeAttribute.getHR_Designation_ID());
if (designation == null && importEmployeeAttribute.getDesignationValue() != null)
designation = MHRDesignation.getByValue(getCtx(), importEmployeeAttribute.getDesignationValue());
if (designation != null && designation.getHR_Designation_ID() > 0)
importEmployeeAttribute.setHR_Designation_ID(designation.getHR_Designation_ID());
//Set Salary Structure
MHRSalaryStructure salaryStructure = null;
if (importEmployeeAttribute.getHR_SalaryRange_ID() > 0)
salaryStructure = MHRSalaryStructure.getById(getCtx(), importEmployeeAttribute.getHR_SalaryStructure_ID());
if (salaryStructure == null && importEmployeeAttribute.getSalaryStructureValue() != null)
salaryStructure = MHRSalaryStructure.getByValue(getCtx(), importEmployeeAttribute.getSalaryStructureValue());
if (salaryStructure != null && salaryStructure.getHR_SalaryStructure_ID() > 0)
importEmployeeAttribute.setHR_SalaryRange_ID(salaryStructure.getHR_SalaryStructure_ID());
//Set Salary Range
MHRSalaryRange salaryRange = null;
if (importEmployeeAttribute.getHR_SalaryRange_ID() > 0)
salaryRange = MHRSalaryRange.getById(getCtx(), importEmployeeAttribute.getHR_SalaryRange_ID());
if (salaryRange == null && importEmployeeAttribute.getSalaryRangeValue() != null)
salaryRange = MHRSalaryRange.getByValue(getCtx(), importEmployeeAttribute.getSalaryRangeValue());
if (salaryRange != null && salaryRange.getHR_SalaryRange_ID() > 0)
importEmployeeAttribute.setHR_SalaryRange_ID(salaryRange.getHR_SalaryRange_ID());
// Set Employee Type
MHREmployeeType employeeType = null;
if (importEmployeeAttribute.getHR_EmployeeType_ID() > 0)
employeeType = MHREmployeeType.getById(getCtx(), importEmployeeAttribute.getHR_EmployeeType_ID());
if (employeeType == null && importEmployeeAttribute.getEmployeeTypeValue() != null)
employeeType = MHREmployeeType.getByValue(getCtx(), importEmployeeAttribute.getEmployeeTypeValue());
if (employeeType != null && employeeType.getHR_EmployeeType_ID() > 0)
importEmployeeAttribute.setHR_EmployeeType_ID(employeeType.getHR_EmployeeType_ID());
// Set Skill Type
MHRSkillType skillType = null;
if (importEmployeeAttribute.getHR_SkillType_ID() > 0)
skillType = MHRSkillType.getById(getCtx(), importEmployeeAttribute.getHR_SkillType_ID());
if (skillType == null && importEmployeeAttribute.getSkillTypeValue() != null)
skillType = MHRSkillType.getByValue(getCtx(), importEmployeeAttribute.getSkillTypeValue());
if (skillType != null && skillType.getHR_SkillType_ID() > 0)
importEmployeeAttribute.setHR_SkillType_ID(skillType.getHR_SkillType_ID());
//
importEmployeeAttribute.saveEx();
}
use of org.compiere.model.MOrg in project adempiere by adempiere.
the class MRP method doIt.
protected String doIt() throws Exception {
parameters = new ArrayList<Object>();
dd_order_id_cache.clear();
partner_cache.clear();
StringBuffer whereClause = new StringBuffer(MResource.COLUMNNAME_ManufacturingResourceType + "=? AND AD_Client_ID=?");
parameters.add(MResource.MANUFACTURINGRESOURCETYPE_Plant);
parameters.add(getAD_Client_ID());
if (getPlant_ID() > 0) {
whereClause.append(" AND " + MResource.COLUMNNAME_S_Resource_ID + "=?");
parameters.add(getPlant_ID());
}
List<MResource> plants = new Query(getCtx(), MResource.Table_Name, whereClause.toString(), get_TrxName()).setParameters(parameters).list();
if (plants == null || plants.size() <= 0)
return MRefList.getListName(getCtx(), MResource.MANUFACTURINGRESOURCETYPE_AD_Reference_ID, "PT") + " @S_Resource_ID@ @NotFound@";
for (MResource plant : plants) {
log.info("Run MRP to Plant: " + plant.getName());
this.Planning_Horizon = TimeUtil.addDays(getToday(), plant.getPlanningHorizon());
parameters = new ArrayList<Object>();
whereClause = new StringBuffer("AD_Client_ID=?");
parameters.add(getAD_Client_ID());
if (getAD_Org_ID() > 0) {
whereClause.append(" AND AD_Org_ID=?");
parameters.add(getAD_Org_ID());
}
List<MOrg> orgList = new Query(getCtx(), MOrg.Table_Name, whereClause.toString(), get_TrxName()).setParameters(parameters).list();
for (MOrg org : orgList) {
// Set Default Document Type To Requisition
int AD_User_ID = Env.getAD_User_ID(getCtx());
docTypeReq_ID = MPPMRP.getDocType(getCtx(), MDocType.DOCBASETYPE_PurchaseRequisition, org.getAD_Org_ID(), AD_User_ID, get_TrxName());
docTypeMO_ID = MPPMRP.getDocType(getCtx(), MDocType.DOCBASETYPE_ManufacturingOrder, org.getAD_Org_ID(), AD_User_ID, get_TrxName());
docTypeMF_ID = MPPMRP.getDocType(getCtx(), MDocType.DOCBASETYPE_MaintenanceOrder, org.getAD_Org_ID(), AD_User_ID, get_TrxName());
docTypeDO_ID = MPPMRP.getDocType(getCtx(), MDocType.DOCBASETYPE_DistributionOrder, org.getAD_Org_ID(), AD_User_ID, get_TrxName());
log.info("Run MRP to Organization: " + org.getName());
MWarehouse[] ws;
if (getM_Warehouse_ID() <= 0) {
ws = MWarehouse.getForOrg(getCtx(), org.getAD_Org_ID());
} else {
ws = new MWarehouse[] { MWarehouse.get(getCtx(), getM_Warehouse_ID()) };
}
//
for (MWarehouse w : ws) {
// remove using DRP should be executed
//if(plant.getM_Warehouse_ID() == w.getM_Warehouse_ID() && isRequiredDRP())
// continue;
log.info("Run MRP to Wharehouse: " + w.getName());
runMRP(getAD_Client_ID(), org.getAD_Org_ID(), plant.getS_Resource_ID(), w.getM_Warehouse_ID());
StringBuffer resultMsg = new StringBuffer();
resultMsg.append("<br> <b> @AD_Org_ID@: </b>" + org.getName());
resultMsg.append("<b>, @M_Warehouse_ID@: </b>" + w.getName());
resultMsg.append("<b>, @S_Resource_ID@: </b>" + plant.getName());
resultMsg.append("<hr>");
resultMsg.append("<br><b>@PP_Order_ID@:</b> " + count_MO);
resultMsg.append("<br><b>@DD_Order_ID@:</b> " + count_DO);
resultMsg.append("<br><b>@M_Requisition_ID@:</b> " + count_MR);
resultMsg.append("<br><b>@AD_Note_ID@:</b> " + count_Msg);
count_MO = 0;
count_MR = 0;
count_DO = 0;
count_Msg = 0;
addLog("");
addLog(resultMsg.toString());
}
//resultMsg.append("<br>finish MRP to Organization " +org.getName());
}
}
//
return "";
}
use of org.compiere.model.MOrg in project adempiere by adempiere.
the class MRP method createDDOrder.
protected void createDDOrder(int AD_Org_ID, int PP_MRP_ID, MProduct product, BigDecimal QtyPlanned, Timestamp DemandDateStartSchedule, String trxName) throws AdempiereException, SQLException {
//TODO vpj-cd I need to create logic for DRP-040 Shipment Due Action Notice
//Indicates that a shipment for a Order Distribution is due.
// Action should be taken at the source warehouse to ensure that the order is received on time.
//TODO vpj-cd I need to create logic for DRP-050 Shipment Pas Due Action Notice
//Indicates that a shipment for a Order Distribution is past due. You should either delay the orders created the requirement for the product
//or expedite them when the product does arrive.
//Setting DRP Change net Update out the model validator
MPPMRP.setIsRequired(m_product_planning, MPPProductPlanning.COLUMNNAME_IsRequiredDRP, false, trxName);
if (m_product_planning.getDD_NetworkDistribution_ID() == 0) {
//Indicates that the Product Planning Data for this product does not specify a valid network distribution.
createMRPNote("DRP-060", AD_Org_ID, PP_MRP_ID, product, (String) null, null, null, trxName);
}
//TODO: Create functionality for Valid form and Valid To for an Network Distribution
MDDNetworkDistribution network = MDDNetworkDistribution.get(getCtx(), m_product_planning.getDD_NetworkDistribution_ID());
MDDNetworkDistributionLine[] network_lines = network.getLines(m_product_planning.getM_Warehouse_ID());
int M_Shipper_ID = 0;
MDDOrder order = null;
Integer DD_Order_ID = 0;
for (MDDNetworkDistributionLine network_line : network_lines) {
if (network_line.getM_Shipper_ID() == 0) {
String comment = Msg.translate(getCtx(), MDDNetworkDistribution.COLUMNNAME_Name) + " : " + network.getName();
createMRPNote("DRP-030", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
continue;
}
//get supply source warehouse and locator
MWarehouse source = new MWarehouse(getCtx(), network_line.getM_WarehouseSource_ID(), trxName);
MLocator locator = MLocator.getDefault(source);
if (locator == null || locator.getM_Locator_ID() <= 0) {
String comment = Msg.translate(getCtx(), " @M_Locator_ID@ @Default@ @NotFound@ @To@ ") + source.getName();
createMRPNote("DRP-001", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
continue;
}
//get supply target warehouse and locator
MWarehouse target = new MWarehouse(getCtx(), network_line.getM_Warehouse_ID(), trxName);
MLocator locator_to = MLocator.getDefault(target);
if (locator_to == null || locator_to.getM_Locator_ID() <= 0) {
String comment = Msg.translate(getCtx(), " @M_Locator_ID@ @Default@ @NotFound@ @To@ ") + source.getName();
createMRPNote("DRP-001", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
continue;
}
//get the transfer time
BigDecimal transferTime = network_line.getTransferTime();
if (transferTime.compareTo(Env.ZERO) <= 0) {
transferTime = m_product_planning.getTransferTime();
}
if (locator == null || locator_to == null) {
String comment = Msg.translate(getCtx(), MDDNetworkDistributionLine.COLUMNNAME_M_WarehouseSource_ID) + " : " + source.getName();
createMRPNote("DRP-001", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
continue;
}
//get the warehouse in transit
MWarehouse[] wsts = MWarehouse.getInTransitForOrg(getCtx(), source.getAD_Org_ID());
if (wsts == null || wsts.length == 0) {
String comment = Msg.translate(getCtx(), MOrg.COLUMNNAME_Name) + " : " + MOrg.get(getCtx(), AD_Org_ID).getName();
createMRPNote("DRP-010", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
continue;
}
if (M_Shipper_ID != network_line.getM_Shipper_ID()) {
//Org Must be linked to BPartner
MOrg org = MOrg.get(getCtx(), locator_to.getAD_Org_ID());
int C_BPartner_ID = org.getLinkedC_BPartner_ID(trxName);
if (C_BPartner_ID == 0) {
String comment = Msg.translate(getCtx(), MOrg.COLUMNNAME_Name) + " : " + MOrg.get(getCtx(), AD_Org_ID).getName();
createMRPNote("DRP-020", AD_Org_ID, PP_MRP_ID, product, null, null, comment, trxName);
continue;
}
MBPartner bp = getBPartner(C_BPartner_ID);
// Try found some order with Shipper , Business Partner and Doc Status = Draft
// Consolidate the demand in a single order for each Shipper , Business Partner , DemandDateStartSchedule
DD_Order_ID = getDDOrder_ID(AD_Org_ID, wsts[0].get_ID(), network_line.getM_Shipper_ID(), bp.getC_BPartner_ID(), TimeUtil.getDay(DemandDateStartSchedule.getTime()), trxName);
if (DD_Order_ID <= 0) {
order = new MDDOrder(getCtx(), 0, trxName);
order.setAD_Org_ID(target.getAD_Org_ID());
order.setC_BPartner_ID(C_BPartner_ID);
order.setAD_User_ID(bp.getPrimaryAD_User_ID());
order.setC_DocType_ID(docTypeDO_ID);
order.setM_Warehouse_ID(wsts[0].get_ID());
order.setDocAction(MDDOrder.DOCACTION_Complete);
order.setDateOrdered(TimeUtil.addDays(DemandDateStartSchedule, (m_product_planning.getDeliveryTime_Promised().add(transferTime)).negate().intValueExact()));
order.setDatePromised(DemandDateStartSchedule);
order.setM_Shipper_ID(network_line.getM_Shipper_ID());
order.setIsInDispute(false);
order.setIsInTransit(false);
order.setSalesRep_ID(m_product_planning.getPlanner_ID());
order.setProcessed(false);
order.setProcessing(false);
order.saveEx();
order.addDescription(Msg.parseTranslation(getCtx(), "@DD_Order_ID@ @DocumentNo@ " + order.getDocumentNo() + " @Generate@ @from@ " + getName()));
order.saveEx();
DD_Order_ID = order.get_ID();
String key = order.getAD_Org_ID() + "#" + order.getM_Warehouse_ID() + "#" + network_line.getM_Shipper_ID() + "#" + C_BPartner_ID + "#" + TimeUtil.getDay(DemandDateStartSchedule.getTime()) + "DR";
dd_order_id_cache.put(key, DD_Order_ID);
} else {
order = new MDDOrder(getCtx(), DD_Order_ID, trxName);
}
M_Shipper_ID = network_line.getM_Shipper_ID();
}
BigDecimal QtyOrdered = QtyPlanned.multiply(network_line.getPercent()).divide(Env.ONEHUNDRED);
MDDOrderLine oline = new MDDOrderLine(getCtx(), 0, trxName);
oline.setDD_Order_ID(order.getDD_Order_ID());
oline.setAD_Org_ID(target.getAD_Org_ID());
oline.setM_Locator_ID(locator.getM_Locator_ID());
oline.setM_LocatorTo_ID(locator_to.getM_Locator_ID());
oline.setM_Product_ID(m_product_planning.getM_Product_ID());
oline.setDateOrdered(order.getDateOrdered());
oline.setDatePromised(DemandDateStartSchedule);
oline.setQtyEntered(QtyOrdered);
oline.setQtyOrdered(QtyOrdered);
oline.setTargetQty(MPPMRP.getQtyReserved(getCtx(), target.getM_Warehouse_ID(), m_product_planning.getM_Product_ID(), DemandDateStartSchedule, trxName));
oline.setIsInvoiced(false);
oline.saveEx();
// Set Correct Dates for Plan
final String whereClause = MPPMRP.COLUMNNAME_DD_OrderLine_ID + "=?";
List<MPPMRP> mrpList = new Query(getCtx(), MPPMRP.Table_Name, whereClause, trxName).setParameters(new Object[] { oline.getDD_OrderLine_ID() }).list();
for (MPPMRP mrp : mrpList) {
mrp.setDateOrdered(getToday());
mrp.setDateOrdered(mrp.getDD_Order().getDateOrdered());
mrp.setDateStartSchedule(mrp.getDateOrdered());
mrp.setDatePromised(DemandDateStartSchedule);
mrp.setDateFinishSchedule(DemandDateStartSchedule);
mrp.saveEx();
if (MPPMRP.TYPEMRP_Supply.equals(mrp.getTypeMRP()))
supplies.put(mrp.get_ID(), mrp.getQty());
}
count_DO += 1;
}
}
use of org.compiere.model.MOrg 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);
}
}
use of org.compiere.model.MOrg in project adempiere by adempiere.
the class Allocation method getInvoiceData.
public Vector<Vector<Object>> getInvoiceData(boolean isMultiCurrency, Object date, IMiniTable invoiceTable) {
/********************************
* Load unpaid Invoices
* 1-TrxDate, 2-Value, (3-Currency, 4-InvAmt,)
* 5-ConvAmt, 6-ConvOpen, 7-ConvDisc, 8-WriteOff, 9-Applied
*
SELECT i.DateInvoiced,i.DocumentNo,i.C_Invoice_ID,c.ISO_Code,
i.GrandTotal*i.MultiplierAP "GrandTotal",
currencyConvert(i.GrandTotal*i.MultiplierAP,i.C_Currency_ID,i.C_Currency_ID,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID) "GrandTotal $",
invoiceOpen(C_Invoice_ID,C_InvoicePaySchedule_ID) "Open",
currencyConvert(invoiceOpen(C_Invoice_ID,C_InvoicePaySchedule_ID),i.C_Currency_ID,i.C_Currency_ID,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID)*i.MultiplierAP "Open $",
invoiceDiscount(i.C_Invoice_ID,SysDate,C_InvoicePaySchedule_ID) "Discount",
currencyConvert(invoiceDiscount(i.C_Invoice_ID,SysDate,C_InvoicePaySchedule_ID),i.C_Currency_ID,i.C_Currency_ID,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID)*i.Multiplier*i.MultiplierAP "Discount $",
i.MultiplierAP, i.Multiplier
FROM C_Invoice_v i INNER JOIN C_Currency c ON (i.C_Currency_ID=c.C_Currency_ID)
WHERE -- i.IsPaid='N' AND i.Processed='Y' AND i.C_BPartner_ID=1000001
*/
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
StringBuffer sql = new StringBuffer(// 1..3
"SELECT i.DateInvoiced,i.DocumentNo,i.C_Invoice_ID," + // 4..5 Orig Currency
"c.ISO_Code,i.GrandTotal*i.MultiplierAP, " + // 6 #1 Converted, #2 Date
"currencyConvert(i.GrandTotal*i.MultiplierAP,i.C_Currency_ID,?,?,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID), " + // 7 #3, #4 Converted Open
"currencyConvert(invoiceOpen(C_Invoice_ID,C_InvoicePaySchedule_ID),i.C_Currency_ID,?,?,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID)*i.MultiplierAP, " + // 8 AllowedDiscount
"currencyConvert(invoiceDiscount" + // #5, #6
"(i.C_Invoice_ID,?,C_InvoicePaySchedule_ID),i.C_Currency_ID,?,i.DateInvoiced,i.C_ConversionType_ID,i.AD_Client_ID,i.AD_Org_ID)*i.Multiplier*i.MultiplierAP," + // 9..11
"i.MultiplierAP, i.IsSoTrx, i.AD_Org_ID " + // corrected for CM/Split
"FROM C_Invoice_v i" + " INNER JOIN C_Currency c ON (i.C_Currency_ID=c.C_Currency_ID) " + "WHERE i.IsPaid='N' AND i.Processed='Y'" + // #7
" AND i.C_BPartner_ID=?");
if (!isMultiCurrency)
// #8
sql.append(" AND i.C_Currency_ID=?");
if (m_AD_Org_ID != 0)
sql.append(" AND i.AD_Org_ID=" + m_AD_Org_ID);
if (apar != null && !apar.equals(APAR_A)) {
sql.append(" AND i.IsSoTrx='" + (apar.equals(APAR_R) ? "Y" : "N") + "'");
}
sql.append(" ORDER BY i.DateInvoiced, i.DocumentNo");
log.fine("InvSQL=" + sql.toString());
// role security
sql = new StringBuffer(MRole.getDefault(Env.getCtx(), false).addAccessSQL(sql.toString(), "i", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO));
try {
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, m_C_Currency_ID);
pstmt.setTimestamp(2, (Timestamp) date);
pstmt.setInt(3, m_C_Currency_ID);
pstmt.setTimestamp(4, (Timestamp) date);
pstmt.setTimestamp(5, (Timestamp) date);
pstmt.setInt(6, m_C_Currency_ID);
pstmt.setInt(7, m_C_BPartner_ID);
if (!isMultiCurrency)
pstmt.setInt(8, m_C_Currency_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
Vector<Object> line = new Vector<Object>();
// 0-C_Invoice_ID
line.add(new IDColumn(rs.getInt(3)));
// 1-TrxDate
line.add(rs.getTimestamp(1));
if (// Ar/Ap
rs.getString(10).equals("Y"))
line.add("AR");
else
line.add("AP");
// 11 AD_Org_ID
int orgID = rs.getInt(11);
if (orgID == 0)
line.add("*");
else
line.add((new MOrg(Env.getCtx(), orgID, null).getName()));
KeyNamePair pp = new KeyNamePair(rs.getInt(3), rs.getString(2));
// 2-Value
line.add(pp);
if (isMultiCurrency) {
// 3-Currency
line.add(rs.getString(4));
// 4-Orig Amount
line.add(rs.getBigDecimal(5));
}
// 3/5-ConvAmt
line.add(rs.getBigDecimal(6));
BigDecimal open = rs.getBigDecimal(7);
if (// no conversion rate
open == null)
open = Env.ZERO;
// 4/6-ConvOpen
line.add(open);
BigDecimal discount = rs.getBigDecimal(8);
if (// no conversion rate
discount == null)
discount = Env.ZERO;
// 5/7-ConvAllowedDisc
line.add(discount);
// 6/8-WriteOff
line.add(Env.ZERO);
// 7/9-Applied
line.add(Env.ZERO);
// 8/10-OverUnder
line.add(open);
// Add when open <> 0 (i.e. not if no conversion rate)
if (Env.ZERO.compareTo(open) != 0)
data.add(line);
}
rs.close();
pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, sql.toString(), e);
}
return data;
}
Aggregations