Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: adds support for multiple UBL formats #927

Merged
merged 7 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' );
alexmigf marked this conversation as resolved.
Show resolved Hide resolved

// enable settings document switch
$( '.wcpdf_document_settings_sections > h2' ).on( 'click', function() {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin-script.min.js

Large diffs are not rendered by default.

23 changes: 19 additions & 4 deletions includes/Documents/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public function get_ubl_settings_fields( $option_name ) {
$settings_fields = array(
array(
'type' => 'section',
'id' => $this->type.'_ubl',
'id' => $this->type . '_ubl',
'title' => '',
'callback' => 'section',
),
Expand All @@ -588,18 +588,32 @@ public function get_ubl_settings_fields( $option_name ) {
'id' => 'enabled',
'title' => __( 'Enable', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'checkbox',
'section' => $this->type.'_ubl',
'section' => $this->type . '_ubl',
'args' => array(
'option_name' => $option_name,
'id' => 'enabled',
)
),
array(
'type' => 'setting',
'id' => 'ubl_format',
'title' => __( 'Format', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'select',
'section' => $this->type . '_ubl',
'args' => array(
'option_name' => $option_name,
'id' => 'ubl_format',
'options' => apply_filters( 'wpo_wcpdf_document_ubl_settings_formats', array(
'ubl_2_1' => __( 'UBL 2.1' , 'woocommerce-pdf-invoices-packing-slips' ),
), $this ),
)
),
array(
'type' => 'setting',
'id' => 'attach_to_email_ids',
'title' => __( 'Attach to:', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'multiple_checkboxes',
'section' => $this->type.'_ubl',
'section' => $this->type . '_ubl',
'args' => array(
'option_name' => $option_name,
'id' => 'attach_to_email_ids',
Expand All @@ -613,7 +627,7 @@ public function get_ubl_settings_fields( $option_name ) {
'id' => 'include_encrypted_pdf',
'title' => __( 'Include encrypted PDF:', 'woocommerce-pdf-invoices-packing-slips' ),
'callback' => 'checkbox',
'section' => $this->type.'_ubl',
'section' => $this->type . '_ubl',
'args' => array(
'option_name' => $option_name,
'id' => 'include_encrypted_pdf',
Expand Down Expand Up @@ -687,6 +701,7 @@ public function get_settings_categories( string $output_format ): array {
'title' => __( 'General', 'woocommerce-pdf-invoices-packing-slips' ),
'members' => array(
'enabled',
'ubl_format',
'attach_to_email_ids',
'include_encrypted_pdf',
),
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() {
alexmigf marked this conversation as resolved.
Show resolved Hide resolved
$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 includes/Settings/SettingsGeneral.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public function init_settings() {
'option_name' => $option_name,
'id' => 'shop_phone_number',
'translatable' => true,
// 'description' => __( 'Required for e-Invoice.', 'woocommerce-pdf-invoices-packing-slips' ),
'description' => __( 'Mandatory for certain UBL formats.', 'woocommerce-pdf-invoices-packing-slips' ),
)
),
array(
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 );
}
alexmigf marked this conversation as resolved.
Show resolved Hide resolved

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
Loading