There is a column as Amount in my oracle apex tabular form. I need to calculate SUM of all fields under this column while data is being entered and display on a Display only field below the tabular form.
I think this can be done using JavaScript and call that JavaScript at onchange of Amount column.
But I don't know how to calculate SUMof Amountcolumn in my oracle apex tabular form. How could I do this?
Add the following JavaScript code into the Page HTML Header property:
<script type="text/javascript">
function tot_cal()
{
var f5=new Array();
var tol=0;
f5=document.getElementsByName("f05"); /*f05 is Apex array which holds the data*/
for(i=0;i<f5.length;i++){
tol = (tol*1) + (f5[i].value.replace(/,/g, '') * 1);
}
/* alert(tol); */
$s('P10_AMOUNT_VALUE', tol.formatMoney(2,',','.'));
}
Number.prototype.formatMoney = function(decPlaces, thouSeparator, decSeparator) {
var n = this,
decPlaces = isNaN(decPlaces = Math.abs(decPlaces)) ? 2 : decPlaces,
decSeparator = decSeparator == undefined ? "." : decSeparator,
thouSeparator = thouSeparator == undefined ? "," : thouSeparator,
sign = n < 0 ? "-" : "",
i = parseInt(n = Math.abs(+n || 0).toFixed(decPlaces)) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return sign + (j ? i.substr(0, j) + thouSeparator : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thouSeparator) + (decPlaces ? decSeparator + Math.abs(n - i).toFixed(decPlaces).slice(2) : "");
};
</script>
Tabular Form Element/Element Attributes property of the Amount column:
onchange="tot_cal();"
Related
I'm new around here, apologies in advance. I go with my question: I have a google spreadsheet with multiple cells and two sheets. What I am trying to do is that when I type a value in any cell in column 2, the time and date will automatically appear in the adjacent cell. I have gotten this code, which only worked for me on Sheet 1:
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "HOJA 1-HF-SSB" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( r.getColumn() == 2 ) { //checks the column
var nextCell = r.offset(0, 1);
if( nextCell.getValue() === '' ) //is empty?
nextCell.setValue(new Date()).setNumberFormat("dd-MM-yyyy HH:mm");
}
}
}
Then I have managed to simplify it and adapt it to work on both sheets of the document:
function onEdit(e) {
var sheets = ["HOJA 1-HF-SSB", "HOJA 2-FM-DMR"];
if (sheets.indexOf(e.source.getActiveSheet()
.getName()) === -1 || e.range.columnStart !== 2) return;
e.range.offset(0, 1)
.setValue(new Date()).setNumberFormat("dd-MM-yyyy HH:mm");
}
My questions are: Is there a way to get the date and time to go in separate columns? That is, when I fill in column 2, the date is written in column 3 and the time in column 4?
My final goal, apart from separating the date and time, is to determine later (I don't know how to do it) and highlight which values recorded in column 2 are duplicated on the same date, comparing them with the automatic dates in column 3, regardless of the time. Thank you and excuse me, I am a very newbie!
Try (only for column #2)
function onEdit(e) {
var sheets = ["HOJA 1-HF-SSB", "HOJA 2-FM-DMR"];
if (sheets.indexOf(e.source.getActiveSheet().getName()) === -1 || e.range.getColumn() !== 2) return;
var dateObj = new Date();
var month = dateObj.getUTCMonth() + 1; //months from 1-12
var day = dateObj.getUTCDate();
var year = dateObj.getUTCFullYear();
var newdate = year + "/" + month + "/" + day;
e.range.offset(0, 1).setValue(newdate).setNumberFormat("dd-MM-yyyy");
e.range.offset(0, 2).setValue(new Date()).setNumberFormat("HH:mm");
}
https://docs.google.com/spreadsheets/d/1NYxNfoPM6l_PJTPBDxEth2n-T_H0o03FG6C0OMDuJOo/copy
When the user select a range of dates on the calendar, a modal opens and the input fields of initial and final dates are auto complete with the dates selected previously. The problem is that they are displaying in this format YYYY-MM-DD and I want it to be DD-MM-YYYY. I have tried everything but nothing seems to work.
Here is where I get the dates and fill the inputs:
select: function (info) {
$('#ModalAdd').modal('show');
$('#ModalAdd').appendTo("body");
$('#activoReservar').val($('#selectActivoReserva option:selected').text());
$('#fechaInicial').val(info.startStr);
var endDate = new Date(info.end);
var beforeDay = new Date(endDate.getFullYear(),endDate.getMonth(),endDate.getDate() - 1).toISOString().slice(0,10);
$('#fechaFinal').val(beforeDay);
},
And here are the things I have tried:
$('#fechaInicial').val(info.startStr.format('ddd, DD-MM-YYYY')); //i tried with dd and a single d too. And without any d
$('#fechaFinal').val(beforeDay.format('ddd, DD-MM-YYYY'));
you may create another function (which you can use anywhere else too),
pass a date to that function and return your desired format.
The sample function might look like as follow:
function dateToDMY(date) {
var d = date.getDate();
var m = date.getMonth() + 1; //Month from 0 to 11
var y = date.getFullYear();
return '' + (d <= 9 ? '0' + d : d) + '-' + (m <= 9 ? '0' + m : m) + '-' + y;
}
And you may call the function from select or any other place as follow:
select: function (selectionInfo) {
var startStr = dateToDMY(selectionInfo.start);
}
I am creating a MVC application, and the user's have asked that on the datetimepicker if the values could be switched to intervals of 6.
So on this part of the datetimepicker:
Is there a way to change the values to 00, 06, 12, 18, etc?
Any help is appreciated.
I found it!
The original datetimepicker was based off of this:
fillMinutes = function () {
var table = widget.find('.timepicker-minutes table'),
currentMinute = viewDate.clone().startOf('h'),
html = [],
row = $('<tr>'),
step = options.stepping === 1 ? 5 : options.stepping;
while (viewDate.isSame(currentMinute, 'h')) {
if (currentMinute.minute() % (step * 4) === 0) {
row = $('<tr>');
html.push(row);
}
row.append('<td data-action="selectMinute" class="minute' + (!isValid(currentMinute, 'm') ? ' disabled' : '') + '">' + currentMinute.format('mm') + '</td>');
currentMinute.add(step, 'm');
}
table.empty().append(html);
},
so I changed the step = options.stepping === 1 ? 5 : options.stepping; to:
step = options.stepping === 1 ? 6 : options.stepping;
Trying to pull a list of ratings from a collection of Reviews and then average them to come up with an aggregated average rating for a Plate. When I look at the data output from the ratings variable I get nothing but "undefined undefined undefined".
averageRating: function() {
var reviews = Reviews.findOne({plateId: this._id});
var ratings = _.pluck(reviews, 'rating');
var sum = ratings.reduce(function(pv, cv){return pv + cv;}, 0);
var avg = sum / ratings.length;
//Testing output
var test = "";
var x;
for (x in reviews) {
text += reviews[x] + ',';
}
return test;
}
Sorry if this is a super newbie question, but I've been at this for hours and cannot figure it out.
I figured out the issue. As listed above var reviews gets set to a cursor which apparently .pluck does not work on. By first converting the cursor to an array of objects I was then able to use .pluck. So updated code looks like this:
averageRating: function() {
var reviewsCursor = Reviews.find({plateId: this._id});
//Converts cursor to an array of objects
var reviews = reviewsCursor.fetch();
var ratings = _.pluck(reviews, 'rating');
var sum = ratings.reduce(function(pv, cv){return pv + cv;}, 0);
var avg = (sum / ratings.length).toPrecision(2);
return avg;
}
I have an aspx(devexpress) grid. Using which I generate columns dynamically from code behind.Below is the code from my grid_databinding event.
GridViewDataTextColumn bfield = new GridViewDataTextColumn();
if (TestString.YearSelectedNames.ToString().Length > 4)
{ string colName = string.Empty;
if (iCount % 2 == 0)
{
colName = TestString.YearSelectedNames.ToString().Substring(5, 4) + "-" + dtFreezing.Columns[iCount].ColumnName.ToString();
bfield.HeaderTemplate = new DevxGridViewTemplate(ListItemType.Header, typeof(Label), colName, iCount);
}
else
{
colName = TestString.YearSelectedNames.ToString().Substring(0, 4) + "-" + dtFreezing.Columns[iCount].ColumnName.ToString().Replace('1', ' ');
bfield.HeaderTemplate = new DevxGridViewTemplate(ListItemType.Header, typeof(Label), colName, iCount);
}
}
else
{
bfield.HeaderTemplate = new DevxGridViewTemplate(ListItemType.Header, typeof(Label), dtFreezing.Columns[iCount].ColumnName.Trim(), iCount);
}
bfield.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
bfield.HeaderStyle.Wrap = DevExpress.Utils.DefaultBoolean.True;
bfield.Name = dtFreezing.Columns[iCount].ColumnName.Trim();
bfield.Width = Unit.Pixel(120);
bfield.VisibleIndex = iCount;
bfield.DataItemTemplate = new DevxGridViewTemplate(ListItemType.Item, typeof(Label), dtFreezing.Columns[iCount].ColumnName.Trim(), iCount);
bfield.CellStyle.HorizontalAlign = HorizontalAlign.Right;
bfield.PropertiesTextEdit.DisplayFormatString = "N2";
gridViewProductCrop.Columns.Add(bfield);
Here the line of code
bfield.PropertiesTextEdit.DisplayFormatString = "N2";
is where I am trying to set the property of the grids' column to display only two decimals after the decimal point.
This line of code doesn't seem to work in the first place.
I have even tried using "{0:0.00}" and "{0:N2}" but in vain
Possible reason being that I am writing this line of code in the grid's databinding event. But how else can I set the column properties from code behind
Try to change this code
bfield.PropertiesTextEdit.DisplayFormatString = "N2";
to
this.PropertiesTextEdit.DisplayFormatString = "N2";
i think this happen coz u loop the object(make a new object) and the properties would be overwrite.
CMIIW