-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added order relations fixed ticket bug
- Loading branch information
Showing
13 changed files
with
537 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Controllers\XController; | ||
use App\Http\Requests\InvoiceSaveRequest; | ||
use App\Models\Access; | ||
use App\Models\Credit; | ||
use App\Models\Customer; | ||
use App\Models\Invoice; | ||
use App\Models\Order; | ||
use Illuminate\Http\Request; | ||
use App\Helper; | ||
use function App\Helpers\hasCreateRoute; | ||
|
||
class InvoiceController extends XController | ||
{ | ||
|
||
// protected $_MODEL_ = Invoice::class; | ||
// protected $SAVE_REQUEST = InvoiceSaveRequest::class; | ||
|
||
protected $cols = ['hash', 'customer_id', 'count', 'total_price', 'status']; | ||
protected $extra_cols = ['id']; | ||
|
||
protected $searchable = ['desc']; | ||
|
||
protected $listView = 'admin.invoices.invoice-list'; | ||
protected $formView = 'admin.invoices.invoice-form'; | ||
|
||
|
||
protected $buttons = [ | ||
'edit' => | ||
['title' => "Edit", 'class' => 'btn-outline-primary', 'icon' => 'ri-edit-2-line'], | ||
'show' => | ||
['title' => "Detail", 'class' => 'btn-outline-light', 'icon' => 'ri-eye-line'], | ||
'destroy' => | ||
['title' => "Remove", 'class' => 'btn-outline-danger delete-confirm', 'icon' => 'ri-close-line'], | ||
]; | ||
|
||
|
||
public function __construct() | ||
{ | ||
parent::__construct(Invoice::class, InvoiceSaveRequest::class); | ||
} | ||
|
||
/** | ||
* @param $invoice Invoice | ||
* @param $request InvoiceSaveRequest | ||
* @return Invoice | ||
*/ | ||
public function save($invoice, $request) | ||
{ | ||
|
||
$invoice->transport_id = $request->input('transport_id', null); | ||
$invoice->address_id = $request->input('address_id', null); | ||
$invoice->tracking_code = $request->tracking_code; | ||
$invoice->status = $request->status; | ||
$invoice->save(); | ||
return $invoice; | ||
|
||
} | ||
|
||
|
||
/** | ||
* Show the form for creating a new resource. | ||
*/ | ||
public function create() | ||
{ | ||
// | ||
return view($this->formView); | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
*/ | ||
public function edit(Invoice $item) | ||
{ | ||
// | ||
return view($this->formView, compact('item')); | ||
} | ||
|
||
public function bulk(Request $request) | ||
{ | ||
|
||
// dd($request->all()); | ||
$data = explode('.', $request->input('action')); | ||
$action = $data[0]; | ||
$ids = $request->input('id'); | ||
switch ($action) { | ||
case 'delete': | ||
$msg = __(':COUNT items deleted successfully', ['COUNT' => count($ids)]); | ||
$this->_MODEL_::destroy($ids); | ||
break; | ||
/**restore*/ | ||
case 'restore': | ||
$msg = __(':COUNT items restored successfully', ['COUNT' => count($ids)]); | ||
foreach ($ids as $id) { | ||
$this->_MODEL_::withTrashed()->find($id)->restore(); | ||
} | ||
break; | ||
/*restore**/ | ||
default: | ||
$msg = __('Unknown bulk action : :ACTION', ["ACTION" => $action]); | ||
} | ||
|
||
return $this->do_bulk($msg, $action, $ids); | ||
} | ||
|
||
public function destroy(Invoice $item) | ||
{ | ||
return parent::delete($item); | ||
} | ||
|
||
|
||
public function update(Request $request, Invoice $item) | ||
{ | ||
return $this->bringUp($request, $item); | ||
} | ||
|
||
/**restore*/ | ||
public function restore($item) | ||
{ | ||
return parent::restoreing(Invoice::withTrashed()->where('id', $item)->first()); | ||
} | ||
|
||
public function removeOrder(Order $order) | ||
{ | ||
|
||
$customer = Customer::whereId($order->invoice->customer_id)->first(); | ||
if ($order->price_total > 0) { | ||
$diff = $order->price_total; | ||
$customer->credit += $diff; | ||
$customer->save(); | ||
$cr = new Credit(); | ||
$cr->customer_id = $customer->id; | ||
$cr->amount = $diff; | ||
$cr->data = json_encode([ | ||
'user_id' => auth()->user()->id, | ||
'message' => __("Increase by Admin removed:") . ' ' . $order->product->name . __("Invoice") . ' : ' . $order->invoice->hash, | ||
]); | ||
$cr->save(); | ||
$order->delete(); | ||
} | ||
return redirect()->back()->with('message', __('Order removed successfully')); | ||
} | ||
/*restore**/ | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class InvoiceSaveRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return auth()->check(); | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'transport_id' => ['nullable', 'integer', 'exists:transports,id'], | ||
'address_id' => ['nullable', 'integer', 'exists:addresses,id'], | ||
'tracking_code' => ['nullable', 'string'], | ||
'status' => ['required', 'string'], | ||
]; | ||
} | ||
} |
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.