partial #1465
This commit is contained in:
parent
40073d04bc
commit
a33cda7a08
@ -427,6 +427,11 @@ class Crunchbutton_Promo extends Cana_Table
|
|||||||
$gifts = self::q($query);
|
$gifts = self::q($query);
|
||||||
return $gifts;
|
return $gifts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function groups(){
|
||||||
|
return Crunchbutton_Promo_Group::q( "SELECT g.* FROM promo_group g INNER JOIN promo_group_promo pgp ON pgp.id_promo_group = g.id_promo_group AND pgp.id_promo = {$this->id_promo}" );
|
||||||
|
}
|
||||||
|
|
||||||
public function order_reference(){
|
public function order_reference(){
|
||||||
return Order::o($this->id_order_reference);
|
return Order::o($this->id_order_reference);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,19 +20,39 @@ class Crunchbutton_Promo_Group extends Cana_Table
|
|||||||
|
|
||||||
public function giftcards(){
|
public function giftcards(){
|
||||||
if ( !isset( $this->_giftcards ) ) {
|
if ( !isset( $this->_giftcards ) ) {
|
||||||
$sql = "SELECT * FROM promo p INNER JOIN promo_group_promo pgp ON p.id_promo = pgp.id_promo AND pgp.id_promo_group = {$this->id_promo_group}";
|
$query = "SELECT p.* FROM promo p INNER JOIN promo_group_promo pgp ON p.id_promo = pgp.id_promo AND pgp.id_promo_group = {$this->id_promo_group}";
|
||||||
$this->_giftcards = Promo::q($sql, $this->db());
|
$this->_giftcards = Promo::q( $query, $this->db() );
|
||||||
}
|
}
|
||||||
return $this->_giftcards;
|
return $this->_giftcards;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function giftcards_redeemed(){
|
||||||
|
if ( !isset( $this->_giftcards_redeemed ) ) {
|
||||||
|
$query = "SELECT p.* FROM promo p
|
||||||
|
INNER JOIN promo_group_promo pgp ON p.id_promo = pgp.id_promo AND pgp.id_promo_group = {$this->id_promo_group}
|
||||||
|
INNER JOIN credit c ON p.id_promo = c.id_promo AND p.id_promo = c.id_promo";
|
||||||
|
$this->_giftcards_redeemed = Promo::q( $query, $this->db() );
|
||||||
|
}
|
||||||
|
return $this->_giftcards_redeemed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function giftcards_redeemed_total(){
|
||||||
|
$query = "SELECT COUNT(*) AS total FROM promo p
|
||||||
|
INNER JOIN promo_group_promo pgp ON p.id_promo = pgp.id_promo AND pgp.id_promo_group = {$this->id_promo_group}
|
||||||
|
INNER JOIN credit c ON p.id_promo = c.id_promo AND p.id_promo = c.id_promo";
|
||||||
|
$total = c::db()->get( $query );
|
||||||
|
return $total->_items[0]->total;
|
||||||
|
}
|
||||||
|
|
||||||
public function remove_giftcards(){
|
public function remove_giftcards(){
|
||||||
$query = "DELETE FROM promo_group_promo WHERE id_promo_group = {$this->id_promo_group}";
|
$query = "DELETE FROM promo_group_promo WHERE id_promo_group = {$this->id_promo_group}";
|
||||||
Cana::db()->query( $query );
|
Cana::db()->query( $query );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function giftcards_total(){
|
public function giftcards_total(){
|
||||||
return $this->giftcards()->count();
|
$query = "SELECT COUNT(*) AS total FROM promo p INNER JOIN promo_group_promo pgp ON p.id_promo = pgp.id_promo AND pgp.id_promo_group = {$this->id_promo_group}";
|
||||||
|
$total = c::db()->get( $query );
|
||||||
|
return $total->_items[0]->total;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save_giftcards( $range ){
|
public function save_giftcards( $range ){
|
||||||
@ -80,32 +100,36 @@ class Crunchbutton_Promo_Group extends Cana_Table
|
|||||||
|
|
||||||
public function range(){
|
public function range(){
|
||||||
if( $this->giftcards_total() > 0 ){
|
if( $this->giftcards_total() > 0 ){
|
||||||
$giftcards = $this->giftcards();
|
$query = "SELECT p.id_promo FROM promo p INNER JOIN promo_group_promo pgp ON p.id_promo = pgp.id_promo AND pgp.id_promo_group = {$this->id_promo_group}";
|
||||||
|
$giftcards = c::db()->get( $query );
|
||||||
$ids = [];
|
$ids = [];
|
||||||
foreach ( $giftcards as $giftcard ) {
|
foreach ( $giftcards as $giftcard ) {
|
||||||
$ids[] = intval( $giftcard->id_promo );
|
$ids[] = intval( $giftcard->id_promo );
|
||||||
}
|
}
|
||||||
|
|
||||||
sort( $ids );
|
sort( $ids );
|
||||||
$groups = array();
|
|
||||||
|
|
||||||
for( $i = 0; $i < count( $ids ); $i++ ){
|
$groups = array();
|
||||||
if( $i > 0 && ( $ids[$i - 1] == $ids[ $i ] - 1 ) ){
|
$total = sizeof( $ids );
|
||||||
array_push( $groups[ count( $groups ) - 1 ], $ids[ $i ] );
|
for( $i = 0; $i < $total; $i++ ){
|
||||||
|
if( $i > 0 && ( $ids[ $i - 1 ] == $ids[ $i ] - 1 ) ){
|
||||||
|
$groups[ count( $groups ) - 1 ][ 1 ] = $ids[ $i ];
|
||||||
} else {
|
} else {
|
||||||
array_push( $groups, array( $ids[ $i ] ) );
|
$groups[] = array( $ids[ $i ] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$str_group = '';
|
$str_group = '';
|
||||||
$commas = '';
|
$commas = '';
|
||||||
foreach($groups as $group){
|
foreach($groups as $group){
|
||||||
if( count( $group ) == 1 ){
|
if( count( $group ) == 1 ){
|
||||||
$str_group .= $commas . $group[ 0 ];
|
$str_group .= $commas . $group[ 0 ];
|
||||||
} else {
|
} else {
|
||||||
$str_group .= $commas . $group[0] . ' - ' . $group[count($group) - 1];
|
$str_group .= $commas . $group[0] . ' - ' . $group[ count( $group ) - 1];
|
||||||
}
|
}
|
||||||
$commas = ', ';
|
$commas = ', ';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $str_group;
|
return $str_group;
|
||||||
} else {
|
} else {
|
||||||
return '';
|
return '';
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
<td>Email</td>
|
<td>Email</td>
|
||||||
<td>Note</td>
|
<td>Note</td>
|
||||||
<td>Issued as</td>
|
<td>Issued as</td>
|
||||||
|
<td>Group</td>
|
||||||
<td>Redeemed</td>
|
<td>Redeemed</td>
|
||||||
</thead>
|
</thead>
|
||||||
<? foreach ($this->giftcards as $giftcard) : ?>
|
<? foreach ($this->giftcards as $giftcard) : ?>
|
||||||
@ -43,6 +44,20 @@
|
|||||||
<i class="icon-print"></i> Paper (print)
|
<i class="icon-print"></i> Paper (print)
|
||||||
<?php } else { ?> - <?php } ?>
|
<?php } else { ?> - <?php } ?>
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
<?php
|
||||||
|
$groups = $giftcard->groups();
|
||||||
|
if( $groups->count() > 0 ){
|
||||||
|
$commas = '';
|
||||||
|
foreach ( $groups as $group ) {
|
||||||
|
echo $commas . $group->name ;
|
||||||
|
$commas = ', ';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo '-';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</td>
|
||||||
<td class="center">
|
<td class="center">
|
||||||
<?php if( $wasUsed ) { ?>
|
<?php if( $wasUsed ) { ?>
|
||||||
<span class="badge badge-green">Redeemed</span>
|
<span class="badge badge-green">Redeemed</span>
|
||||||
|
|||||||
@ -8,7 +8,9 @@ $groups = $this->giftcards_groups;
|
|||||||
<thead>
|
<thead>
|
||||||
<td>Name</td>
|
<td>Name</td>
|
||||||
<td>Date</td>
|
<td>Date</td>
|
||||||
<td>Number of Gift cards</td>
|
<td>Range</td>
|
||||||
|
<td>Gift cards</td>
|
||||||
|
<td>Gift cards Redeemed</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
</thead>
|
</thead>
|
||||||
<?php foreach ( $groups as $group ) {
|
<?php foreach ( $groups as $group ) {
|
||||||
@ -17,7 +19,9 @@ $groups = $this->giftcards_groups;
|
|||||||
<tr>
|
<tr>
|
||||||
<td><?php echo $group->name;?> </td>
|
<td><?php echo $group->name;?> </td>
|
||||||
<td><?php echo $date->format('M jS Y')?> - <?php echo $date->format('g:i:s A')?> </td>
|
<td><?php echo $date->format('M jS Y')?> - <?php echo $date->format('g:i:s A')?> </td>
|
||||||
<td><?php echo $group->giftcards_total(); ?></td>
|
<td><?php echo $group->range(); ?></td>
|
||||||
|
<td><?php echo $group->giftcards_redeemed_total(); ?></td>
|
||||||
|
<td><?php echo $group->giftcards_redeemed_total(); ?></td>
|
||||||
<td style="width:150px;">
|
<td style="width:150px;">
|
||||||
<a href="/giftcards/groups/<?php echo $group->id_promo_group; ?>" class="btn btn-green admin-giftcard-group-new"><i class="icon-edit"></i> Edit</a>
|
<a href="/giftcards/groups/<?php echo $group->id_promo_group; ?>" class="btn btn-green admin-giftcard-group-new"><i class="icon-edit"></i> Edit</a>
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
$this->title2icon = 'group';
|
$this->title2icon = 'group';
|
||||||
|
|
||||||
$group = $this->group;
|
$group = $this->group;
|
||||||
|
|
||||||
if( $group->id_promo_group ){
|
if( $group->id_promo_group ){
|
||||||
$range = $group->range();
|
$range = $group->range();
|
||||||
}
|
}
|
||||||
@ -34,9 +35,16 @@
|
|||||||
<?php echo $group->giftcards_total(); ?>
|
<?php echo $group->giftcards_total(); ?>
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<span>Number of giftcards redeemed</span>
|
||||||
|
<span class="pull-right">
|
||||||
|
<?php echo $group->giftcards_redeemed_total(); ?>
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<li>
|
<li>
|
||||||
<span>Range of giftcards</span>
|
<span>Range of giftcards ids</span>
|
||||||
<span class="pull-right">
|
<span class="pull-right">
|
||||||
<input type="text" name="range" maxlength="250" id="range" value="<?php echo $range; ?>" />
|
<input type="text" name="range" maxlength="250" id="range" value="<?php echo $range; ?>" />
|
||||||
<div class="note large">
|
<div class="note large">
|
||||||
@ -61,8 +69,14 @@ $(function() {
|
|||||||
} );
|
} );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var processing = false;
|
||||||
|
|
||||||
function sendForm(){
|
function sendForm(){
|
||||||
|
|
||||||
|
if( processing ){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var name = $.trim( $( '#name' ).val() );
|
var name = $.trim( $( '#name' ).val() );
|
||||||
var range = $.trim( $( '#range' ).val() );
|
var range = $.trim( $( '#range' ).val() );
|
||||||
if( name == '' ){
|
if( name == '' ){
|
||||||
@ -73,6 +87,11 @@ function sendForm(){
|
|||||||
|
|
||||||
var data = { 'name' : name, 'range' : range };
|
var data = { 'name' : name, 'range' : range };
|
||||||
|
|
||||||
|
processing = true;
|
||||||
|
|
||||||
|
$( '.admin-giftcard-group-save' ).html( '<i class="icon-spinner icon-spin"></i> Please wait' );
|
||||||
|
|
||||||
|
|
||||||
var url = App.service + 'giftcard/group/<?php echo $group->id_promo_group; ?>';
|
var url = App.service + 'giftcard/group/<?php echo $group->id_promo_group; ?>';
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
@ -80,6 +99,7 @@ function sendForm(){
|
|||||||
data: data,
|
data: data,
|
||||||
url: url,
|
url: url,
|
||||||
success: function( json ) {
|
success: function( json ) {
|
||||||
|
processing = false;
|
||||||
if( json.error ){
|
if( json.error ){
|
||||||
alert( 'Error at saving the group!' );
|
alert( 'Error at saving the group!' );
|
||||||
} else {
|
} else {
|
||||||
@ -88,6 +108,7 @@ function sendForm(){
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function( ){
|
error: function( ){
|
||||||
|
processing = false;
|
||||||
alert( 'Error at saving the group!' );
|
alert( 'Error at saving the group!' );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user