Class MovementDAO

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

public class MovementDAO extends CommonDAO
DAO for stock Movement records and inventoru_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
    • transfer

      public void transfer(int fromStoreId, int toStoreId, int itemId, BigDecimal qty, int processId, int userId, String serialNumber, String comment) throws SQLException
      Moves quantity from one store to another as a linked pair of movements (append-only, same pattern as reserve/unreserve and writeoff/receipt-reversal): the source row (type=transfer) debits fromStoreId and records toStoreId in related_store_id, the destination row (type=transfer_in) credits toStoreId, records fromStoreId in related_store_id, and links back via ref_movement_id — so the movement list can show "→ Title"/"← Title" on each side and the two legs of any transfer can always be found from either one. Caller is responsible for the available-quantity check and for committing.
      Throws:
      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: itemId, itemTitle, itemTypeId, quantity, reserved. Ordered by item title. Only rows with quantity > 0 or reserved > 0. itemTypeId lets the caller split consumables from asset-kind items (see ItemTypeProperties) without a second query.
      Throws:
      SQLException
    • fromRs

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