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) public function exportCustomers($batch, $totalBatch, $total, $updateCount)
{ {
HesabixLogService::writeLogStr("Export Customers"); HesabixLogService::writeLogStr("Export Customers");
$wpFaService = new HesabixWpFaService();
$result = array(); $result = array();
$result["error"] = false; $result["error"] = false;
$rpp = 500;
global $wpdb; global $wpdb;
$total = $wpdb->get_var("SELECT COUNT(*) FROM `" . $wpdb->prefix . "users`");
if ($batch == 1) { $customers = $wpdb->get_results("SELECT id,user_nicename,user_email FROM " . $wpdb->prefix . "users");
$total = $wpdb->get_var("SELECT COUNT(*) FROM `" . $wpdb->prefix . "users`"); $data = array();
$totalBatch = ceil($total / $rpp); foreach($customers as $customer){
} $temp = array();
$tempresult = $wpdb->get_results("SELECT meta_key,meta_value FROM `" . $wpdb->prefix . "usermeta` WHERE user_id='". $customer->id . "'");
$offset = ($batch - 1) * $rpp; foreach($tempresult as $tmr){
$customers = $wpdb->get_results("SELECT ID FROM `" . $wpdb->prefix . "users` ORDER BY ID ASC LIMIT $offset,$rpp"); if($tmr->meta_key == 'nickname'){
$temp['nickname'] = $tmr->meta_value;
$items = array(); }
foreach ($customers as $item) { if($tmr->meta_key == 'first_name'){
$id_customer = $item->ID; $temp['name'] = $tmr->meta_value;
$id_obj = $wpFaService->getWpFaId('customer', $id_customer); }
if (!$id_obj) { if($tmr->meta_key == 'last_name'){
$hesabixCustomer = ssbhesabixCustomerService::mapCustomer(null, $id_customer); $temp['name'] .= $tmr->meta_value;
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));
} }
} 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["total"] = $total;
$result["updateCount"] = $updateCount;
return $result; return $result;
} }

View file

@ -1527,31 +1527,7 @@ class Ssbhesabix_Setting {
return $available_cashes; 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() { public static function ssbhesabix_get_salesmen() {
$ssbhesabix_api = new Ssbhesabix_Api(); $ssbhesabix_api = new Ssbhesabix_Api();

View file

@ -111,16 +111,6 @@ class Ssbhesabix_Api
return $this->apiRequest($method, $data); 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) public function contactDelete($code)
{ {
$method = 'contact/delete'; $method = 'contact/delete';
@ -438,10 +428,16 @@ class Ssbhesabix_Api
return $this->apiRequest($method); return $this->apiRequest($method);
} }
//================================================================================================ //================================================================================================
public function settingExportProdects($data)
{
$method = 'hooks/commodity/import';
return $this->apiRequest($method,$data);
}
//================================================================================================ //================================================================================================
public function settingExportProdects($data) public function personsImport($data)
{ {
$method = 'hooks/commodity/import'; $method = 'hooks/person/import';
return $this->apiRequest($method,$data); return $this->apiRequest($method,$data);
} }
} }

View file

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