vb_book/app/Views/report_general_invoice.php
2025-03-07 16:02:22 +05:30

293 lines
13 KiB
PHP
Executable File

<!-- start page title -->
<div class="row d-flex align-items-center">
<!-- Title Section -->
<div class="col-md-4">
<div class="page-title-box page-title-box-alt">
<h4 class="page-title"><?= $page_name ?></h4>
</div>
</div>
<!-- Form Section -->
<div class="col-md-5 offset-md-3">
<form action="<?php echo base_url('general_inv_rp'); ?>" method="post">
<div class="form-group">
<div class="row">
<div class="col-md-7">
<input class="form-control input-daterange-datepicker" type="text" name="date" value="<?php echo $selected_data; ?>" />
</div>
<div class="col-md-5">
<button type="submit" class="btn btn-primary">Generate Report</button>
</div>
</div>
</div>
</form>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row mb-3">
<div class="col-md-12 d-flex justify-content-end">
<button type="button" class="btn btn-primary show-column-selection-modal">Select Columns</button>
</div>
</div>
<div class="table-responsive">
<table id="datatable-buttons" class="table table-striped nowrap w-100">
<thead>
<tr>
<th hidden>id</th>
<th>Invoice No</th>
<th>Invoice Date</th>
<th>Customer Name</th>
<th>Count</th>
<th>Invoice Type</th>
<th>Status</th>
<th>Payment</th>
<th>Discount (₹)</th>
<th>OT Charges (₹)</th>
<th>GST (%)</th>
<th>Total (₹)</th>
</tr>
</thead>
<tbody>
<?php foreach ($report_data as $row) { ?>
<tr>
<td hidden><?php echo $row->invoice_id; ?></td>
<td><?php echo $row->invoice_number; ?></td>
<td style="text-align: left;"><?php echo $row->formatted_invoice_date; ?></td>
<td style="text-align: left;"><?php echo $row->first_name . " " . $row->last_name; ?></td>
<td style="text-align: center;"><?php echo $row->item_count; ?></td>
<td><?php echo ($row->invoice_type == 1) ? 'Book' : 'Membership'; ?></td>
<td><?php echo $row->status; ?></td>
<td style="text-align: left;"><?php echo strtoupper($row->payment_method); ?></td>
<td style="text-align: right;"><?php echo number_format($row->discount, 2, '.', ','); ?></td>
<td style="text-align: right;"><?php echo number_format($row->shipping_charge, 2, '.', ','); ?></td>
<td style="text-align: right;"><?php echo $row->tax ? $row->tax : '0.00'; ?></td>
<td style="text-align: right;max: width 5%;"><?php echo number_format($row->total_amount, 2, '.', ','); ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="modal fade" id="columnSelectionModal" tabindex="-1" role="dialog" aria-labelledby="columnSelectionModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="columnSelectionModalLabel">Select Columns to Display</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<!-- Add checkboxes for each column -->
<div class="form-check form-check-inline">
<input type="checkbox" class="form-check-input column-toggle" data-column="1" checked> Invoice No
</div><br>
<div class="form-check form-check-inline">
<input type="checkbox" class="form-check-input column-toggle" data-column="2" checked> Invoice Date
</div><br>
<div class="form-check form-check-inline">
<input type="checkbox" class="form-check-input column-toggle" data-column="3" checked> Customer Name
</div><br>
<div class="form-check form-check-inline">
<input type="checkbox" class="form-check-input column-toggle" data-column="4" checked> Count
</div><br>
<div class="form-check form-check-inline">
<input type="checkbox" class="form-check-input column-toggle" data-column="5" checked> Invoice Type
</div><br>
<div class="form-check form-check-inline">
<input type="checkbox" class="form-check-input column-toggle" data-column="6" checked> Status
</div><br>
<div class="form-check form-check-inline">
<input type="checkbox" class="form-check-input column-toggle" data-column="7" checked> Payment
</div><br>
<div class="form-check form-check-inline">
<input type="checkbox" class="form-check-input column-toggle" data-column="8" checked> Discount
</div><br>
<div class="form-check form-check-inline">
<input type="checkbox" class="form-check-input column-toggle" data-column="9" checked> OT Charges
</div><br>
<div class="form-check form-check-inline">
<input type="checkbox" class="form-check-input column-toggle" data-column="10" checked> GST
</div><br>
<div class="form-check form-check-inline">
<input type="checkbox" class="form-check-input column-toggle" data-column="11" checked> Total
</div><br>
<!-- Repeat similar blocks for other columns -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary apply-column-selection">Apply</button>
</div>
</div>
</div>
</div>
</div> <!-- end card body-->
</div> <!-- end card -->
</div><!-- end col-->
</div>
<!-- end row-->
<script>
$(document).ready(function() {
var table = $('#datatable-buttons').DataTable({
"order": [
// [0, 'desc']
],
"dom": '<"row mb-3"<"col-md-6 d-flex align-items-center"B><"col-md-6 d-flex justify-content-end"f>>rtip',
buttons: [{
extend: 'print',
text: 'Print',
title: '<?= $page_name.' ' .$selected_data ?>',
customize: function(win) {
// Exclude the first and last columns
$(win.document.body).find('table').find('th:first-child, td:first-child').remove();
}
},
{
extend: 'csv',
text: 'CSV',
title: '<?= $page_name.' ' .$selected_data?>',
exportOptions: {
columns: ':not(:first-child)'
}
}
],
columnDefs: [{
type: 'date',
targets: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
orderable: false
} // Specify the column index for date sorting and disable sorting
]
});
$('.show-column-selection-modal').on('click', function() {
// Hide dropdowns when the modal is shown
$('.table-responsive select').hide();
$('#columnSelectionModal').modal('show');
});
// Handle column visibility toggling
$('.column-toggle').on('change', function() {
var column = table.column($(this).data('column'));
column.visible(!column.visible());
// Remove corresponding values when column is removed
if (!column.visible()) {
// Find the index of the column
var columnIndex = $(this).data('column');
// Remove values from the column selection dropdown
$('#datatable-buttons thead tr:eq(1) th:eq(' + columnIndex + ') select').remove();
// Remove the date range filter for the column
if (columnIndex === 2) {
$('#datatable-buttons thead tr:eq(2) th:eq(2) input').daterangepicker('destroy').remove();
}
}
});
// Apply Column Selection
$('.apply-column-selection').on('click', function() {
// Show dropdowns when the modal is closed
$('.table-responsive select').show();
$('#columnSelectionModal').modal('hide');
});
// Add date range filter and dropdowns
$('#datatable-buttons thead tr').clone(true).appendTo('#datatable-buttons thead');
$('#datatable-buttons thead tr:eq(1) th').each(function(i) {
var title = $(this).text();
// For non-"Invoice Date" columns, add a dropdown
var uniqueValues = table.column(i).data().unique().sort();
var select = $('<select class="form-control form-control-sm"><option value="">Search ' + title + '</option></select>')
.appendTo($(this).empty())
.on('change', function() {
var val = $.fn.dataTable.util.escapeRegex($(this).val());
table.column(i)
.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
uniqueValues.each(function(d, j) {
select.append('<option value="' + d + '">' + d + '</option>');
});
$('input', this).on('keyup change', function() {
if (table.column(i).search() !== this.value) {
table
.column(i)
.search(this.value)
.draw();
}
});
});
// Add date range filter for "Invoice Date" column
// Set the default date format for moment.js globally
// Set the default date format for moment.js globally
moment.updateLocale('en', {
longDateFormat: {
L: 'DD/MM/YYYY',
// LTS: 'h:mm:ss A',
// LTS: 'h:mm A',
}
});
$(document).ready(function () {
var $select_data = '<?php echo $selected_data; ?>';
var dateRangeFilter = $('input.input-daterange-datepicker')
.daterangepicker({
locale: {
format: 'DD/MM/YYYY',
cancelLabel: 'Clear'
},
startDate: $select_data ? moment($select_data.split(' - ')[0], 'DD/MM/YYYY') : moment(),
endDate: $select_data ? moment($select_data.split(' - ')[1], 'DD/MM/YYYY') : moment(),
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'This Month': [moment().startOf('month'), moment().endOf('month')]
}
})
.on('apply.daterangepicker', function (ev, picker) {
var formattedStartDate = picker.startDate.format('DD/MM/YYYY');
var formattedEndDate = picker.endDate.format('DD/MM/YYYY');
var selectedDateRange = formattedStartDate + ' - ' + formattedEndDate;
$(this).val(selectedDateRange);
})
.on('cancel.daterangepicker', function () {
$(this).val('');
});
$('.today-btn').on('click', function () {
var today = moment();
dateRangeFilter.data('daterangepicker').setStartDate(today);
dateRangeFilter.data('daterangepicker').setEndDate(today);
dateRangeFilter.val(today.format('DD/MM/YYYY') + ' - ' + today.format('DD/MM/YYYY'));
dateRangeFilter.trigger('apply.daterangepicker');
});
// Trigger "Today" button click to set it as default if $select_data is empty
if ($select_data === '') {
$('.today-btn').trigger('click');
}
});
});
</script>