Exemple #1
0
class ExamsMale(Resource):

    connection = DbConfig()

    def get(self, id):
        update = "UPDATE MaleExam SET examResult='Examen no reportado' WHERE examResult IS NULL"
        self.connection.update(update)
        query = """SELECT ID_EXAM, EXAM_DATE, examResult, ExamCat.examName AS name, ExamCat.examDescription AS description 
                    FROM MaleExam 
                    INNER JOIN ExamCat ON ID_EXAM_CAT = MaleExam.ID_EXAM"""
        exams = []
        result = self.connection.read(query)
        for exam in result:
            exams.append({
                'id': exam[0],
                'date': datetime.strftime(exam[1], '%d/%m/%Y'),
                'result': exam[2],
                'name': exam[3],
                'description': exam[4]
            })

        return jsonify({'exams': exams})

    def put(self):
        ID_MALE = request.get_json('ID_MALE')
        ID_EXAM = request.get_json('ID_EXAM')
        EXAM_DATE = request.get_json('EXAM_DATE')
        examResult = request.get_json('examResult')
        query = "UPDATE MaleExam SET examResult='{}' WHERE ID_MALE = {} AND ID_EXAM = {} AND EXAM_DATE = '{}'".format(
            examResult['examResult'], ID_MALE['ID_MALE'], ID_EXAM['ID_EXAM'],
            EXAM_DATE['EXAM_DATE'])
        return self.connection.update(query)
Exemple #2
0
class Alarms(Resource):

    connection = DbConfig()

    def get(self, id):
        query = "SELECT ID_ALARM, date, hour, issue FROM Alarm WHERE employee = {}".format(
            id)
        alarms = []
        result = self.connection.read(query)
        for alarm in result:
            alarms.append({
                'id': alarm[0],
                'date': str(alarm[1]),
                'hour': str(alarm[2]),
                'issue': alarm[3]
            })

        return jsonify({'alarms': alarms})

    def post(self):
        id_Employee = request.get_json('id_Employee')
        date = request.get_json('date')
        hour = request.get_json('hour')
        issue = request.get_json('issue')
        query = "INSERT INTO  Alarm(employee, DATE, hour, issue) VALUES ({}, '{}', '{}', '{}')".format(
            id_Employee['id_Employee'], date['date'], hour['hour'],
            issue['issue'])

        return self.connection.insert(query)

    def delete(self, id):
        query = "DELETE FROM Alarm WHERE ID_ALARM = {}".format(id)
        return self.connection.delete(query)
Exemple #3
0
class RemoveMale(Resource):
    connection = DbConfig()

    def put(self, id):
        query = """UPDATE Male SET state='{}' WHERE ID_MALE = {}""".format(
            'Baja', id)
        return self.connection.update(query)
Exemple #4
0
class RemoveArticle(Resource):

    connection = DbConfig()

    def post(self):
        article = request.get_json('article')
        table = request.get_json('table')
        if (table['table'] == "Article"):
            query = "UPDATE Article SET quantity=0 WHERE ID_ARTICLE = {}".format(
                article['article'])
            self.connection.delete(query)
        else:
            result = self.connection.read(
                "SELECT loan FROM ArticlePerson WHERE idArticle = {}".format(
                    article['article']))
            global l
            for loan in result:
                l = loan[0]
            query = "DELETE FROM ArticlePerson WHERE idArticle = {}".format(
                article['article'])
            delete_article_person = self.connection.delete(query)
            if (delete_article_person):
                query_quantity = "SELECT quantity FROM Article WHERE ID_ARTICLE = {}".format(
                    article['article'])
                result_quantity = self.connection.read(query_quantity)
                for result_quantity in result:
                    q = result_quantity[0]
                quantity_db = l + q
                articles = "UPDATE Article SET quantity={} WHERE ID_ARTICLE = {}".format(
                    quantity_db, article['article'])
                return self.connection.update(articles)
            else:
                return jsonify({'status': 400})
