-
Notifications
You must be signed in to change notification settings - Fork 1
/
lastincome.inc.php
119 lines (110 loc) · 3.49 KB
/
lastincome.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
<?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;
}
$text.= "<div class=\"caption_out\" style=\"margin-top:5px\"><div class=\"caption\">";
$text.= "<b>הכנסות אחרונות</b>\n";
$text.= "</div></div><br>\n";
$text.= "<table border=\"0\" class=\"hovertbl\"><tr class=\"tblhead\">\n";
$text.= "<td style=\"width:2.5em\">מספר</td>\n";
$text.= "<td style=\"width:6em\">תאריך</td>\n";
$text.= "<td style=\"width:10em\">לקוח</td>\n";
$text.= "<td style=\"width:10em\">חשבון הכנסות</td>\n";
$text.= "<td style=\"width:5em\">אסמכתא</td>\n";
$text.= "<td style=\"width:5em\">פרטים</td>\n";
$text.= "<td style=\"width:5em\">לפני מע\"מ</td>\n";
$text.= "<td style=\"width:4em\">סכום</td>\n";
$text.= "</tr>\n";
$t = MANINVOICE;
$query = "SELECT * FROM $transactionstbl WHERE prefix='$prefix' ";
$query .= "AND type='$t' AND sum<'0' ORDER BY num DESC LIMIT 10";
$result = DoQuery($query, "tranrep.php");
while($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$custacct == 0;
$inacct == 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) == CUSTOMER) {
$custacct = $acct1;
$sum *= -1.0;
}
if(GetAcctType($acct1) == INCOME)
$inacct = $acct1;
if(GetAcctType($acct2) == CUSTOMER) {
$custacct = $acct2;
}
if(GetAcctType($acct2) == INCOME)
$inacct = $acct2;
$query = "SELECT sum FROM $transactionstbl WHERE num='$num' AND account='$inacct'";
$r = DoQuery($query, "lastincome");
$l = mysql_fetch_array($r, MYSQL_NUM);
$novatsum = number_format(abs($l[0]));
$custname = GetAccountName($custacct);
$inname = GetAccountName($inacct);
if(($custacct == 0) || ($inacct == 0))
continue;
$text.='<tr>';
$text.= "<td>$num</td>\n";
$text.= "<td>$date</td>\n";
$url = "?module=acctdisp&account=$custacct&begin=start&end=today";
$text.= "<td><a href=\"$url\">$custname</a></td>\n";
$url = "?module=acctdisp&account=$inacct&begin=start&end=today";
$text.= "<td><a href=\"$url\">$inname</a></td>\n";
$text.= "<td>$refnum1</td>\n";
$text.= "<td>$details</td>\n";
$text.= "<td>$novatsum</td>\n";
$sum = number_format($sum);
$text.= "<td>$sum</td>\n";
$text.= "</tr>\n";
}
$text.= "</table>\n";
?>