Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Blair2004 committed Jul 8, 2021
1 parent 8440ff4 commit e8c0c3b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/Crud/OrderInstalmentCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ],
];

/**
Expand Down Expand Up @@ -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}' . '' ),
Expand Down
3 changes: 2 additions & 1 deletion app/Crud/RolesCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? '',
Expand Down
18 changes: 9 additions & 9 deletions app/Services/ReportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -632,16 +633,14 @@ 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' ),
])
->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' )
Expand All @@ -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;
Expand All @@ -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' ] )
Expand Down
14 changes: 10 additions & 4 deletions resources/ts/pages/dashboard/products/ns-stock-adjustment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions resources/views/layout/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<body>
<div class="h-full w-full flex flex-col">
<div id="dashboard-body" class="overflow-hidden flex flex-auto">
<div id="dashboard-aside" v-cloak v-if="sidebar === 'visible'" class="w-64 z-10 absolute md:static flex-shrink-0 bg-gray-900 h-full flex-col overflow-hidden">
<div id="dashboard-aside" v-cloak v-if="sidebar === 'visible'" class="w-64 z-50 absolute md:static flex-shrink-0 bg-gray-900 h-full flex-col overflow-hidden">
<div class="overflow-y-auto h-full text-sm">
<div class="logo py-4 flex justify-center items-center">
@if ( ns()->option->get( 'ns_store_rectangle_logo' ) )
Expand All @@ -77,7 +77,7 @@
</ul>
</div>
</div>
<div id="dashboard-overlay" v-if="sidebar === 'visible'" @click="closeMenu()" class="w-full h-full md:hidden absolute" style="background: rgb(51 51 51 / 25%)"></div>
<div id="dashboard-overlay" v-if="sidebar === 'visible'" @click="closeMenu()" class="z-40 w-full h-full md:hidden absolute" style="background: rgb(51 51 51 / 25%)"></div>
<div class="flex flex-auto overflow-hidden bg-gray-200">
<div class="overflow-y-auto flex-auto">
@yield( 'layout.dashboard.body', View::make( 'common.dashboard.with-header' ) )
Expand Down

0 comments on commit e8c0c3b

Please sign in to comment.