コード例 #1
0
ファイル: dataTest.php プロジェクト: nemein/openpsa
 public function testCRUD()
 {
     midcom::get('auth')->request_sudo('org.openpsa.invoices');
     $data = new org_openpsa_invoices_billing_data_dba();
     $data->linkGuid = self::$_contact->guid;
     $data->useContactAddress = true;
     $stat = $data->create();
     $this->assertTrue($stat, midcom_connection::get_error_string());
     $this->register_object($data);
     $parent = $data->get_parent();
     $this->assertEquals($parent->guid, self::$_contact->guid);
     self::$_contact->refresh();
     $this->assertEquals(self::$_contact->street, $data->street);
     $data->vat = 12;
     $data->due = 12;
     $stat = $data->update();
     $this->assertTrue($stat);
     self::$_contact->refresh();
     $invoice = new org_openpsa_invoices_invoice_dba();
     $invoice->customerContact = self::$_contact->id;
     $invoice_data = $invoice->get_billing_data();
     $this->assertEquals($data->guid, $invoice_data->guid);
     $this->assertEquals($data->vat, $invoice->get_default('vat'));
     $this->assertEquals($data->due, $invoice->get_default('due'));
     $stat = $data->delete();
     $this->assertTrue($stat);
     midcom::get('auth')->drop_sudo();
 }
コード例 #2
0
ファイル: billingdata.php プロジェクト: nemein/openpsa
 /**
  * Datamanager callback
  */
 public function &dm2_create_callback(&$datamanager)
 {
     $billing_data = new org_openpsa_invoices_billing_data_dba();
     $billing_data->linkGuid = $this->_linked_object->guid;
     if (!$billing_data->create()) {
         debug_print_r('We operated on this object:', $billing_data);
         throw new midcom_error("Failed to create a new billing_data. Error: " . midcom_connection::get_error_string());
     }
     return $billing_data;
 }
コード例 #3
0
ファイル: interfaces.php プロジェクト: nemein/openpsa
 /**
  * Handle deletes of "parent" objects
  *
  * @param mixed $object The object triggering the watch
  */
 public function _on_watched_dba_delete($object)
 {
     midcom::get('auth')->request_sudo();
     $qb_billing_data = org_openpsa_invoices_billing_data_dba::new_query_builder();
     $qb_billing_data->add_constraint('linkGuid', '=', $object->guid);
     $result = $qb_billing_data->execute();
     if (count($result) > 0) {
         foreach ($result as $billing_data) {
             debug_add("Delete billing data with guid:" . $billing_data->guid . " for object with guid:" . $object->guid);
             $billing_data->delete();
         }
     }
     midcom::get('auth')->drop_sudo();
 }
コード例 #4
0
ファイル: view.php プロジェクト: nemein/openpsa
 /**
  * Handler method for listing group members
  *
  * @param string $handler_id Name of the used handler
  * @param mixed $args Array containing the variable arguments passed to the handler
  * @param mixed &$data Data passed to the show method
  */
 public function _handler_view($handler_id, array $args, array &$data)
 {
     midcom::get('auth')->require_valid_user();
     // Get the requested group object
     $this->_group = new org_openpsa_contacts_group_dba($args[0]);
     $data['group'] = $this->_group;
     if ($this->_group->orgOpenpsaObtype < org_openpsa_contacts_group_dba::MYCONTACTS) {
         $this->_type = 'group';
         $data['group_tree'] = $this->_master->get_group_tree();
         $data['members_grid'] = new org_openpsa_widgets_grid('members_grid', 'json');
         org_openpsa_widgets_tree::add_head_elements();
     } else {
         $this->_type = 'organization';
         $root_group = org_openpsa_contacts_interface::find_root_group();
         if ($this->_group->owner != $root_group->id) {
             $data['parent_group'] = $this->_group->get_parent();
         } else {
             $data['parent_group'] = false;
         }
         //pass billing-data if invoices is installed
         if (midcom::get('componentloader')->is_installed('org.openpsa.invoices')) {
             $qb_billing_data = org_openpsa_invoices_billing_data_dba::new_query_builder();
             $qb_billing_data->add_constraint('linkGuid', '=', $this->_group->guid);
             $billing_data = $qb_billing_data->execute();
             if (count($billing_data) > 0) {
                 $this->_request_data['billing_data'] = $billing_data[0];
             }
         }
         // This handler uses Ajax, include the handler javascripts
         midcom::get('head')->add_jsfile(MIDCOM_STATIC_URL . "/org.openpsa.helpers/ajaxutils.js");
         org_openpsa_widgets_ui::enable_ui_tab();
     }
     $data['view'] = midcom_helper_datamanager2_handler::get_view($this, $this->_group);
     // Add toolbar items
     $this->_populate_toolbar();
     $this->bind_view_to_object($this->_group);
     midcom::get('head')->set_pagetitle($this->_group->official);
     org_openpsa_contacts_viewer::add_breadcrumb_path_for_group($this->_group, $this);
 }
