Bläddra i källkod

feat(financial): streamline charges and lock paid status

ebagabee 5 dagar sedan
förälder
incheckning
ebe2689169

+ 24 - 19
src/pages/financial/AccountsPayablePage.vue

@@ -61,11 +61,26 @@
               dense
               no-caps
               unelevated
-              :disable="!canEdit"
-              :loading="reopeningId === row.id"
+              :disable="!canEdit || row.status === 'paid'"
               @click.stop="changeStatus(row)"
             >
-              <q-tooltip v-if="canEdit">Clique para alterar o status</q-tooltip>
+              <q-tooltip v-if="canEdit && row.status !== 'paid'">Dar baixa</q-tooltip>
+            </q-btn>
+          </q-td>
+        </template>
+        <template #body-cell-actions="{ row }">
+          <q-td auto-width>
+            <q-btn
+              v-if="row.invoice_url"
+              round
+              dense
+              flat
+              color="teal-7"
+              icon="mdi-open-in-new"
+              aria-label="Abrir cobrança"
+              @click="openInvoice(row)"
+            >
+              <q-tooltip>Abrir cobrança no Asaas</q-tooltip>
             </q-btn>
           </q-td>
         </template>
@@ -178,7 +193,6 @@ import {
   getPayablesMe,
   createPayableMe,
   settlePayableMe,
-  reopenPayableMe,
 } from "src/api/unit_payable";
 
 import DefaultHeaderPage from "src/components/layout/DefaultHeaderPage.vue";
@@ -203,7 +217,6 @@ const rows = ref([]);
 const settleDialog = ref(false);
 const selected = ref(null);
 const settling = ref(false);
-const reopeningId = ref(null);
 const settleForm = ref({ payment_date: null, payment_date_iso: null, discount: 0, fine: 0 });
 
 const createDialog = ref(false);
@@ -217,6 +230,7 @@ const columns = [
   { name: "value", label: "Valor", field: "value", align: "left" },
   { name: "due_date", label: "Vencimento", field: "due_date", align: "left" },
   { name: "status", label: "Status", field: "status", align: "left" },
+  { name: "actions", label: "Ações", field: "actions", align: "right" },
 ];
 
 function formatCurrency(value) {
@@ -276,8 +290,11 @@ function openSettle(row) {
 }
 
 function changeStatus(row) {
-  if (row.status === "paid") onReopen(row);
-  else openSettle(row);
+  if (row.status !== "paid") openSettle(row);
+}
+
+function openInvoice(row) {
+  window.open(row.invoice_url, "_blank");
 }
 
 async function onSettle() {
@@ -298,18 +315,6 @@ async function onSettle() {
   }
 }
 
-async function onReopen(row) {
-  reopeningId.value = row.id;
-  try {
-    await reopenPayableMe(row.id);
-    await loadData();
-  } catch (e) {
-    console.error(e);
-  } finally {
-    reopeningId.value = null;
-  }
-}
-
 function openCreate() {
   const today = new Date();
   createForm.value = {

+ 8 - 28
src/pages/financial/AccountsReceivablePage.vue

@@ -49,11 +49,10 @@
               dense
               no-caps
               unelevated
-              :disable="!canEdit"
-              :loading="reopeningId === row.id"
+              :disable="!canEdit || row.status === 'paid'"
               @click.stop="changeStatus(row)"
             >
-              <q-tooltip v-if="canEdit">Clique para alterar o status</q-tooltip>
+              <q-tooltip v-if="canEdit && row.status !== 'paid'">Dar baixa</q-tooltip>
             </q-btn>
           </q-td>
         </template>
@@ -80,15 +79,16 @@
                   row.status !== 'cancelled'
                 "
                 color="deep-purple-5"
-                label="Gerar cobrança"
                 icon="mdi-cash-fast"
+                round
                 dense
-                no-caps
                 outline
-                class="q-px-sm"
+                aria-label="Gerar cobrança"
                 :loading="chargingId === row.id"
                 @click="onCharge(row)"
-              />
+              >
+                <q-tooltip>Gerar cobrança no Asaas</q-tooltip>
+              </q-btn>
             </div>
           </q-td>
         </template>
@@ -229,11 +229,9 @@ import { computed, onMounted, ref } from "vue";
 import {
   getReceivablesMe,
   settleReceivableMe,
-  reopenReceivableMe,
   chargeReceivableMe,
   createManualReceivableMe,
   settleManualReceivableMe,
-  reopenManualReceivableMe,
 } from "src/api/unit_receivable";
 import { getStudentsForSelect } from "src/api/student";
 import { getPlanAccountsForSelect } from "src/api/financial_plan_account";
@@ -260,7 +258,6 @@ const rows = ref([]);
 const settleDialog = ref(false);
 const selected = ref(null);
 const settling = ref(false);
-const reopeningId = ref(null);
 const chargingId = ref(null);
 
 const settleForm = ref({ payment_date: null, payment_date_iso: null, discount: 0, fine: 0 });
@@ -411,8 +408,7 @@ function openSettle(row) {
 }
 
 function changeStatus(row) {
-  if (row.status === "paid") onReopen(row);
-  else openSettle(row);
+  if (row.status !== "paid") openSettle(row);
 }
 
 async function onSettle() {
@@ -438,22 +434,6 @@ async function onSettle() {
   }
 }
 
-async function onReopen(row) {
-  reopeningId.value = row.id;
-  try {
-    if (row.source === "manual") {
-      await reopenManualReceivableMe(row.realId);
-    } else {
-      await reopenReceivableMe(row.realId);
-    }
-    await loadData();
-  } catch (e) {
-    console.error(e);
-  } finally {
-    reopeningId.value = null;
-  }
-}
-
 async function onCharge(row) {
   chargingId.value = row.id;
   try {