Skip to content

Commit

Permalink
changed some custoemr code
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkerr committed Jul 8, 2015
1 parent 86d9ee2 commit 0a42c05
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 112 deletions.
97 changes: 56 additions & 41 deletions upload/admin/controller/sale/customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1212,20 +1212,6 @@ public function history() {

$this->load->model('sale/customer');

if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateHistory()) {
$this->model_sale_customer->addHistory($this->request->get['customer_id'], $this->request->post['comment']);

$data['success'] = $this->language->get('text_success');
} else {
$data['success'] = '';
}

if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}

$data['text_no_results'] = $this->language->get('text_no_results');

$data['column_date_added'] = $this->language->get('column_date_added');
Expand All @@ -1243,8 +1229,8 @@ public function history() {

foreach ($results as $result) {
$data['histories'][] = array(
'comment' => $result['comment'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
'comment' => $result['comment'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
);
}

Expand All @@ -1263,25 +1249,30 @@ public function history() {
$this->response->setOutput($this->load->view('sale/customer_history.tpl', $data));
}

public function transaction() {
public function addHistory() {
$this->load->language('sale/customer');

$this->load->model('sale/customer');

if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->user->hasPermission('modify', 'sale/customer')) {
$this->model_sale_customer->addTransaction($this->request->get['customer_id'], $this->request->post['description'], $this->request->post['amount']);
$json = array();

$data['success'] = $this->language->get('text_success');
if (!$this->user->hasPermission('modify', 'sale/customer')) {
$json['error'] = $this->language->get('error_permission');
} else {
$data['success'] = '';
}
$this->load->model('sale/customer');

if (($this->request->server['REQUEST_METHOD'] == 'POST') && !$this->user->hasPermission('modify', 'sale/customer')) {
$data['error_warning'] = $this->language->get('error_permission');
} else {
$data['error_warning'] = '';
$this->model_sale_customer->addHistory($this->request->get['customer_id'], $this->request->post['comment']);

$json['success'] = $this->language->get('text_success');
}

$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}

public function transaction() {
$this->load->language('sale/customer');

$this->load->model('sale/customer');

$data['text_no_results'] = $this->language->get('text_no_results');
$data['text_balance'] = $this->language->get('text_balance');

Expand Down Expand Up @@ -1324,25 +1315,30 @@ public function transaction() {
$this->response->setOutput($this->load->view('sale/customer_transaction.tpl', $data));
}

public function reward() {
public function addTransaction() {
$this->load->language('sale/customer');

$this->load->model('sale/customer');

if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->user->hasPermission('modify', 'sale/customer')) {
$this->model_sale_customer->addReward($this->request->get['customer_id'], $this->request->post['description'], $this->request->post['points']);
$json = array();

$data['success'] = $this->language->get('text_success');
if (!$this->user->hasPermission('modify', 'sale/customer')) {
$json['error'] = $this->language->get('error_permission');
} else {
$data['success'] = '';
}
$this->load->model('sale/customer');

if (($this->request->server['REQUEST_METHOD'] == 'POST') && !$this->user->hasPermission('modify', 'sale/customer')) {
$data['error_warning'] = $this->language->get('error_permission');
} else {
$data['error_warning'] = '';
$this->model_sale_customer->addTransaction($this->request->get['customer_id'], $this->request->post['description'], $this->request->post['amount']);

$json['success'] = $this->language->get('text_success');
}

$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}

public function reward() {
$this->load->language('sale/customer');

$this->load->model('sale/customer');

$data['text_no_results'] = $this->language->get('text_no_results');
$data['text_balance'] = $this->language->get('text_balance');

Expand Down Expand Up @@ -1385,6 +1381,25 @@ public function reward() {
$this->response->setOutput($this->load->view('sale/customer_reward.tpl', $data));
}

public function addReward() {
$this->load->language('sale/customer');

$json = array();

if (!$this->user->hasPermission('modify', 'sale/customer')) {
$json['error'] = $this->language->get('error_permission');
} else {
$this->load->model('sale/customer');

$this->model_sale_customer->addReward($this->request->get['customer_id'], $this->request->post['description'], $this->request->post['points']);

$json['success'] = $this->language->get('text_success');
}

$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}

public function ip() {
$this->load->language('sale/customer');

Expand Down Expand Up @@ -1568,4 +1583,4 @@ public function address() {
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
}
62 changes: 42 additions & 20 deletions upload/admin/view/template/sale/customer_form.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -950,25 +950,33 @@ $('#history').delegate('.pagination a', 'click', function(e) {
$('#history').load('index.php?route=sale/customer/history&token=<?php echo $token; ?>&customer_id=<?php echo $customer_id; ?>');
$('#button-history').on('click', function(e) {
e.preventDefault();
e.preventDefault();
$.ajax({
url: 'index.php?route=sale/customer/history&token=<?php echo $token; ?>&customer_id=<?php echo $customer_id; ?>',
url: 'index.php?route=sale/customer/addhistory&token=<?php echo $token; ?>&customer_id=<?php echo $customer_id; ?>',
type: 'post',
dataType: 'html',
dataType: 'json',
data: 'comment=' + encodeURIComponent($('#tab-history textarea[name=\'comment\']').val()),
beforeSend: function() {
$('#button-history').button('loading');
},
complete: function() {
$('#button-history').button('reset');
},
success: function(html) {
success: function(json) {
$('.alert').remove();
$('#history').html(html);
if (json['error']) {
$('#tab-history').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div></div>');
}
if (json['success']) {
$('#tab-history').prepend('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div></div>');
$('#tab-history textarea[name=\'comment\']').val('');
$('#history').load('index.php?route=sale/customer/history&token=<?php echo $token; ?>&customer_id=<?php echo $customer_id; ?>');
$('#tab-history textarea[name=\'comment\']').val('');
}
}
});
});
Expand All @@ -986,23 +994,31 @@ $('#button-transaction').on('click', function(e) {
e.preventDefault();
$.ajax({
url: 'index.php?route=sale/customer/transaction&token=<?php echo $token; ?>&customer_id=<?php echo $customer_id; ?>',
url: 'index.php?route=sale/customer/addtransaction&token=<?php echo $token; ?>&customer_id=<?php echo $customer_id; ?>',
type: 'post',
dataType: 'html',
dataType: 'json',
data: 'description=' + encodeURIComponent($('#tab-transaction input[name=\'description\']').val()) + '&amount=' + encodeURIComponent($('#tab-transaction input[name=\'amount\']').val()),
beforeSend: function() {
$('#button-transaction').button('loading');
},
complete: function() {
$('#button-transaction').button('reset');
},
success: function(html) {
success: function(json) {
$('.alert').remove();
$('#transaction').html(html);
if (json['error']) {
$('#tab-transaction').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div></div>');
}
$('#tab-transaction input[name=\'amount\']').val('');
$('#tab-transaction input[name=\'description\']').val('');
if (json['success']) {
$('#tab-transaction').prepend('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div></div>');
$('#transaction').load('index.php?route=sale/customer/transaction&token=<?php echo $token; ?>&customer_id=<?php echo $customer_id; ?>');
$('#tab-transaction input[name=\'amount\']').val('');
$('#tab-transaction input[name=\'description\']').val('');
}
}
});
});
Expand All @@ -1020,23 +1036,31 @@ $('#button-reward').on('click', function(e) {
e.preventDefault();
$.ajax({
url: 'index.php?route=sale/customer/reward&token=<?php echo $token; ?>&customer_id=<?php echo $customer_id; ?>',
url: 'index.php?route=sale/customer/addreward&token=<?php echo $token; ?>&customer_id=<?php echo $customer_id; ?>',
type: 'post',
dataType: 'html',
dataType: 'json',
data: 'description=' + encodeURIComponent($('#tab-reward input[name=\'description\']').val()) + '&points=' + encodeURIComponent($('#tab-reward input[name=\'points\']').val()),
beforeSend: function() {
$('#button-reward').button('loading');
},
complete: function() {
$('#button-reward').button('reset');
},
success: function(html) {
success: function(json) {
$('.alert').remove();
$('#reward').html(html);
if (json['error']) {
$('#tab-reward').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div></div>');
}
if (json['success']) {
$('#tab-reward').prepend('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div></div>');
$('#tab-reward input[name=\'points\']').val('');
$('#tab-reward input[name=\'description\']').val('');
$('#reward').load('index.php?route=sale/customer/reward&token=<?php echo $token; ?>&customer_id=<?php echo $customer_id; ?>');
$('#tab-reward input[name=\'points\']').val('');
$('#tab-reward input[name=\'description\']').val('');
}
}
});
});
Expand Down Expand Up @@ -1068,8 +1092,6 @@ $('body').delegate('.button-ban-add', 'click', function() {
if (json['error']) {
$('#content > .container-fluid').prepend('<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + '</div>');
$('.alert').fadeIn('slow');
}
if (json['success']) {
Expand Down
54 changes: 23 additions & 31 deletions upload/admin/view/template/sale/customer_history.tpl
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
<?php if ($error_warning) { ?>
<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
<button type="button" class="close" data-dismiss="alert">&times;</button>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
<tr>
<td class="text-left"><?php echo $column_date_added; ?></td>
<td class="text-left"><?php echo $column_comment; ?></td>
</tr>
</thead>
<tbody>
<?php if ($histories) { ?>
<?php foreach ($histories as $history) { ?>
<tr>
<td class="text-left"><?php echo $history['date_added']; ?></td>
<td class="text-left"><?php echo $history['comment']; ?></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td class="text-center" colspan="2"><?php echo $text_no_results; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php } ?>
<?php if ($success) { ?>
<div class="alert alert-success"><i class="fa fa-check-circle"></i> <?php echo $success; ?>
<button type="button" class="close" data-dismiss="alert">&times;</button>
</div>
<?php } ?>
<table class="table table-bordered">
<thead>
<tr>
<td class="text-left"><?php echo $column_date_added; ?></td>
<td class="text-left"><?php echo $column_comment; ?></td>
</tr>
</thead>
<tbody>
<?php if ($histories) { ?>
<?php foreach ($histories as $history) { ?>
<tr>
<td class="text-left"><?php echo $history['date_added']; ?></td>
<td class="text-left"><?php echo $history['comment']; ?></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td class="text-center" colspan="2"><?php echo $text_no_results; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="row">
<div class="col-sm-6 text-left"><?php echo $pagination; ?></div>
<div class="col-sm-6 text-right"><?php echo $results; ?></div>
Expand Down
10 changes: 0 additions & 10 deletions upload/admin/view/template/sale/customer_reward.tpl
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<?php if ($error_warning) { ?>
<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
<button type="button" class="close" data-dismiss="alert">&times;</button>
</div>
<?php } ?>
<?php if ($success) { ?>
<div class="alert alert-success"><i class="fa fa-check-circle"></i> <?php echo $success; ?>
<button type="button" class="close" data-dismiss="alert">&times;</button>
</div>
<?php } ?>
<div class="table-responsive">
<table class="table table-bordered table-hover">
<thead>
Expand Down
10 changes: 0 additions & 10 deletions upload/admin/view/template/sale/customer_transaction.tpl
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<?php if ($error_warning) { ?>
<div class="alert alert-danger"><i class="fa fa-exclamation-circle"></i> <?php echo $error_warning; ?>
<button type="button" class="close" data-dismiss="alert">&times;</button>
</div>
<?php } ?>
<?php if ($success) { ?>
<div class="alert alert-success"><i class="fa fa-check-circle"></i> <?php echo $success; ?>
<button type="button" class="close" data-dismiss="alert">&times;</button>
</div>
<?php } ?>
<div class="table-responsive">
<table class="table table-bordered table-hover">
<thead>
Expand Down

0 comments on commit 0a42c05

Please sign in to comment.