Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Simple Batch Processing - Printing Invoices, update status, notify customer


Llamma123

Recommended Posts

I hope someone out there can point me in the right direction. I'm slowly learning PHP coding and have a reasonable understanding of what is going on in this code but did not write it myself. I know there are already other modules to do batch printing of packing slips/invoices but I would like to add this one to the contributions as well, its pretty simple requires 2 new files and 1 new table and optional modification of one file to add a link to the batch print page from orders.php

 

What it does:

1-Take all the new orders and makes a page with a listing of all the orders and provides links to each invoice.

2-When the page is loaded a table is populated with all the orders that are on the list.

In internet explorer you choose to print the page and use the second tab of the print dialog to opt to print all linked documents. This prints the listing as well as one invoice for each order.

3-Once this batch is printed you click the success button and it steps through the table created, updating each order with a status change to 'Processing' and notifies the customer.

 

multiprint.php

<?php
require('includes/application_top.php');
include(DIR_WS_CLASSES . 'order.php');
$ids_query = tep_db_query("select orders_id from " . TABLE_ORDERS . " where orders_status = 7 or orders_status = 8");
$invNum=mysql_num_rows($ids_query);
tep_db_query("DELETE FROM `order_invoice_printed` ");

echo "
<h1>Make sure the printer has <b><u>$invNum</b></u> sheets of paper</h1>Displaying $invNum invoices to print...<br>In Internet Explorer go to File/Print, select the options tab and check the print all linked documents tab<br>If print was successful click the button to update statuses";
echo '<br>
<b>Batch Print Invoices:</b>
<form name="input" action="updatestatus.php"
method="get">
<input type="submit" value="Success!!" />
</form>';
$oIDmax = min($oIDmin + $capacity,$oIDmax);
while ($row  =  mysql_fetch_row($ids_query)) {
$oIDCurr=$row[0]; 
tep_db_query("insert into order_invoice_printed (Order_ID, Print_Status) values ('" . (int)$oIDCurr . "', 0)");
$order = new order($oIDCurr);
echo '<a href="' . tep_href_link(FILENAME_ORDERS_INVOICE, 'oID=' . $oIDCurr) . '" TARGET="multi_invoice">' . tep_image_button('button_invoice.gif', IMAGE_ORDERS_INVOICE) . '</a> ';
echo  '(' .$order->customer['name'] . ' - Order #' . $oIDCurr . ') <br>';
}
?>

 

and the code to make the updates to the selected orders

updatestatus.php

<?php
require('includes/application_top.php');
include(DIR_WS_CLASSES . 'order.php');
require(DIR_WS_CLASSES . 'currencies.php');
 $currencies = new currencies();

$status=2;
$comments='';

