akaunting 3.0 (the last dance)
This commit is contained in:
@ -5,16 +5,18 @@ namespace App\Abstracts\Http;
|
||||
use App\Traits\Jobs;
|
||||
use App\Traits\Permissions;
|
||||
use App\Traits\Relationships;
|
||||
use Dingo\Api\Exception\ResourceException;
|
||||
use Dingo\Api\Routing\Helpers;
|
||||
use App\Exceptions\Http\Resource as ResourceException;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
|
||||
abstract class ApiController extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, Jobs, Helpers, Permissions, Relationships, ValidatesRequests;
|
||||
use AuthorizesRequests, Jobs, Permissions, Relationships, ValidatesRequests;
|
||||
|
||||
/**
|
||||
* Instantiate a new controller instance.
|
||||
@ -39,4 +41,146 @@ abstract class ApiController extends BaseController
|
||||
|
||||
return redirect()->to($this->getRedirectUrl())->withInput($request->input())->withErrors($errors, $this->errorBag());
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond with a location and a created resource.
|
||||
*
|
||||
* @param string $location
|
||||
* @param object $resource
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function created($location, $resource): JsonResponse
|
||||
{
|
||||
return $resource
|
||||
->response()
|
||||
->setStatusCode(201)
|
||||
->header('Location', $location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond with a location and an accepted resource.
|
||||
*
|
||||
* @param string $location
|
||||
* @param object $resource
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function accepted($location, $resource): JsonResponse
|
||||
{
|
||||
return $resource
|
||||
->response()
|
||||
->setStatusCode(202)
|
||||
->header('Location', $location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond with empty content.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function noContent(): Response
|
||||
{
|
||||
return (new Response)
|
||||
->setStatusCode(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an error response.
|
||||
*
|
||||
* @param string $message
|
||||
* @param int $statusCode
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function error($message, $statusCode)
|
||||
{
|
||||
throw new HttpException($statusCode, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a 404 not found error.
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function errorNotFound($message = 'Not Found')
|
||||
{
|
||||
$this->error($message, 404);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a 400 bad request error.
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function errorBadRequest($message = 'Bad Request')
|
||||
{
|
||||
$this->error($message, 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a 403 forbidden error.
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function errorForbidden($message = 'Forbidden')
|
||||
{
|
||||
$this->error($message, 403);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a 500 internal server error.
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function errorInternal($message = 'Internal Error')
|
||||
{
|
||||
$this->error($message, 500);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a 401 unauthorized error.
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function errorUnauthorized($message = 'Unauthorized')
|
||||
{
|
||||
$this->error($message, 401);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a 405 method not allowed error.
|
||||
*
|
||||
* @param string $message
|
||||
*
|
||||
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function errorMethodNotAllowed($message = 'Method Not Allowed')
|
||||
{
|
||||
$this->error($message, 405);
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ abstract class FormRequest extends BaseFormRequest
|
||||
* @param string $offset
|
||||
* @return bool
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
public function offsetExists($offset): bool
|
||||
{
|
||||
return Arr::has(
|
||||
$this->route() ? $this->all() + $this->route()->parameters() : $this->all(),
|
||||
|
@ -41,16 +41,18 @@ abstract class PaymentController extends BaseController
|
||||
});
|
||||
}
|
||||
|
||||
public function show(Document $invoice, PaymentRequest $request)
|
||||
public function show(Document $invoice, PaymentRequest $request, $cards = [])
|
||||
{
|
||||
$this->setContactFirstLastName($invoice);
|
||||
|
||||
$confirm_url = $this->getConfirmUrl($invoice);
|
||||
|
||||
$html = view('partials.portal.payment_method.' . $this->type, [
|
||||
$html = view('components.payment_method.' . $this->type, [
|
||||
'setting' => $this->setting,
|
||||
'invoice' => $invoice,
|
||||
'confirm_url' => $confirm_url,
|
||||
'store_card' => !empty($this->setting['store_card']) ? true : false,
|
||||
'cards' => $cards,
|
||||
])->render();
|
||||
|
||||
return response()->json([
|
||||
@ -101,15 +103,15 @@ abstract class PaymentController extends BaseController
|
||||
|
||||
flash($message)->success();
|
||||
|
||||
$invoice_url = $this->getInvoiceUrl($invoice);
|
||||
$finish_url = $this->getFinishUrl($invoice);
|
||||
|
||||
if ($force_redirect || ($this->type == 'redirect')) {
|
||||
return redirect($invoice_url);
|
||||
return redirect($finish_url);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'error' => $message,
|
||||
'redirect' => $invoice_url,
|
||||
'redirect' => $finish_url,
|
||||
'success' => true,
|
||||
'data' => false,
|
||||
]);
|
||||
@ -122,6 +124,13 @@ abstract class PaymentController extends BaseController
|
||||
: URL::signedRoute('signed.invoices.show', [$invoice->id]);
|
||||
}
|
||||
|
||||
public function getFinishUrl($invoice)
|
||||
{
|
||||
return request()->isPortal($invoice->company_id)
|
||||
? route('portal.invoices.finish', $invoice->id)
|
||||
: URL::signedRoute('signed.invoices.finish', [$invoice->id]);
|
||||
}
|
||||
|
||||
public function getConfirmUrl($invoice)
|
||||
{
|
||||
return $this->getModuleUrl($invoice, 'confirm');
|
||||
|
161
app/Abstracts/Http/SettingController.php
Normal file
161
app/Abstracts/Http/SettingController.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
|
||||
namespace App\Abstracts\Http;
|
||||
|
||||
use App\Abstracts\Http\Controller;
|
||||
use App\Http\Requests\Setting\Setting as Request;
|
||||
use App\Models\Common\Company;
|
||||
use App\Models\Setting\Currency;
|
||||
use App\Traits\DateTime;
|
||||
use App\Traits\Uploads;
|
||||
use App\Utilities\Installer;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
abstract class SettingController extends Controller
|
||||
{
|
||||
use DateTime, Uploads;
|
||||
|
||||
public $redirect_route = '';
|
||||
|
||||
public $skip_keys = ['company_id', '_method', '_token', '_prefix'];
|
||||
|
||||
public $file_keys = ['company.logo', 'invoice.logo'];
|
||||
|
||||
public $uploaded_file_keys = ['company.uploaded_logo', 'invoice.uploaded_logo'];
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function update(Request $request)
|
||||
{
|
||||
$fields = $request->all();
|
||||
$prefix = $request->get('_prefix', 'general');
|
||||
$company_id = $request->get('company_id');
|
||||
|
||||
if (empty($company_id)) {
|
||||
$company_id = company_id();
|
||||
}
|
||||
|
||||
$company = Company::find($company_id);
|
||||
|
||||
$total_companies = Company::count();
|
||||
|
||||
foreach ($fields as $key => $value) {
|
||||
$real_key = $prefix . '.' . $key;
|
||||
|
||||
// Don't process unwanted keys
|
||||
if (in_array($key, $this->skip_keys)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// change dropzone middleware already uploaded file
|
||||
if (in_array($real_key, $this->uploaded_file_keys)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Process file uploads
|
||||
if (in_array($real_key, $this->file_keys)) {
|
||||
// Upload attachment
|
||||
if ($request->file($key)) {
|
||||
$media = $this->getMedia($request->file($key), 'settings');
|
||||
|
||||
$company->attachMedia($media, Str::snake($real_key));
|
||||
|
||||
$value = $media->id;
|
||||
}
|
||||
|
||||
// Prevent reset
|
||||
if (empty($value)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ($real_key == 'default.locale') {
|
||||
if (!in_array($value, config('language.allowed'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
user()->setAttribute('locale', $value)->save();
|
||||
}
|
||||
|
||||
if ($real_key == 'default.currency') {
|
||||
$currencies = Currency::enabled()->pluck('code')->toArray();
|
||||
|
||||
if (!in_array($value, $currencies)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$currency = Currency::code($value)->first();
|
||||
$currency->rate = '1';
|
||||
$currency->save();
|
||||
}
|
||||
|
||||
// If only 1 company
|
||||
if ($total_companies == 1) {
|
||||
$this->oneCompany($real_key, $value);
|
||||
}
|
||||
|
||||
setting()->set($real_key, $value);
|
||||
}
|
||||
|
||||
// Save all settings
|
||||
setting()->save();
|
||||
|
||||
$message = trans('messages.success.updated', ['type' => trans_choice('general.settings', 2)]);
|
||||
|
||||
$redirect_url = !empty($this->redirect_route) ? route($this->redirect_route) : url()->previous();
|
||||
|
||||
$response = [
|
||||
'status' => null,
|
||||
'success' => true,
|
||||
'error' => false,
|
||||
'message' => $message,
|
||||
'data' => null,
|
||||
'redirect' => $redirect_url,
|
||||
];
|
||||
|
||||
flash($message)->success();
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
protected function oneCompany($real_key, $value)
|
||||
{
|
||||
switch ($real_key) {
|
||||
case 'company.name':
|
||||
Installer::updateEnv(['MAIL_FROM_NAME' => '"' . $value . '"']);
|
||||
break;
|
||||
case 'company.email':
|
||||
Installer::updateEnv(['MAIL_FROM_ADDRESS' => '"' . $value . '"']);
|
||||
break;
|
||||
case 'default.locale':
|
||||
Installer::updateEnv(['APP_LOCALE' => '"' . $value . '"']);
|
||||
break;
|
||||
case 'schedule.time':
|
||||
Installer::updateEnv(['APP_SCHEDULE_TIME' => '"' . $value . '"']);
|
||||
break;
|
||||
case 'email.protocol':
|
||||
Installer::updateEnv(['MAIL_MAILER' => '"' . $value . '"']);
|
||||
break;
|
||||
case 'email.smtp_host':
|
||||
Installer::updateEnv(['MAIL_HOST' => '"' . $value . '"']);
|
||||
break;
|
||||
case 'email.smtp_port':
|
||||
Installer::updateEnv(['MAIL_PORT' => '"' . $value . '"']);
|
||||
break;
|
||||
case 'email.smtp_username':
|
||||
Installer::updateEnv(['MAIL_USERNAME' => '"' . $value . '"']);
|
||||
break;
|
||||
case 'email.smtp_password':
|
||||
Installer::updateEnv(['MAIL_PASSWORD' => '"' . $value . '"']);
|
||||
break;
|
||||
case 'email.smtp_encryption':
|
||||
Installer::updateEnv(['MAIL_ENCRYPTION' => '"' . $value . '"']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user