Commit Graph

22 Commits (a229d59c49cfe61d49f843f9df281fc14e5ebaae)

Author SHA1 Message Date
Dustin a229d59c49 Redirect / to /receipts 2025-03-09 21:09:08 -05:00
Dustin b661d04eaa receipt-list: Make cards bigger
On mobile, we don't want 4 cards wide.  Let's make them a static size
and let there be however many fit on a row.
2025-03-09 21:14:03 -05:00
Dustin 1c18ea4bbc receipt-form: Omit empty uploaded file
If there is no file to be uploaded, then we must not send the value of
the `photo` file input.  Doing so causes two files to be uploaded, the
first one being a zero-byte file with no name, and the second one being
the one we captured from the camera.  The server only uses the first
uploaded file if there are multiple, so the correct file is never used.
2025-03-09 21:04:15 -05:00
Dustin 6baf916511 Run DB migrations at startup
Naturally, we need the database schema in place in order to use it.
2025-03-09 20:55:26 -05:00
Dustin 98623730d2 Store receipts in the database
Rethinking the workflow again.  Requiring the transaction to be present
in Firefly already will be problematic for two very important cases:

* Gas station purchase never show up in Firefly automatically
* HSA purchase show up hours or days later and have no information
  besides the amount

These are arguably the most important cases, since they are the ones
that really need receipts in order to keep the transaction register
correct.  Thus, we need a different way to handle these types of
transactions.

Really, what I need is a way to associate transaction data with an image
I really liked the original idea of storing receipts in Paperless, but
that ended up not working out because the OCR failed miserably and thus
made it impossible to search, so finding a receipt meant looking at each
image individually.  I think, therefore, the best solution is to store
the images along with manually-entered data.

To implement this new functionality, I am using `sqlx`, a SQL toolkit
for Rust.  It's not exactly an ORM, nor does it have a dynamic query
builder like SQLAlchemy, but it does have compile-time checking of
query strings and can produce type-safe query results.  Rocket has
support for managing its connection pools as part of the server state,
so that simplifies usage quite a bit.

On the front-end, I factored out the camera image capture into an HTML
custom element, `camera-input`.  I did not update the original form to
use it, since I imagine that workflow will actually go away entirely.
2025-03-09 19:55:08 -05:00
Dustin a885c3f8ba Use Rocket's Figment for configuration
Instead of reading our own TOML file for configuration, we can hook into
Rocket's [built-in configuration system][0].  Although it doesn't matter
much right now, it may if we end up using Rocket's SQL [database
integration][1], because it uses the same mechanism.  Without making
this change, we would end up with two configuration files in that case.

[0]: https://rocket.rs/guide/v0.5/configuration/#extracting-values
[1]: https://rocket.rs/guide/v0.5/state/#databases
2025-03-09 07:11:20 -05:00
Dustin dccd64f0e0 Add container image build script 2025-03-08 21:15:16 -06:00
Dustin 40d4eb3ed6 ui: Request higher video resolution from camera
Apparently, you get 640x480 unless you ask for more?  Need to constrain
the viewer size, though, otherwise it massively overflows the page and
makes it impossible to see what you're taking a picture of.
2025-03-08 21:14:29 -06:00
Dustin 4ac24aa8cc ui: Remove photo cropper element
It turns out the cropper is _way_ too hard to use on mobile.  The
cropper handles are much too small for a touch screen.  Maybe I can
figure out how to improve the UX eventually, but for now, Tabitha
requested that we remove that functionality.
2025-03-08 20:28:38 -06:00
Dustin bf844224b5 ui: Persist success notification, redirect to list
Tabitha requested that the application returns to the transaction list
after the form was submitted successfully.  Before the navigation
starts, we still want to see the info toast, though.  Since the
navigation may take a few seconds, we keep the toast open indefinitely.
2025-03-08 20:18:37 -06:00
Dustin b5dff8eaf7 ui: Disable submit button while cropping
It's not immediately clear that submitting the form while the cropper is
active will not include the image _at all_.  To make this evident, we
disable the submit button until the crop is complete.
2025-03-08 20:15:41 -06:00
Dustin 9fe1eb2c0d ui: Fix date field on xact form
Accidentally left a hard-coded development value here.
2025-03-08 20:14:54 -06:00
Dustin 21b10c4ec1 backend: Attach photo to Journal ID
Firefly attachments are related to transaction journal entries rather
than the transactions themselves.  In other words, they're attached to
splits.
2025-03-08 20:13:10 -06:00
Dustin ff043631fa ui: Move camera action buttons below image viewer
On mobile, the screen is too narrow to put the action buttons to the
right of the image viewer.
2025-03-08 20:12:20 -06:00
Dustin 1f8584e164 ui: Select environment camera if possible
Apparently, Firefox/Android defaults to using the front camera, and
does not provide any native UI for selecting a different one.  We can
request the back camera by indiciting that the "environment" camera is
"ideal."
2025-03-08 20:10:50 -06:00
Dustin ab4b443a2d Fix path to static resources
In production deployments, the static assets are stored in
`/usr/local/share/receipts/static`.  The working directory is
`/usr/local/share/receipts`, so using a relative path of `static` is
sufficient.  We can use the same path in development with a symlink
pointing to the `esbuild` output directory.
2025-03-08 20:09:13 -06:00
Dustin 62e040836a Attach receipts to Firefly transactions
And now we come to the meat of the thing: the ability to update
transactions and attach receipts.  Most of this is straightforward,
except for changing the amount of split transactions.  Hopefully, this
won't come up too often, since I can't really split transactions without
a receipt.  Just to be on the safe side, attempting to change the amount
of a split transaction will return an error.
2025-03-08 20:08:14 -06:00
Dustin 5169758c23 Fetch transactions from Firefly III
This is all pretty straightforward.  The only real problem is that
the search results only contain matching transactions *splits*.  Since
transactions themselves do not have an amount, the value shown in the
_Amount_ column on the transaction list may be incorrect if a
transaction contains multiple splits and some of them do not match the
search query.
2025-03-08 16:01:08 -06:00
Dustin ec2e477fcd Implement basic page navigation w/ mock data
Obviously, we'll replace the mock `Database` with a Firefly III API
client, but this is here for now to support the UI interactions.
2025-03-08 11:16:35 -06:00
Dustin 7c6e993c1b fixup! Initial commit 2025-03-08 11:16:13 -06:00
Dustin 660a882971 js: Initial UI implementation
I've implemented the UI using TypeScript and Shoelace.  I originally
started with Pico CSS, but I didn't really like its visuals.  Since
capturing photos using the camera requires JavaScript, and that's
basically the entire point of this application, Shoelace's JavaScript
dependency (for WebComponents), is acceptable.

The photo capture uses the Media Capture Web API, which exposes the
camera directly as a video stream.  We capture a frame from this stream
and save it in a canvas, which we then pass to Cropper.js to let the
user select only the relevant portion of the picture containing the
receipt itself.
2025-03-08 11:11:42 -06:00
Dustin 63ced69e31 Initial commit 2025-03-05 18:02:52 -06:00