public static function invoice_data(SI_Invoice $invoice)
 {
     $invoice_data = array('title' => $invoice->get_title(), 'id' => $invoice->get_id(), 'invoice_id' => $invoice->get_invoice_id(), 'status' => $invoice->get_status(), 'balance' => $invoice->get_balance(), 'deposit' => $invoice->get_deposit(), 'issue_date' => $invoice->get_issue_date(), 'estimate_id' => $invoice->get_estimate_id(), 'due_date' => $invoice->get_due_date(), 'expiration_date' => $invoice->get_expiration_date(), 'client_id' => $invoice->get_client_id(), 'client_data' => array(), 'po_number' => $invoice->get_po_number(), 'discount' => $invoice->get_discount(), 'tax' => $invoice->get_tax(), 'tax2' => $invoice->get_tax2(), 'currency' => $invoice->get_currency(), 'subtotal' => $invoice->get_subtotal(), 'calculated_total' => $invoice->get_calculated_total(), 'project_id' => $invoice->get_project_id(), 'terms' => $invoice->get_terms(), 'notes' => $invoice->get_notes(), 'line_items' => $invoice->get_line_items(), 'user_id' => $invoice->get_user_id(), 'payment_ids' => $invoice->get_payments());
     if ($invoice->get_client_id()) {
         $client = SI_Client::get_instance($invoice->get_client_id());
         if (is_a($client, 'SI_Client')) {
             $invoice_data['client_data'] = self::client_data($client);
         }
     }
     return $invoice_data;
 }
 public static function payment_request_line_items(SI_Invoice $invoice)
 {
     $i = 0;
     $total = 0;
     // we can add individual item info if there's actually an item cost
     foreach ($invoice->get_line_items() as $position => $data) {
         if ($data['total']) {
             $nvpData['L_NAME' . $i] = html_entity_decode(strip_tags($data['desc']), ENT_QUOTES, 'UTF-8');
             $nvpData['L_AMT' . $i] = si_get_number_format($data['rate'] * $data['qty']);
             $nvpData['L_NUMBER' . $i] = $position;
             $nvpData['L_QTY' . $i] = 1;
             $total += si_get_number_format($data['rate'] * $data['qty']);
             $i++;
         }
         if (floatval($data['total']) !== floatval($data['rate'] * $data['qty'])) {
             $nvpData['L_NAME' . $i] = __('Adjustment: ', 'sprout-invoices') . ' ' . html_entity_decode(strip_tags($data['desc']), ENT_QUOTES, 'UTF-8');
             $nvpData['L_AMT' . $i] = si_get_number_format($data['total'] - $data['rate'] * $data['qty']);
             $nvpData['L_NUMBER' . $i] = $position . '.1';
             $nvpData['L_QTY' . $i] = 1;
             $total += si_get_number_format($data['total'] - $data['rate'] * $data['qty']);
             $i++;
         }
     }
     if ($invoice->get_deposit() && $invoice->get_deposit() < $invoice->get_balance()) {
         $nvpData['L_NAME' . $i] = __('Deposit Adjustment', 'sprout-invoices');
         $nvpData['L_AMT' . $i] = si_get_number_format($invoice->get_deposit() - $total);
         $nvpData['L_NUMBER' . $i] = time() . '_dep';
         $nvpData['L_QTY' . $i] = '1';
         $i++;
     }
     // payment adjustments and discounts are overlooked for deposits.
     if ($invoice->get_deposit()) {
         return $nvpData;
     }
     $payments_total = $invoice->get_payments_total();
     if ($payments_total > 0) {
         $nvpData['L_NAME' . $i] = __('Payment Adjustment', 'sprout-invoices');
         $nvpData['L_AMT' . $i] = -si_get_number_format($payments_total);
         $nvpData['L_NUMBER' . $i] = time() . '_pay';
         $nvpData['L_QTY' . $i] = '1';
         $i++;
     }
     $discount = $invoice->get_discount_total();
     if ($discount > 0.0) {
         $nvpData['L_NAME' . $i] = __('Invoice Discount', 'sprout-invoices');
         $nvpData['L_AMT' . $i] = -si_get_number_format($discount);
         $nvpData['L_NUMBER' . $i] = time() . '_discount';
         $nvpData['L_QTY' . $i] = '1';
         $i++;
     }
     return $nvpData;
 }