# Path: jasper_erpnext_report/utils/file.py
# def get_jasper_path(for_all_sites = False):
# 	if not for_all_sites:
# 		return 	get_site_path("jasper")
# 
# 	module_path = os.path.normpath(os.path.join(os.path.dirname(jasper_erpnext_report.__file__), "jasper"))
# 	return module_path
# 
# def write_file(content, file_path, modes="w+"):
# 	with open(file_path, modes) as f:
# 		f.write(content)
# 	return file_path
# 
# def get_html_reports_path(report_name, where="reports", hash=None, localsite=None):
# 	site = localsite or frappe.local.site
# 	path_jasper_module = os.path.dirname(jasper_erpnext_report.__file__)
# 	path = os.path.join(path_jasper_module, "public", where, site, report_name, hash)
# 	frappe.create_folder(path)
# 	return path


import frappe
import json, os
from frappe import _
from email.utils import formataddr
from jasper_erpnext_report.utils.file import get_jasper_path, write_file, get_html_reports_path
	from frappe.website.utils import is_signup_enabled
	from frappe.core.doctype.communication.communication import get_email, send
	from frappe.core.doctype.communication.communication import make
	from jasper_erpnext_report.utils.utils import getFrappeVersion
	from frappe.model.naming import make_autoname
	from frappe.email.smtp import _get_email_account
def sendmail(file_name, output, fileid, doctype=None, name=None, sender=None, content=None, subject=None, sent_or_received="Sent", print_html=None, print_format=None, attachments='[]',
		send_me_a_copy=False, recipients=None):

	sent_via = frappe.get_doc(doctype, name)
	content += get_attach_link(fileid)
	d = frappe._dict({"subject": subject, "content": content, "sent_or_received": sent_or_received, "sender": sender or frappe.db.get_value("User", frappe.session.user, "email"),
	"recipients": recipients})
	send_comm_email(d, file_name, output, sent_via=sent_via, print_html=print_html, print_format=print_format, attachments=attachments, send_me_a_copy=send_me_a_copy)


def sendmail_v5(url, doctype=None, name=None, sender=None, content=None, subject=None, sent_or_received="Sent", send_email=False, print_html=None, print_format=None, attachments='[]',
		recipients=None):


	content += get_attach_link(url)
	return make(doctype=doctype, name=name, sender=sender, content=content, subject=subject, sent_or_received=sent_or_received, send_email=send_email, print_html=print_html, print_format=print_format, attachments=attachments,
		recipients=recipients)


def get_attach_link(url):
		"""Returns public link for the attachment via `templates/emails/print_link.html`."""
		return frappe.get_template("templates/emails/print_link.html").render({
			"url": "%s/%s" % (frappe.utils.get_url(), url)
		})


def get_email_pdf_path(report_name, reqId, site=None):

	site = site or frappe.local.site


# Path: jasper_erpnext_report/utils/file.py
# def get_jasper_path(for_all_sites = False):
# 	if not for_all_sites:
# 		return 	get_site_path("jasper")
# 
# 	module_path = os.path.normpath(os.path.join(os.path.dirname(jasper_erpnext_report.__file__), "jasper"))
# 	return module_path
# 
# def write_file(content, file_path, modes="w+"):
# 	with open(file_path, modes) as f:
# 		f.write(content)
# 	return file_path
# 
# def get_html_reports_path(report_name, where="reports", hash=None, localsite=None):
# 	site = localsite or frappe.local.site
# 	path_jasper_module = os.path.dirname(jasper_erpnext_report.__file__)
# 	path = os.path.join(path_jasper_module, "public", where, site, report_name, hash)
# 	frappe.create_folder(path)
# 	return path


# Path: jasper_erpnext_report/utils/jasper_email.py
import frappe
import json, os
from frappe import _
from email.utils import formataddr
from jasper_erpnext_report.utils.file import get_jasper_path, write_file, get_html_reports_path
	from frappe.website.utils import is_signup_enabled
	from frappe.core.doctype.communication.communication import get_email, send
	from frappe.core.doctype.communication.communication import make
	from jasper_erpnext_report.utils.utils import getFrappeVersion
	from frappe.model.naming import make_autoname
	from frappe.email.smtp import _get_email_account

def sendmail(file_name, output, fileid, doctype=None, name=None, sender=None, content=None, subject=None, sent_or_received="Sent", print_html=None, print_format=None, attachments='[]',
		send_me_a_copy=False, recipients=None):

	sent_via = frappe.get_doc(doctype, name)
	content += get_attach_link(fileid)
	d = frappe._dict({"subject": subject, "content": content, "sent_or_received": sent_or_received, "sender": sender or frappe.db.get_value("User", frappe.session.user, "email"),
	"recipients": recipients})
	send_comm_email(d, file_name, output, sent_via=sent_via, print_html=print_html, print_format=print_format, attachments=attachments, send_me_a_copy=send_me_a_copy)


def sendmail_v5(url, doctype=None, name=None, sender=None, content=None, subject=None, sent_or_received="Sent", send_email=False, print_html=None, print_format=None, attachments='[]',
		recipients=None):


	content += get_attach_link(url)
	return make(doctype=doctype, name=name, sender=sender, content=content, subject=subject, sent_or_received=sent_or_received, send_email=send_email, print_html=print_html, print_format=print_format, attachments=attachments,
		recipients=recipients)


def get_attach_link(url):
		"""Returns public link for the attachment via `templates/emails/print_link.html`."""
		return frappe.get_template("templates/emails/print_link.html").render({
			"url": "%s/%s" % (frappe.utils.get_url(), url)
		})


def get_email_pdf_path(report_name, reqId, site=None):

	site = site or frappe.local.site


	file_path = get_html_reports_path(report_name, where="reports", hash=reqId, localsite=site)