akaunting 3.0 (the last dance)
This commit is contained in:
18
app/View/Components/Contacts/Form/Address.php
Normal file
18
app/View/Components/Contacts/Form/Address.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Contacts\Form;
|
||||
|
||||
use App\Abstracts\View\Components\Contacts\Form as Component;
|
||||
|
||||
class Address extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.contacts.form.address');
|
||||
}
|
||||
}
|
18
app/View/Components/Contacts/Form/Billing.php
Normal file
18
app/View/Components/Contacts/Form/Billing.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Contacts\Form;
|
||||
|
||||
use App\Abstracts\View\Components\Contacts\Form as Component;
|
||||
|
||||
class Billing extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.contacts.form.billing');
|
||||
}
|
||||
}
|
18
app/View/Components/Contacts/Form/Buttons.php
Normal file
18
app/View/Components/Contacts/Form/Buttons.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Contacts\Form;
|
||||
|
||||
use App\Abstracts\View\Components\Contacts\Form as Component;
|
||||
|
||||
class Buttons extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.contacts.form.buttons');
|
||||
}
|
||||
}
|
18
app/View/Components/Contacts/Form/Content.php
Normal file
18
app/View/Components/Contacts/Form/Content.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Contacts\Form;
|
||||
|
||||
use App\Abstracts\View\Components\Contacts\Form as Component;
|
||||
|
||||
class Content extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.contacts.form.content');
|
||||
}
|
||||
}
|
18
app/View/Components/Contacts/Form/General.php
Normal file
18
app/View/Components/Contacts/Form/General.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Contacts\Form;
|
||||
|
||||
use App\Abstracts\View\Components\Contacts\Form as Component;
|
||||
|
||||
class General extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.contacts.form.general');
|
||||
}
|
||||
}
|
18
app/View/Components/Contacts/Index/Buttons.php
Normal file
18
app/View/Components/Contacts/Index/Buttons.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Contacts\Index;
|
||||
|
||||
use App\Abstracts\View\Components\Contacts\Index as Component;
|
||||
|
||||
class Buttons extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.contacts.index.buttons');
|
||||
}
|
||||
}
|
18
app/View/Components/Contacts/Index/Content.php
Normal file
18
app/View/Components/Contacts/Index/Content.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Contacts\Index;
|
||||
|
||||
use App\Abstracts\View\Components\Contacts\Index as Component;
|
||||
|
||||
class Content extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.contacts.index.content');
|
||||
}
|
||||
}
|
18
app/View/Components/Contacts/Index/MoreButtons.php
Normal file
18
app/View/Components/Contacts/Index/MoreButtons.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Contacts\Index;
|
||||
|
||||
use App\Abstracts\View\Components\Contacts\Index as Component;
|
||||
|
||||
class MoreButtons extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.contacts.index.more-buttons');
|
||||
}
|
||||
}
|
72
app/View/Components/Contacts/Script.php
Normal file
72
app/View/Components/Contacts/Script.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Contacts;
|
||||
|
||||
use App\Abstracts\View\Component;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Traits\ViewComponents;
|
||||
|
||||
class Script extends Component
|
||||
{
|
||||
use ViewComponents;
|
||||
|
||||
public const OBJECT_TYPE = 'contact';
|
||||
public const DEFAULT_TYPE = 'customer';
|
||||
public const DEFAULT_PLURAL_TYPE = 'customers';
|
||||
|
||||
/** @var string */
|
||||
public $type;
|
||||
|
||||
public $contact;
|
||||
|
||||
public $currencies;
|
||||
|
||||
public $currency_code;
|
||||
|
||||
/** @var string */
|
||||
public $alias;
|
||||
|
||||
/** @var string */
|
||||
public $folder;
|
||||
|
||||
/** @var string */
|
||||
public $file;
|
||||
|
||||
/**
|
||||
* Create a new component instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
string $type = '', $contact = false, $currencies = [],
|
||||
string $alias = '', string $folder = '', string $file = ''
|
||||
) {
|
||||
$this->type = $type;
|
||||
$this->contact = $contact;
|
||||
$this->currencies = $this->getCurrencies($currencies);
|
||||
$this->currency_code = ($contact) ? $contact->currency_code : setting('default.currency');
|
||||
|
||||
$this->alias = $this->getAlias($type, $alias);
|
||||
$this->folder = $this->getScriptFolder($type, $folder);
|
||||
$this->file = $this->getScriptFile($type, $file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.contacts.script');
|
||||
}
|
||||
|
||||
protected function getCurrencies($currencies)
|
||||
{
|
||||
if (!empty($currencies)) {
|
||||
return $currencies;
|
||||
}
|
||||
|
||||
return Currency::enabled()->orderBy('name')->get()->makeHidden(['id', 'company_id', 'created_at', 'updated_at', 'deleted_at']);
|
||||
}
|
||||
}
|
18
app/View/Components/Contacts/Show/Buttons.php
Normal file
18
app/View/Components/Contacts/Show/Buttons.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Contacts\Show;
|
||||
|
||||
use App\Abstracts\View\Components\Contacts\Show as Component;
|
||||
|
||||
class Buttons extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.contacts.show.buttons');
|
||||
}
|
||||
}
|
102
app/View/Components/Contacts/Show/Content.php
Normal file
102
app/View/Components/Contacts/Show/Content.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Contacts\Show;
|
||||
|
||||
use App\Utilities\Date;
|
||||
use App\Abstracts\View\Components\Contacts\Show as Component;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Pagination\Paginator;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
class Content extends Component
|
||||
{
|
||||
public $counts;
|
||||
|
||||
public $totals;
|
||||
|
||||
public $transactions;
|
||||
|
||||
public $documents;
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
$totals = [
|
||||
'paid' => 0,
|
||||
'open' => 0,
|
||||
'overdue' => 0,
|
||||
];
|
||||
|
||||
$this->counts = [];
|
||||
|
||||
// Handle documents
|
||||
$this->documents = $this->contact->documents()->with('transactions')->isNotRecurring()->get();
|
||||
|
||||
$this->counts['documents'] = $this->documents->count();
|
||||
|
||||
$today = Date::today()->toDateString();
|
||||
|
||||
foreach ($this->documents as $item) {
|
||||
// Already in transactions
|
||||
if ($item->status == 'paid' || $item->status == 'cancelled') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$transactions = 0;
|
||||
|
||||
foreach ($item->transactions as $transaction) {
|
||||
$transactions += $transaction->getAmountConvertedToDefault();
|
||||
}
|
||||
|
||||
// Check if it's open or overdue invoice
|
||||
if ($item->due_at > $today) {
|
||||
$totals['open'] += $item->getAmountConvertedToDefault() - $transactions;
|
||||
} else {
|
||||
$totals['overdue'] += $item->getAmountConvertedToDefault() - $transactions;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle payments
|
||||
$this->transactions = $this->contact->transactions()->with('account', 'category')->isNotRecurring()->get();
|
||||
|
||||
$this->counts['transactions'] = $this->transactions->count();
|
||||
|
||||
// Prepare data
|
||||
$this->transactions->each(function ($item) use (&$totals) {
|
||||
$totals['paid'] += $item->getAmountConvertedToDefault();
|
||||
});
|
||||
|
||||
$this->totals = $totals;
|
||||
|
||||
$limit = (int) request('limit', setting('default.list_limit', '25'));
|
||||
$this->transactions = $this->paginate($this->transactions->sortByDesc('paid_at'), $limit);
|
||||
$this->documents = $this->paginate($this->documents->sortByDesc('issued_at'), $limit);
|
||||
|
||||
return view('components.contacts.show.content');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a pagination collection.
|
||||
*
|
||||
* @param array|Collection $items
|
||||
* @param int $perPage
|
||||
* @param int $page
|
||||
* @param array $options
|
||||
*
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function paginate($items, $perPage = 15, $page = null, $options = [])
|
||||
{
|
||||
$perPage = $perPage ?: (int) request('limit', setting('default.list_limit', '25'));
|
||||
|
||||
$page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
|
||||
|
||||
$items = $items instanceof Collection ? $items : Collection::make($items);
|
||||
|
||||
return new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(), $perPage, $page, $options);
|
||||
}
|
||||
}
|
18
app/View/Components/Contacts/Show/MoreButtons.php
Normal file
18
app/View/Components/Contacts/Show/MoreButtons.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Contacts\Show;
|
||||
|
||||
use App\Abstracts\View\Components\Contacts\Show as Component;
|
||||
|
||||
class MoreButtons extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('components.contacts.show.more-buttons');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user