mirror of
https://github.com/itflow-org/itflow
synced 2026-03-01 11:24:52 +00:00
Merged Client Invoices and Invoices into one file using logic at the header to seperate between client and global section
This commit is contained in:
@@ -1,230 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// Default Column Sortby Filter
|
|
||||||
$sort = "invoice_number";
|
|
||||||
$order = "DESC";
|
|
||||||
|
|
||||||
require_once "includes/inc_all_client.php";
|
|
||||||
|
|
||||||
// Perms
|
|
||||||
enforceUserPermission('module_sales');
|
|
||||||
|
|
||||||
//Rebuild URL
|
|
||||||
$url_query_strings_sort = http_build_query($get_copy);
|
|
||||||
|
|
||||||
$sql = mysqli_query(
|
|
||||||
$mysqli,
|
|
||||||
"SELECT SQL_CALC_FOUND_ROWS * FROM invoices
|
|
||||||
LEFT JOIN categories ON invoice_category_id = category_id
|
|
||||||
WHERE invoice_client_id = $client_id
|
|
||||||
AND (CONCAT(invoice_prefix,invoice_number) LIKE '%$q%' OR invoice_scope LIKE '%$q%' OR category_name LIKE '%$q%' OR invoice_status LIKE '%$q%' OR invoice_amount LIKE '%$q%')
|
|
||||||
ORDER BY $sort $order LIMIT $record_from, $record_to"
|
|
||||||
);
|
|
||||||
|
|
||||||
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
||||||
<div class="card card-dark">
|
|
||||||
<div class="card-header py-2">
|
|
||||||
<h3 class="card-title mt-2"><i class="fa fa-fw fa-file-invoice mr-2"></i>Invoices</h3>
|
|
||||||
<div class="card-tools">
|
|
||||||
<div class="btn-group">
|
|
||||||
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addInvoiceModal"><i class="fas fa-plus mr-2"></i>New Invoice</button>
|
|
||||||
<?php if ($num_rows[0] > 0) { ?>
|
|
||||||
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown"></button>
|
|
||||||
<div class="dropdown-menu">
|
|
||||||
<a class="dropdown-item text-dark" href="#" data-toggle="modal" data-target="#exportInvoiceModal">
|
|
||||||
<i class="fa fa-fw fa-download mr-2"></i>Export
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<?php } ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="card-body">
|
|
||||||
<form autocomplete="off">
|
|
||||||
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
|
|
||||||
<div class="row">
|
|
||||||
|
|
||||||
<div class="col-md-4">
|
|
||||||
<div class="input-group mb-3 mb-md-0">
|
|
||||||
<input type="search" class="form-control" name="q"
|
|
||||||
value="<?php if (isset($q)) {echo stripslashes(nullable_htmlentities($q)); } ?>"
|
|
||||||
placeholder="Search Invoices"
|
|
||||||
>
|
|
||||||
<div class="input-group-append">
|
|
||||||
<button class="btn btn-dark"><i class="fa fa-search"></i></button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-md-8">
|
|
||||||
<div class="float-right">
|
|
||||||
<div class="btn-group float-right">
|
|
||||||
<?php if ($balance > 0) { ?>
|
|
||||||
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#addBulkPaymentModal"><i class="fa fa-credit-card mr-2"></i>Batch Payment</button>
|
|
||||||
<?php } ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
<hr>
|
|
||||||
<div class="table-responsive-sm">
|
|
||||||
<table class="table table-striped table-borderless table-hover">
|
|
||||||
<thead class="text-dark <?php if ($num_rows[0] == 0) { echo "d-none"; } ?>">
|
|
||||||
<tr>
|
|
||||||
<th>
|
|
||||||
<a class="text-secondary" href="?<?php echo $url_query_strings_sort; ?>&sort=invoice_number&order=<?php echo $disp; ?>">
|
|
||||||
Number <?php if ($sort == 'invoice_number') { echo $order_icon; } ?>
|
|
||||||
</a>
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
<a class="text-secondary" href="?<?php echo $url_query_strings_sort; ?>&sort=invoice_scope&order=<?php echo $disp; ?>">
|
|
||||||
Scope <?php if ($sort == 'invoice_scope') { echo $order_icon; } ?>
|
|
||||||
</a>
|
|
||||||
</th>
|
|
||||||
<th class="text-right">
|
|
||||||
<a class="text-secondary" href="?<?php echo $url_query_strings_sort; ?>&sort=invoice_amount&order=<?php echo $disp; ?>">
|
|
||||||
Amount <?php if ($sort == 'invoice_amount') { echo $order_icon; } ?>
|
|
||||||
</a>
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
<a class="text-secondary" href="?<?php echo $url_query_strings_sort; ?>&sort=invoice_date&order=<?php echo $disp; ?>">
|
|
||||||
Date <?php if ($sort == 'invoice_date') { echo $order_icon; } ?>
|
|
||||||
</a>
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
<a class="text-secondary" href="?<?php echo $url_query_strings_sort; ?>&sort=invoice_due&order=<?php echo $disp; ?>">
|
|
||||||
Due <?php if ($sort == 'invoice_due') { echo $order_icon; } ?>
|
|
||||||
</a>
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
<a class="text-secondary" href="?<?php echo $url_query_strings_sort; ?>&sort=category_name&order=<?php echo $disp; ?>">
|
|
||||||
Category <?php if ($sort == 'category_name') { echo $order_icon; } ?>
|
|
||||||
</a>
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
<a class="text-secondary" href="?<?php echo $url_query_strings_sort; ?>&sort=invoice_status&order=<?php echo $disp; ?>">
|
|
||||||
Status <?php if ($sort == 'invoice_status') { echo $order_icon; } ?>
|
|
||||||
</a>
|
|
||||||
</th>
|
|
||||||
<th class="text-center">Action</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<?php
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($sql)) {
|
|
||||||
$invoice_id = intval($row['invoice_id']);
|
|
||||||
$invoice_prefix = nullable_htmlentities($row['invoice_prefix']);
|
|
||||||
$invoice_number = nullable_htmlentities($row['invoice_number']);
|
|
||||||
$invoice_scope = nullable_htmlentities($row['invoice_scope']);
|
|
||||||
if (empty($invoice_scope)) {
|
|
||||||
$invoice_scope_display = "-";
|
|
||||||
} else {
|
|
||||||
$invoice_scope_display = $invoice_scope;
|
|
||||||
}
|
|
||||||
$invoice_status = nullable_htmlentities($row['invoice_status']);
|
|
||||||
$invoice_date = nullable_htmlentities($row['invoice_date']);
|
|
||||||
$invoice_due = nullable_htmlentities($row['invoice_due']);
|
|
||||||
$invoice_discount = floatval($row['invoice_discount_amount']);
|
|
||||||
$invoice_amount = floatval($row['invoice_amount']);
|
|
||||||
$invoice_currency_code = nullable_htmlentities($row['invoice_currency_code']);
|
|
||||||
$invoice_created_at = nullable_htmlentities($row['invoice_created_at']);
|
|
||||||
$category_id = intval($row['category_id']);
|
|
||||||
$category_name = nullable_htmlentities($row['category_name']);
|
|
||||||
|
|
||||||
if (($invoice_status == "Sent" || $invoice_status == "Partial" || $invoice_status == "Viewed") && strtotime($invoice_due) < time()) {
|
|
||||||
$overdue_color = "text-danger font-weight-bold";
|
|
||||||
} else {
|
|
||||||
$overdue_color = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
//Set Badge color based off of invoice status
|
|
||||||
if ($invoice_status == "Sent") {
|
|
||||||
$invoice_badge_color = "warning";
|
|
||||||
} elseif ($invoice_status == "Viewed") {
|
|
||||||
$invoice_badge_color = "info";
|
|
||||||
} elseif ($invoice_status == "Partial") {
|
|
||||||
$invoice_badge_color = "primary";
|
|
||||||
} elseif ($invoice_status == "Paid") {
|
|
||||||
$invoice_badge_color = "success";
|
|
||||||
} elseif ($invoice_status == "Cancelled") {
|
|
||||||
$invoice_badge_color = "danger";
|
|
||||||
} else {
|
|
||||||
$invoice_badge_color = "secondary";
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td class="text-bold"><a href="invoice.php?client_id=<?php echo $client_id; ?>&invoice_id=<?php echo $invoice_id; ?>"><?php echo "$invoice_prefix$invoice_number"; ?></a></td>
|
|
||||||
<td><?php echo $invoice_scope_display; ?></td>
|
|
||||||
<td class="text-bold text-right"><?php echo numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code); ?></td>
|
|
||||||
<td><?php echo $invoice_date; ?></td>
|
|
||||||
<td>
|
|
||||||
<div class="<?php echo $overdue_color; ?>"><?php echo $invoice_due; ?></div>
|
|
||||||
</td>
|
|
||||||
<td><?php echo $category_name; ?></td>
|
|
||||||
<td>
|
|
||||||
<span class="p-2 badge badge-<?php echo $invoice_badge_color; ?>">
|
|
||||||
<?php echo $invoice_status; ?>
|
|
||||||
</span>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<div class="dropdown dropleft text-center">
|
|
||||||
<button class="btn btn-secondary btn-sm" type="button" data-toggle="dropdown">
|
|
||||||
<i class="fas fa-ellipsis-h"></i>
|
|
||||||
</button>
|
|
||||||
<div class="dropdown-menu">
|
|
||||||
<?php if (!empty($config_smtp_host)) { ?>
|
|
||||||
<a class="dropdown-item" href="post.php?email_invoice=<?php echo $invoice_id; ?>">
|
|
||||||
<i class="fas fa-fw fa-paper-plane mr-2"></i>Send
|
|
||||||
</a>
|
|
||||||
<div class="dropdown-divider"></div>
|
|
||||||
<?php } ?>
|
|
||||||
<a class="dropdown-item" href="#"
|
|
||||||
data-toggle = "ajax-modal"
|
|
||||||
data-ajax-url = "ajax/ajax_invoice_edit.php"
|
|
||||||
data-ajax-id = "<?php echo $invoice_id; ?>"
|
|
||||||
>
|
|
||||||
<i class="fas fa-fw fa-edit mr-2"></i>Edit
|
|
||||||
</a>
|
|
||||||
<a class="dropdown-item" href="#"
|
|
||||||
data-toggle = "ajax-modal"
|
|
||||||
data-ajax-url = "ajax/ajax_invoice_copy.php"
|
|
||||||
data-ajax-id = "<?php echo $invoice_id; ?>"
|
|
||||||
>
|
|
||||||
<i class="fas fa-fw fa-copy mr-2"></i>Copy
|
|
||||||
</a>
|
|
||||||
<div class="dropdown-divider"></div>
|
|
||||||
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_invoice=<?php echo $invoice_id; ?>">
|
|
||||||
<i class="fas fa-fw fa-trash mr-2"></i>Delete
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<?php
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<?php require_once "includes/filter_footer.php";
|
|
||||||
?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php
|
|
||||||
require_once "modals/invoice_add_modal.php";
|
|
||||||
require_once "modals/invoice_payment_add_bulk_modal.php";
|
|
||||||
require_once "modals/client_invoice_export_modal.php";
|
|
||||||
require_once "includes/footer.php";
|
|
||||||
@@ -259,7 +259,7 @@
|
|||||||
<?php if (lookupUserPermission("module_sales") >= 1) { ?>
|
<?php if (lookupUserPermission("module_sales") >= 1) { ?>
|
||||||
|
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a href="client_invoices.php?client_id=<?php echo $client_id; ?>" class="nav-link <?php if (basename($_SERVER["PHP_SELF"]) == "client_invoices.php" || basename($_SERVER["PHP_SELF"]) == "invoice.php") { echo "active"; } ?>">
|
<a href="invoices.php?client_id=<?php echo $client_id; ?>" class="nav-link <?php if (basename($_SERVER["PHP_SELF"]) == "invoices.php" || basename($_SERVER["PHP_SELF"]) == "invoice.php") { echo "active"; } ?>">
|
||||||
<i class="nav-icon fas fa-file-invoice"></i>
|
<i class="nav-icon fas fa-file-invoice"></i>
|
||||||
<p>
|
<p>
|
||||||
Invoices
|
Invoices
|
||||||
|
|||||||
@@ -164,14 +164,14 @@ if (isset($_GET['invoice_id'])) {
|
|||||||
<a href="client_overview.php?client_id=<?php echo $client_id; ?>"><?php echo $client_name; ?></a>
|
<a href="client_overview.php?client_id=<?php echo $client_id; ?>"><?php echo $client_name; ?></a>
|
||||||
</li>
|
</li>
|
||||||
<li class="breadcrumb-item">
|
<li class="breadcrumb-item">
|
||||||
<a href="client_invoices.php?client_id=<?php echo $client_id; ?>">Invoices</a>
|
<a href="invoices.php?client_id=<?php echo $client_id; ?>">Invoices</a>
|
||||||
</li>
|
</li>
|
||||||
<?php } else { ?>
|
<?php } else { ?>
|
||||||
<li class="breadcrumb-item">
|
<li class="breadcrumb-item">
|
||||||
<a href="invoices.php">Invoices</a>
|
<a href="invoices.php">Invoices</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="breadcrumb-item">
|
<li class="breadcrumb-item">
|
||||||
<a href="client_invoices.php?client_id=<?php echo $client_id; ?>"><?php echo $client_name; ?></a>
|
<a href="invoices.php?client_id=<?php echo $client_id; ?>"><?php echo $client_name; ?></a>
|
||||||
</li>
|
</li>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<li class="breadcrumb-item active"><?php echo "$invoice_prefix$invoice_number"; ?></li>
|
<li class="breadcrumb-item active"><?php echo "$invoice_prefix$invoice_number"; ?></li>
|
||||||
|
|||||||
45
invoices.php
45
invoices.php
@@ -4,55 +4,62 @@
|
|||||||
$sort = "invoice_number";
|
$sort = "invoice_number";
|
||||||
$order = "DESC";
|
$order = "DESC";
|
||||||
|
|
||||||
require_once "includes/inc_all.php";
|
// If client_id is in URI then show client Side Bar and client header
|
||||||
|
if (isset($_GET['client_id'])) {
|
||||||
|
require_once "includes/inc_all_client.php";
|
||||||
|
$client_query = "AND invoice_client_id = $client_id";
|
||||||
|
} else {
|
||||||
|
require_once "includes/inc_all.php";
|
||||||
|
$client_query = '';
|
||||||
|
}
|
||||||
|
|
||||||
// Perms
|
// Perms
|
||||||
enforceUserPermission('module_sales');
|
enforceUserPermission('module_sales');
|
||||||
|
|
||||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Sent'"));
|
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Sent' $client_query"));
|
||||||
$sent_count = $row['num'];
|
$sent_count = $row['num'];
|
||||||
|
|
||||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Viewed'"));
|
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Viewed' $client_query"));
|
||||||
$viewed_count = $row['num'];
|
$viewed_count = $row['num'];
|
||||||
|
|
||||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Partial'"));
|
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Partial' $client_query"));
|
||||||
$partial_count = $row['num'];
|
$partial_count = $row['num'];
|
||||||
|
|
||||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Draft'"));
|
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Draft' $client_query"));
|
||||||
$draft_count = $row['num'];
|
$draft_count = $row['num'];
|
||||||
|
|
||||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Cancelled'"));
|
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status = 'Cancelled' $client_query"));
|
||||||
$cancelled_count = $row['num'];
|
$cancelled_count = $row['num'];
|
||||||
|
|
||||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Paid' AND invoice_status NOT LIKE 'Cancelled' AND invoice_due < CURDATE()"));
|
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Paid' AND invoice_status NOT LIKE 'Cancelled' AND invoice_due < CURDATE() $client_query"));
|
||||||
$overdue_count = $row['num'];
|
$overdue_count = $row['num'];
|
||||||
|
|
||||||
$sql_total_draft_amount = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_draft_amount FROM invoices WHERE invoice_status = 'Draft'");
|
$sql_total_draft_amount = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_draft_amount FROM invoices WHERE invoice_status = 'Draft' $client_query");
|
||||||
$row = mysqli_fetch_array($sql_total_draft_amount);
|
$row = mysqli_fetch_array($sql_total_draft_amount);
|
||||||
$total_draft_amount = floatval($row['total_draft_amount']);
|
$total_draft_amount = floatval($row['total_draft_amount']);
|
||||||
|
|
||||||
$sql_total_sent_amount = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_sent_amount FROM invoices WHERE invoice_status = 'Sent'");
|
$sql_total_sent_amount = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_sent_amount FROM invoices WHERE invoice_status = 'Sent' $client_query");
|
||||||
$row = mysqli_fetch_array($sql_total_sent_amount);
|
$row = mysqli_fetch_array($sql_total_sent_amount);
|
||||||
$total_sent_amount = floatval($row['total_sent_amount']);
|
$total_sent_amount = floatval($row['total_sent_amount']);
|
||||||
|
|
||||||
$sql_total_viewed_amount = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_viewed_amount FROM invoices WHERE invoice_status = 'Viewed'");
|
$sql_total_viewed_amount = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_viewed_amount FROM invoices WHERE invoice_status = 'Viewed' $client_query");
|
||||||
$row = mysqli_fetch_array($sql_total_viewed_amount);
|
$row = mysqli_fetch_array($sql_total_viewed_amount);
|
||||||
$total_viewed_amount = floatval($row['total_viewed_amount']);
|
$total_viewed_amount = floatval($row['total_viewed_amount']);
|
||||||
|
|
||||||
$sql_total_cancelled_amount = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_cancelled_amount FROM invoices WHERE invoice_status = 'Cancelled'");
|
$sql_total_cancelled_amount = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_cancelled_amount FROM invoices WHERE invoice_status = 'Cancelled' $client_query");
|
||||||
$row = mysqli_fetch_array($sql_total_cancelled_amount);
|
$row = mysqli_fetch_array($sql_total_cancelled_amount);
|
||||||
$total_cancelled_amount = floatval($row['total_cancelled_amount']);
|
$total_cancelled_amount = floatval($row['total_cancelled_amount']);
|
||||||
|
|
||||||
$sql_total_partial_amount = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_partial_amount FROM payments, invoices WHERE payment_invoice_id = invoice_id AND invoice_status = 'Partial'");
|
$sql_total_partial_amount = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_partial_amount FROM payments, invoices WHERE payment_invoice_id = invoice_id AND invoice_status = 'Partial' $client_query");
|
||||||
$row = mysqli_fetch_array($sql_total_partial_amount);
|
$row = mysqli_fetch_array($sql_total_partial_amount);
|
||||||
$total_partial_amount = floatval($row['total_partial_amount']);
|
$total_partial_amount = floatval($row['total_partial_amount']);
|
||||||
$total_partial_count = mysqli_num_rows($sql_total_partial_amount);
|
$total_partial_count = mysqli_num_rows($sql_total_partial_amount);
|
||||||
|
|
||||||
$sql_total_overdue_partial_amount = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_overdue_partial_amount FROM payments, invoices WHERE payment_invoice_id = invoice_id AND invoice_status = 'Partial' AND invoice_due < CURDATE()");
|
$sql_total_overdue_partial_amount = mysqli_query($mysqli, "SELECT SUM(payment_amount) AS total_overdue_partial_amount FROM payments, invoices WHERE payment_invoice_id = invoice_id AND invoice_status = 'Partial' AND invoice_due < CURDATE() $client_query");
|
||||||
$row = mysqli_fetch_array($sql_total_overdue_partial_amount);
|
$row = mysqli_fetch_array($sql_total_overdue_partial_amount);
|
||||||
$total_overdue_partial_amount = floatval($row['total_overdue_partial_amount']);
|
$total_overdue_partial_amount = floatval($row['total_overdue_partial_amount']);
|
||||||
|
|
||||||
$sql_total_overdue_amount = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_overdue_amount FROM invoices WHERE invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Paid' AND invoice_status NOT LIKE 'Cancelled' AND invoice_due < CURDATE()");
|
$sql_total_overdue_amount = mysqli_query($mysqli, "SELECT SUM(invoice_amount) AS total_overdue_amount FROM invoices WHERE invoice_status NOT LIKE 'Draft' AND invoice_status NOT LIKE 'Paid' AND invoice_status NOT LIKE 'Cancelled' AND invoice_due < CURDATE() $client_query");
|
||||||
$row = mysqli_fetch_array($sql_total_overdue_amount);
|
$row = mysqli_fetch_array($sql_total_overdue_amount);
|
||||||
$total_overdue_amount = floatval($row['total_overdue_amount']);
|
$total_overdue_amount = floatval($row['total_overdue_amount']);
|
||||||
|
|
||||||
@@ -85,6 +92,7 @@ $sql = mysqli_query(
|
|||||||
$overdue_query
|
$overdue_query
|
||||||
AND DATE(invoice_date) BETWEEN '$dtf' AND '$dtt'
|
AND DATE(invoice_date) BETWEEN '$dtf' AND '$dtt'
|
||||||
AND (CONCAT(invoice_prefix,invoice_number) LIKE '%$q%' OR invoice_scope LIKE '%$q%' OR client_name LIKE '%$q%' OR invoice_status LIKE '%$q%' OR invoice_amount LIKE '%$q%' OR category_name LIKE '%$q%')
|
AND (CONCAT(invoice_prefix,invoice_number) LIKE '%$q%' OR invoice_scope LIKE '%$q%' OR client_name LIKE '%$q%' OR invoice_status LIKE '%$q%' OR invoice_amount LIKE '%$q%' OR category_name LIKE '%$q%')
|
||||||
|
$client_query
|
||||||
ORDER BY $sort $order LIMIT $record_from, $record_to"
|
ORDER BY $sort $order LIMIT $record_from, $record_to"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -156,6 +164,9 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
|||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form class="mb-4" autocomplete="off">
|
<form class="mb-4" autocomplete="off">
|
||||||
<input type="hidden" name="status" value="<?php if (isset($_GET['status'])) { echo nullable_htmlentities($_GET['status']); } ?>">
|
<input type="hidden" name="status" value="<?php if (isset($_GET['status'])) { echo nullable_htmlentities($_GET['status']); } ?>">
|
||||||
|
<?php if(isset($_GET['client_id'])) { ?>
|
||||||
|
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
|
||||||
|
<?php } ?>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-4">
|
<div class="col-sm-4">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
@@ -219,11 +230,13 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
|||||||
Scope <?php if ($sort == 'invoice_scope') { echo $order_icon; } ?>
|
Scope <?php if ($sort == 'invoice_scope') { echo $order_icon; } ?>
|
||||||
</a>
|
</a>
|
||||||
</th>
|
</th>
|
||||||
|
<?php if(!isset($_GET['client_id'])) { ?>
|
||||||
<th>
|
<th>
|
||||||
<a class="text-dark" href="?<?php echo $url_query_strings_sort; ?>&sort=client_name&order=<?php echo $disp; ?>">
|
<a class="text-dark" href="?<?php echo $url_query_strings_sort; ?>&sort=client_name&order=<?php echo $disp; ?>">
|
||||||
Client <?php if ($sort == 'client_name') { echo $order_icon; } ?>
|
Client <?php if ($sort == 'client_name') { echo $order_icon; } ?>
|
||||||
</a>
|
</a>
|
||||||
</th>
|
</th>
|
||||||
|
<?php } ?>
|
||||||
<th class="text-right">
|
<th class="text-right">
|
||||||
<a class="text-dark" href="?<?php echo $url_query_strings_sort; ?>&sort=invoice_amount&order=<?php echo $disp; ?>">
|
<a class="text-dark" href="?<?php echo $url_query_strings_sort; ?>&sort=invoice_amount&order=<?php echo $disp; ?>">
|
||||||
Amount <?php if ($sort == 'invoice_amount') { echo $order_icon; } ?>
|
Amount <?php if ($sort == 'invoice_amount') { echo $order_icon; } ?>
|
||||||
@@ -297,7 +310,9 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="text-bold"><a href="invoice.php?invoice_id=<?php echo $invoice_id; ?>"><?php echo "$invoice_prefix$invoice_number"; ?></a></td>
|
<td class="text-bold"><a href="invoice.php?invoice_id=<?php echo $invoice_id; ?>"><?php echo "$invoice_prefix$invoice_number"; ?></a></td>
|
||||||
<td><?php echo $invoice_scope_display; ?></td>
|
<td><?php echo $invoice_scope_display; ?></td>
|
||||||
<td class="text-bold"><a href="client_invoices.php?client_id=<?php echo $client_id; ?>"><?php echo $client_name; ?></a></td>
|
<?php if(!isset($_GET['client_id'])) { ?>
|
||||||
|
<td class="text-bold"><a href="invoices.php?client_id=<?php echo $client_id; ?>"><?php echo $client_name; ?></a></td>
|
||||||
|
<?php } ?>
|
||||||
<td class="text-bold text-right"><?php echo numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code); ?></td>
|
<td class="text-bold text-right"><?php echo numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code); ?></td>
|
||||||
<td><?php echo $invoice_date; ?></td>
|
<td><?php echo $invoice_date; ?></td>
|
||||||
<td class="<?php echo $overdue_color; ?>"><?php echo $invoice_due; ?></td>
|
<td class="<?php echo $overdue_color; ?>"><?php echo $invoice_due; ?></td>
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
<div class="modal" id="exportInvoiceModal" tabindex="-1">
|
|
||||||
<div class="modal-dialog">
|
|
||||||
<div class="modal-content bg-dark">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h5 class="modal-title"><i class="fas fa-fw fa-download mr-2"></i>Export Invoices to CSV</h5>
|
|
||||||
<button type="button" class="close text-white" data-dismiss="modal">
|
|
||||||
<span>×</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<form action="post.php" method="post" autocomplete="off">
|
|
||||||
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
|
|
||||||
<div class="modal-body bg-white">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer bg-white">
|
|
||||||
<button type="submit" name="export_client_invoices_csv" class="btn btn-primary text-bold"><i class="fas fa-fw fa-download mr-2"></i>Download CSV</button>
|
|
||||||
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fas fa-times mr-2"></i>Cancel</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@@ -8,6 +8,9 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<form action="post.php" method="post" autocomplete="off">
|
<form action="post.php" method="post" autocomplete="off">
|
||||||
|
<?php if (isset($_GET['client_id'])) { ?>
|
||||||
|
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
|
||||||
|
<?php } ?>
|
||||||
<div class="modal-body bg-white">
|
<div class="modal-body bg-white">
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|||||||
@@ -1594,54 +1594,14 @@ if (isset($_GET['force_recurring'])) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_POST['export_client_invoices_csv'])) {
|
if (isset($_POST['export_invoices_csv'])) {
|
||||||
$client_id = intval($_POST['client_id']);
|
if (isset($_POST['client_id'])) {
|
||||||
|
$client_id = intval($_POST['client_id']);
|
||||||
//get records from database
|
$client_query = "AND invoice_client_id = $client_id";
|
||||||
$sql = mysqli_query($mysqli,"SELECT client_name FROM clients WHERE client_id = $client_id");
|
} else {
|
||||||
$row = mysqli_fetch_array($sql);
|
$client_query = '';
|
||||||
|
|
||||||
$client_name = $row['client_name'];
|
|
||||||
|
|
||||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices WHERE invoice_client_id = $client_id ORDER BY invoice_number ASC");
|
|
||||||
|
|
||||||
$num_rows = mysqli_num_rows($sql);
|
|
||||||
|
|
||||||
if ($num_rows > 0) {
|
|
||||||
$delimiter = ",";
|
|
||||||
$filename = $client_name . "-Invoices-" . date('Y-m-d') . ".csv";
|
|
||||||
|
|
||||||
//create a file pointer
|
|
||||||
$f = fopen('php://memory', 'w');
|
|
||||||
|
|
||||||
//set column headers
|
|
||||||
$fields = array('Invoice Number', 'Scope', 'Amount', 'Issued Date', 'Due Date', 'Status');
|
|
||||||
fputcsv($f, $fields, $delimiter);
|
|
||||||
|
|
||||||
//output each row of the data, format line as csv and write to file pointer
|
|
||||||
while($row = $sql->fetch_assoc()) {
|
|
||||||
$lineData = array($row['invoice_prefix'] . $row['invoice_number'], $row['invoice_scope'], $row['invoice_amount'], $row['invoice_date'], $row['invoice_due'], $row['invoice_status']);
|
|
||||||
fputcsv($f, $lineData, $delimiter);
|
|
||||||
}
|
|
||||||
|
|
||||||
//move back to beginning of file
|
|
||||||
fseek($f, 0);
|
|
||||||
|
|
||||||
//set headers to download file rather than displayed
|
|
||||||
header('Content-Type: text/csv');
|
|
||||||
header('Content-Disposition: attachment; filename="' . $filename . '";');
|
|
||||||
|
|
||||||
//output all remaining data on a file pointer
|
|
||||||
fpassthru($f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logAction("Invoice", "Export", "$session_name exported $num_rows invoices to CSV file", $client_id);
|
|
||||||
|
|
||||||
exit;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_POST['export_invoices_csv'])) {
|
|
||||||
$date_from = sanitizeInput($_POST['date_from']);
|
$date_from = sanitizeInput($_POST['date_from']);
|
||||||
$date_to = sanitizeInput($_POST['date_to']);
|
$date_to = sanitizeInput($_POST['date_to']);
|
||||||
if (!empty($date_from) && !empty($date_to)) {
|
if (!empty($date_from) && !empty($date_to)) {
|
||||||
@@ -1652,7 +1612,7 @@ if (isset($_POST['export_invoices_csv'])) {
|
|||||||
$file_name_date = date('Y-m-d');
|
$file_name_date = date('Y-m-d');
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = mysqli_query($mysqli,"SELECT * FROM invoices LEFT JOIN clients ON invoice_client_id = client_id WHERE $date_query ORDER BY invoice_number ASC");
|
$sql = mysqli_query($mysqli,"SELECT * FROM invoices LEFT JOIN clients ON invoice_client_id = client_id WHERE $date_query $client_query ORDER BY invoice_number ASC");
|
||||||
|
|
||||||
$row = mysqli_fetch_array($sql);
|
$row = mysqli_fetch_array($sql);
|
||||||
$client_name = $row['client_name'];
|
$client_name = $row['client_name'];
|
||||||
|
|||||||
Reference in New Issue
Block a user