Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 02b31f92

Von Moritz Bunkus vor fast 8 Jahren hinzugefügt

  • ID 02b31f9250ed39394490ed94a08c5e96cd767a65
  • Vorgänger db1d60aa
  • Nachfolger d30c34a5

Zahlungsein-/-ausgänge: Kunden-/Lieferantenpicker verwenden

Unterschiede anzeigen:

SL/CP.pm
101 101
  $main::lxdebug->leave_sub();
102 102
}
103 103

  
104
sub get_openvc {
105
  $main::lxdebug->enter_sub();
106

  
107
  my ($self, $myconfig, $form) = @_;
108

  
109
  my $dbh = SL::DB->client->dbh;
110

  
111
  my $arap = ($form->{vc} eq 'customer') ? 'ar' : 'ap';
112
  my $vc = $form->{vc} eq "customer" ? "customer" : "vendor";
113
  my $query =
114
    qq|SELECT count(*) | .
115
    qq|FROM $vc ct, $arap a | .
116
    qq|WHERE (a.${vc}_id = ct.id) AND (a.amount != a.paid)|;
117
  my ($count) = selectrow_query($form, $dbh, $query);
118

  
119
  # build selection list
120
  if ($count < $myconfig->{vclimit}) {
121
    $query =
122
      qq|SELECT DISTINCT ct.id, ct.name | .
123
      qq|FROM $vc ct, $arap a | .
124
      qq|WHERE (a.${vc}_id = ct.id) AND (a.amount != a.paid) | .
125
      qq|ORDER BY ct.name|;
126
    $form->{"all_$form->{vc}"} = selectall_hashref_query($form, $dbh, $query);
127
  }
128

  
129
  $main::lxdebug->leave_sub();
130
}
131

  
132 104
sub get_openinvoices {
133 105
  $main::lxdebug->enter_sub();
134 106

  
......
360 332
}
361 333

  
362 334
1;
363

  
bin/mozilla/cp.pl
60 60
  $form->{ARAP} = ($form->{type} eq 'receipt') ? "AR" : "AP";
61 61
  $form->{arap} = lc $form->{ARAP};
62 62

  
63
  # setup customer/vendor selection for open invoices
64
  if ($form->{all_vc}) {
65
    # Dieser Zweig funktioniert derzeit NIE. Ggf. ganz raus oder
66
    # alle offenen Zahlungen wieder korrekt anzeigen. jb 12.10.2010
67
    $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
68
  } else {
69
    CP->get_openvc(\%myconfig, \%$form);
70
  }
71
  # Auswahlliste für vc zusammenbauen
72
  # Erweiterung für schliessende option und erweiterung um value
73
  # für bugfix 1771 (doppelte Leerzeichen werden nicht 'gepostet')
74
  $form->{"select$form->{vc}"} = "";
75

  
76
  if ($form->{"all_$form->{vc}"}) {
77
    $form->{"select$form->{vc}"} .= "<option value=\"\"></option>\n";
78
    # s.o. jb 12.10.2010
79
    $form->{"$form->{vc}_id"} = $form->{"all_$form->{vc}"}->[0]->{id};
80
    # hotfix for 2450. TODO remove legacy code and use L
81
    map { $form->{"select$form->{vc}"} .= "<option value=\"" . H($_->{name}) . "--$_->{id}\">" . H($_->{name}) . "--$_->{id}</option>\n" }
82
      @{ $form->{"all_$form->{vc}"} };
83
  }
84 63
  CP->paymentaccounts(\%myconfig, \%$form);
85 64

  
86 65
  # Standard Konto für Umlaufvermögen
......
124 103

  
125 104
  $auth->assert('cash');
126 105

  
127
  my ($vc, $arap, $exchangerate);
106
  $::request->layout->add_javascripts("autocomplete_customer.js");
107

  
108
  my ($arap, $exchangerate);
