Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4493d1eb

Von Moritz Bunkus vor mehr als 8 Jahren hinzugefügt

  • ID 4493d1eb7845b7eba868f0a16ec2e623dcf1d591
  • Vorgänger 6e1a7a2e
  • Nachfolger c7241bf7

CVars: Lieferadressen-CVars bei Ein-/Verkaufsbelegen benutzen können

Unterschiede anzeigen:

SL/Common.pm
447 447

  
448 448
  map { $form->{"${prefix}${_}"} = $ref->{$_} } keys %{ $ref } if $ref;
449 449

  
450
  my $cvars = CVar->get_custom_variables(
451
    dbh      => $dbh,
452
    module   => 'ShipTo',
453
    trans_id => $shipto_id,
454
  );
455
  $form->{"${prefix}shiptocvar_$_->{name}"} = $_->{value} for @{ $cvars };
456

  
450 457
  $dbh->disconnect();
451 458

  
452 459
  $main::lxdebug->leave_sub();
SL/DO.pm
263 263
  if ($form->{id}) {
264 264

  
265 265
    # only delete shipto complete
266
    $query = qq|DELETE FROM custom_variables
267
                WHERE (config_id IN (SELECT id        FROM custom_variable_configs WHERE (module = 'ShipTo')))
268
                  AND (trans_id  IN (SELECT shipto_id FROM shipto                  WHERE (module = 'DO') AND (trans_id = ?)))|;
269
    do_query($form, $dbh, $query, $form->{id});
270

  
266 271
    $query = qq|DELETE FROM shipto WHERE trans_id = ? AND module = 'DO'|;
267 272
    do_query($form, $dbh, $query, conv_i($form->{id}));
268 273

  
......
748 753
    map { $form->{$_} = $ref->{$_} } keys %$ref;
749 754
    $sth->finish();
750 755

  
756
    if ($form->{shipto_id}) {
757
      my $cvars = CVar->get_custom_variables(
758
        dbh      => $dbh,
759
        module   => 'ShipTo',
760
        trans_id => $form->{shipto_id},
761
      );
762
      $form->{"shiptocvar_$_->{name}"} = $_->{value} for @{ $cvars };
763
    }
764

  
751 765
    # get printed, emailed and queued
752 766
    $query = qq|SELECT s.printed, s.emailed, s.spoolfile, s.formname FROM status s WHERE s.trans_id = ?|;
753 767
    $sth   = prepare_execute_query($form, $dbh, $query, conv_i($form->{id}));
SL/Form.pm
1848 1848
    my $query = qq|SELECT * FROM shipto WHERE shipto_id = ?|;
1849 1849
    my $ref = selectfirst_hashref_query($self, $dbh, $query, $self->{shipto_id});
1850 1850
    map({ $self->{$_} = $ref->{$_} } keys(%$ref));
1851

  
1852
    my $cvars = CVar->get_custom_variables(
1853
      dbh      => $dbh,
1854
      module   => 'ShipTo',
1855
      trans_id => $self->{shipto_id},
1856
    );
1857
    $self->{"shiptocvar_$_->{name}"} = $_->{value} for @{ $cvars };
1851 1858
  }
1852 1859

  
1853 1860
  $main::lxdebug->leave_sub();
1854 1861
}
1855 1862

  
1856 1863
sub add_shipto {
1857
  $main::lxdebug->enter_sub();
1858

  
1859 1864
  my ($self, $dbh, $id, $module) = @_;
1860 1865

  
1861 1866
  my $shipto;
......
1869 1874
    push(@values, $self->{"shipto${item}"});
1870 1875
  }
1871 1876

  
1872
  if ($shipto) {
1873
    if ($self->{shipto_id}) {
1874
      my $query = qq|UPDATE shipto set
1875
                       shiptoname = ?,
1876
                       shiptodepartment_1 = ?,
1877
                       shiptodepartment_2 = ?,
1878
                       shiptostreet = ?,
1879
                       shiptozipcode = ?,
1880
                       shiptocity = ?,
1881
                       shiptocountry = ?,
1882
                       shiptogln = ?,
1883
                       shiptocontact = ?,
1884
                       shiptocp_gender = ?,
1885
                       shiptophone = ?,
1886
                       shiptofax = ?,
1887
                       shiptoemail = ?
1888
                     WHERE shipto_id = ?|;
1889
      do_query($self, $dbh, $query, @values, $self->{shipto_id});
1890
    } else {
1891
      my $query = qq|SELECT * FROM shipto
1892
                     WHERE shiptoname = ? AND
1893
                       shiptodepartment_1 = ? AND
1894
                       shiptodepartment_2 = ? AND
1895
                       shiptostreet = ? AND
1896
                       shiptozipcode = ? AND
1897
                       shiptocity = ? AND
1898
                       shiptocountry = ? AND
1899
                       shiptogln = ? AND
1900
                       shiptocontact = ? AND
1901
                       shiptocp_gender = ? AND
1902
                       shiptophone = ? AND
1903
                       shiptofax = ? AND
1904
                       shiptoemail = ? AND
1905
                       module = ? AND
1906
                       trans_id = ?|;
1907
      my $insert_check = selectfirst_hashref_query($self, $dbh, $query, @values, $module, $id);
1908
      if(!$insert_check){
1909
        $query =
1910
          qq|INSERT INTO shipto (trans_id, shiptoname, shiptodepartment_1, shiptodepartment_2,
1911
                                 shiptostreet, shiptozipcode, shiptocity, shiptocountry, shiptogln,
1912
                                 shiptocontact, shiptocp_gender, shiptophone, shiptofax, shiptoemail, module)
1913
             VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
1914
        do_query($self, $dbh, $query, $id, @values, $module);
1915
      }
1877
  return if !$shipto;
1878

  
1879
  my $shipto_id = $self->{shipto_id};
1880

  
1881
  if ($self->{shipto_id}) {
1882
    my $query = qq|UPDATE shipto set
1883
                     shiptoname = ?,
1884
                     shiptodepartment_1 = ?,
1885
                     shiptodepartment_2 = ?,
1886
                     shiptostreet = ?,
1887
                     shiptozipcode = ?,
1888
                     shiptocity = ?,
1889
                     shiptocountry = ?,
1890
                     shiptogln = ?,
1891
                     shiptocontact = ?,
1892
                     shiptocp_gender = ?,
1893
                     shiptophone = ?,
1894
                     shiptofax = ?,
1895
                     shiptoemail = ?
1896
                   WHERE shipto_id = ?|;
1897
    do_query($self, $dbh, $query, @values, $self->{shipto_id});
1898
  } else {
1899
    my $query = qq|SELECT * FROM shipto
1900
                   WHERE shiptoname = ? AND
1901
                     shiptodepartment_1 = ? AND
1902
                     shiptodepartment_2 = ? AND
1903
                     shiptostreet = ? AND
1904
                     shiptozipcode = ? AND
1905
                     shiptocity = ? AND
1906
                     shiptocountry = ? AND
1907
                     shiptogln = ? AND
1908
                     shiptocontact = ? AND
1909
                     shiptocp_gender = ? AND
1910
                     shiptophone = ? AND
1911
                     shiptofax = ? AND
1912
                     shiptoemail = ? AND
1913
                     module = ? AND
1914
                     trans_id = ?|;
1915
    my $insert_check = selectfirst_hashref_query($self, $dbh, $query, @values, $module, $id);
1916
    if(!$insert_check){
1917
      my $insert_query =
1918
        qq|INSERT INTO shipto (trans_id, shiptoname, shiptodepartment_1, shiptodepartment_2,
1919
                               shiptostreet, shiptozipcode, shiptocity, shiptocountry, shiptogln,
1920
                               shiptocontact, shiptocp_gender, shiptophone, shiptofax, shiptoemail, module)
1921
           VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
1922
      do_query($self, $dbh, $insert_query, $id, @values, $module);
1923

  
1924
      $insert_check = selectfirst_hashref_query($self, $dbh, $query, @values, $module, $id);
1916 1925
    }
1926

  
1927
    $shipto_id = $insert_check->{shipto_id};
1917 1928
  }
1918 1929

  
1919
  $main::lxdebug->leave_sub();
1930
  return unless $shipto_id;
1931

  
1932
  CVar->save_custom_variables(
1933
    dbh         => $dbh,
1934
    module      => 'ShipTo',
1935
    trans_id    => $shipto_id,
1936
    variables   => $self,
1937
    name_prefix => 'shipto',
1938
  );
1920 1939
}
1921 1940

  
1922 1941
sub get_employee {
......
3375 3394
    $self->{"employee_${_}"} = $defaults->$_   for qw(address businessnumber co_ustid company duns sepa_creditor_id taxnumber);
3376 3395
  }
3377 3396

  
3378
  # Load shipping address from database if shipto_id is set.
3379
  if ($self->{shipto_id}) {
3380
    my $shipto  = SL::DB::Shipto->new(shipto_id => $self->{shipto_id})->load;
3397
  # Load shipping address from database. If shipto_id is set then it's
3398
  # one from the customer's/vendor's master data. Otherwise look an a
3399
  # customized address linking back to the current record.
3400
  my $shipto_module = $self->{type} =~ /_delivery_order$/                                             ? 'DO'
3401
                    : $self->{type} =~ /sales_order|sales_quotation|request_quotation|purchase_order/ ? 'OE'
3402
                    :                                                                                   'AR';
3403
  my $shipto        = $self->{shipto_id} ? SL::DB::Shipto->new(shipto_id => $self->{shipto_id})->load
3404
                    :                      SL::DB::Manager::Shipto->get_first(where => [ module => $shipto_module, trans_id => $self->{id} ]);
3405
  if ($shipto) {
3381 3406
    $self->{$_} = $shipto->$_ for grep { m{^shipto} } map { $_->name } @{ $shipto->meta->columns };
3407
    $self->{"shiptocvar_" . $_->config->name} = $_->value_as_text for @{ $shipto->cvars_by_config };
3382 3408
  }
3383 3409

  
3384 3410
  my $language = $self->{language} ? '_' . $self->{language} : '';
SL/IS.pm
1818 1818
  # delete acc_trans
1819 1819
  my @values = (conv_i($form->{id}));
1820 1820
  do_query($form, $dbh, qq|DELETE FROM acc_trans WHERE trans_id = ?|, @values);
1821

  
1822
  $query = qq|DELETE FROM custom_variables
1823
              WHERE (config_id IN (SELECT id        FROM custom_variable_configs WHERE (module = 'ShipTo')))
1824
                AND (trans_id  IN (SELECT shipto_id FROM shipto                  WHERE (module = 'AR') AND (trans_id = ?)))|;
1825
  do_query($form, $dbh, $query, @values);
1821 1826
  do_query($form, $dbh, qq|DELETE FROM shipto WHERE (trans_id = ?) AND (module = 'AR')|, @values);
1822 1827

  
1823 1828
  $main::lxdebug->leave_sub();
......
2049 2054
    }
2050 2055
    $sth->finish;
2051 2056

  
2057
    # Fetch shipping address.
2058
    $query = qq|SELECT s.* FROM shipto s WHERE s.trans_id = ? AND s.module = 'AR'|;
2059
    $ref   = selectfirst_hashref_query($form, $dbh, $query, $form->{id});
2060

  
2061
    $form->{$_} = $ref->{$_} for grep { $_ ne 'id' } keys %$ref;
2062

  
2063
    if ($form->{shipto_id}) {
2064
      my $cvars = CVar->get_custom_variables(
2065
        dbh      => $dbh,
2066
        module   => 'ShipTo',
2067
        trans_id => $form->{shipto_id},
2068
      );
2069
      $form->{"shiptocvar_$_->{name}"} = $_->{value} for @{ $cvars };
2070
    }
2071

  
2052 2072
    Common::webdav_folder($form);
2053 2073
  }
2054 2074

  
SL/OE.pm
421 421
  $form->{$number_field} ||= $trans_number->create_unique; # set $form->{ordnumber} or $form->{quonumber}
422 422

  
423 423
  if ($form->{id}) {
424
    $query = qq|DELETE FROM custom_variables
425
                WHERE (config_id IN (SELECT id        FROM custom_variable_configs WHERE (module = 'ShipTo')))
426
                  AND (trans_id  IN (SELECT shipto_id FROM shipto                  WHERE (module = 'OE') AND (trans_id = ?)))|;
427
    do_query($form, $dbh, $query, $form->{id});
428

  
424 429
    $query = qq|DELETE FROM shipto | .
425 430
             qq|WHERE trans_id = ? AND module = 'OE'|;
426 431
    do_query($form, $dbh, $query, $form->{id});
......
1011 1016
      map { $form->{$_} = $ref->{$_} } keys %$ref;
1012 1017
      $sth->finish;
1013 1018

  
1019
      if ($form->{shipto_id}) {
1020
        my $cvars = CVar->get_custom_variables(
1021
          dbh      => $dbh,
1022
          module   => 'ShipTo',
1023
          trans_id => $form->{shipto_id},
1024
        );
1025
        $form->{"shiptocvar_$_->{name}"} = $_->{value} for @{ $cvars };
1026
      }
1027

  
1014 1028
      # get printed, emailed and queued
1015 1029
      $query = qq|SELECT s.printed, s.emailed, s.spoolfile, s.formname FROM status s WHERE s.trans_id = ?|;
1016 1030
      $sth = prepare_execute_query($form, $dbh, $query, $form->{id});
bin/mozilla/do.pl
327 327

  
328 328
  $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.SalesPurchase ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_customer autocomplete_part));