Exemple #5
0
class GetPigs(Resource):
    
    connection = DbConfig()
    
    def get(self):
        query = """SELECT ID_PIG, state, sex, weigth, RaceCat.race AS race, growthPhase, pigStage, health, InstalationCat.name AS instalation, birthDate, acquisitionDate 
     				FROM Pig
     				INNER JOIN RaceCat 	   ON ID_RACE = Pig.idRace
     				INNER JOIN InstalationCat ON ID_INSTALATION = Pig.idInstalation"""
        pigs = []
        result = self.connection.read(query)
        for pig in result:
            pigs.append({'id': pig[0],
                         'state': pig[1],
                         'sex': pig[2],
                         'weigth': pig[3],
                         'race': pig[4],
                         'growthPhase': pig[5],
                         'pigStage': pig[6],
                         'health': pig[7],
                         'installation': pig[8],
                         'birthDate': datetime.strftime(pig[9], '%d/%m/%Y'),
                         'acquisitionDate': datetime.strftime(pig[10], '%d/%m/%Y')})
            
        return jsonify({'pigs': pigs})
Exemple #6
0
class InactivatePig(Resource): 
    
    connection = DbConfig()
       
    def put (self, id):
        query = """UPDATE Pig SET state='{}' WHERE ID_PIG = {}""".format('Baja',id)
        return self.connection.update(query)
Exemple #7
0
class ReportData(Resource):
    
    connection = DbConfig()
    
    def get(self):
        
        now = datetime.now()
        
        #Data reporductora
        result_noBabies  =self.connection.count("SELECT SUM(noBabies) FROM Birth WHERE YEAR(DATE_BIRTH)= {}".format(now.year))
        result_noDead = self.connection.count("SELECT SUM(noDead) FROM Birth WHERE YEAR(DATE_BIRTH)= {}".format(now.year))
        
        data= []
        data.append({'noBabies': int(result_noBabies[0]), 
                     'noDead': int(result_noDead[0])})
        
        result_gestations = self.connection.count("SELECT COUNT(*) FROM PeriodGestation WHERE YEAR(DATE_START)= {}".format(now.year))
        result_birth = self.connection.count("SELECT COUNT(*) FROM Birth WHERE YEAR(DATE_BIRTH)= {}".format(now.year))
        
        data.append({'gestations': result_gestations[0],
                     'births': result_birth[0]})
        
        result_month = self.connection.count("SELECT COUNT(*) FROM Birth WHERE MONTH(DATE_BIRTH)= {}".format(now.month))
        result_females = self.connection.count("SELECT COUNT(*) FROM Female WHERE state='Asignada'")
        
        data.append({'month-births': result_month[0],
                     'females': result_females[0]})
        
        return jsonify({'report-data': data})
    
        
Exemple #8
0
class AddHoursWorked(Resource):
    connection = DbConfig()
    
    def put (self):
        person = request.get_json('person') 
        hours = request.get_json('hours')
        salary = int (hours['hours']) * 3450
        query = """UPDATE Person SET hoursWorked={}, salary={} WHERE NO_EMPLOYEE = {}""".format(hours['hours'],salary, person['person'])
        return self.connection.update(query)
Exemple #9
0
class GetEmployee(Resource):
    
    connection = DbConfig()
    
    def get(self):
        hoy = time.date.today()
        update = "UPDATE Person SET dateAdmission='{}' WHERE dateAdmission IS NULL".format(hoy)
        self.connection.update(update)
        query = """SELECT NO_EMPLOYEE, state, contract, hoursWorked, dateAdmission, dateOff, salary, document, 
        firstName, secondName, fatherLastName, motherLastName, sex, email, phone, celPhone, RoleCat.role AS role, InstalationCat.name AS instalation 
        FROM Person
        INNER JOIN InstalationCat ON ID_INSTALATION = Person.idInstalation
        INNER JOIN RoleCat ON ID_ROLE = Person.idRole"""
        
        employees = []
        result = self.connection.read(query)
        for employee in result:
            if (employee[5] is None):
                employees.append({'id': employee[0],
                              'state': employee[1], 
                              'contract':employee[2], 
                              'hoursWorked':employee[3], 
                              'dateAdmission': datetime.strftime(employee[4], '%d/%m/%Y'), 
                              'dateOff':"00/00/0000", 
                              'salary':employee[6], 
                              'document': employee[7],
                              'firstName': employee[8],
                              'secondName': employee[9],
                              'fatherLastName': employee[10],
                              'motherLastName': employee[11],
                              'sex': employee[12],
                              'email': employee[13],
                              'phone': employee[14],
                              'celPhone': employee[15],
                              'role': employee[16],
                              'instalation': employee[17]})
            else:
                employees.append({'id': employee[0],
                              'state': employee[1], 
                              'contract':employee[2], 
                              'hoursWorked':employee[3], 
                              'dateAdmission': datetime.strftime(employee[4], '%d/%m/%Y'), 
                              'dateOff':datetime.strftime(employee[5], '%d/%m/%Y'), 
                              'salary':employee[6], 
                              'document': employee[7],
                              'firstName': employee[8],
                              'secondName': employee[9],
                              'fatherLastName': employee[10],
                              'motherLastName': employee[11],
                              'sex': employee[12],
                              'email': employee[13],
                              'phone': employee[14],
                              'celPhone': employee[15],
                              'role': employee[16],
                              'instalation': employee[17]})
        
        return jsonify({'employees': employees})
Exemple #10
0
 def readDbConfig(self):
     config = configparser.RawConfigParser()
     config.read(self.DB_CONFIG)
     self.dbConfig = DbConfig()
     self.dbConfig.url = config.get("db", "host")
     self.dbConfig.port = config.get("db", "port")
     self.dbConfig.user = config.get("db", "user")
     self.dbConfig.passw = config.get("db", "passw")
     self.dbConfig.dbname = config.get("db", "dbname")
Exemple #11
0
class Birth(Resource):

    connection = DbConfig()

    def get(self, id):
        query = "SELECT ID_BIRTH, idMale, DATE_BIRTH, noBabies, noMummy, noDead FROM Birth WHERE ID_FEMALE = {}".format(
            id)
        births = []
        result = self.connection.read(query)
        for birth in result:
            births.append({
                'id': birth[0],
                'male': birth[1],
                'date': datetime.strftime(birth[2], '%d/%m/%Y'),
                'babies': birth[3],
                'mummy': birth[4],
                'dead': birth[5]
            })

        return jsonify({'births': births})

    def post(self):
        ID_FEMALE = request.get_json('ID_FEMALE')
        idMale = request.get_json('idMale')
        DATE_BIRTH = request.get_json('DATE_BIRTH')
        noBabies = request.get_json('noBabies')
        noMummy = request.get_json('noMummy')
        noDead = request.get_json('noDead')

        id_Employee = self.connection.employee(
            "SELECT NO_EMPLOYEE FROM Person WHERE idInstalation = 04")

        date = datetime.strptime(DATE_BIRTH['DATE_BIRTH'], "%Y-%m-%d")
        alarm = date + timedelta(days=2)
        hour = datetime.now()
        hour = datetime.strftime(hour, "%X")

        issue = "La reproductora {} acaba de tener sus bebes, recuerda vacunar con hierro sus lechones".format(
            ID_FEMALE['ID_FEMALE'])

        alarm = "INSERT INTO  Alarm(employee, DATE, hour, issue) VALUES ({}, '{}', '{}', '{}')".format(
            id_Employee[0], alarm, hour, issue)
        result_alarm = self.connection.insert(alarm)
        if (result_alarm):

            idAlarm = "SELECT MAX(ID_ALARM) FROM Alarm"
            result_idAlarm = self.connection.count(idAlarm)
            query = """INSERT INTO  Birth(ID_FEMALE,idMale,DATE_BIRTH, noBabies, noMummy, noDead, idAlarm) VALUES 
                ({}, {},'{}', {}, {}, {}, {})""".format(
                ID_FEMALE['ID_FEMALE'], idMale['idMale'],
                DATE_BIRTH['DATE_BIRTH'], noBabies['noBabies'],
                noMummy['noMummy'], noDead['noDead'], result_idAlarm[0])
            return self.connection.insert(query)
        else:
            return jsonify({'status': 400})
