Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 15682dc4

Von Moritz Bunkus vor fast 18 Jahren hinzugefügt

  • ID 15682dc47316fcc2deab66730045cd38afec001f
  • Vorgänger f27a8a8f
  • Nachfolger 8e206587

Drop-Down-Auswahlboxen für Ansprechpartner und Lieferadresse bei jedem Maskenaufbau aus der Datenbank aufbauen. Für den HTML-Code wird jetzt das CGI-Modul verwendet.

Unterschiede anzeigen:

SL/Form.pm
1395 1395
  $main::lxdebug->leave_sub();
1396 1396
}
1397 1397

  
1398
# get other contact for transaction and form - html/tex
1399
sub get_contact {
1398
# get contacts for id, if no contact return {"","","","",""}
1399
sub get_contacts {
1400 1400
  $main::lxdebug->enter_sub();
1401 1401

  
1402
  my ($self, $dbh, $id) = @_;
1402
  my ($self, $dbh, $id, $key) = @_;
1403 1403

  
1404
  my $query = qq|SELECT c.*
1405
              FROM contacts c
1406
              WHERE cp_id=$id|;
1407
  $sth = $dbh->prepare($query);
1408
  $sth->execute || $self->dberror($query);
1404
  $key = "all_contacts" unless ($key);
1405
  $self->{$key} = [];
1409 1406

  
1410
  $ref = $sth->fetchrow_hashref(NAME_lc);
1407
  my $query =
1408
    qq|SELECT c.cp_id, c.cp_cv_id, c.cp_name, c.cp_givenname, c.cp_abteilung | .
1409
    qq|FROM contacts c | .
1410
    qq|WHERE cp_cv_id = ? | .
1411
    qq|ORDER BY lower(c.cp_name)|;
1412
  my $sth = $dbh->prepare($query);
1413
  $sth->execute($id) || $self->dberror($query . " ($id)");
1411 1414

  
1412
  push @{ $self->{$_} }, $ref;
1415
  my $i = 0;
1416
  while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
1417
    push @{ $self->{$key} }, $ref;
1418
    $i++;
1419
  }
1413 1420

  
1421
  if ($i == 0) {
1422
    push @{ $self->{$key} }, { { "", "", "", "", "", "" } };
1423
  }
1414 1424
  $sth->finish;
1415 1425
  $main::lxdebug->leave_sub();
1416 1426
}
1417 1427

  
1418
# get contacts for id, if no contact return {"","","","",""}
1419
sub get_contacts {
1428
sub get_lists {
1420 1429
  $main::lxdebug->enter_sub();
1421 1430

  
1422
  my ($self, $dbh, $id) = @_;
1431
  my $self = shift;
1432
  my %params = @_;
1433

  
1434
  my $dbh = $self->dbconnect(\%main::myconfig);
1435
  my ($sth, $query, $ref);
1423 1436

  
1424
  my $query = qq|SELECT c.cp_id, c.cp_cv_id, c.cp_name, c.cp_givenname, c.cp_abteilung
1425
              FROM contacts c
1426
              WHERE cp_cv_id=$id|;
1427
  my $sth = $dbh->prepare($query);
1428
  $sth->execute || $self->dberror($query);
1437
  my $vc = $self->{"vc"} eq "customer" ? "customer" : "vendor";
1438
  my $vc_id = $self->{"${vc}_id"};
1429 1439

  
1430
  my $i = 0;
1431
  while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
1432
    push @{ $self->{all_contacts} }, $ref;
1433
    $i++;
1440
  if ($params{"contacts"}) {
1441
    $self->get_contacts($dbh, $vc_id, $params{"contacts"});
1434 1442
  }
1435 1443

  
1436
  if ($i == 0) {
1437
    push @{ $self->{all_contacts} }, { { "", "", "", "", "", "" } };
1444
  if ($params{"shipto"}) {
1445
    # get shipping addresses
1446
    $query =
1447
      qq|SELECT s.shipto_id,s.shiptoname,s.shiptodepartment_1 | .
1448
      qq|FROM shipto s | .
1449
      qq|WHERE s.trans_id = ?|;
1450
    $sth = $dbh->prepare($query);
1451
    $sth->execute($vc_id) || $self->dberror($query . " ($vc_id)");
1452

  
1453
    $self->{$params{"shipto"}} = [];
1454
    while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1455
      push(@{ $self->{$params{"shipto"}} }, $ref);
1456
    }
1457
    $sth->finish;
1438 1458
  }
1439
  $sth->finish;
1459

  
1460
  $dbh->disconnect();
1461

  
1440 1462
  $main::lxdebug->leave_sub();
1441 1463
}
1442 1464

  
SL/IR.pm
81 81
    $sth->finish;
82 82
  }
