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