Exemplo n.º 1
0
    def update(self):
        self.normalize()
        if self.badSetup:
            log(self.ID, "Employee is invalid")
            return
        if not self.exists:
            log(self.ID, "Employee does not exist yet, did you mean to create?")
            return
        _first_name = "first_name='{}'".format(self.first_name)
        _last_name = "last_name='{}'".format(self.last_name)
        _ssn = "ssn='{}'".format(self.ssn)
        _job_title = "job_title='{}'".format(self.job_title)
        _salary_type = "salary_type='{}'".format(self.salary_type)
        _insurancePlan = "insurancePlan='{}'".format(self.insurancePlan)
        _email = "email='{}'".format(self.email)
        _country = "country='{}'".format(self.country)
        _state = "state='{}'".format(self.state)
        _street_name = "street_name='{}'".format(self.street_name)
        _postal_code = "postal_code='{}'".format(self.postal_code)
        _F01k_deduction = "F01k_deduction='{}'".format(self.F01k_deduction)
        _rate = "rate='{}'".format(self.rate)
        _hours = "hours='{}'".format(self.hours)
        DB.execute(
            Query.UPDATE_SINGLE(
                Entity.EMPLOYEE,
                self.e_id,
                _first_name,
                _last_name,
                _ssn,
                _job_title,
                _salary_type,
                _insurancePlan,
                _email,
                _country,
                _state,
                _street_name,
                _postal_code,
                _F01k_deduction,
                _rate,
                _hours,
            )
        )

        # TODO: Only modify tables that actually changed

        DB.execute(Query.DELETE(Relation.HAS, "e_id='{}'".format(self.e_id)))

        DB.execute(Query.DELETE(Multivalue.EMPLOYEE_PHONE, "e_id='{}'".format(self.e_id)))

        DB.execute(Query.DELETE(Multivalue.EMPLOYEE_BENEFIT_SELECTION, "e_id='{}'".format(self.e_id)))

        for d in self.Dependents:
            DB.execute(Query.CREATE(Relation.HAS, self.e_id, d))

        for p in self.PhoneNumbers:
            DB.execute(Query.CREATE(Multivalue.EMPLOYEE_PHONE, self.e_id, p))

        for b in self.Benefits:
            DB.execute(Query.CREATE(Multivalue.EMPLOYEE_BENEFIT_SELECTION, self.e_id, b))
Exemplo n.º 2
0
    def create(self):  # TODO: use prepared statements instead
        self.normalize()
        if self.badSetup:
            log(self.ID, "Employee is invalid")
            return
        if self.exists:
            log(self.ID, "Employee already created, did you mean to update?")
            return
        DB.execute(
            Query.CREATE(
                Entity.EMPLOYEE,
                self.e_id,
                self.first_name,
                self.last_name,
                self.ssn,
                self.job_title,
                self.salary_type,
                self.insurancePlan,
                self.email,
                self.country,
                self.state,
                self.street_name,
                self.postal_code,
                self.F01k_deduction,
                self.rate,
                self.hours,
            )
        )

        if DB.result():
            log(self.ID, "Created employee {}".format(self.e_id))

        for d in self.Dependents:
            DB.execute(Query.CREATE(Relation.HAS, self.e_id, d))

        for p in self.PhoneNumbers:
            DB.execute(Query.CREATE(Multivalue.EMPLOYEE_PHONE, self.e_id, p))

        for b in self.Benefits:
            DB.execute(Query.CREATE(Multivalue.EMPLOYEE_BENEFIT_SELECTION, self.e_id, b))
Exemplo n.º 3
0
    def create(self):
        self.normalize()
        if self.badSetup:
            log(self.ID, "Dependent is invalid")
            return
        if self.exists:
            log(self.ID, "Dependent already created, did you mean to update?")
            return
        DB.execute(
            Query.CREATE(Entity.DEPENDENT, self.d_id, self.first_name,
                         self.last_name, self.ssn, self.benefitSelection))

        if DB.result():
            log(self.ID, "Created Dependent {}".format(self.d_id))