-
Notifications
You must be signed in to change notification settings - Fork 1
/
lasttran.inc.php
132 lines (121 loc) · 3.74 KB
/
lasttran.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?PHP
/*
| Get last rows from transactions tbl
*/
global $transactionstbl;
function GetAcctType($acct) {
global $prefix, $accountstbl;
$query = "SELECT type FROM $accountstbl WHERE num='$acct' AND prefix='$prefix'";
$result = DoQuery($query, "GetAcctType");
$line = mysql_fetch_array($result, MYSQL_NUM);
return $line[0];
}
function GetOppositAccount($num, $sum) {
global $transactionstbl, $prefix;
$query = "SELECT account,sum FROM $transactionstbl WHERE num='$num' AND prefix='$prefix'";
$result = mysql_query($query);
if(!$result) {
echo mysql_error();
exit;
}
if($sum < 0.0)
$neg = 1;
else
$neg = 0;
$maxsum = 0;
while($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$account = $line['account'];
$tsum = $line['sum'];
if($neg == 1) { /* we are looking for positive sums */
if($tsum > 0.0) {
if($tsum > $maxsum) {
$maxsum = $tsum;
$retacct = $account;
}
}
}
else { /* we are looking for negative sums */
if($tsum < 0.0) {
if($tsum < $maxsum) {
$maxsum = $tsum;
$retacct = $account;
}
}
}
}
return $retacct;
}
$l = _("Last outcomes");
$text.= "<h3>$l</h3><br />\n";// class=\"hovertbl\"
$text.= "<table border=\"0\" id=\"outcome\" class=\"tablesorter\"><thead><tr>\n";
$l = _("Num.");
$text.= "<th style=\"width:2.5em\">$l</th>\n";
$l = _("Date");
$text.= "<th style=\"width:6em\">$l</th>\n";
$l = _("Supplier");
$text.= "<th style=\"width:11em\">$l</th>\n";
$l = _("Outcome acc.");
$text.= "<th style=\"width:10em\">$l</th>\n";
$l = _("Ref. num");
$text.= "<th style=\"width:5em\">$l</th>\n";
$l = _("Details");
$text.= "<th style=\"width:15em\">$l</th>\n";
$l = _("Before VAT");
$text.= "<th style=\"width:5em\">$l</th>\n";
$l = _("Sum");
$text.= "<th style=\"width:4em\">$l</th>\n";
$text.= "</tr></thead><tbody>\n";
$t = SUPINV;
$query = "SELECT * FROM $transactionstbl WHERE prefix='$prefix' ";
$query .= "AND type='$t' AND sum>'0' ORDER BY num DESC LIMIT 10";
//print $query;
$result = DoQuery($query, "lasttran");
while($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$supacct == 0;
$outacct == 0;
$sum1 = 0;
$sum2 = 0;
$num = $line['num'];
$acct1 = $line['account'];
$date = FormatDate($line['date'], "mysql", "dmy");
$sum = $line['sum'];
$details = $line['details'];
$refnum1 = $line['refnum1'];
$refnum2 = $line['refnum2'];
$acct2 = GetOppositAccount($num, $sum);
if(GetAcctType($acct1) == SUPPLIER)
$supacct = $acct1;
if(GetAcctType($acct2) == SUPPLIER) {
$supacct = $acct2;
$sum *= -1.0;
}
if(GetAcctType($acct1) == OUTCOME)
$outacct = $acct1;
if(GetAcctType($acct2) == OUTCOME)
$outacct = $acct2;
//print "b:".$outacct.",".$supacct.";<br />";
$query = "SELECT sum FROM $transactionstbl WHERE num='$num' AND account='$outacct' AND prefix='$prefix'";
$r = DoQuery($query, "lasttran");
$l = mysql_fetch_array($r, MYSQL_NUM);
$novatsum = number_format(abs($l[0]));
$supname = GetAccountName($supacct);
$outname = GetAccountName($outacct);
// print "Sup: $supname, out: $outname<br>\n";
if(($supacct == 0) || ($outacct == 0))
continue;
$text.='<tr>';
$text.= "<td>$num</td>\n";
$text.= "<td>$date</td>\n";
$url = "?module=acctdisp&account=$supacct&begin=start&end=today";
$text.= "<td><a href=\"$url\">$supname</a></td>\n";
$url = "?module=acctdisp&account=$outacct&begin=start&end=today";
$text.= "<td><a href=\"$url\">$outname</a></td>\n";
$text.= "<td>$refnum1</td>\n";
$text.= "<td>$details</td>\n";
$text.= "<td dir=\"ltr\" align=\"right\">$novatsum</td>\n";
$tstr = number_format($sum);
$text.= "<td dir=\"ltr\" align=\"right\">$tstr</td>\n";
$text.= "</tr>\n";
}
$text.= "</tbody></table>\n";
?>