Skip to content

Commit

Permalink
Menambah riwayat pembayaran pada edit penginapan
Browse files Browse the repository at this point in the history
  • Loading branch information
itsfaqih committed Jul 27, 2020
1 parent 0d521b9 commit 3164467
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 32 deletions.
5 changes: 5 additions & 0 deletions app/Bill.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public function logdging()
{
return $this->belongsTo(Lodging::class);
}

public function invoice()
{
return $this->hasOne(Invoice::class);
}

public function scopeFilter($query, array $filters)
{
Expand Down
13 changes: 11 additions & 2 deletions app/Http/Controllers/LodgingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function index()
'deleted_at' => $lodging->deleted_at,
];
}),
// ->only('id', 'room_id', 'renter_id', 'start_at', 'end_at', 'deleted_at')
]);
}

Expand Down Expand Up @@ -64,7 +63,17 @@ public function edit(Lodging $lodging)
'room' => $lodging->room,
'start_at' => $lodging->start_at->format('Y-m-d'),
'end_at' => $lodging->end_at->format('Y-m-d'),
'deleted_at' => $lodging->deleted_at
'deleted_at' => $lodging->deleted_at,
'payments' => $lodging->payments->transform(function ($payment) {
return [
'id' => $payment->id,
'item' => $payment->invoice->bill->name,
'amount' => $payment->amount,
'issued_at' => $payment->invoice->created_at->format('d F Y'),
'created_at' => $payment->created_at->format('d F Y'),
'deleted_at' => $payment->deleted_at
];
})
],
'rooms' => Room::all(),
'renters' => Renter::all(),
Expand Down
5 changes: 5 additions & 0 deletions app/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public function bill()
return $this->belongsTo(Bill::class);
}

public function payment()
{
return $this->hasOne(Payment::class);
}

public function scopeFilter($query, array $filters)
{
$query->when($filters['search'] ?? null, function ($query, $search) {
Expand Down
18 changes: 18 additions & 0 deletions app/Lodging.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

use Carbon\Carbon;
use Illuminate\Database\Eloquent\SoftDeletes;
use Staudenmeir\EloquentHasManyDeep\HasRelationships;

class Lodging extends Model
{
use SoftDeletes;
use HasRelationships;

protected $dates = ['start_at', 'end_at'];

public function renter()
Expand All @@ -20,6 +23,21 @@ public function room()
return $this->belongsTo(Room::class);
}

public function bills()
{
return $this->hasMany(Bill::class);
}

public function invoices()
{
return $this->hasManyThrough(Invoice::class, Bill::class);
}

public function payments()
{
return $this->hasManyDeep(Payment::class, [Bill::class, Invoice::class]);
}

public function scopeFilter($query, array $filters)
{
$query->when($filters['search'] ?? null, function ($query, $search) {
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"laravel/ui": "^2.0",
"league/glide": "2.0.x-dev",
"reinink/remember-query-strings": "^0.1.0",
"staudenmeir/eloquent-has-many-deep": "^1.7",
"tightenco/ziggy": "^0.8.0"
},
"autoload": {
Expand Down
45 changes: 44 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 40 additions & 29 deletions resources/js/Pages/Lodgings/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import TextInput from '@/Shared/TextInput';
import SelectInput from '@/Shared/SelectInput';
import TrashedMessage from '@/Shared/TrashedMessage';
import Icon from '@/Shared/Icon';
import { currency } from '@/utils';

export default () => {
const { errors, lodging, renters, rooms } = usePage();
Expand Down Expand Up @@ -73,7 +74,7 @@ export default () => {
<div className="max-w-3xl overflow-hidden bg-white rounded shadow">
<form onSubmit={handleSubmit}>
<div className="flex flex-wrap p-8 -mb-8 -mr-6">
<SelectInput
<SelectInput
className="w-full pb-8 pr-6 lg:w-1/2"
label="Penyewa"
name="renter_id"
Expand All @@ -82,11 +83,11 @@ export default () => {
onChange={handleChange}
>
<option value="" disabled>Pilih Penyewa</option>
{
renters.map((renter, index) => (
<option key={index} value={renter.id}>{renter.name}</option>
))
}
{
renters.map((renter, index) => (
<option key={index} value={renter.id}>{renter.name}</option>
))
}
</SelectInput>
<SelectInput
className="w-full pb-8 pr-6 lg:w-1/2"
Expand All @@ -97,15 +98,15 @@ export default () => {
onChange={handleChange}
>
<option value="" disabled>Pilih Kamar</option>
{
rooms.map((room, index) => (
<option key={index} value={room.id}>{room.number}</option>
))
}
{
rooms.map((room, index) => (
<option key={index} value={room.id}>{room.number}</option>
))
}
</SelectInput>
<TextInput
className="w-full pb-8 pr-6 lg:w-1/2"
label="Start at"
label="Mulai sewa"
name="start_at"
type="date"
errors={errors.start_at}
Expand All @@ -114,7 +115,7 @@ export default () => {
/>
<TextInput
className="w-full pb-8 pr-6 lg:w-1/2"
label="End at"
label="Selesai sewa"
name="end_at"
type="date"
errors={errors.end_at}
Expand All @@ -138,32 +139,33 @@ export default () => {
</div>
</form>
</div>
{/* <h2 className="mt-12 text-2xl font-bold">Contacts</h2>
<h2 className="mt-12 text-2xl font-bold">Riwayat Pembayaran</h2>
<div className="mt-6 overflow-x-auto bg-white rounded shadow">
<table className="w-full whitespace-no-wrap">
<thead>
<tr className="font-bold text-left">
<th className="px-6 pt-5 pb-4">Name</th>
<th className="px-6 pt-5 pb-4">City</th>
<th className="px-6 pt-5 pb-4">Item Tagihan</th>
<th className="px-6 pt-5 pb-4">Jumlah</th>
<th className="px-6 pt-5 pb-4">Tanggal Penagihan</th>
<th className="px-6 pt-5 pb-4" colSpan="2">
Phone
Tanggal Pembayaran
</th>
</tr>
</thead>
<tbody>
{lodging.contacts.map(
({ id, name, phone, city, deleted_at }) => {
{lodging.payments.map(
({ id, item, amount, issued_at, created_at, deleted_at }) => {
return (
<tr
key={id}
className="hover:bg-gray-100 focus-within:bg-gray-100"
>
<td className="border-t">
<InertiaLink
href={route('contacts.edit', id)}
href={route('payments.edit', id)}
className="flex items-center px-6 py-4 focus:text-indigo"
>
{name}
{item}
{deleted_at && (
<Icon
name="trash"
Expand All @@ -175,25 +177,34 @@ export default () => {
<td className="border-t">
<InertiaLink
tabIndex="-1"
href={route('contacts.edit', id)}
href={route('payments.edit', id)}
className="flex items-center px-6 py-4 focus:text-indigo"
>
{city}
{currency(amount)}
</InertiaLink>
</td>
<td className="border-t">
<InertiaLink
tabIndex="-1"
href={route('contacts.edit', id)}
href={route('payments.edit', id)}
className="flex items-center px-6 py-4 focus:text-indigo"
>
{phone}
{issued_at}
</InertiaLink>
</td>
<td className="border-t">
<InertiaLink
tabIndex="-1"
href={route('payments.edit', id)}
className="flex items-center px-6 py-4 focus:text-indigo"
>
{created_at}
</InertiaLink>
</td>
<td className="w-px border-t">
<InertiaLink
tabIndex="-1"
href={route('contacts.edit', id)}
href={route('payments.edit', id)}
className="flex items-center px-4"
>
<Icon
Expand All @@ -206,16 +217,16 @@ export default () => {
);
}
)}
{lodging.contacts.length === 0 && (
{lodging.payments.length === 0 && (
<tr>
<td className="px-6 py-4 border-t" colSpan="4">
No contacts found.
Belum ada data pembayaran
</td>
</tr>
)}
</tbody>
</table>
</div> */}
</div>
</div>
</Layout>
);
Expand Down

0 comments on commit 3164467

Please sign in to comment.