Ejemplo n.º 1
0
 def __init__(self, **kwargs):
     self.__session = Session()
     self.__args = kwargs
     self._retval = list()
     self.__search_filter = list()
     self.__search_param = ['attendant_name', 'attendantid']
     self.__data = None
Ejemplo n.º 2
0
 def __init__(self, **kwargs):
     self.__session = Session()
     self.__args = kwargs
     self._retval = list()
     self.__search_filter = list()
     self.__search_param = ['service_name']
     self.__data = None
Ejemplo n.º 3
0
 def __init__(self, **kwargs):
     self.__session = Session()
     self.__args = kwargs
     self._retval = list()
     self.__search_filter = list()
     self.__search_param = ['member00id']
     self.__data = None
Ejemplo n.º 4
0
    def __init__(self, **kwargs):
        self.__session = Session()
        self.__args = kwargs
        self._retval = list()
        self.__search_filter = list()
        self.__search_param = ['username', 'password', 'role']
        self.__data = None

        for key in self.__search_param:
            if key in self.__args and self.__args[key] not in (None, ''):
                self.__search_filter.append(
                    getattr(Users_table, key) == self.__args[key])

        if len(self.__search_filter) != 0:
            self.__data = self.__session.query(Users_table).filter(
                *self.__search_filter).order_by(Users_table.userid).all()

            for d in self.__data:
                r = d.toJSONExcept()
                self._retval.append(r)

        else:
            self.__data = self.__session.query(Users_table).order_by(
                Users_table.userid).all()

            for d in self.__data:
                r = d.toJSONExcept()
                self._retval.append(r)
Ejemplo n.º 5
0
    def __init__(self, **kwargs):
        self.__session = Session()
        self.__args = kwargs
        self.__retval = dict()

        # column start for insert of image
        self.__column = 0
Ejemplo n.º 6
0
 def __init__(self, **kwargs):
     self.__session = Session()
     self.__args = kwargs
     self._retval = list()
     self.__search_filter = list()
     self.__search_param = [
         'member00id', 'membertype', 'attendantid', 'upgraded_by'
     ]
     self.__data = None
Ejemplo n.º 7
0
    def __init__(self, querytype='all', **kwargs):
        self.__session = Session()
        self.__args = kwargs
        self._retval = list()
        self.__search_filter = list()
        self.__search_param = [
            'active', 'transaction_type', 'transactionid', 'attendantid',
            'member00id'
        ]
        self.__data = None

        for key in self.__search_param:
            if key in self.__args and self.__args[key] not in (None, ""):
                self.__search_filter.append(
                    getattr(T_Transaction, key) == self.__args[key])

        ds = self.__args.get('from', None)
        de = self.__args.get('to', None)

        if ds and de:
            self.__search_filter.append(
                getattr(T_Transaction, 'datecreated').between(ds, de))

        if self.__search_filter:
            self.__data = self.__session.query(T_Transaction).filter(
                and_(*self.__search_filter)).order_by(
                    T_Transaction.datestart).all()

            for d in self.__data:
                r = d.toJSONExcept()
                time = datetime.datetime.strptime(r['datestart'],
                                                  '%m/%d/%Y %H:%M')
                r['started'] = time.time().strftime("%I:%M %p")
                etime = time + datetime.timedelta(
                    minutes=int(d.estimated_time))
                r['endtime'] = etime.strftime("%I:%M %p")
                self._retval.append(r)

        elif querytype is not None:
            self.__data = self.__session.query(T_Transaction).order_by(
                T_Transaction.datestart).all()

            for d in self.__data:
                r = d.toJSONExcept()
                time = datetime.datetime.strptime(r['datestart'],
                                                  '%m/%d/%Y %H:%M')
                r['started'] = time.time().strftime("%I:%M %p")
                etime = time + datetime.timedelta(
                    minutes=int(d.estimated_time))
                r['endtime'] = etime.strftime("%I:%M %p")
                self._retval.append(r)
Ejemplo n.º 8
0
class Product_data(Mini_func):
    def __init__(self):
        self.__session = Session()

    def purchase_product(self, **kwargs):
        prod = T_Products()

        for key in kwargs:
            try:
                setattr(prod, key, kwargs[key])
            except TypeError:
                continue

        self.__session.add(prod)

        self.__session.commit()
Ejemplo n.º 9
0
    def __init__(self, **kwargs):
        self.__session = Session()
        self.__data = ''
        self.__args = kwargs
        self.__search_filter = list()
        self.__search_param = ['username', 'password']
        self.__inputed_pass = None

        for key in self.__search_param:
            if key in self.__args and self.__args[key] not in (None, ''):
                if key in ('username'):
                    self.__search_filter.append(
                        getattr(Users_table, key) == self.__args[key])
                elif key in ('password'):
                    self.__inputed_pass = self.__args[key]

        if len(self.__search_filter) != 0:
            data = self.__session.query(Users_table).filter(
                *self.__search_filter)
            self.__data = [x for x in data]
Ejemplo n.º 10
0
class Login_validation(object):
    def __init__(self, **kwargs):
        self.__session = Session()
        self.__data = ''
        self.__args = kwargs
        self.__search_filter = list()
        self.__search_param = ['username', 'password']
        self.__inputed_pass = None

        for key in self.__search_param:
            if key in self.__args and self.__args[key] not in (None, ''):
                if key in ('username'):
                    self.__search_filter.append(
                        getattr(Users_table, key) == self.__args[key])
                elif key in ('password'):
                    self.__inputed_pass = self.__args[key]

        if len(self.__search_filter) != 0:
            data = self.__session.query(Users_table).filter(
                *self.__search_filter)
            self.__data = [x for x in data]

    def validate(self):
        retval = dict()

        if len(self.__data) == 0:
            retval = {
                'status': 'Failed',
                'data': [{
                    'Message': 'Invalid Credentials'
                }],
                'total': 0
            }

            return retval

        username = getattr(self.__data[0], 'username')
        hashed_password = str.encode(getattr(self.__data[0], 'password'))
        inputed_pass = str.encode(
            self.__inputed_pass
        ) if self.__inputed_pass is not None else str.encode('')

        if bcrypt.hashpw(inputed_pass, hashed_password) == hashed_password:
            retval = {
                'status': 'OK',
                'data': [d.toJSONExcept() for d in self.__data],
                'total': 1
            }

            http_session['username'] = username
        else:
            retval = {
                'status': 'Failed',
                'data': [{
                    'Message': 'Incorrect Password'
                }],
                'total': 0
            }

        return retval

    def __del__(self):
        if self.__session is not None:
            self.__session.close()
Ejemplo n.º 11
0
class Member00_data(Mini_func):
    def __init__(self, **kwargs):
        self.__session = Session()
        self.__args = kwargs
        self._retval = list()
        self.__search_filter = list()
        self.__search_param = [
            'member00id', 'membertype', 'attendantid', 'upgraded_by'
        ]
        self.__data = None

    def getmemberdata(self):

        for key in self.__search_param:
            if key in self.__args and self.__args[key] not in (None, ""):
                self.__search_filter.append(
                    getattr(T_Member00, key) == self.__args[key])

        ds = self.__args.get('from', None)
        de = self.__args.get('to', None)
        upg = self.__args.get('upgraded_by', None)

        if ds and de and not upg:
            self.__search_filter.append(
                getattr(T_Member00, 'datecreated').between(ds, de))

        if ds and de and upg:
            self.__search_filter.append(
                getattr(T_Member00, 'upgraded').between(ds, de))

        if not self.__search_filter:
            self.__data = self.__session.query(T_Member00).order_by(
                T_Member00.member00id).all()

            for d in self.__data:
                r = d.toJSONExcept()
                self._retval.append(r)

        else:
            self.__data = self.__session.query(T_Member00).filter(
                *self.__search_filter).order_by(T_Member00.member00id).all()

            for d in self.__data:
                r = d.toJSONExcept()
                self._retval.append(r)

    def postmemberdata(self, **kwargs):

        member = T_Member00()

        for key in kwargs:
            try:
                setattr(member, key, kwargs[key])
            except TypeError:
                continue

        self.__session.add(member)

        self.__session.commit()

        query = "select max(member00id) from member00;"
        result = self.__session.execute(query).first()

        for memid in result:
            r = {'member00id': memid}
            self._retval.append(r)

    def editmemberdata(self, **kwargs):
        update_kwargs = kwargs
        search_param = ['member00id']
        search_filter = list()
        retval = False

        for key in search_param:
            if key in update_kwargs and update_kwargs[key] not in (None, ""):
                search_filter.append(
                    getattr(T_Member00, key) == update_kwargs[key])

        if search_filter:
            retval = True
            data = self.__session.query(T_Member00).filter(
                *search_filter).order_by(T_Member00.member00id).all()

        update_param = [
            'membershipcost', 'membertype', 'upgraded_by', 'upgraded',
            'address', 'mobile_number', 'landline_number', 'email_address',
            'birthdate', 'name'
        ]

        print(update_kwargs)
        for obj in data:
            for key in update_param:
                if key in update_kwargs and update_kwargs[key] not in (None,
                                                                       ""):
                    if key == 'upgraded':
                        print('upgraded')
                        update_kwargs[key] = datetime.datetime.strptime(
                            update_kwargs[key], '%m/%d/%Y')
                        print(update_kwargs[key])
                    try:
                        setattr(obj, key, update_kwargs[key])
                    except TypeError:
                        continue

        self.__session.commit()

        return retval

    def get_customize_members(self, char):
        memtype = self.__args.get('membertype', None)

        result = self.__session.query(T_Member00).filter(
            T_Member00.name.like("%{}%".format(char))).filter(
                T_Member00.membertype == "{}".format(memtype)).all()

        for d in result:
            r = d.toJSONExcept()
            print(r)
            self._retval.append(r)

    def __del__(self):
        if self.__session is not None:
            self.__session.close()
Ejemplo n.º 12
0
class Login_data(Mini_func, object):
    def __init__(self, **kwargs):
        self.__session = Session()
        self.__args = kwargs
        self._retval = list()
        self.__search_filter = list()
        self.__search_param = ['username', 'password', 'role']
        self.__data = None

        for key in self.__search_param:
            if key in self.__args and self.__args[key] not in (None, ''):
                self.__search_filter.append(
                    getattr(Users_table, key) == self.__args[key])

        if len(self.__search_filter) != 0:
            self.__data = self.__session.query(Users_table).filter(
                *self.__search_filter).order_by(Users_table.userid).all()

            for d in self.__data:
                r = d.toJSONExcept()
                self._retval.append(r)

        else:
            self.__data = self.__session.query(Users_table).order_by(
                Users_table.userid).all()

            for d in self.__data:
                r = d.toJSONExcept()
                self._retval.append(r)

    def insert_user(self, **kwargs):

        user = Users_table()

        for key in kwargs:
            if key in ('password'):
                try:
                    setattr(user, key, self.encrypt_password(kwargs[key]))
                except TypeError:
                    continue
            else:
                try:
                    setattr(user, key, kwargs[key])
                except TypeError:
                    continue

        self.__session.add(user)

        self.__session.commit()

        data = self.__session.query(Users_table).filter(
            Users_table.userid == user.userid)

        self._retval = list()

        for d in data:
            r = d.toJSONExcept()
            self._retval.append(r)

    def encrypt_password(self, password):
        converted_pass = str.encode(password)
        salt = bcrypt.gensalt()
        hashed = bcrypt.hashpw(converted_pass, salt)
        retval = hashed.decode('utf-8')

        return retval

    def __del__(self):
        if self.__session is not None:
            self.__session.close()
Ejemplo n.º 13
0
class Promomodel(object):
    def __init__(self, **kwargs):
        self.__session = Session()
        self.__kwargs = kwargs

    def make_promo(self):
        promo = T_promos()

        for key, value in self.__kwargs.items():

            if value:
                if key in ('datestart', 'dateend'):
                    value = value.strftime('%Y-%m-%d')

                setattr(promo, key, value)

        self.__session.add(promo)

        self.__session.commit()

    def get_promo(self):
        retval = list()
        search_filter = list()

        for key, value in self.__kwargs.items():
            if key in ('curdate') and value:
                datetoday = datetime.datetime.now().date().strftime('%Y-%m-%d')
                search_filter.append(
                    getattr(T_promos, 'datestart') <= datetoday)
                search_filter.append(getattr(T_promos, 'dateend') >= datetoday)
            else:
                if value:
                    search_filter.append(getattr(T_promos, key) == value)

        if search_filter:
            result = self.__session.query(T_promos).filter(
                and_(*search_filter)).all()

            for data in result:
                dict_data = data.toJSONExcept()
                retval.append(dict_data)

        else:
            result = self.__session.query(T_promos).all()

            for data in result:
                dict_data = data.toJSONExcept()
                retval.append(dict_data)

        return retval

    def edit_promo(self):
        retval = None

        promoid = self.__kwargs.get('promoid', 0)

        if not promoid:
            return retval

        promoobj = self.__session.query(T_promos).filter(
            getattr(T_promos, 'promoid') == promoid).first()

        for key, value in self.__kwargs.items():

            if value in ('', None):
                continue

            if key in ('datestart', 'dateend'):
                dateval = datetime.datetime.strptime(value, '%m/%d/%Y')
                value = dateval.strftime('%Y-%m-%d')

            setattr(promoobj, key, value)

        try:
            self.__session.commit()
        except:
            retval = None
        else:
            retval = self.__kwargs

        return retval
Ejemplo n.º 14
0
class Member01_data(Mini_func):
    def __init__(self, **kwargs):
        self.__session = Session()
        self.__args = kwargs
        self._retval = list()
        self.__search_filter = list()
        self.__search_param = ['member00id']
        self.__data = None

    def getmemberdata(self):

        for key in self.__search_param:
            if key in self.__args and self.__args[key] not in (None, ""):
                self.__search_filter.append(
                    getattr(T_Member01, key) == self.__args[key])

        if not self.__search_filter:
            self.__data = self.__session.query(T_Member01).order_by(
                T_Member01.member00id).all()

            for d in self.__data:
                r = d.toJSONExcept()
                self._retval.append(r)

        else:
            if len(self.__search_filter) != 0:
                self.__data = self.__session.query(T_Member01).filter(
                    *self.__search_filter).order_by(
                        T_Member01.member01id).all()

                for d in self.__data:
                    r = d.toJSONExcept()
                    self._retval.append(r)

    def postmemberdata(self, **kwargs):

        member = T_Member01()

        for key in kwargs:
            try:
                setattr(member, key, kwargs[key])
            except TypeError:
                continue

        self.__session.add(member)

        self.__session.commit()

    def get_customize_members(self, char):
        sel_statement = """SELECT name, membertype, member00id from member00 where name like '%{0}%' union all
						   SELECT name, relationship, member00id from member01 where name like '%{0}%' """.format(
            char)

        result = self.__session.execute(sel_statement)

        for d in result:
            r = {
                'name': d.name,
                'membertype': d.membertype,
                'member00id': d.member00id
            }
            self._retval.append(r)

    def __del__(self):
        if self.__session is not None:
            self.__session.close()
