use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class MInvoiceLine method setRMALine.
// copyLinesFrom
// end MZ
/**
* @param rmaline
*/
public void setRMALine(MRMALine rmaLine) {
// Check if this invoice is CreditMemo - teo_sarca [ 2804142 ]
if (!getParent().isCreditMemo()) {
throw new AdempiereException("InvoiceNotCreditMemo");
}
setAD_Org_ID(rmaLine.getAD_Org_ID());
setM_RMALine_ID(rmaLine.getM_RMALine_ID());
setDescription(rmaLine.getDescription());
setLine(rmaLine.getLine());
setC_Charge_ID(rmaLine.getC_Charge_ID());
setM_Product_ID(rmaLine.getM_Product_ID());
setC_UOM_ID(rmaLine.getC_UOM_ID());
setC_Tax_ID(rmaLine.getC_Tax_ID());
setPrice(rmaLine.getAmt());
BigDecimal qty = rmaLine.getQty();
if (rmaLine.getQtyInvoiced() != null)
qty = qty.subtract(rmaLine.getQtyInvoiced());
setQty(qty);
setLineNetAmt();
setTaxAmt();
setLineTotalAmt(rmaLine.getLineNetAmt());
setC_Project_ID(rmaLine.getC_Project_ID());
setC_Activity_ID(rmaLine.getC_Activity_ID());
setC_Campaign_ID(rmaLine.getC_Campaign_ID());
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class Browser method getInfoColumnForAxisField.
/**
* Get Info_Column for Axis Field
* @param field defined as Axis
* @return Info_Column with Axis Field
*/
public List<MBrowseField> getInfoColumnForAxisField(MBrowseField field) {
List<MBrowseField> list = new ArrayList<MBrowseField>();
axisParameters = new ArrayList<>();
axisParametersValues = new ArrayList<>();
try {
I_AD_View_Column xcol, pcol, ycol;
xcol = field.getAD_View_Column();
pcol = field.getAxis_Parent_Column();
ycol = field.getAxis_Column();
String columnName = xcol.getAD_Column().getColumnName();
MBrowseField fieldKey = ((MBrowse) field.getAD_Browse()).getFieldKey();
if (fieldKey == null)
throw new AdempiereException("@NotFound@ @IsKey@");
MTable xTable = (MTable) ycol.getAD_View_Definition().getAD_Table();
String xTableName = xTable.getTableName();
String keyColumn = MQuery.getZoomColumnName(columnName);
String tableName = MQuery.getZoomTableName(columnName);
String whereClause = "";
if (pcol != null && pcol.getAD_View_Column_ID() > 0) {
MTable parentTable = MTable.get(field.getCtx(), tableName);
MColumn parentColumn = getParentColumn(parentTable.getAD_Table_ID());
if (parentColumn == null)
throw new AdempiereException("@NotFound@ @IsParent@");
// BR [ 242 ]
if (field.getAD_Val_Rule_ID() > 0)
whereClause = Env.parseContext(Env.getCtx(), getWindowNo(), field.getAD_Val_Rule().getCode(), false);
}
MLookup lookup = MLookupFactory.get(Env.getCtx(), 0, xcol.getAD_Column_ID(), field.getAD_Reference_ID(), m_language, keyColumn, field.getAD_Reference_Value_ID(), false, whereClause);
int cols = 0;
StringBuilder axisSql = new StringBuilder("(SELECT ");
axisSql.append("SUM(").append(ycol.getAD_Column().getColumnName()).append(") FROM ").append(ycol.getAD_View_Definition().getAD_Table().getTableName()).append(" WHERE ").append(xTableName).append(".").append(fieldKey.getAD_View_Column().getAD_Column().getColumnName()).append("=").append(fieldKey.getAD_View_Column().getColumnSQL());
for (int id : getAxisRecordIds(tableName, whereClause)) {
cols++;
String display = lookup.getDisplay(id).trim();
display = display.length() > 12 ? display.substring(1, 12) + "_" + cols : display;
String joinColumn = Msg.translate(m_language, ycol.getAD_Column().getColumnName());
joinColumn = joinColumn.length() > 15 ? joinColumn.substring(1, 15) : joinColumn;
String sqlColName = display + "/" + joinColumn;
String colName = lookup.getDisplay(id).trim() + "/" + Msg.translate(m_language, ycol.getAD_Column().getColumnName());
StringBuilder axisWhere = new StringBuilder(" ");
axisWhere.append(getAxisSQLWhere(ycol)).append(" AND ").append(xcol.getAD_View_Definition().getTableAlias()).append(".").append(xcol.getAD_Column().getColumnName());
StringBuffer select = new StringBuffer();
select.append(axisSql).append(axisWhere);
select.append("=").append(id).append(")");
MViewColumn viewColumn = new MViewColumn(field.getCtx(), 0, field.get_TrxName());
MViewColumn.copyValues((MViewColumn) ycol, viewColumn);
viewColumn.setAD_View_Column_ID(ycol.getAD_View_Column_ID());
viewColumn.setAD_Column_ID(ycol.getAD_Column_ID());
viewColumn.setColumnSQL(select.toString());
viewColumn.setColumnName("\"" + sqlColName + "\"");
MBrowseField browseField = new MBrowseField((MBrowse) field.getAD_Browse(), viewColumn);
browseField.setAD_Browse_ID(field.getAD_Browse_ID());
browseField.setAD_Element_ID(field.getAD_Element_ID());
browseField.setName(colName);
browseField.setDescription(viewColumn.getDescription());
browseField.setHelp(viewColumn.getHelp());
if (viewColumn.get_ID() > 0)
browseField.setAD_View_Column_ID(viewColumn.getAD_View_Column_ID());
browseField.setIsActive(true);
browseField.setIsIdentifier(viewColumn.isIdentifier());
browseField.setIsRange(false);
browseField.setIsQueryCriteria(false);
browseField.setAD_Reference_ID(ycol.getAD_Column().getAD_Reference_ID());
browseField.setAD_Reference_Value_ID(ycol.getAD_Column().getAD_Reference_Value_ID());
browseField.setIsKey(false);
browseField.setIsDisplayed(true);
browseField.setAxis_Column_ID(field.getAxis_Column_ID());
browseField.setAxis_Parent_Column_ID(field.getAxis_Parent_Column_ID());
browseField.setIsReadOnly(field.isReadOnly());
browseField.setAD_Element_ID(field.getAD_Element_ID());
list.add(browseField);
log.finest("Added Column=" + sqlColName + " SQL = " + select);
}
} catch (Exception e) {
throw new AdempiereException(e);
}
return list;
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class ReleaseInOutBound method createDistributionOrder.
/**
* get Out Bound Order Lines from Smart Browser
* @return
*/
/*private List <MWMInOutBoundLine> getOutBoundOrderLine()
{
StringBuilder whereClause = new StringBuilder();
whereClause.append("EXISTS (SELECT 1 FROM WM_InOutBound o WHERE o.WM_InOutBound_ID=WM_InOutBoundLine.WM_InOutBound_ID AND o.Processed='N' AND o.DocAction NOT IN ('CO','CL','VO')) AND ");
whereClause.append("EXISTS (SELECT T_Selection_ID FROM T_Selection WHERE T_Selection.AD_PInstance_ID=? AND T_Selection.T_Selection_ID=WM_InOutBoundLine.WM_InOutboundLine_ID)");
return new Query(getCtx(), I_WM_InOutBoundLine.Table_Name, whereClause.toString(), get_TrxName())
.setClient_ID()
.setParameters(getAD_PInstance_ID())
.list();
}*/
/**
* create Distribution Order to performance a Pick List
* @param outBoundOrderLine Out bound Line
* @return Quantity that was not covert for inventory
*/
protected BigDecimal createDistributionOrder(MWMInOutBoundLine outBoundOrderLine) {
WMRuleEngine engineRule = WMRuleEngine.get();
List<MStorage> storageList = engineRule.getStorage(outBoundOrderLine, getWarehouseAreaTypeId(), getWarehouseSectionTypeId());
int shipperId = 0;
BigDecimal qtySupply = BigDecimal.ZERO;
if (storageList != null && storageList.size() > 0) {
//get the warehouse in transit
MWarehouse[] wsts = MWarehouse.getInTransitForOrg(getCtx(), outBoundLocator.getAD_Org_ID());
if (wsts == null || wsts.length == 0)
throw new AdempiereException("@M_Warehouse_ID@ @IsInTransit@ @NotFound@");
//Org Must be linked to BPartner
MOrg org = MOrg.get(getCtx(), outBoundLocator.getAD_Org_ID());
int partnerId = org.getLinkedC_BPartner_ID(get_TrxName());
if (partnerId == 0)
throw new NoBPartnerLinkedforOrgException(org);
MBPartner partner = MBPartner.get(getCtx(), partnerId);
if (orderDistribution == null) {
orderDistribution = new MDDOrder(getCtx(), 0, get_TrxName());
orderDistribution.setAD_Org_ID(outBoundLocator.getAD_Org_ID());
orderDistribution.setC_BPartner_ID(partnerId);
if (getDocumentTypeId() > 0) {
orderDistribution.setC_DocType_ID(getDocumentTypeId());
} else {
orderDistribution.setC_DocType_ID(MDocType.getDocType(X_C_DocType.DOCBASETYPE_DistributionOrder));
}
orderDistribution.setM_Warehouse_ID(wsts[0].get_ID());
if (getDocumentAction() != null)
orderDistribution.setDocAction(getDocumentAction());
else
orderDistribution.setDocAction(X_DD_Order.DOCACTION_Prepare);
MUser[] users = MUser.getOfBPartner(getCtx(), partner.getC_BPartner_ID(), get_TrxName());
if (users == null || users.length == 0)
throw new AdempiereException("@AD_User_ID@ @NotFound@ @Value@ - @C_BPartner_ID@ : " + partner.getValue() + " - " + partner.getName());
orderDistribution.setAD_User_ID(users[0].getAD_User_ID());
orderDistribution.setDateOrdered(getToday());
orderDistribution.setDatePromised(getToday());
orderDistribution.setM_Shipper_ID(shipperId);
orderDistribution.setIsInDispute(false);
orderDistribution.setIsInTransit(false);
orderDistribution.setSalesRep_ID(getAD_User_ID());
orderDistribution.saveEx();
}
storageList.stream().forEach(storage -> {
MDDOrderLine orderLine = new MDDOrderLine(orderDistribution);
orderLine.setM_Locator_ID(storage.getM_Locator_ID());
orderLine.setM_LocatorTo_ID(outBoundLocator.getM_Locator_ID());
orderLine.setC_UOM_ID(outBoundOrderLine.getC_UOM_ID());
orderLine.setM_Product_ID(outBoundOrderLine.getM_Product_ID());
orderLine.setDateOrdered(getToday());
orderLine.setDatePromised(outBoundOrderLine.getPickDate());
orderLine.setWM_InOutBoundLine_ID(outBoundOrderLine.getWM_InOutBoundLine_ID());
orderLine.setIsInvoiced(false);
orderLine.saveEx();
});
} else {
qtySupply = outBoundOrderLine.getQtyToPick().subtract(qtySupply);
}
return qtySupply;
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class ReleaseInOutBound method doIt.
/**
* Process - Generate Export Format
* @return info
*/
@Override
protected String doIt() throws Exception {
List<MWMInOutBoundLine> outBoundLines = (List<MWMInOutBoundLine>) getInstancesForSelection(get_TrxName());
outBoundLines.stream().forEach(outBoundLine -> {
if (outBoundLine.getDD_OrderLine_ID() > 0) {
MDDOrderLine orderDistributionLine = (MDDOrderLine) outBoundLine.getDD_OrderLine();
if (orderDistributionLine.getWM_InOutBoundLine_ID() <= 0) {
orderDistributionLine.setWM_InOutBoundLine_ID(orderDistributionLine.getWM_InOutBoundLine_ID());
orderDistributionLine.saveEx();
}
if (orderDistributionLine.getM_LocatorTo_ID() == outBoundLocator.getM_Locator_ID())
return;
}
BigDecimal qtySupply = createDistributionOrder(outBoundLine);
if (isCreateSupply() && qtySupply.signum() > 0) {
Env.setContext(outBoundLine.getCtx(), IsCreateSupply, "Y");
createSupply(outBoundLine, qtySupply);
}
});
if (orderDistribution != null && getDocumentAction() != null) {
orderDistribution.setDocAction(getDocumentAction());
orderDistribution.setDocStatus(org.compiere.process.DocAction.STATUS_InProgress);
orderDistribution.completeIt();
orderDistribution.save();
}
if (isPrintPickList() && orderDistribution != null) {
// Get Format & Data
ReportEngine reportEngine = getReportEngine("DistributionOrder_Header ** TEMPLATE **", "DD_Order_Header_v", orderDistribution.getDD_Order_ID());
if (reportEngine == null)
throw new AdempiereException("@NotFound@ @AD_PrintFormat_ID@");
ReportCtl.preview(reportEngine);
// prints only original
reportEngine.print();
}
//@DocumentNo@ " + order.getDocumentNo();
return "";
}
use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.
the class GenerateShipmentOutBound method processingMovements.
public void processingMovements() {
distributionOrders.entrySet().stream().forEach(entry -> {
I_DD_Order distributionOrder = entry.getValue();
List<Integer> orderIds = new ArrayList<Integer>();
orderIds.add(distributionOrder.getDD_Order_ID());
ProcessInfo processInfo = ProcessBuilder.create(getCtx()).process(MovementGenerate.getProcessId()).withSelectedRecordsIds(orderIds).withParameter(MWMInOutBound.COLUMNNAME_M_Warehouse_ID, distributionOrder.getM_Warehouse_ID()).withParameter(MMovement.COLUMNNAME_MovementDate, getMovementDate()).withoutTransactionClose().execute(get_TrxName());
if (processInfo.isError())
throw new AdempiereException(processInfo.getSummary());
addLog(processInfo.getSummary());
Arrays.stream(processInfo.getIDs()).forEach(recordId -> {
MMovement movement = new MMovement(getCtx(), recordId, get_TrxName());
if (movement != null && movement.get_ID() > 0)
GenerateMovement.printDocument(movement, "Inventory Move Hdr (Example)", processInfo.getWindowNo());
else
throw new AdempiereException("@M_Movement_ID@ @NotFound@");
});
});
}
Aggregations