2025-03-18 08:05:00 +00:00
|
|
|
import {
|
|
|
|
|
CreationOptional,
|
|
|
|
|
DataTypes,
|
|
|
|
|
InferAttributes,
|
|
|
|
|
InferCreationAttributes,
|
|
|
|
|
Model,
|
|
|
|
|
NonAttribute,
|
|
|
|
|
Sequelize,
|
|
|
|
|
} from "sequelize";
|
2025-04-01 14:26:15 +00:00
|
|
|
import { InvoiceModel } from "./invoice.model";
|
2025-03-18 08:05:00 +00:00
|
|
|
|
|
|
|
|
export type TCreationInvoiceItem_Model = InferCreationAttributes<
|
|
|
|
|
InvoiceItem_Model,
|
2025-04-01 14:26:15 +00:00
|
|
|
{
|
|
|
|
|
/*omit: "invoice"*/
|
|
|
|
|
}
|
2025-03-18 08:05:00 +00:00
|
|
|
>;
|
|
|
|
|
|
|
|
|
|
export class InvoiceItem_Model extends Model<
|
2025-04-01 14:26:15 +00:00
|
|
|
InferAttributes<
|
|
|
|
|
InvoiceItem_Model,
|
|
|
|
|
{
|
|
|
|
|
/*omit: "invoice"*/
|
|
|
|
|
}
|
|
|
|
|
>,
|
|
|
|
|
InferCreationAttributes<
|
|
|
|
|
InvoiceItem_Model,
|
|
|
|
|
{
|
|
|
|
|
/*omit: "invoice"*/
|
|
|
|
|
}
|
|
|
|
|
>
|
2025-03-18 08:05:00 +00:00
|
|
|
> {
|
|
|
|
|
static associate(connection: Sequelize) {
|
|
|
|
|
const { Invoice_Model, InvoiceItem_Model } = connection.models;
|
|
|
|
|
|
|
|
|
|
InvoiceItem_Model.belongsTo(Invoice_Model, {
|
|
|
|
|
as: "invoice",
|
|
|
|
|
foreignKey: "invoice_id",
|
|
|
|
|
onDelete: "CASCADE",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
declare invoice_id: string;
|
|
|
|
|
declare item_id: string;
|
|
|
|
|
declare parent_id: CreationOptional<string>;
|
|
|
|
|
declare position: number;
|
|
|
|
|
declare item_type: string;
|
|
|
|
|
declare description: CreationOptional<string>;
|
|
|
|
|
|
2025-04-01 14:26:15 +00:00
|
|
|
declare quantity_amount: CreationOptional<number>;
|
|
|
|
|
declare quantity_scale: CreationOptional<number>;
|
|
|
|
|
|
|
|
|
|
declare unit_price_amount: CreationOptional<number>;
|
|
|
|
|
declare unit_price_scale: CreationOptional<number>;
|
|
|
|
|
|
|
|
|
|
declare subtotal_amount: CreationOptional<number>;
|
|
|
|
|
declare subtotal_scale: CreationOptional<number>;
|
|
|
|
|
|
|
|
|
|
declare total_amount: CreationOptional<number>;
|
|
|
|
|
declare total_scale: CreationOptional<number>;
|
|
|
|
|
|
|
|
|
|
declare invoice?: NonAttribute<InvoiceModel>;
|
2025-03-18 08:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default (sequelize: Sequelize) => {
|
|
|
|
|
InvoiceItem_Model.init(
|
|
|
|
|
{
|
|
|
|
|
item_id: {
|
|
|
|
|
type: new DataTypes.UUID(),
|
|
|
|
|
primaryKey: true,
|
|
|
|
|
},
|
|
|
|
|
invoice_id: {
|
|
|
|
|
type: new DataTypes.UUID(),
|
|
|
|
|
primaryKey: true,
|
|
|
|
|
},
|
|
|
|
|
parent_id: {
|
|
|
|
|
type: new DataTypes.UUID(),
|
|
|
|
|
allowNull: true, // Puede ser nulo para elementos de nivel superior
|
|
|
|
|
},
|
|
|
|
|
position: {
|
|
|
|
|
type: new DataTypes.MEDIUMINT(),
|
|
|
|
|
autoIncrement: false,
|
|
|
|
|
allowNull: false,
|
|
|
|
|
},
|
|
|
|
|
item_type: {
|
|
|
|
|
type: new DataTypes.STRING(),
|
|
|
|
|
allowNull: false,
|
|
|
|
|
defaultValue: "simple",
|
|
|
|
|
},
|
|
|
|
|
description: {
|
|
|
|
|
type: new DataTypes.TEXT(),
|
|
|
|
|
allowNull: true,
|
|
|
|
|
},
|
2025-04-01 14:26:15 +00:00
|
|
|
|
|
|
|
|
quantity_amount: {
|
|
|
|
|
type: new DataTypes.BIGINT(),
|
|
|
|
|
allowNull: true,
|
|
|
|
|
defaultValue: null,
|
|
|
|
|
},
|
|
|
|
|
quantity_scale: {
|
|
|
|
|
type: new DataTypes.SMALLINT(),
|
2025-03-18 08:05:00 +00:00
|
|
|
allowNull: true,
|
2025-04-01 14:26:15 +00:00
|
|
|
defaultValue: null,
|
2025-03-18 08:05:00 +00:00
|
|
|
},
|
2025-04-01 14:26:15 +00:00
|
|
|
|
|
|
|
|
unit_price_amount: {
|
2025-03-18 08:05:00 +00:00
|
|
|
type: new DataTypes.BIGINT(),
|
|
|
|
|
allowNull: true,
|
2025-04-01 14:26:15 +00:00
|
|
|
defaultValue: null,
|
2025-03-18 08:05:00 +00:00
|
|
|
},
|
2025-04-01 14:26:15 +00:00
|
|
|
unit_price_scale: {
|
|
|
|
|
type: new DataTypes.SMALLINT(),
|
|
|
|
|
allowNull: true,
|
|
|
|
|
defaultValue: null,
|
|
|
|
|
},
|
|
|
|
|
|
2025-03-18 08:05:00 +00:00
|
|
|
/*tax_slug: {
|
|
|
|
|
type: new DataTypes.DECIMAL(3, 2),
|
|
|
|
|
allowNull: true,
|
|
|
|
|
},
|
|
|
|
|
tax_rate: {
|
|
|
|
|
type: new DataTypes.DECIMAL(3, 2),
|
|
|
|
|
allowNull: true,
|
|
|
|
|
},
|
|
|
|
|
tax_equalization: {
|
|
|
|
|
type: new DataTypes.DECIMAL(3, 2),
|
|
|
|
|
allowNull: true,
|
|
|
|
|
},*/
|
2025-04-01 14:26:15 +00:00
|
|
|
|
|
|
|
|
subtotal_amount: {
|
|
|
|
|
type: new DataTypes.BIGINT(), // importante: evita problemas de precisión con valores grandes
|
|
|
|
|
allowNull: true,
|
|
|
|
|
defaultValue: null,
|
|
|
|
|
},
|
|
|
|
|
subtotal_scale: {
|
|
|
|
|
type: new DataTypes.SMALLINT(),
|
2025-03-18 08:05:00 +00:00
|
|
|
allowNull: true,
|
2025-04-01 14:26:15 +00:00
|
|
|
defaultValue: null,
|
2025-03-18 08:05:00 +00:00
|
|
|
},
|
2025-04-01 14:26:15 +00:00
|
|
|
|
2025-03-18 08:05:00 +00:00
|
|
|
/*tax_amount: {
|
|
|
|
|
type: new DataTypes.BIGINT(),
|
|
|
|
|
allowNull: true,
|
|
|
|
|
},*/
|
2025-04-01 14:26:15 +00:00
|
|
|
total_amount: {
|
|
|
|
|
type: new DataTypes.BIGINT(), // importante: evita problemas de precisión con valores grandes
|
2025-03-18 08:05:00 +00:00
|
|
|
allowNull: true,
|
2025-04-01 14:26:15 +00:00
|
|
|
defaultValue: null,
|
|
|
|
|
},
|
|
|
|
|
total_scale: {
|
|
|
|
|
type: new DataTypes.SMALLINT(),
|
|
|
|
|
allowNull: true,
|
|
|
|
|
defaultValue: null,
|
2025-03-18 08:05:00 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
sequelize,
|
|
|
|
|
tableName: "invoice_items",
|
2025-04-01 14:26:15 +00:00
|
|
|
}
|
2025-03-18 08:05:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return InvoiceItem_Model;
|
|
|
|
|
};
|