Commit 7be992fc authored by Rodrigo's avatar Rodrigo
Browse files

Add Income Info card to Dashboard

Change money variables to float
Add discount attribute to Registrants
parent 6e347b50
......@@ -107,7 +107,7 @@ class Gen_Caldera_Forms_Data_Collector {
}
$registration_array[ sanitize_key( $field->slug ) ] = sanitize_text_field( $field->value );
}
$registration = $this->get_registrants( $registration_array );
$registration = $this->get_registrants( $registration_array );
if ( ! is_wp_error( $registration ) ) {
$all_registrations[] = $registration;
}
......@@ -181,9 +181,9 @@ class Gen_Caldera_Forms_Data_Collector {
* Discount
*/
if ( isset( $registration_array[ Gen_Form_Parameters::DISCOUNT ] ) ) {
$discount = $registration_array[ Gen_Form_Parameters::DISCOUNT ];
$group_discount = $registration_array[ Gen_Form_Parameters::DISCOUNT ];
} else {
$discount = 0;
$group_discount = 0;
}
/**
* Donation
......@@ -371,6 +371,10 @@ class Gen_Caldera_Forms_Data_Collector {
*/
$registrant_meals_price = $meals_price / $number_of_registrants;
/**
* Discount
*/
$registrant_discount = $group_discount / $number_of_registrants;
/**
* Accommodation Type
*/
$accommodation = [];
......@@ -420,7 +424,8 @@ class Gen_Caldera_Forms_Data_Collector {
$registrant_name,
$registrant_event_price,
$registrant_accommodation_price,
$registrant_meals_price
$registrant_meals_price,
$registrant_discount
)
);
break;
......@@ -440,7 +445,8 @@ class Gen_Caldera_Forms_Data_Collector {
$registrant_name,
$registrant_event_price,
$registrant_accommodation_price,
$registrant_meals_price
$registrant_meals_price,
$registrant_discount
)
);
break;
......@@ -459,7 +465,8 @@ class Gen_Caldera_Forms_Data_Collector {
$registrant_name,
$registrant_event_price,
$registrant_accommodation_price,
$registrant_meals_price
$registrant_meals_price,
$registrant_discount
)
);
break;
......@@ -478,7 +485,7 @@ class Gen_Caldera_Forms_Data_Collector {
$meals_price,
$donation,
$fee,
$discount,
$group_discount,
$total_price,
$registrants
);
......
......@@ -37,7 +37,7 @@ class Gen_Registration {
*
* @since 1.0.1
* @access private
* @var int $event_price The total price of the event ticket.
* @var float $event_price The total price of the event ticket.
*/
private $event_price;
/**
......@@ -45,7 +45,7 @@ class Gen_Registration {
*
* @since 1.0.1
* @access private
* @var int $accommodation_price The total price of accommodation for the registration.
* @var float $accommodation_price The total price of accommodation for the registration.
*/
private $accommodation_price;
/**
......@@ -53,7 +53,7 @@ class Gen_Registration {
*
* @since 1.0.1
* @access private
* @var int $meals_price The total price of meals for the registration.
* @var float $meals_price The total price of meals for the registration.
*/
private $meals_price;
/**
......@@ -61,7 +61,7 @@ class Gen_Registration {
*
* @since 1.0.1
* @access private
* @var int $donation The total amount in Donation Given to GEN Europe.
* @var float $donation The total amount in Donation Given to GEN Europe.
*/
private $donation;
/**
......@@ -69,7 +69,7 @@ class Gen_Registration {
*
* @since 1.0.1
* @access private
* @var int $fee The total amount of fees for the registration.
* @var float $fee The total amount of fees for the registration.
*/
private $fee;
/**
......@@ -77,7 +77,7 @@ class Gen_Registration {
*
* @since 1.0.1
* @access private
* @var int $discount Discount for this registration.
* @var float $discount Discount for this registration.
*/
private $discount;
/**
......@@ -85,7 +85,7 @@ class Gen_Registration {
*
* @since 1.0.1
* @access private
* @var int $total_price The total price for the registration.
* @var float $total_price The total price for the registration.
*/
private $total_price;
/**
......@@ -100,13 +100,13 @@ class Gen_Registration {
* Initiate an object with its attributes
*
* @param int $registration_id The registration ID.
* @param int $event_price Total event price.
* @param int $accommodation_price Total accommodation price.
* @param int $meals_price Total meals price.
* @param int $donation Donation to GEN Europe.
* @param int $fee Total Fee.
* @param int $discount Discount.
* @param int $total_price Total registration price.
* @param float $event_price Total event price.
* @param float $accommodation_price Total accommodation price.
* @param float $meals_price Total meals price.
* @param float $donation Donation to GEN Europe.
* @param float $fee Total Fee.
* @param float $discount Discount.
* @param float $total_price Total registration price.
* @param array $registrants List of registrants in this registration.
*/
public function __construct(
......@@ -141,7 +141,7 @@ class Gen_Registration {
/**
* Retrieves the event price.
*
* @return int Event price.
* @return float Event price.
*/
public function get_event_price() {
return $this->event_price;
......@@ -149,7 +149,7 @@ class Gen_Registration {
/**
* Retrieves the accommodation price.
*
* @return int Accommodation price.
* @return float Accommodation price.
*/
public function get_accommodation_price() {
return $this->accommodation_price;
......@@ -157,7 +157,7 @@ class Gen_Registration {
/**
* Retrieves the meals price.
*
* @return int Meals price.
* @return float Meals price.
*/
public function get_meals_price() {
return $this->meals_price;
......@@ -165,7 +165,7 @@ class Gen_Registration {
/**
* Retrieves the donation amount.
*
* @return int Donation.
* @return float Donation.
*/
public function get_donation() {
return $this->donation;
......@@ -173,7 +173,7 @@ class Gen_Registration {
/**
* Retrieves the fee amount.
*
* @return int Fee amount.
* @return float Fee amount.
*/
public function get_fee() {
return $this->fee;
......@@ -181,7 +181,7 @@ class Gen_Registration {
/**
* Retrieves the Discount.
*
* @return int Discount.
* @return float Discount.
*/
public function get_discount() {
return $this->discount;
......@@ -189,7 +189,7 @@ class Gen_Registration {
/**
* Retrieves the registration price.
*
* @return int Total registraton price.
* @return float Total registraton price.
*/
public function get_total_price() {
return $this->total_price;
......
......@@ -129,6 +129,38 @@ class Gen_Dashboard_Loader {
* @var WP_Error $error_list List of errors occurred.
*/
protected $error_list;
/**
* Total accommodation income of the Registration process.
*
* @since 1.0.1
* @access protected
* @var float $total_accommodation_income Total accommodation income.
*/
protected $total_accommodation_income;
/**
* Total event income of the Registration process.
*
* @since 1.0.1
* @access protected
* @var float $total_event_income Total event income.
*/
protected $total_event_income;
/**
* Total meals income of the Registration process.
*
* @since 1.0.1
* @access protected
* @var float $total_meals_income Total meals income.
*/
protected $total_meals_income;
/**
* Total donations income of the Registration process.
*
* @since 1.0.1
* @access protected
* @var float $total_donations_income Total donations income.
*/
protected $total_donations_income;
/**
* Retrieves the class instance.
*
......@@ -148,12 +180,17 @@ class Gen_Dashboard_Loader {
* @param Gen_Caldera_Forms_Data_Collector $data_source Object that contains all the information collected from Caldera Forms form.
*/
private function __construct( $data_source ) {
$this->error_list = new WP_Error();
$all_registrations = $data_source->get_all_registrations();
$this->error_list = new WP_Error();
$this->total_meals_income = 0;
$this->total_event_income = 0;
$this->total_donations_income = 0;
$this->total_accommodation_income = 0;
$all_registrations = $data_source->get_all_registrations();
foreach ( $data_source->get_diet_types() as $type_name ) {
$this->number_of_registrants_by_diet_type_list[ $type_name ] = 0;
}
foreach ( $all_registrations as $registration ) {
self::calculate_income( $registration );
foreach ( $registration->get_registrants() as $registrant ) {
self::count_number_of_registrants_by_region( $registrant );
self::count_number_of_registrants_by_day( $registrant );
......@@ -184,6 +221,19 @@ class Gen_Dashboard_Loader {
$aux = $this->number_of_registrants_by_day_list[ $date ];
}
}
/**
* Calculates the income of the registration process separated by Accommodation, Event, Meals and Donations.
*
* @param Gen_Registration $registration A Registration with one or more Registrants.
*/
private function calculate_income( $registration ) {
$this->total_event_income = $this->total_event_income + ( $registration->get_event_price() - $registration->get_discount() );
$this->total_accommodation_income = $this->total_accommodation_income + $registration->get_accommodation_price();
$this->total_meals_income = $this->total_meals_income + $registration->get_meals_price();
$this->total_donations_income = $this->total_donations_income + $registration->get_donation();
}
/**
* Adds one registrant to the sum of registrants by age group and registration type.
*
......@@ -415,4 +465,36 @@ class Gen_Dashboard_Loader {
public function get_error_list() {
return $this->error_list;
}
/**
* Retrieve the total accommodation Income from the Registration Process.
*
* @return float Total accommodation income.
*/
public function get_total_accommodation_income() {
return $this->total_accommodation_income;
}
/**
* Retrieve the total donations Income from the Registration Process.
*
* @return float Total donations income.
*/
public function get_total_donations_income() {
return $this->total_donations_income;
}
/**
* Retrieve the total event Income from the Registration Process.
*
* @return float Total event income.
*/
public function get_total_event_income() {
return $this->total_event_income;
}
/**
* Retrieve the total meals Income from the Registration Process.
*
* @return float Total meals income.
*/
public function get_total_meals_income() {
return $this->total_meals_income;
}
}
......@@ -22,7 +22,7 @@ class Gen_Dashboard_Viewer {
* @since 1.0.0
*/
public static function display_dashboard( $dashboard ) {
self::display_income_info_card( $dashboard );
self::display_age_groups_info_card( $dashboard );
self::display_transportation_type_info_card( $dashboard );
self::display_accommodation_type_info_card( $dashboard );
......@@ -37,6 +37,42 @@ class Gen_Dashboard_Viewer {
}
}
/** Function that displays a card containing the registration income information.
*
* @param Gen_Dashboard_Loader $dashboard Object of type Gen_Dashboard_Loader containing all the information from the registration.
* @since 1.0.1
*/
private static function display_income_info_card( $dashboard ) {
if ( ! $dashboard instanceof Gen_Dashboard_Loader ) {
Gen_Utility::print_errors( new WP_Error( 'no_valid_dashboard_instance', 'Income info card has not received a valid dashboard instance.' ) );
return;
}
/**
* Format the numbers to the (9.999,99 EU) format.
* Decimal numbers = 2
* Decimal separator = ','
* Thousands separator = '.'
*/
$formated_event_income = number_format( $dashboard->get_total_event_income(), 2, ',', '.' ) . ' EU ';
$formated_accommodation_income = number_format( $dashboard->get_total_accommodation_income(), 2, ',', '.' ) . ' EU ';
$formated_meals_income = number_format( $dashboard->get_total_meals_income(), 2, ',', '.' ) . ' EU ';
$formated_donations_income = number_format( $dashboard->get_total_donations_income(), 2, ',', '.' ) . ' EU ';
?>
<div class="info-card">
<header class="gen-container gen-blue">
<h1>Registration Income</h1>
</header>
<div class="gen-container">
<hr>
<strong>Event:</strong><span class="gen-value"><?php echo esc_html( $formated_event_income ); ?></span><hr>
<strong>Accommodation:</strong><span class="gen-value"><?php echo esc_html( $formated_accommodation_income ); ?></span><hr>
<strong>Meals:</strong><span class="gen-value"><?php echo esc_html( $formated_meals_income ); ?></span><hr>
<strong>Donations:</strong><span class="gen-value"><?php echo esc_html( $formated_donations_income ); ?></span><hr>
</div>
</div>
<?php
}
/** Function that displays a card containing the information about the Delegates and their organization.
*
* @param Gen_Dashboard_Loader $dashboard Object of type Gen_Dashboard_Loader containing all the information from the registration.
......
......@@ -40,13 +40,13 @@ class Gen_Delegate extends Gen_Registrant {
* @param string $diet Type of diet selected by the registrant.
* @param string $country Country the registrant comes from.
* @param string $name Registrant's name.
* @param int $registration_price The price paid for the event registration.
* @param int $accommodation_price The price paid for the event registration.
* @param int $food_price The price paid for the event registration.
* @param float $registration_price The price paid for the event registration.
* @param float $accommodation_price The price paid for the event registration.
* @param float $meals_price The price paid for the event registration.
* @param float $discount Discount given to registrant.
*/
public function __construct( $registration_id, $age, $delegate_organization, $transportation, $accommodation, $arrival, $departure, $diet, $country, $name, $registration_price, $accommodation_price, $food_price ) {
parent::__construct( $registration_id, $age, $transportation, $accommodation, $arrival, $departure, $diet, $country, $name, $registration_price, $accommodation_price, $food_price );
public function __construct( $registration_id, $age, $delegate_organization, $transportation, $accommodation, $arrival, $departure, $diet, $country, $name, $registration_price, $accommodation_price, $meals_price, $discount ) {
parent::__construct( $registration_id, $age, $transportation, $accommodation, $arrival, $departure, $diet, $country, $name, $registration_price, $accommodation_price, $meals_price, $discount );
$this->organization = $delegate_organization;
}
/**
......@@ -55,7 +55,6 @@ class Gen_Delegate extends Gen_Registrant {
* @return string Organization's name.
*/
public function get_organization() {
return $this->organization;
}
}
......@@ -96,7 +96,7 @@ abstract class Gen_Registrant {
*
* @since 1.0.1
* @access private
* @var int $registration_price The price paid for the event registration.
* @var float $registration_price The price paid for the event registration.
*/
private $registration_price;
/**
......@@ -104,17 +104,25 @@ abstract class Gen_Registrant {
*
* @since 1.0.1
* @access private
* @var int $accommodation_price The price paid for the accommodation during the event.
* @var float $accommodation_price The price paid for the accommodation during the event.
*/
private $accommodation_price;
/**
* The price paid for the food during the event.
* The price paid for the meals during the event.
*
* @since 1.0.1
* @access private
* @var int $food_price The price paid for the food during the event.
* @var float $meals_price The price paid for the meals during the event.
*/
private $food_price;
private $meals_price;
/**
* Discount given to the registrant.
*
* @since 1.0.1
* @access private
* @var float $discount Discount given to the registrant.
*/
private $discount;
/**
* Initiate an object with its attributes
*
......@@ -127,11 +135,12 @@ abstract class Gen_Registrant {
* @param string $diet Type of diet selected by the registrant.
* @param string $country Country the registrant comes from.
* @param string $name Registrant's name.
* @param int $registration_price The price paid for the event registration.
* @param int $accommodation_price The price paid for the event registration.
* @param int $food_price The price paid for the event registration.
* @param float $registration_price The price paid for the event registration.
* @param float $accommodation_price The price paid for the event registration.
* @param float $meals_price The price paid for the event registration.
* @param float $discount Discount Given to the registrant.
*/
public function __construct( $id, $registrant_age, $transportation, $accommodation, $arrival, $departure, $diet, $country, $name, $registration_price, $accommodation_price, $food_price ) {
public function __construct( $id, $registrant_age, $transportation, $accommodation, $arrival, $departure, $diet, $country, $name, $registration_price, $accommodation_price, $meals_price, $discount ) {
$this->registration_id = $id;
$this->age = $registrant_age;
$this->transportation_type = $transportation;
......@@ -143,7 +152,8 @@ abstract class Gen_Registrant {
$this->name = $name;
$this->registration_price = $registration_price;
$this->accommodation_price = $accommodation_price;
$this->food_price = $food_price;
$this->meals_price = $meals_price;
$this->discount = $discount;
}
/**
* Retrieves the Regstration ID for this Registrant.
......@@ -220,7 +230,7 @@ abstract class Gen_Registrant {
/**
* Retrieves the registration price.
*
* @return int Registration price.
* @return float Registration price.
*/
public function get_registration_price() {
return $this->registration_price;
......@@ -228,17 +238,25 @@ abstract class Gen_Registrant {
/**
* Retrieves the accommodation price.
*
* @return int Accommodation price.
* @return float Accommodation price.
*/
public function get_accommodation_price() {
return $this->accommodation_price;
}
/**
* Retrieves the food price.
* Retrieves the meals price.
*
* @return float meals price.
*/
public function get_meals_price() {
return $this->meals_price;
}
/**
* Retrieves the discount.
*
* @return int Food price.
* @return float discount.
*/
public function get_food_price() {
return $this->food_price;
public function get_discount() {
return $this->discount;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment