Compare commits

...

4 Commits

Author SHA1 Message Date
b1067e1378 Added Passkey login, fixed password reset as a result of updating laravel
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 1m14s
Create Docker Image / Final Docker Image Manifest (push) Successful in 9s
2024-07-23 00:13:54 +10:00
45fb023d8a Moving accounting commands into an Intuit/ namespace, updates to intuit module 2024-07-14 13:49:00 +10:00
9580fb1cd9 Home page performance optimisations
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 35s
Create Docker Image / Final Docker Image Manifest (push) Successful in 9s
2024-07-09 21:09:34 +10:00
3aac3d310f Optimise Invoice 2024-07-09 20:17:30 +10:00
39 changed files with 1319 additions and 704 deletions

View File

@ -1,3 +1,4 @@
APP_ADMIN=
APP_DEBUG=false
APP_NAME=OSB
APP_NAME_HTML_LONG="<b>Graytech</b>Hosting"
@ -7,6 +8,8 @@ APP_KEY=
APP_TIMEZONE=Australia/Melbourne
APP_URL=https://www.graytech.net.au
AUTH_PASSWORD_RESET_TOKEN_TABLE=password_resets
LOG_CHANNEL=daily
DB_CONNECTION=pgsql

View File

@ -1,51 +0,0 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
use App\Models\{ProviderOauth,Site,User};
use App\Jobs\AccountingAccountSync as Job;
/**
* Synchronise Customers with Accounts
*/
class AccountingAccountSync extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'accounting:account:sync'
.' {siteid : Site ID}'
.' {provider : Provider Name}'
.' {user : User Email}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Synchronise accounts with accounting system';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$site = Site::findOrFail($this->argument('siteid'));
Config::set('site',$site);
$uo = User::where('email',$this->argument('user'))->singleOrFail();
$so = ProviderOauth::where('name',$this->argument('provider'))->singleOrFail();
if (! ($to=$so->token($uo)))
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
Job::dispatchSync($to);
}
}

View File

@ -1,33 +1,32 @@
<?php
namespace App\Console\Commands;
namespace App\Console\Commands\Intuit;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
use Intuit\Jobs\AccountingCustomerUpdate;
use Intuit\Models\Customer as AccAccount;
use App\Models\{Account,ProviderOauth,Site,User};
use App\Models\{Account,ProviderOauth,User};
class AccountingAccountAdd extends Command
class AccountAdd extends Command
{
private const provider = 'intuit';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'accounting:account:add'
.' {siteid : Site ID}'
.' {provider : Provider Name}'
.' {user : User Email}'
.' {id : Account ID}';
protected $signature = 'intuit:account:add'
.' {id : Account ID}'
.' {user? : User Email}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Add an account to the accounting provider';
protected $description = 'Add an account to quickbooks';
/**
* Execute the console command.
@ -36,12 +35,9 @@ class AccountingAccountAdd extends Command
*/
public function handle()
{
$site = Site::findOrFail($this->argument('siteid'));
Config::set('site',$site);
$uo = User::where('email',$this->argument('user') ?: config('osb.admin'))->singleOrFail();
$uo = User::where('email',$this->argument('user'))->singleOrFail();
$so = ProviderOauth::where('name',$this->argument('provider'))->singleOrFail();
$so = ProviderOauth::where('name',self::provider)->singleOrFail();
if (! ($to=$so->token($uo)))
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));

View File

@ -1,33 +1,32 @@
<?php
namespace App\Console\Commands;
namespace App\Console\Commands\Intuit;
use GuzzleHttp\Exception\ConnectException;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
use Intuit\Exceptions\ConnectionIssueException;
use App\Models\{ProviderOauth,Site,User};
use App\Models\{ProviderOauth,User};
class AccountingAccountGet extends Command
class AccountGet extends Command
{
private const provider = 'intuit';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'accounting:account:get'
.' {siteid : Site ID}'
.' {provider : Provider Name}'
.' {user : User Email}'
.' {id : Account ID}';
protected $signature = 'intuit:account:get'
.' {id : Account ID}'
.' {user? : User Email}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Get an account from the accounting provider';
protected $description = 'Get an account from quickbooks';
/**
* Execute the console command.
@ -36,12 +35,9 @@ class AccountingAccountGet extends Command
*/
public function handle()
{
$site = Site::findOrFail($this->argument('siteid'));
Config::set('site',$site);
$uo = User::where('email',$this->argument('user') ?: config('osb.admin'))->singleOrFail();
$uo = User::where('email',$this->argument('user'))->singleOrFail();
$so = ProviderOauth::where('name',$this->argument('provider'))->singleOrFail();
$so = ProviderOauth::where('name',self::provider)->singleOrFail();
if (! ($to=$so->token($uo)))
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
@ -52,7 +48,9 @@ class AccountingAccountGet extends Command
} catch (ConnectException|ConnectionIssueException $e) {
$this->error($e->getMessage());
return Command::FAILURE;
return self::FAILURE;
}
return self::SUCCESS;
}
}

View File

@ -0,0 +1,49 @@
<?php
namespace App\Console\Commands\Intuit;
use Illuminate\Console\Command;
use App\Models\{ProviderOauth,User};
use App\Jobs\AccountingAccountSync as Job;
/**
* Synchronise Customers with Accounts
*/
class AccountSync extends Command
{
private const provider = 'intuit';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'intuit:account:sync'
.' {user? : User Email}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Synchronise accounts with quickbooks';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$uo = User::where('email',$this->argument('user') ?: config('osb.admin'))->singleOrFail();
$so = ProviderOauth::where('name',self::provider)->singleOrFail();
if (! ($to=$so->token($uo)))
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
Job::dispatchSync($to);
return self::SUCCESS;
}
}

View File