83 83

  
84
  ($null, $form->{contact_id}) = split /--/, $form->{contact};
85
  $form->{contact_id} *= 1;
86

  
87 84
  map { $form->{$_} =~ s/\'/\'\'/g } qw(invnumber ordnumber quonumber);
88 85

  
89 86
  my ($amount, $linetotal, $lastinventoryaccno, $lastexpenseaccno);
......
641 638
	      curr = '$form->{currency}',
642 639
	      department_id = $form->{department_id},
643 640
              storno = '$form->{storno}',
644
              cp_id = $form->{contact_id}
641
              cp_id = | . conv_i($form->{cp_id}, 'NULL') . qq|
645 642
              WHERE id = $form->{id}|;
646 643
  $dbh->do($query) || $form->dberror($query);
647 644

  
......
1042 1039
  }
1043 1040
  $sth->finish;
1044 1041

  
1045
  $form->get_contacts($dbh, $form->{vendor_id});
1046

  
1047
  ($null, $form->{cp_id}) = split /--/, $form->{contact};
1048

  
1049
  # get contact if selected
1050
  if ($form->{contact} ne "--" && $form->{contact} ne "") {
1051
    $form->get_contact($dbh, $form->{cp_id});
1052
  }
1053

  
1054 1042
  # get shipto if we do not convert an order or invoice
1055 1043
  if (!$form->{shipto}) {
1056 1044
    map { delete $form->{$_} }
SL/IS.pm
475 475
    $form->get_employee($dbh);
476 476
  }
477 477

  
478
  $form->{contact_id} = $form->{cp_id};
479
  $form->{contact_id} *= 1;
480 478
  $form->{payment_id} *= 1;
481 479
  $form->{language_id} *= 1;
482 480
  $form->{taxzone_id} *= 1;
......
1010 1008
              delivery_vendor_id = $form->{delivery_vendor_id},
1011 1009
              employee_id = $form->{employee_id},
1012 1010
              storno = '$form->{storno}',
1013
              cp_id = $form->{contact_id}
1011
              cp_id = | . conv_i($form->{"cp_id"}, 'NULL') . qq|
1014 1012
              WHERE id = $form->{id}
1015 1013
             |;
1016 1014
  $dbh->do($query) || $form->dberror($query);
......
1775 1773
  }
1776 1774
  $sth->finish;
1777 1775

  
1778
  $form->get_contacts($dbh, $form->{customer_id});
1779
  $form->{cp_id} *= 1;
1780

  
1781
  # get contact if selected
1782
  if ($form->{cp_id}) {
1783
    $form->get_contact($dbh, $form->{cp_id});
1784
  }
1785

  
1786 1776
  # get shipto if we did not converted an order or invoice
1787 1777
  if (!$form->{shipto}) {
1788 1778
    map { delete $form->{$_} }
......
1813 1803
  }
1814 1804
  $sth->finish;
1815 1805

  
1816
  # get shipping addresses
1817
  $query = qq|SELECT s.shipto_id,s.shiptoname,s.shiptodepartment_1
1818
              FROM shipto s
1819
	      WHERE s.trans_id = $form->{customer_id}|;
1820
  $sth = $dbh->prepare($query);
1821
  $sth->execute || $form->dberror($query);
1822

  
1823
  my $customertax = ();
1824
  while ($ref = $sth->fetchrow_hashref(NAME_lc)) {
1825
    push(@{ $form->{SHIPTO} }, $ref);
1826
  }
1827
  $sth->finish;
1828

  
1829 1806
  # setup last accounts used for this customer
