79 lines
2.0 KiB
PHP
Raw Normal View History

2019-11-16 10:21:14 +03:00
<?php
2019-12-31 15:49:09 +03:00
namespace App\BulkActions\Purchases;
2019-11-16 10:21:14 +03:00
use App\Abstracts\BulkAction;
2019-12-31 15:49:09 +03:00
use App\Exports\Purchases\Bills as Export;
use App\Jobs\Purchase\CreateBillHistory;
use App\Jobs\Purchase\DeleteBill;
use App\Models\Purchase\Bill;
2019-11-16 10:21:14 +03:00
class Bills extends BulkAction
{
public $model = Bill::class;
public $actions = [
'received' => [
2019-12-23 12:46:00 +03:00
'name' => 'bills.mark_received',
'message' => 'bulk_actions.message.received',
2019-12-31 15:49:09 +03:00
'permission' => 'update-purchases-bills',
2019-11-16 10:21:14 +03:00
],
2019-12-23 12:46:00 +03:00
'delete' => [
'name' => 'general.delete',
'message' => 'bulk_actions.message.delete',
2019-12-31 15:49:09 +03:00
'permission' => 'delete-purchases-bills',
2019-11-16 10:21:14 +03:00
],
'export' => [
'name' => 'general.export',
2019-12-23 12:46:00 +03:00
'message' => 'bulk_actions.message.export',
2019-12-27 15:42:22 +03:00
],
2019-11-16 10:21:14 +03:00
];
2019-12-23 12:46:00 +03:00
public function received($request)
2019-11-16 10:21:14 +03:00
{
2019-12-23 12:46:00 +03:00
$bills = $this->getSelectedRecords($request);
2019-11-16 10:21:14 +03:00
foreach ($bills as $bill) {
2019-12-23 12:46:00 +03:00
$bill->bill_status_code = 'received';
$bill->save();
$description = trans('bills.mark_recevied');
2019-11-16 10:21:14 +03:00
2019-12-23 12:46:00 +03:00
$this->dispatch(new CreateBillHistory($bill, 0, $description));
2019-11-16 10:21:14 +03:00
}
}
2019-12-23 12:46:00 +03:00
public function duplicate($request)
2019-11-16 10:21:14 +03:00
{
2019-12-23 12:46:00 +03:00
$bills = $this->getSelectedRecords($request);
foreach ($bills as $bill) {
$clone = $bill->duplicate();
$description = trans('messages.success.added', ['type' => $clone->bill_number]);
$this->dispatch(new CreateBillHistory($clone, 0, $description));
}
2019-11-16 10:21:14 +03:00
}
public function destroy($request)
{
2019-12-23 12:46:00 +03:00
$bills = $this->getSelectedRecords($request);
2019-11-16 10:21:14 +03:00
foreach ($bills as $bill) {
2019-12-23 12:46:00 +03:00
try {
$this->dispatch(new DeleteBill($bill));
} catch (\Exception $e) {
flash($e->getMessage())->error();
}
2019-11-16 10:21:14 +03:00
}
}
public function export($request)
{
2019-12-23 12:46:00 +03:00
$selected = $this->getSelectedInput($request);
2019-11-16 10:21:14 +03:00
return \Excel::download(new Export($selected), trans_choice('general.bills', 2) . '.xlsx');
}
}