add delete group to persons list
This commit is contained in:
parent
e34d8e887b
commit
8ad24235c5
|
@ -1465,4 +1465,68 @@ class PersonsController extends AbstractController
|
||||||
}
|
}
|
||||||
return new Response(json_encode($rows));
|
return new Response(json_encode($rows));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route('/api/person/deletegroup', name: 'app_persons_delete_group', methods: ['POST'])]
|
||||||
|
public function app_persons_delete_group(
|
||||||
|
Extractor $extractor,
|
||||||
|
Request $request,
|
||||||
|
Access $access,
|
||||||
|
Log $log,
|
||||||
|
EntityManagerInterface $entityManager
|
||||||
|
): JsonResponse {
|
||||||
|
$acc = $access->hasRole('person');
|
||||||
|
if (!$acc) {
|
||||||
|
throw $this->createAccessDeniedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$params = json_decode($request->getContent(), true);
|
||||||
|
if (!isset($params['codes']) || !is_array($params['codes'])) {
|
||||||
|
return $this->json(['Success' => false, 'message' => 'لیست کدهای اشخاص ارسال نشده است'], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$hasIgnored = false;
|
||||||
|
$deletedCount = 0;
|
||||||
|
|
||||||
|
foreach ($params['codes'] as $code) {
|
||||||
|
$person = $entityManager->getRepository(Person::class)->findOneBy([
|
||||||
|
'bid' => $acc['bid'],
|
||||||
|
'code' => $code
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!$person) {
|
||||||
|
$hasIgnored = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// بررسی اسناد حسابداری
|
||||||
|
$docs = $entityManager->getRepository(HesabdariRow::class)->findBy(['bid' => $acc['bid'], 'person' => $person]);
|
||||||
|
if (count($docs) > 0) {
|
||||||
|
$hasIgnored = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// بررسی اسناد انبار
|
||||||
|
$storeDocs = $entityManager->getRepository(StoreroomTicket::class)->findBy(['bid' => $acc['bid'], 'Person' => $person]);
|
||||||
|
if (count($storeDocs) > 0) {
|
||||||
|
$hasIgnored = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$personName = $person->getNikename();
|
||||||
|
$entityManager->remove($person);
|
||||||
|
$log->insert('اشخاص', 'شخص با نام ' . $personName . ' حذف شد.', $this->getUser(), $acc['bid']->getId());
|
||||||
|
$deletedCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$entityManager->flush();
|
||||||
|
|
||||||
|
return $this->json([
|
||||||
|
'Success' => true,
|
||||||
|
'result' => [
|
||||||
|
'ignored' => $hasIgnored,
|
||||||
|
'deletedCount' => $deletedCount,
|
||||||
|
'message' => $hasIgnored ? 'برخی اشخاص به دلیل استفاده در اسناد حذف نشدند' : 'همه اشخاص با موفقیت حذف شدند'
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -268,6 +268,7 @@ const fa_lang = {
|
||||||
count: "تعداد",
|
count: "تعداد",
|
||||||
},
|
},
|
||||||
dialog: {
|
dialog: {
|
||||||
|
delete_group: 'حذف گروهی',
|
||||||
acc_price: 'مبلغ',
|
acc_price: 'مبلغ',
|
||||||
des: 'شرح',
|
des: 'شرح',
|
||||||
warning: 'هشدار',
|
warning: 'هشدار',
|
||||||
|
|
|
@ -63,6 +63,11 @@
|
||||||
<v-btn v-bind="props" icon="mdi-table-cog" color="primary" @click="dialogColumns = true" />
|
<v-btn v-bind="props" icon="mdi-table-cog" color="primary" @click="dialogColumns = true" />
|
||||||
</template>
|
</template>
|
||||||
</v-tooltip>
|
</v-tooltip>
|
||||||
|
<v-tooltip :text="$t('dialog.delete_group')" location="bottom">
|
||||||
|
<template v-slot:activator="{ props }">
|
||||||
|
<v-btn v-bind="props" icon="mdi-trash-can" color="red" @click="deleteGroup" />
|
||||||
|
</template>
|
||||||
|
</v-tooltip>
|
||||||
</v-toolbar>
|
</v-toolbar>
|
||||||
|
|
||||||
<v-text-field :loading="loading" color="green" class="mb-0 pt-0 rounded-0" hide-details="auto" density="compact"
|
<v-text-field :loading="loading" color="green" class="mb-0 pt-0 rounded-0" hide-details="auto" density="compact"
|
||||||
|
@ -493,6 +498,53 @@ onMounted(() => {
|
||||||
fetchPersonTypes();
|
fetchPersonTypes();
|
||||||
fetchData();
|
fetchData();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const deleteGroup = async () => {
|
||||||
|
if (selectedItems.value.length === 0) {
|
||||||
|
Swal.fire({
|
||||||
|
text: 'هیچ شخصی برای حذف انتخاب نشده است',
|
||||||
|
icon: 'warning',
|
||||||
|
confirmButtonText: 'قبول',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await Swal.fire({
|
||||||
|
text: 'آیا از حذف اشخاص انتخابشده اطمینان دارید؟',
|
||||||
|
icon: 'warning',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: 'بله',
|
||||||
|
cancelButtonText: 'خیر',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
try {
|
||||||
|
loading.value = true;
|
||||||
|
const codes = selectedItems.value.map(item => item.code);
|
||||||
|
const response = await axios.post('/api/person/deletegroup', { codes });
|
||||||
|
if (response.data.Success) {
|
||||||
|
Swal.fire({
|
||||||
|
text: response.data.result.ignored
|
||||||
|
? 'برخی اشخاص به دلیل استفاده در اسناد حذف نشدند'
|
||||||
|
: 'اشخاص با موفقیت حذف شدند',
|
||||||
|
icon: response.data.result.ignored ? 'warning' : 'success',
|
||||||
|
confirmButtonText: 'قبول',
|
||||||
|
});
|
||||||
|
selectedItems.value = [];
|
||||||
|
fetchData();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error deleting group:', error);
|
||||||
|
Swal.fire({
|
||||||
|
text: 'خطا در حذف گروهی: ' + (error.response?.data?.detail || error.message),
|
||||||
|
icon: 'error',
|
||||||
|
confirmButtonText: 'قبول',
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style></style>
|
<style></style>
|
|
@ -423,55 +423,55 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//submit data
|
//submit data
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
let data = {
|
let data = {
|
||||||
'bid': localStorage.getItem('activeBid'),
|
'bid': localStorage.getItem('activeBid'),
|
||||||
'name': this.content.name,
|
'name': this.content.name,
|
||||||
'legal_name': this.content.legal_name,
|
'legal_name': this.content.legal_name,
|
||||||
'field': this.content.field,
|
'field': this.content.field,
|
||||||
'type': this.content.type,
|
'type': this.content.type,
|
||||||
'shenasemeli': this.content.shenasemeli,
|
'shenasemeli': this.content.shenasemeli,
|
||||||
'codeeqtesadi': this.content.codeeqtesadi,
|
'codeeqtesadi': this.content.codeeqtesadi,
|
||||||
'shomaresabt': this.content.shomaresabt,
|
'shomaresabt': this.content.shomaresabt,
|
||||||
'country': this.content.country,
|
'country': this.content.country,
|
||||||
'ostan': this.content.ostan,
|
'ostan': this.content.ostan,
|
||||||
'shahrestan': this.content.shahrestan,
|
'shahrestan': this.content.shahrestan,
|
||||||
'postalcode': this.content.postalcode,
|
'postalcode': this.content.postalcode,
|
||||||
'tel': this.content.tel,
|
'tel': this.content.tel,
|
||||||
'mobile': this.content.mobile,
|
'mobile': this.content.mobile,
|
||||||
'address': this.content.address,
|
'address': this.content.address,
|
||||||
'website': this.content.website,
|
'website': this.content.website,
|
||||||
'email': this.content.email,
|
'email': this.content.email,
|
||||||
'arzmain': this.content.arzmain,
|
'arzmain': this.content.arzmain,
|
||||||
'maliyatafzode': this.content.maliyatafzode,
|
'maliyatafzode': this.content.maliyatafzode,
|
||||||
'shortlinks': this.content.shortlinks,
|
'shortlinks': this.content.shortlinks,
|
||||||
'walletEnabled': this.content.walletEnabled,
|
'walletEnabled': this.content.walletEnabled,
|
||||||
'walletMatchBank': this.content.walletMatchBank,
|
'walletMatchBank': this.content.walletMatchBank,
|
||||||
'year': this.content.year,
|
'year': this.content.year,
|
||||||
'commodityUpdateBuyPriceAuto': this.content.updateBuyPrice,
|
'commodityUpdateBuyPriceAuto': this.content.updateBuyPrice,
|
||||||
'commodityUpdateSellPriceAuto': this.content.updateSellPrice,
|
'commodityUpdateSellPriceAuto': this.content.updateSellPrice,
|
||||||
'profitCalcType': this.content.profitCalcType
|
'profitCalcType': this.content.profitCalcType
|
||||||
};
|
};
|
||||||
|
|
||||||
axios.post('/api/business/insert', data)
|
axios.post('/api/business/insert', data)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
if (response.data.result == 1) {
|
if (response.data.result == 1) {
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
text: 'با موفقیت ثبت شد.',
|
text: 'با موفقیت ثبت شد.',
|
||||||
icon: 'success',
|
icon: 'success',
|
||||||
confirmButtonText: 'قبول',
|
confirmButtonText: 'قبول',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else if (response.data.result === 0) {
|
else if (response.data.result === 0) {
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
text: 'تکمیل موارد ستاره دار الزامی است.',
|
text: 'تکمیل موارد ستاره دار الزامی است.',
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
confirmButtonText: 'قبول'
|
confirmButtonText: 'قبول'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
|
|
Loading…
Reference in a new issue