---
# System prepended metadata

title: mPOS / Transaction and Receipt printing completeness
tags: [mPOS]

---

---
tags: mPOS
---
<style>
.mermaid{
margin:-70px;
}
</style>

# mPOS / Transaction and Receipt printing completeness
[toc]


## **Current**: Insert DB commit Then invoke Print

```plantuml
@startuml
skinparam default {
    FontSize 16
}
skinparam sequence {
    MessageAlign center
    LifelineBorderColor grey
}
skinparam lifelineStrategy nosolid
participant "mPOS\n(iPad)" as mpos
box RPi #lightblue
  participant "mPOS API\n(Java)" As api
  participant "MQTT\nBroker\n(mosquitto)" as broker
  participant "Printer\n(Python)" as printer
end box
database    "SC DB" as SC
mpos -> api : POST /transaction
...
...
api ->>  api: - Get DB connection\n- conn.autoCommit = false 

api -> SC++ :  insert THD
SC --> api-- :
api -> SC++ :  batch insert TDL
SC --> api-- :
api -> SC++: commit
SC --> api-- 

api -> broker : send printjob message

par #transparent
 broker -> printer++ : send message
 printer -> broker-- : send reply message
else
  api ->> api : Lock thread and wait max 5s

end

alt #transparent Receive Message in 5s
  broker -> api : send message
  alt #transparent Print SUCCESS (status == 2)
      api --> mpos : Transaction SUCCESS
  else Print FAILED (status != 2)
      api --> mpos : Transaction SUCCESS / Print FAILED
  end
else TIMEOUT (5s)
  api --> mpos : Transaction SUCCESS / Print FAILED
end


@enduml
``` 

## Previous: Conditional insert DB commit after print attempt
```plantuml
@startuml
skinparam default {
    FontSize 16
}
skinparam sequence {
    MessageAlign center
    LifelineBorderColor grey
}
skinparam lifelineStrategy nosolid
participant "mPOS\n(iPad)" as mpos
box RPi #lightblue
  participant "mPOS API\n(Java)" As api
  participant "MQTT\nBroker\n(mosquitto)" as broker
  participant "Printer\n(Python)" as printer
end box
database    "SC DB" as SC
mpos -> api++ : POST /transaction
...
...
api ->>  api: - Get DB connection\n- conn.autoCommit = false 

api -> SC++ :  insert THD
SC --> api-- :
api -> SC++ :  batch insert TDL
SC --> api-- :
api -> broker : send printjob message (MQTT)

par #transparent
 broker -> printer++ : send message
 printer -> broker-- : send reply message
else
  api ->> api : Lock thread and wait max 5s

end


alt #transparent Receive Message in 5s
  broker -> api : send message  (MQTT)
  alt Print SUCCESS (status == 2)/OUT OF PAPER/COVER OPEN
      api -> SC++: commit
      SC --> api-- :
      api --> mpos : Transaction SUCCESS
      ...
  else Print FAILED (status != 2 (DISCONNECT, TIMEOUT...))
      api -> SC++: rollback
      SC --> api-- :
      api --> mpos : Transaction FAILED
      ...
  end
 
else TIMEOUT (5s)
  api -> SC++: rollback
  SC --> api-- :    
  api --> mpos-- : Transaction FAILED
end




@enduml
``` 

