Skip to content

Commit

Permalink
WIP: feat-80 (#82) - Adiciona opcao para possibilitar o destaque (sub…
Browse files Browse the repository at this point in the history
…tracao) do valor do frete na NFSe

* core: Declaring extension incompatibility with High-Performance Order Storage (HPOS)

* repo: update git ignore

* feat: adiciona destaque do frete do calculo de impostos

Adiciona opcao para possibilitar o destaque (subtracao) do valor do frete do calculo dos impostos da NF.

ref: #80

* update translations

* refact: change access to order id property

Change direct access to id to object method get_id

* build: update grunt packages and scripts

Update grunt packages and add wp-env to dev dependencies.
  • Loading branch information
andrekutianski authored Nov 13, 2023
1 parent f89db4b commit a618b26
Show file tree
Hide file tree
Showing 13 changed files with 1,859 additions and 223 deletions.
66 changes: 34 additions & 32 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

# Created by https://www.toptal.com/developers/gitignore/api/linux,macos,windows,phpstorm,wordpress,phpcodesniffer,node
# Edit at https://www.toptal.com/developers/gitignore?templates=linux,macos,windows,phpstorm,wordpress,phpcodesniffer,node
# Created by https://www.toptal.com/developers/gitignore/api/node,linux,macos,windows,phpcodesniffer,phpunit,wordpress,php-cs-fixer,phpstorm+all
# Edit at https://www.toptal.com/developers/gitignore?templates=node,linux,macos,windows,phpcodesniffer,phpunit,wordpress,php-cs-fixer,phpstorm+all

### Linux ###
*~
Expand Down Expand Up @@ -190,13 +189,24 @@ dist
# SvelteKit build / generate output
.svelte-kit

### PHP-CS-Fixer ###
# Covers PHP CS Fixer
# Reference: https://cs.symfony.com/

# Generated files
.php-cs-fixer.cache

# Local config See: https://cs.symfony.com/doc/config.html
.php-cs-fixer.php

### PHPCodeSniffer ###
# CodeSniffer
phpcs.xml

/vendor/*
/wpcs/*

### PhpStorm ###
### PhpStorm+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

Expand Down Expand Up @@ -275,39 +285,29 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### PhpStorm Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
### PhpStorm+all Patch ###
# Ignore everything but code style settings and run configurations
# that are supposed to be shared within teams.

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
.idea/*

# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/
!.idea/codeStyles
!.idea/runConfigurations

# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml
### PHPUnit ###
# Covers PHPUnit
# Reference: https://phpunit.de/

# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/

# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/$CACHE_FILE$
# Generated files
.phpunit.result.cache
.phpunit.cache

# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml
# PHPUnit
/app/phpunit.xml
/phpunit.xml

# Azure Toolkit for IntelliJ plugin
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
.idea/**/azureSettings.xml
# Build data
/build/

### Windows ###
# Windows thumbnail cache files
Expand Down Expand Up @@ -379,5 +379,7 @@ wp-config.php
# uncomment the next line
#/wp-content/themes

# rsync script
rsync.sh

