bug fix in cheque and add support person transactions sort by
This commit is contained in:
parent
63b6654cc8
commit
11caf42da8
|
@ -86,6 +86,7 @@ class PersonService
|
|||
$search = $params['search'] ?? '';
|
||||
$types = $params['types'] ?? null;
|
||||
$transactionFilters = $params['transactionFilters'] ?? null;
|
||||
$sortBy = $params['sortBy'] ?? null;
|
||||
|
||||
$queryBuilder = $this->entityManager->getRepository(Person::class)
|
||||
->createQueryBuilder('p')
|
||||
|
@ -104,18 +105,66 @@ class PersonService
|
|||
->setParameter('types', $types);
|
||||
}
|
||||
|
||||
// بررسی اینکه آیا سورت روی فیلدهای محاسبهشده است
|
||||
$hasCalculatedSort = false;
|
||||
$calculatedSortField = null;
|
||||
$calculatedSortOrder = null;
|
||||
if ($sortBy && is_array($sortBy) && !empty($sortBy)) {
|
||||
foreach ($sortBy as $sort) {
|
||||
if (isset($sort['key']) && in_array($sort['key'], ['bs', 'bd', 'balance'])) {
|
||||
$hasCalculatedSort = true;
|
||||
$calculatedSortField = $sort['key'];
|
||||
$calculatedSortOrder = $sort['order'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// اگر سورت روی فیلدهای محاسبهشده است، ابتدا همه دادهها را دریافت کن
|
||||
if ($hasCalculatedSort) {
|
||||
$persons = $queryBuilder
|
||||
->select('p')
|
||||
->getQuery()
|
||||
->getResult();
|
||||
} else {
|
||||
// اعمال سورت کردن برای فیلدهای مستقیم
|
||||
if ($sortBy && is_array($sortBy) && !empty($sortBy)) {
|
||||
foreach ($sortBy as $sort) {
|
||||
if (isset($sort['key']) && isset($sort['order'])) {
|
||||
$field = $sort['key'];
|
||||
$order = strtoupper($sort['order']);
|
||||
|
||||
// بررسی فیلدهای مجاز برای سورت
|
||||
$allowedFields = [
|
||||
'code', 'nikename', 'name', 'birthday', 'company',
|
||||
'shenasemeli', 'codeeghtesadi', 'sabt', 'keshvar',
|
||||
'ostan', 'shahr', 'postalcode', 'tel', 'mobile',
|
||||
'mobile2', 'email', 'website', 'fax', 'speedAccess'
|
||||
];
|
||||
|
||||
if (in_array($field, $allowedFields)) {
|
||||
$queryBuilder->addOrderBy("p.$field", $order);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// سورت پیشفرض بر اساس کد
|
||||
$queryBuilder->orderBy('p.code', 'ASC');
|
||||
}
|
||||
|
||||
$persons = $queryBuilder
|
||||
->select('p')
|
||||
->setFirstResult(($page - 1) * $itemsPerPage)
|
||||
->setMaxResults($itemsPerPage)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
$totalItems = (clone $queryBuilder)
|
||||
->select('COUNT(p.id)')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
|
||||
$persons = $queryBuilder
|
||||
->select('p')
|
||||
->setFirstResult(($page - 1) * $itemsPerPage)
|
||||
->setMaxResults($itemsPerPage)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
|
||||
$response = [];
|
||||
foreach ($persons as $person) {
|
||||
$rows = $this->entityManager->getRepository(HesabdariRow::class)->findBy([
|
||||
|
@ -158,10 +207,27 @@ class PersonService
|
|||
}
|
||||
}
|
||||
|
||||
// اگر سورت روی فیلدهای محاسبهشده است، اینجا سورت کن
|
||||
if ($hasCalculatedSort && $calculatedSortField && $calculatedSortOrder) {
|
||||
usort($response, function($a, $b) use ($calculatedSortField, $calculatedSortOrder) {
|
||||
$aVal = $a[$calculatedSortField] ?? 0;
|
||||
$bVal = $b[$calculatedSortField] ?? 0;
|
||||
|
||||
if ($calculatedSortOrder === 'ASC') {
|
||||
return $aVal <=> $bVal;
|
||||
} else {
|
||||
return $bVal <=> $aVal;
|
||||
}
|
||||
});
|
||||
|
||||
// اعمال صفحهبندی بعد از سورت
|
||||
$response = array_slice($response, ($page - 1) * $itemsPerPage, $itemsPerPage);
|
||||
}
|
||||
|
||||
$filteredTotal = count($response);
|
||||
|
||||
return [
|
||||
'items' => array_slice($response, 0, $itemsPerPage),
|
||||
'items' => $response,
|
||||
'total' => $filteredTotal,
|
||||
'unfilteredTotal' => $totalItems,
|
||||
];
|
||||
|
|
|
@ -745,6 +745,7 @@ const fa_lang = {
|
|||
},
|
||||
"person_card": {
|
||||
accounting_status: 'وضعیت حسابداری',
|
||||
transfer_cheque: 'واگذاری چک',
|
||||
"title": "کارت حساب اشخاص",
|
||||
"account_card": "کارت حساب",
|
||||
"account_status": "وضعیت حساب",
|
||||
|
|
|
@ -384,6 +384,7 @@ export default {
|
|||
modify_cheque: '/acc/accounting/view/',
|
||||
modify_cheque_output: '/acc/accounting/view/',
|
||||
pass_cheque: '/acc/accounting/view/',
|
||||
transfer_cheque: '/acc/accounting/view/',
|
||||
};
|
||||
return routes[type] + code;
|
||||
},
|
||||
|
@ -403,6 +404,7 @@ export default {
|
|||
modify_cheque: this.$t('pages.person_card.modify_cheque'),
|
||||
pass_cheque: this.$t('pages.person_card.pass_cheque'),
|
||||
modify_cheque_output: this.$t('pages.person_card.modify_cheque_output'),
|
||||
transfer_cheque: this.$t('pages.person_card.transfer_cheque'),
|
||||
};
|
||||
return labels[type] || type;
|
||||
},
|
||||
|
|
|
@ -307,10 +307,13 @@ const fetchData = async () => {
|
|||
const selectedTransactionFilters = transactionFilters.value
|
||||
.filter((filter) => filter.checked)
|
||||
.map((filter) => filter.value);
|
||||
|
||||
// تبدیل سورتهای Vuetify به فرمت مورد نیاز سرور
|
||||
const sortBy = serverOptions.value.sortBy.map((sort) => ({
|
||||
key: sort.key,
|
||||
order: sort.order === 'asc' ? 'ASC' : 'DESC',
|
||||
}));
|
||||
|
||||
const response = await axios.post('/api/person/list', {
|
||||
page: serverOptions.value.page,
|
||||
itemsPerPage: serverOptions.value.rowsPerPage,
|
||||
|
|
|
@ -121,7 +121,7 @@
|
|||
<PrintDialog
|
||||
v-model="modal"
|
||||
:plugins="plugins"
|
||||
@print="printInvoice"
|
||||
@print="handlePrint"
|
||||
@cancel="modal = false"
|
||||
/>
|
||||
<!-- End Print Modal -->
|
||||
|
@ -187,10 +187,9 @@
|
|||
|
||||
<script>
|
||||
import axios from "axios";
|
||||
import { ref, defineComponent } from "vue";
|
||||
import PrintDialog from '@/components/PrintDialog.vue';
|
||||
|
||||
export default defineComponent ({
|
||||
export default {
|
||||
name: "list",
|
||||
components: {
|
||||
PrintDialog
|
||||
|
@ -232,7 +231,7 @@ export default defineComponent ({
|
|||
sumTotal: 0,
|
||||
itemsSelected: [],
|
||||
searchValue: '',
|
||||
loading: ref(true),
|
||||
loading: true,
|
||||
items: [],
|
||||
orgItems: [],
|
||||
headers: [
|
||||
|
@ -335,13 +334,16 @@ export default defineComponent ({
|
|||
}
|
||||
});
|
||||
},
|
||||
printInvoice(pdf = true, cloudePrinters = true) {
|
||||
handlePrint(printOptions) {
|
||||
this.printInvoice(true, true, printOptions);
|
||||
},
|
||||
printInvoice(pdf = true, cloudePrinters = true, printOptions = null) {
|
||||
this.loading = true;
|
||||
axios.post('/api/preinvoice/print/invoice', {
|
||||
'code': this.printOptions.selectedPrintCode,
|
||||
'pdf': pdf,
|
||||
'printers': cloudePrinters,
|
||||
'printOptions': this.printOptions
|
||||
'printOptions': printOptions || this.printOptions
|
||||
}).then((response) => {
|
||||
this.loading = false;
|
||||
window.open(this.$API_URL + '/front/print/' + response.data.id, '_blank', 'noreferrer');
|
||||
|
@ -419,7 +421,7 @@ export default defineComponent ({
|
|||
deep: false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
|
Loading…
Reference in a new issue