Skip to content

Commit

Permalink
Merge pull request #865 from twetech/v0.1.5
Browse files Browse the repository at this point in the history
Update to V0.1.5
  • Loading branch information
johnnyq authored Jan 11, 2024
2 parents f8757fc + b499b52 commit e69317e
Show file tree
Hide file tree
Showing 5 changed files with 272 additions and 34 deletions.
12 changes: 12 additions & 0 deletions client_tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
$ticket_status_snippet = "ticket_status != 'Closed'";
}

if (isset($_GET['billable']) && ($_GET['billable']) == '1') {
if (isset($_GET['unbilled'])) {
$billable = 1;
$ticket_billable_snippet = "ticket_billable = 1 AND ticket_invoice_id = 0";
$ticket_status_snippet = '1 = 1';
}
} else {
$billable = 0;
$ticket_billable_snippet = '1 = 1';
}

//Rebuild URL
$url_query_strings_sort = http_build_query($get_copy);

Expand All @@ -31,6 +42,7 @@
LEFT JOIN vendors ON ticket_vendor_id = vendor_id
WHERE ticket_client_id = $client_id
AND $ticket_status_snippet
AND $ticket_billable_snippet
AND (CONCAT(ticket_prefix,ticket_number) LIKE '%$q%' OR ticket_subject LIKE '%$q%' OR ticket_status LIKE '%$q%' OR ticket_priority LIKE '%$q%' OR user_name LIKE '%$q%' OR contact_name LIKE '%$q%' OR asset_name LIKE '%$q%' OR vendor_name LIKE '%$q%' OR ticket_vendor_ticket_number LIKE '%q%')
ORDER BY $sort $order LIMIT $record_from, $record_to"
);
Expand Down
41 changes: 26 additions & 15 deletions invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,37 @@
$sql_payments = mysqli_query($mysqli, "SELECT * FROM payments, accounts WHERE payment_account_id = account_id AND payment_invoice_id = $invoice_id ORDER BY payments.payment_id DESC");

$sql_tickets = mysqli_query($mysqli, "
SELECT
tickets.*,
SELECT
tickets.*,
SEC_TO_TIME(SUM(TIME_TO_SEC(STR_TO_DATE(ticket_reply_time_worked, '%H:%i:%s')))) AS 'total_time_worked'
FROM
tickets
LEFT JOIN
ticket_replies ON tickets.ticket_id = ticket_replies.ticket_reply_ticket_id
WHERE
ticket_invoice_id = $invoice_id
GROUP BY
tickets.ticket_id
ORDER BY
FROM
tickets
LEFT JOIN
ticket_replies ON tickets.ticket_id = ticket_replies.ticket_reply_ticket_id
WHERE
ticket_invoice_id = $invoice_id
GROUP BY
tickets.ticket_id
ORDER BY
ticket_id DESC
");

//Get billable, and unbilled tickets to add to invoice
$sql_tickets_billable = mysqli_query($mysqli, "SELECT * FROM tickets WHERE ticket_client_id = $client_id AND ticket_billable = 1 AND ticket_invoice_id = 0;");



$sql_tickets_billable = mysqli_query(
$mysqli, "
SELECT
*
FROM
tickets
WHERE
ticket_client_id = $client_id
AND
ticket_billable = 1
AND
ticket_invoice_id = 0
AND
ticket_status LIKE '%close%';
");


//Add up all the payments for the invoice and get the total amount paid to the invoice
Expand Down
63 changes: 44 additions & 19 deletions invoice_add_ticket_modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,50 @@
<span>&times;</span>
</button>
</div>
<div class="modal->body bg-white">
<table class="table">
<tr>
<th>Ticket Number</th>
<th>Scope</th>
<th></th>
</tr>
<?php while ($row = mysqli_fetch_array($sql_tickets_billable)) {
$ticket_id = intval($row['ticket_id']);
$ticket_subject = nullable_htmlentities($row['ticket_subject']);
?>
<tr>
<td><?php echo $ticket_id?></td>
<td><?php echo $ticket_subject ?></td>
<td></td>
<td><a href='ticket.php?ticket_id=<?php echo $ticket_id?>&invoice_id=<?php echo $invoice_id?>#addInvoiceFromTicketModal'>Add</a></td>
</tr>
<?php } ?>
</table>
<div class="modal-body bg-white">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Ticket Number</th>
<th>Scope</th>
<th>Add to Invoice</th>
</tr>
</thead>
<?php while ($row = mysqli_fetch_array($sql_tickets_billable)) {
$ticket_id = intval($row['ticket_id']);
$ticket_subject = nullable_htmlentities($row['ticket_subject']);
$ticket_number = intval($row['ticket_number']);
$ticket_prefix = nullable_htmlentities($row['ticket_prefix']);
$ticket_status = nullable_htmlentities($row['ticket_status']);

switch ($ticket_status) {
case 'Closed':
$ticket_status_class = 'badge-dark';
break;
case 'Auto Close':
$ticket_status_class = 'badge-warning';
break;
default:
$ticket_status_class = 'badge-secondary';
break;
}


?>
<tr>
<td>
<a href="ticket.php?ticket_id=<?php echo $ticket_id; ?>">
<span class="badge badge-pill <?php echo $ticket_status_class?> p-3"><?php echo "$ticket_prefix$ticket_number"; ?></span>
</a>
</td>
<td><?php echo $ticket_subject ?></td>
<td><a href='ticket.php?ticket_id=<?php echo $ticket_id?>&invoice_id=<?php echo $invoice_id?>#addInvoiceFromTicketModal'>
<i class="fas fa-fw fa-plus-circle"></i></td>
</tr>
<?php } ?>
</table>
</div>
</div>
</div>
</div>
Expand Down
183 changes: 183 additions & 0 deletions report_tickets_unbilled.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
<?php

require_once "inc_all_reports.php";

validateTechRole();
validateAccountantRole();

function secondsToTime($inputSeconds) {
$secondsInAMinute = 60;
$secondsInAnHour = 60 * $secondsInAMinute;
$secondsInADay = 24 * $secondsInAnHour;

// Extract days
$days = floor($inputSeconds / $secondsInADay);

// Extract hours
$hourSeconds = $inputSeconds % $secondsInADay;
$hours = floor($hourSeconds / $secondsInAnHour);

// Extract minutes
$minuteSeconds = $hourSeconds % $secondsInAnHour;
$minutes = floor($minuteSeconds / $secondsInAMinute);

// Extract the remaining seconds
$remainingSeconds = $minuteSeconds % $secondsInAMinute;
$seconds = ceil($remainingSeconds);

// Format and return
$timeParts = [];
$sections = [
'day' => (int)$days,
'hour' => (int)$hours,
'minute' => (int)$minutes,
'second' => (int)$seconds,
];

foreach ($sections as $name => $value){
if ($value > 0){
$timeParts[] = $value. ' '.$name.($value == 1 ? '' : 's');
}
}

return implode(', ', $timeParts);
}

if (isset($_GET['year'])) {
$year = intval($_GET['year']);
} else {
$year = date('Y');
}

$sql_ticket_years = mysqli_query($mysqli, "SELECT DISTINCT YEAR(ticket_created_at) AS ticket_year FROM tickets ORDER BY ticket_year DESC");

$sql_clients = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients ORDER BY client_name ASC");

$rows = 0;


?>

<div class="card card-dark">
<div class="card-header py-2">
<h3 class="card-title mt-2"><i class="fas fa-fw fa-life-ring mr-2"></i>Unbilled Tickets By Client</h3>
<div class="card-tools">
<button type="button" class="btn btn-primary d-print-none" onclick="window.print();"><i class="fas fa-fw fa-print mr-2"></i>Print</button>
</div>
</div>
<div class="card-body">
<form class="mb-3">
<select onchange="this.form.submit()" class="form-control" name="year">
<?php
while ($row = mysqli_fetch_array($sql_ticket_years)) {
$ticket_year = intval($row['ticket_year']); ?>
<option <?php if ($year == $ticket_year) { ?> selected <?php } ?> > <?php echo $ticket_year; ?></option>
<?php } ?>
</select>
</form>

<div class="table-responsive-sm">
<table class="table table-striped">
<thead>
<tr>
<th>Client</th>
<th class="text-right">Tickets Raised</th>
<th class="text-right">Billable Tickets</th>
<th class="text-right">Unbilled Tickets</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_array($sql_clients)) {
$client_id = intval($row['client_id']);
$client_name = nullable_htmlentities($row['client_name']);

// Calculate total tickets raised in period
$sql_ticket_raised_count = mysqli_query(
$mysqli,
"SELECT
COUNT(ticket_id) AS ticket_raised_count
FROM
tickets
WHERE
YEAR(ticket_created_at) = $year
AND
ticket_client_id = $client_id"
);
$row = mysqli_fetch_array($sql_ticket_raised_count);
$ticket_raised_count = intval($row['ticket_raised_count']);

// Calculate total tickets raised in period that are closed and billable
$sql_ticket_closed_count = mysqli_query(
$mysqli,
"SELECT
COUNT(ticket_id) AS ticket_closed_count
FROM
tickets
WHERE
YEAR(ticket_created_at) = $year
AND
ticket_client_id = $client_id
AND
ticket_status = 'Closed'
AND
ticket_billable = 1
");
$row = mysqli_fetch_array($sql_ticket_closed_count);
$ticket_closed_count = intval($row['ticket_closed_count']);

// Calculate total tickets raised in period that are closed and billable, but not invoiced
$sql_ticket_unbilled_count = mysqli_query(
$mysqli,
"SELECT
COUNT(ticket_id) AS ticket_unbilled_count
FROM
tickets
WHERE
YEAR(ticket_created_at) = $year
AND
ticket_client_id = $client_id
AND
ticket_status = 'Closed'
AND
ticket_billable = 1
AND
ticket_invoice_id = 0");
$row = mysqli_fetch_array($sql_ticket_unbilled_count);
$ticket_unbilled_count = intval($row['ticket_unbilled_count']);

if ($ticket_unbilled_count > 0) {
$rows = $rows + 1;

?>

<tr>
<td>
<a href="client_tickets.php?client_id=<?php echo $client_id; ?>&billable=1&unbilled"><?php echo $client_name; ?></a>
</td>
<td class="text-right"><?php echo $ticket_raised_count; ?></td>
<td class="text-right"><?php echo $ticket_closed_count; ?></td>
<td class="text-right"><?php echo $ticket_unbilled_count; ?></td>
</tr>
<?php
}
}

if ($rows == 0) {
?>
<tr>
<td colspan="4">You are all caught up! There are no unbilled tickets for this year.
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>

<?php
require_once "footer.php";

7 changes: 7 additions & 0 deletions reports_side_nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
<p>Collections</p>
</a>
</li>
<li class="nav-item">
<a href="report_tickets_unbilled.php" class="nav-link <?php if (basename($_SERVER["PHP_SELF"]) == "report_tickets_unbilled.php") { echo "active"; } ?>">
<i class="nav-icon fas fa-life-ring"></i>
<p>Unbilled Tickets</p>
</a>
</li>
<?php } // End financial reports IF statement ?>

<?php if ($session_user_role == 2 || $session_user_role == 3) { ?>
Expand All @@ -92,6 +98,7 @@
<p>Tickets</p>
</a>
</li>

<li class="nav-item">
<a href="report_ticket_by_client.php" class="nav-link <?php if (basename($_SERVER["PHP_SELF"]) == "report_ticket_by_client.php") { echo "active"; } ?>">
<i class="nav-icon fas fa-life-ring"></i>
Expand Down

0 comments on commit e69317e

Please sign in to comment.