Skip to content

Commit a3e2ce3

Browse files
committed
Update related order deliveries
1 parent 64c3bb0 commit a3e2ce3

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

resources/views/deliveries/partials/card-show.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<dt class="col-sm-4 text-right">{{ ucfirst(__('laravel-crm::lang.reference')) }}</dt>
4242
<dd class="col-sm-8">
4343
@if($delivery->order)
44-
<a href="{{ route('laravel-crm.orders.show', $delivery->order) }}">{{ $delivery->order->reference }}</a>
44+
{{ $delivery->order->reference }}
4545
@endif
4646
</dd>
4747
@hasordersenabled

src/Console/LaravelCrmUpdate.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Console\Command;
66
use Illuminate\Support\Composer;
7+
use VentureDrake\LaravelCrm\Models\Delivery;
78
use VentureDrake\LaravelCrm\Models\Invoice;
89
use VentureDrake\LaravelCrm\Models\Order;
910
use VentureDrake\LaravelCrm\Models\Person;
@@ -150,6 +151,29 @@ public function handle()
150151
$this->info('Updating Laravel CRM split orders, invoices & deliveries complete.');
151152
}
152153

154+
if($this->settingService->get('db_update_0193')->value == 0) {
155+
$this->info('Updating Laravel CRM split deliveries...');
156+
157+
foreach(Delivery::whereNotNull('order_id')->get() as $delivery) {
158+
if($delivery->order) {
159+
foreach($delivery->order->orderProducts as $orderProduct) {
160+
if($deliveryProduct = $delivery->deliveryProducts()
161+
->whereNull('quantity')
162+
->where([
163+
'order_product_id' => $orderProduct->id,
164+
])->first()) {
165+
$deliveryProduct->update([
166+
'quantity' => $orderProduct->quantity
167+
]);
168+
}
169+
}
170+
}
171+
}
172+
173+
$this->settingService->set('db_update_0193', 1);
174+
$this->info('Updating Laravel CRM split deliveries complete.');
175+
}
176+
153177
$this->info('Laravel CRM is now updated.');
154178
}
155179
}

src/Http/Middleware/Settings.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ public function handle($request, Closure $next)
159159
]);
160160
}
161161

162+
if((int) Str::replace('.', '', config('laravel-crm.version')) >= 193) {
163+
Setting::firstOrCreate([
164+
'global' => 1,
165+
'name' => 'db_update_0193',
166+
], [
167+
'value' => 0,
168+
]);
169+
}
170+
162171
$installIdSetting = Setting::where([
163172
'name' => 'install_id',
164173
])->first();

src/Http/Middleware/SystemCheck.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ public function handle($request, Closure $next)
5858
}
5959
}
6060

61+
if($setting = \VentureDrake\LaravelCrm\Models\Setting::where('name', 'db_update_0193')->first()) {
62+
if($setting->value == 0) {
63+
$dbUpdateRequired = true;
64+
}
65+
}
66+
6167
if($dbUpdateRequired) {
6268
flash('Your Laravel CRM software version requires some database updates to function correctly. Please <a href="https://github.com/venturedrake/laravel-crm#upgrading-from--02">update database</a>')->info()->important();
6369
}

0 commit comments

Comments
 (0)