diff --git a/hesabixCore/config/services.yaml b/hesabixCore/config/services.yaml index 922d3b4..375185b 100644 --- a/hesabixCore/config/services.yaml +++ b/hesabixCore/config/services.yaml @@ -7,6 +7,7 @@ parameters: blogMediaDir: '%kernel.project_dir%/../public_html/blog/media' archiveMediaDir: '%kernel.project_dir%/../hesabixArchive' archiveTempMediaDir: '%kernel.project_dir%/../hesabixArchive/temp' + avatarDir: '%kernel.project_dir%/../hesabixArchive/avatars' services: # default configuration for services in *this* file _defaults: diff --git a/hesabixCore/src/Controller/AvatarController.php b/hesabixCore/src/Controller/AvatarController.php index 14b326f..bbfd39b 100644 --- a/hesabixCore/src/Controller/AvatarController.php +++ b/hesabixCore/src/Controller/AvatarController.php @@ -3,12 +3,16 @@ namespace App\Controller; use App\Service\Access; +use App\Service\Log; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\BinaryFileResponse; +use Symfony\Component\HttpFoundation\File\Exception\FileException; use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\String\Slugger\SluggerInterface; class AvatarController extends AbstractController { @@ -34,11 +38,62 @@ class AvatarController extends AbstractController } #[Route('/api/avatar/post', name: 'api_avatar_post')] - public function api_avatar_post(Access $access,EntityManagerInterface $entityManagerInterface): Response + public function api_avatar_post(Log $log, SluggerInterface $slugger, Request $request, Access $access, EntityManagerInterface $entityManagerInterface): Response { $acc = $access->hasRole('owner'); if (!$acc) throw $this->createAccessDeniedException(); - var_dump($params); + + $uploadedFile = $request->files->get('bytes'); + if ($uploadedFile) { + $originalFilename = pathinfo($uploadedFile->getClientOriginalName(), PATHINFO_FILENAME); + // this is needed to safely include the file name as part of the URL + $safeFilename = $slugger->slug($originalFilename); + $newFilename = $safeFilename . '-' . uniqid() . '.' . $uploadedFile->guessExtension(); + $ext = $uploadedFile->getClientOriginalExtension(); + $extOK = false; + if ($ext == 'png' || $ext == 'jpg' || $ext == 'jpeg') { + $extOK = true; + } + else{ + return new Response('e'); + } + $sizeOK = false; + if ($uploadedFile->getSize() < 1000000) { + $sizeOK = true; + } + else{ + return new Response('s'); + } + $imgSizeOK = false; + $info = getimagesize($uploadedFile); + list($x, $y) = $info; + if ($x < 513 && $y < 513) { + $imgSizeOK = true; + } + else{ + return new Response('is'); + } + if ($extOK && $sizeOK && $imgSizeOK) { + // Move the file to the directory where brochures are stored + try { + $uploadedFile->move( + $this->getParameter('avatarDir'), + $newFilename + ); + } catch (FileException $e) { + // ... handle exception if something happens during file upload + return $this->json("error"); + } + $acc['bid']->setAvatar($newFilename); + $entityManagerInterface->persist($acc['bid']); + $entityManagerInterface->flush(); + //save log + $log->insert('تنظیمات پایه','نمایه کسب و کار تغییر یافت',$this->getUser(),$acc['bid']); + + return new Response($acc['bid']->getAvatar()); + } + } + if ($acc['bid']->getAvatar()) { return new Response($acc['bid']->getAvatar()); } diff --git a/hesabixCore/src/Controller/SellController.php b/hesabixCore/src/Controller/SellController.php index e9d0ddf..32169ff 100644 --- a/hesabixCore/src/Controller/SellController.php +++ b/hesabixCore/src/Controller/SellController.php @@ -377,4 +377,65 @@ class SellController extends AbstractController return $this->json(['id' => $pdfPid]); } + + #[Route('/api/sell/print/invoice', name: 'app_sell_print_invoice')] + public function app_sell_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('sell'); + 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->getBd(); + } elseif ($item->getRef()->getCode() == 61) { + $transfer = $item->getBs(); + } + } + $pdfPid = 0; + if ($params['pdf']) { + $pdfPid = $provider->createPrint( + $acc['bid'], + $this->getUser(), + $this->renderView('pdf/printers/sell.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/justSell.html.twig', [ + 'bid' => $acc['bid'], + 'doc' => $doc, + 'rows' => $doc->getHesabdariRows(), + ]), + false + ); + $printers->addFile($pid, $acc, "fastSellInvoice"); + } + return $this->json(['id' => $pdfPid]); + } } diff --git a/hesabixCore/src/Service/pdfMGR.php b/hesabixCore/src/Service/pdfMGR.php index 69ef005..99ae09f 100644 --- a/hesabixCore/src/Service/pdfMGR.php +++ b/hesabixCore/src/Service/pdfMGR.php @@ -20,28 +20,25 @@ class pdfMGR $defaultConfig = (new \Mpdf\Config\ConfigVariables())->getDefaults(); $fontDirs = $defaultConfig['fontDir']; - - $defaultFontConfig = (new \Mpdf\Config\FontVariables())->getDefaults(); - $fontData = $defaultFontConfig['fontdata']; $mpdf = new \Mpdf\Mpdf([ 'mode' => 'utf-8', 'format' => 'A4-L', 'fontDir' => array_merge($fontDirs, [ __DIR__ . '../Fonts', ]), - 'fontdata' => $fontData + [ // lowercase letters only in font key - 'Vazirmatn-Regular' => [ - 'R' => 'Vazirmatn-Regular.ttf', - 'I' => 'Vazirmatn-Regular.ttf', - ] - ], - 'default_font' => 'Vazirmatn-Regular', - 'tempDir' => sys_get_temp_dir().DIRECTORY_SEPARATOR.'mpdf' + 'fontdata' => [ + 'vazirmatn' => [ + 'R' => 'Vazir-Regular-FD.ttf', + 'I' => 'Vazir-Regular-FD.ttf', + 'useOTL' => 0xFF, + 'useKashida' => 75, + ] + ], + 'default_font' => 'vazirmatn', + 'tempDir' => sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mpdf', + 'autoArabic' => true, ]); + $mpdf->AddFontDirectory(__DIR__ . '../Fonts'); - $mpdf->setFooter('{PAGENO}'); - $stylesheet = file_get_contents(__DIR__ . '/../../../public_html/assets/css/dashmix.min.css'); - - $mpdf->WriteHTML($stylesheet,\Mpdf\HTMLParserMode::HEADER_CSS); $mpdf->WriteHTML($printQueue->getView()); $mpdf->Output(); } diff --git a/hesabixCore/templates/pdf/header.html.twig b/hesabixCore/templates/pdf/header.html.twig index e69de29..6a6dd10 100644 --- a/hesabixCore/templates/pdf/header.html.twig +++ b/hesabixCore/templates/pdf/header.html.twig @@ -0,0 +1 @@ +header \ No newline at end of file diff --git a/hesabixCore/templates/pdf/printers/sell.html.twig b/hesabixCore/templates/pdf/printers/sell.html.twig new file mode 100644 index 0000000..4172adf --- /dev/null +++ b/hesabixCore/templates/pdf/printers/sell.html.twig @@ -0,0 +1,270 @@ + + + +
+ + + +
+ |
+
+ صورتحساب فروش کالا و خدمات+ |
+
+ + تاریخ: + {{ doc.date }}++ + شماره: + {{ doc.code }}+ + |
+
+ + نام: + + {{ bid.legalName }} + + |
+
+ + شماره ثبت / شناسه ملی: + + {{ bid.shomaresabt }} + + |
+
+ + شماره اقتصادی: + + {{ bid.codeeghtesadi }} + + |
+
+ + تلفن / نمابر: + {{ bid.tel }} + + |
+
+ + کد پستی: + {{ bid.postalcode }} + + |
+
+ + آدرس: + + استان + {{ bid.ostan }}، شهر + {{ bid.shahrestan }}، + {{ bid.address }} + + |
+
+ + نام: + + {{ bid.legalName }} + + |
+
+ + شماره ثبت / شناسه ملی: + + {{ bid.shomaresabt }} + + |
+
+ + شماره اقتصادی: + + {{ bid.codeeghtesadi }} + + |
+
+ + تلفن / نمابر: + {{ bid.tel }} + + |
+
+ + کد پستی: + {{ bid.postalcode }} + + |
+
+ + آدرس: + + استان + {{ bid.ostan }}، شهر + {{ bid.shahrestan }}، + {{ bid.address }} + + |
+
ردیف | +کالا/خدمات | +شرح | +تعداد / مقدار | +مبلغ واحد | +تخفیف | +مالیات | +مبلغ کل | +
---|---|---|---|---|---|---|---|
{{rowIndex}} | ++ {{ item.commodity.code }} + - + {{ item.commodity.name }} | +{{ item.des }} | ++ {{ item.commdityCount | number_format }} + {{ item.commodity.unit.name }} + | +{{ ((item.bs - item.tax + item.discount) / item.commdityCount) | number_format }} | +{{ item.discount | number_format }} | +{{ item.tax | number_format}} | +{{ item.bs| number_format }} | +
+ + تخفیف: + {{discount | number_format}} ++ |
+
+ + مالیات: + {{taxAll | number_format}} ++ |
+
+ + حمل و نقل: + {{transfer | number_format}} ++ |
+
+ + جمع کل: + {{doc.amount | number_format}} ++ |
+
+ + توضیحات: + {{doc.des}} ++ |
+
+ + مهر و امضا خریدار ++ |
+
+ + مهر و امضا فروشنده: ++ |
+