Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How Filter transactions #888

Closed
starking8b opened this issue Feb 13, 2024 · 17 comments
Closed

How Filter transactions #888

starking8b opened this issue Feb 13, 2024 · 17 comments
Assignees
Labels
question Further information is requested Stale

Comments

@starking8b
Copy link

starking8b commented Feb 13, 2024

I have integrated wallet in my system , my system structure has many models which using the wallet , like Company , Subscriber, Invoice, Revenue , I have a page where I listing all the transactions without any issue , my problem is with globalfilter in datatable , I want the admin to filter the name or username of the company or customer who made this transaction , or the transactiosn that received from the searched word

actually I have override the Transaction Model and I added these 2 relations


  public  function deposit_transfer(){
        return $this->hasOne(\Bavix\Wallet\Models\Transfer::class,"deposit_id","id")->withoutGlobalScope("company_id");
     }
     public  function withdraw_transfer(){
         return $this->hasOne(TransferOver::class,"withdraw_id","id")->withoutGlobalScope("company_id");
     }

now when I am retrieving the data using this query
$queryBuilder= Transaction::query()->with(["deposit_transfer","deposit_transfer.from","deposit_transfer.from.holder","withdraw_transfer","withdraw_transfer.to","withdraw_transfer.to.wallet.holder"])-> withoutGlobalScope('company_id');

and this is how I am showing the name or username(in case of subscriber) of the owner of the transaction using yajra datatable

   ->addColumn('username', function ($data) {

                $type=$data->type;
                if($type=="deposit")
                {
                    $relation=$data->deposit_transfer;

                    if($relation->from->holder_type==Revenue::class){
                        if(isset($relation->from->holder->invoice->customer->username ))
                            return  "<a  href='/ISP/userview/".$relation->from->holder->invoice->customer->id."'>".$relation->from->holder->invoice->customer->username."</a>" ;

                    }
                    elseif($relation->from->holder_type==Invoice::class){
                        if(isset($relation->from->holder->customer->username ))
                            return  "<a  href='/ISP/userview/".$relation->from->holder->customer->id."'>".$relation->from->holder->customer->username."</a>" ;

                    }
                   else if($relation->to_type==Company::class){
                        if(isset($relation->from->holder->name ))
                            return  $relation->from->holder->name??"N\a" ;
                        return  $data->company->name;

                    }
                   else if($relation->from->holder_type==Totalrevenue::class){

                       return  $data->company->name;

                   }

                }


            elseif($type=="withdraw"){
                    $relation=$data->withdraw_transfer;

                    if(isset($relation)&&$relation->from_type ==Wallet::class &&$relation->to_type==Invoice::class){

                        if(isset($relation->to->customer->username ))
                            return  "<a  href='/ISP/userview/".$relation->to->customer->username."'>".$relation->to->customer->username."</a>" ;

                    }
                elseif(isset($relation)&&$relation->from_type ==Wallet::class &&$relation->to_type==Revenue::class){

                    if(isset($relation->to->invoice->customer->username ))
                        return  "<a  href='/ISP/userview/".$relation->to->invoice->customer->username."'>".$relation->to->invoice->customer->username."</a>" ;

                }
                    else{
                        if($data->payable_type==Company::class)
                        {
                            if(isset($relation->to->name))
                                return $relation->to->name??"N\A";
                            return $data->company->name??"N\A";
                        }
                        return "N\A";
                    }
                }

                if($data->to_type =='App\\Models\\Invoice')
                {   if(isset($data->to->customer->username ))
                    return  "<a  href='/ISP/userview/".$data->to->customer->id."'>".$data->to->customer->username."</a>" ;
                    else
                        return "N\a";

                }



            })

