Skip to content

Commit

Permalink
feat: Update menu item name and invoice status labels
Browse files Browse the repository at this point in the history
  • Loading branch information
bangyadiii committed Jun 22, 2024
1 parent 63eadbb commit d5d1e72
Show file tree
Hide file tree
Showing 10 changed files with 1,086 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ yarn-error.log
/public/assets/js
/public/assets/css
/public/assets/vendor
.env
.env
composer.lock
66 changes: 66 additions & 0 deletions app/Exports/BillExport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace App\Exports;

use App\Enums\BillStatus;
use App\Enums\PaymentMethod;
use App\Models\Bill;
use Carbon\Carbon;
use Illuminate\Support\Facades\Date;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class BillExport implements FromCollection, WithHeadings, WithMapping
{
public $bills;

public function __construct($bills)
{
$this->bills = $bills;
}

public function collection()
{
return Bill::query()
->with(['customer', 'plan', 'payment'])
->whereIn('id', $this->bills)->get();
}

/**
* @param Bill $bill
*/
public function map($bill): array
{
return [
$bill->customer->id,
$bill->customer->customer_name,
$bill->plan->name,
$bill->plan->price,
Date::parse($bill->dude_date)->format('F Y'),
$bill->discount ?? 0,
$bill->tax_rate,
$bill->total_amount,
$bill->status == BillStatus::PAID ? 'Lunas' : 'Belum Lunas',
$bill->payment?->payment_date ?? '-',
$bill->payment?->method == PaymentMethod::CASH ? 'Tunai' : 'Midtrans',
];
}

public function headings(): array
{
return [
'Nomor Pelanggan',
'Nama',
'Paket',
'Tarif',
'Tagihan',
'Diskon',
'PPN',
'Total',
'Status',
'Tanggal Pembayaran',
'Metode',
];
}
}
60 changes: 60 additions & 0 deletions app/Exports/CustomerExport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace App\Exports;

use App\Models\Customer;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class CustomerExport implements FromCollection, WithMapping, WithHeadings
{
public $customers;

public function __construct($customers)
{
$this->customers = $customers;
}

/**
* @param Customer $customer
*/
public function map($customer): array
{
return [
$customer->id,
$customer->customer_name,
$customer->phone_number,
$customer->address,
$customer->installment_status->value,
$customer->service_status->value,
$customer->active_date,
$customer->auto_isolir ? 'Ya' : 'Tidak',
$customer->isolir_date,
$customer->plan->name,
];
}

public function collection()
{
return Customer::query()
->with('plan')
->whereIn('id', $this->customers)->get();
}

public function headings(): array
{
return [
'Nomor Pelanggan',
'Nama',
'Telepon',
'Alamat',
'Status Pemasangan',
'Status Layanan',
'Tanggal Aktif',
'Auto Isolir',
'Tanggal Isolir',
'Paket',
];
}
}
35 changes: 19 additions & 16 deletions app/Livewire/Customer/CreateCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Livewire\Customer;

use App\Enums\BillStatus;
use App\Enums\InstallmentStatus;
use App\Enums\ServiceStatus;
use App\Livewire\Forms\CustomerForm;
use App\Models\Bill;
use App\Models\Customer;
Expand Down Expand Up @@ -77,25 +79,26 @@ public function store()

$customer->save();

$isolirDate = Carbon::createFromDate(now()->year, now()->month, $customer->isolir_date);
if ($customer->service_status == ServiceStatus::ACTIVE && $customer->installment_status == InstallmentStatus::INSTALLED) {
$isolirDate = Carbon::createFromDate(now()->year, now()->month, $customer->isolir_date);
if ($isolirDate->isPast()) {
$isolirDate->addMonth();
}

// TOOD: check more detail about this
if ($isolirDate->isPast()) {
$isolirDate->addMonth();
$tax = (int) Setting::where('key', 'ppn')->first()->value ?? 0;
$bill = $customer->bills()->create([
'due_date' => $isolirDate,
'plan_id' => $customer->plan_id,
'total_amount' => ($plan->price - $this->form->discount) * ($tax / 100 + 1),
'tax_rate' => $tax,
'discount' => $this->form->discount,
'status' => BillStatus::UNPAID,
]);

$bill->invoice_link = $this->createInvoice($customer, $bill, $plan);
$bill->save();
}

$tax = (int) Setting::where('key', 'ppn')->first()->value ?? 0;
$bill = $customer->bills()->create([
'due_date' => $isolirDate,
'plan_id' => $customer->plan_id,
'total_amount' => ($plan->price - $this->form->discount) * ($tax / 100 + 1),
'tax_rate' => $tax,
'discount' => $this->form->discount,
'status' => BillStatus::UNPAID,
]);
$bill->invoice_link = $this->createInvoice($customer, $bill, $plan);
$bill->save();

$this->dispatch('toast', title: 'Customer created successfully', type: 'success');
return $this->redirectRoute('customers.index', navigate: true);
}
Expand Down
18 changes: 18 additions & 0 deletions app/Livewire/CustomerTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Enums\InstallmentStatus;
use App\Enums\ServiceStatus;
use App\Exports\CustomerExport;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;
use App\Models\Customer;
Expand All @@ -12,6 +13,7 @@
use App\Models\Secret;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Maatwebsite\Excel\Facades\Excel;
use Rappasoft\LaravelLivewireTables\Views\Filters\DateFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\DateRangeFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter;
Expand All @@ -26,6 +28,22 @@ public function configure(): void
$this->setPrimaryKey('id');
}

public function bulkActions(): array
{
return [
'export' => 'Export',
];
}

public function export()
{
$customers = $this->getSelected();

$this->clearSelected();

return Excel::download(new CustomerExport($customers), 'customers.xlsx');
}

public function columns(): array
{
return [
Expand Down
23 changes: 22 additions & 1 deletion app/Livewire/Transaction/TransactionTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

use App\Enums\BillStatus;
use App\Enums\PaymentMethod;
use App\Exports\BillExport;
use App\Models\Bill;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;
use App\Models\Plan;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Maatwebsite\Excel\Facades\Excel;
use Rappasoft\LaravelLivewireTables\Views\Filters\DateFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\DateRangeFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter;
Expand All @@ -24,9 +26,28 @@ public function configure(): void
->setDefaultSort('due_date', 'desc');
}

public function bulkActions(): array
{
return [
'export' => 'Export',
];
}

public function export()
{
$bills = $this->getSelected();

$this->clearSelected();

return Excel::download(new BillExport($bills), 'bills.xlsx');
}


public function columns(): array
{
return [
Column::make("No Pelanggan", "id")
->hideIf(true),
Column::make("No Pelanggan", "customer.id")
->searchable(),
Column::make("Nama", "customer.customer_name")
Expand Down Expand Up @@ -83,7 +104,7 @@ public function columns(): array
->label(
fn ($row, Column $column) => view('components.livewire.datatables.action-column')->with(
[
'printRoute' => route('invoices', ['id' => $row->id]),
'printRoute' => route('invoices', ['bill_id' => $row->id]),
// 'deleteMethod' => 'delete(' . $row->id . ')',
]
)
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/tinker": "^2.8",
"laraveldaily/laravel-invoices": "^4.0",
"livewire/livewire": "^3.4",
"maatwebsite/excel": "^3.1",
"rap2hpoutre/laravel-log-viewer": "^2.4",
"rappasoft/laravel-livewire-tables": "^3.2",
"sawirricardo/laravel-midtrans": "^1.6",
Expand Down
Loading

0 comments on commit d5d1e72

Please sign in to comment.