.
This commit is contained in:
parent
ef3a9c3576
commit
debbb3f3dd
@ -1 +1,2 @@
|
||||
export * from "./Profile";
|
||||
export * from "./ProfileLogotype";
|
||||
|
||||
@ -8,6 +8,7 @@ import {
|
||||
Result,
|
||||
UniqueID,
|
||||
} from "@shared/contexts";
|
||||
import { DealerLogotype } from "./DealerLogotype";
|
||||
import { DealerStatus } from "./DealerStatus";
|
||||
|
||||
export interface IDealerProps {
|
||||
@ -18,6 +19,7 @@ export interface IDealerProps {
|
||||
additionalInfo: KeyValueMap;
|
||||
status: DealerStatus;
|
||||
currency: CurrencyData;
|
||||
logo: DealerLogotype;
|
||||
}
|
||||
|
||||
export interface IDealer {
|
||||
@ -29,6 +31,7 @@ export interface IDealer {
|
||||
additionalInfo: KeyValueMap;
|
||||
status: DealerStatus;
|
||||
currency: CurrencyData;
|
||||
logo: DealerLogotype;
|
||||
|
||||
getAcronym: () => string;
|
||||
}
|
||||
@ -69,6 +72,10 @@ export class Dealer extends AggregateRoot<IDealerProps> implements IDealer {
|
||||
return this.props.currency;
|
||||
}
|
||||
|
||||
get logo(): DealerLogotype {
|
||||
return this.props.logo;
|
||||
}
|
||||
|
||||
public getAcronym(): string {
|
||||
return this.props.name.getAcronym();
|
||||
}
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
import { ProfileLogotype } from "@/contexts/profile/domain";
|
||||
|
||||
export class DealerLogotype extends ProfileLogotype {}
|
||||
@ -1,3 +1,4 @@
|
||||
export * from "./Dealer";
|
||||
export * from "./DealerLogotype";
|
||||
export * from "./DealerRole";
|
||||
export * from "./DealerStatus";
|
||||
|
||||
@ -9,16 +9,15 @@ import puppeteer from "puppeteer";
|
||||
import report from "puppeteer-report";
|
||||
|
||||
export interface IReportQuoteReporter {
|
||||
toHTML: (quote: Quote, context: ISalesContext) => string;
|
||||
toHTML: (quote: Quote, context: ISalesContext) => Promise<string>;
|
||||
toPDF: (quote: Quote, context: ISalesContext) => Promise<Buffer>;
|
||||
}
|
||||
|
||||
// https://plnkr.co/edit/lWk6Yd?preview
|
||||
|
||||
export const ReportQuotePresenter: IReportQuoteReporter = {
|
||||
toHTML: (quote: Quote, context: ISalesContext): string => {
|
||||
const quote_dto = map(quote, context);
|
||||
//console.log(quote_dto);
|
||||
toHTML: async (quote: Quote, context: ISalesContext): Promise<string> => {
|
||||
const quote_dto = await map(quote, context);
|
||||
|
||||
// Obtener y compilar la plantilla HTML
|
||||
const templateHtml = readFileSync(
|
||||
@ -29,7 +28,7 @@ export const ReportQuotePresenter: IReportQuoteReporter = {
|
||||
},
|
||||
|
||||
toPDF: async (quote: Quote, context: ISalesContext): Promise<Buffer> => {
|
||||
const html = ReportQuotePresenter.toHTML(quote, context);
|
||||
const html = await ReportQuotePresenter.toHTML(quote, context);
|
||||
|
||||
// Generar el PDF con Puppeteer
|
||||
const browser = await puppeteer.launch({
|
||||
@ -62,7 +61,7 @@ export const ReportQuotePresenter: IReportQuoteReporter = {
|
||||
},
|
||||
};
|
||||
|
||||
const map = (quote: Quote, context: ISalesContext) => {
|
||||
const map = async (quote: Quote, context: ISalesContext) => {
|
||||
const { dealer } = context;
|
||||
|
||||
return {
|
||||
@ -103,6 +102,7 @@ const map = (quote: Quote, context: ISalesContext) => {
|
||||
default_notes: dealer?.additionalInfo.get("default_notes"),
|
||||
default_legal_terms: dealer?.additionalInfo.get("default_legal_terms"),
|
||||
default_quote_validity: dealer?.additionalInfo.get("default_quote_validity"),
|
||||
logo: await dealer?.logo.toBase64(),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@ -56,7 +56,7 @@
|
||||
</div>
|
||||
</aside>
|
||||
<section class="flex pb-2 space-x-4">
|
||||
<img id="dealer-logo" src="https://via.placeholder.com/200x100" alt="Logo distribuidor" />
|
||||
<img id="dealer-logo" src={{dealer.logo}} alt="Logo distribuidor" />
|
||||
<address class="text-base not-italic font-medium whitespace-pre-line" id="from">{{dealer.contact_information}}
|
||||
</address>
|
||||
</section>
|
||||
|
||||
@ -4,7 +4,7 @@ import {
|
||||
SequelizeMapper,
|
||||
} from "@/contexts/common/infrastructure";
|
||||
import { CurrencyData, KeyValueMap, Language, Name, UniqueID } from "@shared/contexts";
|
||||
import { Dealer, DealerStatus, IDealerProps } from "../../domain/entities";
|
||||
import { Dealer, DealerLogotype, DealerStatus, IDealerProps } from "../../domain/entities";
|
||||
import { ISalesContext } from "../Sales.context";
|
||||
import { DealerCreationAttributes, Dealer_Model } from "../sequelize";
|
||||
|
||||
@ -25,6 +25,7 @@ class DealerMapper
|
||||
const status = this.mapsValue(source, "status", DealerStatus.create);
|
||||
const language = this.mapsValue(source, "lang_code", Language.createFromCode);
|
||||
const currency = this.mapsValue(source, "currency_code", CurrencyData.createFromCode);
|
||||
const logo = this.mapsValue(source, "logo", DealerLogotype.create);
|
||||
|
||||
const additionalInfoOrError = KeyValueMap.create([
|
||||
["contact_information", source.contact_information],
|
||||
@ -43,6 +44,7 @@ class DealerMapper
|
||||
language,
|
||||
currency,
|
||||
additionalInfo: additionalInfoOrError.object,
|
||||
logo,
|
||||
};
|
||||
|
||||
const id = this.mapsValue(source, "id", UniqueID.create);
|
||||
@ -71,6 +73,7 @@ class DealerMapper
|
||||
default_legal_terms: source.additionalInfo.get("default_legal_terms")?.toString() ?? "",
|
||||
default_quote_validity: source.additionalInfo.get("default_quote_validity")?.toString() ?? "",
|
||||
default_tax: Number(source.additionalInfo.get("default_tax") ?? 0),
|
||||
logo: source.logo.toPrimitive(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user