summaryrefslogtreecommitdiff
path: root/httemplate/edit/quotation_pkg_detail.html
blob: ae09b9c6a3b7d44cf18e35b7fcb1faeb6fc0cea1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<% include("/elements/header-popup.html", $title, '',
            ( $cgi->param('error') ? '' : 'onload="addRow()"' ),
          )
%>

%# <% include('/elements/error.html') %>

<FORM ACTION="process/quotation_pkg_detail.html" NAME="DetailForm" ID="DetailForm" METHOD="POST">

<INPUT TYPE="hidden" NAME="pkgnum" VALUE="<% $pkgnum %>">

<TABLE ID="DetailTable" BGCOLOR="#cccccc" BORDER=0 CELLSPACING=1 STYLE="background-color: #cccccc">

  <TR>
    <TD ALIGN="right">Package</TD>
    <TD BGCOLOR="#ffffff"><% $part_pkg->pkg %></TD>
  </TR>

  <TR>
    <TD ALIGN="right">Comment</TD>
    <TD BGCOLOR="#ffffff"><% $part_pkg->comment |h %></TD>
  </TR>

  <TR>
    <TD></TD>
    <TD>
      <SELECT NAME="copy_on_order">
        <OPTION VALUE=""<% $copy_on_order ? '' : ' SELECTED' %>>
          <% emt('Details will only appear on quotation') %>
        </OPTION>
        <OPTION VALUE="Y"<% $copy_on_order ? ' SELECTED' : '' %>>
          <% emt('Copy details to invoice when placing order') %>
        </OPTION>
      </SELECT>
    </TD>
  </TR>

% my $row = 0;
% for ( @details ) { 

    <TR>
      <TD ALIGN="right"><% $row ? '' : 'Detail' %></TD>
      <TD>
        <INPUT TYPE="text" NAME="detail<% $row %>" SIZE="60" MAXLENGTH="65" VALUE="<% $_ |h %>" rownum="<% $row++ %>" onkeyup="possiblyAddRow" onchange="possiblyAddrow">
      </TD>
    </TR>

% } 

</TABLE>

<BR>
<INPUT TYPE="submit" ID="submit" NAME="submit" VALUE="<% $title %>">

</FORM>

<SCRIPT TYPE="text/javascript">
% # abject false laziness with edit/cust_pkg_detail.html

  var rownum = <% $row %>;

  function possiblyAddRow() {
    if ( ( rownum - this.getAttribute('rownum') ) == 1 ) {
      addRow();
    }
  }

  function addRow() {

    var table = document.getElementById('DetailTable');
    var tablebody = table.getElementsByTagName('tbody').item(0);

    var row = document.createElement('TR');

    var empty_cell = document.createElement('TD');
    if (!rownum) {
      empty_cell.innerHTML = 'Detail:'
      empty_cell.style.textAlign = 'right';
    }
    row.appendChild(empty_cell);

    var detail_cell = document.createElement('TD');

      var detail_input = document.createElement('INPUT');
      detail_input.setAttribute('name', 'detail'+rownum);
      detail_input.setAttribute('id',   'detail'+rownum);
      detail_input.setAttribute('size', 60);
      detail_input.setAttribute('maxLength', 65);
      detail_input.setAttribute('rownum',   rownum);
      detail_input.onkeyup = possiblyAddRow;
      detail_input.onchange = possiblyAddRow;
      detail_cell.appendChild(detail_input);

    row.appendChild(detail_cell);

    tablebody.appendChild(row);

    rownum++;

  }

</SCRIPT>

</BODY>
</HTML>
<%init>

my $curuser = $FS::CurrentUser::CurrentUser;

die "access denied"
  unless $curuser->access_right('Generate quotation');

$cgi->param('pkgnum') =~ /^(\d+)$/ or die 'illegal pkgnum';
my $pkgnum = $1;

my $quotation_pkg = qsearchs({
  'table'     => 'quotation_pkg',
  'addl_from' => 'LEFT JOIN quotation USING ( quotationnum )'.
                 'LEFT JOIN cust_main USING ( custnum )',
  'hashref'   => { 'quotationpkgnum' => $pkgnum },
  'extra_sql' => ' AND '. $curuser->agentnums_sql,
});

my $part_pkg = $quotation_pkg->part_pkg;

my @details = $quotation_pkg->details;

my $copy_on_order = 0;
if (@details) {

  # currently, they should either all have this flag, or none
  # but just in case, erring on the side of not copying to invoice 
  #   unless every existing detail has copy_on_order
  # (anyway, user has to submit change, this is just for autofill)

  my @quotation_pkg_detail = $quotation_pkg->quotation_pkg_detail;
  my @copy_on_order = grep { $_->copy_on_order } @quotation_pkg_detail;
  $copy_on_order = 1 if @copy_on_order;
  my @no_copy_on_order = grep { !$_->copy_on_order } @quotation_pkg_detail;
  $copy_on_order = 0 if @no_copy_on_order;  
}

my $title = ( scalar(@details) ? 'Edit ' : 'Add ' ). 'Quotation Details';

</%init>