I made module for vtiger 6.5 but it is not showing. - vtiger

language and module file path
vtiger/language/en_us/Expenses.php
vtiger/modules/Expenses/Expenses.php
both file are same.
include_once 'modules/Vtiger/CRMEntity.php';
class Expenses extends Vtiger_CRMEntity {
var $table_name = 'vtiger_expenses';
var $table_index= 'expensesid';
var $customFieldTable = Array('vtiger_expensescf', 'expensesid');
var $tab_name = Array('vtiger_crmentity', 'vtiger_expenses', 'vtiger_expensescf');
var $tab_name_index = Array(
'vtiger_crmentity' => 'crmid',
'vtiger_expenses' => 'expensesid',
'vtiger_expensescf'=>'expensesid');
var $list_fields = Array (
/* Format: Field Label => Array(tablename, columnname) */
// tablename should not have prefix 'vtiger_'
'Summary' => Array('expenses', 'summary'),
'Assigned To' => Array('crmentity','smownerid')
);
var $list_fields_name = Array (
/* Format: Field Label => fieldname */
'Summary' => 'summary',
'Assigned To' => 'assigned_user_id',
);
// Make the field link to detail view
var $list_link_field = 'summary';
// For Popup listview and UI type support
var $search_fields = Array(
/* Format: Field Label => Array(tablename, columnname) */
// tablename should not have prefix 'vtiger_'
'Summary' => Array('expenses', 'summary'),
'Assigned To' => Array('vtiger_crmentity','assigned_user_id'),
);
var $search_fields_name = Array (
/* Format: Field Label => fieldname */
'Summary' => 'summary',
'Assigned To' => 'assigned_user_id',
);
// For Popup window record selection
var $popup_fields = Array ('summary');
// For Alphabetical search
var $def_basicsearch_col = 'summary';
// Column value to use on detail view record text display
var $def_detailview_recname = 'summary';
// Used when enabling/disabling the mandatory fields for the module.
// Refers to vtiger_field.fieldname values.
var $mandatory_fields = Array('summary','assigned_user_id');
var $default_order_by = 'summary';
var $default_sort_order='ASC';
}
root file
vtiger/Expenses.php
include_once 'vtlib/Vtiger/Module.php';
$Vtiger_Utils_Log = true;
$MODULENAME = 'Expenses';
$moduleInstance = Vtiger_Module::getInstance($MODULENAME);
if ($moduleInstance || file_exists('modules/'.$MODULENAME)) {
echo "Module already present - choose a different name.";
} else {
$moduleInstance = new Vtiger_Module();
$moduleInstance->name = $MODULENAME;
$moduleInstance->parent= 'Tools';
$moduleInstance->save();
// Schema Setup
$moduleInstance->initTables();
// Field Setup
$block = new Vtiger_Block();
$block->label = 'LBL_'. strtoupper($moduleInstance->name) . '_INFORMATION';
$moduleInstance->addBlock($block);
$blockcf = new Vtiger_Block();
$blockcf->label = 'LBL_CUSTOM_INFORMATION';
$moduleInstance->addBlock($blockcf);
$field1 = new Vtiger_Field();
$field1->name = 'summary';
$field1->label= 'Summary';
$field1->uitype= 2;
$field1->column = $field1->name;
$field1->columntype = 'VARCHAR(255)';
$field1->typeofdata = 'V~M';
$block->addField($field1);
$moduleInstance->setEntityIdentifier($field1);
$field2 = new Vtiger_Field();
$field2->name = 'expenseon';
$field2->label= 'Expense On';
$field2->uitype= 5;
$field2->column = $field2->name;
$field2->columntype = 'Date';
$field2->typeofdata = 'D~O';
$block->addField($field2);
$field3 = new Vtiger_Field();
$field3->name = 'expenseamount';
$field3->label= 'Amount';
$field3->uitype= 71;
$field3->column = $field3->name;
$field3->columntype = 'VARCHAR(255)';
$field3->typeofdata = 'V~M';
$block->addField($field3);
$field3 = new Vtiger_Field();
$field3->name = 'description';
$field3->label= 'Description';
$field3->uitype= 19;
$field3->column = 'description';
$field3->table = 'vtiger_crmentity';
$blockcf->addField($field3);
// Recommended common fields every Entity module should have (linked to core table)
$mfield1 = new Vtiger_Field();
$mfield1->name = 'assigned_user_id';
$mfield1->label = 'Assigned To';
$mfield1->table = 'vtiger_crmentity';
$mfield1->column = 'smownerid';
$mfield1->uitype = 53;
$mfield1->typeofdata = 'V~M';
$block->addField($mfield1);
$mfield2 = new Vtiger_Field();
$mfield2->name = 'CreatedTime';
$mfield2->label= 'Created Time';
$mfield2->table = 'vtiger_crmentity';
$mfield2->column = 'createdtime';
$mfield2->uitype = 70;
$mfield2->typeofdata = 'T~O';
$mfield2->displaytype= 2;
$block->addField($mfield2);
$mfield3 = new Vtiger_Field();
$mfield3->name = 'ModifiedTime';
$mfield3->label= 'Modified Time';
$mfield3->table = 'vtiger_crmentity';
$mfield3->column = 'modifiedtime';
$mfield3->uitype = 70;
$mfield3->typeofdata = 'T~O';
$mfield3->displaytype= 2;
$block->addField($mfield3);
// Filter Setup
$filter1 = new Vtiger_Filter();
$filter1->name = 'All';
$filter1->isdefault = true;
$moduleInstance->addFilter($filter1);
$filter1->addField($field1)->addField($field2, 1)->addField($field3, 2)->addField($mfield1, 3);
// Sharing Access Setup
$moduleInstance->setDefaultSharing();
// Webservice Setup
$moduleInstance->initWebservice();
mkdir('modules/'.$MODULENAME);
echo "OK\n";
}
//
language and module file path
vtiger/language/en_us/Expenses.php
vtiger/modules/Expenses/Expenses.php
both file are same.
//

