Page 1 of 1
Manually Edit Invoice Number
Posted: Wed Mar 04, 2015 6:24 am
by wilek666
Dear all,
I'm struggling with manually editing invoice number.
I would like to send new value from text field into database.
Could You help me ?
http://www.ortopediko.pl/image/data/cha ... number.jpg
Re: Manually Edit Invoice Number
Posted: Wed Mar 04, 2015 10:15 am
by gedielson
This invoice number is stored as invoice_prefix in database. In template file, you already have created the input and button, right? Set button id="update-invoice-no" and input name="new_invoice_no".
Then, before <?php echo $footer; ?> add:
Code: Select all
<script type="text/javascript"><!--
$('#update-invoice-no').live('click', function() {
$.ajax({
url: 'index.php?route=sale/order/updateinvoiceno&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>',
type: 'post',
dataType: 'json',
data: 'invoice_no=' + encodeURIComponent($('input[name=\'new_invoice_no\']').val()),
beforeSend: function() {
$('#update-invoice-no').attr('disabled', true);
},
complete: function() {
$('#update-invoice-no').attr('disabled', false);
},
success: function(json) {
if (json.new_invoice_no) {
$('#invoice').fadeOut('slow', function() {
$('#invoice').html(json['new_invoice_no']);
$('#invoice').fadeIn('slow');
});
}
}
});
});
Then, in admin/controller/sale/order.php add a function
Code: Select all
public function updateinvoiceno() {
if ($this->request->server['REQUEST_METHOD'] == 'POST') {
$this->db->query->("UPDATE " . DB_PREFIX . "order SET invoice_prefix = '" . $this->db->escape($this->request->post['invoice_no']) . "' WHERE order_id = '" . $this->request->get['order_id'] . "'");
$json['new_invoice_no'] = $this->request->post['invoice_no'];
$this->response->setOutput(json_encode($json));
}
}
I don't have tested it, since I write this code hurriedly. But this should do the trick.
Remember that if you set a duplicated invoice_prefix you will get in a big trouble. Take care.
Re: Manually Edit Invoice Number
Posted: Fri Mar 06, 2015 1:58 am
by wilek666
Dear gedielson,
Thank you for answer but I think there is a bug in controller file - on line with query (I checked the query and it worked fine):
Code: Select all
Parse error: syntax error, unexpected '(', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in C:\xampp\htdocs\opencart\vqmod\vqcache\vq2-adminwilek666_controller_sale_order.php on line 17
Code: Select all
if ($this->request->server['REQUEST_METHOD'] == 'POST') {
$this->db->query->("UPDATE " . DB_PREFIX . "order SET invoice_prefix = '" . $this->db->escape($this->request->post['invoice_no']) . "' WHERE order_id = '" . $this->request->get['order_id'] . "'");
and for sure I didn't correctly fill tpl file.
I added to tpl file: admin/view/template/sale/order_info.tpl text area (1 line of code) and button (2 line of code):
Code: Select all
<td><textarea name="new_invoice_no" cols="40" rows="5"><?php echo $invoice_no; ?></textarea></td>
<td align="left"><a id="update-invoice-no" name="new_invoice_no" class="button"><?php echo 'change invoice no'; ?></a></td>
and on the bottom everything You said:
Code: Select all
<script type="text/javascript"><!--
$('#update-invoice-no').live('click', function() {
$.ajax({
url: 'index.php?route=sale/order/updateinvoiceno&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>',
type: 'post',
dataType: 'json',
data: 'invoice_no=' + encodeURIComponent($('input[name=\'new_invoice_no\']').val()),
beforeSend: function() {
$('#update-invoice-no').attr('disabled', true);
},
complete: function() {
$('#update-invoice-no').attr('disabled', false);
},
success: function(json) {
if (json.new_invoice_no) {
$('#invoice').fadeOut('slow', function() {
$('#invoice').html(json['new_invoice_no']);
$('#invoice').fadeIn('slow');
});
}
}
});
});
//--></script>
and in contorller file admin/controller/sale/order.php
Code: Select all
public function updateinvoiceno() {
if ($this->request->server['REQUEST_METHOD'] == 'POST') {
$this->db->query->("UPDATE " . DB_PREFIX . "order SET invoice_prefix = '" . $this->db->escape($this->request->post['invoice_no']) . "' WHERE order_id = '" . $this->request->get['order_id'] . "'");
$json['new_invoice_no'] = $this->request->post['invoice_no'];
$this->response->setOutput(json_encode($json));
}
}
Please could You check what is wrong ?
Re: Manually Edit Invoice Number
Posted: Fri Mar 06, 2015 8:20 am
by gedielson
Ok, let's go.
I made a typo In controller, change this
To this (only remove the
-> after query)
Then, in tpl file change this
Code: Select all
<td><textarea name="new_invoice_no" cols="40" rows="5"><?php echo $invoice_no; ?></textarea></td>
<td align="left"><a id="update-invoice-no" name="new_invoice_no" class="button"><?php echo 'change invoice no'; ?></a></td>
To this
Code: Select all
<td><input name="new_invoice_no" value="<?php echo $invoice_no; ?>"></input></td>
<td align="left"><a id="update-invoice-no" class="button"><?php echo 'change invoice no'; ?></a></td>
Now, test it.
Re: Manually Edit Invoice Number
Posted: Sat Mar 07, 2015 2:16 am
by wilek666
Dear gedielson,
You are great! Thank you.
If someone was interested in funtionality to override present invoice number - please download extention from
this link
Re: Manually Edit Invoice Number
Posted: Sat Mar 07, 2015 6:08 am
by gedielson
I'm happy to have helped you and thank you very much for the credit in the extension!
Cheers.