almost finish fast sell

This commit is contained in:
babak alizadeh 2024-06-21 22:20:12 +03:30
parent 37b6fd077f
commit b8ea6f054e
11 changed files with 345 additions and 27 deletions

View file

@ -70,6 +70,10 @@ class CommodityController extends AbstractController
$temp['minOrderCount'] = $item->getMinOrderCount(); $temp['minOrderCount'] = $item->getMinOrderCount();
$temp['dayLoading'] = $item->getDayLoading(); $temp['dayLoading'] = $item->getDayLoading();
$temp['orderPoint'] = $item->getOrderPoint(); $temp['orderPoint'] = $item->getOrderPoint();
$temp['unitData'] = [
'name' => $item->getUnit()->getName(),
'floatNumber' => $item->getUnit()->getFloatNumber(),
];
//calculate count //calculate count
if ($item->isKhadamat()) { if ($item->isKhadamat()) {
$temp['count'] = 0; $temp['count'] = 0;

View file

@ -67,7 +67,13 @@ class GeneralController extends AbstractController
$print = $entityManager->getRepository(PrinterQueue::class)->findOneBy(['pid'=>$id]); $print = $entityManager->getRepository(PrinterQueue::class)->findOneBy(['pid'=>$id]);
if(!$print) if(!$print)
throw $this->createNotFoundException(); throw $this->createNotFoundException();
$pdfMGR->streamTwig2PDF($print); if($print->isPosprint()){
$pdfMGR->streamTwig2PDFInvoiceType($print);
}
else{
$pdfMGR->streamTwig2PDF($print);
}
return new Response(''); return new Response('');
} }
} }

View file

@ -106,7 +106,7 @@ class PersonsController extends AbstractController
if ($person) if ($person)
return $this->json(['result' => 2]); return $this->json(['result' => 2]);
$person = new Person(); $person = new Person();
$person->setCode($provider->getAccountingCode($request->headers->get('activeBid'), 'person')); $person->setCode($provider->getAccountingCode($acc['bid'], 'person'));
} else { } else {
$person = $entityManager->getRepository(Person::class)->findOneBy([ $person = $entityManager->getRepository(Person::class)->findOneBy([
'bid' => $acc['bid'], 'bid' => $acc['bid'],
@ -208,7 +208,7 @@ class PersonsController extends AbstractController
} }
} }
$entityManager->flush(); $entityManager->flush();
$log->insert('اشخاص', 'شخص با نام مستعار ' . $params['nikename'] . ' افزوده/ویرایش شد.', $this->getUser(), $request->headers->get('activeBid')); $log->insert('اشخاص', 'شخص با نام مستعار ' . $params['nikename'] . ' افزوده/ویرایش شد.', $this->getUser(), $acc['bid']);
return $this->json(['result' => 1]); return $this->json(['result' => 1]);
} }
@ -254,7 +254,8 @@ class PersonsController extends AbstractController
#[Route('/api/person/list/limit', name: 'app_persons_list_limit')] #[Route('/api/person/list/limit', name: 'app_persons_list_limit')]
public function app_persons_list_limit(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse public function app_persons_list_limit(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{ {
if (!$access->hasRole('person')) $acc = $access->hasRole('person');
if (!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$params = []; $params = [];
if ($content = $request->getContent()) { if ($content = $request->getContent()) {
@ -262,12 +263,12 @@ class PersonsController extends AbstractController
} }
if (array_key_exists('speedAccess', $params)) { if (array_key_exists('speedAccess', $params)) {
$persons = $entityManager->getRepository(Person::class)->findBy([ $persons = $entityManager->getRepository(Person::class)->findBy([
'bid' => $request->headers->get('activeBid'), 'bid' => $acc['bid'],
'speedAccess' => true 'speedAccess' => true
]); ]);
} else { } else {
$persons = $entityManager->getRepository(Person::class)->findBy([ $persons = $entityManager->getRepository(Person::class)->findBy([
'bid' => $request->headers->get('activeBid') 'bid' => $acc['bid']
]); ]);
} }
$response = []; $response = [];
@ -298,7 +299,8 @@ class PersonsController extends AbstractController
#[Route('/api/person/list', name: 'app_persons_list')] #[Route('/api/person/list', name: 'app_persons_list')]
public function app_persons_list(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): Response public function app_persons_list(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): Response
{ {
if (!$access->hasRole('person')) $acc = $access->hasRole('person');
if(!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$params = []; $params = [];
if ($content = $request->getContent()) { if ($content = $request->getContent()) {
@ -306,12 +308,12 @@ class PersonsController extends AbstractController
} }
if (array_key_exists('speedAccess', $params)) { if (array_key_exists('speedAccess', $params)) {
$persons = $entityManager->getRepository(Person::class)->findBy([ $persons = $entityManager->getRepository(Person::class)->findBy([
'bid' => $request->headers->get('activeBid'), 'bid' => $acc['bid'],
'speedAccess' => true 'speedAccess' => true
]); ]);
} else { } else {
$persons = $entityManager->getRepository(Person::class)->findBy([ $persons = $entityManager->getRepository(Person::class)->findBy([
'bid' => $request->headers->get('activeBid') 'bid' => $acc['bid']
]); ]);
} }
$response = Explore::ExplorePersons($persons, $entityManager->getRepository(PersonType::class)->findAll()); $response = Explore::ExplorePersons($persons, $entityManager->getRepository(PersonType::class)->findAll());
@ -335,7 +337,8 @@ class PersonsController extends AbstractController
#[Route('/api/person/list/debtors/{amount}', name: 'app_persons_list_debtors')] #[Route('/api/person/list/debtors/{amount}', name: 'app_persons_list_debtors')]
public function app_persons_list_debtors(string $amount, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse public function app_persons_list_debtors(string $amount, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{ {
if (!$access->hasRole('person')) $acc = $access->hasRole('person');
if (!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$params = []; $params = [];
if ($content = $request->getContent()) { if ($content = $request->getContent()) {
@ -343,12 +346,12 @@ class PersonsController extends AbstractController
} }
if (array_key_exists('speedAccess', $params)) { if (array_key_exists('speedAccess', $params)) {
$persons = $entityManager->getRepository(Person::class)->findBy([ $persons = $entityManager->getRepository(Person::class)->findBy([
'bid' => $request->headers->get('activeBid'), 'bid' => $acc['bid'],
'speedAccess' => true 'speedAccess' => true
]); ]);
} else { } else {
$persons = $entityManager->getRepository(Person::class)->findBy([ $persons = $entityManager->getRepository(Person::class)->findBy([
'bid' => $request->headers->get('activeBid') 'bid' => $acc['bid']
]); ]);
} }
@ -383,7 +386,7 @@ class PersonsController extends AbstractController
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$persons = $entityManager->getRepository(Person::class)->findBy([ $persons = $entityManager->getRepository(Person::class)->findBy([
'bid' => $request->headers->get('activeBid') 'bid' => $acc['bid']
]); ]);
$response = $provider->ArrayEntity2Array($persons, 0); $response = $provider->ArrayEntity2Array($persons, 0);
foreach ($persons as $key => $person) { foreach ($persons as $key => $person) {
@ -421,7 +424,8 @@ class PersonsController extends AbstractController
#[Route('/api/person/list/depositors/{amount}', name: 'app_persons_list_depoistors')] #[Route('/api/person/list/depositors/{amount}', name: 'app_persons_list_depoistors')]
public function app_persons_list_depoistors(string $amount, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse public function app_persons_list_depoistors(string $amount, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{ {
if (!$access->hasRole('person')) $acc = $access->hasRole('person');
if (!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$params = []; $params = [];
if ($content = $request->getContent()) { if ($content = $request->getContent()) {
@ -429,12 +433,12 @@ class PersonsController extends AbstractController
} }
if (array_key_exists('speedAccess', $params)) { if (array_key_exists('speedAccess', $params)) {
$persons = $entityManager->getRepository(Person::class)->findBy([ $persons = $entityManager->getRepository(Person::class)->findBy([
'bid' => $request->headers->get('activeBid'), 'bid' => $acc['bid'],
'speedAccess' => true 'speedAccess' => true
]); ]);
} else { } else {
$persons = $entityManager->getRepository(Person::class)->findBy([ $persons = $entityManager->getRepository(Person::class)->findBy([
'bid' => $request->headers->get('activeBid') 'bid' => $acc['bid']
]); ]);
} }
@ -470,7 +474,7 @@ class PersonsController extends AbstractController
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$persons = $entityManager->getRepository(Person::class)->findBy([ $persons = $entityManager->getRepository(Person::class)->findBy([
'bid' => $request->headers->get('activeBid') 'bid' => $acc['bid']
]); ]);
$response = $provider->ArrayEntity2Array($persons, 0); $response = $provider->ArrayEntity2Array($persons, 0);
foreach ($persons as $key => $person) { foreach ($persons as $key => $person) {
@ -940,7 +944,7 @@ class PersonsController extends AbstractController
//check exist before //check exist before
if (!$person) { if (!$person) {
$person = new Person(); $person = new Person();
$person->setCode($provider->getAccountingCode($request->headers->get('activeBid'), 'person')); $person->setCode($provider->getAccountingCode($acc['bid'], 'person'));
$person->setNikename($item[0]); $person->setNikename($item[0]);
$person->setBid($acc['bid']); $person->setBid($acc['bid']);
@ -984,7 +988,7 @@ class PersonsController extends AbstractController
} }
$entityManager->flush(); $entityManager->flush();
} }
$log->insert('اشخاص', 'تعداد ' . count($data) . ' شخص به صورت گروهی وارد شد.', $this->getUser(), $request->headers->get('activeBid')); $log->insert('اشخاص', 'تعداد ' . count($data) . ' شخص به صورت گروهی وارد شد.', $this->getUser(), $acc['bid']);
return $this->json(['result' => 1]); return $this->json(['result' => 1]);
} }

View file

@ -313,4 +313,35 @@ class SellController extends AbstractController
} }
return $this->json($dataTemp); return $this->json($dataTemp);
} }
#[Route('/api/sell/posprinter/invoice', name: 'app_sell_posprinter_invoice')]
public function app_sell_posprinter_invoice(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();
$posPrint = false;
if(array_key_exists('posprint',$params)) $posPrint = true;
$pid = $provider->createPrint(
$acc['bid'],
$this->getUser(),
$this->renderView('pdf/posPrinters/sell.html.twig', [
'bid' => $acc['bid'],
'doc'=>$doc,
'rows'=>$doc->getHesabdariRows()
]),
$posPrint
);
return $this->json(['id' => $pid]);
}
} }

View file

@ -30,6 +30,9 @@ class PrinterQueue
#[ORM\ManyToOne] #[ORM\ManyToOne]
private ?Business $bid = null; private ?Business $bid = null;
#[ORM\Column(nullable: true)]
private ?bool $posprint = null;
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;
@ -94,4 +97,16 @@ class PrinterQueue
return $this; return $this;
} }
public function isPosprint(): ?bool
{
return $this->posprint;
}
public function setPosprint(?bool $posprint): static
{
$this->posprint = $posprint;
return $this;
}
} }

View file

@ -1,8 +1,11 @@
<?php <?php
namespace App\Service; namespace App\Service;
use App\Entity\APIToken;
use App\Entity\Business; use App\Entity\Business;
use App\Entity\Permission; use App\Entity\Permission;
use App\Entity\UserToken;
use App\Entity\Year; use App\Entity\Year;
use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
@ -16,6 +19,9 @@ class Access
protected Request $request; protected Request $request;
protected RequestStack $requestStack; protected RequestStack $requestStack;
protected UserInterface | null $user; protected UserInterface | null $user;
protected Business | string $bid;
function __construct( function __construct(
EntityManagerInterface $entityManager, EntityManagerInterface $entityManager,
TokenStorageInterface $tokenStorage, TokenStorageInterface $tokenStorage,
@ -36,12 +42,33 @@ class Access
{ {
if(is_null($this->user)) if(is_null($this->user))
return false; return false;
$bid = $this->em->getRepository(Business::class)->find($this->request->headers->get('activeBid')); if ($this->request->headers->get('activeBid')) {
if(is_null($bid)) $bid = $this->em->getRepository(Business::class)->find($this->request->headers->get('activeBid'));
return false; if (is_null($bid)) {
$year = $this->em->getRepository(Year::class)->find($this->request->headers->get('activeYear')); return false;
if(is_null($year)) }
return false; }
elseif($this->request->headers->get('api-key')){
$token = $this->em->getRepository(APIToken::class)->findOneBy([
'token'=>$this->request->headers->get('api-key')
]);
if(!$token) { return false; }
$bid = $token->getBid();
}
if ($this->request->headers->get('activeYear')) {
$year = $this->em->getRepository(Year::class)->findOneBy([
'id' => $this->request->headers->get('activeYear'),
'bid'=>$bid
]);
if (!$year) { return false; }
}
elseif($this->request->headers->get('api-key')){
$year = $this->em->getRepository(Year::class)->findOneBy([
'head' => true,
'bid'=>$bid
]);
}
$accessArray = [ $accessArray = [
'bid'=>$bid, 'bid'=>$bid,
'user'=>$this->user, 'user'=>$this->user,

View file

@ -172,7 +172,11 @@ class Explore
'count' => $count, 'count' => $count,
'unit' => $item->getUnit()->getName(), 'unit' => $item->getUnit()->getName(),
'des' => $des, 'des' => $des,
'withoutTax' => $item->isWithoutTax() 'withoutTax' => $item->isWithoutTax(),
'unitData' => [
'name' => $item->getUnit()->getName(),
'floatNumber' => $item->getUnit()->getFloatNumber(),
]
]; ];
return null; return null;
} }

View file

@ -147,13 +147,14 @@ class Provider
return $result; return $result;
} }
public function createPrint(Business $bid, User $user, String $data) public function createPrint(Business $bid, User $user, String $data,$posPrint = false)
{ {
$print = new PrinterQueue(); $print = new PrinterQueue();
$print->setDateSubmit(time()); $print->setDateSubmit(time());
$print->setSubmitter($user); $print->setSubmitter($user);
$print->setBid($bid); $print->setBid($bid);
$print->setView($data); $print->setView($data);
$print->setPosprint($posPrint);
$print->setPid($this->RandomString(128)); $print->setPid($this->RandomString(128));
$this->entityManager->persist($print); $this->entityManager->persist($print);
$this->entityManager->flush(); $this->entityManager->flush();

View file

@ -46,6 +46,37 @@ class pdfMGR
$mpdf->Output(); $mpdf->Output();
} }
public function streamTwig2PDFInvoiceType(PrinterQueue $printQueue, $configs = [])
{
$mpdf = new \Mpdf\Mpdf([
'mode' => 'utf-8', 'format' => [80, 600],
'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',
'setAutoTopMargin' => true,
'autoArabic' => true,
'margin-collapse' => 'collapse|none'
]);
$mpdf->AddPageByArray([
'margin-left' => 0,
'margin-right' => 0,
'margin-top' => 0,
'margin-bottom' => 0,
]);
$mpdf->AddFontDirectory(__DIR__ . '../Fonts');
$mpdf->WriteHTML($printQueue->getView());
$mpdf->Output();
}
private function imageToBase64($path) { private function imageToBase64($path) {
$path = $path; $path = $path;
$type = pathinfo($path, PATHINFO_EXTENSION); $type = pathinfo($path, PATHINFO_EXTENSION);

View file

@ -0,0 +1,191 @@
<!DOCTYPE html>
<html lang="fa" direction="rtl">
<head>
<style>
body {
margin: 0;
padding: 0;
font-size: 100%;
}
table {
width: 100%;
}
tr {
width: 100%;
}
h1 {
text-align: center;
vertical-align: middle;
}
#logo {
width: 60%;
text-align: center;
-webkit-align-content: center;
align-content: center;
padding: 5px;
margin: 0 auto;
display: block;
}
header {
width: 100%;
text-align: center;
-webkit-align-content: center;
align-content: center;
vertical-align: middle;
}
.items thead {
text-align: center;
}
.center-align {
text-align: center;
}
.bill-details td {
font-size: 12px;
}
.receipt {
font-size: medium;
}
.items .heading {
font-size: 12.5px;
text-transform: uppercase;
border-top: 1px solid black;
margin-bottom: 4px;
border-bottom: 1px solid black;
vertical-align: middle;
}
.items thead tr th:first-child,
.items tbody tr td:first-child {
word-break: break-all;
text-align: center;
}
.items td {
font-size: 12px;
text-align: center;
vertical-align: bottom;
}
.price::after {
content: "";
text-align: right;
}
.sum-up {
text-align: right !important;
}
.total {
font-size: 13px;
border-top: 1px dashed black !important;
border-bottom: 1px dashed black !important;
}
.total.text,
.total.price {
text-align: right;
}
.total.price::after {
content: " ریال ";
}
.line {
border-top: 1px solid black !important;
}
p {
padding: 1px;
margin: 0;
}
section,
footer {
font-size: 12px;
}
tbody,
thead,
th,
td,
tr {
text-align: center;
}
</style>
</head>
<body style="direction:rtl; text-align:right; width:100%">
<header>
<p style="text-align:center;">{{ bid.name }}</p>
</header>
<table class="bill-details">
<tbody style="text-align:right">
<tr>
<td style="text-align:right">تاریخ :
<span>{{doc.date}}</span>
</td>
<td style="text-align:right">شماره :
<span>#
{{doc.code | number_format}}</span>
</td>
</tr>
<tr>
<td style="text-align:right"></td>
<td></td>
</tr>
<tr>
<th class="center-align" colspan="2">
<span class="receipt">صورتحساب</span>
</th>
</tr>
</tbody>
</table>
<table class="items">
<thead style="background:gray;text-color:white;">
<tr>
<th class="heading name">کالا</th>
<th class="heading qty">تعداد</th>
<th class="heading rate">فی</th>
<th class="heading amount">جمع</th>
</tr>
</thead>
<tbody>
{% for row in rows %}
{% if row.commodity != null %}
<tr>
<td>{{row.commodity.name}}</td>
<td>{{row.commdityCount}}</td>
<td class="price">{{(row.bs / row.commdityCount) | number_format}}</td>
<td class="price">{{row.bs | number_format}}</td>
</tr>
{% endif %}
{% endfor %}
<tr>
<th colspan="3" class="total text">جمع فاکتور</th>
<th class="total price">{{doc.amount | number_format}}</th>
</tr>
</tbody>
</table>
<section style="margin-bottom:10px;margin-top:10px;">
<p style="text-align:center">
از خرید شما متشکریم
</p>
</section>
<footer style="text-align:center">
<p>{{ bid.name }}</p>
<p>{{ bid.address }}</p>
<p>{{ bid.tel }}</p>
<p>hesabix.ir</p>
</footer>
</body>
</html>

View file

@ -171,6 +171,10 @@
</table> </table>
</div> </div>
<!-- END Table --> <!-- END Table -->
<div class="block block-rounded">
توضیحات:
{{ doc.des }}
</div>
<div class="block block-rounded"> <div class="block block-rounded">
<div class="block-header block-header-default"> <div class="block-header block-header-default">
<h3 class="block-title">سوابق پرداخت‌ها</h3> <h3 class="block-title">سوابق پرداخت‌ها</h3>