From 1051b03b007e005fcbd1946bd3429c077b50a70d Mon Sep 17 00:00:00 2001 From: jayvirsinh_gohil Date: Fri, 15 Nov 2019 13:39:57 +0530 Subject: [PATCH] refactor auto updateand invoice and estimate send --- app/Http/Controllers/EstimatesController.php | 7 +++++-- app/Http/Controllers/InvoicesController.php | 12 ++++++------ app/Http/Controllers/UpdateController.php | 2 +- app/Space/Updater.php | 8 +++++--- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/EstimatesController.php b/app/Http/Controllers/EstimatesController.php index ef84d541..39a69c1c 100644 --- a/app/Http/Controllers/EstimatesController.php +++ b/app/Http/Controllers/EstimatesController.php @@ -306,8 +306,6 @@ class EstimatesController extends Controller public function sendEstimate(Request $request) { $estimate = Estimate::findOrFail($request->id); - $estimate->status = Estimate::STATUS_SENT; - $estimate->save(); $data['estimate'] = $estimate->toArray(); $userId = $data['estimate']['user_id']; @@ -330,6 +328,11 @@ class EstimatesController extends Controller ]); } + if ($estimate->status == Estimate::STATUS_DRAFT) { + $estimate->status = Estimate::STATUS_SENT; + $estimate->save(); + } + \Mail::to($email)->send(new EstimatePdf($data, $notificationEmail)); return response()->json([ diff --git a/app/Http/Controllers/InvoicesController.php b/app/Http/Controllers/InvoicesController.php index 7eaebb7b..a91df038 100644 --- a/app/Http/Controllers/InvoicesController.php +++ b/app/Http/Controllers/InvoicesController.php @@ -371,12 +371,6 @@ class InvoicesController extends Controller { $invoice = Invoice::findOrFail($request->id); - if ($invoice->status == Invoice::STATUS_DRAFT) { - $invoice->status = Invoice::STATUS_SENT; - $invoice->sent = true; - $invoice->save(); - } - $data['invoice'] = $invoice->toArray(); $userId = $data['invoice']['user_id']; $data['user'] = User::find($userId)->toArray(); @@ -398,6 +392,12 @@ class InvoicesController extends Controller ]); } + if ($invoice->status == Invoice::STATUS_DRAFT) { + $invoice->status = Invoice::STATUS_SENT; + $invoice->sent = true; + $invoice->save(); + } + \Mail::to($email)->send(new invoicePdf($data, $notificationEmail)); return response()->json([ diff --git a/app/Http/Controllers/UpdateController.php b/app/Http/Controllers/UpdateController.php index 2b1049d9..736fac56 100644 --- a/app/Http/Controllers/UpdateController.php +++ b/app/Http/Controllers/UpdateController.php @@ -12,7 +12,7 @@ class UpdateController extends Controller { set_time_limit(600); // 10 minutes - $json = Updater::update($request->installed, $request->version); + $json = Updater::update($request->installed, $request->version, $request->isMinor); return response()->json($json); } diff --git a/app/Space/Updater.php b/app/Space/Updater.php index b5d8b369..2368140b 100644 --- a/app/Space/Updater.php +++ b/app/Space/Updater.php @@ -13,12 +13,12 @@ class Updater { use SiteApi; - public static function update($installed, $version) + public static function update($installed, $version, $isMinor) { $data = null; $path = null; - $url = '/download/'.$version; + $url = '/download/'.$version.'?type=update'; $response = static::getRemote($url, ['timeout' => 100, 'track_redirects' => true]); @@ -78,7 +78,9 @@ class Updater File::deleteDirectory($temp_path2); try { - event(new UpdateFinished($installed, $version)); + if (!$isMinor) { + event(new UpdateFinished($installed, $version)); + } return [ 'success' => true,