feat:optin list

This commit is contained in:
snehalathad@aissel.com 2024-06-13 14:46:09 +05:30
parent f4137e34cc
commit 565cb5d79a
12 changed files with 522 additions and 0 deletions

View File

@ -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)

View File

@ -0,0 +1,8 @@
// Copyright (c) 2024, snehalatha and contributors
// For license information, please see license.txt
// frappe.ui.form.on("optlistprod", {
// refresh(frm) {
// },
// });

View File

@ -0,0 +1,108 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "field:kol_id",
"creation": "2024-06-13 14:13:54.096900",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"kol_id",
"kol_name",
"project_name",
"client_name",
"client_poc",
"optin_received_date",
"optin_approved_date",
"status",
"cs_assigned_poc",
"optin_type",
"data_processed_date"
],
"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",
"in_list_view": 1,
"label": "Client Name"
},
{
"fieldname": "client_poc",
"fieldtype": "Data",
"label": "Client POC"
},
{
"fieldname": "optin_received_date",
"fieldtype": "Data",
"in_list_view": 1,
"label": "OptIn Received Date"
},
{
"fieldname": "optin_approved_date",
"fieldtype": "Data",
"label": "OptIn Approved Date"
},
{
"fieldname": "status",
"fieldtype": "Data",
"label": "Status"
},
{
"fieldname": "cs_assigned_poc",
"fieldtype": "Data",
"label": "CS Assigned POC"
},
{
"fieldname": "optin_type",
"fieldtype": "Data",
"label": "OptIn Type"
},
{
"fieldname": "data_processed_date",
"fieldtype": "Data",
"label": "Data Processed Date"
}
],
"index_web_pages_for_search": 1,
"is_virtual": 1,
"links": [],
"modified": "2024-06-13 14:36:08.390315",
"modified_by": "Administrator",
"module": "Opt management production",
"name": "optlistprod",
"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": []
}

View File

@ -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 optmanagementprod.kol_databases import get_records
class optlistprod(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"]),
"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"]),
"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"

View File

@ -0,0 +1,9 @@
# Copyright (c) 2024, snehalatha and Contributors
# See license.txt
# import frappe
from frappe.tests.utils import FrappeTestCase
class Testoptlistprod(FrappeTestCase):
pass

File diff suppressed because one or more lines are too long

View File

@ -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

View File

@ -0,0 +1,140 @@
<!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 %}
<h4>Opt In Data</h4>
<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: 'optmanagementprod.www.optanalystview.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"],optin_type:rec["optin_type"],data_processed_date:rec["data_processed_date"]
});
}
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,
// layout:"fitDataStretch",
ajaxLoaderLoading:"<span>Loading Data</span>",
// paginationMode:"remote",
paginationSizeSelector: [5, 10, 50, 100],
paginationCounter: "rows",
columns:[ // Define table columns
{title:"KOL ID", field:"kol_id",headerFilterPlaceholder: "Search", headerFilter: true,},
{title:"KOL Name", field:"kol_name",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:"Requested Date", field:"optin_received_date",headerFilterPlaceholder: "Search", headerFilter: true,},
{title:"Approved Date", field:"optin_approved_date",headerFilterPlaceholder: "Search", headerFilter: true,},
{title:"Status", field:"status",headerFilterPlaceholder: "Search", headerFilter: true,},
{title:"Opt-In Type", field:"optin_type",headerFilterPlaceholder: "Search", headerFilter: true,},
{title:"Data Processed Date", field:"data_processed_date",headerFilterPlaceholder: "Search", headerFilter: true,},
],
});
document.getElementById("download-csv").addEventListener("click", function(){
table.download("csv", "optInData.csv");
});
//trigger download of data.xlsx file
document.getElementById("download-xlsx").addEventListener("click", function(){
table.download("xlsx", "optInData.xlsx", {sheetName:"Opt In Data"});
});
//trigger download of data.pdf file
document.getElementById("download-pdf").addEventListener("click", function(){
table.download("pdf", "optInData.pdf", {
orientation:"portrait", //set page orientation to portrait
title:"opt In Data Report", //add title to report
});
});
}
}
});
});
</script>
{% endblock %}
</body>
</html>

View File

@ -0,0 +1,22 @@
import frappe
@frappe.whitelist(allow_guest=True)
def fetch_data():
records = frappe.get_list('optlistprod',
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"]),
}
for client in records]