psi_mmobile

Untitled

Oct 21st, 2025
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   onFileDropped(event) {
  2.     const results = [];
  3.     if (!this.personsPresenceService.readOnly) {
  4.       for (let i = 0; i < event.length; i++) {
  5.         const file = event[i];
  6.         if (
  7.           file.type === 'application/pdf' ||
  8.           file.type === 'image/jpeg' ||
  9.           file.type === 'image/png'
  10.         ) {
  11.           this.personsPresence.analysing = true;
  12.           this.personsPresenceService.analysis(file).subscribe(
  13.             (detectedInfo: any) => {
  14.               // make document
  15.               if (detectedInfo.Expiration) {
  16.                 const dmy = detectedInfo.Expiration.split('/');
  17.                 detectedInfo.Expiration = new Date(dmy[2], dmy[1] - 1, dmy[0]);
  18.               }
  19.               if (detectedInfo.Issue) {
  20.                 const dmy = detectedInfo.Issue.split('/');
  21.                 detectedInfo.Issue = new Date(dmy[2], dmy[1] - 1, dmy[0]);
  22.               }
  23.               const document = {
  24.                 data: {
  25.                   name: file.name,
  26.                   document_type_id: detectedInfo.detected_types,
  27.                   expiration: detectedInfo.Expiration,
  28.                   documentDate: detectedInfo.Issue,
  29.                   traxxeo_ai_verified: 'Y',
  30.                   lm_name: this.userDataService.username,
  31.                   validated: true,
  32.                   validation_date: new Date(),
  33.                   validation_gui_user_id: localStorage.guiUserId,
  34.                   validation_person: this.userDataService.username,
  35.                   file
  36.                 }
  37.               };
  38.  
  39.               // find the person attached to this file
  40.               let belongPerson = this.ListPersonGridComponent.grid.data.find(
  41.                 (person) =>
  42.                   (person.niss &&
  43.                     person.niss === detectedInfo.NISS &&
  44.                     (!detectedInfo.BCE ||
  45.                       person.real_employer_tin === detectedInfo.BCE)) ||
  46.                   (person.limosa && person.limosa === detectedInfo.limosa)
  47.               );
  48.  
  49.               const result = {
  50.                 belongPerson,
  51.                 fileData: document.data,
  52.                 detectedInfo,
  53.                 newPerson: false
  54.               };
  55.               if (belongPerson) {
  56.                 results.push(result);
  57.  
  58.                 // check document
  59.                 const verified = this.personsPresence.checkDocument(
  60.                   detectedInfo,
  61.                   belongPerson.data.niss
  62.                 );
  63.                 document.data.traxxeo_ai_verified = verified;
  64.  
  65.                 // update person according to info find on doc
  66.                 if (verified === 'Y') {
  67.                   this.personsPresence.updateDetectedInfoPerson(
  68.                     belongPerson,
  69.                     detectedInfo
  70.                   );
  71.                 }
  72.                 this.personsPresenceService
  73.                   .updatePerson(belongPerson)
  74.                   .subscribe(
  75.                     () => {
  76.                       // add document to the person attached to this file
  77.                       this.personsPresenceService
  78.                         .addAttachDoc(document, belongPerson.data.person_id)
  79.                         .subscribe(
  80.                           () => {
  81.                             // sync with DB for updated person
  82.                             this.personsPresenceService
  83.                               .getPersons(belongPerson.data.person_id, null)
  84.                               .then(
  85.                                 (persons: any) => {
  86.                                   const personUpdated = persons.items[0];
  87.                                   Object.assign(
  88.                                     this.personsPresence.persons.find(
  89.                                       (person) =>
  90.                                         person.person_id ===
  91.                                         personUpdated.person_id
  92.                                     ),
  93.                                     personUpdated
  94.                                   );
  95.                                   this.personsPresence.parsePerson(
  96.                                     personUpdated
  97.                                   );
  98.                                   this.ListPersonGridComponent.grid.store.add(
  99.                                     personUpdated
  100.                                   );
  101.                                   this.ListPersonGridComponent.grid.store.filter();
  102.                                 },
  103.                                 (error) => {
  104.                                   this.notificationService.errorToast(
  105.                                     'get person',
  106.                                     error
  107.                                   );
  108.                                 }
  109.                               );
  110.                           },
  111.                           (error) => {
  112.                             this.notificationService.errorToast(
  113.                               'new doc',
  114.                               error
  115.                             );
  116.                           }
  117.                         );
  118.                     },
  119.                     (error) => {
  120.                       this.notificationService.errorToast(
  121.                         'update person',
  122.                         error
  123.                       );
  124.                     }
  125.                   );
  126.               } else if (detectedInfo.NISS || detectedInfo.limosa) {
  127.                 // create new person
  128.                 belongPerson = {
  129.                   last_name: detectedInfo.lastName,
  130.                   first_name: detectedInfo.firstName,
  131.                   name: detectedInfo.lastName + ' ' + detectedInfo.firstName,
  132.                   niss: detectedInfo.NISS,
  133.                   real_employer_name: detectedInfo.companyName,
  134.                   real_employer_tin: detectedInfo.BCE,
  135.                   limosa: detectedInfo.limosa,
  136.                   category_name: this.personsPresence.getDefaultCategory().name,
  137.                   person_status_id: 0,
  138.                   is_blacklisted: 'N'
  139.                 };
  140.  
  141.                 result.belongPerson = { data: belongPerson };
  142.                 result.newPerson = true;
  143.                 results.push(result);
  144.  
  145.                 this.personsPresenceService
  146.                   .createPerson(belongPerson)
  147.                   .subscribe(
  148.                     (res: any) => {
  149.                       this.personsPresenceService
  150.                         .addAttachDoc(document, +res.person_id)
  151.                         .subscribe(
  152.                           () => {
  153.                             // sync with DB for updated person
  154.                             this.personsPresenceService
  155.                               .getPersons(+res.person_id, null)
  156.                               .then(
  157.                                 (persons: any) => {
  158.                                   const personUpdated = persons.items[0];
  159.                                   this.personsPresence.persons.push(
  160.                                     personUpdated
  161.                                   );
  162.                                   this.personsPresence.parsePerson(
  163.                                     personUpdated
  164.                                   );
  165.                                   this.ListPersonGridComponent.grid.store.add(
  166.                                     personUpdated
  167.                                   );
  168.                                   this.ListPersonGridComponent.grid.selectRow(
  169.                                     { record: personUpdated.id },
  170.                                     true
  171.                                   );
  172.                                   this.ListPersonGridComponent.grid.store.filter();
  173.                                 },
  174.                                 (error) => {
  175.                                   this.notificationService.errorToast(
  176.                                     'get person',
  177.                                     error
  178.                                   );
  179.                                 }
  180.                               );
  181.                           },
  182.                           (error) => {
  183.                             this.notificationService.errorToast(
  184.                               'new doc',
  185.                               error
  186.                             );
  187.                           }
  188.                         );
  189.                     },
  190.                     (error) => {
  191.                       this.notificationService.errorToast('new person', error);
  192.                     }
  193.                   );
  194.               } else {
  195.                 // unattached document
  196.                 results.push(result);
  197.               }
  198.  
  199.               if (i === event.length - 1) {
  200.                 this.openDropResult(results);
  201.                 this.personsPresence.analysing = false;
  202.               }
  203.             },
  204.             (error) => {
  205.               if (i === event.length - 1) {
  206.                 this.openDropResult(results);
  207.                 this.personsPresence.analysing = false;
  208.               }
  209.               this.notificationService.errorToast('analysis', error);
  210.             }
  211.           );
  212.         } else {
  213.           const document = {
  214.             data: {
  215.               name: file.name,
  216.               file
  217.             }
  218.           };
  219.           results.push({
  220.             belongPerson: null,
  221.             fileData: document.data,
  222.             detectedInfo: null,
  223.             newPerson: false
  224.           });
  225.           if (i === event.length - 1) {
  226.             this.openDropResult(results);
  227.             this.personsPresence.analysing = false;
  228.           }
  229.         }
  230.       }
  231.     }
  232.   }
Add Comment
Please, Sign In to add comment