office pages
This commit is contained in:
@@ -618,6 +618,24 @@ ALTER TABLE ONLY generative_results
|
|||||||
ALTER TABLE generative_results OWNER TO merms_panel;
|
ALTER TABLE generative_results OWNER TO merms_panel;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE TABLE office_users(
|
||||||
|
id SERIAL,
|
||||||
|
uid uuid DEFAULT uuid_generate_v4(),
|
||||||
|
username VARCHAR(25) UNIQUE NOT NULL,
|
||||||
|
password VARCHAR(100) NOT NULL,
|
||||||
|
firstname VARCHAR(25) NOT NULL,
|
||||||
|
lastname VARCHAR(25) NOT NULL,
|
||||||
|
acc_level INT DEFAULT 10,
|
||||||
|
status INT DEFAULT 0,
|
||||||
|
added timestamp without time zone DEFAULT now()
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE ONLY office_users
|
||||||
|
ADD CONSTRAINT office_users_id_key UNIQUE (id);
|
||||||
|
|
||||||
|
ALTER TABLE office_users OWNER TO merms_panel;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from app.api.services import (
|
|||||||
SubscriptionsService,
|
SubscriptionsService,
|
||||||
CommonDataService,
|
CommonDataService,
|
||||||
OfficeCustomerService,
|
OfficeCustomerService,
|
||||||
GenerativesService
|
GenerativesService, OfficeUsersService
|
||||||
)
|
)
|
||||||
from app.api.services.comments import CommentsService
|
from app.api.services.comments import CommentsService
|
||||||
from app.utils.logger import logger
|
from app.utils.logger import logger
|
||||||
@@ -420,7 +420,6 @@ def get_subscription_billings_office():
|
|||||||
|
|
||||||
|
|
||||||
@api.route('/office/transaction', methods=['GET'])
|
@api.route('/office/transaction', methods=['GET'])
|
||||||
# @token_required
|
|
||||||
def get_subscription_transaction_office():
|
def get_subscription_transaction_office():
|
||||||
# Call the dashboard service
|
# Call the dashboard service
|
||||||
filters = {
|
filters = {
|
||||||
@@ -432,6 +431,33 @@ def get_subscription_transaction_office():
|
|||||||
result = OfficeDashboardService.get_payments_data(filters)
|
result = OfficeDashboardService.get_payments_data(filters)
|
||||||
return jsonify(result)
|
return jsonify(result)
|
||||||
|
|
||||||
|
@api.route('/office/recent-signup', methods=['GET'])
|
||||||
|
def get_recent_signup_office():
|
||||||
|
# Call the dashboard service
|
||||||
|
filters = {}
|
||||||
|
result = OfficeDashboardService.get_payments_data(filters)
|
||||||
|
return jsonify(result)
|
||||||
|
|
||||||
|
@api.route('/office/right-sidebar', methods=['GET'])
|
||||||
|
def get_office_sidebar():
|
||||||
|
# Call the dashboard service
|
||||||
|
filters = {}
|
||||||
|
result = OfficeDashboardService.get_payments_data(filters)
|
||||||
|
return jsonify(result)
|
||||||
|
|
||||||
|
@api.route('/office/users', methods=['GET'])
|
||||||
|
def get_office_users():
|
||||||
|
# Call the dashboard service
|
||||||
|
filters = {}
|
||||||
|
result = OfficeUsersService.get_office_users(filters)
|
||||||
|
return jsonify(result)
|
||||||
|
|
||||||
|
@api.route('/office/products', methods=['GET'])
|
||||||
|
def get_product_office():
|
||||||
|
# Call the dashboard service
|
||||||
|
filters = {}
|
||||||
|
result = OfficeDashboardService.get_office_products(filters)
|
||||||
|
return jsonify(result)
|
||||||
|
|
||||||
# =====================================================
|
# =====================================================
|
||||||
@api.route('/web/contents', methods=['GET'])
|
@api.route('/web/contents', methods=['GET'])
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from app.api.services.subscriptions import SubscriptionsService
|
|||||||
from app.api.services.common_data import CommonDataService
|
from app.api.services.common_data import CommonDataService
|
||||||
from app.api.services.genaratives import GenerativesService
|
from app.api.services.genaratives import GenerativesService
|
||||||
from app.api.services.comments import CommentsService
|
from app.api.services.comments import CommentsService
|
||||||
|
from app.api.services.office_users import OfficeUsersService
|
||||||
# OFFICE
|
# OFFICE
|
||||||
from app.api.services.office_customer import OfficeCustomerService
|
from app.api.services.office_customer import OfficeCustomerService
|
||||||
from app.api.services.office_dashboard import OfficeDashboardService
|
from app.api.services.office_dashboard import OfficeDashboardService
|
||||||
|
|||||||
@@ -122,3 +122,26 @@ class OfficeDashboardService(BaseService):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"An error occurred while getting dashboard data: {str(e)}", exc_info=True)
|
logger.error(f"An error occurred while getting dashboard data: {str(e)}", exc_info=True)
|
||||||
return jsonify({"message": "Internal Server Error"}), 500
|
return jsonify({"message": "Internal Server Error"}), 500
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_office_products(filters):
|
||||||
|
products = Products.get_user_product_list(0)
|
||||||
|
product_data = []
|
||||||
|
|
||||||
|
for t in products:
|
||||||
|
product_data.append({
|
||||||
|
'id': t.id,
|
||||||
|
'uid': t.uid,
|
||||||
|
'product_id': t.product_id,
|
||||||
|
'description': t.description,
|
||||||
|
'name': t.name,
|
||||||
|
'status': t.status,
|
||||||
|
'added': t.added.isoformat() if t.added else None,
|
||||||
|
'updated': t.updated.isoformat() if t.updated else None,
|
||||||
|
'banner': t.banner,
|
||||||
|
})
|
||||||
|
products_result = {
|
||||||
|
"products": product_data,
|
||||||
|
}
|
||||||
|
|
||||||
|
return products_result
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
from flask import jsonify
|
||||||
|
from app.utils.logger import logger
|
||||||
|
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, Payments, \
|
||||||
|
OfficeUsers
|
||||||
|
|
||||||
|
|
||||||
|
class OfficeUsersService(BaseService):
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_office_users(filters):
|
||||||
|
office_users = OfficeUsers.get_office_users_list()
|
||||||
|
office_users_data = []
|
||||||
|
if office_users:
|
||||||
|
for t in office_users:
|
||||||
|
office_users_data.append({
|
||||||
|
'id': t.id,
|
||||||
|
'uid': t.uid,
|
||||||
|
'product_id': t.product_id,
|
||||||
|
'description': t.description,
|
||||||
|
'name': t.name,
|
||||||
|
'status': t.status,
|
||||||
|
'added': t.added.isoformat() if t.added else None,
|
||||||
|
'updated': t.updated.isoformat() if t.updated else None,
|
||||||
|
'banner': t.banner,
|
||||||
|
})
|
||||||
|
|
||||||
|
office_users_result = {
|
||||||
|
"office_users": office_users_data,
|
||||||
|
}
|
||||||
|
|
||||||
|
return office_users_result
|
||||||
@@ -9,7 +9,7 @@ from .provision_actions import ProvisionActions
|
|||||||
from .password_reset import PasswordReset
|
from .password_reset import PasswordReset
|
||||||
from .member_product_refresh import MembersProductsRefresh
|
from .member_product_refresh import MembersProductsRefresh
|
||||||
from .members_products_settings import MembersProductsSettings
|
from .members_products_settings import MembersProductsSettings
|
||||||
from .members_profile import MembersProfile
|
from .members_profile import MembersProfile
|
||||||
from .subscription_options import SubscriptionOptions
|
from .subscription_options import SubscriptionOptions
|
||||||
from .subscription_options_items import SubscriptionOptionsItems
|
from .subscription_options_items import SubscriptionOptionsItems
|
||||||
from .products_templates import ProductsTemplates
|
from .products_templates import ProductsTemplates
|
||||||
@@ -17,11 +17,11 @@ from .payments_session import PaymentsSession
|
|||||||
from .payments import Payments
|
from .payments import Payments
|
||||||
from .subscription_generative import SubscriptionGenerative
|
from .subscription_generative import SubscriptionGenerative
|
||||||
from .generative_results import GenerativeResults
|
from .generative_results import GenerativeResults
|
||||||
|
from .office_users import OfficeUsers
|
||||||
|
|
||||||
__all__ = ['Members', 'Account', 'Products',
|
__all__ = ['Members', 'Account', 'Products',
|
||||||
'MembersProducts', 'MembersActions', 'MembersPending', 'ProductsDetails',
|
'MembersProducts', 'MembersActions', 'MembersPending', 'ProductsDetails',
|
||||||
'ProvisionActions', 'MembersProductsRefresh','MembersProductsSettings',
|
'ProvisionActions', 'MembersProductsRefresh', 'MembersProductsSettings',
|
||||||
'PasswordReset','MembersProfile','SubscriptionOptions','SubscriptionOptionsItems',
|
'PasswordReset', 'MembersProfile', 'SubscriptionOptions', 'SubscriptionOptionsItems',
|
||||||
'ProductsTemplates','Payments','PaymentsSession','SubscriptionGenerative','GenerativeResults']
|
'ProductsTemplates', 'Payments', 'PaymentsSession', 'SubscriptionGenerative', 'GenerativeResults',
|
||||||
|
'OfficeUsers']
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
from datetime import datetime, timezone, timedelta
|
||||||
|
from itertools import product
|
||||||
|
from app.extensions import db
|
||||||
|
from app.models.customer import Customer
|
||||||
|
from app.models.account import Account
|
||||||
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
from dateutil.relativedelta import relativedelta
|
||||||
|
from datetime import timedelta
|
||||||
|
import logging
|
||||||
|
from sqlalchemy import and_, or_, not_
|
||||||
|
from sqlalchemy.sql import func
|
||||||
|
import json
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class OfficeUsers(db.Model):
|
||||||
|
__tablename__ = 'office_users'
|
||||||
|
|
||||||
|
id = db.Column(
|
||||||
|
db.Integer,
|
||||||
|
primary_key=True,
|
||||||
|
autoincrement=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
uid = db.Column(db.String(150), nullable=True)
|
||||||
|
username = db.Column(db.String(25), nullable=False)
|
||||||
|
password = db.Column(db.String(100), nullable=False)
|
||||||
|
firstname = db.Column(db.String(25), nullable=False)
|
||||||
|
lastname = db.Column(db.String(25), nullable=False)
|
||||||
|
acc_level = db.Column(db.Integer, nullable=True, default=10)
|
||||||
|
status = db.Column(db.Integer, nullable=True, default=0)
|
||||||
|
added = db.Column(db.DateTime(timezone=True), server_default=func.now())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_office_users_list(cls):
|
||||||
|
"""
|
||||||
|
Return all offers in dictionary format.
|
||||||
|
"""
|
||||||
|
users_list = cls.query.all()
|
||||||
|
|
||||||
|
if not users_list:
|
||||||
|
raise ValueError(f"No available users")
|
||||||
|
return users_list
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_office_user_id(cls, user_id):
|
||||||
|
"""
|
||||||
|
Get customer's active loans by loan_id.
|
||||||
|
"""
|
||||||
|
users_list = cls.query.filter_by(id=user_id).first()
|
||||||
|
if not users_list:
|
||||||
|
# raise ValueError(f"pProduct with ID {product_id} does not exist.")
|
||||||
|
logger.error(f"users_list with ID {user_id} does not exist.")
|
||||||
|
return None
|
||||||
|
return users_list
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
"""
|
||||||
|
Convert the Loan object to a dictionary format for JSON serialization.
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
'id': self.id,
|
||||||
|
'uid': self.uid,
|
||||||
|
'username': self.username,
|
||||||
|
'password': self.password,
|
||||||
|
'firstname': self.firstname,
|
||||||
|
'lastname': self.lastname,
|
||||||
|
'acc_level': self.acc_level,
|
||||||
|
'status': self.status,
|
||||||
|
'added': self.added
|
||||||
|
}
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f'<Products {self.id}>'
|
||||||
Reference in New Issue
Block a user