@php
$id = 'orderProducts';
# LIST COMPONENTS
$id_form = "{$id}Insert";
$id_table = "{$id}Records";
$products = [];
$order_id = 0;
$allow_delete = false;
if( !empty($order) ){
// IT SOULD CONTAIN BOTH REQUIRED ID & PRODUCTS
$order_id = $order['id'];
$through = "{$order_id}/products";
$products = $order['products'];
$allow_delete = $order->deletable_products;
}
$headers = [
[
'label' => __('table.header.id'),
'target' => 'pivot.id',
],
[
'label' => __('table.header.code'),
'target' => 'code',
],
[
'label' => __('table.header.product'),
'target' => 'label',
'dclass' => 'lefted',
],
[
'label' => __('table.header.quantity'),
'target' => 'pivot.quantity',
'hclass' => 'quantity'
],
[
'label' => __('table.header.price'),
'target' => 'price',
'hclass' => 'price'
],
[
'label' => __('table.header.subtotal'),
'target' => 'subtotal',
'hclass' => 'price'
],
[
'label' => __('table.header.created'),
'target' => 'created_at',
],
[
'label' => __('table.header.notes'),
'target' => 'notes',
'wclass' => 'notes',
'hclass' => 'notes',
'dclass' => 'notes',
],
];
if($allow_delete){ // ORDER PRODUCTS DELETABLE
array_push($headers,
[
'label' => __('table.header.delete'),
'target' => '_delete'
]);
}
// GET HEADERS TARGETS
$col = array_flip( array_column($headers, 'target') );
@endphp
@push('style')
@endpush
{{-- @extends('master') --}}
@include('components.form', [
'id' => $id_form, // INPUT ID BIND
'resource' => 'orders', // FORM RESOURCE TARGET
'method' => config('const.crud.create'), // RESOURCE METHOD AVAILABLE
'through' => $through, // THROUGH SPEC
'refs' => [
'table' => "{$id_table}Table", // RECORDS TABLE
'form' => "{$id_form}Form" // RECORDS TABLE
],
'groups' => [
[
'product_code' => [
'required' => true,
'type' => 'input-text',
'label' => __('form.label.product'),
'label-class' => 'col-md-1 small',
'div-class' => 'col-md-5',
'input-class' => 'select2x',
'input-attrs' => 'data-init="product_code:product_label"',
'placeholder' => __('form.placeholder.product.name'),
'help' => __('form.help.product.name'),
],
'quantity' => [
'required' => true,
'type' => 'input-text',
'label' => __('form.label.quantity'),
'label-class' => 'col-md-1 small',
'div-class' => 'col-md-2',
'input-class' => 'centered padding0',
'placeholder' => __('form.placeholder.product.quantity'),
'help' => __('form.help.product.quantity')
],
'notes' => [
'type' => 'textarea',
'label-class' => 'col-md-1 small',
'div-class' => 'col-md-2',
'rows' => '2', // 2 LINES
'label' => __('form.label.notes'),
]
],
]
])
{{ __( 'Ordered Products') }}
@include('components.table', [
'id' => $id_table, // INPUT ID BIND
'class' => 'table cell-border hover order-products',
'resource' => 'orders', // FORM RESOURCE TARGET
'method' => config('const.crud.delete'), // RESOURCE METHOD AVAILABLE
'through' => $through, // THROUGH SPEC
'rows_id' => "pivot.id", // ROWS ID FIELD SPEC (DEFAULT ID)
'data' => $products, // PASS DATA IF ANY
'headers' => $headers,
'footers' => [
[
'attrs' => 'class="total" colspan="4" style="text-align:right"',
'label' => 'Total'
]
],
])
@push('script')
@endpush