+ $ret = $_SESSION['Items']->write(1);
+ if ($ret == -1)
+ {
+ display_error(_("The entered reference is already in use."));
+ $ref = $Refs->get_next($_SESSION['Items']->trans_type, null, array('date' => Today()));
+ if ($ref != $_SESSION['Items']->reference)
+ {
+ unset($_POST['ref']); // force refresh reference
+ display_error(_("The reference number field has been increased. Please save the document again."));
+ }
+ set_focus('ref');
+ }
+ else
+ {
+ if (count($messages)) { // abort on failure or error messages are lost
+ $Ajax->activate('_page_body');
+ display_footer_exit();
+ }
+ $trans_no = key($_SESSION['Items']->trans_no);
+ $trans_type = $_SESSION['Items']->trans_type;
+ new_doc_date($_SESSION['Items']->document_date);
+ processing_end();
+ if ($modified) {
+ if ($trans_type == ST_SALESQUOTE)
+ meta_forward($_SERVER['PHP_SELF'], "UpdatedQU=$trans_no");
+ else
+ meta_forward($_SERVER['PHP_SELF'], "UpdatedID=$trans_no");
+ } elseif ($trans_type == ST_SALESORDER) {
+ meta_forward($_SERVER['PHP_SELF'], "AddedID=$trans_no");
+ } elseif ($trans_type == ST_SALESQUOTE) {
+ meta_forward($_SERVER['PHP_SELF'], "AddedQU=$trans_no");
+ } elseif ($trans_type == ST_SALESINVOICE) {
+ meta_forward($_SERVER['PHP_SELF'], "AddedDI=$trans_no&Type=$so_type");
+ } else {
+ meta_forward($_SERVER['PHP_SELF'], "AddedDN=$trans_no&Type=$so_type");
+ }
+ }