128 109

  
129
  if ($form->{ $form->{vc} } eq "") {
110
  if (!$form->{ $form->{vc} . '_id' }) {
130 111
    map { $form->{"addr$_"} = "" } (1 .. 4);
131 112
  }
132 113

  
133
  # sometimes it happens that values in customer arrive without the signs '--'
134
  # but in order to select the right option field we need values with '--'
135
  if ($form->{vc} eq "customer" && $form->{"all_$form->{vc}"}){
136
    my ($customername) = split /--/, $form->{ $form->{vc} };
137
    $form->{ $form->{vc} } = $customername . "--" . $form->{customer_id};
138
  }
139 114
  # bugfix 1771
140 115
  # geändert von <option>asdf--2929
141 116
  # nach:
142 117
  #              <option value="asdf--2929">asdf--2929</option>
143 118
  # offen: $form->{ARAP} kann raus?
144
  for my $item ($form->{vc}, "account", "currency", $form->{ARAP}) {
119
  for my $item ("account", "currency", $form->{ARAP}) {
145 120
    $form->{$item} = H($form->{$item});
146 121
    $form->{"select$item"} =~ s/ selected//;
147 122
    $form->{"select$item"} =~ s/option value="\Q$form->{$item}\E">\Q$form->{$item}\E/option selected value="$form->{$item}">$form->{$item}/;
148 123
  }
149 124

  
150
  $vc =
151
    ($form->{"select$form->{vc}"})
152
    ? qq|<select name=$form->{vc}>$form->{"select$form->{vc}"}\n</select>|
153
    : qq|<input name=$form->{vc} size=35 value="$form->{$form->{vc}}">|;
154

  
155
  $form->{openinvoices} = $form->{all_vc} ? "" : 1;
125
  $form->{openinvoices} = 1;
156 126

  
157 127
  # $locale->text('AR')
158 128
  # $locale->text('AP')
......
165 135
    is_customer => $form->{vc}   eq 'customer',
166 136
    is_receipt  => $form->{type} eq 'receipt',
167 137
    arap        => $arap,
168
    vccontent   => $vc,
169 138
  });
170 139

  
171 140
  $lxdebug->leave_sub;
......
204 173

  
205 174
  $auth->assert('cash');
206 175

  
207
  my ($new_name_selected) = @_;
208

  
209
  my ($buysell, $newvc, $updated, $exchangerate, $amount);
176
  my ($buysell, $updated, $exchangerate, $amount);
210 177

  
211 178
  if ($form->{vc} eq 'customer') {
212 179
    $buysell = "buy";
......
214 181
    $buysell = "sell";
215 182
  }
216 183

  
217
  # if we switched to all_vc
218
  # funktioniert derzeit nicht 12.10.2010 jb
219
  if ($form->{all_vc} ne $form->{oldall_vc}) {
220

  
221
    $form->{openinvoices} = ($form->{all_vc}) ? 0 : 1;
222

  
223
    $form->{"select$form->{vc}"} = "";
224

  
225
    if ($form->{all_vc}) {
226
      $form->all_vc(\%myconfig, $form->{vc}, $form->{ARAP});
227

  
228
      if ($form->{"all_$form->{vc}"}) {
229
        map {
230
          $form->{"select$form->{vc}"} .=
231
            "<option>$_->{name}--$_->{id}\n"
232
        } @{ $form->{"all_$form->{vc}"} };
233
      }
234
    } else {  # ab hier wieder ausgeführter code (s.o.):
235
      CP->get_openvc(\%myconfig, \%$form);
236

  
237
      if ($form->{"all_$form->{vc}"}) {
238
        $newvc =
239
          qq|$form->{"all_$form->{vc}"}[0]->{name}--$form->{"all_$form->{vc}"}[0]->{id}|;
240
        map {
241
          $form->{"select$form->{vc}"} .=
242
            "<option>$_->{name}--$_->{id}\n"
243
        } @{ $form->{"all_$form->{vc}"} };
244
      }
245

  
246
      # if the name is not the same
247
      if ($form->{"select$form->{vc}"} !~ /$form->{$form->{vc}}/) {
248
        $form->{ $form->{vc} } = $newvc;
249
      }
250
    }
251
  }
252

  
253
  # search by customernumber
254
  # the customernumber has to be correct otherwise nothing is found
255
  if ($form->{vc} eq 'customer' and $form->{customernumber} and $form->{ARAP} eq 'AR') {
256
    $form->{open} ='Y'; # only open invoices
257
    # ar_transactions automatically searches by $form->{customer_id} or else
258
    # $form->{customer} if available, and these variables will always be set
259
    # so we have to empty these values first
260
    $form->{customer_id} = '';
261
    $form->{customer} = '';
262
    AR->ar_transactions(\%myconfig, \%$form);
263

  
264
    # Here we just take the first returned value even if the custumernumber
265
    # may not be unique
266
    $form->{customer} = $form->{AR}[0]{name};
267
    $form->{customer_id} = $form->{AR}[0]{customer_id};
268
  }
269

  
270 184
  # search by invoicenumber,
271 185
  if ($form->{invnumber}) {
272 186
    $form->{open} ='Y'; # only open invoices
......
289 203
      foreach my $i ( @{ $form->{AR} } ) {
290 204
        next unless $i->{invnumber} eq $form->{invnumber};
291 205
        # found exactly matching invnumber
292
        $form->{$form->{vc}} = $i->{name};
293 206
        $form->{customer_id} = $i->{customer_id};
294
        #$form->{"old${form->{vc}"} = $i->{customer_id};
295 207
        $found_exact_invnumber_match = 1;
296 208
      };
297 209

  
298 210
      unless ( $found_exact_invnumber_match ) {
299 211
        # use first returned entry, may not be the correct one if invnumber doesn't
300 212
        # match uniquely
301
        $form->{$form->{vc}} = $form->{AR}[0]{name};
302 213
        $form->{customer_id} = $form->{AR}[0]{customer_id};
303 214
      };
304 215
    } else {
305 216
      # s.o. nur für zahlungsausgang
306 217
      AP->ap_transactions(\%myconfig, \%$form);
307
      $form->{$form->{vc}} = $form->{AP}[0]{name};
218
      $form->{vendor_id} = $form->{AP}[0]{vendor_id};
308 219
    }
309 220
  }
310 221

  
311 222
  # determine customer/vendor
312
  if ( $form->{customer_id} and ($form->{invnumber} or $form->{customernumber}) ) {
313
    # we already know the exact customer_id, so fill $form with customer data
223
  my $vc = $form->{vc};
224
  if (($form->{"previous_${vc}_id"} || $form->{"${vc}_id"}) != $form->{"${vc}_id"}) {
314 225
    IS->get_customer(\%myconfig, \%$form);
315
    $updated = 1;
316
  } else {
317
    # check_name is called with "customer" or "vendor" and otherwise uses contents of $form
318
    # check_name also runs get_customer/get_vendor
319
    $updated = &check_name($form->{vc});
320
  };
321

  
322
  if ($new_name_selected || $updated) {
323
    # get open invoices from ar/ap using $form->{vc} and a.${vc}_id, i.e. customer_id
324
    CP->get_openinvoices(\%myconfig, \%$form);
325
    ($newvc) = split /--/, $form->{ $form->{vc} };
326
    $form->{"old$form->{vc}"} = qq|$newvc--$form->{"$form->{vc}_id"}|;
327
    $updated = 1;
328 226
  }
329 227

  
330
  if ($form->{currency} ne $form->{oldcurrency}) {
331
    $form->{oldcurrency} = $form->{currency};
332
    if (!$updated) {
333
      CP->get_openinvoices(\%myconfig, \%$form);
334
      $updated = 1;
335
    }
336
  }
228
  $form->{oldcurrency} = $form->{currency};
229

  
230
  # get open invoices from ar/ap using a.${vc}_id, i.e. customer_id
231
  CP->get_openinvoices(\%myconfig, \%$form) if $form->{"${vc}_id"};
337 232

  
338 233
  if (!$form->{forex}) {        # read exchangerate from input field (not hidden)
339 234
    $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
......
343 238

  
344 239
  $amount = $form->{amount} = $form->parse_amount(\%myconfig, $form->{amount});
345 240

  
346
  if ($updated) {
241
  if ($form->{"${vc}_id"}) {
347 242
    $form->{rowcount} = 0;
348 243

  
349 244
    $form->{queued} = "";
......
408 303
  $form->{amount}=$amount;
409 304

  
410 305
  &form_header;
411
  &list_invoices;
306
  list_invoices() if $form->{"${vc}_id"};
412 307
  &form_footer;
413 308

  
414 309
  $lxdebug->leave_sub();
......
449 344

  
450 345
  my ($closedto, $datepaid, $amount);
451 346

  
452
  &check_name($form->{vc});
347
  my $vc = $form->{vc};
348
  if (($form->{"previous_${vc}_id"} || $form->{"${vc}_id"}) != $form->{"${vc}_id"}) {
349
    IS->get_customer(\%myconfig, $form) if $vc eq 'customer';
350
    IR->get_vendor(\%myconfig, $form)   if $vc eq 'vendor';
351
  }
453 352

  
454 353
  if ($form->{currency} ne $form->{oldcurrency}) {
455 354
    &update;
templates/webpages/cp/form_header.html
1 1
[%- USE L %]
2 2
[%- USE HTML %]
3 3
[%- USE T8 %]
4
[%- USE LxERP %]
4
[%- USE LxERP %][%- USE P -%]
5 5
<form method=post action=cp.pl>
6 6

  
7
[% SET vc_id = vc _ '_id'
8
       style = "width: 250px" %]
7 9
[% L.hidden_tag('defaultcurrency', defaultcurrency) %]
8 10
[% L.hidden_tag('closedto', closedto) %]
9 11
[% L.hidden_tag('vc', vc) %]
......
16 18

  
17 19
<h1>[% is_receipt ? LxERP.t8('Receipt') : LxERP.t8('Payment') %]</h1>
18 20

  
19
<table width=100%>
21
<table>
20 22
  <tr valign=top>
21 23
    <td>
22 24
      <table>
23 25
        <tr>
24 26
          <th align=right>[% is_customer ? LxERP.t8('Customer') : LxERP.t8('Vendor') %]</th>
25
          <td>[% vccontent %]</td>
26
         [% IF vc == 'customer' %]
27
           [% L.hidden_tag('selectcustomer', selectcustomer) %]
28
           [% L.hidden_tag('customer_id', customer_id) %]
29
           [% L.hidden_tag('oldcustomer', oldcustomer) %]
30
          [% ELSE %]
31
           [% L.hidden_tag('selectvendor', selectvendor) %]
32
           [% L.hidden_tag('vendor_id', vendor_id) %]
33
           [% L.hidden_tag('oldvendor', oldvendor) %]
34
          [% END %]
35
        </tr>
36
        [% IF vc == 'customer' %]
37
        <tr>
38
          <th align=right>[% 'Customer Number' | $T8 %]</th>
39
          <td><input name="customernumber" size="35"></td>
27
          <td>
28
           [% P.customer_vendor_picker(vc_id, $vc_id, type=vc, class="initial_focus", style=style) %]
29
           [% P.hidden_tag("previous_" _ vc_id, $vc_id) %]
30
          </td>
40 31
        </tr>
41
        [% END %]
42 32
        <tr>
43 33
          <th align=right>[% 'Invoice Number' | $T8 %]</th>
44 34
          <td><input name="invnumber" size="35"></td>

Auch abrufbar als: Unified diff