Skip to content

Commit

Permalink
Work on Recurring Bill UI
Browse files Browse the repository at this point in the history
  • Loading branch information
inikoo committed Jan 29, 2025
1 parent d10d7c4 commit 92915b0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ public function handle(RecurringBill $recurringBill, $prefix = null): LengthAwar
$queryBuilder = QueryBuilder::for(RecurringBillTransaction::class);
$queryBuilder->where('recurring_bill_transactions.recurring_bill_id', $recurringBill->id);
$queryBuilder->join('assets', 'recurring_bill_transactions.asset_id', '=', 'assets.id');
$queryBuilder->join('historic_assets', 'recurring_bill_transactions.historic_asset_id', '=', 'historic_assets.id');


$queryBuilder->join('historic_assets', 'recurring_bill_transactions.historic_asset_id', '=', 'historic_assets.id');
$queryBuilder->join('currencies', 'assets.currency_id', '=', 'currencies.id');
$queryBuilder->leftjoin('rental_agreement_clauses', 'recurring_bill_transactions.rental_agreement_clause_id', '=', 'rental_agreement_clauses.id');
$queryBuilder->leftjoin('fulfilment_customers', 'recurring_bill_transactions.fulfilment_customer_id', '=', 'fulfilment_customers.id');
$queryBuilder->leftjoin('fulfilments', 'recurring_bill_transactions.fulfilment_id', '=', 'fulfilments.id');
$queryBuilder->leftjoin('organisations', 'recurring_bill_transactions.organisation_id', '=', 'organisations.id');



// $queryBuilder->leftjoin('organisations', 'recurring_bill_transactions.organisation_id', '=', 'organisations.id');

$queryBuilder
->defaultSort('recurring_bill_transactions.id')
Expand All @@ -46,6 +50,9 @@ public function handle(RecurringBill $recurringBill, $prefix = null): LengthAwar
'recurring_bill_transactions.gross_amount',
'recurring_bill_transactions.item_type',
'recurring_bill_transactions.item_id',
'recurring_bill_transactions.start_date',
'recurring_bill_transactions.end_date',

'assets.type as asset_type',
'recurring_bill_transactions.historic_asset_id',
'assets.slug as asset_slug',
Expand All @@ -57,16 +64,16 @@ public function handle(RecurringBill $recurringBill, $prefix = null): LengthAwar

'fulfilment_customers.slug as fulfilment_customer_slug',
'fulfilments.slug as fulfilment_slug',
'organisations.slug as organisation_slug',

// 'organisations.slug as organisation_slug',

'recurring_bill_transactions.temporal_quantity',
'recurring_bill_transactions.quantity',
'currencies.code as currency_code',
'rental_agreement_clauses.percentage_off as discount'
]);


return $queryBuilder->allowedSorts(['id', 'asset_name'])
return $queryBuilder->allowedSorts(['id', 'asset_code'])
->withPaginator($prefix)
->withQueryString();
}
Expand All @@ -93,11 +100,11 @@ public function tableStructure(RecurringBill $recurringBill, ?array $modelOperat

$table
->column(key: 'type', label: __('type'), canBeHidden: false, sortable: true, searchable: true)
->column(key: 'item_name', label: __('Name'), canBeHidden: false, sortable: true, searchable: true)
->column(key: 'asset_code', label: __('rental code'), canBeHidden: false, sortable: true, searchable: true)
->column(key: 'asset_name', label: __('rental name'), canBeHidden: false, sortable: true, searchable: true)
->column(key: 'description', label: __('description'))
->column(key: 'asset_code', label: __('billable'), canBeHidden: false, sortable: true, searchable: true)
// ->column(key: 'asset_name', label: __('rental name'))
->column(key: 'asset_price', label: __('base price'), canBeHidden: false, sortable: true, searchable: true)
->column(key: 'quantity', label: __('quantity'), canBeHidden: false, sortable: true, searchable: true)
->column(key: 'quantity', label: __('quantity'))
->column(key: 'total', label: __('net'), canBeHidden: false, sortable: true, searchable: true, className: 'text-right font-mono')
->defaultSort('id');
};
Expand Down
101 changes: 31 additions & 70 deletions app/Http/Resources/Fulfilment/RecurringBillTransactionsResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

namespace App\Http\Resources\Fulfilment;

use App\Models\Billables\Service;
use App\Models\Catalogue\Product;
use App\Actions\Utils\Abbreviate;
use App\Enums\Catalogue\Asset\AssetTypeEnum;
use App\Models\Fulfilment\Pallet;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Carbon;

