feat: add stock keeping units management

- Created migration to drop `type` column from `stock_keeping_units` table.
- Added `Guild` model to Prisma schema.
- Implemented `BusinessActivitiesQueryService` for querying business activities.
- Developed `GoodsSharedService` for handling goods creation and updates.
- Introduced DTOs for creating and updating stock keeping units.
- Created controller and service for managing stock keeping units.
- Implemented response DTOs for stock keeping units service.
- Established module for stock keeping units management.
This commit is contained in:
2026-05-07 20:30:24 +03:30
parent 658496320b
commit fbe7230865
77 changed files with 2065 additions and 1846 deletions
+176 -176
View File
@@ -1,6 +1,5 @@
import { PasswordUtil } from '@/common/utils/password.util'
import { generateTrackingCode } from '@/common/utils/tracking-code-generator.util'
import { ConsumerType, GoodPricingModel, TspProviderType } from '@/generated/prisma/enums'
import { GoodPricingModel } from '@/generated/prisma/enums'
import { GoodCreateManyInput } from '@/generated/prisma/models'
import { prisma } from '../src/lib/prisma'
@@ -123,6 +122,12 @@ async function main() {
skipDuplicates: true,
})
const geramMeasureUnit = await tx.measureUnits.findFirst({
where: {
code: '63',
},
})
// ****************** GUILD Start ****************** //
let guilds = await tx.guild.findMany()
if (!guilds.length) {
@@ -133,11 +138,6 @@ async function main() {
code: 'Gold',
invoice_template: 'GOLD_JEWELRY',
},
{
name: 'میوه و تره‌بار',
code: 'Fruit',
invoice_template: 'SALE',
},
],
})
guilds = await tx.guild.findMany()
@@ -234,49 +234,49 @@ async function main() {
zivarCategory.id,
GoodPricingModel.GOLD,
'2720000044696',
'63',
geramMeasureUnit!.id,
),
await goodFactory(
'النگو',
zivarCategory.id,
GoodPricingModel.GOLD,
'2720000044665',
'63',
geramMeasureUnit!.id,
),
await goodFactory(
'انگشتر',
zivarCategory.id,
GoodPricingModel.GOLD,
'2720000044672',
'63',
geramMeasureUnit!.id,
),
await goodFactory(
'دست‌بند',
zivarCategory.id,
GoodPricingModel.GOLD,
'2720000044689',
'63',
geramMeasureUnit!.id,
),
await goodFactory(
'زنجیر',
zivarCategory.id,
GoodPricingModel.GOLD,
'2720000044702',
'63',
geramMeasureUnit!.id,
),
await goodFactory(
'سرویس',
zivarCategory.id,
GoodPricingModel.GOLD,
'2720000044733',
'63',
geramMeasureUnit!.id,
),
await goodFactory(
'گوشواره',
zivarCategory.id,
GoodPricingModel.GOLD,
'2720000044726',
'63',
geramMeasureUnit!.id,
),
].filter((item): item is GoodCreateManyInput => item !== null)
goodItems.push(...preparedGoodItems)
@@ -395,178 +395,178 @@ async function main() {
}
// ****************** partner Start ****************** //
let partner = await tx.partner.findFirst()
let license = await tx.license.findFirst()
if (!partner) {
partner = await tx.partner.create({
data: {
name: 'تیس',
code: 'TIS',
status: 'ACTIVE',
tsp_provider: TspProviderType.NAMA,
accounts: {
create: {
role: 'OWNER',
account: {
create: {
username: 'tis',
password: await PasswordUtil.hash('123456'),
status: 'ACTIVE',
type: 'PARTNER',
},
},
},
},
},
})
}
if (partner && !license) {
await tx.$transaction(async tx => {
const startOfToday = new Date()
startOfToday.setHours(0, 0, 0, 0)
// let partner = await tx.partner.findFirst()
// let license = await tx.license.findFirst()
// if (!partner) {
// partner = await tx.partner.create({
// data: {
// name: 'تیس',
// code: 'TIS',
// status: 'ACTIVE',
// tsp_provider: TspProviderType.NAMA,
// accounts: {
// create: {
// role: 'OWNER',
// account: {
// create: {
// username: 'tis',
// password: await PasswordUtil.hash('123456'),
// status: 'ACTIVE',
// type: 'PARTNER',
// },
// },
// },
// },
// },
// })
// }
// if (partner && !license) {
// await tx.$transaction(async tx => {
// const startOfToday = new Date()
// startOfToday.setHours(0, 0, 0, 0)
const month = startOfToday.getMonth()
let year = startOfToday.getFullYear()
let expMonth = month + 3
if (expMonth > 11) {
expMonth = expMonth - 11
year = year + 1
}
// const month = startOfToday.getMonth()
// let year = startOfToday.getFullYear()
// let expMonth = month + 3
// if (expMonth > 11) {
// expMonth = expMonth - 11
// year = year + 1
// }
startOfToday.setFullYear(year)
startOfToday.setMonth(expMonth)
// startOfToday.setFullYear(year)
// startOfToday.setMonth(expMonth)
const transaction = await tx.licenseChargeTransaction.create({
data: {
activation_expires_at: startOfToday,
purchased_count: 1,
tracking_code: generateTrackingCode('LIC', 6),
partner: {
connect: {
id: partner.id,
},
},
},
select: {
id: true,
},
})
if (transaction)
license = await tx.license.create({
data: {
charge_transaction: {
connect: {
id: transaction.id,
},
},
},
})
})
}
// const transaction = await tx.licenseChargeTransaction.create({
// data: {
// activation_expires_at: startOfToday,
// purchased_count: 1,
// tracking_code: generateTrackingCode('LIC', 6),
// partner: {
// connect: {
// id: partner.id,
// },
// },
// },
// select: {
// id: true,
// },
// })
// if (transaction)
// license = await tx.license.create({
// data: {
// charge_transaction: {
// connect: {
// id: transaction.id,
// },
// },
// },
// })
// })
// }
// ****************** BA Start ****************** //
const ba = await tx.businessActivity.count()
// // ****************** BA Start ****************** //
// const ba = await tx.businessActivity.count()
if (!ba && license) {
const startOfToday = new Date()
startOfToday.setHours(0, 0, 0, 0)
// if (!ba && license) {
// const startOfToday = new Date()
// startOfToday.setHours(0, 0, 0, 0)
let year = startOfToday.getFullYear()
let expYear = year + 1
// if (expMonth > 11) {
// expMonth = expMonth - 11
// year = year + 1
// }
// let year = startOfToday.getFullYear()
// let expYear = year + 1
// // if (expMonth > 11) {
// // expMonth = expMonth - 11
// // year = year + 1
// // }
startOfToday.setFullYear(expYear)
// startOfToday.setFullYear(expYear)
await tx.businessActivity.create({
data: {
name: 'طلا فروشی',
economic_code: '0111111111',
fiscal_id: '0111111111',
partner_token: 'TIS-BA-001',
license_activation: {
create: {
expires_at: startOfToday,
starts_at: new Date(),
license: {
connect: {
id: license.id,
},
},
},
},
consumer: {
create: {
type: ConsumerType.INDIVIDUAL,
individual: {
create: {
first_name: 'محمد',
last_name: 'زرگر',
mobile_number: '09120258155',
national_code: '1234567890',
partner: {
connect: {
id: partner.id,
},
},
},
},
accounts: {
create: {
role: 'OWNER',
account: {
create: {
username: 'zargar',
password: await PasswordUtil.hash('123456'),
status: 'ACTIVE',
type: 'CONSUMER',
},
},
},
},
},
},
guild: {
connect: {
id: guilds[0].id,
},
},
complexes: {
create: {
name: 'فروشگاه طلای مرکزی',
address: 'تهران، خیابان جمهوری',
branch_code: '12332',
// await tx.businessActivity.create({
// data: {
// name: 'طلا فروشی',
// economic_code: '0111111111',
// fiscal_id: '0111111111',
// partner_token: 'TIS-BA-001',
// license_activation: {
// create: {
// expires_at: startOfToday,
// starts_at: new Date(),
// license: {
// connect: {
// id: license.id,
// },
// },
// },
// },
// consumer: {
// create: {
// type: ConsumerType.INDIVIDUAL,
// individual: {
// create: {
// first_name: 'محمد',
// last_name: 'زرگر',
// mobile_number: '09120258155',
// national_code: '1234567890',
// partner: {
// connect: {
// id: partner.id,
// },
// },
// },
// },
// accounts: {
// create: {
// role: 'OWNER',
// account: {
// create: {
// username: 'zargar',
// password: await PasswordUtil.hash('123456'),
// status: 'ACTIVE',
// type: 'CONSUMER',
// },
// },
// },
// },
// },
// },
// guild: {
// connect: {
// id: guilds[0].id,
// },
// },
// complexes: {
// create: {
// name: 'فروشگاه طلای مرکزی',
// address: 'تهران، خیابان جمهوری',
// branch_code: '12332',
// pos_list: {
// create: {
// name: 'لاین ۱',
// pos_type: POSType.WEB,
// status: 'ACTIVE',
// account: {
// create: {
// role: 'OPERATOR',
// account_allocation: {
// // pos_list: {
// // create: {
// // name: 'لاین ۱',
// // pos_type: POSType.WEB,
// // status: 'ACTIVE',
// // account: {
// // create: {
// // role: 'OPERATOR',
// // account_allocation: {
// },
// account: {
// create: {
// username: 'line1',
// password: await PasswordUtil.hash('123456'),
// status: 'ACTIVE',
// type: 'CONSUMER',
// },
// },
// }
// }
// },
// },
},
},
},
})
}
// // },
// // account: {
// // create: {
// // username: 'line1',
// // password: await PasswordUtil.hash('123456'),
// // status: 'ACTIVE',
// // type: 'CONSUMER',
// // },
// // },
// // }
// // }
// // },
// // },
// },
// },
// },
// })
// }
// ****************** BA Start ****************** //
// ****************** provider Start ****************** //