/*========================================================================================= File Name: app-invoice-list.js Description: app-invoice-list Javascripts ---------------------------------------------------------------------------------------- Item Name: Vuexy - Vuejs, HTML & Laravel Admin Dashboard Template Version: 1.0 Author: PIXINVENT Author URL: http://www.themeforest.net/user/pixinvent ==========================================================================================*/ $(function () { 'use strict'; var dtInvoiceTable = $('.invoice-list-table'), assetPath = '../../../app-assets/', invoicePreview = 'app-invoice-preview.html', invoiceAdd = 'app-invoice-add.html', invoiceEdit = 'app-invoice-edit.html'; if ($('body').attr('data-framework') === 'laravel') { assetPath = $('body').attr('data-asset-path'); invoicePreview = assetPath + 'app/invoice/preview'; invoiceAdd = assetPath + 'app/invoice/add'; invoiceEdit = assetPath + 'app/invoice/edit'; } // datatable if (dtInvoiceTable.length) { var dtInvoice = dtInvoiceTable.DataTable({ ajax: assetPath + 'data/invoice-list.json', // JSON file to add data autoWidth: false, columns: [ // columns according to JSON { data: 'responsive_id' }, { data: 'invoice_id' }, { data: 'invoice_status' }, { data: 'issued_date' }, { data: 'client_name' }, { data: 'total' }, { data: 'balance' }, { data: 'invoice_status' }, { data: '' } ], columnDefs: [ { // For Responsive className: 'control', responsivePriority: 2, targets: 0 }, { // Invoice ID targets: 1, width: '46px', render: function (data, type, full, meta) { var $invoiceId = full['invoice_id']; // Creates full output for row var $rowOutput = ' #' + $invoiceId + ''; return $rowOutput; } }, { // Invoice status targets: 2, width: '42px', render: function (data, type, full, meta) { var $invoiceStatus = full['invoice_status'], $dueDate = full['due_date'], $balance = full['balance'], roleObj = { Sent: { class: 'bg-light-secondary', icon: 'send' }, Paid: { class: 'bg-light-success', icon: 'check-circle' }, Draft: { class: 'bg-light-primary', icon: 'save' }, Downloaded: { class: 'bg-light-info', icon: 'arrow-down-circle' }, 'Past Due': { class: 'bg-light-danger', icon: 'info' }, 'Partial Payment': { class: 'bg-light-warning', icon: 'pie-chart' } }; return ( " Balance: ' + $balance + '
Due Date: ' + $dueDate + "
'>" + '
' + '' + feather.icons[roleObj[$invoiceStatus].icon].toSvg({ class: 'avatar-icon' }) + '' + '
' + '' ); } }, { // Client name and Service targets: 3, responsivePriority: 4, width: '270px', render: function (data, type, full, meta) { var $name = full['client_name'], $email = full['email'], $image = full['avatar'], stateNum = Math.floor(Math.random() * 6), states = ['success', 'danger', 'warning', 'info', 'primary', 'secondary'], $state = states[stateNum], $name = full['client_name'], $initials = $name.match(/\b\w/g) || []; $initials = (($initials.shift() || '') + ($initials.pop() || '')).toUpperCase(); if ($image) { // For Avatar image var $output = 'Avatar'; } else { // For Avatar badge $output = '
' + $initials + '
'; } // Creates full output for row var colorClass = $image === '' ? ' bg-light-' + $state + ' ' : ' '; var $rowOutput = '
' + '
' + '
' + $output + '
' + '
' + '
' + '
' + $name + '
' + '' + $email + '' + '
' + '
'; return $rowOutput; } }, { // Total Invoice Amount targets: 4, width: '73px', render: function (data, type, full, meta) { var $total = full['total']; return '' + $total + '$' + $total; } }, { // Due Date targets: 5, width: '130px', render: function (data, type, full, meta) { var $dueDate = new Date(full['due_date']); // Creates full output for row var $rowOutput = '' + moment($dueDate).format('YYYYMMDD') + '' + moment($dueDate).format('DD MMM YYYY'); $dueDate; return $rowOutput; } }, { // Client Balance/Status targets: 6, width: '98px', render: function (data, type, full, meta) { var $balance = full['balance']; if ($balance === 0) { var $badge_class = 'badge-light-success'; return ' Paid '; } else { return '' + $balance + '' + $balance; } } }, { targets: 7, visible: false }, { // Actions targets: -1, title: 'Actions', width: '80px', orderable: false, render: function (data, type, full, meta) { return ( '
' + '' + feather.icons['send'].toSvg({ class: 'font-medium-2 text-body' }) + '' + '' + feather.icons['eye'].toSvg({ class: 'font-medium-2 text-body' }) + '' + '' + '
' ); } } ], order: [[1, 'desc']], dom: '<"row d-flex justify-content-between align-items-center m-1"' + '<"col-lg-6 d-flex align-items-center"l<"dt-action-buttons text-xl-end text-lg-start text-lg-end text-start "B>>' + '<"col-lg-6 d-flex align-items-center justify-content-lg-end flex-lg-nowrap flex-wrap pe-lg-1 p-0"f<"invoice_status ms-sm-2">>' + '>t' + '<"d-flex justify-content-between mx-2 row"' + '<"col-sm-12 col-md-6"i>' + '<"col-sm-12 col-md-6"p>' + '>', language: { sLengthMenu: 'Show _MENU_', search: 'Search', searchPlaceholder: 'Search Invoice', paginate: { // remove previous & next text from pagination previous: ' ', next: ' ' } }, // Buttons with Dropdown buttons: [ { text: 'Add Record', className: 'btn btn-primary btn-add-record ms-2', action: function (e, dt, button, config) { window.location = invoiceAdd; } } ], // For responsive popup responsive: { details: { display: $.fn.dataTable.Responsive.display.modal({ header: function (row) { var data = row.data(); return 'Details of ' + data['client_name']; } }), type: 'column', renderer: function (api, rowIdx, columns) { var data = $.map(columns, function (col, i) { return col.columnIndex !== 2 // ? Do not show row in modal popup if title is blank (for check box) ? '' + '' + col.title + ':' + ' ' + '' + col.data + '' + '' : ''; }).join(''); return data ? $('').append('' + data + '') : false; } } }, initComplete: function () { $(document).find('[data-bs-toggle="tooltip"]').tooltip(); // Adding role filter once table initialized this.api() .columns(7) .every(function () { var column = this; var select = $( '' ) .appendTo('.invoice_status') .on('change', function () { var val = $.fn.dataTable.util.escapeRegex($(this).val()); column.search(val ? '^' + val + '$' : '', true, false).draw(); }); column .data() .unique() .sort() .each(function (d, j) { select.append(''); }); }); }, drawCallback: function () { $(document).find('[data-bs-toggle="tooltip"]').tooltip(); } }); } });