Search in sources :

Example 6 with MInventoryLine

use of org.compiere.model.MInventoryLine in project adempiere by adempiere.

the class ScanBar method createLine.

public void createLine() {
    int lineNo = DB.getSQLValueEx(null, "SELECT Line FROM " + tableLine.getTableName() + " WHERE " + table.getTableName() + "_ID=?", getRecord_ID());
    if (lineNo <= 0)
        lineNo = 10;
    for (Vector<Object> line : getData().values()) {
        String value = (String) line.get(0);
        String lotNo = (String) line.get(2);
        String serNo = (String) line.get(3);
        Boolean isASI = (lotNo != null && lotNo.length() > 0) || (serNo != null && serNo.length() > 0) ? true : false;
        BigDecimal qty = (BigDecimal) line.get(4);
        int id = (Integer) line.get(5);
        Integer referenceId = (Integer) line.get(6);
        PO poLine = null;
        MAttributeSetInstance asi = null;
        MProduct product = new Query(Env.getCtx(), I_M_Product.Table_Name, "Value = ? ", null).setClient_ID().setParameters(value).firstOnly();
        String desc = null;
        poLine = tableLine.getPO(id, null);
        if (product.getM_AttributeSet_ID() > 0 && isASI) {
            if (poLine != null && poLine.get_ValueAsInt(I_M_AttributeSetInstance.COLUMNNAME_M_AttributeSetInstance_ID) > 0)
                asi = new MAttributeSetInstance(Env.getCtx(), poLine.get_ValueAsInt(I_M_AttributeSetInstance.COLUMNNAME_M_AttributeSetInstance_ID), null);
            else
                asi = getAttributeSetInstance(product, lotNo, serNo, getM_Locater_ID(), null);
        }
        poLine.set_ValueOfColumn(table.getKeyColumns()[0], getRecord_ID());
        poLine.set_ValueOfColumn(I_M_Product.COLUMNNAME_M_Product_ID, product.get_ID());
        poLine.set_ValueOfColumn(I_M_Product.COLUMNNAME_C_UOM_ID, product.getC_UOM_ID());
        poLine.set_ValueOfColumn(I_M_InOutLine.COLUMNNAME_Line, lineNo);
        poLine.set_ValueOfColumn(I_M_InOutLine.COLUMNNAME_IsActive, true);
        int locatorColumnId = poLine.get_ColumnIndex(I_M_InOutLine.COLUMNNAME_M_Locator_ID);
        if (locatorColumnId > 0 && getM_Locater_ID() > 0)
            poLine.set_ValueOfColumn(I_M_InOutLine.COLUMNNAME_M_Locator_ID, getM_Locater_ID());
        if (asi == null && isASI) {
            if (asi == null && isASI) {
                asi = new MAttributeSetInstance(Env.getCtx(), 0, product.getM_AttributeSet_ID(), null);
                if (lotNo != null) {
                    asi.setLot(lotNo);
                    desc = lotNo;
                }
                if (serNo != null) {
                    asi.setSerNo(serNo);
                    if (desc != null)
                        desc = desc + " - " + serNo;
                    else
                        desc = serNo;
                }
                asi.setDescription(desc);
                asi.saveEx();
            }
        }
        if (poLine instanceof MInventoryLine) {
            MStorage storage = MStorage.get(Env.getCtx(), getM_Locater_ID(), product.getM_Product_ID(), asi == null ? 0 : asi.getM_AttributeSetInstance_ID(), null);
            poLine.set_CustomColumn(I_M_InventoryLine.COLUMNNAME_QtyCount, qty);
            poLine.set_CustomColumn(I_M_InventoryLine.COLUMNNAME_QtyBook, storage == null ? Env.ZERO : storage.getQtyOnHand());
        } else if (poLine instanceof MInOutLine) {
            MInOutLine ioLine = (MInOutLine) poLine;
            ioLine.setQty(qty);
            ioLine.setC_OrderLine_ID(referenceId);
        } else if (poLine instanceof MMovementLine) {
            MMovementLine movementLine = (MMovementLine) poLine;
            movementLine.setM_LocatorTo_ID(getM_LocaterTo_ID());
            movementLine.setMovementQty(qty);
        } else
            poLine.set_ValueOfColumn(I_M_InOutLine.COLUMNNAME_MovementQty, qty);
        poLine.set_ValueOfColumn(MAttributeSetInstance.COLUMNNAME_M_AttributeSetInstance_ID, asi == null ? 0 : asi.get_ID());
        if (poLine.is_Changed())
            poLine.saveEx();
        lineNo = lineNo + 10;
    }
}
Also used : MProduct(org.compiere.model.MProduct) Query(org.compiere.model.Query) MInventoryLine(org.compiere.model.MInventoryLine) MInOutLine(org.compiere.model.MInOutLine) MAttributeSetInstance(org.compiere.model.MAttributeSetInstance) MStorage(org.compiere.model.MStorage) BigDecimal(java.math.BigDecimal) MMovementLine(org.compiere.model.MMovementLine) PO(org.compiere.model.PO)

Example 7 with MInventoryLine

use of org.compiere.model.MInventoryLine in project adempiere by adempiere.

the class Doc_Inventory method loadLines.

//  loadDocumentDetails
/**
	 *	Load Invoice Line
	 *	@param inventory inventory
	 *  @return DocLine Array
	 */
private DocLine[] loadLines(MInventory inventory) {
    ArrayList<DocLine> list = new ArrayList<DocLine>();
    MInventoryLine[] lines = inventory.getLines(false);
    for (int i = 0; i < lines.length; i++) {
        MInventoryLine line = lines[i];
        //	nothing to post
        if (line.getQtyBook().compareTo(line.getQtyCount()) == 0 && line.getQtyInternalUse().signum() == 0)
            continue;
        //
        DocLine docLine = new DocLine(line, this);
        BigDecimal Qty = line.getQtyInternalUse();
        if (Qty.signum() != 0)
            //	Internal Use entered positive
            Qty = Qty.negate();
        else {
            BigDecimal QtyBook = line.getQtyBook();
            BigDecimal QtyCount = line.getQtyCount();
            Qty = QtyCount.subtract(QtyBook);
        }
        // -5 => -5
        docLine.setQty(Qty, false);
        docLine.setReversalLine_ID(line.getReversalLine_ID());
        log.fine(docLine.toString());
        list.add(docLine);
    }
    //	Return Array
    DocLine[] dls = new DocLine[list.size()];
    list.toArray(dls);
    return dls;
}
Also used : MInventoryLine(org.compiere.model.MInventoryLine) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal)

Example 8 with MInventoryLine

use of org.compiere.model.MInventoryLine 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);
    }
}
Also used : MProjectIssue(org.compiere.model.MProjectIssue) MInOutLine(org.compiere.model.MInOutLine) MMatchPO(org.compiere.model.MMatchPO) MInventoryLine(org.compiere.model.MInventoryLine) MProductionLine(org.compiere.model.MProductionLine) MMatchInv(org.compiere.model.MMatchInv) MPPCostCollector(org.eevolution.model.MPPCostCollector) MMovementLine(org.compiere.model.MMovementLine) MProduction(org.compiere.model.MProduction)

Example 9 with MInventoryLine

use of org.compiere.model.MInventoryLine 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());
}
Also used : MDocType(org.compiere.model.MDocType) MInOutLine(org.compiere.model.MInOutLine) MInventoryLine(org.compiere.model.MInventoryLine) MTransaction(org.compiere.model.MTransaction) MPPCostCollector(org.eevolution.model.MPPCostCollector) MOrderLine(org.compiere.model.MOrderLine) MMovementLine(org.compiere.model.MMovementLine)

Example 10 with MInventoryLine

use of org.compiere.model.MInventoryLine in project adempiere by adempiere.

the class InventoryUtil method createInventory.

public static MInventory createInventory(MMDocument doc, String trxName) {
    Properties ctx = Env.getCtx();
    int AD_Org_ID = getFirst_Org_ID();
    MProduct product = getCreateProduct(doc);
    MLocator locator = getCreateLocator(AD_Org_ID, doc.LocatorValue, doc.LocatorValue);
    //
    MInventory inv = new MInventory(ctx, 0, trxName);
    inv.setAD_Org_ID(AD_Org_ID);
    //inv.setIsInternalUseInventory(true); // TODO: arhipac: teo_sarca - add this column to trunk
    inv.setMovementDate(doc.Date);
    inv.setM_Warehouse_ID(locator.getM_Warehouse_ID());
    setGeneratedTag(inv);
    inv.saveEx();
    //
    MInventoryLine line = new MInventoryLine(inv, locator.get_ID(), product.get_ID(), 0, null, null);
    line.setQtyInternalUse(doc.Qty);
    line.setC_Charge_ID(getCreateCharge("junit-charge").get_ID());
    line.saveEx();
    //
    doc.document = inv;
    processDocument(doc, MInventory.DOCACTION_Complete, MInventory.DOCSTATUS_Completed);
    if (!Util.isEmpty(doc.ASI)) {
        line.load(trxName);
        doc.scenario.registerASICode(doc.ASI, line.getM_AttributeSetInstance_ID(), line.getQtyInternalUse().signum() <= 0);
    }
    checkLineCosts(doc, line, doc.Qty.signum() >= 0);
    return inv;
}
Also used : MProduct(org.compiere.model.MProduct) MInventory(org.compiere.model.MInventory) MInventoryLine(org.compiere.model.MInventoryLine) MLocator(org.compiere.model.MLocator) Properties(java.util.Properties)

Aggregations

MInventoryLine (org.compiere.model.MInventoryLine)15 BigDecimal (java.math.BigDecimal)7 MInOutLine (org.compiere.model.MInOutLine)6 MInventory (org.compiere.model.MInventory)6 MMovementLine (org.compiere.model.MMovementLine)6 MProduct (org.compiere.model.MProduct)5 MAttributeSetInstance (org.compiere.model.MAttributeSetInstance)3 MMatchInv (org.compiere.model.MMatchInv)3 MMatchPO (org.compiere.model.MMatchPO)3 MPPCostCollector (org.eevolution.model.MPPCostCollector)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 Timestamp (java.sql.Timestamp)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 MAttributeSet (org.compiere.model.MAttributeSet)2 MInventoryLineMA (org.compiere.model.MInventoryLineMA)2 MLocator (org.compiere.model.MLocator)2 MOrderLine (org.compiere.model.MOrderLine)2