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
# Genereal Ledger
25
#
26
#======================================================================
27
 
28
 
29
use SL::GL;
30
use SL::PE;
31
 
32
require "$form->{path}/arap.pl";
33
 
34
1;
35
# end of main
36
 
37
 
38
# this is for our long dates
39
# $locale->text('January')
40
# $locale->text('February')
41
# $locale->text('March')
42
# $locale->text('April')
43
# $locale->text('May ')
44
# $locale->text('June')
45
# $locale->text('July')
46
# $locale->text('August')
47
# $locale->text('September')
48
# $locale->text('October')
49
# $locale->text('November')
50
# $locale->text('December')
51
 
52
# this is for our short month
53
# $locale->text('Jan')
54
# $locale->text('Feb')
55
# $locale->text('Mar')
56
# $locale->text('Apr')
57
# $locale->text('May')
58
# $locale->text('Jun')
59
# $locale->text('Jul')
60
# $locale->text('Aug')
61
# $locale->text('Sep')
62
# $locale->text('Oct')
63
# $locale->text('Nov')
64
# $locale->text('Dec')
65
 
66
 
67
sub add {
68
 
69
  $form->{title} = "Add";
70
 
114 finnarne 71
  $form->{callback} = "$form->{script}?action=add&transfer=$form->{transfer}&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback};
2 finnarne 72
 
73
  # we use this only to set a default date
74
  GL->transaction(\%myconfig, \%$form);
75
 
114 finnarne 76
  map { $form->{selectaccno} .= "<option>$_->{accno}--$_->{description}" } @{ $form->{all_accno} };
77
 
78
  if ($form->{all_project}) {
79
    $form->{selectprojectnumber} = "<option>\n";
80
    map { $form->{selectprojectnumber} .= "<option>$_->{projectnumber}\n" } @{ $form->{all_project} };
81
  }
82
 
83
 
84
  $form->{rowcount} = ($form->{transfer}) ? 2 : 4;
2 finnarne 85
 
86
  &display_form;
87
 
88
}
89
 
90
 
91
sub edit {
92
 
93
  GL->transaction(\%myconfig, \%$form);
94
 
114 finnarne 95
  map { $form->{selectaccno} .= "<option>$_->{accno}--$_->{description}" } @{ $form->{all_accno} };
2 finnarne 96
 
114 finnarne 97
  if ($form->{all_project}) {
98
    $form->{selectprojectnumber} = "<option>\n";
99
    map { $form->{selectprojectnumber} .= "<option>$_->{projectnumber}\n" } @{ $form->{all_project} };
100
  }
2 finnarne 101
 
114 finnarne 102
 
103
  $form->{locked} = ($form->{revtrans}) ? '1' : ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig));
104
 
105
  # readonly
106
  $form->{readonly} = 1 if $myconfig{acs} =~ /General Ledger--Add Transaction/;
107
 
2 finnarne 108
  $form->{title} = "Edit";
109
 
110
  &form_header;
111
 
112
  $i = 1;
113
  foreach $ref (@{ $form->{GL} }) {
114 finnarne 114
    $form->{"accno_$i"} = "$ref->{accno}--$ref->{description}";
115
 
116
    $form->{"projectnumber_$i"} = "$ref->{projectnumber}";
117
    $form->{"fx_transaction_$i"} = $ref->{fx_transaction};
2 finnarne 118
 
119
    if ($ref->{amount} < 0) {
120
      $form->{totaldebit} -= $ref->{amount};
121
      $form->{"debit_$i"} = $form->format_amount(\%myconfig, $ref->{amount} * -1, 2);
122
    } else {
123
      $form->{totalcredit} += $ref->{amount};
124
      $form->{"credit_$i"} = ($ref->{amount} > 0) ? $form->format_amount(\%myconfig, $ref->{amount}, 2) : "";
125
    }
126
 
127
    &form_row($i++);
128
  }
129
 
130
  &form_row($i);
131
 
132
  &form_footer;
133
 
134
}
135
 
136
 
137
 
