estimate handling, percentage discounts

This commit is contained in:
Casey 2025-12-23 08:12:37 -06:00
parent 9c837deb52
commit b8c264f779
10 changed files with 1365 additions and 31 deletions

View file

@ -65,7 +65,38 @@ def get_estimate(estimate_name):
"""Get detailed information for a specific estimate.""" """Get detailed information for a specific estimate."""
try: try:
estimate = frappe.get_doc("Quotation", estimate_name) estimate = frappe.get_doc("Quotation", estimate_name)
return build_success_response(estimate.as_dict()) est_dict = estimate.as_dict()
address_name = estimate.custom_installation_address or estimate.customer_address
if address_name:
# Fetch Address Doc
address_doc = frappe.get_doc("Address", address_name).as_dict()
est_dict["full_address"] = address_doc.get("full_address")
# Logic from get_address_by_full_address to populate customer and contacts
customer_exists = frappe.db.exists("Customer", address_doc.get("custom_customer_to_bill"))
doctype = "Customer" if customer_exists else "Lead"
name = ""
if doctype == "Customer":
name = address_doc.get("custom_customer_to_bill")
else:
lead_links = address_doc.get("links", [])
lead_name = [link.link_name for link in lead_links if link.link_doctype == "Lead"]
name = lead_name[0] if lead_name else ""
if name:
address_doc["customer"] = frappe.get_doc(doctype, name).as_dict()
contacts = []
if address_doc.get("custom_linked_contacts"):
for contact_link in address_doc.get("custom_linked_contacts"):
contact_doc = frappe.get_doc("Contact", contact_link.contact)
contacts.append(contact_doc.as_dict())
address_doc["contacts"] = contacts
est_dict["address_details"] = address_doc
return build_success_response(est_dict)
except Exception as e: except Exception as e:
return build_error_response(str(e), 500) return build_error_response(str(e), 500)
@ -202,7 +233,7 @@ def update_response(name, response):
estimate.custom_response = response estimate.custom_response = response
estimate.custom_current_status = new_status estimate.custom_current_status = new_status
estimate.custom_followup_needed = 1 if response == "Requested call" else 0 estimate.custom_followup_needed = 1 if response == "Requested call" else 0
estimate.status = "Ordered" if accepted else "Closed" # estimate.status = "Ordered" if accepted else "Closed"
estimate.flags.ignore_permissions = True estimate.flags.ignore_permissions = True
print("DEBUG: Updating estimate with response:", response, "and status:", new_status) print("DEBUG: Updating estimate with response:", response, "and status:", new_status)
estimate.save() estimate.save()
@ -222,7 +253,7 @@ def update_response(name, response):
return Response(html, mimetype="text/html") return Response(html, mimetype="text/html")
except Exception as e: except Exception as e:
template = "custom_ui/templates/estimates/error.html" template = "custom_ui/templates/estimates/error.html"
html = frappe.render_template(template, {"error_message": str(e)}) html = frappe.render_template(template, {"error": str(e)})
return Response(html, mimetype="text/html") return Response(html, mimetype="text/html")
@ -236,6 +267,7 @@ def upsert_estimate(data):
print("DEBUG: Upsert estimate data:", data) print("DEBUG: Upsert estimate data:", data)
estimate_name = data.get("estimate_name") estimate_name = data.get("estimate_name")
is_customer = True if frappe.db.exists("Customer", data.get("customer")) else False
# If estimate_name exists, update existing estimate # If estimate_name exists, update existing estimate
if estimate_name: if estimate_name:
@ -244,7 +276,8 @@ def upsert_estimate(data):
# Update fields # Update fields
estimate.custom_installation_address = data.get("address_name") estimate.custom_installation_address = data.get("address_name")
estimate.party_name = data.get("contact_name") estimate.party_name = data.get("customer")
estimate.contact_person = data.get("contact_name")
estimate.custom_requires_half_payment = data.get("requires_half_payment", 0) estimate.custom_requires_half_payment = data.get("requires_half_payment", 0)
# Clear existing items and add new ones # Clear existing items and add new ones
@ -254,6 +287,8 @@ def upsert_estimate(data):
estimate.append("items", { estimate.append("items", {
"item_code": item.get("item_code"), "item_code": item.get("item_code"),
"qty": item.get("qty"), "qty": item.get("qty"),
"discount_amount": item.get("discount_amount") or item.get("discountAmount", 0),
"discount_percentage": item.get("discount_percentage") or item.get("discountPercentage", 0)
}) })
estimate.save() estimate.save()
@ -267,18 +302,24 @@ def upsert_estimate(data):
new_estimate = frappe.get_doc({ new_estimate = frappe.get_doc({
"doctype": "Quotation", "doctype": "Quotation",
"custom_requires_half_payment": data.get("requires_half_payment", 0), "custom_requires_half_payment": data.get("requires_half_payment", 0),
"custom_installation_address": data.get("address_name"), # "custom_installation_address": data.get("address_name"),
"custom_current_status": "Draft", "custom_current_status": "Draft",
"contact_email": data.get("contact_email"), "contact_email": data.get("contact_email"),
"party_name": data.get("contact_name"), "party_name": data.get("customer"),
"company": "Sprinklers Northwest", "quotation_to": "Customer" if is_customer else "Lead",
"customer_name": data.get("customer_name"), "company": data.get("company"),
"customer_name": data.get("customer"),
"customer_address": data.get("address_name"),
"contact_person": data.get("contact_name"),
"letter_head": "company",
}) })
for item in data.get("items", []): for item in data.get("items", []):
item = json.loads(item) if isinstance(item, str) else item item = json.loads(item) if isinstance(item, str) else item
new_estimate.append("items", { new_estimate.append("items", {
"item_code": item.get("item_code"), "item_code": item.get("item_code"),
"qty": item.get("qty"), "qty": item.get("qty"),
"discount_amount": item.get("discount_amount") or item.get("discountAmount", 0),
"discount_percentage": item.get("discount_percentage") or item.get("discountPercentage", 0)
}) })
new_estimate.insert() new_estimate.insert()
print("DEBUG: New estimate created with name:", new_estimate.name) print("DEBUG: New estimate created with name:", new_estimate.name)
@ -287,3 +328,12 @@ def upsert_estimate(data):
print(f"DEBUG: Error in upsert_estimate: {str(e)}") print(f"DEBUG: Error in upsert_estimate: {str(e)}")
return build_error_response(str(e), 500) return build_error_response(str(e), 500)
# @frappe.whitelist()
# def get_estimate_counts():
# """Get specific counts of estimates based on their status."""
# try:
# counts = {
# "total_estimates": frappe.db.count("Quotation"),
# "ready_to_"
# }

