use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.
the class DistributionVerify method doIt.
// prepare
/**
* Process
* @return message
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("doIt - GL_Distribution_ID=" + getRecord_ID());
MDistribution distribution = new MDistribution(getCtx(), getRecord_ID(), get_TrxName());
if (distribution.get_ID() == 0)
throw new AdempiereUserError("Not found GL_Distribution_ID=" + getRecord_ID());
String error = distribution.validate();
boolean saved = distribution.save();
if (error != null)
throw new AdempiereUserError(error);
if (!saved)
throw new AdempiereSystemError("@NotSaved@");
return "@OK@";
}
use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.
the class ReplenishReportProduction method doIt.
// prepare
/**
* Perform process.
* @return Message
* @throws Exception if not successful
*/
protected String doIt() throws Exception {
log.info("M_Warehouse_ID=" + p_M_Warehouse_ID + ", C_BPartner_ID=" + p_C_BPartner_ID + " - ReplenishmentCreate=" + p_ReplenishmentCreate + ", C_DocType_ID=" + p_C_DocType_ID);
if (p_ReplenishmentCreate != null && p_C_DocType_ID == 0 && !p_ReplenishmentCreate.equals("PRD"))
throw new AdempiereUserError("@FillMandatory@ @C_DocType_ID@");
MWarehouse wh = MWarehouse.get(getCtx(), p_M_Warehouse_ID);
if (wh.get_ID() == 0)
throw new AdempiereSystemError("@FillMandatory@ @M_Warehouse_ID@");
//
prepareTable();
fillTable(wh);
//
if (p_ReplenishmentCreate == null)
return "OK";
//
MDocType dt = MDocType.get(getCtx(), p_C_DocType_ID);
if (!p_ReplenishmentCreate.equals("PRD") && !dt.getDocBaseType().equals(p_ReplenishmentCreate))
throw new AdempiereSystemError("@C_DocType_ID@=" + dt.getName() + " <> " + p_ReplenishmentCreate);
//
if (p_ReplenishmentCreate.equals("POO"))
createPO();
else if (p_ReplenishmentCreate.equals("POR"))
createRequisition();
else if (p_ReplenishmentCreate.equals("MMM"))
createMovements();
else if (p_ReplenishmentCreate.equals("DOO"))
createDO();
else if (p_ReplenishmentCreate.equals("PRD"))
createProduction();
return m_info;
}
use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.
the class AllocationAuto method allocateBPOldestFirst.
// allocateBPartnerAll
/**
* Allocate Oldest First using Accounting currency
* @return allocations
*/
private int allocateBPOldestFirst() throws Exception {
int C_Currency_ID = MClient.get(getCtx()).getC_Currency_ID();
Timestamp dateAcct = null;
// Payments
BigDecimal totalPayments = Env.ZERO;
for (int p = 0; p < m_payments.length; p++) {
MPayment payment = m_payments[p];
if (payment.isAllocated())
continue;
if (payment.getC_Currency_ID() != C_Currency_ID)
continue;
BigDecimal allocatedAmt = payment.getAllocatedAmt();
log.info(payment + ", Allocated=" + allocatedAmt);
BigDecimal availableAmt = payment.getPayAmt().add(payment.getDiscountAmt()).add(payment.getWriteOffAmt()).add(payment.getOverUnderAmt());
availableAmt = availableAmt.subtract(allocatedAmt);
if (!payment.isReceipt())
availableAmt = availableAmt.negate();
log.fine("Available=" + availableAmt);
if (dateAcct == null || payment.getDateAcct().after(dateAcct))
dateAcct = payment.getDateAcct();
totalPayments = totalPayments.add(availableAmt);
}
// Invoices
BigDecimal totalInvoices = Env.ZERO;
for (int i = 0; i < m_invoices.length; i++) {
MInvoice invoice = m_invoices[i];
if (invoice.isPaid())
continue;
if (invoice.getC_Currency_ID() != C_Currency_ID)
continue;
BigDecimal openAmt = invoice.getOpenAmt(true, null);
log.fine("" + invoice);
if (!invoice.isSOTrx())
openAmt = openAmt.negate();
// Foreign currency
log.fine("Open=" + openAmt);
if (dateAcct == null || invoice.getDateAcct().after(dateAcct))
dateAcct = invoice.getDateAcct();
totalInvoices = totalInvoices.add(openAmt);
}
// must be either AP or AR balance
if (totalInvoices.signum() != totalPayments.signum()) {
log.fine("Signum - Invoices=" + totalInvoices.signum() + " <> Payments=" + totalPayments.signum());
return 0;
}
BigDecimal difference = totalInvoices.subtract(totalPayments);
BigDecimal maxAmt = totalInvoices.abs().min(totalPayments.abs());
if (totalInvoices.signum() < 0)
maxAmt = maxAmt.negate();
log.info("= Invoices=" + totalInvoices + " - Payments=" + totalPayments + " = Difference=" + difference + " - Max=" + maxAmt);
// Allocate Payments up to max
BigDecimal allocatedPayments = Env.ZERO;
for (int p = 0; p < m_payments.length; p++) {
MPayment payment = m_payments[p];
if (payment.isAllocated())
continue;
if (payment.getC_Currency_ID() != C_Currency_ID)
continue;
BigDecimal allocatedAmt = payment.getAllocatedAmt();
// comment following lines to allow partial allocation
// if (allocatedAmt != null && allocatedAmt.signum() != 0)
// continue;
BigDecimal availableAmt = payment.getPayAmt().add(payment.getDiscountAmt()).add(payment.getWriteOffAmt()).add(payment.getOverUnderAmt());
availableAmt = availableAmt.subtract(allocatedAmt);
if (!payment.isReceipt())
availableAmt = availableAmt.negate();
allocatedPayments = allocatedPayments.add(availableAmt);
if ((totalInvoices.signum() > 0 && allocatedPayments.compareTo(maxAmt) > 0) || (totalInvoices.signum() < 0 && allocatedPayments.compareTo(maxAmt) < 0)) {
BigDecimal diff = allocatedPayments.subtract(maxAmt);
availableAmt = availableAmt.subtract(diff);
allocatedPayments = allocatedPayments.subtract(diff);
}
log.fine("Payment Allocated=" + availableAmt);
if (!createAllocation(C_Currency_ID, "BP Oldest (" + difference.abs() + ")", dateAcct, availableAmt, null, null, null, payment.getC_BPartner_ID(), payment.getC_Payment_ID(), 0, payment.getAD_Org_ID())) {
throw new AdempiereSystemError("Cannot create Allocation");
}
if (allocatedPayments.compareTo(maxAmt) == 0)
break;
}
// for all payments
// Allocated Invoices up to max
BigDecimal allocatedInvoices = Env.ZERO;
for (int i = 0; i < m_invoices.length; i++) {
MInvoice invoice = m_invoices[i];
if (invoice.isPaid())
continue;
if (invoice.getC_Currency_ID() != C_Currency_ID)
continue;
BigDecimal openAmt = invoice.getOpenAmt(true, null);
if (!invoice.isSOTrx())
openAmt = openAmt.negate();
allocatedInvoices = allocatedInvoices.add(openAmt);
if ((totalInvoices.signum() > 0 && allocatedInvoices.compareTo(maxAmt) > 0) || (totalInvoices.signum() < 0 && allocatedInvoices.compareTo(maxAmt) < 0)) {
BigDecimal diff = allocatedInvoices.subtract(maxAmt);
openAmt = openAmt.subtract(diff);
allocatedInvoices = allocatedInvoices.subtract(diff);
}
if (openAmt.signum() == 0)
break;
log.fine("Invoice Allocated=" + openAmt);
if (!createAllocation(C_Currency_ID, "BP Oldest (" + difference.abs() + ")", dateAcct, openAmt, null, null, null, invoice.getC_BPartner_ID(), 0, invoice.getC_Invoice_ID(), invoice.getAD_Org_ID())) {
throw new AdempiereSystemError("Cannot create Allocation");
}
if (allocatedInvoices.compareTo(maxAmt) == 0)
break;
}
if (allocatedPayments.compareTo(allocatedInvoices) != 0) {
throw new AdempiereSystemError("Allocated Payments=" + allocatedPayments + " <> Invoices=" + allocatedInvoices);
}
processAllocation();
return 1;
}
use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.
the class AllocationAuto method allocateBPOneToOne.
// allocateIndividualPayments
/**
* Allocate Payment:Invoice 1:1
* @return allocations
*/
private int allocateBPOneToOne() throws Exception {
int count = 0;
for (int p = 0; p < m_payments.length; p++) {
MPayment payment = m_payments[p];
if (payment.isAllocated())
continue;
BigDecimal allocatedAmt = payment.getAllocatedAmt();
log.info(payment + ", Allocated=" + allocatedAmt);
if (allocatedAmt != null && allocatedAmt.signum() != 0)
continue;
BigDecimal availableAmt = payment.getPayAmt().add(payment.getDiscountAmt()).add(payment.getWriteOffAmt()).add(payment.getOverUnderAmt());
if (!payment.isReceipt())
availableAmt = availableAmt.negate();
log.fine("Available=" + availableAmt);
for (int i = 0; i < m_invoices.length; i++) {
MInvoice invoice = m_invoices[i];
if (invoice == null || invoice.isPaid())
continue;
if (payment.getC_Currency_ID() == invoice.getC_Currency_ID()) {
// log.fine("allocateBPartnerAll - " + invoice);
BigDecimal openAmt = invoice.getOpenAmt(true, null);
if (!invoice.isSOTrx())
openAmt = openAmt.negate();
BigDecimal difference = availableAmt.subtract(openAmt).abs();
log.fine(invoice + ", Open=" + openAmt + " - Difference=" + difference);
if (difference.signum() == 0) {
Timestamp dateAcct = payment.getDateAcct();
if (invoice.getDateAcct().after(dateAcct))
dateAcct = invoice.getDateAcct();
if (!createAllocation(payment.getC_Currency_ID(), "1:1 (" + availableAmt + ")", dateAcct, availableAmt, null, null, null, invoice.getC_BPartner_ID(), payment.getC_Payment_ID(), invoice.getC_Invoice_ID(), invoice.getAD_Org_ID())) {
throw new AdempiereSystemError("Cannot create Allocation");
}
processAllocation();
count++;
// remove invoice
m_invoices[i] = null;
m_payments[p] = null;
payment = null;
break;
}
} else // Multi-Currency
{
}
}
// for all invoices
}
// for all payments
return count;
}
use of org.compiere.util.AdempiereSystemError in project adempiere by adempiere.
the class AllocationAuto method allocateBPartnerAll.
// allocateOneToOne
/**
* Allocate all Payments/Invoices using Accounting currency
* @return allocations
*/
private int allocateBPartnerAll() throws Exception {
int C_Currency_ID = MClient.get(getCtx()).getC_Currency_ID();
Timestamp dateAcct = null;
// Payments
BigDecimal totalPayments = Env.ZERO;
for (int p = 0; p < m_payments.length; p++) {
MPayment payment = m_payments[p];
if (payment.isAllocated())
continue;
BigDecimal allocatedAmt = payment.getAllocatedAmt();
// log.info("allocateBPartnerAll - " + payment + ", Allocated=" + allocatedAmt);
if (allocatedAmt != null && allocatedAmt.signum() != 0)
continue;
BigDecimal availableAmt = payment.getPayAmt().add(payment.getDiscountAmt()).add(payment.getWriteOffAmt()).add(payment.getOverUnderAmt());
if (!payment.isReceipt())
availableAmt = availableAmt.negate();
// Foreign currency
if (payment.getC_Currency_ID() != C_Currency_ID)
continue;
// log.fine("allocateBPartnerAll - Available=" + availableAmt);
if (dateAcct == null || payment.getDateAcct().after(dateAcct))
dateAcct = payment.getDateAcct();
totalPayments = totalPayments.add(availableAmt);
}
// Invoices
BigDecimal totalInvoices = Env.ZERO;
for (int i = 0; i < m_invoices.length; i++) {
MInvoice invoice = m_invoices[i];
if (invoice.isPaid())
continue;
// log.info("allocateBPartnerAll - " + invoice);
BigDecimal openAmt = invoice.getOpenAmt(true, null);
if (!invoice.isSOTrx())
openAmt = openAmt.negate();
// Foreign currency
if (invoice.getC_Currency_ID() != C_Currency_ID)
continue;
// log.fine("allocateBPartnerAll - Open=" + openAmt);
if (dateAcct == null || invoice.getDateAcct().after(dateAcct))
dateAcct = invoice.getDateAcct();
totalInvoices = totalInvoices.add(openAmt);
}
BigDecimal difference = totalInvoices.subtract(totalPayments);
log.info("= Invoices=" + totalInvoices + " - Payments=" + totalPayments + " = Difference=" + difference);
if (difference.signum() == 0) {
for (int p = 0; p < m_payments.length; p++) {
MPayment payment = m_payments[p];
if (payment.isAllocated())
continue;
BigDecimal allocatedAmt = payment.getAllocatedAmt();
if (allocatedAmt != null && allocatedAmt.signum() != 0)
continue;
BigDecimal availableAmt = payment.getPayAmt().add(payment.getDiscountAmt()).add(payment.getWriteOffAmt()).add(payment.getOverUnderAmt());
if (!payment.isReceipt())
availableAmt = availableAmt.negate();
// Foreign currency
if (payment.getC_Currency_ID() != C_Currency_ID)
continue;
if (!createAllocation(C_Currency_ID, "BP All", dateAcct, availableAmt, null, null, null, payment.getC_BPartner_ID(), payment.getC_Payment_ID(), 0, payment.getAD_Org_ID())) {
throw new AdempiereSystemError("Cannot create Allocation");
}
}
//
for (int i = 0; i < m_invoices.length; i++) {
MInvoice invoice = m_invoices[i];
if (invoice.isPaid())
continue;
BigDecimal openAmt = invoice.getOpenAmt(true, null);
if (!invoice.isSOTrx())
openAmt = openAmt.negate();
// Foreign currency
if (invoice.getC_Currency_ID() != C_Currency_ID)
continue;
if (!createAllocation(C_Currency_ID, "BP All", dateAcct, openAmt, null, null, null, invoice.getC_BPartner_ID(), 0, invoice.getC_Invoice_ID(), invoice.getAD_Org_ID())) {
throw new AdempiereSystemError("Cannot create Allocation");
}
}
// for all invoices
processAllocation();
return 1;
}
return 0;
}
Aggregations