diff --git a/database/migrations/.snapshot-dmenu.json b/database/migrations/.snapshot-dmenu.json index 3903d2b..6a4d810 100644 --- a/database/migrations/.snapshot-dmenu.json +++ b/database/migrations/.snapshot-dmenu.json @@ -4326,6 +4326,16 @@ "nullable": true, "mappedType": "text" }, + "print_invoice": { + "name": "print_invoice", + "type": "boolean", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": false, + "default": "false", + "mappedType": "boolean" + }, "table_number": { "name": "table_number", "type": "varchar(255)", diff --git a/database/migrations/Migration20260701083547_addPrintInvoiceToOrders.ts b/database/migrations/Migration20260701083547_addPrintInvoiceToOrders.ts new file mode 100644 index 0000000..7fa41f2 --- /dev/null +++ b/database/migrations/Migration20260701083547_addPrintInvoiceToOrders.ts @@ -0,0 +1,13 @@ +import { Migration } from '@mikro-orm/migrations'; + +export class Migration20260701083547_addPrintInvoiceToOrders extends Migration { + + override async up(): Promise { + this.addSql(`alter table "orders" add column "print_invoice" boolean not null default false;`); + } + + override async down(): Promise { + this.addSql(`alter table "orders" drop column "print_invoice";`); + } + +} diff --git a/src/modules/cart/dto/set-all-cart-params.dto.ts b/src/modules/cart/dto/set-all-cart-params.dto.ts index 9710211..9964612 100644 --- a/src/modules/cart/dto/set-all-cart-params.dto.ts +++ b/src/modules/cart/dto/set-all-cart-params.dto.ts @@ -1,5 +1,5 @@ import { ApiProperty } from '@nestjs/swagger'; -import { IsArray, IsNotEmpty, IsObject, IsOptional, IsString } from 'class-validator'; +import { IsArray, IsBoolean, IsNotEmpty, IsObject, IsOptional, IsString } from 'class-validator'; import { SetCarDeliveryDto } from './set-car-delivery.dto'; @@ -33,6 +33,16 @@ export class SetAllCartParmsDto { @IsString() tableNumber?: string; + @ApiProperty({ + description: 'Whether the customer wants a printed invoice', + required: false, + default: false, + example: false, + }) + @IsOptional() + @IsBoolean() + printInvoice?: boolean; + @ApiProperty() @IsOptional() @IsObject() diff --git a/src/modules/cart/interfaces/cart.interface.ts b/src/modules/cart/interfaces/cart.interface.ts index 459fdc0..0bc9152 100644 --- a/src/modules/cart/interfaces/cart.interface.ts +++ b/src/modules/cart/interfaces/cart.interface.ts @@ -19,6 +19,7 @@ export interface Cart { paymentMethodId?: string; deliveryMethodId?: string; description?: string; + printInvoice?: boolean; tableNumber?: string; attachments?: string[]; paymentDesc?: string; diff --git a/src/modules/cart/providers/cart.service.ts b/src/modules/cart/providers/cart.service.ts index bcb70cd..e2b7386 100644 --- a/src/modules/cart/providers/cart.service.ts +++ b/src/modules/cart/providers/cart.service.ts @@ -28,7 +28,7 @@ export class CartService { * Set all cart parameters at once */ async setAllCartParams(userId: string, restaurantId: string, params: SetAllCartParmsDto): Promise { - const { deliveryMethodId, paymentMethodId, addressId, carAddress, description, tableNumber, attachments, paymentDesc } = params; + const { deliveryMethodId, paymentMethodId, addressId, carAddress, description, tableNumber, printInvoice, attachments, paymentDesc } = params; // get existing cart (or throw) const cart = await this.findOneOrFail(userId, restaurantId); @@ -117,6 +117,10 @@ export class CartService { cart.description = description; } + if (printInvoice !== undefined) { + cart.printInvoice = printInvoice; + } + if (paymentMethod.method === PaymentMethodEnum.CreditCard) { this.validationService.assertCreditCardPaymentDetails(paymentMethod, paymentDesc, attachments); cart.paymentDesc = paymentDesc?.trim() || undefined; diff --git a/src/modules/orders/entities/order.entity.ts b/src/modules/orders/entities/order.entity.ts index 195ea26..0458707 100644 --- a/src/modules/orders/entities/order.entity.ts +++ b/src/modules/orders/entities/order.entity.ts @@ -92,6 +92,9 @@ export class Order extends BaseEntity { @Property({ type: 'text', nullable: true }) description?: string; + @Property({ type: 'boolean', default: false }) + printInvoice: boolean = false; + @Property({ nullable: true }) tableNumber?: string; diff --git a/src/modules/orders/providers/orders.service.ts b/src/modules/orders/providers/orders.service.ts index aa19fbf..a9611bc 100644 --- a/src/modules/orders/providers/orders.service.ts +++ b/src/modules/orders/providers/orders.service.ts @@ -87,6 +87,7 @@ export class OrdersService { total: cart.total || 0, totalItems: cart.totalItems || 0, description: cart.description, + printInvoice: cart.printInvoice ?? false, tableNumber: cart.tableNumber, status: OrderStatus.PENDING_PAYMENT, history: [{ status: OrderStatus.PENDING_PAYMENT, changedAt: new Date() }], @@ -199,6 +200,7 @@ export class OrdersService { total, totalItems, description: dto.description, + printInvoice: false, tableNumber: dto.tableNumber, status: OrderStatus.PENDING_PAYMENT, history: [{ status: OrderStatus.PENDING_PAYMENT, changedAt: new Date() }],