From b9191bf67af040af785d7233dc8f5020127e65ef Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 31 May 2021 15:27:26 +1000 Subject: [PATCH] Company Ledger Adjustment --- app/Console/Commands/SendRemindersCron.php | 7 ++- app/Http/Controllers/ClientController.php | 57 +++++++++++++++++++ .../Client/AdjustClientLedgerRequest.php | 55 ++++++++++++++++++ app/Jobs/Util/WebhookHandler.php | 4 +- routes/api.php | 1 + 5 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 app/Http/Requests/Client/AdjustClientLedgerRequest.php diff --git a/app/Console/Commands/SendRemindersCron.php b/app/Console/Commands/SendRemindersCron.php index 54d00824d2f4..45177ef269c8 100644 --- a/app/Console/Commands/SendRemindersCron.php +++ b/app/Console/Commands/SendRemindersCron.php @@ -12,12 +12,12 @@ namespace App\Console\Commands; use App\Jobs\Ninja\SendReminders; -use App\Jobs\Util\WebHookHandler; use App\Libraries\MultiDB; use App\Models\Invoice; use App\Models\Quote; use App\Models\Webhook; use Illuminate\Console\Command; +use App\Jobs\Util\WebhookHandler; class SendRemindersCron extends Command { @@ -54,8 +54,8 @@ class SendRemindersCron extends Command { SendReminders::dispatchNow(); - $this->webHookOverdueInvoices(); - $this->webHookExpiredQuotes(); + $this->webHookOverdueInvoices(); + $this->webHookExpiredQuotes(); } private function webHookOverdueInvoices() @@ -90,6 +90,7 @@ class SendRemindersCron extends Command $invoices->each(function ($invoice) { WebHookHandler::dispatch(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company); + }); $quotes = Quote::where('is_deleted', 0) diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index 89e29a16cf44..6b83d04019cd 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -585,4 +585,61 @@ class ClientController extends BaseController } +/** + * Update the specified resource in storage. + * + * @param UploadClientRequest $request + * @param Client $client + * @return Response + * + * + * + * @OA\Put( + * path="/api/v1/clients/{id}/adjust_ledger", + * operationId="adjustLedger", + * tags={"clients"}, + * summary="Adjust the client ledger to rebalance", + * description="Adjust the client ledger to rebalance", + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\Parameter( + * name="id", + * in="path", + * description="The Client Hashed ID", + * example="D2J234DFA", + * required=true, + * @OA\Schema( + * type="string", + * format="string", + * ), + * ), + * @OA\Response( + * response=200, + * description="Returns the client object", + * @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * @OA\JsonContent(ref="#/components/schemas/Client"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + */ + + public function adjustLedger(Request $request, Client $client) + { + + } + } diff --git a/app/Http/Requests/Client/AdjustClientLedgerRequest.php b/app/Http/Requests/Client/AdjustClientLedgerRequest.php new file mode 100644 index 000000000000..7fe6cc8bda64 --- /dev/null +++ b/app/Http/Requests/Client/AdjustClientLedgerRequest.php @@ -0,0 +1,55 @@ +user()->can('edit', $this->client); + } + + public function rules() + { + /* Ensure we have a client name, and that all emails are unique*/ + + $rules = []; + + return $rules; + } + + public function messages() + { + return [ + ]; + } + + protected function prepareForValidation() + { + $input = $this->all(); + + $this->replace($input); + } + + +} diff --git a/app/Jobs/Util/WebhookHandler.php b/app/Jobs/Util/WebhookHandler.php index 970ecc07de86..35fb4274ef88 100644 --- a/app/Jobs/Util/WebhookHandler.php +++ b/app/Jobs/Util/WebhookHandler.php @@ -35,9 +35,9 @@ class WebhookHandler implements ShouldQueue private $company; - public $tries = 5; //number of retries + public $tries = 3; //number of retries - public $backoff = 5; //seconds to wait until retry + public $backoff = 10; //seconds to wait until retry public $deleteWhenMissingModels = true; diff --git a/routes/api.php b/routes/api.php index 1ce7f9bc8ce3..1a8a3e11387e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -34,6 +34,7 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a Route::post('claim_license', 'LicenseController@index')->name('license.index'); Route::resource('clients', 'ClientController'); // name = (clients. index / create / show / update / destroy / edit + Route::put('clients/{client}/adjust_ledger', 'ClientController@adjustLedger')->name('clients.adjust_ledger'); Route::put('clients/{client}/upload', 'ClientController@upload')->name('clients.upload'); Route::post('clients/bulk', 'ClientController@bulk')->name('clients.bulk');