Jump to content

Exibir créditos disponíveis em vários locais


gsouza

Recommended Posts

Olá Pessoal, boa noite.

Queria tirar uma dúvida.

Encontrei este tópico

Me ajudou muito, porem eu queria inserir em mais um local e não consegui =/

Podem me ajudar ?

Quero inserir esta Hook que o amigo criou tanto na área inicial, quanto na aba minhas faturas.

E gostaria de dois pequenos ajustes.
O primeiro é que se o credito for maior que zero , mude a frase e informe por exemplo: Você não possui créditos em sua conta. clique no botão abaixo e adicione um saldo em sua conta!. Algo do tipo.

O segundo é inserir um botão verde para (Adicionar fundos) no fim da guia.
E se possivel deixar o valor atual na área toda assim como este 
http://prntscr.com/kl0icc

Meu código esta assim atualmente.

Agradeço a ajuda.

<?php

use WHMCS\Session;
use WHMCS\Database\Capsule;
use WHMCS\View\Menu\Item as MenuItem;

if (!defined("WHMCS")){
    die("Acesso restrito!");
}

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{

    $idusuario = $_SESSION["uid"];

    foreach (Capsule::table('tblclients')->where([['id','=',$idusuario],])->get() as $clientes) {
        $credito = $clientes->credit;
    }
if ($clientes->credit > 0){
    if (!is_null($primarySidebar->getChild('Client Details'))) {
            
        $saldoConta = $primarySidebar->addChild('Saldo da Conta');
        $saldoConta = $primarySidebar->addChild('Saldo da Conta',
        
        array(
            'icon'  => 'fal fa-donate',
            'order' => 1,
        )
        );

        // Add hours to the panel.
        $saldoConta->addChild('Saldo da Conta')
                    ->setLabel('<p style="float: left; padding: 3px 0px 0px; margin-top: 6px;"><strong> Saldo disponível:</strong></p> <strong style="margin-top: 6px; background-color: #5bc0de; padding: 4px 10px; color: #FFF; float: right; border-radius: 5px;">R$ '.$credito.'</strong>')
                    ->setClass('panel-body clearfix')
                    ->setOrder(101);                
    }
    
}

});


Resultado atual

http://prntscr.com/kl0hy5

o que desejo
http://prntscr.com/kl0i2h

Link to comment
Share on other sites

9 horas atrás, AJ Meireles disse:

Olá,

Há uma outra forma de obter o saldo do cliente afim de evitar o uso da consulta:

GLOBAL $smarty;    
$VariavelQualquer = $smarty->getVariable('clientsstats')->value['creditbalance'];

@AJ Meireles bom dia.
Agradeço a informação, vou utilizar neste hook

Link to comment
Share on other sites

Segue o Hook que usamos aqui.

o que ele faz:

- Mostra na página inicial e páginas de faturamento

- Caso o cliente não possua crédito o mesmo é ocultado

 

Espero ter ajudado!

 

<?php

/**
 * Display Client's Credit Balance in Client Area
 *
 * @author WHMCMS
 * @link   www.whmcms.com
 * @since  WHMCS v6.0.0+
 */

use WHMCS\View\Menu\Item as MenuItem;
use Illuminate\Database\Capsule\Manager as Capsule;

# Add Balance To Sidebar
add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $primarySidebar){

    $filename = APP::getCurrentFileName();

    $client = Menu::context("client");

    $clientid = (int) $client->id;
    $action = $_GET['action'];
    $allowed = array('invoices', 'quotes', 'masspay', 'addfunds','');

    if ($filename!=='clientarea' || $clientid===0 || !in_array($action,$allowed)){
        return;
    }
    if ($client->credit <= 0.00) { return; }
	

    $primarySidebar->addChild('Client-Balance', array(
        'label' => "Crédito disponível",
        'uri' => '#',
        'order' => '1',
        'icon' => 'fa-money'
    ));
    
    # Get Currency
    $getCurrency = Capsule::table('tblcurrencies')->where('id', $client->currency)->get();
    
    # Retrieve the panel we just created.
    $balancePanel = $primarySidebar->getChild('Client-Balance');
    
    // Move the panel to the end of the sorting order so it's always displayed
    // as the last panel in the sidebar.
    $balancePanel->moveToBack();
    $balancePanel->setOrder(0);
    
    # Add Balance.
    $balancePanel->addChild('balance-amount', array(
        'uri' => 'clientarea.php?action=addfunds',
        'label' => '<h4 style="text-align:center;">'.$getCurrency['0']->prefix.$client->credit.' '. $getCurrency['0']->suffix.'</h4>',
        'order' => 1
    ));
    
    $balancePanel->setFooterHtml(
        '<a href="clientarea.php?action=addfunds" class="btn btn-success btn-sm btn-block">
            <i class="fa fa-plus"></i> Adicionar fundos
        </a>'
    );

});

 

3 minutos atrás, jerenc disse:

Segue o Hook que usamos aqui.

o que ele faz:

- Mostra na página inicial e páginas de faturamento

- Caso o cliente não possua crédito o mesmo é ocultado

 

Espero ter ajudado!

 


<?php

/**
 * Display Client's Credit Balance in Client Area
 *
 * @author WHMCMS
 * @link   www.whmcms.com
 * @since  WHMCS v6.0.0+
 */

use WHMCS\View\Menu\Item as MenuItem;
use Illuminate\Database\Capsule\Manager as Capsule;

