Accept Quote: This will convert the quote to an invoice.
DRAFT
MGT Business Solutons Sdn Bhd
1-9, 2-9 Jalan Bukit Jalil Indah 4,
Komplex Niaga LTAT, Bukit Jalil,
Kuala Lumpur
sales@mugattionline.com.my
01154095478
http://www.mgtbusinesssolutions.com
Kick Start Package
Quote Number Quote_000002
Quote Date 11/09/2025
Valid Until Date 12/09/2025
Total MYR20.00

To

Mugatti Sdn Bhd
quanpolo@gmail.com
123
Service Qty Rate Adjust (%) Total
Marketing service
For testing purposes, you may simulate transactions using these test credentials, and view all test transactions via the sandbox portal. To access the sandbox portal, please login with your registered email address and password: "Password".
1 MYR20.00 MYR20.00
Sub Total:MYR20.00
Total:MYR20.00

Terms & Conditions

1.up of the automated deduction of 2.monthly payment from your bank account using this mandate link. Please note that your 3.settlement may be withheld if this step is not completed.
DRAFT
`; // Write the content to the new window printWindow.document.write(printHTML); printWindow.document.close(); // Wait for content to load, then print printWindow.onload = function() { setTimeout(function() { printWindow.print(); printWindow.close(); }, 500); }; } document.addEventListener('DOMContentLoaded', function() { const quoteId = '13'; const acceptActionDescription = 'This will convert the quote to an invoice.'; const declinedMessage = ''; const isDeclineReasonRequired = false; // Utility: Show loading spinner in a button function setButtonLoading(btn, loadingText) { btn.disabled = true; btn.innerHTML = ` ${loadingText}`; } // resetButtonLoading function is now defined globally above // Accept Quote Button const acceptButton = document.querySelector('.quote-actions .accept'); if (acceptButton) { acceptButton.addEventListener('click', function() { let message = 'Accept this quote?'; if (acceptActionDescription) { message += '\n\n' + acceptActionDescription; } showConfirmationModal( 'Accept Quote', message, 'Accept Quote', 'Cancel', 'primary', function(modal, confirmBtn, originalText) { handleAcceptQuote(quoteId, confirmBtn, originalText); } ); }); } // Decline Quote Button const declineButton = document.querySelector('.quote-actions .decline'); if (declineButton) { declineButton.addEventListener('click', function() { let message = 'Decline this quote?'; if (declinedMessage) { message += '\n\n' + declinedMessage; } if (isDeclineReasonRequired) { showDeclineModalWithReason(); } else { showConfirmationModal( 'Decline Quote', message, 'Decline Quote', 'Cancel', 'danger', function(modal, confirmBtn, originalText) { handleDeclineQuote(quoteId, confirmBtn, originalText); } ); } }); } // Note: Download and Send Email buttons are handled via inline onclick attributes to avoid duplicate bindings // Custom Modal System function showConfirmationModal(title, message, confirmText, cancelText, confirmType, onConfirm) { // Remove existing modal if any const existingModal = document.querySelector('.ei-modal-overlay'); if (existingModal) { existingModal.remove(); } // Create modal overlay const overlay = document.createElement('div'); overlay.className = 'ei-modal-overlay'; // Create modal content const modal = document.createElement('div'); modal.className = 'ei-modal'; const confirmBtnClass = confirmType === 'danger' ? 'ei-modal-btn-danger' : 'ei-modal-btn-primary'; const iconClass = confirmType === 'danger' ? 'danger' : 'info'; const icon = confirmType === 'danger' ? '' : ''; modal.innerHTML = `
${icon}

${title}

${message}
`; overlay.appendChild(modal); document.body.appendChild(overlay); // Show modal with animation setTimeout(() => { overlay.classList.add('show'); modal.classList.add('show'); }, 10); // Handle button clicks const confirmBtn = modal.querySelector('#modal-confirm'); const cancelBtn = modal.querySelector('#modal-cancel'); confirmBtn.addEventListener('click', function() { const originalText = confirmBtn.innerHTML; setButtonLoading(confirmBtn, confirmBtn.textContent.trim()); onConfirm(modal, confirmBtn, originalText); }); cancelBtn.addEventListener('click', function() { hideModal(overlay); }); // Handle overlay click to close overlay.addEventListener('click', function(e) { if (e.target === overlay) { hideModal(overlay); } }); // Handle escape key const handleEscape = function(e) { if (e.key === 'Escape') { hideModal(overlay); document.removeEventListener('keydown', handleEscape); } }; document.addEventListener('keydown', handleEscape); // Focus on confirm button setTimeout(() => { confirmBtn.focus(); }, 100); } // Decline Modal with Reason Field function showDeclineModalWithReason() { // Remove existing modal if any const existingModal = document.querySelector('.ei-modal-overlay'); if (existingModal) { existingModal.remove(); } // Create modal overlay const overlay = document.createElement('div'); overlay.className = 'ei-modal-overlay'; // Create modal content const modal = document.createElement('div'); modal.className = 'ei-modal'; let message = 'Decline this quote?'; if (declinedMessage) { message += '\n\n' + declinedMessage; } modal.innerHTML = `

Decline Quote

