progress in export balance report
This commit is contained in:
parent
0ede84e486
commit
c0119d4c72
|
@ -2,8 +2,12 @@
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\BankAccount;
|
||||
use App\Entity\Cashdesk;
|
||||
use App\Entity\Commodity;
|
||||
use App\Entity\HesabdariTable;
|
||||
use App\Entity\Person;
|
||||
use App\Entity\Salary;
|
||||
use App\Service\Access;
|
||||
use App\Service\pdfMGR;
|
||||
use App\Service\Provider;
|
||||
|
@ -21,6 +25,13 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|||
|
||||
class ReportController extends AbstractController
|
||||
{
|
||||
private $em;
|
||||
private $provider;
|
||||
function __construct(Provider $provider, EntityManagerInterface $entityManager)
|
||||
{
|
||||
$this->em = $entityManager;
|
||||
$this->provider = $provider;
|
||||
}
|
||||
#[Route('/api/report/person/buysell', name: 'app_report_person_buysell')]
|
||||
public function app_report_person_buysell(Provider $provider, Jdate $jdate, Access $access, Request $request, EntityManagerInterface $entityManagerInterface): JsonResponse
|
||||
{
|
||||
|
@ -44,7 +55,7 @@ class ReportController extends AbstractController
|
|||
'year' => $acc['year'],
|
||||
'bid' => $acc['bid'],
|
||||
'type' => $params['type'],
|
||||
'money'=> $acc['money']
|
||||
'money' => $acc['money']
|
||||
]);
|
||||
}
|
||||
//filter docs by date
|
||||
|
@ -192,14 +203,14 @@ class ReportController extends AbstractController
|
|||
$docs = $entityManagerInterface->getRepository(HesabdariDoc::class)->findBy([
|
||||
'year' => $acc['year'],
|
||||
'bid' => $acc['bid'],
|
||||
'money'=> $acc['money']
|
||||
'money' => $acc['money']
|
||||
]);
|
||||
} else {
|
||||
$docs = $entityManagerInterface->getRepository(HesabdariDoc::class)->findBy([
|
||||
'year' => $acc['year'],
|
||||
'bid' => $acc['bid'],
|
||||
'type' => $params['type'],
|
||||
'money'=> $acc['money']
|
||||
'money' => $acc['money']
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -273,4 +284,262 @@ class ReportController extends AbstractController
|
|||
}
|
||||
return $this->json($response);
|
||||
}
|
||||
|
||||
#[Route('/api/report/acc/explore_accounts', name: 'app_report_acc_explore_accounts')]
|
||||
public function app_report_acc_explore_accounts(Provider $provider, Jdate $jdate, Access $access, Request $request, EntityManagerInterface $entityManagerInterface): JsonResponse
|
||||
{
|
||||
$acc = $access->hasRole('report');
|
||||
if (!$acc) {
|
||||
throw $this->createAccessDeniedException();
|
||||
}
|
||||
|
||||
$params = [];
|
||||
if ($content = $request->getContent()) {
|
||||
$params = json_decode($content, true);
|
||||
}
|
||||
if (!array_key_exists('node', $params))
|
||||
throw $this->createNotFoundException();
|
||||
if ($params['node'] == 'root') {
|
||||
$rootNode = $entityManagerInterface->getRepository(HesabdariTable::class)->findOneBy(['upper' => null]);
|
||||
} else {
|
||||
$rootNode = $entityManagerInterface->getRepository(HesabdariTable::class)->find($params['node']);
|
||||
}
|
||||
if (!$rootNode)
|
||||
throw $this->createNotFoundException();
|
||||
|
||||
|
||||
if ($params['node'] == 'root') {
|
||||
$tableItems = $entityManagerInterface->getRepository(HesabdariTable::class)->findBy([
|
||||
'upper' => 1
|
||||
]);
|
||||
} else {
|
||||
if ($rootNode->getType() == 'calc') {
|
||||
$tableItems = $entityManagerInterface->getRepository(HesabdariTable::class)->findBy([
|
||||
'upper' => $rootNode
|
||||
]);
|
||||
} elseif ($rootNode->getType() == 'bank') {
|
||||
$tableItems = $entityManagerInterface->getRepository(BankAccount::class)->findBy([
|
||||
'bid' => $acc['bid'],
|
||||
'money' => $acc['money'],
|
||||
]);
|
||||
} elseif ($rootNode->getType() == 'cashdesk') {
|
||||
$tableItems = $entityManagerInterface->getRepository(Cashdesk::class)->findBy([
|
||||
'bid' => $acc['bid'],
|
||||
'money' => $acc['money'],
|
||||
]);
|
||||
} elseif ($rootNode->getType() == 'salary') {
|
||||
$tableItems = $entityManagerInterface->getRepository(Salary::class)->findBy([
|
||||
'bid' => $acc['bid'],
|
||||
'money' => $acc['money'],
|
||||
]);
|
||||
} elseif ($rootNode->getType() == 'person') {
|
||||
$tableItems = $entityManagerInterface->getRepository(Person::class)->findBy([
|
||||
'bid' => $acc['bid'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
$response = [];
|
||||
if ($rootNode->getType() == 'calc') {
|
||||
foreach ($tableItems as $item) {
|
||||
$temp = [
|
||||
'id' => $item->getId(),
|
||||
'account' => $item->getName(),
|
||||
'code' => $item->getCode(),
|
||||
];
|
||||
$childs = $entityManagerInterface->getRepository(HesabdariTable::class)->findBy([
|
||||
'upper' => $item
|
||||
]);
|
||||
$temp['hasChild'] = false;
|
||||
if (count($childs) > 0 || $item->getType() != 'calc') {
|
||||
$temp['hasChild'] = true;
|
||||
}
|
||||
$temp = array_merge($temp, $this->getBalance($acc, $item->getCode(), $rootNode->getType()));
|
||||
$response[] = $temp;
|
||||
}
|
||||
} elseif ($rootNode->getType() == 'bank') {
|
||||
foreach ($tableItems as $item) {
|
||||
$temp = [
|
||||
'id' => $item->getId(),
|
||||
'account' => $item->getName(),
|
||||
'code' => $item->getCode(),
|
||||
];
|
||||
$temp = array_merge($temp, $this->getBalance($acc, $item->getCode(), $rootNode->getType()));
|
||||
$temp['hasChild'] = false;
|
||||
$response[] = $temp;
|
||||
}
|
||||
} elseif ($rootNode->getType() == 'cashdesk') {
|
||||
foreach ($tableItems as $item) {
|
||||
$temp = [
|
||||
'id' => $item->getId(),
|
||||
'account' => $item->getName(),
|
||||
'code' => $item->getCode(),
|
||||
];
|
||||
$temp = array_merge($temp, $this->getBalance($acc, $item->getCode(), $rootNode->getType()));
|
||||
$temp['hasChild'] = false;
|
||||
$response[] = $temp;
|
||||
}
|
||||
} elseif ($rootNode->getType() == 'salary') {
|
||||
foreach ($tableItems as $item) {
|
||||
$temp = [
|
||||
'id' => $item->getId(),
|
||||
'account' => $item->getName(),
|
||||
'code' => $item->getCode(),
|
||||
];
|
||||
$temp = array_merge($temp, $this->getBalance($acc, $item->getCode(), $rootNode->getType()));
|
||||
$temp['hasChild'] = false;
|
||||
$response[] = $temp;
|
||||
}
|
||||
} elseif ($rootNode->getType() == 'person') {
|
||||
foreach ($tableItems as $item) {
|
||||
$temp = [
|
||||
'id' => $item->getId(),
|
||||
'account' => $item->getNikename(),
|
||||
'code' => $item->getCode(),
|
||||
];
|
||||
$temp = array_merge($temp, $this->getBalance($acc, $item->getCode(), $rootNode->getType()));
|
||||
$temp['hasChild'] = false;
|
||||
$response[] = $temp;
|
||||
}
|
||||
}
|
||||
$data = [];
|
||||
$data['itemData'] = $response;
|
||||
$data['tree'] = $this->getTree($rootNode);
|
||||
|
||||
return $this->json($data);
|
||||
}
|
||||
|
||||
private function getTree(HesabdariTable $table): array
|
||||
{
|
||||
$tree = [];
|
||||
while ($table->getUpper() != null) {
|
||||
$tree[] = [
|
||||
'id' => $table->getId(),
|
||||
'code' => $table->getCode(),
|
||||
'name' => $table->getName(),
|
||||
];
|
||||
$table = $table->getUpper();
|
||||
}
|
||||
$tree[] = [
|
||||
'id' => 1,
|
||||
'code' => 'root',
|
||||
'name' => 'جدول حسابها',
|
||||
];
|
||||
return array_reverse($tree);
|
||||
}
|
||||
private function getBalance($acc, $code, $type = 'calc'): array
|
||||
{
|
||||
$res = [
|
||||
'bal_bd' => 0,
|
||||
'bal_bs' => 0,
|
||||
'his_bd' => 0,
|
||||
'his_bs' => 0,
|
||||
];
|
||||
if ($type == 'calc') {
|
||||
$calc = $this->em->getRepository(HesabdariTable::class)->findOneBy([
|
||||
'code' => $code,
|
||||
]);
|
||||
$faltItemsArray = $this->provider->tree2flat($calc);
|
||||
|
||||
//var_dump($faltItemsArray);
|
||||
$bs = 0;
|
||||
$bd = 0;
|
||||
|
||||
foreach ($faltItemsArray as $item) {
|
||||
if ($item['type'] == 'calc') {
|
||||
$items = $this->em->getRepository(HesabdariRow::class)->findBy([
|
||||
'money' => $acc['money'],
|
||||
'bid' => $acc['bid'],
|
||||
'hesabdariTable' => $item['id']
|
||||
]);
|
||||
foreach ($items as $objItem) {
|
||||
$bs += $objItem->getBs();
|
||||
$bd += $objItem->getBd();
|
||||
}
|
||||
}
|
||||
elseif ($item['type'] == 'person') {
|
||||
$items = $this->em->getRepository(HesabdariRow::class)->findBy([
|
||||
'money' => $acc['money'],
|
||||
'bid' => $acc['bid'],
|
||||
'person' => $item['id']
|
||||
]);
|
||||
foreach ($items as $objItem) {
|
||||
$bs += $objItem->getBs();
|
||||
$bd += $objItem->getBd();
|
||||
}
|
||||
}
|
||||
elseif ($item['type'] == 'cashdesk') {
|
||||
$items = $this->em->getRepository(HesabdariRow::class)->findBy([
|
||||
'money' => $acc['money'],
|
||||
'bid' => $acc['bid'],
|
||||
'cashdesk' => $item['id']
|
||||
]);
|
||||
foreach ($items as $objItem) {
|
||||
$bs += $objItem->getBs();
|
||||
$bd += $objItem->getBd();
|
||||
}
|
||||
}
|
||||
elseif ($item['type'] == 'salary') {
|
||||
$items = $this->em->getRepository(HesabdariRow::class)->findBy([
|
||||
'money' => $acc['money'],
|
||||
'bid' => $acc['bid'],
|
||||
'salary' => $item['id']
|
||||
]);
|
||||
foreach ($items as $objItem) {
|
||||
$bs += $objItem->getBs();
|
||||
$bd += $objItem->getBd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} elseif ($type == 'bank') {
|
||||
$bank = $this->em->getRepository(BankAccount::class)->findOneBy([
|
||||
'money' => $acc['money'],
|
||||
'bid' => $acc['bid'],
|
||||
'code' => $code,
|
||||
]);
|
||||
$items = $this->em->getRepository(HesabdariRow::class)->findBy([
|
||||
'bank' => $bank
|
||||
]);
|
||||
} elseif ($type == 'cashdesk') {
|
||||
$cashdesk = $this->em->getRepository(Cashdesk::class)->findOneBy([
|
||||
'money' => $acc['money'],
|
||||
'bid' => $acc['bid'],
|
||||
'code' => $code,
|
||||
]);
|
||||
$items = $this->em->getRepository(HesabdariRow::class)->findBy([
|
||||
'cashdesk' => $cashdesk
|
||||
]);
|
||||
} elseif ($type == 'salary') {
|
||||
$salary = $this->em->getRepository(Salary::class)->findOneBy([
|
||||
'money' => $acc['money'],
|
||||
'bid' => $acc['bid'],
|
||||
'code' => $code,
|
||||
]);
|
||||
$items = $this->em->getRepository(HesabdariRow::class)->findBy([
|
||||
'salary' => $salary
|
||||
]);
|
||||
} elseif ($type == 'person') {
|
||||
$person = $this->em->getRepository(Person::class)->findOneBy([
|
||||
'bid' => $acc['bid'],
|
||||
'code' => $code,
|
||||
]);
|
||||
$items = $this->em->getRepository(HesabdariRow::class)->findBy([
|
||||
'person' => $person
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($items as $item) {
|
||||
$res['his_bd'] += $item->getBd();
|
||||
$res['his_bs'] += $item->getBs();
|
||||
}
|
||||
if ($res['his_bd'] > $res['his_bs']) {
|
||||
$res['bal_bd'] = $res['his_bd'] - $res['his_bs'];
|
||||
$res['bal_bs'] = 0;
|
||||
} else {
|
||||
$res['bal_bs'] = $res['his_bs'] - $res['his_bd'];
|
||||
$res['bal_bd'] = 0;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Service;
|
||||
|
||||
use App\Entity\Business;
|
||||
use App\Entity\HesabdariTable;
|
||||
use App\Entity\PlugNoghreOrder;
|
||||
use App\Entity\PrinterQueue;
|
||||
use App\Entity\User;
|
||||
|
@ -65,13 +66,13 @@ class Provider
|
|||
|
||||
public function maxPages($params, $rowsAllCount)
|
||||
{
|
||||
$res = $rowsAllCount / $params['count'];
|
||||
return is_float($res) ? (int)$res + 1 : $res;
|
||||
$res = $rowsAllCount / $params['count'];
|
||||
return is_float($res) ? (int) $res + 1 : $res;
|
||||
}
|
||||
public function maxPagesWithPageCount($count, $rowsAllCount)
|
||||
{
|
||||
$res = $rowsAllCount / $count;
|
||||
return is_float($res) ? (int)$res + 1 : $res;
|
||||
$res = $rowsAllCount / $count;
|
||||
return is_float($res) ? (int) $res + 1 : $res;
|
||||
}
|
||||
public function gravatarHash($email)
|
||||
{
|
||||
|
@ -100,7 +101,8 @@ class Provider
|
|||
*/
|
||||
public function Entity2Array($entity, int $deep = 1, array $ignores = []): null|array
|
||||
{
|
||||
if (is_null($entity)) return [];
|
||||
if (is_null($entity))
|
||||
return [];
|
||||
$result = [];
|
||||
$methods = get_class_methods($entity);
|
||||
$getMethods = [];
|
||||
|
@ -139,7 +141,8 @@ class Provider
|
|||
|
||||
public function ArrayEntity2Array(array $entity, int $deep = 1, array $ignores = []): null|array
|
||||
{
|
||||
if (count($entity) == 0) return [];
|
||||
if (count($entity) == 0)
|
||||
return [];
|
||||
$result = [];
|
||||
foreach ($entity as $item) {
|
||||
$result[] = $this->Entity2Array($item, $deep, $ignores);
|
||||
|
@ -147,7 +150,7 @@ class Provider
|
|||
return $result;
|
||||
}
|
||||
|
||||
public function createPrint(Business $bid, User $user, String $data,$posPrint = false,$paperSize = 'A4-L',$footer = true)
|
||||
public function createPrint(Business $bid, User $user, string $data, $posPrint = false, $paperSize = 'A4-L', $footer = true)
|
||||
{
|
||||
$print = new PrinterQueue();
|
||||
$print->setDateSubmit(time());
|
||||
|
@ -213,7 +216,8 @@ class Provider
|
|||
*/
|
||||
public function Entity2ArrayJustIncludes($entity, array $includes, int $deep = 1): null|array
|
||||
{
|
||||
if (is_null($entity)) return [];
|
||||
if (is_null($entity))
|
||||
return [];
|
||||
$result = [];
|
||||
foreach ($includes as $method) {
|
||||
if (method_exists($entity, $method)) {
|
||||
|
@ -236,7 +240,8 @@ class Provider
|
|||
*/
|
||||
public function ArrayEntity2ArrayJustIncludes(array $entity, array $includes, int $deep = 1): null|array
|
||||
{
|
||||
if (count($entity) == 0) return [];
|
||||
if (count($entity) == 0)
|
||||
return [];
|
||||
$result = [];
|
||||
foreach ($entity as $item) {
|
||||
$result[] = $this->Entity2ArrayJustIncludes($item, $includes, $deep);
|
||||
|
@ -244,7 +249,7 @@ class Provider
|
|||
return $result;
|
||||
}
|
||||
|
||||
public function shamsiDateToTimestamp(string $stringDate): string | bool
|
||||
public function shamsiDateToTimestamp(string $stringDate): string|bool
|
||||
{
|
||||
$jdate = new Jdate();
|
||||
$timeArray = explode('-', $stringDate);
|
||||
|
@ -260,4 +265,29 @@ class Provider
|
|||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function tree2flat(HesabdariTable $table): array
|
||||
{
|
||||
$result = [];
|
||||
$nodes = $this->entityManager->getRepository(HesabdariTable::class)->findBy([
|
||||
'upper' => $table
|
||||
]);
|
||||
foreach ($nodes as $node) {
|
||||
$childeNode = $this->entityManager->getRepository(HesabdariTable::class)->findBy([
|
||||
'upper' => $node
|
||||
]);
|
||||
|
||||
if (count($childeNode) == 0) {
|
||||
$result[$node->getId()] = [
|
||||
'id' => $node->getId(),
|
||||
'code' => $node->getCode(),
|
||||
'name' => $node->getName(),
|
||||
'type' => $node->getType(),
|
||||
];
|
||||
} else {
|
||||
$result[$node->getId()] = $this->tree2flat($node);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue