Skip to content

Commit

Permalink
pledge editor funds to API and datatables ajaxified
Browse files Browse the repository at this point in the history
  • Loading branch information
crossan007 committed Aug 21, 2018
1 parent 5d54f97 commit 04e337b
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 28 deletions.
1 change: 1 addition & 0 deletions src/api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
require __DIR__ . '/routes/calendar/calendar.php';

// finance routes
require __DIR__ . '/routes/finance/finance-general.php';
require __DIR__ . '/routes/finance/finance-deposits.php';
require __DIR__ . '/routes/finance/finance-payments.php';

Expand Down
13 changes: 13 additions & 0 deletions src/api/routes/finance/finance-general.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

use ChurchCRM\Base\DonationFundQuery;
use Slim\Http\Request;
use Slim\Http\Response;

$app->group('/finance/', function () {

$this->get('funds', function ($request, $response, $args) {
$DonationFunds = DonationFundQuery::create()->filterByActive("true")->find();
return $response->withJSON($DonationFunds->toArray());
});
});
31 changes: 3 additions & 28 deletions src/v2/templates/finances/payment-fund-split.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,9 @@
<th class="<?= $PledgeOrPayment == 'Pledge' ? 'LabelColumn' : 'PaymentLabelColumn' ?>"><?= gettext('Comment') ?></th>
</tr>
</thead>
<tbody>
<?php
foreach ($fundId2Name as $fun_id => $fun_name) {
?>
<tr>
<td class="TextColumn"><?= $fun_name ?></td>
<td class="TextColumn">
<input class="FundAmount" type="number" step="any" name="<?= $fun_id ?>_Amount" id="<?= $fun_id ?>_Amount" value="<?= ($nAmount[$fun_id] ? $nAmount[$fun_id] : "") ?>"><br>
<font color="red"><?= $sAmountError[$fun_id] ?></font>
</td>
<?php
if ($bEnableNonDeductible) {
?>
<td class="TextColumn">
<input type="number" step="any" name="<?= $fun_id ?>_NonDeductible" id="<?= $fun_id ?>_NonDeductible" value="<?= ($nNonDeductible[$fun_id] ? $nNonDeductible[$fun_id] : "")?>" />
<br>
<font color="red"><?= $sNonDeductibleError[$fun_id]?></font>
</td>
<?php
} ?>
<td class="TextColumn">
<input type="text" size=40 name="<?= $fun_id ?>_Comment" id="<?= $fun_id ?>_Comment" value="<?= $sComment[$fun_id] ?>">
</td>
</tr>
<?php
} ?>
</tbody>
</table>
</div>
</div>
</div>
</div>


99 changes: 99 additions & 0 deletions src/v2/templates/finances/payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,105 @@

</div>

<script nonce="<?= SystemURLs::getCSPNonce() ?>" >
$(document).ready(function() {

$("#FamilyName").select2({
minimumInputLength: 2,
ajax: {
url: function (params){
var a = window.CRM.root + '/api/families/search/'+ params.term;
return a;
},
dataType: 'json',
delay: 250,
data: "",
processResults: function (data, params) {
var results = [];
var families = JSON.parse(data).Families
$.each(families, function(key, object) {
results.push({
id: object.Id,
text: object.displayName
});
});
return {
results: results
};
}
}
});

$("#FamilyName").on("select2:select", function (e) {
$('[name=FamilyID]').val(e.params.data.id);
});

$("#FundTable").DataTable({
"language": {
"url": window.CRM.plugin.dataTable.language.url
},
responsive:true,
paging: false,
searching: false,
"dom": window.CRM.plugin.dataTable.dom,
ajax: {
url: window.CRM.root + "/api/finance/funds",
"dataSrc":""
},
columns: [
{
title: i18next.t('FundName'),
data: 'Name'
},
{
title: i18next.t('Amount'),
data: '',
render: function (data, type, full, meta) {
console.log(full);
return '<input class="FundAmount" type="number" step="any" name="'+full.Id+'_Amount" id="'+full.Id+'_Amount" value="">';
}
}
],

});


$(".FundAmount").change(function(){
CalculateTotal();
});

$("#Method").change(function() {
EvalCheckNumberGroup();
});

EvalCheckNumberGroup();
CalculateTotal();
});

function EvalCheckNumberGroup()
{
if ($("#Method option:selected").val()==="CHECK") {
$("#checkNumberGroup").show();
}
else
{
$("#checkNumberGroup").hide();
$("#CheckNo").val('');
}
}
function CalculateTotal() {
var Total = 0;
$(".FundAmount").each(function(object){
var FundAmount = Number($(this).val());
if (FundAmount >0 )
{
Total += FundAmount;
}
});
$("#TotalAmount").val(Total);
}
</script>


<?php
require SystemURLs::getDocumentRoot() . '/Include/Footer.php';
Expand Down

0 comments on commit 04e337b

Please sign in to comment.