]>
Softwares of Agnibho - librevax.git/blob - inventory.py
2 # Copyright (C) 2024 Dr. Agnibho Mondal
3 # This file is part of LibreVax.
4 # LibreVax is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
5 # LibreVax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
6 # You should have received a copy of the GNU General Public License along with LibreVax. If not, see <https://www.gnu.org/licenses/>.
8 def create ( cursor
, data
, available
):
10 cursor
. execute ( "INSERT INTO inventory (mid, vaccine, altname, dose, dpv, route, batch, doe, available, data) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" , ( data
[ "mid" ], data
[ "vaccine" ], data
[ "altname" ], data
[ "dose" ], data
[ "dpv" ], data
[ "route" ], data
[ "batch" ], data
[ "doe" ], available
, "" ))
11 if ( cursor
. rowcount
== 0 ):
12 return ( False , "Failed to create record." )
14 return ( True , cursor
. lastrowid
)
15 except Exception as e
:
19 def read ( cursor
, iid
):
21 result
= cursor
. execute ( "SELECT * FROM inventory WHERE iid=?" , ( iid
,))
22 if ( cursor
. rowcount
== 0 ):
23 return ( False , "Record not found." )
25 return ( True , result
. fetchone ())
26 except Exception as e
:
29 def update ( cursor
, iid
, data
, available
):
31 cursor
. execute ( "UPDATE inventory SET vaccine=?, altname=?, dose=?, dpv=?, route=?, batch=?, doe=?, available=? WHERE iid=?" , ( data
[ "vaccine" ], data
[ "altname" ], data
[ "dose" ], data
[ "dpv" ], data
[ "route" ], data
[ "batch" ], data
[ "doe" ], available
, iid
))
32 if ( cursor
. rowcount
== 0 ):
33 return ( False , "Failed to update record." )
35 return ( True , cursor
. lastrowid
)
36 except Exception as e
:
39 def delete ( cursor
, iid
):
41 cursor
. execute ( "DELETE FROM inventory WHERE iid=?" , ( iid
,))
42 if ( cursor
. rowcount
== 0 ):
43 return ( False , "Failed to delete record." )
45 return ( True , cursor
. lastrowid
)
46 except Exception as e
:
49 def list ( cursor
, mid
, all
= False ):
52 result
= cursor
. execute ( "SELECT * FROM inventory WHERE mid=? ORDER BY available DESC" , ( mid
,))
54 result
= cursor
. execute ( "SELECT * FROM inventory WHERE mid=? AND available=?" , ( mid
, True ))
55 if ( cursor
. rowcount
== 0 ):
56 return ( False , "Record not found." )
58 return ( True , result
. fetchall ())
59 except Exception as e
: