merge app api

This commit is contained in:
Schneider Roland
2023-01-19 17:43:10 +01:00
570 changed files with 81491 additions and 1263 deletions

View File

@@ -18,6 +18,12 @@ use yii\i18n\Formatter;
class DateUtil
{
public static function fromUnixTimeStamp($timestamp){
$dt = DateUtil::utcDate();
$dt->setTimestamp($timestamp);
return $dt;
}
/**
* Get UTC today @00:00:00 .
* Helper method to generate date for mysql
@@ -25,13 +31,49 @@ class DateUtil
* @return DateTime
* @throws Exception
*/
public static function todayStart( ){
$d2 = new DateTime();
public static function todayStart(){
$d2 = new DateTime();
return DateUtil::utcDate($d2);
}
/**
* @param $date \DateTime optional. The date to set as utc date. If not set, new DateTime() will be used
* @return DateTime the datetime object with time reset and utc timezone
*/
public static function utcDate($date = null){
$d2 = isset($date ) ? $date : new DateTime();
$d2 = DateUtil::withTimeZoneUTC($d2);
return DateUtil::resetTime($d2);
}
/**
* @param $date \DateTime optional. If not set,defaults to : new DateTime() .
* @return DateTime
*/
public static function utcDateTime($date = null){
$d2 = isset($date ) ? $date : new DateTime();
return DateUtil::withTimeZoneUTC($d2);
}
/**
* @param $date \DateTime
* @return DateTime
*/
public static function withTimeZoneUTC( $date = null){
$d2 = isset($date ) ? $date : new DateTime();
$d2->setTimezone( new DateTimeZone('UTC') );
$d2->setTime(0, 0);
return $d2;
}
/**
* @param $dateTime \DateTime
* @return \DateTime
*/
public static function resetTime($dateTime){
$dateTime->setTime(0, 0);
return $dateTime;
}
/**
* Get UTC t @00:00:00 .
* Helper method to generate date for mysql
@@ -39,16 +81,12 @@ class DateUtil
* @return DateTime
* @throws Exception
*/
public static function tomorrowStart( ){
$d2 = new DateTime();
public static function tomorrowStart( $date = null){
$d2 = isset($date) ? $date : new DateTime();
$d2->add(new DateInterval('P1D'));
$d2->setTimezone( new DateTimeZone('UTC') );
$d2->setTime(0, 0);
return $d2;
return DateUtil::utcDate($d2);
}
public static function addMonth($timestamp, $monthCount = 1)
{
@@ -99,7 +137,7 @@ class DateUtil
* @return string
* @throws InvalidConfigException
*/
public static function formatUtc($dateTimeObject)
public static function formatDateTimeUtc($dateTimeObject)
{
$formatter = new Formatter;
$formatter->datetimeFormat = 'php:Y-m-d H:i:s';
@@ -127,6 +165,10 @@ class DateUtil
return $date;
}
public static function parseDateTime($dateTimeString){
return DateTime::createFromFormat('Y-m-d H:i:s', $dateTimeString, new DateTimeZone( 'UTC'));
}
/**
* @param integer $weekDay Numeric representation of the day of the week. @See https://www.php.net/manual/en/function.date.php
* @return string

View File

@@ -4,7 +4,7 @@ namespace common\components;
use common\models\Transfer;
use yii\base\Object;
use yii\base\BaseObject;
use common\models\MessageDetstaLab;
use common\models\MessageDetstaTetel;
use common\models\MessageDetsta;
@@ -12,13 +12,13 @@ use common\models\MessageDetstaFej;
use common\models\TicketInstallmentRequest;
/**
* Detstat üzenet mentése adatbázisba
*
*
* @property common\models\Ugiro $koteg
* @property common\models\giro\GiroDETSTA $giroDETSTA
*/
class DetStaDBSave extends Object
class DetStaDBSave extends BaseObject
{
/**
* giro köteg
* */
@@ -35,21 +35,21 @@ class DetStaDBSave extends Object
public $messageFej;
/**messagedetsta lab*/
public $messageLab;
public $path;
/**messagedetsta tetelek*/
public $messageTetelek = [];
public function run(){
$this->saveMessageDetsta();
$this->saveMessageDetstaFej( );
$this->saveMessageDetstaLab();
$this->saveMessageDetstaTetelek();
}
/**
*
* */
@@ -60,17 +60,17 @@ class DetStaDBSave extends Object
if ( isset( $this->koteg ) ){
$this->message->id_ugiro = $this->koteg->id_ugiro;
}
if ( !$this->message->save() ){
\Yii::error("Nem sikerült menteni a detsta üzenet fájlt");
throw new \Exception("Nem sikerült menteni a detsta üzenet fájtl");
}
\Yii::info("detsta üzenet mentve");
}
protected function readDate($date){
$date = trim($date);
if ( empty($date))
@@ -81,7 +81,7 @@ class DetStaDBSave extends Object
}
return $dtime->format('Y-m-d');
}
/**
*
* */
@@ -89,9 +89,9 @@ class DetStaDBSave extends Object
$this->messageFej = new MessageDetstaFej();
$fej = $this->giroDETSTA->fej;
/** @var common\components\giro\GiroDETSTAFej $fej */
$dtime = \DateTime::createFromFormat("yyyyMMdd","");
$this->messageFej->id_message = $this->message->id_message;
$this->messageFej->record_tipus = $fej->recordTipus;
$this->messageFej->uzenet_tipus = $fej->uzenetTipus;
@@ -108,7 +108,7 @@ class DetStaDBSave extends Object
}
\Yii::info("detsta fej üzenet mentve");
}
protected function saveMessageDetstaLab( ){
$this->messageLab = new MessageDetstaLab();
$lab = $this->giroDETSTA->lab;
@@ -120,25 +120,25 @@ class DetStaDBSave extends Object
$this->messageLab->visszautasitott_tetelek_osszerteke = $lab->visszautasitottTetelekSzama;
$this->messageLab->megnemvalaszolt_tetelek_szama = $lab->megNemValaszoltTetelekSzama;
$this->messageLab->megnemvalaszolt_tetelek_osszerteke = $lab->megNemValaszoltTetelekOsszerteke;
if ( !$this->messageLab->save(false)){
\Yii::error("Nem sikerült menteni a detsta üzenet lab fájlt");
throw new \Exception("Nem sikerült menteni a detsta üzenet lab fájlt");
}
\Yii::info("detsta lab üzenet mentve");
}
protected function saveMessageDetstaTetelek( ){
$tetelek = $this->giroDETSTA->tetelek;
foreach ($tetelek as $tetel){
$this->saveMessageDetstaTetel($tetel);
}
}
protected function saveMessageDetstaTetel($tetel ){
$mt = new MessageDetstaTetel();
$mt->id_message = $this->message->id_message;
$mt->record_tipus = $tetel->recordTipus ;
$mt->tetel_sorszam= $tetel->tetelSorszam ;
$mt->osszeg= $tetel->osszeg ;
@@ -149,22 +149,22 @@ class DetStaDBSave extends Object
$mt->valasz_hivatkozasi_kod= $tetel->valaszHivatkozasiKod ;
$mt->eredeti_hivatkozasi_kod= $tetel->eredetiHivatkozasiKod ;
$mt->ugyfel_azonosito= $tetel->ugyfelAzonosito ;
$request = $this->readRequest($mt->tetel_sorszam);
if ( isset($request) ){
$mt->id_ticket_installment_request = $request->id_ticket_installment_request;
}
if ( !$mt->save(false)){
\Yii::error("Nem sikerült menteni a detsta üzenet tetelt");
throw new \Exception("Nem sikerült menteni a detsta üzenet tetelt");
}
\Yii::info("detsta tetel üzenet mentve");
$this->messageTetelek[] = $mt;
}
protected function readRequest($tetel_sorszam){
$query = TicketInstallmentRequest::find();
$query->innerJoin("ugiro_request_assignment","ugiro_request_assignment.id_request = ticket_installment_request.id_ticket_installment_request");
@@ -173,6 +173,6 @@ class DetStaDBSave extends Object
$query->andWhere(['ticket_installment_request.number' => $tetel_sorszam]);
return $query->one();
}
}
}

