| [ PHPXref.com ] | [ Generated: Sun Jul 20 21:01:50 2008 ] | [ webERP 3.0.4 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /* $Revision: 1.2 $ */ 3 4 $PageSecurity = 15; 5 6 include ('includes/session.inc'); 7 8 $title = _('Tax Categories'); 9 10 include ('includes/header.inc'); 11 12 if ( isset($_GET['SelectedTaxCategory']) ) 13 $SelectedTaxCategory = $_GET['SelectedTaxCategory']; 14 elseif (isset($_POST['SelectedTaxCategory'])) 15 $SelectedTaxCategory = $_POST['SelectedTaxCategory']; 16 17 if (isset($_POST['submit'])) { 18 19 //initialise no input errors assumed initially before we test 20 21 $InputError = 0; 22 23 /* actions to take once the user has clicked the submit button 24 ie the page has called itself with some user input */ 25 26 //first off validate inputs sensible 27 28 if (strpos($_POST['TaxCategoryName'],'&')>0 OR strpos($_POST['TaxCategoryName'],"'")>0) { 29 $InputError = 1; 30 prnMsg( _('The tax category name cannot contain the character') . " '&' " . _('or the character') ." '",'error'); 31 } 32 if (trim($_POST['TaxCategoryName']) == '') { 33 $InputError = 1; 34 prnMsg( _('The tax category name may not be empty'), 'error'); 35 } 36 37 if ($_POST['SelectedTaxCategory']!='' AND $InputError !=1) { 38 39 /*SelectedTaxCategory could also exist if submit had not been clicked this code would not run in this case cos submit is false of course see the delete code below*/ 40 // Check the name does not clash 41 $sql = "SELECT count(*) FROM taxcategories 42 WHERE taxcatid <> " . $SelectedTaxCategory ." 43 AND taxcatname ".LIKE." '" . $_POST['TaxCategoryName'] . "'"; 44 $result = DB_query($sql,$db); 45 $myrow = DB_fetch_row($result); 46 if ( $myrow[0] > 0 ) { 47 $InputError = 1; 48 prnMsg( _('The tax category cannot be renamed because another with the same name already exists.'),'error'); 49 } else { 50 // Get the old name and check that the record still exists 51 52 $sql = "SELECT taxcatname FROM taxcategories 53 WHERE taxcatid = " . $SelectedTaxCategory; 54 $result = DB_query($sql,$db); 55 if ( DB_num_rows($result) != 0 ) { 56 // This is probably the safest way there is 57 $myrow = DB_fetch_row($result); 58 $OldTaxCategoryName = $myrow[0]; 59 $sql = "UPDATE taxcategories 60 SET taxcatname='" . DB_escape_string($_POST['TaxCategoryName']) . "' 61 WHERE taxcatname ".LIKE." '".$OldTaxCategoryName."'"; 62 $ErrMsg = _('The tax category could not be updated'); 63 $result = DB_query($sql,$db,$ErrMsg); 64 } else { 65 $InputError = 1; 66 prnMsg( _('The tax category no longer exists'),'error'); 67 } 68 } 69 $msg = _('Tax category name changed'); 70 } elseif ($InputError !=1) { 71 /*SelectedTaxCategory is null cos no item selected on first time round so must be adding a record*/ 72 $sql = "SELECT count(*) FROM taxcategories 73 WHERE taxcatname " .LIKE. " '".$_POST['TaxCategoryName'] ."'"; 74 $result = DB_query($sql,$db); 75 $myrow = DB_fetch_row($result); 76 if ( $myrow[0] > 0 ) { 77 $InputError = 1; 78 prnMsg( _('The tax category cannot be created because another with the same name already exists'),'error'); 79 } else { 80 $result = DB_query('BEGIN',$db); 81 $sql = "INSERT INTO taxcategories ( 82 taxcatname ) 83 VALUES ( 84 '" . DB_escape_string($_POST['TaxCategoryName']) ."' 85 )"; 86 $ErrMsg = _('The new tax category could not be added'); 87 $result = DB_query($sql,$db,$ErrMsg,true); 88 89 $LastTaxCatID = DB_Last_Insert_ID($db, 'taxcategories','taxcatid'); 90 91 $sql = 'INSERT INTO taxauthrates (taxauthority, 92 dispatchtaxprovince, 93 taxcatid) 94 SELECT taxauthorities.taxid, 95 taxprovinces.taxprovinceid, 96 ' . $LastTaxCatID . ' 97 FROM taxauthorities, taxprovinces'; 98 $result = DB_query($sql,$db,$ErrMsg,true); 99 100 $result = DB_query('COMMIT',$db); 101 } 102 $msg = _('New tax category added'); 103 } 104 105 if ($InputError!=1){ 106 prnMsg($msg,'success'); 107 } 108 unset ($SelectedTaxCategory); 109 unset ($_POST['SelectedTaxCategory']); 110 unset ($_POST['TaxCategoryName']); 111 112 } elseif (isset($_GET['delete'])) { 113 //the link to delete a selected record was clicked instead of the submit button 114 // PREVENT DELETES IF DEPENDENT RECORDS IN 'stockmaster' 115 // Get the original name of the tax category the ID is just a secure way to find the tax category 116 $sql = "SELECT taxcatname FROM taxcategories 117 WHERE taxcatid = " . DB_escape_string($SelectedTaxCategory); 118 $result = DB_query($sql,$db); 119 if ( DB_num_rows($result) == 0 ) { 120 // This is probably the safest way there is 121 prnMsg( _('Cannot delete this tax category because it no longer exists'),'warn'); 122 } else { 123 $myrow = DB_fetch_row($result); 124 $OldTaxCategoryName = $myrow[0]; 125 $sql= "SELECT COUNT(*) FROM stockmaster WHERE taxcatid ".LIKE." '" . DB_escape_string($OldTaxCategoryName) . "'"; 126 $result = DB_query($sql,$db); 127 $myrow = DB_fetch_row($result); 128 if ($myrow[0]>0) { 129 prnMsg( _('Cannot delete this tax category because inventory items have been created using this tax category'),'warn'); 130 echo '<br>' . _('There are') . ' ' . $myrow[0] . ' ' . _('inventory items that refer to this tax category') . '</FONT>'; 131 } else { 132 $sql = 'DELETE FROM taxauthrates WHERE taxcatid = ' . $SelectedTaxCategory; 133 $result = DB_query($sql,$db); 134 $sql = 'DELETE FROM taxcategories WHERE taxcatid = ' .$SelectedTaxCategory;; 135 $result = DB_query($sql,$db); 136 prnMsg( $OldTaxCategoryName . ' ' . _('tax category and any tax rates set for it have been deleted'),'success'); 137 } 138 } //end if 139 unset ($SelectedTaxCategory); 140 unset ($_GET['SelectedTaxCategory']); 141 unset($_GET['delete']); 142 unset ($_POST['SelectedTaxCategory']); 143 unset ($_POST['TaxCategoryName']); 144 } 145 146 if (!isset($SelectedTaxCategory)) { 147 148 /* An tax category could be posted when one has been edited and is being updated 149 or GOT when selected for modification 150 SelectedTaxCategory will exist because it was sent with the page in a GET . 151 If its the first time the page has been displayed with no parameters 152 then none of the above are true and the list of account groups will be displayed with 153 links to delete or edit each. These will call the same page again and allow update/input 154 or deletion of the records*/ 155 156 $sql = "SELECT taxcatid, 157 taxcatname 158 FROM taxcategories 159 ORDER BY taxcatid"; 160 161 $ErrMsg = _('Could not get tax categories because'); 162 $result = DB_query($sql,$db,$ErrMsg); 163 164 echo "<CENTER><TABLE> 165 <TR> 166 <TD class='tableheader'>" . _('Tax Categories') . "</TD> 167 </TR>"; 168 169 $k=0; //row colour counter 170 while ($myrow = DB_fetch_row($result)) { 171 172 if ($k==1){ 173 echo "<TR BGCOLOR='#CCCCCC'>"; 174 $k=0; 175 } else { 176 echo "<TR BGCOLOR='#EEEEEE'>"; 177 $k++; 178 } 179 180 echo '<TD>' . $myrow[1] . '</TD>'; 181 echo '<TD><A HREF="' . $_SERVER['PHP_SELF'] . '?' . SID . '&SelectedTaxCategory=' . $myrow[0] . '">' . _('Edit') . '</A></TD>'; 182 echo '<TD><A HREF="' . $_SERVER['PHP_SELF'] . '?' . SID . '&SelectedTaxCategory=' . $myrow[0] . '&delete=1">' . _('Delete') .'</A></TD>'; 183 echo '</TR>'; 184 185 } //END WHILE LIST LOOP 186 echo '</table></CENTER><p>'; 187 } //end of ifs and buts! 188 189 190 if (isset($SelectedTaxCategory)) { 191 echo '<CENTER><A HREF=' . $_SERVER['PHP_SELF'] . '?' . SID .'>' . _('Review Tax Categories') . '</A></CENTER>'; 192 } 193 194 echo '<P>'; 195 196 if (! isset($_GET['delete'])) { 197 198 echo "<FORM METHOD='post' action=" . $_SERVER['PHP_SELF'] . '?' . SID . '>'; 199 200 if (isset($SelectedTaxCategory)) { 201 //editing an existing section 202 203 $sql = "SELECT taxcatid, 204 taxcatname 205 FROM taxcategories 206 WHERE taxcatid=" . DB_escape_string($SelectedTaxCategory); 207 208 $result = DB_query($sql, $db); 209 if ( DB_num_rows($result) == 0 ) { 210 prnMsg( _('Could not retrieve the requested tax category, please try again.'),'warn'); 211 unset($SelectedTaxCategory); 212 } else { 213 $myrow = DB_fetch_array($result); 214 215 $_POST['TaxCategoryName'] = $myrow['taxcatname']; 216 217 echo "<INPUT TYPE=HIDDEN NAME='SelectedTaxCategory' VALUE='" . $myrow['taxcatid'] . "'>"; 218 echo "<CENTER><TABLE>"; 219 } 220 221 } else { 222 $_POST['TaxCategoryName']=''; 223 echo "<CENTER><TABLE>"; 224 } 225 echo "<TR> 226 <TD>" . _('Tax Category Name') . ':' . "</TD> 227 <TD><input type='Text' name='TaxCategoryName' SIZE=30 MAXLENGTH=30 value='" . $_POST['TaxCategoryName'] . "'></TD> 228 </TR>"; 229 echo '</TABLE>'; 230 231 echo '<CENTER><input type=Submit name=submit value=' . _('Enter Information') . '>'; 232 233 echo '</FORM>'; 234 235 } //end if record deleted no point displaying form to add record 236 237 include ('includes/footer.inc'); 238 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |