public static function export_feed($entry, $form, $settings) { $name_fields = array(); foreach ($form["fields"] as $field) { if (RGFormsModel::get_input_type($field) == "name") { $name_fields[] = $field; } } //Creating client self::log_debug("Checking to see if client exists or a new client needs to be created."); $client = self::get_client($form, $entry, $settings, $name_fields); //if client could not be created, ignore invoice and estimate if (!$client) { self::log_debug("Unable to create client, not creating invoice/estimate."); return; } if ($settings["meta"]["alsocreate"] == "invoice") { $invoice_estimate = new FreshBooks_Invoice(); } else { if ($settings["meta"]["alsocreate"] == "estimate") { $invoice_estimate = new FreshBooks_Estimate(); } else { return; } } //don't create invoice or estimate if (!empty($settings["meta"]["ponumber"])) { $invoice_estimate->poNumber = esc_html(self::get_entry_value($settings["meta"]["ponumber"], $entry, $name_fields)); } $invoice_estimate->discount = $settings["meta"]["discount"]; $invoice_estimate->notes = esc_html($settings["meta"]["notes2"]); $invoice_estimate->terms = esc_html($settings["meta"]["terms"]); $total = 0; $lines = array(); if ($settings["meta"]["is_fixed_cost"] == "2") { //creating line items based on pricing fields $products = GFCommon::get_product_fields($form, $entry, true, false); foreach ($products["products"] as $product) { $product_name = $product["name"]; $price = GFCommon::to_number($product["price"]); if (!empty($product["options"])) { $product_name .= " ("; $options = array(); foreach ($product["options"] as $option) { $price += GFCommon::to_number($option["price"]); $options[] = $option["option_name"]; } $product_name .= implode(", ", $options) . ")"; } $subtotal = floatval($product["quantity"]) * $price; $total += $subtotal; $lines[] = array("name" => esc_html($product["name"]), "description" => esc_html($product_name), "unitCost" => $price, "quantity" => $product["quantity"], "amount" => $subtotal); } //adding shipping if form has shipping if (!empty($products["shipping"]["name"])) { $total += floatval($products["shipping"]["price"]); $lines[] = array("name" => esc_html($products["shipping"]["name"]), "description" => esc_html($products["shipping"]["name"]), "unitCost" => $products["shipping"]["price"], "quantity" => 1, "amount" => $products["shipping"]["price"]); } } else { //creating line items based on fixed cost or mapped fields foreach ($settings["meta"]["items"] as $item) { $cost = $settings["meta"]["is_fixed_cost"] ? $item["cost"] : self::get_entry_value($item["cost"], $entry, $name_fields); $cost = self::get_number($cost); $quantity = $settings["meta"]["is_fixed_cost"] ? $item["quantity"] : self::get_entry_value($item["quantity"], $entry, $name_fields); $amount = $quantity * $cost; $total += $amount; $lines[] = array("name" => $item["item_id"], "description" => esc_html($item["description"]), "unitCost" => $cost, "quantity" => $quantity, "amount" => $amount); } } $invoice_estimate->amount = $total; $invoice_estimate->clientId = $client->clientId; $invoice_estimate->firstName = $client->firstName; $invoice_estimate->lastName = $client->lastName; $invoice_estimate->lines = $lines; $invoice_estimate->organization = $client->organization; $invoice_estimate->pStreet1 = $client->pStreet1; $invoice_estimate->pStreet2 = $client->pStreet2; $invoice_estimate->pCity = $client->pCity; $invoice_estimate->pState = $client->pState; $invoice_estimate->pCode = $client->pCode; $invoice_estimate->pCountry = $client->pCountry; self::log_debug("Creating invoice/estimate."); $invoice_estimate->create(); $lastError = $invoice_estimate->lastError; if (empty($lastError)) { self::log_debug("Invoice/estimate created."); } else { self::log_error("The following error occurred when trying to create an invoice/estimate: {$lastError}"); } }