Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b1253e4f

Von Philip Reetz vor fast 19 Jahren hinzugefügt

  • ID b1253e4fa3f2a31c7452894439386d43951f5bc8
  • Vorgänger c7f9bb36
  • Nachfolger 0fdd4332

Perltidy Lauf der Aenderungen zu Splittbuchungen

Unterschiede anzeigen:

SL/GL.pm
40 40

  
41 41
sub delete_transaction {
42 42
  my ($self, $myconfig, $form) = @_;
43
  
43
  $lxdebug->enter_sub();
44

  
44 45
  # connect to database
45 46
  my $dbh = $form->dbconnect_noauto($myconfig);
46 47

  
......
53 54
  # commit and redirect
54 55
  my $rc = $dbh->commit;
55 56
  $dbh->disconnect;
56
  
57
  $lxdebug->leave_sub();
58

  
57 59
  $rc;
58
  
59
}
60 60

  
61
}
61 62

  
62 63
sub post_transaction {
63 64
  my ($self, $myconfig, $form) = @_;
64
  
65
  $lxdebug->enter_sub();
66

  
65 67
  my ($debit, $credit) = (0, 0);
66 68
  my $project_id;
67 69

  
68 70
  my $i;
71

  
69 72
  # check if debit and credit balances
70
  
73

  
71 74
  if ($form->{storno}) {
72
  	$debit = $debit * -1;
73
	$credit = $credit * -1;
74
	$tax = $tax * -1;
75
	$form->{reference} = "Storno-".$form->{reference};
76
	$form->{description} = "Storno-".$form->{description};
77
  }  
75
    $debit               = $debit * -1;
76
    $credit              = $credit * -1;
77
    $tax                 = $tax * -1;
78
    $form->{reference}   = "Storno-" . $form->{reference};
79
    $form->{description} = "Storno-" . $form->{description};
80
  }
78 81

  
79 82
  # connect to database, turn off AutoCommit
80 83
  my $dbh = $form->dbconnect_noauto($myconfig);
......
94 97
  if (!$form->{taxincluded}) {
95 98
    $form->{taxincluded} = 0;
96 99
  }
97
  
100

  
98 101
  my ($query, $sth);
99
  
102

  
100 103
  if ($form->{id}) {
104

  
101 105
    # delete individual transactions
102 106
    $query = qq|DELETE FROM acc_trans 
103 107
                WHERE trans_id = $form->{id}|;
104 108
    $dbh->do($query) || $form->dberror($query);
105
    
109

  
106 110
  } else {
107 111
    my $uid = time;
108 112
    $uid .= $form->{login};
......
111 115
                VALUES ('$uid', (SELECT e.id FROM employee e
112 116
		                 WHERE e.login = '$form->{login}'))|;
113 117
    $dbh->do($query) || $form->dberror($query);
114
    
118

  
115 119
    $query = qq|SELECT g.id FROM gl g
116 120
                WHERE g.reference = '$uid'|;
117 121
    $sth = $dbh->prepare($query);
......
121 125
    $sth->finish;
122 126

  
123 127
  }
124
  
128

  
125 129
  my ($null, $department_id) = split /--/, $form->{department};
126 130
  $department_id *= 1;
127
  
131

  
128 132
  $query = qq|UPDATE gl SET 
129 133
	      reference = '$form->{reference}',
130 134
	      description = '$form->{description}',
......
133 137
	      department_id = $department_id,
134 138
	      taxincluded = '$form->{taxincluded}'
135 139
	      WHERE id = $form->{id}|;
136
	   
140

  
137 141
  $dbh->do($query) || $form->dberror($query);
138 142
  ($taxkey, $rate) = split(/--/, $form->{taxkey});
139 143

  
140

  
141 144
  # insert acc_trans transactions
