use of org.compiere.model.MInOutLine in project adempiere by adempiere.
the class ReverseTheSalesTransaction method cancelShipments.
private void cancelShipments(MInOut[] sourceShipments) {
for (MInOut sourceShipment : sourceShipments) {
MRMA rma = new MRMA(getCtx(), 0, get_TrxName());
rma.setM_InOut_ID(sourceShipment.getM_InOut_ID());
rma.setAD_Org_ID(sourceShipment.getAD_Org_ID());
rma.setM_RMAType_ID(getRMATypeId());
rma.setC_BPartner_ID(sourceShipment.getC_BPartner_ID());
rma.setName(sourceShipment.getDocumentInfo());
rma.setIsSOTrx(true);
rma.setSalesRep_ID(sourceShipment.getSalesRep_ID());
rma.setC_DocType_ID(MDocType.getDocTypeBaseOnSubType(sourceShipment.getAD_Org_ID(), MDocType.DOCBASETYPE_SalesOrder, MDocType.DOCSUBTYPESO_ReturnMaterial));
rma.setDocStatus(DocAction.STATUS_Drafted);
rma.setDocAction(DocAction.ACTION_Complete);
rma.saveEx();
MInOut customerReturn = new MInOut(getCtx(), 0, get_TrxName());
PO.copyValues(sourceShipment, customerReturn);
customerReturn.setDocumentNo(null);
customerReturn.setM_RMA_ID(rma.getM_RMA_ID());
customerReturn.setIsSOTrx(true);
customerReturn.setC_BPartner_ID(sourceShipment.getC_BPartner_ID());
customerReturn.setC_Order_ID(-1);
for (MDocType documentType : MDocType.getOfDocBaseType(getCtx(), MDocType.DOCBASETYPE_MaterialReceipt)) if (documentType.isSOTrx())
customerReturn.setC_DocType_ID();
customerReturn.setMovementType(MInOut.MOVEMENTTYPE_CustomerReturns);
customerReturn.setDocStatus(DocAction.STATUS_Drafted);
customerReturn.setDocAction(DocAction.ACTION_Complete);
customerReturn.setProcessed(false);
customerReturn.saveEx();
for (MInOutLine sourceShipmentLine : sourceShipment.getLines()) {
MRMALine rmaLine = new MRMALine(getCtx(), 0, get_TrxName());
rmaLine.setM_RMA_ID(rma.getM_RMA_ID());
rmaLine.setAD_Org_ID(sourceShipmentLine.getAD_Org_ID());
rmaLine.setM_InOutLine_ID(sourceShipmentLine.getM_InOutLine_ID());
rmaLine.setQty(sourceShipmentLine.getMovementQty());
rmaLine.saveEx();
MInOutLine customerReturnLine = new MInOutLine(getCtx(), 0, get_TrxName());
customerReturnLine.setM_InOut_ID(customerReturn.getM_InOut_ID());
customerReturnLine.setM_RMALine_ID(rmaLine.getM_RMALine_ID());
customerReturnLine.setM_Product_ID(rmaLine.getM_Product_ID());
customerReturnLine.setM_Locator_ID(sourceShipmentLine.getM_Locator_ID());
customerReturnLine.setMovementQty(rmaLine.getQty());
customerReturnLine.saveEx();
}
rma.processIt(DocAction.ACTION_Complete);
rma.saveEx();
addLog(rma.getDocumentInfo());
if (customerReturn.getC_DocType().isShipConfirm() && isShipReceiptConfirmation()) {
customerReturn.processIt(DocAction.STATUS_InProgress);
customerReturn.saveEx();
for (MInOutConfirm confirm : customerReturn.getConfirmations(true)) {
for (MInOutLineConfirm confirmLine : confirm.getLines(true)) {
confirmLine.setConfirmedQty(confirmLine.getTargetQty());
confirmLine.saveEx();
}
confirm.processIt(DocAction.ACTION_Complete);
confirm.saveEx();
addLog(confirm.getDocumentInfo());
}
}
customerReturn.processIt(DocAction.STATUS_Completed);
customerReturn.saveEx();
addLog(customerReturn.getDocumentInfo());
customerReturns.add(customerReturn);
}
}
use of org.compiere.model.MInOutLine in project adempiere by adempiere.
the class Doc_MatchInv method loadDocumentDetails.
/** Commitments */
// private DocLine[] m_commitments = null;
/**
* Load Specific Document Details
* @return error message or null
*/
protected String loadDocumentDetails() {
setC_Currency_ID(Doc.NO_CURRENCY);
MMatchInv matchInv = (MMatchInv) getPO();
setDateDoc(matchInv.getDateTrx());
setQty(matchInv.getQty());
// Invoice Info
int C_InvoiceLine_ID = matchInv.getC_InvoiceLine_ID();
m_invoiceLine = new MInvoiceLine(getCtx(), C_InvoiceLine_ID, getTrxName());
// BP for NotInvoicedReceipts
int C_BPartner_ID = m_invoiceLine.getParent().getC_BPartner_ID();
setC_BPartner_ID(C_BPartner_ID);
//
int M_InOutLine_ID = matchInv.getM_InOutLine_ID();
m_receiptLine = new MInOutLine(getCtx(), M_InOutLine_ID, getTrxName());
//
m_pc = new ProductCost(Env.getCtx(), getM_Product_ID(), matchInv.getM_AttributeSetInstance_ID(), getTrxName());
m_pc.setQty(getQty());
return null;
}
use of org.compiere.model.MInOutLine in project adempiere by adempiere.
the class AverageInvoiceCostingMethod method adjustCostDetail.
/**
* Recalculate Cost Detail
* @param cost
*/
public void adjustCostDetail(MCostDetail cost) {
Properties ctx = cost.getCtx();
String trxName = cost.get_TrxName();
int transactionId = cost.getM_Transaction_ID();
int clientId = cost.getAD_Client_ID();
MTransaction transaction = new MTransaction(ctx, transactionId, trxName);
MCostType costType = (MCostType) cost.getM_CostType();
MCostElement costElement = (MCostElement) cost.getM_CostElement();
MAcctSchema accountSchema = (MAcctSchema) cost.getC_AcctSchema();
CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).clearAccounting(accountSchema, transaction);
if (MTransaction.MOVEMENTTYPE_VendorReceipts.equals(transaction.getMovementType())) {
MInOutLine line = (MInOutLine) transaction.getDocumentLine();
if (MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
if (cost.getM_InOutLine_ID() > 0 && cost.getQty().signum() != 0) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, line, true);
} else if (cost.getM_InOutLine_ID() > 0 && cost.getQty().signum() != 0 && cost.getC_OrderLine_ID() > 0) {
List<MMatchPO> orderMatches = MMatchPO.getInOutLine(line);
for (MMatchPO match : orderMatches) {
if (match.getM_InOutLine_ID() == line.getM_InOutLine_ID() && match.getM_Product_ID() == transaction.getM_Product_ID()) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
}
}
} else if (cost.getM_InOutLine_ID() > 0 && cost.getQty().signum() == 0 && cost.getC_InvoiceLine_ID() > 0 && cost.getC_LandedCostAllocation_ID() == 0) {
List<MMatchInv> invoiceMatches = MMatchInv.getInOutLine(line);
for (MMatchInv match : invoiceMatches) {
if (match.getM_Product_ID() == transaction.getM_Product_ID()) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
}
}
}
}
// only own allocation
if (cost.getC_LandedCostAllocation_ID() != 0) {
MLandedCostAllocation allocation = (MLandedCostAllocation) cost.getC_LandedCostAllocation();
{
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, allocation, true);
}
}
} else
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, transaction.getDocumentLine(), true);
}
use of org.compiere.model.MInOutLine in project adempiere by adempiere.
the class CostEngine method clearAccounting.
/**
* clear Accounting
* @param accountSchema
* @param transaction
*/
public void clearAccounting(MAcctSchema accountSchema, MTransaction transaction) {
if (transaction.getM_InOutLine_ID() > 0) {
MInOutLine line = (MInOutLine) transaction.getM_InOutLine();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getDateAcct()))
return;
// get Purchase matches
List<MMatchPO> orderMatches = MMatchPO.getInOutLine(line);
for (MMatchPO match : orderMatches) {
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), match, transaction.getM_Product_ID(), line.getDateAcct()))
return;
}
// get invoice matches
List<MMatchInv> invoiceMatches = MMatchInv.getInOutLine(line);
for (MMatchInv match : invoiceMatches) {
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), match, transaction.getM_Product_ID(), line.getDateAcct()))
return;
}
} else if (transaction.getC_ProjectIssue_ID() > 0) {
MProjectIssue line = (MProjectIssue) transaction.getC_ProjectIssue();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getMovementDate()))
return;
} else if (transaction.getM_InventoryLine_ID() > 0) {
MInventoryLine line = (MInventoryLine) transaction.getM_InventoryLine();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getDateAcct()))
return;
} else if (transaction.getM_MovementLine_ID() > 0) {
MMovementLine line = (MMovementLine) transaction.getM_MovementLine();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getDateAcct()))
return;
} else if (transaction.getM_ProductionLine_ID() > 0) {
MProductionLine line = (MProductionLine) transaction.getM_ProductionLine();
MProduction production = (MProduction) line.getM_ProductionPlan().getM_Production();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), production, transaction.getM_Product_ID(), production.getMovementDate()))
return;
} else if (transaction.getPP_Cost_Collector_ID() > 0) {
MPPCostCollector costCollector = (MPPCostCollector) transaction.getPP_Cost_Collector();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), costCollector, costCollector.getM_Product_ID(), costCollector.getDateAcct()))
;
return;
} else {
log.info("Document does not exist :" + transaction);
}
}
use of org.compiere.model.MInOutLine in project adempiere by adempiere.
the class AbstractCostingMethod method clearAccounting.
public void clearAccounting(MCostDetail cost) {
// Only can delete if period is open
MTransaction trx = new MTransaction(cost.getCtx(), cost.getM_Transaction_ID(), cost.get_TrxName());
IDocumentLine documentLine = trx.getDocumentLine();
MDocType docType = MDocType.get(cost.getCtx(), documentLine.getC_DocType_ID());
Boolean openPeriod = MPeriod.isOpen(cost.getCtx(), cost.getDateAcct(), docType.getDocBaseType(), cost.getAD_Org_ID());
if (!openPeriod)
return;
String sqldelete = "DELETE FROM Fact_Acct WHERE Record_ID =? AND AD_Table_ID=?";
int tableId = 0;
int recordId = 0;
if (cost.getC_OrderLine_ID() != 0) {
MOrderLine line = (MOrderLine) cost.getC_OrderLine();
line.getParent().setPosted(false);
line.getParent().saveEx();
recordId = line.getParent().get_ID();
tableId = line.getParent().get_Table_ID();
}
if (cost.getM_InOutLine_ID() != 0) {
MInOutLine line = (MInOutLine) cost.getM_InOutLine();
line.getParent().setPosted(false);
line.getParent().saveEx();
recordId = line.getParent().get_ID();
tableId = line.getParent().get_Table_ID();
}
if (cost.getM_InventoryLine_ID() != 0) {
MInventoryLine line = (MInventoryLine) cost.getM_InventoryLine();
line.getParent().setPosted(false);
line.getParent().saveEx();
recordId = line.getParent().get_ID();
tableId = line.getParent().get_Table_ID();
}
if (cost.getM_MovementLine_ID() != 0) {
MMovementLine line = (MMovementLine) cost.getM_MovementLine();
line.getParent().setPosted(false);
line.getParent().saveEx();
recordId = line.getParent().get_ID();
tableId = line.getParent().get_Table_ID();
}
if (cost.getM_ProductionLine_ID() != 0) {
}
if (cost.getPP_Cost_Collector_ID() != 0) {
MPPCostCollector costCollector = (MPPCostCollector) cost.getPP_Cost_Collector();
costCollector.setPosted(false);
costCollector.saveEx();
recordId = costCollector.get_ID();
tableId = costCollector.get_Table_ID();
}
int no = DB.executeUpdateEx(sqldelete, new Object[] { recordId, tableId }, cost.get_TrxName());
}
Aggregations