Author Archive

SugarCRM Code Review Points


2011
06.15
1. Don’t write sql queries inside a page, rather write as a function of a class.
2. Do not write functions in a general page, rather write as a class function.
3. Do not require or include extra pages and do not write any extra code. If you are
using copy-paste also try to remove extra codes.
4. Try not to bother built in functionalities and to use already defined functions or
css classes as much as possible.
5. No need to re-declare already declared variables as global.
6. Except some situation no need to define a variable.
7. Do not write strings (i.e, error notice) in a page, rather use language file so that if
there is a sudden requirement of multi lingual site no need to change the code.
In JavaScript file language can be added as
SUGAR.language.get(‘Reports’, ‘LBL_BLANK_MODULE’)
or
SUGAR.language.get(‘app_strings’,'LBL_LOADING_PAGE’)
8. Maintain Class and module name convention. (i.e, module name is ended with ‘s’
or plural, any other file inside the module is singular, Class name is also singular)
9. Write functions name in such a way that anyone can have a clear idea of what will
be the functionality of that function.
10. If some functionality is getting used many times in different module or pages, try
to write that in a common place as a common function or common class function
(may be in include/utils.php or module/module_name/class_name.php)
11. General convention:
a. If you want to write a function related to a module, write the function in
that module class file.
b. If you want any functionality which you need inside any module and that
functionality is related to some database operation, write the function in
‘data/SugarBean.php’.
c. If you want any functionality which you need inside any module and that
functionality is not related to any database operation, write the function in
‘include/utils.php’.

PHP Find time ago between two dates


2011
06.11

Tired of displaying time as plain old dd-mm-yyyy format? here’s the algorithm for displaying time and date not in old style manner like 05-12-2011 rather as “** minutes ago” or “** days Ago” or “** months ago” Or “** Years Ago”. So if we have the date of a particular content in database we can simply show this ‘ago time calculation’ using the following algorithm.

This getTimeAgo function takes two parameters, first is the date to calculate the time ago and the second option from which date to calculate the time ago, which defaults to current date.

The getTimeAgo function’s output can be further modified by putting in extra conditions so that time greater than a specific number of year/months says very long ago or if the content is very recently which is maybe less than 1 day’s old then returning just now or recently or any other custom text.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/***
* Function to accept dates and to output in the format
* "XYZ days/months/years ago"
* Takes two parameters first one the date to calculate and the second optional  date from,
* which defaults to current date
* use where you want to find out the time ago of a date
*
*
*/

function getTimeAgo( $dateTo, $dateFrom = 'now' ){
$outPut = '';

//////
$secs = (strtotime($dateFrom)-strtotime($dateTo));
$mints = abs((intval($secs/60)));
$hrs = abs(intval($mints/60));
$days = abs(intval($hrs/24));
$week = abs(intval($days/7));
$months = abs(intval($week/4));
$years = abs(intval($months/12));
//////
if($mints == 0){            $outPut = ("".$secs." seconds ago");
}else if($mints == 1){    $outPut =  ("1 minute");
}else if ($hrs == 0){        $outPut =  (" ".$mints." minutes ago");
}else if ($hrs == 1){        $outPut =  (" 1 hour ago");
}else if ($days == 0 && $hrs < 24){
if ($hrs == 1){        $outPut =  ("1 hour ago");
}else{                    $outPut =  ("" . $hrs ." hours ago");
}
}else if ($days == 1){        $outPut = ("Yesterday");
}else if ($days <= 7){        $outPut =  ("". $days ." days ago");
}
else if($week  == 1){
$outPut = ("about 1 week ago");
}
else if($week  < 4){
$outPut = ("". $week ." weeks ago");
}
else if ($months == 1){        $outPut =  ("1 month ago");
}else if ($months < 12){        $outPut =  ("".$months." months ago");
}else if ($years == 1){        $outPut =  ("about 1 year ago");
}else{                        $outPut =  ("".$years." years ago");
}

return $outPut;
}

Also let me know if anybody finds issues with using the function.

Organisational Goals according to March & Simon


2011
02.27

* Officials goals. These goals are the formally stated goals of an organization described in its charter and annual reports and they are emphasized in public statements by key executives.

* Operative goals are the outcomes that the� organization actually seeks to attain through its operating policies and activities.

* Operational goals Organizational goals define the performance objectives and desired behaviours within an organization.

Decision-Making in the five management functions


2010
10.30

Planning:

- What is the mission of the organization? What should it be?

- What are the needs of the customers?

- What are the organization’s strengths, weaknesses, threats, and opportunities?

- What are the strategic, tactical and operational goals?

- What strategies will achieve these goals?

Organizing:

- What organizational option will best achieve the objectives?

- What type of departmental structure will result in teamwork?

- How many employees should report to a manager?

- When should a manager delegate authority? How much?

Staffing:

- How many employees will we need this year?

- What skills are necessary to do this job?

- What type of training will best prepare the employee?

- How can we improve the quality of the performance appraisal system?

Leading:

- What can we do to have motivated employees?

- What style of leadership is the most effective with an individual?

- What strategies are available to manage conflict?

- How can we build teams?

Controlling:

- What tasks in the organization need to be controlled?

- Which control technique is the most effective for monitoring finance?

- What is the effect of controls on employee behaviour?

- How do we establish acceptable standards of performance?

Managerial Functions


2010
10.30

The functions which describe managerial job, when put together, make up the management process. This process is analyzed into key functions of management viz., planning, organizing, staffing, directing and controlling. Planning, organizing and controlling which deal mostly with non-human aspects are known as mechanics of management, whereas staffing and direction which are primarily concerned with human aspects constitute dynamics of management. In the conceptual scheme, though the functions are listed out in a sequence, I practice they are interlocked as a system. As all functions are not equally important for all managers, time spent by them for each of these functions varies according to their levels in the organization. These functions has been discussed below:
1.    Planning: Planning refers to anticipate the opportunity, problems and conditions and choosing from among the alternative future courses of action. The planning process generally includes the following activities.
1.    Forecasting is looking ahead to anticipate the opportunity, problems and conditions in a future period of time.
2.    Establishing objectives means setting the end results to be accomplished by directing organizational efforts.
3.    Programming is establishing sequence and priority of actions to be followed in the attainment of the objectives.
4.    Scheduling is deciding on time sequence for program steps.
5.    Budgeting is allocation of resources to minimize costs.
6.    Establishing procedures means developing and applying standardized methods of performing a specific work.
7.    Developing policies involve establishment and interpretation of standing decisions that apply to repetitive questions and problems of significance to be organization as a whole.
1.    Organizing function: The organizing function of management is the process of defining and grouping of activities and creating authority relationship among them. It consists of
1.    Developing the organization structure which involves identification of task and grouping them into units or departments for performance.
2.    Delegating authority to the managers and making him responsible for group performance.
3.    Establishing relations creating conditions necessary for mutually fooperative efforts of people in the organization.
2.    Staffing: Planning the organization with suitable personnel constitutes the staffing function. It involves selection, training and development, compensation, and appraisal of subordinates by the manager. Manpower planning and manpower management looks after these activities and try to ensure suitable methods of remuneration and performance appraisal of the employees.
3.    Directing Function: involves managing people and the work through the means of motivation, proper leadership, effective communication and coordination. A manager must develop ability to command. He should issue orders and instructions without arousing any resentment among the subordinates. He must be able to secure willing obedience from his subordinates without destroying their initiative and creativity. Moreover, it requires a sound communication system to enable exchange of ideas and information for common understanding.
4.    Controlling Function: enables management to ensure that achievement is in accordance with the established plans it involves:
1.    Establishing performance standards for evaluating results.
2.    Performance on the basis of records and reports on the progress of work.
3.    Performance evaluation against the standards set.
4.    Corrective action to regulate operations, remove deficiencies and improve performance