$id_query = tep_db_query("select Order_ID from order_invoice_printed where Print_Status=0");
while ($row  =  mysql_fetch_row($id_query)) {
$oIDCurr=$row[0]; 

$check_status_query = tep_db_query("SELECT customers_name, customers_email_address, orders_status, date_purchased from " . TABLE_ORDERS . " where orders_id = $oIDCurr");
$check_status = tep_db_fetch_array($check_status_query);

if (($check_status['orders_status'] != 2) || tep_not_null($comments)) {
         tep_db_query("update " . TABLE_ORDERS . " set orders_status = 2, last_modified = now() where orders_id = '" . (int)$oIDCurr . "'");
}

$customer_notified = '1';

$email = STORE_NAME . "\n\n" . "Order Number: #" . ' ' . $oIDCurr . "\n" . "Invoice URL: "  . ' ' . tep_catalog_href_link(FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . $oIDCurr, 'SSL') . "\n" . "Date Ordered: " . ' ' . tep_date_long($check_status['date_purchased']) . "\n\n" . $notify_comments . sprintf(Updated , $orders_status_array[$status]);

           tep_mail($check_status['customers_name'], $check_status['customers_email_address'], "Order Update from Llamma Corp", $email, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

tep_db_query("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (orders_id, orders_status_id, date_added, customer_notified) values ('" . (int)$oIDCurr . "', 2, now(), '" . tep_db_input($customer_notified) . "')");
}

header( "Location: http://yoursite.com/catalog/admin/orders.php" )
?>

 

If you would like to try this out create the two files named as above add to your admin directory and add one table called 'order_invoice_printed' add to that table 2 rows called 'Order_ID' int(11) and 'Print_Status' char(1) you are up and running. As coded the orders in status 6 or 7 will be added to the list, alter the status line in multiprint.php to suit your needs.

 

So that the basic deal. It works, its probably not all that pretty. I think done right it could be done in a single file and without the need for an additional table.

 

What i would like to improve is the the ordering of the invoices. Once we have printed the stack we sort for any duplicate orders, we separate based on USPS shipped order and FedEx shipped orders and then order the postal service orders to group the heavier ones that will go USPS priority and the lighter ones that will be shipped USPS first class.

 

I would like automate the process by pre-sorting the orders, first grouping any orders from the same customer, then the various fedex descending by weight and then postal service descending by weight. It seems like building an array of the orders and then manipulate the array before it is presented to the screen might be a viable option and could also eliminate the need for a table. I believe this whole process could be contained in a single file as apposed to two as we have done above. Any input would be appreciated.

Link to comment
Share on other sites

You could join to the orders total table and sort on the description for the "ot_shipping" records.

 

HTH

 

G

Need help installing add ons/contributions, cleaning a hacked site or a bespoke development, check my profile

 

Virus Threat Scanner

My Contributions

Basic install answers.

Click here for Contributions / Add Ons.

UK your site.

Site Move.

Basic design info.

 

For links mentioned in old answers that are no longer here follow this link Useful Threads.

 

If this post was useful, click the Like This button over there ======>>>>>.

Link to comment
Share on other sites

  • 3 weeks later...

Thanks for the input. The information seems to only be available in the orders_history table.

The entries I need to use will all look something like the following.

 

United States Postal Service (1 x 1.75lbs) (1lbs, 12oz) (First-Class Mail International Package):

United States Postal Service (1 x 0.5lbs) (0lbs, 8oz) (Express Mail) :

United States Postal Service (1 x 0.6lbs) (0lbs, 9.6oz) (US Postal Service):

Federal Express (1 x 0.5lbs) (Home Delivery)

Federal Express (1 x 0.5lbs) (Express Saver (3 Day))

Federal Express (1 x 0.5lbs) (2 Day Air):

Federal Express (1 x 0.5lbs) (Standard Overnight (by 3PM, later for rural)):

Federal Express (1 x 0.5lbs) (Priority (by 10:30AM, later for rural)):

Federal Express (1 x 0.5lbs) (First Overnight):

 

 

I've also been working on some updates to my invoice and a part of this was adding a short carrier/service level so I added the following to look at the Orders History table.

 

	$check_shipping_query = tep_db_query("SELECT text, title from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$oID . "' and sort_order = 2");
$check_shipping = tep_db_fetch_array($check_shipping_query);

$service= substr($check_shipping['title'],0,1);
if ($service==U){
$carrier='USPS';
} else {
$carrier='FEDEX';
}

$pmtshort='PP';
if ($order->info['payment_method'] == "Check/Money Order") $pmtshort='MO';
if ($order->info['payment_method'] == 'Cardinal Centinel') $pmtshort='CC';

$shpclass=false;
IF (strpos($check_shipping['title'], "US Postal") !== false) $shpclass='Postal';
IF (strpos($check_shipping['title'], "Express Mail") !== false) $shpclass='Express';
IF (strpos($check_shipping['title'], "Express Mail International") !==false) $shpclass='<b>INTL Express</b>';
IF (strpos($check_shipping['title'], "Priority Mail International") !==false) $shpclass='<b>INTL Priority</b>';
IF (strpos($check_shipping['title'], "First-Class Mail International Package") !==false) $shpclass='<b>INTL First</b>';
IF (strpos($check_shipping['title'], "Home Delivery") !== false) $shpclass='Ground';
IF (strpos($check_shipping['title'], "Express Saver ") !== false) $shpclass='Saver';
IF (strpos($check_shipping['title'], "2 Day") !== false) $shpclass='2 Day';
IF (strpos($check_shipping['title'], "Standard Overnight") !== false) $shpclass='Overnight';
IF (strpos($check_shipping['title'], "by 10:30AM") !== false) $shpclass='POvernight';
IF (strpos($check_shipping['title'], "First Overnight") !== false) $shpclass='FOvernight';

 

So with the above I have the basic tools to get the job done I'm sure there are other methods. I'm pretty much a novice when it comes to PHP so I welcome any input or comments on prefered ways to accomplish the same thing.

 

So now the big question, where do I go from here? I should be able to build an array that includes the order number,carrier, service level, and the weight. Oh yeah the weight anyone know any cool commands to select the data between the first set of parenthesis in a string?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...