- Implemented stock transfer creation and management with Livewire components. - Created StockTransfer and StockTransferItem models with necessary relationships. - Added migration files for stock_transfers and stock_transfer_items tables. - Developed traits for handling stock transfer items (add, delete, update). - Integrated stock transfer logging in StockActivityLogService. - Updated ViewServiceProvider to include stock transfer permissions and routes. - Created frontend views for stock transfer form and index with appropriate UI components. - Added role permissions for stock transfer actions in RolePermissionSeeder.
79 lines
2.9 KiB
PHP
79 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Datatable\Manage;
|
|
|
|
use App\Models\StockTransfer;
|
|
use App\Traits\Datatable\WithAppendColumn;
|
|
use App\Traits\Datatable\WithConfiguration;
|
|
use App\Traits\Datatable\WithPrependColumn;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Rappasoft\LaravelLivewireTables\DataTableComponent;
|
|
use Rappasoft\LaravelLivewireTables\Views\Column;
|
|
use Rappasoft\LaravelLivewireTables\Views\Columns\ArrayColumn;
|
|
|
|
class StockTransfersTable extends DataTableComponent
|
|
{
|
|
use WithAppendColumn, WithConfiguration, WithPrependColumn;
|
|
|
|
protected $model = StockTransfer::class;
|
|
|
|
protected string $sortColumn = 'transfer_date';
|
|
|
|
protected string $sortDirection = 'desc';
|
|
|
|
public function columns(): array
|
|
{
|
|
return [
|
|
Column::make('Outlet Asal', 'sourceOutlet.name')->searchable(),
|
|
|
|
Column::make('Outlet Tujuan', 'destinationOutlet.name')->searchable(),
|
|
|
|
Column::make('Tanggal Transfer', 'transfer_date')
|
|
->format(fn ($value) => formatDateLocalized($value))
|
|
->searchable()
|
|
->sortable(),
|
|
|
|
Column::make('Catatan', 'note')->searchable(),
|
|
|
|
ArrayColumn::make('Item')
|
|
->data(
|
|
fn ($value, $row) => $row->items->map(fn ($item) => [
|
|
'name' => $item->transferable?->name,
|
|
'quantity' => formatCurrencyNumber($item->quantity, ''),
|
|
])->toArray()
|
|
)
|
|
->outputFormat(
|
|
fn ($index, $value) => "
|
|
<div class='text-[13px] leading-tight mb-1'>
|
|
<div class='font-bold text-gray-800 dark:text-white'>{$value['name']}</div>
|
|
<div class='text-gray-400 text-[12px]'>Qty: {$value['quantity']}</div>
|
|
</div>"
|
|
)
|
|
->flexCol(['class' => 'flex-col gap-3']),
|
|
|
|
Column::make('Aksi')
|
|
->label(function ($row) {
|
|
$actions = '';
|
|
|
|
if (auth()->user()->can('delete stock transfer')) {
|
|
$actions .= view('components.actions.table.delete', [
|
|
'id' => $row->hash,
|
|
])->render();
|
|
}
|
|
|
|
return $actions;
|
|
})
|
|
->html()
|
|
->hideIf(auth()->user()->cannot('update stock transfer')),
|
|
];
|
|
}
|
|
|
|
public function builder(): Builder
|
|
{
|
|
return StockTransfer::select('stock_transfers.id', 'source_outlet_id', 'destination_outlet_id', 'transfer_date', 'note')
|
|
->with(['sourceOutlet', 'destinationOutlet', 'items', 'items.transferable'])
|
|
->whereIn('source_outlet_id', auth()->user()->outlets->pluck('id')->toArray())
|
|
->orWhereIn('destination_outlet_id', auth()->user()->outlets->pluck('id')->toArray());
|
|
}
|
|
}
|