1830 1807
  if (!$form->{id} && $form->{type} !~ /_(order|quotation)/) {
1831 1808
    $query = qq|SELECT c.accno, c.description, c.link, c.category
SL/OE.pm
180 180
    $form->get_employee($dbh);
181 181
  }
182 182

  
183
  $form->{contact_id} = $form->{cp_id};
184
  $form->{contact_id} *= 1;
185 183
  $form->{payment_id} *= 1;
186 184
  $form->{language_id} *= 1;
187 185
  $form->{shipto_id} *= 1;
......
477 475
	      delivery_vendor_id = $form->{delivery_vendor_id},
478 476
	      delivery_customer_id = $form->{delivery_customer_id},
479 477
	      employee_id = $form->{employee_id},
480
              cp_id = $form->{contact_id}
478
              cp_id = | . conv_i($form->{cp_id}, 'NULL') . qq|
481 479
              WHERE id = $form->{id}|;
482 480
  $dbh->do($query) || $form->dberror($query);
483 481

  
am.pl
42 42
use SL::LXDebug;
43 43
$lxdebug = LXDebug->new();
44 44

  
45
use CGI;
45 46
use SL::Form;
46 47
use SL::Locale;
47 48

  
......
53 54
}
54 55

  
55 56
$form = new Form;
57
$cgi = new CGI('');
56 58

  
57 59
# name of this script
58 60
$0 =~ tr/\\/\//;
bin/mozilla/ir.pl
219 219
  $lxdebug->enter_sub();
220 220

  
221 221
  # set option selected
222
  foreach $item (qw(AP vendor currency department contact)) {
222
  foreach $item (qw(AP vendor currency department)) {
223 223
    $form->{"select$item"} =~ s/ selected//;
224 224
    $form->{"select$item"} =~
225 225
      s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
......
239 239
  $form->{creditremaining} =
240 240
    $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
241 241

  
242
  #build contacts
243
  if ($form->{all_contacts}) {
244

  
245
    $form->{selectcontact} = "";
246
    foreach $item (@{ $form->{all_contacts} }) {
247
      if ($form->{cp_id} == $item->{cp_id}) {
248
        $form->{selectcontact} .=
249
          "<option selected>$item->{cp_name}--$item->{cp_id}";
250
      } else {
251
        $form->{selectcontact} .= "<option>$item->{cp_name}--$item->{cp_id}";
252
      }
253
    }
254
  }
255

  
256 242
  $exchangerate = "";
257 243
  if ($form->{currency} ne $form->{defaultcurrency}) {
258 244
    if ($form->{forex}) {
......
273 259
<input type=hidden name=forex value=$form->{forex}>
274 260
|;
275 261

  
262
  $form->get_lists("contacts" => "ALL_CONTACTS");
263

  
264
  my (%labels, @values);
265
  foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
266
    push(@values, $item->{"cp_id"});
267
    $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
268
      ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
269
  }
270
  my $contact =
271
    $cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
272
                     '-labels' => \%labels, '-default' => $form->{"cp_id"});
276 273

  
277 274
  if (@{ $form->{TAXZONE} }) {
278 275
    $form->{selecttaxzone} = "";
......
308 305
    ? qq|<select name=vendor>$form->{selectvendor}</select>\n<input type=hidden name="selectvendor" value="$form->{selectvendor}">|
309 306
    : qq|<input name=vendor value="$form->{vendor}" size=35>|;
310 307

  
311
  $contact =
312
    ($form->{selectcontact})
313
    ? qq|<select name=contact>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">|
314
    : qq|<input name=contact value="$form->{contact}" size=35>|;
315

  
316 308
  $department = qq|
317 309
              <tr>
318 310
	      <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
bin/mozilla/is.pl
353 353
		<input type=hidden name=selecttaxzone value="$form->{selecttaxzone}">
354 354
	      </tr>|;
355 355

  
356

  
357
  if (@{ $form->{SHIPTO} }) {
358
    $form->{selectshipto} = "<option value=0></option>";
359
    foreach $item (@{ $form->{SHIPTO} }) {
360
      if ($item->{shipto_id} == $form->{shipto_id}) {
361
        $form->{selectshipto} .=
362
          "<option value=$item->{shipto_id} selected>$item->{shiptoname} $item->{shiptodepartment_1}</option>";
363
      } else {
364
        $form->{selectshipto} .=
365
          "<option value=$item->{shipto_id}>$item->{shiptoname} $item->{shiptodepartment}</option>";
366
      }
367

  
368
    }
369
  } else {
370
    $form->{selectshipto} = $form->unquote($form->{selectshipto});
371
    $form->{selectshipto} =~ s/ selected//g;
372
    if ($form->{shipto_id} ne "") {
373
      $form->{selectshipto} =~ s/value=$form->{shipto_id}/value=$form->{shipto_id} selected/;
374
    }
356
  $form->get_lists("contacts" => "ALL_CONTACTS",
357
                   "shipto" => "ALL_SHIPTO");
358

  
359
  my (%labels, @values);
360
  foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
361
    push(@values, $item->{"cp_id"});
362
    $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
363
      ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
364
  }
365
  my $contact =
366
    $cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
367
                     '-labels' => \%labels, '-default' => $form->{"cp_id"});
368

  
369
  %labels = ();
370
  @values = ("");
371
  foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
372
    push(@values, $item->{"shipto_id"});
373
    $labels{$item->{"shipto_id"}} =
374
      $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
375 375
  }
376 376

  
377
  $shipto = qq|
377
  my $shipto = qq|
378 378
		<th align=right>| . $locale->text('Shipping Address') . qq|</th>
379
		<td><select name=shipto_id style="width:200px;">$form->{selectshipto}</select></td>|;
380
  $form->{selectshipto} = $form->quote($form->{selectshipto});
381
  $shipto .= qq| <input type=hidden name=selectshipto value="$form->{selectshipto}">|;
382

  
383

  
379
		<td>| .
380
    $cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
381
                     '-labels' => \%labels, '-default' => $form->{"shipto_id"})
