def checkAdmin(self):
     db = CreateConnection()["users"]
     result = db.find_one({"user_role": {"$eq": "admin"}})
     if result:
         self.clearForm()
     else:
         return None
 def checkUsername(self):
     if self.username is not None:
         db = CreateConnection()["users"]
         res = db.find_one({"username": {"$eq": self.username}})
         if res is not None:
             return True
         else:
             return False
 def checkEmail(self):
     if self.email is not None:
         db = CreateConnection()["users"]
         res = db.find_one({"email": {"$eq": self.email}})
         if res is not None:
             return True
         else:
             return False
    def vardiya_degistir(yeniSorumlu, degisecek_vardiya):
        global x
        print(yeniSorumlu)
        print(type(yeniSorumlu))
        print(degisecek_vardiya)

        user = CreateConnection()["users"]
        vardiya = CreateConnection()["vardiya"]
        eskiSorumlu = vardiya.find_one({
            "vardiya_adi": degisecek_vardiya
        })["vardiya_sorumlu"]
        print(eskiSorumlu)
        if len(eskiSorumlu) > 20:
            x = user.update_one({
                "_id": ObjectId(eskiSorumlu)
            }, {
                "$set": {"vardiya": "null"}
            })
            print(x)
        y = user.update_one({
            "_id": ObjectId(yeniSorumlu)
        }, {
            "$set": {"vardiya": degisecek_vardiya}
        })
        print(y)
        z = vardiya.update_one({
            "vardiya_adi": degisecek_vardiya
        }, {
            "$set": {"vardiya_sorumlu": yeniSorumlu}
        })
        print(z)
 def checkEmail(email):
     if email is not None:
         db = CreateConnection()["users"]
         result = db.find_one({
             "email": {
                 "$eq": email
             }
         })
         print(f'checkEmail {result}')
         if result is not None:
             return True
         else:
             return False
     else:
         print("Username gelmedi")
 def checkUserName(username):
     if username is not None:
         db = CreateConnection()["users"]
         result = db.find_one({
             "username": {
                 "$eq": username
             }
         })
         print(f'checkUserName {result}')
         if result is not None:
             return True
         else:
             return False
     else:
         print("Username gelmedi")
    def addUserToSuperVisorShift(self, data):
        from Controllers.SuperVisor import SuperVisor
        user = SuperVisor()
        # getSupervisor2(data[0])

        shiftCollection = CreateConnection()["shift"]
        res = shiftCollection.find_one_and_update({"name": {
            "$eq": data[-1]
        }}, {'$set': {
            "supervisor": user._id
        }})

        if res:
            return True
        else:
            return False
 def save(self):
     collection = CreateConnection()["users"]
     self.user_role = "supervisor"
     print(self.user_role)
     response = collection.insert_one({
         "full_name": self.full_name,
         "username": self.username,
         "password": self.password,
         "email": self.email,
         "user_role": self.user_role,
         "imagePath": self.imagePath + '/'
     })
     if response is not None:
         return True
     else:
         return False
 def getInformationShift(vardiya_adi):
     if not vardiya_adi:
         return False
     else:
         db = CreateConnection()["vardiya"].find_one({
             "vardiya_adi": vardiya_adi
         })
         return db
 def getAllSuperVisor():
     users = CreateConnection()["users"].find(
         {"user_role": {
             "$eq": "supervisor"
         }})
     if users is not None:
         return list(users)
     else:
         return False
 def Login(self, username, password, userType=False):
     db = CreateConnection()["users"]
     if userType:
         result = db.find_one({
             "username": {"$eq": username},
             "password": {"$eq": password},
             "user_role": {"$eq": "admin"}
         })
         if result:
             return result
         else:
             return False
     else:
         result = db.find_one({
             "username": {"$eq": username},
             "password": {"$eq": password}
         })
         if result:
             return result
         else:
             return False
    def editSupervisorShift(id, vardiya):
        user = CreateConnection()["users"].find_one_and_update(
            {"_id": {
                "$eq": id
            }}, {"$set": {
                'vardiya': vardiya
            }})

        if user is not None:
            return True
        else:
            return False
 def getSupervisor(self):
     user = CreateConnection()["users"].find_one({
         "username": {
             "$eq": self.username
         },
         "password": {
             "$eq": self.password
         },
         "user_role": {
             "$eq": "admin"
         }
     })
     return user
 def isciKontrol(self):
     isciler = CreateConnection()["isciler"].find_one(
         {'TcNo': {
             "$eq": self.ui.txt_TcNo.text()
         }})
     if isciler is not None:
         return False
     else:
         tcNo = self.ui.txt_TcNo.text()
         self.imagePath = self.home + tcNo
         print(self.imagePath)
         self.createFolder(self.imagePath)
         return True
 def getSupervisor(self):
     print(self.username)
     user = CreateConnection()["users"].find_one(
         {"username": {
             "$eq": self.username
         }})
     print(user)
     print(user.get('user_role'))
     self.id = user.get('_id')
     self.full_name = user.get('full_name')
     self.user_role = user.get('user_role')
     self.phone = user.get('phone')
     self.email = user.get('email')
     self.vardiya = user.get('vardiya')
 def addWorkerToShift(self, tcNo):
     db = CreateConnection()["vardiya"].find_one(
         {"vardiya_adi":
          self.ui.cmb_Vardiyas.currentText()})['vardiya_iscileri']
     idx = CreateConnection()['isciler'].find_one({"TcNo": tcNo})["_id"]
     db.append(idx)
     CreateConnection()['vardiya'].update_one(
         {"vardiya_adi": self.ui.cmb_Vardiyas.currentText()},
         {"$set": {
             "vardiya_iscileri": db
         }})
    def addShift(self, eskiVardiya, YeniVardiya):
        # TODO: vardiyalar tablsounda eski vardiya durumunu sil
        # TODO: vardiyalar tablosuna işçiyi ekle
        # TODO: işçide vardiya durumunu güncelle
        print("Eski Vardiya ", eskiVardiya)
        print(f'Yeni Vardiya', YeniVardiya)
        print(self.id)
        db = CreateConnection()["vardiya"]
        isciler = db.find_one({"vardiya_adi": eskiVardiya})['vardiya_iscileri']
        yeniVardiya = db.find_one({"vardiya_adi":
                                   YeniVardiya})['vardiya_iscileri']
        # if eskiVardiya != YeniVardiya:

        if self.id in isciler:
            print("eski tablo güncelleme")
            isciler.remove(self.id)
            print("isciler")
            print("")
            db.update_one({"vardiya_adi": eskiVardiya},
                          {"$set": {
                              "vardiya_iscileri": isciler
                          }})
        print("1x")
        if self.id not in yeniVardiya:
            print("yeni tablo güncelleme")
            yeniVardiya.append(self.id)
            db.update_one({"vardiya_adi": YeniVardiya},
                          {"$set": {
                              "vardiya_iscileri": yeniVardiya
                          }})
        print("2x")
        if self.vardiya != YeniVardiya:
            print()
            self.vardiya = YeniVardiya
            self.collection.update_one({"_id": self.id},
                                       {"$set": {
                                           "vardiya": self.vardiya
                                       }})
        return True
 def save(self):
     sql = {
         "full_name": self.full_name,
         "username": self.username,
         "password": self.password,
         "email": self.email,
         "phone": self.phone,
         "user_role": self.user_role
     }
     print(sql)
     try:
         db = CreateConnection()
         res = db["users"].insert_one(sql)
         if res:
             print(f'{self.full_name} user is created')
             return True
         else:
             return False
     except Exception as err:
         print(err)
 def __init__(self, tcNo=None):
     super().__init__()
     self.collection = CreateConnection()["isciler"]
     if tcNo is not None:
         self.tcNo = tcNo
         self.getWorker()
