Plugin Directory

Changeset 3086710


Ignore:
Timestamp:
05/14/2024 07:38:34 PM (23 months ago)
Author:
kamilml
Message:

3.1.16

Location:
apisunat
Files:
62 added
5 edited

Legend:

Unmodified
Added
Removed
  • apisunat/trunk/README.txt

    r2979275 r3086710  
    55Requires at least: 5.8
    66Tested up to: 6.3.2
    7 Stable tag: 1.3.15
     7Stable tag: 1.3.16
    88Requires PHP: 7.4
    99License: GPLv3 or later
     
    7676== Changelog ==
    7777
     78= 1.3.16 =
     79* Se agregó configuración de IGV al 10% y 18%
     80* Se corrigió un error que causaba doble emisión cuando se tenía más de una instancia del servidor
     81
    7882= 1.3.15 =
    7983* Correcciones en textos y descripciones varios
  • apisunat/trunk/admin/class-apisunat-admin.php

    r2979275 r3086710  
    112112                // return $bytes;
    113113
    114                 if(get_option('apisunat_logtail_token')){
     114                if (get_option('apisunat_logtail_token')) {
    115115
    116116                    $url = 'https://in.logs.betterstack.com';
     
    127127                        CURLOPT_HTTPHEADER     => array(
    128128                            'Content-Type: application/json',
    129                             'Authorization: Bearer '. get_option('apisunat_logtail_token')
     129                            'Authorization: Bearer ' . get_option('apisunat_logtail_token')
    130130                        ),
    131131                        CURLOPT_POSTFIELDS      => json_encode($data),
     
    141141                    curl_close($curl);
    142142                }
    143 
    144                
    145 
    146143            }
    147144        }
     
    156153
    157154            if ('auto' === $new_value) {
    158                 plugin_log("Registro de fecha cambio a automatico: ". $fecha_actual);
     155                plugin_log("Registro de fecha cambio a automatico: " . $fecha_actual);
    159156                update_option('apisunat_fecha', $fecha_actual);
    160157            }
     
    479476    public function apisunat_check_status_on_schedule(): void
    480477    {
    481 
    482         if (get_option('apisunat_forma_envio') === 'auto') {
    483 
    484             if (!get_option('apisunat_fecha')) {
    485                 update_option('apisunat_fecha', current_time('mysql'));
    486             }
    487 
    488             $fecha_limite = get_option('apisunat_fecha');
    489 
    490             $orders_completed = wc_get_orders(
    491                 array(
    492                     'orderby' => 'id',
    493                     'order' => 'DESC',
    494                     'limit'  => 60,
    495                     'status' => 'wc-completed',
    496                     // 'date_query' => array(
    497                     //  array(
    498                     //      'after' => date('Y-m-d H:i:s', $fecha_limite), // Formatea la fecha límite.
    499                     //  ),
    500                     // ),
    501                     'date_after'   => $fecha_limite,
    502                     'meta_key'     => 'apisunat_document_status',
    503                     'meta_compare' => 'NOT EXISTS',
    504                 )
    505             );
    506             plugin_log($fecha_limite . ' FECHA LIMITE / Ejecutando apisunat_check_status_on_schedule ' . count($orders_completed) . ' órdenes');
    507 
    508             foreach ($orders_completed as $order) {
    509                 plugin_log("orders_completed foreach: ". $order->get_id());
    510 
    511                 if ($order->meta_exists('_billing_apisunat_meta_data_mapping')) {
    512                     plugin_log("send_apisunat_order: ". $order->get_id());
    513                     $this->send_apisunat_order($order->get_id());
    514                    
    515                 }
    516             }
    517         }
    518 
    519         $orders = wc_get_orders(
    520             array(
    521                 'limit'        => -1, // Query all orders.
    522                 'meta_key'     => 'apisunat_document_status', // The postmeta key field.
    523                 'meta_value'   => 'PENDIENTE', // The postmeta key field.
    524                 'meta_compare' => '=', // The comparison argument.
    525             )
    526         );
    527 
    528         foreach ($orders as $order) {
    529             if ($order->meta_exists('apisunat_document_id') && $order->get_meta('apisunat_document_status') === 'PENDIENTE') {
    530                 $request = wp_remote_get(self::API_URL . '/documents/' . $order->get_meta('apisunat_document_id') . '/getById');
    531                 $data    = json_decode(wp_remote_retrieve_body($request), true);
    532                 $status  = $data['status'];
    533 
    534                 $order->add_order_note(' El documento se encuentra en estado: ' . $status);
    535                 update_post_meta($order->get_id(), 'apisunat_document_status', $status);
    536             }
    537         }
     478        plugin_log('Ejecutando apisunat_check_status_on_schedule 111');
     479        global $wpdb;
     480        $table_name = $wpdb->prefix . 'semaphore';
     481        if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
     482            $sql = "CREATE TABLE $table_name (id INT PRIMARY KEY, is_locked BOOLEAN)";
     483            $wpdb->query($sql);
     484            $wpdb->insert($table_name, array('id' => 1, 'is_locked' => false));
     485        }
     486        $result = $wpdb->query($wpdb->prepare("UPDATE $table_name SET is_locked = TRUE WHERE id = 1 AND is_locked = FALSE"));
     487        sleep ( rand ( 1, 5));
     488        plugin_log('Ejecutando apisunat_check_status_on_schedule 222 / result: ' . $result);
     489
     490        if ($result > 0) {
     491            if (get_option('apisunat_forma_envio') === 'auto') {
     492
     493                if (!get_option('apisunat_fecha')) {
     494                    update_option('apisunat_fecha', current_time('mysql'));
     495                }
     496
     497                $fecha_limite = get_option('apisunat_fecha');
     498
     499                $orders_completed = wc_get_orders(
     500                    array(
     501                        'orderby' => 'id',
     502                        'order' => 'DESC',
     503                        'limit' => 60,
     504                        'status' => 'wc-completed',
     505                        // 'date_query' => array(
     506                        //  array(
     507                        //      'after' => date('Y-m-d H:i:s', $fecha_limite), // Formatea la fecha límite.
     508                        //  ),
     509                        // ),
     510                        'date_after' => $fecha_limite,
     511                        'meta_key' => 'apisunat_document_status',
     512                        'meta_compare' => 'NOT EXISTS',
     513                    )
     514                );
     515                plugin_log($fecha_limite . ' FECHA LIMITE / Ejecutando apisunat_check_status_on_schedule ' . count($orders_completed) . ' órdenes');
     516
     517                foreach ($orders_completed as $order) {
     518                    plugin_log("orders_completed foreach: " . $order->get_id());
     519
     520                    if ($order->meta_exists('_billing_apisunat_meta_data_mapping')) {
     521                        plugin_log("send_apisunat_order: " . $order->get_id());
     522                        $this->send_apisunat_order($order->get_id());
     523
     524                    }
     525                }
     526            }
     527
     528            $orders = wc_get_orders(
     529                array(
     530                    'limit' => -1, // Query all orders.
     531                    'meta_key' => 'apisunat_document_status', // The postmeta key field.
     532                    'meta_value' => 'PENDIENTE', // The postmeta key field.
     533                    'meta_compare' => '=', // The comparison argument.
     534                )
     535            );
     536
     537            foreach ($orders as $order) {
     538                if ($order->meta_exists('apisunat_document_id') && $order->get_meta('apisunat_document_status') === 'PENDIENTE') {
     539                    $request = wp_remote_get(self::API_URL . '/documents/' . $order->get_meta('apisunat_document_id') . '/getById');
     540                    $data = json_decode(wp_remote_retrieve_body($request), true);
     541                    $status = $data['status'];
     542
     543                    $order->add_order_note(' El documento se encuentra en estado: ' . $status);
     544                    update_post_meta($order->get_id(), 'apisunat_document_status', $status);
     545                }
     546            }
     547
     548            $wpdb->query($wpdb->prepare("UPDATE $table_name SET is_locked = FALSE WHERE id = 1"));
     549        } else {
     550            $wpdb->query($wpdb->prepare("UPDATE $table_name SET is_locked = FALSE WHERE id = 1"));
     551        }
    538552    }
    539553
     
    548562        if (get_option('apisunat_forma_envio') === 'auto') {
    549563            // add_action( 'woocommerce_order_status_completed', array( $this, 'send_apisunat_order' ), 10, 1 );
    550             add_action('woocommerce_order_status_changed', array($this, 'apisunat_order_status_change'), 10, 3);
     564            // add_action('woocommerce_order_status_changed', array($this, 'apisunat_order_status_change'), 10, 3); // TEMPORALMENTE COMENTADO
    551565        }
    552566        add_action('wp_ajax_send_apisunat_order', array($this, 'send_apisunat_order'), 10, 1);
     
    10431057                    '20' => 'EXONERADO',
    10441058                    '30' => 'INAFECTO',
     1059                ),
     1060                'group'    => 'apisunat_general_settings',
     1061                'section'  => 'apisunat_data_section',
     1062            ),
     1063            array(
     1064                'title'    => 'Factor IGV (solo para GRAVADO): ',
     1065                'type'     => 'select',
     1066                'name'     => 'apisunat_factor_tributo',
     1067                'id'       => 'apisunat_factor_tributo',
     1068                'required' => true,
     1069                'options'  => array(
     1070                    '18' => '18',
     1071                    '10' => '10',
    10451072                ),
    10461073                'group'    => 'apisunat_general_settings',
     
    13691396        $send_data['plugin_data']['serie03']       = get_option('apisunat_serie_boleta');
    13701397        $send_data['plugin_data']['affectation']   = get_option('apisunat_tipo_tributo');
     1398        $send_data['plugin_data']['affectation_factor']   = get_option('apisunat_factor_tributo');
    13711399        $send_data['plugin_data']['issueTime']     = get_option('apisunat_include_time');
    13721400        $send_data['plugin_data']['shipping_cost'] = get_option('apisunat_shipping_cost');
  • apisunat/trunk/apisunat.php

    r2979275 r3086710  
    1616 * Plugin URI:        https://github.com/kamilml/apisunat-for-woocommerce
    1717 * Description:       Emite tus comprobantes electrónicos para SUNAT-PERU directamente desde tu tienda en WooCommerce.
    18  * Version:           1.3.15
     18 * Version:           1.3.16
    1919 * Author:            APISUNAT
    2020 * Author URI:        https://apisunat.com/
     
    4646}
    4747
     48// Warning for incompatibility with HPOS
     49add_action( 'before_woocommerce_init', function() {
     50    if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
     51        \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, false );
     52    }
     53} );
     54
    4855/**
    4956 * Currently plugin version.
    5057 */
    51 const APISUNAT_VERSION = '1.2.1';
     58const APISUNAT_VERSION = '1.3.16';
    5259
    5360/**
  • apisunat/trunk/includes/class-apisunat-activator.php

    r2979254 r3086710  
    3232        // }
    3333
    34         if ( ! wp_next_scheduled( 'apisunat_one_minute_event' ) ) {
    35             wp_schedule_event( time(), 'every_minute', 'apisunat_one_minute_event' );
     34        if (!wp_next_scheduled('apisunat_one_minute_event')) {
     35            wp_schedule_event(time(), 'every_minute', 'apisunat_one_minute_event');
     36        }
     37
     38        global $wpdb;
     39        $table_name = $wpdb->prefix . 'semaphore';
     40
     41        if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
     42            $sql = "CREATE TABLE $table_name (id INT PRIMARY KEY, is_locked BOOLEAN)";
     43            $wpdb->query($sql);
     44            $wpdb->insert($table_name, array('id' => 1, 'is_locked' => false));
    3645        }
    3746    }
    3847}
    39 
  • apisunat/trunk/includes/class-apisunat.php

    r2979254 r3086710  
    154154        $plugin_admin = new Apisunat_Admin( $this->get_plugin_name(), $this->get_version() );
    155155
     156        function agregar_intervalo_cron_personalizado($schedules) {
     157            $schedules['apisunat_every_one_minute'] = array(
     158                'interval' => 60,
     159                'display' => 'Cada 1 minuto',
     160            );
     161            return $schedules;
     162        }
     163       
     164        add_filter('cron_schedules', 'agregar_intervalo_cron_personalizado');
     165
    156166        $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
    157167        $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
Note: See TracChangeset for help on using the changeset viewer.