/**
  * Create a new contract tied to the composite provided in the composite_id parameter
  */
 public function add_from_composite()
 {
     $contract = new rental_contract();
     $contract->set_location_id(phpgw::get_var('responsibility_id'));
     if ($contract->has_permission(PHPGW_ACL_EDIT)) {
         $so_contract = rental_socontract::get_instance();
         $db_contract = $so_contract->get_db();
         $db_contract->transaction_begin();
         if ($so_contract->store($contract)) {
             // Add that composite to the new contract
             $success = $so_contract->add_composite($contract->get_id(), phpgw::get_var('id'));
             if ($success) {
                 $db_contract->transaction_commit();
                 $comp_name = rental_socomposite::get_instance()->get_single(phpgw::get_var('id'))->get_name();
                 $message = lang('messages_new_contract_from_composite') . ' ' . $comp_name;
                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uicontract.edit', 'id' => $contract->get_id(), 'message' => $message));
             } else {
                 $db_contract->transaction_abort();
                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uicontract.edit', 'id' => $contract->get_id(), 'message' => lang('messages_form_error')));
             }
         } else {
             $db_contract->transaction_abort();
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uicontract.edit', 'id' => $contract->get_id(), 'message' => lang('messages_form_error')));
         }
     }
     // If no executive officer
     $this->render('permission_denied.php', array('error' => lang('permission_denied_new_contract')));
 }
 /**
  * Create a new contract tied to the composite provided in the composite_id parameter
  */
 public function add_from_composite()
 {
     $contract = new rental_contract();
     $contract->set_location_id(phpgw::get_var('responsibility_id'));
     $contract->set_account_in(rental_socontract::get_instance()->get_default_account($contract->get_location_id(), true));
     $contract->set_account_out(rental_socontract::get_instance()->get_default_account($contract->get_location_id(), false));
     $contract->set_executive_officer_id($GLOBALS['phpgw_info']['user']['account_id']);
     $config = CreateObject('phpgwapi.config', 'rental');
     $config->read();
     $default_billing_term = $config->config_data['default_billing_term'];
     $contract->set_term_id($default_billing_term);
     $units = rental_socomposite::get_instance()->get_single(phpgw::get_var('id'))->get_units();
     $location_code = $units[0]->get_location()->get_location_code();
     $args = array('acl_location' => '.contract', 'location_code' => $location_code, 'contract' => &$contract);
     $hook_helper = CreateObject('rental.hook_helper');
     $hook_helper->add_contract_from_composite($args);
     //		_debug_array($contract); die();
     if ($contract->has_permission(PHPGW_ACL_EDIT)) {
         $so_contract = rental_socontract::get_instance();
         $db_contract = $so_contract->get_db();
         $db_contract->transaction_begin();
         if ($so_contract->store($contract)) {
             // Add standard price items to contract
             if ($contract->get_location_id() && ($this->isExecutiveOfficer() || $this->isAdministrator())) {
                 $so_price_item = rental_soprice_item::get_instance();
                 //get default price items for location_id
                 $default_price_items = $so_contract->get_default_price_items($contract->get_location_id());
                 foreach ($default_price_items as $price_item_id) {
                     $so_price_item->add_price_item($contract->get_id(), $price_item_id);
                 }
             }
             // Add that composite to the new contract
             $success = $so_contract->add_composite($contract->get_id(), phpgw::get_var('id'));
             if ($success) {
                 $db_contract->transaction_commit();
                 $comp_name = rental_socomposite::get_instance()->get_single(phpgw::get_var('id'))->get_name();
                 $message = lang('messages_new_contract_from_composite') . ' ' . $comp_name;
                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uicontract.edit', 'id' => $contract->get_id(), 'message' => $message));
             } else {
                 $db_contract->transaction_abort();
                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uicontract.edit', 'id' => $contract->get_id(), 'message' => lang('messages_form_error')));
             }
         } else {
             $db_contract->transaction_abort();
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'rental.uicontract.edit', 'id' => $contract->get_id(), 'message' => lang('messages_form_error')));
         }
     }
     // If no executive officer
     $this->render('permission_denied.php', array('error' => lang('permission_denied_new_contract')));
 }