add document type to history

This commit is contained in:
Hesabix 2024-01-25 10:00:35 +00:00
parent 69eb2ba402
commit 6e08797265
6 changed files with 122 additions and 3 deletions

View file

@ -16,6 +16,7 @@ use App\Entity\Salary;
use App\Entity\StoreroomTicket; use App\Entity\StoreroomTicket;
use App\Service\Access; use App\Service\Access;
use App\Service\Jdate; use App\Service\Jdate;
use App\Service\JsonResp;
use App\Service\Log; use App\Service\Log;
use App\Service\Provider; use App\Service\Provider;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
@ -156,7 +157,7 @@ class HesabdariController extends AbstractController
$rds[] = $temp; $rds[] = $temp;
} }
return $this->json([ return $this->json([
'doc'=>$doc, 'doc'=>JsonResp::SerializeHesabdariDoc($doc),
'rows'=>$rows, 'rows'=>$rows,
'relatedDocs'=>$rds 'relatedDocs'=>$rds
]); ]);
@ -379,7 +380,12 @@ class HesabdariController extends AbstractController
$doc->setAmount($amount); $doc->setAmount($amount);
$entityManager->persist($doc); $entityManager->persist($doc);
$entityManager->flush(); $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([ return $this->json([
'result'=>1, 'result'=>1,

View file

@ -3,6 +3,8 @@
namespace App\Controller; namespace App\Controller;
use App\Entity\Business; use App\Entity\Business;
use App\Entity\HesabdariDoc;
use App\Entity\Log as EntityLog;
use App\Service\Access; use App\Service\Access;
use App\Service\Jdate; use App\Service\Jdate;
use App\Service\Log; use App\Service\Log;
@ -51,4 +53,33 @@ class LogController extends AbstractController
} }
return $this->json(array_reverse($temps)); 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);
}
} }

View file

@ -92,12 +92,16 @@ class HesabdariDoc
#[ORM\Column(type: Types::ARRAY, nullable: true)] #[ORM\Column(type: Types::ARRAY, nullable: true)]
private ?array $tempStatus = null; private ?array $tempStatus = null;
#[ORM\OneToMany(mappedBy: 'doc', targetEntity: Log::class)]
private Collection $logs;
public function __construct() public function __construct()
{ {
$this->hesabdariRows = new ArrayCollection(); $this->hesabdariRows = new ArrayCollection();
$this->plugNoghreOrders = new ArrayCollection(); $this->plugNoghreOrders = new ArrayCollection();
$this->relatedDocs = new ArrayCollection(); $this->relatedDocs = new ArrayCollection();
$this->storeroomTickets = new ArrayCollection(); $this->storeroomTickets = new ArrayCollection();
$this->logs = new ArrayCollection();
} }
public function getId(): ?int public function getId(): ?int
@ -422,4 +426,34 @@ class HesabdariDoc
return $this; return $this;
} }
/**
* @return Collection<int, Log>
*/
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;
}
} }

View file

@ -31,6 +31,9 @@ class Log
#[ORM\Column(length: 255, nullable: true)] #[ORM\Column(length: 255, nullable: true)]
private ?string $ipaddress = null; private ?string $ipaddress = null;
#[ORM\ManyToOne(inversedBy: 'logs')]
private ?HesabdariDoc $doc = null;
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;
@ -107,4 +110,16 @@ class Log
return $this; return $this;
} }
public function getDoc(): ?HesabdariDoc
{
return $this->doc;
}
public function setDoc(?HesabdariDoc $doc): static
{
$this->doc = $doc;
return $this;
}
} }

View file

@ -0,0 +1,30 @@
<?php
namespace App\Service;
use App\Entity\Business;
use App\Entity\HesabdariDoc;
use App\Entity\Settings;
use App\Entity\User;
use Melipayamak\MelipayamakApi;
use Doctrine\ORM\EntityManagerInterface;
class JsonResp
{
// this function get Hesabdari Document in entity format and return back in array format
public static function SerializeHesabdariDoc(HesabdariDoc $hesabdariDoc) : array {
return [
'id' => $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(),
];
}
}

View file

@ -3,6 +3,8 @@
namespace App\Service; namespace App\Service;
use App\Entity\Business; use App\Entity\Business;
use App\Entity\HesabdariDoc;
use App\Entity\User;
use App\Module\RemoteAddress; use App\Module\RemoteAddress;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
@ -17,7 +19,7 @@ class Log
$this->remoteAddress = new RemoteAddress(); $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)) if(is_string($bid))
$bid = $this->em->getRepository(Business::class)->find($bid); $bid = $this->em->getRepository(Business::class)->find($bid);
@ -27,6 +29,7 @@ class Log
$log->setDes($des); $log->setDes($des);
$log->setUser($user); $log->setUser($user);
$log->setBid($bid); $log->setBid($bid);
$log->setDoc($hesabdariDoc);
$log->setIpaddress($this->remoteAddress->getIpAddress()); $log->setIpaddress($this->remoteAddress->getIpAddress());
$this->em->persist($log); $this->em->persist($log);
$this->em->flush(); $this->em->flush();