142 145
  for $i (1 .. $form->{rowcount}) {
146

  
143 147
    # extract accno
144 148
    my ($accno) = split(/--/, $form->{"accno_$i"});
145 149
    my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
146 150
    my $amount = 0;
147
    my $debit = $form->{"debit_$i"};
151
    my $debit  = $form->{"debit_$i"};
148 152
    my $credit = $form->{"credit_$i"};
149
    my $tax = $form->{"tax_$i"};
150
    
153
    my $tax    = $form->{"tax_$i"};
154

  
151 155
    if ($credit) {
152 156
      $amount = $credit;
153 157
      $posted = 0;
154 158
    }
155 159
    if ($debit) {
156 160
      $amount = $debit * -1;
157
      $tax = $tax * -1;
161
      $tax    = $tax * -1;
158 162
      $posted = 0;
159 163
    }
160 164

  
161

  
162 165
    # if there is an amount, add the record
163 166
    if ($amount != 0) {
164
      $project_id = ($form->{"project_id_$i"}) ? $form->{"project_id_$i"} : 'NULL'; 
167
      $project_id =
168
        ($form->{"project_id_$i"}) ? $form->{"project_id_$i"} : 'NULL';
165 169
      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
166 170
                  source, memo, project_id, taxkey)
167 171
		  VALUES
168 172
		  ($form->{id}, (SELECT c.id
169 173
		                 FROM chart c
170 174
				 WHERE c.accno = '$accno'),
171
		   $amount, '$form->{transdate}', |.
172
		   $dbh->quote($form->{"source_$i"}) .qq|, |.
173
		  $dbh->quote($form->{"memo_$i"}).qq|,
175
		   $amount, '$form->{transdate}', |
176
        . $dbh->quote($form->{"source_$i"}) . qq|, |
177
        . $dbh->quote($form->{"memo_$i"}) . qq|,
174 178
		  $project_id, $taxkey)|;
175
    
179

  
176 180
      $dbh->do($query) || $form->dberror($query);
177 181
    }
178
  
179
    if ($tax !=0) {
180
          # add taxentry
181
          $amount = $tax;
182
          
183
          
184
          $project_id = ($form->{"project_id_$i"}) ? $form->{"project_id_$i"} : 'NULL'; 
185
          $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
182

  
183
    if ($tax != 0) {
184

  
185
      # add taxentry
186
      $amount = $tax;
187

  
188
      $project_id =
189
        ($form->{"project_id_$i"}) ? $form->{"project_id_$i"} : 'NULL';
190
      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
186 191
                  source, memo, project_id, taxkey)
187 192
                  VALUES
188 193
                  ($form->{id}, (SELECT t.chart_id
189 194
                  FROM tax t
190 195
                  WHERE t.taxkey = $taxkey),
191
                  $amount, '$form->{transdate}', |.
192
		   $dbh->quote($form->{"source_$i"}) .qq|, |.
193
		  $dbh->quote($form->{"memo_$i"}).qq|,
196
                  $amount, '$form->{transdate}', |
197
        . $dbh->quote($form->{"source_$i"}) . qq|, |
198
        . $dbh->quote($form->{"memo_$i"}) . qq|,
194 199
                          $project_id, $taxkey)|;
195
          
196
          $dbh->do($query) || $form->dberror($query);
200

  
201
      $dbh->do($query) || $form->dberror($query);
197 202
    }
198 203
  }
199 204

  
200
  my %audittrail = ( tablename  => 'gl',
201
                     reference  => $form->{reference},
202
		     formname   => 'transaction',
203
		     action     => 'posted',
204
		     id         => $form->{id} );
205
 
205
  my %audittrail = (tablename => 'gl',
206
                    reference => $form->{reference},
207
                    formname  => 'transaction',
208
                    action    => 'posted',
209
                    id        => $form->{id});
210

  
206 211
  # $form->audittrail($dbh, "", \%audittrail);
207 212

  
208 213
  # commit and redirect
209 214
  my $rc = $dbh->commit;
210 215
  $dbh->disconnect;
216
  $lxdebug->leave_sub();
211 217

  
212 218
  $rc;
