some progress and bug fix
This commit is contained in:
parent
0d35ed9b7c
commit
49eb437fd7
|
@ -431,6 +431,10 @@ class BusinessController extends AbstractController
|
|||
'archiveView' => true,
|
||||
'active' => $perm->getUser()->isActive(),
|
||||
'shareholder' => true,
|
||||
'plugAccproAccounting'=>true,
|
||||
'plugAccproRfsell'=>true,
|
||||
'plugAccproRfbuy'=>true,
|
||||
'plugAccproCloseYear'=>true,
|
||||
];
|
||||
} elseif ($perm) {
|
||||
$result = [
|
||||
|
@ -466,6 +470,10 @@ class BusinessController extends AbstractController
|
|||
'archiveView' => $perm->isArchiveView(),
|
||||
'active' => $perm->getUser()->isActive(),
|
||||
'shareholder' => $perm->isShareholder(),
|
||||
'plugAccproAccounting'=>$perm->isPlugAccproAccounting(),
|
||||
'plugAccproRfsell'=>$perm->isPlugAccproRfsell(),
|
||||
'plugAccproRfbuy'=>$perm->isPlugAccproRfbuy(),
|
||||
'plugAccproCloseYear'=>$perm->isPlugAccproCloseYear(),
|
||||
];
|
||||
}
|
||||
return $this->json($result);
|
||||
|
@ -529,6 +537,10 @@ class BusinessController extends AbstractController
|
|||
$perm->setArchiveUpload($params['archiveUpload']);
|
||||
$perm->setArchiveView($params['archiveView']);
|
||||
$perm->setShareholder($params['shareholder']);
|
||||
$perm->setPlugAccproCloseYear($params['plugAccproCloseYear']);
|
||||
$perm->setPlugAccproRfbuy($params['plugAccproRfbuy']);
|
||||
$perm->setPlugAccproRfsell($params['plugAccproRfsell']);
|
||||
$perm->setPlugAccproAccounting($params['plugAccproAccounting']);
|
||||
$entityManager->persist($perm);
|
||||
$entityManager->flush();
|
||||
$log->insert('تنظیمات پایه', 'ویرایش دسترسیهای کاربر با پست الکترونیکی ' . $user->getEmail(), $this->getUser(), $business);
|
||||
|
|
|
@ -405,7 +405,6 @@ class CommodityController extends AbstractController
|
|||
#[Route('/api/commodity/cat/get/line', name: 'app_commodity_cat_get_line')]
|
||||
public function app_commodity_cat_get_line(Jdate $jdate, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
|
||||
{
|
||||
|
||||
$acc = $access->hasRole('commodity');
|
||||
if (!$acc)
|
||||
throw $this->createAccessDeniedException();
|
||||
|
|
|
@ -183,10 +183,10 @@ class HesabdariController extends AbstractController
|
|||
elseif($params['type'] == 'cost') $roll='cost';
|
||||
elseif($params['type'] == 'income') $roll='income';
|
||||
elseif($params['type'] == 'buy') $roll='buy';
|
||||
elseif($params['type'] == 'buy_rfb') $roll='buy';
|
||||
elseif($params['type'] == 'rfbuy') $roll='plugAccproRfbuy';
|
||||
elseif($params['type'] == 'transfer') $roll='transfer';
|
||||
elseif($params['type'] == 'sell') $roll='sell';
|
||||
elseif($params['type'] == 'sell_rbs') $roll='buy';
|
||||
elseif($params['type'] == 'rfsell') $roll='plugAccproRfsell';
|
||||
elseif($params['type'] == 'all') $roll='accounting';
|
||||
else
|
||||
$this->createNotFoundException();
|
||||
|
@ -223,7 +223,7 @@ class HesabdariController extends AbstractController
|
|||
'amount'=>$item->getAmount(),
|
||||
'submitter'=> $item->getSubmitter()->getFullName(),
|
||||
];
|
||||
if($params['type'] == 'sell_rbs' || $params['type'] == 'buy_rfb' || $params['type'] == 'buy' || $params['type'] == 'sell'){
|
||||
if($params['type'] == 'rfsell' || $params['type'] == 'rfbuy' || $params['type'] == 'buy' || $params['type'] == 'sell'){
|
||||
$mainRow = $entityManager->getRepository(HesabdariRow::class)->getNotEqual($item,'person');
|
||||
$temp['person'] = '';
|
||||
if($mainRow)
|
||||
|
|
|
@ -10,6 +10,7 @@ use App\Service\Provider;
|
|||
use App\Entity\HesabdariDoc;
|
||||
use App\Entity\HesabdariRow;
|
||||
use App\Service\Explore;
|
||||
use App\Service\Jdate;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
@ -21,7 +22,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|||
class ReportController extends AbstractController
|
||||
{
|
||||
#[Route('/api/report/person/buysell', name: 'app_report_person_buysell')]
|
||||
public function app_report_person_buysell(Access $access, Request $request, EntityManagerInterface $entityManagerInterface): JsonResponse
|
||||
public function app_report_person_buysell(Provider $provider, Jdate $jdate, Access $access, Request $request, EntityManagerInterface $entityManagerInterface): JsonResponse
|
||||
{
|
||||
$acc = $access->hasRole('report');
|
||||
if (!$acc) {
|
||||
|
@ -32,11 +33,34 @@ class ReportController extends AbstractController
|
|||
if ($content = $request->getContent()) {
|
||||
$params = json_decode($content, true);
|
||||
}
|
||||
$docs = $entityManagerInterface->getRepository(HesabdariDoc::class)->findBy([
|
||||
'year' => $acc['year'],
|
||||
'bid' => $acc['bid'],
|
||||
'type' => $params['type'],
|
||||
]);
|
||||
if ($params['type'] == 'all') {
|
||||
$docs = $entityManagerInterface->getRepository(HesabdariDoc::class)->findBy([
|
||||
'year' => $acc['year'],
|
||||
'bid' => $acc['bid'],
|
||||
]);
|
||||
} else {
|
||||
$docs = $entityManagerInterface->getRepository(HesabdariDoc::class)->findBy([
|
||||
'year' => $acc['year'],
|
||||
'bid' => $acc['bid'],
|
||||
'type' => $params['type'],
|
||||
]);
|
||||
}
|
||||
//filter docs by date
|
||||
$result = [];
|
||||
$dateStart = $provider->shamsiDateToTimestamp($params['dateStart']);
|
||||
$dateEnd = $provider->shamsiDateToTimestamp($params['dateEnd']);
|
||||
foreach ($docs as $doc) {
|
||||
$canAdd = true;
|
||||
if ($dateStart) {
|
||||
if ($provider->shamsiDateToTimestamp($doc->getDate()) < $dateStart) $canAdd = false;
|
||||
}
|
||||
if ($dateEnd) {
|
||||
if ($provider->shamsiDateToTimestamp($doc->getDate()) > $dateEnd) $canAdd = false;
|
||||
}
|
||||
|
||||
if ($canAdd) $result[] = $doc;
|
||||
}
|
||||
$docs = $result;
|
||||
|
||||
$person = $entityManagerInterface->getRepository(Person::class)->findOneBy([
|
||||
'bid' => $acc['bid']->getId(),
|
||||
|
@ -77,11 +101,12 @@ class ReportController extends AbstractController
|
|||
'docCode' => $item->getDoc()->getCode(),
|
||||
'type' => $item->getDoc()->getType()
|
||||
];
|
||||
if ($params['type'] == 'buy') {
|
||||
if ($item->getDoc()->getType() == 'buy' || $item->getDoc()->getType() == 'rfsell') {
|
||||
$temp['priceAll'] = $item->getBd();
|
||||
} elseif ($params['type'] == 'sell') {
|
||||
} elseif ($item->getDoc()->getType() == 'sell' || $item->getDoc()->getType() == 'rfbuy') {
|
||||
$temp['priceAll'] = $item->getBs();
|
||||
}
|
||||
|
||||
if ($temp['count'] != 0) {
|
||||
$temp['priceOne'] = $temp['priceAll'] / $temp['count'];
|
||||
$temp['priceAll'] = number_format($temp['priceAll']);
|
||||
|
@ -147,7 +172,7 @@ class ReportController extends AbstractController
|
|||
}
|
||||
|
||||
#[Route('/api/report/commodity/buysell', name: 'app_report_commodity_buysell')]
|
||||
public function app_report_commodity_buysell(Access $access, Request $request, EntityManagerInterface $entityManagerInterface): JsonResponse
|
||||
public function app_report_commodity_buysell(Provider $provider, Jdate $jdate, Access $access, Request $request, EntityManagerInterface $entityManagerInterface): JsonResponse
|
||||
{
|
||||
$acc = $access->hasRole('report');
|
||||
if (!$acc) {
|
||||
|
@ -176,16 +201,33 @@ class ReportController extends AbstractController
|
|||
'bid' => $acc['bid']->getId(),
|
||||
'code' => $params['commodity'],
|
||||
]);
|
||||
//filter docs by date
|
||||
$result = [];
|
||||
$dateStart = $provider->shamsiDateToTimestamp($params['dateStart']);
|
||||
$dateEnd = $provider->shamsiDateToTimestamp($params['dateEnd']);
|
||||
foreach ($docs as $doc) {
|
||||
$canAdd = true;
|
||||
if ($dateStart) {
|
||||
if ($provider->shamsiDateToTimestamp($doc->getDate()) < $dateStart) $canAdd = false;
|
||||
}
|
||||
if ($dateEnd) {
|
||||
if ($provider->shamsiDateToTimestamp($doc->getDate()) > $dateEnd) $canAdd = false;
|
||||
}
|
||||
|
||||
if ($canAdd) $result[] = $doc;
|
||||
}
|
||||
$docs = $result;
|
||||
$result = [];
|
||||
foreach ($docs as $doc) {
|
||||
$rows = $doc->getHesabdariRows();
|
||||
foreach ($rows as $row) {
|
||||
if ($row->getCommodity() && $row->getCommodity()->getId() == $commodity->getId()) {
|
||||
$result[] = $row;
|
||||
}
|
||||
if ($row->getCommodity())
|
||||
if ($row->getCommodity()->getId() == $commodity->getId()) {
|
||||
$result[] = $row;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$response = [];
|
||||
foreach ($result as $item) {
|
||||
$temp = [
|
||||
|
@ -200,9 +242,9 @@ class ReportController extends AbstractController
|
|||
'docCode' => $item->getDoc()->getCode(),
|
||||
'type' => $item->getDoc()->getType(),
|
||||
];
|
||||
if ($item->getDoc()->getType() == 'buy') {
|
||||
if ($item->getDoc()->getType() == 'buy' || $item->getDoc()->getType() == 'rfsell') {
|
||||
$temp['priceAll'] = $item->getBd();
|
||||
} elseif ($item->getDoc()->getType() == 'sell') {
|
||||
} elseif ($item->getDoc()->getType() == 'sell' || $item->getDoc()->getType() == 'rfbuy') {
|
||||
$temp['priceAll'] = $item->getBs();
|
||||
}
|
||||
if ($temp['count'] != 0) {
|
||||
|
|
59
hesabixCore/src/Controller/RfbuyController.php
Normal file
59
hesabixCore/src/Controller/RfbuyController.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Service\Log;
|
||||
use App\Service\Access;
|
||||
use App\Service\Explore;
|
||||
use App\Entity\HesabdariDoc;
|
||||
use App\Entity\StoreroomTicket;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
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 RfbuyController extends AbstractController
|
||||
{
|
||||
#[Route('/api/rfbuy/edit/can/{code}', name: 'app_rfbuy_can_edit')]
|
||||
public function app_rfbuy_can_edit(Request $request,Access $access,Log $log,EntityManagerInterface $entityManager, string $code): JsonResponse
|
||||
{
|
||||
$canEdit = true;
|
||||
$acc = $access->hasRole('plugAccproRfbuy');
|
||||
if(!$acc)
|
||||
throw $this->createAccessDeniedException();
|
||||
|
||||
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
|
||||
'bid'=>$acc['bid'],
|
||||
'code'=>$code
|
||||
]);
|
||||
//check related documents
|
||||
if(count($doc->getRelatedDocs()) != 0)
|
||||
$canEdit = false;
|
||||
|
||||
//check storeroom tickets
|
||||
$tickets = $entityManager->getRepository(StoreroomTicket::class)->findBy(['doc'=>$doc]);
|
||||
if(count($tickets) != 0)
|
||||
$canEdit = false;
|
||||
return $this->json([
|
||||
'result'=> $canEdit
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/api/rfbuy/get/info/{code}', name: 'app_rfbuy_get_info')]
|
||||
public function app_rfbuy_get_info(Request $request,Access $access,Log $log,EntityManagerInterface $entityManager, string $code): JsonResponse
|
||||
{
|
||||
$acc = $access->hasRole('plugAccproRfbuy');
|
||||
if(!$acc)
|
||||
throw $this->createAccessDeniedException();
|
||||
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
|
||||
'bid'=>$acc['bid'],
|
||||
'code'=>$code
|
||||
]);
|
||||
if(!$doc)
|
||||
throw $this->createNotFoundException();
|
||||
|
||||
return $this->json(Explore::ExploreSellDoc($doc));
|
||||
}
|
||||
}
|
18
hesabixCore/src/Controller/RfsellController.php
Normal file
18
hesabixCore/src/Controller/RfsellController.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class RfsellController extends AbstractController
|
||||
{
|
||||
#[Route('/rfsell', name: 'app_rfsell')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('rfsell/index.html.twig', [
|
||||
'controller_name' => 'RfsellController',
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -105,6 +105,18 @@ class Permission
|
|||
#[ORM\Column(nullable: true)]
|
||||
private ?bool $cheque = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?bool $plugAccproRfbuy = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?bool $plugAccproRfsell = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?bool $plugAccproAccounting = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?bool $plugAccproCloseYear = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
|
@ -469,4 +481,52 @@ class Permission
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isPlugAccproRfbuy(): ?bool
|
||||
{
|
||||
return $this->plugAccproRfbuy;
|
||||
}
|
||||
|
||||
public function setPlugAccproRfbuy(?bool $plugAccproRfbuy): static
|
||||
{
|
||||
$this->plugAccproRfbuy = $plugAccproRfbuy;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isPlugAccproRfsell(): ?bool
|
||||
{
|
||||
return $this->plugAccproRfsell;
|
||||
}
|
||||
|
||||
public function setPlugAccproRfsell(?bool $plugAccproRfsell): static
|
||||
{
|
||||
$this->plugAccproRfsell = $plugAccproRfsell;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isPlugAccproAccounting(): ?bool
|
||||
{
|
||||
return $this->plugAccproAccounting;
|
||||
}
|
||||
|
||||
public function setPlugAccproAccounting(?bool $plugAccproAccounting): static
|
||||
{
|
||||
$this->plugAccproAccounting = $plugAccproAccounting;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isPlugAccproCloseYear(): ?bool
|
||||
{
|
||||
return $this->plugAccproCloseYear;
|
||||
}
|
||||
|
||||
public function setPlugAccproCloseYear(?bool $plugAccproCloseYear): static
|
||||
{
|
||||
$this->plugAccproCloseYear = $plugAccproCloseYear;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,8 +46,9 @@ class PersonRepository extends ServiceEntityRepository
|
|||
public function searchByNikename(Business $bid,string $search,int $maxResults = 10): array
|
||||
{
|
||||
return $this->createQueryBuilder('p')
|
||||
->andWhere('p.bid = :val')
|
||||
->andwhere('p.bid = :val')
|
||||
->andWhere("p.nikename LIKE :search")
|
||||
->orWhere("p.mobile LIKE :search")
|
||||
->setParameter('val', $bid)
|
||||
->setParameter('search', '%' . $search . '%')
|
||||
->setMaxResults($maxResults)
|
||||
|
|
|
@ -29,7 +29,8 @@ class Provider
|
|||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
public function createSearchParams(Request $request){
|
||||
public function createSearchParams(Request $request)
|
||||
{
|
||||
$response = [];
|
||||
$params = [];
|
||||
if ($content = $request->getContent()) {
|
||||
|
@ -38,51 +39,55 @@ class Provider
|
|||
|
||||
//set page of content want to search
|
||||
$page = 1;
|
||||
if(array_key_exists('page',$params))
|
||||
if (array_key_exists('page', $params))
|
||||
$page = $params['page'];
|
||||
$response['page'] = $page;
|
||||
|
||||
$cat = '';
|
||||
if(array_key_exists('cat',$params))
|
||||
if (array_key_exists('cat', $params))
|
||||
$cat = $params['cat'];
|
||||
$response['cat'] = $cat;
|
||||
|
||||
//set max Count of content want to search
|
||||
$count = 15;
|
||||
if(array_key_exists('count',$params))
|
||||
if (array_key_exists('count', $params))
|
||||
$count = $params['count'];
|
||||
$response['count'] = $count;
|
||||
|
||||
//set search keyword of content
|
||||
$search = '';
|
||||
if(array_key_exists('key',$params))
|
||||
if (array_key_exists('key', $params))
|
||||
$search = $params['key'];
|
||||
$response['key'] = $search;
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function maxPages($params,$rowsAllCount){
|
||||
public function maxPages($params, $rowsAllCount)
|
||||
{
|
||||
$res = $rowsAllCount / $params['count'];
|
||||
return is_float($res) ? (int)$res+1:$res;
|
||||
return is_float($res) ? (int)$res + 1 : $res;
|
||||
}
|
||||
public function maxPagesWithPageCount($count,$rowsAllCount){
|
||||
public function maxPagesWithPageCount($count, $rowsAllCount)
|
||||
{
|
||||
$res = $rowsAllCount / $count;
|
||||
return is_float($res) ? (int)$res+1:$res;
|
||||
return is_float($res) ? (int)$res + 1 : $res;
|
||||
}
|
||||
public function gravatarHash($email){
|
||||
return md5( strtolower( trim( $email) ) );
|
||||
public function gravatarHash($email)
|
||||
{
|
||||
return md5(strtolower(trim($email)));
|
||||
}
|
||||
|
||||
public function getAccountingCode($bid,$part){
|
||||
$setter = 'set' . ucfirst($part). 'Code';
|
||||
$part = 'get' . ucfirst($part). 'Code';
|
||||
public function getAccountingCode($bid, $part)
|
||||
{
|
||||
$setter = 'set' . ucfirst($part) . 'Code';
|
||||
$part = 'get' . ucfirst($part) . 'Code';
|
||||
|
||||
$business = $this->entityManager->getRepository(Business::class)->find($bid);
|
||||
if(!$business)
|
||||
if (!$business)
|
||||
return false;
|
||||
$count = $business->{$part}();
|
||||
if(is_null($count))
|
||||
if (is_null($count))
|
||||
$count = 1000;
|
||||
$business->{$setter}(intval($count) + 1);
|
||||
$this->entityManager->persist($business);
|
||||
|
@ -93,22 +98,22 @@ class Provider
|
|||
/**
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function Entity2Array($entity, int $deep = 1, array $ignores = []): null|array{
|
||||
if(is_null($entity)) return [];
|
||||
public function Entity2Array($entity, int $deep = 1, array $ignores = []): null|array
|
||||
{
|
||||
if (is_null($entity)) return [];
|
||||
$result = [];
|
||||
$methods = get_class_methods($entity);
|
||||
$getMethods = [];
|
||||
//get getter methods
|
||||
foreach ($methods as $method){
|
||||
if(str_starts_with($method, 'get')){
|
||||
foreach ($methods as $method) {
|
||||
if (str_starts_with($method, 'get')) {
|
||||
$getMethods[] = trim(trim($method));
|
||||
}
|
||||
elseif(str_starts_with($method, 'is')){
|
||||
} elseif (str_starts_with($method, 'is')) {
|
||||
$getMethods[] = trim(trim($method));
|
||||
}
|
||||
}
|
||||
foreach ($getMethods as $method){
|
||||
if(!is_int(array_search(lcfirst(trim(str_replace(['get','is'], '', $method))), $ignores))) {
|
||||
foreach ($getMethods as $method) {
|
||||
if (!is_int(array_search(lcfirst(trim(str_replace(['get', 'is'], '', $method))), $ignores))) {
|
||||
if (method_exists($entity, $method)) {
|
||||
$method = trim(trim($method));
|
||||
$canProced = true;
|
||||
|
@ -119,30 +124,31 @@ class Provider
|
|||
$canProced = false;
|
||||
if ($canProced) {
|
||||
if (!is_object($value)) {
|
||||
$result[lcfirst(str_replace(['get','is'], '', $method))] = $value;
|
||||
$result[lcfirst(str_replace(['get', 'is'], '', $method))] = $value;
|
||||
} else {
|
||||
if ($deep != 0) {
|
||||
$result[lcfirst(str_replace(['get','is'], '', $method))] = $this->Entity2Array($value, $deep - 1,$ignores);
|
||||
$result[lcfirst(str_replace(['get', 'is'], '', $method))] = $this->Entity2Array($value, $deep - 1, $ignores);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function ArrayEntity2Array(array $entity, int $deep = 1, array $ignores = []): null|array{
|
||||
if(count($entity) == 0) return [];
|
||||
public function ArrayEntity2Array(array $entity, int $deep = 1, array $ignores = []): null|array
|
||||
{
|
||||
if (count($entity) == 0) return [];
|
||||
$result = [];
|
||||
foreach ($entity as $item){
|
||||
$result[] = $this->Entity2Array($item,$deep,$ignores);
|
||||
foreach ($entity as $item) {
|
||||
$result[] = $this->Entity2Array($item, $deep, $ignores);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function createPrint(Business $bid,User $user,String $data){
|
||||
public function createPrint(Business $bid, User $user, String $data)
|
||||
{
|
||||
$print = new PrinterQueue();
|
||||
$print->setDateSubmit(time());
|
||||
$print->setSubmitter($user);
|
||||
|
@ -157,16 +163,17 @@ class Provider
|
|||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function createExcell(array $entities, array $ignores = [],array $headers = null){
|
||||
public function createExcell(array $entities, array $ignores = [], array $headers = null)
|
||||
{
|
||||
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$activeWorksheet = $spreadsheet->getActiveSheet();
|
||||
$arrayEntity = $this->ArrayEntity2Array($entities,0,$ignores);
|
||||
$activeWorksheet->fromArray($arrayEntity,null,'A1');
|
||||
$arrayEntity = $this->ArrayEntity2Array($entities, 0, $ignores);
|
||||
$activeWorksheet->fromArray($arrayEntity, null, 'A1');
|
||||
$activeWorksheet->setRightToLeft(true);
|
||||
$activeWorksheet->getHeaderFooter()->setOddHeader('&CHeader of the Document');
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
$filePath = __DIR__ . '/../../var/'.$this->RandomString(12).'.xlsx';
|
||||
$filePath = __DIR__ . '/../../var/' . $this->RandomString(12) . '.xlsx';
|
||||
$writer->save($filePath);
|
||||
return $filePath;
|
||||
}
|
||||
|
@ -174,15 +181,16 @@ class Provider
|
|||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function createExcellFromArray(array $entities,array $headers = null){
|
||||
public function createExcellFromArray(array $entities, array $headers = null)
|
||||
{
|
||||
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$activeWorksheet = $spreadsheet->getActiveSheet();
|
||||
$activeWorksheet->fromArray($entities,null,'A1');
|
||||
$activeWorksheet->fromArray($entities, null, 'A1');
|
||||
$activeWorksheet->setRightToLeft(true);
|
||||
$activeWorksheet->getHeaderFooter()->setOddHeader('&CHeader of the Document');
|
||||
$writer = new Xlsx($spreadsheet);
|
||||
$filePath = __DIR__ . '/../../var/'.$this->RandomString(12).'.xlsx';
|
||||
$filePath = __DIR__ . '/../../var/' . $this->RandomString(12) . '.xlsx';
|
||||
$writer->save($filePath);
|
||||
return $filePath;
|
||||
}
|
||||
|
@ -192,25 +200,27 @@ class Provider
|
|||
* @param int $length number of characters in the generated string
|
||||
* @return string a new string is created with random characters of the desired length
|
||||
*/
|
||||
private function RandomString($length = 32) {
|
||||
return substr(str_shuffle(str_repeat($x='23456789ABCDEFGHJKLMNPQRSTUVWXYZ', ceil($length/strlen($x)) )),1,$length);
|
||||
private function RandomString($length = 32)
|
||||
{
|
||||
return substr(str_shuffle(str_repeat($x = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function Entity2ArrayJustIncludes($entity, array $includes, int $deep = 1): null|array{
|
||||
if(is_null($entity)) return [];
|
||||
public function Entity2ArrayJustIncludes($entity, array $includes, int $deep = 1): null|array
|
||||
{
|
||||
if (is_null($entity)) return [];
|
||||
$result = [];
|
||||
foreach ($includes as $method){
|
||||
foreach ($includes as $method) {
|
||||
if (method_exists($entity, $method)) {
|
||||
$method = trim(trim($method));
|
||||
$value = $entity->$method();
|
||||
if (!is_object($value)) {
|
||||
$result[lcfirst(str_replace(['get','is'], '', $method))] = $value;
|
||||
$result[lcfirst(str_replace(['get', 'is'], '', $method))] = $value;
|
||||
} else {
|
||||
if ($deep != 0) {
|
||||
$result[lcfirst(str_replace(['get','is'], '', $method))] = $this->Entity2ArrayJustIncludes($value,$includes, $deep - 1);
|
||||
$result[lcfirst(str_replace(['get', 'is'], '', $method))] = $this->Entity2ArrayJustIncludes($value, $includes, $deep - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -221,12 +231,30 @@ class Provider
|
|||
/**
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function ArrayEntity2ArrayJustIncludes(array $entity, array $includes, int $deep = 1): null|array{
|
||||
if(count($entity) == 0) return [];
|
||||
public function ArrayEntity2ArrayJustIncludes(array $entity, array $includes, int $deep = 1): null|array
|
||||
{
|
||||
if (count($entity) == 0) return [];
|
||||
$result = [];
|
||||
foreach ($entity as $item){
|
||||
$result[] = $this->Entity2ArrayJustIncludes($item,$includes,$deep);
|
||||
foreach ($entity as $item) {
|
||||
$result[] = $this->Entity2ArrayJustIncludes($item, $includes, $deep);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
public function shamsiDateToTimestamp(string $stringDate): string | bool
|
||||
{
|
||||
$jdate = new Jdate();
|
||||
$timeArray = explode('-', $stringDate);
|
||||
if (count($timeArray) == 3)
|
||||
$result = $jdate->jmktime(0, 0, 0, $timeArray[1], $timeArray[2], $timeArray[0]);
|
||||
else {
|
||||
$timeArray = explode('/', $stringDate);
|
||||
if (count($timeArray) == 3)
|
||||
$result = $jdate->jmktime(0, 0, 0, $timeArray[1], $timeArray[2], $timeArray[0]);
|
||||
else
|
||||
$result = false;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue