Example #1
0
    def Edit(self, ID):

        listboxid = self.staffsummarylistbox.GetSelection()
        staffid = self.staffsummarylistbox.htmllist[listboxid][0]

        success = False
        date = self.dateentry.GetValue()
        date = miscmethods.GetSQLDateFromWXDate(date)
        vet = self.vetentry.GetValue()
        timeon = self.timeonentry.GetValue()
        timeoff = self.timeoffentry.GetValue()
        if self.operatingcheckbox.GetValue() == True:
            operating = 1
        else:
            operating = 0

        if miscmethods.ValidateTime(
                timeon) == True and miscmethods.ValidateTime(timeoff) == True:
            timeonint = int(timeon[:2] + timeon[3:5])
            timeoffint = int(timeoff[:2] + timeoff[3:5])
            if timeonint < timeoffint:
                success = True
            else:
                miscmethods.ShowMessage(
                    self.GetLabel("vetfinishedbeforestartingmessage"))

        if success == True:

            dbmethods.WriteToStaffTable(self.localsettings.dbconnection, date,
                                        vet, timeon, timeoff, operating,
                                        staffid)

            self.RefreshRota()
        else:
            miscmethods.ShowMessage(self.GetLabel("invalidtimemessage"))
Example #2
0
def WriteToStaffTable(connection, date, name, position, timeon, timeoff,
                      operating, ID, localsettings):

    success = False

    if miscmethods.ValidateTime(timeon) == True and miscmethods.ValidateTime(
            timeoff) == True:

        timeonint = int(timeon[:2] + timeon[3:5])
        timeoffint = int(timeoff[:2] + timeoff[3:5])

        if timeonint < timeoffint:

            success = True
        else:

            miscmethods.ShowMessage(
                GetLabel(localsettings, "vetfinishedbeforestartingmessage"))

    if success == True:

        starttimesql = timeon[:2] + ":" + timeon[3:5] + ":00"
        offtimesql = timeoff[:2] + ":" + timeoff[3:5] + ":00"

        action = "SELECT ID FROM staff WHERE DATE = \'" + str(
            date
        ) + "\' AND Name = \'" + name + "\' AND ( \'" + starttimesql + "\' BETWEEN TimeOn AND TimeOff OR \'" + offtimesql + "\' BETWEEN TimeOn AND TimeOff OR TimeOn BETWEEN \'" + starttimesql + "\' AND \'" + offtimesql + "\' OR TimeOff BETWEEN \'" + starttimesql + "\' AND \'" + offtimesql + "\' )"
        results = db.SendSQL(action, connection)

        if len(results) > 0 and ID == False:

            miscmethods.ShowMessage(
                GetLabel(localsettings, "vettwoplacesatoncemessage"))

            success = False
        else:

            if ID == False:
                action = "INSERT INTO staff (Name, Date, Position, TimeOn, TimeOff, Operating) VALUES (\'" + name + "\', \'" + str(
                    date
                ) + "\', \'" + position + "\', \'" + timeon + "\', \'" + timeoff + "\', " + str(
                    operating) + ")"
            else:
                action = "REPLACE INTO staff (ID, Name, Date, Position, TimeOn, TimeOff, Operating) VALUES (" + str(
                    ID
                ) + ", \'" + name + "\', \'" + str(
                    date
                ) + "\', \'" + position + "\', \'" + timeon + "\', \'" + timeoff + "\', " + str(
                    operating) + ")"
            db.SendSQL(action, connection)

    else:

        miscmethods.ShowMessage(GetLabel(localsettings, "invalidtimemessage"))

    return success
Example #3
0
    def Submit(self, ID):

        success = False
        date = self.dateentry.GetValue()
        date = miscmethods.GetSQLDateFromWXDate(date)
        vet = self.vetentry.GetValue()
        timeon = self.timeonentry.GetValue()
        timeoff = self.timeoffentry.GetValue()
        if self.operatingcheckbox.GetValue() == True:
            operating = 1
        else:
            operating = 0

        if vet == "":

            miscmethods.ShowMessage(self.GetLabel("novetnamemessage"))

        else:

            if miscmethods.ValidateTime(
                    timeon) == True and miscmethods.ValidateTime(
                        timeoff) == True:
                timeonint = int(timeon[:2] + timeon[3:5])
                timeoffint = int(timeoff[:2] + timeoff[3:5])
                if timeonint < timeoffint:
                    success = True
                else:
                    miscmethods.ShowMessage(
                        self.GetLabel("vetfinishedbeforestartingmessage"))

            if success == True:

                starttimesql = timeon[:2] + ":" + timeon[3:5] + ":00"
                offtimesql = timeoff[:2] + ":" + timeoff[3:5] + ":00"

                action = "SELECT ID FROM staff WHERE DATE = \"" + date + "\" AND Vet = \"" + vet + "\" AND ( \"" + starttimesql + "\" BETWEEN TimeOn AND TimeOff OR \"" + offtimesql + "\" BETWEEN TimeOn AND TimeOff OR TimeOn BETWEEN \"" + starttimesql + "\" AND \"" + offtimesql + "\" OR TimeOff BETWEEN \"" + starttimesql + "\" AND \"" + offtimesql + "\" )"
                results = db.SendSQL(action, self.localsettings.dbconnection)

                if len(results) > 0:
                    miscmethods.ShowMessage(
                        self.GetLabel("vettwoplacesatoncemessage"))
                else:
                    dbmethods.WriteToStaffTable(
                        self.localsettings.dbconnection, date, vet, timeon,
                        timeoff, operating)

                    self.RefreshRota()
            else:
                miscmethods.ShowMessage(self.GetLabel("invalidtimemessage"))
Example #4
0
	def SubmitProcedure(self, ID):
		
		panel = ID.GetEventObject().GetParent()
		
		name = panel.nameentry.GetValue()
		
		if name == "":
			
			miscmethods.ShowMessage(self.GetLabel("proceduresunnamedproceduremessage"))
			
		else:
			
			description = panel.descriptionentry.GetValue()
			price = panel.priceentry.GetValue()
			price = str(miscmethods.ConvertPriceToPennies(price))
			
			if panel.procedureid > -1:
				
				procedureid = panel.procedureid
				
				action = "REPLACE INTO procedures (ID, Name, Description, Price) VALUES (" + str(procedureid) + ", \"" + name + "\", \"" + description + "\", \"" + price + "\")"
				db.SendSQL(action, self.localsettings.dbconnection)
				
			else:
				
				action = "INSERT INTO procedures (Name, Description, Price) VALUES (\"" + name + "\", \"" + description + "\", \"" + price + "\")"
				db.SendSQL(action, self.localsettings.dbconnection)
			
			self.RefreshList()
			
			panel.GetParent().Close()
Example #5
0
    def SubmitLookup(self, ID):

        panel = ID.GetEventObject().GetParent()

        name = panel.nameentry.GetValue()

        lookup = self.lookup
        columnname = lookup[0].upper() + lookup[1:] + "Name"

        if name == "":

            miscmethods.ShowMessage(self.GetLabel("lookupsnonamemessage"))

        else:

            if panel.lookupid == False:

                action = "INSERT INTO " + lookup + " (" + columnname + ") VALUES (\"" + name + "\")"

            else:

                action = "UPDATE " + lookup + " SET " + columnname + " = \"" + name + "\" WHERE ID = " + str(
                    panel.lookupid)

            db.SendSQL(action, self.localsettings.dbconnection)
            self.RefreshLookups()

            panel.GetParent().Close()
Example #6
0
	def Submit(self, ID):
		
		panel = ID.GetEventObject().GetParent()
		
		extension = panel.extensionentry.GetValue()
		
		program = panel.programentry.GetValue()
		
		output = ""
		
		success = True
		
		if panel.countid == -1:
			
			existingextensions = []
			
			for a in range(0, len(self.listbox.htmllist)):
				
				existingextensions.append(self.listbox.htmllist[a][1][0].strip())
				
				output = output + self.listbox.htmllist[a][1][0].strip() + "$$$" + self.listbox.htmllist[a][1][1].strip() + "\n"
			
			output = output + extension.strip() + "$$$" + program.strip()
			
			if existingextensions.__contains__(extension):
				
				success = False
				
				miscmethods.ShowMessage(self.GetLabel("fileassociationexistsmessage"))
			
		else:
			
			for a in range(0, len(self.listbox.htmllist)):
				
				if a == panel.countid:
					
					output = output + self.listbox.htmllist[a][1][0].strip() + "$$$" + program + "\n"
					
				else:
					
					output = output + self.listbox.htmllist[a][1][0].strip() + "$$$" + self.listbox.htmllist[a][1][1].strip() + "\n"
			
			output = output.strip()
		
		if success == True:
			
			pathtofiletypesfile = miscmethods.GetHome() + "/.evette/filetypes.conf"
			
			out = open(pathtofiletypesfile, "w")
			out.write(output)
			out.close()
			
			self.listbox.RefreshList()
			
			panel.GetParent().Close()
Example #7
0
	def ResetAllTables(self, ID=False):
		
		if miscmethods.ConfirmMessage(self.GetMenu("resetdatabasequestion")) == True:
			connection = db.GetConnection(self.localsettings)
			action = "DROP DATABASE evette"
			db.SendSQL(action, connection)
			connection.close()
			
			db.CreateDatabase(self.localsettings)
			
			miscmethods.ShowMessage(self.GetMenu("alltablesresetmessage"))
Example #8
0
    def AddMedia(self, ID):

        busy = wx.BusyCursor()

        filename = wx.FileSelector()

        if filename == "":

            pass

        else:

            inp = open(filename, "rb")

            size = os.path.getsize(filename)
            size = size / 1024.00

            if size > 20480:

                miscmethods.ShowMessage(self.GetLabel("mediatoolargemessage"))

            else:

                content = inp.read()
                content = base64.encodestring(content)
                inp.close()

                todaysdate = datetime.date.today()
                todayssqldate = miscmethods.GetSQLDateFromDate(todaysdate)

                uploadedby = todayssqldate + "$$$" + self.localsettings.username

                if filename.__contains__("\\"):

                    filename = filename.replace("\\", "/")

                dbmethods.WriteToMediaTable(self.localsettings.dbconnection,
                                            False, self.linktype, self.linkid,
                                            filename.split("/")[-1], "", size,
                                            content, uploadedby)

                self.listbox.RefreshList()

        del busy
Example #9
0
    def EditVetForm(self, ID):

        panel = ID.GetEventObject().panel

        listbox = panel.listbox

        notebook = self.GetGrandParent().GetParent()

        appointmentid = listbox.htmllist[listbox.GetSelection()][3]

        appointmentdata = appointmentmethods.AppointmentSettings(
            self.localsettings, False, appointmentid)
        stayingid = appointmentdata.staying
        animalid = appointmentdata.animalid

        today = datetime.date.today()

        appointmentdate = miscmethods.GetDateFromSQLDate(appointmentdata.date)

        if appointmentdate != today:

            appointmentdata.staying = 0
            appointmentdata.done = 1
            appointmentdata.withvet = 0

            appointmentdata.Submit(True)

            miscmethods.ShowMessage(self.GetLabel("animalstayedmessage"), self)

            appointmentdata = appointmentmethods.AppointmentSettings(
                self.localsettings, animalid, False)
            appointmentdata.reason = self.GetLabel("overnightstaylabel")
            appointmentdata.time = str(datetime.datetime.today().time())[:5]
            appointmentdata.arrived = 1
            appointmentdata.withvet = 1
            appointmentdata.staying = stayingid

            appointmentdata.Submit()

        vetform = vetmethods.VetForm(notebook, appointmentdata,
                                     self.localsettings, self)

        notebook.AddPage(vetform)
