У меня есть страница с именем ca sh -flow. Я хочу показать данные, которые я выбрал из базы данных, используя ajax. Я получил данные, но не отображается в поле зрения. в чем проблема, пожалуйста, руководство. это мой файл просмотра
<div class="row">
<div class="col-sm-12">
<div class="box">
<div class="box-body">
@can('account.access')
<div class="table-responsive">
<table class="table table-bordered table-striped" id="cash_flow_table">
<thead>
<tr>
<th>@lang( 'messages.date' )</th>
<th>@lang( 'account.account' )</th>
<th>@lang( 'lang_v1.description' )</th>
<th>@lang('account.credit')</th>
<th>@lang('account.debit')</th>
<th>@lang( 'lang_v1.balance' )</th>
</tr>
</thead>
</table>
</div>
@endcan
</div>
</div>
</div>
</div>
<div class="modal fade account_model" tabindex="-1" role="dialog"
aria-labelledby="gridSystemModalLabel">
</div>
</section>
<!-- /.content -->
@endsection
@section('javascript')
<script>
$(document).ready(function(){
dateRangeSettings.autoUpdateInput = false
$('#transaction_date_range').daterangepicker(
dateRangeSettings,
function (start, end) {
$('#transaction_date_range').val(start.format(moment_date_format) + ' ~ ' + end.format(moment_date_format));
var start = '';
var end = '';
if($('#transaction_date_range').val()){
start = $('input#transaction_date_range').data('daterangepicker').startDate.format('YYYY-MM-DD');
end = $('input#transaction_date_range').data('daterangepicker').endDate.format('YYYY-MM-DD');
}
cash_flow_table.ajax.reload();
}
);
// Cash Flow Table
cash_flow_table = $('#cash_flow_table').DataTable({
processing: true,
serverSide: true,
"ajax": {
"url": "{{action("AccountController@cashFlow")}}",
"data": function ( d ) {
var start = '';
var end = '';
if($('#transaction_date_range').val() != ''){
start = $('#transaction_date_range').data('daterangepicker').startDate.format('YYYY-MM-DD');
end = $('#transaction_date_range').data('daterangepicker').endDate.format('YYYY-MM-DD');
}
d.account_id = $('#account_id').val();
d.type = $('#transaction_type').val();
d.start_date = start,
d.end_date = end
}
},
"ordering": false,
"searching": false,
columns: [
{data: 'operation_date', name: 'operation_date'},
{data: 'account_name', name: 'account_name'},
{data: 'sub_type', name: 'sub_type'},
{data: 'credit', name: 'amount'},
{data: 'debit', name: 'amount'},
{data: 'balance', name: 'balance'},
],
"fnDrawCallback": function (oSettings) {
__currency_convert_recursively($('#cash_flow_table'));
}
});
$('#transaction_type, #account_id').change( function(){
cash_flow_table.ajax.reload();
});
$('#transaction_date_range').on('cancel.daterangepicker', function(ev, picker) {
$('#transaction_date_range').val('').change();
cash_flow_table.ajax.reload();
});
});
</script>
Это функция контроллера, который извлекает данные
public function cashFlow()
{
if (!auth()->user()->can('account.access')) {
abort(403, 'Unauthorized action.');
}
$business_id = request()->session()->get('user.business_id');
$accounts = AccountTransaction::join(
'accounts as A',
'account_transactions.account_id',
'=',
'A.id'
)
->where('A.business_id', $business_id)
->with(['transaction', 'transaction.contact', 'transfer_transaction'])
->select(['type', 'amount', 'operation_date',
'sub_type', 'transfer_transaction_id',
DB::raw('(SELECT SUM(IF(AT.type="credit", AT.amount, -1 * AT.amount)) from account_transactions as AT WHERE AT.operation_date <= account_transactions.operation_date AND AT.deleted_at IS NULL) as balance'),
'transaction_id',
'account_transactions.id',
'A.name as account_name'
])
->groupBy('account_transactions.id')
->orderBy('account_transactions.operation_date', 'desc')->get();
if (!empty(request()->input('type'))) {
$accounts->where('type', request()->input('type'));
}
if (!empty(request()->input('account_id'))) {
$accounts->where('A.id', request()->input('account_id'));
}
$start_date = request()->input('start_date');
$end_date = request()->input('end_date');
if (!empty($start_date) && !empty($end_date)) {
$accounts->whereBetween(DB::raw('date(operation_date)'), [$start_date, $end_date]);
}
return DataTables::of($accounts)
->addColumn('debit', function ($row) {
if ($row->type == 'debit') {
return '<span class="display_currency" data-currency_symbol="true">' . $row->amount . '</span>';
}
return '';
})
->addColumn('credit', function ($row) {
if ($row->type == 'credit') {
return '<span class="display_currency" data-currency_symbol="true">' . $row->amount . '</span>';
}
return '';
})
->editColumn('balance', function ($row) {
return '<span class="display_currency" data-currency_symbol="true">' . $row->balance . '</span>';
})
->editColumn('operation_date', function ($row) {
return $this->commonUtil->format_date($row->operation_date, true);
})
->editColumn('sub_type', function ($row) {
$details = '';
if (!empty($row->sub_type)) {
$details = __('account.' . $row->sub_type);
if (in_array($row->sub_type, ['fund_transfer', 'deposit']) && !empty($row->transfer_transaction)) {
if ($row->type == 'credit') {
$details .= ' ( ' . __('account.from') .': ' . $row->transfer_transaction->account->name . ')';
} else {
$details .= ' ( ' . __('account.to') .': ' . $row->transfer_transaction->account->name . ')';
}
}
} else {
if (!empty($row->transaction->type)) {
if ($row->transaction->type == 'purchase') {
$details = '<b>' . __('purchase.supplier') . ':</b> ' . $row->transaction->contact->name . '<br><b>'.
__('purchase.ref_no') . ':</b> ' . $row->transaction->ref_no;
} elseif ($row->transaction->type == 'sell') {
$details = '<b>' . __('contact.customer') . ':</b> ' . $row->transaction->contact->name . '<br><b>'.
__('sale.invoice_no') . ':</b> ' . $row->transaction->invoice_no;
}
}
}
return $details;
})
->removeColumn('id')
->rawColumns(['credit', 'debit', 'balance', 'sub_type'])
->make(true);
$accounts = Account::forDropdown($business_id, false);
$accounts->prepend(__('messages.all'), '');
return view('account.cash_flow')
->with(compact('accounts'));
}
, он показывает мне следующие данные в браузере, но не отображается. Что не так, пожалуйста, руководство
{"draw":0,"recordsTotal":3,"recordsFiltered":3,"data":[{"type":"credit","amount":"10000.0000","operation_date":"01\/16\/2020 23:07","sub_type":"Opening Balance","transfer_transaction_id":null,"balance":"<span class=\"display_currency\" data-currency_symbol=\"true\">12726.7500<\/span>","transaction_id":null,"account_name":"bank name","transaction":null,"transfer_transaction":null,"debit":"","credit":"<span class=\"display_currency\" data-currency_symbol=\"true\">10000.0000<\/span>"},{"type":"credit","amount":"123.0000","operation_date":"01\/16\/2020 23:02","sub_type":"Opening Balance","transfer_transaction_id":null,"balance":"<span class=\"display_currency\" data-currency_symbol=\"true\">2726.7500<\/span>","transaction_id":null,"account_name":"Nazmul Huda","transaction":null,"transfer_transaction":null,"debit":"","credit":"<span class=\"display_currency\" data-currency_symbol=\"true\">123.0000<\/span>"},{"type":"credit","amount":"100.0000","operation_date":"01\/16\/2020 22:42","sub_type":"Opening Balance","transfer_transaction_id":null,"balance":"<span class=\"display_currency\" data-currency_symbol=\"true\">2491.7500<\/span>","transaction_id":null,"account_name":"bank name","transaction":null,"transfer_transaction":null,"debit":"","credit":"<span class=\"display_currency\" data-currency_symbol=\"true\">100.0000<\/span>"}],"input":[]}