def adminViewPurchase():
    try:
        if adminLoginSession() == 'admin':
            purchaseDAO = PurchaseDAO()
            purchaseVOList = purchaseDAO.viewPurchase()
            print("__________________", purchaseVOList)
            loginVO = LoginVO()
            loginDAO = LoginDAO()
            packageVO = PackageVO()
            packageDAO = PackageDAO()
            purchaseDictList = [i.as_dict() for i in purchaseVOList]
            print('$$$$$$$$$$$$$$$$', purchaseDictList)

            loginVO.loginId = purchaseDictList[0]['purchase_loginId']
            packageVO.packageId = purchaseDictList[0]['purchase_packageId']

            packageVOList = packageDAO.viewUserPackage(packageVO)
            loginVOList = loginDAO.registerLogin(loginVO)
            print('ok')
            return render_template('admin/viewPurchase.html',
                                   purchaseVOList=purchaseVOList,
                                   packageVOList=packageVOList,
                                   loginVOList=loginVOList)
        else:
            adminLogoutSession()
    except Exception as ex:
        print(ex)
def adminUpdateTrafficPoliceStation():
    try:
        if adminLoginSession() == 'admin':
            trafficPoliceStationId = request.form['trafficPoliceStationId']
            trafficPoliceStationUsername = request.form[
                'trafficPoliceStationUsername']
            trafficPoliceStationName = request.form['trafficPoliceStationName']
            trafficPoliceStation_AreaId = request.form[
                'trafficPoliceStation_AreaId']
            trafficPoliceStationAddress = request.form[
                'trafficPoliceStationAddress']
            trafficPoliceStationContact = request.form[
                'trafficPoliceStationContact']
            trafficPoliceStation_LoginId = request.form[
                'trafficPoliceStation_LoginId']

            trafficPoliceStationVO = TrafficPoliceStationVO()
            trafficPoliceStationDAO = TrafficPoliceStationDAO()

            loginVO = LoginVO()
            loginDAO = LoginDAO()

            loginVO.loginId = trafficPoliceStation_LoginId
            loginVOList = loginDAO.registerLogin(loginVO)
            loginDictList = [i.as_dict() for i in loginVOList]

            loginVO.loginId = loginDictList[0]['loginId']
            loginVO.loginUsername = trafficPoliceStationUsername
            loginVO.loginPassword = loginDictList[0]['loginPassword']
            loginVO.loginStatus = loginDictList[0]['loginStatus']
            loginVO.loginRole = loginDictList[0]['loginRole']
            loginDAO.updateLogin(loginVO)
            trafficPoliceStationVO.trafficPoliceStationId = trafficPoliceStationId
            trafficPoliceStationVO.trafficPoliceStationName = trafficPoliceStationName
            trafficPoliceStationVO.trafficPoliceStationAddress = trafficPoliceStationAddress
            trafficPoliceStationVO.trafficPoliceStationContact = trafficPoliceStationContact
            trafficPoliceStationVO.trafficPoliceStation_AreaId = trafficPoliceStation_AreaId
            trafficPoliceStationVO.trafficPoliceStation_LoginId = trafficPoliceStation_LoginId
            trafficPoliceStationDAO.updateTrafficPoliceStation(
                trafficPoliceStationVO)

            return redirect(url_for('adminViewTrafficPoliceStation'))
        else:
            adminLogoutSession()
    except Exception as ex:
        print(ex)