Skip to content

Commit

Permalink
Add history, multiple memo lines, etc...
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Safee committed Jun 22, 2024
1 parent 50abca6 commit a7cc6e0
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 49 deletions.
2 changes: 1 addition & 1 deletion printmechecks/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { RouterLink, RouterView } from 'vue-router'
<RouterLink to="/" class="nav-link" :class="{'active': $route.path == '/'}">Check</RouterLink>
</li>
<li class="nav-item">
<RouterLink to="/settings" class="nav-link" :class="{'active': $route.path == '/settings'}">Settings</RouterLink>
<RouterLink to="/history" class="nav-link" :class="{'active': $route.path == '/history'}">History</RouterLink>
</li>
</ul>
<nav>
Expand Down
86 changes: 61 additions & 25 deletions printmechecks/src/components/CheckPrinter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<span class="dollar-line"></span>
</div>
<div class="bank-name" style="position: absolute; top: 300px; left: 60px">{{check.bankName}}</div>
<div class="memo-data" style="position: absolute; top: 377px; left: 120px">{{check.memo}}</div>
<div class="memo-data" style="position: absolute; top: 367px; left: 120px">{{check.memo}}</div>
<div class="memo" style="position: absolute; top: 390px; left: 60px">
Memo: ____________________________________
</div>
Expand Down Expand Up @@ -119,48 +119,64 @@
<input type="text" class="form-control" v-model="check.signature">
</div>
</form>
<div class="col-12" style="margin-top: 30px;">
<button type="button" class="btn btn-primary" @click="saveToHistory">Save to History</button>
</div>
</div>
</div>
</template>

<script setup lang="ts">
import print from 'print-js';
import { default as converter } from 'number-to-words';
import { ref, reactive, nextTick, watch} from 'vue'
const check = reactive({
accountHolderName: 'John Smith',
accountHolderAddress: '123 Cherry Tree Lane',
accountHolderCity: 'New York',
accountHolderState: 'NY',
accountHolderZip: '10001',
checkNumber: '554',
date: new Date().toLocaleDateString(),
bankName: 'Bank Name, INC',
amount: '100.00',
payTo: 'Michael Johnson',
memo: 'Rent',
signature: 'John Smith',
routingNumber: '022303659',
bankAccountNumber: '000000000000',
lineLength: 166
})
import { ref, reactive, nextTick, watch, onMounted} from 'vue'
import {formatMoney} from '../utilities.ts'
import {useAppStore} from '../stores/app.ts'
const state = useAppStore()
function toWords (number: string) {
if (!number) return ''
return converter.toWords(number)
}
function formatMoney (number: string) {
var numberFloat: float = parseFloat(number)
return numberFloat.toLocaleString('en-US', {style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2})
}
function printCheck () {
window.print()
}
function saveToHistory () {
let checkList = JSON.parse(localStorage.getItem('checkList') || '[]')
checkList.push(check)
localStorage.setItem('checkList', JSON.stringify(checkList))
}
function genNewCheck () {
let checkList = JSON.parse(localStorage.getItem('checkList') || '[]')
let recentCheck = checkList[checkList.length - 1]
let check = {}
check.accountHolderName = recentCheck?.accountHolderName || 'John Smith'
check.accountHolderAddress = recentCheck?.accountHolderAddress || '123 Cherry Tree Lane'
check.accountHolderCity = recentCheck?.accountHolderCity || 'New York'
check.accountHolderState = recentCheck?.accountHolderState || 'NY'
check.accountHolderZip = recentCheck?.accountHolderZip || '10001'
check.checkNumber = recentCheck?.checkNumber ? (parseInt(recentCheck?.checkNumber + 1)) : '100'
check.date = new Date().toLocaleDateString()
check.bankName = recentCheck?.bankName || 'Bank Name, INC'
check.amount = '0.00'
check.payTo = 'Michael Johnson'
check.memo = recentCheck?.memo || 'Rent'
check.signature = recentCheck?.signature || 'John Smith'
check.routingNumber = recentCheck?.routingNumber || '022303659'
check.bankAccountNumber = recentCheck?.bankAccountNumber || '000000000000'
return check
}
const check = reactive(
genNewCheck()
)
const line = ref(null)
watch(check, async () => {
Expand All @@ -171,6 +187,25 @@ watch(check, async () => {
}, { immediate: true })
onMounted(() => {
if (state.check) {
check.accountHolderName = state.check.accountHolderName
check.accountHolderAddress = state.check.accountHolderAddress
check.accountHolderCity = state.check.accountHolderCity
check.accountHolderState = state.check.accountHolderState
check.accountHolderZip = state.check.accountHolderZip
check.checkNumber = state.check.checkNumber
check.date = state.check.date
check.bankName = state.check.bankName
check.amount = state.check.amount
check.payTo = state.check.payTo
check.memo = state.check.memo
check.signature = state.check.signature
check.routingNumber = state.check.routingNumber
check.bankAccountNumber = state.check.bankAccountNumber
}
state.check = null
})
</script>

Expand All @@ -194,7 +229,8 @@ label {
.memo-data {
font-family: Caveat;
font-size: 30px;
transform: rotate(-2deg);
max-width: 350px;
line-height: 0.65;
}
.signature-data {
font-family: Caveat;
Expand Down
6 changes: 3 additions & 3 deletions printmechecks/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ const router = createRouter({
component: HomeView
},
{
path: '/settings',
name: 'settings',
path: '/history',
name: 'history',
// route level code-splitting
// this generates a separate chunk (About.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import('../views/SettingsView.vue')
component: () => import('../views/HistoryView.vue')
}
]
})
Expand Down
8 changes: 8 additions & 0 deletions printmechecks/src/stores/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useAppStore = defineStore('useAppStore', () => {
const check = ref(null)

return { check }
})
12 changes: 0 additions & 12 deletions printmechecks/src/stores/counter.ts

This file was deleted.

7 changes: 7 additions & 0 deletions printmechecks/src/utilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function formatMoney (number: string) {
var numberFloat: float = parseFloat(number)
return numberFloat.toLocaleString('en-US', {style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2})
}

export { formatMoney }

70 changes: 70 additions & 0 deletions printmechecks/src/views/HistoryView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<template>
<div class="about">
<h1>History</h1>
<div v-if="history.length === 0">
<p>No history yet</p>
</div>
<div v-else>
<table class="table">
<thead>
<tr>
<th>Check #</th>
<th>Amount</th>
<th>Payee</th>
<th>Account</th>
<th></th>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in history" :key="item.id">
<td>{{ item.checkNumber }}</td>
<td>${{ formatMoney(item.amount) }}</td>
<td>{{ item.payTo }}</td>
<td>{{ item.bankAccountNumber }}</td>
<td>
<button class="btn btn-outline-danger" @click="deleteItem(index)" style="margin-right: 10px">Delete</button>
<button class="btn btn-outline-primary" @click="viewItem(index)">View</button>
</td>

</tr>
</tbody>
</table>
</div>
</div>
</template>

<style>
</style>

<script setup>
import {formatMoney} from '../utilities.ts'
import { ref, onMounted} from 'vue'
import { useAppStore } from '../stores/app.ts'
import { useRouter } from 'vue-router'
const state = useAppStore()
const router = useRouter()
const history = ref([])
const loadHistory = () => {
history.value = JSON.parse(localStorage.getItem('checkList') || '[]')
}
const deleteItem = (index) => {
history.value.splice(index, 1)
localStorage.setItem('checkList', JSON.stringify(history.value))
}
const viewItem = (index) => {
const item = history.value[index]
state.check = item
router.push('/')
}
onMounted(() => {
loadHistory()
})
</script>
8 changes: 0 additions & 8 deletions printmechecks/src/views/SettingsView.vue

This file was deleted.

0 comments on commit a7cc6e0

Please sign in to comment.