View file

@ -3,6 +3,51 @@ import os
import subprocess import subprocess
import frappe import frappe
from custom_ui.utils import create_module from custom_ui.utils import create_module
from custom_ui.db_utils import search_any_field
@click.command("update-data")
@click.option("--site", default=None, help="Site to update data for")
def update_data(site):
address_names = frappe.get_all("Address", pluck="name")
total_addresses = len(address_names)
updated_addresses = 0
updated_contacts = 0
updated_customers = 0
total_updated_fields = 0
skipped = 0
for address_name in address_names:
should_update = False
address = frappe.get_doc("Address", address_name)
customer_name = address.custom_customer_to_bill
customer_links = [link for link in address.get("links", []) if link.link_doctype == "Customer"]
# lead_links = [link for link in address.get("links", []) if link.link_doctype == "Lead"]
contact_links = [link for link in address.get("links", []) if link.link_doctype == "Contact"] + address.get("custom_linked_contacts", [])
if frappe.db.exists("Customer", customer_name):
customer = frappe.get_doc("Customer", customer_name)
else:
lead_names = frappe.get_all("Lead", filters={"lead_name": customer_name}, pluck="name")
customer_name = lead_names[0] if lead_names else None
customer = frappe.get_doc("Lead", customer_name) if customer_name else None
if not customer_links and customer and customer.doctype == "Customer":
address.append("links", {
"link_doctype": customer.doctype,
"link_name": customer.name
})
updated_addresses += 1
should_update = True
elif not lead_links and customer and customer.doctype == "Lead":
address.append("links", {
"link_doctype": customer.doctype,
"link_name": customer.name
})
updated_addresses += 1
should_update = True
@click.command("build-frontend") @click.command("build-frontend")
@click.option("--site", default=None, help="Site to build frontend for") @click.option("--site", default=None, help="Site to build frontend for")

View file

@ -1,4 +1,5 @@
import frappe
import json import json
def map_field_name(frontend_field): def map_field_name(frontend_field):
@ -195,3 +196,30 @@ def map_lead_update(client_data):
client_data[lead_field] = client_data[client_field] client_data[lead_field] = client_data[client_field]
return client_data return client_data
def search_any_field(doctype, text):
meta = frappe.get_meta(doctype)
like = f"%{text}%"
conditions = []
# 1⃣ Explicitly include `name`
conditions.append("`name` LIKE %s")
# 2⃣ Include searchable DocFields
for field in meta.fields:
if field.fieldtype in ("Data", "Small Text", "Text", "Link"):
conditions.append(f"`{field.fieldname}` LIKE %s")
query = f"""
SELECT name
FROM `tab{doctype}`
WHERE {" OR ".join(conditions)}
LIMIT 20
"""
return frappe.db.sql(
query,
[like] * len(conditions),
as_dict=True
)

View file

@ -33,7 +33,13 @@ def on_update_after_submit(doc, method):
try: try:
new_sales_order = make_sales_order(doc.name) new_sales_order = make_sales_order(doc.name)
new_sales_order.custom_requires_half_payment = doc.requires_half_payment new_sales_order.custom_requires_half_payment = doc.requires_half_payment
new_sales_order.payment_schedule = []
print("DEBUG: Setting payment schedule for Sales Order")
new_sales_order.set_payment_schedule()
print("DEBUG: Inserting Sales Order:", new_sales_order.as_dict())
new_sales_order.delivery_date = new_sales_order.transaction_date
new_sales_order.insert() new_sales_order.insert()
print("DEBUG: Submitting Sales Order")
new_sales_order.submit() new_sales_order.submit()
print("DEBUG: Sales Order created successfully:", new_sales_order.name) print("DEBUG: Sales Order created successfully:", new_sales_order.name)
except Exception as e: except Exception as e:

View file