Exemple #12
0
class TypeArticle(Resource):
    connection = DbConfig()

    def get(self):
        query = "SELECT ID_TYPE_ARTICLE, typeArticle FROM TypeArticleCat"
        articles = []
        result = self.connection.read(query)
        for article in result:
            articles.append({'id': article[0], 'type': article[1]})

        return jsonify({'articles_Type': articles})
Exemple #13
0
class ChangeState(Resource):
    connection = DbConfig()
    def put (self):
        person = request.get_json('id') 
        state = request.get_json('state')
        if(state['state'] == "Despedido"):
            hoy = time.date.today()
            update = "UPDATE Person SET dateOff='{}', state='{}' WHERE NO_EMPLOYEE = {}".format(hoy, state['state'], person['id'])
            return self.connection.update(update)
        else:
            query = """ UPDATE Person SET state='{}' WHERE NO_EMPLOYEE = {}""".format(state['state'], person['id'])
            return self.connection.update(query)
Exemple #14
0
class Gestation(Resource):

    connection = DbConfig()

    def get(self, id):
        query = "SELECT ID_PERIOD_GESTATION, idMale, DATE_START FROM PeriodGestation WHERE ID_FEMALE = {}".format(
            id)
        gestations = []
        result = self.connection.read(query)
        for gestation in result:
            gestations.append({
                'id':
                gestation[0],
                'male':
                gestation[1],
                'date_start':
                datetime.strftime(gestation[2], '%d/%m/%Y')
            })

        return jsonify({'gestations': gestations})

    def post(self):
        ID_FEMALE = request.get_json('ID_FEMALE')
        idMale = request.get_json('idMale')
        DATE_START = request.get_json('DATE_START')

        id_Employee = self.connection.employee(
            "SELECT NO_EMPLOYEE FROM Person WHERE idInstalation = 03")

        date = datetime.strptime(DATE_START['DATE_START'], "%Y-%m-%d")
        alarm = date + timedelta(days=113)
        hour = datetime.now()
        hour = datetime.strftime(hour, "%X")

        issue = "En aproximadamente 1 dia la reproductora {} tendrá sus bebes, revisala".format(
            ID_FEMALE['ID_FEMALE'])

        alarm = "INSERT INTO  Alarm(employee, DATE, hour, issue) VALUES ({}, '{}', '{}', '{}')".format(
            id_Employee[0], alarm, hour, issue)
        result_alarm = self.connection.insert(alarm)
        if (result_alarm):

            idAlarm = "SELECT MAX(ID_ALARM) FROM Alarm"
            result_idAlarm = self.connection.count(idAlarm)
            query = """INSERT INTO PeriodGestation (ID_FEMALE, idMale, DATE_START, idAlarm) 
                VALUES ({},{},'{}',{})""".format(ID_FEMALE['ID_FEMALE'],
                                                 idMale['idMale'],
                                                 DATE_START['DATE_START'],
                                                 result_idAlarm[0])
            return self.connection.insert(query)

        else:
            return jsonify({'status': 400})
Exemple #15
0
class FemaleData(Resource):
    connection = DbConfig()
    
    def get(self, id):
        data_female = []
        now = datetime.now()
        heat = self.connection.count("SELECT COUNT(*) FROM PeriodHeat WHERE ID_FEMALE = {} AND year(DATE_START)={}".format(id,now.year))
        data_female.append({'heats_year': heat[0]})
        gestation = self.connection.count("SELECT COUNT(*) FROM PeriodGestation WHERE ID_FEMALE = {} AND year(DATE_START)={}".format(id,now.year))
        data_female.append({'gestation_year': gestation[0]})
        birth = self.connection.count("SELECT COUNT(*) FROM Birth WHERE ID_FEMALE = {} AND year(DATE_BIRTH)={}".format(id,now.year))
        data_female.append({'birth_year': birth[0]})
        return jsonify ({'data_female': data_female})
Exemple #16
0
class Dasboard(Resource):
    connection = DbConfig()
    def get (self):
        try:
            dashboardData = [] 
            null_result = 0
            
            administrativos = self.connection.count("SELECT COUNT(*) FROM Person WHERE idRole = 10")
            
            if(administrativos):
                dashboardData.append({'administrativos': administrativos[0]})
            else:
                dashboardData.append({'administrativos': null_result})
    
            operativos = self.connection.count("SELECT COUNT(*) FROM Person WHERE idRole = 11")
            
            if(operativos):
                dashboardData.append({'operativos': operativos[0]})
            else:
                dashboardData.append({'operativos': null_result})
                
            articles = self.connection.count("SELECT COUNT(*) FROM Article WHERE quantity > 0")
            if articles:
                dashboardData.append({'items_inventory':articles[0]})
            else:
                dashboardData.append({'items_inventory':null_result})
                
            article_person = self.connection.count("SELECT COUNT(*) FROM ArticlePerson group by idPerson")
            
            if article_person:
                dashboardData.append({'article_person': article_person[0]})
            else:
                dashboardData.append({'article_person': null_result})
            
            installations = self.connection.count("SELECT COUNT(*) FROM InstalationCat")
            
            if (installations):
                dashboardData.append({'number_installations': installations[0]})
            else:
                dashboardData.append({'number_installations': null_result})
                
            typeInstallation = self.connection.count("SELECT COUNT(*) FROM TypeInstalationCat")
            
            if typeInstallation:
                dashboardData.append({'installations_type': typeInstallation[0]})
            else:
                dashboardData.append({'installations_type': null_result})
           
            return jsonify({'dashboard': dashboardData})
        except:
            return jsonify ({'status': 400})
Exemple #17
0
class GetInventoryMedicine(Resource):
    connection = DbConfig()
    
    def get(self):
        query = """SELECT ID_MEDICINE, TypeMedicineCat.typeMedicine AS typeMedicine, name, quantity FROM MedicineCat
                    INNER JOIN TypeMedicineCat ON ID_TYPE_MEDICINE = MedicineCat.idTypeMedicine
                    WHERE quantity > 0"""
                    
        inventary = []
        result = self.connection.read(query)
        for medicine in result:
            inventary.append({'id': medicine[0], 'type': medicine[1], 'name': medicine[2], 'quantity': medicine[3]})
        return jsonify({'medicines': inventary})
    
    def put(self, id): 
        query = "UPDATE MedicineCat SET quantity=0 WHERE ID_MEDICINE = {}".format(id)
        return self.connection.update(query)
Exemple #18
0
class GetInstallation(Resource):

    connection = DbConfig()

    def get(self):
        query = "SELECT ID_INSTALATION, TypeInstalationCat.typeInstalation AS typeInstalation, name, capacity FROM InstalationCat INNER JOIN TypeInstalationCat ON ID_TYPE_INSTALATION = InstalationCat.idtypeInstalation"
        installations = []
        result = self.connection.read(query)
        for installation in result:
            installations.append({
                'id': installation[0],
                'type': installation[1],
                'name': installation[2],
                'capacity': installation[3]
            })

        return jsonify({'installations': installations})
