2025-03-18 08:05:00 +00:00
|
|
|
import {
|
|
|
|
|
CreationOptional,
|
|
|
|
|
DataTypes,
|
|
|
|
|
InferAttributes,
|
|
|
|
|
InferCreationAttributes,
|
|
|
|
|
Model,
|
2025-05-02 21:43:51 +00:00
|
|
|
NonAttribute,
|
2025-03-18 08:05:00 +00:00
|
|
|
Sequelize,
|
|
|
|
|
} from "sequelize";
|
2025-06-11 15:13:44 +00:00
|
|
|
import { CustomerInvoiceModel } from "./customerCustomerInvoice.model";
|
2025-03-18 08:05:00 +00:00
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
export type CustomerInvoiceItemCreationAttributes = InferCreationAttributes<
|
|
|
|
|
CustomerInvoiceItemModel,
|
|
|
|
|
{ omit: "customerCustomerInvoice" }
|
2025-05-02 21:43:51 +00:00
|
|
|
>;
|
2025-03-18 08:05:00 +00:00
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
export class CustomerInvoiceItemModel extends Model<
|
|
|
|
|
InferAttributes<CustomerInvoiceItemModel>,
|
|
|
|
|
InferCreationAttributes<CustomerInvoiceItemModel, { omit: "customerCustomerInvoice" }>
|
2025-03-18 08:05:00 +00:00
|
|
|
> {
|
|
|
|
|
declare item_id: string;
|
2025-06-11 15:13:44 +00:00
|
|
|
declare customerCustomerInvoice_id: string;
|
2025-04-22 08:11:50 +00:00
|
|
|
|
2025-03-18 08:05:00 +00:00
|
|
|
declare parent_id: CreationOptional<string>;
|
|
|
|
|
declare position: number;
|
|
|
|
|
declare item_type: string;
|
2025-04-22 08:11:50 +00:00
|
|
|
|
2025-03-18 08:05:00 +00:00
|
|
|
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>;
|
|
|
|
|
|
2025-04-22 08:11:50 +00:00
|
|
|
declare discount_amount: CreationOptional<number>;
|
|
|
|
|
declare discount_scale: CreationOptional<number>;
|
|
|
|
|
|
2025-04-01 14:26:15 +00:00
|
|
|
declare total_amount: CreationOptional<number>;
|
|
|
|
|
declare total_scale: CreationOptional<number>;
|
|
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
declare customerCustomerInvoice: NonAttribute<CustomerInvoiceModel>;
|
2025-05-02 21:43:51 +00:00
|
|
|
|
|
|
|
|
static associate(database: Sequelize) {
|
2025-06-11 15:13:44 +00:00
|
|
|
/*const { CustomerInvoice_Model, CustomerInvoiceItem_Model } = connection.models;
|
2025-05-02 21:43:51 +00:00
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
CustomerInvoiceItem_Model.belongsTo(CustomerInvoice_Model, {
|
|
|
|
|
as: "customerCustomerInvoice",
|
|
|
|
|
foreignKey: "customerCustomerInvoice_id",
|
2025-05-02 21:43:51 +00:00
|
|
|
onDelete: "CASCADE",
|
|
|
|
|
});*/
|
|
|
|
|
}
|
2025-03-18 08:05:00 +00:00
|
|
|
}
|
|
|
|
|
|
2025-05-02 21:43:51 +00:00
|
|
|
export default (database: Sequelize) => {
|
2025-06-11 15:13:44 +00:00
|
|
|
CustomerInvoiceItemModel.init(
|
2025-03-18 08:05:00 +00:00
|
|
|
{
|
|
|
|
|
item_id: {
|
|
|
|
|
type: new DataTypes.UUID(),
|
|
|
|
|
primaryKey: true,
|
|
|
|
|
},
|
2025-06-11 15:13:44 +00:00
|
|
|
customerCustomerInvoice_id: {
|
2025-03-18 08:05:00 +00:00
|
|
|
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-04-22 08:11:50 +00:00
|
|
|
discount_amount: {
|
|
|
|
|
type: new DataTypes.SMALLINT(),
|
|
|
|
|
allowNull: true,
|
|
|
|
|
defaultValue: null,
|
|
|
|
|
},
|
|
|
|
|
discount_scale: {
|
|
|
|
|
type: new DataTypes.SMALLINT(),
|
|
|
|
|
allowNull: true,
|
|
|
|
|
defaultValue: null,
|
|
|
|
|
},
|
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2025-05-02 21:43:51 +00:00
|
|
|
sequelize: database,
|
2025-06-11 15:13:44 +00:00
|
|
|
tableName: "customerCustomerInvoice_items",
|
2025-04-22 08:11:50 +00:00
|
|
|
|
|
|
|
|
defaultScope: {},
|
|
|
|
|
|
|
|
|
|
scopes: {},
|
2025-04-01 14:26:15 +00:00
|
|
|
}
|
2025-03-18 08:05:00 +00:00
|
|
|
);
|
|
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
return CustomerInvoiceItemModel;
|
2025-03-18 08:05:00 +00:00
|
|
|
};
|