Initial commit.
This commit is contained in:
152
htdocs/emandy/scripts/accounting.js
Normal file
152
htdocs/emandy/scripts/accounting.js
Normal file
@@ -0,0 +1,152 @@
|
||||
/* Mandy Wu's Website
|
||||
* accounting.js: The accounting-related JavaScript subroutines.
|
||||
*/
|
||||
|
||||
/* Copyright (c) 2007-2018 imacat.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* Author: imacat <imacat@mail.imacat.idv.tw>
|
||||
* First written: 2007-09-26
|
||||
*/
|
||||
|
||||
// setAutoSummary: Automatically supply a summary
|
||||
function setAutoSummary(subj) {
|
||||
var i, j, sum, dateText, today, subjText, subjCode, thisMonth;
|
||||
// Get the name prefix of this selection
|
||||
i = subj.name.indexOf("subj");
|
||||
// Obtain the summary column
|
||||
sum = subj.form[subj.name.substr(0, i) + "summary"];
|
||||
// Get today's date
|
||||
today = new Date;
|
||||
dateText = trim(subj.form.date.value);
|
||||
if (!isDate(dateText))
|
||||
return;
|
||||
today.setFullYear(dateText.substr(0, 4));
|
||||
today.setMonth(dateText.substr(5, 2) - 1);
|
||||
today.setDate(dateText.substr(8, 2));
|
||||
thisMonth = today.getMonth() + 1;
|
||||
// Obtain the selected subject
|
||||
// The value of the selection is S/N but not subject code,
|
||||
// so we have to obtain the subject code from the option text
|
||||
subjText = subj.options[subj.selectedIndex].text;
|
||||
subjCode = parseInt(subjText.substr(0, subjText.indexOf(" ")));
|
||||
switch (subjCode) {
|
||||
// 62561 和信 0927-02-1680
|
||||
case 62561:
|
||||
sum.value = "和信" + ((thisMonth + 10) % 12 + 1) + "月";
|
||||
break;
|
||||
// 21412 應付帳款—玉山信用卡
|
||||
case 21412:
|
||||
// Only fill in the debit side, as our repay
|
||||
if (sum.name.substr(0, 4) == "debt") {
|
||||
// 25 or later - assume to be of this month
|
||||
if (today.getDate() >= 25) {
|
||||
sum.value = "玉山信用卡" + thisMonth + "月";
|
||||
// Before 25 - assume to be of previous month
|
||||
} else {
|
||||
sum.value = "玉山信用卡" + ((thisMonth + 10) % 12 + 1) + "月";
|
||||
}
|
||||
}
|
||||
break;
|
||||
// 21413 應付帳款—台新信用卡
|
||||
case 21413:
|
||||
// Only fill in the debitowing side, as our repay
|
||||
if (sum.name.substr(0, 4) == "debt") {
|
||||
// 25 or later - assume to be of this month
|
||||
if (today.getDate() >= 25) {
|
||||
sum.value = "台新信用卡" + thisMonth + "月";
|
||||
// Before 25 - assume to be of previous month
|
||||
} else {
|
||||
sum.value = "台新信用卡" + ((thisMonth + 10) % 12 + 1) + "月";
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// acctRepQueryDisableNoUseRanges: Disable range parameters that are not in use
|
||||
function acctRepQueryDisableNoUseRanges() {
|
||||
var i, form, curValue;
|
||||
// Obtain our form
|
||||
form = document.forms["acctrepquery"];
|
||||
if (form == undefined)
|
||||
return;
|
||||
// Find the current selection
|
||||
for (i = 0; i < form.r.length; i++) {
|
||||
if (form["r"][i].checked) {
|
||||
curValue = form["r"][i].value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Disable or enable the month selection
|
||||
if (curValue == "m")
|
||||
form["m"].disabled = false;
|
||||
else
|
||||
form["m"].disabled = true;
|
||||
// Disable or enable the year selection
|
||||
if (curValue == "y")
|
||||
form["y"].disabled = false;
|
||||
else
|
||||
form["y"].disabled = true;
|
||||
// Disable or enable the start and end date
|
||||
if (curValue == "s") {
|
||||
form["f"].disabled = false;
|
||||
form["t"].disabled = false;
|
||||
} else {
|
||||
form["f"].disabled = true;
|
||||
form["t"].disabled = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// calcTotal: Calculating the total
|
||||
function calcTotal(amount) {
|
||||
var i, j, side, sum, a, pos, isNumber;
|
||||
a = "NT$ 3,433.00";
|
||||
side = amount.name.substr(0, 4);
|
||||
for ( i = 0, sum = 0;
|
||||
amount.form[side + i + "amount"] != undefined;
|
||||
i++) {
|
||||
a = amount.form[side + i + "amount"];
|
||||
// Trim the text
|
||||
a.value = trim(a.value);
|
||||
// Remove the dollar sign
|
||||
if (a.value.substr(0, 3) == "NT$")
|
||||
a.value = a.value.substr(3);
|
||||
// Trim the text again, for possible spaces after the dollar sign
|
||||
a.value = trim(a.value);
|
||||
// Remove the decimal point
|
||||
if (a.value.substr(a.value.length - 3) == ".00")
|
||||
a.value = a.value.substr(0, a.value.length - 3);
|
||||
// Remove the thousand seperators
|
||||
while ((pos = a.value.indexOf(",")) != -1) {
|
||||
a.value = a.value.substr(0, pos) + a.value.substr(pos + 1);
|
||||
}
|
||||
// Check if it is a number
|
||||
for (j = 0, isNumber = true; j < a.value.length; j++) {
|
||||
if (a.value.charCodeAt(j) < 48 || a.value.charCodeAt(j) > 57) {
|
||||
isNumber = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Add the amount
|
||||
if (isNumber)
|
||||
sum = sum + a.value * 1;
|
||||
}
|
||||
a = amount.form[side + "total"];
|
||||
if (a != undefined)
|
||||
a.value = sum;
|
||||
}
|
||||
139
htdocs/emandy/scripts/common.js
Normal file
139
htdocs/emandy/scripts/common.js
Normal file
@@ -0,0 +1,139 @@
|
||||
/* Mandy Wu's Website
|
||||
* common.js: The common JavaScript subroutines.
|
||||
*/
|
||||
|
||||
/* Copyright (c) 2007-2018 imacat.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* Author: imacat <imacat@mail.imacat.idv.tw>
|
||||
* First written: 2007-09-27
|
||||
*/
|
||||
|
||||
// _: Gettext
|
||||
function _(msg) {
|
||||
var i;
|
||||
for (i = 0; i < lc_messages.length; i++) {
|
||||
if (lc_messages[i][0] == msg) {
|
||||
return lc_messages[i][1];
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
// The messages
|
||||
lc_messages = [];
|
||||
|
||||
// isEmail: Check if an email address is legal
|
||||
function isEmail(a) {
|
||||
var i, c, re;
|
||||
if (typeof(RegExp) == "undefined") return true;
|
||||
re = new RegExp("^[\\w\\-]+(\\.[\\w\\-]+)*\\@([\\w\\-]+\\.)+[\\w\\-]+$");
|
||||
if (typeof(a) != "string") return false;
|
||||
a = a.toLowerCase();
|
||||
if (re.exec(a) == null) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// isDate: Check if a date is legal
|
||||
function isDate(dateText) {
|
||||
var i, year, month, day, maxDay;
|
||||
if (dateText.length != 10) {
|
||||
return false;
|
||||
}
|
||||
// Check each character
|
||||
for (i = 0; i < dateText.length; i++) {
|
||||
// The dash sign
|
||||
if (i == 4 || i == 7) {
|
||||
if (dateText.charAt(i) != "-")
|
||||
return false;
|
||||
// The digits
|
||||
} else {
|
||||
if (dateText.charCodeAt(i) < 48 || dateText.charCodeAt(i) > 57)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Check if the date is valid
|
||||
year = dateText.substr(0, 4) * 1;
|
||||
month = dateText.substr(5, 2) * 1;
|
||||
day = dateText.substr(8, 2) * 1;
|
||||
// A reasonable month
|
||||
if (month < 1 || month > 12)
|
||||
return false;
|
||||
// Find the maximum day in this month
|
||||
switch (month) {
|
||||
case 1:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
case 8:
|
||||
case 10:
|
||||
case 12:
|
||||
maxDay = 31;
|
||||
break;
|
||||
case 4:
|
||||
case 6:
|
||||
case 9:
|
||||
case 11:
|
||||
maxDay = 30;
|
||||
break;
|
||||
case 2:
|
||||
maxDay = 28;
|
||||
if (year % 4 == 0)
|
||||
maxDay = 29;
|
||||
if (year % 100 == 0)
|
||||
maxDay = 28;
|
||||
if (year % 400 == 0)
|
||||
maxDay = 29;
|
||||
break;
|
||||
}
|
||||
// A reasonable day
|
||||
if (day < 1 || day > maxDay)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// trim: Trim the leading and tailing spaces
|
||||
function trim(a) {
|
||||
var pos, start, len, spaces;
|
||||
start = 0;
|
||||
len = a.length;
|
||||
spaces = " \t\f\n\r";
|
||||
for (start = 0; start < a.length && spaces.indexOf(a.charAt(start)) >= 0; start++, len--);
|
||||
for (pos = a.length - 1; pos >= 0 && spaces.indexOf(a.charAt(pos)) >= 0; pos--, len--);
|
||||
return a.substr(start, len);
|
||||
}
|
||||
function trimText(a) {
|
||||
var pos, start, len, spaces, newlines;
|
||||
start = 0;
|
||||
len = a.length;
|
||||
spaces = " \t\f\n\r";
|
||||
newlines = "\n\r";
|
||||
for (start = 0; start < a.length && spaces.indexOf(a.charAt(start)) >= 0; start++, len--);
|
||||
for ( ; start-1 >= 0 && newlines.indexOf(a.charAt(start-1)) < 0; start--, len++);
|
||||
for (pos = a.length - 1; pos >= 0 && spaces.indexOf(a.charAt(pos)) >= 0; pos--, len--);
|
||||
return a.substr(start, len);
|
||||
}
|
||||
|
||||
// Replace one phace with another in a string
|
||||
function replace(source, oldStr, newStr) {
|
||||
var pos;
|
||||
pos = 0;
|
||||
while (true) {
|
||||
pos = source.indexOf(oldStr, pos);
|
||||
if (pos == -1) break;
|
||||
source = source.substr(0, pos) + newStr + source.substr(pos + oldStr.length)
|
||||
pos += newStr.length;
|
||||
}
|
||||
return source;
|
||||
}
|
||||
26
htdocs/emandy/scripts/lang.zh-tw.js
Normal file
26
htdocs/emandy/scripts/lang.zh-tw.js
Normal file
@@ -0,0 +1,26 @@
|
||||
/* Mandy Wu's Website
|
||||
* lang.zh-tw.js: The Chinese (Taiwan) localized messages.
|
||||
*/
|
||||
|
||||
/* Copyright (c) 2007-2018 imacat.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* Author: imacat <imacat@mail.imacat.idv.tw>
|
||||
* First written: 2007-09-27
|
||||
*/
|
||||
|
||||
// The messages
|
||||
lc_messages = [
|
||||
];
|
||||
Reference in New Issue
Block a user