Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 411: Pricing formulas #522

Open
wants to merge 17 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@

<?php } ?>

<tr><td><div class='adminMenuLink'><a href='javascript:void(0);' class='PricingFormulaLink'><?php echo _("Pricing Formulas");?></div></td></tr>
<tr><td><div class='adminMenuLink'><a href='javascript:void(0);' id='PurchaseSite' class='AdminLink'><?php echo _("Purchasing Site");?></div></td></tr>
<tr><td><div class='adminMenuLink'><a href='javascript:void(0);' id='ResourceFormat' class='AdminLink'><?php echo _("Resource Format");?></div></td></tr>
<tr><td><div class='adminMenuLink'><a href='javascript:void(0);' id='ResourceType' class='AdminLink'><?php echo _("Resource Type");?></div></td></tr>
Expand Down
60 changes: 60 additions & 0 deletions resources/admin/classes/domain/PricingFormula.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/*
**************************************************************************************************************************
** CORAL Resources Module v. 1.0
**
** Copyright (c) 2010 University of Notre Dame
**
** This file is part of CORAL.
**
** CORAL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
**
** CORAL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License along with CORAL. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************************************************************
*/

class PricingFormula extends DatabaseObject {

protected function defineRelationships() {}

public function allAsArray() {
$query = "SELECT * FROM PricingFormula ORDER BY 1";
$result = $this->db->processQuery($query, 'assoc');

$resultArray = array();
$rowArray = array();

if (isset($result['pricingFormulaID'])){
foreach (array_keys($result) as $attributeName) {
$rowArray[$attributeName] = $result[$attributeName];
}
array_push($resultArray, $rowArray);
}else{
foreach ($result as $row) {
foreach (array_keys($this->attributeNames) as $attributeName) {
$rowArray[$attributeName] = $row[$attributeName];
}
array_push($resultArray, $rowArray);
}
}

return $resultArray;
}

public function getFieldValues() {
$fieldValues = array();
for ($i = 1; $i <= 10; $i++) {
$memberName = "field${i}Name";
if ($this->$memberName)
$fieldValues[$memberName] = $this->$memberName;
}
return $fieldValues;
}

}

?>
10 changes: 10 additions & 0 deletions resources/admin/classes/domain/ResourcePayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public function getPaymentAmountChangeFromPreviousYear(){
}
return 'n/a';
}

public function getFormulaValues() {
$fieldValues = array();
for ($i = 1; $i <= 10; $i++) {
$memberName = "field${i}Value";
if ($this->$memberName)
$fieldValues['field' . $i . 'Name'] = $this->$memberName;
}
return $fieldValues;
}
}

?>
39 changes: 39 additions & 0 deletions resources/ajax_forms/getAdminPricingFormulaUpdateForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

$pricingFormulaID = $_GET['pricingFormulaID'];

if ($pricingFormulaID){
$instance = new PricingFormula(new NamedArguments(array('primaryKey' => $pricingFormulaID)));
} else {
$instance = new PricingFormula();
}
?>
<div id='div_updateForm'>
<form id="pricingFormulaConfig">
<input type='hidden' name='pricingFormulaID' id='pricingFormulaID' value='<?php echo $pricingFormulaID; ?>' />

<div class='formTitle' style='width:280px; margin-bottom:5px;position:relative;'><span class='headerText'><?php if ($pricingFormulaID){ echo _("Edit pricing formula"); } else { echo _("Add pricing formula"); } ?></span></div>
<table>
<tr>
<td><label for="formulaName"><b><?php echo _("Name"); ?>:</b></label></td><td><input type="text" value="<?php echo $instance->shortName; ?>" name="formulaName" /></td>
</tr><tr>
<?php

for ($i = 1; $i <= 10; $i++) {
$memberName = "field${i}Name";
echo ("<tr><td><label for='$memberName'><b>" . _("Field") ." $i:</b></label></td><td><input type='text' value=\"" . htmlentities($instance->$memberName) . "\" name='$memberName' /></td></tr>");
}

