add startDate endDate in instition and receipt , codeProductRecieve in taskOrder
This commit is contained in:
parent
e42b772dcf
commit
f98371132a
7 changed files with 84 additions and 5 deletions
2
prisma/migrations/20250418095201_add/migration.sql
Normal file
2
prisma/migrations/20250418095201_add/migration.sql
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "TaskOrder" ADD COLUMN "codeProductReceived" TEXT;
|
||||||
18
prisma/migrations/20250418103300_add/migration.sql
Normal file
18
prisma/migrations/20250418103300_add/migration.sql
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Institution" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
ADD COLUMN "createdByUserId" TEXT,
|
||||||
|
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
ADD COLUMN "updatedByUserId" TEXT;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Payment" ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
ADD COLUMN "updatedByUserId" TEXT;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Institution" ADD CONSTRAINT "Institution_createdByUserId_fkey" FOREIGN KEY ("createdByUserId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Institution" ADD CONSTRAINT "Institution_updatedByUserId_fkey" FOREIGN KEY ("updatedByUserId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Payment" ADD CONSTRAINT "Payment_updatedByUserId_fkey" FOREIGN KEY ("updatedByUserId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
@ -484,12 +484,15 @@ model User {
|
||||||
flowCreated WorkflowTemplate[] @relation("FlowCreatedByUser")
|
flowCreated WorkflowTemplate[] @relation("FlowCreatedByUser")
|
||||||
flowUpdated WorkflowTemplate[] @relation("FlowUpdatedByUser")
|
flowUpdated WorkflowTemplate[] @relation("FlowUpdatedByUser")
|
||||||
invoiceCreated Invoice[]
|
invoiceCreated Invoice[]
|
||||||
paymentCreated Payment[]
|
paymentCreated Payment[] @relation("PaymentCreatedByUser")
|
||||||
|
paymentUpdated Payment[] @relation("PaymentUpdatedByUser")
|
||||||
notificationReceive Notification[] @relation("NotificationReceiver")
|
notificationReceive Notification[] @relation("NotificationReceiver")
|
||||||
notificationRead Notification[] @relation("NotificationRead")
|
notificationRead Notification[] @relation("NotificationRead")
|
||||||
notificationDelete Notification[] @relation("NotificationDelete")
|
notificationDelete Notification[] @relation("NotificationDelete")
|
||||||
taskOrderCreated TaskOrder[] @relation("TaskOrderCreatedByUser")
|
taskOrderCreated TaskOrder[] @relation("TaskOrderCreatedByUser")
|
||||||
creditNoteCreated CreditNote[] @relation("CreditNoteCreatedByUser")
|
creditNoteCreated CreditNote[] @relation("CreditNoteCreatedByUser")
|
||||||
|
institutionCreated Institution[] @relation("InstitutionCreatedByUser")
|
||||||
|
institutionUpdated Institution[] @relation("InstitutionUpdatedByUser")
|
||||||
|
|
||||||
requestWorkStepStatus RequestWorkStepStatus[]
|
requestWorkStepStatus RequestWorkStepStatus[]
|
||||||
userTask UserTask[]
|
userTask UserTask[]
|
||||||
|
|
@ -1015,6 +1018,13 @@ model Institution {
|
||||||
contactEmail String?
|
contactEmail String?
|
||||||
contactTel String?
|
contactTel String?
|
||||||
|
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
createdBy User? @relation(name: "InstitutionCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
|
||||||
|
createdByUserId String?
|
||||||
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
|
updatedBy User? @relation(name: "InstitutionUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
|
||||||
|
updatedByUserId String?
|
||||||
|
|
||||||
bank InstitutionBank[]
|
bank InstitutionBank[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1463,8 +1473,12 @@ model Payment {
|
||||||
date DateTime?
|
date DateTime?
|
||||||
|
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
createdBy User? @relation(fields: [createdByUserId], references: [id], onDelete: SetNull)
|
createdBy User? @relation(name: "PaymentCreatedByUser", fields: [createdByUserId], references: [id], onDelete: SetNull)
|
||||||
createdByUserId String?
|
createdByUserId String?
|
||||||
|
|
||||||
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
|
updatedBy User? @relation(name: "PaymentUpdatedByUser", fields: [updatedByUserId], references: [id], onDelete: SetNull)
|
||||||
|
updatedByUserId String?
|
||||||
}
|
}
|
||||||
|
|
||||||
enum RequestDataStatus {
|
enum RequestDataStatus {
|
||||||
|
|
@ -1617,7 +1631,8 @@ model TaskProduct {
|
||||||
model TaskOrder {
|
model TaskOrder {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
|
|
||||||
code String
|
code String
|
||||||
|
codeProductReceived String?
|
||||||
|
|
||||||
taskName String
|
taskName String
|
||||||
taskOrderStatus TaskOrderStatus @default(Pending)
|
taskOrderStatus TaskOrderStatus @default(Pending)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import {
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import prisma from "../db";
|
import prisma from "../db";
|
||||||
import { isUsedError, notFoundError } from "../utils/error";
|
import { isUsedError, notFoundError } from "../utils/error";
|
||||||
import { queryOrNot } from "../utils/relation";
|
import { queryOrNot, whereDateQuery } from "../utils/relation";
|
||||||
import { RequestWithUser } from "../interfaces/user";
|
import { RequestWithUser } from "../interfaces/user";
|
||||||
import { deleteFile, fileLocation, getFile, getPresigned, listFile, setFile } from "../utils/minio";
|
import { deleteFile, fileLocation, getFile, getPresigned, listFile, setFile } from "../utils/minio";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
|
|
@ -108,8 +108,19 @@ export class InstitutionController extends Controller {
|
||||||
@Query() status?: Status,
|
@Query() status?: Status,
|
||||||
@Query() activeOnly?: boolean,
|
@Query() activeOnly?: boolean,
|
||||||
@Query() group?: string,
|
@Query() group?: string,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
return this.getInstitutionListByCriteria(query, page, pageSize, status, activeOnly, group);
|
return this.getInstitutionListByCriteria(
|
||||||
|
query,
|
||||||
|
page,
|
||||||
|
pageSize,
|
||||||
|
status,
|
||||||
|
activeOnly,
|
||||||
|
group,
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post("list")
|
@Post("list")
|
||||||
|
|
@ -122,6 +133,8 @@ export class InstitutionController extends Controller {
|
||||||
@Query() status?: Status,
|
@Query() status?: Status,
|
||||||
@Query() activeOnly?: boolean,
|
@Query() activeOnly?: boolean,
|
||||||
@Query() group?: string,
|
@Query() group?: string,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
@Body()
|
@Body()
|
||||||
body?: {
|
body?: {
|
||||||
group?: string[];
|
group?: string[];
|
||||||
|
|
@ -134,6 +147,7 @@ export class InstitutionController extends Controller {
|
||||||
{ name: { contains: query, mode: "insensitive" } },
|
{ name: { contains: query, mode: "insensitive" } },
|
||||||
{ code: { contains: query, mode: "insensitive" } },
|
{ code: { contains: query, mode: "insensitive" } },
|
||||||
]),
|
]),
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
} satisfies Prisma.InstitutionWhereInput;
|
} satisfies Prisma.InstitutionWhereInput;
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
@ -178,6 +192,7 @@ export class InstitutionController extends Controller {
|
||||||
body: InstitutionPayload & {
|
body: InstitutionPayload & {
|
||||||
status?: Status;
|
status?: Status;
|
||||||
},
|
},
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
return await prisma.$transaction(async (tx) => {
|
return await prisma.$transaction(async (tx) => {
|
||||||
const last = await tx.runningNo.upsert({
|
const last = await tx.runningNo.upsert({
|
||||||
|
|
@ -194,6 +209,8 @@ export class InstitutionController extends Controller {
|
||||||
return await tx.institution.create({
|
return await tx.institution.create({
|
||||||
include: {
|
include: {
|
||||||
bank: true,
|
bank: true,
|
||||||
|
createdBy: true,
|
||||||
|
updatedBy: true,
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
...body,
|
...body,
|
||||||
|
|
@ -204,6 +221,8 @@ export class InstitutionController extends Controller {
|
||||||
data: body.bank ?? [],
|
data: body.bank ?? [],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
createdByUserId: req.user.sub,
|
||||||
|
updatedByUserId: req.user.sub,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { Prisma } from "@prisma/client";
|
||||||
import { notFoundError } from "../utils/error";
|
import { notFoundError } from "../utils/error";
|
||||||
import { RequestWithUser } from "../interfaces/user";
|
import { RequestWithUser } from "../interfaces/user";
|
||||||
import { createPermCondition } from "../services/permission";
|
import { createPermCondition } from "../services/permission";
|
||||||
|
import { whereDateQuery } from "../utils/relation";
|
||||||
|
|
||||||
const permissionCondCompany = createPermCondition((_) => true);
|
const permissionCondCompany = createPermCondition((_) => true);
|
||||||
|
|
||||||
|
|
@ -21,6 +22,8 @@ export class ReceiptController extends Controller {
|
||||||
@Query() quotationId?: string,
|
@Query() quotationId?: string,
|
||||||
@Query() debitNoteId?: string,
|
@Query() debitNoteId?: string,
|
||||||
@Query() debitNoteOnly?: boolean,
|
@Query() debitNoteOnly?: boolean,
|
||||||
|
@Query() startDate?: Date,
|
||||||
|
@Query() endDate?: Date,
|
||||||
) {
|
) {
|
||||||
const where: Prisma.PaymentWhereInput = {
|
const where: Prisma.PaymentWhereInput = {
|
||||||
paymentStatus: "PaymentSuccess",
|
paymentStatus: "PaymentSuccess",
|
||||||
|
|
@ -33,6 +36,7 @@ export class ReceiptController extends Controller {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
...whereDateQuery(startDate, endDate),
|
||||||
};
|
};
|
||||||
|
|
||||||
const [result, total] = await prisma.$transaction([
|
const [result, total] = await prisma.$transaction([
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,7 @@ export class QuotationPayment extends Controller {
|
||||||
async updatePayment(
|
async updatePayment(
|
||||||
@Path() paymentId: string,
|
@Path() paymentId: string,
|
||||||
@Body() body: { amount?: number; date?: Date; paymentStatus?: PaymentStatus },
|
@Body() body: { amount?: number; date?: Date; paymentStatus?: PaymentStatus },
|
||||||
|
@Request() req: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
const record = await prisma.payment.findUnique({
|
const record = await prisma.payment.findUnique({
|
||||||
where: { id: paymentId },
|
where: { id: paymentId },
|
||||||
|
|
@ -164,6 +165,7 @@ export class QuotationPayment extends Controller {
|
||||||
code: lastReceipt
|
code: lastReceipt
|
||||||
? `RE${year}${month}${lastReceipt.value.toString().padStart(6, "0")}`
|
? `RE${year}${month}${lastReceipt.value.toString().padStart(6, "0")}`
|
||||||
: undefined,
|
: undefined,
|
||||||
|
updatedByUserId: req.user.sub,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -697,12 +697,31 @@ export class TaskActionController extends Controller {
|
||||||
if (!record) throw notFoundError("Task Order");
|
if (!record) throw notFoundError("Task Order");
|
||||||
|
|
||||||
await prisma.$transaction(async (tx) => {
|
await prisma.$transaction(async (tx) => {
|
||||||
|
const last = await tx.runningNo.upsert({
|
||||||
|
where: {
|
||||||
|
key: "TASK_RI",
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
key: "TASK_RI",
|
||||||
|
value: 1,
|
||||||
|
},
|
||||||
|
update: {
|
||||||
|
value: { increment: 1 },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const current = new Date();
|
||||||
|
const year = `${current.getFullYear()}`.padStart(2, "0");
|
||||||
|
const month = `${current.getMonth() + 1}`.padStart(2, "0");
|
||||||
|
|
||||||
|
const code = `RI${year}${month}${last.value.toString().padStart(6, "0")}`;
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
tx.taskOrder.update({
|
tx.taskOrder.update({
|
||||||
where: { id: taskOrderId },
|
where: { id: taskOrderId },
|
||||||
data: {
|
data: {
|
||||||
urgent: false,
|
urgent: false,
|
||||||
taskOrderStatus: TaskOrderStatus.Complete,
|
taskOrderStatus: TaskOrderStatus.Complete,
|
||||||
|
codeProductReceived: code,
|
||||||
userTask: {
|
userTask: {
|
||||||
updateMany: {
|
updateMany: {
|
||||||
where: { taskOrderId },
|
where: { taskOrderId },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue