diff --git a/hesabixCore/src/Controller/BuyController.php b/hesabixCore/src/Controller/BuyController.php index 7662a42..382fa09 100644 --- a/hesabixCore/src/Controller/BuyController.php +++ b/hesabixCore/src/Controller/BuyController.php @@ -4,19 +4,25 @@ namespace App\Controller; use App\Service\Log; use App\Service\Access; -use App\Service\JsonResp; +use App\Service\Explore; +use App\Entity\Commodity; +use App\Service\Provider; +use App\Service\Extractor; use App\Entity\HesabdariDoc; -use App\Entity\PersonType; +use App\Entity\HesabdariRow; +use App\Entity\HesabdariTable; +use App\Entity\InvoiceType; +use App\Entity\Person; use App\Entity\StoreroomTicket; -use App\Service\Explore as ServiceExplore; +use App\Service\Printers; use Doctrine\ORM\EntityManagerInterface; -use Explore; 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 BuyController extends AbstractController { #[Route('/api/buy/edit/can/{code}', name: 'app_buy_can_edit')] @@ -57,7 +63,7 @@ class BuyController extends AbstractController if(!$doc) throw $this->createNotFoundException(); - return $this->json(ServiceExplore::ExploreBuyDoc($doc)); + return $this->json(Explore::ExploreBuyDoc($doc)); } #[Route('/api/buy/get/invoices/list', name: 'app_buy_get_invoices_list')] @@ -71,6 +77,317 @@ class BuyController extends AbstractController 'year'=>$acc['year'], 'type'=>'buy' ]); - return $this->json(ServiceExplore::ExploreBuyDocsList($invoices)); + return $this->json(Explore::ExploreBuyDocsList($invoices)); + } + + #[Route('/api/buy/mod', name: 'app_buy_mod')] + public function app_buy_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('buy'); + 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) return $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('buy'); + $doc->setSubmitter($this->getUser()); + $doc->setMoney($acc['bid']->getMoney()); + $doc->setCode($provider->getAccountingCode($acc['bid'], 'accounting')); + } + if($params['transferCost'] != 0){ + $hesabdariRow = new HesabdariRow(); + $hesabdariRow->setDes('حمل و نقل کالا'); + $hesabdariRow->setBid($acc['bid']); + $hesabdariRow->setYear($acc['year']); + $hesabdariRow->setDoc($doc); + $hesabdariRow->setBd($params['transferCost']); + $hesabdariRow->setBs(0); + $ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy([ + 'code' => '90' // transfer cost income + ]); + $hesabdariRow->setRef($ref); + $entityManager->persist($hesabdariRow); + } + if($params['discountAll'] != 0){ + $hesabdariRow = new HesabdariRow(); + $hesabdariRow->setDes('تخفیف فاکتور'); + $hesabdariRow->setBid($acc['bid']); + $hesabdariRow->setYear($acc['year']); + $hesabdariRow->setDoc($doc); + $hesabdariRow->setBd(0); + $hesabdariRow->setBs($params['discountAll']); + $ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy([ + 'code' => '104' // سایر هزینه های پخش و خرید + ]); + $hesabdariRow->setRef($ref); + $entityManager->persist($hesabdariRow); + } + $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->setBd($row['sumWithoutTax'] + $row['tax']); + $hesabdariRow->setBs(0); + $hesabdariRow->setDiscount($row['discount']); + $hesabdariRow->setTax($row['tax']); + $ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy([ + 'code' => '120' // buy 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 - $params['discountAll'] + $params['transferCost']); + //set person seller + $hesabdariRow = new HesabdariRow(); + $hesabdariRow->setDes('فاکتور خرید'); + $hesabdariRow->setBid($acc['bid']); + $hesabdariRow->setYear($acc['year']); + $hesabdariRow->setDoc($doc); + $hesabdariRow->setBd(0); + $hesabdariRow->setBs($sumTax + $sumTotal + $params['transferCost'] - $params['discountAll']); + $ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy([ + 'code' => '3' // persons + ]); + $hesabdariRow->setRef($ref); + $person = $entityManager->getRepository(Person::class)->findOneBy([ + 'bid' => $acc['bid'], + 'code' => $params['seller']['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()); + } + + #[Route('/api/buy/label/change', name: 'app_buy_label_change')] + public function app_buy_label_change(Request $request, Access $access, Extractor $extractor, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + + $acc = $access->hasRole('buy'); + if (!$acc) + throw $this->createAccessDeniedException(); + if ($params['label'] != 'clear') { + $label = $entityManager->getRepository(InvoiceType::class)->findOneBy([ + 'code' => $params['label']['code'], + 'type' => 'buy' + ]); + if (!$label) return $this->json($extractor->notFound()); + } + foreach ($params['items'] as $item) { + $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ + 'bid' => $acc['bid'], + 'year' => $acc['year'], + 'code' => $item['code'] + ]); + if (!$doc) return $this->json($extractor->notFound()); + if ($params['label'] != 'clear') { + $doc->setInvoiceLabel($label); + $entityManager->persist($doc); + $log->insert( + 'حسابداری', + ' تغییر برچسب فاکتور شماره ' . $doc->getCode() . ' به ' . $label->getLabel(), + $this->getUser(), + $acc['bid']->getId(), + $doc + ); + } else { + $doc->setInvoiceLabel(null); + $entityManager->persist($doc); + $log->insert( + 'حسابداری', + ' حذف برچسب فاکتور شماره ' . $doc->getCode(), + $this->getUser(), + $acc['bid']->getId(), + $doc + ); + } + } + $entityManager->flush(); + return $this->json($extractor->operationSuccess()); + } + + #[Route('/api/buy/docs/search', name: 'app_buy_docs_search')] + public function app_buy_docs_search(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('buy'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + $data = $entityManager->getRepository(HesabdariDoc::class)->findBy([ + 'bid' => $acc['bid'], + 'year' => $acc['year'], + 'type' => 'buy' + ], [ + 'id' => 'DESC' + ]); + + $dataTemp = []; + foreach ($data as $item) { + $temp = [ + 'id' => $item->getId(), + 'dateSubmit' => $item->getDateSubmit(), + 'date' => $item->getDate(), + 'type' => $item->getType(), + 'code' => $item->getCode(), + 'des' => $item->getDes(), + 'amount' => $item->getAmount(), + 'submitter' => $item->getSubmitter()->getFullName(), + ]; + $mainRow = $entityManager->getRepository(HesabdariRow::class)->getNotEqual($item, 'person'); + $temp['person'] = ''; + if ($mainRow) + $temp['person'] = Explore::ExplorePerson($mainRow->getPerson()); + + $temp['label'] = null; + if ($item->getInvoiceLabel()) { + $temp['label'] = [ + 'code' => $item->getInvoiceLabel()->getCode(), + 'label' => $item->getInvoiceLabel()->getLabel() + ]; + } + + $temp['relatedDocsCount'] = count($item->getRelatedDocs()); + $pays = 0; + foreach ($item->getRelatedDocs() as $relatedDoc) { + $pays += $relatedDoc->getAmount(); + } + $temp['relatedDocsPays'] = $pays; + + foreach ($item->getHesabdariRows() as $item) { + if ($item->getRef()->getCode() == '104') { + $temp['discountAll'] = $item->getBd(); + } elseif ($item->getRef()->getCode() == '90') { + $temp['transferCost'] = $item->getBs(); + } + } + if(!array_key_exists('discountAll',$temp)) $temp['discountAll'] = 0; + if(!array_key_exists('transferCost',$temp)) $temp['transferCost'] = 0; + $dataTemp[] = $temp; + } + return $this->json($dataTemp); + } + + #[Route('/api/buy/print/invoice', name: 'app_buy_print_invoice')] + public function app_buy_print_invoice(Printers $printers, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + + $acc = $access->hasRole('buy'); + if (!$acc) throw $this->createAccessDeniedException(); + + $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ + 'bid' => $acc['bid'], + 'code' => $params['code'] + ]); + if (!$doc) throw $this->createNotFoundException(); + $person = null; + $discount = 0; + $transfer = 0; + foreach ($doc->getHesabdariRows() as $item) { + if ($item->getPerson()) { + $person = $item->getPerson(); + } elseif ($item->getRef()->getCode() == 104) { + $discount = $item->getBs(); + } elseif ($item->getRef()->getCode() == 90) { + $transfer = $item->getBd(); + } + } + $pdfPid = 0; + if ($params['pdf']) { + $pdfPid = $provider->createPrint( + $acc['bid'], + $this->getUser(), + $this->renderView('pdf/printers/buy.html.twig', [ + 'bid' => $acc['bid'], + 'doc' => $doc, + 'rows' => $doc->getHesabdariRows(), + 'person' => $person, + 'printInvoice' => $params['printers'], + 'discount' => $discount, + 'transfer' => $transfer + ]), + false + ); + } + if ($params['printers'] == true) { + $pid = $provider->createPrint( + $acc['bid'], + $this->getUser(), + $this->renderView('pdf/posPrinters/justBuy.html.twig', [ + 'bid' => $acc['bid'], + 'doc' => $doc, + 'rows' => $doc->getHesabdariRows(), + ]), + false + ); + $printers->addFile($pid, $acc, "fastBuyInvoice"); + } + return $this->json(['id' => $pdfPid]); } } diff --git a/hesabixCore/src/Controller/Plugins/PlugRepserviceController.php b/hesabixCore/src/Controller/Plugins/PlugRepserviceController.php index d8228c0..af73523 100644 --- a/hesabixCore/src/Controller/Plugins/PlugRepserviceController.php +++ b/hesabixCore/src/Controller/Plugins/PlugRepserviceController.php @@ -223,7 +223,7 @@ class PlugRepserviceController extends AbstractController $orders = $entityManagerInterface->getRepository(PlugRepserviceOrder::class)->findBy([ 'bid' => $acc['bid'] - ],['code'=>'DESC']); + ],['date'=>'DESC']); return $this->json($this->ExploreOrders($orders)); } diff --git a/hesabixCore/src/Service/Explore.php b/hesabixCore/src/Service/Explore.php index 1202a39..f5f6a4c 100644 --- a/hesabixCore/src/Service/Explore.php +++ b/hesabixCore/src/Service/Explore.php @@ -75,14 +75,18 @@ 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()); + } + elseif($item->getRef()->getCode() == '104'){ + $result['discountAll'] = $item->getBs(); + } elseif ($item->getRef()->getCode() == '90') { + $result['transferCost'] = $item->getBd(); } } + if (!array_key_exists('discountAll', $result)) $result['discountAll'] = 0; + if (!array_key_exists('transferCost', $result)) $result['transferCost'] = 0; $result['person'] = $person; return $result; } diff --git a/hesabixCore/templates/pdf/posPrinters/justBuy.html.twig b/hesabixCore/templates/pdf/posPrinters/justBuy.html.twig new file mode 100644 index 0000000..64b78f1 --- /dev/null +++ b/hesabixCore/templates/pdf/posPrinters/justBuy.html.twig @@ -0,0 +1,186 @@ + + + +
+ + + +{{ bid.name }}
+تاریخ : + {{doc.date}} + | +شماره : + # + {{doc.code | number_format}} + | +
+ رسید خرید + | +
---|
کالا | +تعداد | +فی | +جمع | +
---|---|---|---|
{{row.commodity.name}} | +{{row.commdityCount}} | +{{(row.bs / row.commdityCount) | number_format}} | +{{row.bs | number_format}} | +
جمع فاکتور | +{{doc.amount | number_format}} | +
+ |
+
+ فاکتور خرید کالا و خدمات+ |
+
+ + تاریخ: + {{ doc.date }}++ + شماره: + {{ doc.code }}+ + |
+
+ + نام: + + {{ bid.legalName }} + + |
+
+ + شماره ثبت / شناسه ملی: + + {{ bid.shomaresabt }} + + |
+
+ + شماره اقتصادی: + + {{ bid.codeeghtesadi }} + + |
+
+ + تلفن / نمابر: + {{ bid.tel }} + + |
+
+ + کد پستی: + {{ bid.postalcode }} + + |
+
+ + آدرس: + + استان + {{ bid.ostan }}، شهر + {{ bid.shahrestan }}، + {{ bid.address }} + + |
+
+ + نام: + + {{ person.nikename }} + + |
+
+ + شماره ثبت / شناسه ملی: + + {{ person.codeeghtesadi }} + + |
+
+ + شماره اقتصادی: + + {{ person.codeeghtesadi }} + + |
+
+ + تلفن / نمابر: + {{ person.tel }} + + |
+
+ + کد پستی: + {{ person.postalcode }} + + |
+
+ + آدرس: + + استان + {{ person.ostan }}، شهر + {{ person.shahr }}، + {{ person.address }} + + |
+
ردیف | +کالا/خدمات | +شرح | +تعداد / مقدار | +مبلغ واحد | +تخفیف | +مالیات | +مبلغ کل | +
---|---|---|---|---|---|---|---|
{{rowIndex}} | ++ {{ item.commodity.code }} + - + {{ item.commodity.name }} | +{{ item.des }} | ++ {{ item.commdityCount | number_format }} + {{ item.commodity.unit.name }} + | +{{ ((item.bd - item.tax + item.discount) / item.commdityCount) | number_format }} | +{{ item.discount | number_format }} | +{{ item.tax | number_format}} | +{{ item.bd| number_format }} | +
+ + تخفیف: + {{discount | number_format}} ++ |
+
+ + مالیات: + {{taxAll | number_format}} ++ |
+
+ + حمل و نقل: + {{transfer | number_format}} ++ |
+
+ + جمع کل: + {{doc.amount | number_format}} ++ |
+
+ + توضیحات: + {{doc.des}} ++ |
+
+ + مهر و امضا خریدار ++ |
+
+ + مهر و امضا فروشنده: ++ |
+