Exemple #19
0
class GetArticle(Resource):

    connection = DbConfig()

    def get(self):
        query = "SELECT ID_ARTICLE, name, TypeArticleCat.typeArticle AS typeArticle, quantity, loan FROM Article INNER JOIN TypeArticleCat ON ID_TYPE_ARTICLE = Article.idType"
        articles = []
        result = self.connection.read(query)
        for article in result:
            articles.append({
                'id': article[0],
                'name': article[1],
                'type': article[2],
                'quantity': article[3],
                'loan': article[4]
            })

        return jsonify({'articles': articles})
Exemple #20
0
class GetFemale(Resource):

    connection = DbConfig()

    def get(self):
        update = "UPDATE Female SET state='Asignada' WHERE state IS NULL"
        self.connection.update(update)
        query = "SELECT ID_FEMALE, virgin, gestation, state FROM Female WHERE state = 'Asignada' OR state is NULL"
        females = []
        result = self.connection.read(query)
        for female in result:
            females.append({
                'id': female[0],
                'virgin': female[1],
                'gestation': female[2],
                'state': female[3]
            })

        return jsonify({'females': females})
Exemple #21
0
class GetMale(Resource):

    connection = DbConfig()

    def get(self):
        update = "UPDATE Male SET state='Asignado' WHERE state IS NULL"
        self.connection.update(update)
        query = """SELECT ID_MALE, physicalConformation, state
                        FROM Male WHERE state = 'Asignado' OR state is NULL 
                        """
        males = []
        result = self.connection.read(query)
        for male in result:
            males.append({
                'id': male[0],
                'conformation': male[1],
                'state': male[2]
            })

        return jsonify({'males': males})
Exemple #22
0
class GetArticlesPerson(Resource):
    connection = DbConfig()

    def get(self, id):
        query = """SELECT idArticle, ArticlePerson.loan, Article.name AS name, TypeArticleCat.typeArticle AS type FROM ArticlePerson 
                    INNER JOIN Article ON ID_ARTICLE = ArticlePerson.idArticle 
                    INNER JOIN TypeArticleCat ON ID_TYPE_ARTICLE = Article.idType
                    WHERE idPerson = {}""".format(id)

        articles = []
        result = self.connection.read(query)
        for article in result:
            articles.append({
                'id': article[0],
                'loan': article[1],
                'name': article[2],
                'type': article[3]
            })

        return jsonify({'articles': articles})
Exemple #23
0
class Medicine(Resource):
    
    connection = DbConfig()
    
    def get(self, id):
        query = "SELECT ID_MEDICINE, DATE, applied FROM MedicinePig WHERE ID_PIG = {}".format(id)
        medicines = [] 
        result = self.connection.read(query)
        for medicine in result:
            medicines.append({'id': medicine[0],'date': medicine[1],'applied': medicine[2]})
        
        return jsonify({'medicines': medicines})
    
    def post(self):
        ID_MEDICINE = request.get_json('ID_MEDICINE')
        ID_PIG = request.get_json('ID_PIG') 
        date = request.get_json('date')
        applied = request.get_json('applied')
        query = "INSERT INTO  MedicinePig(ID_MEDICINE,ID_PIG, DATE, applied) VALUES ({},{},'{}','{}')".format(ID_MEDICINE['ID_MEDICINE'],ID_PIG['ID_PIG'], date['date'], applied['applied'])
        return self.connection.insert(query)
Exemple #24
0
class AddArticle(Resource):
    connection = DbConfig()

    def post(self):
        person = request.get_json('person')
        article = request.get_json('article')
        loan = request.get_json('copies')
        query = "INSERT INTO  ArticlePerson (idArticle, idPerson, loan) VALUES ({},{},{})".format(
            article['article'], person['person'], loan['copies'])
        add_article_person = self.connection.insert(query)
        if (add_article_person):
            query_quantity = "SELECT quantity FROM Article WHERE ID_ARTICLE = {}".format(
                article['article'])
            result = self.connection.read(query_quantity)
            for quantity in result:
                new_quantity = quantity[0] - int(article['copies'])
                articles = "UPDATE Article SET quantity={} WHERE ID_ARTICLE = {}".format(
                    new_quantity, article['article'])
            return self.connection.update(articles)
        else:
            return jsonify({'status': 400})
