Bugfix zu Bug 789: Ansprechpartner zeigen jetzt auch den Vornamen an
[kivitendo-erp.git] / bin / mozilla / ct.pl
index 2a2d1a1..76d9fb7 100644 (file)
 # $locale->text('Add Customer')
 # $locale->text('Add Vendor')
 
-use CGI;
 use CGI::Ajax;
 use POSIX qw(strftime);
 
 use SL::CT;
+use SL::CVar;
 use SL::ReportGenerator;
 
 require "bin/mozilla/common.pl";
@@ -54,10 +54,12 @@ require "bin/mozilla/reportgenerator.pl";
 sub add {
   $lxdebug->enter_sub();
 
+  $auth->assert('customer_vendor_edit');
+
   $form->{title} = "Add";
 
   $form->{callback} =
-    "$form->{script}?action=add&db=$form->{db}&login=$form->{login}&password=$form->{password}"
+    "$form->{script}?action=add&db=$form->{db}"
     unless $form->{callback};
 
   CT->populate_drop_down_boxes(\%myconfig, \%$form);
@@ -71,13 +73,22 @@ sub add {
 sub search {
   $lxdebug->enter_sub();
 
+  $auth->assert('customer_vendor_edit');
+
   $form->{IS_CUSTOMER} = $form->{db} eq 'customer';
 
   $form->get_lists("business_types" => "ALL_BUSINESS_TYPES");
   $form->{SHOW_BUSINESS_TYPES} = scalar @{ $form->{ALL_BUSINESS_TYPES} } > 0;
 
-  $form->{title} = $form->{IS_CUSTOMER} ? $locale->text('Customers') : $locale->text('Vendors');
-  $form->{fokus} = 'Form.name';
+  $form->{CUSTOM_VARIABLES}                  = CVar->get_configs('module' => 'CT');
+  ($form->{CUSTOM_VARIABLES_FILTER_CODE},
+   $form->{CUSTOM_VARIABLES_INCLUSION_CODE}) = CVar->render_search_options('variables'      => $form->{CUSTOM_VARIABLES},
+                                                                           'include_prefix' => 'l_',
+                                                                           'include_value'  => 'Y');
+
+  $form->{jsscript} = 1;
+  $form->{title}    = $form->{IS_CUSTOMER} ? $locale->text('Customers') : $locale->text('Vendors');
+  $form->{fokus}    = 'Form.name';
 
   $form->header();
   print $form->parse_html_template('ct/search');
@@ -88,30 +99,25 @@ sub search {
 sub list_names {
   $lxdebug->enter_sub();
 
+  $auth->assert('customer_vendor_edit');
+
   $form->{IS_CUSTOMER} = $form->{db} eq 'customer';
 
   CT->search(\%myconfig, \%$form);
 
+  my $cvar_configs = CVar->get_configs('module' => 'CT');
+
   my @options;
   if ($form->{status} eq 'all') {
     push @options, $locale->text('All');
-
   } elsif ($form->{status} eq 'orphaned') {
     push @options, $locale->text('Orphaned');
   }
 
-  if ($form->{name}) {
-    push @options, $locale->text('Name') . " : $form->{name}";
-  }
-  if ($form->{contact}) {
-    push @options, $locale->text('Contact') . " : $form->{contact}";
-  }
-  if ($form->{"$form->{db}number"}) {
-    push @options, $locale->text('Number') . qq| : $form->{"$form->{db}number"}|;
-  }
-  if ($form->{email}) {
-    push @options, $locale->text('E-mail') . " : $form->{email}";
-  }
+  push @options, $locale->text('Name') . " : $form->{name}"                    if $form->{name};
+  push @options, $locale->text('Contact') . " : $form->{contact}"              if $form->{contact};
+  push @options, $locale->text('Number') . qq| : $form->{"$form->{db}number"}| if $form->{"$form->{db}number"};
+  push @options, $locale->text('E-mail') . " : $form->{email}"                 if $form->{email};
 
   my @columns = (
     'id',        'name',  "$form->{db}number", 'address',  'contact',  'phone',
@@ -119,6 +125,11 @@ sub list_names {
     'ordnumber', 'quonumber'
   );
 
+  my @includeable_custom_variables = grep { $_->{includeable} } @{ $cvar_configs };
+  my %column_defs_cvars            = map { +"cvar_$_->{name}" => { 'text' => $_->{description} } } @includeable_custom_variables;
+
+  push @columns, map { "cvar_$_->{name}" } @includeable_custom_variables;
+
   my %column_defs = (
     'id'                => { 'text' => $locale->text('ID'), },
     "$form->{db}number" => { 'text' => $form->{IS_CUSTOMER} ? $locale->text('Customer Number') : $locale->text('Vendor Number'), },
@@ -135,6 +146,7 @@ sub list_names {
     'invnumber'         => { 'text' => $locale->text('Invoice'), },
     'ordnumber'         => { 'text' => $form->{IS_CUSTOMER} ? $locale->text('Sales Order') : $locale->text('Purchase Order'), },
     'quonumber'         => { 'text' => $form->{IS_CUSTOMER} ? $locale->text('Quotation')   : $locale->text('Request for Quotation'), },
+    %column_defs_cvars,
   );
 
   map { $column_defs{$_}->{visible} = $form->{"l_$_"} eq 'Y' } @columns;
@@ -177,6 +189,12 @@ sub list_names {
 
   $report->set_sort_indicator($form->{sort}, 1);
 
+  CVar->add_custom_variables_to_report('module'         => 'CT',
+                                       'trans_id_field' => 'id',
+                                       'configs'        => $cvar_configs,
+                                       'column_defs'    => \%column_defs,
+                                       'data'           => $form->{CT});
+
   my $previous_id;
 
   foreach my $ref (@{ $form->{CT} }) {
@@ -208,6 +226,8 @@ sub list_names {
 sub edit {
   $lxdebug->enter_sub();
 
+  $auth->assert('customer_vendor_edit');
+
   # show history button
   $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
   #/show hhistory button
@@ -235,15 +255,19 @@ sub edit {
 sub form_header {
   $lxdebug->enter_sub();
 
-  $form->get_lists("employees" => "ALL_SALESMEN",
+  $auth->assert('customer_vendor_edit');
+
+  $form->get_lists("employees" => "ALL_EMPLOYEES",
                    "taxzones"  => "ALL_TAXZONES");
   $form->get_pricegroup(\%myconfig, { all => 1 });
 
+  $form->{ALL_SALESMEN}   = $form->{ALL_EMPLOYEES};
   $form->{taxincluded}    = ($form->{taxincluded}) ? "checked" : "";
   $form->{is_admin}       = $myconfig{role} eq 'admin';
   $form->{is_customer}    = $form->{db}     eq 'customer';
   $form->{salesman_label} = sub { $_[0]->{name} ne "" ? $_[0]->{name} : $_[0]->{login} };
   $form->{shipto_label}   = sub { "$_[0]->{shiptoname} $_[0]->{shiptodepartment_1}" };
+  $form->{contacts_label} = sub { "$_[0]->{cp_givenname} $_[0]->{cp_name}" };
   $form->{taxzone_id}     = 0                                                               if !$form->{id};
   $form->{jsscript}       = 1;
   $form->{fokus}          = "ct.greeting";
@@ -252,7 +276,7 @@ sub form_header {
   unshift @{ $form->{CONTACTS} }, +{ cp_id     => '0', cp_name => $locale->text('New contact') };
 
   push @{ $form->{AJAX} }, map { 
-    new CGI::Ajax( "get_$_" => "$form->{script}?login=$form->{login}&password=$form->{password}&action=get_$_" ) 
+    new CGI::Ajax( "get_$_" => "$form->{script}?action=get_$_" ) 
   } qw(shipto contact delivery);
 
   $form->{title} = $form->{title_save} 
@@ -263,6 +287,12 @@ sub form_header {
   map { $form->{"MB_$_"} = [ map +{ id => $_, description => $_ }, @{ $form->{$_} } ] } qw(TITLES GREETINGS COMPANY_GREETINGS DEPARTMENT);
 ## /LINET
 
+  $form->{NOTES} ||= [ ];
+
+  $form->{CUSTOM_VARIABLES} = CVar->get_custom_variables('module' => 'CT', 'trans_id' => $form->{id});
+
+  CVar->render_inputs('variables' => $form->{CUSTOM_VARIABLES}) if (scalar @{ $form->{CUSTOM_VARIABLES} });
+
   $form->header;
   print $form->parse_html_template('ct/form_header');
 
@@ -272,81 +302,18 @@ sub form_header {
 sub form_footer {
   $lxdebug->enter_sub();
 
-  $label     = ucfirst $form->{db};
-  $quotation =
-    ($form->{db} eq 'customer')
-    ? $locale->text('Save and Quotation')
-    : $locale->text('Save and RFQ');
-  $arap =
-    ($form->{db} eq 'customer')
-    ? $locale->text('Save and AR Transaction')
-    : $locale->text('Save and AP Transaction');
-
-##<input class=submit type=submit name=action value="|.$locale->text("Save and Quotation").qq|">
-##<input class=submit type=submit name=action value="|.$locale->text("Save and RFQ").qq|">
-##<input class=submit type=submit name=action value="|.$locale->text("Save and AR Transaction").qq|">
-##<input class=submit type=submit name=action value="|.$locale->text("Save and AP Transaction").qq|">
-
-  print qq|
-<input name=id type=hidden id=cvid value=$form->{id}>
-<input name=business_save type=hidden value="$form->{selectbusiness}">
-<input name=title_save type=hidden value="$form->{title}">
-
-<input type=hidden name=login value=$form->{login}>
-<input type=hidden name=password value=$form->{password}>
-
-<input type=hidden name=callback value="$form->{callback}">
-<input type=hidden name=db id=db value=$form->{db}>
-
-
-
-<br>
-<input class=submit type=submit name=action accesskey="s" value="|
-    . $locale->text("Save") . qq|">
-<input class=submit type=submit name=action accesskey="s" value="|
-    . $locale->text("Save and Close") . qq|">
-<input class=submit type=submit name=action value="$arap">
-<input class=submit type=submit name=action value="|
-    . $locale->text("Save and Invoice") . qq|">
-<input class=submit type=submit name=action value="|
-    . $locale->text("Save and Order") . qq|">
-<input class=submit type=submit name=action value="$quotation">
-|;
-
-  if ($form->{id} && $form->{status} eq 'orphaned') {
-    print qq|<input class=submit type=submit name=action value="|
-      . $locale->text('Delete')
-      . qq|">\n|;
-  }
-
-  # button for saving history
-  if($form->{id} ne "") {
-    print qq|
-         <input type=button class=submit onclick=set_history_window(|
-         . $form->{id} 
-         . qq|); name=history id=history value=|
-         . $locale->text('history') 
-         . qq|>|;
-  }
-  # /button for saving history
-
-  print qq|
-
-  </form>
-<script type="text/javascript">
-//Start Tab Content script for UL with id="maintab" Separate multiple ids each with a comma.
-initializetabcontent("maintab")
-</script>
-</body>
-</html>
-|;
+  $auth->assert('customer_vendor_edit');
 
+  print $form->parse_html_template('ct/form_footer', { is_orphaned => $form->{status} eq 'orphaned',
+                                                       is_customer => $form->{db}     eq 'customer' });
   $lxdebug->leave_sub();
 }
 
 sub add_transaction {
   $lxdebug->enter_sub();
 
+  $auth->assert('customer_vendor_edit & general_ledger');
+
 #  # saving the history
 #  if(!exists $form->{addition}) {
 #      $form->{addition} = "ADD TRANSACTION";
@@ -365,7 +332,7 @@ sub add_transaction {
   $name = $form->escape("$form->{name}", 1);
 
   $form->{callback} =
-    "$form->{script}?login=$form->{login}&password=$form->{password}&action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&callback=$form->{callback}";
+    "$form->{script}?action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&callback=$form->{callback}";
   $form->redirect;
 
   $lxdebug->leave_sub();
@@ -374,6 +341,8 @@ sub add_transaction {
 sub save_and_ap_transaction {
   $lxdebug->enter_sub();
 
+  $auth->assert('customer_vendor_edit & general_ledger');
+
   $form->{script} = "ap.pl";
   # saving the history
   if(!exists $form->{addition}) {
@@ -389,6 +358,8 @@ sub save_and_ap_transaction {
 sub save_and_ar_transaction {
   $lxdebug->enter_sub();
 
+  $auth->assert('customer_vendor_edit & general_ledger');
+
   $form->{script} = "ar.pl";
   # saving the history
   if(!exists $form->{addition}) {
@@ -404,6 +375,12 @@ sub save_and_ar_transaction {
 sub save_and_invoice {
   $lxdebug->enter_sub();
 
+  if ($form->{db} eq 'customer') {
+    $auth->assert('customer_vendor_edit & invoice_edit');
+  } else {
+    $auth->assert('customer_vendor_edit & vendor_invoice_edit');
+  }
+
   $form->{script} = ($form->{db} eq 'customer') ? "is.pl" : "ir.pl";
   $form->{type} = "invoice";
   # saving the history
@@ -420,6 +397,8 @@ sub save_and_invoice {
 sub save_and_rfq {
   $lxdebug->enter_sub();
 
+  $auth->assert('customer_vendor_edit & request_quotation_edit');
+
   $form->{script} = "oe.pl";
   $form->{type}   = "request_quotation";
   # saving the history
@@ -436,6 +415,8 @@ sub save_and_rfq {
 sub save_and_quotation {
   $lxdebug->enter_sub();
 
+  $auth->assert('customer_vendor_edit & sales_quotation_edit');
+
   $form->{script} = "oe.pl";
   $form->{type}   = "sales_quotation";
   # saving the history
@@ -452,6 +433,8 @@ sub save_and_quotation {
 sub save_and_order {
   $lxdebug->enter_sub();
 
+  $auth->assert('customer_vendor_edit & sales_order_edit');
+
   $form->{script} = "oe.pl";
   $form->{type}   =
     ($form->{db} eq 'customer') ? "sales_order" : "purchase_order";
@@ -469,6 +452,8 @@ sub save_and_order {
 sub save_and_close {
   $lxdebug->enter_sub();
 
+  $auth->assert('customer_vendor_edit');
+
   # $locale->text('Customer saved!')
   # $locale->text('Vendor saved!')
 
@@ -499,6 +484,8 @@ sub save_and_close {
 sub save {
   $lxdebug->enter_sub();
 
+  $auth->assert('customer_vendor_edit');
+
   # $locale->text('Customer saved!')
   # $locale->text('Vendor saved!')
 
@@ -536,6 +523,8 @@ sub save {
 sub delete {
   $lxdebug->enter_sub();
 
+  $auth->assert('customer_vendor_edit');
+
   # $locale->text('Customer deleted!')
   # $locale->text('Cannot delete customer!')
   # $locale->text('Vendor deleted!')
@@ -563,6 +552,8 @@ sub delete {
 sub display {
   $lxdebug->enter_sub();
 
+  $auth->assert('customer_vendor_edit');
+
   &form_header();
   &form_footer();
 
@@ -572,6 +563,8 @@ sub display {
 sub update {
   $lxdebug->enter_sub();
 
+  $auth->assert('customer_vendor_edit');
+
   &display();
   $lxdebug->leave_sub();
 }
@@ -579,13 +572,13 @@ sub update {
 sub get_contact {
   $lxdebug->enter_sub();
 
+  $auth->assert('customer_vendor_edit');
+
   CT->get_contact(\%myconfig, \%$form);
 
-  my $q = new CGI;
   $result = "$form->{cp_name}";
   map { $result .= "__pjx__" . $form->{$_} } qw(cp_greeting cp_title cp_givenname cp_phone1 cp_phone2 cp_email cp_abteilung cp_fax cp_mobile1 cp_mobile2 cp_satphone cp_satfax cp_project cp_privatphone cp_privatemail cp_birthday);
-  print $q->header();
-  print $result;
+  print $cgi->header(), $result;
   $lxdebug->leave_sub();
 
 }
@@ -593,13 +586,13 @@ sub get_contact {
 sub get_shipto {
   $lxdebug->enter_sub();
 
+  $auth->assert('customer_vendor_edit');
+
   CT->get_shipto(\%myconfig, \%$form);
 
-  my $q = new CGI;
   $result = "$form->{shiptoname}";
   map { $result .= "__pjx__" . $form->{$_} } qw(shiptodepartment_1 shiptodepartment_2 shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax shiptoemail);
-  print $q->header();
-  print $result;
+  print $cgi->header(), $result;
   $lxdebug->leave_sub();
 
 }
@@ -607,87 +600,13 @@ sub get_shipto {
 sub get_delivery {
   $lxdebug->enter_sub();
 
-  CT->get_delivery(\%myconfig, \%$form );
-
-  @column_index =
-    $form->sort_columns(shiptoname,
-                        invnumber,
-                        ordnumber,
-                        transdate,
-                        description,
-                        qty,
-                        unit,
-                        sellprice);
-
-
-
-  $column_header{shiptoname} =
-    qq|<th class=listheading>| . $locale->text('Shipping Address') . qq|</th>|;
-  $column_header{invnumber} =
-      qq|<th class=listheading>|. $locale->text('Invoice'). qq|</th>|;
-  $column_header{ordnumber} =
-      qq|<th class=listheading>|. $locale->text('Order'). qq|</th>|;
-  $column_header{transdate} =
-    qq|<th class=listheading>| . $locale->text('Invdate') . qq|</th>|;
-  $column_header{description} =
-    qq|<th class=listheading>| . $locale->text('Description') . qq|</th>|;
-  $column_header{qty} =
-    qq|<th class=listheading>| . $locale->text('Qty') . qq|</th>|;
-  $column_header{unit} =
-    qq|<th class=listheading>| . $locale->text('Unit') . qq|</th>|;
-  $column_header{sellprice} =
-    qq|<th class=listheading>| . $locale->text('Sell Price') . qq|</th>|;
-  $result .= qq|
-
-<table width=100%>
-  <tr>
-    <td>
-      <table width=100%>
-       <tr class=listheading>
-|;
-
-  map { $result .= "$column_header{$_}\n" } @column_index;
-
-  $result .= qq|
-        </tr>
-|;
-
-
-  foreach $ref (@{ $form->{DELIVERY} }) {
-
-    if ($ref->{shiptoname} eq $sameshiptoname) {
-      map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
-      $column_data{shiptoname} = "<td>&nbsp;</td>";
-    } else {
-      map { $column_data{$_} = "<td>$ref->{$_}&nbsp;</td>" } @column_index;
-    }
-    $column_data{sellprice} = "<td>". $form->format_amount(\%myconfig,$ref->{sellprice},2)."&nbsp;</td>";
-    $i++;
-    $i %= 2;
-    $result .= "
-        <tr class=listrow$i>
-";
-
-    map { $result .= "$column_data{$_}\n" } @column_index;
+  $auth->assert('customer_vendor_edit');
 
-    $result .= qq|
-        </tr>
-|;
-
-    $sameshiptoname = $ref->{shiptoname};
-
-  }
-
-  $result .= qq|
-      </table>
-|;
+  CT->get_delivery(\%myconfig, \%$form );
 
+  print $cgi->header(), $form->parse_html_template('ct/get_delivery');
 
-  my $q = new CGI;
-  print $q->header();
-  print $result;
   $lxdebug->leave_sub();
-
 }
 
 sub continue { call_sub($form->{nextsub}); }