Ejemplo n.º 1
0
 def update_customer(self,customerEntity):
     _db = None
     _id_customer = 0
     _status = 1
     try:
         _db = Database()
         _db.connect(self.host,self.port,self.user,self.password,self.database)
         print('Se conecto a la bd')
         _con_client = _db.get_client()
         _sql = """UPDATE main.customer SET full_name= %s, cellphone= %s, photo= %s
                 WHERE id = %s and status = %s;"""
         _cur = _con_client.cursor()
         _cur.execute(_sql, (customerEntity.full_name,customerEntity.cellphone,
                             customerEntity.photo,customerEntity.id,
                             _status))
         _id_customer = customerEntity.id
         _con_client.commit()
         _cur.close()
     except(Exception) as e:
         self.add_log(str(e),type(self).__name__)
     finally:
         if _db is not None:
             _db.disconnect()
             print("Se cerro la conexion")
     return _id_customer
Ejemplo n.º 2
0
    def get_coupon_by_id_sale(self,id_sale):
        _db = None
        _status = 1
        _coupon = None
   
        try:
            _id_sale = id_sale
            _db = Database()
            _db.connect(self.host,self.port,self.user,self.password,self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()

            _sql = """SELECT s.coupon
                    FROM   main.sale s 
                    WHERE s.id = %s; """   

            _cur = _con_client.cursor()
            _cur.execute(_sql,(_id_sale,))
            _rows = _cur.fetchall()
        
            if len(_rows) >= 1:
                _coupon = _rows[0][0]

            _cur.close()
        except(Exception) as e:
            self.add_log(str(e),type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return _coupon
Ejemplo n.º 3
0
 def add_customer_rate(self,entity):
     _db = None
     _id_customer = 0
     _status = 1
     _i = 0
     try:
         _db = Database()
         _db.connect(self.host,self.port,self.user,self.password,self.database)
         print('Se conecto a la bd')
         _con_client = _db.get_client()
         _sql = """INSERT INTO main.customer_rate (id_user,id_service,id_customer,rate,description,status,date_transaction) 
                 VALUES(%s,%s,%s,%s,%s,%s,current_timestamp);"""
         _cur = _con_client.cursor()
         _cur.execute(_sql, (entity.id_user,entity.id_service,entity.id_customer,
                             entity.rate,entity.description,_status))
                             
         _con_client.commit()
         _cur.close()
     except(Exception) as e:
         self.add_log(str(e),type(self).__name__)
     finally:
         if _db is not None:
             _db.disconnect()
             print("Se cerro la conexion")
     return entity
Ejemplo n.º 4
0
 def change_password_user_web(self, full_name, password):
     _db = None
     _status = 1
     try:
         _db = Database()
         _db.connect(self.host, self.port, self.user, self.password,
                     self.database)
         print('Se conecto a la bd')
         _con_client = _db.get_client()
         _sql = """UPDATE main.user_web SET "password" = %s WHERE full_name = %s AND status = %s;"""
         _cur = _con_client.cursor()
         _cur.execute(_sql, (
             password,
             full_name,
             _status,
         ))
         _con_client.commit()
         _cur.close()
     except (Exception) as e:
         self.add_log(str(e), type(self).__name__)
     finally:
         if _db is not None:
             _db.disconnect()
             print("Se cerro la conexion")
     return full_name
Ejemplo n.º 5
0
    def get_customer_fire_base_token(self):
        _db = None
        _status = 1
        _data = []
        try:
            _db = Database()
            _db.connect(self.host, self.port, self.user, self.password,
                        self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()
            _sql = """SELECT up.id_fire_base_token
                        FROM main.customer up 
                        WHERE up.id_fire_base_token IS NOT NULL
                        AND up.id_fire_base_token <> ''
                        AND up.status = %s; """

            _cur = _con_client.cursor()
            _cur.execute(_sql, (_status, ))
            _rows = _cur.fetchall()

            for row in _rows:
                _data.append(row[0])

            _cur.close()
        except (Exception) as e:
            self.add_log(str(e), type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return _data
Ejemplo n.º 6
0
    def update_customer_address(self,entity):
        _db = None
        _status = 1
        try:
            _db = Database()
            _db.connect(self.host,self.port,self.user,self.password,self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()
            _sql = """UPDATE main.customer_address 
                    SET id_customer = %s,
                    address = %s,
                    longitude = %s,
                    latitude = %s,
                    main = %s
                    WHERE id = %s;"""

            _cur = _con_client.cursor()
            _cur.execute(_sql, (entity.id_customer,entity.address,entity.longitude,entity.latitude,entity.main,entity.id,))
            _con_client.commit()
            _cur.close()
        except(Exception) as e:
            self.add_log(str(e),type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return entity
Ejemplo n.º 7
0
    def get_services_wa(self):
        _db = None
        _status = 1
        _data_row = []
        try:
            _db = Database()
            _db.connect(self.host, self.port, self.user, self.password,
                        self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()
            _sql = """SELECT id, full_name, color,encode(file_image,'base64') AS file_image,status FROM main.service ORDER BY 1;"""
            _cur = _con_client.cursor()
            _cur.execute(_sql)
            _rows = _cur.fetchall()
            for row in _rows:
                _serviceEntity = serviceEntity()
                _serviceEntity.id = row[0]
                _serviceEntity.full_name = row[1]
                _serviceEntity.color = row[2]
                _file_image = row[3]
                if _file_image is None:
                    _serviceEntity.file_image = _file_image
                else:
                    _serviceEntity.file_image = _file_image.replace('\n', '')
                _serviceEntity.status = row[4]
                _data_row.append(_serviceEntity)

            _cur.close()
        except (Exception) as e:
            print('error: ' + str(e))
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return _data_row
Ejemplo n.º 8
0
    def add_sub_service(self, entity, id_service, status):
        _db = None
        _status = status
        _id_service = id_service
        _i = 0
        try:
            _db = Database()
            _db.connect(self.host, self.port, self.user, self.password,
                        self.database)
            print('Se conecto a la bd')

            _con_client = _db.get_client()
            _sql = """INSERT INTO main.sub_service (id_service, full_name, status, in_filter)
                    VALUES(%s,%s,%s,%s) RETURNING id;"""
            _cur = _con_client.cursor()
            _cur.execute(_sql, (
                _id_service,
                entity.full_name,
                _status,
                entity.in_filter,
            ))
            _id_service = _cur.fetchone()[0]
            entity.id = _id_service
            _con_client.commit()
            _cur.close()
        except (Exception) as e:
            self.add_log(str(e), type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return entity
Ejemplo n.º 9
0
 def update_file_image(self, id_service, file_image):
     _db = None
     _status = 1
     _data_row = []
     try:
         _db = Database()
         _db.connect(self.host, self.port, self.user, self.password,
                     self.database)
         print('Se conecto a la bd')
         _con_client = _db.get_client()
         _sql = """UPDATE main.service 
                 SET    file_image = %s 
                 WHERE  id = %s;"""
         _cur = _con_client.cursor()
         _cur.execute(_sql, (
             file_image,
             id_service,
         ))
         _con_client.commit()
         _cur.close()
     except (Exception) as e:
         print('error: ' + str(e))
     finally:
         if _db is not None:
             _db.disconnect()
             print("Se cerro la conexion")
     return _data_row
Ejemplo n.º 10
0
    def get_password_by_id(self,email):
        _db = None
        _status = 1
        _entity = None
        _mail = email
        try:
            _db = Database()
            _db.connect(self.host,self.port,self.user,self.password,self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()

            _sql = """SELECT c."password", c.cellphone
                    FROM   main.customer c 
                    WHERE  c.status = %s
                        AND c.mail = %s; """   

            _cur = _con_client.cursor()
            _cur.execute(_sql,(_status,_mail,))
            _rows = _cur.fetchall()
        
            if len(_rows) >= 1:
                _entity  = customerEntity()
                _entity.password = _rows[0][0]
                _entity.cellphone = _rows[0][1]

            _cur.close()
        except(Exception) as e:
            self.add_log(str(e),type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return _entity
Ejemplo n.º 11
0
    def add_customer_coupon(self,id_customer,id_customer_main):
        _db = None
        _id_customer = id_customer
        _id_customer_main = id_customer_main
        _status = 1
        _i = 0
        try:
            _db = Database()
            _db.connect(self.host,self.port,self.user,self.password,self.database)
            print('Se conecto a la bd')

            _date = datetime.now()
            entity = customerCouponEntity()
            entity.id_customer = _id_customer
            entity.coupon = "CPN-APP"+ str(_id_customer) +"-"+ str(_date.hour)+str(_date.year)+str(_date.month)+str(_date.minute)
            entity.amount = int(self.amount_coupon)

            _con_client = _db.get_client()
            _sql = """INSERT INTO main.customer_coupon (coupon, id_customer, id_customer_main,effective_date, amount, status)
                    VALUES(%s,%s,%s,current_date + 30,%s,%s);"""
            _cur = _con_client.cursor()
            _cur.execute(_sql,(entity.coupon,entity.id_customer,_id_customer_main,entity.amount,_status))
                                
            _con_client.commit()
            _cur.close()
        except(Exception) as e:
            self.add_log(str(e),type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return entity
Ejemplo n.º 12
0
 def update_sub_service(self, entity, id_service, status):
     _db = None
     _status = 1
     try:
         _db = Database()
         _db.connect(self.host, self.port, self.user, self.password,
                     self.database)
         print('Se conecto a la bd')
         _con_client = _db.get_client()
         _sql = """UPDATE main.sub_service 
                 SET    id_service = %s,
                 full_name = %s,
                 status = %s,
                 in_filter = %s
                 WHERE  id = %s;"""
         _cur = _con_client.cursor()
         _cur.execute(_sql, (id_service, entity.full_name, status,
                             entity.in_filter, entity.id))
         _con_client.commit()
         _cur.close()
     except (Exception) as e:
         self.add_log(str(e), type(self).__name__)
     finally:
         if _db is not None:
             _db.disconnect()
             print("Se cerro la conexion")
     return entity
Ejemplo n.º 13
0
 def validate_referred_code(self, referred_coupon):
     _db = None
     _value = False
     _status = 1
     _id_customer = None
     try:
         _referred_coupon = referred_coupon
         _db = Database()
         _db.connect(self.host,self.port,self.user,self.password,self.database)
         print('Se conecto a la bd')
         _con_client = _db.get_client()
         _sql = """SELECT id
                 FROM   main.customer c 
                 WHERE c.id_code = %s AND c.status = %s;"""   
         _cur = _con_client.cursor()
         _cur.execute(_sql,(_referred_coupon,_status,))
         _rows = _cur.fetchall()
         if len(_rows) >= 1:
             _id_customer = _rows[0][0]
         _cur.close()
     except(Exception) as e:
         self.add_log(str(e),type(self).__name__)
     finally:
         if _db is not None:
             _db.disconnect()
             print("Se cerro la conexion")
     return _id_customer
Ejemplo n.º 14
0
 def validate_mail(self, mail):
     _db = None
     _value = False
     try:
         _mail = mail
         _db = Database()
         _db.connect(self.host,self.port,self.user,self.password,self.database)
         print('Se conecto a la bd')
         _con_client = _db.get_client()
         _sql = """SELECT id
                 FROM   main.customer c 
                 WHERE c.mail = %s;"""   
         _cur = _con_client.cursor()
         _cur.execute(_sql,(_mail,))
         _rows = _cur.fetchall()
         if len(_rows) >= 1:
             _value = True
         _cur.close()
     except(Exception) as e:
         self.add_log(str(e),type(self).__name__)
     finally:
         if _db is not None:
             _db.disconnect()
             print("Se cerro la conexion")
     return _value
Ejemplo n.º 15
0
 def add_user_store(self,entity):
     _db = None
     _id = 0
     _status = 1
     _i = 0
     try:
         _db = Database()
         _db.connect(self.host,self.port,self.user,self.password,self.database)
         print('Se conecto a la bd')
         _con_client = _db.get_client()
         _sql = """INSERT INTO main.user_store (id_user,full_name, address, longitude, latitude, main, status ) 
                 VALUES(%s,%s,%s,%s,%s,%s,%s) RETURNING id;"""
         _cur = _con_client.cursor()
         _cur.execute(_sql, (entity.id_user,entity.full_name,entity.address,
                             entity.longitude,entity.latitude,entity.main,_status))
         _id = _cur.fetchone()[0]
         entity.id = _id
                             
         _con_client.commit()
         _cur.close()
     except(Exception) as e:
         self.add_log(str(e),type(self).__name__)
     finally:
         if _db is not None:
             _db.disconnect()
             print("Se cerro la conexion")
     return entity
Ejemplo n.º 16
0
    def get_user_stores_by_id_user(self,id_user):
        _db = None
        _status = 1
        _id_user = id_user
        _data_row = []
        print(id_user)
        try:
            _db = Database()
            _db.connect(self.host,self.port,self.user,self.password,self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()
            _sql = """SELECT id, id_user, full_name, address, longitude, latitude, main, status FROM main.user_store
                      WHERE status = %s and id_user = %s;"""
            _cur = _con_client.cursor()
            _cur.execute(_sql,(_status,_id_user))
            _rows = _cur.fetchall()

            for row in _rows:
                _userStoreEntity= userStoreEntity()
                _userStoreEntity.id  = row[0]
                _userStoreEntity.id_user  = row[1] 
                _userStoreEntity.full_name  = row[2]
                _userStoreEntity.address  = row[3]
                _userStoreEntity.longitude  = row[4]
                _userStoreEntity.latitude  = row[5]
                _userStoreEntity.main  = row[6]
                _data_row.append(_userStoreEntity)
            _cur.close()
        except(Exception) as e:
            self.add_log(str(e),type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return _data_row
Ejemplo n.º 17
0
 def add_log(self, p_e, p_class):
     _db = None
     _id_user = 0
     _status = 1
     _i = 0
     try:
         _db = Database()
         _db.connect(self.host, self.port, self.user, self.password,
                     self.database)
         print('Se conecto a la bd LOG')
         print('error :' + p_e + 'clase: ' + p_class)
         _con_client = _db.get_client()
         _sql = """INSERT INTO main.log_error (error, class_name, date_transaction) 
                 VALUES(%s,%s,current_timestamp);"""
         _cur = _con_client.cursor()
         _cur.execute(_sql, (
             p_e,
             p_class,
         ))
         _con_client.commit()
         _cur.close()
     except (Exception) as e:
         print('error: ' + str(e))
     finally:
         if _db is not None:
             _db.disconnect()
             print("Se cerro la conexion LOG")
Ejemplo n.º 18
0
    def update_customer_user_favorite(self,customerUserFavorite):
        _db = None
        _status = 1
        try:
            _db = Database()
            _db.connect(self.host,self.port,self.user,self.password,self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()

            _sql = """SELECT c.id_user, c.id_customer, c."enable"
                    FROM   main.customer_user_favorite c 
                    WHERE c.id_user = %s and c.id_customer = %s;"""   

            _cur = _con_client.cursor()
            _cur.execute(_sql,(customerUserFavorite.id_user,customerUserFavorite.id_customer,))
            _rows = _cur.fetchall()
        
            if len(_rows) == 0 or _rows is None:
                _sql_add = """INSERT INTO main.customer_user_favorite (id_user, id_customer, "enable", status) 
                             VALUES(%s, %s, %s, %s);"""
                _cur.execute(_sql_add,(customerUserFavorite.id_user,customerUserFavorite.id_customer,customerUserFavorite.enable,_status,))
            else:
                _sql_update = """UPDATE main.customer_user_favorite SET "enable" = %s WHERE id_user = %s and id_customer = %s;"""
                _cur.execute(_sql_update,(customerUserFavorite.enable,customerUserFavorite.id_user,customerUserFavorite.id_customer,))


            _con_client.commit()
            _cur.close()
        except(Exception) as e:
            self.add_log(str(e),type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return customerUserFavorite
Ejemplo n.º 19
0
    def login_customer(self, loginEntity):
        _db = None
        _status = 1
        _entity = None
        try:
            _mail = loginEntity.mail
            _password = loginEntity.password
            _db = Database()
            _db.connect(self.host, self.port, self.user, self.password,
                        self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()

            _sql = """SELECT id, 
                        mail, 
                        full_name, 
                        cellphone, 
                        photo,
                        id_code,
                        referred_code
                    FROM   main.customer c 
                    WHERE  c.status = %s
                        AND c.mail = %s 
                        AND c."password" = %s; """

            _cur = _con_client.cursor()
            _cur.execute(_sql, (
                _status,
                _mail,
                _password,
            ))
            _rows = _cur.fetchall()

            if len(_rows) >= 1:
                _entity = customerEntity()
                _entity.id = _rows[0][0]
                _entity.mail = _rows[0][1]
                _entity.full_name = _rows[0][2]
                _entity.cellphone = _rows[0][3]
                _entity.photo = _rows[0][4]
                _entity.id_code = _rows[0][5]
                _entity.referred_code = _rows[0][6]

                _sql_fire_base = """UPDATE main.customer SET id_fire_base_token = %s WHERE id = %s;"""
                _cur.execute(_sql_fire_base, (
                    loginEntity.id_fire_base_token,
                    _entity.id,
                ))
                _con_client.commit()

            _cur.close()
        except (Exception) as e:
            self.add_log(str(e), type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return _entity
    def get_user_date_availability_by_user(self, id_user):
        _db = None
        _status = 1
        _data_row = []
        _id_user = id_user
        try:
            _db = Database()
            _db.connect(self.host, self.port, self.user, self.password,
                        self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()
            _sql = """SELECT ud.id_user, 
                        ud.id_type_availability, 
                        ta.full_name, 
                        to_char(ud.date_availability,'DD-MM-YYYY') as date_availability, 
                        ud.hour_availability, 
                        ud."enable"
                    FROM   main.user_date_availability ud 
                        INNER JOIN main.type_availability ta 
                                ON ud.id_type_availability = ta.id 
                    WHERE  ud.status = %s and ud.id_user = %s and ud."enable" = 1
                    order by 4,5; """

            _cur = _con_client.cursor()
            _cur.execute(_sql, (
                _status,
                _id_user,
            ))
            _rows = _cur.fetchall()
            _id_date_old = None
            for row in _rows:
                _entity = userDateAndHourAvailabilityEntity()
                _entity.id_user = row[0]
                _entity.id_type_availability = row[1]
                _entity.full_name = row[2]
                _entity.date_availability = row[3]
                _entity.enable = row[5]
                _hours = []
                if _id_date_old != _entity.date_availability:
                    for se in _rows:
                        if row[3] == se[3]:
                            _hours.append(se[4])

                    _entity.hours_availability = _hours
                    _data_row.append(_entity)
                    _id_date_old = _entity.date_availability

            _cur.close()
        except (Exception) as e:
            self.add_log(str(e), type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return _data_row
    def update_user_date_availability(self, entity):
        _db = None
        _status = 1
        _i = 0
        _data_row = []
        try:
            _db = Database()
            _db.connect(self.host, self.port, self.user, self.password,
                        self.database)
            _entities = entity.user_date_availabilities
            print('Se conecto a la bd')
            _con_client = _db.get_client()
            _cur = _con_client.cursor()

            if (len(_entities) >= 1):
                _en = _entities[0]
                _sql_delete = """DELETE FROM main.user_date_availability 
                                WHERE  id_user = %s 
                                    AND id_type_availability = %s
                                    AND date_availability = To_date(%s, 'DD-MM-YYYY'); """
                _cur.execute(_sql_delete, (
                    _en.id_user,
                    _en.id_type_availability,
                    _en.date_availability,
                ))

            _sql_insert = """INSERT INTO main.user_date_availability
                                (id_user, id_type_availability, date_availability, hour_availability, enable, status) 
                                VALUES(%s, %s,to_date(%s,'DD-MM-YYYY') , %s, %s, %s) RETURNING status;"""

            for us in _entities:
                if (us.hour_availability >= 1):
                    _cur.execute(_sql_insert, (
                        us.id_user,
                        us.id_type_availability,
                        us.date_availability,
                        us.hour_availability,
                        us.enable,
                        _status,
                    ))
                    _status_insert = _cur.fetchone()[0]
                    _entities[_i].status = _status_insert
                    _data_row.append(_entities[_i])
                    _i += 1

            _con_client.commit()
            _cur.close()
        except (Exception) as e:
            self.add_log(str(e), type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return _data_row
Ejemplo n.º 22
0
    def get_customer_card_by_id_customer(self,id_customer):
        _db = None
        _status = 1
        _data = []
        _id_customer = id_customer
        try:
            _db = Database()
            _db.connect(self.host,self.port,self.user,self.password,self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()

            _sql = """SELECT cc.id, 
                    cc.id_customer,
                    id_type_card, 
                    document_number, 
                    expiration_year, 
                    expiration_month, 
                    email, 
                    full_name_card, 
                    tc.brand, 
                    tc.url_image 
                FROM   main.customer_card cc 
                    INNER JOIN main.type_card tc 
                            ON cc.id_type_card = tc.id 
                WHERE  cc.status = %s 
                    AND cc.id_customer = %s; """   

            _cur = _con_client.cursor()
            _cur.execute(_sql,(_status,_id_customer,))
            _rows = _cur.fetchall()
        
            for row in _rows:
                _entity  = customerCardEntity()
                _entity.id = row[0]
                _entity.id_customer = row[1]
                _entity.id_type_card = row[2]
                _entity.document_number =row[3]
                _entity.expiration_year =row[4]
                _entity.expiration_month =row[5]
                _entity.email =row[6]
                _entity.full_name_card =row[7]
                _entity.brand =row[8]
                _entity.url_image =row[9]
                _data.append(_entity)

            _cur.close()
        except(Exception) as e:
            self.add_log(str(e),type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return _data
Ejemplo n.º 23
0
    def get_sub_services(self, id_service):
        _db = None
        _status = 1
        _data_row = []
        _id_service = id_service
        try:
            _db = Database()
            _db.connect(self.host, self.port, self.user, self.password,
                        self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()
            _sql = """SELECT ss.id, 
                    s.full_name  AS service, 
                    ss.full_name sub_service, 
                    ss.status, 
                    ss.in_filter 
                FROM   main.sub_service ss 
                    INNER JOIN main.service s 
                            ON ss.id_service = s.id 
                WHERE  ss.id_service = CASE 
                                        WHEN %s = 0 THEN ss.id_service 
                                        ELSE %s 
                                    END 
                ORDER  BY 1; """
            _cur = _con_client.cursor()
            _cur.execute(_sql, (
                _id_service,
                _id_service,
            ))
            _rows = _cur.fetchall()
            for row in _rows:
                _entity = subServiceEntity()
                _entity.id = row[0]
                _entity.service = row[1]
                _entity.full_name = row[2]
                _entity.status = row[3]
                _entity.in_filter = row[4]
                _data_row.append(_entity)

            _cur.close()
        except (Exception) as e:
            self.add_log(str(e), type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return _data_row
Ejemplo n.º 24
0
    def add_customer(self,entity):
        _db = None
        _id_customer = 0
        _status = 1
        _status_first_sale = 0
        _i = 0
        try:
            _db = Database()
            _db.connect(self.host,self.port,self.user,self.password,self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()
            _sql = """INSERT INTO main.customer (mail,full_name,cellphone,photo,password,referred_code,status,status_first_sale) 
                    VALUES(%s,%s,%s,%s,%s,%s,%s,%s) RETURNING id;"""
            _cur = _con_client.cursor()
            _cur.execute(_sql, (entity.mail,entity.full_name,entity.cellphone,
                                entity.photo,entity.password,entity.referred_code,_status,
                                _status_first_sale))
            _id_customer = _cur.fetchone()[0]
            entity.id = _id_customer

            _date = datetime.now()
            _id_code = "COD-APP"+ str(_id_customer) +"-"+ str(_date.hour)+str(_date.year)+str(_date.month)
            _sql_coupon = """UPDATE main.customer SET id_code = %s WHERE id = %s;"""
            _cur.execute(_sql_coupon,(_id_code,_id_customer))
            entity.id_code = _id_code

            _sql_store = """INSERT INTO main.customer_address(id_customer, address, longitude , latitude, main, status) 
                            VALUES(%s,%s,%s,%s,%s,%s) RETURNING id;"""
            for us in entity.customer_address:
                _cur.execute(_sql_store, (_id_customer,us.address,us.longitude,us.latitude,us.main,_status))
                _id_customer_address = _cur.fetchone()[0]
                entity.customer_address[_i].id = _id_customer_address
                entity.customer_address[_i].id_customer = _id_customer
                _i += 1

            _con_client.commit()
            _cur.close()
        except(Exception) as e:
            self.add_log(str(e),type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return entity
Ejemplo n.º 25
0
    def add_sale_reserve(self,saleEntity):

        _db = None
        _id_user = 0
        _status = 1
        _status_sale = 0
        _i = 0
        try:
            _db = Database()
            _db.connect(self.host,self.port,self.user,self.password,self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()
            _sql = """INSERT INTO main.sale (id_type_availability, id_customer, id_user, coupon, date_availability, hour_availability, total_amount,
                      status, date_transaction,id_type_card, document_number,expiration_year,expiration_month,mail,full_name_card,id_customer_address,status_sale, 
                      amount_coupon,id_user_store,amount_delivery,"comment")
                      VALUES(%s,%s,%s,%s,to_date(%s,'DD-MM-YYY'),%s,%s,%s,current_timestamp,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) RETURNING id;"""
            _cur = _con_client.cursor()
            _cur.execute(_sql, (saleEntity.id_type_availability,saleEntity.id_customer,saleEntity.id_user,
                                saleEntity.coupon,saleEntity.date_availability,saleEntity.hour_availability,
                                saleEntity.total_amount,_status,saleEntity.id_type_card,
                                saleEntity.document_number,saleEntity.expiration_year,saleEntity.expiration_month,
                                saleEntity.mail,saleEntity.full_name_card,saleEntity.id_customer_address,_status_sale,
                                saleEntity.amount_coupon,saleEntity.id_user_store,saleEntity.amount_delivery,saleEntity.comment))
            _id_sale = _cur.fetchone()[0]
            saleEntity.id = _id_sale
            
            _sql_store = """INSERT INTO main.type_sale (id_sale, id_sub_service, amount, status,date_transaction) 
                            VALUES(%s,%s,%s,%s,current_timestamp) RETURNING id;"""
            for us in saleEntity.type_sales:
                _cur.execute(_sql_store, (_id_sale,us.id_sub_service,us.amount,_status))
                _id_type_sale = _cur.fetchone()[0]
                saleEntity.type_sales[_i].id = _id_type_sale
                saleEntity.type_sales[_i].id_sale = _id_sale
                _i += 1

            _con_client.commit()
            _cur.close()
        except(Exception) as e:
            self.add_log(str(e),type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return saleEntity
Ejemplo n.º 26
0
    def get_sub_services_by_id_service_and_id_user(self, id_service, id_user):
        _db = None
        _data = []
        try:
            _id_service = id_service
            _id_user = id_user
            _db = Database()
            _db.connect(self.host, self.port, self.user, self.password,
                        self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()
            _sql = """SELECT ss.id, 
                    ss.full_name, 
                    uss.charge, 
                    ss.id_service, 
                    uss.id_user 
                FROM   main.user_sub_service uss 
                    INNER JOIN main.sub_service ss 
                            ON uss.id_sub_service = ss.id 
                WHERE  uss.id_service = %s 
                    AND id_user = %s;"""
            _cur = _con_client.cursor()
            _cur.execute(_sql, (
                _id_service,
                _id_user,
            ))
            _rows = _cur.fetchall()

            for row in _rows:
                _entity = subServiceEntity()
                _entity.id = row[0]
                _entity.full_name = row[1]
                _entity.charge = row[2]
                _data.append(_entity)

            _cur.close()
        except (Exception) as e:
            self.add_log(str(e), type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return _data
Ejemplo n.º 27
0
    def get_customer_address_by_id_customer(self,id_customer):
        _db = None
        _status = 1
        _data = []
        _id_customer = id_customer
        try:
            _db = Database()
            _db.connect(self.host,self.port,self.user,self.password,self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()

            _sql = """SELECT id, 
                    id_customer, 
                    address, 
                    longitude, 
                    latitude, 
                    main 
                FROM   main.customer_address ca 
                WHERE  id_customer = %s 
                    AND status = %s; """   

            _cur = _con_client.cursor()
            _cur.execute(_sql,(_id_customer,_status,))
            _rows = _cur.fetchall()
        
            for row in _rows:
                _entity  = customerAddressEntity()
                _entity.id = row[0]
                _entity.id_customer = row[1]
                _entity.address =row[2]
                _entity.longitude =row[3]
                _entity.latitude =row[4]
                _entity.main =row[5]
                _data.append(_entity)

            _cur.close()
        except(Exception) as e:
            self.add_log(str(e),type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return _data
Ejemplo n.º 28
0
    def get_quantity_first_sales(self,id_customer):
        _db = None
        _status = 1
        _referred_code = None
        _quantity = None
        _status_first_sale = 1
        try:
            _id_customer = id_customer
            _db = Database()
            _db.connect(self.host,self.port,self.user,self.password,self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()
            _cur = _con_client.cursor()

            _sql = """SELECT s.referred_code
                    FROM   main.customer s 
                    WHERE s.id = %s; """   

            _cur.execute(_sql,(_id_customer,))
            _rows = _cur.fetchall()
            if len(_rows) >= 1:
                _referred_code = _rows[0][0]

            print(_referred_code)

            _sql_quantity = """SELECT count(*) as quantity 
                FROM   main.customer s 
                WHERE s.referred_code = %s and s.status_first_sale = %s; """   
            _cur.execute(_sql_quantity,(_referred_code,_status_first_sale,))
            _rows = _cur.fetchall()
            if len(_rows) >= 1:
                _quantity = _rows[0][0]
            print(_quantity)

            _cur.close()
        except(Exception) as e:
            self.add_log(str(e),type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return _quantity
Ejemplo n.º 29
0
    def login_user_web(self, full_name, password):
        _db = None
        _status = 1
        _entity = None
        try:
            _full_name = full_name
            _password = password
            _db = Database()
            _db.connect(self.host, self.port, self.user, self.password,
                        self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()

            _sql = """SELECT u.id, 
                        u.full_name
                    FROM   main.user_web u 
                    WHERE  u.status = %s
                        AND u.full_name = %s 
                        AND u."password" = %s; """

            _cur = _con_client.cursor()
            _cur.execute(_sql, (
                _status,
                _full_name,
                _password,
            ))
            _rows = _cur.fetchall()

            if len(_rows) >= 1:
                _entity = userEntity()
                _entity.id = _rows[0][0]
                _entity.full_name = _rows[0][1]

            _cur.close()
        except (Exception) as e:
            self.add_log(str(e), type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return _entity
Ejemplo n.º 30
0
    def get_sub_services_by_id(self, id_sub_service):
        _db = None
        _id_sub_service = id_sub_service
        _entity = None
        try:
            _db = Database()
            _db.connect(self.host, self.port, self.user, self.password,
                        self.database)
            print('Se conecto a la bd')
            _con_client = _db.get_client()
            _sql = """SELECT ss.id, 
                    ss.full_name AS sub_service, 
                    s.id         AS id_service, 
                    s.full_name  AS service, 
                    ss.status, 
                    ss.in_filter 
                FROM   main.sub_service ss 
                    INNER JOIN main.service s 
                            ON ss.id_service = s.id 
                WHERE  ss.id = %s;"""
            _cur = _con_client.cursor()
            _cur.execute(_sql, (_id_sub_service, ))
            _rows = _cur.fetchall()

            if len(_rows) >= 1:
                _entity = subServiceEntity()
                _entity.id = _rows[0][0]
                _entity.full_name = _rows[0][1]
                _entity.id_service = _rows[0][2]
                _entity.service = _rows[0][3]
                _entity.status = _rows[0][4]
                _entity.in_filter = _rows[0][5]

            _cur.close()
        except (Exception) as e:
            self.add_log(str(e), type(self).__name__)
        finally:
            if _db is not None:
                _db.disconnect()
                print("Se cerro la conexion")
        return _entity