?>
<tr><td><label for="formula"><b><?php echo _("Formula"); ?>:</b></label></td>
<td><textarea name="formula" id="formula"><?php echo $instance->formula; ?></textarea></td></tr>
</table><br />
<button class="btn btn-primary" type="submit" ><?php echo _("Save"); ?></button>
</form>
<p><?php echo _("To help you fill your own pricing formulas, here is an example:"); ?>
<br />
<?php echo _("adding an arbitrary tax rate."); ?></p>
<ul><li><?php echo _("Name: Custom tax rate"); ?></li>
<li><?php echo _("Field 1: price"); ?></li>
<li><?php echo _("Field 2: tax rate"); ?></li>
<li><?php echo _("Formula: price + (tax rate * price / 100)"); ?></li>
90 changes: 69 additions & 21 deletions resources/ajax_forms/getCostForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
$costDetailsObj = new CostDetails();
$costDetailsArray = $costDetailsObj->allAsArray();

// get all pricing formulas
$formulaObj = new PricingFormula();
$formulaArray = $formulaObj->allAsArray();
$formulaEnabled = sizeof($formulaArray) > 0;

//get payments
$sanitizedInstance = array();
$instance = new ResourcePayment();
Expand All @@ -41,9 +46,9 @@

// Table geometry is different if enhanced cost history is enabled
$baseWidth = 345;
$numCols = 6;
$numCols = 7;
if ($enhancedCostFlag){
$baseWidth += 688;
$baseWidth += 638;
$numCols += 8; // year, sub start, sub end, cost details, invoice num
}

Expand Down Expand Up @@ -76,10 +81,13 @@
<th><?php echo _("Fund");?></th>
<?php if ($enhancedCostFlag){ ?>
<th><?php echo _("Tax Excl.");?></th>
<th><?php echo _("Tax Rate");?></th>
<th><?php echo _("Rate");?></th>
<th><?php echo _("Tax Incl.");?></th>
<?php } ?>
<th><?php echo _("Payment");?></th>
<?php if ($formulaEnabled) { ?>
<th><?php echo _("Formula");?></th>
<?php } ?>
<th><?php echo _("Payment");?></th>
<th><?php echo _("Currency");?></th>
<th><?php echo _("Type");?></th>
<?php if ($enhancedCostFlag){ ?>
Expand All @@ -98,10 +106,10 @@
<td>
<input type='text' value='' class='changeDefaultWhite changeInput year costHistoryYear' />
</td>
<td>
<td class="date-pick-td">
<input type='text' value='' class='date-pick changeDefaultWhite changeInput subscriptionStartDate costHistorySubStart' placeholder='mm/dd/yyyy' />
</td>
<td>
<td class="date-pick-td">
<input type='text' value='' class='date-pick changeDefaultWhite changeInput subscriptionEndDate costHistorySubEnd' placeholder='mm/dd/yyyy' />
</td>
<?php } ?>
Expand All @@ -123,15 +131,29 @@
</td>
<?php if ($enhancedCostFlag){ ?>
<td>
<input type='text' value='' style='width:60px;' class='changeDefaultWhite changeInput priceTaxExcluded' />
<input type='text' value='' style='width:40px;' class='changeDefaultWhite changeInput priceTaxExcluded' />
</td>
<td>
<input type='text' value='' style='width:60px;' class='changeDefaultWhite changeInput taxRate' />
<input type='text' value='' style='width:20px;' class='changeDefaultWhite changeInput taxRate' />
</td>
<td>
<input type='text' value='' style='width:60px;' class='changeDefaultWhite changeInput priceTaxIncluded' />
<input type='text' value='' style='width:40px;' class='changeDefaultWhite changeInput priceTaxIncluded' />
</td>
<?php } ?>
<?php }
if ($formulaEnabled) {
?>
<td class="formulaSelectTD">
<select name="formulaSelect" class="formulaSelect">
<option value=""><?php echo _("None"); ?></option>
<?php
foreach ($formulaArray as $formula) {
echo ('<option value="' . $formula['pricingFormulaID'] . '">' . $formula['shortName'] . '</option>');
}
?>
</select>
<a href="#" class="showFormula">+</a>
</td>
<?php } ?>
<td>
<input type='text' value='' class='changeDefaultWhite changeInput paymentAmount costHistoryPayment' />
</td>
Expand Down Expand Up @@ -189,8 +211,6 @@
<input class='addPayment add-button' title='<?php echo _("add payment");?>' type='button' value='<?php echo _("Add");?>'/>
</a>
</td>


</tr>
<tr>
<td colspan='<?php echo $numCols; ?>'>
Expand All @@ -199,6 +219,11 @@
<hr style='width:<?php echo $baseWidth; ?>px;margin:0px 0px 5px 5px;' />
</td>
</tr>
<tr class="newFormulaTR">
<td colspan='<?php echo $numCols; ?>'>
<div class="formulaDiv"></div>
</td>
</tr>
</tbody>
</table>
<div class='paymentTableDiv'>
Expand All @@ -208,15 +233,16 @@
if (count($paymentArray) > 0){
foreach ($paymentArray as $payment){
?>
<tr>
<tr class="paymentTR">
<input type="hidden" name="resourcePaymentID" value="<?php echo $payment['resourcePaymentID']; ?>" />
<?php if ($enhancedCostFlag){ ?>
<td>
<input type='text' value='<?php echo $payment['year']; ?>' class='changeInput year costHistoryYear' />
</td>
<td>
<td class="date-pick-td">
<input type='text' value='<?php echo normalize_date($payment['subscriptionStartDate']); ?>' class='date-pick changeInput subscriptionStartDate costHistorySubStart' />
</td>
<td>
<td class="date-pick-td">
<input type='text' value='<?php echo normalize_date($payment['subscriptionEndDate']); ?>' class='date-pick changeInput subscriptionEndDate costHistorySubEnd' />
</td>
<?php } ?>
Expand Down Expand Up @@ -252,15 +278,33 @@
</td>
<?php if ($enhancedCostFlag){ ?>
<td>
<input type='text' value='<?php echo integer_to_cost($payment['priceTaxExcluded']); ?>' style='width:60px;' class='changeInput priceTaxExcluded' />
<input type='text' value='<?php echo integer_to_cost($payment['priceTaxExcluded']); ?>' style='width:40px;' class='changeInput priceTaxExcluded' />
</td>
<td>
<input type='text' value='<?php echo integer_to_cost($payment['taxRate']); ?>' style='width:60px;' class='changeInput taxRate' />
<input type='text' value='<?php echo integer_to_cost($payment['taxRate']); ?>' style='width:20px;' class='changeInput taxRate' />
</td>
<td>
<input type='text' value='<?php echo integer_to_cost($payment['priceTaxIncluded']); ?>' style='width:60px;' class='changeInput priceTaxIncluded' />
<input type='text' value='<?php echo integer_to_cost($payment['priceTaxIncluded']); ?>' style='width:40px;' class='changeInput priceTaxIncluded' />
</td>
<?php } ?>
<?php }
if ($formulaEnabled) {
?>
<td class="formulaSelectTD">
<input type="hidden" name="paymentPricingFormulaID" value="<?php echo $payment['pricingFormulaID']; ?>" />
<select name="formulaSelect" class="formulaSelect">
<option value=""><?php echo _("None"); ?></option>
<?php
foreach ($formulaArray as $formula) {
echo ('<option value="' . $formula['pricingFormulaID'] . '"');
if ($payment['pricingFormulaID'] == $formula['pricingFormulaID'])
echo (' selected="selected"');
echo ('>' . $formula['shortName'] . '</option>');
}
?>
</select>
<a href="#" class="showFormula">+</a>
</td>
<?php } ?>
<td>
<input type='text' value='<?php echo integer_to_cost($payment['paymentAmount']); ?>' class='changeInput paymentAmount costHistoryPayment' />
</td>
Expand Down Expand Up @@ -338,7 +382,12 @@
<div class='smallDarkRedText div_errorPayment' style='margin:0px 20px 0px 26px;'></div>
</td>
</tr>
<tbody>
<tr class="formulaTR">
<td colspan='<?php echo $numCols; ?>'>
<div class="formulaDiv"></div>
</td>
</tr>
</tbody>

<?php }} ?>
</table>
Expand All @@ -361,7 +410,6 @@


