| 1 |
<?php |
| 2 |
/** |
| 3 |
* Statement of account for one client. |
| 4 |
* |
| 5 |
* Receives from StatementController::maybeRenderPage(): |
| 6 |
* $client (WP_User), $client_id, $statement, $from, $to |
| 7 |
* |
| 8 |
* @package Easy_Invoice |
| 9 |
*/ |
| 10 |
|
| 11 |
use EasyInvoice\Controllers\StatementController; |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
$clients_url = admin_url( 'admin.php?page=easy-invoice-clients' ); |
| 18 |
$name = $client->display_name ?: $client->user_login; |
| 19 |
$ei_rec = \EasyInvoice\Providers\ClientServiceProvider::getClientRepository()->find( (int) $client_id ); |
| 20 |
if ( $ei_rec ) { |
| 21 |
$ei_person = trim( (string) $ei_rec->getFirstName() . ' ' . (string) $ei_rec->getLastName() ); |
| 22 |
$name = (string) $ei_rec->getBusinessClientName() ?: ( $ei_person ?: $name ); |
| 23 |
} |
| 24 |
$ei_sym = \EasyInvoice\Helpers\CurrencyHelper::getCurrencySymbol( (string) get_option( 'easy_invoice_currency_code', 'USD' ) ); |
| 25 |
$owes = $statement['balance'] > 0.001; |
| 26 |
?> |
| 27 |
|
| 28 |
<div class="p-8"> |
| 29 |
|
| 30 |
<div class="ei-app-page-header bg-white border-b border-gray-200 px-6 easy-invoice-admin-page-header"> |
| 31 |
<div class="flex items-center justify-between flex-wrap gap-4"> |
| 32 |
<div> |
| 33 |
<h1 class="text-2xl font-bold text-gray-900"> |
| 34 |
<?php |
| 35 |
printf( |
| 36 |
/* translators: %s: client name. */ |
| 37 |
esc_html__( 'Statement — %s', 'easy-invoice' ), |
| 38 |
esc_html( $name ) |
| 39 |
); |
| 40 |
?> |
| 41 |
</h1> |
| 42 |
<p class="mt-1 text-sm text-gray-500"> |
| 43 |
<?php esc_html_e( 'Every invoice, payment and credit note that moved this balance, in date order.', 'easy-invoice' ); ?> |
| 44 |
</p> |
| 45 |
</div> |
| 46 |
<div class="flex items-center gap-3"> |
| 47 |
<a href="<?php echo esc_url( StatementController::pdfUrl( (int) $client_id, $from, $to ) ); ?>" |
| 48 |
class="inline-flex items-center px-3 py-1.5 text-sm font-medium rounded-md bg-indigo-600 text-white hover:bg-indigo-700"> |
| 49 |
<?php esc_html_e( 'Download PDF', 'easy-invoice' ); ?> |
| 50 |
</a> |
| 51 |
<a href="<?php echo esc_url( $clients_url ); ?>" class="text-sm font-medium text-indigo-600 hover:text-indigo-800"> |
| 52 |
<?php esc_html_e( 'Back to clients', 'easy-invoice' ); ?> |
| 53 |
</a> |
| 54 |
</div> |
| 55 |
</div> |
| 56 |
</div> |
| 57 |
|
| 58 |
<form method="get" class="mt-6 bg-white rounded-lg border border-gray-200 p-4 flex flex-wrap items-end gap-4"> |
| 59 |
<input type="hidden" name="page" value="<?php echo esc_attr( StatementController::PAGE_SLUG ); ?>"> |
| 60 |
<input type="hidden" name="client_id" value="<?php echo esc_attr( (string) $client_id ); ?>"> |
| 61 |
<div> |
| 62 |
<label for="ei-st-from" class="block text-xs font-semibold uppercase tracking-wide text-gray-500"><?php esc_html_e( 'From', 'easy-invoice' ); ?></label> |
| 63 |
<input type="date" id="ei-st-from" name="from" value="<?php echo esc_attr( $from ); ?>" class="mt-1 rounded-md border-gray-300 shadow-sm text-sm"> |
| 64 |
</div> |
| 65 |
<div> |
| 66 |
<label for="ei-st-to" class="block text-xs font-semibold uppercase tracking-wide text-gray-500"><?php esc_html_e( 'To', 'easy-invoice' ); ?></label> |
| 67 |
<input type="date" id="ei-st-to" name="to" value="<?php echo esc_attr( $to ); ?>" class="mt-1 rounded-md border-gray-300 shadow-sm text-sm"> |
| 68 |
</div> |
| 69 |
<button type="submit" class="px-3 py-1.5 text-sm font-medium rounded-md border border-gray-300 bg-white hover:bg-gray-50"> |
| 70 |
<?php esc_html_e( 'Apply', 'easy-invoice' ); ?> |
| 71 |
</button> |
| 72 |
<p class="text-xs text-gray-500 basis-full sm:basis-auto"> |
| 73 |
<?php esc_html_e( 'Leave both empty for the whole relationship.', 'easy-invoice' ); ?> |
| 74 |
</p> |
| 75 |
</form> |
| 76 |
|
| 77 |
<div class="mt-6 grid grid-cols-2 lg:grid-cols-4 gap-4"> |
| 78 |
<?php |
| 79 |
$tiles = [ |
| 80 |
[ __( 'Invoiced', 'easy-invoice' ), $statement['invoiced'], 'text-gray-900' ], |
| 81 |
[ __( 'Paid', 'easy-invoice' ), $statement['paid'], 'text-green-700' ], |
| 82 |
[ __( 'Credited', 'easy-invoice' ), $statement['credited'], 'text-gray-900' ], |
| 83 |
[ __( 'Balance due', 'easy-invoice' ), $statement['balance'], $owes ? 'text-red-700' : 'text-green-700' ], |
| 84 |
]; |
| 85 |
foreach ( $tiles as $tile ) : |
| 86 |
?> |
| 87 |
<div class="bg-white rounded-lg border border-gray-200 p-4"> |
| 88 |
<div class="text-xs font-semibold uppercase tracking-wide text-gray-500"><?php echo esc_html( $tile[0] ); ?></div> |
| 89 |
<div class="mt-1 text-xl font-bold <?php echo esc_attr( $tile[2] ); ?>" style="font-variant-numeric: tabular-nums;"> |
| 90 |
<?php echo esc_html( easy_invoice_format_money( (float) $tile[1] ) ); ?> |
| 91 |
</div> |
| 92 |
</div> |
| 93 |
<?php endforeach; ?> |
| 94 |
</div> |
| 95 |
|
| 96 |
<div class="mt-6 bg-white rounded-lg border border-gray-200 p-6"> |
| 97 |
<?php if ( empty( $statement['rows'] ) ) : ?> |
| 98 |
<p class="text-sm text-gray-600"><?php esc_html_e( 'Nothing on this account in that period.', 'easy-invoice' ); ?></p> |
| 99 |
<?php else : ?> |
| 100 |
<div class="overflow-x-auto"> |
| 101 |
<table class="min-w-full divide-y divide-gray-200 text-sm"> |
| 102 |
<thead> |
| 103 |
<tr class="text-left text-xs uppercase tracking-wide text-gray-500"> |
| 104 |
<th class="py-2 pr-4 font-semibold"><?php esc_html_e( 'Date', 'easy-invoice' ); ?></th> |
| 105 |
<th class="py-2 px-4 font-semibold"><?php esc_html_e( 'Document', 'easy-invoice' ); ?></th> |
| 106 |
<th class="py-2 px-4 font-semibold text-right"><?php esc_html_e( 'Charge', 'easy-invoice' ); ?></th> |
| 107 |
<th class="py-2 px-4 font-semibold text-right"><?php esc_html_e( 'Credit', 'easy-invoice' ); ?></th> |
| 108 |
<th class="py-2 pl-4 font-semibold text-right"><?php esc_html_e( 'Balance', 'easy-invoice' ); ?></th> |
| 109 |
</tr> |
| 110 |
</thead> |
| 111 |
<tbody class="divide-y divide-gray-100"> |
| 112 |
<?php if ( abs( (float) $statement['opening'] ) > 0.001 ) : ?> |
| 113 |
<tr class="text-gray-500"> |
| 114 |
<td class="py-2.5 pr-4">—</td> |
| 115 |
<td class="py-2.5 px-4 italic"><?php esc_html_e( 'Brought forward', 'easy-invoice' ); ?></td> |
| 116 |
<td class="py-2.5 px-4"></td> |
| 117 |
<td class="py-2.5 px-4"></td> |
| 118 |
<td class="py-2.5 pl-4 text-right" style="font-variant-numeric: tabular-nums;"> |
| 119 |
<?php echo esc_html( easy_invoice_format_money( (float) $statement['opening'] ) ); ?> |
| 120 |
</td> |
| 121 |
</tr> |
| 122 |
<?php endif; ?> |
| 123 |
<?php foreach ( $statement['rows'] as $row ) : ?> |
| 124 |
<tr> |
| 125 |
<td class="py-2.5 pr-4 text-gray-700"><?php echo esc_html( $row['date'] ); ?></td> |
| 126 |
<td class="py-2.5 px-4"> |
| 127 |
<span class="font-medium text-gray-900"><?php echo esc_html( $row['label'] ); ?></span> |
| 128 |
<?php if ( '' !== $row['number'] ) : ?> |
| 129 |
<span class="text-gray-500"><?php echo esc_html( $row['number'] ); ?></span> |
| 130 |
<?php endif; ?> |
| 131 |
</td> |
| 132 |
<td class="py-2.5 px-4 text-right text-gray-900" style="font-variant-numeric: tabular-nums;"> |
| 133 |
<?php echo $row['charge'] > 0 ? esc_html( easy_invoice_format_money( (float) $row['charge'] ) ) : ''; ?> |
| 134 |
</td> |
| 135 |
<td class="py-2.5 px-4 text-right text-green-700" style="font-variant-numeric: tabular-nums;"> |
| 136 |
<?php echo $row['credit'] > 0 ? esc_html( easy_invoice_format_money( (float) $row['credit'] ) ) : ''; ?> |
| 137 |
</td> |
| 138 |
<td class="py-2.5 pl-4 text-right font-medium text-gray-900" style="font-variant-numeric: tabular-nums;"> |
| 139 |
<?php echo esc_html( easy_invoice_format_money( (float) $row['balance'] ) ); ?> |
| 140 |
</td> |
| 141 |
</tr> |
| 142 |
<?php endforeach; ?> |
| 143 |
</tbody> |
| 144 |
</table> |
| 145 |
</div> |
| 146 |
<?php endif; ?> |
| 147 |
</div> |
| 148 |
</div> |
| 149 |
|