|
From: <tim...@us...> - 2013-01-27 22:43:07
|
Revision: 5800
http://sourceforge.net/p/web-erp/reponame/5800
Author: tim_schofield
Date: 2013-01-27 22:43:04 +0000 (Sun, 27 Jan 2013)
Log Message:
-----------
New scripts for sell through support functionality
Added Paths:
-----------
trunk/PDFSellThroughSupportClaim.php
trunk/SellThroughSupport.php
Added: trunk/PDFSellThroughSupportClaim.php
===================================================================
--- trunk/PDFSellThroughSupportClaim.php (rev 0)
+++ trunk/PDFSellThroughSupportClaim.php 2013-01-27 22:43:04 UTC (rev 5800)
@@ -0,0 +1,175 @@
+<?php
+
+/* $Id: PDFSellThroughSupportClaim.php 5788 2013-01-02 03:22:38Z daintree $*/
+
+include('includes/session.inc');
+
+if (isset($_POST['PrintPDF'])) {
+
+ include('includes/PDFStarter.php');
+ $pdf->addInfo('Title', _('Sell Through Support Claim'));
+ $pdf->addInfo('Subject', _('Sell Through Support Claim'));
+ $FontSize=10;
+ $PageNumber=1;
+ $line_height=12;
+
+ $Title = _('Sell Through Support Claim') . ' - ' . _('Problem Report');
+
+ if (! Is_Date($_POST['FromDate']) OR ! Is_Date($_POST['ToDate'])){
+ include('includes/header.inc');
+ prnMsg(_('The dates entered must be in the format') . ' ' . $_SESSION['DefaultDateFormat'],'error');
+ include('includes/footer.inc');
+ exit;
+ }
+
+ /*Now figure out the data to report for the category range under review */
+ $SQL = "SELECT sellthroughsupport.supplierno,
+ suppliers.suppname,
+ suppliers.currcode,
+ currencies.decimalplaces as currdecimalplaces,
+ stockmaster.stockid,
+ stockmaster.decimalplaces,
+ stockmaster.description,
+ stockmoves.transno,
+ stockmoves.trandate,
+ systypes.typename,
+ stockmoves.qty,
+ stockmoves.debtorno,
+ debtorsmaster.name,
+ stockmoves.price*(1-stockmoves.discountpercent) as sellingprice,
+ purchdata.price as fxcost,
+ sellthroughsupport.rebatepercent,
+ sellthroughsupport.rebateamount
+ FROM stockmaster INNER JOIN stockmoves
+ ON stockmaster.stockid=stockmoves.stockid
+ INNER JOIN sellthroughsupport
+ INNER JOIN systypes
+ ON stockmoves.type=systypes.typeid
+ INNER JOIN debtorsmaster
+ ON stockmoves.debtorno=debtorsmaster.debtorno
+ INNER JOIN suppliers
+ ON sellthroughsupport.supplierno=suppliers.supplierid
+ INNER JOIN purchdata
+ ON purchdata.stockid = stockmaster.stockid
+ AND purchdata.supplierno = sellthroughsupport.supplierno
+ INNER JOIN currencies
+ ON currencies.currabrev=suppliers.currcode
+ WHERE stockmoves.trandate >= '" . FormatDateForSQL($_POST['FromDate']) . "'
+ AND stockmoves.trandate <= '" . FormatDateForSQL($_POST['ToDate']) . "'
+ AND (stockmoves.type=10 OR stockmoves.type=11)
+ AND (sellthroughsupport.stockid=stockmoves.stockid OR sellthroughsupport.categoryid=stockmaster.categoryid)
+ AND (sellthroughsupport.debtorno=stockmoves.debtorno OR sellthroughsupport.debtorno='')
+ ORDER BY sellthroughsupport.supplierno,
+ stockmaster.stockid";
+
+ $ClaimsResult = DB_query($SQL,$db,'','',false,false);
+
+ if (DB_error_no($db) !=0) {
+
+ include('includes/header.inc');
+ prnMsg(_('The sell through support items to claim could not be retrieved by the SQL because') . ' - ' . DB_error_msg($db),'error');
+ echo '<br /><a href="' .$RootPath .'/index.php">' . _('Back to the menu') . '</a>';
+ if ($debug==1){
+ echo '<br />' . $SQL;
+ }
+ include('includes/footer.inc');
+ exit;
+ }
+
+ if (DB_num_rows($LowGPSalesResult) == 0) {
+
+ include('includes/header.inc');
+ prnMsg(_('No sell through support items retrieved'), 'warn');
+ echo '<br /><a href="' . $RootPath . '/index.php">' . _('Back to the menu') . '</a>';
+ if ($debug==1){
+ echo '<br />' . $SQL;
+ }
+ include('includes/footer.inc');
+ exit;
+ }
+
+ include ('includes/PDFSellThroughSuppPageHeader.inc');
+ $SupplierClaimTotal=0;
+ $Supplier = '';
+ $FontSize=8;
+ while ($SellThroRow = DB_fetch_array($ClaimsResult,$db)){
+
+ $YPos -=$line_height;
+ if ($SellThroRow['suppname']!=$Supplier){
+ $FontSize = 10;
+ $LeftOvers = $pdf->addTextWrap($Left_Margin+2,$YPos,30,$FontSize,$SellThroRow['suppname']);
+ $YPos -=$line_height;
+
+ if ($SupplierClaimTotal > 0) {
+ $LeftOvers = $pdf->addTextWrap($Left_Margin+2,$YPos,30,$FontSize,$Supplier . ' ' . _('Total Claim:') . ' (' . $CurrCode . ')');
+ $LeftOvers = $pdf->addTextWrap(440,$YPos,60,$FontSize, locale_number_format($SupplierClaimTotal,$CurrDecimalPlaces), 'right');
+ include('includes/PDFLowGPPageHeader.inc');
+ }
+ $Supplier = $SellThroRow['suppname'];
+ $CurrDeciamlPlaces = $SellThroRow['currdecimalplaces'];
+ $CurrCode = $SellThroRow['currcode'];
+ $SupplierClaimTotal=0;
+ $FontSize =8;
+ }
+ $LeftOvers = $pdf->addTextWrap($Left_Margin+2,$YPos,30,$FontSize,$SellThroRow['typename']);
+ $LeftOvers = $pdf->addTextWrap(100,$YPos,30,$FontSize,$SellThroRow['transno']);
+ $LeftOvers = $pdf->addTextWrap(130,$YPos,50,$FontSize,$SellThroRow['stockid']);
+ $LeftOvers = $pdf->addTextWrap(220,$YPos,50,$FontSize,$SellThroRow['name']);
+ $DisplaySellingPrice = locale_number_format($SellThroRow['sellingprice'],$_SESSION['CompanyRecord']['decimalplaces']);
+ $LeftOvers = $pdf->addTextWrap(330,$YPos,60,$FontSize,$DisplaySellingPrice,'right');
+ $ClaimAmount = (($SellThroRow['fxcost']*$SellThroRow['rebatepercent']) + $SellThroRow['rebateamount']) * -$SellThroRow['qty'];
+ $SupplierClaimTotal += $ClaimTotal;
+
+
+ $LeftOvers = $pdf->addTextWrap(380,$YPos,60,$FontSize,locale_number_format(-$SellThroRow['qty']), 'right');
+ $LeftOvers = $pdf->addTextWrap(440,$YPos,60,$FontSize,locale_number_format($ClaimAmount,$CurrDecimalPlaces), 'right');
+
+ if ($YPos < $Bottom_Margin + $line_height){
+ include('includes/PDFLowGPPageHeader.inc');
+ }
+
+ } /*end sell through support claims while loop */
+
+ $FontSize =10;
+
+ $YPos -= (2*$line_height);
+ $pdf->OutputD($_SESSION['DatabaseName'] . '_SellThroughSupportClaim_' . date('Y-m-d') . '.pdf');
+ $pdf->__destruct();
+
+} else { /*The option to print PDF was not hit */
+
+ include('includes/header.inc');
+
+ echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/transactions.png" title="' . $Title . '" alt="" />' . ' '
+ . _('Sell Through Support Claims Report') . '</p>';
+
+ if (!isset($_POST['FromDate']) OR !isset($_POST['ToDate'])) {
+
+ /*if $FromDate is not set then show a form to allow input */
+ $_POST['FromDate']=Date($_SESSION['DefaultDateFormat']);
+ $_POST['ToDate']=Date($_SESSION['DefaultDateFormat']);
+ echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">';
+ echo '<div>
+ <input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />
+ <table class="selection">
+ <tr>
+ <td>' . _('Sales Made From') . ' (' . _('in the format') . ' ' . $_SESSION['DefaultDateFormat'] . '):</td>
+ <td><input type="text" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '" name="FromDate" size="10" maxlength="10" value="' . $_POST['FromDate'] . '" /></td>
+ </tr>
+ <tr>
+ <td>' . _('Sales Made To') . ' (' . _('in the format') . ' ' . $_SESSION['DefaultDateFormat'] . '):</td>
+ <td><input type="text" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '" name="ToDate" size="10" maxlength="10" value="' . $_POST['ToDate'] . '" /></td>
+ </tr>
+ </table>
+ <br />
+ <div class="centre">
+ <input type="submit" name="PrintPDF" value="' . _('Create Claims Report') . '" />
+ </div>';
+ echo '</div>
+ </form>';
+ }
+ include('includes/footer.inc');
+
+} /*end of else not PrintPDF */
+
+?>
\ No newline at end of file
Added: trunk/SellThroughSupport.php
===================================================================
--- trunk/SellThroughSupport.php (rev 0)
+++ trunk/SellThroughSupport.php 2013-01-27 22:43:04 UTC (rev 5800)
@@ -0,0 +1,489 @@
+<?php
+/* $Id: SellThroughSupport.php 5785 2012-12-29 04:47:42Z daintree $*/
+
+include ('includes/session.inc');
+
+$Title = _('Sell Through Support');
+
+include ('includes/header.inc');
+
+if (isset($_GET['SupplierID']) AND $_GET['SupplierID']!='') {
+ $SupplierID = trim(mb_strtoupper($_GET['SupplierID']));
+} elseif (isset($_POST['SupplierID'])) {
+ $SupplierID = trim(mb_strtoupper($_POST['SupplierID']));
+}
+
+//if $Edit == true then we are editing an existing SellThroughSupport record
+if (isset($_GET['Edit'])) {
+ $Edit = true;
+} elseif (isset($_POST['Edit'])) {
+ $Edit = true;
+} else {
+ $Edit = false;
+}
+
+
+/*Deleting a supplier sell through support record */
+if (isset($_GET['Delete'])){
+ $Result = DB_query("DELETE FROM sellthroughsupport WHERE id='" . intval($_GET['SellSupportID']) . "'", $db);
+ prnMsg(_('Deleted the supplier sell through support record'),'success');
+}
+
+
+if ((isset($_POST['AddRecord']) OR isset($_POST['UpdateRecord'])) AND isset($SupplierID)) { /*Validate Inputs */
+ $InputError = 0; /*Start assuming the best */
+
+ if (is_numeric(filter_number_format($_POST['RebateAmount']))==false) {
+ $InputError = 1;
+ prnMsg(_('The rebate amount entered was not numeric and a number is required.'), 'error');
+ unset($_POST['RebateAmount']);
+ } elseif (filter_number_format($_POST['RebateAmount']) == 0 AND filter_number_format($_POST['RebatePercent'])==0) {
+ prnMsg(_('Both the rebate amount and the rebate percent is zero. One or the other must be a positive number?'), 'error');
+ $InputError = 1;
+
+/*
+ } elseif (mb_strlen($_POST['Narrative'])==0 OR $_POST['Narrative']==''){
+ prnMsg(_('The narrative cannot be empty.'),'error');
+ $InputError = 1;
+*/
+ } elseif (filter_number_format($_POST['RebatePercent'])>100 OR filter_number_format($_POST['RebatePercent']) < 0) {
+ prnMsg(_('The rebate percent must be greater than zero but less than 100 percent. No changes will be made to this record'),'error');
+ $InputError = 1;
+ } elseif (filter_number_format($_POST['RebateAmount']) !=0 AND filter_number_format($_POST['RebatePercent'])!=0) {
+ prnMsg(_('Both the rebate percent and rebate amount are non-zero. Only one or the other can be used.'),'error');
+ $InputError = 1;
+ } elseif (Date1GreaterThanDate2($_POST['EffectiveFrom'], $_POST['EffectiveTo'])) {
+ prnMsg(_('The effective to date is prior to the effective from date.'),'error');
+ $InputError = 1;
+ }
+
+ if ($InputError == 0 AND isset($_POST['AddRecord'])) {
+ $sql = "INSERT INTO sellthroughsupport (supplierno,
+ debtorno,
+ categoryid,
+ stockid,
+ narrative,
+ rebateamount,
+ rebatepercent,
+ effectivefrom,
+ effectiveto )
+ VALUES ('" . $SupplierID . "',
+ '" . $_POST['DebtorNo'] . "',
+ '" . $_POST['CategoryID'] . "',
+ '" . $_POST['StockID'] . "',
+ '" . $_POST['Narrative'] . "',
+ '" . filter_number_format($_POST['RebateAmount']) . "',
+ '" . filter_number_format($_POST['RebatePercent']/100) . "',
+ '" . FormatDateForSQL($_POST['EffectiveFrom']) . "',
+ '" . FormatDateForSQL($_POST['EffectiveTo']) . "')";
+
+ $ErrMsg = _('The sell through support record could not be added to the database because');
+ $DbgMsg = _('The SQL that failed was');
+ $AddResult = DB_query($sql, $db, $ErrMsg, $DbgMsg);
+ prnMsg(_('This sell through support has been added to the database'), 'success');
+ }
+ if ($InputError == 0 AND isset($_POST['UpdateRecord'])) {
+ $sql = "UPDATE sellthroughsupport SET debtorno='" . $_POST['DebtorNo'] . "',
+ categoryid='" . $_POST['CategoryID'] . "',
+ stockid='" . $_POST['StockID'] . "',
+ narrative='" . $_POST['Narrative'] . "',
+ rebateamount='" . filter_number_format($_POST['RebateAmount']) . "',
+ rebatepercent='" . filter_number_format($_POST['RebatePercent'])/100 . "',
+ effectivefrom='" . FormatDateForSQL($_POST['EffectiveFrom']) . "',
+ effectiveto='" . FormatDateForSQL($_POST['EffectiveTo']) . "'
+ WHERE id='" . $_POST['SellSupportID'] . "'";
+
+ $ErrMsg = _('The sell through support record could not be updated because');
+ $DbgMsg = _('The SQL that failed was');
+ $UpdResult = DB_query($sql, $db, $ErrMsg, $DbgMsg);
+ prnMsg(_('Sell Through Support record has been updated'), 'success');
+ $Edit = false;
+
+ }
+
+ if ($InputError == 0) {
+ /* insert took place and need to clear the form */
+ unset($_POST['StockID']);
+ unset($_POST['EffectiveFrom']);
+ unset($_POST['DebtorNo']);
+ unset($_POST['CategoryID']);
+ unset($_POST['Narrative']);
+ unset($_POST['RebatePercent']);
+ unset($_POST['RebateAmount']);
+ unset($_POST['EffectiveFrom']);
+ unset($_POST['EffectiveTo']);
+ }
+}
+
+if (isset($_POST['SearchSupplier'])) {
+ if (isset($_POST['Keywords']) AND isset($_POST['SupplierCode'])) {
+ prnMsg( _('Supplier Name keywords have been used in preference to the Supplier Code extract entered') . '.', 'info' );
+ echo '<br />';
+ }
+ if ($_POST['Keywords'] == '' AND $_POST['SupplierCode'] == '') {
+ $_POST['Keywords'] = ' ';
+ }
+ if (mb_strlen($_POST['Keywords']) > 0) {
+ //insert wildcard characters in spaces
+ $SearchString = '%' . str_replace(' ', '%', $_POST['Keywords']) . '%';
+
+ $SQL = "SELECT suppliers.supplierid,
+ suppliers.suppname,
+ suppliers.currcode,
+ suppliers.address1,
+ suppliers.address2,
+ suppliers.address3
+ FROM suppliers
+ WHERE suppliers.suppname " . LIKE . " '".$SearchString."'";
+
+ } elseif (mb_strlen($_POST['SupplierCode']) > 0) {
+ $SQL = "SELECT suppliers.supplierid,
+ suppliers.suppname,
+ suppliers.currcode,
+ suppliers.address1,
+ suppliers.address2,
+ suppliers.address3
+ FROM suppliers
+ WHERE suppliers.supplierid " . LIKE . " '%" . $_POST['SupplierCode'] . "%'";
+
+ } //one of keywords or SupplierCode was more than a zero length string
+ $ErrMsg = _('The suppliers matching the criteria entered could not be retrieved because');
+ $DbgMsg = _('The SQL to retrieve supplier details that failed was');
+ $SuppliersResult = DB_query($SQL, $db, $ErrMsg, $DbgMsg);
+
+ echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">
+ <input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />
+ <table cellpadding="2" colspan="7" class="selection">';
+ echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
+ $TableHeader = '<tr>
+ <th>' . _('Code') . '</th>
+ <th>' . _('Supplier Name') . '</th>
+ <th>' . _('Currency') . '</th>
+ <th>' . _('Address 1') . '</th>
+ <th>' . _('Address 2') . '</th>
+ <th>' . _('Address 3') . '</th>
+ </tr>';
+ echo $TableHeader;
+ $k = 0;
+ while ($myrow = DB_fetch_array($SuppliersResult)) {
+ if ($k==1){
+ echo '<tr class="EvenTableRows">';
+ $k=0;
+ } else {
+ echo '<tr class="OddTableRows">';
+ $k++;
+ }
+ printf('<td><input type="submit" name="SupplierID" value="%s" /></td>
+ <td>%s</td>
+ <td>%s</td>
+ <td>%s</td>
+ <td>%s</td>
+ <td>%s</td>
+ </tr>',
+ $myrow['supplierid'],
+ $myrow['suppname'],
+ $myrow['currcode'],
+ $myrow['address1'],
+ $myrow['address2'],
+ $myrow['address3']);
+ }//end of while loop
+ echo '</table>
+ <br/>
+ </form>';
+}//end if results to show
+ elseif (!isset($SupplierID)) {
+ echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">
+ <input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />
+ <table cellpadding="3" colspan="4" class="selection">
+ <tr>
+ <input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />
+ <td>' . _('Text in the Supplier') . ' <b>' . _('NAME') . '</b>:</td>
+ <td><input type="text" name="Keywords" size="20" maxlength="25" /></td>
+ <td><b>' . _('OR') . '</b></td>
+ <td>' . _('Text in Supplier') . ' <b>' . _('CODE') . '</b>:</td>
+ <td><input type="text" name="SupplierCode" size="20" maxlength="50" /></td>
+ </tr>
+ </table>
+ <br />
+ <div class="centre">
+ <input type="submit" name="SearchSupplier" value="' . _('Find Suppliers Now') . '" />
+ </div>
+ </form>';
+ include ('includes/footer.inc');
+ exit;
+}
+
+
+
+if (isset($SupplierID)) { /* Then display all the sell through support for the supplier */
+
+ /*Get the supplier details */
+ $SuppResult = DB_query("SELECT suppname,
+ currcode,
+ decimalplaces
+ FROM suppliers INNER JOIN currencies
+ ON suppliers.currcode=currencies.currabrev
+ WHERE supplierid='" . $SupplierID . "'",$db);
+ $SuppRow = DB_fetch_array($SuppResult);
+
+ echo '<p class="page_title_text"><img src="' . $RootPath . '/css/' . $Theme . '/images/maintenance.png" title="' . _('Search') . '" alt="" />' . ' ' . $Title . ' ' . _('For Supplier') . ' - ' . $SupplierID . ' - ' . $SuppRow['suppname'] . '</p><br />';
+}
+
+if (isset($SupplierID) AND $Edit == false) {
+
+ $sql = "SELECT id,
+ sellthroughsupport.debtorno,
+ debtorsmaster.name,
+ rebateamount,
+ rebatepercent,
+ effectivefrom,
+ effectiveto,
+ sellthroughsupport.stockid,
+ description,
+ categorydescription,
+ sellthroughsupport.categoryid,
+ narrative
+ FROM sellthroughsupport LEFT JOIN stockmaster
+ ON sellthroughsupport.stockid=stockmaster.stockid
+ LEFT JOIN stockcategory
+ ON sellthroughsupport.categoryid = stockcategory.categoryid
+ LEFT JOIN debtorsmaster
+ ON sellthroughsupport.debtorno=debtorsmaster.debtorno
+ WHERE supplierno = '" . $SupplierID . "'
+ ORDER BY sellthroughsupport.effectivefrom DESC";
+ $ErrMsg = _('The supplier sell through support deals could not be retrieved because');
+ $Result = DB_query($sql, $db, $ErrMsg);
+ if (DB_num_rows($Result)==0) {
+ prnMsg(_('There are no sell through support deals entered for this supplier'), 'info');
+ } else {
+ echo '<table cellpadding="2" class="selection">';
+ $TableHeader = '<tr>
+ <th>' . _('Item or Category') . '</th>
+ <th>' . _('Customer') . '</th>
+ <th>' . _('Rebate') . '<br />' . _('Value') . ' ' . $SuppRow['currcode'] . '</th>
+ <th>' . _('Rebate') . '<br />' . _('Percent') . '</th>
+ <th>' . _('Narrative') . '</th>
+ <th>' . _('Effective From') . '</th>
+ <th>' . _('Effective To') . '</th>
+ </tr>';
+
+ echo $TableHeader;
+ $k = 0; //row colour counter
+ while ($myrow = DB_fetch_array($Result)) {
+ if ($k == 1) {
+ echo '<tr class="EvenTableRows">';
+ $k = 0;
+ } else {
+ echo '<tr class="OddTableRows">';
+ $k++;
+ }
+ if ($myrow['categoryid']=='') {
+ $ItemDescription = $myrow['stockid'] . ' - ' . $myrow['description'];
+ } else {
+ $ItemDescription = _('Any') . ' ' . $myrow['categorydescription'];
+ }
+ if ($myrow['debtorno']==''){
+ $Customer = _('All Customers');
+ } else {
+ $Customer = $myrow['debtorno'] . ' - ' . $myrow['name'];
+ }
+
+ printf('<td>%s</td>
+ <td>%s</td>
+ <td class="number">%s</td>
+ <td class="number">%s</td>
+ <td>%s</td>
+ <td>%s</td>
+ <td>%s</td>
+ <td><a href="%s?SellSupportID=%s&SupplierID=%s&Edit=1">' . _('Edit') . '</a></td>
+ <td><a href="%s?SellSupportID=%s&Delete=1&SupplierID=%s" onclick=\'return confirm("' . _('Are you sure you wish to delete this sell through support record?') . '");\'>' . _('Delete') . '</a></td>
+ </tr>',
+ $ItemDescription,
+ $Customer,
+ locale_number_format($myrow['rebateamount'],$SuppRow['decimalplaces']),
+ locale_number_format($myrow['rebatepercent']*100,2),
+ $myrow['narrative'],
+ ConvertSQLDate($myrow['effectivefrom']),
+ ConvertSQLDate($myrow['effectiveto']),
+ htmlspecialchars($_SERVER['PHP_SELF']),
+ $myrow['id'],
+ $SupplierID,
+ htmlspecialchars($_SERVER['PHP_SELF']),
+ $myrow['id'],
+ $SupplierID);
+ } //end of while loop
+ echo '</table><br/>';
+ } // end of there are sell through support rows to show
+ echo '<br/>';
+} /* Only show the existing supplier sell through support records if one is not being edited */
+
+/*Show the input form for new supplier sell through support details */
+if (isset($SupplierID)) { //not selecting a supplier
+ if ($Edit == true) {
+ $sql = "SELECT id,
+ debtorno,
+ rebateamount,
+ rebatepercent,
+ effectivefrom,
+ effectiveto,
+ stockid,
+ categoryid,
+ narrative
+ FROM sellthroughsupport
+ WHERE id='" . floatval($_GET['SellSupportID']) . "'";
+
+ $ErrMsg = _('The supplier sell through support could not be retrieved because');
+ $EditResult = DB_query($sql, $db, $ErrMsg);
+ $myrow = DB_fetch_array($EditResult);
+ }
+
+ $SuppName = $myrow['suppname'];
+
+ echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">
+ <input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />
+ <input type="hidden" name="SupplierID" value="' . $SupplierID . '" />
+ <table class="selection">';
+
+ if ($Edit == true) {
+ $_POST['DebtorNo'] = $myrow['debtorno'];
+ $_POST['StockID'] = $myrow['stockid'];
+ $_POST['CategoryID'] = $myrow['categoryid'];
+ $_POST['Narrative'] = $myrow['narrative'];
+ $_POST['RebatePercent'] = locale_number_format($myrow['rebatepercent']*100,2);
+ $_POST['RebateAmount'] = locale_number_format($myrow['rebateamount'],$CurrDecimalPlaces);
+ $_POST['EffectiveFrom'] = ConvertSQLDate($myrow['effectivefrom']);
+ $_POST['EffectiveTo'] = ConvertSQLDate($myrow['effectiveto']);
+
+ echo '<input type="hidden" name="SellSupportID" value="' . $myrow['id'] . '" />';
+ }
+ if (!isset($_POST['RebateAmount'])) {
+ $_POST['RebateAmount'] = 0;
+ }
+ if (!isset($_POST['RebatePercent'])) {
+ $_POST['RebatePercent'] = 0;
+ }
+ if (!isset($_POST['EffectiveFrom'])) {
+ $_POST['EffectiveFrom'] = Date($_SESSION['DefaultDateFormat']);
+ }
+ if (!isset($_POST['EffectiveTo'])) {
+ /* Default EffectiveTo to the end of the month */
+ $_POST['EffectiveTo'] = Date($_SESSION['DefaultDateFormat'], mktime(0,0,0,Date('m')+1,0,Date('y')));
+ }
+ if (!isset($_POST['DebtorNo'])){
+ $_POST['DebtorNo']='';
+ }
+ if (!isset($_POST['Narrative'])){
+ $_POST['Narrative'] ='';
+ }
+
+
+ echo '<tr>
+ <td>' . _('Support for Customer') . ':</td>
+ <td><select name="DebtorNo">';
+ if ($_POST['DebtorNo']=='') {
+ echo '<option selected="selected" value="">' . _('All Customers') . '</option>';
+ } else {
+ echo '<option value="">' . _('All Customers') . '</option>';
+ }
+
+ $CustomerResult = DB_query("SELECT debtorno, name FROM debtorsmaster",$db);
+
+ while ($CustomerRow = DB_fetch_array($CustomerResult)){
+ if ($CustomerRow['debtorno'] == $_POST['DebtorNo']){
+ echo '<option selected="selected" value="' . $CustomerRow['debtorno'] . '">' . $CustomerRow['name'] . '</option>';
+ } else {
+ echo '<option value="' . $CustomerRow['debtorno'] . '">' . $CustomerRow['name'] . '</option>';
+ }
+ }
+ echo '</select></td>
+ </tr>';
+
+ echo '<tr>
+ <td>' . _('Support Whole Category') . ':</td>
+ <td><select name="CategoryID">';
+ if ($_POST['CategoryID']=='') {
+ echo '<option selected="selected" value="">' . _('Specific Item Only') . '</option>';
+ } else {
+ echo '<option value="">' . _('Specific Item Only') . '</option>';
+ }
+
+ $CategoriesResult = DB_query("SELECT categoryid, categorydescription FROM stockcategory WHERE stocktype='F'",$db);
+
+ while ($CategoriesRow = DB_fetch_array($CategoriesResult)){
+ if ($CategoriesRow['categoryid'] == $_POST['CategoryID']){
+ echo '<option selected="selected" value="' . $CategoriesRow['categoryid'] . '">' . $CategoriesRow['categorydescription'] . '</option>';
+ } else {
+ echo '<option value="' . $CategoriesRow['categoryid'] . '">' . $CategoriesRow['categorydescription'] . '</option>';
+ }
+ }
+ echo '</select></td>
+ </tr>';
+
+ echo '<tr>
+ <td>' . _('Support Specific Item') . ':</td>
+ <td><select name="StockID">';
+ if ($_POST['StockID']=='') {
+ echo '<option selected="selected" value="">' . _('Support An Entire Category') . '</option>';
+ } else {
+ echo '<option value="">' . _('Support An Entire Category') . '</option>';
+ }
+
+
+ $SQL = "SELECT stockmaster.stockid,
+ stockmaster.description
+ FROM purchdata INNER JOIN stockmaster
+ ON purchdata.stockid=stockmaster.stockid
+ WHERE supplierno ='" . $SupplierID . "'
+ AND preferred=1";
+ $ErrMsg = _('Could not retrieve the items that the supplier provides');
+ $DbgMsg = _('The SQL that was used to get the supplier items and failed was');
+ $ItemsResult = DB_query($SQL,$db,$ErrMsg,$DbgMsg);
+
+ while ($ItemsRow = DB_fetch_array($ItemsResult)){
+ if ($ItemsRow['stockid'] == $_POST['StockID']){
+ echo '<option selected="selected" value="' . $ItemsRow['stockid'] . '">' . $ItemsRow['stockid'] . ' - ' . $ItemsRow['description'] . '</option>';
+ } else {
+ echo '<option value="' . $ItemsRow['stockid'] . '">' . $ItemsRow['stockid'] . ' - ' . $ItemsRow['description'] . '</option>';
+ }
+ }
+ echo '</select></td>
+ </tr>';
+
+ echo '<tr>
+ <td>' . _('Narrative') . ':</td>
+ <td><input type="text" name="Narrative" maxlength="20" size="21" value="' . $_POST['Narrative'] . '" /></td>
+ </tr>
+ <tr>
+ <td>' . _('Rebate value per unit') . ' (' . $SuppRow['currcode'] . '):</td>
+ <td><input type="text" class="number" name="RebateAmount" maxlength="12" size="12" value="' . $_POST['RebateAmount'] . '" /></td>
+ </tr>
+ <tr>
+ <td>' . _('Rebate Percent') . ':</td>
+ <td><input type="text" class="number" name="RebatePercent" maxlength="5" size="6" value="' . $_POST['RebatePercent'] . '" />%</td>
+ </tr>
+ <tr>
+ <td>' . _('Support Start Date') . ':</td>
+ <td><input type="text" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '" name="EffectiveFrom" maxlength="10" size="11" value="' . $_POST['EffectiveFrom'] . '" /></td>
+ </tr>
+ <tr>
+ <td>' . _('Support End Date') . ':</td>
+ <td><input type="text" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '" name="EffectiveTo" maxlength="10" size="11" value="' . $_POST['EffectiveTo'] . '" /></td>
+ </tr>
+ </table>
+ <br />
+ <div class="centre">';
+ if ($Edit == true) {
+ echo '<input type="submit" name="UpdateRecord" value="' . _('Update') . '" />';
+ echo '<input type="hidden" name="Edit" value="1" />';
+
+ /*end if there is a supplier sell through support record being updated */
+ } else {
+ echo '<input type="submit" name="AddRecord" value="' . _('Add') . '" />';
+ }
+
+ echo '</div>
+ </form>';
+}
+
+include ('includes/footer.inc');
+?>
|