329 329

  
330
  my @custom_hidden;
331
  push @custom_hidden, map { "shiptocvar_" . $_->name } @{ SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'ShipTo' ]) };
332

  
333
  $::form->{HIDDENS} = [ map { +{ name => $_, value => $::form->{$_} } } (@custom_hidden) ];
334

  
330 335
  $form->header();
331 336
  # Fix für Bug 1082 Erwartet wird: 'abteilungsNAME--abteilungsID'
332 337
  # und Erweiterung für Bug 1760:
bin/mozilla/io.pl
1648 1648
  call_sub($::form->{vc} . "_details", qw(name department_1 department_2 street zipcode city country gln contact email phone fax), $::form->{vc} . "number");
1649 1649
  $::form->{rowcount}--;
1650 1650

  
1651
  my $cvars         = SL::DB::Shipto->new->cvars_by_config;
1651 1652
  my @shipto_vars   = qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptogln
1652 1653
                         shiptocontact shiptocp_gender shiptophone shiptofax shiptoemail
1653 1654
                         shiptodepartment_1 shiptodepartment_2);
1654
  my $previous_form = $::auth->save_form_in_session(skip_keys => [ @shipto_vars, qw(header shipto_id) ]);
1655
  my $previous_form = $::auth->save_form_in_session(skip_keys => [ @shipto_vars, qw(header shipto_id), map { "shiptocvar_" . $_->config->name } @{ $cvars } ]);
1655 1656
  $::form->{title}  = $::locale->text('Ship to');
1656 1657
  $::form->header;
1657 1658

  
1658 1659
  my $vc_obj = ($::form->{vc} eq 'customer' ? "SL::DB::Customer" : "SL::DB::Vendor")->new(id => $::form->{$::form->{vc} . "_id"})->load;
1659 1660

  
1661
  $_->value($::form->{"shiptocvar_" . $_->config->name}) for @{ $cvars };
1662

  
1660 1663
  print $::form->parse_html_template('io/ship_to', { previousform => $previous_form,
1661 1664
                                                     nextsub      => $::form->{display_form} || 'display_form',
1662 1665
                                                     vc_obj       => $vc_obj,
1666
                                                     cvars        => $cvars,
1663 1667
                                                   });
1664 1668

  
1665 1669
  $main::lxdebug->leave_sub();
bin/mozilla/is.pl
380 380
  $TMPL_VAR{dateformat}          = $myconfig{dateformat};
381 381
  $TMPL_VAR{numberformat}        = $myconfig{numberformat};
382 382

  
383
  push @custom_hiddens, map { "shiptocvar_" . $_->name } @{ SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'ShipTo' ]) };
384

  
383 385
  # hiddens
384 386
  $TMPL_VAR{HIDDENS} = [qw(
385 387
    id action type media format queued printed emailed title vc discount
bin/mozilla/oe.pl
473 473
  if ($form->{CFDD_shipto} && $form->{CFDD_shipto_id} ) {
474 474
      $form->{shipto_id} = $form->{CFDD_shipto_id};
475 475
  }
476

  
477
  push @custom_hiddens, map { "shiptocvar_" . $_->name } @{ SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'ShipTo' ]) };