213 219

  
214 220
}
215 221

  
216

  
217

  
218 222
sub all_transactions {
219 223
  my ($self, $myconfig, $form) = @_;
224
  $lxdebug->enter_sub();
220 225

  
221 226
  # connect to database
222 227
  my $dbh = $form->dbconnect($myconfig);
223 228
  my ($query, $sth, $source, $null);
224 229

  
225 230
  my ($glwhere, $arwhere, $apwhere) = ("1 = 1", "1 = 1", "1 = 1");
226
  
231

  
227 232
  if ($form->{reference}) {
228 233
    $source = $form->like(lc $form->{reference});
229 234
    $glwhere .= " AND lower(g.reference) LIKE '$source'";
......
282 287
  }
283 288

  
284 289
  if ($form->{accno}) {
290

  
285 291
    # get category for account
286 292
    $query = qq|SELECT c.category
287 293
                FROM chart c
288 294
		WHERE c.accno = '$form->{accno}'|;
289
    $sth = $dbh->prepare($query); 
295
    $sth = $dbh->prepare($query);
296

  
297
    $sth->execute || $form->dberror($query);
298
    ($form->{ml}) = $sth->fetchrow_array;
299
    $sth->finish;
290 300

  
291
    $sth->execute || $form->dberror($query); 
292
    ($form->{ml}) = $sth->fetchrow_array; 
293
    $sth->finish; 
294
    
295 301
    if ($form->{datefrom}) {
296 302
      $query = qq|SELECT SUM(ac.amount)
297 303
		  FROM acc_trans ac, chart c
......
306 312
      $sth->finish;
307 313
    }
308 314
  }
309
  
315

  
310 316
  if ($form->{gifi_accno}) {
317

  
311 318
    # get category for account
312 319
    $query = qq|SELECT c.category
313 320
                FROM chart c
314 321
		WHERE c.gifi_accno = '$form->{gifi_accno}'|;
315
    $sth = $dbh->prepare($query); 
322
    $sth = $dbh->prepare($query);
323

  
324
    $sth->execute || $form->dberror($query);
325
    ($form->{ml}) = $sth->fetchrow_array;
326
    $sth->finish;
316 327

  
317
    $sth->execute || $form->dberror($query); 
318
    ($form->{ml}) = $sth->fetchrow_array; 
319
    $sth->finish; 
320
   
321 328
    if ($form->{datefrom}) {
322 329
      $query = qq|SELECT SUM(ac.amount)
323 330
		  FROM acc_trans ac, chart c
......
333 340
    }
334 341
  }
335 342

  
336
  my $false = ($myconfig->{dbdriver} eq 'Pg') ? FALSE : q|'0'|;
343
  my $false = ($myconfig->{dbdriver} eq 'Pg') ? FALSE: q|'0'|;
337 344

  
338
  
339
  my $query = qq|SELECT g.id, 'gl' AS type, $false AS invoice, g.reference, ac.taxkey, t.taxkey AS sorttax,
345
  my $query =
346
    qq|SELECT g.id, 'gl' AS type, $false AS invoice, g.reference, ac.taxkey, t.taxkey AS sorttax,
340 347
                 g.description, ac.transdate, ac.source, ac.trans_id,
341 348
		 ac.amount, c.accno, c.gifi_accno, g.notes, t.chart_id, ac.oid
342 349
                 FROM gl g, acc_trans ac, chart c LEFT JOIN tax t ON
......
367 374
	         ORDER BY transdate, trans_id, taxkey DESC, sorttax DESC, oid|;
368 375
  my $sth = $dbh->prepare($query);
369 376
  $sth->execute || $form->dberror($query);
370
  
377

  
371 378
  while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
372 379
    print(STDERR $ref->{id}, " Transaction\n");
380

  
373 381
    # gl
374 382
    if ($ref->{type} eq "gl") {
375 383
      $ref->{module} = "gl";
......
392 400
        $ref->{module} = "ar";
393 401
      }
394 402
    }
395
    $balance=$ref->{amount};
396
    $i = 0;
397
    $j = 0;
398
    $k = 0;
399
    $l = 0;
403
    $balance = $ref->{amount};
404
    $i       = 0;
405
    $j       = 0;
406
    $k       = 0;
407
    $l       = 0;