@ -1,26 +1,25 @@
<?php
namespace App\Console\Commands;
namespace App\Console\Commands\Intuit;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
use Intuit\Jobs\AccountingInvoiceUpdate;
use Intuit\Models\Invoice as AccInvoice;
use App\Models\{Invoice,ProviderOauth,Site,User};
use App\Models\{Invoice,ProviderOauth,User};
class AccountingInvoiceAdd extends Command
class InvoiceAdd extends Command
{
private const provider = 'intuit';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'accounting:invoice:add'
.' {siteid : Site ID}'
.' {provider : Provider Name}'
.' {user : User Email}'
.' {id : Invoice ID}';
.' {id : Invoice ID}'
.' {user? : User Email}';
/**
* The console command description.
@ -33,15 +32,13 @@ class AccountingInvoiceAdd extends Command
* Execute the console command.
*
* @return int
* @throws \Exception
*/
public function handle()
{
$site = Site::findOrFail($this->argument('siteid'));
Config::set('site',$site);
$uo = User::where('email',$this->argument('user') ?: config('osb.admin'))->singleOrFail();
$uo = User::where('email',$this->argument('user'))->singleOrFail();
$so = ProviderOauth::where('name',$this->argument('provider'))->singleOrFail();
$so = ProviderOauth::where('name',self::provider)->singleOrFail();
if (! ($to=$so->token($uo)))
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
@ -78,12 +75,14 @@ class AccountingInvoiceAdd extends Command
// Some validation
if (! ($ref=$key->product->provider_ref($so))) {
$this->error(sprintf('Accounting not defined in product [%d]',$key->product_id));
exit(1);
return self::FAILURE;
}
if ($key->taxes->count() !== 1) {
$this->error(sprintf('Cannot handle when there is not just 1 tax line [%d]',$key->id));
exit(1);
return self::FAILURE;
}
$c++;

View File

@ -1,33 +1,32 @@
<?php
namespace App\Console\Commands;
namespace App\Console\Commands\Intuit;
use GuzzleHttp\Exception\ConnectException;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
use Intuit\Exceptions\ConnectionIssueException;
use App\Models\{ProviderOauth,Site,User};
use App\Models\{ProviderOauth,User};
class AccountingInvoiceGet extends Command
class InvoiceGet extends Command
{
private const provider = 'intuit';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'accounting:invoice:get'
.' {siteid : Site ID}'
.' {provider : Provider Name}'
.' {user : User Email}'
.' {id : Invoice ID}';
protected $signature = 'intuit:invoice:get'
.' {id : Invoice ID}'
.' {user? : User Email}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Get an invoice from the accounting provider';
protected $description = 'Get an invoice from the quickbooks';
/**
* Execute the console command.
@ -36,12 +35,9 @@ class AccountingInvoiceGet extends Command
*/
public function handle()
{
$site = Site::findOrFail($this->argument('siteid'));
Config::set('site',$site);
$uo = User::where('email',$this->argument('user') ?: config('osb.admin'))->singleOrFail();
$uo = User::where('email',$this->argument('user'))->singleOrFail();
$so = ProviderOauth::where('name',$this->argument('provider'))->singleOrFail();
$so = ProviderOauth::where('name',self::provider)->singleOrFail();
if (! ($to=$so->token($uo)))
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
@ -52,7 +48,9 @@ class AccountingInvoiceGet extends Command
} catch (ConnectException|ConnectionIssueException $e) {
$this->error($e->getMessage());
return Command::FAILURE;
return self::FAILURE;
}
return self::SUCCESS;
}
}

View File

@ -1,25 +1,23 @@
<?php
namespace App\Console\Commands;
namespace App\Console\Commands\Intuit;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use App\Models\{Product, ProviderOauth, Site, User};
use App\Models\{Product,ProviderOauth,User};
use App\Jobs\AccountingItemSync as Job;
class AccountingItemList extends Command
class ItemList extends Command
{
private const provider = 'intuit';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'accounting:item:list'
.' {siteid : Site ID}'
.' {provider : Provider Name}'
.' {user : User Email}';
.' {user? : User Email}';
/**
* The console command description.
@ -35,12 +33,9 @@ class AccountingItemList extends Command
*/
public function handle()
{
$site = Site::findOrFail($this->argument('siteid'));
Config::set('site',$site);
$so = ProviderOauth::where('name',$this->argument('provider'))->singleOrFail();
$uo = User::where('email',$this->argument('user'))->singleOrFail();
$uo = User::where('email',$this->argument('user') ?: config('osb.admin'))->singleOrFail();
$so = ProviderOauth::where('name',self::provider)->singleOrFail();
if (($x=$so->tokens->where('user_id',$uo->id))->count() !== 1)
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
@ -67,5 +62,7 @@ class AccountingItemList extends Command
else
$this->info(sprintf('Product [%d](%s) set to accounting [%s]',$po->id,$po->name,$po->accounting));
}
return self::SUCCESS;
}
}

View File

@ -1,27 +1,26 @@
<?php
namespace App\Console\Commands;
namespace App\Console\Commands\Intuit;
use GuzzleHttp\Exception\ConnectException;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
use Intuit\Exceptions\ConnectionIssueException;
use App\Jobs\AccountingPaymentSync as Job;
use App\Models\{ProviderOauth,Site,User};
use App\Models\{ProviderOauth,User};
class AccountingPaymentGet extends Command
class PaymentGet extends Command
{
private const provider = 'intuit';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'accounting:payment:get'
.' {siteid : Site ID}'
.' {provider : Provider Name}'
.' {user : User Email}'
.' {id : Payment ID}';
.' {id : Payment ID}'
.' {user? : User Email}';
/**
* The console command description.
@ -37,12 +36,9 @@ class AccountingPaymentGet extends Command
*/
public function handle()
{
$site = Site::findOrFail($this->argument('siteid'));
Config::set('site',$site);
$uo = User::where('email',$this->argument('user') ?: config('osb.admin'))->singleOrFail();
$uo = User::where('email',$this->argument('user'))->singleOrFail();
$so = ProviderOauth::where('name',$this->argument('provider'))->singleOrFail();
$so = ProviderOauth::where('name',self::provider)->singleOrFail();
if (! ($to=$so->token($uo)))
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
@ -59,5 +55,7 @@ class AccountingPaymentGet extends Command
if ($acc)
Job::dispatchSync($to,$acc);
return self::SUCCESS;
}
}

View File

@ -1,24 +1,23 @@
<?php
namespace App\Console\Commands;
namespace App\Console\Commands\Intuit;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
use App\Models\{ProviderOauth,Site,User};
use App\Models\{ProviderOauth,User};
use App\Jobs\AccountingPaymentSync as Job;
class AccountingPaymentSync extends Command
class PaymentSync extends Command
{
private const provider = 'intuit';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'accounting:payment:sync'
.' {siteid : Site ID}'
.' {provider : Provider Name}'
.' {user : User Email}';
.' {user? : User Email}';
/**
* The console command description.
@ -34,17 +33,16 @@ class AccountingPaymentSync extends Command
*/
public function handle()
{
$site = Site::findOrFail($this->argument('siteid'));
Config::set('site',$site);
$uo = User::where('email',$this->argument('user') ?: config('osb.admin'))->singleOrFail();
$uo = User::where('email',$this->argument('user'))->singleOrFail();
$so = ProviderOauth::where('name',$this->argument('provider'))->singleOrFail();
$so = ProviderOauth::where('name',self::provider)->singleOrFail();
if (! ($to=$so->token($uo)))
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
$api = $to->API();
foreach ($api->getPayments() as $acc)
Job::dispatchSync($to,$acc);
return self::SUCCESS;
}
}

View File

@ -1,27 +1,26 @@
<?php
namespace App\Console\Commands;
namespace App\Console\Commands\Intuit;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
use App\Models\{ProviderOauth,Site,User};
use App\Models\{ProviderOauth,User};
use App\Jobs\AccountingTaxSync as Job;
/**
* Synchronise TAX ids with our taxes.
*/
class AccountingTaxSync extends Command
class TaxSync extends Command
{
private const provider = 'intuit';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'accounting:tax:sync'
.' {siteid : Site ID}'
.' {provider : Provider Name}'
.' {user : User Email}';
.' {user? : User Email}';
/**
* The console command description.
@ -37,15 +36,14 @@ class AccountingTaxSync extends Command
*/
public function handle()
{
$site = Site::findOrFail($this->argument('siteid'));
Config::set('site',$site);
$uo = User::where('email',$this->argument('user') ?: config('osb.admin'))->singleOrFail();
$uo = User::where('email',$this->argument('user'))->singleOrFail();
$so = ProviderOauth::where('name',$this->argument('provider'))->singleOrFail();
$so = ProviderOauth::where('name',self::provider)->singleOrFail();
if (! ($to=$so->token($uo)))
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
Job::dispatchSync($to);
return self::SUCCESS;
}
}

View File

