add edit to sell list
This commit is contained in:
parent
1f40005683
commit
83aed97247
|
@ -2,17 +2,58 @@
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use App\Service\Log;
|
||||
use App\Service\Access;
|
||||
use App\Service\Explore;
|
||||
use App\Entity\HesabdariDoc;
|
||||
use App\Entity\StoreroomTicket;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
class SellController extends AbstractController
|
||||
{
|
||||
#[Route('/sell', name: 'app_sell')]
|
||||
public function index(): Response
|
||||
#[Route('/api/sell/edit/can/{code}', name: 'app_buy_can_edit')]
|
||||
public function app_buy_can_edit(Request $request,Access $access,Log $log,EntityManagerInterface $entityManager, string $code): JsonResponse
|
||||
{
|
||||
return $this->render('sell/index.html.twig', [
|
||||
'controller_name' => 'SellController',
|
||||
$canEdit = true;
|
||||
$acc = $access->hasRole('buy');
|
||||
if(!$acc)
|
||||
throw $this->createAccessDeniedException();
|
||||
|
||||
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
|
||||
'bid'=>$acc['bid'],
|
||||
'code'=>$code
|
||||
]);
|
||||
//check related documents
|
||||
if(count($doc->getRelatedDocs()) != 0)
|
||||
$canEdit = false;
|
||||
|
||||
//check storeroom tickets
|
||||
$tickets = $entityManager->getRepository(StoreroomTicket::class)->findBy(['doc'=>$doc]);
|
||||
if(count($tickets) != 0)
|
||||
$canEdit = false;
|
||||
return $this->json([
|
||||
'result'=> $canEdit
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/api/sell/get/info/{code}', name: 'app_buy_get_info')]
|
||||
public function app_buy_get_info(Request $request,Access $access,Log $log,EntityManagerInterface $entityManager, string $code): JsonResponse
|
||||
{
|
||||
$acc = $access->hasRole('buy');
|
||||
if(!$acc)
|
||||
throw $this->createAccessDeniedException();
|
||||
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
|
||||
'bid'=>$acc['bid'],
|
||||
'code'=>$code
|
||||
]);
|
||||
if(!$doc)
|
||||
throw $this->createNotFoundException();
|
||||
|
||||
return $this->json(Explore::ExploreSellDoc($doc));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,22 @@ use App\Entity\Salary;
|
|||
|
||||
class Explore{
|
||||
|
||||
public static function ExploreSellDoc(HesabdariDoc $hesabdariDoc){
|
||||
$result = self::ExploreHesabdariDoc($hesabdariDoc);
|
||||
$person = [];
|
||||
$commodities = [];
|
||||
foreach($hesabdariDoc->getHesabdariRows() as $item){
|
||||
if($item->getPerson()){
|
||||
$person = self::ExplorePerson($item->getPerson());
|
||||
}
|
||||
elseif($item->getCommodity()){
|
||||
$commodities[] = Explore::ExploreCommodity($item->getCommodity(),$item->getCommdityCount());
|
||||
}
|
||||
}
|
||||
$result['person'] = $person;
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function ExploreBuyDoc(HesabdariDoc $hesabdariDoc){
|
||||
$result = self::ExploreHesabdariDoc($hesabdariDoc);
|
||||
$person = [];
|
||||
|
|
Loading…
Reference in a new issue