almost finish chart data sell

This commit is contained in:
Hesabix 2025-02-11 00:56:26 +00:00
parent 6ec2fb99d7
commit 673a962dfa
4 changed files with 79 additions and 21 deletions

View file

@ -62,6 +62,7 @@ class DashboardController extends AbstractController
if(array_key_exists('commodities',$params)) $setting->setCommodities($params['commodities']); if(array_key_exists('commodities',$params)) $setting->setCommodities($params['commodities']);
if(array_key_exists('persons',$params)) $setting->setPersons($params['persons']); if(array_key_exists('persons',$params)) $setting->setPersons($params['persons']);
if(array_key_exists('notif',$params)) $setting->setNotif($params['notif']); if(array_key_exists('notif',$params)) $setting->setNotif($params['notif']);
if(array_key_exists('sellChart',$params)) $setting->setSellChart($params['sellChart']);
$entityManagerInterface->persist($setting); $entityManagerInterface->persist($setting);
$entityManagerInterface->flush(); $entityManagerInterface->flush();

View file

@ -2,6 +2,7 @@
namespace App\Controller; namespace App\Controller;
use App\Service\Jdate;
use App\Service\Log; use App\Service\Log;
use App\Service\Access; use App\Service\Access;
use App\Service\Explore; use App\Service\Explore;
@ -39,7 +40,7 @@ class SellController extends AbstractController
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
'bid' => $acc['bid'], 'bid' => $acc['bid'],
'code' => $code, 'code' => $code,
'money'=> $acc['money'] 'money' => $acc['money']
]); ]);
//check related documents //check related documents
if (count($doc->getRelatedDocs()) != 0) if (count($doc->getRelatedDocs()) != 0)
@ -63,7 +64,7 @@ class SellController extends AbstractController
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
'bid' => $acc['bid'], 'bid' => $acc['bid'],
'code' => $code, 'code' => $code,
'money'=> $acc['money'] 'money' => $acc['money']
]); ]);
if (!$doc) if (!$doc)
throw $this->createNotFoundException(); throw $this->createNotFoundException();
@ -74,8 +75,7 @@ class SellController extends AbstractController
if ($item->getCommodity() && $item->getCommdityCount()) { if ($item->getCommodity() && $item->getCommdityCount()) {
if ($acc['bid']->getProfitCalctype() == 'simple') { if ($acc['bid']->getProfitCalctype() == 'simple') {
$profit = $profit + (($item->getCommodity()->getPriceSell() - $item->getCommodity()->getPriceSell()) * $item->getCommdityCount()); $profit = $profit + (($item->getCommodity()->getPriceSell() - $item->getCommodity()->getPriceSell()) * $item->getCommdityCount());
} } elseif ($acc['bid']->getProfitCalctype() == 'lis') {
elseif ($acc['bid']->getProfitCalctype() == 'lis') {
$last = $entityManager->getRepository(HesabdariRow::class)->findOneBy([ $last = $entityManager->getRepository(HesabdariRow::class)->findOneBy([
'commodity' => $item->getCommodity(), 'commodity' => $item->getCommodity(),
'bs' => 0 'bs' => 0
@ -104,8 +104,7 @@ class SellController extends AbstractController
if ($count != 0) { if ($count != 0) {
$price = $avg / $count; $price = $avg / $count;
$profit = $profit + ((($item->getBs() / $item->getCommdityCount()) - $price) * $item->getCommdityCount()); $profit = $profit + ((($item->getBs() / $item->getCommdityCount()) - $price) * $item->getCommdityCount());
} } else {
else{
$profit = $profit + $item->getBs(); $profit = $profit + $item->getBs();
} }
@ -139,11 +138,11 @@ class SellController extends AbstractController
'bid' => $acc['bid'], 'bid' => $acc['bid'],
'year' => $acc['year'], 'year' => $acc['year'],
'code' => $params['update'], 'code' => $params['update'],
'money'=> $acc['money'] 'money' => $acc['money']
]); ]);
if (!$doc) if (!$doc)
return $this->json($extractor->notFound()); return $this->json($extractor->notFound());
$rows = $doc->getHesabdariRows(); $rows = $doc->getHesabdariRows();
foreach ($rows as $row) foreach ($rows as $row)
$entityManager->remove($row); $entityManager->remove($row);
@ -249,19 +248,19 @@ class SellController extends AbstractController
$entityManager->persist($doc); $entityManager->persist($doc);
$entityManager->flush(); $entityManager->flush();
if(!$doc->getShortlink()){ if (!$doc->getShortlink()) {
$doc->setShortlink($doc->getId()); $doc->setShortlink($doc->getId());
} }
//add pair docs //add pair docs
if(array_key_exists('pair_docs',$params)){ if (array_key_exists('pair_docs', $params)) {
foreach($params['pair_docs'] as $pairCode){ foreach ($params['pair_docs'] as $pairCode) {
$pair = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ $pair = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
'bid'=>$acc['bid'], 'bid' => $acc['bid'],
'code'=>$pairCode, 'code' => $pairCode,
'type'=>'buy' 'type' => 'buy'
]); ]);
if($pair){ if ($pair) {
$doc->addPairDoc($pair); $doc->addPairDoc($pair);
} }
} }
@ -333,7 +332,7 @@ class SellController extends AbstractController
'bid' => $acc['bid'], 'bid' => $acc['bid'],
'year' => $acc['year'], 'year' => $acc['year'],
'code' => $item['code'], 'code' => $item['code'],
'money'=> $acc['money'] 'money' => $acc['money']
]); ]);
if (!$doc) if (!$doc)
return $this->json($extractor->notFound()); return $this->json($extractor->notFound());
@ -378,7 +377,7 @@ class SellController extends AbstractController
'bid' => $acc['bid'], 'bid' => $acc['bid'],
'year' => $acc['year'], 'year' => $acc['year'],
'type' => 'sell', 'type' => 'sell',
'money'=> $acc['money'] 'money' => $acc['money']
], [ ], [
'id' => 'DESC' 'id' => 'DESC'
]); ]);
@ -454,8 +453,7 @@ class SellController extends AbstractController
if ($count != 0) { if ($count != 0) {
$price = $avg / $count; $price = $avg / $count;
$temp['profit'] = $temp['profit'] + ((($item->getBs() / $item->getCommdityCount()) - $price) * $item->getCommdityCount()); $temp['profit'] = $temp['profit'] + ((($item->getBs() / $item->getCommdityCount()) - $price) * $item->getCommdityCount());
} } else {
else{
$temp['profit'] = $temp['profit'] + $item->getBs(); $temp['profit'] = $temp['profit'] + $item->getBs();
} }
} }
@ -489,7 +487,7 @@ class SellController extends AbstractController
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
'bid' => $acc['bid'], 'bid' => $acc['bid'],
'code' => $params['code'], 'code' => $params['code'],
'money'=> $acc['money'] 'money' => $acc['money']
]); ]);
if (!$doc) if (!$doc)
throw $this->createNotFoundException(); throw $this->createNotFoundException();
@ -555,7 +553,7 @@ class SellController extends AbstractController
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
'bid' => $acc['bid'], 'bid' => $acc['bid'],
'code' => $params['code'], 'code' => $params['code'],
'money'=> $acc['money'] 'money' => $acc['money']
]); ]);
if (!$doc) if (!$doc)
throw $this->createNotFoundException(); throw $this->createNotFoundException();
@ -639,4 +637,45 @@ class SellController extends AbstractController
} }
return $this->json(['id' => $pdfPid]); return $this->json(['id' => $pdfPid]);
} }
#[Route('/api/sell/chart/data', name: 'app_sell_chart_data')]
public function app_sell_chart_data(Jdate $jdate, Printers $printers, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{
$acc = $access->hasRole('sell');
if (!$acc)
throw $this->createAccessDeniedException();
// create data numbers
$dayTime = 3600 * 24;
$dayNames = [];
$daySells = [];
for ($i = 0; $i < 7; $i++) {
$dayInfo = [
$jdate->jdate('l', time() - ($i * $dayTime)),
$jdate->jdate('Y/n/d', time() - ($i * $dayTime))
];
$dayNames[] = $jdate->jdate('l', time() - ($i * $dayTime));
//get sell docs
$docs = $entityManager->getRepository(HesabdariDoc::class)->findBy([
'bid' => $acc['bid'],
'money' => $acc['money'],
'year' => $acc['year'],
'type' => 'sell',
'date' => $dayInfo[1],
]);
$bd = 0;
foreach ($docs as $doc) {
foreach ($doc->getHesabdariRows() as $row) {
if ($row->getPerson()) {
$bd += $row->getBd();
}
}
}
$daySells[] = $bd;
}
return $this->json([
'dayNames' => $dayNames,
'daySells' => $daySells
]);
}
} }

View file

@ -48,6 +48,9 @@ class DashboardSettings
#[ORM\Column(nullable: true)] #[ORM\Column(nullable: true)]
private ?bool $notif = null; private ?bool $notif = null;
#[ORM\Column(nullable: true)]
private ?bool $sellChart = null;
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;
@ -184,4 +187,16 @@ class DashboardSettings
return $this; return $this;
} }
public function isSellChart(): ?bool
{
return $this->sellChart;
}
public function setSellChart(?bool $sellChart): static
{
$this->sellChart = $sellChart;
return $this;
}
} }

View file

@ -577,6 +577,7 @@ class Explore
'commodities' => $item->isCommodities(), 'commodities' => $item->isCommodities(),
'persons' => $item->isPersons(), 'persons' => $item->isPersons(),
'notif' => $item->isNotif(), 'notif' => $item->isNotif(),
'sellChart' => $item->isSellChart(),
]; ];
if ($result['banks'] === null) if ($result['banks'] === null)
$result['banks'] = true; $result['banks'] = true;
@ -596,6 +597,8 @@ class Explore
$result['persons'] = true; $result['persons'] = true;
if ($result['notif'] === null) if ($result['notif'] === null)
$result['notif'] = true; $result['notif'] = true;
if ($result['sellChart'] === null)
$result['sellChart'] = true;
return $result; return $result;
} }