PHP Classes

Laravel Rackbeat Integration Dashboard: Show a dashboard with integrations with Rackbeat

Recommend this page to a friend!
  Info   View files Documentation   View files View files (43)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 21 This week: 1All time: 11,167 This week: 560Up
Version License PHP version Categories
rackbeat-integration 1.0.0MIT/X Consortium ...5PHP 5, E-Commerce, Libraries, Content...
Description 

Author

This package can show a dashboard with integrations with Rackbeat.

It provides a service that a site built with Laravel can use to show a dashboard with information from activity associated with a Rackbeat inventory management account.

Currently, it can display ongoing jobs that belong to a given Rackbeat account.

Innovation Award
PHP Programming Innovation award nominee
May 2022
Number 7
Rackbeat is a Web-based service that customers can use to help them manage the inventory in their warehouse places.

It can manage inventory jobs that are going on in a customer warehouse.

This package can help site owners who are Rackbeat customers quickly see the ongoing jobs in their Rackbeat account in one place on their site.

The package implements a Rackbeat jobs dashboard that developers can add to a site built with Laravel.

Manuel Lemos
Picture of Stefan Ninic
Name: Stefan Ninic is available for providing paid consulting. Contact Stefan Ninic .
Classes: 8 packages by
Country: Bosnia and Herzegovina Bosnia and Herzegovina
Age: ???
All time rank: 37747 in Bosnia and Herzegovina Bosnia and Herzegovina
Week rank: 416 Up1 in Bosnia and Herzegovina Bosnia and Herzegovina Up
Innovation award
Innovation award
Nominee: 5x

Documentation

Laravel Package that allows central monitoring of all Rackbeat integrations

1. composer require kg-bot/rackbeat-integration-dashboard inside your integration project

2. Export configurations php artisan vendor:publish for this package and change your Connection class inside

3. Run migrations

$ php artisan migrate

4. Run php artisan make:dashboard-token

