- modules/fotolab updated imagej to current version & some cod fixes to make it work
[care2x.git] / Care2007 / modules / weberp / TaxAuthorities.php
blob932cb80117b5bf3bb46273a820f57db4ea13b327
1 <?php
3 /* $Revision: 1.15 $ */
6 $PageSecurity=15;
7 include('includes/session.inc');
8 $title = _('Tax Authorities');
9 include('includes/header.inc');
12 if (isset($_POST['SelectedTaxAuthID'])){
13 $SelectedTaxAuthID =$_POST['SelectedTaxAuthID'];
14 } elseif(isset($_GET['SelectedTaxAuthID'])){
15 $SelectedTaxAuthID =$_GET['SelectedTaxAuthID'];
19 if (isset($_POST['submit'])) {
21 /* actions to take once the user has clicked the submit button
22 ie the page has called itself with some user input */
23 if ( trim( $_POST['Description'] ) == '' ) {
24 $InputError = 1;
25 prnMsg( _('The tax type description may not be empty'), 'error');
28 if (isset($SelectedTaxAuthID)) {
30 /*SelectedTaxAuthID could also exist if submit had not been clicked this code
31 would not run in this case cos submit is false of course see the
32 delete code below*/
34 $sql = 'UPDATE taxauthorities
35 SET taxglcode =' . $_POST['TaxGLCode'] . ',
36 purchtaxglaccount =' . $_POST['PurchTaxGLCode'] . ",
37 description = '" . DB_escape_string($_POST['Description']) . "',
38 bank = '".DB_escape_string($_POST['Bank'])."',
39 bankacctype = '".DB_escape_string($_POST['BankAccType'])."',
40 bankacc = '".DB_escape_string($_POST['BankAcc'])."',
41 bankswift = '".DB_escape_string($_POST['BankSwift'])."'
42 WHERE taxid = " . $SelectedTaxAuthID;
44 $ErrMsg = _('The update of this tax authority failed because');
45 $result = DB_query($sql,$db,$ErrMsg);
47 $msg = _('The tax authority for record has been updated');
49 } elseif ($InputError !=1) {
51 /*Selected tax authority is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new tax authority form */
53 $sql = "INSERT INTO taxauthorities (
54 taxglcode,
55 purchtaxglaccount,
56 description,
57 bank,
58 bankacctype,
59 bankacc,
60 bankswift)
61 VALUES (
62 " . $_POST['TaxGLCode'] . ",
63 " . $_POST['PurchTaxGLCode'] . ",
64 '" .DB_escape_string($_POST['Description']) . "',
65 '" .DB_escape_string($_POST['Bank']) . "',
66 '" .DB_escape_string($_POST['BankAccType']) . "',
67 '" .DB_escape_string($_POST['BankAcc']) . "',
68 '" .DB_escape_string($_POST['BankSwift']) . "'
69 )";
71 $Errmsg = _('The addition of this tax authority failed because');
72 $result = DB_query($sql,$db,$ErrMsg);
74 $msg = _('The new tax authority record has been added to the database');
76 $NewTaxID = DB_Last_Insert_ID($db,'taxauthorities','taxid');
78 $sql = 'INSERT INTO taxauthrates (
79 taxauthority,
80 dispatchtaxprovince,
81 taxcatid
83 SELECT
84 ' . $NewTaxID . ',
85 taxprovinces.taxprovinceid,
86 taxcategories.taxcatid
87 FROM taxprovinces,
88 taxcategories';
90 $InsertResult = DB_query($sql,$db);
92 //run the SQL from either of the above possibilites
93 if ($InputError !=1) {
94 unset( $_POST['TaxGLCode']);
95 unset( $_POST['PurchTaxGLCode']);
96 unset( $_POST['Description']);
97 unset( $SelectedTaxID );
100 prnMsg($msg);
102 } elseif (isset($_GET['delete'])) {
103 //the link to delete a selected record was clicked instead of the submit button
105 // PREVENT DELETES IF DEPENDENT RECORDS IN OTHER TABLES
107 $sql= 'SELECT COUNT(*)
108 FROM taxgrouptaxes
109 WHERE taxauthid=' . $SelectedTaxAuthID;
111 $result = DB_query($sql,$db);
112 $myrow = DB_fetch_row($result);
113 if ($myrow[0]>0) {
114 prnmsg(_('Cannot delete this tax authority because there are tax groups defined that use it'),'warn');
115 } else {
116 /*Cascade deletes in TaxAuthLevels */
117 $result = DB_query('DELETE FROM taxauthrates WHERE taxauthority= ' . $SelectedTaxAuthID,$db);
118 $result = DB_query('DELETE FROM taxauthorities WHERE taxid= ' . $SelectedTaxAuthID,$db);
119 prnMsg(_('The selected tax authority record has been deleted'),'success');
120 unset ($SelectedTaxAuthID);
121 } // end of related records testing
124 if (!isset($SelectedTaxAuthID)) {
126 /* It could still be the second time the page has been run and a record has been selected for modification - SelectedTaxAuthID will exist because it was sent with the new call. If its the first time the page has been displayed with no parameters then none of the above are true and the list of tax authorities will be displayed with links to delete or edit each. These will call the same page again and allow update/input or deletion of the records*/
128 $sql = 'SELECT taxid,
129 description,
130 taxglcode,
131 purchtaxglaccount,
132 bank,
133 bankacc,
134 bankacctype,
135 bankswift
136 FROM taxauthorities';
138 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The defined tax authorities could not be retrieved because');
139 $DbgMsg = _('The following SQL to retrieve the tax authorities was used');
140 $result = DB_query($sql,$db,$ErrMsg,$DbgMsg);
142 echo '<CENTER><table border=1>';
143 echo "<tr>
144 <td class='tableheader'>" . _('ID') . "</td>
145 <td class='tableheader'>" . _('Description') . "</td>
146 <td class='tableheader'>" . _('Input Tax') . '<BR>' . _('GL Account') . "</td>
147 <td class='tableheader'>" . _('Output Tax') . '<BR>' . _('GL Account') . "</td>
148 <td class='tableheader'>" . _('Bank') . "</td>
149 <td class='tableheader'>" . _('Bank Account') . "</td>
150 <td class='tableheader'>" . _('Bank Act Type') . "</td>
151 <td class='tableheader'>" . _('Bank Swift') . "</td>
152 </tr></FONT>";
154 while ($myrow = DB_fetch_row($result)) {
156 printf("<tr><td>%s</td>
157 <td>%s</td>
158 <td>%s</td>
159 <td>%s</td>
160 <td>%s</td>
161 <td>%s</td>
162 <td>%s</td>
163 <td>%s</td>
164 <td><td><a href=\"%s&TaxAuthority=%s\">" . _('Edit Rates') . "</a></td>
165 <td><a href=\"%s&SelectedTaxAuthID=%s\">" . _('Edit') . "</a></td>
166 <td><a href=\"%s&SelectedTaxAuthID=%s&delete=yes\">" . _('Delete') . '</a></td>
167 </tr>',
168 $myrow[0],
169 $myrow[1],
170 $myrow[3],
171 $myrow[2],
172 $myrow[4],
173 $myrow[5],
174 $myrow[6],
175 $myrow[7],
176 $rootpath . '/TaxAuthorityRates.php?' . SID,
177 $myrow[0],
178 $_SERVER['PHP_SELF'] . '?' . SID,
179 $myrow[0],
180 $_SERVER['PHP_SELF'] . '?' . SID,
181 $myrow[0]);
184 //END WHILE LIST LOOP
186 //end of ifs and buts!
188 echo '</table></CENTER><p>';
193 if (isset($SelectedTaxAuthID)) {
194 echo "<Center><a href='" . $_SERVER['PHP_SELF'] . '?' . SID ."'>" . _('Reveiw all defined tax authority records') . '</a></Center>';
198 echo "<P><FORM METHOD='post' action=" . $_SERVER['PHP_SELF'] . '?' . SID .'>';
200 if (isset($SelectedTaxAuthID)) {
201 //editing an existing tax authority
203 $sql = 'SELECT taxglcode,
204 purchtaxglaccount,
205 description,
206 bank,
207 bankacc,
208 bankacctype,
209 bankswift
210 FROM taxauthorities
211 WHERE taxid=' . $SelectedTaxAuthID;
213 $result = DB_query($sql, $db);
214 $myrow = DB_fetch_array($result);
216 $_POST['TaxGLCode'] = $myrow['taxglcode'];
217 $_POST['PurchTaxGLCode']= $myrow['purchtaxglaccount'];
218 $_POST['Description'] = $myrow['description'];
219 $_POST['Bank'] = $myrow['bank'];
220 $_POST['BankAccType'] = $myrow['bankacctype'];
221 $_POST['BankAcc'] = $myrow['bankacc'];
222 $_POST['BankSwift'] = $myrow['bankswift'];
225 echo "<INPUT TYPE=HIDDEN NAME='SelectedTaxAuthID' VALUE=" . $SelectedTaxAuthID . '>';
227 } //end of if $SelectedTaxAuthID only do the else when a new record is being entered
230 $SQL = 'SELECT accountcode,
231 accountname
232 FROM chartmaster,
233 accountgroups
234 WHERE chartmaster.group_=accountgroups.groupname
235 AND accountgroups.pandl=0
236 ORDER BY accountcode';
237 $result = DB_query($SQL,$db);
239 echo '<CENTER><TABLE>
240 <TR><TD>' . _('Tax Type Description') . ":</TD>
241 <TD><input type=Text name='Description' SIZE=21 MAXLENGTH=20 value='" . $_POST['Description'] . "'></TD></TR>";
244 echo '<TR><TD>' . _('Input tax GL Account') . ':</TD>
245 <TD><SELECT name=PurchTaxGLCode>';
247 while ($myrow = DB_fetch_array($result)) {
248 if ($myrow['accountcode']==$_POST['PurchTaxGLCode']) {
249 echo '<OPTION SELECTED VALUE=';
250 } else {
251 echo '<OPTION VALUE=';
253 echo $myrow['accountcode'] . '>' . $myrow['accountname'] . ' ('.$myrow['accountcode'].')';
255 } //end while loop
257 echo '</SELECT></TD></TR>';
259 DB_data_seek($result,0);
261 echo '<TR><TD>' . _('Output tax GL Account') . ':</TD>
262 <TD><SELECT name=TaxGLCode>';
265 while ($myrow = DB_fetch_array($result)) {
266 if ($myrow['accountcode']==$_POST['TaxGLCode']) {
267 echo "<OPTION SELECTED VALUE='";
268 } else {
269 echo "<OPTION VALUE='";
271 echo $myrow['accountcode'] . "'>" . $myrow['accountname'] . ' ('.$myrow['accountcode'].')';
273 } //end while loop
277 echo '</SELECT></TD></TR>';
278 echo '<TR><TD>' . _('Bank Name') . ':</TD>';
279 echo '<TD><input type=Text name="Bank" SIZE=41 MAXLENGTH=40 value="' . $_POST['Bank'] . '"></TD></TR>';
280 echo '<TR><TD>' . _('Bank Account Type') . ':</TD>';
281 echo '<TD><input type=Text name="BankAccType" SIZE=15 MAXLENGTH=20 value="' . $_POST['BankAccType'] . '"></TD></TR>';
282 echo '<TR><TD>' . _('Bank Account') . ':</TD>';
283 echo '<TD><input type=Text name="BankAcc" SIZE=21 MAXLENGTH=20 value="' . $_POST['BankAcc'] . '"></TD></TR>';
284 echo '<TR><TD>' . _('Bank Swift No') . ':</TD>';
285 echo '<TD><input type=Text name="BankSwift" SIZE=15 MAXLENGTH=14 value="' . $_POST['BankSwift'] . '"></TD></TR>';
287 echo '</TABLE>';
289 echo '<input type=submit name=submit value=' . _('Enter Information') . '></CENTER></FORM>';
291 include('includes/footer.inc');