feat: add customer export
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 5s
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 5s
This commit is contained in:
parent
c9c9ad927c
commit
c749e91ffa
3 changed files with 122 additions and 1 deletions
|
|
@ -548,6 +548,19 @@ async function openSpecificEmployee(id: string) {
|
||||||
employeeFormState.value.drawerModal = true;
|
employeeFormState.value.drawerModal = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function triggerExport() {
|
||||||
|
switch (currentTab.value) {
|
||||||
|
case 'employer':
|
||||||
|
customerStore.customerExport({ pageSize: 10000 });
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'employee':
|
||||||
|
employeeStore.employeeExport({ pageSize: 10000 });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: When in employee form, if select address same as customer then auto fill
|
// TODO: When in employee form, if select address same as customer then auto fill
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
@ -801,7 +814,7 @@ const emptyCreateDialog = ref(false);
|
||||||
outlined
|
outlined
|
||||||
dense
|
dense
|
||||||
:label="$t('general.search')"
|
:label="$t('general.search')"
|
||||||
class="col col-md-3"
|
class="col col-md-3 q-mr-sm"
|
||||||
:bg-color="$q.dark.isActive ? 'dark' : 'white'"
|
:bg-color="$q.dark.isActive ? 'dark' : 'white'"
|
||||||
v-model="inputSearch"
|
v-model="inputSearch"
|
||||||
debounce="200"
|
debounce="200"
|
||||||
|
|
@ -843,6 +856,13 @@ const emptyCreateDialog = ref(false);
|
||||||
</template>
|
</template>
|
||||||
</q-input>
|
</q-input>
|
||||||
|
|
||||||
|
<SaveButton
|
||||||
|
icon-only
|
||||||
|
class="q-mr-auto"
|
||||||
|
:icon="'material-symbols:download'"
|
||||||
|
@click.stop="triggerExport()"
|
||||||
|
/>
|
||||||
|
|
||||||
<div class="row col-md-5" style="white-space: nowrap">
|
<div class="row col-md-5" style="white-space: nowrap">
|
||||||
<q-select
|
<q-select
|
||||||
v-if="$q.screen.gt.sm"
|
v-if="$q.screen.gt.sm"
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import {
|
||||||
CitizenPayload,
|
CitizenPayload,
|
||||||
} from './types';
|
} from './types';
|
||||||
import { Employee } from '../employee/types';
|
import { Employee } from '../employee/types';
|
||||||
|
import { getToken } from 'src/services/keycloak';
|
||||||
import { baseUrl, manageAttachment, manageFile, manageMeta } from '../utils';
|
import { baseUrl, manageAttachment, manageFile, manageMeta } from '../utils';
|
||||||
|
|
||||||
const useCustomerStore = defineStore('api-customer', () => {
|
const useCustomerStore = defineStore('api-customer', () => {
|
||||||
|
|
@ -472,6 +473,52 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function customerExport(params: {
|
||||||
|
customerType?: CustomerType;
|
||||||
|
query?: string;
|
||||||
|
status?: 'CREATED' | 'ACTIVE' | 'INACTIVE';
|
||||||
|
page?: number;
|
||||||
|
pageSize?: number;
|
||||||
|
includeBranch?: boolean;
|
||||||
|
company?: boolean;
|
||||||
|
activeBranchOnly?: boolean;
|
||||||
|
startDate?: string | Date;
|
||||||
|
endDate?: string | Date;
|
||||||
|
}) {
|
||||||
|
let url = baseUrl + '/' + 'customer-export';
|
||||||
|
|
||||||
|
const queryParams = new URLSearchParams(
|
||||||
|
Object.keys(params).reduce((acc: Record<string, string>, key) => {
|
||||||
|
const value = params[key as keyof typeof params];
|
||||||
|
if (value !== undefined && value !== null && value !== '') {
|
||||||
|
const stringValue =
|
||||||
|
typeof value === 'boolean' || typeof value === 'number'
|
||||||
|
? String(value)
|
||||||
|
: value instanceof Date
|
||||||
|
? value.toISOString()
|
||||||
|
: String(value);
|
||||||
|
acc[key] = stringValue;
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, {}),
|
||||||
|
);
|
||||||
|
|
||||||
|
url += '?' + queryParams.toString();
|
||||||
|
|
||||||
|
const res = await fetch(url, {
|
||||||
|
headers: { ['Authorization']: 'Bearer ' + (await getToken()) },
|
||||||
|
});
|
||||||
|
const text = await res.json();
|
||||||
|
const blob = new Blob([text], { type: 'text/csv' });
|
||||||
|
if (res.ok && blob) {
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.download = 'customer-report' + '.csv';
|
||||||
|
a.href = window.URL.createObjectURL(blob);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
|
|
||||||
|
|
@ -498,6 +545,8 @@ const useCustomerStore = defineStore('api-customer', () => {
|
||||||
fetchBranchEmployee,
|
fetchBranchEmployee,
|
||||||
|
|
||||||
deleteAttachment,
|
deleteAttachment,
|
||||||
|
|
||||||
|
customerExport,
|
||||||
...attachmentManager,
|
...attachmentManager,
|
||||||
...fileManager,
|
...fileManager,
|
||||||
...metaManager,
|
...metaManager,
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import {
|
||||||
EmployeeVisaPayload,
|
EmployeeVisaPayload,
|
||||||
} from './types';
|
} from './types';
|
||||||
import { CustomerBranch } from '../customer/types';
|
import { CustomerBranch } from '../customer/types';
|
||||||
|
import { getToken } from 'src/services/keycloak';
|
||||||
import { baseUrl, manageAttachment, manageFile, manageMeta } from '../utils';
|
import { baseUrl, manageAttachment, manageFile, manageMeta } from '../utils';
|
||||||
|
|
||||||
const useEmployeeStore = defineStore('api-employee', () => {
|
const useEmployeeStore = defineStore('api-employee', () => {
|
||||||
|
|
@ -469,6 +470,55 @@ const useEmployeeStore = defineStore('api-employee', () => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function employeeExport(params: {
|
||||||
|
zipCode?: string;
|
||||||
|
gender?: string;
|
||||||
|
status?: Status;
|
||||||
|
visa?: boolean;
|
||||||
|
passport?: boolean;
|
||||||
|
customerId?: string;
|
||||||
|
customerBranchId?: string;
|
||||||
|
query?: string;
|
||||||
|
page?: number;
|
||||||
|
pageSize?: number;
|
||||||
|
activeOnly?: boolean;
|
||||||
|
startDate?: string | Date;
|
||||||
|
endDate?: string | Date;
|
||||||
|
}) {
|
||||||
|
let url = baseUrl + '/' + 'employee-export';
|
||||||
|
|
||||||
|
const queryParams = new URLSearchParams(
|
||||||
|
Object.keys(params).reduce((acc: Record<string, string>, key) => {
|
||||||
|
const value = params[key as keyof typeof params];
|
||||||
|
if (value !== undefined && value !== null && value !== '') {
|
||||||
|
const stringValue =
|
||||||
|
typeof value === 'boolean' || typeof value === 'number'
|
||||||
|
? String(value)
|
||||||
|
: value instanceof Date
|
||||||
|
? value.toISOString()
|
||||||
|
: String(value);
|
||||||
|
acc[key] = stringValue;
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, {}),
|
||||||
|
);
|
||||||
|
|
||||||
|
url += '?' + queryParams.toString();
|
||||||
|
|
||||||
|
const res = await fetch(url, {
|
||||||
|
headers: { ['Authorization']: 'Bearer ' + (await getToken()) },
|
||||||
|
});
|
||||||
|
const text = await res.json();
|
||||||
|
const blob = new Blob([text], { type: 'text/csv' });
|
||||||
|
if (res.ok && blob) {
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.download = 'employee-report' + '.csv';
|
||||||
|
a.href = window.URL.createObjectURL(blob);
|
||||||
|
a.click();
|
||||||
|
a.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
globalOption,
|
globalOption,
|
||||||
|
|
@ -512,6 +562,8 @@ const useEmployeeStore = defineStore('api-employee', () => {
|
||||||
...attachmentManager,
|
...attachmentManager,
|
||||||
...fileManager,
|
...fileManager,
|
||||||
...metaManager,
|
...metaManager,
|
||||||
|
|
||||||
|
employeeExport,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue