payment pages working

This commit is contained in:
Casey 2026-02-06 08:07:18 -06:00
parent 991038bc47
commit 91783757e4
12 changed files with 402 additions and 18 deletions

View File

@ -81,6 +81,13 @@ def before_save(doc, method):
def after_save(doc, method):
print("DEBUG: After Save Triggered for Project:", doc.name)
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 = {

View File

@ -9,7 +9,7 @@ def on_submit(doc, method):
if so_ref:
so_doc = frappe.get_doc("Sales Order", so_ref.reference_name)
if so_doc.requires_half_payment:
is_paid = doc.custom_halfdown_amount <= doc.advance_paid or doc.advance_paid >= so_doc.grand_total / 2
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

View File

@ -151,7 +151,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()

View File

@ -204,6 +204,9 @@ 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"
}
}

View File

@ -54,8 +54,8 @@ class StripeService:
"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",
success_url=f"{get_url()}/payment_success?session_id={{CHECKOUT_SESSION_ID}}",
cancel_url=f"{get_url()}/payment_cancelled",
)
return session

View File

@ -1,4 +0,0 @@
{% extends "templates/web.html" %}
{% block page_content %}
<p>Payment cancelled.</p>
{% endblock %}

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

View File

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

View 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

View File

@ -1,4 +0,0 @@
{% extends "templates/web.html" %}
{% block page_content %}
<p>Thank you for your payment!</p>
{% endblock %}

View File

@ -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>
@ -991,13 +997,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 +1181,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;
@ -1306,13 +1314,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
}
);