From 6e08797265fe82f846580d1537869f6f7893be77 Mon Sep 17 00:00:00 2001 From: babak alizadeh Date: Thu, 25 Jan 2024 10:00:35 +0000 Subject: [PATCH] add document type to history --- .../src/Controller/HesabdariController.php | 10 ++++-- hesabixCore/src/Controller/LogController.php | 31 +++++++++++++++++ hesabixCore/src/Entity/HesabdariDoc.php | 34 +++++++++++++++++++ hesabixCore/src/Entity/Log.php | 15 ++++++++ hesabixCore/src/Service/JsonResp.php | 30 ++++++++++++++++ hesabixCore/src/Service/Log.php | 5 ++- 6 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 hesabixCore/src/Service/JsonResp.php diff --git a/hesabixCore/src/Controller/HesabdariController.php b/hesabixCore/src/Controller/HesabdariController.php index 90bf61b..467a658 100644 --- a/hesabixCore/src/Controller/HesabdariController.php +++ b/hesabixCore/src/Controller/HesabdariController.php @@ -16,6 +16,7 @@ use App\Entity\Salary; use App\Entity\StoreroomTicket; use App\Service\Access; use App\Service\Jdate; +use App\Service\JsonResp; use App\Service\Log; use App\Service\Provider; use Doctrine\ORM\EntityManagerInterface; @@ -156,7 +157,7 @@ class HesabdariController extends AbstractController $rds[] = $temp; } return $this->json([ - 'doc'=>$doc, + 'doc'=>JsonResp::SerializeHesabdariDoc($doc), 'rows'=>$rows, 'relatedDocs'=>$rds ]); @@ -379,7 +380,12 @@ class HesabdariController extends AbstractController $doc->setAmount($amount); $entityManager->persist($doc); $entityManager->flush(); - $log->insert('حسابداری','سند حسابداری شماره ' . $doc->getCode() . ' ثبت / ویرایش شد.',$this->getUser(),$request->headers->get('activeBid')); + $log->insert( + 'حسابداری','سند حسابداری شماره ' . $doc->getCode() . ' ثبت / ویرایش شد.', + $this->getUser(), + $request->headers->get('activeBid'), + $doc + ); return $this->json([ 'result'=>1, diff --git a/hesabixCore/src/Controller/LogController.php b/hesabixCore/src/Controller/LogController.php index 5bb75fc..9b2386b 100644 --- a/hesabixCore/src/Controller/LogController.php +++ b/hesabixCore/src/Controller/LogController.php @@ -3,6 +3,8 @@ namespace App\Controller; use App\Entity\Business; +use App\Entity\HesabdariDoc; +use App\Entity\Log as EntityLog; use App\Service\Access; use App\Service\Jdate; use App\Service\Log; @@ -51,4 +53,33 @@ class LogController extends AbstractController } return $this->json(array_reverse($temps)); } + + #[Route('/api/business/logs/doc/{id}', name: 'api_business_doc_logs')] + public function api_business_doc_logs(Access $access,String $id, Jdate $jdate, EntityManagerInterface $entityManager,Log $log): JsonResponse + { + $acc = $access->hasRole('log'); + if(!$acc) + throw $this->createAccessDeniedException(); + $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy(['bid'=>$acc['bid'], 'code'=>$id]); + if(!$doc) + throw $this->createNotFoundException(); + if($doc->getBid()->getId() != $acc['bid']->getId()) + throw $this->createAccessDeniedException(); + + $logs = $entityManager->getRepository(\App\Entity\Log::class)->findBy(['bid'=>$acc['bid'],'doc'=>$doc],['id'=>'DESC']); + + $temps = []; + foreach ($logs as $log){ + $temp = []; + if($log->getUser()) + $temp['user'] = $log->getUser()->getFullName(); + else + $temp['user'] = ''; + $temp['des'] = $log->getDes(); + $temp['part'] = $log->getPart(); + $temp['date'] = $jdate->jdate('Y/n/d H:i',$log->getDateSubmit()); + $temps[] = $temp; + } + return $this->json($temps); + } } diff --git a/hesabixCore/src/Entity/HesabdariDoc.php b/hesabixCore/src/Entity/HesabdariDoc.php index 4eaa16b..ba6dbf7 100644 --- a/hesabixCore/src/Entity/HesabdariDoc.php +++ b/hesabixCore/src/Entity/HesabdariDoc.php @@ -92,12 +92,16 @@ class HesabdariDoc #[ORM\Column(type: Types::ARRAY, nullable: true)] private ?array $tempStatus = null; + #[ORM\OneToMany(mappedBy: 'doc', targetEntity: Log::class)] + private Collection $logs; + public function __construct() { $this->hesabdariRows = new ArrayCollection(); $this->plugNoghreOrders = new ArrayCollection(); $this->relatedDocs = new ArrayCollection(); $this->storeroomTickets = new ArrayCollection(); + $this->logs = new ArrayCollection(); } public function getId(): ?int @@ -422,4 +426,34 @@ class HesabdariDoc return $this; } + + /** + * @return Collection + */ + public function getLogs(): Collection + { + return $this->logs; + } + + public function addLog(Log $log): static + { + if (!$this->logs->contains($log)) { + $this->logs->add($log); + $log->setDoc($this); + } + + return $this; + } + + public function removeLog(Log $log): static + { + if ($this->logs->removeElement($log)) { + // set the owning side to null (unless already changed) + if ($log->getDoc() === $this) { + $log->setDoc(null); + } + } + + return $this; + } } diff --git a/hesabixCore/src/Entity/Log.php b/hesabixCore/src/Entity/Log.php index 7dd520d..343966b 100644 --- a/hesabixCore/src/Entity/Log.php +++ b/hesabixCore/src/Entity/Log.php @@ -31,6 +31,9 @@ class Log #[ORM\Column(length: 255, nullable: true)] private ?string $ipaddress = null; + #[ORM\ManyToOne(inversedBy: 'logs')] + private ?HesabdariDoc $doc = null; + public function getId(): ?int { return $this->id; @@ -107,4 +110,16 @@ class Log return $this; } + + public function getDoc(): ?HesabdariDoc + { + return $this->doc; + } + + public function setDoc(?HesabdariDoc $doc): static + { + $this->doc = $doc; + + return $this; + } } diff --git a/hesabixCore/src/Service/JsonResp.php b/hesabixCore/src/Service/JsonResp.php new file mode 100644 index 0000000..5c0a7a3 --- /dev/null +++ b/hesabixCore/src/Service/JsonResp.php @@ -0,0 +1,30 @@ + $hesabdariDoc->getId(), + 'dateSubmit' => $hesabdariDoc->getDateSubmit(), + 'date' => $hesabdariDoc->getDate(), + 'type' => $hesabdariDoc->getType(), + 'code' => $hesabdariDoc->getCode(), + 'des' => $hesabdariDoc->getDes(), + 'amount'=>$hesabdariDoc->getAmount(), + 'mdate' =>$hesabdariDoc->getMdate(), + 'plugin'=>$hesabdariDoc->getPlugin(), + 'refData'=>$hesabdariDoc->getRefData(), + 'shortLink'=>$hesabdariDoc->getShortlink(), + 'status' => $hesabdariDoc->getStatus(), + 'tempStatus' => $hesabdariDoc->getTempStatus(), + ]; + } +} \ No newline at end of file diff --git a/hesabixCore/src/Service/Log.php b/hesabixCore/src/Service/Log.php index 2631cfa..af235af 100644 --- a/hesabixCore/src/Service/Log.php +++ b/hesabixCore/src/Service/Log.php @@ -3,6 +3,8 @@ namespace App\Service; use App\Entity\Business; +use App\Entity\HesabdariDoc; +use App\Entity\User; use App\Module\RemoteAddress; use Doctrine\ORM\EntityManagerInterface; @@ -17,7 +19,7 @@ class Log $this->remoteAddress = new RemoteAddress(); } - public function insert($part,$des, $user = null, $bid = null): void + public function insert(string $part,string $des, User | null $user = null, Business | string | null $bid = null , HesabdariDoc | null $hesabdariDoc = null): void { if(is_string($bid)) $bid = $this->em->getRepository(Business::class)->find($bid); @@ -27,6 +29,7 @@ class Log $log->setDes($des); $log->setUser($user); $log->setBid($bid); + $log->setDoc($hesabdariDoc); $log->setIpaddress($this->remoteAddress->getIpAddress()); $this->em->persist($log); $this->em->flush();