AND DATE_ADD(recurringsalesorders.lastrecurrence, ' . INTERVAL('365/recurringsalesorders.frequency', 'DAY') . ') <= recurringsalesorders.stopdate'; $RecurrOrdersDueResult = DB_query($sql, $db, _('There was a problem retrieving the recurring sales order templates. The database reported:')); if (DB_num_rows($RecurrOrdersDueResult) == 0) { prnMsg(_('There are no recurring order templates that are due to have another recurring order created'), 'warn'); include 'includes/footer.inc'; exit; } echo '<BR>The number of recurring orders to process is : ' . DB_num_rows($RecurrOrdersDueResult); while ($RecurrOrderRow = DB_fetch_array($RecurrOrdersDueResult)) { $EmailText = ''; echo '<BR>' . _('Recurring order') . ' ' . $RecurrOrderRow['recurrorderno'] . ' ' . _('for') . ' ' . $RecurrOrderRow['debtorno'] . ' - ' . $RecurrOrderRow['branchcode'] . ' ' . _('is being processed'); $result = DB_Txn_Begin($db); /*the last recurrence was the date of the last time the order recurred the frequency is the number of times per annum that the order should recurr so 365 / frequency gives the number of days between recurrences */ $DelDate = FormatDateforSQL(DateAdd(ConvertSQLDate($RecurrOrderRow['lastrecurrence']), 'd', 365 / $RecurrOrderRow['frequency'])); echo '<BR>Date calculated for the next recurrence was: ' . $DelDate; $HeaderSQL = "INSERT INTO salesorders (\n\t\t\t\tdebtorno,\n\t\t\t\tbranchcode,\n\t\t\t\tcustomerref,\n\t\t\t\tcomments,\n\t\t\t\torddate,\n\t\t\t\tordertype,\n\t\t\t\tshipvia,\n\t\t\t\tdeliverto,\n\t\t\t\tdeladd1,\n\t\t\t\tdeladd2,\n\t\t\t\tdeladd3,\n\t\t\t\tdeladd4,\n\t\t\t\tdeladd5,\n\t\t\t\tdeladd6,\n\t\t\t\tcontactphone,\n\t\t\t\tcontactemail,\n\t\t\t\tfreightcost,\n\t\t\t\tfromstkloc,\n\t\t\t\tdeliverydate )\n\t\t\tVALUES (\n\t\t\t\t'" . $RecurrOrderRow['debtorno'] . "',\n\t\t\t\t'" . $RecurrOrderRow['branchcode'] . "',\n\t\t\t\t'" . $RecurrOrderRow['customerref'] . "',\n\t\t\t\t'" . $RecurrOrderRow['comments'] . "',\n\t\t\t\t'" . $DelDate . "',\n\t\t\t\t'" . $RecurrOrderRow['ordertype'] . "',\n\t\t\t\t" . $RecurrOrderRow['shipvia'] . ",\n\t\t\t\t'" . $RecurrOrderRow['deliverto'] . "',\n\t\t\t\t'" . $RecurrOrderRow['deladd1'] . "',\n\t\t\t\t'" . $RecurrOrderRow['deladd2'] . "',\n\t\t\t\t'" . $RecurrOrderRow['deladd3'] . "',\n\t\t\t\t'" . $RecurrOrderRow['deladd4'] . "',\n\t\t\t\t'" . $RecurrOrderRow['deladd5'] . "',\n\t\t\t\t'" . $RecurrOrderRow['deladd6'] . "',\n\t\t\t\t'" . $RecurrOrderRow['contactphone'] . "',\n\t\t\t\t'" . $RecurrOrderRow['contactemail'] . "',\n\t\t\t\t" . $RecurrOrderRow['freightcost'] . ",\n\t\t\t\t'" . $RecurrOrderRow['fromstkloc'] . "',\n\t\t\t\t'" . $DelDate . "')"; $ErrMsg = _('The order cannot be added because'); $InsertQryResult = DB_query($HeaderSQL, $db, $ErrMsg, true); $OrderNo = GetNextTransNo(30, $db); $EmailText = _('A new order has been created from a recurring order template for customer') . ' ' . $RecurrOrderRow['debtorno'] . ' ' . $RecurrOrderRow['branchcode'] . "\n" . _('The order number is:') . ' ' . $OrderNo; /*need to look up RecurringOrder from the template and populate the line RecurringOrder array with the sales order details records */ $LineItemsSQL = "SELECT recurrsalesorderdetails.stkcode,\n\t\t\t\trecurrsalesorderdetails.unitprice,\n\t\t\t\trecurrsalesorderdetails.quantity,\n\t\t\t\trecurrsalesorderdetails.discountpercent,\n\t\t\t\trecurrsalesorderdetails.narrative,\n\t\t\t\tstockmaster.taxcatid\n\t\t\tFROM recurrsalesorderdetails INNER JOIN stockmaster\n\t\t\t\tON recurrsalesorderdetails.stkcode = stockmaster.stockid\n\t\t\tWHERE recurrsalesorderdetails.recurrorderno =" . $RecurrOrderRow['recurrorderno']; $ErrMsg = _('The line items of the recurring order cannot be retrieved because'); $LineItemsResult = db_query($LineItemsSQL, $db, $ErrMsg); $LineCounter = 0; if (db_num_rows($LineItemsResult) > 0) { $OrderTotal = 0; //intialise $OrderLineTotal = 0;
function ModifySalesOrderHeader($OrderHeader, $user, $password) { $Errors = array(); $db = db($user, $password); if (gettype($db) == 'integer') { $Errors[0] = NoAuthorisation; return $Errors; } foreach ($OrderHeader as $key => $value) { $OrderHeader[$key] = DB_escape_string($value); } $Errors = VerifyOrderHeaderExists($OrderHeader['orderno'], sizeof($Errors), $Errors, $db); $Errors = VerifyDebtorExists($OrderHeader['debtorno'], sizeof($Errors), $Errors, $db); $Errors = VerifyBranchNoExists($OrderHeader['debtorno'], $OrderHeader['branchcode'], sizeof($Errors), $Errors, $db); if (isset($OrderHeader['customerref'])) { $Errors = VerifyCustomerRef($OrderHeader['customerref'], sizeof($Errors), $Errors); } if (isset($OrderHeader['buyername'])) { $Errors = VerifyBuyerName($OrderHeader['buyername'], sizeof($Errors), $Errors); } if (isset($OrderHeader['comments'])) { $Errors = VerifyComments($OrderHeader['comments'], sizeof($Errors), $Errors); } if (isset($OrderHeader['orddate'])) { $Errors = VerifyOrderDate($OrderHeader['orddate'], sizeof($Errors), $Errors, $db); } if (isset($OrderHeader['ordertype'])) { $Errors = VerifyOrderType($OrderHeader['ordertype'], sizeof($Errors), $Errors, $db); } if (isset($OrderHeader['shipvia'])) { $Errors = VerifyShipVia($OrderHeader['shipvia'], sizeof($Errors), $Errors, $db); } if (isset($OrderHeader['deladd1'])) { $Errors = VerifyAddressLine($OrderHeader['deladd1'], 40, sizeof($Errors), $Errors); } if (isset($OrderHeader['deladd2'])) { $Errors = VerifyAddressLine($OrderHeader['deladd2'], 40, sizeof($Errors), $Errors); } if (isset($OrderHeader['deladd3'])) { $Errors = VerifyAddressLine($OrderHeader['deladd3'], 40, sizeof($Errors), $Errors); } if (isset($OrderHeader['deladd4'])) { $Errors = VerifyAddressLine($OrderHeader['deladd4'], 40, sizeof($Errors), $Errors); } if (isset($OrderHeader['deladd5'])) { $Errors = VerifyAddressLine($OrderHeader['deladd5'], 20, sizeof($Errors), $Errors); } if (isset($OrderHeader['deladd6'])) { $Errors = VerifyAddressLine($OrderHeader['deladd6'], 15, sizeof($Errors), $Errors); } if (isset($OrderHeader['contactphone'])) { $Errors = VerifyPhoneNumber($OrderHeader['contactphone'], sizeof($Errors), $Errors); } if (isset($OrderHeader['contactemail'])) { $Errors = VerifyEmailAddress($OrderHeader['contactemail'], sizeof($Errors), $Errors); } if (isset($OrderHeader['deliverto'])) { $Errors = VerifyDeliverTo($OrderHeader['deliverto'], sizeof($Errors), $Errors); } if (isset($OrderHeader['deliverblind'])) { $Errors = VerifyDeliverBlind($OrderHeader['deliverblind'], sizeof($Errors), $Errors); } if (isset($OrderHeader['freightcost'])) { $Errors = VerifyFreightCost($OrderHeader['freightcost'], sizeof($Errors), $Errors); } if (isset($OrderHeader['fromstkloc'])) { $Errors = VerifyFromStockLocation($OrderHeader['fromstkloc'], sizeof($Errors), $Errors, $db); } if (isset($OrderHeader['deliverydate'])) { $Errors = VerifyDeliveryDate($OrderHeader['deliverydate'], sizeof($Errors), $Errors, $db); } if (isset($OrderHeader['quotation'])) { $Errors = VerifyQuotation($OrderHeader['quotation'], sizeof($Errors), $Errors); } global $SOH_DateFields; $sql = 'UPDATE salesorders SET '; foreach ($OrderHeader as $key => $value) { if (in_array($key, $SOH_DateFields)) { $value = FormatDateforSQL($value); } // Fix dates $sql .= $key . '="' . $value . '", '; } $sql = substr($sql, 0, -2) . ' WHERE orderno="' . $OrderHeader['orderno'] . '"'; if (sizeof($Errors) == 0) { $result = api_DB_Query($sql, $db); echo DB_error_no($db); if (DB_error_no($db) != 0) { $Errors[0] = DatabaseUpdateFailed; } else { $Errors[0] = 0; } } return $Errors; }
echo '<p><img src="' . $rootpath . '/css/' . $theme . '/images/reports.png" title="' . _('Order') . '" alt="">' . ' ' . '<a href="' . $rootpath . '/PDFQuotation.php?' . SID . 'identifier=' . $identifier . '&QuotationNo=' . $OrderNo . '">' . _('Print Quotation') . '</a>'; } echo '<div class="centre"><p><img src="' . $rootpath . '/css/' . $theme . '/images/sales.png" title="' . _('Order') . '" alt="">' . ' ' . '<a href="' . $rootpath . '/SelectOrderItems.php?' . SID . 'identifier=' . $identifier . '&NewOrder=Yes">' . _('Add Sales Order') . '</a></div>'; } else { /*its a customer logon so thank them */ prnMsg(_('Thank you for your business'), 'success'); } unset($_SESSION['Items' . $identifier]->LineItems); unset($_SESSION['Items' . $identifier]); include 'includes/footer.inc'; exit; } elseif (isset($OK_to_PROCESS) and $OK_to_PROCESS == 1 && $_SESSION['ExistingOrder'] != 0) { /* update the order header then update the old order line details and insert the new lines */ $DelDate = FormatDateforSQL($_SESSION['Items' . $identifier]->DeliveryDate); $QuotDate = FormatDateforSQL($_SESSION['Items' . $identifier]->QuoteDate); $ConfDate = FormatDateforSQL($_SESSION['Items' . $identifier]->ConfirmedDate); $Result = DB_Txn_Begin($db); $HeaderSQL = 'UPDATE salesorders SET debtorno = ' . "'" . $_SESSION['Items' . $identifier]->DebtorNo . "'" . ', branchcode = ' . "'" . $_SESSION['Items' . $identifier]->Branch . "'" . ', customerref = ' . "'" . DB_escape_string($_SESSION['Items' . $identifier]->CustRef) . "'" . ', comments = ' . "'" . DB_escape_string($_SESSION['Items' . $identifier]->Comments) . "'" . ', ordertype = ' . "'" . $_SESSION['Items' . $identifier]->DefaultSalesType . "'" . ', shipvia = ' . $_POST['ShipVia'] . ', deliverydate = ' . "'" . FormatDateForSQL(DB_escape_string($_SESSION['Items' . $identifier]->DeliveryDate)) . "'" . ', quotedate = ' . "'" . FormatDateForSQL(DB_escape_string($_SESSION['Items' . $identifier]->QuoteDate)) . "'" . ', confirmeddate = ' . "'" . FormatDateForSQL(DB_escape_string($_SESSION['Items' . $identifier]->ConfirmedDate)) . "'" . ', deliverto = ' . "'" . DB_escape_string($_SESSION['Items' . $identifier]->DeliverTo) . "'" . ', deladd1 = ' . "'" . DB_escape_string($_SESSION['Items' . $identifier]->DelAdd1) . "'" . ', deladd2 = ' . "'" . DB_escape_string($_SESSION['Items' . $identifier]->DelAdd2) . "'" . ', deladd3 = ' . "'" . DB_escape_string($_SESSION['Items' . $identifier]->DelAdd3) . "'" . ',
$myrow = DB_fetch_row($StockItemsResult); $SelectedStockItem = $myrow[0]; $_POST['SearchOrders'] = 'True'; unset($StockItemsResult); echo '<br>' . _('For the part') . ': ' . $SelectedStockItem . ' ' . _('and') . " <input type=hidden name='SelectedStockItem' value='{$SelectedStockItem}'>"; } } } else { if (isset($_POST['SearchOrders']) and Is_Date($_POST['OrdersAfterDate']) == 1) { //figure out the SQL required from the inputs available if (isset($OrderNumber)) { $SQL = "SELECT salesorders.orderno, \n\t\t\t\t\tdebtorsmaster.name, \n\t\t\t\t\tcustbranch.brname, \n\t\t\t\t\tsalesorders.customerref, \n\t\t\t\t\tsalesorders.orddate, \n\t\t\t\t\tsalesorders.deliverydate, \n\t\t\t\t\tsalesorders.deliverto, SUM(salesorderdetails.unitprice*salesorderdetails.quantity*(1-salesorderdetails.discountpercent)) AS ordervalue \n\t\t\t\tFROM salesorders, \n\t\t\t\t\tsalesorderdetails, \n\t\t\t\t\tdebtorsmaster, \n\t\t\t\t\tcustbranch \n\t\t\t\tWHERE salesorders.orderno = salesorderdetails.orderno \n\t\t\t\tAND salesorders.branchcode = custbranch.branchcode \n\t\t\t\tAND salesorders.debtorno = debtorsmaster.debtorno \n\t\t\t\tAND debtorsmaster.debtorno = custbranch.debtorno \n\t\t\t\tAND salesorders.orderno=" . $OrderNumber . " \n\t\t\t\tAND salesorders.quotation=0 \n\t\t\t\tAND salesorderdetails.completed" . $completed . " \n\t\t\t\tGROUP BY salesorders.orderno,\n\t\t\t\t\tdebtorsmaster.name, \n\t\t\t\t\tcustbranch.brname, \n\t\t\t\t\tsalesorders.customerref, \n\t\t\t\t\tsalesorders.orddate, \n\t\t\t\t\tsalesorders.deliverydate, \n\t\t\t\t\tsalesorders.deliverto\n\t\t\t\tORDER BY salesorders.orderno"; } elseif (isset($CustomerRef)) { $SQL = "SELECT salesorders.orderno, \n\t\t\t\t\tdebtorsmaster.name, \n\t\t\t\t\tcustbranch.brname, \n\t\t\t\t\tsalesorders.customerref, \n\t\t\t\t\tsalesorders.orddate, \n\t\t\t\t\tsalesorders.deliverydate, \n\t\t\t\t\tsalesorders.deliverto, SUM(salesorderdetails.unitprice*salesorderdetails.quantity*(1-salesorderdetails.discountpercent)) AS ordervalue \n\t\t\t\tFROM salesorders, \n\t\t\t\t\tsalesorderdetails, \n\t\t\t\t\tdebtorsmaster, \n\t\t\t\t\tcustbranch \n\t\t\t\tWHERE salesorders.orderno = salesorderdetails.orderno \n\t\t\t\tAND salesorders.branchcode = custbranch.branchcode \n\t\t\t\tAND salesorders.debtorno = debtorsmaster.debtorno \n\t\t\t\tAND debtorsmaster.debtorno = custbranch.debtorno \n\t\t\t\tAND salesorders.customerref like '%" . $CustomerRef . "%'\n\t\t\t\tAND salesorders.quotation=0 \n\t\t\t\tAND salesorderdetails.completed" . $completed . " \n\t\t\t\tGROUP BY salesorders.orderno,\n\t\t\t\t\tdebtorsmaster.name, \n\t\t\t\t\tcustbranch.brname, \n\t\t\t\t\tsalesorders.customerref, \n\t\t\t\t\tsalesorders.orddate, \n\t\t\t\t\tsalesorders.deliverydate, \n\t\t\t\t\tsalesorders.deliverto\n\t\t\t\tORDER BY salesorders.orderno"; } else { $DateAfterCriteria = FormatDateforSQL($_POST['OrdersAfterDate']); if (isset($SelectedCustomer) and !isset($OrderNumber) and !isset($CustomerRef)) { if (isset($SelectedStockItem)) { $SQL = "SELECT salesorders.orderno, \n\t\t\t\t\t\tdebtorsmaster.name, \n\t\t\t\t\t\tcustbranch.brname, \n\t\t\t\t\t\tsalesorders.customerref, \n\t\t\t\t\t\tsalesorders.orddate, \n\t\t\t\t\t\tsalesorders.deliverydate, \n\t\t\t\t\t\tsalesorders.deliverto, SUM(salesorderdetails.unitprice*salesorderdetails.quantity*(1-salesorderdetails.discountpercent)) AS ordervalue \n\t\t\t\t\tFROM salesorders, \n\t\t\t\t\t\tsalesorderdetails, \n\t\t\t\t\t\tdebtorsmaster, \n\t\t\t\t\t\tcustbranch \n\t\t\t\t\tWHERE salesorders.orderno = salesorderdetails.orderno \n\t\t\t\t\tAND salesorders.branchcode = custbranch.branchcode \n\t\t\t\t\tAND salesorders.debtorno = debtorsmaster.debtorno \n\t\t\t\t\tAND debtorsmaster.debtorno = custbranch.debtorno \n\t\t\t\t\tAND salesorderdetails.stkcode='" . $SelectedStockItem . "' \n\t\t\t\t\tAND salesorders.debtorno='" . $SelectedCustomer . "' \n\t\t\t\t\tAND salesorders.orddate >= '" . $DateAfterCriteria . "' \n\t\t\t\t\tAND salesorders.quotation=0 \n\t\t\t\t\tAND salesorderdetails.completed" . $completed . " \n\t\t\t\t\tGROUP BY salesorders.orderno, \n\t\t\t\t\t\tdebtorsmaster.name, \n\t\t\t\t\t\tcustbranch.brname, \n\t\t\t\t\t\tsalesorders.customerref, \n\t\t\t\t\t\tsalesorders.orddate, \n\t\t\t\t\t\tsalesorders.deliverydate, \n\t\t\t\t\t\tsalesorders.deliverto\n\t\t\t\t\tORDER BY salesorders.orderno"; } else { $SQL = "SELECT salesorders.orderno, \n\t\t\t\t\t\tdebtorsmaster.name, \n\t\t\t\t\t\tcustbranch.brname, \n\t\t\t\t\t\tsalesorders.customerref, \n\t\t\t\t\t\tsalesorders.orddate, \n\t\t\t\t\t\tsalesorders.deliverto, \n\t\t\t\t\t\tsalesorders.deliverydate, SUM(salesorderdetails.unitprice*salesorderdetails.quantity*(1-salesorderdetails.discountpercent)) AS ordervalue \n\t\t\t\t\tFROM salesorders, \n\t\t\t\t\t\tsalesorderdetails, \n\t\t\t\t\t\tdebtorsmaster, \n\t\t\t\t\t\tcustbranch \n\t\t\t\t\tWHERE salesorders.orderno = salesorderdetails.orderno \n\t\t\t\t\tAND salesorders.debtorno = debtorsmaster.debtorno \n\t\t\t\t\tAND salesorders.branchcode = custbranch.branchcode \n\t\t\t\t\tAND debtorsmaster.debtorno = custbranch.debtorno \n\t\t\t\t\tAND salesorders.debtorno='" . $SelectedCustomer . "' \n\t\t\t\t\tAND salesorders.orddate >= '" . $DateAfterCriteria . "' \n\t\t\t\t\tAND salesorders.quotation=0 \n\t\t\t\t\tAND salesorderdetails.completed" . $completed . " \n\t\t\t\t\tGROUP BY salesorders.orderno, \n\t\t\t\t\t\tdebtorsmaster.name, \n\t\t\t\t\t\tcustbranch.brname, \n\t\t\t\t\t\tsalesorders.customerref, \n\t\t\t\t\t\tsalesorders.orddate, \n\t\t\t\t\t\tsalesorders.deliverydate, \n\t\t\t\t\t\tsalesorders.deliverto\n\t\t\t\t\tORDER BY salesorders.orderno"; } } else { //no customer selected if (isset($SelectedStockItem)) { $SQL = "SELECT salesorders.orderno, \n\t\t\t\t\t\tdebtorsmaster.name, \n\t\t\t\t\t\tcustbranch.brname, \n\t\t\t\t\t\tsalesorders.customerref, \n\t\t\t\t\t\tsalesorders.orddate, \n\t\t\t\t\t\tsalesorders.deliverto, \n\t\t\t\t\t\tsalesorders.deliverydate, SUM(salesorderdetails.unitprice*salesorderdetails.quantity*(1-salesorderdetails.discountpercent)) AS ordervalue \n\t\t\t\t\tFROM salesorders, \n\t\t\t\t\t\tsalesorderdetails, \n\t\t\t\t\t\tdebtorsmaster, \n\t\t\t\t\t\tcustbranch \n\t\t\t\t\tWHERE salesorders.orderno = salesorderdetails.orderno \n\t\t\t\t\tAND salesorders.debtorno = debtorsmaster.debtorno \n\t\t\t\t\tAND salesorders.branchcode = custbranch.branchcode \n\t\t\t\t\tAND debtorsmaster.debtorno = custbranch.debtorno \n\t\t\t\t\tAND salesorderdetails.stkcode='" . $SelectedStockItem . "' \n\t\t\t\t\tAND salesorders.orddate >= '" . $DateAfterCriteria . "' \n\t\t\t\t\tAND salesorders.quotation=0 \n\t\t\t\t\tAND salesorderdetails.completed" . $completed . " \n\t\t\t\t\tGROUP BY salesorders.orderno, \n\t\t\t\t\t\tdebtorsmaster.name, \n\t\t\t\t\t\tcustbranch.brname, \n\t\t\t\t\t\tsalesorders.customerref, \n\t\t\t\t\t\tsalesorders.orddate, \n\t\t\t\t\t\tsalesorders.deliverydate, \n\t\t\t\t\t\tsalesorders.deliverto\n\t\t\t\t\tORDER BY salesorders.orderno"; } else { $SQL = "SELECT salesorders.orderno, \n\t\t\t\t\t\tdebtorsmaster.name, \n\t\t\t\t\t\tcustbranch.brname, \n\t\t\t\t\t\tsalesorders.customerref, \n\t\t\t\t\t\tsalesorders.orddate, \n\t\t\t\t\t\tsalesorders.deliverto, \n\t\t\t\t\t\tsalesorders.deliverydate, SUM(salesorderdetails.unitprice*salesorderdetails.quantity*(1-salesorderdetails.discountpercent)) AS ordervalue \n\t\t\t\t\tFROM salesorders, \n\t\t\t\t\t\tsalesorderdetails, \n\t\t\t\t\t\tdebtorsmaster, \n\t\t\t\t\t\tcustbranch \n\t\t\t\t\tWHERE salesorders.orderno = salesorderdetails.orderno \n\t\t\t\t\tAND salesorders.debtorno = debtorsmaster.debtorno \n\t\t\t\t\tAND salesorders.branchcode = custbranch.branchcode \n\t\t\t\t\tAND debtorsmaster.debtorno = custbranch.debtorno \n\t\t\t\t\tAND salesorders.orddate >= '{$DateAfterCriteria}' \n\t\t\t\t\tAND salesorders.quotation=0 \n\t\t\t\t\tAND salesorderdetails.completed" . $completed . " \n\t\t\t\t\tGROUP BY salesorders.orderno, \n\t\t\t\t\t\tdebtorsmaster.name, \n\t\t\t\t\t\tcustbranch.brname, \n\t\t\t\t\t\tsalesorders.customerref, \n\t\t\t\t\t\tsalesorders.orddate, \n\t\t\t\t\t\tsalesorders.deliverydate, \n\t\t\t\t\t\tsalesorders.deliverto\n\t\t\t\t\tORDER BY salesorders.orderno"; } } //end selected customer
$ErrMsg = _('The recurring order cannot be added because'); $DbgMsg = _('The SQL that failed was'); $InsertQryResult = DB_query($HeaderSQL, $ErrMsg, $DbgMsg, true); $RecurrOrderNo = DB_Last_Insert_ID($db, 'recurringsalesorders', 'recurrorderno'); echo 'xxx' . $RecurrOrderNo; $StartOf_LineItemsSQL = "INSERT INTO recurrsalesorderdetails (recurrorderno,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tstkcode,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tunitprice,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tquantity,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdiscountpercent,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tnarrative)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tVALUES ('"; foreach ($_SESSION['Items' . $identifier]->LineItems as $StockItem) { $LineItemsSQL = $StartOf_LineItemsSQL . $RecurrOrderNo . "',\n\t\t\t\t\t\t\t\t'" . $StockItem->StockID . "',\n\t\t\t\t\t\t\t\t'" . filter_number_format($StockItem->Price) . "',\n\t\t\t\t\t\t\t\t'" . filter_number_format($StockItem->Quantity) . "',\n\t\t\t\t\t\t\t\t'" . filter_number_format($StockItem->DiscountPercent) . "',\n\t\t\t\t\t\t\t\t'" . $StockItem->Narrative . "')"; $Ins_LineItemResult = DB_query($LineItemsSQL, $ErrMsg, $DbgMsg, true); } /* inserted line items into sales order details */ $result = DB_Txn_Commit(); prnmsg(_('The new recurring order template has been added'), 'success'); } else { /* must be updating an existing recurring order */ $HeaderSQL = "UPDATE recurringsalesorders SET\n\t\t\t\t\t\tstopdate = '" . FormatDateforSQL($_POST['StopDate']) . "',\n\t\t\t\t\t\tfrequency = '" . $_POST['Frequency'] . "',\n\t\t\t\t\t\tautoinvoice = '" . $_POST['AutoInvoice'] . "'\n\t\t\t\t\tWHERE recurrorderno = '" . $_POST['ExistingRecurrOrderNo'] . "'"; $ErrMsg = _('The recurring order cannot be updated because'); $UpdateQryResult = DB_query($HeaderSQL, $ErrMsg); prnmsg(_('The recurring order template has been updated'), 'success'); } echo '<p><a href="' . $RootPath . '/SelectOrderItems.php?NewOrder=Yes">' . _('Enter New Sales Order') . '</a>'; echo '<p><a href="' . $RootPath . '/SelectRecurringSalesOrder.php">' . _('Select A Recurring Sales Order Template') . '</a>'; unset($_SESSION['Items' . $identifier]->LineItems); unset($_SESSION['Items' . $identifier]); include 'includes/footer.inc'; exit; } } echo '<p class="page_title_text"><img src="' . $RootPath . '/css/' . $Theme . '/images/customer.png" title="' . _('Search') . '" alt="" /><b>' . ' ' . _('Recurring Order for Customer') . ' : ' . $_SESSION['Items' . $identifier]->CustomerName . '</b></p>'; echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8') . '?identifier=' . $identifier . '" method="post">'; echo '<div>';
$DelDate = FormatDateforSQL($_SESSION['Items']->DeliveryDate); $HeaderSQL = "INSERT INTO recurringsalesorders (\n\t\t\t\t\tdebtorno,\n\t\t\t\t\tbranchcode,\n\t\t\t\t\tcustomerref,\n\t\t\t\t\tcomments,\n\t\t\t\t\torddate,\n\t\t\t\t\tordertype,\n\t\t\t\t\tdeliverto,\n\t\t\t\t\tdeladd1,\n\t\t\t\t\tdeladd2,\n\t\t\t\t\tdeladd3,\n\t\t\t\t\tdeladd4,\n\t\t\t\t\tdeladd5,\n\t\t\t\t\tdeladd6,\n\t\t\t\t\tcontactphone,\n\t\t\t\t\tcontactemail,\n\t\t\t\t\tfreightcost,\n\t\t\t\t\tfromstkloc,\n\t\t\t\t\tshipvia,\n\t\t\t\t\tlastrecurrence,\n\t\t\t\t\tstopdate,\n\t\t\t\t\tfrequency,\n\t\t\t\t\tautoinvoice)\n\t\t\t\tVALUES (\n\t\t\t\t\t'" . $_SESSION['Items']->DebtorNo . "',\n\t\t\t\t\t'" . $_SESSION['Items']->Branch . "',\n\t\t\t\t\t'" . $_SESSION['Items']->CustRef . "',\n\t\t\t\t\t'" . $_SESSION['Items']->Comments . "',\n\t\t\t\t\t'" . Date("Y-m-d H:i") . "',\n\t\t\t\t\t'" . $_SESSION['Items']->DefaultSalesType . "',\n\t\t\t\t\t'" . $_SESSION['Items']->DeliverTo . "',\n\t\t\t\t\t'" . $_SESSION['Items']->BrAdd1 . "',\n\t\t\t\t\t'" . $_SESSION['Items']->BrAdd2 . "',\n\t\t\t\t\t'" . $_SESSION['Items']->BrAdd3 . "',\n\t\t\t\t\t'" . $_SESSION['Items']->BrAdd4 . "',\n\t\t\t\t\t'" . $_SESSION['Items']->BrAdd5 . "',\n\t\t\t\t\t'" . $_SESSION['Items']->BrAdd6 . "',\n\t\t\t\t\t'" . $_SESSION['Items']->PhoneNo . "',\n\t\t\t\t\t'" . $_SESSION['Items']->Email . "',\n\t\t\t\t\t" . $_SESSION['Items']->FreightCost . ",\n\t\t\t\t\t'" . $_SESSION['Items']->Location . "',\n\t\t\t\t\t'" . $_SESSION['Items']->ShipVia . "',\n\t\t\t\t\t'" . FormatDateforSQL($_POST['StartDate']) . "',\n\t\t\t\t\t'" . FormatDateforSQL($_POST['StopDate']) . "',\n\t\t\t\t\t" . $_POST['Frequency'] . ', ' . $_POST['AutoInvoice'] . ')'; $ErrMsg = _('The recurring order cannot be added because'); $InsertQryResult = DB_query($HeaderSQL, $db, $ErrMsg); $RecurrOrderNo = DB_Last_Insert_ID($db, 'recurringsalesorders', 'recurrorderno'); $StartOf_LineItemsSQL = "INSERT INTO recurrsalesorderdetails (\n\t\t\t\t\t\trecurrorderno,\n\t\t\t\t\t\tstkcode,\n\t\t\t\t\t\tunitprice,\n\t\t\t\t\t\tquantity,\n\t\t\t\t\t\tdiscountpercent,\n\t\t\t\t\t\tnarrative)\n\t\t\t\t\tVALUES ("; foreach ($_SESSION['Items']->LineItems as $StockItem) { $LineItemsSQL = $StartOf_LineItemsSQL . $RecurrOrderNo . ",\n\t\t\t\t\t'" . $StockItem->StockID . "',\n\t\t\t\t\t" . $StockItem->Price . ",\n\t\t\t\t\t" . $StockItem->Quantity . ",\n\t\t\t\t\t" . $StockItem->DiscountPercent . ",\n\t\t\t\t\t'" . $StockItem->Narrative . "'\n\t\t\t\t)"; $Ins_LineItemResult = DB_query($LineItemsSQL, $db); } /* inserted line items into sales order details */ prnmsg(_('The new recurring order template has been added'), 'success'); } else { /* must be updating an existing recurring order */ $HeaderSQL = "UPDATE recurringsalesorders SET\n\t\t\t\t\t\tstopdate = '" . FormatDateforSQL($_POST['StopDate']) . "',\n\t\t\t\t\t\tfrequency = " . $_POST['Frequency'] . ",\n\t\t\t\t\t\tautoinvoice = " . $_POST['AutoInvoice'] . ' WHERE recurrorderno = ' . $_POST['ExistingRecurrOrderNo']; $ErrMsg = _('The recurring order cannot be updated because'); $UpdateQryResult = DB_query($HeaderSQL, $db, $ErrMsg); prnmsg(_('The recurring order template has been updated'), 'success'); } echo "<P><A HREF='{$rootpath}/SelectOrderItems.php?" . SID . "&NewOrder=Yes'>" . _('Enter New Sales Order') . '</A>'; echo "<P><A HREF='{$rootpath}/SelectRecurringSalesOrder.php?" . SID . "'>" . _('Select A Recurring Sales Order Template') . '</A>'; unset($_SESSION['Items']->LineItems); unset($_SESSION['Items']); include 'includes/footer.inc'; exit; } } echo '<CENTER><FONT SIZE=4><B>' . _('Recurring Order for Customer') . ' : ' . $_SESSION['Items']->CustomerName . '</B></FONT></CENTER>'; echo "<FORM ACTION='" . $_SERVER['PHP_SELF'] . '?' . $SID . "' METHOD=POST>";
} else { /*link to print the quotation */ echo '<p><img src="' . $rootpath . '/css/' . $theme . '/images/reports.png" TITLE="' . _('Order') . '" ALT="">' . ' ' . '<a href="' . $rootpath . '/PDFQuotation.php?' . SID . '&QuotationNo=' . $OrderNo . '">' . _('Print Quotation') . '</a>'; } echo '<CENTER><p><img src="' . $rootpath . '/css/' . $theme . '/images/sales.png" TITLE="' . _('Order') . '" ALT="">' . ' ' . '<a href="' . $rootpath . '/SelectOrderItems.php?' . SID . '&NewOrder=Yes">' . _('Add Sales Order') . '</a>'; } else { /*its a customer logon so thank them */ prnMsg(_('Thank you for your business'), 'success'); } unset($_SESSION['Items']->LineItems); unset($_SESSION['Items']); include 'includes/footer.inc'; exit; } elseif (isset($OK_to_PROCESS) and $OK_to_PROCESS == 1 && $_SESSION['ExistingOrder'] != 0) { /* update the order header then update the old order line details and insert the new lines */ $DelDate = FormatDateforSQL($_SESSION['Items']->DeliveryDate); $Result = DB_Txn_Begin($db); $HeaderSQL = 'UPDATE salesorders SET debtorno = ' . "'" . $_SESSION['Items']->DebtorNo . "'" . ', branchcode = ' . "'" . $_SESSION['Items']->Branch . "'" . ', customerref = ' . "'" . DB_escape_string($_SESSION['Items']->CustRef) . "'" . ', comments = ' . "'" . DB_escape_string($_SESSION['Items']->Comments) . "'" . ', ordertype = ' . "'" . $_SESSION['Items']->DefaultSalesType . "'" . ', shipvia = ' . $_POST['ShipVia'] . ', deliverydate = ' . "'" . DB_escape_string($_SESSION['Items']->DeliveryDate) . "'" . ', deliverto = ' . "'" . DB_escape_string($_SESSION['Items']->DeliverTo) . "'" . ', deladd1 = ' . "'" . DB_escape_string($_SESSION['Items']->DelAdd1) . "'" . ', deladd2 = ' . "'" . DB_escape_string($_SESSION['Items']->DelAdd2) . "'" . ', deladd3 = ' . "'" . DB_escape_string($_SESSION['Items']->DelAdd3) . "'" . ', deladd4 = ' . "'" . DB_escape_string($_SESSION['Items']->DelAdd4) . "'" . ', deladd5 = ' . "'" . DB_escape_string($_SESSION['Items']->DelAdd5) . "'" . ',