-
Notifications
You must be signed in to change notification settings - Fork 1
/
inout.php
319 lines (294 loc) · 10.7 KB
/
inout.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<?PHP
/*
| Create transactions report (תקבולים תשלומים)
| This is part of Freelance accounting system.
| Written by Ori Idan for Shay Harel
| Modified by Adam BH 11/2011
*/
global $prefix, $accountstbl, $companiestbl, $transactionstbl, $tranreptbl;
$text='';
/* open window script */
if(isset($module)) {
print "<script type=\"text/javascript\">\n";
print "function PrintWin(url) {\n";
print "\twindow.open(url, 'PrintWin', 'width=800,height=600,scrollbar=yes');\n";
print "}\n";
print "</script>\n";
}
if(!isset($prefix) || ($prefix == '')) {
ErrorReport("לא ניתן לבצע פעולה זו ללא בחירת עסק");
return;
}
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];
}
$haeder='ספר תקבולים תשלומים';
if(!isset($module)) {
$query = "SELECT companyname FROM $companiestbl WHERE prefix='$prefix'";
$result = DoQuery($query, "GetAccountName");
$line = mysql_fetch_array($result, MYSQL_NUM);
$str = $line[0];
//print "<h1>$str</h1>\n";
//print "<h1>ספר תקבולים תשלומים</h1>\n";
}
else if($step != 0) {
//print "<h1>ספר תקבולים תשלומים</h1>";
}
/* prepare temporary table */
$query = "DELETE FROM $tranreptbl WHERE prefix='$prefix'";
DoQuery($query, "inout.php");
$step = isset($_GET['step']) ? $_GET['step'] : 0;
if($step == 0) { /* Get date range */
$edate = date("d-m-Y");
list($d, $m, $y) = explode('-', $edate);
$bdate = "1-1-$y";
//$text.= "<div class=\"righthalf2\">\n";
//$text.= "<div class=\"caption_out\"><div class=\"caption\">";
$text.= "<b>ספר תקבולים תשלומים</b>\n";
//$text.= "</div></div>\n";
$text.= "<form name=\"dtrange\" method=\"get\">\n";
$text.= "<input type=\"hidden\" name=\"module\" value=\"inout\">\n";
$text.= "<input type=\"hidden\" name=\"step\" value=\"1\">\n";
$text.= "<table dir=\"rtl\" cellpadding=\"20px\" cellspacing=\"20px\"><tr>\n";
$text.= "<td>בחר תאריך תחילה: </td>\n";
$text.= "<td><input class=\"date\" id=\"begindate\" type=\"text\" name=\"begindate\" value=\"$bdate\" size=\"7\">\n";
$text.= "</td>\n";
$text.= "<td>בחר תאריך סיום: </td>\n";
$text.= "<td><input class=\"date\" type=\"text\" id=\"enddate\" name=\"enddate\" value=\"$edate\" size=\"7\">\n";
$text.= "</td>\n";
$text.= "<td><input class=\"btnaction\" type=\"submit\" value=\"הפק\"></td>\n";
$text.= "</tr></table>\n";
$text.= "</form>\n";
//print "</div>\n";
//print "<div class=\"lefthalf2\">\n";
//ShowText('inout');
//print "</div>\n";
}
if($step == 2) {
$filename = "tmp/inoutrep.csv";
$fd = fopen($filename, 'w');
}
if($step >= 1) {
$RelevantTypes = array(RECEIPT, MANRECEIPT, SUPPLIERPAYMENT,VAT);
$order = isset($_GET['order']) ? $_GET['order'] : '';
$begindate = $_GET['begindate'];
$enddate = $_GET['enddate'];
$bdate = FormatDate($begindate, "dmy", "mysql");
$edate = FormatDate($enddate, "dmy", "mysql");
$text.= "<h2>לתקופה: $begindate - $enddate</h2>\n";
//$numorderurl = "?module=tranrep&step=1&begindate=$begindate&enddate=$enddate&order=num";
//$dtorderurl = "?module=tranrep&step=1&begindate=$begindate&enddate=$enddate&order=date";
//$typeorderurl = "?module=tranrep&step=1&begindate=$begindate&enddate=$enddate&order=opacctname";
if($step == 1) {
$text.= "<table class=\"tablesorter\"><thead><tr>\n";
//if(isset($module))
$text.= "<th>תנועה</th>\n";
//else
// $text.= "<th>תנועה </th>\n";
//if(isset($module)) {
// $text.= "<td style=\"width:5.5em\"><a href=\"$dtorderurl\">תאריך</a></th>\n";
// $text.= "<td><a href=\"$typeorderurl\">סעיף </a></td>\n";
//}
//else {
$text.= "<th style=\"width:5.5em\">תאריך</th>\n";
$text.= "<th>סעיף </th>\n";
//}
$text.= "<th style=\"width:3.5em\"> אסמכתא </th>\n";
$text.= "<th>לקוח\\ספק </th>\n";
$text.= "<th>פירוט </th>\n";
$text.= "<th style=\"width:4em\">תקבול </th>\n";
$text.= "<th style=\"width:4em\">תשלום </th>\n";
$text.= "</tr></thead>\n";
}
else if($step == 2) {
fwrite($fd, "\"תנועה\",");
fwrite($fd, "\"תאריך\",");
fwrite($fd, "\"סעיף\",");
fwrite($fd, "\"אסמכתא\",");
fwrite($fd, "\"לקוח\ספק\",");
fwrite($fd, "\"פירוט\",");
fwrite($fd, "\"תקבול\",");
fwrite($fd, "\"תשלום\",\n");
}
// print "order: $order<br>\n";
$query = "SELECT * FROM $transactionstbl WHERE prefix='$prefix' ";
$query .= "AND date>='$bdate' AND date<='$edate' ORDER BY num DESC";
$result = DoQuery($query, "tranrep.php");
$tnum = 0;
$state = 0;
$lastnum = 0;
$wnum = 0;
while($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$tnum = $line['num'];
if(($lastnum > 0) && ($tnum != $lastnum) && (abs($sum) > 0.01)) {
$opaccountname = GetAccountName($opaccount);
$query = "INSERT INTO $tranreptbl VALUES('$prefix', '$lastnum', '$dt', ";
$query .= "'$refnum', '$acctnum', '$acctname', '$opaccount', '$opaccountname', '$details', ";
$query .= "'$sum', '0', '0')";
// print "oppaccount: $oppaccount<br>\n";
// print "<div dir=\"ltr\">Query: $query<br></div>\n";
DoQuery($query, "inout.php");
$wnum = $tnum;
$sum = 0.0;
$details = '';
$oppaccount = 0;
$acctname = '';
$refnum = '';
}
$type = $line['type'];
$dt = $line['date'];
/*
| We are interested only in: RECEIPT, MANRECEIPT, SUPPLIERPAYMENT
*/
if(!in_array($type, $RelevantTypes))
continue;
$lastnum = $tnum;
/* We now have a transaction with relevant type */
$account = $line['account'];
if(GetAcctType($account) == CUSTOMER) {
$acctname = GetAccountName($account);
$acctnum = $account;
$details = $line['details'];
$refnum = $line['refnum1'];
$sum = $line['sum'];
}
/*else if(GetAcctType($account) == CASH) {
$novattotal = $line['sum'];
$opaccount = $account;
$opacctname = GetAccountName($account);
}*/
else if(($account == PAYVAT)||($account == NATINSPAY)){
$acctname = GetAccountName($account);
$acctnum = $account;
$sum =$line['sum'];
$refnum = $line['refnum1';
$details = $line['details'];
}else if(GetAcctType($account) == SUPPLIER) {
$acctname = GetAccountName($account);
$acctnum = $account;
$sum = $line['sum'];
$refnum = $line['refnum1';
$details = $line['details'];
}
else if(($account == CASH) || (GetAcctType($account) == BANKS)) {//cash is out
$sum = $line['sum'];
$opaccount = $account;
// print "Outcome: $oppaccount<br>\n";
}
}
if(($type == MANRECEIPT) || ($type == RECEIPT) || ($type == SUPPLIERPAYMENT) || ($wnum == 0)) {
$opacctname = GetAccountName($opaccount);
$query = "INSERT INTO $tranreptbl VALUES('$prefix', '$lastnum', '$dt', ";
$query .= "'$refnum', '$acctnum', '$acctname', '$opaccount', '$opacctname', '$details', ";
$query .= "'$sum', '0', '0')";
// print "Query: $query<br>\n";
DoQuery($query, "inout1.php");
}
$tc_sum = 0.0;
$td_sum = 0.0;
if($order == '')
$order = 'num';
/* Now take data out of temporary table and display on screen table */
$query = "SELECT * FROM $tranreptbl WHERE prefix='$prefix'";
if($order) {
$query .= " ORDER BY $order";
if($order == 'num')
$query .= " DESC";
}
// print "Query: $query<br>\n";
$result = DoQuery($query, __FILE__.": ".__LINE__);
$e = 0;
$tbody='';
while($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$num = $line['num'];
$dtdmy = FormatDate($line['date'], "mysql", "dmy");
$refnum = substr($line['refnum'], -6);
$acctnum = $line['acctnum'];
$accttype = GetAcctType($line['acctnum']);
$acctname = $line['acctname'];
$opacct = $line['opacct'];
// print "opacct: $opacct<br>\n";
$opacctname = GetAccountName($opacct);
$details = $line['details'];
$sum = $line['total'];
$total_sum += $sum;
if($step == 2) {
fwrite($fd, "$num,$dtmy,\"$opacctname\",\"$refnum\",\"$acctname\",\"$details\",");
if($accttype == SUPPLIER) {
fwrite($fd, "\"\",");
fwrite($fd, "$sum\n");
}
else {
fwrite($fd, "$sum");
fwrite($fd, "\n");
}
}
if($step == 1) {
$tbody.= "<tr>\n";
$tbody.= "<td>$num</td><td>$dtdmy</td><td>";
//if(isset($module)) {
$tbody.= "<a href=\"?module=acctdisp&account=$opacct&begin=$begindate&end=$enddate\">$opacctname</a></td><td> $refnum</td>";
$tbody.= "<td><a href=\"?module=acctdisp&account=$acctnum&begin=$begindate&end=$enddate\">$acctname</a></td>";
}
//else {
// $text.= "$opacctname</td><td> $refnum</td>";
// $text.= "<td>$acctname</td>";
//}
$tbody.= "<td>$details</td>\n";
if($accttype == SUPPLIER) {
$tbody.= "<td> </td>\n";
$tstr = number_format($sum);
$tbody.= "<td dir=\"ltr\" align=\"right\" >$tstr</td>\n";
$td_sum += $sum;
}
else {
$tstr = number_format($sum);
$tbody.= "<td dir=\"ltr\" align=\"right\" >$tstr</td>\n";
$tbody.= "<td> </td>\n";
$tc_sum += $sum;
}
$tbody.= "</tr>\n";
}
}
if($step == 1) {
//if(!isset($module))
$text.= "<tfoot><tr class=\"sumlineprt\">\n";
//else
// $text.= "<tr class=\"sumline\">\n";
$text.= "<td colspan=\"6\" align=\"left\"><b>סה\"כ: </b></td>\n";
$tstr = number_format($tc_sum);
$text.= "<td>$tstr</td>\n";
$tstr = number_format($td_sum);
$text.= "<td>$tstr</td>\n";
$text.= "</tr></tfoot>\n";
$text.= "$tbody</table>\n";
}
else if($step == 2) {
fclose($fd);
Conv1255($filename);
$text.= "<h2>להורדת הדוח לחץ כאן: ";
$url = "download.php?file=$filename&name=inout.csv";
$text.= "<a href=\"$url\">inout.csv</a></h2>\n";
//$//text.= "<h2>לחץ על שם הקובץ עם כפתור ימני ובחר \"שמור בשם\"</h2>\n";
//$text.= "<script type=\"text/javascript\">\n";
//$text.= "setTimeout(\"window.open('$url', 'Download')\", 1000);\n";
//$text.= "</script>\n";
}
if(isset($module) && ($step == 1)) {
$url = "?module=tranrep&print=1&step=1&begindate=$begindate&enddate=$enddate";
$url .= "&prefix=$prefix";
if($order)
$url .= "&order=$order";
$text.= "<div class=\"repbottom\">\n";
//$text.= "<input type=\"button\" value=\"הדפס\" onclick=\"PrintWin('$url')\">\n";
//$text.= " ";
$text.= "<a class=\"btnsmall\" href='?module=inout&step=2&begindate=$begindate&enddate=$enddate'\">יצוא לקובץ</a>\n";
$text.= "</div>\n";
}
//}
createForm($text,$haeder,'',750,'','',1,getHelp());
?>