Skip to content

Commit

Permalink
feat: sync volume for report using data in contract
Browse files Browse the repository at this point in the history
  • Loading branch information
newarifrh committed Sep 6, 2024
1 parent 13fd66d commit f6c0c98
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
29 changes: 29 additions & 0 deletions src/api/contractApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,35 @@ export const getContractStatistic = async () => {
return result.data;
};

export const getContractActivityVolume = async (
outputId: string,
period: string
) => {
const auth = useAuthStore();

const query = {
outputId: outputId,
period: period,
};

const response = await fetch(
`${BASE_URL}/v1/contracts/activity/volume?` + new URLSearchParams(query),
{
headers: {
Authorization: `Bearer ${auth.token}`,
},
}
);

const result = await response.json();

if (!response.ok) {
throw new Error(result.message);
}

return result.data;
};

export const printContracts = async (payload: any) => {
const auth = useAuthStore();

Expand Down
19 changes: 15 additions & 4 deletions src/components/report/FormReportByActivity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
<el-select v-model="form.output.outputId" placeholder="Pilih Nama Output" clearable filterable>
<el-option v-for="output in outputs" :key="output._id" :label="output.name" :value="output._id">
<span style="float: left">{{ output.name }}</span>
<span
style="
<span style="
float: right;
color: var(--el-text-color-secondary);
font-size: 13px;
"
>
">
{{ output.activity.name }}
</span>
</el-option>
Expand Down Expand Up @@ -44,6 +42,7 @@
</el-upload>
<el-button type="success" @click="downloadMasterPartner()">Unduh Master Data Mitra</el-button>
<el-button @click="downloadTemplateImportPartner()">Template Impor Mitra</el-button>
<el-button @click="syncPartner()">Sinkronisasi Mitra</el-button>
</div>
</template>
</el-card>
Expand All @@ -64,6 +63,7 @@ import { getOutputs } from "@/api/outputApi";
import { generatePeriods } from "@/utils/date";
import { downloadPartners, getPartners } from "@/api/partnerApi";
import { downloadTemplatePartner } from "@/api/reportApi";
import { getContractActivityVolume } from "@/api/contractApi";
const formRef = ref<FormInstance>();
const fileInput = ref<UploadInstance>();
Expand Down Expand Up @@ -122,6 +122,17 @@ const downloadTemplateImportPartner = () => {
downloadTemplatePartner()
}
const syncPartner = async () => {
const result = await getContractActivityVolume(form.output.outputId, form.contract.period)
result.forEach((rawPartner: any) => {
form.partners.push({
partnerId: rawPartner.partnerId,
total: rawPartner.volume,
});
});
}
const handleFileChange = async (uploadFile: UploadFile, uploadFiles: UploadFiles) => {
const raw = await uploadFile.raw?.text();
Expand Down

0 comments on commit f6c0c98

Please sign in to comment.