Example #10
0
    def Submit(self, ID):

        success = True

        if self.selectedstaffid == 0:

            staffid = False

        else:

            staffid = self.selectedstaffid

        date = miscmethods.GetSQLDateFromDate(self.date)

        name = self.nameentry.GetValue()

        if name == "":
            miscmethods.ShowMessage("No name")
            success = False

        position = self.positionentry.GetValue()
        timeon = self.inentry.GetValue()
        timeoff = self.outentry.GetValue()

        operating = self.operatingentry.GetValue()

        if operating == True:

            operating = 1

        else:

            operating = 0

        if success == True:

            if dbmethods.WriteToStaffTable(self.localsettings.dbconnection,
                                           date, name, position, timeon,
                                           timeoff, operating, staffid,
                                           self.localsettings) == True:

                self.parent.GetParent().OpenDay()
Example #11
0
    def Submit(self, ID):

        miscmethods.ShowMessage(self.GetLabel("randomdatawarningmessage"))
        RandomClientsThread(self)
Example #12
0
	def SubmitAppointment(self, ID):
		
		time = self.appointmenttimeentry.GetValue()
		
		success = False
		
		if miscmethods.ValidateTime(time) == True:
			
			if miscmethods.GetMinutesFromTime(time) < miscmethods.GetMinutesFromTime(self.appointmentdata.localsettings.opento) + 1:
				
				if miscmethods.GetMinutesFromTime(time) > miscmethods.GetMinutesFromTime(self.appointmentdata.localsettings.openfrom) - 1:
					
					time = time[:2] + ":" + time[3:5]
					success = True
				else:
					failurereason = self.GetLabel("appointmenttimetooearlymessage")
			else:
				failurereason = self.GetLabel("appointmenttimetoolatemessage")
		else:
			failurereason = self.GetLabel("appointmentinvalidtimemessage")
		
		if success == True:
			
			self.appointmentdata.date = miscmethods.GetSQLDateFromWXDate(self.appointmententry.GetValue())
			self.appointmentdata.time = time
			
			self.appointmentdata.reason = self.reasonentry.GetValue()
			self.appointmentdata.operation = 0
			if self.vetcombobox.GetValue() == "Vet":
				self.appointmentdata.vet = "None"
			else:
				self.appointmentdata.vet = self.vetcombobox.GetValue()
			
			choice = self.statuschoice.GetSelection()
			
			if choice == 0:
				self.appointmentdata.arrived = 0
				self.appointmentdata.withvet = 0
				self.appointmentdata.done = 0
			elif choice == 1:
				self.appointmentdata.arrived = 1
				self.appointmentdata.withvet = 0
				self.appointmentdata.done = 0
			elif choice == 2:
				self.appointmentdata.arrived = 1
				self.appointmentdata.withvet = 1
				self.appointmentdata.done = 0
			elif choice == 3:
				self.appointmentdata.arrived = 1
				self.appointmentdata.withvet = 0
				self.appointmentdata.done = 1
			
			self.appointmentdata.Submit()
			
			try:
				self.parent.RefreshAppointments()
			except:
				pass
			
			self.Close()
			
		else:
			
			miscmethods.ShowMessage(failurereason)
Example #13
0
    def GenerateCVSFile(self, ID=False):

        fromdate = self.fromdateentry.GetValue()
        fromdate = miscmethods.GetSQLDateFromWXDate(fromdate)
        todate = self.todateentry.GetValue()
        todate = miscmethods.GetSQLDateFromWXDate(todate)

        action = "SELECT client.ClientTitle, client.ClientSurname, client.ClientAddress, client.ClientPostcode, animal.Name, animal.Species, medication.Name, medicationout.NextDue AS NextDue FROM medicationout INNER JOIN appointment ON medicationout.AppointmentID = appointment.ID INNER JOIN animal ON appointment.AnimalID = animal.ID INNER JOIN client ON appointment.OwnerID = client.ID INNER JOIN medication ON medicationout.MedicationID = medication.ID WHERE medicationout.NextDue BETWEEN \"" + str(
            fromdate) + "\" AND \"" + str(todate) + "\""

        if self.vaccinetickbox.GetValue() == False:

            if len(self.includedvaccinationslist) == 0:

                action = action + " AND medication.Name IS NULL"

            else:

                action = action + " AND ("

                for a in self.includedvaccinationslist:

                    action = action + "medication.Name = \"" + a + "\" OR "

                action = action[:-4]

                action = action + ")"

        if self.speciestickbox.GetValue() == False:

            if len(self.includedspecieslist) == 0:

                action = action + " AND animal.Species IS NULL"

            else:

                action = action + " AND ("

                for a in self.includedspecieslist:

                    action = action + "animal.Species = \"" + a + "\" OR "

                action = action[:-4]

                action = action + ")"

        action = action + " UNION SELECT client.ClientTitle, client.ClientSurname, client.ClientAddress, client.ClientPostcode, animal.Name, animal.Species, manualvaccination.Name, manualvaccination.Next AS NextDue FROM manualvaccination INNER JOIN animal ON manualvaccination.AnimalID = animal.ID INNER JOIN client ON animal.OwnerID = client.ID WHERE manualvaccination.Next BETWEEN \"" + str(
            fromdate) + "\" AND \"" + str(todate) + "\""

        if self.vaccinetickbox.GetValue() == False:

            if len(self.includedvaccinationslist) == 0:

                action = action + " AND manualvaccination.Name IS NULL"

            else:

                action = action + " AND ("

                for a in self.includedvaccinationslist:

                    action = action + "manualvaccination.Name = \"" + a + "\" OR "

                action = action[:-4]

                action = action + ")"

        if self.speciestickbox.GetValue() == False:

            if len(self.includedspecieslist) == 0:

                action = action + " AND animal.Species IS NULL"

            else:

                action = action + " AND ("

                for a in self.includedspecieslist:

                    action = action + "animal.Species = \"" + a + "\" OR "

                action = action[:-4]

                action = action + ")"

        action = action + " ORDER BY NextDue desc"

        results = db.SendSQL(action, self.localsettings.dbconnection)

        output = "\"title\",\"surname\",\"address\",\"postcode\",\"animalname\",\"species\",\"vaccinationtype\",\"duedate\"\n"

        for a in results:

            for b in range(0, len(a)):

                if b == 7:

                    duedate = a[b]
                    duedate = miscmethods.FormatSQLDate(
                        duedate, self.localsettings)
                    output = output + "\"" + str(duedate) + "\","

                elif b == 2:

                    address = a[b]  #.replace("\n", ", ")
                    output = output + "\"" + str(address) + "\","

                else:

                    output = output + "\"" + str(a[b]) + "\","

            output = output[:-1] + "\n"

        output = output[:-1]

        path = wx.SaveFileSelector("CSV", "csv", "duevaccinations.csv")

        out = open(path, "w")
        out.write(output)
        out.close()

        miscmethods.ShowMessage(self.GetLabel("csvsavedtolabel") + " " + path)
Example #14
0
    else:

        serverpresent = True

localsettings.dbconnection = db.GetConnection(localsettings)

if localsettings.dbconnection == False:

    if db.CreateDatabase(localsettings) == False:

        sys.exit()

    else:

        miscmethods.ShowMessage(
            GetLabel("launchdatabasecreatedmessage", localsettings), None)

        localsettings.dbconnection = db.GetConnection(localsettings)

versioncheck = dbupdates.CheckVersion(localsettings)

if versioncheck == True:

    LaunchDialog(localsettings, splashimagepath)

else:

    sys.exit()

app.MainLoop()
Example #15
0
	def SubmitASMImport(self, ID):
		
		panel = ID.GetEventObject().GetGrandParent()
		
		listboxid = panel.listbox.GetSelection()
		
		if listboxid != -1:
			
			animaldata = panel.animaldata[listboxid]
			
			action = "SELECT ID FROM animal WHERE ASMRef = \"" + animaldata[0] + "\""
			results = db.SendSQL(action, self.localsettings.dbconnection)
			
			if len(results) > 0:
				
				if miscmethods.ConfirmMessage(self.GetMenu("alreadyimportedmessage"), self.notebook):
					
					animalsettings = animalmethods.AnimalSettings(self.localsettings, False, results[0][0])
					
					animalpanel = animalmethods.AnimalPanel(self.notebook, animalsettings)
					
					self.notebook.AddPage(animalpanel)
					
					panel.GetParent().Close()
				
			else:
				
				archived = animaldata[10]
				activemovementtype = animaldata[11]
				
				if archived == 0 or activemovementtype == 2:
					
					action = "SELECT ShelterID FROM settings"
					clientid = db.SendSQL(action, self.localsettings.dbconnection)[0][0]
					
					#miscmethods.ShowMessage("Animal is on shelter", panel)
					
				else:
					
					action = "SELECT owner.OwnerSurname, owner.OwnerAddress, owner.OwnerPostcode, owner.HomeTelephone, owner.MobileTelephone, owner.WorkTelephone, owner.EmailAddress, animal.ActiveMovementType, owner.OwnerTitle, owner.OwnerForenames FROM owner INNER JOIN adoption ON adoption.OwnerID = owner.ID INNER JOIN animal ON adoption.ID = animal.ActiveMovementID WHERE animal.ShelterCode = \"" + animaldata[0] + "\" AND ( animal.ActiveMovementType = 1 OR animal.ActiveMovementType = 2 ) AND animal.Archived = 1"
					results = db.SendSQL(action, panel.asmconnection)
					
					if len(results) == 1:
						
						ownersurname = results[0][0]
						
						if ownersurname == None:
							
							ownersurname = ""
						
						owneraddress = results[0][1]
						
						if owneraddress == None:
							
							owneraddress = ""
						
						owneraddress = owneraddress.replace("\r", "")
						
						ownerpostcode = results[0][2]
						
						if ownerpostcode == None:
							
							ownerpostcode = ""
						
						ownerhometelephone = results[0][3]
						
						if ownerhometelephone == None:
							
							ownerhometelephone = ""
						
						ownermobiletelephone = results[0][4]
						
						if ownermobiletelephone == None:
							
							ownermobiletelephone = ""
						
						ownerworktelephone = results[0][5]
						
						if ownerworktelephone == None:
							
							ownerworktelephone = ""
						
						owneremailaddress = results[0][6]
						
						if owneremailaddress == None:
							
							owneremailaddress = ""
						
						movementtype = results[0][7]
						
						ownertitle = results[0][8]
						
						if ownertitle == None:
							
							ownertitle = ""
						
						ownerforenames = results[0][9]
						
						if ownerforenames == None:
							
							ownerforenames = ""
						
						action = "SELECT ID, ClientTitle, ClientForenames, ClientSurname, ClientAddress FROM client WHERE ClientPostCode = \"" + ownerpostcode + "\" OR ClientSurname = \"" + ownersurname + "\""
						evetteowners = db.SendSQL(action, self.localsettings.dbconnection)
						
						possiblematches = []
						
						asmhousenumber = owneraddress.split(" ")[0]
						
						for a in evetteowners:
							
							evettehousenumber = a[4].split(" ")[0]
							
							if asmhousenumber == evettehousenumber:
								
								possiblematches.append(a)
								
							else:
								
								if ownerforenames == "" or a[2] == "" or ownerforenames == a[2]:
									
									possiblematches.append(a)
						
						selectedownerid = 0
						
						panel.chosenownerid = 0
						
						if len(possiblematches) > 0:
							
							panel.possiblematches = possiblematches
							
							dialog = wx.Dialog(panel, -1, "Possible Owners")
							
							dialog.panel = panel
							
							topsizer = wx.BoxSizer(wx.VERTICAL)
							
							sheltermanagerownerinfo = wx.StaticText(dialog, -1, ownertitle + " " + ownerforenames + " " + ownersurname + ". " + owneraddress.replace("\n", ", ") + ". " + ownerpostcode)
							
							topsizer.Add(sheltermanagerownerinfo, 0, wx.EXPAND)
							
							topsizer.Add(wx.StaticText(dialog, -1, "", size=(-1,10)))
							
							chooseownerlabel = wx.StaticText(dialog, -1, "Choose an owner")
							topsizer.Add(chooseownerlabel, 0, wx.ALIGN_LEFT)
							
							dialog.listbox = wx.ListBox(dialog)
							dialog.listbox.Bind(wx.EVT_LISTBOX_DCLICK, self.SelectOwner)
							
							for v in possiblematches:
								
								listboxoutput = v[1] + " " + v[2] + " " + v[3] + ". " + v[4].replace("\n", ", ").replace("\r", "")
								
								dialog.listbox.Append(listboxoutput)
							
							topsizer.Add(dialog.listbox, 1, wx.EXPAND)
							
							dialog.SetSizer(topsizer)
							
							
							
							dialog.ShowModal()
							
							clientid = panel.chosenownerid
							
						if panel.chosenownerid == 0:
							
							clientsettings = clientmethods.ClientSettings(self.localsettings)
							
							clientsettings.title = ownertitle
							clientsettings.forenames = ownerforenames
							clientsettings.surname = ownersurname
							clientsettings.address = owneraddress
							clientsettings.postcode = ownerpostcode
							clientsettings.hometelephone = ownerhometelephone
							clientsettings.mobiletelephone = ownermobiletelephone
							clientsettings.worktelephone = ownerworktelephone
							clientsettings.emailaddress = owneremailaddress
							clientsettings.comments = "Imported from ASM"
							
							clientsettings.Submit()
							
							clientid = clientsettings.ID
						
					else:
						
						clientid = 0
				
				if clientid > 0:
					
					animalsettings = animalmethods.AnimalSettings(self.localsettings, clientid)
					
					animalsettings.name = animaldata[1]
##					print "animaldata[2] = " + str(animaldata[2])
##					if animaldata[2] == 0:
##                                                animalsettings.sex = 2
##                                        elif animaldata[2] == 1:
##                                                animalsettings.sex = 1
##                                        else:
##                                                animalsettings.sex = 0
##                                        
##                                        print "sex = " + str(animalsettings.sex)
                                        
                                        if animaldata[2] == self.GetMenu("malelabel"):
                                                
                                                animalsettings.sex = 1
                                                
                                        elif animaldata[2] == self.GetMenu("femalelabel"):
                                                
                                                animalsettings.sex = 2
                                        else:
                                                
                                                animalsettings.sex = 0
					
					animalsettings.species = animaldata[4]
					animalsettings.breed = animaldata[5]
					animalsettings.colour = animaldata[6]
					
					dob = animaldata[7]
					
					animalsettings.dob = miscmethods.FormatDate(dob, self.localsettings)
					
					animalsettings.comments = ""
					
					animalsettings.neutered = animaldata[3]
					animalsettings.chipno = animaldata[8]
					
					if animalsettings.chipno == None:
						
						animalsettings.chipno = ""
					
					if animalsettings.comments == None:
						
						animalsettings.comments = ""
					
					animalsettings.asmref = animaldata[0]
					
					animalsettings.Submit()
					
					animalpanel = animalmethods.AnimalPanel(self.notebook, animalsettings)
					
					self.notebook.AddPage(animalpanel)
					
					panel.GetParent().Close()
					
				else:
					
					miscmethods.ShowMessage(self.GetMenu("errorobtainingownermessage"), panel)
Example #16
0
def CheckVersion(localsettings):

    success = False

    try:
        connection = db.GetConnection(localsettings)
        action = "SELECT VersionNo FROM version"
        results = db.SendSQL(action, connection)
        oldversion = results[0][0]
        connection.close()
        success = True
    except:
        if miscmethods.ConfirmMessage(
                GetLabel(localsettings, "versiontablenotfoundquestion")):

            action = "CREATE TABLE version (ID int unsigned not null auto_increment primary key, VersionNo varchar(10))"
            db.SendSQL(action, localsettings.dbconnection)

            action = "INSERT INTO version (VersionNo) VALUES (\"1.1.2\")"
            db.SendSQL(action, localsettings.dbconnection)

            oldversion = "1.1.2"

            success = True

    if success == True:

        if versionno > oldversion:

            if miscmethods.ConfirmMessage(
                    GetLabel(localsettings, "versionupdatequestion1") + " " +
                    versionno + ", " +
                    GetLabel(localsettings, "versionupdatequestion2") + " " +
                    oldversion + ". " +
                    GetLabel(localsettings, "versionupdatequestion3")):

                if oldversion == "1.1.2":

                    action = "CREATE TABLE manualvaccination (ID int unsigned not null auto_increment primary key, AnimalID int, Date date, Name varchar(50), Batch varchar(50), Next date)"
                    db.SendSQL(action, localsettings.dbconnection)

                    currenttime = datetime.datetime.today().strftime("%x %X")

                    for a in ("medication", "medicationin", "medicationout",
                              "vaccinationtype", "vaccinationin",
                              "vaccinationout", "receipt"):
                        action = "ALTER TABLE " + a + " ADD ChangeLog text"
                        db.SendSQL(action, localsettings.dbconnection)
                        action = "UPDATE " + a + " SET ChangeLog = \"" + currenttime + "%%%" + str(
                            localsettings.userid) + "\""
                        db.SendSQL(action, localsettings.dbconnection)

                    action = "REPLACE INTO version (ID, VersionNo) VALUES (1, \"1.1.3\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE settings DROP HTMLViewer"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE user ADD Permissions varchar(50)"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE user SET Permissions = \"111$11$111$11$11$11$11$111$111\""
                    db.SendSQL(action, localsettings.dbconnection)

                    oldversion = "1.1.3"

                if oldversion == "1.1.3":

                    action = "REPLACE INTO version (ID, VersionNo) VALUES (1, \"1.1.4\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    oldversion = "1.1.4"

                if oldversion == "1.1.4":

                    action = "ALTER TABLE animal ADD IsDeceased int"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE animal SET IsDeceased = 0"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE animal ADD DeceasedDate date"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE animal SET DeceasedDate = \"0000-00-00\""
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE animal ADD CauseOfDeath text"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE animal SET CauseOfDeath = \"\""
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "REPLACE INTO version (ID, VersionNo) VALUES (1, \"1.1.5\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    oldversion = "1.1.5"

                if oldversion == "1.1.5":

                    action = "DROP TABLE staff"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "CREATE TABLE staff (ID int unsigned not null auto_increment primary key, Name varchar(20), Date date, Position varchar(20), TimeOn varchar(20), TimeOff varchar(20), Operating int)"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "REPLACE INTO version (ID, VersionNo) VALUES (1, \"1.1.6\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    oldversion = "1.1.6"

                if oldversion == "1.1.6":

                    dbmethods.CreateDiaryTable(localsettings.dbconnection)

                    action = "REPLACE INTO version (ID, VersionNo) VALUES (1, \"1.1.7\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE user SET Permissions = CONCAT(Permissions, \"$111\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    oldversion = "1.1.7"

                if oldversion == "1.1.7":

                    dbmethods.CreateMediaTable(localsettings.dbconnection)

                    action = "REPLACE INTO version (ID, VersionNo) VALUES (1, \"1.1.8\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    oldversion = "1.1.8"

                if oldversion == "1.1.8":

                    dbmethods.CreateWeightTable(localsettings.dbconnection)

                    action = "ALTER TABLE medication ADD ReOrderNo int"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE medication SET ReOrderNo = 0"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "REPLACE INTO version (ID, VersionNo) VALUES (1, \"1.1.9\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    oldversion = "1.1.9"

                if oldversion == "1.1.9" or oldversion == "1.2":

                    action = "ALTER TABLE settings ADD PracticeAddress varchar(250)"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE settings ADD PracticePostcode varchar(10)"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE settings ADD PracticeTelephone varchar(20)"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE settings ADD PracticeEmail varchar(100)"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE settings ADD PracticeWebsite varchar(250)"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE settings SET PracticeAddress = \"\", PracticePostcode = \"\", PracticeTelephone = \"\", PracticeEmail = \"\", PracticeWebsite = \"\""
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE form ADD FormType varchar(50)"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE form SET FormType = \"animal\""
                    db.SendSQL(action, localsettings.dbconnection)

                    formbody = """
<p>
<<PracticeName>><br>
<<PracticeAddress>><br>
<<PracticePostcode>><br>
<<PracticeTelephone>>
</p>

<p>
<<Today>>
</p>

<p>
<<ClientName>><br>
<<ClientAddress>><br>
<<ClientPostcode>>
</p>

<p>
Dear <<ClientName>>
</p>

<p>
We have been trying to contact you unsuccessfully for some time on the following numbers:
</p>

<p>
<ul>
<li><<ClientHomeTelephone>></li>
<li><<ClientMobileTelephone>></li>
<li><<ClientWorkTelephone>></li>
</ul>
</p>

<p>
Could you please contact us on <<PracticeTelephone>> so that we can update you record.
</p>

<p>
Thank you in advance
</p>

<p>
<<PracticeName>>
</p>
"""

                    action = "INSERT INTO form (Title, Body, FormType) VALUES (\"Unable to contact letter\", \"" + formbody + "\", \"client\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    formbody = """
<h2 align=center>Invoice #<<InvoiceNumber>></h2>

<p align=center>from <<FromDate>> to <<ToDate>></p>

<table align=center>
<tr>
<td valign=top>
<fieldset>
<legend>Client</legend>
<<ClientName>><br>
<<ClientAddress>><br>
<<ClientPostcode>>
</td>
<td width=20>
</td>
<td valign=top>
<<InvoiceBreakdown>>
<br>
<table align=right>
<tr>
<td>
<fieldset>
<legend>Total</legend>
<font size=5>&pound;<<InvoiceTotal>></font>
</fieldset>
</td>
</tr>
</table>
</td>
<td width=20>
</td>
<td valign=top>
<fieldset>
<legend>Payable to</legend>
<<PracticeName>><br>
<<PracticeAddress>><br>
<<PracticePostcode>>
</fieldset>
</td>
</tr>
</table>
"""

                    action = "INSERT INTO form (Title, Body, FormType) VALUES (\"Standard Invoice\", \"" + formbody + "\", \"invoice\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    formbody = """
<table width=300 align=center>
	<tr>
		<td colspan=2 align=center>
			<font size=2><b><<PracticeName>></b></font><br>
			<font size=1><<PracticeAddress>>, <<PracticePostcode>>, <<PracticeTelephone>>.</font>
		</td>
	</tr>
	<tr>
		<td valign=top>
			<fieldset><legend><font size=1>Client</font></legend>
			<font size=1><<ClientName>><br><<ClientAddress>><br><<ClientPostcode>></font>
			</fieldset>
		</td>
		<td valign=top>
			<fieldset><legend><font size=1>Animal</font></legend>
			<font size=1><<AnimalName>><br><<AnimalSpecies>><br><<AnimalColour>></font>
			</fieldset>
		</td>
	</tr>
	<tr>
		<td colspan=2>
			<fieldset><legend><div><font size=1>Medication</font></div></legend>
			<font size=2><b><<MedicationName>> x <<Quantity>></b></font>
			</fieldset>
		</td>
	</tr>
	<tr>
		<td colspan=2>
			<fieldset><legend><font size=1>Instructions</font></legend>
			<font size=2><b><<Instructions>></b></font>
			</fieldset>
		</td>
	</tr>
	<tr>
		<td colspan=2 align=center>
			<font size=1>Keep all medicines out of reach of children<br>ANIMAL TREATMENT ONLY</font>
		</td>
	</tr>
</table>
"""

                    action = "INSERT INTO form (Title, Body, FormType) VALUES (\"Medication Label\", \"" + formbody + "\", \"medication\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE medication ADD ExpiryDate date"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE medication SET ExpiryDate = \"0000-00-00\""
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "CREATE TABLE invoice (ID int unsigned not null auto_increment primary key, ClientID int, FromDate date, ToDate date, Total int, Body text, Paid int)"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "REPLACE INTO version (ID, VersionNo) VALUES (1, \"1.2.1\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    oldversion = "1.2.1"

                if oldversion == "1.2.1":

                    action = "ALTER TABLE medication ADD Type int"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE medication SET Type = 0"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE medicationout ADD NextDue date"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE medicationout SET NextDue = \"0000-00-00\""
                    db.SendSQL(action, localsettings.dbconnection)

                    try:

                        action = "SELECT * FROM vaccinationtype"
                        results = db.SendSQL(action,
                                             localsettings.dbconnection)

                        action = "SELECT * FROM vaccinationin"
                        vaccinationindata = db.SendSQL(
                            action, localsettings.dbconnection)

                        action = "SELECT * FROM vaccinationout"
                        vaccinationoutdata = db.SendSQL(
                            action, localsettings.dbconnection)

                        for a in results:

                            #VaccinationType --- (ID, Name, Description, CurrentBatch, Price, ChangeLog)

                            #MedicationType --- (ID, Name, Description, Unit, BatchNo, CurrentPrice, ChangeLog, ReOrderNo, ExpiryDate)

                            vaccinationid = a[0]

                            action = "INSERT INTO medication (Name, description, Unit, BatchNo, CurrentPrice, ChangeLog, ReOrderNo, ExpiryDate, Type) VALUES (\"" + a[
                                1] + "\", \"" + a[2] + "\", \"" + GetLabel(
                                    localsettings, "vaccinationsvaccinelabel"
                                ).lower() + "\", \"" + a[3] + "\", " + str(
                                    a[4]
                                ) + ", \"" + a[5] + "\", 0, \"0000-00-00\", 1)"
                            db.SendSQL(action, localsettings.dbconnection)

                            #action = "SELECT LAST_INSERT_ID() FROM medication"
                            action = "SELECT ID from medication ORDER BY ID DESC LIMIT 1"
                            medicationid = db.SendSQL(
                                action, localsettings.dbconnection)

                            #print 'medicationid', type(medicationid), medicationid

                            if type(medicationid) in [
                                    type(['array']),
                                    type(('touple'))
                            ]:

                                pass

                            medicationid = medicationid[0][0]

                            print 'medicationid', type(
                                medicationid), medicationid

                            for b in vaccinationindata:
                                if a[0] == b[1]:

                                    #Vaccinationin --- (ID, VaccinationID, Date, Amount, BatchNo, Expires, WhereFrom, ChangeLog)

                                    #Medicationin --- (ID, MedicationID, Date, Amount, BatchNo, Expires, WhereFrom, ChangeLog)

                                    action = "INSERT INTO medicationin (MedicationID, Date, Amount, BatchNo, Expires, WhereFrom, ChangeLog) VALUES (" + \
                                    str(medicationid) + ", \"" + str(b[2]) + "\", \"" + str(b[3]) + "\", \"" + b[4] + "\", \"" + str(b[5]) + "\", \"" + b[6] + "\", \"" + b[7] + "\")"

                                    db.SendSQL(action,
                                               localsettings.dbconnection)

                            for b in vaccinationoutdata:

                                if a[0] == b[1]:

                                    #Vaccinationout --- (ID, VaccinationID, Date, Amount, BatchNo, WhereTo, AppointmentID, NextDue, ChangeLog)

                                    #Medicationout --- (ID, MedicationID, Date, Amount, BatchNo, WhereTo, AppointmentID, ChangeLog, NextDue)

                                    action = "INSERT INTO medicationout (MedicationID, Date, Amount, BatchNo, WhereTo, AppointmentID, ChangeLog, NextDue) VALUES (" + str(
                                        medicationid
                                    ) + ", \"" + str(b[2]) + "\",  \"" + str(
                                        b[3]
                                    ) + "\", \"" + b[4] + "\", \"" + str(
                                        b[5]) + "\", " + str(
                                            b[6]
                                        ) + ", \"" + b[8] + "\", \"" + str(
                                            b[7]) + "\")"

                                    db.SendSQL(action,
                                               localsettings.dbconnection)

                        action = "DROP TABLE vaccinationtype"
                        db.SendSQL(action, localsettings.dbconnection)

                        action = "DROP TABLE vaccinationin"
                        db.SendSQL(action, localsettings.dbconnection)

                        action = "DROP TABLE vaccinationout"
                        db.SendSQL(action, localsettings.dbconnection)

                    except:

                        print "Vaccination tables not found - ignored!"

                    action = "REPLACE INTO version (ID, VersionNo) VALUES (1, \"1.2.2\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    oldversion = "1.2.2"

                if oldversion == "1.2.2":

                    dbmethods.CreateKennelTables(localsettings.dbconnection)

                    action = "ALTER TABLE appointment ADD Staying int"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE appointment SET Staying = 0"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE animal ADD ASMRef varchar(10)"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE animal SET ASMRef = \"\""
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE settings ADD ShelterID int"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE settings SET ShelterID = 0"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "CREATE TABLE reason (ID int unsigned not null auto_increment primary key, ReasonName varchar(200))"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "REPLACE INTO version (ID, VersionNo) VALUES (1, \"1.2.3\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    oldversion = "1.2.3"

                if oldversion == "1.2.3":

                    action = "ALTER TABLE appointment ADD ArrivalTime time"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE appointment SET ArrivalTime = NULL"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "SELECT ID, Permissions FROM user"
                    results = db.SendSQL(action, localsettings.dbconnection)

                    for a in results:

                        permissions = a[1]

                        permissions = permissions[:30] + "1" + permissions[30:]

                        action = "UPDATE user SET Permissions = \"" + str(
                            permissions) + "\" WHERE ID = " + str(a[0])
                        db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE medication ADD CostPrice int"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE medication SET CostPrice = 0"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "REPLACE INTO version (ID, VersionNo) VALUES (1, \"1.2.6\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    oldversion = "1.2.6"

                if oldversion == "1.2.6":

                    action = "ALTER TABLE settings ADD MarkupMultiplyBy varchar(10)"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE settings SET MarkupMultiplyBy = \"1.175\""
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE settings ADD MarkupRoundTo int"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE settings SET MarkupRoundTo = 5"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "REPLACE INTO version (ID, VersionNo) VALUES (1, \"1.2.7\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    oldversion = "1.2.7"

                if oldversion == "1.2.7":

                    dbmethods.CreateLostAndFoundTables(
                        localsettings.dbconnection)

                    action = "ALTER TABLE client ADD PhonePermissions int"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE client SET PhonePermissions = 0"
                    db.SendSQL(action, localsettings.dbconnection)

                    animalsexes = []

                    action = "ALTER TABLE animal ADD TempSex int"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE animal SET TempSex = 0"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE animal SET TempSex = 1 WHERE Sex = \"" + GetLabel(
                        localsettings, "malelabel") + "\""
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE animal SET TempSex = 2 WHERE Sex = \"" + GetLabel(
                        localsettings, "femalelabel") + "\""
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE animal MODIFY Sex int"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE animal SET Sex = TempSex"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE animal DROP TempSex"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "REPLACE INTO version (ID, VersionNo) VALUES (1, \"1.2.8\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    oldversion = "1.2.8"

                if oldversion == "1.2.8":

                    action = "REPLACE INTO version (ID, VersionNo) VALUES (1, \"1.2.9\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    oldversion = "1.2.9"

                if oldversion == "1.2.9":

                    action = "REPLACE INTO version (ID, VersionNo) VALUES (1, \"1.3\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    oldversion = "1.3"

                if oldversion == "1.3":

                    action = "REPLACE INTO version (ID, VersionNo) VALUES (1, \"1.3.1\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    oldversion = "1.3.1"

                if oldversion == "1.3.1":

                    action = "ALTER TABLE settings ADD ASMVaccinationID int"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE settings SET ASMVaccinationID = 0"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "ALTER TABLE settings ADD PrescriptionFee int"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "UPDATE settings SET PrescriptionFee = 0"
                    db.SendSQL(action, localsettings.dbconnection)

                    action = "SELECT ID, Permissions FROM user"
                    results = db.SendSQL(action, localsettings.dbconnection)

                    for a in results:

                        permissions = a[1]

                        permissions = permissions[:31] + "0" + permissions[31:]

                        action = "UPDATE user SET Permissions = \"" + str(
                            permissions) + "\" WHERE ID = " + str(a[0])
                        db.SendSQL(action, localsettings.dbconnection)

                    action = "REPLACE INTO version (ID, VersionNo) VALUES (1, \"1.3.2\")"
                    db.SendSQL(action, localsettings.dbconnection)

                    oldversion = "1.3.2"

                    home = miscmethods.GetHome()
                    out = open(home + "/.evette.conf", "w")
                    out.write(localsettings.dbip + "\n" +
                              localsettings.dbuser + "\n" +
                              localsettings.dbpass + "\n\nuser\n" +
                              str(localsettings.language) + "\n15")
                    out.close()

            else:

                success = False

        elif versionno < oldversion:

            miscmethods.ShowMessage(
                GetLabel(localsettings, "clientolderthanservermessage"))

            success = False

    return success