138
sub search {
139
 
140
  $form->{title} = $locale->text('General Ledger')." ".$locale->text('Reports');
141
 
142
  $form->header;
143
 
144
  print qq|
145
<body>
146
 
147
<form method=post action=$form->{script}>
148
 
149
<input type=hidden name=sort value=transdate>
150
 
151
<table width=100%>
152
  <tr>
153
    <th class=listtop>$form->{title}</th>
154
  </tr>
155
  <tr height="5"></tr>
156
  <tr>
157
    <td>
158
      <table>
159
        <tr>
160
          <th align=right>|.$locale->text('Reference').qq|</th>
161
          <td><input name=reference size=20></td>
162
          <th align=right>|.$locale->text('Source').qq|</th>
163
          <td><input name=source size=20></td>
164
        </tr>
165
        <tr>
166
          <th align=right>|.$locale->text('Description').qq|</th>
167
          <td colspan=3><input name=description size=40></td>
168
        </tr>
169
        <tr>
170
          <th align=right>|.$locale->text('Notes').qq|</th>
171
          <td colspan=3><input name=notes size=40></td>
172
        </tr>
173
        <tr>
174
          <th align=right>|.$locale->text('From').qq|</th>
175
          <td><input name=datefrom size=11 title="$myconfig{dateformat}"></td>
15 finnarne 176
          <th align=right>|.$locale->text('to').qq|</th>
2 finnarne 177
          <td><input name=dateto size=11 title="$myconfig{dateformat}"></td>
178
        </tr>
179
        <tr>
114 finnarne 180
          <th align=right>|.$locale->text('Amount').qq| >=</th>
181
          <td><input name=amountfrom size=11</td>
182
          <th align=right>|.$locale->text('Amount').qq| <=</th>
183
          <td><input name=amountto size=11></td>
184
        </tr>
185
        <tr>
2 finnarne 186
          <th align=right>|.$locale->text('Include in Report').qq|</th>
187
          <td colspan=3>
188
            <table>
189
              <tr>
190
                <td>
191
                  <input name="category" class=radio type=radio value=X checked>&nbsp;|.$locale->text('All').qq|
192
                  <input name="category" class=radio type=radio value=A>&nbsp;|.$locale->text('Asset').qq|
193
                  <input name="category" class=radio type=radio value=L>&nbsp;|.$locale->text('Liability').qq|
194
                  <input name="category" class=radio type=radio value=Q>&nbsp;|.$locale->text('Equity').qq|
195
                  <input name="category" class=radio type=radio value=I>&nbsp;|.$locale->text('Income').qq|
196
                  <input name="category" class=radio type=radio value=E>&nbsp;|.$locale->text('Expense').qq|
197
                </td>
198
              </tr>
199
              <tr>
200
                <table>
201
                  <tr>
202
                    <td align=right><input name="l_id" class=checkbox type=checkbox value=Y></td>
203
                    <td>|.$locale->text('ID').qq|</td>
204
                    <td align=right><input name="l_transdate" class=checkbox type=checkbox value=Y checked></td>
205
                    <td>|.$locale->text('Date').qq|</td>
206
                    <td align=right><input name="l_reference" class=checkbox type=checkbox value=Y checked></td>
207
                    <td>|.$locale->text('Reference').qq|</td>
208
                    <td align=right><input name="l_description" class=checkbox type=checkbox value=Y checked></td>
209
                    <td>|.$locale->text('Description').qq|</td>
210
                    <td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
211
                    <td>|.$locale->text('Notes').qq|</td>
212
                  </tr>
213
                  <tr>
214
                    <td align=right><input name="l_debit" class=checkbox type=checkbox value=Y checked></td>
215
                    <td>|.$locale->text('Debit').qq|</td>
216
                    <td align=right><input name="l_credit" class=checkbox type=checkbox value=Y checked></td>
217
                    <td>|.$locale->text('Credit').qq|</td>
218
                    <td align=right><input name="l_source" class=checkbox type=checkbox value=Y checked></td>
219
                    <td>|.$locale->text('Source').qq|</td>
220
                    <td align=right><input name="l_accno" class=checkbox type=checkbox value=Y checked></td>
221
                    <td>|.$locale->text('Account').qq|</td>
222
                    <td align=right><input name="l_gifi_accno" class=checkbox type=checkbox value=Y></td>
223
                    <td>|.$locale->text('GIFI').qq|</td>
224
                  </tr>
225
                  <tr>
226
                    <td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
227
                    <td>|.$locale->text('Subtotal').qq|</td>
228
                  </tr>
229
                </table>
230
              </tr>
231
            </table>
232
        </tr>
233
      </table>
234
    </td>
235
  </tr>
236
  <tr>
237
    <td><hr size=3 noshade></td>
238
  </tr>
239
</table>
240
 
241
<input type=hidden name=nextsub value=generate_report>
242
 
243
<input type=hidden name=path value=$form->{path}>
244
<input type=hidden name=login value=$form->{login}>
245
<input type=hidden name=password value=$form->{password}>
246
 
247
<br>
248
<input class=submit type=submit name=action value="|.$locale->text('Continue').qq|">
249
</form>
250
 
251
</body>
252
</html>
253
|;
254
}
255
 
256
 
257
sub generate_report {
258
 
259
  GL->all_transactions(\%myconfig, \%$form);
260
 
261
  $callback = "$form->{script}?action=generate_report&path=$form->{path}&login=$form->{login}&password=$form->{password}";
262
 
263
  %acctype = ( 'A' => $locale->text('Asset'),
264
               'L' => $locale->text('Liability'),
265
               'Q' => $locale->text('Equity'),
266
               'I' => $locale->text('Income'),
267
               'E' => $locale->text('Expense'),
268
             );
269
 
270
  $form->{title} = $locale->text('General Ledger');
271
 
272
  $ml = ($form->{ml} =~ /(A|E)/) ? -1 : 1;
273
 
274
  unless ($form->{category} eq 'X') {
275
    $form->{title} .= " : ".$locale->text($acctype{$form->{category}});
276
  }
277
  if ($form->{accno}) {
278
    $callback .= "&accno=$form->{accno}";
279
    $option = $locale->text('Account')." : $form->{accno} $form->{account_description}";
280
  }
281
  if ($form->{gifi_accno}) {
282
    $callback .= "&gifi_accno=$form->{gifi_accno}";
283
    $option .= "\n<br>" if $option;
284
    $option .= $locale->text('GIFI')." : $form->{gifi_accno} $form->{gifi_account_description}";
285
  }
286
  if ($form->{source}) {
287
    $callback .= "&source=".$form->escape($form->{source});
288
    $option .= "\n<br>" if $option;
289
    $option .= $locale->text('Source')." : $form->{source}";
290
  }
291
  if ($form->{reference}) {
292
    $callback .= "&reference=".$form->escape($form->{reference});
293
    $option .= "\n<br>" if $option;
294
    $option .= $locale->text('Reference')." : $form->{reference}";
295
  }
296
  if ($form->{description}) {
297
    $callback .= "&description=".$form->escape($form->{description});
298
    $option .= "\n<br>" if $option;
299
    $option .= $locale->text('Description')." : $form->{description}";
300
  }
301
  if ($form->{notes}) {
302
    $callback .= "&notes=".$form->escape($form->{notes});
303
    $option .= "\n<br>" if $option;
304
    $option .= $locale->text('Notes')." : $form->{notes}";
305
  }
306
 
307
  if ($form->{datefrom}) {
308
    $callback .= "&datefrom=$form->{datefrom}";
309
    $option .= "\n<br>" if $option;
310
    $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{datefrom}, 1);
311
  }
312
  if ($form->{dateto}) {
313
    $callback .= "&dateto=$form->{dateto}";
314
    if ($form->{datefrom}) {
315
      $option .= " ";
316
    } else {
317
      $option .= "\n<br>" if $option;
318
    }
15 finnarne 319
    $option .= $locale->text('to')." ".$locale->date(\%myconfig, $form->{dateto}, 1);
2 finnarne 320
  }
321
 
114 finnarne 322
  if ($form->{amountfrom}) {
323
    $href .= "&amountfrom=$form->{amountfrom}";
324
    $callback .= "&amountfrom=$form->{amountfrom}";
325
    $option .= "\n<br>" if $option;
326
    $option .= $locale->text('Amount')." >= ".$form->format_amount(\%myconfig, $form->{amountfrom}, 2);
327
  }
328
  if ($form->{amountto}) {
329
    $href .= "&amountto=$form->{amountto}";
330
    $callback .= "&amountto=$form->{amountto}";
331
    if ($form->{amountfrom}) {
332
      $option .= " <= ";
333
    } else {
334
      $option .= "\n<br>" if $option;
335
      $option .= $locale->text('Amount')." <= ";
336
    }
337
    $option .= $form->format_amount(\%myconfig, $form->{amountto}, 2);
338
  }
339
 
2 finnarne 340
  @columns = $form->sort_columns(qw(transdate id reference description notes source debit credit accno gifi_accno));
114 finnarne 341
  if ($form->{link} =~ /_paid/) {
342
    @columns = $form->sort_columns(qw(transdate id reference description notes source cleared debit credit accno gifi_accno));
343
    $form->{l_cleared} = "Y";
344
  }
2 finnarne 345
 
114 finnarne 346
 
2 finnarne 347
  if ($form->{accno} || $form->{gifi_accno}) {
348
    @columns = grep !/(accno|gifi_accno)/, @columns;
349
    push @columns, "balance";
350
    $form->{l_balance} = "Y";
351
  }
