feat: add salePrice field to Product model and update related files

- Added salePrice field to Product model in Prisma schema and generated files.
- Updated Product scalar field enums in both TypeScript files.
- Modified aggregate output types to include salePrice.
- Enhanced input types for creating and updating products to support salePrice.
- Updated migration file to add salePrice column to Products table.
- Created DTOs for inventory management in POS module.
- Implemented POS controller and service with methods for stock and product categories.
This commit is contained in:
2025-12-14 20:34:07 +03:30
parent 9d7d94b5f8
commit 687c89c3e1
13 changed files with 360 additions and 25 deletions
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `Products` ADD COLUMN `salePrice` DECIMAL(10, 2) NOT NULL DEFAULT 0.00;
+1
View File
@@ -70,6 +70,7 @@ model Product {
createdAt DateTime @default(now()) @db.Timestamp(0)
updatedAt DateTime @updatedAt @db.Timestamp(0)
deletedAt DateTime? @db.Timestamp(0)
salePrice Decimal @default(0.00) @db.Decimal(10, 2)
brandId Int?
categoryId Int?
inventoryTransferItems InventoryTransferItem[] @relation("InventoryTransferItem_Product")
+42 -21
View File
@@ -33,40 +33,61 @@ async function main() {
if ((await prisma.productCategory.count()) === 0) {
await prisma.productCategory.createMany({
data: [{ name: 'دسته‌ی ۱' }, { name: 'دسته‌ی ۲' }, { name: 'دسته‌ی ۳' }],
data: Array.from({ length: 10 }, (_, i) => ({ name: `دسته‌ی ${i + 1}` })),
})
}
if ((await prisma.productBrand.count()) === 0) {
await prisma.productBrand.createMany({
data: [{ name: 'برند ۱' }, { name: 'برند ۲' }, { name: 'برند ۳' }],
data: Array.from({ length: 10 }, (_, i) => ({ name: `برند ${i + 1}` })),
})
}
if ((await prisma.supplier.count()) === 0) {
await prisma.supplier.createMany({
data: [
{
data: Array.from({ length: 20 }, (_, i) => ({
firstName: 'تامین‌',
lastName: 'کننده ۱',
mobileNumber: '09120000001',
email: 'supplier1@example.com',
},
{
firstName: 'تامین‌',
lastName: 'کننده ۲',
mobileNumber: '09120000002',
email: 'supplier2@example.com',
},
{
firstName: 'تامین‌',
lastName: 'کننده 3',
mobileNumber: '09120000003',
email: 'supplier3@example.com',
},
],
lastName: `کننده ${i + 1}`,
mobileNumber: `0912000000${i + 1}`,
email: `supplier${i + 1}@example.com`,
})),
})
}
if ((await prisma.customer.count()) === 0) {
await prisma.customer.createMany({
data: Array.from({ length: 5 }, (_, i) => ({
firstName: 'مشتری',
lastName: `${i + 1}`,
mobileNumber: `0913000000${i + 1}`,
email: `customer${i + 1}@example.com`,
})),
})
}
if ((await prisma.product.count()) === 0) {
const categories = await prisma.productCategory.findMany()
const brands = await prisma.productBrand.findMany()
await prisma.product.createMany({
data: Array.from({ length: 100 }, (_, i) => ({
name: `کالای ${i + 1}`,
sku: `SKU-${1000 + i + 1}`,
salePrice: parseInt((Math.random() * (100 - 10) + 10).toString()) * 10000,
categoryId: categories[i % categories.length].id,
brandId: brands[i % brands.length].id,
})),
})
}
// const products = await prisma.product.findMany()
// for (const product of products) {
// await prisma.product.update({
// where: { id: product.id },
// data: {
// salePrice: parseInt((Math.random() * (100 - 10) + 10).toString()) * 10000,
// },
// })
// }
}
main()
+2
View File
@@ -5,6 +5,7 @@ import { CustomersModule } from './customers/customers.module'
import { InventoriesModule } from './inventories/inventories.module'
import { InventoryTransferItemsModule } from './inventory-transfer-items/inventory-transfer-items.module'
import { InventoryTransfersModule } from './inventory-transfers/inventory-transfers.module'
import { PosModule } from './pos/pos.module'
import { PrismaModule } from './prisma/prisma.module'
import { ProductBrandsModule } from './product-brands/product-brands.module'
import { ProductCategoriesModule } from './product-categories/product-categories.module'
@@ -46,6 +47,7 @@ import { UsersModule } from './users/users.module'
StockMovementsModule,
StockAdjustmentsModule,
StockBalanceModule,
PosModule,
],
controllers: [AppController],
providers: [AppService],
File diff suppressed because one or more lines are too long
@@ -2068,6 +2068,7 @@ export const ProductScalarFieldEnum = {
createdAt: 'createdAt',
updatedAt: 'updatedAt',
deletedAt: 'deletedAt',
salePrice: 'salePrice',
brandId: 'brandId',
categoryId: 'categoryId'
} as const
@@ -153,6 +153,7 @@ export const ProductScalarFieldEnum = {
createdAt: 'createdAt',
updatedAt: 'updatedAt',
deletedAt: 'deletedAt',
salePrice: 'salePrice',
brandId: 'brandId',
categoryId: 'categoryId'
} as const
+78 -1
View File
@@ -28,12 +28,14 @@ export type AggregateProduct = {
export type ProductAvgAggregateOutputType = {
id: number | null
salePrice: runtime.Decimal | null
brandId: number | null
categoryId: number | null
}
export type ProductSumAggregateOutputType = {
id: number | null
salePrice: runtime.Decimal | null
brandId: number | null
categoryId: number | null
}
@@ -47,6 +49,7 @@ export type ProductMinAggregateOutputType = {
createdAt: Date | null
updatedAt: Date | null
deletedAt: Date | null
salePrice: runtime.Decimal | null
brandId: number | null
categoryId: number | null
}
@@ -60,6 +63,7 @@ export type ProductMaxAggregateOutputType = {
createdAt: Date | null
updatedAt: Date | null
deletedAt: Date | null
salePrice: runtime.Decimal | null
brandId: number | null
categoryId: number | null
}
@@ -73,6 +77,7 @@ export type ProductCountAggregateOutputType = {
createdAt: number
updatedAt: number
deletedAt: number
salePrice: number
brandId: number
categoryId: number
_all: number
@@ -81,12 +86,14 @@ export type ProductCountAggregateOutputType = {
export type ProductAvgAggregateInputType = {
id?: true
salePrice?: true
brandId?: true
categoryId?: true
}
export type ProductSumAggregateInputType = {
id?: true
salePrice?: true
brandId?: true
categoryId?: true
}
@@ -100,6 +107,7 @@ export type ProductMinAggregateInputType = {
createdAt?: true
updatedAt?: true
deletedAt?: true
salePrice?: true
brandId?: true
categoryId?: true
}
@@ -113,6 +121,7 @@ export type ProductMaxAggregateInputType = {
createdAt?: true
updatedAt?: true
deletedAt?: true
salePrice?: true
brandId?: true
categoryId?: true
}
@@ -126,6 +135,7 @@ export type ProductCountAggregateInputType = {
createdAt?: true
updatedAt?: true
deletedAt?: true
salePrice?: true
brandId?: true
categoryId?: true
_all?: true
@@ -226,6 +236,7 @@ export type ProductGroupByOutputType = {
createdAt: Date
updatedAt: Date
deletedAt: Date | null
salePrice: runtime.Decimal
brandId: number | null
categoryId: number | null
_count: ProductCountAggregateOutputType | null
@@ -262,6 +273,7 @@ export type ProductWhereInput = {
createdAt?: Prisma.DateTimeFilter<"Product"> | Date | string
updatedAt?: Prisma.DateTimeFilter<"Product"> | Date | string
deletedAt?: Prisma.DateTimeNullableFilter<"Product"> | Date | string | null
salePrice?: Prisma.DecimalFilter<"Product"> | runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: Prisma.IntNullableFilter<"Product"> | number | null
categoryId?: Prisma.IntNullableFilter<"Product"> | number | null
inventoryTransferItems?: Prisma.InventoryTransferItemListRelationFilter
@@ -285,6 +297,7 @@ export type ProductOrderByWithRelationInput = {
createdAt?: Prisma.SortOrder
updatedAt?: Prisma.SortOrder
deletedAt?: Prisma.SortOrderInput | Prisma.SortOrder
salePrice?: Prisma.SortOrder
brandId?: Prisma.SortOrderInput | Prisma.SortOrder
categoryId?: Prisma.SortOrderInput | Prisma.SortOrder
inventoryTransferItems?: Prisma.InventoryTransferItemOrderByRelationAggregateInput
@@ -312,6 +325,7 @@ export type ProductWhereUniqueInput = Prisma.AtLeast<{
createdAt?: Prisma.DateTimeFilter<"Product"> | Date | string
updatedAt?: Prisma.DateTimeFilter<"Product"> | Date | string
deletedAt?: Prisma.DateTimeNullableFilter<"Product"> | Date | string | null
salePrice?: Prisma.DecimalFilter<"Product"> | runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: Prisma.IntNullableFilter<"Product"> | number | null
categoryId?: Prisma.IntNullableFilter<"Product"> | number | null
inventoryTransferItems?: Prisma.InventoryTransferItemListRelationFilter
@@ -335,6 +349,7 @@ export type ProductOrderByWithAggregationInput = {
createdAt?: Prisma.SortOrder
updatedAt?: Prisma.SortOrder
deletedAt?: Prisma.SortOrderInput | Prisma.SortOrder
salePrice?: Prisma.SortOrder
brandId?: Prisma.SortOrderInput | Prisma.SortOrder
categoryId?: Prisma.SortOrderInput | Prisma.SortOrder
_count?: Prisma.ProductCountOrderByAggregateInput
@@ -356,6 +371,7 @@ export type ProductScalarWhereWithAggregatesInput = {
createdAt?: Prisma.DateTimeWithAggregatesFilter<"Product"> | Date | string
updatedAt?: Prisma.DateTimeWithAggregatesFilter<"Product"> | Date | string
deletedAt?: Prisma.DateTimeNullableWithAggregatesFilter<"Product"> | Date | string | null
salePrice?: Prisma.DecimalWithAggregatesFilter<"Product"> | runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: Prisma.IntNullableWithAggregatesFilter<"Product"> | number | null
categoryId?: Prisma.IntNullableWithAggregatesFilter<"Product"> | number | null
}
@@ -368,6 +384,7 @@ export type ProductCreateInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemCreateNestedManyWithoutProductInput
productCharges?: Prisma.ProductChargeCreateNestedManyWithoutProductInput
variants?: Prisma.ProductVariantCreateNestedManyWithoutProductInput
@@ -389,6 +406,7 @@ export type ProductUncheckedCreateInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: number | null
categoryId?: number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedCreateNestedManyWithoutProductInput
@@ -409,6 +427,7 @@ export type ProductUpdateInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemUpdateManyWithoutProductNestedInput
productCharges?: Prisma.ProductChargeUpdateManyWithoutProductNestedInput
variants?: Prisma.ProductVariantUpdateManyWithoutProductNestedInput
@@ -430,6 +449,7 @@ export type ProductUncheckedUpdateInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
categoryId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedUpdateManyWithoutProductNestedInput
@@ -451,6 +471,7 @@ export type ProductCreateManyInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: number | null
categoryId?: number | null
}
@@ -463,6 +484,7 @@ export type ProductUpdateManyMutationInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
}
export type ProductUncheckedUpdateManyInput = {
@@ -474,6 +496,7 @@ export type ProductUncheckedUpdateManyInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
categoryId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
}
@@ -498,12 +521,14 @@ export type ProductCountOrderByAggregateInput = {
createdAt?: Prisma.SortOrder
updatedAt?: Prisma.SortOrder
deletedAt?: Prisma.SortOrder
salePrice?: Prisma.SortOrder
brandId?: Prisma.SortOrder
categoryId?: Prisma.SortOrder
}
export type ProductAvgOrderByAggregateInput = {
id?: Prisma.SortOrder
salePrice?: Prisma.SortOrder
brandId?: Prisma.SortOrder
categoryId?: Prisma.SortOrder
}
@@ -517,6 +542,7 @@ export type ProductMaxOrderByAggregateInput = {
createdAt?: Prisma.SortOrder
updatedAt?: Prisma.SortOrder
deletedAt?: Prisma.SortOrder
salePrice?: Prisma.SortOrder
brandId?: Prisma.SortOrder
categoryId?: Prisma.SortOrder
}
@@ -530,12 +556,14 @@ export type ProductMinOrderByAggregateInput = {
createdAt?: Prisma.SortOrder
updatedAt?: Prisma.SortOrder
deletedAt?: Prisma.SortOrder
salePrice?: Prisma.SortOrder
brandId?: Prisma.SortOrder
categoryId?: Prisma.SortOrder
}
export type ProductSumOrderByAggregateInput = {
id?: Prisma.SortOrder
salePrice?: Prisma.SortOrder
brandId?: Prisma.SortOrder
categoryId?: Prisma.SortOrder
}
@@ -762,6 +790,7 @@ export type ProductCreateWithoutVariantsInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemCreateNestedManyWithoutProductInput
productCharges?: Prisma.ProductChargeCreateNestedManyWithoutProductInput
brand?: Prisma.ProductBrandCreateNestedOneWithoutProductsInput
@@ -782,6 +811,7 @@ export type ProductUncheckedCreateWithoutVariantsInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: number | null
categoryId?: number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedCreateNestedManyWithoutProductInput
@@ -817,6 +847,7 @@ export type ProductUpdateWithoutVariantsInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemUpdateManyWithoutProductNestedInput
productCharges?: Prisma.ProductChargeUpdateManyWithoutProductNestedInput
brand?: Prisma.ProductBrandUpdateOneWithoutProductsNestedInput
@@ -837,6 +868,7 @@ export type ProductUncheckedUpdateWithoutVariantsInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
categoryId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedUpdateManyWithoutProductNestedInput
@@ -856,6 +888,7 @@ export type ProductCreateWithoutBrandInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemCreateNestedManyWithoutProductInput
productCharges?: Prisma.ProductChargeCreateNestedManyWithoutProductInput
variants?: Prisma.ProductVariantCreateNestedManyWithoutProductInput
@@ -876,6 +909,7 @@ export type ProductUncheckedCreateWithoutBrandInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
categoryId?: number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedCreateNestedManyWithoutProductInput
productCharges?: Prisma.ProductChargeUncheckedCreateNestedManyWithoutProductInput
@@ -925,6 +959,7 @@ export type ProductScalarWhereInput = {
createdAt?: Prisma.DateTimeFilter<"Product"> | Date | string
updatedAt?: Prisma.DateTimeFilter<"Product"> | Date | string
deletedAt?: Prisma.DateTimeNullableFilter<"Product"> | Date | string | null
salePrice?: Prisma.DecimalFilter<"Product"> | runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: Prisma.IntNullableFilter<"Product"> | number | null
categoryId?: Prisma.IntNullableFilter<"Product"> | number | null
}
@@ -937,6 +972,7 @@ export type ProductCreateWithoutCategoryInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemCreateNestedManyWithoutProductInput
productCharges?: Prisma.ProductChargeCreateNestedManyWithoutProductInput
variants?: Prisma.ProductVariantCreateNestedManyWithoutProductInput
@@ -957,6 +993,7 @@ export type ProductUncheckedCreateWithoutCategoryInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedCreateNestedManyWithoutProductInput
productCharges?: Prisma.ProductChargeUncheckedCreateNestedManyWithoutProductInput
@@ -1002,6 +1039,7 @@ export type ProductCreateWithoutProductChargesInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemCreateNestedManyWithoutProductInput
variants?: Prisma.ProductVariantCreateNestedManyWithoutProductInput
brand?: Prisma.ProductBrandCreateNestedOneWithoutProductsInput
@@ -1022,6 +1060,7 @@ export type ProductUncheckedCreateWithoutProductChargesInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: number | null
categoryId?: number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedCreateNestedManyWithoutProductInput
@@ -1057,6 +1096,7 @@ export type ProductUpdateWithoutProductChargesInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemUpdateManyWithoutProductNestedInput
variants?: Prisma.ProductVariantUpdateManyWithoutProductNestedInput
brand?: Prisma.ProductBrandUpdateOneWithoutProductsNestedInput
@@ -1077,6 +1117,7 @@ export type ProductUncheckedUpdateWithoutProductChargesInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
categoryId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedUpdateManyWithoutProductNestedInput
@@ -1096,6 +1137,7 @@ export type ProductCreateWithoutPurchaseReceiptItemsInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemCreateNestedManyWithoutProductInput
productCharges?: Prisma.ProductChargeCreateNestedManyWithoutProductInput
variants?: Prisma.ProductVariantCreateNestedManyWithoutProductInput
@@ -1116,6 +1158,7 @@ export type ProductUncheckedCreateWithoutPurchaseReceiptItemsInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: number | null
categoryId?: number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedCreateNestedManyWithoutProductInput
@@ -1151,6 +1194,7 @@ export type ProductUpdateWithoutPurchaseReceiptItemsInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemUpdateManyWithoutProductNestedInput
productCharges?: Prisma.ProductChargeUpdateManyWithoutProductNestedInput
variants?: Prisma.ProductVariantUpdateManyWithoutProductNestedInput
@@ -1171,6 +1215,7 @@ export type ProductUncheckedUpdateWithoutPurchaseReceiptItemsInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
categoryId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedUpdateManyWithoutProductNestedInput
@@ -1190,6 +1235,7 @@ export type ProductCreateWithoutSalesInvoiceItemsInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemCreateNestedManyWithoutProductInput
productCharges?: Prisma.ProductChargeCreateNestedManyWithoutProductInput
variants?: Prisma.ProductVariantCreateNestedManyWithoutProductInput
@@ -1210,6 +1256,7 @@ export type ProductUncheckedCreateWithoutSalesInvoiceItemsInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: number | null
categoryId?: number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedCreateNestedManyWithoutProductInput
@@ -1245,6 +1292,7 @@ export type ProductUpdateWithoutSalesInvoiceItemsInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemUpdateManyWithoutProductNestedInput
productCharges?: Prisma.ProductChargeUpdateManyWithoutProductNestedInput
variants?: Prisma.ProductVariantUpdateManyWithoutProductNestedInput
@@ -1265,6 +1313,7 @@ export type ProductUncheckedUpdateWithoutSalesInvoiceItemsInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
categoryId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedUpdateManyWithoutProductNestedInput
@@ -1284,6 +1333,7 @@ export type ProductCreateWithoutStockMovementsInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemCreateNestedManyWithoutProductInput
productCharges?: Prisma.ProductChargeCreateNestedManyWithoutProductInput
variants?: Prisma.ProductVariantCreateNestedManyWithoutProductInput
@@ -1304,6 +1354,7 @@ export type ProductUncheckedCreateWithoutStockMovementsInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: number | null
categoryId?: number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedCreateNestedManyWithoutProductInput
@@ -1339,6 +1390,7 @@ export type ProductUpdateWithoutStockMovementsInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemUpdateManyWithoutProductNestedInput
productCharges?: Prisma.ProductChargeUpdateManyWithoutProductNestedInput
variants?: Prisma.ProductVariantUpdateManyWithoutProductNestedInput
@@ -1359,6 +1411,7 @@ export type ProductUncheckedUpdateWithoutStockMovementsInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
categoryId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedUpdateManyWithoutProductNestedInput
@@ -1378,6 +1431,7 @@ export type ProductCreateWithoutStockBalancesInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemCreateNestedManyWithoutProductInput
productCharges?: Prisma.ProductChargeCreateNestedManyWithoutProductInput
variants?: Prisma.ProductVariantCreateNestedManyWithoutProductInput
@@ -1398,6 +1452,7 @@ export type ProductUncheckedCreateWithoutStockBalancesInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: number | null
categoryId?: number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedCreateNestedManyWithoutProductInput
@@ -1433,6 +1488,7 @@ export type ProductUpdateWithoutStockBalancesInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemUpdateManyWithoutProductNestedInput
productCharges?: Prisma.ProductChargeUpdateManyWithoutProductNestedInput
variants?: Prisma.ProductVariantUpdateManyWithoutProductNestedInput
@@ -1453,6 +1509,7 @@ export type ProductUncheckedUpdateWithoutStockBalancesInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
categoryId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedUpdateManyWithoutProductNestedInput
@@ -1472,6 +1529,7 @@ export type ProductCreateWithoutInventoryTransferItemsInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
productCharges?: Prisma.ProductChargeCreateNestedManyWithoutProductInput
variants?: Prisma.ProductVariantCreateNestedManyWithoutProductInput
brand?: Prisma.ProductBrandCreateNestedOneWithoutProductsInput
@@ -1492,6 +1550,7 @@ export type ProductUncheckedCreateWithoutInventoryTransferItemsInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: number | null
categoryId?: number | null
productCharges?: Prisma.ProductChargeUncheckedCreateNestedManyWithoutProductInput
@@ -1527,6 +1586,7 @@ export type ProductUpdateWithoutInventoryTransferItemsInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
productCharges?: Prisma.ProductChargeUpdateManyWithoutProductNestedInput
variants?: Prisma.ProductVariantUpdateManyWithoutProductNestedInput
brand?: Prisma.ProductBrandUpdateOneWithoutProductsNestedInput
@@ -1547,6 +1607,7 @@ export type ProductUncheckedUpdateWithoutInventoryTransferItemsInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
categoryId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
productCharges?: Prisma.ProductChargeUncheckedUpdateManyWithoutProductNestedInput
@@ -1566,6 +1627,7 @@ export type ProductCreateWithoutStockAdjustmentsInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemCreateNestedManyWithoutProductInput
productCharges?: Prisma.ProductChargeCreateNestedManyWithoutProductInput
variants?: Prisma.ProductVariantCreateNestedManyWithoutProductInput
@@ -1586,6 +1648,7 @@ export type ProductUncheckedCreateWithoutStockAdjustmentsInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: number | null
categoryId?: number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedCreateNestedManyWithoutProductInput
@@ -1621,6 +1684,7 @@ export type ProductUpdateWithoutStockAdjustmentsInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemUpdateManyWithoutProductNestedInput
productCharges?: Prisma.ProductChargeUpdateManyWithoutProductNestedInput
variants?: Prisma.ProductVariantUpdateManyWithoutProductNestedInput
@@ -1641,6 +1705,7 @@ export type ProductUncheckedUpdateWithoutStockAdjustmentsInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
categoryId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedUpdateManyWithoutProductNestedInput
@@ -1661,6 +1726,7 @@ export type ProductCreateManyBrandInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
categoryId?: number | null
}
@@ -1672,6 +1738,7 @@ export type ProductUpdateWithoutBrandInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemUpdateManyWithoutProductNestedInput
productCharges?: Prisma.ProductChargeUpdateManyWithoutProductNestedInput
variants?: Prisma.ProductVariantUpdateManyWithoutProductNestedInput
@@ -1692,6 +1759,7 @@ export type ProductUncheckedUpdateWithoutBrandInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
categoryId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedUpdateManyWithoutProductNestedInput
productCharges?: Prisma.ProductChargeUncheckedUpdateManyWithoutProductNestedInput
@@ -1712,6 +1780,7 @@ export type ProductUncheckedUpdateManyWithoutBrandInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
categoryId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
}
@@ -1724,6 +1793,7 @@ export type ProductCreateManyCategoryInput = {
createdAt?: Date | string
updatedAt?: Date | string
deletedAt?: Date | string | null
salePrice?: runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: number | null
}
@@ -1735,6 +1805,7 @@ export type ProductUpdateWithoutCategoryInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
inventoryTransferItems?: Prisma.InventoryTransferItemUpdateManyWithoutProductNestedInput
productCharges?: Prisma.ProductChargeUpdateManyWithoutProductNestedInput
variants?: Prisma.ProductVariantUpdateManyWithoutProductNestedInput
@@ -1755,6 +1826,7 @@ export type ProductUncheckedUpdateWithoutCategoryInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
inventoryTransferItems?: Prisma.InventoryTransferItemUncheckedUpdateManyWithoutProductNestedInput
productCharges?: Prisma.ProductChargeUncheckedUpdateManyWithoutProductNestedInput
@@ -1775,6 +1847,7 @@ export type ProductUncheckedUpdateManyWithoutCategoryInput = {
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
deletedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
salePrice?: Prisma.DecimalFieldUpdateOperationsInput | runtime.Decimal | runtime.DecimalJsLike | number | string
brandId?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
}
@@ -1881,6 +1954,7 @@ export type ProductSelect<ExtArgs extends runtime.Types.Extensions.InternalArgs
createdAt?: boolean
updatedAt?: boolean
deletedAt?: boolean
salePrice?: boolean
brandId?: boolean
categoryId?: boolean
inventoryTransferItems?: boolean | Prisma.Product$inventoryTransferItemsArgs<ExtArgs>
@@ -1907,11 +1981,12 @@ export type ProductSelectScalar = {
createdAt?: boolean
updatedAt?: boolean
deletedAt?: boolean
salePrice?: boolean
brandId?: boolean
categoryId?: boolean
}
export type ProductOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "name" | "description" | "sku" | "barcode" | "createdAt" | "updatedAt" | "deletedAt" | "brandId" | "categoryId", ExtArgs["result"]["product"]>
export type ProductOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "name" | "description" | "sku" | "barcode" | "createdAt" | "updatedAt" | "deletedAt" | "salePrice" | "brandId" | "categoryId", ExtArgs["result"]["product"]>
export type ProductInclude<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = {
inventoryTransferItems?: boolean | Prisma.Product$inventoryTransferItemsArgs<ExtArgs>
productCharges?: boolean | Prisma.Product$productChargesArgs<ExtArgs>
@@ -1949,6 +2024,7 @@ export type $ProductPayload<ExtArgs extends runtime.Types.Extensions.InternalArg
createdAt: Date
updatedAt: Date
deletedAt: Date | null
salePrice: runtime.Decimal
brandId: number | null
categoryId: number | null
}, ExtArgs["result"]["product"]>
@@ -2338,6 +2414,7 @@ export interface ProductFieldRefs {
readonly createdAt: Prisma.FieldRef<"Product", 'DateTime'>
readonly updatedAt: Prisma.FieldRef<"Product", 'DateTime'>
readonly deletedAt: Prisma.FieldRef<"Product", 'DateTime'>
readonly salePrice: Prisma.FieldRef<"Product", 'Decimal'>
readonly brandId: Prisma.FieldRef<"Product", 'Int'>
readonly categoryId: Prisma.FieldRef<"Product", 'Int'>
}
+15
View File
@@ -0,0 +1,15 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
import { IsOptional, IsString } from 'class-validator'
export class CreateInventoryDto {
@ApiProperty()
@IsString()
name: string
@ApiPropertyOptional()
@IsOptional()
@IsString()
location?: string
}
// export class CreateSaleInvoice extends Prisma.
+21
View File
@@ -0,0 +1,21 @@
import { ApiPropertyOptional } from '@nestjs/swagger'
import { Type } from 'class-transformer'
import { IsBoolean, IsOptional, IsString } from 'class-validator'
export class UpdateInventoryDto {
@ApiPropertyOptional()
@IsOptional()
@IsString()
name?: string
@ApiPropertyOptional()
@IsOptional()
@IsString()
location?: string
@ApiPropertyOptional()
@IsOptional()
@Type(() => Boolean)
@IsBoolean()
isActive?: boolean
}
+67
View File
@@ -0,0 +1,67 @@
import { Controller, Get } from '@nestjs/common'
import { PosService } from './pos.service'
@Controller('pos')
export class PosController {
constructor(private readonly posService: PosService) {}
@Get()
getInfo() {
return this.posService.getInfo()
}
@Get('/stock')
async getStock() {
const inventoryId = await this.posService.getDefaultInventoryId()
return this.posService.getStock(inventoryId!)
}
@Get('/product-categories')
async getProductCategories() {
const inventoryId = await this.posService.getDefaultInventoryId()
return this.posService.getProductCategories(inventoryId!)
}
// @Post()
// create(@Body() dto: CreateInventoryDto) {
// return this.inventoriesService.create(dto)
// }
// @Get()
// @ApiQuery({ name: 'isPointOfSale', required: false, type: Boolean })
// findAll(@Query('isPointOfSale') isPointOfSale?: boolean) {
// return this.inventoriesService.findAll(isPointOfSale)
// }
// @Get(':id')
// findOne(@Param('id') id: string) {
// return this.inventoriesService.findOne(Number(id))
// }
// @Patch(':id')
// update(@Param('id') id: string, @Body() dto: UpdateInventoryDto) {
// return this.inventoriesService.update(Number(id), dto)
// }
// @Delete(':id')
// remove(@Param('id') id: string) {
// return this.inventoriesService.remove(Number(id))
// }
// @Get(':id/movements')
// @ApiQuery({ name: 'type', required: false, enum: MovementType })
// findInventoryMovements(@Param('id') id: string, @Query('type') type?: MovementType) {
// return this.inventoriesService.findInventoryMovements(Number(id), type ?? undefined)
// }
// @Get(':id/stock')
// @ApiQuery({ name: 'isAvailable', required: false, type: Boolean })
// getStock(@Param('id') id: string, @Query('isAvailable') isAvailable?: boolean) {
// return this.inventoriesService.getStock(Number(id), isAvailable ?? undefined)
// }
// @Get(':id/products/:productId/cardex')
// getProductCardex(@Param('id') id: string, @Param('productId') productId: string) {
// return this.inventoriesService.getProductCardex(Number(id), Number(productId))
// }
}
+11
View File
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common'
import { PrismaModule } from '../prisma/prisma.module'
import { PosController } from './pos.controller'
import { PosService } from './pos.service'
@Module({
imports: [PrismaModule],
controllers: [PosController],
providers: [PosService],
})
export class PosModule {}
+116
View File
@@ -0,0 +1,116 @@
import { Injectable } from '@nestjs/common'
import { ResponseMapper } from '../common/response/response-mapper'
import { Prisma } from '../generated/prisma/client'
import { PrismaService } from '../prisma/prisma.service'
@Injectable()
export class PosService {
constructor(private prisma: PrismaService) {}
async getDefaultInventoryId() {
const inventory = await this.prisma.inventory.findFirst({
where: { isPointOfSale: true },
select: { id: true },
})
return inventory?.id || null
}
async getInfo() {
const info = await this.prisma.inventory.findFirst({
where: { isPointOfSale: true },
select: {
id: true,
name: true,
},
})
return ResponseMapper.single({ store: info })
}
async getStock(inventoryId: number, isAvailable?: boolean, page = 1, pageSize = 50) {
const query: Prisma.StockBalanceFindManyArgs = {
where: {
inventoryId,
quantity:
isAvailable === true
? { gt: 0 }
: isAvailable === false
? { lte: 0 }
: undefined,
},
}
const [items, count] = await this.prisma.$transaction([
this.prisma.stockBalance.findMany({
where: query.where,
include: {
product: {
select: {
id: true,
name: true,
sku: true,
salePrice: true,
category: {
select: { id: true, name: true },
},
},
},
},
orderBy: {
quantity: 'desc',
},
skip: (page - 1) * pageSize,
take: pageSize,
}),
this.prisma.stockBalance.count({ where: query.where }),
])
const mapped = items.map(item => ({
id: item.id,
quantity: Number(item.quantity),
product: item.product,
}))
return ResponseMapper.paginate(mapped, count, page, pageSize)
}
async getProductCategories(inventoryId: number) {
const balances = await this.prisma.stockBalance.findMany({
where: { inventoryId },
select: {
product: { select: { id: true, category: { select: { id: true, name: true } } } },
quantity: true,
},
})
const map = new Map<
number,
{ id: number; name: string; totalQuantity: number; productCount: number }
>()
for (const b of balances) {
const product = b.product
const cat = product?.category
if (!cat) continue // skip products without category
const existing = map.get(cat.id)
if (existing) {
existing.totalQuantity += Number(b.quantity)
existing.productCount += 1
} else {
map.set(cat.id, {
id: cat.id,
name: cat.name,
totalQuantity: Number(b.quantity),
productCount: 1,
})
}
}
const categories = Array.from(map.values())
return ResponseMapper.list(categories)
}
async createSaleInvoice(data: any) {
const item = await this.prisma.salesInvoice.create({ data })
return ResponseMapper.create(item)
}
}