@dascompany/product 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/reader/OrderProductsReader.js +2 -2
- package/dist/reader/ProductReader.js +2 -2
- package/dist/stockObjects/Order.js +2 -2
- package/dist/stockObjects/Product.js +3 -3
- package/dist/utils/PriceConverter.d.ts +4 -0
- package/dist/utils/PriceConverter.js +14 -0
- package/dist/utils/createQueryOptionsForId.d.ts +2 -0
- package/dist/utils/createQueryOptionsForId.js +6 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -77,4 +77,6 @@ import CompanyData from "./stockObjects/CompanyData";
|
|
|
77
77
|
import CompanyDataRepo from "./repo/CompanyDataRepo";
|
|
78
78
|
import CompanyDataReader from "./reader/CompanyDataReader";
|
|
79
79
|
import CompanyDataI from "./types/CompanyDataI";
|
|
80
|
-
|
|
80
|
+
import PriceConverter from "./utils/PriceConverter";
|
|
81
|
+
import createQueryOptionsForId from "./utils/createQueryOptionsForId";
|
|
82
|
+
export { Client, ClientAccountRepo, ClientAccountReader, Admin, AdminRepo, AdminReader, Address, AddressI, AddressesRepo, AddressesReader, PersonalData, PersonalDataRepo, PersonalDataReader, PersonalDataI, CompanyDetails, CompanyDetailsRepo, CompanyDetailsReader, CompanyDetailsI, ContactDetails, ContactDetailsRepo, ContactDetailsReader, ContactDetailsI, DeliveryDetails, DeliveryDetailsRepo, DeliveryDetailsReader, DeliveryDetailsI, DeliveryMethods, DeliveryMethodRepo, DeliveryMethodReader, DeliveryMethodI, DeliveryMethodTypeE, DeliveryStatus, DeliveryStatusReader, DeliveryStatusTypeE, InvoiceDetails, InvoiceDetailsRepo, InvoiceDetailsReader, InvoiceDetailsI, PaymentDetails, PaymentDetailsRepo, PaymentDetailsReader, PaymentDetailsI, PaymentMethods, PaymentMethodRepo, PaymentMethodReader, PaymentMethodE, PaymentMethodI, PaymentStatus, PaymentStatusesReader, PaymentStatusE, Order, OrderRepo, OrderReader, OrderProduct, OrderProductsRepo, OrderProductsReader, OrderProductI, Status, OrderStatusRepo, OrderStatusReader, StatusI, OrderStatusTypeE, StatusTypesReader, ProductI, Product, ProductRepo, ProductReader, File, FilesRepo, FilesReader, FileI, FileConnection, FileConnectionsRepo, FileConnectionsReader, FileConnectionTypeE, CompanyData, CompanyDataRepo, CompanyDataReader, CompanyDataI, PriceConverter, createQueryOptionsForId };
|
package/dist/index.js
CHANGED
|
@@ -63,4 +63,6 @@ import FileConnectionTypeE from './types/FileConnectionTypeE';
|
|
|
63
63
|
import CompanyData from "./stockObjects/CompanyData";
|
|
64
64
|
import CompanyDataRepo from "./repo/CompanyDataRepo";
|
|
65
65
|
import CompanyDataReader from "./reader/CompanyDataReader";
|
|
66
|
-
|
|
66
|
+
import PriceConverter from "./utils/PriceConverter";
|
|
67
|
+
import createQueryOptionsForId from "./utils/createQueryOptionsForId";
|
|
68
|
+
export { Client, ClientAccountRepo, ClientAccountReader, Admin, AdminRepo, AdminReader, Address, AddressesRepo, AddressesReader, PersonalData, PersonalDataRepo, PersonalDataReader, CompanyDetails, CompanyDetailsRepo, CompanyDetailsReader, ContactDetails, ContactDetailsRepo, ContactDetailsReader, DeliveryDetails, DeliveryDetailsRepo, DeliveryDetailsReader, DeliveryMethods, DeliveryMethodRepo, DeliveryMethodReader, DeliveryMethodTypeE, DeliveryStatus, DeliveryStatusReader, DeliveryStatusTypeE, InvoiceDetails, InvoiceDetailsRepo, InvoiceDetailsReader, PaymentDetails, PaymentDetailsRepo, PaymentDetailsReader, PaymentMethods, PaymentMethodRepo, PaymentMethodReader, PaymentMethodE, PaymentStatus, PaymentStatusesReader, PaymentStatusE, Order, OrderRepo, OrderReader, OrderProduct, OrderProductsRepo, OrderProductsReader, Status, OrderStatusRepo, OrderStatusReader, OrderStatusTypeE, StatusTypesReader, Product, ProductRepo, ProductReader, File, FilesRepo, FilesReader, FileConnection, FileConnectionsRepo, FileConnectionsReader, FileConnectionTypeE, CompanyData, CompanyDataRepo, CompanyDataReader, PriceConverter, createQueryOptionsForId };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ParameterType, QueryOptions } from "@dascompany/database";
|
|
2
2
|
import DatabaseConnection from "../DatabaseConnection";
|
|
3
|
-
import calculateNetToGrossPrice from "../utils/calculateNetToGrossPrice";
|
|
4
3
|
import FilesReader from "./FilesReader";
|
|
4
|
+
import PriceConverter from "../utils/PriceConverter";
|
|
5
5
|
export default class OrderProductsReader {
|
|
6
6
|
static async getAll(queryOptions) {
|
|
7
7
|
const orderProducts = await DatabaseConnection.getInstance().ordersProducts.selectAll(queryOptions);
|
|
@@ -28,7 +28,7 @@ export default class OrderProductsReader {
|
|
|
28
28
|
sku: orderProduct.sku,
|
|
29
29
|
title: orderProduct.title,
|
|
30
30
|
netPrice: orderProduct.net_price,
|
|
31
|
-
grossPrice:
|
|
31
|
+
grossPrice: PriceConverter.netToGrossPrice(orderProduct.net_price, orderProduct.vat),
|
|
32
32
|
vat: orderProduct.vat,
|
|
33
33
|
file,
|
|
34
34
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ParameterType, QueryOptions } from "@dascompany/database";
|
|
2
|
-
import calculateNetToGrossPrice from "../utils/calculateNetToGrossPrice";
|
|
3
2
|
import FilesReader from "./FilesReader";
|
|
4
3
|
import DatabaseConnection from "../DatabaseConnection";
|
|
5
4
|
import FileConnectionTypeE from "../types/FileConnectionTypeE";
|
|
5
|
+
import PriceConverter from "../utils/PriceConverter";
|
|
6
6
|
export default class ProductReader {
|
|
7
7
|
static async get(queryOption) {
|
|
8
8
|
const product = await DatabaseConnection.getInstance().products.select(queryOption);
|
|
@@ -55,7 +55,7 @@ export default class ProductReader {
|
|
|
55
55
|
createdAt: product.created_at,
|
|
56
56
|
deleted: product.deleted,
|
|
57
57
|
thumbnail: thumbnail ? thumbnail : null,
|
|
58
|
-
grossPrice:
|
|
58
|
+
grossPrice: PriceConverter.netToGrossPrice(product.net_price, product.vat),
|
|
59
59
|
jsonData: product.json_data
|
|
60
60
|
};
|
|
61
61
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ParameterType, QueryOptions, StockObject } from "@dascompany/database";
|
|
2
2
|
import OrderMapper from "../mappers/OrderMapper";
|
|
3
3
|
import OrderProductsRepo from "../repo/OrderProductsRepo";
|
|
4
|
-
import
|
|
4
|
+
import PriceConverter from "../utils/PriceConverter";
|
|
5
5
|
export default class Order extends StockObject {
|
|
6
6
|
email;
|
|
7
7
|
price;
|
|
@@ -45,7 +45,7 @@ export default class Order extends StockObject {
|
|
|
45
45
|
}
|
|
46
46
|
getGrossPrice() {
|
|
47
47
|
const vatPercentage = 23; //brak stawki vat dla zamówienia
|
|
48
|
-
return
|
|
48
|
+
return PriceConverter.netToGrossPrice(this.price, vatPercentage);
|
|
49
49
|
}
|
|
50
50
|
getclientId() {
|
|
51
51
|
return this.clientId;
|
|
@@ -2,7 +2,7 @@ import { ParameterType, QueryOptions, StockObject } from "@dascompany/database";
|
|
|
2
2
|
import ProductMapper from "../mappers/ProductMapper";
|
|
3
3
|
import FilesReader from "../reader/FilesReader";
|
|
4
4
|
import FileConnectionTypeE from "../types/FileConnectionTypeE";
|
|
5
|
-
import
|
|
5
|
+
import PriceConverter from "../utils/PriceConverter";
|
|
6
6
|
export default class Product extends StockObject {
|
|
7
7
|
sku;
|
|
8
8
|
url;
|
|
@@ -54,7 +54,7 @@ export default class Product extends StockObject {
|
|
|
54
54
|
return this.description;
|
|
55
55
|
}
|
|
56
56
|
getNetPrice() {
|
|
57
|
-
return
|
|
57
|
+
return PriceConverter.netToGrossPrice(this.netPrice, this.vat);
|
|
58
58
|
}
|
|
59
59
|
getGrossPrice() {
|
|
60
60
|
return this.netPrice;
|
|
@@ -126,7 +126,7 @@ export default class Product extends StockObject {
|
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
128
|
calculateGrossPrice() {
|
|
129
|
-
return
|
|
129
|
+
return PriceConverter.netToGrossPrice(this.netPrice, this.vat);
|
|
130
130
|
}
|
|
131
131
|
setCreatedAt(createdAt) {
|
|
132
132
|
this.createdAt = createdAt;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default class PriceConverter {
|
|
2
|
+
static netToGrossPrice(netPrice, vatPercentage = 23) {
|
|
3
|
+
const netPriceInPenny = Math.round(netPrice * 100);
|
|
4
|
+
const vatPriceInPenny = Math.round((netPriceInPenny * vatPercentage) / 100);
|
|
5
|
+
const grossPriceInPenny = netPriceInPenny + vatPriceInPenny;
|
|
6
|
+
const grossPrice = (grossPriceInPenny / 100).toFixed(2);
|
|
7
|
+
return Number(grossPrice);
|
|
8
|
+
}
|
|
9
|
+
static grossToNetPrice(grossPrice, vatPercentage = 23) {
|
|
10
|
+
const grossPriceInPenny = Math.round(grossPrice * 100);
|
|
11
|
+
const netPrice = ((grossPriceInPenny / (vatPercentage / 100 + 1)) / 100).toFixed(2);
|
|
12
|
+
return Number(netPrice);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ParameterType, QueryOptions } from "@dascompany/database";
|
|
2
|
+
export default function createQueryOptionsForId(id) {
|
|
3
|
+
const queryOptions = new QueryOptions();
|
|
4
|
+
queryOptions.setWhere([{ name: 'id', type: ParameterType.bigint, value: id }]);
|
|
5
|
+
return queryOptions;
|
|
6
|
+
}
|