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/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} : '';

Auch abrufbar als: Unified diff