From 49ee40d89dc3217265022ee294e0a4c0895d722d Mon Sep 17 00:00:00 2001 From: Blair2004 Date: Sat, 31 Jul 2021 10:36:08 +0100 Subject: [PATCH 01/11] - fix #227 - Removed: console log --- resources/ts/filters/currency.ts | 1 - resources/ts/popups/ns-pos-customer-select-popup.vue | 9 +++++++++ resources/ts/popups/ns-pos-customers.vue | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/resources/ts/filters/currency.ts b/resources/ts/filters/currency.ts index a486a9a88..096716771 100755 --- a/resources/ts/filters/currency.ts +++ b/resources/ts/filters/currency.ts @@ -8,7 +8,6 @@ declare const window; const precision = ( new Array( parseInt( ns.currency.ns_currency_precision ) ) ).fill('').map( _ => 0 ).join(''); const nsCurrency = Vue.filter( 'currency', ( value, format = 'full', locale = 'en' ) => { - console.log( format ); let numeralFormat, currencySymbol; switch( ns.currency.ns_currency_prefered ) { diff --git a/resources/ts/popups/ns-pos-customer-select-popup.vue b/resources/ts/popups/ns-pos-customer-select-popup.vue index b62650430..2acc6e1f8 100755 --- a/resources/ts/popups/ns-pos-customer-select-popup.vue +++ b/resources/ts/popups/ns-pos-customer-select-popup.vue @@ -27,6 +27,9 @@
  • {{ __( 'No customer match your query...' ) }}
  • +
  • + {{ __( 'Create a customer' ) }} +
  • {{ customer.name }}

    @@ -142,6 +145,12 @@ export default { this.customers = customers; }) }, + + createCustomerWithMatch( value ) { + this.resolveIfQueued(false) + Popup.show( nsPosCustomersVue, { name: value }) + }, + getRecentCustomers() { this.isLoading = true; diff --git a/resources/ts/popups/ns-pos-customers.vue b/resources/ts/popups/ns-pos-customers.vue index 6b2ff5240..09d99150a 100755 --- a/resources/ts/popups/ns-pos-customers.vue +++ b/resources/ts/popups/ns-pos-customers.vue @@ -10,6 +10,7 @@ @@ -136,6 +137,10 @@ export default { this.activeTab = 'account-payment'; this.customer = this.$popupParams.customer; this.loadCustomerOrders( this.customer.id ); + } else if ( this.$popupParams.name !== undefined ) { + setTimeout( () => { + + }, 100 ); } } }); @@ -149,6 +154,12 @@ export default { return [ 'unpaid', 'partially_paid', 'hold' ].includes( order.payment_status ); }, + prefillForm( event ) { + if ( this.$popupParams.name !== undefined ) { + event.main.value = this.$popupParams.name; + } + }, + openCustomerSelection() { this.$popup.close(); Popup.show( nsPosCustomerSelectPopupVue ); From 51d0568d15bf52720b9a19f405c6e5dfa4e83a7b Mon Sep 17 00:00:00 2001 From: Blair2004 Date: Sat, 31 Jul 2021 16:25:15 +0100 Subject: [PATCH 02/11] - fix #228 --- .../Dashboard/CashRegistersController.php | 7 ++- .../CashRegisterEventsSubscriber.php | 2 + app/Services/CashRegistersService.php | 49 +++++++++++++++++++ ..._000000_create_registers_history_table.php | 2 +- ...update_nexopos_registers_history_jul31.php | 30 ++++++++++++ .../ns-pos-registers-button.vue | 16 +++++- .../ns-pos-cash-registers-action-popup.vue | 4 +- .../ns-pos-cash-registers-options-popup.vue | 23 ++++++++- resources/ts/popups/ns-pos-units.vue | 1 - resources/ts/pos-init.ts | 37 +++++++------- tests/Feature/CreateOrderOnRegister.php | 22 +++++++++ .../Feature/OpenAndCloseCashRegisterTest.php | 22 +++++++++ 12 files changed, 190 insertions(+), 25 deletions(-) create mode 100644 database/migrations/schema-updates/2021_07_31_100843_update_nexopos_registers_history_jul31.php create mode 100644 tests/Feature/CreateOrderOnRegister.php create mode 100644 tests/Feature/OpenAndCloseCashRegisterTest.php diff --git a/app/Http/Controllers/Dashboard/CashRegistersController.php b/app/Http/Controllers/Dashboard/CashRegistersController.php index 97a1efa6a..ce3d4d67b 100755 --- a/app/Http/Controllers/Dashboard/CashRegistersController.php +++ b/app/Http/Controllers/Dashboard/CashRegistersController.php @@ -12,6 +12,7 @@ use App\Exceptions\NotAllowedException; use App\Exceptions\NotFoundException; use App\Http\Controllers\DashboardController; +use App\Models\Order; use Illuminate\Http\Request; use App\Models\ProductCategory; use App\Models\Register; @@ -58,11 +59,13 @@ public function editRegister( Register $register ) public function getRegisters( $register_id = null ) { if ( $register_id !== null ) { - return Register::findOrFail( $register_id ); + $register = Register::findOrFail( $register_id ); + $this->registersService->getRegisterDetails( $register ); + return $register; } return Register::get()->map( function( $register ) { - $register->status_label = $this->registersService->getRegisterStatusLabel( $register->status ); + $this->registersService->getRegisterDetails( $register ); return $register; }); } diff --git a/app/Listeners/CashRegisterEventsSubscriber.php b/app/Listeners/CashRegisterEventsSubscriber.php index 55cf94d2b..829e40b5e 100755 --- a/app/Listeners/CashRegisterEventsSubscriber.php +++ b/app/Listeners/CashRegisterEventsSubscriber.php @@ -3,7 +3,9 @@ namespace App\Listeners; use App\Events\CashRegisterHistoryAfterCreatedEvent; +use App\Events\OrderAfterCreatedEvent; use App\Events\OrderAfterPaymentCreatedEvent; +use App\Events\OrderAfterUpdatedEvent; use App\Services\CashRegistersService; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; diff --git a/app/Services/CashRegistersService.php b/app/Services/CashRegistersService.php index d0ca8f220..94fcd6f71 100755 --- a/app/Services/CashRegistersService.php +++ b/app/Services/CashRegistersService.php @@ -2,9 +2,12 @@ namespace App\Services; use App\Events\CashRegisterHistoryAfterCreatedEvent; +use App\Events\OrderAfterCreatedEvent; use App\Events\OrderAfterPaymentCreatedEvent; +use App\Events\OrderAfterUpdatedEvent; use App\Events\OrderRefundPaymentAfterCreatedEvent; use App\Exceptions\NotAllowedException; +use App\Models\Order; use App\Models\Register; use App\Models\RegisterHistory; use Exception; @@ -229,6 +232,11 @@ public function getActionLabel( $label ) } } + /** + * Returns the register status for human + * @param string $label + * @return string + */ public function getRegisterStatusLabel( $label ) { switch( $label ) { @@ -249,4 +257,45 @@ public function getRegisterStatusLabel( $label ) break; } } + + /** + * Update the register with various details + * @param Register $register + * @return void + */ + public function getRegisterDetails( Register $register ) + { + $register->status_label = $this->getRegisterStatusLabel( $register->status ); + $register->opening_balance = 0; + $register->total_sale_amount = 0; + + if ( $register->status === Register::STATUS_OPENED ) { + $history = $register->history() + ->where( 'action', RegisterHistory::ACTION_OPENING ) + ->orderBy( 'id', 'desc' )->first(); + $register->opening_balance = $history->value; + $register->total_sale_amount = Order::paid() + ->where( 'register_id', $register->id ) + ->sum( 'total' ); + } + + return $register; + } + + /** + * Will save the order total amount to the + * register every time the order is completely paid. + * @param OrderAfterCreatedEvent|OrderAfterUpdatedEvent $event + * @return void + */ + public function recordPaidOrderAmount( $event ) + { + if ( $event->order->payment_status === Order::PAYMENT_PAID ) { + $register = Register::find( $event->order->register_id ); + + if ( $register instanceof Register ) { + $this->cashIn( $register, $event->order->total, __( 'Automatically recorded sale payment.' ) ); + } + } + } } \ No newline at end of file diff --git a/database/migrations/create-tables/2020_06_20_000000_create_registers_history_table.php b/database/migrations/create-tables/2020_06_20_000000_create_registers_history_table.php index ea41bcfbb..c6e254152 100755 --- a/database/migrations/create-tables/2020_06_20_000000_create_registers_history_table.php +++ b/database/migrations/create-tables/2020_06_20_000000_create_registers_history_table.php @@ -24,7 +24,7 @@ public function up() $table->integer( 'register_id' ); $table->string( 'action' ); $table->integer( 'author' ); - $table->float( 'value', 11, 5 ); + $table->float( 'value', 11, 5 )->default(0); $table->text( 'description' )->nullable(); $table->string( 'uuid' )->nullable(); $table->timestamps(); diff --git a/database/migrations/schema-updates/2021_07_31_100843_update_nexopos_registers_history_jul31.php b/database/migrations/schema-updates/2021_07_31_100843_update_nexopos_registers_history_jul31.php new file mode 100644 index 000000000..3e417b5dd --- /dev/null +++ b/database/migrations/schema-updates/2021_07_31_100843_update_nexopos_registers_history_jul31.php @@ -0,0 +1,30 @@ +float( 'value' )->default(0)->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/resources/ts/pages/dashboard/pos/header-buttons/ns-pos-registers-button.vue b/resources/ts/pages/dashboard/pos/header-buttons/ns-pos-registers-button.vue index 1fe46aabc..07cf2b9dd 100755 --- a/resources/ts/pages/dashboard/pos/header-buttons/ns-pos-registers-button.vue +++ b/resources/ts/pages/dashboard/pos/header-buttons/ns-pos-registers-button.vue @@ -56,6 +56,7 @@ export default { * throughout the orders send to the server */ POS.set( 'register', response.data.register ); + this.setRegister( response.data.register ); return response; } catch( exception ) { @@ -69,6 +70,17 @@ export default { } this.name = __( `Cash Register : {register}` ).replace( '{register}', this.settings.register.name ); + }, + setRegister( register ) { + if ( register !== undefined ) { + /** + * This will update the register ID once we've + * successfully loaded the opened cash register + */ + const order = POS.order.getValue(); + order.register_id = register.id; + POS.order.next( order ); + } } }, destroyed() { @@ -83,7 +95,9 @@ export default { }); this.settingsSubscriber = POS.settings.subscribe( settings => { - this.settings = settings; + this.settings = settings; + + this.setRegister( this.settings.register ); this.setButtonName(); }); diff --git a/resources/ts/popups/ns-pos-cash-registers-action-popup.vue b/resources/ts/popups/ns-pos-cash-registers-action-popup.vue index 4f79b2868..56676bdfd 100755 --- a/resources/ts/popups/ns-pos-cash-registers-action-popup.vue +++ b/resources/ts/popups/ns-pos-cash-registers-action-popup.vue @@ -15,7 +15,7 @@ {{ amount | currency }}

    - +
    @@ -97,7 +97,7 @@ export default { }, triggerSubmit() { const fields = this.validation.extractFields( this.fields ); - fields.amount = this.amount; + fields.amount = this.amount === '' ? 0 : this.amount; nsHttpClient.post( `/api/nexopos/v4/cash-registers/${this.action}/${this.register_id || this.settings.register.id}`, fields ) .subscribe( result => { diff --git a/resources/ts/popups/ns-pos-cash-registers-options-popup.vue b/resources/ts/popups/ns-pos-cash-registers-options-popup.vue index ffdfc9451..b6424106b 100755 --- a/resources/ts/popups/ns-pos-cash-registers-options-popup.vue +++ b/resources/ts/popups/ns-pos-cash-registers-options-popup.vue @@ -6,16 +6,20 @@ import popupResolver from '@/libraries/popup-resolver'; import { __ } from '@/libraries/lang'; export default { mounted() { + // destroy observable this.settingsSubscriber = POS.settings.subscribe( settings => { this.settings = settings; }); this.popupCloser(); + + this.loadRegisterSummary(); }, data() { return { settings: null, settingsSubscriber: null, + register: {} } }, methods: { @@ -25,6 +29,13 @@ export default { popupCloser, + loadRegisterSummary() { + nsHttpClient.get( `/api/nexopos/v4/cash-registers/${this.settings.register.id}` ) + .subscribe( result => { + this.register = result; + }) + }, + closePopup() { this.popupResolver({ status: 'failed', @@ -122,13 +133,23 @@ export default { }