# End of https://www.toptal.com/developers/gitignore/api/linux,macos,windows,phpstorm,wordpress,phpcodesniffer,node
# End of https://www.toptal.com/developers/gitignore/api/node,linux,macos,windows,phpcodesniffer,phpunit,wordpress,php-cs-fixer,phpstorm+all
11 changes: 11 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"core": null,
"phpVersion": "8.1",
"plugins": [
"WordPress/woocommerce",
"WordPress/woocommerce-extra-checkout-fields-for-brazil"
],
"mappings": {
"wp-content/plugins/woo-nfe": "."
}
}
9 changes: 8 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = grunt => {
require('load-grunt-tasks')(grunt);

grunt.loadNpmTasks( 'grunt-wp-i18n' );
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

Expand Down Expand Up @@ -33,6 +33,13 @@ module.exports = grunt => {
],
expand: true
}
},
makepot: {
target: {
options: {
type: 'wp-plugin'
}
}
}
});
};
10 changes: 5 additions & 5 deletions includes/admin/class-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public static function front_issue() {
$order = nfe_wc_get_order( absint( $nfe_issue ) );

// Bail if there is no order id or it is false.
if ( empty( $order->id ) || ! $order ) {
if ( empty( $order->get_id() ) ) {
return;
}

if ( ! nfe_order_address_filled( $order->id ) ) {
if ( ! nfe_order_address_filled( $order->get_id() ) ) {
wc_add_notice( __( 'The order is missing important NFe information, update it before trying to issue it.', 'woo-nfe' ), 'error' );
} else {
NFe_Woo()->issue_invoice( array( $order->id ) );
NFe_Woo()->issue_invoice( array( $order->get_id() ) );

wc_add_notice( __( 'NFe was issued successfully.', 'woo-nfe' ) );
}
Expand All @@ -69,11 +69,11 @@ public static function front_download_pdf() {
$order = nfe_wc_get_order( absint( $nfe_download_pdf ) );

// Bail if there is no order id or it is false.
if ( empty( $order->id ) || ! $order ) {
if ( empty( $order->get_id() ) ) {
return;
}

self::download_pdf( $order->id );
self::download_pdf( $order->get_id() );
}

/**
Expand Down
32 changes: 30 additions & 2 deletions includes/admin/class-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,25 @@ public function order_info( $order_id ) {
// Get order object.
$order = nfe_wc_get_order( $order_id );

// if tax formation is exclude shipping, remove shipping from total.
if($this->highlight_shipping_tax() == 'exclude_shipping') {
// subtract shipping from total.
$servicesAmount = $order->get_total() - $order->get_shipping_total();
// get invoice info.
$invoiceInfo = $this->remover_caracter( $this->city_service_info( 'desc', $order_id ) );
// build shipping info line
$shippingInfo = __('Shipping', 'woo-nfe') . ": " . $order->get_shipping_method();
// build shipping value line
$shippingValueDescription = __('Shipping Value', 'woo-nfe') . ": " . $order->get_shipping_total() . $order->get_currency();
// final description
$servicesDescription = $this->remover_caracter("{$invoiceInfo} \n $shippingInfo \n $shippingValueDescription");
} else {
// if tax formation is include shipping, keep shipping in total.
$servicesAmount = $order->get_total();
// get invoice info.
$servicesDescription = $this->remover_caracter( $this->city_service_info( 'desc', $order_id ) );
}

$address = array(
'postalCode' => $this->check_customer_info( 'cep', $order_id ),
'street' => $this->remover_caracter( $this->check_customer_info( 'street', $order_id ) ),
Expand All @@ -219,8 +238,8 @@ public function order_info( $order_id ) {
$data = array(
'cityServiceCode' => $this->city_service_info( 'code', $order_id ),
'federalServiceCode' => $this->city_service_info( 'fed_code', $order_id ),
'description' => $this->remover_caracter( $this->city_service_info( 'desc', $order_id ) ),
'servicesAmount' => $order->get_total(),
'description' => $servicesDescription,
'servicesAmount' => $servicesAmount,
'borrower' => $borrower,
);

Expand Down Expand Up @@ -325,6 +344,15 @@ public function get_company() {
return nfe_get_field( 'choose_company' );
}

/**
* Highlight Shipping fees from the order taxes.
* @return string
*/
public function highlight_shipping_tax()
{
return nfe_get_field( 'highlight_shipping_tax' );
}

/**
* Logging method.
*
Expand Down
19 changes: 17 additions & 2 deletions includes/admin/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public function init_form_fields() {
}

if ( $this->has_api_key() ) {
$lists = $this->get_companies();
// Get companies. If no companies, return an empty array.
$lists = $this->get_companies() ? $this->get_companies() : array();
// $lists = $this->get_companies();

if ( empty( $lists ) ) {
$company_list = array_merge( array( '' => __( 'No company found', 'woo-nfe' ) ), $lists );
Expand Down Expand Up @@ -139,8 +141,21 @@ public function init_form_fields() {
'css' => 'min-width:300px;',
'desc_tip' => __( 'Does an address is required to issue a NFe?', 'woo-nfe' ),
),
'highlight_shipping_tax' => array(
'title' => __('Highlight shipping from taxes', 'woo-nfe'),
'type' => 'select',
'label' => __('Highlight shipping from taxes', 'woo-nfe'),
'default' => 'include_shipping',
'options' => array(
'include_shipping' => __('Include Shipping fees on tax calculation', 'woo-nfe'),
'exclude_shipping' => __('Exclude Shipping fees on tax calculation', 'woo-nfe'),
),
'class' => 'wc-enhanced-select',
'css' => 'min-width:300px;',
'desc_tip' => __('Tax Formation: total + shipping will considerate ship value on tax calculation. Total - shipping will not considerate ship value on tax calculation.', 'woo-nfe'),
),
'nfe_events_title' => array(
'title' => __( 'NFe.io Webkook Setup', 'woo-nfe' ),
'title' => __( 'NFe.io Webhook Setup', 'woo-nfe' ),
'type' => 'title',
),
'nfe_webhook_url' => array(
Expand Down
Binary file added languages/en.mo
Binary file not shown.
Loading

0 comments on commit a618b26

Please sign in to comment.