Have you run the file which you have created in root directory(vtiger/Expenses.php) of CRM.
You have to run this file from browser.
http://localhost/vtiger/Expenses.php
There is no issue in your script file you have created.

Best method for creating module as below:
For Windows:
- Just open command line
- go in www/html/vtigercrm/vtlib/tools directory and run php -f console.php command.
- Now Enter your module name and refresh you crm and click on all will display your module
For Linux:
- Just open Terminal
- Go in cd var/www/html/vtigercrm/vtlib/tools directory
- Run php -f console.php command.
- It will display like
user#user:~$ cd /var/www/html/vtigercrm/vtlib/tools
user#user:/var/www/html/vtigercrm/vtlib/tools$ php -f console.php
Welcome to Vtiger CRM Creator.
This tool will enable you to get started with developing extensions with ease.
Have a good time. Press CTRL+C to "quit".
Choose the options below:
1. Create New Module.
2. Create New Layout.
3. Create New Language Pack.
4. Create Test Language Pack.
5. Import Module.
6. Update Module.
7. Remove Module.
Enter your choice:
- Enter 1
- Enter name of module
- Now refresh crm and click on all menu, you can see your module

Related

Hot to use variable in query in Drupal 8?

I have this code:
function my_module_test($key_make = '') {
$db = new mysqli('xxx', 'xxx', 'xxx', "xxx");
mysqli_set_charset($db, "UTF8");
if ($key_make) {
$sql_model = "SELECT * FROM `car_model` WHERE `id_car_make` = ('$key_make')";
$res_model = $db->query($sql_model) or die(mysqli_error($db));
while ($row = mysqli_fetch_object($res_model)) {
$Key_model = $row->id_car_model;
$Model_value = $row->name;
$dropdown_model[$Key_model] = $Model_value;
}
}
return $dropdown_model;
}
How can I pass the value of the variable $key_make in WHERE clausole ?
The query function takes a second parameter with an array of replacement values, so you would do it like this:
$sql_model = "SELECT * FROM {car_model} WHERE id_car_make = :make";
$res_model = $db->query($sql_model, [':make' => $key_make]);
Static queries are documented here
You could also use a dynamic query (documented here):
$query = $db->select('car_model', 'cm');
$query->fields('cm');
$query->condition('cm.id_car_make', $key_make);
$res_model = $query->execute();
But...
if your "car_model"s are custom entities (which they should be as you will get many benefits like views integration), you should probably use an entityQuery
First you need to use the Drupal Database API to connect to a database. So my final code is the following and it works.
function car2db_model_dropdown_options($key_make) {
$connection = Database::getConnection('default', 'migrate');
$dropdown_model = ['_none'=>'Select'];
$key_make = (int)$key_make;
$sql_model = "SELECT * FROM car_model WHERE id_car_make = :make";
$query = $connection->query($sql_model, [':make' => $key_make]);
$result = $query->fetchAll();
foreach ($result as $row) {
$Key_model = $row->id_car_model;
$Model_value = $row->name;
$dropdown_model[$Key_model] = $Model_value;
}
return $dropdown_model;
}

Test Automapper return collection or not

I am testing one of my services - movieService. GetLatestMovies method should return all movies, ordered by date. I am using automapper to map the entity Movie to MovieViewModel.
* Question 1: * How am I supposed to test that, should I set the return collection in the test or what?
* Question 2: * I am filling the InMemory database with a few movies and I am expecting correct ordered result from the movieService, how am I supposed to check, If the service is returning correct result, If I set the return from the automapper?
TestUtils.FillContextWithActorsMoviesAndGenres(options) - just fills the context with a few movies.
This is the movieService method I am testing
public async Task<ICollection<MovieViewModel>> GetLatestMoviesAsync()
{
var movies = await this.context.Movies
.Include(um => um.ApplicationUserMovie)
.ThenInclude(u => u.User)
.Include(x => x.Genre)
.Include(x => x.MovieActor)
.ThenInclude(x => x.Actor)
.OrderByDescending(x => x.CreatedOn).ToListAsync();
var returnMovies = this.mappingProvider.MapTo<ICollection<MovieViewModel>>(movies);
return returnMovies;
}
[TestMethod]
public async Task Return_TwoMoviesWithHighestRating()
{
var dabataseName = nameof(Return_TwoMoviesWithHighestRating);
var options = TestUtils.GetOptions(dabataseName);
// We fill the context with data and save it.
TestUtils.FillContextWithActorsMoviesAndGenres(options);
var movieOne = new MovieViewModel()
{
Name = "BestRatedMovieTest",
Duration = 90,
Director = "TestDirector",
Storyline = "TestStoryline",
ImageUrl = "TestImageUrl",
Genre = "Comedy"
};
var movieTwo = new MovieViewModel()
{
Name = "SecondMovieTestName",
Duration = 90,
Director = "TestDirector",
Storyline = "TestStoryline",
ImageUrl = "TestImageUrl",
Genre = "Comedy"
};
var collectionMovieViewModels = new List<MovieViewModel>() { movieOne, movieTwo };
var mappingProviderMock = new Mock<IMappingProvider>();
mappingProviderMock
.Setup(x => x.MapTo<ICollection<MovieViewModel>>(It.IsAny<List<Movie>>()))
.Returns(collectionMovieViewModels);
using (var actAndAssertContext = new MovieManagementContext(options))
{
var sut = new MovieService(actAndAssertContext, mappingProviderMock.Object);
var movies = await sut.GetLatestMoviesAsync();
Assert.AreEqual(2, movies.Count());
Assert.AreEqual("BestRatedMovieTest", movies.FirstOrDefault().Name);
}
}
I created an empty collection and set the Callback of the method to fill that collection,
var collectionOfMovies = new List<Movie>();
var mappingProviderMock = new Mock<IMappingProvider>();
mappingProviderMock
.Setup(x => x.MapTo<ICollection<MovieViewModel>>(It.IsAny<List<Movie>>()))
.Callback<object>(inputargs => collectionOfMovies = inputargs as List<Movie>);

How to remove column with ML.NET ColumnDropper

