-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathintmatch.php
More file actions
352 lines (324 loc) · 11.2 KB
/
intmatch.php
File metadata and controls
352 lines (324 loc) · 11.2 KB
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<?PHP
/*
| Accounts transactions match handling script for Drorit Free accounting software
| Written by Ori Idan Helicon technologies Ltd. 2004
|
| This program is a free software licensed under the GPL
*/
if(!isset($prefix) || ($prefix == '')) {
ErrorReport( _("This operation can not be executed without choosing a business first"));
//print "<h1>$l</h1>\n";
return;
}
$text='';
global $accountstbl, $transactionstbl;
global $namecache;
global $TranType;
global $dir;
global $correlationtbl,$curuser;
function PrintAccountSelect() {
global $accountstbl, $prefix;
$type1 = CUSTOMER;
$type2 = SUPPLIER;
$text='';
$query = "SELECT num,company FROM $accountstbl WHERE type='$type1' AND prefix='$prefix' ORDER BY company ASC";
$result = DoQuery($query, __LINE__);
$text.= "<select id=\"account\" name=\"account\">\n";
$l = _("Select account");
$text.= "<option value=\"0\">-- $l --</option>\n";
while($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$num = $line['num'];
$name = stripslashes($line['company']);
$text.= "<option value=\"$num\">$name</option>\n";
}
$query = "SELECT num,company FROM $accountstbl WHERE type='$type2' AND prefix='$prefix' ORDER BY company ASC";
$result = DoQuery($query, __LINE__);
while($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$num = $line['num'];
$name = stripslashes($line['company']);
$text.= "<option value=\"$num\">$name</option>\n";
}
$text.= "</select>\n";
return $text;
}//*/
?>
<script type="text/javascript">
function CalcDebitSum() {
var vals = document.getElementsByClassName('debit');
var sum = document.getElementsByClassName('debit_sum');
var t = document.form1.debit_total;
size = vals.length;
total = parseFloat("0.0");
t.value = '';
if(size) {
for(i = 0; i < size; i++) {
if(vals[i].checked) {
total += parseFloat(sum[i].value);
}
}
}
else {
if(vals.checked)
total = parseFloat(sum.value);
}
t.value = total;
}
function CalcCreditSum() {
var vals = document.getElementsByClassName('credit');
var sum = document.getElementsByClassName('credit_sum');
var t = document.form1.credit_total;
size = vals.length;
total = parseFloat("0.0");
t.value = '';
if(size) {
for(i = 0; i < size; i++) {
if(vals[i].checked) {
total += parseFloat(sum[i].value);
}
}
}
else {
if(vals.checked)
total = parseFloat(sum.value);
}
t.value = total;
}
function goForm(){
$(function() {
$( "#dialog:ui-dialog" ).dialog( "destroy" );
$( "#dialog-confirm" ).dialog({
resizable: false,height:200,width:300,//modal: true,
buttons: {
"Ok": function() {
$( this ).dialog( "close" );
},
"no thanks": function() {
$( this ).dialog( "close" );
}
}
});
});
}
function go(){
var bil=true;//CalcSum();
if(parseFloat($('#credit_total').val())!=parseFloat($('#debit_total').val())){
var sum=(-1)*(parseFloat($('#credit_total').val())-parseFloat($('#debit_total').val()));
var account =parseFloat($('#account').val());
//alert('we r not balanced!');
var dialog = $('<div dir="rtl" id="dialogdiv"></div>').appendTo('body');
dialog.load("?action=lister&form=voucher&sum="+sum+"&acc="+account, {},
function (responseText, textStatus, XMLHttpRequest) {
var agreed = false;
dialog.dialog({resizable: false,height:500,width:780,hide: 'clip',title: ''});
dialog.bind('dialogclose', function(event) {
var acc=$('#account').val();
window.location.href='?module=intmatch&step=1&account='+acc;
});
}
);
bil=false;
}
if(bil)
document.form1.submit();
}
$(document).ready(function(){
$("#form").validate({
submitHandler: function(form) {
go();
}
});
});
</script>
<?PHP
$haeder = _("Accounts reconciliations");
//print "<h3>$l</h3>\n";
$step = isset($_GET['step']) ? $_GET['step'] : 0;
if($step == 2) {
$debit = GetPoster('debit');
$credit = GetPoster('credit');
$account = GetPoster('account');
$debit_str = '';
$total = 0.0;
if(is_array($debit)) {
// $debit = array_unique($debit);
foreach($debit as $val) {
/* $val is transaction number in debit side */
list($num,$id) = explode(":", $val);
$query = "SELECT sum FROM $transactionstbl WHERE num='$val' AND id='$id' AND account='$account' AND prefix='$prefix'";
$result = DoQuery($query,__FILE__.": ".__LINE__);
while($line = mysql_fetch_array($result, MYSQL_NUM)) {
$sum = $line[0];
$total += $sum;
//print "sum: $sum<br />\n";
if(!empty($debit_str))
$debit_str .= ',';
$debit_str .= $val;
}
}
}
//print "total: $total<br />\n";
$credit_str = '';
if(is_array($credit)) {
// $credit = array_unique($credit);
foreach($credit as $val) {
/* $val is transaction number in debit side */
list($num,$id) = explode(":", $val);
$query = "SELECT sum FROM $transactionstbl WHERE num='$val' AND id='$id' AND account='$account' AND prefix='$prefix'";
//print $query."<br />\n";
$result = DoQuery($query,__FILE__.": ".__LINE__);
while($line = mysql_fetch_array($result, MYSQL_NUM)) {
$sum = $line[0];
//print "sum: $sum<br />\n";
$total += $sum;
if(!empty($credit_str))
$credit_str .= ',';
$credit_str .= $val;
}
}
}
//print "total: $total<br />\n";
// print "debit_str: $debit_str<BR>\n";
// print "credit_str: $credit_str<BR>\n";
if(($total > 0.01) || ($total < -0.01)) {
$l = _("Unbalanced reconciliation");
ErrorReport($l);
exit;
}
/* balanced match so put debit_str for all credit side transactions and credit_str for all debit side */
// print_r($credit);
// print_r($debit);
// print "<BR>debit: $debit_str<BR>credit: $credit_str<BR>\n";
$cor_num=maxSql(array('prefix'=>$prefix), "num", $correlationtbl);
$uid=$curuser->id;
$query = "INSERT INTO $correlationtbl VALUES ('$prefix', '$cor_num', '$debit_str', '$credit_str', '".OPEN."', '$uid');";
DoQuery($query, __FILE__.":".__LINE__);
foreach($credit as $val) {
list($num,$id) = explode(":", $val);
$query = "UPDATE $transactionstbl SET cor_num='$cor_num' ";
$query .= "WHERE num='$num' AND id='$id' AND account='$account' AND prefix='$prefix'";
// print "Query: $query<BR>\n";
$result = DoQuery($query,__FILE__.": ".__LINE__);
}
foreach($debit as $val) {
list($num,$id) = explode(":", $val);
$query = "UPDATE $transactionstbl SET cor_num='$cor_num' ";
$query .= "WHERE num='$num' AND id='$id' AND account='$account' AND prefix='$prefix'";
$result = DoQuery($query,__FILE__.": ".__LINE__);
}
$step = 1;
}
if($step == 1) {
$account = GetPoster('account');
if($account == 0) {
$l = _("No account chosen");
ErrorReport($l);
exit;
}
//adam:?
//print "</div>\n"; /* end of righthalf */
//print "<div class=\"form innercontent\">\n";
$l = _("Account");
$text.= "<h2>$l: \n";
$text.= GetAccountName($account);
$text.= "</h2>\n";
$text.= "<form id=\"form\" name=\"form1\" action=\"?module=intmatch&step=2\" method=\"post\">\n";
$text.= "<input type=\"hidden\" id=\"account\" name=\"account\" value=\"$account\" />\n";
$text.= "<table><tr>\n";
$l = _("Debit transactions");
$text.= "<td align=\"right\"><h2>$l</h2></td>\n";
$text.= "<td style=\"background:white\"> </td>\n";
$l = _("Credit transactions");
$text.= "<td align=\"right\"><h2>$l</h2></td>\n";
$text.= "</tr><tr><td valign=\"top\">\n";
$text.= "<table class=\"formy\" border=\"1\"><tr>\n";
$text.= "<th> </th>\n";
$l = _("Tran. type");
$text.= "<th>$l</th>\n";
$l = _("Date");
$text.= "<th>$l</th>\n";
$l = _("Ref. num");
$text.= "<th>$l</th>\n";
$l = _("Sum");
$text.= "<th>$l</th>\n";
$text.= "</tr>\n";
/* Now the actual work of printing transactions in debit side */
$query = "SELECT * FROM $transactionstbl WHERE account='$account' AND sum<0 AND prefix='$prefix'";
$result = DoQuery($query, __LINE__);
while($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$cor = $line['cor_num'];
if(($cor != '') && ($cor != 0))
continue;
$num = $line['num'];
$id = $line['id'];
$type_str = $TranType[$line['type']];
$date = FormatDate($line['date'], "mysql", "dmy");
$refnum = $line['refnum1'];
$sum = $line['sum'];
$sum *= -1.0;
$text.= "<tr>\n";
$text.= "<td><input type=\"checkbox\" class=\"debit\" name=\"debit[]\" value=\"$num:$id\" onchange=\"CalcDebitSum()\"></td>\n";
$text.= "<td>$type_str</td>\n";
$text.= "<td>$date</td>\n";
$text.= "<td>$refnum</td>\n";
$text.= "<td>$sum</td><input type=\"hidden\" class=\"debit_sum name=\"debit_sum[]\" value=\"$sum\"></TD>\n";
$text.= "</tr>\n";
}
$text.= "<tr><td colspan=\"4\"> </td>\n";
$text.= "<td><input type=\"text\" id=\"debit_total\" name=\"debit_total\" value=\"0\" size=\"5\" readonly></td></tr>\n";
$text.= "</table>\n";
$text.= "<td style=\"background:white\"> </td>\n";
$text.= "</td><td valign=\"top\">\n";
$text.= "<table class=\"formy\" border=\"1\"><tr>\n";
$text.= "<th> </th>\n";
$l = _("Tran. type");
$text.= "<th>$l</th>\n";
$l = _("Date");
$text.= "<th>$l</th>\n";
$l = _("Ref. num");
$text.= "<th>$l</th>\n";
$l = _("Sum");
$text.= "<th>$l</th>\n";
$text.= "</tr>\n";
/* Now the actual work of printing transactions in credit side */
$query = "SELECT * FROM $transactionstbl WHERE account='$account' AND sum>0 AND prefix='$prefix'";
$result = DoQuery($query,__FILE__.": ".__LINE__);
while($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$cor = $line['cor_num'];
if(($cor != '') && ($cor != 0))
continue;
$num = $line['num'];
$id = $line['id'];
$type_str = $TranType[$line['type']];
$date = FormatDate($line['date'], "mysql", "dmy");
$refnum = $line['refnum1'];
$sum = $line['sum'];
$text.= "<tr>\n";
$text.= "<td><input type=\"checkbox\" class=\"credit\" name=\"credit[]\" value=\"$num:$id\" onchange=\"CalcCreditSum()\" /></td>\n";
$text.= "<td>$type_str</td>\n";
$text.= "<td>$date</td>\n";
$text.= "<td>$refnum</td>\n";
$text.= "<td>$sum<input type=\"hidden\" class=\"credit_sum\" name=\"credit_sum[]\" value=\"$sum\" /></td>\n";
$text.= "</tr>\n";
}
$text.= "<tr><td colspan=\"4\"> </td>\n";
$text.= "<td><input type=\"text\" id=\"credit_total\" name=\"credit_total\" value=\"0\" size=\"5\" readonly /></td></tr>\n";
$text.= "</table>\n";
$text.= "</td></tr>\n";
$l = _("Reconciliate");
$text.= "<tr><td colspan=\"3\" align=\"center\"><input type=\"submit\" value=\"$l\" class='btnaction' /></td></tr>\n";
$text.= "</table>\n";
$text.= "</form>\n";
//print "</div>\n";
//print "<div class=\"form righthalf1\">\n";
}
$text.= '<form name="form2" action="?module=intmatch&step=1" method="post"><table border="0" width="100%" class="formtbl">';
$l = _("Select account");
$text.= "<tr><td>$l: </td>\n";
$text.= '<td>';
$text.= PrintAccountSelect();
$text.= '</td></tr><tr><td> </td></tr>';
$l = _("Select");
$text.= "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"$l\" class='btnaction' /></td></tr>\n";
$text.= '</table></form>';
createForm($text,$haeder,'',750,'','',1,getHelp());
?>