sorry to take so long on this just saw this
this one is a little more involved so do this.
if you need I can make a branch of the repo to see the changes, so let me know.
in 'sales/inquiry/sales_orders_view.php' do much like you did before. create a copy function and paste it near the edit function about line 115 in the page
function copy_link($row)
{
global $page_nested;
return pager_link(_("Copy Order") ,
"/sales/sales_order_entry.php?CopyOrder=". $row['order_no'], ICON_DOC);
}
then in that same file call it in the salesorder if statement around line 330 at the end of the file. (you could add it to other vues on the page if desired. the changed elseif should look like this. NOTE: it has the closing bracket from the last elseif above.
} elseif ($trans_type == ST_SALESORDER) {
array_append($cols,array(
_("Tmpl") => array('insert'=>true, 'fun'=>'tmpl_checkbox'),
array('insert'=>true, 'fun'=>'edit_link'),
array('insert'=>true, 'fun'=>'copy_link'),
array('insert'=>true, 'fun'=>'dispatch_link'),
array('insert'=>true, 'fun'=>'prt_link')));
};
Now the problem is the cart doesn't support copying orders like it did on deliveries/invoices. so we will add it.
in file 'sales/sales_order_entry.php' in the top array about line 36 add a CopyOrder type. the finished array should look like this.
array( 'NewOrder' => 'SA_SALESORDER',
'CopyOrder' => 'SA_SALESORDER',
'ModifyOrderNumber' => 'SA_SALESORDER',
'AddedID' => 'SA_SALESORDER',
'UpdatedID' => 'SA_SALESORDER',
'NewQuotation' => 'SA_SALESQUOTE',
'ModifyQuotationNumber' => 'SA_SALESQUOTE',
'NewQuoteToSalesOrder' => 'SA_SALESQUOTE',
'AddedQU' => 'SA_SALESQUOTE',
'UpdatedQU' => 'SA_SALESQUOTE',
'NewDelivery' => 'SA_SALESDELIVERY',
'AddedDN' => 'SA_SALESDELIVERY',
'NewInvoice' => 'SA_SALESINVOICE',
'AddedDI' => 'SA_SALESINVOICE'
)
in the same file the function create_cart() needs to be modified to allow this new 'CopyOrder' type to pass as a template. change the function to look like this
function create_cart($type, $trans_no)
{
global $Refs, $SysPrefs;
if (!$SysPrefs->db_ok) // create_cart is called before page() where the check is done
return;
processing_start();
if (isset($_GET['NewQuoteToSalesOrder']))
{
$trans_no = $_GET['NewQuoteToSalesOrder'];
$doc = new Cart(ST_SALESQUOTE, $trans_no, true);
$doc->Comments = _("Sales Quotation") . " # " . $trans_no;
$_SESSION['Items'] = $doc;
}
elseif(($type != ST_SALESORDER || isset($_GET['CopyOrder'])) && $type != ST_SALESQUOTE && $trans_no != 0) { // this is template
$doc = new Cart(ST_SALESORDER, array($trans_no));
$doc->trans_type = $type;
$doc->trans_no = 0;
$doc->document_date = new_doc_date();
if ($type == ST_SALESINVOICE) {
$doc->due_date = get_invoice_duedate($doc->payment, $doc->document_date);
$doc->pos = get_sales_point(user_pos());
} else
$doc->due_date = $doc->document_date;
$doc->reference = $Refs->get_next($doc->trans_type, null, array('date' => Today()));
//$doc->Comments='';
foreach($doc->line_items as $line_no => $line) {
$doc->line_items[$line_no]->qty_done = 0;
}
$_SESSION['Items'] = $doc;
} else
$_SESSION['Items'] = new Cart($type, array($trans_no));
copy_from_cart();
}
@apmuthu and @joe
here is an idea though I dont think it should be in core. People can already template an order and copy invoices and deliveries. if you copy or direct deliver you will get a delivery ref number and that could be used for an api unique ID. Or if you have to use an order could you not use the order# already?