[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [15566] rental: compute billing by monthly price type
From: |
sigurdne |
Subject: |
[Fmsystem-commits] [15566] rental: compute billing by monthly price type |
Date: |
Fri, 2 Sep 2016 11:28:34 +0000 (UTC) |
Revision: 15566
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=15566
Author: sigurdne
Date: 2016-09-02 11:28:34 +0000 (Fri, 02 Sep 2016)
Log Message:
-----------
rental: compute billing by monthly price type
Modified Paths:
--------------
trunk/rental/inc/class.socontract_price_item.inc.php
trunk/rental/inc/class.uibilling.inc.php
trunk/rental/inc/model/class.contract_price_item.inc.php
trunk/rental/inc/model/class.invoice.inc.php
trunk/rental/inc/model/class.invoice_price_item.inc.php
trunk/rental/inc/model/class.price_item.inc.php
Modified: trunk/rental/inc/class.socontract_price_item.inc.php
===================================================================
--- trunk/rental/inc/class.socontract_price_item.inc.php 2016-09-02
10:22:13 UTC (rev 15565)
+++ trunk/rental/inc/class.socontract_price_item.inc.php 2016-09-02
11:28:34 UTC (rev 15566)
@@ -123,7 +123,7 @@
. "
rental_contract_price_item.contract_id, rental_contract_price_item.area,
rental_contract_price_item.count,"
. "
rental_contract_price_item.agresso_id, rental_contract_price_item.title,
rental_contract_price_item.is_area,"
. " rental_contract_price_item.price,
rental_contract_price_item.total_price, rental_contract_price_item.is_one_time,"
- . "
rental_contract_price_item.date_start, rental_contract_price_item.date_end";
+ . "
rental_contract_price_item.date_start,
rental_contract_price_item.date_end,rental_price_item.type'";
}
else
{
Modified: trunk/rental/inc/class.uibilling.inc.php
===================================================================
--- trunk/rental/inc/class.uibilling.inc.php 2016-09-02 10:22:13 UTC (rev
15565)
+++ trunk/rental/inc/class.uibilling.inc.php 2016-09-02 11:28:34 UTC (rev
15566)
@@ -112,7 +112,7 @@
}
if (($contract_ids != null &&
is_array($contract_ids) && count($contract_ids) > 0) ||
(is_array($contract_bill_only_one_time) && count($contract_bill_only_one_time)
> 0)) // User submitted contracts to bill
{
- $missing_billing_info =
rental_sobilling::get_instance()->get_missing_billing_info(phpgw::get_var('billing_term'),
phpgw::get_var('year'), phpgw::get_var('month'), $contract_ids,
$contract_ids_override, phpgw::get_var('export_format'));
+ $missing_billing_info =
rental_sobilling::get_instance()->get_missing_billing_info(phpgw::get_var('billing_term'),
phpgw::get_var('year'), phpgw::get_var('month'), $contract_ids,
(array)$contract_ids_override, phpgw::get_var('export_format'));
if ($missing_billing_info == null ||
count($missing_billing_info) == 0)
{
@@ -126,7 +126,7 @@
phpgw::get_var('title'),
$GLOBALS['phpgw_info']['user']['account_id'],
$contract_ids,
- $contract_ids_override,
+ (array)
$contract_ids_override,
phpgw::get_var('export_format'),
$existing_billing,
$contract_bill_only_one_time,
@@ -577,11 +577,11 @@
//... 1. Contracts following
regular billing cycle
$filters =
array('contracts_for_billing' => true, 'contract_type' => $contract_type,
'billing_term_id' =>
$billing_term, 'year' => $year, 'month' => $month);
- $contracts =
rental_socontract::get_instance()->get($start_index, $num_of_objects,
$sort_field, $sort_ascending, $search_for, $search_type, $filters);
+ $contracts =
rental_socontract::get_instance()->get($start_index = 0, $num_of_objects = 0,
$sort_field = '', (bool)$sort_ascending, (string)$search_for,
(string)$search_type, $filters);
$filters2 =
array('contract_ids_one_time' => true, 'billing_term_id' => $billing_term,
'year' => $year,
'month' => $month);
}
- $contract_price_items =
$socontract_price_item->get($start_index, $num_of_objects, $sort_field,
$sort_ascending, $search_for, $search_type, $filters2);
+ $contract_price_items =
$socontract_price_item->get($start_index = 0, $num_of_objects = 0, $sort_field
= '', (bool)$sort_ascending, (string)$search_for, (string)$search_type,
$filters2);
foreach ($contract_price_items as
$contract_price_item)
{
@@ -1478,7 +1478,7 @@
$draw = phpgw::get_var('draw', 'int');
$columns = phpgw::get_var('columns');
- $start_index = phpgw::get_var('start', 'int',
'REQUEST', 0);
+ $start_index = (int)phpgw::get_var('start', 'int' );
$num_of_objects = (phpgw::get_var('length', 'int') <=
0) ? $user_rows_per_page : phpgw::get_var('length', 'int');
$sort_field = ($columns[$order[0]['column']]['data']) ?
$columns[$order[0]['column']]['data'] : 'id';
$sort_ascending = ($order[0]['dir'] == 'desc') ? false
: true;
Modified: trunk/rental/inc/model/class.contract_price_item.inc.php
===================================================================
--- trunk/rental/inc/model/class.contract_price_item.inc.php 2016-09-02
10:22:13 UTC (rev 15565)
+++ trunk/rental/inc/model/class.contract_price_item.inc.php 2016-09-02
11:28:34 UTC (rev 15566)
@@ -21,6 +21,7 @@
protected $location_factor;
protected $standard_factor;
protected $custom_factor;
+ protected $price_type_id;
/**
* Constructor. Takes an optional ID. If a price item is
created from outside
Modified: trunk/rental/inc/model/class.invoice.inc.php
===================================================================
--- trunk/rental/inc/model/class.invoice.inc.php 2016-09-02 10:22:13 UTC
(rev 15565)
+++ trunk/rental/inc/model/class.invoice.inc.php 2016-09-02 11:28:34 UTC
(rev 15566)
@@ -515,7 +515,8 @@
$contract_price_item->get_area(), //
the rented area on this contract (derived from contract)
$contract_price_item->get_count(), //
the number of items on this price item
$invoice_price_item_start, // the
start date from which this price item should be calculated
- $invoice_price_item_end // the end
date to which this price item should be calculated
+ $invoice_price_item_end, // the end
date to which this price item should be calculated
+
$contract_price_item->get_price_type_id() // The price type, default: year
);
// If the contract price item is of type
one-time and it's dates are within the invoice period ...
Modified: trunk/rental/inc/model/class.invoice_price_item.inc.php
===================================================================
--- trunk/rental/inc/model/class.invoice_price_item.inc.php 2016-09-02
10:22:13 UTC (rev 15565)
+++ trunk/rental/inc/model/class.invoice_price_item.inc.php 2016-09-02
11:28:34 UTC (rev 15566)
@@ -14,7 +14,8 @@
protected $invoice_id;
protected $is_area;
protected $is_one_time;
- protected $price_per_year;
+ protected $price_per_type;
+ protected $price_type_id;
protected $area;
protected $count;
protected $total_price;
@@ -22,7 +23,7 @@
protected $timestamp_end; // End date for the given invoice
public static $so;
- public function __construct( int $decimals, int $id, int
$invoice_id, string $title, string $agresso_id, bool $is_area, float
$price_per_year, float $area, int $count, int $timestamp_start, int
$timestamp_end )
+ public function __construct( int $decimals, int $id, int
$invoice_id, string $title, string $agresso_id, bool $is_area, float
$price_per_type, float $area, int $count, int $timestamp_start, int
$timestamp_end, int $price_type_id )
{
$this->decimals = (int)$decimals;
$this->id = (int)$id;
@@ -30,12 +31,13 @@
$this->title = $title;
$this->agresso_id = $agresso_id;
$this->is_area = (bool)$is_area;
- $this->price_per_year = (float)$price_per_year;
+ $this->price_per_type = (float)$price_per_type;
$this->area = (float)$area;
$this->count = (int)$count;
$this->timestamp_start = (int)$timestamp_start;
$this->timestamp_end = (int)$timestamp_end;
$this->total_price = null; // Needs to be re-calculated
+ $this->price_type_id = $price_type_id ? $price_type_id
: 1;
}
public function set_invoice_id( int $invoice_id )
@@ -65,17 +67,26 @@
$this->total_price = null; // Needs to be re-calculated
}
- public function set_price( $price_per_year )
+ public function set_price( $price_per_type )
{
- $this->price_per_year = (float)$price_per_year;
+ $this->price_per_type = (float)$price_per_type;
$this->total_price = null; // Needs to be re-calculated
}
public function get_price()
{
- return $this->price_per_year;
+ return $this->price_per_type;
}
+ public function set_price_type_id( $price_type_id = 1)
+ {
+ $this->price_type_id = (int)$price_type_id;
+ }
+ public function get_price_type_id()
+ {
+ return $this->price_type_id;
+ }
+
public function set_area( $area )
{
$this->area = (float)$area;
@@ -173,9 +184,21 @@
else // Incomplete month
{
// YYY: There must be a
better day to do this!?
-
$num_of_days_in_current_year = (date('L', strtotime($current_year . '01-01'))
== 0) ? 365 : 366;
- $num_of_days =
$last_day - $first_day + 1;
- $incomplete_months[] =
array($num_of_days_in_current_year, $num_of_days);
+ if($this->price_type_id
== 1) // year
+ {
+
$num_of_days_in_current_year = (date('L', strtotime($current_year . '01-01'))
== 0) ? 365 : 366;
+ $num_of_days =
$last_day - $first_day + 1;
+
$incomplete_months[] = array($num_of_days_in_current_year, $num_of_days);
+ }
+ else
if($this->price_type_id == 2) //month
+ {
+ $num_of_days =
$last_day - $first_day + 1;
+
$incomplete_months[] = array($num_of_days_in_current_month, $num_of_days);
+ }
+ else
+ {
+ throw new
Exception('Price type not supported');
+ }
}
}
}
@@ -184,18 +207,30 @@
$amount = $this->is_area() ? $this->get_area()
: $this->get_count();
// The total price of this price element for
complete months
- $this->total_price = (($this->get_price() *
$num_of_complete_months) / 12.0) * $amount;
+
+ if($this->price_type_id == 1) // year
+ {
+ $this->total_price =
(($this->get_price() * $num_of_complete_months) / 12.0) * $amount;
+ }
+ else if($this->price_type_id == 2) //month
+ {
+ $this->total_price =
($this->get_price() * $num_of_complete_months) * $amount;
+ }
+ else
+ {
+ throw new Exception('Price type not
supported');
+ }
// ---- Calculate incomplete months
- $price_per_year = $this->get_price() * $amount;
+ $price_per_type = $this->get_price() * $amount;
// Run through all the incomplete months ...
foreach ($incomplete_months as $day_factors)
{
// ... and add the sum of each
incomplete month to the total price of the price item
// Calculation: Price per day (price
per year divided with number of days in year) multiplied with number of days in
incomplete month
- $this->total_price += ($price_per_year
/ $day_factors[0]) * $day_factors[1];
+ $this->total_price += ($price_per_type
/ $day_factors[0]) * $day_factors[1];
}
// We round the total price for each price item
with the specified number of decimals precision
$this->total_price = round($this->total_price,
$this->decimals);
Modified: trunk/rental/inc/model/class.price_item.inc.php
===================================================================
--- trunk/rental/inc/model/class.price_item.inc.php 2016-09-02 10:22:13 UTC
(rev 15565)
+++ trunk/rental/inc/model/class.price_item.inc.php 2016-09-02 11:28:34 UTC
(rev 15566)
@@ -24,8 +24,8 @@
protected $price_types = array(
1 => 'year',
2 => 'month',
- 3 => 'day',
- 4 => 'hour',
+// 3 => 'day',
+// 4 => 'hour',
);
//protected $is_one_time;
@@ -148,6 +148,7 @@
'responsibility_id' =>
$this->get_responsibility_id(),
'responsibility_title' =>
lang($this->get_responsibility_title()),
'price_type_title' =>
lang($this->get_price_type_title()),
+ 'price_type_id' => $this->get_price_type_id(),
//'is_one_time' => $this->is_one_time()
);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [15566] rental: compute billing by monthly price type,
sigurdne <=