activities_helper.php
3 months ago
agent_helper.php
3 months ago
analytics_helper.php
1 week ago
auth_helper.php
6 days ago
blocks_helper.php
2 weeks ago
booking_helper.php
4 days ago
bricks_helper.php
3 months ago
bundles_helper.php
4 days ago
calendar_helper.php
2 days ago
carts_helper.php
3 months ago
connector_helper.php
3 months ago
csv_helper.php
3 months ago
customer_helper.php
1 month ago
customer_import_helper.php
1 month ago
database_helper.php
1 week ago
debug_helper.php
3 months ago
defaults_helper.php
3 months ago
elementor_helper.php
3 months ago
email_helper.php
3 months ago
encrypt_helper.php
3 months ago
events_helper.php
3 months ago
form_helper.php
3 months ago
icalendar_helper.php
3 months ago
image_helper.php
3 months ago
invoices_helper.php
2 weeks ago
license_helper.php
3 months ago
location_helper.php
3 months ago
marketing_systems_helper.php
3 months ago
meeting_systems_helper.php
3 months ago
menu_helper.php
2 weeks ago
meta_helper.php
3 months ago
migrations_helper.php
3 months ago
money_helper.php
3 months ago
notifications_helper.php
3 months ago
nps_survey_helper.php
3 months ago
order_intent_helper.php
2 months ago
orders_helper.php
3 months ago
otp_helper.php
3 months ago
pages_helper.php
3 months ago
params_helper.php
3 months ago
payments_helper.php
2 months ago
plugin_version_update_helper.php
2 months ago
price_breakdown_helper.php
3 months ago
process_jobs_helper.php
3 months ago
processes_helper.php
3 months ago
razorpay_connect_helper.php
1 week ago
replacer_helper.php
3 months ago
resource_helper.php
4 days ago
roles_helper.php
2 weeks ago
router_helper.php
3 months ago
service_helper.php
3 months ago
sessions_helper.php
3 months ago
settings_helper.php
1 week ago
short_links_systems_helper.php
3 months ago
shortcodes_helper.php
2 weeks ago
sms_helper.php
3 months ago
steps_helper.php
1 week ago
stripe_connect_helper.php
1 week ago
styles_helper.php
3 months ago
support_topics_helper.php
3 months ago
time_helper.php
2 months ago
timeline_helper.php
2 months ago
transaction_helper.php
1 month ago
transaction_intent_helper.php
3 months ago
util_helper.php
1 month ago
version_specific_updates_helper.php
3 months ago
whatsapp_helper.php
1 month ago
work_periods_helper.php
3 months ago
wp_datetime.php
3 months ago
wp_user_helper.php
3 months ago
price_breakdown_helper.php
124 lines
| 1 | <?php |
| 2 | /* |
| 3 | * Copyright (c) 2023 LatePoint LLC. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | class OsPriceBreakdownHelper { |
| 7 | |
| 8 | public static function output_price_breakdown( $rows, $inline_styles = false ) { |
| 9 | $prev_heading = ''; |
| 10 | foreach ( $rows['before_subtotal'] as $row ) { |
| 11 | $skip_heading = ! empty( $row['heading'] ) && $row['heading'] == $prev_heading; |
| 12 | self::output_price_breakdown_row( $row, $inline_styles, $skip_heading ); |
| 13 | $prev_heading = $row['heading']; |
| 14 | } |
| 15 | // if there is nothing between subtotal and total - don't show subtotal as it will be identical to total |
| 16 | if ( ! empty( $rows['after_subtotal'] ) ) { |
| 17 | if ( ! empty( $rows['subtotal'] ) ) { |
| 18 | echo '<div class="subtotal-separator"></div>'; |
| 19 | self::output_price_breakdown_row( $rows['subtotal'], $inline_styles ); |
| 20 | } |
| 21 | foreach ( $rows['after_subtotal'] as $row ) { |
| 22 | self::output_price_breakdown_row( $row, $inline_styles ); |
| 23 | } |
| 24 | } |
| 25 | if ( ! empty( $rows['total'] ) ) { |
| 26 | self::output_price_breakdown_row( $rows['total'], $inline_styles ); |
| 27 | } |
| 28 | if ( ! empty( $rows['payments'] ) ) { |
| 29 | foreach ( $rows['payments'] as $row ) { |
| 30 | self::output_price_breakdown_row( $row, $inline_styles ); |
| 31 | } |
| 32 | } |
| 33 | if ( ! empty( $rows['balance'] ) ) { |
| 34 | self::output_price_breakdown_row( $rows['balance'], $inline_styles ); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | public static function output_price_breakdown_row( $row, $inline_styles = false, $skip_heading = false ) { |
| 39 | if ( ! empty( $row['items'] ) ) { |
| 40 | if ( ! $skip_heading ) { |
| 41 | if ( $inline_styles ) { |
| 42 | if ( ! empty( $row['heading'] ) ) { |
| 43 | echo '<table width="100%" cellpadding="0" cellspacing="0" style="margin-bottom: 5px; margin-top: 10px;"><tr><td style="color: #788291;font-size: 11px;text-transform: uppercase;letter-spacing: 1px;font-weight: 600;">' . esc_html( $row['heading'] ) . '</td><td style="width: 100%;"><div style="height: 1px;background-color: #f1f1f1;margin-left: 10px;"></div></td></tr></table>'; |
| 44 | } |
| 45 | } else { |
| 46 | if ( ! empty( $row['heading'] ) ) { |
| 47 | echo '<div class="summary-box-heading"><div class="sbh-item">' . esc_html( $row['heading'] ) . '</div><div class="sbh-line"></div></div>'; |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | foreach ( $row['items'] as $row_item ) { |
| 52 | self::output_price_breakdown_row( $row_item, $inline_styles ); |
| 53 | } |
| 54 | } else { |
| 55 | $extra_class = ''; |
| 56 | $extra_css = ''; |
| 57 | if ( isset( $row['style'] ) && $row['style'] == 'strong' ) { |
| 58 | $extra_class .= ' spi-strong'; |
| 59 | } |
| 60 | if ( isset( $row['style'] ) && $row['style'] == 'total' ) { |
| 61 | $extra_class .= ' spi-total'; |
| 62 | if ( $inline_styles ) { |
| 63 | $extra_css = 'border-top: 3px solid #41444b;padding-top: 10px;margin-top: 10px;font-size: 16px;'; |
| 64 | } |
| 65 | } |
| 66 | if ( isset( $row['type'] ) && $row['type'] == 'credit' ) { |
| 67 | $extra_class .= ' spi-positive'; |
| 68 | } |
| 69 | if ( isset( $row['style'] ) && $row['style'] == 'sub' ) { |
| 70 | $extra_class .= ' spi-sub'; |
| 71 | } |
| 72 | |
| 73 | if ( $inline_styles ) { ?> |
| 74 | <table width="100%" cellpadding="0" cellspacing="0" style="margin-bottom: 7px;<?php echo esc_attr( $extra_css ); ?>"> |
| 75 | <tr> |
| 76 | <td style="text-align: left;"> |
| 77 | <?php echo esc_html( $row['label'] ); ?> |
| 78 | <?php if ( ! empty( $row['note'] ) ) { |
| 79 | echo '<span class="pi-note">' . esc_html( $row['note'] ) . '</span>';} ?> |
| 80 | <?php if ( ! empty( $row['badge'] ) ) { |
| 81 | echo '<span class="pi-badge">' . esc_html( $row['badge'] ) . '</span>';} ?> |
| 82 | </td> |
| 83 | <td style="text-align: right;"> |
| 84 | <?php echo esc_html( $row['value'] ); ?> |
| 85 | </td> |
| 86 | </tr> |
| 87 | </table> |
| 88 | <?php |
| 89 | } else { |
| 90 | ?> |
| 91 | <div class="summary-price-item-w <?php echo esc_attr( $extra_class ); ?>"> |
| 92 | <div class="spi-name"> |
| 93 | <?php echo esc_html( $row['label'] ); ?> |
| 94 | <?php if ( ! empty( $row['note'] ) ) { |
| 95 | echo '<span class="pi-note">' . esc_html( $row['note'] ) . '</span>';} ?> |
| 96 | <?php if ( ! empty( $row['badge'] ) ) { |
| 97 | echo '<span class="pi-badge">' . esc_html( $row['badge'] ) . '</span>';} ?> |
| 98 | </div> |
| 99 | <div class="spi-price"><?php echo esc_html( $row['value'] ); ?></div> |
| 100 | </div> |
| 101 | <?php |
| 102 | } |
| 103 | } |
| 104 | if ( ! empty( $row['sub_items'] ) ) { |
| 105 | if ( $inline_styles ) { |
| 106 | if ( ! empty( $row['sub_items_heading'] ) ) { |
| 107 | echo '<table width="100%" cellpadding="0" cellspacing="0" style="margin-bottom: 5px; margin-top: 10px;"><tr><td style="color: #788291;font-size: 11px;text-transform: uppercase;letter-spacing: 1px;font-weight: 600;">' . esc_html( $row['sub_items_heading'] ) . '</td><td style="width: 100%;"><div style="height: 1px;background-color: #f1f1f1;margin-left: 10px;"></div></td></tr></table>'; |
| 108 | } |
| 109 | } else { |
| 110 | if ( ! empty( $row['sub_items_heading'] ) ) { |
| 111 | echo '<div class="summary-box-heading"><div class="sbh-item">' . esc_html( $row['sub_items_heading'] ) . '</div><div class="sbh-line"></div></div>'; |
| 112 | } |
| 113 | } |
| 114 | foreach ( $row['sub_items'] as $row_item ) { |
| 115 | self::output_price_breakdown_row( $row_item, $inline_styles ); |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | public static function is_zero( array $price_breakdown_rows ): bool { |
| 121 | $subtotal = (float) $price_breakdown_rows['subtotal']['raw_value']; |
| 122 | return ( $subtotal == 0 ); |
| 123 | } |
| 124 | } |