Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 0484d9e0

Von Moritz Bunkus vor fast 18 Jahren hinzugefügt

  • ID 0484d9e05fcfb8bd52a850010bec25d6cda4a28e
  • Vorgänger c0f83f3e
  • Nachfolger f7057756

Keine Form-Variablen direkt in SQL-Queries verwenden.

Unterschiede anzeigen:

SL/OP.pm
34 34

  
35 35
package OP;
36 36

  
37
use SL::DBUtils;
38

  
37 39
sub overpayment {
38 40
  $main::lxdebug->enter_sub();
39 41

  
40 42
  my ($self, $myconfig, $form, $dbh, $amount, $ml) = @_;
41 43

  
42 44
  my $fxamount = $form->round_amount($amount * $form->{exchangerate}, 2);
43
  my ($paymentaccno) = split /--/, $form->{account};
45
  my ($paymentaccno) = split(/--/, $form->{account});
44 46

  
45
  my $vc_id = "$form->{vc}_id";
47
  my $vc_id = $form->{vc} eq "customer" ? "customer_id" : "vendor_id";
48
  my $arap = $form->{arap} eq "ar" ? "ar" : "ap";
46 49

  
47
  my $uid = time;
48
  $uid .= $form->{login};
50
  my $query = qq|SELECT nextval('glid')|;
51
  my ($new_id) = selectrow_query($form, $dbh, $query);
49 52

  
50 53
  # add AR/AP header transaction with a payment
51
  $query = qq|INSERT INTO $form->{arap} (invnumber, employee_id)
52
	      VALUES ('$uid', (SELECT e.id FROM employee e
53
			     WHERE e.login = '$form->{login}'))|;
54
  $dbh->do($query) || $form->dberror($query);
55

  
56
  $query = qq|SELECT a.id FROM $form->{arap} a
57
	    WHERE a.invnumber = '$uid'|;
58
  $sth = $dbh->prepare($query);
59
  $sth->execute || $form->dberror($query);
60

  
61
  ($uid) = $sth->fetchrow_array;
62
  $sth->finish;
63

  
64
  my $invnumber = ($form->{invnumber}) ? $form->{invnumber} : $uid;
65
  $query = qq|UPDATE $form->{arap} set
66
	      invnumber = '$invnumber',
67
	      $vc_id = $form->{"$form->{vc}_id"},
68
	      transdate = '$form->{datepaid}',
69
	      datepaid = '$form->{datepaid}',
70
	      duedate = '$form->{datepaid}',
71
	      netamount = 0,
72
	      amount = 0,
73
	      paid = $fxamount,
74
	      curr = '$form->{currency}',
75
	      department_id = $form->{department_id}
76
	      WHERE id = $uid|;
77
  $dbh->do($query) || $form->dberror($query);
54
  $query =
55
    qq|INSERT INTO $arap (id, invnumber, employee_id) | .
56
    qq|VALUES (?, ?, (SELECT id FROM employee WHERE login = ?))|;
57
  my @values = ($new_id, $form->{login}, $form->{login});
58
  do_query($form, $dbh, $query, @values);
59

  
60
  my $invnumber = ($form->{invnumber}) ? $form->{invnumber} : $new_id;
61
  $query =
62
    qq|UPDATE $arap SET invnumber = ?, $vc_id = ?, transdate = ?, datepaid = ?, | .
63
    qq|duedate = ?, netamount = ?, amount = ?, paid = ?, | .
64
    qq|curr = ?, department_id = ? | .
65
    qq|WHERE id = ?|;
66
  @values = ($invnumber, $form->{$vc_id},
67
             conv_date($form->{datepaid}), conv_date($form->{datepaid}),
68
             conv_date($form->{datepaid}), 0, 0, $fxamount, $form->{currency},
69
             $form->{department_id}, $new_id);
70
  do_query($form, $dbh, $query, @values);
78 71

  
79 72
  # add AR/AP
80 73
  ($accno) = split /--/, $form->{ $form->{ARAP} };
81 74

  
82
  $query = qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, amount)
83
	      VALUES ($uid, (SELECT c.id FROM chart c
84
			     WHERE c.accno = '$accno'),
85
	      '$form->{datepaid}', $fxamount * $ml)|;
86
  $dbh->do($query) || $form->dberror($query);
75
  $query =
76
    qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, amount) | .
77
    qq|VALUES (?, (SELECT id FROM chart WHERE accno = ? ), ?, ?)|;
78
	@values = ($new_id, $accno, conv_date($form->{datepaid}), $fxamount * $ml);
79
  do_query($form, $dbh, $query, @values);
87 80

  
88 81
  # add payment
89
  $query = qq|INSERT INTO acc_trans (trans_id, chart_id, transdate,
90
	      amount, source, memo)
91
	      VALUES ($uid, (SELECT c.id FROM chart c
92
			     WHERE c.accno = '$paymentaccno'),
93
		'$form->{datepaid}', $amount * $ml * -1,
94
		'$form->{source}', '$form->{memo}')|;
95
  $dbh->do($query) || $form->dberror($query);
82
  $query =
83
    qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, amount, source, memo) | .
84
    qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?)|;
85
  @values = ($new_id, $paymentaccno, conv_date($form->{datepaid}),
86
             $amount * $ml * -1, $form->{source}, $form->{memo});
87
  do_query($form, $dbh, $query, @values);
96 88

  
97 89
  # add exchangerate difference
98 90
  if ($fxamount != $amount) {
99
    $query = qq|INSERT INTO acc_trans (trans_id, chart_id, transdate,
100
		amount, cleared, fx_transaction)
101
		VALUES ($uid, (SELECT c.id FROM chart c
102
			       WHERE c.accno = '$paymentaccno'),
103
	      '$form->{datepaid}', ($fxamount - $amount) * $ml * -1,
104
	      '1', '1')|;
105
    $dbh->do($query) || $form->dberror($query);
91
    $query =
92
      qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, amount, cleared, fx_transaction) | .
93
      qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?)|;
94
	  @values = ($new_id, $paymentaccno, conv_date($form->{datepaid}),
95
               (($fxamount - $amount) * $ml * -1), 1, 1);
96
    do_query($form, $dbh, $query, @values);
106 97
  }
107 98

  
108 99
  $main::lxdebug->leave_sub();

Auch abrufbar als: Unified diff