382
    . qq|</td>|;
384 383

  
385 384
  # set option selected
386 385
  foreach $item (qw(AR customer currency department employee)) {
......
392 391
  #quote customer Bug 133
393 392
  $form->{selectcustomer} = $form->quote($form->{selectcustomer});
394 393
  
395
  #build contacts
396
  if ($form->{all_contacts}) {
397

  
398
    $form->{selectcontact} = "<option></option>";
399
    foreach $item (@{ $form->{all_contacts} }) {
400
      my $department = ($item->{cp_abteilung}) ? "--$item->{cp_abteilung}" : "";
401
      if ($form->{cp_id} == $item->{cp_id}) {
402
        $form->{selectcontact} .=
403
          "<option value=$item->{cp_id} selected>$item->{cp_name}$department</option>";
404
      } else {
405
        $form->{selectcontact} .= "<option value=$item->{cp_id}>$item->{cp_name}$department</option>";
406
      }
407
    }
408
  } else {
409
    $form->{selectcontact} =~ s/ selected//g;
410
    if ($form->{cp_id} ne "") {
411
      $form->{selectcontact} =~ s/value=$form->{cp_id}/value=$form->{cp_id} selected/;
412
    }
413
  }
414

  
415

  
416 394
  if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) {
417 395
    $creditwarning = 1;
418 396
  } else {
419 397
    $creditwarning = 0;
420 398
  }
421 399

  
422
  #else {$form->{all_contacts} = 0;}
423

  
424 400
  $form->{exchangerate} =
425 401
    $form->format_amount(\%myconfig, $form->{exchangerate});
426 402

  
......
452 428
    ? qq|<select name=customer>$form->{selectcustomer}</select>\n<input type=hidden name="selectcustomer" value="$form->{selectcustomer}">|
453 429
    : qq|<input name=customer value="$form->{customer}" size=35>|;
454 430

  
455
  #sk
456
  $contact =
457
    ($form->{selectcontact})
458
    ? qq|<select name=cp_id>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">|
459
    : qq|<input name=contact value="$form->{contact}" size=35>|;
460

  
461 431
  $department = qq|
462 432
              <tr>
463 433
	        <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
bin/mozilla/oe.pl
407 407
  #quote select[customer|vendor] Bug 133
408 408
  $form->{"select$form->{vc}"} = $form->quote($form->{"select$form->{vc}"});
409 409

  
410
  #build contacts