Guys I'm new in machine learning and I'm trying to use Microsoft.ML and in particular Transform part of the framework.
Can you somebody tell me what I'm doing wrong. I cannot remove a column from my dataset?
var loader = new Microsoft.ML.Data.TextLoader(TrainDataPath).CreateFrom<BloodDonateData>(useHeader: true, separator: ',');
int columnsCount = 5;
using (var environment = new TlcEnvironment())
{
Experiment experiment = environment.CreateExperiment();
ILearningPipelineDataStep pipelineDataStep = loader.ApplyStep(null,
experiment) as ILearningPipelineDataStep;
experiment.Compile();
loader.SetInput(environment, experiment);
experiment.Run();
ColumnDropper columnDropper = new ColumnDropper
{
Column = new string[] { "Time" },
Data = pipelineDataStep.Data
};
columnDropper.ApplyStep(pipelineDataStep, experiment);
var data = experiment.GetOutput(columnDropper.Data);
using (var cursor = data.GetRowCursor(a => true))
{
// print data..
}
}

How I can use predicate buider for Sitecore Lucene Search

I am working on Sitecore 8.1 and I am implementing filter functionality for one of the page by Sitecore lucene. Fot filtering I am using predicate builder. I have 3 multi-lists field on detail items
Product
Category
Services
Now on listing page I have all three group filters as checkboxes as given in below image -
My Requirement is I want to apply Or between inside the group like between products condition should be Or and between two groups condition should be And. For example products and Category should be And.
I followed http://getfishtank.ca/blog/building-dynamic-content-search-linq-queries-in-sitecore-7 blog post to implement this
To achieve this what I am trying -
var builder = PredicateBuilder.True<TestResultItem>();
var Categorybuilder = PredicateBuilder.False<TestResultItem>();
if (!string.IsNullOrEmpty(Categorys))
{
var CategoryItems = Categorys.Split('|');
foreach (var Category in CategoryItems)
{
var ct = Sitecore.ContentSearch.Utilities.IdHelper.NormalizeGuid(Categorys, true);
Categorybuilder = Categorybuilder.Or(i => i.Category.Contains(ct));
}
}
var Servicebuilder = PredicateBuilder.False<TestResultItem>();
if (!string.IsNullOrEmpty(Service))
{
var ServiceItems = Service.Split('|');
foreach (var ser in ServiceItems)
{
var si = Sitecore.ContentSearch.Utilities.IdHelper.NormalizeGuid(ser, true);
Servicebuilder = Servicebuilder.Or(i => i.Service.Contains(si));
}
}
var productsbuilder = PredicateBuilder.False<TestResultItem>();
if (!string.IsNullOrEmpty(products))
{
var productItems = products.Split('|');
foreach (var product in productItems)
{
var pd = Sitecore.ContentSearch.Utilities.IdHelper.NormalizeGuid(product, true);
productsbuilder = productsbuilder.Or(i => i.Category.Contains(pd));
}
}
Servicebuilder = Servicebuilder.Or(Categorybuilder);
productsbuilder = productsbuilder.Or(Servicebuilder);
builder = builder.And(productsbuilder);
The above given code is not working for me. I know I am doing something wrong as I am not good with Predicate builder, Or condition is not working between check boxes group.
Can anyone please tell me where I am wrong in given code or any best way to achieve this.
Any help would be appreciated
I did something similar recently and it works like this:
Create your "or" predicates:
var tagPredicate = PredicateBuilder.False<BlogItem>();
tagPredicate = tagValues.Aggregate(tagPredicate, (current, tag) => current.Or(p => p.Tags.Contains(tag)))
where tagValues is an IEnumerable containing the normalized guids.
I do this for several guid lists. In the end I wrap them together like this:
var predicate = PredicateBuilder.True<BlogItem>();
predicate = predicate.And(tagPredicate);
predicate = predicate.And(...);
Looking at your code: first of all change
Servicebuilder = Servicebuilder.Or(Categorybuilder);
productsbuilder = productsbuilder.Or(Servicebuilder);
builder = builder.And(productsbuilder);
into
builder = builder.And(Categorybuilder);
builder = builder.And(Servicebuilder);
builder = builder.And(productsbuilder);
You need to have one main predicate to join filters with AND condition & other predicates (e.g. for categories or services or products) to join filters internally with OR condition.
// This is your main predicate builder
var builder = PredicateBuilder.True<TestResultItem>();
var Categorybuilder = PredicateBuilder.False<TestResultItem>();
var Servicebuilder = PredicateBuilder.False<TestResultItem>();
var productsbuilder = PredicateBuilder.False<TestResultItem>();
builder = builder.And(Categorybuilder);
builder = builder.And(Servicebuilder);
builder = builder.And(productsbuilder);
Hope this will help you.
Thanks all for providing your inputs -
I updated the code as per your inputs and now it's working.
There was two changes in my old code one was builder for multilist should be inside the if statement and also adding newly created builder to main builder on same location (inside the if statement) -
I am sharing the code below so that if anyone want to use it he can easily copy from here -
var builder = PredicateBuilder.True<TestResultItem>();
if (!string.IsNullOrEmpty(Categorys))
{ var Categorybuilder = PredicateBuilder.False<TestResultItem>();
var CategoryItems = Categorys.Split('|');
foreach (var Category in CategoryItems)
{
var ct = Sitecore.ContentSearch.Utilities.IdHelper.NormalizeGuid(Categorys, true);
Categorybuilder = Categorybuilder.Or(i => i.Category.Contains(ct));
}
builder = builder.And(Categorybuilder);
}
if (!string.IsNullOrEmpty(Service))
{
var Servicebuilder = PredicateBuilder.False<TestResultItem>();
var ServiceItems = Service.Split('|');
foreach (var ser in ServiceItems)
{
var si = Sitecore.ContentSearch.Utilities.IdHelper.NormalizeGuid(ser, true);
Servicebuilder = Servicebuilder.Or(i => i.Service.Contains(si));
}
builder = builder.And(Servicebuilder);
}
if (!string.IsNullOrEmpty(products))
{
var productsbuilder = PredicateBuilder.False<TestResultItem>();
var productItems = products.Split('|');
foreach (var product in productItems)
{
var pd = Sitecore.ContentSearch.Utilities.IdHelper.NormalizeGuid(product, true);
productsbuilder = productsbuilder.Or(i => i.Category.Contains(pd));
}
builder = builder.And(productsbuilder);
}
In the above code Categorys, Service and products are pipe separated values which are coming from Sitecore Multi-list field.
Thanks again everyone for help!!

