javascript - Handle sale transactions when webapp goes offline -


my web application (point of sale) handles sales on multiple branches. each sale has unique integer id. sale id on branch 1 n, next sale on branch 2 n+1.

when branch looses internet connectivity, save sale information on browser internal database, sale id last sale id plus one. when connectivity restored send info server , store in real database.

nightmare happens when 2 or more branches loose internet connectivity. because when make sale offline , internet comes on, server receive 2 sales same id, horrible because customer ticket has been printed !

my plan now, make each sale id mix branch id , branch actual sale number. branch 1 sale id 1-1, , next sale branch 2 2-1. sounds until brach has 2 points of sale, not case, isn't future proof.

what think best approach ? there better way of doing ?

the safe way avoid id collisions on single id server allocated ids. if pos goes offline, may want allocate local , temporary ids recording sale locally , when pos comes online, fetch real ids server , modify local ids real ids before sending transactions. had system once used negative numbers denote client-created ids , positive numbers server-create ids. when server received negative id, change uniquely created server id , return id client client update it's database real transaction id.

if want/need client-defined ids globally unique, each pos client needs server-assigned uniqueid can part of multi-part compound id. then, each client can maintain it's own counter that, when combined it's unique client-id globally unique id. it's extension of branchid concept except it's clientid uniquely assigned every client can have multiple pos clients @ each branch. assigning clientid can either done manually @ client setup time or can done more dynamically asking server unique clientid during setup or intialization process.

which technique practical depends on lot more of system you've describe here you'll either have pick based on knowledge of or describe more how system works able more.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -