diff --git a/application/models/Orders.php b/application/models/Orders.php index 810f6b0f..ef45c786 100644 --- a/application/models/Orders.php +++ b/application/models/Orders.php @@ -2024,66 +2024,62 @@ public static function incomeQuarter($year = null ) { * @return ArrayObject */ public static function incomeMonthly($year = null ) { + $baseArray = array('grandtotal' => 0, 'total' => 0, 'vat' => 0, 'growPercent' => 0, 'growDiff' => 0); + $yearIncome = array(); + $present_year = !empty($year) ? $year : date("Y"); $last_year = $present_year - 1; // Get the invoices montly total - $income = Doctrine_Query::create ()->select ( "invoice_id, MONTH(i.invoice_date) as monthly, YEAR(i.invoice_date) as year, SUM(o.grandtotal) as grandtotal, SUM(o.total) as total, SUM(o.vat) as vat" ) + $incomes = Doctrine_Query::create ()->select ( "invoice_id, MONTH(i.invoice_date) as month, YEAR(i.invoice_date) as year, SUM(o.grandtotal) as grandtotal, SUM(o.total) as total, SUM(o.vat) as vat" ) ->from ( 'Invoices i' ) ->leftJoin ( 'i.Orders o' ) ->where('o.status_id = ?', Statuses::id('complete', 'orders')) - ->groupBy("monthly, year") - ->orderBy('year, monthly') + ->groupBy("month, year") + ->orderBy('year, month') ->execute ( null, Doctrine::HYDRATE_ARRAY ); // Get the credit notes montly total - $creditnotes = Doctrine_Query::create ()->select ( "creditnote_id, MONTH(c.creationdate) as monthly, YEAR(c.creationdate) as year, SUM(c.total) as grandtotal, SUM(c.total_net) as total, SUM(c.total_vat) as vat" ) + $creditnotes = Doctrine_Query::create ()->select ( "creditnote_id, MONTH(c.creationdate) as month, YEAR(c.creationdate) as year, SUM(c.total) as grandtotal, SUM(c.total_net) as total, SUM(c.total_vat) as vat" ) ->from ( 'CreditNotes c' ) - ->groupBy("monthly, year") - ->orderBy('year, monthly') + ->groupBy("month, year") + ->orderBy('year, month') ->execute ( null, Doctrine::HYDRATE_ARRAY ); - - for ($i=0; $i 0){ - $diff = $income[$i]['total'] - $item['total']; - $percent = $diff / $item['total'] * 100; - }else{ - $percent = 0; - } - - $income[$i]['old'] = $item; - - // Assign the yield percentage value - $income[$i]['yieldrate'] = number_format($percent, 2, ',', '');; - continue; - } - } + $yearIncome[$lastYear][$month] = array_merge(array('month'=>$month,'year'=>$lastYear), $baseArray); + $yearIncome[$currentYear][$month] = array_merge(array('month'=>$month,'year'=>$currentYear), $baseArray); } - -// Zend_Debug::dump($income); -// Zend_Debug::dump($creditnotes); - - foreach ($creditnotes as $item){ - // If the selected year is before last year and the quarter is the same do + + // Merge income to year array + foreach ( $incomes as $income ) { + unset($income['invoice_id']); + $income['month'] = str_pad($income['month'],2,'0',STR_PAD_LEFT); + $month = $income['month']; + $year = $income['year']; + // Calculate the Yield percentage on diff between years + if ( $year == $currentYear ) { + $diff = $income['total'] - $yearIncome[$lastYear][$month]['total']; + $percent = round($diff / $income['total'] * 100); + $income['growPercent'] = $percent; + $income['growDiff'] = $diff; + } + + $yearIncome[$year][$month] = array_merge($yearIncome[$year][$month], $income); } - - return !empty($income[0]) ? $income: array(); + + return $yearIncome; + } /** diff --git a/application/modules/admin/views/helpers/Summary.php b/application/modules/admin/views/helpers/Summary.php index fd1befdd..4256a0b9 100644 --- a/application/modules/admin/views/helpers/Summary.php +++ b/application/modules/admin/views/helpers/Summary.php @@ -19,4 +19,4 @@ public function summary($year = null) { return $this->view->render ( 'partials/summary.phtml' ); } -} +} \ No newline at end of file diff --git a/application/modules/admin/views/scripts/index/index.phtml b/application/modules/admin/views/scripts/index/index.phtml index ca111b39..5e59c67d 100644 --- a/application/modules/admin/views/scripts/index/index.phtml +++ b/application/modules/admin/views/scripts/index/index.phtml @@ -3,13 +3,12 @@
- summary()?> + summary(); ?>
widget(Orders::Last($statuses), "Processing Orders", "orders")?> diff --git a/application/modules/admin/views/scripts/partials/summary.phtml b/application/modules/admin/views/scripts/partials/summary.phtml index 3891470b..858a1d14 100644 --- a/application/modules/admin/views/scripts/partials/summary.phtml +++ b/application/modules/admin/views/scripts/partials/summary.phtml @@ -27,13 +27,14 @@ income_monthly; ?> +
    - +
  • currency($inc['total'], array('currency' => $currency)) ?> translate('%s° month of %s', $inc['monthly'], $inc['year'])?> @@ -43,9 +44,74 @@ ">%
  • - +
+ + + + +
+
\ No newline at end of file diff --git a/library/Shineisp/Commons/Hasher.php b/library/Shineisp/Commons/Hasher.php index eb469356..8ff1cb24 100644 --- a/library/Shineisp/Commons/Hasher.php +++ b/library/Shineisp/Commons/Hasher.php @@ -5,13 +5,95 @@ * */ class Shineisp_Commons_Hasher { - public static function generateSalt() { - $salt_pattern = '0, 1, 2, 6, 7, 10, 11, 12, 14, 15, 20, 21, 25, 29, 32, 36, 37, 38, 39, 40'; - return preg_split('/,\s*/', $salt_pattern); - } + /** + * Create the salt code + * @return string + */ + public static function createSalt(){ + $arrChars = array(); + $saltLength = 28; + + while ( count ( $arrChars ) < $saltLength ) { + $i = rand(0, 40); + $arrChars[$i] = $i; + } + + asort($arrChars); + + return implode(',', $arrChars); + } + + /** + * Get the salt code + * @return boolean or string + */ + public static function getSalt() { + $filename = APPLICATION_PATH . "/configs/config.xml"; + + // Check the existence of the config.xml file + if (file_exists ($filename)) { + + // Load the config file + $xml = simplexml_load_file ( $filename ); + if(empty($xml->config->saltpattern)){ + // create a salt pattern and save it in the config file + self::resetSalt(); + + // reload the config file + $xml = simplexml_load_file ( $filename ); + }else{ + return preg_split('/,\s*/', $xml->config->saltpattern); + } + + return preg_split('/,\s*/', $xml->config->saltpattern); + }else{ + throw new Exception("Error on reading the xml file in " . APPLICATION_PATH . "/configs/config.xml
Please check the folder permissions"); + } + } + + /** + * Create the salt code + * A salt code is a random set of bytes of a + * fixed length that is added to + * the input of a hash algorithm. + */ + public static function resetSalt() { + + $saltpattern = self::createSalt(); + + $filename = APPLICATION_PATH . "/configs/config.xml"; + if (file_exists ($filename)) { + $xml = simplexml_load_file ( $filename ); + if(empty($xml->config->saltpattern)){ + $config = $xml->config; + $config->addChild('saltpattern', $saltpattern); + }else{ + $xml->config->saltpattern = $saltpattern; + } + + // Get the xml string + $xmlstring =$xml->asXML(); + + // Prettify and save the xml configuration + $dom = new DOMDocument(); + $dom->loadXML($xmlstring); + $dom->formatOutput = true; + $formattedXML = $dom->saveXML(); + + // Save the config xml file + if(@$dom->save(APPLICATION_PATH . "/configs/config.xml")){ + return true; + }else{ + throw new Exception("Error on saving the xml file in " . APPLICATION_PATH . "/configs/config.xml
Please check the folder permissions"); + } + + }else{ + throw new Exception('There was a problem to save data in the config.xml file. Permission file problems?'); + } + } public function hash_string($password, $salt = FALSE) { - $salt_pattern = self::generateSalt(); + $salt_pattern = self::getSalt(); if ($salt === FALSE) { // Create a salt seed, same length as the number of offsets in the pattern @@ -51,7 +133,7 @@ public function hash_string($password, $salt = FALSE) { public function unhash_string($password) { - $salt_pattern = self::generateSalt(); + $salt_pattern = self::getSalt(); $clean_password = ''; $password = str_split($password, 1); @@ -73,7 +155,7 @@ private function hash($str) public function find_salt($password) { - $salt_pattern = self::generateSalt(); + $salt_pattern = self::getSalt(); $salt = ''; foreach ($salt_pattern as $i => $offset) diff --git a/public/skins/admin/base/js/smartresize.js b/public/skins/admin/base/js/smartresize.js new file mode 100644 index 00000000..f6dc241b --- /dev/null +++ b/public/skins/admin/base/js/smartresize.js @@ -0,0 +1,27 @@ +(function($,sr){ + + // debouncing function from John Hann + // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/ + var debounce = function (func, threshold, execAsap) { + var timeout; + + return function debounced () { + var obj = this, args = arguments; + function delayed () { + if (!execAsap) + func.apply(obj, args); + timeout = null; + }; + + if (timeout) + clearTimeout(timeout); + else if (execAsap) + func.apply(obj, args); + + timeout = setTimeout(delayed, threshold || 100); + }; + } + // smartresize + jQuery.fn[sr] = function(fn){ return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); }; + +})(jQuery,'smartresize'); diff --git a/public/skins/admin/base/layout.xml b/public/skins/admin/base/layout.xml index 4f1236ea..7423b906 100644 --- a/public/skins/admin/base/layout.xml +++ b/public/skins/admin/base/layout.xml @@ -43,6 +43,7 @@ /js/admin.js /js/iscroll.js /js/widget.js + /js/smartresize.js /css/html.css