Class DeviceAccountingService

java.lang.Object
org.bgerp.plugin.inventoru.service.DeviceAccountingService

public class DeviceAccountingService extends Object
Keeps a unit and the balance of its position in step whenever the unit itself is saved, deleted or restored — from its card, from the equipment import or from the 1C stock import. A unit is counted on a store when its position is serial tracked, it stands on that store and it is not deleted; the balance of the position there is never below the units counted. Writing device.store_id directly, as the card and the import used to, put ten units on a store whose balance stayed zero, and the first write-off there then failed on a discrepancy nobody could explain. Here a unit is put on a store, moved or refused, and only through a movement when the balance has to change. Units not counted — position without serial tracking, or none — are saved as before.
  • Constructor Details

    • DeviceAccountingService

      public DeviceAccountingService(Connection con)
  • Method Details

    • normalize

      public void normalize(Device before, Device after) throws SQLException
      Applies what the configuration says about a unit becoming decommissioned: it goes back to the main store. On a store 1C keeps it stays — the return is 1C's document, and the next stock import moves it; the card says so.
      Throws:
      SQLException
    • plan

      What saving after over before means for the balance; nothing is written.
      Parameters:
      before - the unit as stored now, null for a new one
      Throws:
      SQLException
    • describe

      public String describe(DeviceAccountingService.Plan plan) throws SQLException
      Returns:
      a line for a preview: what the balance will see, or why it is refused.
      Throws:
      SQLException
    • save

      public DeviceAccountingService.Plan save(Device before, Device after, int userId, DeviceAccountingService.Source source, String comment) throws SQLException, BGMessageException
      Saves the unit and writes the movement its new place requires, in the caller's transaction.
      Parameters:
      before - the unit as stored now, null for a new one; after.id matches it
      comment - comment of the movement, says where the change came from
      Throws:
      BGMessageException - refused; nothing has been written
      SQLException
    • checkDelete

      public void checkDelete(Device device) throws SQLException, BGMessageException
      Refuses to delete a counted unit: it would stop being counted while the balance it makes up stays.
      Throws:
      SQLException
      BGMessageException
    • restore

      public void restore(Device device, int userId) throws SQLException, BGMessageException
      Restores a deleted unit. Coming back counted, it takes a place in the balance: against a balance no unit backs, if there is one; otherwise a receipt. On a store 1C keeps it comes back off every store — 1C places it.
      Throws:
      SQLException
      BGMessageException
    • isSerialTracked

      public boolean isSerialTracked(int itemId) throws SQLException
      Throws:
      SQLException
    • checkWriteoffUnit

      public void checkWriteoffUnit(Device device) throws SQLException, BGMessageException
      Refuses to write a unit off a warehouse by hand when that would not do what it promises. The write-off of one unit is the way out for equipment entered by mistake: it drops the balance by one and takes the unit off the books. That only holds for a position counted per unit — under a plain one the movement would lower the balance and leave the card standing on the warehouse, the very divergence this service exists to prevent. On a warehouse whose serial numbers 1C keeps the write-off would be undone by the next stock import, which sees the unit still standing there and proposes to bring it back.
      Throws:
      SQLException
      BGMessageException
    • canWriteoffUnit

      public boolean canWriteoffUnit(Device device) throws SQLException
      Whether writing this unit off by hand would go through — what the card asks before it draws the button. A button that is always refused on click is worse than no button: the person types a reason, presses save and is told the action was never possible.
      Throws:
      SQLException
    • uncovered

      public BigDecimal uncovered(int itemId, int storeId) throws SQLException
      Returns:
      balance of the position on the store minus the units counted there
      Throws:
      SQLException