talkgroup

invoice archetypes

Tags: #<Tag:0x00007fd91ff89350> #<Tag:0x00007fd91ff891c0> #<Tag:0x00007fd91ff89058>

Deciding to use Hugo for invoicing, I planned out how I wanted it. But the invoice archetype is holding me up, let’s see if talking it out helps. :slight_smile:

Basically, I want to create a new invoice and have it loaded with a bunch of info for me, including a sequential/unique ID.

I figure I’d use something like:

title: UUID; no one ever sees this
date: on creation, use to determine pay-by date
client: taxonomy of clients (meaning they need to be entered, first)

Oh yeah: Archetypes | Hugo

The default archetype is:

title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true

That take the name of the file created and transforms it. I’ll probably write a small bash script that runs the hugo command and pass it a date, epoch, or UUID as the name, and then I can go from there.


Okay, invoices have tables of services, ne? I mean, they don’t have to, but I often have multiple line items, each with their own cost and quantity. I rarely charge by hour, but I do charge by multiple months: “Monthly hosting $X, for 3 months.”

Additionally, I’d like to use the database of text information that is my invoices and create reports for myself. That means including the invoice fees in front matter or related data.

I’m using YAML, which contains nested values. I’m wondering if I can utilize that to fill in certain details. Something like:

fee:
  description: Monthly Hosting
  cost: 50
  quantity: 3

I’ll be editing these in nvim, so loading 3 or 4 fee blocks in the archetype and then deleting the ones I don’t need will probably work. Then I can do the math and build the table in the relevant template.


Okay, there are some presumptions, let’s see how it works…

I wanted to get the line items in front matter handled, and after some trial and error, I figured out a nested YAML formatting that works:

fee:
- description: Monthly Hosting
  cost: 50
  quantity: 3
- description: Tech Support
  cost: 75
  quantity: 6
- description: Monthly Hosting
  cost: 20
  quantity: 6

I was able to produce the output I wanted:

<table>
    <thead>
        <tr>
            <th>Description</th>
            <th>Cost</th>
            <th>Qty</th>
            <th>Line Total</th>
        </tr>
    </thead>
    <tbody>
    
        <tr>
            <td>Monthly Hosting</td>
            <td>50</td>
            <td>3</td>
            <td>150</td>
        </tr>
    
        <tr>
            <td>Tech Support</td>
            <td>75</td>
            <td>6</td>
            <td>450</td>
        </tr>
    
        <tr>
            <td>Monthly Hosting</td>
            <td>20</td>
            <td>6</td>
            <td>120</td>
        </tr>
    
    </tbody>
</table>

But I’m not sure how to get the total of line totals:

Anyone have an idea? :slight_smile:

Zachary did!

I was able to incorporate that into my template and it produces what I expect!

<table>
    <thead>
        <tr>
            <th>Description</th>
            <th>Cost</th>
            <th>Qty</th>
            <th>Line Total</th>
        </tr>
    </thead>
    <tbody>
    {{ $total := 0 }}
    {{ range .Params.fee }}
        {{ $line_total := mul .cost .quantity }}
        <tr>
            <td>{{ .description }}</td>
            <td>{{ .cost }}</td>
            <td>{{ .quantity }}</td>
            <td>{{ $line_total }}</td>
        </tr>
        {{ $total = add $total $line_total }}
    {{ end }}
        <tr>
            <td>
              {{ $total }}
            </td>
         </tr>
    </tbody>
</table>
<table>
    <thead>
        <tr>
            <th>Description</th>
            <th>Cost</th>
            <th>Qty</th>
            <th>Line Total</th>
        </tr>
    </thead>
    <tbody>
    
    
        
        <tr>
            <td>Monthly Hosting</td>
            <td>50</td>
            <td>3</td>
            <td>150</td>
        </tr>
        
    
        
        <tr>
            <td>Tech Support</td>
            <td>75</td>
            <td>6</td>
            <td>450</td>
        </tr>
        
    
        
        <tr>
            <td>Monthly Hosting</td>
            <td>20</td>
            <td>6</td>
            <td>120</td>
        </tr>
        
    
        <tr>
            <td>
              720
            </td>
         </tr>
    </tbody>
</table>

Most of my concerns about the concept are relieved, so next step will be packaging what I have so far into a theme component.

I have the beginnings of a theme component thing at maiki/bizwax: An invoice template system for Hugo. - allthe.codes. I’m still getting a feel for how to develop a thing as a module locally, and how to use it to actually deploy.

For this project I will setup a demo site somewhere, with a demonstration repo on how to pull it together. Obviously we’d not publish our actually invoices online.