Post by wilek666 » Wed Mar 04, 2015 6:24 am

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

http://www.ortopediko.pl
http://www.pszczelafarma.pl


User avatar
New member

Posts

Joined
Sun Dec 07, 2014 2:26 am
Location - Warsaw, Poland

Post by gedielson » Wed Mar 04, 2015 10:15 am

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.

http://gepeixoto.com.br


User avatar
New member

Posts

Joined
Wed Oct 01, 2014 7:37 am
Location - Brazil

Post by wilek666 » Fri Mar 06, 2015 1:58 am

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 ?

http://www.ortopediko.pl
http://www.pszczelafarma.pl


User avatar
New member

Posts

Joined
Sun Dec 07, 2014 2:26 am
Location - Warsaw, Poland

Post by gedielson » Fri Mar 06, 2015 8:20 am

Ok, let's go.

I made a typo In controller, change this

Code: Select all

$this->db->query->("UPDATE
To this (only remove the -> after query)

Code: Select all

$this->db->query("UPDATE
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.

http://gepeixoto.com.br


User avatar
New member

Posts

Joined
Wed Oct 01, 2014 7:37 am
Location - Brazil

Post by wilek666 » Sat Mar 07, 2015 2:16 am

Dear gedielson,

You are great! Thank you.

If someone was interested in funtionality to override present invoice number - please download extention from this link

http://www.ortopediko.pl
http://www.pszczelafarma.pl


User avatar
New member

Posts

Joined
Sun Dec 07, 2014 2:26 am
Location - Warsaw, Poland

Post by gedielson » Sat Mar 07, 2015 6:08 am

I'm happy to have helped you and thank you very much for the credit in the extension!

Cheers.

http://gepeixoto.com.br


User avatar
New member

Posts

Joined
Wed Oct 01, 2014 7:37 am
Location - Brazil
Who is online

Users browsing this forum: No registered users and 21 guests