function calculate_discounted_price($old_product, $new_product) { $formula_dao = new FormulaDAO(); $new_device_discount = $formula_dao->findOneByName('new_device_discount'); $delta_e = ($old_product->purchase_price - $new_product->purchase_price) * ($new_product->release_year - $old_product->release_year); $discount_percentage = min($delta_e * $new_device_discount->variable_1 * 0.01, $new_device_discount->variable_2); return round((1 - $discount_percentage) * $new_product->purchase_price); }
<?php require '../../include/global_functions.php'; loggedInOrRedirect(); $formula_dao = new FormulaDAO(); $new_device_discount = $formula_dao->findOneByName('new_device_discount'); if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($_POST['variable_1'] && $_POST['variable_2']) { $formula_dao->updateByName('new_device_discount', (double) $_POST['variable_1'], (double) $_POST['variable_2']); die(header('Location: manage_formulas.php?succeeded=yes')); } die(header('Location: manage_formulas.php?succeeded=no')); } $page['title'] = 'Manage formulas'; require '../../include/header.inc'; require '../../include/index.inc'; if ($_GET['succeeded']) { if ($_GET['succeeded'] == 'yes') { print '<div class="text-success">' . t('Changes saved successfully') . '.</div><br>'; } else { print '<div class="text-danger">' . t('No changes were saved') . '.</div><br>'; } } ?> <h3><?php echo t('Modify formulas'); ?> </h3> <form action="?" method="POST"> <b><?php echo t('Discount formula');