Skip to content

Commit

Permalink
Merge branch 'feature/notify-outstanding-dailies-on-borrow' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsher committed Dec 5, 2023
2 parents c05aeda + a843c1a commit eb42612
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
52 changes: 52 additions & 0 deletions src/devicekiosk.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class UI(QObject):
showDailyLoanerChargerScreenSignal = Signal(None)
showFinishDailyBorrowSignal = Signal(None)
showFinishDailyReturnSignal = Signal(None)
showOutstandingLoansSignal = Signal(str)

firstName = ""
lastName = ""
Expand Down Expand Up @@ -471,6 +472,57 @@ def dailyReport(self):
if (self.config["print_daily_report"] == True):
lpr = subprocess.Popen("/usr/bin/lpr", stdin=subprocess.PIPE)
lpr.communicate(bytes(body, 'utf-8'))

@Slot()
def checkForOustandingLoans(self):
print("Checking for outstanding loans")

loanedDevices = ""

deviceType = ""
if (self.serviceMode == ServiceMode.dailyDeviceBorrow):
deviceType = "Laptop"
elif (self.serviceMode == ServiceMode.dailyChargerBorrow):
deviceType = "Charger"

print("Email adddress: " + self.emailAddress.lower())
print("Device type: " + deviceType)

try:
# Connect to DB and create a cursor
path = os.path.dirname(os.path.abspath(__file__))
db = os.path.join(path,'daily.db')
sqliteConnection = sqlite3.connect(db)
cursor = sqliteConnection.cursor()

# Write a query and execute it with cursor
query = "SELECT Serial FROM DAILY WHERE Date_Returned IS NULL AND Email = ? AND Device = ?"
args = (self.emailAddress.lower(), deviceType)
print(args)
#cursor.execute(query, args)

# Fetch and output result
result = cursor.execute(query, args).fetchall()
print(result)
if (len(result) > 0):
for entry in result:
print(entry[0])
loanedDevices += entry[0] + " "
self.showOutstandingLoansSignal.emit(loanedDevices)

# Close the cursor
cursor.close()

# Handle errors
except sqlite3.Error as error:
print('Error occurred - ', error)

# Close DB Connection irrespective of success
# or failure
finally:
if sqliteConnection:
sqliteConnection.close()
print('SQLite Connection closed')

def emailDailyReport(self, body):
msg = EmailMessage()
Expand Down
16 changes: 14 additions & 2 deletions src/qml/DailyLoanerDevice.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import QtQuick.Controls
import QtQuick.Layouts

Item {
Connections {
target: ui

function onShowOutstandingLoansSignal(serials) {
txtInstructions.text += "\nNOTE: The following device(s) are currently checked out by this student: " + serials + "\n"
}
}

function verifyForm() {
if (inputSerial.text.toString().length > 0) {
Expand All @@ -16,15 +23,16 @@ Item {

function setFocus() {
inputSerial.focus = true
inputSerial.forceActiveFocus()
inputSerial.forceActiveFocus()
}


ColumnLayout {
anchors.fill: parent
// spacing: 2

Text {
id: txtEmail
id: txtInstructions
Layout.fillWidth: true
Layout.fillHeight: true

Expand All @@ -34,6 +42,10 @@ Item {
wrapMode: Text.WordWrap
font.pointSize: 30

Component.onCompleted: {
ui.checkForOustandingLoans()
}

}

// AnimatedImage {
Expand Down

0 comments on commit eb42612

Please sign in to comment.