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

	return file_path


def get_email_other_path(data, file_name, reqId, sender):

	path_join = os.path.join
	rdoc = frappe.get_doc(data.get("doctype"), data.get('report_name'))
	for_all_sites = rdoc.jasper_all_sites_report
	jasper_path = get_jasper_path(for_all_sites)
	jasper_path_intern = path_join("jasper_sent_email", sender, reqId)
	outputPath = path_join(jasper_path, jasper_path_intern)
	frappe.create_folder(outputPath)
	file_path = path_join(outputPath, file_name)

	return file_path


def jasper_save_email(file_path, output):


# 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

		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)

	return file_path


def get_email_other_path(data, file_name, reqId, sender):

	path_join = os.path.join
	rdoc = frappe.get_doc(data.get("doctype"), data.get('report_name'))
	for_all_sites = rdoc.jasper_all_sites_report
	jasper_path = get_jasper_path(for_all_sites)
	jasper_path_intern = path_join("jasper_sent_email", sender, reqId)
	outputPath = path_join(jasper_path, jasper_path_intern)
	frappe.create_folder(outputPath)
	file_path = path_join(outputPath, file_name)

	return file_path


def jasper_save_email(file_path, output):


	write_file(output, file_path, modes="wb")