This repository has been archived by the owner on May 6, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from Tolfix/dev
v2.8
- Loading branch information
Showing
20 changed files
with
313 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { IQuotes } from "@interface/Quotes.interface"; | ||
import { GetCurrencySymbol } from "../../../Lib/Currencies"; | ||
import GetTableStyle from "../CSS/GetTableStyle"; | ||
|
||
export default async function printQuotesItemsTable(quote: IQuotes) | ||
{ | ||
return ` | ||
<table style="${GetTableStyle}"> | ||
<thead> | ||
<tr> | ||
<th>Product</th> | ||
<th>Quantity</th> | ||
<th>Price</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
${(await Promise.all(quote.items.map(async item => ` | ||
<tr> | ||
<td>${item.name}</td> | ||
<td>${item.quantity}</td> | ||
<td>${item.price} ${GetCurrencySymbol(quote.currency)}</td> | ||
</tr> | ||
`))).join('')} | ||
</tbody> | ||
</table> | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { stripIndents } from "common-tags"; | ||
import { CPG_Customer_Panel_Domain } from "../../../Config"; | ||
import { ICustomer } from "@interface/Customer.interface"; | ||
import getFullName from "../../../Lib/Customers/getFullName"; | ||
import UseStyles from "../General/UseStyles"; | ||
import { IQuotes } from "@interface/Quotes.interface"; | ||
|
||
export default async (quote: IQuotes, customer: ICustomer) => await UseStyles(stripIndents` | ||
<div> | ||
<h1>Hello ${getFullName(customer)}.</h1> | ||
<p> | ||
This is a notice that quote <strong>#${quote.id}</strong> has been accepted. | ||
</p> | ||
<p> | ||
We will generate a invoice for you shortly. | ||
</p> | ||
${CPG_Customer_Panel_Domain ? ` | ||
<p> | ||
<a href="${CPG_Customer_Panel_Domain}/quotes?id=${quote.id}">View quote</a>. | ||
</p> | ||
` : ''} | ||
</div> | ||
`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { stripIndents } from "common-tags"; | ||
import { Company_Name, CPG_Customer_Panel_Domain } from "../../../Config"; | ||
import { ICustomer } from "@interface/Customer.interface"; | ||
import getFullName from "../../../Lib/Customers/getFullName"; | ||
import UseStyles from "../General/UseStyles"; | ||
import { IQuotes } from "@interface/Quotes.interface"; | ||
import printQuotesItemsTable from "../Methods/QuotesItems.print"; | ||
|
||
export default async (quote: IQuotes, customer: ICustomer) => await UseStyles(stripIndents` | ||
<div> | ||
<h1>Hello ${getFullName(customer)}.</h1> | ||
<p> | ||
This is a notice that <strong>${await Company_Name()}</strong> has sent a <strong>quote</strong> to you. | ||
</p> | ||
<p> | ||
<strong>Memo:</strong> ${quote.memo} | ||
</p> | ||
<p> | ||
<strong>Due Date:</strong> ${quote.due_date} | ||
</p> | ||
<p> | ||
<strong>Payment Method:</strong> ${quote.payment_method} | ||
</p> | ||
${await printQuotesItemsTable(quote)} | ||
<p> | ||
<strong> | ||
Total: | ||
</strong> | ||
${quote.items.reduce((total, item) => total + (item.price * item.quantity), 0) + ((quote.tax_rate/100) * quote.items.reduce((total, item) => total + (item.price * item.quantity), 0))} | ||
</p> | ||
${CPG_Customer_Panel_Domain ? ` | ||
<p> | ||
<a href="${CPG_Customer_Panel_Domain}/quotes?id=${quote.id}">View quote</a> to accept or decline. | ||
</p> | ||
` : ''} | ||
</div> | ||
`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { IQuotes } from "@interface/Quotes.interface"; | ||
import InvoiceModel from "../../Database/Models/Invoices.model"; | ||
import { idInvoice } from "../Generator"; | ||
import dateFormat from "date-and-time"; | ||
import mainEvent from "../../Events/Main.event"; | ||
|
||
export default async (quote: IQuotes) => | ||
{ | ||
// Converts quote to invoice | ||
const invoice = await (new InvoiceModel({ | ||
uid: idInvoice(), | ||
customer_uid: quote.customer_uid, | ||
items: quote.items.map(item => ({ | ||
notes: item.name, | ||
amount: item.price, | ||
quantity: item.quantity, | ||
})), | ||
dates: { | ||
invoice_date: dateFormat.format(new Date(), "YYYY-MM-DD"), | ||
due_date: quote.due_date, | ||
}, | ||
amount: quote.items.reduce((acc, item) => acc + item.price * item.quantity, 0), | ||
currency: quote.currency, | ||
tax_rate: quote.tax_rate, | ||
notified: false, | ||
transactions: [], | ||
paid: false, | ||
notes: quote.memo, | ||
payment_method: quote.payment_method, | ||
}).save()); | ||
|
||
mainEvent.emit("invoice_created", invoice); | ||
|
||
return invoice; | ||
} |
Oops, something went wrong.