diff --git a/hesabixCore/src/Cog/AccountingDocService.php b/hesabixCore/src/Cog/AccountingDocService.php index 97a6bcf..b800e54 100644 --- a/hesabixCore/src/Cog/AccountingDocService.php +++ b/hesabixCore/src/Cog/AccountingDocService.php @@ -55,7 +55,7 @@ class AccountingDocService 'person' => $person, 'year' => $acc['year'] ], [ - 'id' => 'DESC' + 'id' => 'ASC' ]); } elseif ($params['type'] == 'bank') { $bank = $em->getRepository(\App\Entity\BankAccount::class)->findOneBy([ @@ -68,7 +68,7 @@ class AccountingDocService 'bank' => $bank, 'year' => $acc['year'] ], [ - 'id' => 'DESC' + 'id' => 'ASC' ]); } elseif ($params['type'] == 'cashdesk') { $cashdesk = $em->getRepository(\App\Entity\Cashdesk::class)->findOneBy([ @@ -81,7 +81,7 @@ class AccountingDocService 'cashdesk' => $cashdesk, 'year' => $acc['year'] ], [ - 'id' => 'DESC' + 'id' => 'ASC' ]); } elseif ($params['type'] == 'salary') { $salary = $em->getRepository(\App\Entity\Salary::class)->findOneBy([ @@ -94,13 +94,29 @@ class AccountingDocService 'salary' => $salary, 'year' => $acc['year'] ], [ - 'id' => 'DESC' + 'id' => 'ASC' ]); } else { return ['error' => 'نوع پشتیبانی نمیشود']; } + $dataTemp = []; + $runningBalance = 0; // باقیمانده تجمعی + foreach ($data as $item) { + // محاسبه باقیمانده تجمعی + $runningBalance += ($item->getBs() - $item->getBd()); + + // محاسبه تشخیص بر اساس باقیمانده تجمعی + $settlement = ''; + if ($runningBalance > 0) { + $settlement = 'بستانکار'; + } elseif ($runningBalance < 0) { + $settlement = 'بدهکار'; + } else { + $settlement = 'تسویهشده'; + } + $temp = [ 'id' => $item->getId(), 'dateSubmit' => $item->getDoc()->getDateSubmit(), @@ -111,10 +127,14 @@ class AccountingDocService 'bs' => $item->getBs(), 'bd' => $item->getBd(), 'code' => $item->getDoc()->getCode(), - 'submitter' => $item->getDoc()->getSubmitter()->getFullName() + 'submitter' => $item->getDoc()->getSubmitter()->getFullName(), + 'settlement' => $settlement, // ستون تشخیص + 'balance' => $runningBalance // ستون باقیمانده ]; $dataTemp[] = $temp; } - return $dataTemp; + + // معکوس کردن ترتیب برای نمایش جدیدترینها اول + return array_reverse($dataTemp); } } \ No newline at end of file diff --git a/hesabixCore/src/Controller/PersonsController.php b/hesabixCore/src/Controller/PersonsController.php index 76fbae6..f237127 100644 --- a/hesabixCore/src/Controller/PersonsController.php +++ b/hesabixCore/src/Controller/PersonsController.php @@ -721,10 +721,25 @@ class PersonsController extends AbstractController 'تفضیل', 'بستانکار', 'بدهکار', + 'تشخیص', + 'باقیمانده', 'سال مالی', ] ]; + + $runningBalance = 0; foreach ($transactions as $transaction) { + $runningBalance += ($transaction->getBs() - $transaction->getBd()); + + $settlement = ''; + if ($runningBalance > 0) { + $settlement = 'بستانکار'; + } elseif ($runningBalance < 0) { + $settlement = 'بدهکار'; + } else { + $settlement = 'تسویهشده'; + } + $arrayEntity[] = [ $transaction->getId(), $transaction->getDoc()->getDate(), @@ -732,6 +747,8 @@ class PersonsController extends AbstractController $transaction->getRef()->getName(), $transaction->getBs(), $transaction->getBd(), + $settlement, + $runningBalance, $transaction->getYear()->getlabel() ]; } diff --git a/hesabixCore/templates/pdf/person_card.html.twig b/hesabixCore/templates/pdf/person_card.html.twig index 2e357a0..53e200b 100644 --- a/hesabixCore/templates/pdf/person_card.html.twig +++ b/hesabixCore/templates/pdf/person_card.html.twig @@ -81,13 +81,25 @@