Skip to content

Commit

Permalink
Changelog:
Browse files Browse the repository at this point in the history
- Fixed: layout issue with the permissions
- Added: new permissions to control the pos features
- Added: new filter
  • Loading branch information
Blair2004 committed Aug 6, 2021
1 parent 29dfc55 commit d6b9c3d
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function up()
include_once( dirname( __FILE__ ) . '/../../permissions/taxes.php' );
include_once( dirname( __FILE__ ) . '/../../permissions/reports.php' );
include_once( dirname( __FILE__ ) . '/../../permissions/payments-types.php' );
include_once( dirname( __FILE__ ) . '/../../permissions/pos.php' );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function up()
$admin->addPermissions( Permission::includes( '.trucks' )->get()->map( fn( $permission ) => $permission->namespace ) );
$admin->addPermissions( Permission::includes( '.units' )->get()->map( fn( $permission ) => $permission->namespace ) );
$admin->addPermissions( Permission::includes( '.manage-payments-types' )->get()->map( fn( $permission ) => $permission->namespace ) );
$admin->addPermissions( Permission::includes( '.pos' )->get()->map( fn( $permission ) => $permission->namespace ) );

/**
* store administrator role
Expand Down Expand Up @@ -119,6 +120,7 @@ public function up()
$storeAdmin->addPermissions( Permission::includes( '.trucks' )->get()->map( fn( $permission ) => $permission->namespace ) );
$storeAdmin->addPermissions( Permission::includes( '.units' )->get()->map( fn( $permission ) => $permission->namespace ) );
$storeAdmin->addPermissions( Permission::includes( '.manage-payments-types' )->get()->map( fn( $permission ) => $permission->namespace ) );
$storeAdmin->addPermissions( Permission::includes( '.pos' )->get()->map( fn( $permission ) => $permission->namespace ) );


/**
Expand All @@ -132,6 +134,7 @@ public function up()
$storeCashier->save();
$storeCashier->addPermissions([ 'read.dashboard' ]);
$storeCashier->addPermissions( Permission::includes( '.profile' )->get()->map( fn( $permission ) => $permission->namespace ) );
$storeCashier->addPermissions( Permission::includes( '.pos' )->get()->map( fn( $permission ) => $permission->namespace ) );
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

use App\Models\Permission;
use App\Models\Role;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class UpdateAddNewPermissionsAug5 extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
include( dirname( __FILE__ ) . '/../../permissions/pos.php' );

Role::namespace( 'admin' )
->addPermissions( Permission::includes( '.pos' )
->get()->map( fn( $permission ) => $permission->namespace ) );

Role::namespace( 'nexopos.store.administrator' )
->addPermissions( Permission::includes( '.pos' )
->get()->map( fn( $permission ) => $permission->namespace ) );

Role::namespace( 'nexopos.store.cashier' )
->addPermissions( Permission::includes( '.pos' )
->get()->map( fn( $permission ) => $permission->namespace ) );
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
35 changes: 35 additions & 0 deletions database/permissions/pos.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use App\Models\Permission;

if ( ! Permission::namespace( 'nexopos.pos.edit-purchase-price' ) instanceof Permission ) {
$pos = new Permission();
$pos->name = __( 'Edit Purchase Price' );
$pos->namespace = 'nexopos.pos.edit-purchase-price';
$pos->description = __( 'Let the user edit the purchase price of products.' );
$pos->save();
}

if ( ! Permission::namespace( 'nexopos.pos.edit-settings' ) instanceof Permission ) {
$pos = new Permission();
$pos->name = __( 'Edit Order Settings' );
$pos->namespace = 'nexopos.pos.edit-settings';
$pos->description = __( 'Let the user edit the order settings.' );
$pos->save();
}

if ( ! Permission::namespace( 'nexopos.pos.products-discount' ) instanceof Permission ) {
$pos = new Permission();
$pos->name = __( 'Edit Product Discounts' );
$pos->namespace = 'nexopos.pos.products-discount';
$pos->description = __( 'Let the user add discount on products.' );
$pos->save();
}

if ( ! Permission::namespace( 'nexopos.pos.cart-discount' ) instanceof Permission ) {
$pos = new Permission();
$pos->name = __( 'Edit Cart Discounts' );
$pos->namespace = 'nexopos.pos.cart-discount';
$pos->description = __( 'Let the user add discount on cart.' );
$pos->save();
}
3 changes: 2 additions & 1 deletion resources/ts/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Popup } from "./libraries/popup";
import Vue from "vue";
import FormValidation from "./libraries/form-validation";
import Url from "./libraries/url";
import { nsCurrency, nsAbbreviate, nsRawCurrency } from "./filters/declarations";
import { nsCurrency, nsAbbreviate, nsRawCurrency, nsTruncate } from "./filters/declarations";
import CrudHandler from "./libraries/crud-handler";
import { createHooks } from '@wordpress/hooks';
import { __, __m } from "./libraries/lang";
Expand Down Expand Up @@ -127,6 +127,7 @@ nsHttpClient.defineClient( Axios );
( window as any ).nsHttpClient = nsHttpClient;
( window as any ).nsSnackBar = nsSnackBar;
( window as any ).nsCurrency = nsCurrency;
( window as any ).nsTruncate = nsTruncate;
( window as any ).nsRawCurrency = nsRawCurrency;
( window as any ).nsAbbreviate = nsAbbreviate;
( window as any ).nsState = nsState;
Expand Down
3 changes: 2 additions & 1 deletion resources/ts/filters/declarations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { nsAbbreviate } from './abbreviate';
import { nsCurrency, nsRawCurrency } from './currency';
import { nsTruncate } from './truncate';

export { nsCurrency, nsAbbreviate, nsRawCurrency };
export { nsCurrency, nsAbbreviate, nsRawCurrency, nsTruncate };
18 changes: 18 additions & 0 deletions resources/ts/filters/truncate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Vue from 'vue';

const nsTruncate = Vue.filter('truncate', function (value, length) {
if ( !value ) {
return '';
}

value = value.toString();

if( value.length > length ){
return value.substring(0, length) + "..."
} else {
return value
}
})


export { nsTruncate };
26 changes: 22 additions & 4 deletions resources/ts/pages/dashboard/ns-permissions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@
<div id="permission-wrapper">
<div class="rounded shadow bg-white flex">
<div id="permissions" class="w- bg-gray-800 flex-shrink-0">
<div class="py-4 px-2 border-b border-gray-700 text-gray-100">{{ __( 'Permissions' ) }}</div>
<div :key="permission.id" v-for="permission of permissions" class="p-2 border-b border-gray-700 text-gray-100">
<a href="javascript:void(0)" :title="permission.namespace">{{ permission.name }}</a>
<div class="py-4 px-2 border-b border-gray-700 text-gray-100 flex justify-between items-center">
<span v-if="! toggled">{{ __( 'Permissions' ) }}</span>
<div>
<button @click="toggled = ! toggled" class="rounded-full bg-white text-gray-700 h-6 w-6 flex items-center justify-center" v-if="! toggled">
<i class="las la-expand"></i>
</button>
<button @click="toggled = ! toggled" class="rounded-full bg-white text-gray-700 h-6 w-6 flex items-center justify-center" v-if="toggled">
<i class="las la-compress"></i>
</button>
</div>
</div>
<div :key="permission.id" v-for="permission of permissions" :class="toggled ? 'w-24' : 'w-54'" class="p-2 border-b border-gray-700 text-gray-100">
<a href="javascript:void(0)" :title="permission.namespace">
<span v-if="! toggled">{{ permission.name }}</span>
<span v-if="toggled">{{ permission.name | truncate(5) }}</span>
</a>
</div>
</div>
<div class="flex flex-auto overflow-hidden">
<div class="overflow-y-auto">
<div class="text-gray-700 flex">
<div v-for="role of roles" :key="role.id" class="py-4 px-2 items-center border-b justify-center flex role w-56 flex-shrink-0 border-r border-gray-200">
<div v-for="role of roles" :key="role.id" class="py-4 px-2 w-56 items-center border-b justify-center flex role flex-shrink-0 border-r border-gray-200">
<p class="mx-1"><span>{{ role.name }}</span></p>
<span class="mx-1"><ns-checkbox @change="selectAllPermissions( role )" :field="role.field"></ns-checkbox></span>
</div>
Expand All @@ -26,14 +39,19 @@
</div>
</template>
<script>
import { nsTruncate } from '@/filters/truncate';
import { forkJoin } from "rxjs";
import { nsHttpClient, nsSnackBar } from "../../bootstrap";
import { __ } from '@/libraries/lang';
export default {
name: 'ns-permissions',
filters: [
nsTruncate,
],
data() {
return {
permissions: [],
toggled: false,
roles: [],
}
},
Expand Down
16 changes: 16 additions & 0 deletions resources/ts/pages/dashboard/pos/ns-pos-cart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ export default {
switchTo,
async changeProductPrice( product ) {
if ( ! this.settings.edit_purchase_price ) {
return nsSnackBar.error( __( `You don't have the right to edit the purchase price.` ) ).subscribe();
}
if ( this.settings.unit_price_editable ) {
try {
product.unit_price = await new Promise( ( resolve, reject ) => {
Expand Down Expand Up @@ -343,6 +347,10 @@ export default {
},
async defineOrderSettings() {
if ( ! this.settings.edit_settings ) {
return nsSnackBar.error( __( 'You\'re not allowed to edit the order settings.' ) ).subscribe();
}
try {
const response = await new Promise( ( resolve, reject) => {
Popup.show( nsPosOrderSettingsVue, { resolve, reject, order : this.order });
Expand Down Expand Up @@ -458,6 +466,14 @@ export default {
},
openDiscountPopup( reference, type ) {
if ( ! this.settings.products_discount && type === 'product' ) {
return nsSnackBar.error( `You're not allowed to add a discount on the product.` ).subscribe();
}
if ( ! this.settings.cart_discount && type === 'cart' ) {
return nsSnackBar.error( `You're not allowed to add a discount on the cart.` ).subscribe();
}
Popup.show( nsPosDiscountPopupVue, {
reference,
type,
Expand Down
22 changes: 15 additions & 7 deletions resources/views/pages/dashboard/orders/pos.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@
@parent
<script src="{{ asset( 'js/pos-init.js' ) }}"></script>
<script>
POS.defineTypes( <?php echo json_encode( $orderTypes );?>);
POS.defineTypes( <?php
use App\Models\User;
echo json_encode( $orderTypes );?>);
POS.defineOptions( <?php echo json_encode( $options );?>);
POS.defineSettings({
barcode_search : true,
text_search : false,
breadcrumb : [],
products_queue : [],
unit_price_editable : <?php echo ns()->option->get( 'ns_pos_unit_price_ediable', 'yes' ) === 'yes' ? 'true' : 'false';?>,
urls : <?php echo json_encode( $urls );?>
barcode_search : true,
text_search : false,
edit_purchase_price : <?php echo User::allowedTo( 'nexopos.pos.edit-purchase-price' ) ? 'true' : 'false';?>,
edit_settings : <?php echo User::allowedTo( 'nexopos.pos.edit-settings' ) ? 'true' : 'false';?>,
products_discount : <?php echo User::allowedTo( 'nexopos.pos.products-discount' ) ? 'true' : 'false';?>,
cart_discount : <?php echo User::allowedTo( 'nexopos.pos.cart-discount' ) ? 'true' : 'false';?>,
breadcrumb : [],
products_queue : [],
unit_price_editable : <?php echo ns()->option->get( 'ns_pos_unit_price_ediable', 'yes' ) === 'yes' ? 'true' : 'false';?>,
urls : <?php echo json_encode( $urls );?>
});
POS.definedPaymentsType( <?php echo json_encode( $paymentTypes );?> );
Expand Down

0 comments on commit d6b9c3d

Please sign in to comment.