function _pminvoice_beforesave in Drupal PM (Project Management) 7
Prepares pminvoice for saving.
2 calls to _pminvoice_beforesave()
- pminvoice_insert in pminvoice/
pminvoice.module - Implements hook_insert().
- pminvoice_update in pminvoice/
pminvoice.module - Implements hook_update().
File
- pminvoice/
pminvoice.module, line 584 - 1: Hooks (help, perm, init, menu, theme, node_info) 2: Access functions 3: Load organization and project details 4: Invoice create / edit form 5: Invoice node manipulation functions 6: Admin settings 7: Views hook 8: Project Managementinvoiceitem…
Code
function _pminvoice_beforesave(&$node) {
// Allow use of comma when inputting numerical values - str_replace with period decimal
$node->amount = floatval(str_replace(',', '.', $node->amount));
$node->tax1 = floatval(str_replace(',', '.', $node->tax1));
$node->tax2 = floatval(str_replace(',', '.', $node->tax2));
$node->total = floatval(str_replace(',', '.', $node->total));
$node->totalcustomercurr = floatval(str_replace(',', '.', $node->totalcustomercurr));
$org_result = db_select('node', 'n')
->fields('n', array(
'title',
))
->condition('n.type', 'pmorganization')
->condition('n.nid', $node->organization_nid)
->execute();
$organization = $org_result
->fetchObject();
$node->organization_title = $organization->title;
if (isset($node->project_nid)) {
$pro_result = db_select('node', 'n')
->fields('n', array(
'title',
))
->condition('n.type', 'pmproject')
->condition('n.nid', $node->project_nid)
->execute();
$project = $pro_result
->fetchObject();
$node->project_title = isset($project->title) ? $project->title : NULL;
}
// Parse invoice items
// from linear to array/object combination
$j = 0;
$variable = 'items_' . $j . '_description';
while (isset($node->{$variable})) {
$node->items[$j]->description = $node->{$variable};
$variable = 'items_' . $j . '_amount';
$node->items[$j]->amount = str_replace(',', '.', $node->{$variable});
$variable = 'items_' . $j . '_tax1app';
$node->items[$j]->tax1app = $node->{$variable};
$variable = 'items_' . $j . '_tax1percent';
$node->items[$j]->tax1percent = $node->{$variable};
$variable = 'items_' . $j . '_tax2app';
$node->items[$j]->tax2app = $node->{$variable};
$variable = 'items_' . $j . '_tax2percent';
$node->items[$j]->tax2percent = $node->{$variable};
$variable = 'items_' . $j . '_weight';
$node->items[$j]->weight = isset($node->{$variable}) ? $node->{$variable} : $j;
$variable = 'items_' . $j . '_src_nid';
$node->items[$j]->src_nid = $node->{$variable};
$variable = 'items_' . $j . '_src_vid';
$node->items[$j]->src_vid = $node->{$variable};
// Update taxes
pm_taxation($node->items[$j]);
$j++;
$variable = 'items_' . $j . '_description';
}
}