Просмотр исходного кода

Adds amount played and travel costs to invoice.

Alan Lam 8 лет назад
Родитель
Сommit
06ad08a850

+ 32 - 5
controllers/test_invoice.php

@@ -8,10 +8,17 @@ if(Core::$user->id != $test->tester_id && !Core::$user->canAdmin()) throw new Ex
 $project = $test->getProject();
 $location = $test->getLocation();
 $tester = $test->getTester();
+$values = $test->getValues(true);
 
 $location_address = $location->name . ", " . $location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]);
 
-$fee = !empty($test->test_fee) ? $test->test_fee : $project->default_tester_fee;
+$fee = floatval($test->test_fee) > 0 ? $test->test_fee : $project->default_tester_fee;
+$fee = (float) $fee;
+
+$play_spent = (float) ($values["play_spent"] ?? 0);
+$travel_cost = (float) http::value("travel_cost", "float");
+
+$invoice_total = $fee + $play_spent + $travel_cost;
 
 $address = $tester->getInvoiceAddress();
 if(!$address) throw new Exception("Invoice address not found. Please set an address as the invoice address then try again.");
@@ -91,7 +98,7 @@ $pdf->Cell(45, 8, date("d/m/Y", time() + 2592000), 0, 1, "R");
 $pdf->Rect(110, $pdf->GetY(), 90, 8, "F");
 $pdf->Cell(45, 8, "Balance Due:", 0, 0, "R");
 $pdf->SetTextColor(0);
-$pdf->Cell(45, 8, utf8_decode("£") . number_format($fee, 2), 0, 1, "R");
+$pdf->Cell(45, 8, utf8_decode("£") . number_format($invoice_total, 2), 0, 1, "R");
 
 // Left addresses
 $pdf->SetXY(10, 10);
@@ -141,16 +148,36 @@ $pdf->Cell(30, 5, utf8_decode("£") . number_format($fee, 2), 0, 0, "R");
 $pdf->Cell(30, 5, utf8_decode("£") . number_format($fee, 2), 0, 0, "R");
 $pdf->SetXY(10, $next_y);
 
-// TODO: Amount Spent field
+if($play_spent) {
+	$pdf->MoveY(5);
+	$y = $pdf->GetY();
+	$pdf->MultiCell(115, 5, "Play Costs", 0, "L");
+	$next_y = $pdf->GetY();
+	$pdf->SetXY(125, $y);
+	$pdf->Cell(15, 5, 1, 0, 0, "R");
+	$pdf->Cell(30, 5, utf8_decode("£") . number_format($play_spent, 2), 0, 0, "R");
+	$pdf->Cell(30, 5, utf8_decode("£") . number_format($play_spent, 2), 0, 0, "R");
+	$pdf->SetXY(10, $next_y);
+}
 
-// TODO: Travel costs
+if($travel_cost) {
+	$pdf->MoveY(5);
+	$y = $pdf->GetY();
+	$pdf->MultiCell(115, 5, "Travel Costs", 0, "L");
+	$next_y = $pdf->GetY();
+	$pdf->SetXY(125, $y);
+	$pdf->Cell(15, 5, 1, 0, 0, "R");
+	$pdf->Cell(30, 5, utf8_decode("£") . number_format($travel_cost, 2), 0, 0, "R");
+	$pdf->Cell(30, 5, utf8_decode("£") . number_format($travel_cost, 2), 0, 0, "R");
+	$pdf->SetXY(10, $next_y);
+}
 
 $pdf->MoveY(10);
 
 $pdf->SetTextColor(128);
 $pdf->Cell(150, 5, "Total:", 0, 0, "R");
 $pdf->SetTextColor(0);
-$pdf->Cell(40, 5, utf8_decode("£") . number_format($fee, 2), 0, 1, "R");
+$pdf->Cell(40, 5, utf8_decode("£") . number_format($invoice_total, 2), 0, 1, "R");
 
 $pdf->MoveY(10);
 

+ 3 - 0
controllers/tests_completed.php

@@ -1,5 +1,7 @@
 <?php
 
+Core::addScript("public/js/app-completed-tests.js");
+
 $page_title = "Completed Tests";
 
 Core::addBreadcrumb("/account", "Account");
@@ -16,6 +18,7 @@ Core::$page_count = $pagination_object->pageCount;
 
 View::includeOnce("header", compact("page_title"));
 View::include("test_list_completed", compact("tests", "pagination_object"));
+View::include("modal_test_invoice", compact("tests", "pagination_object"));
 View::includeOnce("footer");
 
 ?>

+ 12 - 0
public/js/app-completed-tests.js

@@ -0,0 +1,12 @@
+$(function() {
+
+	$("#modal-test-invoice").on("show.bs.modal", function(event) {
+		var a = $(event.relatedTarget);
+		var id = $(a).data("id");
+
+		$(this).find("form").attr("action", "/account/tests/" + id + "/invoice");
+		$(this).find("input[name=travel_cost]").val("0.00");
+
+	});
+
+});

+ 36 - 0
views/modal_test_invoice.php

@@ -0,0 +1,36 @@
+<div class="modal fade" id="modal-test-invoice" tabindex="-1" role="dialog">
+	<div class="modal-dialog modal-lg" role="document">
+		<div class="modal-content">
+			<form method="get" action="" target="_blank">
+
+				<div class="modal-header">
+					<h5 class="modal-title"><strong>Generate Invoice</strong></h5>
+					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
+						<span aria-hidden="true">&times;</span>
+					</button>
+				</div>
+				<div class="modal-body">
+					<div class="row mb-3">
+						<div class="col-sm-4 col-form-label">
+							<label for="travel-cost">Travel Costs</label>
+						</div>
+						<div class="col-sm">
+							<div class="input-group">
+								<div class="input-group-prepend">
+									<span class="input-group-text">£</span>
+								</div>
+								<input class="form-control" type="number" step="0.01" min="0" name="travel_cost" id="travel-cost" value="0.00" />
+							</div>
+							<small class="form-text text-muted">You may be contacted for verification purposes.</small>
+						</div>
+					</div>
+					<div class="row">
+						<div class="col-sm offset-sm-4">
+							<button class="btn btn-primary" type="submit">Generate Invoice</button>
+						</div>
+					</div>
+				</div>
+			</form>
+		</div>
+	</div>
+</div>

+ 1 - 1
views/test_list_completed.php

@@ -84,7 +84,7 @@
 									<?php
 									if($test->status == Test::STATUS_COMPLETED) {
 										?>
-										<a href="/account/tests/<?=$test->id?>/invoice" target="_blank">
+										<a href="#" data-toggle="modal" data-target="#modal-test-invoice" data-invoice data-id="<?=$test->id?>">
 											<i class="fal fa-fw fa-external-link"></i> Invoice
 										</a>
 										<?php