Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmigf committed Dec 13, 2024
1 parent 10e0301 commit c755305
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
11 changes: 11 additions & 0 deletions assets/js/admin-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ jQuery( function( $ ) {
$( this ).closest( 'tr' ).nextAll( 'tr' ).has( 'input#next_invoice_number' ).first().show();
}
} ).trigger( 'change' );

// disable encrypted pdf option for non UBL 2.1 formats
$( "[name='wpo_wcpdf_documents_settings_invoice_ubl[ubl_format]']" ).on( 'change', function( event ) {
let $encryptedPdfCheckbox = $( this ).closest( 'form' ).find( "[name='wpo_wcpdf_documents_settings_invoice_ubl[include_encrypted_pdf]']" );

if ( $( this ).val() !== 'ubl_2_1' ) {
$encryptedPdfCheckbox.prop( 'checked', false ).prop( 'disabled', true );
} else {
$encryptedPdfCheckbox.prop( 'disabled', false );
}
} ).trigger( 'change' );

// enable settings document switch
$( '.wcpdf_document_settings_sections > h2' ).on( 'click', function() {
Expand Down
2 changes: 1 addition & 1 deletion includes/Documents/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public function get_ubl_settings_fields( $option_name ) {
'section' => $this->type . '_ubl',
'args' => array(
'option_name' => $option_name,
'id' => 'format',
'id' => 'ubl_format',
'options' => apply_filters( 'wpo_wcpdf_ubl_formats', array(
'ubl_2_1' => __( 'UBL 2.1' , 'woocommerce-pdf-invoices-packing-slips' ),
) ),
Expand Down
6 changes: 6 additions & 0 deletions includes/Documents/OrderDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ public function is_enabled( $output_format = 'pdf' ) {

return apply_filters( 'wpo_wcpdf_document_is_enabled', $is_enabled, $this->type, $output_format );
}

public function get_ubl_format() {
$ubl_format = $this->get_setting( 'ubl_format', false, 'ubl' );

return apply_filters( 'wpo_wcpdf_document_ubl_format', $ubl_format, $this );
}

public function get_hook_prefix() {
return 'wpo_wcpdf_' . $this->slug . '_get_';
Expand Down
2 changes: 1 addition & 1 deletion ubl/Builders/SabreBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function build( Document $document ) {
$namespaces = array_flip( $document->get_namespaces() );
$this->service->namespaceMap = $namespaces;

return $this->service->write( 'Invoice', $document->get_data() );
return $this->service->write( $document->get_root_element(), $document->get_data() );
}

}
8 changes: 6 additions & 2 deletions ubl/Documents/UblDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
}

class UblDocument extends Document {

public function get_root_element() {
return apply_filters( 'wpo_wc_ubl_document_root_element', 'Invoice', $this );
}

public function get_format() {
$format = apply_filters( 'wpo_wc_ubl_document_format' , array(
Expand Down Expand Up @@ -82,7 +86,7 @@ public function get_format() {
'enabled' => true,
'handler' => \WPO\IPS\UBL\Handlers\Invoice\InvoiceLineHandler::class,
),
) );
), $this );

foreach ( $format as $key => $element ) {
if ( false === $element['enabled'] ) {
Expand All @@ -98,7 +102,7 @@ public function get_namespaces() {
'cac' => 'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2',
'cbc' => 'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2',
'' => 'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2',
) );
), $this );
}

public function get_data() {
Expand Down

0 comments on commit c755305

Please sign in to comment.