improve customer api & gui

This commit is contained in:
Roland Schneider
2021-10-02 22:21:14 +02:00
parent 1d065cc729
commit f98dcb656f
44 changed files with 893 additions and 298 deletions

View File

@@ -22,7 +22,7 @@ class Helper {
*/
public static function calcStartDatimeDaysSinceToday($start, $format = "datetime" ){
$now = time();
if ( $format == "datetime"){
$format = "Y-m-d H:i";
}else if ( $format == "date") {
@@ -30,10 +30,10 @@ class Helper {
}else{
//use format
}
$d = \DateTime::createFromFormat( $format , $start)->getTimeStamp();
$days_between = ceil(abs( $now - $d) / 86400 );
return $days_between;
}
@@ -52,8 +52,8 @@ class Helper {
*/
public static function restrictIfNotAdminTheStartDate($query,$date, $fields = ['transfer.paid_at','transfer.created_at'], $format = 'datetime'){
$result = null;
$needFix = false;
if ( !isset($date) || empty($date)){
$needFix = true;
@@ -63,19 +63,19 @@ class Helper {
$needFix = true;
}
}
if ( $needFix == true ){
$d = Helper::getReceptionVisibilityDays();
$time = date( "Y-m-d H:i:s", strtotime("today -$d day") );
$conditions = [];
foreach ($fields as $f ){
$conditions[] = ['>=', $f, $time];
}
if ( count($conditions) > 1 ){
$andWhereCond = [];
$andWhereCond[0] = "or";
@@ -87,26 +87,26 @@ class Helper {
}else if ( count($conditions) == 1 ){
$andWhereCond = $conditions[0];
}
// $start_date_condition = ['or',[ '>=', 'transfer.created_at', $time ] ,[ '>=', 'transfer.paid_at', $time] ];
if ( isset($andWhereCond)){
if ( isset($andWhereCond)){
$query->andWhere( $andWhereCond );
}
}
return $result;
}
public static function getDateTimeString( ){
return date("Y-m-d H:i:s");
}
public static function getDateString( ){
return date("Y-m-d");
}
public static function getArrayValue($arr,$key,$def){
$result = $def;
if ( array_key_exists($key, $arr)){
@@ -114,8 +114,8 @@ class Helper {
}
return $result;
}
public static function hufRound($m) {
$result = round ( $m / 5, 0 ) * 5;
return $result;
@@ -128,18 +128,18 @@ class Helper {
* @param $end
*/
public static function notInInterval($query, $field, $start, $end) {
$query->andFilterWhere ( [
$query->andFilterWhere ( [
'or',
[
[
'<',
$field,
isset ( $start ) ? $start : '1900-01-01'
isset ( $start ) ? $start : '1900-01-01'
],
[
[
'>=',
$field,
isset ( $end ) ? $end : '3000-01-01'
]
isset ( $end ) ? $end : '3000-01-01'
]
] );
}
@@ -150,21 +150,21 @@ class Helper {
* @param string $end the end date
*/
public static function notPaid($query, $field, $start, $end) {
$query->andFilterWhere ( [
$query->andFilterWhere ( [
'or',
[
[
'<',
$field,
isset ( $start ) ? $start : '1900-01-01'
isset ( $start ) ? $start : '1900-01-01'
],
[
[
'>=',
$field,
isset ( $end ) ? $end : '3000-01-01'
isset ( $end ) ? $end : '3000-01-01'
],
[
"transfer.status" => Transfer::STATUS_NOT_PAID
]
[
"transfer.status" => Transfer::STATUS_NOT_PAID
]
] );
}
@@ -175,15 +175,15 @@ class Helper {
* @param string $end the end date
*/
public static function inInterval($query, $field, $start, $end) {
$query->andFilterWhere ( [
$query->andFilterWhere ( [
'>=',
$field,
$start
$start
] );
$query->andFilterWhere ( [
$query->andFilterWhere ( [
'<',
$field,
$end
$end
] );
}
@@ -194,53 +194,53 @@ class Helper {
* @return array the query 'in interval' rule
*/
public static function queryInIntervalRule($field, $start, $end) {
return [
return [
'and',
[
[
'>=',
$field,
$start
$start
],
[
[
'<',
$field,
$end
]
$end
]
];
}
public static function queryExpireRule($field_start, $field_end, $start, $end) {
return [
return [
'and',
[
[
'<',
$field_start,
$end
$end
],
[
[
'>=',
$field_end,
$start
$start
],
[
[
'<=',
$field_end,
$end
]
$end
]
];
}
public static function queryValidRule($field_start, $field_end, $start, $end) {
return [
return [
'and',
[
[
'<',
$field_start,
$end
$end
],
[
[
'>=',
$field_end,
$start
]
$start
]
];
}
public static function sqlInIntervalRule($field, $paramStart, $paramEnd) {
@@ -270,35 +270,35 @@ class Helper {
public static function queryAccountConstraint($query, $field) {
if (! RoleDefinition::isAdmin ()) {
$query->innerJoin ( "user_account_assignment", $field . ' = user_account_assignment.id_account' );
$query->andWhere ( [
'user_account_assignment.id_user' => Yii::$app->user->id
$query->andWhere ( [
'user_account_assignment.id_user' => Yii::$app->user->id
] );
}
}
public static function roleLabels() {
return [
return [
'reception' => Yii::t ( 'common/role', 'Reception' ),
'admin' => Yii::t ( 'common/role', 'Administrator' ),
'employee' => Yii::t ( 'common/role', 'Alkalmazott' )
'employee' => Yii::t ( 'common/role', 'Alkalmazott' )
];
}
public static function roleDefinitions() {
return [
'employee' => [
'canAllow' => [
'employee'
]
return [
'employee' => [
'canAllow' => [
'employee'
]
],
'admin' => [
'canAllow' => [
'admin' => [
'canAllow' => [
'admin',
'reception',
'employee'
]
'employee'
]
],
'reception' => [
'canAllow' => [ ]
]
'reception' => [
'canAllow' => [ ]
]
];
}
public static function flash($mode, $message) {
@@ -322,26 +322,26 @@ class Helper {
public static function isUserCartVisibilityAll() {
return \Yii::$app->params ['user_cart_item_visibility'] == 'all';
}
public static function getBackendSkin() {
return \Yii::$app->params ['backend_skin'] ;
}
public static function getCompany() {
return \Yii::$app->params ['company'] ;
}
public static function getCompanyName() {
return \Yii::$app->params ['company_name'] ;
}
public static function isCompanyMovar() {
return \Yii::$app->params ['company'] == 'movar';
}
public static function isCompanyGyor() {
return \Yii::$app->params ['company'] == 'gyor';
}
public static function isUserCartOn() {
return \Yii::$app->params ['user_cart_on'] == true;
}
@@ -353,26 +353,26 @@ class Helper {
public static function isTicketTypeDoorAllowedCheckOn() {
return \Yii::$app->params ['ticket_type_door_allowed_check_on'] == true;
}
public static function getProductSaleDefaultFocus() {
return \Yii::$app->params ['product_sale_default_focus'] ;
}
public static function isProductVisibilityAccount() {
return \Yii::$app->params ['product_visiblity'] == 'account';
}
public static function isAccountStateClosePreloadMoney() {
return \Yii::$app->params ['account_state_close_preload_money'] == true;
}
public static function isAccountStateOpenSendMail() {
return \Yii::$app->params ['mail_account_state_open'] == true;
}
public static function isAccountStateCloseSendMail() {
return \Yii::$app->params ['mail_account_state_close'] == true;
}
public static function getReceptionVisibilityDays() {
return \Yii::$app->params ['reception_visibility_days'] ;
}
@@ -399,12 +399,16 @@ class Helper {
public static function isReceptionTransferIndexEnabled(){
return !Helper::isReceptionTransferListToday();
}
public static function getGroupTrainingUrl(){
return \Yii::$app->params['group_training.url'];
}
public static function getRealUserIp() {
$client = @$_SERVER ['HTTP_CLIENT_IP'];
$forward = @$_SERVER ['HTTP_X_FORWARDED_FOR'];
$remote = $_SERVER ['REMOTE_ADDR'];
if (filter_var ( $client, FILTER_VALIDATE_IP )) {
$ip = $client;
} elseif (filter_var ( $forward, FILTER_VALIDATE_IP )) {
@@ -412,10 +416,10 @@ class Helper {
} else {
$ip = $remote;
}
return $ip;
}
public static function url_get_contents ($Url) {
if (!function_exists('curl_init')){
die('CURL is not installed!');
@@ -427,14 +431,14 @@ class Helper {
curl_close($ch);
return $output;
}
public static function getGeoIp() {
$ip = Helper::getRealUserIp ();
$details = json_decode ( Helper::url_get_contents( "http://ipinfo.io/{$ip}/json" ) );
return $details;
}
public static function mkYiiSortItem($field, $column){
return [
$field => [
@@ -454,7 +458,7 @@ class Helper {
}
return $result;
}
public static function setBit($val,$index,$bit_on){
$flag = +$val;
if ( $bit_on ){
@@ -471,7 +475,7 @@ class Helper {
return $result ;
}
public static function generateRandomString($length = 6,$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWX' ) {
$charactersLength = strlen($characters);
$randomString = '';
@@ -480,7 +484,7 @@ class Helper {
}
return $randomString;
}
public static function getWebUrl(){
if ( \Yii::$app->params['development'] == true ){
return "http://localhost/fitness-web";
@@ -529,5 +533,5 @@ class Helper {
return $result;
}
}
}