411
  if ($form->{all_contacts}) {
412

  
413
    $form->{selectcontact} = "<option></option>";
414
    foreach $item (@{ $form->{all_contacts} }) {
415
      my $department = ($item->{cp_abteilung}) ? "--$item->{cp_abteilung}" : "";
416
      if ($form->{cp_id} == $item->{cp_id}) {
417
        $form->{selectcontact} .=
418
          "<option value=$item->{cp_id} selected>$item->{cp_name}$department</option>";
419
      } else {
420
        $form->{selectcontact} .= "<option value=$item->{cp_id}>$item->{cp_name}$department</option>";
421
      }
422
    }
423
  } else {
424
    $form->{selectcontact} =~ s/ selected//g;
425
    if ($form->{cp_id} ne "") {
426
      $form->{selectcontact} =~ s/value=$form->{cp_id}/value=$form->{cp_id} selected/;
427
    }
428
  }
410
  $form->get_lists("contacts" => "ALL_CONTACTS",
411
                   "shipto" => "ALL_SHIPTO");
429 412

  
413
  my (%labels, @values);
414
  foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
415
    push(@values, $item->{"cp_id"});
416
    $labels{$item->{"cp_id"}} = $item->{"cp_name"} .
417
      ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
418
  }
419
  my $contact =
420
    $cgi->popup_menu('-name' => 'cp_id', '-values' => \@values,
421
                     '-labels' => \%labels, '-default' => $form->{"cp_id"});
430 422

  
431
  if (@{ $form->{SHIPTO} }) {
432
    $form->{selectshipto} = "<option value=0></option>";
433
    foreach $item (@{ $form->{SHIPTO} }) {
434
      if ($item->{shipto_id} == $form->{shipto_id}) {
435
        $form->{selectshipto} .=
436
          "<option value=$item->{shipto_id} selected>$item->{shiptoname} $item->{shiptodepartment_1}</option>";
437
      } else {
438
        $form->{selectshipto} .=
439
          "<option value=$item->{shipto_id}>$item->{shiptoname} $item->{shiptodepartment}</option>";
440
      }
441

  
442
    }
443
  } else {
444
    $form->{selectshipto} = $form->unquote($form->{selectshipto});
445
    $form->{selectshipto} =~ s/ selected//g;
446
    if ($form->{shipto_id} ne "") {
447
      $form->{selectshipto} =~ s/value=$form->{shipto_id}/value=$form->{shipto_id} selected/;
448
    }
423
  %labels = ();
424
  @values = ("");
425
  foreach my $item (@{ $form->{"ALL_SHIPTO"} }) {
426
    push(@values, $item->{"shipto_id"});
427
    $labels{$item->{"shipto_id"}} =
428
      $item->{"shiptoname"} . " " . $item->{"shiptodepartment_1"};
449 429
  }
450 430

  
451
  $shipto = qq|
431
  my $shipto = qq|
452 432
		<th align=right>| . $locale->text('Shipping Address') . qq|</th>
453
		<td><select name=shipto_id style="width:200px;">$form->{selectshipto}</select></td>|;
454
  $form->{selectshipto} = $form->quote($form->{selectshipto});
455
  $shipto .= qq| <input type=hidden name=selectshipto value="$form->{selectshipto}">|;
456

  
457

  
433
		<td>| .
434
    $cgi->popup_menu('-name' => 'shipto_id', '-values' => \@values,
435
                     '-labels' => \%labels, '-default' => $form->{"shipto_id"})
436
    . qq|</td>|;
458 437

  
459 438
  $form->{exchangerate} =
460 439
    $form->format_amount(\%myconfig, $form->{exchangerate});
......
470 449
  $form->{creditremaining} =
471 450
    $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
472 451

  
473
  $contact =
474
    ($form->{selectcontact})
475
    ? qq|<select name=cp_id>$form->{selectcontact}</select>\n<input type=hidden name="selectcontact" value="$form->{selectcontact}">|
476
    : qq|<input name=contact value="$form->{contact}" size=35>|;
477

  
478 452
  $exchangerate = qq|
479 453
<input type=hidden name=forex value=$form->{forex}>
480 454
|;

Auch abrufbar als: Unified diff