Subversion Repositories sql-ledger-old

Rev

Rev 114 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 finnarne 1
#=====================================================================
2
# SQL-Ledger, Accounting
3
# Copyright (c) 1998-2002
4
#
5
#  Author: Dieter Simader
6
#   Email: dsimader@sql-ledger.org
7
#     Web: http://www.sql-ledger.org
8
#
9
#
10
# This program is free software; you can redistribute it and/or modify
11
# it under the terms of the GNU General Public License as published by
12
# the Free Software Foundation; either version 2 of the License, or
13
# (at your option) any later version.
14
#
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License
20
# along with this program; if not, write to the Free Software
21
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
#======================================================================
23
#
24
# Inventory received module
25
#
26
#======================================================================
27
 
28
 
29
use SL::IR;
30
use SL::PE;
31
 
32
require "$form->{path}/io.pl";
33
require "$form->{path}/arap.pl";
34
 
35
1;
36
# end of main
37
 
38
 
39
 
40
sub add {
41
 
114 finnarne 42
  $form->{title} = $locale->text('Add Vendor Invoice');
2 finnarne 43
 
44
  &invoice_links;
45
  &prepare_invoice;
46
  &display_form;
47
 
48
}
49
 
50
 
51
sub edit {
52
 
114 finnarne 53
  $form->{title} = $locale->text('Edit Vendor Invoice');
2 finnarne 54
 
55
  &invoice_links;
56
  &prepare_invoice;
57
  &display_form;
58
 
59
}
60
 
61
 
62
sub invoice_links {
63
 
64
  # create links
65
  $form->create_links("AP", \%myconfig, "vendor");
66
 
67
  IR->get_vendor(\%myconfig, \%$form);
68
  IR->retrieve_invoice(\%myconfig, \%$form);
69
 
114 finnarne 70
  $form->get_partsgroup(\%myconfig);
71
  if (@ { $form->{all_partsgroup} }) {
72
    $form->{selectpartsgroup} = "<option>\n";
73
    map { $form->{selectpartsgroup} .= "<option>$_->{partsgroup}\n" } @{ $form->{all_partsgroup} };
74
  }
75
 
76
  if (@{ $form->{all_project} }) {
77
    $form->{selectprojectnumber} = "<option>\n";
78
    map { $form->{selectprojectnumber} .= "<option>$_->{projectnumber}\n" } @{ $form->{all_project} };
79
  }
80
 
81
 
2 finnarne 82
  # currencies
83
  @curr = split /:/, $form->{currencies};
84
  chomp $curr[0];
85
  $form->{defaultcurrency} = $curr[0];
86
 
87
  map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
88
 
89
  $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
114 finnarne 90
  $form->{oldinvdate} = $form->{invdate};
2 finnarne 91
 
92
  # vendors
93
  if (@{ $form->{all_vendor} }) {
94
    $form->{vendor} = "$form->{vendor}--$form->{vendor_id}";
95
    map { $form->{selectvendor} .= "<option>$_->{name}--$_->{id}\n" } (@{ $form->{all_vendor} });
96
  }
97
 
98
 
99
  # forex
100
  $form->{forex} = $form->{exchangerate};
101
  $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
102
 
103
  foreach $key (keys %{ $form->{AP_links} }) {
104
 
105
    foreach $ref (@{ $form->{AP_links}{$key} }) {
106
      $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
107
    }
108
 
109
    if ($key eq "AP_paid") {
110
      for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
111
        $form->{"AP_paid_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
112
        # reverse paid
113
        $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{amount};
114
        $form->{"datepaid_$i"} = $form->{acc_trans}{$key}->[$i-1]->{transdate};
115
        $form->{"forex_$i"} = $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i-1]->{exchangerate};
116
        $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i-1]->{source};
117
        $form->{paidaccounts} = $i;
118
      }
119
    } else {
120
      $form->{$key} = "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
121
    }
122
  }
123
 
124
  $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
125
 
19 finnarne 126
  $form->{AP} = $form->{AP_1} unless $form->{id};
127
 
114 finnarne 128
  $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum($form->{invdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig));
2 finnarne 129
 
114 finnarne 130
  $form->{readonly} = 1 if $myconfig{acs} =~ /AP--Vendor Invoice/;
131
 
2 finnarne 132
}
133
 
134
 
135
 
