reports
This commit is contained in:
@@ -4,7 +4,7 @@ from app.api.services.base_service import BaseService
|
||||
from sqlalchemy import func, desc
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from app.extensions import db
|
||||
from app.models import MembersProducts, Products, Members, ProductsDetails, ProductsDetails, ProvisionActions
|
||||
from app.models import MembersProducts, Products, Members, ProductsDetails, ProductsDetails, ProvisionActions, Payments
|
||||
|
||||
|
||||
class OfficeDashboardService(BaseService):
|
||||
@@ -15,8 +15,8 @@ class OfficeDashboardService(BaseService):
|
||||
filters = {}
|
||||
|
||||
# Extract filters
|
||||
product_id = filters.get('product_id')
|
||||
member_id = filters.get('member_id')
|
||||
option_name = filters.get('option_name')
|
||||
# member_id = filters.get('member_id')
|
||||
|
||||
# Extract pagination parameters
|
||||
page = int(filters.get('page', 1))
|
||||
@@ -28,19 +28,20 @@ class OfficeDashboardService(BaseService):
|
||||
if limit < 1 or limit > 100:
|
||||
limit = 20
|
||||
|
||||
membersSubList, total_count = MembersProducts.get_all_subscriptions(product_id, member_id, page, limit)
|
||||
membersPayList, total_count = Payments.get_all_payments(option_name, None, page, limit)
|
||||
# Convert loans to dictionary format
|
||||
member_sub_data = []
|
||||
for subs in membersSubList:
|
||||
for subs in membersPayList:
|
||||
member_sub_data.append({
|
||||
'id': subs.id,
|
||||
'member_id': subs.member_id,
|
||||
'product_id': subs.product_id,
|
||||
'internal_url': subs.internal_url,
|
||||
'external_url': subs.external_url,
|
||||
'dns_group': subs.dns_group,
|
||||
'option_name': subs.option_name,
|
||||
'option_type': subs.option_type,
|
||||
'payment_uid': subs.payment_uid,
|
||||
'amount': subs.amount*0.01,
|
||||
'status': subs.status,
|
||||
'updated': subs.updated,
|
||||
'sub_start': subs.sub_start,
|
||||
'sub_stop': subs.sub_stop,
|
||||
"added": subs.added,
|
||||
})
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ from app.models.charge import Charge
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from app.utils.logger import logger
|
||||
|
||||
class Payments(db.Model):
|
||||
__tablename__ = 'payments'
|
||||
@@ -68,6 +69,31 @@ class Payments(db.Model):
|
||||
return None
|
||||
return member_payments
|
||||
|
||||
@classmethod
|
||||
def get_all_payments(cls, option_name=None, member_id=None, page=1, limit=20):
|
||||
|
||||
query = cls.query
|
||||
logger.info(f"Get all payments back")
|
||||
|
||||
if member_id:
|
||||
query = query.filter(cls.member_id == member_id)
|
||||
|
||||
if option_name:
|
||||
query = query.filter(cls.option_name == option_name)
|
||||
|
||||
# Order by created_at descending (newest first)
|
||||
query = query.order_by(cls.added.desc())
|
||||
|
||||
# Get total count before pagination
|
||||
total_count = query.count()
|
||||
|
||||
# Apply pagination
|
||||
offset = (page - 1) * limit
|
||||
query = query.limit(limit).offset(offset)
|
||||
|
||||
return query.all(), total_count
|
||||
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"id": self.id,
|
||||
|
||||
Reference in New Issue
Block a user