Improved admin package code standard

This commit is contained in:
Jitendra Singh 2020-02-19 15:56:44 +05:30
parent b4c68c7f0b
commit 99d506db94
16 changed files with 45 additions and 53 deletions

View File

@ -5,7 +5,6 @@ namespace Webkul\Admin\Exceptions;
use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Database\Eloquent\PDOException;
use Illuminate\Database\Eloquent\ErrorException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

View File

@ -12,16 +12,14 @@ use Maatwebsite\Excel\Concerns\ShouldAutoSize;
* @author Rahul Shukla <rahulshukla.symfony517@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class DataGridExport implements FromView, ShouldAutoSize
{
/**
* DataGrid instance
*
* @var mixed
*/
protected $gridData = array();
protected $gridData = [];
/**
* Create a new instance.
@ -40,7 +38,7 @@ class DataGridExport implements FromView, ShouldAutoSize
*/
public function view(): View
{
$columns = array();
$columns = [];
foreach($this->gridData as $key => $gridData) {
$columns = array_keys((array) $gridData);

View File

@ -51,7 +51,6 @@ class ConfigurationController extends Controller
$this->_config = request('_config');
$this->prepareConfigTree();
}
/**

View File

@ -152,7 +152,6 @@ class AddressController extends Controller
$address = $this->customerAddress->find($id);
if ($address) {
$this->customerAddress->update($data, $id);
session()->flash('success', trans('admin::app.customers.addresses.success-update'));

View File

@ -225,9 +225,7 @@ class CustomerController extends Controller
$customer = $this->customerRepository->find(request()->input('_customer'));
$noteTaken = $customer->update([
'notes' => request()->input('notes'),
]);
$noteTaken = $customer->update(['notes' => request()->input('notes')]);
if ($noteTaken) {
session()->flash('success', 'Note taken');
@ -251,9 +249,7 @@ class CustomerController extends Controller
foreach ($customerIds as $customerId) {
$customer = $this->customerRepository->find($customerId);
$customer->update([
'status' => $updateOption,
]);
$customer->update(['status' => $updateOption]);
}
session()->flash('success', trans('admin::app.customers.customers.mass-update-success'));
@ -271,9 +267,7 @@ class CustomerController extends Controller
$customerIds = explode(',', request()->input('indexes'));
foreach ($customerIds as $customerId) {
$this->customerRepository->deleteWhere([
'id' => $customerId,
]);
$this->customerRepository->deleteWhere(['id' => $customerId]);
}
session()->flash('success', trans('admin::app.customers.customers.mass-destroy-success'));

View File

@ -116,8 +116,9 @@ class DashboardController extends Controller
*/
public function getPercentageChange($previous, $current)
{
if (! $previous)
if (! $previous) {
return $current ? 100 : 0;
}
return ($current - $previous) / $previous * 100;
}
@ -132,30 +133,30 @@ class DashboardController extends Controller
$this->setStartEndDate();
$statistics = [
'total_customers' => [
'total_customers' => [
'previous' => $previous = $this->getCustomersBetweenDates($this->lastStartDate, $this->lastEndDate)->count(),
'current' => $current = $this->getCustomersBetweenDates($this->startDate, $this->endDate)->count(),
'current' => $current = $this->getCustomersBetweenDates($this->startDate, $this->endDate)->count(),
'progress' => $this->getPercentageChange($previous, $current)
],
'total_orders' => [
'total_orders' => [
'previous' => $previous = $this->previousOrders()->count(),
'current' => $current = $this->currentOrders()->count(),
'current' => $current = $this->currentOrders()->count(),
'progress' => $this->getPercentageChange($previous, $current)
],
'total_sales' => [
'total_sales' => [
'previous' => $previous = $this->previousOrders()->sum('base_grand_total_invoiced') - $this->previousOrders()->sum('base_grand_total_refunded'),
'current' => $current = $this->currentOrders()->sum('base_grand_total_invoiced') - $this->currentOrders()->sum('base_grand_total_refunded'),
'current' => $current = $this->currentOrders()->sum('base_grand_total_invoiced') - $this->currentOrders()->sum('base_grand_total_refunded'),
'progress' => $this->getPercentageChange($previous, $current)
],
'avg_sales' => [
'avg_sales' => [
'previous' => $previous = $this->previousOrders()->avg('base_grand_total_invoiced') - $this->previousOrders()->avg('base_grand_total_refunded'),
'current' => $current = $this->currentOrders()->avg('base_grand_total_invoiced') - $this->currentOrders()->avg('base_grand_total_refunded'),
'current' => $current = $this->currentOrders()->avg('base_grand_total_invoiced') - $this->currentOrders()->avg('base_grand_total_refunded'),
'progress' => $this->getPercentageChange($previous, $current)
],
'top_selling_categories' => $this->getTopSellingCategories(),
'top_selling_products' => $this->getTopSellingProducts(),
'top_selling_categories' => $this->getTopSellingCategories(),
'top_selling_products' => $this->getTopSellingProducts(),
'customer_with_most_sales' => $this->getCustomerWithMostSales(),
'stock_threshold' => $this->getStockThreshold(),
'stock_threshold' => $this->getStockThreshold(),
];
foreach (core()->getTimeInterval($this->startDate, $this->endDate) as $interval) {
@ -264,8 +265,9 @@ class DashboardController extends Controller
? Carbon::createFromTimeString(request()->get('end') . " 23:59:59")
: Carbon::now();
if ($this->endDate > Carbon::now())
if ($this->endDate > Carbon::now()) {
$this->endDate = Carbon::now();
}
$this->lastStartDate = clone $this->startDate;
$this->lastEndDate = clone $this->startDate;

View File

@ -38,6 +38,7 @@ class ExportController extends Controller
$format = $criteria['format'];
$gridName = explode('\\', $criteria['gridName']);
$path = '\Webkul\Admin\DataGrids'.'\\'.last($gridName);
$proceed = false;
@ -53,6 +54,7 @@ class ExportController extends Controller
}
$gridInstance = new $path;
$records = $gridInstance->export();
if (count($records) == 0) {

View File

@ -103,6 +103,7 @@ class InvoiceController extends Controller
$data = request()->all();
$haveProductToInvoice = false;
foreach ($data['invoice']['items'] as $itemId => $qty) {
if ($qty) {
$haveProductToInvoice = true;

View File

@ -40,7 +40,6 @@ class OrderController extends Controller
$this->_config = request('_config');
$this->orderRepository = $orderRepository;
}
/**

View File

@ -148,8 +148,9 @@ class RefundController extends Controller
{
$data = $this->refundRepository->getOrderItemsRefundSummary(request()->all(), $orderId);
if (! $data)
if (! $data) {
return response('');
}
return response()->json($data);
}

View File

@ -115,9 +115,9 @@ class ShipmentController extends Controller
$this->validate(request(), [
'shipment.carrier_title' => 'required',
'shipment.track_number' => 'required',
'shipment.source' => 'required',
'shipment.items.*.*' => 'required|numeric|min:0',
'shipment.track_number' => 'required',
'shipment.source' => 'required',
'shipment.items.*.*' => 'required|numeric|min:0',
]);
$data = request()->all();
@ -143,8 +143,9 @@ class ShipmentController extends Controller
*/
public function isInventoryValidate(&$data)
{
if (! isset($data['shipment']['items']))
if (! isset($data['shipment']['items'])) {
return ;
}
$valid = false;
@ -154,13 +155,15 @@ class ShipmentController extends Controller
if ($qty = $inventorySource[$inventorySourceId]) {
$orderItem = $this->orderItemRepository->find($itemId);
if ($orderItem->qty_to_ship < $qty)
if ($orderItem->qty_to_ship < $qty) {
return false;
}
if ($orderItem->getTypeInstance()->isComposite()) {
foreach ($orderItem->children as $child) {
if (! $child->qty_ordered)
if (! $child->qty_ordered) {
continue;
}
$finalQty = ($child->qty_ordered / $orderItem->qty_ordered) * $qty;
@ -168,16 +171,18 @@ class ShipmentController extends Controller
->where('inventory_source_id', $inventorySourceId)
->sum('qty');
if ($child->qty_to_ship < $finalQty || $availableQty < $finalQty)
if ($child->qty_to_ship < $finalQty || $availableQty < $finalQty) {
return false;
}
}
} else {
$availableQty = $orderItem->product->inventories()
->where('inventory_source_id', $inventorySourceId)
->sum('qty');
if ($orderItem->qty_to_ship < $qty || $availableQty < $qty)
if ($orderItem->qty_to_ship < $qty || $availableQty < $qty) {
return false;
}
}
$valid = true;

View File

@ -26,13 +26,6 @@ class ConfigurationForm extends FormRequest
{
$this->rules = [];
// if (request()->has('sales.orderSettings.order_number')) {
// $this->rules = [
// 'sales.orderSettings.order_number.order_number_prefix' => 'required|regex:/^[a-zA-Z0-9$%^&*@]+$/u',
// 'sales.orderSettings.order_number.order_number_suffix' => 'required|regex:/^[a-zA-Z0-9$%^&*@]+$/u',
// ];
// }
if (request()->has('general.design.admin_logo.logo_image') && ! request()->input('general.design.admin_logo.logo_image.delete')) {
$this->rules = [
'general.design.admin_logo.logo_image' => 'required|mimes:jpeg,bmp,png,jpg'
@ -46,12 +39,10 @@ class ConfigurationForm extends FormRequest
* Get the error messages for the defined validation rules.
*
* @return array
*/
*/
public function messages()
{
return [
// 'sales.orderSettings.order_number.order_number_prefix.regex' => 'Invalid format. Can not use #.',
// 'sales.orderSettings.order_number.order_number_suffix.regex' => 'Invalid format. Can not use #.',
'general.design.admin_logo.logo_image.mimes' => 'Invalid file format. Use only jpeg, bmp, png, jpg.'
];
}

View File

@ -11,9 +11,10 @@ class CancelOrderNotification extends Mailable
{
use Queueable, SerializesModels;
/*
/**
* @var Order
* */
*
*/
public $order;
public function __construct($order)

View File

@ -24,7 +24,6 @@ class NewAdminNotification extends Mailable
*/
public $order;
/**
* Create a new message instance.
*

View File

@ -43,6 +43,7 @@ class NewInventorySourceNotification extends Mailable
public function build()
{
$order = $this->shipment->order;
$inventory = $this->shipment->inventory_source;
return $this->to($inventory->contact_email, $inventory->name)

View File

@ -139,8 +139,9 @@ class AdminServiceProvider extends ServiceProvider
{
static $tree;
if ($tree)
if ($tree) {
return $tree;
}
$tree = Tree::create();