Skip to content

Commit

Permalink
wip(app): implement core functionality in wtfdyp.ts
Browse files Browse the repository at this point in the history
- Began work on `wtfdyp.ts`, the main TypeScript file responsible for orchestrating the extension's core functionality. This file aims to integrate various components of the project, such as fetching invoice data, calculating combinations, and updating the UI based on user input.
- Imported `getInvoiceCombinations` and `sortCombinations` functions to utilize the algorithm for finding optimal invoice combinations given a payment amount.
- Temporarily commented out the Chrome message listener intended to react to popup actions. This listener will ultimately handle receiving the payment amount from the popup, initiating the combination finding and sorting process, and updating the DOM to reflect the selected invoices.
- Included a test scenario with hardcoded invoice amounts and a payment amount to demonstrate the output of the sorting algorithm. This test will be replaced with dynamic data extraction from the page and interaction with the popup.

This work-in-progress represents a significant step towards achieving the extension's goal of automating invoice selection. The next steps include finalizing the message listener to interact with the popup, extracting actual invoice data from the page, and implementing DOM manipulation to visually indicate the chosen invoices.
  • Loading branch information
tsdevau committed Mar 18, 2024
1 parent bec0280 commit c2fe81e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/wtfdyp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @license
* tsdevau <https://tsdev.au/>
* License: BSD-3-Clause
* Licence Copywright: This software is licensed under the BSD-3-Clause License. See LICENCE file.
*
* Copyright (c) 2020-2024 tpsTech, TPS Contractors Pty Ltd and its affiliates. All rights reserved.
*/

import { getInvoiceCombinations } from "./getInvoiceCombinations"
import { sortCombinations } from "./sortCombinations"
import type { Combo, WeightedCombo } from "./types"

// chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
// const paymentAmount = request.paymentAmount
// Logic to read the table and extract invoice amounts
// Your algorithm to find the best combination
// Update the page DOM to check off the selected invoices
// })

// Test output of sorting algorithm
const invAmounts: number[] = [
20.99, 80.1, 11.55, 57.6, 31.85, 278.5, 59.3, 14.8, 25, 112.16, 23, 58.4, 35, 246.32, 21.8, 56.63,
25.8,
]
const paymentAmount: number = 379.39

// Get the valid combinations
const validCombos: Combo[][] = getInvoiceCombinations(invAmounts, paymentAmount)

// Sort the valid combinations
const rankedCombos: WeightedCombo[] = sortCombinations(validCombos)

// Log the sorted combinations
console.log(rankedCombos)

0 comments on commit c2fe81e

Please sign in to comment.