[Weberp-svn] SF.net SVN: weberp:[8359] trunk
Brought to you by:
sotandeka,
tim_schofield
From: <tim...@us...> - 2011-11-27 12:11:35
|
Revision: 8359 http://weberp.svn.sourceforge.net/weberp/?rev=8359&view=rev Author: tim_schofield Date: 2011-11-27 12:11:28 +0000 (Sun, 27 Nov 2011) Log Message: ----------- New sales inquiry by sales category script Modified Paths: -------------- trunk/includes/session.inc trunk/index.php Added Paths: ----------- trunk/SalesCategoryPeriodInquiry.php trunk/sql/mysql/updates/103.php Added: trunk/SalesCategoryPeriodInquiry.php =================================================================== --- trunk/SalesCategoryPeriodInquiry.php (rev 0) +++ trunk/SalesCategoryPeriodInquiry.php 2011-11-27 12:11:28 UTC (rev 8359) @@ -0,0 +1,220 @@ +<?php + +/* $Id: SalesCategoryPeriodInquiry.php 4261 2010-12-22 15:56:50Z $*/ + +include('includes/session.inc'); +$title = _('Sales Category Report'); +include('includes/header.inc'); +include('includes/DefineCartClass.php'); + +echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/transactions.png" title="' . _('Sales Report') . '" alt="" />' . ' ' . _('Sales Category Report') . '</p>'; +echo '<div class="page_help_text">' . _('Select the parameters for the report') . '</div><br />'; + +if (!isset($_POST['DateRange'])){ + /* then assume report is for This Month - maybe wrong to do this but hey better than reporting an error?*/ + $_POST['DateRange']='ThisMonth'; +} + +echo '<form name="form1" action="' . htmlspecialchars($_SERVER['PHP_SELF']) . '" method="post">'; +echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; + +echo '<table cellpadding=2 class="selection">'; + +echo '<tr><th colspan="2" class="centre">' . _('Date Selection') . '</th> + </tr> + <tr> + <td>' . _('Custom Range') . ':</td> + <td><input type="radio" name="DateRange" value="Custom" '; +if ($_POST['DateRange']=='Custom'){ + echo 'checked'; +} +echo ' onChange="ReloadForm(form1.ShowSales)" /></td> + </tr> + <tr> + <td>' . _('This Week') . ':</td> + <td><input type="radio" name="DateRange" value="ThisWeek" '; +if ($_POST['DateRange']=='ThisWeek'){ + echo 'checked'; +} +echo ' onChange="ReloadForm(form1.ShowSales)" /></td> + </tr> + <tr> + <td>' . _('This Month') . ':</td> + <td><input type="radio" name="DateRange" value="ThisMonth" '; +if ($_POST['DateRange']=='ThisMonth'){ + echo 'checked'; +} +echo ' onChange="ReloadForm(form1.ShowSales)" /></td> + </tr> + <tr> + <td>' . _('This Quarter') . ':</td> + <td><input type="radio" name="DateRange" value="ThisQuarter" '; +if ($_POST['DateRange']=='ThisQuarter'){ + echo 'checked'; +} +echo ' onChange="ReloadForm(form1.ShowSales)" /></td> + </tr>'; +if ($_POST['DateRange']=='Custom'){ + if (!isset($_POST['FromDate'])){ + unset($_POST['ShowSales']); + $_POST['FromDate'] = Date($_SESSION['DefaultDateFormat'],mktime(1,1,1,Date('m')-12,Date('d')+1,Date('Y'))); + $_POST['ToDate'] = Date($_SESSION['DefaultDateFormat']); + } + echo '<tr> + <td>' . _('Date From') . ':</td> + <td><input type="text" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '" name="FromDate" maxlength="10" size="11" value="' . $_POST['FromDate'] . '" /></td> + </tr>'; + echo '<tr> + <td>' . _('Date To') . ':</td> + <td><input type="text" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '" name="ToDate" maxlength="10" size="11" value="' . $_POST['ToDate'] . '" /></td> + </tr>'; +} +echo '</table>'; + + +echo '<br /><div class="centre"><input tabindex=4 type="submit" name="ShowSales" value="' . _('Show Sales') . '" />'; +echo '</form></div>'; +echo '<br />'; + + +if (isset($_POST['ShowSales'])){ + $InputError=0; //assume no input errors now test for errors + if ($_POST['DateRange']=='Custom'){ + if (!Is_Date($_POST['FromDate'])){ + $InputError = 1; + prnMsg(_('The date entered for the from date is not in the appropriate format. Dates must be entered in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'error'); + } + if (!Is_Date($_POST['ToDate'])){ + $InputError = 1; + prnMsg(_('The date entered for the to date is not in the appropriate format. Dates must be entered in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'error'); + } + if (Date1GreaterThanDate2($_POST['FromDate'],$_POST['ToDate'])){ + $InputError = 1; + prnMsg(_('The from date is expected to be a date prior to the to date. Please review the selected date range'),'error'); + } + } + switch ($_POST['DateRange']) { + case 'ThisWeek': + $FromDate = date('Y-m-d',mktime(0,0,0,date('m'),date('d')-date('w')+1,date('Y'))); + $ToDate = date('Y-m-d'); + break; + case 'ThisMonth': + $FromDate = date('Y-m-d',mktime(0,0,0,date('m'),1,date('Y'))); + $ToDate = date('Y-m-d'); + break; + case 'ThisQuarter': + switch (date('m')) { + case 1: + case 2: + case 3: + $QuarterStartMonth=1; + break; + case 4: + case 5: + case 6: + $QuarterStartMonth=4; + break; + case 7: + case 8: + case 9: + $QuarterStartMonth=7; + break; + default: + $QuarterStartMonth=10; + } + $FromDate = date('Y-m-d',mktime(0,0,0,$QuarterStartMonth,1,date('Y'))); + $ToDate = date('Y-m-d'); + break; + case 'Custom': + $FromDate = FormatDateForSQL($_POST['FromDate']); + $ToDate = FormatDateForSQL($_POST['ToDate']); + } + $sql = "SELECT stockmaster.categoryid, + stockcategory.categorydescription, + SUM(CASE WHEN stockmoves.type=10 THEN + price*(1-discountpercent)* -qty + ELSE 0 END) as salesvalue, + SUM(CASE WHEN stockmoves.type=11 THEN + price*(1-discountpercent)* (-qty) + ELSE 0 END) as returnvalue, + SUM(CASE WHEN stockmoves.type=11 + OR stockmoves.type=10 THEN + price*(1-discountpercent)* (-qty) + ELSE 0 END) as netsalesvalue, + SUM((standardcost * -qty)) as cost + FROM stockmoves INNER JOIN stockmaster + ON stockmoves.stockid=stockmaster.stockid + INNER JOIN stockcategory + ON stockmaster.categoryid=stockcategory.categoryid + WHERE (stockmoves.type=10 or stockmoves.type=11) + AND show_on_inv_crds =1 + AND trandate>='" . $FromDate . "' + AND trandate<='" . $ToDate . "' + GROUP BY stockmaster.categoryid + ORDER BY netsalesvalue DESC"; + + $ErrMsg = _('The sales data could not be retrieved because') . ' - ' . DB_error_msg($db); + $SalesResult = DB_query($sql,$db,$ErrMsg); + + echo '<table cellpadding=2 class="selection">'; + + echo'<tr> + <th>' . _('Category') . '</th> + <th>' . _('Total Sales') . '</th> + <th>' . _('Refunds') . '</th> + <th>' . _('Net Sales') . '</th> + <th>' . _('Cost of Sales') . '</th> + <th>' . _('Gross Profit') . '</th> + </tr>'; + + $CumulativeTotalSales = 0; + $CumulativeTotalRefunds = 0; + $CumulativeTotalNetSales = 0; + $CumulativeTotalCost = 0; + $CumulativeTotalGP = 0; + + $k=0; + while ($SalesRow=DB_fetch_array($SalesResult)) { + if ($k==1){ + echo '<tr class="EvenTableRows">'; + $k=0; + } else { + echo '<tr class="OddTableRows">'; + $k=1; + } + + echo '<td>' . $SalesRow['categoryid'] . ' - ' . $SalesRow['categorydescription'] . '</td> + <td class="number">' . locale_number_format($SalesRow['salesvalue'],$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + <td class="number">' . locale_number_format($SalesRow['returnvalue'],$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + <td class="number">' . locale_number_format($SalesRow['salesvalue']+$SalesRow['returnvalue'],$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + <td class="number">' . locale_number_format($SalesRow['cost'],$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + <td class="number">' . locale_number_format(($SalesRow['salesvalue']+$SalesRow['returnvalue']-$SalesRow['cost']),$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + </tr>'; + + $CumulativeTotalSales += $SalesRow['salesvalue']; + $CumulativeTotalRefunds += $SalesRow['returnvalue']; + $CumulativeTotalNetSales += ($SalesRow['salesvalue']+$SalesRow['returnvalue']); + $CumulativeTotalCost += $SalesRow['cost']; + $CumulativeTotalGP += ($SalesRow['salesvalue']+$SalesRow['returnvalue']-$SalesRow['cost']); + } //loop around category sales for the period + + if ($k==1){ + echo '<tr class="EvenTableRows"><td colspan="8"><hr></td></tr>'; + echo '<tr class="OddTableRows">'; + } else { + echo '<tr class="OddTableRows"><td colspan="8"><hr></td></tr>'; + echo '<tr class="EvenTableRows">'; + } + echo '<td class="number">' . _('GRAND Total') . '</td> + <td class="number">' . locale_number_format($CumulativeTotalSales,$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + <td class="number">' . locale_number_format($CumulativeTotalRefunds,$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + <td class="number">' . locale_number_format($CumulativeTotalNetSales,$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + <td class="number">' . locale_number_format($CumulativeTotalCost,$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + <td class="number">' . locale_number_format($CumulativeTotalGP,$_SESSION['CompanyRecord']['decimalplaces']) . '</td> + </tr>'; + + echo '</table>'; + +} //end of if user hit show sales +include('includes/footer.inc'); +?> \ No newline at end of file Modified: trunk/includes/session.inc =================================================================== --- trunk/includes/session.inc 2011-11-27 12:11:15 UTC (rev 8358) +++ trunk/includes/session.inc 2011-11-27 12:11:28 UTC (rev 8359) @@ -13,7 +13,7 @@ header('Location:' . $rootpath . '/install/index.php'); } include($PathPrefix . 'config.php'); -$DBVersion=102; +$DBVersion=103; if (isset($SessionSavePath)){ session_save_path($SessionSavePath); } Modified: trunk/index.php =================================================================== --- trunk/index.php 2011-11-27 12:11:15 UTC (rev 8358) +++ trunk/index.php 2011-11-27 12:11:28 UTC (rev 8359) @@ -53,6 +53,7 @@ _('Order Status Report'), _('Orders Invoiced Reports'), _('Daily Sales Inquiry'), + _('Sales By Category Inquiry'), _('Top Sellers Inquiry'), _('Order Delivery Differences Report'), _('Delivery In Full On Time (DIFOT) Report'), @@ -66,6 +67,7 @@ '/PDFOrderStatus.php', '/PDFOrdersInvoiced.php', '/DailySalesInquiry.php', + '/SalesCategoryPeriodInquiry.php', '/SalesTopItemsInquiry.php', '/PDFDeliveryDifferences.php', '/PDFDIFOT.php', Added: trunk/sql/mysql/updates/103.php =================================================================== --- trunk/sql/mysql/updates/103.php (rev 0) +++ trunk/sql/mysql/updates/103.php 2011-11-27 12:11:28 UTC (rev 8359) @@ -0,0 +1,10 @@ +<?php + +/* Include the new script for printing quotations in Portrait + */ + +InsertRecord('pagesecurity', array('script', 'security'), array('SalesCategoryPeriodInquiry.php',1), array('script', 'security'), array('SalesCategoryPeriodInquiry.php',1), $db); + +UpdateDBNo(103, $db); + +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |