From: <tim...@us...> - 2010-06-26 15:02:48
|
Revision: 3527 http://web-erp.svn.sourceforge.net/web-erp/?rev=3527&view=rev Author: tim_schofield Date: 2010-06-26 15:02:41 +0000 (Sat, 26 Jun 2010) Log Message: ----------- Add the ability to have supplier types. Modified Paths: -------------- trunk/Suppliers.php trunk/doc/Change.log.html trunk/sql/mysql/upgrade3.11.1-3.12.sql Added Paths: ----------- trunk/SupplierTypes.php Added: trunk/SupplierTypes.php =================================================================== --- trunk/SupplierTypes.php (rev 0) +++ trunk/SupplierTypes.php 2010-06-26 15:02:41 UTC (rev 3527) @@ -0,0 +1,256 @@ +<?php +/* $Revision: 1.6 $ */ +/* $Id$*/ + +$PageSecurity = 4; + +include('includes/session.inc'); +$title = _('Supplier Types') . ' / ' . _('Maintenance'); +include('includes/header.inc'); + +if (isset($_POST['SelectedType'])){ + $SelectedType = strtoupper($_POST['SelectedType']); +} elseif (isset($_GET['SelectedType'])){ + $SelectedType = strtoupper($_GET['SelectedType']); +} + +if (isset($Errors)) { + unset($Errors); +} + +$Errors = array(); + +echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/maintenance.png" title="' . _('Supplier Types') + . '" alt="">' . _('Supplier Type Setup') . '</p>'; +echo '<div class="page_help_text">' . _('Add/edit/delete Supplier Types') . '</div><br>'; + +if (isset($_POST['submit'])) { + + //initialise no input errors assumed initially before we test + $InputError = 0; + + /* actions to take once the user has clicked the submit button + ie the page has called itself with some user input */ + + //first off validate inputs sensible + $i=1; + if (strlen($_POST['typename']) >100) { + $InputError = 1; + echo prnMsg(_('The supplier type name description must be 100 characters or less long'),'error'); + $Errors[$i] = 'SupplierType'; + $i++; + } + + if (strlen($_POST['typename'])==0) { + $InputError = 1; + echo prnMsg(_('The supplier type name description must contain at least one character'),'error'); + $Errors[$i] = 'SupplierType'; + $i++; + } + + $checksql = "SELECT count(*) + FROM suppliertype + WHERE typename = '" . $_POST['typename'] . "'"; + $checkresult=DB_query($checksql, $db); + $checkrow=DB_fetch_row($checkresult); + if ($checkrow[0]>0) { + $InputError = 1; + echo prnMsg(_('You already have a supplier type called').' '.$_POST['typename'],'error'); + $Errors[$i] = 'SupplierName'; + $i++; + } + + if (isset($SelectedType) AND $InputError !=1) { + + $sql = "UPDATE suppliertype + SET typename = '" . $_POST['typename'] . "' + WHERE typeid = '$SelectedType'"; + + $msg = _('The supplier type') . ' ' . $SelectedType . ' ' . _('has been updated'); + } elseif ( $InputError !=1 ) { + + // First check the type is not being duplicated + + $checkSql = "SELECT count(*) + FROM suppliertype + WHERE typeid = '" . $_POST['typeid'] . "'"; + + $checkresult = DB_query($checkSql,$db); + $checkrow = DB_fetch_row($checkresult); + + if ( $checkrow[0] > 0 ) { + $InputError = 1; + prnMsg( _('The supplier type ') . $_POST['typeid'] . _(' already exist.'),'error'); + } else { + + // Add new record on submit + + $sql = "INSERT INTO suppliertype + (typename) + VALUES ('" . $_POST['typename'] . "')"; + + + $msg = _('Supplier type') . ' ' . $_POST["typename"] . ' ' . _('has been created'); + $checkSql = "SELECT count(typeid) + FROM suppliertype"; + $result = DB_query($checkSql, $db); + $row = DB_fetch_row($result); + + } + } + + if ( $InputError !=1) { + //run the SQL from either of the above possibilites + $result = DB_query($sql,$db); + + + // Fetch the default price list. + $sql = "SELECT confvalue + FROM config + WHERE confname='DefaultSupplierType'"; + $result = DB_query($sql,$db); + $SupplierTypeRow = DB_fetch_row($result); + $DefaultSupplierType = $SupplierTypeRow[0]; + + // Does it exist + $checkSql = "SELECT count(*) + FROM suppliertype + WHERE typeid = '" . $DefaultSupplierType . "'"; + $checkresult = DB_query($checkSql,$db); + $checkrow = DB_fetch_row($checkresult); + + // If it doesnt then update config with newly created one. + if ($checkrow[0] == 0) { + $sql = "UPDATE config + SET confvalue='" . $_POST['typeid'] . "' + WHERE confname='DefaultSupplierType'"; + $result = DB_query($sql,$db); + $_SESSION['DefaultSupplierType'] = $_POST['typeid']; + } + + prnMsg($msg,'success'); + + unset($SelectedType); + unset($_POST['typeid']); + unset($_POST['typename']); + } + +} elseif ( isset($_GET['delete']) ) { + + $sql = "SELECT COUNT(*) FROM suppliers WHERE supptype='$SelectedType'"; + + $ErrMsg = _('The number of suppliers using this Type record could not be retrieved because'); + $result = DB_query($sql,$db,$ErrMsg); + $myrow = DB_fetch_row($result); + if ($myrow[0]>0) { + prnMsg (_('Cannot delete this type because suppliers are currently set up to use this type') . '<br>' . + _('There are') . ' ' . $myrow[0] . ' ' . _('suppliers with this type code')); + } else { + + $sql="DELETE FROM suppliertype WHERE typeid='$SelectedType'"; + $ErrMsg = _('The Type record could not be deleted because'); + $result = DB_query($sql,$db,$ErrMsg); + prnMsg(_('Supplier type') . $SelectedType . ' ' . _('has been deleted') ,'success'); + + unset ($SelectedType); + unset($_GET['delete']); + + } +} + +if (!isset($SelectedType)){ + +/* It could still be the second time the page has been run and a record has been selected for modification - SelectedType 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 sales types 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 + */ + + $sql = 'SELECT typeid, typename FROM suppliertype'; + $result = DB_query($sql,$db); + + echo '<br><table class=selection>'; + echo "<tr> + <th>" . _('Type ID') . "</th> + <th>" . _('Type Name') . "</th> + </tr>"; + +$k=0; //row colour counter + +while ($myrow = DB_fetch_row($result)) { + if ($k==1){ + echo '<tr class="EvenTableRows">'; + $k=0; + } else { + echo '<tr class="OddTableRows">'; + $k=1; + } + + printf(" + <td>%s</td> + <td>%s</td> + <td><a href='%sSelectedType=%s'>" . _('Edit') . "</td> + <td><a href='%sSelectedType=%s&delete=yes' onclick=\"return confirm('" . + _('Are you sure you wish to delete this Supplier Type?') . "');\">" . _('Delete') . "</td> + </tr>", + $myrow[0], + $myrow[1], + $_SERVER['PHP_SELF'] . '?' . SID, $myrow[0], + $_SERVER['PHP_SELF'] . '?' . SID, $myrow[0]); + } + //END WHILE LIST LOOP + echo '</table>'; +} + +//end of ifs and buts! +if (isset($SelectedType)) { + + echo '<div class="centre"><p><a href="' . $_SERVER['PHP_SELF'] . '?' . SID . '">' . _('Show All Types Defined') . '</a></div><p>'; +} +if (! isset($_GET['delete'])) { + + echo "<form method='post' action=" . $_SERVER['PHP_SELF'] . '?' . SID . '>'; + echo '<p><table class=selection>'; //Main table + echo '<td>'; // First column + + + // The user wish to EDIT an existing type + if ( isset($SelectedType) AND $SelectedType!='' ) + { + + $sql = "SELECT typeid, + typename + FROM suppliertype + WHERE typeid='$SelectedType'"; + + $result = DB_query($sql, $db); + $myrow = DB_fetch_array($result); + + $_POST['typeid'] = $myrow['typeid']; + $_POST['typename'] = $myrow['typename']; + + echo "<input type=hidden name='SelectedType' VALUE=" . $SelectedType . ">"; + echo "<input type=hidden name='typeid' VALUE=" . $_POST['typeid'] . ">"; + + // We dont allow the user to change an existing type code + + echo 'Type ID: </td><td>' . $_POST['typeid'] . '</td></tr>'; + + } + + if (!isset($_POST['typename'])) { + $_POST['typename']=''; + } + echo "<tr><td>" . _('Type Name') . ":</td><td><input type='Text' name='typename' value='" . $_POST['typename'] . "'></td></tr>"; + + echo '<tr><td colspan=2><p><div class="centre"><input type=submit name=submit VALUE="' . _('Accept') . '"></div>'; + + echo '</td></tr></table>'; // close main table + + echo '</form>'; + +} // end if user wish to delete + + +include('includes/footer.inc'); +?> \ No newline at end of file Modified: trunk/Suppliers.php =================================================================== --- trunk/Suppliers.php 2010-06-26 08:05:36 UTC (rev 3526) +++ trunk/Suppliers.php 2010-06-26 15:02:41 UTC (rev 3527) @@ -465,6 +465,7 @@ telephone='".$_POST['Phone']."', fax = '".$_POST['Fax']."', email = '".$_POST['Email']."', + supptype = ".$_POST['SupplierType'].", currcode='" . $_POST['CurrCode'] . "', suppliersince='$SQL_SupplierSince', paymentterms='" . $_POST['PaymentTerms'] . "', @@ -490,6 +491,7 @@ telephone='".$_POST['Phone']."', fax = '".$_POST['Fax']."', email = '".$_POST['Email']."', + supptype = ".$_POST['SupplierType'].", suppliersince='$SQL_SupplierSince', paymentterms='" . $_POST['PaymentTerms'] . "', bankpartics='" . $_POST['BankPartics'] . "', @@ -522,6 +524,7 @@ telephone, fax, email, + supptype, currcode, suppliersince, paymentterms, @@ -543,6 +546,7 @@ '".$_POST['Phone']."', '".$_POST['Fax']."', '".$_POST['Email']."', + ".$_POST['SupplierType'].", '" . $_POST['CurrCode'] . "', '" . $SQL_SupplierSince . "', '" . $_POST['PaymentTerms'] . "', @@ -572,6 +576,7 @@ unset($_POST['Phone']); unset($_POST['Fax']); unset($_POST['Email']); + unset($_POST['SupplierType']); unset($_POST['CurrCode']); unset($SQL_SupplierSince); unset($_POST['PaymentTerms']); @@ -646,7 +651,7 @@ echo "<input type='hidden' name='New' VALUE='Yes'>"; - echo '<table>'; + echo '<table class=selection>'; echo '<tr><td>' . _('Supplier Code') . ":</td><td><input type='text' name='SupplierID' size=11 maxlength=10></td></tr>"; echo '<tr><td>' . _('Supplier Name') . ":</td><td><input type='text' name='SuppName' size=42 maxlength=40></td></tr>"; echo '<tr><td>' . _('Address Line 1 (Street)') . ":</td><td><input type='text' name='Address1' size=42 maxlength=40></td></tr>"; @@ -656,6 +661,12 @@ echo '<tr><td>' . _('Telephone') . ":</td><td><input type='text' name='Phone' size=30 maxlength=40></td></tr>"; echo '<tr><td>' . _('Facsimile') . ":</td><td><input type='text' name='Fax' size=30 maxlength=40></td></tr>"; echo '<tr><td>' . _('Email Address') . ":</td><td><input type='text' name='Email' size=30 maxlength=40></td></tr>"; + echo '<tr><td>' . _('Supplier Type') . ":</td><td><select name='SupplierType'>"; + $result=DB_query('SELECT typeid, typename FROM suppliertype', $db); + while ($myrow = DB_fetch_array($result)) { + echo "<option VALUE='". $myrow['typeid'] . "'>" . $myrow['typename']; + } //end while loop + echo "</select></td></tr>"; $DateString = Date($_SESSION['DefaultDateFormat']); echo '<tr><td>' . _('Supplier Since') . ' (' . $_SESSION['DefaultDateFormat'] . "):</td><td><input type='text' class='date' alt='".$_SESSION['DefaultDateFormat']."' name='SupplierSince' VALUE=$DateString size=12 maxlength=10></td></tr>"; @@ -734,7 +745,7 @@ //SupplierID exists - either passed when calling the form or from the form itself echo "<form method='post' action='" . $_SERVER['PHP_SELF'] . "?" . SID . "'>"; - echo '<table>'; + echo '<table class=selection>'; if (!isset($_POST['New'])) { $sql = "SELECT supplierid, @@ -746,6 +757,7 @@ telephone, fax, email, + supptype, currcode, suppliersince, paymentterms, @@ -771,6 +783,7 @@ $_POST['Phone'] = $myrow['telephone']; $_POST['Fax'] = $myrow['fax']; $_POST['Email'] = $myrow['email']; + $_POST['SupplierType'] = $myrow['supptype']; $_POST['SupplierSince'] = ConvertSQLDate($myrow['suppliersince']); $_POST['PaymentTerms'] = $myrow['paymentterms']; $_POST['BankPartics'] = stripcslashes($myrow['bankpartics']); @@ -797,6 +810,16 @@ echo '<tr><td>' . _('Telephone') . ':</td><td><input '.(in_array('Name',$Errors) ? 'class="inputerror"' : '').' type="text" name="Phone" VALUE="' . $_POST['Phone'] . '" size=42 maxlength=40></td></tr>'; echo '<tr><td>' . _('Facsimile') . ':</td><td><input '.(in_array('Name',$Errors) ? 'class="inputerror"' : '').' type="text" name="Fax" VALUE="' . $_POST['Fax'] . '" size=42 maxlength=40></td></tr>'; echo '<tr><td>' . _('Email Address') . ':</td><td><input '.(in_array('Name',$Errors) ? 'class="inputerror"' : '').' type="text" name="Email" VALUE="' . $_POST['Email'] . '" size=42 maxlength=40></td></tr>'; + echo '<tr><td>' . _('Supplier Type') . ":</td><td><select name='SupplierType'>"; + $result=DB_query('SELECT typeid, typename FROM suppliertype', $db); + while ($myrow = DB_fetch_array($result)) { + if ($_POST['SupplierType']==$myrow['typeid']) { + echo "<option selected value='". $myrow['typeid'] . "'>" . $myrow['typename']; + } else { + echo "<option value='". $myrow['typeid'] . "'>" . $myrow['typename']; + } + } //end while loop + echo "</select></td></tr>"; echo '<tr><td>' . _('Supplier Since') . ' (' . $_SESSION['DefaultDateFormat'] .'):</td><td><input '.(in_array('SupplierSince',$Errors) ? 'class="inputerror"' : '').' size=12 maxlength=10 type="text" class="date" alt="'.$_SESSION['DefaultDateFormat'].'" name="SupplierSince" VALUE=' . $_POST['SupplierSince'] . '></td></tr>'; echo '<tr><td>' . _('Bank Particulars') . ":</td><td><input type='text' name='BankPartics' size=13 maxlength=12 VALUE='" . $_POST['BankPartics'] . "'></td></tr>"; @@ -877,15 +900,15 @@ if (isset($_POST['New'])) { echo "<p><div class='centre'>><input type='Submit' name='submit' VALUE='" . _('Add These New Supplier Details') . "'></form>"; } else { - echo "<p><div class='centre'><input type='Submit' name='submit' VALUE='" . _('Update Supplier') . "'>"; + echo "<br><p><div class='centre'><input type='Submit' name='submit' VALUE='" . _('Update Supplier') . "'></div><br>"; // echo '<p><font color=red><b>' . _('WARNING') . ': ' . _('There is no second warning if you hit the delete button below') . '. ' . _('However checks will be made to ensure there are no outstanding purchase orders or existing accounts payable transactions before the deletion is processed') . '<br></font></b>'; prnMsg(_('WARNING') . ': ' . _('There is no second warning if you hit the delete button below') . '. ' . _('However checks will be made to ensure there are no outstanding purchase orders or existing accounts payable transactions before the deletion is processed'), 'Warn'); - echo "<input type='Submit' name='delete' VALUE='" . _('Delete Supplier') . "' onclick=\"return confirm('" . _('Are you sure you wish to delete this supplier?') . "');\"></form>"; - echo "<br><a href='$rootpath/SupplierContacts.php?" . SID . "SupplierID=$SupplierID'>" . _('Review Contact Details') . '</a>'; + echo "<br><div class=centre><input type='Submit' name='delete' VALUE='" . _('Delete Supplier') . "' onclick=\"return confirm('" . + _('Are you sure you wish to delete this supplier?') . "');\"></form>"; + echo "<br><a href='$rootpath/SupplierContacts.php?" . SID . "SupplierID=$SupplierID'>" . _('Review Contact Details') . '</a></div>'; } echo '</div>'; } // end of main ifs include('includes/footer.inc'); -?> - +?> \ No newline at end of file Modified: trunk/doc/Change.log.html =================================================================== --- trunk/doc/Change.log.html 2010-06-26 08:05:36 UTC (rev 3526) +++ trunk/doc/Change.log.html 2010-06-26 15:02:41 UTC (rev 3527) @@ -1,5 +1,6 @@ <p><font SIZE=4 COLOR=BLUE><b>webERP Change Log</b></font></p> <p></p> +<p>25/06/10 Tim: Add the ability to have supplier types.</p> <p>25/06/10 Tim: PDFStarter.php - Add in A5 parameters.</p> <p>25/06/10 Tim: SupplierTender.php - Highlight any expired offers.</p> <p>25/06/10 Tim: SupplierTender.php - Add in expiry date for offers.</p> Modified: trunk/sql/mysql/upgrade3.11.1-3.12.sql =================================================================== --- trunk/sql/mysql/upgrade3.11.1-3.12.sql 2010-06-26 08:05:36 UTC (rev 3526) +++ trunk/sql/mysql/upgrade3.11.1-3.12.sql 2010-06-26 15:02:41 UTC (rev 3527) @@ -267,3 +267,13 @@ ALTER TABLE `salesorderdetails` ADD COLUMN `commissionrate` double NOT NULL DEFAULT 0.0; ALTER TABLE `salesorderdetails` ADD COLUMN `commissionearned` double NOT NULL DEFAULT 0.0; + +CREATE TABLE `suppliertype` ( + `typeid` tinyint(4) NOT NULL AUTO_INCREMENT, + `typename` varchar(100) NOT NULL, + PRIMARY KEY (`typeid`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; + +INSERT INTO `config` VALUES ('DefaultSupplierType', 1); +INSERT INTO `suppliertype` VALUES(1, 'Default'); +ALTER TABLE `suppliers` ADD COLUMN `supptype` tinyint(4) NOT NULL DEFAULT 1 AFTER `address6`; \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |