Skip to content

Commit

Permalink
Add invoice app
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoginth committed Dec 4, 2024
1 parent d4f6b19 commit 2146ef9
Show file tree
Hide file tree
Showing 6 changed files with 433 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/invoice/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
38 changes: 38 additions & 0 deletions apps/invoice/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Base image
FROM node:18-alpine AS base
RUN apk add --no-cache libc6-compat

# Installer stage
FROM base AS installer
WORKDIR /app

# Install pnpm globally
RUN npm install -g pnpm

# Copy all files to the build context
COPY . .

# Install dependencies
RUN pnpm install --frozen-lockfile

# Prune dev dependencies to reduce image size
RUN pnpm prune --prod

# Runner stage
FROM base AS runner
WORKDIR /app

# Install pnpm globally
RUN npm install -g pnpm

# Add non-root user for better security
RUN addgroup --system --gid 1001 hey
RUN adduser --system --uid 1001 app

USER app

# Copy built application and production dependencies from builder stage
COPY --from=installer /app .

# Command to run the app
CMD sleep 3 && pnpm --filter @hey/cron run start
20 changes: 20 additions & 0 deletions apps/invoice/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@hey/invoice",
"version": "0.0.0",
"private": true,
"license": "AGPL-3.0",
"scripts": {
"generate": "NODE_ENV=production tsx src/index.ts",
"typecheck": "tsc --pretty"
},
"dependencies": {
"dotenv": "^16.4.5",
"easyinvoice": "^3.0.47",
"tsx": "^4.19.2"
},
"devDependencies": {
"@hey/config": "workspace:*",
"@types/node": "^22.10.0",
"typescript": "^5.7.2"
}
}
49 changes: 49 additions & 0 deletions apps/invoice/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import easyinvoice, { type InvoiceData } from "easyinvoice";

const forYogi = true;
const month = "1";
const year = "2024";

const amountPerAccount = 33.87;

const data: InvoiceData = {
apiKey: "PntktbOaJHXsR5272jJImlN5KW6RbXp0KL646ojBoM2SS5Set5Yh45pPPJ3DrON9",
mode: "production",
images: { logo: "https://hey-assets.b-cdn.net/images/app-icon/0.png" },
sender: {
company: forYogi ? "Yoginth" : "Sagar",
address: `HD-${forYogi ? "322" : "323"}, WeWork Latitude, 10th floor, RMZ Latitude Commercial, Bellary Road, Hebbal, Near Godrej Apt`,
zip: "560024",
city: "Bangalore, Karnataka",
country: "India"
},
translate: { number: "Invoice Number" },
products: [
{ description: "Hey Account", price: amountPerAccount, quantity: "1" }
],
bottomNotice: `GSTIN: ${forYogi ? "29AYKPY4219R1Z8" : "29JZXPS2474H1Z6"}`,
settings: {
currency: "INR",
taxNotation: "GST",
marginTop: 25,
marginRight: 25,
marginLeft: 25,
marginBottom: 25
}
};

const generateInvoice = () => {
const dueDate = `${month}/${Math.floor(Math.random() * 30) + 1}/${year}`;

const injectedData: InvoiceData = {
...data,
client: { company: "Client Corp" },
information: { number: "1", dueDate }
};

easyinvoice.createInvoice(injectedData, (result) => {
console.log("PDF base64 string: ", result.pdf);
});
};

generateInvoice();
10 changes: 10 additions & 0 deletions apps/invoice/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@hey/config/base.tsconfig.json",
"compilerOptions": {
"module": "CommonJS",
"noEmit": false,
"outDir": "dist",
"baseUrl": "."
},
"include": ["**/*.ts", "src"]
}
Loading

0 comments on commit 2146ef9

Please sign in to comment.