post_type ) ? 'quote' : 'invoice'; $is_quote = ( 'quote' === $document_type ); $document = null; if ( $post ) { if ( $is_quote && \EasyInvoice\Constants\PostTypes::EASY_INVOICE_QUOTE_POST_TYPE === $post->post_type ) { $document = \EasyInvoice\Providers\QuoteServiceProvider::getQuoteRepository()->find( $post->ID ); if ( $document && is_callable( [ $document, 'ensureProperSlug' ] ) ) { $document->ensureProperSlug(); } } elseif ( ! $is_quote && \EasyInvoice\Constants\PostTypes::EASY_INVOICE_POST_TYPE === $post->post_type ) { $document = \EasyInvoice\Providers\InvoiceServiceProvider::getInvoiceRepository()->find( $post->ID ); } } if ( ! $document ) { wp_die( $is_quote ? esc_html__( 'Quote not found.', 'easy-invoice' ) : esc_html__( 'Invoice not found.', 'easy-invoice' ) ); } $invoice = $is_quote ? null : $document; $quote = $is_quote ? $document : null; $document_id = (int) $document->getId(); $formatter = $is_quote ? new \EasyInvoice\Helpers\QuoteFormatter( $quote ) : new \EasyInvoice\Helpers\InvoiceFormatter( $invoice ); $text_settings = $is_quote ? \EasyInvoice\Helpers\TemplateTextHelper::getQuoteTextSettings() : \EasyInvoice\Helpers\TemplateTextHelper::getInvoiceTextSettings(); $template_file = easy_invoice_design_template( $document_type, (string) $document->getTemplate() ); $status = (string) $document->getStatus(); $is_admin_user = is_user_logged_in() && current_user_can( 'manage_options' ); // The emailed link carries an access token; every URL we build keeps it so // the recipient stays authorised across print, PDF and email actions. $token_param = $is_quote ? 'qk' : 'ik'; $token = isset( $_GET[ $token_param ] ) ? sanitize_text_field( wp_unslash( $_GET[ $token_param ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended /** This filter is documented in includes/Controllers/InvoiceController.php */ $token = (string) apply_filters( 'easy_invoice_presented_access_token', $token, $document_type ); $pdf_url = add_query_arg( array_filter( [ 'auto_download_pdf' => '1', $token_param => $token ] ), get_permalink( $document_id ) ); // Invoice: may the viewer pay? Quote: may the viewer accept or decline? // Payable while something is owed: unpaid, part-paid or overdue — a draft is // not issued yet, a paid or cancelled invoice has nothing to collect. $can_pay = ! $is_quote && in_array( $status, [ 'unpaid', 'available', 'partial', 'overdue' ], true ) && \EasyInvoice\Services\InvoiceBalance::due( $invoice ) > 0; // Open for a decision: authorised viewer, and the quote neither decided nor // past its expiry date. When it is closed the reason is shown instead. $quote_closed_reason = ''; $quote_closed_tone = 'expired'; $can_act = false; if ( $is_quote && \EasyInvoice\Controllers\QuoteController::canActOnQuote( $document_id, $quote ) ) { $ei_open = \EasyInvoice\Controllers\QuoteController::openForDecision( $quote ); if ( true === $ei_open ) { $can_act = true; } elseif ( is_wp_error( $ei_open ) ) { // The reader came here to decide; tell them what already happened // instead of showing a quote with no buttons and no explanation. $ei_qstatus = strtolower( (string) $quote->getStatus() ); if ( 'accepted' === $ei_qstatus ) { $ei_when = (string) get_post_meta( $document_id, '_easy_invoice_quote_accepted_date', true ); $quote_closed_tone = 'accepted'; $quote_closed_reason = '' !== $ei_when && strtotime( $ei_when ) /* translators: %s: date. */ ? sprintf( __( 'You accepted this quote on %s. Thank you — nothing more to do here.', 'easy-invoice' ), date_i18n( get_option( 'date_format' ), strtotime( $ei_when ) ) ) : __( 'This quote has been accepted. Thank you — nothing more to do here.', 'easy-invoice' ); } elseif ( 'declined' === $ei_qstatus ) { $quote_closed_tone = 'declined'; $quote_closed_reason = __( 'This quote was declined. If that was a mistake, reply to the email it came with and we will send a fresh one.', 'easy-invoice' ); } else { $quote_closed_reason = $ei_open->get_error_message(); } } } $accept_description = ''; if ( $can_act ) { switch ( \EasyInvoice\Controllers\SettingsController::getQuoteAcceptAction() ) { case 'convert': $accept_description = __( 'This will convert the quote to an invoice.', 'easy-invoice' ); break; case 'convert_send': $accept_description = __( 'This will convert the quote to an invoice and send it to the client.', 'easy-invoice' ); break; case 'duplicate': $accept_description = __( 'This will create a new invoice while keeping this quote unchanged.', 'easy-invoice' ); break; case 'duplicate_send': $accept_description = __( 'This will create a new invoice and send it to the client, while keeping this quote unchanged.', 'easy-invoice' ); break; default: $accept_description = __( 'This will mark the quote as accepted.', 'easy-invoice' ); } } $additional_css = (string) get_post_meta( $document_id, '_easy_invoice_additional_css', true ); ?> > <?php echo esc_html( $document->getTitle() ?: ( $is_quote ? __( 'Quote', 'easy-invoice' ) : __( 'Invoice', 'easy-invoice' ) ) ); ?> of the public document page. * * Kept for the gateways and addons that print their assets here * directly; new code should enqueue on `wp_enqueue_scripts` and test * `DocumentPage::currentType()` instead. */ do_action( 'easy_invoice_head' ); ?> , so tags are stripped instead of escaped. ?> >
:
$document, 'document_type' => $document_type, 'formatter' => $formatter, 'invoice' => $invoice, 'quote' => $quote, ] ); } if ( $is_quote ) { do_action( 'easy_invoice_quote_content_after', $quote ); } ?>
$document_type, 'additional_css' => $additional_css, ] ); ?>