Merged main into clean install.
This commit is contained in:
commit
5922aaa9df
BIN
Screenshot from 2026-02-04 12-41-31.png
Normal file
BIN
Screenshot from 2026-02-04 12-41-31.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 496 KiB |
@ -132,7 +132,7 @@ def submit_bid_meeting_note_form(bid_meeting, project_template, fields, form_tem
|
||||
})
|
||||
new_bid_meeting_note_doc.insert(ignore_permissions=True)
|
||||
for field_row, field in zip(new_bid_meeting_note_doc.fields, fields):
|
||||
print(f"DEBUG: {field_row.label} - {field.get("label")}")
|
||||
print(f"DEBUG: {field_row.label} - {field.get('label')}")
|
||||
if not isinstance(field.get("value"), list):
|
||||
continue
|
||||
for item in field["value"]:
|
||||
|
||||
@ -2,9 +2,9 @@ import frappe, json
|
||||
from frappe.utils.pdf import get_pdf
|
||||
from custom_ui.api.db.general import get_doc_history
|
||||
from custom_ui.db_utils import DbUtils, process_query_conditions, build_datatable_dict, get_count_or_filters, build_success_response, build_error_response
|
||||
from werkzeug.wrappers import Response
|
||||
from custom_ui.api.db.clients import check_if_customer, convert_lead_to_customer
|
||||
from custom_ui.services import DbService, ClientService, AddressService, ContactService
|
||||
from custom_ui.services import ItemService, DbService, ClientService, AddressService, ContactService, EstimateService, ItemService
|
||||
from frappe.email.doctype.email_template.email_template import get_email_template
|
||||
|
||||
# ===============================================================================
|
||||
# ESTIMATES & INVOICES API METHODS
|
||||
@ -86,11 +86,25 @@ def get_estimate_table_data(filters={}, sortings=[], page=1, page_size=10):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_quotation_items():
|
||||
def get_quotation_items(project_template:str = None):
|
||||
"""Get all available quotation items."""
|
||||
try:
|
||||
items = frappe.get_all("Item", fields=["*"], filters={"item_group": "SNW-S"})
|
||||
return build_success_response(items)
|
||||
filters = EstimateService.map_project_template_to_filter(project_template)
|
||||
items = frappe.get_all("Item", fields=["item_code", "item_group"], filters=filters)
|
||||
grouped_item_dicts = {}
|
||||
for item in items:
|
||||
item_dict = ItemService.get_full_dict(item.item_code)
|
||||
if item_dict["bom"]:
|
||||
if "Packages" not in grouped_item_dicts:
|
||||
grouped_item_dicts["Packages"] = {}
|
||||
if item.item_group not in grouped_item_dicts["Packages"]:
|
||||
grouped_item_dicts["Packages"][item.item_group] = []
|
||||
grouped_item_dicts["Packages"][item.item_group].append(item_dict)
|
||||
else:
|
||||
if item.item_group not in grouped_item_dicts:
|
||||
grouped_item_dicts[item.item_group] = []
|
||||
grouped_item_dicts[item.item_group].append(item_dict)
|
||||
return build_success_response(grouped_item_dicts)
|
||||
except Exception as e:
|
||||
return build_error_response(str(e), 500)
|
||||
|
||||
@ -131,6 +145,7 @@ def get_estimate(estimate_name):
|
||||
est_dict["address_details"] = address_doc
|
||||
|
||||
est_dict["history"] = get_doc_history("Quotation", estimate_name)
|
||||
est_dict["items"] = [ItemService.get_full_dict(item.item_code) for item in estimate.items]
|
||||
|
||||
return build_success_response(est_dict)
|
||||
except Exception as e:
|
||||
@ -177,7 +192,7 @@ def send_estimate_email(estimate_name):
|
||||
print("DEBUG: Sending estimate email for:", estimate_name)
|
||||
quotation = frappe.get_doc("Quotation", estimate_name)
|
||||
|
||||
|
||||
# Get recipient email
|
||||
if not DbService.exists("Contact", quotation.contact_person):
|
||||
return build_error_response("No email found for the customer.", 400)
|
||||
party = ContactService.get_or_throw(quotation.contact_person)
|
||||
@ -196,21 +211,71 @@ def send_estimate_email(estimate_name):
|
||||
if not email:
|
||||
return build_error_response("No email found for the customer or address.", 400)
|
||||
|
||||
# email = "casey@shilohcode.com"
|
||||
template_name = "Quote with Actions - SNW"
|
||||
template = frappe.get_doc("Email Template", template_name)
|
||||
message = frappe.render_template(template.response, {"name": quotation.name})
|
||||
subject = frappe.render_template(template.subject, {"doc": quotation})
|
||||
print("DEBUG: Message: ", message)
|
||||
print("DEBUG: Subject: ", subject)
|
||||
# Get customer name
|
||||
customer_name = party.first_name or party.name or "Valued Customer"
|
||||
if party.last_name:
|
||||
customer_name = f"{party.first_name} {party.last_name}"
|
||||
|
||||
# Get full address
|
||||
full_address = "Address not specified"
|
||||
if quotation.custom_job_address:
|
||||
address_doc = frappe.get_doc("Address", quotation.custom_job_address)
|
||||
full_address = address_doc.full_address or address_doc.address_line1 or "Address not specified"
|
||||
|
||||
# Format price
|
||||
price = frappe.utils.fmt_money(quotation.grand_total, currency=quotation.currency)
|
||||
|
||||
# Get additional notes
|
||||
additional = quotation.terms or ""
|
||||
|
||||
# Get company phone
|
||||
company_phone = ""
|
||||
if quotation.company:
|
||||
company_doc = frappe.get_doc("Company", quotation.company)
|
||||
company_phone = getattr(company_doc, 'phone_no', '') or getattr(company_doc, 'phone', '')
|
||||
|
||||
# Get base URL
|
||||
base_url = frappe.utils.get_url()
|
||||
|
||||
# Get letterhead image
|
||||
letterhead_image = ""
|
||||
if quotation.letter_head:
|
||||
letterhead_doc = frappe.get_doc("Letter Head", quotation.letter_head)
|
||||
if letterhead_doc.image:
|
||||
letterhead_image = frappe.utils.get_url() + letterhead_doc.image
|
||||
|
||||
# Prepare template context
|
||||
template_context = {
|
||||
"company": quotation.company,
|
||||
"customer_name": customer_name,
|
||||
"price": price,
|
||||
"address": full_address,
|
||||
"additional": additional,
|
||||
"company_phone": company_phone,
|
||||
"base_url": base_url,
|
||||
"estimate_name": quotation.name,
|
||||
"letterhead_image": letterhead_image
|
||||
}
|
||||
|
||||
# Render the email template
|
||||
template_path = "custom_ui/templates/emails/general_estimation.html"
|
||||
message = frappe.render_template(template_path, template_context)
|
||||
subject = f"Estimate from {quotation.company} - {quotation.name}"
|
||||
|
||||
print("DEBUG: Subject:", subject)
|
||||
print("DEBUG: Sending email to:", email)
|
||||
|
||||
# Generate PDF attachment
|
||||
html = frappe.get_print("Quotation", quotation.name, print_format="Quotation - SNW - Standard", letterhead=True)
|
||||
print("DEBUG: Generated HTML for PDF.")
|
||||
pdf = get_pdf(html)
|
||||
print("DEBUG: Generated PDF for email attachment.")
|
||||
|
||||
# Send email
|
||||
frappe.sendmail(
|
||||
recipients=email,
|
||||
subject=subject,
|
||||
content=message,
|
||||
message=message,
|
||||
doctype="Quotation",
|
||||
name=quotation.name,
|
||||
read_receipt=1,
|
||||
@ -218,11 +283,14 @@ def send_estimate_email(estimate_name):
|
||||
attachments=[{"fname": f"{quotation.name}.pdf", "fcontent": pdf}]
|
||||
)
|
||||
print(f"DEBUG: Email sent to {email} successfully.")
|
||||
|
||||
# Update quotation status
|
||||
quotation.custom_current_status = "Submitted"
|
||||
quotation.custom_sent = 1
|
||||
quotation.save()
|
||||
quotation.submit()
|
||||
frappe.db.commit()
|
||||
|
||||
updated_quotation = frappe.get_doc("Quotation", estimate_name)
|
||||
return build_success_response(updated_quotation.as_dict())
|
||||
except Exception as e:
|
||||
@ -255,45 +323,6 @@ def manual_response(name, response):
|
||||
return build_error_response(str(e), 500)
|
||||
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def update_response(name, response):
|
||||
"""Update the response for a given estimate."""
|
||||
print("DEBUG: RESPONSE RECEIVED:", name, response)
|
||||
try:
|
||||
if not frappe.db.exists("Quotation", name):
|
||||
raise Exception("Estimate not found.")
|
||||
estimate = frappe.get_doc("Quotation", name)
|
||||
if estimate.docstatus != 1:
|
||||
raise Exception("Estimate must be submitted to update response.")
|
||||
accepted = True if response == "Accepted" else False
|
||||
new_status = "Estimate Accepted" if accepted else "Lost"
|
||||
|
||||
estimate.custom_response = response
|
||||
estimate.custom_current_status = new_status
|
||||
estimate.custom_followup_needed = 1 if response == "Requested call" else 0
|
||||
# estimate.status = "Ordered" if accepted else "Closed"
|
||||
estimate.flags.ignore_permissions = True
|
||||
print("DEBUG: Updating estimate with response:", response, "and status:", new_status)
|
||||
estimate.save()
|
||||
|
||||
if accepted:
|
||||
template = "custom_ui/templates/estimates/accepted.html"
|
||||
# if check_if_customer(estimate.party_name):
|
||||
# print("DEBUG: Party is already a customer:", estimate.party_name)
|
||||
# else:
|
||||
# print("DEBUG: Converting lead to customer for party:", estimate.party_name)
|
||||
# convert_lead_to_customer(estimate.party_name)
|
||||
elif response == "Requested call":
|
||||
template = "custom_ui/templates/estimates/request-call.html"
|
||||
else:
|
||||
template = "custom_ui/templates/estimates/rejected.html"
|
||||
html = frappe.render_template(template, {"doc": estimate})
|
||||
return Response(html, mimetype="text/html")
|
||||
except Exception as e:
|
||||
template = "custom_ui/templates/estimates/error.html"
|
||||
html = frappe.render_template(template, {"error": str(e)})
|
||||
return Response(html, mimetype="text/html")
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_estimate_templates(company):
|
||||
"""Get available estimate templates."""
|
||||
@ -448,6 +477,7 @@ def upsert_estimate(data):
|
||||
estimate.append("items", {
|
||||
"item_code": item.get("item_code"),
|
||||
"qty": item.get("qty"),
|
||||
"rate": item.get("rate"),
|
||||
"discount_amount": item.get("discount_amount") or item.get("discountAmount", 0),
|
||||
"discount_percentage": item.get("discount_percentage") or item.get("discountPercentage", 0)
|
||||
})
|
||||
@ -492,6 +522,7 @@ def upsert_estimate(data):
|
||||
new_estimate.append("items", {
|
||||
"item_code": item.get("item_code"),
|
||||
"qty": item.get("qty"),
|
||||
"rate": item.get("rate"),
|
||||
"discount_amount": item.get("discount_amount") or item.get("discountAmount", 0),
|
||||
"discount_percentage": item.get("discount_percentage") or item.get("discountPercentage", 0)
|
||||
})
|
||||
@ -502,7 +533,9 @@ def upsert_estimate(data):
|
||||
# AddressService.append_link(data.get("address_name"), "quotations", "quotation", new_estimate.name)
|
||||
# ClientService.append_link(data.get("customer"), "quotations", "quotation", new_estimate.name)
|
||||
print("DEBUG: New estimate created with name:", new_estimate.name)
|
||||
return build_success_response(new_estimate.as_dict())
|
||||
dict = new_estimate.as_dict()
|
||||
dict["items"] = [ItemService.get_full_dict(item.item_code) for item in new_estimate.items]
|
||||
return build_success_response(dict)
|
||||
except Exception as e:
|
||||
print(f"DEBUG: Error in upsert_estimate: {str(e)}")
|
||||
return build_error_response(str(e), 500)
|
||||
|
||||
80
custom_ui/api/db/items.py
Normal file
80
custom_ui/api/db/items.py
Normal file
@ -0,0 +1,80 @@
|
||||
import frappe
|
||||
import json
|
||||
from custom_ui.models import PackageCreationData
|
||||
from custom_ui.services import ProjectService, ItemService
|
||||
from custom_ui.db_utils import build_error_response, build_success_response
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_by_project_template(project_template: str) -> dict:
|
||||
"""Retrieve items associated with a given project template."""
|
||||
print(f"DEBUG: Getting items for Project Template {project_template}")
|
||||
item_groups = ProjectService.get_project_item_groups(project_template)
|
||||
items = ItemService.get_items_by_groups(item_groups)
|
||||
print(f"DEBUG: Retrieved {len(items)} items for Project Template {project_template}")
|
||||
categorized_items = ItemService.build_category_dict(items)
|
||||
return build_success_response(categorized_items)
|
||||
|
||||
@frappe.whitelist()
|
||||
def save_as_package_item(data):
|
||||
"""Save a new Package Item based on the provided data."""
|
||||
from custom_ui.models import BOMItem
|
||||
data = json.loads(data)
|
||||
print(f"DEBUG: Saving Package Item with data: {data}")
|
||||
# Map 'category' to 'item_group' for the model
|
||||
data['item_group'] = data.pop('category')
|
||||
# Convert items dictionaries to BOMItem instances
|
||||
data['items'] = [
|
||||
BOMItem(
|
||||
item_code=item['item_code'],
|
||||
qty=item['qty'],
|
||||
uom=item['uom']
|
||||
) for item in data['items']
|
||||
]
|
||||
data = PackageCreationData(**data)
|
||||
item = frappe.get_doc({
|
||||
"doctype": "Item",
|
||||
"item_code": ItemService.build_item_code(data.code_prefix, data.package_name),
|
||||
"item_name": data.package_name,
|
||||
"is_stock_item": 0,
|
||||
"item_group": data.item_group,
|
||||
"description": data.description,
|
||||
"standard_rate": data.rate or 0.0,
|
||||
"company": data.company,
|
||||
"has_variants": 0,
|
||||
"stock_uom": "Nos",
|
||||
"is_sales_item": 1,
|
||||
"is_purchase_item": 0,
|
||||
"is_pro_applicable": 0,
|
||||
"is_fixed_asset": 0,
|
||||
"is_service_item": 0
|
||||
}).insert()
|
||||
bom = frappe.get_doc({
|
||||
"doctype": "BOM",
|
||||
"item": item.name,
|
||||
"uom": "Nos",
|
||||
"is_active": 1,
|
||||
"is_default": 1,
|
||||
"items": [{
|
||||
"item_code": bom_item.item_code,
|
||||
"qty": bom_item.qty,
|
||||
"uom": bom_item.uom
|
||||
} for bom_item in data.items]
|
||||
}).insert()
|
||||
bom.submit()
|
||||
item.reload() # Refresh to get latest version after BOM submission
|
||||
item.default_bom = bom.name
|
||||
item.save()
|
||||
print(f"DEBUG: Created Package Item with name: {item.name}")
|
||||
item_dict = item.as_dict()
|
||||
item_dict["bom"] = ItemService.get_full_bom_dict(item.item_code) # Attach BOM details to the item dict
|
||||
return build_success_response(item_dict)
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_item_categories():
|
||||
"""Retrieve all item groups for categorization."""
|
||||
print("DEBUG: Getting item categories")
|
||||
item_groups = frappe.get_all("Item Group", pluck="name")
|
||||
print(f"DEBUG: Retrieved item categories: {item_groups}")
|
||||
return build_success_response(item_groups)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import frappe, json
|
||||
from custom_ui.db_utils import process_query_conditions, build_datatable_dict, get_count_or_filters, build_success_response, build_error_response
|
||||
from custom_ui.services import AddressService, ClientService, ServiceAppointmentService
|
||||
from custom_ui.db_utils import process_query_conditions, build_datatable_dict, get_count_or_filters, build_success_response, build_error_response, process_sorting
|
||||
from custom_ui.services import AddressService, ClientService, ServiceAppointmentService, ProjectService
|
||||
from frappe.utils import getdate
|
||||
|
||||
# ===============================================================================
|
||||
@ -119,13 +119,7 @@ def get_job(job_id=""):
|
||||
"""Get particular Job from DB"""
|
||||
print("DEBUG: Loading Job from database:", job_id)
|
||||
try:
|
||||
project = frappe.get_doc("Project", job_id)
|
||||
address_doc = AddressService.get_or_throw(project.job_address)
|
||||
project = project.as_dict()
|
||||
project["job_address"] = address_doc
|
||||
project["client"] = ClientService.get_client_or_throw(project.customer)
|
||||
task_names = frappe.get_all("Task", filters={"project": job_id})
|
||||
project["tasks"] = [frappe.get_doc("Task", task_name).as_dict() for task_name in task_names]
|
||||
project = ProjectService.get_full_project_details(job_id)
|
||||
return build_success_response(project)
|
||||
except Exception as e:
|
||||
return build_error_response(str(e), 500)
|
||||
@ -187,6 +181,8 @@ def get_job_task_list(job_id=""):
|
||||
def get_jobs_table_data(filters={}, sortings=[], page=1, page_size=10):
|
||||
"""Get paginated job table data with filtering and sorting support."""
|
||||
print("DEBUG: Raw job options received:", filters, sortings, page, page_size)
|
||||
filters = json.loads(filters) if isinstance(filters, str) else filters
|
||||
sortings = json.loads(sortings) if isinstance(sortings, str) else sortings
|
||||
|
||||
processed_filters, processed_sortings, is_or, page, page_size = process_query_conditions(filters, sortings, page, page_size)
|
||||
|
||||
|
||||
@ -2,6 +2,15 @@ import frappe, json
|
||||
from custom_ui.db_utils import build_success_response, build_error_response
|
||||
from custom_ui.services import ServiceAppointmentService
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_service_appointment(service_appointment_name):
|
||||
"""Get a single Service Appointment by name."""
|
||||
try:
|
||||
service_appointment = ServiceAppointmentService.get_full_dict(service_appointment_name)
|
||||
return build_success_response(service_appointment)
|
||||
except Exception as e:
|
||||
return build_error_response(str(e), 500)
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_service_appointments(companies, filters={}):
|
||||
"""Get Service Appointments for given companies."""
|
||||
@ -65,5 +74,19 @@ def update_service_appointment_scheduled_dates(service_appointment_name: str, st
|
||||
end_time
|
||||
)
|
||||
return build_success_response(updated_service_appointment.as_dict())
|
||||
except Exception as e:
|
||||
return build_error_response(str(e), 500)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_service_appointment_status(service_appointment_name: str, new_status: str):
|
||||
"""Update status for a Service Appointment."""
|
||||
print(f"DEBUG: Updating status for Service Appointment {service_appointment_name} to new status: {new_status}")
|
||||
try:
|
||||
updated_service_appointment = ServiceAppointmentService.update_status(
|
||||
service_appointment_name,
|
||||
new_status
|
||||
)
|
||||
return build_success_response(updated_service_appointment.as_dict())
|
||||
except Exception as e:
|
||||
return build_error_response(str(e), 500)
|
||||
43
custom_ui/api/public/estimates.py
Normal file
43
custom_ui/api/public/estimates.py
Normal file
@ -0,0 +1,43 @@
|
||||
import frappe
|
||||
from werkzeug.wrappers import Response
|
||||
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def update_response(name, response):
|
||||
"""Update the response for a given estimate."""
|
||||
print("DEBUG: RESPONSE RECEIVED:", name, response)
|
||||
try:
|
||||
if not frappe.db.exists("Quotation", name):
|
||||
raise Exception("Estimate not found.")
|
||||
estimate = frappe.get_doc("Quotation", name)
|
||||
if estimate.docstatus != 1:
|
||||
raise Exception("Estimate must be submitted to update response.")
|
||||
accepted = True if response == "Accepted" else False
|
||||
new_status = "Estimate Accepted" if accepted else "Lost"
|
||||
|
||||
estimate.custom_response = response
|
||||
estimate.custom_current_status = new_status
|
||||
estimate.custom_followup_needed = 1 if response == "Requested call" else 0
|
||||
# estimate.status = "Ordered" if accepted else "Closed"
|
||||
estimate.flags.ignore_permissions = True
|
||||
print("DEBUG: Updating estimate with response:", response, "and status:", new_status)
|
||||
estimate.save()
|
||||
|
||||
if accepted:
|
||||
template = "custom_ui/templates/estimates/accepted.html"
|
||||
# if check_if_customer(estimate.party_name):
|
||||
# print("DEBUG: Party is already a customer:", estimate.party_name)
|
||||
# else:
|
||||
# print("DEBUG: Converting lead to customer for party:", estimate.party_name)
|
||||
# convert_lead_to_customer(estimate.party_name)
|
||||
elif response == "Requested call":
|
||||
template = "custom_ui/templates/estimates/request-call.html"
|
||||
else:
|
||||
template = "custom_ui/templates/estimates/rejected.html"
|
||||
html = frappe.render_template(template, {"doc": estimate})
|
||||
frappe.db.commit()
|
||||
return Response(html, mimetype="text/html")
|
||||
except Exception as e:
|
||||
template = "custom_ui/templates/estimates/error.html"
|
||||
html = frappe.render_template(template, {"error": str(e)})
|
||||
return Response(html, mimetype="text/html")
|
||||
@ -1,7 +1,9 @@
|
||||
import frappe
|
||||
import json
|
||||
from datetime import datetime
|
||||
from frappe.utils.data import flt
|
||||
from custom_ui.services import DbService, StripeService
|
||||
from custom_ui.services import DbService, StripeService, PaymentService
|
||||
from custom_ui.models import PaymentData
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def half_down_stripe_payment(sales_order):
|
||||
@ -13,16 +15,37 @@ def half_down_stripe_payment(sales_order):
|
||||
frappe.throw("This sales order does not require a half-down payment.")
|
||||
if so.docstatus != 1:
|
||||
frappe.throw("Sales Order must be submitted to proceed with payment.")
|
||||
if so.custom_halfdown_is_paid or so.advanced_paid >= so.custom_halfdown_amount:
|
||||
if so.custom_halfdown_is_paid or so.advance_paid >= so.custom_halfdown_amount:
|
||||
frappe.throw("Half-down payment has already been made for this sales order.")
|
||||
stripe_session = StripeService.create_checkout_session(
|
||||
company=so.company,
|
||||
amount=so.custom_halfdown_amount,
|
||||
service=so.custom_project_template,
|
||||
sales_order=so.name,
|
||||
order_num=so.name,
|
||||
for_advance_payment=True
|
||||
)
|
||||
return frappe.redirect(stripe_session.url)
|
||||
frappe.local.response["type"] = "redirect"
|
||||
frappe.local.response["location"] = stripe_session.url
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def invoice_stripe_payment(sales_invoice):
|
||||
"""Public endpoint for initiating a full payment for a sales invoice."""
|
||||
if not DbService.exists("Sales Invoice", sales_invoice):
|
||||
frappe.throw("Sales Invoice does not exist.")
|
||||
si = DbService.get_or_throw("Sales Invoice", sales_invoice)
|
||||
if si.docstatus != 1:
|
||||
frappe.throw("Sales Invoice must be submitted to proceed with payment.")
|
||||
if si.outstanding_amount <= 0:
|
||||
frappe.throw("This invoice has already been paid.")
|
||||
stripe_session = StripeService.create_checkout_session(
|
||||
company=si.company,
|
||||
amount=si.outstanding_amount,
|
||||
service=si.project_template,
|
||||
order_num=si.name,
|
||||
for_advance_payment=False
|
||||
)
|
||||
frappe.local.response["type"] = "redirect"
|
||||
frappe.local.response["location"] = stripe_session.url
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def stripe_webhook():
|
||||
@ -31,39 +54,60 @@ def stripe_webhook():
|
||||
sig_header = frappe.request.headers.get('Stripe-Signature')
|
||||
session, metadata = StripeService.get_session_and_metadata(payload, sig_header)
|
||||
|
||||
# Validate required metadata
|
||||
if not metadata.get("company"):
|
||||
raise frappe.ValidationError("Missing required metadata key: company")
|
||||
if not metadata.get("payment_type"):
|
||||
raise frappe.ValidationError("Missing required metadata key: payment_type")
|
||||
|
||||
# Determine reference document based on payment type
|
||||
payment_type = metadata.get("payment_type")
|
||||
reference_doctype = None
|
||||
reference_doc_name = None
|
||||
|
||||
if payment_type == "advance":
|
||||
reference_doctype = "Sales Order"
|
||||
reference_doc_name = metadata.get("sales_order")
|
||||
if not reference_doc_name:
|
||||
raise frappe.ValidationError("Missing sales_order in metadata for advance payment")
|
||||
elif payment_type == "full":
|
||||
reference_doctype = "Sales Invoice"
|
||||
reference_doc_name = metadata.get("sales_invoice")
|
||||
if not reference_doc_name:
|
||||
raise frappe.ValidationError("Missing sales_invoice in metadata for full payment")
|
||||
else:
|
||||
raise frappe.ValidationError(f"Invalid payment type in metadata: {payment_type}")
|
||||
|
||||
# Check if payment already exists
|
||||
if DbService.exists("Payment Entry", {"reference_no": session.id}):
|
||||
raise frappe.ValidationError("Payment Entry already exists for this session.")
|
||||
|
||||
reference_doctype = "Sales Invoice"
|
||||
|
||||
if metadata.get("payment_type") == "advance":
|
||||
reference_doctype = "Sales Order"
|
||||
elif metadata.get("payment_type") != "full":
|
||||
raise frappe.ValidationError("Invalid payment type in metadata.")
|
||||
|
||||
amount_paid = flt(session.amount_total) / 100
|
||||
currency = session.currency.upper()
|
||||
reference_doc = frappe.get_doc(reference_doctype, metadata.get("order_num"))
|
||||
|
||||
pe = frappe.get_doc({
|
||||
"doctype": "Payment Entry",
|
||||
"payment_type": "Receive",
|
||||
"party_type": "Customer",
|
||||
"mode_of_payment": "Stripe",
|
||||
"party": reference_doc.customer,
|
||||
"party_name": reference_doc.customer,
|
||||
"paid_to": metadata.get("company"),
|
||||
"reference_no": session.id,
|
||||
"reference_date": frappe.utils.nowdate(),
|
||||
"reference_doctype": reference_doctype,
|
||||
"reference_name": reference_doc.name,
|
||||
"paid_amount": amount_paid,
|
||||
"paid_currency": currency,
|
||||
})
|
||||
# Convert Unix timestamp to date string (YYYY-MM-DD)
|
||||
reference_date = datetime.fromtimestamp(session.created).strftime('%Y-%m-%d')
|
||||
|
||||
pe.insert()
|
||||
pe.submit()
|
||||
return "Payment Entry created and submitted successfully."
|
||||
# Set Administrator context to create Payment Entry
|
||||
frappe.set_user("Administrator")
|
||||
|
||||
try:
|
||||
pe = PaymentService.create_payment_entry(
|
||||
data=PaymentData(
|
||||
mode_of_payment="Stripe",
|
||||
reference_no=session.id,
|
||||
reference_date=reference_date,
|
||||
received_amount=amount_paid,
|
||||
company=metadata.get("company"),
|
||||
reference_doc_name=reference_doc_name
|
||||
)
|
||||
)
|
||||
pe.flags.ignore_permissions = True
|
||||
pe.submit()
|
||||
frappe.db.commit()
|
||||
return "Payment Entry created and submitted successfully."
|
||||
finally:
|
||||
# Reset to Guest user
|
||||
frappe.set_user("Guest")
|
||||
|
||||
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ def map_field_name(frontend_field):
|
||||
"job_status": "custom_job_status",
|
||||
"installation_address": "custom_installation_address",
|
||||
"warranty_id": "name",
|
||||
"customer": "customer_name",
|
||||
"customer": "customer",
|
||||
"fromCompany": "from_company",
|
||||
"warranty_status": "warranty_amc_status"
|
||||
}
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
import frappe
|
||||
|
||||
|
||||
def before_save(doc, method):
|
||||
print("DEBUG: Before save hook triggered for Customer:", doc.name)
|
||||
print("DEBUG: current state: ", doc.as_dict())
|
||||
@ -31,13 +31,13 @@ def before_insert(doc, method):
|
||||
print("DEBUG: CHECKING CUSTOMER NAME")
|
||||
print(doc.actual_customer_name)
|
||||
print("Quotation_to:", doc.quotation_to)
|
||||
doc.customer_address = frappe.get_value(doc.customer_type, doc.actual_customer_name, "customer_billing_address")
|
||||
doc.customer_address = frappe.get_value(doc.customer_type, doc.actual_customer_name, "custom_billing_address")
|
||||
# print("Party_type:", doc.party_type)
|
||||
if doc.custom_project_template == "SNW Install":
|
||||
print("DEBUG: Quotation uses SNW Install template, making sure no duplicate linked estimates.")
|
||||
address_doc = AddressService.get_or_throw(doc.custom_job_address)
|
||||
if "SNW Install" in [link.project_template for link in address_doc.quotations]:
|
||||
raise frappe.ValidationError("An Estimate with project template 'SNW Install' is already linked to this address.")
|
||||
# if "SNW Install" in [link.project_template for link in address_doc.quotations]:
|
||||
# raise frappe.ValidationError("An Estimate with project template 'SNW Install' is already linked to this address.")
|
||||
|
||||
def before_submit(doc, method):
|
||||
print("DEBUG: Before submit hook triggered for Quotation:", doc.name)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import frappe
|
||||
from custom_ui.services import AddressService, ClientService, ServiceAppointmentService, TaskService
|
||||
from custom_ui.services import SalesOrderService, AddressService, ClientService, ServiceAppointmentService, TaskService
|
||||
from datetime import timedelta
|
||||
import traceback
|
||||
|
||||
@ -50,7 +50,7 @@ def after_insert(doc, method):
|
||||
)
|
||||
if task_names:
|
||||
doc.save(ignore_permissions=True)
|
||||
TaskService.calculate_and_set_due_dates(task_names, "Created", current_triggering_dict=doc.as_dict())
|
||||
TaskService.fire_task_triggers(task_names, "Created", current_triggering_dict=doc.as_dict())
|
||||
|
||||
|
||||
|
||||
@ -62,6 +62,7 @@ def before_insert(doc, method):
|
||||
|
||||
def before_save(doc, method):
|
||||
print("DEBUG: Before Save Triggered for Project:", doc.name)
|
||||
print("DEBUG: Checking status: ", doc.status)
|
||||
if doc.expected_start_date and doc.expected_end_date:
|
||||
print("DEBUG: Project has expected start and end dates, marking as scheduled")
|
||||
doc.is_scheduled = 1
|
||||
@ -73,7 +74,7 @@ def before_save(doc, method):
|
||||
doc.is_scheduled = 0
|
||||
event = TaskService.determine_event(doc)
|
||||
if event:
|
||||
TaskService.calculate_and_set_due_dates(
|
||||
TaskService.fire_task_triggers(
|
||||
[task.task for task in doc.tasks],
|
||||
event,
|
||||
current_triggering_dict=doc.as_dict()
|
||||
@ -81,6 +82,18 @@ def before_save(doc, method):
|
||||
|
||||
def after_save(doc, method):
|
||||
print("DEBUG: After Save Triggered for Project:", doc.name)
|
||||
if doc.status == "Completed":
|
||||
print("DEBUG: Project marked as Completed. Generating and sending final invoice.")
|
||||
sales_order_status = frappe.get_value("Sales Order", doc.sales_order, "billing_status")
|
||||
if sales_order_status == "Not Billed":
|
||||
SalesOrderService.create_sales_invoice_from_sales_order(doc.sales_order)
|
||||
if doc.ready_to_schedule:
|
||||
service_apt_ready_to_schedule = frappe.get_value("Service Address 2", doc.service_appointment, "ready_to_schedule")
|
||||
if not service_apt_ready_to_schedule:
|
||||
print("DEBUG: Project is ready to schedule, setting Service Appointment to ready to schedule.")
|
||||
service_apt_doc = frappe.get_doc("Service Address 2", doc.service_appointment)
|
||||
service_apt_doc.ready_to_schedule = 1
|
||||
service_apt_doc.save(ignore_permissions=True)
|
||||
if doc.project_template == "SNW Install":
|
||||
print("DEBUG: Project template is SNW Install, updating Address Job Status based on Project status")
|
||||
status_mapping = {
|
||||
|
||||
16
custom_ui/events/payments.py
Normal file
16
custom_ui/events/payments.py
Normal file
@ -0,0 +1,16 @@
|
||||
import frappe
|
||||
|
||||
def on_submit(doc, method):
|
||||
print("DEBUG: On Submit Triggered for Payment Entry")
|
||||
is_advance_payment = any(ref.reference_doctype == "Sales Order" for ref in doc.references)
|
||||
if is_advance_payment:
|
||||
print("DEBUG: Payment Entry is for an advance payment, checking Sales Order if half down requirement is met.")
|
||||
so_ref = next((ref for ref in doc.references if ref.reference_doctype == "Sales Order"), None)
|
||||
if so_ref:
|
||||
so_doc = frappe.get_doc("Sales Order", so_ref.reference_name)
|
||||
if so_doc.requires_half_payment:
|
||||
is_paid = so_doc.custom_halfdown_amount <= so_doc.advance_paid or so_doc.advance_paid >= so_doc.grand_total / 2
|
||||
if is_paid and not so_doc.custom_halfdown_is_paid:
|
||||
print("DEBUG: Sales Order requires half payment and it has not been marked as paid, marking it as paid now.")
|
||||
so_doc.custom_halfdown_is_paid = 1
|
||||
so_doc.save()
|
||||
22
custom_ui/events/sales_invoice.py
Normal file
22
custom_ui/events/sales_invoice.py
Normal file
@ -0,0 +1,22 @@
|
||||
import frappe
|
||||
from custom_ui.services.email_service import EmailService
|
||||
|
||||
def on_submit(doc, method):
|
||||
print("DEBUG: On Submit Triggered for Sales Invoice:", doc.name)
|
||||
|
||||
# Send invoice email to customer
|
||||
try:
|
||||
print("DEBUG: Preparing to send invoice email for", doc.name)
|
||||
EmailService.send_invoice_email(doc.name)
|
||||
print("DEBUG: Invoice email sent successfully for", doc.name)
|
||||
frappe.set_value("Project", doc.project, "invoice_status", "Invoice Sent")
|
||||
except Exception as e:
|
||||
print(f"ERROR: Failed to send invoice email: {str(e)}")
|
||||
# Don't raise the exception - we don't want to block the invoice submission
|
||||
frappe.log_error(f"Failed to send invoice email for {doc.name}: {str(e)}", "Invoice Email Error")
|
||||
|
||||
def after_insert(doc, method):
|
||||
print("DEBUG: After Insert Triggered for Sales Invoice:", doc.name)
|
||||
# Additional logic can be added here if needed after invoice creation
|
||||
frappe.set_value("Project", doc.project, "invoice_status", "Invoice Created")
|
||||
|
||||
@ -71,6 +71,21 @@ def after_insert(doc, method):
|
||||
ClientService.append_link_v2(
|
||||
doc.customer, "sales_orders", {"sales_order": doc.name, "project_template": doc.custom_project_template}
|
||||
)
|
||||
|
||||
# Send down payment email if required
|
||||
if doc.requires_half_payment:
|
||||
try:
|
||||
print("DEBUG: Sales Order requires half payment, preparing to send down payment email")
|
||||
from custom_ui.services.email_service import EmailService
|
||||
|
||||
# Use EmailService to send the down payment email
|
||||
EmailService.send_downpayment_email(doc.name)
|
||||
|
||||
except Exception as e:
|
||||
print(f"ERROR: Failed to send down payment email: {str(e)}")
|
||||
# Don't raise the exception - we don't want to block the sales order creation
|
||||
frappe.log_error(f"Failed to send down payment email for {doc.name}: {str(e)}", "Down Payment Email Error")
|
||||
|
||||
|
||||
def on_update_after_submit(doc, method):
|
||||
print("DEBUG: on_update_after_submit hook triggered for Sales Order:", doc.name)
|
||||
@ -78,7 +93,9 @@ def on_update_after_submit(doc, method):
|
||||
project_is_scheduable = frappe.get_value("Project", doc.project, "ready_to_schedule")
|
||||
if not project_is_scheduable:
|
||||
print("DEBUG: Half-down payment made, setting Project to ready to schedule.")
|
||||
frappe.set_value("Project", doc.project, "ready_to_schedule", 1)
|
||||
project_doc = frappe.get_doc("Project", doc.project)
|
||||
project_doc.ready_to_schedule = 1
|
||||
project_doc.save()
|
||||
|
||||
|
||||
|
||||
@ -121,3 +138,4 @@ def create_sales_invoice_from_sales_order(doc, method):
|
||||
# except Exception as e:
|
||||
# print("ERROR creating Sales Invoice from Sales Order:", str(e))
|
||||
# frappe.log_error(f"Error creating Sales Invoice from Sales Order {doc.name}: {str(e)}", "Sales Order after_submit Error")
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ def on_update(doc, method):
|
||||
def after_insert(doc, method):
|
||||
print("DEBUG: After Insert Triggered for Service Appointment")
|
||||
task_names = [task.name for task in TaskService.get_tasks_by_project(doc.project)]
|
||||
TaskService.calculate_and_set_due_dates(task_names=task_names, event="Created", current_triggering_dict=doc.as_dict())
|
||||
TaskService.fire_task_triggers(task_names=task_names, event="Created", current_triggering_dict=doc.as_dict())
|
||||
|
||||
def before_save(doc, method):
|
||||
print("DEBUG: Before Save Triggered for Service Appointment")
|
||||
@ -28,4 +28,6 @@ def before_save(doc, method):
|
||||
event = TaskService.determine_event(doc)
|
||||
if event:
|
||||
task_names = [task.name for task in TaskService.get_tasks_by_project(doc.project)]
|
||||
TaskService.calculate_and_set_due_dates(task_names=task_names, event=event, current_triggering_dict=doc.as_dict())
|
||||
TaskService.fire_task_triggers(task_names=task_names, event=event, current_triggering_dict=doc.as_dict())
|
||||
if doc.status == "Completed" and frappe.get_value("Service Address 2", doc.name, "status") != "Completed":
|
||||
frappe.set_value("Project", doc.project, "invoice_status", "Ready to Invoice")
|
||||
@ -23,12 +23,33 @@ def after_insert(doc, method):
|
||||
doc.customer, "tasks", {"task": doc.name, "project_template": doc.project_template }
|
||||
)
|
||||
task_names = [task.name for task in TaskService.get_tasks_by_project(doc.project)]
|
||||
TaskService.calculate_and_set_due_dates(task_names, "Created", current_triggering_dict=doc.as_dict())
|
||||
TaskService.fire_task_triggers(task_names, "Created", current_triggering_dict=doc.as_dict())
|
||||
|
||||
def before_save(doc, method):
|
||||
print("DEBUG: Before Save Triggered for Task:", doc.name)
|
||||
task_type_weight = frappe.get_value("Task Type", doc.type, "weight") or 0
|
||||
if doc.task_weight != task_type_weight:
|
||||
print(f"DEBUG: Updating Task weight from {doc.task_weight} to {task_type_weight}")
|
||||
doc.task_weight = task_type_weight
|
||||
event = TaskService.determine_event(doc)
|
||||
if event:
|
||||
task_names = [task.name for task in TaskService.get_tasks_by_project(doc.project)]
|
||||
TaskService.calculate_and_set_due_dates(task_names, event, current_triggering_dict=doc.as_dict())
|
||||
|
||||
TaskService.fire_task_triggers(task_names, event, current_triggering_dict=doc.as_dict())
|
||||
|
||||
def after_save(doc, method):
|
||||
print("DEBUG: After Save Triggered for Task:", doc.name)
|
||||
if doc.project and doc.status == "Completed":
|
||||
print("DEBUG: Task is completed, checking if project has calculated 100% Progress.")
|
||||
project_doc = frappe.get_doc("Project", doc.project)
|
||||
if project_doc.percent_complete == 100:
|
||||
project_update_required = False
|
||||
if project_doc.status == "Completed" and project_doc.customCompletionDate is None:
|
||||
print("DEBUG: Project is marked as Completed but customCompletionDate is not set, updating customCompletionDate.")
|
||||
project_doc.customCompletionDate = frappe.utils.nowdate()
|
||||
project_update_required = True
|
||||
if project_doc.invoice_status == "Not Ready":
|
||||
project_doc.invoice_status = "Ready to Invoice"
|
||||
project_update_required = True
|
||||
if project_update_required:
|
||||
project_doc.save(ignore_permissions=True)
|
||||
print("DEBUG: Updated Project document after Task completion")
|
||||
@ -1,116 +1 @@
|
||||
[
|
||||
{
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "Address",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 0,
|
||||
"fieldname": "custom_subdivision",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_preview": 0,
|
||||
"in_standard_filter": 0,
|
||||
"insert_after": "custom_linked_city",
|
||||
"is_system_generated": 0,
|
||||
"is_virtual": 0,
|
||||
"label": "Subdivision",
|
||||
"length": 0,
|
||||
"link_filters": null,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2026-01-30 08:27:37.157366",
|
||||
"module": "Custom UI",
|
||||
"name": "Address-custom_subdivision",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": "Territory",
|
||||
"permlevel": 0,
|
||||
"placeholder": null,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"show_dashboard": 0,
|
||||
"sort_options": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
},
|
||||
{
|
||||
"allow_in_quick_entry": 1,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"collapsible_depends_on": null,
|
||||
"columns": 0,
|
||||
"default": null,
|
||||
"depends_on": null,
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Custom Field",
|
||||
"dt": "Address",
|
||||
"fetch_from": null,
|
||||
"fetch_if_empty": 1,
|
||||
"fieldname": "custom_customer_to_bill",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"hide_border": 0,
|
||||
"hide_days": 0,
|
||||
"hide_seconds": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_preview": 1,
|
||||
"in_standard_filter": 1,
|
||||
"insert_after": "custom_column_break_rrto0",
|
||||
"is_system_generated": 0,
|
||||
"is_virtual": 0,
|
||||
"label": "Customer to Bill",
|
||||
"length": 0,
|
||||
"link_filters": null,
|
||||
"mandatory_depends_on": null,
|
||||
"modified": "2026-01-30 09:05:24.498640",
|
||||
"module": "Custom UI",
|
||||
"name": "Address-custom_customer_to_bill",
|
||||
"no_copy": 0,
|
||||
"non_negative": 0,
|
||||
"options": "Customer",
|
||||
"permlevel": 0,
|
||||
"placeholder": null,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"print_width": null,
|
||||
"read_only": 0,
|
||||
"read_only_depends_on": null,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"show_dashboard": 0,
|
||||
"sort_options": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0,
|
||||
"width": null
|
||||
}
|
||||
]
|
||||
[]
|
||||
@ -1 +1,12 @@
|
||||
[]
|
||||
[
|
||||
{
|
||||
"docstatus": 0,
|
||||
"doctype": "Email Template",
|
||||
"modified": "2026-01-24 07:18:15.939258",
|
||||
"name": "Customer Invoice",
|
||||
"response": "<div class=\"ql-editor read-mode\"><p>-- Copywriting goes here --</p><p>-- Customized Payment Link goes here --</p><p>-- In the meantime --</p><p>Invoice number: {{ name }}</p><p>Amount: {{ grand_total }}</p><p>https://sprinklersnorthwest.com/product/bill-pay/</p></div>",
|
||||
"response_html": null,
|
||||
"subject": "Your Invoice is Ready",
|
||||
"use_html": 0
|
||||
}
|
||||
]
|
||||
@ -1,10 +1,12 @@
|
||||
[
|
||||
{
|
||||
"bid_meeting_note_form": null,
|
||||
"calendar_color": null,
|
||||
"company": "Sprinklers Northwest",
|
||||
"docstatus": 0,
|
||||
"doctype": "Project Template",
|
||||
"modified": "2026-01-27 09:16:15.614554",
|
||||
"item_groups": null,
|
||||
"modified": "2026-01-29 09:51:46.681553",
|
||||
"name": "SNW Install",
|
||||
"project_type": "External",
|
||||
"tasks": [
|
||||
@ -51,5 +53,25 @@
|
||||
"task": "TASK-2025-00006"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"bid_meeting_note_form": null,
|
||||
"calendar_color": null,
|
||||
"company": "Sprinklers Northwest",
|
||||
"docstatus": 0,
|
||||
"doctype": "Project Template",
|
||||
"item_groups": null,
|
||||
"modified": "2026-01-08 10:36:39.245470",
|
||||
"name": "Other",
|
||||
"project_type": null,
|
||||
"tasks": [
|
||||
{
|
||||
"parent": "Other",
|
||||
"parentfield": "tasks",
|
||||
"parenttype": "Project Template",
|
||||
"subject": "Primary Job",
|
||||
"task": "TASK-2025-00004"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@ -10,6 +10,7 @@
|
||||
"completed_on": null,
|
||||
"custom_foreman": "HR-EMP-00014",
|
||||
"custom_property": null,
|
||||
"customer": null,
|
||||
"department": null,
|
||||
"depends_on": [],
|
||||
"depends_on_tasks": "",
|
||||
@ -54,6 +55,7 @@
|
||||
"completed_on": null,
|
||||
"custom_foreman": null,
|
||||
"custom_property": null,
|
||||
"customer": null,
|
||||
"department": null,
|
||||
"depends_on": [],
|
||||
"depends_on_tasks": "",
|
||||
@ -98,50 +100,7 @@
|
||||
"completed_on": null,
|
||||
"custom_foreman": null,
|
||||
"custom_property": null,
|
||||
"department": null,
|
||||
"depends_on": [],
|
||||
"depends_on_tasks": "",
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Task",
|
||||
"duration": 0,
|
||||
"exp_end_date": null,
|
||||
"exp_start_date": null,
|
||||
"expected_time": 0.0,
|
||||
"is_group": 0,
|
||||
"is_milestone": 0,
|
||||
"is_template": 1,
|
||||
"issue": null,
|
||||
"modified": "2025-05-08 13:04:15.934399",
|
||||
"name": "TASK-2025-00001",
|
||||
"old_parent": "",
|
||||
"parent_task": null,
|
||||
"priority": "Low",
|
||||
"progress": 0.0,
|
||||
"project": null,
|
||||
"project_template": null,
|
||||
"review_date": null,
|
||||
"start": 0,
|
||||
"status": "Template",
|
||||
"subject": "Send customer 3-5 day window for start date",
|
||||
"task_weight": 0.0,
|
||||
"template_task": null,
|
||||
"total_billing_amount": 0.0,
|
||||
"total_costing_amount": 0.0,
|
||||
"total_expense_claim": 0.0,
|
||||
"type": "Admin"
|
||||
},
|
||||
{
|
||||
"act_end_date": null,
|
||||
"act_start_date": null,
|
||||
"actual_time": 0.0,
|
||||
"closing_date": null,
|
||||
"color": null,
|
||||
"company": "Sprinklers Northwest",
|
||||
"completed_by": null,
|
||||
"completed_on": null,
|
||||
"custom_foreman": null,
|
||||
"custom_property": null,
|
||||
"customer": null,
|
||||
"department": null,
|
||||
"depends_on": [],
|
||||
"depends_on_tasks": "",
|
||||
@ -186,6 +145,7 @@
|
||||
"completed_on": null,
|
||||
"custom_foreman": null,
|
||||
"custom_property": null,
|
||||
"customer": null,
|
||||
"department": null,
|
||||
"depends_on": [],
|
||||
"depends_on_tasks": "",
|
||||
@ -230,6 +190,7 @@
|
||||
"completed_on": null,
|
||||
"custom_foreman": null,
|
||||
"custom_property": null,
|
||||
"customer": null,
|
||||
"department": null,
|
||||
"depends_on": [],
|
||||
"depends_on_tasks": "",
|
||||
@ -244,8 +205,8 @@
|
||||
"is_milestone": 0,
|
||||
"is_template": 1,
|
||||
"issue": null,
|
||||
"modified": "2025-05-10 05:06:24.653035",
|
||||
"name": "TASK-2025-00004",
|
||||
"modified": "2025-05-10 05:06:35.232465",
|
||||
"name": "TASK-2025-00005",
|
||||
"old_parent": "",
|
||||
"parent_task": null,
|
||||
"priority": "Low",
|
||||
@ -255,7 +216,7 @@
|
||||
"review_date": null,
|
||||
"start": 0,
|
||||
"status": "Template",
|
||||
"subject": "Primary Job",
|
||||
"subject": "Hydroseeding",
|
||||
"task_weight": 0.0,
|
||||
"template_task": null,
|
||||
"total_billing_amount": 0.0,
|
||||
@ -274,6 +235,7 @@
|
||||
"completed_on": null,
|
||||
"custom_foreman": null,
|
||||
"custom_property": null,
|
||||
"customer": null,
|
||||
"department": null,
|
||||
"depends_on": [],
|
||||
"depends_on_tasks": "",
|
||||
@ -318,6 +280,7 @@
|
||||
"completed_on": null,
|
||||
"custom_foreman": null,
|
||||
"custom_property": null,
|
||||
"customer": null,
|
||||
"department": null,
|
||||
"depends_on": [],
|
||||
"depends_on_tasks": "",
|
||||
@ -332,8 +295,8 @@
|
||||
"is_milestone": 0,
|
||||
"is_template": 1,
|
||||
"issue": null,
|
||||
"modified": "2025-05-10 05:06:35.232465",
|
||||
"name": "TASK-2025-00005",
|
||||
"modified": "2025-05-08 13:04:15.934399",
|
||||
"name": "TASK-2025-00001",
|
||||
"old_parent": "",
|
||||
"parent_task": null,
|
||||
"priority": "Low",
|
||||
@ -343,7 +306,52 @@
|
||||
"review_date": null,
|
||||
"start": 0,
|
||||
"status": "Template",
|
||||
"subject": "Hydroseeding",
|
||||
"subject": "Send customer 3-5 day window for start date",
|
||||
"task_weight": 0.0,
|
||||
"template_task": null,
|
||||
"total_billing_amount": 0.0,
|
||||
"total_costing_amount": 0.0,
|
||||
"total_expense_claim": 0.0,
|
||||
"type": "Admin"
|
||||
},
|
||||
{
|
||||
"act_end_date": null,
|
||||
"act_start_date": null,
|
||||
"actual_time": 0.0,
|
||||
"closing_date": null,
|
||||
"color": null,
|
||||
"company": "Sprinklers Northwest",
|
||||
"completed_by": null,
|
||||
"completed_on": null,
|
||||
"custom_foreman": null,
|
||||
"custom_property": null,
|
||||
"customer": null,
|
||||
"department": null,
|
||||
"depends_on": [],
|
||||
"depends_on_tasks": "",
|
||||
"description": null,
|
||||
"docstatus": 0,
|
||||
"doctype": "Task",
|
||||
"duration": 0,
|
||||
"exp_end_date": null,
|
||||
"exp_start_date": null,
|
||||
"expected_time": 0.0,
|
||||
"is_group": 0,
|
||||
"is_milestone": 0,
|
||||
"is_template": 1,
|
||||
"issue": null,
|
||||
"modified": "2025-05-10 05:06:24.653035",
|
||||
"name": "TASK-2025-00004",
|
||||
"old_parent": "",
|
||||
"parent_task": null,
|
||||
"priority": "Low",
|
||||
"progress": 0.0,
|
||||
"project": null,
|
||||
"project_template": null,
|
||||
"review_date": null,
|
||||
"start": 0,
|
||||
"status": "Template",
|
||||
"subject": "Primary Job",
|
||||
"task_weight": 0.0,
|
||||
"template_task": null,
|
||||
"total_billing_amount": 0.0,
|
||||
|
||||
@ -205,6 +205,12 @@ doc_events = {
|
||||
"before_save": "custom_ui.events.service_appointment.before_save",
|
||||
"after_insert": "custom_ui.events.service_appointment.after_insert",
|
||||
"on_update": "custom_ui.events.service_appointment.on_update"
|
||||
},
|
||||
"Payment Entry": {
|
||||
"on_submit": "custom_ui.events.payments.on_submit"
|
||||
},
|
||||
"Sales Invoice": {
|
||||
"on_submit": "custom_ui.events.sales_invoice.on_submit"
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,13 +244,13 @@ fixtures = [
|
||||
# Scheduled Tasks
|
||||
# ---------------
|
||||
|
||||
# scheduler_events = {
|
||||
scheduler_events = {
|
||||
# "all": [
|
||||
# "custom_ui.tasks.all"
|
||||
# ],
|
||||
# "daily": [
|
||||
# "custom_ui.tasks.daily"
|
||||
# ],
|
||||
"daily": [
|
||||
"custom_ui.scheduled_tasks.daily"
|
||||
],
|
||||
# "hourly": [
|
||||
# "custom_ui.tasks.hourly"
|
||||
# ],
|
||||
@ -254,7 +260,7 @@ fixtures = [
|
||||
# "monthly": [
|
||||
# "custom_ui.tasks.monthly"
|
||||
# ],
|
||||
# }
|
||||
}
|
||||
|
||||
# Testing
|
||||
# -------
|
||||
|
||||
@ -49,6 +49,8 @@ def after_migrate():
|
||||
create_task_types()
|
||||
# create_tasks()
|
||||
create_bid_meeting_note_form_templates()
|
||||
create_accounts()
|
||||
# init_stripe_accounts()
|
||||
|
||||
# update_address_fields()
|
||||
# build_frontend()
|
||||
@ -844,3 +846,58 @@ def create_bid_meeting_note_form_templates():
|
||||
)
|
||||
|
||||
doc.insert(ignore_permissions=True)
|
||||
|
||||
def create_accounts():
|
||||
"""Create necessary accounts if they do not exist."""
|
||||
print("\n🔧 Checking for necessary accounts...")
|
||||
|
||||
accounts = [
|
||||
{
|
||||
"Sprinklers Northwest": [
|
||||
{
|
||||
"account_name": "Stripe Clearing - Sprinklers Northwest",
|
||||
"account_type": "Bank",
|
||||
"parent_account": "Bank Accounts - S",
|
||||
"company": "Sprinklers Northwest"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
for company_accounts in accounts:
|
||||
for company, account_list in company_accounts.items():
|
||||
for account in account_list:
|
||||
# Idempotency check
|
||||
if frappe.db.exists("Account", {"account_name": account["account_name"], "company": account["company"]}):
|
||||
continue
|
||||
doc = frappe.get_doc({
|
||||
"doctype": "Account",
|
||||
"account_name": account["account_name"],
|
||||
"account_type": account["account_type"],
|
||||
"company": account["company"],
|
||||
"parent_account": account["parent_account"],
|
||||
"is_group": 0
|
||||
})
|
||||
doc.insert(ignore_permissions=True, ignore_if_duplicate=True)
|
||||
|
||||
frappe.db.commit()
|
||||
|
||||
def init_stripe_accounts():
|
||||
"""Initializes the bare configurations for each Stripe Settings doctypes."""
|
||||
print("\n🔧 Initializing Stripe Settings for companies...")
|
||||
|
||||
companies = ["Sprinklers Northwest"]
|
||||
|
||||
for company in companies:
|
||||
if not frappe.db.exists("Stripe Settings", {"company": company}):
|
||||
doc = frappe.get_doc({
|
||||
"doctype": "Stripe Settings",
|
||||
"company": company,
|
||||
"api_key": "",
|
||||
"publishable_key": "",
|
||||
"webhook_secret": "",
|
||||
"account": f"Stripe Clearing - {company}"
|
||||
})
|
||||
doc.insert(ignore_permissions=True)
|
||||
|
||||
frappe.db.commit()
|
||||
|
||||
2
custom_ui/models/__init__.py
Normal file
2
custom_ui/models/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from .payments import PaymentData
|
||||
from .item_models import BOMItem, PackageCreationData
|
||||
18
custom_ui/models/item_models.py
Normal file
18
custom_ui/models/item_models.py
Normal file
@ -0,0 +1,18 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
@dataclass
|
||||
class BOMItem:
|
||||
item_code: str
|
||||
qty: float
|
||||
uom: str
|
||||
item_name: str = None
|
||||
|
||||
@dataclass
|
||||
class PackageCreationData:
|
||||
package_name: str
|
||||
items: list[BOMItem]
|
||||
item_group: str
|
||||
code_prefix: str
|
||||
rate: float = 0.0
|
||||
company: str = None
|
||||
description: str = None
|
||||
10
custom_ui/models/payments.py
Normal file
10
custom_ui/models/payments.py
Normal file
@ -0,0 +1,10 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
@dataclass
|
||||
class PaymentData:
|
||||
mode_of_payment: str
|
||||
reference_no: str
|
||||
reference_date: str
|
||||
received_amount: float
|
||||
company: str = None
|
||||
reference_doc_name: str = None
|
||||
8
custom_ui/scheduled_tasks.py
Normal file
8
custom_ui/scheduled_tasks.py
Normal file
@ -0,0 +1,8 @@
|
||||
import frappe
|
||||
from custom_ui.services import TaskService
|
||||
|
||||
def daily_task():
|
||||
"""Scheduled task to run daily."""
|
||||
print("#################### Running Daily Task ####################")
|
||||
print("DEBUG: Checking Task due dates")
|
||||
TaskService.find_and_update_overdue_tasks()
|
||||
@ -6,4 +6,9 @@ from .estimate_service import EstimateService
|
||||
from .onsite_meeting_service import OnSiteMeetingService
|
||||
from .task_service import TaskService
|
||||
from .service_appointment_service import ServiceAppointmentService
|
||||
from .stripe_service import StripeService
|
||||
from .stripe_service import StripeService
|
||||
from .payment_service import PaymentService
|
||||
from .item_service import ItemService
|
||||
from .project_service import ProjectService
|
||||
from .sales_order_service import SalesOrderService
|
||||
from .email_service import EmailService
|
||||
@ -186,6 +186,7 @@ class AddressService:
|
||||
address_doc.append(field, link)
|
||||
print("DEBUG: Saving address document after appending link.")
|
||||
address_doc.save(ignore_permissions=True)
|
||||
frappe.db.commit()
|
||||
print(f"DEBUG: Set link field {field} for Address {address_name} with link data {link}")
|
||||
|
||||
@staticmethod
|
||||
|
||||
@ -55,6 +55,7 @@ class ClientService:
|
||||
client_doc.append(field, link)
|
||||
print("DEBUG: Saving client document after appending link.")
|
||||
client_doc.save(ignore_permissions=True)
|
||||
frappe.db.commit()
|
||||
print(f"DEBUG: Set link field {field} for client {client_doc.get('name')} with link data {link}")
|
||||
|
||||
@staticmethod
|
||||
@ -91,6 +92,7 @@ class ClientService:
|
||||
try:
|
||||
print(f"DEBUG: Processing address: {address.get('address')}")
|
||||
ClientService.append_link_v2(customer_doc.name, "properties", {"address": address.get("address")})
|
||||
customer_doc.reload()
|
||||
address_doc = AddressService.get_or_throw(address.get("address"))
|
||||
AddressService.link_address_to_customer(address_doc, "Customer", customer_doc.name)
|
||||
print(f"DEBUG: Linked address {address.get('address')} to customer")
|
||||
@ -104,6 +106,7 @@ class ClientService:
|
||||
try:
|
||||
print(f"DEBUG: Processing contact: {contact.get('contact')}")
|
||||
ClientService.append_link_v2(customer_doc.name, "contacts", {"contact": contact.get("contact")})
|
||||
customer_doc.reload()
|
||||
contact_doc = ContactService.get_or_throw(contact.get("contact"))
|
||||
ContactService.link_contact_to_customer(contact_doc, "Customer", customer_doc.name)
|
||||
print(f"DEBUG: Linked contact {contact.get('contact')} to customer")
|
||||
@ -117,6 +120,7 @@ class ClientService:
|
||||
try:
|
||||
print(f"DEBUG: Processing quotation: {quotation.get('quotation')}")
|
||||
ClientService.append_link_v2(customer_doc.name, "quotations", {"quotation": quotation.get("quotation")})
|
||||
customer_doc.reload()
|
||||
quotation_doc = EstimateService.get_or_throw(quotation.get("quotation"))
|
||||
EstimateService.link_estimate_to_customer(quotation_doc, "Customer", customer_doc.name)
|
||||
print(f"DEBUG: Linked quotation {quotation.get('quotation')} to customer")
|
||||
@ -130,6 +134,7 @@ class ClientService:
|
||||
print(f"DEBUG: Processing onsite meeting: {meeting.get('onsite_meeting')}")
|
||||
meeting_doc = DbService.get_or_throw("On-Site Meeting",meeting.get("onsite_meeting"))
|
||||
ClientService.append_link_v2(customer_doc.name, "onsite_meetings", {"onsite_meeting": meeting.get("onsite_meeting")})
|
||||
customer_doc.reload()
|
||||
OnSiteMeetingService.link_onsite_meeting_to_customer(meeting_doc, "Customer", customer_doc.name)
|
||||
print(f"DEBUG: Linked onsite meeting {meeting.get('onsite_meeting')} to customer")
|
||||
except Exception as e:
|
||||
@ -141,11 +146,13 @@ class ClientService:
|
||||
try:
|
||||
print(f"DEBUG: Processing company: {company.get('company')}")
|
||||
ClientService.append_link_v2(customer_doc.name, "companies", {"company": company.get("company")})
|
||||
customer_doc.reload()
|
||||
print(f"DEBUG: Linked company {company.get('company')} to customer")
|
||||
except Exception as e:
|
||||
print(f"ERROR: Failed to link company {company.get('company')}: {str(e)}")
|
||||
frappe.log_error(f"Company linking error: {str(e)}", "convert_lead_to_customer")
|
||||
print(f"DEBUG: Converted Lead {lead_name} to Customer {customer_doc.name}")
|
||||
frappe.db.commit()
|
||||
return customer_doc
|
||||
|
||||
except Exception as e:
|
||||
|
||||
240
custom_ui/services/email_service.py
Normal file
240
custom_ui/services/email_service.py
Normal file
@ -0,0 +1,240 @@
|
||||
import frappe
|
||||
from frappe.utils import get_url
|
||||
|
||||
class EmailService:
|
||||
|
||||
@staticmethod
|
||||
def get_customer_email(customer_name: str, doctype: str = "Customer") -> str | None:
|
||||
"""
|
||||
Get the primary email for a customer or lead.
|
||||
|
||||
Args:
|
||||
customer_name: Name of the Customer or Lead
|
||||
doctype: Either "Customer" or "Lead"
|
||||
|
||||
Returns:
|
||||
Email address if found, None otherwise
|
||||
"""
|
||||
try:
|
||||
customer_doc = frappe.get_doc(doctype, customer_name)
|
||||
email = None
|
||||
|
||||
# Try primary_contact field
|
||||
if hasattr(customer_doc, 'primary_contact') and customer_doc.primary_contact:
|
||||
try:
|
||||
primary_contact = frappe.get_doc("Contact", customer_doc.primary_contact)
|
||||
email = primary_contact.email_id
|
||||
except Exception as e:
|
||||
print(f"Warning: Could not get primary_contact: {str(e)}")
|
||||
|
||||
# Fallback to customer_primary_contact
|
||||
if not email and hasattr(customer_doc, 'customer_primary_contact') and customer_doc.customer_primary_contact:
|
||||
try:
|
||||
primary_contact = frappe.get_doc("Contact", customer_doc.customer_primary_contact)
|
||||
email = primary_contact.email_id
|
||||
except Exception as e:
|
||||
print(f"Warning: Could not get customer_primary_contact: {str(e)}")
|
||||
|
||||
# Last resort - get any contact linked to this customer/lead
|
||||
if not email:
|
||||
contact_links = frappe.get_all("Dynamic Link",
|
||||
filters={
|
||||
"link_doctype": doctype,
|
||||
"link_name": customer_name,
|
||||
"parenttype": "Contact"
|
||||
},
|
||||
pluck="parent"
|
||||
)
|
||||
if contact_links:
|
||||
try:
|
||||
contact = frappe.get_doc("Contact", contact_links[0])
|
||||
email = contact.email_id
|
||||
except Exception as e:
|
||||
print(f"Warning: Could not get contact from dynamic link: {str(e)}")
|
||||
|
||||
return email
|
||||
|
||||
except Exception as e:
|
||||
print(f"ERROR: Failed to get email for {doctype} {customer_name}: {str(e)}")
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def send_templated_email(
|
||||
recipients: str | list,
|
||||
subject: str,
|
||||
template_path: str,
|
||||
template_context: dict,
|
||||
doctype: str = None,
|
||||
docname: str = None,
|
||||
cc: str | list = None,
|
||||
bcc: str | list = None,
|
||||
attachments: list = None
|
||||
) -> bool:
|
||||
"""
|
||||
Send an email using a Jinja2 template.
|
||||
|
||||
Args:
|
||||
recipients: Email address(es) to send to
|
||||
subject: Email subject line
|
||||
template_path: Path to the Jinja2 template (relative to app root)
|
||||
template_context: Dictionary of variables to pass to template
|
||||
doctype: Optional doctype to link email to
|
||||
docname: Optional document name to link email to
|
||||
cc: Optional CC recipients
|
||||
bcc: Optional BCC recipients
|
||||
attachments: Optional list of attachments
|
||||
|
||||
Returns:
|
||||
True if email sent successfully, False otherwise
|
||||
"""
|
||||
try:
|
||||
# Render the email template
|
||||
message = frappe.render_template(template_path, template_context)
|
||||
|
||||
# Prepare sendmail arguments
|
||||
email_args = {
|
||||
"recipients": recipients,
|
||||
"subject": subject,
|
||||
"message": message,
|
||||
}
|
||||
|
||||
if doctype:
|
||||
email_args["doctype"] = doctype
|
||||
if docname:
|
||||
email_args["name"] = docname
|
||||
if cc:
|
||||
email_args["cc"] = cc
|
||||
if bcc:
|
||||
email_args["bcc"] = bcc
|
||||
if attachments:
|
||||
email_args["attachments"] = attachments
|
||||
|
||||
# Send email
|
||||
frappe.sendmail(**email_args)
|
||||
|
||||
print(f"DEBUG: Email sent successfully to {recipients}")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"ERROR: Failed to send email: {str(e)}")
|
||||
frappe.log_error(f"Failed to send email to {recipients}: {str(e)}", "Email Service Error")
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def send_downpayment_email(sales_order_name: str) -> bool:
|
||||
"""
|
||||
Send a down payment email for a Sales Order.
|
||||
|
||||
Args:
|
||||
sales_order_name: Name of the Sales Order
|
||||
|
||||
Returns:
|
||||
True if email sent successfully, False otherwise
|
||||
"""
|
||||
try:
|
||||
doc = frappe.get_doc("Sales Order", sales_order_name)
|
||||
|
||||
# Get customer email
|
||||
email = EmailService.get_customer_email(doc.customer, "Customer")
|
||||
|
||||
if not email:
|
||||
print(f"ERROR: No email found for customer {doc.customer}, cannot send down payment email")
|
||||
return False
|
||||
|
||||
# Prepare template context
|
||||
half_down_amount = doc.custom_halfdown_amount or (doc.grand_total / 2)
|
||||
base_url = get_url()
|
||||
|
||||
template_context = {
|
||||
"company_name": doc.company,
|
||||
"customer_name": doc.customer_name or doc.customer,
|
||||
"sales_order_number": doc.name,
|
||||
"total_amount": frappe.utils.fmt_money(half_down_amount, currency=doc.currency),
|
||||
"base_url": base_url
|
||||
}
|
||||
|
||||
# Send email
|
||||
template_path = "custom_ui/templates/emails/downpayment.html"
|
||||
subject = f"Down Payment Required - {doc.company} - {doc.name}"
|
||||
|
||||
return EmailService.send_templated_email(
|
||||
recipients=email,
|
||||
subject=subject,
|
||||
template_path=template_path,
|
||||
template_context=template_context,
|
||||
doctype="Sales Order",
|
||||
docname=doc.name
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
print(f"ERROR: Failed to send down payment email for {sales_order_name}: {str(e)}")
|
||||
frappe.log_error(f"Failed to send down payment email for {sales_order_name}: {str(e)}", "Down Payment Email Error")
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def send_invoice_email(sales_invoice_name: str) -> bool:
|
||||
"""
|
||||
Send an invoice email for a Sales Invoice.
|
||||
|
||||
Args:
|
||||
sales_invoice_name: Name of the Sales Invoice
|
||||
|
||||
Returns:
|
||||
True if email sent successfully, False otherwise
|
||||
"""
|
||||
try:
|
||||
doc = frappe.get_doc("Sales Invoice", sales_invoice_name)
|
||||
|
||||
# Get customer email
|
||||
email = EmailService.get_customer_email(doc.customer, "Customer")
|
||||
|
||||
if not email:
|
||||
print(f"ERROR: No email found for customer {doc.customer}, cannot send invoice email")
|
||||
return False
|
||||
|
||||
# Calculate amounts
|
||||
outstanding_amount = doc.outstanding_amount
|
||||
paid_amount = doc.grand_total - outstanding_amount
|
||||
|
||||
# Get related Sales Order if available
|
||||
sales_order = None
|
||||
if hasattr(doc, 'items') and doc.items:
|
||||
for item in doc.items:
|
||||
if item.sales_order:
|
||||
sales_order = item.sales_order
|
||||
break
|
||||
|
||||
# Prepare template context
|
||||
base_url = get_url()
|
||||
|
||||
template_context = {
|
||||
"company_name": doc.company,
|
||||
"customer_name": doc.customer_name or doc.customer,
|
||||
"invoice_number": doc.name,
|
||||
"invoice_date": doc.posting_date,
|
||||
"due_date": doc.due_date,
|
||||
"grand_total": frappe.utils.fmt_money(doc.grand_total, currency=doc.currency),
|
||||
"outstanding_amount": frappe.utils.fmt_money(outstanding_amount, currency=doc.currency),
|
||||
"paid_amount": frappe.utils.fmt_money(paid_amount, currency=doc.currency),
|
||||
"sales_order": sales_order,
|
||||
"base_url": base_url,
|
||||
"payment_url": f"{base_url}/api/method/custom_ui.api.public.payments.invoice_stripe_payment?sales_invoice={doc.name}" if outstanding_amount > 0 else None
|
||||
}
|
||||
|
||||
# Send email
|
||||
template_path = "custom_ui/templates/emails/invoice.html"
|
||||
subject = f"Invoice {doc.name} - {doc.company}"
|
||||
|
||||
return EmailService.send_templated_email(
|
||||
recipients=email,
|
||||
subject=subject,
|
||||
template_path=template_path,
|
||||
template_context=template_context,
|
||||
doctype="Sales Invoice",
|
||||
docname=doc.name
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
print(f"ERROR: Failed to send invoice email for {sales_invoice_name}: {str(e)}")
|
||||
frappe.log_error(f"Failed to send invoice email for {sales_invoice_name}: {str(e)}", "Invoice Email Error")
|
||||
return False
|
||||
@ -1,4 +1,5 @@
|
||||
import frappe
|
||||
from .item_service import ItemService
|
||||
|
||||
class EstimateService:
|
||||
|
||||
@ -21,6 +22,7 @@ class EstimateService:
|
||||
print("DEBUG: Quotation document not found.")
|
||||
return None
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_or_throw(estimate_name: str) -> frappe._dict:
|
||||
"""Retrieve a Quotation document by name or throw an error if not found."""
|
||||
@ -93,4 +95,18 @@ class EstimateService:
|
||||
estimate_doc.customer = customer_name
|
||||
estimate_doc.save(ignore_permissions=True)
|
||||
print(f"DEBUG: Linked Quotation {estimate_doc.name} to {customer_type} {customer_name}")
|
||||
|
||||
|
||||
@staticmethod
|
||||
def map_project_template_to_filter(project_template: str = None) -> dict | None:
|
||||
"""Map a project template to a filter."""
|
||||
print(f"DEBUG: Mapping project template {project_template} to quotation category")
|
||||
if not project_template:
|
||||
print("DEBUG: No project template provided, defaulting to 'General'")
|
||||
return None
|
||||
mapping = {
|
||||
# SNW Install is both Irrigation and SNW-S categories
|
||||
"SNW Install": ["in", ["Irrigation", "SNW-S", "Landscaping"]],
|
||||
}
|
||||
category = mapping.get(project_template, "General")
|
||||
print(f"DEBUG: Mapped to quotation category: {category}")
|
||||
return { "item_group": category }
|
||||
204
custom_ui/services/item_service.py
Normal file
204
custom_ui/services/item_service.py
Normal file
@ -0,0 +1,204 @@
|
||||
import frappe
|
||||
|
||||
class ItemService:
|
||||
|
||||
@staticmethod
|
||||
def get_item_category(item_code: str) -> str:
|
||||
"""Retrieve the category of an Item document by item code."""
|
||||
print(f"DEBUG: Getting category for Item {item_code}")
|
||||
category = frappe.db.get_value("Item", item_code, "item_group")
|
||||
print(f"DEBUG: Retrieved category: {category}")
|
||||
return category
|
||||
|
||||
@staticmethod
|
||||
def get_full_dict(item_code: str) -> frappe._dict:
|
||||
"""Retrieve the full Item document by item code."""
|
||||
print(f"DEBUG: Getting full document for Item {item_code}")
|
||||
item_doc = frappe.get_doc("Item", item_code).as_dict()
|
||||
item_doc["bom"] = ItemService.get_full_bom_dict(item_code) if item_doc.get("default_bom") else None
|
||||
return item_doc
|
||||
|
||||
@staticmethod
|
||||
def get_full_bom_dict(item_code: str):
|
||||
"""Retrieve the Bill of Materials (BOM) associated with an Item."""
|
||||
print(f"DEBUG: Getting BOM for Item {item_code}")
|
||||
bom_name = frappe.db.get_value("BOM", {"item": item_code, "is_active": 1}, "name")
|
||||
bom_dict = frappe.get_doc("BOM", bom_name).as_dict()
|
||||
for item in bom_dict.get('items', []):
|
||||
bom_no = item.get("bom_no")
|
||||
if bom_no:
|
||||
bom_item_code = frappe.db.get_value("BOM", bom_no, "item")
|
||||
item["bom"] = ItemService.get_full_bom_dict(bom_item_code)
|
||||
return bom_dict
|
||||
|
||||
@staticmethod
|
||||
def exists(item_code: str) -> bool:
|
||||
"""Check if an Item document exists by item code."""
|
||||
print(f"DEBUG: Checking existence of Item {item_code}")
|
||||
exists = frappe.db.exists("Item", item_code) is not None
|
||||
print(f"DEBUG: Item {item_code} exists: {exists}")
|
||||
return exists
|
||||
|
||||
@staticmethod
|
||||
def get_child_groups(item_group: str) -> list[str]:
|
||||
"""Retrieve all child item groups of a given item group."""
|
||||
print(f"DEBUG: Getting child groups for Item Group {item_group}")
|
||||
children = []
|
||||
child_groups = frappe.get_all("Item Group", filters={"parent_item_group": item_group}, pluck="name")
|
||||
if child_groups:
|
||||
children.extend(child_groups)
|
||||
print(f"DEBUG: Found child groups: {child_groups}. Checking for further children.")
|
||||
for child_group in child_groups:
|
||||
additional_child_groups = ItemService.get_child_groups(child_group)
|
||||
children.extend(additional_child_groups)
|
||||
|
||||
print(f"DEBUG: Retrieved child groups: {child_groups}")
|
||||
return children
|
||||
|
||||
@staticmethod
|
||||
def get_item_names_by_group(item_groups: set[str]) -> list[str]:
|
||||
"""Retrieve item names for items belonging to the specified item groups."""
|
||||
print(f"DEBUG: Getting item names for Item Groups {item_groups}")
|
||||
items = frappe.get_all("Item", filters={"item_group": ["in", list(item_groups)]}, pluck="name")
|
||||
print(f"DEBUG: Retrieved item names: {items}")
|
||||
return items
|
||||
|
||||
@staticmethod
|
||||
def get_items_by_groups(item_groups: list[str]) -> list[dict]:
|
||||
"""Retrieve all items belonging to the specified item groups."""
|
||||
print(f"DEBUG: Getting items for Item Groups {item_groups}")
|
||||
all_groups = set(item_groups)
|
||||
for group in item_groups:
|
||||
all_groups.update(ItemService.get_child_groups(group))
|
||||
|
||||
# Batch fetch all items at once with all needed fields
|
||||
items = frappe.get_all(
|
||||
"Item",
|
||||
filters={"item_group": ["in", list(all_groups)]},
|
||||
fields=[
|
||||
"name", "item_code", "item_name", "item_group", "description",
|
||||
"standard_rate", "stock_uom", "default_bom"
|
||||
]
|
||||
)
|
||||
|
||||
# Get all item codes that have BOMs
|
||||
items_with_boms = [item for item in items if item.get("default_bom")]
|
||||
item_codes_with_boms = [item["item_code"] for item in items_with_boms]
|
||||
|
||||
# Batch fetch all BOMs and their nested structure
|
||||
bom_dict = ItemService.batch_fetch_boms(item_codes_with_boms) if item_codes_with_boms else {}
|
||||
|
||||
# Attach BOMs to items
|
||||
for item in items:
|
||||
if item.get("default_bom"):
|
||||
item["bom"] = bom_dict.get(item["item_code"])
|
||||
else:
|
||||
item["bom"] = None
|
||||
|
||||
print(f"DEBUG: Retrieved {len(items)} items")
|
||||
return items
|
||||
|
||||
@staticmethod
|
||||
def batch_fetch_boms(item_codes: list[str]) -> dict:
|
||||
"""Batch fetch all BOMs and build nested structure efficiently."""
|
||||
if not item_codes:
|
||||
return {}
|
||||
|
||||
print(f"DEBUG: Batch fetching BOMs for {len(item_codes)} items")
|
||||
|
||||
# Fetch all active BOMs for the given items
|
||||
boms = frappe.get_all(
|
||||
"BOM",
|
||||
filters={"item": ["in", item_codes], "is_active": 1},
|
||||
fields=["name", "item"]
|
||||
)
|
||||
|
||||
if not boms:
|
||||
return {}
|
||||
|
||||
bom_names = [bom["name"] for bom in boms]
|
||||
|
||||
# Fetch all BOM items (children) in one query
|
||||
bom_items = frappe.get_all(
|
||||
"BOM Item",
|
||||
filters={"parent": ["in", bom_names]},
|
||||
fields=["parent", "item_code", "item_name", "qty", "uom", "bom_no"],
|
||||
order_by="idx"
|
||||
)
|
||||
|
||||
# Group BOM items by their parent BOM
|
||||
bom_items_map = {}
|
||||
nested_bom_items = set()
|
||||
|
||||
for bom_item in bom_items:
|
||||
parent = bom_item["parent"]
|
||||
if parent not in bom_items_map:
|
||||
bom_items_map[parent] = []
|
||||
bom_items_map[parent].append(bom_item)
|
||||
|
||||
# Track which items have nested BOMs
|
||||
if bom_item.get("bom_no"):
|
||||
nested_bom_items.add(bom_item["item_code"])
|
||||
|
||||
# Recursively fetch nested BOMs if any
|
||||
nested_bom_dict = {}
|
||||
if nested_bom_items:
|
||||
nested_bom_dict = ItemService.batch_fetch_boms(list(nested_bom_items))
|
||||
|
||||
# Build the result dictionary mapping item_code to its BOM structure
|
||||
result = {}
|
||||
for bom in boms:
|
||||
bom_name = bom["name"]
|
||||
item_code = bom["item"]
|
||||
|
||||
items = bom_items_map.get(bom_name, [])
|
||||
# Attach nested BOMs to items
|
||||
for item in items:
|
||||
if item.get("bom_no"):
|
||||
item["bom"] = nested_bom_dict.get(item["item_code"])
|
||||
else:
|
||||
item["bom"] = None
|
||||
|
||||
result[item_code] = {
|
||||
"name": bom_name,
|
||||
"items": items
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def build_category_dict(items: list[dict]) -> dict:
|
||||
"""Build a dictionary categorizing items by their item group."""
|
||||
print(f"DEBUG: Building category dictionary for items")
|
||||
category_dict = {}
|
||||
category_dict["Packages"] = {}
|
||||
for item in items:
|
||||
if item.get("bom"):
|
||||
if item.get("item_group", "Uncategorized") not in category_dict["Packages"]:
|
||||
category_dict["Packages"][item.get("item_group", "Uncategorized")] = []
|
||||
category_dict["Packages"][item.get("item_group", "Uncategorized")].append(item)
|
||||
else:
|
||||
category = item.get("item_group", "Uncategorized")
|
||||
if category not in category_dict:
|
||||
category_dict[category] = []
|
||||
category_dict[category].append(item)
|
||||
print(f"DEBUG: Built category dictionary with categories: {list(category_dict.keys())}")
|
||||
return category_dict
|
||||
|
||||
@staticmethod
|
||||
def build_item_code(prefix: str, item_name: str) -> str:
|
||||
"""Build a unique item code based on the provided prefix and item name."""
|
||||
print(f"DEBUG: Building item code with prefix: {prefix} and item name: {item_name}")
|
||||
# Replace all " " with "-" and convert to uppercase
|
||||
base_code = f"{prefix}-{item_name.replace(' ', '-').upper()}"
|
||||
# Check for existing items with the same base code and append a number if necessary
|
||||
existing_codes = frappe.get_all("Item", filters={"item_code": ["like", f"{base_code}-%"]}, pluck="item_code")
|
||||
if base_code in existing_codes:
|
||||
suffix = 1
|
||||
while f"{base_code}-{suffix}" in existing_codes:
|
||||
suffix += 1
|
||||
final_code = f"{base_code}-{suffix}"
|
||||
else:
|
||||
final_code = base_code
|
||||
print(f"DEBUG: Built item code: {final_code}")
|
||||
return final_code
|
||||
@ -1,29 +1,52 @@
|
||||
import frappe
|
||||
from custom_ui.services import DbService
|
||||
from custom_ui.services import DbService, StripeService
|
||||
from dataclasses import dataclass
|
||||
from custom_ui.models import PaymentData
|
||||
|
||||
|
||||
|
||||
class PaymentService:
|
||||
|
||||
@staticmethod
|
||||
def create_payment_entry(reference_doctype: str, reference_doc_name: str, data: dict) -> frappe._dict:
|
||||
def create_payment_entry(data: PaymentData) -> frappe._dict:
|
||||
"""Create a Payment Entry document based on the reference document."""
|
||||
print(f"DEBUG: Creating Payment Entry for {reference_doctype} {reference_doc_name} with data: {data}")
|
||||
reference_doc = DbService.get_or_throw(reference_doctype, reference_doc_name)
|
||||
print(f"DEBUG: Creating Payment Entry for {data.reference_doc_name} with data: {data}")
|
||||
reference_doctype = PaymentService.determine_reference_doctype(data.reference_doc_name)
|
||||
reference_doc = DbService.get_or_throw(reference_doctype, data.reference_doc_name)
|
||||
account = StripeService.get_stripe_settings(data.company).custom_account
|
||||
pe = frappe.get_doc({
|
||||
"doctype": "Payment Entry",
|
||||
"company": data.company,
|
||||
"payment_type": "Receive",
|
||||
"party_type": "Customer",
|
||||
"mode_of_payment": data.get("mode_of_payment", "Stripe"),
|
||||
"mode_of_payment": data.mode_of_payment or "Stripe",
|
||||
"party": reference_doc.customer,
|
||||
"party_name": reference_doc.customer,
|
||||
"paid_to": data.get("paid_to"),
|
||||
"reference_no": data.get("reference_no"),
|
||||
"reference_date": data.get("reference_date", frappe.utils.nowdate()),
|
||||
"reference_doctype": reference_doctype,
|
||||
"reference_name": reference_doc.name,
|
||||
"paid_amount": data.get("paid_amount"),
|
||||
"paid_currency": data.get("paid_currency"),
|
||||
"paid_to": account,
|
||||
"reference_no": data.reference_no,
|
||||
"reference_date": data.reference_date or frappe.utils.nowdate(),
|
||||
"paid_amount": data.received_amount,
|
||||
"received_amount": data.received_amount,
|
||||
"paid_currency": "USD",
|
||||
"received_currency": "USD",
|
||||
"references": [{
|
||||
"reference_doctype": reference_doc.doctype,
|
||||
"reference_name": reference_doc.name,
|
||||
"allocated_amount": data.received_amount,
|
||||
}]
|
||||
})
|
||||
pe.insert()
|
||||
print(f"DEBUG: Created Payment Entry with name: {pe.name}")
|
||||
return pe.as_dict()
|
||||
return pe
|
||||
|
||||
@staticmethod
|
||||
def determine_reference_doctype(reference_doc_name: str) -> str:
|
||||
"""Determine the reference doctype based on the document name pattern."""
|
||||
print(f"DEBUG: Determining reference doctype for document name: {reference_doc_name}")
|
||||
if DbService.exists("Sales Order", reference_doc_name):
|
||||
return "Sales Order"
|
||||
elif DbService.exists("Sales Invoice", reference_doc_name):
|
||||
return "Sales Invoice"
|
||||
else:
|
||||
frappe.throw("Unable to determine reference doctype from document name.")
|
||||
|
||||
29
custom_ui/services/project_service.py
Normal file
29
custom_ui/services/project_service.py
Normal file
@ -0,0 +1,29 @@
|
||||
import frappe
|
||||
from custom_ui.services import TaskService, AddressService
|
||||
|
||||
class ProjectService:
|
||||
|
||||
@staticmethod
|
||||
def get_project_item_groups(project_template: str) -> list[str]:
|
||||
"""Retrieve item groups associated with a given project template."""
|
||||
print(f"DEBUG: Getting item groups for Project Template {project_template}")
|
||||
item_groups_str = frappe.db.get_value("Project Template", project_template, "item_groups") or ""
|
||||
item_groups = [item_group.strip() for item_group in item_groups_str.split(",") if item_group.strip()]
|
||||
print(f"DEBUG: Retrieved item groups: {item_groups}")
|
||||
return item_groups
|
||||
|
||||
@staticmethod
|
||||
def get_full_project_details(project_name: str) -> dict:
|
||||
"""Retrieve comprehensive details for a given project, including linked sales order and invoice information."""
|
||||
print(f"DEBUG: Getting full project details for project: {project_name}")
|
||||
project = frappe.get_doc("Project", project_name).as_dict()
|
||||
project["tasks"] = [frappe.get_doc("Task", task["task"]).as_dict() for task in project["tasks"] if task.get("task")]
|
||||
for task in project["tasks"]:
|
||||
task["type"] = frappe.get_doc("Task Type", task["type"]).as_dict() if task.get("type") else None
|
||||
project["job_address"] = frappe.get_doc("Address", project["job_address"]).as_dict() if project["job_address"] else None
|
||||
project["service_appointment"] = frappe.get_doc("Service Address 2", project["service_appointment"]).as_dict() if project["service_appointment"] else None
|
||||
project["client"] = frappe.get_doc("Customer", project["customer"]).as_dict() if project["customer"] else None
|
||||
project["sales_order"] = frappe.get_doc("Sales Order", project["sales_order"]).as_dict() if project["sales_order"] else None
|
||||
project["billing_address"] = frappe.get_doc("Address", project["client"]["custom_billing_address"]).as_dict() if project["client"] and project["client"].get("custom_billing_address") else None
|
||||
project["invoice"] = frappe.get_doc("Sales Invoice", {"project": project["name"]}).as_dict() if frappe.db.exists("Sales Invoice", {"project": project["name"]}) else None
|
||||
return project
|
||||
@ -1,7 +1,28 @@
|
||||
import frappe
|
||||
|
||||
from frappe.utils import today
|
||||
from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
|
||||
|
||||
class SalesOrderService:
|
||||
|
||||
@staticmethod
|
||||
def apply_advance_payment(sales_order_name: str, payment_entry_doc):
|
||||
pass
|
||||
def create_sales_invoice_from_sales_order(sales_order_name):
|
||||
try:
|
||||
sales_order_doc = frappe.get_doc("Sales Order", sales_order_name)
|
||||
sales_invoice = make_sales_invoice(sales_order_doc.name)
|
||||
sales_invoice.project = sales_order_doc.project
|
||||
sales_invoice.posting_date = today()
|
||||
sales_invoice.due_date = today()
|
||||
sales_invoice.remarks = f"Auto-generated from Sales Order {sales_order_doc.name}"
|
||||
sales_invoice.job_address = sales_order_doc.custom_job_address
|
||||
sales_invoice.project_template = sales_order_doc.custom_project_template
|
||||
|
||||
sales_invoice.set_advances()
|
||||
sales_invoice.set_missing_values()
|
||||
sales_invoice.calculate_taxes_and_totals()
|
||||
|
||||
sales_invoice.insert()
|
||||
sales_invoice.submit()
|
||||
return sales_invoice.name
|
||||
except Exception as e:
|
||||
print("ERROR creating Sales Invoice from Sales Order:", str(e))
|
||||
return None
|
||||
@ -51,4 +51,14 @@ class ServiceAppointmentService:
|
||||
setattr(service_appointment, field, value)
|
||||
service_appointment.save()
|
||||
print(f"DEBUG: Updated fields for Service Appointment {service_appointment_name}")
|
||||
return service_appointment
|
||||
|
||||
@staticmethod
|
||||
def update_status(service_appointment_name: str, new_status: str):
|
||||
"""Update the status of a Service Appointment."""
|
||||
print(f"DEBUG: Updating status for Service Appointment {service_appointment_name} to {new_status}")
|
||||
service_appointment = DbService.get_or_throw("Service Address 2", service_appointment_name)
|
||||
service_appointment.status = new_status
|
||||
service_appointment.save()
|
||||
print(f"DEBUG: Updated status for Service Appointment {service_appointment_name} to {new_status}")
|
||||
return service_appointment
|
||||
@ -9,7 +9,7 @@ class StripeService:
|
||||
@staticmethod
|
||||
def get_stripe_settings(company: str):
|
||||
"""Fetch Stripe settings for a given company."""
|
||||
settings_name = frappe.get_all("Stripe Settings", pluck="name", filters={"company": company})
|
||||
settings_name = frappe.get_all("Stripe Settings", pluck="name", filters={"custom_company": company})
|
||||
if not settings_name:
|
||||
frappe.throw(f"Stripe Settings not found for company: {company}")
|
||||
settings = frappe.get_doc("Stripe Settings", settings_name[0]) if settings_name else None
|
||||
@ -19,63 +19,138 @@ class StripeService:
|
||||
def get_api_key(company: str) -> str:
|
||||
"""Retrieve the Stripe API key for the specified company."""
|
||||
settings = StripeService.get_stripe_settings(company)
|
||||
return settings.secret_key
|
||||
return settings.get_password("secret_key")
|
||||
|
||||
@staticmethod
|
||||
def get_webhook_secret(company: str) -> str:
|
||||
"""Retrieve the Stripe webhook secret for the specified company."""
|
||||
settings = StripeService.get_stripe_settings(company)
|
||||
if not settings.webhook_secret:
|
||||
if not settings.custom_webhook_secret:
|
||||
frappe.throw(f"Stripe Webhook Secret not configured for company: {company}")
|
||||
return settings.webhook_secret
|
||||
return settings.custom_webhook_secret
|
||||
|
||||
@staticmethod
|
||||
def create_checkout_session(company: str, amount: float, service: str, order_num: str, currency: str = "usd", for_advance_payment: bool = False, line_items: list | None = None) -> stripe.checkout.Session:
|
||||
"""Create a Stripe Checkout Session. order_num is a Sales Order name if for_advance_payment is True, otherwise it is a Sales Invoice name."""
|
||||
def create_checkout_session(
|
||||
company: str,
|
||||
amount: float,
|
||||
service: str,
|
||||
order_num: str,
|
||||
currency: str = "usd",
|
||||
for_advance_payment: bool = False,
|
||||
line_items: list | None = None,
|
||||
sales_invoice: str = None
|
||||
) -> stripe.checkout.Session:
|
||||
"""
|
||||
Create a Stripe Checkout Session.
|
||||
|
||||
Args:
|
||||
company: Company name
|
||||
amount: Payment amount (should be the outstanding amount for invoices)
|
||||
service: Service description
|
||||
order_num: Sales Order name if for_advance_payment is True, otherwise Sales Invoice name
|
||||
currency: Currency code (default: "usd")
|
||||
for_advance_payment: True if this is an advance/down payment, False for full invoice payment
|
||||
line_items: Optional custom line items for the checkout session
|
||||
sales_invoice: Sales Invoice name (for full payments)
|
||||
|
||||
Returns:
|
||||
stripe.checkout.Session object
|
||||
"""
|
||||
stripe.api_key = StripeService.get_api_key(company)
|
||||
|
||||
# Determine payment description
|
||||
if for_advance_payment:
|
||||
description = f"Advance payment for {company}{' - ' + service if service else ''}"
|
||||
else:
|
||||
description = f"Invoice payment for {company}{' - ' + service if service else ''}"
|
||||
if sales_invoice:
|
||||
description = f"Invoice {sales_invoice} - {company}"
|
||||
|
||||
# Use custom line items if provided and not an advance payment, otherwise create default line item
|
||||
line_items = line_items if line_items and not for_advance_payment else [{
|
||||
"price_data": {
|
||||
"currency": currency.lower(),
|
||||
"product_data": {
|
||||
"name": f"Advance payment for {company}{' - ' + service if service else ''}"
|
||||
"name": description
|
||||
},
|
||||
"unit_amount": int(amount * 100),
|
||||
"unit_amount": int(amount * 100), # Stripe expects amount in cents
|
||||
},
|
||||
"quantity": 1,
|
||||
}]
|
||||
|
||||
# Prepare metadata
|
||||
metadata = {
|
||||
"company": company,
|
||||
"payment_type": "advance" if for_advance_payment else "full"
|
||||
}
|
||||
|
||||
# Add appropriate document reference to metadata
|
||||
if for_advance_payment:
|
||||
metadata["sales_order"] = order_num
|
||||
else:
|
||||
metadata["sales_invoice"] = sales_invoice or order_num
|
||||
if sales_invoice:
|
||||
# Check if there's a related sales order
|
||||
invoice_doc = frappe.get_doc("Sales Invoice", sales_invoice)
|
||||
if hasattr(invoice_doc, 'items') and invoice_doc.items:
|
||||
for item in invoice_doc.items:
|
||||
if item.sales_order:
|
||||
metadata["sales_order"] = item.sales_order
|
||||
break
|
||||
|
||||
session = stripe.checkout.Session.create(
|
||||
mode="payment",
|
||||
payment_method_types=["card"],
|
||||
line_items=line_items,
|
||||
metadata={
|
||||
"order_num": order_num,
|
||||
"company": company,
|
||||
"payment_type": "advance" if for_advance_payment else "full"
|
||||
},
|
||||
success_url=f"{get_url()}/payment-success?session_id={{CHECKOUT_SESSION_ID}}",
|
||||
cancel_url=f"{get_url()}/payment-cancelled",
|
||||
metadata=metadata,
|
||||
success_url=f"{get_url()}/payment_success?session_id={{CHECKOUT_SESSION_ID}}",
|
||||
cancel_url=f"{get_url()}/payment_cancelled",
|
||||
)
|
||||
|
||||
return session
|
||||
|
||||
@staticmethod
|
||||
def get_event(payload: bytes, sig_header: str, company: str = None) -> stripe.Event:
|
||||
company = company if company else json.loads(payload).get("data", {}).get("object", {}).get("metadata", {}).get("company")
|
||||
print("DEBUG: Stripe webhook received")
|
||||
print(f"DEBUG: Signature header present: {bool(sig_header)}")
|
||||
|
||||
# If company not provided, try to extract from payload metadata
|
||||
if not company:
|
||||
try:
|
||||
payload_dict = json.loads(payload)
|
||||
print(f"DEBUG: Parsed payload type: {payload_dict.get('type')}")
|
||||
|
||||
metadata = payload_dict.get("data", {}).get("object", {}).get("metadata", {})
|
||||
print(f"DEBUG: Metadata from payload: {metadata}")
|
||||
|
||||
company = metadata.get("company")
|
||||
print(f"DEBUG: Extracted company from metadata: {company}")
|
||||
except (json.JSONDecodeError, KeyError, AttributeError) as e:
|
||||
print(f"DEBUG: Failed to parse payload: {str(e)}")
|
||||
|
||||
# If we still don't have a company, reject the webhook
|
||||
if not company:
|
||||
print("ERROR: Company information missing in webhook payload")
|
||||
frappe.throw("Company information missing in webhook payload.")
|
||||
|
||||
print(f"DEBUG: Validating webhook signature for company: {company}")
|
||||
|
||||
# Validate webhook signature with the specified company's secret
|
||||
try:
|
||||
event = stripe.Webhook.construct_event(
|
||||
payload=payload,
|
||||
sig_header=sig_header,
|
||||
secret=StripeService.get_webhook_secret(company),
|
||||
api_key=StripeService.get_api_key(company)
|
||||
secret=StripeService.get_webhook_secret(company)
|
||||
)
|
||||
print(f"DEBUG: Webhook signature validated successfully for company: {company}")
|
||||
print(f"DEBUG: Event type: {event.type}")
|
||||
print(f"DEBUG: Event ID: {event.id}")
|
||||
except ValueError as e:
|
||||
print(f"ERROR: Invalid payload: {str(e)}")
|
||||
frappe.throw(f"Invalid payload: {str(e)}")
|
||||
except stripe.error.SignatureVerificationError as e:
|
||||
frappe.throw(f"Invalid signature: {str(e)}")
|
||||
print(f"ERROR: Invalid signature for company {company}: {str(e)}")
|
||||
frappe.throw(f"Invalid signature for company {company}: {str(e)}")
|
||||
|
||||
return event
|
||||
|
||||
|
||||
@ -6,10 +6,10 @@ class TaskService:
|
||||
|
||||
|
||||
@staticmethod
|
||||
def calculate_and_set_due_dates(task_names: list[str], event: str, current_triggering_dict=None):
|
||||
def fire_task_triggers(task_names: list[str], event: str, current_triggering_dict=None):
|
||||
"""Calculate the due date for a list of tasks based on their expected end dates."""
|
||||
for task_name in task_names:
|
||||
TaskService.check_and_update_task_due_date(task_name, event, current_triggering_dict)
|
||||
TaskService.fire_task_trigger(task_name, event, current_triggering_dict)
|
||||
|
||||
|
||||
@staticmethod
|
||||
@ -20,49 +20,60 @@ class TaskService:
|
||||
return tasks
|
||||
|
||||
@staticmethod
|
||||
def check_and_update_task_due_date(task_name: str, event: str, current_triggering_dict=None):
|
||||
def fire_task_trigger(task_name: str, event: str, current_triggering_dict=None):
|
||||
"""Determine the triggering configuration for a given task."""
|
||||
task_type_doc = TaskService.get_task_type_doc(task_name)
|
||||
if task_type_doc.no_due_date:
|
||||
print(f"DEBUG: Task {task_name} is marked as no due date, skipping calculation.")
|
||||
return
|
||||
if task_type_doc.triggering_doctype != current_triggering_dict.get("doctype") and current_triggering_dict:
|
||||
schedule_trigger = task_type_doc.triggering_doctype == current_triggering_dict.get("doctype") if current_triggering_dict else False
|
||||
completion_trigger = task_type_doc.custom_completion_trigger_doctype == current_triggering_dict.get("doctype") if current_triggering_dict else False
|
||||
match_schedule_event = task_type_doc.trigger == event
|
||||
match_completion_event = task_type_doc.custom_completion_trigger == event
|
||||
if not schedule_trigger and not completion_trigger:
|
||||
print(f"DEBUG: Task {task_name} triggering doctype {task_type_doc.triggering_doctype} does not match triggering doctype {current_triggering_dict.get('doctype')}, skipping calculation.")
|
||||
return
|
||||
if task_type_doc.trigger != event:
|
||||
if not match_schedule_event and not match_completion_event:
|
||||
print(f"DEBUG: Task {task_name} trigger {task_type_doc.trigger} does not match event {event}, skipping calculation.")
|
||||
return
|
||||
if task_type_doc.logic_key:
|
||||
print(f"DEBUG: Task {task_name} has a logic key set, skipping calculations and running logic.")
|
||||
safe_eval(task_type_doc.logic_key, {"task_name": task_name, "task_type_doc": task_type_doc})
|
||||
if task_type_doc.no_due_date:
|
||||
print(f"DEBUG: Task {task_name} is marked as no due date, skipping calculation.")
|
||||
return
|
||||
calculate_from = task_type_doc.calculate_from
|
||||
trigger = task_type_doc.trigger
|
||||
print(f"DEBUG: Calculating triggering data for Task {task_name} from {calculate_from} on trigger {trigger}")
|
||||
|
||||
|
||||
triggering_doc_dict = current_triggering_dict if current_triggering_dict else TaskService.get_triggering_doc_dict(task_name=task_name, task_type_doc=task_type_doc)
|
||||
|
||||
|
||||
calculated_due_date, calculated_start_date = TaskService.calculate_dates(
|
||||
task_name=task_name,
|
||||
triggering_doc_dict=triggering_doc_dict,
|
||||
task_type_doc=task_type_doc
|
||||
)
|
||||
|
||||
update_required = TaskService.determine_update_required(
|
||||
task_name=task_name,
|
||||
calculated_due_date=calculated_due_date,
|
||||
calculated_start_date=calculated_start_date
|
||||
)
|
||||
if update_required:
|
||||
TaskService.update_task_dates(
|
||||
if schedule_trigger:
|
||||
triggering_doc_dict = current_triggering_dict if current_triggering_dict else TaskService.get_triggering_doc_dict(task_name=task_name, doctype=task_type_doc.triggering_doctype, task_type_calculate_from=task_type_doc.task_type_calculate_from)
|
||||
calculate_from = task_type_doc.calculate_from
|
||||
trigger = task_type_doc.trigger
|
||||
print(f"DEBUG: Calculating triggering data for Task {task_name} from {calculate_from} on trigger {trigger}")
|
||||
|
||||
calculated_due_date, calculated_start_date = TaskService.calculate_dates(
|
||||
task_name=task_name,
|
||||
triggering_doc_dict=triggering_doc_dict,
|
||||
task_type_doc=task_type_doc
|
||||
)
|
||||
|
||||
update_required = TaskService.determine_due_date_update_required(
|
||||
task_name=task_name,
|
||||
calculated_due_date=calculated_due_date,
|
||||
calculated_start_date=calculated_start_date
|
||||
)
|
||||
if update_required:
|
||||
TaskService.update_task(
|
||||
task_name=task_name,
|
||||
calculated_due_date=calculated_due_date,
|
||||
calculated_start_date=calculated_start_date
|
||||
)
|
||||
if completion_trigger:
|
||||
triggering_doc_dict = current_triggering_dict if current_triggering_dict else TaskService.get_triggering_doc_dict(task_name=task_name, doctype=task_type_doc.custom_completion_trigger_doctype)
|
||||
print(f"DEBUG: Running completion trigger logic for Task {task_name}")
|
||||
update_required = TaskService.determine_completion_update_required(
|
||||
task_name=task_name,
|
||||
task_type_doc=task_type_doc,
|
||||
)
|
||||
if update_required:
|
||||
TaskService.update_task(
|
||||
task_name=task_name,
|
||||
status="Completed"
|
||||
)
|
||||
print(f"DEBUG: Marked Task {task_name} as Completed due to completion trigger.")
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_task_type_doc(task_name: str):
|
||||
@ -94,7 +105,7 @@ class TaskService:
|
||||
return calculated_due_date, calculated_start_date
|
||||
|
||||
@staticmethod
|
||||
def determine_update_required(task_name: str, calculated_due_date: date | None, calculated_start_date: date | None) -> bool:
|
||||
def determine_due_date_update_required(task_name: str, calculated_due_date: date | None, calculated_start_date: date | None) -> bool:
|
||||
current_due_date = frappe.get_value("Task", task_name, "exp_end_date")
|
||||
current_start_date = frappe.get_value("Task", task_name, "exp_start_date")
|
||||
if current_due_date != calculated_due_date or current_start_date != calculated_start_date:
|
||||
@ -104,32 +115,60 @@ class TaskService:
|
||||
print(f"DEBUG: No update required for Task {task_name}. Dates are up to date.")
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def determine_completion_update_required(task_name: str, task_type_doc) -> bool:
|
||||
current_status = frappe.get_value("Task", task_name, "status")
|
||||
determination = False
|
||||
if current_status == "Completed":
|
||||
print(f"DEBUG: Task {task_name} is already marked as Completed, no update required.")
|
||||
return False
|
||||
else:
|
||||
triggering_doc_dict = TaskService.get_triggering_doc_dict(task_name=task_name, doctype=task_type_doc.custom_completion_trigger_doctype)
|
||||
check_field = TaskService.map_completion_check_field(task_type_doc.custom_completion_trigger)
|
||||
check_value = triggering_doc_dict.get(check_field)
|
||||
trigger = task_type_doc.custom_completion_trigger
|
||||
if trigger == "Completed" and check_value == "Completed" and current_status != "Completed":
|
||||
determination = True
|
||||
elif trigger == "Percentage Reached" and check_value >= task_type_doc.custom_target_percent and current_status != "Completed":
|
||||
determination = True
|
||||
elif trigger in ["Scheduled", "Started", "Created"] and check_value and current_status != "Completed":
|
||||
determination = True
|
||||
print(f"DEBUG: Completion trigger '{trigger}' met for Task {task_name}, check field {check_field} has value {check_value}.")
|
||||
return determination
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_triggering_doc_dict(task_name: str, task_type_doc) -> dict | None:
|
||||
def get_triggering_doc_dict(task_name: str, doctype, task_type_calculate_from = None) -> dict | None:
|
||||
project_name = frappe.get_value("Task", task_name, "project")
|
||||
print(f"DEBUG: Project name: {project_name}")
|
||||
dict = None
|
||||
if task_type_doc.calculate_from == "Project":
|
||||
if doctype == "Project":
|
||||
dict = frappe.get_doc("Project", project_name).as_dict()
|
||||
if task_type_doc.calculate_from == "Service Address 2":
|
||||
if doctype == "Service Address 2":
|
||||
service_name = frappe.get_value("Project", project_name, "service_appointment")
|
||||
dict = frappe.get_doc("Service Address 2", service_name).as_dict()
|
||||
if task_type_doc.calculate_from == "Task":
|
||||
if doctype == "Task":
|
||||
project_doc = frappe.get_doc("Project", project_name)
|
||||
for task in project_doc.tasks:
|
||||
if task.task_type == task_type_doc.task_type_calculate_from:
|
||||
if task.task_type == task_type_calculate_from:
|
||||
dict = frappe.get_doc("Task", task.task).as_dict()
|
||||
print(f"DEBUG: Triggering doc dict for Task {task_name}: {dict}")
|
||||
return dict
|
||||
|
||||
@staticmethod
|
||||
def update_task_dates(task_name: str, calculated_due_date: date | None, calculated_start_date: date | None):
|
||||
def update_task(task_name: str, calculated_due_date: date | None = None, calculated_start_date: date | None = None, status: str | None = None):
|
||||
task_doc = frappe.get_doc("Task", task_name)
|
||||
task_doc.exp_end_date = calculated_due_date
|
||||
task_doc.exp_start_date = calculated_start_date
|
||||
if calculated_due_date is not None:
|
||||
task_doc.exp_end_date = calculated_due_date
|
||||
if calculated_start_date is not None:
|
||||
task_doc.exp_start_date = calculated_start_date
|
||||
if status is not None:
|
||||
task_doc.status = status
|
||||
if status == "Completed":
|
||||
task_doc.actual_end_date = datetime.now()
|
||||
task_doc.save(ignore_permissions=True)
|
||||
print(f"DEBUG: Updated Task {task_name} with new dates - Start: {calculated_start_date}, End: {calculated_due_date}")
|
||||
print(f"DEBUG: Updated Task {task_name} with new dates - Start: {calculated_start_date}, End: {calculated_due_date}, Status: {status}")
|
||||
|
||||
@staticmethod
|
||||
def map_base_date_to_field(base_date: str, triggering_doctype: str) -> str:
|
||||
@ -150,6 +189,17 @@ class TaskService:
|
||||
return task_date_field_map.get(base_date, "exp_end_date")
|
||||
return base_date_field_map.get(base_date, "expected_end_date")
|
||||
|
||||
@staticmethod
|
||||
def map_completion_check_field(completion_trigger: str) -> str:
|
||||
completion_check_field_map = {
|
||||
"Completed": "status",
|
||||
"Scheduled": "expected_end_date",
|
||||
"Created": "creation",
|
||||
"Started": "actual_start_date",
|
||||
"Percentage Reached": "progress"
|
||||
}
|
||||
return completion_check_field_map.get(completion_trigger, "status")
|
||||
|
||||
@staticmethod
|
||||
def determine_event(triggering_doc) -> str | None:
|
||||
print("DEBUG: Current Document:", triggering_doc.as_dict())
|
||||
@ -168,4 +218,16 @@ class TaskService:
|
||||
return "Completed"
|
||||
else:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def find_and_update_overdue_tasks():
|
||||
today = date.today()
|
||||
overdue_tasks = frappe.get_all("Task", filters={"exp_end_date": ("<", today), "status": ["not in", ["Completed", "Template", "Cancelled", "Overdue"]]}, pluck="name")
|
||||
print(f"DEBUG: Found {len(overdue_tasks)} overdue tasks.")
|
||||
for task_name in overdue_tasks:
|
||||
task_doc = frappe.get_doc("Task", task_name)
|
||||
task_doc.status = "Overdue"
|
||||
task_doc.save(ignore_permissions=True)
|
||||
print(f"DEBUG: Updated Task {task_name} to Overdue status.")
|
||||
frappe.db.commit()
|
||||
|
||||
@ -75,10 +75,10 @@
|
||||
<div class="payment-details">
|
||||
<h2>Payment Details</h2>
|
||||
<p><strong>Sales Order Number:</strong> {{ sales_order_number }}</p>
|
||||
<p><strong>Down Payment Amount:</strong> ${{ total_amount }}</p>
|
||||
<p><strong>Down Payment Amount:</strong> {{ total_amount }}</p>
|
||||
</div>
|
||||
<p>Please click the button below to make your secure payment through our payment processor:</p>
|
||||
<a href="https://yourdomain.com/downpayment?so={{ sales_order_number }}&amount={{ total_amount }}" class="cta-button">Make Payment</a>
|
||||
<a href="{{ base_url }}/api/method/custom_ui.api.public.payments.half_down_stripe_payment?sales_order={{ sales_order_number }}" class="cta-button">Make Payment</a>
|
||||
<p>If you have any questions or need assistance, feel free to contact us. We're here to help!</p>
|
||||
<p>Best regards,<br>The Team at {{ company_name }}</p>
|
||||
</div>
|
||||
251
custom_ui/templates/emails/general_estimation.html
Normal file
251
custom_ui/templates/emails/general_estimation.html
Normal file
@ -0,0 +1,251 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Estimate from {{ company }}</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
background-color: #f4f4f4;
|
||||
}
|
||||
.email-container {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
.letterhead {
|
||||
text-align: center;
|
||||
padding: 30px 20px;
|
||||
background-color: #ffffff;
|
||||
border-bottom: 3px solid #0066cc;
|
||||
}
|
||||
.letterhead img {
|
||||
max-width: 250px;
|
||||
height: auto;
|
||||
}
|
||||
.company-name {
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
color: #333333;
|
||||
margin: 10px 0;
|
||||
}
|
||||
.content {
|
||||
padding: 40px 30px;
|
||||
}
|
||||
.greeting {
|
||||
font-size: 18px;
|
||||
color: #333333;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.intro-text {
|
||||
font-size: 16px;
|
||||
color: #555555;
|
||||
line-height: 1.6;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
.estimate-box {
|
||||
background-color: #f8f9fa;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
padding: 25px;
|
||||
margin: 30px 0;
|
||||
}
|
||||
.estimate-label {
|
||||
font-size: 14px;
|
||||
color: #666666;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.estimate-value {
|
||||
font-size: 16px;
|
||||
color: #333333;
|
||||
margin-bottom: 20px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.estimate-value:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.price-section {
|
||||
background-color: #0066cc;
|
||||
color: #ffffff;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
margin-top: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.price-label {
|
||||
font-size: 14px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.price-amount {
|
||||
font-size: 36px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.additional-section {
|
||||
background-color: #fff9e6;
|
||||
border-left: 4px solid #ffc107;
|
||||
padding: 20px;
|
||||
margin: 30px 0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.additional-label {
|
||||
font-size: 14px;
|
||||
color: #856404;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 1px;
|
||||
margin-bottom: 10px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.additional-text {
|
||||
font-size: 15px;
|
||||
color: #333333;
|
||||
line-height: 1.6;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
.action-buttons {
|
||||
text-align: center;
|
||||
margin: 40px 0;
|
||||
padding: 20px;
|
||||
}
|
||||
.btn {
|
||||
display: inline-block;
|
||||
padding: 14px 28px;
|
||||
margin: 8px;
|
||||
text-decoration: none;
|
||||
border-radius: 6px;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
.btn:hover {
|
||||
opacity: 0.85;
|
||||
}
|
||||
.btn-accept {
|
||||
background-color: #28a745;
|
||||
color: #ffffff;
|
||||
}
|
||||
.btn-decline {
|
||||
background-color: #dc3545;
|
||||
color: #ffffff;
|
||||
}
|
||||
.btn-call {
|
||||
background-color: #ffc107;
|
||||
color: #333333;
|
||||
}
|
||||
.closing-text {
|
||||
font-size: 16px;
|
||||
color: #555555;
|
||||
line-height: 1.6;
|
||||
margin-top: 30px;
|
||||
}
|
||||
.contact-info {
|
||||
font-size: 15px;
|
||||
color: #0066cc;
|
||||
font-weight: bold;
|
||||
margin-top: 15px;
|
||||
}
|
||||
.footer {
|
||||
background-color: #f8f9fa;
|
||||
padding: 30px;
|
||||
text-align: center;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
}
|
||||
.footer-text {
|
||||
font-size: 14px;
|
||||
color: #666666;
|
||||
line-height: 1.6;
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
.content {
|
||||
padding: 30px 20px;
|
||||
}
|
||||
.estimate-box {
|
||||
padding: 20px;
|
||||
}
|
||||
.price-amount {
|
||||
font-size: 28px;
|
||||
}
|
||||
.company-name {
|
||||
font-size: 24px;
|
||||
}
|
||||
.btn {
|
||||
display: block;
|
||||
margin: 10px auto;
|
||||
max-width: 250px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="email-container">
|
||||
<!-- Letterhead Section -->
|
||||
<div class="letterhead">
|
||||
{% if letterhead_image %}
|
||||
<img src="{{ letterhead_image }}" alt="{{ company }} Logo">
|
||||
{% else %}
|
||||
<div class="company-name">{{ company }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Main Content -->
|
||||
<div class="content">
|
||||
<div class="greeting">Hello {{ customer_name }},</div>
|
||||
|
||||
<div class="intro-text">
|
||||
Thank you for considering {{ company }} for your project. We are pleased to provide you with the following estimate for the services requested.
|
||||
</div>
|
||||
|
||||
<!-- Estimate Details Box -->
|
||||
<div class="estimate-box">
|
||||
<div class="estimate-label">Service Location</div>
|
||||
<div class="estimate-value">{{ address }}</div>
|
||||
|
||||
<!-- Price Section -->
|
||||
<div class="price-section">
|
||||
<div class="price-label">Total Estimate</div>
|
||||
<div class="price-amount">{{ price }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Additional Notes (Conditional) -->
|
||||
{% if additional %}
|
||||
<div class="additional-section">
|
||||
<div class="additional-label">Additional Notes</div>
|
||||
<div class="additional-text">{{ additional }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<div class="action-buttons">
|
||||
<a href="{{ base_url }}/api/method/custom_ui.api.public.estimates.update_response?name={{ estimate_name }}&response=Accepted" class="btn btn-accept">Accept</a>
|
||||
<a href="{{ base_url }}/api/method/custom_ui.api.public.estimates.update_response?name={{ estimate_name }}&response=Rejected" class="btn btn-decline">Decline</a>
|
||||
<a href="{{ base_url }}/api/method/custom_ui.api.public.estimates.update_response?name={{ estimate_name }}&response=Requested%20call" class="btn btn-call">Request a Call</a>
|
||||
</div>
|
||||
|
||||
<!-- Closing -->
|
||||
<div class="closing-text">
|
||||
This estimate is valid for 30 days from the date of this email. If you have any questions or would like to proceed with this estimate, please don't hesitate to contact us.
|
||||
{% if company_phone %}
|
||||
<div class="contact-info">Call us at: {{ company_phone }}</div>
|
||||
{% endif %}
|
||||
<br>
|
||||
We look forward to working with you!
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Footer -->
|
||||
<div class="footer">
|
||||
<div class="footer-text">
|
||||
<strong>{{ company }}</strong><br>
|
||||
This is an automated message. Please do not reply directly to this email.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
152
custom_ui/templates/emails/invoice.html
Normal file
152
custom_ui/templates/emails/invoice.html
Normal file
@ -0,0 +1,152 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Invoice - {{ invoice_number }}</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
line-height: 1.6;
|
||||
color: #333;
|
||||
background-color: #f4f4f4;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
}
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
background-color: #ffffff;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.header {
|
||||
text-align: center;
|
||||
padding-bottom: 20px;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
.header h1 {
|
||||
color: #2c3e50;
|
||||
margin: 0;
|
||||
}
|
||||
.content {
|
||||
padding: 20px 0;
|
||||
}
|
||||
.invoice-details {
|
||||
background-color: #ecf0f1;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
.invoice-details h2 {
|
||||
margin-top: 0;
|
||||
color: #3498db;
|
||||
}
|
||||
.detail-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 5px 0;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
.detail-row:last-child {
|
||||
border-bottom: none;
|
||||
font-weight: bold;
|
||||
margin-top: 10px;
|
||||
padding-top: 10px;
|
||||
border-top: 2px solid #3498db;
|
||||
}
|
||||
.detail-label {
|
||||
font-weight: bold;
|
||||
}
|
||||
.cta-button {
|
||||
display: inline-block;
|
||||
background-color: #27ae60;
|
||||
color: #ffffff;
|
||||
padding: 12px 24px;
|
||||
text-decoration: none;
|
||||
border-radius: 5px;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
margin: 20px 0;
|
||||
}
|
||||
.footer {
|
||||
text-align: center;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid #eee;
|
||||
color: #7f8c8d;
|
||||
font-size: 14px;
|
||||
}
|
||||
.note {
|
||||
background-color: #fff3cd;
|
||||
border-left: 4px solid #ffc107;
|
||||
padding: 10px;
|
||||
margin: 15px 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>Invoice</h1>
|
||||
</div>
|
||||
<div class="content">
|
||||
<p>Dear {{ customer_name }},</p>
|
||||
<p>Thank you for your business with {{ company_name }}. Please find your invoice details below:</p>
|
||||
|
||||
<div class="invoice-details">
|
||||
<h2>Invoice Details</h2>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Invoice Number:</span>
|
||||
<span>{{ invoice_number }}</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Invoice Date:</span>
|
||||
<span>{{ invoice_date }}</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Due Date:</span>
|
||||
<span>{{ due_date }}</span>
|
||||
</div>
|
||||
{% if sales_order %}
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Related Sales Order:</span>
|
||||
<span>{{ sales_order }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Invoice Total:</span>
|
||||
<span>{{ grand_total }}</span>
|
||||
</div>
|
||||
{% if paid_amount and paid_amount != "$0.00" %}
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Amount Paid:</span>
|
||||
<span>{{ paid_amount }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">Amount Due:</span>
|
||||
<span>{{ outstanding_amount }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if payment_url and outstanding_amount != "$0.00" %}
|
||||
<div class="note">
|
||||
<strong>Payment Required:</strong> There is an outstanding balance on this invoice. Please click the button below to make a secure payment.
|
||||
</div>
|
||||
<a href="{{ payment_url }}" class="cta-button">Pay Now</a>
|
||||
{% else %}
|
||||
<div class="note">
|
||||
<strong>Paid in Full:</strong> This invoice has been paid in full. Thank you!
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<p>If you have any questions about this invoice, please don't hesitate to contact us.</p>
|
||||
<p>Best regards,<br>The Team at {{ company_name }}</p>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<p>This is an automated email. Please do not reply directly.</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@ -1 +1,141 @@
|
||||
<p>Payment cancelled.</p>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Payment Cancelled</title>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Roboto', sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #333;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
}
|
||||
.payment-container {
|
||||
text-align: center;
|
||||
background-color: #fff;
|
||||
padding: 50px;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
|
||||
max-width: 500px;
|
||||
width: 90%;
|
||||
position: relative;
|
||||
}
|
||||
.cancelled-icon {
|
||||
font-size: 5rem;
|
||||
color: #e74c3c;
|
||||
margin-bottom: 30px;
|
||||
animation: cancelledAnimation 1.5s ease-out;
|
||||
}
|
||||
|
||||
@keyframes cancelledAnimation {
|
||||
0% {
|
||||
transform: scale(0) rotate(180deg);
|
||||
opacity: 0;
|
||||
}
|
||||
50% {
|
||||
transform: scale(1.2) rotate(0deg);
|
||||
opacity: 1;
|
||||
}
|
||||
70% {
|
||||
transform: scale(0.9) rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
transform: scale(1) rotate(0deg);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.payment-title {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.payment-message {
|
||||
font-size: 1.2rem;
|
||||
line-height: 1.6;
|
||||
margin-bottom: 30px;
|
||||
color: #666;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.cancelled-notice {
|
||||
background-color: #ffeaea;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
margin-top: 30px;
|
||||
border: 1px solid #f5c6cb;
|
||||
}
|
||||
|
||||
.cancelled-notice h3 {
|
||||
margin: 0 0 10px 0;
|
||||
color: #721c24;
|
||||
font-size: 1.3rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.cancelled-notice p {
|
||||
margin: 0;
|
||||
color: #721c24;
|
||||
font-weight: 400;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.next-steps {
|
||||
background-color: #f8f9fa;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
margin-top: 20px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.next-steps h4 {
|
||||
margin: 0 0 15px 0;
|
||||
color: #333;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.next-steps ul {
|
||||
margin: 0;
|
||||
padding-left: 20px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.next-steps li {
|
||||
margin-bottom: 8px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="payment-container">
|
||||
<div class="cancelled-icon">✕</div>
|
||||
<h1 class="payment-title">Payment Cancelled</h1>
|
||||
<p class="payment-message">Your payment has been cancelled.</p>
|
||||
|
||||
<div class="cancelled-notice">
|
||||
<h3>Payment Not Processed</h3>
|
||||
<p>No charges have been made to your account. If you cancelled by mistake or need assistance, please try again or contact support.</p>
|
||||
</div>
|
||||
|
||||
<div class="next-steps">
|
||||
<h4>What happens next?</h4>
|
||||
<ul>
|
||||
<li>No payment has been processed</li>
|
||||
<li>You can safely close this window</li>
|
||||
<li>Try your payment again if needed</li>
|
||||
<li>Contact us if you need help</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
141
custom_ui/www/payment_cancelled.html
Normal file
141
custom_ui/www/payment_cancelled.html
Normal file
@ -0,0 +1,141 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Payment Cancelled</title>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Roboto', sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #333;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
}
|
||||
.payment-container {
|
||||
text-align: center;
|
||||
background-color: #fff;
|
||||
padding: 50px;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
|
||||
max-width: 500px;
|
||||
width: 90%;
|
||||
position: relative;
|
||||
}
|
||||
.cancelled-icon {
|
||||
font-size: 5rem;
|
||||
color: #e74c3c;
|
||||
margin-bottom: 30px;
|
||||
animation: cancelledAnimation 1.5s ease-out;
|
||||
}
|
||||
|
||||
@keyframes cancelledAnimation {
|
||||
0% {
|
||||
transform: scale(0) rotate(180deg);
|
||||
opacity: 0;
|
||||
}
|
||||
50% {
|
||||
transform: scale(1.2) rotate(0deg);
|
||||
opacity: 1;
|
||||
}
|
||||
70% {
|
||||
transform: scale(0.9) rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
transform: scale(1) rotate(0deg);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.payment-title {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.payment-message {
|
||||
font-size: 1.2rem;
|
||||
line-height: 1.6;
|
||||
margin-bottom: 30px;
|
||||
color: #666;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.cancelled-notice {
|
||||
background-color: #ffeaea;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
margin-top: 30px;
|
||||
border: 1px solid #f5c6cb;
|
||||
}
|
||||
|
||||
.cancelled-notice h3 {
|
||||
margin: 0 0 10px 0;
|
||||
color: #721c24;
|
||||
font-size: 1.3rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.cancelled-notice p {
|
||||
margin: 0;
|
||||
color: #721c24;
|
||||
font-weight: 400;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.next-steps {
|
||||
background-color: #f8f9fa;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
margin-top: 20px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.next-steps h4 {
|
||||
margin: 0 0 15px 0;
|
||||
color: #333;
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.next-steps ul {
|
||||
margin: 0;
|
||||
padding-left: 20px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.next-steps li {
|
||||
margin-bottom: 8px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="payment-container">
|
||||
<div class="cancelled-icon">✕</div>
|
||||
<h1 class="payment-title">Payment Cancelled</h1>
|
||||
<p class="payment-message">Your payment has been cancelled.</p>
|
||||
|
||||
<div class="cancelled-notice">
|
||||
<h3>Payment Not Processed</h3>
|
||||
<p>No charges have been made to your account. If you cancelled by mistake or need assistance, please try again or contact support.</p>
|
||||
</div>
|
||||
|
||||
<div class="next-steps">
|
||||
<h4>What happens next?</h4>
|
||||
<ul>
|
||||
<li>No payment has been processed</li>
|
||||
<li>You can safely close this window</li>
|
||||
<li>Try your payment again if needed</li>
|
||||
<li>Contact us if you need help</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
0
custom_ui/www/payment_cancelled.py
Normal file
0
custom_ui/www/payment_cancelled.py
Normal file
212
custom_ui/www/payment_success.html
Normal file
212
custom_ui/www/payment_success.html
Normal file
@ -0,0 +1,212 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Payment Successful</title>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Roboto', sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #333;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
}
|
||||
.payment-container {
|
||||
text-align: center;
|
||||
background-color: #fff;
|
||||
padding: 50px;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
|
||||
max-width: 500px;
|
||||
width: 90%;
|
||||
position: relative;
|
||||
}
|
||||
.success-icon {
|
||||
font-size: 5rem;
|
||||
color: #00b894;
|
||||
margin-bottom: 30px;
|
||||
animation: checkmarkAnimation 1.5s ease-out;
|
||||
}
|
||||
|
||||
@keyframes checkmarkAnimation {
|
||||
0% {
|
||||
transform: scale(0) rotate(-180deg);
|
||||
opacity: 0;
|
||||
}
|
||||
50% {
|
||||
transform: scale(1.2) rotate(0deg);
|
||||
opacity: 1;
|
||||
}
|
||||
70% {
|
||||
transform: scale(0.9) rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
transform: scale(1) rotate(0deg);
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.payment-title {
|
||||
font-size: 2.5rem;
|
||||
margin-bottom: 20px;
|
||||
color: #333;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.payment-message {
|
||||
font-size: 1.2rem;
|
||||
line-height: 1.6;
|
||||
margin-bottom: 30px;
|
||||
color: #666;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.advance-notice {
|
||||
background-color: #e3f2fd;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
margin-top: 20px;
|
||||
border-left: 4px solid #2196f3;
|
||||
}
|
||||
|
||||
.contact-section {
|
||||
background-color: #f8f9fa;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
margin-top: 30px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.contact-section h3 {
|
||||
margin: 0 0 10px 0;
|
||||
color: #333;
|
||||
font-size: 1.3rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.contact-section > p {
|
||||
margin: 0 0 15px 0;
|
||||
color: #666;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.contact-details {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.contact-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 5px 0;
|
||||
border-bottom: 1px solid #e9ecef;
|
||||
}
|
||||
|
||||
.contact-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.contact-label {
|
||||
font-weight: 500;
|
||||
color: #495057;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.contact-value {
|
||||
font-weight: 400;
|
||||
color: #6c757d;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.contact-value a {
|
||||
color: #007bff;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.contact-value a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="payment-container">
|
||||
<div class="success-icon">✓</div>
|
||||
{% if reference_doc %}
|
||||
<h1 class="payment-title">
|
||||
{% if company_doc and company_doc.company_name %}
|
||||
{{ company_doc.company_name }}
|
||||
{% else %}
|
||||
Payment Received
|
||||
{% endif %}
|
||||
</h1>
|
||||
{% if reference_doc.doctype == "Sales Order" %}
|
||||
<p class="payment-message">
|
||||
{% if reference_doc.customer %}
|
||||
Thank you {{ reference_doc.customer }} for your advance payment!
|
||||
{% else %}
|
||||
Thank you for your advance payment!
|
||||
{% endif %}
|
||||
</p>
|
||||
<div class="advance-notice">
|
||||
<p>The remaining balance will be invoiced once the project is complete.</p>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="payment-message">
|
||||
{% if reference_doc.customer %}
|
||||
Thank you {{ reference_doc.customer }} for your payment!
|
||||
{% else %}
|
||||
Thank you for your payment!
|
||||
{% endif %}
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if company_doc %}
|
||||
<div class="contact-section">
|
||||
<h3>Have Questions?</h3>
|
||||
<p>We're here to help! Contact us if you need assistance.</p>
|
||||
<div class="contact-details">
|
||||
{% if company_doc.company_name %}
|
||||
<div class="contact-row">
|
||||
<span class="contact-label">Company:</span>
|
||||
<span class="contact-value">{{ company_doc.company_name }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if company_doc.phone_no %}
|
||||
<div class="contact-row">
|
||||
<span class="contact-label">Phone:</span>
|
||||
<span class="contact-value">{{ company_doc.phone_no }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if company_doc.email %}
|
||||
<div class="contact-row">
|
||||
<span class="contact-label">Email:</span>
|
||||
<span class="contact-value"><a href="mailto:{{ company_doc.email }}">{{ company_doc.email }}</a></span>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if company_doc.website %}
|
||||
<div class="contact-row">
|
||||
<span class="contact-label">Website:</span>
|
||||
<span class="contact-value"><a href="{{ company_doc.website }}" target="_blank">{{ company_doc.website }}</a></span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<h1 class="payment-title">Payment Received</h1>
|
||||
<p class="payment-message">Thank you for your payment!</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
18
custom_ui/www/payment_success.py
Normal file
18
custom_ui/www/payment_success.py
Normal file
@ -0,0 +1,18 @@
|
||||
import frappe
|
||||
|
||||
def get_context(context):
|
||||
context.no_cache = 1
|
||||
|
||||
context.title = "Payment Received"
|
||||
context.message = "Thank you for your payment! Your transaction was successful."
|
||||
|
||||
context.session_id = frappe.form_dict.get("session_id")
|
||||
|
||||
payment_entry = frappe.get_value("Payment Entry", {"reference_no": context.session_id}, "name")
|
||||
payment_entry_doc = frappe.get_doc("Payment Entry", payment_entry) if payment_entry else None
|
||||
reference = payment_entry_doc.references[0] if payment_entry_doc and payment_entry_doc.references else None
|
||||
reference_doc = frappe.get_doc(reference.reference_doctype, reference.reference_name) if reference else None
|
||||
company_doc = frappe.get_doc("Company", reference_doc.company) if reference_doc and reference_doc.company else None
|
||||
context.reference_doc = reference_doc.as_dict() if reference_doc else None
|
||||
context.company_doc = company_doc.as_dict() if company_doc else None
|
||||
return context
|
||||
@ -1 +0,0 @@
|
||||
<p>Thank you for your payment!</p>
|
||||
8
docker-compose.local.yaml
Normal file
8
docker-compose.local.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
services:
|
||||
mailhog:
|
||||
image: mailhog/mailhog:latest
|
||||
container_name: mailhog
|
||||
ports:
|
||||
- "8025:8025" # MailHog web UI
|
||||
- "1025:1025" # SMTP server
|
||||
restart: unless-stopped
|
||||
151
doctype_diff_report.md
Normal file
151
doctype_diff_report.md
Normal file
@ -0,0 +1,151 @@
|
||||
# DocType Field Differences Report
|
||||
|
||||
## Fields present in LOCAL but missing in STAGE
|
||||
|
||||
### Address
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| is_service_address | Is Service Address | Check | None | 0 | 0 | False |
|
||||
|
||||
### Event
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| participants | Participants | Section Break | None | 0 | 0 | False |
|
||||
|
||||
### Project
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| service_appointment | Service Appointment | Link | Service Address 2 | 0 | 0 | False |
|
||||
| tasks | Tasks | Table | Project Task Link | 0 | 0 | False |
|
||||
| ready_to_schedule | Ready to Schedule | Check | None | 0 | 0 | False |
|
||||
|
||||
### Project Template
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| bid_meeting_note_form | Bid Meeting Note Form | Link | Bid Meeting Note Form | 0 | 0 | False |
|
||||
| item_groups | Item Groups | Data | None | 0 | 0 | False |
|
||||
|
||||
### Quotation
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| from_template | From Template | Link | Quotation Template | 0 | 0 | False |
|
||||
| project_template | Project Template | Link | Project Template | 0 | 0 | False |
|
||||
|
||||
### Sales Invoice
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| project_template | Project Template | Link | Project Template | 0 | 0 | False |
|
||||
| job_address | Job Address | Link | Address | 0 | 0 | False |
|
||||
|
||||
### Task
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| customer | Customer | Link | Customer | 0 | 0 | False |
|
||||
|
||||
### Task Type
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| base_date | Base Date | Select | Start
|
||||
End
|
||||
Completion
|
||||
Creation | 1 | 0 | False |
|
||||
| offset_days | Offset Days | Int | None | 1 | 0 | False |
|
||||
| skip_weekends | Skip Weekends | Check | None | 0 | 0 | False |
|
||||
| skip_holidays | Skip Holidays | Check | None | 0 | 0 | False |
|
||||
| logic_key | Logic Key | Data | None | 0 | 0 | False |
|
||||
| offset_direction | Offset Direction | Select | After
|
||||
Before | 1 | 0 | False |
|
||||
| title | Title | Data | None | 1 | 0 | False |
|
||||
| days | Days | Int | None | 0 | 0 | False |
|
||||
| calculate_from | Calculate From | Select | Service Address 2
|
||||
Project
|
||||
Task | 1 | 0 | False |
|
||||
| trigger | Trigger | Select | Scheduled
|
||||
Completed
|
||||
Created | 1 | 0 | False |
|
||||
| task_type_calculate_from | Task Type For Task Calculate From | Link | Task Type | 0 | 0 | False |
|
||||
| work_type | Work Type | Select | Admin
|
||||
Labor
|
||||
QA | 1 | 0 | False |
|
||||
| no_due_date | No Due Date | Check | None | 0 | 0 | False |
|
||||
| triggering_doctype | Triggering Doctype | Select | Service Address 2
|
||||
Project
|
||||
Task | 1 | 0 | False |
|
||||
|
||||
## Fields present in STAGE but missing in LOCAL
|
||||
|
||||
### Communication Link
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| communication_date | Communication Date | Datetime | None | 0 | 0 | False |
|
||||
|
||||
### Event
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| notifications | Notifications | Table | Event Notifications | 0 | 0 | False |
|
||||
| location | Location | Data | None | 0 | 0 | False |
|
||||
| attending | Attending | Select |
|
||||
Yes
|
||||
No
|
||||
Maybe | 0 | 0 | False |
|
||||
| participants_tab | Participants | Tab Break | None | 0 | 0 | False |
|
||||
| links_tab | Links | Tab Break | None | 0 | 0 | False |
|
||||
| notifications_tab | Notifications | Tab Break | None | 0 | 0 | False |
|
||||
|
||||
### Event Notifications
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| type | Type | Select | Notification
|
||||
Email | 0 | 0 | False |
|
||||
| before | Before | Int | None | 0 | 0 | False |
|
||||
| interval | Interval | Select | None | 0 | 0 | False |
|
||||
| time | Time | Time | None | 0 | 0 | False |
|
||||
|
||||
### Event Participants
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| attending | Attending | Select |
|
||||
Yes
|
||||
No
|
||||
Maybe | 0 | 0 | False |
|
||||
|
||||
### Job Opening
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| job_opening_template | Job Opening Template | Link | Job Opening Template | 0 | 0 | False |
|
||||
|
||||
### Job Opening Template
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| template_title | Template Title | Data | None | 1 | 0 | False |
|
||||
| department | Department | Link | Department | 0 | 0 | False |
|
||||
| column_break_wkcr | None | Column Break | None | 0 | 0 | False |
|
||||
| employment_type | Employment Type | Link | Employment Type | 0 | 0 | False |
|
||||
| location | Location | Link | Branch | 0 | 0 | False |
|
||||
| section_break_dwfh | None | Section Break | None | 0 | 0 | False |
|
||||
| description | Description | Text Editor | None | 0 | 0 | False |
|
||||
|
||||
### Payment Ledger Entry
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| project | Project | Link | Project | 0 | 0 | False |
|
||||
|
||||
### Quotation Item
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| ordered_qty | Ordered Qty | Float | None | 1 | 1 | False |
|
||||
|
||||
### Salary Structure Assignment
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| leave_encashment_amount_per_day | Leave Encashment Amount Per Day | Currency | currency | 0 | 0 | False |
|
||||
|
||||
### Selling Settings
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| set_zero_rate_for_expired_batch | Set Incoming Rate as Zero for Expired Batch | Check | None | 0 | 0 | False |
|
||||
|
||||
### Service Appointment
|
||||
| Fieldname | Label | Fieldtype | Options | Required | Hidden | Custom Field |
|
||||
|-----------|-------|----------|---------|---------|--------|--------------|
|
||||
| custom_location_of_meeting | Service Address | Link | Address | 0 | 0 | False |
|
||||
@ -19,6 +19,9 @@ const FRAPPE_GET_ESTIMATE_TEMPLATES_METHOD = "custom_ui.api.db.estimates.get_est
|
||||
const FRAPPE_CREATE_ESTIMATE_TEMPLATE_METHOD = "custom_ui.api.db.estimates.create_estimate_template";
|
||||
const FRAPPE_GET_UNAPPROVED_ESTIMATES_COUNT_METHOD = "custom_ui.api.db.estimates.get_unapproved_estimates_count";
|
||||
const FRAPPE_GET_ESTIMATES_HALF_DOWN_COUNT_METHOD = "custom_ui.api.db.estimates.get_estimates_half_down_count";
|
||||
// Item methods
|
||||
const FRAPPE_SAVE_AS_PACKAGE_ITEM_METHOD = "custom_ui.api.db.items.save_as_package_item";
|
||||
const FRAPPE_GET_ITEMS_BY_PROJECT_TEMPLATE_METHOD = "custom_ui.api.db.items.get_by_project_template";
|
||||
// Job methods
|
||||
const FRAPPE_GET_JOB_METHOD = "custom_ui.api.db.jobs.get_job";
|
||||
const FRAPPE_GET_JOBS_METHOD = "custom_ui.api.db.jobs.get_jobs_table_data";
|
||||
@ -67,8 +70,10 @@ const FRAPPE_GET_EMPLOYEES_ORGANIZED_METHOD = "custom_ui.api.db.employees.get_em
|
||||
const FRAPPE_GET_WEEK_HOLIDAYS_METHOD = "custom_ui.api.db.general.get_week_holidays";
|
||||
const FRAPPE_GET_DOC_LIST_METHOD = "custom_ui.api.db.general.get_doc_list";
|
||||
// Service Appointment methods
|
||||
const FRAPPE_GET_SERVICE_APPOINTMENT_METHOD = "custom_ui.api.db.service_appointments.get_service_appointment";
|
||||
const FRAPPE_GET_SERVICE_APPOINTMENTS_METHOD = "custom_ui.api.db.service_appointments.get_service_appointments";
|
||||
const FRAPPE_UPDATE_SERVICE_APPOINTMENT_SCHEDULED_DATES_METHOD = "custom_ui.api.db.service_appointments.update_service_appointment_scheduled_dates";
|
||||
const FRAPPE_UPDATE_SERVICE_APPOINTMENT_STATUS_METHOD = "custom_ui.api.db.service_appointments.update_service_appointment_status";
|
||||
class Api {
|
||||
// ============================================================================
|
||||
// CORE REQUEST METHOPD
|
||||
@ -229,8 +234,8 @@ class Api {
|
||||
// ESTIMATE / QUOTATION METHODS
|
||||
// ============================================================================
|
||||
|
||||
static async getQuotationItems() {
|
||||
return await this.request("custom_ui.api.db.estimates.get_quotation_items");
|
||||
static async getQuotationItems(projectTemplate) {
|
||||
return await this.request("custom_ui.api.db.estimates.get_quotation_items", { projectTemplate });
|
||||
}
|
||||
|
||||
static async getEstimateFromAddress(fullAddress) {
|
||||
@ -454,6 +459,10 @@ class Api {
|
||||
// SERVICE APPOINTMENT METHODS
|
||||
// ============================================================================
|
||||
|
||||
static async getServiceAppointment(serviceAppointmentName) {
|
||||
return await this.request(FRAPPE_GET_SERVICE_APPOINTMENT_METHOD, { serviceAppointmentName });
|
||||
}
|
||||
|
||||
static async getServiceAppointments(companies = [], filters = {}) {
|
||||
return await this.request(FRAPPE_GET_SERVICE_APPOINTMENTS_METHOD, { companies, filters });
|
||||
}
|
||||
@ -469,6 +478,10 @@ class Api {
|
||||
})
|
||||
}
|
||||
|
||||
static async setServiceAppointmentStatus(serviceAppointmentName, newStatus) {
|
||||
return await this.request(FRAPPE_UPDATE_SERVICE_APPOINTMENT_STATUS_METHOD, { serviceAppointmentName, newStatus });
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// TASK METHODS
|
||||
// ============================================================================
|
||||
@ -657,6 +670,22 @@ class Api {
|
||||
return await this.request(FRAPPE_GET_ADDRESSES_METHOD, { fields, filters });
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// ITEM/PACKAGE METHODS
|
||||
// ============================================================================
|
||||
|
||||
static async getItemsByProjectTemplate(projectTemplate) {
|
||||
return await this.request(FRAPPE_GET_ITEMS_BY_PROJECT_TEMPLATE_METHOD, { projectTemplate });
|
||||
}
|
||||
|
||||
static async saveAsPackageItem(data) {
|
||||
return await this.request(FRAPPE_SAVE_AS_PACKAGE_ITEM_METHOD, { data });
|
||||
}
|
||||
|
||||
static async getItemCategories() {
|
||||
return await this.request("custom_ui.api.db.items.get_item_categories");
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// SERVICE / ROUTE / TIMESHEET METHODS
|
||||
// ============================================================================
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="calendar-navigation">
|
||||
<Tabs value="0" v-if="companyStore.currentCompany == 'Sprinklers Northwest'">
|
||||
<Tabs :value="defaultTab" v-if="companyStore.currentCompany == 'Sprinklers Northwest'">
|
||||
<TabList>
|
||||
<Tab value="0">Bids</Tab>
|
||||
<Tab value="1">Projects</Tab>
|
||||
@ -26,7 +26,7 @@
|
||||
</TabPanel>
|
||||
</TabPanels>
|
||||
</Tabs>
|
||||
<Tabs v-else value="0">
|
||||
<Tabs v-else :value="defaultTab">
|
||||
<TabList>
|
||||
<Tab value="0">Bids</Tab>
|
||||
<Tab value="1">Projects</Tab>
|
||||
@ -61,20 +61,36 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { ref, onMounted } from 'vue';
|
||||
import Tab from 'primevue/tab';
|
||||
import Tabs from 'primevue/tabs';
|
||||
import TabList from 'primevue/tablist';
|
||||
import TabPanel from 'primevue/tabpanel';
|
||||
import TabPanels from 'primevue/tabpanels';
|
||||
import ScheduleBid from '../calendar/bids/ScheduleBid.vue';
|
||||
import JobsCalendar from '../calendar/jobs/JobsCalendar.vue';
|
||||
import SNWProjectCalendar from './jobs/SNWProjectCalendar.vue';
|
||||
import { useNotificationStore } from '../../stores/notifications-primevue';
|
||||
import { useCompanyStore } from '../../stores/company';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
const notifications = useNotificationStore();
|
||||
const companyStore = useCompanyStore();
|
||||
const route = useRoute();
|
||||
|
||||
const defaultTab = ref('0');
|
||||
|
||||
const mappedTabs = {
|
||||
'bid': '0',
|
||||
'projects': '1',
|
||||
'service': '2',
|
||||
'warranties': companyStore.currentCompany == 'Sprinklers Northwest' ? '6' : '3'
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
// Check for route query parameter to set default tab
|
||||
if (route.query.tab) {
|
||||
defaultTab.value = mappedTabs[route.query.tab] || '0';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@ -17,6 +17,12 @@
|
||||
<span class="date-text">{{ weekDisplayText }}</span>
|
||||
<v-icon right size="small">mdi-calendar</v-icon>
|
||||
</v-btn>
|
||||
<v-btn
|
||||
@click="nextWeek"
|
||||
icon="mdi-chevron-right"
|
||||
variant="outlined"
|
||||
size="small"
|
||||
></v-btn>
|
||||
<v-btn @click="goToThisWeek" variant="outlined" size="small" class="ml-4">
|
||||
This Week
|
||||
</v-btn>
|
||||
@ -324,10 +330,14 @@ import { ref, onMounted, computed, watch } from "vue";
|
||||
import Api from "../../../api";
|
||||
import { useNotificationStore } from "../../../stores/notifications-primevue";
|
||||
import { useCompanyStore } from "../../../stores/company";
|
||||
import { useRoute } from "vue-router";
|
||||
import JobDetailsModal from "../../modals/JobDetailsModal.vue";
|
||||
|
||||
const notifications = useNotificationStore();
|
||||
const companyStore = useCompanyStore();
|
||||
const route = useRoute();
|
||||
|
||||
const serviceAptToFind = route.query.apt || null;
|
||||
|
||||
// Reactive data
|
||||
const scheduledServices = ref([]);
|
||||
@ -991,13 +1001,14 @@ const handleDrop = async (event, foremanId, date) => {
|
||||
await Api.updateServiceAppointmentScheduledDates(
|
||||
draggedService.value.name,
|
||||
date,
|
||||
draggedService.value.expectedEndDate, // Keep the same end date
|
||||
date, // Reset to single day when moved
|
||||
foreman.name
|
||||
);
|
||||
// Update the scheduled job
|
||||
scheduledServices.value[scheduledIndex] = {
|
||||
...scheduledServices.value[scheduledIndex],
|
||||
expectedStartDate: date,
|
||||
expectedEndDate: date, // Reset to single day
|
||||
foreman: foreman.name
|
||||
};
|
||||
notifications.addSuccess("Job moved successfully!");
|
||||
@ -1174,9 +1185,10 @@ const handleResize = (event) => {
|
||||
// Calculate proposed end date by adding days to the CURRENT end date
|
||||
let proposedEndDate = addDays(currentEndDate, daysToAdd);
|
||||
|
||||
// Don't allow shrinking before the current end date (minimum stay at current)
|
||||
if (daysToAdd < 0) {
|
||||
proposedEndDate = currentEndDate;
|
||||
// Don't allow shrinking before the start date
|
||||
const startDate = resizingJob.value.expectedStartDate;
|
||||
if (parseLocalDate(proposedEndDate) < parseLocalDate(startDate)) {
|
||||
proposedEndDate = startDate;
|
||||
}
|
||||
|
||||
let newEndDate = proposedEndDate;
|
||||
@ -1294,6 +1306,40 @@ const stopResize = async () => {
|
||||
originalEndDate.value = null;
|
||||
};
|
||||
|
||||
const handleServiceAptToFind = async () => {
|
||||
if (!serviceAptToFind) return;
|
||||
|
||||
try {
|
||||
// Fetch the specific service appointment
|
||||
const appointment = await Api.getServiceAppointment(serviceAptToFind);
|
||||
|
||||
if (appointment && appointment.expectedStartDate) {
|
||||
// Navigate to the week containing this appointment
|
||||
weekStartDate.value = getWeekStart(parseLocalDate(appointment.expectedStartDate));
|
||||
|
||||
// Wait for data to load
|
||||
await fetchServiceAppointments();
|
||||
|
||||
// Find the appointment in the loaded data
|
||||
const foundAppointment = scheduledServices.value.find(s => s.name === serviceAptToFind) ||
|
||||
unscheduledServices.value.find(s => s.name === serviceAptToFind);
|
||||
|
||||
if (foundAppointment) {
|
||||
// Open the details modal
|
||||
selectedEvent.value = foundAppointment;
|
||||
eventDialog.value = true;
|
||||
} else {
|
||||
notifications.addWarning("Service appointment found but not visible in current filters");
|
||||
}
|
||||
} else {
|
||||
notifications.addWarning("Service appointment not scheduled yet");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error finding service appointment:", error);
|
||||
notifications.addError("Failed to find service appointment");
|
||||
}
|
||||
};
|
||||
|
||||
const fetchServiceAppointments = async (currentDate) => {
|
||||
try {
|
||||
// Calculate date range for the week
|
||||
@ -1306,13 +1352,14 @@ const fetchServiceAppointments = async (currentDate) => {
|
||||
{
|
||||
"expectedStartDate": ["<=", endDate],
|
||||
"expectedEndDate": [">=", startDate],
|
||||
"status": ["not in", ["Canceled"]]
|
||||
"status": ["not in", ["Canceled", "Open"]]
|
||||
}
|
||||
);
|
||||
unscheduledServices.value = await Api.getServiceAppointments(
|
||||
[companyStore.currentCompany],
|
||||
{
|
||||
"status": "Open"
|
||||
"status": "Open",
|
||||
"ready_to_schedule": 1
|
||||
}
|
||||
);
|
||||
|
||||
@ -1388,6 +1435,9 @@ onMounted(async () => {
|
||||
// await fetchProjects();
|
||||
await fetchServiceAppointments();
|
||||
await fetchHolidays();
|
||||
|
||||
// Handle serviceAptToFind query parameter
|
||||
await handleServiceAptToFind();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
167
frontend/src/components/common/ItemSelector.vue
Normal file
167
frontend/src/components/common/ItemSelector.vue
Normal file
@ -0,0 +1,167 @@
|
||||
<template>
|
||||
<div class="items-container">
|
||||
<div v-if="items.length === 0" class="no-items-message">
|
||||
<i class="pi pi-inbox"></i>
|
||||
<p>{{ emptyMessage }}</p>
|
||||
</div>
|
||||
<div v-else v-for="item in items" :key="item.itemCode" class="item-card" :class="{ 'item-selected': isItemSelected(item.itemCode) }" @click="handleItemClick(item, $event)">
|
||||
<div class="item-card-header">
|
||||
<span class="item-code">{{ item.itemCode }}</span>
|
||||
<span class="item-name">{{ item.itemName }}</span>
|
||||
<span class="item-price">${{ item.standardRate?.toFixed(2) || '0.00' }}</span>
|
||||
<Button
|
||||
:label="isItemSelected(item.itemCode) ? 'Selected' : 'Select'"
|
||||
:icon="isItemSelected(item.itemCode) ? 'pi pi-check' : 'pi pi-plus'"
|
||||
@click.stop="handleItemClick(item, $event)"
|
||||
size="small"
|
||||
:severity="isItemSelected(item.itemCode) ? 'success' : 'secondary'"
|
||||
class="select-item-button"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="item.description" class="item-description">
|
||||
{{ item.description }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch, computed, shallowRef } from "vue";
|
||||
import Button from "primevue/button";
|
||||
|
||||
const props = defineProps({
|
||||
items: {
|
||||
type: Array,
|
||||
required: true,
|
||||
default: () => []
|
||||
},
|
||||
selectedItems: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
},
|
||||
emptyMessage: {
|
||||
type: String,
|
||||
default: "No items found in this category"
|
||||
}
|
||||
});
|
||||
|
||||
const emit = defineEmits(['select']);
|
||||
|
||||
const internalSelection = ref([]);
|
||||
const selectionSet = shallowRef(new Set());
|
||||
|
||||
// Sync internal selection with prop
|
||||
watch(() => props.selectedItems, (newVal) => {
|
||||
internalSelection.value = [...newVal];
|
||||
selectionSet.value = new Set(newVal.map(item => item.itemCode));
|
||||
}, { immediate: true });
|
||||
|
||||
const isItemSelected = (itemCode) => {
|
||||
return selectionSet.value.has(itemCode);
|
||||
};
|
||||
|
||||
const handleItemClick = (item, event) => {
|
||||
// Always multi-select mode - toggle item in selection
|
||||
const index = internalSelection.value.findIndex(i => i.itemCode === item.itemCode);
|
||||
const newSet = new Set(selectionSet.value);
|
||||
|
||||
if (index >= 0) {
|
||||
internalSelection.value.splice(index, 1);
|
||||
newSet.delete(item.itemCode);
|
||||
} else {
|
||||
internalSelection.value.push(item);
|
||||
newSet.add(item.itemCode);
|
||||
}
|
||||
|
||||
// Update Set directly instead of recreating from array
|
||||
selectionSet.value = newSet;
|
||||
// Emit the entire selection array
|
||||
emit('select', [...internalSelection.value]);
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.items-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
height: 100%;
|
||||
overflow-y: scroll;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.no-items-message {
|
||||
text-align: center;
|
||||
padding: 3rem 2rem;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.no-items-message i {
|
||||
font-size: 3em;
|
||||
color: #ccc;
|
||||
margin-bottom: 1rem;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.no-items-message p {
|
||||
margin: 0;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.item-card {
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 6px;
|
||||
padding: 0.75rem;
|
||||
background-color: #fafafa;
|
||||
transition: all 0.2s ease;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.item-card:hover {
|
||||
background-color: #f0f0f0;
|
||||
border-color: #2196f3;
|
||||
}
|
||||
|
||||
.item-selected {
|
||||
background-color: #e3f2fd;
|
||||
border-color: #2196f3;
|
||||
border-width: 2px;
|
||||
}
|
||||
|
||||
.item-card-header {
|
||||
display: grid;
|
||||
grid-template-columns: 150px 1fr 120px 100px;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.item-code {
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
font-family: monospace;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.item-name {
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.item-price {
|
||||
font-weight: 600;
|
||||
color: #2196f3;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.select-item-button {
|
||||
justify-self: end;
|
||||
}
|
||||
|
||||
.item-description {
|
||||
margin-top: 0.5rem;
|
||||
padding-top: 0.5rem;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
color: #666;
|
||||
font-size: 0.9rem;
|
||||
line-height: 1.4;
|
||||
}
|
||||
</style>
|
||||
649
frontend/src/components/modals/AddItemModal.vue
Normal file
649
frontend/src/components/modals/AddItemModal.vue
Normal file
@ -0,0 +1,649 @@
|
||||
<template>
|
||||
<Modal
|
||||
:visible="visible"
|
||||
@update:visible="$emit('update:visible', $event)"
|
||||
@close="handleClose"
|
||||
:options="{ showActions: false, maxWidth: '90vw', width: '1350px' }"
|
||||
class="add-item-modal"
|
||||
>
|
||||
<template #title>
|
||||
<div class="modal-title-container">
|
||||
<span>Add Item</span>
|
||||
<span v-if="selectedItemsCount > 0" class="selection-badge">{{ selectedItemsCount }} selected</span>
|
||||
</div>
|
||||
</template>
|
||||
<div class="modal-content items-modal-content">
|
||||
<div class="search-section">
|
||||
<label for="item-search" class="field-label">Search Items</label>
|
||||
<InputText
|
||||
id="item-search"
|
||||
v-model="searchTerm"
|
||||
placeholder="Search by item code or name..."
|
||||
fluid
|
||||
/>
|
||||
</div>
|
||||
<div class="tabs-container">
|
||||
<Tabs v-model="activeItemTab" v-if="itemGroups.length > 0 || packageGroups.length > 0">
|
||||
<TabList>
|
||||
<Tab v-if="packageGroups.length > 0" value="Packages">
|
||||
<i class="pi pi-box"></i>
|
||||
<span>Packages</span>
|
||||
</Tab>
|
||||
<Tab v-for="group in itemGroups" :key="group" :value="group">{{ group }}</Tab>
|
||||
</TabList>
|
||||
<TabPanels>
|
||||
<!-- Packages tab with nested sub-tabs -->
|
||||
<TabPanel v-if="packageGroups.length > 0" value="Packages">
|
||||
<Tabs v-model="activePackageTab" class="nested-tabs">
|
||||
<TabList>
|
||||
<Tab v-for="packageGroup in packageGroups" :key="packageGroup" :value="packageGroup">{{ packageGroup }}</Tab>
|
||||
</TabList>
|
||||
<TabPanels>
|
||||
<TabPanel v-for="packageGroup in packageGroups" :key="packageGroup" :value="packageGroup">
|
||||
<div class="package-items-container">
|
||||
<div v-for="item in getFilteredPackageItemsForGroup(packageGroup)" :key="item.itemCode" class="package-item" :class="{ 'package-item-selected': item._selected }">
|
||||
<div class="package-item-header">
|
||||
<Button
|
||||
:icon="isPackageExpanded(item.itemCode) ? 'pi pi-chevron-down' : 'pi pi-chevron-right'"
|
||||
@click="togglePackageExpansion(item.itemCode)"
|
||||
text
|
||||
rounded
|
||||
class="expand-button"
|
||||
/>
|
||||
<span class="package-item-code">{{ item.itemCode }}</span>
|
||||
<span class="package-item-name">{{ item.itemName }}</span>
|
||||
<span class="package-item-price">${{ item.standardRate?.toFixed(2) || '0.00' }}</span>
|
||||
<Button
|
||||
:label="item._selected ? 'Selected' : 'Select'"
|
||||
:icon="item._selected ? 'pi pi-check' : 'pi pi-plus'"
|
||||
@click="handleItemSelection(item)"
|
||||
size="small"
|
||||
:severity="item._selected ? 'success' : 'secondary'"
|
||||
class="add-package-button"
|
||||
/>
|
||||
</div>
|
||||
<div v-if="isPackageExpanded(item.itemCode) && item.bom && item.bom.items" class="bom-details">
|
||||
<div class="bom-header">Bill of Materials:</div>
|
||||
<div v-for="bomItem in item.bom.items" :key="bomItem.itemCode" class="bom-item-wrapper">
|
||||
<BomItem :item="bomItem" :parentPath="item.itemCode" :level="0" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</TabPanel>
|
||||
</TabPanels>
|
||||
</Tabs>
|
||||
</TabPanel>
|
||||
<!-- Regular category tabs -->
|
||||
<TabPanel v-for="group in itemGroups" :key="group" :value="group">
|
||||
<ItemSelector
|
||||
:items="getFilteredItemsForGroup(group)"
|
||||
:selected-items="getSelectedItemsForGroup(group)"
|
||||
@select="handleItemSelection"
|
||||
/>
|
||||
</TabPanel>
|
||||
</TabPanels>
|
||||
</Tabs>
|
||||
<!-- Fallback if no categories -->
|
||||
<ItemSelector v-else :items="[]" empty-message="No items available. Please select a Project Template first." />
|
||||
</div>
|
||||
<div class="modal-actions">
|
||||
<Button
|
||||
label="Clear Selection"
|
||||
@click="clearSelection"
|
||||
severity="secondary"
|
||||
:disabled="selectedItemsCount === 0"
|
||||
/>
|
||||
<Button
|
||||
:label="`Add ${selectedItemsCount} Item${selectedItemsCount !== 1 ? 's' : ''}`"
|
||||
@click="addItems"
|
||||
icon="pi pi-plus"
|
||||
:disabled="selectedItemsCount === 0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, watch, defineComponent, h, shallowRef } from "vue";
|
||||
import Modal from "../common/Modal.vue";
|
||||
import ItemSelector from "../common/ItemSelector.vue";
|
||||
import InputText from "primevue/inputtext";
|
||||
import Button from "primevue/button";
|
||||
import Tabs from "primevue/tabs";
|
||||
import TabList from "primevue/tablist";
|
||||
import Tab from "primevue/tab";
|
||||
import TabPanels from "primevue/tabpanels";
|
||||
import TabPanel from "primevue/tabpanel";
|
||||
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
required: true
|
||||
},
|
||||
quotationItems: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
}
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:visible', 'add-items']);
|
||||
|
||||
const searchTerm = ref("");
|
||||
const expandedPackageItems = shallowRef(new Set());
|
||||
const selectedItemsInModal = shallowRef(new Set());
|
||||
|
||||
// BomItem component for recursive rendering
|
||||
const BomItem = defineComponent({
|
||||
name: 'BomItem',
|
||||
props: {
|
||||
item: Object,
|
||||
parentPath: String,
|
||||
level: {
|
||||
type: Number,
|
||||
default: 0
|
||||
}
|
||||
},
|
||||
setup(props) {
|
||||
const itemPath = computed(() => {
|
||||
return props.parentPath ? `${props.parentPath}.${props.item.itemCode}` : props.item.itemCode;
|
||||
});
|
||||
|
||||
const isPackage = computed(() => {
|
||||
return props.item.bom && props.item.bom.items && props.item.bom.items.length > 0;
|
||||
});
|
||||
|
||||
const isExpanded = computed(() => {
|
||||
return expandedPackageItems.value.has(itemPath.value);
|
||||
});
|
||||
|
||||
const toggleExpansion = () => {
|
||||
if (expandedPackageItems.value.has(itemPath.value)) {
|
||||
expandedPackageItems.value.delete(itemPath.value);
|
||||
} else {
|
||||
expandedPackageItems.value.add(itemPath.value);
|
||||
}
|
||||
expandedPackageItems.value = new Set(expandedPackageItems.value);
|
||||
};
|
||||
|
||||
return () => h('div', {
|
||||
class: 'bom-item',
|
||||
style: { paddingLeft: `${props.level * 1}rem` }
|
||||
}, [
|
||||
h('div', { class: 'bom-item-content' }, [
|
||||
isPackage.value ? h(Button, {
|
||||
icon: isExpanded.value ? 'pi pi-chevron-down' : 'pi pi-chevron-right',
|
||||
onClick: toggleExpansion,
|
||||
text: true,
|
||||
rounded: true,
|
||||
size: 'small',
|
||||
class: 'bom-expand-button'
|
||||
}) : h('i', { class: 'pi pi-circle-fill bom-item-bullet' }),
|
||||
isPackage.value ? h('i', { class: 'pi pi-box package-icon' }) : null,
|
||||
h('span', { class: 'bom-item-code' }, props.item.itemCode),
|
||||
h('span', { class: 'bom-item-name' }, props.item.itemName),
|
||||
h('span', { class: 'bom-item-qty' }, `Qty: ${props.item.qty}`)
|
||||
]),
|
||||
isPackage.value && isExpanded.value && props.item.bom?.items ? h('div', { class: 'nested-bom' },
|
||||
props.item.bom.items.map(nestedItem =>
|
||||
h(BomItem, {
|
||||
key: nestedItem.itemCode,
|
||||
item: nestedItem,
|
||||
parentPath: itemPath.value,
|
||||
level: props.level + 1
|
||||
})
|
||||
)
|
||||
) : null
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
const itemGroups = computed(() => {
|
||||
if (!props.quotationItems || typeof props.quotationItems !== 'object') return [];
|
||||
// Get all keys except 'Packages'
|
||||
const groups = Object.keys(props.quotationItems).filter(key => key !== 'Packages').sort();
|
||||
return groups;
|
||||
});
|
||||
|
||||
const packageGroups = computed(() => {
|
||||
if (!props.quotationItems?.Packages || typeof props.quotationItems.Packages !== 'object') return [];
|
||||
return Object.keys(props.quotationItems.Packages).sort();
|
||||
});
|
||||
|
||||
// Active tabs with default to Packages
|
||||
const activeItemTab = computed({
|
||||
get: () => _activeItemTab.value || (packageGroups.value.length > 0 ? "Packages" : itemGroups.value[0]) || "",
|
||||
set: (val) => { _activeItemTab.value = val; }
|
||||
});
|
||||
|
||||
const activePackageTab = computed({
|
||||
get: () => _activePackageTab.value || packageGroups.value[0] || "",
|
||||
set: (val) => { _activePackageTab.value = val; }
|
||||
});
|
||||
|
||||
const _activeItemTab = ref("");
|
||||
const _activePackageTab = ref("");
|
||||
|
||||
const getFilteredItemsForGroup = (group) => {
|
||||
if (!props.quotationItems || typeof props.quotationItems !== 'object') return [];
|
||||
|
||||
let items = [];
|
||||
|
||||
// Get items from the specified group
|
||||
if (group && props.quotationItems[group]) {
|
||||
items = [...props.quotationItems[group]];
|
||||
}
|
||||
|
||||
// Filter by search term
|
||||
if (searchTerm.value.trim()) {
|
||||
const term = searchTerm.value.toLowerCase();
|
||||
items = items.filter(
|
||||
(item) =>
|
||||
item.itemCode?.toLowerCase().includes(term) ||
|
||||
item.itemName?.toLowerCase().includes(term),
|
||||
);
|
||||
}
|
||||
|
||||
// Map items and mark those that are selected
|
||||
return items.map((item) => ({
|
||||
...item,
|
||||
id: item.itemCode
|
||||
}));
|
||||
};
|
||||
|
||||
const getSelectedItemsForGroup = (group) => {
|
||||
if (selectedItemsInModal.value.size === 0) return [];
|
||||
const allItems = getFilteredItemsForGroup(group);
|
||||
return allItems.filter(item => selectedItemsInModal.value.has(item.itemCode));
|
||||
};
|
||||
|
||||
const getFilteredPackageItemsForGroup = (packageGroup) => {
|
||||
if (!props.quotationItems?.Packages || typeof props.quotationItems.Packages !== 'object') return [];
|
||||
|
||||
let items = [];
|
||||
|
||||
// Get items from the specified package group
|
||||
if (packageGroup && props.quotationItems.Packages[packageGroup]) {
|
||||
items = [...props.quotationItems.Packages[packageGroup]];
|
||||
}
|
||||
|
||||
// Filter by search term
|
||||
if (searchTerm.value.trim()) {
|
||||
const term = searchTerm.value.toLowerCase();
|
||||
items = items.filter(
|
||||
(item) =>
|
||||
item.itemCode?.toLowerCase().includes(term) ||
|
||||
item.itemName?.toLowerCase().includes(term),
|
||||
);
|
||||
}
|
||||
|
||||
return items.map((item) => ({
|
||||
...item,
|
||||
id: item.itemCode,
|
||||
_selected: selectedItemsInModal.value.has(item.itemCode)
|
||||
}));
|
||||
};
|
||||
|
||||
const selectedItemsCount = computed(() => selectedItemsInModal.value.size);
|
||||
|
||||
const togglePackageExpansion = (itemCode) => {
|
||||
const newExpanded = new Set(expandedPackageItems.value);
|
||||
if (newExpanded.has(itemCode)) {
|
||||
newExpanded.delete(itemCode);
|
||||
} else {
|
||||
newExpanded.add(itemCode);
|
||||
}
|
||||
expandedPackageItems.value = newExpanded;
|
||||
};
|
||||
|
||||
const isPackageExpanded = (itemCode) => {
|
||||
return expandedPackageItems.value.has(itemCode);
|
||||
};
|
||||
|
||||
const handleItemSelection = (itemOrRows) => {
|
||||
// Handle both single item (from package cards) and array (from DataTable)
|
||||
if (Array.isArray(itemOrRows)) {
|
||||
// From ItemSelector - merge with existing selection
|
||||
const newSelection = new Set(selectedItemsInModal.value);
|
||||
const itemCodes = itemOrRows.map(row => row.itemCode);
|
||||
|
||||
// Check if all items are already selected
|
||||
const allSelected = itemCodes.every(code => newSelection.has(code));
|
||||
|
||||
if (allSelected) {
|
||||
// Deselect all items
|
||||
itemCodes.forEach(code => newSelection.delete(code));
|
||||
} else {
|
||||
// Select all items
|
||||
itemCodes.forEach(code => newSelection.add(code));
|
||||
}
|
||||
|
||||
selectedItemsInModal.value = newSelection;
|
||||
} else {
|
||||
// From package card - toggle single item
|
||||
const newSelection = new Set(selectedItemsInModal.value);
|
||||
if (newSelection.has(itemOrRows.itemCode)) {
|
||||
newSelection.delete(itemOrRows.itemCode);
|
||||
} else {
|
||||
newSelection.add(itemOrRows.itemCode);
|
||||
}
|
||||
selectedItemsInModal.value = newSelection;
|
||||
}
|
||||
};
|
||||
|
||||
const clearSelection = () => {
|
||||
selectedItemsInModal.value = new Set();
|
||||
};
|
||||
|
||||
const addItems = () => {
|
||||
// Get all selected items from all categories
|
||||
const allItems = [];
|
||||
|
||||
// Collect from regular categories
|
||||
if (props.quotationItems && typeof props.quotationItems === 'object') {
|
||||
Object.keys(props.quotationItems).forEach(key => {
|
||||
if (key !== 'Packages' && Array.isArray(props.quotationItems[key])) {
|
||||
props.quotationItems[key].forEach(item => {
|
||||
if (selectedItemsInModal.value.has(item.itemCode)) {
|
||||
allItems.push(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Collect from Packages sub-categories
|
||||
if (props.quotationItems.Packages && typeof props.quotationItems.Packages === 'object') {
|
||||
Object.keys(props.quotationItems.Packages).forEach(subKey => {
|
||||
if (Array.isArray(props.quotationItems.Packages[subKey])) {
|
||||
props.quotationItems.Packages[subKey].forEach(item => {
|
||||
if (selectedItemsInModal.value.has(item.itemCode)) {
|
||||
allItems.push(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (allItems.length > 0) {
|
||||
emit('add-items', allItems);
|
||||
selectedItemsInModal.value = new Set();
|
||||
}
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
selectedItemsInModal.value = new Set();
|
||||
searchTerm.value = "";
|
||||
emit('update:visible', false);
|
||||
};
|
||||
|
||||
// Watch modal visibility to reset state when closing
|
||||
watch(() => props.visible, (newVal) => {
|
||||
if (newVal) {
|
||||
// Modal is opening - reset to first tabs
|
||||
_activeItemTab.value = "";
|
||||
_activePackageTab.value = "";
|
||||
} else {
|
||||
// Modal is closing - reset state
|
||||
selectedItemsInModal.value = new Set();
|
||||
searchTerm.value = "";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.items-modal-content {
|
||||
height: 70vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.tabs-container {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.tabs-container :deep(.p-tabs) {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.tabs-container :deep(.p-tabpanels) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.tabs-container :deep(.p-tabpanel) {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.search-section {
|
||||
/* margin removed - parent gap handles spacing */
|
||||
}
|
||||
|
||||
.field-label {
|
||||
display: block;
|
||||
margin-bottom: 0.5rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.tip-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.75rem;
|
||||
background-color: #e3f2fd;
|
||||
border: 1px solid #2196f3;
|
||||
border-radius: 4px;
|
||||
color: #1565c0;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.tip-section i {
|
||||
color: #2196f3;
|
||||
}
|
||||
|
||||
.tip-section kbd {
|
||||
background-color: #fff;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 3px;
|
||||
padding: 2px 6px;
|
||||
font-family: monospace;
|
||||
font-size: 0.85em;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.modal-title-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.modal-title-container :deep(.p-tab) {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.selection-badge {
|
||||
background-color: #2196f3;
|
||||
color: white;
|
||||
padding: 0.25rem 0.75rem;
|
||||
border-radius: 12px;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.modal-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 0.75rem;
|
||||
padding-top: 1rem;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.nested-tabs {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.nested-tabs :deep(.p-tabs) {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.nested-tabs :deep(.p-tabpanels) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.nested-tabs :deep(.p-tabpanel) {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.package-items-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
height: 100%;
|
||||
overflow-y: scroll;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.package-item {
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 6px;
|
||||
padding: 0.75rem;
|
||||
background-color: #fafafa;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.package-item:hover {
|
||||
background-color: #f0f0f0;
|
||||
border-color: #2196f3;
|
||||
}
|
||||
|
||||
.package-item-selected {
|
||||
background-color: #e3f2fd;
|
||||
border-color: #2196f3;
|
||||
border-width: 2px;
|
||||
}
|
||||
|
||||
.package-item-header {
|
||||
display: grid;
|
||||
grid-template-columns: 40px 120px 1fr 100px 80px;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.expand-button {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
}
|
||||
|
||||
.package-item-code {
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.package-item-name {
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.package-item-price {
|
||||
font-weight: 600;
|
||||
color: #2196f3;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.add-package-button {
|
||||
justify-self: end;
|
||||
}
|
||||
|
||||
.bom-details {
|
||||
margin-top: 0.75rem;
|
||||
padding: 0.75rem;
|
||||
background-color: #fff;
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.bom-header {
|
||||
font-weight: 600;
|
||||
margin-bottom: 0.5rem;
|
||||
color: #666;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.bom-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.bom-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.bom-item-content {
|
||||
display: grid;
|
||||
grid-template-columns: 32px 24px 120px 1fr 100px;
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.bom-expand-button {
|
||||
width: 1.5rem;
|
||||
height: 1.5rem;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.bom-item-bullet {
|
||||
font-size: 0.4rem;
|
||||
color: #ccc;
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
|
||||
.package-icon {
|
||||
color: #2196f3;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.bom-item-code {
|
||||
font-family: monospace;
|
||||
color: #666;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.bom-item-name {
|
||||
color: #555;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.bom-item-qty {
|
||||
color: #888;
|
||||
font-size: 0.85rem;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.nested-bom {
|
||||
background-color: #fafafa;
|
||||
border-left: 2px solid #e0e0e0;
|
||||
margin-left: 1rem;
|
||||
}
|
||||
</style>
|
||||
@ -20,24 +20,27 @@
|
||||
|
||||
<div v-else-if="formConfig" class="form-container">
|
||||
<Button @click="debugLog" label="Debug" severity="secondary" size="small" class="debug-button" />
|
||||
<template v-for="row in groupedFields" :key="`row-${row.rowIndex}`">
|
||||
<div class="form-row">
|
||||
<div
|
||||
v-for="field in row.fields"
|
||||
:key="field.name"
|
||||
:class="`form-column-${Math.min(Math.max(field.columns || 12, 1), 12)}`"
|
||||
>
|
||||
<div class="form-field">
|
||||
<!-- Field Label -->
|
||||
<label :for="field.name" class="field-label">
|
||||
{{ field.label }}
|
||||
<span v-if="field.required" class="required-indicator">*</span>
|
||||
</label>
|
||||
<div
|
||||
v-for="row in groupedFields"
|
||||
:key="`row-${row.rowIndex}`"
|
||||
class="form-row"
|
||||
>
|
||||
<div
|
||||
v-for="field in row.fields"
|
||||
:key="field.name"
|
||||
:class="`form-column-${Math.min(Math.max(field.columns || 12, 1), 12)}`"
|
||||
>
|
||||
<div class="form-field">
|
||||
<!-- Field Label -->
|
||||
<label :for="field.name" class="field-label">
|
||||
{{ field.label }}
|
||||
<span v-if="field.required" class="required-indicator">*</span>
|
||||
</label>
|
||||
|
||||
<!-- Help Text -->
|
||||
<small v-if="field.helpText" class="field-help-text">
|
||||
{{ field.helpText }}
|
||||
</small>
|
||||
<!-- Help Text -->
|
||||
<small v-if="field.helpText" class="field-help-text">
|
||||
{{ field.helpText }}
|
||||
</small>
|
||||
|
||||
<!-- Data/Text Field -->
|
||||
<template v-if="field.type === 'Data' || field.type === 'Text'">
|
||||
@ -211,10 +214,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="error-container">
|
||||
@ -573,7 +575,7 @@ const loadDoctypeOptions = async () => {
|
||||
for (const field of fieldsWithDoctype) {
|
||||
try {
|
||||
// Use the new API method for fetching docs
|
||||
let docs = await Api.getQuotationItems();
|
||||
let docs = await Api.getQuotationItems(props.projectTemplate);
|
||||
|
||||
// Deduplicate by value field
|
||||
const valueField = field.doctypeValueField || 'name';
|
||||
|
||||
@ -187,6 +187,17 @@
|
||||
<v-icon left>mdi-open-in-new</v-icon>
|
||||
View Job
|
||||
</v-btn>
|
||||
<v-btn
|
||||
v-if="job.status !== 'Completed'"
|
||||
color="success"
|
||||
variant="flat"
|
||||
@click="updateStatus('Completed')"
|
||||
:loading="isUpdatingStatus"
|
||||
:disabled="isUpdatingStatus"
|
||||
>
|
||||
<v-icon left>mdi-check-circle</v-icon>
|
||||
Mark as Completed
|
||||
</v-btn>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn variant="text" @click="handleClose">Close</v-btn>
|
||||
</v-card-actions>
|
||||
@ -196,6 +207,10 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from "vue";
|
||||
import Api from "../../api";
|
||||
import { useNotificationStore } from "../../stores/notifications-primevue";
|
||||
|
||||
const notifications = useNotificationStore();
|
||||
|
||||
// Props
|
||||
const props = defineProps({
|
||||
@ -214,7 +229,10 @@ const props = defineProps({
|
||||
});
|
||||
|
||||
// Emits
|
||||
const emit = defineEmits(["update:modelValue", "close"]);
|
||||
const emit = defineEmits(["update:modelValue", "close", "statusUpdated"]);
|
||||
|
||||
// State
|
||||
const isUpdatingStatus = ref(false);
|
||||
|
||||
// Computed
|
||||
const showModal = computed({
|
||||
@ -304,6 +322,34 @@ const getPriorityColor = (priority) => {
|
||||
}
|
||||
};
|
||||
|
||||
const updateStatus = async (newStatus) => {
|
||||
if (!props.job?.name) return;
|
||||
|
||||
isUpdatingStatus.value = true;
|
||||
try {
|
||||
await Api.setServiceAppointmentStatus(props.job.name, newStatus);
|
||||
notifications.addSuccess(`Service appointment marked as ${newStatus}`);
|
||||
|
||||
// Update local job status
|
||||
if (props.job) {
|
||||
props.job.status = newStatus;
|
||||
}
|
||||
|
||||
// Emit event to parent to refresh data
|
||||
emit("statusUpdated", { name: props.job.name, status: newStatus });
|
||||
|
||||
// Close modal after short delay
|
||||
setTimeout(() => {
|
||||
handleClose();
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
console.error("Error updating service appointment status:", error);
|
||||
notifications.addError("Failed to update service appointment status");
|
||||
} finally {
|
||||
isUpdatingStatus.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const viewJob = () => {
|
||||
if (props.job?.name) {
|
||||
window.location.href = `/job?name=${encodeURIComponent(props.job.name)}`;
|
||||
|
||||
382
frontend/src/components/modals/SavePackageModal.vue
Normal file
382
frontend/src/components/modals/SavePackageModal.vue
Normal file
@ -0,0 +1,382 @@
|
||||
<template>
|
||||
<Modal
|
||||
:visible="visible"
|
||||
@update:visible="$emit('update:visible', $event)"
|
||||
@close="handleClose"
|
||||
:options="{ showActions: false }"
|
||||
>
|
||||
<template #title>Save as Package</template>
|
||||
<div class="modal-content">
|
||||
<div class="form-section">
|
||||
<label for="packageName" class="field-label">
|
||||
Package Name
|
||||
<span class="required">*</span>
|
||||
</label>
|
||||
<InputText
|
||||
id="packageName"
|
||||
v-model="formData.packageName"
|
||||
placeholder="Enter package name"
|
||||
fluid
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-section">
|
||||
<label for="description" class="field-label">
|
||||
Description
|
||||
</label>
|
||||
<InputText
|
||||
id="description"
|
||||
v-model="formData.description"
|
||||
placeholder="Enter package description (optional)"
|
||||
fluid
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-section">
|
||||
<label for="codePrefix" class="field-label">
|
||||
Code Prefix
|
||||
<span class="required">*</span>
|
||||
</label>
|
||||
<Select
|
||||
id="codePrefix"
|
||||
v-model="formData.codePrefix"
|
||||
:options="codePrefixOptions"
|
||||
placeholder="Select a code prefix"
|
||||
fluid
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-section">
|
||||
<label for="category" class="field-label">
|
||||
Category
|
||||
<span class="required">*</span>
|
||||
</label>
|
||||
<Select
|
||||
id="category"
|
||||
v-model="formData.category"
|
||||
:options="categories"
|
||||
placeholder="Select a category"
|
||||
fluid
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-section">
|
||||
<label for="rate" class="field-label">
|
||||
Rate
|
||||
<span class="required">*</span>
|
||||
</label>
|
||||
<InputNumber
|
||||
id="rate"
|
||||
v-model="formData.rate"
|
||||
mode="currency"
|
||||
currency="USD"
|
||||
locale="en-US"
|
||||
:min="0"
|
||||
placeholder="$0.00"
|
||||
fluid
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-section">
|
||||
<h4>Package Contents</h4>
|
||||
<div v-if="items.length === 0" class="no-items">
|
||||
No items selected
|
||||
</div>
|
||||
<div v-else class="items-list">
|
||||
<div
|
||||
v-for="(item, index) in items"
|
||||
:key="index"
|
||||
class="package-item"
|
||||
>
|
||||
<div class="item-header" @click="toggleItemExpansion(index)">
|
||||
<div class="item-info">
|
||||
<i
|
||||
v-if="isPackage(item)"
|
||||
:class="[
|
||||
'pi',
|
||||
expandedItems.has(index) ? 'pi-chevron-down' : 'pi-chevron-right',
|
||||
'expand-icon'
|
||||
]"
|
||||
></i>
|
||||
<span class="item-name">{{ item.itemName || item.itemCode }}</span>
|
||||
<span v-if="isPackage(item)" class="package-badge">Package</span>
|
||||
</div>
|
||||
<span class="item-qty">Qty: {{ item.qty || 1 }}</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="isPackage(item) && expandedItems.has(index)"
|
||||
class="package-contents"
|
||||
>
|
||||
<div
|
||||
v-for="(bomItem, bomIndex) in item.bom"
|
||||
:key="bomIndex"
|
||||
class="bom-item"
|
||||
>
|
||||
<span class="bom-item-name">{{ bomItem.itemName || bomItem.itemCode }}</span>
|
||||
<span class="bom-item-qty">Qty: {{ bomItem.qty || 1 }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="action-buttons">
|
||||
<Button label="Cancel" @click="handleClose" severity="secondary" />
|
||||
<Button
|
||||
label="Save Package"
|
||||
@click="handleSave"
|
||||
:disabled="!isFormValid"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, computed, watch } from "vue";
|
||||
import Modal from "../common/Modal.vue";
|
||||
import InputText from "primevue/inputtext";
|
||||
import InputNumber from "primevue/inputnumber";
|
||||
import Button from "primevue/button";
|
||||
import Select from "primevue/select";
|
||||
import Api from "../../api";
|
||||
import { useNotificationStore } from "../../stores/notifications-primevue";
|
||||
|
||||
const props = defineProps({
|
||||
visible: {
|
||||
type: Boolean,
|
||||
required: true,
|
||||
},
|
||||
items: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
defaultRate: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
});
|
||||
|
||||
const emit = defineEmits(["update:visible", "save"]);
|
||||
|
||||
const notificationStore = useNotificationStore();
|
||||
|
||||
const formData = reactive({
|
||||
packageName: "",
|
||||
description: "",
|
||||
codePrefix: null,
|
||||
category: null,
|
||||
rate: null,
|
||||
});
|
||||
|
||||
const codePrefixOptions = ref(["BLDR", "SNW-I"]);
|
||||
const categories = ref([]);
|
||||
const expandedItems = ref(new Set());
|
||||
const isLoading = ref(false);
|
||||
|
||||
const isFormValid = computed(() => {
|
||||
return formData.packageName.trim() !== "" &&
|
||||
formData.codePrefix !== null &&
|
||||
formData.category !== null &&
|
||||
formData.rate !== null &&
|
||||
formData.rate > 0;
|
||||
});
|
||||
|
||||
const isPackage = (item) => {
|
||||
return item.bom && Array.isArray(item.bom) && item.bom.length > 0;
|
||||
};
|
||||
|
||||
const toggleItemExpansion = (index) => {
|
||||
const item = props.items[index];
|
||||
if (!isPackage(item)) return;
|
||||
|
||||
if (expandedItems.value.has(index)) {
|
||||
expandedItems.value.delete(index);
|
||||
} else {
|
||||
expandedItems.value.add(index);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchCategories = async () => {
|
||||
try {
|
||||
isLoading.value = true;
|
||||
const result = await Api.getItemCategories();
|
||||
categories.value = result || [];
|
||||
} catch (error) {
|
||||
console.error("Error fetching item categories:", error);
|
||||
notificationStore.addNotification("Failed to fetch item categories", "error");
|
||||
categories.value = [];
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
// Reset form
|
||||
formData.packageName = "";
|
||||
formData.description = "";
|
||||
formData.codePrefix = null;
|
||||
formData.category = null;
|
||||
formData.rate = null;
|
||||
expandedItems.value.clear();
|
||||
emit("update:visible", false);
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
if (!isFormValid.value) {
|
||||
notificationStore.addNotification("Please fill in all required fields", "error");
|
||||
return;
|
||||
}
|
||||
|
||||
const packageData = {
|
||||
packageName: formData.packageName,
|
||||
description: formData.description,
|
||||
codePrefix: formData.codePrefix,
|
||||
category: formData.category,
|
||||
rate: formData.rate,
|
||||
items: props.items.map(item => ({
|
||||
itemCode: item.itemCode,
|
||||
itemName: item.itemName,
|
||||
qty: item.qty || 1,
|
||||
uom: item.uom || item.stockUom,
|
||||
})),
|
||||
};
|
||||
|
||||
emit("save", packageData);
|
||||
handleClose();
|
||||
};
|
||||
|
||||
// Watch for modal opening to fetch categories
|
||||
watch(
|
||||
() => props.visible,
|
||||
(newVal) => {
|
||||
if (newVal) {
|
||||
fetchCategories();
|
||||
// Set rate to defaultRate when modal opens
|
||||
if (props.defaultRate > 0) {
|
||||
formData.rate = props.defaultRate;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.modal-content {
|
||||
padding: 1.5rem;
|
||||
max-height: 70vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.form-section {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.field-label {
|
||||
display: block;
|
||||
margin-bottom: 0.5rem;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.required {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.no-items {
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
color: #666;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.items-list {
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.package-item {
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.package-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.item-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0.75rem 1rem;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
.item-header:hover {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
.item-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.expand-icon {
|
||||
font-size: 0.8rem;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.item-name {
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.package-badge {
|
||||
display: inline-block;
|
||||
padding: 0.2rem 0.5rem;
|
||||
background-color: #e3f2fd;
|
||||
color: #1976d2;
|
||||
border-radius: 4px;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.item-qty {
|
||||
color: #666;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.package-contents {
|
||||
background-color: #f8f9fa;
|
||||
padding: 0.5rem 1rem 0.5rem 2.5rem;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.bom-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 0.5rem 0;
|
||||
color: #666;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.bom-item-name {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.bom-item-qty {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
justify-content: flex-end;
|
||||
margin-top: 1.5rem;
|
||||
padding-top: 1rem;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
}
|
||||
</style>
|
||||
@ -318,9 +318,9 @@ const handleSubmit = async () => {
|
||||
const createdClient = await Api.createClient(client.value);
|
||||
console.log("Created client:", createdClient);
|
||||
notificationStore.addSuccess("Client created successfully!");
|
||||
stripped_name = createdClient.customerName.split("-#-")[0].trim();
|
||||
const strippedName = createdClient.name.split("-#-")[0].trim();
|
||||
// Navigate to the created client
|
||||
router.push('/client?client=' + encodeURIComponent(stripped_name));
|
||||
router.push('/client?client=' + encodeURIComponent(strippedName));
|
||||
} else {
|
||||
// TODO: Implement save logic
|
||||
notificationStore.addSuccess("Changes saved successfully!");
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -136,9 +136,9 @@ const chartData = ref({
|
||||
})
|
||||
|
||||
const columns = [
|
||||
{ label: "Job ID", fieldName: "name", type: "text", sortable: true, filterable: true },
|
||||
{ label: "Address", fieldName: "jobAddress", type: "text", sortable: true },
|
||||
{ label: "Customer", fieldName: "customer", type: "text", sortable: true, filterable: true },
|
||||
{ label: "Address", fieldName: "jobAddress", type: "text", sortable: true },
|
||||
{ label: "Job ID", fieldName: "name", type: "text", sortable: true, filterable: true },
|
||||
{ label: "Overall Status", fieldName: "status", type: "status", sortable: true },
|
||||
{ label: "Invoice Status", fieldName: "invoiceStatus", type: "text", sortable: true },
|
||||
{ label: "Progress", fieldName: "percentComplete", type: "text", sortable: true }
|
||||
@ -275,7 +275,6 @@ const loadChartData = async () => {
|
||||
|
||||
// Load initial data
|
||||
onMounted(async () => {
|
||||
notifications.addWarning("Jobs page coming soon");
|
||||
// Initialize pagination and filters
|
||||
paginationStore.initializeTablePagination("jobs", { rows: 10 });
|
||||
filtersStore.initializeTableFilters("jobs", columns);
|
||||
|
||||
115
stripe-init-webhook.sh
Normal file
115
stripe-init-webhook.sh
Normal file
@ -0,0 +1,115 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to initialize and run Stripe CLI webhook forwarding
|
||||
# Usage: ./stripe-init-webhook.sh --site <site> --port <port>
|
||||
|
||||
set -e
|
||||
|
||||
# Default values
|
||||
SITE=""
|
||||
PORT="8000"
|
||||
|
||||
# Parse command line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--site)
|
||||
SITE="$2"
|
||||
shift 2
|
||||
;;
|
||||
--port)
|
||||
PORT="$2"
|
||||
shift 2
|
||||
;;
|
||||
-h|--help)
|
||||
echo "Usage: $0 --site <site> [--port <port>]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --site Required. The site domain (e.g., erp.local)"
|
||||
echo " --port Optional. The port number (default: 8000)"
|
||||
echo ""
|
||||
echo "Example:"
|
||||
echo " $0 --site erp.local --port 8000"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
echo "Use --help for usage information"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check if required flag is provided
|
||||
if [ -z "$SITE" ]; then
|
||||
echo "Error: --site flag is required"
|
||||
echo "Usage: $0 --site <site> [--port <port>]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Checking Stripe CLI installation..."
|
||||
|
||||
# Check if Stripe CLI is installed
|
||||
if ! command -v stripe &> /dev/null; then
|
||||
echo "Stripe CLI is not installed."
|
||||
read -p "Would you like to install it now? (y/n) " -n 1 -r
|
||||
echo
|
||||
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo "Installing Stripe CLI..."
|
||||
|
||||
# Add GPG key
|
||||
echo "Adding Stripe GPG key..."
|
||||
curl -s https://packages.stripe.dev/api/security/keypair/stripe-cli-gpg/public | gpg --dearmor | sudo tee /usr/share/keyrings/stripe.gpg > /dev/null
|
||||
|
||||
# Add repository
|
||||
echo "Adding Stripe repository..."
|
||||
echo "deb [signed-by=/usr/share/keyrings/stripe.gpg] https://packages.stripe.dev/stripe-cli-debian-local stable main" | sudo tee -a /etc/apt/sources.list.d/stripe.list
|
||||
|
||||
# Update and install
|
||||
echo "Updating package list..."
|
||||
sudo apt update
|
||||
|
||||
echo "Installing Stripe CLI..."
|
||||
sudo apt install stripe -y
|
||||
|
||||
echo "Stripe CLI installed successfully!"
|
||||
else
|
||||
echo "Installation cancelled. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Stripe CLI is already installed."
|
||||
fi
|
||||
|
||||
# Check if Stripe CLI is authenticated
|
||||
echo "Checking authentication status..."
|
||||
if ! stripe config --list &> /dev/null; then
|
||||
echo "Stripe CLI is not authenticated."
|
||||
echo "Please log in to your Stripe account..."
|
||||
stripe login --interactive
|
||||
else
|
||||
# Try to verify authentication by running a simple command
|
||||
if stripe config --list | grep -q "test_mode_api_key"; then
|
||||
echo "Stripe CLI is authenticated."
|
||||
else
|
||||
echo "Stripe CLI authentication may be invalid."
|
||||
echo "Please log in to your Stripe account..."
|
||||
stripe login --interactive
|
||||
fi
|
||||
fi
|
||||
|
||||
# Start Docker containers
|
||||
echo ""
|
||||
echo "Starting Docker containers..."
|
||||
docker compose -f docker-compose.local.yaml up -d
|
||||
|
||||
# Start listening for webhooks
|
||||
WEBHOOK_URL="http://${SITE}:${PORT}/api/method/custom_ui.api.public.payments.stripe_webhook"
|
||||
echo ""
|
||||
echo "Starting Stripe webhook listener..."
|
||||
echo "Forwarding to: $WEBHOOK_URL"
|
||||
echo ""
|
||||
echo "Press Ctrl+C to stop"
|
||||
echo ""
|
||||
|
||||
stripe listen --forward-to "$WEBHOOK_URL"
|
||||
150
stripe-local-init.sh
Executable file
150
stripe-local-init.sh
Executable file
@ -0,0 +1,150 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to initialize and run Stripe CLI webhook forwarding
|
||||
# Usage: ./stripe-init-webhook.sh --site <site> --port <port>
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
BLUE='\033[0;34m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Display banner
|
||||
echo ""
|
||||
echo -e "${BLUE}+-----------------------------------------------+${NC}"
|
||||
echo -e "${BLUE} ██████╗ ██╗ ██╗██╗██╗ ██████╗ ██╗ ██╗${NC}"
|
||||
echo -e "${BLUE} ██╔════╝ ██║ ██║██║██║ ██╔═══██╗██║ ██║${NC}"
|
||||
echo -e "${BLUE} ╚█████╗ ███████║██║██║ ██║ ██║███████║${NC}"
|
||||
echo -e "${BLUE} ╚═══██╗ ██╔══██║██║██║ ██║ ██║██╔══██║${NC}"
|
||||
echo -e "${BLUE} ██████╔╝ ██║ ██║██║███████╗╚██████╔╝██║ ██║${NC}"
|
||||
echo -e "${BLUE} ╚═════╝ ╚═╝ ╚═╝╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝${NC}"
|
||||
echo -e "${BLUE}+-----------------------------------------------+${NC}"
|
||||
echo -e "${YELLOW} 🚀 Automated Local Stripe Environment${NC}"
|
||||
echo -e "${YELLOW} 💼 For ERPNext Development${NC}"
|
||||
echo -e "${BLUE}+-----------------------------------------------+${NC}"
|
||||
echo ""
|
||||
|
||||
# Default values
|
||||
SITE=""
|
||||
PORT="8000"
|
||||
|
||||
# Parse command line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--site)
|
||||
SITE="$2"
|
||||
shift 2
|
||||
;;
|
||||
--port)
|
||||
PORT="$2"
|
||||
shift 2
|
||||
;;
|
||||
-h|--help)
|
||||
echo "Usage: $0 --site <site> [--port <port>]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --site Required. The site domain (e.g., erp.local)"
|
||||
echo " --port Optional. The port number (default: 8000)"
|
||||
echo ""
|
||||
echo "Example:"
|
||||
echo " $0 --site erp.local --port 8000"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
echo "Use --help for usage information"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Check if required flag is provided
|
||||
if [ -z "$SITE" ]; then
|
||||
echo -e "${RED}❌ Error: --site flag is required${NC}"
|
||||
echo "Usage: $0 --site <site> [--port <port>]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${BLUE}🔍 Checking Stripe CLI installation...${NC}"
|
||||
|
||||
# Check if Stripe CLI is installed
|
||||
if ! command -v stripe &> /dev/null; then
|
||||
echo -e "${YELLOW}⚠️ Stripe CLI is not installed.${NC}"
|
||||
read -p "Would you like to install it now? (y/n) " -n 1 -r
|
||||
echo
|
||||
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
echo -e "${BLUE}📦 Installing Stripe CLI...${NC}"
|
||||
|
||||
# Add GPG key
|
||||
echo -e "${BLUE}🔑 Adding Stripe GPG key...${NC}"
|
||||
curl -s https://packages.stripe.dev/api/security/keypair/stripe-cli-gpg/public | gpg --dearmor | sudo tee /usr/share/keyrings/stripe.gpg > /dev/null
|
||||
|
||||
# Add repository
|
||||
echo -e "${BLUE}📚 Adding Stripe repository...${NC}"
|
||||
echo "deb [signed-by=/usr/share/keyrings/stripe.gpg] https://packages.stripe.dev/stripe-cli-debian-local stable main" | sudo tee -a /etc/apt/sources.list.d/stripe.list
|
||||
|
||||
# Update and install
|
||||
echo -e "${BLUE}🔄 Updating package list...${NC}"
|
||||
sudo apt update
|
||||
|
||||
echo -e "${BLUE}⬇️ Installing Stripe CLI...${NC}"
|
||||
sudo apt install stripe -y
|
||||
|
||||
echo -e "${GREEN}✅ Stripe CLI installed successfully!${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Installation cancelled. Exiting.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo -e "${GREEN}✅ Stripe CLI is already installed.${NC}"
|
||||
fi
|
||||
|
||||
# Check if Stripe CLI is authenticated
|
||||
echo -e "${BLUE}🔐 Checking authentication status...${NC}"
|
||||
if ! stripe config --list &> /dev/null; then
|
||||
echo -e "${YELLOW}⚠️ Stripe CLI is not authenticated.${NC}"
|
||||
echo -e "${BLUE}🔑 Please log in to your Stripe account...${NC}"
|
||||
stripe login --interactive
|
||||
else
|
||||
# Try to verify authentication by running a simple command
|
||||
if stripe config --list | grep -q "test_mode_api_key"; then
|
||||
echo -e "${GREEN}✅ Stripe CLI is authenticated.${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Stripe CLI authentication may be invalid.${NC}"
|
||||
echo -e "${BLUE}🔑 Please log in to your Stripe account...${NC}"
|
||||
stripe login --interactive
|
||||
fi
|
||||
fi
|
||||
|
||||
# Start Docker containers
|
||||
echo ""
|
||||
echo -e "${BLUE}🐳 Starting Docker containers...${NC}"
|
||||
docker compose -f docker-compose.local.yaml up -d
|
||||
|
||||
# Cleanup function to run on exit
|
||||
cleanup() {
|
||||
echo ""
|
||||
echo -e "${YELLOW}🛑 Shutting down...${NC}"
|
||||
echo -e "${BLUE}🐳 Stopping Docker containers...${NC}"
|
||||
docker compose -f docker-compose.local.yaml down
|
||||
echo -e "${GREEN}✨ Cleanup complete. Goodbye!${NC}"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Trap Ctrl+C (SIGINT) and termination signals
|
||||
trap cleanup SIGINT SIGTERM EXIT
|
||||
|
||||
# Start listening for webhooks
|
||||
WEBHOOK_URL="http://${SITE}:${PORT}/api/method/custom_ui.api.public.payments.stripe_webhook"
|
||||
echo ""
|
||||
echo -e "${GREEN}🎧 Starting Stripe webhook listener...${NC}"
|
||||
echo -e "${BLUE}📡 Forwarding to: ${YELLOW}$WEBHOOK_URL${NC}"
|
||||
echo ""
|
||||
echo -e "${YELLOW}⌨️ Press Ctrl+C to stop${NC}"
|
||||
echo ""
|
||||
|
||||
stripe listen --forward-to "$WEBHOOK_URL"
|
||||
Loading…
x
Reference in New Issue
Block a user