add sms to storeroom and view for user

This commit is contained in:
babak alizadeh 2024-10-15 13:12:39 +03:30
parent e3c24230f6
commit 419422f725
4 changed files with 303 additions and 37 deletions

View file

@ -6,6 +6,7 @@ use App\Entity\Business;
use App\Entity\HesabdariDoc;
use App\Entity\HesabdariRow;
use App\Entity\PrintOptions;
use App\Entity\StoreroomTicket;
use App\Service\Provider;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -14,8 +15,37 @@ use Symfony\Component\Routing\Annotation\Route;
class ShortlinksController extends AbstractController
{
#[Route('/st/{bid}/{id}', name: 'shortlinks_storeroom_show')]
public function shortlinks_storeroom_show(string $bid, string $id, EntityManagerInterface $entityManager): Response
{
$bus = $entityManager->getRepository(Business::class)->find($bid);
if (!$bus)
throw $this->createNotFoundException();
$ticket = $entityManager->getRepository(StoreroomTicket::class)->findOneBy([
'bid' => $bid,
'id' => $id
]);
if (!$ticket)
throw $this->createNotFoundException();
if(!$ticket->isCanShare())
throw $this->createAccessDeniedException();
$person = null;
foreach ($ticket->getDoc()->getHesabdariRows() as $item) {
if ($item->getPerson()) {
$person = $item->getPerson();
}
}
return $this->render('shortlinks/storeroom.html.twig', [
'bid' => $bus,
'doc' => $ticket,
'person'=>$person
]);
}
#[Route('/sl/{type}/{bid}/{link}/{msg}', name: 'shortlinks_show')]
public function shortlinks_show(string $bid, string $type, string $link, EntityManagerInterface $entityManager, String $msg = 'default'): Response
public function shortlinks_show(string $bid, string $type, string $link, EntityManagerInterface $entityManager, string $msg = 'default'): Response
{
$bus = $entityManager->getRepository(Business::class)->find($bid);
if (!$bus)
@ -31,12 +61,12 @@ class ShortlinksController extends AbstractController
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
'type' => 'sell',
'id' => $link,
'bid'=>$bus
'bid' => $bus
]);
if (!$doc)
throw $this->createNotFoundException();
}
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy(['doc' => $doc]);
$items = [];
$person = null;
@ -54,11 +84,11 @@ class ShortlinksController extends AbstractController
return $this->render('shortlinks/sell.html.twig', [
'bid' => $doc->getBid(),
'doc' => $doc,
'link'=>$link,
'link' => $link,
'rows' => $items,
'person'=> $person,
'totalPays'=>$totalPays,
'msg'=>$msg
'person' => $person,
'totalPays' => $totalPays,
'msg' => $msg
]);
}
@ -69,9 +99,11 @@ class ShortlinksController extends AbstractController
'type' => 'sell',
'id' => $link
]);
if (!$doc) throw $this->createNotFoundException();
if (!$doc)
throw $this->createNotFoundException();
$bid = $entityManager->getRepository(Business::class)->find($bid);
if (!$bid) throw $this->createNotFoundException();
if (!$bid)
throw $this->createNotFoundException();
$person = null;
$discount = 0;
$transfer = 0;
@ -86,15 +118,17 @@ class ShortlinksController extends AbstractController
}
$printOptions = [
'bidInfo' => true,
'pays' =>true,
'taxInfo' =>true,
'discountInfo' =>true,
'note' =>true,
'paper' =>'A4-L'
'pays' => true,
'taxInfo' => true,
'discountInfo' => true,
'note' => true,
'paper' => 'A4-L'
];
$note = '';
$printSettings = $entityManager->getRepository(PrintOptions::class)->findOneBy(['bid'=>$bid]);
if($printSettings){$note = $printSettings->getSellNoteString();}
$printSettings = $entityManager->getRepository(PrintOptions::class)->findOneBy(['bid' => $bid]);
if ($printSettings) {
$note = $printSettings->getSellNoteString();
}
$pdfPid = $provider->createPrint(
$bid,
$bid->getOwner(),
@ -105,12 +139,12 @@ class ShortlinksController extends AbstractController
'person' => $person,
'discount' => $discount,
'transfer' => $transfer,
'printOptions'=> $printOptions,
'note'=> $note
'printOptions' => $printOptions,
'note' => $note
]),
false,
$printOptions['paper']
);
return $this->redirectToRoute('app_front_print',['id'=>$pdfPid]);
return $this->redirectToRoute('app_front_print', ['id' => $pdfPid]);
}
}

View file

@ -14,6 +14,9 @@ use App\Entity\StoreroomTicket;
use App\Entity\StoreroomTransferType;
use App\Service\Access;
use App\Service\Log;
use App\Service\PluginService;
use App\Service\registryMGR;
use App\Service\SMS;
use Doctrine\ORM\EntityManagerInterface;
use ReflectionException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -25,7 +28,7 @@ use Symfony\Component\Routing\Annotation\Route;
class StoreroomController extends AbstractController
{
#[Route('/api/storeroom/list/{type}', name: 'app_storeroom_list')]
public function app_storeroom_list(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, String $type = 'active'): JsonResponse
public function app_storeroom_list(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, string $type = 'active'): JsonResponse
{
$acc = $access->hasRole('store');
if (!$acc)
@ -201,7 +204,7 @@ class StoreroomController extends AbstractController
]);
}
private function getPerson(HesabdariDoc $doc): Person | bool
private function getPerson(HesabdariDoc $doc): Person|bool
{
foreach ($doc->getHesabdariRows() as $row) {
if ($row->getPerson())
@ -226,7 +229,7 @@ class StoreroomController extends AbstractController
* @throws ReflectionException
*/
#[Route('/api/storeroom/doc/get/info/{id}', name: 'app_storeroom_get_doc_info')]
public function app_storeroom_get_doc_info(String $id, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
public function app_storeroom_get_doc_info(string $id, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{
$acc = $access->hasRole('store');
if (!$acc)
@ -322,7 +325,7 @@ class StoreroomController extends AbstractController
}
}
#[Route('/api/storeroom/transfertype/list', name: 'app_storeroom_get_transfertype_list')]
public function app_storeroom_get_transfertype_list(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
public function app_storeroom_get_transfertype_list(PluginService $pluginService, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{
$acc = $access->hasRole('store');
if (!$acc)
@ -331,7 +334,7 @@ class StoreroomController extends AbstractController
}
#[Route('/api/storeroom/ticket/insert', name: 'app_storeroom_ticket_insert')]
public function app_storeroom_ticket_insert(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
public function app_storeroom_ticket_insert(PluginService $pluginService,registryMGR $registryMGR, SMS $sms, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{
$acc = $access->hasRole('store');
if (!$acc)
@ -382,6 +385,7 @@ class StoreroomController extends AbstractController
$ticket->setBid($acc['bid']);
$ticket->setDateSubmit(time());
$ticket->setDoc($doc);
$ticket->setSenderTel($params['ticket']['senderTel']);
$ticket->setTransfer($params['ticket']['transfer']);
$ticket->setYear($acc['year']);
$ticket->setCode($provider->getAccountingCode($acc['bid'], 'storeroom'));
@ -427,13 +431,65 @@ class StoreroomController extends AbstractController
$entityManager->flush();
//save logs
$log->insert('انبارداری', 'حواله انبار با شماره ' . $ticket->getCode() . ' اضافه / ویرایش شد.', $this->getUser(), $acc['bid']);
if ($pluginService->isActive('accpro', $acc['bid'])) {
//notification to person
if ($params['ticket']['sms'] == true) {
$ticket->setCanShare(true);
$entityManager->persist($ticket);
$entityManager->flush();
if ($transferType->getName() == 'باربری') {
if($ticket->getTransfer() == null) $ticket->setTransfer(0);
if($ticket->getReferral() == null) $ticket->setReferral(0);
if($ticket->getSenderTel() == null) $ticket->setSenderTel(0);
$smsres = $sms->sendByBalance(
[
$person->getNikename(),
$ticket->getTransfer(),
$ticket->getReferral(),
$ticket->getSenderTel(),
$acc['bid']->getName(),
$acc['bid']->getId() . '/' . $ticket->getId()
],
$registryMGR->get('sms', 'plugAccproStoreroomSmsBarbari'),
$person->getMobile(),
$acc['bid'],
$this->getUser(),
3
);
} else {
$smsres = $sms->sendByBalance(
[
$person->getNikename(),
$ticket->getReferral(),
$transferType->getName(),
$acc['bid']->getName(),
$acc['bid']->getId() . '/' . $ticket->getId()
],
$registryMGR->get('sms', 'plugAccproStoreroomSmsOther'),
$person->getMobile(),
$acc['bid'],
$this->getUser(),
3
);
}
if ($smsres == 2) {
return $this->json([
'code' => 11,
'data' => '',
'message' => 'operation success but sms not send'
]);
}
}
}
return $this->json([
'result' => 0
]);
}
#[Route('/api/storeroom/tickets/list/{type}', name: 'app_storeroom_tickets_list')]
public function app_storeroom_tickets_list(String $type, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
public function app_storeroom_tickets_list(string $type, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{
$acc = $access->hasRole('store');
if (!$acc)
@ -442,8 +498,8 @@ class StoreroomController extends AbstractController
'bid' => $acc['bid'],
'year' => $acc['year'],
'type' => $type
],[
'date'=>'DESC'
], [
'date' => 'DESC'
]);
return $this->json($provider->ArrayEntity2ArrayJustIncludes($tickets, [
'getDes',
@ -457,7 +513,7 @@ class StoreroomController extends AbstractController
}
#[Route('/api/storeroom/tickets/info/{code}', name: 'app_storeroom_ticket_view')]
public function app_storeroom_ticket_view(String $code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
public function app_storeroom_ticket_view(string $code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{
$acc = $access->hasRole('store');
if (!$acc)
@ -476,14 +532,14 @@ class StoreroomController extends AbstractController
$res['person'] = $provider->Entity2ArrayJustIncludes($ticket->getPerson(), ['getKeshvar', 'getOstan', 'getShahr', 'getAddress', 'getNikename', 'getCodeeghtesadi', 'getPostalcode', 'getName', 'getTel', 'getSabt'], 0);
//get rows
$rows = $entityManager->getRepository(StoreroomItem::class)->findBy(['ticket' => $ticket]);
$res['commodities'] = $provider->ArrayEntity2ArrayJustIncludes($rows, ['getId', 'getDes', 'getCode', 'getName', 'getCommodity', 'getUnit', 'getCount','getReferal'], 2);
$res['commodities'] = $provider->ArrayEntity2ArrayJustIncludes($rows, ['getId', 'getDes', 'getCode', 'getName', 'getCommodity', 'getUnit', 'getCount', 'getReferal'], 2);
//calculate rows data
$this->calcStoreRemaining($res, $ticket->getDoc(), $entityManager);
return $this->json($res);
}
#[Route('/api/storeroom/commodity/list/{sid}', name: 'app_storeroom_commodity_list')]
public function app_storeroom_commodity_list(String $sid, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
public function app_storeroom_commodity_list(string $sid, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{
$acc = $access->hasRole('store');
if (!$acc)
@ -542,7 +598,7 @@ class StoreroomController extends AbstractController
return $items;
}
#[Route('/api/storeroom/ticket/remove/{id}', name: 'app_storeroom_ticket_remove')]
public function app_storeroom_ticket_remove(String $id, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
public function app_storeroom_ticket_remove(string $id, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{
$acc = $access->hasRole('store');
if (!$acc)
@ -574,17 +630,18 @@ class StoreroomController extends AbstractController
}
$acc = $access->hasRole('store');
if (!$acc) throw $this->createAccessDeniedException();
if (!$acc)
throw $this->createAccessDeniedException();
$doc = $entityManager->getRepository(StoreroomTicket::class)->findOneBy([
'bid' => $acc['bid'],
'code' => $params['code']
]);
if (!$doc) throw $this->createNotFoundException();
if($params['type'] == 'input'){
if (!$doc)
throw $this->createNotFoundException();
if ($params['type'] == 'input') {
$title = 'حواله ورود به انبار';
}
else{
} else {
$title = 'حواله خروج از انبار';
}
$pdfPid = 0;
@ -592,7 +649,7 @@ class StoreroomController extends AbstractController
$acc['bid'],
$this->getUser(),
$this->renderView('pdf/printers/storeroom/input.html.twig', [
'title'=> $title,
'title' => $title,
'bid' => $acc['bid'],
'doc' => $doc,
'rows' => $doc->getStoreroomItems(),

View file

@ -71,6 +71,12 @@ class StoreroomTicket
#[ORM\Column(length: 255, nullable: true)]
private ?string $des = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $senderTel = null;
#[ORM\Column(nullable: true)]
private ?bool $canShare = null;
public function __construct()
{
$this->storeroomItems = new ArrayCollection();
@ -302,4 +308,28 @@ class StoreroomTicket
return $this;
}
public function getSenderTel(): ?string
{
return $this->senderTel;
}
public function setSenderTel(?string $senderTel): static
{
$this->senderTel = $senderTel;
return $this;
}
public function isCanShare(): ?bool
{
return $this->canShare;
}
public function setCanShare(?bool $canShare): static
{
$this->canShare = $canShare;
return $this;
}
}

View file

@ -0,0 +1,145 @@
{% extends 'blank.html.twig' %}
{% block title %}مشاهده حواله خروج از انبار
{% endblock %}
{% block body %}
<main
id="main-container">
<!-- Hero -->
<div class="bg-body-light d-print-none">
<div class="content content-full">
<div class="d-flex flex-column flex-sm-row justify-content-sm-between align-items-sm-center">
<img src="/front/avatar/file/get/{{bid.id}}" class="img-fluid" width="80">
<h2 class="flex-grow-1 fs-3 fw-semibold my-2 my-sm-3 mx-2">
حوله خروج از انبار
</h2>
</div>
</div>
</div>
<!-- END Hero -->
<!-- Page Content -->
<div
class="content content-boxed">
<!-- Invoice -->
<div class="block block-rounded">
<div class="block-header block-header-default">
<h3 class="block-title">
شماره حواله انبار:
<span class="text-primary">
{{doc.code}}
</span>
</h3>
<div class="block-options"></div>
</div>
<div class="block-content">
<div
class="p-sm-2 p-xl-1">
<!-- Invoice Info -->
<div
class="row mb-5">
<!-- Company Info -->
<div class="col-6">
<p class="h3">
{{bid.type}}
:
{{bid.name}}
</p>
<address>آدرس :
استان
{{bid.ostan}}
شهرستان
{{bid.shahrestan}}
{{bid.address}}
</address>
<div>
کد پستی:
{{bid.postalcode}}
</div>
<div>
تلفن :
{{bid.tel}}
</div>
<div>
موبایل :
{{bid.mobile}}
</div>
</div>
<!-- END Company Info -->
<!-- Client Info -->
<div class="col-6 text-end">
<p class="h3">نحوه ارسال:
{{ doc.transferType.name }}
</p>
<div>کد پیگیری/شماره قبض :
{{doc.referral}}
</div>
<div>
واحد تحویل/باربری :
{{doc.transfer}}
</div>
<div>
تلفن تحویل دهنده :
{{doc.senderTel}}
</div>
<div>
تحویل گیرنده :
{{doc.receiver}}
</div>
</div>
<!-- END Client Info -->
</div>
<!-- END Invoice Info -->
<!-- Table -->
<div class="table-responsive push text-center">
<table class="table table-bordered">
<thead>
<tr class="bg-body">
<th class="text-dark">ردیف</th>
<th class="text-dark">کالا/خدمات</th>
<th class="text-dark">شرح</th>
<th class="text-dark">تعداد / مقدار</th>
</tr>
</thead>
<tbody>
{% for item in doc.storeroomItems%}
<tr>
<td>{{loop.index}}</td>
<td>
{{ item.commodity.code }}
-
{{ item.commodity.name }}</td>
<td>{{ item.des }}</td>
<td>
{{ item.count }}
{{ item.commodity.unit.name }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- END Table -->
<div class="block block-rounded">
توضیحات:
{{ doc.des }}
</div>
<!-- Footer -->
<a href="https://hesabix.ir" class="p-4 mb-3text-primary text-center my-5">
حسابیکس
<label class="text-muted">سامانه جامع مالی رایگان ، ابری و متن باز</label>
</a>
<!-- END Footer -->
</div>
</div>
</div>
<!-- END Invoice -->
</div>
<!-- END Page Content -->
</main>
{% endblock %}