Skip to content

Commit

Permalink
Merge pull request #64 from linsmeyer/fixIssues
Browse files Browse the repository at this point in the history
Fix issues
  • Loading branch information
gblmarquez authored Oct 14, 2020
2 parents f8df2e9 + eea5d56 commit e7cbf51
Show file tree
Hide file tree
Showing 52 changed files with 2,467 additions and 438 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ Ou você pode colocar este plugin no diretório wp-content/plugins e ativá-lo.
* Removed Composer support for the client-php.
* Removed checks when on automatic issuing, as it was avoiding important log information to be saved.
* Added better labeling for the NFe.io `flowStatus`.

### 1.2.9
3 changes: 3 additions & 0 deletions bin/install-wp-tests.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ install_test_suite() {
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
fi

cd $WP_TESTS_DIR

if [ ! -f wp-tests-config.php ]; then
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php
Expand Down Expand Up @@ -116,3 +118,4 @@ install_db() {
install_wp
install_test_suite
install_db

13 changes: 10 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
{
"name" : "Renato Alves",
"homepage": "https://ralv.es/"
},
{
"name" : "Linsmeyer",
"homepage": "https://github.com/linsmeyer/"
}
],
"support": {
Expand All @@ -27,9 +31,12 @@
"source": "https://github.com/nfe/woo-nfe/"
},
"require": {
"composer/installers": "~1.0"
"php": "^7",
"composer/installers": "^1.9.0"
},
"require-dev": {
"phpunit/phpunit": ">=3.7@stable"
}
"phpunit/phpunit": "^7.5.20",
"phpunit/php-code-coverage": "^6.1.4",
"friends-of-phpspec/phpspec-code-coverage": "^4.3"
}
}
208 changes: 121 additions & 87 deletions includes/admin/class-admin.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@
*/
class WC_NFe_Admin {

/**
* The single instance
*/
protected static $_instance = null;

/**
* Singleton getter
*/
public static function get_instance() {
if ( is_null(self::$_instance) ) {
self::$_instance = new self();
}
return self::$_instance;
}

/**
* Class Constructor
*
Expand Down Expand Up @@ -117,47 +132,47 @@ public function nfe_status_widget_order_rows() {
<li class="nfe-issued-orders">
<a href="<?php echo esc_url( admin_url( 'edit.php?post_type=shop_order' ) ); ?>">
<?php
/* translators: %s: order count */
printf(
_n( '<strong>%s receipt</strong> issued', '<strong>%s receipts</strong> issued', $nfe_issued_count, 'woo-nfe' ),
$nfe_issued_count
);
/* translators: %s: order count */
printf(
_n( '<strong>%s receipt</strong> issued', '<strong>%s receipts</strong> issued', $nfe_issued_count, 'woo-nfe' ),
$nfe_issued_count
);
?>
</a>
</li>

<li class="nfe-processing-orders">
<a href="<?php echo esc_url( admin_url( 'edit.php?post_type=shop_order' ) ); ?>">
<?php
/* translators: %s: order count */
printf(
_n( '<strong>%s receipt</strong> processing', '<strong>%s receipts</strong> processing', $nfe_issuing_count, 'woo-nfe' ),
$nfe_issuing_count
);
/* translators: %s: order count */
printf(
_n( '<strong>%s receipt</strong> processing', '<strong>%s receipts</strong> processing', $nfe_issuing_count, 'woo-nfe' ),
$nfe_issuing_count
);
?>
</a>
</li>

<li class="nfe-error-orders">
<a href="<?php echo esc_url( admin_url( 'edit.php?post_type=shop_order' ) ); ?>">
<?php
/* translators: %s: order count */
printf(
_n( '<strong>%s receipt</strong> with error', '<strong>%s receipts</strong> with error', $nfe_error_count, 'woo-nfe' ),
$nfe_error_count
);
/* translators: %s: order count */
printf(
_n( '<strong>%s receipt</strong> with error', '<strong>%s receipts</strong> with error', $nfe_error_count, 'woo-nfe' ),
$nfe_error_count
);
?>
</a>
</li>

<li class="nfe-cancelled-orders">
<a href="<?php echo esc_url( admin_url( 'edit.php?post_type=shop_order' ) ); ?>">
<?php
/* translators: %s: order count */
printf(
_n( '<strong>%s receipt</strong> cancelled', '<strong>%s receipts</strong> cancelled', $nfe_cancelled_count, 'woo-nfe' ),
$nfe_cancelled_count
);
/* translators: %s: order count */
printf(
_n( '<strong>%s receipt</strong> cancelled', '<strong>%s receipts</strong> cancelled', $nfe_cancelled_count, 'woo-nfe' ),
$nfe_cancelled_count
);
?>
</a>
</li>
Expand Down Expand Up @@ -393,74 +408,74 @@ public function order_status_column_content( $column ) {
}
?>
<mark>
<?php
$actions = array();

if ( ! empty( $nfe ) && 'Cancelled' === $nfe['status'] ) {
$actions['woo_nfe_cancelled'] = array(
'name' => __( 'NFe Cancelled', 'woo-nfe' ),
'action' => 'woo_nfe_cancelled',
);
} elseif ( ! empty( $nfe ) && 'Issued' === $nfe['status'] ) {
$actions['woo_nfe_emitida'] = array(
'name' => __( 'NFe Issued', 'woo-nfe' ),
'action' => 'woo_nfe_emitida',
);
} elseif ( ! empty( $nfe ) && 'CancelledFailed' === $nfe['status'] ) {
$actions['woo_nfe_issue'] = array(
'name' => __( 'NFe Cancelling Failed', 'woo-nfe' ),
'action' => 'woo_nfe_issue',
);
} elseif ( ! empty( $nfe ) && 'IssueFailed' === $nfe['status'] ) {
$actions['woo_nfe_issue'] = array(
'name' => __( 'NFe Issuing Failed', 'woo-nfe' ),
'action' => 'woo_nfe_issue',
);
} elseif ( ! empty( $nfe ) && in_array( $nfe['status'], nfe_processing_status(), true ) ) {
$actions['woo_nfe_issuing'] = array(
'name' => __( 'Processing NFe', 'woo-nfe' ),
'action' => 'woo_nfe_issuing',
);
} else {
if ( '0.00' === $order->get_total() ) {
$actions['woo_nfe_pending_address'] = array(
'name' => __( 'Zero Order', 'woo-nfe' ),
'action' => 'woo_nfe_pending_address',
<?php
$actions = array();

if ( ! empty( $nfe ) && 'Cancelled' === $nfe['status'] ) {
$actions['woo_nfe_cancelled'] = array(
'name' => __( 'NFe Cancelled', 'woo-nfe' ),
'action' => 'woo_nfe_cancelled',
);
} elseif ( ! empty( $nfe ) && 'Issued' === $nfe['status'] ) {
$actions['woo_nfe_emitida'] = array(
'name' => __( 'NFe Issued', 'woo-nfe' ),
'action' => 'woo_nfe_emitida',
);
} elseif ( ! empty( $nfe ) && 'CancelledFailed' === $nfe['status'] ) {
$actions['woo_nfe_issue'] = array(
'name' => __( 'NFe Cancelling Failed', 'woo-nfe' ),
'action' => 'woo_nfe_issue',
);
} elseif ( ! nfe_order_address_filled( $order_id ) ) {
$actions['woo_nfe_pending_address'] = array(
'name' => __( 'Pending Address', 'woo-nfe' ),
'action' => 'woo_nfe_pending_address',
} elseif ( ! empty( $nfe ) && 'IssueFailed' === $nfe['status'] ) {
$actions['woo_nfe_issue'] = array(
'name' => __( 'NFe Issuing Failed', 'woo-nfe' ),
'action' => 'woo_nfe_issue',
);
} elseif ( ! empty( $nfe ) && in_array( $nfe['status'], nfe_processing_status(), true ) ) {
$actions['woo_nfe_issuing'] = array(
'name' => __( 'Processing NFe', 'woo-nfe' ),
'action' => 'woo_nfe_issuing',
);
} else {
if ( nfe_get_field( 'issue_past_notes' ) === 'yes' ) {
if ( nfe_issue_past_orders( $order ) && empty( $nfe['id'] ) ) {
if ( '0.00' === $order->get_total() ) {
$actions['woo_nfe_pending_address'] = array(
'name' => __( 'Zero Order', 'woo-nfe' ),
'action' => 'woo_nfe_pending_address',
);
} elseif ( ! nfe_order_address_filled( $order_id ) ) {
$actions['woo_nfe_pending_address'] = array(
'name' => __( 'Pending Address', 'woo-nfe' ),
'action' => 'woo_nfe_pending_address',
);
} else {
if ( nfe_get_field( 'issue_past_notes' ) === 'yes' ) {
if ( nfe_issue_past_orders( $order ) && empty( $nfe['id'] ) ) {
$actions['woo_nfe_issue'] = array(
'name' => __( 'Issue NFe', 'woo-nfe' ),
'action' => 'woo_nfe_issue',
);
} else {
$actions['woo_nfe_expired'] = array(
'name' => __( 'Issue Expired', 'woo-nfe' ),
'action' => 'woo_nfe_expired',
);
}
} else {
$actions['woo_nfe_issue'] = array(
'name' => __( 'Issue NFe', 'woo-nfe' ),
'action' => 'woo_nfe_issue',
);
} else {
$actions['woo_nfe_expired'] = array(
'name' => __( 'Issue Expired', 'woo-nfe' ),
'action' => 'woo_nfe_expired',
);
}
} else {
$actions['woo_nfe_issue'] = array(
'name' => __( 'Issue NFe', 'woo-nfe' ),
'action' => 'woo_nfe_issue',
);
}
}
}

foreach ( $actions as $action ) {
printf( '<span class="woo_nfe_actions %s">%s</span>',
esc_attr( $action['action'] ),
esc_attr( $action['name'] )
);
}
?>
foreach ( $actions as $action ) {
printf( '<span class="woo_nfe_actions %s">%s</span>',
esc_attr( $action['action'] ),
esc_attr( $action['name'] )
);
}
?>
</mark>
<?php
}
Expand Down Expand Up @@ -510,9 +525,28 @@ public function display_order_data_preview_in_admin( $order ) {
<?php echo wc_price( $nfe['amountNet'], array( 'currency' => $order->get_currency() ) ); // WPCS: XSS ok. ?>
<?php endif; ?>
<br />

<?php if ( ! empty( $nfe['id'] ) ) : ?>
<strong><?php esc_html_e( 'Fatura: ', 'woo-nfe' );?></strong>
<?php echo sprintf( '<a href="https://app.nfe.io/companies/'.NFe_Woo()->get_company().'/service-invoices/'.$nfe['id'].'">Link</a>', 'woo-nfe' );?>
<br />
<?php endif; ?>


<?php
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );

if ( is_plugin_active( 'woocommerce-extra-checkout-fields-for-brazil/woocommerce-extra-checkout-fields-for-brazil.php' ) ) {
esc_html_e( 'Plugin Custom Fields: ', 'woo-nfe' );
echo sprintf( 'OK');
} else {esc_html_e( 'Plugin Custom Fields: ', 'woo-nfe' );
echo sprintf( 'NOT_OK');
}
?>

</p>
</div>
<?php
<?php
}

/**
Expand Down Expand Up @@ -560,23 +594,23 @@ public function nfe_admin_order_preview() {
<h2><?php esc_html_e( 'NFe Details', 'woo-nfe' ); ?></h2>

<# if ( data.nfe.status ) { #>
<strong><?php esc_html_e( 'Status', 'woo-nfe' ); ?></strong>
{{{ data.nfe.status }}}
<strong><?php esc_html_e( 'Status', 'woo-nfe' ); ?></strong>
{{{ data.nfe.status }}}
<# } #>

<# if ( data.nfe.number ) { #>
<strong><?php esc_html_e( 'Number', 'woo-nfe' ); ?></strong>
{{{ data.nfe.number }}}
<strong><?php esc_html_e( 'Number', 'woo-nfe' ); ?></strong>
{{{ data.nfe.number }}}
<# } #>

<# if ( data.nfe.check_code ) { #>
<strong><?php esc_html_e( 'CheckCode', 'woo-nfe' ); ?></strong>
{{{ data.nfe.check_code }}}
<strong><?php esc_html_e( 'CheckCode', 'woo-nfe' ); ?></strong>
{{{ data.nfe.check_code }}}
<# } #>

<# if ( data.nfe.issued ) { #>
<strong><?php esc_html_e( 'Issued On', 'woo-nfe' ); ?></strong>
{{{ data.nfe.issued }}}
<strong><?php esc_html_e( 'Issued On', 'woo-nfe' ); ?></strong>
{{{ data.nfe.issued }}}
<# } #>
</div>
</div>
Expand Down Expand Up @@ -653,6 +687,6 @@ protected function should_we_issue( $download, $order ) {
}
}

return new WC_NFe_Admin();
return WC_NFe_Admin::get_instance();

endif;
4 changes: 2 additions & 2 deletions includes/admin/class-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,8 @@ protected function get_key() {
*
* @return string
*/
protected function get_company() {
return nfe_get_field( 'choose_company' );
public function get_company() {
return nfe_get_field( 'choose_company');
}

/**
Expand Down
20 changes: 20 additions & 0 deletions includes/admin/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ public function __construct() {
* Initialize integration settings form fields.
*/
public function init_form_fields() {


if (is_plugin_active( 'woocommerce-extra-checkout-fields-for-brazil/woocommerce-extra-checkout-fields-for-brazil.php' ) ) {
$custom_fields_plugin = 'yes';
$custom_fields_plugin_message = 'instalado';
$description = '';
} else {
$custom_fields_plugin = 'no';
$custom_fields_plugin_message = 'não instalado';
$description = __('<a href="plugin-install.php?tab=plugin-information&amp;plugin=woocommerce-extra-checkout-fields-for-brazil&" aria-label="Mais informações sobre Brazilian Market on WooCommerce" data-title="Brazilian Market on WooCommerce">Ver detalhes</a>', 'woo-nfe' );
}

if ( $this->has_api_key() ) {
$lists = $this->get_companies();

Expand All @@ -55,6 +67,14 @@ public function init_form_fields() {
}

$this->form_fields = array(
'custom_fields' => array(
'title' => __( 'Custom Fields Plugin', 'woo-nfe' ),
'type' => 'checkbox',
'label' => __( $custom_fields_plugin_message, 'woo-nfe' ),
'default' => $custom_fields_plugin,
'disabled' => true,
'description' => $description,
),
'nfe_enable' => array(
'title' => __( 'Enable/Disable', 'woo-nfe' ),
'type' => 'checkbox',
Expand Down
4 changes: 1 addition & 3 deletions includes/nfe-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
*
* @return string
*/
function nfe_get_field( $value = '' ) {
$nfe_fields = get_option( 'woocommerce_woo-nfe_settings' );

function nfe_get_field($value = '') {
if ( empty( $value ) ) {
$output = $nfe_fields;
} else {
Expand Down
Binary file removed li/client-php/composer.phar
Binary file not shown.
Loading

0 comments on commit e7cbf51

Please sign in to comment.