<hr style='width:100%;margin:15px 0px 10px 0px;' />

<table class='noBorderTable' style='width:125px;'>
<tr>
<td style='text-align:left'><input type='button' value='<?php echo _("submit");?>' name='submitCost' id ='submitCost' class='submit-button'></td>
Expand Down
35 changes: 35 additions & 0 deletions resources/ajax_forms/getPricingFormulaForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

$pricingFormulaID = isset($_GET['pricingFormulaID']) ? $_GET['pricingFormulaID'] : null;
$resourcePaymentID = isset($_GET['resourcePaymentID']) ? $_GET['resourcePaymentID'] : null;
$instance = new PricingFormula(new NamedArguments(array('primaryKey' => $pricingFormulaID)));
if ($resourcePaymentID) {
$rp = new ResourcePayment(new NamedArguments(array('primaryKey' => $resourcePaymentID)));
}
?>
<input type="hidden" id="formulaID" class="formulaID" value="<?php echo $instance->pricingFormulaID; ?>" />
<table>
<tr><td><?php echo _("Formula");?>:</td><td><?php echo $instance->formula; ?></td></tr>
<?php
if ($rp->pricingFormulaID) {
$fieldValues = $instance->getFieldValues();
$formulaValues = $rp->getFormulaValues();
$formula = $instance->formula;
foreach ($fieldValues as $dbName => $formulaElementName) {
$formula = str_replace($formulaElementName, ($formulaValues[$dbName] ? number_format($formulaValues[$dbName] / 100, 2, '.', '') : 0), $formula);
}
echo "<tr><td>" . _("With values") . ":</td><td>" . $formula . "</td></tr>";
}
for ($i = 1; $i <= 10; $i++) {
$memberName = "field${i}Name";
$memberValue = "field${i}Value";
if ($instance->$memberName) {
echo ("<tr><td><label for='$memberName'>" . $instance->$memberName . "</label>:</td><td><input type='text' name='$memberName'");
if (isset($rp))
echo (" value='" . ($rp->$memberValue ? number_format($rp->$memberValue / 100, 2, '.', '') : 0) . "'");
echo ('/></td></tr>');
}
}
?>
</table>
<button class="btn btn-primary" id="addFormulaButton" >Save</button>
2 changes: 1 addition & 1 deletion resources/ajax_htmldata/getAcquisitionsDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if ($enhancedCostFlag){
$numCols = 12;
$tableWidth = 760;
$formWidth = 1084;
$formWidth = 1034;
?>
<!-- Hide the helpful links, etc. -->
<script>
Expand Down
38 changes: 38 additions & 0 deletions resources/ajax_htmldata/getAdminPricingFormulas.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

$instanceArray = array();
$obj = new PricingFormula();

$instanceArray = $obj->allAsArray();

echo "<div class='adminRightHeader'>"._("Pricing formulas")."</div>";

if (count($instanceArray) > 0){
?>
<table class='linedDataTable'>
<tr>
<th style='width:100%;'><?php echo _("Name");?></th>
<th>&nbsp;</th>
<th>&nbsp;</th>
</tr>
<?php

foreach($instanceArray as $instance) {
echo "<tr>";
echo "<td>" . $instance['shortName'] . "</td>";
echo "<td><a href='ajax_forms.php?action=getAdminPricingFormulaUpdateForm&pricingFormulaID=" . $instance['pricingFormulaID'] . "&height=530&width=385&modal=true' class='thickbox'><img src='images/edit.gif' alt='"._("edit")."' title='"._("edit")."'></a></td>";
echo "<td><a href='javascript:deletePricingFormula(" . $instance['pricingFormulaID'] . ");'><img src='images/cross.gif' alt='"._("remove")."' title='"._("remove")."'></a></td>";
echo "</tr>";
}

?>
</table>
<?php

}else{
echo _("(none found)");
}

echo "<a href='ajax_forms.php?action=getAdminPricingFormulaUpdateForm&updateID=&height=530&width=385&modal=true' class='thickbox'>"._("add new formula")."</a>";

?>
Loading