Jump to content

Get/Fetch Client Data by Ajax Request


Blesta Addons

Recommended Posts

Hello All .

@Licensecart has request me to do a simple plugin to fetch client data and include it in your Html Template.

The Plugin Is Available in Github https://github.com/Blesta-Addons/Client_Data

Blesta Plugin That Allow Dev/Themers Get Client Data Info As Json Response , then they can use it in their Template or Plugin .

This Plugin didn't need install, just upload the folder client_data to plugins and you are ready to go .

Not all request should be Done Via Ajax , a direct call will return a blank page .

Example of Requests :

1 - For Tickets, the last element is the Tickets status

Get CLient's Open Tickets

http://your_domain.com/blesta_dir/plugin/client_data/client_main/count_tickets/open

Get CLient's Closed Tickets

http://your_domain.com/blesta_dir/plugin/client_data/client_main/count_tickets/closed

2 - For Services, the last element is the Service status

Get CLient's Active Services

http://your_domain.com/blesta_dir/plugin/client_data/client_main/count_services/active

Get CLient's Suspended Services

http://your_domain.com/blesta_dir/plugin/client_data/client_main/count_services/suspended

3 - For Invoices, the last element is the Invoices status

Get CLient's Open Invoices

http://your_domain.com/blesta_dir/plugin/client_data/client_main/count_invoices/open

Get CLient's Vioded Invoices

http://your_domain.com/blesta_dir/plugin/client_data/client_main/count_invoices/vioded

To get the info by Ajax request in template us this code

		<?php
		$this->Javascript->setInline('
			$(document).ready(function() {
				fetchInvoices("open");
			});
			
			function fetchInvoices(status) {
				$(this).blestaRequest("GET", "' . $this->Html->safe($this->base_uri . "plugin/client_data/client_main/count_invoices/") . '" + status, null, function(data) {
					if (data)
						$("#my_div_id_to_replace").html(data);
				},
				null,
				{dataType:"json"});
			}
		');
		?>

To explain the code , you need to change the url and the div to put the requested data .

Link to comment
Share on other sites

23 minutes ago, naja7host said:

ahhh, errors in link, client_main instead main .

Tried both mate:

Code:

<?php
$this->Javascript->setInline('
    			$(document).ready(function() {
    				fetchTicketsOpen("open");
    			});

    			function fetchTicketsOpen(status) {
    				$(this).blestaRequest("GET", "' . $this->Html->safe($this->base_uri . "plugin/client_data/client_main/count_tickets/") . '" + status, null, function(data) {
    					if (data)
    						$(".count_ticket_open").html(data);
    				},
    				null,
    				{dataType:"json"});
    			}
    		');

    		$this->Javascript->setInline('
    			$(document).ready(function() {
    				fetchTicketsClosed("closed");
    			});

    			function fetchTicketsClosed(status) {
    				$(this).blestaRequest("GET", "' . $this->Html->safe($this->base_uri . "plugin/client_data/client_main/count_tickets/") . '" + status, null, function(data) {
    					if (data)
    						$(".count_ticket_closed").html(data);
    				},
    				null,
    				{dataType:"json"});
    			}
    		');
?>

Html:

<span class="count_ticket_open">0</span>/<span class="count_ticket_closed">0</span>

Both show 0/0 should be 0/11

Link to comment
Share on other sites

On 2016. 10. 02. at 2:46 PM, naja7host said:

i have tested the plugin in v4, is working, this related only to v3 .

Hello :)

The invoices are working but how to shoe the active services? I tried to figure out but none of them worked for me. Here is the code:

Quote

    <?php
        $this->Javascript->setInline('
            $(document).ready(function() {
                fetchInvoices("open");
            });
            
            function fetchInvoices(status) {
                $(this).blestaRequest("GET", "' . $this->Html->safe($this->base_uri . "plugin/client_data/client_main/count_invoices/") . '" + status, null, function(data) {
                    if (data)
                        $(".count_invoices").html(data);
                },
                null,
                {dataType:"json"});
            }
        ');
        $this->Javascript->setInline('
            $(document).ready(function() {
                fetchServices("active");
            });
            
            function fetchServices(status) {
                $(this).blestaRequest("GET", "' . $this->Html->safe($this->base_uri . "plugin/client_data/client_main/count_services/active") . '" + status, null, function(data) {
                    if (data)
                        $(".count_active_services").html(data);
                },
                null,
                {dataType:"json"});
            }
        ');
        ?>

Whats wrong with the services:)?

Inovices: <span class="count_invoices">0</span>

Services: <span class="count_active_services">0</span>

Link to comment
Share on other sites

  • 2 weeks later...

Is there something wrong with my code?

Did not show any value. But invoices and other works smoothly

Div call

<div class="count-active-service"></div>

 

        $this->Javascript->setInline('
            $(document).ready(function() {
                fetchServices("active");
            });
            
            function fetchServices(status) {
                $(this).blestaRequest("GET", "' . $this->Html->safe($this->base_uri . "plugin/client_data/client_main/count_services") . '" + status, null, function(data) {
                    if (data)
                        $(".count-active-service").html(data);
                },
                null,
                {dataType:"json"});
            }
        ');

 

Link to comment
Share on other sites

  • 9 months later...

 <li class="dropdown messages-menu">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                <i class="fa fa-envelope"></i>
                                <span class="label label-success">0</span>
                            </a>
                        </li>
                        <!-- Notifications: style can be found in dropdown.less -->
                        <li class="dropdown notifications-menu">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                <i class="fa fa-warning"></i>
                                <span class="label label-warning">0</span>
                            </a> 
                        </li>
                        <!-- Tasks: style can be found in dropdown.less -->
                        <li class="dropdown tasks-menu">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                                <i class="fa fa-tasks"></i>
                                <span class="label label-danger">0</span>
                            </a>
                        </li>

 

 

I want to put the code to count the services, ticket, domain etc. how can I do this???

   this is your adminLTE template @Blesta Addons

Link to comment
Share on other sites

  • 1 year later...

any way to apply this to the quotes ?

I tried to write this to the controller but still doesn't work

	
	/**
	 * Get Quotes count
	 */
	public function count_quotes() 
	{
		// Ensure a valid Status
		if (isset($this->get[0])) {
			$status = $this->get[0];
		} else {
			$status = "open";
		}

		if ($this->isAjax()) {
			// Load Model Only When we Need it !!!
			$this->uses(["QuotesSystem"]);
			
			$response = $this->QuotesSystem->getStatusCount($this->client_id, $status);
			// JSON encode the AJAX response
			$this->outputAsJson($response);
			return false;		
		}
		
		return false;
	}
	

everything else works

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.

Guest
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.

Loading...
×
×
  • Create New...