Some invoice layout fixes, start on traffic collection, update console command service:list
This commit is contained in:
parent
dd1460463f
commit
86861a6daf
115
app/Classes/External/Supplier.php
vendored
Normal file
115
app/Classes/External/Supplier.php
vendored
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Classes\External;
|
||||||
|
|
||||||
|
use GuzzleHttp\Client;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
abstract class Supplier
|
||||||
|
{
|
||||||
|
protected $o = NULL;
|
||||||
|
protected $_columns = [];
|
||||||
|
|
||||||
|
public function __construct(Model $o)
|
||||||
|
{
|
||||||
|
$this->o = $o;
|
||||||
|
$this->_columns = collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect and pull down traffic data
|
||||||
|
*
|
||||||
|
* @param array $args
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function connect(array $args=[])
|
||||||
|
{
|
||||||
|
if ($x=$this->mustPause()) {
|
||||||
|
Log::error('API Throttle, waiting .',['m'=>__METHOD__]);
|
||||||
|
sleep($x);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = Cache::remember('Supplier:'.$this->o->id,86400,function() {
|
||||||
|
$client = $this->getClient();
|
||||||
|
|
||||||
|
$result = $client->request('POST',null,[
|
||||||
|
'query'=>[
|
||||||
|
$this->login_user_field=>$this->o->stats_username,
|
||||||
|
$this->login_pass_field=>$this->o->stats_password,
|
||||||
|
$this->date_field=>$this->o->stats_lastupdate,
|
||||||
|
],
|
||||||
|
/*
|
||||||
|
'headers' => [
|
||||||
|
'Accept'=>'application/json',
|
||||||
|
],
|
||||||
|
*/
|
||||||
|
]);
|
||||||
|
|
||||||
|
$api_remain = Arr::get($result->getHeader('X-RateLimit-Remaining'),0);
|
||||||
|
$api_reset = Arr::get($result->getHeader('X-RateLimit-Reset'),0);
|
||||||
|
|
||||||
|
if ($api_remain == 0) {
|
||||||
|
Log::error('API Throttle.',['m'=>__METHOD__]);
|
||||||
|
Cache::put('api_throttle',$api_reset,now()->addSeconds($api_reset));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result->getBody()->getContents();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the API HTTP client
|
||||||
|
* @return Client
|
||||||
|
*/
|
||||||
|
protected function getClient(): Client
|
||||||
|
{
|
||||||
|
return new Client(['base_uri'=>$this->o->stats_url]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the expected columns from a supplier traffic import
|
||||||
|
*
|
||||||
|
* @param string $line
|
||||||
|
* @param Collection $expect
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
protected function getColumns(string $line,Collection $expect): Collection
|
||||||
|
{
|
||||||
|
$fields = collect(explode(',',$line))->filter();
|
||||||
|
$this->_columns = $expect;
|
||||||
|
|
||||||
|
if ($this->_columns->diff($fields)->count()) {
|
||||||
|
abort('500','Missing columns in data: '.join('|',$this->_columns->diff($fields)->toArray()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fields->intersect($this->_columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the key ID for a column
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function getColumnKey(string $key)
|
||||||
|
{
|
||||||
|
return $this->_columns->search($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the supplier has API throttling...
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function mustPause()
|
||||||
|
{
|
||||||
|
return Cache::get('api_throttle');
|
||||||
|
}
|
||||||
|
}
|
47
app/Console/Commands/BroadbandTraffic.php
Normal file
47
app/Console/Commands/BroadbandTraffic.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
use App\Jobs\BroadbandTraffic as Job;
|
||||||
|
use App\Models\AdslSupplier;
|
||||||
|
|
||||||
|
class BroadbandTraffic extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'broadband:traffic:import';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Input Broadband Traffic from Suppliers';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
foreach (AdslSupplier::active()->get() as $o) {
|
||||||
|
Job::dispatchNow($o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,7 +15,10 @@ class ServiceList extends Command
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'service:list';
|
protected $signature = 'service:list '.
|
||||||
|
'{--a|active : Active Only}'.
|
||||||
|
'{--category= : Category}'.
|
||||||
|
'{--f|fix : Fix start_date}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@ -45,15 +48,46 @@ class ServiceList extends Command
|
|||||||
Log::debug('- SQL',['sql'=>$query->sql,'binding'=>$query->bindings]);
|
Log::debug('- SQL',['sql'=>$query->sql,'binding'=>$query->bindings]);
|
||||||
});
|
});
|
||||||
|
|
||||||
foreach (Service::active()->get() as $o) {
|
$this->warn(sprintf('|%10s|%-6s|%-20s|%-50s|%8s|%14s|%10s|%10s|%10s|%10s|%10s|',
|
||||||
$this->info(sprintf('|%10s|%-6s|%-20s|%-50s|%8s|%14s|%10s|',
|
'ID',
|
||||||
|
'CAT',
|
||||||
|
'Product',
|
||||||
|
'Name',
|
||||||
|
'active',
|
||||||
|
'status',
|
||||||
|
'invoice next',
|
||||||
|
'start date',
|
||||||
|
'stop date',
|
||||||
|
'connect date',
|
||||||
|
'first invoice'
|
||||||
|
));
|
||||||
|
|
||||||
|
foreach (Service::all() as $o) {
|
||||||
|
if ($this->option('active') AND ! $o->isActive())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ($this->option('category') AND $o->product->category !== $this->option('category'))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
$c = $o->invoice_items->filter(function($item) {return $item->item_type === 0; })->sortby('date_start')->first();
|
||||||
|
|
||||||
|
if ($this->option('fix') AND ! $o->date_start AND $c AND $c->date_start AND $o->type AND $o->type->service_connect_date AND $c->date_start->format('Y-m-d') == $o->type->service_connect_date->format('Y-m-d')) {
|
||||||
|
$o->date_start = $o->type->service_connect_date;
|
||||||
|
$o->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->info(sprintf('|%10s|%-6s|%-20s|%-50s|%8s|%14s|%10s|%10s|%10s|%10s|%10s|',
|
||||||
$o->sid,
|
$o->sid,
|
||||||
$o->product->category,
|
$o->product->category,
|
||||||
$o->product_name,
|
$o->product_name,
|
||||||
$o->name_short,
|
$o->name_short,
|
||||||
$o->active ? 'active' : 'inactive',
|
$o->active ? 'active' : 'inactive',
|
||||||
$o->status,
|
$o->status,
|
||||||
$o->invoice_next ? $o->invoice_next : NULL,
|
$o->invoice_next ? $o->invoice_next->format('Y-m-d') : NULL,
|
||||||
|
$o->date_start ? $o->date_start->format('Y-m-d') : NULL,
|
||||||
|
$o->date_end ? $o->date_end->format('Y-m-d') : NULL,
|
||||||
|
($o->type AND $o->type->service_connect_date) ? $o->type->service_connect_date->format('Y-m-d') : NULL,
|
||||||
|
$c ? $c->date_start->format('Y-m-d') : NULL,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class SearchController extends Controller
|
|||||||
->orderBy('firstname')
|
->orderBy('firstname')
|
||||||
->limit(10)->get() as $o)
|
->limit(10)->get() as $o)
|
||||||
{
|
{
|
||||||
$result->push(['name'=>sprintf('US:%s %s',$o->aid,$o->name),'value'=>'/u/home/'.$o->id,'category'=>'Users']);
|
$result->push(['name'=>sprintf('%s %s',$o->aid,$o->name),'value'=>'/u/home/'.$o->id,'category'=>'Users']);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Look for Account
|
# Look for Account
|
||||||
@ -43,7 +43,7 @@ class SearchController extends Controller
|
|||||||
->orderBy('company')
|
->orderBy('company')
|
||||||
->limit(10)->get() as $o)
|
->limit(10)->get() as $o)
|
||||||
{
|
{
|
||||||
$result->push(['name'=>sprintf('AC:%s %s',$o->aid,$o->company),'value'=>'/u/home/'.$o->user_id,'category'=>'Accounts']);
|
$result->push(['name'=>sprintf('%s %s',$o->aid,$o->company),'value'=>'/u/home/'.$o->user_id,'category'=>'Accounts']);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Look for a Service
|
# Look for a Service
|
||||||
@ -52,7 +52,7 @@ class SearchController extends Controller
|
|||||||
->orderBy('id')
|
->orderBy('id')
|
||||||
->limit(10)->get() as $o)
|
->limit(10)->get() as $o)
|
||||||
{
|
{
|
||||||
$result->push(['name'=>sprintf('SV:%s (%s)',$o->name,$o->sid),'value'=>'/u/service/'.$o->id,'category'=>'Services']);
|
$result->push(['name'=>sprintf('%s (%s)',$o->name,$o->sid),'value'=>'/u/service/'.$o->id,'category'=>'Services']);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Look for an Invoice
|
# Look for an Invoice
|
||||||
@ -61,7 +61,7 @@ class SearchController extends Controller
|
|||||||
->orderBy('id')
|
->orderBy('id')
|
||||||
->limit(10)->get() as $o)
|
->limit(10)->get() as $o)
|
||||||
{
|
{
|
||||||
$result->push(['name'=>sprintf('IN:%s #%s',$o->account->name,$o->invoice_id),'value'=>'/u/invoice/'.$o->id,'category'=>'Invoices']);
|
$result->push(['name'=>sprintf('%s #%s',$o->account->name,$o->invoice_id),'value'=>'/u/invoice/'.$o->id,'category'=>'Invoices']);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Look for an ADSL/NBN Service
|
# Look for an ADSL/NBN Service
|
||||||
@ -70,7 +70,7 @@ class SearchController extends Controller
|
|||||||
->orderBy('service_number')
|
->orderBy('service_number')
|
||||||
->limit(10)->get() as $o)
|
->limit(10)->get() as $o)
|
||||||
{
|
{
|
||||||
$result->push(['name'=>sprintf('SV:%s (%s)',$o->name,$o->service->sid),'value'=>'/u/service/'.$o->id,'category'=>'Broadband']);
|
$result->push(['name'=>sprintf('%s (%s)',$o->name,$o->service->sid),'value'=>'/u/service/'.$o->id,'category'=>'Broadband']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<h4>
|
<h4>
|
||||||
<i class="fa fa-globe"></i> {{ $so->site_name }}
|
<i class="fa fa-globe"></i> {{ $so->site_name }}
|
||||||
<small class="pull-right">Date: {{ $o->invoice_date}}</small>
|
<small class="float-right">Date: {{ $o->invoice_date}}</small>
|
||||||
</h4>
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
<!-- /.col -->
|
<!-- /.col -->
|
||||||
@ -50,10 +50,8 @@
|
|||||||
@endif
|
@endif
|
||||||
</address>
|
</address>
|
||||||
</div>
|
</div>
|
||||||
{{-- col-sm-offset-2 not working here --}}
|
|
||||||
<div class="col-1"></div>
|
|
||||||
|
|
||||||
<div class="col-3 invoice-col">
|
<div class="ml-auto col-3">
|
||||||
<table class="table table-borderless text-right" style="font-size: 1.1rem;">
|
<table class="table table-borderless text-right" style="font-size: 1.1rem;">
|
||||||
<tr >
|
<tr >
|
||||||
<td class="p-0">Account:</td><td class="p-0"><strong>{{ $o->account->account_id }}</strong></td>
|
<td class="p-0">Account:</td><td class="p-0"><strong>{{ $o->account->account_id }}</strong></td>
|
||||||
@ -131,12 +129,12 @@
|
|||||||
--}}
|
--}}
|
||||||
|
|
||||||
<p class="text-muted well well-sm no-shadow" style="margin-top: 10px;">
|
<p class="text-muted well well-sm no-shadow" style="margin-top: 10px;">
|
||||||
{{ $o->invoice_text }}
|
{!! $o->invoice_text !!}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- /.col -->
|
<!-- /.col -->
|
||||||
<div class="offset-2 col-4 table-responsive">
|
<div class="ml-auto col-4">
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="2" style="width:50%">Subtotal:</th>
|
<th colspan="2" style="width:50%">Subtotal:</th>
|
||||||
@ -184,8 +182,8 @@
|
|||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<a href="javascript:window.print();" class="btn btn-default"><i class="fa fa-print"></i> Print</a>
|
<a href="javascript:window.print();" class="btn btn-default"><i class="fa fa-print"></i> Print</a>
|
||||||
@if($o->id)
|
@if($o->id)
|
||||||
<button type="button" class="btn btn-success pull-right"><i class="fa fa-credit-card"></i> Submit Payment</button>
|
<button type="button" class="btn btn-success float-right"><i class="fa fa-credit-card"></i> Submit Payment</button>
|
||||||
<a href="{{ url(sprintf('u/invoice/%s/pdf',$o->id)) }}" class="btn btn-primary pull-right" style="margin-right: 5px;">
|
<a href="{{ url(sprintf('u/invoice/%s/pdf',$o->id)) }}" class="btn btn-primary float-right" style="margin-right: 5px;">
|
||||||
<i class="fa fa-download"></i> Download PDF
|
<i class="fa fa-download"></i> Download PDF
|
||||||
</a>
|
</a>
|
||||||
@endif
|
@endif
|
||||||
|
Loading…
Reference in New Issue
Block a user