hesabixWCPlugin/admin/partials/hesabix-admin-setting.php

2646 lines
153 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Hesabix Admin Setting
*
* @package Hesabix
* @author Mohammad Rezai
* @author URI https://pirouz.xyz
* @since 1.0.0
*/
include_once(plugin_dir_path(__DIR__) . 'services/hesabixLogService.php');
error_reporting(0);
class Hesabix_Setting
{
public static function init()
{
add_action('hesabix_home_setting', array(__CLASS__, 'hesabix_home_setting'));
add_action('hesabix_catalog_setting', array(__CLASS__, 'hesabix_catalog_setting'));
add_action('hesabix_catalog_setting_save_field', array(
__CLASS__,
'hesabix_catalog_setting_save_field'
));
add_action('hesabix_customers_setting', array(__CLASS__, 'hesabix_customers_setting'));
add_action('hesabix_invoice_setting', array(__CLASS__, 'hesabix_invoice_setting'));
add_action('hesabix_api_setting', array(__CLASS__, 'hesabix_api_setting'));
add_action('hesabix_sync_setting', array(__CLASS__, 'hesabix_sync_setting'));
add_action('hesabix_log_setting', array(__CLASS__, 'hesabix_log_setting'));
add_action('hesabix_extra_setting', array(__CLASS__, 'hesabix_extra_setting'));
add_action('hesabix_extra_setting_save_field', array(
__CLASS__,
'hesabix_extra_setting_save_field'
));
}
public static function hesabix_home_setting()
{
?>
<div class="hesabix-card">
<div class="hesabix-card-header">
<h2 class="hesabix-card-title"><?php echo __('Current Statistics', 'hesabix'); ?></h2>
<p class="hesabix-card-subtitle">
<?php echo __('Overview of your store and Hesabix integration', 'hesabix'); ?>
</p>
</div>
<div class="hesabix-grid hesabix-grid-4" id="hesabix-stats-container">
<div class="hesabix-feature-card">
<div class="hesabix-feature-icon">
<svg width="40" height="40" viewBox="0 0 24 24" fill="currentColor">
<path
d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-5 14H7v-2h7v2zm3-4H7v-2h10v2zm0-4H7V7h10v2z" />
</svg>
</div>
<h3 id="hesabix-home-products-count"><span class="hesabix-spinner-small"
style="display:inline-block;vertical-align:middle;"></span></h3>
<p id="hesabix-home-products-label"></p>
</div>
<div class="hesabix-feature-card">
<div class="hesabix-feature-icon">
<svg width="40" height="40" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z" />
</svg>
</div>
<h3 id="hesabix-home-customers-count"><span class="hesabix-spinner-small"
style="display:inline-block;vertical-align:middle;"></span></h3>
<p id="hesabix-home-customers-label"></p>
</div>
<div class="hesabix-feature-card">
<div class="hesabix-feature-icon">
<svg width="40" height="40" viewBox="0 0 24 24" fill="currentColor">
<path
d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-5 14H7v-2h7v2zm3-4H7v-2h10v2zm0-4H7V7h10v2z" />
</svg>
</div>
<h3 id="hesabix-home-orders-count"><span class="hesabix-spinner-small"
style="display:inline-block;vertical-align:middle;"></span></h3>
<p id="hesabix-home-orders-label"></p>
</div>
<div class="hesabix-feature-card" id="hesabix-home-connection-card">
<div class="hesabix-feature-icon">
<svg width="40" height="40" viewBox="0 0 24 24" fill="currentColor">
<path id="hesabix-home-connection-icon" d="" />
</svg>
</div>
<h3 id="hesabix-home-connection-text"><span class="hesabix-spinner-small"
style="display:inline-block;vertical-align:middle;"></span></h3>
<p id="hesabix-home-status-label"></p>
</div>
</div>
</div>
<!-- <div class="hesabix-card">
<div class="hesabix-card-header">
<h2 class="hesabix-card-title"><?php echo __('Setup Guide', 'hesabix'); ?></h2>
<p class="hesabix-card-subtitle"><?php echo __('Follow these steps to complete the integration', 'hesabix'); ?></p>
</div>
<div class="hesabix-setup-steps">
<div class="hesabix-setup-step">
<div class="hesabix-step-number">1</div>
<div class="hesabix-step-content">
<h4><?php echo __('Register in Hesabix', 'hesabix'); ?></h4>
<p><?php echo __('Visit hesabix.ir and create a free account. Choose your business and get your API keys from the settings menu.', 'hesabix'); ?></p>
</div>
</div>
<div class="hesabix-setup-step">
<div class="hesabix-step-number">2</div>
<div class="hesabix-step-content">
<h4><?php echo __('Configure API Settings', 'hesabix'); ?></h4>
<p><?php echo __('Go to the API tab and enter your Hesabix API key, business ID, and fiscal year information.', 'hesabix'); ?></p>
</div>
</div>
<div class="hesabix-setup-step">
<div class="hesabix-step-number">3</div>
<div class="hesabix-step-content">
<h4><?php echo __('Configure Sync Settings', 'hesabix'); ?></h4>
<p><?php echo __('Set up your catalog, customer, and invoice synchronization preferences in their respective tabs.', 'hesabix'); ?></p>
</div>
</div>
<div class="hesabix-setup-step">
<div class="hesabix-step-number">4</div>
<div class="hesabix-step-content">
<h4><?php echo __('Start Synchronization', 'hesabix'); ?></h4>
<p><?php echo __('Use the sync tab to manually synchronize your existing data or let the automatic sync handle new data.', 'hesabix'); ?></p>
</div>
</div>
</div>
</div> -->
<div class="hesabix-card">
<div class="hesabix-card-header">
<h2 class="hesabix-card-title"><?php echo __('Important Warnings', 'hesabix'); ?></h2>
<p class="hesabix-card-subtitle"><?php echo __('Please read these warnings carefully', 'hesabix'); ?></p>
</div>
<div class="hesabix-alert hesabix-alert-danger d-flex flex-column gap-2 align-items-start">
<div class="d-flex gap-2 align-items-center">
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm5 13.59L15.59 17 12 13.41 8.41 17 7 15.59 10.59 12 7 8.41 8.41 7 12 10.59 15.59 7 17 8.41 13.41 12 17 15.59z" />
</svg>
<strong><?php echo __('Code Management', 'hesabix'); ?></strong>
</div>
<div>
<p><?php echo __('The plugin uses product codes, customer codes, and invoice numbers for identification. Do not change these codes in Hesabix after they have been created.', 'hesabix'); ?>
</p>
</div>
</div>
<div class="hesabix-alert hesabix-alert-warning d-flex flex-column gap-2 align-items-start">
<div class="d-flex gap-2 align-items-center">
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
<path d="M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z" />
</svg>
<strong><?php echo __('Plugin Removal', 'hesabix'); ?></strong>
</div>
<div>
<p><?php echo __('Removing the plugin from WordPress will delete the relationship table from the database and all connections will be lost.', 'hesabix'); ?>
</p>
</div>
</div>
</div>
<div class="hesabix-card">
<div class="hesabix-card-header">
<h2 class="hesabix-card-title"><?php echo __('Need Help?', 'hesabix'); ?></h2>
<p class="hesabix-card-subtitle"><?php echo __('Get support and documentation', 'hesabix'); ?></p>
</div>
<div class="hesabix-btn-group">
<a href="https://hesabix.ir/help/topics/%D8%A7%D9%81%D8%B2%D9%88%D9%86%D9%87/%D9%88%D9%88%DA%A9%D8%A7%D9%85%D8%B1%D8%B3"
target="_blank" class="hesabix-btn hesabix-btn-info">
<svg width="16px" height="16px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"
transform="scale(-1,1)">
<path
d="M3 3V2H2V3H3ZM12.2929 13.7071C12.6834 14.0976 13.3166 14.0976 13.7071 13.7071C14.0976 13.3166 14.0976 12.6834 13.7071 12.2929L12.2929 13.7071ZM4 11V3H2V11H4ZM3 4H11V2H3V4ZM2.29289 3.70711L12.2929 13.7071L13.7071 12.2929L3.70711 2.29289L2.29289 3.70711Z"
fill="currentColor" />
<path
d="M4 15V15C4 16.8692 4 17.8038 4.40192 18.5C4.66523 18.9561 5.04394 19.3348 5.5 19.5981C6.19615 20 7.13077 20 9 20H14C16.8284 20 18.2426 20 19.1213 19.1213C20 18.2426 20 16.8284 20 14V9C20 7.13077 20 6.19615 19.5981 5.5C19.3348 5.04394 18.9561 4.66523 18.5 4.40192C17.8038 4 16.8692 4 15 4V4"
stroke="currentColor" stroke-width="2" stroke-linecap="round" />
</svg>
<?php echo __('Complete Guide', 'hesabix'); ?>
</a>
<a href="https://app.hesabix.ir" target="_blank" class="hesabix-btn hesabix-btn-success">
<svg width="16px" height="16px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"
transform="scale(-1,1)">
<path
d="M3 3V2H2V3H3ZM12.2929 13.7071C12.6834 14.0976 13.3166 14.0976 13.7071 13.7071C14.0976 13.3166 14.0976 12.6834 13.7071 12.2929L12.2929 13.7071ZM4 11V3H2V11H4ZM3 4H11V2H3V4ZM2.29289 3.70711L12.2929 13.7071L13.7071 12.2929L3.70711 2.29289L2.29289 3.70711Z"
fill="currentColor" />
<path
d="M4 15V15C4 16.8692 4 17.8038 4.40192 18.5C4.66523 18.9561 5.04394 19.3348 5.5 19.5981C6.19615 20 7.13077 20 9 20H14C16.8284 20 18.2426 20 19.1213 19.1213C20 18.2426 20 16.8284 20 14V9C20 7.13077 20 6.19615 19.5981 5.5C19.3348 5.04394 18.9561 4.66523 18.5 4.40192C17.8038 4 16.8692 4 15 4V4"
stroke="currentColor" stroke-width="2" stroke-linecap="round" />
</svg>
<?php echo __('Go to Hesabix', 'hesabix'); ?>
</a>
<a href="https://hesabix.ir" target="_blank" class="hesabix-btn hesabix-btn-outline">
<svg width="16px" height="16px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"
transform="scale(-1,1)">
<path
d="M3 3V2H2V3H3ZM12.2929 13.7071C12.6834 14.0976 13.3166 14.0976 13.7071 13.7071C14.0976 13.3166 14.0976 12.6834 13.7071 12.2929L12.2929 13.7071ZM4 11V3H2V11H4ZM3 4H11V2H3V4ZM2.29289 3.70711L12.2929 13.7071L13.7071 12.2929L3.70711 2.29289L2.29289 3.70711Z"
fill="currentColor" />
<path
d="M4 15V15C4 16.8692 4 17.8038 4.40192 18.5C4.66523 18.9561 5.04394 19.3348 5.5 19.5981C6.19615 20 7.13077 20 9 20H14C16.8284 20 18.2426 20 19.1213 19.1213C20 18.2426 20 16.8284 20 14V9C20 7.13077 20 6.19615 19.5981 5.5C19.3348 5.04394 18.9561 4.66523 18.5 4.40192C17.8038 4 16.8692 4 15 4V4"
stroke="currentColor" stroke-width="2" stroke-linecap="round" />
</svg>
<?php echo __('Visit Website', 'hesabix'); ?>
</a>
</div>
</div>
<div class="hesabix-d-none">
<div class="hesabix-card">
<div class="hesabix-card-header">
<h2 class="hesabix-card-title"><?php echo __('Plugin Tutorial Video', 'hesabix'); ?></h2>
</div>
<video controls poster="https://hesabix.ir/assets/woocommerc-plugin-help-cover.jpg" id="hesabix-tutorial-video"
class="hesabix-w-100">
<source src="https://hesabix.ir/file/woocommerce/woocommerce-plugin-tutorial.mp4" type="video/mp4">
</video>
</div>
</div>
<?php
}
public static function hesabix_extra_setting_fields()
{
$fields[] = array(
'desc' => __('Enable or Disable Debug Mode', 'hesabix'),
'id' => 'hesabix_debug_mode_checkbox',
'default' => 'no',
'type' => 'checkbox',
);
return $fields;
}
public static function hesabix_extra_setting()
{
?>
<div class="hesabix-card hesabix-extra-card" style="margin-bottom: 24px;">
<div class="hesabix-alert hesabix-alert-warning hesabix-f" style="margin-bottom: 0;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"
style="vertical-align: middle; margin-left: 8px;">
<path d="M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z" />
</svg>
<?php echo __('This page is for advanced plugin settings.', 'hesabix'); ?>
</div>
<h3 class="hesabix-tab-page-title" style="margin-top: 24px;"><?php echo __('Extra Settings', 'hesabix'); ?>
</h3>
<?php
$hesabi_setting_fields = self::hesabix_extra_setting_fields();
$Html_output = new Hesabix_Html_output();
global $plugin_version;
if (defined('HESABIX_VERSION')) {
$plugin_version = constant('HESABIX_VERSION');
}
$server_php_version = phpversion();
$wordpress_version = get_bloginfo('version');
$woocommerce_version = defined('WC_VERSION') ? WC_VERSION : __('Inactive', 'hesabix');
global $wpdb;
$mysql_version = $wpdb->db_version();
$max_execution_time = ini_get('max_execution_time');
$memory_limit = ini_get('memory_limit');
$upload_max_filesize = ini_get('upload_max_filesize');
$post_max_size = ini_get('post_max_size');
$is_connected = get_option('hesabix_account_api') ? true : false;
$connection_status = $is_connected ? __('Connected', 'hesabix') : __('Disconnected', 'hesabix');
$connection_color = $is_connected ? 'white' : 'white';
$business_info = array();
if ($is_connected) {
try {
$subscription_info = self::getSubscriptionInfo();
if (!empty($subscription_info['businessName'])) {
$business_info = $subscription_info;
}
} catch (Exception $e) {
}
}
?>
<div class="hesabix-card hesabix-version-card hesabix-fade-in" style="margin-bottom: 48px;">
<div class="hesabix-version-info">
<div style="display:flex;justify-content:center;align-items:center;margin-bottom:24px;">
<div class="hesabix-version-icon">
<svg width="40" height="40" fill="currentColor" viewBox="0 0 175 175">
<path
d="M0 0 C8.18911268 -0.04651976 16.37816933 -0.08196836 24.56738186 -0.10362434 C28.37073399 -0.1140227 32.17399514 -0.12810896 35.97729492 -0.15087891 C39.65369106 -0.17274917 43.33000016 -0.18459825 47.00645638 -0.18975449 C48.40294831 -0.19342496 49.79943596 -0.20059186 51.19589043 -0.21146011 C70.52100326 -0.35576139 70.52100326 -0.35576139 77.875 4.9375 C78.95394531 5.69353516 78.95394531 5.69353516 80.0546875 6.46484375 C81.86022562 7.88969612 83.49355997 9.26143557 85 11 C85 11.66 85 12.32 85 13 C85.66 13 86.32 13 87 13 C95.22733894 27.10400962 102.15873305 42.6164818 104 59 C96.75715618 63.31586256 89.47667122 67.35231517 81.8125 70.875 C68.75107607 76.90104562 55.90645412 83.25993579 44.15234375 91.6015625 C42 93 42 93 40 93 C40 93.66 40 94.32 40 95 C39.34 95 38.68 95 38 95 C37.7525 95.515625 37.505 96.03125 37.25 96.5625 C36 99 36 99 33.875 102.0625 C31.15545354 106.80637052 31.21495525 111.68893195 32 117 C34.32115958 121.99942063 36.86818998 124.08814921 42 126 C48.39527592 127.20939892 54.78386689 127.21978588 61.27734375 127.31640625 C62.4438295 127.33718735 63.61031525 127.35796844 64.81214905 127.37937927 C68.52054224 127.44450911 72.22900332 127.50358917 75.9375 127.5625 C78.45899126 127.60572001 80.98047577 127.6493354 83.50195312 127.69335938 C89.66789799 127.80015284 95.83390967 127.9019857 102 128 C101.93941406 128.82717529 101.87882812 129.65435059 101.81640625 130.5065918 C101.34836605 136.96779677 100.90354848 143.42894793 100.5 149.89453125 C100.4175 151.19841797 100.335 152.50230469 100.25 153.84570312 C100.12331924 155.85577043 99.99676859 157.86584984 99.875 159.8762207 C99.75425015 161.86175392 99.62723905 163.84690331 99.5 165.83203125 C99.39171875 167.57577026 99.39171875 167.57577026 99.28125 169.35473633 C99 172 99 172 98 173 C96.4330281 173.10383049 94.86140929 173.13852298 93.29101562 173.14526367 C92.28486206 173.15164352 91.2787085 173.15802338 90.24206543 173.16459656 C89.14124634 173.16570938 88.04042725 173.1668222 86.90625 173.16796875 C85.77159302 173.17129715 84.63693604 173.17462555 83.46789551 173.17805481 C81.05005296 173.18313527 78.63220335 173.18546279 76.21435547 173.18530273 C72.57116456 173.1874579 68.92829221 173.20551329 65.28515625 173.22460938 C43.73078865 173.27698802 26.30867365 172.0953979 7 162 C7 161.34 7 160.68 7 160 C6.12021484 159.62294922 6.12021484 159.62294922 5.22265625 159.23828125 C2.72235663 157.84531995 1.29240124 156.35777594 -0.5625 154.1875 C-1.43068359 153.18783203 -1.43068359 153.18783203 -2.31640625 152.16796875 C-5.79457149 147.68912488 -7.61625501 143.53318556 -9.125 138.0625 C-9.45757813 136.87785156 -9.79015625 135.69320312 -10.1328125 134.47265625 C-14.39279807 117.41352483 -12.09195406 100.21053561 -3.76171875 84.74609375 C4.1957617 72.34230493 16.4411864 62.43966551 29.625 56.0625 C30.31142578 55.72476563 30.99785156 55.38703125 31.70507812 55.0390625 C38.085784 51.91646406 44.52696191 48.9261679 51 46 C51 45.01 51 44.02 51 43 C33.18 42.67 15.36 42.34 -3 42 C-1.83928571 11.82142857 -1.83928571 11.82142857 0 0 Z "
fill="currentColor" transform="translate(40,4)" />
</svg>
</div>
<div class="hesabix-version-title">
<?php echo __('Comprehensive Hesabix System Information', 'hesabix'); ?>
</div>
</div>
<div class="hesabix-version-section">
<div class="hesabix-version-section-title"><?php echo __('Main Information', 'hesabix'); ?></div>
<div class="hesabix-version-grid">
<div class="hesabix-version-row">
<span class="hesabix-version-label"><?php echo __('Plugin Version:', 'hesabix'); ?></span>
<span class="hesabix-version-value"><?php echo $plugin_version; ?></span>
</div>
<div class="hesabix-version-row">
<span class="hesabix-version-label"><?php echo __('Connection Status:', 'hesabix'); ?></span>
<span class="hesabix-version-value" style="color: <?php echo $connection_color; ?>;">
<?php echo $connection_status; ?>
</span>
</div>
<?php if (!empty($business_info['businessName'])): ?>
<div class="hesabix-version-row">
<span class="hesabix-version-label"><?php echo __('Business Name:', 'hesabix'); ?></span>
<span class="hesabix-version-value"><?php echo $business_info['businessName']; ?></span>
</div>
<?php endif; ?>
</div>
</div>
<div class="hesabix-version-section">
<div class="hesabix-version-section-title"><?php echo __('Server Information', 'hesabix'); ?></div>
<div class="hesabix-version-grid">
<div class="hesabix-version-row">
<span class="hesabix-version-label"><?php echo __('PHP Version:', 'hesabix'); ?></span>
<span class="hesabix-version-value"><?php echo $server_php_version; ?></span>
</div>
<div class="hesabix-version-row">
<span class="hesabix-version-label"><?php echo __('WordPress Version:', 'hesabix'); ?></span>
<span class="hesabix-version-value"><?php echo $wordpress_version; ?></span>
</div>
<div class="hesabix-version-row">
<span class="hesabix-version-label"><?php echo __('WooCommerce Version:', 'hesabix'); ?></span>
<span class="hesabix-version-value"><?php echo $woocommerce_version; ?></span>
</div>
<div class="hesabix-version-row">
<span class="hesabix-version-label"><?php echo __('MySQL Version:', 'hesabix'); ?></span>
<span class="hesabix-version-value"><?php echo $mysql_version; ?></span>
</div>
</div>
</div>
<div class="hesabix-version-section">
<div class="hesabix-version-section-title"><?php echo __('Server Settings', 'hesabix'); ?></div>
<div class="hesabix-version-grid">
<div class="hesabix-version-row">
<span
class="hesabix-version-label"><?php echo __('Maximum Execution Time:', 'hesabix'); ?></span>
<span class="hesabix-version-value"><?php echo $max_execution_time; ?>
<?php echo __('seconds', 'hesabix'); ?></span>
</div>
<div class="hesabix-version-row">
<span class="hesabix-version-label"><?php echo __('Memory Limit:', 'hesabix'); ?></span>
<span class="hesabix-version-value"><?php echo $memory_limit; ?></span>
</div>
<div class="hesabix-version-row">
<span class="hesabix-version-label"><?php echo __('Maximum Upload:', 'hesabix'); ?></span>
<span class="hesabix-version-value"><?php echo $upload_max_filesize; ?></span>
</div>
<div class="hesabix-version-row">
<span class="hesabix-version-label"><?php echo __('Maximum POST:', 'hesabix'); ?></span>
<span class="hesabix-version-value"><?php echo $post_max_size; ?></span>
</div>
</div>
</div>
</div>
</div>
<form id="hesabix_extra_form" enctype="multipart/form-data" action="" method="post">
<div id="extra-settings-message" style="display:none;"></div>
<div class="hesabix-section">
<?php $Html_output->init($hesabi_setting_fields); ?>
<div class="hesabix-grid hesabix-grid-2" style="margin-top:24px;">
<div class="hesabix-card hesabix-fade-in" style="background:#f8f9fa;">
<label class="hesabix-form-label" for="hesabix_set_rpp_for_sync_products_into_hesabix">
<?php echo __('Number of concurrent requests for synchronizing WooCommerce products in Hesabix', 'hesabix'); ?>
</label>
<select class="hesabix-form-control" name="hesabix_set_rpp_for_sync_products_into_hesabix"
id="hesabix_set_rpp_for_sync_products_into_hesabix">
<option value="-1" <?php if (!get_option('hesabix_set_rpp_for_sync_products_into_hesabix'))
echo 'selected'; ?>><?php echo __('Select', 'hesabix'); ?></option>
<option value="50" <?php if (get_option('hesabix_set_rpp_for_sync_products_into_hesabix') == '50')
echo 'selected'; ?>>
50</option>
<option value="100" <?php if (get_option('hesabix_set_rpp_for_sync_products_into_hesabix') == '100')
echo 'selected'; ?>>
100</option>
<option value="150" <?php if (get_option('hesabix_set_rpp_for_sync_products_into_hesabix') == '150')
echo 'selected'; ?>>
150</option>
<option value="200" <?php if (get_option('hesabix_set_rpp_for_sync_products_into_hesabix') == '200')
echo 'selected'; ?>>
200</option>
<option value="300" <?php if (get_option('hesabix_set_rpp_for_sync_products_into_hesabix') == '300')
echo 'selected'; ?>>
300</option>
<option value="400" <?php if (get_option('hesabix_set_rpp_for_sync_products_into_hesabix') == '400')
echo 'selected'; ?>>
400</option>
<option value="500" <?php if (get_option('hesabix_set_rpp_for_sync_products_into_hesabix') == '500')
echo 'selected'; ?>>
500</option>
</select>
<span class="hesabix-form-text"><?php echo __('Plugin default: 500', 'hesabix'); ?></span>
</div>
<div class="hesabix-card hesabix-fade-in" style="background:#f8f9fa;">
<label class="hesabix-form-label" for="hesabix_set_rpp_for_sync_products_into_woocommerce">
<?php echo __('Number of concurrent requests for synchronizing Hesabix products in WooCommerce', 'hesabix'); ?>
</label>
<select class="hesabix-form-control" name="hesabix_set_rpp_for_sync_products_into_woocommerce"
id="hesabix_set_rpp_for_sync_products_into_woocommerce">
<option value="-1" <?php if (!get_option('hesabix_set_rpp_for_sync_products_into_woocommerce'))
echo 'selected'; ?>>
<?php echo __('Select', 'hesabix'); ?>
</option>
<option value="50" <?php if (get_option('hesabix_set_rpp_for_sync_products_into_woocommerce') == '50')
echo 'selected'; ?>>50</option>
<option value="100" <?php if (get_option('hesabix_set_rpp_for_sync_products_into_woocommerce') == '100')
echo 'selected'; ?>>100</option>
<option value="150" <?php if (get_option('hesabix_set_rpp_for_sync_products_into_woocommerce') == '150')
echo 'selected'; ?>>150</option>
<option value="200" <?php if (get_option('hesabix_set_rpp_for_sync_products_into_woocommerce') == '200')
echo 'selected'; ?>>200</option>
<option value="300" <?php if (get_option('hesabix_set_rpp_for_sync_products_into_woocommerce') == '300')
echo 'selected'; ?>>300</option>
<option value="400" <?php if (get_option('hesabix_set_rpp_for_sync_products_into_woocommerce') == '400')
echo 'selected'; ?>>400</option>
<option value="500" <?php if (get_option('hesabix_set_rpp_for_sync_products_into_woocommerce') == '500')
echo 'selected'; ?>>500</option>
</select>
<span class="hesabix-form-text"><?php echo "پیش‌فرض افزونه: 200"; ?></span>
</div>
<!-- <div class="hesabix-card hesabix-fade-in" style="background:#f8f9fa;">
<label class="hesabix-form-label" for="hesabix_set_rpp_for_import_products">
<?php echo __('تعداد درخواست همزمان برای ایمپورت محصولات', 'hesabix'); ?>
</label>
<select class="hesabix-form-control" name="hesabix_set_rpp_for_import_products"
id="hesabix_set_rpp_for_import_products">
<option value="-1" <?php if (!get_option('hesabix_set_rpp_for_import_products'))
echo 'selected'; ?>><?php echo __('Select', 'hesabix'); ?></option>
<option value="50" <?php if (get_option('hesabix_set_rpp_for_import_products') == '50')
echo 'selected'; ?>>50</option>
<option value="100" <?php if (get_option('hesabix_set_rpp_for_import_products') == '100')
echo 'selected'; ?>>100</option>
</select>
<span class="hesabix-form-text"><?php echo __('Plugin default: 100', 'hesabix'); ?></span>
</div>
<div class="hesabix-card hesabix-fade-in" style="background:#f8f9fa;">
<label class="hesabix-form-label" for="hesabix_set_rpp_for_export_products">
<?php echo __('تعداد درخواست همزمان برای اکسپورت محصولات', 'hesabix'); ?>
</label>
<select class="hesabix-form-control" name="hesabix_set_rpp_for_export_products"
id="hesabix_set_rpp_for_export_products">
<option value="-1" <?php if (!get_option('hesabix_set_rpp_for_export_products'))
echo 'selected'; ?>><?php echo __('Select', 'hesabix'); ?></option>
<option value="50" <?php if (get_option('hesabix_set_rpp_for_export_products') == '50')
echo 'selected'; ?>>50</option>
<option value="100" <?php if (get_option('hesabix_set_rpp_for_export_products') == '100')
echo 'selected'; ?>>100</option>
<option value="150" <?php if (get_option('hesabix_set_rpp_for_export_products') == '150')
echo 'selected'; ?>>150</option>
<option value="200" <?php if (get_option('hesabix_set_rpp_for_export_products') == '200')
echo 'selected'; ?>>200</option>
<option value="300" <?php if (get_option('hesabix_set_rpp_for_export_products') == '300')
echo 'selected'; ?>>300</option>
<option value="400" <?php if (get_option('hesabix_set_rpp_for_export_products') == '400')
echo 'selected'; ?>>400</option>
<option value="500" <?php if (get_option('hesabix_set_rpp_for_export_products') == '500')
echo 'selected'; ?>>500</option>
</select>
<span class="hesabix-form-text"><?php echo __('Plugin default: 500', 'hesabix'); ?></span>
</div>
<div class="hesabix-card hesabix-fade-in" style="background:#f8f9fa;">
<label class="hesabix-form-label" for="hesabix_set_rpp_for_export_opening_products">
<?php echo __('تعداد درخواست همزمان برای اکسپورت موجودی اولیه محصولات', 'hesabix'); ?>
</label>
<select class="hesabix-form-control" name="hesabix_set_rpp_for_export_opening_products"
id="hesabix_set_rpp_for_export_opening_products">
<option value="-1" <?php if (!get_option('hesabix_set_rpp_for_export_opening_products'))
echo 'selected'; ?>><?php echo __('Select', 'hesabix'); ?></option>
<option value="50" <?php if (get_option('hesabix_set_rpp_for_export_opening_products') == '50')
echo 'selected'; ?>>50</option>
<option value="100" <?php if (get_option('hesabix_set_rpp_for_export_opening_products') == '100')
echo 'selected'; ?>>
100</option>
<option value="150" <?php if (get_option('hesabix_set_rpp_for_export_opening_products') == '150')
echo 'selected'; ?>>
150</option>
<option value="200" <?php if (get_option('hesabix_set_rpp_for_export_opening_products') == '200')
echo 'selected'; ?>>
200</option>
<option value="300" <?php if (get_option('hesabix_set_rpp_for_export_opening_products') == '300')
echo 'selected'; ?>>
300</option>
<option value="400" <?php if (get_option('hesabix_set_rpp_for_export_opening_products') == '400')
echo 'selected'; ?>>
400</option>
<option value="500" <?php if (get_option('hesabix_set_rpp_for_export_opening_products') == '500')
echo 'selected'; ?>>
500</option>
</select>
<span class="hesabix-form-text"><?php echo __('Plugin default: 500', 'hesabix'); ?></span>
</div>
</div> -->
</div>
<div class="hesabix-form-actions">
<button type="button" id="ajax-save-extra-settings" class="hesabix-btn hesabix-btn-primary">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" />
</svg>
<?php echo __('Save Changes', 'hesabix'); ?>
</button>
</div>
</form>
</div>
<?php
}
public static function hesabix_extra_setting_save_field()
{
$fields = Hesabix_Setting::hesabix_extra_setting_fields();
$Html_output = new Hesabix_Html_output();
$Html_output->save_fields($fields);
}
public static function hesabix_catalog_setting_fields()
{
$warehouses = Hesabix_Setting::hesabix_get_warehouses();
$fields[] = array(
'title' => __('Catalog Settings', 'hesabix'),
'type' => 'title',
'desc' => '',
'id' => 'catalog_options'
);
$fields[] = array(
'title' => __('Update Price', 'hesabix'),
'desc' => __('Update Price after change in Hesabix', 'hesabix'),
'id' => 'hesabix_item_update_price',
'default' => 'no',
'type' => 'checkbox'
);
$fields[] = array(
'title' => __('Update Quantity', 'hesabix'),
'desc' => __('Update Quantity after change in Hesabix', 'hesabix'),
'id' => 'hesabix_item_update_quantity',
'default' => 'no',
'type' => 'checkbox'
);
// $fields[] = array(
// 'title' => __("Update product's quantity based on", 'hesabix'),
// 'id' => 'hesabix_item_update_quantity_based_on',
// 'type' => 'select',
// 'options' => $warehouses,
// );
$fields[] = array(
'title' => "",
'desc' => __('Remove The Titles for Attributes When Saving Product To Hesabix', 'hesabix'),
'id' => 'hesabix_remove_attributes_titles',
'default' => 'no',
'type' => 'checkbox'
);
$fields[] = array(
'title' => "",
'desc' => __('Do not update purchase and sales titles in hesabix', 'hesabix'),
'id' => 'hesabix_do_not_update_titles_in_hesabix',
'default' => 'no',
'type' => 'checkbox'
);
$fields[] = array(
'title' => "",
'desc' => __('Do not submit product in Hesabix automatically by saving product in woocommerce', 'hesabix'),
'id' => 'hesabix_do_not_submit_product_automatically',
'default' => 'no',
'type' => 'checkbox'
);
$fields[] = array(
'title' => "",
'desc' => __('Do not update product price in Hesabix by editing product in woocommerce', 'hesabix'),
'id' => 'hesabix_do_not_update_product_price_in_hesabix',
'default' => 'no',
'type' => 'checkbox'
);
$fields[] = array(
'title' => "",
'desc' => __('Do not update product barcode in Hesabix by saving product in woocommerce', 'hesabix'),
'id' => 'hesabix_do_not_update_product_barcode_in_hesabix',
'default' => 'no',
'type' => 'checkbox'
);
$fields[] = array(
'title' => "",
'desc' => __('Do not update product category in Hesabix by saving product in woocommerce', 'hesabix'),
'id' => 'hesabix_do_not_update_product_category_in_hesabix',
'default' => 'no',
'type' => 'checkbox'
);
$fields[] = array(
'title' => "",
'desc' => __('Do not update product code in Hesabix by saving product in woocommerce', 'hesabix'),
'id' => 'hesabix_do_not_update_product_product_code_in_hesabix',
'default' => 'no',
'type' => 'checkbox'
);
$fields[] = array(
'title' => "",
'desc' => __('Show Hesabix ID in Products Page', 'hesabix'),
'id' => 'hesabix_show_product_code_in_products_page',
'default' => 'no',
'type' => 'checkbox'
);
$fields[] = array(
'title' => "",
'desc' => __('Show Hesabix Code in Woocommerce Excel Export', 'hesabix'),
'id' => 'hesabix_show_hesabix_code_in_excel_export',
'default' => 'no',
'type' => 'checkbox'
);
$fields[] = array(
'title' => "",
'desc' => __('Set Special Sale as Discount in invoice', 'hesabix'),
'id' => 'hesabix_set_special_sale_as_discount',
'default' => 'no',
'type' => 'checkbox'
);
$options_to_update_sale_price = array();
$options_to_update_sale_price[0] = __("The Sale price does not change", 'hesabix');
$options_to_update_sale_price[1] = __("The Sale price gets removed", 'hesabix');
$options_to_update_sale_price[2] = __("The sale price get changes in proportion to the regular price", 'hesabix');
$fields[] = array(
'title' => __("Update sale price", 'hesabix'),
'id' => 'hesabix_item_update_sale_price',
'type' => 'select',
'options' => $options_to_update_sale_price,
);
$fields[] = array('type' => 'sectionend', 'id' => 'catalog_options');
return $fields;
}
public static function hesabix_catalog_setting()
{
$hesabi_setting_fields = self::hesabix_catalog_setting_fields();
$Html_output = new Hesabix_Html_output();
?>
<div class="hesabix-card">
<div class="hesabix-card-header">
<h2 class="hesabix-card-title"><?php echo __('Catalog Settings', 'hesabix'); ?></h2>
<p class="hesabix-card-subtitle">
<?php echo __('Configure product sync and catalog options between WooCommerce and Hesabix', 'hesabix'); ?>
</p>
</div>
<form id="hesabix_catalog_form" enctype="multipart/form-data" action="" method="post">
<div id="catalog-settings-message" style="display:none;"></div>
<div class="hesabix-section">
<?php $Html_output->init($hesabi_setting_fields); ?>
</div>
<div class="hesabix-form-actions">
<button type="button" id="ajax-save-catalog-settings" class="hesabix-btn hesabix-btn-primary">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" />
</svg>
<?php echo __('Save Changes', 'hesabix'); ?>
</button>
</div>
</form>
</div>
<?php
}
public static function hesabix_catalog_setting_save_field()
{
$hesabi_setting_fields = self::hesabix_catalog_setting_fields();
$Html_output = new Hesabix_Html_output();
$Html_output->save_fields($hesabi_setting_fields);
}
public static function hesabix_customers_setting_fields()
{
$fields[] = array(
'title' => __('Customers Settings', 'hesabix'),
'type' => 'title',
'desc' => '',
'id' => 'customer_options'
);
$fields[] = array(
'title' => __('Update Customer Address', 'hesabix'),
'desc' => __('Choose when update Customer address in Hesabix.', 'hesabix'),
'id' => 'hesabix_contact_address_status',
'type' => 'select',
'options' => array(
'1' => __('Use first customer address', 'hesabix'),
'2' => __('update address with Invoice address', 'hesabix'),
'3' => __('update address with Delivery address', 'hesabix')
),
);
$fields[] = array(
'title' => __('Customer\'s Group', 'hesabix'),
'desc' => __('Enter a Customer\'s Group in Hesabix', 'hesabix'),
'id' => 'hesabix_contact_node_family',
'type' => 'text',
'default' => 'مشتریان فروشگاه آنلاین'
);
$fields[] = array(
'title' => __('Save Customer\'s group', 'hesabix'),
'desc' => __('Automatically save Customer\'s group in hesabix', 'hesabix'),
'id' => 'hesabix_contact_automatic_save_node_family',
'default' => 'yes',
'type' => 'checkbox'
);
$fields[] = array(
'title' => __('Customer\'s detail auto save and update', 'hesabix'),
'desc' => __('Save and update Customer\'s detail automatically in hesabix', 'hesabix'),
'id' => 'hesabix_contact_automatically_save_in_hesabix',
'type' => 'checkbox',
'default' => 'yes'
);
$fields[] = array('type' => 'sectionend', 'id' => 'customer_options');
return $fields;
}
public static function hesabix_customers_setting()
{
$hesabi_setting_fields = self::hesabix_customers_setting_fields();
$add_fields = get_option('hesabix_contact_add_fields', '1');
$nationalCodeCheck = get_option('hesabix_contact_NationalCode_checkbox_hesabix') == 'yes';
$economicCodeCheck = get_option('hesabix_contact_EconomicCode_checkbox_hesabix') == 'yes';
$registrationNumberCheck = get_option('hesabix_contact_RegistrationNumber_checkbox_hesabix') == 'yes';
$websiteCheck = get_option('hesabix_contact_Website_checkbox_hesabix') == 'yes';
$nationalCodeRequired = get_option('hesabix_contact_NationalCode_isRequired_hesabix') == 'yes';
$economicCodeRequired = get_option('hesabix_contact_EconomicCode_isRequired_hesabix') == 'yes';
$registrationNumberRequired = get_option('hesabix_contact_RegistrationNumber_isRequired_hesabix') == 'yes';
$websiteRequired = get_option('hesabix_contact_Website_isRequired_hesabix') == 'yes';
$nationalCodeMetaName = get_option('hesabix_contact_NationalCode_text_hesabix', null);
$economicCodeMetaName = get_option('hesabix_contact_EconomicCode_text_hesabix', null);
$registrationNumberMetaName = get_option('hesabix_contact_RegistrationNumber_text_hesabix', null);
$websiteMetaName = get_option('hesabix_contact_Website_text_hesabix', null);
$Html_output = new Hesabix_Html_output();
?>
<div class="hesabix-card">
<div class="hesabix-card-header">
<h2 class="hesabix-card-title"><?php echo __('Customer Settings', 'hesabix'); ?></h2>
<p class="hesabix-card-subtitle">
<?php echo __('Configure customer management and additional checkout fields', 'hesabix'); ?>
</p>
</div>
<div class="hesabix-section">
<!-- <h3 class="hesabix-section-title"><?php echo __('Basic Settings', 'hesabix'); ?></h3> -->
<div id="customers-settings-message"></div>
<div id="customers-fields-message"></div>
<form id="hesabix_customers_form" enctype="multipart/form-data" action="" method="post">
<?php $Html_output->init($hesabi_setting_fields); ?>
<div class="hesabix-form-actions">
<button type="button" id="ajax-save-customers-settings" class="hesabix-btn hesabix-btn-primary">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" />
</svg>
<?php echo __('Save Changes', 'hesabix'); ?>
</button>
</div>
</form>
</div>
<div class="hesabix-section">
<h3 class="hesabix-section-title"><?php echo __('Additional Checkout Fields', 'hesabix'); ?></h3>
<p class="hesabix-section-description">
<?php echo __('Configure additional fields that will be displayed on the checkout page for customer information collection.', 'hesabix'); ?>
</p>
<div class="hesabix-field-group">
<label class="hesabix-field-label"><?php echo __('Field Source', 'hesabix'); ?></label>
<div class="hesabix-radio-group" role="radiogroup" aria-labelledby="field-source-label">
<label class="hesabix-radio">
<input type="radio" name="addFieldsRadio" value="1" <?php echo $add_fields == '1' ? 'checked' : '' ?>>
<span class="hesabix-radio-custom" aria-hidden="true"></span>
<span
class="hesabix-radio-text"><?php echo __('Customer add field to checkout by hesabix', 'hesabix'); ?></span>
</label>
<label class="hesabix-radio">
<input type="radio" name="addFieldsRadio" value="2" <?php echo $add_fields == '2' ? 'checked' : '' ?>>
<span class="hesabix-radio-custom" aria-hidden="true"></span>
<span
class="hesabix-radio-text"><?php echo __('Customer add field to checkout by postmeta', 'hesabix'); ?></span>
</label>
</div>
</div>
<div class="hesabix-table-container">
<table class="hesabix-table" role="table"
aria-label="<?php echo __('Additional checkout fields configuration', 'hesabix'); ?>">
<thead>
<tr>
<th scope="col"><?php echo __('Show', 'hesabix'); ?></th>
<th scope="col"><?php echo __('Required', 'hesabix'); ?></th>
<th scope="col"><?php echo __('Title', 'hesabix'); ?></th>
<th scope="col"><?php echo __('Meta code in Postmeta', 'hesabix'); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<label class="hesabix-switch" for="nationalCodeCheck">
<input type="checkbox" name="nationalCodeCheck" id="nationalCodeCheck" <?php echo $nationalCodeCheck ? 'checked' : '' ?> value="yes">
<span class="hesabix-slider" aria-hidden="true"></span>
<span class="sr-only"><?php echo __('Show national code field', 'hesabix'); ?></span>
</label>
</td>
<td>
<label class="hesabix-switch" for="nationalCodeRequired">
<input type="checkbox" name="nationalCodeRequired" id="nationalCodeRequired" <?php echo $nationalCodeRequired ? 'checked' : '' ?> value="yes">
<span class="hesabix-slider" aria-hidden="true"></span>
<span
class="sr-only"><?php echo __('Make national code field required', 'hesabix'); ?></span>
</label>
</td>
<td><?php echo __('National code', 'hesabix'); ?></td>
<td>
<input type="text" name="nationalCode" id="nationalCode"
value="<?php echo $nationalCodeMetaName ?>" class="hesabix-input contact_text_input"
placeholder="<?php echo __('Enter meta code', 'hesabix'); ?>"
aria-label="<?php echo __('Meta code for national code field', 'hesabix'); ?>">
</td>
</tr>
<tr>
<td>
<label class="hesabix-switch" for="economicCodeCheck">
<input type="checkbox" name="economicCodeCheck" id="economicCodeCheck" <?php echo $economicCodeCheck ? 'checked' : '' ?> value="yes">
<span class="hesabix-slider" aria-hidden="true"></span>
<span class="sr-only"><?php echo __('Show economic code field', 'hesabix'); ?></span>
</label>
</td>
<td>
<label class="hesabix-switch" for="economicCodeRequired">
<input type="checkbox" name="economicCodeRequired" id="economicCodeRequired" <?php echo $economicCodeRequired ? 'checked' : '' ?> value="yes">
<span class="hesabix-slider" aria-hidden="true"></span>
<span
class="sr-only"><?php echo __('Make economic code field required', 'hesabix'); ?></span>
</label>
</td>
<td><?php echo __('Economic code', 'hesabix'); ?></td>
<td>
<input type="text" name="economicCode" id="economicCode"
value="<?php echo $economicCodeMetaName ?>" class="hesabix-input contact_text_input"
placeholder="<?php echo __('Enter meta code', 'hesabix'); ?>"
aria-label="<?php echo __('Meta code for economic code field', 'hesabix'); ?>">
</td>
</tr>
<tr>
<td>
<label class="hesabix-switch" for="registrationNumberCheck">
<input type="checkbox" name="registrationNumberCheck" id="registrationNumberCheck" <?php echo $registrationNumberCheck ? 'checked' : '' ?> value="yes">
<span class="hesabix-slider" aria-hidden="true"></span>
<span
class="sr-only"><?php echo __('Show registration number field', 'hesabix'); ?></span>
</label>
</td>
<td>
<label class="hesabix-switch" for="registrationNumberRequired">
<input type="checkbox" name="registrationNumberRequired" id="registrationNumberRequired"
<?php echo $registrationNumberRequired ? 'checked' : '' ?> value="yes">
<span class="hesabix-slider" aria-hidden="true"></span>
<span
class="sr-only"><?php echo __('Make registration number field required', 'hesabix'); ?></span>
</label>
</td>
<td><?php echo __('Registration number', 'hesabix'); ?></td>
<td>
<input type="text" name="registrationNumber" id="registrationNumber"
value="<?php echo $registrationNumberMetaName ?>"
class="hesabix-input contact_text_input"
placeholder="<?php echo __('Enter meta code', 'hesabix'); ?>"
aria-label="<?php echo __('Meta code for registration number field', 'hesabix'); ?>">
</td>
</tr>
<tr>
<td>
<label class="hesabix-switch" for="websiteCheck">
<input type="checkbox" name="websiteCheck" id="websiteCheck" <?php echo $websiteCheck ? 'checked' : '' ?> value="yes">
<span class="hesabix-slider" aria-hidden="true"></span>
<span class="sr-only"><?php echo __('Show website field', 'hesabix'); ?></span>
</label>
</td>
<td>
<label class="hesabix-switch" for="websiteRequired">
<input type="checkbox" name="websiteRequired" id="websiteRequired" <?php echo $websiteRequired ? 'checked' : '' ?> value="yes">
<span class="hesabix-slider" aria-hidden="true"></span>
<span class="sr-only"><?php echo __('Make website field required', 'hesabix'); ?></span>
</label>
</td>
<td><?php echo __('Website', 'hesabix'); ?></td>
<td>
<input type="text" name="website" id="website" value="<?php echo $websiteMetaName ?>"
class="hesabix-input contact_text_input"
placeholder="<?php echo __('Enter meta code', 'hesabix'); ?>"
aria-label="<?php echo __('Meta code for website field', 'hesabix'); ?>">
</td>
</tr>
</tbody>
</table>
</div>
<div class="hesabix-form-actions">
<button type="button" id="ajax-save-customers-fields" class="hesabix-btn hesabix-btn-primary">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" />
</svg>
<span><?php echo __('Save Additional Fields', 'hesabix'); ?></span>
</button>
</div>
</div>
</div>
<?php
}
public static function hesabix_invoice_setting_fields()
{
$fields[] = array(
'title' => __('Invoice Settings', 'hesabix'),
'type' => 'title',
'desc' => '',
'id' => 'invoice_options'
);
$fields[] = array(
'title' => __('Add invoice in which status', 'hesabix'),
'id' => 'hesabix_invoice_status',
'type' => 'custom_status_selector',
'options' => array(
'pending' => __('Pending payment', 'hesabix'),
'processing' => __('Processing', 'hesabix'),
'on-hold' => __('On hold', 'hesabix'),
'completed' => __('Completed', 'hesabix'),
'cancelled' => __('Cancelled', 'hesabix'),
'refunded' => __('Refunded', 'hesabix'),
'failed' => __('Failed', 'hesabix'),
'checkout-draft' => __('Draft', 'hesabix'),
),
);
$fields[] = array(
'title' => __('Save Shipping Costs', 'hesabix'),
'id' => 'hesabix_invoice_freight',
'type' => 'freight_switch',
'options' => [
'disabled' => __("Don't Save", 'hesabix'),
0 => __("Save as Freight", 'hesabix'),
1 => __("Save as Service", 'hesabix')
],
'desc' => __('Choose how shipping costs should be handled in invoices', 'hesabix'),
);
$fields[] = array(
'title' => __('Service Code For Freight', 'hesabix'),
'id' => 'hesabix_invoice_freight_code',
'type' => 'text',
'placeholder' => __('Enter Freight Service Code', 'hesabix'),
'desc' => __('Required when "Save as Service" is selected. Create this service in Hesabix first.', 'hesabix'),
);
if (is_plugin_active('dokan-lite/dokan.php')) {
$fields[] = array(
'title' => __("Submit invoice base on Dokan orders", 'hesabix'),
'id' => 'hesabix_invoice_dokan',
'type' => 'radio',
'options' => [
0 => __("Inactive", 'hesabix'),
1 => __("Submit parent order", 'hesabix'),
2 => __("Submit children orders", 'hesabix')
],
'default' => 0
);
}
$fields[] = array('type' => 'sectionend', 'id' => 'invoice_options');
return $fields;
}
public static function hesabix_invoice_setting()
{
$hesabi_setting_fields = self::hesabix_invoice_setting_fields();
$Html_output = new Hesabix_Html_output();
?>
<div class="hesabix-card">
<div class="hesabix-card-header">
<h2 class="hesabix-card-title"><?php echo __('Invoice Settings', 'hesabix'); ?></h2>
<p class="hesabix-card-subtitle">
<?php echo __('Configure invoice generation and freight settings', 'hesabix'); ?>
</p>
</div>
<div class="hesabix-section" style="margin-bottom: 0px;">
<div class="hesabix-alert hesabix-alert-warning d-flex flex-column gap-2 align-items-start"
style="margin-bottom: 0px;">
<div class="d-flex gap-2 align-items-center">
<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
<path d="M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z" />
</svg>
<h4><?php echo __('Important Notice', 'hesabix'); ?></h4>
</div>
<ul>
<li><?php echo __('Configure when invoices should be created in Hesabix and when return invoices should be generated for orders.', 'hesabix'); ?>
</li>
<li><?php echo __('If you choose to save shipping costs as a service, you must first create a service in Hesabix and enter its code in the Freight Service Code field.', 'hesabix'); ?>
</li>
<li><?php echo __('The "Save as Service" option is for tax compliance systems.', 'hesabix'); ?>
</li>
<li><strong><?php echo __('Please ensure this field is correctly entered to avoid invoice creation issues.', 'hesabix'); ?></strong>
</li>
</ul>
</div>
</div>
<div class="hesabix-section">
<div id="invoice-settings-message"></div>
<form id="hesabix_invoice_form" enctype="multipart/form-data" action="" method="post">
<?php $Html_output->init($hesabi_setting_fields); ?>
<div class="hesabix-form-actions">
<button type="button" id="ajax-save-invoice-settings" class="hesabix-btn hesabix-btn-primary">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" />
</svg>
<?php echo __('Save Changes', 'hesabix'); ?>
</button>
</div>
</form>
</div>
</div>
<style>
#hesabix_invoice_freight_code,
#hesabix_invoice_salesman_percentage {
min-width: 250px;
}
#hesabix_invoice_transaction_fee {
width: fit-content;
}
</style>
<?php
if (get_option('hesabix_invoice_freight') == 1 && !(get_option('hesabix_invoice_freight_code'))) {
HesabixLogService::writeLogStr("Invoice Freight Service Code is not Defined in Hesabix ---- کد خدمت حمل و نقل تعریف نشده است");
echo '<script>alert("کد خدمت حمل و نقل تعریف نشده است");</scrip>';
}
?>
<?php
}
public static function hesabix_api_setting_fields()
{
$fields[] = array(
'title' => __('API Settings', 'hesabix'),
'type' => 'title',
'desc' => '',
'id' => 'api_options'
);
$fields[] = array(
'title' => __('API Key', 'hesabix'),
'desc' => __('Find API key in Setting->Access Tokens Menu', 'hesabix'),
'id' => 'hesabix_account_api',
'type' => 'text',
);
$fields[] = array(
'title' => __('API Address', 'hesabix'),
'id' => 'hesabix_api_address',
'type' => 'select',
'options' => array(
"0" => "app.hesabix.ir",
"1" => "next.hesabix.ir",
"2" => "hesabix.dragonizzer.ir",
"custom" => __("Custom Address", 'hesabix')
)
);
$fields[] = array(
'title' => __('Custom API Address', 'hesabix'),
'desc' => __('Enter your custom API address (e.g., your-domain.com)', 'hesabix'),
'id' => 'hesabix_custom_api_address',
'type' => 'text',
'class' => 'custom-api-address-field'
);
$fields[] = array('type' => 'sectionend', 'id' => 'api_options');
return $fields;
}
public static function hesabix_api_setting()
{
$businessInfo = self::getSubscriptionInfo();
$isBusinessInfo = false;
if ($businessInfo["expireDate"] != '' && $businessInfo["expireDate"] != null) {
$isBusinessInfo = true;
$expireDate = strtotime($businessInfo["expireDate"]);
$expireDateStr = date("Y/m/d", $expireDate);
}
$hesabi_setting_fields = self::hesabix_api_setting_fields();
$Html_output = new Hesabix_Html_output();
?>
<div class="hesabix-card">
<div class="hesabix-card-header">
<h2 class="hesabix-card-title"><?php echo __('API Settings', 'hesabix'); ?></h2>
<p class="hesabix-card-subtitle">
<?php echo __('Configure your Hesabix API connection and settings', 'hesabix'); ?>
</p>
</div>
<?php if ($isBusinessInfo): ?>
<div class="hesabix-section">
<h3 class="hesabix-section-title"><?php echo __('Business Information', 'hesabix'); ?></h3>
<div class="hesabix-grid hesabix-grid-2">
<div class="hesabix-feature-card">
<div class="hesabix-feature-icon">
<svg width="40" height="40" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 7V3H2v18h20V7H12zM6 19H4v-2h2v2zm0-4H4v-2h2v2zm0-4H4V9h2v2zm0-4H4V5h2v2zm4 12H8v-2h2v2zm0-4H8v-2h2v2zm0-4H8V9h2v2zm0-4H8V5h2v2zm10 12h-8v-2h2v-2h-2v-2h2v-2h-2V9h8v10z" />
</svg>
</div>
<h3><?php echo $businessInfo["businessName"]; ?></h3>
<p><?php echo __('Business Name', 'hesabix'); ?></p>
</div>
<div class="hesabix-feature-card">
<div class="hesabix-feature-icon">
<svg width="40" height="40" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" />
</svg>
</div>
<h3><?php echo $businessInfo["plan"]; ?></h3>
<p><?php echo __('Subscription Plan', 'hesabix'); ?></p>
</div>
<div class="hesabix-feature-card">
<div class="hesabix-feature-icon">
<svg width="40" height="40" viewBox="0 0 24 24" fill="currentColor">
<path
d="M11.8 10.9c-2.27-.59-3-1.2-3-2.15 0-1.09 1.01-1.85 2.7-1.85 1.78 0 2.44.85 2.5 2.1h2.21c-.07-1.72-1.12-3.3-3.21-3.81V3h-3v2.16c-1.94.42-3.5 1.68-3.5 3.61 0 2.31 1.91 3.46 4.7 4.13 2.5.6 3 1.48 3 2.41 0 .69-.49 1.79-2.7 1.79-2.06 0-2.87-.92-2.98-2.1h-2.2c.12 2.19 1.76 3.42 3.68 3.83V21h3v-2.15c1.95-.37 3.5-1.5 3.5-3.55 0-2.84-2.43-3.81-4.7-4.4z" />
</svg>
</div>
<h3><?php echo $businessInfo["credit"]; ?></h3>
<p><?php echo __('Document Credit', 'hesabix'); ?></p>
</div>
<div class="hesabix-feature-card">
<div class="hesabix-feature-icon">
<svg width="40" height="40" viewBox="0 0 24 24" fill="currentColor">
<path
d="M19 3h-1V1h-2v2H8V1H6v2H5c-1.11 0-1.99.9-1.99 2L3 19c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V8h14v11zM7 10h5v5H7z" />
</svg>
</div>
<h3><?php echo $expireDateStr; ?></h3>
<p><?php echo __('Expiry Date', 'hesabix'); ?></p>
</div>
</div>
</div>
<?php endif; ?>
<div class="hesabix-section">
<!-- <h3 class="hesabix-section-title"><?php echo __('API Configuration', 'hesabix'); ?></h3> -->
<div class="hesabix-alert hesabix-alert-warning d-flex flex-column gap-2 align-items-start">
<div class="d-flex gap-2 align-items-center">
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" />
</svg>
<strong><?php echo __('Important Notes', 'hesabix'); ?></strong>
</div>
<div>
<ul>
<li><?php echo __('To connect to Hesabix API and activate this plugin, you need to enter your API key and login token here.', 'hesabix'); ?>
</li>
<li><?php echo __('If you use login token for Hesabix API connection, you don\'t need to enter email and password.', 'hesabix'); ?>
</li>
<li><?php echo __('To find login token and API key, go to Settings > API Settings in Hesabix.', 'hesabix'); ?>
</li>
<li><?php echo __('If you want to connect another business to the plugin, first remove and reinstall the plugin to clear the previous business connections.', 'hesabix'); ?>
</li>
</ul>
</div>
</div>
<form id="hesabix_api_form" enctype="multipart/form-data" action="" method="post">
<?php $Html_output->init($hesabi_setting_fields); ?>
<div class="hesabix-form-actions">
<button type="submit" name="hesabix_integration" class="hesabix-btn hesabix-btn-primary"
id="save-api-settings">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
<path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" />
</svg>
<?php echo __('Save Changes', 'hesabix'); ?>
</button>
<button type="button" class="hesabix-btn hesabix-btn-secondary" id="test-connection">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" />
</svg>
<?php echo __('Test Connection', 'hesabix'); ?>
</button>
</div>
</form>
</div>
<div class="hesabix-alert hesabix-alert-danger d-flex flex-column gap-2 align-items-start">
<div class="d-flex gap-2 align-items-center">
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 2C6.47 2 2 6.47 2 12s4.47 10 10 10 10-4.47 10-10S17.53 2 12 2zm5 13.59L15.59 17 12 13.41 8.41 17 7 15.59 10.59 12 7 8.41 8.41 7 12 10.59 15.59 7 17 8.41 13.41 12 17 15.59z" />
</svg>
<strong><?php echo __('Warning', 'hesabix'); ?></strong>
</div>
<div>
<p><?php echo __('To connect another business to the plugin, first remove and reinstall the plugin to clear the previous business connections.', 'hesabix'); ?>
</p>
</div>
</div>
</div>
<?php
}
public static function hesabix_api_setting_save_field()
{
$hesabi_setting_fields = self::hesabix_api_setting_fields();
$Html_output = new Hesabix_Html_output();
$Html_output->save_fields($hesabi_setting_fields);
$api_key = get_option('hesabix_account_api');
if (!empty($api_key)) {
Hesabix_Setting::hesabix_set_webhook();
}
}
public static function hesabix_export_setting()
{
$productExportResult = (isset($_GET['productExportResult'])) ? wc_clean($_GET['productExportResult']) : null;
$productImportResult = (isset($_GET['productImportResult'])) ? wc_clean($_GET['productImportResult']) : null;
$error = (isset($_GET['error'])) ? wc_clean($_GET['error']) : null;
if (!is_null($productExportResult) && $productExportResult === 'true') {
$processed = (isset($_GET['processed'])) ? wc_clean($_GET['processed']) : null;
if ($processed == 0) {
echo '<div class="updated">';
echo '<p class="hesabix-p">' . __('No products were exported, All products were exported or there are no product', 'hesabix');
echo '</div>';
} else {
echo '<div class="updated">';
echo '<p class="hesabix-p">' . sprintf(__('Export products completed. %s products added/updated.', 'hesabix'), $processed);
echo '</div>';
}
} elseif ($productExportResult === 'false') {
if (!is_null($error) && $error === '-1') {
echo '<div class="updated">';
echo '<p class="hesabix-p">' . __('Export products fail. Hesabix has already contained products.', 'hesabix');
echo '</div>';
} else {
echo '<div class="updated">';
echo '<p class="hesabix-p">' . __('Export products fail. Please check the log file.', 'hesabix');
echo '</div>';
}
}
if (!is_null($productImportResult) && $productImportResult === 'true') {
$processed = (isset($_GET['processed'])) ? wc_clean($_GET['processed']) : null;
if ($processed == 0) {
echo '<div class="updated">';
echo '<p class="hesabix-p">' . __('No products were imported, All products were imported or there are no product', 'hesabix');
echo '</div>';
} else {
echo '<div class="updated">';
echo '<p class="hesabix-p">' . sprintf(__('Import products completed. %s products added/updated.', 'hesabix'), $processed);
echo '</div>';
}
} elseif ($productImportResult === 'false') {
echo '<div class="updated">';
echo '<p class="hesabix-p">' . __('Import products fail. Please check the log file.', 'hesabix');
echo '</div>';
}
$productOpeningQuantityExportResult = (isset($_GET['productOpeningQuantityExportResult'])) ? wc_clean($_GET['productOpeningQuantityExportResult']) : null;
if (!is_null($productOpeningQuantityExportResult) && $productOpeningQuantityExportResult === 'true') {
echo '<div class="updated">';
echo '<p class="hesabix-p">' . __('Export product opening quantity completed.', 'hesabix');
echo '</div>';
} elseif (!is_null($productOpeningQuantityExportResult) && $productOpeningQuantityExportResult === 'false') {
$shareholderError = (isset($_GET['shareholderError'])) ? wc_clean($_GET['shareholderError']) : null;
$noProduct = (isset($_GET['noProduct'])) ? wc_clean($_GET['noProduct']) : null;
if ($shareholderError == 'true') {
echo '<div class="error">';
echo '<p class="hesabix-p">' . __('Export product opening quantity fail. No Shareholder exists, Please define Shareholder in Hesabix', 'hesabix');
echo '</div>';
} elseif ($noProduct == 'true') {
echo '<div class="error">';
echo '<p class="hesabix-p">' . __('No product available for Export product opening quantity.', 'hesabix');
echo '</div>';
} else {
echo '<div class="error">';
echo '<p class="hesabix-p">' . __('Export product opening quantity fail. Please check the log file.', 'hesabix');
echo '</div>';
}
}
$customerExportResult = (isset($_GET['customerExportResult'])) ? wc_clean($_GET['customerExportResult']) : null;
if (!is_null($customerExportResult) && $customerExportResult === 'true') {
$processed = (isset($_GET['processed'])) ? wc_clean($_GET['processed']) : null;
if ($processed == 0) {
echo '<div class="updated">';
echo '<p class="hesabix-p">' . __('No customers were exported, All customers were exported or there are no customer', 'hesabix');
echo '</div>';
} else {
echo '<div class="updated">';
echo '<p class="hesabix-p">' . sprintf(__('Export customers completed. %s customers added.', 'hesabix'), $processed);
echo '</div>';
}
} elseif (!is_null($customerExportResult) && $customerExportResult === 'false') {
if (!is_null($error) && $error === '-1') {
echo '<div class="updated">';
echo '<p class="hesabix-p">' . __('Export customers fail. Hesabix has already contained customers.', 'hesabix');
echo '</div>';
} else {
echo '<div class="updated">';
echo '<p class="hesabix-p">' . __('Export customers fail. Please check the log file.', 'hesabix');
echo '</div>';
}
}
?>
<div class="notice notice-info">
<p class="hesabix-p"><?php echo __('Export can take several minutes.', 'hesabix') ?></p>
</div>
<br>
<form class="card hesabix-card" id="hesabix_export_products" autocomplete="off"
action="<?php echo admin_url('admin.php?page=hesabix-option&tab=export'); ?>" method="post">
<div>
<div>
<label for="hesabix-export-product-submit"></label>
<div>
<button class="button button-primary hesabix-f" id="hesabix-export-product-submit"
name="hesabix-export-product-submit"><?php echo __('Export Products', 'hesabix'); ?></button>
</div>
</div>
<p class="hesabix-p mt-2">
<?php echo __('Export and add all online store products to Hesabix', 'hesabix'); ?>
</p>
<div class="progress mt-1 mb-2" style="height: 5px; max-width: 400px; border: 1px solid silver"
id="exportProductsProgress">
<div class="progress-bar progress-bar-striped bg-success" id="exportProductsProgressBar" role="progressbar"
style="width: 0%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="p-2 hesabix-f">
<label class="fw-bold mb-2">نکات مهم:</label>
<ul>
<li>با انجام این عملیات محصولات لینک نشده از فروشگاه وارد حسابیکس می شوند.</li>
<li>اگر محصولات از قبل هم در فروشگاه تعریف شده اند و هم در حسابیکس و به هم لینک نشده اند باید از
گزینه
همسان سازی دستی محصولات استفاده کنید.
</li>
<li>با انجام این عملیات موجودی محصولات وارد حسابیکس نمی شود و برای وارد کردن موجودی محصولات
فروشگاه
در حسابیکس، باید از گزینه استخراج موجودی اول دوره استفاده کنید.
</li>
</ul>
</div>
</div>
</form>
<form class="card hesabix-card hesabix-f" id="hesabix_export_products_opening_quantity" autocomplete="off"
action="<?php echo admin_url('admin.php?page=hesabix-option&tab=export'); ?>" method="post">
<div>
<div>
<label for="hesabix-export-product-opening-quantity-submit"></label>
<div>
<button class="button button-primary hesabix-f" id="hesabix-export-product-opening-quantity-submit"
name="hesabix-export-product-opening-quantity-submit" <?php if (get_option('hesabix_use_export_product_opening_quantity') == true) {
echo 'disabled';
} ?>><?php echo __('Export Products opening quantity', 'hesabix'); ?></button>
</div>
</div>
<p class="hesabix-p mt-2">
<?php echo __('Export the products quantity and record the \'products opening quantity\' in the Hesabix', 'hesabix'); ?>
</p>
<div class="progress mt-1 mb-2" style="height: 5px; max-width: 400px; border: 1px solid silver"
id="exportProductsOpeningQuantityProgress">
<div class="progress-bar progress-bar-striped bg-success" id="exportProductsOpeningQuantityProgressBar"
role="progressbar" style="width: 0%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="p-2 hesabix-f">
<label class="fw-bold mb-2">نکات مهم:</label>
<ul>
<li>با انجام این عملیات موجودی کنونی محصولات در فروشگاه بعنوان موجودی اول دوره محصولات در حسابیکس
ثبت می شوند.
</li>
<li>بطور کلی فقط یک بار باید از این گزینه استفاده کنید،
که این کار باید پس از خروج محصولات به حسابیکس و یا پس از همسان سازی دستی تمام محصولات
انجام شود.
</li>
</ul>
</div>
</div>
</form>
<form class="card hesabix-card hesabix-f" id="hesabix_export_customers" autocomplete="off"
action="<?php echo admin_url('admin.php?page=hesabix-option&tab=export'); ?>" method="post">
<div>
<div>
<label for="hesabix-export-customer-submit"></label>
<div>
<button class="button button-primary hesabix-f" id="hesabix-export-customer-submit"
name="hesabix-export-customer-submit"><?php echo __('Export Customers', 'hesabix'); ?></button>
</div>
</div>
<p class="hesabix-p mt-2">
<?php echo __('Export and add all online store customers to Hesabix.', 'hesabix'); ?>
</p>
<div class="progress mt-1 mb-2" style="height: 5px; max-width: 400px; border: 1px solid silver"
id="exportCustomersProgress">
<div class="progress-bar progress-bar-striped bg-success" id="exportCustomersProgressBar" role="progressbar"
style="width: 0%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="p-2 hesabix-f">
<label class="fw-bold mb-2">نکات مهم:</label>
<ul>
<li>با انجام این عملیات مشتریان لینک نشده از فروشگاه وارد حسابیکس می شوند.</li>
<li>
اگر یک مشتری بیش از یک بار وارد حسابیکس شده است می توانید از گزینه ادغام تراکنش ها در حسابیکس
استفاده کنید.
</li>
</ul>
</div>
</div>
</form>
<form class="card hesabix-card hesabix-f" id="hesabix_import_products" autocomplete="off"
action="<?php echo admin_url('admin.php?page=hesabix-option&tab=export'); ?>" method="post">
<div>
<div>
<label for="hesabix-import-product-submit"></label>
<div>
<button class="button button-primary hesabix-f" id="hesabix-import-product-submit"
name="hesabix-import-product-submit"><?php echo __('Import Products', 'hesabix'); ?></button>
</div>
</div>
<p class="hesabix-p mt-2">
<?php echo __('Import and add all products from Hesabix to online store', 'hesabix'); ?>
</p>
<div class="progress mt-1 mb-2" style="height: 5px; max-width: 400px; border: 1px solid silver"
id="importProductsProgress">
<div class="progress-bar progress-bar-striped bg-success" id="importProductsProgressBar" role="progressbar"
style="width: 0%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="p-2">
<label class="fw-bold mb-2">نکات مهم:</label>
<ul>
<li>با انجام این عملیات محصولات لینک نشده از حسابیکس وارد فروشگاه می شوند.</li>
<li>اگر محصولات از قبل هم در فروشگاه تعریف شده اند و هم در حسابیکس و به هم لینک نشده اند باید از
گزینه
همسان سازی دستی محصولات استفاده کنید.
</li>
<li>محصولات در وضعیت خصوصی وارد فروشگاه می شوند و سپس هر زمان مایل بودید می توانید وضعیت را به
منتشر شده تغییر دهید.
</li>
<li>تمامی محصولات بعنوان محصول ساده (و نه متغیر) وارد فروشگاه می شوند.</li>
</ul>
</div>
</div>
</form>
<?php
}
public static function hesabix_sync_setting()
{
?>
<div class="hesabix-card hesabix-fade-in" style="margin-bottom: 24px;">
<div class="hesabix-alert hesabix-alert-info hesabix-f" style="margin-bottom: 0;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"
style="vertical-align: middle; margin-left: 8px;">
<path
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z" />
</svg>
<?php echo __('This page is for synchronizing information between the store and Hesabix. Please check the settings before starting.', 'hesabix'); ?>
</div>
<h3 class="hesabix-tab-page-title" style="margin-top: 24px;">
<?php echo __('Information Synchronization', 'hesabix'); ?>
</h3>
<div class="hesabix-grid hesabix-grid-3" style="margin-bottom: 32px;">
<div class="hesabix-feature-card">
<div class="hesabix-feature-icon">
<svg width="32" height="32" fill="currentColor" viewBox="0 0 24 24">
<path
d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-5 14H7v-2h7v2zm3-4H7v-2h10v2zm0-4H7V7h10v2z" />
</svg>
</div>
<h3><?php echo __('Store Products Count', 'hesabix'); ?></h3>
<p><b id="sync-store-products-count"><span class="hesabix-spinner-small"
style="display:inline-block;vertical-align:middle;"></span></b></p>
</div>
<div class="hesabix-feature-card">
<div class="hesabix-feature-icon">
<svg width="32" height="32" fill="currentColor" viewBox="0 0 175 175">
<path
d="M0 0 C8.18911268 -0.04651976 16.37816933 -0.08196836 24.56738186 -0.10362434 C28.37073399 -0.1140227 32.17399514 -0.12810896 35.97729492 -0.15087891 C39.65369106 -0.17274917 43.33000016 -0.18459825 47.00645638 -0.18975449 C48.40294831 -0.19342496 49.79943596 -0.20059186 51.19589043 -0.21146011 C70.52100326 -0.35576139 70.52100326 -0.35576139 77.875 4.9375 C78.95394531 5.69353516 78.95394531 5.69353516 80.0546875 6.46484375 C81.86022562 7.88969612 83.49355997 9.26143557 85 11 C85 11.66 85 12.32 85 13 C85.66 13 86.32 13 87 13 C95.22733894 27.10400962 102.15873305 42.6164818 104 59 C96.75715618 63.31586256 89.47667122 67.35231517 81.8125 70.875 C68.75107607 76.90104562 55.90645412 83.25993579 44.15234375 91.6015625 C42 93 42 93 40 93 C40 93.66 40 94.32 40 95 C39.34 95 38.68 95 38 95 C37.7525 95.515625 37.505 96.03125 37.25 96.5625 C36 99 36 99 33.875 102.0625 C31.15545354 106.80637052 31.21495525 111.68893195 32 117 C34.32115958 121.99942063 36.86818998 124.08814921 42 126 C48.39527592 127.20939892 54.78386689 127.21978588 61.27734375 127.31640625 C62.4438295 127.33718735 63.61031525 127.35796844 64.81214905 127.37937927 C68.52054224 127.44450911 72.22900332 127.50358917 75.9375 127.5625 C78.45899126 127.60572001 80.98047577 127.6493354 83.50195312 127.69335938 C89.66789799 127.80015284 95.83390967 127.9019857 102 128 C101.93941406 128.82717529 101.87882812 129.65435059 101.81640625 130.5065918 C101.34836605 136.96779677 100.90354848 143.42894793 100.5 149.89453125 C100.4175 151.19841797 100.335 152.50230469 100.25 153.84570312 C100.12331924 155.85577043 99.99676859 157.86584984 99.875 159.8762207 C99.75425015 161.86175392 99.62723905 163.84690331 99.5 165.83203125 C99.39171875 167.57577026 99.39171875 167.57577026 99.28125 169.35473633 C99 172 99 172 98 173 C96.4330281 173.10383049 94.86140929 173.13852298 93.29101562 173.14526367 C92.28486206 173.15164352 91.2787085 173.15802338 90.24206543 173.16459656 C89.14124634 173.16570938 88.04042725 173.1668222 86.90625 173.16796875 C85.77159302 173.17129715 84.63693604 173.17462555 83.46789551 173.17805481 C81.05005296 173.18313527 78.63220335 173.18546279 76.21435547 173.18530273 C72.57116456 173.1874579 68.92829221 173.20551329 65.28515625 173.22460938 C43.73078865 173.27698802 26.30867365 172.0953979 7 162 C7 161.34 7 160.68 7 160 C6.12021484 159.62294922 6.12021484 159.62294922 5.22265625 159.23828125 C2.72235663 157.84531995 1.29240124 156.35777594 -0.5625 154.1875 C-1.43068359 153.18783203 -1.43068359 153.18783203 -2.31640625 152.16796875 C-5.79457149 147.68912488 -7.61625501 143.53318556 -9.125 138.0625 C-9.45757813 136.87785156 -9.79015625 135.69320312 -10.1328125 134.47265625 C-14.39279807 117.41352483 -12.09195406 100.21053561 -3.76171875 84.74609375 C4.1957617 72.34230493 16.4411864 62.43966551 29.625 56.0625 C30.31142578 55.72476563 30.99785156 55.38703125 31.70507812 55.0390625 C38.085784 51.91646406 44.52696191 48.9261679 51 46 C51 45.01 51 44.02 51 43 C33.18 42.67 15.36 42.34 -3 42 C-1.83928571 11.82142857 -1.83928571 11.82142857 0 0 Z "
fill="currentColor" transform="translate(40,4)" />
</svg>
</div>
<h3><?php echo __('Hesabix Products Count', 'hesabix'); ?></h3>
<p><b id="sync-hesabix-products-count"><span class="hesabix-spinner-small"
style="display:inline-block;vertical-align:middle;"></span></b></p>
</div>
<div class="hesabix-feature-card">
<div class="hesabix-feature-icon">
<svg fill="currentColor" width="35" height="35" viewBox="0 0 52 52" enable-background="new 0 0 52 52"
xml:space="preserve">
<g>
<path d="M17.3,36.1l-1.1-1.4c0,0-0.7-1-0.9-1.6c-0.2-0.3-0.5-0.5-0.9-0.5h-0.6c-3.5,0-6.5-2.6-6.7-6
c-0.3-3.8,2.8-6.9,6.5-6.9h9.1c1.2,0,2.3,0.4,3.2,0.8c1.2,0.7,2.2,1.8,2.7,3.1c0.3,0.8,0.5,1.6,0.5,2.6c0,0.5-0.1,0.9-0.2,1.4
c-0.2,0.7,0.3,1.3,1,1.2l3.4,0c0.5,0,0.8-0.4,1-0.8c0.1-0.6,0.1-1.2,0.1-1.8c0-0.8-0.1-1.7-0.3-2.6c-0.3-1.4-0.9-2.7-1.7-3.9
c-1.5-2.2-3.8-4-6.4-4.7c-1-0.3-2.2-0.5-3.2-0.5H14c-6.3,0-11.7,4.9-11.9,11.2c-0.3,6.6,5,12.1,11.6,12.1h3
C17.4,37.7,17.8,36.7,17.3,36.1z M49.9,25.6c-0.2-6.3-5.6-11.3-11.9-11.2l-2.7-0.1c-0.8,0-1.3,1-0.8,1.6c0.8,0.9,1.4,1.9,2,3
c0.2,0.3,0.5,0.5,0.9,0.5H38c3.5,0,6.5,2.6,6.7,6c0.3,3.8-2.8,6.9-6.5,6.9l-9.1,0c-1.2,0-2.3-0.4-3.2-0.8c-1.2-0.7-2.2-1.8-2.7-3.1
c-0.3-0.8-0.5-1.6-0.5-2.6c0-0.5,0.1-0.9,0.2-1.4c0.2-0.7-0.3-1.3-1-1.2h-3.4c-0.5,0-0.8,0.4-1,0.8c-0.1,0.6-0.1,1.2-0.1,1.8
c0,0.8,0.1,1.8,0.3,2.6c0.3,1.4,0.9,2.7,1.7,3.8c1.5,2.2,3.8,4,6.4,4.7c1,0.3,2.2,0.5,3.2,0.5l9.1,0C44.8,37.7,50.1,32.2,49.9,25.6
z" />
</g>
</svg>
</div>
<h3><?php echo __('Linked Products', 'hesabix'); ?></h3>
<p><b id="sync-linked-products-count"><span class="hesabix-spinner-small"
style="display:inline-block;vertical-align:middle;"></span></b></p>
</div>
</div>
<div class="hesabix-grid hesabix-grid-2">
<!-- <div class="hesabix-card hesabix-fade-in" style="background:#f8f9fa;">
<h4 class="hesabix-section-title"><?php echo __('General Changes Synchronization', 'hesabix'); ?></h4>
<form id="hesabix_sync_changes" autocomplete="off"
action="<?php echo admin_url('admin.php?page=hesabix-option&tab=sync'); ?>" method="post">
<div class="hesabix-form-actions" style="border: none; margin-top: 0; padding-top: 0;">
<button class="hesabix-btn hesabix-btn-primary" id="hesabix-sync-changes-submit"
name="hesabix-sync-changes-submit" type="submit">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46C19.54 15.03 20 13.57 20 12c0-4.42-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6 0-1.01.25-1.97.7-2.8L5.24 7.74C4.46 8.97 4 10.43 4 12c0 4.42 3.58 8 8 8v3l4-4-4-4v3z" />
</svg>
<?php echo __('Synchronize Changes', 'hesabix'); ?>
</button>
</div>
<div class="hesabix-form-text">
<?php echo __('This operation synchronizes all changes (products, customers, orders).', 'hesabix'); ?>
</div>
</form>
</div> -->
<div class="hesabix-card hesabix-fade-in" style="background:#f8f9fa;">
<h4 class="hesabix-section-title">
<?php echo __('Update Hesabix Products Based on Woocommerce', 'hesabix'); ?>
</h4>
<form id="hesabix_update_products" autocomplete="off"
action="<?php echo admin_url('admin.php?page=hesabix-option&tab=sync'); ?>" method="post">
<div class="hesabix-form-actions" style="border: none; margin-top: 0; padding-top: 0;">
<button class="hesabix-btn hesabix-btn-primary" id="hesabix-update-products-submit"
name="hesabix-update-products-submit" type="submit">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
<path
d="M8.71,7.71,11,5.41V15a1,1,0,0,0,2,0V5.41l2.29,2.3a1,1,0,0,0,1.42,0,1,1,0,0,0,0-1.42l-4-4a1,1,0,0,0-.33-.21,1,1,0,0,0-.76,0,1,1,0,0,0-.33.21l-4,4A1,1,0,1,0,8.71,7.71ZM21,12a1,1,0,0,0-1,1v6a1,1,0,0,1-1,1H5a1,1,0,0,1-1-1V13a1,1,0,0,0-2,0v6a3,3,0,0,0,3,3H19a3,3,0,0,0,3-3V13A1,1,0,0,0,21,12Z" />
</svg>
<?php echo __('Update Hesabix Products', 'hesabix'); ?>
</button>
</div>
<div class="hesabix-form-text">
<?php echo __('Product features such as name and price in Hesabix are updated based on the store (inventory does not change).', 'hesabix'); ?>
</div>
</form>
</div>
<div class="hesabix-card hesabix-fade-in" style="background:#f8f9fa;">
<h4 class="hesabix-section-title">
<?php echo __('Product Price and Inventory Synchronization', 'hesabix'); ?>
</h4>
<form id="hesabix_sync_products" autocomplete="off"
action="<?php echo admin_url('admin.php?page=hesabix-option&tab=sync'); ?>" method="post">
<div class="hesabix-form-actions" style="border: none; margin-top: 0; padding-top: 0;">
<?php if (get_option('hesabix_item_update_price') == 'no' && get_option('hesabix_item_update_quantity') == 'no') { ?>
<button disabled class="hesabix-btn hesabix-btn-primary" id="hesabix-sync-products-submit"
name="hesabix-sync-products-submit" type="submit">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46C19.54 15.03 20 13.57 20 12c0-4.42-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6 0-1.01.25-1.97.7-2.8L5.24 7.74C4.46 8.97 4 10.43 4 12c0 4.42 3.58 8 8 8v3l4-4-4-4v3z" />
</svg>
<?php echo __('Synchronize Price and Inventory', 'hesabix'); ?>
</button>
<?php } else { ?>
<button class="hesabix-btn hesabix-btn-primary" id="hesabix-sync-products-submit"
name="hesabix-sync-products-submit" type="submit">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46C19.54 15.03 20 13.57 20 12c0-4.42-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6 0-1.01.25-1.97.7-2.8L5.24 7.74C4.46 8.97 4 10.43 4 12c0 4.42 3.58 8 8 8v3l4-4-4-4v3z" />
</svg>
<?php echo __('Synchronize Price and Inventory', 'hesabix'); ?>
</button>
<?php } ?>
</div>
<div class="hesabix-form-text">
<?php echo __('Based on the products tab settings, product prices and inventory are synchronized.', 'hesabix'); ?>
</div>
</form>
</div>
<div class="hesabix-card hesabix-fade-in order-sync-card" style="background:#f8f9fa;grid-column:1/3;">
<h4 class="hesabix-section-title"><?php echo __('Order Synchronization (Time Range)', 'hesabix'); ?></h4>
<form id="hesabix_sync_orders" autocomplete="off"
style="display:flex;justify-content:space-between;gap:16px;"
action="<?php echo admin_url('admin.php?page=hesabix-option&tab=sync'); ?>" method="post">
<div>
<div class="hesabix-date-presets" style="margin-bottom: 16px;">
<label style="display: block; margin-bottom: 8px; font-weight: 500; color: #374151;">
<?php echo __('Quick Select:', 'hesabix'); ?>
</label>
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
<button type="button" class="hesabix-date-preset-btn" data-days="7">
<?php echo __('Last 7 Days', 'hesabix'); ?>
</button>
<button type="button" class="hesabix-date-preset-btn" data-days="30">
<?php echo __('Last 30 Days', 'hesabix'); ?>
</button>
<button type="button" class="hesabix-date-preset-btn" data-days="90">
<?php echo __('Last 3 Months', 'hesabix'); ?>
</button>
<button type="button" class="hesabix-date-preset-btn" data-custom="true">
<?php echo __('Custom Range', 'hesabix'); ?>
</button>
</div>
</div>
<div class="hesabix-date-range-container" style="display: none;">
<div class="hesabix-date-range-wrapper">
<div class="hesabix-date-field">
<label for="hesabix_sync_order_date" class="hesabix-date-label">
<?php echo __('From Date:', 'hesabix'); ?>
</label>
<input type="text" id="hesabix_sync_order_date_jalali"
class="hesabix-form-control hesabix-date-input-jalali" placeholder="1402/01/01"
style="direction: ltr; text-align: center;" required>
<input type="date" id="hesabix_sync_order_date" name="hesabix_sync_order_date"
class="hesabix-form-control hesabix-date-input" style="display: none;" required>
</div>
<div class="hesabix-date-arrow">
<label for="hesabix_sync_order_date" class="hesabix-date-label">
</label>
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"
style="transform: scale(-1);">
<path d="M8.59 16.59L13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.41z" />
</svg>
</div>
<div class="hesabix-date-field">
<label for="hesabix_sync_order_end_date" class="hesabix-date-label">
<?php echo __('To Date:', 'hesabix'); ?>
</label>
<input type="text" id="hesabix_sync_order_end_date_jalali"
class="hesabix-form-control hesabix-date-input-jalali" placeholder="1402/01/01"
style="direction: ltr; text-align: center;" required>
<input type="date" id="hesabix_sync_order_end_date" name="hesabix_sync_order_end_date"
class="hesabix-form-control hesabix-date-input" style="display: none;" required>
</div>
</div>
<div class="hesabix-date-validation-message"
style="display: none; color: #dc2626; font-size: 14px; margin-top: 8px;">
<?php echo __('End date must be after start date.', 'hesabix'); ?>
</div>
</div>
<div class="hesabix-selected-range"
style="display: none; padding: 12px; background: #f0f9ff; border: 1px solid #0ea5e9; border-radius: 6px; margin: 8px 0;">
<div style="display: flex; align-items: center; gap: 8px;">
<svg width="16" height="16" viewBox="0 0 24 24" fill="#0ea5e9">
<path
d="M19 3h-1V1h-2v2H8V1H6v2H5c-1.11 0-1.99.9-1.99 2L3 19c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V8h14v11zM7 10h5v5H7z" />
</svg>
<span style="font-weight: 500; color: #0369a1;">
<?php echo __('Selected Range:', 'hesabix'); ?>
</span>
<span id="hesabix-range-display" style="color: #0369a1;"></span>
</div>
</div>
</div>
<div class="hesabix-form-actions" style="border: none; margin-top: 0; padding-top: 0;">
<button class="hesabix-btn hesabix-btn-primary" id="hesabix-sync-orders-submit"
style="height: fit-content;margin-top: auto;" name="hesabix-sync-orders-submit" type="submit"
disabled>
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
<path
d="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46C19.54 15.03 20 13.57 20 12c0-4.42-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6 0-1.01.25-1.97.7-2.8L5.24 7.74C4.46 8.97 4 10.43 4 12c0 4.42 3.58 8 8 8v3l4-4-4-4v3z" />
</svg>
<?php echo __('Synchronize Orders', 'hesabix'); ?>
</button>
</div>
</form>
<div class="hesabix-form-text">
<?php echo __('Store orders that are not registered in Hesabix are checked and registered in the selected date range. Choose a preset option or select a custom date range.', 'hesabix'); ?>
</div>
</div>
<div class="hesabix-card hesabix-fade-in" style="background:#f8f9fa;">
<h4 class="hesabix-section-title"><?php echo __('Update Hesabix Customers', 'hesabix'); ?>
</h4>
<form id="hesabix_update_customers" autocomplete="off"
action="<?php echo admin_url('admin.php?page=hesabix-option&tab=sync'); ?>" method="post">
<div class="hesabix-form-actions" style="border: none; margin-top: 0; padding-top: 0;">
<button class="hesabix-btn hesabix-btn-primary" id="hesabix-update-customers-submit"
name="hesabix-update-customers-submit" type="submit">
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
<path
d="M8.71,7.71,11,5.41V15a1,1,0,0,0,2,0V5.41l2.29,2.3a1,1,0,0,0,1.42,0,1,1,0,0,0,0-1.42l-4-4a1,1,0,0,0-.33-.21,1,1,0,0,0-.76,0,1,1,0,0,0-.33.21l-4,4A1,1,0,1,0,8.71,7.71ZM21,12a1,1,0,0,0-1,1v6a1,1,0,0,1-1,1H5a1,1,0,0,1-1-1V13a1,1,0,0,0-2,0v6a3,3,0,0,0,3,3H19a3,3,0,0,0,3-3V13A1,1,0,0,0,21,12Z" />
</svg>
<span
class="update-customers-text"><?php echo __('Update Hesabix Customers', 'hesabix'); ?></span>
</button>
</div>
<div class="hesabix-form-text">
<?php echo __('Customers existing in the store that are not registered in Hesabix will be checked and registered in Hesabix.', 'hesabix'); ?>
</div>
</form>
</div>
<div class="hesabix-card hesabix-fade-in" style="background:#f8f9fa;">
<h4 class="hesabix-section-title">
<?php echo __('Update Woocommerce Products Based on Hesabix', 'hesabix'); ?>
</h4>
<form id="hesabix_update_wc_products" autocomplete="off"
action="<?php echo admin_url('admin.php?page=hesabix-option&tab=sync'); ?>" method="post">
<div class="hesabix-form-actions" style="border: none; margin-top: 0; padding-top: 0;">
<button class="hesabix-btn hesabix-btn-primary" id="hesabix-update-wc-products-submit"
name="hesabix-update-wc-products-submit" type="submit">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M12 2a1 1 0 0 1 1 1v10.586l2.293-2.293a1 1 0 0 1 1.414 1.414l-4 4a1 1 0 0 1-1.414 0l-4-4a1 1 0 1 1 1.414-1.414L11 13.586V3a1 1 0 0 1 1-1zM5 17a1 1 0 0 1 1 1v2h12v-2a1 1 0 1 1 2 0v2a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-2a1 1 0 0 1 1-1z"
fill="currentColor" />
</svg>
<span
class="update-wc-products-text"><?php echo __('Update Woocommerce Products', 'hesabix'); ?></span>
</button>
</div>
<div class="hesabix-form-text">
<?php echo __('Product features such as name and price in Woocommerce are updated based on Hesabix (inventory does not change).', 'hesabix'); ?>
</div>
</form>
</div>
</div>
</div>
<div id="hesabix-sync-overlay" class="hesabix-sync-overlay">
<div class="hesabix-sync-overlay-backdrop"></div>
<div class="hesabix-sync-overlay-content">
<div class="hesabix-sync-spinner"></div>
<h3 class="hesabix-sync-overlay-title"><?php echo __('Operation in Progress...', 'hesabix'); ?></h3>
</div>
</div>
<style>
.hesabix-sync-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 99999;
font-family: 'Vazir', sans-serif;
}
.hesabix-sync-overlay-backdrop {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(4px);
animation: hesabix-overlay-fadeIn 0.3s ease-out;
}
.hesabix-sync-overlay-content {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
animation: hesabix-overlay-fadeIn 0.4s ease-out;
}
.hesabix-sync-spinner {
width: 50px;
height: 50px;
border: 3px solid #f3f3f3;
border-top: 3px solid #667eea;
border-radius: 50%;
animation: hesabix-sync-spin 1s linear infinite;
margin: 0 auto 20px;
}
.hesabix-sync-overlay-title {
color: #333;
margin: 0;
font-size: 1.1rem;
font-weight: 600;
}
@keyframes hesabix-sync-spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
@keyframes hesabix-overlay-fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@media (max-width: 768px) {
.hesabix-sync-spinner {
width: 40px;
height: 40px;
border-width: 2px;
}
.hesabix-sync-overlay-title {
font-size: 1rem;
}
}
</style>
<?php
}
public static function getProductsCount()
{
$storeProductsCount = self::getProductCountsInStore();
$hesabixProductsCount = self::getProductCountsInHesabix();
$linkedProductsCount = self::getLinkedProductsCount();
return array(
"storeProductsCount" => $storeProductsCount,
"hesabixProductsCount" => $hesabixProductsCount,
"linkedProductsCount" => $linkedProductsCount
);
}
public static function getProductCountsInHesabix()
{
$hesabix = new Hesabix_Api();
$filters = array(array("Property" => "khadamat", "Operator" => "=", "Value" => 0));
$response = $hesabix->itemGetItems(array('Filters' => $filters, 'Take' => -1));
if ($response->Success) {
return $response->data->FilteredCount;
} else {
return 0;
}
}
public static function getLinkedProductsCount()
{
global $wpdb;
return $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(*) FROM {$wpdb->prefix}hesabix WHERE obj_type = 'product'"
)
);
}
public static function getProductCountsInStore()
{
if (!function_exists('wc_get_products')) {
return 0;
}
$args = array(
'limit' => -1,
'status' => array('publish', 'private', 'draft'),
'return' => 'ids',
);
$products = wc_get_products($args);
return count($products);
}
public static function getCustomersCount()
{
if (!class_exists('WP_User_Query')) {
return 0;
}
$args = array(
'fields' => 'ID',
'number' => -1,
);
$user_query = new WP_User_Query($args);
return $user_query->get_total();
}
public static function getOrdersCount()
{
if (!function_exists('wc_get_orders')) {
return 0;
}
$args = array(
'limit' => -1,
'return' => 'ids',
);
$orders = wc_get_orders($args);
return count($orders);
}
public static function getSubscriptionInfo()
{
$businessName = '';
$credit = '';
$expireDate = '';
$plan = '';
$hesabix = new Hesabix_Api();
$response = $hesabix->settingGetSubscriptionInfo();
if (isset($response->Success) && $response->Success && isset($response->Result)) {
$businessName = $response->Result->name ?? 'نامشخص';
$credit = $response->Result->credit ?? 0;
$expireDate = $response->Result->expireDate ?? null;
$plan = $response->Result->subscription ?? 'ندارد';
}
return array(
"businessName" => $businessName,
"credit" => $credit,
"expireDate" => $expireDate,
"plan" => $plan
);
}
public static function hesabix_set_webhook($show_errors = true)
{
$url = get_site_url() . '/index.php?hesabix_webhook=1&token=' . substr(wp_hash(AUTH_KEY . 'hesabix/webhook'), 0, 10);
$hookPassword = get_option('hesabix_webhook_password');
$hesabix_api = new Hesabix_Api();
$response = $hesabix_api->settingSetChangeHook($url, $hookPassword);
if (is_object($response)) {
if ($response->Success) {
update_option('hesabix_live_mode', 1);
update_option('hesabix_account_bid', $response->bid);
update_option('hesabix_account_year', $response->year);
if (Hesabix_Admin_Functions::isDateInFiscalYear(date('Y-m-d H:i:s')) === 0) {
if ($show_errors) {
echo '<div class="error">';
echo '<p class="hesabix-p">' . __('The fiscal year has passed or not arrived. Please check the fiscal year settings in Hesabix.', 'hesabix') . '</p>';
echo '</div>';
}
update_option('hesabix_live_mode', 0);
}
$default_currency = $hesabix_api->settingGetCurrency();
if ($default_currency->Success) {
$woocommerce_currency = get_woocommerce_currency();
$hesabix_currency = $default_currency->Result->moneyName;
if ($hesabix_currency == $woocommerce_currency || ($hesabix_currency == 'IRR' && $woocommerce_currency == 'IRT') || ($hesabix_currency == 'IRT' && $woocommerce_currency == 'IRR')) {
update_option('hesabix_hesabix_default_currency', $hesabix_currency);
} else {
update_option('hesabix_hesabix_default_currency', 0);
update_option('hesabix_live_mode', 0);
if ($show_errors) {
echo '<div class="error">';
echo '<p class="hesabix-p">' . __('Hesabix and WooCommerce default currency must be same.', 'hesabix');
echo '</div>';
}
}
} else {
if ($show_errors) {
echo '<div class="error">';
echo '<p class="hesabix-p">' . __('Cannot check the Hesabix default currency. Error Message: ', 'hesabix') . (string) $default_currency->ErrorMessage . '</p>';
echo '</div>';
}
HesabixLogService::log(array("Cannot check the Hesabix default currency. Error Message: " . (string) $default_currency->ErrorMessage . ". Error Code: " . (string) $default_currency->ErrorCode));
}
if (get_option('hesabix_live_mode') && $show_errors) {
echo '<div class="updated">';
echo '<p class="hesabix-p">' . __('API Setting updated. Test Successfully', 'hesabix') . '</p>';
echo '</div>';
}
} else {
update_option('hesabix_live_mode', 0);
if ($response->ErrorCode === 108) {
if ($show_errors) {
echo '<div class="error">';
echo '<p class="hesabix-p">' . __('Cannot connect to Hesabix. Business expired.', 'hesabix') . (string) $response->ErrorMessage . '</p>';
echo '</div>';
}
update_option('hesabix_business_expired', 1);
} else {
if ($show_errors) {
echo '<div class="error">';
echo '<p class="hesabix-p">' . __('Cannot set Hesabix webHook. Error Message:', 'hesabix') . (string) $response->ErrorMessage . '</p>';
echo '</div>';
}
update_option('hesabix_business_expired', 0);
}
HesabixLogService::log(array("Cannot set Hesabix webHook. Error Message: " . (string) $response->ErrorMessage . ". Error Code: " . (string) $response->ErrorCode));
}
} else {
update_option('hesabix_live_mode', 0);
if ($show_errors) {
echo '<div class="error">';
echo '<p class="hesabix-p">' . __('Cannot connect to Hesabix servers. Please check your Internet connection', 'hesabix') . '</p>';
echo '</div>';
}
HesabixLogService::log(array("Cannot connect to hesabix servers. Check your internet connection"));
}
return $response;
}
public static function hesabix_get_banks()
{
$hesabix_api = new Hesabix_Api();
$banks = $hesabix_api->settingGetBanks();
if (is_object($banks) && $banks->Success) {
$available_banks = array();
$available_banks[-1] = __('Choose', 'hesabix');
foreach ($banks->Result as $bank) {
if ($bank->Currency == get_woocommerce_currency() || (get_woocommerce_currency() == 'IRT' && $bank->Currency == 'IRR') || (get_woocommerce_currency() == 'IRR' && $bank->Currency == 'IRT')) {
$available_banks['bank' . $bank->Code] = $bank->Name . ' - ' . $bank->Branch . ' - ' . $bank->AccountNumber;
}
}
if (empty($available_banks)) {
$available_banks[0] = __('Define at least one bank in Hesabix', 'hesabix');
}
return $available_banks;
} else {
update_option('hesabix_live_mode', 0);
echo '<div class="error">';
echo '<p class="hesabix-p">' . __('Cannot get Banks detail.', 'hesabix') . '</p>';
echo '</div>';
HesabixLogService::log(array("Cannot get banking information. Error Code: " . (string) $banks->ErrorCode . ". Error Message: " . (string) $banks->ErrorMessage . "."));
return array('0' => __('Cannot get Banks detail.', 'hesabix'));
}
}
public static function hesabix_get_cashes()
{
$hesabix_api = new Hesabix_Api();
$cashes = $hesabix_api->settingGetCashes();
if (is_object($cashes) && $cashes->Success) {
$available_cashes = array();
foreach ($cashes->Result as $cash) {
if ($cash->Currency == get_woocommerce_currency() || (get_woocommerce_currency() == 'IRT' && $cash->Currency == 'IRR') || (get_woocommerce_currency() == 'IRR' && $cash->Currency == 'IRT')) {
$available_cashes['cash' . $cash->Code] = $cash->Name;
}
}
return $available_cashes;
}
}
public static function hesabix_get_projects()
{
$hesabix_api = new Hesabix_Api();
$projects = $hesabix_api->settingGetProjects();
if (is_object($projects) && $projects->Success) {
$available_projects = array();
$available_projects[-1] = __('Choose', 'hesabix');
foreach ($projects->data as $project) {
$available_projects[$project->id] = $project->name;
}
return $available_projects;
} else {
update_option('hesabix_live_mode', 0);
echo '<div class="error">';
echo '<p class="hesabix-p">' . __('Cannot get Projects detail.', 'hesabix') . '</p>';
echo '</div>';
HesabixLogService::log(array("Cannot get projects information. Error Code: " . (string) $projects->ErrorCode . ". Error Message: " . (string) $projects->ErrorMessage . "."));
return array('0' => __('Cannot get projects detail.', 'hesabix'));
}
}
public static function hesabix_get_salesmen()
{
$hesabix_api = new Hesabix_Api();
$salesmen = $hesabix_api->settingGetSalesmen();
if (is_object($salesmen) && $salesmen->Success) {
$available_salesmen = array();
$available_salesmen[-1] = __('Choose', 'hesabix');
foreach ($salesmen->result as $salesman) {
$available_salesmen[$salesman->code] = $salesman->nikename;
}
return $available_salesmen;
} else {
update_option('hesabix_live_mode', 0);
echo '<div class="error">';
echo '<p class="hesabix-p">' . __('Cannot get Salesmen detail.', 'hesabix') . '</p>';
echo '</div>';
HesabixLogService::log(array("Cannot get salesmen information. Error Code: " . (string) $salesmen->ErrorCode . ". Error Message: " . (string) $salesmen->ErrorMessage . "."));
return array('0' => __('Cannot get salesmen detail.', 'hesabix'));
}
}
public static function hesabix_log_setting()
{
$cleanLogResult = (isset($_GET['cleanLogResult'])) ? wc_clean($_GET['cleanLogResult']) : null;
if (!is_null($cleanLogResult) && $cleanLogResult === 'true') {
echo '<div class="updated">';
echo '<p class="hesabix-p">' . __('The log file was cleared.', 'hesabix') . '</p>';
echo '</div>';
} elseif ($cleanLogResult === 'false') {
echo '<div class="updated">';
echo '<p class="hesabix-p">' . __('Log file not found.', 'hesabix') . '</p>';
echo '</div>';
}
self::hesabix_tab_log_html();
}
public static function hesabix_tab_log_html()
{
$logFiles = [];
for ($i = 0; $i < 10; $i++) {
$logDate = date("20y-m-d", strtotime(-$i . "day"));
if (file_exists(WP_CONTENT_DIR . '/hesabix-' . $logDate . '.txt')) {
$logFiles[] = $logDate;
}
}
$hasLogs = count($logFiles) > 0;
$defaultLogDate = $hasLogs ? $logFiles[0] : date("20y-m-d");
$defaultLogFile = WP_CONTENT_DIR . '/hesabix-' . $defaultLogDate . '.txt';
$logFileContent = ($hasLogs && file_exists($defaultLogFile)) ? file_get_contents($defaultLogFile) : '';
?>
<div class="hesabix-card hesabix-log-card" style="margin-bottom: 24px;">
<div class="hesabix-alert hesabix-alert-warning hesabix-f d-flex flex-column gap-2 align-items-start"
style="margin-bottom: 0;">
<div class="d-flex gap-2 align-items-center">
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"
style="vertical-align: middle; margin-left: 8px;">
<path d="M1 21h22L12 2 1 21zm12-3h-2v-2h2v2zm0-4h-2v-4h2v4z" />
</svg>
<h4><?php echo __('Important Notice', 'hesabix'); ?></h4>
</div>
<ul>
<li><?php echo __('By clicking the "Delete All Logs" button, all log files will be deleted.', 'hesabix'); ?>
</li>
<li><?php echo __('To delete the current log, click the "Delete Current Log" button when the log file is selected.', 'hesabix'); ?>
</li>
<li><?php echo __('The log history list displays logs from the last 10 days.', 'hesabix'); ?>
</li>
</ul>
</div>
<h3 class="hesabix-tab-page-title" style="margin-top: 24px;"><?php echo __('Events and bugs log', 'hesabix') ?>
</h3>
<div class="hesabix-form-actions hesabix-log-actions"
style="display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 16px; align-items: center;">
<button type="button" id="delete-all-logs-btn" class="hesabix-btn hesabix-btn-danger" style="min-width:160px;"
<?php if (!$hasLogs)
echo 'disabled'; ?>>
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"
style="vertical-align:middle;margin-left:6px;">
<path d="M16 9v10H8V9h8m-1.5-6h-5l-1 1H5v2h14V4h-4.5l-1-1M18 7H6v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V7z" />
</svg>
<?php echo __('Delete All Logs', 'hesabix'); ?>
</button>
<a id="download-log-btn" class="hesabix-btn hesabix-btn-secondary" target="_blank"
href="<?php echo $hasLogs ? WP_CONTENT_URL . '/hesabix-' . $defaultLogDate . '.txt' : '#'; ?>" <?php if (!$hasLogs)
echo 'disabled style="pointer-events:none;opacity:0.5;"'; ?>>
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"
style="vertical-align:middle;margin-left:6px;">
<path d="M5 20h14v-2H5m14-9h-4V3H9v6H5l7 7 7-7z" />
</svg>
<?php echo __('Download Current Log', 'hesabix'); ?>
</a>
<button type="button" id="delete-current-log-btn" class="hesabix-btn hesabix-btn-warning" <?php if (!$hasLogs)
echo 'disabled'; ?>>
<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"
style="vertical-align:middle;margin-left:6px;">
<path
d="M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19M19,4H15.5L14.79,3.29C14.42,2.9 13.88,2.9 13.5,3.29L12.79,4H5V6H19V4Z" />
</svg>
<?php echo __('Delete Current Log', 'hesabix'); ?>
</button>
</div>
<hr>
<div class="hesabix-log-history" style="margin-bottom: 16px;">
<h4 style="margin-bottom: 8px;"><?php echo __('Log History (Last 10 Days)', 'hesabix'); ?>:</h4>
<div id="log-history-list" style="display:flex; flex-wrap:wrap; gap:8px;">
<?php if ($hasLogs) {
foreach ($logFiles as $idx => $logDate) {
$isActive = ($idx === 0) ? ' active' : '';
echo '<button type="button" class="hesabix-btn hesabix-btn-outline log-date-btn' . $isActive . '" data-log-date="' . $logDate . '">' . $logDate . '</button>';
}
} else {
echo '<span style="color:#888;">' . __('No logs found.', 'hesabix') . '</span>';
} ?>
</div>
</div>
<div id="log-message" style="display:none;"></div>
<div class="hesabix-log-content"
style="background: #f8f9fa; border-radius: 8px; border: 1px solid #e3e6ea; padding: 16px;">
<h4 style="margin-bottom: 8px;"><?php echo __('Log Content', 'hesabix'); ?>:</h4>
<textarea id="log-textarea" rows="25"
style="width: 100%; box-sizing: border-box; direction: ltr; background-color: #fff; border-radius: 6px; border: 1px solid #e3e6ea; font-family: monospace; font-size: 14px; padding: 12px; color: #222; resize: vertical; min-height: 300px;"
readonly><?php echo $hasLogs ? $logFileContent : __('No logs found.', 'hesabix'); ?></textarea>
</div>
</div>
<script>
jQuery(document).ready(function ($) {
var currentLogDate = '<?php echo $defaultLogDate; ?>';
function setLogActions(date) {
$('#download-log-btn').attr('href', '<?php echo WP_CONTENT_URL . '/hesabix-'; ?>' + date + '.txt');
$('#delete-current-log-btn').data('log-date', date);
$('.log-date-btn').removeClass('active');
$('.log-date-btn[data-log-date="' + date + '"]:first').addClass('active');
}
setLogActions(currentLogDate);
if (!<?php echo $hasLogs ? 'true' : 'false'; ?>) return;
$('#log-textarea').val('<?php echo __('Loading...', 'hesabix'); ?>');
$.ajax({
url: ajaxurl,
type: 'POST',
data: { action: 'hesabix_get_log_file_ajax', log_date: currentLogDate, nonce: '<?php echo wp_create_nonce('hesabix_ajax_nonce'); ?>' },
success: function (response) {
if (response.success && response.data) {
$('#log-textarea').val(response.data);
} else {
$('#log-textarea').val('<?php echo __('Error fetching log!', 'hesabix'); ?>');
}
},
error: function () {
$('#log-textarea').val('<?php echo __('Error connecting to server!', 'hesabix'); ?>');
}
});
$('.log-date-btn').on('click', function () {
var logDate = $(this).data('log-date');
currentLogDate = logDate;
setLogActions(logDate);
$('#log-message').hide();
$('#log-textarea').val('<?php echo __('Loading...', 'hesabix'); ?>');
$.ajax({
url: ajaxurl,
type: 'POST',
data: { action: 'hesabix_get_log_file_ajax', log_date: logDate, nonce: '<?php echo wp_create_nonce('hesabix_ajax_nonce'); ?>' },
success: function (response) {
if (response.success && response.data) {
$('#log-textarea').val(response.data);
$('#log-message').html('<div class="hesabix-alert hesabix-alert-success" style="margin-bottom:12px;">' + logDate + ' ' + '<?php echo __('log loaded successfully.', 'hesabix'); ?>' + '</div>').fadeIn();
} else {
$('#log-textarea').val('<?php echo __('Error fetching log!', 'hesabix'); ?>');
$('#log-message').html('<div class="hesabix-alert hesabix-alert-danger" style="margin-bottom:12px;">' + '<?php echo __('Error fetching log!', 'hesabix'); ?>' + '</div>').fadeIn();
}
},
error: function () {
$('#log-textarea').val('<?php echo __('Error connecting to server!', 'hesabix'); ?>');
$('#log-message').html('<div class="hesabix-alert hesabix-alert-danger" style="margin-bottom:12px;">' + '<?php echo __('Error connecting to server!', 'hesabix'); ?>' + '</div>').fadeIn();
}
});
});
$('#delete-current-log-btn').on('click', function () {
var logDate = $(this).data('log-date') || currentLogDate;
if (!confirm('<?php echo __('Are you sure you want to delete this log?', 'hesabix'); ?>')) return;
$('#log-message').hide();
$.ajax({
url: ajaxurl,
type: 'POST',
data: { action: 'hesabix_delete_log_file_ajax', log_date: logDate, nonce: '<?php echo wp_create_nonce('hesabix_ajax_nonce'); ?>' },
success: function (response) {
if (response.success) {
$('#log-textarea').val('<?php echo __('Log deleted.', 'hesabix'); ?>');
$('#log-message').html('<div class="hesabix-alert hesabix-alert-success" style="margin-bottom:12px;">' + '<?php echo __('Log deleted successfully.', 'hesabix'); ?>' + '</div>').fadeIn();
$('.log-date-btn[data-log-date="' + logDate + '"]').remove();
if ($('.log-date-btn').length === 0) {
$('#delete-all-logs-btn').prop('disabled', true);
$('#download-log-btn').prop('disabled', true).css({ 'pointer-events': 'none', 'opacity': '0.5' });
$('#delete-current-log-btn').prop('disabled', true);
$('#log-history-list').append('<span style="color:#888;">' + '<?php echo __('No logs found.', 'hesabix'); ?>' + '</span>');
$('#log-textarea').val('<?php echo __('No logs found.', 'hesabix'); ?>');
}
} else {
$('#log-message').html('<div class="hesabix-alert hesabix-alert-danger" style="margin-bottom:12px;">' + '<?php echo __('Error deleting log!', 'hesabix'); ?>' + '</div>').fadeIn();
}
},
error: function () {
$('#log-message').html('<div class="hesabix-alert hesabix-alert-danger" style="margin-bottom:12px;">' + '<?php echo __('Error connecting to server!', 'hesabix'); ?>' + '</div>').fadeIn();
}
});
});
$('#delete-all-logs-btn').on('click', function () {
if (!confirm('<?php echo __('Are you sure you want to delete all logs?', 'hesabix'); ?>')) return;
$('#log-message').hide();
$.ajax({
url: ajaxurl,
type: 'POST',
data: { action: 'hesabix_delete_all_logs_ajax', nonce: '<?php echo wp_create_nonce('hesabix_ajax_nonce'); ?>' },
success: function (response) {
if (response.success) {
$('#log-textarea').val('<?php echo __('All logs deleted.', 'hesabix'); ?>');
$('#log-message').html('<div class="hesabix-alert hesabix-alert-success" style="margin-bottom:12px;">' + '<?php echo __('All logs deleted successfully.', 'hesabix'); ?>' + '</div>').fadeIn();
$('.log-date-btn').remove();
$('#delete-all-logs-btn').prop('disabled', true);
$('#download-log-btn').prop('disabled', true).css({ 'pointer-events': 'none', 'opacity': '0.5' });
$('#delete-current-log-btn').prop('disabled', true);
$('#log-history-list').append('<span style="color:#888;">' + '<?php echo __('No logs found.', 'hesabix'); ?>' + '</span>');
$('#log-textarea').val('<?php echo __('No logs found.', 'hesabix'); ?>');
} else {
$('#log-message').html('<div class="hesabix-alert hesabix-alert-danger" style="margin-bottom:12px;">' + '<?php echo __('Error deleting all logs!', 'hesabix'); ?>' + '</div>').fadeIn();
}
},
error: function () {
$('#log-message').html('<div class="hesabix-alert hesabix-alert-danger" style="margin-bottom:12px;">' + '<?php echo __('Error connecting to server!', 'hesabix'); ?>' + '</div>').fadeIn();
}
});
});
});
</script>
<?php
}
public static function hesabix_get_warehouses()
{
$hesabix_api = new Hesabix_Api();
$warehouses = $hesabix_api->settingGetWarehouses();
if (is_object($warehouses->data)) {
$available_warehouses = array();
$available_warehouses[-1] = __('Accounting quantity (Total inventory)', 'hesabix');
return $available_warehouses;
}
if (is_object($warehouses) && $warehouses->Success) {
$available_warehouses = array();
$available_warehouses[-1] = __('Accounting quantity (Total inventory)', 'hesabix');
foreach ($warehouses->data as $warehouse) {
$available_warehouses[$warehouse->code] = $warehouse->name;
}
return $available_warehouses;
} else {
update_option('hesabix_live_mode', 0);
echo '<div class="error">';
echo '<p class="hesabix-p">' . __('Cannot get warehouses.', 'hesabix') . '</p>';
echo '</div>';
HesabixLogService::log(array("Cannot get warehouses. Error Code: " . (string) $warehouses->ErrorCode . ". Error Message: " . (string) $warehouses->ErrorMessage . "."));
return array('0' => __('Cannot get warehouses.', 'hesabix'));
}
}
}
Hesabix_Setting::init();
add_action('wp_ajax_hesabix_save_catalog_settings_ajax', function () {
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'hesabix_ajax_nonce')) {
wp_send_json_error(array('message' => 'Security check failed'));
return;
}
$fields_to_save = array(
'hesabix_item_update_price' => isset($_POST['hesabix_item_update_price']) ? 'yes' : 'no',
'hesabix_item_update_quantity' => isset($_POST['hesabix_item_update_quantity']) ? 'yes' : 'no',
'hesabix_item_update_quantity_based_on' => isset($_POST['hesabix_item_update_quantity_based_on']) ? sanitize_text_field($_POST['hesabix_item_update_quantity_based_on']) : '',
'hesabix_remove_attributes_titles' => isset($_POST['hesabix_remove_attributes_titles']) ? 'yes' : 'no',
'hesabix_do_not_update_titles_in_hesabix' => isset($_POST['hesabix_do_not_update_titles_in_hesabix']) ? 'yes' : 'no',
'hesabix_do_not_submit_product_automatically' => isset($_POST['hesabix_do_not_submit_product_automatically']) ? 'yes' : 'no',
'hesabix_do_not_update_product_price_in_hesabix' => isset($_POST['hesabix_do_not_update_product_price_in_hesabix']) ? 'yes' : 'no',
'hesabix_do_not_update_product_barcode_in_hesabix' => isset($_POST['hesabix_do_not_update_product_barcode_in_hesabix']) ? 'yes' : 'no',
'hesabix_do_not_update_product_category_in_hesabix' => isset($_POST['hesabix_do_not_update_product_category_in_hesabix']) ? 'yes' : 'no',
'hesabix_do_not_update_product_product_code_in_hesabix' => isset($_POST['hesabix_do_not_update_product_product_code_in_hesabix']) ? 'yes' : 'no',
'hesabix_show_product_code_in_products_page' => isset($_POST['hesabix_show_product_code_in_products_page']) ? 'yes' : 'no',
'hesabix_show_hesabix_code_in_excel_export' => isset($_POST['hesabix_show_hesabix_code_in_excel_export']) ? 'yes' : 'no',
'hesabix_set_special_sale_as_discount' => isset($_POST['hesabix_set_special_sale_as_discount']) ? 'yes' : 'no',
'hesabix_item_update_sale_price' => isset($_POST['hesabix_item_update_sale_price']) ? sanitize_text_field($_POST['hesabix_item_update_sale_price']) : ''
);
$success = true;
foreach ($fields_to_save as $option_name => $option_value) {
$result = update_option($option_name, $option_value);
if (!$result && get_option($option_name) !== $option_value) {
$success = false;
}
}
if ($success) {
wp_send_json_success(array('message' => __('Settings saved successfully', 'hesabix'), 'options' => $fields_to_save));
} else {
wp_send_json_error(array('message' => __('Failed to save settings', 'hesabix')));
}
});
add_action('wp_ajax_hesabix_get_log_file_ajax', function () {
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'hesabix_ajax_nonce')) {
wp_send_json_error(array('message' => 'Security check failed'));
return;
}
$log_date = isset($_POST['log_date']) ? sanitize_text_field($_POST['log_date']) : '';
$file = WP_CONTENT_DIR . '/hesabix-' . $log_date . '.txt';
if (file_exists($file)) {
$content = file_get_contents($file);
wp_send_json_success($content);
} else {
wp_send_json_error();
}
});
add_action('wp_ajax_hesabix_delete_log_file_ajax', function () {
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'hesabix_ajax_nonce')) {
wp_send_json_error(array('message' => 'Security check failed'));
return;
}
$log_date = isset($_POST['log_date']) ? sanitize_text_field($_POST['log_date']) : '';
$file = WP_CONTENT_DIR . '/hesabix-' . $log_date . '.txt';
if (file_exists($file) && unlink($file)) {
wp_send_json_success();
} else {
wp_send_json_error();
}
});
add_action('wp_ajax_hesabix_delete_all_logs_ajax', function () {
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'hesabix_ajax_nonce')) {
wp_send_json_error(array('message' => 'Security check failed'));
return;
}
$prefix = WP_CONTENT_DIR . '/hesabix-';
$files = glob($prefix . '*');
$success = true;
if ($files) {
foreach ($files as $file) {
if (is_file($file)) {
if (!unlink($file)) {
$success = false;
}
}
}
}
if ($success) {
wp_send_json_success();
} else {
wp_send_json_error();
}
});
add_action('wp_ajax_hesabix_save_extra_settings_ajax', function () {
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'hesabix_ajax_nonce')) {
wp_send_json_error(array('message' => 'Security check failed'));
return;
}
$fields_to_save = array(
'hesabix_debug_mode_checkbox' => isset($_POST['hesabix_debug_mode_checkbox']) ? 'yes' : 'no',
'hesabix_set_rpp_for_sync_products_into_hesabix' => isset($_POST['hesabix_set_rpp_for_sync_products_into_hesabix']) ? sanitize_text_field($_POST['hesabix_set_rpp_for_sync_products_into_hesabix']) : '',
'hesabix_set_rpp_for_sync_products_into_woocommerce' => isset($_POST['hesabix_set_rpp_for_sync_products_into_woocommerce']) ? sanitize_text_field($_POST['hesabix_set_rpp_for_sync_products_into_woocommerce']) : '',
'hesabix_set_rpp_for_import_products' => isset($_POST['hesabix_set_rpp_for_import_products']) ? sanitize_text_field($_POST['hesabix_set_rpp_for_import_products']) : '',
'hesabix_set_rpp_for_export_products' => isset($_POST['hesabix_set_rpp_for_export_products']) ? sanitize_text_field($_POST['hesabix_set_rpp_for_export_products']) : '',
'hesabix_set_rpp_for_export_opening_products' => isset($_POST['hesabix_set_rpp_for_export_opening_products']) ? sanitize_text_field($_POST['hesabix_set_rpp_for_export_opening_products']) : ''
);
$success = true;
foreach ($fields_to_save as $option_name => $option_value) {
$result = update_option($option_name, $option_value);
if (!$result && get_option($option_name) !== $option_value) {
$success = false;
}
}
if ($success) {
wp_send_json_success(array('message' => __('Settings saved successfully', 'hesabix')));
} else {
wp_send_json_error(array('message' => __('Failed to save settings', 'hesabix')));
}
});
add_action('wp_ajax_hesabix_save_invoice_settings_ajax', function () {
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'hesabix_ajax_nonce')) {
wp_send_json_error(array('message' => 'Security check failed'));
return;
}
$fields_to_save = array(
'hesabix_invoice_status' => isset($_POST['hesabix_invoice_status']) ? sanitize_text_field($_POST['hesabix_invoice_status']) : '',
'hesabix_invoice_project' => isset($_POST['hesabix_invoice_project']) ? sanitize_text_field($_POST['hesabix_invoice_project']) : '',
'hesabix_invoice_salesman' => isset($_POST['hesabix_invoice_salesman']) ? sanitize_text_field($_POST['hesabix_invoice_salesman']) : '',
'hesabix_invoice_salesman_percentage' => isset($_POST['hesabix_invoice_salesman_percentage']) ? sanitize_text_field($_POST['hesabix_invoice_salesman_percentage']) : '',
'hesabix_invoice_draft_save_in_hesabix' => isset($_POST['hesabix_invoice_draft_save_in_hesabix']) ? 'yes' : 'no',
'hesabix_invoice_freight' => isset($_POST['hesabix_invoice_freight']) ? sanitize_text_field($_POST['hesabix_invoice_freight']) : '',
'hesabix_invoice_freight_code' => isset($_POST['hesabix_invoice_freight_code']) ? sanitize_text_field($_POST['hesabix_invoice_freight_code']) : ''
);
if (is_plugin_active('dokan-lite/dokan.php')) {
$fields_to_save['hesabix_invoice_dokan'] = isset($_POST['hesabix_invoice_dokan']) ? sanitize_text_field($_POST['hesabix_invoice_dokan']) : '0';
}
$success = true;
foreach ($fields_to_save as $option_name => $option_value) {
$result = update_option($option_name, $option_value);
if (!$result && get_option($option_name) !== $option_value) {
$success = false;
}
}
if ($success) {
wp_send_json_success(array('message' => __('Settings saved successfully', 'hesabix')));
} else {
wp_send_json_error(array('message' => __('Failed to save settings', 'hesabix')));
}
});
add_action('wp_ajax_hesabix_save_customers_settings_ajax', function () {
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'hesabix_ajax_nonce')) {
wp_send_json_error(array('message' => 'Security check failed'));
return;
}
$fields_to_save = array(
'hesabix_contact_address_status' => isset($_POST['hesabix_contact_address_status']) ? sanitize_text_field($_POST['hesabix_contact_address_status']) : '',
'hesabix_contact_node_family' => isset($_POST['hesabix_contact_node_family']) ? sanitize_text_field($_POST['hesabix_contact_node_family']) : '',
'hesabix_contact_automatic_save_node_family' => isset($_POST['hesabix_contact_automatic_save_node_family']) ? 'yes' : 'no',
'hesabix_contact_automatically_save_in_hesabix' => isset($_POST['hesabix_contact_automatically_save_in_hesabix']) ? 'yes' : 'no'
);
$success = true;
foreach ($fields_to_save as $option_name => $option_value) {
$result = update_option($option_name, $option_value);
if (!$result && get_option($option_name) !== $option_value) {
$success = false;
}
}
if ($success) {
wp_send_json_success(array('message' => __('Settings saved successfully', 'hesabix')));
} else {
wp_send_json_error(array('message' => __('Failed to save settings', 'hesabix')));
}
});
add_action('wp_ajax_hesabix_get_sync_stats_ajax', function () {
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'hesabix_ajax_nonce')) {
wp_send_json_error(array('message' => 'Security check failed'));
return;
}
$result = Hesabix_Setting::getProductsCount();
wp_send_json_success([
'storeProductsCount' => $result['storeProductsCount'],
'hesabixProductsCount' => $result['hesabixProductsCount'],
'linkedProductsCount' => $result['linkedProductsCount'],
]);
});