Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
- Added: Products Combinaison
- Fixed: Editing Procurement
- Added: New Vue Components
- Fixed: Pagination
- Added: Reward System Preview
- Fixed: Requesting TimeZone for Year Report
  • Loading branch information
Blair2004 committed Oct 8, 2021
1 parent 72182b5 commit 60c52f5
Show file tree
Hide file tree
Showing 22 changed files with 345 additions and 20 deletions.
7 changes: 7 additions & 0 deletions app/Forms/ProcurementForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ public function __construct()
'products' => isset( $procurement ) ? $procurement->products->map( function( $_product ) {
$product = Product::findOrFail( $_product->product_id );
$product->load( 'unit_quantities.unit' )->get();

$_product->procurement = array_merge( $_product->toArray(), [
'$invalid' => false,
'purchase_price_edit' => $_product->purchase_price
]);

$_product->unit_quantities = $product->unit_quantities;

return $_product;
}) : [],
'tabs' => [
Expand Down
10 changes: 10 additions & 0 deletions app/Http/Controllers/Dashboard/CustomersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,5 +395,15 @@ public function listGeneratedCoupons()
{
return CustomerCouponCrud::table();
}

/**
* Will return the customer rewards
* @param Customer $customer
* @return array<CustomerReward> $customerRewards
*/
public function getCustomerRewards( Customer $customer )
{
return $customer->rewards()->paginate(20);
}
}

57 changes: 57 additions & 0 deletions app/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use App\Casts\CurrencyCast;
use App\Casts\DateCast;
use App\Classes\Hook;
use App\Services\DateService;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand Down Expand Up @@ -152,4 +153,60 @@ public function scopePaymentStatusIn( $query, array $statuses )
{
return $query->whereIn( 'payment_status', $statuses );
}

/**
* Will return conditionnaly the merged products
* or all the product if it's enabled or disabled.
* @return array
*/
public function getProductsAttribute()
{
if ( ns()->option->get( 'ns_invoice_merge_similar_products', 'no' ) === 'yes' ) {
return $this->combinedProducts;
}

return $this->products()->get();
}

public function getCombinedProductsAttribute()
{
$combinaison = [];

$this->products()->with( 'unit' )->get()->each( function( $product ) use ( &$combinaison ){
$values = $product->toArray();

extract( $values );

$keys = array_keys( $combinaison );
$stringified = Hook::filter( 'ns-products-combinaison-identifier', $product_id . '-' . $order_id . '-' . $discount . '-' . $product_category_id . '-' . $status, $product );
$combinaisonAttributes = Hook::filter( 'ns-products-combinaison-attributes', [
'quantity',
'total_gross_price',
'total_price',
'total_purchase_price',
'total_net_price',
'discount'
]);

if ( in_array( $stringified, $keys ) ) {
foreach( $combinaisonAttributes as $attribute ) {
$combinaison[ $stringified ][ $attribute ] += (float) $product->$attribute;
}
} else {
$rawProduct = $product->toArray();

unset( $rawProduct[ 'id' ] );
unset( $rawProduct[ 'created_at' ] );
unset( $rawProduct[ 'updated_at' ] );
unset( $rawProduct[ 'procurement_product_id' ] );

$combinaison[ $stringified ] = $rawProduct;
}
});

/**
* that's nasty.
*/
return collect( json_decode( json_encode( $combinaison ) ) );
}
}
4 changes: 2 additions & 2 deletions app/Services/TestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