5. Add rackbeat-integration-dashboard/* to your VerifyCsrfToken middleware $except property

This package requires you to use Laravel Jobs for all of your transfers and tasks between Rackbeat and 3rd party integrations.

Each of your Job classes must extend KgBot\RackbeatDashboard\Classes\DashboardJob and it must have special __construct code.

Jobs are not dispatched directly, instead you need to create a new KgBot\RackbeatDashboard\Models\Job model and it will automatically dispatch job using observer.

If you need any special constructor data you must send them in Job model's create() method, they will be serialized and saved in database so you will have to use them as so from you Job's constructor.

Example of this would look like this:

// App\Jobs\Webhooks\TransferInvoice.php

<?php

namespace App\Jobs\Webhooks;

use App\Connection;
use App\Transformers\CustomerTransformer;
use App\Transformers\InvoiceTransformer;
use App\Transformers\SupplierTransformer;
use App\Transformers\TransformerInterface;
use Illuminate\Support\Facades\Log;
use KgBot\Billy\Billy;
use KgBot\Billy\Models\Customer;
use KgBot\Billy\Models\Supplier;
use KgBot\RackbeatDashboard\Classes\DashboardJob;
use KgBot\RackbeatDashboard\Models\Job;
use Rackbeat\Utils\Model;

class TransferInvoice extends DashboardJob
{

	/
	 * @var $conn Connection
	 */
	protected $conn;

	/
	 * @var $type string
	 */
	protected $type;

	/
	 * @var $request array
	 */
	protected $request;

	protected $tries = 1;

	protected $timeout = 0;

	/
	 * Create a new job instance.
	 *
	 * @return void
	 */
	public function __construct( Job $job, $connection, $request, string $type = 'customer' ) {

		parent::__construct( $job );
		$connection = Connection::find( $connection->id );

		$this->conn    = $connection;
		$this->type    = $type;
		$this->request = (array) $request;
	}

	/
	 * Execute the job.
	 *
	 * @return void
	 */
	public function execute() {
		$this->conn->focus();

		// todo Determine is this supplier or customer invoice so we know what integration to check if enabled

		try {

			if ( $this->type === 'customer' ) {
				$invoice = $this->conn->createRackbeatClient()->rb->customer_invoices()->find( $this->request['key'] );

				if ( ! $this->conn->hasDebtorIntegration() ) {
					return;

				}
			} else {

				$invoice = $this->conn->createRackbeatClient()->rb->supplier_invoices()->find( $this->request['key'] );

				if ( ! $this->conn->hasCreditorIntegration() ) {

					return;

				}
			}

			$this->jobModel->updateProgress( 10 );
		} catch ( \Exception $exception ) {

			$this->jobModel->updateProgress( 5 );
			Log::error( 'Can\'t get invoice from webhook: ' . $exception->getMessage() );
			throw $exception;
		}


		$this->createInvoice( $this->conn, $invoice );
		$this->jobModel->updateProgress( 100 );
	}

	/
	 * @param Connection $connection
	 * @param Model      $invoice
	 *
	 * @return bool
	 */
	protected function createInvoice( Connection $connection, Model $invoice ) {

		$billy    = $connection->createBillyClient();
		$rackbeat = $connection->createRackbeatClient();

		$type      = ( $invoice->getEntity() === 'supplier-invoices' ) ? 'supplier' : 'customer';
		$rb_entity = $type . 's';

		$contact = $this->findOrCreateContact( $rackbeat->rb->{$rb_entity}()->find( $invoice->{$type . '_id'} ), $billy, $type );

		$this->jobModel->updateProgress( 50 );
		$invoice = InvoiceTransformer::rackbeat( $connection, $invoice );

		$invoice['contactId'] = $contact->id;

		if ( $type === 'customer' ) {
			$this->jobModel->updateProgress( 80 );
			$this->createBillyInvoice( $invoice, $billy );
		} else {
			$this->jobModel->updateProgress( 80 );
			$this->createBillyBill( $invoice, $billy );
		}

		return true;
	}

	/
	 * @param        $contact Model
	 * @param        $billy   Billy
	 * @param string $type    string
	 *
	 * @return Supplier|Customer
	 */
	protected function findOrCreateContact( $contact, $billy, $type = 'supplier' ) {
		switch ( $type ) {

			case 'customer':
				$billy = $billy->customers();
				/
				 * @var $transformer TransformerInterface
				 */
				$transformer = new CustomerTransformer( $this->conn );
				break;
			default:
				$billy       = $billy->suppliers();
				$transformer = new SupplierTransformer( $this->conn );
		}

		$billy_contact = $billy->get( [
			[ 'contactNo', '=', $contact->number ]
		] )->first();

		if ( ! $billy_contact ) {

			$billy_contact = $billy->create( $transformer->fromRackbeat( $contact ) );
		}

		return $billy_contact;
	}

	/
	 * @param $invoice
	 * @param $billy Billy
	 */
	protected function createBillyInvoice( $invoice, $billy ) {

		$billy->invoices()->create( $invoice );
	}

	/
	 * @param $invoice
	 * @param $billy Billy
	 */
	protected function createBillyBill( $invoice, $billy ) {

		$billy->bills()->create( $invoice );
	}
}

And this is how you would start this job from your controller

// App\Http\Controllers\Webhooks\InvoiceController.php

<?php

namespace App\Http\Controllers\Webhooks;

use App\Connection;
use App\Jobs\Webhooks\TransferInvoice;
use KgBot\RackbeatDashboard\Models\Job;

class InvoiceController extends Controller
{
	public function test() {

		Job::create( [

			'command'    => TransferInvoice::class,
			'queue'      => 'rackbeat-dashboard',
			'args'       => [ Connection::find( 1 ), [ 'key' => 3001 ], 'customer' ],
			'title'      => 'Transfer Invoice',
			'created_by' => 1,
		] );

		return redirect()->to( '/' );
	}
}

created_by parameter is Connection ID for which you create this model/job.

If you need any more info feel free to contact maintainers, read this code or read Billy integration code because this is all used inside that integration.


  Files folder image Files  
File Role Description
Files folder imagesrc (2 files, 10 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files  /  src  
File Role Description
Files folder imageClasses (6 files)
Files folder imageconfig (1 file)
Files folder imageConsole (1 directory)
Files folder imagedatabase (1 directory)
Files folder imageHttp (2 directories)
Files folder imageMail (1 file)
Files folder imageModels (2 files)
Files folder imageNotifications (5 files)
Files folder imageObservers (1 file)
Files folder imageresources (1 directory)
  Plain text file RackbeatDashboardServiceProvider.php Class Class source
  Plain text file routes.php Class Class source

  Files folder image Files  /  src  /  Classes  
File Role Description
  Plain text file CloudWatchLogger.php Class Class source
  Plain text file DashboardJob.php Class Class source
  Plain text file ErrorCauserChecker.php Class Class source
  Plain text file Executable.php Class Class source
  Plain text file JobState.php Class Class source
  Plain text file Reportable.php Class Class source

  Files folder image Files  /  src  /  config  
File Role Description
  Plain text file rackbeat-integration-dashboard.php Class Class source

  Files folder image Files  /  src  /  Console  
File Role Description
Files folder imageCommands (6 files)

  Files folder image Files  /  src  /  Console  /  Commands  
File Role Description
  Plain text file ClearOldJobs.php Class Class source
  Plain text file DeactivateDeadRackbeat.php Class Class source
  Plain text file GetRetryJobs.php Class Class source
  Plain text file InstallMissingPlug...installWebhooks.php Class Class source
  Plain text file MakeDashboardToken.php Class Class source
  Plain text file RefreshRackbeatToken.php Class Class source

  Files folder image Files  /  src  /  database  
File Role Description
Files folder imagemigrations (12 files)

  Files folder image Files  /  src  /  database  /  migrations  
File Role Description
  Plain text file 2019_02_22_084052_create_job_logs.php Class Class source
  Plain text file 2019_02_22_084127_..._dashboard_jobs.php Class Class source
  Plain text file 2019_02_22_095634_...board_jobs_args.php Class Class source
  Plain text file 2019_02_23_134140_...oard_jobs_title.php Class Class source
  Plain text file 2019_03_25_181357_...oard_jobs_delay.php Class Class source
  Plain text file 2020_01_28_132000_...rd_jobs_indexes.php Class Class source
  Plain text file 2020_01_28_154000_...bs_more_indexes.php Class Class source
  Plain text file 2020_05_15_085003_..._complete_index.php Class Class source
  Plain text file 2020_05_15_100130_...reated_by_index.php Class Class source
  Plain text file 2020_10_02_102010_...s_extra_as_json.php Class Class source
  Plain text file 2020_10_02_103050_...s_only_log_jobs.php Class Class source
  Plain text file 2020_10_02_104845_...gs_foreign_keys.php Class Class source

  Files folder image Files  /  src  /  Http  
File Role Description
Files folder imageControllers (2 files)
Files folder imageMiddleware (2 files)

  Files folder image Files  /  src  /  Http  /  Controllers  
File Role Description
  Plain text file Controller.php Class Class source
  Plain text file JobsController.php Class Class source

  Files folder image Files  /  src  /  Http  /  Middleware  
File Role Description
  Plain text file CheckDashboardToken.php Class Class source
  Plain text file JobBelongsToAccount.php Class Class source

  Files folder image Files  /  src  /  Mail  
File Role Description
  Plain text file JobFailed.php Class Class source

  Files folder image Files  /  src  /  Models  
File Role Description
  Plain text file Job.php Class Class source
  Plain text file JobLog.php Class Class source

  Files folder image Files  /  src  /  Notifications  
File Role Description
  Plain text file LogMessage.php Class Class source
  Plain text file Notificator.php Class Class source
  Plain text file Progress.php Class Class source
  Plain text file StateMessage.php Class Class source
  Plain text file UserMessage.php Class Class source

  Files folder image Files  /  src  /  Observers  
File Role Description
  Plain text file JobObserver.php Class Class source

  Files folder image Files  /  src  /  resources  
File Role Description
Files folder imageviews (1 directory)

  Files folder image Files  /  src  /  resources  /  views  
File Role Description
Files folder imagemail (1 file)

  Files folder image Files  /  src  /  resources  /  views  /  mail  
File Role Description
  Accessible without login Plain text file job-failed.blade.php Aux. Auxiliary script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:21
This week:1
All time:11,167
This week:560Up