Skip to content

Commit

Permalink
did destination bulk
Browse files Browse the repository at this point in the history
  • Loading branch information
magnussolution authored and callcenter-magnus committed Aug 21, 2023
1 parent c37de88 commit f6e5345
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 0 deletions.
Binary file modified build/MagnusBilling-current.tar.gz
Binary file not shown.
175 changes: 175 additions & 0 deletions classic/src/view/did/Bulk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/**
* Classe que define a window import csv de "Rate"
*
* =======================================
* ###################################
* MagnusBilling
*
* @package MagnusBilling
* @author Adilson Leffa Magnus.
* @copyright Todos os direitos reservados.
* ###################################
* =======================================
* MagnusSolution.com <[email protected]>
* 08/11/2012
*/
Ext.define('MBilling.view.did.Bulk', {
extend: 'Ext.window.Window',
alias: 'widget.didbulk',
autoShow: true,
modal: true,
layout: 'fit',
iconCls: 'icon-import-csv',
title: t('Bulk destination'),
width: 400,
height: window.isThemeNeptune || window.isThemeCrisp ? 295 : window.isThemeTriton ? 390 : 270,
labelWidthFields: 120,
htmlTipInfo: '',
fieldsImport: [],
fil: [],
initComponent: function() {
var me = this,
filters = me.list.filters.getFilterData();
if (!filters || filters == 0) {
Ext.ux.Alert.alert('Alert', t('Use filters'), 'information');
me.items = [{}]
} else {
me.fil = filters;
me.items = [{
xtype: 'form',
reference: 'didbilkPanel',
bodyPadding: 5,
defaults: {
anchor: '0',
enableKeyEvents: true,
labelWidth: me.labelWidthFields,
msgTarget: 'side',
plugins: 'markallowblank',
allowBlank: false
},
items: [{
xtype: 'userlookup',
name: 'id_user',
fieldLabel: t('Username'),
allowBlank: false
}, {
xtype: 'fieldset',
style: 'margin-top:25px; overflow: visible;',
title: t('DID destination'),
collapsible: true,
collapsed: false,
defaults: {
labelWidth: 90,
anchor: '100%',
labelAlign: me.labelAlignFields
},
items: [{
xtype: 'didtypecombo',
name: 'voip_call',
fieldLabel: t('Type'),
listeners: {
select: function(combo, records, eOpts) {
me.onSelectMethod(combo, records)
},
scope: this
}
}, {
xtype: 'textfield',
name: 'destination',
fieldLabel: t('Destination'),
value: '',
allowBlank: true,
hidden: true
}, {
xtype: 'ivrlookup',
name: 'id_ivr',
fieldLabel: t('IVR'),
allowBlank: true,
hidden: true
}, {
xtype: 'queuelookup',
name: 'id_queue',
fieldLabel: t('Queue'),
allowBlank: true,
hidden: true
}, {
xtype: 'siplookup',
name: 'id_sip',
fieldLabel: t('Sip user'),
allowBlank: true
}, {
xtype: 'textarea',
name: 'context',
fieldLabel: t('Context'),
allowBlank: true,
emptyText: t('Asterisk dial plan. Example: exten => _X.=>1,Dial(SIP/[email protected],30); )'),
height: 300,
anchor: '100%',
hidden: true
}]
}]
}];
}
me.title = me.title + (me.titleModule ? ' - ' + me.titleModule : '');
me.bbar = [{
width: 150,
iconCls: 'icon-import-csv',
text: t('Bulk DID Destination'),
scope: me,
handler: me.onBulk
}];
me.callParent(arguments);
},
onSelectMethod: function(combo, records) {
this.showFieldsRelated(records.getData().showFields);
},
showFieldsRelated: function(showFields) {
var me = this,
getForm = me.down('form');
fields = getForm.getForm().getFields();
fields.each(function(field) {
if (field.name == 'id_user') {
field.setVisible(true);
} else {
field.setVisible(showFields.indexOf(field.name) !== -1);
}
});
},
onBulk: function(btn) {
var me = this,
store = me.list.getStore();
if (!me.down('form').isValid()) {
return;
}
Ext.Ajax.setTimeout(1000000);
me.down('form').submit({
url: 'index.php/diddestination/bulkdestinatintion',
scope: me,
params: {
filters: Ext.encode(me.fil)
},
success: function(form, action) {
var obj = Ext.decode(action.response.responseText);
if (obj.success) {
Ext.ux.Alert.alert(t('Success'), obj.msg, 'success');
} else {
Ext.ux.Alert.alert(t('Error'), obj.errors, 'error');
}
btn.enable();
me.list.setLoading(false);
store.load();
me.close();
},
failure: function(form, action) {
var obj = Ext.decode(action.response.responseText),
errors = Helper.Util.convertErrorsJsonToString(obj.errors);
if (!Ext.isObject(obj.errors)) {
Ext.ux.Alert.alert(me.titleError, t(errors), 'error');
} else {
form.markInvalid(obj.errors);
Ext.ux.Alert.alert(me.titleWarning, t(errors), 'error');
}
}
});
}
});
1 change: 1 addition & 0 deletions classic/src/view/did/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/
Ext.define('MBilling.view.did.Controller', {
extend: 'Ext.ux.app.ViewController',
requires: ['MBilling.view.did.Bulk'],
alias: 'controller.did',
isSubmitForm: true,
init: function() {
Expand Down
5 changes: 5 additions & 0 deletions classic/src/view/did/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ Ext.define('MBilling.view.did.List', {
iconCls: 'icon-delete',
handler: 'onRelease',
disabled: false
}, {
text: t('Bulk DID'),
iconCls: 'icon-delete',
handler: 'onBulk',
hidden: !App.user.isAdmin || window.isTablet
}];
if (App.user.isClient) {
me.buttonImportCsv = false;
Expand Down
98 changes: 98 additions & 0 deletions protected/controllers/DiddestinationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,104 @@ public function checkRelation($values)

}

public function actionbulkdestinatintion()
{
$this->isNewRecord = true;
$values = $this->getAttributesRequest();



$_GET['filter'] = $values['filters'];

$id_user = $values['id_user'];

$this->setfilter($_GET);

$modelDid = Did::model()->findAll($this->filter, $this->paramsFilter);

foreach ($modelDid as $key => $did) {

$values['id_did'] = $did->id;

if ($did->id_user == null && $did->reserved == 0) {

//isnewDID

$modelDiddestination = new Diddestination();
$modelDiddestination->id_did = $did->id;
$modelDiddestination->id_user = $id_user;
$modelDiddestination->voip_call = $values['voip_call'];
$modelDiddestination->priority = 1;
if (strlen($values['destination']) && $values['destination'] != 'undefined') {
$modelDiddestination->destination = $values['destination'];
}
if (strlen($values['id_ivr']) && $values['id_ivr'] != 'undefined') {
$modelDiddestination->id_ivr = $values['id_ivr'];
}

if (strlen($values['id_queue']) && $values['id_queue'] != 'undefined') {
$modelDiddestination->id_queue = $values['id_queue'];
}

if (strlen($values['id_sip']) && $values['id_sip'] != 'undefined') {
$modelDiddestination->id_sip = $values['id_sip'];
}

if (strlen($values['context']) && $values['context'] != 'undefined') {
$modelDiddestination->context = $values['context'];
}

$values = $this->beforeSave($values);

$modelDiddestination->save();

$this->afterSave($modelDiddestination, $values);

} else {
//update destination

$modelDiddestination = Diddestination::model()->find('id_did = :key', [':key' => $did->id]);

if (isset($modelDiddestination)) {
if ($modelDiddestination->id_user == $id_user) {
//update destination
$modelDiddestination->voip_call = $values['voip_call'];
if (strlen($values['destination']) && $values['destination'] != 'undefined') {
$modelDiddestination->destination = $values['destination'];
}
if (strlen($values['id_ivr']) && $values['id_ivr'] != 'undefined') {
$modelDiddestination->id_ivr = $values['id_ivr'];
}

if (strlen($values['id_queue']) && $values['id_queue'] != 'undefined') {
$modelDiddestination->id_queue = $values['id_queue'];
}

if (strlen($values['id_sip']) && $values['id_sip'] != 'undefined') {
$modelDiddestination->id_sip = $values['id_sip'];
}

if (strlen($values['context']) && $values['context'] != 'undefined') {
$modelDiddestination->context = $values['context'];
}
$values = $this->beforeSave($values);
$modelDiddestination->save();

} else {
continue;
}
}
}
}

AsteriskAccess::instance()->generateSipDid();
echo json_encode(array(
$this->nameSuccess => $this->success,
$this->nameMsg => $this->msg,
));

}

public function afterSave($model, $values)
{
AsteriskAccess::instance()->writeDidContext();
Expand Down

0 comments on commit f6e5345

Please sign in to comment.