HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: //www/wwwroot/www.shooperm.com/Modules/GST/Repositories/GstConfigureRepository.php
<?php

namespace Modules\GST\Repositories;

use Modules\GST\Entities\GSTGroup;
use Modules\GST\Entities\GstTax;

class GstConfigureRepository
{
    public function getGroup(){
        return GSTGroup::all();
    }
    public function stoteGroup($data){
        $same_state_gst = [];
        $outsite_state_gst = [];
        foreach($data['same_state_gst'] as $key => $gst){
            $gst = explode('-',$gst);
            $percent = 0;
            if($data['same_state_gst_percent'][$key] != null){
                $percent = $data['same_state_gst_percent'][$key];
            }
            $same_state_gst[$gst[1]] = floatval($percent);
        }

        foreach($data['outsite_state_gst'] as $key => $gst){
            $percent = 0;
            $gst = explode('-',$gst);
            if($data['outsite_state_gst_percent'][$key] != null){
                $percent = $data['outsite_state_gst_percent'][$key];
            }
            $outsite_state_gst[$gst[1]] = floatval($percent);
        }

        GSTGroup::create([
            'name' => $data['name'],
            'same_state_gst' => json_encode($same_state_gst),
            'outsite_state_gst' => json_encode($outsite_state_gst)
        ]);
        return true;
    }

    public function updateGroup($data){
        $same_state_gst = [];
        $outsite_state_gst = [];
        foreach($data['same_state_gst'] as $key => $gst){
            $gst = explode('-',$gst);
            $percent = 0;
            if($data['same_state_gst_percent'][$key] != null){
                $percent = $data['same_state_gst_percent'][$key];
            }
            $same_state_gst[$gst[1]] = floatval($percent);
        }

        foreach($data['outsite_state_gst'] as $key => $gst){
            $percent = 0;
            $gst = explode('-',$gst);
            if($data['outsite_state_gst_percent'][$key] != null){
                $percent = $data['outsite_state_gst_percent'][$key];
            }
            $outsite_state_gst[$gst[1]] = floatval($percent);
        }

        GSTGroup::where('id', $data['id'])->update([
            'name' => $data['name'],
            'same_state_gst' => json_encode($same_state_gst),
            'outsite_state_gst' => json_encode($outsite_state_gst)
        ]);
        return true;
    }

    public function getGroupById($id){
        $group = GSTGroup::where('id', $id)->first();
        if($group){
            return $group;
        }
        return false;
    }

    public function deleteGroupById($id){
        $group = GSTGroup::where('id', $id)->first();
        if(count($group->products) > 0){
            return 'not_posible';
        }else{
            $group->delete();
            return 'posible';
        }
    }

    public function updateConfiguration($data)
    {
        $previousRouteServiceProvier = base_path('Modules/GST/Resources/assets/config_files/config.json');
        $newRouteServiceProvier      = base_path('Modules/GST/Resources/assets/config_files/config.txt');
        copy($newRouteServiceProvier, $previousRouteServiceProvier);
        $jsonString = file_get_contents(base_path('Modules/GST/Resources/assets/config_files/config.json'));
        $config = json_decode($jsonString, true);
        $config['enable_gst'] = (!empty($data['enable_gst'])) ? $data['enable_gst'] : "0";
        $config['flat_tax_id'] = (!empty($data['flat_tax_id'])) ? $data['flat_tax_id'] : "0";
        foreach ($data as $key => $value) {
            if (is_array($data[$key])) {
                for ($i=0; $i < count($value); $i++) {
                    $config[$key][$i] = $value[$i];
                }
                $newJsonString = json_encode($config, JSON_PRETTY_PRINT);
                $newJsonString2 = json_encode($config[$key] , JSON_PRETTY_PRINT);
                file_put_contents(base_path('Modules/GST/Resources/assets/config_files/config.json'), stripslashes($newJsonString));
            }
        }
    }
}