Skip to content

Commit

Permalink
Changelog
Browse files Browse the repository at this point in the history
- fix #313
- Added: capacity to edit customer coupon usage
- fix #317
  • Loading branch information
Blair2004 committed Sep 23, 2021
1 parent 2bfd421 commit d734fd1
Show file tree
Hide file tree
Showing 19 changed files with 326 additions and 64 deletions.
68 changes: 19 additions & 49 deletions app/Crud/CustomerCouponCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CustomerCouponCrud extends CrudService
* default slug
* @param string
*/
protected $slug = 'customers/coupons';
protected $slug = 'customers/coupons-generated';

/**
* Define namespace
Expand All @@ -43,9 +43,9 @@ class CustomerCouponCrud extends CrudService
*/
protected $permissions = [
'create' => false,
'read' => true,
'update' => false,
'delete' => false,
'read' => 'nexopos.read.coupons',
'update' => 'nexopos.update.coupons',
'delete' => 'nexopos.delete.coupons',
];

/**
Expand Down Expand Up @@ -151,60 +151,28 @@ public function getForm( $entry = null )
return [
'main' => [
'label' => __( 'Name' ),
// 'name' => 'name',
// 'value' => $entry->name ?? '',
'name' => 'name',
'value' => $entry->name ?? '',
'description' => __( 'Provide a name to the resource.' )
],
'tabs' => [
'general' => [
'label' => __( 'General' ),
'fields' => [
[
'type' => 'text',
'name' => 'id',
'label' => __( 'Id' ),
'value' => $entry->id ?? '',
], [
'type' => 'text',
'name' => 'name',
'label' => __( 'Name' ),
'value' => $entry->name ?? '',
], [
'type' => 'text',
'name' => 'usage',
'label' => __( 'Usage' ),
'description' => __( 'Define how many time the coupon has been used.' ),
'value' => $entry->usage ?? '',
], [
'type' => 'text',
'name' => 'limit',
'name' => 'limit_usage',
'label' => __( 'Limit' ),
'value' => $entry->limit ?? '',
], [
'type' => 'text',
'name' => 'coupon_id',
'label' => __( 'Coupon_id' ),
'value' => $entry->coupon_id ?? '',
], [
'type' => 'text',
'name' => 'customer_id',
'label' => __( 'Customer_id' ),
'value' => $entry->customer_id ?? '',
], [
'type' => 'text',
'name' => 'author',
'label' => __( 'Author' ),
'value' => $entry->author ?? '',
], [
'type' => 'text',
'name' => 'created_at',
'label' => __( 'Created_at' ),
'value' => $entry->created_at ?? '',
], [
'type' => 'text',
'name' => 'updated_at',
'label' => __( 'Updated_at' ),
'value' => $entry->updated_at ?? '',
], ]
'description' => __( 'Define the maximum usage possible for this coupon.' ),
'value' => $entry->limit_usage ?? '',
],
]
]
]
];
Expand Down Expand Up @@ -323,7 +291,9 @@ public function beforeDelete( $namespace, $id, $model ) {

public function hook( $query )
{
$query->where( 'customer_id', request()->query( 'customer_id' ) );
if ( ! empty( request()->query( 'customer_id' ) ) ) {
$query->where( 'customer_id', request()->query( 'customer_id' ) );
}
}

/**
Expand Down Expand Up @@ -362,7 +332,7 @@ public function getColumns() {
'$direction' => '',
'$sort' => false
],
'limit' => [
'limit_usage' => [
'label' => __( 'Limit' ),
'$direction' => '',
'$sort' => false
Expand Down Expand Up @@ -475,11 +445,11 @@ public function bulkAction( Request $request )
public function getLinks()
{
return [
'list' => '#', // ns()->url( 'dashboard/' . 'customers/' . request()->query( 'customer_id' ) . '/coupons' ),
'list' => ns()->route( 'ns.dashboard.customers-coupons-generated-list' ),
'create' => '#', // ns()->url( 'dashboard/' . 'customers/' . request()->query( 'customer_id' ) . '/coupons/create' ),
'edit' => '#', // ns()->url( 'dashboard/' . 'customers/' . request()->query( 'customer_id' ) . '/coupons/edit/' ),
'edit' => ns()->url( 'dashboard/' . 'customers/' . request()->query( 'customer_id' ) . '/coupons/edit/' ),
'post' => ns()->url( 'api/nexopos/v4/crud/' . 'ns.customers-coupons' ),
'put' => ns()->url( 'api/nexopos/v4/crud/' . 'ns.customers-coupons/' . request()->query( 'customer_id' ) . '' . '' ),
'put' => ns()->url( 'api/nexopos/v4/crud/' . 'ns.customers-coupons/{id}' ),
];
}

Expand Down
28 changes: 28 additions & 0 deletions app/Http/Controllers/Dashboard/CustomersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
use App\Http\Controllers\DashboardController;
use App\Models\Coupon;
use App\Models\CustomerAccountHistory;
use App\Models\CustomerCoupon;
use App\Models\CustomerReward;
use App\Models\Order;
use Exception;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\View;

class CustomersController extends DashboardController
{
Expand Down Expand Up @@ -339,6 +341,11 @@ public function getCustomerAccountHistory( Customer $customer )
]);
}

/**
* Will render a form to create a customer account history
* @param Customer $customer
* @return View
*/
public function createCustomerAccountHistory( Customer $customer )
{
return CustomerAccountCrud::form( null, [
Expand Down Expand Up @@ -367,5 +374,26 @@ public function recordAccountHistory( Customer $customer, Request $request )
$request->input( 'general.description' )
);
}

/**
* Will render a form for editing
* a generated coupon
* @param CustomerCoupon $coupon
* @return View
*/
public function editGeneratedCoupon( CustomerCoupon $coupon )
{
return CustomerCouponCrud::form( $coupon );
}

/**
* Will list all coupons generated
* for the available customer
* @return View
*/
public function listGeneratedCoupons()
{
return CustomerCouponCrud::table();
}
}

5 changes: 5 additions & 0 deletions app/Models/CustomerCoupon.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public function scopeCustomer( $query, $customer_id )
public function coupon() {
return $this->hasOne( Coupon::class, 'id', 'coupon_id' );
}

public function customer()
{
return $this->belongsTo( Customer::class, 'customer_id', 'id' );
}
}
2 changes: 1 addition & 1 deletion app/Models/ProductHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ class ProductHistory extends NsModel
ProductHistory::ACTION_DEFECTIVE,
ProductHistory::ACTION_LOST,
ProductHistory::ACTION_ADJUSTMENT_SALE,
ProductHistory::ACTION_DELETED,
];

/**
* actions that increase stock
*/
const STOCK_INCREASE = [
ProductHistory::ACTION_DELETED,
ProductHistory::ACTION_ADDED,
ProductHistory::ACTION_RETURNED,
ProductHistory::ACTION_TRANSFER_IN,
Expand Down
2 changes: 1 addition & 1 deletion app/Services/OrdersService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2037,7 +2037,7 @@ public function deleteOrder(Order $order)
* only if the product is not a quick product/service
*/
if ( $product->product_id > 0 ) {
$this->productService->stockAdjustment( ProductHistory::ACTION_DELETED, [
$this->productService->stockAdjustment( ProductHistory::ACTION_RETURNED, [
'total_price' => $product->total_price,
'product_id' => $product->product_id,
'unit_id' => $product->unit_id,
Expand Down
1 change: 1 addition & 0 deletions phpunit.ci.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<directory suffix="CreateProductTest.php">./tests/Feature</directory>
<directory suffix="CreateProviderTest.php">./tests/Feature</directory>
<directory suffix="MakeProcurementTest.php">./tests/Feature</directory>
<directory suffix="PerformStockAdjustmentTest.php">./tests/Feature</directory>
<directory suffix="CreateOrderTest.php">./tests/Feature</directory>
<directory suffix="DeleteOrderTest.php">./tests/Feature</directory>
<directory suffix="CanSeeReportsTest.php">./tests/Feature</directory>
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<directory suffix="CreateProductTest.php">./tests/Feature</directory>
<directory suffix="CreateProviderTest.php">./tests/Feature</directory>
<directory suffix="MakeProcurementTest.php">./tests/Feature</directory>
<directory suffix="PerformStockAdjustmentTest.php">./tests/Feature</directory>
<directory suffix="CreateOrderTest.php">./tests/Feature</directory>
<directory suffix="DeleteOrderTest.php">./tests/Feature</directory>
<directory suffix="CanSeeReportsTest.php">./tests/Feature</directory>
Expand Down
6 changes: 4 additions & 2 deletions public/css/app.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/app.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/auth.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/manifest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/js/pos.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/setup.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/vendor.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions resources/ts/components/ns-crud.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ import { HttpStatusResponse } from '@/interfaces/http-status-response';
import { HttpCrudResponse } from '@/interfaces/http-crud-response';
import nsOrdersFilterPopupVue from '@/popups/ns-orders-filter-popup.vue';
declare const nsCrudHandler;
export default {
data: () => {
return {
Expand Down
4 changes: 3 additions & 1 deletion routes/web/customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@
Route::get( '/customers/rewards-system/edit/{reward}', [ RewardsSystemController::class, 'edit' ])->name( ns()->routeName( 'ns.dashboard.rewards-edit' ) );
Route::get( '/customers/coupons', [ CustomersController::class, 'listCoupons' ])->name( ns()->routeName( 'ns.dashboard.customers-coupons-list' ) );
Route::get( '/customers/coupons/create', [ CustomersController::class, 'createCoupon' ])->name( ns()->routeName( 'ns.dashboard.customers-coupons-create' ) );
Route::get( '/customers/coupons/edit/{coupon}', [ CustomersController::class, 'editCoupon' ])->name( ns()->routeName( 'ns.dashboard.customers-coupons-edit' ) );
Route::get( '/customers/coupons/edit/{coupon}', [ CustomersController::class, 'editCoupon' ])->name( ns()->routeName( 'ns.dashboard.customers-coupons-edit' ) );
Route::get( '/customers/coupons-generated', [ CustomersController::class, 'listGeneratedCoupons' ])->name( ns()->routeName( 'ns.dashboard.customers-coupons-generated-list' ) );
Route::get( '/customers/coupons-generated/edit/{coupon}', [ CustomersController::class, 'editGeneratedCoupon' ])->name( ns()->routeName( 'ns.dashboard.customers-coupons-generated-edit' ) );
4 changes: 2 additions & 2 deletions tests/Feature/DeleteOrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ public function test_example()

$products->each( function( $product ) use ( $productService ){
$product->actual_quantity = $productService->getQuantity( $product->product_id, $product->unit_id );

/**
* Let's check if the quantity has been restored
* to the default value.
*/
$this->assertTrue(
$product->actual_quantity == $product->previous_quantity + $product->quantity,
( float ) $product->actual_quantity == ( float ) $product->previous_quantity + ( float ) $product->quantity,
__( 'The new quantity was not restored to what it was before the deletion.')
);
});
Expand Down
113 changes: 113 additions & 0 deletions tests/Feature/PerformStockAdjustmentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php

namespace Tests\Feature;

use App\Models\ProductHistory;
use App\Models\ProductUnitQuantity;
use App\Models\Role;
use Exception;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Laravel\Sanctum\Sanctum;
use Tests\TestCase;

class PerformStockAdjustmentTest extends TestCase
{
/**
* A basic feature test example.
*
* @return void
*/
public function test_increase_product_stock()
{
Sanctum::actingAs(
Role::namespace( 'admin' )->users->first(),
['*']
);

$productQuantity = ProductUnitQuantity::where( 'quantity', '>', 0 )->first();

if ( ! $productQuantity instanceof ProductUnitQuantity ) {
throw new Exception( __( 'Unable to find a product to perform this test.' ) );
}

$product = $productQuantity->product;

foreach( ProductHistory::STOCK_INCREASE as $action ) {
$response = $this->withSession( $this->app[ 'session' ]->all() )
->json( 'POST', 'api/nexopos/v4/products/adjustments', [
'products' => [
[
'adjust_action' => $action,
'adjust_unit' => [
'sale_price' => $productQuantity->sale_price,
'unit_id' => $productQuantity->unit_id,
],
'id' => $product->id,
'adjust_quantity' => 10,
]
]
]);

$oldQuantity = $productQuantity->quantity;
$productQuantity->refresh();

$response->assertStatus(200);

$this->assertTrue(
$productQuantity->quantity - $oldQuantity === ( float ) 10,
sprintf(
__( 'The stock modification : %s hasn\'t made any change' ),
$action
)
);
}

}

public function test_decreate_product_stock()
{
Sanctum::actingAs(
Role::namespace( 'admin' )->users->first(),
['*']
);

$productQuantity = ProductUnitQuantity::where( 'quantity', '>', 0 )->first();

if ( ! $productQuantity instanceof ProductUnitQuantity ) {
throw new Exception( __( 'Unable to find a product to perform this test.' ) );
}

$product = $productQuantity->product;

foreach( ProductHistory::STOCK_REDUCE as $action ) {
$response = $this->withSession( $this->app[ 'session' ]->all() )
->json( 'POST', 'api/nexopos/v4/products/adjustments', [
'products' => [
[
'adjust_action' => $action,
'adjust_unit' => [
'sale_price' => $productQuantity->sale_price,
'unit_id' => $productQuantity->unit_id,
],
'id' => $product->id,
'adjust_quantity' => 1,
]
]
]);

$oldQuantity = $productQuantity->quantity;
$productQuantity->refresh();

$response->assertStatus(200);

$this->assertTrue(
$oldQuantity - $productQuantity->quantity === ( float ) 1,
sprintf(
__( 'The stock modification : %s hasn\'t made any change' ),
$action
)
);
}
}
}
Loading

0 comments on commit d734fd1

Please sign in to comment.