almost complete commodity list and explore accounts
This commit is contained in:
parent
2ad9c8bf7b
commit
f2bc6f07c6
|
@ -21,14 +21,135 @@ use App\Entity\StoreroomItem;
|
|||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class CommodityController extends AbstractController
|
||||
{
|
||||
|
||||
#[Route('/api/commodities/search', name: 'search_commodities')]
|
||||
public function searchCommodities(
|
||||
Access $access,
|
||||
EntityManagerInterface $entityManager,
|
||||
Request $request,
|
||||
Explore $explore
|
||||
): JsonResponse {
|
||||
$acc = $access->hasRole('commodity');
|
||||
if (!$acc) {
|
||||
throw $this->createAccessDeniedException();
|
||||
}
|
||||
|
||||
// دریافت دادهها از بدنه درخواست POST
|
||||
$payload = json_decode($request->getContent(), true) ?? [];
|
||||
$filters = $payload['filters'] ?? [];
|
||||
$pagination = $payload['pagination'] ?? [];
|
||||
$sort = $payload['sort'] ?? [];
|
||||
|
||||
// پارامترهای صفحهبندی و مرتبسازی
|
||||
$page = max(1, $pagination['page'] ?? 1);
|
||||
$limit = max(1, $pagination['limit'] ?? 10);
|
||||
$sortBy = $sort['sortBy'] ?? 'code';
|
||||
$sortDesc = $sort['sortDesc'] ?? true;
|
||||
|
||||
// فیلدهای معتبر برای مرتبسازی
|
||||
$validSortFields = ['id', 'name', 'code', 'des', 'priceBuy', 'priceSell', 'orderPoint', 'minOrderCount', 'dayLoading'];
|
||||
$sortBy = in_array($sortBy, $validSortFields) ? $sortBy : 'code';
|
||||
|
||||
// ساخت کوئری پایه
|
||||
$qb = $entityManager->getRepository(Commodity::class)->createQueryBuilder('c')
|
||||
->andWhere('c.bid = :bid')
|
||||
->setParameter('bid', $acc['bid']);
|
||||
|
||||
// اعمال فیلتر دستهبندی
|
||||
if (!empty($filters['cat']) && !empty($filters['cat']['value'])) {
|
||||
$qb->andWhere('c.cat IN (:cats)')
|
||||
->setParameter('cats', (array) $filters['cat']['value']);
|
||||
}
|
||||
|
||||
// جستجوی جامع در تمام فیلدها
|
||||
if (!empty($filters['search']) && !empty($filters['search']['value'])) {
|
||||
$searchValue = trim($filters['search']['value']);
|
||||
$searchConditions = [];
|
||||
$searchParams = [];
|
||||
|
||||
// فیلدهای رشتهای با LOWER
|
||||
$stringFields = ['name', 'des', 'barcodes'];
|
||||
foreach ($stringFields as $index => $field) {
|
||||
$paramName = "search_$index";
|
||||
$searchConditions[] = "LOWER(c.$field) LIKE :$paramName";
|
||||
$searchParams[$paramName] = "%$searchValue%";
|
||||
}
|
||||
|
||||
// کد کالا بدون LOWER
|
||||
$searchConditions[] = "c.code LIKE :search_code";
|
||||
$searchParams['search_code'] = "%$searchValue%";
|
||||
|
||||
// فیلدهای عددی
|
||||
$numericFields = ['priceBuy', 'priceSell', 'orderPoint', 'minOrderCount', 'dayLoading'];
|
||||
foreach ($numericFields as $index => $field) {
|
||||
$paramName = "search_" . (count($stringFields) + $index + 1);
|
||||
$searchConditions[] = "CAST(c.$field AS CHAR) LIKE :$paramName";
|
||||
$searchParams[$paramName] = "%$searchValue%";
|
||||
}
|
||||
|
||||
// جستجو در نام واحد شمارش
|
||||
$qb->leftJoin('c.unit', 'u');
|
||||
$searchConditions[] = "LOWER(u.name) LIKE :search_unit";
|
||||
$searchParams['search_unit'] = "%$searchValue%";
|
||||
|
||||
$qb->andWhere('(' . implode(' OR ', $searchConditions) . ')');
|
||||
foreach ($searchParams as $param => $value) {
|
||||
$qb->setParameter($param, $value);
|
||||
}
|
||||
}
|
||||
|
||||
// مرتبسازی
|
||||
$qb->orderBy("c.$sortBy", $sortDesc ? 'DESC' : 'ASC');
|
||||
|
||||
// شمارش کل نتایج
|
||||
$countQb = clone $qb;
|
||||
$totalItems = $countQb->select('COUNT(c.id)')->getQuery()->getSingleScalarResult();
|
||||
|
||||
// اعمال صفحهبندی
|
||||
$qb->setFirstResult(($page - 1) * $limit)
|
||||
->setMaxResults($limit);
|
||||
|
||||
// اجرای کوئری
|
||||
$results = $qb->getQuery()->getResult();
|
||||
|
||||
// تبدیل نتایج
|
||||
$data = array_map(function (Commodity $item) use ($entityManager, $acc, $explore) {
|
||||
$temp = $explore::ExploreCommodity($item);
|
||||
if (!$item->isKhadamat()) {
|
||||
$rows = $entityManager->getRepository('App\Entity\HesabdariRow')->findBy([
|
||||
'bid' => $acc['bid'],
|
||||
'commodity' => $item
|
||||
]);
|
||||
$count = 0;
|
||||
foreach ($rows as $row) {
|
||||
$count += $row->getDoc()->getType() === 'buy' ? $row->getCommdityCount() : -$row->getCommdityCount();
|
||||
}
|
||||
$temp['count'] = $count;
|
||||
}
|
||||
return $temp;
|
||||
}, $results);
|
||||
|
||||
return new JsonResponse([
|
||||
'results' => $data,
|
||||
'pagination' => [
|
||||
'current_page' => $page,
|
||||
'per_page' => $limit,
|
||||
'total_items' => (int) $totalItems,
|
||||
'total_pages' => ceil($totalItems / $limit),
|
||||
],
|
||||
], 200);
|
||||
}
|
||||
|
||||
#[Route('/api/commodity/search/extra', name: 'app_commodity_search_extra')]
|
||||
public function app_commodity_search_extra(Provider $provider, Extractor $extractor, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
||||
{
|
||||
|
@ -338,63 +459,93 @@ class CommodityController extends AbstractController
|
|||
return $this->json($extractor->operationSuccess($temp));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
#[Route('/api/commodity/list/excel', name: 'app_commodity_list_excel')]
|
||||
public function app_commodity_list_excel(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): BinaryFileResponse|JsonResponse|StreamedResponse
|
||||
{
|
||||
#[Route('/api/commodity/list/excel', name: 'app_commodity_list_excel', methods: ['POST'])]
|
||||
public function app_commodity_list_excel(
|
||||
Provider $provider,
|
||||
Request $request,
|
||||
Access $access,
|
||||
Log $log,
|
||||
EntityManagerInterface $entityManager
|
||||
): BinaryFileResponse {
|
||||
$acc = $access->hasRole('commodity');
|
||||
if (!$acc)
|
||||
if (!$acc) {
|
||||
throw $this->createAccessDeniedException();
|
||||
$params = [];
|
||||
if ($content = $request->getContent()) {
|
||||
$params = json_decode($content, true);
|
||||
}
|
||||
if (!array_key_exists('items', $params)) {
|
||||
$items = $entityManager->getRepository(Commodity::class)->findBy([
|
||||
'bid' => $acc['bid']
|
||||
]);
|
||||
|
||||
$params = json_decode($request->getContent(), true) ?? [];
|
||||
|
||||
if (isset($params['all']) && $params['all'] === true) {
|
||||
// دریافت همه کالاها بدون محدودیت
|
||||
$items = $entityManager->getRepository(Commodity::class)->findBy(['bid' => $acc['bid']]);
|
||||
} else {
|
||||
if (!isset($params['items']) || empty($params['items'])) {
|
||||
throw new \Exception('هیچ کالایی برای خروجی انتخاب نشده است');
|
||||
}
|
||||
$items = [];
|
||||
foreach ($params['items'] as $param) {
|
||||
$prs = $entityManager->getRepository(Commodity::class)->findOneBy([
|
||||
$item = $entityManager->getRepository(Commodity::class)->findOneBy([
|
||||
'id' => $param['id'],
|
||||
'bid' => $acc['bid']
|
||||
]);
|
||||
if ($prs)
|
||||
$items[] = $prs;
|
||||
if ($item) {
|
||||
$items[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
return new BinaryFileResponse($provider->createExcell($items));
|
||||
|
||||
if (empty($items)) {
|
||||
throw new \Exception('هیچ کالایی برای خروجی یافت نشد');
|
||||
}
|
||||
|
||||
$filePath = $provider->createExcell($items);
|
||||
$response = new BinaryFileResponse($filePath);
|
||||
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'commodities.xlsx');
|
||||
$response->deleteFileAfterSend(true);
|
||||
|
||||
$log->insert('کالا/خدمات', 'خروجی اکسل برای ' . count($items) . ' کالا تولید شد.', $this->getUser(), $acc['bid']->getId());
|
||||
return $response;
|
||||
}
|
||||
|
||||
#[Route('/api/commodity/list/print', name: 'app_commodity_list_print')]
|
||||
public function app_commodity_list_print(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
||||
{
|
||||
|
||||
|
||||
#[Route('/api/commodity/list/print', name: 'app_commodity_list_print', methods: ['POST'])]
|
||||
public function app_commodity_list_print(
|
||||
Provider $provider,
|
||||
Request $request,
|
||||
Access $access,
|
||||
Log $log,
|
||||
EntityManagerInterface $entityManager
|
||||
): JsonResponse {
|
||||
$acc = $access->hasRole('commodity');
|
||||
if (!$acc)
|
||||
if (!$acc) {
|
||||
throw $this->createAccessDeniedException();
|
||||
$params = [];
|
||||
if ($content = $request->getContent()) {
|
||||
$params = json_decode($content, true);
|
||||
}
|
||||
if (!array_key_exists('items', $params)) {
|
||||
$items = $entityManager->getRepository(Commodity::class)->findBy([
|
||||
'bid' => $request->headers->get('activeBid')
|
||||
]);
|
||||
|
||||
$params = json_decode($request->getContent(), true) ?? [];
|
||||
|
||||
if (isset($params['all']) && $params['all'] === true) {
|
||||
// دریافت همه کالاها بدون محدودیت
|
||||
$items = $entityManager->getRepository(Commodity::class)->findBy(['bid' => $acc['bid']]);
|
||||
} else {
|
||||
if (!isset($params['items']) || empty($params['items'])) {
|
||||
return $this->json(['Success' => false, 'message' => 'هیچ کالایی برای چاپ انتخاب نشده است'], 400);
|
||||
}
|
||||
$items = [];
|
||||
foreach ($params['items'] as $param) {
|
||||
$prs = $entityManager->getRepository(Commodity::class)->findOneBy([
|
||||
$item = $entityManager->getRepository(Commodity::class)->findOneBy([
|
||||
'id' => $param['id'],
|
||||
'bid' => $acc['bid']
|
||||
]);
|
||||
if ($prs)
|
||||
$items[] = $prs;
|
||||
if ($item) {
|
||||
$items[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($items)) {
|
||||
return $this->json(['Success' => false, 'message' => 'هیچ کالایی برای چاپ یافت نشد'], 400);
|
||||
}
|
||||
|
||||
$pid = $provider->createPrint(
|
||||
$acc['bid'],
|
||||
$this->getUser(),
|
||||
|
@ -404,8 +555,11 @@ class CommodityController extends AbstractController
|
|||
'persons' => $items
|
||||
])
|
||||
);
|
||||
|
||||
$log->insert('کالا/خدمات', 'خروجی PDF برای ' . count($items) . ' کالا تولید شد.', $this->getUser(), $acc['bid']->getId());
|
||||
return $this->json(['id' => $pid]);
|
||||
}
|
||||
|
||||
#[Route('/api/commodity/info/{code}', name: 'app_commodity_info')]
|
||||
public function app_commodity_info($code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
||||
{
|
||||
|
@ -1079,70 +1233,100 @@ class CommodityController extends AbstractController
|
|||
return $this->json(['result' => 1]);
|
||||
}
|
||||
|
||||
#[Route('/api/commodity/delete/{code}', name: 'app_commodity_delete')]
|
||||
public function app_commodity_delete(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse
|
||||
{
|
||||
#[Route('/api/commodities/{code}', name: 'app_commodity_delete', methods: ['DELETE'])]
|
||||
public function app_commodity_delete(
|
||||
Provider $provider,
|
||||
Request $request,
|
||||
Access $access,
|
||||
Log $log,
|
||||
EntityManagerInterface $entityManager,
|
||||
$code = 0
|
||||
): JsonResponse {
|
||||
$acc = $access->hasRole('commodity');
|
||||
if (!$acc)
|
||||
if (!$acc) {
|
||||
throw $this->createAccessDeniedException();
|
||||
}
|
||||
|
||||
$commodity = $entityManager->getRepository(Commodity::class)->findOneBy(['bid' => $acc['bid'], 'code' => $code]);
|
||||
if (!$commodity)
|
||||
throw $this->createNotFoundException();
|
||||
//check accounting docs
|
||||
$docs = $entityManager->getRepository(HesabdariRow::class)->findby(['bid' => $acc['bid'], 'commodity' => $commodity]);
|
||||
if (count($docs) > 0)
|
||||
return $this->json(['result' => 2]);
|
||||
//check for storeroom docs
|
||||
$storeDocs = $entityManager->getRepository(StoreroomItem::class)->findby(['bid' => $acc['bid'], 'commodity' => $commodity]);
|
||||
if (count($storeDocs) > 0)
|
||||
return $this->json(['result' => 2]);
|
||||
if (!$commodity) {
|
||||
throw $this->createNotFoundException('کالا یافت نشد');
|
||||
}
|
||||
|
||||
// بررسی اسناد حسابداری
|
||||
$docs = $entityManager->getRepository(HesabdariRow::class)->findBy(['bid' => $acc['bid'], 'commodity' => $commodity]);
|
||||
if (count($docs) > 0) {
|
||||
return $this->json(['result' => 2, 'message' => 'این کالا در اسناد حسابداری استفاده شده و قابل حذف نیست']);
|
||||
}
|
||||
|
||||
// بررسی اسناد انبار
|
||||
$storeDocs = $entityManager->getRepository(StoreroomItem::class)->findBy(['bid' => $acc['bid'], 'commodity' => $commodity]);
|
||||
if (count($storeDocs) > 0) {
|
||||
return $this->json(['result' => 2, 'message' => 'این کالا در اسناد انبار استفاده شده و قابل حذف نیست']);
|
||||
}
|
||||
|
||||
$comName = $commodity->getName();
|
||||
$entityManager->remove($commodity);
|
||||
$log->insert('کالا/خدمات', ' کالا / خدمات با نام ' . $comName . ' حذف شد. ', $this->getUser(), $acc['bid']->getId());
|
||||
return $this->json(['result' => 1]);
|
||||
$entityManager->flush();
|
||||
$log->insert('کالا/خدمات', 'کالا/خدمات با نام ' . $comName . ' حذف شد.', $this->getUser(), $acc['bid']->getId());
|
||||
return $this->json(['result' => 1, 'message' => 'کالا با موفقیت حذف شد']);
|
||||
}
|
||||
|
||||
#[Route('/api/commodity/deletegroup', name: 'app_commodity_delete_group')]
|
||||
public function app_commodity_delete_group(Extractor $extractor, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse
|
||||
{
|
||||
#[Route('/api/commodity/deletegroup', name: 'app_commodity_delete_group', methods: ['POST'])]
|
||||
public function app_commodity_delete_group(
|
||||
Extractor $extractor,
|
||||
Request $request,
|
||||
Access $access,
|
||||
Log $log,
|
||||
EntityManagerInterface $entityManager
|
||||
): JsonResponse {
|
||||
$acc = $access->hasRole('commodity');
|
||||
if (!$acc)
|
||||
if (!$acc) {
|
||||
throw $this->createAccessDeniedException();
|
||||
$params = $request->getPayload()->all();
|
||||
}
|
||||
|
||||
$params = json_decode($request->getContent(), true);
|
||||
if (!isset($params['codes']) || !is_array($params['codes'])) {
|
||||
return $this->json(['Success' => false, 'message' => 'لیست کدهای کالا ارسال نشده است'], 400);
|
||||
}
|
||||
|
||||
$hasIgnored = false;
|
||||
foreach ($params as $param) {
|
||||
$deletedCount = 0;
|
||||
|
||||
foreach ($params['codes'] as $code) {
|
||||
$commodity = $entityManager->getRepository(Commodity::class)->findOneBy([
|
||||
'bid' => $acc['bid'],
|
||||
'code' => $param['code']
|
||||
'code' => $code
|
||||
]);
|
||||
|
||||
if (!$commodity) {
|
||||
$hasIgnored = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
//check accounting docs
|
||||
$docs = $entityManager->getRepository(HesabdariRow::class)->findby(['bid' => $acc['bid'], 'commodity' => $commodity]);
|
||||
if (count($docs) > 0) {
|
||||
$hasIgnored = true;
|
||||
continue;
|
||||
}
|
||||
$docs = $entityManager->getRepository(HesabdariRow::class)->findBy(['bid' => $acc['bid'], 'commodity' => $commodity]);
|
||||
$storeDocs = $entityManager->getRepository(StoreroomItem::class)->findBy(['bid' => $acc['bid'], 'commodity' => $commodity]);
|
||||
|
||||
//check for storeroom docs
|
||||
$storeDocs = $entityManager->getRepository(StoreroomItem::class)->findby(['bid' => $acc['bid'], 'commodity' => $commodity]);
|
||||
if (count($storeDocs) > 0) {
|
||||
if (count($docs) > 0 || count($storeDocs) > 0) {
|
||||
$hasIgnored = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
$comName = $commodity->getName();
|
||||
$entityManager->getRepository(Commodity::class)->remove($commodity, false);
|
||||
$log->insert('کالا/خدمات', ' کالا / خدمات با نام ' . $comName . ' حذف شد. ', $this->getUser(), $acc['bid']->getId());
|
||||
$entityManager->remove($commodity);
|
||||
$log->insert('کالا/خدمات', 'کالا/خدمات با نام ' . $comName . ' حذف شد.', $this->getUser(), $acc['bid']->getId());
|
||||
$deletedCount++;
|
||||
}
|
||||
$entityManager->flush();
|
||||
return $this->json($extractor->operationSuccess(['ignored' => $hasIgnored]));
|
||||
|
||||
$entityManager->flush();
|
||||
|
||||
return $this->json([
|
||||
'Success' => true,
|
||||
'result' => [
|
||||
'ignored' => $hasIgnored,
|
||||
'deletedCount' => $deletedCount,
|
||||
'message' => $hasIgnored ? 'برخی کالاها به دلیل استفاده در اسناد حذف نشدند' : 'همه کالاها با موفقیت حذف شدند'
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/api/commodity/pricelist/list', name: 'app_commodity_pricelist_list')]
|
||||
|
@ -1316,149 +1500,4 @@ class CommodityController extends AbstractController
|
|||
return $this->json($extractor->operationSuccess());
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/api/commodities/search", name="search_commodities", methods={"POST"})
|
||||
*/
|
||||
public function searchCommodities(Access $access, EntityManagerInterface $entityManagerInterface, Request $request): JsonResponse
|
||||
{
|
||||
$acc = $access->hasRole('commodity');
|
||||
if (!$acc) {
|
||||
throw $this->createAccessDeniedException();
|
||||
}
|
||||
|
||||
// لیست فیلدهای ممنوعه
|
||||
$forbiddenFields = ['id', 'bid', 'submitter'];
|
||||
|
||||
// پارامترهای صفحهبندی
|
||||
$page = max(1, $request->query->getInt('page', 1));
|
||||
$limit = max(1, $request->query->getInt('limit', 10));
|
||||
|
||||
// دریافت فیلترهای ارسالی
|
||||
$filters = json_decode($request->getContent(), true);
|
||||
if (!is_array($filters)) {
|
||||
$filters = [];
|
||||
}
|
||||
|
||||
// ساخت کوئری
|
||||
$qb = $entityManagerInterface->getRepository(Commodity::class)->createQueryBuilder('c');
|
||||
|
||||
// شرط ثابت: bid.id همیشه برابر با $acc['bid']
|
||||
$qb->andWhere('c.bid = :bid')
|
||||
->setParameter('bid', $acc['bid']);
|
||||
|
||||
// اعمال فیلترهای کاربر
|
||||
foreach ($filters as $field => $condition) {
|
||||
if (in_array($field, $forbiddenFields)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($condition['operator']) || !isset($condition['value'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$operator = $condition['operator'];
|
||||
$value = $condition['value'];
|
||||
$paramName = str_replace('.', '_', $field) . '_param';
|
||||
|
||||
switch ($operator) {
|
||||
case '=':
|
||||
$qb->andWhere("c.$field = :$paramName")
|
||||
->setParameter($paramName, $value);
|
||||
break;
|
||||
case '>':
|
||||
$qb->andWhere("c.$field > :$paramName")
|
||||
->setParameter($paramName, $value);
|
||||
break;
|
||||
case '<':
|
||||
$qb->andWhere("c.$field < :$paramName")
|
||||
->setParameter($paramName, $value);
|
||||
break;
|
||||
case '%':
|
||||
$qb->andWhere("c.$field LIKE :$paramName")
|
||||
->setParameter($paramName, "%$value%");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// مرتبسازی پیشفرض بر اساس code (نزولی)
|
||||
$qb->orderBy('c.code', 'DESC');
|
||||
|
||||
// شمارش کل نتایج
|
||||
$countQb = clone $qb;
|
||||
$totalItems = $countQb->select('COUNT(c.id)')->getQuery()->getSingleScalarResult();
|
||||
|
||||
// اعمال صفحهبندی
|
||||
$qb->setFirstResult(($page - 1) * $limit)
|
||||
->setMaxResults($limit);
|
||||
|
||||
// اجرای کوئری
|
||||
$results = $qb->getQuery()->getResult();
|
||||
|
||||
// تبدیل نتایج به آرایه
|
||||
$data = array_map(function (Commodity $item) use ($entityManagerInterface, $acc): array {
|
||||
$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['catData'] = Explore::ExploreCommodityCat($item->getCat());
|
||||
}
|
||||
$temp['khadamat'] = false;
|
||||
if ($item->isKhadamat()) {
|
||||
$temp['khadamat'] = true;
|
||||
}
|
||||
$temp['withoutTax'] = false;
|
||||
if ($item->isWithoutTax()) {
|
||||
$temp['withoutTax'] = true;
|
||||
}
|
||||
$temp['commodityCountCheck'] = $item->isCommodityCountCheck();
|
||||
$temp['minOrderCount'] = $item->getMinOrderCount();
|
||||
$temp['dayLoading'] = $item->getDayLoading();
|
||||
$temp['orderPoint'] = $item->getOrderPoint();
|
||||
$temp['unitData'] = [
|
||||
'name' => $item->getUnit()->getName(),
|
||||
'floatNumber' => $item->getUnit()->getFloatNumber(),
|
||||
];
|
||||
$temp['barcodes'] = $item->getBarcodes();
|
||||
// محاسبه موجودی
|
||||
if ($item->isKhadamat()) {
|
||||
$temp['count'] = 0;
|
||||
} else {
|
||||
$rows = $entityManagerInterface->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;
|
||||
}
|
||||
return $temp;
|
||||
}, $results);
|
||||
|
||||
// اطلاعات صفحهبندی
|
||||
$totalPages = ceil($totalItems / $limit);
|
||||
|
||||
return new JsonResponse([
|
||||
'results' => $data,
|
||||
'pagination' => [
|
||||
'current_page' => $page,
|
||||
'per_page' => $limit,
|
||||
'total_items' => $totalItems,
|
||||
'total_pages' => $totalPages,
|
||||
],
|
||||
], 200);
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -15,7 +15,7 @@ use App\Service\Extractor;
|
|||
use App\Service\Jdate;
|
||||
use App\Service\Provider;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Proxies\__CG__\App\Entity\HesabdariRow;
|
||||
use App\Entity\HesabdariRow;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
|
|
@ -21,7 +21,7 @@ use OpenApi\Annotations as OA;
|
|||
|
||||
class PluginController extends AbstractController
|
||||
{
|
||||
private const PRICE_MULTIPLIER = 1.09; // ضریب قیمت به صورت ثابت برای محاسبه
|
||||
private const PRICE_MULTIPLIER = 10.1; // ضریب قیمت به صورت ثابت برای محاسبه
|
||||
|
||||
/**
|
||||
* بررسی دسترسی کاربر با نقش مشخص
|
||||
|
@ -117,7 +117,7 @@ class PluginController extends AbstractController
|
|||
$result = $payMGR->createRequest(
|
||||
$plugin->getPrice(),
|
||||
$this->generateUrl('api_plugin_buy_verify', ['id' => $plugin->getId()], UrlGeneratorInterface::ABSOLUTE_URL),
|
||||
'خرید فضای ابری'
|
||||
'خرید ' . $pp->getName()
|
||||
);
|
||||
|
||||
if ($result['Success'] ?? false) {
|
||||
|
@ -149,7 +149,7 @@ class PluginController extends AbstractController
|
|||
* @OA\Response(response=404, description="افزونه یافت نشد")
|
||||
* )
|
||||
*/
|
||||
#[Route('/api/plugin/buy/verify/{id}', name: 'api_plugin_buy_verify', methods: ["POST"])]
|
||||
#[Route('/api/plugin/buy/verify/{id}', name: 'api_plugin_buy_verify',requirements: ['id' => '.+'], methods: ["POST"])]
|
||||
public function api_plugin_buy_verify(string $id, twigFunctions $twigFunctions, PayMGR $payMGR, Request $request, EntityManagerInterface $entityManager, Log $log): Response
|
||||
{
|
||||
$req = $entityManager->getRepository(Plugin::class)->find($id)
|
||||
|
|
|
@ -2,21 +2,11 @@
|
|||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Commodity;
|
||||
use App\Entity\HesabdariRow;
|
||||
use App\Entity\Money;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\NonUniqueResultException;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<HesabdariRow>
|
||||
*
|
||||
* @method HesabdariRow|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method HesabdariRow|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method HesabdariRow[] findAll()
|
||||
* @method HesabdariRow[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class HesabdariRowRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
|
@ -27,7 +17,6 @@ class HesabdariRowRepository extends ServiceEntityRepository
|
|||
public function save(HesabdariRow $entity, bool $flush = false): void
|
||||
{
|
||||
$this->getEntityManager()->persist($entity);
|
||||
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
|
@ -36,15 +25,42 @@ class HesabdariRowRepository extends ServiceEntityRepository
|
|||
public function remove(HesabdariRow $entity, bool $flush = false): void
|
||||
{
|
||||
$this->getEntityManager()->remove($entity);
|
||||
|
||||
if ($flush) {
|
||||
$this->getEntityManager()->flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws NonUniqueResultException
|
||||
* پیدا کردن ردیفها با جوین روی سند و فیلتر پول، با حذف تکرارها
|
||||
*/
|
||||
public function findByJoinMoney(array $params, Money $money): array
|
||||
{
|
||||
$query = $this->createQueryBuilder('t')
|
||||
->select('DISTINCT t') // حذف تکرارها با DISTINCT
|
||||
->innerJoin('t.doc', 'd')
|
||||
->where('d.money = :money')
|
||||
->andWhere('t.bid = :bid OR t.bid IS NULL') // فقط کسبوکار فعلی یا عمومی
|
||||
->setParameter('money', $money)
|
||||
->setParameter('bid', $params['bid']); // bid از پارامترها دریافت میشود
|
||||
|
||||
unset($params['bid']); // حذف bid از params برای جلوگیری از تداخل
|
||||
|
||||
foreach ($params as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$temp = array_map(fn($v) => is_object($v) ? $v->getId() : $v, $value);
|
||||
$query->andWhere('t.' . $key . ' IN (:' . $key . ')')
|
||||
->setParameter($key, $temp);
|
||||
} else {
|
||||
$query->andWhere('t.' . $key . ' = :' . $key)
|
||||
->setParameter($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $query->getQuery()->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Doctrine\ORM\NonUniqueResultException
|
||||
*/
|
||||
public function getNotEqual($doc, $notField): ?HesabdariRow
|
||||
{
|
||||
|
@ -56,28 +72,4 @@ class HesabdariRowRepository extends ServiceEntityRepository
|
|||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
|
||||
public function findByJoinMoney(array $params, Money $money): array
|
||||
{
|
||||
$query = $this->createQueryBuilder('t')
|
||||
->select('t')
|
||||
->innerJoin('t.doc', 'd')
|
||||
->where('d.money = :money')
|
||||
->setParameter('money', $money);
|
||||
foreach ($params as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$temp = [];
|
||||
foreach ($value as $k => $v) {
|
||||
$temp[] = $v->getId();
|
||||
}
|
||||
$query->andWhere('t.' . $key . ' IN (:' . $key . ')');
|
||||
$query->setParameter($key, $temp);
|
||||
} else {
|
||||
$query->andWhere('t.' . $key . '= :' . $key);
|
||||
$query->setParameter($key, $value);
|
||||
}
|
||||
|
||||
}
|
||||
return $query->getQuery()->getResult();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -54,13 +54,17 @@ class HesabdariTableRepository extends ServiceEntityRepository
|
|||
// ;
|
||||
// }
|
||||
|
||||
public function findNode($value, $bid): ?HesabdariTable
|
||||
/**
|
||||
* پیدا کردن یک نود با فیلتر bid
|
||||
*/
|
||||
public function findNode($nodeId, $bid): ?HesabdariTable
|
||||
{
|
||||
return $this->createQueryBuilder('h')
|
||||
->Where('h.id = :val AND (h.bid= :bid OR h.bid IS NULL)')
|
||||
->setParameters(['val' => $value, 'bid' => $bid])
|
||||
return $this->createQueryBuilder('ht')
|
||||
->where('ht.id = :nodeId')
|
||||
->andWhere('ht.bid = :bid OR ht.bid IS NULL') // فقط کسبوکار فعلی یا عمومی
|
||||
->setParameter('nodeId', $nodeId)
|
||||
->setParameter('bid', $bid)
|
||||
->getQuery()
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue