Skip to content
This repository was archived by the owner on May 6, 2022. It is now read-only.

Commit 64a31a6

Browse files
authored
Merge pull request #95 from Tolfix/dev
v2.8
2 parents 50d0b0f + 7229546 commit 64a31a6

20 files changed

Lines changed: 313 additions & 47 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cpg-api",
3-
"version": "v2.7",
3+
"version": "v2.8",
44
"description": "Central Payment Gateway",
55
"main": "./build/Main.js",
66
"dependencies": {

src/Database/Models/Quotes.model.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { IQuotes } from "@interface/Quotes.interface";
55
import Logger from "../../Lib/Logger";
66
import GetText from "../../Translation/GetText";
77
import { A_CC_Payments } from "../../Types/PaymentMethod";
8+
import { currencyCodes } from "../../Lib/Currencies";
89

910
const QuotesSchema = new Schema
1011
(
@@ -27,7 +28,6 @@ const QuotesSchema = new Schema
2728
type: [
2829
{
2930
name: String,
30-
tax_rate: Number,
3131
price: Number,
3232
quantity: Number,
3333
}
@@ -50,6 +50,28 @@ const QuotesSchema = new Schema
5050
default: "",
5151
},
5252

53+
currency: {
54+
type: String,
55+
required: true,
56+
enum: currencyCodes,
57+
default: "EUR",
58+
},
59+
60+
tax_rate: {
61+
type: Number,
62+
default: 0,
63+
},
64+
65+
accepted: {
66+
type: Boolean,
67+
default: false
68+
},
69+
70+
declined: {
71+
type: Boolean,
72+
default: false
73+
},
74+
5375
payment_method: {
5476
type: String,
5577
enum: [...A_CC_Payments],

src/Database/Models/Transactions.model.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import mongoose, { model, Schema } from "mongoose"
1+
import mongoose, { Document, model, Schema } from "mongoose"
22
import increment from "mongoose-auto-increment";
33
import { Default_Language, MongoDB_URI } from "../../Config";
4-
import { IDTransactions } from "@interface/Transactions.interface";
4+
import { ITransactions } from "@interface/Transactions.interface";
55
import Logger from "../../Lib/Logger";
66
import GetText from "../../Translation/GetText";
77
import { A_CC_Payments } from "../../Types/PaymentMethod";
@@ -58,7 +58,7 @@ const TransactionsSchema = new Schema
5858
);
5959

6060
// Log when a transaction is created
61-
TransactionsSchema.post('save', function(doc: IDTransactions)
61+
TransactionsSchema.post('save', function(doc: ITransactions & Document)
6262
{
6363
Logger.db(GetText(Default_Language).database.txt_Model_Created(doc.modelName, doc.uid));
6464
// Logger.db(`Created transaction ${doc.uid}`);
@@ -74,6 +74,6 @@ TransactionsSchema.plugin(increment.plugin, {
7474
incrementBy: 1
7575
});
7676

77-
const TransactionsModel = model<IDTransactions>("transactions", TransactionsSchema);
77+
const TransactionsModel = model<ITransactions & Document>("transactions", TransactionsSchema);
7878

7979
export default TransactionsModel;

src/Email/Templates/Invoices/Invoice.template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default async (invoice: IInvoice & IInvoiceMethods, customer: ICustomer)
7878
</p>
7979
${CPG_Customer_Panel_Domain ? `
8080
<p>
81-
<a href="${CPG_Customer_Panel_Domain}/invoices/${invoice.id}">View Invoice</a>
81+
<a href="${CPG_Customer_Panel_Domain}/invoices?id=${invoice.id}">View Invoice</a>
8282
</p>
8383
` : ''}
8484
</div>

src/Email/Templates/Invoices/LateInvoice.Template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default async (invoice: IInvoice & IInvoiceMethods, customer: ICustomer)
7878
</p>
7979
${CPG_Customer_Panel_Domain ? `
8080
<p>
81-
<a href="${CPG_Customer_Panel_Domain}/invoices/${invoice.id}">View Invoice</a>
81+
<a href="${CPG_Customer_Panel_Domain}/invoices?id=${invoice.id}">View Invoice</a>
8282
</p>
8383
` : ''}
8484
</div>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { IQuotes } from "@interface/Quotes.interface";
2+
import { GetCurrencySymbol } from "../../../Lib/Currencies";
3+
import GetTableStyle from "../CSS/GetTableStyle";
4+
5+
export default async function printQuotesItemsTable(quote: IQuotes)
6+
{
7+
return `
8+
<table style="${GetTableStyle}">
9+
<thead>
10+
<tr>
11+
<th>Product</th>
12+
<th>Quantity</th>
13+
<th>Price</th>
14+
</tr>
15+
</thead>
16+
<tbody>
17+
${(await Promise.all(quote.items.map(async item => `
18+
<tr>
19+
<td>${item.name}</td>
20+
<td>${item.quantity}</td>
21+
<td>${item.price} ${GetCurrencySymbol(quote.currency)}</td>
22+
</tr>
23+
`))).join('')}
24+
</tbody>
25+
</table>
26+
`
27+
}

src/Email/Templates/Orders/NewOrderCreated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default async (order: IOrder, customer: ICustomer) => await UseStyles(str
5252
5353
${CPG_Customer_Panel_Domain ? `
5454
<p>
55-
<a href="${CPG_Customer_Panel_Domain}/orders/${order.id}">View Order</a>
55+
<a href="${CPG_Customer_Panel_Domain}/orders?id=${order.id}">View Order</a>
5656
</p>
5757
` : ''}
5858

src/Email/Templates/Payments/PaymentFailed.template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export = async (invoice: IInvoice, customer: ICustomer) => UseStyles(stripIndent
4141
${CPG_Customer_Panel_Domain ? `
4242
4343
<p>
44-
<a href="${CPG_Customer_Panel_Domain}/invoices/${invoice.uid}">View invoice</a>
44+
<a href="${CPG_Customer_Panel_Domain}/invoices?id=${invoice.id}">View invoice</a>
4545
</p>
4646
4747
` : ''}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { stripIndents } from "common-tags";
2+
import { CPG_Customer_Panel_Domain } from "../../../Config";
3+
import { ICustomer } from "@interface/Customer.interface";
4+
import getFullName from "../../../Lib/Customers/getFullName";
5+
import UseStyles from "../General/UseStyles";
6+
import { IQuotes } from "@interface/Quotes.interface";
7+
8+
export default async (quote: IQuotes, customer: ICustomer) => await UseStyles(stripIndents`
9+
<div>
10+
<h1>Hello ${getFullName(customer)}.</h1>
11+
<p>
12+
This is a notice that quote <strong>#${quote.id}</strong> has been accepted.
13+
</p>
14+
<p>
15+
We will generate a invoice for you shortly.
16+
</p>
17+
${CPG_Customer_Panel_Domain ? `
18+
<p>
19+
<a href="${CPG_Customer_Panel_Domain}/quotes?id=${quote.id}">View quote</a>.
20+
</p>
21+
` : ''}
22+
</div>
23+
`);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { stripIndents } from "common-tags";
2+
import { Company_Name, CPG_Customer_Panel_Domain } from "../../../Config";
3+
import { ICustomer } from "@interface/Customer.interface";
4+
import getFullName from "../../../Lib/Customers/getFullName";
5+
import UseStyles from "../General/UseStyles";
6+
import { IQuotes } from "@interface/Quotes.interface";
7+
import printQuotesItemsTable from "../Methods/QuotesItems.print";
8+
9+
export default async (quote: IQuotes, customer: ICustomer) => await UseStyles(stripIndents`
10+
<div>
11+
<h1>Hello ${getFullName(customer)}.</h1>
12+
<p>
13+
This is a notice that <strong>${await Company_Name()}</strong> has sent a <strong>quote</strong> to you.
14+
</p>
15+
<p>
16+
<strong>Memo:</strong> ${quote.memo}
17+
</p>
18+
<p>
19+
<strong>Due Date:</strong> ${quote.due_date}
20+
</p>
21+
<p>
22+
<strong>Payment Method:</strong> ${quote.payment_method}
23+
</p>
24+
25+
${await printQuotesItemsTable(quote)}
26+
27+
<p>
28+
<strong>
29+
Total:
30+
</strong>
31+
${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))}
32+
</p>
33+
${CPG_Customer_Panel_Domain ? `
34+
<p>
35+
<a href="${CPG_Customer_Panel_Domain}/quotes?id=${quote.id}">View quote</a> to accept or decline.
36+
</p>
37+
` : ''}
38+
</div>
39+
`);

0 commit comments

Comments
 (0)