From 6f4aebe423b3704a1c04e43bd6cbf0a2ce35f86c Mon Sep 17 00:00:00 2001 From: Prashant Singh Date: Fri, 11 Jan 2019 13:58:44 +0530 Subject: [PATCH] Datagrid enhancements and fault tolerant to column orders display and safe implementation of wrappers --- .../Admin/src/DataGrids/AttributeDataGrid.php | 32 ++- .../Admin/src/DataGrids/CategoryDataGrid.php | 10 +- .../Admin/src/DataGrids/CustomerDataGrid.php | 8 +- .../src/DataGrids/CustomerGroupDataGrid.php | 4 +- .../src/DataGrids/CustomerReviewDataGrid.php | 9 +- .../DataGrids/InventorySourcesDataGrid.php | 8 +- .../src/DataGrids/NewsLetterDataGrid.php | 8 +- .../Admin/src/DataGrids/OrderDataGrid.php | 268 ++++++++---------- .../src/DataGrids/OrderInvoicesDataGrid.php | 198 +++++-------- .../src/DataGrids/OrderShipmentsDataGrid.php | 222 ++++++--------- .../Admin/src/DataGrids/TestDataGrid.php | 14 +- .../Admin/src/DataGrids/UserDataGrid.php | 6 +- .../views/sales/invoices/index.blade.php | 12 +- .../views/sales/orders/index.blade.php | 12 +- .../views/sales/shipments/index.blade.php | 12 +- .../Webkul/Product/src/Helpers/Toolbar.php | 2 +- .../Resources/views/testgrid/body.blade.php | 27 +- 17 files changed, 381 insertions(+), 471 deletions(-) diff --git a/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php b/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php index a0886d882..fa7a936c3 100755 --- a/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/AttributeDataGrid.php @@ -75,7 +75,13 @@ class AttributeDataGrid extends AbsGrid 'type' => 'boolean', 'sortable' => true, 'searchable' => false, - 'width' => '100px' + 'width' => '100px', + 'wrapper' => function($value){ + if($value == 1) + return 'True'; + else + return 'False'; + } ]); $this->addColumn([ @@ -85,7 +91,13 @@ class AttributeDataGrid extends AbsGrid 'type' => 'boolean', 'sortable' => true, 'searchable' => false, - 'width' => '100px' + 'width' => '100px', + 'wrapper' => function($value){ + if($value == 1) + return 'True'; + else + return 'False'; + } ]); $this->addColumn([ @@ -95,7 +107,13 @@ class AttributeDataGrid extends AbsGrid 'type' => 'boolean', 'sortable' => true, 'searchable' => false, - 'width' => '100px' + 'width' => '100px', + 'wrapper' => function($value){ + if($value == 1) + return 'True'; + else + return 'False'; + } ]); $this->addColumn([ @@ -105,7 +123,13 @@ class AttributeDataGrid extends AbsGrid 'type' => 'boolean', 'sortable' => true, 'searchable' => false, - 'width' => '100px' + 'width' => '100px', + 'wrapper' => function($value){ + if($value == 1) + return 'True'; + else + return 'False'; + } ]); } diff --git a/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php index 9fca0077f..8665cab42 100755 --- a/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CategoryDataGrid.php @@ -61,11 +61,17 @@ class CategoryDataGrid extends AbsGrid $this->addColumn([ 'index' => 'cat.status', 'alias' => 'catStatus', - 'label' => 'Type', + 'label' => 'Status', 'type' => 'boolean', 'sortable' => true, 'searchable' => true, - 'width' => '100px' + 'width' => '100px', + 'wrapper' => function($value){ + if($value == 1) + return 'Active'; + else + return 'Inactive'; + } ]); $this->addColumn([ diff --git a/packages/Webkul/Admin/src/DataGrids/CustomerDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CustomerDataGrid.php index 442c81d61..463534b67 100755 --- a/packages/Webkul/Admin/src/DataGrids/CustomerDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CustomerDataGrid.php @@ -29,7 +29,7 @@ class CustomerDataGrid extends AbsGrid public function addColumns() { $this->addColumn([ - 'column' => 'cus.id', + 'index' => 'cus.id', 'alias' => 'customerId', 'label' => 'ID', 'type' => 'number', @@ -40,7 +40,7 @@ class CustomerDataGrid extends AbsGrid $this->addColumn([ // 'column' => 'CONCAT(cus.first_name, " ", cus.last_name)', - 'column' => 'cus.first_name', + 'index' => 'cus.first_name', 'alias' => 'customerFullName', 'label' => 'Name', 'type' => 'string', @@ -50,7 +50,7 @@ class CustomerDataGrid extends AbsGrid ]); $this->addColumn([ - 'column' => 'cus.email', + 'index' => 'cus.email', 'alias' => 'customerEmail', 'label' => 'Email', 'type' => 'string', @@ -60,7 +60,7 @@ class CustomerDataGrid extends AbsGrid ]); $this->addColumn([ - 'column' => 'cg.name', + 'index' => 'cg.name', 'alias' => 'customerGroupName', 'label' => 'Group', 'type' => 'string', diff --git a/packages/Webkul/Admin/src/DataGrids/CustomerGroupDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CustomerGroupDataGrid.php index 5e45525eb..64891c0d3 100755 --- a/packages/Webkul/Admin/src/DataGrids/CustomerGroupDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CustomerGroupDataGrid.php @@ -29,7 +29,7 @@ class CustomerGroupDataGrid extends AbsGrid public function addColumns() { $this->addColumn([ - 'column' => 'id', + 'index' => 'id', 'alias' => 'groupId', 'label' => 'ID', 'type' => 'number', @@ -40,7 +40,7 @@ class CustomerGroupDataGrid extends AbsGrid $this->addColumn([ // 'column' => 'CONCAT(cus.first_name, " ", cus.last_name)', - 'column' => 'name', + 'index' => 'name', 'alias' => 'groupName', 'label' => 'Name', 'type' => 'string', diff --git a/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php b/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php index 3693884d6..015f0783e 100755 --- a/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/CustomerReviewDataGrid.php @@ -75,7 +75,14 @@ class CustomerReviewDataGrid extends AbsGrid 'type' => 'boolean', 'searchable' => true, 'sortable' => true, - 'width' => '100px' + 'width' => '100px', + 'closure' => true, + 'wrapper' => function ($value) { + if($value == 'approved') + return 'Approved'; + else if($value == "pending") + return 'Pending'; + }, ]); } diff --git a/packages/Webkul/Admin/src/DataGrids/InventorySourcesDataGrid.php b/packages/Webkul/Admin/src/DataGrids/InventorySourcesDataGrid.php index 81ae566d6..668fe3bc3 100755 --- a/packages/Webkul/Admin/src/DataGrids/InventorySourcesDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/InventorySourcesDataGrid.php @@ -75,7 +75,13 @@ class InventorySourcesDataGrid extends AbsGrid 'type' => 'boolean', 'searchable' => true, 'sortable' => true, - 'width' => '100px' + 'width' => '100px', + 'wrapper' => function($value){ + if($value == 1) + return 'Active'; + else + return 'Inactive'; + } ]); } diff --git a/packages/Webkul/Admin/src/DataGrids/NewsLetterDataGrid.php b/packages/Webkul/Admin/src/DataGrids/NewsLetterDataGrid.php index 9ba0df5b7..84d7e2dad 100755 --- a/packages/Webkul/Admin/src/DataGrids/NewsLetterDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/NewsLetterDataGrid.php @@ -45,7 +45,13 @@ class NewsLetterDataGrid extends AbsGrid 'type' => 'string', 'searchable' => true, 'sortable' => true, - 'width' => '100px' + 'width' => '100px', + 'wrapper' => function($value){ + if($value == 1) + return 'True'; + else + return 'False'; + } ]); $this->addColumn([ diff --git a/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php b/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php index 512281de6..b2913d2dc 100755 --- a/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/OrderDataGrid.php @@ -2,177 +2,139 @@ namespace Webkul\Admin\DataGrids; -use Illuminate\View\View; -use Webkul\Ui\DataGrid\Facades\DataGrid; +use Webkul\Ui\DataGrid\AbsGrid; +use DB; /** - * OrderDataGrid + * Product Data Grid class * - * @author Prashant Singh @prashant-webkul + * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class OrderDataGrid +class OrderDataGrid extends AbsGrid { + public $allColumns = []; - /** - * The Data Grid implementation for orders - */ - public function createOrderDataGrid() + public function prepareQueryBuilder() { - return DataGrid::make([ - 'name' => 'orders', - 'table' => 'orders as or', - 'select' => 'or.id', - 'perpage' => 10, - 'aliased' => false, //True in case of joins else aliasing key required on all cases + $queryBuilder = DB::table('orders')->select('id', 'base_grand_total', 'grand_total', 'created_at', 'channel_name', 'status')->addSelect(DB::raw('CONCAT(customer_first_name, " ", customer_last_name) as fullname')); - 'massoperations' =>[ - // [ - // 'route' => route('admin.datagrid.delete'), - // 'method' => 'DELETE', - // 'label' => 'Delete', - // 'type' => 'button', - // ], - ], + $this->setQueryBuilder($queryBuilder); + } - 'actions' => [ - [ - 'type' => 'View', - 'route' => 'admin.sales.orders.view', - // 'confirm_text' => 'Do you really want to view this record?', - 'icon' => 'icon eye-icon', - 'icon-alt' => 'View' - ] - ], + public function setIndex() { + $this->index = 'id'; //the column that needs to be treated as index column + } - 'join' => [], + public function addColumns() + { + $this->addColumn([ + 'index' => 'id', + 'alias' => 'orderId', + 'label' => 'ID', + 'type' => 'number', + 'searchable' => false, + 'sortable' => true, + 'width' => '40px' + ]); - //use aliasing on secodary columns if join is performed - 'columns' => [ - [ - 'name' => 'or.id', - 'alias' => 'orderid', - 'type' => 'number', - 'label' => 'ID', - 'sortable' => true, - ], [ - 'name' => 'CONCAT(or.customer_first_name, " ", or.customer_last_name)', - 'alias' => 'oafirstname', - 'type' => 'string', - 'label' => 'Billed To', - 'sortable' => false, - ], [ - 'name' => 'or.base_grand_total', - 'alias' => 'orbasegrandtotal', - 'type' => 'string', - 'label' => 'Base Total', - 'sortable' => true, - 'wrapper' => function ($value) { - return core()->formatBasePrice($value); - } - ], [ - 'name' => 'or.grand_total', - 'alias' => 'oagrandtotal', - 'type' => 'string', - 'label' => 'Grand Total', - 'sortable' => false, - 'wrapper' => function ($value) { - return core()->formatBasePrice($value); - } - ], [ - 'name' => 'or.created_at', - 'alias' => 'createdat', - 'type' => 'datetime', - 'label' => 'Order Date', - 'sortable' => true, - ], [ - 'name' => 'or.channel_name', - 'alias' => 'channelname', - 'type' => 'string', - 'label' => 'Channel Name', - 'sortable' => true, - ], [ - 'name' => 'or.status', - 'alias' => 'orstatus', - 'type' => 'string', - 'label' => 'Status', - 'sortable' => true, - 'closure' => true, //to be used when ever wrappers or callables are used - 'wrapper' => function ($value) { - if($value == 'processing') - return 'Processing'; - else if($value == 'completed') - return 'Completed'; - else if($value == "canceled") - return 'Canceled'; - else if($value == "closed") - return 'Closed'; - else if($value == "pending") - return 'Pending'; - else if($value == "pending_payment") - return 'Pending Payment'; - else if($value == "fraud") - return 'Fraud'; - }, - ], - ], + $this->addColumn([ + 'index' => 'base_grand_total', + 'alias' => 'baseGrandTotal', + 'label' => 'Base Total', + 'type' => 'string', + 'searchable' => true, + 'sortable' => true, + 'width' => '100px', + 'wrapper' => function ($value) { + return core()->formatBasePrice($value); + } + ]); - 'filterable' => [ - [ - 'column' => 'or.id', - 'alias' => 'orderid', - 'type' => 'number', - 'label' => 'ID', - ], [ - 'column' => 'or.status', - 'alias' => 'orstatus', - 'type' => 'string', - 'label' => 'Status' - ], [ - 'column' => 'or.created_at', - 'alias' => 'createdat', - 'type' => 'datetime', - 'label' => 'Order Date', - ], [ - 'column' => 'CONCAT(or.customer_first_name, " ", or.customer_last_name)', - 'alias' => 'oafirstname', - 'type' => 'string', - 'label' => 'Billed To', - ], - ], + $this->addColumn([ + 'index' => 'grand_total', + 'alias' => 'grandTotal', + 'label' => 'Grand Total', + 'type' => 'string', + 'searchable' => true, + 'sortable' => true, + 'width' => '100px', + 'wrapper' => function ($value) { + return core()->formatBasePrice($value); + } + ]); - //don't use aliasing in case of searchables - 'searchable' => [ - [ - 'column' => 'or.id', - 'alias' => 'orderid', - 'type' => 'number', - ], [ - 'column' => 'or.status', - 'alias' => 'orstatus', - 'type' => 'string', - ] - ], + $this->addColumn([ + 'index' => 'created_at', + 'alias' => 'orderDate', + 'label' => 'Order Date', + 'type' => 'string', + 'sortable' => true, + 'searchable' => true, + 'width' => '100px', + ]); - //list of viable operators that will be used - 'operators' => [ - 'eq' => "=", - 'lt' => "<", - 'gt' => ">", - 'lte' => "<=", - 'gte' => ">=", - 'neqs' => "<>", - 'neqn' => "!=", - 'like' => "like", - 'nlike' => "not like", - ], + $this->addColumn([ + 'index' => 'channel_name', + 'alias' => 'channelName', + 'label' => 'Channel Name', + 'type' => 'string', + 'sortable' => true, + 'searchable' => false, + 'width' => '100px' + ]); - // 'css' => [] + $this->addColumn([ + 'index' => 'status', + 'alias' => 'status', + 'label' => 'Status', + 'type' => 'string', + 'sortable' => true, + 'searchable' => false, + 'width' => '100px', + 'closure' => true, + 'wrapper' => function ($value) { + if($value == 'processing') + return 'Processing'; + else if($value == 'completed') + return 'Completed'; + else if($value == "canceled") + return 'Canceled'; + else if($value == "closed") + return 'Closed'; + else if($value == "pending") + return 'Pending'; + else if($value == "pending_payment") + return 'Pending Payment'; + else if($value == "fraud") + return 'Fraud'; + } + ]); + + $this->addColumn([ + 'index' => 'fullname', + 'alias' => 'fullName', + 'label' => 'Billed To', + 'type' => 'string', + 'searchable' => false, + 'sortable' => true, + 'width' => '100px' ]); } - public function render($pagination = true) - { - return $this->createOrderDataGrid()->render($pagination); + public function prepareActions() { + $this->addAction([ + 'type' => 'View', + 'route' => 'admin.sales.orders.view', + 'icon' => 'icon eye-icon' + ]); + } + + public function prepareMassActions() { + // $this->addMassAction([ + // 'type' => 'delete', + // 'action' => route('admin.catalog.attributes.massdelete'), + // 'method' => 'DELETE' + // ]); } } \ No newline at end of file diff --git a/packages/Webkul/Admin/src/DataGrids/OrderInvoicesDataGrid.php b/packages/Webkul/Admin/src/DataGrids/OrderInvoicesDataGrid.php index be9ab208f..b21410693 100755 --- a/packages/Webkul/Admin/src/DataGrids/OrderInvoicesDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/OrderInvoicesDataGrid.php @@ -2,156 +2,86 @@ namespace Webkul\Admin\DataGrids; -use Illuminate\View\View; -use Webkul\Ui\DataGrid\Facades\DataGrid; +use Webkul\Ui\DataGrid\AbsGrid; +use DB; /** - * OrderInvoicesDataGrid + * Product Data Grid class * - * @author Prashant Singh @prashant-webkul + * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class OrderInvoicesDataGrid +class OrderInvoicesDataGrid extends AbsGrid { + public $allColumns = []; - /** - * The Order invoices Data Grid implementation for invoices of orders - */ - public function createOrderInvoicesDataGrid() + public function prepareQueryBuilder() { + $queryBuilder = DB::table('invoices')->select('id', 'order_id', 'state', 'grand_total', 'created_at'); - return DataGrid::make([ - 'name' => 'invoices', - 'table' => 'invoices as inv', - 'select' => 'inv.id', - 'perpage' => 10, - 'aliased' => false, + $this->setQueryBuilder($queryBuilder); + } - 'massoperations' =>[ - // [ - // 'route' => route('admin.datagrid.delete'), - // 'method' => 'DELETE', - // 'label' => 'Delete', - // 'type' => 'button', - // ], - ], + public function setIndex() { + $this->index = 'id'; //the column that needs to be treated as index column + } - 'actions' => [ - [ - 'type' => 'View', - 'route' => 'admin.sales.invoices.view', - // 'confirm_text' => 'Do you really want to view this record?', - 'icon' => 'icon eye-icon', - 'icon-alt' => 'View' - ], - ], + public function addColumns() + { + $this->addColumn([ + 'index' => 'id', + 'alias' => 'invid', + 'label' => 'ID', + 'type' => 'number', + 'searchable' => false, + 'sortable' => true, + 'width' => '40px' + ]); - 'join' => [ - // [ - // 'join' => 'leftjoin', - // 'table' => 'orders as ors', - // 'primaryKey' => 'inv.order_id', - // 'condition' => '=', - // 'secondaryKey' => 'ors.id', - // ] - ], + $this->addColumn([ + 'index' => 'order_id', + 'alias' => 'orderId', + 'label' => 'Order ID', + 'type' => 'number', + 'searchable' => false, + 'sortable' => true, + 'width' => '100px' + ]); - //use aliasing on secodary columns if join is performed + $this->addColumn([ + 'index' => 'grand_total', + 'alias' => 'invgrandtotal', + 'label' => 'Grand Total', + 'type' => 'string', + 'searchable' => true, + 'sortable' => true, + 'width' => '100px', + ]); - 'columns' => [ - [ - 'name' => 'inv.id', - 'alias' => 'invid', - 'type' => 'number', - 'label' => 'ID', - 'sortable' => true - ], [ - 'name' => 'inv.order_id', - 'alias' => 'invorderid', - 'type' => 'number', - 'label' => 'Order ID', - 'sortable' => true - ], [ - 'name' => 'inv.state', - 'alias' => 'invstate', - 'type' => 'string', - 'label' => 'State', - 'sortable' => true - ], [ - 'name' => 'inv.grand_total', - 'alias' => 'invgrandtotal', - 'type' => 'number', - 'label' => 'Amount', - 'sortable' => true, - 'wrapper' => function ($value) { - return core()->formatBasePrice($value); - }, - ], [ - 'name' => 'inv.created_at', - 'alias' => 'invcreated_at', - 'type' => 'datetime', - 'label' => 'Invoice Date', - 'sortable' => true - ] - ], - - 'filterable' => [ - [ - 'column' => 'inv.id', - 'alias' => 'invid', - 'type' => 'number', - 'label' => 'ID', - ], [ - 'column' => 'inv.order_id', - 'alias' => 'invorderid', - 'type' => 'number', - 'label' => 'Order ID', - ], [ - 'column' => 'inv.state', - 'alias' => 'invstate', - 'type' => 'string', - 'label' => 'State', - ], [ - 'column' => 'inv.grand_total', - 'alias' => 'invgrandtotal', - 'type' => 'number', - 'label' => 'Amount', - ], [ - 'column' => 'inv.created_at', - 'alias' => 'invcreated_at', - 'type' => 'datetime', - 'label' => 'Invoice Date', - ] - ], - //don't use aliasing in case of searchables - - 'searchable' => [ - // [ - // 'column' => 'or.id', - // 'alias' => 'orderid', - // 'type' => 'number', - // 'label' => 'ID', - // ] - ], - - //list of viable operators that will be used - 'operators' => [ - 'eq' => "=", - 'lt' => "<", - 'gt' => ">", - 'lte' => "<=", - 'gte' => ">=", - 'neqs' => "<>", - 'neqn' => "!=", - 'like' => "like", - 'nlike' => "not like", - ], - // 'css' => [] + $this->addColumn([ + 'index' => 'created_at', + 'alias' => 'invcreatedat', + 'label' => 'Invoice Date', + 'type' => 'datetime', + 'searchable' => true, + 'sortable' => true, + 'width' => '100px', ]); } - public function render($pagination = true) - { - return $this->createOrderInvoicesDataGrid()->render($pagination); + public function prepareActions() { + $this->addAction([ + 'type' => 'View', + 'route' => 'admin.sales.invoices.view', + 'icon' => 'icon eye-icon' + ]); + } + + public function prepareMassActions() { + // $this->addMassAction([ + // 'type' => 'delete', + // 'action' => route('admin.catalog.attributes.massdelete'), + // 'method' => 'DELETE' + // ]); } } \ No newline at end of file diff --git a/packages/Webkul/Admin/src/DataGrids/OrderShipmentsDataGrid.php b/packages/Webkul/Admin/src/DataGrids/OrderShipmentsDataGrid.php index c6e6f3e54..46d26af23 100755 --- a/packages/Webkul/Admin/src/DataGrids/OrderShipmentsDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/OrderShipmentsDataGrid.php @@ -2,154 +2,116 @@ namespace Webkul\Admin\DataGrids; -use Illuminate\View\View; -use Webkul\Ui\DataGrid\Facades\DataGrid; +use Webkul\Ui\DataGrid\AbsGrid; use DB; /** - * OrderShipmentsDataGrid + * Product Data Grid class * - * @author Prashant Singh @prashant-webkul + * @author Prashant Singh @prashant-webkul * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class OrderShipmentsDataGrid +class OrderShipmentsDataGrid extends AbsGrid { + public $allColumns = []; - /** - * The Order Shipments Data Grid implementation for shipments of orders - */ - public function createOrderShipmentsDataGrid() + public function prepareQueryBuilder() { - return DataGrid::make([ - 'name' => 'shipments', - 'table' => 'shipments as ship', - 'select' => 'ship.id', - 'perpage' => 10, - 'aliased' => true, + $queryBuilder = DB::table('shipments as ship')->select('ship.id', 'ship.order_id', 'ship.total_qty', 'is.name', 'ors.created_at as orderdate', 'ship.created_at')->addSelect(DB::raw('CONCAT(ors.customer_first_name, " ", ors.customer_last_name) as custname'))->leftJoin('orders as ors', 'ship.order_id', '=', 'ors.id')->leftJoin('inventory_sources as is', 'ship.inventory_source_id', '=', 'is.id'); - 'massoperations' =>[ - // [ - // 'route' => route('admin.datagrid.delete'), - // 'method' => 'DELETE', - // 'label' => 'Delete', - // 'type' => 'button', - // ], - ], + $this->setQueryBuilder($queryBuilder); + } - 'actions' => [ - [ - 'type' => 'View', - 'route' => 'admin.sales.shipments.view', - // 'confirm_text' => 'Do you really want to view this record?', - 'icon' => 'icon eye-icon', - 'icon-alt' => 'View' - ], - ], + public function setIndex() { + $this->index = 'id'; //the column that needs to be treated as index column + } - 'join' => [ - [ - 'join' => 'leftjoin', - 'table' => 'orders as ors', - 'primaryKey' => 'ship.order_id', - 'condition' => '=', - 'secondaryKey' => 'ors.id', - ], [ - 'join' => 'leftjoin', - 'table' => 'inventory_sources as is', - 'primaryKey' => 'ship.inventory_source_id', - 'condition' => '=', - 'secondaryKey' => 'is.id', - ] - ], + public function addColumns() + { + $this->addColumn([ + 'index' => 'ship.id', + 'alias' => 'shipId', + 'label' => 'ID', + 'type' => 'number', + 'searchable' => false, + 'sortable' => true, + 'width' => '40px' + ]); - //use aliasing on secodary columns if join is performed - 'columns' => [ - [ - 'name' => 'ship.id', - 'alias' => 'shipID', - 'type' => 'number', - 'label' => 'ID', - 'sortable' => true - ], [ - 'name' => 'ship.order_id', - 'alias' => 'orderid', - 'type' => 'number', - 'label' => 'Order ID', - 'sortable' => true - ], [ - 'name' => 'ship.total_qty', - 'alias' => 'shiptotalqty', - 'type' => 'number', - 'label' => 'Total Quantity', - 'sortable' => true - ], [ - 'name' => 'CONCAT(ors.customer_first_name, " ", ors.customer_last_name)', - 'alias' => 'ordercustomerfirstname', - 'type' => 'string', - 'label' => 'Customer Name', - 'sortable' => false, - ], [ - 'name' => 'is.name', - 'alias' => 'inventorySourceName', - 'type' => 'string', - 'label' => 'Inventory Source', - 'sortable' => true - ], [ - 'name' => 'ors.created_at', - 'alias' => 'orscreated', - 'type' => 'date', - 'label' => 'Order Date', - 'sortable' => true - ], [ - 'name' => 'ship.created_at', - 'alias' => 'shipdate', - 'type' => 'datetime', - 'label' => 'Shipment Date', - 'sortable' => true - ] - ], + $this->addColumn([ + 'index' => 'ship.order_id', + 'alias' => 'orderId', + 'label' => 'Order ID', + 'type' => 'number', + 'searchable' => false, + 'sortable' => true, + 'width' => '100px' + ]); - 'filterable' => [ - [ - 'column' => 'ship.id', - 'alias' => 'shipID', - 'type' => 'number', - 'label' => 'ID', - ], [ - 'column' => 'ship.created_at', - 'alias' => 'shipdate', - 'type' => 'datetime', - 'label' => 'Shipment Date', - ] - ], - //don't use aliasing in case of searchables + $this->addColumn([ + 'index' => 'ship.total_qty', + 'alias' => 'shipTotalQty', + 'label' => 'Total Qty', + 'type' => 'number', + 'searchable' => true, + 'sortable' => true, + 'width' => '100px', + ]); - 'searchable' => [ - // [ - // 'column' => 'ors.customer_first_name', - // 'alias' => 'ordercustomerfirstname', - // 'type' => 'string', - // ] - ], + $this->addColumn([ + 'index' => 'is.name', + 'alias' => 'shipInventoryName', + 'label' => 'Inventory Source', + 'type' => 'string', + 'searchable' => true, + 'sortable' => true, + 'width' => '100px', + ]); - //list of viable operators that will be used - 'operators' => [ - 'eq' => "=", - 'lt' => "<", - 'gt' => ">", - 'lte' => "<=", - 'gte' => ">=", - 'neqs' => "<>", - 'neqn' => "!=", - 'like' => "like", - 'nlike' => "not like", - ], - // 'css' => [] + $this->addColumn([ + 'index' => 'orderdate', + 'alias' => 'shipOrderDate', + 'label' => 'Order Date', + 'type' => 'datetime', + 'sortable' => true, + 'searchable' => true, + 'width' => '100px' + ]); + + $this->addColumn([ + 'index' => 'ship.created_at', + 'alias' => 'shipDate', + 'label' => 'Shipment Date', + 'type' => 'datetime', + 'sortable' => true, + 'searchable' => false, + 'width' => '100px' + ]); + + $this->addColumn([ + 'index' => 'custname', + 'alias' => 'shipTO', + 'label' => 'Shipping To', + 'type' => 'string', + 'sortable' => true, + 'searchable' => false, + 'width' => '100px' ]); } - public function render($pagination = true) - { - return $this->createOrderShipmentsDataGrid()->render($pagination); + public function prepareActions() { + $this->addAction([ + 'type' => 'View', + 'route' => 'admin.sales.orders.view', + 'icon' => 'icon eye-icon' + ]); + } + + public function prepareMassActions() { + // $this->addMassAction([ + // 'type' => 'delete', + // 'action' => route('admin.catalog.attributes.massdelete'), + // 'method' => 'DELETE' + // ]); } } \ No newline at end of file diff --git a/packages/Webkul/Admin/src/DataGrids/TestDataGrid.php b/packages/Webkul/Admin/src/DataGrids/TestDataGrid.php index 707ebea0b..441d3c646 100644 --- a/packages/Webkul/Admin/src/DataGrids/TestDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/TestDataGrid.php @@ -79,7 +79,13 @@ class TestDataGrid extends AbsGrid 'type' => 'boolean', 'sortable' => true, 'searchable' => false, - 'width' => '100px' + 'width' => '100px', + 'wrapper' => function($value) { + if($value == 1) + return 'Active'; + else + return 'Inactive'; + } ]); $this->addColumn([ @@ -89,11 +95,13 @@ class TestDataGrid extends AbsGrid 'type' => 'number', 'sortable' => true, 'searchable' => false, - 'width' => '100px' + 'width' => '100px', + 'wrapper' => function($value) { + return core()->formatBasePrice($value); + } ]); $this->addColumn([ - // 'column' => 'products_grid.quantity', 'index' => 'products_grid.quantity', 'alias' => 'productqty', 'label' => 'Quantity', diff --git a/packages/Webkul/Admin/src/DataGrids/UserDataGrid.php b/packages/Webkul/Admin/src/DataGrids/UserDataGrid.php index ff29b2554..fe40caafd 100755 --- a/packages/Webkul/Admin/src/DataGrids/UserDataGrid.php +++ b/packages/Webkul/Admin/src/DataGrids/UserDataGrid.php @@ -57,10 +57,10 @@ class UserDataGrid extends AbsGrid 'sortable' => true, 'width' => '100px', 'wrapper' => function($value) { - if($value == 0) { - return false; + if($value == 1) { + return 'Active'; } else { - return true; + return 'Inactive'; } } ]); diff --git a/packages/Webkul/Admin/src/Resources/views/sales/invoices/index.blade.php b/packages/Webkul/Admin/src/Resources/views/sales/invoices/index.blade.php index be6610721..b85fb7296 100755 --- a/packages/Webkul/Admin/src/Resources/views/sales/invoices/index.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/sales/invoices/index.blade.php @@ -11,14 +11,14 @@

{{ __('admin::app.sales.invoices.title') }}

-
+ {{--
{{ __('admin::app.export.export') }}
-
+
--}}
@@ -27,18 +27,18 @@
- + {{--

{{ __('admin::app.export.download') }}

-
+
--}} @stop @push('scripts') - + --}} @endpush \ No newline at end of file diff --git a/packages/Webkul/Admin/src/Resources/views/sales/orders/index.blade.php b/packages/Webkul/Admin/src/Resources/views/sales/orders/index.blade.php index c023f8293..149b1eeff 100755 --- a/packages/Webkul/Admin/src/Resources/views/sales/orders/index.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/sales/orders/index.blade.php @@ -11,14 +11,14 @@

{{ __('admin::app.sales.orders.title') }}

-
+ {{--
{{ __('admin::app.export.export') }}
-
+
--}}
@@ -27,18 +27,18 @@
- + {{--

{{ __('admin::app.export.download') }}

-
+
--}} @stop @push('scripts') - + --}} + --}} @endpush \ No newline at end of file diff --git a/packages/Webkul/Product/src/Helpers/Toolbar.php b/packages/Webkul/Product/src/Helpers/Toolbar.php index b1c72dbf5..80d45dfcd 100755 --- a/packages/Webkul/Product/src/Helpers/Toolbar.php +++ b/packages/Webkul/Product/src/Helpers/Toolbar.php @@ -18,7 +18,7 @@ class Toolbar extends AbstractProduct 'created_at-desc' => 'newest-first', 'created_at-asc' => 'oldest-first', 'price-asc' => 'cheapest-first', - 'price-desc' => 'expansive-first' + 'price-desc' => 'expensive-first' ]; } /** diff --git a/packages/Webkul/Ui/src/Resources/views/testgrid/body.blade.php b/packages/Webkul/Ui/src/Resources/views/testgrid/body.blade.php index 8883e7850..b58078251 100644 --- a/packages/Webkul/Ui/src/Resources/views/testgrid/body.blade.php +++ b/packages/Webkul/Ui/src/Resources/views/testgrid/body.blade.php @@ -8,24 +8,23 @@ - - @foreach($record as $key1 => $column) - @if($columns[$i]['type'] == 'boolean' && $columns[$i]['label'] == 'Status') - @if($column == 0) - Inactive + + @foreach($columns as $column) + @php + $index = explode('.', $column['index']); + + $index = end($index); + @endphp + + @if(isset($column['wrapper'])) + @if(isset($column['closure']) && $column['closure'] == true) + {!! $column['wrapper']($record->{$index}) !!} @else - Active - @endif - @elseif($columns[$i]['type'] == 'boolean' && $columns[$i]['label'] != 'Status') - @if($column == 0) - False - @else - True + {{ $column['wrapper']($record->{$index}) }} @endif @else - {{ $column }} + {{ $record->{$index} }} @endif - @endforeach