Total Unpaid Invoices Added

This commit is contained in:
devansh bawari 2021-08-16 17:29:16 +05:30
parent 06608c17fb
commit 28ec9cb7b9
2 changed files with 58 additions and 8 deletions

View File

@ -2,12 +2,13 @@
namespace Webkul\Admin\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
use Webkul\Sales\Repositories\OrderRepository;
use Webkul\Sales\Repositories\OrderItemRepository;
use Illuminate\Support\Facades\DB;
use Webkul\Customer\Repositories\CustomerRepository;
use Webkul\Product\Repositories\ProductInventoryRepository;
use Webkul\Sales\Repositories\InvoiceRepository;
use Webkul\Sales\Repositories\OrderItemRepository;
use Webkul\Sales\Repositories\OrderRepository;
class DashboardController extends Controller
{
@ -32,6 +33,13 @@ class DashboardController extends Controller
*/
protected $orderItemRepository;
/**
* InvoiceRepository object
*
* @var \Webkul\Sales\Repositories\InvoiceRepository
*/
protected $invoiceRepository;
/**
* CustomerRepository object
*
@ -86,6 +94,7 @@ class DashboardController extends Controller
public function __construct(
OrderRepository $orderRepository,
OrderItemRepository $orderItemRepository,
InvoiceRepository $invoiceRepository,
CustomerRepository $customerRepository,
ProductInventoryRepository $productInventoryRepository
)
@ -98,6 +107,8 @@ class DashboardController extends Controller
$this->orderItemRepository = $orderItemRepository;
$this->invoiceRepository = $invoiceRepository;
$this->customerRepository = $customerRepository;
$this->productInventoryRepository = $productInventoryRepository;
@ -149,6 +160,11 @@ class DashboardController extends Controller
'current' => $current = $this->currentOrders()->avg('base_grand_total_invoiced') - $this->currentOrders()->avg('base_grand_total_refunded'),
'progress' => $this->getPercentageChange($previous, $current),
],
'total_unpaid_invoices' => [
'previous' => $previous = $this->getPendingInvoicesBetweenDate($this->lastStartDate, $this->lastEndDate),
'current' => $current = $this->getPendingInvoicesBetweenDate($this->startDate, $this->endDate),
'progress' => $this->getPercentageChange($previous, $current),
],
'top_selling_categories' => $this->getTopSellingCategories(),
'top_selling_products' => $this->getTopSellingProducts(),
'customer_with_most_sales' => $this->getCustomerWithMostSales(),
@ -260,12 +276,12 @@ class DashboardController extends Controller
public function setStartEndDate()
{
$this->startDate = request()->get('start')
? Carbon::createFromTimeString(request()->get('start') . " 00:00:01")
: Carbon::createFromTimeString(Carbon::now()->subDays(30)->format('Y-m-d') . " 00:00:01");
? Carbon::createFromTimeString(request()->get('start') . " 00:00:01")
: Carbon::createFromTimeString(Carbon::now()->subDays(30)->format('Y-m-d') . " 00:00:01");
$this->endDate = request()->get('end')
? Carbon::createFromTimeString(request()->get('end') . " 23:59:59")
: Carbon::now();
? Carbon::createFromTimeString(request()->get('end') . " 23:59:59")
: Carbon::now();
if ($this->endDate > Carbon::now()) {
$this->endDate = Carbon::now();
@ -275,7 +291,6 @@ class DashboardController extends Controller
$this->lastEndDate = clone $this->startDate;
$this->lastStartDate->subDays($this->startDate->diffInDays($this->endDate));
// $this->lastEndDate->subDays($this->lastStartDate->diffInDays($this->lastEndDate));
}
/**
@ -298,6 +313,15 @@ class DashboardController extends Controller
return $this->getOrdersBetweenDate($this->startDate, $this->endDate);
}
private function getPendingInvoicesBetweenDate($start, $end)
{
return $this->invoiceRepository
->where('invoices.created_at', '>=', $start)
->where('invoices.created_at', '<=', $end)
->where('state', 'pending')
->sum('grand_total');
}
/**
* Returns orders between two dates
*

View File

@ -125,6 +125,32 @@
</div>
</div>
<div class="dashboard-card">
<div class="title">
{{ __('admin::app.dashboard.total-unpaid-invoices') }}
</div>
<div class="data">
{{ core()->formatBasePrice($statistics['total_unpaid_invoices']['current']) }}
<span class="progress">
@if ($statistics['total_unpaid_invoices']['progress'] < 0)
<span class="icon graph-down-icon"></span>
{{ __('admin::app.dashboard.decreased', [
'progress' => -number_format($statistics['total_unpaid_invoices']['progress'], 1)
])
}}
@else
<span class="icon graph-up-icon"></span>
{{ __('admin::app.dashboard.increased', [
'progress' => number_format($statistics['total_unpaid_invoices']['progress'], 1)
])
}}
@endif
</span>
</div>
</div>
</div>
<div class="graph-stats">