feat:opt in management
This commit is contained in:
parent
654cd3979c
commit
036aa8136f
|
@ -0,0 +1,7 @@
|
|||
import frappe
|
||||
from optmanagement.remote_db import get_remote_data
|
||||
|
||||
@frappe.whitelist()
|
||||
def fetch_data():
|
||||
data = get_remote_data()
|
||||
return data
|
|
@ -4,6 +4,8 @@ app_publisher = "snehalatha"
|
|||
app_description = "Opt In Management"
|
||||
app_email = "snehalathad@aissel.com"
|
||||
app_license = "mit"
|
||||
|
||||
|
||||
# required_apps = []
|
||||
|
||||
# Includes in <head>
|
||||
|
@ -13,22 +15,31 @@ app_license = "mit"
|
|||
# app_include_css = "/assets/optmanagement/css/optmanagement.css"
|
||||
# app_include_js = "/assets/optmanagement/js/optmanagement.js"
|
||||
|
||||
|
||||
app_include_css = [
|
||||
"https://unpkg.com/tabulator-tables@5.4.3/dist/css/tabulator.min.css"
|
||||
]
|
||||
|
||||
app_include_js = [
|
||||
"https://unpkg.com/tabulator-tables@5.4.3/dist/js/tabulator.min.js"
|
||||
]
|
||||
# include js, css files in header of web template
|
||||
# web_include_css = "/assets/optmanagement/css/optmanagement.css"
|
||||
# web_include_js = "/assets/optmanagement/js/optmanagement.js"
|
||||
|
||||
# include custom scss in every website theme (without file extension ".scss")
|
||||
# website_theme_scss = "optmanagement/public/scss/website"
|
||||
# website_theme_scss = "optmanagement/public/css/tabulator.min"
|
||||
|
||||
# include js, css files in header of web form
|
||||
# webform_include_js = {"doctype": "public/js/doctype.js"}
|
||||
# webform_include_css = {"doctype": "public/css/doctype.css"}
|
||||
# webform_include_css = {"doctype": "public/css/tabulator.min.css"}
|
||||
|
||||
# include js in page
|
||||
# page_js = {"page" : "public/js/file.js"}
|
||||
page_js = {"page" : "public/js/tabulator.min.js"}
|
||||
# page_css = {"page" : "public/css/tabulator.min.css"}
|
||||
|
||||
# include js in doctype views
|
||||
# doctype_js = {"doctype" : "public/js/doctype.js"}
|
||||
#doctype_js = {"doctype" : "public/js/optlist.js"}
|
||||
# doctype_list_js = {"doctype" : "public/js/doctype_list.js"}
|
||||
# doctype_tree_js = {"doctype" : "public/js/doctype_tree.js"}
|
||||
# doctype_calendar_js = {"doctype" : "public/js/doctype_calendar.js"}
|
||||
|
@ -227,3 +238,9 @@ app_license = "mit"
|
|||
# "Logging DocType Name": 30 # days to retain logs
|
||||
# }
|
||||
|
||||
# website_route_rules = [
|
||||
# {"from_route": "/optmanagement/www/custompage", "to_route": "custompage"}
|
||||
# ]
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
import mysql.connector
|
||||
from mysql.connector import Error
|
||||
|
||||
# Define the database connection details
|
||||
db_configs = [
|
||||
{
|
||||
'user': 'snehalatha',
|
||||
'password': 'paSsWord@#654',
|
||||
'host': '35.153.190.180',
|
||||
'database': 'kolm_lite_cardio_staging'
|
||||
},
|
||||
{
|
||||
'user': 'snehalatha',
|
||||
'password': 'paSsWord@#654',
|
||||
'host': '35.153.190.180',
|
||||
'database': 'kolm_lite_veterinary_staging'
|
||||
},
|
||||
{
|
||||
'user': 'snehalatha',
|
||||
'password': 'paSsWord@#654',
|
||||
'host': '35.153.190.180',
|
||||
'database': 'kolm_lite_oralhealth_staging'
|
||||
}
|
||||
]
|
||||
|
||||
def fetch_records(config):
|
||||
try:
|
||||
# Connect to the database
|
||||
connection = mysql.connector.connect(
|
||||
host=config['host'],
|
||||
user=config['user'],
|
||||
password=config['password'],
|
||||
database=config['database']
|
||||
)
|
||||
if connection.is_connected():
|
||||
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
cursor.execute("SELECT kols.id,CONCAT_WS(' ',kols.first_name,kols.middle_name,kols.last_name) as kol_name, GROUP_CONCAT(DISTINCT projects.name) as project_name, clients.name as client_name,CONCAT(client_users.first_name,client_users.last_name) as user_name, GROUP_CONCAT(DISTINCT log_activities.transaction_name,':',date(log_activities.created_on)) as project_details FROM kols left join user_kols on user_kols.kol_id = kols.id inner join opt_inout_statuses on opt_inout_statuses.id = user_kols.opt_in_out_status left join log_activities on log_activities.miscellaneous1 = user_kols.kol_id left join client_users on client_users.id = user_kols.user_id left join clients on client_users.client_id = clients.id left join project_kols on project_kols.kol_id = user_kols.kol_id left join projects on projects.id = project_kols.project_id where log_activities.module ='opt_in_out' and log_activities.transaction_name in ('New','Opt-in Requested','Opt-out','Opt-in Approved','Opt-in Expired','Opt-in Received','Opt-in') group by kols.id;")
|
||||
records = cursor.fetchall()
|
||||
return records
|
||||
|
||||
except Error as e:
|
||||
print(f"Error while connecting to MySQL: {e}")
|
||||
return None
|
||||
|
||||
finally:
|
||||
if connection.is_connected():
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
# Loop through the databases and fetch records
|
||||
|
||||
def get_records():
|
||||
all_records = []
|
||||
for config in db_configs:
|
||||
records = fetch_records(config)
|
||||
if records:
|
||||
all_records.extend(records)
|
||||
|
||||
return all_records
|
||||
|
||||
# Print or process the fetched records
|
||||
# for record in all_records:
|
||||
# print(record)
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
import mysql.connector
|
||||
from frappe import _
|
||||
|
||||
def config():
|
||||
configdata = {
|
||||
'user': 'snehalatha',
|
||||
'password': 'paSsWord@#654',
|
||||
'host': '35.153.190.180',
|
||||
'database': 'kolm_lite_cardio_staging'
|
||||
}
|
||||
return configdata
|
||||
|
||||
|
||||
def get_remote_kol_data():
|
||||
# Database connection details
|
||||
|
||||
|
||||
try:
|
||||
# Establish the connection
|
||||
connection = mysql.connector.connect(**config())
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
# Execute the query
|
||||
query = "SELECT kols.id,CONCAT_WS(' ',kols.first_name,kols.middle_name,kols.last_name) as kol_name, GROUP_CONCAT(DISTINCT projects.name) as project_name, clients.name as client_name,CONCAT(client_users.first_name,client_users.last_name) as user_name, GROUP_CONCAT(DISTINCT log_activities.transaction_name,':',date(log_activities.created_on)) as project_details FROM kols left join user_kols on user_kols.kol_id = kols.id inner join opt_inout_statuses on opt_inout_statuses.id = user_kols.opt_in_out_status left join log_activities on log_activities.miscellaneous1 = user_kols.kol_id left join client_users on client_users.id = user_kols.user_id left join clients on client_users.client_id = clients.id left join project_kols on project_kols.kol_id = user_kols.kol_id left join projects on projects.id = project_kols.project_id where log_activities.module ='opt_in_out' and log_activities.transaction_name in ('New','Opt-in Requested','Opt-out','Opt-in Approved','Opt-in Expired','Opt-in Received','Opt-in') group by kols.id;"
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
# Fetch all rows
|
||||
rows = cursor.fetchall()
|
||||
|
||||
return rows
|
||||
|
||||
except mysql.connector.Error as err:
|
||||
frappe.throw(_("Error: {0}".format(err)))
|
||||
|
||||
finally:
|
||||
# Close the cursor and connection
|
||||
cursor.close()
|
||||
connection.close()
|
|
@ -0,0 +1,9 @@
|
|||
// Copyright (c) 2024, snehalatha and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on("clientlist", {
|
||||
refresh(frm) {
|
||||
|
||||
|
||||
},
|
||||
});
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"actions": [],
|
||||
"allow_rename": 1,
|
||||
"autoname": "prompt",
|
||||
"creation": "2024-05-29 17:12:18.286641",
|
||||
"doctype": "DocType",
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"client"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "client",
|
||||
"fieldtype": "Data",
|
||||
"is_virtual": 1,
|
||||
"label": "Client"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_virtual": 1,
|
||||
"links": [],
|
||||
"modified": "2024-05-31 18:01:07.034531",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Opt In Management",
|
||||
"name": "clientlist",
|
||||
"naming_rule": "Set by user",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"show_title_field_in_link": 1,
|
||||
"sort_field": "creation",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"title_field": "client"
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
# Copyright (c) 2024, snehalatha and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from optmanagement.remote_db import get_remote_data
|
||||
|
||||
|
||||
class clientlist(Document):
|
||||
|
||||
def db_insert(self, *args, **kwargs):
|
||||
raise NotImplementedError
|
||||
|
||||
def load_from_db(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def db_update(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def delete(self):
|
||||
raise NotImplementedError
|
||||
|
||||
@staticmethod
|
||||
def get_list(args):
|
||||
filters = args.get('filters', {})
|
||||
fields = args.get('fields', ['*'])
|
||||
order_by = args.get('order_by', 'creation desc')
|
||||
limit_start = args.get('limit_start', 0)
|
||||
limit_page_length = args.get('limit_page_length', 5)
|
||||
|
||||
data = [
|
||||
{'client': 'record1'},
|
||||
{'client': 'record2'},
|
||||
{'client': 'record3'},
|
||||
]
|
||||
|
||||
if filters:
|
||||
data = [record for record in data if all(record[k] == v for k, v in filters.items())]
|
||||
|
||||
|
||||
# data = data[limit_start:limit_start + limit_page_length]
|
||||
|
||||
return data
|
||||
|
||||
# @staticmethod
|
||||
# def get_list(filters=None, page_length=20, **kwargs):
|
||||
# clients = get_remote_data()
|
||||
# clientlist = []
|
||||
# if kwargs.get("as_list"):
|
||||
# return [(rec["name"]) for rec in clients]
|
||||
# clientlist = [
|
||||
# frappe._dict({
|
||||
# "client" : "Aissel",
|
||||
# "_id" : "1"
|
||||
# }),
|
||||
# frappe._dict({
|
||||
# "client" : "Aissel2",
|
||||
# "_id" : "264654"
|
||||
# }),
|
||||
# frappe._dict({
|
||||
# "client" : "Aissel3",
|
||||
# "_id" : "45633456"
|
||||
# })]
|
||||
# return clientlist
|
||||
|
||||
|
||||
# print(f"args########{kwargs}")
|
||||
# print(f"rec########{clients}")
|
||||
# if kwargs.get("as_list"):
|
||||
# return [(rec["name"]) for rec in clients]
|
||||
|
||||
# for client in clients :
|
||||
# clientlist.append({
|
||||
# "client" : str(client["name"]),
|
||||
# "_id" : str(client["id"])
|
||||
# })
|
||||
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_count(filters=None, **kwargs):
|
||||
return 3
|
||||
|
||||
@staticmethod
|
||||
def get_stats(**kwargs):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
|
||||
|
||||
|
||||
frappe.listview_settings['clientlist'] = {
|
||||
// add fields to fetch
|
||||
// add_fields: ['title', 'public'],
|
||||
// // set default filters
|
||||
// filters: [
|
||||
// ['public', '=', 1]
|
||||
// ],
|
||||
// hide_name_column: true, // hide the last column which shows the `name`
|
||||
// hide_name_filter: true, // hide the default filter field for the name column
|
||||
onload(listview) {
|
||||
// triggers once before the list is loaded
|
||||
},
|
||||
before_render() {
|
||||
// triggers before every render of list records
|
||||
//clients = get_remote_data()
|
||||
},
|
||||
|
||||
// set this to true to apply indicator function on draft documents too
|
||||
has_indicator_for_draft: false,
|
||||
|
||||
// get_indicator(doc) {
|
||||
// // customize indicator color
|
||||
// if (doc.public) {
|
||||
// return [__("Public"), "green", "public,=,Yes"];
|
||||
// } else {
|
||||
// return [__("Private"), "darkgrey", "public,=,No"];
|
||||
// }
|
||||
// },
|
||||
// primary_action() {
|
||||
// // triggers when the primary action is clicked
|
||||
// },
|
||||
// get_form_link(doc) {
|
||||
// // override the form route for this doc
|
||||
// },
|
||||
// add a custom button for each row
|
||||
button: {
|
||||
show(doc) {
|
||||
return doc.reference_name;
|
||||
},
|
||||
get_label() {
|
||||
return 'Views';
|
||||
},
|
||||
get_description(doc) {
|
||||
return __('View {0}', [`${doc.reference_type} ${doc.reference_name}`])
|
||||
},
|
||||
action(doc) {
|
||||
frappe.set_route('Form', doc.reference_type, doc.reference_name);
|
||||
}
|
||||
},
|
||||
// format how a field value is shown
|
||||
formatters: {
|
||||
title(val) {
|
||||
return val.bold();
|
||||
},
|
||||
public(val) {
|
||||
return val ? 'Yes' : 'No';
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
# Copyright (c) 2024, snehalatha and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
|
||||
|
||||
class Testclientlist(FrappeTestCase):
|
||||
pass
|
|
@ -0,0 +1,8 @@
|
|||
// Copyright (c) 2024, snehalatha and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
// frappe.ui.form.on("clients", {
|
||||
// refresh(frm) {
|
||||
|
||||
// },
|
||||
// });
|
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
"actions": [],
|
||||
"allow_rename": 1,
|
||||
"autoname": "prompt",
|
||||
"creation": "2024-05-30 17:27:35.555431",
|
||||
"doctype": "DocType",
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"client_name"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "client_name",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Client Name"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_virtual": 1,
|
||||
"links": [],
|
||||
"modified": "2024-05-31 18:13:48.098498",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Opt In Management",
|
||||
"name": "clients",
|
||||
"naming_rule": "Set by user",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "creation",
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
# Copyright (c) 2024, snehalatha and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from optmanagement.remote_db import get_remote_data
|
||||
|
||||
class clients(Document):
|
||||
|
||||
|
||||
|
||||
|
||||
def db_insert(self, *args, **kwargs):
|
||||
raise NotImplementedError
|
||||
|
||||
def load_from_db(self):
|
||||
clients = get_remote_data()
|
||||
clientlist = []
|
||||
|
||||
|
||||
for client in clients :
|
||||
clientlist.append({
|
||||
**client,
|
||||
"client_name" : str(client["name"]),
|
||||
"_id" : str(client["id"])
|
||||
})
|
||||
|
||||
for client in clientlist :
|
||||
if client["client_name"] == self.name :
|
||||
d = client
|
||||
# d = clientlist[0]
|
||||
|
||||
super(Document, self).__init__(d)
|
||||
|
||||
def db_update(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def delete(self):
|
||||
raise NotImplementedError
|
||||
|
||||
@staticmethod
|
||||
def get_list(filters=None, page_length=20, **kwargs):
|
||||
clients = get_remote_data()
|
||||
clientlist = []
|
||||
|
||||
|
||||
for client in clients :
|
||||
clientlist.append({
|
||||
**client,
|
||||
"client_name" : str(client["name"]),
|
||||
"_id" : str(client["id"])
|
||||
})
|
||||
return clientlist
|
||||
|
||||
@staticmethod
|
||||
def get_count(filters=None, **kwargs):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def get_stats(**kwargs):
|
||||
pass
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
# Copyright (c) 2024, snehalatha and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
|
||||
|
||||
class Testclients(FrappeTestCase):
|
||||
pass
|
|
@ -0,0 +1,57 @@
|
|||
// // Copyright (c) 2024, snehalatha and contributors
|
||||
// // For license information, please see license.txt
|
||||
|
||||
// frappe.ui.form.on("optlist", {
|
||||
// refresh(frm) {
|
||||
// frm.page_length = 20;
|
||||
// frm.start = 0;
|
||||
// load_data(frm);
|
||||
// },
|
||||
// on_next_page: function(frm) {
|
||||
// frm.start += frm.page_length;
|
||||
// load_data(frm);
|
||||
// },
|
||||
// on_previous_page: function(frm) {
|
||||
// frm.start -= frm.page_length;
|
||||
// load_data(frm);
|
||||
// }
|
||||
|
||||
// });
|
||||
|
||||
// function load_data(frm) {
|
||||
// frappe.call({
|
||||
// method: "optmanagement.opt_in_management.doctype.optlist.optlist.get_paginated_data",
|
||||
// args: {
|
||||
// start: frm.start,
|
||||
// page_length: frm.page_length
|
||||
// },
|
||||
// callback: function(r) {
|
||||
// if (r.message) {
|
||||
// const { data, total_records } = r.message;
|
||||
// // Render data in the form
|
||||
// frm.doc.data = data;
|
||||
// frm.total_records = total_records;
|
||||
// frm.refresh_field('data');
|
||||
// print("####")
|
||||
// update_pagination_buttons(frm);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// function update_pagination_buttons(frm) {
|
||||
// frm.dashboard.clear_headline();
|
||||
// frm.dashboard.set_headline(
|
||||
// `Showing ${frm.start + 1} to ${Math.min(frm.start + frm.page_length, frm.total_records)} of ${frm.total_records}`
|
||||
// );
|
||||
// if (frm.start > 0) {
|
||||
// frm.page.add_action_icon('fa fa-chevron-left', function() {
|
||||
// frm.trigger('on_previous_page');
|
||||
// });
|
||||
// }
|
||||
// if (frm.start + frm.page_length < frm.total_records) {
|
||||
// frm.page.add_action_icon('fa fa-chevron-right', function() {
|
||||
// frm.trigger('on_next_page');
|
||||
// });
|
||||
// }
|
||||
// }
|
|
@ -0,0 +1,152 @@
|
|||
{
|
||||
"actions": [],
|
||||
"allow_guest_to_view": 1,
|
||||
"allow_rename": 1,
|
||||
"autoname": "field:kol_id",
|
||||
"creation": "2024-06-04 11:35:32.137448",
|
||||
"doctype": "DocType",
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"opt_in_details_section",
|
||||
"kol_id",
|
||||
"kol_name",
|
||||
"project_name",
|
||||
"client_name",
|
||||
"column_break_wrvr",
|
||||
"client_poc",
|
||||
"cs_assigned_poc",
|
||||
"status",
|
||||
"optin_received_date",
|
||||
"column_break_tmrt",
|
||||
"optin_approved_date",
|
||||
"optin_type",
|
||||
"data_processed_date",
|
||||
"project_details",
|
||||
"frappe_settings_section",
|
||||
"is_published",
|
||||
"route"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "kol_id",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "KOL ID",
|
||||
"unique": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "kol_name",
|
||||
"fieldtype": "Data",
|
||||
"label": "KOL Name"
|
||||
},
|
||||
{
|
||||
"fieldname": "project_name",
|
||||
"fieldtype": "Data",
|
||||
"label": "Project Name"
|
||||
},
|
||||
{
|
||||
"fieldname": "client_name",
|
||||
"fieldtype": "Data",
|
||||
"label": "Client Name"
|
||||
},
|
||||
{
|
||||
"fieldname": "client_poc",
|
||||
"fieldtype": "Data",
|
||||
"label": "Client POC"
|
||||
},
|
||||
{
|
||||
"fieldname": "cs_assigned_poc",
|
||||
"fieldtype": "Data",
|
||||
"label": "CS Assigned POC"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_wrvr",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "is_published",
|
||||
"fieldtype": "Check",
|
||||
"label": "is published"
|
||||
},
|
||||
{
|
||||
"fieldname": "route",
|
||||
"fieldtype": "Data",
|
||||
"label": "route"
|
||||
},
|
||||
{
|
||||
"fieldname": "opt_in_details_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "OPT IN DETAILS"
|
||||
},
|
||||
{
|
||||
"fieldname": "status",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "status"
|
||||
},
|
||||
{
|
||||
"fieldname": "optin_received_date",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"in_preview": 1,
|
||||
"label": "OptIn Received Date"
|
||||
},
|
||||
{
|
||||
"fieldname": "optin_approved_date",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "OptIn Approved Date"
|
||||
},
|
||||
{
|
||||
"fieldname": "optin_type",
|
||||
"fieldtype": "Data",
|
||||
"label": "OptIn Type"
|
||||
},
|
||||
{
|
||||
"fieldname": "data_processed_date",
|
||||
"fieldtype": "Data",
|
||||
"label": "Data processed date"
|
||||
},
|
||||
{
|
||||
"fieldname": "frappe_settings_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Frappe Settings"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_tmrt",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "project_details",
|
||||
"fieldtype": "Data",
|
||||
"label": "Project Details"
|
||||
}
|
||||
],
|
||||
"is_published_field": "is_published",
|
||||
"is_virtual": 1,
|
||||
"links": [],
|
||||
"modified": "2024-06-06 17:16:32.614427",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Opt In Management",
|
||||
"name": "optlist",
|
||||
"naming_rule": "By fieldname",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "creation",
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
# Copyright (c) 2024, snehalatha and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
from optmanagement.kol_databases import get_records
|
||||
|
||||
class optlist(Document):
|
||||
|
||||
def db_insert(self, *args, **kwargs):
|
||||
raise NotImplementedError
|
||||
|
||||
def load_from_db(self):
|
||||
clients_array = get_records()
|
||||
clientlist = []
|
||||
|
||||
|
||||
for client in clients_array :
|
||||
clientlist.append(
|
||||
{
|
||||
"name": client["id"],
|
||||
"kol_id" : str(client["id"]),
|
||||
"kol_name" : str(client["kol_name"]),
|
||||
"project_name" : str(client["project_name"]),
|
||||
"client_name" : str(client["client_name"]),
|
||||
"client_poc" : str(client["user_name"]),
|
||||
"project_details" : str(client["project_details"]),
|
||||
"optin_received_date" : optinReceived(str(client["project_details"]),"Opt-in Received"),
|
||||
"optin_approved_date" : optinReceived(str(client["project_details"]),"Opt-in Approved"),
|
||||
"status" : optinStatus(str(client["project_details"])),
|
||||
}
|
||||
)
|
||||
|
||||
print(f"$$name: {self.name}")
|
||||
|
||||
for client in clientlist :
|
||||
if client["kol_id"] == self.name :
|
||||
d = client
|
||||
|
||||
super(Document, self).__init__(d)
|
||||
|
||||
def db_update(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def delete(self):
|
||||
raise NotImplementedError
|
||||
|
||||
@staticmethod
|
||||
def get_list(filters=None, page_length=20, **kwargs):
|
||||
clientlist = []
|
||||
clientlist = getValues()
|
||||
page_length = 20
|
||||
|
||||
# for client in clients_array :
|
||||
# clientlist.append({
|
||||
# **client,
|
||||
# # "_id": str(client["id"]),
|
||||
# # "kol_id" : str(client["id"]),
|
||||
# # "kol_name" : str(client["kol_name"]),
|
||||
# # "client_poc" : str(client["client_name"]),
|
||||
# # "project_name" : str(client["project_details"]),
|
||||
# # "cs_assigned_poc" : str(client["user_name"]),
|
||||
# })
|
||||
|
||||
# {'id': 457002, 'kol_name': 'Ferdinand Douglas', 'project_name': None, 'client_name': 'Abbott EMEA', 'user_name': 'Abbott EMEAGeneric', 'project_details': 'New-2024-04-18,Opt-in Requested-2024-04-18'}
|
||||
# print(f"################################check person {clientlist}")
|
||||
return clientlist
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_count(filters=None, **kwargs):
|
||||
clientlist = []
|
||||
clientlist = getValues()
|
||||
return len(clientlist)
|
||||
|
||||
@staticmethod
|
||||
def get_stats(**kwargs):
|
||||
pass
|
||||
|
||||
|
||||
# def get_virtual_data(start=0, page_length=20):
|
||||
# data = [{"name": f"Doc {i+1}", "value": i+1}
|
||||
# for i in range(start, start + page_length)]
|
||||
|
||||
# total_records = 1000
|
||||
# return data, total_records
|
||||
|
||||
|
||||
|
||||
# def get_paginated_data(start=0, page_length=20):
|
||||
# start = int(start)
|
||||
# page_length = int(page_length)
|
||||
|
||||
# data, total_records = get_virtual_data(start, page_length)
|
||||
|
||||
# return {
|
||||
# "data": data,
|
||||
# "total_records": total_records,
|
||||
# }
|
||||
|
||||
def getValues():
|
||||
records = get_records()
|
||||
# print(f"rec########{records}")
|
||||
|
||||
return[
|
||||
{
|
||||
"name": client["id"],
|
||||
"kol_id" : str(client["id"]),
|
||||
"kol_name" : str(client["kol_name"]),
|
||||
"project_name" : str(client["project_name"]),
|
||||
"client_name" : str(client["client_name"]),
|
||||
"client_poc" : str(client["user_name"]),
|
||||
"project_details" : str(client["project_details"]),
|
||||
"optin_received_date" : optinReceived(str(client["project_details"]),"Opt-in Received"),
|
||||
"optin_approved_date" : optinReceived(str(client["project_details"]),"Opt-in Approved"),
|
||||
"status" : optinStatus(str(client["project_details"])),
|
||||
}
|
||||
for client in records
|
||||
]
|
||||
|
||||
|
||||
def optinReceived(str,key):
|
||||
if not str:
|
||||
return str("")
|
||||
else:
|
||||
dictionary = dict(subString.split(":") for subString in str.split(","))
|
||||
if(key in dictionary):
|
||||
return dictionary[key]
|
||||
|
||||
def optinStatus(str):
|
||||
if not str:
|
||||
return str("")
|
||||
else:
|
||||
dictionary = dict(subString.split(":") for subString in str.split(","))
|
||||
if("Opt-in" in dictionary):
|
||||
if(len(dictionary) == 1 ):
|
||||
return "Opted In"
|
||||
else:
|
||||
if("Opt-out" in dictionary):
|
||||
return "Opted Out"
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{% extends "templates/web.html" %}
|
||||
|
||||
{% block page_content %}
|
||||
<h1>{{ title |e }}</h1>
|
||||
{% endblock %}
|
||||
|
||||
<!-- this is a sample default web page template -->
|
|
@ -0,0 +1,4 @@
|
|||
<div>
|
||||
<a href="/{{ doc.route |e }}">{{ (doc.title or doc.name) |e }}</a>
|
||||
</div>
|
||||
<!-- this is a sample default list template -->
|
|
@ -0,0 +1,9 @@
|
|||
# Copyright (c) 2024, snehalatha and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
|
||||
|
||||
class Testoptlist(FrappeTestCase):
|
||||
pass
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,15 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Your Frappe App</title>
|
||||
<!-- Tabulator CSS -->
|
||||
<link href="https://unpkg.com/tabulator-tables@5.4.4/dist/css/tabulator.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<!-- Your content -->
|
||||
|
||||
<!-- Tabulator JS -->
|
||||
|
||||
<script src="https://unpkg.com/tabulator-tables@5.4.4/dist/js/tabulator.min.js"></script>
|
||||
</body>
|
||||
</html>
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,38 @@
|
|||
import mysql.connector
|
||||
from frappe import _
|
||||
|
||||
def config():
|
||||
configdata = {
|
||||
'user': 'snehalatha',
|
||||
'password': 'paSsWord@#654',
|
||||
'host': '35.153.190.180',
|
||||
'database': 'cardio_28march'
|
||||
}
|
||||
return configdata
|
||||
|
||||
|
||||
def get_remote_data():
|
||||
# Database connection details
|
||||
|
||||
|
||||
try:
|
||||
# Establish the connection
|
||||
connection = mysql.connector.connect(**config())
|
||||
cursor = connection.cursor(dictionary=True)
|
||||
|
||||
# Execute the query
|
||||
query = "select * from clients;"
|
||||
cursor.execute(query)
|
||||
|
||||
# Fetch all rows
|
||||
rows = cursor.fetchall()
|
||||
|
||||
return rows
|
||||
|
||||
except mysql.connector.Error as err:
|
||||
frappe.throw(_("Error: {0}".format(err)))
|
||||
|
||||
finally:
|
||||
# Close the cursor and connection
|
||||
cursor.close()
|
||||
connection.close()
|
|
@ -0,0 +1,24 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
|
||||
<link href="https://unpkg.com/tabulator-tables@5.3.4/dist/css/tabulator.min.css" rel="stylesheet">
|
||||
|
||||
<!-- Tabulator JS -->
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<h1>Subscribed Successfully!</h1>
|
||||
<div id="example-table"></div>
|
||||
|
||||
<script src="./custompage.js"></script>
|
||||
|
||||
<script type="text/javascript" src="https://unpkg.com/tabulator-tables@5.0.7/dist/js/tabulator.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
// import {Tabulator} from 'tabulator-tables';
|
||||
|
||||
// (function(){
|
||||
document.addEventListener('DOMContentLoaded', function(){
|
||||
var table = new Tabulator("#example-table", {
|
||||
height:"311px",
|
||||
persistence:{
|
||||
sort:true,
|
||||
filter:true,
|
||||
columns:true,
|
||||
},
|
||||
persistenceID:"examplePerststance",
|
||||
columns:[
|
||||
{title:"Name", field:"name", width:200},
|
||||
{title:"Progress", field:"progress", width:100, sorter:"number"},
|
||||
{title:"Gender", field:"gender"},
|
||||
{title:"Rating", field:"rating", width:80},
|
||||
{title:"Favourite Color", field:"col"},
|
||||
{title:"Date Of Birth", field:"dob", hozAlign:"center", sorter:"date"},
|
||||
{title:"Driver", field:"car", hozAlign:"center", formatter:"tickCross"},
|
||||
],
|
||||
});
|
||||
})
|
|
@ -0,0 +1,4 @@
|
|||
from frappe import _
|
||||
|
||||
def get_context(context):
|
||||
context.tabulator_page = "custompage.html"
|
|
@ -0,0 +1,135 @@
|
|||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>OPT IN ANALYST</title>
|
||||
<!-- Tabulator CSS -->
|
||||
<link href="https://unpkg.com/tabulator-tables@5.4.4/dist/css/tabulator.min.css" rel="stylesheet">
|
||||
<style>
|
||||
.button {
|
||||
border: none;
|
||||
color: white;
|
||||
padding: 4px 4px;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
font-size: 12px;
|
||||
margin: 4px 2px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.button1 {background-color: #04AA6D;}
|
||||
.button2 {background-color: #008CBA;}
|
||||
.button3 {background-color: #9bba00;}
|
||||
/* .tabulator .tabulator-header .tabulator-col {background-color: #2b9af3;} */
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- {% extends "templates/web.html" %} -->
|
||||
|
||||
{% block title %}Pricing{% endblock %}
|
||||
{% block content %}
|
||||
<div>
|
||||
<button id="download-csv" class="button button1">Download CSV</button>
|
||||
<button id="download-xlsx" class="button button2">Download XLSX</button>
|
||||
<button id="download-pdf" class="button button3">Download PDF</button>
|
||||
</div>
|
||||
<div id="tabulator-table" class="tabulator-table"></div>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block script %}
|
||||
<script src="https://unpkg.com/tabulator-tables@5.4.4/dist/js/tabulator.min.js"></script>
|
||||
<script frappe.csrf_token = "{{frappe.session.csrf_token}}"; ></script>
|
||||
<script type="text/javascript" src="https://oss.sheetjs.com/sheetjs/xlsx.full.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.4.0/jspdf.umd.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.20/jspdf.plugin.autotable.min.js"></script>
|
||||
<script>
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
var data = [];
|
||||
frappe.call({
|
||||
method: 'optmanagement.www.optlistview.fetch_data',
|
||||
callback: function(r) {
|
||||
if (r.message) {
|
||||
data = r.message;
|
||||
// Render data in the HTML
|
||||
console.log(data);
|
||||
// You can use the data to populate your table or any other HTML element
|
||||
|
||||
|
||||
// Sample data for the table
|
||||
var tableData = [];
|
||||
for(var rec in data)
|
||||
{
|
||||
tableData.push({
|
||||
kol_id:rec.kol_id, kol_name:rec["kol_name"],project_name: rec["project_name"], client_name:rec["client_name"], client_poc:rec["client_poc"], cs_Assigned_poc:rec["cs_Assigned_poc"],optin_received_date:rec["optin_received_date"],optin_approved_date:rec["optin_approved_date"],status:rec["status"],project_details:rec["project_details"]
|
||||
});
|
||||
}
|
||||
console.log(tableData);
|
||||
// var tableData = [(
|
||||
// {kol_id:1, kol_name:"Oli Bob",project_name: "", client_name:"12", client_poc:"red", cs_Assigned_poc:""} )
|
||||
|
||||
// ];
|
||||
|
||||
// Create Tabulator table
|
||||
|
||||
var table = new Tabulator("#tabulator-table", {
|
||||
data:data, // Assign data to table
|
||||
layout:"fitColumns",
|
||||
// filterMode: "remote",
|
||||
pagination:true,
|
||||
paginationSize: 20,
|
||||
ajaxLoaderLoading:"<span>Loading Data</span>",
|
||||
// paginationMode:"remote",
|
||||
paginationSizeSelector: [5, 10, 50, 100],
|
||||
paginationCounter: "rows",
|
||||
columns:[ // Define table columns
|
||||
{title:"KOL ID", field:"kol_id", width:150,headerFilterPlaceholder: "Search", headerFilter: true,},
|
||||
{title:"KOL Name", field:"kol_name", width:150,headerFilterPlaceholder: "Search", headerFilter: true,},
|
||||
{title:"Project Name", field:"project_name",headerFilterPlaceholder: "Search", headerFilter: true,},
|
||||
{title:"Client Name", field:"client_name",headerFilterPlaceholder: "Search", headerFilter: true,},
|
||||
{title:"Client POC", field:"client_poc",headerFilterPlaceholder: "Search", headerFilter: true,},
|
||||
{title:"CS Assigned POC", field:"cs_assigned_poc",headerFilterPlaceholder: "Search", headerFilter: true,},
|
||||
{title:"Opt-in Requested", field:"optin_received_date",headerFilterPlaceholder: "Search", headerFilter: true,},
|
||||
{title:"Opt-in Approved", field:"optin_approved_date",headerFilterPlaceholder: "Search", headerFilter: true,},
|
||||
{title:"Status", field:"status",headerFilterPlaceholder: "Search", headerFilter: true,},
|
||||
{title:"Project Details", field:"project_details",headerFilterPlaceholder: "Search", headerFilter: true,},
|
||||
],
|
||||
});
|
||||
document.getElementById("download-csv").addEventListener("click", function(){
|
||||
table.download("csv", "data.csv");
|
||||
});
|
||||
|
||||
|
||||
|
||||
//trigger download of data.xlsx file
|
||||
document.getElementById("download-xlsx").addEventListener("click", function(){
|
||||
table.download("xlsx", "data.xlsx", {sheetName:"My Data"});
|
||||
});
|
||||
|
||||
//trigger download of data.pdf file
|
||||
document.getElementById("download-pdf").addEventListener("click", function(){
|
||||
table.download("pdf", "data.pdf", {
|
||||
orientation:"portrait", //set page orientation to portrait
|
||||
title:"Example Report", //add title to report
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,20 @@
|
|||
import frappe
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def fetch_data():
|
||||
records = frappe.get_list('optlist',
|
||||
filters=None,
|
||||
limit_page_length=20)
|
||||
return [{
|
||||
"kol_id" : str(client["kol_id"]),
|
||||
"kol_name" : str(client["kol_name"]),
|
||||
"project_name" : str(client["project_name"]),
|
||||
"client_name" : str(client["client_name"]),
|
||||
"client_poc" : str(client["client_poc"]),
|
||||
"optin_received_date" : str(client["optin_received_date"]),
|
||||
"optin_approved_date" : str(client["optin_approved_date"]),
|
||||
"status" : str(client["status"]),
|
||||
"project_details": str(client["project_details"])
|
||||
}
|
||||
for client in records]
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"name": "optmanagement",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "optmanagement",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"tabulator-tables": "^6.2.1"
|
||||
}
|
||||
},
|
||||
"node_modules/tabulator-tables": {
|
||||
"version": "6.2.1",
|
||||
"resolved": "https://registry.npmjs.org/tabulator-tables/-/tabulator-tables-6.2.1.tgz",
|
||||
"integrity": "sha512-iCyLUzE9xEesEWqHDzNgShr6fpIIsRXnvTSDxiEti3sVbVYwlRt5HTBnXsl8bxY+4p64Rxxdlk9jT3voNLcIZQ=="
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "optmanagement",
|
||||
"version": "1.0.0",
|
||||
"description": "Opt In Management",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"tabulator-tables": "^6.2.1"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue