some progress in commodity and reports
This commit is contained in:
parent
f1f18b9561
commit
e5ecfe747e
|
@ -28,7 +28,8 @@ class CommodityController extends AbstractController
|
||||||
#[Route('/api/commodity/list', name: 'app_commodity_list')]
|
#[Route('/api/commodity/list', name: 'app_commodity_list')]
|
||||||
public function app_commodity_list(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
public function app_commodity_list(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
||||||
{
|
{
|
||||||
if (!$access->hasRole('commodity'))
|
$acc = $access->hasRole('commodity');
|
||||||
|
if (!$acc)
|
||||||
throw $this->createAccessDeniedException();
|
throw $this->createAccessDeniedException();
|
||||||
$params = [];
|
$params = [];
|
||||||
if ($content = $request->getContent()) {
|
if ($content = $request->getContent()) {
|
||||||
|
@ -66,6 +67,84 @@ class CommodityController extends AbstractController
|
||||||
$temp['minOrderCount'] = $item->getMinOrderCount();
|
$temp['minOrderCount'] = $item->getMinOrderCount();
|
||||||
$temp['dayLoading'] = $item->getDayLoading();
|
$temp['dayLoading'] = $item->getDayLoading();
|
||||||
$temp['orderPoint'] = $item->getOrderPoint();
|
$temp['orderPoint'] = $item->getOrderPoint();
|
||||||
|
//calculate count
|
||||||
|
if ($item->isKhadamat()) {
|
||||||
|
$temp['count'] = 0;
|
||||||
|
} else {
|
||||||
|
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
||||||
|
'bid' => $acc['bid'],
|
||||||
|
'commodity' => $item
|
||||||
|
]);
|
||||||
|
$count = 0;
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
if ($row->getDoc()->getType() == 'buy') {
|
||||||
|
$count += $row->getCommdityCount();
|
||||||
|
} elseif ($row->getDoc()->getType() == 'sell') {
|
||||||
|
$count -= $row->getCommdityCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$temp['count'] = $count;
|
||||||
|
}
|
||||||
|
|
||||||
|
$res[] = $temp;
|
||||||
|
}
|
||||||
|
return $this->json($res);
|
||||||
|
}
|
||||||
|
#[Route('/api/commodity/list/search', name: 'app_commodity_list_search')]
|
||||||
|
public function app_commodity_list_search(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
||||||
|
{
|
||||||
|
$acc = $access->hasRole('commodity');
|
||||||
|
if (!$acc)
|
||||||
|
throw $this->createAccessDeniedException();
|
||||||
|
$params = [];
|
||||||
|
if ($content = $request->getContent()) {
|
||||||
|
$params = json_decode($content, true);
|
||||||
|
}
|
||||||
|
if (array_key_exists('search', $params))
|
||||||
|
$items = $entityManager->getRepository(Commodity::class)->searchByName($acc['bid'], $params['search'], 10);
|
||||||
|
else
|
||||||
|
$items = $entityManager->getRepository(Commodity::class)->getLasts($acc['bid'], 10);
|
||||||
|
$res = [];
|
||||||
|
foreach ($items as $key => $item) {
|
||||||
|
$temp = [];
|
||||||
|
$temp['id'] = $item->getId();
|
||||||
|
$temp['name'] = $item->getName();
|
||||||
|
$temp['unit'] = $item->getUnit()->getName();
|
||||||
|
$temp['des'] = $item->getDes();
|
||||||
|
$temp['priceBuy'] = $item->getPriceBuy();
|
||||||
|
$temp['speedAccess'] = $item->isSpeedAccess();
|
||||||
|
$temp['priceSell'] = $item->getPriceSell();
|
||||||
|
$temp['code'] = $item->getCode();
|
||||||
|
$temp['cat'] = null;
|
||||||
|
if ($item->getCat())
|
||||||
|
$temp['cat'] = $item->getCat()->getName();
|
||||||
|
$temp['khadamat'] = false;
|
||||||
|
if ($item->isKhadamat())
|
||||||
|
$temp['khadamat'] = true;
|
||||||
|
|
||||||
|
$temp['commodityCountCheck'] = $item->isCommodityCountCheck();
|
||||||
|
$temp['minOrderCount'] = $item->getMinOrderCount();
|
||||||
|
$temp['dayLoading'] = $item->getDayLoading();
|
||||||
|
$temp['orderPoint'] = $item->getOrderPoint();
|
||||||
|
//calculate count
|
||||||
|
if ($item->isKhadamat()) {
|
||||||
|
$temp['count'] = 0;
|
||||||
|
} else {
|
||||||
|
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
||||||
|
'bid' => $acc['bid'],
|
||||||
|
'commodity' => $item
|
||||||
|
]);
|
||||||
|
$count = 0;
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
if ($row->getDoc()->getType() == 'buy') {
|
||||||
|
$count += $row->getCommdityCount();
|
||||||
|
} elseif ($row->getDoc()->getType() == 'sell') {
|
||||||
|
$count -= $row->getCommdityCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$temp['count'] = $count;
|
||||||
|
}
|
||||||
|
|
||||||
$res[] = $temp;
|
$res[] = $temp;
|
||||||
}
|
}
|
||||||
return $this->json($res);
|
return $this->json($res);
|
||||||
|
@ -153,6 +232,25 @@ class CommodityController extends AbstractController
|
||||||
$res['cat'] = '';
|
$res['cat'] = '';
|
||||||
if ($data->getCat())
|
if ($data->getCat())
|
||||||
$res['cat'] = $data->getCat()->getId();
|
$res['cat'] = $data->getCat()->getId();
|
||||||
|
$count = 0;
|
||||||
|
//calculate count
|
||||||
|
if ($data->isKhadamat()) {
|
||||||
|
$res['count'] = 0;
|
||||||
|
} else {
|
||||||
|
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
|
||||||
|
'bid' => $acc['bid'],
|
||||||
|
'commodity' => $data
|
||||||
|
]);
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
if ($row->getDoc()->getType() == 'buy') {
|
||||||
|
$count += $row->getCommdityCount();
|
||||||
|
} elseif ($row->getDoc()->getType() == 'sell') {
|
||||||
|
$count -= $row->getCommdityCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$res['count'] = $count;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->json($res);
|
return $this->json($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,14 @@
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Commodity;
|
||||||
use App\Entity\Person;
|
use App\Entity\Person;
|
||||||
use App\Service\Access;
|
use App\Service\Access;
|
||||||
use App\Service\pdfMGR;
|
use App\Service\pdfMGR;
|
||||||
use App\Service\Provider;
|
use App\Service\Provider;
|
||||||
use App\Entity\HesabdariDoc;
|
use App\Entity\HesabdariDoc;
|
||||||
use App\Entity\HesabdariRow;
|
use App\Entity\HesabdariRow;
|
||||||
|
use App\Service\Explore;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
@ -143,4 +145,80 @@ class ReportController extends AbstractController
|
||||||
];
|
];
|
||||||
return new BinaryFileResponse($provider->createExcellFromArray($response));
|
return new BinaryFileResponse($provider->createExcellFromArray($response));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Route('/api/report/commodity/buysell', name: 'app_report_commodity_buysell')]
|
||||||
|
public function app_report_commodity_buysell(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 ($params['type'] == 'all') {
|
||||||
|
$docs = $entityManagerInterface->getRepository(HesabdariDoc::class)->findBy([
|
||||||
|
'year' => $acc['year'],
|
||||||
|
'bid' => $acc['bid'],
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
$docs = $entityManagerInterface->getRepository(HesabdariDoc::class)->findBy([
|
||||||
|
'year' => $acc['year'],
|
||||||
|
'bid' => $acc['bid'],
|
||||||
|
'type' => $params['type'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$commodity = $entityManagerInterface->getRepository(Commodity::class)->findOneBy([
|
||||||
|
'bid' => $acc['bid']->getId(),
|
||||||
|
'code' => $params['commodity'],
|
||||||
|
]);
|
||||||
|
$result = [];
|
||||||
|
foreach ($docs as $doc) {
|
||||||
|
$rows = $doc->getHesabdariRows();
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
if ($row->getCommodity() && $row->getCommodity()->getId() == $commodity->getId()) {
|
||||||
|
$result[] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [];
|
||||||
|
foreach ($result as $item) {
|
||||||
|
$temp = [
|
||||||
|
'id' => $item->getCommodity()->getId(),
|
||||||
|
'rowId' => $item->getId(),
|
||||||
|
'code' => $item->getCommodity()->getCode(),
|
||||||
|
'khadamat' => $item->getCommodity()->isKhadamat(),
|
||||||
|
'name' => $item->getCommodity()->getName(),
|
||||||
|
'unit' => $item->getCommodity()->getUnit()->getName(),
|
||||||
|
'count' => $item->getCommdityCount(),
|
||||||
|
'date' => $item->getDoc()->getDate(),
|
||||||
|
'docCode' => $item->getDoc()->getCode(),
|
||||||
|
'type' => $item->getDoc()->getType(),
|
||||||
|
];
|
||||||
|
if ($item->getDoc()->getType() == 'buy') {
|
||||||
|
$temp['priceAll'] = $item->getBd();
|
||||||
|
} elseif ($item->getDoc()->getType() == 'sell') {
|
||||||
|
$temp['priceAll'] = $item->getBs();
|
||||||
|
}
|
||||||
|
if ($temp['count'] != 0) {
|
||||||
|
$temp['priceOne'] = $temp['priceAll'] / $temp['count'];
|
||||||
|
$temp['priceAll'] = number_format($temp['priceAll']);
|
||||||
|
$temp['priceOne'] = number_format($temp['priceOne']);
|
||||||
|
$temp['count'] = number_format($temp['count']);
|
||||||
|
}
|
||||||
|
//find person
|
||||||
|
foreach ($item->getDoc()->getHesabdariRows() as $rw) {
|
||||||
|
if ($rw->getPerson()) {
|
||||||
|
$temp['person'] = Explore::ExplorePerson($rw->getPerson());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$response[] = $temp;
|
||||||
|
}
|
||||||
|
return $this->json($response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
|
|
||||||
namespace App\Repository;
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\Business;
|
||||||
use App\Entity\Commodity;
|
use App\Entity\Commodity;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
||||||
use Doctrine\ORM\OptimisticLockException;
|
|
||||||
use Doctrine\ORM\ORMException;
|
use Doctrine\ORM\ORMException;
|
||||||
|
use Doctrine\ORM\OptimisticLockException;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method Commodity|null find($id, $lockMode = null, $lockVersion = null)
|
* @method Commodity|null find($id, $lockMode = null, $lockVersion = null)
|
||||||
|
@ -54,6 +55,35 @@ class CommodityRepository extends ServiceEntityRepository
|
||||||
->getResult()
|
->getResult()
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @return Person[] Returns an array of Person objects
|
||||||
|
*/
|
||||||
|
public function searchByName(Business $bid,string $search,int $maxResults = 10): array
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('p')
|
||||||
|
->andWhere('p.bid = :val')
|
||||||
|
->andWhere("p.name LIKE :search")
|
||||||
|
->setParameter('val', $bid)
|
||||||
|
->setParameter('search', '%' . $search . '%')
|
||||||
|
->setMaxResults($maxResults)
|
||||||
|
->orderBy('p.id', 'ASC')
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Person[] Returns an array of Person objects
|
||||||
|
*/
|
||||||
|
public function getLasts(Business $bid,int $maxResults = 10): array
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('p')
|
||||||
|
->andWhere('p.bid = :val')
|
||||||
|
->setParameter('val', $bid)
|
||||||
|
->setMaxResults($maxResults)
|
||||||
|
->orderBy('p.id', 'ASC')
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
}
|
||||||
// /**
|
// /**
|
||||||
// * @return Commodity[] Returns an array of Commodity objects
|
// * @return Commodity[] Returns an array of Commodity objects
|
||||||
// */
|
// */
|
||||||
|
|
Loading…
Reference in a new issue