コード例 #5
0
ファイル: view.php プロジェクト: nemein/openpsa
 /**
  * Helper function that populates the toolbar with the necessary items
  *
  * @param string $handler_id the ID of the current handler
  */
 private function _populate_toolbar($handler_id)
 {
     $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "person/edit/{$this->_contact->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('edit'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/edit.png', MIDCOM_TOOLBAR_ENABLED => $this->_contact->can_do('midgard:update'), MIDCOM_TOOLBAR_ACCESSKEY => 'e'));
     $siteconfig = org_openpsa_core_siteconfig::get_instance();
     $invoices_url = $siteconfig->get_node_full_url('org.openpsa.invoices');
     $user_url = $siteconfig->get_node_full_url('org.openpsa.user');
     if ($invoices_url && midcom::get('auth')->can_user_do('midgard:create', null, 'org_openpsa_invoices_invoice_dba')) {
         $billing_data_url = "create/" . $this->_contact->guid . "/";
         $qb_billing_data = org_openpsa_invoices_billing_data_dba::new_query_builder();
         $qb_billing_data->add_constraint('linkGuid', '=', $this->_contact->guid);
         $billing_data = $qb_billing_data->execute();
         if (count($billing_data) > 0) {
             $billing_data_url = $billing_data[0]->guid . "/";
         }
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => $invoices_url . "billingdata/" . $billing_data_url, MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('edit billingdata'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/edit.png', MIDCOM_TOOLBAR_ENABLED => $this->_contact->can_do('midgard:update')));
     }
     if ($user_url && (midcom_connection::get_user() == $this->_contact->id || midcom::get('auth')->can_user_do('org.openpsa.user:access', null, 'org_openpsa_user_interface'))) {
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => $user_url . "view/{$this->_contact->guid}/", MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('user management', 'org.openpsa.user'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/properties.png'));
     }
     $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "person/delete/{$this->_contact->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('delete'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/trash.png', MIDCOM_TOOLBAR_ENABLED => $this->_contact->can_do('midgard:delete'), MIDCOM_TOOLBAR_ACCESSKEY => 'd'));
     $mycontacts = new org_openpsa_contacts_mycontacts();
     if ($mycontacts->is_member($this->_contact->guid)) {
         // We're buddies, show remove button
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "mycontacts/remove/{$this->_contact->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('remove from my contacts'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/trash.png'));
     } else {
         // We're not buddies, show add button
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "mycontacts/add/{$this->_contact->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('add to my contacts'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/stock_person.png'));
     }
 }
コード例 #6
0
ファイル: invoice.php プロジェクト: nemein/openpsa
 /**
  * helper function to get the billing data for given contact if any
  * @param string $dba_class
  * @param mixed $contact_id
  */
 private function _get_billing_data($dba_class, $contact_id)
 {
     if ($contact_id == 0) {
         return false;
     }
     try {
         $contact = call_user_func(array($dba_class, 'get_cached'), $contact_id);
         $qb = org_openpsa_invoices_billing_data_dba::new_query_builder();
         $qb->add_constraint('linkGuid', '=', $contact->guid);
         $billing_data = $qb->execute();
         if (count($billing_data) == 0) {
             return false;
         }
         // call set_address so the billing_data contains address of the linked contact
         // if the property useContactAddress is set
         $billing_data[0]->set_address();
         return $billing_data[0];
     } catch (midcom_error $e) {
         $e->log();
     }
 }
コード例 #7
0
ファイル: list.php プロジェクト: nemein/openpsa
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  */
 public function _handler_customer($handler_id, array $args, array &$data)
 {
     midcom::get('auth')->require_valid_user();
     try {
         $this->_customer = new org_openpsa_contacts_group_dba($args[0]);
     } catch (midcom_error $e) {
         $this->_customer = new org_openpsa_contacts_person_dba($args[0]);
     }
     $data['customer'] = $this->_customer;
     if (midcom::get('auth')->can_user_do('midgard:create', null, 'org_openpsa_invoices_invoice_dba')) {
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "invoice/new/{$this->_request_data['customer']->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('create invoice'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/printer.png'));
         $billing_data_url = "create/" . $this->_customer->guid . "/";
         $qb_billing_data = org_openpsa_invoices_billing_data_dba::new_query_builder();
         $qb_billing_data->add_constraint('linkGuid', '=', $this->_customer->guid);
         $billing_data = $qb_billing_data->execute();
         if (count($billing_data) > 0) {
             $billing_data_url = $billing_data[0]->guid . "/";
         }
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => "billingdata/" . $billing_data_url, MIDCOM_TOOLBAR_LABEL => midcom::get('i18n')->get_string('edit billingdata', 'org.openpsa.contacts'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/edit.png', MIDCOM_TOOLBAR_ENABLED => $this->_customer->can_do('midgard:update')));
     }
     if ($this->_request_data['contacts_url']) {
         $this->_view_toolbar->add_item(array(MIDCOM_TOOLBAR_URL => $this->_request_data['contacts_url'] . (is_a($this->_customer, 'org_openpsa_contacts_group_dba') ? 'group' : 'person') . "/{$this->_request_data['customer']->guid}/", MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('go to customer'), MIDCOM_TOOLBAR_ICON => 'stock-icons/16x16/jump-to.png'));
     }
     $title = sprintf($this->_l10n->get('all invoices for customer %s'), $this->_request_data['customer']->get_label());
     midcom::get('head')->set_pagetitle($title);
     $this->add_breadcrumb("", $title);
 }