diff --git a/public/js/utils/item-editor.js b/public/js/utils/item-editor.js index 62805bd..78334dd 100644 --- a/public/js/utils/item-editor.js +++ b/public/js/utils/item-editor.js @@ -47,7 +47,9 @@ export function addItem(containerId, { item = null, type = 'invoice', laborRate temp.innerHTML = item.description; previewDesc = temp.textContent.substring(0, 50) + (temp.textContent.length > 50 ? '...' : ''); } - const typeLabel = (item && item.qbo_item_id == '5') ? 'Labor' : 'Parts'; + const typeLabel = (item && item.qbo_item_id == '5') ? 'Labor' + : (item && item.qbo_item_id == '115') ? 'Subscription' + : 'Parts'; const itemDiv = document.createElement('div'); itemDiv.className = 'border border-gray-300 rounded-lg mb-3 bg-white'; @@ -87,6 +89,7 @@ export function addItem(containerId, { item = null, type = 'invoice', laborRate @@ -177,7 +180,9 @@ function updateItemPreview(itemDiv) { if (amountPreview && amountInput) amountPreview.textContent = amountInput.value || '$0.00'; if (typePreview && typeInput) { - typePreview.textContent = typeInput.value == '5' ? 'Labor' : 'Parts'; + typePreview.textContent = typeInput.value == '5' ? 'Labor' + : typeInput.value == '115' ? 'Subscription' + : 'Parts'; } if (descPreview && editorDiv && editorDiv.quillInstance) { diff --git a/src/routes/invoices.js b/src/routes/invoices.js index 492e2d1..9ed7de1 100644 --- a/src/routes/invoices.js +++ b/src/routes/invoices.js @@ -520,7 +520,9 @@ router.post('/:id/export', async (req, res) => { const rate = parseFloat(item.rate.replace(/[^0-9.]/g, '')) || 0; const amount = parseFloat(item.amount.replace(/[^0-9.]/g, '')) || 0; const itemRefId = item.qbo_item_id || '9'; - const itemRefName = itemRefId == '5' ? "Labor:Labor" : "Parts:Parts"; + const itemRefName = itemRefId == QBO_LABOR_ID ? "Labor:Labor" + : itemRefId == '115' ? "Subscription" + : "Parts:Parts"; return { "DetailType": "SalesItemLineDetail", @@ -653,7 +655,9 @@ router.post('/:id/update-qbo', async (req, res) => { const rate = parseFloat(item.rate.replace(/[^0-9.]/g, '')) || 0; const amount = parseFloat(item.amount.replace(/[^0-9.]/g, '')) || 0; const itemRefId = item.qbo_item_id || QBO_PARTS_ID; - const itemRefName = itemRefId == QBO_LABOR_ID ? "Labor:Labor" : "Parts:Parts"; + const itemRefName = itemRefId == QBO_LABOR_ID ? "Labor:Labor" + : itemRefId == '115' ? "Subscription" + : "Parts:Parts"; return { "DetailType": "SalesItemLineDetail", diff --git a/src/services/qbo-service.js b/src/services/qbo-service.js index da98d31..bb57154 100644 --- a/src/services/qbo-service.js +++ b/src/services/qbo-service.js @@ -8,6 +8,7 @@ const { getOAuthClient, getQboBaseUrl, makeQboApiCall } = require('../config/qbo // QBO Item IDs const QBO_LABOR_ID = '5'; const QBO_PARTS_ID = '9'; +const QBO_SUBSCRIPTION_ID = '115'; function getClientInfo() { const oauthClient = getOAuthClient(); @@ -54,7 +55,9 @@ async function exportInvoiceToQbo(invoiceId, dbClient) { // <-- Nutzt jetzt dbCl const qty = parseNum(item.quantity) || 1; const amount = rate * qty; const itemRefId = item.qbo_item_id || QBO_PARTS_ID; - const itemRefName = itemRefId == QBO_LABOR_ID ? "Labor:Labor" : "Parts:Parts"; + const itemRefName = itemRefId == QBO_LABOR_ID ? "Labor:Labor" + : itemRefId == QBO_SUBSCRIPTION_ID ? "Subscription" + : "Parts:Parts"; return { "DetailType": "SalesItemLineDetail", @@ -157,7 +160,9 @@ async function syncInvoiceToQbo(invoiceId, dbClient) { // <-- Nutzt jetzt dbClie const qty = parseNum(item.quantity) || 1; const amount = rate * qty; const itemRefId = item.qbo_item_id || QBO_PARTS_ID; - const itemRefName = itemRefId == QBO_LABOR_ID ? "Labor:Labor" : "Parts:Parts"; + const itemRefName = itemRefId == QBO_LABOR_ID ? "Labor:Labor" + : itemRefId == QBO_SUBSCRIPTION_ID ? "Subscription" + : "Parts:Parts"; return { "DetailType": "SalesItemLineDetail", @@ -216,6 +221,7 @@ async function syncInvoiceToQbo(invoiceId, dbClient) { // <-- Nutzt jetzt dbClie module.exports = { QBO_LABOR_ID, QBO_PARTS_ID, + QBO_SUBSCRIPTION_ID, getClientInfo, exportInvoiceToQbo, syncInvoiceToQbo