handle bundle product prices editor and prices summary
This commit is contained in:
@@ -0,0 +1,277 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<style>
|
||||
table tr:not(.wiaas-package-price) td:not(:first-child) {
|
||||
text-align: center;
|
||||
vertical-align: middle; !important;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<div id="wiaas_package_pricing_editor" class="wrap">
|
||||
|
||||
<h1>
|
||||
<?php
|
||||
esc_html_e($package->get_title(), 'wiaas');
|
||||
|
||||
$country = Wiaas_Countries::get_package_country($package);
|
||||
|
||||
if (! empty($country)) {
|
||||
|
||||
esc_html_e(' (sold in ' . $country['name'] . ')', 'wiaas');
|
||||
}
|
||||
?>
|
||||
</h1>
|
||||
|
||||
<br class="clear" />
|
||||
|
||||
<div id="col-container">
|
||||
<div id="post-body" class="metabox-holder columns-2">
|
||||
|
||||
<div id="col-right">
|
||||
|
||||
<div class="col-wrap">
|
||||
|
||||
<div class="inside">
|
||||
|
||||
<table class="widefat">
|
||||
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
$products_total_cost = 0;
|
||||
$one_time_services_cost = 0;
|
||||
$recurring_services_cost = 0;
|
||||
$installation_cost = 0;
|
||||
|
||||
foreach ($bundled_items_per_category as $cat => $items) {
|
||||
|
||||
?>
|
||||
<tr style="background: #F5F5F5;">
|
||||
<td colspan="4">
|
||||
<strong style="text-transform: uppercase;">
|
||||
<?php esc_html_e($cat . ' (' . count($items) . ')', 'wiaas') ?>
|
||||
</strong>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
foreach ($items as $item) {
|
||||
$product = $item->product;
|
||||
|
||||
$product_price = Wiaas_Product_Pricing::get_product_price($product);
|
||||
|
||||
$total_cost = Wiaas_Pricing::get_product_total_cost($product);
|
||||
|
||||
?>
|
||||
<tr>
|
||||
<td>
|
||||
<span>
|
||||
<?php esc_html_e($item->get_quantity(), 'wiaas') ?>
|
||||
x
|
||||
<?php esc_html_e($product->get_title(), 'wiaas') ?>
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<?php
|
||||
esc_html_e(
|
||||
$total_cost * $item->get_quantity(),
|
||||
'wiaas')
|
||||
?>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<?php
|
||||
esc_html_e(
|
||||
$total_cost . ' per unit',
|
||||
'wiaas');
|
||||
?>
|
||||
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<?php
|
||||
if ($product_price['is_recurring']) {
|
||||
esc_html_e(
|
||||
$product_price['price'] . ' / month for ' . $product_price['pay_period'] . ' months',
|
||||
'wiaas');
|
||||
|
||||
} else {
|
||||
|
||||
echo '-';
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<tr class="wiaas-package-price">
|
||||
<td style="border-top: 1px solid #e5e5e5;"></td>
|
||||
<td colspan="3" style="border-top: 1px solid #e5e5e5;">
|
||||
<strong>
|
||||
<?php
|
||||
|
||||
if ($cat === 'product') {
|
||||
|
||||
$products_total_cost = wiaas_get_package_hardware_procurement_cost($package) +
|
||||
wiaas_get_package_software_procurement_cost($package);
|
||||
|
||||
esc_html_e('Total: ' . $products_total_cost, 'wiaas');
|
||||
}
|
||||
|
||||
if ($cat === 'service') {
|
||||
|
||||
$one_time_services_cost = wiaas_get_package_one_time_services_procurement_cost($package);
|
||||
|
||||
$recurring_services_cost = wiaas_get_package_recurring_services_procurement_cost($package);
|
||||
|
||||
esc_html_e('One time services: ' . $one_time_services_cost, 'wiaas');
|
||||
|
||||
echo '<br>';
|
||||
|
||||
esc_html_e('Recurring services: ' . $recurring_services_cost . ' / month ', 'wiaas');
|
||||
}
|
||||
|
||||
if ($cat === 'installation') {
|
||||
|
||||
$installation_cost = wiaas_get_package_installation_procurement_cost($package);
|
||||
|
||||
esc_html_e('Installation: ' . $installation_cost, 'wiaas');
|
||||
}
|
||||
?>
|
||||
</strong>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
|
||||
<tfoot>
|
||||
<tr class="wiaas-package-price">
|
||||
<td>
|
||||
<h4>TOTAL COST :</h4>
|
||||
</td>
|
||||
<td colspan="3">
|
||||
<strong>Fixed: <?php esc_html_e($products_total_cost + $one_time_services_cost + $installation_cost)?></strong>
|
||||
<br>
|
||||
<strong>Recurring: <?php esc_html_e($recurring_services_cost)?> / month</strong>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="col-left">
|
||||
|
||||
<div class="col-wrap">
|
||||
<div class="form-wrap">
|
||||
|
||||
<h2><?php esc_html_e('Set package prices', 'wiaas') ?></h2>
|
||||
|
||||
<form action="" method="post">
|
||||
|
||||
<input type="hidden" name="page" value="wiaas-package_price_editor">
|
||||
<input type="hidden" name="id" value="<?php esc_attr_e($package->get_id(), 'wiaas') ?>">
|
||||
|
||||
<div class="form-field">
|
||||
<label><?php esc_html_e('Max cost margin:', 'wiaas') ?></label>
|
||||
<input
|
||||
id="wiaas_pricing_rules_max_cost_margin"
|
||||
name="wiaas_max_cost_margin"
|
||||
type="number"
|
||||
min="0"
|
||||
value="<?php esc_attr_e($max_cost_margin, 'wiaas') ?>"
|
||||
data-total="<?php esc_attr_e(Wiaas_Pricing::get_package_total_cost($package), 'wiaas') ?>"
|
||||
>
|
||||
|
||||
<p
|
||||
id="wiaas_pricing_rules_max_cost_margin_error"
|
||||
<?php if(Wiaas_Package_Status::get_package_status($package->get_id()) !== Wiaas_Package_Status::INVALID_MARGIN) echo 'style="display: none;"' ?>
|
||||
class="wiaas-package-error"
|
||||
>The total costs are greater than the package max margin!</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-field">
|
||||
<label><?php esc_html_e('Commision ( % ):', 'wiaas') ?></label>
|
||||
<input
|
||||
id="wiaas_pricing_rules_commision"
|
||||
name="wiaas_pricing_rules_commision"
|
||||
type="number"
|
||||
value="<?php esc_attr_e($commission, 'wiaas') ?>"
|
||||
min="0" max="100"
|
||||
>
|
||||
<p id="wiaas_pricing_rules_commission_details">
|
||||
<?php esc_html_e('Commercial lead: ' . (100 - $commission) .'%', 'wiaas') ?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="form-field">
|
||||
|
||||
<div class="wrap">
|
||||
|
||||
<select id="wiaas_pay_types" name="wiaas-pay-type" class="pricing_rule_mode">
|
||||
<option selected value="0" disabled> Select payment type ...</option>
|
||||
|
||||
<?php
|
||||
$available_pay_types = Wiaas_Package_Pricing::get_available_pay_types();
|
||||
|
||||
foreach ($available_pay_types as $name => $pay_type) {
|
||||
$is_added = ! empty( $pricing_rules[$name])
|
||||
?>
|
||||
<option
|
||||
value="<?php esc_attr_e($name, 'wiaas') ?>"
|
||||
id="wiaas_pay_type_<?php esc_attr_e($name, 'wiaas') ?>"
|
||||
<?php disabled($is_added, true, true) ?>
|
||||
>
|
||||
<?php esc_html_e( $pay_type['title'], 'wiaas' ); ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
</select>
|
||||
|
||||
<button
|
||||
title="<?php _e( 'Add pricing type.', 'wiaas' ); ?>"
|
||||
id="wiaas-add-pricing"
|
||||
type="button"
|
||||
class="button">
|
||||
<?php _e( 'Add Pricing Type', 'wiaas' ); ?>
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="wiaas_package_pricing_rules">
|
||||
|
||||
<?php
|
||||
require 'html-package-pricing-rules-list.php';
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php wp_nonce_field( 'wiaas_save_package_prices', 'wiaas_save_package_prices_nonce' ); ?>
|
||||
|
||||
<input type="submit" value="Save" class="button button-primary button-large">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -8,7 +8,7 @@ $available_pay_types = Wiaas_Package_Pricing::get_available_pay_types();
|
||||
foreach ( $pricing_rules as $name => $pricing_rule ) {
|
||||
$pay_type = $available_pay_types[$name];
|
||||
?>
|
||||
<div id="wiaas-pricing-rule-<?php echo $name; ?>" class="wiaas-pricing-rule">
|
||||
<div id="wiaas-pricing-rule-<?php echo $name; ?>" class="wiaas-pricing-rule form-field">
|
||||
<div class="section">
|
||||
<h4 class="first"><?php echo $pay_type['title']; ?>
|
||||
<a href="#" data-name="<?php echo $name; ?>"
|
||||
|
||||
@@ -1,256 +0,0 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div id="wiaas_package_price" class="panel woocommerce_options_panel">
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function ($) {
|
||||
$("#wiaas-add-pricing").click(function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var set_index = $("#wiaas_package_pricing_rules").data('setindex') + 1;
|
||||
$("#wiaas_package_pricing_rules").data('setindex', set_index);
|
||||
|
||||
var pay_type = $('#wiaas_pay_type').val();
|
||||
|
||||
var data = {
|
||||
'pay_type': pay_type,
|
||||
post:<?php echo isset( $_GET['post'] ) ? $_GET['post'] : 0; ?>,
|
||||
action: 'create_empty_pricing_rule'
|
||||
};
|
||||
|
||||
$.post(ajaxurl, data, function (response) {
|
||||
$('#wiaas_package_pricing_rules').append(response);
|
||||
|
||||
$(`#wiaas_pay_type_${pay_type}`).addClass('wiaas_hidden');
|
||||
|
||||
var available_options = $('#wiaas_pay_type option').not('.wiaas_hidden');
|
||||
if (available_options.length === 0) {
|
||||
$('#wiaas_package_price_controls').addClass('wiaas_hidden');
|
||||
} else {
|
||||
$('#wiaas_pay_type').val(available_options.first().val());
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
//Remove Pricing Type
|
||||
$('#wiaas_package_pricing_rules').delegate('.delete_wiaas_pricing_rule', 'click', function (event) {
|
||||
event.preventDefault();
|
||||
if (confirm("<?php _e( 'Are you sure you would like to remove this pay type?', 'wiaas' ); ?>")) {
|
||||
var name = $(this).data('name');
|
||||
$('#wiaas-pricing-rule-' + name).slideUp().remove();
|
||||
|
||||
// append new option to controls
|
||||
$(`#wiaas_pay_type_${name}`).removeClass('wiaas_hidden');
|
||||
var available_options = $('#wiaas_pay_type option').not('.wiaas_hidden');
|
||||
if (available_options.length === 1) {
|
||||
$('#wiaas_package_price_controls').removeClass('wiaas_hidden');
|
||||
$('#wiaas_pay_type').val(available_options.first().val());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#wiaas_package_pricing_rules').delegate('.wiaas_minimal_services_price', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var minimal_services_price = parseFloat($(this).val()) || 0;
|
||||
var principal_amount = 0;
|
||||
var name = $(this).data('name');
|
||||
|
||||
var principal_amount_input = $(`#wiaas_principal_amount_${name}`).first();
|
||||
if (principal_amount_input) {
|
||||
principal_amount = parseFloat(principal_amount_input.val() / principal_amount_input.data('period')) || 0;
|
||||
}
|
||||
$(`#wiaas_minimal_recurrent_price_${name}`).text((minimal_services_price + principal_amount).toFixed(2));
|
||||
|
||||
var services_contract_period = $(this).data('period');
|
||||
if (services_contract_period > 0) {
|
||||
var final_services_price = minimal_services_price * services_contract_period;
|
||||
$(`#wiaas_minimal_services_price_${name}_final`).text(final_services_price.toFixed(2));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$('#wiaas_package_pricing_rules').delegate('.wiaas_principal_amount', 'change', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
var value = parseFloat($(this).val());
|
||||
var period = parseFloat($(this).data('period'));
|
||||
var interestRate = 0.58;
|
||||
|
||||
|
||||
var principal_amount = calculateFinancing(interestRate, period, value);
|
||||
var minimal_services_price = 0;
|
||||
var name = $(this).data('name');
|
||||
|
||||
var minimal_services_price_input = $(`#wiaas_minimal_services_price_${name}`).first();
|
||||
if (minimal_services_price_input) {
|
||||
minimal_services_price = parseFloat(minimal_services_price_input.val()) || 0;
|
||||
}
|
||||
|
||||
$(`#wiaas_minimal_recurrent_price_${name}`).text((minimal_services_price + principal_amount).toFixed(0));
|
||||
$(`#wiaas_minimal_recurrent_package_price_${name}`).text(principal_amount.toFixed(0));
|
||||
});
|
||||
|
||||
/**
|
||||
* Copy of Excel's PMT function.
|
||||
* Credit: http://stackoverflow.com/questions/2094967/excel-pmt-function-in-js
|
||||
*
|
||||
* @param ratePerPeriod The interest rate for the loan.
|
||||
* @param numberOfPayments The total number of payments for the loan in months.
|
||||
* @param presentValue The present value, or the total amount that a series of future payments is worth now;
|
||||
* Also known as the principal.
|
||||
* @param futureValue The future value, or a cash balance you want to attain after the last payment is made.
|
||||
* If fv is omitted, it is assumed to be 0 (zero), that is, the future value of a loan is 0.
|
||||
* @param type Optional, defaults to 0. The number 0 (zero) or 1 and indicates when payments are due.
|
||||
* 0 = At the end of period
|
||||
* 1 = At the beginning of the period
|
||||
* @returns {number}
|
||||
*/
|
||||
function calculateFinancing(ratePerPeriod, numberOfPayments, presentValue, futureValue = 0, type = 0) {
|
||||
/*var q = 0;
|
||||
var c = 0;
|
||||
const monthlyRatePerPeriod = ratePerPeriod / 12;
|
||||
|
||||
if (monthlyRatePerPeriod !== 0.0) {
|
||||
// Interest rate exists
|
||||
q = Math.pow(1 + monthlyRatePerPeriod, numberOfPayments);
|
||||
c = (monthlyRatePerPeriod * (futureValue + (q * presentValue))) / ((-1 + q) * (1 + monthlyRatePerPeriod * (type)));
|
||||
return c.toFixed(2);
|
||||
|
||||
} else if (numberOfPayments !== 0.0) {
|
||||
// No interest rate, but number of payments exists
|
||||
return -(futureValue + presentValue) / numberOfPayments;
|
||||
}
|
||||
|
||||
return 0;*/
|
||||
const rates = {
|
||||
24 : 4.282,
|
||||
30 : 3.451,
|
||||
36 : 2.896,
|
||||
42 : 2.500,
|
||||
48 : 2.223,
|
||||
54 : 2.025,
|
||||
60 : 1.834
|
||||
};
|
||||
|
||||
const interest = rates[numberOfPayments] || 10;
|
||||
|
||||
return presentValue * (interest / 100);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div class="wrap">
|
||||
<div class="poststuff">
|
||||
<div id="post-body" class="metabox-holder columns-2">
|
||||
|
||||
<div id="postbox-container-1" class="postbox-container">
|
||||
|
||||
<div class="postbox">
|
||||
<div class="inside">
|
||||
<div class="panel-wrap">
|
||||
|
||||
<div class="panel">
|
||||
<h3>Test</h3>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="postbox-container-2" class="postbox-container">
|
||||
|
||||
<div class="postbox">
|
||||
<div class="inside">
|
||||
<div class="panel-wrap">
|
||||
<div class="wrap">
|
||||
<div class="options_group">
|
||||
<?php
|
||||
woocommerce_wp_text_input(
|
||||
array(
|
||||
'id' => '_wiaas_max_cost_margin',
|
||||
'name' => 'wiaas_max_cost_margin',
|
||||
'value' => $max_cost_margin,
|
||||
'label' => __( 'Max cost margin:', 'wiaas' ),
|
||||
'type' => 'number',
|
||||
)
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="options_group">
|
||||
<?php
|
||||
woocommerce_wp_text_input(
|
||||
array(
|
||||
'id' => '_wiaas_price_commision',
|
||||
'name' => 'wiaas_pricing_rules_commision',
|
||||
'value' => $commission,
|
||||
'label' => __( 'Commision (Percent):', 'wiaas' ),
|
||||
'type' => 'number',
|
||||
)
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
|
||||
<div class="options_group">
|
||||
<div class="wc-metaboxes-wrapper">
|
||||
<?php
|
||||
$has_available_pay_types = false;
|
||||
$available_pay_types = Wiaas_Package_Pricing::get_available_pay_types();
|
||||
foreach ($available_pay_types as $name => $pay_type) {
|
||||
if (!isset($pricing_rule_sets[$name])) {
|
||||
$has_available_pay_types = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$class = $has_available_pay_types ? '' : 'wiaas_hidden';
|
||||
|
||||
?>
|
||||
<div id="wiaas_package_price_controls" class="toolbar toolbar-top <?php echo $class ?>">
|
||||
<select id="wiaas_pay_type" name="wiaas-pay-type" class="pricing_rule_mode">
|
||||
<?php
|
||||
foreach ($available_pay_types as $name => $pay_type) {
|
||||
?>
|
||||
<option
|
||||
value="<?php echo $name ?>"
|
||||
id="wiaas_pay_type_<?php echo $name ?>"
|
||||
class="<?php echo $class ?>"
|
||||
>
|
||||
<?php _e( $pay_type['title'], 'wiaas' ); ?>
|
||||
</option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<button
|
||||
title="<?php _e( 'Add pricing type.', 'wiaas' ); ?>"
|
||||
id="wiaas-add-pricing"
|
||||
type="button"
|
||||
class="button button-primary">
|
||||
<?php _e( 'Add Pricing Type', 'wiaas' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div id="wiaas_package_pricing_rules" class="wc-metaboxes">
|
||||
<?php
|
||||
require 'html-package-pricing-rules-list.php';
|
||||
?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -4,29 +4,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
}
|
||||
?>
|
||||
|
||||
<script>
|
||||
jQuery(document).ready(function($) {
|
||||
if ($('#product-type').val() === 'simple') {
|
||||
$('#general_product_data').find('.pricing').show();
|
||||
} else {
|
||||
$('#general_product_data').find('.pricing').hide();
|
||||
}
|
||||
|
||||
$('#general_product_data').find('.pricing').attr('class','wiaas_show_if_simple');
|
||||
|
||||
$('body').on('woocommerce-product-type-change', function (event, select_val) {
|
||||
|
||||
if ('simple' === select_val) {
|
||||
$('.wiaas_show_if_simple').show();
|
||||
} else {
|
||||
$('.wiaas_show_if_simple').hide();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php
|
||||
woocommerce_wp_checkbox(
|
||||
array(
|
||||
|
||||
Reference in New Issue
Block a user