firstcommit
This commit is contained in:
0
Modules/Estimate/app/Http/Controllers/.gitkeep
Normal file
0
Modules/Estimate/app/Http/Controllers/.gitkeep
Normal file
194
Modules/Estimate/app/Http/Controllers/EstimateController.php
Normal file
194
Modules/Estimate/app/Http/Controllers/EstimateController.php
Normal file
@ -0,0 +1,194 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Estimate\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Billing\Repositories\BillingComponentInterface;
|
||||
use Modules\Customer\Repositories\CustomerInterface;
|
||||
use Modules\Estimate\Models\Estimate;
|
||||
use Modules\Estimate\Models\EstimateDetail;
|
||||
use Modules\Estimate\Repositories\EstimateDetailInterface;
|
||||
use Modules\Estimate\Repositories\EstimateInterface;
|
||||
|
||||
class EstimateController extends Controller
|
||||
{
|
||||
private $estimateRepository;
|
||||
private $estimateDetailRepository;
|
||||
private $customerRepository;
|
||||
private $billingComponentRepository;
|
||||
|
||||
public function __construct(
|
||||
EstimateInterface $estimateRepository,
|
||||
BillingComponentInterface $billingComponentRepository,
|
||||
CustomerInterface $customerRepository
|
||||
) {
|
||||
$this->estimateRepository = $estimateRepository;
|
||||
$this->customerRepository = $customerRepository;
|
||||
$this->billingComponentRepository = $billingComponentRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data['title'] = 'Estimate List';
|
||||
$data['statusList'] = Estimate::APPROVAL_STATUS;
|
||||
$data['estimates'] = $this->estimateRepository->findAll();
|
||||
return view('estimate::estimate.index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$data['title'] = 'Create Estimate';
|
||||
$data['editable'] = false;
|
||||
$data['customerList'] = $this->customerRepository->pluck();
|
||||
$data['billingComponentList'] = $this->billingComponentRepository->pluck();
|
||||
return view('estimate::estimate.create', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
|
||||
$request->merge([
|
||||
'approval_status' => 1,
|
||||
]);
|
||||
|
||||
try {
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$estimateData = $request->only(Estimate::getFillableFields());
|
||||
|
||||
$estimate = $this->estimateRepository->create($estimateData);
|
||||
|
||||
$estimateDetails = json_decode($request->estimateDetails);
|
||||
|
||||
foreach ($estimateDetails as $item) {
|
||||
|
||||
$estimateDetailData = [
|
||||
'estimate_id' => $estimate->id,
|
||||
'billing_component_id' => $item->billing_component_id,
|
||||
'price' => $item->price,
|
||||
'qty' => $item->qty,
|
||||
'tax_amount' => $item->tax_amount,
|
||||
];
|
||||
|
||||
EstimateDetail::create($estimateDetailData);
|
||||
|
||||
}
|
||||
|
||||
toastr()->success('Estimate created succesfully');
|
||||
|
||||
DB::commit();
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
echo $th->getMessage();
|
||||
|
||||
DB::rollback();
|
||||
|
||||
toastr()->error($th->getMessage());
|
||||
|
||||
}
|
||||
|
||||
return redirect()->route('estimate.index');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$data['title'] = 'Show Estimate';
|
||||
$data['estimate'] = $this->estimateRepository->getEstimateById($id);
|
||||
$data['statusList'] = Estimate::APPROVAL_STATUS;
|
||||
$data['customerList'] = $this->customerRepository->pluck();
|
||||
return view('estimate::estimate.show', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$data['title'] = 'Edit Estimate';
|
||||
$data['editable'] = true;
|
||||
$data['estimate'] = $this->estimateRepository->getEstimateById($id);
|
||||
$data['customerList'] = $this->customerRepository->pluck();
|
||||
$data['billingComponentList'] = $this->billingComponentRepository->pluck();
|
||||
return view('estimate::estimate.edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
$estimateData = $request->only(Estimate::getFillableFields());
|
||||
|
||||
try {
|
||||
|
||||
$this->estimateRepository->update($id, $estimateData);
|
||||
|
||||
flash()->success('Estimate updated succesfully');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
echo $th->getMessage();
|
||||
|
||||
flash()->error($th->getMessage());
|
||||
}
|
||||
|
||||
return redirect()->route('estimate.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
$EstimateModel = $this->estimateRepository->getEstimateById($id);
|
||||
|
||||
$EstimateModel->delete();
|
||||
|
||||
flash()->success('Estimate deleted succesfully');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
flash()->error($th->getMessage());
|
||||
}
|
||||
|
||||
return response()->json(['status' => true, 'message' => 'Estimate deleted succesfully']);
|
||||
|
||||
}
|
||||
|
||||
public function changeStatus(Request $request)
|
||||
{
|
||||
try {
|
||||
$estimate = $this->estimateRepository->getEstimateById($request->estimate_id);
|
||||
$estimate->update([
|
||||
'approval_status' => $request->approval_status,
|
||||
'approval_remarks' => $request->approval_remarks,
|
||||
'approval_on' => now(),
|
||||
'approval_by' => auth()->user()->id,
|
||||
]);
|
||||
|
||||
return redirect()->back();
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
flash()->error($th->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Estimate\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Customer\Repositories\CustomerInterface;
|
||||
use Modules\Estimate\Models\EstimateDetail;
|
||||
use Modules\Estimate\Repositories\EstimateDetailInterface;
|
||||
|
||||
class EstimateDetailController extends Controller
|
||||
{
|
||||
private $estimateDetailRepository;
|
||||
private $customerRepository;
|
||||
|
||||
public function __construct(
|
||||
EstimateDetailInterface $estimateDetailRepository,
|
||||
CustomerInterface $customerRepository
|
||||
) {
|
||||
$this->estimateDetailRepository = $estimateDetailRepository;
|
||||
$this->customerRepository = $customerRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data['title'] = 'Estimate Detail List';
|
||||
$data['estimateDetails'] = $this->estimateDetailRepository->findAll();
|
||||
return view('estimate::estimateDetail.index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$data['title'] = 'Create EstimateDetail';
|
||||
$data['editable'] = false;
|
||||
$data['customerList'] = $this->customerRepository->pluck();
|
||||
return view('estimate::estimateDetail.create', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
try {
|
||||
|
||||
$inputData = $request->all();
|
||||
|
||||
$this->estimateDetailRepository->create($inputData);
|
||||
|
||||
toastr()->success('EstimateDetail created succesfully');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
|
||||
return redirect()->route('estimateDetail.index');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$data['title'] = 'Show EstimateDetail';
|
||||
$data['estimateDetail'] = $this->estimateDetailRepository->getEstimateDetailById($id);
|
||||
$data['customerList'] = $this->customerRepository->pluck();
|
||||
return view('estimate::estimateDetail.show', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$data['title'] = 'Edit EstimateDetail';
|
||||
$data['editable'] = true;
|
||||
$data['estimateDetail'] = $this->estimateDetailRepository->getEstimateDetailById($id);
|
||||
return view('estimate::estimateDetail.edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
$inputData = $request->except(['_method', '_token']);
|
||||
try {
|
||||
|
||||
$this->estimateDetailRepository->update($id, $inputData);
|
||||
|
||||
flash()->success('EstimateDetail updated succesfully');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
flash()->error($th->getMessage());
|
||||
}
|
||||
return redirect()->route('EstimateDetail.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
$EstimateDetailModel = $this->estimateDetailRepository->getEstimateDetailById($id);
|
||||
|
||||
$EstimateDetailModel->delete();
|
||||
|
||||
flash()->success('EstimateDetail deleted succesfully');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
flash()->error($th->getMessage());
|
||||
}
|
||||
|
||||
return response()->json(['status' => true, 'message' => 'EstimateDetail deleted succesfully']);
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user