136
sub prepare_invoice {
137
 
138
  if ($form->{id}) {
139
 
140
    map { $form->{$_} =~ s/"/&quot;/g } qw(invnumber ordnumber);
141
 
142
    foreach $ref (@{ $form->{invoice_details} }) {
143
      $i++;
144
      map { $form->{"${_}_$i"} = $ref->{$_} } keys %{ $ref };
145
 
146
      ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
147
      $dec = length $dec;
148
      $decimalplaces = ($dec > 2) ? $dec : 2;
149
 
150
      $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
151
      $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
152
 
153
      $form->{rowcount} = $i;
154
    }
155
  }
156
 
157
}
158
 
159
 
160
 
161
sub form_header {
162
 
163
  # set option selected
164
  foreach $item (qw(AP vendor currency)) {
165
    $form->{"select$item"} =~ s/ selected//;
166
    $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
167
  }
168
 
169
  $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
170
 
171
  $exchangerate = "";
172
  if ($form->{currency} ne $form->{defaultcurrency}) {
173
    if ($form->{forex}) {
174
      $exchangerate .= qq|
114 finnarne 175
      <th align=right nowrap>|.$locale->text('Exchange Rate').qq|</th>
2 finnarne 176
      <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>
177
|;
178
    } else {
179
      $exchangerate .= qq|
114 finnarne 180
      <th align=right nowrap>|.$locale->text('Exchange Rate').qq|</th>
2 finnarne 181
      <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>
182
|;
183
    }
184
  }
185
  $exchangerate .= qq|
186
<input type=hidden name=forex value=$form->{forex}>
187
|;
188
 
189
  $vendor = ($form->{selectvendor}) ? qq|<select name=vendor>$form->{selectvendor}</select>\n<input type=hidden name="selectvendor" value="$form->{selectvendor}">| : qq|<input name=vendor value="$form->{vendor}" size=35>|;
190
 
191
 
192
  $form->header;
193
 
194
  print qq|
195
<body>
196
 
197
<form method=post action=$form->{script}>
198
 
199
<input type=hidden name=id value=$form->{id}>
200
<input type=hidden name=title value="$form->{title}">
201
<input type=hidden name=vc value="vendor">
202
 
114 finnarne 203
<input type=hidden name=terms value=$form->{terms}>
204
 
2 finnarne 205
<input type=hidden name=closedto value=$form->{closedto}>
206
<input type=hidden name=locked value=$form->{locked}>
207
 
114 finnarne 208
<input type=hidden name=oldinvdate value=$form->{oldinvdate}>
2 finnarne 209
 
114 finnarne 210
<input type=hidden name=selectpartsgroup value="$form->{selectpartsgroup}">
211
<input type=hidden name=selectprojectnumber value="$form->{selectprojectnumber}">
212
 
2 finnarne 213
<table width=100%>
214
  <tr class=listtop>
215
    <th>$form->{title}</th>
216
  </tr>
217
  <tr height="5"></tr>
218
  <tr>
219
    <td>
220
      <table width=100%>
114 finnarne 221
        <tr valign=top>
222
          <td>
223
            <table>
224
              <tr>
225
                <th align=right>|.$locale->text('Record in').qq|</th>
226
                <td colspan=3><select name=AP>$form->{selectAP}</select></td>
227
                <input type=hidden name=selectAP value="$form->{selectAP}">
228
              </tr>
229
              <tr>
230
                <th align=right nowrap>|.$locale->text('Vendor').qq|</th>
231
                <td colspan=3>$vendor</td>
232
 
233
                <input type=hidden name=vendor_id value=$form->{vendor_id}>
234
                <input type=hidden name=oldvendor value="$form->{oldvendor}">
2 finnarne 235
 
114 finnarne 236
              </tr>
237
              <tr>
238
                <th align=right nowrap>|.$locale->text('Currency').qq|</th>
239
                <td><select name=currency>$form->{selectcurrency}</select></td>
240
                $exchangerate
241
              </tr>
242
            </table>
243
          </td>
244
          <td align=right>
245
            <table>
246
              <tr>
247
                <th align=right nowrap>|.$locale->text('Invoice Number').qq|</th>
248
                <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
249
              </tr>
250
              <tr>
251
                <th align=right nowrap>|.$locale->text('Invoice Date').qq|</th>
252
                <td><input name=invdate size=11 title="$myconfig{dateformat}" value=$form->{invdate}></td>
253
              </tr>
254
              <tr>
255
                <th align=right nowrap>|.$locale->text('Due Date').qq|</th>
256
                <td><input name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
257
              </tr>
258
              <tr>
259
                <th align=right nowrap>|.$locale->text('Order Number').qq|</th>
260
                <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
261
              </tr>
262
            </table>
263
          </td>
2 finnarne 264
        </tr>
265
      </table>
266
    </td>
267
  </tr>
268
<input type=hidden name=selectcurrency value="$form->{selectcurrency}">
269
<input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
270
<input type=hidden name=fxgain_accno value=$form->{fxgain_accno}>
271
<input type=hidden name=fxloss_accno value=$form->{fxloss_accno}>
272
 
273
<input type=hidden name=taxpart value="$form->{taxpart}">
274
<input type=hidden name=taxservice value="$form->{taxservice}">
275
 
276
<input type=hidden name=taxaccounts value="$form->{taxaccounts}">
277
|;
278
 
279
  foreach $item (split / /, $form->{taxaccounts}) {
280
    print qq|
281
<input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
282
<input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
283
|;
284
  }
285
 
286
}
287
 
288
 
289
 
290
sub form_footer {
291
 
292
  $form->{invtotal} = $form->{invsubtotal};
293
 
294
  if (($rows = $form->numtextrows($form->{notes}, 50, 8)) < 2) {
295
    $rows = 2;
296
  }
297
  $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
298
 
114 finnarne 299
 
300
  $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
301
  if ($form->{taxaccounts}) {
302
    $taxincluded = qq|
303
                <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|.$locale->text('Tax Included').qq|</b><br><br>
304
|;
305
  }
306
 
2 finnarne 307
  if (!$form->{taxincluded}) {
308
 
309
    foreach $item (split / /, $form->{taxaccounts}) {
310
      if ($form->{"${item}_base"}) {
311
        $form->{invtotal} += $form->{"${item}_total"} = $form->round_amount($form->{"${item}_base"} * $form->{"${item}_rate"}, 2);
312
        $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
313
 
314
        $tax .= qq|
315
                <tr>
316
                  <th align=right>$form->{"${item}_description"}</th>
317
                  <td align=right>$form->{"${item}_total"}</td>
318
                </tr>
319
|;
320
      }
321
    }
322
 
323
    $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
324
 
325
    $subtotal = qq|
326
              <tr>
327
                <th align=right>|.$locale->text('Subtotal').qq|</th>
328
                <td align=right>$form->{invsubtotal}</td>
329
              </tr>
330
|;
331
 
332
  }
333
 
334
 
335
  $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
336
 
337
  print qq|
338
  <tr>
114 finnarne 339
    <td>
340
      <table width=100%>
2 finnarne 341
        <tr valign=bottom>
342
          <td>
343
            <table>
344
              <tr>
345
                <th align=left>|.$locale->text('Notes').qq|</th>
346
              </tr>
347
              <tr>
348
                <td>$notes</td>
349
              </tr>
350
            </table>
351
          </td>
114 finnarne 352
          <td align=right>
353
            $taxincluded
354
            <table>
2 finnarne 355
              $subtotal
356
              $tax
357
              <tr>
358
                <th align=right>|.$locale->text('Total').qq|</th>
359
                <td align=right>$form->{invtotal}</td>
360
              </tr>
361
            </table>
362
          </td>
363
        </tr>
364
      </table>
365
    </td>
366
  </tr>
367
  <tr>
368
    <td colspan=$colspan>
369
      <table width=100%>
370
        <tr>
371
          <th colspan=5 class=listheading>|.$locale->text('Payments').qq|</th>
372
        </tr>
373
|;
374
 
114 finnarne 375
    if ($form->{currency} eq $form->{defaultcurrency}) {
376
      @column_index = qw(datepaid source paid AP_paid);
377
    } else {
378
      @column_index = qw(datepaid source paid exchangerate AP_paid);
379
    }
380
 
2 finnarne 381
    $column_data{datepaid} = "<th>".$locale->text('Date')."</th>";
382
    $column_data{paid} = "<th>".$locale->text('Amount')."</th>";
383
    $column_data{exchangerate} = "<th>".$locale->text('Exch')."</th>";
384
    $column_data{AP_paid} = "<th>".$locale->text('Account')."</th>";
385
    $column_data{source} = "<th>".$locale->text('Source')."</th>";
386
 
387
    print qq|
388
        <tr>
389
|;
390
    map { print "$column_data{$_}\n" } @column_index;
391
    print qq|
392
        </tr>
393
|;
394
 
395
    $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
396
    for $i (1 .. $form->{paidaccounts}) {
397
 
398
      print qq|
399
        <tr>
400
|;
401
 
402
      $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
403
      $form->{"selectAP_paid_$i"} =~ s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
404
 
405
      # format amounts
406
      $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
407
      $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
408
 
409
      $exchangerate = qq|&nbsp;|;
410
      if ($form->{currency} ne $form->{defaultcurrency}) {
411
        if ($form->{"forex_$i"}) {
412
          $exchangerate = qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
413
        } else {
414
          $exchangerate = qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
415
        }
416
      }
417
      $exchangerate .= qq|
418
<input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
419
|;
420
 
421
      $column_data{"paid_$i"} = qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
422
      $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
423
      $column_data{"AP_paid_$i"} = qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
424
      $column_data{"datepaid_$i"} = qq|<td align=center><input name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;
114 finnarne 425
      $column_data{"source_$i"} = qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
2 finnarne 426
 
427
      map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
428
 
429
      print qq|
430
        </tr>
431
|;
432
    }
433
 
434
    print qq|
435
            <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
436
            <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
437
      </table>
438
    </td>
439
  </tr>
440
  <tr>
441
    <td><hr size=3 noshade></td>
442
  </tr>
443
</table>
444
<br>
445
|;
446
 
447
  $invdate = $form->datetonum($form->{invdate}, \%myconfig);
448
  $closedto = $form->datetonum($form->{closedto}, \%myconfig);
449
 
114 finnarne 450
  if (! $form->{readonly}) {
451
    if ($form->{id}) {
452
      print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
453
  |;
2 finnarne 454
 
455
      if (!$form->{locked}) {
456
        print qq|
457
        <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">
458
        <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">
114 finnarne 459
  |;
2 finnarne 460
      }
461
 
462
      print qq|
114 finnarne 463
        <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">
464
        <input class=submit type=submit name=action value="|.$locale->text('Order').qq|">
465
  |;
2 finnarne 466
 
114 finnarne 467
    } else {
468
      if ($invdate > $closedto) {
469
        print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
470
        <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|;
471
      }
2 finnarne 472
    }
473
  }
474
 
475
print qq|
476
 
477
<input type=hidden name=rowcount value=$form->{rowcount}>
478
 
479
<input name=callback type=hidden value="$form->{callback}">
480
 
481
<input type=hidden name=path value=$form->{path}>
482
<input type=hidden name=login value=$form->{login}>
483
<input type=hidden name=password value=$form->{password}>
484
 
485
</form>
486
 
487
</body>
488
</html>
489
|;
490
 
491
}
492
 
493
 
494
 
495
sub update {
496
 
497
  $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
498
 
499
  &check_name(vendor);
500
 
114 finnarne 501
  if ($form->{invdate} ne $form->{oldinvdate}) {
502
    $form->{duedate} = $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1);
503
    $form->{oldinvdate} = $form->{invdate};
504
  }
2 finnarne 505
 
114 finnarne 506
 
2 finnarne 507
  $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell')));
508
 
509
 
510
  for $i (1 .. $form->{paidaccounts}) {
511
    if ($form->{"paid_$i"}) {
512
      map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
513
 
514
      $form->{"exchangerate_$i"} = $exchangerate if ($form->{"forex_$i"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell')));
515
    }
516
  }
517
 
518
  $i = $form->{rowcount};
519
  $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
520
 
114 finnarne 521
  if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) {
2 finnarne 522
 
523
    &check_form;
524
 
525
  } else {
526
 
527
    IR->retrieve_item(\%myconfig, \%$form);
528
 
529
    my $rows = scalar @{ $form->{item_list} };
530
 
531
    if ($rows) {
532
      $form->{"qty_$i"}                     = 1 unless ($form->{"qty_$i"});
533
 
534
      if ($rows > 1) {
535
 
536
        &select_item;
537
        exit;
538
 
539
      } else {
540
        # override sellprice if there is one entered
541
        $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
542
 
543
        map { $form->{item_list}[$i]{$_} =~ s/"/&quot;/g } qw(partnumber description unit);
544
 
545
        map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
546
 
547
        $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"};
548
 
549
        ($dec) = ($s =~ /\.(\d+)/);
550
        $dec = length $dec;
551
        $decimalplaces = ($dec > 2) ? $dec : 2;
552
 
553
        if ($sellprice) {
554
          $form->{"sellprice_$i"} = $sellprice;
555
        } else {
556
          # if there is an exchange rate adjust sellprice
557
          $form->{"sellprice_$i"} /= $exchangerate;
558
        }
559
 
560
        $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
561
        $form->{"qty_$i"} =  $form->format_amount(\%myconfig, $form->{"qty_$i"});
562
      }
563
 
564
      &display_form;
565
 
566
    } else {
567
      # ok, so this is a new part
568
      # ask if it is a part or service item
569
 
114 finnarne 570
      if ($form->{"partsgroup_$i"} && ($form->{"partsnumber_$i"} eq "") && ($form->{"description_$i"} eq "")) {
571
        $form->{rowcount}--;
572
        $form->{"discount_$i"} = "";
573
        &display_form;
574
      } else {
575
 
576
        $form->{"id_$i"}                = 0;
577
        $form->{"unit_$i"}      = $locale->text('ea');
2 finnarne 578
 
114 finnarne 579
        &new_item;
580
 
581
      }
2 finnarne 582
    }
583
  }
584
}
585
 
586
 
587
 
588
sub post {
589
 
590
  $form->isblank("invnumber", $locale->text('Invoice Number missing!'));
591
  $form->isblank("invdate", $locale->text('Invoice Date missing!'));
592
  $form->isblank("vendor", $locale->text('Vendor missing!'));
593
 
594
  # if the vendor changed get new values
595
  if (&check_name(vendor)) {
596
    &update;
597
    exit;
598
  }
599
 
600
  &validate_items;
601
 
602
  $closedto = $form->datetonum($form->{closedto}, \%myconfig);
603
  $invdate = $form->datetonum($form->{invdate}, \%myconfig);
604
 
605
  $form->error($locale->text('Cannot post invoice for a closed period!')) if ($invdate <= $closedto);
606
 
114 finnarne 607
  $form->isblank("exchangerate", $locale->text('Exchange rate missing!')) if ($form->{currency} ne $form->{defaultcurrency});
2 finnarne 608
 
609
  for $i (1 .. $form->{paidaccounts}) {
610
    if ($form->{"paid_$i"}) {
611
      $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
612
 
613
      $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
614
 
615
      $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);
616
 
617
      if ($form->{currency} ne $form->{defaultcurrency}) {
618
        $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid);
114 finnarne 619
        $form->isblank("exchangerate_$i", $locale->text('Exchange rate for payment missing!'));
2 finnarne 620
      }
621
    }
622
  }
623
 
624
 
625
  ($form->{AP}) = split /--/, $form->{AP};
626
  ($form->{AP_paid}) = split /--/, $form->{AP_paid};
627
 
628
  $form->{id} = 0 if $form->{postasnew};
629
 
630
  $form->redirect($locale->text('Invoice posted!')) if (IR->post_invoice(\%myconfig, \%$form));
631
  $form->error($locale->text('Cannot post invoice!'));
632
 
633
}
634
 
635
 
636
 
637
sub delete {
638
 
639
  $form->header;
640
 
641
  print qq|
642
<body>
643
 
644
<form method=post action=$form->{script}>
645
|;
646
 
647
  # delete action variable
648
  delete $form->{action};
649
 
650
  foreach $key (keys %$form) {
651
    $form->{$key} =~ s/"/&quot;/g;
652
    print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
653
  }
654
 
655
  print qq|
656
<h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
657
 
658
<h4>|.$locale->text('Are you sure you want to delete Invoice Number').qq| $form->{invnumber}</h4>
659
<p>
660
<input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
661
</form>
662
|;
663
 
664
 
665
}
666
 
667
 
668
 
669
sub yes {
670
 
671
  $form->redirect($locale->text('Invoice deleted!')) if (IR->delete_invoice(\%myconfig, \%$form));
672
  $form->error($locale->text('Cannot delete invoice!'));
673
 
674
}
675
 
676