@floristcloud/api-lib 1.2.107 → 1.2.108
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/build/commands/client/create-client.command.js +2 -0
- package/build/commands/client/get-client-list.query.js +8 -0
- package/build/commands/client/index.js +1 -0
- package/build/commands/client/update-client-contract-data.command.js +22 -0
- package/build/commands/client/update-client.command.js +2 -0
- package/build/commands/money-account/get-money-account-by-criteria.query.js +7 -2
- package/build/commands/money-account/get-money-account-list.query.js +5 -1
- package/build/commands/report/export-inventory-stock.query.js +4 -17
- package/build/commands/report/export-inventory-turnover.query.js +4 -27
- package/build/commands/report/get-inventory-stock.query.js +34 -0
- package/build/commands/report/get-inventory-turnover.query.js +43 -0
- package/build/commands/report/get-report-by-client-weeks.query.js +19 -0
- package/build/commands/report/get-report-group-by-client.query.js +21 -2
- package/build/commands/report/get-report-group-by-position.query.js +21 -2
- package/build/commands/report/get-sales-by-client.query.js +45 -0
- package/build/commands/report/index.js +3 -0
- package/build/commands/settings/get-company-profile.query.js +24 -0
- package/build/commands/settings/index.js +1 -0
- package/build/enum/client-contract-status.enum.js +13 -0
- package/build/enum/index.js +3 -0
- package/build/enum/report-sort-by.enum.js +13 -0
- package/build/helpers/index.js +2 -0
- package/build/helpers/pagination.helper.js +12 -0
- package/build/helpers/query-boolean.helper.js +16 -0
- package/build/schemas/client/client.schema.js +2 -0
- package/build/schemas/index.js +7 -0
- package/build/schemas/money-account/money-account-with-balance.schema.js +13 -0
- package/build/schemas/report/inventory-stock-category-item.schema.js +10 -0
- package/build/schemas/report/inventory-stock-detailed-item.schema.js +14 -0
- package/build/schemas/report/inventory-turnover-category-item.schema.js +15 -0
- package/build/schemas/report/inventory-turnover-detailed-item.schema.js +19 -0
- package/build/schemas/report/sales-by-client-row.schema.js +45 -0
- package/build/schemas/report/sales-by-client-top-item.schema.js +9 -0
- package/commands/client/create-client.command.ts +2 -0
- package/commands/client/get-client-list.query.ts +8 -0
- package/commands/client/index.ts +1 -0
- package/commands/client/update-client-contract-data.command.ts +24 -0
- package/commands/client/update-client.command.ts +2 -0
- package/commands/money-account/get-money-account-by-criteria.query.ts +10 -3
- package/commands/money-account/get-money-account-list.query.ts +8 -2
- package/commands/report/export-inventory-stock.query.ts +4 -19
- package/commands/report/export-inventory-turnover.query.ts +4 -29
- package/commands/report/get-inventory-stock.query.ts +36 -0
- package/commands/report/get-inventory-turnover.query.ts +45 -0
- package/commands/report/get-report-by-client-weeks.query.ts +20 -1
- package/commands/report/get-report-group-by-client.query.ts +22 -3
- package/commands/report/get-report-group-by-position.query.ts +23 -4
- package/commands/report/get-sales-by-client.query.ts +47 -0
- package/commands/report/index.ts +3 -0
- package/commands/settings/get-company-profile.query.ts +24 -0
- package/commands/settings/index.ts +1 -0
- package/enum/client-contract-status.enum.ts +9 -0
- package/enum/index.ts +3 -0
- package/enum/report-sort-by.enum.ts +9 -0
- package/helpers/index.ts +2 -0
- package/helpers/pagination.helper.ts +9 -0
- package/helpers/query-boolean.helper.ts +14 -0
- package/package.json +1 -1
- package/schemas/client/client.schema.ts +2 -0
- package/schemas/index.ts +7 -0
- package/schemas/money-account/money-account-with-balance.schema.ts +11 -0
- package/schemas/report/inventory-stock-category-item.schema.ts +8 -0
- package/schemas/report/inventory-stock-detailed-item.schema.ts +12 -0
- package/schemas/report/inventory-turnover-category-item.schema.ts +13 -0
- package/schemas/report/inventory-turnover-detailed-item.schema.ts +17 -0
- package/schemas/report/sales-by-client-row.schema.ts +43 -0
- package/schemas/report/sales-by-client-top-item.schema.ts +7 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MoneyAccountWithBalanceSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const money_account_schema_1 = require("./money-account.schema");
|
|
6
|
+
/**
|
|
7
|
+
* Денежный счёт в ответах списков. `balance` — текущий остаток счёта (приход минус расход),
|
|
8
|
+
* приходит только при `?withBalance=true`: поле аддитивное, клиенты без этого параметра
|
|
9
|
+
* получают ровно прежнюю форму ответа.
|
|
10
|
+
*/
|
|
11
|
+
exports.MoneyAccountWithBalanceSchema = money_account_schema_1.MoneyAccountSchema.extend({
|
|
12
|
+
balance: zod_1.z.number().optional(),
|
|
13
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InventoryStockCategoryItemSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/** Строка отчёта об остатках в разрезе категорий (`detailed=false`). */
|
|
6
|
+
exports.InventoryStockCategoryItemSchema = zod_1.z.object({
|
|
7
|
+
categoryUUID: zod_1.z.string(),
|
|
8
|
+
categoryName: zod_1.z.string(),
|
|
9
|
+
balance: zod_1.z.number(),
|
|
10
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InventoryStockDetailedItemSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/** Строка отчёта об остатках с детализацией по name/size/grower (`detailed=true`). */
|
|
6
|
+
exports.InventoryStockDetailedItemSchema = zod_1.z.object({
|
|
7
|
+
categoryUUID: zod_1.z.string(),
|
|
8
|
+
categoryName: zod_1.z.string(),
|
|
9
|
+
name: zod_1.z.string(),
|
|
10
|
+
color: zod_1.z.string().nullable(),
|
|
11
|
+
size: zod_1.z.string().nullable(),
|
|
12
|
+
grower: zod_1.z.string().nullable(),
|
|
13
|
+
balance: zod_1.z.number(),
|
|
14
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InventoryTurnoverCategoryItemSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/** Строка отчёта об оборачиваемости в разрезе категорий (`detailed=false`). */
|
|
6
|
+
exports.InventoryTurnoverCategoryItemSchema = zod_1.z.object({
|
|
7
|
+
categoryUUID: zod_1.z.string(),
|
|
8
|
+
categoryName: zod_1.z.string(),
|
|
9
|
+
initialBalance: zod_1.z.number(), // начальный остаток
|
|
10
|
+
receipts: zod_1.z.number(), // приходы
|
|
11
|
+
sales: zod_1.z.number(), // продажи
|
|
12
|
+
currentBalance: zod_1.z.number(), // текущий остаток
|
|
13
|
+
daysInStock: zod_1.z.number(), // дни в наличии на складе
|
|
14
|
+
turnoverRate: zod_1.z.number(), // коэффициент оборачиваемости
|
|
15
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InventoryTurnoverDetailedItemSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/** Строка отчёта об оборачиваемости с детализацией по name/size/grower (`detailed=true`). */
|
|
6
|
+
exports.InventoryTurnoverDetailedItemSchema = zod_1.z.object({
|
|
7
|
+
categoryUUID: zod_1.z.string(),
|
|
8
|
+
categoryName: zod_1.z.string(),
|
|
9
|
+
name: zod_1.z.string(),
|
|
10
|
+
color: zod_1.z.string().nullable(),
|
|
11
|
+
size: zod_1.z.string().nullable(),
|
|
12
|
+
grower: zod_1.z.string().nullable(), // производитель
|
|
13
|
+
initialBalance: zod_1.z.number(), // начальный остаток
|
|
14
|
+
receipts: zod_1.z.number(), // приходы
|
|
15
|
+
sales: zod_1.z.number(), // продажи
|
|
16
|
+
currentBalance: zod_1.z.number(), // текущий остаток
|
|
17
|
+
daysInStock: zod_1.z.number(), // дни в наличии на складе
|
|
18
|
+
turnoverRate: zod_1.z.number(), // коэффициент оборачиваемости
|
|
19
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SalesByClientRowSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const sales_by_client_top_item_schema_1 = require("./sales-by-client-top-item.schema");
|
|
6
|
+
/**
|
|
7
|
+
* Строка отчёта «продажи по клиентам» — те же данные, что уходят в Excel из `export/sales/clients`.
|
|
8
|
+
* Опциональные поля отсутствуют в ответе, когда у клиента нет соответствующего значения.
|
|
9
|
+
*/
|
|
10
|
+
exports.SalesByClientRowSchema = zod_1.z.object({
|
|
11
|
+
uuid: zod_1.z.string(),
|
|
12
|
+
clientName: zod_1.z.string(),
|
|
13
|
+
responsibleUserName: zod_1.z.string().optional(),
|
|
14
|
+
totalOrders: zod_1.z.number(),
|
|
15
|
+
soldUnits: zod_1.z.number(),
|
|
16
|
+
soldUnitsByUnit: zod_1.z.object({
|
|
17
|
+
PIECE: zod_1.z.number(),
|
|
18
|
+
PACK: zod_1.z.number(),
|
|
19
|
+
BOX: zod_1.z.number(),
|
|
20
|
+
}),
|
|
21
|
+
totalSales: zod_1.z.number(),
|
|
22
|
+
avgCheck: zod_1.z.number(),
|
|
23
|
+
totalWriteOff: zod_1.z.number(),
|
|
24
|
+
grossProfit: zod_1.z.number(),
|
|
25
|
+
marginality: zod_1.z.number(),
|
|
26
|
+
// Оплаты (INCOME) и предоплаты (PREPAYMENT) клиента за период
|
|
27
|
+
totalPayments: zod_1.z.number(),
|
|
28
|
+
totalPrepayments: zod_1.z.number(),
|
|
29
|
+
// Сумма услуг (order_service_line) за период — отдельно, вне товарных sales/margin
|
|
30
|
+
totalServiceAmount: zod_1.z.number(),
|
|
31
|
+
// Текущий баланс клиента (на момент формирования отчёта)
|
|
32
|
+
balance: zod_1.z.number(),
|
|
33
|
+
lastOrderDate: zod_1.z.coerce.date().optional(),
|
|
34
|
+
// Топ-5 по сумме выручки за период
|
|
35
|
+
topCategories: zod_1.z.array(sales_by_client_top_item_schema_1.SalesByClientTopItemSchema),
|
|
36
|
+
topProducts: zod_1.z.array(sales_by_client_top_item_schema_1.SalesByClientTopItemSchema),
|
|
37
|
+
// Статическая информация о клиенте
|
|
38
|
+
code: zod_1.z.string().optional(),
|
|
39
|
+
city: zod_1.z.string().optional(),
|
|
40
|
+
contactName: zod_1.z.string().optional(),
|
|
41
|
+
phone: zod_1.z.string().optional(),
|
|
42
|
+
clientType: zod_1.z.string().optional(),
|
|
43
|
+
status: zod_1.z.string().optional(),
|
|
44
|
+
group: zod_1.z.string().optional(),
|
|
45
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SalesByClientTopItemSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/** Элемент топа (категория или товар) внутри строки отчёта «продажи по клиентам». */
|
|
6
|
+
exports.SalesByClientTopItemSchema = zod_1.z.object({
|
|
7
|
+
name: zod_1.z.string(),
|
|
8
|
+
amount: zod_1.z.number(),
|
|
9
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ClientSchema } from '../../schemas';
|
|
3
3
|
import { ClientStatusEnum } from '../../enum/client-status.enum';
|
|
4
|
+
import { ClientContractStatusEnum } from '../../enum/client-contract-status.enum';
|
|
4
5
|
import { ClientTypeEnum } from '../../enum/client-type.enum';
|
|
5
6
|
|
|
6
7
|
const CreateClientRequestSchema = z.object({
|
|
@@ -13,6 +14,7 @@ const CreateClientRequestSchema = z.object({
|
|
|
13
14
|
isCommon: z.coerce.boolean(),
|
|
14
15
|
contractNumber: z.string().nullable().optional(),
|
|
15
16
|
contractDate: z.coerce.date().nullable().optional(),
|
|
17
|
+
contractStatus: z.nativeEnum(ClientContractStatusEnum).optional(),
|
|
16
18
|
address: z.string().nullable().optional(),
|
|
17
19
|
city: z.string().nullable().optional(),
|
|
18
20
|
code: z.string().nullable().optional(),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ClientExtendedListSchema } from '../../schemas';
|
|
3
3
|
import { ClientStatusEnum } from '../../enum/client-status.enum';
|
|
4
|
+
import { ClientContractStatusEnum } from '../../enum/client-contract-status.enum';
|
|
4
5
|
import { ClientTypeEnum } from '../../enum/client-type.enum';
|
|
5
6
|
|
|
6
7
|
const GetClientListRequestSchema = z.object({
|
|
@@ -17,6 +18,13 @@ const GetClientListRequestSchema = z.object({
|
|
|
17
18
|
.string()
|
|
18
19
|
.optional()
|
|
19
20
|
.transform(val => (val === 'true' ? true : val === 'false' || val === '' ? false : undefined)),
|
|
21
|
+
contractStatus: z.nativeEnum(ClientContractStatusEnum).optional(),
|
|
22
|
+
// Feeds the "Contracts" tab: a client counts as having a contract record when a number or a date
|
|
23
|
+
// is filled in, or the contract status has been moved off NONE.
|
|
24
|
+
hasContractRecord: z
|
|
25
|
+
.string()
|
|
26
|
+
.optional()
|
|
27
|
+
.transform(val => (val === 'true' ? true : val === 'false' ? false : undefined)),
|
|
20
28
|
});
|
|
21
29
|
|
|
22
30
|
const GetClientListResponseSchema = z.object({
|
package/commands/client/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './get-client-list.query';
|
|
|
4
4
|
export * from './get-client-debt-list.query';
|
|
5
5
|
export * from './create-client.command';
|
|
6
6
|
export * from './update-client.command';
|
|
7
|
+
export * from './update-client-contract-data.command';
|
|
7
8
|
export * from './delete-client.command';
|
|
8
9
|
export * from './get-client-calculate.query';
|
|
9
10
|
export * from './set-balance-calculate-client.command';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ClientSchema } from '../../schemas';
|
|
3
|
+
import { ClientContractStatusEnum } from '../../enum/client-contract-status.enum';
|
|
4
|
+
|
|
5
|
+
// Narrow, partial counterpart of UpdateClientContract: touches only the contract fields, so a
|
|
6
|
+
// one-click status change cannot overwrite the rest of the client with a stale snapshot.
|
|
7
|
+
const UpdateClientContractDataRequestSchema = z.object({
|
|
8
|
+
contractNumber: z.string().nullable().optional(),
|
|
9
|
+
contractDate: z.coerce.date().nullable().optional(),
|
|
10
|
+
contractStatus: z.nativeEnum(ClientContractStatusEnum).optional(),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const UpdateClientContractDataResponseSchema = z.object({
|
|
14
|
+
message: z.string().optional(),
|
|
15
|
+
data: ClientSchema.nullable(),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export namespace UpdateClientContractDataContractCommand {
|
|
19
|
+
export const RequestSchema = UpdateClientContractDataRequestSchema;
|
|
20
|
+
export type Request = z.infer<typeof RequestSchema>;
|
|
21
|
+
|
|
22
|
+
export const ResponseSchema = UpdateClientContractDataResponseSchema;
|
|
23
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
|
24
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ClientSchema } from '../../schemas';
|
|
3
3
|
import { ClientStatusEnum } from '../../enum/client-status.enum';
|
|
4
|
+
import { ClientContractStatusEnum } from '../../enum/client-contract-status.enum';
|
|
4
5
|
import { ClientTypeEnum } from '../../enum/client-type.enum';
|
|
5
6
|
|
|
6
7
|
const UpdateClientRequestSchema = z.object({
|
|
@@ -13,6 +14,7 @@ const UpdateClientRequestSchema = z.object({
|
|
|
13
14
|
type: z.nativeEnum(ClientTypeEnum),
|
|
14
15
|
contractNumber: z.string().nullable(),
|
|
15
16
|
contractDate: z.coerce.date().nullable(),
|
|
17
|
+
contractStatus: z.nativeEnum(ClientContractStatusEnum).optional(),
|
|
16
18
|
address: z.string().nullable().optional(),
|
|
17
19
|
city: z.string().nullable().optional(),
|
|
18
20
|
code: z.string().nullable().optional(),
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { MoneyAccountWithBalanceSchema } from '../../schemas';
|
|
3
|
+
import { queryBooleanSchema } from '../../helpers/query-boolean.helper';
|
|
3
4
|
|
|
4
|
-
const GetMoneyAccountByCriteriaRequestSchema = z.object({
|
|
5
|
+
const GetMoneyAccountByCriteriaRequestSchema = z.object({
|
|
6
|
+
// Опционально: посчитать остаток каждого счёта одним агрегатом вместо отдельного
|
|
7
|
+
// GET /transaction/sum/:moneyAccountUUID на каждый счёт. Описание видит и MCP-каталог.
|
|
8
|
+
withBalance: queryBooleanSchema.describe(
|
|
9
|
+
'Pass "true" to include the current balance of every money account, instead of calling transaction/sum per account.',
|
|
10
|
+
),
|
|
11
|
+
});
|
|
5
12
|
|
|
6
13
|
const GetMoneyAccountByCriteriaResponseSchema = z.object({
|
|
7
14
|
message: z.string().optional(),
|
|
8
|
-
data:
|
|
15
|
+
data: MoneyAccountWithBalanceSchema.array(),
|
|
9
16
|
});
|
|
10
17
|
|
|
11
18
|
export namespace GetMoneyAccountByCriteriaContractQuery {
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { MoneyAccountWithBalanceSchema } from '../../schemas';
|
|
3
|
+
import { queryBooleanSchema } from '../../helpers/query-boolean.helper';
|
|
3
4
|
|
|
4
5
|
const GetMoneyAccountListRequestSchema = z.object({
|
|
5
6
|
page: z.string().transform(val => Number(val) || 1),
|
|
6
7
|
count: z.string().transform(val => Number(val) || 10),
|
|
8
|
+
// Опционально: посчитать остаток каждого счёта одним агрегатом вместо отдельного
|
|
9
|
+
// GET /transaction/sum/:moneyAccountUUID на каждый счёт. Описание видит и MCP-каталог.
|
|
10
|
+
withBalance: queryBooleanSchema.describe(
|
|
11
|
+
'Pass "true" to include the current balance of every money account, instead of calling transaction/sum per account.',
|
|
12
|
+
),
|
|
7
13
|
});
|
|
8
14
|
|
|
9
15
|
const GetMoneyAccountListResponseSchema = z.object({
|
|
10
16
|
message: z.string().optional(),
|
|
11
17
|
data: z.object({
|
|
12
|
-
list: z.array(
|
|
18
|
+
list: z.array(MoneyAccountWithBalanceSchema),
|
|
13
19
|
total: z.number(),
|
|
14
20
|
}),
|
|
15
21
|
});
|
|
@@ -1,30 +1,15 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { InventoryStockCategoryItemSchema } from '../../schemas/report/inventory-stock-category-item.schema';
|
|
3
|
+
import { InventoryStockDetailedItemSchema } from '../../schemas/report/inventory-stock-detailed-item.schema';
|
|
2
4
|
|
|
3
5
|
const ExportInventoryStockRequestSchema = z.object({
|
|
4
6
|
categoryUUID: z.uuid().optional(), // Фильтр по категории
|
|
5
7
|
detailed: z.coerce.boolean().optional().default(false), // Флаг для детализации (группировка по name, size, grower)
|
|
6
8
|
});
|
|
7
9
|
|
|
8
|
-
//
|
|
9
|
-
const CategoryStockItemSchema = z.object({
|
|
10
|
-
categoryUUID: z.string(),
|
|
11
|
-
categoryName: z.string(),
|
|
12
|
-
balance: z.number(),
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
// Ответ для детализированного отчета (с группировкой по name, size, grower)
|
|
16
|
-
const DetailedStockItemSchema = z.object({
|
|
17
|
-
categoryUUID: z.string(),
|
|
18
|
-
categoryName: z.string(),
|
|
19
|
-
name: z.string(),
|
|
20
|
-
color: z.string().nullable(),
|
|
21
|
-
size: z.string().nullable(),
|
|
22
|
-
grower: z.string().nullable(),
|
|
23
|
-
balance: z.number(),
|
|
24
|
-
});
|
|
25
|
-
|
|
10
|
+
// Строки живут в schemas/report — их же отдаёт JSON-эндпоинт report/inventory/stock, форма ответа общая.
|
|
26
11
|
const ExportInventoryStockResponseSchema = z.object({
|
|
27
|
-
data: z.array(z.union([
|
|
12
|
+
data: z.array(z.union([InventoryStockCategoryItemSchema, InventoryStockDetailedItemSchema])),
|
|
28
13
|
});
|
|
29
14
|
|
|
30
15
|
export namespace ExportInventoryStockContractQuery {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { dateRangeCheck } from '../../helpers/date.helper';
|
|
3
|
+
import { InventoryTurnoverCategoryItemSchema } from '../../schemas/report/inventory-turnover-category-item.schema';
|
|
4
|
+
import { InventoryTurnoverDetailedItemSchema } from '../../schemas/report/inventory-turnover-detailed-item.schema';
|
|
3
5
|
|
|
4
6
|
const ExportInventoryTurnoverRequestSchema = z
|
|
5
7
|
.object({
|
|
@@ -22,36 +24,9 @@ const ExportInventoryTurnoverRequestSchema = z
|
|
|
22
24
|
},
|
|
23
25
|
);
|
|
24
26
|
|
|
25
|
-
//
|
|
26
|
-
const CategoryTurnoverItemSchema = z.object({
|
|
27
|
-
categoryUUID: z.string(),
|
|
28
|
-
categoryName: z.string(),
|
|
29
|
-
initialBalance: z.number(), // начальный остаток
|
|
30
|
-
receipts: z.number(), // приходы
|
|
31
|
-
sales: z.number(), // продажи
|
|
32
|
-
currentBalance: z.number(), // текущий остаток
|
|
33
|
-
daysInStock: z.number(), // дни в наличии на складе
|
|
34
|
-
turnoverRate: z.number(), // коэффициент оборачиваемости
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// Ответ для детализированного отчета (с группировкой по name, size, grower)
|
|
38
|
-
const DetailedTurnoverItemSchema = z.object({
|
|
39
|
-
categoryUUID: z.string(),
|
|
40
|
-
categoryName: z.string(),
|
|
41
|
-
name: z.string(),
|
|
42
|
-
color: z.string().nullable(),
|
|
43
|
-
size: z.string().nullable(),
|
|
44
|
-
grower: z.string().nullable(), // производитель
|
|
45
|
-
initialBalance: z.number(), // начальный остаток
|
|
46
|
-
receipts: z.number(), // приходы
|
|
47
|
-
sales: z.number(), // продажи
|
|
48
|
-
currentBalance: z.number(), // текущий остаток
|
|
49
|
-
daysInStock: z.number(), // дни в наличии на складе
|
|
50
|
-
turnoverRate: z.number(), // коэффициент оборачиваемости
|
|
51
|
-
});
|
|
52
|
-
|
|
27
|
+
// Строки живут в schemas/report — их же отдаёт JSON-эндпоинт report/inventory/turnover, форма ответа общая.
|
|
53
28
|
const ExportInventoryTurnoverResponseSchema = z.object({
|
|
54
|
-
data: z.array(z.union([
|
|
29
|
+
data: z.array(z.union([InventoryTurnoverCategoryItemSchema, InventoryTurnoverDetailedItemSchema])),
|
|
55
30
|
});
|
|
56
31
|
|
|
57
32
|
export namespace ExportInventoryTurnoverContractQuery {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { isPageAccompaniedByCount } from '../../helpers/pagination.helper';
|
|
3
|
+
import { queryBooleanSchema } from '../../helpers/query-boolean.helper';
|
|
4
|
+
import { InventoryStockCategoryItemSchema } from '../../schemas/report/inventory-stock-category-item.schema';
|
|
5
|
+
import { InventoryStockDetailedItemSchema } from '../../schemas/report/inventory-stock-detailed-item.schema';
|
|
6
|
+
|
|
7
|
+
const GetInventoryStockRequestSchema = z
|
|
8
|
+
.object({
|
|
9
|
+
categoryUUID: z.uuid().optional().describe('Keep only the products of this category.'),
|
|
10
|
+
detailed: queryBooleanSchema.describe('Pass "true" to group rows by product name / size / grower instead of by category only.'),
|
|
11
|
+
// Пагинация по строкам отчёта. Без count лимит не накладывается — отдаём весь отчёт,
|
|
12
|
+
// а page без count отклоняется: иначе листание молча возвращало бы одну и ту же выдачу.
|
|
13
|
+
page: z.coerce.number().int().positive().optional().describe('1-based page number, requires "count".'),
|
|
14
|
+
count: z.coerce.number().int().positive().optional().describe('Rows per page. Without it the whole report is returned.'),
|
|
15
|
+
})
|
|
16
|
+
.refine(isPageAccompaniedByCount, {
|
|
17
|
+
message: 'validation.pageRequiresCount',
|
|
18
|
+
path: ['page'],
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const GetInventoryStockResponseSchema = z.object({
|
|
22
|
+
message: z.string().optional(),
|
|
23
|
+
data: z.object({
|
|
24
|
+
list: z.array(z.union([InventoryStockCategoryItemSchema, InventoryStockDetailedItemSchema])),
|
|
25
|
+
// Число строк во всём отчёте — не размер страницы.
|
|
26
|
+
total: z.number(),
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export namespace GetInventoryStockContractQuery {
|
|
31
|
+
export const RequestSchema = GetInventoryStockRequestSchema;
|
|
32
|
+
export type Request = z.infer<typeof RequestSchema>;
|
|
33
|
+
|
|
34
|
+
export const ResponseSchema = GetInventoryStockResponseSchema;
|
|
35
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { dateRangeCheck } from '../../helpers/date.helper';
|
|
3
|
+
import { isPageAccompaniedByCount } from '../../helpers/pagination.helper';
|
|
4
|
+
import { queryBooleanSchema } from '../../helpers/query-boolean.helper';
|
|
5
|
+
import { InventoryTurnoverCategoryItemSchema } from '../../schemas/report/inventory-turnover-category-item.schema';
|
|
6
|
+
import { InventoryTurnoverDetailedItemSchema } from '../../schemas/report/inventory-turnover-detailed-item.schema';
|
|
7
|
+
|
|
8
|
+
const GetInventoryTurnoverRequestSchema = z
|
|
9
|
+
.object({
|
|
10
|
+
// Даты обязательны: без периода оборачиваемость не считается (в отличие от export/*, где
|
|
11
|
+
// отсутствие дат приводило к ошибке уже внутри сервиса).
|
|
12
|
+
startDate: z.coerce.date(),
|
|
13
|
+
endDate: z.coerce.date(),
|
|
14
|
+
categoryUUID: z.uuid().optional().describe('Keep only the products of this category.'),
|
|
15
|
+
detailed: queryBooleanSchema.describe('Pass "true" to group rows by product name / size / grower instead of by category only.'),
|
|
16
|
+
// Пагинация по строкам отчёта. Без count лимит не накладывается — отдаём весь отчёт,
|
|
17
|
+
// а page без count отклоняется: иначе листание молча возвращало бы одну и ту же выдачу.
|
|
18
|
+
page: z.coerce.number().int().positive().optional().describe('1-based page number, requires "count".'),
|
|
19
|
+
count: z.coerce.number().int().positive().optional().describe('Rows per page. Without it the whole report is returned.'),
|
|
20
|
+
})
|
|
21
|
+
.refine(value => dateRangeCheck(value.startDate, value.endDate), {
|
|
22
|
+
message: 'validation.dateRange',
|
|
23
|
+
path: ['endDate', 'startDate'],
|
|
24
|
+
})
|
|
25
|
+
.refine(isPageAccompaniedByCount, {
|
|
26
|
+
message: 'validation.pageRequiresCount',
|
|
27
|
+
path: ['page'],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const GetInventoryTurnoverResponseSchema = z.object({
|
|
31
|
+
message: z.string().optional(),
|
|
32
|
+
data: z.object({
|
|
33
|
+
list: z.array(z.union([InventoryTurnoverCategoryItemSchema, InventoryTurnoverDetailedItemSchema])),
|
|
34
|
+
// Число строк во всём отчёте — не размер страницы.
|
|
35
|
+
total: z.number(),
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export namespace GetInventoryTurnoverContractQuery {
|
|
40
|
+
export const RequestSchema = GetInventoryTurnoverRequestSchema;
|
|
41
|
+
export type Request = z.infer<typeof RequestSchema>;
|
|
42
|
+
|
|
43
|
+
export const ResponseSchema = GetInventoryTurnoverResponseSchema;
|
|
44
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
|
45
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { dateRangeCheck } from '../../helpers/date.helper';
|
|
3
|
+
import { isPageAccompaniedByCount } from '../../helpers/pagination.helper';
|
|
4
|
+
import { queryBooleanSchema } from '../../helpers/query-boolean.helper';
|
|
3
5
|
import { ClientByWeeksSchema } from '../../schemas';
|
|
4
6
|
|
|
5
7
|
const GetReportByClientWeeksRequestSchema = z
|
|
@@ -7,6 +9,15 @@ const GetReportByClientWeeksRequestSchema = z
|
|
|
7
9
|
startDate: z.coerce.date(),
|
|
8
10
|
endDate: z.coerce.date(),
|
|
9
11
|
responsibleUserUUID: z.string().optional(),
|
|
12
|
+
// Отчёт — это матрица «неделя × клиент», поэтому по умолчанию отдаёт строку и на нулевые недели.
|
|
13
|
+
// Флаг оставляет только недели с заказами: то, что обычно и нужно, и на порядок меньше данных.
|
|
14
|
+
onlyWithOrders: queryBooleanSchema,
|
|
15
|
+
// Фильтр по группе клиента (client."group") — дешёвый, применяется до CROSS JOIN недель.
|
|
16
|
+
clientGroup: z.string().optional(),
|
|
17
|
+
// Пагинация по строкам матрицы. Без count лимит не накладывается — поведение по умолчанию
|
|
18
|
+
// прежнее, а page без count отклоняется: иначе листание молча возвращало бы одну и ту же выдачу.
|
|
19
|
+
page: z.coerce.number().int().positive().optional(),
|
|
20
|
+
count: z.coerce.number().int().positive().optional(),
|
|
10
21
|
})
|
|
11
22
|
.refine(
|
|
12
23
|
value => {
|
|
@@ -20,11 +31,19 @@ const GetReportByClientWeeksRequestSchema = z
|
|
|
20
31
|
message: 'validation.dateRange',
|
|
21
32
|
path: ['endDate', 'startDate'],
|
|
22
33
|
},
|
|
23
|
-
)
|
|
34
|
+
)
|
|
35
|
+
.refine(isPageAccompaniedByCount, {
|
|
36
|
+
message: 'validation.pageRequiresCount',
|
|
37
|
+
path: ['page'],
|
|
38
|
+
});
|
|
24
39
|
|
|
25
40
|
const GetReportGroupByClientResponseSchema = z.object({
|
|
26
41
|
message: z.string().optional(),
|
|
27
42
|
data: z.array(ClientByWeeksSchema),
|
|
43
|
+
// `total` лежит РЯДОМ с data, а не внутри неё: панель читает `data` как плоский массив строк,
|
|
44
|
+
// и обёртка `{ list, total }` (как в остальных пагинируемых отчётах) сломала бы ей рендер.
|
|
45
|
+
// Без total последняя страница неотличима от полной выдачи.
|
|
46
|
+
total: z.number().describe('Rows in the whole report, before "page"/"count" are applied.'),
|
|
28
47
|
});
|
|
29
48
|
|
|
30
49
|
export namespace GetReportByClientWeeksContractQuery {
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { OrderByEnum, ReportSortByEnum } from '../../enum';
|
|
3
|
+
import { dateRangeCheck } from '../../helpers/date.helper';
|
|
3
4
|
|
|
4
5
|
const GetReportGroupByClientRequestSchema = z
|
|
5
6
|
.object({
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
// Даты приходят «сырым» днём — раскладку в полуинтервал [start, endExclusive) делает сервис
|
|
8
|
+
// в таймзоне компании, как в cash-flow. Прежний setStartDay/setEndDay в UTC разворачивал день
|
|
9
|
+
// второй раз, и в таймзоне с плюсовым сдвигом конец периода уезжал на сутки вперёд.
|
|
10
|
+
startDate: z.coerce.date(),
|
|
11
|
+
endDate: z.coerce.date(),
|
|
12
|
+
// Сортировка НЕ имеет значения по умолчанию: без явного sortBy/sortOrder строки отдаются
|
|
13
|
+
// в том порядке, в каком их вернул отчёт (панель рендерит map в порядке ключей, и тихая
|
|
14
|
+
// пересортировка меняла бы ей вид таблицы). Исключение — limit: он срезает хвост, что без
|
|
15
|
+
// сортировки бессмысленно, поэтому при limit применяется порядок «по прибыли, убывание».
|
|
16
|
+
sortBy: z
|
|
17
|
+
.nativeEnum(ReportSortByEnum)
|
|
18
|
+
.optional()
|
|
19
|
+
.describe('Sort metric. Without it (and without "limit") rows keep the report order.'),
|
|
20
|
+
sortOrder: z.nativeEnum(OrderByEnum).optional().describe('Sort direction. Defaults to "desc" once sorting applies.'),
|
|
21
|
+
// Без значения — ограничения нет: панель по-прежнему получает все строки.
|
|
22
|
+
limit: z.coerce.number().int().positive().optional().describe('Keep only the top N rows; implies sorting by gross profit desc.'),
|
|
8
23
|
})
|
|
9
24
|
.refine(
|
|
10
25
|
value => {
|
|
@@ -43,6 +58,10 @@ const GetReportGroupByClientResponseSchema = z.object({
|
|
|
43
58
|
marginality: z.number(),
|
|
44
59
|
}),
|
|
45
60
|
),
|
|
61
|
+
// Аддитивно к прежней форме: число клиентов во ВСЁМ отчёте до усечения и применённый limit.
|
|
62
|
+
// Без них усечённый ответ неотличим от полного.
|
|
63
|
+
total: z.number().describe('Client rows in the whole report, before "limit".'),
|
|
64
|
+
limit: z.number().optional().describe('Row limit that actually cut rows off. Absent when the response is complete.'),
|
|
46
65
|
}),
|
|
47
66
|
});
|
|
48
67
|
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { PositionReportTypeEnum } from '../../enum';
|
|
3
|
-
import { dateRangeCheck
|
|
2
|
+
import { OrderByEnum, PositionReportTypeEnum, ReportSortByEnum } from '../../enum';
|
|
3
|
+
import { dateRangeCheck } from '../../helpers/date.helper';
|
|
4
4
|
|
|
5
5
|
const GetReportGroupByPositionRequestSchema = z
|
|
6
6
|
.object({
|
|
7
7
|
type: z.nativeEnum(PositionReportTypeEnum).default(PositionReportTypeEnum.PRODUCT),
|
|
8
8
|
categoryUUID: z.string().optional(),
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
// Даты приходят «сырым» днём — раскладку в полуинтервал [start, endExclusive) делает сервис
|
|
10
|
+
// в таймзоне компании, как в cash-flow. Прежний setStartDay/setEndDay в UTC разворачивал день
|
|
11
|
+
// второй раз, и в таймзоне с плюсовым сдвигом конец периода уезжал на сутки вперёд.
|
|
12
|
+
startDate: z.coerce.date(),
|
|
13
|
+
endDate: z.coerce.date(),
|
|
14
|
+
// Сортировка НЕ имеет значения по умолчанию: без явного sortBy/sortOrder строки отдаются
|
|
15
|
+
// в том порядке, в каком их вернул отчёт (панель рендерит map в порядке ключей, и тихая
|
|
16
|
+
// пересортировка меняла бы ей вид таблицы). Исключение — limit: он срезает хвост, что без
|
|
17
|
+
// сортировки бессмысленно, поэтому при limit применяется порядок «по прибыли, убывание».
|
|
18
|
+
sortBy: z
|
|
19
|
+
.nativeEnum(ReportSortByEnum)
|
|
20
|
+
.optional()
|
|
21
|
+
.describe('Sort metric. Without it (and without "limit") rows keep the report order.'),
|
|
22
|
+
sortOrder: z.nativeEnum(OrderByEnum).optional().describe('Sort direction. Defaults to "desc" once sorting applies.'),
|
|
23
|
+
// Без значения — ограничения нет: панель по-прежнему получает все строки.
|
|
24
|
+
limit: z.coerce.number().int().positive().optional().describe('Keep only the top N rows; implies sorting by gross profit desc.'),
|
|
11
25
|
})
|
|
12
26
|
.refine(
|
|
13
27
|
value => {
|
|
@@ -67,6 +81,11 @@ const GetReportGroupByPositionResponseSchema = z.object({
|
|
|
67
81
|
}),
|
|
68
82
|
)
|
|
69
83
|
.optional(),
|
|
84
|
+
// Аддитивно к прежней форме: отчёт отдаёт ЛИБО категории, ЛИБО товары (при categoryUUID),
|
|
85
|
+
// поэтому total относится к той группировке, что вернулась. Вместе с limit это единственный
|
|
86
|
+
// способ отличить усечённый ответ от полного.
|
|
87
|
+
total: z.number().describe('Rows in the whole report (of the returned grouping), before "limit".'),
|
|
88
|
+
limit: z.number().optional().describe('Row limit that actually cut rows off. Absent when the response is complete.'),
|
|
70
89
|
}),
|
|
71
90
|
});
|
|
72
91
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { OrderByEnum, ReportSortByEnum } from '../../enum';
|
|
3
|
+
import { dateRangeCheck, isStatementPeriodWithinLimit } from '../../helpers/date.helper';
|
|
4
|
+
import { isPageAccompaniedByCount } from '../../helpers/pagination.helper';
|
|
5
|
+
import { SalesByClientRowSchema } from '../../schemas/report/sales-by-client-row.schema';
|
|
6
|
+
|
|
7
|
+
const GetSalesByClientRequestSchema = z
|
|
8
|
+
.object({
|
|
9
|
+
startDate: z.coerce.date(),
|
|
10
|
+
endDate: z.coerce.date(),
|
|
11
|
+
// По умолчанию самые прибыльные клиенты сверху, чтобы count срезал хвост, а не топ.
|
|
12
|
+
sortBy: z.nativeEnum(ReportSortByEnum).optional().default(ReportSortByEnum.GROSS_PROFIT),
|
|
13
|
+
sortOrder: z.nativeEnum(OrderByEnum).optional().default(OrderByEnum.DESC),
|
|
14
|
+
// Пагинация по строкам отчёта. Без count лимит не накладывается — отдаём всех клиентов,
|
|
15
|
+
// а page без count отклоняется: иначе листание молча возвращало бы одну и ту же выдачу.
|
|
16
|
+
page: z.coerce.number().int().positive().optional().describe('1-based page number, requires "count".'),
|
|
17
|
+
count: z.coerce.number().int().positive().optional().describe('Rows per page. Without it every client row is returned.'),
|
|
18
|
+
})
|
|
19
|
+
.refine(value => dateRangeCheck(value.startDate, value.endDate), {
|
|
20
|
+
message: 'validation.dateRange',
|
|
21
|
+
path: ['endDate', 'startDate'],
|
|
22
|
+
})
|
|
23
|
+
.refine(value => isStatementPeriodWithinLimit(value.startDate, value.endDate), {
|
|
24
|
+
message: 'validation.reportPeriodMax',
|
|
25
|
+
path: ['endDate', 'startDate'],
|
|
26
|
+
})
|
|
27
|
+
.refine(isPageAccompaniedByCount, {
|
|
28
|
+
message: 'validation.pageRequiresCount',
|
|
29
|
+
path: ['page'],
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const GetSalesByClientResponseSchema = z.object({
|
|
33
|
+
message: z.string().optional(),
|
|
34
|
+
data: z.object({
|
|
35
|
+
list: z.array(SalesByClientRowSchema),
|
|
36
|
+
// Число клиентов во всём отчёте — не размер страницы.
|
|
37
|
+
total: z.number(),
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export namespace GetSalesByClientContractQuery {
|
|
42
|
+
export const RequestSchema = GetSalesByClientRequestSchema;
|
|
43
|
+
export type Request = z.infer<typeof RequestSchema>;
|
|
44
|
+
|
|
45
|
+
export const ResponseSchema = GetSalesByClientResponseSchema;
|
|
46
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
|
47
|
+
}
|
package/commands/report/index.ts
CHANGED
|
@@ -12,3 +12,6 @@ export * from './export-client-statement.query';
|
|
|
12
12
|
export * from './get-report-by-client-weeks.query';
|
|
13
13
|
export * from './get-daily-orders-summary.query';
|
|
14
14
|
export * from './get-cash-flow.query';
|
|
15
|
+
export * from './get-inventory-stock.query';
|
|
16
|
+
export * from './get-inventory-turnover.query';
|
|
17
|
+
export * from './get-sales-by-client.query';
|