almost finish sell invoice and pdf invoice

This commit is contained in:
babak alizadeh 2024-07-07 00:11:55 +03:30
parent 4f6fedf477
commit 1b75e02ddc
8 changed files with 6895 additions and 37 deletions

View file

@ -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:

View file

@ -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());
}

View file

@ -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]);
}
}

View file

@ -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();
}

View file

@ -0,0 +1 @@
header

View file

@ -0,0 +1,270 @@
<!DOCTYPE html>
<html lang="fa" direction="rtl"></html>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<head>
<style>
@page {
margin: 3%;
margin-header: 0;
margin-footer: 0;
}
.center {
text-align: center;
}
.text-white {
color: white;
}
.stimol td,
.stimol th {
border: 1px solid black;
}
.item {
height: 40px;
}
</style>
</head>
<body style="direction:rtl; width:100%">
<div class="block-content pt-1 pb-3 d-none d-sm-block">
<div class="c-print container-xl">
<div class="tg-wrap" style="width:100%; border:1px solid black;border-radius: 8px;">
<table class="rounded" style="width:100%;">
<thead>
<tr>
<td style="width:20%">
<img src="{{ "/api/avatar/get/file/" ~ bid.avatar}}" width="65"/>
</td>
<td style="width:60%; text-align:center">
<h3 class="">صورتحساب فروش کالا و خدمات</h3>
</td>
<td style="width:20%">
<h4>
<b>تاریخ:</b>
{{ doc.date }}</h4>
<br/>
<h4>
<b>شماره:</b>
{{ doc.code }}</h4>
</td>
</tr>
</thead>
</table>
</div>
<div style="width:100%; border:1px solid black;border-radius: 8px;margin-top:5px;text-align:center;">
<div class="tg-wrap" style="width:100%;border-radius: 8px 8px 0px 0px;text-align:center;background-color:gray">
<b style="color:white;">فروشنده</b>
</div>
<table style="width:100%;">
<tbody>
<tr style="text-align:center;">
<td class="">
<p>
<b>نام:
</b>
{{ bid.legalName }}
</p>
</td>
<td class="center">
<p>
<b>شماره ثبت / شناسه ملی:
</b>
{{ bid.shomaresabt }}
</p>
</td>
<td class="center">
<p>
<b>شماره اقتصادی:
</b>
{{ bid.codeeghtesadi }}
</p>
</td>
<td class="center">
<p>
<b>تلفن / نمابر:</b>
{{ bid.tel }}
</p>
</td>
</tr>
<tr>
<td class="" colspan="1">
<p>
<b>کد پستی:</b>
{{ bid.postalcode }}
</p>
</td>
<td class="" colspan="3">
<p>
<b>آدرس:
</b>
استان
{{ bid.ostan }}، شهر
{{ bid.shahrestan }}،
{{ bid.address }}
</p>
</td>
</tr>
</tbody>
</table>
</div>
<div style="width:100%; border:1px solid black;border-radius: 8px;margin-top:5px;text-align:center;">
<div class="tg-wrap" style="width:100%;border-radius: 8px 8px 0px 0px;text-align:center;background-color:gray">
<b style="color:white;">خریدار</b>
</div>
<table style="width:100%;">
<tbody>
<tr style="text-align:center;">
<td class="">
<p>
<b>نام:
</b>
{{ bid.legalName }}
</p>
</td>
<td class="center">
<p>
<b>شماره ثبت / شناسه ملی:
</b>
{{ bid.shomaresabt }}
</p>
</td>
<td class="center">
<p>
<b>شماره اقتصادی:
</b>
{{ bid.codeeghtesadi }}
</p>
</td>
<td class="center">
<p>
<b>تلفن / نمابر:</b>
{{ bid.tel }}
</p>
</td>
</tr>
<tr>
<td class="" colspan="1">
<p>
<b>کد پستی:</b>
{{ bid.postalcode }}
</p>
</td>
<td class="" colspan="3">
<p>
<b>آدرس:
</b>
استان
{{ bid.ostan }}، شهر
{{ bid.shahrestan }}،
{{ bid.address }}
</p>
</td>
</tr>
</tbody>
</table>
</div>
<div style="width:100%;margin-top:5px;text-align:center;">
<table style="width:100%;">
<thead>
<tr class="stimol" style="background-color:gray;">
<th class="text-white" style="width:80px">ردیف</th>
<th class="text-white">کالا/خدمات</th>
<th class="text-white">شرح</th>
<th class="text-white">تعداد / مقدار</th>
<th class="text-white">مبلغ واحد</th>
<th class="text-white">تخفیف</th>
<th class="text-white">مالیات</th>
<th class="text-white">مبلغ کل</th>
</tr>
</thead>
<tbody>
{% set taxAll = 0 %}
{% set rowIndex = 0 %}
{% for item in rows%}
{% if item.commodity %}
{% set taxAll = taxAll + item.tax %}
{% set rowIndex = rowIndex + 1 %}
<tr class="stimol">
<td class="center item">{{rowIndex}}</td>
<td class="center item">
{{ item.commodity.code }}
-
{{ item.commodity.name }}</td>
<td class="center item">{{ item.des }}</td>
<td class="center item">
{{ item.commdityCount | number_format }}
{{ item.commodity.unit.name }}
</td>
<td class="center item">{{ ((item.bs - item.tax + item.discount) / item.commdityCount) | number_format }}</td>
<td class="center item">{{ item.discount | number_format }}</td>
<td class="center item">{{ item.tax | number_format}}</td>
<td class="center item">{{ item.bs| number_format }}</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
<div style="width:100%;margin-top:0px;text-align:center;">
<table style="width:100%;">
<tbody>
<tr class="stimol">
<td class="item">
<h4>
تخفیف:
{{discount | number_format}}
</h4>
</td>
<td class="item">
<h4>
مالیات:
{{taxAll | number_format}}
</h4>
</td>
<td class="item">
<h4>
حمل و نقل:
{{transfer | number_format}}
</h4>
</td>
<td class="item">
<h4>
جمع کل:
{{doc.amount | number_format}}
</h4>
</td>
</tr>
<tr class="stimol">
<td class="item" colspan="4">
<h4>
توضیحات:
{{doc.des}}
</h4>
</td>
</tr>
</tbody>
</table>
</div>
<div style="width:100%;margin-top:20px;text-align:center;">
<table style="width:100%;">
<tbody>
<tr class="">
<td class="center" style="height:90px">
<h4>
مهر و امضا خریدار
</h4>
</td>
<td class="center" style="height:90px">
<h4>
مهر و امضا فروشنده:
</h4>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</body></div></body></html>

View file

@ -1,20 +0,0 @@
{% extends 'base.html.twig' %}
{% block title %}Hello PrintersController!{% endblock %}
{% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style>
<div class="example-wrapper">
<h1>Hello {{ controller_name }}! ✅</h1>
This friendly message is coming from:
<ul>
<li>Your controller at <code><a href="{{ 'C:/xampp/htdocs/hesabixCore/src/Controller/PrintersController.php'|file_link(0) }}">src/Controller/PrintersController.php</a></code></li>
<li>Your template at <code><a href="{{ 'C:/xampp/htdocs/hesabixCore/templates/printers/index.html.twig'|file_link(0) }}">templates/printers/index.html.twig</a></code></li>
</ul>
</div>
{% endblock %}

6493
public_html/css/bootstrap.mpdf.css vendored Normal file

File diff suppressed because it is too large Load diff