diff --git a/src/views/dashboards/superUserDashboard/InvoicingBillingPeriod/views/InvoicingBillingPeriodViewAll.vue b/src/views/dashboards/superUserDashboard/InvoicingBillingPeriod/views/InvoicingBillingPeriodViewAll.vue index af8c6612..a3e475fa 100644 --- a/src/views/dashboards/superUserDashboard/InvoicingBillingPeriod/views/InvoicingBillingPeriodViewAll.vue +++ b/src/views/dashboards/superUserDashboard/InvoicingBillingPeriod/views/InvoicingBillingPeriodViewAll.vue @@ -133,10 +133,7 @@ const onFilterChanged = (filters: any) => { tmpFilters.value = filters; const includeRequiresAction = filters.displayRequiresAction !== false; const includeBooked = filters.displayBooked !== false; - if ( - periodPaging.includeRequiresAction !== includeRequiresAction - || periodPaging.includeBooked !== includeBooked - ) { + if (periodPaging.includeRequiresAction !== includeRequiresAction || periodPaging.includeBooked !== includeBooked) { periodPaging.includeRequiresAction = includeRequiresAction; periodPaging.includeBooked = includeBooked; periodPaging.page = 1; @@ -289,13 +286,11 @@ const getDuplicateTransactionCustomerLabel = (transaction: any) => { return [customerName, customerNumber].filter(Boolean).join(" "); }; -const getDuplicateTransactionDateLabel = (transaction: any) => formatDuplicateDateLabel( - getDuplicateTransactionDateKey(transaction) -); +const getDuplicateTransactionDateLabel = (transaction: any) => + formatDuplicateDateLabel(getDuplicateTransactionDateKey(transaction)); -const getDuplicateTransactionAmountLabel = (transaction: any) => SessionUser.functions.currency.toLocal( - getDuplicateTransactionAmount(transaction) -); +const getDuplicateTransactionAmountLabel = (transaction: any) => + SessionUser.functions.currency.toLocal(getDuplicateTransactionAmount(transaction)); const getTransactionIds = (customer: any) => { if (!customer.transactions || customer.transactions.length === 0) { @@ -372,8 +367,11 @@ const onClickInvoiceNow = async (customer: any, transactionIds: number[]) => { const year = dates.variables.start.value.getFullYear(); if (customer?.meta?.fixed_pricing) { - const response = await SessionUser.objects.collectedOrderInvoices.functions - .createVehicleSubscriptionInvoice(customer.customer_number, month, year); + const response = await SessionUser.objects.collectedOrderInvoices.functions.createVehicleSubscriptionInvoice( + customer.customer_number, + month, + year + ); const newInvoiceCollectionId = parsePositiveInteger(response?.data?.data?.id); if (!newInvoiceCollectionId) { invoiceQueue.finishPeriodRefresh?.([customerNumber], []); @@ -383,8 +381,11 @@ const onClickInvoiceNow = async (customer: any, transactionIds: number[]) => { await SessionUser.objects.collectedOrderInvoices.functions.add_fixed_pricing(newInvoiceCollectionId); queueInvoiceCollections([newInvoiceCollectionId], customer); } else if (view.variables.currentView.value === "vehicle_subscriptions") { - const response = await SessionUser.objects.collectedOrderInvoices.functions - .createVehicleSubscriptionInvoice(customer.customer_number, month, year); + const response = await SessionUser.objects.collectedOrderInvoices.functions.createVehicleSubscriptionInvoice( + customer.customer_number, + month, + year + ); const newInvoiceCollectionId = parsePositiveInteger(response?.data?.data?.id); if (!newInvoiceCollectionId) { invoiceQueue.finishPeriodRefresh?.([customerNumber], []); @@ -573,16 +574,19 @@ const isCustomerDraftBlocked = (customer: any) => { const isActiveFlag = (flag: any) => String(flag?.status || "active") === "active"; const getActiveFlags = (flags: any[] = []) => flags.filter((flag: any) => isActiveFlag(flag)); -const sortCustomerFlags = (flags: any[] = []) => [...flags].sort((left: any, right: any) => { - const sourceOrder: Record = { manual: 0, automatic: 1 }; - const leftSource = sourceOrder[left?.source] ?? 99; - const rightSource = sourceOrder[right?.source] ?? 99; - if (leftSource !== rightSource) { - return leftSource - rightSource; - } +const sortCustomerFlags = (flags: any[] = []) => + [...flags].sort((left: any, right: any) => { + const sourceOrder: Record = { manual: 0, automatic: 1 }; + const leftSource = sourceOrder[left?.source] ?? 99; + const rightSource = sourceOrder[right?.source] ?? 99; + if (leftSource !== rightSource) { + return leftSource - rightSource; + } - return String(left?.created_at || left?.fingerprint || "").localeCompare(String(right?.created_at || right?.fingerprint || "")); -}); + return String(left?.created_at || left?.fingerprint || "").localeCompare( + String(right?.created_at || right?.fingerprint || "") + ); + }); const flagIdentity = (flag: any) => String(flag?.id || flag?.fingerprint || ""); @@ -599,26 +603,24 @@ const getFlagCounts = (flags: any[] = []) => { return counts; }; -const toPositiveIntegerSet = (values: any[] = []) => new Set( - values - .map((value: any) => parsePositiveInteger(value)) - .filter((value): value is number => value !== null) -); +const toPositiveIntegerSet = (values: any[] = []) => + new Set(values.map((value: any) => parsePositiveInteger(value)).filter((value): value is number => value !== null)); const getFlagOrderId = (flag: any) => { const targetType = String(flag?.target_type || ""); return parsePositiveInteger( - flag?.order_id - ?? flag?.context?.order_id - ?? (["order", "order_field"].includes(targetType) ? flag?.target_id : null) + flag?.order_id ?? + flag?.context?.order_id ?? + (["order", "order_field"].includes(targetType) ? flag?.target_id : null) ); }; -const getFlagInvoiceCollectionId = (flag: any) => parsePositiveInteger( - flag?.invoice_collection_id - ?? flag?.context?.invoice_collection_id - ?? (String(flag?.target_type || "") === "collected_order_invoice" ? flag?.target_id : null) -); +const getFlagInvoiceCollectionId = (flag: any) => + parsePositiveInteger( + flag?.invoice_collection_id ?? + flag?.context?.invoice_collection_id ?? + (String(flag?.target_type || "") === "collected_order_invoice" ? flag?.target_id : null) + ); const isFlagInCustomerCardScope = (customer: any, flag: any) => { if (!isActiveFlag(flag)) { @@ -640,21 +642,32 @@ const isFlagInCustomerCardScope = (customer: any, flag: any) => { if (["order", "order_field", "order_item", "order_item_field"].includes(targetType)) { const orderId = getFlagOrderId(flag); - return orderId !== null && transactionIdSet.has(orderId); + if (orderId !== null && transactionIdSet.has(orderId)) { + return true; + } + + const invoiceCollectionId = getFlagInvoiceCollectionId(flag); + return ( + invoiceCollectionId !== null && + toPositiveIntegerSet(getInvoiceCollectionIdsForTransactionIds(customer, transactionIds)).has(invoiceCollectionId) + ); } if (targetType === "collected_order_invoice") { const invoiceCollectionId = getFlagInvoiceCollectionId(flag); - return invoiceCollectionId !== null - && toPositiveIntegerSet(getInvoiceCollectionIdsForTransactionIds(customer, transactionIds)).has(invoiceCollectionId); + return ( + invoiceCollectionId !== null && + toPositiveIntegerSet(getInvoiceCollectionIdsForTransactionIds(customer, transactionIds)).has(invoiceCollectionId) + ); } return false; }; -const getCustomerScopedFlags = (customer: any) => sortCustomerFlags( - getActiveFlags(customer?.flags || []).filter((flag: any) => isFlagInCustomerCardScope(customer, flag)) -); +const getCustomerScopedFlags = (customer: any) => + sortCustomerFlags( + getActiveFlags(customer?.flags || []).filter((flag: any) => isFlagInCustomerCardScope(customer, flag)) + ); const getCustomerActiveFlagCounts = (customer: any) => { const scopedFlags = getCustomerScopedFlags(customer); @@ -696,9 +709,10 @@ const getCustomerStatusIconClass = (customer: any) => { const isOrderLineFlag = (flag: any) => ["order", "order_field"].includes(String(flag?.target_type || "")); const isOrderItemLineFlag = (flag: any) => ["order_item", "order_item_field"].includes(String(flag?.target_type || "")); -const getCustomerCardFlags = (customer: any) => getCustomerScopedFlags(customer) - .filter((flag: any) => !isOrderLineFlag(flag)) - .filter((flag: any) => !isOrderItemLineFlag(flag)); +const getCustomerCardFlags = (customer: any) => + getCustomerScopedFlags(customer).filter((flag: any) => !isOrderLineFlag(flag) && !isOrderItemLineFlag(flag)); +const getCustomerExpandedFlags = (customer: any) => + getCustomerScopedFlags(customer).filter((flag: any) => isOrderLineFlag(flag) || isOrderItemLineFlag(flag)); const recomputeCustomerFlagState = (customer: any) => { customer.flags = sortCustomerFlags(getActiveFlags(customer.flags || [])); @@ -714,7 +728,7 @@ const recomputeCustomerFlagState = (customer: any) => { } }; -const forEachPeriodCustomerWithNumber = (customerNumber: number, callback: (customer: any) => void) => { +const forEachPeriodCustomerWithNumber = (customerNumber: number, callback: (_customer: any) => void) => { const types = view.variables.sharedVariables.value?.types || {}; Object.values(types).forEach((customers: any) => { if (!Array.isArray(customers)) { @@ -806,7 +820,6 @@ const getTransactionQueryParameters = () => { show_fixed_pricing: true, }; }; -