3 /* $Revision: 1.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'] ) == '' ) {
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
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 (
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']) . "'
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 (
85 taxprovinces.taxprovinceid,
86 taxcategories.taxcatid
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 );
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(*)
109 WHERE taxauthid=' . $SelectedTaxAuthID;
111 $result = DB_query($sql,$db);
112 $myrow = DB_fetch_row($result);
114 prnmsg(_('Cannot delete this tax authority because there are tax groups defined that use it'),'warn');
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,
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>';
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>
154 while ($myrow = DB_fetch_row($result)) {
156 printf("<tr><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>
176 $rootpath . '/TaxAuthorityRates.php?' . SID
,
178 $_SERVER['PHP_SELF'] . '?' . SID
,
180 $_SERVER['PHP_SELF'] . '?' . SID
,
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,
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,
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=';
251 echo '<OPTION VALUE=';
253 echo $myrow['accountcode'] . '>' . $myrow['accountname'] . ' ('.$myrow['accountcode'].')';
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='";
269 echo "<OPTION VALUE='";
271 echo $myrow['accountcode'] . "'>" . $myrow['accountname'] . ' ('.$myrow['accountcode'].')';
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>';
289 echo '<input type=submit name=submit value=' . _('Enter Information') . '></CENTER></FORM>';
291 include('includes/footer.inc');