400 408
    if ($ref->{amount} < 0) {
401
      if ($ref->{chart_id} >0) {
402
        $ref->{debit_tax}{$i} = $ref->{amount} * -1;
409
      if ($ref->{chart_id} > 0) {
410
        $ref->{debit_tax}{$i}       = $ref->{amount} * -1;
403 411
        $ref->{debit_tax_accno}{$i} = $ref->{accno};
404
        }
405
      else {
406
        $ref->{debit}{$k} = $ref->{amount} * -1;
407
        $ref->{debit_accno}{$k} = $ref->{accno};
412
      } else {
413
        $ref->{debit}{$k}        = $ref->{amount} * -1;
414
        $ref->{debit_accno}{$k}  = $ref->{accno};
408 415
        $ref->{debit_taxkey}{$k} = $ref->{taxkey};
409
        }
416
      }
410 417
    } else {
411
      if ($ref->{chart_id} >0) {
412
        $ref->{credit_tax}{$j} = $ref->{amount};
418
      if ($ref->{chart_id} > 0) {
419
        $ref->{credit_tax}{$j}       = $ref->{amount};
413 420
        $ref->{credit_tax_accno}{$j} = $ref->{accno};
414
        }
415
      else {
416
        $ref->{credit}{$l} = $ref->{amount};
417
        $ref->{credit_accno}{$l} = $ref->{accno};
421
      } else {
422
        $ref->{credit}{$l}        = $ref->{amount};
423
        $ref->{credit_accno}{$l}  = $ref->{accno};
418 424
        $ref->{credit_taxkey}{$l} = $ref->{taxkey};
419
        }
425
      }
420 426
    }
421 427

  
422
    while (abs($balance)>=0.015) {
423
      my $ref2 = $sth->fetchrow_hashref(NAME_lc) || $form->error("Unbalanced ledger!");
428
    while (abs($balance) >= 0.015) {
429
      my $ref2 = $sth->fetchrow_hashref(NAME_lc)
430
        || $form->error("Unbalanced ledger!");
424 431

  
425
      $balance = (int($balance * 100000) + int(100000 * $ref2->{amount})) / 100000;
426
      print(STDERR $balance," BAlance\n");
432
      $balance =
433
        (int($balance * 100000) + int(100000 * $ref2->{amount})) / 100000;
434
      print(STDERR $balance, " BAlance\n");
427 435
      if ($ref2->{amount} < 0) {
428
        if ($ref2->{chart_id} >0) {
436
        if ($ref2->{chart_id} > 0) {
429 437
          if ($ref->{debit_tax_accno}{$i} ne "") {
430 438
            $i++;
431 439
          }
432
          $ref->{debit_tax}{$i} = $ref2->{amount} * -1;
440
          $ref->{debit_tax}{$i}       = $ref2->{amount} * -1;
433 441
          $ref->{debit_tax_accno}{$i} = $ref2->{accno};
434
          }
435
        else {
442
        } else {
436 443
          if ($ref->{debit_accno}{$k} ne "") {
437 444
            $k++;
438 445
          }
439
          $ref->{debit}{$k} = $ref2->{amount} * -1;
440
          $ref->{debit_accno}{$k} = $ref2->{accno};
446
          $ref->{debit}{$k}        = $ref2->{amount} * -1;
447
          $ref->{debit_accno}{$k}  = $ref2->{accno};
441 448
          $ref->{debit_taxkey}{$k} = $ref2->{taxkey};
442
          }
449
        }
443 450
      } else {
444
        if ($ref2->{chart_id} >0) {
451
        if ($ref2->{chart_id} > 0) {
445 452
          if ($ref->{credit_tax_accno}{$j} ne "") {
446 453
            $j++;
447 454
          }
448
          $ref->{credit_tax}{$j} = $ref2->{amount};
455
          $ref->{credit_tax}{$j}       = $ref2->{amount};
449 456
          $ref->{credit_tax_accno}{$j} = $ref2->{accno};
450
          }
451
        else {
457
        } else {
452 458
          if ($ref->{credit_accno}{$l} ne "") {
453 459
            $l++;
454 460
          }
455
          $ref->{credit}{$l} = $ref2->{amount};
456
          $ref->{credit_accno}{$l} = $ref2->{accno};
461
          $ref->{credit}{$l}        = $ref2->{amount};
462
          $ref->{credit_accno}{$l}  = $ref2->{accno};
457 463
          $ref->{credit_taxkey}{$l} = $ref2->{taxkey};
458
          }
464
        }
459 465
      }
460 466
    }
461
#    print(STDERR Dumper($ref));       
467

  
468
    #    print(STDERR Dumper($ref));
462 469
    push @{ $form->{GL} }, $ref;
463
    $balance=0;
470
    $balance = 0;
464 471
  }
