diff --git a/hesabixCore/config/services.yaml b/hesabixCore/config/services.yaml index 5e830b2..87bac68 100644 --- a/hesabixCore/config/services.yaml +++ b/hesabixCore/config/services.yaml @@ -26,6 +26,8 @@ services: # please note that last definitions always *replace* previous ones Jdate: class: App\Service\Jdate + Exctractor: + class: App\Service\Exctractor Log: class: App\Service\Log arguments: [ "@doctrine.orm.entity_manager" ] diff --git a/hesabixCore/src/Controller/BusinessController.php b/hesabixCore/src/Controller/BusinessController.php index 48c7f03..8d15c8b 100644 --- a/hesabixCore/src/Controller/BusinessController.php +++ b/hesabixCore/src/Controller/BusinessController.php @@ -614,8 +614,17 @@ class BusinessController extends AbstractController 'type' => 'buy', ]); $buysTotal = 0; - foreach ($buys as $item) - $buysTotal += $item->getAmount(); + foreach ($buys as $item) { + $canAdd = false; + foreach ($item->getHesabdariRows() as $row) { + if ($row->getCommodity()) + $canAdd = true; + } + if ($canAdd) { + $buysTotal += $item->getAmount(); + } + } + $sells = $entityManager->getRepository(HesabdariDoc::class)->findBy([ 'bid' => $buss, @@ -623,8 +632,16 @@ class BusinessController extends AbstractController 'type' => 'sell', ]); $sellsTotal = 0; - foreach ($sells as $item) - $sellsTotal += $item->getAmount(); + foreach ($sells as $item) { + $canAdd = false; + foreach ($item->getHesabdariRows() as $row) { + if ($row->getCommodity()) + $canAdd = true; + } + if ($canAdd) { + $sellsTotal += $item->getAmount(); + } + } $response = [ 'personCount' => count($persons), 'bankCount' => count($banks), diff --git a/hesabixCore/src/Controller/CommodityController.php b/hesabixCore/src/Controller/CommodityController.php index b335524..89af0e5 100644 --- a/hesabixCore/src/Controller/CommodityController.php +++ b/hesabixCore/src/Controller/CommodityController.php @@ -110,6 +110,10 @@ class CommodityController extends AbstractController $temp['id'] = $item->getId(); $temp['name'] = $item->getName(); $temp['unit'] = $item->getUnit()->getName(); + $temp['unitData'] = [ + 'name' => $item->getUnit()->getName(), + 'floatNumber' => $item->getUnit()->getFloatNumber(), + ]; $temp['des'] = $item->getDes(); $temp['priceBuy'] = $item->getPriceBuy(); $temp['speedAccess'] = $item->isSpeedAccess(); diff --git a/hesabixCore/src/Controller/SellController.php b/hesabixCore/src/Controller/SellController.php index 38f330b..7bb42f1 100644 --- a/hesabixCore/src/Controller/SellController.php +++ b/hesabixCore/src/Controller/SellController.php @@ -5,7 +5,13 @@ namespace App\Controller; use App\Service\Log; use App\Service\Access; use App\Service\Explore; +use App\Entity\Commodity; +use App\Service\Provider; +use App\Service\Extractor; use App\Entity\HesabdariDoc; +use App\Entity\HesabdariRow; +use App\Entity\HesabdariTable; +use App\Entity\Person; use App\Entity\StoreroomTicket; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\Request; @@ -17,43 +23,149 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class SellController extends AbstractController { #[Route('/api/sell/edit/can/{code}', name: 'app_sell_can_edit')] - public function app_sell_can_edit(Request $request,Access $access,Log $log,EntityManagerInterface $entityManager, string $code): JsonResponse + public function app_sell_can_edit(Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, string $code): JsonResponse { $canEdit = true; $acc = $access->hasRole('sell'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ - 'bid'=>$acc['bid'], - 'code'=>$code + 'bid' => $acc['bid'], + 'code' => $code ]); //check related documents - if(count($doc->getRelatedDocs()) != 0) + if (count($doc->getRelatedDocs()) != 0) $canEdit = false; //check storeroom tickets - $tickets = $entityManager->getRepository(StoreroomTicket::class)->findBy(['doc'=>$doc]); - if(count($tickets) != 0) + $tickets = $entityManager->getRepository(StoreroomTicket::class)->findBy(['doc' => $doc]); + if (count($tickets) != 0) $canEdit = false; return $this->json([ - 'result'=> $canEdit + 'result' => $canEdit ]); } #[Route('/api/sell/get/info/{code}', name: 'app_sell_get_info')] - public function app_sell_get_info(Request $request,Access $access,Log $log,EntityManagerInterface $entityManager, string $code): JsonResponse + public function app_sell_get_info(Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, string $code): JsonResponse { $acc = $access->hasRole('sell'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ - 'bid'=>$acc['bid'], - 'code'=>$code + 'bid' => $acc['bid'], + 'code' => $code ]); - if(!$doc) + if (!$doc) throw $this->createNotFoundException(); - + return $this->json(Explore::ExploreSellDoc($doc)); } + + #[Route('/api/sell/mod', name: 'app_sell_mod')] + public function app_sell_mod(Provider $provider, Extractor $extractor, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + + $acc = $access->hasRole('sell'); + if (!$acc) + throw $this->createAccessDeniedException(); + + if (!array_key_exists('update', $params)) { + return $this->json($extractor->paramsNotSend()); + } + if ($params['update'] != '') { + $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ + 'bid' => $acc['bid'], + 'year' => $acc['year'], + 'code' => $params['update'] + ]); + if (!$doc) $this->json($extractor->notFound()); + + $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ + 'doc' => $doc + ]); + foreach ($rows as $row) + $entityManager->remove($row); + } else { + $doc = new HesabdariDoc(); + $doc->setBid($acc['bid']); + $doc->setYear($acc['year']); + $doc->setDateSubmit(time()); + $doc->setType('sell'); + $doc->setSubmitter($this->getUser()); + $doc->setMoney($acc['bid']->getMoney()); + $doc->setCode($provider->getAccountingCode($acc['bid'], 'accounting')); + } + $doc->setDes($params['des']); + $doc->setDate($params['date']); + $sumTax = 0; + $sumTotal = 0; + foreach ($params['rows'] as $row) { + $sumTax += $row['tax']; + $sumTotal += $row['sumWithoutTax']; + $hesabdariRow = new HesabdariRow(); + $hesabdariRow->setDes($row['des']); + $hesabdariRow->setBid($acc['bid']); + $hesabdariRow->setYear($acc['year']); + $hesabdariRow->setDoc($doc); + $hesabdariRow->setBs($row['sumWithoutTax'] + $row['tax']); + $hesabdariRow->setBd(0); + $hesabdariRow->setDiscount($row['discount']); + $hesabdariRow->setTax($row['tax']); + $ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy([ + 'code' => '59' // sell commodity + ]); + $hesabdariRow->setRef($ref); + $row['count'] = str_replace(',', '', $row['count']); + $commodity = $entityManager->getRepository(Commodity::class)->findOneBy([ + 'id' => $row['commodity']['id'], + 'bid' => $acc['bid'] + ]); + if (!$commodity) + return $this->json($extractor->paramsNotSend()); + $hesabdariRow->setCommodity($commodity); + $hesabdariRow->setCommdityCount($row['count']); + $entityManager->persist($hesabdariRow); + } + //set amount of document + $doc->setAmount($sumTax + $sumTotal); + //set person buyer + $hesabdariRow = new HesabdariRow(); + $hesabdariRow->setDes('فاکتور فروش'); + $hesabdariRow->setBid($acc['bid']); + $hesabdariRow->setYear($acc['year']); + $hesabdariRow->setDoc($doc); + $hesabdariRow->setBs(0); + $hesabdariRow->setBd($sumTax + $sumTotal); + $ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy([ + 'code' => '3' // persons + ]); + $hesabdariRow->setRef($ref); + $person = $entityManager->getRepository(Person::class)->findOneBy([ + 'bid' => $acc['bid'], + 'code' => $params['buyer']['code'] + ]); + if (!$person) + return $this->json($extractor->paramsNotSend()); + $hesabdariRow->setPerson($person); + $entityManager->persist($hesabdariRow); + + //set tax info + + $entityManager->persist($doc); + $entityManager->flush(); + $log->insert( + 'حسابداری', + 'سند حسابداری شماره ' . $doc->getCode() . ' ثبت / ویرایش شد.', + $this->getUser(), + $request->headers->get('activeBid'), + $doc + ); + return $this->json($extractor->operationSuccess()); + } } diff --git a/hesabixCore/src/Entity/CommodityUnit.php b/hesabixCore/src/Entity/CommodityUnit.php index 1027641..f9220ba 100644 --- a/hesabixCore/src/Entity/CommodityUnit.php +++ b/hesabixCore/src/Entity/CommodityUnit.php @@ -23,6 +23,9 @@ class CommodityUnit #[Ignore] private $commodities; + #[ORM\Column(nullable: true)] + private ?int $floatNumber = null; + public function __construct() { $this->commodities = new ArrayCollection(); @@ -74,4 +77,16 @@ class CommodityUnit return $this; } + + public function getFloatNumber(): ?int + { + return $this->floatNumber; + } + + public function setFloatNumber(?int $floatNumber): static + { + $this->floatNumber = $floatNumber; + + return $this; + } } diff --git a/hesabixCore/src/Service/Explore.php b/hesabixCore/src/Service/Explore.php index 0c8404d..60e0641 100644 --- a/hesabixCore/src/Service/Explore.php +++ b/hesabixCore/src/Service/Explore.php @@ -39,15 +39,12 @@ class Explore { $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(), $item->getDes()); } } - $result['person'] = $person; + $result['person'] = $person; return $result; } @@ -141,7 +138,9 @@ class Explore 'des' => $row->getDes(), 'plugin' => $row->getPlugin(), 'commodity_count' => $row->getCommdityCount(), - 'commodity' => self::ExploreCommodity($row->getCommodity(), $row->getCommdityCount(), $row->getDes()) + 'commodity' => self::ExploreCommodity($row->getCommodity(), $row->getCommdityCount(), $row->getDes()), + 'tax' =>$row->getTax(), + 'discount' =>$row->getDiscount(), ]; } diff --git a/hesabixCore/src/Service/Extractor.php b/hesabixCore/src/Service/Extractor.php new file mode 100644 index 0000000..2a2ddf8 --- /dev/null +++ b/hesabixCore/src/Service/Extractor.php @@ -0,0 +1,44 @@ + 0, + 'data' =>$data, + 'message'=>'operation success' + ]; + } + public function notFound($data = ''){ + return [ + 'code' => 404, + 'data' =>$data, + 'message'=>'item not found' + ]; + } + + public function paramsNotSend(){ + return [ + 'code' => 101, + 'data' =>'', + 'message'=>'parameters not send currectly' + ]; + } +}