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
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
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:
Then, in admin/controller/sale/order.php add a function
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.
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');
});
}
}
});
});
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));
}
}
Remember that if you set a duplicated invoice_prefix you will get in a big trouble. Take care.
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):
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):
and on the bottom everything You said:
and in contorller file admin/controller/sale/order.php
Please could You check what is wrong ?
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'] . "'");
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>
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>
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));
}
}
Attachments
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
To this
Now, test it.
I made a typo In controller, change this
Code: Select all
$this->db->query->("UPDATE
Code: Select all
$this->db->query("UPDATE
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>
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>
Dear gedielson,
You are great! Thank you.
If someone was interested in funtionality to override present invoice number - please download extention from this link
You are great! Thank you.
If someone was interested in funtionality to override present invoice number - please download extention from this link
I'm happy to have helped you and thank you very much for the credit in the extension!
Cheers.
Cheers.
Who is online
Users browsing this forum: No registered users and 21 guests