HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall/buyercall/blueprints/admin/__pycache__/models.cpython-310.pyc
o

�we��@slddlmZmZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZGdd	�d	e�Zd
S)�)�and_�func)�text)�db)�User)�Issue)�Subscription)�PartnershipAccountc@sTeZdZedd��Zedd��Zedd��Zedd��Zed	d
��Zedd��Z	d
S)�	DashboardcCsdtj�t��tj�d����}tj�t�tj	���
�}|dkr"d}nt|t|�dd�}|||fS)z`
        Obtain coupon usage statistics across all subscribers.

        :return: tuple
        Nr�d�)
r�session�queryr�filter�coupon�isnot�countr�id�scalar�round�float)�cls�not_null�total�percent�r�C/home/arjun/projects/buyercall/buyercall/blueprints/admin/models.py�group_and_count_couponss
��
z!Dashboard.group_and_count_couponscCsz|jdkr+tj�tj��tj|jktjdk���}t	tj�
|�tjtjktj
dk�}n
|jdvr5tj
dk}t�ttj|�S)zZ
        Perform a group by/count on all subscriber types.

        :return: dict
        �partnerT�active)�sysadmin�
limitsysadmin)�roler	r�
with_entitiesrr�partnership_idr�allr�in_�subscription_idr�statusr
�group_and_count�plan)r�current_user�ids�
filter_exprrr�group_and_count_planss
��
�

zDashboard.group_and_count_planscCst�ttj�S)zT
        Perform a group by/count on all user types.

        :return: dict
        )r
�_group_and_countrr")rrrr�group_and_count_users2szDashboard.group_and_count_userscCsdtd�}|jdkrtj|jk}|jdkr*|jr"|j}ttj|k�}nttj|jk�}t�	ttj
|�S)zU
        Perform a group by/count on all issue types.

        :return: dict
        z1 = 1r�admin)rr"rr$�is_viewing_partnership�'get_user_viewing_partnership_account_idr�partnership_account_idr
r)r()rr+r-r4rrr�group_and_count_issues;s

z Dashboard.group_and_count_issuescCs6t�|�}tj�||��|���}||j��d�}|S)z�
        Group results for a specific model and field.

        :param model: Name of the model
        :type model: SQLAlchemy model
        :param field: Name of the field to group on
        :type field: SQLAlchemy field
        :return: dict
        �rr)rrrr
r�group_byr%)r�model�fieldrr�resultsrrrr/Qs
�zDashboard._group_and_countcCsBt�|�}tj�||��|��|���}||j�|���d�}|S)a]
        Group results for a specific model and field.

        :param model: Name of the model
        :type model: SQLAlchemy model
        :param field: Name of the field to group on
        :type field: SQLAlchemy field
        :param filter_exp: SQLAlchemy filter expression
        :type field: SQLAlchemy filter
        :return: dict
        r6)rrrr
rrr7r%)rr8r9r-rrr:rrrr)fs

�zDashboard.group_and_countN)
�__name__�
__module__�__qualname__�classmethodrr.r0r5r/r)rrrrr

s




r
N)�
sqlalchemyrr�sqlalchemy.sqlr�buyercall.extensionsr� buyercall.blueprints.user.modelsr�!buyercall.blueprints.issue.modelsr�0buyercall.blueprints.billing.models.subscriptionr�'buyercall.blueprints.partnership.modelsr	�objectr
rrrr�<module>s