You are here

function _pminvoice_aftersave in Drupal PM (Project Management) 7

Calculate sums for amount and taxes and save to database.

2 calls to _pminvoice_aftersave()
pminvoice_insert in pminvoice/pminvoice.module
Implements hook_insert().
pminvoice_update in pminvoice/pminvoice.module
Implements hook_update().

File

pminvoice/pminvoice.module, line 680
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_aftersave($node) {

  // Updates totals
  $query = db_select('pminvoice_items', 'sii');
  $query
    ->addExpression('sum(amount)', 'tamount');
  $query
    ->addExpression('sum(tax1)', 'ttax1');
  $query
    ->addExpression('sum(tax2)', 'ttax2');
  $query
    ->addExpression('sum(total)', 'ttotal');
  $query
    ->condition('invoice_vid', $node->vid);
  $result = $query
    ->execute();
  $t = $result
    ->fetchObject();
  $node->amount = $t->tamount;
  $node->tax1 = $t->ttax1;
  $node->tax2 = $t->ttax2;
  $node->total = $t->ttotal;
  if (!$node->totalcustomercurr) {
    $node->totalcustomercurr = $node->total;
  }
  db_update('pminvoice')
    ->fields(array(
    'amount' => $node->amount,
    'tax1' => $node->tax1,
    'tax2' => $node->tax2,
    'total' => $node->total,
    'totalcustomercurr' => $node->totalcustomercurr,
  ))
    ->condition('vid', $node->vid)
    ->execute();
}