Files
selima-perl/htdocs/emandy/scripts/accounting.js
2026-03-10 21:31:43 +08:00

153 lines
5.2 KiB
JavaScript

/* 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;
}