/**
* @property int $asset_id
Expand All @@ -27,66 +28,38 @@
* @property mixed $id
* @property mixed $is_auto_assign
* @property mixed $historic_assets_id
* @property mixed $temporal_quantity
* @property mixed $item_type
* @property mixed $net_amount
* @property mixed $discount
* @property mixed $item_id
* @property mixed $start_date
* @property mixed $end_date
*/
class RecurringBillTransactionsResource extends JsonResource
{
public function toArray($request): array
{
if ($this->asset_type == 'service') {
$unitAbbreviation = 's';
$unitLabel = __('service');
} else {
$unitAbbreviation = 'u';
$unitLabel = __('unit');
}
$description='';

$item_name = '';
$item_slug = '';
$route = [];
if ($this->item_type == 'Pallet') {
$pallet = Pallet::find($this->item_id);
if ($pallet) {
$item_name = $pallet->customer_reference;
$item_slug = $pallet->slug;
$route = [
'name' => 'grp.org.fulfilments.show.crm.customers.show.pallets.show',
'parameters' => [
'organisation' => $this->organisation_slug,
'fulfilment' => $this->fulfilment_slug,
'fulfilmentCustomer' => $this->fulfilment_customer_slug,
'pallet' => $item_slug
]
];
}
} elseif ($this->item_type == 'Service') {
$service = Service::find($this->item_id);
if ($service) {
$item_name = $service->name;
$item_slug = $service->slug;
$route = [
'name' => 'grp.org.fulfilments.show.catalogue.services.show',
'parameters' => [
'organisation' => $this->organisation_slug,
'fulfilment' => $this->fulfilment_slug,
'service' => $item_slug
]
];
}
} elseif ($this->item_type == 'Product') {
$product = Product::find($this->item_id);
if ($product) {
$item_name = $product->name;
$item_slug = $product->slug;
$route = [
'name' => 'grp.org.fulfilments.show.catalogue.outers.show',
'parameters' => [
'organisation' => $this->organisation_slug,
'fulfilment' => $this->fulfilment_slug,
'product' => $item_slug
]
];
if($this->item_type=='Pallet'){
$pallet=Pallet::find($this->item_id);

$description=__('Storage').': '.$pallet->reference;
if($this->start_date){
$description .= ' (' . Carbon::parse($this->start_date)->format('d M Y') . '-';
} if($this->end_date){
$description .= Carbon::parse($this->end_date)->format('d M Y') . ')';
}else{
$description .= __('ongoing').')';
}


}

$unitAbbreviation=Abbreviate::run($this->asset_unit);


return [
'id' => $this->id,
'type' => $this->item_type,
Expand All @@ -96,32 +69,20 @@ public function toArray($request): array
'asset_code' => $this->asset_code,
'asset_price' => $this->asset_price,
'asset_name' => $this->asset_name,
'asset_price' => $this->asset_price,
'asset_unit' => $this->asset_unit,
'asset_units' => $this->asset_units,
'currency_code' => $this->currency_code,
'unit_abbreviation' => $unitAbbreviation,
'unit_label' => $unitLabel,
'quantity' => (int) $this->quantity,
'unit_label' => $this->asset_unit,
'quantity' => (int) $this->quantity*$this->temporal_quantity,
'total' => $this->net_amount,
'discount' => (int) $this->discount,

'fulfilment_customer_slug' => $this->fulfilment_customer_slug,
'fulfilment_slug' => $this->fulfilment_slug,
'organisation_slug' => $this->organisation_slug,

'item_name' => $item_name,
'item_slug' => $item_slug,

'route' => $route
// 'historic_assets_id'=> $this->historic_assets_id


'description'=>$description

];
}

public function typeIcon($type)
public function typeIcon($type): ?array
{
if ($type == 'Pallet') {
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ const locale = inject('locale', aikuLocaleStructure)
<!-- <pre>{{ data.data[0] }}</pre> -->

<Table :resource="data" :name="tab" class="mt-5" :is-check-box="false">
<template #cell(item_name)="{ item }">
<Link :href="route(item.route.name, {...item.route.parameters})" class="primaryLink">
{{ item['item_name'] }}
</Link>
</template>

<template #cell(asset_price)="{ item }">
{{ locale.currencyFormat(item.currency_code, item.asset_price || 0) }}/{{ item.unit_label }}
<Tag v-if="item['discount'] > 0" :theme="17">
Expand Down

0 comments on commit 92915b0

Please sign in to comment.