@ -16,9 +16,8 @@ class ProviderTokenRefresh extends Command
* @var string
*/
protected $signature = 'provider:token:refresh'
.' {siteid : Site ID}'
.' {provider : Supplier Name}'
.' {user : User Email}';
.' {user? : User Email}';
/**
* The console command description.
@ -34,15 +33,14 @@ class ProviderTokenRefresh extends Command
*/
public function handle()
{
$site = Site::findOrFail($this->argument('siteid'));
Config::set('site',$site);
$uo = User::where('email',$this->argument('user') ?: config('osb.admin'))->singleOrFail();
$so = ProviderOauth::where('name',$this->argument('provider'))->singleOrFail();
$uo = User::where('email',$this->argument('user'))->singleOrFail();
if (($x=$so->tokens->where('user_id',$uo->id))->count() !== 1)
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
Job::dispatchSync($x->pop());
return self::SUCCESS;
}
}

View File

@ -19,4 +19,14 @@ class ForgotPasswordController extends Controller
*/
use SendsPasswordResetEmails;
/**
* Display the form to request a password reset link.
*
* @return \Illuminate\View\View
*/
public function showLinkRequestForm()
{
return view('adminlte::auth.passwords.email');
}
}

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Http\Request;
class ResetPasswordController extends Controller
{
@ -26,4 +27,23 @@ class ResetPasswordController extends Controller
* @var string
*/
protected $redirectTo = '/home';
/**
* Display the password reset view for the given token.
*
* If no token is present, display the link request form.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function showResetForm(Request $request)
{
$token = $request->route()->parameter('token');
return view('adminlte::auth.passwords.reset')
->with([
'token' => $token,
'email' => $request->email
]);
}
}

View File

@ -3,14 +3,38 @@
namespace App\Http\Controllers;
use Carbon\Carbon;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Session;
use Illuminate\Validation\Rule;
use App\Http\Requests\UserEdit;
use App\Models\{Supplier,User};
class UserController extends Controller
{
/**
* Update user settings
*
* @param UserEdit $request
* @param User $o
* @return RedirectResponse
*/
public function edit(UserEdit $request,User $o): RedirectResponse
{
foreach (Arr::except($request->validated(),['password']) as $field => $value)
$o->{$field} = $value;
if ($x=$request->validated('password'))
$o->password = Hash::make($x);
return redirect()
->back()
->with('success',($o->isDirty() && $o->save()) ? 'User Updated' : 'No Changes');
}
/**
* Add a supplier to a user's profile
*

View File

@ -0,0 +1,39 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rules\Password;
class UserEdit extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return Auth::id() === $this->route('o')->id;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'email'=>'required|email|min:5',
'password'=>['nullable','confirmed',Password::min(8)],
'firstname'=>'required|min:2',
'lastname'=>'required|min:2',
'address1'=>'required|min:8',
'address2'=>'nullable|min:8',
'city'=>'required|min:4',
'state'=>'required|min:3|max:3',
'postcode'=>'required|min:4|max:4',
'country_id'=>'required|exists:countries,id'
];
}
}

View File

@ -102,7 +102,7 @@ class Account extends Model implements IDs
public function invoices()
{
return $this->hasMany(Invoice::class)
->with(['items.taxes','paymentitems.payment']);
->with(['items.taxes','payment_items.payment']);
}
/**

View File

@ -3,21 +3,16 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Leenooks\Traits\ScopeActive;
class Country extends Model
{
use ScopeActive;
public $timestamps = FALSE;
/* RELATIONS */
/**
* The currency this country belongs to
*/
public function currency()
{
return $this->belongsTo(Currency::class);
}
public function taxes()
{
return $this->hasMany(Tax::class);

View File

@ -1,29 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Currency extends Model
{
public $timestamps = FALSE;
const ROUND_HALF_UP = 1;
const ROUND_HALF_DOWN = 2;
const ROUND_HALF_EVEN = 3;
const ROUND_HALF_ODD = 4;
/* RELATIONS */
public function country()
{
return $this->hasOne(Country::class);
}
/* METHODS */
public function round($value,$mode=self::ROUND_HALF_UP)
{
return round($value,$this->rounding,$mode);
}
}

View File

@ -7,6 +7,7 @@ use Clarkeash\Doorman\Facades\Doorman;
use Clarkeash\Doorman\Models\Invite;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Leenooks\Casts\LeenooksCarbon;
use Leenooks\Traits\ScopeActive;
@ -19,16 +20,16 @@ use App\Traits\PushNew;
* Invoices that belong to an Account
*
* Attributes for services:
* + created_at : Date the invoice was created
* + due : Balance due on an invoice
* + due_date : Date the invoice is due
* + invoice_date : Date the invoice was created
* + due_at : Date the invoice is due
* + lid : Local ID for invoice
* + paid : Total of payments received (excluding pending)
* + paid_date : Date the invoice was paid in full
* + paid_pending : Total of pending payments received
* + sid : System ID for invoice
* + sub_total : Invoice sub-total before taxes
* + total_tax : Invoices total of taxes
* + tax_total : Invoices total of taxes
* + total : Invoice total
*
* @package App\Models
@ -97,13 +98,13 @@ class Invoice extends Model implements IDs
// Array of items that can be updated with PushNew
protected $pushable = ['items'];
/*
protected $with = [
'account.country.currency',
'items.taxes',
'paymentitems'
'items_active:id,start_at,stop_at,quantity,price_base,discount_amt,item_type,product_id,service_id,invoice_id',
'items_active.taxes:id,invoice_item_id,amount,tax_id',
'items_active.product:id',
'items_active.product.translate:id,product_id,name_short,name_detail',
'payment_items_active:id,amount,payment_id,invoice_id',
];
*/
/* STATIC METHODS */
@ -181,29 +182,58 @@ class Invoice extends Model implements IDs
/* RELATIONS */
/**
* Account this invoice belongs to
*/
public function account()
{
return $this->belongsTo(Account::class);
}
/**
* Items on this invoice belongs to
*/
public function items()
{
return $this->hasMany(InvoiceItem::class)
->where('active',TRUE)
->with(['taxes','product']);
}
/**
* Active items on this invoice belongs to
*/
public function items_active()
{
return $this->items()
->where('active',TRUE);
}
/**
* Payments applied to this invoice
*/
public function payments()
{
return $this->hasManyThrough(Payment::class,PaymentItem::class,NULL,'id',NULL,'payment_id')
->active();
->where('active',TRUE);
}
public function paymentitems()
/**
* Payment items attached to this invoice
*/
public function payment_items()
{
return $this->hasMany(PaymentItem::class);
}
public function payment_items_active()
{
return $this->payment_items()
->where('payment_items.active',TRUE);
}
/**
* 3rd party provider details to this invoice (eg: accounting providers)
*/
public function providers()
{
return $this->belongsToMany(ProviderOauth::class,'invoice__provider')
@ -236,31 +266,6 @@ class Invoice extends Model implements IDs
return sprintf('%3.2f',$this->getTotalAttribute()-$this->getPaidAttribute());
}
/**
* @return mixed
* @todo Change references to due_at to use due_date
*/
public function getDueDateAttribute(): Carbon
{
return $this->due_at;
}
/**
* Date the invoices was created
*
* @return Carbon
*/
public function getInvoiceDateAttribute(): Carbon
{
return $this->created_at;
}
// @todo Move this to a site configuration
public function getInvoiceTextAttribute()
{
return sprintf('Thank you for using %s for your Internet Services.',config('site')->site_name);
}
/**
* Total of payments received for this invoice
* excluding pending payments
@ -269,9 +274,7 @@ class Invoice extends Model implements IDs
*/
public function getPaidAttribute(): float
{
return $this->paymentitems
->filter(function($item) { return ! $item->payment->pending_status && $item->payment->active; })
->sum('amount');
return $this->payment_items_active->sum('amount');
}
/**
@ -282,11 +285,13 @@ class Invoice extends Model implements IDs
*/
public function getPaidDateAttribute(): ?Carbon
{
// If the invoice still has a due balance, its not paid
if ($this->getDueAttribute())
return NULL;
$o = $this->payments
->filter(function($item) { return ! $item->pending_status; })
$o = $this
->payments
->filter(fn($item)=>(! $item->pending_status))
->last();
return $o?->paid_at;
@ -299,8 +304,8 @@ class Invoice extends Model implements IDs
*/
public function getPaidPendingAttribute(): float
{
return $this->paymentitems
->filter(function($item) { return $item->payment->pending_status; })
return $this->payment_items
->filter(fn($item)=>$item->payment->pending_status)
->sum('amount');
}
@ -311,28 +316,17 @@ class Invoice extends Model implements IDs
*/
public function getSubTotalAttribute(): float
{
return $this->items->where('active',TRUE)->sum('sub_total');
return $this->items_active->sum('sub_total');
}
/**
* Get the invoices taxes total
*
* @return float
* @deprecated use getTotalTaxAttribute();
*/
public function getTaxTotalAttribute(): float
{
return $this->getTotalTaxAttribute();
}
/**
* Get the invoices taxes total
*
* @return float
*/
public function getTotalTaxAttribute(): float
{
return $this->items->where('active',TRUE)->sum('tax');
return $this->items_active->sum('tax');
}
/**
@ -342,17 +336,11 @@ class Invoice extends Model implements IDs
*/
public function getTotalAttribute(): float
{
return $this->getSubTotalAttribute()+$this->getTotalTaxAttribute();
return $this->getSubTotalAttribute()+$this->getTaxTotalAttribute();
}
/* METHODS */
// @todo This shouldnt be here - current should be handled at an account level.
public function currency()
{
return $this->account->country->currency;
}
/**
* Return a download link for non-auth downloads
*
@ -366,57 +354,37 @@ class Invoice extends Model implements IDs
$tokendate = ($x=Carbon::now()->addDays(21)) > ($y=$this->due_at->addDays(21)) ? $x : $y;
// Extend the expire date
if ($io AND ($tokendate > $io->valid_until)) {
if ($io && ($tokendate > $io->valid_until)) {
$io->valid_until = $tokendate;
$io->save();
}
$code = (! $io) ? Doorman::generate()->for($this->account->user->email)->uses(0)->expiresOn($tokendate)->make()->first()->code : $io->code;
$code = (! $io)
? Doorman::generate()
->for($this->account->user->email)
->uses(0)
->expiresOn($tokendate)
->make()
->first()
->code
: $io->code;
return url('u/invoice',[$this->id,'email',$code]);
}
// @todo document
public function products()
/**
* Return all the items on an invoice for a particular service and product
*
* @param Product $po
* @param Service $so
* @return Collection
*/
public function product_service_items(Product $po,Service $so): Collection
{
$return = collect();
foreach ($this->items->groupBy('product_id') as $o) {
$po = $o->first()->product;
$po->count = count($o->pluck('service_id')->unique());
$return->push($po);
}
return $return->sortBy(function ($item) {
return $item->name;
});
}
// @todo document
public function product_services(Product $po)
{
$return = collect();
$this->items->load(['service']);
foreach ($this->items->filter(function ($item) use ($po) {
return $item->product_id == $po->id;
}) as $o)
{
$so = $o->service;
$return->push($so);
};
return $return->unique()->sortBy('name');
}
// @todo document
public function product_service_items(Product $po,Service $so)
{
return $this->items->filter(function ($item) use ($po,$so) {
return $item->product_id == $po->id AND $item->service_id == $so->id;
})->filter()->sortBy('item_type');
return $this
->items_active
->filter(fn($item)=>($item->product_id === $po->id) && ($item->service_id === $so->id))
->sortBy('item_type');
}
/**
@ -439,6 +407,7 @@ class Invoice extends Model implements IDs
*
* @param array $options
* @return bool
* @todo Change this to a saving event
*/
public function save(array $options = [])
{
@ -453,4 +422,29 @@ class Invoice extends Model implements IDs
return parent::save($options);
}
/**
* Group the invoice items by product ID, returning the number of products and total
*
* @return Collection
*/
public function summary_products(): Collection
{
$return = collect();
foreach ($this->items_active->groupBy('product_id') as $o) {
$po = $o->first()->product;
$po->count = count($o->pluck('service_id')->unique());
$return->push([
'product' => $o->first()->product,
'services' => $o->pluck('service_id')->unique(),
'sub_total' => $o->sum('sub_total'),
'tax_total' => $o->sum('tax'),
'total' => $o->sum('total'),
]);
}
return $return->sortBy('product.name');
}
}

View File

@ -125,7 +125,7 @@ class InvoiceItem extends Model
*/
public function getSubTotalAttribute(): float
{
return sprintf('%3.2f',$this->quantity * $this->price_base - $this->discount_amt);
return sprintf('%3.2f',$this->quantity * ($this->price_base - $this->discount_amt));
}
/**

View File

@ -44,11 +44,6 @@ class Site extends Model
return $this->belongsTo(Country::class);
}
public function currency()
{
return $this->belongsTo(Currency::class);
}
public function details()
{
return $this->hasMany(SiteDetail::class,NULL,'site_id');

View File

@ -29,6 +29,7 @@ class User extends Authenticatable implements IDs
protected $casts = [
'last_access' => 'datetime:Y-m-d H:i:s',
'passkey' => 'json',
];
/**

View File

@ -2,6 +2,7 @@
namespace App\Notifications;
use App\Models\Site;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Auth\Notifications\ResetPassword as ResetPasswordNotification;
@ -15,17 +16,19 @@ class ResetPassword extends ResetPasswordNotification implements ShouldQueue
* Build the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
* @return MailMessage
*/
public function toMail($notifiable)
public function toMail($notifiable): MailMessage
{
$site = Site::findOrFail($notifiable->site_id);
if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable, $this->token);
}
return (new MailMessage)
->markdown('email.user.passwordreset',[
'site'=>$notifiable->site,
'site'=>$site,
'user'=>$notifiable,
'reset_link'=>route('password.reset',$this->token,true),
]);

View File

@ -4,11 +4,13 @@ namespace App\Providers;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
use Intuit\Traits\IntuitSocialite;
use Leenooks\Traits\SingleOrFail;
class AppServiceProvider extends ServiceProvider
{
use SingleOrFail;
use IntuitSocialite;
/**
* Register any application services.
@ -32,5 +34,7 @@ class AppServiceProvider extends ServiceProvider
Gate::define('reseller', function ($user) {
return $user->isReseller();
});
$this->bootIntuitSocialite();
}
}

View File

@ -3,6 +3,9 @@
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Leenooks\Http\Middleware\ActiveUser;
use App\Http\Middleware\{Role,SetSite};
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
@ -12,11 +15,12 @@ return Application::configure(basePath: dirname(__DIR__))
)
->withMiddleware(function (Middleware $middleware) {
$middleware->append([
\App\Http\Middleware\SetSite::class,
SetSite::class,
]);
$middleware->alias([
'role' => \App\Http\Middleware\Role::class,
'activeuser' => ActiveUser::class,
'role' => Role::class,
]);
})
->withExceptions(function (Exceptions $exceptions) {

View File

@ -14,10 +14,11 @@
"laravel/dreamscape": "^0.1.0",
"laravel/framework": "^11.0",
"laravel/intuit": "^0.1.7",
"laravel/leenooks": "^11.0",
"laravel/passport": "^12.0",
"laravel/socialite": "^5.15",
"laravel/ui": "^4.5",
"leenooks/laravel": "^11.1",
"leenooks/passkey": "^0.2",
"paypal/paypal-checkout-sdk": "^1.0",
"repat/laravel-job-models": "^0.9",
"web-auth/webauthn-lib": "^4.4"
@ -61,6 +62,10 @@
"laravel-console-summary": {
"type": "vcs",
"url": "https://github.com/leenooks/laravel-console-summary"
},
"passkey": {
"type": "vcs",
"url": "https://gitea.dege.au/laravel/passkey.git"
}
},
"scripts": {

585
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -2,4 +2,6 @@
return [
'language_id' => 1,
'invoice_text' => 'Thank you for using our Internet Services.',
'admin' => env('APP_ADMIN'),
];

258
public/passkey/passkey.js vendored Normal file
View File

@ -0,0 +1,258 @@
/*
* Passkey Implementation
*/
let passkey_debug = false;
/**
* Convert a ArrayBuffer to Base64
* @param {ArrayBuffer} buffer
* @returns {String}
*/
function arrayBufferToBase64(buffer) {
let binary = '';
let bytes = new Uint8Array(buffer);
let len = bytes.byteLength;
for (let i = 0; i < len; i++) {
binary += String.fromCharCode( bytes[ i ] );
}
return window.btoa(binary);
}
/**
* convert RFC 1342-like base64 strings to array buffer
* @param {mixed} obj
* @returns {undefined}
*/
function recursiveBase64StrToArrayBuffer(obj) {
let prefix = '=?BINARY?B?';
let suffix = '?=';
if (typeof obj === 'object') {
for (let key in obj) {
if (typeof obj[key] === 'string') {
let str = obj[key];
if (str.substring(0, prefix.length) === prefix && str.substring(str.length - suffix.length) === suffix) {
str = str.substring(prefix.length, str.length - suffix.length);
let binary_string = window.atob(str);
let len = binary_string.length;
let bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
obj[key] = bytes.buffer;
}
} else {
recursiveBase64StrToArrayBuffer(obj[key]);
}
}
}
}
function passkey_check_browser()
{
// check browser support
if ((! window.fetch) || (! navigator.credentials) || (! navigator.credentials.create))
throw new Error('Browser not supported.');
/*
// Availability of `window.PublicKeyCredential` means WebAuthn is usable.
// `isUserVerifyingPlatformAuthenticatorAvailable` means the feature detection is usable.
// `isConditionalMediationAvailable` means the feature detection is usable.
if (window.PublicKeyCredential &&
PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable &&
PublicKeyCredential.isConditionalMediationAvailable) {
// Check if user verifying platform authenticator is available.
Promise.all([
PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable(),
PublicKeyCredential.isConditionalMediationAvailable(),
]).then(results => {
if (results.every(r => r === true)) {
// Display "Create a new passkey" button
}
});
}
*/
if (passkey_debug)
console.log('Passkey: Browser OK');
return true;
}
/**
* Register/Create a passkey for a user
*/
async function passkey_register(csrf_token,icon_dom,icon,icon_shell_current,icon_shell_success,icon_shell_fail)
{
try {
if (! passkey_check_browser())
return;
// Change our icon so that it is obvious we are doing something
icon_dom.find('i').removeClass(icon).addClass('spinner-grow spinner-grow-sm');
// Get our arguments
var createArgs;
$.ajax({
url: '/passkey/register',
type: 'GET',
dataType: 'json',
async: false,
cache: false,
success: function(data) {
if (passkey_debug)
console.log('Passkey: Get Register Success');
recursiveBase64StrToArrayBuffer(data);
createArgs = data;
},
error: function(e,status,error) {
throw new Error(status || 'Unknown error occurred');
}
});
// Create credentials
try {
const cred = await navigator.credentials.create(createArgs);
const authenticatorAttestationResponse = {
id: cred.id,
rawId: arrayBufferToBase64(cred.rawId),
transports: cred.response.getTransports ? cred.response.getTransports() : null,
clientDataJSON: cred.response.clientDataJSON ? arrayBufferToBase64(cred.response.clientDataJSON) : null,
attestationObject: cred.response.attestationObject ? arrayBufferToBase64(cred.response.attestationObject) : null,
authenticatorAttachment: cred.authenticatorAttachment,
_token: csrf_token,
};
$.ajax({
url: '/passkey/check',
type: 'POST',
data: authenticatorAttestationResponse,
cache: false,
success: function(data) {
if (passkey_debug)
console.log('Passkey: Registration Success');
icon_dom.find('i').addClass(icon).removeClass('spinner-grow spinner-grow-sm');
icon_dom.removeClass(icon_shell_current).addClass(icon_shell_success);
},
error: function(e,status,error) {
throw new Error(status || 'Unknown error occurred');
}
});
} catch (status) {
if (passkey_debug)
console.log(status || 'Passkey: User Aborted Register');
// Restore the icon
icon_dom.removeClass(icon_shell_current).addClass(icon_shell_fail).find('i').addClass(icon).removeClass('spinner-grow spinner-grow-sm');
return;
}
} catch (err) {
window.alert(err || 'An UNKNOWN error occurred?');
}
}
/**
* Check a passkey being presented
*/
async function passkey_check(csrf_token,redirect)
{
if (passkey_debug)
console.log('Passkey: Check User Passkey');
try {
if (! passkey_check_browser())
return;
// Get our arguments
var getArgs;
$.ajax({
url: '/passkey/get',
type: 'GET',
dataType: 'json',
async: false,
cache: false,
success: function(data) {
if (passkey_debug)
console.log('Passkey: Get Args Success');
recursiveBase64StrToArrayBuffer(data);
getArgs = data;
},
error: function(e,status,error) {
throw new Error(status || 'Unknown error occurred');
}
});
// check credentials with hardware
const cred = await navigator.credentials.get(getArgs);
// create object for transmission to server
const authenticatorAttestationResponse = {
id: cred.rawId ? arrayBufferToBase64(cred.rawId) : null,
clientDataJSON: cred.response.clientDataJSON ? arrayBufferToBase64(cred.response.clientDataJSON) : null,
authenticatorData: cred.response.authenticatorData ? arrayBufferToBase64(cred.response.authenticatorData) : null,
signature: cred.response.signature ? arrayBufferToBase64(cred.response.signature) : null,
userHandle: cred.response.userHandle ? arrayBufferToBase64(cred.response.userHandle) : null,
_token: csrf_token
};
$.ajax({
url: '/passkey/process',
type: 'POST',
data: authenticatorAttestationResponse,
cache: false,
success: function(data) {
if (passkey_debug)
console.log('Passkey: Process Success');
// Direct to the home page
window.location.href = (redirect !== undefined) ? redirect : '/';
},
error: function(e,status,error) {
throw new Error(status || 'Unknown error occurred');
}
});
} catch (err) {
window.alert(err || 'An UNKNOWN error occurred?');
}
}
function passkey_create(object,csrf,icon,icon_class_current,icon_class_success,icon_class_nop)
{
if (passkey_debug)
console.log('Passkey: Create Click');
// Availability of `window.PublicKeyCredential` means WebAuthn is usable.
// `isUserVerifyingPlatformAuthenticatorAvailable` means the feature detection is usable.
// `sConditionalMediationAvailable` means the feature detection is usable.
if (window.PublicKeyCredential &&
PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable &&
PublicKeyCredential.isConditionalMediationAvailable) {
// Check if user verifying platform authenticator is available.
Promise.all([
PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable(),
PublicKeyCredential.isConditionalMediationAvailable(),
]).then(results => {
if (passkey_debug)
console.log('Passkey: Browser Supported');
if (results.every(r => r === true)) {
passkey_register(csrf,object,icon,icon_class_current,icon_class_success,icon_class_nop);
} else {
alert('It seems that passkey is NOT supported by your browse (B)');
}
});
} else {
alert('It seems that passkey is NOT supported by your browser (A)');
}
return false;
}

View File

@ -7,7 +7,7 @@ A new invoice has been generated on your account. A summary of that invoice is b
| # | ID | Name | Amount |
| -: | - |:-----| ------:|
@foreach ($invoice->products() as $po)
| {{ $po->count }} | {{ $po->product_id }} | {{ $po->name }} | ${{ number_format($invoice->items->filter(function($item) use ($po) {return $item->product_id == $po->id; })->sum('total'),$invoice->currency()->rounding) }} |
| {{ $po->count }} | {{ $po->product_id }} | {{ $po->name }} | ${{ number_format($invoice->items->filter(function($item) use ($po) {return $item->product_id == $po->id; })->sum('total'),2) }} |
@endforeach
||| Sub Total | ${{ number_format($invoice->sub_total,2) }} |
||| Tax | ${{ number_format($invoice->tax_total,2) }} |

View File

@ -3,7 +3,7 @@
@if(($x=$o->invoices()
->where('active',TRUE)
->orderBy('due_at')
->with(['items.taxes','paymentitems.payment','account'])
->with(['items.taxes','payment_items.payment','account'])
->get()
->filter(function($item) use ($pid) { return $item->due > 0 || $item->payments->search(function($item) use ($pid) { return $item->id == $pid; }) !== FALSE; }))->count())
<table class="table table-hover">
@ -22,12 +22,12 @@
@foreach ($x as $io)
<tr>
<td><a href="{{ url('u/invoice',[$io->id]) }}">{{ $io->sid }}</a></td>
<td>{{ $io->invoice_date->format('Y-m-d') }}</td>
<td>{{ $io->created_at->format('Y-m-d') }}</td>
<td>{{ $io->due_at->format('Y-m-d') }}</td>
<td>{{ number_format($io->total,2) }}</td>
<td>{{ number_format($io->due,2) }}</td>
<td class="text-right">
<input type="text" class="text-right invoice" name="invoices[{{ $io->id }}][id]" value="{{ number_format(($x=$io->paymentitems->filter(function($item) use ($pid) { return $item->payment_id == $pid; })) ? $x->sum('amount') : 0,2) }}">
<input type="text" class="text-right invoice" name="invoices[{{ $io->id }}][id]" value="{{ number_format(($x=$io->payment_items->filter(function($item) use ($pid) { return $item->payment_id == $pid; })) ? $x->sum('amount') : 0,2) }}">
</td>
</tr>
@endforeach

View File

@ -4,7 +4,7 @@
</div>
<div class="card-body">
@if ($x=$user->accounts_all->count())
@if($x=$o->accounts_all->count())
<table class="table table-striped table-hover" id="accounts">
<thead>
<tr>
@ -14,7 +14,10 @@
</tr>
</thead>
<tbody>
@foreach ($user->accounts_all as $ao)
@foreach($o->accounts_all as $ao)
@php
$ao->load(['services:id,active,account_id']);
@endphp
<tr>
<td><a href="{{ url('r/switch/start',$ao->user_id) }}"><i class="fas fa-external-link-alt"></i></a></td>
<td>{{ $ao->name }}</td>

View File

@ -1,4 +1,8 @@
<!-- $o = Account::class -->
@php
$o->load(['services_active.invoiced_service_items_active_recent']);
@endphp
<!-- Show active services -->
<div class="card card-light">
<div class="card-header">
@ -6,7 +10,7 @@
</div>
<div class="card-body">
@if (($x=$o->services->where('active',TRUE))->count())
@if (($x=$o->services_active)->count())
<table class="table table-striped table-hover w-100" id="services_active_{{ $ao->id }}">
<thead>
<tr>

View File

@ -1,3 +1,8 @@
@php
use App\Models\{Account,Service};
$acts = $o->accounts_all->pluck('id');
@endphp
@if($user->isReseller() && ($o->accounts->count() <= 2) && ($x=$o->accounts->pluck('providers')->flatten())->count())
<div class="col-12 col-sm-4 col-md-2">
<div class="info-box">
@ -31,7 +36,7 @@
<div class="info-box-content">
<span class="info-box-text">Active Services</span>
<span class="info-box-number">{{ $o->accounts_all->map(fn($item)=>$item->services->where('active',TRUE)->count())->sum() }} <small>/{{ $o->accounts_all->map(fn($item)=>$item->services->count())->sum() }}</small></span>
<span class="info-box-number">{{ Service::active()->whereIn('account_id',$acts)->count() }} <small>/{{ Service::whereIn('account_id',$acts)->count() }}</small></span>
</div>
</div>
</div>
@ -42,7 +47,7 @@
<div class="info-box-content">
<span class="info-box-text">Account Balance</span>
<span class="info-box-number"><small>$</small> {{ number_format(($x=$o->accounts_all->map(fn($item)=>$item->invoiceSummaryDue()->get()->pluck('_balance'))->flatten())->sum(),2) }}</span>
<span class="info-box-number"><small>$</small> {{ number_format(($x=Account::InvoicesDue()->filter(fn($item)=>$acts->contains($item->account_id)))->sum('_balance'),2) }}</span>
</div>
</div>
</div>

View File

@ -1,3 +1,7 @@
@php
use App\Models\{Checkout,Service};
@endphp
<!-- $o = Invoice::class -->
@extends('adminlte::layouts.app')
@ -49,7 +53,7 @@
{!! $o->account->address->join('<br>') !!}
<br><br>
<strong>Email:</strong> {{ $o->account->user->email }}<br>
@if ($o->account->phone)
@if($o->account->phone)
<strong>Phone:</strong> {{ $o->account->phone }}<br>
@endif
</address>
@ -58,7 +62,7 @@
<div class="ml-auto col-3">
<table class="table table-borderless text-right" style="font-size: 1.1rem;">
<tr >
<td class="p-0">Issue Date:</td><td class="p-0"><strong>{{ $o->invoice_date->format('Y-m-d') }}</strong></td>
<td class="p-0">Issue Date:</td><td class="p-0"><strong>{{ $o->created_at->format('Y-m-d') }}</strong></td>
</tr>
<tr >
<td class="p-0">Account:</td><td class="p-0"><strong>{{ $o->account->sid }}</strong></td>
@ -70,12 +74,12 @@
<td class="p-0">Payment Due:</td><td class="p-0"><strong>{{ $o->due_at->format('Y-m-d') }}</strong></td>
</tr>
<tr>
<td class="p-0">This Invoice Due:</td><td class="p-0"><strong>${{ number_format($o->total,$o->currency()->rounding) }}</strong></td>
<td class="p-0">This Invoice Due:</td><td class="p-0"><strong>${{ number_format($o->total,2) }}</strong></td>
</tr>
{{--
<!-- @todo -->
<tr>
<td class="p-0">Total Account Due:</td><td class="p-0"><strong>${{ number_format($o->account->due,$o->currency()->rounding) }}</strong></td>
<td class="p-0">Total Account Due:</td><td class="p-0"><strong>${{ number_format($o->account->due,2) }}</strong></td>
</tr>
--}}
</table>
@ -97,29 +101,29 @@
</thead>
<tbody>
@foreach ($o->products() as $po)
@foreach($o->summary_products() as $item)
<tr id="invoice-services">
<td>{{ $po->count }}</td>
<td>#{{ $po->lid }}</td>
<td colspan="2">{{ $po->name }}</td>
<td colspan="3" class="text-right">${{ number_format($o->items->filter(function($item) use ($po) {return $item->product_id == $po->id; })->sum('total'),$o->currency()->rounding) }}</td>
<td>{{ $item['services']->count() }}</td>
<td>#{{ $item['product']->lid }}</td>
<td colspan="2">{{ $item['product']->name }}</td>
<td colspan="3" class="text-right">${{ number_format($item['total'],2) }}</td>
</tr>
@foreach ($o->product_services($po) as $so)
<tr id="invoice-service-items" class="invoice-services @if($o->products()->count() > 1) d-print-table-row @endif">
@foreach(Service::whereIn('id',$item['services'])->get() as $so)
<tr id="invoice-service-items" class="invoice-services @if($item['services']->count() > 1) d-print-table-row @endif">
<td colspan="2">&nbsp;</td>
<td colspan="2">Service: <strong>{{ $so->sid }}: [{{ $so->name }}]</strong></td>
<td>&nbsp;</td>
<td class="text-right">${{ number_format($o->product_service_items($po,$so)->sum('total'),$o->currency()->rounding) }}</td>
<td class="text-right">${{ number_format($o->product_service_items($item['product'],$so)->sum('total'),2) }}</td>
<td>&nbsp;</td>
</tr>
@foreach ($o->product_service_items($po,$so) as $io)
@foreach($o->product_service_items($item['product'],$so) as $io)
<tr class="invoice-service-items d-print-table-row">
<td colspan="2">&nbsp;</td>
<td width="5%">&nbsp;</td>
<td>{{ $io->item_type_name }}</td>
<td class="text-right">${{ number_format($io->total,$o->currency()->rounding) }}</td>
<td class="text-right">${{ number_format($io->total,2) }}</td>
<td colspan="2">&nbsp;</td>
</tr>
@endforeach
@ -141,7 +145,7 @@
<p class="lead">Payment Methods:</p>
<table class="table table-borderless">
@foreach (\App\Models\Checkout::available() as $cho)
@foreach(Checkout::available() as $cho)
<tr>
<td style="width: 50px;"><i class="fa-2x fa-fw {{ $cho->icon }}"></i></td>
<td>{{ $cho->name }}</td>
@ -152,7 +156,7 @@
</table>
<p class="text-muted well well-sm no-shadow" style="position: absolute;bottom: 0;left: 0;">
{!! $o->invoice_text !!}
{{ config('osb.invoice_text') }}
</p>
</div>
@ -161,12 +165,12 @@
<table class="table">
<tr>
<th colspan="3" style="width:50%">Subtotal:</th>
<td colspan="2" class="text-right">${{ number_format($o->sub_total,$o->currency()->rounding) }}</td>
<td colspan="2" class="text-right">${{ number_format($o->sub_total,2) }}</td>
</tr>
<tr>
<th>&nbsp;</th>
<th>Tax (GST 10%)</th>
<td colspan="2" class="text-right">${{ number_format($o->total_tax,$o->currency()->rounding) }}</td>
<td colspan="2" class="text-right">${{ number_format($o->tax_total,2) }}</td>
</tr>
<tr>
<th>&nbsp;</th>
@ -176,23 +180,23 @@
</tr>
<tr>
<th colspan="2">Total:</th>
<td colspan="2" class="text-right">${{ number_format($o->total,$o->currency()->rounding) }}</td>
<td colspan="2" class="text-right">${{ number_format($o->total,2) }}</td>
</tr>
@if($o->id)
<tr>
<th>&nbsp;</th>
<th>Payments To Clear:</th>
<td colspan="2" class="text-right">${{ number_format($o->paid_pending,$o->currency()->rounding) }}</td>
<td colspan="2" class="text-right">${{ number_format($o->paid_pending,2) }}</td>
</tr>
<tr>
<th>&nbsp;</th>
<th>Payments:</th>
<td>#{{ $o->payments->pluck('id')->join(', #') }}</td>
<td class="text-right">${{ number_format($o->paid,$o->currency()->rounding) }}</td>
<td>#{{ $o->payment_items_active->pluck('payment_id')->join(', #') }}</td>
<td class="text-right">${{ number_format($o->paid,2) }}</td>
</tr>
<tr style="font-size: 145%">
<th colspan="2">Invoice Due:</th>
<td colspan="2" class="text-right">${{ number_format($o->due,$o->currency()->rounding) }}</td>
<td colspan="2" class="text-right">${{ number_format($o->due,2) }}</td>
</tr>
@endif
</table>

View File

@ -0,0 +1,126 @@
@extends('adminlte::layouts.app')
@section('htmlheader_title')
{{ ($o??$user)->role }} Settings
@endsection
@section('page_title')
{{ ($o??$user)->name_full }}
@endsection
@section('contentheader_title')
{{ ($o??$user)->name_full }}
@endsection
@section('contentheader_description')
{{ ($o??$user)->role }}
@endsection
@use(App\Models\Country)
<!-- ($o??$user)=User::class -->
@section('main-content')
<div class="row">
<div class="col">
<div class="card">
<div class="card-header">
<div class="card-title">Update Settings</div>
@session('success')<x-leenooks::success class="float-right">{{ $value }}</x-leenooks::success>@endsession
</div>
<form method="POST" action="{{ url(request()->path(),[($o??$user)->id]) }}">
@csrf
<div class="card-body">
<div class="row">
<div class="col-12 col-sm-6">
<div class="row">
<div class="col">
<x-leenooks::form.email id="email" name="email" icon="fa-at" label="Email" :value="($o??$user)->email ?? ''"/>
</div>
</div>
<div class="row">
<div class="col">
<x-leenooks::form.password id="password" name="password" icon="fa-lock" label="Password"/>
</div>
</div>
<div class="row">
<div class="col">
<x-leenooks::form.password id="password_confirm" name="password_confirmation" icon="fa-lock" label="Password Confirm"/>
</div>
</div>
<div class="row">
<div class="col pb-3">
<button type="reset" id="passkey" name="passkey" @class(['btn','btn-success'=>$x=($o??$user)->passkey,'btn-outline-secondary'=>! $x])><i class="fas fa-fw fa-key"></i> Passkey</button>
</div>
</div>
</div>
<div class="col-12 col-sm-6">
<div class="row">
<div class="col-12 col-md-6">
<x-leenooks::form.text name="firstname" icon="fa-headset" label="First Name" :value="($o??$user)->firstname ?? ''"/>
</div>
<div class="col-12 col-md-6">
<x-leenooks::form.text name="lastname" icon="fa-signature" label="Last Name" :value="($o??$user)->lastname ?? ''"/>
</div>
</div>
<div class="row">
<div class="col">
<x-leenooks::form.text name="address1" icon="fa-map" label="Address" :value="($o??$user)->address1 ?? ''"/>
</div>
</div>
<div class="row">
<div class="col">
<x-leenooks::form.text name="address2" :value="($o??$user)->address2 ?? ''"/>
</div>
</div>
<div class="row">
<div class="col-12 col-md-4">
<x-leenooks::form.text name="city" label="City" :value="($o??$user)->city ?? ''"/>
</div>
<div class="col-12 col-md-4">
<x-leenooks::form.text name="state" label="State" :value="($o??$user)->state ?? ''"/>
</div>
<div class="col-12 col-md-4">
<x-leenooks::form.text name="postcode" label="Post Code" :value="($o??$user)->postcode ?? ''"/>
</div>
</div>
<div class="row">
<div class="col-12 col-md-6">
<x-leenooks::form.select id="country" name="country_id" icon="fa-globe" label="Country" :value="($o??$user)->country_id ?? ''" :options="Country::select(['id','name'])->active()->get()->map(function($item) { $item->value = $item->name; return $item; })->toArray()"/>
</div>
</div>
</div>
</div>
<div class="row pt-3">
<div class="col">
<button type="reset" name="cancel" class="btn btn-danger">Cancel</button>
<button type="submit" name="submit" class="btn btn-success float-right">Save</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
@endsection
@section('page-scripts')
<!-- Passkeys -->
<script type='text/javascript' src='{{ asset('/passkey/passkey.js') }}'></script>
<script type="text/javascript">
$(document).ready(function() {
$('#passkey').on('click',function(item) {
return passkey_create($(this),'{{ csrf_token() }}','fa-key','{{ ($o??$user)->passkey ? 'btn-success' : 'btn-outline-secondary' }}','btn-success','{{ ($o??$user)->passkey ? 'btn-secondary' : 'btn-outline-secondary' }}');
});
});
</script>
@append

View File

@ -0,0 +1,161 @@
<!-- Main Header -->
<!-- Navbar -->
<nav class="main-header navbar navbar-expand bg-white navbar-light border-bottom">
<!-- Left navbar links -->
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" data-widget="pushmenu" href="#"><i class="fas fa-bars"></i></a>
</li>
</ul>
<!-- SEARCH FORM -->
<form class="form-inline ml-3">
<div class="input-group input-group-sm">
<input class="form-control form-control-navbar" name="q" type="search" placeholder="Search" aria-label="Search" autocomplete="off">
<div class="input-group-append">
<span class="input-group-text"><i class="fas fa-search"></i></span>
<span class="p-1 d-none" name="searching"><i class="fas fa-spinner fa-spin" style="margin-top: .33em; width: 1em; height: 1em;"></i></span>
</div>
<div id="search_results"></div>
</div>
</form>
<!-- Right navbar links -->
<ul class="navbar-nav ml-auto">
@include('adminlte::layouts.partials.topmenu')
@if(Auth::check())
<!-- Profile Settings -->
<li class="nav-item dropdown">
<a class="nav-link" data-toggle="dropdown" href="#">
<i class="fas fa-cog"></i>
</a>
<div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
<span class="dropdown-item dropdown-header @if($user->switched) bg-danger @endif">
@if($user->switched)
SUDO (<small>{{ $user->name ?: 'User Name' }}</small>)
@else
{{ $user->name ?: 'User Name' }}
@endif
</span>
<div class="dropdown-divider"></div>
<a href="{{ url('u/settings') }}" class="dropdown-item">
<i class="fas fa-user mr-2"></i> Settings
</a>
<div class="dropdown-divider"></div>
@if ($user->switched)
<a href="{{ url('/admin/switch/stop') }}" class="dropdown-item">
<i class="fas fa-sign-out-alt mr-2"></i> {{ trans('adminlte_lang::message.switchoff') }}
</a>
@else
<a href="{{ url('logout') }}" class="dropdown-item">
<i class="fas fa-sign-out-alt mr-2"></i> Log Out
</a>
@endif
</div>
</li>
@else
<a href="{{ url()->current().'?login=1' }}" class="text-muted pr-2"><i class="fas fa-lock"></i></a>
@endif
<!-- Control Side Bar -->
@isset($controlsidebar)
<li class="nav-item">
<a class="nav-link" data-widget="control-sidebar" data-slide="true" href="#">
<i class="fas fa-th"></i>
</a>
</li>
@endisset
</ul>
</nav>
@section('page-scripts')
<style>
/* Solid border */
div.typeahead.dropdown-menu > .dropdown-header {
color: #000000;
text-align: left;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
$('input[name=q]').typeahead({
autoSelect: false,
scrollHeight: 10,
theme: 'bootstrap4',
delay: 500,
minLength: 2,
items: {{ isset($search_limit) ? $search_limit : 100 }},
fitToElement: false,
selectOnBlur: false,
appendTo: "#search_results",
source: function (query,process) {
search('{{ url("search",['date'=>isset($ido) ? $ido->id : NULL]) }}',query,process);
},
matcher: function () { return true; },
// Disable sorting and just return the items (items should by the ajax method)
sorter: function(items) {
return items;
},
updater: function (item) {
window.parent.location.href = item.value;
},
})
.on('keyup keypress', function(event) {
var key = event.keyCode || event.which;
if (key === 13) {
event.preventDefault();
return false;
}
});
});
var c=0;
var search = _.debounce(function(url,query,process,icon){
$.ajax({
url : url,
type : 'GET',
data : 'term=' + query,
dataType : 'JSON',
async : true,
cache : false,
beforeSend : function() {
if (c++ == 0) {
if (icon)
$('i[name='+icon+']').addClass("fa-spin");
else {
$('span[name=searching]').removeClass("d-none");
}
}
},
success : function(data) {
// if json is null, means no match, won't do again.
if(data==null || (data.length===0)) return;
process(data);
},
complete : function() {
if (--c == 0) {
if (icon)
$('i[name='+icon+']').removeClass("fa-spin");
else {
$('span[name=searching]').addClass("d-none");
}
}
},
statusCode: {
401: function() {
window.parent.location.href = '{{ route('login') }}';
}
}
})
}, 500);
</script>
@append

View File

@ -1,5 +1,7 @@
<?php
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
use Leenooks\Controllers\SwitchUserController;
use App\Http\Controllers\{AdminController,
@ -8,7 +10,6 @@ use App\Http\Controllers\{AdminController,
CheckoutController,
HomeController,
InvoiceController,
MediaController,
OrderController,
PaypalController,
ProductController,
@ -16,7 +17,6 @@ use App\Http\Controllers\{AdminController,
ServiceController,
SupplierController,
UserController,
WelcomeController,
Wholesale\ReportController};
use App\Models\Supplier;
@ -44,6 +44,8 @@ Auth::routes([
Route::get('logout',[LoginController::class,'logout'])
->name('logout-get');
Route::redirect('passkey/loggedin','/home');
// Account linking to OPENID host
Route::group([],function() {
Route::get('auth/{socialProvider}',[SocialLoginController::class,'redirectToProvider']);
@ -58,10 +60,6 @@ Route::get('admin/switch/stop',[SwitchUserController::class,'switch_stop'])
->middleware('auth')
->name('switch.stop');
// Generic Image Renderer - Render images that we dont have with a generic image
Route::get('image/generic/{width}/{height}/{color}/{name?}',[MediaController::class,'image'])
->name('image');
// Our Admin Routes - for wholesalers
Route::group(['middleware'=>['auth','role:wholesaler'],'prefix'=>'a'],function() {
// Site Setup
@ -193,6 +191,9 @@ Route::group(['middleware'=>['auth'],'prefix'=>'u'],function() {
Route::get('service/{o}/change/{status}',[ServiceController::class,'change'])
->where('o','[0-9]+')
->middleware('can:progress,o,status');
Route::view('settings','theme.backend.adminlte.user.settings');
Route::post('settings/{o}',[UserController::class,'edit']);
});
// Doorman Code Routes