Changeset 26292


Ignore:
Timestamp:
06/08/10 10:18:31 (7 years ago)
Author:
gudd
Message:

Added Watcher to delete billing_data along with the corresponding person/group.
Fixed error-notice in create-handler of group.
Divided billing_data handler in edit & create handler.
Refs #1808

Location:
branches/ragnaroek/midcom
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/ragnaroek/midcom/org.openpsa.contacts/handler/group/create.php

    r25741 r26292  
    9494        $this->_controller->callback_object =& $this;
    9595        $this->_controller->defaults =& $this->_defaults;
    96         org_openpsa_contacts_viewer::modify_schema_invoice_defaults($this->_controller);
     96
    9797        if (! $this->_controller->initialize())
    9898        {
  • branches/ragnaroek/midcom/org.openpsa.contacts/handler/group/view.php

    r26257 r26292  
    157157        );
    158158        //add button for editing billing data
    159         if($_MIDCOM->componentloader->is_installed('org.openpsa.invoices'))
     159        if (   $_MIDCOM->componentloader->is_installed('org.openpsa.invoices')
     160            && $_MIDCOM->auth->can_user_do('midgard:create', null, 'org_openpsa_invoices_invoice_dba'))
    160161        {
    161162            $siteconfig = org_openpsa_core_siteconfig::get_instance();
    162163            $invoices_url = $siteconfig->get_node_full_url('org.openpsa.invoices');
     164            $billing_data_url = "create/" . $this->_group->guid ."/";
     165            $qb_billing_data = org_openpsa_invoices_billing_data_dba::new_query_builder();
     166            $qb_billing_data->add_constraint('linkGuid' , '=' , $this->_group->guid);
     167            $billing_data = $qb_billing_data->execute();
     168            if(count($billing_data) > 0)
     169            {
     170                $billing_data_url = $billing_data[0]->guid . "/";
     171            }
     172
    163173            $this->_view_toolbar->add_item
    164174            (
    165175                array
    166176                (
    167                     MIDCOM_TOOLBAR_URL => $invoices_url."billingdata/{$this->_group->guid}/",
     177                    MIDCOM_TOOLBAR_URL => $invoices_url."billingdata/" . $billing_data_url,
    168178                    MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('edit billingdata'),
    169179                    MIDCOM_TOOLBAR_HELPTEXT => null,
  • branches/ragnaroek/midcom/org.openpsa.contacts/handler/person/view.php

    r26257 r26292  
    199199            )
    200200        );
    201         if($_MIDCOM->componentloader->is_installed('org.openpsa.invoices'))
    202         {
     201        if (   $_MIDCOM->componentloader->is_installed('org.openpsa.invoices')
     202            && $_MIDCOM->auth->can_user_do('midgard:create', null, 'org_openpsa_invoices_invoice_dba'))
     203        {
     204            $billing_data_url = "create/" . $this->_contact->guid ."/";
     205            $qb_billing_data = org_openpsa_invoices_billing_data_dba::new_query_builder();
     206            $qb_billing_data->add_constraint('linkGuid' , '=' , $this->_contact->guid);
     207            $billing_data = $qb_billing_data->execute();
     208            if(count($billing_data) > 0)
     209            {
     210                $billing_data_url = $billing_data[0]->guid . "/";
     211            }
    203212            $siteconfig = org_openpsa_core_siteconfig::get_instance();
    204213            $invoices_url = $siteconfig->get_node_full_url('org.openpsa.invoices');
     
    207216                array
    208217                (
    209                     MIDCOM_TOOLBAR_URL => $invoices_url."billingdata/{$this->_contact->guid}/",
     218                    MIDCOM_TOOLBAR_URL => $invoices_url."billingdata/" . $billing_data_url,
    210219                    MIDCOM_TOOLBAR_LABEL => $this->_l10n->get('edit billingdata'),
    211220                    MIDCOM_TOOLBAR_HELPTEXT => null,
  • branches/ragnaroek/midcom/org.openpsa.invoices/billing/data.php

    r26257 r26292  
    3030    {
    3131        return $_MIDCOM->dbfactory->get_cached(__CLASS__, $src);
     32    }
     33
     34    function get_parent_guid_uncached()
     35    {
     36        return $this->linkGuid;
    3237    }
    3338    /**
  • branches/ragnaroek/midcom/org.openpsa.invoices/config/manifest.inc

    r25413 r26292  
    88(
    99    'midcom_dba_classes.inc',
     10),
     11'watches' => array
     12(
     13    array
     14    (
     15        'classes' => array(
     16            'org_openpsa_contacts_person_dba',
     17            'org_openpsa_contacts_group_dba',
     18            ),
     19        'operations' => MIDCOM_OPERATION_DBA_DELETE,
     20    ),
    1021),
    1122'package.xml' => array
     
    4354(
    4455    'skip_cache_generation' => true,
    45 ),   
     56),
  • branches/ragnaroek/midcom/org.openpsa.invoices/handler/billingdata.php

    r26257 r26292  
    3939     private $_datamanager = null;
    4040     /**
    41      * contains schema for datamanger
     41     * contains schema for datamanager
    4242     */
    4343     private $_schemadb = null;
     
    5151    {
    5252        //get billing_data
    53         $qb_billing_data = org_openpsa_invoices_billing_data_dba::new_query_builder();
    54         $qb_billing_data->add_constraint('linkGuid' , '=' , $args[0]);
     53        $this->_billing_data = org_openpsa_invoices_billing_data_dba::get_cached($args[0]);
     54        $this->_linked_object = $_MIDCOM->dbfactory->get_object_by_guid($this->_billing_data->linkGuid);
     55
     56        $_MIDCOM->set_pagetitle($_MIDCOM->i18n->get_string('edit' , 'midcom') . " " . $this->_l10n->get("billing data"));
     57
     58        $this->_prepare_datamanager();
     59        $this->_load_controller();
     60        $this->_process_billing_form();
     61
     62        $_MIDCOM->enable_jquery();
     63        $_MIDCOM->add_link_head
     64        (
     65            array
     66            (
     67                'rel' => 'stylesheet',
     68                'type' => 'text/css',
     69                'href' => MIDCOM_STATIC_URL . "/org.openpsa.core/ui-elements.css",
     70            )
     71        );
     72
     73        $this->_update_breadcrumb();
     74
     75        // Add toolbar items
     76        org_openpsa_helpers::dm2_savecancel($this);
     77        $_MIDCOM->bind_view_to_object($this->_billing_data);
     78
     79        $this->_request_data['datamanager'] =& $this->_datamanager;
     80        $this->_request_data['controller'] =& $this->_controller;
     81
     82        return true;
     83    }
     84
     85    function _show_billingdata($handler_id, &$data)
     86    {
     87        midcom_show_style('show-billingdata');
     88    }
     89    /**
     90     * function to load libraries/schemas for datamanager
     91     */
     92    private function _prepare_datamanager()
     93    {
     94        $_MIDCOM->load_library('midcom.helper.datamanager2');
     95        $this->_schemadb = midcom_helper_datamanager2_schema::load_database($this->_config->get('schemadb_billing_data'));
     96
     97        $fields =& $this->_schemadb[$this->_schema]->fields;
     98        // Fill VAT select
     99        $vat_array = explode(',', $this->_config->get('vat_percentages'));
     100        if (   is_array($vat_array)
     101            && count($vat_array) > 0)
     102        {
     103            $vat_values = array();
     104            foreach ($vat_array as $vat)
     105            {
     106                $vat_values[$vat] = "{$vat}%";
     107            }
     108            $fields['vat']['type_config']['options'] = $vat_values;
     109        }
     110        $this->_datamanager = new midcom_helper_datamanager2_datamanager($this->_schemadb);
     111
     112        if (!$this->_datamanager)
     113        {
     114            $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "Datamanager could not be instantiated.");
     115            // This will exit.
     116        }
     117    }
     118
     119    /**
     120     * load controller for datamanager
     121     *
     122     * @access private
     123     */
     124    private function _load_controller()
     125    {
     126        if($this->_billing_data)
     127        {
     128            $this->_controller = midcom_helper_datamanager2_controller::create('simple');
     129        }
     130        else
     131        {
     132            $this->_controller = midcom_helper_datamanager2_controller::create('create');
     133        }
     134        $this->_controller->schemadb =& $this->_schemadb;
     135        $this->_controller->schemaname = $this->_schema;
     136        $this->_controller->callback_object =& $this;
     137        if($this->_billing_data)
     138        {
     139            $this->_controller->set_storage($this->_billing_data, $this->_schema);
     140        }
     141        if (! $this->_controller->initialize())
     142        {
     143            $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "Failed to initialize a DM2 create controller.");
     144            // This will exit.
     145        }
     146
     147        $dummy_invoice = new org_openpsa_invoices_invoice_dba();
     148        //set the defaults for vat & due to the schema
     149        $this->_controller->schemadb[$this->_schema]->fields['due']['default'] = $dummy_invoice->get_default_due();
     150        $this->_controller->schemadb[$this->_schema]->fields['vat']['default'] = $dummy_invoice->get_default_vat();
     151        unset($dummy_invoice);
     152    }
     153
     154    /**
     155     * Datamanager callback
     156     */
     157    function & dm2_create_callback(&$datamanager)
     158    {
     159        $billing_data = new org_openpsa_invoices_billing_data_dba();
     160        $billing_data->linkGuid = $this->_linked_object->guid;
     161        if (! $billing_data->create())
     162        {
     163            debug_push_class(__CLASS__, __FUNCTION__);
     164            debug_print_r('We operated on this object:', $billing_data);
     165            debug_pop();
     166            $_MIDCOM->generate_error(MIDCOM_ERRCRIT,
     167                "Failed to create a new billing_data, cannot continue. Error: " . midcom_application::get_error_string());
     168            // This will exit.
     169        }
     170
     171        return $billing_data;
     172    }
     173
     174    /**
     175     * helper to update the breadcrumb
     176     */
     177    private function _update_breadcrumb()
     178    {
     179        $ref = midcom_helper_reflector::get($this->_linked_object);
     180        $object_label = $ref->get_object_label($this->_linked_object);
     181
     182        $tmp[] = array
     183        (
     184            MIDCOM_NAV_URL => $_MIDCOM->permalinks->create_permalink($this->_linked_object->guid),
     185            MIDCOM_NAV_NAME => $object_label,
     186        );
     187        $tmp[] = array
     188        (
     189            MIDCOM_NAV_URL => '#',
     190            MIDCOM_NAV_NAME => $this->_l10n->get('billing data') . " : " . $object_label,
     191        );
     192        $_MIDCOM->set_custom_context_data('midcom.helper.nav.breadcrumb', $tmp);
     193    }
     194
     195    function _handler_create($handler_id, $args, &$data)
     196    {
     197        $_MIDCOM->auth->require_valid_user();
    55198
    56199        $this->_linked_object = $_MIDCOM->dbfactory->get_object_by_guid($args[0]);
     
    61204            debug_pop();
    62205        }
    63         $billing_data_result = $qb_billing_data->execute();
    64 
    65         //set pagetitle according to found billing_data
     206
    66207        $_MIDCOM->set_pagetitle(($_MIDCOM->i18n->get_string('create' , 'midcom') . " " . $this->_l10n->get("billing data")));
    67         //TODO: more than one result possible ?
    68         if(count($billing_data_result) > 0)
    69         {
    70             $this->_billing_data = $billing_data_result[0];
    71             $_MIDCOM->set_pagetitle($_MIDCOM->i18n->get_string('edit' , 'midcom') . " " . $this->_l10n->get("billing data"));
    72         }
    73208
    74209        $this->_prepare_datamanager();
    75210        $this->_load_controller();
    76211
     212        $this->_process_billing_form();
     213
     214        $_MIDCOM->enable_jquery();
     215        $_MIDCOM->add_link_head
     216        (
     217            array
     218            (
     219                'rel' => 'stylesheet',
     220                'type' => 'text/css',
     221                'href' => MIDCOM_STATIC_URL . "/org.openpsa.core/ui-elements.css",
     222            )
     223        );
     224
     225        $this->_update_breadcrumb();
     226
     227        // Add toolbar items
     228        org_openpsa_helpers::dm2_savecancel($this);
     229
     230
     231        $this->_request_data['datamanager'] =& $this->_datamanager;
     232        $this->_request_data['controller'] =& $this->_controller;
     233
     234        return true;
     235    }
     236
     237    function _show_create($handler_id, &$data)
     238    {
     239        midcom_show_style('show-billingdata');
     240    }
     241
     242    /**
     243     * helper function to process the form of the controller
     244     */
     245    private function _process_billing_form()
     246    {
    77247        switch ($this->_controller->process_form())
    78248        {
     
    96266                // This will exit.
    97267        }
    98 
    99         $_MIDCOM->add_link_head
    100         (
    101             array
    102             (
    103                 'rel' => 'stylesheet',
    104                 'type' => 'text/css',
    105                 'href' => MIDCOM_STATIC_URL . "/org.openpsa.core/ui-elements.css",
    106             )
    107         );
    108 
    109         $this->_update_breadcrumb();
    110 
    111         // Add toolbar items
    112         org_openpsa_helpers::dm2_savecancel($this);
    113 
    114         $this->_request_data['datamanager'] =& $this->_datamanager;
    115         $this->_request_data['controller'] =& $this->_controller;
    116 
    117         return true;
    118     }
    119 
    120     function _show_billingdata($handler_id, &$data)
    121     {
    122         midcom_show_style('show-billingdata');
    123     }
    124     /**
    125      * function to load libraries/schemas for datamanager
    126      */
    127     private function _prepare_datamanager()
    128     {
    129         $_MIDCOM->load_library('midcom.helper.datamanager2');
    130         $this->_schemadb = midcom_helper_datamanager2_schema::load_database($this->_config->get('schemadb_billing_data'));
    131 
    132         $fields =& $this->_schemadb[$this->_schema]->fields;
    133         // Fill VAT select
    134         $vat_array = explode(',', $this->_config->get('vat_percentages'));
    135         if (   is_array($vat_array)
    136             && count($vat_array) > 0)
    137         {
    138             $vat_values = array();
    139             foreach ($vat_array as $vat)
    140             {
    141                 $vat_values[$vat] = "{$vat}%";
    142             }
    143             $fields['vat']['type_config']['options'] = $vat_values;
    144         }
    145         $this->_datamanager = new midcom_helper_datamanager2_datamanager($this->_schemadb);
    146 
    147         if (!$this->_datamanager)
    148         {
    149             $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "Datamanager could not be instantiated.");
    150             // This will exit.
    151         }
    152     }
    153 
    154     /**
    155      * load controller for datamanager
    156      *
    157      * @access private
    158      */
    159     private function _load_controller()
    160     {
    161         if($this->_billing_data)
    162         {
    163             $this->_controller = midcom_helper_datamanager2_controller::create('simple');
    164         }
    165         else
    166         {
    167             $this->_controller = midcom_helper_datamanager2_controller::create('create');
    168         }
    169         $this->_controller->schemadb =& $this->_schemadb;
    170         $this->_controller->schemaname = $this->_schema;
    171         $this->_controller->callback_object =& $this;
    172         if($this->_billing_data)
    173         {
    174             $this->_controller->set_storage($this->_billing_data, $this->_schema);
    175         }
    176         if (! $this->_controller->initialize())
    177         {
    178             $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "Failed to initialize a DM2 create controller.");
    179             // This will exit.
    180         }
    181 
    182         $dummy_invoice = new org_openpsa_invoices_invoice_dba();
    183         //set the defaults for vat & due to the schema
    184         $this->_controller->schemadb[$this->_schema]->fields['due']['default'] = $dummy_invoice->get_default_due();
    185         $this->_controller->schemadb[$this->_schema]->fields['vat']['default'] = $dummy_invoice->get_default_vat();
    186         unset($dummy_invoice);
    187     }
    188 
    189     /**
    190      * Datamanager callback
    191      */
    192     function & dm2_create_callback(&$datamanager)
    193     {
    194         $billing_data = new org_openpsa_invoices_billing_data_dba();
    195         $billing_data->linkGuid = $this->_linked_object->guid;
    196         if (! $billing_data->create())
    197         {
    198             debug_push_class(__CLASS__, __FUNCTION__);
    199             debug_print_r('We operated on this object:', $billing_data);
    200             debug_pop();
    201             $_MIDCOM->generate_error(MIDCOM_ERRCRIT,
    202                 "Failed to create a new billing_data, cannot continue. Error: " . midcom_application::get_error_string());
    203             // This will exit.
    204         }
    205 
    206         return $billing_data;
    207     }
    208 
    209     /**
    210      * helper to update the breadcrumb
    211      */
    212     private function _update_breadcrumb()
    213     {
    214         $ref = midcom_helper_reflector::get($this->_linked_object);
    215         $object_label = $ref->get_object_label($this->_linked_object);
    216 
    217         $tmp[] = array
    218         (
    219             MIDCOM_NAV_URL => $_MIDCOM->permalinks->create_permalink($this->_linked_object->guid),
    220             MIDCOM_NAV_NAME => $object_label,
    221         );
    222         $tmp[] = array
    223         (
    224             MIDCOM_NAV_URL => '#',
    225             MIDCOM_NAV_NAME => $this->_l10n->get('billing data') . " : " . $object_label,
    226         );
    227         $_MIDCOM->set_custom_context_data('midcom.helper.nav.breadcrumb', $tmp);
    228     }
    229 
     268    }
    230269}
    231270?>
  • branches/ragnaroek/midcom/org.openpsa.invoices/midcom/interfaces.php

    r22915 r26292  
    4141        return "invoice/{$invoice->guid}/";
    4242    }
     43
     44    /**
     45     * Handle deletes of "parent" objects
     46     *
     47     * @param mixed $object The object triggering the watch
     48     */
     49    function _on_watched_dba_delete($object)
     50    {
     51        $_MIDCOM->auth->request_sudo();
     52        $qb_billing_data = org_openpsa_invoices_billing_data_dba::new_query_builder();
     53        $qb_billing_data->add_constraint('linkGuid' , '=' , $object->guid);
     54        $result = $qb_billing_data->execute();
     55        if (count($result) > 0 )
     56        {
     57            foreach ($result as $billing_data)
     58            {
     59                debug_push_class(__CLASS__, __FUNCTION__);
     60                debug_add("Delete billing data with guid:" . $billing_data->guid . " for object with guid:" . $object->guid);
     61                debug_pop();
     62                $billing_data->delete();
     63            }
     64        }
     65        $_MIDCOM->auth->drop_sudo();
     66    }
    4367}
    4468
  • branches/ragnaroek/midcom/org.openpsa.invoices/viewer.php

    r26257 r26292  
    126126            'variable_args' => 1,
    127127        );
    128         // Match /billingdata/GUID
    129         $this->_request_switch['invoice_data'] = array
     128        // Match /billingdata/create/<guid>
     129        $this->_request_switch['billing_data_create'] = array
     130        (
     131            'handler' => array('org_openpsa_invoices_handler_billingdata', 'create'),
     132            'fixed_args' => array('billingdata' , 'create'),
     133            'variable_args' => 1,
     134        );
     135        // Match /billingdata/<guid>
     136        $this->_request_switch['billing_data'] = array
    130137        (
    131138            'handler' => array('org_openpsa_invoices_handler_billingdata', 'billingdata'),
Note: See TracChangeset for help on using the changeset viewer.