You are here

function invoice_edit_item in Invoice 6

Same name and namespace in other branches
  1. 7 invoice_ajax.inc \invoice_edit_item()

Edit an invoice item

1 string reference to 'invoice_edit_item'
invoice_menu in ./invoice.module
Implementation of hook_menu()

File

./invoice_ajax.inc, line 245
Invoice module

Code

function invoice_edit_item() {
  $fv =& $_GET;
  $a_data = array();

  // Check user admin access for this invoice
  if (!_invoice_user_has_admin_access_to_invoice($fv['invoice_number'])) {
    $a_data['error'] = t('You are not the owner of this item id!');
    drupal_json($a_data);
    exit;
  }

  // Check if the item to delete exists
  $a_invoice = db_fetch_object(db_query("SELECT *, COUNT(*) AS count\n    FROM {invoice_items}\n    WHERE iid=%d AND invoice_id=%d GROUP BY iid", $fv['iid'], $fv['invoice_number']));
  if ($a_invoice->count == 0) {
    $a_data['error'] = t('This item id does not exist!');
  }
  else {
    $a_data['description'] = $a_invoice->description;
    $a_data['vat'] = $a_invoice->vat;
    $a_data['quantity'] = $a_invoice->quantity;
    $a_data['exunitcost'] = $a_invoice->unitcost;
    $a_data['incunitcost'] = $a_invoice->unitcost * _invoice_vat_percent_to_decimal(variable_get('invoice_vat', 0));
    $a_data['actionvalue'] = t('Save item');
  }
  drupal_json($a_data);
  exit;
}