summaryrefslogtreecommitdiff
path: root/LedgerSMB/OP.pm
blob: 081abd29f04366a7968d49b351689186ce48c275 (plain)
  1. #=====================================================================
  2. # LedgerSMB
  3. # Small Medium Business Accounting software
  4. #
  5. # Copyright (C) 2006
  6. # This work contains copyrighted information from a number of sources all used
  7. # with permission.
  8. #
  9. # This file contains source code included with or based on SQL-Ledger which
  10. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  11. # under the GNU General Public License version 2 or, at your option, any later
  12. # version. For a full list including contact information of contributors,
  13. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  14. #
  15. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  16. # Copyright (C) 2001
  17. #
  18. # Author: DWS Systems Inc.
  19. # Web: http://www.sql-ledger.org
  20. #
  21. # Contributors:
  22. #
  23. #======================================================================
  24. #
  25. # This file has NOT undergone whitespace cleanup.
  26. #
  27. #======================================================================
  28. #
  29. # Overpayment function
  30. # used in AR, AP, IS, IR, OE, CP
  31. #
  32. #======================================================================
  33. package OP;
  34. sub overpayment {
  35. my ($self, $myconfig, $form, $dbh, $amount, $ml) = @_;
  36. my $fxamount = $form->round_amount($amount * $form->{exchangerate}, 2);
  37. my ($paymentaccno) = split /--/, $form->{account};
  38. my ($null, $department_id) = split /--/, $form->{department};
  39. $department_id *= 1;
  40. my $uid = localtime;
  41. $uid .= "$$";
  42. # add AR/AP header transaction with a payment
  43. $query = qq|INSERT INTO $form->{arap} (invnumber, employee_id)
  44. VALUES ('$uid', (SELECT id FROM employee
  45. WHERE login = '$form->{login}'))|;
  46. $dbh->do($query) || $form->dberror($query);
  47. $query = qq|SELECT id FROM $form->{arap}
  48. WHERE invnumber = '$uid'|;
  49. ($uid) = $dbh->selectrow_array($query);
  50. my $invnumber = $form->{invnumber};
  51. $invnumber = $form->update_defaults($myconfig, ($form->{arap} eq 'ar') ? "sinumber" : "vinumber", $dbh) unless $invnumber;
  52. $query = qq|UPDATE $form->{arap} set
  53. invnumber = |.$dbh->quote($invnumber).qq|,
  54. $form->{vc}_id = $form->{"$form->{vc}_id"},
  55. transdate = '$form->{datepaid}',
  56. datepaid = '$form->{datepaid}',
  57. duedate = '$form->{datepaid}',
  58. netamount = 0,
  59. amount = 0,
  60. paid = $fxamount,
  61. curr = '$form->{currency}',
  62. department_id = $department_id
  63. WHERE id = $uid|;
  64. $dbh->do($query) || $form->dberror($query);
  65. # add AR/AP
  66. ($accno) = split /--/, $form->{$form->{ARAP}};
  67. $query = qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, amount)
  68. VALUES ($uid, (SELECT id FROM chart
  69. WHERE accno = '$accno'),
  70. '$form->{datepaid}', $fxamount * $ml)|;
  71. $dbh->do($query) || $form->dberror($query);
  72. # add payment
  73. $query = qq|INSERT INTO acc_trans (trans_id, chart_id, transdate,
  74. amount, source, memo)
  75. VALUES ($uid, (SELECT id FROM chart
  76. WHERE accno = '$paymentaccno'),
  77. '$form->{datepaid}', $amount * $ml * -1, |
  78. .$dbh->quote($form->{source}).qq|, |
  79. .$dbh->quote($form->{memo}).qq|)|;
  80. $dbh->do($query) || $form->dberror($query);
  81. # add exchangerate difference
  82. if ($fxamount != $amount) {
  83. $query = qq|INSERT INTO acc_trans (trans_id, chart_id, transdate,
  84. amount, cleared, fx_transaction, source)
  85. VALUES ($uid, (SELECT id FROM chart
  86. WHERE accno = '$paymentaccno'),
  87. '$form->{datepaid}', ($fxamount - $amount) * $ml * -1,
  88. '1', '1', |
  89. .$dbh->quote($form->{source}).qq|)|;
  90. $dbh->do($query) || $form->dberror($query);
  91. }
  92. my %audittrail = ( tablename => $form->{arap},
  93. reference => $invnumber,
  94. formname => ($form->{arap} eq 'ar') ? 'deposit' : 'pre-payment',
  95. action => 'posted',
  96. id => $uid );
  97. $form->audittrail($dbh, "", \%audittrail);
  98. }
  99. 1;