class TestService
{
public function prepareOrder( Carbon $date, array $orderDetails = [], array $productDetails = [] )
public function prepareOrder( Carbon $date, array $orderDetails = [], array $productDetails = [], array $config = [] )
{
/**
* @var CurrencyService
*/
$currency = app()->make( CurrencyService::class );
$faker = Factory::create();
$products = Product::where( 'tax_group_id', '>', 0 )->with( 'unit_quantities' )->get()->shuffle()->take(3);
$products = isset( $config[ 'products' ] ) ? $config[ 'products' ]() : Product::where( 'tax_group_id', '>', 0 )->with( 'unit_quantities' )->get()->shuffle()->take(3);
$shippingFees = $faker->randomElement([10,15,20,25,30,35,40]);
$discountRate = $faker->numberBetween(0,5);

Expand Down
10 changes: 10 additions & 0 deletions app/Settings/invoice-settings/receipts.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
'name' => 'ns_invoice_receipt_logo',
'value' => $options->get( 'ns_invoice_receipt_logo' ),
'description' => __( 'Provide a URL to the logo.' )
], [
'label' => __( 'Merge Products On Receipt/Invoice' ),
'type' => 'switch',
'options' => Helper::kvToJsOptions([
'no' => __( 'No' ),
'yes' => __( 'Yes' )
]),
'name' => 'ns_invoice_merge_similar_products',
'value' => $options->get( 'ns_invoice_merge_similar_products' ),
'description' => __( 'All similar products will be merged to avoid a paper waste for the receipt/invoice.' )
], [
'label' => __( 'Receipt Footer' ),
'type' => 'textarea',
Expand Down
1 change: 1 addition & 0 deletions phpunit.ci.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<directory suffix="CreateRegisterTest.php">./tests/Feature</directory>
<directory suffix="CreateOrderOnRegister.php">./tests/Feature</directory>
<directory suffix="CreateOrderTest.php">./tests/Feature</directory>
<directory suffix="CombiningProductsTest.php">./tests/Feature</directory>
<directory suffix="ComputeTaxesFromSales.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 @@ -27,6 +27,7 @@
<directory suffix="CreateRegisterTest.php">./tests/Feature</directory>
<directory suffix="CreateOrderOnRegister.php">./tests/Feature</directory>
<directory suffix="CreateOrderTest.php">./tests/Feature</directory>
<directory suffix="CombiningProductsTest.php">./tests/Feature</directory>
<directory suffix="ComputeTaxesFromSales.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 resources/lang/pt.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions resources/ts/components/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { nsInput } from './ns-input';
import { nsSelect } from './ns-select';
import { nsSelectAudio } from './ns-select-audio';
import { nsCheckbox } from './ns-checkbox';
import { default as nsCrud } from './ns-crud.vue';
import { nsTableRow } from './ns-table-row';
import { nsSpinner } from './ns-spinner';
import { nsCrudForm } from './ns-crud-form';
Expand All @@ -21,11 +20,13 @@ import { nsIconButton } from './ns-icon-button';
import { nsCkeditor } from './ns-ckeditor';
import { nsTabs, nsTabsItem } from './ns-tabs';
import { nsDateTimePicker } from './ns-date-time-picker';
import { default as nsCrud } from './ns-crud.vue';
import { default as nsNumpad } from './ns-numpad.vue';
import { default as nsAvatar } from './ns-avatar.vue';
import { default as nsDateRangePicker } from './ns-date-range-picker.vue';

const nsDatepicker = require( './ns-datepicker.vue' ).default;
import { default as nsNotice } from './ns-notice.vue';
import { default as nsDatepicker } from './ns-datepicker.vue';
import { default as nsPaginate } from './ns-paginate.vue';

export { nsMenu };
export { nsSubmenu };
Expand Down Expand Up @@ -54,3 +55,5 @@ export { nsNumpad };
export { nsSelectAudio };
export { nsAvatar };
export { nsDateRangePicker };
export { nsNotice };
export { nsPaginate };
5 changes: 3 additions & 2 deletions resources/ts/components/ns-crud-form.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { nsHooks, nsHttpClient, nsSnackBar } from '../bootstrap';
import Vue from 'vue';
import FormValidation from '../libraries/form-validation';

import { __ } from '@/libraries/lang';
const nsCrudForm = Vue.component( 'ns-crud-form', {
data: () => {
return {
Expand All @@ -26,6 +26,7 @@ const nsCrudForm = Vue.component( 'ns-crud-form', {
}
},
methods: {
__,
toggle( identifier ) {
for( let key in this.form.tabs ) {
this.form.tabs[ key ].active = false;
Expand Down Expand Up @@ -123,7 +124,7 @@ const nsCrudForm = Vue.component( 'ns-crud-form', {
<span v-if="form.main.name">{{ form.main.label }}</span>
</label>
<div for="title" class="text-sm my-2 text-gray-700">
<a v-if="returnUrl" :href="returnUrl" class="rounded-full border border-gray-400 hover:border-red-600 hover:bg-red-600 hover:text-white bg-white px-2 py-1">Return</a>
<a v-if="returnUrl" :href="returnUrl" class="rounded-full border border-gray-400 hover:border-red-600 hover:bg-red-600 hover:text-white bg-white px-2 py-1">{{ __( 'Go Back' ) }}</a>
</div>
</div>
<template v-if="form.main.name">
Expand Down
18 changes: 14 additions & 4 deletions resources/ts/components/ns-crud.vue
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,21 @@ export default {
pageNumbers(count, current) {
var shownPages = 3;
var result = [];
if (current > count - shownPages) {
result.push(count - 2, count - 1, count);
} else {
result.push(current, current + 1, current + 2, '...', count);
if ( current - 3 > 1 ) {
result.push( 1, '...' );
}
for( let i = 1; i <= count; i++ ) {
if ( current + 3 > i && current - 3 < i ) {
result.push(i);
}
}
if ( current + 3 < count ) {
result.push( '...', count );
}
return result.filter( f => f > 0 || typeof f === 'string' );
},
Expand Down
17 changes: 17 additions & 0 deletions resources/ts/components/ns-notice.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<div :class="'bg-' + actualColor + '-100 border-l-4 border-' + actualColor + '-500 text-' + actualColor + '-700'" class="p-4" role="alert">
<p class="font-bold"><slot name="title"></slot></p>
<p><slot name="description"></slot></p>
</div>
</template>
<script>
export default {
name: 'ns-notice',
props: [ 'color' ],
computed: {
actualColor() {
return this.color || 'blue';
}
}
}
</script>
68 changes: 68 additions & 0 deletions resources/ts/components/ns-paginate.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<template>
<div id="pagination" class="flex -mx-1">
<template v-if="pagination.current_page">
<a href="javascript:void(0)" @click="gotoPage( pagination.first_page )" class="mx-1 flex items-center justify-center h-8 w-8 rounded-full bg-gray-200 text-gray-700 hover:bg-blue-400 hover:text-white shadow">
<i class="las la-angle-double-left"></i>
</a>
<template v-for="(_paginationPage, index) of getPagination">
<a :key="index" v-if="page !== '...'" :class="page == _paginationPage ? 'bg-blue-400 text-white' : 'bg-gray-200 text-gray-700'" @click="gotoPage( _paginationPage )" href="javascript:void(0)" class="mx-1 flex items-center justify-center h-8 w-8 rounded-full hover:bg-blue-400 hover:text-white">{{ _paginationPage }}</a>
<a :key="index" v-if="page === '...'" href="javascript:void(0)" class="mx-1 flex items-center justify-center h-8 w-8 rounded-full bg-gray-200 text-gray-700">...</a>
</template>
<a href="javascript:void(0)" @click="gotoPage( pagination.last_page )" class="mx-1 flex items-center justify-center h-8 w-8 rounded-full bg-gray-200 text-gray-700 hover:bg-blue-400 hover:text-white shadow">
<i class="las la-angle-double-right"></i>
</a>
</template>
</div>
</template>
<script>
export default {
name: 'ns-paginate',
props: [ 'pagination' ],
data: () => {
return {
page: 1,
path: '',
}
},
mounted(){
this.path = this.pagination.path;
},
computed: {
getPagination() {
if ( this.pagination ) {
return this.pageNumbers( this.pagination.last_page, this.pagination.current_page );
}
return [];
},
},
methods: {
gotoPage( page ) {
this.page = page;
this.$emit( 'load', `${this.path}?page=${this.page}` );
},
pageNumbers(count, current) {
var shownPages = 3;
var result = [];
if ( current - 3 > 1 ) {
result.push( 1, '...' );
}
for( let i = 1; i <= count; i++ ) {
if ( current + 3 > i && current - 3 < i ) {
result.push(i);
}
}
if ( current + 3 < count ) {
result.push( '...', count );
}
console.log( result );
return result.filter( f => f > 0 || typeof f === 'string' );
},
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ export default {
<div class="flex justify-between items-center">
<label for="title" class="font-bold my-2 text-gray-700"><slot name="title">{{ __( 'No title is provided' ) }}</slot></label>
<div for="title" class="text-sm my-2 text-gray-700">
<a v-if="returnUrl" :href="returnUrl" class="rounded-full border border-gray-400 hover:bg-red-600 hover:text-white bg-white px-2 py-1">{{ __( 'Return' ) }}</a>
<a v-if="returnUrl" :href="returnUrl" class="rounded-full border border-gray-400 hover:bg-red-600 hover:text-white bg-white px-2 py-1">{{ __( 'Go Back' ) }}</a>
</div>
</div>
<div :class="form.main.disabled ? 'border-gray-500' : form.main.errors.length > 0 ? 'border-red-600' : 'border-blue-500'" class="flex border-2 rounded overflow-hidden">
Expand Down
12 changes: 9 additions & 3 deletions resources/ts/pages/dashboard/reports/ns-yearly-report.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
<script>
import moment from "moment";
import nsDatepicker from "@/components/ns-datepicker";
import nsNotice from "@/components/ns-notice";
import { nsHttpClient, nsSnackBar } from '@/bootstrap';
import nsPosConfirmPopupVue from '@/popups/ns-pos-confirm-popup.vue';
export default {
name : 'ns-yearly-report',
mounted() {
this.loadReport();
if ( this.timezone !== '' ) {
this.year = ns.date.getMoment().format( 'Y' );
this.loadReport();
}
},
components: {
nsDatepicker
nsDatepicker,
nsNotice
},
data() {
return {
startDate: moment(),
endDate: moment(),
report: {},
year: ns.date.getMoment().format( 'Y' ),
timezone: ns.date.timeZone,
year: '',
labels: [ 'month_paid_orders', 'month_taxes', 'month_expenses', 'month_income' ]
}
},
Expand Down
2 changes: 1 addition & 1 deletion resources/ts/popups/ns-orders-refund-popup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="border-b p-2 flex items-center justify-between">
<h3>{{ __( 'Order Refunds' ) }}</h3>
<div class="flex">
<div v-if="view === 'details'" @click="view = 'summary'" class="flex items-center justify-center cursor-pointer rounded-full px-3 border hover:bg-blue-400 hover:text-white mr-1">{{ __( 'Return' ) }}</div>
<div v-if="view === 'details'" @click="view = 'summary'" class="flex items-center justify-center cursor-pointer rounded-full px-3 border hover:bg-blue-400 hover:text-white mr-1">{{ __( 'Go Back' ) }}</div>
<ns-close-button @click="close()"></ns-close-button>
</div>
</div>
Expand Down
Loading

0 comments on commit 60c52f5

Please sign in to comment.