2025-04-01 14:26:15 +00:00
|
|
|
import {
|
|
|
|
|
CreationOptional,
|
|
|
|
|
DataTypes,
|
|
|
|
|
InferAttributes,
|
|
|
|
|
InferCreationAttributes,
|
|
|
|
|
Model,
|
2025-04-22 08:11:50 +00:00
|
|
|
NonAttribute,
|
2025-04-01 14:26:15 +00:00
|
|
|
Sequelize,
|
|
|
|
|
} from "sequelize";
|
2025-06-11 15:13:44 +00:00
|
|
|
import { CustomerInvoiceItemCreationAttributes, CustomerInvoiceItemModel } from "./customerCustomerInvoice-item.model";
|
2025-04-01 14:26:15 +00:00
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
export type CustomerInvoiceCreationAttributes = InferCreationAttributes<CustomerInvoiceModel, { omit: "items" }> & {
|
|
|
|
|
items?: CustomerInvoiceItemCreationAttributes[];
|
2025-04-22 08:11:50 +00:00
|
|
|
};
|
2025-04-01 14:26:15 +00:00
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
export class CustomerInvoiceModel extends Model<
|
|
|
|
|
InferAttributes<CustomerInvoiceModel>,
|
|
|
|
|
InferCreationAttributes<CustomerInvoiceModel, { omit: "items" }>
|
2025-05-02 21:43:51 +00:00
|
|
|
> {
|
2025-04-01 14:26:15 +00:00
|
|
|
declare id: string;
|
|
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
declare customerCustomerInvoice_status: string;
|
|
|
|
|
declare customerCustomerInvoice_series: CreationOptional<string>;
|
|
|
|
|
declare customerCustomerInvoice_number: CreationOptional<string>;
|
2025-04-01 14:26:15 +00:00
|
|
|
declare issue_date: CreationOptional<string>;
|
|
|
|
|
declare operation_date: CreationOptional<string>;
|
2025-06-11 15:13:44 +00:00
|
|
|
declare customerCustomerInvoice_language: string;
|
|
|
|
|
declare customerCustomerInvoice_currency: string;
|
2025-04-01 14:26:15 +00:00
|
|
|
|
|
|
|
|
// Subtotal
|
|
|
|
|
declare subtotal_amount: CreationOptional<number>;
|
|
|
|
|
declare subtotal_scale: CreationOptional<number>;
|
|
|
|
|
|
|
|
|
|
// Total
|
|
|
|
|
declare total_amount: CreationOptional<number>;
|
|
|
|
|
declare total_scale: CreationOptional<number>;
|
|
|
|
|
|
2025-05-02 21:43:51 +00:00
|
|
|
// Relaciones
|
2025-06-11 15:13:44 +00:00
|
|
|
declare items: NonAttribute<CustomerInvoiceItemModel[]>;
|
|
|
|
|
//declare customer: NonAttribute<CustomerInvoiceParticipant_Model[]>;
|
2025-05-02 21:43:51 +00:00
|
|
|
|
|
|
|
|
static associate(database: Sequelize) {
|
2025-06-11 15:13:44 +00:00
|
|
|
const { CustomerInvoiceModel, CustomerInvoiceItemModel } = database.models;
|
2025-05-02 21:43:51 +00:00
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
CustomerInvoiceModel.hasMany(CustomerInvoiceItemModel, {
|
2025-05-02 21:43:51 +00:00
|
|
|
as: "items",
|
2025-06-11 15:13:44 +00:00
|
|
|
foreignKey: "customerCustomerInvoice_id",
|
2025-05-02 21:43:51 +00:00
|
|
|
onDelete: "CASCADE",
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-04-01 14:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
2025-05-02 21:43:51 +00:00
|
|
|
export default (database: Sequelize) => {
|
2025-06-11 15:13:44 +00:00
|
|
|
CustomerInvoiceModel.init(
|
2025-04-01 14:26:15 +00:00
|
|
|
{
|
|
|
|
|
id: {
|
|
|
|
|
type: new DataTypes.UUID(),
|
|
|
|
|
primaryKey: true,
|
|
|
|
|
},
|
|
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
customerCustomerInvoice_status: {
|
2025-04-01 14:26:15 +00:00
|
|
|
type: new DataTypes.STRING(),
|
|
|
|
|
allowNull: false,
|
|
|
|
|
},
|
|
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
customerCustomerInvoice_series: {
|
2025-04-01 14:26:15 +00:00
|
|
|
type: new DataTypes.STRING(),
|
|
|
|
|
allowNull: true,
|
|
|
|
|
defaultValue: null,
|
|
|
|
|
},
|
|
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
customerCustomerInvoice_number: {
|
2025-04-01 14:26:15 +00:00
|
|
|
type: new DataTypes.STRING(),
|
|
|
|
|
allowNull: true,
|
|
|
|
|
defaultValue: null,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
issue_date: {
|
2025-04-01 15:32:53 +00:00
|
|
|
type: new DataTypes.DATEONLY(),
|
2025-04-01 14:26:15 +00:00
|
|
|
allowNull: true,
|
|
|
|
|
defaultValue: null,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
operation_date: {
|
2025-04-01 15:32:53 +00:00
|
|
|
type: new DataTypes.DATEONLY(),
|
2025-04-01 14:26:15 +00:00
|
|
|
allowNull: true,
|
|
|
|
|
defaultValue: null,
|
|
|
|
|
},
|
|
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
customerCustomerInvoice_language: {
|
2025-04-01 14:26:15 +00:00
|
|
|
type: new DataTypes.STRING(),
|
|
|
|
|
allowNull: false,
|
|
|
|
|
},
|
|
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
customerCustomerInvoice_currency: {
|
2025-04-01 14:26:15 +00:00
|
|
|
type: new DataTypes.STRING(3), // ISO 4217
|
|
|
|
|
allowNull: false,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
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(),
|
|
|
|
|
allowNull: true,
|
|
|
|
|
defaultValue: null,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
total_amount: {
|
|
|
|
|
type: new DataTypes.BIGINT(), // importante: evita problemas de precisión con valores grandes
|
|
|
|
|
allowNull: true,
|
|
|
|
|
defaultValue: null,
|
|
|
|
|
},
|
|
|
|
|
total_scale: {
|
|
|
|
|
type: new DataTypes.SMALLINT(),
|
|
|
|
|
allowNull: true,
|
|
|
|
|
defaultValue: null,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
2025-05-02 21:43:51 +00:00
|
|
|
sequelize: database,
|
2025-06-11 15:13:44 +00:00
|
|
|
tableName: "customerCustomerInvoices",
|
2025-04-01 14:26:15 +00:00
|
|
|
|
|
|
|
|
paranoid: true, // softs deletes
|
|
|
|
|
timestamps: true,
|
|
|
|
|
|
|
|
|
|
createdAt: "created_at",
|
|
|
|
|
updatedAt: "updated_at",
|
|
|
|
|
deletedAt: "deleted_at",
|
|
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
indexes: [{ unique: true, fields: ["customerCustomerInvoice_number"] }],
|
2025-04-01 14:26:15 +00:00
|
|
|
|
|
|
|
|
whereMergeStrategy: "and", // <- cómo tratar el merge de un scope
|
|
|
|
|
|
|
|
|
|
defaultScope: {},
|
|
|
|
|
|
|
|
|
|
scopes: {},
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2025-06-11 15:13:44 +00:00
|
|
|
return CustomerInvoiceModel;
|
2025-04-01 14:26:15 +00:00
|
|
|
};
|