Class MovementDAO

java.lang.Object
ru.bgcrm.dao.CommonDAO
org.bgerp.plugin.inventory.dao.MovementDAO

public class MovementDAO extends CommonDAO
DAO for stock Movement records and inventory_balance. Movements are append-only — never updated or deleted. Balance is maintained via INSERT ... ON DUPLICATE KEY UPDATE.
  • Constructor Details

    • MovementDAO

      public MovementDAO(Connection con)
  • Method Details

    • getById

      public Movement getById(long id) throws SQLException
      Throws:
      SQLException
    • isActiveReserve

      public boolean isActiveReserve(long reserveId) throws SQLException
      Returns true if the given reserve movement is still active, i.e. no unreserve/writeoff already references it via ref_movement_id. Used to reject a duplicate/stale unreserve request instead of silently recording a phantom cancellation on top of an already-settled reserve.
      Throws:
      SQLException
    • getListByStore

      public List<Movement> getListByStore(int storeId, int limit) throws SQLException
      Throws:
      SQLException
    • getListByProcess

      public List<Movement> getListByProcess(int processId) throws SQLException
      Throws:
      SQLException
    • append

      public void append(Movement m) throws SQLException
      Appends a movement record and updates the balance accordingly. For "reserve" adds to reserved; for "unreserve"/"writeoff"/"return" adjusts reserved/quantity.
      Parameters:
      m - movement to record
      Throws:
      IllegalStateException - if the operation would make balance negative
      SQLException
    • getBalanceItems

      public List<Map<String,Object>> getBalanceItems(Collection<Integer> storeIds) throws SQLException
      Returns balance data for given store IDs as a flat list of maps. Each map has keys: storeId, itemId, quantity, reserved. Used for JS-driven balance hints in the process materials tab.
      Throws:
      SQLException
    • getBalanceList

      public List<Map<String,Object>> getBalanceList(int storeId) throws SQLException
      Returns balance for a store as list of maps with keys: itemTitle, quantity, reserved. Ordered by item title. Only rows with quantity > 0 or reserved > 0.
      Throws:
      SQLException
    • fromRs

      public static Movement fromRs(ResultSet rs) throws SQLException
      Throws:
      SQLException