@silexpert/core 1.0.81 → 1.0.82

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@ export interface IBalanceSheet {
6
6
  state: number;
7
7
  dateBalanceSend: Date | null;
8
8
  deadline: Date | null;
9
+ bankCollectingState: number;
9
10
  idExercice: number;
10
11
  idCalendarEvent: number | null;
11
12
  createdAt?: Date | null;
@@ -1 +1 @@
1
- {"version":3,"file":"IBalanceSheet.d.ts","sourceRoot":"","sources":["../../../../ts/types/Interface/models/IBalanceSheet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,MAAM,WAAW,aAAa;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,IAAI,GAAG,IAAI,CAAC;IAC7B,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACxB,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IAGxB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B,WAAW,EAAE,YAAY,CAAC;CAC3B"}
1
+ {"version":3,"file":"IBalanceSheet.d.ts","sourceRoot":"","sources":["../../../../ts/types/Interface/models/IBalanceSheet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,MAAM,WAAW,aAAa;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,IAAI,GAAG,IAAI,CAAC;IAC7B,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACxB,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IAGxB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B,WAAW,EAAE,YAAY,CAAC;CAC3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"IBalanceSheet.js","sourceRoot":"","sources":["../../../../ts/types/Interface/models/IBalanceSheet.ts"],"names":[],"mappings":"","sourcesContent":["import { IExercice } from './IExercice';\nimport { ICalendarEvent } from './ICalendarEvent';\nimport { ISupervision } from './ISupervision';\n\n// balanceSheet\nexport interface IBalanceSheet {\n id?: number;\n state: number;\n dateBalanceSend: Date | null;\n deadline: Date | null;\n idExercice: number;\n idCalendarEvent: number | null;\n createdAt?: Date | null;\n updatedAt?: Date | null;\n\n // Associations\n exercice?: IExercice;\n calendarEvent?: ICalendarEvent;\n supervision: ISupervision;\n}\n"]}
1
+ {"version":3,"file":"IBalanceSheet.js","sourceRoot":"","sources":["../../../../ts/types/Interface/models/IBalanceSheet.ts"],"names":[],"mappings":"","sourcesContent":["import { IExercice } from './IExercice';\nimport { ICalendarEvent } from './ICalendarEvent';\nimport { ISupervision } from './ISupervision';\n\n// balanceSheet\nexport interface IBalanceSheet {\n id?: number;\n state: number;\n dateBalanceSend: Date | null;\n deadline: Date | null;\n bankCollectingState: number;\n idExercice: number;\n idCalendarEvent: number | null;\n createdAt?: Date | null;\n updatedAt?: Date | null;\n\n // Associations\n exercice?: IExercice;\n calendarEvent?: ICalendarEvent;\n supervision: ISupervision;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../../ts/utils/commercialManagement/document.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,8BAA8B,EAAuB,MAAM,qDAAqD,CAAC;AAI1H,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAOvE,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAK3E,wBAAgB,0BAA0B,CAAC,qBAAqB,EAAE,mBAAmB,EAAE,OAAO,EAAE,qBAAqB,GAAG,qBAAqB,GAAG,8BAA8B,CAoD7K;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,qBAAqB,GAAG,8BAA8B,CA6CtG"}
1
+ {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../../ts/utils/commercialManagement/document.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,8BAA8B,EAAuB,MAAM,qDAAqD,CAAC;AAI1H,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAOvE,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAK3E,wBAAgB,0BAA0B,CAAC,qBAAqB,EAAE,mBAAmB,EAAE,OAAO,EAAE,qBAAqB,GAAG,qBAAqB,GAAG,8BAA8B,CA0D7K;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,qBAAqB,GAAG,8BAA8B,CAmDtG"}
@@ -11,11 +11,11 @@ import { vatToReadVatEditing } from './vat';
11
11
  import { thirdPartyToReadThirdPartyEditing } from './thirdParty';
12
12
  const ejs = require('ejs');
13
13
  export function generateCommercialDocument(idEstimateInvoiceType, payload) {
14
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
14
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
15
15
  const products = _orderBy(payload.products.map((product) => productToReadProductEditing(product), 'reorder'));
16
16
  const vats = _orderBy(Object.values(_groupBy(products, 'vatFormatted')).map((v) => (vatToReadVatEditing(v)), 'value')).filter((v) => v.id !== Vat.MARGE.id);
17
17
  const thirdParty = thirdPartyToReadThirdPartyEditing(payload.thirdParty);
18
- const data = Object.assign(Object.assign({}, payload), { thirdParty, paymentLink: (_a = payload.paymentLink) !== null && _a !== void 0 ? _a : '#', idEstimateInvoiceType, title: (_b = payload.title) !== null && _b !== void 0 ? _b : null, penalties: (_c = payload.penalties) !== null && _c !== void 0 ? _c : null, compensation: (_d = payload.compensation) !== null && _d !== void 0 ? _d : null, discount: (_e = payload.discount) !== null && _e !== void 0 ? _e : null, vatMention: (_f = payload.vatMention) !== null && _f !== void 0 ? _f : null, phoneContact: (_h = (_g = payload.settings) === null || _g === void 0 ? void 0 : _g.phoneContact) !== null && _h !== void 0 ? _h : null, comment: payload.comment && typeof payload.comment === 'string' ? payload.comment.replace(/\n/g, '<br/>') : payload.comment, products,
18
+ const data = Object.assign(Object.assign({}, payload), { thirdParty, paymentLink: (_a = payload.paymentLink) !== null && _a !== void 0 ? _a : '#', idEstimateInvoiceType, title: (_b = payload.title) !== null && _b !== void 0 ? _b : null, penalties: (_c = payload.penalties) !== null && _c !== void 0 ? _c : null, compensation: (_d = payload.compensation) !== null && _d !== void 0 ? _d : null, discount: (_e = payload.discount) !== null && _e !== void 0 ? _e : null, vatMention: (_f = payload.vatMention) !== null && _f !== void 0 ? _f : null, phoneContact: (_h = (_g = payload.settings) === null || _g === void 0 ? void 0 : _g.phoneContact) !== null && _h !== void 0 ? _h : null, products,
19
19
  vats, totalTaxExcluded: _sumBy(products, 'totalTaxExcluded'), totalTaxIncluded: _sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount'), totalTaxAndDiscountIncluded: _sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount'), generalDiscountFormatted: payload.generalDiscount2 ? integerToFormattedAmountString(payload.generalDiscount2) : null, depositFormatted: payload.deposit ? integerToFormattedAmountString(payload.deposit) : null, totalTaxExcludedFormatted: integerToFormattedAmountString(_sumBy(products, 'totalTaxExcluded')), totalTaxIncludedFormatted: integerToFormattedAmountString(_sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount')), totalTaxAndDiscountIncludedFormatted: integerToFormattedAmountString(_sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount') - ((_j = payload.generalDiscount2) !== null && _j !== void 0 ? _j : 0) - ((_k = payload.deposit) !== null && _k !== void 0 ? _k : 0)), totalVatAmountFormatted: integerToFormattedAmountString(_sumBy(vats, 'amount')), font: {
20
20
  id: (_m = (_l = payload.settings) === null || _l === void 0 ? void 0 : _l.idFont) !== null && _m !== void 0 ? _m : FontIds.CIRCULAR_STD,
21
21
  name: (_p = (_o = fontList.find((f) => { var _a; return f.id === ((_a = payload.settings) === null || _a === void 0 ? void 0 : _a.idFont); })) === null || _o === void 0 ? void 0 : _o.name) !== null && _p !== void 0 ? _p : fontList[0].name,
@@ -27,16 +27,19 @@ export function generateCommercialDocument(idEstimateInvoiceType, payload) {
27
27
  const documentFreeText = [EstimateInvoiceType.DEVIS, EstimateInvoiceType.BON].includes(idEstimateInvoiceType) ? (_u = payload === null || payload === void 0 ? void 0 : payload.settings) === null || _u === void 0 ? void 0 : _u.freeEstimateText : (_v = payload === null || payload === void 0 ? void 0 : payload.settings) === null || _v === void 0 ? void 0 : _v.freeInvoiceText;
28
28
  return {
29
29
  header: ejs.render(commonTemplate.header, data),
30
- body: ejs.render(bodyTemplate, data),
30
+ body: ejs.render(bodyTemplate, Object.assign(Object.assign({}, data), { comment: data.comment && typeof data.comment === 'string' ? (_w = data.comment) === null || _w === void 0 ? void 0 : _w.replace(/\n/g, '<br/>') : null, products: data.products.map((p) => {
31
+ var _a;
32
+ return (Object.assign(Object.assign({}, p), { comment: p.comment && typeof p.comment === 'string' ? (_a = p.comment) === null || _a === void 0 ? void 0 : _a.replace(/\n/g, '<br/>') : null }));
33
+ }) })),
31
34
  footer: ejs.render(commonTemplate.footer, Object.assign(Object.assign({}, data), { freeText: documentFreeText !== null && documentFreeText !== void 0 ? documentFreeText : null })),
32
35
  data,
33
36
  };
34
37
  }
35
38
  export function generateAdvanceDocument(payload) {
36
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
39
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
37
40
  if (!payload.deposit)
38
41
  throw new Error('Aucun acompte défini');
39
- const data = Object.assign(Object.assign({}, payload), { title: (_a = payload.title) !== null && _a !== void 0 ? _a : null, paymentLink: (_b = payload.paymentLink) !== null && _b !== void 0 ? _b : '#', idEstimateInvoiceType: EstimateInvoiceType.ACOMPTE, phoneContact: (_d = (_c = payload.settings) === null || _c === void 0 ? void 0 : _c.phoneContact) !== null && _d !== void 0 ? _d : null, products: [], vats: [], totalTaxExcluded: payload.deposit, totalTaxIncluded: payload.deposit, totalTaxAndDiscountIncluded: payload.deposit, generalDiscountFormatted: null, comment: payload.comment && typeof payload.comment === 'string' ? payload.comment.replace(/\n/g, '<br/>') : payload.comment, depositFormatted: integerToFormattedAmountString(payload.deposit), totalTaxExcludedFormatted: integerToFormattedAmountString(payload.deposit), totalTaxIncludedFormatted: integerToFormattedAmountString(payload.deposit), totalTaxAndDiscountIncludedFormatted: integerToFormattedAmountString(payload.deposit), totalVatAmountFormatted: integerToFormattedAmountString(0), font: {
42
+ const data = Object.assign(Object.assign({}, payload), { title: (_a = payload.title) !== null && _a !== void 0 ? _a : null, paymentLink: (_b = payload.paymentLink) !== null && _b !== void 0 ? _b : '#', idEstimateInvoiceType: EstimateInvoiceType.ACOMPTE, phoneContact: (_d = (_c = payload.settings) === null || _c === void 0 ? void 0 : _c.phoneContact) !== null && _d !== void 0 ? _d : null, products: [], vats: [], totalTaxExcluded: payload.deposit, totalTaxIncluded: payload.deposit, totalTaxAndDiscountIncluded: payload.deposit, generalDiscountFormatted: null, depositFormatted: integerToFormattedAmountString(payload.deposit), totalTaxExcludedFormatted: integerToFormattedAmountString(payload.deposit), totalTaxIncludedFormatted: integerToFormattedAmountString(payload.deposit), totalTaxAndDiscountIncludedFormatted: integerToFormattedAmountString(payload.deposit), totalVatAmountFormatted: integerToFormattedAmountString(0), font: {
40
43
  id: (_f = (_e = payload.settings) === null || _e === void 0 ? void 0 : _e.idFont) !== null && _f !== void 0 ? _f : FontIds.CIRCULAR_STD,
41
44
  name: (_h = (_g = fontList.find((f) => { var _a; return f.id === ((_a = payload.settings) === null || _a === void 0 ? void 0 : _a.idFont); })) === null || _g === void 0 ? void 0 : _g.name) !== null && _h !== void 0 ? _h : fontList[0].name,
42
45
  url: (_k = (_j = fontList.find((f) => { var _a; return f.id === ((_a = payload.settings) === null || _a === void 0 ? void 0 : _a.idFont); })) === null || _j === void 0 ? void 0 : _j.link) !== null && _k !== void 0 ? _k : fontList[0].link,
@@ -46,8 +49,11 @@ export function generateAdvanceDocument(payload) {
46
49
  const commonTemplate = new CommercialDocumentCommonHTML();
47
50
  return {
48
51
  header: ejs === null || ejs === void 0 ? void 0 : ejs.render(commonTemplate.header, data),
49
- body: ejs === null || ejs === void 0 ? void 0 : ejs.render(bodyTemplate, data),
50
- footer: ejs === null || ejs === void 0 ? void 0 : ejs.render(commonTemplate.footer, Object.assign(Object.assign({}, data), { freeText: (_q = (_p = payload === null || payload === void 0 ? void 0 : payload.settings) === null || _p === void 0 ? void 0 : _p.freeInvoiceText) !== null && _q !== void 0 ? _q : null })),
52
+ body: ejs === null || ejs === void 0 ? void 0 : ejs.render(bodyTemplate, Object.assign(Object.assign({}, data), { comment: data.comment && typeof data.comment === 'string' ? (_p = data.comment) === null || _p === void 0 ? void 0 : _p.replace(/\n/g, '<br/>') : null, products: data.products.map((p) => {
53
+ var _a;
54
+ return (Object.assign(Object.assign({}, p), { comment: p.comment && typeof p.comment === 'string' ? (_a = p.comment) === null || _a === void 0 ? void 0 : _a.replace(/\n/g, '<br/>') : null }));
55
+ }) })),
56
+ footer: ejs === null || ejs === void 0 ? void 0 : ejs.render(commonTemplate.footer, Object.assign(Object.assign({}, data), { freeText: (_r = (_q = payload === null || payload === void 0 ? void 0 : payload.settings) === null || _q === void 0 ? void 0 : _q.freeInvoiceText) !== null && _r !== void 0 ? _r : null })),
51
57
  data,
52
58
  };
53
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"document.js","sourceRoot":"","sources":["../../../ts/utils/commercialManagement/document.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,IAAI,QAAQ,EAAE,OAAO,IAAI,QAAQ,EAAE,KAAK,IAAI,MAAM,EAAE,IAAI,IAAI,KAAK,GACzE,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EACL,sBAAsB,EAAE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,GAC/D,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,8BAA8B,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,iCAAiC,EAAE,MAAM,cAAc,CAAC;AAEjE,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;AAE3B,MAAM,UAAU,0BAA0B,CAAC,qBAA0C,EAAE,OAAsD;;IAC3I,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,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AC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,EACrG,2BAA2B,EAAE,KAAK,EAClC,UAAU,EAAE,IAAI;QAChB,aAAa;QACb,UAAU,EAAE,KAAK,CAAC,CAAC,MAAA,OAAO,CAAC,iBAAiB,mCAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,eAAC,OAAA,MAAA,MAAA,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,0CAAE,KAAK,mCAAI,IAAI,CAAA,EAAA,CAAC,CAAC,EAC3H,2BAA2B,EAAE,MAAA,MAAA,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC,kBAAkB,CAAC,0CAAE,KAAK,mCAAI,IAAI,GACpH,CAAC;IAEF,MAAM,cAAc,GAAG,IAAI,4BAA4B,EAAE,CAAC;IAE1D,OAAO;QACL,MAAM,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC;QAChD,IAAI,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,CAAC,YAAY,EAAE,IAAI,CAAC;QACrC,MAAM,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,CAAC,cAAc,CAAC,MAAM,kCAAO,IAAI,KAAE,QAAQ,EAAE,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,0CAAE,eAAe,mCAAI,IAAI,IAAG;QAC7G,IAAI;KACL,CAAC;AACJ,CAAC","sourcesContent":["import {\n orderBy as _orderBy, groupBy as _groupBy, sumBy as _sumBy, uniq as _uniq,\n} from 'lodash';\nimport * as dayjs from 'dayjs';\nimport { ReadCommercialDocumentTemplate, ReadDocumentEditing } from '../../types/Interface/api/commercialManagement/Read';\nimport {\n AccountingCategoryList, FontIds, fontList, VatMarginCategyList,\n} from '../../types/Enum/CommercialManagement';\nimport { EstimateInvoiceType } from '../../types/Enum/EstimateInvoice';\nimport { Vat } from '../../types/Enum/Vat';\nimport { integerToFormattedAmountString } from '../amount';\nimport { CommercialDocumentCommonHTML } from './templates/common';\nimport { bodyTemplate } from './templates/body';\nimport { productToReadProductEditing } from './product';\nimport { vatToReadVatEditing } from './vat';\nimport { CreateInvoiceDocument, CreatePreSaleDocument } from '../../types';\nimport { thirdPartyToReadThirdPartyEditing } from './thirdParty';\n\nconst ejs = require('ejs');\n\nexport function generateCommercialDocument(idEstimateInvoiceType: EstimateInvoiceType, payload: CreateInvoiceDocument | CreatePreSaleDocument): ReadCommercialDocumentTemplate {\n const products = _orderBy(payload.products.map((product) => productToReadProductEditing(product), 'reorder'));\n const vats = _orderBy(Object.values(_groupBy(products, 'vatFormatted')).map((v) => (vatToReadVatEditing(v)), 'value')).filter((v) => v.id !== Vat.MARGE.id);\n const thirdParty = thirdPartyToReadThirdPartyEditing(payload.thirdParty);\n\n const data: ReadDocumentEditing = {\n ...payload,\n thirdParty,\n paymentLink: payload.paymentLink ?? '#',\n idEstimateInvoiceType,\n title: payload.title ?? null,\n penalties: payload.penalties ?? null,\n compensation: payload.compensation ?? null,\n discount: payload.discount ?? null,\n vatMention: payload.vatMention ?? null,\n phoneContact: payload.settings?.phoneContact ?? null,\n comment: payload.comment && typeof payload.comment === 'string' ? payload.comment.replace(/\\n/g, '<br/>') : payload.comment,\n products,\n vats,\n totalTaxExcluded: _sumBy(products, 'totalTaxExcluded'),\n totalTaxIncluded: _sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount'),\n totalTaxAndDiscountIncluded: _sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount'),\n generalDiscountFormatted: payload.generalDiscount2 ? integerToFormattedAmountString(payload.generalDiscount2) : null,\n depositFormatted: payload.deposit ? integerToFormattedAmountString(payload.deposit) : null,\n totalTaxExcludedFormatted: integerToFormattedAmountString(_sumBy(products, 'totalTaxExcluded')),\n totalTaxIncludedFormatted: integerToFormattedAmountString(_sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount')),\n totalTaxAndDiscountIncludedFormatted: integerToFormattedAmountString(_sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount') - (payload.generalDiscount2 ?? 0) - (payload.deposit ?? 0)),\n totalVatAmountFormatted: integerToFormattedAmountString(_sumBy(vats, 'amount')),\n font: {\n id: payload.settings?.idFont ?? FontIds.CIRCULAR_STD,\n name: fontList.find((f) => f.id === payload.settings?.idFont)?.name ?? fontList[0].name,\n url: fontList.find((f) => f.id === payload.settings?.idFont)?.link ?? fontList[0].link,\n },\n capitalFormatted: payload.capital ? `${payload.capital}`.split('').reduceRight((acc, char, i, { length }) => `${char}${(length - (i + 1)) % 3 === 0 ? ' ' : ''}${acc}`, '').trim() : null,\n dueDateFormatted: payload.dueDate ? dayjs(payload.dueDate).format('DD/MM/YYYY') : null,\n expirationDateFormatted: payload.expirationDate ? dayjs(payload.expirationDate).format('DD/MM/YYYY') : null,\n emissionDateFormatted: payload.emissionDate ? dayjs(payload.emissionDate).format('DD/MM/YYYY') : null,\n shouldDisplayDiscountColumn: !!products.find((p) => p.discount2 && p.discount2 > 0),\n // @ts-ignore\n marginVats: _uniq(products.filter((p) => p.marginVatFormatted !== null).map((p) => p.marginVatFormatted)),\n accountingCategoryFormatted: AccountingCategoryList.find((a) => a.id === payload.accountingCategory)?.label ?? null,\n };\n\n const commonTemplate = new CommercialDocumentCommonHTML();\n const documentFreeText = [EstimateInvoiceType.DEVIS, EstimateInvoiceType.BON].includes(idEstimateInvoiceType) ? payload?.settings?.freeEstimateText : payload?.settings?.freeInvoiceText;\n\n return {\n header: ejs.render(commonTemplate.header, data),\n body: ejs.render(bodyTemplate, data),\n footer: ejs.render(commonTemplate.footer, { ...data, freeText: documentFreeText ?? null }),\n data,\n };\n}\n\nexport function generateAdvanceDocument(payload: CreateInvoiceDocument): ReadCommercialDocumentTemplate {\n if (!payload.deposit) throw new Error('Aucun acompte défini');\n\n const data: ReadDocumentEditing = {\n ...payload,\n title: payload.title ?? null,\n paymentLink: payload.paymentLink ?? '#',\n idEstimateInvoiceType: EstimateInvoiceType.ACOMPTE,\n phoneContact: payload.settings?.phoneContact ?? null,\n products: [],\n vats: [],\n totalTaxExcluded: payload.deposit,\n totalTaxIncluded: payload.deposit,\n totalTaxAndDiscountIncluded: payload.deposit,\n generalDiscountFormatted: null,\n comment: payload.comment && typeof payload.comment === 'string' ? payload.comment.replace(/\\n/g, '<br/>') : payload.comment,\n depositFormatted: integerToFormattedAmountString(payload.deposit),\n totalTaxExcludedFormatted: integerToFormattedAmountString(payload.deposit),\n totalTaxIncludedFormatted: integerToFormattedAmountString(payload.deposit),\n totalTaxAndDiscountIncludedFormatted: integerToFormattedAmountString(payload.deposit),\n totalVatAmountFormatted: integerToFormattedAmountString(0),\n font: {\n id: payload.settings?.idFont ?? FontIds.CIRCULAR_STD,\n name: fontList.find((f) => f.id === payload.settings?.idFont)?.name ?? fontList[0].name,\n url: fontList.find((f) => f.id === payload.settings?.idFont)?.link ?? fontList[0].link,\n },\n capitalFormatted: payload.capital ? `${payload.capital}`.split('').reduceRight((acc, char, i, { length }) => `${char}${(length - (i + 1)) % 3 === 0 ? ' ' : ''}${acc}`, '').trim() : null,\n dueDateFormatted: payload.dueDate ? dayjs(payload.dueDate).format('DD/MM/YYYY') : null,\n expirationDateFormatted: payload.expirationDate ? dayjs(payload.expirationDate).format('DD/MM/YYYY') : null,\n emissionDateFormatted: payload.emissionDate ? dayjs(payload.emissionDate).format('DD/MM/YYYY') : null,\n shouldDisplayDiscountColumn: false,\n disableVat: true,\n // @ts-ignore\n marginVats: _uniq((payload.assetMarginVatIds ?? []).map((m) => VatMarginCategyList.find((c) => c.id === m)?.label ?? null)),\n accountingCategoryFormatted: AccountingCategoryList.find((a) => a.id === payload.accountingCategory)?.label ?? null,\n };\n\n const commonTemplate = new CommercialDocumentCommonHTML();\n\n return {\n header: ejs?.render(commonTemplate.header, data),\n body: ejs?.render(bodyTemplate, data),\n footer: ejs?.render(commonTemplate.footer, { ...data, freeText: payload?.settings?.freeInvoiceText ?? null }),\n data,\n };\n}"]}
1
+ {"version":3,"file":"document.js","sourceRoot":"","sources":["../../../ts/utils/commercialManagement/document.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,IAAI,QAAQ,EAAE,OAAO,IAAI,QAAQ,EAAE,KAAK,IAAI,MAAM,EAAE,IAAI,IAAI,KAAK,GACzE,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EACL,sBAAsB,EAAE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,GAC/D,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,8BAA8B,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,iCAAiC,EAAE,MAAM,cAAc,CAAC;AAEjE,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;AAE3B,MAAM,UAAU,0BAA0B,CAAC,qBAA0C,EAAE,OAAsD;;IAC3I,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,2BAA2B,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;IAC9G,MAAM,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CAAC,CAAC,OAAO,0CAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,IAC/F,CAAA;aAAA,CAAC,IACH;QACF,MAAM,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,CAAC,cAAc,CAAC,MAAM,kCAAO,IAAI,KAAE,QAAQ,EAAE,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,0CAAE,eAAe,mCAAI,IAAI,IAAG;QAC7G,IAAI;KACL,CAAC;AACJ,CAAC","sourcesContent":["import {\n orderBy as _orderBy, groupBy as _groupBy, sumBy as _sumBy, uniq as _uniq,\n} from 'lodash';\nimport * as dayjs from 'dayjs';\nimport { ReadCommercialDocumentTemplate, ReadDocumentEditing } from '../../types/Interface/api/commercialManagement/Read';\nimport {\n AccountingCategoryList, FontIds, fontList, VatMarginCategyList,\n} from '../../types/Enum/CommercialManagement';\nimport { EstimateInvoiceType } from '../../types/Enum/EstimateInvoice';\nimport { Vat } from '../../types/Enum/Vat';\nimport { integerToFormattedAmountString } from '../amount';\nimport { CommercialDocumentCommonHTML } from './templates/common';\nimport { bodyTemplate } from './templates/body';\nimport { productToReadProductEditing } from './product';\nimport { vatToReadVatEditing } from './vat';\nimport { CreateInvoiceDocument, CreatePreSaleDocument } from '../../types';\nimport { thirdPartyToReadThirdPartyEditing } from './thirdParty';\n\nconst ejs = require('ejs');\n\nexport function generateCommercialDocument(idEstimateInvoiceType: EstimateInvoiceType, payload: CreateInvoiceDocument | CreatePreSaleDocument): ReadCommercialDocumentTemplate {\n const products = _orderBy(payload.products.map((product) => productToReadProductEditing(product), 'reorder'));\n const vats = _orderBy(Object.values(_groupBy(products, 'vatFormatted')).map((v) => (vatToReadVatEditing(v)), 'value')).filter((v) => v.id !== Vat.MARGE.id);\n const thirdParty = thirdPartyToReadThirdPartyEditing(payload.thirdParty);\n\n const data: ReadDocumentEditing = {\n ...payload,\n thirdParty,\n paymentLink: payload.paymentLink ?? '#',\n idEstimateInvoiceType,\n title: payload.title ?? null,\n penalties: payload.penalties ?? null,\n compensation: payload.compensation ?? null,\n discount: payload.discount ?? null,\n vatMention: payload.vatMention ?? null,\n phoneContact: payload.settings?.phoneContact ?? null,\n products,\n vats,\n totalTaxExcluded: _sumBy(products, 'totalTaxExcluded'),\n totalTaxIncluded: _sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount'),\n totalTaxAndDiscountIncluded: _sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount'),\n generalDiscountFormatted: payload.generalDiscount2 ? integerToFormattedAmountString(payload.generalDiscount2) : null,\n depositFormatted: payload.deposit ? integerToFormattedAmountString(payload.deposit) : null,\n totalTaxExcludedFormatted: integerToFormattedAmountString(_sumBy(products, 'totalTaxExcluded')),\n totalTaxIncludedFormatted: integerToFormattedAmountString(_sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount')),\n totalTaxAndDiscountIncludedFormatted: integerToFormattedAmountString(_sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount') - (payload.generalDiscount2 ?? 0) - (payload.deposit ?? 0)),\n totalVatAmountFormatted: integerToFormattedAmountString(_sumBy(vats, 'amount')),\n font: {\n id: payload.settings?.idFont ?? FontIds.CIRCULAR_STD,\n name: fontList.find((f) => f.id === payload.settings?.idFont)?.name ?? fontList[0].name,\n url: fontList.find((f) => f.id === payload.settings?.idFont)?.link ?? fontList[0].link,\n },\n capitalFormatted: payload.capital ? `${payload.capital}`.split('').reduceRight((acc, char, i, { length }) => `${char}${(length - (i + 1)) % 3 === 0 ? ' ' : ''}${acc}`, '').trim() : null,\n dueDateFormatted: payload.dueDate ? dayjs(payload.dueDate).format('DD/MM/YYYY') : null,\n expirationDateFormatted: payload.expirationDate ? dayjs(payload.expirationDate).format('DD/MM/YYYY') : null,\n emissionDateFormatted: payload.emissionDate ? dayjs(payload.emissionDate).format('DD/MM/YYYY') : null,\n shouldDisplayDiscountColumn: !!products.find((p) => p.discount2 && p.discount2 > 0),\n // @ts-ignore\n marginVats: _uniq(products.filter((p) => p.marginVatFormatted !== null).map((p) => p.marginVatFormatted)),\n accountingCategoryFormatted: AccountingCategoryList.find((a) => a.id === payload.accountingCategory)?.label ?? null,\n };\n\n const commonTemplate = new CommercialDocumentCommonHTML();\n const documentFreeText = [EstimateInvoiceType.DEVIS, EstimateInvoiceType.BON].includes(idEstimateInvoiceType) ? payload?.settings?.freeEstimateText : payload?.settings?.freeInvoiceText;\n\n return {\n header: ejs.render(commonTemplate.header, data),\n body: ejs.render(bodyTemplate, {\n ...data,\n comment: data.comment && typeof data.comment === 'string' ? data.comment?.replace(/\\n/g, '<br/>') : null,\n products: data.products.map((p) => ({\n ...p,\n comment: p.comment && typeof p.comment === 'string' ? p.comment?.replace(/\\n/g, '<br/>') : null,\n })),\n }),\n footer: ejs.render(commonTemplate.footer, { ...data, freeText: documentFreeText ?? null }),\n data,\n };\n}\n\nexport function generateAdvanceDocument(payload: CreateInvoiceDocument): ReadCommercialDocumentTemplate {\n if (!payload.deposit) throw new Error('Aucun acompte défini');\n\n const data: ReadDocumentEditing = {\n ...payload,\n title: payload.title ?? null,\n paymentLink: payload.paymentLink ?? '#',\n idEstimateInvoiceType: EstimateInvoiceType.ACOMPTE,\n phoneContact: payload.settings?.phoneContact ?? null,\n products: [],\n vats: [],\n totalTaxExcluded: payload.deposit,\n totalTaxIncluded: payload.deposit,\n totalTaxAndDiscountIncluded: payload.deposit,\n generalDiscountFormatted: null,\n depositFormatted: integerToFormattedAmountString(payload.deposit),\n totalTaxExcludedFormatted: integerToFormattedAmountString(payload.deposit),\n totalTaxIncludedFormatted: integerToFormattedAmountString(payload.deposit),\n totalTaxAndDiscountIncludedFormatted: integerToFormattedAmountString(payload.deposit),\n totalVatAmountFormatted: integerToFormattedAmountString(0),\n font: {\n id: payload.settings?.idFont ?? FontIds.CIRCULAR_STD,\n name: fontList.find((f) => f.id === payload.settings?.idFont)?.name ?? fontList[0].name,\n url: fontList.find((f) => f.id === payload.settings?.idFont)?.link ?? fontList[0].link,\n },\n capitalFormatted: payload.capital ? `${payload.capital}`.split('').reduceRight((acc, char, i, { length }) => `${char}${(length - (i + 1)) % 3 === 0 ? ' ' : ''}${acc}`, '').trim() : null,\n dueDateFormatted: payload.dueDate ? dayjs(payload.dueDate).format('DD/MM/YYYY') : null,\n expirationDateFormatted: payload.expirationDate ? dayjs(payload.expirationDate).format('DD/MM/YYYY') : null,\n emissionDateFormatted: payload.emissionDate ? dayjs(payload.emissionDate).format('DD/MM/YYYY') : null,\n shouldDisplayDiscountColumn: false,\n disableVat: true,\n // @ts-ignore\n marginVats: _uniq((payload.assetMarginVatIds ?? []).map((m) => VatMarginCategyList.find((c) => c.id === m)?.label ?? null)),\n accountingCategoryFormatted: AccountingCategoryList.find((a) => a.id === payload.accountingCategory)?.label ?? null,\n };\n\n const commonTemplate = new CommercialDocumentCommonHTML();\n\n return {\n header: ejs?.render(commonTemplate.header, data),\n body: ejs?.render(bodyTemplate, {\n ...data,\n comment: data.comment && typeof data.comment === 'string' ? data.comment?.replace(/\\n/g, '<br/>') : null,\n products: data.products.map((p) => ({\n ...p,\n comment: p.comment && typeof p.comment === 'string' ? p.comment?.replace(/\\n/g, '<br/>') : null,\n })),\n }),\n footer: ejs?.render(commonTemplate.footer, { ...data, freeText: payload?.settings?.freeInvoiceText ?? null }),\n data,\n };\n}"]}
@@ -1 +1 @@
1
- {"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../../ts/utils/commercialManagement/product.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAMlE,wBAAgB,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAU5D;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAGpE;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,eAAe,GAAG,kBAAkB,CAaxF"}
1
+ {"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../../ts/utils/commercialManagement/product.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAMlE,wBAAgB,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAU5D;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAGpE;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,eAAe,GAAG,kBAAkB,CAYxF"}
@@ -22,6 +22,6 @@ export function getTotalTaxExcluded(product) {
22
22
  }
23
23
  export function productToReadProductEditing(payload) {
24
24
  var _a, _b, _c, _d, _e, _f;
25
- return Object.assign(Object.assign({}, payload), { comment: payload.comment && typeof payload.comment === 'string' ? payload.comment.replace(/\n/g, '<br/>') : payload.comment, totalTaxExcluded: getTotalTaxExcluded(payload), unitFormatted: (_b = (_a = Object.values(Unit).find((unit) => unit.id === payload.unit)) === null || _a === void 0 ? void 0 : _a.shortName) !== null && _b !== void 0 ? _b : '', vatFormatted: (_d = (_c = getById(payload.idVat)) === null || _c === void 0 ? void 0 : _c.saleName) !== null && _d !== void 0 ? _d : '', priceTaxExcludedFormatted: isDefined(payload.priceTaxExcluded) ? integerToFormattedAmountString(payload.priceTaxExcluded) : null, totalTaxExcludedFormatted: isDefined(payload.priceTaxExcluded) ? integerToFormattedAmountString(getTotalTaxExcluded(payload)) : null, discountFormatted: payload.discount2 && payload.discount2 > 0 ? integerToFormattedAmountString(getDiscount(payload)) : null, discountTypeFormatted: payload.discount2 && payload.discount2 > 0 ? payload.discountType === DiscountType.PERCENT ? `${(payload.discount2 / 100).toFixed(2)}%` : `${integerToFormattedAmountString(payload.discount2)}€` : null, marginVatFormatted: payload.marginVatType ? (_f = (_e = VatMarginCategyList.find((c) => c.id === payload.marginVatType)) === null || _e === void 0 ? void 0 : _e.label) !== null && _f !== void 0 ? _f : null : null });
25
+ return Object.assign(Object.assign({}, payload), { totalTaxExcluded: getTotalTaxExcluded(payload), unitFormatted: (_b = (_a = Object.values(Unit).find((unit) => unit.id === payload.unit)) === null || _a === void 0 ? void 0 : _a.shortName) !== null && _b !== void 0 ? _b : '', vatFormatted: (_d = (_c = getById(payload.idVat)) === null || _c === void 0 ? void 0 : _c.saleName) !== null && _d !== void 0 ? _d : '', priceTaxExcludedFormatted: isDefined(payload.priceTaxExcluded) ? integerToFormattedAmountString(payload.priceTaxExcluded) : null, totalTaxExcludedFormatted: isDefined(payload.priceTaxExcluded) ? integerToFormattedAmountString(getTotalTaxExcluded(payload)) : null, discountFormatted: payload.discount2 && payload.discount2 > 0 ? integerToFormattedAmountString(getDiscount(payload)) : null, discountTypeFormatted: payload.discount2 && payload.discount2 > 0 ? payload.discountType === DiscountType.PERCENT ? `${(payload.discount2 / 100).toFixed(2)}%` : `${integerToFormattedAmountString(payload.discount2)}€` : null, marginVatFormatted: payload.marginVatType ? (_f = (_e = VatMarginCategyList.find((c) => c.id === payload.marginVatType)) === null || _e === void 0 ? void 0 : _e.label) !== null && _f !== void 0 ? _f : null : null });
26
26
  }
27
27
  //# sourceMappingURL=product.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"product.js","sourceRoot":"","sources":["../../../ts/utils/commercialManagement/product.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAC1F,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,8BAA8B,EAAE,MAAM,WAAW,CAAC;AAE3D,MAAM,UAAU,WAAW,CAAC,OAAwB;;IAClD,IAAI,OAAO,CAAC,SAAS,KAAK,IAAI,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,IAAI,OAAO,CAAC,SAAS,IAAI,CAAC;QAAE,OAAO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,CAAC,0CAAE,SAAS,mCAAI,EAAE,EAC5F,YAAY,EAAE,MAAA,MAAA,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,0CAAE,QAAQ,mCAAI,EAAE,EACpD,yBAAyB,EAAE,SAAS,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,8BAA8B,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,IAAI,EAChI,yBAAyB,EAAE,SAAS,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,8BAA8B,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EACpI,iBAAiB,EAAE,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,8BAA8B,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAC3H,qBAAqB,EAAE,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,KAAK,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,8BAA8B,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAC/N,kBAAkB,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,MAAA,MAAA,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC,aAAa,CAAC,0CAAE,KAAK,mCAAI,IAAI,CAAC,CAAC,CAAC,IAAI,IACjI;AACJ,CAAC","sourcesContent":["import { isDefined } from 'class-validator';\nimport { IProductInvoice, ReadProductEditing } from '../../types';\nimport { Unit } from '../../types/Enum/Unit';\nimport { DiscountType, VatMarginCategyList } from '../../types/Enum/CommercialManagement';\nimport { getById } from './vat';\nimport { integerToFormattedAmountString } from '../amount';\n\nexport function getDiscount(product: IProductInvoice): number {\n if (product.discount2 === null || product.discount2 === undefined || product.discount2 <= 0) return 0;\n\n if (product.discountType === DiscountType.PERCENT) {\n return ((product.priceTaxExcluded ?? 0) * ((product.discount2 ?? 0) / 100)) / 100;\n } if (product.discountType === DiscountType.AMOUNT) {\n return (product.discount2 ?? 0);\n }\n\n return 0;\n}\n\nexport function getTotalTaxExcluded(product: IProductInvoice): number {\n const discount = product.discount2 && product.discount2 > 0 ? getDiscount(product) : 0;\n return ((product.priceTaxExcluded ?? 0) - discount) * (product.quantity ?? 1);\n}\n\nexport function productToReadProductEditing(payload: IProductInvoice): ReadProductEditing {\n return {\n ...payload,\n comment: payload.comment && typeof payload.comment === 'string' ? payload.comment.replace(/\\n/g, '<br/>') : payload.comment,\n totalTaxExcluded: getTotalTaxExcluded(payload),\n unitFormatted: Object.values(Unit).find((unit) => unit.id === payload.unit)?.shortName ?? '',\n vatFormatted: getById(payload.idVat)?.saleName ?? '',\n priceTaxExcludedFormatted: isDefined(payload.priceTaxExcluded) ? integerToFormattedAmountString(payload.priceTaxExcluded) : null,\n totalTaxExcludedFormatted: isDefined(payload.priceTaxExcluded) ? integerToFormattedAmountString(getTotalTaxExcluded(payload)) : null,\n discountFormatted: payload.discount2 && payload.discount2 > 0 ? integerToFormattedAmountString(getDiscount(payload)) : null,\n discountTypeFormatted: payload.discount2 && payload.discount2 > 0 ? payload.discountType === DiscountType.PERCENT ? `${(payload.discount2 / 100).toFixed(2)}%` : `${integerToFormattedAmountString(payload.discount2)}€` : null,\n marginVatFormatted: payload.marginVatType ? VatMarginCategyList.find((c) => c.id === payload.marginVatType)?.label ?? null : null,\n };\n}"]}
1
+ {"version":3,"file":"product.js","sourceRoot":"","sources":["../../../ts/utils/commercialManagement/product.ts"],"names":[],"mappings":"AAAA,OAAO,EA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AAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC,aAAa,CAAC,0CAAE,KAAK,mCAAI,IAAI,CAAC,CAAC,CAAC,IAAI,IACjI;AACJ,CAAC","sourcesContent":["import { isDefined } from 'class-validator';\nimport { IProductInvoice, ReadProductEditing } from '../../types';\nimport { Unit } from '../../types/Enum/Unit';\nimport { DiscountType, VatMarginCategyList } from '../../types/Enum/CommercialManagement';\nimport { getById } from './vat';\nimport { integerToFormattedAmountString } from '../amount';\n\nexport function getDiscount(product: IProductInvoice): number {\n if (product.discount2 === null || product.discount2 === undefined || product.discount2 <= 0) return 0;\n\n if (product.discountType === DiscountType.PERCENT) {\n return ((product.priceTaxExcluded ?? 0) * ((product.discount2 ?? 0) / 100)) / 100;\n } if (product.discountType === DiscountType.AMOUNT) {\n return (product.discount2 ?? 0);\n }\n\n return 0;\n}\n\nexport function getTotalTaxExcluded(product: IProductInvoice): number {\n const discount = product.discount2 && product.discount2 > 0 ? getDiscount(product) : 0;\n return ((product.priceTaxExcluded ?? 0) - discount) * (product.quantity ?? 1);\n}\n\nexport function productToReadProductEditing(payload: IProductInvoice): ReadProductEditing {\n return {\n ...payload,\n totalTaxExcluded: getTotalTaxExcluded(payload),\n unitFormatted: Object.values(Unit).find((unit) => unit.id === payload.unit)?.shortName ?? '',\n vatFormatted: getById(payload.idVat)?.saleName ?? '',\n priceTaxExcludedFormatted: isDefined(payload.priceTaxExcluded) ? integerToFormattedAmountString(payload.priceTaxExcluded) : null,\n totalTaxExcludedFormatted: isDefined(payload.priceTaxExcluded) ? integerToFormattedAmountString(getTotalTaxExcluded(payload)) : null,\n discountFormatted: payload.discount2 && payload.discount2 > 0 ? integerToFormattedAmountString(getDiscount(payload)) : null,\n discountTypeFormatted: payload.discount2 && payload.discount2 > 0 ? payload.discountType === DiscountType.PERCENT ? `${(payload.discount2 / 100).toFixed(2)}%` : `${integerToFormattedAmountString(payload.discount2)}€` : null,\n marginVatFormatted: payload.marginVatType ? VatMarginCategyList.find((c) => c.id === payload.marginVatType)?.label ?? null : null,\n };\n}"]}
@@ -37,7 +37,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
37
37
  const ejs = require('ejs');
38
38
 
39
39
  function generateCommercialDocument(idEstimateInvoiceType, payload) {
40
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
40
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
41
41
 
42
42
  const products = (0, _lodash.orderBy)(payload.products.map(product => (0, _product.productToReadProductEditing)(product), 'reorder'));
43
43
  const vats = (0, _lodash.orderBy)(Object.values((0, _lodash.groupBy)(products, 'vatFormatted')).map(v => (0, _vat.vatToReadVatEditing)(v), 'value')).filter(v => v.id !== _Vat.Vat.MARGE.id);
@@ -52,7 +52,6 @@ function generateCommercialDocument(idEstimateInvoiceType, payload) {
52
52
  discount: (_e = payload.discount) !== null && _e !== void 0 ? _e : null,
53
53
  vatMention: (_f = payload.vatMention) !== null && _f !== void 0 ? _f : null,
54
54
  phoneContact: (_h = (_g = payload.settings) === null || _g === void 0 ? void 0 : _g.phoneContact) !== null && _h !== void 0 ? _h : null,
55
- comment: payload.comment && typeof payload.comment === 'string' ? payload.comment.replace(/\n/g, '<br/>') : payload.comment,
56
55
  products,
57
56
  vats,
58
57
  totalTaxExcluded: (0, _lodash.sumBy)(products, 'totalTaxExcluded'),
@@ -92,7 +91,16 @@ function generateCommercialDocument(idEstimateInvoiceType, payload) {
92
91
  const documentFreeText = [_EstimateInvoice.EstimateInvoiceType.DEVIS, _EstimateInvoice.EstimateInvoiceType.BON].includes(idEstimateInvoiceType) ? (_u = payload === null || payload === void 0 ? void 0 : payload.settings) === null || _u === void 0 ? void 0 : _u.freeEstimateText : (_v = payload === null || payload === void 0 ? void 0 : payload.settings) === null || _v === void 0 ? void 0 : _v.freeInvoiceText;
93
92
  return {
94
93
  header: ejs.render(commonTemplate.header, data),
95
- body: ejs.render(_body.bodyTemplate, data),
94
+ body: ejs.render(_body.bodyTemplate, Object.assign(Object.assign({}, data), {
95
+ comment: data.comment && typeof data.comment === 'string' ? (_w = data.comment) === null || _w === void 0 ? void 0 : _w.replace(/\n/g, '<br/>') : null,
96
+ products: data.products.map(p => {
97
+ var _a;
98
+
99
+ return Object.assign(Object.assign({}, p), {
100
+ comment: p.comment && typeof p.comment === 'string' ? (_a = p.comment) === null || _a === void 0 ? void 0 : _a.replace(/\n/g, '<br/>') : null
101
+ });
102
+ })
103
+ })),
96
104
  footer: ejs.render(commonTemplate.footer, Object.assign(Object.assign({}, data), {
97
105
  freeText: documentFreeText !== null && documentFreeText !== void 0 ? documentFreeText : null
98
106
  })),
@@ -101,7 +109,7 @@ function generateCommercialDocument(idEstimateInvoiceType, payload) {
101
109
  }
102
110
 
103
111
  function generateAdvanceDocument(payload) {
104
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
112
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
105
113
 
106
114
  if (!payload.deposit) throw new Error('Aucun acompte défini');
107
115
  const data = Object.assign(Object.assign({}, payload), {
@@ -115,7 +123,6 @@ function generateAdvanceDocument(payload) {
115
123
  totalTaxIncluded: payload.deposit,
116
124
  totalTaxAndDiscountIncluded: payload.deposit,
117
125
  generalDiscountFormatted: null,
118
- comment: payload.comment && typeof payload.comment === 'string' ? payload.comment.replace(/\n/g, '<br/>') : payload.comment,
119
126
  depositFormatted: (0, _amount.integerToFormattedAmountString)(payload.deposit),
120
127
  totalTaxExcludedFormatted: (0, _amount.integerToFormattedAmountString)(payload.deposit),
121
128
  totalTaxIncludedFormatted: (0, _amount.integerToFormattedAmountString)(payload.deposit),
@@ -153,9 +160,18 @@ function generateAdvanceDocument(payload) {
153
160
  const commonTemplate = new _common.CommercialDocumentCommonHTML();
154
161
  return {
155
162
  header: ejs === null || ejs === void 0 ? void 0 : ejs.render(commonTemplate.header, data),
156
- body: ejs === null || ejs === void 0 ? void 0 : ejs.render(_body.bodyTemplate, data),
163
+ body: ejs === null || ejs === void 0 ? void 0 : ejs.render(_body.bodyTemplate, Object.assign(Object.assign({}, data), {
164
+ comment: data.comment && typeof data.comment === 'string' ? (_p = data.comment) === null || _p === void 0 ? void 0 : _p.replace(/\n/g, '<br/>') : null,
165
+ products: data.products.map(p => {
166
+ var _a;
167
+
168
+ return Object.assign(Object.assign({}, p), {
169
+ comment: p.comment && typeof p.comment === 'string' ? (_a = p.comment) === null || _a === void 0 ? void 0 : _a.replace(/\n/g, '<br/>') : null
170
+ });
171
+ })
172
+ })),
157
173
  footer: ejs === null || ejs === void 0 ? void 0 : ejs.render(commonTemplate.footer, Object.assign(Object.assign({}, data), {
158
- freeText: (_q = (_p = payload === null || payload === void 0 ? void 0 : payload.settings) === null || _p === void 0 ? void 0 : _p.freeInvoiceText) !== null && _q !== void 0 ? _q : null
174
+ freeText: (_r = (_q = payload === null || payload === void 0 ? void 0 : payload.settings) === null || _q === void 0 ? void 0 : _q.freeInvoiceText) !== null && _r !== void 0 ? _r : null
159
175
  })),
160
176
  data
161
177
  };
@@ -1 +1 @@
1
- {"version":3,"file":"document.js","mappings":";;;;;QAoBgBA,0B,GAAAA,0B;QAsDAC,uB,GAAAA,uB;;AA1EhB;;AAGA;;IAAYC,K;;AAEZ;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;AAEA,MAAMC,GAAG,GAAGC,OAAO,CAAC,KAAD,CAAnB;;AAEM,SAAUJ,0BAAV,CAAqCK,qBAArC,EAAiFC,OAAjF,EAAuI;;;EAC3I,MAAMC,QAAQ,GAAG,qBAASD,OAAO,CAACC,QAAR,CAAiBC,GAAjB,CAAsBC,OAAD,IAAa,0CAA4BA,OAA5B,CAAlC,EAAwE,SAAxE,CAAT,CAAjB;EACA,MAAMC,IAAI,GAA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IAAlD,CAAX,CAAjC,CAHH;IAIL7C;EAJK,CAAP;AAMD","names":["generateCommercialDocument","generateAdvanceDocument","dayjs","ejs","require","idEstimateInvoiceType","payload","products","map","product","vats","Object","values","v","filter","id","Vat","MARGE","thirdParty","data","paymentLink","_a","title","_b","penalties","_c","compensation","_d","discount","_e","vatMention","_f","phoneContact","settings","_g","_h","comment","replace","totalTaxExcluded","totalTaxIncluded","totalTaxAndDiscountIncluded","generalDiscountFormatted","generalDiscount2","depositFormatted","deposit","totalTaxExcludedFormatted","totalTaxIncludedFormatted","totalTaxAndDiscountIncludedFormatted","_j","_k","totalVatAmountFormatted","font","_l","idFont","_m","FontIds","CIRCULAR_STD","name","find","f","_o","_p","fontList","url","_q","link","_r","capitalFormatted","capital","split","reduceRight","acc","char","i","length","trim","dueDateFormatted","dueDate","format","expirationDateFormatted","expirationDate","emissionDateFormatted","emissionDate","shouldDisplayDiscountColumn","p","discount2","marginVats","marginVatFormatted","accountingCategoryFormatted","a","accountingCategory","_s","label","_t","commonTemplate","CommercialDocumentCommonHTML","documentFreeText","EstimateInvoiceType","DEVIS","BON","includes","_u","freeEstimateText","_v","freeInvoiceText","header","render","body","bodyTemplate","footer","freeText","Error","ACOMPTE","disableVat","assetMarginVatIds","m","c"],"sourceRoot":"","sources":["../../../ts/utils/commercialManagement/document.ts"],"sourcesContent":["import {\n orderBy as _orderBy, groupBy as _groupBy, sumBy as _sumBy, uniq as _uniq,\n} from 'lodash';\nimport * as dayjs from 'dayjs';\nimport { ReadCommercialDocumentTemplate, ReadDocumentEditing } from '../../types/Interface/api/commercialManagement/Read';\nimport {\n AccountingCategoryList, FontIds, fontList, VatMarginCategyList,\n} from '../../types/Enum/CommercialManagement';\nimport { EstimateInvoiceType } from '../../types/Enum/EstimateInvoice';\nimport { Vat } from '../../types/Enum/Vat';\nimport { integerToFormattedAmountString } from '../amount';\nimport { CommercialDocumentCommonHTML } from './templates/common';\nimport { bodyTemplate } from './templates/body';\nimport { productToReadProductEditing } from './product';\nimport { vatToReadVatEditing } from './vat';\nimport { CreateInvoiceDocument, CreatePreSaleDocument } from '../../types';\nimport { thirdPartyToReadThirdPartyEditing } from './thirdParty';\n\nconst ejs = require('ejs');\n\nexport function generateCommercialDocument(idEstimateInvoiceType: EstimateInvoiceType, payload: CreateInvoiceDocument | CreatePreSaleDocument): ReadCommercialDocumentTemplate {\n const products = _orderBy(payload.products.map((product) => productToReadProductEditing(product), 'reorder'));\n const vats = _orderBy(Object.values(_groupBy(products, 'vatFormatted')).map((v) => (vatToReadVatEditing(v)), 'value')).filter((v) => v.id !== Vat.MARGE.id);\n const thirdParty = thirdPartyToReadThirdPartyEditing(payload.thirdParty);\n\n const data: ReadDocumentEditing = {\n ...payload,\n thirdParty,\n paymentLink: payload.paymentLink ?? '#',\n idEstimateInvoiceType,\n title: payload.title ?? null,\n penalties: payload.penalties ?? null,\n compensation: payload.compensation ?? null,\n discount: payload.discount ?? null,\n vatMention: payload.vatMention ?? null,\n phoneContact: payload.settings?.phoneContact ?? null,\n comment: payload.comment && typeof payload.comment === 'string' ? payload.comment.replace(/\\n/g, '<br/>') : payload.comment,\n products,\n vats,\n totalTaxExcluded: _sumBy(products, 'totalTaxExcluded'),\n totalTaxIncluded: _sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount'),\n totalTaxAndDiscountIncluded: _sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount'),\n generalDiscountFormatted: payload.generalDiscount2 ? integerToFormattedAmountString(payload.generalDiscount2) : null,\n depositFormatted: payload.deposit ? integerToFormattedAmountString(payload.deposit) : null,\n totalTaxExcludedFormatted: integerToFormattedAmountString(_sumBy(products, 'totalTaxExcluded')),\n totalTaxIncludedFormatted: integerToFormattedAmountString(_sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount')),\n totalTaxAndDiscountIncludedFormatted: integerToFormattedAmountString(_sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount') - (payload.generalDiscount2 ?? 0) - (payload.deposit ?? 0)),\n totalVatAmountFormatted: integerToFormattedAmountString(_sumBy(vats, 'amount')),\n font: {\n id: payload.settings?.idFont ?? FontIds.CIRCULAR_STD,\n name: fontList.find((f) => f.id === payload.settings?.idFont)?.name ?? fontList[0].name,\n url: fontList.find((f) => f.id === payload.settings?.idFont)?.link ?? fontList[0].link,\n },\n capitalFormatted: payload.capital ? `${payload.capital}`.split('').reduceRight((acc, char, i, { length }) => `${char}${(length - (i + 1)) % 3 === 0 ? ' ' : ''}${acc}`, '').trim() : null,\n dueDateFormatted: payload.dueDate ? dayjs(payload.dueDate).format('DD/MM/YYYY') : null,\n expirationDateFormatted: payload.expirationDate ? dayjs(payload.expirationDate).format('DD/MM/YYYY') : null,\n emissionDateFormatted: payload.emissionDate ? dayjs(payload.emissionDate).format('DD/MM/YYYY') : null,\n shouldDisplayDiscountColumn: !!products.find((p) => p.discount2 && p.discount2 > 0),\n // @ts-ignore\n marginVats: _uniq(products.filter((p) => p.marginVatFormatted !== null).map((p) => p.marginVatFormatted)),\n accountingCategoryFormatted: AccountingCategoryList.find((a) => a.id === payload.accountingCategory)?.label ?? null,\n };\n\n const commonTemplate = new CommercialDocumentCommonHTML();\n const documentFreeText = [EstimateInvoiceType.DEVIS, EstimateInvoiceType.BON].includes(idEstimateInvoiceType) ? payload?.settings?.freeEstimateText : payload?.settings?.freeInvoiceText;\n\n return {\n header: ejs.render(commonTemplate.header, data),\n body: ejs.render(bodyTemplate, data),\n footer: ejs.render(commonTemplate.footer, { ...data, freeText: documentFreeText ?? null }),\n data,\n };\n}\n\nexport function generateAdvanceDocument(payload: CreateInvoiceDocument): ReadCommercialDocumentTemplate {\n if (!payload.deposit) throw new Error('Aucun acompte défini');\n\n const data: ReadDocumentEditing = {\n ...payload,\n title: payload.title ?? null,\n paymentLink: payload.paymentLink ?? '#',\n idEstimateInvoiceType: EstimateInvoiceType.ACOMPTE,\n phoneContact: payload.settings?.phoneContact ?? null,\n products: [],\n vats: [],\n totalTaxExcluded: payload.deposit,\n totalTaxIncluded: payload.deposit,\n totalTaxAndDiscountIncluded: payload.deposit,\n generalDiscountFormatted: null,\n comment: payload.comment && typeof payload.comment === 'string' ? payload.comment.replace(/\\n/g, '<br/>') : payload.comment,\n depositFormatted: integerToFormattedAmountString(payload.deposit),\n totalTaxExcludedFormatted: integerToFormattedAmountString(payload.deposit),\n totalTaxIncludedFormatted: integerToFormattedAmountString(payload.deposit),\n totalTaxAndDiscountIncludedFormatted: integerToFormattedAmountString(payload.deposit),\n totalVatAmountFormatted: integerToFormattedAmountString(0),\n font: {\n id: payload.settings?.idFont ?? FontIds.CIRCULAR_STD,\n name: fontList.find((f) => f.id === payload.settings?.idFont)?.name ?? fontList[0].name,\n url: fontList.find((f) => f.id === payload.settings?.idFont)?.link ?? fontList[0].link,\n },\n capitalFormatted: payload.capital ? `${payload.capital}`.split('').reduceRight((acc, char, i, { length }) => `${char}${(length - (i + 1)) % 3 === 0 ? ' ' : ''}${acc}`, '').trim() : null,\n dueDateFormatted: payload.dueDate ? dayjs(payload.dueDate).format('DD/MM/YYYY') : null,\n expirationDateFormatted: payload.expirationDate ? dayjs(payload.expirationDate).format('DD/MM/YYYY') : null,\n emissionDateFormatted: payload.emissionDate ? dayjs(payload.emissionDate).format('DD/MM/YYYY') : null,\n shouldDisplayDiscountColumn: false,\n disableVat: true,\n // @ts-ignore\n marginVats: _uniq((payload.assetMarginVatIds ?? []).map((m) => VatMarginCategyList.find((c) => c.id === m)?.label ?? null)),\n accountingCategoryFormatted: AccountingCategoryList.find((a) => a.id === payload.accountingCategory)?.label ?? null,\n };\n\n const commonTemplate = new CommercialDocumentCommonHTML();\n\n return {\n header: ejs?.render(commonTemplate.header, data),\n body: ejs?.render(bodyTemplate, data),\n footer: ejs?.render(commonTemplate.footer, { ...data, freeText: payload?.settings?.freeInvoiceText ?? null }),\n data,\n };\n}"]}
1
+ {"version":3,"file":"document.js","mappings":";;;;;QAoBgBA,0B,GAAAA,0B;QA4DAC,uB,GAAAA,uB;;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CommercialDocument","generateAdvanceDocument","dayjs","ejs","require","idEstimateInvoiceType","payload","products","map","product","vats","Object","values","v","filter","id","Vat","MARGE","thirdParty","data","paymentLink","_a","title","_b","penalties","_c","compensation","_d","discount","_e","vatMention","_f","phoneContact","settings","_g","_h","totalTaxExcluded","totalTaxIncluded","totalTaxAndDiscountIncluded","generalDiscountFormatted","generalDiscount2","depositFormatted","deposit","totalTaxExcludedFormatted","totalTaxIncludedFormatted","totalTaxAndDiscountIncludedFormatted","_j","_k","totalVatAmountFormatted","font","_l","idFont","_m","FontIds","CIRCULAR_STD","name","find","f","_o","_p","fontList","url","_q","link","_r","capitalFormatted","capital","split","reduceRight","acc","char","i","length","trim","dueDateFormatted","dueDate","format","expirationDateFormatted","expirationDate","emissionDateFormatted","emissionDate","shouldDisplayDiscountColumn","p","discount2","marginVats","marginVatFormatted","accountingCategoryFormatted","a","accountingCategory","_s","label","_t","commonTemplate","CommercialDocumentCommonHTML","documentFreeText","EstimateInvoiceType","DEVIS","BON","includes","_u","freeEstimateText","_v","freeInvoiceText","header","render","body","bodyTemplate","comment","_w","replace","footer","freeText","Error","ACOMPTE","disableVat","assetMarginVatIds","m","c"],"sourceRoot":"","sources":["../../../ts/utils/commercialManagement/document.ts"],"sourcesContent":["import {\n orderBy as _orderBy, groupBy as _groupBy, sumBy as _sumBy, uniq as _uniq,\n} from 'lodash';\nimport * as dayjs from 'dayjs';\nimport { ReadCommercialDocumentTemplate, ReadDocumentEditing } from '../../types/Interface/api/commercialManagement/Read';\nimport {\n AccountingCategoryList, FontIds, fontList, VatMarginCategyList,\n} from '../../types/Enum/CommercialManagement';\nimport { EstimateInvoiceType } from '../../types/Enum/EstimateInvoice';\nimport { Vat } from '../../types/Enum/Vat';\nimport { integerToFormattedAmountString } from '../amount';\nimport { CommercialDocumentCommonHTML } from './templates/common';\nimport { bodyTemplate } from './templates/body';\nimport { productToReadProductEditing } from './product';\nimport { vatToReadVatEditing } from './vat';\nimport { CreateInvoiceDocument, CreatePreSaleDocument } from '../../types';\nimport { thirdPartyToReadThirdPartyEditing } from './thirdParty';\n\nconst ejs = require('ejs');\n\nexport function generateCommercialDocument(idEstimateInvoiceType: EstimateInvoiceType, payload: CreateInvoiceDocument | CreatePreSaleDocument): ReadCommercialDocumentTemplate {\n const products = _orderBy(payload.products.map((product) => productToReadProductEditing(product), 'reorder'));\n const vats = _orderBy(Object.values(_groupBy(products, 'vatFormatted')).map((v) => (vatToReadVatEditing(v)), 'value')).filter((v) => v.id !== Vat.MARGE.id);\n const thirdParty = thirdPartyToReadThirdPartyEditing(payload.thirdParty);\n\n const data: ReadDocumentEditing = {\n ...payload,\n thirdParty,\n paymentLink: payload.paymentLink ?? '#',\n idEstimateInvoiceType,\n title: payload.title ?? null,\n penalties: payload.penalties ?? null,\n compensation: payload.compensation ?? null,\n discount: payload.discount ?? null,\n vatMention: payload.vatMention ?? null,\n phoneContact: payload.settings?.phoneContact ?? null,\n products,\n vats,\n totalTaxExcluded: _sumBy(products, 'totalTaxExcluded'),\n totalTaxIncluded: _sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount'),\n totalTaxAndDiscountIncluded: _sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount'),\n generalDiscountFormatted: payload.generalDiscount2 ? integerToFormattedAmountString(payload.generalDiscount2) : null,\n depositFormatted: payload.deposit ? integerToFormattedAmountString(payload.deposit) : null,\n totalTaxExcludedFormatted: integerToFormattedAmountString(_sumBy(products, 'totalTaxExcluded')),\n totalTaxIncludedFormatted: integerToFormattedAmountString(_sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount')),\n totalTaxAndDiscountIncludedFormatted: integerToFormattedAmountString(_sumBy(products, 'totalTaxExcluded') + _sumBy(vats, 'amount') - (payload.generalDiscount2 ?? 0) - (payload.deposit ?? 0)),\n totalVatAmountFormatted: integerToFormattedAmountString(_sumBy(vats, 'amount')),\n font: {\n id: payload.settings?.idFont ?? FontIds.CIRCULAR_STD,\n name: fontList.find((f) => f.id === payload.settings?.idFont)?.name ?? fontList[0].name,\n url: fontList.find((f) => f.id === payload.settings?.idFont)?.link ?? fontList[0].link,\n },\n capitalFormatted: payload.capital ? `${payload.capital}`.split('').reduceRight((acc, char, i, { length }) => `${char}${(length - (i + 1)) % 3 === 0 ? ' ' : ''}${acc}`, '').trim() : null,\n dueDateFormatted: payload.dueDate ? dayjs(payload.dueDate).format('DD/MM/YYYY') : null,\n expirationDateFormatted: payload.expirationDate ? dayjs(payload.expirationDate).format('DD/MM/YYYY') : null,\n emissionDateFormatted: payload.emissionDate ? dayjs(payload.emissionDate).format('DD/MM/YYYY') : null,\n shouldDisplayDiscountColumn: !!products.find((p) => p.discount2 && p.discount2 > 0),\n // @ts-ignore\n marginVats: _uniq(products.filter((p) => p.marginVatFormatted !== null).map((p) => p.marginVatFormatted)),\n accountingCategoryFormatted: AccountingCategoryList.find((a) => a.id === payload.accountingCategory)?.label ?? null,\n };\n\n const commonTemplate = new CommercialDocumentCommonHTML();\n const documentFreeText = [EstimateInvoiceType.DEVIS, EstimateInvoiceType.BON].includes(idEstimateInvoiceType) ? payload?.settings?.freeEstimateText : payload?.settings?.freeInvoiceText;\n\n return {\n header: ejs.render(commonTemplate.header, data),\n body: ejs.render(bodyTemplate, {\n ...data,\n comment: data.comment && typeof data.comment === 'string' ? data.comment?.replace(/\\n/g, '<br/>') : null,\n products: data.products.map((p) => ({\n ...p,\n comment: p.comment && typeof p.comment === 'string' ? p.comment?.replace(/\\n/g, '<br/>') : null,\n })),\n }),\n footer: ejs.render(commonTemplate.footer, { ...data, freeText: documentFreeText ?? null }),\n data,\n };\n}\n\nexport function generateAdvanceDocument(payload: CreateInvoiceDocument): ReadCommercialDocumentTemplate {\n if (!payload.deposit) throw new Error('Aucun acompte défini');\n\n const data: ReadDocumentEditing = {\n ...payload,\n title: payload.title ?? null,\n paymentLink: payload.paymentLink ?? '#',\n idEstimateInvoiceType: EstimateInvoiceType.ACOMPTE,\n phoneContact: payload.settings?.phoneContact ?? null,\n products: [],\n vats: [],\n totalTaxExcluded: payload.deposit,\n totalTaxIncluded: payload.deposit,\n totalTaxAndDiscountIncluded: payload.deposit,\n generalDiscountFormatted: null,\n depositFormatted: integerToFormattedAmountString(payload.deposit),\n totalTaxExcludedFormatted: integerToFormattedAmountString(payload.deposit),\n totalTaxIncludedFormatted: integerToFormattedAmountString(payload.deposit),\n totalTaxAndDiscountIncludedFormatted: integerToFormattedAmountString(payload.deposit),\n totalVatAmountFormatted: integerToFormattedAmountString(0),\n font: {\n id: payload.settings?.idFont ?? FontIds.CIRCULAR_STD,\n name: fontList.find((f) => f.id === payload.settings?.idFont)?.name ?? fontList[0].name,\n url: fontList.find((f) => f.id === payload.settings?.idFont)?.link ?? fontList[0].link,\n },\n capitalFormatted: payload.capital ? `${payload.capital}`.split('').reduceRight((acc, char, i, { length }) => `${char}${(length - (i + 1)) % 3 === 0 ? ' ' : ''}${acc}`, '').trim() : null,\n dueDateFormatted: payload.dueDate ? dayjs(payload.dueDate).format('DD/MM/YYYY') : null,\n expirationDateFormatted: payload.expirationDate ? dayjs(payload.expirationDate).format('DD/MM/YYYY') : null,\n emissionDateFormatted: payload.emissionDate ? dayjs(payload.emissionDate).format('DD/MM/YYYY') : null,\n shouldDisplayDiscountColumn: false,\n disableVat: true,\n // @ts-ignore\n marginVats: _uniq((payload.assetMarginVatIds ?? []).map((m) => VatMarginCategyList.find((c) => c.id === m)?.label ?? null)),\n accountingCategoryFormatted: AccountingCategoryList.find((a) => a.id === payload.accountingCategory)?.label ?? null,\n };\n\n const commonTemplate = new CommercialDocumentCommonHTML();\n\n return {\n header: ejs?.render(commonTemplate.header, data),\n body: ejs?.render(bodyTemplate, {\n ...data,\n comment: data.comment && typeof data.comment === 'string' ? data.comment?.replace(/\\n/g, '<br/>') : null,\n products: data.products.map((p) => ({\n ...p,\n comment: p.comment && typeof p.comment === 'string' ? p.comment?.replace(/\\n/g, '<br/>') : null,\n })),\n }),\n footer: ejs?.render(commonTemplate.footer, { ...data, freeText: payload?.settings?.freeInvoiceText ?? null }),\n data,\n };\n}"]}
@@ -44,7 +44,6 @@ function productToReadProductEditing(payload) {
44
44
  var _a, _b, _c, _d, _e, _f;
45
45
 
46
46
  return Object.assign(Object.assign({}, payload), {
47
- comment: payload.comment && typeof payload.comment === 'string' ? payload.comment.replace(/\n/g, '<br/>') : payload.comment,
48
47
  totalTaxExcluded: getTotalTaxExcluded(payload),
49
48
  unitFormatted: (_b = (_a = Object.values(_Unit.Unit).find(unit => unit.id === payload.unit)) === null || _a === void 0 ? void 0 : _a.shortName) !== null && _b !== void 0 ? _b : '',
50
49
  vatFormatted: (_d = (_c = (0, _vat.getById)(payload.idVat)) === null || _c === void 0 ? void 0 : _c.saleName) !== null && _d !== void 0 ? _d : '',
@@ -1 +1 @@
1
- {"version":3,"file":"product.js","mappings":";;;;;QAOgBA,W,GAAAA,W;QAYAC,mB,GAAAA,mB;QAKAC,2B,GAAAA,2B;;AAxBhB;;AAEA;;AACA;;AACA;;AACA;;AAEM,SAAUF,WAAV,CAAsBG,OAAtB,EAA8C;;;EAClD,IAAIA,OAAO,CAACC,SAAR,KAAsB,IAAtB,IAA8BD,OAAO,CAACC,SAAR,KAAsBC,SAApD,IAAiEF,OAAO,CAACC,SAAR,IAAqB,CAA1F,EAA6F,OAAO,CAAP;;EAE7F,IAAID,OAAO,CAACG,YAAR,KAAyBC,mCAAaC,OAA1C,EAAmD;IACjD,OAAQ,CAAC,aAAO,CAACC,gBAAR,MAAwB,IAAxB,IAAwBC,aAAxB,GAAwBA,EAAxB,GAA4B,CAA7B,KAAmC,CAAC,aAAO,CAACN,SAAR,MAAiB,IAAjB,IAAiBO,aAAjB,GAAiBA,EAAjB,GAAqB,CAAtB,IAA2B,GAA9D,CAAD,GAAuE,GAA9E;EACD;;EAAC,IAAIR,OAAO,CAACG,YAAR,KAAyBC,mCAAaK,MAA1C,EAAkD;IAClD,OAAQ,aAAO,CAACR,SAAR,MAAiB,IAAjB,IAAiBS,aAAjB,GA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,OAAO,CAACP,gBAAlB,IAAsC,4CAA+BO,OAAO,CAACP,gBAAvC,CAAtC,GAAiG,IALlH;IAMVuB,yBAAyB,EAAE,+BAAUhB,OAAO,CAACP,gBAAlB,IAAsC,4CAA+BR,mBAAmB,CAACe,OAAD,CAAlD,CAAtC,GAAqG,IANtH;IAOViB,iBAAiB,EAAEjB,OAAO,CAACZ,SAAR,IAAqBY,OAAO,CAACZ,SAAR,GAAoB,CAAzC,GAA6C,4CAA+BJ,WAAW,CAACgB,OAAD,CAA1C,CAA7C,GAAoG,IAP7G;IAQVkB,qBAAqB,EAAElB,OAAO,CAACZ,SAAR,IAAqBY,OAAO,CAACZ,SAAR,GAAoB,CAAzC,GAA6CY,OAAO,CAACV,YAAR,KAAyBC,mCAAaC,OAAtC,GAAgD,GAAG,CAACQ,OAAO,CAACZ,SAAR,GAAoB,GAArB,EAA0B+B,OAA1B,CAAkC,CAAlC,CAAoC,GAAvF,GAA6F,GAAG,4CAA+BnB,OAAO,CAACZ,SAAvC,CAAiD,GAA9L,GAAoM,IARjN;IASVgC,kBAAkB,EAAEpB,OAAO,CAACqB,aAAR,GAAwB,sDAAoBd,IAApB,CAA0Be,CAAD,IAAOA,CAAC,CAACb,EAAF,KAAST,OAAO,CAACqB,aAAjD,OAA+D,IAA/D,IAA+DE,aAA/D,GAA+D,MAA/D,GAA+DA,GAAEC,KAAjE,MAAsE,IAAtE,IAAsEC,aAAtE,GAAsEA,EAAtE,GAA0E,IAAlG,GAAyG;EATnH,CADZ;AAYD","names":["getDiscount","getTotalTaxExcluded","productToReadProductEditing","product","discount2","undefined","discountType","DiscountType","PERCENT","priceTaxExcluded","_a","_b","AMOUNT","_c","discount","quantity","payload","comment","replace","totalTaxExcluded","unitFormatted","values","Unit","find","unit","id","shortName","vatFormatted","idVat","saleName","_d","priceTaxExcludedFormatted","totalTaxExcludedFormatted","discountFormatted","discountTypeFormatted","toFixed","marginVatFormatted","marginVatType","c","_e","label","_f"],"sourceRoot":"","sources":["../../../ts/utils/commercialManagement/product.ts"],"sourcesContent":["import { isDefined } from 'class-validator';\nimport { IProductInvoice, ReadProductEditing } from '../../types';\nimport { Unit } from '../../types/Enum/Unit';\nimport { DiscountType, VatMarginCategyList } from '../../types/Enum/CommercialManagement';\nimport { getById } from './vat';\nimport { integerToFormattedAmountString } from '../amount';\n\nexport function getDiscount(product: IProductInvoice): number {\n if (product.discount2 === null || product.discount2 === undefined || product.discount2 <= 0) return 0;\n\n if (product.discountType === DiscountType.PERCENT) {\n return ((product.priceTaxExcluded ?? 0) * ((product.discount2 ?? 0) / 100)) / 100;\n } if (product.discountType === DiscountType.AMOUNT) {\n return (product.discount2 ?? 0);\n }\n\n return 0;\n}\n\nexport function getTotalTaxExcluded(product: IProductInvoice): number {\n const discount = product.discount2 && product.discount2 > 0 ? getDiscount(product) : 0;\n return ((product.priceTaxExcluded ?? 0) - discount) * (product.quantity ?? 1);\n}\n\nexport function productToReadProductEditing(payload: IProductInvoice): ReadProductEditing {\n return {\n ...payload,\n comment: payload.comment && typeof payload.comment === 'string' ? payload.comment.replace(/\\n/g, '<br/>') : payload.comment,\n totalTaxExcluded: getTotalTaxExcluded(payload),\n unitFormatted: Object.values(Unit).find((unit) => unit.id === payload.unit)?.shortName ?? '',\n vatFormatted: getById(payload.idVat)?.saleName ?? '',\n priceTaxExcludedFormatted: isDefined(payload.priceTaxExcluded) ? integerToFormattedAmountString(payload.priceTaxExcluded) : null,\n totalTaxExcludedFormatted: isDefined(payload.priceTaxExcluded) ? integerToFormattedAmountString(getTotalTaxExcluded(payload)) : null,\n discountFormatted: payload.discount2 && payload.discount2 > 0 ? integerToFormattedAmountString(getDiscount(payload)) : null,\n discountTypeFormatted: payload.discount2 && payload.discount2 > 0 ? payload.discountType === DiscountType.PERCENT ? `${(payload.discount2 / 100).toFixed(2)}%` : `${integerToFormattedAmountString(payload.discount2)}€` : null,\n marginVatFormatted: payload.marginVatType ? VatMarginCategyList.find((c) => c.id === payload.marginVatType)?.label ?? null : null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AAkB,EAAElB,OAAO,CAACmB,aAAR,GAAwB,sDAAoBd,IAApB,CAA0Be,CAAD,IAAOA,CAAC,CAACb,EAAF,KAASP,OAAO,CAACmB,aAAjD,OAA+D,IAA/D,IAA+DE,aAA/D,GAA+D,MAA/D,GAA+DA,GAAEC,KAAjE,MAAsE,IAAtE,IAAsEC,aAAtE,GAAsEA,EAAtE,GAA0E,IAAlG,GAAyG;EARnH,CADZ;AAWD","names":["getDiscount","getTotalTaxExcluded","productToReadProductEditing","product","discount2","undefined","discountType","DiscountType","PERCENT","priceTaxExcluded","_a","_b","AMOUNT","_c","discount","quantity","payload","totalTaxExcluded","unitFormatted","values","Unit","find","unit","id","shortName","vatFormatted","idVat","saleName","_d","priceTaxExcludedFormatted","totalTaxExcludedFormatted","discountFormatted","discountTypeFormatted","toFixed","marginVatFormatted","marginVatType","c","_e","label","_f"],"sourceRoot":"","sources":["../../../ts/utils/commercialManagement/product.ts"],"sourcesContent":["import { isDefined } from 'class-validator';\nimport { IProductInvoice, ReadProductEditing } from '../../types';\nimport { Unit } from '../../types/Enum/Unit';\nimport { DiscountType, VatMarginCategyList } from '../../types/Enum/CommercialManagement';\nimport { getById } from './vat';\nimport { integerToFormattedAmountString } from '../amount';\n\nexport function getDiscount(product: IProductInvoice): number {\n if (product.discount2 === null || product.discount2 === undefined || product.discount2 <= 0) return 0;\n\n if (product.discountType === DiscountType.PERCENT) {\n return ((product.priceTaxExcluded ?? 0) * ((product.discount2 ?? 0) / 100)) / 100;\n } if (product.discountType === DiscountType.AMOUNT) {\n return (product.discount2 ?? 0);\n }\n\n return 0;\n}\n\nexport function getTotalTaxExcluded(product: IProductInvoice): number {\n const discount = product.discount2 && product.discount2 > 0 ? getDiscount(product) : 0;\n return ((product.priceTaxExcluded ?? 0) - discount) * (product.quantity ?? 1);\n}\n\nexport function productToReadProductEditing(payload: IProductInvoice): ReadProductEditing {\n return {\n ...payload,\n totalTaxExcluded: getTotalTaxExcluded(payload),\n unitFormatted: Object.values(Unit).find((unit) => unit.id === payload.unit)?.shortName ?? '',\n vatFormatted: getById(payload.idVat)?.saleName ?? '',\n priceTaxExcludedFormatted: isDefined(payload.priceTaxExcluded) ? integerToFormattedAmountString(payload.priceTaxExcluded) : null,\n totalTaxExcludedFormatted: isDefined(payload.priceTaxExcluded) ? integerToFormattedAmountString(getTotalTaxExcluded(payload)) : null,\n discountFormatted: payload.discount2 && payload.discount2 > 0 ? integerToFormattedAmountString(getDiscount(payload)) : null,\n discountTypeFormatted: payload.discount2 && payload.discount2 > 0 ? payload.discountType === DiscountType.PERCENT ? `${(payload.discount2 / 100).toFixed(2)}%` : `${integerToFormattedAmountString(payload.discount2)}€` : null,\n marginVatFormatted: payload.marginVatType ? VatMarginCategyList.find((c) => c.id === payload.marginVatType)?.label ?? null : null,\n };\n}"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@silexpert/core",
3
- "version": "1.0.81",
3
+ "version": "1.0.82",
4
4
  "description": "Silex Core perform HTTP Request and object binding. Silex core helps developers to retrieve and return formatted object",
5
5
  "homepage": "https://gitlab.compta-clementine.fr/dev/silex-api",
6
6
  "main": "js/index.js",
@@ -8,6 +8,7 @@ export interface IBalanceSheet {
8
8
  state: number;
9
9
  dateBalanceSend: Date | null;
10
10
  deadline: Date | null;
11
+ bankCollectingState: number;
11
12
  idExercice: number;
12
13
  idCalendarEvent: number | null;
13
14
  createdAt?: Date | null;
@@ -34,7 +34,6 @@ export function generateCommercialDocument(idEstimateInvoiceType: EstimateInvoic
34
34
  discount: payload.discount ?? null,
35
35
  vatMention: payload.vatMention ?? null,
36
36
  phoneContact: payload.settings?.phoneContact ?? null,
37
- comment: payload.comment && typeof payload.comment === 'string' ? payload.comment.replace(/\n/g, '<br/>') : payload.comment,
38
37
  products,
39
38
  vats,
40
39
  totalTaxExcluded: _sumBy(products, 'totalTaxExcluded'),
@@ -66,7 +65,14 @@ export function generateCommercialDocument(idEstimateInvoiceType: EstimateInvoic
66
65
 
67
66
  return {
68
67
  header: ejs.render(commonTemplate.header, data),
69
- body: ejs.render(bodyTemplate, data),
68
+ body: ejs.render(bodyTemplate, {
69
+ ...data,
70
+ comment: data.comment && typeof data.comment === 'string' ? data.comment?.replace(/\n/g, '<br/>') : null,
71
+ products: data.products.map((p) => ({
72
+ ...p,
73
+ comment: p.comment && typeof p.comment === 'string' ? p.comment?.replace(/\n/g, '<br/>') : null,
74
+ })),
75
+ }),
70
76
  footer: ejs.render(commonTemplate.footer, { ...data, freeText: documentFreeText ?? null }),
71
77
  data,
72
78
  };
@@ -87,7 +93,6 @@ export function generateAdvanceDocument(payload: CreateInvoiceDocument): ReadCom
87
93
  totalTaxIncluded: payload.deposit,
88
94
  totalTaxAndDiscountIncluded: payload.deposit,
89
95
  generalDiscountFormatted: null,
90
- comment: payload.comment && typeof payload.comment === 'string' ? payload.comment.replace(/\n/g, '<br/>') : payload.comment,
91
96
  depositFormatted: integerToFormattedAmountString(payload.deposit),
92
97
  totalTaxExcludedFormatted: integerToFormattedAmountString(payload.deposit),
93
98
  totalTaxIncludedFormatted: integerToFormattedAmountString(payload.deposit),
@@ -113,7 +118,14 @@ export function generateAdvanceDocument(payload: CreateInvoiceDocument): ReadCom
113
118
 
114
119
  return {
115
120
  header: ejs?.render(commonTemplate.header, data),
116
- body: ejs?.render(bodyTemplate, data),
121
+ body: ejs?.render(bodyTemplate, {
122
+ ...data,
123
+ comment: data.comment && typeof data.comment === 'string' ? data.comment?.replace(/\n/g, '<br/>') : null,
124
+ products: data.products.map((p) => ({
125
+ ...p,
126
+ comment: p.comment && typeof p.comment === 'string' ? p.comment?.replace(/\n/g, '<br/>') : null,
127
+ })),
128
+ }),
117
129
  footer: ejs?.render(commonTemplate.footer, { ...data, freeText: payload?.settings?.freeInvoiceText ?? null }),
118
130
  data,
119
131
  };
@@ -25,7 +25,6 @@ export function getTotalTaxExcluded(product: IProductInvoice): number {
25
25
  export function productToReadProductEditing(payload: IProductInvoice): ReadProductEditing {
26
26
  return {
27
27
  ...payload,
28
- comment: payload.comment && typeof payload.comment === 'string' ? payload.comment.replace(/\n/g, '<br/>') : payload.comment,
29
28
  totalTaxExcluded: getTotalTaxExcluded(payload),
30
29
  unitFormatted: Object.values(Unit).find((unit) => unit.id === payload.unit)?.shortName ?? '',
31
30
  vatFormatted: getById(payload.idVat)?.saleName ?? '',