Issue #1111 - Developing the button resend notification.

This commit is contained in:
Daniel Camargo 2013-04-29 10:01:41 -03:00
parent a5eb49e0c9
commit 7b04834a62
6 changed files with 60 additions and 2 deletions

View File

@ -15,6 +15,7 @@ class Controller_api_order extends Crunchbutton_Controller_Rest {
$repeat = 3;
switch (c::getPagePiece(3)) {
case 'refund':
if (!$order->get(0)->refund()) {
echo json_encode(['status' => 'false', 'errors' => 'failed to refund']);
@ -22,6 +23,17 @@ class Controller_api_order extends Crunchbutton_Controller_Rest {
}
break;
case 'resend_notification':
if( $_SESSION['admin'] ){
if ( $order->resend_notify() ) {
echo json_encode(['status' => 'success']);
exit;
} else {
echo json_encode(['status' => 'error']);
}
}
break;
case 'say':
header('Content-type: text/xml');
$message = '<Say voice="'.c::config()->twilio->voice.'">Press 1 to hear the order. Otherwise we will call back in 2 minutes.</Say>'

View File

@ -11,8 +11,8 @@ class Crunchbutton_Notification extends Cana_Table
public function send(Crunchbutton_Order $order) {
$env = c::env() == 'live' ? 'live' : 'dev';
if ($_SESSION['admin'] && c::config()->testphone[$_SESSION['username']]) {
c::config()->twilio->testnumber = c::config()->testphone[$_SESSION['username']];
if ($_SESSION['admin'] && c::config()->testphone->{ $_SESSION[ 'username' ] } ) {
c::config()->twilio->testnumber = c::config()->testphone->{ $_SESSION[ 'username' ] };
}
$num = ($env == 'live' ? $this->value : c::config()->twilio->testnumber);
$sms = ($env == 'live' ? $this->value : c::config()->twilio->testnumber);

View File

@ -9,6 +9,11 @@ class Crunchbutton_Notification_Log extends Cana_Table {
return self::q('select * from notification_log where id_order="'.$this->id_order.'"')->count();
}
public function deleteFromOrder( $id_order ){
$query = 'DELETE FROM notification_log WHERE id_order = ' . $id_order;
Cana::db()->query( $query );
}
public function notification() {
return Notification::o($this->id_notification);
}

View File

@ -520,6 +520,18 @@ class Crunchbutton_Order extends Cana_Table {
Crunchbutton_Hipchat_Notification::notifyOrder($order);
}
public function resend_notify(){
$order = $this;
Log::debug([ 'order' => $order->id_order, 'action' => 'restarting starting notification', 'notification_type' => $n->type, 'type' => 'notification']);
$order->confirmed = 0;
$order->save();
// Delete all the notification log in order to start a new one
Notification_Log::DeleteFromOrder( $order->id_order );
Cana::timeout(function() use($order) {
$order->notify();
});
}
public function confirm() {
if ($this->confirmed || !$this->restaurant()->confirmation) {

View File

@ -55,6 +55,15 @@
</td>
<td>
<?=$date->format('M jS Y')?><br /><br /><?=$date->format('g:i:s A')?>
<br/>
<br/>
<a href="javascript:;" class="resend_notification" data-confirmed="<?php echo $order->confirmed; ?>" data-uuid="<?=$order->uuid?>">Resend notification</a>
<br/><br/>
<?php if( $order->confirmed ) { ?>
Confirmed!
<?php } else { ?>
NOT confirmed.
<?php } ?>
</td>
<td><?=$order->restaurant()->name?></td>
<td style="width: 300px; white-space: normal;">

View File

@ -108,6 +108,26 @@
});
});
$(document).on('click', '.resend_notification', function() {
var el = $(this);
var question = 'Are you sure you want to resend the notification?';
if( parseFloat( el.attr( 'data-confirmed' ) ) > 0 ){
question += "\n";
question += 'This order was already confirmed!' ;
}
if (!confirm( question )) {
return;
}
$.getJSON('/api/order/' + el.attr('data-uuid') + '/resend_notification',function( json ) {
if( json.status == 'success' ){
alert('Notification resended!');
} else {
alert('Oops, error! Please try it again.');
}
});
});
$(document).on('click', '.admin-order-search', function() {
App.orders.load();
});