service = $service;
$this->suppliers = $suppliers;
}
/**
* Build a signed print URL for a PO.
*
* @param int $po_id PO ID.
*/
public static function url( int $po_id ): string {
return wp_nonce_url(
admin_url( 'admin-post.php?action=' . self::ACTION . '&id=' . $po_id ),
self::ACTION
);
}
/**
* Render the printable document and exit.
*/
public function render(): void {
if ( ! Capabilities::current_user_can() ) {
wp_die( esc_html__( 'You do not have permission to view this.', 'profit-engine' ), '', array( 'response' => 403 ) );
}
$nonce = isset( $_GET['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ) : '';
if ( ! wp_verify_nonce( $nonce, self::ACTION ) ) {
wp_die( esc_html__( 'Security check failed.', 'profit-engine' ), '', array( 'response' => 403 ) );
}
$po_id = isset( $_GET['id'] ) ? absint( wp_unslash( $_GET['id'] ) ) : 0;
$po = $this->service->get( $po_id );
if ( ! $po ) {
wp_die( esc_html__( 'Purchase order not found.', 'profit-engine' ), '', array( 'response' => 404 ) );
}
$supplier = $this->suppliers->find( (int) $po['supplier_id'] );
$store = get_bloginfo( 'name' );
$profit_engine_settings = get_option( 'profit_engine_settings', array() );
$logo = is_array( $profit_engine_settings ) && ! empty( $profit_engine_settings['po_logo'] ) ? (string) $profit_engine_settings['po_logo'] : '';
$symbol = function_exists( 'get_woocommerce_currency_symbol' )
? html_entity_decode( get_woocommerce_currency_symbol( $po['currency'] ) )
: '';
$money = static fn( float $v ): string => esc_html( $symbol . number_format_i18n( $v, 2 ) );
// Register + enqueue this document's own CSS/JS through the standard API,
// then print those specific handles inside the page below.
wp_register_style( 'profit-engine-po-print', PROFIT_ENGINE_PLUGIN_URL . 'assets/css/po-print.css', array(), PROFIT_ENGINE_VERSION );
wp_enqueue_style( 'profit-engine-po-print' );
wp_register_script( 'profit-engine-po-print', PROFIT_ENGINE_PLUGIN_URL . 'assets/js/po-print.js', array(), PROFIT_ENGINE_VERSION, true );
wp_enqueue_script( 'profit-engine-po-print' );
nocache_headers();
header( 'Content-Type: text/html; charset=utf-8' );
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- values escaped inline below.
?>
>
| |
| - |
| 0 ? ' (' . esc_html__( 'non-refundable', 'profit-engine' ) . ')' : ''; ?> | |
| |
0 ) : ?>
| |
| |