# Add Balance To Sidebar
add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $primarySidebar){

    $filename = APP::getCurrentFileName();

    $client = Menu::context("client");

    $clientid = (int) $client->id;
    $action = $_GET['action'];
    $allowed = array('invoices', 'quotes', 'masspay', 'addfunds','');

    if ($filename!=='clientarea' || $clientid===0 || !in_array($action,$allowed)){
        return;
    }
    if ($client->credit <= 0.00) { return; }
	

    $primarySidebar->addChild('Client-Balance', array(
        'label' => "Crédito disponível",
        'uri' => '#',
        'order' => '1',
        'icon' => 'fa-money'
    ));
    
    # Get Currency
    $getCurrency = Capsule::table('tblcurrencies')->where('id', $client->currency)->get();
    
    # Retrieve the panel we just created.
    $balancePanel = $primarySidebar->getChild('Client-Balance');
    
    // Move the panel to the end of the sorting order so it's always displayed
    // as the last panel in the sidebar.
    $balancePanel->moveToBack();
    $balancePanel->setOrder(0);
    
    # Add Balance.
    $balancePanel->addChild('balance-amount', array(
        'uri' => 'clientarea.php?action=addfunds',
        'label' => '<h4 style="text-align:center;">'.$getCurrency['0']->prefix.$client->credit.' '. $getCurrency['0']->suffix.'</h4>',
        'order' => 1
    ));
    
    $balancePanel->setFooterHtml(
        '<a href="clientarea.php?action=addfunds" class="btn btn-success btn-sm btn-block">
            <i class="fa fa-plus"></i> Adicionar fundos
        </a>'
    );

});

 

Resultado do hook compartilhado acima.

 

credito-whmcs.jpg

Link to comment
Share on other sites

Em 24/08/2018 em 10:06 PM, jerenc disse:

Segue o Hook que usamos aqui.

o que ele faz:

- Mostra na página inicial e páginas de faturamento

- Caso o cliente não possua crédito o mesmo é ocultado

 

Espero ter ajudado!

 


<?php

/**
 * Display Client's Credit Balance in Client Area
 *
 * @author WHMCMS
 * @link   www.whmcms.com
 * @since  WHMCS v6.0.0+
 */

use WHMCS\View\Menu\Item as MenuItem;
use Illuminate\Database\Capsule\Manager as Capsule;

# Add Balance To Sidebar
add_hook('ClientAreaSecondarySidebar', 1, function(MenuItem $primarySidebar){

    $filename = APP::getCurrentFileName();

    $client = Menu::context("client");

    $clientid = (int) $client->id;
    $action = $_GET['action'];
    $allowed = array('invoices', 'quotes', 'masspay', 'addfunds','');

    if ($filename!=='clientarea' || $clientid===0 || !in_array($action,$allowed)){
        return;
    }
    if ($client->credit <= 0.00) { return; }
	

    $primarySidebar->addChild('Client-Balance', array(
        'label' => "Crédito disponível",
        'uri' => '#',
        'order' => '1',
        'icon' => 'fa-money'
    ));
    
    # Get Currency
    $getCurrency = Capsule::table('tblcurrencies')->where('id', $client->currency)->get();
    
    # Retrieve the panel we just created.
    $balancePanel = $primarySidebar->getChild('Client-Balance');
    
    // Move the panel to the end of the sorting order so it's always displayed
    // as the last panel in the sidebar.
    $balancePanel->moveToBack();
    $balancePanel->setOrder(0);
    
    # Add Balance.
    $balancePanel->addChild('balance-amount', array(
        'uri' => 'clientarea.php?action=addfunds',
        'label' => '<h4 style="text-align:center;">'.$getCurrency['0']->prefix.$client->credit.' '. $getCurrency['0']->suffix.'</h4>',
        'order' => 1
    ));
    
    $balancePanel->setFooterHtml(
        '<a href="clientarea.php?action=addfunds" class="btn btn-success btn-sm btn-block">
            <i class="fa fa-plus"></i> Adicionar fundos
        </a>'
    );

});

 

Resultado do hook compartilhado acima.

 

credito-whmcs.jpg

Opa como vai mestre.

 

Funcionou sim.

Estou tentando ajustar para que não seja necessário efetuar consultas em banco

Consegui isso até agora

 

<?php

use WHMCS\Session;
use WHMCS\View\Menu\Item as MenuItem;

if (!defined("WHMCS")){
    die("Acesso restrito!");
}

add_hook('ClientAreaPrimarySidebar', 1, function (MenuItem $primarySidebar)
{

    GLOBAL $smarty;    
    $saldo = $smarty->getVariable('clientsstats')->value['creditbalance'];
    $tesald = preg_replace('/[^\d.]/i', '', $saldo);
if ($tesald > 0){
    if (!is_null($primarySidebar->getChild('Client Details'))) {
            
        $saldoConta = $primarySidebar->addChild('Saldo da Conta');
        $saldoConta = $primarySidebar->addChild('Saldo da Conta',
        
        array(
            'icon'  => 'fal fa-donate',
            'order' => 1,
        )
        );

        // Add hours to the panel.
        $saldoConta->addChild('Saldo da Conta')
                    ->setLabel('<p style="float: left; padding: 3px 0px 0px; margin-top: 6px;"><strong> Saldo disponível:</strong></p> <strong style="margin-top: 6px; background-color: #5bc0de; padding: 4px 10px; color: #FFF; float: right; border-radius: 5px;">'.$saldo.'</strong>')
                    ->setClass('panel-body clearfix')
                    ->setOrder(101);                
    }
    
}

});

image.png.8d98195baadfd37168f0c9faf73b3d9b.png

Este foi o resultado.

Me agradou bastante, porem ainda preciso ajustar o botão de add fundos e que exiba nas abas que o seu esta exibindo.

invoices', 'quotes', 'masspay', 'addfunds

Alguma dica ? 
Estou querendo manter a utilização da função Smarty

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...

Important Information

Do you agree with our terms?