Commit 57e355c3 authored by droces's avatar droces

Addition of multiple booking codes: base_cost, total_cost, total_payable, amount_due

parent 804636c6
......@@ -4,6 +4,8 @@
* Contains functions that manage codes used in email templates.
*/
use Drupal\node\Entity\Node;
/**
* CONTENTS
*
......@@ -47,7 +49,7 @@ function get_codes_fm_bookable($bookable) {
}
function get_codes_fm_booking($booking) {
function get_codes_fm_booking(Node $booking) {
$base_cost = 0;
$base_cost_value = $booking->get('field_base_cost')->getValue();
if (in_array('value', $base_cost_value)[0]) {
......@@ -60,17 +62,17 @@ function get_codes_fm_booking($booking) {
$deposit_rate = \Drupal::config('abookings.bookingsettings')->get('deposit_rate');
$deposit = intval($base_cost) / (100 / $deposit_rate);
$codes = [
// field_addons - How to show this?
'{booking_id}' => $booking->id(),
'{checkin_date}' => $booking->get('field_checkin_date')->getValue()[0]['value'],
'{checkout_date}' => $booking->get('field_checkout_date')->getValue()[0]['value'],
'{booking_status}' => $booking->get('field_booking_status')->getValue()[0]['value'],
'{first_name}' => $booking->get('field_first_name')->getValue()[0]['value'],
'{last_name}' => $booking->get('field_last_name')->getValue()[0]['value'],
'{booking_status}' => $booking->get('field_booking_status')->getValue()[0]['value'],
// '{country}' => $booking->get('field_country')->getValue()[0]['value'],
'{email_address}' => $booking->get('field_email_address')->getValue()[0]['value'],
'{first_name}' => $booking->get('field_first_name')->getValue()[0]['value'],
// '{notes}' => $booking->get('field_notes')->getValue()[0]['value'],
'{num_guests}' => $booking->get('field_num_guests')->getValue()[0]['value'],
'{num_nights}' => $booking->get('field_num_nights')->getValue()[0]['value'],
......@@ -80,6 +82,10 @@ function get_codes_fm_booking($booking) {
'{deposit_amount}' => $deposit,
'{deposit_rate}' => $deposit_rate . '%',
'{base_cost}' => $base_cost,
'{total_cost}' => get_booking_costs($booking)['total_cost'],
'{total_payable}' => get_booking_costs($booking)['total_payable'],
// '{amount_due}' => $booking->get('field_amount_due')->getValue()[0]['value'],
'{amount_due}' => get_booking_costs($booking)['amount_due'],
];
// foreach ($codes as $code_text => $field_name) {
// set_code_if_exists($codes, $code_text, $booking, $field_name, 'value');
......@@ -118,6 +124,8 @@ function get_codes() {
'{deposit_rate}' => '',
],
'bookable' => [
// field_addons
// field_price_type
'{bookable_id}' => '',
'{bookable_name}' => '',
'{checkin_time}' => '',
......@@ -126,6 +134,8 @@ function get_codes() {
'{min_guests}' => '',
],
'booking' => [
// field_addons
// field_history
'{booking_id}' => '',
'{checkin_date}' => '',
'{checkout_date}' => '',
......@@ -144,7 +154,10 @@ function get_codes() {
'{promo_code_provided}' => '',
'{deposit_amount}' => '',
'{deposit_rate}' => '',
'{base_cost}' => '',
'{total_cost}' => '',
'{total_payable}' => '',
'{amount_due}' => '',
],
];
return $codes;
......
Markdown is supported
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