示例#1
0
def GetBalance(clientdata, localsettings):

    connection = db.GetConnection(localsettings)

    action = "SELECT receipt.Price FROM receipt WHERE receipt.Type = 4 AND receipt.TypeID = " + str(
        clientdata.ID)

    balanceresults1 = db.SendSQL(action, connection)

    action = "SELECT receipt.Price FROM appointment INNER JOIN receipt ON appointment.ID = receipt.AppointmentID WHERE appointment.OwnerID = " + str(
        clientdata.ID)

    balanceresults2 = db.SendSQL(action, connection)

    connection.close()

    balanceresults = balanceresults1 + balanceresults2

    balance = 0

    for a in balanceresults:

        balance = balance + a[0]

    return balance
示例#2
0
文件: evette.py 项目: tuksik/evette
	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"))
示例#3
0
def CheckDBConnection():

    localsettings = settings.settings(False)
    success = False
    try:
        localsettings.GetSettings()
        connection = db.GetConnection(localsettings)
        connection.close()
        success = True
    except:
        pass

    return success
示例#4
0
def GenerateDayPlan(localsettings, sqldate, step):

    openfromraw = localsettings.openfrom
    openfromtime = (int(str(openfromraw)[:2]) * 60) + int(
        str(openfromraw)[3:5])

    opentoraw = localsettings.opento
    opentotime = (int(str(opentoraw)[:2]) * 60) + int(str(opentoraw)[3:5])

    connection = db.GetConnection(localsettings)
    action = "SELECT * FROM staff WHERE Date = \"" + str(sqldate) + "\""
    results = db.SendSQL(action, connection)
    connection.close()

    vetnames = []
    vetdata = []
    colours = ("red", "#cbd202", "green", "blue")
    colourcount = 0
    for a in results:
        if vetnames.__contains__(a[1]) == False:
            vetnames.append(a[1])

        colour = colours[colourcount]
        vetdata.append((a[1], a[3], a[4], colour, a[5]))

    output = "<table><tr><td valign=bottom><u><font size=2>" + localsettings.dictionary[
        "timelabel"][localsettings.language] + "</font></u></td>"
    for a in vetnames:
        output = output + "<td valign=bottom><u><font size=2>" + a + "</font></u></td>"
    output = output + "<td valign=bottom><u><font size=2>" + localsettings.dictionary[
        "animalappointmentslabel"][
            localsettings.
            language] + "</font></u></td><td valign=bottom><u><font size=2>" + localsettings.dictionary[
                "operationslabel"][
                    localsettings.language] + "</font></u></td><tr>"

    columncount = len(vetnames)

    rowcount = (opentotime - openfromtime) / step
    rowcount = rowcount + 1

    lasttime = 0
    time = openfromtime

    for a in range(0, rowcount):

        timestring = GetTimeFromMinutes(time)

        output = output + "<tr height=100><td valign=top><font size=1>" + timestring + "<br></font></td>"

        noofvets = 0

        for b in range(0, columncount):

            colourcount = b
            while colourcount > len(colours) - 1:
                colourcount = colourcount - len(colours)
            colour = colours[colourcount]

            vetname = vetnames[b]

            success = False

            for c in range(0, len(vetdata)):

                openfromb = vetdata[c][1]
                openfrombint = (int(openfromb[:2]) * 60) + int(openfromb[3:5])

                opentob = vetdata[c][2]
                opentobint = (int(opentob[:2]) * 60) + int(opentob[3:5])

                vetnameb = vetdata[c][0]

                if vetdata[c][4] == 0:
                    roleb = localsettings.dictionary["consultinglabel"][
                        localsettings.language].lower()
                else:
                    roleb = localsettings.dictionary["operatinglabel"][
                        localsettings.language].lower()

                if time > openfrombint - 1 and time < opentobint + 1 and vetnameb == vetname:
                    output = output + "<td bgcolor=" + colour + "><font size=1 color=white>" + roleb + "</font></td>"
                    success = True
                    noofvets = noofvets + 1
                    break

            if success == False:
                output = output + "<td></td>"

        appointmenttime = GetTimeFromMinutes(time) + ":00"
        nextappointmenttime = GetTimeFromMinutes(time + step - 1) + ":59"
        connection = db.GetConnection(localsettings)
        action = "SELECT ID FROM appointment WHERE Date = \"" + sqldate + "\" AND Time BETWEEN \"" + appointmenttime + "\" AND \"" + nextappointmenttime + "\" AND Operation = 0"
        results = db.SendSQL(action, connection)
        connection.close()
        noofappointments = len(results)
        noofspaces = (float(step) / 10) * float(noofvets)

        if float(noofappointments) > noofspaces:
            appointmentcolour = "red"
        else:
            appointmentcolour = "green"

        output = output + "<td align=center><font size=2 color=" + appointmentcolour + "><b>" + str(
            noofappointments) + "</b></font></td>"

        if a == 0:
            connection = db.GetConnection(localsettings)
            action = "SELECT ID FROM appointment WHERE Date = \"" + sqldate + "\" AND Operation = 1"
            results = db.SendSQL(action, connection)
            connection.close()

            noofappointments = len(results)
            output = output + "<td align=center><font size=2><b>" + str(
                noofappointments) + "</b></font></td></tr>"
        else:
            output = output + "<td></td></tr>"

        lasttime = time
        time = time + step

    output = output + "</table>"

    return output
示例#5
0
def OpenMedia(mediaid, formname=False):

    if mediaid != False:

        localsettings = settings.settings(False)
        localsettings.GetSettings()

        connection = db.GetConnection(localsettings)
        action = "SELECT FileName, Content FROM media WHERE ID = " + str(
            mediaid)
        results = db.SendSQL(action, connection)
        connection.close()

        filename = results[0][0]
        content = results[0][1]

        output = base64.decodestring(content)

        if filename.__contains__("."):

            fileextension = filename.split(".")[-1]

        else:

            fileextension = ""

        targetfile = WriteToTempFolder(filename, output)

        out = open(targetfile, "wb")
        out.write(output)
        out.close()

    else:

        if formname.__contains__("."):

            fileextension = formname.split(".")[-1]

        else:

            fileextension = ""

        targetfile = pathtotempfolder = GetHome() + "/.evette/temp/" + formname

    pathtofiletypesfile = GetHome() + "/.evette/filetypes.conf"

    if os.path.isfile(pathtofiletypesfile) == True:

        inp = open(pathtofiletypesfile, "r")
        fileassociations = []
        for a in inp.readlines():
            fileassociations.append(a.strip().split("$$$"))
        inp.close()

        program = ""

        for a in fileassociations:

            if a[0] == fileextension:

                program = a[1]

        if program == "":

            localsettings = settings.settings(False)
            localsettings.GetSettings()

            wx.CallAfter(
                ShowMessage, fileextension + " - " +
                localsettings.dictionary["noprogramassociatedmessage"][
                    localsettings.language] + " " +
                localsettings.dictionary["readfileassociationhelpmessage"][
                    localsettings.language])

        else:

            if str(sys.platform)[:3] == "win":

                command = "\"" + program + "\" \"" + targetfile + "\""
                command = command.replace("/", "\\")
                os.system("\"" + command + "\"")

            else:

                command = "\"" + program + "\" \"" + targetfile + "\""
                os.system(command)

    else:

        localsettings = settings.settings(False)
        localsettings.GetSettings()

        wx.CallAfter(
            ShowMessage, localsettings.dictionary["noprogramassociatedmessage"]
            [localsettings.language])
示例#6
0
文件: launch.py 项目: tuksik/evette
serverpresent = False

while serverpresent == False:

    localsettings = settings.settings(False)
    localsettings.GetSettings()

    if db.CheckServer(localsettings) == False:

        AdjustSettingsDialog(None, localsettings)

    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)
示例#7
0
文件: settings.py 项目: tuksik/evette
    def GetSettings(self):

        home = miscmethods.GetHome()

        self.dictionary = language.GetDictionary()

        conffile = home + "/.evette.conf"

        try:

            if os.path.isfile(conffile):

                inp = open(conffile, "r")
                filecontents = ""

                for a in inp.readlines():

                    filecontents = filecontents + a

                inp.close()

                settingslist = filecontents.strip().split("\n")
                self.dbip = settingslist[0]
                self.dbuser = settingslist[1]
                self.dbpass = settingslist[2]
                self.lastuser = settingslist[4]
                self.language = int(settingslist[5])
                self.appointmentrefresh = int(settingslist[6])
            else:
                self.dbip = "localhost"
                self.dbuser = "******"
                self.dbpass = ""
                self.lastuser = "******"
                self.language = 0
                self.appointmentrefresh = 30
        except:
            #print sys.exc_info()
            self.dbip = "localhost"
            self.dbuser = "******"
            self.dbpass = ""
            self.lastuser = "******"
            self.language = 0
            self.appointmentrefresh = 30

        if self.userid != False:

            connection = db.GetConnection(self)
            self.dbconnection = connection

            action = "SELECT * FROM settings"
            results = db.SendSQL(action, connection)

            self.practicename = unicode(results[0][1], "utf8")
            self.openfrom = results[0][2]
            self.opento = results[0][3]
            self.operationtime = results[0][4]
            self.practiceaddress = unicode(results[0][5], "utf8")
            self.practicepostcode = unicode(results[0][6], "utf8")
            self.practicetelephone = unicode(results[0][7], "utf8")
            self.practiceemail = unicode(results[0][8], "utf8")
            self.practicewebsite = unicode(results[0][9], "utf8")
            self.shelterid = results[0][10]
            self.markupmultiplyby = results[0][11]
            self.markuproundto = results[0][12]
            self.asmvaccinationid = results[0][13]
            self.prescriptionfee = results[0][14]

            action = "SELECT * FROM user WHERE ID = " + str(self.userid)
            results = db.SendSQL(action, connection)

            self.username = unicode(results[0][1], "utf8")
            self.userposition = unicode(results[0][3], "utf8")

            changelog = results[0][4].split("$")
            self.editclients = int(changelog[0][0])
            self.deleteclients = int(changelog[0][1])
            self.editfinances = int(changelog[0][2])
            self.editanimals = int(changelog[1][0])
            self.deleteanimals = int(changelog[1][1])
            self.editappointments = int(changelog[2][0])
            self.deleteappointments = int(changelog[2][1])
            self.vetform = int(changelog[2][2])
            self.editmedication = int(changelog[3][0])
            self.deletemedication = int(changelog[3][1])
            self.editprocedures = int(changelog[4][0])
            self.deleteprocedures = int(changelog[4][1])
            self.editlookups = int(changelog[5][0])
            self.deletelookups = int(changelog[5][1])
            self.editforms = int(changelog[6][0])
            self.deleteforms = int(changelog[6][1])
            self.editusers = int(changelog[7][0])
            self.deleteusers = int(changelog[7][1])
            self.editrota = int(changelog[7][2])
            self.toolbar = int(changelog[8][0])
            self.changelog = int(changelog[8][1])
            self.editsettings = int(changelog[8][2])
            self.multiplepanels = int(changelog[8][3])
            self.asmsync = int(changelog[8][4])
            self.addtodiary = int(changelog[9][0])
            self.editdiary = int(changelog[9][1])
            self.deletefromdiary = int(changelog[9][2])
示例#8
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