diff --git a/hesabixCore/src/Controller/ChequeController.php b/hesabixCore/src/Controller/ChequeController.php new file mode 100644 index 0000000..68460e0 --- /dev/null +++ b/hesabixCore/src/Controller/ChequeController.php @@ -0,0 +1,123 @@ +hasRole('cheque'); + if(!$acc) + throw $this->createAccessDeniedException(); + $chequesInput = $entityManager->getRepository(Cheque::class)->findBy([ + 'bid'=>$acc['bid'], + 'type'=>'input' + ]); + return $this->json([ + 'input'=>Explore::SerializeCheques(array_reverse($chequesInput)) + ]); + } + + #[Route('/api/cheque/pass/{id}', name: 'app_cheque_pass')] + public function app_cheque_pass(string $id,Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,Jdate $jdate): JsonResponse + { + $acc = $access->hasRole('cheque'); + if(!$acc) + throw $this->createAccessDeniedException(); + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + if(! array_key_exists('bank',$params) || ! array_key_exists('date',$params)) + $this->createNotFoundException(); + $cheque = $entityManager->getRepository(Cheque::class)->findOneBy([ + 'bid'=>$acc['bid'], + 'type'=>'input', + 'id' => $id + ]); + $bank = $entityManager->getRepository(BankAccount::class)->findOneBy([ + 'bid'=>$acc['bid'], + 'code' => $params['bank']['code'] + ]); + if(!$cheque || !$bank) + throw $this->createNotFoundException(); + if($cheque->isLocked()) + throw $this->createAccessDeniedException('cheque operation not permitted'); + + //edit cheque info + $cheque->setBank($bank); + $cheque->setStatus('پاس شده'); + $cheque->setDate($params['date']); + $cheque->setLocked(true); + $entityManager->persist($cheque); + + //create cheque document + $hesabdariDoc = new HesabdariDoc; + $hesabdariDoc->setBid($acc['bid']); + $hesabdariDoc->setSubmitter($this->getUser()); + $hesabdariDoc->setYear($acc['year']); + $hesabdariDoc->setMoney($acc['bid']->getMoney()); + $hesabdariDoc->setDateSubmit(time()); + $hesabdariDoc->setDate($params['date']); + $hesabdariDoc->setType('pass_cheque'); + $hesabdariDoc->setCode($provider->getAccountingCode($acc['bid'],'accounting')); + $hesabdariDoc->setDes($params['des']); + $hesabdariDoc->setAmount($cheque->getAmount()); + $entityManager->persist($hesabdariDoc); + + //cheate hesabdari rows + $hesabdariRow1 = new HesabdariRow(); + $hesabdariRow1->setDoc($hesabdariDoc); + $hesabdariRow1->setCheque($cheque); + $hesabdariRow1->setPerson($cheque->getPerson()); + $hesabdariRow1->setYear($acc['year']); + $hesabdariRow1->setBs($cheque->getAmount()); + $hesabdariRow1->setRef($entityManager->getRepository(HesabdariTable::class)->findOneBy(['code'=>3])); + $hesabdariRow1->setBd(0); + $hesabdariRow1->setBid($acc['bid']); + $hesabdariRow1->setDes('پاس شدن چک و انتقال به بانک'); + $entityManager->persist($hesabdariRow1); + + $hesabdariRow2 = new HesabdariRow(); + $hesabdariRow2->setDoc($hesabdariDoc); + $hesabdariRow2->setCheque($cheque); + $hesabdariRow2->setBank($bank); + $hesabdariRow2->setYear($acc['year']); + $hesabdariRow2->setBs(0); + $hesabdariRow2->setRef($entityManager->getRepository(HesabdariTable::class)->findOneBy(['code'=>5])); + $hesabdariRow2->setBd($cheque->getAmount()); + $hesabdariRow2->setBid($acc['bid']); + $hesabdariRow2->setDes('پاس شدن چک و انتقال به بانک'); + $entityManager->persist($hesabdariRow2); + $entityManager->flush(); + $log->insert( + 'حسابداری','ثبت چک پاس شده شماره ' . $cheque->getNumber() . ' و ثبت واریز به بانک ' . $bank->getName(), + $this->getUser(), + $acc['bid']->getId(), + $hesabdariDoc + ); + + return $this->json([ + 'result'=>'ok' + ]); + } +} diff --git a/hesabixCore/src/Controller/HesabdariController.php b/hesabixCore/src/Controller/HesabdariController.php index c47158b..b9b2883 100644 --- a/hesabixCore/src/Controller/HesabdariController.php +++ b/hesabixCore/src/Controller/HesabdariController.php @@ -4,6 +4,7 @@ namespace App\Controller; use App\Entity\BankAccount; use App\Entity\Cashdesk; +use App\Entity\Cheque; use App\Entity\Commodity; use App\Entity\HesabdariDoc; use App\Entity\HesabdariRow; @@ -20,6 +21,7 @@ use App\Service\Jdate; use App\Service\JsonResp; use App\Service\Log; use App\Service\Provider; +use DateTime; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; @@ -244,7 +246,7 @@ class HesabdariController extends AbstractController * @throws \ReflectionException */ #[Route('/api/accounting/insert', name: 'app_accounting_insert')] - public function app_accounting_insert(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse + public function app_accounting_insert(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,Jdate $jdate): JsonResponse { $params = []; if ($content = $request->getContent()) { @@ -328,6 +330,13 @@ class HesabdariController extends AbstractController $hesabdariRow->setDoc($doc); $hesabdariRow->setBs($row['bs']); $hesabdariRow->setBd($row['bd']); + $ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy([ + 'code'=>$row['table'] + ]); + $hesabdariRow->setRef($ref); + + $entityManager->persist($hesabdariRow); + if(array_key_exists('referral',$row)) $hesabdariRow->setReferral($row['referral']); $amount += $row['bs']; @@ -338,6 +347,37 @@ class HesabdariController extends AbstractController elseif ($person->getBid()->getId() != $acc['bid']->getId()) throw $this->createAccessDeniedException('person is not in this business'); $hesabdariRow->setPerson($person); } + if($row['type'] == 'cheque'){ + $person = $entityManager->getRepository(Person::class)->findOneBy([ + 'bid'=> $acc['bid'], + 'id'=>$row['person'] + ]); + $cheque = new Cheque(); + $cheque->setBid($acc['bid']); + $cheque->setSubmitter($this->getUser()); + $cheque->setPayDate($row['chequeDate']); + $cheque->setBankOncheque($row['chequeBank']); + $cheque->setRef($hesabdariRow->getRef()); + $cheque->setNumber($row['chequeNum']); + $cheque->setSayadNum($row['chequeSayadNum']); + $cheque->setDateSubmit(time()); + $cheque->setDes($row['des']); + $dateArray = explode('-',$row['chequeDate']); + $dateGre = strtotime($jdate->jalali_to_gregorian($dateArray['0'],$dateArray['1'],$dateArray['2'],'/')); + $cheque->setDateStamp($dateGre); + $cheque->setPerson($person); + $cheque->setRef($entityManager->getRepository(HesabdariTable::class)->findOneBy(['code'=>$row['table']])); + $cheque->setType($row['chequeType']); + if($cheque->getType() == 'input') + $cheque->setAmount($hesabdariRow->getBd()); + else + $cheque->setAmount($hesabdariRow->getBs()); + $cheque->setLocked(false); + $cheque->setStatus('پاس نشده'); + $entityManager->persist($cheque); + $entityManager->flush(); + $hesabdariRow->setCheque($cheque); + } elseif ($row['type'] == 'bank'){ $bank = $entityManager->getRepository(BankAccount::class)->find($row['id']); if(!$bank) throw $this->createNotFoundException('bank not found'); @@ -364,16 +404,13 @@ class HesabdariController extends AbstractController $hesabdariRow->setCommodity($commodity); $hesabdariRow->setCommdityCount($row['count']); } - $ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy([ - 'code'=>$row['table'] - ]); - + if(array_key_exists('plugin',$row)) $hesabdariRow->setPlugin($row['plugin']); if(array_key_exists('refData',$row)) $hesabdariRow->setRefData($row['refData']); - $hesabdariRow->setRef($ref); + $hesabdariRow->setDes($row['des']); $entityManager->persist($hesabdariRow); $entityManager->flush(); @@ -441,8 +478,22 @@ class HesabdariController extends AbstractController $tickets = $entityManager->getRepository(StoreroomTicket::class)->findBy(['doc'=>$doc]); foreach ($tickets as $ticket) $entityManager->remove($ticket); - foreach ($rows as $row) + //remove rows and check sub systems + foreach ($rows as $row){ + if($row->getCheque()){ + if($row->getCheque()->isLocked()){ + //doc has transaction + return $this->json([ + 'result'=>2, + 'message'=>'سند به دلیل داشتن تراکنش مرتبط با چک بانکی قابل حذف نیست.' + ]); + } + $log->insert('بانکداری','چک شماره شماره ' . $row->getCheque()->getNumber() . ' حذف شد.',$this->getUser(),$request->headers->get('activeBid')); + $entityManager->remove($row->getCheque()); + } $entityManager->remove($row); + } + foreach ($doc->getRelatedDocs() as $relatedDoc){ if($relatedDoc->getType() != 'walletPay'){ $items = $entityManager->getRepository(HesabdariRow::class)->findBy(['doc'=>$relatedDoc]); diff --git a/hesabixCore/src/Entity/BankAccount.php b/hesabixCore/src/Entity/BankAccount.php index 9ac0476..6f4c21e 100644 --- a/hesabixCore/src/Entity/BankAccount.php +++ b/hesabixCore/src/Entity/BankAccount.php @@ -58,9 +58,13 @@ class BankAccount #[ORM\Column(length: 255, nullable: true)] private ?string $balance = null; + #[ORM\OneToMany(mappedBy: 'bank', targetEntity: Cheque::class)] + private Collection $cheques; + public function __construct() { $this->hesabdariRows = new ArrayCollection(); + $this->cheques = new ArrayCollection(); } public function getId(): ?int @@ -241,4 +245,34 @@ class BankAccount return $this; } + + /** + * @return Collection + */ + public function getCheques(): Collection + { + return $this->cheques; + } + + public function addCheque(Cheque $cheque): static + { + if (!$this->cheques->contains($cheque)) { + $this->cheques->add($cheque); + $cheque->setBank($this); + } + + return $this; + } + + public function removeCheque(Cheque $cheque): static + { + if ($this->cheques->removeElement($cheque)) { + // set the owning side to null (unless already changed) + if ($cheque->getBank() === $this) { + $cheque->setBank(null); + } + } + + return $this; + } } diff --git a/hesabixCore/src/Entity/Business.php b/hesabixCore/src/Entity/Business.php index 0f048b8..04b64e7 100644 --- a/hesabixCore/src/Entity/Business.php +++ b/hesabixCore/src/Entity/Business.php @@ -202,6 +202,9 @@ class Business #[ORM\OneToMany(mappedBy: 'bid', targetEntity: Hook::class, orphanRemoval: true)] private Collection $hooks; + #[ORM\OneToMany(mappedBy: 'bid', targetEntity: Cheque::class, orphanRemoval: true)] + private Collection $cheques; + public function __construct() { $this->logs = new ArrayCollection(); @@ -227,6 +230,7 @@ class Business $this->archiveOrders = new ArrayCollection(); $this->shareholders = new ArrayCollection(); $this->hooks = new ArrayCollection(); + $this->cheques = new ArrayCollection(); } public function getId(): ?int @@ -1355,4 +1359,34 @@ class Business return $this; } + + /** + * @return Collection + */ + public function getCheques(): Collection + { + return $this->cheques; + } + + public function addCheque(Cheque $cheque): static + { + if (!$this->cheques->contains($cheque)) { + $this->cheques->add($cheque); + $cheque->setBid($this); + } + + return $this; + } + + public function removeCheque(Cheque $cheque): static + { + if ($this->cheques->removeElement($cheque)) { + // set the owning side to null (unless already changed) + if ($cheque->getBid() === $this) { + $cheque->setBid(null); + } + } + + return $this; + } } diff --git a/hesabixCore/src/Entity/Cheque.php b/hesabixCore/src/Entity/Cheque.php new file mode 100644 index 0000000..29ca7a5 --- /dev/null +++ b/hesabixCore/src/Entity/Cheque.php @@ -0,0 +1,318 @@ +hesabdariRows = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getBid(): ?Business + { + return $this->bid; + } + + public function setBid(?Business $bid): static + { + $this->bid = $bid; + + return $this; + } + + public function getSubmitter(): ?User + { + return $this->submitter; + } + + public function setSubmitter(?User $submitter): static + { + $this->submitter = $submitter; + + return $this; + } + + public function getDateSubmit(): ?string + { + return $this->dateSubmit; + } + + public function setDateSubmit(string $dateSubmit): static + { + $this->dateSubmit = $dateSubmit; + + return $this; + } + + public function getType(): ?string + { + return $this->type; + } + + public function setType(string $type): static + { + $this->type = $type; + + return $this; + } + + public function getBank(): ?BankAccount + { + return $this->bank; + } + + public function setBank(?BankAccount $bank): static + { + $this->bank = $bank; + + return $this; + } + + public function getPerson(): ?Person + { + return $this->person; + } + + public function setPerson(?Person $person): static + { + $this->person = $person; + + return $this; + } + + public function getSayadNum(): ?string + { + return $this->sayadNum; + } + + public function setSayadNum(?string $sayadNum): static + { + $this->sayadNum = $sayadNum; + + return $this; + } + + public function getDes(): ?string + { + return $this->des; + } + + public function setDes(?string $des): static + { + $this->des = $des; + + return $this; + } + + public function getDateStamp(): ?string + { + return $this->dateStamp; + } + + public function setDateStamp(string $dateStamp): static + { + $this->dateStamp = $dateStamp; + + return $this; + } + + public function getPayDate(): ?string + { + return $this->payDate; + } + + public function setPayDate(?string $payDate): static + { + $this->payDate = $payDate; + + return $this; + } + + public function getRef(): ?HesabdariTable + { + return $this->ref; + } + + public function setRef(?HesabdariTable $ref): static + { + $this->ref = $ref; + + return $this; + } + + public function getNumber(): ?string + { + return $this->number; + } + + public function setNumber(string $number): static + { + $this->number = $number; + + return $this; + } + + /** + * @return Collection + */ + public function getHesabdariRows(): Collection + { + return $this->hesabdariRows; + } + + public function addHesabdariRow(HesabdariRow $hesabdariRow): static + { + if (!$this->hesabdariRows->contains($hesabdariRow)) { + $this->hesabdariRows->add($hesabdariRow); + $hesabdariRow->setCheque($this); + } + + return $this; + } + + public function removeHesabdariRow(HesabdariRow $hesabdariRow): static + { + if ($this->hesabdariRows->removeElement($hesabdariRow)) { + // set the owning side to null (unless already changed) + if ($hesabdariRow->getCheque() === $this) { + $hesabdariRow->setCheque(null); + } + } + + return $this; + } + + public function getBankOncheque(): ?string + { + return $this->bankOncheque; + } + + public function setBankOncheque(string $bankOncheque): static + { + $this->bankOncheque = $bankOncheque; + + return $this; + } + + public function getAmount(): ?string + { + return $this->amount; + } + + public function setAmount(string $amount): static + { + $this->amount = $amount; + + return $this; + } + + public function getStatus(): ?string + { + return $this->status; + } + + public function setStatus(?string $status): static + { + $this->status = $status; + + return $this; + } + + public function isLocked(): ?bool + { + return $this->locked; + } + + public function setLocked(?bool $locked): static + { + $this->locked = $locked; + + return $this; + } + + public function getDate(): ?string + { + return $this->date; + } + + public function setDate(?string $date): static + { + $this->date = $date; + + return $this; + } + +} diff --git a/hesabixCore/src/Entity/HesabdariRow.php b/hesabixCore/src/Entity/HesabdariRow.php index c2b07a4..64abfec 100644 --- a/hesabixCore/src/Entity/HesabdariRow.php +++ b/hesabixCore/src/Entity/HesabdariRow.php @@ -82,10 +82,15 @@ class HesabdariRow #[ORM\Column(type: Types::ARRAY, nullable: true)] private ?array $tempData = null; + #[ORM\ManyToOne(inversedBy: 'hesabdariRows')] + private ?Cheque $cheque = null; + + + public function __construct() { - + } public function getId(): ?int @@ -296,4 +301,16 @@ class HesabdariRow return $this; } + + public function getCheque(): ?Cheque + { + return $this->cheque; + } + + public function setCheque(?Cheque $cheque): static + { + $this->cheque = $cheque; + + return $this; + } } diff --git a/hesabixCore/src/Entity/Person.php b/hesabixCore/src/Entity/Person.php index 3608707..4615e77 100644 --- a/hesabixCore/src/Entity/Person.php +++ b/hesabixCore/src/Entity/Person.php @@ -116,6 +116,9 @@ class Person #[ORM\Column(nullable: true)] private ?bool $speedAccess = null; + #[ORM\OneToMany(mappedBy: 'person', targetEntity: Cheque::class)] + private Collection $cheques; + public function __construct() { $this->hesabdariRows = new ArrayCollection(); @@ -123,6 +126,7 @@ class Person $this->ordersFromCustomer = new ArrayCollection(); $this->storeroomTickets = new ArrayCollection(); $this->shareholders = new ArrayCollection(); + $this->cheques = new ArrayCollection(); } public function getId(): ?int @@ -591,4 +595,34 @@ class Person return $this; } + + /** + * @return Collection + */ + public function getCheques(): Collection + { + return $this->cheques; + } + + public function addCheque(Cheque $cheque): static + { + if (!$this->cheques->contains($cheque)) { + $this->cheques->add($cheque); + $cheque->setPerson($this); + } + + return $this; + } + + public function removeCheque(Cheque $cheque): static + { + if ($this->cheques->removeElement($cheque)) { + // set the owning side to null (unless already changed) + if ($cheque->getPerson() === $this) { + $cheque->setPerson(null); + } + } + + return $this; + } } diff --git a/hesabixCore/src/Entity/User.php b/hesabixCore/src/Entity/User.php index d37fad0..9e924bb 100644 --- a/hesabixCore/src/Entity/User.php +++ b/hesabixCore/src/Entity/User.php @@ -101,6 +101,9 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\OneToMany(mappedBy: 'submitter', targetEntity: Hook::class, orphanRemoval: true)] private Collection $hooks; + #[ORM\OneToMany(mappedBy: 'submitter', targetEntity: Cheque::class, orphanRemoval: true)] + private Collection $cheques; + public function __construct() { $this->userTokens = new ArrayCollection(); @@ -121,6 +124,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface $this->archiveFiles = new ArrayCollection(); $this->archiveOrders = new ArrayCollection(); $this->hooks = new ArrayCollection(); + $this->cheques = new ArrayCollection(); } public function getId(): ?int @@ -804,4 +808,34 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } + + /** + * @return Collection + */ + public function getCheques(): Collection + { + return $this->cheques; + } + + public function addCheque(Cheque $cheque): static + { + if (!$this->cheques->contains($cheque)) { + $this->cheques->add($cheque); + $cheque->setSubmitter($this); + } + + return $this; + } + + public function removeCheque(Cheque $cheque): static + { + if ($this->cheques->removeElement($cheque)) { + // set the owning side to null (unless already changed) + if ($cheque->getSubmitter() === $this) { + $cheque->setSubmitter(null); + } + } + + return $this; + } } diff --git a/hesabixCore/src/Repository/ChequeRepository.php b/hesabixCore/src/Repository/ChequeRepository.php new file mode 100644 index 0000000..51f4a25 --- /dev/null +++ b/hesabixCore/src/Repository/ChequeRepository.php @@ -0,0 +1,40 @@ + + * + * @method Cheque|null find($id, $lockMode = null, $lockVersion = null) + * @method Cheque|null findOneBy(array $criteria, array $orderBy = null) + * @method Cheque[] findAll() + * @method Cheque[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class ChequeRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Cheque::class); + } + +// /** +// * @return Cheque[] Returns an array of Cheque objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('c') +// ->andWhere('c.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('c.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +} diff --git a/hesabixCore/src/Service/Explore.php b/hesabixCore/src/Service/Explore.php index 16744a5..357adf5 100644 --- a/hesabixCore/src/Service/Explore.php +++ b/hesabixCore/src/Service/Explore.php @@ -6,6 +6,7 @@ use App\Entity\User; use App\Entity\Year; use App\Entity\Business; use App\Entity\Cashdesk; +use App\Entity\Cheque; use App\Entity\Commodity; use App\Entity\HesabdariDoc; use App\Entity\HesabdariRow; @@ -205,4 +206,33 @@ class Explore{ return $result; } + public static function SerializeCheque(Cheque | null $cheque){ + if(!$cheque) + return null; + $jdate = new Jdate; + return [ + 'id' => $cheque->getId(), + 'number'=> $cheque->getNumber(), + 'sayadNum'=>$cheque->getSayadNum(), + 'chequeBank'=>$cheque->getBankOncheque(), + 'person'=>self::ExplorePerson($cheque->getPerson()), + 'bank'=>self::ExploreBank($cheque->getBank()), + 'des'=>$cheque->getDes(), + 'datePay'=>$cheque->getPayDate(), + 'type'=>$cheque->getType(), + 'amount'=>$cheque->getAmount(), + 'status'=>$cheque->getStatus(), + 'date'=>$cheque->getDate(), + 'locked'=>$cheque->isLocked() + + ]; + } + + public static function SerializeCheques(array $cheques){ + $result = []; + foreach($cheques as $cheque) + $result[] = self::SerializeCheque($cheque); + return $result; + } + } \ No newline at end of file