Now all modules are in core modules folder
This commit is contained in:
parent
5ba1cdfa0b
commit
05b6a91b0c
1907 changed files with 0 additions and 0 deletions
443
modules/storm/stormexpense/stormexpense.admin.inc
Normal file
443
modules/storm/stormexpense/stormexpense.admin.inc
Normal file
|
@ -0,0 +1,443 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
function stormexpense_list() {
|
||||
$breadcrumb = array();
|
||||
$breadcrumb[] = l(t('SuiteDesk'), 'dashboard');
|
||||
drupal_set_breadcrumb($breadcrumb);
|
||||
|
||||
if (array_key_exists('organization_nid', $_GET)) {
|
||||
if ($_SESSION['stormexpense_list_filter']['organization_nid'] != $_GET['organization_nid']) {
|
||||
$_SESSION['stormexpense_list_filter']['organization_nid'] = $_GET['organization_nid'];
|
||||
}
|
||||
unset($_SESSION['stormexpense_list_filter']['project_nid']);
|
||||
unset($_SESSION['stormexpense_list_filter']['task_nid']);
|
||||
unset($_SESSION['stormexpense_list_filter']['ticket_nid']);
|
||||
}
|
||||
|
||||
if (array_key_exists('project_nid', $_GET)) {
|
||||
if ($_SESSION['stormexpense_list_filter']['project_nid'] != $_GET['project_nid']) {
|
||||
$_SESSION['stormexpense_list_filter']['project_nid'] = $_GET['project_nid'];
|
||||
}
|
||||
$p = node_load($_GET['project_nid']);
|
||||
$_SESSION['stormexpense_list_filter']['organization_nid'] = $p->organization_nid;
|
||||
|
||||
unset($_SESSION['stormexpense_list_filter']['task_nid']);
|
||||
unset($_SESSION['stormexpense_list_filter']['ticket_nid']);
|
||||
}
|
||||
|
||||
if (array_key_exists('task_nid', $_GET)) {
|
||||
if ($_SESSION['stormexpense_list_filter']['task_nid'] != $_GET['task_nid']) {
|
||||
$_SESSION['stormexpense_list_filter']['task_nid'] = $_GET['task_nid'];
|
||||
}
|
||||
|
||||
$t = node_load($_GET['task_nid']);
|
||||
$_SESSION['stormexpense_list_filter']['organization_nid'] = $t->organization_nid;
|
||||
$_SESSION['stormexpense_list_filter']['project_nid'] = $t->project_nid;
|
||||
unset($_SESSION['stormexpense_list_filter']['ticket_nid']);
|
||||
}
|
||||
|
||||
if (array_key_exists('ticket_nid', $_GET)) {
|
||||
if ($_SESSION['stormexpense_list_filter']['ticket_nid'] != $_GET['ticket_nid']) {
|
||||
$_SESSION['stormexpense_list_filter']['ticket_nid'] = $_GET['ticket_nid'];
|
||||
}
|
||||
|
||||
$ti = node_load($_GET['ticket_nid']);
|
||||
$_SESSION['stormexpense_list_filter']['organization_nid'] = $ti->organization_nid;
|
||||
$_SESSION['stormexpense_list_filter']['project_nid'] = $ti->project_nid;
|
||||
$_SESSION['stormexpense_list_filter']['task_nid'] = $ti->task_nid;
|
||||
}
|
||||
|
||||
$i = new stdClass();
|
||||
$i->type = 'stormexpense';
|
||||
|
||||
$report_attrs = array(
|
||||
'onclick' => "storm_popup(this, 'expense_list_form_report', 'Expenses', 300, 150, 'stormexpense_list_form_report', 'l'); return false;",
|
||||
);
|
||||
|
||||
$header = array(
|
||||
array(
|
||||
'data' => t('Organization'),
|
||||
'field' => 'sex.organization_title',
|
||||
),
|
||||
array(
|
||||
'data' => t('Project'),
|
||||
'field' => 'sex.project_title',
|
||||
),
|
||||
array(
|
||||
'data' => t('Title'),
|
||||
'field' => 'n.title',
|
||||
),
|
||||
array(
|
||||
'data' => t('Date'),
|
||||
'field' => 'sex.expensedate',
|
||||
'sort' => 'desc',
|
||||
),
|
||||
array(
|
||||
'data' => t('Total'),
|
||||
'style' => 'text-align: right;'
|
||||
),
|
||||
array(
|
||||
'data' => storm_icon_l('report', '', t('Reports'), '', array(), $report_attrs) .' '. storm_icon_add_node($i, $_GET),
|
||||
'class' => 'storm_list_operations',
|
||||
),
|
||||
);
|
||||
|
||||
$s = "SELECT n.*, sex.*, nre.format FROM {node} AS n
|
||||
INNER JOIN {stormexpense} AS sex ON n.vid=sex.vid
|
||||
INNER JOIN {node_revisions} AS nre ON n.vid = nre.vid
|
||||
WHERE n.status=1 AND n.type='stormexpense' ";
|
||||
|
||||
$s_totals = "SELECT SUM(amount) AS t_amount, SUM(tax1) AS t_tax1, SUM(tax2) AS t_tax2, SUM(total) AS t_total FROM
|
||||
{node} AS n INNER JOIN {stormexpense} AS sex ON n.vid=sex.vid WHERE n.status=1 AND n.type='stormexpense' ";
|
||||
|
||||
$where = array();
|
||||
$args = array();
|
||||
$filterfields = array();
|
||||
|
||||
if (isset($_SESSION['stormexpense_list_filter']['organization_nid']) && $_SESSION['stormexpense_list_filter']['organization_nid'] != 0) {
|
||||
$where[] = 'sex.organization_nid=%d';
|
||||
$args[] = $_SESSION['stormexpense_list_filter']['organization_nid'];
|
||||
$filterfields[] = t('Organization');
|
||||
}
|
||||
if (isset($_SESSION['stormexpense_list_filter']['project_nid']) && $_SESSION['stormexpense_list_filter']['project_nid'] != 0) {
|
||||
$where[] = 'sex.project_nid=%d';
|
||||
$args[] = $_SESSION['stormexpense_list_filter']['project_nid'];
|
||||
$filterfields[] = t('Project');
|
||||
}
|
||||
if (isset($_SESSION['stormexpense_list_filter']['task_nid']) && $_SESSION['stormexpense_list_filter']['task_nid'] != 0) {
|
||||
$where[] = 'sex.task_nid=%d';
|
||||
$args[] = $_SESSION['stormexpense_list_filter']['task_nid'];
|
||||
$filterfields[] = t('Task');
|
||||
}
|
||||
if (isset($_SESSION['stormexpense_list_filter']['ticket_nid']) && $_SESSION['stormexpense_list_filter']['ticket_nid'] != 0) {
|
||||
$where[] = 'sex.ticket_nid=%d';
|
||||
$args[] = $_SESSION['stormexpense_list_filter']['ticket_nid'];
|
||||
$filterfields[] = t('Ticket');
|
||||
}
|
||||
if (isset($_SESSION['stormexpense_list_filter']['datefrom']) && $_SESSION['stormexpense_list_filter']['datefrom']['day'] != -1) {
|
||||
$datefrom = $_SESSION['stormexpense_list_filter']['datefrom'];
|
||||
$datefrom['hour'] = 0;
|
||||
$datefrom['minute'] = 0;
|
||||
$where[] = 'sex.expensedate>=%d';
|
||||
$args[] = _storm_datetime_to_gmtimestamp($datefrom);
|
||||
$filterfields[] = t('Date');
|
||||
}
|
||||
if (isset($_SESSION['stormexpense_list_filter']['title']) && $_SESSION['stormexpense_list_filter']['title'] != '') {
|
||||
$where[] = "LOWER(n.title) LIKE LOWER('%s')";
|
||||
$args[] = $_SESSION['stormexpense_list_filter']['title'];
|
||||
$filterfields[] = t('Title');
|
||||
}
|
||||
if (isset($_SESSION['stormexpense_list_filter']['provider_title']) && $_SESSION['stormexpense_list_filter']['provider_title'] != '') {
|
||||
$where[] = "LOWER(sex.provider_title) LIKE LOWER('%s')";
|
||||
$args[] = $_SESSION['stormexpense_list_filter']['provider_title'];
|
||||
$filterfields[] = t('Provider');
|
||||
}
|
||||
|
||||
$itemsperpage = isset($_SESSION['stormexpense_list_filter']['itemsperpage']) ? $_SESSION['stormexpense_list_filter']['itemsperpage'] : variable_get('storm_default_items_per_page', 10);
|
||||
|
||||
if (isset($_SESSION['stormexpense_list_filter']['user']) && $_SESSION['stormexpense_list_filter']['user'] != '') {
|
||||
$expenseuser = user_load(array('name' => $_SESSION['stormexpense_list_filter']['user']));
|
||||
if ($expenseuser === FALSE) $expenseuser->uid = -1;
|
||||
$where[] = 'n.uid=%d';
|
||||
$args[] = $expenseuser->uid;
|
||||
$filterfields[] = t('User');
|
||||
}
|
||||
|
||||
if (count($filterfields) == 0) {
|
||||
$filterdesc = t('Not filtered');
|
||||
}
|
||||
else {
|
||||
$filterdesc = t('Filtered by !fields', array('!fields' => implode(", ", array_unique($filterfields))));
|
||||
}
|
||||
$filterdesc .= ' | '. t('!items items per page', array('!items' => $itemsperpage));
|
||||
|
||||
$o = drupal_get_form('stormexpense_list_filter', $filterdesc);
|
||||
|
||||
$s = stormexpense_access_sql($s, $where);
|
||||
$s = db_rewrite_sql($s);
|
||||
$tablesort = tablesort_sql($header);
|
||||
$r = pager_query($s . $tablesort, $itemsperpage, 0, NULL, $args);
|
||||
|
||||
$_SESSION['stormexpense_list_filter']['sql'] = $s . $tablesort;
|
||||
$_SESSION['stormexpense_list_filter']['args'] = $args;
|
||||
|
||||
$expenses = array();
|
||||
while ($item = db_fetch_object($r)) {
|
||||
$expenses[] = $item;
|
||||
}
|
||||
|
||||
$s_totals = stormexpense_access_sql($s_totals, $where);
|
||||
$s_totals = db_rewrite_sql($s_totals);
|
||||
$r = db_query($s_totals, $args);
|
||||
$totals = db_fetch_object($r);
|
||||
|
||||
$o .= theme('stormexpense_list', $header, $expenses, $totals);
|
||||
$o .= theme('pager', NULL, $itemsperpage, 0);
|
||||
$o .= drupal_get_form('stormexpense_list_form_report');
|
||||
print theme('page', $o);
|
||||
}
|
||||
|
||||
function stormexpense_list_filter(&$form_state, $filterdesc = 'Filter') {
|
||||
$organization_nid = isset($_SESSION['stormexpense_list_filter']['organization_nid']) ? $_SESSION['stormexpense_list_filter']['organization_nid'] : 0;
|
||||
$project_nid = isset($_SESSION['stormexpense_list_filter']['project_nid']) ? $_SESSION['stormexpense_list_filter']['project_nid'] : 0;
|
||||
$task_nid = isset($_SESSION['stormexpense_list_filter']['task_nid']) ? $_SESSION['stormexpense_list_filter']['task_nid'] : 0;
|
||||
$ticket_nid = isset($_SESSION['stormexpense_list_filter']['ticket_nid']) ? $_SESSION['stormexpense_list_filter']['ticket_nid'] : 0;
|
||||
$itemsperpage = isset($_SESSION['stormexpense_list_filter']['itemsperpage']) ? $_SESSION['stormexpense_list_filter']['itemsperpage'] : variable_get('storm_default_items_per_page', 10);
|
||||
$_SESSION['stormexpense_list_filter']['itemsperpage'] = $itemsperpage;
|
||||
$title = isset($_SESSION['stormexpense_list_filter']['title']) ? $_SESSION['stormexpense_list_filter']['title'] : '';
|
||||
$provider_title = isset($_SESSION['stormexpense_list_filter']['provider_title']) ? $_SESSION['stormexpense_list_filter']['provider_title'] : '';
|
||||
|
||||
$datefrom = isset($_SESSION['stormexpense_list_filter']['datefrom']) ? $_SESSION['stormexpense_list_filter']['datefrom'] : NULL;
|
||||
|
||||
$expenseuser = isset($_SESSION['stormexpense_list_filter']['user']) ? $_SESSION['stormexpense_list_filter']['user'] : '';
|
||||
|
||||
$form = array();
|
||||
|
||||
$form['filter'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => $filterdesc,
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#theme' => 'stormexpense_list_filter',
|
||||
);
|
||||
|
||||
$form['filter']['group1'] = array(
|
||||
'#type' => 'markup',
|
||||
'#theme' => 'storm_form_group',
|
||||
'#weight' => -20,
|
||||
);
|
||||
|
||||
$s = "SELECT n.nid, n.title FROM {node} AS n INNER JOIN {stormorganization} AS sor ON
|
||||
sor.vid=n.vid WHERE n.status=1 AND n.type='stormorganization' ORDER BY n.title";
|
||||
$s = stormorganization_access_sql($s);
|
||||
$s = db_rewrite_sql($s);
|
||||
$r = db_query($s);
|
||||
$organizations = array();
|
||||
while ($organization = db_fetch_object($r)) {
|
||||
$organizations[$organization->nid] = $organization->title;
|
||||
}
|
||||
$organizations = array(0 => t('All')) + $organizations;
|
||||
$form['filter']['group1']['organization_nid'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Organization'),
|
||||
'#default_value' => $organization_nid,
|
||||
'#options' => $organizations,
|
||||
'#attributes' => array('onchange' => "stormticket_organization_project_task_tickets(this, 'edit-project-nid', 'edit-task-nid', 'edit-ticket-nid', true, '" . t('All') . "')"),
|
||||
);
|
||||
|
||||
$s = "SELECT n.nid, n.title FROM {node} AS n INNER JOIN {stormproject} AS spr ON spr.vid=n.vid
|
||||
WHERE n.status=1 AND spr.organization_nid=%d AND n.type='stormproject' ORDER BY n.title";
|
||||
$s = stormproject_access_sql($s);
|
||||
$s = db_rewrite_sql($s);
|
||||
$r = db_query($s, $organization_nid);
|
||||
$projects = array();
|
||||
while ($project = db_fetch_object($r)) {
|
||||
$projects[$project->nid] = $project->title;
|
||||
}
|
||||
$projects = array(0 => t('All')) + $projects;
|
||||
$form['filter']['group1']['project_nid'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Project'),
|
||||
'#default_value' => $project_nid,
|
||||
'#options' => $projects,
|
||||
'#process' => array('storm_dependent_select_process'),
|
||||
'#attributes' => array('onchange' => "stormticket_project_task_tickets(this, 'edit-organization-nid', 'edit-task-nid', 'edit-ticket-nid', true, '" . t('All') . "')"),
|
||||
);
|
||||
|
||||
$tree = _stormtask_get_tree($project_nid);
|
||||
$tasks = _stormtask_plain_tree($tree);
|
||||
$tasks = array(0 => t('All')) + $tasks;
|
||||
$form['filter']['group1']['task_nid'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Task'),
|
||||
'#default_value' => $task_nid,
|
||||
'#options' => $tasks,
|
||||
'#process' => array('storm_dependent_select_process'),
|
||||
'#attributes' => array('onchange' => "stormticket_task_tickets(this, 'edit-organization-nid', 'edit-project-nid', 'edit-ticket-nid', true, '" . t('All') . "')"),
|
||||
);
|
||||
|
||||
$s = "SELECT n.nid, n.title FROM {node} AS n INNER JOIN {stormticket} AS sti ON sti.vid=n.vid
|
||||
WHERE n.status=1 AND n.type='stormticket' AND sti.organization_nid=%d AND sti.project_nid=%d AND sti.task_nid=%d ORDER BY title ";
|
||||
$s = stormticket_access_sql($s);
|
||||
$s = db_rewrite_sql($s);
|
||||
$r = db_query($s, $organization_nid, $project_nid, $task_nid);
|
||||
$tickets = array();
|
||||
while ($ticket = db_fetch_object($r)) {
|
||||
$tickets[$ticket->nid] = $ticket->title;
|
||||
}
|
||||
$tickets = array(0 => t('All')) + $tickets;
|
||||
$form['filter']['group1']['ticket_nid'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Ticket'),
|
||||
'#default_value' => $ticket_nid,
|
||||
'#process' => array('storm_dependent_select_process'),
|
||||
'#options' => $tickets,
|
||||
);
|
||||
|
||||
$form['filter']['group2'] = array(
|
||||
'#type' => 'markup',
|
||||
'#theme' => 'storm_form_group',
|
||||
'#weight' => -19,
|
||||
);
|
||||
|
||||
$form['filter']['group2']['datefrom'] = array(
|
||||
'#type' => 'dateext',
|
||||
'#title' => t('Date from'),
|
||||
'#withnull' => TRUE,
|
||||
'#default_value' => $datefrom,
|
||||
);
|
||||
|
||||
$form['filter']['group2']['user'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('User'),
|
||||
'#size' => 25,
|
||||
'#default_value' => $expenseuser,
|
||||
'#autocomplete_path' => 'user/autocomplete',
|
||||
);
|
||||
|
||||
$form['filter']['group3'] = array(
|
||||
'#type' => 'markup',
|
||||
'#theme' => 'storm_form_group',
|
||||
);
|
||||
|
||||
$form['filter']['group3']['title'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Title'),
|
||||
'#size' => 40,
|
||||
'#default_value' => $title,
|
||||
);
|
||||
|
||||
$form['filter']['group3']['provider_title'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Provider'),
|
||||
'#size' => 40,
|
||||
'#default_value' => $provider_title,
|
||||
'#autocomplete_path' => 'storm/expenses/provider_autocomplete',
|
||||
);
|
||||
|
||||
$form['filter']['group4'] = array(
|
||||
'#type' => 'markup',
|
||||
'#theme' => 'storm_form_group',
|
||||
'#attributes' => array('class' => 'formgroup-submit'),
|
||||
);
|
||||
|
||||
$form['filter']['group4']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Filter'),
|
||||
'#submit' => array('stormexpense_list_filter_filter'),
|
||||
);
|
||||
|
||||
$form['filter']['group4']['reset'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Reset'),
|
||||
'#submit' => array('stormexpense_list_filter_reset'),
|
||||
);
|
||||
|
||||
$form['filter']['group4']['itemsperpage'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Items'),
|
||||
'#size' => 10,
|
||||
'#default_value' => $itemsperpage,
|
||||
'#prefix' => '<div class="container-inline">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
function stormexpense_list_filter_filter($form, &$form_state) {
|
||||
$_SESSION['stormexpense_list_filter']['organization_nid'] = $form_state['values']['organization_nid'];
|
||||
$_SESSION['stormexpense_list_filter']['project_nid'] = $form_state['values']['project_nid'];
|
||||
$_SESSION['stormexpense_list_filter']['task_nid'] = $form_state['values']['task_nid'];
|
||||
$_SESSION['stormexpense_list_filter']['ticket_nid'] = $form_state['values']['ticket_nid'];
|
||||
$_SESSION['stormexpense_list_filter']['datefrom'] = $form_state['values']['datefrom'];
|
||||
$_SESSION['stormexpense_list_filter']['itemsperpage'] = $form_state['values']['itemsperpage'];
|
||||
$_SESSION['stormexpense_list_filter']['user'] = $form_state['values']['user'];
|
||||
$_SESSION['stormexpense_list_filter']['title'] = $form_state['values']['title'];
|
||||
$_SESSION['stormexpense_list_filter']['provider_title'] = $form_state['values']['provider_title'];
|
||||
}
|
||||
|
||||
function stormexpense_list_filter_reset($form, &$form_state) {
|
||||
unset($_SESSION['stormexpense_list_filter']);
|
||||
}
|
||||
|
||||
function stormexpense_list_form_report() {
|
||||
$form = array();
|
||||
$form['#prefix'] = '<div id="stormexpense_list_form_report" class="storm_list_form_report">';
|
||||
$form['report'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Reports'),
|
||||
'#options' => theme('stormexpense_list_form_report_reports'),
|
||||
);
|
||||
|
||||
if (module_exists('locale')) {
|
||||
$language_list = language_list();
|
||||
$languages = array();
|
||||
foreach ($language_list as $key => $lang) {
|
||||
$languages[$key] = $lang->name;
|
||||
}
|
||||
$form['language'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Language'),
|
||||
'#options' => $languages,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form['language'] = array(
|
||||
'#type' => 'hidden',
|
||||
'#default_value' => 'en',
|
||||
);
|
||||
}
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Report'),
|
||||
);
|
||||
$form['#suffix'] = '</div>';
|
||||
return $form;
|
||||
}
|
||||
|
||||
function stormexpense_list_form_report_submit($form, &$form_state) {
|
||||
$report = $form_state['values']['report'];
|
||||
$language = $form_state['values']['language'];
|
||||
drupal_goto('expenses/report/'. $report .'/'. $language);
|
||||
}
|
||||
|
||||
function stormexpense_list_report($report, $language) {
|
||||
$timetrackings = array();
|
||||
|
||||
$s = "SELECT n.*, sex.* FROM {node} AS n INNER JOIN {stormexpense} AS sex ON n.vid=sex.vid WHERE n.status=1 AND n.type='stormexpense' ";
|
||||
$s = stormexpense_access_sql($s, array());
|
||||
$s = db_rewrite_sql($s);
|
||||
|
||||
$sql = isset($_SESSION['stormexpense_list_filter']['sql']) ? $_SESSION['stormexpense_list_filter']['sql'] : $s;
|
||||
$args = isset($_SESSION['stormexpense_list_filter']['args']) ? $_SESSION['stormexpense_list_filter']['args'] : array();
|
||||
$r = db_query($sql, $args);
|
||||
$expenses = array();
|
||||
while ($e = db_fetch_object($r)) {
|
||||
$expense = node_load($e->nid);
|
||||
$expenses[] = $expense;
|
||||
}
|
||||
|
||||
print theme('stormexpense_list_report', $report, $language, $expenses);
|
||||
}
|
||||
|
||||
function stormexpense_autocomplete($string = '') {
|
||||
// Autocomplete for providers textbox: shows any active organizations in SuiteDesk system which have been selected as providers.
|
||||
$matches = array();
|
||||
if ($string) {
|
||||
$s = "SELECT n.title FROM {node} AS n INNER JOIN {stormorganization} AS sor ON n.vid=sor.vid WHERE n.status=1 AND n.type='stormorganization' AND sor.isprovider=1 AND sor.isactive=1";
|
||||
$where = array("LOWER(title) LIKE LOWER('%s%%')");
|
||||
$s = stormorganization_access_sql($s, $where);
|
||||
$s = db_rewrite_sql($s);
|
||||
$result = db_query_range($s, $string, 0, 10);
|
||||
while ($pro = db_fetch_object($result)) {
|
||||
$matches[$pro->title] = check_plain($pro->title);
|
||||
}
|
||||
}
|
||||
|
||||
drupal_json($matches);
|
||||
}
|
15
modules/storm/stormexpense/stormexpense.info
Normal file
15
modules/storm/stormexpense/stormexpense.info
Normal file
|
@ -0,0 +1,15 @@
|
|||
name = Storm Expense
|
||||
description = "Allows recording of expenses based on organizations, projects, tasks and tickets."
|
||||
dependencies[] = storm
|
||||
dependencies[] = stormorganization
|
||||
dependencies[] = stormproject
|
||||
dependencies[] = stormtask
|
||||
dependencies[] = stormticket
|
||||
package = Storm
|
||||
core = 6.x
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-08-05
|
||||
version = "6.x-2.2"
|
||||
core = "6.x"
|
||||
project = "storm"
|
||||
datestamp = "1375697500"
|
164
modules/storm/stormexpense/stormexpense.install
Normal file
164
modules/storm/stormexpense/stormexpense.install
Normal file
|
@ -0,0 +1,164 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
function stormexpense_install() {
|
||||
drupal_install_schema('stormexpense');
|
||||
variable_set('node_options_stormexpense', array('status'));
|
||||
|
||||
$attributes = array();
|
||||
|
||||
$attributes['Expense status'] = array(
|
||||
'outstanding' => 'Outstanding',
|
||||
'paid' => 'Paid',
|
||||
);
|
||||
|
||||
$attributes['Expense status search'] = array(
|
||||
'outstanding' => 'Outstanding',
|
||||
'paid' => 'Paid',
|
||||
);
|
||||
|
||||
$s = "INSERT INTO {stormattribute} (domain, akey, avalue, weight) VALUES ('%s', '%s', '%s', %d)";
|
||||
$prevdomain = '';
|
||||
$weight = 0;
|
||||
foreach ($attributes as $domain => $attribute) {
|
||||
if ($domain != $prevdomain) $weight=0;
|
||||
foreach ($attribute as $key => $value) {
|
||||
db_query($s, $domain, $key, $value, $weight);
|
||||
$weight++;
|
||||
}
|
||||
$prevdomain = $domain;
|
||||
}
|
||||
}
|
||||
|
||||
function stormexpense_disable() {
|
||||
drupal_set_message(t('Nodes of type "Expense" have not been deleted on disabling SuiteDesk Expense. Please note that they will now have reduced functionality, and will not be protected by SuiteDesk Expense access controls.'), 'warning');
|
||||
}
|
||||
|
||||
function stormexpense_uninstall() {
|
||||
drupal_uninstall_schema('stormexpense');
|
||||
|
||||
db_query($s = "DELETE FROM {stormattribute} WHERE domain IN ('Expense status', 'Expense status search')");
|
||||
}
|
||||
|
||||
function stormexpense_schema() {
|
||||
$schema['stormexpense'] = array(
|
||||
'fields' => array(
|
||||
'vid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
|
||||
'nid' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
|
||||
'organization_nid' => array('type' => 'int'),
|
||||
'organization_title' => array('type' => 'varchar', 'length' => 128),
|
||||
'project_nid' => array('type' => 'int'),
|
||||
'project_title' => array('type' => 'varchar', 'length' => 128),
|
||||
'task_nid' => array('type' => 'int'),
|
||||
'task_stepno' => array('type' => 'varchar', 'length' => 128),
|
||||
'task_title' => array('type' => 'varchar', 'length' => 128),
|
||||
'ticket_nid' => array('type' => 'int'),
|
||||
'ticket_title' => array('type' => 'varchar', 'length' => 128),
|
||||
'provider_nid' => array('type' => 'int'),
|
||||
'provider_title' => array('type' => 'varchar', 'length' => 128),
|
||||
'expensedate' => array('type' => 'int'),
|
||||
'expensestatus' => array('type' => 'varchar', 'length' => 128),
|
||||
'amount' => array('type' => 'float'),
|
||||
'tax1app' => array('type' => 'int'),
|
||||
'tax1percent' => array('type' => 'float'),
|
||||
'tax1' => array('type' => 'float'),
|
||||
'subtotal' => array('type' => 'float'),
|
||||
'tax2app' => array('type' => 'int'),
|
||||
'tax2percent' => array('type' => 'float'),
|
||||
'tax2' => array('type' => 'float'),
|
||||
'total' => array('type' => 'float'),
|
||||
),
|
||||
'primary key' => array('vid'),
|
||||
'indexes' => array(
|
||||
'nid' => array('nid'),
|
||||
'organization_nid' => array('organization_nid'),
|
||||
'project_nid' => array('project_nid'),
|
||||
'task_nid' => array('task_nid'),
|
||||
'ticket_nid' => array('ticket_nid'),
|
||||
'provider_nid' => array('provider_nid'),
|
||||
),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
function stormexpense_update_1() {
|
||||
$ret = array();
|
||||
db_change_field($ret, 'stormexpense', 'vat', 'tax', array('type' => 'float'));
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function stormexpense_update_6101() {
|
||||
$ret = array();
|
||||
db_add_field($ret, 'stormexpense', 'expensestatus', array('type' => 'varchar', 'length' => 128));
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function stormexpense_update_6102() {
|
||||
$ret = array();
|
||||
db_change_field($ret, 'stormexpense', 'tax', 'tax1', array('type' => 'float'));
|
||||
db_add_field($ret, 'stormexpense', 'tax1app', array('type' => 'int'));
|
||||
db_add_field($ret, 'stormexpense', 'tax1percent', array('type' => 'float'));
|
||||
db_add_field($ret, 'stormexpense', 'tax2app', array('type' => 'int'));
|
||||
db_add_field($ret, 'stormexpense', 'tax2percent', array('type' => 'float'));
|
||||
db_add_field($ret, 'stormexpense', 'tax2', array('type' => 'float'));
|
||||
db_add_field($ret, 'stormexpense', 'subtotal', array('type' => 'float'));
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Improve primary keys and indexes
|
||||
*/
|
||||
function stormexpense_update_6201() {
|
||||
$return = array();
|
||||
db_drop_primary_key($return, 'stormexpense');
|
||||
db_add_primary_key($return, 'stormexpense', array('vid'));
|
||||
$indexes = array(
|
||||
'nid' => array('nid'),
|
||||
'organization_nid' => array('organization_nid'),
|
||||
'project_nid' => array('project_nid'),
|
||||
'task_nid' => array('task_nid'),
|
||||
'ticket_nid' => array('ticket_nid'),
|
||||
'provider_nid' => array('provider_nid'),
|
||||
);
|
||||
foreach ($indexes as $name => $fields) {
|
||||
db_add_index($return, 'stormexpense', $name, $fields);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move SuiteDesk Attribute module into component modules
|
||||
*/
|
||||
function stormexpense_update_6202() {
|
||||
// Only run this update if was not previously run as part of the legacy stormattribute module
|
||||
if (db_result(db_query("SELECT schema_version FROM {system} WHERE name = 'stormattribute'")) < 6108) {
|
||||
$attributes['Expense status'] = array(
|
||||
'outstanding' => 'Outstanding',
|
||||
'paid' => 'Paid',
|
||||
);
|
||||
|
||||
$attributes['Expense status search'] = array(
|
||||
'outstanding' => 'Outstanding',
|
||||
'paid' => 'Paid',
|
||||
);
|
||||
|
||||
$s = "INSERT INTO {stormattribute} (domain, akey, avalue, weight, isactive) VALUES ('%s', '%s', '%s', %d, 1)";
|
||||
$prevdomain = '';
|
||||
$weight = 0;
|
||||
foreach ($attributes as $domain => $attribute) {
|
||||
if ($domain != $prevdomain) $weight=0;
|
||||
foreach ($attribute as $key => $value) {
|
||||
db_query($s, $domain, $key, $value, $weight);
|
||||
$weight++;
|
||||
}
|
||||
$prevdomain = $domain;
|
||||
}
|
||||
}
|
||||
|
||||
$ret = array();
|
||||
return $ret;
|
||||
}
|
773
modules/storm/stormexpense/stormexpense.module
Normal file
773
modules/storm/stormexpense/stormexpense.module
Normal file
|
@ -0,0 +1,773 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
function stormexpense_help($path, $arg) {
|
||||
$o = '';
|
||||
|
||||
switch ($path) {
|
||||
case "admin/help#stormexpense":
|
||||
$o = '<p>'. t("Provides expense support for SuiteDesk") .'</p>';
|
||||
break;
|
||||
}
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
function stormexpense_perm() {
|
||||
return array(
|
||||
'Storm expense: access',
|
||||
'Storm expense: add',
|
||||
'Storm expense: delete all',
|
||||
'Storm expense: delete own',
|
||||
'Storm expense: delete of user organization',
|
||||
'Storm expense: edit all',
|
||||
'Storm expense: edit own',
|
||||
'Storm expense: edit of user organization',
|
||||
'Storm expense: view all',
|
||||
'Storm expense: view own',
|
||||
'Storm expense: view of user organization',
|
||||
'Storm expense: view if assigned to project',
|
||||
);
|
||||
}
|
||||
|
||||
function stormexpense_access($op, $node, $account = NULL) {
|
||||
if (empty($account)) {
|
||||
global $user;
|
||||
$account = $user;
|
||||
}
|
||||
|
||||
if ($op == 'create') {
|
||||
return user_access('Storm expense: add');
|
||||
}
|
||||
|
||||
if (is_numeric($node)) {
|
||||
$node = node_load($node);
|
||||
}
|
||||
|
||||
if (!isset($account->stormorganization_nid) && module_exists('stormperson')) {
|
||||
_stormperson_user_load($account);
|
||||
}
|
||||
|
||||
if ($op == 'delete') {
|
||||
if (user_access('Storm expense: delete all')) {
|
||||
return TRUE;
|
||||
}
|
||||
elseif (user_access('Storm expense: delete own') && ($account->uid == $node->uid)) {
|
||||
return TRUE;
|
||||
}
|
||||
elseif (user_access('Storm expense: delete of user organization') && ($account->stormorganization_nid == $node->organization_nid)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if ($op == 'update') {
|
||||
if (user_access('Storm expense: edit all')) {
|
||||
return TRUE;
|
||||
}
|
||||
elseif (user_access('Storm expense: edit own') && ($account->uid == $node->uid)) {
|
||||
return TRUE;
|
||||
}
|
||||
elseif (user_access('Storm expense: edit of user organization') && ($account->stormorganization_nid == $node->organization_nid)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if ($op == 'view') {
|
||||
if (user_access('Storm expense: view all')) {
|
||||
return TRUE;
|
||||
}
|
||||
elseif (user_access('Storm expense: view own') && ($account->uid == $node->uid)) {
|
||||
return TRUE;
|
||||
}
|
||||
elseif (user_access('Storm expense: view of user organization') && ($account->stormorganization_nid == $node->organization_nid)) {
|
||||
return TRUE;
|
||||
}
|
||||
elseif (user_access('Storm expense: view if assigned to project') && module_exists('stormteam')) {
|
||||
$project = node_load($node->project_nid);
|
||||
if (stormteam_user_belongs_to_team($project->assigned_nid, $account->stormperson_nid)) {
|
||||
return TRUE;
|
||||
}
|
||||
elseif (stormteam_user_belongs_to_team($project->assigned_nid, $account->stormorganization_nid)) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function stormexpense_access_sql($sql, $where = array()) {
|
||||
if (!user_access('Storm expense: view all')) {
|
||||
global $user;
|
||||
|
||||
$cond = '';
|
||||
$join = array();
|
||||
if (user_access('Storm expense: view own')) {
|
||||
$cond .= 'n.uid = ' . $user->uid;
|
||||
}
|
||||
if (user_access('Storm expense: view of user organization')) {
|
||||
$cond .= !empty($cond) ? ' OR ' : '';
|
||||
$cond .= 'sex.organization_nid = ' . $user->stormorganization_nid;
|
||||
}
|
||||
if (user_access('Storm expense: view if assigned to project')) {
|
||||
$join[] = 'LEFT JOIN {node} npr ON npr.nid = sex.project_nid';
|
||||
$join[] = 'LEFT JOIN {stormproject} spr ON spr.vid = npr.vid';
|
||||
|
||||
$cond .= !empty($cond) ? ' OR ' : '';
|
||||
$cond .= 'spr.assigned_nid = ' . $user->stormperson_nid;
|
||||
|
||||
if (module_exists('stormteam')) {
|
||||
// Load teams that the account belongs to:
|
||||
$belonged_teams = stormteam_user_return_teams();
|
||||
// Allow access if any of those teams is the one in question:
|
||||
foreach ($belonged_teams as $belonged_team) {
|
||||
$cond .= ' OR spr.assigned_nid = ' . $belonged_team;
|
||||
}
|
||||
}
|
||||
}
|
||||
$where[] = empty($cond) ? '0 = 1' : $cond;
|
||||
}
|
||||
|
||||
$where[] = "'storm_access' = 'storm_access'";
|
||||
return storm_rewrite_sql($sql, $where, $join);
|
||||
}
|
||||
|
||||
function stormexpense_storm_rewrite_where_sql($query, $primary_table, $account) {
|
||||
static $conds = array();
|
||||
|
||||
if (isset($conds[$primary_table][$account->uid])) {
|
||||
return $conds[$primary_table][$account->uid];
|
||||
}
|
||||
|
||||
$cond = '';
|
||||
if (!preg_match("/'storm_access' = 'storm_access'/", $query)) {
|
||||
if (user_access('Storm expense: view all', $account)) {
|
||||
return '';
|
||||
}
|
||||
$from = '{stormexpense} sex1';
|
||||
if (user_access('Storm expense: view own', $account)) {
|
||||
$cond .= "${primary_table}.uid = " . $account->uid;
|
||||
}
|
||||
if (user_access('Storm expense: view of user organization', $account)) {
|
||||
$cond .= !empty($cond) ? ' OR ' : '';
|
||||
# If function is called without viewing an organization, this variable
|
||||
# may not be set. These lines check for that and set the organization
|
||||
# node id to zero if not otherwise set.
|
||||
if (!isset($account->stormorganization_nid)) {
|
||||
$account->stormorganization_nid = 0;
|
||||
}
|
||||
$cond .= ' sex1.organization_nid = ' . $account->stormorganization_nid;
|
||||
}
|
||||
if (user_access('Storm expense: view if assigned to project')) {
|
||||
$from .= ' LEFT JOIN {node} npr1 ON npr1.nid = sex1.project_nid LEFT JOIN {stormproject} spr1 ON spr1.vid = npr1.vid';
|
||||
$cond .= !empty($cond) ? ' OR ' : '';
|
||||
$cond .= 'spr1.assigned_nid = ' . $account->stormperson_nid;
|
||||
|
||||
if (module_exists('stormteam')) {
|
||||
// Load teams that the account belongs to:
|
||||
$belonged_teams = stormteam_user_return_teams($account);
|
||||
// Allow access if any of those teams is the one in question:
|
||||
foreach ($belonged_teams as $belonged_team) {
|
||||
$cond .= ' OR spr1.assigned_nid = ' . $belonged_team;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($cond) {
|
||||
$cond = " WHEN 'stormexpense' THEN (SELECT IF($cond, 1, 0) FROM ${from} WHERE sex1.vid = ${primary_table}.vid) ";
|
||||
}
|
||||
else {
|
||||
$cond = " WHEN 'stormexpense' THEN 0 ";
|
||||
}
|
||||
}
|
||||
$conds[$primary_table][$account->uid] = $cond;
|
||||
return $cond;
|
||||
}
|
||||
|
||||
function stormexpense_menu() {
|
||||
$items = array();
|
||||
|
||||
$items['expenses'] = array(
|
||||
'title' => 'Expenses',
|
||||
'description' => 'SuiteDesk expenses',
|
||||
'page callback' => 'stormexpense_list',
|
||||
'access arguments' => array('Storm expense: access'),
|
||||
'type' => MENU_NORMAL_ITEM,
|
||||
'file' => 'stormexpense.admin.inc',
|
||||
'weight' => 9,
|
||||
);
|
||||
|
||||
$items['expenses/report/%/%'] = array(
|
||||
'title' => 'Expenses',
|
||||
'description' => 'SuiteDesk expenses',
|
||||
'page arguments' => array(3, 4),
|
||||
'page callback' => 'stormexpense_list_report',
|
||||
'access arguments' => array('Storm expense: access'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'stormexpense.admin.inc',
|
||||
);
|
||||
|
||||
$items['storm/expenses/provider_autocomplete'] = array(
|
||||
'title' => 'Provider autocomplete',
|
||||
'page callback' => 'stormexpense_autocomplete',
|
||||
'access arguments' => array('Storm expense: access'),
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'stormexpense.admin.inc',
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
function stormexpense_theme() {
|
||||
return array(
|
||||
'stormexpense_list' => array(
|
||||
'file' => 'stormexpense.theme.inc',
|
||||
'arguments' => array('header', 'tasks', 'duration'),
|
||||
),
|
||||
'stormexpense_view' => array(
|
||||
'file' => 'stormexpense.theme.inc',
|
||||
'arguments' => array('node', 'teaser', 'page'),
|
||||
),
|
||||
'stormexpense_list_form_report_reports' => array(
|
||||
'file' => 'stormexpense.theme.inc',
|
||||
),
|
||||
'stormexpense_list_report' => array(
|
||||
'file' => 'stormexpense.theme.inc',
|
||||
'arguments' => array('report', 'language', 'timetrackings'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function stormexpense_node_info() {
|
||||
return array(
|
||||
'stormexpense' => array(
|
||||
'name' => t('Expense'),
|
||||
'module' => 'stormexpense',
|
||||
'description' => t("An expense for SuiteDesk."),
|
||||
'title_label' => t("Title"),
|
||||
'body_label' => t("Description"),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function stormexpense_content_extra_fields($type_name) {
|
||||
if ($type_name == 'stormexpense') {
|
||||
return array(
|
||||
'group1' => array('label' => 'Organization/Project/Task/Ticket Group', 'weight' => -20),
|
||||
'group2' => array('label' => 'Date/Provider Group', 'weight' => -19),
|
||||
'group3' => array('label' => 'Amount', 'weight' => -18),
|
||||
'group4' => array('label' => 'Tax Group', 'weight' => -17),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function stormexpense_stormorganization_change($organization_nid, $organization_title) {
|
||||
$s = "UPDATE {stormexpense} SET organization_title='%s' WHERE organization_nid=%d AND organization_title <> '%s'";
|
||||
db_query($s, $organization_title, $organization_nid, $organization_title);
|
||||
}
|
||||
|
||||
function stormexpense_stormproject_change($project_nid, $project_title) {
|
||||
$s = "UPDATE {stormexpense} SET project_title='%s' WHERE project_nid=%d AND project_title <> '%s'";
|
||||
db_query($s, $project_title, $project_nid, $project_title);
|
||||
}
|
||||
|
||||
function stormexpense_stormtask_change($task_nid, $task_title, $task_stepno) {
|
||||
$s = "UPDATE {stormexpense} SET task_title='%s', task_stepno='%s' WHERE task_nid=%d AND
|
||||
(task_title<>'%s' OR task_stepno<>'%s')";
|
||||
db_query($s, $task_title, $task_stepno, $task_nid, $task_title, $task_stepno);
|
||||
}
|
||||
|
||||
function stormexpense_stormticket_change($ticket_nid, $ticket_title) {
|
||||
$s = "UPDATE {stormexpense} SET ticket_title='%s' WHERE ticket_nid=%d AND ticket_title <> '%s'";
|
||||
db_query($s, $ticket_title, $ticket_nid, $ticket_title);
|
||||
}
|
||||
|
||||
function stormexpense_stormproject_change_hierarchy($project_nid, $organization_nid, $organization_title) {
|
||||
$s = "UPDATE {stormexpense} SET organization_nid=%d, organization_title='%s' WHERE project_nid=%d";
|
||||
db_query($s, $organization_nid, $organization_title, $project_nid);
|
||||
}
|
||||
|
||||
function stormexpense_stormtask_change_hierarchy($task_nid, $organization_nid, $organization_title, $project_nid, $project_title) {
|
||||
$s = "UPDATE {stormexpense} SET organization_nid=%d, organization_title='%s', project_nid=%d, project_title='%s' WHERE task_nid=%d";
|
||||
db_query($s, $organization_nid, $organization_title, $project_nid, $project_title, $task_nid);
|
||||
}
|
||||
|
||||
function stormexpense_stormticket_change_hierarchy($ticket_nid, $organization_nid, $organization_title, $project_nid, $project_title, $task_nid, $task_title) {
|
||||
$s = "UPDATE {stormexpense} SET organization_nid=%d, organization_title='%s', project_nid=%d, project_title='%s', task_nid=%d, task_title='%s' WHERE ticket_nid=%d";
|
||||
db_query($s, $organization_nid, $organization_title, $project_nid, $project_title, $task_nid, $task_title, $ticket_nid);
|
||||
}
|
||||
|
||||
function stormexpense_form(&$node) {
|
||||
$breadcrumb = array();
|
||||
$breadcrumb[] = l(t('SuiteDesk'), 'dashboard');
|
||||
$breadcrumb[] = l(t('Expenses'), 'expenses');
|
||||
drupal_set_breadcrumb($breadcrumb);
|
||||
|
||||
if (arg(1)=='add') {
|
||||
if (array_key_exists('organization_nid', $_GET) && !$node->organization_nid) {
|
||||
$node->organization_nid = $_GET['organization_nid'];
|
||||
}
|
||||
if (array_key_exists('project_nid', $_GET) && !$node->project_nid) {
|
||||
$node->project_nid = $_GET['project_nid'];
|
||||
$p = node_load($node->project_nid);
|
||||
$node->organization_nid = $p->organization_nid;
|
||||
if (!stormorganization_access('view', $node->organization_nid)) {
|
||||
drupal_set_message(t("You cannot add an expense for this project, as you do not have access to view the organization's profile"));
|
||||
drupal_goto('node/'. $node->project_nid);
|
||||
}
|
||||
}
|
||||
if (array_key_exists('task_nid', $_GET) && !$node->task_nid) {
|
||||
$node->task_nid = $_GET['task_nid'];
|
||||
$t = node_load($node->task_nid);
|
||||
$node->organization_nid = $t->organization_nid;
|
||||
$node->project_nid = $t->project_nid;
|
||||
// $project_access deals with the case whereby the project could be blank, hence access rules not required
|
||||
$project_access = $node->project_nid ? stormproject_access('view', $node->project_nid) : TRUE;
|
||||
if (!stormorganization_access('view', $node->organization_nid) || !$project_access) {
|
||||
drupal_set_message(t("You cannot add an expense for this task, as you do not have access to view the both the organization and project's profile"));
|
||||
drupal_goto('node/'. $node->task_nid);
|
||||
}
|
||||
}
|
||||
if (array_key_exists('ticket_nid', $_GET) && !$node->ticket_nid) {
|
||||
$node->ticket_nid = $_GET['ticket_nid'];
|
||||
$t = node_load($node->ticket_nid);
|
||||
$node->organization_nid = $t->organization_nid;
|
||||
$node->project_nid = $t->project_nid;
|
||||
$node->task_nid = $t->task_nid;
|
||||
// $project_access deals with the case whereby the project could be blank, hence access rules not required
|
||||
$project_access = $node->project_nid ? stormproject_access('view', $node->project_nid) : TRUE;
|
||||
$task_access = $node->task_nid ? stormtask_access('view', $node->task_nid) : TRUE;
|
||||
if (!stormorganization_access('view', $node->organization_nid) || !project_access || !task_access) {
|
||||
drupal_set_message(t("You cannot add an expense for this ticket, as you do not have access to view all of the organization, project and task's profile"));
|
||||
drupal_goto('node/'. $node->ticket_nid);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_SESSION['stormexpense_list_filter']['organization_nid']) && !$node->organization_nid) {
|
||||
$node->organization_nid = $_SESSION['stormexpense_list_filter']['organization_nid'];
|
||||
}
|
||||
if (!empty($_SESSION['stormexpense_list_filter']['project_nid']) && !$node->project_nid) {
|
||||
$node->project_nid = $_SESSION['stormexpense_list_filter']['project_nid'];
|
||||
}
|
||||
if (!empty($_SESSION['stormexpense_list_filter']['task_nid']) && !$node->task_nid) {
|
||||
$node->task_nid = $_SESSION['stormexpense_list_filter']['task_nid'];
|
||||
}
|
||||
if (!empty($_SESSION['stormexpense_list_filter']['ticket_nid']) && !$node->ticket_nid) {
|
||||
$node->ticket_nid = $_SESSION['stormexpense_list_filter']['ticket_nid'];
|
||||
}
|
||||
if (array_key_exists('organization_nid', $_GET)) $node->organization_nid = $_GET['organization_nid'];
|
||||
if (array_key_exists('project_nid', $_GET)) $node->project_nid = $_GET['project_nid'];
|
||||
if (array_key_exists('task_nid', $_GET)) $node->task_nid = $_GET['task_nid'];
|
||||
if (array_key_exists('ticket_nid', $_GET)) $node->ticket_nid = $_GET['ticket_nid'];
|
||||
|
||||
$node->expensedate = time();
|
||||
$s_org = "SELECT n.nid, n.title FROM {stormorganization} so INNER JOIN {node} n
|
||||
ON so.nid=n.nid WHERE n.status=1 AND so.isactive=1 AND n.type='stormorganization' ORDER BY n.title";
|
||||
|
||||
// Load tax defaults
|
||||
$node->tax1app = variable_get('storm_tax1_app', 1);
|
||||
$node->tax1percent = variable_get('storm_tax1_percent', 20);
|
||||
$node->tax2app = variable_get('storm_tax2_app', 0);
|
||||
$node->tax2percent = variable_get('storm_tax2_percent', 20);
|
||||
}
|
||||
else {
|
||||
$s_org = "SELECT n.nid, n.title FROM {stormorganization} so INNER JOIN {node} n
|
||||
ON so.nid=n.nid WHERE n.status=1 AND n.type='stormorganization' ORDER BY n.title";
|
||||
}
|
||||
|
||||
// Transition to compound tax - allow for nodes which may have been saved in the past without a tax percentage
|
||||
if ((arg(2) == 'edit') && ($node->tax1percent == NULL)) {
|
||||
$node->tax1percent = $node->tax1 / $node->amount * 100;
|
||||
}
|
||||
|
||||
$type = node_get_types('type', $node);
|
||||
$w = -100;
|
||||
|
||||
$form['#attributes']['class'] = 'stormcomponent_node_form';
|
||||
|
||||
$form['group1'] = array(
|
||||
'#type' => 'markup',
|
||||
'#theme' => 'storm_form_group',
|
||||
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'group1') : -20,
|
||||
);
|
||||
|
||||
$s_org = stormorganization_access_sql($s_org);
|
||||
$s_org = db_rewrite_sql($s_org);
|
||||
$r = db_query($s_org);
|
||||
$organizations = array();
|
||||
# if ($r->num_rows > 0) {
|
||||
while ($organization = db_fetch_object($r)) {
|
||||
$organizations[$organization->nid] = $organization->title;
|
||||
if (!isset($node->organization_nid)) {
|
||||
$node->organization_nid = $organization->nid;
|
||||
}
|
||||
}
|
||||
# }
|
||||
$form['group1']['organization_nid'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Organization'),
|
||||
'#default_value' => $node->organization_nid,
|
||||
'#options' => $organizations,
|
||||
'#required' => TRUE,
|
||||
'#attributes' => array('onchange' => "stormticket_organization_project_task_tickets(this, 'edit-project-nid', 'edit-task-nid', 'edit-ticket-nid', true, '-')"),
|
||||
);
|
||||
|
||||
$s = "SELECT n.nid, n.title FROM {node} AS n INNER JOIN {stormproject} AS spr ON spr.vid=n.vid
|
||||
WHERE spr.organization_nid=%d AND n.status=1 AND n.type='stormproject' ORDER BY n.title";
|
||||
$s = stormproject_access_sql($s);
|
||||
$s = db_rewrite_sql($s);
|
||||
$r = db_query($s, $node->organization_nid);
|
||||
$projects = array();
|
||||
while ($project = db_fetch_object($r)) {
|
||||
$projects[$project->nid] = $project->title;
|
||||
}
|
||||
$projects = array(0 => '-') + $projects;
|
||||
$form['group1']['project_nid'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Project'),
|
||||
'#default_value' => (isset($node->project_nid)) ? $node->project_nid : NULL,
|
||||
'#options' => $projects,
|
||||
'#process' => array('storm_dependent_select_process'),
|
||||
'#attributes' => array('onchange' => "stormticket_project_task_tickets(this, 'edit-organization-nid', 'edit-task-nid', 'edit-ticket-nid', true, '-')"),
|
||||
);
|
||||
|
||||
$tree = _stormtask_get_tree((isset($node->project_nid)) ? $node->project_nid : NULL);
|
||||
$tasks = _stormtask_plain_tree($tree);
|
||||
$tasks = array(0 => '-') + $tasks;
|
||||
$form['group1']['task_nid'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Task'),
|
||||
'#default_value' => (isset($node->task_nid)) ? $node->task_nid : NULL,
|
||||
'#options' => (isset($tasks)) ? $tasks : NULL,
|
||||
'#process' => array('storm_dependent_select_process'),
|
||||
'#attributes' => array('onchange' => "stormticket_task_tickets(this, 'edit-organization-nid', 'edit-project-nid', 'edit-ticket-nid', true, '-')"),
|
||||
);
|
||||
|
||||
$tickets = array();
|
||||
$s = "SELECT n.nid, n.title FROM {node} AS n INNER JOIN {stormticket} AS sti ON sti.vid=n.vid WHERE n.status=1 AND n.type='stormticket'
|
||||
AND sti.organization_nid=%d AND sti.project_nid=%d AND sti.task_nid=%d ORDER BY n.title";
|
||||
$s = stormticket_access_sql($s);
|
||||
$s = db_rewrite_sql($s);
|
||||
if (isset($node->organization_nid) && (isset($node->project_nid))) {
|
||||
$r = db_query($s, $node->organization_nid, $node->project_nid, $node->task_nid);
|
||||
}
|
||||
while ($ticket = db_fetch_object($r)) {
|
||||
$tickets[$ticket->nid] = $ticket->title;
|
||||
}
|
||||
$form['group1']['ticket_nid'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Ticket'),
|
||||
'#default_value' => (isset($node->ticket_nid)) ? $node->ticket_nid : NULL,
|
||||
'#options' => array(0 => '-') + $tickets,
|
||||
'#process' => array('storm_dependent_select_process'),
|
||||
);
|
||||
|
||||
$form['group2'] = array(
|
||||
'#type' => 'markup',
|
||||
'#theme' => 'storm_form_group',
|
||||
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'group2') : -19,
|
||||
);
|
||||
|
||||
$form['group2']['expensedate'] = array(
|
||||
'#type' => 'dateext',
|
||||
'#title' => t('Date'),
|
||||
'#default_value' => $node->expensedate,
|
||||
);
|
||||
|
||||
$form['group2']['provider_title'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Provider'),
|
||||
'#size' => 50,
|
||||
'#default_value' => (isset($node->provider_title)) ? $node->provider_title : NULL,
|
||||
'#autocomplete_path' => 'storm/expenses/provider_autocomplete',
|
||||
);
|
||||
|
||||
$form['group3'] = array(
|
||||
'#type' => 'markup',
|
||||
'#theme' => 'storm_form_group',
|
||||
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'group3') : -18,
|
||||
);
|
||||
|
||||
$form['group3']['amount'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Amount'),
|
||||
'#default_value' => (isset($node->amount)) ? $node->amount : NULL,
|
||||
'#size' => 15,
|
||||
);
|
||||
|
||||
$form['group4'] = array(
|
||||
'#type' => 'markup',
|
||||
'#theme' => 'storm_form_group',
|
||||
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'group4') : -17,
|
||||
);
|
||||
|
||||
$form['group4']['tax1app'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Tax 1 Application'),
|
||||
'#options' => array(
|
||||
1 => t('Apply to item amount'),
|
||||
0 => t('Do not apply tax'),
|
||||
),
|
||||
'#default_value' => $node->tax1app,
|
||||
);
|
||||
|
||||
$form['group4']['tax1percent'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Tax 1 Percentage'),
|
||||
'#default_value' => $node->tax1percent,
|
||||
'#size' => 20,
|
||||
);
|
||||
|
||||
$form['group4']['tax2app'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Tax 2 Application'),
|
||||
'#options' => array(
|
||||
2 => t('Apply to total of item amount plus previous tax'),
|
||||
1 => t('Apply to item amount'),
|
||||
0 => t('Do not apply tax'),
|
||||
),
|
||||
'#default_value' => $node->tax2app,
|
||||
);
|
||||
|
||||
$form['group4']['tax2percent'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Tax 2 Percentage'),
|
||||
'#default_value' => $node->tax2percent,
|
||||
'#size' => 20,
|
||||
);
|
||||
|
||||
if (!variable_get('storm_tax_display', TRUE)) {
|
||||
$form['group4']['#type'] = 'hidden';
|
||||
}
|
||||
if (!variable_get('storm_tax2_display', TRUE)) {
|
||||
$form['group4']['tax2app']['#type'] = 'hidden';
|
||||
$form['group4']['tax2percent']['#type'] = 'hidden';
|
||||
}
|
||||
|
||||
$form['taxnotes'] = array(
|
||||
'#type' => 'markup',
|
||||
'#value' => t('Totals will be calculated automatically according to your tax selections.'),
|
||||
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'group4') : -17,
|
||||
);
|
||||
|
||||
$form['title'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => check_plain($type->title_label),
|
||||
'#required' => TRUE,
|
||||
'#default_value' => $node->title,
|
||||
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'title') : -16,
|
||||
);
|
||||
|
||||
if ($type->has_body) {
|
||||
$form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
// NODE MANIPULATION FUNCTIONS
|
||||
function stormexpense_insert($node) {
|
||||
_stormexpense_beforesave($node);
|
||||
|
||||
db_query("INSERT INTO {stormexpense}
|
||||
(vid, nid, organization_nid, organization_title, project_nid, project_title,
|
||||
task_nid, task_title, task_stepno, ticket_nid, ticket_title,
|
||||
provider_nid, provider_title, expensedate, amount, tax1app, tax1percent,
|
||||
tax1, subtotal, tax2app, tax2percent, tax2, total) VALUES
|
||||
(%d, %d, %d, '%s', %d, '%s',
|
||||
%d, '%s', '%s', %d, '%s',
|
||||
%d, '%s', %d, %f, %d, %f,
|
||||
%f, %f, %d, %f, %f, %f)",
|
||||
$node->vid, $node->nid, $node->organization_nid, $node->organization_title, $node->project_nid, (isset($node->project_title)) ? $node->project_title : NULL,
|
||||
(isset($node->task_nid)) ? $node->task_nid : NULL, (isset($node->task_title)) ? $node->task_title : NULL, (isset($node->task_stepno)) ? $node->task_stepno : NULL, $node->ticket_nid, (isset($node->ticket_title)) ? $node->ticket_title : NULL,
|
||||
(isset($node->provider_nid)) ? $node->provider_nid : NULL, $node->provider_title, $node->expensedate, $node->amount, $node->tax1app, $node->tax1percent,
|
||||
$node->tax1, $node->subtotal, $node->tax2app, $node->tax2percent, $node->tax2, $node->total);
|
||||
}
|
||||
|
||||
function stormexpense_update($node) {
|
||||
_stormexpense_beforesave($node);
|
||||
|
||||
if ($node->revision) {
|
||||
stormexpense_insert($node);
|
||||
}
|
||||
else {
|
||||
db_query("UPDATE {stormexpense} SET
|
||||
organization_nid=%d, organization_title='%s', project_nid=%d, project_title='%s',
|
||||
task_nid=%d, task_title='%s', task_stepno='%s', ticket_nid=%d, ticket_title='%s',
|
||||
provider_nid=%d, provider_title='%s', expensedate=%d, amount=%f, tax1app=%d, tax1percent=%f,
|
||||
tax1=%f, subtotal=%f, tax2app=%d, tax2percent=%f, tax2=%f, total=%f WHERE vid = %d",
|
||||
$node->organization_nid, $node->organization_title, $node->project_nid, $node->project_title,
|
||||
$node->task_nid, $node->task_title, $node->task_stepno, $node->ticket_nid, $node->ticket_title,
|
||||
$node->provider_nid, $node->provider_title, $node->expensedate, $node->amount, $node->tax1app, $node->tax1percent,
|
||||
$node->tax1, $node->subtotal, $node->tax2app, $node->tax2percent, $node->tax2, $node->total, $node->vid);
|
||||
}
|
||||
}
|
||||
|
||||
function _stormexpense_beforesave(&$node) {
|
||||
// Allow use of comma when inputting numerical values - str_replace with period decimal
|
||||
$node->amount = str_replace(',', '.', $node->amount);
|
||||
$node->tax1percent = str_replace(',', '.', $node->tax1percent);
|
||||
$node->tax2percent = str_replace(',', '.', $node->tax2percent);
|
||||
|
||||
$node->expensedate = _storm_date_to_gmtimestamp($node->expensedate);
|
||||
|
||||
storm_taxation($node);
|
||||
|
||||
$s = "SELECT n.title FROM {node} AS n
|
||||
INNER JOIN {stormorganization} AS o ON n.nid=o.nid
|
||||
WHERE type='stormorganization' AND n.nid=%d";
|
||||
$r = db_query($s, $node->organization_nid);
|
||||
$o = db_fetch_object($r);
|
||||
$o ? $node->organization_title = $o->title : NULL;
|
||||
|
||||
$s = "SELECT n.title, p.organization_title
|
||||
FROM {node} n INNER JOIN {stormproject} p ON n.nid=p.nid
|
||||
WHERE type='stormproject' AND n.nid=%d";
|
||||
$r = db_query($s, $node->project_nid);
|
||||
$p = db_fetch_object($r);
|
||||
$p ? $node->project_title = $p->title : NULL;
|
||||
|
||||
$s = "SELECT title, stepno FROM {node} AS n INNER JOIN {stormtask} AS t ON n.vid=t.vid WHERE n.type='stormtask' AND n.nid=%d";
|
||||
(isset($node->task_nid)) ? $r = db_query($s, $node->task_nid) : NULL;
|
||||
$ta = db_fetch_object($r);
|
||||
(isset($ta->title)) ? $node->task_title = $ta->title : NULL;
|
||||
(isset($ta->stepno)) ? $node->task_stepno = $ta->stepno : NULL;
|
||||
|
||||
$s = "SELECT title FROM {node} AS n INNER JOIN {stormticket} AS t ON n.vid=t.vid WHERE n.type='stormticket' AND n.nid=%d";
|
||||
(isset($node->ticket_nid)) ? $r = db_query($s, $node->ticket_nid) : NULL;
|
||||
|
||||
$ti = db_fetch_object($r);
|
||||
(isset($ti->title)) ? $node->ticket_title = $ti->title : NULL;
|
||||
}
|
||||
|
||||
function stormexpense_nodeapi(&$node, $op, $teaser, $page) {
|
||||
if ($node->type != 'stormexpense') {
|
||||
return;
|
||||
}
|
||||
switch ($op) {
|
||||
case 'delete revision':
|
||||
// Notice that we're matching a single revision based on the node's vid.
|
||||
db_query('DELETE FROM {stormexpense} WHERE vid = %d', $node->vid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function stormexpense_delete($node) {
|
||||
db_query('DELETE FROM {stormexpense} WHERE nid = %d', $node->nid);
|
||||
}
|
||||
|
||||
function stormexpense_load($node) {
|
||||
$additions = db_fetch_object(db_query('SELECT * FROM {stormexpense} WHERE vid = %d', $node->vid));
|
||||
return $additions;
|
||||
}
|
||||
|
||||
function stormexpense_view($node, $teaser = FALSE, $page = FALSE) {
|
||||
return theme('stormexpense_view', $node, $teaser, $page);
|
||||
}
|
||||
|
||||
// INVOICE AUTO ADD HANDLER
|
||||
function stormexpense_storminvoice_auto_add($node, $invoice_nid = NULL) {
|
||||
if (!module_exists('storminvoice')) {
|
||||
drupal_set_message(t('This function should only be called from within SuiteDesk Invoice'));
|
||||
return;
|
||||
}
|
||||
else {
|
||||
global $user;
|
||||
|
||||
if (!$invoice_nid) {
|
||||
|
||||
$new_invoice = new StdClass;
|
||||
|
||||
// Code copied with edits from node form
|
||||
$new_invoice->requestdate = time();
|
||||
$new_invoice->duedate = $new_invoice->requestdate + (variable_get('storminvoice_payment_days', 30) * 86400);
|
||||
$s = "SELECT MAX(CAST(SUBSTRING_INDEX(sin.number, '/', 1) AS SIGNED)) FROM {node} n INNER JOIN {storminvoice} sin ON n.nid=sin.nid
|
||||
WHERE n.type='storminvoice' AND YEAR(FROM_UNIXTIME(sin.requestdate))=YEAR(FROM_UNIXTIME(%d))";
|
||||
$date = getdate($new_invoice->requestdate);
|
||||
$new_invoice->number = (db_result(db_query($s, $new_invoice->requestdate)) + 1) .'/'. $date['year'];
|
||||
|
||||
$new_invoice->title = $node->title;
|
||||
$new_invoice->uid = $user->uid;
|
||||
$new_invoice->type = 'storminvoice';
|
||||
// $new_invoice->reference
|
||||
$new_invoice->organization_nid = $node->organization_nid;
|
||||
$new_invoice->organization_title = $node->organization_title;
|
||||
$new_invoice->project_nid = $node->project_nid;
|
||||
$new_invoice->project_title = $node->project_title;
|
||||
// $new_invoice->amount
|
||||
// $new_invoice->tax
|
||||
// $new_invoice->total
|
||||
// $new_invoice->totalcustomercurr
|
||||
// $new_invoice->taxexempt
|
||||
$new_invoice->src_nid = $node->nid;
|
||||
$new_invoice->src_vid = $node->vid;
|
||||
|
||||
node_save($new_invoice);
|
||||
$invoice_nid = $new_invoice->nid;
|
||||
}
|
||||
else {
|
||||
$new_invoice = node_load($invoice_nid);
|
||||
}
|
||||
|
||||
if ($node->ticket_nid) {
|
||||
$parent_ticket = node_load($node->ticket_nid);
|
||||
}
|
||||
elseif ($node->task_nid) {
|
||||
$parent_task = node_load($node->task_nid);
|
||||
}
|
||||
elseif ($node->project_nid) {
|
||||
$parent_project = node_load($node->project_nid);
|
||||
}
|
||||
else {
|
||||
$parent_organization = node_load($node->organization_nid);
|
||||
}
|
||||
|
||||
$count = count($new_invoice->items);
|
||||
|
||||
$new_invoice->items[$count]->description = $node->title;
|
||||
$new_invoice->items[$count]->amount = $node->amount;
|
||||
// Tax percent uses the values set on the expense.
|
||||
$new_invoice->items[$count]->tax1app = $node->tax1app;
|
||||
$new_invoice->items[$count]->tax1percent = $node->tax1percent;
|
||||
$new_invoice->items[$count]->tax1 = $node-> tax1;
|
||||
$new_invoice->items[$count]->tax2app = $node->tax2app;
|
||||
$new_invoice->items[$count]->tax2percent = $node->tax2percent;
|
||||
$new_invoice->items[$count]->tax2 = $node->tax2;
|
||||
$new_invoice->items[$count]->total = $node->total;
|
||||
$new_invoice->items[$count]->src_nid = $node->nid;
|
||||
$new_invoice->items[$count]->src_vid = $node->vid;
|
||||
|
||||
// storm_taxation($new_invoice->items[$count]);
|
||||
storminvoice_update($new_invoice);
|
||||
}
|
||||
return $invoice_nid;
|
||||
}
|
||||
|
||||
|
||||
function stormexpense_views_api() {
|
||||
return array(
|
||||
'api' => 2,
|
||||
'path' => drupal_get_path('module', 'stormexpense'),
|
||||
);
|
||||
}
|
||||
|
||||
function stormexpense_storm_dashboard_links($type) {
|
||||
$links = array();
|
||||
if ($type == 'page' || $type == 'block') {
|
||||
$links[] = array(
|
||||
'theme' => 'storm_dashboard_link',
|
||||
'title' => t('Expenses'),
|
||||
'icon' => 'stormexpense-item',
|
||||
'path' => 'expenses',
|
||||
'params' => array(),
|
||||
'access_arguments' => 'Storm expense: access',
|
||||
'node_type' => 'stormexpense',
|
||||
'add_type' => 'stormexpense',
|
||||
'map' => array(),
|
||||
'weight' => 11,
|
||||
);
|
||||
}
|
||||
return $links;
|
||||
}
|
191
modules/storm/stormexpense/stormexpense.test
Normal file
191
modules/storm/stormexpense/stormexpense.test
Normal file
|
@ -0,0 +1,191 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Test definitions for the SuiteDesk expense module
|
||||
*/
|
||||
class StormexpenseTestCase extends DrupalWebTestCase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => t('SuiteDesk Expense Functionality'),
|
||||
'description' => t('Test the functionality of the SuiteDesk Expense module'),
|
||||
'group' => 'Storm',
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp('storm', 'stormorganization', 'stormproject', 'stormtask', 'stormticket', 'stormexpense', 'stormperson');
|
||||
}
|
||||
|
||||
public function testStormexpenseAccess() {
|
||||
$this->drupalGet('expenses');
|
||||
$this->assertResponse(403, t('Make sure access is denied to SuiteDesk Expense list for anonymous user'));
|
||||
|
||||
$basic_user = $this->drupalCreateUser();
|
||||
$this->drupalLogin($basic_user);
|
||||
$this->drupalGet('expenses');
|
||||
$this->assertResponse(403, t('Make sure access is denied to SuiteDesk Expense list for basic user'));
|
||||
|
||||
$privileged_user = $this->drupalCreateUser(array('Storm expense: access'));
|
||||
$this->drupalLogin($privileged_user);
|
||||
$this->drupalGet('expenses');
|
||||
$this->assertText(t('Expenses'), t('Make sure the correct page has been displayed by checking that the title is "Expenses".'));
|
||||
}
|
||||
|
||||
public function testStormexpenseCreate() {
|
||||
// Create and login user
|
||||
$user = $this->drupalCreateUser(array('Storm organization: add', 'Storm organization: view all', 'Storm expense: add', 'Storm expense: view all', 'Storm project: view all', 'Storm task: view all'));
|
||||
$this->drupalLogin($user);
|
||||
|
||||
// Create a team
|
||||
$org = array(
|
||||
'title' => $this->randomName(32),
|
||||
);
|
||||
|
||||
$expense = array(
|
||||
'organization_nid' => '1',
|
||||
'title' => $this->randomName(32),
|
||||
);
|
||||
|
||||
$this->drupalPost('node/add/stormorganization', $org, t('Save'));
|
||||
|
||||
$this->drupalPost('node/add/stormexpense', $expense, t('Save'));
|
||||
|
||||
$this->assertText(t('Expense @title has been created.', array('@title' => $expense['title'])));
|
||||
}
|
||||
|
||||
public function testStormexpenseReports() {
|
||||
// Create and login user
|
||||
$user = $this->drupalCreateUser(array('Storm expense: access'));
|
||||
$this->drupalLogin($user);
|
||||
|
||||
// Create a team
|
||||
$this->drupalGet('expenses/report/std/en');
|
||||
}
|
||||
|
||||
public function testStormexpenseList() {
|
||||
// Create and login user
|
||||
$userAll = $this->drupalCreateUser(array('Storm organization: add', 'Storm organization: view all', 'Storm expense: access', 'Storm expense: add', 'Storm expense: view all', 'Storm expense: edit all', 'Storm expense: delete all', 'Storm person: add'));
|
||||
$userOrg = $this->drupalCreateUser(array('Storm organization: add', 'Storm organization: view all', 'Storm expense: access', 'Storm expense: add', 'Storm expense: view of user organization', 'Storm expense: edit of user organization', 'Storm expense: delete of user organization'));
|
||||
$userOwn = $this->drupalCreateUser(array('Storm organization: add', 'Storm organization: view all', 'Storm expense: access', 'Storm expense: add', 'Storm expense: view own', 'Storm expense: edit own', 'Storm expense: delete own'));
|
||||
$userViewAllEditOwn = $this->drupalCreateUser(array('Storm organization: add', 'Storm organization: view all', 'Storm expense: access', 'Storm expense: add', 'Storm expense: view all', 'Storm expense: edit own', 'Storm expense: delete own'));
|
||||
|
||||
$this->drupalLogin($userAll);
|
||||
|
||||
// Create organization
|
||||
$org = array(
|
||||
'title' => $this->randomName(32),
|
||||
'body' => $this->randomName(64),
|
||||
);
|
||||
$this->drupalPost('node/add/stormorganization', $org, t('Save'));
|
||||
$org = node_load(array('title' => $org['title']));
|
||||
|
||||
// Create organization
|
||||
$org2 = array(
|
||||
'title' => $this->randomName(32),
|
||||
'body' => $this->randomName(64),
|
||||
);
|
||||
$this->drupalPost('node/add/stormorganization', $org2, t('Save'));
|
||||
$org2 = node_load(array('title' => $org2['title']));
|
||||
|
||||
// Create stormperson with organization to userOrg
|
||||
$personOrg = array(
|
||||
'title' => $this->randomName(32),
|
||||
'body' => $this->randomName(64),
|
||||
'organization_nid' => $org->nid,
|
||||
'user_name' => $userOrg->name,
|
||||
);
|
||||
$this->drupalPost('node/add/stormperson', $personOrg, t('Save'));
|
||||
|
||||
// Create expenses
|
||||
$exp1 = array(
|
||||
'organization_nid' => $org->nid,
|
||||
'title' => $this->randomName(32),
|
||||
);
|
||||
$this->drupalPost('node/add/stormexpense', $exp1, t('Save'));
|
||||
$exp1 = node_load(array('title' => $exp1['title']));
|
||||
|
||||
$this->drupalLogin($userOwn);
|
||||
$exp2 = array(
|
||||
'title' => $this->randomName(32),
|
||||
'organization_nid' => $org->nid,
|
||||
);
|
||||
$this->drupalPost('node/add/stormexpense', $exp2, t('Save'));
|
||||
$exp2 = node_load(array('title' => $exp2['title']));
|
||||
|
||||
$this->drupalLogin($userViewAllEditOwn);
|
||||
$exp3 = array(
|
||||
'title' => $this->randomName(32),
|
||||
'organization_nid' => $org2->nid,
|
||||
);
|
||||
$this->drupalPost('node/add/stormexpense', $exp3, t('Save'));
|
||||
$exp3 = node_load(array('title' => $exp3['title']));
|
||||
|
||||
// Test for 'Storm expense: view all'
|
||||
$this->drupalLogin($userAll);
|
||||
$this->drupalGet('expenses');
|
||||
|
||||
$this->assertLink($exp1->title, 0, 'The Expense appears on the list');
|
||||
$this->assertRaw('node/'. $exp1->nid .'/edit', 'The Expense edit icon appears on the list');
|
||||
$this->assertRaw('node/'. $exp1->nid .'/delete', 'The Expense edit icon appears on the list');
|
||||
|
||||
$this->assertLink($exp2->title, 0, 'The Expense appears on the list');
|
||||
$this->assertRaw('node/'. $exp2->nid .'/edit', 'The Expense edit icon appears on the list');
|
||||
$this->assertRaw('node/'. $exp2->nid .'/delete', 'The Expense edit icon appears on the list');
|
||||
|
||||
$this->assertLink($exp3->title, 0, 'The Expense appears on the list');
|
||||
$this->assertRaw('node/'. $exp3->nid .'/edit', 'The Expense edit icon appears on the list');
|
||||
$this->assertRaw('node/'. $exp3->nid .'/delete', 'The Expense edit icon appears on the list');
|
||||
|
||||
// Test for 'Storm expense: view of user organization'
|
||||
$this->drupalLogin($userOrg);
|
||||
$this->drupalGet('expenses');
|
||||
|
||||
$this->assertLink($exp1->title, 0, 'The Expense appears on the list');
|
||||
$this->assertRaw('node/'. $exp1->nid .'/edit', 'The Expense edit icon appears on the list');
|
||||
$this->assertRaw('node/'. $exp1->nid .'/delete', 'The Expense edit icon appears on the list');
|
||||
|
||||
$this->assertLink($exp2->title, 0, 'The Expense appears on the list');
|
||||
$this->assertRaw('node/'. $exp2->nid .'/edit', 'The Expense edit icon appears on the list');
|
||||
$this->assertRaw('node/'. $exp2->nid .'/delete', 'The Expense edit icon appears on the list');
|
||||
|
||||
$this->assertNoLink($exp3->title, 'The Expense does not appear on the list');
|
||||
$this->assertNoRaw('node/'. $exp3->nid .'/edit', 'The Expense edit icon does not appear on the list');
|
||||
$this->assertNoRaw('node/'. $exp3->nid .'/delete', 'The Expense edit icon does not appear on the list');
|
||||
|
||||
// Test for 'Storm expense: view own'
|
||||
$this->drupalLogin($userOwn);
|
||||
$this->drupalGet('expenses');
|
||||
|
||||
$this->assertNoLink($exp1->title, 'The Expense does not appear on the list');
|
||||
$this->assertNoRaw('node/'. $exp1->nid .'/edit', 'The Expense edit icon does not appear on the list');
|
||||
$this->assertNoRaw('node/'. $exp1->nid .'/delete', 'The Expense edit icon does not appear on the list');
|
||||
|
||||
$this->assertLink($exp2->title, 0, 'The Expense appears on the list');
|
||||
$this->assertRaw('node/'. $exp2->nid .'/edit', 'The Expense edit icon appears on the list');
|
||||
$this->assertRaw('node/'. $exp2->nid .'/delete', 'The Expense edit icon appears on the list');
|
||||
|
||||
$this->assertNoLink($exp3->title, 'The Expense does not appear on the list');
|
||||
$this->assertNoRaw('node/'. $exp3->nid .'/edit', 'The Expense edit icon does not appear on the list');
|
||||
$this->assertNoRaw('node/'. $exp3->nid .'/delete', 'The Expense edit icon does not appear on the list');
|
||||
|
||||
|
||||
// Test for 'Storm expense: view all', 'Storm expense: edit own'
|
||||
$this->drupalLogin($userViewAllEditOwn);
|
||||
$this->drupalGet('expenses');
|
||||
|
||||
$this->assertLink($exp1->title, 0, 'The Expense appears on the list');
|
||||
$this->assertNoRaw('node/'. $exp1->nid .'/edit', 'The Expense edit icon does not appear on the list');
|
||||
$this->assertNoRaw('node/'. $exp1->nid .'/delete', 'The Expense edit icon does not appear on the list');
|
||||
|
||||
$this->assertLink($exp2->title, 0, 'The Expense appears on the list');
|
||||
$this->assertNoRaw('node/'. $exp2->nid .'/edit', 'The Expense edit icon does not appear on the list');
|
||||
$this->assertNoRaw('node/'. $exp2->nid .'/delete', 'The Expense edit icon does not appear on the list');
|
||||
|
||||
$this->assertLink($exp3->title, 0, 'The Expense appears on the list');
|
||||
$this->assertRaw('node/'. $exp3->nid .'/edit', 'The Expense edit icon appears on the list');
|
||||
$this->assertRaw('node/'. $exp3->nid .'/delete', 'The Expense edit icon appears on the list');
|
||||
|
||||
}
|
||||
}
|
||||
|
335
modules/storm/stormexpense/stormexpense.theme.inc
Normal file
335
modules/storm/stormexpense/stormexpense.theme.inc
Normal file
|
@ -0,0 +1,335 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
|
||||
function theme_stormexpense_list($header, $expenses, $totals) {
|
||||
$rows = array();
|
||||
foreach ($expenses as $expense) {
|
||||
$rows[] = array(
|
||||
l($expense->organization_title, 'node/'. $expense->organization_nid),
|
||||
l($expense->project_title, 'node/'. $expense->project_nid),
|
||||
l($expense->title, 'node/'. $expense->nid),
|
||||
format_date($expense->expensedate, 'custom', 'Y-m-d'),
|
||||
array('data' => sprintf('%.2f', $expense->total), 'align' => 'right'),
|
||||
array(
|
||||
'data' => storm_icon_edit_node($expense, $_GET) .' '. storm_icon_delete_node($expense, $_GET),
|
||||
'class' => 'storm_list_operations',
|
||||
),
|
||||
);
|
||||
}
|
||||
$o = theme('table', $header, $rows);
|
||||
|
||||
$header = array(
|
||||
array(
|
||||
'data' => t('Amount'),
|
||||
'style' => 'text-align: right;',
|
||||
),
|
||||
array(
|
||||
'data' => variable_get('storm_tax1_name', 'VAT'),
|
||||
'style' => 'text-align: right;',
|
||||
),
|
||||
array(
|
||||
'data' => variable_get('storm_tax2_name', 'Tax 2'),
|
||||
'style' => 'text-align: right;',
|
||||
),
|
||||
array(
|
||||
'data' => t('Total'),
|
||||
'style' => 'text-align: right;',
|
||||
),
|
||||
);
|
||||
|
||||
$rows = array();
|
||||
$rows[] = array(
|
||||
array(
|
||||
'data' => sprintf('%.2f', $totals->t_amount),
|
||||
'style' => 'text-align: right;',
|
||||
),
|
||||
array(
|
||||
'data' => sprintf('%.2f', $totals->t_tax1),
|
||||
'style' => 'text-align: right;',
|
||||
),
|
||||
array(
|
||||
'data' => sprintf('%.2f', $totals->t_tax2),
|
||||
'style' => 'text-align: right;',
|
||||
),
|
||||
array(
|
||||
'data' => sprintf('%.2f', $totals->t_total),
|
||||
'style' => 'text-align: right;',
|
||||
),
|
||||
);
|
||||
|
||||
$o .= theme('table', $header, $rows);
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
function theme_stormexpense_view($node, $teaser = FALSE, $page = FALSE) {
|
||||
drupal_add_css(drupal_get_path('module', 'storm') . '/storm-node.css', 'module');
|
||||
|
||||
$node = node_prepare($node, $teaser);
|
||||
$l_pos = 1; // Used to increase the link position number (see issue 814820)
|
||||
|
||||
$node->content['links'] = array(
|
||||
'#prefix' => '<div class="stormlinks"><dl>',
|
||||
'#suffix' => '</dl></div>',
|
||||
'#weight' => -25,
|
||||
);
|
||||
// Code to create invoice auto_add link
|
||||
if (module_exists('storminvoice') && user_access('Storm invoice: add')) {
|
||||
$v = '';
|
||||
$v .= '<strong>'. t('Invoice this item:') .'</strong>';
|
||||
$v .= '<ul>';
|
||||
$v .= '<li>'. l(t('Add to new invoice'), 'invoice/auto_add/new/'. $node->nid) .'</li>';
|
||||
$v .= '<li>'. l(t('Add to existing invoice'), 'invoice/auto_add/existing/'. $node->nid) .'</li>';
|
||||
$v .= '</ul>';
|
||||
|
||||
$node->content['links']['auto_invoice'] = array(
|
||||
'#prefix' => '<dt id="storminvoice-item" class="stormcomponent">',
|
||||
'#suffix' => '</dt>',
|
||||
'#value' => $v,
|
||||
'#weight' => $l_pos++,
|
||||
);
|
||||
}
|
||||
|
||||
$node->content['group1'] = array(
|
||||
'#prefix' => '<div class="stormfields">',
|
||||
'#suffix' => '</div>',
|
||||
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'group1') : -20,
|
||||
);
|
||||
|
||||
$node->content['group1']['organization'] = array(
|
||||
'#prefix' => '<div class="organization">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', t('Organization'), l($node->organization_title, 'node/'. $node->organization_nid)),
|
||||
'#weight' => 1,
|
||||
);
|
||||
|
||||
$node->content['group1']['project'] = array(
|
||||
'#prefix' => '<div class="project">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', t('Project'), l($node->project_title, 'node/'. $node->project_nid)),
|
||||
'#weight' => 2,
|
||||
);
|
||||
|
||||
$node->content['group1']['task'] = array(
|
||||
'#prefix' => '<div class="task">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', t('Task'), l($node->task_title, 'node/'. $node->task_nid)),
|
||||
'#weight' => 3,
|
||||
);
|
||||
|
||||
$node->content['group1']['ticket'] = array(
|
||||
'#prefix' => '<div class="ticket">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', t('Ticket'), l($node->ticket_title, 'node/'. $node->ticket_nid)),
|
||||
'#weight' => 4,
|
||||
);
|
||||
|
||||
$node->content['group2'] = array(
|
||||
'#prefix' => '<div class="stormfields">',
|
||||
'#suffix' => '</div>',
|
||||
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'group2') : -19,
|
||||
);
|
||||
|
||||
$node->content['group2']['expensedate'] = array(
|
||||
'#prefix' => '<div class="expensedate">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', t('Date'), format_date($node->expensedate, 'custom', 'Y-m-d')),
|
||||
'#weight' => 1,
|
||||
);
|
||||
|
||||
$node->content['group2']['provider'] = array(
|
||||
'#prefix' => '<div class="provider">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', t('Provider'), $node->provider_title),
|
||||
'#weight' => 2,
|
||||
);
|
||||
|
||||
$node->content['group3'] = array(
|
||||
'#prefix' => '<div class="stormfields">',
|
||||
'#suffix' => '</div>',
|
||||
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'group3') : -18,
|
||||
);
|
||||
|
||||
$node->content['group3']['amount'] = array(
|
||||
'#prefix' => '<div class="amount">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', t('Amount'), sprintf('%.2f', $node->amount)),
|
||||
'#weight' => 1,
|
||||
);
|
||||
|
||||
$node->content['group4'] = array(
|
||||
'#prefix' => '<div class="stormfields">',
|
||||
'#suffix' => '</div>',
|
||||
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'group4') : -17,
|
||||
);
|
||||
|
||||
if ($node->tax1) {
|
||||
$node->content['group4']['tax1'] = array(
|
||||
'#prefix' => '<div class="tax">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', variable_get('storm_tax1_name', 'VAT'), sprintf('%.2f', $node->tax1)),
|
||||
'#weight' => 1,
|
||||
);
|
||||
}
|
||||
|
||||
if ($node->tax2) {
|
||||
$node->content['group4']['tax2'] = array(
|
||||
'#prefix' => '<div class="tax">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', variable_get('storm_tax2_name', 'Tax 2'), sprintf('%.2f', $node->tax2)),
|
||||
'#weight' => 2,
|
||||
);
|
||||
}
|
||||
|
||||
if ($node->tax1 || $node->tax2) {
|
||||
$node->content['group4']['total'] = array(
|
||||
'#prefix' => '<div class="total">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', t('Total'), sprintf('%.2f', $node->total)),
|
||||
'#weight' => 3,
|
||||
);
|
||||
}
|
||||
|
||||
$node->content['group_item'] = array(
|
||||
'#prefix' => '<div class="stormfields">',
|
||||
'#suffix' => '</div>',
|
||||
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'group_item') : -20,
|
||||
);
|
||||
$node->content['group_item']['author'] = array(
|
||||
'#prefix' => '<div class="author">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', t('Submitted by'), theme('username', $node)),
|
||||
'#weight' => 1,
|
||||
);
|
||||
$node->content['group_item']['created'] = array(
|
||||
'#prefix' => '<div class="created">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', t('Created'), format_date($node->created, 'small')),
|
||||
'#weight' => 2,
|
||||
);
|
||||
if ($node->changed != $node->created) {
|
||||
$node->content['group_item']['modified'] = array(
|
||||
'#prefix' => '<div class="modified">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', t('Modified'), format_date($node->changed, 'small')),
|
||||
'#weight' => 3,
|
||||
);
|
||||
}
|
||||
|
||||
$node->content['body_field'] = array(
|
||||
'#prefix' => '<div class="stormbody">',
|
||||
'#suffix' => '</div>',
|
||||
'#value' => theme('storm_view_item', t('Description'), $node->content['body']['#value']),
|
||||
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'body_field') : -16,
|
||||
);
|
||||
unset($node->content['body']);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
function theme_stormexpense_list_form_report_reports() {
|
||||
$reports = array(
|
||||
'std' => t('Standard'),
|
||||
'for_organization' => t('For an organization'),
|
||||
'for_organization_w_task' => t('For an org. with tasks'),
|
||||
'for_project' => t('For a project'),
|
||||
);
|
||||
|
||||
return $reports;
|
||||
}
|
||||
|
||||
function theme_stormexpense_list_report($report, $language, $expenses) {
|
||||
switch ($report) {
|
||||
case 'std':
|
||||
$header = array(
|
||||
t('Organization', array(), $language),
|
||||
t('Project', array(), $language),
|
||||
t('Title', array(), $language),
|
||||
t('Date', array(), $language),
|
||||
t('Total', array(), $language));
|
||||
$expenses_total = 0;
|
||||
$rows = array();
|
||||
foreach ($expenses as $expense) {
|
||||
$rows[] = array(
|
||||
check_plain($expense->organization_title),
|
||||
check_plain($expense->project_title),
|
||||
check_plain($expense->title),
|
||||
format_date($expense->expensedate, 'custom', 'Y-m-d'),
|
||||
array('data' => sprintf('%.2f', $expense->total), 'align' => 'right'),
|
||||
);
|
||||
$expenses_total += $expense->total;
|
||||
}
|
||||
$title = '<h2>'. t('Expenses report', array(), $language) .'</h2><br />';
|
||||
break;
|
||||
case 'for_organization':
|
||||
$organization = node_load($_SESSION['stormexpense_list_filter']['organization_nid']);
|
||||
$header = array(
|
||||
t('Project', array(), $language),
|
||||
t('Title', array(), $language),
|
||||
t('Date', array(), $language),
|
||||
t('Total', array(), $language));
|
||||
$expenses_total = 0;
|
||||
foreach ($expenses as $expense) {
|
||||
$rows[] = array(
|
||||
check_plain($expense->project_title),
|
||||
check_plain($expense->title),
|
||||
format_date($expense->expensedate, 'custom', 'Y-m-d'),
|
||||
array('data' => sprintf('%.2f', $expense->total), 'align' => 'right'),
|
||||
);
|
||||
$expenses_total += $expense->total;
|
||||
}
|
||||
$title = '<h2>'. t('Expenses report', array(), $language) .'</h2><br />';
|
||||
$title .= t('Organization : @organization', array('@organization' => $organization->fullname), $language) .'<br />';
|
||||
break;
|
||||
case 'for_organization_w_task':
|
||||
$organization = node_load($_SESSION['stormexpense_list_filter']['organization_nid']);
|
||||
$header = array(
|
||||
t('Project', 'expense', array(), $language),
|
||||
t('Task', 'expense', array(), $language),
|
||||
t('Title', 'expense', array(), $language),
|
||||
t('Date', 'expense', array(), $language),
|
||||
t('Total', 'expense', array(), $language));
|
||||
$total_duration = 0;
|
||||
foreach ($expenses as $expense) {
|
||||
$rows[] = array(
|
||||
check_plain($expense->project_title),
|
||||
check_plain($expense->task_title),
|
||||
check_plain($expense->title),
|
||||
format_date($expense->expensedate, 'custom', 'Y-m-d'),
|
||||
array('data' => sprintf('%.2f', $expense->total), 'align' => 'right'),
|
||||
);
|
||||
$expenses_total += $expense->total;
|
||||
}
|
||||
$title = '<h2>'. t('Expenses report', array(), $language) .'</h2><br />';
|
||||
$title .= t('Organization : @organization', array('@organization' => $organization->fullname), $language) .'<br />';
|
||||
break;
|
||||
case 'for_project':
|
||||
$organization = node_load($_SESSION['stormexpense_list_filter']['organization_nid']);
|
||||
$project = node_load($_SESSION['stormexpense_list_filter']['project_nid']);
|
||||
|
||||
$header = array(
|
||||
t('Task', 'expense', array(), $language),
|
||||
t('Title', 'expense', array(), $language),
|
||||
t('Date', 'expense', array(), $language),
|
||||
t('Total', 'expense', array(), $language));
|
||||
$total_duration = 0;
|
||||
foreach ($expenses as $expense) {
|
||||
$rows[] = array(
|
||||
check_plain($expense->task_title),
|
||||
check_plain($expense->title),
|
||||
format_date($expense->expensedate, 'custom', 'Y-m-d'),
|
||||
array('data' => sprintf('%.2f', $expense->total), 'align' => 'right'),
|
||||
);
|
||||
$expenses_total += $expense->total;
|
||||
}
|
||||
$title = '<h2>'. t('Expenses report', array(), $language) .'</h2><br />';
|
||||
$title .= t('Organization : @organization', array('@organization' => $organization->fullname), $language) .'<br />';
|
||||
$title .= t('Project : @project', array('@project' => $project->title), $language) .'<br />';
|
||||
break;
|
||||
}
|
||||
$footer = '<h3>'. t('Expenses total : %expenses_total' , array('%expenses_total' => format_plural($expenses_total, '1', '@count', array(), $language)), $language) .'</h3>';
|
||||
return theme('storm_list_report', $header, $rows, $title, $footer);
|
||||
}
|
287
modules/storm/stormexpense/stormexpense.views.inc
Normal file
287
modules/storm/stormexpense/stormexpense.views.inc
Normal file
|
@ -0,0 +1,287 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Functions to expose SuiteDesk expense data to views
|
||||
*/
|
||||
function stormexpense_views_data() {
|
||||
$data['stormexpense']['table']['group'] = t('SuiteDesk Expense');
|
||||
$data['stormexpense']['table']['join'] = array(
|
||||
'node' => array(
|
||||
'left_field' => 'vid',
|
||||
'field' => 'vid',
|
||||
),
|
||||
);
|
||||
|
||||
$data['stormexpense']['organization_nid'] = array(
|
||||
'title' => t('Organization'),
|
||||
'help' => t('Expense -> Organization'),
|
||||
'relationship' => array(
|
||||
'base' => 'node',
|
||||
'field' => 'nid',
|
||||
'handler' => 'views_handler_relationship',
|
||||
'label' => t('Expense -> Organization'),
|
||||
),
|
||||
);
|
||||
|
||||
$data['stormexpense']['organization_title'] = array(
|
||||
'title' => t('Organization'),
|
||||
'help' => t('SuiteDesk Expense: Organization (title only)'),
|
||||
'field' => array(
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_string',
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_string',
|
||||
),
|
||||
);
|
||||
|
||||
$data['stormexpense']['project_nid'] = array(
|
||||
'title' => t('Project'),
|
||||
'help' => t('Expense -> Project'),
|
||||
'relationship' => array(
|
||||
'base' => 'node',
|
||||
'field' => 'nid',
|
||||
'handler' => 'views_handler_relationship',
|
||||
'label' => t('Expense -> Project'),
|
||||
),
|
||||
);
|
||||
|
||||
$data['stormexpense']['project_title'] = array(
|
||||
'title' => t('Project'),
|
||||
'help' => t('SuiteDesk Expense Project (title only)'),
|
||||
'field' => array(
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_string',
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_string',
|
||||
),
|
||||
);
|
||||
|
||||
$data['stormexpense']['task_nid'] = array(
|
||||
'title' => t('Task'),
|
||||
'help' => t('Expense -> Task'),
|
||||
'relationship' => array(
|
||||
'base' => 'node',
|
||||
'field' => 'nid',
|
||||
'handler' => 'views_handler_relationship',
|
||||
'label' => t('Expense -> Task'),
|
||||
),
|
||||
);
|
||||
|
||||
$data['stormexpense']['task_stepno'] = array(
|
||||
'title' => t('Task step number'),
|
||||
'help' => t('SuiteDesk Expense Task Step Number'),
|
||||
'field' => array(
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_numeric',
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_numeric',
|
||||
),
|
||||
);
|
||||
|
||||
$data['stormexpense']['task_title'] = array(
|
||||
'title' => t('Task'),
|
||||
'help' => t('SuiteDesk Expense Task (title only)'),
|
||||
'field' => array(
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_string',
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_string',
|
||||
),
|
||||
);
|
||||
|
||||
$data['stormexpense']['ticket_nid'] = array(
|
||||
'title' => t('Ticket'),
|
||||
'help' => t('Expense -> Ticket'),
|
||||
'relationship' => array(
|
||||
'base' => 'node',
|
||||
'field' => 'nid',
|
||||
'handler' => 'views_handler_relationship',
|
||||
'label' => t('Expense -> Ticket'),
|
||||
),
|
||||
);
|
||||
|
||||
$data['stormexpense']['ticket_title'] = array(
|
||||
'title' => t('Ticket'),
|
||||
'help' => t('SuiteDesk Expense Ticket (title only)'),
|
||||
'field' => array(
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_string',
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_string',
|
||||
),
|
||||
);
|
||||
|
||||
$data['stormexpense']['provider_nid'] = array(
|
||||
'title' => t('Provider'),
|
||||
'help' => t('Expense -> Provider'),
|
||||
'relationship' => array(
|
||||
'base' => 'node',
|
||||
'field' => 'nid',
|
||||
'handler' => 'views_handler_relationship',
|
||||
'label' => t('Expense -> Provider'),
|
||||
),
|
||||
);
|
||||
|
||||
$data['stormexpense']['provider_title'] = array(
|
||||
'title' => t('Provider'),
|
||||
'help' => t('SuiteDesk Expense Provider (title only)'),
|
||||
'field' => array(
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_string',
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_string',
|
||||
),
|
||||
);
|
||||
|
||||
$data['stormexpense']['expensedate'] = array(
|
||||
'title' => t('Date'),
|
||||
'help' => t('SuiteDesk Expense Date'),
|
||||
'field' => array(
|
||||
'click sortable' => TRUE,
|
||||
'handler' => 'views_handler_field_date',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort_date',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_date',
|
||||
),
|
||||
);
|
||||
|
||||
$data['stormexpense']['amount'] = array(
|
||||
'title' => t('Amount'),
|
||||
'help' => t('SuiteDesk Expense Amount'),
|
||||
'field' => array(
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_numeric',
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_numeric',
|
||||
),
|
||||
);
|
||||
|
||||
$data['stormexpense']['tax'] = array(
|
||||
'title' => t('Tax'),
|
||||
'help' => t('SuiteDesk Expense Tax'),
|
||||
'field' => array(
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_numeric',
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_numeric',
|
||||
),
|
||||
);
|
||||
|
||||
$data['stormexpense']['total'] = array(
|
||||
'title' => t('Total'),
|
||||
'help' => t('SuiteDesk Expense Total'),
|
||||
'field' => array(
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_numeric',
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_numeric',
|
||||
),
|
||||
);
|
||||
|
||||
$data['stormexpense']['operation'] = array(
|
||||
'field' => array(
|
||||
'title' => t('Edit/Delete link'),
|
||||
'help' => t('Provide a simple link to edit and delete the node.'),
|
||||
'handler' => 'storm_handler_field_operation',
|
||||
'type' => 'stormexpense',
|
||||
),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
function stormexpense_views_handlers() {
|
||||
return array(
|
||||
'info' => array(
|
||||
'path' => drupal_get_path('module', 'storm'),
|
||||
),
|
||||
'handlers' => array(
|
||||
'storm_handler_filter_attributes_domain' => array(
|
||||
'parent' => 'views_handler_filter_in_operator',
|
||||
),
|
||||
'storm_handler_field_operation' => array(
|
||||
'parent' => 'views_handler_field_node_link',
|
||||
'path' => drupal_get_path('module', 'storm'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function stormexpense_date_api_fields($field) {
|
||||
$values = array(
|
||||
'sql_type' => DATE_UNIX,
|
||||
'tz_handling' => 'site',
|
||||
'timezone_field' => '',
|
||||
'offset_field' => '',
|
||||
'related_fields' => array(),
|
||||
'granularity' => array('year', 'month', 'day'),
|
||||
);
|
||||
|
||||
switch ($field) {
|
||||
case 'stormexpense.expensedate':
|
||||
return $values;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function stormexpense_date_api_tables() {
|
||||
return array('stormexpense');
|
||||
}
|
||||
|
Reference in a new issue