@experteam-mx/ngx-services 20.6.0-dev2.1 → 20.7.0

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.
@@ -1,7 +1,7 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { InjectionToken, makeEnvironmentProviders, NgModule, inject, Injectable } from '@angular/core';
3
3
  import { provideHttpClient, HttpClient, HttpHeaders, HttpResponse, HttpParams } from '@angular/common/http';
4
- import { map, mergeMap, forkJoin, tap, Observable, of } from 'rxjs';
4
+ import { map, mergeMap, forkJoin, tap, BehaviorSubject, merge, firstValueFrom, Observable, of } from 'rxjs';
5
5
  import { map as map$1, tap as tap$1, finalize, shareReplay } from 'rxjs/operators';
6
6
  import { CookieService } from 'ngx-cookie-service';
7
7
  import Pusher from 'pusher-js';
@@ -3400,56 +3400,6 @@ class ApiInventoriesService {
3400
3400
  return this.http.get(`${this.url}/stock-update/packages/${id}`)
3401
3401
  .pipe(map(({ data }) => data));
3402
3402
  }
3403
- /**
3404
- * Retrieves a list of courier routes based on query parameters.
3405
- *
3406
- * @param {QueryParams} params - Query parameters for filtering the courier routes.
3407
- * @returns {Observable<CourierRoutesOut>} An observable that emits the list of courier routes.
3408
- */
3409
- getCourierRoutes(params) {
3410
- return this.http.get(`${this.url}/courier-routes`, {
3411
- params
3412
- }).pipe(map(({ data }) => data));
3413
- }
3414
- /**
3415
- * Fetches the courier route details based on the provided courier route ID.
3416
- *
3417
- * @param {number} id - The courier route id
3418
- * @return {Observable<CourierRouteOut>} An observable that emits the courier route data.
3419
- */
3420
- getCourierRoute(id) {
3421
- return this.http.get(`${this.url}/courier-routes/${id}`)
3422
- .pipe(map(({ data }) => data));
3423
- }
3424
- /**
3425
- * Creates a new courier route.
3426
- *
3427
- * @param {CourierRouteIn} body - The data for the new courier route.
3428
- * @returns {Observable<CourierRouteOut>} An observable the created courier route detail.
3429
- */
3430
- postCourierRoute(body) {
3431
- return this.http.post(`${this.url}/courier-routes`, body).pipe(map(({ data }) => data));
3432
- }
3433
- /**
3434
- * Update an existing courier route.
3435
- *
3436
- * @param {number} id - The identifier of the courier route record to update.
3437
- * @param {CourierRouteIn} body - The courier route data to be updated.
3438
- * @returns {Observable<CourierRouteOut>} An observable detail of the updated courier route.
3439
- */
3440
- putCourierRoute(id, body) {
3441
- return this.http.put(`${this.url}/courier-routes/${id}`, body).pipe(map(({ data }) => data));
3442
- }
3443
- /**
3444
- * Delete an existing courier route.
3445
- *
3446
- * @param {number} id - The unique identifier of the courier route to be deleted.
3447
- * @returns {Observable<CourierRouteOut>} An observable that emits the result of the delete courier route.
3448
- */
3449
- deleteCourierRoute(id) {
3450
- return this.http.delete(`${this.url}/courier-routes/${id}`)
3451
- .pipe(map(({ data }) => data));
3452
- }
3453
3403
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: ApiInventoriesService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
3454
3404
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: ApiInventoriesService, providedIn: 'root' });
3455
3405
  }
@@ -3471,6 +3421,32 @@ class ApiInvoicesService {
3471
3421
  get url() {
3472
3422
  return this.environments.apiInvoicesUrl ?? '';
3473
3423
  }
3424
+ /**
3425
+ * Retrieves the printable ticket payload for a billing operation.
3426
+ *
3427
+ * Sends a GET request to `/operation/print/ticket/{documentId}` and unwraps
3428
+ * the `data` field from the API success envelope.
3429
+ *
3430
+ * @param documentId - Numeric identifier of the document to print.
3431
+ * @returns An Observable that emits the ticket data for the given document.
3432
+ */
3433
+ getOperationPrintTicket(documentId) {
3434
+ return this.http.get(`${this.url}/operation/print/ticket/${documentId}`)
3435
+ .pipe(map(({ data }) => data));
3436
+ }
3437
+ /**
3438
+ * Retrieves the printable document payload for a billing operation.
3439
+ *
3440
+ * Sends a GET request to `/operation/print/document/{documentId}` and unwraps
3441
+ * the `data` field from the API success envelope.
3442
+ *
3443
+ * @param documentId - Numeric identifier of the document to print.
3444
+ * @returns An Observable that emits the printable document data for the given document.
3445
+ */
3446
+ getOperationPrintDocument(documentId) {
3447
+ return this.http.get(`${this.url}/operation/print/document/${documentId}`)
3448
+ .pipe(map(({ data }) => data));
3449
+ }
3474
3450
  /**
3475
3451
  * Sends an operation document to the server and processes the response.
3476
3452
  *
@@ -3575,16 +3551,6 @@ class ApiInvoicesService {
3575
3551
  return this.http.post(`${this.url}/operation/shipment/external/payment`, params)
3576
3552
  .pipe(map(({ data }) => data));
3577
3553
  }
3578
- /**
3579
- * Retrieves and returns billing operation print details for a given document ID.
3580
- *
3581
- * @param {number} documentId - The ID of the document for which to fetch the print billing operation details.
3582
- * @return {Observable<OperationPrintDocumentOut>} An observable emitting the print billing operation details for the specified document.
3583
- */
3584
- getOperationPrintDocument(documentId) {
3585
- return this.http.get(`${this.url}/operation/print/document/${documentId}`)
3586
- .pipe(map(({ data }) => data));
3587
- }
3588
3554
  /**
3589
3555
  * Fetches all country payment types.
3590
3556
  *
@@ -5117,6 +5083,168 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.25", ngImpo
5117
5083
  }]
5118
5084
  }] });
5119
5085
 
5086
+ const base64PdfToUrl = (base64) => {
5087
+ const data = new Uint8Array(atob(base64)
5088
+ .split('')
5089
+ .map(char => char.charCodeAt(0)));
5090
+ const blob = new Blob([data], { type: 'application/pdf' });
5091
+ return window.URL.createObjectURL(blob);
5092
+ };
5093
+ const downloadBase64Pdf = (base64) => window.open(base64PdfToUrl(base64));
5094
+
5095
+ var PrintMode;
5096
+ (function (PrintMode) {
5097
+ PrintMode["PRINT"] = "PRINT";
5098
+ PrintMode["DISPLAY"] = "DISPLAY";
5099
+ PrintMode["BOTH"] = "BOTH";
5100
+ })(PrintMode || (PrintMode = {}));
5101
+ var PrintableFormat;
5102
+ (function (PrintableFormat) {
5103
+ PrintableFormat["PDF"] = "pdf";
5104
+ PrintableFormat["ZPL2"] = "zpl2";
5105
+ })(PrintableFormat || (PrintableFormat = {}));
5106
+ var PrintersType;
5107
+ (function (PrintersType) {
5108
+ PrintersType["LABEL"] = "label";
5109
+ PrintersType["RECEIPT"] = "receipt";
5110
+ PrintersType["OTHERS"] = "others";
5111
+ })(PrintersType || (PrintersType = {}));
5112
+
5113
+ class PrintersService {
5114
+ environments = inject(ENVIRONMENT_TOKEN);
5115
+ http = inject(HttpClient);
5116
+ availablePrinters$ = new BehaviorSubject([]);
5117
+ printMode = PrintMode.DISPLAY;
5118
+ printers = [];
5119
+ /**
5120
+ * Retrieves the print URL from the environments configuration or defaults to 'http://localhost:9100'
5121
+ * if not specified.
5122
+ *
5123
+ * @return {string} The URL to be used for printing.
5124
+ */
5125
+ get url() {
5126
+ return this.environments.printUrl ?? 'http://localhost:9100';
5127
+ }
5128
+ /**
5129
+ * Prints or displays a document based on the current print mode.
5130
+ * It can handle printing to a physical printer, displaying in the browser,
5131
+ * or both simultaneously.
5132
+ *
5133
+ * @param {Printable} document - The document to be printed or displayed.
5134
+ * @return {Promise<void>} A promise that resolves when the printing or displaying process is complete, or rejects if an error occurs.
5135
+ */
5136
+ print(document) {
5137
+ return new Promise((resolve, reject) => {
5138
+ switch (this.printMode) {
5139
+ case PrintMode.PRINT:
5140
+ this.sendToPrinter(document).then(() => resolve()).catch(reject);
5141
+ break;
5142
+ case PrintMode.DISPLAY:
5143
+ this.sendToBrowser(document).then(resolve).catch(reject);
5144
+ break;
5145
+ case PrintMode.BOTH:
5146
+ merge([
5147
+ this.sendToBrowser(document),
5148
+ this.sendToPrinter(document)
5149
+ ]).subscribe({
5150
+ next: () => resolve(),
5151
+ error: reject,
5152
+ });
5153
+ break;
5154
+ }
5155
+ });
5156
+ }
5157
+ /**
5158
+ * Configures and initializes the print settings based on the provided parameters.
5159
+ *
5160
+ * @param {Object} config - The configuration object to set up the print mode and manage printers.
5161
+ * @param {string} config.country - The country code used to determine printer configurations.
5162
+ * @param {PrintMode} config.printMode - The mode of printing, defining whether to use print, digital, or both.
5163
+ * @return {void} This method does not return any value.
5164
+ */
5165
+ setUp({ country, printMode }) {
5166
+ this.printMode = printMode;
5167
+ if (this.printMode === PrintMode.BOTH || this.printMode === PrintMode.PRINT) {
5168
+ this.checkPrinters(country);
5169
+ }
5170
+ }
5171
+ /**
5172
+ * Resets the printers list and updates the availablePrinters$ observable.
5173
+ * The method clears the current list of printers, emits the updated empty list
5174
+ * through the availablePrinters$ observable, and finalizes the observable stream.
5175
+ *
5176
+ * @return {void} No return value.
5177
+ */
5178
+ setDown() {
5179
+ this.printers = [];
5180
+ this.availablePrinters$.next(this.printers);
5181
+ this.availablePrinters$.complete();
5182
+ }
5183
+ sendToPrinter({ type, content, format }) {
5184
+ const printer = this.printers.find(({ name }) => name === type);
5185
+ if (!printer) {
5186
+ throw new Error(`Printer ${type} not found.`);
5187
+ }
5188
+ return firstValueFrom(this.http.post(`${this.url}/print`, {
5189
+ base64: content,
5190
+ deviceName: printer.name,
5191
+ format,
5192
+ }).pipe(map(({ data }) => data)));
5193
+ }
5194
+ sendToBrowser({ format, content }) {
5195
+ return new Promise((resolve, reject) => {
5196
+ try {
5197
+ if (format === PrintableFormat.ZPL2) {
5198
+ return;
5199
+ }
5200
+ downloadBase64Pdf(content);
5201
+ resolve();
5202
+ }
5203
+ catch (e) {
5204
+ reject(e);
5205
+ }
5206
+ });
5207
+ }
5208
+ checkPrinters(country) {
5209
+ if (country.label_printer_name) {
5210
+ this.printers.push({
5211
+ name: PrintersType.LABEL,
5212
+ configured: false,
5213
+ });
5214
+ }
5215
+ if (country.receipt_printer_name) {
5216
+ this.printers.push({
5217
+ name: PrintersType.RECEIPT,
5218
+ configured: false,
5219
+ });
5220
+ }
5221
+ if (country.others_printer_name) {
5222
+ this.printers.push({
5223
+ name: PrintersType.OTHERS,
5224
+ configured: false,
5225
+ });
5226
+ }
5227
+ this.http.get(`${this.url}/available`)
5228
+ .subscribe({
5229
+ next: ({ printer }) => {
5230
+ this.printers = this.printers.map((item) => {
5231
+ const available = printer.some(({ name }) => name === item.name);
5232
+ return available ? { ...item, configured: true } : item;
5233
+ });
5234
+ this.availablePrinters$.next(this.printers);
5235
+ }
5236
+ });
5237
+ }
5238
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: PrintersService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
5239
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: PrintersService, providedIn: 'root' });
5240
+ }
5241
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: PrintersService, decorators: [{
5242
+ type: Injectable,
5243
+ args: [{
5244
+ providedIn: 'root'
5245
+ }]
5246
+ }] });
5247
+
5120
5248
  var DepositTypeCode;
5121
5249
  (function (DepositTypeCode) {
5122
5250
  DepositTypeCode["CASH"] = "CASH";
@@ -5504,15 +5632,6 @@ function httpCachingInterceptor(req, next) {
5504
5632
  return sharedRequest;
5505
5633
  }
5506
5634
 
5507
- const base64PdfToUrl = (base64) => {
5508
- const data = new Uint8Array(atob(base64)
5509
- .split('')
5510
- .map(char => char.charCodeAt(0)));
5511
- const blob = new Blob([data], { type: 'application/pdf' });
5512
- return window.URL.createObjectURL(blob);
5513
- };
5514
- const downloadBase64Pdf = (base64) => window.open(base64PdfToUrl(base64));
5515
-
5516
5635
  /**
5517
5636
  * Convert an object of key-value pairs into a URL query string.
5518
5637
  *
@@ -5586,5 +5705,5 @@ const xmlHeaders = (format = 'object') => {
5586
5705
  * Generated bundle index. Do not edit.
5587
5706
  */
5588
5707
 
5589
- export { AlphaNumeric, ApiBillingCOService, ApiBillingDOService, ApiBillingGtService, ApiBillingMxService, ApiBillingPaService, ApiBillingSvService, ApiCashOperationsService, ApiCatalogsService, ApiCompaniesService, ApiCompositionService, ApiCustomsService, ApiDiscountsService, ApiEToolsAutoBillingService, ApiEventsService, ApiExternalOperationsService, ApiInventoriesService, ApiInvoicesService, ApiNotificationsService, ApiOpenItemsService, ApiQuoteService, ApiReportsService, ApiSecurityService, ApiServicesService, ApiShipmentsService, ApiSuppliesService, ApiSurveysService, CryptoService, DefaultValueType, DepositTypeCode, DocumentStatusCode, ENVIRONMENT_TOKEN, Event, Group, NgxServicesModule, OpeningStatusCode, OperationModuleStatus, PaymentTypeCode, ShipmentIncomeTypeCode, TransferenceTypeCode, ViewSectionOption, WebSocketsService, apiHeadersInterceptor, apiTokenInterceptor, base64PdfToUrl, downloadBase64Pdf, httpCachingInterceptor, httpParams, pdfHeaders, provideNgxServices, queryString, xmlHeaders };
5708
+ export { AlphaNumeric, ApiBillingCOService, ApiBillingDOService, ApiBillingGtService, ApiBillingMxService, ApiBillingPaService, ApiBillingSvService, ApiCashOperationsService, ApiCatalogsService, ApiCompaniesService, ApiCompositionService, ApiCustomsService, ApiDiscountsService, ApiEToolsAutoBillingService, ApiEventsService, ApiExternalOperationsService, ApiInventoriesService, ApiInvoicesService, ApiNotificationsService, ApiOpenItemsService, ApiQuoteService, ApiReportsService, ApiSecurityService, ApiServicesService, ApiShipmentsService, ApiSuppliesService, ApiSurveysService, CryptoService, DefaultValueType, DepositTypeCode, DocumentStatusCode, ENVIRONMENT_TOKEN, Event, Group, NgxServicesModule, OpeningStatusCode, OperationModuleStatus, PaymentTypeCode, PrintMode, PrintableFormat, PrintersService, PrintersType, ShipmentIncomeTypeCode, TransferenceTypeCode, ViewSectionOption, WebSocketsService, apiHeadersInterceptor, apiTokenInterceptor, base64PdfToUrl, downloadBase64Pdf, httpCachingInterceptor, httpParams, pdfHeaders, provideNgxServices, queryString, xmlHeaders };
5590
5709
  //# sourceMappingURL=experteam-mx-ngx-services.mjs.map