Merge branch 'master' of github.com:crunchbutton/crunchbutton
This commit is contained in:
commit
f06f645d6d
@ -3,8 +3,6 @@
|
||||
class Controller_Api_Test_Sandbox extends Cana_Controller {
|
||||
public function init(){
|
||||
|
||||
die('not today!');
|
||||
|
||||
$out = [ 'ok' => [], 'no' => [] ];
|
||||
|
||||
$admins = Admin::q( 'SELECT * FROM admin WHERE active = 0 OR active IS NULL ORDER BY name ASC' );
|
||||
@ -15,10 +13,12 @@ class Controller_Api_Test_Sandbox extends Cana_Controller {
|
||||
if( $change_set->id_admin_change_set ){
|
||||
$date = new DateTime( $change_set->date, new DateTimeZone( c::config()->timezone ) );
|
||||
$admin->date_terminated = $date->format( 'Y-m-d' );
|
||||
// $admin->save();
|
||||
$admin->save();
|
||||
$out[ 'ok' ][ $admin->id_admin ] = $admin->name;
|
||||
} else {
|
||||
$admin->date_terminated = '2015-01-01';
|
||||
$out[ 'no' ][ $admin->id_admin ] = $admin->name;
|
||||
$admin->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,17 +2,11 @@
|
||||
|
||||
class Crunchbutton_Cron_Job_CSTicketsDigest extends Crunchbutton_Cron_Log {
|
||||
public function run($params){
|
||||
$supports = Crunchbutton_Support::q('SELECT
|
||||
support.*
|
||||
FROM support
|
||||
WHERE
|
||||
support.type != "WARNING"
|
||||
AND support.datetime > date_sub(now(), interval 1 day)
|
||||
ORDER BY support.id_support ASC
|
||||
limit 250' );
|
||||
$params = array( 'to' => 'digests@_DOMAIN_', 'messages'=> $supports );
|
||||
$email = new Crunchbutton_Email_CSDigest($params);
|
||||
$tickets = Crunchbutton_Support::dailyDigest( 1 );
|
||||
$params = array( 'to' => 'digests@_DOMAIN_', 'tickets' => $tickets );
|
||||
$email = new Crunchbutton_Email_CSDigest( $params );
|
||||
$email->send();
|
||||
// echo $email->message();
|
||||
// it always must call finished method at the end
|
||||
$this->finished();
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ class Crunchbutton_Email_CSDigest extends Email{
|
||||
|
||||
$this->buildView($params);
|
||||
|
||||
$params['messageHtml'] = $this->view()->render('cs/digest',['display' => true, 'set' => ['messages' => $params['messages'], ]]);
|
||||
$params['messageHtml'] = $this->view()->render('cs/digest',['display' => true, 'set' => ['tickets' => $params['tickets'], ]]);
|
||||
|
||||
parent::__construct($params);
|
||||
}
|
||||
|
||||
@ -168,11 +168,14 @@ class Crunchbutton_Settlement extends Cana_Model {
|
||||
public function workedShiftsByPeriod( $id_admin, $filters ){
|
||||
|
||||
$admin = Admin::o( $id_admin );
|
||||
if( $admin->date_terminated ){
|
||||
$where = 'AND DATE_FORMAT( cs.date_start, "%Y-%m-%d" ) <= "' . $admin->date_terminated . '"';
|
||||
} else {
|
||||
$where = '';
|
||||
if( !$admin->active ){
|
||||
if( $admin->date_terminated ){
|
||||
$where = 'AND DATE_FORMAT( cs.date_start, "%Y-%m-%d" ) <= "' . $admin->date_terminated . '"';
|
||||
} else {
|
||||
$where = 'AND 1 = 0';
|
||||
}
|
||||
}
|
||||
|
||||
$start = ( new DateTime( $filters[ 'start' ] ) )->format( 'Y-m-d' );
|
||||
$end = ( new DateTime( $filters[ 'end' ] ) )->format( 'Y-m-d' );
|
||||
$query = 'SELECT cs.*, asa.id_admin_shift_assign FROM community_shift cs
|
||||
|
||||
@ -806,7 +806,59 @@ class Crunchbutton_Support extends Cana_Table_Trackchange {
|
||||
}
|
||||
|
||||
public function comments(){
|
||||
return Crunchbutton_Support_Message::q( 'SELECT * FROM support_message sm WHERE sm.id_support = "' . $this->id_support . '" AND sm.type = "' . Crunchbutton_Support_Message::TYPE_NOTE . '" AND `from` != "' . Crunchbutton_Support_Message::TYPE_FROM_SYSTEM . '" ORDER BY sm.id_support_message DESC' );
|
||||
return Crunchbutton_Support_Message::q( 'SELECT * FROM support_message sm WHERE sm.id_support = "' . $this->id_support . '" AND sm.type = "' . Crunchbutton_Support_Message::TYPE_NOTE . '" AND `from` != "' . Crunchbutton_Support_Message::TYPE_FROM_SYSTEM . '" ORDER BY sm.date DESC' );
|
||||
}
|
||||
|
||||
public function dailyDigest( $days = 1 ){
|
||||
|
||||
$query = 'SELECT DISTINCT( sm.id_support ) AS id, s.* FROM support_message sm
|
||||
INNER JOIN support s ON s.id_support = sm.id_support
|
||||
WHERE sm.date > DATE_SUB( NOW(), interval ' . $days . ' day ) AND s.type != "' . Crunchbutton_Support::TYPE_WARNING . '"
|
||||
ORDER BY sm.date ASC';
|
||||
|
||||
$tickets = Crunchbutton_Support::q( $query );
|
||||
$out = [ 'open' => [], 'closed' => [] ];
|
||||
foreach( $tickets as $ticket ){
|
||||
$data = [];
|
||||
$data[ 'id_support' ] = $ticket->id_support;
|
||||
$data[ 'phone' ] = Crunchbutton_Util::format_phone( $ticket->firstMessage()->phone );
|
||||
$data[ 'name' ] = $ticket->firstMessage()->name;
|
||||
$messages = Crunchbutton_Support_Message::q( 'SELECT * FROM support_message sm WHERE id_support = "' . $ticket->id_support . '" AND sm.date > DATE_SUB( NOW(), interval ' . $days . ' day )' );
|
||||
$count = 0;
|
||||
$prev_type = null;
|
||||
$prev_from = null;
|
||||
$prev_body = null;
|
||||
foreach( $messages as $message ){
|
||||
if( $message->from == Crunchbutton_Support_Message::TYPE_FROM_SYSTEM ||
|
||||
$message->body == '(Ticket created at cockpit)' ){
|
||||
continue;
|
||||
}
|
||||
if( !$data[ 'date' ] ){
|
||||
$data[ 'date' ] = $message->date()->format( 'M jS g:i a' );
|
||||
}
|
||||
if( $prev_from == $message->from && $prev_type == $message->type ){
|
||||
$join = ( ctype_upper( substr( $message->body, 0 ) ) ) ? '' : '<br>';
|
||||
$data[ 'messages' ][ $count ][ 'body' ] .= $join . $message->body;
|
||||
} else {
|
||||
$count++;
|
||||
$data[ 'messages' ][ $count ] = [ 'type' => $message->from , 'body' => $message->body ];
|
||||
}
|
||||
$prev_type = $message->type;
|
||||
$prev_from = $message->from;
|
||||
$prev_body = $message->body;
|
||||
}
|
||||
if( count( $data[ 'messages' ] ) ){
|
||||
if( $ticket->status == Crunchbutton_Support::STATUS_OPEN ){
|
||||
$data[ 'status' ] = 'Opened';
|
||||
$out[ 'open' ][] = $data;
|
||||
} else {
|
||||
$data[ 'status' ] = 'Closed';
|
||||
$out[ 'closed' ][] = $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,23 +1,66 @@
|
||||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<h1>Customer Service Morning Digest</h1>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Time</th>
|
||||
<th>Message</th>
|
||||
<th>Phone</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($messages as $message) : ?>
|
||||
<tr>
|
||||
<td><?= $message->firstMessage()->name ?></td>
|
||||
<td nowrap="nowrap"><?= DATE_FORMAT(new DateTime($message->firstMessage()->date), 'g:i A')?></td>
|
||||
<td><?= $message->firstMessage()->body ?></td>
|
||||
<td><?= $message->firstMessage()->phone ?></td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php
|
||||
$ticked_opened = count( $tickets[ 'open' ] );
|
||||
$ticked_closed = count( $tickets[ 'closed' ] );
|
||||
?>
|
||||
<p class="summary">
|
||||
<span class="open">
|
||||
Opened: <?php echo $ticked_opened; ?>
|
||||
</span>
|
||||
<br>
|
||||
<span class="closed">
|
||||
Closed: <?php echo $ticked_closed; ?>
|
||||
</span>
|
||||
<br>
|
||||
Total tickets: <?php echo ( $ticked_opened + $ticked_closed ); ?>
|
||||
</p>
|
||||
<?php
|
||||
|
||||
// $ = 'style="background: #e6e6e6;" bgcolor="#e6e6e6">
|
||||
$client_row_style = "font-size: 12px; font-family: 'Helvetica', 'Arial' !important; padding: 5px 3px 5px 5px; border: 0;background: #e6e6e6; bgcolor=#e6e6e6";
|
||||
$crunchbutton_row_style = "font-size: 12px; font-family: 'Helvetica', 'Arial' !important; padding: 5px 3px 5px 5px; border: 0;background: #e6e6e6; bgcolor=#F5F5F5";
|
||||
$thead_th_row = "font-family: 'Helvetica', 'Arial' !important; padding-top: 25px; text-align: left; font-size: 13px; padding-right: 3px;";
|
||||
$body_td_row = "font-size: 12px; font-family: 'Helvetica', 'Arial' !important; padding: 5px 3px 5px 5px; border: 0;";
|
||||
?>
|
||||
<?php foreach ( $tickets as $status => $tickets ) { ?>
|
||||
<?php if( $status == 'open' ){ ?>
|
||||
<h2 style="font-size: 16px; font-family: 'Helvetica', 'Arial' !important; color: red; margin: 30px 0 0px;">Opened tickets</h2>
|
||||
<?php } else { ?>
|
||||
<h2 style="font-size: 16px; font-family: 'Helvetica', 'Arial' !important; color: green; margin: 30px 0 0px;">Closed tickets</h2>
|
||||
<?php } ?>
|
||||
<table>
|
||||
<?php foreach( $tickets as $ticket ) { ?>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="<?php echo $thead_th_row ?>" align="left"><a href="https://cockpit.la/ticket/<?php echo $ticket[ 'id_support' ]; ?>"><?php echo $ticket[ 'id_support' ]; ?></a></th>
|
||||
<th style="<?php echo $thead_th_row ?>" align="left"><?php echo $ticket[ 'status' ]; ?></th>
|
||||
<th style="<?php echo $thead_th_row ?>" align="left"><?php echo $ticket[ 'date' ]; ?></th>
|
||||
<th style="<?php echo $thead_th_row ?>" align="left"><?php if( $ticket[ 'name' ] ){ echo $ticket[ 'name' ]; } else { echo '-'; } ?></th>
|
||||
<th style="<?php echo $thead_th_row ?>" align="left"><?php echo $ticket[ 'phone' ]; ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if( count( $ticket[ 'messages' ] ) ) { ?>
|
||||
<?php foreach( $ticket[ 'messages' ] as $message ) { ?>
|
||||
<tr style="<?php if($message[ 'type' ] == 'client' ){ echo $client_row_style; } else { $crunchbutton_row_style; } ?>">
|
||||
<td valign="top" style="<?php echo $body_td_row; ?>">
|
||||
<?php if( $message[ 'type' ] == 'client' ) { ?>
|
||||
Client
|
||||
<?php } else { ?>
|
||||
Crunchbutton
|
||||
<?php } ?>
|
||||
</td>
|
||||
<td colspan="4" style="<?php echo $body_td_row; ?>">
|
||||
<?php echo $message[ 'body' ]; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
<tr>
|
||||
<td style="font-size: 12px; font-family: 'Helvetica', 'Arial' !important; border-top-color: #999; border-top-style: solid; padding: 5px 3px 5px 5px; border-width: 2px 0 0;" colspan="5"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
<?php } ?>
|
||||
</table>
|
||||
<?php } ?>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user