Saturday, October 9, 2010

PrestaShop Tips - How to make order number, delivery number and invoice number the same?

At PrestaShop, order number, invoice number and delivery numbers are issued separately and independently. I think that it is nature to have different order/invoice/delivery numbers. It is kind of business activity log of your store.

But for management convenience purpose, some store owners may want to keep the following three numbers same, but have different prefix.
- order number, for example Ord20021
- invoice number, for example, Inv20021
- delivery number, for example DLR20021

This approach is not recommended, but doable with some code changes. If you really want to make all those numbers to be the same, you have an option to do so in following way. The key points of this approach are:
1. Keep invoice/delivery ID as it is in database
2. Use order # for other (invoice/delivery) numbers when display on UI
3. Use the Order # for other (invoice/delivery) numbers when generate PDF document

How to make this happen?
Note
A. The line number below are for reference purpose only, they might be slightly different at your copy of version. Please search the keyword to find the exact locations.
B. The changes listed here are just guidance purpose, I have not tested it yet. Please do test it by yourself before put it in service.


1. Make delivery number the same as that of order #
Replace following lines "$order->delivery_number" to "$order->id"(5 files, 7 lines)


\admin168\pdf.php(line:48): PDF::invoice($order, 'D', false, $tmp, false, $order->delivery_number);
\admin168\tabs\AdminOrders.php(line:434): (($currentState->delivery OR $order->delivery_number) ? ' - <a href="pdf.php?id_delivery='.$order->delivery_number.'"><img src="../img/admin/delivery.gif" alt="'.$this->l('View delivery slip').'" title="'.$this->l('View delivery slip').'" /></a>' : '').
\admin168\tabs\AdminOrders.php(line:527): '.(($currentState->delivery OR $order->delivery_number) ? '<br /><a href="pdf.php?id_delivery='.$order->delivery_number.'">'.$this->l('Delivery slip #').'<b>'.Configuration::get('PS_DELIVERY_PREFIX', intval($cookie->id_lang)).sprintf('%06d', $order->delivery_number).'</b></a><br />' : '');
\classes\Order.php(line:693): $this->delivery_number = $number;
\classes\Order.php(line:716): if ($orderState->delivery OR $order->delivery_number)
\classes\Order.php(line:717): echo '<a href="pdf.php?id_delivery='.intval($order->delivery_number).'"><img src="../img/admin/delivery.gif" alt="delivery" /></a>';
\classes\OrderHistory.php(line:93): if ($newOS->delivery AND !$order->delivery_number)
\classes\PDF.php(line:219): PDF::invoice($orderObj, 'D', true, $pdf, false, $orderObj->delivery_number);


2. Make invoice number the same as that of order #
Replace following lines "$order->invoice_number" to "$order->id" (7 files, 15 lines)


\admin168\tabs\AdminOrders.php(line:433): ((($currentState->invoice OR $order->invoice_number) AND count($products)) ? ' - <a href="pdf.php?id_order='.$order->id.'&pdf"><img src="../img/admin/tab-invoice.gif" alt="'.$this->l('View invoice').'" title="'.$this->l('View invoice').'" /></a>' : '').
\admin168\tabs\AdminOrders.php(line:513): if (($currentState->invoice OR $order->invoice_number) AND count($products))
\admin168\tabs\AdminOrders.php(line:517): <a href="pdf.php?id_order='.$order->id.'&pdf">'.$this->l('Invoice #').'<b>'.Configuration::get('PS_INVOICE_PREFIX', intval($cookie->id_lang)).sprintf('%06d', $order->invoice_number).'</b></a>
\classes\Order.php(line:158): $fields['invoice_number'] = intval($this->invoice_number);
\classes\Order.php(line:677): $this->invoice_number = $number;
\classes\Order.php(line:710): if (($orderState->invoice OR $order->invoice_number) AND intval($tr['product_number']))
\classes\OrderHistory.php(line:91): if ($newOS->invoice AND !$order->invoice_number)
\classes\PaymentModule.php(line:342): if (intval(Configuration::get('PS_INVOICE')) AND Validate::isLoadedObject($orderStatus) AND $orderStatus->invoice AND $order->invoice_number)
\classes\PaymentModule.php(line:345): $fileAttachment['name'] = Configuration::get('PS_INVOICE_PREFIX', intval($order->id_lang)).sprintf('%06d', $order->invoice_number).'.pdf';
\classes\PDF.php(line:150): elseif (self::$order->invoice_number)
\classes\PDF.php(line:151): $this->Cell(77, 10, self::l('INVOICE #').' '.Configuration::get('PS_INVOICE_PREFIX', intval($cookie->id_lang)).sprintf('%06d', self::$order->invoice_number), 0, 1, 'R');
\classes\PDF.php(line:354): if (!Validate::isLoadedObject($order) OR (!$cookie->id_employee AND (!OrderState::invoiceAvailable($order->getCurrentState()) AND !$order->invoice_number)))
\classes\PDF.php(line:443): $pdf->Cell(0, 6, self::l('INVOICE #').Configuration::get('PS_INVOICE_PREFIX', intval($cookie->id_lang)).sprintf('%06d', self::$order->invoice_number).' '.self::l('from') . ' ' .Tools::displayDate(self::$order->invoice_date, self::$order->id_lang), 1, 2, 'L', 1);
\order-detail.php(line:88): 'invoice' => (OrderState::invoiceAvailable(intval($id_order_state)) AND $order->invoice_number),
\pdf-invoice.php(line:17):elseif (!OrderState::invoiceAvailable($order->getCurrentState()) AND !$order->invoice_number)

No comments: