# To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.

__author__ = "Arius_EX"
__date__ = "$10 31, 16 3:15:37 PM$"

from connectdb import ConnectDB
from time import gmtime, strftime
from datetime import datetime

c = ConnectDB()
connection = c.connection()
cur = connection.cursor()


class RequisitionAndIssuanceSlip:
    def addRIS(self, reqnum, purpose, details, idnum):

        sql = "insert into req_iss_slip values('{}', null, '{}','{}', '{}', NULL, NULL, NULL)".format(
            reqnum, purpose, strftime("%Y-%m-%d", gmtime()), idnum)

        print(sql)
        cur.execute(sql)
        connection.commit()
        print("Done")

    def updateRISApproval(self, reqnum, decision, reason):

        if decision == 'TRUE':
            sql = "update req_iss_slip set status = TRUE where slipnum = '" + reqnum + "'"
from connectdb import ConnectDB

cdb = ConnectDB()

connection = cdb.connection()
cur = connection.cursor()


class dbTable:

    dbname = None

    def __init__(self, dbname):

        self.dbname = dbname
        sql = "create table if not exists " + dbname + "()"
        dbTable.executeUpdate(self, sql)

    def column(self, columnname, datatype, pkey):

        try:

            sqlwhilesy = "alter table " + self.dbname + "  add column " + columnname + " " + datatype + ";"

            if pkey == True:
                sqlwhilesy = sqlwhilesy + "alter table " + self.dbname + " alter column " + columnname + " set not null; alter table " + self.dbname + " ADD PRIMARY KEY (" + columnname + ");"

            sql = "DO $$ BEGIN BEGIN " + sqlwhilesy + " EXCEPTION WHEN duplicate_column THEN RAISE NOTICE ''; END; END;$$"

            dbTable.executeUpdate(self, sql)