2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU Affero General Public License,
5 AGPL, as published by the Free Software Foundation, either version
6 3 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/agpl-3.0.html>.
11 ***********************************************************************/
12 /* Author Rob Mallon */
15 include_once($path_to_root . "/includes/session.inc");
17 include_once($path_to_root . "/includes/date_functions.inc");
18 include_once($path_to_root . "/includes/ui.inc");
19 include_once($path_to_root . "/includes/data_checks.inc");
21 include_once($path_to_root . "/gl/includes/gl_db.inc");
22 include_once($path_to_root . "/includes/banking.inc");
25 if (isset($_POST["command"]) && $_POST["command"]=="Reconcile") {
27 $reconcile_id = strtok($_POST["reconcile_idtokens"], "|");
28 while ($reconcile_id !== false) {
29 $formfield="reconcile".$reconcile_id;
30 if (!isset($_POST[$formfield]))
31 $_POST[$formfield] = 0;
32 $reconcile_value=$_POST[$formfield];
33 $sql="UPDATE ".TB_PREF."bank_trans SET reconciled=$reconcile_value WHERE id=$reconcile_id";
34 $result = db_query($sql,"Error setting reconcile flag on trans id $reconcile_id");
35 $reconcile_id = strtok("|");
37 $sql2="UPDATE ".TB_PREF."bank_accounts SET last_reconciled_date='".date2sql($_POST["reconcile_date"])."',
38 ending_reconcile_balance=".$_POST["reconcile_ending_balance"]." WHERE id=".$_POST["bank_account"];
39 $result = db_query($sql2,"Error updating reconciliation information");
43 if ($use_popup_windows)
44 $js .= get_js_open_window(800, 500);
46 $js .= get_js_date_picker();
47 page(_("Reconcile Bank Account"), false, false, "", $js);
51 function handleReconcileClick(form,reconcile_value,reconcile_amount) {
52 var val1=form.reconcile_difference.value*1;
53 val1=(Math.round(val1*100))/100;
54 var val2=reconcile_amount*1;
55 val2=(Math.round(val2*100))/100;
56 var val4=form.reconcile_amount.value*1;
57 val4=(Math.round(val4*100))/100;
59 if (reconcile_value=='1') {
60 val3=(Math.round((val1-val2)*100))/100;
61 form.reconcile_difference.value=val3;
62 val5=(Math.round((val4+val2)*100))/100;
63 form.reconcile_amount.value=val5;
66 val3=(Math.round((val1+val2)*100))/100;
67 form.reconcile_difference.value=val3;
68 val5=(Math.round((val4-val2)*100))/100;
69 form.reconcile_amount.value=val5;
74 function handleReconcileDifference(form) {
75 form.reconcile_difference.value=Number(form.reconcile_ending_balance.value)-Number(form.reconcile_beginning_balance.value);
81 check_db_has_bank_accounts(_("There are no bank accounts defined in the system."));
83 //-----------------------------------------------------------------------------------
88 $Ajax->activate('trans_tbl');
90 //------------------------------------------------------------------------------------------------
93 start_table("class='tablestyle_noborder'");
95 bank_accounts_list_cells(_("Account:"), 'bank_account', null);
97 date_cells(_("From:"), 'TransAfterDate', '', null, -30);
98 date_cells(_("To:"), 'TransToDate');
100 if (!isset($_POST['ShowReconciled']))
101 $_POST['ShowReconciled'] = 0;
102 $show_reconciled = $_POST['ShowReconciled'];
103 yesno_list_cells(_("Show Reconciled:"), 'ShowReconciled');
105 submit_cells('Show',_("Show"),'','', false);
110 $reconcile_sql="SELECT last_reconciled_date,ending_reconcile_balance FROM ".TB_PREF."bank_accounts WHERE id=".$_POST['bank_account'];
111 $reconcile_result = db_query($reconcile_sql,"Error");
112 if ($reconcile_row = db_fetch($reconcile_result)) {
114 start_table("class='tablestyle_noborder'");
116 label_cell("<b>Last Reconciled Date: </b>");
117 label_cell("<b>".sql2date($reconcile_row["last_reconciled_date"])."</b>");
118 label_cell(" ");
119 label_cell("<b>Last Reconciled Ending Balance: </b>");
120 amount_cell($reconcile_row["ending_reconcile_balance"],true);
124 echo "Error: $reconcile_sql<br>";
126 start_form(false,false,"", 'reconcileform');
127 start_table($table_style);
128 $th = array(_("Reconcile Date"), _("Beginning<br>Balance"), _("Ending<br>Balance"), _("Reconciled<br>Amount"), _("Difference"));
131 date_cells("", "reconcile_date");
132 text_cells("", "reconcile_beginning_balance", $reconcile_row["ending_reconcile_balance"], 7, "", false, "", "", "onchange='handleReconcileDifference(this.form);'");
133 text_cells("", "reconcile_ending_balance", 0,7, "", false, "", "", "onchange='handleReconcileDifference(this.form);'");
134 text_cells("", "reconcile_amount", 0, 7, "", false, "", "", "READONLY");
135 text_cells("", "reconcile_difference", 0, 7, "", false, "", "", "READONLY");
139 //------------------------------------------------------------------------------------------------
141 $date_after = date2sql($_POST['TransAfterDate']);
142 $date_to = date2sql($_POST['TransToDate']);
144 if (!isset($_POST['bank_account']))
145 $_POST['bank_account'] = "";
148 $sql = "SELECT ".TB_PREF."bank_trans.* FROM ".TB_PREF."bank_trans
149 WHERE ".TB_PREF."bank_trans.bank_act = '" . $_POST['bank_account'] . "'
150 AND trans_date >= '$date_after'
151 AND trans_date <= '$date_to'";
153 if ($show_reconciled=='0')
154 $sql .= " AND ".TB_PREF."bank_trans.reconciled=0 ";
155 $sql .= " ORDER BY trans_date,".TB_PREF."bank_trans.id";
157 $result = db_query($sql,"The transactions for '" . $_POST['bank_account'] . "' could not be retrieved");
159 div_start('trans_tbl');
160 $act = get_bank_account($_POST["bank_account"]);
161 display_heading($act['bank_account_name']." - ".$act['bank_curr_code']);
165 hidden('command', 'Reconcile');
166 hidden('Show', 'Show');
167 hidden('bank_account', $_POST["bank_account"]);
168 hidden('TransAfterDate',$_POST["TransAfterDate"]);
169 hidden('TransToDate',$_POST["TransToDate"]);
170 hidden('ShowReconciled',$_POST["ShowReconciled"]);
172 start_table($table_style);
174 $th = array(_("Type"), _("#"), _("Reference"), _("Date"),
175 _("Debit"), _("Credit"), _("Person/Item"), "", "X");
178 $k = 0; //row colour counter
179 while ($myrow = db_fetch($result))
181 $idtokens.=$myrow["id"]."|";
182 alt_table_row_color($k);
184 $trandate = sql2date($myrow["trans_date"]);
186 $reconcile_check_name="reconcile".$myrow["id"];
187 label_cell(systypes::name($myrow["type"]));
188 label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"]));
189 label_cell(get_trans_view_str($myrow["type"],$myrow["trans_no"],$myrow['ref']));
190 label_cell($trandate);
191 display_debit_or_credit_cells($myrow["amount"]);
192 //amount_cell($running_total);
193 label_cell(payment_person_types::person_name($myrow["person_type_id"],$myrow["person_id"]));
194 label_cell(get_gl_view_str($myrow["type"], $myrow["trans_no"]));
195 //Added 1/9/09 I needed the javascript action onclick, so I made my own checkbox
197 echo "<input type='checkbox' name='$reconcile_check_name' ";
198 if ($myrow["reconciled"]==1) echo "CHECKED ";
200 echo "onclick=\"javascript:handleReconcileClick(this.form,this.checked,'".$myrow["amount"]."');\">";
202 //check_cells('', $reconcile_check_name, $myrow["reconciled"], false);
204 //Removed by Rob Mallon on 1/8/09
208 // table_header($th);
215 hidden('reconcile_idtokens',$idtokens);
216 submit_center('Reconcile',_("Reconcile"),true,'', false);
221 //------------------------------------------------------------------------------------------------