${message}
`; overlay.appendChild(modal); document.body.appendChild(overlay); setTimeout(() => { overlay.classList.add('show'); modal.classList.add('show'); }, 10); // Handle button clicks const confirmBtn = modal.querySelector('#modal-confirm'); const cancelBtn = modal.querySelector('#modal-cancel'); const reasonField = modal.querySelector('#decline-reason'); confirmBtn.addEventListener('click', function() { const reason = reasonField.value.trim(); if (!reason) { reasonField.focus(); reasonField.classList.add('error'); return; } const originalText = confirmBtn.innerHTML; setButtonLoading(confirmBtn, confirmBtn.textContent.trim()); handleDeclineQuote(quoteId, confirmBtn, reason, originalText); }); cancelBtn.addEventListener('click', function() { hideModal(overlay); }); overlay.addEventListener('click', function(e) { if (e.target === overlay) { hideModal(overlay); } }); const handleEscape = function(e) { if (e.key === 'Escape') { hideModal(overlay); document.removeEventListener('keydown', handleEscape); } }; document.addEventListener('keydown', handleEscape); setTimeout(() => { reasonField.focus(); }, 100); reasonField.addEventListener('input', function() { this.classList.remove('error'); }); } function hideModal(overlay) { const modal = overlay.querySelector('.ei-modal'); modal.classList.remove('show'); overlay.classList.remove('show'); setTimeout(() => { if (overlay.parentNode) { overlay.remove(); } }, 300); } // Show message in modal (used for AJAX responses) function showModalMessage(type, message, onClose) { // Remove existing modal if any const existingModal = document.querySelector('.ei-modal-overlay'); if (existingModal) { existingModal.remove(); } // Create modal overlay const overlay = document.createElement('div'); overlay.className = 'ei-modal-overlay'; // Create modal content const modal = document.createElement('div'); modal.className = 'ei-modal'; const iconClass = type === 'success' ? 'info' : 'danger'; const icon = type === 'success' ? '' : ''; modal.innerHTML = `
${icon}

${type === 'success' ? 'Success' : 'Error'}

${message}
`; overlay.appendChild(modal); document.body.appendChild(overlay); setTimeout(() => { overlay.classList.add('show'); modal.classList.add('show'); }, 10); const closeBtn = modal.querySelector('#modal-close'); closeBtn.addEventListener('click', function() { hideModal(overlay); if (onClose) onClose(); }); overlay.addEventListener('click', function(e) { if (e.target === overlay) { hideModal(overlay); if (onClose) onClose(); } }); const handleEscape = function(e) { if (e.key === 'Escape') { hideModal(overlay); document.removeEventListener('keydown', handleEscape); if (onClose) onClose(); } }; document.addEventListener('keydown', handleEscape); setTimeout(() => { closeBtn.focus(); }, 100); } // Show loading state in modal function showModalLoading(message) { // Remove existing modal if any const existingModal = document.querySelector('.ei-modal-overlay'); if (existingModal) { existingModal.remove(); } // Create modal overlay const overlay = document.createElement('div'); overlay.className = 'ei-modal-overlay'; // Create modal content const modal = document.createElement('div'); modal.className = 'ei-modal'; modal.innerHTML = `

Please wait...

${message}
`; overlay.appendChild(modal); document.body.appendChild(overlay); setTimeout(() => { overlay.classList.add('show'); modal.classList.add('show'); }, 10); } // Handle Accept Quote function handleAcceptQuote(quoteId, confirmBtn, originalText) { showModalLoading('Accepting quote...'); jQuery.ajax({ url: 'https://mugattionline.com.my/wp-admin/admin-ajax.php', type: 'POST', data: { action: 'easy_invoice_accept_quote', quote_id: quoteId, nonce: '175f77efae' }, success: function(response) { if (response.success) { // Check if an invoice was created and redirect to it if (response.data && response.data.invoice_id) { // Use the PHP-generated URL (secure URL first, then regular URL) let invoiceUrl = response.data.secure_url || response.data.invoice_url; if (invoiceUrl) { showModalMessage('success', response.data.message || 'Quote accepted successfully! Redirecting to invoice...', function() { window.location.href = invoiceUrl; }); } else { // Fallback to reload if no URL available showModalMessage('success', response.data.message || 'Quote accepted successfully', function() { location.reload(); }); } } else { // No invoice created, just show success message showModalMessage('success', response.data && response.data.message ? response.data.message : 'Quote accepted successfully', function() { location.reload(); }); } } else { resetButtonLoading(confirmBtn, originalText); showModalMessage('error', response.data || 'Error accepting quote'); } }, error: function() { resetButtonLoading(confirmBtn, originalText); showModalMessage('error', 'Error connecting to server'); } }); } // Handle Decline Quote function handleDeclineQuote(quoteId, confirmBtn, reason = '', originalText) { showModalLoading('Declining quote...'); const ajaxData = { action: 'easy_invoice_decline_quote', quote_id: quoteId, nonce: '175f77efae' }; if (reason) { ajaxData.decline_reason = reason; } jQuery.ajax({ url: 'https://mugattionline.com.my/wp-admin/admin-ajax.php', type: 'POST', data: ajaxData, success: function(response) { if (response.success) { showModalMessage('success', response.data && response.data.message ? response.data.message : 'Quote declined successfully', function() { location.reload(); }); } else { resetButtonLoading(confirmBtn, originalText); showModalMessage('error', response.data || 'Error declining quote'); } }, error: function() { resetButtonLoading(confirmBtn, originalText); showModalMessage('error', 'Error connecting to server'); } }); } // Functions moved to global scope above });