Facturas de cliente
This commit is contained in:
parent
4c4afe2b3a
commit
2c695ee8a6
@ -43,7 +43,7 @@ export class IssueProformaUseCase {
|
|||||||
|
|
||||||
const proformaId = idOrError.data;
|
const proformaId = idOrError.data;
|
||||||
const presenter = this.presenterRegistry.getPresenter({
|
const presenter = this.presenterRegistry.getPresenter({
|
||||||
resource: "proforma",
|
resource: "issued-invoice",
|
||||||
projection: "FULL",
|
projection: "FULL",
|
||||||
}) as ProformaFullPresenter;
|
}) as ProformaFullPresenter;
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import {
|
|||||||
type ValidationErrorDetail,
|
type ValidationErrorDetail,
|
||||||
extractOrPushError,
|
extractOrPushError,
|
||||||
maybeFromNullableVO,
|
maybeFromNullableVO,
|
||||||
toNullable,
|
toEmptyString,
|
||||||
} from "@repo/rdx-ddd";
|
} from "@repo/rdx-ddd";
|
||||||
import { Maybe, Result } from "@repo/rdx-utils";
|
import { Maybe, Result } from "@repo/rdx-utils";
|
||||||
|
|
||||||
@ -120,10 +120,10 @@ export class CustomerInvoiceVerifactuDomainMapper
|
|||||||
id: UniqueID.generateNewID().toPrimitive(),
|
id: UniqueID.generateNewID().toPrimitive(),
|
||||||
invoice_id: parent.id.toPrimitive(),
|
invoice_id: parent.id.toPrimitive(),
|
||||||
estado: VerifactuRecordEstado.createPendiente().toPrimitive(),
|
estado: VerifactuRecordEstado.createPendiente().toPrimitive(),
|
||||||
qr: null,
|
qr: "",
|
||||||
url: null,
|
url: "",
|
||||||
uuid: null,
|
uuid: "",
|
||||||
operacion: null,
|
operacion: "",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,10 +133,10 @@ export class CustomerInvoiceVerifactuDomainMapper
|
|||||||
id: verifactu.id.toPrimitive(),
|
id: verifactu.id.toPrimitive(),
|
||||||
invoice_id: parent.id.toPrimitive(),
|
invoice_id: parent.id.toPrimitive(),
|
||||||
estado: verifactu.estado.toPrimitive(),
|
estado: verifactu.estado.toPrimitive(),
|
||||||
qr: toNullable(verifactu.qrCode, (v) => v),
|
qr: toEmptyString(verifactu.qrCode, (v) => v),
|
||||||
url: toNullable(verifactu.url, (v) => v.toPrimitive()),
|
url: toEmptyString(verifactu.url, (v) => v.toPrimitive()),
|
||||||
uuid: toNullable(verifactu.uuid, (v) => v),
|
uuid: toEmptyString(verifactu.uuid, (v) => v),
|
||||||
operacion: toNullable(verifactu.operacion, (v) => v),
|
operacion: toEmptyString(verifactu.operacion, (v) => v),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,18 +76,47 @@ export class CustomerInvoiceRepository
|
|||||||
const mapper: ICustomerInvoiceDomainMapper = this._registry.getDomainMapper({
|
const mapper: ICustomerInvoiceDomainMapper = this._registry.getDomainMapper({
|
||||||
resource: "customer-invoice",
|
resource: "customer-invoice",
|
||||||
});
|
});
|
||||||
const dto = mapper.mapToPersistence(invoice);
|
const dtoResult = mapper.mapToPersistence(invoice);
|
||||||
|
|
||||||
if (dto.isFailure) {
|
console.log("DTO to persist:", dtoResult);
|
||||||
return Result.fail(dto.error);
|
|
||||||
|
if (dtoResult.isFailure) {
|
||||||
|
return Result.fail(dtoResult.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data } = dto;
|
const dto = dtoResult.data;
|
||||||
|
const { id, items, taxes, verifactu, ...createPayload } = dto;
|
||||||
|
|
||||||
await CustomerInvoiceModel.create(data, {
|
// 1. Insertar cabecera
|
||||||
include: [{ all: true }],
|
await CustomerInvoiceModel.create(
|
||||||
transaction,
|
{
|
||||||
});
|
...createPayload,
|
||||||
|
id,
|
||||||
|
},
|
||||||
|
{ transaction }
|
||||||
|
);
|
||||||
|
|
||||||
|
// 2. Inserta taxes de cabecera
|
||||||
|
if (Array.isArray(taxes) && taxes.length > 0) {
|
||||||
|
await CustomerInvoiceTaxModel.bulkCreate(taxes, { transaction });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Inserta items + sus taxes
|
||||||
|
if (Array.isArray(items) && items.length > 0) {
|
||||||
|
for (const item of items) {
|
||||||
|
const { taxes: itemTaxes, ...itemData } = item;
|
||||||
|
await CustomerInvoiceItemModel.create(itemData, { transaction });
|
||||||
|
|
||||||
|
if (Array.isArray(itemTaxes) && itemTaxes.length > 0) {
|
||||||
|
await CustomerInvoiceItemTaxModel.bulkCreate(itemTaxes, { transaction });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Inserta VerifactuRecord si existe
|
||||||
|
if (verifactu) {
|
||||||
|
await VerifactuRecordModel.create(verifactu, { transaction });
|
||||||
|
}
|
||||||
|
|
||||||
return Result.ok();
|
return Result.ok();
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user