326c2f9549b7e2c9b5eb8b48571bfd73b8f51d07
[freeside.git] / httemplate / view / cust_main / menu.html
1 <style type="text/css">
2 #menu_ul {
3   padding: 0;
4   margin: .5em 0 0 0;
5   font-size: smaller;
6 }
7
8 #menu_ul li {
9   margin: 0;
10   float: left;
11   list-style: none;
12   position: relative;
13 }
14
15 #menu_ul a {
16   display: block;
17   margin: 0;
18   padding: .5em .75em;
19   background: #f8f8f8;
20   color: #525151;
21   white-space: nowrap;
22   text-decoration: none;
23   border-bottom: thin solid #CFDFDF;
24   border-top-left-radius: .5em;
25   border-top-right-radius: .5em;
26 }
27
28 #menu_ul a.current_show {
29   font-weight: bold;
30   background: #FFFFFF;
31   border-top: thin solid #CFDEFF;
32   border-left: thin solid #CFDEFF;
33   border-right: thin solid #CFDEFF;
34   border-bottom: none;
35 }
36
37 #menu_ul ul {
38   margin:0;
39   padding:0;
40   display:none;
41   position: absolute;
42   top: 100%;
43   left: 0;
44   background: #ffffff;
45   border-top: none;
46   border-left: thin solid #CFDEFF;
47   border-right: thin solid #CFDEFF;
48   border-bottom: thin solid #CFDEFF;
49 }
50
51 #menu_ul ul li {
52   margin: 0;
53   padding: 0;
54   float: none;
55 }
56
57 #menu_ul ul a {
58   color: #333333;
59   background: transparent;
60   border-bottom: none;
61   border-radius: 0;
62 }
63
64 #menu_ul a:hover {
65   background: #cfdeff;
66   text-decoration: underline;
67   color: #7e0079;
68 }
69
70 </style>
71 <script src="<% $p %>elements/jquery.js"></script>
72 <script type="text/javascript">
73
74 $(document).ready(function() {
75         var openmenu;
76         function closemenu () {
77                 if (openmenu !== undefined) {
78                         openmenu.hide();
79                         openmenu = undefined;
80                 }
81         }               
82         $('#menu_ul > li').hover(function(){
83                 closemenu();
84                 openmenu = $('ul:first', this);
85                 openmenu.show();
86         }, function(){
87                 closemenu();
88         });
89 });
90 </script>
91
92 <ul id="menu_ul">
93 % foreach my $submenu (@processed_menu) {
94   <li>
95     <% shift @$submenu %>
96     <ul>
97 %   foreach my $link ( @$submenu ) {
98       <li><% $link %></li>
99 %   }
100     </ul>
101   </li>
102 % }
103 </ul>
104
105 <%init>
106 my %opt = @_;
107 my $cust_main = $opt{'cust_main'};
108 my $custnum = $cust_main->custnum;
109 my $curuser = $FS::CurrentUser::CurrentUser;
110 my $conf = FS::Conf->new;
111
112 my %payby = map { $_ => 1 } $conf->config('payby');
113
114 # nice declarative menu; should be a parameter to some kind of menu generator
115 my @menu = ( 
116   [
117     { show        => 'basics',
118       label       => 'Basics',
119     },
120     {
121       label       => 'Edit customer',
122       url         => "edit/cust_main.cgi?$custnum",
123       acl         => 'Edit customer'
124     },
125     {
126       label       => 'Edit contacts',
127       url         => "edit/cust_main-contacts.html?$custnum",
128     },
129 # separator
130     {
131       label       => 'Bill now',
132       acl         => 'Bill customer now',
133       content     => sub { include( '/elements/bill.html',
134                               label   => emt('Bill now'),
135                               url     => $cgi->self_url,
136                               custnum => shift->custnum,
137                            ),
138                      },
139     },
140     {
141       label       => 'Suspend',
142       popup       => "misc/suspend_cust.html?custnum=$custnum",
143       acl         => 'Suspend customer',
144       condition   => sub { shift->unsuspended_pkgs > 0 },
145       actionlabel => 'Confirm Suspension',
146       color       => '#ff9900',
147     },
148     {
149       label       => 'Unsuspend',
150       popup       => "misc/unsuspend_cust.html?custnum=$custnum",
151       acl         => 'Unsuspend customer',
152       condition   => sub { shift->suspended_pkgs > 0 },
153       actionlabel => 'Confirm Unsuspension',
154     },
155     {
156       label       => 'Cancel',
157       popup       => "misc/suspend_cust.html?custnum=$custnum",
158       acl         => 'Cancel customer',
159       condition   => sub { shift->ncancelled_pkgs > 0 },
160       actionlabel => 'Confirm Cancellation',
161       color       => '#ff0000',
162     },
163     {
164       label       => 'Merge',
165       popup       => "misc/merge_cust.html?custnum=$custnum",
166       acl         => 'Merge customer',
167       actionlabel => 'Merge customer',
168       width       => 569,
169       height      => 210,
170     },
171     {
172       label       => 'Refer a new customer',
173       url         => "edit/cust_main.cgi?referral_custnum=$custnum",
174       confexists  => '!disable_customer_referrals',
175     },
176 # should have a separator here
177     {
178       label       => 'View this customer\'s referrals',
179       url         => "search/cust_main.cgi?referral_custnum=$custnum",
180       confexists  => '!disable_customer_referrals',
181       condition   => sub {
182         FS::cust_main->count('referral_custnum = ?', shift->custnum) > 0
183       },
184     },
185     {
186       label       => 'View billing events',
187       url         => "search/cust_event.html?custnum=$custnum",
188       acl         => [ 'Billing event reports',
189                        'View customer billing events' ],
190     },
191     {
192       label       => 'Email a notice to this customer',
193       url         => sub {
194                       my $cust_main = shift;
195                       my $agentnum = $cust_main->agentnum;
196                       'misc/email-customers.html?table=cust_main;search_hash='.
197                       'agent_virt_agentnum='.$agentnum.";custnum=$custnum";
198                      },
199       condition   => sub { shift->invoicing_list_emailonly },
200     },
201   ],
202   [
203     {
204       label => 'Notes',
205       show  => 'notes',
206     },
207     {
208       label       => 'Add note',
209       popup       => "edit/cust_main_note.cgi?custnum=$custnum",
210       actionlabel => 'Add note',
211       confexists  => '!cust_main-disable_notes',
212       acl         => 'Add customer note',
213       width       => 616,
214       height      => 538,
215     },
216     {
217       label       => 'Attach file',
218       popup       => "edit/cust_main_attach.cgi?custnum=$custnum",
219       actionlabel => 'Upload file',
220       confexists  => '!disable_cust_attachment',
221       acl         => 'Add attachment',
222       width       => 480,
223       height      => 296,
224     },
225   ],
226   [
227     {
228       label => 'Tickets',
229       show  => 'tickets',
230       confexists => 'ticket_system'
231     },
232   ],
233   [
234     {
235       label => 'Appointments',
236       show  => 'appointments',
237       confexists => 'ticket_system',
238       acl   => 'View appointments',
239     },
240     {
241       label       => 'Schedule new appointment',
242       confexists  => 'ticket_system',
243       acl        => 'Make appointment',
244       popup       => "elements/make_appointment.html?custnum=$custnum",
245       actionlabel => 'Schedule appointment',
246     },
247   ],
248   [
249     {
250       label => 'Quotations',
251       show  => 'quotations',
252     },
253     {
254       label => 'Add quotation',
255       url   => "edit/quotation.html?custnum=$custnum",
256       acl   => 'Generate quotation',
257     },
258   ],
259   [
260     {
261       label => 'Packages',
262       show  => 'packages',
263     },
264     {
265       label       => 'New qualification',
266       popup       => "misc/qual.html?custnum=$custnum",
267       actionlabel => 'New qualification',
268       color       => '#333399',
269       width       => 763,
270       height      => 436,
271       acl         => 'Qualify service',
272     },
273     {
274       label       => 'Order new package',
275       popup       => "misc/order_pkg.html?custnum=$custnum",
276       actionlabel => 'Order new package',
277       color       => '#333399',
278       width       => 960,
279       height      => 740,
280       acl         => 'Order customer package',
281     },
282     {
283       # it's just a popup, but there's some freaky CCH tax stuff in it
284       label       => 'One-time charge',
285       content     => sub {
286                       include( '/elements/one_time_charge_link.html',
287                         custnum => shift->custnum,
288                       );
289                      },
290       acl         => 'One-time charge',
291     },
292     {
293       label       => 'Move services between packages',
294       popup       => "edit/bulk-cust_svc-pkgnum.html?custnum=$custnum",
295       actionlabel => 'Move services',
296       width       => 968,
297       height      => 575,
298       acl         => 'Bulk move customer services',
299     },
300     {
301       label       => 'Bulk order and cancel packages',
302       url         => "edit/cust_pkg.cgi?$custnum",
303       acl         => 'Bulk change customer packages',
304     },
305 # separator
306     {
307       label => 'Package reports',
308       url   => "search/report_cust_pkg?custnum=$custnum",
309     },
310     {
311       label => 'View qualifications',
312       url   => "search/qual.cgi?custnum=$custnum",
313       acl   => 'Qualify service',
314     },
315     {
316       label => 'View accounts',
317       url   => "search/report_svc_acct.html?custnum=$custnum",
318     },
319     {
320       label => 'View CDRs',
321       url   => "search/report_cdr.html?custnum=$custnum",
322     },
323   ],
324   [
325     {
326       label => 'Payment History',
327       show  => 'payment_history',
328     },
329     # manual payment entry via edit/cust_pay
330     {
331       label       => 'Enter check payment',
332       popup       => "edit/cust_pay.cgi?popup=1;payby=BILL;custnum=$custnum",
333       actionlabel => 'Enter check payment',
334       width       => 763,
335       height      => 392,
336       acl         => [ 'Post payment', 'Post check payment' ],
337       condition   => sub { $payby{BILL} },
338     },
339     {
340       label       => 'Enter cash payment',
341       popup       => "edit/cust_pay.cgi?popup=1;payby=CASH;custnum=$custnum",
342       actionlabel => 'Enter cash payment',
343       width       => 763,
344       height      => 392,
345       acl         => [ 'Post payment', 'Post cash payment' ],
346       condition   => sub { $payby{CASH} },
347     },
348     {
349       label       => 'Enter Western Union payment',
350       popup       => "edit/cust_pay.cgi?popup=1;payby=WEST;custnum=$custnum",
351       actionlabel => 'Enter Western Union payment',
352       width       => 763,
353       height      => 392,
354       acl         => [ 'Post payment', ],
355       condition   => sub { $payby{WEST} },
356     },
357     {
358       label       => 'Post manual (offline/POS) credit card payment',
359       popup       => "edit/cust_pay.cgi?popup=1;payby=MCRD;custnum=$custnum",
360       actionlabel => 'Enter credit card payment',
361       width       => 763,
362       height      => 392,
363       acl         => [ 'Post payment', ],
364       condition   => sub { $payby{MCRD} },
365     },
366     {
367       label       => 'Post manual (offline/POS) electronic check',
368       popup       => "edit/cust_pay.cgi?popup=1;payby=MCHK;custnum=$custnum",
369       actionlabel => 'Enter credit card payment',
370       width       => 763,
371       height      => 392,
372       acl         => [ 'Post payment', ],
373       condition   => sub { $payby{MCHK} },
374     },
375     # realtime payments via payment.cgi
376     {
377       label       => 'Process credit card payment',
378       url         => "misc/payment.cgi?payby=CARD;custnum=$custnum",
379       acl         => [ 'Process payment', 'Process credit card payment', ],
380       condition   => sub { $payby{CARD} or $payby{DCRD} },
381     },
382     {
383       label       => 'Process electronic check payment',
384       url         => "misc/payment.cgi?payby=CHEK;custnum=$custnum",
385       acl         => [ 'Process payment', 'Process Echeck payment', ],
386       condition   => sub { $payby{CHEK} or $payby{DCHK} },
387     },
388 #separator?
389     {
390       label       => 'Enter credit',
391       popup       => "edit/cust_credit.cgi?custnum=$custnum",
392       actionlabel => 'Enter credit',
393       width       => 763,
394       acl         => 'Post credit',
395     },
396     {
397       label       => 'Credit line items',
398       popup       => "edit/credit-cust_bill_pkg.html?custnum=$custnum",
399       actionlabel => 'Credit line items',
400       width       => 968,
401       height      => 575,
402       acl         => 'Credit line items',
403       condition   => sub {
404         FS::cust_bill->count('custnum = ?', shift->custnum) > 0
405       },
406     },
407     {
408       label       => 'Enter check refund',
409       popup       => "edit/cust_refund.cgi?popup=1;payby=BILL;custnum=$custnum",
410       actionlabel => 'Enter check refund',
411       width       => 440,
412       acl         => ['Post refund', 'Post check refund'],
413       condition   => sub { $payby{BILL} },
414     },
415     {
416       label       => 'Enter cash refund',
417       popup       => "edit/cust_refund.cgi?popup=1;payby=CASH;custnum=$custnum",
418       actionlabel => 'Enter cash refund',
419       width       => 392,
420       acl         => ['Post refund', 'Post cash refund'],
421       condition   => sub { $payby{CASH} },
422     },
423     {
424       label       => 'Enter manual (offline/POS) credit card refund',
425       popup       => "edit/cust_refund.cgi?popup=1;payby=MCRD;custnum=$custnum",
426       actionlabel => 'Enter credit card refund',
427       width       => 440,
428       acl         => ['Post refund' ],
429       condition   => sub { $payby{MCRD} },
430     },
431     {
432       label       => 'Enter manual (offline/POS) electronic check refund',
433       popup       => "edit/cust_refund.cgi?popup=1;payby=MCHK;custnum=$custnum",
434       actionlabel => 'Enter electronic check refund',
435       width       => 440,
436       acl         => ['Post refund' ],
437       condition   => sub { $payby{MCHK} },
438     },
439     {
440       label       => 'Add tax adjustment',
441       popup       => "edit/cust_tax_adjustment.html?custnum=$custnum",
442       actionlabel => 'Add tax adjustment',
443       height      => 200,
444       confexists  => 'enable_tax_adjustments',
445       acl         => 'Add customer tax adjustment',
446     },
447 # separator, definitely
448     {
449       label       => 'Download statement',
450       url         => "view/cust_main_statement-pdf.cgi?$custnum",
451       acl         => 'List invoices',
452       condition   => sub {
453         FS::cust_bill->count('custnum = ?', shift->custnum) > 0
454       },
455     },
456     {
457       label       => 'Search invoices',
458       url         => "search/report_cust_bill.html?custnum=$custnum",
459       acl         => 'List invoices',
460     },
461     {
462       label       => 'View tax exemptions',
463       url         => "search/cust_tax_exempt_pkg.cgi?custnum=$custnum",
464       acl         => 'View customer tax exemptions',
465     },
466     {
467       label       => 'View tax adjustments',
468       url         => "search/cust_tax_adjustment.html?custnum=$custnum",
469       confexists  => 'enable_tax_adjustments',
470       acl         => 'Add customer tax adjustment',
471     },
472     {
473       label       => 'View pending payments',
474       url         => "search/cust_pay_pending.html?magic=_date;statusNOT=done;custnum=$custnum",
475       acl         => 'View pending payments',
476       condition   => sub { 
477         FS::cust_pay_pending->count('custnum = ?', shift->custnum) > 0
478       },
479     },
480   ],
481   [
482     {
483       label => 'Change History',
484       show  => 'change_history',
485       acl   => 'View customer history',
486     },
487   ],
488 );
489
490
491 my @processed_menu;
492 foreach my $submenu (@menu) {
493
494   my @links;
495   my $first = 1;
496   foreach my $entry ( @$submenu ) {
497     # if the menu head was skipped, skip the whole menu
498     last if (!$first and !@links);
499     $first = 0;
500
501     # check conditions
502     if ( $entry->{acl} ) {
503       next unless $curuser->access_right( $entry->{acl} );
504     }
505     if ( $entry->{confexists} ) {
506       if ( $entry->{confexists} =~ /^!(.*)/ ) {
507         # confexists => !foo, a negative condition
508         next if $conf->exists( $1 );
509       } else {
510         next unless $conf->exists( $entry->{confexists} );
511       }
512     }
513     if ( $entry->{condition} ) {
514       next unless &{ $entry->{condition} }($cust_main);
515     }
516
517     my $label = emt($entry->{label});
518     my $target = $entry->{content}
519               || $entry->{popup}
520               || $entry->{url};
521
522     if ( ref($target) eq 'CODE' ) {
523       $target = &$target($cust_main);
524     }
525     my $a = '';
526
527     if ( $entry->{content} ) { # then the coderef specified the whole thing
528       $a = $target;
529
530     } elsif ( $entry->{show} ) {
531
532       # the menu head: always a link back to this page
533       $cgi->param('show', $entry->{show});
534             $target = $cgi->self_url;
535
536       $a = qq[ <A HREF="$target"];
537       if ( $opt{'show'} eq $entry->{show} ) {
538         $a .= ' class="current_show"';
539       }
540       $a .= qq[>$label</A> ];
541
542
543     } elsif ( $entry->{popup} ) {
544
545       $target =~ s/\$custnum/$custnum/g;
546       $target = $p.$target;
547       $a = include('/elements/popup_link.html',
548         action  => $target,
549         width   => 616,
550         height  => 410,
551         %$entry,
552         label   => emt($label),
553       );
554
555     } elsif ( $entry->{url} ) {
556
557       $target =~ s/\$custnum/$custnum/g;
558       $target = $p.$target;
559       $a = qq[ <A HREF="$target">$label</A> ];
560     }
561
562     push @links, $a;
563
564   } # foreach $entry
565   if (@links) {
566     push @processed_menu, \@links;
567   }
568 }
569 </%init>