352
 
353
  $href = "$callback&sort=$form->{sort}";        # needed for accno
354
 
355
  foreach $item (@columns) {
356
    if ($form->{"l_$item"} eq "Y") {
357
      push @column_index, $item;
358
 
359
      # add column to href and callback
360
      $callback .= "&l_$item=Y";
361
      $href .= "&l_$item=Y";
362
    }
363
  }
364
 
365
  if ($form->{l_subtotal} eq 'Y') {
366
    $callback .= "&l_subtotal=Y";
367
    $href .= "&l_subtotal=Y";
368
  }
369
 
370
  $callback .= "&category=$form->{category}";
371
  $href .= "&category=$form->{category}";
372
 
373
  $column_header{id} = "<th><a class=listheading href=$callback&sort=id>".$locale->text('ID')."</a></th>";
374
  $column_header{transdate} = "<th><a class=listheading href=$callback&sort=transdate>".$locale->text('Date')."</a></th>";
375
  $column_header{reference} = "<th><a class=listheading href=$callback&sort=reference>".$locale->text('Reference')."</a></th>";
376
  $column_header{source} = "<th><a class=listheading href=$callback&sort=source>".$locale->text('Source')."</a></th>";
377
  $column_header{description} = "<th><a class=listheading href=$callback&sort=description>".$locale->text('Description')."</a></th>";
15 finnarne 378
  $column_header{notes} = "<th class=listheading>".$locale->text('Notes')."</th>";
379
  $column_header{debit} = "<th class=listheading>".$locale->text('Debit')."</th>";
380
  $column_header{credit} = "<th class=listheading>".$locale->text('Credit')."</th>";
2 finnarne 381
  $column_header{accno} = "<th><a class=listheading href=$callback&sort=accno>".$locale->text('Account')."</a></th>";
382
  $column_header{gifi_accno} = "<th><a class=listheading href=$callback&sort=gifi_accno>".$locale->text('GIFI')."</a></th>";
15 finnarne 383
  $column_header{balance} = "<th class=listheading>".$locale->text('Balance')."</th>";
114 finnarne 384
 
385
  $column_header{cleared} = qq|<th>|.$locale->text('R').qq|</th>|;
386
 
2 finnarne 387
 
388
  $form->header;
389
 
390
  print qq|
391
<body>
392
 
393
<table width=100%>
394
  <tr>
395
    <th class=listtop>$form->{title}</th>
396
  </tr>
397
  <tr height="5"></tr>
398
  <tr>
399
    <td>$option</td>
400
  </tr>
401
  <tr>
402
    <td>
403
      <table width=100%>
404
        <tr class=listheading>
405
|;
406
 
407
map { print "$column_header{$_}\n" } @column_index;
408
 
409
print "
410
        </tr>
411
";
412
 
413
  # add sort to callback
414
  $form->{callback} = "$callback&sort=$form->{sort}";
415
  $callback = $form->escape($form->{callback});
416
 
417
  # initial item for subtotals
418
  if (@{ $form->{GL} }) {
419
    $sameitem = $form->{GL}->[0]->{$form->{sort}};
420
  }
421
 
422
  if (($form->{accno} || $form->{gifi_accno}) && $form->{balance}) {
423
 
424
    map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
425
    $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
426
 
427
    $i++; $i %= 2;
428
    print qq|
429
        <tr class=listrow$i>
430
|;
431
    map { print "$column_data{$_}\n" } @column_index;
432
 
433
    print qq|
434
        </tr>
435
|;
436
  }
437
 
438
  foreach $ref (@{ $form->{GL} }) {
439
 
440
    # if item ne sort print subtotal
441
    if ($form->{l_subtotal} eq 'Y') {
442
      if ($sameitem ne $ref->{$form->{sort}}) {
443
        &gl_subtotal;
444
      }
445
    }
446
 
447
    $form->{balance} += $ref->{amount};
448
 
449
    $subtotaldebit += $ref->{debit};
450
    $subtotalcredit += $ref->{credit};
451
 
452
    $totaldebit += $ref->{debit};
453
    $totalcredit += $ref->{credit};
454
 
455
    $ref->{debit} = $form->format_amount(\%myconfig, $ref->{debit}, 2, "&nbsp;");
456
    $ref->{credit} = $form->format_amount(\%myconfig, $ref->{credit}, 2, "&nbsp;");
457
 
458
    $column_data{id} = "<td>$ref->{id}</td>";
459
    $column_data{transdate} = "<td>$ref->{transdate}</td>";
460
    $column_data{reference} = "<td><a href=$ref->{module}.pl?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ref->{reference}</td>";
461
    $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
462
    $column_data{source} = "<td>$ref->{source}&nbsp;</td>";
463
    $column_data{notes} = "<td>$ref->{notes}&nbsp;</td>";
464
    $column_data{debit} = "<td align=right>$ref->{debit}</td>";
465
    $column_data{credit} = "<td align=right>$ref->{credit}</td>";
466
    $column_data{accno} = "<td><a href=$href&accno=$ref->{accno}&callback=$callback>$ref->{accno}</a></td>";
467
    $column_data{gifi_accno} = "<td><a href=$href&gifi_accno=$ref->{gifi_accno}&callback=$callback>$ref->{gifi_accno}</a>&nbsp;</td>";
468
    $column_data{balance} = "<td align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</td>";
114 finnarne 469
 
470
    $column_data{cleared} = ($ref->{cleared}) ? "<td>*</td>" : "<td>&nbsp;</td>";
2 finnarne 471
 
472
    $i++; $i %= 2;
473
    print "
474
        <tr class=listrow$i>";
475
    map { print "$column_data{$_}\n" } @column_index;
476
    print "</tr>";
477
 
478
  }
479
 
480
 
481
  &gl_subtotal if ($form->{l_subtotal} eq 'Y');
482
 
483
 
484
  map { $column_data{$_} = "<td>&nbsp;</td>" } @column_index;
485
 
486
  $column_data{debit} = "<th align=right>".$form->format_amount(\%myconfig, $totaldebit, 2, "&nbsp;")."</th>";
487
  $column_data{credit} = "<th align=right>".$form->format_amount(\%myconfig, $totalcredit, 2, "&nbsp;")."</th>";
488
  $column_data{balance} = "<th align=right>".$form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)."</th>";
489
 
490
  print qq|
491
        <tr class=listtotal>
492
|;
493
 
494
  map { print "$column_data{$_}\n" } @column_index;
495
 
114 finnarne 496
  $i = 1;
497
  if ($myconfig{acs} !~ /General Ledger--General Ledger/) {
498
    $button{'General Ledger--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('GL Transaction').qq|"> |;
499
    $button{'General Ledger--Add Transaction'}{order} = $i++;
500
  }
501
  if ($myconfig{acs} !~ /AR--AR/) {
502
    $button{'AR--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AR Transaction').qq|"> |;
503
    $button{'AR--Add Transaction'}{order} = $i++;
504
    $button{'AR--Sales Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Sales Invoice').qq|"> |;
505
    $button{'AR--Sales Invoice'}{order} = $i++;
506
  }
507
  if ($myconfig{acs} !~ /AP--AP/) {
508
    $button{'AP--Add Transaction'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('AP Transaction').qq|"> |;
509
    $button{'AP--Add Transaction'}{order} = $i++;
510
    $button{'AP--Vendor Invoice'}{code} = qq|<input class=submit type=submit name=action value="|.$locale->text('Vendor Invoice').qq|"> |;
511
    $button{'AP--Vendor Invoice'}{order} = $i++;
512
  }
513
 
514
  foreach $item (split /;/, $myconfig{acs}) {
515
    delete $button{$item};
516
  }
517
 
2 finnarne 518
  print qq|
519
        </tr>
520
      </table>
521
    </td>
522
  </tr>
523
  <tr>
524
    <td><hr size=3 noshade></td>
525
  </tr>
526
</table>
527
 
528
<br>
529
 
530
<form method=post action=$form->{script}>
531
 
532
<input name=callback type=hidden value="$form->{callback}">
533
 
534
<input type=hidden name=path value=$form->{path}>
535
<input type=hidden name=login value=$form->{login}>
536
<input type=hidden name=password value=$form->{password}>
114 finnarne 537
|;
2 finnarne 538
 
114 finnarne 539
  foreach $item (sort { $a->{order} <=> $b->{order} } %button) {
540
    print $item->{code};
541
  }
2 finnarne 542
 
114 finnarne 543
  print qq|
2 finnarne 544
</form>
545
 
546
</body>
547
</html>
548
|;
549
 
550
}
551
 
552
 
553
sub gl_subtotal {
554
 
555
  $subtotaldebit = $form->format_amount(\%myconfig, $subtotaldebit, 2, "&nbsp;");
556
  $subtotalcredit = $form->format_amount(\%myconfig, $subtotalcredit, 2, "&nbsp;");
557
 
558
  map { $column_data{$_} = "<td>&nbsp;</td>" } qw(transdate id reference source description accno);
15 finnarne 559
  $column_data{debit} = "<th class=listsubtotal align=right>$subtotaldebit</td>";
560
  $column_data{credit} = "<th class=listsubtotal align=right>$subtotalcredit</td>";
2 finnarne 561
 
562
 
563
  print "<tr class=listsubtotal>";
564
  map { print "$column_data{$_}\n" } @column_index;
565
  print "</tr>";
566
 
567
  $subtotaldebit = 0;
568
  $subtotalcredit = 0;
569
 
570
  $sameitem = $ref->{$form->{sort}};
571
 
572
}
573
 
574
 
575
sub update {
576
 
577
  @a = ();
578
  $count = 0;
114 finnarne 579
  @flds = (qw(accno debit credit projectnumber));
2 finnarne 580
 
581
  for $i (1 .. $form->{rowcount}) {
582
    unless (($form->{"debit_$i"} eq "") && ($form->{"credit_$i"} eq "")) {
583
      # take accno apart
584
      ($form->{"accno_$i"}) = split(/--/, $form->{"accno_$i"});
585
 
586
      push @a, {};
587
      $j = $#a;
588
 
589
      map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
590
      $count++;
591
    }
592
  }
593
 
594
  for $i (1 .. $count) {
595
    $j = $i - 1;
596
    map { $form->{"${_}_$i"} = $a[$j]->{$_} } @flds;
597
  }
598
 
599
  for $i ($count + 1 .. $form->{rowcount}) {
600
    map { delete $form->{"${_}_$i"} } @flds;
601
  }
602
 
603
  $form->{rowcount} = $count;
604
 
605
 
606
  &display_form;
607
 
608
}
609
 
610
 
611
sub display_form {
612
 
613
  &form_header;
614
 
615
  $form->{rowcount}++;
616
  $form->{totaldebit} = 0;
617
  $form->{totalcredit} = 0;
618
 
619
  for $i (1 .. $form->{rowcount}) {
620
    $form->{totaldebit} += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
621
    $form->{totalcredit} += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
622
 
623
    &form_row($i);
624
  }
625
 
626
  &form_footer;
627
 
628
}
629
 
630
 
631
sub form_row {
632
  my $i = shift;
114 finnarne 633
 
634
  foreach $item (qw(accno projectnumber)) {
635
    $form->{"select$item"} =~ s/ selected//;
636
    $form->{"select$item"} =~ s/option>\Q$form->{"${item}_$i"}\E/option selected>$form->{"${item}_$i"}/;
637
  }
638
 
639
  $project = qq|
640
  <td><select name="projectnumber_$i">$form->{selectprojectnumber}</select></td>
641
| if $form->{selectprojectnumber};
2 finnarne 642
 
114 finnarne 643
  if ($form->{transfer}) {
644
    $form->{"fx_transaction_$i"} = ($form->{"fx_transaction_$i"}) ? "checked" : "";
645
    $fx_transaction = qq|
646
  <td><input name="fx_transaction_$i" class=checkbox type=checkbox value=1 $form->{"fx_transaction_$i"}></td>
647
|;
648
  } else {
649
    $fx_transaction = qq|
650
    <input type=hidden name="fx_transaction_$i" value=$form->{"fx_transaction_$i"}>
651
|;
652
  }
2 finnarne 653
 
654
  print qq|<tr>
114 finnarne 655
  <td><select name="accno_$i">$form->{selectaccno}</select></td>
656
  $fx_transaction
2 finnarne 657
  <td><input name="debit_$i" size=12 value=$form->{"debit_$i"}></td>
658
  <td><input name="credit_$i" size=12 value=$form->{"credit_$i"}></td>
114 finnarne 659
  $project
2 finnarne 660
</tr>
661
<input type=hidden name=rowcount value=$i>
662
 
663
|;
664
 
665
}
666
 
667
 
668
sub form_header {
669
 
670
  $title = $form->{title};
114 finnarne 671
  if ($form->{transfer}) {
672
    $form->{title} = $locale->text("$title Cash Transfer Transaction");
673
  } else {
674
    $form->{title} = $locale->text("$title General Ledger Transaction");
675
  }
676
 
677
# $locale->text('Add Cash Transfer Transaction')
678
# $locale->text('Edit Cash Transfer Transaction')
2 finnarne 679
# $locale->text('Add General Ledger Transaction')
680
# $locale->text('Edit General Ledger Transaction')
681
 
114 finnarne 682
  map { $form->{$_} =~ s/"/&quot;/g } qw(reference description accno);
2 finnarne 683
 
684
  if (($rows = $form->numtextrows($form->{description}, 50)) > 1) {
685
    $description = qq|<textarea name=description rows=$rows cols=50 wrap=soft>$form->{description}</textarea>|;
686
  } else {
687
    $description = qq|<input name=description size=50 value="$form->{description}">|;
688
  }
689
 
690
  if (($rows = $form->numtextrows($form->{notes}, 50)) > 1) {
691
    $notes = qq|<textarea name=notes rows=$rows cols=50 wrap=soft>$form->{notes}</textarea>|;
692
  } else {
693
    $notes = qq|<input name=notes size=50 value="$form->{notes}">|;
694
  }
695
 
114 finnarne 696
  $project = qq|
697
          <th class=listheading width=1%>|.$locale->text('Project').qq|</th>
698
| if $form->{selectprojectnumber};
699
 
700
  if ($form->{transfer}) {
701
    $fx_transaction = qq|
702
          <th>|.$locale->text('FX').qq|</th>
703
|;
704
  }
705
 
2 finnarne 706
  $form->header;
707
 
708
  print qq|
709
<body>
710
 
711
<form method=post action=$form->{script}>
712
 
713
<input name=id type=hidden value=$form->{id}>
714
 
114 finnarne 715
<input type=hidden name=transfer value=$form->{transfer}>
716
 
717
<input type=hidden name=selectaccno value="$form->{selectaccno}">
718
<input type=hidden name=selectprojectnumber value="$form->{selectprojectnumber}">
719
 
2 finnarne 720
<input type=hidden name=closedto value=$form->{closedto}>
721
<input type=hidden name=locked value=$form->{locked}>
722
<input type=hidden name=title value="$title">
723
 
724
<table width=100%>
725
  <tr>
726
    <th class=listtop>$form->{title}</th>
727
  </tr>
728
  <tr height="5"></tr>
729
  <tr>
730
    <td>
731
      <table width=100%>
732
        <tr>
733
          <th align=right>|.$locale->text('Reference').qq|</th>
734
          <td><input name=reference size=20 value="$form->{reference}"></td>
735
          <td align=right>
736
            <table>
737
              <tr>
738
                <th align=right>|.$locale->text('Date').qq|</th>
739
                <td><input name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
740
              </tr>
741
            </table>
742
          </td>
743
        </tr>
744
        <tr>
745
          <th align=right>|.$locale->text('Description').qq|</th>
746
          <td colspan=2>$description</td>
747
        </tr>
748
        <tr>
749
          <th align=right>|.$locale->text('Notes').qq|</th>
750
          <td colspan=2>$notes</td>
751
        </tr>
752
      </table>
753
    </td>
754
  </tr>
755
  <tr>
756
    <td>
757
      <table width=100%>
758
        <tr class=listheading>
15 finnarne 759
          <th class=listheading>|.$locale->text('Account').qq|</th>
114 finnarne 760
          $fx_transaction
15 finnarne 761
          <th class=listheading>|.$locale->text('Debit').qq|</th>
762
          <th class=listheading>|.$locale->text('Credit').qq|</th>
114 finnarne 763
          $project
2 finnarne 764
        </tr>
765
|;
766
 
767
}
768
 
769
 
770
sub form_footer {
771
 
772
  ($dec) = ($form->{totaldebit} =~ /\.(\d+)/);
773
  $dec = length $dec;
774
  $decimalplaces = ($dec > 2) ? $dec : 2;
775
 
776
  map { $form->{$_} = $form->format_amount(\%myconfig, $form->{$_}, $decimalplaces, "&nbsp;") } qw(totaldebit totalcredit);
777
 
114 finnarne 778
  $project = qq|
779
          <th>&nbsp;</th>
780
| if $form->{selectprojectnumber};
781
 
782
  if ($form->{transfer}) {
783
    $fx_transaction = qq|
784
          <th>&nbsp;</th>
785
|;
786
  }
787
 
2 finnarne 788
  print qq|
789
        <tr class=listtotal>
790
          <th>&nbsp;</th>
114 finnarne 791
          $fx_transaction
15 finnarne 792
          <th class=listtotal align=right>$form->{totaldebit}</th>
793
          <th class=listtotal align=right>$form->{totalcredit}</th>
114 finnarne 794
          $project
2 finnarne 795
        </tr>
796
      </table>
797
    </td>
798
  </tr>
799
  <tr>
800
    <td><hr size=3 noshade></td>
801
  </tr>
802
</table>
803
 
804
<input type=hidden name=path value=$form->{path}>
805
<input type=hidden name=login value=$form->{login}>
806
<input type=hidden name=password value=$form->{password}>
807
 
808
<input name=callback type=hidden value="$form->{callback}">
809
 
810
<br>
811
|;
812
 
813
  $transdate = $form->datetonum($form->{transdate}, \%myconfig);
814
  $closedto = $form->datetonum($form->{closedto}, \%myconfig);
815
 
114 finnarne 816
  if (! $form->{readonly}) {
817
 
818
    if ($form->{id}) {
819
      print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
2 finnarne 820
|;
821
 
822
      if (!$form->{locked}) {
823
        print qq|
824
        <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">
825
        <input class=submit type=submit name=action value="|.$locale->text('Delete').qq|">
826
|;
827
      }
828
 
829
      print qq|
114 finnarne 830
        <input class=submit type=submit name=action value="|.$locale->text('Post as new').qq|">
2 finnarne 831
|;
114 finnarne 832
 
833
    } else {
834
      if ($transdate > $closedto) {
835
        print qq|<input class=submit type=submit name=action value="|.$locale->text('Update').qq|">
836
        <input class=submit type=submit name=action value="|.$locale->text('Post').qq|">|;
837
      }
2 finnarne 838
    }
839
  }
840
 
841
  print "</form>
842
 
843
</body>
844
</html>
845
";
846
 
847
}
848
 
849
 
850
sub delete {
851
 
852
  $form->header;
853
 
854
  print qq|
855
<body>
856
 
857
<form method=post action=$form->{script}>
858
|;
859
 
860
  foreach $key (keys %$form) {
114 finnarne 861
    $form->{$key} =~ s/"/&quot;/g;
2 finnarne 862
    print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
863
  }
864
 
865
  print qq|
866
<h2 class=confirm>|.$locale->text('Confirm!').qq|</h2>
867
 
868
<h4>|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{reference}</h4>
869
 
870
<input name=action class=submit type=submit value="|.$locale->text('Yes').qq|">
871
</form>
872
|;
873
 
874
}
875
 
876
 
877
sub yes {
878
 
879
  $form->redirect($locale->text('Transaction deleted!')) if (GL->delete_transaction(\%myconfig, \%$form));
880
  $form->error($locale->text('Cannot delete transaction!'));
881
 
882
}
883
 
884
 
885
sub post {
886
 
887
  # check if there is something in reference and date
888
  $form->isblank("reference", $locale->text('Reference missing!'));
889
  $form->isblank("transdate", $locale->text('Transaction Date missing!'));
890
 
891
  $transdate = $form->datetonum($form->{transdate}, \%myconfig);
892
  $closedto = $form->datetonum($form->{closedto}, \%myconfig);
893
 
15 finnarne 894
 
2 finnarne 895
  $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
896
 
114 finnarne 897
  if (!$form->{adjustment}) {
898
    for $i (1 .. $form->{rowcount}) {
899
      $debit += $form->parse_amount(\%myconfig, $form->{"debit_$i"});
900
      $credit += $form->parse_amount(\%myconfig, $form->{"credit_$i"});
901
    }
902
 
903
    if ($form->round_amount($debit, 2) != $form->round_amount($credit, 2)) {
904
      &post_adjustment;
905
      exit;
906
    }
2 finnarne 907
  }
908
 
114 finnarne 909
  $form->redirect($locale->text('Transaction posted!')) if GL->post_transaction(\%myconfig, \%$form);
910
  $form->error($locale->text('Cannot post transaction!'));
911
 
2 finnarne 912
}
913
 
914
 
915
sub post_as_new {
916
 
917
  $form->{id} = 0;
918
  &post;
919
 
920
}
921
 
922
 
114 finnarne 923
sub post_adjustment {
924
 
925
  $form->header;
926
 
927
  print qq|
928
<body>
929
 
930
<form method=post action=$form->{script}>
931
 
932
<input type=hidden name=adjustment value=1>
933
|;
934
 
935
  foreach $key (keys %$form) {
936
    $form->{$key} =~ s/"/&quot;/g;
937
    print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
938
  }
939
 
940
  print qq|
941
<h2 class=confirm>|.$locale->text('Warning!').qq|</h2>
942
 
943
<h4>|.$locale->text('Out of balance transaction!').qq|</h4>
944
 
945
<input name=action class=submit type=submit value="|.$locale->text('Post').qq|">
946
</form>
947
|;
948
 
949
}
950
 
951