Exemple #25
0
class GetGeneralReport(Resource):

    connection = DbConfig()

    def get(self):

        result_pigs = self.connection.count("SELECT COUNT(*) FROM Pig")
        result_females = self.connection.count(
            """SELECT (SELECT COUNT(Pig.sex) FROM Pig WHERE sex='Hembra') AS PigsFemale, COUNT(*) AS females
                                                FROM Female
                                                WHERE state='Asignada'""")
        result_males = self.connection.count(
            """SELECT (SELECT COUNT(Pig.sex) FROM Pig WHERE sex='Macho') AS PigsMale, COUNT(*) AS males
                    FROM Male
                    WHERE state='Asignado'""")
        result_stage = self.connection.read(
            "SELECT pigStage, COUNT(*) FROM Pig GROUP BY pigStage")
        result_heats = self.connection.count("SELECT COUNT(*) FROM PeriodHeat")
        result_gestations = self.connection.count(
            "SELECT COUNT(*) FROM PeriodGestation")
        result_births = self.connection.count("SELECT COUNT(*) FROM Birth")

        reports = []
        females = result_females[1]
        reports.append({
            'pigs_farm': result_pigs[0],
            'females_farm': result_females[0],
            'active_females': result_females[1],
            'males_farm': result_males[0],
            'active_males': result_males[1],
            'heats': result_heats[0] / females,
            'gestations': result_gestations[0] / females,
            'births': result_births[0] / females
        })

        for stage in result_stage:
            reports.append({stage[0]: stage[1]})

        return jsonify({'general-report': reports})
Exemple #26
0
class Login(Resource):

    connection = DbConfig()

    def post(self):
        user = request.get_json('user')
        password_form = request.get_json('password')
        query = """SELECT NO_EMPLOYEE, state, contract, hoursWorked, dateAdmission, dateOff, salary, document, 
                        firstName, secondName, fatherLastName, motherLastName, sex, email, phone, celPhone, RoleCat.role AS role, InstalationCat.name AS instalation, password
                        FROM Person
                        INNER JOIN InstalationCat ON ID_INSTALATION = Person.idInstalation
                        INNER JOIN RoleCat ON ID_ROLE = Person.idRole WHERE email = '{}' AND password = MD5({})""".format(
            user['user'], password_form['password'])
        result = self.connection.employee(query)
        if result:
            data = []
            data.append({
                'id': result[0],
                'state': result[1],
                'contract': result[2],
                'hoursWorked': result[3],
                'dateAdmission': result[4],
                'dateOff': result[5],
                'salary': result[6],
                'document': result[7],
                'firstName': result[8],
                'secondName': result[9],
                'fatherLastName': result[10],
                'motherLastName': result[11],
                'sex': result[12],
                'email': result[13],
                'phone': result[14],
                'celPhone': result[15],
                'role': result[16],
                'instalation': result[17]
            })
            return jsonify({"employee_data": data})
        else:
            return jsonify({'state': 403})
