Skip to content

Commit

Permalink
(issue #15) and (issue #17)Fixed. Also Add date validity check to dat…
Browse files Browse the repository at this point in the history
…e fields in Cost History
  • Loading branch information
mang committed May 20, 2016
1 parent a2a5de9 commit c2dc731
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 22 deletions.
16 changes: 14 additions & 2 deletions resources/admin/classes/domain/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,18 @@ public function export($whereAdd, $orderBy){

}


if ($config->settings->enhancedCostHistory == 'Y'){
$costHistSelectAdd = "GROUP_CONCAT(COALESCE(RPAY.year,'null'), '|', COALESCE(RPAY.subscriptionStartDate,'null'), '|', COALESCE(RPAY.subscriptionEndDate,'null'), '|',
COALESCE(RPAY.fundName,'null'), '|', ROUND(COALESCE(RPAY.paymentAmount, 0) / 100, 2), RPAY.currencyCode, '|', OT.shortName, '|',
COALESCE(CD.shortName, 'null'), '|', COALESCE(RPAY.costNote, 'null'), '|', COALESCE(RPAY.invoiceNum, 'null'), '|' ORDER BY RPAY.paymentAmount ASC SEPARATOR '; ') payments";
$costDetailsJoinAdd = " LEFT JOIN CostDetails CD ON CD.costDetailsID = RPAY.costDetailsID";
}

else {
$costHistSelectAdd = "GROUP_CONCAT(COALESCE(RPAY.fundName,'null'), '|', ROUND(COALESCE(RPAY.paymentAmount, 0) / 100, 2), RPAY.currencyCode, '|', OT.shortName, '|',
COALESCE(RPAY.costNote, 'null') ,'|' ORDER BY RPAY.paymentAmount ASC SEPARATOR '; ') payments";
$costDetailsJoinAdd = "";
}
$status = new Status();
//also add to not retrieve saved records
$savedStatusID = intval($status->getIDFromName('saved'));
Expand Down Expand Up @@ -1445,7 +1456,7 @@ public function export($whereAdd, $orderBy){
GROUP_CONCAT(DISTINCT ADS.shortName ORDER BY ADS.shortName DESC SEPARATOR '; ') administeringSites,
GROUP_CONCAT(DISTINCT RP.titleText ORDER BY RP.titleText DESC SEPARATOR '; ') parentResources,
GROUP_CONCAT(DISTINCT RC.titleText ORDER BY RC.titleText DESC SEPARATOR '; ') childResources,
GROUP_CONCAT(DISTINCT RPAY.fundName, ': ', ROUND(COALESCE(RPAY.paymentAmount, 0) / 100, 2), ' ', RPAY.currencyCode, ' ', OT.shortName ORDER BY RPAY.paymentAmount ASC SEPARATOR '; ') payments
" . $costHistSelectAdd . "
FROM Resource R
LEFT JOIN Alias A ON R.resourceID = A.resourceID
LEFT JOIN ResourceOrganizationLink ROL ON R.resourceID = ROL.resourceID
Expand All @@ -1462,6 +1473,7 @@ public function export($whereAdd, $orderBy){
LEFT JOIN ResourceStep RS ON R.resourceID = RS.resourceID
LEFT JOIN ResourcePayment RPAY ON R.resourceID = RPAY.resourceID
LEFT JOIN OrderType OT ON RPAY.orderTypeID = OT.orderTypeID
" . $costDetailsJoinAdd . "
LEFT JOIN Status S ON R.statusID = S.statusID
LEFT JOIN ResourceNote RN ON R.resourceID = RN.resourceID
LEFT JOIN NoteType NT ON RN.noteTypeID = NT.noteTypeID
Expand Down
8 changes: 4 additions & 4 deletions resources/ajax_forms/getCostForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@
<td style='vertical-align:top;text-align:left;background:white;'>
<input type='text' value='' style='width:53px;' class='changeDefaultWhite changeInput year' /></td>
<td style='vertical-align:top;text-align:left;background:white;'>
<input type='text' value='' style='width:60px;' class='date-pick changeDefaultWhite changeInput subscriptionStartDate' /></td>
<input type='text' value='' style='width:60px;' class='date-pick changeDefaultWhite changeInput subscriptionStartDate' placeholder='mm/dd/yyyy' /></td>
<td style='vertical-align:top;text-align:left;background:white;'>
<input type='text' value='' style='width:60px;' class='date-pick changeDefaultWhite changeInput subscriptionEndDate' /></td>
<input type='text' value='' style='width:60px;' class='date-pick changeDefaultWhite changeInput subscriptionEndDate' placeholder='mm/dd/yyyy' /></td>
<?php } ?>
<td style='vertical-align:top;text-align:left;background:white;'>
<input type='text' value='' style='width:60px;' class='changeDefaultWhite changeInput fundName' />
Expand Down Expand Up @@ -156,9 +156,9 @@
<input type='text' value='<?php echo $payment['year']; ?>' style='width:53px;' class='changeInput year' />
</td>
<td style='vertical-align:top;text-align:left;'>
<input type='text' value='<?php echo normalize_date($payment['subscriptionStartDate']); ?>' style='width:60px;' class='date-pick changeInput subscriptionStartDate' /></td>
<input type='text' value='<?php echo normalize_date($payment['subscriptionStartDate']); ?>' style='width:60px;' class='date-pick changeInput subscriptionStartDate' placeholder='mm/dd/yyyy' /></td>
<td style='vertical-align:top;text-align:left;'>
<input type='text' value='<?php echo normalize_date($payment['subscriptionEndDate']); ?>' style='width:60px;' class='date-pick changeInput subscriptionEndDate' /></td>
<input type='text' value='<?php echo normalize_date($payment['subscriptionEndDate']); ?>' style='width:60px;' class='date-pick changeInput subscriptionEndDate' placeholder='mm/dd/yyyy' /></td>
<?php } ?>
<td style='vertical-align:top;text-align:left;'>
<input type='text' value='<?php echo $payment['fundName']; ?>' style='width:60px;' class='changeInput fundName' />
Expand Down
40 changes: 38 additions & 2 deletions resources/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ function validateDate(field,alerttxt) {


function isAmount(pAmount){

pAmount = pAmount.replace('$','');
pAmount = pAmount.replace('$','');
pAmount = pAmount.replace(',','');

if (isNaN(pAmount)){
Expand Down Expand Up @@ -283,3 +282,40 @@ function postwith (to,p) {
document.body.removeChild(myForm) ;
}


function isValidDate(dateString)
{
// First check for the pattern
var regex_date = /^\d{1,2}\/\d{1,2}\/\d{4}$/;

if(!regex_date.test(dateString))
{
return false;
}

// Parse the date parts to integers
//borrowed from http://jsfiddle.net/niklasvh/xfrLm/
//http://stackoverflow.com/questions/6177975/how-to-validate-date-with-format-mm-dd-yyyy-in-javascript
var parts = dateString.split("/");
var day = parseInt(parts[1], 10);
var month = parseInt(parts[0], 10);
var year = parseInt(parts[2], 10);


// Check the ranges of month and year
if(year < 1000 || year > 3000 || month == 0 || month > 12)
{
return false;
}

var monthLength = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];

// Adjust for leap years
if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
{
monthLength[1] = 29;
}

// Check the range of the day
return day > 0 && day <= monthLength[month - 1];
}
11 changes: 8 additions & 3 deletions resources/js/forms/costForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,19 @@ $(function(){
$(".addPayment").live('click', function () {

var y = $('.newPaymentTable').children().children().children().children('.year').val();
var ssd = $('.newPaymentTable').children().children().children().children('.susbcriptionStartDate').val();
var sed = $('.newPaymentTable').children().children().children().children('.susbcriptionEndDate').val();
var ssd = $('.newPaymentTable').children().children().children().children('.subscriptionStartDate').val();
var sed = $('.newPaymentTable').children().children().children().children('.subscriptionEndDate').val();
var fName = $('.newPaymentTable').children().children().children().children('.fundName').val();
var typeID = $('.newPaymentTable').children().children().children().children('.orderTypeID').val();
var detailsID = $('.newPaymentTable').children().children().children().children('.costDetailsID').val();
var pAmount = $('.newPaymentTable').children().children().children().children('.paymentAmount').val();
var cNote = $('.newPaymentTable').children().children().children().children('.costNote').val();


if (isValidDate(ssd)=== false || isValidDate(sed)=== false ) {
$('#div_errorPayment').html(_("Error - for dates, use MM/DD/YYYY format."));
return false;
}

if ((pAmount == '' || pAmount == null) && (fName == '' || fName == null)){
$('#div_errorPayment').html(_("Error - Either amount or fund is required"));
return false;
Expand Down
67 changes: 56 additions & 11 deletions resources/summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
$resourceID = $_GET['resourceID'];
$resource = new Resource(new NamedArguments(array('primaryKey' => $resourceID)));

//used to get default currency
$config = new Configuration();
$enhancedCostFlag = ($config->settings->enhancedCostHistory == 'Y') ? 1 : 0;

//if this is a valid resource
if ($resource->titleText){
Expand Down Expand Up @@ -107,8 +110,7 @@
foreach ($resource->getResourceAuthorizedSites() as $instance) {
$authorizedSiteArray[]=$instance->shortName;
}



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

$orderType = new OrderType(new NamedArguments(array('primaryKey' => $instance->orderTypeID)));
$sanitizedInstance['orderType'] = $orderType->shortName;

$costDetails = new CostDetails(new NamedArguments(array('primaryKey' => $instance->costDetailsID)));
$sanitizedInstance['costDetails'] = $costDetails->shortName;


array_push($paymentArray, $sanitizedInstance);
Expand Down Expand Up @@ -482,21 +487,61 @@

<table class='linedFormTable'>
<tr>
<th colspan='3'><?php echo _("Cost History");?></th>
<th colspan='2' style='vertical-align:bottom;'>
<span style='float:left;vertical-align:bottom;'><?php echo _("Cost History");?></span>
</th>
</tr>

<?php
if (count($paymentArray) > 0){
foreach ($paymentArray as $payment){ ?>
<tr>
<td><?php echo $payment['fundName']; ?></td>
<td><?php echo $payment['currencyCode'] . " " . integer_to_cost($payment['paymentAmount']); ?></td>
<td><?php echo $payment['orderType']; ?></td>
if (count($paymentArray) > 0){
foreach ($paymentArray as $payment){ ?>
<tr><td style='vertical-align:top;width:150px;' colspan='2'></td></tr>
<?php if ($enhancedCostFlag){ ?>
<tr>
<td style='vertical-align:top;width:150px;'><?php echo _("Year:");?></td>
<td><?php echo $payment['year']; ?></td>
</tr>
<tr>
<td style='vertical-align:top;width:150px;'><?php echo _("Sub StartDate:");?></td>
<td><?php echo $payment['subscriptionStartDate']; ?></td>
</tr>
<tr>
<td style='vertical-align:top;width:150px;'><?php echo _("Sub EndDate:");?></td>
<td><?php echo $payment['subscriptionEndDate']; ?></td>
</tr>
<?php } ?>
<tr>
<td style='vertical-align:top;width:150px;'><?php echo _("Fund:");?></td>
<td><?php echo $payment['fundName']; ?></td>
</tr>
<tr>
<td style='vertical-align:top;width:150px;'><?php echo _("Payment:");?></td>
<td><?php echo $payment['currencyCode'] . " " . integer_to_cost($payment['paymentAmount']); ?></td>
</tr>
<tr>
<td style='vertical-align:top;width:150px;'><?php echo _("Order Type:");?></td>
<td><?php echo $payment['orderType']; ?></td>
</tr>
<?php if ($enhancedCostFlag){ ?>
<tr>
<td style='vertical-align:top;width:150px;'><?php echo _("Details:");?></td>
<td><?php echo $payment['costDetails']; ?></td>
</tr>
<?php } ?>
<tr>
<td style='vertical-align:top;width:150px;'><?php echo _("Note:");?></td>
<td><?php echo $payment['costNote']; ?></td>
</tr>
<?php if ($enhancedCostFlag){ ?>
<tr>
<td style='vertical-align:top;width:150px;'><?php echo _("Invoice No.:");?></td>
<td><?php echo $payment['invoiceNum']; ?></td>
</tr>
<?php } ?>


<?php
}
<?php
}
}else{
echo "<tr><td colspan='3'><i>"._("No payment information available.")."</i></td></tr>";
}
Expand Down

0 comments on commit c2dc731

Please sign in to comment.