the records are coming right without any issue , but I am not able to filter actually
this is my filter code

  ->filterColumn('username', function($query, $keyword) {


                     $query->where(function($q) use ($keyword){
                         return $q->whereHas("withdraw_transfer", function ($q) use ($keyword) {
                             return $q->where('to_type', Invoice::class)->wherehas('to', function ($q) use ($keyword) {
                                 return $q-> wherehas('wallet', function ($q) use ($keyword) {
                                     return $q->where('holder_type', Invoice::class)->wherehas("holder",function($q)use ($keyword){
                                         return $q-> wherehas('customer', function ($q) use ($keyword) {

                                         });
                                     });
                                 });

                             });
                         });
                     });

this is only in case of withdraw , as I am trying with it right now , but it is not working as expected and it return error that saying Revenue not has customer relation , I am not sure why it is trying with revenue model although I am seting the holder type to be invoice .
can u help me please

@starking8b starking8b added the question Further information is requested label Feb 13, 2024
@rez1dent3
Copy link
Member

Hello.
@starking8b Starting with version 9.x I started actively disabling morph in the transfer table. Now the from_type and to_type fields always look at the wallet, always. And in version 11.x, both fields will be removed.

This change is directly related to the addition of support for uuid identifiers to the project.

For you, the connection should now be like this.

$transfer->to->holder;
$transfer->from->holder;

Where holder will be the owner of the wallet.

Upgrade guide:
https://bavix.github.io/laravel-wallet/#/upgrade-guide?id=_81x-%e2%86%92-90x

@rez1dent3
Copy link
Member

rez1dent3 commented Feb 13, 2024

@starking8b I think, you can use https://laravel.com/docs/10.x/eloquent-relationships#has-many-through

UPD: will not work

@starking8b
Copy link
Author

I am not sure , even when I am flowing upgrade guide and upgrading to [6.2.4] I have a lot of issues , which is happening while making transfer or pay , like this error
local.ERROR: Bavix\Wallet\Services\CastService::getWallet(): Argument #1 ($object) must be of type Bavix\Wallet\Interfaces\Wallet, null given,
I followed the guide many times but it is not working , actually I need to upgrade to 7 version as I need to work with credit but I am not able

@starking8b
Copy link
Author

hello, I have another issue , actually after I upgrade and no issue come out , when I am using $user->pay($item) I see the transactiosns has been done in database , but no effect to the balance , the balance remain same when I am using pay / safepay

@rez1dent3
Copy link
Member

@starking8b I thought you were already on more modern versions of the package.

local.ERROR: Bavix\Wallet\Services\CastService::getWallet(): Argument #1 ($object) must be of type Bavix\Wallet\Interfaces\Wallet, null given,

This is too small a part of the trace to understand the reason from it.

hello, I have another issue , actually after I upgrade and no issue come out , when I am using $user->pay($item) I see the transactiosns has been done in database , but no effect to the balance , the balance remain same when I am using pay / safepay

Please attach a code example. Details are very important. For example, support for laravel transactions appeared only in laravel-wallet 9.6.


The more information, the more accurate the answer will be.

I need from you:

  • php version;
  • database + version;
  • what cache and lock you use with your wallet;
  • laravel version;
  • full error trace;

Because this is version 6.x, then are you using bavix/laravel-wallet-vacuum or not?

@starking8b
Copy link
Author

starking8b commented Feb 15, 2024

actually in config/wallet.php if I use Wallet::class as a model I get that error but when I am override the wallet using this model

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Bavix\Wallet\Models\Wallet as ModelsWallet;
class Wallet extends ModelsWallet
{
    public function holder(): MorphTo
    {
         return $this->morphTo()->withoutGlobalScope('company_id');
    }
}

where I added the holder relation the cast error is not shown , when I am using it in the wallet.php file like this

 'wallet' => [
        'table' => 'wallets',
        'model' => \App\Models\Wallet::class,
        'creating' => [],
        'default' => [
            'name' => 'Default Wallet',
            'slug' => 'default',
            'meta' => [],
        ],
    ],

this is the exception that I had

[2024-02-15 13:27:34] production.INFO: TypeError: Bavix\Wallet\Services\CastService::getModel(): Argument #1 ($object) must be of type object, null given, called in /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Services/CastService.php on line 56 and defined in /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Services/CastService.php:59
Stack trace:
#0 /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Services/CastService.php(56): Bavix\Wallet\Services\CastService->getModel()
#1 /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Services/PrepareService.php(69): Bavix\Wallet\Services\CastService->getHolder()
#2 /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Services/PrepareService.php(98): Bavix\Wallet\Services\PrepareService->withdraw()
#3 /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Traits/CartPay.php(122): Bavix\Wallet\Services\PrepareService->transferLazy()
#4 /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Internal/Service/DatabaseService.php(43): App\Models\Company->Bavix\Wallet\Traits\{closure}()
#5 /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Services/AtomicService.php(45): Bavix\Wallet\Internal\Service\DatabaseService->transaction()
#6 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Cache/Lock.php(126): Bavix\Wallet\Services\AtomicService->Bavix\Wallet\Services\{closure}()
#7 /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Internal/Service/LockService.php(34): Illuminate\Cache\Lock->block()
#8 /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Services/AtomicService.php(46): Bavix\Wallet\Internal\Service\LockService->block()
#9 /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Traits/CartPay.php(131): Bavix\Wallet\Services\AtomicService->block()
#10 /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Traits/CanPay.php(57): App\Models\Company->payCart()
#11 /var/www/html/NewISPCRM/ispcrm/app/Traits/HasPayment.php(39): App\Models\Company->pay()
#12 /var/www/html/NewISPCRM/ispcrm/app/Traits/hasSubscription.php(73): App\Models\Invoice->make_payment()
#13 /var/www/html/NewISPCRM/ispcrm/app/Http/Controllers/ISPUsersController.php(2340): App\Models\Subscriber->RenewCustomer()
#14 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\Http\Controllers\ISPUsersController->saverenewvalue()
#15 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction()
#16 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Route.php(262): Illuminate\Routing\ControllerDispatcher->dispatch()
#17 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\Routing\Route->runController()
#18 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Router.php(721): Illuminate\Routing\Route->run()
#19 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#20 /var/www/html/NewISPCRM/ispcrm/app/Http/Middleware/CheckISPvalidation.php(52): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#21 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\CheckISPvalidation->handle()
#22 /var/www/html/NewISPCRM/ispcrm/vendor/spatie/laravel-permission/src/Middlewares/RoleOrPermissionMiddleware.php(25): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#23 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Spatie\Permission\Middlewares\RoleOrPermissionMiddleware->handle()
#24 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Auth/Middleware/EnsureEmailIsVerified.php(30): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#25 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Auth\Middleware\EnsureEmailIsVerified->handle()
#26 /var/www/html/NewISPCRM/ispcrm/app/Http/Middleware/CheckExpiration.php(42): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#27 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\CheckExpiration->handle()
#28 /var/www/html/NewISPCRM/ispcrm/app/Http/Middleware/Tenancy.php(43): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#29 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\Tenancy->handle()
#30 /var/www/html/NewISPCRM/ispcrm/vendor/dipeshsukhia/laravel-html-minify/src/Middleware/LaravelMinifyHtml.php(15): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#31 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): DipeshSukhia\LaravelHtmlMinify\Middleware\LaravelMinifyHtml->handle()
#32 /var/www/html/NewISPCRM/ispcrm/app/Http/Middleware/ChangePassword.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#33 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\ChangePassword->handle()
#34 /var/www/html/NewISPCRM/ispcrm/app/Http/Middleware/Banned.php(30): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#35 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\Banned->handle()
#36 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#37 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Routing\Middleware\SubstituteBindings->handle()
#38 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(44): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#39 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Auth\Middleware\Authenticate->handle()
#40 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(78): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#41 /var/www/html/NewISPCRM/ispcrm/app/Http/Middleware/VerifyCsrfToken.php(48): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle()
#42 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\VerifyCsrfToken->handle()
#43 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#44 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\View\Middleware\ShareErrorsFromSession->handle()
#45 /var/www/html/NewISPCRM/ispcrm/app/Http/Middleware/LocaleMiddleware.php(26): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#46 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\LocaleMiddleware->handle()
#47 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#48 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession->handleStatefulRequest()
#49 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Session\Middleware\StartSession->handle()
#50 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#51 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle()
#52 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#53 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Router.php(723): Illuminate\Pipeline\Pipeline->then()
#54 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Router.php(698): Illuminate\Routing\Router->runRouteWithinStack()
#55 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Router.php(662): Illuminate\Routing\Router->runRoute()
#56 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Router.php(651): Illuminate\Routing\Router->dispatchToRoute()
#57 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(167): Illuminate\Routing\Router->dispatch()
#58 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()
#59 /var/www/html/NewISPCRM/ispcrm/vendor/livewire/livewire/src/DisableBrowserCache.php(19): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#60 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Livewire\DisableBrowserCache->handle()
#61 /var/www/html/NewISPCRM/ispcrm/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(66): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#62 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Barryvdh\Debugbar\Middleware\InjectDebugbar->handle()
#63 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#64 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#65 /var/www/html/NewISPCRM/ispcrm/vendor/dipeshsukhia/laravel-html-minify/src/Middleware/LaravelMinifyHtml.php(15): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#66 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): DipeshSukhia\LaravelHtmlMinify\Middleware\LaravelMinifyHtml->handle()
#67 /var/www/html/NewISPCRM/ispcrm/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#68 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fideloper\Proxy\TrustProxies->handle()
#69 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#70 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#71 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull->handle()
#72 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#73 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#74 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TrimStrings->handle()
#75 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#76 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle()
#77 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#78 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle()
#79 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#80 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(142): Illuminate\Pipeline\Pipeline->then()
#81 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(111): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()
#82 /var/www/html/NewISPCRM/ispcrm/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle()
#83 {main}

Next Bavix\Wallet\Internal\Exceptions\TransactionFailedException: Transaction failed in /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Internal/Service/DatabaseService.php:65
Stack trace:
#0 /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Services/AtomicService.php(45): Bavix\Wallet\Internal\Service\DatabaseService->transaction()
#1 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Cache/Lock.php(126): Bavix\Wallet\Services\AtomicService->Bavix\Wallet\Services\{closure}()
#2 /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Internal/Service/LockService.php(34): Illuminate\Cache\Lock->block()
#3 /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Services/AtomicService.php(46): Bavix\Wallet\Internal\Service\LockService->block()
#4 /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Traits/CartPay.php(131): Bavix\Wallet\Services\AtomicService->block()
#5 /var/www/html/NewISPCRM/ispcrm/vendor/bavix/laravel-wallet/src/Traits/CanPay.php(57): App\Models\Company->payCart()
#6 /var/www/html/NewISPCRM/ispcrm/app/Traits/HasPayment.php(39): App\Models\Company->pay()
#7 /var/www/html/NewISPCRM/ispcrm/app/Traits/hasSubscription.php(73): App\Models\Invoice->make_payment()
#8 /var/www/html/NewISPCRM/ispcrm/app/Http/Controllers/ISPUsersController.php(2340): App\Models\Subscriber->RenewCustomer()
#9 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\Http\Controllers\ISPUsersController->saverenewvalue()
#10 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction()
#11 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Route.php(262): Illuminate\Routing\ControllerDispatcher->dispatch()
#12 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\Routing\Route->runController()
#13 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Router.php(721): Illuminate\Routing\Route->run()
#14 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#15 /var/www/html/NewISPCRM/ispcrm/app/Http/Middleware/CheckISPvalidation.php(52): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#16 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\CheckISPvalidation->handle()
#17 /var/www/html/NewISPCRM/ispcrm/vendor/spatie/laravel-permission/src/Middlewares/RoleOrPermissionMiddleware.php(25): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#18 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Spatie\Permission\Middlewares\RoleOrPermissionMiddleware->handle()
#19 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Auth/Middleware/EnsureEmailIsVerified.php(30): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#20 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Auth\Middleware\EnsureEmailIsVerified->handle()
#21 /var/www/html/NewISPCRM/ispcrm/app/Http/Middleware/CheckExpiration.php(42): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#22 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\CheckExpiration->handle()
#23 /var/www/html/NewISPCRM/ispcrm/app/Http/Middleware/Tenancy.php(43): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#24 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\Tenancy->handle()
#25 /var/www/html/NewISPCRM/ispcrm/vendor/dipeshsukhia/laravel-html-minify/src/Middleware/LaravelMinifyHtml.php(15): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#26 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): DipeshSukhia\LaravelHtmlMinify\Middleware\LaravelMinifyHtml->handle()
#27 /var/www/html/NewISPCRM/ispcrm/app/Http/Middleware/ChangePassword.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#28 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\ChangePassword->handle()
#29 /var/www/html/NewISPCRM/ispcrm/app/Http/Middleware/Banned.php(30): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#30 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\Banned->handle()
#31 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#32 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Routing\Middleware\SubstituteBindings->handle()
#33 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(44): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#34 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Auth\Middleware\Authenticate->handle()
#35 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(78): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#36 /var/www/html/NewISPCRM/ispcrm/app/Http/Middleware/VerifyCsrfToken.php(48): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle()
#37 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\VerifyCsrfToken->handle()
#38 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#39 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\View\Middleware\ShareErrorsFromSession->handle()
#40 /var/www/html/NewISPCRM/ispcrm/app/Http/Middleware/LocaleMiddleware.php(26): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#41 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\LocaleMiddleware->handle()
#42 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#43 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession->handleStatefulRequest()
#44 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Session\Middleware\StartSession->handle()
#45 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#46 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle()
#47 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#48 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Router.php(723): Illuminate\Pipeline\Pipeline->then()
#49 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Router.php(698): Illuminate\Routing\Router->runRouteWithinStack()
#50 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Router.php(662): Illuminate\Routing\Router->runRoute()
#51 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Routing/Router.php(651): Illuminate\Routing\Router->dispatchToRoute()
#52 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(167): Illuminate\Routing\Router->dispatch()
#53 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()
#54 /var/www/html/NewISPCRM/ispcrm/vendor/livewire/livewire/src/DisableBrowserCache.php(19): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#55 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Livewire\DisableBrowserCache->handle()
#56 /var/www/html/NewISPCRM/ispcrm/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(66): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#57 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Barryvdh\Debugbar\Middleware\InjectDebugbar->handle()
#58 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#59 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#60 /var/www/html/NewISPCRM/ispcrm/vendor/dipeshsukhia/laravel-html-minify/src/Middleware/LaravelMinifyHtml.php(15): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#61 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): DipeshSukhia\LaravelHtmlMinify\Middleware\LaravelMinifyHtml->handle()
#62 /var/www/html/NewISPCRM/ispcrm/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#63 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fideloper\Proxy\TrustProxies->handle()
#64 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#65 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#66 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull->handle()
#67 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#68 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#69 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TrimStrings->handle()
#70 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#71 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle()
#72 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#73 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle()
#74 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#75 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(142): Illuminate\Pipeline\Pipeline->then()
#76 /var/www/html/NewISPCRM/ispcrm/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(111): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()
#77 /var/www/html/NewISPCRM/ispcrm/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle()

but after that this code is working
$res = $current_company->forceTransferFloat($company, $limit, ['method' => $method, 'description' => 'Add limit', 'action' => 'Add limit', 'old_balance' => $current_company->balance, "to_company_old_balance" => $to_company_old_balance, 'payment_method' => $method, 'reference_no' => $reference_no, 'comment' => $comment, 'type' => 'balance', "payment_status" => $payment_collected, "added_by" => auth()->user()->id]);
and I see the limit is added and the wallet is changed , this is my company class looks like

class Company extends Model implements   Wallet,Customer,HasMedia,WalletFloat
{   use BelongsToTenants;
    use InteractsWithMedia;

    use CanPayFloat;
    use SoftDeletes;
    use \RecursiveRelationships\Traits\HasRecursiveRelationships;
    use HasAddress;
    use HasContact;
    use HasRazorpay;
    use HasWallet;
    use HasWalletFloat;
    use HasInvoiceNumber;
}

the parent company can add/Reduce Limit to Child company , and the balance get effected , but this code is not effecting the balance
$company->pay($invoice);
and this is my Invoice model looks like

class Invoice extends Model  implements Wallet, Product,ReportInterface,WalletFloat
{    use SoftDeletes;
    use BelongsToTenants;
    use HasFactory;
  // use HasTransactions;
    use LogsActivity;
    use HasInvoiceNumber;
     use HasWallet;
     use HasReport;
     use HasPayment;
     use HasWalletFloat;
  public function getAmountProduct(Customer $customer)
    {
        
        return   \config('wallet.package.coefficient') * $this->total;
    }
} 
of course  I  added  that value in the config like this 
  'package' => [

        'coefficient' => 100.,

    ],

and even I added credit to one company using this code

$meta=["credit"=>1000];
$wallet=$company->wallt;
$wallet->meta=$meta;
$wallet->save();

but when I am doing pay function the credit is not reduced it still same

I am using

php 8.1
laravel 8
10.3.39-MariaDB as mysql database
'cache' => ['driver' => 'array'],

'lock' => [
    'driver' => 'array',
    'seconds' => 1,
],

I am not using laravel-wallet-vacuum

@starking8b
Copy link
Author

Upd : now I am using Wallet 7.x after I upgraded from 6.1 to 6.2.4 then to 7.x

@starking8b
Copy link
Author

starking8b commented Feb 15, 2024

I noticed somethings else
this is my code to make payment

  \Log::info($company->balanceFloat);
                if ($balance >= $price  ) {

                    $company->pay($invoice);

                    if ((bool)$company->paid($invoice)) {
                        $company->wallet->refreshBalance();
                        \Log::info($company->balanceFloat);
                        $company->wallet->refreshBalance();
                        $reseller = ResellerPlan::query()->withoutGlobalScope('company_id')->where('plan_id', $plan->id)->where('reseller_id', $company->id)->first();
                        $this->calculateRevenue($reseller,$invoice);
                        return true;
                    }
                }

and this is what I have in database
+----+-------------------------+-----------+----------------+---------+--------------------------------------+-------------+------+----------+----------------+---------------------+---------------------+

| id | holder_type             | holder_id | name           | slug    | uuid                                 | description | meta | balance  | decimal_places | created_at          | updated_at          |
+----+-------------------------+-----------+----------------+---------+--------------------------------------+-------------+------+----------+----------------+---------------------+---------------------+
|  2 | App\Models\Company      |         4 | Default Wallet | default | 28f3999b-96de-4076-8218-0c28f17c2741 | NULL        | []   |    74351 |              2 | 2023-12-13 13:57:07 | 2024-02-15 13:49:58 |

as u see the balance is 74351 when I making payment the log showing me this balance

744.51

and after the payment is done I get this balance which i in negative after making some payment which is right actually

-2348.61

but when I am trying to get the balance every time it showing the 744.51 I don't understand all the transactions in my database has confirmed and it has value 1

@starking8b
Copy link
Author

after a lot of trying now I upgraded my laravel to version 9 , and updated wallet package to version 9.x as well , it seems working well , but credit I don't think it is working , I added credit to the company , but I am not able to pay
Bavix\Wallet\Exceptions\InsufficientFunds: Insufficient funds

@rez1dent3
Copy link
Member

rez1dent3 commented Feb 15, 2024

So, after your trace and metadata, everything has changed a lot. I would like to immediately note that I tested integration with mariadb starting from 10.5, and laravel-wallet ^11.0 supports mariadb only from version 10.10+, because The Laravel core is changing a lot. More details here: laravel/framework#48455


Total what you have now:
php 8.1;
laravel 9;
MariaDB 10.3.39 (you need to update to at least 10.5, and preferably to 10.10);
laravel-wallet 9.6.3
lock array
cache array


Let's recalculate the balance of all wallets. You can do this using the library:

composer require bavix/laravel-wallet-warmup:2.2.0

Next, let's run the recalculation command.

./artisan wallet:warm-up

Now a little about your package setup. I highly recommend at least setting up redis. You may often catch a race condition.


I noticed that you set the limit =1000 in the credit field, but the coefficient for you (your business logic) is set to 100. Considering your business model, 1000/100 = 10.00.

Conventionally, you have issued a credit limit of 10.


I would start from decimal places, you clearly have it =2. This means that for *float methods the shift is two decimal places.

@rez1dent3
Copy link
Member

Oh, that's right. Don't forget to run the command

artisan bx:transfer:fix

@rez1dent3
Copy link
Member

Today or tomorrow I definitely won’t have time to prepare a test environment for myself to test your case. But I'll try this over the weekend if you haven't figured out your problems yet.

@starking8b
Copy link
Author

many thanks for your help , I ll try to figure it out ,if not success I will wait for your help ,

@starking8b
Copy link
Author

starking8b commented Feb 15, 2024

oh without understanding the balance issue has been solved :) I don't know how , but now when I am paying it decreesing the balance .
any way , right now the most important things is the filter ,till now I am not able to filter in datatable , global search , I don't know if you have any idea that help me with the filter , as I mentioned upove , my system has company, subscriber , and revenue , actually I am making transfer between all of these models , so when I want to filter , I want to get the holder ,and access the attribute that I need for some reasons I am not able specially in withdraw transfer this is my filter code


filterColumn('username', function($query, $keyword) {
                                           $query ->where(function($q) use($keyword){
                                 return $q->whereHas("deposit_transfer", function ($q) use ($keyword) {
                    return $q->wherehas('from',function($q)use ($keyword){
                        return $q->wherehas("holder",function($q)use ($keyword){
                           return $q->where('name','like',"%".$keyword."%");
                        });
                        });
                      }); })->orwhere(function($q) use($keyword){
                                     return $q->whereHas("withdraw_transfer", function ($q) use ($keyword) {
//                                         return $q->where( function($q)use ($keyword){
                                             return $q->wherehas('to',function($q)use ($keyword){
                                                 return $q->where("holder_type",Invoice::class)->wherehas("holder",function($q)use($keyword){
                                                     return $q->wherehas("customer",function($q)use ($keyword){

                                                     });
                                                 });
//                                             });

                                         });
                                     });
                     });

            })

although i am using where("holder_type",Invoice::class) but it is trying to search in other model like revenue which i don't want ,and this is my data

{
"id": 21,
"payable_type": "App\\Models\\Company",
"payable_id": 5,
"wallet_id": 3,
"type": "withdraw",
"amount": "₹-799.00",
"confirmed": true,
"meta": {
"type": "",
"action": "",
"method": "",
"comment": "",
"description": "  Payment",
"old_balance": 250000,
"reference_no": "",
"payment_method": "",
"to_company_old_balance": 250000
},
"uuid": "692a9997-e9b5-4d08-9847-9e82d99bc352",
"created_at": "2023-12-15 08:52:51",
"updated_at": "2024-02-01T08:10:07.000000Z",
"payment_status": 0,
"deposit_transfer": null,
"withdraw_transfer": {
"id": 11,
"from_type": "Bavix\\Wallet\\Models\\Wallet",
"from_id": 3,
"to_type": "Bavix\\Wallet\\Models\\Wallet",
"to_id": 18,
"status": "paid",
"status_last": null,
"deposit_id": 22,
"withdraw_id": 21,
"discount": "0",
"fee": "0",
"uuid": "7408a3e3-7b2f-4c52-8283-c89196dfc161",
"created_at": "2023-12-15T03:22:51.000000Z",
"updated_at": "2024-02-15T11:15:50.000000Z",
"to": {
"id": 18,
"holder_type": "App\\Models\\Invoice",
"holder_id": 7,
"name": "Default Wallet",
"slug": "default",
"uuid": "8ecc95a4-9477-4b71-8cde-4896869a57dc",
"description": null,
"meta": [],
"balance": "79900",
"decimal_places": 2,
"created_at": "2023-12-15T03:22:51.000000Z",
"updated_at": "2024-02-14T13:45:36.000000Z",
"holder": {
"id": 7,
"customer_id": 52,
"number": "KL000000001",
"date_created": "2023-12-15",
"real_create_datetime": "2023-12-15 11:22:51",
"date_payment": "2023-12-25",
"total": "799.0016",
"status": "not_paid",
"payment_id": null,
"is_sent": "0",
"payd_from_deposit": "0",
"use_transactions": "1",
"note": "Renew user&#039;s Service",
"memo": "Renew user&#039;s Service",
"added_by": null,
"added_by_id": 29,
"deleted": "0",
"created_at": "2023-12-15T05:52:51.000000Z",
"updated_at": "2023-12-15T09:44:48.000000Z",
"deleted_at": null,
"plan_id": 21,
"paid_by": 29,
"company_id": 5,
"is_gst": false,
"next_invoice": "KL000000002",
"creditnote_id": null,
"invoice_type": "invoice",
"invoice_id": null
}
}
},
"revenuetype": "<div class='badge badge-info'>  Payment</div>",
"username": "<a  href='/ISP/userview/a@aswin'>a@aswin</a>",
"plan": "N\\a",
"old_balance": "₹2500.00",
"new_balance": "₹1701.00",
"deposit": "₹0.00",
"withdraw": "₹-799.00",
"paid_by": null,
"revenue": "₹0.00",
"parent_revenue": "₹0.00"
},

as u see the holder is Invoice , but I get error that saying the Revenue::customer relation is not exists

@rez1dent3
Copy link
Member

Example of filtering by name:

$filter = static fn (Buyer $buyer): Builder => Transfer::query()
->whereHas(
'from',
fn (Builder $q) => $q->whereHas(
'holder',
fn (Builder $q) => $q->where('name', $buyer->name),
)
);
$fromFiltered = $filter($from)->get()->all();
self::assertCount(3, $fromFiltered);
$toFiltered = $filter($to)->get()->all();
self::assertCount(1, $toFiltered);

By analogy, you can make a similar filter for to or any other field.

BUT I highly do not recommend doing such complex filters in the database. It is better to describe the index and do the search through elasticsearch, for example.

@rez1dent3
Copy link
Member

Did you succeed?

Copy link

This issue is stale because it has been open 7 days with no activity.

@github-actions github-actions bot added the Stale label Feb 25, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 28, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

2 participants