class Worker(IWorker):
    def __init__(self, tcNo=None):
        super().__init__()
        self.collection = CreateConnection()["isciler"]
        if tcNo is not None:
            self.tcNo = tcNo
            self.getWorker()

    def save(self):
        # TODO: TCKNO - Adı Soyadı - Vardiyası
        print(self.full_name)
        print("test")
        res = self.collection.insert_one({
            "TcNo": self.tcNo,
            "full_name": self.full_name,
            "vardiya": self.vardiya,
            "user_role": self.user_role,
            "imagePath": self.imagePath + "/"
        })
        if res is not None:
            print(f'{self.full_name} user is created')
            return True
        else:
            return False

    def edit(self):
        res = self.collection.find_one_and_update({"_id": ObjectId(self.id)}, {
            '$set': {
                "TcNo": self.tcNo,
                "full_name": self.full_name,
                "vardiya": self.vardiya
            }
        })
        if res:
            return True
        else:
            return False

    def addShift(self, eskiVardiya, YeniVardiya):
        # TODO: vardiyalar tablsounda eski vardiya durumunu sil
        # TODO: vardiyalar tablosuna işçiyi ekle
        # TODO: işçide vardiya durumunu güncelle
        print("Eski Vardiya ", eskiVardiya)
        print(f'Yeni Vardiya', YeniVardiya)
        print(self.id)
        db = CreateConnection()["vardiya"]
        isciler = db.find_one({"vardiya_adi": eskiVardiya})['vardiya_iscileri']
        yeniVardiya = db.find_one({"vardiya_adi":
                                   YeniVardiya})['vardiya_iscileri']
        # if eskiVardiya != YeniVardiya:

        if self.id in isciler:
            print("eski tablo güncelleme")
            isciler.remove(self.id)
            print("isciler")
            print("")
            db.update_one({"vardiya_adi": eskiVardiya},
                          {"$set": {
                              "vardiya_iscileri": isciler
                          }})
        print("1x")
        if self.id not in yeniVardiya:
            print("yeni tablo güncelleme")
            yeniVardiya.append(self.id)
            db.update_one({"vardiya_adi": YeniVardiya},
                          {"$set": {
                              "vardiya_iscileri": yeniVardiya
                          }})
        print("2x")
        if self.vardiya != YeniVardiya:
            print()
            self.vardiya = YeniVardiya
            self.collection.update_one({"_id": self.id},
                                       {"$set": {
                                           "vardiya": self.vardiya
                                       }})
        return True

    def delete(self):
        res = self.collection.find_one_and_delete({'_id': ObjectId(self.id)})
        if res:
            return True
        else:
            return False

    def getWorker(self):
        isci = self.collection.find_one({"TcNo": self.tcNo})
        print(isci)
        self.id = isci['_id']
        self.tcNo = isci['TcNo']
        self.full_name = isci['full_name']
        self.vardiya = isci['vardiya']
        self.user_role = isci['user_role']
        self.imagePath = isci['imagePath']

    def getAllWorker(self):
        return list(self.collection.find())
Esempio n. 21
0
from bson import ObjectId

from Controllers.Worker import Worker
from Database.DataBaseConnection import CreateConnection
from Controllers.CommonMethods import CommonMethods
test = CreateConnection()["isciler"]


def getWorker2(idNo):
    collection = CreateConnection()["isciler"]
    isci = collection.find_one({"_id": idNo})
    return isci


def getVardiya(vardiyaAdi):
    collection = CreateConnection()["vardiya"]
    vardiya = collection.find_one({"vardiya_adi":
                                   vardiyaAdi})['vardiya_iscileri']
    return vardiya


data = getVardiya("Sabah")
isciler = []
for i in data:
    isciler.append(CommonMethods.getWorker(i))

print(isciler)
print(type(isciler))
print(len(isciler))

# from datetime import date
 def getSupervisor2(_id):
     user = CreateConnection()["users"].find_one(
         {"_id": {
             "$eq": ObjectId(_id)
         }})
     return user
Esempio n. 23
0
def getVardiya(vardiyaAdi):
    collection = CreateConnection()["vardiya"]
    vardiya = collection.find_one({"vardiya_adi":
                                   vardiyaAdi})['vardiya_iscileri']
    return vardiya
Esempio n. 24
0
def getWorker2(idNo):
    collection = CreateConnection()["isciler"]
    isci = collection.find_one({"_id": idNo})
    return isci
 def getWorker(idNo):
     return CreateConnection()["isciler"].find_one({"_id": idNo})