Browse Source

ajuste add importacao no layout do parceiro

Gustavo Zanatta 1 week ago
parent
commit
abaee51ca1

+ 5 - 5
src/i18n/locales/en.json

@@ -995,10 +995,10 @@
     "inactivated": "Inactivated",
     "inactivated": "Inactivated",
     "no_history": "No imports recorded"
     "no_history": "No imports recorded"
   },
   },
-  "import_partner": {
-  "import_exams": "Import Exams",
-  "import_exams_result": "Import completed. Exams created: {created}. Exams updated: {updated}.",
-  "import_exams_processing": "The exam import is being processed.",
-  "import_exams_error": "Unable to import the exams."
+  "import_parceiro": {
+  "import_exames": "Import Exams",
+  "import_exames_result": "Import completed. Exams created: {created}. Exams updated: {updated}.",
+  "import_exames_processing": "The exam import is being processed.",
+  "import_exames_error": "Unable to import the exams."
 }
 }
 }
 }

+ 5 - 5
src/i18n/locales/es.json

@@ -995,10 +995,10 @@
     "inactivated": "Desactivados",
     "inactivated": "Desactivados",
     "no_history": "Ninguna importación registrada"
     "no_history": "Ninguna importación registrada"
   },
   },
-  "import_partner": {
-    "import_exams": "Importar Exámenes",
-    "import_exams_result": "Importación completada. Exámenes creados: {created}. Exámenes actualizados: {updated}.",
-    "import_exams_processing": "La importación de los exámenes está siendo procesada.",
-    "import_exams_error": "No fue posible importar los exámenes."
+  "import_parceiro": {
+    "import_exames": "Importar Exámenes",
+    "import_exames_result": "Importación completada. Exámenes creados: {created}. Exámenes actualizados: {updated}.",
+    "import_exames_processing": "La importación de los exámenes está siendo procesada.",
+    "import_exames_error": "No fue posible importar los exámenes."
   }
   }
 }
 }

+ 112 - 1
src/pages/parceiros-convenios/ParceiroDadosPage.vue

@@ -278,6 +278,26 @@
         >
         >
           <div class="bg-violet-light q-pb-md">
           <div class="bg-violet-light q-pb-md">
             <div class="row justify-end q-mb-sm q-gutter-sm">
             <div class="row justify-end q-mb-sm q-gutter-sm">
+              <input
+                ref="importExamesInput"
+                type="file"
+                accept=".xlsx,.csv"
+                class="hidden"
+                @change="onExamesFileSelected"
+              />
+
+              <q-btn
+                v-if="serviceTab.serviceType === 'exame'"
+                unelevated
+                icon="mdi-upload"
+                :label="$t('import_parceiro.import_exames')"
+                padding="6px 12px"
+                :disable="!partnerId"
+                :loading="importingExames"
+                class="btn-gradient"
+                @click="onImportExamesClick"
+              />
+
               <q-btn
               <q-btn
                 unelevated
                 unelevated
                 icon="mdi-plus"
                 icon="mdi-plus"
@@ -342,7 +362,9 @@ import {
   uploadMyPartnerMedia,
   uploadMyPartnerMedia,
   deleteMyPartnerMedia,
   deleteMyPartnerMedia,
 } from "src/api/partnerAgreement";
 } from "src/api/partnerAgreement";
-import { getServicesByPartner } from "src/api/partnerAgreementService";
+import { permissionStore } from "src/stores/permission";
+import { getServicesByPartner, importServices } from "src/api/partnerAgreementService";
+import { useImportPoller } from "src/composables/useImportPoller";
 import { formatToBRLCurrencyOrDash } from "src/helpers/utils";
 import { formatToBRLCurrencyOrDash } from "src/helpers/utils";
 import axios from "axios";
 import axios from "axios";
 
 
@@ -361,6 +383,7 @@ const $q     = useQuasar();
 const { t }  = useI18n();
 const { t }  = useI18n();
 const { prepareFile } = useMediaFile();
 const { prepareFile } = useMediaFile();
 const { inputRules } = useInputRules();
 const { inputRules } = useInputRules();
+const permission_store = permissionStore();
 
 
 const loadingPage = ref(true);
 const loadingPage = ref(true);
 const partner     = ref(null);
 const partner     = ref(null);
@@ -607,6 +630,87 @@ const loadServices = async () => {
   }
   }
 };
 };
 
 
+const onImportExamesClick = () => {
+  if (!permission_store.getAccess("parceiro.servico", "add")) {
+    $q.notify({
+      type: "negative",
+      message: t("validation.permissions.add"),
+    });
+    return;
+  }
+
+  if (!partnerId.value) {
+    return;
+  }
+
+  const input = importExamesInput.value?.[0];
+
+  if (!input) {
+    console.error("Input de importação de exames não encontrado.");
+    return;
+  }
+
+  input.value = null;
+  input.click();
+};
+
+const onExamesFileSelected = async (event) => {
+  const file = event.target.files?.[0];
+
+  if (!file) {
+    return;
+  }
+
+  if (!partnerId.value) {
+    return;
+  }
+
+  try {
+    const { import_id } = await importServices(
+      partnerId.value,
+      file,
+    );
+
+    startExamesPolling(import_id, {
+      onComplete: async (stats) => {
+        $q.notify({
+          type: "positive",
+          message: t("import_parceiro.import_exames_result", {
+            created: stats?.created ?? 0,
+            updated: stats?.updated ?? 0,
+          }),
+          timeout: 7000,
+        });
+
+        await loadServices();
+      },
+
+      onError: () => {
+        $q.notify({
+          type: "negative",
+          message: t("http.errors.failed"),
+        });
+      },
+
+      onTimeout: () => {
+        $q.notify({
+          type: "warning",
+          message: t("import_parceiro.import_exames_processing"),
+        });
+      },
+    });
+  } catch (error) {
+    console.error(error);
+
+    $q.notify({
+      type: "negative",
+      message: t("http.errors.failed"),
+    });
+  } finally {
+    event.target.value = null;
+  }
+};
+
 const onAddService = () => {
 const onAddService = () => {
   router.push({
   router.push({
     name:   "ParceiroDadosServicoPage",
     name:   "ParceiroDadosServicoPage",
@@ -622,6 +726,13 @@ const onEditService = (svc) => {
   });
   });
 };
 };
 
 
+//import de exames/serviços
+const importExamesInput = useTemplateRef("importExamesInput");
+const {
+  polling: importingExames,
+  start: startExamesPolling,
+} = useImportPoller();
+
 // ─── Populate ────────────────────────────────────────────────────────────────
 // ─── Populate ────────────────────────────────────────────────────────────────
 const populateForms = (p) => {
 const populateForms = (p) => {
   if (!p) return;
   if (!p) return;