use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class MPPOrderBOMLine method reserveStock.
/**
* Reserve Inventory for this BOM Line
*/
protected void reserveStock() {
final int header_M_Warehouse_ID = getParent().getM_Warehouse_ID();
// Check/set WH/Org
if (// enforce WH
header_M_Warehouse_ID != 0) {
if (header_M_Warehouse_ID != getM_Warehouse_ID())
setM_Warehouse_ID(header_M_Warehouse_ID);
if (getAD_Org_ID() != getAD_Org_ID())
setAD_Org_ID(getAD_Org_ID());
}
//
final BigDecimal target = getQtyRequired();
final BigDecimal difference = target.subtract(getQtyReserved()).subtract(getQtyDelivered());
log.fine("Line=" + getLine() + " - Target=" + target + ",Difference=" + difference + " - Requiered=" + getQtyRequired() + ",Reserved=" + getQtyReserved() + ",Delivered=" + getQtyDelivered());
if (difference.signum() == 0) {
return;
}
// Check Product - Stocked and Item
MProduct product = getM_Product();
if (!product.isStocked()) {
return;
}
BigDecimal reserved = difference;
int M_Locator_ID = getM_Locator_ID(reserved);
// Update Storage
if (!MStorage.add(getCtx(), getM_Warehouse_ID(), M_Locator_ID, getM_Product_ID(), getM_AttributeSetInstance_ID(), getM_AttributeSetInstance_ID(), Env.ZERO, reserved, Env.ZERO, get_TrxName())) {
throw new AdempiereException();
}
// update line
setQtyReserved(getQtyReserved().add(difference));
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class PayrollProcessing method doIt.
@Override
protected String doIt() throws Exception {
if (m_HR_Process_ID <= 0)
throw new FillMandatoryException(PARAM_HR_Process_ID);
MHRProcess process = new MHRProcess(getCtx(), m_HR_Process_ID, get_TrxName());
long start = System.currentTimeMillis();
boolean ok = process.processIt(MHRProcess.ACTION_Complete);
process.saveEx();
if (!ok) {
throw new AdempiereException(process.getProcessMsg());
}
return "@Processed@ " + process.getName() + " - " + (System.currentTimeMillis() - start) + "ms";
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class MHRProcess method prepareIt.
// invalidateIt
/**************************************************************************
* Prepare Document
* @return new status (In Progress or Invalid)
*/
public String prepareIt() {
logger.info("prepareIt - " + toString());
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_PREPARE);
if (m_processMsg != null)
return DocAction.STATUS_Invalid;
reActivateIt();
// Std Period open?
MHRPeriod period = MHRPeriod.get(getCtx(), getHR_Period_ID());
MPeriod.testPeriodOpen(getCtx(), getHR_Period_ID() > 0 ? period.getDateAcct() : getDateAcct(), getC_DocTypeTarget_ID(), getAD_Org_ID());
// New or in Progress/Invalid
if (DOCSTATUS_Drafted.equals(getDocStatus()) || DOCSTATUS_InProgress.equals(getDocStatus()) || DOCSTATUS_Invalid.equals(getDocStatus()) || getC_DocType_ID() == 0) {
setC_DocType_ID(getC_DocTypeTarget_ID());
}
try {
createMovements();
} catch (Exception exception) {
deleteMovements();
throw new AdempiereException(exception);
}
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_AFTER_PREPARE);
if (m_processMsg != null)
return DocAction.STATUS_Invalid;
//
m_justPrepared = true;
if (!DOCACTION_Complete.equals(getDocAction()))
setDocAction(DOCACTION_Complete);
return DocAction.STATUS_InProgress;
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class MHRProcess method calculateMovements.
/**
* Calaculate Movements
* @param partner
* @param payrollPeriod
*/
private void calculateMovements(MBPartner partner, MHRPeriod payrollPeriod) {
logger.info(Msg.parseTranslation(getCtx(), "@HR_Employee_ID@ # ") + Msg.parseTranslation(getCtx(), " @BPValue@ ") + partner.getValue() + Msg.parseTranslation(getCtx(), " @BPName@ ") + partner.getName() + " " + partner.getName2());
partnerId = partner.get_ID();
employee = MHREmployee.getActiveEmployee(getCtx(), partnerId, null);
String employeePayrollValue = null;
if (employee.getHR_Payroll_ID() != 0) {
MHRPayroll employeePayroll = MHRPayroll.getById(getCtx(), employee.getHR_Payroll_ID());
employeePayrollValue = employeePayroll.getValue();
}
Timestamp employeeValidFrom = dateFrom;
Timestamp employeeValidTo = dateTo;
// Valid from for employee
if (employee.getStartDate() != null && dateFrom != null && employee.getStartDate().getTime() > dateFrom.getTime()) {
employeeValidFrom = employee.getStartDate();
}
// Valid to for employee
if (employee.getEndDate() != null && dateTo != null && employee.getEndDate().getTime() < dateTo.getTime()) {
employeeValidTo = employee.getEndDate();
}
scriptCtx.remove("_DateStart");
scriptCtx.remove("_DateEnd");
scriptCtx.remove("_Days");
scriptCtx.remove("_C_BPartner_ID");
scriptCtx.remove("_HR_Employee_ID");
scriptCtx.remove("_C_BPartner");
scriptCtx.remove("_HR_Employee");
scriptCtx.remove("_HR_Employee_ValidFrom");
scriptCtx.remove("_HR_Employee_ValidTo");
scriptCtx.remove("_HR_Employee_Payroll_Value");
scriptCtx.put("_DateStart", employee.getStartDate());
scriptCtx.put("_DateEnd", employee.getEndDate() == null ? dateTo == null ? getDateAcct() : dateTo : employee.getEndDate());
scriptCtx.put("_Days", TimeUtil.getDaysBetween(payrollPeriod.getStartDate(), payrollPeriod.getEndDate()) + 1);
scriptCtx.put("_C_BPartner_ID", partner.getC_BPartner_ID());
scriptCtx.put("_HR_Employee_ID", employee.getHR_Employee_ID());
scriptCtx.put("_C_BPartner", partner);
scriptCtx.put("_HR_Employee", employee);
scriptCtx.put("_HR_Employee_Payroll_Value", employeePayrollValue);
// Get Employee valid from and to
scriptCtx.put("_HR_Employee_ValidFrom", employeeValidFrom);
scriptCtx.put("_HR_Employee_ValidTo", employeeValidTo);
//
if (getHR_Period_ID() > 0) {
createCostCollectorMovements(partner.get_ID(), payrollPeriod);
}
// Clear movements
movements.clear();
loadMovements(movements, partnerId);
//
for (// ==================================================== Concept
MHRPayrollConcept payrollConcept : // ==================================================== Concept
payrollConcepts) {
payrollConceptId = payrollConcept.getHR_Concept_ID();
MHRConcept concept = MHRConcept.get(getCtx(), payrollConceptId);
boolean printed = payrollConcept.isPrinted() || concept.isPrinted();
// as it's now recursive, it can happen that the concept is already generated
MHRMovement movement = movements.get(concept.get_ID());
if (movement == null) {
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");
scriptCtx.put("_HR_PayrollConcept_ID", payrollConcept.getHR_PayrollConcept_ID());
createMovementFromConcept(concept, printed);
movement = movements.get(concept.get_ID());
// Validate null
if (movement == null)
throw new AdempiereException("Concept " + concept.getValue() + " not created");
//
movement.setHR_Payroll_ID(payrollConcept.getHR_Payroll_ID());
movement.setHR_PayrollConcept_ID(payrollConcept.getHR_PayrollConcept_ID());
movement.setPeriodNo(payrollPeriod.getPeriodNo());
}
}
// Save movements:
for (MHRMovement movement : movements.values()) {
MHRConcept concept = MHRConcept.get(getCtx(), movement.getHR_Concept_ID());
if (concept != null && concept.get_ID() > 0) {
if (concept.isManual()) {
logger.fine("Skip saving " + movement);
} else {
boolean saveThisRecord = (concept.isSaveInHistoric() || movement.isPrinted() || concept.isPaid() || concept.isPrinted()) && (!concept.isNotSaveInHistoryIfNull() || !movement.isEmpty());
if (saveThisRecord)
movement.saveEx();
}
}
}
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class AdempiereMonitorFilter method checkAuthorization.
// doFilter
/**
* Check Authorization
* @param authorization authorization
* @return true if authenticated
*/
private boolean checkAuthorization(String authorization) {
if (authorization == null)
return false;
try {
String userInfo = authorization.substring(6).trim();
Base64 decoder = new Base64();
String namePassword = new String(decoder.decode(userInfo.getBytes()));
// log.fine("checkAuthorization - Name:Password=" + namePassword);
int index = namePassword.indexOf(':');
String name = namePassword.substring(0, index);
String password = namePassword.substring(index + 1);
Login login = new Login(Env.getCtx());
KeyNamePair[] rolesKNPairs = login.getRoles(name, password);
if (rolesKNPairs == null || rolesKNPairs.length == 0)
throw new AdempiereException("@UserPwdError@");
for (KeyNamePair keyNamePair : rolesKNPairs) {
if ("System Administrator".equals(keyNamePair.getName())) {
log.info("Name=" + name);
return true;
}
}
log.warning("Not a Sys Admin = " + name);
return false;
} catch (Exception e) {
log.log(Level.SEVERE, "check", e);
}
return false;
}
Aggregations