ViewContractDialog.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <q-dialog ref="dialogRef" @hide="onDialogHide">
  3. <q-card
  4. class="q-dialog-plugin overflow-hidden"
  5. style="width: 100%; max-width: 1100px"
  6. >
  7. <DefaultDialogHeader
  8. title="Visualizar Contrato"
  9. @close="onDialogCancel"
  10. />
  11. <q-card-section>
  12. <div class="text-body2 q-mb-sm">Dados da Unidade</div>
  13. <div class="row q-col-gutter-x-sm">
  14. <DefaultInput
  15. :model-value="unitData.id"
  16. class="col-md-3 col-12"
  17. color="secondary"
  18. disable
  19. label="ID"
  20. label-color="secondary"
  21. />
  22. <DefaultInput
  23. :model-value="unitData.franchisee_name"
  24. class="col-md-3 col-12"
  25. color="secondary"
  26. disable
  27. label="Nome do Franqueado"
  28. label-color="secondary"
  29. />
  30. <DefaultInput
  31. :model-value="unitData.franchisee_document"
  32. class="col-md-3 col-12"
  33. color="secondary"
  34. disable
  35. label="CPF / CNH"
  36. label-color="secondary"
  37. />
  38. <DefaultInput
  39. :model-value="unitData.franchisee_birthday"
  40. class="col-md-3 col-12"
  41. color="secondary"
  42. disable
  43. label="Data de Nascimento"
  44. label-color="secondary"
  45. />
  46. </div>
  47. </q-card-section>
  48. <q-card-section>
  49. <div class="row q-col-gutter-sm">
  50. <DefaultInputDatePicker
  51. v-model:untreated-date="contractForm.start_date"
  52. class="col-md-3 col-12"
  53. color="secondary"
  54. disable
  55. label="Data de Início"
  56. label-color="secondary"
  57. />
  58. <DefaultInputDatePicker
  59. v-model:untreated-date="contractForm.end_date"
  60. class="col-md-3 col-12"
  61. color="secondary"
  62. disable
  63. label="Data de Fim"
  64. label-color="secondary"
  65. />
  66. <DefaultInput
  67. v-model="contractForm.invoice_due_date"
  68. class="col-md-3 col-12"
  69. color="secondary"
  70. disable
  71. label="Dia de Vencimento do Boleto"
  72. label-color="secondary"
  73. type="number"
  74. />
  75. <DefaultSelect
  76. v-model="contractForm.inhabitant_classification_id"
  77. class="col-md-3 col-12"
  78. color="secondary"
  79. disable
  80. emit-value
  81. fill-input
  82. hide-selected
  83. input-debounce="0"
  84. label="Faixa de Habitantes"
  85. label-color="secondary"
  86. map-options
  87. use-input
  88. :options="inhabitantOptions"
  89. />
  90. </div>
  91. <div class="row q-col-gutter-sm q-mt-xs">
  92. <DefaultCurrencyInput
  93. v-model="contractForm.tbr_fixed_value"
  94. class="col-md-3 col-12"
  95. color="secondary"
  96. disable
  97. label="TBR $"
  98. label-color="secondary"
  99. />
  100. <DefaultInput
  101. v-model="contractForm.tax_base_royalts"
  102. class="col-md-3 col-12"
  103. color="secondary"
  104. disable
  105. label="Taxa Base Royalties"
  106. label-color="secondary"
  107. type="number"
  108. >
  109. <template #append>
  110. <span class="text-secondary">%</span>
  111. </template>
  112. </DefaultInput>
  113. <DefaultInput
  114. v-model="contractForm.tax_base_fnm"
  115. class="col-md-3 col-12"
  116. color="secondary"
  117. disable
  118. label="Fundo Nacional de Marketing"
  119. label-color="secondary"
  120. type="number"
  121. >
  122. <template #append>
  123. <span class="text-secondary">%</span>
  124. </template>
  125. </DefaultInput>
  126. <DefaultInput
  127. v-model="contractForm.tax_base_maintenance"
  128. class="col-md-3 col-12"
  129. color="secondary"
  130. disable
  131. label="Taxa de Manutenção"
  132. label-color="secondary"
  133. type="number"
  134. >
  135. <template #append>
  136. <span class="text-secondary">%</span>
  137. </template>
  138. </DefaultInput>
  139. </div>
  140. </q-card-section>
  141. <q-card-section>
  142. <div class="text-body2 q-mb-sm">
  143. Histórico de Reajuste de Valores e TBR
  144. </div>
  145. <q-table
  146. dense
  147. flat
  148. no-data-label="Nenhum histórico disponível"
  149. row-key="id"
  150. :columns="historyColumns"
  151. :loading="loadingHistory"
  152. :pagination="{ rowsPerPage: 5 }"
  153. :rows="tbrHistory"
  154. />
  155. </q-card-section>
  156. <q-card-actions align="right">
  157. <q-btn color="primary" label="Fechar" @click="onDialogCancel" />
  158. </q-card-actions>
  159. </q-card>
  160. </q-dialog>
  161. </template>
  162. <script setup>
  163. import { onMounted, reactive, ref } from "vue";
  164. import { useDialogPluginComponent } from "quasar";
  165. import DefaultDialogHeader from "src/components/defaults/DefaultDialogHeader.vue";
  166. import DefaultInput from "src/components/defaults/DefaultInput.vue";
  167. import DefaultInputDatePicker from "src/components/defaults/DefaultInputDatePicker.vue";
  168. import DefaultCurrencyInput from "src/components/defaults/DefaultCurrencyInput.vue";
  169. import DefaultSelect from "src/components/defaults/DefaultSelect.vue";
  170. import { getFranchiseeContractTaxHistory } from "src/api/franchisee_contract";
  171. import { getInhabitantClassificationsForSelect } from "src/api/inhabitant_classification";
  172. import { getUnitMe } from "src/api/unit";
  173. defineEmits([...useDialogPluginComponent.emits]);
  174. const props = defineProps({
  175. contract: {
  176. type: Object,
  177. required: true,
  178. },
  179. unitId: {
  180. type: Number,
  181. required: true,
  182. },
  183. });
  184. const { dialogRef, onDialogHide, onDialogCancel } = useDialogPluginComponent();
  185. const loadingHistory = ref(false);
  186. const inhabitantOptions = ref([]);
  187. const tbrHistory = ref([]);
  188. const unitData = reactive({
  189. id: null,
  190. franchisee_birthday: null,
  191. franchisee_document: null,
  192. franchisee_name: null,
  193. });
  194. const contractForm = reactive({
  195. start_date: props.contract.start_date ?? null,
  196. end_date: props.contract.end_date ?? null,
  197. tbr_fixed_value: props.contract.tbr_fixed_value
  198. ? parseFloat(props.contract.tbr_fixed_value)
  199. : null,
  200. invoice_due_date: props.contract.invoice_due_date ?? null,
  201. inhabitant_classification_id:
  202. props.contract.inhabitant_classification_id ?? null,
  203. tax_base_royalts:
  204. props.contract.tbr_fixed_value_percentage != null
  205. ? parseFloat((props.contract.tbr_fixed_value_percentage * 100).toFixed(4))
  206. : null,
  207. tax_base_fnm:
  208. props.contract.marketing_fund_percentage != null
  209. ? parseFloat((props.contract.marketing_fund_percentage * 100).toFixed(4))
  210. : null,
  211. tax_base_maintenance:
  212. props.contract.maintance_tax_percentage != null
  213. ? parseFloat((props.contract.maintance_tax_percentage * 100).toFixed(4))
  214. : null,
  215. });
  216. const historyColumns = [
  217. { name: "id", label: "Id", field: "id", align: "left" },
  218. {
  219. name: "year",
  220. label: "Ano",
  221. field: (row) => new Date(row.created_at).getFullYear(),
  222. align: "left",
  223. },
  224. {
  225. name: "inhabitant_classification",
  226. label: "Faixa de Habitantes",
  227. field: "inhabitant_classification",
  228. align: "left",
  229. },
  230. {
  231. name: "tbr_fixed_value",
  232. label: "TBR",
  233. field: "tbr_fixed_value",
  234. align: "left",
  235. },
  236. {
  237. name: "marketing_fund_percentage",
  238. label: "FNM",
  239. field: (row) =>
  240. row.marketing_fund_percentage != null
  241. ? `${(row.marketing_fund_percentage * 100).toFixed(0)}%`
  242. : "-",
  243. align: "left",
  244. },
  245. {
  246. name: "maintance_tax_percentage",
  247. label: "Manutenção",
  248. field: (row) =>
  249. row.maintance_tax_percentage != null
  250. ? `${(row.maintance_tax_percentage * 100).toFixed(0)}%`
  251. : "-",
  252. align: "left",
  253. },
  254. ];
  255. async function loadData() {
  256. const [unit, classifications] = await Promise.all([
  257. getUnitMe(),
  258. getInhabitantClassificationsForSelect(),
  259. ]);
  260. unitData.id = unit.id;
  261. unitData.franchisee_name = unit.name_responsible;
  262. const firstPartner = unit.partners?.[0];
  263. if (firstPartner) {
  264. unitData.franchisee_document = firstPartner.cpf;
  265. unitData.franchisee_birthday = firstPartner.birth_date;
  266. }
  267. inhabitantOptions.value = classifications.map((c) => ({
  268. label: `${c.description} (${c.acronym})`,
  269. value: c.id,
  270. }));
  271. loadingHistory.value = true;
  272. try {
  273. tbrHistory.value = await getFranchiseeContractTaxHistory(props.contract.id);
  274. } finally {
  275. loadingHistory.value = false;
  276. }
  277. }
  278. onMounted(loadData);
  279. </script>