summaryrefslogtreecommitdiff
path: root/httemplate/elements
diff options
context:
space:
mode:
authorIvan Kohler <ivan@freeside.biz>2014-01-08 17:23:05 -0800
committerIvan Kohler <ivan@freeside.biz>2014-01-08 17:23:05 -0800
commit8861d46820af163c7de7839178b6120c9b32ab2c (patch)
treeebd723b2d1ea70f57bc52f94c80d991b5f50094a /httemplate/elements
parent49809d3653e7ac4951d36716dce3cd25ba9c3728 (diff)
time/data/etc. unit pricing add-ons, RT#24392
Diffstat (limited to 'httemplate/elements')
-rw-r--r--httemplate/elements/cust_pkg_usageprice.html72
-rw-r--r--httemplate/elements/order_pkg.js69
-rw-r--r--httemplate/elements/order_pkg_link.html2
-rw-r--r--httemplate/elements/tr-cust_pkg_usageprice.html24
4 files changed, 164 insertions, 3 deletions
diff --git a/httemplate/elements/cust_pkg_usageprice.html b/httemplate/elements/cust_pkg_usageprice.html
new file mode 100644
index 000000000..729099320
--- /dev/null
+++ b/httemplate/elements/cust_pkg_usageprice.html
@@ -0,0 +1,72 @@
+% unless ( $opt{'js_only'} ) {
+
+ <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
+
+ <INPUT TYPE = "hidden"
+ NAME = "<%$name%>_usagepricepart"
+ ID = "<%$id%>_usagepricepart"
+ VALUE = "<% $part_pkg_usageprice->usagepricepart %>"
+ >
+
+ <TABLE STYLE="display:inline">
+ <TR>
+
+% ###
+% # action
+% ###
+ <TD>
+% # maybe we should be a quantity entry instead of a select? even more
+% # javascript auto-calculation need to display a subtotal & total
+ <SELECT NAME = "<%$name%>_quantity"
+ ID = "<%$id%>_quantity"
+ <% $onchange %>
+ >
+% my $info = $part_pkg_usageprice->target_info;
+% my $amount = $part_pkg_usageprice->amount / ($info->{multiplier}||1);
+ <OPTION VALUE="">Additional <% $info->{label} %>
+% for (1..100) { #100? arbitrary.
+ <OPTION VALUE="<% $_ %>"><%
+ $money_char. sprintf('%.2f', $_ * $part_pkg_usageprice->price ).
+ ' '.
+ 'for'. #( $part_pkg_usageprice->action eq 'increment' ? 'per' : 'for' ).
+ ' '.
+ ( $_ * $amount ). ' '. $info->{label}
+ %>
+% }
+ </SELECT>
+ </TD>
+
+ </TR>
+ </TABLE>
+
+% }
+<%init>
+
+#my $targets = FS::part_pkg_usageprice->targets;
+
+my( %opt ) = @_;
+
+my $conf = new FS::Conf;
+my $money_char = $conf->config('money_char') || '$';
+
+my $name = $opt{'element_name'} || $opt{'field'} || 'usagepricenum';
+my $id = $opt{'id'} || $opt{'field'} || 'usagepricenum';
+
+my $curr_value = $opt{'curr_value'} || $opt{'value'};
+
+my $onchange = '';
+if ( $opt{'onchange'} ) {
+ $onchange = $opt{'onchange'};
+ $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
+ $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack. all onchange
+ #callbacks should act the same
+ $onchange = 'onChange="'. $onchange. '"';
+}
+
+my $cust_pkg_usageprice = $curr_value
+ ? qsearchs('cust_pkg_usageprice', { 'usagepricenum' => $curr_value } )
+ : new FS::cust_pkg_usageprice { 'usagepricepart' => $opt{usagepricepart} };
+
+my $part_pkg_usageprice = $cust_pkg_usageprice->part_pkg_usageprice;
+
+</%init>
diff --git a/httemplate/elements/order_pkg.js b/httemplate/elements/order_pkg.js
index 4e41fd64a..393b845c9 100644
--- a/httemplate/elements/order_pkg.js
+++ b/httemplate/elements/order_pkg.js
@@ -21,8 +21,8 @@ function pkg_changed () {
}
}
-// if this form element exists, then the start date is a future
-// package change date; don't replace it
+ // if this form element exists, then the start date is a future
+ // package change date; don't replace it
if ( form.delay ) {
return;
}
@@ -39,6 +39,8 @@ function pkg_changed () {
date_button_disabled.style.display = '';
}
+ get_part_pkg_usageprice( opt.value, update_part_pkg_usageprice );
+
} else {
form.submitButton.disabled = true;
if ( discountnum ) { form.discountnum.disabled = true; }
@@ -46,6 +48,69 @@ function pkg_changed () {
}
}
+function update_part_pkg_usageprice(part_pkg_usageprice) {
+
+ var table = document.getElementById('cust_pkg_usageprice_table');
+
+ // black the current usage price rows
+ for ( var r = table.rows.length - 1; r >= 0; r-- ) {
+ table.deleteRow(r);
+ }
+
+ // add the new usage price rows
+ var rownum = 0;
+ var usagepriceArray = eval('(' + part_pkg_usageprice + ')' );
+ for ( var s = 0; s < usagepriceArray.length; s=s+2 ) {
+ //surely this should be some kind of JSON structure
+ var html = usagepriceArray[s+0];
+ var javascript = usagepriceArray[s+1];
+
+ // a lot like ("inspiried by") edit/elements/edit.html function spawn_<%$field%>
+
+ // XXX evaluate the javascript
+ //if (window.ActiveXObject) {
+ // window.execScript(newfunc);
+ //} else { /* (window.XMLHttpRequest) */
+ // //window.eval(newfunc);
+ // setTimeout(newfunc, 0);
+ //}
+
+ var row = table.insertRow(rownum++);
+
+ //var label_cell = document.createElement('TD');
+
+ //label_cell.id = '<% $field %>_label' + <%$field%>_fieldnum;
+
+ //label_cell.style.textAlign = "right";
+ //label_cell.style.verticalAlign = "top";
+ //label_cell.style.borderTop = "1px solid black";
+ //label_cell.style.paddingTop = "5px";
+
+ //label_cell.innerHTML = '<% $label %>';
+
+ //row.appendChild(label_cell);
+
+ var widget_cell = document.createElement('TD');
+
+ //widget_cell.style.borderTop = "1px solid black";
+ widget_cell.style.paddingTop = "3px";
+ widget_cell.colSpan = "2";
+
+ widget_cell.innerHTML = html;
+
+ row.appendChild(widget_cell);
+
+ }
+
+ if ( rownum > 0 ) {
+ document.getElementById('cust_pkg_usageprice_title').style.display = '';
+ } else {
+ document.getElementById('cust_pkg_usageprice_title').style.display = 'none';
+ }
+
+}
+
+
function standardize_new_location() {
var form = document.OrderPkgForm;
var loc = form.locationnum;
diff --git a/httemplate/elements/order_pkg_link.html b/httemplate/elements/order_pkg_link.html
index 0cae49284..6e0dd6852 100644
--- a/httemplate/elements/order_pkg_link.html
+++ b/httemplate/elements/order_pkg_link.html
@@ -21,6 +21,6 @@ my %optional =
grep $opt{$_},
qw( lock_pkgpart lock_locationnum qualnum quotationnum svcpart );
-my $height = $opt{'lock_locationnum'} ? 336 : 606;
+my $height = $opt{'lock_locationnum'} ? 470 : 740;
</%init>
diff --git a/httemplate/elements/tr-cust_pkg_usageprice.html b/httemplate/elements/tr-cust_pkg_usageprice.html
new file mode 100644
index 000000000..ccd06311a
--- /dev/null
+++ b/httemplate/elements/tr-cust_pkg_usageprice.html
@@ -0,0 +1,24 @@
+% unless ( $opt{'js_only'} ) {
+
+ <% include('tr-td-label.html', %opt) %>
+ <TD <% $cell_style %>>
+
+% }
+%
+ <% include( '/elements/cust_pkg_usageprice.html', %opt ) %>
+%
+% unless ( $opt{'js_only'} ) {
+
+ </TD>
+ </TR>
+
+% }
+<%init>
+
+my( %opt ) = @_;
+
+my $cell_style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : '';
+
+#$opt{'label'} ||= 'XXX Something';
+
+</%init>