Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 39 additions & 43 deletions application/models/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<count($income); $i++){

// Yield Percentage
$income[$i]['yieldrate'] = 0;

// Before the last year
$income[$i]['old'] = array();

//print_r($incomes);

$currentYear = date('Y');
$lastYear = $currentYear -1;

// Cycle months
for ( $i = 01; $i <= 12; $i++ ) {
$month = str_pad($i,2,'0',STR_PAD_LEFT);

// For each Quarter do
foreach ($income as $item){

// If the selected year is before last year and the quarter is the same do
if($item['year'] == ($income[$i]['year'] - 1) && $item['monthly'] == $income[$i]['monthly']){

// Calculate the Yield percentage on diff
if($income[$i]['total'] > 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;

}

/**
Expand Down
2 changes: 1 addition & 1 deletion application/modules/admin/views/helpers/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ public function summary($year = null) {
return $this->view->render ( 'partials/summary.phtml' );
}

}
}
3 changes: 1 addition & 2 deletions application/modules/admin/views/scripts/index/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
<div class="portlets">

<div class="column column-large" id="col0">
<?= $this->summary()?>
<?php echo $this->summary(); ?>
</div>

<div class="column column-fixed column-large" id="col1">
<div class="portlet" id="processing_order">
<?php
// Open, Processing and Waiting Reply tickets
$statuses = array(Statuses::id("processing", "orders"), Statuses::id("pending", "orders"));
?>
<?php echo $this->widget(Orders::Last($statuses), "Processing Orders", "orders")?>
Expand Down
70 changes: 68 additions & 2 deletions application/modules/admin/views/scripts/partials/summary.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
<?php endif;?>

<?php $income = $this->income_monthly; ?>

<?php if(!empty($income)): ?>
<div class="portlet" id="income-month">
<div class="widget-wrapper">
<div class="widget-header"><h3><a href="#"><?php echo $this->translate('Income by Month')?></a></h3></div>
<div class="widget-content">
<ul class="stats">
<?php foreach($income as $inc):?>
<?php /* foreach($income as $inc):?>
<?php if($inc['year'] == date('Y')): ?>
<li title="<? echo $this->translate('Grand Total: %s - Total: %s - VAT: %s', $this->currency($inc['grandtotal'], array('currency' => $currency)), $this->currency($inc['total'], array('currency' => $currency)), $this->currency($inc['vat'], array('currency' => $currency))) ?>"><strong><?php echo $this->currency($inc['total'], array('currency' => $currency)) ?></strong>
<small><?php echo $this->translate('%s° month of %s', $inc['monthly'], $inc['year'])?></small>
Expand All @@ -43,9 +44,74 @@
<span class="<?php echo ($inc['yieldrate'] > 0) ? "green" : "red" ?>"><?php echo $inc['yieldrate'] ?>%</span>
</li>
<?php endif; ?>
<?php endforeach;?>
<?php endforeach; */ ?>
</ul>
</div>
</div>

<script type="text/javascript" src="//www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawMonthlyIncomeChart);
function drawMonthlyIncomeChart() {
var data = new google.visualization.DataTable({
cols: [{id: 'month', label: '<?=$this->translate('Month')?>', type: 'string'},
{id: 'grandTotal', label: '<?=$this->translate('Grand Total')?> <?=$inc['year']?>', type: 'number'},
{'p': {'role':'tooltip','html':true}}, // tooltip for current year
{id: 'grandTotalLast', label: '<?=$this->translate('Grand Total')?> <?=$inc['old']['year']?>', type: 'number'},
{'p': {'role':'tooltip','html':true}} // tooltip for previous year
],

rows: [
<?php
$currentYear = date('Y');
$lastYear = $currentYear -1;
$arrGrafico = array();
foreach($income[$currentYear] as $yearIncome):
$month = $yearIncome['month'];

$currentMonthTitle = strftime('%B %Y', mktime(0,0,0,$month,1,$currentYear));
$lastMonthTitle = strftime('%B %Y', mktime(0,0,0,$month,1,$lastYear));

$total = (isset($yearIncome['total'])) ? $yearIncome['total'] : 0;
$oldTotal = (isset($income[$lastYear][$month]['total'])) ? $income[$lastYear][$month]['total'] : 0;
$growDiff = (isset($yearIncome['growDiff'])) ? $yearIncome['growDiff'] : 0;
$growPercent = (isset($yearIncome['growPercent'])) ? $yearIncome['growPercent'] : 0;

$spanColor = ( $growPercent > 0 ) ? 'green' : 'red';

$arrColonne = array();
$arrColonne[] = "{v: '".$yearIncome['month']."'}";
$arrColonne[] = "{v:".$total."}";
$arrColonne[] = "{v:'<div style=\'font-size:14px\'><strong>".$currentMonthTitle."</strong><br/>".$this->translate('Grand Total').": &euro; ".$total."<br/>".$this->translate('Grand Total')." ".$lastYear.": &euro; ".$oldTotal."<br/>".$this->translate('Grow').": <span class=\'".$spanColor."\'>&euro; ".$growDiff." (".$growPercent."%)</span></div>'}"; // tooltip for current year
$arrColonne[] = "{v:".$oldTotal."}";
$arrColonne[] = "{v:'<div style=\'font-size:14px\'><strong>".$lastMonthTitle."</strong><br/>".$this->translate('Grand Total')." ".$lastYear.": &euro; ".$oldTotal."'}"; // tooltip for previous year

$arrGrafico[] = "{c:[".implode(',',$arrColonne)."]}\n";
endforeach;

echo implode(',', $arrGrafico);

?>
]

}, 0.6);

var options = {
curveType: 'function'
,tooltip: {isHtml: true}
};

var chart = new google.visualization.LineChart(document.getElementById('grafico'));
chart.draw(data, options);

$(window).smartresize(function(){
chart.draw(data, options);
});
}
</script>

<div id='grafico'></div>

</div>
<?php endif;?>
96 changes: 89 additions & 7 deletions library/Shineisp/Commons/Hasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <br/>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 <br/>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
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions public/skins/admin/base/js/smartresize.js
Original file line number Diff line number Diff line change
@@ -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');
1 change: 1 addition & 0 deletions public/skins/admin/base/layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<js>/js/admin.js</js>
<js>/js/iscroll.js</js>
<js>/js/widget.js</js>
<js>/js/smartresize.js</js>

<!-- In this case the files must be located in /skins/default/YOURTEMPLATE/css folder -->
<css>/css/html.css</css>
Expand Down