5 $ableToRunBilling = GetAbleToRunBilling($dbh, $Hu);
8 <script type=
"text/javascript">
12 getShowWaitFunctions();
24 function ShowWarnings(warnings) {
25 var keys = Object.keys(warnings);
26 $(
"#warningDiv").empty();
27 if (keys.length == 0) {
28 $(
"#warningDiv").hide();
31 $(
"#warningDiv").show();
32 for(var j = 0; j != keys.length; j++) {
33 var cuId =
"cu_" + keys[j];
34 var theseKeys = Object.keys(warnings[keys[j]]);
35 $(
"#warningDiv").append(
"<div id='" + cuId +
"'></div>");
36 for(var i = 0; i != theseKeys.length; i++) {
37 var prodId =
"prod_" + theseKeys[i];
38 var prodArray = warnings[keys[j]][theseKeys[i]];
39 $(
"#" + cuId).append(
"<div id='" + prodId +
"'>" + prodArray.join(
"<br>") +
"</div>");
45 var runBillingDS =
null;
46 var runBillingIntervalFunc =
null;
54 function InitDataSources() {
64 runBillingDS =
new kendo.data.DataSource({
71 operation:
"gatherBillingInfo" 74 parameterMap:
function(data, type) {
80 parse:
function (data) {
83 if (data.status !==
"000") {
84 $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
88 if (data.type ==
"check") {
89 clearInterval(runBillingIntervalFunc);
97 var childCall =
"gatherBillingInfoChildren";
98 var childTypes = [
"contracts",
"estatements",
"ivr",
"ipay",
"timetrack"];
99 var checkRunBillingInterval = <?php echo CheckRunBillingInterval(); ?>;
101 runBillingIntervalFunc = setInterval(
function() { runBillingDS.read({operation:
"checkBillingInfo", sid: data.sid}); },
102 checkRunBillingInterval);
104 <?php
if ($SYSENV[
"devmode"] == 1) { ?>
105 var parameters = {sid: data.sid, reportDate: data.reportDate, cutoffDate: data.cutoffDate,
106 cutoffTime: data.cutoffTime, operation: childCall, callMy: data.callMy};
108 var parameters = {sid: data.sid, reportDate: data.reportDate, cutoffDate: data.cutoffDate,
109 cutoffTime: data.cutoffTime, operation: childCall};
113 for (var i = 0; i != childTypes.length; i++) {
116 $.post(
"index.prg?childType=" + childTypes[i], parameters);
122 clearInterval(runBillingIntervalFunc);
123 runBillingDS.read({operation:
"runBilling", sid: data.sid});
128 runBillingDS.read({operation:
"runBillingCleanup", sid: data.sid});
132 $(
"#billingGrid").data(
"kendoGrid").dataSource.read();
152 function InitMonthlyBilling() {
159 var grid = $(
"#billingGrid").kendoGrid({
167 operation:
"monthlyBillingLoad" 170 parameterMap:
function(data, type) {
179 month: {type:
"date", editable:
false, nullable:
false},
180 runDate: {type:
"date"},
181 completeDate: {type:
"date"},
182 status: {type:
"string"},
183 message: {type:
"string"},
184 cus: {type:
"odata"},
185 mainStatus: {type:
"string"}
188 parse:
function (data) {
191 if (data.status !==
"000") {
192 $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
195 ShowWarnings(data.warnings);
198 <?php
if ($ableToRunBilling) { ?>
199 if (!ignoreProgress && data.running.length > 0) {
200 SetupProgressBar(data.running[0].month, kendo.toString(
new Date(data.running[0].month),
"MMMM yyyy"));
211 {field:
"status", hidden:
true},
212 {field:
"month", title:
"Month", format:
"{0:MMM yyyy}", width:
"15%"},
213 {field:
"runDate", title:
"Start", format:
"{0:MM/dd/yyyy}", width:
"15%"},
214 {field:
"mainStatus", title:
"Main Status", width:
"15%"},
215 {field:
"completeDate", title:
"Completed Date",
216 template:
"# if (completeDate == null) { # # } else { # #: kendo.toString(completeDate, 'MM/dd/yyyy') # # } #", width:
"15%"}
218 toolbar: [<?php
if ($ableToRunBilling) { ?> {name:
"startBilling", text:
"Start Billing"}, <?php } ?> {name:
"createReport", text:
"Create Report"}],
219 detailTemplate:
"<div class=\"grid_12\"><div class=\"errorDiv\"></div></div><div class=\"grid_12\">" 220 +
"<div class=\"detailGrid1\" style=\"width:100%\"></div></div>",
221 detailInit:
function (eOuter) {
223 var errorMessage =
"(No errors)";
224 var errorDiv = eOuter.detailRow.find(
".errorDiv");
225 if (eOuter.data.status.trim() !=
"") {
226 errorMessage = eOuter.data.message;
227 eOuter.masterRow.css({color:
"red", fontWeight:
"bold"});
228 errorDiv.css({color:
"red", fontWeight:
"bold"});
230 errorDiv.text(errorMessage);
231 var detailGrid1 = eOuter.detailRow.find(
".detailGrid1").kendoGrid({
234 read:
function (options) {
235 options.success(eOuter.data.cus);
242 cu: {type:
"string", editable:
false, nullable:
false},
243 totalAmount: {type:
"number"},
244 invoices: {type:
"odata"},
245 type: {type:
"string"},
246 cuName: {type:
"string"}
252 {field:
"cuName", title:
"CU"},
253 {field:
"cu", title:
"CU No.", width:
"15%"},
254 {field:
"type", title:
"Type", width:
"15%"},
255 {field:
"totalAmount", title:
"Total", format:
"{0:c}", width:
"15%", attributes: {style:
"text-align: right;"}}
257 detailTemplate:
"<div class=\"detailGrid2\"></div>",
258 detailInit:
function (eMiddle) {
259 var detailGrid2 = eMiddle.detailRow.find(
".detailGrid2").kendoGrid({
262 read:
function (options) {
263 options.success(eMiddle.data.invoices);
270 preInvoiceId: {type:
"number", editable:
false, nullable:
false},
271 featureBillingDetailId: {type:
"number"},
272 invoiceDescription: {type:
"string"},
273 quantity: {type:
"number"},
274 amount: {type:
"number"},
275 productDescription: {type:
"string"},
276 featureDescription: {type:
"string"},
277 quantityLabel: {type:
"string"}
283 {field:
"featureBillingDetailId", title:
"Id", width:
"8%", attributes: {style:
"text-align: right;"}},
284 {field:
"productDescription", title:
"Product"},
285 {field:
"featureDescription", title:
"Feature"},
286 {field:
"invoiceDescription", title:
"Description"},
287 {field:
"quantity", title:
"Count",
template:
"#= Number(quantity) # #= quantityLabel #", width:
"15%"},
288 {field:
"amount", title:
"Total", format:
"{0:c}", width:
"15%", attributes: {style:
"text-align: right;"}}
290 }).data(
"kendoGrid");
292 }).data(
"kendoGrid");
294 dataBound:
function (eOuter) {
295 $(
"#billingGrid .k-grid-content .k-master-row").each(
function () {
296 if ($(
this).find(
"td:eq(1)").text().trim() !=
"") {
297 $(
this).css({color:
"red", fontWeight:
"bold"});
303 }).data(
"kendoGrid");
314 function SetupReport() {
316 var reportWindow = $(
"#reportWindow").kendoWindow({
318 template: kendo.template($(
"#reportTemplate").html())
321 title:
"Get Report For...",
327 }).data(
"kendoWindow");
329 var previousMonth =
new Date();
330 previousMonth.setMonth(previousMonth.getMonth() - 1);
331 previousMonth.setDate(1);
332 previousMonth.setHours(0,0,0,0);
335 var reportMonthPicker = $(
"#reportMonthPicker").kendoDatePicker({
339 }).data(
"kendoDatePicker");
342 $(
"#billingGrid").on(
"click",
".k-grid-createReport",
function () {
343 reportMonthPicker.value(previousMonth);
345 reportWindow.center();
349 $(
"#reportWindow .reportOkayBtn").click(
function () {
351 reportWindow.close();
353 var simpleReportMonth =
'<input name="reportDate" value="' + kendo.toString(reportMonthPicker.value(),
"yyyy-MM-dd") +
'">';
356 if ($(
"#asCSV").prop(
"checked")) {
357 send =
'<form id="sendForm" style="display:none;" action="index.prg?operation=monthReportCSV" method="POST">';
358 send += simpleReportMonth;
361 send =
'<form id="sendForm" style="display:none;" action="index.prg?page=monthReport" method="POST">';
362 send += simpleReportMonth;
366 $(
"#reportWindow").append(send);
367 $(
"#sendForm").submit();
368 $(
"#sendForm").
remove();
370 $(
"#asCSV").prop(
"checked",
false);
374 $(
"#reportWindow .reportCancelBtn").click(
function () {
375 reportWindow.close();
390 function SetupProgressBar(selectedMonth, selectedMonthDisplay) {
391 var progressWindow = $(
"#progressWindow").data(
"kendoWindow");
392 if (progressWindow ==
null) {
393 progressWindow = $(
"#progressWindow").kendoWindow({
395 template: kendo.template($(
"#progressTemplate").html())
398 title:
"QWBC is running",
404 }).data(
"kendoWindow");
408 $.post(
"index.prg?operation=monthlyProgressLoad", {reportDate: selectedMonth},
function (data) {
410 if (data.status !==
"000") {
411 $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
413 var progressBar = $(
"#progressBar").kendoProgressBar({
417 }).data(
"kendoProgressBar");
419 var title =
"Running for " + selectedMonthDisplay;
420 if (data.record.length > 0) {
421 var record = data.record[0];
422 progressBar.value(record.progress);
424 if (record.type ==
"QWBC") {
428 progressBar.value(0);
430 progressWindow.title(title);
432 progressWindow.open().center();
434 intervalFunc = setInterval(ProgressIntervalFunction(selectedMonth), 100);
440 var previousValue1 = -1;
441 var previousValue2 = -1;
442 var previousValue3 = -1;
443 var ignoreProgress =
false;
451 function ProgressIntervalFunction(selectedMonth) {
452 var progressBar = $(
"#progressBar").data(
"kendoProgressBar");
453 var progressWindow = $(
"#progressWindow").data(
"kendoWindow");
455 $.post(
"index.prg?operation=monthlyProgressLoad", {reportDate: selectedMonth},
function (data) {
457 if (data.status !==
"000") {
458 $.homecuValidator.displayMessage(data.error, $.homecuValidator.settings.statusError );
460 var progress = data.record[0].progress;
461 progressBar.value(progress);
463 var threeValuesSame = previousValue1 == previousValue2 && previousValue2 == previousValue3 && previousValue1 != -1;
464 ignoreProgress = threeValuesSame;
465 previousValue3 = previousValue2;
466 previousValue2 = previousValue1;
467 previousValue1 = progress;
469 if (progress >= 1 || threeValuesSame) {
470 clearInterval(intervalFunc);
471 progressWindow.close();
474 if (!threeValuesSame) {
475 $(
"#billingGrid").data(
"kendoGrid").dataSource.read();
482 <?php
if ($ableToRunBilling) { ?>
483 var availableMonths = [];
490 function InitRunBilling() {
491 var window = $(
"#startBillingWindow").data(
"kendoWindow");
493 var monthMap = GetMonthMap();
496 var window = $(
"#startBillingWindow").kendoWindow({
498 template: kendo.template($(
"#startBillingTemplate").html())
501 title:
"Start Billing",
507 }).data(
"kendoWindow");
509 var startBillingBtn = $(
"#billingGrid .k-grid-startBilling").kendoButton({
511 $.homecuValidator.setup({formValidate:
"billingForm", formStatusField:
"formValidateBillingDiv"});
513 var billingMonthPicker = $(
"#billingMonthPicker").data(
"kendoDatePicker");
514 var cutoffPicker = $(
"#cutoffPicker").data(
"kendoDateTimePicker");
515 if (billingMonthPicker ==
null) {
517 cutoffPicker = $(
"#cutoffPicker").kendoDateTimePicker({
518 format:
"yyyy-MM-dd HH:mm:ss",
519 parseFormats: [
"yyyy-MM-dd HH:mm:ss"],
520 change:
function () {
521 var value = this.value();
522 if (value ==
null || $(
"#cutoffPicker").val().trim() ==
"") {
526 }).data(
"kendoDateTimePicker");
528 billingMonthPicker = $(
"#billingMonthPicker").kendoDatePicker({
532 change:
function () {
533 var value = this.value();
534 if (value ==
null || $(
"#billingMonthPicker").val().trim() ==
"") {
538 value.setHours(0,0,0,0);
539 cutoffPicker.value(GetMonthCutoff(value, monthMap));
542 }).data(
"kendoDatePicker");
544 <?php
if ($SYSENV[
"devmode"] == 1) { ?>
545 var debugDDL = $(
"#debugDDL").kendoDropDownList({
546 dataSource: [
"localhost",
"my.homecu.net"],
548 }).data(
"kendoDropDownList");
551 billingMonthPicker.value(
null);
552 cutoffPicker.value(
null);
558 }).data(
"kendoButton");
561 $(
"#startBillingWindow").on(
"click",
".startBillingBtn",
function () {
562 if ($.homecuValidator.validate()) {
566 $.homecuValidator.setup({formValidate:
'formMain', formStatusField:
'formValidateMainDiv'});
568 var billingMonthPicker = $(
"#billingMonthPicker").data(
"kendoDatePicker");
569 var cutoffPicker = $(
"#cutoffPicker").data(
"kendoDateTimePicker");
570 var selectedMonth = kendo.toString(
new Date(billingMonthPicker.value()),
"yyyy-MM-dd");
571 var selectedMonthDisplay = kendo.toString(
new Date(billingMonthPicker.value()),
"MMMM yyyy");
572 var cutoffDate = kendo.toString(cutoffPicker.value(),
"yyyy-MM-dd");
573 var cutoffTime = kendo.toString(cutoffPicker.value(),
"HH:mm:ss");
575 var parameters = {reportDate: selectedMonth, cutoffDate: cutoffDate, cutoffTime: cutoffTime};
577 <?php
if ($SYSENV[
"devmode"] == 1) { ?>
579 var debugValue = $(
"#debugDDL").data(
"kendoDropDownList").value();
581 case "my.homecu.net":
582 parameters.operation =
"gatherBillingInfoOdyssey";
585 parameters.operation =
"gatherBillingInfo";
590 parameters.operation =
"gatherBillingInfo";
592 runBillingDS.read(parameters);
597 $(
"#startBillingWindow").on(
"click",
".cancelBillingBtn",
function() {
624 function GetMonthCutoff(monthDate, monthMap) {
625 var monthString = kendo.toString(monthDate,
"yyyy-MM-dd");
626 var cutoff = monthMap.map[monthString];
627 var firstOfMonth =
new Date(monthDate);
628 var month = firstOfMonth.getMonth() + 1;
629 var year = firstOfMonth.getFullYear();
630 var actualMonth = month - 1;
631 var actualYear = year;
633 if (cutoff ==
null) {
634 if (monthMap.first ==
null) { <?php
641 cutoff =
new Date(
"" + month +
"/1/" + year)
642 }
else if (firstOfMonth.getTime() >= monthMap.last.getTime()) {
643 monthString = kendo.toString(monthMap.last,
"yyyy-MM-dd");
644 cutoff =
new Date(monthMap.map[monthString]);
645 }
else if (firstOfMonth.getTime() == monthMap.first.getTime()) {
646 monthString = kendo.toString(monthMap.first,
"yyyy-MM-dd");
647 cutoff =
new Date(monthMap.map[monthString]);
648 }
else if (firstOfMonth.getTime() < monthMap.first.getTime()) {
649 cutoff =
new Date(monthDate);
651 while (cutoff ==
null) {
656 }
else if (month == 13) {
661 firstOfMonth =
new Date(
"" + month +
"/1/" + year);
662 monthString = kendo.toString(firstOfMonth,
"yyyy-MM-dd");
663 cutoff = monthMap.map[monthString] ==
null ? null :
new Date(monthMap.map[monthString]);
667 cutoff =
new Date(cutoff);
672 if (actualMonth == -1) {
675 }
else if (actualMonth == 12) {
679 cutoff.setFullYear(actualYear, actualMonth, 1);
689 function GetMonthMap() {
690 var gridData = $(
"#billingGrid").data(
"kendoGrid").dataSource.data();
691 var monthMap = {first:
null, last:
null, map: {}};
692 for(var i = 0; i != gridData.length; i++) {
693 var record = gridData[i];
694 var monthLabel = kendo.toString(record.month,
"MMM yyyy");
695 var monthString = kendo.toString(record.month,
"yyyy-MM-dd");
696 var cutoff =
new Date(record.runDate);
697 monthMap.map[monthString] = cutoff;
698 if (monthMap.first ==
null || record.month.getTime() < monthMap.first.getTime()) {
699 monthMap.first =
new Date(record.month); <?php
701 if (monthMap.last ==
null || record.month.getTime() > monthMap.last.getTime()) {
702 monthMap.last =
new Date(record.month);
709 $(document).ready(
function () {
710 $.homecuValidator.setup({formValidate:
'formMain', formStatusField:
'formValidateMainDiv'});
711 InitMonthlyBilling();
715 <?php
if ($ableToRunBilling) { ?>
721 <?php
if ($ableToRunBilling) { ?>
722 <script
id=
"startBillingTemplate" type=
"text/x-kendo-template">
723 <div
class=
"k-edit-form-container">
724 <div
id=
"formValidateBillingDiv" class=
"homecu-formStatus k-block k-error-colored" style=
"display:none;"></div>
725 <form
id=
"billingForm" data-role=
"validator" novalidate>
726 <div
class=
"container_12">
727 <div
class=
"grid_12">
728 <div
class=
"grid_4 alpha">
729 <label>Month:</label>
732 <input
id=
"billingMonthPicker" name=
"billingMonth" required data-required-msg=
"Billing month is required" style=
"width:100%">
734 <div
class=
"grid_1 omega">
735 <span data-
for=
'billingMonth' class=
'k-invalid-msg'></span>
738 <div
class=
"grid_12">
739 <div
class=
"grid_4 alpha">
740 <label>Cutoff:</label>
743 <input
id=
"cutoffPicker" name=
"cutoff" required data-required-msg=
"Cutoff time is required" style=
"width:100%">
745 <div
class=
"grid_1 omega">
746 <span data-
for=
'cutoff' class=
'k-invalid-msg'></span>
749 <?php
if ($SYSENV[
"devmode"] == 1) { ?>
750 <div
class=
"grid_12">
751 <div
class=
"grid_4 alpha">
752 <label>Contract Source:</label>
755 <div
id=
"debugDDL"></div>
757 <div
class=
"grid_1 omega">
764 <div
class=
"k-edit-buttons k-state-default">
765 <a
class=
"k-button k-button-icontext k-primary startBillingBtn" href=
"\#">
766 <span
class=
"k-icon k-update"></span>Start
768 <a
class=
"k-button k-button-icontext cancelBillingBtn" href=
"\#">
769 <span
class=
"k-icon k-cancel"></span>Cancel
774 <script
id=
"progressTemplate" type=
"text/x-kendo-template">
775 <div
class=
"k-edit-form-container">
776 <div
class=
"container_12">
777 <div
class=
"grid_12">
778 <div
id=
"progressBar" style=
"width:100%"></div>
784 <script
id=
"reportTemplate" type=
"text/x-kendo-template">
785 <div
class=
"k-edit-form-container">
786 <div
id=
"formValidateReportDiv" class=
"homecu-formStatus k-block k-error-colored" style=
"display:none;"></div>
787 <form
id=
"reportForm" data-role=
"validator" novalidate>
788 <div
class=
"container_12">
789 <div
class=
"grid_12">
790 <div
class=
"grid_4 alpha">
791 <label>Month:</label>
794 <input
id=
"reportMonthPicker" name=
"reportMonth" required data-required-msg=
"Report month is required" style=
"width:100%">
796 <div
class=
"grid_1 omega">
797 <span data-
for=
'reportMonth' class=
'k-invalid-msg'></span>
800 <div
class=
"grid_12">
801 <div
class=
"grid_4 alpha">
802 <label>As CSV:</label>
805 <input
id=
"asCSV" name=
"asCSV" type=
"checkbox">
807 <div
class=
"grid_1 omega">
808 <span data-
for=
'asCSV' class=
'k-invalid-msg'></span>
813 <div
class=
"k-edit-buttons k-state-default">
814 <a
class=
"k-button k-button-icontext k-primary reportOkayBtn" href=
"\#">
815 <span
class=
"k-icon k-update"></span>Okay
817 <a
class=
"k-button k-button-icontext reportCancelBtn" href=
"\#">
818 <span
class=
"k-icon k-cancel"></span>Cancel
823 <div
id=
"startBillingWindow"></div>
824 <div
id=
"progressWindow"></div>
825 <div
id=
"reportWindow"></div>
826 <div
id=
"runningWindow"></div>
827 <div
class=
"container_12">
828 <div
id=
"formMain"></div>
829 <div
id=
"formValidateMainDiv" style=
"display:none;"></div>
830 <div
class=
"grid_12">
831 <div
id=
"warningDiv" class=
"k-block" style=
"display:none;"></div>
833 <div
class=
"grid_12">
834 <div
id=
"billingGrid"></div>