public function prepare_for_api() { $data = array('id' => $this->get_ID(), 'type' => 'eci_invoice', 'title' => $this->get_data('title', true), 'date' => $this->get_data('date', true), 'contents' => $this->get_meta('contents'), 'service_period' => $this->get_meta('service_period'), 'tax_mode' => $this->get_meta('tax_mode'), 'currency' => $this->get_currency(), 'subtotal' => $this->get_subtotal(), 'total' => $this->get_total(), 'tax' => $this->get_tax(), 'payment' => null, 'customer' => null); $payment_date = $date = $this->get_meta('payment_date', null, true); if ($payment_date) { $data['payment'] = array('date' => $payment_date, 'method' => $this->get_meta('payment_method'), 'currency' => array('original' => $this->get_currency(), 'base' => Util::get_base_currency()), 'subtotal' => array('original' => $this->get_payment_subtotal(), 'base' => $this->get_payment_subtotal(true)), 'total' => array('original' => $this->get_payment_total(), 'base' => $this->get_payment_total(true)), 'tax' => array('original' => $this->get_payment_tax(), 'base' => $this->get_payment_tax(true)), 'fee_amount' => array('original' => $this->get_payment_fee_amount(), 'base' => $this->get_payment_fee_amount(true))); } $customer = $this->get_customer(); if ($customer) { $data['customer'] = $customer->prepare_for_api(); } return $data; }
public function ajax_make_customer_id() { if (!check_ajax_referer('eci_ajax', 'nonce', false)) { wp_send_json_error(__('Missing or invalid AJAX nonce.', 'easy-customer-invoices')); } if (!isset($_REQUEST['first_name'])) { wp_send_json_error(__('Missing first name.', 'easy-customer-invoices')); } if (!isset($_REQUEST['last_name'])) { wp_send_json_error(__('Missing last name.', 'easy-customer-invoices')); } $first_name = $_REQUEST['first_name']; $last_name = $_REQUEST['last_name']; $year = null; if (isset($_REQUEST['year'])) { $year = absint($_REQUEST['year']); } $old_id = null; if (isset($_REQUEST['old_id']) && !empty($_REQUEST['old_id'])) { $old_id = $_REQUEST['old_id']; } wp_send_json_success(Util::make_customer_id($first_name, $last_name, $year, $old_id)); }
public function render($invoice) { $customer = $invoice->get_customer(); $country = $customer->get_country(); $vendor = Vendor::get(); $invoice_date = $invoice->get_data('date', 'Ymd'); $this->AddPage('P'); // Logo $this->Image($vendor->get_company_info('logo_path', $invoice_date, 'medium'), $this->pdf_margin, $this->pdf_margin, 80); // Customer ID (and Customer Tax ID) $this->SetXY($this->pdf_margin + 110, 60); $this->SetCurrentFont('header'); $this->WriteCell($country->get_meta('customer_id_text') . ' ' . $customer->get_data('title'), 'R', 2); if ($customer->get_legal_info('tax_id', $invoice_date)) { $this->WriteCell($country->get_meta('customer_tax_id_text') . ' ' . $customer->get_legal_info('tax_id', $invoice_date), 'R', 2); } // Customer Address $this->SetXY($this->pdf_margin, 60); $this->SetCurrentFont('header_bold'); if (!empty($customer->get_meta('company_name'))) { $this->WriteCell($customer->get_meta('company_name'), 'L', 2); } else { $this->WriteCell($customer->get_meta('first_name') . ' ' . $customer->get_meta('last_name'), 'L', 2); } $this->WriteCell($customer->get_address('line1', $invoice_date), 'L', 2); $this->WriteCell($customer->get_address('line2', $invoice_date), 'L', 2); // Invoice ID $this->SetXY($this->pdf_margin, 85); $this->SetCurrentFont('tall'); $this->WriteCell($country->get_meta('invoice_id_text') . ' ' . $invoice->get_data('title'), 'L', 1); // Invoice Meta $this->SetCurrentFont('default'); $this->WriteCell($country->get_meta('reference_text') . ' ' . Util::get_reference_prefix() . $invoice->get_data('title'), 'L', 1); if (!empty($invoice->get_meta('service_period'))) { $this->WriteCell($country->get_meta('service_period_text') . ' ' . $invoice->get_meta('service_period'), 'L', 1); } $this->WriteCell($country->get_meta('invoice_date_text') . ' ' . $invoice->get_data('date', $country->get_meta('date_format')), 'L', 1); $this->Ln(8); // Invoice Contents $this->WriteCell('', 'L', 0, 1, 'TLB', true); $this->WriteCell($country->get_meta('effort_text'), 'L', 0, 150, 'TB', true); $this->WriteCell($country->get_meta('amount_text'), 'R', 1, 0, 'TRB', true); $this->Cell(0, 4, '', 0, 1, 'L', false); foreach ($invoice->get_meta('contents') as $content) { $this->WriteCell('', 'L', 0, 1); $this->WriteCell($content['effort'], 'L', 0, 150); $this->WriteCell($invoice->format_price($content['amount'], 'chr'), 'R', 1, 0); } // Invoice Results $this->SetCurrentFont('default_bold'); $this->WriteCell($country->get_meta('subtotal_text'), 'R', 0, 151); $this->WriteCell($invoice->format_price($invoice->get_subtotal(), 'chr'), 'R', 1, 0); if ('none' !== $invoice->get_meta('tax_mode') && !$customer->is_reverse_charge()) { $this->WriteCell(sprintf($country->get_meta('tax_text'), Util::get_tax_amount()), 'R', 0, 151); $this->WriteCell($invoice->format_price($invoice->get_tax(), 'chr'), 'R', 1, 0); } $this->SetCurrentFont('tall_bold'); $this->WriteCell($country->get_meta('total_text'), 'R', 0, 151); $this->WriteCell($invoice->format_price($invoice->get_total(), 'chr'), 'R', 1, 0); $this->Ln(8); // Tax Notes $this->SetCurrentFont('default'); if ('none' !== $invoice->get_meta('tax_mode') && $customer->is_reverse_charge()) { $this->WriteMultiCell($country->get_meta('reverse_charge_text') . ' ' . sprintf($country->get_meta('tax_amount_text'), Util::get_tax_amount()), 'L', 1); } elseif ('none' === $invoice->get_meta('tax_mode')) { $this->WriteMultiCell($country->get_meta('no_tax_text'), 'L', 1); } // Payment Notes if ($invoice->get_meta('payment_date')) { $this->WriteMultiCell(sprintf($country->get_meta('paid_text'), $invoice->get_meta('payment_date', null, array('format' => $country->get_meta('date_format'))), $invoice->get_payment_method_name()) . ' ' . $country->get_meta('thank_you_text'), 'L', 1); $this->Ln(); $payment_total = $invoice->get_payment_total(true); $amount_note = ''; if ($country->get_meta('currency') !== Util::get_base_currency()) { $amount_note .= sprintf($country->get_meta('total_base_currency_text'), Util::format_price($payment_total, 'chr')); } $payment_fee = $invoice->get_payment_fee_amount(true); if (0.0 < $payment_fee) { if (!empty($amount_note)) { $amount_note .= ' '; } if ('paypal' === $invoice->get_meta('payment_method')) { $amount_note .= sprintf($country->get_meta('paypal_fee_text'), Util::format_price($payment_fee, 'chr')); $amount_note .= ' ' . sprintf($country->get_meta('revenue_text'), Util::format_price($payment_total - $payment_fee, 'chr')); } elseif ('deposit' === $invoice->get_meta('payment_method')) { $amount_note .= sprintf($country->get_meta('deposit_fee_text'), Util::format_price($payment_fee, 'chr')); $amount_note .= ' ' . sprintf($country->get_meta('revenue_text'), Util::format_price($payment_total - $payment_fee, 'chr')); } } $this->WriteMultiCell($amount_note, 'L', 1); } else { $this->WriteMultiCell($country->get_meta('pay_text') . ' ' . $country->get_meta('thank_you_text'), 'L', 1); } $left_col = array(); if ($vendor_company_name = $vendor->get_company_info('name', $invoice_date)) { $left_col[] = $vendor_company_name; } if ($vendor_address_line1 = trim($vendor->get_address('line1', $invoice_date))) { $left_col[] = $vendor_address_line1; } if ($vendor_address_line2 = trim($vendor->get_address('line2', $invoice_date))) { $left_col[] = $vendor_address_line2; } if ($vendor_phone = $vendor->get_contact('phone', $invoice_date)) { $left_col[] = $country->get_meta('vendor_phone_text') . ' ' . $vendor_phone; } if ($vendor_email = $vendor->get_contact('email', $invoice_date)) { $left_col[] = $country->get_meta('vendor_email_text') . ' ' . $vendor_email; } if ($vendor_website = $vendor->get_contact('website', $invoice_date)) { $left_col[] = $country->get_meta('vendor_website_text') . ' ' . $vendor_website; } $center_col = array(); if ($vendor_bank_name = $vendor->get_bank_account_info('bank_name', $invoice_date)) { $center_col[] = $vendor_bank_name; } if ($vendor_bank_account = $vendor->get_bank_account_info('account_number', $invoice_date)) { $center_col[] = $country->get_meta('vendor_bank_account_text') . ' ' . $vendor_bank_account; } if ($vendor_bank_code = $vendor->get_bank_account_info('bank_code', $invoice_date)) { $center_col[] = $country->get_meta('vendor_bank_code_text') . ' ' . $vendor_bank_code; } if ($vendor_iban = $vendor->get_bank_account_info('iban', $invoice_date)) { $center_col[] = 'IBAN: ' . $vendor_iban; } if ($vendor_bic = $vendor->get_bank_account_info('bic', $invoice_date)) { $center_col[] = 'BIC (SWIFT): ' . $vendor_bic; } $right_col = array(); if ($vendor_name = $vendor->get_name()) { $right_col[] = $country->get_meta('vendor_owner_text') . ' ' . $vendor_name; } if ($vendor_tax_number = $vendor->get_legal_info('tax_number', $invoice_date)) { $right_col[] = $country->get_meta('vendor_tax_number_text') . ' ' . $vendor_tax_number; } if ($vendor_tax_id = $vendor->get_legal_info('tax_id', $invoice_date)) { $right_col[] = $country->get_meta('vendor_tax_id_text') . ' ' . $vendor_tax_id; } if ($vendor_tax_authority = $vendor->get_legal_info('tax_authority', $invoice_date)) { $right_col[] = $vendor_tax_authority; } $this->SetXY($this->pdf_margin, -50); $this->SetCurrentFont('small'); $this->WriteCell('', 'L', 0, 1, 'T'); $this->WriteMultiCell(implode("\n", $left_col), 'L', 1, 60, 'T'); $this->SetXY($this->pdf_margin + 61, -50); $this->WriteMultiCell(implode("\n", $center_col), 'L', 1, 60, 'T'); $this->SetXY($this->pdf_margin + 121, -50); $this->WriteMultiCell(implode("\n", $right_col), 'L', 1, 0, 'T'); }
public function get_legal_info($mode = '', $for_date = null) { $legal = Util::get_relevant($this->get_meta('legal'), $for_date); if (empty($mode)) { return $legal; } if (!isset($legal[$mode])) { return null; } return $legal[$mode]; }
public function get_currency($mode = 'slug') { $currency = Util::get_base_currency(); $country = $this->get_country(); if ($country) { $currency = $country->get_meta('currency'); } if ('slug' === $mode) { return $currency; } $currencies = Util::get_currencies($mode); return $currencies[$currency]; }