[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [13373] rental: insert default values in new contract
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [13373] rental: insert default values in new contracts |
Date: |
Sun, 07 Jun 2015 17:45:29 +0000 |
Revision: 13373
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=13373
Author: sigurdne
Date: 2015-06-07 17:45:23 +0000 (Sun, 07 Jun 2015)
Log Message:
-----------
rental: insert default values in new contracts
Modified Paths:
--------------
trunk/rental/inc/class.menu.inc.php
trunk/rental/inc/class.socontract_price_item.inc.php
trunk/rental/inc/class.uicontract.inc.php
trunk/rental/inc/hook_config.inc.php
trunk/rental/inc/model/class.contract.inc.php
trunk/rental/setup/default_records.inc.php
trunk/rental/setup/setup.inc.php
trunk/rental/setup/tables_update.inc.php
trunk/rental/templates/base/config.tpl
trunk/rental/templates/base/contract.php
Added Paths:
-----------
trunk/rental/inc/custom/
trunk/rental/inc/custom/default/
trunk/rental/inc/custom/default/NLSH_add_contract_from_composite.php
Modified: trunk/rental/inc/class.menu.inc.php
===================================================================
--- trunk/rental/inc/class.menu.inc.php 2015-06-05 16:28:41 UTC (rev 13372)
+++ trunk/rental/inc/class.menu.inc.php 2015-06-07 17:45:23 UTC (rev 13373)
@@ -166,7 +166,12 @@
'text' => lang('import_adjustments'),
'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'rental.uiimport.import_regulations', 'appname' => 'rental') ),
'image' => array('rental',
'document-save')
- )
+ ),
+ 'custom_functions' => array
+ (
+ 'text' => lang('custom functions'),
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'admin.ui_custom.list_custom_function','appname' => 'rental', 'location' =>
'.contract', 'menu_selection' => 'admin::rental::custom_functions') )
+ ),
);
$menus['folders'] =
phpgwapi_menu::get_categories('bergen');
Modified: trunk/rental/inc/class.socontract_price_item.inc.php
===================================================================
--- trunk/rental/inc/class.socontract_price_item.inc.php 2015-06-05
16:28:41 UTC (rev 13372)
+++ trunk/rental/inc/class.socontract_price_item.inc.php 2015-06-07
17:45:23 UTC (rev 13373)
@@ -298,7 +298,8 @@
public function get_total_price($contract_id){
$ts_query = strtotime(date('Y-m-d')); // timestamp for query
(today)
//$this->db->query("SELECT sum(rcpi.total_price::numeric) AS
sum_total FROM rental_contract_price_item rcpi, rental_price_item rpi WHERE
rpi.id = rcpi.price_item_id AND NOT rpi.is_one_time AND
rcpi.contract_id={$contract_id} AND ((rcpi.date_start <= {$ts_query} AND
rcpi.date_end >= {$ts_query}) OR (rcpi.date_start <= {$ts_query} AND
(rcpi.date_end is null OR rcpi.date_end = 0)) OR (rcpi.date_start is null AND
(rcpi.date_end >= {$ts_query} OR rcpi.date_end is null)))");
- $this->db->query("SELECT sum(total_price::numeric) AS sum_total
FROM rental_contract_price_item WHERE NOT is_one_time AND
contract_id={$contract_id}");
+// $this->db->query("SELECT sum(total_price::numeric) AS sum_total
FROM rental_contract_price_item WHERE NOT is_one_time AND
contract_id={$contract_id}");
+ $this->db->query("SELECT sum(total_price::numeric) AS sum_total
FROM rental_contract_price_item WHERE contract_id={$contract_id} AND (NOT
is_one_time OR NOT is_billed)");
if($this->db->next_record()){
$total_price = $this->db->f('sum_total');
return $total_price;
Modified: trunk/rental/inc/class.uicontract.inc.php
===================================================================
--- trunk/rental/inc/class.uicontract.inc.php 2015-06-05 16:28:41 UTC (rev
13372)
+++ trunk/rental/inc/class.uicontract.inc.php 2015-06-07 17:45:23 UTC (rev
13373)
@@ -677,6 +677,30 @@
{
$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));
+
+ $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();
Added: trunk/rental/inc/custom/default/NLSH_add_contract_from_composite.php
===================================================================
--- trunk/rental/inc/custom/default/NLSH_add_contract_from_composite.php
(rev 0)
+++ trunk/rental/inc/custom/default/NLSH_add_contract_from_composite.php
2015-06-07 17:45:23 UTC (rev 13373)
@@ -0,0 +1,50 @@
+<?php
+ /*
+ * This file will only work for the implementation of NLSH
+ */
+
+ /**
+ * Intended for custom configuration on contracts.
+ *
+ * @author Sigurd Nes <address@hidden>
+ */
+ class rental_NLSH_add_contract_from_composite
+ {
+ function __construct()
+ {
+ }
+
+ /**
+ * Do your magic
+ * @param array $data
+ */
+ function validate(&$data)
+ {
+ $contract = $data['contract'];
+ $location_arr = explode('-', $data['location_code']);
+ $loc1 = $location_arr[0];
+
+ if($loc1 > 8006 && $loc1 < 8100)
+ {
+ $responsibility_id = 8018;
+ }
+ else if($loc1 > 8499 && $loc1 < 8600)
+ {
+ $responsibility_id = 3015;
+ }
+ else if($loc1 > 8599 && $loc1 < 8700)
+ {
+ $responsibility_id = 4036;
+ }
+
+ $contract->set_responsibility_id($responsibility_id);
+ return;
+
+ }
+ }
+
+ $process = new rental_NLSH_add_contract_from_composite($data);
+ if($_error = $process->validate($data))
+ {
+ return $receipt['error'][]=array('msg'=>$_error);
+ }
Modified: trunk/rental/inc/hook_config.inc.php
===================================================================
--- trunk/rental/inc/hook_config.inc.php 2015-06-05 16:28:41 UTC (rev
13372)
+++ trunk/rental/inc/hook_config.inc.php 2015-06-07 17:45:23 UTC (rev
13373)
@@ -212,3 +212,34 @@
}
return $out;
}
+
+ /**
+ * Get HTML radiobox with default billing term for new contracts
+ *
+ * @param $config
+ * @return string HTML checkboxes to be placed in a table
+ */
+ function default_billing_term($config)
+ {
+ phpgw::import_class('rental.sobilling');
+ $billing_terms =
rental_sobilling::get_instance()->get_billing_terms();
+ $term_assigned = isset($config['default_billing_term']) ?
$config['default_billing_term'] : array();
+ $lang_none = lang('none');
+ $out = "<tr><td><input type=\"radio\"
name=\"newsettings[default_billing_term]\"
value=\"\"><label>{$lang_none}</label></td></tr>";
+
+ foreach ( $billing_terms as $term_id => $_label)
+ {
+ $label =
$GLOBALS['phpgw']->translation->translate($_label, array(), false, 'rental');
+ $checked = '';
+ if ($term_id == $term_assigned)
+ {
+ $checked = ' checked';
+ }
+
+ $out .= <<<HTML
+ <tr><td><input type="radio"
name="newsettings[default_billing_term]" value="{$term_id}"
{$checked}><label>{$label}</label></td></tr>
+HTML;
+ }
+ return $out;
+ }
+
Modified: trunk/rental/inc/model/class.contract.inc.php
===================================================================
--- trunk/rental/inc/model/class.contract.inc.php 2015-06-05 16:28:41 UTC
(rev 13372)
+++ trunk/rental/inc/model/class.contract.inc.php 2015-06-07 17:45:23 UTC
(rev 13373)
@@ -256,7 +256,11 @@
$this->service_id = $service_id;
}
- public function get_service_id() { return $this->service_id; }
+ public function get_service_id()
+ {
+ //Add magic
+ return $this->service_id;
+ }
public function set_responsibility_id($responsibility_id)
{
Modified: trunk/rental/setup/default_records.inc.php
===================================================================
--- trunk/rental/setup/default_records.inc.php 2015-06-05 16:28:41 UTC (rev
13372)
+++ trunk/rental/setup/default_records.inc.php 2015-06-07 17:45:23 UTC (rev
13373)
@@ -34,7 +34,8 @@
//Create groups, users, add users to groups and set preferences
-$GLOBALS['phpgw']->locations->add('.', 'Root',
'rental',false);
+$GLOBALS['phpgw']->locations->add('.', 'Root',
'rental',false);
+$GLOBALS['phpgw']->locations->add('.contract', 'Contract','rental',
$allow_grant = false, $custom_tbl = false, $c_function = true);
$GLOBALS['phpgw']->locations->add('.ORG', 'Locations for
organisational units', 'rental',false);
$GLOBALS['phpgw']->locations->add('.ORG.BK', 'Organisational units
in Bergen Kommune', 'rental',false);
Modified: trunk/rental/setup/setup.inc.php
===================================================================
--- trunk/rental/setup/setup.inc.php 2015-06-05 16:28:41 UTC (rev 13372)
+++ trunk/rental/setup/setup.inc.php 2015-06-07 17:45:23 UTC (rev 13373)
@@ -1,6 +1,6 @@
<?php
$setup_info['rental']['name'] = 'rental'; // Module
identifier
- $setup_info['rental']['version'] = '0.1.0.20'; // Current module
version
+ $setup_info['rental']['version'] = '0.1.0.21'; // Current module
version
$setup_info['rental']['app_order'] = 51; // (?)
$setup_info['rental']['tables'] = array(
'rental_party', // All
contract participants, tenants etc.
@@ -55,5 +55,4 @@
'config',
'menu' => 'rental.menu.get_menu',
'settings'
- );
-?>
+ );
\ No newline at end of file
Modified: trunk/rental/setup/tables_update.inc.php
===================================================================
--- trunk/rental/setup/tables_update.inc.php 2015-06-05 16:28:41 UTC (rev
13372)
+++ trunk/rental/setup/tables_update.inc.php 2015-06-07 17:45:23 UTC (rev
13373)
@@ -8,52 +8,52 @@
function rental_upgrade0_0_27()
{
$GLOBALS['phpgw_setup']->oProc->AddColumn('rental_party','org_enhet_id', array
('type' => 'int','precision' => 8, 'nullable' => true));
-
+
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0';
return $GLOBALS['setup_info']['rental']['currentver'];
}
-
+
$test[] = '0.1.0';
function rental_upgrade0_1_0()
{
$GLOBALS['phpgw_setup']->oProc->AlterColumn('rental_contract','adjustment_share',array(
- 'type' => 'int',
+ 'type' => 'int',
'precision' => '4',
'nullable' => true,
'default' => 100
));
-
+
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.1';
return $GLOBALS['setup_info']['rental']['currentver'];
}
-
+
$test[] = '0.1.0.1';
function rental_upgrade0_1_0_1()
{
$GLOBALS['phpgw_setup']->oProc->AddColumn('rental_adjustment','adjustment_type',
array('type' => 'varchar','precision' => '255','nullable' => true));
-
+
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.2';
return $GLOBALS['setup_info']['rental']['currentver'];
}
-
+
$test[] = '0.1.0.2';
function rental_upgrade0_1_0_2()
{
$GLOBALS['phpgw_setup']->oProc->AddColumn('rental_adjustment','is_executed',
array('type' => 'bool','nullable' => false,'default' => 'false'));
-
+
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.3';
return $GLOBALS['setup_info']['rental']['currentver'];
}
-
+
$test[] = '0.1.0.3';
function rental_upgrade0_1_0_3()
{
$GLOBALS['phpgw_setup']->oProc->AddColumn('rental_contract','publish_comment',
array('type' => 'bool','nullable' => true,'default' => 'false'));
-
+
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.4';
return $GLOBALS['setup_info']['rental']['currentver'];
}
-
+
$test[] = '0.1.0.4';
function rental_upgrade0_1_0_4()
{
@@ -64,52 +64,52 @@
'rental.soadjustment.run_adjustments',
null
);
-
+
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.5';
return $GLOBALS['setup_info']['rental']['currentver'];
}
-
+
$test[] = '0.1.0.5';
function rental_upgrade0_1_0_5()
{
$GLOBALS['phpgw_setup']->oProc->AlterColumn('rental_notification_workbench','notification_id',array(
- 'type' => 'int',
+ 'type' => 'int',
'precision' => '4',
'nullable' => true
));
-
+
$GLOBALS['phpgw_setup']->oProc->AddColumn('rental_notification_workbench','workbench_message',
array('type' => 'text'));
-
+
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.6';
return $GLOBALS['setup_info']['rental']['currentver'];
}
-
+
$test[] = '0.1.0.6';
function rental_upgrade0_1_0_6()
{
$GLOBALS['phpgw_setup']->oProc->AddColumn('rental_invoice','serial_number',array(
- 'type' => 'int',
+ 'type' => 'int',
'precision' => '8',
'nullable' => true
));
-
+
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.7';
return $GLOBALS['setup_info']['rental']['currentver'];
}
-
+
$test[] = '0.1.0.7';
function rental_upgrade0_1_0_7()
{
$GLOBALS['phpgw_setup']->oProc->AddColumn('rental_price_item','standard',array(
- 'type' => 'bool',
+ 'type' => 'bool',
'nullable' => true,
'default' => 'false'
));
-
+
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.8';
return $GLOBALS['setup_info']['rental']['currentver'];
}
-
+
$test[] = '0.1.0.8';
function rental_upgrade0_1_0_8()
{
@@ -118,16 +118,16 @@
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.9';
return $GLOBALS['setup_info']['rental']['currentver'];
}
-
+
$test[] = '0.1.0.9';
function rental_upgrade0_1_0_9()
{
-
-
+
+
$sql = 'SELECT config_name,config_value FROM phpgw_config'
. " WHERE config_name = 'files_dir'"
. " OR config_name = 'file_repository'";
-
+
$GLOBALS['phpgw_setup']->oProc->query($sql, __LINE__, __FILE__);
while ( $GLOBALS['phpgw_setup']->oProc->next_record() )
{
@@ -135,22 +135,22 @@
}
$GLOBALS['phpgw']->db = & $GLOBALS['phpgw_setup']->oProc->m_odb;
$acl = CreateObject('phpgwapi.acl');
-
+
$admins = $acl->get_ids_for_location('run', 1, 'admin');
$GLOBALS['phpgw_info']['user']['account_id'] = $admins[0];
-
+
//used in vfs
define('PHPGW_ACL_READ',1);
define('PHPGW_ACL_ADD',2);
define('PHPGW_ACL_EDIT',4);
define('PHPGW_ACL_DELETE',8);
-
+
$GLOBALS['phpgw']->session =
createObject('phpgwapi.sessions');
-
+
//Prepare paths
$vfs = CreateObject('phpgwapi.vfs');
$vfs->override_acl = 1;
-
+
$path = "/rental";
$dir = array('string' => $path, RELATIVE_NONE);
if(!$vfs->file_exists($dir)){
@@ -159,7 +159,7 @@
return;
}
}
-
+
$path .= "/billings";
$dir = array('string' => $path, RELATIVE_NONE);
if(!$vfs->file_exists($dir)){
@@ -168,17 +168,17 @@
return;
}
}
-
+
$sql = "SELECT id, export_data FROM rental_billing";
$db = clone $GLOBALS['phpgw']->db;
$result = $db->query($sql, __LINE__, __FILE__);
-
+
while($db->next_record())
{
$id = $db->f('id',true);
$export_data = $db->f('export_data','string');
$file_path = $path."/{$id}";
- if($export_data != ""){
+ if($export_data != ""){
$result = $vfs->write
(
array
@@ -190,7 +190,7 @@
);
}
}
-
+
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.10';
return $GLOBALS['setup_info']['rental']['currentver'];
}
@@ -203,17 +203,17 @@
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.11';
return $GLOBALS['setup_info']['rental']['currentver'];
}
-
+
$test[] = '0.1.0.11';
function rental_upgrade0_1_0_11()
{
// Add adjustment year column
$GLOBALS['phpgw_setup']->oProc->AddColumn('rental_adjustment',
'year', array(
- 'type' => 'int',
+ 'type' => 'int',
'nullable' => true,
'precision' => '4'
));
-
+
// Update year column to match the adjustment_date of all
existing adjustments
$so = CreateObject('rental.soadjustment');
foreach ($so->get(0, NULL, NULL, true, NULL, NULL, NULL) as
$adjustment) {
@@ -221,11 +221,11 @@
$adjustment->set_year($year);
$so->store($adjustment);
}
-
+
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.12';
return $GLOBALS['setup_info']['rental']['currentver'];
}
-
+
$test[] = '0.1.0.12';
function rental_upgrade0_1_0_12()
{
@@ -236,11 +236,11 @@
'rental.uiparty.syncronize_party_name',
null
);
-
+
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.13';
return $GLOBALS['setup_info']['rental']['currentver'];
}
-
+
$test[] = '0.1.0.13';
function rental_upgrade0_1_0_13()
{
@@ -249,21 +249,21 @@
'precision' => 4,
'nullable' => 'True'
));
-
+
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.14';
return $GLOBALS['setup_info']['rental']['currentver'];
}
-
+
$test[] = '0.1.0.14';
function rental_upgrade0_1_0_14()
{
// Add unit_leader column
$GLOBALS['phpgw_setup']->oProc->AddColumn('rental_party',
'unit_leader', array(
- 'type' => 'varchar',
+ 'type' => 'varchar',
'nullable' => true,
'precision' => '255'
));
-
+
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.15';
return $GLOBALS['setup_info']['rental']['currentver'];
}
@@ -282,18 +282,18 @@
'rental.soparty.syncronize_party_name',
null
);
-
+
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.16';
return $GLOBALS['setup_info']['rental']['currentver'];
}
-
- $test[] = '0.1.0.16';
+
+ $test[] = '0.1.0.16';
function rental_upgrade0_1_0_16()
- {
+ {
$sql = "INSERT INTO rental_billing_term (title, months) VALUES
('free_of_charge','0')";
$db = clone $GLOBALS['phpgw']->db;
$result = $db->query($sql, __LINE__, __FILE__);
-
+
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.17';
return $GLOBALS['setup_info']['rental']['currentver'];
}
@@ -315,7 +315,7 @@
'fd' => array(
'id' => array('type' =>
'int','precision' => '4','nullable' => false),
'name' => array('type' =>
'varchar','precision' => '255','nullable' => false),
- 'factor' => array('type' => 'decimal', 'precision' =>
'20','scale' => '2', 'nullable' => true),
+ 'factor' => array('type' => 'decimal',
'precision' => '20','scale' => '2', 'nullable' => true),
),
'pk' => array('id'),
'fk' => array(),
@@ -354,17 +354,25 @@
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.19';
return $GLOBALS['setup_info']['rental']['currentver'];
}
-
- $test[] = '0.1.0.19';
+
+ $test[] = '0.1.0.19';
function rental_upgrade0_1_0_19()
{
// Add unit_leader column
$GLOBALS['phpgw_setup']->oProc->AddColumn('rental_adjustment',
'extra_adjustment', array(
- 'type' => 'bool',
+ 'type' => 'bool',
'nullable' => true,
'default' => 'false'
));
-
+
$GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.20';
return $GLOBALS['setup_info']['rental']['currentver'];
}
+
+ $test[] = '0.1.0.20';
+ function rental_upgrade0_1_0_20()
+ {
+
$GLOBALS['phpgw']->locations->add('.contract','Contract','rental', $allow_grant
= false, $custom_tbl = false, $c_function = true);
+ $GLOBALS['setup_info']['rental']['currentver'] = '0.1.0.21';
+ return $GLOBALS['setup_info']['rental']['currentver'];
+ }
Modified: trunk/rental/templates/base/config.tpl
===================================================================
--- trunk/rental/templates/base/config.tpl 2015-06-05 16:28:41 UTC (rev
13372)
+++ trunk/rental/templates/base/config.tpl 2015-06-07 17:45:23 UTC (rev
13373)
@@ -169,6 +169,16 @@
</table>
</td>
</tr>
+ <tr class="row_on">
+ <td valign = 'top'>{lang_default_billing_term}:</td>
+ <td>
+ <!--to be able to blank the setting - need an
empty value-->
+ <!--input type = 'hidden'
name="newsettings[default_billing_term]" value=""-->
+ <table>
+ {hook_default_billing_term}
+ </table>
+ </td>
+ </tr>
<!-- END body -->
<!-- BEGIN footer -->
Modified: trunk/rental/templates/base/contract.php
===================================================================
--- trunk/rental/templates/base/contract.php 2015-06-05 16:28:41 UTC (rev
13372)
+++ trunk/rental/templates/base/contract.php 2015-06-07 17:45:23 UTC (rev
13373)
@@ -440,7 +440,11 @@
</dt>
<dd>
<?php
- $current_term_id =
$contract->get_term_id();
+ if(!$current_term_id =
$contract->get_term_id())
+ {
+ $current_term_id =
$config->config_data['default_billing_term'];
+ }
+
if ($editable)
{
?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [13373] rental: insert default values in new contracts,
Sigurd Nes <=