Skip to content

Commit b4ab5dd

Browse files
committed
Deal products
1 parent bd1ca65 commit b4ab5dd

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<div class="row deal-product-row">
2+
<div class="col-6">
3+
@include('laravel-crm::partials.form.hidden',[
4+
'name' => 'item_deal_product_id['.$index.']',
5+
'value' => old('item_deal_product_id.'.$index, null),
6+
])
7+
<span class="autocomplete autocomplete-product-name" data-index="{{ $index }}">
8+
@include('laravel-crm::partials.form.hidden',[
9+
'name' => 'item_product_id['.$index.']',
10+
'value' => old('item_product_id.'.$index, null),
11+
])
12+
@include('laravel-crm::partials.form.text',[
13+
'name' => 'item_name['.$index.']',
14+
'label' => 'Item',
15+
'value' => old('item_name.'.$index, null),
16+
'attributes' => [
17+
'autocomplete' => \Illuminate\Support\Str::random(),
18+
19+
]
20+
])
21+
</span>
22+
</div>
23+
<div class="col">
24+
@include('laravel-crm::partials.form.text',[
25+
'name' => 'item_price['.$index.']',
26+
'label' => 'Price',
27+
'type' => 'number',
28+
'value' => old('item_price.'.$index, null) ,
29+
'attributes' => [
30+
'step' => .01
31+
]
32+
])
33+
</div>
34+
<div class="col">
35+
@include('laravel-crm::partials.form.text',[
36+
'name' => 'item_quantity['.$index.']',
37+
'label' => 'Quantity',
38+
'type' => 'number',
39+
'value' => old('item_quantity.'.$index, 1)
40+
])
41+
</div>
42+
<div class="col">
43+
@include('laravel-crm::partials.form.text',[
44+
'name' => 'item_amount['.$index.']',
45+
'label' => 'Amount',
46+
'type' => 'number',
47+
'value' => old('item_amount.'.$index, null) ,
48+
'attributes' => [
49+
'step' => .01,
50+
'readonly' => 'readonly'
51+
]
52+
])
53+
</div>
54+
</div>

resources/views/deals/partials/fields.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221
</div>
222222
</div>
223223
</span>
224-
<h6 class="text-uppercase mt-4 section-h6-title"><span class="fa fa-cart-arrow-down" aria-hidden="true"></span> Products <span class="float-right"><a href="{{ url(route('laravel-crm.deal-products.create', $deal)) }}" class="btn btn-outline-secondary btn-sm btn-action-add-deal-product"><span class="fa fa-plus" aria-hidden="true"></span></a></span></h6>
224+
<h6 class="text-uppercase mt-4 section-h6-title"><span class="fa fa-cart-arrow-down" aria-hidden="true"></span> Products <span class="float-right"><a href="{{ (isset($deal)) ? url(route('laravel-crm.deal-products.create', $deal)) : url(route('laravel-crm.deal-products.create-product')) }}" class="btn btn-outline-secondary btn-sm btn-action-add-deal-product"><span class="fa fa-plus" aria-hidden="true"></span></a></span></h6>
225225
<hr />
226226
<script type="text/javascript">
227227
let products = {!! \VentureDrake\LaravelCrm\Http\Helpers\AutoComplete\products() !!}

src/Http/Controllers/DealProductController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ public function create(Deal $deal)
3737
]);
3838
}
3939

40+
public function createProduct()
41+
{
42+
return view('laravel-crm::deal-products.create-product', [
43+
'index' => rand(),
44+
]);
45+
}
46+
4047
/**
4148
* Store a newly created resource in storage.
4249
*

src/Http/routes.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@
106106
/* Deals */
107107

108108
Route::group(['prefix' => 'deals', 'middleware' => 'auth.laravel-crm'], function () {
109+
Route::get('create-product', 'VentureDrake\LaravelCrm\Http\Controllers\DealProductController@createProduct')
110+
->name('laravel-crm.deal-products.create-product');
111+
109112
Route::get('', 'VentureDrake\LaravelCrm\Http\Controllers\DealController@index')
110113
->name('laravel-crm.deals.index')
111114
->middleware(['can:viewAny,VentureDrake\LaravelCrm\Models\Deal']);
@@ -240,7 +243,6 @@
240243
Route::post('', 'VentureDrake\LaravelCrm\Http\Controllers\PersonController@store')
241244
->name('laravel-crm.people.store')
242245
->middleware(['can:create,VentureDrake\LaravelCrm\Models\Person']);
243-
244246

245247
Route::get('{person}', 'VentureDrake\LaravelCrm\Http\Controllers\PersonController@show')
246248
->name('laravel-crm.people.show')

src/Services/DealService.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ public function create($request, $person = null, $organisation = null)
4040
]);
4141

4242
$deal->labels()->sync($request->labels ?? []);
43+
44+
if (isset($request->item_deal_product_id)) {
45+
foreach ($request->item_deal_product_id as $dealProductKey => $dealProductValue) {
46+
$deal->dealProducts()->create([
47+
'external_id' => Uuid::uuid4()->toString(),
48+
'product_id' => $request->item_product_id[$dealProductKey],
49+
'price' => $request->item_price[$dealProductKey],
50+
'quantity' => $request->item_quantity[$dealProductKey],
51+
'amount' => $request->item_amount[$dealProductKey],
52+
]);
53+
}
54+
}
4355

4456
return $deal;
4557
}

0 commit comments

Comments
 (0)