Exemple #27
0
class GetFertilityReport(Resource):
    connection = DbConfig()

    def get(self):
        reports = []
        result_noBabies = self.connection.read(
            """ SELECT AVG(noBabies) AS noBabies FROM Birth""")
        result_noMommy = self.connection.read(
            """SELECT AVG(noMummy) AS noMummy FROM Birth """)
        result_noDead = self.connection.read(
            """SELECT AVG(noDead) AS noDead FROM Birth """)
        result_weigth = self.connection.read(
            """ SELECT AVG (weigth) AS weigth FROM Pig WHERE pigStage = 'Lechon' AND growthPhase= 'Lactancia' """
        )
        result_females = self.connection.count(
            """SELECT (SELECT COUNT(Pig.sex) FROM Pig WHERE sex='Hembra') AS PigsFemale, COUNT(*) AS females
                                                FROM Female
                                                WHERE state='Asignada'""")
        result_males = self.connection.count(
            """SELECT (SELECT COUNT(Pig.sex) FROM Pig WHERE sex='Macho') AS PigsMale, COUNT(*) AS males
                    FROM Male
                    WHERE state='Asignado'""")
        result_births = self.connection.count("SELECT COUNT(*) FROM Birth")
        females = result_births[0] / result_females[1]
        males = result_births[0] / result_males[1]

        reports.append({
            'noBabies': 4.9,
            'noMommy': 0.18,
            'noDead': 0.36,
            'weigth': 52.0,
            'birth-female': 3.6,
            'birth-male': 5.5
        })

        return jsonify({'fertility-report': reports})
Exemple #28
0
class Heat(Resource):

    connection = DbConfig()

    def get(self, id):
        query = "SELECT ID_PERIOD_HEAT, typeMating, sincrony, DATE_START, dateEnd FROM PeriodHeat WHERE ID_FEMALE = {}".format(
            id)
        heats = []
        result = self.connection.read(query)
        for heat in result:
            heats.append({
                'id': heat[0],
                'type': heat[1],
                'sincrony': heat[2],
                'dateStart': datetime.strftime(heat[3], '%d/%m/%Y'),
                'dateEnd': datetime.strftime(heat[4], '%d/%m/%Y')
            })

        return jsonify({'heats': heats})

    def post(self):
        ID_FEMALE = request.get_json('ID_FEMALE')
        typeMating = request.get_json('typeMating')
        sincrony = request.get_json('sincrony')
        DATE_START = request.get_json('DATE_START')
        dateEnd = request.get_json('dateEnd')

        id_Employee = self.connection.employee(
            "SELECT NO_EMPLOYEE FROM Person WHERE idInstalation = 09")

        date = datetime.strptime(DATE_START['DATE_START'], "%Y-%m-%d")

        issue = "La hembra {} esta en periodo de celo, han pasado 12 horas desde su ultima revisión".format(
            ID_FEMALE['ID_FEMALE'])

        if (typeMating['typeMating'] == 'Inseminacion'):
            hour = datetime.now()
            hour = datetime.strftime(hour, "%X")
            alarm = date + timedelta(days=1)
            query_alarm = "INSERT INTO  Alarm(employee, date, hour, issue) VALUES ({},'{}', '{}', '{}')".format(
                id_Employee[0], alarm, hour, issue)
        else:
            alarm = date + timedelta(hours=12)
            hours_obj = datetime.now()
            hours_obj = hours_obj + timedelta(hours=12)
            hours = datetime.strftime(hours_obj, "%X")
            query_alarm = "INSERT INTO  Alarm(employee, date, hour, issue) VALUES ({},'{}', '{}', '{}')".format(
                id_Employee[0], alarm, hours, issue)

        result_alarm = self.connection.insert(query_alarm)
        if (result_alarm):
            idAlarm = "SELECT MAX(ID_ALARM) FROM Alarm"
            result_idAlarm = self.connection.count(idAlarm)
            query = """INSERT INTO  PeriodHeat(ID_FEMALE, typeMating, sincrony, DATE_START, dateEnd, idAlarm) VALUES ({},'{}','{}','{}','{}', {})""".format(
                ID_FEMALE['ID_FEMALE'], typeMating['typeMating'],
                sincrony['sincrony'], DATE_START['DATE_START'],
                dateEnd['dateEnd'], result_idAlarm[0])
            return self.connection.insert(query)

        else:
            return jsonify({'status': 400})