@ -0,0 +1,59 @@
[
{
"allow_in_quick_entry": 0,
"allow_on_submit": 1,
"bold": 0,
"collapsible": 0,
"collapsible_depends_on": null,
"columns": 0,
"default": null,
"depends_on": null,
"description": null,
"docstatus": 0,
"doctype": "Custom Field",
"dt": "Quotation",
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "custom_quotation_template",
"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": 0,
"in_preview": 0,
"in_standard_filter": 0,
"insert_after": "amended_from",
"is_system_generated": 0,
"is_virtual": 0,
"label": "Quotation Template",
"length": 0,
"link_filters": null,
"mandatory_depends_on": null,
"modified": "2025-12-23 02:28:02.771813",
"module": null,
"name": "Quotation-custom_quotation_template",
"no_copy": 0,
"non_negative": 0,
"options": "Quotation Template",
"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
}
]

View file

@ -0,0 +1,974 @@
[
{
"_assign": null,
"_comments": null,
"_last_update": null,
"_liked_by": null,
"_user_tags": null,
"actions": [],
"allow_auto_repeat": 0,
"allow_copy": 0,
"allow_events_in_timeline": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 1,
"app": null,
"autoname": null,
"beta": 0,
"color": null,
"colour": null,
"custom": 1,
"default_email_template": null,
"default_print_format": null,
"default_view": null,
"description": null,
"docstatus": 0,
"doctype": "DocType",
"document_type": "",
"documentation": null,
"editable_grid": 0,
"email_append_to": 0,
"engine": "InnoDB",
"fields": [
{
"allow_bulk_edit": 0,
"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": "Human readable name",
"documentation_url": null,
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "template_name",
"fieldtype": "Data",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_preview": 0,
"in_standard_filter": 0,
"is_virtual": 0,
"label": "Template Name",
"length": 0,
"link_filters": null,
"make_attachment_public": 0,
"mandatory_depends_on": null,
"max_height": null,
"no_copy": 0,
"non_negative": 0,
"oldfieldname": null,
"oldfieldtype": null,
"options": null,
"parent": "Quotation Template",
"parentfield": "fields",
"parenttype": "DocType",
"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,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"show_dashboard": 0,
"show_on_timeline": 0,
"show_preview_popup": 0,
"sort_options": 0,
"translatable": 0,
"trigger": null,
"unique": 1,
"width": null
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"collapsible_depends_on": null,
"columns": 0,
"default": "1",
"depends_on": null,
"description": "Hide old templates",
"documentation_url": null,
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "is_active",
"fieldtype": "Check",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_preview": 0,
"in_standard_filter": 0,
"is_virtual": 0,
"label": "Active",
"length": 0,
"link_filters": null,
"make_attachment_public": 0,
"mandatory_depends_on": null,
"max_height": null,
"no_copy": 0,
"non_negative": 0,
"oldfieldname": null,
"oldfieldtype": null,
"options": null,
"parent": "Quotation Template",
"parentfield": "fields",
"parenttype": "DocType",
"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,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"show_dashboard": 0,
"show_on_timeline": 0,
"show_preview_popup": 0,
"sort_options": 0,
"translatable": 0,
"trigger": null,
"unique": 0,
"width": null
},
{
"allow_bulk_edit": 0,
"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": "Optional",
"documentation_url": null,
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "description",
"fieldtype": "Small Text",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_preview": 0,
"in_standard_filter": 0,
"is_virtual": 0,
"label": "Description",
"length": 0,
"link_filters": null,
"make_attachment_public": 0,
"mandatory_depends_on": null,
"max_height": null,
"no_copy": 0,
"non_negative": 0,
"oldfieldname": null,
"oldfieldtype": null,
"options": null,
"parent": "Quotation Template",
"parentfield": "fields",
"parenttype": "DocType",
"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,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"show_dashboard": 0,
"show_on_timeline": 0,
"show_preview_popup": 0,
"sort_options": 0,
"translatable": 0,
"trigger": null,
"unique": 0,
"width": null
},
{
"allow_bulk_edit": 0,
"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": "Audit trail",
"documentation_url": null,
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "source_quotation",
"fieldtype": "Link",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_preview": 0,
"in_standard_filter": 0,
"is_virtual": 0,
"label": "Created From Quotation",
"length": 0,
"link_filters": null,
"make_attachment_public": 0,
"mandatory_depends_on": null,
"max_height": null,
"no_copy": 0,
"non_negative": 0,
"oldfieldname": null,
"oldfieldtype": null,
"options": "Quotation",
"parent": "Quotation Template",
"parentfield": "fields",
"parenttype": "DocType",
"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,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"show_dashboard": 0,
"show_on_timeline": 0,
"show_preview_popup": 0,
"sort_options": 0,
"translatable": 0,
"trigger": null,
"unique": 0,
"width": null
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"collapsible_depends_on": null,
"columns": 0,
"default": "30",
"depends_on": null,
"description": "Quote valid for",
"documentation_url": null,
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "validity_days",
"fieldtype": "Int",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_preview": 0,
"in_standard_filter": 0,
"is_virtual": 0,
"label": "Default Validity Days",
"length": 0,
"link_filters": null,
"make_attachment_public": 0,
"mandatory_depends_on": null,
"max_height": null,
"no_copy": 0,
"non_negative": 0,
"oldfieldname": null,
"oldfieldtype": null,
"options": null,
"parent": "Quotation Template",
"parentfield": "fields",
"parenttype": "DocType",
"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,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"show_dashboard": 0,
"show_on_timeline": 0,
"show_preview_popup": 0,
"sort_options": 0,
"translatable": 0,
"trigger": null,
"unique": 0,
"width": null
},
{
"allow_bulk_edit": 0,
"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,
"documentation_url": null,
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "items",
"fieldtype": "Table",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_preview": 0,
"in_standard_filter": 0,
"is_virtual": 0,
"label": "Items",
"length": 0,
"link_filters": null,
"make_attachment_public": 0,
"mandatory_depends_on": null,
"max_height": null,
"no_copy": 0,
"non_negative": 0,
"oldfieldname": null,
"oldfieldtype": null,
"options": "Quotation Template Item",
"parent": "Quotation Template",
"parentfield": "fields",
"parenttype": "DocType",
"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,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"show_dashboard": 0,
"show_on_timeline": 0,
"show_preview_popup": 0,
"sort_options": 0,
"translatable": 0,
"trigger": null,
"unique": 0,
"width": null
}
],
"force_re_route_to_default_view": 0,
"grid_page_length": 50,
"has_web_view": 0,
"hide_toolbar": 0,
"icon": null,
"image_field": null,
"in_create": 0,
"index_web_pages_for_search": 1,
"is_calendar_and_gantt": 0,
"is_published_field": null,
"is_submittable": 0,
"is_tree": 0,
"is_virtual": 0,
"issingle": 0,
"istable": 0,
"links": [],
"make_attachments_public": 0,
"max_attachments": 0,
"menu_index": null,
"migration_hash": null,
"modified": "2025-12-23 02:03:44.840865",
"module": "Selling",
"name": "Quotation Template",
"naming_rule": "",
"nsm_parent_field": null,
"parent_node": null,
"permissions": [
{
"amend": 0,
"cancel": 0,
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"if_owner": 0,
"import": 0,
"match": null,
"parent": "Quotation Template",
"parentfield": "permissions",
"parenttype": "DocType",
"permlevel": 0,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"select": 0,
"share": 1,
"submit": 0,
"write": 1
}
],
"print_outline": null,
"protect_attached_files": 0,
"queue_in_background": 0,
"quick_entry": 0,
"read_only": 0,
"recipient_account_field": null,
"restrict_to_domain": null,
"route": null,
"row_format": "Dynamic",
"rows_threshold_for_grid_search": 20,
"search_fields": null,
"sender_field": null,
"sender_name_field": null,
"show_name_in_global_search": 0,
"show_preview_popup": 0,
"show_title_field_in_link": 0,
"smallicon": null,
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"subject": null,
"subject_field": null,
"tag_fields": null,
"timeline_field": null,
"title_field": null,
"track_changes": 0,
"track_seen": 0,
"track_views": 0,
"translated_doctype": 0,
"website_search_field": null
},
{
"_assign": null,
"_comments": null,
"_last_update": null,
"_liked_by": null,
"_user_tags": null,
"actions": [],
"allow_auto_repeat": 0,
"allow_copy": 0,
"allow_events_in_timeline": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 1,
"app": null,
"autoname": null,
"beta": 0,
"color": null,
"colour": null,
"custom": 1,
"default_email_template": null,
"default_print_format": null,
"default_view": null,
"description": null,
"docstatus": 0,
"doctype": "DocType",
"document_type": "",
"documentation": null,
"editable_grid": 1,
"email_append_to": 0,
"engine": "InnoDB",
"fields": [
{
"allow_bulk_edit": 0,
"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": "Item code link",
"documentation_url": null,
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "item_code",
"fieldtype": "Link",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_preview": 0,
"in_standard_filter": 0,
"is_virtual": 0,
"label": "Item Code",
"length": 0,
"link_filters": null,
"make_attachment_public": 0,
"mandatory_depends_on": null,
"max_height": null,
"no_copy": 0,
"non_negative": 0,
"oldfieldname": null,
"oldfieldtype": null,
"options": "Item",
"parent": "Quotation Template Item",
"parentfield": "fields",
"parenttype": "DocType",
"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,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"show_dashboard": 0,
"show_on_timeline": 0,
"show_preview_popup": 0,
"sort_options": 0,
"translatable": 0,
"trigger": null,
"unique": 0,
"width": null
},
{
"allow_bulk_edit": 0,
"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,
"documentation_url": null,
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "item_name",
"fieldtype": "Data",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_preview": 0,
"in_standard_filter": 0,
"is_virtual": 0,
"label": "Item Name",
"length": 0,
"link_filters": null,
"make_attachment_public": 0,
"mandatory_depends_on": null,
"max_height": null,
"no_copy": 0,
"non_negative": 0,
"oldfieldname": null,
"oldfieldtype": null,
"options": null,
"parent": "Quotation Template Item",
"parentfield": "fields",
"parenttype": "DocType",
"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,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"show_dashboard": 0,
"show_on_timeline": 0,
"show_preview_popup": 0,
"sort_options": 0,
"translatable": 0,
"trigger": null,
"unique": 0,
"width": null
},
{
"allow_bulk_edit": 0,
"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,
"documentation_url": null,
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "description",
"fieldtype": "Small Text",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_preview": 0,
"in_standard_filter": 0,
"is_virtual": 0,
"label": "Description",
"length": 0,
"link_filters": null,
"make_attachment_public": 0,
"mandatory_depends_on": null,
"max_height": null,
"no_copy": 0,
"non_negative": 0,
"oldfieldname": null,
"oldfieldtype": null,
"options": null,
"parent": "Quotation Template Item",
"parentfield": "fields",
"parenttype": "DocType",
"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,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"show_dashboard": 0,
"show_on_timeline": 0,
"show_preview_popup": 0,
"sort_options": 0,
"translatable": 0,
"trigger": null,
"unique": 0,
"width": null
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"collapsible_depends_on": null,
"columns": 0,
"default": "1.00",
"depends_on": null,
"description": null,
"documentation_url": null,
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "quantity",
"fieldtype": "Float",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_preview": 0,
"in_standard_filter": 0,
"is_virtual": 0,
"label": "Quantity",
"length": 0,
"link_filters": null,
"make_attachment_public": 0,
"mandatory_depends_on": null,
"max_height": null,
"no_copy": 0,
"non_negative": 0,
"oldfieldname": null,
"oldfieldtype": null,
"options": null,
"parent": "Quotation Template Item",
"parentfield": "fields",
"parenttype": "DocType",
"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,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"show_dashboard": 0,
"show_on_timeline": 0,
"show_preview_popup": 0,
"sort_options": 0,
"translatable": 0,
"trigger": null,
"unique": 0,
"width": null
},
{
"allow_bulk_edit": 0,
"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,
"documentation_url": null,
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "discount_percentage",
"fieldtype": "Float",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_preview": 0,
"in_standard_filter": 0,
"is_virtual": 0,
"label": "Discount %",
"length": 0,
"link_filters": null,
"make_attachment_public": 0,
"mandatory_depends_on": null,
"max_height": null,
"no_copy": 0,
"non_negative": 0,
"oldfieldname": null,
"oldfieldtype": null,
"options": null,
"parent": "Quotation Template Item",
"parentfield": "fields",
"parenttype": "DocType",
"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,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"show_dashboard": 0,
"show_on_timeline": 0,
"show_preview_popup": 0,
"sort_options": 0,
"translatable": 0,
"trigger": null,
"unique": 0,
"width": null
},
{
"allow_bulk_edit": 0,
"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,
"documentation_url": null,
"fetch_from": null,
"fetch_if_empty": 0,
"fieldname": "rate",
"fieldtype": "Currency",
"hidden": 0,
"hide_border": 0,
"hide_days": 0,
"hide_seconds": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_preview": 0,
"in_standard_filter": 0,
"is_virtual": 0,
"label": "Rate",
"length": 0,
"link_filters": null,
"make_attachment_public": 0,
"mandatory_depends_on": null,
"max_height": null,
"no_copy": 0,
"non_negative": 0,
"oldfieldname": null,
"oldfieldtype": null,
"options": null,
"parent": "Quotation Template Item",
"parentfield": "fields",
"parenttype": "DocType",
"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,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"show_dashboard": 0,
"show_on_timeline": 0,
"show_preview_popup": 0,
"sort_options": 0,
"translatable": 0,
"trigger": null,
"unique": 0,
"width": null
}
],
"force_re_route_to_default_view": 0,
"grid_page_length": 50,
"has_web_view": 0,
"hide_toolbar": 0,
"icon": null,
"image_field": null,
"in_create": 0,
"index_web_pages_for_search": 1,
"is_calendar_and_gantt": 0,
"is_published_field": null,
"is_submittable": 0,
"is_tree": 0,
"is_virtual": 0,
"issingle": 0,
"istable": 1,
"links": [],
"make_attachments_public": 0,
"max_attachments": 0,
"menu_index": null,
"migration_hash": null,
"modified": "2025-12-23 02:00:30.908719",
"module": "Selling",
"name": "Quotation Template Item",
"naming_rule": "",
"nsm_parent_field": null,
"parent_node": null,
"permissions": [],
"print_outline": null,
"protect_attached_files": 0,
"queue_in_background": 0,
"quick_entry": 0,
"read_only": 0,
"recipient_account_field": null,
"restrict_to_domain": null,
"route": null,
"row_format": "Dynamic",
"rows_threshold_for_grid_search": 20,
"search_fields": null,
"sender_field": null,
"sender_name_field": null,
"show_name_in_global_search": 0,
"show_preview_popup": 0,
"show_title_field_in_link": 0,
"smallicon": null,
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"subject": null,
"subject_field": null,
"tag_fields": null,
"timeline_field": null,
"title_field": null,
"track_changes": 0,
"track_seen": 0,
"track_views": 0,
"translated_doctype": 0,
"website_search_field": null
}
]

View file

@ -177,6 +177,25 @@ doc_events = {
} }
} }
fixtures = [
{
"dt": "DocType",
"filters": [
["name", "in", [
"Quotation Template",
"Quotation Template Item"
]]
]
},
{
"dt": "Custom Field",
"filters": [
["dt", "=", "Quotation"],
["fieldname", "=", "custom_quotation_template"]
]
}
]
# Scheduled Tasks # Scheduled Tasks
# --------------- # ---------------

View file

@ -58,6 +58,15 @@
margin-bottom: 15px; margin-bottom: 15px;
line-height: 1.6; line-height: 1.6;
} }
.error-details {
color: #d32f2f;
font-size: 1em;
margin-top: 20px;
padding: 10px;
background-color: #ffebee;
border-left: 4px solid #d32f2f;
border-radius: 4px;
}
.highlight { .highlight {
color: #2196f3; color: #2196f3;
font-weight: 600; font-weight: 600;
@ -69,6 +78,7 @@
<div class="icon">⚠️</div> <div class="icon">⚠️</div>
<h1>Oops! Something went wrong.</h1> <h1>Oops! Something went wrong.</h1>
<p>We're sorry, but an error occurred. Please try again later or contact support if the problem persists.</p> <p>We're sorry, but an error occurred. Please try again later or contact support if the problem persists.</p>
<p class="error-details">Error: {{ error or "An unknown error occurred." }}</p>
</div> </div>
</body> </body>
</html> </html>

View file

@ -269,8 +269,8 @@ class Api {
} }
static async getJobTaskList(jobName) { static async getJobTaskList(jobName) {
if (frappe.db.exists("Project", jobName) { if (frappe.db.exists("Project", jobName)) {
const result = await request(FRAPPE_GET_JOB_TASK_LIST_METHOD, { data: jobName ) const result = await request(FRAPPE_GET_JOB_TASK_LIST_METHOD, { data: jobName })
console.log(`DEBUG: API - retrieved task list from job ${jobName}:`, result); console.log(`DEBUG: API - retrieved task list from job ${jobName}:`, result);
return result return result
} }

View file

@ -77,9 +77,53 @@
showButtons showButtons
buttonLayout="horizontal" buttonLayout="horizontal"
@input="updateTotal" @input="updateTotal"
class="qty-input"
/> />
<span>Price: ${{ (item.standardRate || 0).toFixed(2) }}</span> <span>Price: ${{ (item.standardRate || 0).toFixed(2) }}</span>
<span>Total: ${{ ((item.qty || 0) * (item.standardRate || 0)).toFixed(2) }}</span> <div class="discount-container">
<div class="discount-input-wrapper">
<InputNumber
v-if="item.discountType === 'currency'"
v-model="item.discountAmount"
mode="currency"
currency="USD"
locale="en-US"
:min="0"
:disabled="!isEditable"
@input="updateTotal"
placeholder="$0.00"
class="discount-input"
/>
<InputNumber
v-else
v-model="item.discountPercentage"
suffix="%"
:min="0"
:max="100"
:disabled="!isEditable"
@input="updateTotal"
placeholder="0%"
class="discount-input"
/>
</div>
<div class="discount-toggle">
<Button
icon="pi pi-dollar"
class="p-button-sm p-button-outlined"
:class="{ 'p-button-secondary': item.discountType !== 'currency' }"
@click="toggleDiscountType(item, 'currency')"
:disabled="!isEditable"
/>
<Button
icon="pi pi-percentage"
class="p-button-sm p-button-outlined"
:class="{ 'p-button-secondary': item.discountType !== 'percentage' }"
@click="toggleDiscountType(item, 'percentage')"
:disabled="!isEditable"
/>
</div>
</div>
<span>Total: ${{ ((item.qty || 0) * (item.standardRate || 0) - (item.discountType === 'percentage' ? ((item.qty || 0) * (item.standardRate || 0) * ((item.discountPercentage || 0) / 100)) : (item.discountAmount || 0))).toFixed(2) }}</span>
<Button <Button
v-if="isEditable" v-if="isEditable"
icon="pi pi-trash" icon="pi pi-trash"
@ -259,6 +303,7 @@ const notificationStore = useNotificationStore();
const company = useCompanyStore(); const company = useCompanyStore();
const addressQuery = computed(() => route.query.address || ""); const addressQuery = computed(() => route.query.address || "");
const nameQuery = computed(() => route.query.name || "");
const isNew = computed(() => route.query.new === "true"); const isNew = computed(() => route.query.new === "true");
const isSubmitting = ref(false); const isSubmitting = ref(false);
@ -353,7 +398,7 @@ const selectAddress = async (address) => {
const addItem = (item) => { const addItem = (item) => {
const existing = selectedItems.value.find((i) => i.itemCode === item.itemCode); const existing = selectedItems.value.find((i) => i.itemCode === item.itemCode);
if (!existing) { if (!existing) {
selectedItems.value.push({ ...item, qty: 1 }); selectedItems.value.push({ ...item, qty: 1, discountAmount: null, discountPercentage: null, discountType: 'currency' });
} }
showAddItemModal.value = false; showAddItemModal.value = false;
}; };
@ -366,7 +411,7 @@ const addSelectedItems = (selectedRows) => {
existing.qty += 1; existing.qty += 1;
} else { } else {
// Add new item with quantity 1 // Add new item with quantity 1
selectedItems.value.push({ ...item, qty: 1 }); selectedItems.value.push({ ...item, qty: 1, discountAmount: null, discountPercentage: null, discountType: 'currency' });
} }
}); });
showAddItemModal.value = false; showAddItemModal.value = false;
@ -394,7 +439,13 @@ const saveDraft = async () => {
const data = { const data = {
addressName: formData.addressName, addressName: formData.addressName,
contactName: selectedContact.value.name, contactName: selectedContact.value.name,
items: selectedItems.value.map((i) => ({ itemCode: i.itemCode, qty: i.qty })), customer: selectedAddress.value?.customer?.name,
items: selectedItems.value.map((i) => ({
itemCode: i.itemCode,
qty: i.qty,
discountAmount: i.discountType === 'currency' ? i.discountAmount : 0,
discountPercentage: i.discountType === 'percentage' ? i.discountPercentage : 0
})),
estimateName: formData.estimateName, estimateName: formData.estimateName,
requiresHalfPayment: formData.requiresHalfPayment, requiresHalfPayment: formData.requiresHalfPayment,
company: company.currentCompany company: company.currentCompany
@ -406,7 +457,7 @@ const saveDraft = async () => {
); );
// Redirect to view mode (remove new param) // Redirect to view mode (remove new param)
router.push(`/estimate?address=${encodeURIComponent(formData.address)}`); router.push(`/estimate?name=${encodeURIComponent(estimate.value.name)}`);
} catch (error) { } catch (error) {
console.error("Error saving estimate:", error); console.error("Error saving estimate:", error);
notificationStore.addNotification("Failed to save estimate", "error"); notificationStore.addNotification("Failed to save estimate", "error");
@ -456,6 +507,16 @@ const confirmAndSendEstimate = async () => {
estimate.value = updatedEstimate; estimate.value = updatedEstimate;
}; };
const toggleDiscountType = (item, type) => {
item.discountType = type;
if (type === 'currency') {
item.discountPercentage = null;
} else {
item.discountAmount = null;
}
updateTotal();
};
const tableActions = [ const tableActions = [
{ {
label: "Add Selected Items", label: "Add Selected Items",
@ -470,7 +531,13 @@ const totalCost = computed(() => {
return (selectedItems.value || []).reduce((sum, item) => { return (selectedItems.value || []).reduce((sum, item) => {
const qty = item.qty || 0; const qty = item.qty || 0;
const rate = item.standardRate || 0; const rate = item.standardRate || 0;
return sum + qty * rate; let discount = 0;
if (item.discountType === 'percentage') {
discount = (qty * rate) * ((item.discountPercentage || 0) / 100);
} else {
discount = item.discountAmount || 0;
}
return sum + (qty * rate) - discount;
}, 0); }, 0);
}); });
@ -499,7 +566,7 @@ watch(
() => route.query, () => route.query,
async (newQuery, oldQuery) => { async (newQuery, oldQuery) => {
// If 'new' param or address changed, reload component state // If 'new' param or address changed, reload component state
if (newQuery.new !== oldQuery.new || newQuery.address !== oldQuery.address) { if (newQuery.new !== oldQuery.new || newQuery.address !== oldQuery.address || newQuery.name !== oldQuery.name) {
const duplicating = isDuplicating.value; const duplicating = isDuplicating.value;
const preservedItems = duplicating const preservedItems = duplicating
? (duplicatedItems.value || []).map((item) => ({ ...item })) ? (duplicatedItems.value || []).map((item) => ({ ...item }))
@ -527,29 +594,45 @@ watch(
// Reload data based on new query params // Reload data based on new query params
const newIsNew = newQuery.new === "true"; const newIsNew = newQuery.new === "true";
const newAddressQuery = newQuery.address; const newAddressQuery = newQuery.address;
const newNameQuery = newQuery.name;
if (newAddressQuery && newIsNew) { if (newAddressQuery && newIsNew) {
// Creating new estimate - pre-fill address // Creating new estimate - pre-fill address
await selectAddress(newAddressQuery); await selectAddress(newAddressQuery);
} else if (newAddressQuery && !newIsNew) { } else if ((newNameQuery || newAddressQuery) && !newIsNew) {
// Viewing existing estimate - load and populate all fields // Viewing existing estimate - load and populate all fields
try { try {
if (newNameQuery) {
estimate.value = await Api.getEstimate(newNameQuery);
} else {
estimate.value = await Api.getEstimateFromAddress(newAddressQuery); estimate.value = await Api.getEstimateFromAddress(newAddressQuery);
}
if (estimate.value) { if (estimate.value) {
formData.estimateName = estimate.value.name; formData.estimateName = estimate.value.name;
const fullAddress = estimate.value.fullAddress || estimate.value.full_address;
if (fullAddress) {
await selectAddress(fullAddress);
} else if (newAddressQuery) {
await selectAddress(newAddressQuery); await selectAddress(newAddressQuery);
formData.contact = estimate.value.partyName; }
selectedContact.value = contacts.value.find((c) => c.name === estimate.value.partyName) || null;
formData.contact = estimate.value.contactPerson;
selectedContact.value = contacts.value.find((c) => c.name === estimate.value.contactPerson) || null;
if (estimate.value.items && estimate.value.items.length > 0) { if (estimate.value.items && estimate.value.items.length > 0) {
selectedItems.value = estimate.value.items.map(item => { selectedItems.value = estimate.value.items.map(item => {
const fullItem = quotationItems.value.find(qi => qi.itemCode === item.itemCode); const fullItem = quotationItems.value.find(qi => qi.itemCode === item.itemCode);
const discountPercentage = item.discountPercentage || item.discount_percentage || 0;
const discountAmount = item.discountAmount || item.discount_amount || 0;
return { return {
itemCode: item.itemCode, itemCode: item.itemCode,
itemName: item.itemName, itemName: item.itemName,
qty: item.qty, qty: item.qty,
standardRate: item.rate || fullItem?.standardRate || 0, standardRate: item.rate || fullItem?.standardRate || 0,
discountAmount: discountAmount === 0 ? null : discountAmount,
discountPercentage: discountPercentage === 0 ? null : discountPercentage,
discountType: discountPercentage > 0 ? 'percentage' : 'currency'
}; };
}); });
} }
@ -579,31 +662,46 @@ onMounted(async () => {
if (addressQuery.value && isNew.value) { if (addressQuery.value && isNew.value) {
// Creating new estimate - pre-fill address // Creating new estimate - pre-fill address
await selectAddress(addressQuery.value); await selectAddress(addressQuery.value);
} else if (addressQuery.value && !isNew.value) { } else if ((nameQuery.value || addressQuery.value) && !isNew.value) {
// Viewing existing estimate - load and populate all fields // Viewing existing estimate - load and populate all fields
try { try {
if (nameQuery.value) {
estimate.value = await Api.getEstimate(nameQuery.value);
} else {
estimate.value = await Api.getEstimateFromAddress(addressQuery.value); estimate.value = await Api.getEstimateFromAddress(addressQuery.value);
}
console.log("DEBUG: Loaded estimate:", estimate.value); console.log("DEBUG: Loaded estimate:", estimate.value);
if (estimate.value) { if (estimate.value) {
// Set the estimate name for upserting // Set the estimate name for upserting
formData.estimateName = estimate.value.name; formData.estimateName = estimate.value.name;
const fullAddress = estimate.value.fullAddress || estimate.value.full_address;
if (fullAddress) {
await selectAddress(fullAddress);
} else if (addressQuery.value) {
await selectAddress(addressQuery.value); await selectAddress(addressQuery.value);
}
// Set the contact from the estimate // Set the contact from the estimate
formData.contact = estimate.value.partyName; formData.contact = estimate.value.contactPerson;
selectedContact.value = contacts.value.find((c) => c.name === estimate.value.partyName) || null; selectedContact.value = contacts.value.find((c) => c.name === estimate.value.contactPerson) || null;
// Populate items from the estimate // Populate items from the estimate
if (estimate.value.items && estimate.value.items.length > 0) { if (estimate.value.items && estimate.value.items.length > 0) {
selectedItems.value = estimate.value.items.map(item => { selectedItems.value = estimate.value.items.map(item => {
// Find the full item details from quotationItems // Find the full item details from quotationItems
const fullItem = quotationItems.value.find(qi => qi.itemCode === item.itemCode); const fullItem = quotationItems.value.find(qi => qi.itemCode === item.itemCode);
const discountPercentage = item.discountPercentage || item.discount_percentage || 0;
const discountAmount = item.discountAmount || item.discount_amount || 0;
return { return {
itemCode: item.itemCode, itemCode: item.itemCode,
itemName: item.itemName, itemName: item.itemName,
qty: item.qty, qty: item.qty,
standardRate: item.rate || fullItem?.standardRate || 0, standardRate: item.rate || fullItem?.standardRate || 0,
discountAmount: discountAmount === 0 ? null : discountAmount,
discountPercentage: discountPercentage === 0 ? null : discountPercentage,
discountType: discountPercentage > 0 ? 'percentage' : 'currency'
}; };
}); });
} }
@ -672,7 +770,7 @@ onMounted(async () => {
.item-row { .item-row {
display: grid; display: grid;
grid-template-columns: 2fr 1fr auto auto auto; grid-template-columns: 3fr 140px 1.5fr 220px 1.5fr auto;
align-items: center; align-items: center;
gap: 1rem; gap: 1rem;
margin-bottom: 0.5rem; margin-bottom: 0.5rem;
@ -681,9 +779,54 @@ onMounted(async () => {
border-radius: 4px; border-radius: 4px;
} }
.qty-input {
width: 100%;
}
.qty-input :deep(.p-inputtext) {
width: 40px;
text-align: center;
padding: 0.25rem;
}
.qty-input :deep(.p-button) {
width: 2rem;
padding: 0;
}
.discount-container {
display: flex;
align-items: center;
gap: 0.5rem;
}
.discount-input-wrapper {
flex: 1;
}
.discount-input {
width: 100%;
}
.discount-input :deep(.p-inputtext) {
width: 100%;
padding: 0.5rem;
text-align: right;
}
.discount-toggle {
display: flex;
gap: 2px;
}
.discount-toggle .p-button {
padding: 0.25rem 0.5rem;
width: 2rem;
}
/* When viewing (not editing), adjust grid to remove delete button column */ /* When viewing (not editing), adjust grid to remove delete button column */
.estimate-page:has(h2:contains("View")) .item-row { .estimate-page:has(h2:contains("View")) .item-row {
grid-template-columns: 2fr 1fr auto auto; grid-template-columns: 3fr 140px 1.5fr 220px 1.5fr;
} }
.total-section { .total-section {