478

  
476 479
  $TMPL_VAR{HIDDENS} = [ map { name => $_, value => $form->{$_} },
477 480
     qw(id action type vc formname media format proforma queued printed emailed
478 481
        title creditlimit creditremaining tradediscount business
......
1731 1734
    return;
1732 1735
  }
1733 1736

  
1737
  my $cvars = SL::DB::Shipto->new->cvars_by_config;
1738

  
1734 1739
  if ($form->{shipto_id}) {
1735 1740
    Common->get_shipto_by_id(\%myconfig, $form, $form->{shipto_id}, "CFDD_");
1736 1741

  
......
1738 1743
    map { $form->{"CFDD_${_}"} = $form->{$_ } } grep /^shipto/, keys %{ $form };
1739 1744
  }
1740 1745

  
1746
  $_->value($::form->{"CFDD_shiptocvar_" . $_->config->name}) for @{ $cvars };
1747

  
1741 1748
  delete $form->{action};
1742 1749
  $form->{VARIABLES} = [ map { { "key" => $_, "value" => $form->{$_} } } grep { ($_ ne 'login') && ($_ ne 'password') && (ref $_ eq "") } keys %{ $form } ];
1743 1750

  
1744 1751
  $form->header();
1745
  print $form->parse_html_template("oe/check_for_direct_delivery");
1752
  print $form->parse_html_template("oe/check_for_direct_delivery", { cvars => $cvars });
1746 1753

  
1747 1754
  $main::lxdebug->leave_sub();
1748 1755

  
templates/webpages/do/form_header.html
110 110
  <input type="hidden" name="type" value="[% HTML.escape(type) %]">
111 111
  <input type="hidden" name="vc" value="[% HTML.escape(vc) %]">
112 112
  <input type="hidden" name="lastmtime" value="[% HTML.escape(lastmtime) %]">
113
[%- FOREACH row = HIDDENS %]
114
   [% L.hidden_tag(row.name, row.value) %]
115
[%- END %]
113 116

  
114 117
  <p>
115 118
   <table width="100%">
templates/webpages/io/ship_to.html
15 15
      shiptophone:        "[% JavaScript.escape(vc_obj.phone) %]",
16 16
      shiptofax:          "[% JavaScript.escape(vc_obj.fax) %]",
17 17
      shiptoemail:        "[% JavaScript.escape(vc_obj.email) %]"
18
[% FOREACH var = cvars %]
19
      , "shiptocvar_[% JavaScript.escape(var.config.name) %]": ""
20
[% END %]
18 21
    }
19 22

  
20 23
  [% FOREACH shipto = vc_obj.shipto %]
......
32 35
      shiptophone:        "[% JavaScript.escape(shipto.shiptophone) %]",
33 36
      shiptofax:          "[% JavaScript.escape(shipto.shiptofax) %]",
34 37
      shiptoemail:        "[% JavaScript.escape(shipto.shiptoemail) %]"
38
    [% FOREACH var = shipto.cvars_by_config %]
39
      , "shiptocvar_[% JavaScript.escape(var.config.name) %]": "[% JavaScript.escape(var.value_as_text) %]"
40
    [% END %]
35 41
    }
36 42
  [% END %]
37 43
  ];
......
156 162
    <td>[% HTML.escape(email) %]</td>
157 163
    <td>[% L.input_tag("shiptoemail", shiptoemail, "size", "35") %]</td>
158 164
   </tr>
165
[% FOREACH var = cvars %]
166
   <tr valign="top">
167
    <th align="right" nowrap>[% HTML.escape(var.config.description) %]</th>
168
    <td></td>
169
    <td>[% INCLUDE 'common/render_cvar_input.html' cvar_name_prefix='shiptocvar_' %]</td>
170
   </tr>
171
[% END %]
159 172
  </table>
160 173

  
161 174
  <hr size="3" noshade>
templates/webpages/oe/check_for_direct_delivery.html
65 65
    <th align="right" valign="top">[% 'E-mail' | $T8 %]:</th>
66 66
    <td valign="top">[% HTML.escape(CFDD_shiptoemail) %]</td>
67 67
   </tr>
68

  
69
[% FOREACH var = cvars %]
70
   <tr valign="top">
71
    <th align="right" nowrap>[% HTML.escape(var.config.description) %]</th>
72
    <td>[% HTML.escape(var.value_as_text) %]</td>
73
   </tr>
74
[% END %]
68 75
  </table>
69 76
 </p>
70 77

  

Auch abrufbar als: Unified diff