function page_execute() { /* Check Configuration */ if (!empty($GLOBALS["config"]["ORDERS_BILL_ENDOFMONTH"])) { /* Check that today is the last day of the month */ //if (time_calculate_monthdate_last( date("Y-m-d") ) == date("Y-m-d")) if (true) { log_write("notification", "cron_orders", "Today is the end of the month, time to process customer orders and convert into invoices."); /* Fetch all the customer ID for customers who currently have order items - no point going through *all* customers, only need to do those with items. */ $sql_customer_obj = new sql_query(); $sql_customer_obj->string = "SELECT id_customer FROM customers_orders GROUP BY id_customer"; $sql_customer_obj->execute(); if ($sql_customer_obj->num_rows()) { $sql_customer_obj->fetch_array(); foreach ($sql_customer_obj->data as $data_customer) { /* Execute order processing for customer */ // generate the invoice $obj_customer = new customer_orders(); $obj_customer->id = $data_customer["id_customer"]; $obj_customer->load_data(); $invoiceid = $obj_customer->invoice_generate(); // send the PDF (if desired) if ($GLOBALS["config"]["ACCOUNTS_INVOICE_AUTOEMAIL"] == 1 || $GLOBALS["config"]["ACCOUNTS_INVOICE_AUTOEMAIL"] == "enabled") { $invoice = new invoice(); $invoice->id = $invoiceid; $invoice->type = "ar"; $invoice->load_data(); $invoice->load_data_export(); if ($invoice->data["amount_total"] > 0) { // generate an email $email = $invoice->generate_email(); // send email $invoice->email_invoice("system", $email["to"], $email["cc"], $email["bcc"], $email["subject"], $email["message"]); // complete log_write("notification", "cron_orders", "Invoice " . $invoice->data["code_invoice"] . " has been emailed to customer (" . $email["to"] . ")"); } else { // complete - invoice is for $0, so don't want to email out log_write("notification", "cron_orders", "Invoice " . $invoice->data["code_invoice"] . " has not been emailed to the customer due to invoice being for \$0."); } unset($invoice); } else { log_write("notification", "cron_orders", "Not emailing invoice " . $invoice->data["code_invoice"] . " to customer due to ACCOUNTS_INVOICE_AUTOEMAIL being disabled"); } } } log_write("notification", "cron_orders", "Completed processing of orders, total of " . $sql_customer_obj->num_rows() . " affected"); } else { log_write("notification", "cron_orders", "Not processing orders, waiting until the end of the month"); } } else { log_write("notification", "cron_orders", "Not processing monthly orders, ORDERS_BILL_ENDOFMONTH option is disabled"); } }
// add new cap override options foreach ($data["data_traffic_caps"] as $cap) { log_write("debug", "process", "Creating data traffic cap override for " . $cap["type_id"] . ""); $sql_obj->string = "INSERT INTO services_options (option_type, option_type_id, option_name, option_value) VALUES ('customer', '" . $obj_customer->id_service_customer . "', 'cap_mode_" . $cap["type_id"] . "', '" . $cap["mode"] . "')"; $sql_obj->execute(); $sql_obj->string = "INSERT INTO services_options (option_type, option_type_id, option_name, option_value) VALUES ('customer', '" . $obj_customer->id_service_customer . "', 'cap_units_included_" . $cap["type_id"] . "', '" . $cap["units_included"] . "')"; $sql_obj->execute(); $sql_obj->string = "INSERT INTO services_options (option_type, option_type_id, option_name, option_value) VALUES ('customer', '" . $obj_customer->id_service_customer . "', 'cap_units_price_" . $cap["type_id"] . "', '" . $cap["units_price"] . "')"; $sql_obj->execute(); } } // do we need to generate a setup fee? if ($data["price_setup"] != "0.00" && $data["active"] == 1) { $obj_customer_order = new customer_orders(); $obj_customer_order->id = $obj_customer->id; $obj_customer_order->load_data(); $obj_customer_order->data_orders["date_ordered"] = date("Y-m-d"); $obj_customer_order->data_orders["type"] = "service"; $obj_customer_order->data_orders["customid"] = $obj_customer->obj_service->id; $obj_customer_order->data_orders["quantity"] = "1"; $obj_customer_order->data_orders["price"] = $data["price_setup"]; $obj_customer_order->data_orders["discount"] = $data["discount_setup"]; $obj_customer_order->data_orders["description"] = "Setup Fee: " . $data["name_service"] . ""; if (!$obj_customer_order->action_update_orders()) { log_write("error", "process", "An unexpected error occured whilst attempting to add an order item to the customer"); } else { log_write("notification", "process", "Added setup fee of " . format_money($obj_customer_order->data_orders["amount"]) . " to customer orders, this will then be billed automatically."); } } } // return to services page