Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions backend/Actions/WpErp/RecordApiHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

/**
* WP ERP Record Api
*/

namespace BitApps\Integrations\Actions\WpErp;

use BitApps\Integrations\Config;
use BitApps\Integrations\Core\Util\Common;
use BitApps\Integrations\Core\Util\Hooks;
use BitApps\Integrations\Log\LogHandler;

class RecordApiHelper
{
private $_integrationID;

private $_integrationDetails;

public function __construct($integrationDetails, $integId)
{
$this->_integrationDetails = $integrationDetails;
$this->_integrationID = $integId;
}

public function execute($fieldValues, $fieldMap, $utilities)
{
if (!\function_exists('erp_insert_people')) {
return [
'success' => false,
'message' => __('WP ERP is not installed or activated', 'bit-integrations')
];
}

$fieldData = static::generateReqDataFromFieldMap($fieldMap, $fieldValues);
$mainAction = $this->_integrationDetails->mainAction ?? '';

$defaultResponse = [
'success' => false,
// translators: %s: Plugin name
'message' => wp_sprintf(__('%s plugin is not installed or activated', 'bit-integrations'), 'Bit Integrations Pro')
];

$hookMap = [
'createContact' => ['hook' => 'wperp_create_contact', 'type' => 'contact'],
'updateContact' => ['hook' => 'wperp_update_contact', 'type' => 'contact'],
'createCompany' => ['hook' => 'wperp_create_company', 'type' => 'company'],
'updateCompany' => ['hook' => 'wperp_update_company', 'type' => 'company'],
'createContactGroup' => ['hook' => 'wperp_create_contact_group', 'type' => 'contact_group'],
'addContactToGroup' => ['hook' => 'wperp_add_contact_to_group', 'type' => 'contact_group'],
'removeContactFromGroup' => ['hook' => 'wperp_remove_contact_from_group', 'type' => 'contact_group'],
'addNote' => ['hook' => 'wperp_add_note', 'type' => 'note'],
'createTask' => ['hook' => 'wperp_create_task', 'type' => 'task'],
'createDepartment' => ['hook' => 'wperp_create_department', 'type' => 'department'],
'createDesignation' => ['hook' => 'wperp_create_designation', 'type' => 'designation'],
'createHoliday' => ['hook' => 'wperp_create_holiday', 'type' => 'holiday'],
'createExpense' => ['hook' => 'wperp_create_expense', 'type' => 'expense'],
'createPayment' => ['hook' => 'wperp_create_payment', 'type' => 'payment'],
];

if (!isset($hookMap[$mainAction])) {
$response = [
'success' => false,
'message' => __('Invalid action', 'bit-integrations')
];
$type = 'WpErp';
$actionType = 'unknown';
} else {
$entry = $hookMap[$mainAction];
$response = Hooks::apply(
Config::withPrefix($entry['hook']),
$defaultResponse,
$fieldData,
$utilities,
);
$type = $entry['type'];
$actionType = $mainAction;
}

$responseType = (!is_wp_error($response) && isset($response['success']) && $response['success']) ? 'success' : 'error';
LogHandler::save($this->_integrationID, ['type' => $type, 'type_name' => $actionType], $responseType, $response);

return $response;
}

private static function generateReqDataFromFieldMap($fieldMap, $fieldValues)
{
$dataFinal = [];
foreach ($fieldMap as $item) {
$triggerValue = $item->formField;
$actionValue = $item->wpErpField;

if (empty($actionValue)) {
continue;
}

$dataFinal[$actionValue] = $triggerValue === 'custom' && isset($item->customValue)
? Common::replaceFieldWithValue($item->customValue, $fieldValues)
: ($fieldValues[$triggerValue] ?? '');
}

return $dataFinal;
}
}
14 changes: 14 additions & 0 deletions backend/Actions/WpErp/Routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

if (!defined('ABSPATH')) {
exit;
}

use BitApps\Integrations\Actions\WpErp\WpErpController;
use BitApps\Integrations\Core\Util\Route;

Route::post('wp_erp_authorize', [WpErpController::class, 'wpErpAuthorize']);
Route::post('refresh_wp_erp_contact_groups', [WpErpController::class, 'refreshContactGroups']);
Route::post('refresh_wp_erp_life_stages', [WpErpController::class, 'refreshLifeStages']);
Route::post('refresh_wp_erp_departments', [WpErpController::class, 'refreshDepartments']);
Route::post('refresh_wp_erp_designations', [WpErpController::class, 'refreshDesignations']);
122 changes: 122 additions & 0 deletions backend/Actions/WpErp/WpErpController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php

/**
* WP ERP Integration
*/

namespace BitApps\Integrations\Actions\WpErp;

use WP_Error;

class WpErpController
Comment thread
RishadAlam marked this conversation as resolved.
{
public static function isExists()
{
if (!\function_exists('erp_insert_people')) {
wp_send_json_error(__('WP ERP is not activated or not installed', 'bit-integrations'), 400);
}
}

public static function wpErpAuthorize()
{
self::isExists();
wp_send_json_success(true);
}

public function refreshContactGroups()
{
self::isExists();

$groups = [];

if (\function_exists('erp_crm_get_contact_groups')) {
$groups = array_map(
function ($group) {
$group = (array) $group;

return (object) [
'value' => $group['id'] ?? '',
'label' => $group['name'] ?? '',
];
},
(array) erp_crm_get_contact_groups(['number' => -1])
);
}

wp_send_json_success(['groups' => $groups], 200);
}

public function refreshLifeStages()
{
self::isExists();

$stages = [];

if (\function_exists('erp_crm_get_life_stages_dropdown_raw')) {
foreach ((array) erp_crm_get_life_stages_dropdown_raw() as $value => $label) {
$stages[] = (object) ['value' => $value, 'label' => $label];
}
}

wp_send_json_success(['stages' => $stages], 200);
}

public function refreshDepartments()
{
self::isExists();

$out = [];

if (\function_exists('erp_hr_get_departments')) {
foreach ((array) erp_hr_get_departments(['number' => -1, 'no_object' => true]) as $dept) {
$dept = (array) $dept;
$out[] = (object) [
'value' => $dept['id'] ?? '',
'label' => $dept['title'] ?? '',
];
}
}

wp_send_json_success(['departments' => $out], 200);
}

public function refreshDesignations()
{
self::isExists();

$out = [];

if (\function_exists('erp_hr_get_designations')) {
foreach ((array) erp_hr_get_designations(['number' => -1, 'no_object' => true]) as $designation) {
$designation = (array) $designation;
$out[] = (object) [
'value' => $designation['id'] ?? '',
'label' => $designation['title'] ?? '',
];
}
}

wp_send_json_success(['designations' => $out], 200);
}

public function execute($integrationData, $fieldValues)
{
$integrationDetails = $integrationData->flow_details;
$integId = $integrationData->id;
$fieldMap = $integrationDetails->field_map;
$utilities = $integrationDetails->utilities ?? [];

if (empty($fieldMap)) {
return new WP_Error('field_map_empty', __('Field map is empty', 'bit-integrations'));
}

$recordApiHelper = new RecordApiHelper($integrationDetails, $integId);
$wpErpResponse = $recordApiHelper->execute($fieldValues, $fieldMap, $utilities);

if (is_wp_error($wpErpResponse)) {
return $wpErpResponse;
}

return $wpErpResponse;
}
}
1 change: 1 addition & 0 deletions backend/Core/Util/AllTriggersName.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public static function allTriggersName()
'WSForm' => ['name' => 'WSForm', 'isPro' => true, 'is_active' => false],
'WishlistMember' => ['name' => 'Wishlist Member', 'isPro' => true, 'is_active' => false],
'WpAllImport' => ['name' => 'WP All Import', 'isPro' => true, 'is_active' => false],
'WpErp' => ['name' => 'WP ERP', 'isPro' => true, 'is_active' => false],
Comment thread
RishadAlam marked this conversation as resolved.
'WPLMS' => ['name' => 'WPLMS', 'isPro' => true, 'is_active' => false],
'WPLoyalty' => ['name' => 'WPLoyalty', 'isPro' => true, 'is_active' => false],
'WPSubscription' => ['name' => 'WPSubscription', 'isPro' => true, 'is_active' => false],
Expand Down
5 changes: 5 additions & 0 deletions backend/Flow/Flow.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,11 @@ public static function execute($triggered_entity, $triggered_entity_id, $data, $

break;

case 'WPERP':
$integrationName = 'WpErp';

break;

case 'Monday.Com':
$integrationName = 'MondayCom';

Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/AllIntegrations/EditInteg.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ const EditWishlistMember = lazy(() => import('./WishlistMember/EditWishlistMembe
const EditCreatorLms = lazy(() => import('./CreatorLms/EditCreatorLms'))
const EditUltimateAffiliatePro = lazy(() => import('./UltimateAffiliatePro/EditUltimateAffiliatePro'))
const EditFluentCart = lazy(() => import('./FluentCart/EditFluentCart'))
const EditWpErp = lazy(() => import('./WpErp/EditWpErp'))
const EditPeepSo = lazy(() => import('./PeepSo/EditPeepSo'))
const EditNinjaTables = lazy(() => import('./NinjaTables/EditNinjaTables'))
const EditWCAffiliate = lazy(() => import('./WCAffiliate/EditWCAffiliate'))
Expand Down Expand Up @@ -597,6 +598,8 @@ const IntegType = memo(({ allIntegURL, flow }) => {
return <EditUltimateAffiliatePro allIntegURL={allIntegURL} />
case 'FluentCart':
return <EditFluentCart allIntegURL={allIntegURL} />
case 'WP ERP':
return <EditWpErp allIntegURL={allIntegURL} />
case 'PeepSo':
return <EditPeepSo allIntegURL={allIntegURL} />
case 'Ninja Tables':
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/AllIntegrations/IntegInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ const UltimateAffiliateProAuthorization = lazy(
() => import('./UltimateAffiliatePro/UltimateAffiliateProAuthorization')
)
const FluentCartAuthorization = lazy(() => import('./FluentCart/FluentCartAuthorization'))
const WpErpAuthorization = lazy(() => import('./WpErp/WpErpAuthorization'))
const PeepSoAuthorization = lazy(() => import('./PeepSo/PeepSoAuthorization'))
const NinjaTablesAuthorization = lazy(() => import('./NinjaTables/NinjaTablesAuthorization'))
const WCAffiliateAuthorization = lazy(() => import('./WCAffiliate/WCAffiliateAuthorization'))
Expand Down Expand Up @@ -640,6 +641,8 @@ export default function IntegInfo() {
)
case 'FluentCart':
return <FluentCartAuthorization fluentCartConf={integrationConf} step={1} isInfo />
case 'WP ERP':
return <WpErpAuthorization wpErpConf={integrationConf} step={1} isInfo />
Comment thread
RishadAlam marked this conversation as resolved.
Comment thread
RishadAlam marked this conversation as resolved.
case 'PeepSo':
return <PeepSoAuthorization peepSoConf={integrationConf} step={1} isInfo />
case 'Ninja Tables':
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/components/AllIntegrations/NewInteg.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const WishlistMember = lazy(() => import('./WishlistMember/WishlistMember'))
const CreatorLms = lazy(() => import('./CreatorLms/CreatorLms'))
const UltimateAffiliatePro = lazy(() => import('./UltimateAffiliatePro/UltimateAffiliatePro'))
const FluentCart = lazy(() => import('./FluentCart/FluentCart'))
const WpErp = lazy(() => import('./WpErp/WpErp'))
const PeepSo = lazy(() => import('./PeepSo/PeepSo'))
const NinjaTables = lazy(() => import('./NinjaTables/NinjaTables'))
const WCAffiliate = lazy(() => import('./WCAffiliate/WCAffiliate'))
Expand Down Expand Up @@ -1679,6 +1680,15 @@ export default function NewInteg({ allIntegURL }) {
setFlow={setFlow}
/>
)
case 'WP ERP':
return (
<WpErp
allIntegURL={allIntegURL}
formFields={flow?.triggerData?.fields}
flow={flow}
setFlow={setFlow}
/>
)
case 'PeepSo':
return (
<PeepSo
Expand Down
76 changes: 76 additions & 0 deletions frontend/src/components/AllIntegrations/WpErp/EditWpErp.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { useState } from 'react'
import { useNavigate, useParams } from 'react-router'
import { useRecoilState, useRecoilValue } from 'recoil'
import { $actionConf, $formFields, $newFlow } from '../../../GlobalStates'
import { __ } from '../../../Utils/i18nwrap'
import SnackMsg from '../../Utilities/SnackMsg'
import { saveActionConf } from '../IntegrationHelpers/IntegrationHelpers'
import IntegrationStepThree from '../IntegrationHelpers/IntegrationStepThree'
import SetEditIntegComponents from '../IntegrationHelpers/SetEditIntegComponents'
import { checkMappedFields, handleInput } from './WpErpCommonFunc'
import WpErpIntegLayout from './WpErpIntegLayout'

export default function EditWpErp({ allIntegURL }) {
const navigate = useNavigate()
const { id, formID } = useParams()

const [wpErpConf, setWpErpConf] = useRecoilState($actionConf)
const [flow, setFlow] = useRecoilState($newFlow)
const formFields = useRecoilValue($formFields)
const [isLoading, setIsLoading] = useState(false)
const [snack, setSnackbar] = useState({ show: false })

return (
<div style={{ width: 900 }}>
<SnackMsg snack={snack} setSnackbar={setSnackbar} />

<div className="flx mt-3">
<b className="wdt-200 d-in-b">{__('Integration Name:', 'bit-integrations')}</b>
<input
className="btcd-paper-inp w-5"
onChange={e => handleInput(e, wpErpConf, setWpErpConf)}
name="name"
value={wpErpConf.name}
type="text"
placeholder={__('Integration Name...', 'bit-integrations')}
/>
</div>
<br />

<SetEditIntegComponents entity={flow.triggered_entity} setSnackbar={setSnackbar} />

<WpErpIntegLayout
formID={formID}
formFields={formFields}
wpErpConf={wpErpConf}
setWpErpConf={setWpErpConf}
setSnackbar={setSnackbar}
setIsLoading={setIsLoading}
isLoading={isLoading}
/>

<IntegrationStepThree
edit
saveConfig={() =>
saveActionConf({
flow,
setFlow,
allIntegURL,
conf: wpErpConf,
navigate,
id,
edit: 1,
setIsLoading,
setSnackbar
})
}
disabled={!checkMappedFields(wpErpConf)}
isLoading={isLoading}
dataConf={wpErpConf}
setDataConf={setWpErpConf}
formFields={formFields}
/>
<br />
</div>
)
}
Loading
Loading