View File

@@ -2,7 +2,7 @@
namespace common\components;
use yii\base\Object;
use yii\base\BaseObject;
use common\models\Ugiro;
use common\components\giro\GiroDETSTA;
@@ -14,7 +14,7 @@ use common\components\giro\GiroDETSTA;
* @property \common\models\UGiro $koteg
*
* */
class DetStatProcessor extends Object{
class DetStatProcessor extends BaseObject{
/**aktuális koteg, config paraméterként kapju*/
@@ -154,4 +154,4 @@ class DetStatProcessor extends Object{
}
}
}

View File

@@ -3,7 +3,7 @@
namespace common\components;
use common\models\Transfer;
use yii\base\Object;
use yii\base\BaseObject;
use common\models\TicketInstallmentRequest;
use common\components\giro\GiroDETSTATetel;
use common\models\Account;
@@ -19,7 +19,7 @@ use common\models\Contract;
*
*
*/
class DetStatTetelProcessor extends Object {
class DetStatTetelProcessor extends BaseObject {
/**
* A válasz tétel . Ha nincs megadva, automatikus visszautasítjuk a megbízást
* */
@@ -320,4 +320,4 @@ class DetStatTetelProcessor extends Object {
public function hasError() {
return false;
}
}
}

View File

@@ -4,7 +4,7 @@ namespace common\components;
use common\models\Card;
class FreeUniqueCardNumberGenerator extends \yii\base\Object {
class FreeUniqueCardNumberGenerator extends \yii\base\BaseObject {
public $count;
public $keyset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
public $length = 6;
@@ -37,4 +37,4 @@ class FreeUniqueCardNumberGenerator extends \yii\base\Object {
protected function checkCacheUnique($number) {
return array_search ( $number, $this->cache ) === false;
}
}
}

View File

@@ -147,6 +147,7 @@ class GD
public function save($file, $quality = 90)
{
try{
switch($this->_mime) {
case 'image/jpeg':
return imagejpeg($this->_image, $file, $quality);
@@ -159,6 +160,9 @@ class GD
return imagegif($this->_image, $file);
break;
}
}catch (\Exception $e){
\Yii::error("Failed to save image image:", $e->getMessage());
}
return false;
}
}

View File

@@ -538,4 +538,9 @@ class Helper {
return $result;
}
public static function isRestAllowVerifyOnly() {
return \Yii::$app->params ['rest_allow_verify_only'] == true;
}
}

View File

@@ -1,4 +1,5 @@
<?php
namespace common\components;
use Yii;
@@ -9,14 +10,15 @@ use common\components\GD;
class Image
{
/**
* @param UploadedFile $fileInstance
* @param string $dir relative dir from upload dir
* @param unknown $resizeWidth
* @param unknown $resizeHeight
* @param bool $resizeCrop
* @throws HttpException*/
/**
* @param UploadedFile $fileInstance
* @param string $dir relative dir from upload dir
* @param unknown $resizeWidth
* @param unknown $resizeHeight
* @param bool $resizeCrop
* @throws HttpException
*/
public static function upload(UploadedFile $fileInstance, $dir = '', $resizeWidth = null, $resizeHeight = null, $resizeCrop = false)
{
$fileName = Upload::getUploadPath($dir) . DIRECTORY_SEPARATOR . Upload::getFileName($fileInstance);
@@ -25,29 +27,29 @@ class Image
? self::copyResizedImage($fileInstance->tempName, $fileName, $resizeWidth, $resizeHeight, $resizeCrop)
: $fileInstance->saveAs($fileName);
if(!$uploaded){
throw new HttpException(500, 'Cannot upload file "'.$fileName.'". Please check write permissions.');
if (!$uploaded) {
throw new HttpException(500, 'Cannot upload file "' . $fileName . '". Please check write permissions.');
}
return Upload::getLink($fileName);
}
public static function saveBinary($binary_data, $dir = '')
{
$fileName = Upload::getUploadPath($dir) . DIRECTORY_SEPARATOR . Upload::genFileName("jpg");
$uploaded = file_put_contents( $fileName, $binary_data );
$uploaded = file_put_contents($fileName, $binary_data);
if(!$uploaded){
throw new HttpException(500, 'Cannot upload file "'.$fileName.'". Please check write permissions.');
if (!$uploaded) {
throw new HttpException(500, 'Cannot upload file "' . $fileName . '". Please check write permissions.');
}
return Upload::getLink($fileName);
}
/**
*
*
* @param unknown $filename
* @param unknown $width
* @param unknown $height
@@ -56,16 +58,14 @@ class Image
*/
static function thumb($filename, $width = null, $height = null, $crop = true)
{
if($filename && file_exists(($filename = Yii::getAlias('@frontend/web') . $filename)))
{
if ($filename && file_exists(($filename = Yii::getAlias('@frontend/web') . $filename))) {
$info = pathinfo($filename);
$thumbName = $info['filename'] . '-' . md5( filemtime($filename) . (int)$width . (int)$height . (int)$crop ) . '.' . $info['extension'];
$thumbName = $info['filename'] . '-' . md5(filemtime($filename) . (int)$width . (int)$height . (int)$crop) . '.' . $info['extension'];
$thumbFile = Yii::getAlias('@frontend/web') . DIRECTORY_SEPARATOR . Upload::$UPLOADS_DIR . DIRECTORY_SEPARATOR . 'thumbs' . DIRECTORY_SEPARATOR . $thumbName;
$thumbWebFile = '/' . Upload::$UPLOADS_DIR . '/thumbs/' . $thumbName;
if(file_exists($thumbFile)){
if (file_exists($thumbFile)) {
return $thumbWebFile;
}
elseif(FileHelper::createDirectory(dirname($thumbFile), 0777) && self::copyResizedImage($filename, $thumbFile, $width, $height, $crop)){
} elseif (FileHelper::createDirectory(dirname($thumbFile), 0777) && self::copyResizedImage($filename, $thumbFile, $width, $height, $crop)) {
return $thumbWebFile;
}
}
@@ -74,39 +74,38 @@ class Image
static function copyResizedImage($inputFile, $outputFile, $width, $height = null, $crop = true)
{
if (extension_loaded('gd'))
{
$image = new GD($inputFile);
if (extension_loaded('gd')) {
try {
$image = new GD($inputFile);
if($height) {
if($width && $crop){
$image->cropThumbnail($width, $height);
if ($height) {
if ($width && $crop) {
$image->cropThumbnail($width, $height);
} else {
$image->resize($width, $height);
}
} else {
$image->resize($width, $height);
$image->resize($width);
}
} else {
$image->resize($width);
return $image->save($outputFile);
} catch (\Exception $e) {
\Yii::error("Failed to create thumbnail: ". $e->getMessage());
}
return $image->save($outputFile);
}
elseif(extension_loaded('imagick'))
{
} elseif (extension_loaded('imagick')) {
$image = new \Imagick($inputFile);
if($height && !$crop) {
if ($height && !$crop) {
$image->resizeImage($width, $height, \Imagick::FILTER_LANCZOS, 1, true);
}
else{
} else {
$image->resizeImage($width, null, \Imagick::FILTER_LANCZOS, 1);
}
if($height && $crop){
if ($height && $crop) {
$image->cropThumbnailImage($width, $height);
}
return $image->writeImage($outputFile);
}
else {
} else {
throw new HttpException(500, 'Please install GD or Imagick extension');
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace common\components;
use Mpdf\Mpdf;
use yii\base\BaseObject;
class MpdfUtil extends BaseObject
{
// mpdf version 6 constructor
//function mPDF($mode='',$format='A4',$default_font_size=0,$default_font='',$mgl=15,$mgr=15,$mgt=16,$mgb=16,$mgh=9,$mgf=9, $orientation='P') {
public static function createMpdfWith6XConstructor($mode = '', $format = 'A4', $default_font_size = 0, $default_font = '', $mgl = 15, $mgr = 15, $mgt = 16, $mgb = 16, $mgh = 9, $mgf = 9, $orientation = 'P')
{
return self::createMpdf([
'mode' => $mode,
'format' => $format,
'default_font_size' => $default_font_size,
'default_font' => $default_font,
'margin_left' => $mgl,
'margin_right' => $mgr,
'margin_top' => $mgt,
'margin_bottom' => $mgb,
'margin_header' => $mgh,
'margin_footer' => $mgf,
'orientation' => $orientation
]);
}
public static function createMpdf($options = [])
{
$mpdf = new Mpdf(
array_merge([
'mode' => 'utf-8',
'format' => 'A4'
], $options)
);
return $mpdf;
}
}

View File

@@ -2,7 +2,7 @@
namespace common\components;
use yii\base\Object;
use yii\base\BaseObject;
use yii\db\Query;
use common\models\Product;
use yii\data\ActiveDataProvider;
@@ -14,7 +14,7 @@ use common\models\Transfer;
* @property common\models\Account $account a kassza
* @property common\models\Product[] $products a termékek
* */
class ProductInventory extends Object{
class ProductInventory extends BaseObject{
@@ -110,4 +110,4 @@ class ProductInventory extends Object{
}
?>
?>

View File

@@ -0,0 +1,72 @@
<?php
namespace common\components;
class StopWatch
{
public $start;
public $splits = [];
public $stop;
// public function _(){
// $this->start();
// }
public function __construct()
{
$this->start();
}
public function start()
{
$this->start = $this->time();
}
public function split()
{
$this->splits[] = $this->time();
return $this->getSplit();
}
public function stop()
{
$this->stop = $this->time();
}
function time()
{
return time();
}
function diff($start, $end)
{
if (!isset($start) || !isset($end)) {
return -1;
}
return $end - $start;
}
function getSplit()
{
$lastSplit = null;
if (isset($this->stop)) {
$lastSplit = $this->stop;
} else {
$count = count($this->splits);
if ($count > 0) {
$lastSplit = $this->splits[$count - 1];
}
}
return $this->diff($this->start, $lastSplit);
}
function getTotal(){
return $this->diff($this->start, $this->stop);
}
}

File diff suppressed because one or more lines are too long

View File

@@ -11,7 +11,7 @@ use common\models\Ticket;
class TransferPayout extends \yii\base\Object{
class TransferPayout extends \yii\base\BaseObject{
/**Current user*/
public $idUser = null;
@@ -136,4 +136,4 @@ class TransferPayout extends \yii\base\Object{
}
}
}

View File

@@ -2,34 +2,35 @@
namespace common\components\accountstate;
use yii\base\Object;
use common\models\User;
use common\models\Account;
use common\models\AccountState;
use common\components\DailyListing;
use common\components\MpdfUtil;
use yii\base\BaseObject;
/**
* @property common\models\AccountState $model
* */
class AccountStateMail extends Object {
class AccountStateMail extends BaseObject {
public $controller;
public $model;
public $user;
public $account;
public $message;
public $details;
public function init(){
$this->user = User::findOne($this->model->id_user);
$this->account = Account::findOne($this->model->id_account);
$this->details = null;
if ($this->model ->isTypeClose ()) {
$prev;
if ($this->model->type == AccountState::TYPE_CLOSE) {
if (isset ( $this->model->prev_state )) {
@@ -41,28 +42,28 @@ class AccountStateMail extends Object {
}
$this->details = new DailyListing();
$this->details->loadAccountState ( $this->model );
$this->details->readModeAccountState();
// $this->details->readTotalEasy ();
// $this->details->readTotalDetailed ();
// $this->details->readTotalMedium ();
}
}
public function sednMail(){
$subject = $this->model->isTypeOpen() ? "Kassza nyitás " : "Kassza zárás";
$subject .= " - " . $this->user->username ." - ". $this->account->name;
$this->message = \Yii::$app->mailer->compose('account_state', [
'model' => $this->model,
'details' => $this->details
]);
$this->attachPdf();
try{
$this->message->setFrom(\Yii::$app->params['infoEmail'])
->setTo( \Yii::$app->params['notify_mail'] )
@@ -71,21 +72,21 @@ class AccountStateMail extends Object {
}catch (\Exception $e){
\Yii::error("Nem sikerült elküldeni a kassza müvelet emailt");
}
}
protected function attachPdf(){
$mpdf=new \mPDF('utf-8', 'A4-L');
$mpdf= MpdfUtil::createMpdfWith6XConstructor('utf-8', 'A4-L');
$mpdf->useSubstitutions=false;
$mpdf->simpleTables = true;
$mpdf->SetHeader( \Yii::$app->params[ "company_name" ] . " - Létrehozva: " .$user->username . ", ".\Yii::$app->formatter->asDatetime(time()) );
$mpdf->setFooter('{PAGENO} / {nb}');
$stylesheet = file_get_contents( \Yii::getAlias('@vendor'.'/bower/bootstrap/dist/css/bootstrap.css')); // external css
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($this->controller->renderPartial("@common/views/account-state/account_state_pdf", [
'model' => $this->model,
'details' => $this->details
@@ -94,11 +95,11 @@ class AccountStateMail extends Object {
$dt= "_letrehozva_".date("Ymd_His"). "_" . $this->user->username;
$fn= $type .$dt.".pdf";
$content = $mpdf->Output($fn, 'S');
$this->message->attachContent($content, ['fileName' => $fn, 'contentType' => 'application/pdf']);
}
}
}