Skip to content

Commit

Permalink
new customer results with bar chart
Browse files Browse the repository at this point in the history
  • Loading branch information
indpurvesh committed Sep 16, 2020
1 parent dbeaadb commit d21f8c3
Show file tree
Hide file tree
Showing 13 changed files with 7,521 additions and 64 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"dependencies": {
"avored-components": "^0.1",
"axios": "^0.19.2",
"chart.js": "^2.9.3",
"chartjs": "^0.3.24",
"cross-env": "^7.0.2",
"laravel-mix": "^5.0.4",
"laravel-mix-alias": "^1.0.2",
Expand All @@ -26,6 +28,7 @@
"tailwindcss": "^1.4.6",
"vddl": "^0.7.1",
"vue": "^2.6.11",
"vue-chartjs": "^3.5.1",
"vue-i18n": "^8.18.2",
"vue-router": "^3.3.4",
"vue-simplemde": "^1.1.2",
Expand Down
52 changes: 52 additions & 0 deletions resources/js/modules/system/components/report/NewCustomer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<script>
import { Bar } from 'vue-chartjs'
export default {
extends: Bar,
props: {
customers: {
type: [Object, Array],
default: () => ({})
},
chartdata: {
type: Object,
default: () => ({})
},
options: {
type: Object,
default: () => ({
maintainAspectRatio: false,
title: {
display: true,
text: 'New Customer Report'
}
})
}
},
data() {
return {
}
},
mounted () {
this.chartdata.labels = []
this.chartdata.datasets = []
this.chartdata.datasets.push({
label: 'New Customers',
data: [],
fill: false,
borderColor: '#2554FF',
backgroundColor: '#2554FF',
borderWidth: 1
})
for (const label in this.customers) {
this.chartdata.labels.push(label)
this.chartdata.datasets[0].data.push(this.customers[label].length)
}
this.renderChart(this.chartdata, this.options)
}
}
</script>
2 changes: 2 additions & 0 deletions resources/js/services/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ Vue.use(AvoRedAlert)
Vue.use(AvoRedConfirm)


Vue.component('avored-new-customer-report', require('@/modules/system/components/report/NewCustomer.vue').default)

import Zondicon from 'vue-zondicons'
Vue.component('zondicon', Zondicon)
6 changes: 4 additions & 2 deletions resources/lang/en/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
'sent' => 'We have e-mailed your password reset link!',
'token' => 'This password reset token is invalid.',
'user' => "We can't find a user with that e-mail address.",
'new_customers' => 'New Custoners',
'new_customers' => 'New Customers',
'total_new_customers' => 'Total New Customer',
'new_customer_label' => 'In Perioud Label',
'time_period' => 'Time Period',
Expand All @@ -157,6 +157,8 @@
'first_name' => 'First Name',
'last_name' => 'Last Name',
'email' => 'Email',
'chart_label' => ':attribute Chart Information',
'table_label' => ':attribute Table Information',
'password-reset-btn' => 'Forgot your password?',
'password-confirmation' => 'Confirm your password',
'variation_title' => 'Product Variations',
Expand Down Expand Up @@ -358,7 +360,7 @@
'customer-group' => 'Customer Group',
'customer' => 'Customer',
'report' => 'Report',
'new_customer' => 'New Customers',
'new_customer' => 'New Customer',
'role' => 'Role',
'system' => 'System',
'state' => 'State',
Expand Down
73 changes: 41 additions & 32 deletions resources/views/report/new-customer.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="w-full block">
<form
method="post"
action="{{ route('admin.report.new-customers.post') }}">
action="{{ route('admin.report.post', ['identifier' => 'new-customer']) }}">
@csrf
<div class="flex">
<div class="w-1/2">
Expand Down Expand Up @@ -70,38 +70,47 @@ class="px-6 py-3 font-semibold inline-block text-white leading-7 hover:text-whit
</div>

@if ($displayReport)
<div class="w-full mt-5 block">
<h1 class="mt-3 text-red-700 text-2xl">{{ __('avored::system.new_customers') }}</h1>
<table class="mt-5 border-collapse table-auto w-full whitespace-no-wrap bg-white table-striped relative">
<thead>
<tr class="text-left">

<th class="bg-gray-100 sticky top-0 border-b border-gray-200 px-6 py-2 text-gray-600 font-bold tracking-wider uppercase text-xs">
{{ __('avored::system.new_customer_label') }}
</th>
<th class="bg-gray-100 sticky top-0 border-b border-gray-200 px-6 py-2 text-gray-600 font-bold tracking-wider uppercase text-xs">
{{ __('avored::system.total_new_customers') }}
</th>

</tr>
</thead>
<tbody>
@foreach ($customers as $key => $customer)
<tr>
<td class="border-dashed border-t border-gray-200 userId">
<span class="text-gray-700 px-6 py-3 flex items-center" >{{ $key }}</span>
</td>
<td class="border-dashed border-t border-gray-200 firstName">
<span class="text-gray-700 px-6 py-3 flex items-center">
{{ $customer->count() }}
</span>
</td>
</tr>
@endforeach

</tbody>
</table>
<div class="w-full mt-5 block">
<h1 class="mt-3 text-red-700 text-2xl">
{{ __('avored::system.chart_label', ['attribute' => __('avored::system.new_customers')]) }}
</h1>
<div class="block">
<avored-new-customer-report :customers="{{ json_encode($customers) }}" />
</div>

<h1 class="mt-5 text-red-700 text-2xl">
{{ __('avored::system.table_label', ['attribute' => __('avored::system.new_customers')]) }}
</h1>
<table class="mt-5 border-collapse table-auto w-full whitespace-no-wrap bg-white table-striped relative">
<thead>
<tr class="text-left">

<th class="bg-gray-100 sticky top-0 border-b border-gray-200 px-6 py-2 text-gray-600 font-bold tracking-wider uppercase text-xs">
{{ __('avored::system.new_customer_label') }}
</th>
<th class="bg-gray-100 sticky top-0 border-b border-gray-200 px-6 py-2 text-gray-600 font-bold tracking-wider uppercase text-xs">
{{ __('avored::system.total_new_customers') }}
</th>

</tr>
</thead>
<tbody>
@foreach ($customers as $key => $customer)
<tr>
<td class="border-dashed border-t border-gray-200 userId">
<span class="text-gray-700 px-6 py-3 flex items-center" >{{ $key }}</span>
</td>
<td class="border-dashed border-t border-gray-200 firstName">
<span class="text-gray-700 px-6 py-3 flex items-center">
{{ $customer->count() }}
</span>
</td>
</tr>
@endforeach

</tbody>
</table>
</div>
@endif
</div>
@endsection
8 changes: 4 additions & 4 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@

Route::resource('promotion-code', Promotion\Controllers\PromotionController::class);

Route::get('report/new-customers', [\AvoRed\Framework\Report\Controllers\NewCustomerController::class, 'index'])
->name('report.new-customers');
Route::post('report/new-customers/results', [\AvoRed\Framework\Report\Controllers\NewCustomerController::class, 'results'])
->name('report.new-customers.post');
Route::get('report/{identifier}', [\AvoRed\Framework\Report\Controllers\ReportController::class, 'index'])
->name('report.index');
Route::post('report/{identifier}', [\AvoRed\Framework\Report\Controllers\ReportController::class, 'results'])
->name('report.post');
// Route::get(
// 'promotion-code-edit/{promotionCode?}',
// Promotion\Controllers\PromotionCode\EditController::class
Expand Down
4 changes: 2 additions & 2 deletions src/Menu/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function key($key = null)
* Get/Set Admin Menu Route Name.
* @return \AvoRed\Framework\Menu\Menu|string
*/
public function route($routeName = null)
public function route($routeName = null, $params = [])
{
if (null !== $routeName) {
$this->routeName = $routeName;
Expand Down Expand Up @@ -207,4 +207,4 @@ public function hasSubMenu()

return false;
}
}
}
45 changes: 45 additions & 0 deletions src/Report/Controllers/ReportController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace AvoRed\Framework\Report\Controllers;

use Illuminate\Http\Request;
use AvoRed\Framework\Report\Report\NewCustomer;
use Illuminate\Support\Facades\Session;

class ReportController
{

/**
* Show Configuration of an AvoRed Admin.
* @return \Illuminate\View\View
*/
public function index(string $identifier)
{
$report = app(NewCustomer::class);
Session::put('report_new_customer', []);
$displayReport = false;

return view('avored::report.new-customer')
->with('timePeriodOptions', $report->options())
->with('displayReport', $displayReport);
}

/**
* Show Configuration of an AvoRed Admin.
* @return \Illuminate\Http\RedirectResponse
*/
public function results(Request $request)
{
$displayReport = true;
$report = app(NewCustomer::class);

Session::put('report_new_customer', $request->all());

$customers = $report->data($request);

return view('avored::report.new-customer')
->with('timePeriodOptions', $report->options())
->with('customers', $customers)
->with('displayReport', $displayReport);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<?php

namespace AvoRed\Framework\Report\Controllers;
namespace AvoRed\Framework\Report\Report;

use Illuminate\Http\Request;
use AvoRed\Framework\Support\Facades\Tab;
use AvoRed\Framework\Database\Contracts\CustomerModelInterface;
use Illuminate\Support\Facades\Session;

class NewCustomerController
class NewCustomer implements ReportInterface
{
/**
* Customer Repository for the New Customer Controller.
* Customer Repository for the Report Controller.
* @var \AvoRed\Framework\Database\Repository\CustomerRepository
*/
protected $customerRepository;
Expand Down Expand Up @@ -40,34 +39,21 @@ public function __construct(
* Show Configuration of an AvoRed Admin.
* @return \Illuminate\View\View
*/
public function index()
public function options()
{
Session::put('report_new_customer', []);
$displayReport = false;


return view('avored::report.new-customer')
->with('timePeriodOptions', $this->timePeriodOptions)
->with('displayReport', $displayReport);
return $this->timePeriodOptions;
}

/**
* Show Configuration of an AvoRed Admin.
* @return \Illuminate\Http\RedirectResponse
*/
public function results(Request $request)
public function data(Request $request)
{
$from = $request->get('from');
$to = $request->get('to');
$groupBy = $request->get('group_by');
$displayReport = true;
Session::put('report_new_customer', $request->all());

$customers = $this->customerRepository->getNewCustomersBy($from, $to, $groupBy);

return view('avored::report.new-customer')
->with('timePeriodOptions', $this->timePeriodOptions)
->with('customers', $customers)
->with('displayReport', $displayReport);
return $this->customerRepository->getNewCustomersBy($from, $to, $groupBy);
}
}
22 changes: 22 additions & 0 deletions src/Report/Report/ReportInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace AvoRed\Framework\Report\Report;

use Illuminate\Http\Request;

interface ReportInterface
{
/**
* Options that is required to for the report filter
* @return mixed
*/
public function options();

/**
* Report data based on the given filter
* @param Request $request
* @return mixed
*/
public function data(Request $request);

}
3 changes: 2 additions & 1 deletion src/Support/Providers/MenuProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ public function registerAdminMenu()
$menu->key('new_customer')
->type(MenuItem::ADMIN)
->label('avored::system.admin_menus.new_customer')
->route('admin.report.new-customers');
->route('admin.report.index')
->params(['identifier' => 'new-customer']);
});

Menu::make('user', function (MenuItem $menu) {
Expand Down
Loading

0 comments on commit d21f8c3

Please sign in to comment.