-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
1,211 additions
and
585 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire; | ||
|
||
use App\Models\Volume; | ||
use Exception; | ||
use Illuminate\Support\Facades\DB; | ||
use Livewire\Component; | ||
|
||
class Overview extends Component | ||
{ | ||
public $volumeStatistics = []; | ||
|
||
public $articleStatistics = []; | ||
|
||
public string $search; | ||
|
||
protected $listeners = [ | ||
'$refresh', | ||
'search' => 'filter', | ||
]; | ||
|
||
public function render() | ||
{ | ||
$this->volumeStatistics = $this->getVolumeStatistics(); | ||
$this->articleStatistics = $this->getArticleStatistics(); | ||
|
||
return view('livewire.overview'); | ||
} | ||
|
||
public function filter($filter): void | ||
{ | ||
$this->search = $filter; | ||
} | ||
|
||
private function getVolumeStatistics() | ||
{ | ||
$volumes = DB::table('volumes') | ||
->join('series', 'volumes.series_id', '=', 'series.id') | ||
->leftJoin('publishers', 'series.publisher_id', '=', 'publishers.id'); | ||
if (!empty($this->search)) { | ||
$volumes->where('isbn', 'like', '%' . $this->search . '%') | ||
->orWhere('series.name', 'like', '%' . $this->search . '%') | ||
->orWhere('publishers.name', 'like', '%' . $this->search . '%'); | ||
} | ||
$volumeStatistics = $volumes->select([ | ||
DB::raw('COALESCE(sum(case when volumes.status = 0 then 1 else 0 end), 0) as new'), | ||
DB::raw('COALESCE(sum(case when volumes.status = 1 then 1 else 0 end), 0) as ordered'), | ||
DB::raw('COALESCE(sum(case when volumes.status = 2 then 1 else 0 end), 0) as shipped'), | ||
DB::raw('COALESCE(sum(case when volumes.status = 3 then 1 else 0 end), 0) as delivered'), | ||
DB::raw('COALESCE(sum(case when volumes.status = 4 then 1 else 0 end), 0) as `read`'), | ||
DB::raw('COALESCE(sum(case when volumes.status = 3 OR volumes.status = 4 then price else 0 end), 0) as price'), | ||
DB::raw('count(*) as total'), | ||
])->first(); | ||
|
||
return json_decode(json_encode($volumeStatistics), true); | ||
} | ||
|
||
private function getArticleStatistics() | ||
{ | ||
$articles = DB::table('articles'); | ||
if (!empty($this->search)) { | ||
$articles->where('name', 'like', '%' . $this->search . '%'); | ||
} | ||
$articleStatistics = $articles->select([ | ||
DB::raw('COALESCE(sum(case when status = 0 then 1 else 0 end), 0) as new'), | ||
DB::raw('COALESCE(sum(case when status = 1 then 1 else 0 end), 0) as ordered'), | ||
DB::raw('COALESCE(sum(case when status = 2 then 1 else 0 end), 0) as shipped'), | ||
DB::raw('COALESCE(sum(case when status = 3 then 1 else 0 end), 0) as delivered'), | ||
DB::raw('0 as `read`'), | ||
DB::raw('COALESCE(sum(case when status = 3 then price else 0 end), 0) as price'), | ||
DB::raw('count(*) as total'), | ||
])->first(); | ||
|
||
return json_decode(json_encode($articleStatistics), true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Publishers; | ||
|
||
use App\Models\Publisher; | ||
use Livewire\Component; | ||
|
||
class CreatePublisher extends Component | ||
{ | ||
public Publisher $publisher; | ||
|
||
protected $rules = [ | ||
'publisher.name' => 'required', | ||
]; | ||
|
||
public function updated($property, $value): void | ||
{ | ||
$this->validateOnly($property); | ||
} | ||
|
||
public function mount(): void | ||
{ | ||
$this->publisher = new Publisher(); | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.publishers.create-publisher')->extends('layouts.app')->section('content'); | ||
} | ||
|
||
public function save() | ||
{ | ||
$this->validate(); | ||
|
||
$this->publisher->save(); | ||
toastr()->addSuccess(__(':name has been created', ['name' => $this->publisher->name])); | ||
|
||
return redirect()->route('publishers.index'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Publishers; | ||
|
||
use App\Models\Publisher; | ||
use App\Models\Series; | ||
use Jantinnerezo\LivewireAlert\LivewireAlert; | ||
use Livewire\Component; | ||
|
||
class EditPublisher extends Component | ||
{ | ||
use LivewireAlert; | ||
|
||
public Publisher $publisher; | ||
|
||
protected $rules = [ | ||
'publisher.name' => 'required', | ||
]; | ||
|
||
protected $listeners = [ | ||
'confirmedDelete', | ||
]; | ||
|
||
public function updated($property, $value): void | ||
{ | ||
$this->validateOnly($property); | ||
} | ||
|
||
public function mount(Publisher $publisher): void | ||
{ | ||
$this->publisher = $publisher; | ||
} | ||
|
||
public function render() | ||
{ | ||
return view('livewire.publishers.edit-publisher')->extends('layouts.app')->section('content'); | ||
} | ||
|
||
public function save(): void | ||
{ | ||
$this->validate(); | ||
|
||
$this->publisher->save(); | ||
toastr()->livewire()->addSuccess(__(':name has been updated', ['name' => $this->publisher->name])); | ||
} | ||
|
||
public function delete(): void | ||
{ | ||
$this->confirm(__('Are you sure you want to delete :name?', ['name' => $this->publisher->name]), [ | ||
'confirmButtonText' => __('Delete'), | ||
'cancelButtonText' => __('Cancel'), | ||
'onConfirmed' => 'confirmedDelete', | ||
]); | ||
} | ||
|
||
public function confirmedDelete(): void | ||
{ | ||
Series::wherePublisherId($this->publisher->id)->update(['publisher_id' => null]); | ||
$this->publisher->delete(); | ||
toastr()->addSuccess(__(':name has been deleted', ['name' => $this->publisher->name])); | ||
redirect()->route('publishers.index'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire\Publishers; | ||
|
||
use App\Models\Publisher; | ||
use Livewire\Component; | ||
|
||
class PublisherTable extends Component | ||
{ | ||
public $publishers; | ||
|
||
public function render() | ||
{ | ||
$this->publishers = Publisher::orderBy('name')->get(); | ||
|
||
return view('livewire.publishers.publisher-table')->extends('layouts.app')->section('content'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.