{ "version": 3, "sources": ["apps/frontend/src/app/shared/services/ocr.service.ts"], "sourcesContent": ["import { Injectable } from '@angular/core';\nimport { InputDialogComponent } from '@proman/shared-dialogs/dialogs/input-dialog.component';\nimport { PurchaseEntityInterface, PurchaseTypes } from '@proman/resources/purchase';\nimport { Customer, Material, PromanFile, Supplier } from '@proman/interfaces/entity-interfaces';\nimport { copyToClipboard, mapOptionTranslate } from '@proman/utils';\nimport { SelectOption } from '@proman/interfaces/object-interfaces';\nimport { Entity } from '@proman/services/entity.service';\nimport { FilterService } from '@proman/services/filter.service';\nimport { Dialog } from './dialog.service';\nimport { PromanStateService } from './proman-state.service';\nimport { OcrEntityInterface } from '@proman/resources/ocr';\nimport { ToastService } from '@proman/services/toast.service';\nimport { getPublicSystemOptions } from '@proman/store/system-options';\nimport { Store } from '@ngrx/store';\nimport { RequestService } from '@proman/services/request.service';\nimport { TextPreviewDialogComponent } from '../components/text-preview-dialog.component';\n\n@Injectable({ providedIn: 'root' })\nexport class OcrService {\n typeOptions: SelectOption[];\n purchaseEntityInterface: PurchaseEntityInterface;\n ocrEntityInterface: OcrEntityInterface;\n mediaUrl: string;\n\n constructor(\n private Entity: Entity,\n private Filter: FilterService,\n private PromanState: PromanStateService,\n private Dialog: Dialog,\n private Toast: ToastService,\n private Request: RequestService,\n private store: Store,\n ) {\n this.ocrEntityInterface = this.Entity.get('ocr');\n this.purchaseEntityInterface = this.Entity.get('purchase');\n this.purchaseEntityInterface.getPurchaseTypes().then((response: string[]) => this.typeOptions = response.map((item: string) => mapOptionTranslate(item, this.Filter.translate)));\n this.store.select(getPublicSystemOptions).subscribe((value: any) => this.mediaUrl = value.media_server + '/');\n }\n\n ocrAction = () => {\n this.Dialog.open(InputDialogComponent, {\n header: 'select_file',\n mainField: {\n name: 'file',\n key: 'file',\n type: 'files',\n config: { multiple: false }\n }\n }).then((result: { file: PromanFile[] }) => {\n if (!result || result.file?.length < 2) return;\n this.Request.post(this.mediaUrl + 'ocr', { id: result.file[1].newId }).then((response) => {\n if (!response.text) return;\n copyToClipboard(response.text);\n console.log(response.text);\n this.Dialog.open(TextPreviewDialogComponent, { disableCopy: true, disablePrint: true, text: response.text });\n });\n })\n }\n\n invoiceAnalyze = () => {\n return this.Dialog.open(InputDialogComponent, {\n header: 'select_purchase_type',\n mainField: {\n name: 'purchase_type',\n key: 'type',\n type: 'select',\n config: { options: this.typeOptions }\n },\n parameters: [\n {\n name: 'files',\n key: 'files',\n type: 'files',\n config: { multiple: false }\n }\n ]\n }).then((response: { type: PurchaseTypes, files: PromanFile[] }) => {\n if (response && response.type && response.files && response.files[1]) {\n (response as any).files = response.files[1].id;\n this.ocrEntityInterface.analyzeInvoice({\n id: response.files,\n type: response.type\n }).then((analysisResponse: {\n supplier: Supplier,\n customer: Customer,\n date: string,\n invoiceNumber: string,\n items: Material[],\n type: string,\n id: number,\n }) => {\n if (analysisResponse.type === 'purchase' && analysisResponse.id) {\n this.PromanState.to('Purchase', analysisResponse.id);\n return;\n }\n\n if (analysisResponse.type === 'invoice' && analysisResponse.id) {\n this.PromanState.to('InvoicesEdit', analysisResponse.id);\n return;\n }\n }).catch((e) => this.Toast.pop('error', e.error?.error));\n }\n });\n };\n}\n"], "mappings": "gNAkBA,IAAaA,GAAU,IAAA,CAAjB,MAAOA,CAAU,CAMrBC,YACUC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAAY,CANZ,KAAAN,OAAAA,EACA,KAAAC,OAAAA,EACA,KAAAC,YAAAA,EACA,KAAAC,OAAAA,EACA,KAAAC,MAAAA,EACA,KAAAC,QAAAA,EACA,KAAAC,MAAAA,EAQV,KAAAC,UAAY,IAAK,CACf,KAAKJ,OAAOK,KAAKC,EAAsB,CACrCC,OAAQ,cACRC,UAAW,CACTC,KAAM,OACNC,IAAK,OACLC,KAAM,QACNC,OAAQ,CAAEC,SAAU,EAAK,GAE5B,EAAEC,KAAMC,GAAkC,CACrC,CAACA,GAAUA,EAAOC,MAAMC,OAAS,GACrC,KAAKf,Q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U,EACzD,KAAKC,wBAAwBC,iBAAgB,EAAG/B,KAAMQ,GAAuB,KAAKU,YAAcV,EAASwB,IAAKC,GAAiBC,EAAmBD,EAAM,KAAKjD,OAAOmD,SAAS,CAAC,CAAC,EAC/K,KAAK9C,MAAM+C,OAAOC,CAAsB,EAAEC,UAAWC,GAAe,KAAKlC,SAAWkC,EAAMC,aAAe,GAAG,CAC9G,iDAnBW3D,GAAU4D,EAAA1D,CAAA,EAAA0D,EAAAC,CAAA,EAAAD,EAAAE,CAAA,EAAAF,EAAAvD,CAAA,EAAAuD,EAAAG,CAAA,EAAAH,EAAAI,CAAA,EAAAJ,EAAAK,CAAA,CAAA,CAAA,CAAA,iCAAVjE,EAAUkE,QAAVlE,EAAUmE,UAAAC,WADG,MAAM,CAAA,CAAA,SACnBpE,CAAU,GAAA", "names": ["OcrService", "constructor", "Entity", "Filter", "PromanState", "Dialog", "Toast", "Request", "store", "ocrAction", "open", "InputDialogComponent", "header", "mainField", "name", "key", "type", "config", "multiple", "then", "result", "file", "length", "post", "mediaUrl", "id", "newId", "response", "text", "copyToClipboard", "console", "log", "TextPreviewDialogComponent", "disableCopy", "disablePrint", "invoiceAnalyze", "options", "typeOptions", "parameters", "files", "ocrEntityInterface", "analyzeInvoice", "analysisResponse", "to", "catch", "e", "pop", "error", "get", "purchaseEntityInterface", "getPurchaseTypes", "map", "item", "mapOptionTranslate", "translate", "select", "getPublicSystemOptions", "subscribe", "value", "media_server", "\u0275\u0275inject", "FilterService", "PromanStateService", "ToastService", "RequestService", "Store", "factory", "\u0275fac", "providedIn"] }