add hook api to export perons to hesabix

This commit is contained in:
Hesabix 2024-01-14 01:41:27 +00:00
parent ebdd691308
commit 70a299c0e0
4 changed files with 36 additions and 83 deletions

View file

@ -796,56 +796,37 @@ class Ssbhesabix_Admin_Functions
public function exportCustomers($batch, $totalBatch, $total, $updateCount)
{
HesabixLogService::writeLogStr("Export Customers");
$wpFaService = new HesabixWpFaService();
$result = array();
$result["error"] = false;
$rpp = 500;
global $wpdb;
if ($batch == 1) {
$total = $wpdb->get_var("SELECT COUNT(*) FROM `" . $wpdb->prefix . "users`");
$totalBatch = ceil($total / $rpp);
}
$offset = ($batch - 1) * $rpp;
$customers = $wpdb->get_results("SELECT ID FROM `" . $wpdb->prefix . "users` ORDER BY ID ASC LIMIT $offset,$rpp");
$items = array();
foreach ($customers as $item) {
$id_customer = $item->ID;
$id_obj = $wpFaService->getWpFaId('customer', $id_customer);
if (!$id_obj) {
$hesabixCustomer = ssbhesabixCustomerService::mapCustomer(null, $id_customer);
array_push($items, $hesabixCustomer);
$updateCount++;
}
}
if (!empty($items)) {
$hesabix = new Ssbhesabix_Api();
$response = $hesabix->contactBatchSave($items);
if ($response->Success) {
foreach ($response->Result as $item) {
$json = json_decode($item->Tag);
$wpdb->insert($wpdb->prefix . 'ssbhesabix', array(
'id_hesabix' => (int)$item->Code,
'obj_type' => 'customer',
'id_ps' => (int)$json->id_customer,
));
HesabixLogService::log(array("Contact successfully added. Contact Code: " . $item->Code . ". Customer ID: " . (int)$json->id_customer));
$total = $wpdb->get_var("SELECT COUNT(*) FROM `" . $wpdb->prefix . "users`");
$customers = $wpdb->get_results("SELECT id,user_nicename,user_email FROM " . $wpdb->prefix . "users");
$data = array();
foreach($customers as $customer){
$temp = array();
$tempresult = $wpdb->get_results("SELECT meta_key,meta_value FROM `" . $wpdb->prefix . "usermeta` WHERE user_id='". $customer->id . "'");
foreach($tempresult as $tmr){
if($tmr->meta_key == 'nickname'){
$temp['nickname'] = $tmr->meta_value;
}
if($tmr->meta_key == 'first_name'){
$temp['name'] = $tmr->meta_value;
}
if($tmr->meta_key == 'last_name'){
$temp['name'] .= $tmr->meta_value;
}
} else {
HesabixLogService::log(array("Cannot add bulk contacts. Error Message: $response->ErrorMessage. Error Code: $response->ErrorCode."));
}
$temp['email'] .= $customer->user_email;
array_push($data,$temp);
}
$hesabix = new Ssbhesabix_Api();
$response = $hesabix->personsImport(['data'=>$data]);
if ($response->Success) {
HesabixLogService::log(array("Contact successfully added."));
} else {
HesabixLogService::log(array("Cannot add bulk contacts. Error Message: $response->ErrorMessage. Error Code: $response->ErrorCode."));
}
$result["batch"] = $batch;
$result["totalBatch"] = $totalBatch;
$result["total"] = $total;
$result["updateCount"] = $updateCount;
return $result;
}

View file

@ -1527,31 +1527,7 @@ class Ssbhesabix_Setting {
return $available_cashes;
}
}
//=============================================================================================
public static function ssbhesabix_get_projects() {
$ssbhesabix_api = new Ssbhesabix_Api();
$projects = $ssbhesabix_api->settingGetProjects();
if ( is_object( $projects ) && $projects->Success ) {
$available_projects = array();
$available_projects[ - 1 ] = __( 'Choose', 'ssbhesabix' );
foreach ( $projects->Result as $project ) {
if ( $project->Active ) {
$available_projects[ $project->Title ] = $project->Title;
}
}
return $available_projects;
} else {
update_option( 'ssbhesabix_live_mode', 0 );
echo '<div class="error">';
echo '<p class="hesabix-p">' . __( 'Cannot get Projects detail.', 'ssbhesabix' ) . '</p>';
echo '</div>';
HesabixLogService::log( array("Cannot get projects information. Error Code:$projects->ErrorCode. Error Message: $projects->ErrorMessage.") );
return array( '0' => __( 'Cannot get projects detail.', 'ssbhesabix' ) );
}
}
//=============================================================================================
public static function ssbhesabix_get_salesmen() {
$ssbhesabix_api = new Ssbhesabix_Api();

View file

@ -111,16 +111,6 @@ class Ssbhesabix_Api
return $this->apiRequest($method, $data);
}
//================================================================================================
public function contactBatchSave($contacts)
{
$method = 'contact/batchsave';
$data = array(
'contacts' => $contacts,
);
return $this->apiRequest($method, $data);
}
//================================================================================================
public function contactDelete($code)
{
$method = 'contact/delete';
@ -438,10 +428,16 @@ class Ssbhesabix_Api
return $this->apiRequest($method);
}
//================================================================================================
public function settingExportProdects($data)
{
$method = 'hooks/commodity/import';
return $this->apiRequest($method,$data);
}
//================================================================================================
public function settingExportProdects($data)
{
$method = 'hooks/commodity/import';
return $this->apiRequest($method,$data);
}
public function personsImport($data)
{
$method = 'hooks/person/import';
return $this->apiRequest($method,$data);
}
}

View file

@ -26,7 +26,7 @@ class Ssbhesabix_i18n {
load_plugin_textdomain(
'ssbhesabix',
false,
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages1/'
);
}