Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

PO Numbers on Invoices, Searchable in Orders.

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 06-04-2007, 08:55 PM
 
Berto Berto is offline
 

Member
  
Join Date: Mar 2007
Posts: 19
 

Default PO Numbers on Invoices, Searchable in Orders.

I've been asked to include this modification for people who want to have order-based Purchase Order Numbers, pulling that info from the encrypted field and making it searchable in the admin Orders section. This mod also includes PO Numbers on invoices.

Caveat: In this mod, the new PO Number field is not encrypted. If that's important, then you must modify further to include encryption.

This has been tested on X-Cart 4.1.7. You may wish to modify further for other versions of X-Cart.


Don't forget -- Step One is to create a new field in the database. Steps Two through Ten follow in the next post.


Step 1: Create a new database field with phpMyAdmin or another method in the xcart_orders table directly after "extra," called po_number. (Varchar(50), not null).

see next post for more...
__________________
Russell
X-cart Version 4.1.9 [linux]
Reply With Quote

The following user thanks Berto for this useful post:
notgrass (02-22-2012)
  #2  
Old 06-04-2007, 08:58 PM
 
Berto Berto is offline
 

Member
  
Join Date: Mar 2007
Posts: 19
 

Default Re: PO Numbers on Invoices, Searchable in Orders.

Step 2: Add this to the bottom of xcart_root_folder/include/func/func.db.php: --(See reply #6 for a fix.)

Code:
function getPONum($o_details) { if (strpos($o_details, "PO Number") > -1) { $po_number_arr = explode(' ',$o_details); for ($int=0; $int<count($po_number_arr); $int++) { if ((strpos($po_number_arr[$int], "PO") > -1)&&(strpos($po_number_arr[$int + 1], "Number") > -1)) { $po_num = $po_number_arr[$int + 2]; break; } } return $po_num; } else { return ""; } }


Step 3: The above will not work if there are spaces in the PO Number, so modify xcart_root_folder/skin1/customer/main/payment_po.tpl:
Add this script after the "required fields" script (just before the table tag):
Code:
{literal} <script type="text/javascript"> <!-- function ckFld() { var fld = document.checkout_form.PO_Number; if (fld.value.indexOf(' ') > -1) { alert('There can be no spaces in this field.'); fld.value = fld.value.replace(' ',''); fld.focus(); } } --> </script> {/literal}
and change this line:
Code:
<input type="text" size="32" id="PO_Number" name="PO_Number" />
to this:
Code:
<input type="text" size="32" id="PO_Number" name="PO_Number" onChange="ckFld();" />


Step 4: Find the array in xcart_root_folder/include/func/func_order.php that begins:
Code:
$insert_data = array (
and insert "po_number" at the end of it (around line 579) by replacing this:
Code:
'extra' => addslashes(serialize($_extra)));
with the following, so that the last two lines in the array read:
Code:
'extra' => addslashes(serialize($_extra)), 'po_number' => addslashes(getPONum($order_details)));


Step 5: Modify xcart_root_folder/include/orders.php:

Find the array:
Code:
$advanced_options = array("orderid1", "orderid2", "total_max", "payment_method", "shipping_method", "status", "provider", "features", "product_substring", "productcode", "productid", "price_max", "customer", "address_type", "phone", "email");
and replace it with this to add "po_number" so that it reads:
Code:
$advanced_options = array("orderid1", "orderid2", "total_max", "payment_method", "po_number", "shipping_method", "status", "provider", "features", "product_substring", "productcode", "productid", "price_max", "customer", "address_type", "phone", "email");

In the same file, find:
Code:
if (!empty($sort) && in_array($sort, array("orderid","status","customer","date","provider", "total"))) {
and change it to include "po_number" as well, to read:
Code:
if (!empty($sort) && in_array($sort, array("orderid","status","customer","date","po_number","provider", "total"))) {

Then, find this "if" clause (around line 182):
Code:
# Search by payment method if (!empty($data["payment_method"])) $search_condition .= " AND $sql_tbl[orders].payment_method LIKE '".$data["payment_method"]."%'";
keep it there and add another search clause below it, (before "# Search by shipping method"):
Code:
# Search by po number if (!empty($data["po_number"])) $search_condition .= " AND $sql_tbl[orders].po_number LIKE '%".$data["po_number"]."%'";

The last mod on this file is to find this case (around line 420):
Code:
case "date": $sort_string = "$sql_tbl[orders].date $direction"; break;
keep it there and add this case below it:
Code:
case "po_number": // added for po number $sort_string = "($sql_tbl[orders].po_number + 0) $direction"; break;


Step 6: In the file xcart_root_folder/admin/order.php, find this line (around line 190):
Code:
$query_data['details'] = func_crypt_order_details($details);
and add this line directly under it:
Code:
$query_data['po_number'] = getPOnum($details);


Step 7: Edit the file xcart_root_folder/skin1/mail/html/order_invoice.tpl:

Find this line:
Code:
<b>{$lng.lbl_payment_method}:</b><br />{$order.payment_method}<br /><b>{$lng.lbl_delivery}:</b><br />{$order.shipping|trademark|default:$lng.txt_not_available}
and change it to:
Code:
<b>{$lng.lbl_payment_method}:</b><br />{$order.payment_method}<br /><b>{$lng.lbl_po_number}:</b> {$order.po_number}<br /><b>{$lng.lbl_delivery}:</b><br />{$order.shipping|trademark|default:$lng.txt_not_available}


Step 8: Edit the file xcart_root_folder/skin1/main/order_info.tpl:

After the table row:
Code:
<tr> <td valign="top">{$lng.lbl_payment_method}</td> <td valign="top">{$order.payment_method}</td> </tr>
add this new table row:
Code:
<tr> <td valign="top">{$lng.lbl_po_number}</td> <td valign="top">{$order.po_number}</td> </tr>


Step 9: Edit the file xcart_root_folder/skin1/main/order_list.tpl:

Find the section:
Code:
<tr class="TableHead"> <td width="5">&nbsp;</td> <td width="5%" nowrap="nowrap">{if $search_prefilled.sort_field eq "orderid"}{include file="buttons/sort_pointer.tpl" dir=$search_prefilled.sort_direction}&nbsp;{/if}<a href="orders.php?mode=search&amp;sort=orderid">#</a></td> <td nowrap="nowrap">{if $search_prefilled.sort_field eq "status"}{include file="buttons/sort_pointer.tpl" dir=$search_prefilled.sort_direction}&nbsp;{/if}<a href="orders.php?mode=search&amp;sort=status">{$lng.lbl_status}</a></td> <td width="30%" nowrap="nowrap">{if $search_prefilled.sort_field eq "customer"}{include file="buttons/sort_pointer.tpl" dir=$search_prefilled.sort_direction}&nbsp;{/if}<a href="orders.php?mode=search&amp;sort=customer">{$lng.lbl_customer}</a></td> {if $usertype eq "A" and $single_mode eq ""} {assign var="colspan" value=7} <td width="20%" nowrap="nowrap">{if $search_prefilled.sort_field eq "provider"}{include file="buttons/sort_pointer.tpl" dir=$search_prefilled.sort_direction}&nbsp;{/if}<a href="orders.php?mode=search&amp;sort=provider">{$lng.lbl_provider}</a></td> {/if} <td width="20%" nowrap="nowrap">{if $search_prefilled.sort_field eq "date"}{include file="buttons/sort_pointer.tpl" dir=$search_prefilled.sort_direction}&nbsp;{/if}<a href="orders.php?mode=search&amp;sort=date">{$lng.lbl_date}</a></td> <td width="20%" align="right" nowrap="nowrap">{if $search_prefilled.sort_field eq "total"}{include file="buttons/sort_pointer.tpl" dir=$search_prefilled.sort_direction}&nbsp;{/if}<a href="orders.php?mode=search&amp;sort=total">{$lng.lbl_total}</a></td> </tr>
and replace it with this:
Code:
<tr class="TableHead"> <td width="5">&nbsp;</td> <td width="5%" nowrap="nowrap">{if $search_prefilled.sort_field eq "orderid"}{include file="buttons/sort_pointer.tpl" dir=$search_prefilled.sort_direction}&nbsp;{/if}<a href="orders.php?mode=search&amp;sort=orderid">#</a></td> <td nowrap="nowrap">{if $search_prefilled.sort_field eq "status"}{include file="buttons/sort_pointer.tpl" dir=$search_prefilled.sort_direction}&nbsp;{/if}<a href="orders.php?mode=search&amp;sort=status">{$lng.lbl_status}</a></td> <td width="35%" nowrap="nowrap">{if $search_prefilled.sort_field eq "customer"}{include file="buttons/sort_pointer.tpl" dir=$search_prefilled.sort_direction}&nbsp;{/if}<a href="orders.php?mode=search&amp;sort=customer">{$lng.lbl_customer}</a></td> {if $usertype eq "A" and $single_mode eq ""} {assign var="colspan" value=7} <td width="20%" nowrap="nowrap">{if $search_prefilled.sort_field eq "provider"}{include file="buttons/sort_pointer.tpl" dir=$search_prefilled.sort_direction}&nbsp;{/if}<a href="orders.php?mode=search&amp;sort=provider">{$lng.lbl_provider}</a></td> {/if} <td width="20%" nowrap="nowrap">{if $search_prefilled.sort_field eq "date"}{include file="buttons/sort_pointer.tpl" dir=$search_prefilled.sort_direction}&nbsp;{/if}<a href="orders.php?mode=search&amp;sort=date">{$lng.lbl_date}</a></td> <td width="15%" nowrap="nowrap">{if $search_prefilled.sort_field eq "po_number"}{include file="buttons/sort_pointer.tpl" dir=$search_prefilled.sort_direction}&nbsp;{/if}<a href="orders.php?mode=search&amp;sort=po_number">{$lng.lbl_po_number}</a></td> <td width="10%" align="right" nowrap="nowrap">{if $search_prefilled.sort_field eq "total"}{include file="buttons/sort_pointer.tpl" dir=$search_prefilled.sort_direction}&nbsp;{/if}<a href="orders.php?mode=search&amp;sort=total">{$lng.lbl_total}</a></td> </tr>

Find this line:
Code:
<td nowrap="nowrap"><a href="order.php?orderid={$orders[oid].orderid}">{$orders[oid].date|date_format:$config.Appearance.datetime_format}</a></td>
and add this line directly under it:
Code:
<td nowrap="nowrap"><a href="order.php?orderid={$orders[oid].orderid}">{$orders[oid].po_number}</a></td>


Step 10: Edit the file xcart_root_folder/skin1/main/orders.tpl:

Find the line:
Code:
var searchform_def = [
and at the end of that entire array insert:
Code:
['posted_data[po_number]', '']
after the 'posted_data[status]' line.

Now find the table row:
Code:
<tr> <td class="FormButton" nowrap="nowrap">{$lng.lbl_payment_method}:</td> <td width="10">&nbsp;</td> <td> <select name="posted_data[payment_method]" style="width:70%"> <option value=""></option> {section name=pm loop=$payment_methods} <option value="{$payment_methods[pm].payment_method}"{if $search_prefilled.payment_method eq $payment_methods[pm].payment_method} selected="selected"{/if}>{$payment_methods[pm].payment_method}</option> {/section} </select> </td> </tr>
and add this row after it:
Code:
<tr> <td class="FormButton" nowrap="nowrap">{$lng.lbl_po_number}:</td> <td width="10">&nbsp;</td> <td> <input type="text" name="posted_data[po_number]" size="30" value="{$search_prefilled.po_number}" style="width:70%" /> </td> </tr>


That's it.
__________________
Russell
X-cart Version 4.1.9 [linux]

Last edited by Berto : 06-09-2007 at 02:05 PM. Reason: New function created for step 2
Reply With Quote
  #3  
Old 06-08-2007, 05:34 AM
  chamberinternet's Avatar 
chamberinternet chamberinternet is offline
 

X-Wizard
  
Join Date: Sep 2005
Location: Lancashire, UK
Posts: 1,470
 

Default Re: PO Numbers on Invoices, Searchable in Orders.

Hello ...
This is great It's working fine ... apart from just one thing ..

I'm not sure if it's the function getPONum() but as well as attaching the PO Number is also grabbing the first word of the next line (In this case it's Company Name)

So when i look at the database the po_number field is showing "5361 Company"
(5361 is the actual po number i entered)

Any ideas ?

Thanks A Lot ...

Regards

Shafiq :sK
__________________
Developing in 4.7.x now (Dipping into v5 - Slowly!)
Have used 4.1.x, 4.2.x, 4.4.x, 4.5.x, 4.6.x & 4.7.x
Multiple Instances of X-Cart
MySQL 5.6.37
CentOS 7.4


Chamber Internet
- Lancashire, United Kingdom
http://www.chamberelancs.co.uk
Reply With Quote
  #4  
Old 06-08-2007, 03:28 PM
 
Berto Berto is offline
 

Member
  
Join Date: Mar 2007
Posts: 19
 

Default Re: PO Numbers on Invoices, Searchable in Orders.

Oh, yes...

We removed the Company name and Name of purchaser from our po orders, so, no wonder this didn't come up! My function finds spaces, but not line returns. So here's a possible fix:

Try this function instead in your file x-cart_root/include/func/func.db.php:
Code:
function getPONum($o_details) { if (strpos($o_details, "PO Number") > -1) { $po_number_arr = explode(' ',$o_details); for ($int=0; $int<count($po_number_arr); $int++) { if ((strpos($po_number_arr[$int], "PO") > -1)&&(strpos($po_number_arr[$int + 1], "Number") > -1)) { $po_arr = explode('\n', $po_number_arr[$int + 2]); $po_num = $po_arr[0]; break; } } return $po_num; } else { return ""; } }

Let me know if that one works!
__________________
Russell
X-cart Version 4.1.9 [linux]
Reply With Quote
  #5  
Old 06-09-2007, 11:38 AM
  chamberinternet's Avatar 
chamberinternet chamberinternet is offline
 

X-Wizard
  
Join Date: Sep 2005
Location: Lancashire, UK
Posts: 1,470
 

Default Re: PO Numbers on Invoices, Searchable in Orders.

Hello ... Just tried this ... But no joy

Any other ideas ?

Thanks & Regards

Shafiq :sK
__________________
Developing in 4.7.x now (Dipping into v5 - Slowly!)
Have used 4.1.x, 4.2.x, 4.4.x, 4.5.x, 4.6.x & 4.7.x
Multiple Instances of X-Cart
MySQL 5.6.37
CentOS 7.4


Chamber Internet
- Lancashire, United Kingdom
http://www.chamberelancs.co.uk
Reply With Quote
  #6  
Old 06-09-2007, 02:04 PM
 
Berto Berto is offline
 

Member
  
Join Date: Mar 2007
Posts: 19
 

Default Re: PO Numbers on Invoices, Searchable in Orders.

Ugh.

We've got to find how your system registers line breaks.

So, try this function at the bottom of x-cart_root/include/func/func.db.php instead:
Code:
function getPONum($o_details) { if (strpos($o_details, "PO Number") > -1) { $o_string = preg_replace("/\r\n|\n|\r/", " ", $o_details); $po_number_arr = explode(' ',$o_string); for ($int=0; $int<count($po_number_arr); $int++) { if ((strpos($po_number_arr[$int], "PO") > -1)&&(strpos($po_number_arr[$int + 1], "Number") > -1)) { $po_num = $po_number_arr[$int + 2]; break; } } return $po_num; } else { return ""; } }

Does that do it? I hope so!
__________________
Russell
X-cart Version 4.1.9 [linux]
Reply With Quote
  #7  
Old 06-09-2007, 02:11 PM
  chamberinternet's Avatar 
chamberinternet chamberinternet is offline
 

X-Wizard
  
Join Date: Sep 2005
Location: Lancashire, UK
Posts: 1,470
 

Default Re: PO Numbers on Invoices, Searchable in Orders.

Excellent !!

That did the trick ... Thanks very much !!!

Regards

Shafiq :sK
__________________
Developing in 4.7.x now (Dipping into v5 - Slowly!)
Have used 4.1.x, 4.2.x, 4.4.x, 4.5.x, 4.6.x & 4.7.x
Multiple Instances of X-Cart
MySQL 5.6.37
CentOS 7.4


Chamber Internet
- Lancashire, United Kingdom
http://www.chamberelancs.co.uk
Reply With Quote
  #8  
Old 06-11-2007, 12:58 PM
 
Berto Berto is offline
 

Member
  
Join Date: Mar 2007
Posts: 19
 

Default Re: PO Numbers on Invoices, Searchable in Orders.

Quote:
Originally Posted by chamberinternet
Excellent !!

That did the trick ... Thanks very much !!!

Regards

Shafiq :sK

Hooray!

Now it's a pretty nifty mod for 4.1.x.

Cheers,
__________________
Russell
X-cart Version 4.1.9 [linux]
Reply With Quote
  #9  
Old 03-02-2009, 11:46 AM
 
GreatLakesVacuum GreatLakesVacuum is offline
 

eXpert
  
Join Date: Jan 2009
Posts: 286
 

Default Re: PO Numbers on Invoices, Searchable in Orders.

I tried this on 4.2 ... yikes ... all kinds of stuff is broken now ... I think i backed up all the files but one So now to try to undo it all...
__________________
X-Cart 4.5.4 Gold (Live Business Site)
X-Cart 5.1.9 Business (In Development Now)
Reply With Quote
  #10  
Old 03-02-2009, 12:18 PM
 
GreatLakesVacuum GreatLakesVacuum is offline
 

eXpert
  
Join Date: Jan 2009
Posts: 286
 

Default Re: PO Numbers on Invoices, Searchable in Orders.

Quote:
Originally Posted by GreatLakesVacuum
I tried this on 4.2 ... yikes ... all kinds of stuff is broken now ... I think i backed up all the files but one So now to try to undo it all...

Nevermind, I screwed up a step, it works fine!
__________________
X-Cart 4.5.4 Gold (Live Business Site)
X-Cart 5.1.9 Business (In Development Now)
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 02:03 AM.

   

 
X-Cart forums © 2001-2020