Using GP Web Service: How do I delete a SalesOrderLine from a SalesOrder?

Can someone help me delete a SalesOrderLine from a SalesOrder?
I'm using the GP WS Native Endpoint
My code executes without an error.
However, after updating the SalesOrder, the line I removed still remains.
var salesDocumentKeyObject = new SalesDocumentKey {Id = salesDocumentKey, CompanyKey = this.CompanyKey};
var salesOrder = this.DynamicsGpClient.GetSalesOrderByKey(salesDocumentKeyObject, this.Context);
var newLines = salesOrder.Lines.Where(l => l.Key.LineSequenceNumber != lineItemSequence).ToArray();
salesOrder.Lines = newLines;
var salesOrderUpdatePolicy = this.DynamicsGpClient.GetPolicyByOperation("UpdateSalesOrder", this.Context);
this.DynamicsGpClient.UpdateSalesOrder(salesOrder, this.Context, salesOrderUpdatePolicy);
Thank you for any help,
Karl
Microsoft Dynamics GP Web Service has poor documentation and examples.
Do delete a sales order line, you retrieve the order, locate the line to delete and set the sales order line property, DeleteOnUpdate to true, and then save the order.
Updated code below:
var salesDocumentKeyObject = new SalesDocumentKey {Id = salesDocumentKey, CompanyKey = this.CompanyKey};
var salesOrder = this.DynamicsGpClient.GetSalesOrderByKey(salesDocumentKeyObject, this.Context);
var target= salesOrder.Lines.FirstOrDefault(l => l.Key.LineSequenceNumber == lineItemSequence);
if (target != null) {
target.DeleteOnUpdate = true;
}
var salesOrderUpdatePolicy = this.DynamicsGpClient.GetPolicyByOperation("UpdateSalesOrder", this.Context);
this.DynamicsGpClient.UpdateSalesOrder(salesOrder, this.Context, salesOrderUpdatePolicy);