add delete group to persons list

This commit is contained in:
Hesabix 2025-04-03 20:57:13 +00:00
parent e34d8e887b
commit 8ad24235c5
4 changed files with 162 additions and 45 deletions

View file

@ -1465,4 +1465,68 @@ class PersonsController extends AbstractController
}
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 ? 'برخی اشخاص به دلیل استفاده در اسناد حذف نشدند' : 'همه اشخاص با موفقیت حذف شدند'
]
]);
}
}

View file

@ -268,6 +268,7 @@ const fa_lang = {
count: "تعداد",
},
dialog: {
delete_group: 'حذف گروهی',
acc_price: 'مبلغ',
des: 'شرح',
warning: 'هشدار',

View file

@ -63,6 +63,11 @@
<v-btn v-bind="props" icon="mdi-table-cog" color="primary" @click="dialogColumns = true" />
</template>
</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-text-field :loading="loading" color="green" class="mb-0 pt-0 rounded-0" hide-details="auto" density="compact"
@ -493,6 +498,53 @@ onMounted(() => {
fetchPersonTypes();
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>
<style></style>

View file

@ -423,55 +423,55 @@ export default {
return;
}
//submit data
this.loading = true;
//submit data
this.loading = true;
let data = {
'bid': localStorage.getItem('activeBid'),
'name': this.content.name,
'legal_name': this.content.legal_name,
'field': this.content.field,
'type': this.content.type,
'shenasemeli': this.content.shenasemeli,
'codeeqtesadi': this.content.codeeqtesadi,
'shomaresabt': this.content.shomaresabt,
'country': this.content.country,
'ostan': this.content.ostan,
'shahrestan': this.content.shahrestan,
'postalcode': this.content.postalcode,
'tel': this.content.tel,
'mobile': this.content.mobile,
'address': this.content.address,
'website': this.content.website,
'email': this.content.email,
'arzmain': this.content.arzmain,
'maliyatafzode': this.content.maliyatafzode,
'shortlinks': this.content.shortlinks,
'walletEnabled': this.content.walletEnabled,
'walletMatchBank': this.content.walletMatchBank,
'year': this.content.year,
'commodityUpdateBuyPriceAuto': this.content.updateBuyPrice,
'commodityUpdateSellPriceAuto': this.content.updateSellPrice,
'profitCalcType': this.content.profitCalcType
'bid': localStorage.getItem('activeBid'),
'name': this.content.name,
'legal_name': this.content.legal_name,
'field': this.content.field,
'type': this.content.type,
'shenasemeli': this.content.shenasemeli,
'codeeqtesadi': this.content.codeeqtesadi,
'shomaresabt': this.content.shomaresabt,
'country': this.content.country,
'ostan': this.content.ostan,
'shahrestan': this.content.shahrestan,
'postalcode': this.content.postalcode,
'tel': this.content.tel,
'mobile': this.content.mobile,
'address': this.content.address,
'website': this.content.website,
'email': this.content.email,
'arzmain': this.content.arzmain,
'maliyatafzode': this.content.maliyatafzode,
'shortlinks': this.content.shortlinks,
'walletEnabled': this.content.walletEnabled,
'walletMatchBank': this.content.walletMatchBank,
'year': this.content.year,
'commodityUpdateBuyPriceAuto': this.content.updateBuyPrice,
'commodityUpdateSellPriceAuto': this.content.updateSellPrice,
'profitCalcType': this.content.profitCalcType
};
axios.post('/api/business/insert', data)
.then((response) => {
this.loading = false;
if (response.data.result == 1) {
Swal.fire({
text: 'با موفقیت ثبت شد.',
icon: 'success',
confirmButtonText: 'قبول',
})
}
else if (response.data.result === 0) {
Swal.fire({
text: 'تکمیل موارد ستاره دار الزامی است.',
icon: 'error',
confirmButtonText: 'قبول'
});
}
})
.then((response) => {
this.loading = false;
if (response.data.result == 1) {
Swal.fire({
text: 'با موفقیت ثبت شد.',
icon: 'success',
confirmButtonText: 'قبول',
})
}
else if (response.data.result === 0) {
Swal.fire({
text: 'تکمیل موارد ستاره دار الزامی است.',
icon: 'error',
confirmButtonText: 'قبول'
});
}
})
.catch((error) => {
this.loading = false;
Swal.fire({