本文整理汇总了PHP中invoice::prepare_date_shift方法的典型用法代码示例。如果您正苦于以下问题:PHP invoice::prepare_date_shift方法的具体用法?PHP invoice::prepare_date_shift怎么用?PHP invoice::prepare_date_shift使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类invoice
的用法示例。
在下文中一共展示了invoice::prepare_date_shift方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: service_invoices_generate
function service_invoices_generate($customerid = NULL)
{
log_debug("inc_services_invoicegen", "Executing service_invoices_generate({$customerid})");
/*
Invoice Report Statistics
*/
$invoice_stats = array();
$invoice_stats["time_start"] = time();
$invoice_stats["total"] = 0;
$invoice_stats["total_failed"] = 0;
/*
Run through all the customers
*/
$sql_customers_obj = new sql_query();
$sql_customers_obj->string = "SELECT id, code_customer, name_customer FROM customers";
if ($customerid) {
$sql_customers_obj->string .= " WHERE id='{$customerid}' LIMIT 1";
}
$sql_customers_obj->execute();
if ($sql_customers_obj->num_rows()) {
$sql_customers_obj->fetch_array();
foreach ($sql_customers_obj->data as $customer_data) {
/*
Fetch all periods belonging to this customer which need to be billed.
*/
$sql_periods_obj = new sql_query();
$sql_periods_obj->string = "SELECT " . "services_customers_periods.id, " . "services_customers_periods.rebill, " . "services_customers_periods.invoiceid, " . "services_customers_periods.invoiceid_usage, " . "services_customers_periods.date_start, " . "services_customers_periods.date_end, " . "services_customers.date_period_first, " . "services_customers.date_period_next, " . "services_customers.date_period_last, " . "services_customers.id as id_service_customer, " . "services_customers.serviceid " . "FROM services_customers_periods " . "LEFT JOIN services_customers ON services_customers.id = services_customers_periods.id_service_customer " . "WHERE " . "services_customers.customerid='" . $customer_data["id"] . "' " . "AND (invoiceid = '0' OR rebill = '1')" . "AND date_billed <= '" . date("Y-m-d") . "'";
$sql_periods_obj->execute();
if ($sql_periods_obj->num_rows()) {
$sql_periods_obj->fetch_array();
/*
BILL CUSTOMER
This customer has at least one service that needs to be billed. We need to create
a new invoice, and then process each service, adding the services to the invoice as
items.
*/
/*
Start Transaction
(one transaction per invoice)
*/
$sql_obj = new sql_query();
$sql_obj->trans_begin();
/*
Create new invoice
*/
$invoice = new invoice();
$invoice->type = "ar";
$invoice->prepare_code_invoice();
$invoice->data["customerid"] = $customer_data["id"];
$invoice->data["employeeid"] = 1;
// set employee to the default internal user
$invoice->prepare_date_shift();
if (!$invoice->action_create()) {
log_write("error", "services_invoicegen", "Unexpected problem occured whilst attempting to create invoice.");
$sql_obj->trans_rollback();
return 0;
}
$invoiceid = $invoice->id;
$invoicecode = $invoice->data["code_invoice"];
unset($invoice);
/*
Create Service Items
We need to create an item for basic service plan - IE: the regular fixed fee, and another item for any
excess usage.
*/
foreach ($sql_periods_obj->data as $period_data) {
/*
TODO:
We should be able to re-bill usage here when needed with a clever cheat - if we load the periods to be billed,
we can then ignore the plan item, and rebill the usage item.
*/
$period_data["mode"] = "standard";
if ($period_data["rebill"]) {
if (!$period_data["invoiceid_usage"] && $period_data["invoiceid"]) {
// the selected period has been billed, but the usage has been flagged for rebilling - we need to *ignore* the base plan
// item and only bill for the usage range.
$period_data["mode"] = "rebill_usage";
}
}
// fetch service details
$obj_service = new service_bundle();
$obj_service->option_type = "customer";
$obj_service->option_type_id = $period_data["id_service_customer"];
if (!$obj_service->verify_id_options()) {
log_write("error", "customers_services", "Unable to verify service ID of " . $period_data["id_service_customer"] . " as being valid.");
return 0;
}
$obj_service->load_data();
$obj_service->load_data_options();
// ratio is used to adjust prices for partial periods
$ratio = 1;
if ($obj_service->data["billing_mode_string"] == "monthend" || $obj_service->data["billing_mode_string"] == "monthadvance" || $obj_service->data["billing_mode_string"] == "monthtelco") {
log_debug("services_invoicegen", "Invoice bills by month date");
/*
Handle monthly billing
//.........这里部分代码省略.........
示例2: invoice
function invoice_generate($invoiceid = NULL)
{
log_write("debug", "inc_customers", "Executing invoice_generate()");
// we don't need to worry about checking if this is the appropiate date, that logic is handled by
// other functions before calling this one.
// initatiate SQL
$sql_obj = new sql_query();
$sql_obj->trans_begin();
// do we need to create an invoice?
if (!$invoiceid) {
$obj_invoice = new invoice();
$obj_invoice->type = "ar";
$obj_invoice->data["customerid"] = $this->id;
$obj_invoice->data["employeeid"] = 1;
$obj_invoice->data["notes"] = "Invoice generated from customer orders page.";
$obj_invoice->prepare_date_shift();
$obj_invoice->action_create();
$invoiceid = $obj_invoice->id;
log_write("debug", "inc_customers", "Creating a new invoice with ID of {$invoiceid}");
} else {
// reuse existing
log_write("debug", "inc_customers", "Using specified invoice {$invoiceid} for orders invoicing");
}
// run through the items and add to the invoice
$obj_orders_sql = new sql_query();
$obj_orders_sql->string = "SELECT * FROM customers_orders WHERE id_customer='" . $this->id . "'";
$obj_orders_sql->execute();
if ($obj_orders_sql->num_rows()) {
$obj_orders_sql->fetch_array();
foreach ($obj_orders_sql->data as $data_order) {
log_write("debug", "inc_customers", "Adding order item " . $data_order["id"] . " to invoice " . $invoiceid . " for customer " . $this->id . "");
// select values desired, certain safety checks
$data_order_tmp = array();
$data_order_tmp["customid"] = $data_order["customid"];
$data_order_tmp["quantity"] = $data_order["quantity"];
$data_order_tmp["units"] = addslashes($data_order["units"]);
$data_order_tmp["amount"] = $data_order["amount"];
$data_order_tmp["price"] = $data_order["price"];
$data_order_tmp["discount"] = $data_order["discount"];
$data_order_tmp["description"] = addslashes($data_order["description"]);
// Add each order as an item on the invoice.
$obj_item = new invoice_items();
$obj_item->id_invoice = $invoiceid;
$obj_item->type_invoice = "ar";
$obj_item->type_item = $data_order["type"];
$obj_item->prepare_data($data_order_tmp);
$obj_item->action_create();
$obj_item->action_update();
// delete the item now that it's been added
$obj_delete_sql = new sql_query();
$obj_delete_sql->string = "DELETE FROM customers_orders WHERE id='" . $data_order["id"] . "' LIMIT 1";
$obj_delete_sql->execute();
unset($obj_delete_sql);
}
// update invoice summary information
$obj_item->action_update_tax();
$obj_item->action_update_total();
$obj_item->action_update_ledger();
unset($obj_item);
}
// end if order items.
// make automated payments - such as customer credit pool or auto-pay credit card functionality
if ($GLOBALS["config"]["ACCOUNTS_AUTOPAY"]) {
log_write("debug", "inc_services_invoicegen", "Autopay Functionality Enabled, running appropiate functions for invoice ID {$invoiceid}");
$obj_autopay = new invoice_autopay();
$obj_autopay->id_invoice = $invoiceid;
$obj_autopay->type_invoice = "ar";
$obj_autopay->autopay();
unset($obj_autopay);
}
// save changes
if (error_check()) {
$sql_obj->trans_rollback();
log_write("error", "inc_customers", "An error occurred whilst attempting to generate an invoice.");
return 0;
} else {
$sql_obj->trans_commit();
log_write("notification", "inc_customers", "Successfully generate invoice " . $obj_invoice->data["code_invoice"] . " for customer " . $this->data["name_customer"] . "");
return $invoiceid;
}
}