VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: apri on March 31, 2015, 05:06:49 AM

Title: [fixed]TableInvoices COM_VIRTUEMART_INVOICE_NUMBER in record is missing! Can't
Post by: apri on March 31, 2015, 05:06:49 AM
virtuemart 3.0.6.2

I get that message when trying to delete oder. Everything works except renaming invoice, all database tables get things related to that order deleted.

My findings after some debugging:

invoice is generated like vminvoice_150330cc1011.pdf. It's in the direcory with the correct permissions and could be renamed if no bug.
I put a loggin statements in orders.php directory (\administrator\components\com_virtuemart\models\ )
Here is code fragment with logging statements which are error_log

      // rename invoice pdf file
      $invoice_prefix='vminvoice_'.VmConfig::$vmlang.'_';
      $path = shopFunctions::getInvoicePath(VmConfig::get('forSale_path',0));
      error_log("renaming invoice 0 " . $path);
      $invoice_name_src = $path.DS.$invoice_prefix.$data['invoice_number'].'.pdf';
      error_log("renaming invoice 1 " . $invoice_name_src);
      if(!file_exists($invoice_name_src)){
         // may be it was already deleted when changing order items
         $data['invoice_number'] = "";
      } else {
         error_log("renaming invoice 2");
         $date = date("Ymd");
         $data['invoice_number'] = $data['invoice_number'].'_'.$date;
         $invoice_name_dst = $path.DS.$data['invoice_number'].'.pdf';

         if(!class_exists('JFile')) require(VMPATH_LIBS.DS.'joomla'.DS.'filesystem'.DS.'file.php');
         if (!JFile::move($invoice_name_src, $invoice_name_dst)) {
            vmError ('Could not rename Invoice '.$invoice_name_src.'to '. $invoice_name_dst );
         }
      }

Here're the lines from php error log file:

[30-Mar-2015 22:17:21 America/New_York] renaming invoice 0 C:\xampp\htdocs\vmfiles\invoices

[30-Mar-2015 22:17:21 America/New_York] renaming invoice 1 C:\xampp\htdocs\vmfiles\invoices\vminvoice_en_gb_150330cc1011.pdf

So, this statement
$invoice_prefix='vminvoice_'.VmConfig::$vmlang.'_';
inserts en_gb into invoice name which was originally generated without VmConfig::$vmlang

Such file does not exist and we have this error message and un-renamed file
This fixes the problem:
$invoice_prefix='vminvoice_'; // .VmConfig::$vmlang.'_';


Title: Re: TableInvoices COM_VIRTUEMART_INVOICE_NUMBER in record is missing! Can't save the
Post by: Milbo on March 31, 2015, 23:14:56 PM
Thank you, good work.

does this work for you?


// rename invoice pdf file
$path = shopFunctions::getInvoicePath(VmConfig::get('forSale_path',0));
$invoice_prefix='vminvoice_';
$invoice_name_src = $path.DS.$invoice_prefix.$data['invoice_number'].'.pdf';
if(!file_exists($invoice_name_src)){
$invoice_prefix='vminvoice_'.VmConfig::$vmlang.'_';
$invoice_name_src = $path.DS.$invoice_prefix.$data['invoice_number'].'.pdf';
}

if(!file_exists($invoice_name_src)){


??
Title: Re: TableInvoices COM_VIRTUEMART_INVOICE_NUMBER in record is missing! Can't save the
Post by: apri on April 01, 2015, 16:48:28 PM
It works
Title: Re: TableInvoices COM_VIRTUEMART_INVOICE_NUMBER in record is missing! Can't save the
Post by: Milbo on April 01, 2015, 19:18:46 PM
great
Title: Re: [fixed]TableInvoices COM_VIRTUEMART_INVOICE_NUMBER in record is missing! Can't
Post by: apri on April 02, 2015, 17:41:01 PM
I've checked the code of other versions of VM I have, version 2.9.8.a does not have VmConfig::$vmlang.
Nothing personal, but did whoever added VmConfig::$vmlang  into code bother to test and delete invoice after the routine was modified? It should be fixed when invoice is created.
Title: Re: [fixed]TableInvoices COM_VIRTUEMART_INVOICE_NUMBER in record is missing! Can't
Post by: Milbo on April 03, 2015, 16:04:02 PM
lol, http://dev.virtuemart.net/attachments/download/937/com_virtuemart.3.0.7_extract_first.zip

was not my code
Title: Re: [fixed]TableInvoices COM_VIRTUEMART_INVOICE_NUMBER in record is missing! Can't
Post by: Wapsel on June 09, 2015, 15:29:55 PM
Hi there,

I'm getting the same error when I try to edit a placed order and want to save it for the second time (first time is okay).
I noticed that the pdf invoice in the invoices folder gets the title "_deprecated" with the date behind it. Maybe this has someting to do with it?

Joomla: 3.4.1
VM: 3.0.9

Maybe someone can help me out?
Title: Re: [fixed]TableInvoices COM_VIRTUEMART_INVOICE_NUMBER in record is missing! Can't
Post by: Henrik Holm Nielsen on June 12, 2015, 12:23:04 PM
I see the same in my upgraded install with J3.4.1 & VM3.0.9 when deleting orders....
Title: Re: [fixed]TableInvoices COM_VIRTUEMART_INVOICE_NUMBER in record is missing! Can't
Post by: green-products.co.uk on June 16, 2015, 18:05:04 PM
I get it too when I try to delete orders.

Joomla 3.4.1
VM3.0.9
Title: Re: [fixed]TableInvoices COM_VIRTUEMART_INVOICE_NUMBER in record is missing! Can't
Post by: rojones31 on June 19, 2015, 17:37:53 PM
@Milbo  - I"m having the same issue however, I'm following the code listed above and I can't seem to follow where to input the updated script into the orders.php file. 

In the original orders.php the code is as follows:
// rename invoice pdf file
      $invoice_prefix='vminvoice_';
      $path = shopFunctions::getInvoicePath(VmConfig::get('forSale_path',0));
      $invoice_name_src = $path.DS.$invoice_prefix.$data['invoice_number'].'.pdf';

      if(!file_exists($invoice_name_src)){


In the edited code you posted it reads as follows:  (however it has another if statement at the bottom)
// rename invoice pdf file
      $path = shopFunctions::getInvoicePath(VmConfig::get('forSale_path',0));
      $invoice_prefix='vminvoice_';
      $invoice_name_src = $path.DS.$invoice_prefix.$data['invoice_number'].'.pdf';
      if(!file_exists($invoice_name_src)){
         $invoice_prefix='vminvoice_'.VmConfig::$vmlang.'_';
         $invoice_name_src = $path.DS.$invoice_prefix.$data['invoice_number'].'.pdf';
      }
      
      if(!file_exists($invoice_name_src)){  (Should this script be included? There are two if statements and in the original there is only one if statement.)

I have attached the orginial orders.php in a zip file, so you can edit where the updated script needs to be replaced.

I'm using J3.4 and VM 3.0.6.2

Please edit the file and resend with the correct code.

Thanks for all your help,
RJ



Title: Re: [fixed]TableInvoices COM_VIRTUEMART_INVOICE_NUMBER in record is missing! Can't
Post by: eclark461 on August 21, 2015, 22:18:11 PM
Line 1997 VM 3.0.9 path /administrator/components/com_virtuemart/models/orders.php

Found it there or around there.

Still having same issue after applying script as stated above.