progress in export balance report
This commit is contained in:
parent
0ede84e486
commit
c0119d4c72
|
@ -2,8 +2,12 @@
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\BankAccount;
|
||||||
|
use App\Entity\Cashdesk;
|
||||||
use App\Entity\Commodity;
|
use App\Entity\Commodity;
|
||||||
|
use App\Entity\HesabdariTable;
|
||||||
use App\Entity\Person;
|
use App\Entity\Person;
|
||||||
|
use App\Entity\Salary;
|
||||||
use App\Service\Access;
|
use App\Service\Access;
|
||||||
use App\Service\pdfMGR;
|
use App\Service\pdfMGR;
|
||||||
use App\Service\Provider;
|
use App\Service\Provider;
|
||||||
|
@ -21,6 +25,13 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
|
||||||
class ReportController extends 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')]
|
#[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
|
public function app_report_person_buysell(Provider $provider, Jdate $jdate, Access $access, Request $request, EntityManagerInterface $entityManagerInterface): JsonResponse
|
||||||
{
|
{
|
||||||
|
@ -273,4 +284,262 @@ class ReportController extends AbstractController
|
||||||
}
|
}
|
||||||
return $this->json($response);
|
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;
|
namespace App\Service;
|
||||||
|
|
||||||
use App\Entity\Business;
|
use App\Entity\Business;
|
||||||
|
use App\Entity\HesabdariTable;
|
||||||
use App\Entity\PlugNoghreOrder;
|
use App\Entity\PlugNoghreOrder;
|
||||||
use App\Entity\PrinterQueue;
|
use App\Entity\PrinterQueue;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
|
@ -100,7 +101,8 @@ class Provider
|
||||||
*/
|
*/
|
||||||
public function Entity2Array($entity, int $deep = 1, array $ignores = []): null|array
|
public function Entity2Array($entity, int $deep = 1, array $ignores = []): null|array
|
||||||
{
|
{
|
||||||
if (is_null($entity)) return [];
|
if (is_null($entity))
|
||||||
|
return [];
|
||||||
$result = [];
|
$result = [];
|
||||||
$methods = get_class_methods($entity);
|
$methods = get_class_methods($entity);
|
||||||
$getMethods = [];
|
$getMethods = [];
|
||||||
|
@ -139,7 +141,8 @@ class Provider
|
||||||
|
|
||||||
public function ArrayEntity2Array(array $entity, int $deep = 1, array $ignores = []): null|array
|
public function ArrayEntity2Array(array $entity, int $deep = 1, array $ignores = []): null|array
|
||||||
{
|
{
|
||||||
if (count($entity) == 0) return [];
|
if (count($entity) == 0)
|
||||||
|
return [];
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($entity as $item) {
|
foreach ($entity as $item) {
|
||||||
$result[] = $this->Entity2Array($item, $deep, $ignores);
|
$result[] = $this->Entity2Array($item, $deep, $ignores);
|
||||||
|
@ -147,7 +150,7 @@ class Provider
|
||||||
return $result;
|
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 = new PrinterQueue();
|
||||||
$print->setDateSubmit(time());
|
$print->setDateSubmit(time());
|
||||||
|
@ -213,7 +216,8 @@ class Provider
|
||||||
*/
|
*/
|
||||||
public function Entity2ArrayJustIncludes($entity, array $includes, int $deep = 1): null|array
|
public function Entity2ArrayJustIncludes($entity, array $includes, int $deep = 1): null|array
|
||||||
{
|
{
|
||||||
if (is_null($entity)) return [];
|
if (is_null($entity))
|
||||||
|
return [];
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($includes as $method) {
|
foreach ($includes as $method) {
|
||||||
if (method_exists($entity, $method)) {
|
if (method_exists($entity, $method)) {
|
||||||
|
@ -236,7 +240,8 @@ class Provider
|
||||||
*/
|
*/
|
||||||
public function ArrayEntity2ArrayJustIncludes(array $entity, array $includes, int $deep = 1): null|array
|
public function ArrayEntity2ArrayJustIncludes(array $entity, array $includes, int $deep = 1): null|array
|
||||||
{
|
{
|
||||||
if (count($entity) == 0) return [];
|
if (count($entity) == 0)
|
||||||
|
return [];
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($entity as $item) {
|
foreach ($entity as $item) {
|
||||||
$result[] = $this->Entity2ArrayJustIncludes($item, $includes, $deep);
|
$result[] = $this->Entity2ArrayJustIncludes($item, $includes, $deep);
|
||||||
|
@ -260,4 +265,29 @@ class Provider
|
||||||
|
|
||||||
return $result;
|
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