465 472
  $sth->finish;
466 473

  
467 474
  if ($form->{accno}) {
468
    $query = qq|SELECT c.description FROM chart c WHERE c.accno = '$form->{accno}'|;
475
    $query =
476
      qq|SELECT c.description FROM chart c WHERE c.accno = '$form->{accno}'|;
469 477
    $sth = $dbh->prepare($query);
470 478
    $sth->execute || $form->dberror($query);
471 479

  
......
473 481
    $sth->finish;
474 482
  }
475 483
  if ($form->{gifi_accno}) {
476
    $query = qq|SELECT g.description FROM gifi g WHERE g.accno = '$form->{gifi_accno}'|;
484
    $query =
485
      qq|SELECT g.description FROM gifi g WHERE g.accno = '$form->{gifi_accno}'|;
477 486
    $sth = $dbh->prepare($query);
478 487
    $sth->execute || $form->dberror($query);
479 488

  
480 489
    ($form->{gifi_account_description}) = $sth->fetchrow_array;
481 490
    $sth->finish;
482 491
  }
483
 
492
  $lxdebug->leave_sub();
493

  
484 494
  $dbh->disconnect;
485 495

  
486 496
}
487 497

  
488

  
489 498
sub transaction {
490 499
  my ($self, $myconfig, $form) = @_;
491
  
500
  $lxdebug->enter_sub();
501

  
492 502
  my ($query, $sth, $ref);
493
  
503

  
494 504
  # connect to database
495 505
  my $dbh = $form->dbconnect($myconfig);
496 506

  
......
514 524
    $ref = $sth->fetchrow_hashref(NAME_lc);
515 525
    map { $form->{$_} = $ref->{$_} } keys %$ref;
516 526
    $sth->finish;
517
  
527

  
518 528
    # retrieve individual rows
519 529
    $query = "SELECT c.accno, a.amount, project_id,
520 530
                (SELECT p.projectnumber FROM project p
......
525 535
	      ORDER BY a.oid";
526 536
    $sth = $dbh->prepare($query);
527 537
    $sth->execute || $form->dberror($query);
528
    
538

  
529 539
    while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
530 540
      push @{ $form->{GL} }, $ref;
531 541
    }
532 542

  
533
      # get tax description
543
    # get tax description
534 544
    $query = qq| SELECT * FROM tax t|;
535
    $sth = $dbh->prepare($query);
536
    $sth->execute || $form->dberror($query);  
545
    $sth   = $dbh->prepare($query);
546
    $sth->execute || $form->dberror($query);
537 547
    $form->{TAX} = ();
538 548
    while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
539 549
      push @{ $form->{TAX} }, $ref;
540 550
    }
541
  
551

  
542 552
    $sth->finish;
543 553
  } else {
544 554
    $query = "SELECT current_date AS transdate, closedto, revtrans
......
546 556
    $sth = $dbh->prepare($query);
547 557
    $sth->execute || $form->dberror($query);
548 558

  
549
    ($form->{transdate}, $form->{closedto}, $form->{revtrans}) = $sth->fetchrow_array;
550
    
551
      # get tax description
559
    ($form->{transdate}, $form->{closedto}, $form->{revtrans}) =
560
      $sth->fetchrow_array;
561

  
562
    # get tax description
552 563
    $query = qq| SELECT * FROM tax t order by t.taxkey|;
553
    $sth = $dbh->prepare($query);
554
    $sth->execute || $form->dberror($query);  
564
    $sth   = $dbh->prepare($query);
565
    $sth->execute || $form->dberror($query);
555 566
    $form->{TAX} = ();
556 567
    while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
557 568
      push @{ $form->{TAX} }, $ref;
......
572 583
    push @{ $form->{chart} }, $ref;
573 584
  }
574 585
  $sth->finish;
575
  
576 586

  
577
  
578 587
  $sth->finish;
579
  
588
  $lxdebug->leave_sub();
589

  
580 590
  $dbh->disconnect;
581 591

  
582 592
}
583 593

  
584

  
585 594
1;
586 595

  

Auch abrufbar als: Unified diff