From e8c0c3b887eae6d333e73f756cc4e22e1c7fc48d Mon Sep 17 00:00:00 2001 From: Blair2004 Date: Thu, 8 Jul 2021 19:09:31 +0100 Subject: [PATCH] Update - Fixed : Instalment crud list using a wrong pivot attribute - Fixed : Stock adjustment issue (adding stock) fixes #207 - Fixes #208 - Fixed : unable to load the product reports. - Fixed : some adjustment on the products reports. --- app/Crud/OrderInstalmentCrud.php | 4 ++-- app/Crud/RolesCrud.php | 3 ++- app/Services/ReportService.php | 18 +++++++++--------- .../dashboard/products/ns-stock-adjustment.vue | 14 ++++++++++---- .../reports/ns-best-products-report.vue | 2 +- resources/views/layout/dashboard.blade.php | 4 ++-- 6 files changed, 26 insertions(+), 19 deletions(-) diff --git a/app/Crud/OrderInstalmentCrud.php b/app/Crud/OrderInstalmentCrud.php index 3509dc45a..d8eed4392 100644 --- a/app/Crud/OrderInstalmentCrud.php +++ b/app/Crud/OrderInstalmentCrud.php @@ -55,7 +55,7 @@ class OrderInstalmentCrud extends CrudService */ public $relations = [ [ 'nexopos_orders as order', 'order.id', '=', 'nexopos_orders_instalments.order_id' ], - [ 'nexopos_customers as customer', 'customer.id', '=', 'order.id' ], + [ 'nexopos_customers as customer', 'customer.id', '=', 'order.customer_id' ], ]; /** @@ -416,7 +416,7 @@ public function getLinks() { return [ 'list' => ns()->url( 'dashboard/' . 'orders/instalments' ), - 'create' => ns()->url( 'dashboard/' . 'orders/instalments/create' ), + 'create' => 'javascript:void(0)', 'edit' => ns()->url( 'dashboard/' . 'orders/instalments/edit/' ), 'post' => ns()->url( 'api/nexopos/v4/crud/' . 'ns.orders-instalments' ), 'put' => ns()->url( 'api/nexopos/v4/crud/' . 'ns.orders-instalments/{id}' . '' ), diff --git a/app/Crud/RolesCrud.php b/app/Crud/RolesCrud.php index 56cebeb53..2da35b05f 100755 --- a/app/Crud/RolesCrud.php +++ b/app/Crud/RolesCrud.php @@ -150,7 +150,8 @@ public function getForm( $entry = null ) 'validation' => 'required', 'options' => Helper::kvToJsOptions( Hook::filter( 'ns-dashboard-identifiers', [ 'store' => __( 'Store Dashboard' ), - 'cashier' => __( 'Cashier Dashboard' ) + 'cashier' => __( 'Cashier Dashboard' ), + 'default' => __( 'Default Dashboard' ), ])), 'description' => __( 'Define what should be the home page of the dashboard.' ), 'value' => $entry->dashid ?? '', diff --git a/app/Services/ReportService.php b/app/Services/ReportService.php index 46afa3d1b..6848cfdf7 100755 --- a/app/Services/ReportService.php +++ b/app/Services/ReportService.php @@ -560,10 +560,11 @@ private function getDiff( $old, $new ) { */ private function computeDiff( $old, $new, $operation ) { - if ( $operation === 'decrease' ) { - return ( ( $old - $new ) / $old ) * 100; + if ( $new == 0 ) { + return 100; } else { - return ( ( $new - $old ) / $old ) * 100; + $change = ( ( $old - $new ) / $new ) * 100; + return $operation === 'increase' ? abs( $change ) : $change; } } @@ -632,7 +633,6 @@ private function getBestRecords( $previousDates, $sort ) $orderProductTable . '.unit_name as unit_name', $orderProductTable . '.product_id as product_id', $orderProductTable . '.name as name', - $orderTable . '.created_at as created_at', DB::raw( 'SUM( quantity ) as quantity' ), DB::raw( 'SUM( total_price ) as total_price' ), DB::raw( 'SUM( ' . env( 'DB_PREFIX' ) . $orderProductTable . '.tax_value ) as tax_value' ), @@ -640,8 +640,7 @@ private function getBestRecords( $previousDates, $sort ) ->groupBy( $orderProductTable . '.unit_name', $orderProductTable . '.product_id', - $orderProductTable . '.name', - $orderTable . '.created_at', + $orderProductTable . '.name' ) ->orderBy( $sorting[ 'column' ], $sorting[ 'direction' ] ) ->join( $orderTable, $orderTable . '.id', '=', $orderProductTable . '.order_id' ) @@ -657,9 +656,10 @@ private function getBestRecords( $previousDates, $sort ) foreach( $previousDates[ 'current' ][ 'products' ] as $id => &$product ) { $default = new stdClass; $default->total_price = 0; + $default->quantity = 0; - $oldProduct = collect( $previousDates[ 'previous' ][ 'products' ] )->filter( function( $product ) use ( $id ) { - return $product->product_id === $id; + $oldProduct = collect( $previousDates[ 'previous' ][ 'products' ] )->filter( function( $previousProduct ) use ( $product ) { + return $previousProduct->product_id === $product->product_id; })->first() ?: $default; $product->old_total_price = $oldProduct->total_price; @@ -669,7 +669,7 @@ private function getBestRecords( $previousDates, $sort ) $product->total_price ) : 100; - $product->evolution = $product->total_price > $oldProduct->total_price ? 'progress' : 'regress'; + $product->evolution = $product->quantity > $oldProduct->quantity ? 'progress' : 'regress'; } $previousDates[ 'current' ][ 'total_price' ] = collect( $previousDates[ 'current' ][ 'products' ] ) diff --git a/resources/ts/pages/dashboard/products/ns-stock-adjustment.vue b/resources/ts/pages/dashboard/products/ns-stock-adjustment.vue index 5affa0ec2..51c5a2b54 100755 --- a/resources/ts/pages/dashboard/products/ns-stock-adjustment.vue +++ b/resources/ts/pages/dashboard/products/ns-stock-adjustment.vue @@ -133,10 +133,16 @@ export default { }); promise.then( result => { - if ( product.accurate_tracking !== undefined && result.quantity > product.available_quantity ) { - return nsSnackBar.error( __( 'The specified quantity exceed the available quantity.' ) ).subscribe(); - } else if ( result.quantity > product.adjust_unit.quantity ) { - return nsSnackBar.error( __( 'The specified quantity exceed the available quantity.' ) ).subscribe(); + /** + * will check the stock if the adjustment + * reduce the stock. + */ + if ( ! [ 'added' ].includes( product.adjust_action ) ) { + if ( product.accurate_tracking !== undefined && result.quantity > product.available_quantity ) { + return nsSnackBar.error( __( 'The specified quantity exceed the available quantity.' ) ).subscribe(); + } else if ( result.quantity > product.adjust_unit.quantity ) { + return nsSnackBar.error( __( 'The specified quantity exceed the available quantity.' ) ).subscribe(); + } } product.adjust_quantity = result.quantity; diff --git a/resources/ts/pages/dashboard/reports/ns-best-products-report.vue b/resources/ts/pages/dashboard/reports/ns-best-products-report.vue index a232f75af..97e92095f 100755 --- a/resources/ts/pages/dashboard/reports/ns-best-products-report.vue +++ b/resources/ts/pages/dashboard/reports/ns-best-products-report.vue @@ -41,7 +41,7 @@ export default { const startDate = moment( this.startDate ); const endDate = moment( this.endDate ); - nsHttpClient.post( '/api/nexopos/v4/reports/best-products', { + nsHttpClient.post( '/api/nexopos/v4/reports/products-report', { startDate : startDate.format( 'YYYY/MM/DD HH:mm' ), endDate : endDate.format( 'YYYY/MM/DD HH:mm' ), sort: this.sort diff --git a/resources/views/layout/dashboard.blade.php b/resources/views/layout/dashboard.blade.php index 181c996a1..c901ba7b8 100755 --- a/resources/views/layout/dashboard.blade.php +++ b/resources/views/layout/dashboard.blade.php @@ -51,7 +51,7 @@
-
+
-
+
@yield( 'layout.dashboard.body', View::make( 'common.dashboard.with-header' ) )