Ejemplo n.º 15
0
class Attendants_data(Mini_func):
    def __init__(self, **kwargs):
        self.__session = Session()
        self.__args = kwargs
        self._retval = list()
        self.__search_filter = list()
        self.__search_param = ['attendant_name', 'attendantid']
        self.__data = None

    def get_attendants(self):

        for key in self.__search_param:
            if key in self.__args and self.__args[key] not in (None, ""):
                self.__search_filter.append(
                    getattr(T_Attendants, key) == self.__args[key])

        if not self.__search_filter:
            self.__data = self.__session.query(T_Attendants).order_by(
                T_Attendants.attendantid).all()

            for d in self.__data:
                r = d.toJSONExcept()
                self._retval.append(r)

        else:
            self.__data = self.__session.query(T_Attendants).filter(
                *self.__search_filter).order_by(
                    T_Attendants.attendantid).all()

            for d in self.__data:
                r = d.toJSONExcept()
                self._retval.append(r)

    def del_attendants(self):
        retval = False

        if self.__data:
            retval = True
            for data in self.__data:
                self.__session.delete(data)

        try:
            self.__session.commit()
        except:
            self.__session.rollback()

        return retval

    def insert_Attendant(self, **kwargs):
        attendant = T_Attendants()

        for key in kwargs:
            try:
                setattr(attendant, key, kwargs[key])
            except TypeError:
                continue

        self.__session.add(attendant)

        self.__session.commit()

    def edit_attendant(self, **kwargs):
        update_kwargs = kwargs
        search_param = ['attendantid']
        search_filter = list()

        for key in search_param:
            if key in update_kwargs and update_kwargs[key] not in (None, ''):
                search_filter.append(
                    getattr(T_Attendants, key) == update_kwargs[key])

        if search_filter:
            retval = True
            self.__data = self.__session.query(T_Attendants).filter(
                and_(*search_filter)).order_by(T_Attendants.attendantid).all()
        else:
            retval = False

        update_list = ['position', 'allowance']
        for obj in self.__data:
            for key in update_list:
                if key in update_kwargs and update_kwargs[key] not in ('',
                                                                       None):
                    try:
                        setattr(obj, key, update_kwargs[key])
                    except TypeError:
                        continue

        self.__session.commit()

    def __del__(self):
        if self.__session is not None:
            self.__session.close()
Ejemplo n.º 16
0
 def __init__(self, **kwargs):
     self.__session = Session()
     self.__args = kwargs
Ejemplo n.º 17
0
class Attendant_report(object):
    def __init__(self, **kwargs):
        self.__session = Session()
        self.__args = kwargs
        self.__retval = None
        self.__tempdict = dict()
        self.__total = 0

    def get_reports_data(self):
        """."""
        ds = self.__args.get('from', None)
        de = self.__args.get('to', None)
        by_id = self.__args.get('attendantid', None)

        if all([ds, de, by_id]):
            self.__tempdict['data'] = list()
            transactionstotal, transsales = self.__get_transactions(
                ds, de, by_id)
            memberstotal, memsales = self.__get_members(ds, de, by_id)
            upgradestotal, upgradessales = self.__get_members_upg(
                ds, de, by_id)

        if self.__tempdict:
            self.__retval = self.__tempdict
            self.__retval['total_on_service'] = transactionstotal
            self.__retval['total_on_membership'] = memberstotal + upgradestotal
            self.__retval[
                'total_sales'] = transsales + memsales + upgradessales

        return self.__retval

    def __get_transactions(self, ds, de, attid):
        search_filter = list()

        search_filter.append(
            getattr(T_Transaction, 'datecreated').between(ds, de))
        search_filter.append(getattr(T_Transaction, 'attendantid') == attid)
        search_filter.append(getattr(T_Transaction, 'active') == 0)

        result = self.__session.query(T_Transaction).filter(
            and_(*search_filter)).all()

        total = 0
        total2 = 0

        for data in result:
            key = data.datecreated.strftime('%B-%d-%Y')

            # if key not in self.__tempdict:
            # 	self.__tempdict[key] = list()

            comm = self.__get_commision_on_services(data.service,
                                                    data.service_price,
                                                    data.transaction_type,
                                                    data.add_ons_price)

            total += comm
            total2 += data.total_amount

            data_dict = dict()
            data_dict = {
                'datecreated': key,
                'clientname': data.client_name,
                'services': data.service + ', ' + data.add_ons,
                'timespent':
                '{:02d}H:{:02d}M'.format(*divmod(data.time_spent, 60)),
                'amountpaid': data.total_amount,
                'commision_on_service': comm
            }

            self.__tempdict['data'].append(data_dict)

        return total, total2

    def __get_commision_on_services(self, service, serviceprice, trantype,
                                    add_ons_price):
        commlist = ['Hot Stone Massage', 'Shiatsu Massage']
        retval = 0

        servicecomm = 0
        if service in commlist:
            if serviceprice is None:
                serviceprice = 0

            servicecomm = int(serviceprice) * 0.10

        if not add_ons_price:
            return servicecomm

        addonsprices = add_ons_price.split(',')
        addonscomm = 0

        if trantype in ['Walk-In', 'Non-Member']:
            for price in addonsprices:
                if int(price) <= 299:
                    addonscomm += 25
                elif int(price) >= 300:
                    addonscomm += 50

        elif trantype == 'Member':
            for price in addonsprices:
                if int(price) <= 149:
                    addonscomm += 25
                elif int(price) >= 150:
                    addonscomm += 50

        retval = addonscomm + servicecomm

        return retval

    def __get_members(self, ds, de, attid):
        retval = list()
        search_filter = list()

        search_filter.append(
            getattr(T_Member00, 'datecreated').between(ds, de))
        search_filter.append(getattr(T_Member00, 'attendantid') == attid)

        result = self.__session.query(T_Member00).filter(
            and_(*search_filter)).all()

        total = 0
        total2 = 0

        for data in result:
            key = data.datecreated.strftime('%B-%d-%Y')

            # if key not in self.__tempdict:
            # 	self.__tempdict[key] = list()

            if data.upgraded:
                total += 25
                total2 += 300

                data_dict = dict()
                data_dict = {
                    'clientname': data.name,
                    'services': 'Membership Sold - ' + 'Personalized',
                    'amountpaid': 300,
                    'commision_on_service': 25,
                    'timespent': 'N/A',
                    'datecreated': key
                }
            else:

                comm = 25 if data.membertype == 'Personalized' else 50

                total += comm
                total2 += data.membershipcost

                data_dict = dict()
                data_dict = {
                    'clientname': data.name,
                    'services': 'Membership Sold - ' + data.membertype,
                    'amountpaid': data.membershipcost,
                    'commision_on_service': comm,
                    'timespent': 'N/A',
                    'datecreated': key
                }

            self.__tempdict['data'].append(data_dict)

        return total, total2

    def __get_members_upg(self, ds, de, attid):
        retval = list()
        search_filter = list()

        search_filter.append(getattr(T_Member00, 'upgraded').between(ds, de))
        search_filter.append(getattr(T_Member00, 'upgraded_by') == attid)

        result = self.__session.query(T_Member00).filter(
            and_(*search_filter)).all()

        total = 0
        total2 = 0

        for data in result:
            key = data.upgraded.strftime('%B-%d-%Y')

            # if key not in self.__tempdict:
            # 	self.__tempdict[key] = list()

            total += 25
            total2 += 300

            data_dict = dict()
            data_dict = {
                'clientname': data.name,
                'services':
                'Membership Sold - ' + data.membertype + '[UPGRADED]',
                'amountpaid': 300,
                'commision_on_service': 25,
                'timespent': 'N/A',
                'datecreated': key
            }

            self.__tempdict['data'].append(data_dict)

        return total, total2
Ejemplo n.º 18
0
class Transactions_data(Mini_func):
    def __init__(self, querytype='all', **kwargs):
        self.__session = Session()
        self.__args = kwargs
        self._retval = list()
        self.__search_filter = list()
        self.__search_param = [
            'active', 'transaction_type', 'transactionid', 'attendantid',
            'member00id'
        ]
        self.__data = None

        for key in self.__search_param:
            if key in self.__args and self.__args[key] not in (None, ""):
                self.__search_filter.append(
                    getattr(T_Transaction, key) == self.__args[key])

        ds = self.__args.get('from', None)
        de = self.__args.get('to', None)

        if ds and de:
            self.__search_filter.append(
                getattr(T_Transaction, 'datecreated').between(ds, de))

        if self.__search_filter:
            self.__data = self.__session.query(T_Transaction).filter(
                and_(*self.__search_filter)).order_by(
                    T_Transaction.datestart).all()

            for d in self.__data:
                r = d.toJSONExcept()
                time = datetime.datetime.strptime(r['datestart'],
                                                  '%m/%d/%Y %H:%M')
                r['started'] = time.time().strftime("%I:%M %p")
                etime = time + datetime.timedelta(
                    minutes=int(d.estimated_time))
                r['endtime'] = etime.strftime("%I:%M %p")
                self._retval.append(r)

        elif querytype is not None:
            self.__data = self.__session.query(T_Transaction).order_by(
                T_Transaction.datestart).all()

            for d in self.__data:
                r = d.toJSONExcept()
                time = datetime.datetime.strptime(r['datestart'],
                                                  '%m/%d/%Y %H:%M')
                r['started'] = time.time().strftime("%I:%M %p")
                etime = time + datetime.timedelta(
                    minutes=int(d.estimated_time))
                r['endtime'] = etime.strftime("%I:%M %p")
                self._retval.append(r)

    def insert_transaction(self, **kwargs):

        transaction = T_Transaction()

        for key in kwargs:
            try:
                setattr(transaction, key, kwargs[key])
            except TypeError:
                continue

        self.__session.add(transaction)

        self.__session.commit()

    def edit_transaction(self, **kwargs):
        update_kwargs = kwargs
        search_param = ['transactionid']
        search_filter = list()

        for key in search_param:
            if key in update_kwargs and update_kwargs[key] not in (None, ''):
                search_filter.append(
                    getattr(T_Transaction, key) == update_kwargs[key])

        if search_filter:
            retval = True
            self.__data = self.__session.query(T_Transaction).filter(
                and_(*search_filter)).order_by(T_Transaction.datestart).all()
        else:
            retval = False

        update_list = [
            'payment_type', 'dateend', 'time_spent', 'active', 'service_type',
            'service', 'add_ons', 'attendant_name', 'attendantid',
            'estimated_time', 'total_amount', 'service_price', 'add_ons_price'
        ]

        for obj in self.__data:
            for key in update_list:
                if key in update_kwargs and update_kwargs[key] is not None:
                    if key == 'dateend':
                        update_kwargs[key] = datetime.datetime.strptime(
                            update_kwargs[key], '%m/%d/%Y, %I:%M:%S %p')
                    try:
                        setattr(obj, key, update_kwargs[key])
                    except TypeError:
                        continue

        self.__session.commit()

        return retval

    def del_transaction(self):
        retval = False

        if self.__data:
            retval = True
            for data in self.__data:
                self.__session.delete(data)

        try:
            self.__session.commit()
        except:
            self.__session.rollback()

        return retval

    def __del__(self):
        self.__session.close()
Ejemplo n.º 19
0
class Facialmodel(Mini_func):
    def __init__(self, **kwargs):
        self.__session = Session()
        self.__args = kwargs

    def get_services(self):
        retval = None

        result = self.__session.query(T_Facial_Services).all()

        temp_list = list()
        for d in result:
            r = d.toJSONExcept()
            temp_list.append(r)

        if temp_list:
            retval = temp_list

        return retval

    def insert_facial_service(self, **kwargs):
        fservices = T_Facial_Services()

        for key, value in kwargs.items():
            try:
                setattr(fservices, key, value)
            except TypeError:
                continue

        self.__session.add(fservices)

        self.__session.commit()

    def del_facial_service(self, **kwargs):
        fsid = kwargs.get('id', 0)

        resdata = self.__session.query(T_Facial_Services).filter(
            T_Facial_Services.facial_services_id == fsid).first()

        if resdata:
            self.__session.delete(resdata)

        try:
            self.__session.commit()
        except:
            self.__session.rollback()

    def edit_facial_services(self, **kwargs):
        facialid = kwargs.get('facial_services_id', 0)

        result = self.__session.query(T_Facial_Services).filter(
            T_Facial_Services.facial_services_id == facialid).first()

        update_param = ['member_price', 'non_member_price', 'duration']

        for param in update_param:
            data = kwargs.get(param, None)

            if data:
                try:
                    setattr(result, param, data)
                except TypeError:
                    continue

        self.__session.commit()
Ejemplo n.º 20
0
class Regular_Services_data(Mini_func):
	def __init__(self,**kwargs):
		self.__session = Session()
		self.__args = kwargs
		self._retval = list()
		self.__search_filter = list()
		self.__search_param = ['service_name']
		self.__data = None

	def get_regular_services_data(self):
		for key in self.__search_param:
			if key in self.__args and self.__args[key] not in (None,""):
				self.__search_filter.append(getattr(T_Regular_Services,key)==self.__args[key])

		if len(self.__search_filter) != 0:
			self.__data = self.__session.query(T_Regular_Services).filter(*self.__search_filter).order_by(
				T_Regular_Services.peak_price).all()

			for d in self.__data:
				r = d.toJSONExcept()
				self._retval.append(r)
		else:
			self.__data = self.__session.query(T_Regular_Services).order_by(T_Regular_Services.peak_price).all()

			for d in self.__data:
				r = d.toJSONExcept()
				self._retval.append(r)

	def edit_regular_services_data(self, **kwargs):
		update_kwargs = kwargs
		search_param = ['regular_services_id']
		search_filter = list()

		for key in search_param:
			if key in update_kwargs and update_kwargs[key] not in (None,""):
				search_filter.append(getattr(T_Regular_Services, key) == update_kwargs[key])

		if search_filter:
			result = self.__session.query(T_Regular_Services).filter(*search_filter).all()
		else:
			return False

		update_param = ['off_peak_price', 'peak_price', 'non_member_price', 'duration']

		for obj in result:
			for key in update_param:
				if key in update_kwargs and update_kwargs[key] not in (None, ""):
					try:
						setattr(obj,key,update_kwargs[key])
					except TypeError:
						continue

		self.__session.commit()

	def insert_regular_services_data(self, **kwargs):
		"""."""
		regularservices = T_Regular_Services()

		for key in kwargs:
			try:
				setattr(regularservices,key,kwargs[key])
			except TypeError:
				continue

		self.__session.add(regularservices)

		self.__session.commit()

	def del_regular_services_data(self, **kwargs):
		"""."""
		retval = True
		regid = kwargs.get('id', 0)

		resdata = self.__session.query(T_Regular_Services).filter(T_Regular_Services.regular_services_id == regid).first()

		if resdata:
			self.__session.delete(resdata)

		try:
			self.__session.commit()
		except:
			self.__session.rollback()
			retval = False

		return retval


	def __del__(self):
		if self.__session is not None:
			self.__session.close()
Ejemplo n.º 21
0
 def __init__(self, **kwargs):
     self.__session = Session()
     self.__args = kwargs
     self.__retval = None
     self.__tempdict = dict()
     self.__total = 0
Ejemplo n.º 22
0
 def __init__(self, **kwargs):
     self.__session = Session()
     self.__args = kwargs
     self.__retval = dict()
Ejemplo n.º 23
0
class Memberslist_report(object):
    def __init__(self, **kwargs):
        self.__session = Session()
        self.__args = kwargs
        self.__retval = dict()

    def get_reports_data(self):
        datestart = self.__args['from']
        dateend = self.__args['to']

        memberslist = self.__get_members(datestart, dateend)
        print(memberslist)
        retval = self.__generate_excelfile(memberslist)

        return retval

    def __generate_excelfile(self, memberslist):
        wb = Workbook()
        ws = wb.active

        ws.title = "Personalized"
        wb.create_sheet(index=1, title='Family')
        wb.create_sheet(index=2, title='Upgraded')

        personalizedsheet = wb.get_sheet_by_name('Personalized')
        familysheet = wb.get_sheet_by_name('Family')
        upgradedsheet = wb.get_sheet_by_name('Upgraded')

        personalizeddata = memberslist.get('Personalized', list())
        familydata = memberslist.get('Family', list())
        upgradeddata = memberslist.get('Upgraded', list())

        self.__extract_personalized_data(personalizedsheet, personalizeddata)
        self.__extract_family_data(familysheet, familydata)
        self.__extract_upgraded_data(upgradedsheet, upgradeddata)

        # make file
        filename = datetime.datetime.now().strftime('%Y%m%d%H%M%S')

        folderpath = os.path.join(os.getcwd(), 'Reports')
        if not os.path.exists(folderpath):
            os.makedirs(folderpath)

        retval = 'Members_list' + filename + '.xlsx'
        wb.save(os.path.join(folderpath, retval))

        return retval

    def __extract_personalized_data(self, sheet, data):
        headers = [
            'name', 'address', 'birthdate', 'mobile_number', 'landline_number',
            'email_address', 'date_applied'
        ]

        ft = Font(bold=True)
        row_count = 1
        for column_count, header in enumerate(headers):
            cell = sheet.cell(row=row_count, column=column_count + 1)
            cell.value = header.upper()
            cell.font = ft

        row_count2 = 2
        for data_dict in data:

            for column_count, header in enumerate(headers):
                cell = sheet.cell(row=row_count2, column=column_count + 1)
                cell.value = data_dict[header]

            row_count2 += 1

    def __extract_family_data(self, sheet, data):
        headers = [
            'name', 'address', 'birthdate', 'mobile_number', 'landline_number',
            'email_address', 'submembers', 'date_applied'
        ]

        ft = Font(bold=True)
        row_count = 1
        for column_count, header in enumerate(headers):
            cell = sheet.cell(row=row_count, column=column_count + 1)
            cell.value = header.upper()
            cell.font = ft

        row_count2 = 2
        for data_dict in data:

            for column_count, header in enumerate(headers):
                cell = sheet.cell(row=row_count2, column=column_count + 1)
                cell.value = data_dict[header]

            row_count2 += 1

    def __extract_upgraded_data(self, sheet, data):
        headers = [
            'name', 'address', 'birthdate', 'mobile_number', 'landline_number',
            'email_address', 'submembers', 'date_upgraded'
        ]

        ft = Font(bold=True)
        row_count = 1
        for column_count, header in enumerate(headers):
            cell = sheet.cell(row=row_count, column=column_count + 1)
            cell.value = header.upper()
            cell.font = ft

        row_count2 = 2
        for data_dict in data:

            for column_count, header in enumerate(headers):
                cell = sheet.cell(row=row_count2, column=column_count + 1)
                cell.value = data_dict[header]

            row_count2 += 1

    def __get_members(self, ds, de):
        retval = dict()
        search_filter = [
            getattr(T_Member00, 'datecreated').between(self.__args['from'],
                                                       self.__args['to'])
        ]
        search_filter.append(getattr(T_Member00, 'attendantid') != 0)

        result = self.__session.query(T_Member00).filter(*search_filter).all()

        for data in result:
            temp_dict = dict()

            if data.upgraded or data.upgraded_by:
                if 'Upgraded' not in retval:
                    retval['Upgraded'] = list()

                temp_dict['name'] = data.name
                temp_dict['address'] = data.address
                temp_dict['mobile_number'] = data.mobile_number
                temp_dict['landline_number'] = data.landline_number
                temp_dict['email_address'] = data.email_address
                temp_dict['birthdate'] = data.birthdate
                temp_dict['date_applied'] = data.datecreated
                temp_dict['date_upgraded'] = data.upgraded

                member01list = list()
                member01res = self.__session.query(T_Member01).filter(
                    T_Member01.member00id == data.member00id).all()
                for data2 in member01res:
                    member01list.append(data2.name)

                temp_dict['submembers'] = ','.join(member01list)

                retval['Upgraded'].append(temp_dict)

            else:

                if data.membertype not in retval:
                    retval[data.membertype] = list()

                temp_dict['name'] = data.name
                temp_dict['address'] = data.address
                temp_dict['mobile_number'] = data.mobile_number
                temp_dict['landline_number'] = data.landline_number
                temp_dict['email_address'] = data.email_address
                temp_dict['birthdate'] = data.birthdate
                temp_dict['date_applied'] = data.datecreated

                if data.membertype == 'Family':
                    member01list = list()
                    member01res = self.__session.query(T_Member01).filter(
                        T_Member01.member00id == data.member00id).all()
                    for data2 in member01res:
                        member01list.append(data2.name)

                    temp_dict['submembers'] = ','.join(member01list)

                retval[data.membertype].append(temp_dict)

        return retval
Ejemplo n.º 24
0
class Summary_report(object):
    def __init__(self, **kwargs):
        self.__session = Session()
        self.__args = kwargs
        self.__retval = dict()

        # column start for insert of image
        self.__column = 0

    def get_reports_data(self):
        self.__get_attendants()
        self.__insert_dates()
        self.__get_attendants01()
        self.__get_transactions()
        self.__get_membership()
        self.__get_upgraded()

        total_dict = self.__make_total_dict(self.__retval)

        filename = self.__generate_excelfil(self.__retval, total_dict)

        return filename

    def __get_attendants(self):
        result = self.__session.query(T_Attendants).all()

        for d in result:
            self.__retval[d.attendantid] = {
                'attendant_name': d.attendant_name,
                'allowance_perday': d.allowance,
                'allowance_total': 0,
                'addons_total': 0,
                'commision_total_addons': 0,
                'services_total': 0,
                'commision_total_service': 0,
                'personalized_total': 0,
                'incentive_total_personalized': 0,
                'family_total': 0,
                'incentive_total_family': 0,
                'upgraded_total': 0,
                'incentive_total_upgraded': 0,
                'dates': dict()
            }

    def __insert_dates(self):
        dateend = datetime.datetime.strptime(self.__args['to'], '%Y-%m-%d')
        delta = datetime.timedelta(days=1)

        for attendantid in self.__retval.keys():
            datestart = datetime.datetime.strptime(self.__args['from'],
                                                   '%Y-%m-%d')

            while datestart <= dateend:
                self.__retval[attendantid]['dates'][datestart.strftime(
                    '%B-%d-%Y')] = 'AWOL'

                datestart += delta

    def __get_attendants01(self):
        search_filter = [
            getattr(T_Attendants01,
                    'trandate').between(self.__args['from'], self.__args['to'])
        ]

        result = self.__session.query(T_Attendants01).filter(
            *search_filter).order_by(T_Attendants01.attendantid.asc(),
                                     T_Attendants01.trandate.asc()).all()

        for d in result:
            if not d.timein:
                timein = 'No Time In'
            else:
                timein = d.timein

            if not d.timeout:
                timeout = 'No Time Out'
            else:
                timeout = d.timeout

            self.__retval[d.attendantid]['dates'][d.trandate.strftime(
                '%B-%d-%Y')] = timein + ' - ' + timeout

            x = self.__compute_allowance(
                d.timein, d.timeout,
                self.__retval[d.attendantid]['allowance_perday'])
            self.__retval[d.attendantid]['allowance_total'] += x

    def __compute_allowance(self, timein, timeout, allowance):

        if any([not timein, not timeout]):
            return 0

        per_hour = allowance / 12

        timein = datetime.datetime.strptime(timein, '%I:%M %p')
        timeout = datetime.datetime.strptime(timeout, '%I:%M %p')
        timediff = timeout - timein
        hours = int(timediff.seconds / 3600)
        retval = int(per_hour * hours)

        return retval

    def __get_transactions(self):
        search_filter = [
            getattr(T_Transaction,
                    'datecreated').between(self.__args['from'],
                                           self.__args['to'])
        ]

        result = self.__session.query(T_Transaction).filter(*search_filter)

        temp_dict = dict()
        for d in result:
            comms = self.__compute_commision(d.service, d.service_price,
                                             d.transaction_type,
                                             d.add_ons_price)
            self.__retval[d.attendantid]['commision_total_service'] += comms[0]
            self.__retval[d.attendantid]['commision_total_addons'] += comms[1]
            self.__retval[
                d.attendantid]['addons_total'] += self.__compute_addons(
                    d.add_ons_price)
            self.__retval[
                d.attendantid]['services_total'] += self.__compute_services(
                    d.service_price)

    def __compute_services(self, serviceprice):
        return int(serviceprice)

    def __compute_addons(self, addonsprice):
        total = 0

        if not addonsprice:
            return 0

        for price in addonsprice.split(','):
            total += int(price)

        return total

    def __compute_commision(self, service, serviceprice, trantype,
                            add_ons_price):
        ignore_list = ['5-in-1 Signature Massage', 'Relaxing Swedish Massage']
        retval = list()

        # get services commisions
        servicecomm = 0
        if service not in ignore_list:
            if serviceprice is None:
                serviceprice = 0

            servicecomm = int(serviceprice) * 0.10

        retval.append(servicecomm)

        # get addons commisions
        addonscomm = 0
        if not add_ons_price:
            addonscomm = 0
        else:
            addonsprices = add_ons_price.split(',')
            if trantype in ['Walk-In', 'Non-Member']:
                for price in addonsprices:
                    if int(price) <= 299:
                        addonscomm += 25
                    elif int(price) >= 300:
                        addonscomm += 50

            elif trantype == 'Member':
                for price in addonsprices:
                    if int(price) <= 149:
                        addonscomm += 25
                    elif int(price) >= 150:
                        addonscomm += 50

        retval.append(addonscomm)

        return retval

    def __get_membership(self):
        search_filter = [
            getattr(T_Member00, 'datecreated').between(self.__args['from'],
                                                       self.__args['to'])
        ]
        search_filter.append(getattr(T_Member00, 'attendantid') != 0)

        result = self.__session.query(T_Member00).filter(*search_filter).all()

        for d in result:
            if any([d.upgraded, d.upgraded_by]):
                self.__retval[d.attendantid][
                    'personalized_total'] += d.membershipcost / 2
                self.__retval[
                    d.attendantid]['incentive_total_personalized'] += 25
                continue

            if d.membertype == 'Personalized':
                self.__retval[
                    d.attendantid]['personalized_total'] += d.membershipcost
                self.__retval[
                    d.attendantid]['incentive_total_personalized'] += 25
            elif d.membertype == 'Family':
                self.__retval[
                    d.attendantid]['family_total'] += d.membershipcost
                self.__retval[d.attendantid]['incentive_total_family'] += 50

    def __get_upgraded(self):
        search_filter = [
            getattr(T_Member00, 'upgraded').between(self.__args['from'],
                                                    self.__args['to'])
        ]

        result = self.__session.query(T_Member00).filter(*search_filter).all()

        for d in result:
            self.__retval[
                d.upgraded_by]['upgraded_total'] += d.membershipcost / 2
            self.__retval[d.upgraded_by]['incentive_total_upgraded'] += 25

    def __make_total_dict(self, data):
        retval = {
            'total_allowance': 0,
            'total_commision': 0,
            'total_incentive': 0,
            'total_gross_sales': 0,
            'operational_expenses': 0,
            'total_net_sales': 0,
            'total_addons': 0,
            'total_services': 0,
            'total_members_p': 0,
            'total_members_f': 0,
            'total_members_u': 0
        }

        for key, value in data.items():
            retval['total_allowance'] += value.get('allowance_total', 0)
            retval['total_commision'] += sum([
                value.get('commision_total_addons', 0),
                value.get('commision_total_service', 0)
            ])
            retval['total_incentive'] += sum([
                value.get('incentive_total_personalized', 0),
                value.get('incentive_total_family', 0),
                value.get('incentive_total_upgraded', 0)
            ])
            retval['total_gross_sales'] += sum([
                value.get('addons_total', 0),
                value.get('services_total', 0),
                value.get('personalized_total', 0),
                value.get('family_total', 0),
                value.get('upgraded_total', 0)
            ])
            retval['total_addons'] += value.get('addons_total', 0)
            retval['total_services'] += value.get('services_total', 0)
            retval['total_members_p'] += value.get('personalized_total', 0)
            retval['total_members_f'] += value.get('family_total', 0)
            retval['total_members_u'] += value.get('upgraded_total', 0)

        retval['total_net_sales'] = (retval['total_gross_sales'] -
                                     retval['total_incentive'] -
                                     retval['total_commision'] -
                                     retval['total_allowance'] -
                                     retval['operational_expenses'])

        return retval

    def __generate_excelfil(self, attendantdata, totaldata):
        wb = Workbook()
        ws = wb.active

        ws.title = "Summary Report"
        ws.sheet_properties.tabColor = '1072BA'

        self.__insert_first_column(ws, attendantdata)
        self.__insert_all_data_to_excel(ws, attendantdata)
        self.__insert_totals(ws, totaldata)

        filename = datetime.datetime.now().strftime('%Y%m%d%H%M%S')

        folderpath = os.path.join(os.getcwd(), 'Reports')
        if not os.path.exists(folderpath):
            os.makedirs(folderpath)

        retval = 'Sales_report_' + filename + '.xlsx'
        wb.save(os.path.join(folderpath, retval))

        return retval

    def __insert_first_column(self, ws, data):
        # insert dates to first column
        for key, value in data.items():
            row_count = 2

            dates = list(value['dates'].keys())
            dates.sort(key=lambda x: datetime.datetime.strptime(x, '%B-%d-%Y'))

            for date in dates:
                cell = ws.cell(row=row_count, column=1)
                cell.value = date

                # set fonts
                ft = Font(bold=True)
                al = Alignment(horizontal='center', vertical='center')
                cell.font = ft
                cell.alignment = al

                # set width
                coordinate = cell.coordinate
                coor = re.split('(\d+)', coordinate)
                ws.column_dimensions[str(coor[0])].width = 25

                row_count += 1

            additionalheader = [
                'Allowance', 'Commision on Service', 'Incentive on Membership',
                'Total per Attendant'
            ]

            row_count += 1
            for header in additionalheader:
                cell = ws.cell(row=row_count, column=1)
                cell.value = header

                # set fonts
                ft = Font(bold=True)
                al = Alignment(horizontal='center', vertical='center')
                cell.font = ft
                cell.alignment = al

                row_count += 1

            break

    def __insert_all_data_to_excel(self, ws, data):

        column_count = 2
        for key, value in data.items():
            row_count = 1

            dates = list(value['dates'].keys())
            dates.sort(key=lambda x: datetime.datetime.strptime(x, '%B-%d-%Y'))
            dates.insert(0, 'attendant_name')

            for date in dates:
                cell = ws.cell(row=row_count, column=column_count)

                if date == 'attendant_name':
                    cell.value = value[date]

                    # set fonts
                    ft = Font(bold=True)
                    al = Alignment(horizontal='center', vertical='center')
                    cell.font = ft
                    cell.alignment = al

                    coordinate = cell.coordinate
                    coor = re.split('(\d+)', coordinate)
                    # set height and width of headers cell
                    ws.row_dimensions[int(coor[1])].height = 45
                    ws.column_dimensions[str(coor[0])].width = 25

                else:
                    # set font
                    al = Alignment(horizontal='center', vertical='center')
                    cell.alignment = al

                    cell.value = value['dates'][date]

                row_count += 1

            additionalheader = [
                'Allowance', 'Commision on Service', 'Incentive on Membership',
                'Total per Attendant'
            ]
            row_count += 1
            for header in additionalheader:
                cell = ws.cell(row=row_count, column=column_count)
                # set font
                al = Alignment(horizontal='center', vertical='center')
                cell.alignment = al

                if header == 'Allowance':
                    cell.value = value['allowance_total']

                elif header == 'Commision on Service':
                    val = sum([
                        value.get('commision_total_addons', 0),
                        value.get('commision_total_service', 0)
                    ])
                    cell.value = val

                elif header == 'Incentive on Membership':
                    val = sum([
                        value.get('incentive_total_personalized', 0),
                        value.get('incentive_total_family', 0),
                        value.get('incentive_total_upgraded', 0)
                    ])
                    cell.value = val

                elif header == 'Total per Attendant':
                    val = sum([
                        value['allowance_total'],
                        value.get('commision_total_addons', 0),
                        value.get('commision_total_service', 0),
                        value.get('incentive_total_personalized', 0),
                        value.get('incentive_total_family', 0),
                        value.get('incentive_total_upgraded', 0)
                    ])
                    cell.value = val

                row_count += 1

            column_count += 1

        self.__column = column_count + 1

    def __insert_totals(self, ws, totaldata):
        # insert banahaw image on start
        cell = ws.cell(row=1, column=1)
        img_path = os.path.join(os.getcwd(), 'BanahawApp', 'static', 'img',
                                'Untitled2.png')
        img = drawing.image.Image(img_path)
        ws.add_image(img, cell.coordinate)

        # insert banahaw image
        cell = ws.cell(row=1, column=self.__column)
        img_path = os.path.join(os.getcwd(), 'BanahawApp', 'static', 'img',
                                'Untitled.png')
        img = drawing.image.Image(img_path)
        ws.add_image(img, cell.coordinate)

        # insert color under the image
        cell1 = ws.cell(row=6, column=self.__column)
        cell2 = ws.cell(row=6, column=self.__column + 5)
        mergecells = '{}:{}'.format(cell1.coordinate, cell2.coordinate)
        ws.merge_cells(mergecells)
        fl = PatternFill(start_color='2E8B57',
                         end_color='2E8B57',
                         fill_type='solid')
        cell1.fill = fl

        # insert totals
        row_count = 7

        # add blank for blank in excel
        loop = list(totaldata.keys())
        loop.append('blank')
        loop.append('blank')

        for index, key in enumerate(loop):

            if index == 0:
                self.__merge_cell_insert_head(
                    ws, row_count, 'Total On New Members Personalized',
                    '993366')
                self.__merge_cell_insert_data(ws, row_count,
                                              totaldata['total_members_p'],
                                              '993366')
            elif index == 1:
                self.__merge_cell_insert_head(ws, row_count,
                                              'Total On New Members Family',
                                              '994d33')
                self.__merge_cell_insert_data(ws, row_count,
                                              totaldata['total_members_f'],
                                              '994d33')
            elif index == 2:
                self.__merge_cell_insert_head(
                    ws, row_count, 'Total On Upgraded Members to Family',
                    '996633')
                self.__merge_cell_insert_data(ws, row_count,
                                              totaldata['total_members_u'],
                                              '996633')
            elif index == 3:
                self.__merge_cell_insert_head(
                    ws, row_count, 'Total On Services/Packages/Promos',
                    '998033')
                self.__merge_cell_insert_data(ws, row_count,
                                              totaldata['total_services'],
                                              '998033')
            elif index == 4:
                self.__merge_cell_insert_head(ws, row_count,
                                              'Total On Add - Ons', '999933')
                self.__merge_cell_insert_data(ws, row_count,
                                              totaldata['total_addons'],
                                              '999933')
            elif index == 5:
                # blank
                cell1 = ws.cell(row=row_count, column=self.__column)
                cell2 = ws.cell(row=row_count, column=self.__column + 5)
                mergecells = '{}:{}'.format(cell1.coordinate, cell2.coordinate)
                ws.merge_cells(mergecells)
            elif index == 6:
                self.__merge_cell_insert_head(ws, row_count, 'Total Allowance',
                                              '339980')
                self.__merge_cell_insert_data(ws, row_count,
                                              totaldata['total_allowance'],
                                              '339980')
            elif index == 7:
                self.__merge_cell_insert_head(ws, row_count, 'Total Commision',
                                              '339999')
                self.__merge_cell_insert_data(ws, row_count,
                                              totaldata['total_commision'],
                                              '339999')
            elif index == 8:
                self.__merge_cell_insert_head(ws, row_count,
                                              'Total Incentive on Membership',
                                              '334d99')
                self.__merge_cell_insert_data(ws, row_count,
                                              totaldata['total_incentive'],
                                              '334d99')
            elif index == 9:
                self.__merge_cell_insert_head(ws, row_count,
                                              'Operational Expenses', '4d3399')
                self.__merge_cell_insert_data(
                    ws, row_count, totaldata['operational_expenses'], '4d3399')
            elif index == 10:
                # blank
                cell1 = ws.cell(row=row_count, column=self.__column)
                cell2 = ws.cell(row=row_count, column=self.__column + 5)
                mergecells = '{}:{}'.format(cell1.coordinate, cell2.coordinate)
                ws.merge_cells(mergecells)
            elif index == 11:
                self.__merge_cell_insert_head(ws, row_count,
                                              'Total Gross Sales', '99334d')
                self.__merge_cell_insert_data(ws, row_count,
                                              totaldata['total_gross_sales'],
                                              '99334d')
            elif index == 12:
                self.__merge_cell_insert_head(ws, row_count, 'Total Net Sales',
                                              '339966')
                self.__merge_cell_insert_data(ws, row_count,
                                              totaldata['total_net_sales'],
                                              '339966')

            row_count += 1

        else:
            cell1 = ws.cell(row=row_count, column=self.__column)
            cell2 = ws.cell(row=row_count, column=self.__column + 5)
            mergecells = '{}:{}'.format(cell1.coordinate, cell2.coordinate)
            ws.merge_cells(mergecells)
            fl = PatternFill(start_color='2E8B57',
                             end_color='2E8B57',
                             fill_type='solid')
            cell1.fill = fl

    def __merge_cell_insert_head(self, ws, row, value, color):
        cell1 = ws.cell(row=row, column=self.__column)
        cell2 = ws.cell(row=row, column=self.__column + 3)
        mergecells = '{}:{}'.format(cell1.coordinate, cell2.coordinate)
        ws.merge_cells(mergecells)
        ft = Font(bold=True, italic=True, color=color)
        al = Alignment(horizontal='center', vertical='center')
        cell1.font = ft
        cell1.alignment = al
        cell1.value = value

    def __merge_cell_insert_data(self, ws, row, value, color):
        cell1 = ws.cell(row=row, column=self.__column + 4)
        cell2 = ws.cell(row=row, column=self.__column + 5)
        mergecells = '{}:{}'.format(cell1.coordinate, cell2.coordinate)
        ws.merge_cells(mergecells)
        ft = Font(bold=True, italic=True, color=color)
        al = Alignment(horizontal='center', vertical='center')
        cell1.font = ft
        cell1.alignment = al
        cell1.value = value
Ejemplo n.º 25
0
 def __init__(self):
     self.__session = Session()
Ejemplo n.º 26
0
class Reservations_data(Mini_func):
    def __init__(self, **kwargs):
        self.__session = Session()
        self.__args = kwargs
        self._retval = list()
        self.__search_filter = list()
        self.__search_param = ['reservationid']
        self.__data = None

    def get_reservations(self):
        for key in self.__search_param:
            if key in self.__args and self.__args[key] not in (None, ""):
                self.__search_filter.append(
                    getattr(T_Reservation, key) == self.__args[key])

        ds = self.__args.get('from', None)
        de = self.__args.get('to', None)

        if ds and de:
            self.__search_filter.append(
                getattr(T_Reservation, 'res_date').between(ds, de))

        if self.__search_filter:
            self.__data = self.__session.query(T_Reservation).filter(
                and_(*self.__search_filter)).order_by(
                    T_Reservation.reservationid).all()

            for d in self.__data:
                r = d.toJSONExcept()
                self._retval.append(r)

        else:
            self.__data = self.__session.query(T_Reservation).order_by(
                T_Reservation.reservationid).all()

            for d in self.__data:
                r = d.toJSONExcept()
                self._retval.append(r)

    def post_reservations(self):

        reservation = T_Reservation()

        for key in self.__args:
            try:
                setattr(reservation, key, self.__args[key])
            except TypeError:
                continue

        self.__session.add(reservation)

        self.__session.commit()

    def put_reservations(self):
        pass

    def del_reservations(self):
        retval = False

        if self.__data:
            retval = True
            for data in self.__data:
                self.__session.delete(data)

        try:
            self.__session.commit()
        except:
            self.__session.rollback()

        return retval
Ejemplo n.º 27
0
class Add_Ons_data(Mini_func):
    def __init__(self, **kwargs):
        self.__session = Session()
        self.__args = kwargs
        self._retval = list()
        self.__search_filter = list()
        self.__search_param = ['add_ons_name']
        self.__data = None

    def get_add_ons_data(self):

        for key in self.__search_param:
            if key in self.__args and self.__args[key] not in (None, ""):
                self.__search_filter.append(
                    getattr(T_Add_Ons, key) == self.__args[key])

        if len(self.__search_filter) != 0:
            self.__data = self.__session.query(T_Add_Ons).filter(
                *self.__search_filter).order_by(T_Add_Ons.add_ons_id).all()

            for d in self.__data:
                r = d.toJSONExcept()
                self._retval.append(r)
        else:
            self.__data = self.__session.query(T_Add_Ons).order_by(
                T_Add_Ons.add_ons_id).all()

            for d in self.__data:
                r = d.toJSONExcept()
                self._retval.append(r)

    def edit_add_ons_data(self, **kwargs):
        update_kwargs = kwargs
        search_param = ['add_ons_id']
        search_filter = list()

        for key in search_param:
            if key in update_kwargs and update_kwargs[key] not in (None, ""):
                search_filter.append(
                    getattr(T_Add_Ons, key) == update_kwargs[key])

        if search_filter:
            result = self.__session.query(T_Add_Ons).filter(
                *search_filter).all()
        else:
            return False

        update_param = ['member_price', 'non_member_price', 'duration']

        for obj in result:
            for key in update_param:
                if key in update_kwargs and update_kwargs[key] not in (None,
                                                                       ""):
                    try:
                        setattr(obj, key, update_kwargs[key])
                    except TypeError:
                        continue

        self.__session.commit()

    def del_Add_Ons(self, **kwargs):
        addonid = kwargs.get('id', 0)

        resdata = self.__session.query(T_Add_Ons).filter(
            T_Add_Ons.add_ons_id == addonid).first()

        if resdata:
            self.__session.delete(resdata)

        try:
            self.__session.commit()
        except:
            self.__session.rollback()

    def insert_add_ons(self, **kwargs):
        addons = T_Add_Ons()

        for key, value in kwargs.items():
            try:
                setattr(addons, key, value)
            except TypeError:
                continue

        self.__session.add(addons)

        self.__session.commit()

    def __del__(self):
        if self.__session is not None:
            self.__session.close()
Ejemplo n.º 28
0
class Attendants01_data(Mini_func):
    def __init__(self, **kwargs):
        self.__session = Session()
        self.__args = kwargs
        self._retval = list()
        self.__search_filter = list()
        self.__search_param = ['attendantid']
        self.__data = None

    def get_rawtime(self):
        for key in self.__search_param:
            if key in self.__args and self.__args[key] not in (None, ''):
                self.__search_filter.append(
                    getattr(T_Attendants01, key) == self.__args[key])

        ds = self.__args.get('from', None)
        de = self.__args.get('to', None)

        if ds and de:
            self.__search_filter.append(
                getattr(T_Attendants01, 'trandate').between(ds, de))

        if self.__search_filter:

            self.__data = self.__session.query(T_Attendants01).filter(
                *self.__search_filter).order_by(
                    T_Attendants01.attendantid).all()

            for d in self.__data:
                r = d.toJSONExcept()
                self._retval.append(r)

        else:
            self.__data = self.__session.query(T_Attendants01).order_by(
                T_Attendants01.attendantid).all()

            for d in self.__data:
                r = d.toJSONExcept()
                self._retval.append(r)

    def insert_rawtime(self, **kwargs):
        attendant = T_Attendants01()

        attendantid = kwargs.get('attendantid', 0)
        trandate = kwargs.get('trandate', 0)
        print(attendantid, trandate)
        att_filter = [
            getattr(T_Attendants01, 'attendantid') == attendantid,
            getattr(T_Attendants01, 'trandate') == trandate
        ]

        if not attendantid or not trandate:
            return None

        exist = self.__session.query(T_Attendants01).filter(
            *att_filter).first()

        if not exist:

            for key in kwargs:
                if kwargs[key]:
                    try:
                        setattr(attendant, key, kwargs[key])
                    except TypeError:
                        continue

            self.__session.add(attendant)

            self.__session.commit()

        else:
            update_list = ['timein', 'timeout']

            for key in update_list:
                if key in kwargs and kwargs[key]:
                    try:
                        setattr(exist, key, kwargs[key])
                    except TypeError:
                        continue

            self.__session.commit()