|
|
@@ -107,8 +107,19 @@
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
- <div class="text-subtitle1 q-mt-lg q-mb-md">
|
|
|
- Dados do Contrato
|
|
|
+ <div class="row items-center justify-between q-mt-lg q-mb-md">
|
|
|
+ <div class="text-subtitle1">
|
|
|
+ Dados do Contrato
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <q-toggle
|
|
|
+ v-model="isAutomaticProtocol"
|
|
|
+ color="primary"
|
|
|
+ label="Protocolo automático"
|
|
|
+ left-label
|
|
|
+ dense
|
|
|
+ @update:model-value="handleToggleAutomaticProtocol"
|
|
|
+ />
|
|
|
</div>
|
|
|
|
|
|
<div class="row q-col-gutter-sm">
|
|
|
@@ -116,6 +127,8 @@
|
|
|
<DefaultInput
|
|
|
v-model="form.protocol"
|
|
|
v-model:error="validationErrors.protocol"
|
|
|
+ :disable="isAutomaticProtocol"
|
|
|
+ :loading="loadingProtocol"
|
|
|
label="Protocolo"
|
|
|
:rules="[inputRules.max(255)]"
|
|
|
/>
|
|
|
@@ -422,13 +435,14 @@ import {
|
|
|
|
|
|
import {
|
|
|
createStudentContract,
|
|
|
+ getNextContractProtocol,
|
|
|
updateStudentContract,
|
|
|
} from "src/api/studentContract";
|
|
|
|
|
|
import { computed, nextTick, onMounted, ref, useTemplateRef, watch } from "vue";
|
|
|
import { formatDateDMYtoYMD, formatDateYMDtoDMY } from "src/helpers/utils";
|
|
|
import { getStudentsForSelect } from "src/api/student";
|
|
|
-import { getUnitMe } from "src/api/unit";
|
|
|
+import { getUnitMe, updateUnitMe } from "src/api/unit";
|
|
|
import { getUnitPackagesForSelect } from "src/api/package";
|
|
|
import { permissionStore } from "src/stores/permission";
|
|
|
import { useDialogPluginComponent, useQuasar } from "quasar";
|
|
|
@@ -481,6 +495,8 @@ const scrollAreaRef = useTemplateRef("scrollAreaRef");
|
|
|
const dateConfirmationOpen = ref(false);
|
|
|
const dateOverrideConfirmed = ref(false);
|
|
|
const filteredStudents = ref([]);
|
|
|
+const isAutomaticProtocol = ref(true);
|
|
|
+const loadingProtocol = ref(false);
|
|
|
const packages = ref([]);
|
|
|
const restoringDefaultDates = ref(false);
|
|
|
const selectedStudent = ref(props.student);
|
|
|
@@ -1042,6 +1058,36 @@ watch(
|
|
|
},
|
|
|
);
|
|
|
|
|
|
+const handleToggleAutomaticProtocol = async (value) => {
|
|
|
+ try {
|
|
|
+ await updateUnitMe({ automatic_protocol: value });
|
|
|
+
|
|
|
+ if (unitDetails.value) {
|
|
|
+ unitDetails.value.automatic_protocol = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (store.selectedUnit) {
|
|
|
+ store.selectedUnit.automatic_protocol = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (value && !props.contract) {
|
|
|
+ loadingProtocol.value = true;
|
|
|
+ try {
|
|
|
+ const next = await getNextContractProtocol();
|
|
|
+ form.protocol = next?.protocol ?? "000001";
|
|
|
+ } finally {
|
|
|
+ loadingProtocol.value = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error("Falha ao salvar configuração de protocolo automático:", error);
|
|
|
+ $q.notify({
|
|
|
+ message: "Não foi possível atualizar a preferência de protocolo da unidade.",
|
|
|
+ type: "negative",
|
|
|
+ });
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
onMounted(async () => {
|
|
|
const unitRequest = getUnitMe().catch((error) => {
|
|
|
console.error("Falha ao carregar os dados da unidade:", error);
|
|
|
@@ -1062,6 +1108,21 @@ onMounted(async () => {
|
|
|
|
|
|
unitDetails.value = unitData ?? store.selectedUnit ?? {};
|
|
|
|
|
|
+ isAutomaticProtocol.value = unitDetails.value?.automatic_protocol ?? true;
|
|
|
+
|
|
|
+ if (!props.contract && isAutomaticProtocol.value) {
|
|
|
+ loadingProtocol.value = true;
|
|
|
+ try {
|
|
|
+ const next = await getNextContractProtocol();
|
|
|
+ form.protocol = next?.protocol ?? "000001";
|
|
|
+ } catch (error) {
|
|
|
+ console.error("Falha ao carregar próximo protocolo:", error);
|
|
|
+ form.protocol = "000001";
|
|
|
+ } finally {
|
|
|
+ loadingProtocol.value = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
students.value = unitStudents;
|
|
|
filteredStudents.value = unitStudents;
|
|
|
});
|