first commit

This commit is contained in:
2026-03-05 13:07:40 +01:00
commit 64ba0721ee
25709 changed files with 4691006 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
{
"name": "wpdesk\/flexible-invoices-abstracts",
"description": "Flexible Invoices Abstracts",
"license": "MIT",
"keywords": [
"abstracts",
"interfaces",
"flexible invoices",
"woocommerce documents",
"woocommerce invoices",
"wordpress invoices"
],
"homepage": "https:\/\/gitlab.com\/wpdesk\/flexible-invoices-abstracts",
"minimum-stability": "stable",
"authors": [
{
"name": "piotr.potrebka",
"email": "piotr.potrebka@wpdesk.net"
}
],
"config": {
"sort-packages": true,
"platform": {
"php": "7.0.8"
}
},
"require": {
"php": ">=7.0",
"wpdesk\/wp-persistence": "^3"
},
"require-dev": {
"10up\/wp_mock": "*",
"phpunit\/phpunit": "<7",
"wp-coding-standards\/wpcs": "^0.14.1",
"squizlabs\/php_codesniffer": "^3.0.2",
"wimg\/php-compatibility": "^8"
},
"autoload": {
"psr-4": {
"WPDeskWCInvoicesVendor\\WPDesk\\Library\\FlexibleInvoicesAbstracts\\": "src"
}
},
"scripts": {
"phpcs": "phpcs",
"phpunit-unit": "phpunit --configuration phpunit-unit.xml --coverage-text --colors=never",
"phpunit-unit-fast": "phpunit --configuration phpunit-unit.xml --no-coverage",
"phpunit-integration": "phpunit --configuration phpunit-integration.xml --coverage-text --colors=never",
"phpunit-integration-fast": "phpunit --configuration phpunit-integration.xml --no-coverage"
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Containers;
use WPDeskWCInvoicesVendor\WPDesk\Persistence\PersistentContainer;
/**
* Meta container interface for .
*/
interface MetaContainer extends \WPDeskWCInvoicesVendor\WPDesk\Persistence\PersistentContainer
{
/**
* @param string $name
* @param mixed $default
*
* @return mixed
*/
public function get_fallback($name, $default = null);
}

View File

@@ -0,0 +1,37 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Creator;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\DocumentSetters;
/**
* An interface for creating document creators. It has methods to generate different types of documents.
*/
interface DocumentCreator
{
/**
* @return string
*/
public function get_button_label();
/**
* @return string
*/
public function get_name();
/**
* @return string
*/
public function get_type();
/**
* Create document object.
*
* @param int $document_id
* @param string $source_type Source types: post, postmeta or order.
*/
public function create_document_from_source($document_id, $source_type);
/**
* Get document object.
*
* @return Document
*/
public function get_document();
}

View File

@@ -0,0 +1,34 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Creator;
/**
* Document creator restrictions.
*
* Restrictions are needed mainly for issuing documents through integration with WooCommerce.
*/
interface DocumentCreatorRestrictions
{
/**
* Is it allowed to edit in the WordPress panel.
*
* @return bool
*/
public function is_allowed_for_edit();
/**
* @return bool
*/
public function is_allowed_for_create();
/**
* @return bool
*/
public function is_allowed_for_auto_create();
/**
* @return bool
*/
public function is_allowed_to_send();
/**
* @return bool
*/
public function can_show_document_in_my_account();
}

View File

@@ -0,0 +1,60 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData;
/**
* Define document customer.
*
* @package WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData;
*/
interface Customer
{
/**
* @return int
*/
public function get_id();
/**
* @return string
*/
public function get_name();
/**
* @return string
*/
public function get_street();
/**
* @return string
*/
public function get_street2();
/**
* @return string
*/
public function get_postcode();
/**
* @return string
*/
public function get_city();
/**
* @return string
*/
public function get_vat_number();
/**
* @return string
*/
public function get_country();
/**
* @return string
*/
public function get_phone();
/**
* @return string
*/
public function get_email();
/**
* @return string
*/
public function get_type();
/**
* @return string
*/
public function get_state();
}

View File

@@ -0,0 +1,14 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData;
/**
* Items data.
*/
interface Items
{
/**
* @return array
*/
public function get_items();
}

View File

@@ -0,0 +1,52 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData;
/**
* Define document recipient.
*
* @package WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData;
*/
interface Recipient
{
/**
* @return string
*/
public function get_name();
/**
* @return string
*/
public function get_street();
/**
* @return string
*/
public function get_street2();
/**
* @return string
*/
public function get_postcode();
/**
* @return string
*/
public function get_city();
/**
* @return string
*/
public function get_vat_number();
/**
* @return string
*/
public function get_country();
/**
* @return string
*/
public function get_phone();
/**
* @return string
*/
public function get_email();
/**
* @return string
*/
public function get_state();
}

View File

@@ -0,0 +1,44 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData;
/**
* Define document seller.
*
* @package WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects
*/
interface Seller
{
/**
* @return string
*/
public function get_logo();
/**
* @return string
*/
public function get_name();
/**
* @return string
*/
public function get_address();
/**
* @return string
*/
public function get_vat_number();
/**
* @return string
*/
public function get_bank_name();
/**
* @return string
*/
public function get_bank_account_number();
/**
* @return int
*/
public function get_id();
/**
* @return string
*/
public function get_signature_user();
}

View File

@@ -0,0 +1,16 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentExceptions;
/**
* Throw exception when document already exists.
*.
* @package WPDesk\Library\FlexibleInvoicesAbstracts\DocumentExceptions
*/
class DocumentAlreadyExistsException extends \RuntimeException implements \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentExceptions\DocumentException
{
public function __construct()
{
parent::__construct('Document already exists!');
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentExceptions;
/**
* Main interface for document exceptions.
*
* @package WPDesk\Library\FlexibleInvoicesAbstracts\Exceptions
*/
interface DocumentException
{
}

View File

@@ -0,0 +1,12 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentExceptions;
/**
* Throw exception when the data of the document will not be correct.
*
* @package WPDesk\Library\FlexibleInvoicesAbstracts\Exceptions
*/
class InvalidDocumentDataException extends \RuntimeException implements \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentExceptions\DocumentException
{
}

View File

@@ -0,0 +1,17 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentExceptions;
/**
* Throw an exception when the document type is not recognized.
*
* @package WPDesk\Library\FlexibleInvoicesAbstracts\Exceptions
*/
class UnknownDocumentTypeException extends \RuntimeException implements \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentExceptions\DocumentException
{
public function __construct($document_type)
{
$message = \sprintf('Unknown document type %1$s!', $document_type);
parent::__construct($message);
}
}

View File

@@ -0,0 +1,514 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller;
/**
* @package WPDesk\Library\FlexibleInvoicesAbstracts\Documents
*/
abstract class AbstractDocument implements \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document
{
const DOCUMENT_TYPE = 'invoice';
/**
* @var int
*/
private $number;
/**
* @var string
*/
private $formatted_number;
/**
* @var string
*/
private $currency;
/**
* @var string
*/
private $payment_method_name;
/**
* @var string
*/
private $payment_method = 'topay';
/**
* @var string
*/
private $notes;
/**
* @var string
*/
private $user_lang;
/**
* @var int
*/
private $id = 0;
/**
* @var int
*/
private $order_id = 0;
/**
* @var int
*/
private $corrected_id = 0;
/**
* @var float
*/
private $total_paid;
/**
* @var string
*/
private $payment_status;
/**
* @var array
*/
private $items;
/**
* @var int
*/
private $date_of_sale;
/**
* @var int
*/
private $date_of_issue;
/**
* @var int
*/
private $date_of_pay;
/**
* @var int
*/
private $paid_date;
/**
* @var float
*/
private $total_tax;
/**
* @var float
*/
private $total_net;
/**
* @var float
*/
private $total_gross;
/**
* @var float
*/
private $tax;
/**
* @var Seller
*/
private $seller;
/**
* @var Customer
*/
private $customer;
/**
* @var Recipient
*/
private $recipient;
/**
* @var string
*/
private $customer_filtered_name;
/**
* @var float
*/
private $discount;
/**
* @var string
*/
private $show_order_number;
/**
* @param string $value
*/
public function set_formatted_number($value)
{
$this->formatted_number = $value;
}
/**
* @return string
*/
public function get_formatted_number()
{
return $this->formatted_number;
}
/**
* @param string $value
*/
public function set_currency($value)
{
$this->currency = $value;
}
/**
* @return string
*/
public function get_currency()
{
return $this->currency;
}
/**
* @param string $value
*/
public function set_currency_symbol($value)
{
$this->currency = $value;
}
/**
* @return string
*/
public function get_currency_symbol()
{
return $this->currency;
}
/**
* @param string $value
*/
public function set_payment_method($value)
{
$this->payment_method = $value;
}
/**
* @return string
*/
public function get_payment_method()
{
return $this->payment_method;
}
/**
* @param string $value
*/
public function set_payment_method_name($value)
{
$this->payment_method_name = $value;
}
/**
* @return string
*/
public function get_payment_method_name()
{
return $this->payment_method_name;
}
/**
* @param string $value
*/
public function set_notes($value)
{
$this->notes = $value;
}
/**
* @return string
*/
public function get_notes()
{
return $this->notes;
}
/**
* @param $value
*/
public function set_user_lang($value)
{
$this->user_lang = $value;
}
/**
* @return string
*/
public function get_user_lang()
{
return $this->user_lang;
}
/**
* @param int $id
*/
public function set_id($id)
{
$this->id = $id;
}
/**
* @return int
*/
public function get_id()
{
return $this->id;
}
/**
* @param string $value
*/
public function set_total_paid($value)
{
$this->total_paid = $value;
}
/**
* @return float
*/
public function get_total_paid()
{
return $this->total_paid;
}
/**
* @param string $value
*/
public function set_payment_status($value)
{
$this->payment_status = $value;
}
/**
* @return string
*/
public function get_payment_status()
{
return $this->payment_status;
}
/**
* @param array $items
*/
public function set_items($items)
{
$this->items = $items;
}
/**
* @return array
*/
public function get_items()
{
return $this->items;
}
/**
* @param int $number
*/
public function set_number($number)
{
$this->number = $number;
}
/**
* @return int
*/
public function get_number()
{
return $this->number;
}
/**
* @param int $value
*/
public function set_date_of_sale($value)
{
$this->date_of_sale = $value;
}
/**
* @return int
*/
public function get_date_of_sale()
{
return $this->date_of_sale;
}
/**
* @param int $value
*/
public function set_date_of_issue($value)
{
$this->date_of_issue = $value;
}
/**
* @return int
*/
public function get_date_of_issue()
{
return $this->date_of_issue;
}
/**
* @param int $value
*/
public function set_date_of_pay($value)
{
$this->date_of_pay = $value;
}
/**
* @return int
*/
public function get_date_of_pay()
{
return $this->date_of_pay;
}
/**
* @param int $value
*/
public function set_date_of_paid($value)
{
$this->paid_date = $value;
}
/**
* @return int
*/
public function get_date_of_paid()
{
return $this->paid_date;
}
/**
* @param float $value
*/
public function set_total_tax($value)
{
$this->total_tax = $value;
}
/**
* @return float
*/
public function get_total_tax()
{
return $this->total_tax;
}
/**
* @param float $value
*/
public function set_total_net($value)
{
$this->total_net = $value;
}
/**
* @return float
*/
public function get_total_net()
{
return $this->total_net;
}
/**
* @param float $value
*/
public function set_total_gross($value)
{
$this->total_gross = $value;
}
/**
* @return float
*/
public function get_total_gross()
{
return $this->total_gross;
}
/**
* @param $value
*/
public function set_tax($value)
{
$this->tax = $value;
}
/**
* @return float
*/
public function get_tax()
{
return $this->tax;
}
/**
* @param Seller $seller
*/
public function set_seller(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller $seller)
{
$this->seller = $seller;
}
/**
* @return Seller
*/
public function get_seller()
{
return $this->seller;
}
/**
* @param Customer $customer
*/
public function set_customer(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer $customer)
{
$this->customer = $customer;
}
/**
* @return Customer
*/
public function get_customer()
{
return $this->customer;
}
/**
* @param Recipient $recipient
*/
public function set_recipient(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient $recipient)
{
$this->recipient = $recipient;
}
/**
* @return Recipient
*/
public function get_recipient()
{
return $this->recipient;
}
/**
* @param float $value
*/
public function set_discount($value)
{
$this->discount = $value;
}
/**
* @return float
*/
public function get_discount()
{
return $this->discount;
}
/**
* @param string $customer
*/
public function set_customer_filter_field($customer)
{
$this->customer_filtered_name = $customer;
}
/**
* @return string
*/
public function get_customer_filter_field()
{
return $this->customer_filtered_name;
}
/**
* @param string $value
*/
public function set_show_order_number($value)
{
$this->show_order_number = $value;
}
/**
* @return bool
*/
public function get_show_order_number()
{
return $this->show_order_number;
}
/**
* @param int $id
*/
public function set_order_id($id)
{
$this->order_id = $id;
}
/**
* @return int
*/
public function get_order_id()
{
return $this->order_id;
}
/**
* @param int $id
*/
public function set_corrected_id($id)
{
$this->corrected_id = $id;
}
/**
* @return int
*/
public function get_corrected_id()
{
return $this->corrected_id;
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents;
/**
* Define Document.
*/
interface Document extends \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\DocumentGetters, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\DocumentSetters
{
}

View File

@@ -0,0 +1,134 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller;
/**
* Define document getters.
*/
interface DocumentGetters
{
/**
* @return int
*/
public function get_number();
/**
* @return string
*/
public function get_type();
/**
* @return string
*/
public function get_formatted_number();
/**
* @return string
*/
public function get_currency();
/**
* @return string
*/
public function get_payment_method();
/**
* @return string
*/
public function get_payment_method_name();
/**
* @return string
*/
public function get_notes();
/**
* @return string
*/
public function get_user_lang();
/**
* @return int
*/
public function get_id();
/**
* @return float
*/
public function get_total_paid();
/**
* @return string
*/
public function get_payment_status();
/**
*
* @return array
*/
public function get_items();
/**
* @return int
*/
public function get_date_of_sale();
/**
* @return int
*/
public function get_date_of_issue();
/**
* @return int
*/
public function get_date_of_pay();
/**
* @return int
*/
public function get_date_of_paid();
/**
* @return float
*/
public function get_total_tax();
/**
* @return float
*/
public function get_total_net();
/**
* @return float
*/
public function get_total_gross();
/**
* @return float
*/
public function get_tax();
/**
* @return Seller
*/
public function get_seller();
/**
* @return Customer
*/
public function get_customer();
/**
* @return Recipient
*/
public function get_recipient();
/**
* @return string
*/
public function get_customer_filter_field();
/**
* @return float
*/
public function get_discount();
/**
* @return int
*/
public function get_show_order_number();
/**
* @return int
*/
public function get_order_id();
/**
* @return int
*/
public function get_corrected_id();
/**
* @return int
*/
public function get_is_correction();
/**
* @return string
*/
public function get_currency_symbol();
}

View File

@@ -0,0 +1,130 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller;
/**
* Define document setters.
*/
interface DocumentSetters
{
/**
*
* @param int $number
*/
public function set_number($number);
/**
* @param string $value
*/
public function set_formatted_number($value);
/**
* @param string $value
*/
public function set_currency($value);
/**
* @param string $value
*/
public function set_payment_method($value);
/**
* @param string $value
*/
public function set_payment_method_name($value);
/**
* @param $value
*/
public function set_notes($value);
/**
* @param $value
*/
public function set_user_lang($value);
/**
* @param int $id
*/
public function set_id($id);
/**
* @param float $value
*/
public function set_total_paid($value);
/**
* @param string $value
*/
public function set_payment_status($value);
/**
* @param array $items
*/
public function set_items($items);
/**
* @param int $value
*/
public function set_date_of_sale($value);
/**
* @param int $value
*/
public function set_date_of_issue($value);
/**
* @param int $value
*/
public function set_date_of_pay($value);
/**
* @param int $value
*/
public function set_date_of_paid($value);
/**
* @param float $value
*/
public function set_total_tax($value);
/**
* @param float $value
*/
public function set_total_net($value);
/**
* @param float $value
*/
public function set_total_gross($value);
/**
* @param string $value
*/
public function set_tax($value);
/**
* @param Seller $seller
*/
public function set_seller(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller $seller);
/**
* @param Customer $customer
*/
public function set_customer(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer $customer);
/**
* @param Recipient $recipient
*/
public function set_recipient(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient $recipient);
/**
* @param string $customer_name
*/
public function set_customer_filter_field($customer_name);
/**
* @param float $value
*/
public function set_discount($value);
/**
* @param int $value
*/
public function set_show_order_number($value);
/**
* @param int $id
*/
public function set_order_id($id);
/**
* @param int $id
*/
public function set_corrected_id($id);
/**
* @param bool $is_correction
*/
public function set_is_correction($is_correction);
/**
* @param string $value
*/
public function set_currency_symbol($value);
}

View File

@@ -0,0 +1,174 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer;
/**
* Define document customer.
*
* @package WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects
*/
class DocumentCustomer implements \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer
{
/**
* @var int
*/
private $id;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $street;
/**
* @var string
*/
private $street2;
/**
* @var string
*/
private $postcode;
/**
* @var string
*/
private $city;
/**
* @var string
*/
private $vat_number;
/**
* @var string
*/
private $country;
/**
* @var string
*/
private $phone;
/**
* @var string
*/
private $email;
/**
* @var string
*/
private $type;
/**
* @var string
*/
private $state;
/**
* @param int $id
* @param string $name
* @param string $street
* @param string $postcode
* @param string $city
* @param string $vat_number
* @param string $country
* @param string $phone
* @param string $email
* @param string $type
* @param string $street2
* @param string $state
*/
public function __construct($id, $name, $street, $postcode, $city, $vat_number, $country, $phone, $email, $type = 'individual', $street2 = '', $state = '')
{
$this->id = $id;
$this->name = $name;
$this->street = $street;
$this->postcode = $postcode;
$this->city = $city;
$this->vat_number = $vat_number;
$this->country = $country;
$this->phone = $phone;
$this->email = $email;
$this->type = $type;
$this->street2 = $street2;
$this->state = $state;
}
/**
* @return int
*/
public function get_id()
{
return $this->id;
}
/**
* @return string
*/
public function get_name()
{
return $this->name;
}
/**
* @return string
*/
public function get_street()
{
return $this->street;
}
/**
* @return string
*/
public function get_street2()
{
return $this->street2;
}
/**
* @return string
*/
public function get_postcode()
{
return $this->postcode;
}
/**
* @return string
*/
public function get_city()
{
return $this->city;
}
/**
* @return string
*/
public function get_vat_number()
{
return $this->vat_number;
}
/**
* @return string
*/
public function get_country()
{
return $this->country;
}
/**
* @return string
*/
public function get_phone()
{
return $this->phone;
}
/**
* @return string
*/
public function get_email()
{
return $this->email;
}
/**
* @return string
*/
public function get_type()
{
return $this->type;
}
/**
* @return string
*/
public function get_state()
{
return $this->state;
}
}

View File

@@ -0,0 +1,148 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient;
/**
* Define document recipient.
*
* @package WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects
*/
class DocumentRecipient implements \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient
{
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $street;
/**
* @var string
*/
private $street2;
/**
* @var string
*/
private $postcode;
/**
* @var string
*/
private $city;
/**
* @var string
*/
private $vat_number;
/**
* @var string
*/
private $country;
/**
* @var string
*/
private $phone;
/**
* @var string
*/
private $email;
/**
* @var string
*/
private $state;
/**
* @param string $name
* @param string $street
* @param string $postcode
* @param string $city
* @param string $vat_number
* @param string $country
* @param string $phone
* @param string $email
* @param string $street2
* @param string $state
*/
public function __construct($name, $street, $postcode, $city, $vat_number, $country, $phone, $email, $street2 = '', $state = '')
{
$this->name = $name;
$this->street = $street;
$this->postcode = $postcode;
$this->city = $city;
$this->vat_number = $vat_number;
$this->country = $country;
$this->phone = $phone;
$this->email = $email;
$this->street2 = $street2;
$this->state = $state;
}
/**
* @return string
*/
public function get_name()
{
return $this->name;
}
/**
* @return string
*/
public function get_street()
{
return $this->street;
}
/**
* @return string
*/
public function get_street2()
{
return $this->street2;
}
/**
* @return string
*/
public function get_postcode()
{
return $this->postcode;
}
/**
* @return string
*/
public function get_city()
{
return $this->city;
}
/**
* @return string
*/
public function get_vat_number()
{
return $this->vat_number;
}
/**
* @return string
*/
public function get_country()
{
return $this->country;
}
/**
* @return string
*/
public function get_phone()
{
return $this->phone;
}
/**
* @return string
*/
public function get_email()
{
return $this->email;
}
/**
* @return string
*/
public function get_state()
{
return $this->state;
}
}

View File

@@ -0,0 +1,121 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller;
/**
* Define document seller.
*
* @package WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects
*/
class DocumentSeller implements \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller
{
/**
* @var int
*/
private $id;
/**
* @var string
*/
private $logo;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $address;
/**
* @var string
*/
private $vat_number;
/**
* @var string
*/
private $bank_name;
/**
* @var string
*/
private $bank_account_number;
/**
* @var string
*/
private $signature_user;
/**
* @param string $logo
* @param string $name
* @param string $address
* @param string $vat_number
* @param string $bank_name
* @param int $id
* @param string $signature_user
*/
public function __construct($id, $logo, $name, $address, $vat_number, $bank_name, $bank_account_number, $signature_user)
{
$this->id = $id;
$this->logo = $logo;
$this->name = $name;
$this->address = $address;
$this->vat_number = $vat_number;
$this->bank_name = $bank_name;
$this->bank_account_number = $bank_account_number;
$this->signature_user = $signature_user;
}
/**
* @return string
*/
public function get_logo()
{
return $this->logo;
}
/**
* @return string
*/
public function get_name()
{
return $this->name;
}
/**
* @return string
*/
public function get_address()
{
return $this->address;
}
/**
* @return string
*/
public function get_vat_number()
{
return $this->vat_number;
}
/**
* @return string
*/
public function get_bank_name()
{
return $this->bank_name;
}
/**
* @return string
*/
public function get_bank_account_number()
{
return $this->bank_account_number;
}
/**
* @return int
*/
public function get_id()
{
return $this->id;
}
/**
* @return string
*/
public function get_signature_user()
{
return $this->signature_user;
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Visitors;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document;
/**
* Interface for declaring the classes that will be responsible for saving additional data.
*
*/
interface CanSaveAdditionalData
{
/**
* @param int $document_id
* @param Document $document
*
* @return void
*/
public function save_document($document_id, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document $document);
}

View File

@@ -0,0 +1,106 @@
.post-type-shop_order .wp-list-table .column-fi_actions a.button {
text-indent: 9999px;
margin: 2px 0 2px 4px;
}
.widefat .column-fi_actions a.button {
text-indent: -9999px;
position: relative;
display: inline-block;
margin: 2px 4px 2px 0;
height: 2em !important;
width: 2em;
overflow: hidden;
vertical-align: middle;
padding: 0 !important;
}
.widefat .column-fi_actions a.button::after {
font-family: Dashicons;
speak: never;
font-weight: 400;
font-variant: normal;
text-transform: none;
margin: 0;
text-indent: 0;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
text-align: center;
line-height: 1.85;
margin-top: 2px;
}
.post-type-shop_order .wp-list-table .column-fi_actions a.button {
text-indent: 9999px;
margin: 2px 4px 2px 0;
}
.widefat .column-fi_actions a.view-document {
text-indent: 0 !important;
width: auto;
padding: 0 4px !important;
border: 0;
background: none;
}
.widefat .column-fi_actions a {
background: none;
}
.widefat .column-fi_actions a.generate-document::after {
content: "\f132" !important;
}
.widefat .column-fi_actions a.get-document::after {
content: "\f316" !important;
}
.widefat .column-fi_actions a.send_document::after {
content: "\f465" !important;
}
.fi-download-email-links a.email-not-send {
border-color: red;
color: red;
}
.fi-download-email-links a.email-send {
border-color: green;
color: green;
}
.column-fi_actions {
width: 100px ! important;
}
.fi-download-email-links p {
display: inline-block;
}
/**
* Order meta box
*/
#flexible-invoices-woocommerce .inside p {
margin: 0 0 10px;
}
#flexible-invoices-woocommerce .inside a.button {
margin-right: 5px;
}
.order_notes .fi-note .note_content {
background-color: #eee7cc;
}
.order_notes .fi-note .note_content:after {
border-color: #eee7cc transparent;
}

View File

@@ -0,0 +1,497 @@
/* Settings */
textarea.wide-input, select.wide-input {
width: 100%;
}
/* Metaboxes Custom Actions */
.inspire-panel .metabox-actions {
background-color: #f5f5f5;
border-top: 1px solid #ddd;
clear: both;
padding: 10px;
}
#submitdiv2 #major-publishing-actions {
margin-top: -7px;
}
.inspire-panel .actions .button {
margin: 0 5px 10px 0;
}
/* Publish Metabox Edits */
body.post-type-inspire_invoice #submitdiv h3 {
border-bottom: 0;
}
/**
# Meta boxes styles.
*/
.inspire-panel p:after, .inspire-panel .form-field:after {
clear: both;
content: ".";
display: block;
height: 0;
visibility: hidden;
}
.inspire-panel p, .inspire-panel .form-field, .inspire-panel div.hard-candy {
margin: 9px 0;
padding: 5px 3px;
}
.inspire-panel label {
float: left;
line-height: 24px;
padding: 0;
width: 150px;
}
#options .form-field input {
width: 160px;
}
.inspire-panel input.fluid, .inspire-panel textarea.fluid {
width: calc(100% - 150px);
}
.inspire-panel input.medium, .inspire-panel textarea.medium {
width: 25em;
}
.inspire-panel input.short, .inspire-panel textarea.short {
width: 20%;
}
.inspire-panel input.currency {
width: 100px;
}
.inspire-panel .lonely label {
float: none;
width: auto;
}
.inspire-panel .lonely input {
float: none;
width: auto;
}
.inspire-panel .options-group {
border-bottom: 1px solid #DFDFDF;
border-top: 1px solid #FFFFFF;
}
.inspire-panel .options-group:first-child {
border-top: 0;
}
.inspire-panel .options-group:last-child {
border-bottom: 0;
}
.inspire-panel .options-group:last-child p {
margin-bottom: 0;
}
/**
# End Meta Boxes.
*/
/* Select2 */
.select2-container li {
margin-bottom: 0;
}
.tablenav .select2-container {
float: left;
margin: 1px 6px 1px 1px;
max-width: 200px;
vertical-align: middle;
}
#inspire_invoice_client_select_wrap {
display: inline-block;
margin-right: 10px;
}
#inspire_invoice_client_select_wrap .select2-container {
width: 100%;
}
.select2-container.select2-container--default .select2-selection--single .select2-selection__rendered {
font-size: 14px;
line-height: 26px;
}
/* Table */
table.products {
border-collapse: collapse;
margin-bottom: 12px;
}
table.products input, table.products select, table.products textarea {
font-size: 12px;
}
table.products input {
width: 100%;
}
table.products th, table.products td {
border: 1px solid #e5e5e5;
}
table.products th {
font-size: 12px;
}
table.products th.product-title {
width: 30%;
}
table.products tbody td.discount {
position: relative;
}
table.products tbody td.discount input {
width: 90%;
}
table.products th.product-actions {
width: 20px;
}
table.products a.remove_product {
color: #a00;
display: inline-block;
padding: 3px 0 0;
}
table.products a.remove_product:hover {
color: red;
}
table.products select {
height: 25px;
line-height: 25px;
margin: 0;
}
.wc_error_tip {
color: #fff;
font-size: .8em;
text-align: center;
border-radius: 3px;
padding: .618em 1em;
box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
max-width: 20em;
line-height: 1.8em;
position: absolute;
white-space: normal;
background: #d82223;
margin: 1.5em 1px 0 -1em;
z-index: 9999999;
}
.wc_error_tip:after {
content: "";
display: block;
border: 8px solid #d82223;
border-right-color: transparent;
border-left-color: transparent;
border-top-color: transparent;
position: absolute;
top: -3px;
left: 50%;
margin: -1em 0 0 -3px;
}
.is_duplicated {
color: red;
}
tr.signature-user {
display: none;
}
.inside .main {
padding-bottom: 10px;
}
.remove-disabled {
text-decoration: none;
display: inline-block;
padding: 3px 4px;
box-shadow: none;
outline: 0;
}
.remove-disabled:focus {
box-shadow: none;
outline: 0;
}
.column-wc_actions p p {
display: none;
}
.amount-error {
color: red;
}
@media screen and (max-width: 1280px) {
.fixed .column-client_country,
.fixed .column-netto,
.fixed .column-products,
.fixed .column-taxes,
.fixed .column-sku,
.fixed .column-pay,
.fixed .column-sale,
.fixed .column-order,
.fixed .column-status,
.fixed .column-currency {
display: none ! important;
}
}
@media screen and (max-width: 782px) {
.fixed .column-client_vat_number,
.fixed .column-client_filtered {
display: none ! important;
}
.wp-list-table tr:not(.inline-edit-row):not(.no-items) td:not(.column-primary)::before {
display: none;
}
}
.ocs-meta-box {
display: flex;
}
.ocs-meta-box .ocs-meta-col {
padding: 0 20px;
border-left: 1px solid #EEE;
width: 33.3%;
}
.ocs-meta-box div.ocs-meta-col:first-child {
padding-left: 0;
border-left: 0;
}
.ocs-meta-box div.ocs-meta-col:last-child {
padding-right: 0;
}
.ocs-meta-box .inspire-panel label {
float: none;
width: auto;
display: block;
}
.ocs-meta-box .inspire-panel input, .ocs-meta-box .inspire-panel textarea {
width: 100%;
}
.ocs-meta-box .inspire-panel .form-field {
margin: 0 0 5px;
padding: 0 0;
}
@media screen and (max-width: 1020px) {
.ocs-meta-box {
flex-direction: column;
}
.ocs-meta-box .ocs-meta-col {
border: 0;
padding: 0 0;
width: 100%;
}
.ocs-meta-box div.ocs-meta-col:first-child {
padding: 0 0;
}
table.products {
display: block;
}
table.products thead {
display: none;
}
table.products tbody {
display: block;
border-bottom: 1px solid #EEE;
width: 100%;
}
table.products td {
display: block;
border: 0;
width: 100%;
}
table.products tr {
display: block;
border-bottom: 1px solid #EEE;
width: 100%;
}
}
.flex-container {
display: flex;
}
.flex-col {
flex: 1;
}
.ocs-meta-box .flex-container .flex-col {
padding: 0 5px;
}
.ocs-meta-box .flex-container .flex-col:first-child {
padding-left: 0;
}
.ocs-meta-box .flex-container .flex-col:last-child {
padding-right: 0;
}
.ocs-meta-box button {
border: 0;
background: none;
cursor: pointer;
}
.display .inspire_invoices_owner_name {
font-weight: 700;
}
.display > div {
padding: 2px 0;
}
.invoice-edit-display .display {
display: block;
}
.invoice-edit-display .edit_data {
display: none;
}
.custom-img-container img {
max-width: 120px !important;
max-height: 120px !important;
height: auto !important;
width: auto !important;
}
.inspire_invoices_owner_logo img {
max-width: 120px !important;
max-height: 120px !important;
height: auto !important;
width: auto !important;
}
.fi-download-email-links p {
display: inline-block;
}
body.post-type-inspire_invoice #minor-publishing {
display: none;
}
body.post-type-inspire_invoice #major-publishing-actions {
margin: 0 0;
padding: 0 0;
}
body.post-type-inspire_invoice #delete-action,
body.post-type-inspire_invoice #publishing-action {
padding: 10px;
}
body.post-type-inspire_invoice #major-publishing-actions .fi-download-email-links .button {
margin-right: 5px;
}
.option-form-wrap {
background-color: #FFF;
padding: 10px;
}
.option-form-wrap .form-field:first-child {
margin-top: 0;
}
.fi-download-email-links p {
display: inline-block;
}
.fi-download-email-links a.email-send {
border-color: green;
color: green;
}
.column-fi_actions {
width: 100px ! important;
}
#products .inside {
margin: 0 0 10px 0;
padding: 0 0;
}
#products table {
border: 0;
border-bottom: 1px solid #e5e5e5;
margin-bottom: 10px;
}
#products thead tr th {
border-top: 0;
}
#products thead tr th:first-child {
border-left: 0;
}
#products thead tr th:last-child {
border-right: 0;
}
#products tbody tr td:first-child {
border-left: 0;
}
#products tbody tr td:last-child {
border-right: 0;
}
#products tbody tr:last-child td {
border-bottom: 0;
}
button.add_product {
padding: 3px;
cursor: pointer;
border-radius: 0 !important;
margin-bottom: 10px;
margin-left: 10px !important;
}

View File

@@ -0,0 +1,7 @@
.hide_vat_field {
display: none;
}
#billing_invoice_ask_field .optional {
display: none;
}

View File

@@ -0,0 +1,199 @@
.fix {
clear: both;
visibility: hidden;
height: 0;
width: 0;
font-size: 0;
line-height: 0;
}
/* Globals */
body {
background: #FFF;
color: #000;
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
line-height: 1.5;
margin: 0 auto;
width: 95%;
-webkit-print-color-adjust: exact;
}
#logo {
float: left;
}
.logo {
max-height: 200px;
max-width: 200px;
height: auto;
}
strong {
font-weight: bold;
}
#wrapper {
padding: 0 0;
}
h1 {
font-size: 24px;
font-weight: bold;
padding: 0 0 15px;
}
h2 {
font-size: 14px;
font-weight: bold;
padding: 0 0;
}
h3 {
font-size: 12px;
font-weight: bold;
text-align: left;
}
/* Tables */
table {
border-collapse: collapse;
margin: 0 0 20px;
text-align: left;
width: 100%;
}
table.totals td {
border: 1px solid #FFF;
}
table td, table th {
padding: 4px;
vertical-align: top;
}
table.item-table th {
text-align: center;
}
table.item-table th.item-title {
text-align: left;
}
.table-without-margin {
margin: 0 0;
}
.table-without-margin td {
padding: 0 0;
}
table th {
background-color: #F1F1F1;
font-weight: bold;
}
table td.center {
text-align: center;
}
table td.number {
text-align: right;
}
table tfoot .total td {
background-color: #F1F1F1;
font-weight: bold;
}
table tfoot td.empty {
background-color: #FFF;
border: none;
}
table tfoot td.sum-title {
border: none;
background-color: #FFF;
text-align: right;
}
table tfoot .total td.sum-title {
text-transform: uppercase;
}
#header table td {
border: 0;
padding: 0 0 2px;
}
/* Reports */
#company {
float: right;
}
#company p.name {
font-weight: bold;
}
#signature {
float: right;
padding: 50px 0 0;
text-align: center;
}
/* Invoice */
#companies {
margin: 30px 0 0;
}
#companies .seller {
float: left;
margin: 0 5% 0 0;
width: 45%;
}
#companies .buyer {
float: right;
width: 50%;
}
#companies .title {
font-size: 13px;
font-weight: bold;
}
#signatures {
margin: 75px 0 0;
border-collapse: collapse;
border: 0;
}
#signatures td {
border-collapse: collapse;
border: 0;
text-align: center;
}
#footer {
margin: 10px 0 0;
border-collapse: collapse;
border: 0;
}
#footer td {
border-collapse: collapse;
border: 0;
text-align: left;
line-height: 1.5;
}
.layout3 #footer {
margin: 0 0;
}
.default #footer td {
border-top: 1px solid #EEE;
padding: 10px 0;
}

View File

@@ -0,0 +1,3 @@
@import url("reset.css") print, screen;
@import url("print.css") print, screen;
@import url("front.css") print, screen;

View File

@@ -0,0 +1,23 @@
body {
width: 100% !important;
}
#wrapper {
padding: 0 !important;
}
.print {
display: none !important;
}
table {
border-collapse: collapse !important;
}
.pagebreak {
page-break-before: always;
}
.no-page-break {
page-break-after: avoid;
}

View File

@@ -0,0 +1,7 @@
/*
Copyright (c) 2011, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.com/yui/license.html
version: 2.9.0
*/
html{color:#000;background:#FFF}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,select,p,blockquote,th,td{margin:0;padding:0}table{border-collapse:collapse;border-spacing:0}fieldset,img{border:0}address,button,caption,cite,code,dfn,em,input,optgroup,option,select,strong,textarea,th,var{font:inherit}del,ins{text-decoration:none}li{list-style:none}caption,th{text-align:left}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal}q:before,q:after{content:''}abbr,acronym{border:0;font-variant:normal}sup{vertical-align:baseline}sub{vertical-align:baseline}legend{color:#000}

View File

@@ -0,0 +1,282 @@
/* WooCommerce Admin Table */
table.flexible_invoices_tax {
color: #2ea2cc;
background-color: #FFF;
border-collapse: collapse;
border: 1px solid #DDD;
table-layout: auto;
width: 100%;
}
.flexible_invoices_tax input[type="text"]:focus {
border: 0;
box-shadow: none;
background-color: #f9f9f9;
border-radius: 0;
}
table.flexible_invoices_tax th {
border-right: 1px solid #DFDFDF;
border-bottom: 1px solid #DFDFDF;
padding: 10px 10px;
width: auto;
}
table.flexible_invoices_tax td {
padding: 0;
border-right: 1px solid #DFDFDF;
border-bottom: 1px solid #DFDFDF;
border-top: 0;
background: #fff;
width: auto;
}
table.flexible_invoices_tax td select,
table.flexible_invoices_tax td input[type=text],
table.flexible_invoices_tax td input[type=number] {
width: 100%;
padding: 5px 7px;
margin: 0;
border: 0;
max-width: 100%;
}
table.flexible_invoices_tax td select:focus {
border-color: #FFF;
color: #016087;
box-shadow: 0 0 0 0 #FFF;
}
table.flexible_invoices_tax td.apply_to_shipping,
table.flexible_invoices_tax td.compound {
padding: 5px 7px;
vertical-align: middle
}
table.flexible_invoices_tax td.apply_to_shipping input,
table.flexible_invoices_tax td.compound input {
width: auto;
padding: 0
}
table.flexible_invoices_tax td:last-child {
border-right: 0
}
table.flexible_invoices_tax tr.current td {
background-color: #fefbcc
}
table.flexible_invoices_tax .cost,
table.flexible_invoices_tax .cost input,
table.flexible_invoices_tax .item_cost,
table.flexible_invoices_tax .item_cost input {
text-align: right
}
table.flexible_invoices_tax th.delete,
table.flexible_invoices_tax th.sort {
width: 30px;
padding: 0 4px;
}
table.flexible_invoices_tax td.delete,
table.flexible_invoices_tax td.sort {
padding: 0 4px;
width: 30px;
text-align: center;
}
table.flexible_invoices_tax .ui-sortable:not(.ui-sortable-disabled) td.sort {
cursor: move;
font-size: 15px;
background: #f9f9f9;
text-align: center;
vertical-align: middle;
}
table.flexible_invoices_tax tfoot th {
border-top: 1px solid #DFDFDF;
}
table.flexible_invoices_tax .ui-sortable:not(.ui-sortable-disabled) td.sort:before {
content: "\f333";
font-family: Dashicons;
text-align: center;
line-height: 1;
color: #999;
display: inline-block;
width: 17px;
height: 100%;
font-size: 20px;
}
table.flexible_invoices_tax .delete-item {
text-decoration: none;
}
table.flexible_invoices_tax .ui-sortable:not(.ui-sortable-disabled) td.sort:hover:before {
color: #333;
}
table.flexible_invoices_tax .button {
float: left;
margin-right: 5px
}
table.flexible_invoices_tax .export,
table.flexible_invoices_tax .import {
float: right;
margin-right: 0;
margin-left: 5px
}
table.flexible_invoices_tax span.tips {
padding: 0 3px
}
table.flexible_invoices_tax .pagination {
float: right
}
table.flexible_invoices_tax .pagination .button {
margin-left: 5px;
margin-right: 0
}
table.flexible_invoices_tax .pagination .current {
background: #bbb;
text-shadow: none
}
table.flexible_invoices_tax tfoot th {
padding-left: 20px;
padding-right: 20px
}
table.flexible_invoices_tax tr:last-child td {
border-bottom: 0
}
.flexible_invoices_currency td p,
.flexible_invoices_tax td p {
margin: 0px;
}
.flexible_invoices_currency td p select,
.flexible_invoices_tax td p select {
width: 100%;
}
/**
## Form layout for settings
*/
.inspire-settings {
display: table;
width: 100%;
}
.inspire-settings .inspire-main-content,
.inspire-settings .inspire-sidebar {
display: table-cell;
height: 500px;
margin: 0;
padding: 0;
vertical-align: top;
}
.inspire-settings .inspire-sidebar .inside {
padding: 0 10px;
}
.inspire-settings .inspire-main-content {
min-width: 770px;
}
.inspire-settings .inspire-sidebar {
padding-left: 30px;
width: 280px;
}
/**
## End Form Layout
*/
.form-table td.header-column {
padding-left: 0;
padding-top: 1em;
padding-bottom: 1em;
}
.form-table td.header-column h2, .form-table td.header-column h3, .form-table td.header-column h4 {
margin: 0 0;
padding: 0 0;
}
.form-table td.forminp p.description,
.form-table td.header-column p {
font-size: 13px;
}
.inspire_invoice_page_flexible-invoices-reports-settings .form-table td,
.inspire_invoice_page_download .form-table td {
padding: 10px 0;
}
.js-subsubsub-wrapper {
margin-bottom: 20px;
}
.js-subsubsub-wrapper li:last-child span {
display: none;
}
span.pro-version {
display: inline-block;
padding-left: 10px;
color: dodgerblue;
}
table.pro-version .remove-disabled {
display: none;
}
form.nowoo .subsubsub {
display: none;
}
h4 .pro-version {
padding-left: 0;
}
.disable-for-pro {
color: #BBB;
}
.remove-disabled {
text-decoration: none;
display: inline-block;
padding: 3px 4px;
box-shadow: none;
outline: 0;
}
.remove-disabled:focus {
box-shadow: none;
outline: 0;
}
.form-table td p.submit {
padding: 0;
margin: 0;
}
.invoice-subsubsub a {
font-size: 15px;
}
.pro-version-wrap {
color: #555555;
}

View File

@@ -0,0 +1,111 @@
.form-table td.header-column {
padding-left: 0;
padding-top: 1em;
padding-bottom: 1em;
}
.form-table td.header-column h2, .form-table td.header-column h3, .form-table td.header-column h4 {
margin: 0 0;
padding: 0 0;
}
.select-images label {
display: inline-block;
text-align: center;
padding: 0 10px;
position: relative;
}
.select-images label input {
top: -2000px;
position: fixed;
}
.select-images label span {
display: block;
text-align: center;
}
.select-images label.checked-image img {
border: 2px solid orange;
}
.select-images label img {
border: 2px solid transparent;
}
.select-images label a.zoom {
position: absolute;
right: 14px;
top: 4px;
background: crimson;
border-radius: 3px;
border: 0;
color: #FFF;
padding: 4px;
display: none;
}
.select-images label a.zoom {
text-decoration: none;
}
.select-images label:hover a.zoom {
display: inline-block;
}
.select-images label.disabled{
-webkit-filter: grayscale(100%); /* Safari 6.0 - 9.0 */
filter: grayscale(100%);
}
.select-images label.disabled.checked-image img {
border: 2px solid rgb(231, 231, 231);
}
.large-view {
position: fixed;
top: 150px;
left: 50%;
margin-top: -100px;
margin-left: -250px;
background: #FFFFFF;
padding: 20px;
max-width: 600px;
width: 600px;
height: auto;
z-index: 99999;
box-shadow: #999999 0 0 10px;
border-radius: 3px;
}
.large-view img {
max-width: 600px;
}
.large-view .close {
position: absolute;
top: 4px;
right: 4px;
background: crimson;
border-radius: 3px;
border: 0;
color: #FFF;
padding: 4px;
display: inline-block;
}
.reset-pdf-template {
cursor: pointer;
padding: 0 0;
}
.disabled-checked-image .label.checked-image img,
.disabled-checked-image .label.checked-image img {
border: 2px solid transparent !important;
}
.select-images label {
z-index: 9999!important;
}

View File

@@ -0,0 +1,385 @@
var fi_session = {
'search_user_data': [],
};
jQuery.noConflict();
( function ( $ ) {
FiwG = {
onChangeState: function () {
$( 'body.post-type-inspire_invoice' ).on( 'keyup keypress', 'select, input', function ( e ) {
$( 'body' ).addClass( 'invoice-changed' );
} );
},
editMetaBoxData: function () {
jQuery( 'button.edit-ocs-data' ).click( function ( e ) {
let display = jQuery( this ).closest( '.ocs-meta-col' ).find( '.display' )
let edit = jQuery( this ).closest( '.ocs-meta-col' ).find( '.edit_data' )
if ( display.is( ':visible' ) ) {
display.hide();
edit.show();
} else {
display.show();
edit.hide();
}
} );
},
userDataAndPayment: function () {
$( 'body.post-type-inspire_invoice .get_user_data' ).click( function ( e ) {
if ( fi_session.search_user_data.length !== 0 ) {
console.log( fi_session.search_user_data );
for ( i in fi_session.search_user_data ) {
let field = $( '[name=client\\[' + i + '\\]]' );
let name = field.attr( 'name' );
if ( i === 'country' ) {
console.log( fi_session.search_user_data[ i ] );
field.val( fi_session.search_user_data[ i ] ).change();
} else {
field.val( fi_session.search_user_data[ i ] );
}
}
}
return false;
} );
$( '#payment' ).on( 'change', '#inspire_invoices_payment_status', function ( e ) {
let field_to_change = $( '#inspire_invoices_total_paid' );
if ( $( this ).val() === 'paid' ) {
field_to_change.val( $( '#inspire_invoices_total_price' ).val() );
} else {
field_to_change.val( 0.0 );
}
} );
var show_signatures = $( '#inspire_invoices_show_signatures' );
var signature_row = $( 'tr.signature-user' );
if ( show_signatures.length ) {
if ( show_signatures.prop( 'checked' ) ) {
signature_row.show();
}
show_signatures.click( function () {
if ( $( this ).prop( 'checked' ) ) {
signature_row.show();
} else {
signature_row.hide();
}
} );
}
},
updateOCSFields: function () {
let wrap_handler = jQuery( '.ocs-meta-box .edit_data' );
let display_handler = jQuery( '.ocs-meta-box .display' );
jQuery( 'input,select', wrap_handler ).on( 'keyup change', function () {
let id = jQuery( this ).attr( 'id' );
let value = jQuery( this ).val();
if ( jQuery( this ).is( 'select' ) ) {
value = jQuery( this ).find( 'option:selected' ).text();
}
jQuery( '.' + id + ' span', display_handler ).html( value );
} )
},
imagePicker: function () {
var frame,
metaBox = $( '#image_picker' ),
addImgLink = metaBox.find( '.upload-custom-img' ),
delImgLink = metaBox.find( '.delete-custom-img' ),
imgContainer = metaBox.find( '.custom-img-container' ),
imgIdInput = metaBox.find( '.image-field-value' ),
displayHandler = jQuery( '.ocs-meta-box .display' );
addImgLink.on( 'click', function ( event ) {
event.preventDefault();
if ( frame ) {
frame.open();
return;
}
frame = wp.media( {
library: {
type: [ 'image' ]
},
multiple: false
} );
frame.on( 'select', function () {
var attachment = frame.state().get( 'selection' ).first().toJSON();
let image = '<img src="' + attachment.url + '" alt="" width="100" />';
imgContainer.append( image );
jQuery( '.inspire_invoices_owner_logo', displayHandler ).html( image );
imgIdInput.val( attachment.url );
addImgLink.addClass( 'hidden' );
delImgLink.removeClass( 'hidden' );
} );
frame.open();
} );
delImgLink.on( 'click', function () {
imgContainer.html( '' );
addImgLink.removeClass( 'hidden' );
delImgLink.addClass( 'hidden' );
imgIdInput.val( '' );
return false;
} );
},
selectI18n: function () {
return {
placeholder: inspire_invoice_params.select2_placeholder,
language: {
inputTooShort: function ( args ) {
var remainingChars = args.minimum - args.input.length;
return inspire_invoice_params.select2_min_chars.replace( '%', remainingChars );
},
loadingMore: function () {
return inspire_invoice_params.select2_loading_more;
},
noResults: function () {
return inspire_invoice_params.select2_no_results;
},
searching: function () {
return inspire_invoice_params.select2_searching;
},
errorLoading: function () {
return inspire_invoice_params.select2_error_loading;
},
},
};
},
userSelect2: function () {
let _this = this;
var roles_input = jQuery( '#inspire_invoices_roles' );
if ( roles_input.length ) {
roles_input.select2( {
width: '400px',
..._this.selectI18n(),
} );
}
var _invoice_users_select = $( '#inspire_invoice_client_select' );
if ( _invoice_users_select.length ) {
options = {
width: '200px',
ajax: {
url: ajaxurl,
dataType: 'json',
delay: 300,
type: 'POST',
data: function ( params ) {
return {
action: 'woocommerce-invoice-user-select',
name: params.term,
security: inspire_invoice_params.ajax_nonce
};
},
processResults: function ( data ) {
return {
results: data.items
};
},
cache: true,
},
minimumInputLength: 3,
..._this.selectI18n(),
placeholder: inspire_invoice_params.search_customer
};
if ( $.fn.selectWoo ) {
_invoice_users_select.selectWoo( options ).on( 'select2:select', function ( event ) {
// This is how I got ahold of the data
fi_session.search_user_data = event.params.data.details;
} );
} else if ( $.fn.select2 ) {
_invoice_users_select.select2( options ).on( 'select2:select', function ( event ) {
fi_session.search_user_data = event.params.data.details;
} );
}
}
},
countrySelect2: function () {
var _this = this;
var $state_select = $( '#inspire_invoices_client_state' );
if ( $state_select.length ) {
$state_select.select2( {
..._this.selectI18n(),
width: '100%'
} );
}
var country_select = $( '.country-select2' );
if ( country_select.length ) {
let $country_value = country_select.val();
if ( $country_value ) {
_this.setCountryState( $state_select, $country_value );
}
country_select.select2( {
..._this.selectI18n(),
width: '100%'
} ).on( 'select2:select', function ( event ) {
let country = event.params.data.id;
_this.setCountryState( $state_select, country );
} );
}
},
setCountryState: function ( $state_select, country ) {
if ( $state_select.length && country ) {
let state_value = $state_select.val();
let has_values = false;
let countries_states = inspire_invoice_params.states
let output = '<option value="">----</option>';
let selected = '';
for ( c in countries_states ) {
let country_states = countries_states[ c ];
if ( country === c ) {
if ( country_states ) {
has_values = true;
for ( s in country_states ) {
if ( state_value === s ) {
selected = 'selected="selected"';
} else {
selected = '';
}
output += '<option ' + selected + ' value="' + s + '">' + country_states[ s ] + '</option>';
}
}
}
}
$state_select.html( output );
$state_select.trigger( "change" );
let selected_value = $state_select.attr( 'data-value' );
if ( has_values ) {
$state_select.closest( '.form-field' ).show();
$state_select.val( selected_value );
$( '.inspire_invoices_client_state' ).show();
if ( countries_states && selected_value ) {
$( '.inspire_invoices_client_state span' ).html( countries_states[ country ][ selected_value ] );
} else {
$( '.inspire_invoices_client_state span' ).html( '---' );
}
} else {
$state_select.closest( '.form-field' ).hide();
$( '.inspire_invoices_client_state' ).hide();
}
}
},
generateDocument: function () {
$( '.column-fi_actions .generate-document' ).click( function () {
let $this = $( this );
let tr = $this.closest( 'tr' );
let td = $this.closest( 'td' );
if ( $this.hasClass( 'disabled' ) ) {
return false;
} else {
let generate_buttons = $( 'a.generate-document' );
generate_buttons.addClass( 'disabled' );
$this.parent().html( '<span style="float: none; margin: 4px 4px; height: 2em !important; width: 2em;" class="spinner is-active"></span>' );
$.post( $this.attr( 'href' ), '', function ( result ) {
if ( result.success ) {
tr.find( '.fi_documents' ).html( result.data.html );
td.html( result.data.email_url );
generate_buttons.removeClass( 'disabled' );
} else {
alert( result.data.result );
}
} );
}
return false;
} );
$( '.postbox .generate-document' ).click( function () {
let $this = $( this );
let _parent = $this.closest( 'p' );
_parent.html( '<span style="float: none; margin: 4px 0;" class="spinner is-active"></span>' );
$.post( $this.attr( 'href' ), '', function ( result ) {
if ( result.success ) {
_parent.before( result.data.html );
_parent.before( result.data.email_url );
_parent.hide();
} else {
alert( result.data.html );
}
} );
return false;
} );
},
sendEmail: function () {
$( document ).on( 'click', '.send_document', function () {
var $this = $( this );
function doAction() {
$.post( $this.attr( 'href' ), '', function ( result ) {
if ( result.success ) {
alert( inspire_invoice_params.message_invoice_sent + result.data.email );
$this.addClass( 'email-send' );
} else {
alert( result.data.msg );
}
}
);
}
let email_status = $this.data( 'status' );
if ( email_status === 'yes' ) {
if ( confirm( inspire_invoice_params.email_was_sent ) === true ) {
doAction();
}
} else if ( $( 'body' ).hasClass( 'invoice-changed' ) ) {
if ( confirm( inspire_invoice_params.message_not_saved_changes ) === true ) {
doAction();
}
} else {
doAction();
}
return false;
} );
},
getDocument: function () {
$( 'body.post-type-inspire_invoice .get-document' ).click( function ( e ) {
e.preventDefault();
var $this = $( this );
function doAction() {
var url = $this.attr( 'href' );
window.open( url, '_blank' );
}
if ( $( 'body' ).hasClass( 'invoice-changed' ) ) {
if ( confirm( inspire_invoice_params.message_confirm ) === true ) {
doAction();
}
} else {
doAction();
}
} );
},
};
FiwG.onChangeState();
FiwG.editMetaBoxData();
FiwG.userDataAndPayment();
FiwG.updateOCSFields();
FiwG.imagePicker();
FiwG.userSelect2();
FiwG.countrySelect2();
FiwG.generateDocument();
FiwG.sendEmail();
FiwG.getDocument();
} )( jQuery );

View File

@@ -0,0 +1,20 @@
var invoice_ask_field = jQuery( '#billing_invoice_ask' );
var vat_number_field = jQuery( '#billing_vat_number' );
if ( invoice_ask_field.length ) {
invoice_ask_field.change( function () {
console.log( invoice_ask_field );
var vat_number_p = vat_number_field.closest( 'p' );
if ( invoice_ask_field.is( ':checked' ) ) {
vat_number_p.show();
} else {
vat_number_p.hide();
vat_number_field.val( '' );
}
} );
jQuery( document ).ready( function () {
if ( vat_number_field.val().length > 2 ) {
invoice_ask_field.prop( 'checked', true );
}
invoice_ask_field.trigger( 'change' );
} )
}

View File

@@ -0,0 +1,21 @@
/*
* TipTip
* Copyright 2010 Drew Wilson
* www.drewwilson.com
* code.drewwilson.com/entry/tiptip-jquery-plugin
*
* Version 1.3 - Updated: Mar. 23, 2010
*
* This Plug-In will create a custom tooltip to replace the default
* browser tooltip. It is extremely lightweight and very smart in
* that it detects the edges of the browser window and will make sure
* the tooltip stays within the current window size. As a result the
* tooltip will adjust itself to be displayed above, below, to the left
* or to the right depending on what is necessary to stay within the
* browser window. It is completely customizable as well via CSS.
*
* This TipTip jQuery plug-in is dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function($){$.fn.tipTip=function(options){var defaults={activation:"hover",keepAlive:false,maxWidth:"200px",edgeOffset:3,defaultPosition:"bottom",delay:400,fadeIn:200,fadeOut:200,attribute:"title",content:false,enter:function(){},exit:function(){}};var opts=$.extend(defaults,options);if($("#tiptip_holder").length<=0){var tiptip_holder=$('<div id="tiptip_holder" style="max-width:'+opts.maxWidth+';"></div>');var tiptip_content=$('<div id="tiptip_content"></div>');var tiptip_arrow=$('<div id="tiptip_arrow"></div>');$("body").append(tiptip_holder.html(tiptip_content).prepend(tiptip_arrow.html('<div id="tiptip_arrow_inner"></div>')))}else{var tiptip_holder=$("#tiptip_holder");var tiptip_content=$("#tiptip_content");var tiptip_arrow=$("#tiptip_arrow")}return this.each(function(){var org_elem=$(this);if(opts.content){var org_title=opts.content}else{var org_title=org_elem.attr(opts.attribute)}if(org_title!=""){if(!opts.content){org_elem.removeAttr(opts.attribute)}var timeout=false;if(opts.activation=="hover"){org_elem.hover(function(){active_tiptip()},function(){if(!opts.keepAlive){deactive_tiptip()}});if(opts.keepAlive){tiptip_holder.hover(function(){},function(){deactive_tiptip()})}}else if(opts.activation=="focus"){org_elem.focus(function(){active_tiptip()}).blur(function(){deactive_tiptip()})}else if(opts.activation=="click"){org_elem.click(function(){active_tiptip();return false}).hover(function(){},function(){if(!opts.keepAlive){deactive_tiptip()}});if(opts.keepAlive){tiptip_holder.hover(function(){},function(){deactive_tiptip()})}}function active_tiptip(){opts.enter.call(this);tiptip_content.html(org_title);tiptip_holder.hide().removeAttr("class").css("margin","0");tiptip_arrow.removeAttr("style");var top=parseInt(org_elem.offset()['top']);var left=parseInt(org_elem.offset()['left']);var org_width=parseInt(org_elem.outerWidth());var org_height=parseInt(org_elem.outerHeight());var tip_w=tiptip_holder.outerWidth();var tip_h=tiptip_holder.outerHeight();var w_compare=Math.round((org_width-tip_w)/2);var h_compare=Math.round((org_height-tip_h)/2);var marg_left=Math.round(left+w_compare);var marg_top=Math.round(top+org_height+opts.edgeOffset);var t_class="";var arrow_top="";var arrow_left=Math.round(tip_w-12)/2;if(opts.defaultPosition=="bottom"){t_class="_bottom"}else if(opts.defaultPosition=="top"){t_class="_top"}else if(opts.defaultPosition=="left"){t_class="_left"}else if(opts.defaultPosition=="right"){t_class="_right"}var right_compare=(w_compare+left)<parseInt($(window).scrollLeft());var left_compare=(tip_w+left)>parseInt($(window).width());if((right_compare&&w_compare<0)||(t_class=="_right"&&!left_compare)||(t_class=="_left"&&left<(tip_w+opts.edgeOffset+5))){t_class="_right";arrow_top=Math.round(tip_h-13)/2;arrow_left=-12;marg_left=Math.round(left+org_width+opts.edgeOffset);marg_top=Math.round(top+h_compare)}else if((left_compare&&w_compare<0)||(t_class=="_left"&&!right_compare)){t_class="_left";arrow_top=Math.round(tip_h-13)/2;arrow_left=Math.round(tip_w);marg_left=Math.round(left-(tip_w+opts.edgeOffset+5));marg_top=Math.round(top+h_compare)}var top_compare=(top+org_height+opts.edgeOffset+tip_h+8)>parseInt($(window).height()+$(window).scrollTop());var bottom_compare=((top+org_height)-(opts.edgeOffset+tip_h+8))<0;if(top_compare||(t_class=="_bottom"&&top_compare)||(t_class=="_top"&&!bottom_compare)){if(t_class=="_top"||t_class=="_bottom"){t_class="_top"}else{t_class=t_class+"_top"}arrow_top=tip_h;marg_top=Math.round(top-(tip_h+5+opts.edgeOffset))}else if(bottom_compare|(t_class=="_top"&&bottom_compare)||(t_class=="_bottom"&&!top_compare)){if(t_class=="_top"||t_class=="_bottom"){t_class="_bottom"}else{t_class=t_class+"_bottom"}arrow_top=-12;marg_top=Math.round(top+org_height+opts.edgeOffset)}if(t_class=="_right_top"||t_class=="_left_top"){marg_top=marg_top+5}else if(t_class=="_right_bottom"||t_class=="_left_bottom"){marg_top=marg_top-5}if(t_class=="_left_top"||t_class=="_left_bottom"){marg_left=marg_left+5}tiptip_arrow.css({"margin-left":arrow_left+"px","margin-top":arrow_top+"px"});tiptip_holder.css({"margin-left":marg_left+"px","margin-top":marg_top+"px"}).attr("class","tip"+t_class);if(timeout){clearTimeout(timeout)}timeout=setTimeout(function(){tiptip_holder.stop(true,true).fadeIn(opts.fadeIn)},opts.delay)}function deactive_tiptip(){opts.exit.call(this);if(timeout){clearTimeout(timeout)}tiptip_holder.fadeOut(opts.fadeOut)}}})}})(jQuery);

View File

@@ -0,0 +1,126 @@
(function ($) {
"use strict";
var FlexibleInvoiceAdmin = {
editProductName: function () {
jQuery('.products_container').on('click', '.edit_item_name', function () {
let is_input = $(this).closest('td').find('.item_input_name');
let select_input = $(this).closest('td').find('select');
let select = $(this).closest('td').find('.product_select_name');
let select_products = $(this).closest('td').find('.select-product');
if (!is_input.length) {
select_input.attr( 'name', 'product_name' );
select_products.hide();
let value = select_input.find("option:first-child").val();
select.append('<input type="text" class="item_input_name" name="product[name][]" value="' + value + '" /> ');
select.find( '.item_input_name').focus();
} else {
select_input.attr( 'name', 'product[name][]' );
select_products.show();
is_input.remove();
}
return false;
});
},
/**
* Search products.
*/
initProductsSelect2: function (elem) {
var self = this;
var select2_translations = {
placeholder: inspire_invoice_params.select2_placeholder,
language: {
inputTooShort: function (args) {
var remainingChars = args.minimum - args.input.length;
return inspire_invoice_params.select2_min_chars.replace('%', remainingChars);
},
loadingMore: function () {
return inspire_invoice_params.select2_loading_more;
},
noResults: function () {
return inspire_invoice_params.select2_no_results;
},
searching: function () {
return inspire_invoice_params.select2_searching;
},
errorLoading: function () {
return inspire_invoice_params.select2_error_loading;
},
},
};
if (elem.length) {
elem.select2({
ajax: {
url: ajaxurl,
dataType: 'json',
delay: 300,
type: 'POST',
data: function (params) {
return {
action: 'fiw_find_products',
name: params.term,
security: fiw_localize.nonce
};
},
processResults: function (data) {
return {
results: data.items
};
},
cache: true,
},
minimumInputLength: 3,
...select2_translations,
width: '100%',
});
}
elem.on('select2:select', function (e) {
var data = e.params.data;
var productHandle = $(this).parents('.product_row');
productHandle[0].querySelector("input[name='product[net_price][]']").value = data.net_price;
productHandle[0].querySelector("input[name='product[net_price_sum][]']").value = data.net_price;
productHandle[0].querySelector("input[name='product[vat_sum][]']").value = data.tax_amount;
productHandle[0].querySelector("input[name='product[sku][]']").value = data.sku;
productHandle[0].querySelector("input[name='product[quantity][]']").value = 1;
productHandle[0].querySelector("input[name='product[unit][]']").value = '';
productHandle[0].querySelector("input[name='product[total_price][]']").value = data.gross_price;
let option_value = self.get_option_value(productHandle[0].querySelector("select[name='product[vat_type][]']").options, data.tax_rate);
productHandle[0].querySelector("select[name='product[vat_type][]']").value = option_value;
});
},
get_option_value: function ( options, value ) {
let result = options[0].value;
for (var i = 0; i < options.length; i++) {
if (value == options[i].value.split( '|' )[ 1 ]) {
return options[i].value;
}
}
return result;
},
}
jQuery('#products').on('click', '.add_product', function (e) {
let lastelem = jQuery('.products_container').find('.refresh_product').last();
lastelem.next().remove();
FlexibleInvoiceAdmin.initProductsSelect2(lastelem);
})
if (jQuery('.products_metabox').length) {
jQuery('.refresh_product').each(function () {
FlexibleInvoiceAdmin.initProductsSelect2($(this));
});
}
FlexibleInvoiceAdmin.editProductName();
})(jQuery);

View File

@@ -0,0 +1,150 @@
jQuery.noConflict();
( function ( $ ) {
function parseFloatLocal( num ) {
return parseFloat( num.replace( ",", "." ) );
}
function moneyMultiply( a, b ) {
if ( a === 0 || b === 0 ) {
return 0;
}
var log_10 = function ( c ) {
return Math.log( c ) / Math.log( 10 );
},
ten_e = function ( d ) {
return Math.pow( 10, d );
},
pow_10 = -Math.floor( Math.min( log_10( a ), log_10( b ) ) ) + 1;
var mul = ( ( a * ten_e( pow_10 ) ) * ( b * ten_e( pow_10 ) ) ) / ten_e( pow_10 * 2 );
if ( isNaN( mul ) || ! isFinite( mul ) ) {
return 0;
} else {
return mul;
}
}
function bruttoToNetto( brutto, vat, qty ) {
if ( brutto === 0 || vat === 0 || qty === 0 || isNaN(brutto) || isNaN(vat) || isNaN(qty) ) {
return 0;
}
let netto = brutto / (1 + (vat / 100));
return netto / qty;
}
function getVatRateFromField(field) {
return parseFloat( field.val().split( '|' )[ 1 ], 10 );
}
function invoiceRefreshProductNetPriceSum( $productHandle ) {
$( '[name=product\\[net_price_sum\\]\\[\\]]', $productHandle ).val(
moneyMultiply(
parseFloatLocal( $( '[name=product\\[net_price\\]\\[\\]]', $productHandle ).val() ),
parseFloatLocal( $( '[name=product\\[quantity\\]\\[\\]]', $productHandle ).val() )
).toFixed( 2 )
);
invoiceRefreshProductVatRate( $productHandle );
}
function invoiceRefreshProductBruttoPriceSum( $productHandle ) {
$('[name=product\\[net_price\\]\\[\\]]', $productHandle).val(
bruttoToNetto(
parseFloatLocal($('[name=product\\[total_price\\]\\[\\]]', $productHandle).val()),
getVatRateFromField($('[name=product\\[vat_type\\]\\[\\]]', $productHandle)),
parseFloatLocal( $( '[name=product\\[quantity\\]\\[\\]]', $productHandle ).val() )
).toFixed( 2 )
);
$('[name=product\\[net_price\\]\\[\\]]', $productHandle).trigger('change');
}
function invoiceRefreshProductVatRate($productHandle) {
var vatType = getVatRateFromField($('[name=product\\[vat_type\\]\\[\\]]', $productHandle));
let discount = 0;
if ($('[name=product\\[discount\\]\\[\\]]', $productHandle).length > 0) {
discount = parseFloatLocal($('[name=product\\[discount\\]\\[\\]]', $productHandle).val());
}
let net_price_sum = parseFloatLocal($('[name=product\\[net_price_sum\\]\\[\\]]', $productHandle).val());
if (discount > 0) {
net_price_sum = net_price_sum - discount;
$('[name=product\\[net_price_sum\\]\\[\\]]', $productHandle).val(net_price_sum.toFixed(2));
}
let vat_sum = moneyMultiply(
net_price_sum,
(isNaN(vatType) ? 0 : vatType) / 100
);
$('[name=product\\[vat_sum\\]\\[\\]]', $productHandle).val(vat_sum.toFixed(2));
invoiceRefreshProductTotal( $productHandle );
}
function invoiceRefreshProductTotal( $productHandle ) {
var total = parseFloatLocal( $( '[name=product\\[vat_sum\\]\\[\\]]', $productHandle ).val() ) +
parseFloatLocal($('[name=product\\[net_price_sum\\]\\[\\]]', $productHandle).val());
$( '[name=product\\[total_price\\]\\[\\]]', $productHandle ).val(
(
( isNaN( total ) ? 0 : total ).toFixed( 2 )
)
);
invoiceRefreshTotal();
}
function invoiceRefreshTotal() {
var price = 0.0;
$( '.product_row [name=product\\[total_price\\]\\[\\]]' ).each( function ( index, item ) {
var val = parseFloatLocal( $( item ).val() );
price += isNaN( val ) ? 0 : val;
} );
$( '[name=total_price]' ).val( price.toFixed( 2 ) );
}
$('body.post-type-inspire_invoice .products_metabox')
.on('click', '.remove_product', function (e) {
e.preventDefault();
$(this).parents('.product_row').remove();
invoiceRefreshTotal();
})
.on('click', '.add_product', function (e) {
e.preventDefault();
var $container = $('.products_container');
let item_html = $('#product_prototype').html();
$container.append(item_html);
})
.on('change', '.refresh_net_price_sum', function (e) {
var productHandle = $(this).parents('.product_row');
invoiceRefreshProductNetPriceSum(productHandle);
})
.on('change', '.refresh_product', function (e) {
var productHandle = $(this).parents('.product_row');
var price = this.options[this.selectedIndex].dataset.price;
productHandle[0].querySelector("input[name='product[net_price][]").value = price;
invoiceRefreshProductNetPriceSum(productHandle);
})
.on('change', '.refresh_vat_sum', function (e) {
var productHandle = $(this).parents('.product_row');
invoiceRefreshProductNetPriceSum(productHandle);
})
.on('change', '.refresh_total_price', function (e) {
var productHandle = $(this).parents('.product_row');
//invoiceRefreshProductTotal(productHandle);
$('[name=product\\[total_price\\]\\[\\]]', productHandle).trigger('change');
});
// .on( 'change', '.refresh_total', function ( e ) {
// invoiceRefreshTotal();
// var productHandle = $( this ).parents( '.product_row' );
// invoiceRefreshProductBruttoPriceSum( productHandle );
// } );
} )( jQuery );

View File

@@ -0,0 +1,3 @@
/*! Select2 4.1.0-beta.1 | https://github.com/select2/select2/blob/master/LICENSE.md */
!function(){if(jQuery&&jQuery.fn&&jQuery.fn.select2&&jQuery.fn.select2.amd)var n=jQuery.fn.select2.amd;n.define("select2/i18n/pl",[],function(){var n=["znak","znaki","znaków"],e=["element","elementy","elementów"],r=function(n,e){return 1===n?e[0]:n>1&&n<=4?e[1]:n>=5?e[2]:void 0};return{errorLoading:function(){return"Nie można załadować wyników."},inputTooLong:function(e){var t=e.input.length-e.maximum;return"Usuń "+t+" "+r(t,n)},inputTooShort:function(e){var t=e.minimum-e.input.length;return"Podaj przynajmniej "+t+" "+r(t,n)},loadingMore:function(){return"Trwa ładowanie…"},maximumSelected:function(n){return"Możesz zaznaczyć tylko "+n.maximum+" "+r(n.maximum,e)},noResults:function(){return"Brak wyników"},searching:function(){return"Trwa wyszukiwanie…"},removeAllItems:function(){return"Usuń wszystkie przedmioty"}}}),n.define,n.require}();

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,179 @@
(function ($) {
"use strict";
var FISettings = {
showDependentNipFields: function () {
var field = $("#woocommerce_add_nip_field");
if (field.length) {
field.change(function () {
if ($(this).is(':checked')) {
$('.nip-additional-fields').closest('tr').show();
} else {
$('.nip-additional-fields').closest('tr').hide();
}
});
field.trigger('change');
}
},
showDependentSignatureFields: function () {
var field = $("#show_signatures");
if (field.length) {
field.change(function () {
if ($(this).is(':checked')) {
$('#signature_user').closest('tr').show();
} else {
$('#signature_user').closest('tr').hide();
}
});
field.trigger('change');
}
},
showDependentExchangeFields: function () {
var field = $('.woocommerce_currency_exchange_enable');
if (field.length) {
field.change(function () {
let value = $(this).val();
if (value === 'on' || value === 'yes_without_tax') {
$('.exchange-table-fields').closest('tr').show();
} else {
$('.exchange-table-fields').closest('tr').hide();
}
});
field.trigger('change');
}
},
showDependentMossFields: function () {
let field = $('.woocommerce_eu_vat_vies_validate');
if (field.length) {
field.change(function () {
if ($(this).is(':checked')) {
$('.vies-validation-fields').closest('tr').show();
} else {
$('.vies-validation-fields').closest('tr').hide();
}
});
field.trigger('change');
}
},
taxes: function () {
var fixHelper = function (e, ui) {
ui.children().each(function () {
$(this).width($(this).width());
});
return ui;
};
$('#flexible_invoices_tax_table tbody').sortable({
handle: 'td:first',
helper: fixHelper,
});
let table = jQuery('#flexible_invoices_tax_table');
if (table.length) {
table.on('click', '#insert_tax', function () {
let index = 0;
let new_row = $($('#tax-rates-row').html());
$(document).find('.row-num').each(function () {
let new_index = parseInt($(this).val());
if (new_index > index) {
index = new_index;
}
});
let increaseIndex = index + 1;
new_row.find('input').attr('value', '');
new_row.find('.row-num').val(increaseIndex);
var inputname = new RegExp('\\[' + 0 + '\\]', 'gm');
let elem = new_row.html().replace(inputname, '[' + increaseIndex + ']');
$('#flexible_invoices_tax_table tbody').append('<tr>' + elem + '</tr>');
return false;
});
table.on('click', '.delete-item', function () {
let rows = $(this).closest('tbody').find('tr');
if (rows.length > 1) {
$(this).closest('tr').remove();
}
return false;
});
}
},
initSelect2: function () {
var select = jQuery('.select2');
if (select.length) {
select.select2({
width: '400px'
});
}
},
subSettings: function () {
let tab_cookie_name = 'general';
let nav_active = jQuery('.nav-tab-active');
if (nav_active.length) {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
tab_cookie_name = urlParams.get('tab');
}
let sub_table = jQuery('.sub-table');
if (sub_table.length) {
jQuery('.js-subsubsub-wrapper a').click(function () {
jQuery(this).closest('ul').find('.current').removeClass('current');
jQuery(this).addClass('current');
jQuery('.form-table').hide();
sub_table.hide();
jQuery('.field-settings-' + jQuery(this).attr('id').replace('tab-anchor-', '')).show();
wpCookies.set('fi-settings-tab-' + tab_cookie_name, jQuery(this).attr('id').replace('tab-anchor-', ''));
});
var tab_cookie = wpCookies.get('fi-settings-tab-' + tab_cookie_name);
if (tab_cookie) {
var tab_element = jQuery('.sub-tab-' + tab_cookie);
tab_element.click();
} else {
sub_table.hide();
sub_table.first().show()
}
}
},
editDisabledFields: function () {
let disabled_field = jQuery('.form-table .edit_disabled_field');
if (disabled_field.length) {
disabled_field.after('<a class="remove-disabled" href="#"><span class="dashicons dashicons-edit"></span></a>');
}
jQuery('.form-table').on('click', '.remove-disabled', function () {
let input = $(this).prev();
if (input.attr('disabled') === 'disabled') {
$(this).prev().removeAttr('disabled');
} else {
$(this).prev().attr('disabled', 'disabled');
}
return false;
});
},
}
FISettings.showDependentNipFields();
FISettings.showDependentSignatureFields();
FISettings.showDependentExchangeFields();
FISettings.showDependentMossFields();
FISettings.initSelect2();
FISettings.editDisabledFields();
FISettings.taxes();
FISettings.subSettings();
})
(jQuery);

View File

@@ -0,0 +1,42 @@
( function ( $ ) {
jQuery( document ).ready( function ( $ ) {
$('.color-picker').wpColorPicker();
jQuery(document).find('.color-picker.disabled').each(function (index, item) {
let container = jQuery(this).closest('.wp-picker-container');
container.find('.wp-color-result').attr('disabled', 'disabled');
});
} );
jQuery('.select-images label').click(function (e) {
if (jQuery(this).hasClass('disabled')) {
e.preventDefault();
return false;
}
jQuery( '.select-images' ).find( 'label' ).removeClass( 'checked-image' );
jQuery( this ).addClass( 'checked-image' );
} );
jQuery( '.select-images a.zoom' ).click( function ( e ) {
jQuery( this ).closest( '.select-images' ).find( '.large-view' ).hide();
jQuery( this ).parent().find( '.large-view' ).show();
return false;
} );
jQuery( '.large-view' ).click( function ( e ) {
jQuery( this ).parent().find( '.large-view' ).hide();
return false;
} );
jQuery( document ).on( 'click', '.reset-pdf-template', function ( e ) {
let fields = jQuery( this ).closest( 'form' ).find( '[data-default_value]' );
fields.each( function ( i, n ) {
let value = jQuery( this ).attr( 'data-default_value' );
jQuery( this ).val( value ).change();
} );
return false;
} );
} )( jQuery );

View File

@@ -0,0 +1,82 @@
{
"name": "wpdesk\/flexible-invoices-core",
"description": "Flexible Invoices Core",
"license": "MIT",
"keywords": [
"wordpress",
"woocommerce",
"woocommerce invoices",
"invoices",
"wordpress invoices"
],
"homepage": "https:\/\/gitlab.com\/wpdesk\/flexible-invoices-core",
"prefer-stable": true,
"minimum-stability": "stable",
"authors": [
{
"name": "piotr.potrebka",
"email": "piotr.potrebka@wpdesk.net"
}
],
"config": {
"sort-packages": true,
"platform": {
"php": "7.0"
},
"allow-plugins": {
"cweagans\/composer-patches": true,
"dealerdirect\/phpcodesniffer-composer-installer": true,
"wpdesk\/wp-wpdesk-composer": true
}
},
"require": {
"php": ">=7.0",
"psr\/log": "^1.1.3",
"psr\/container": "^1",
"wpdesk\/flexible-invoices-abstracts": "^1.3",
"wpdesk\/wp-view": "^2",
"wpdesk\/wp-forms": "^2",
"wpdesk\/wp-mutex": "^1.1",
"wpdesk\/wp-notice": "^3.1",
"wpdesk\/wp-helpscout-beacon": "^1.2",
"wpdesk\/wp-persistence": "^3",
"wpdesk\/wc-order-abstract": "*",
"mpdf\/mpdf": "8.0.11",
"ext-json": "*",
"ext-zip": "*",
"ext-mbstring": "*"
},
"require-dev": {
"psr\/log": "^1.1.3",
"psr\/container": "^1",
"10up\/wp_mock": "*",
"mockery\/mockery": "*",
"phpunit\/phpunit": "<7",
"wp-cli\/wp-cli": "2.4.1",
"wp-cli\/wp-cli-bundle": "2.4.0"
},
"autoload": {
"psr-4": {
"WPDeskWCInvoicesVendor\\WPDesk\\Library\\FlexibleInvoicesCore\\": "src\/Invoices"
}
},
"autoload-dev": {
"psr-4": {
"WPDeskWCInvoicesVendor\\Tests\\": "tests"
}
},
"extra": {
"text-domain": "flexible-invoices-core",
"translations-folder": "lang",
"po-files": {
"pl_PL": "pl_PL.po"
}
},
"scripts": {
"phpcs": "phpcs",
"phpunit-unit": "phpunit --configuration phpunit-unit.xml --coverage-text --colors=never",
"phpunit-unit-fast": "phpunit --configuration phpunit-unit.xml --no-coverage",
"phpunit-integration": "phpunit --configuration phpunit-integration.xml --coverage-text --colors=never",
"phpunit-integration-fast": "phpunit --configuration phpunit-integration.xml --no-coverage"
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Beacon;
use WPDeskWCInvoicesVendor\WPDesk\Beacon\BeaconPro;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\LibraryInfo;
use WPDeskWCInvoicesVendor\WPDesk\PluginBuilder\Plugin\Hookable;
/**
* Class BeaconLoaderAction, Beacon loader.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Beacon
*/
class BeaconLoader implements \WPDeskWCInvoicesVendor\WPDesk\PluginBuilder\Plugin\Hookable
{
/**
* @var LibraryInfo
*/
private $plugin_info;
/**
* @param LibraryInfo $plugin_info
*/
public function __construct(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\LibraryInfo $plugin_info)
{
$this->plugin_info = $plugin_info;
}
/**
* Fire hooks.
*/
public function hooks()
{
\add_action('init', [$this, 'init_beacon'], 10);
}
/**
* Init beacon.
*/
public function init_beacon()
{
$beacon_id = '17f6054b-a2fb-4ee7-8bb5-0c3cbad1ef6a';
$beacon = new \WPDeskWCInvoicesVendor\WPDesk\Beacon\BeaconPro($beacon_id, new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Beacon\BeaconShowStrategy(), $this->plugin_info->get_plugin_url() . 'vendor_prefixed/wpdesk/wp-helpscout-beacon/assets/');
$beacon->hooks();
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Beacon;
use WPDeskWCInvoicesVendor\WPDesk\Beacon\BeaconShouldShowStrategy;
class BeaconShowStrategy implements \WPDeskWCInvoicesVendor\WPDesk\Beacon\BeaconShouldShowStrategy
{
const EN_LANG_CODE = 'en';
const SETTINGS_SLUG = ['inspire_invoice', 'edit-inspire_invoice', 'inspire_invoice_page_invoices_settings', 'inspire_invoice_page_download', 'inspire_invoice_page_flexible-invoices-reports-settings'];
public function shouldDisplay()
{
$screen = \get_current_screen();
if (isset($screen->id) && \in_array($screen->id, self::SETTINGS_SLUG, \true)) {
return \substr(\get_locale(), 0, 2) === self::EN_LANG_CODE;
}
return \false;
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Configs;
class PDF
{
const INVOICE_DIRECTORY_NAME = 'wordpress_invoices';
/**
* @return string
*/
public static function get_pdf_path() : string
{
$upload_dir = \wp_upload_dir();
$path = \trailingslashit($upload_dir['basedir']) . \trailingslashit(self::INVOICE_DIRECTORY_NAME);
\wp_mkdir_p($path);
return $path;
}
}

View File

@@ -0,0 +1,207 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Creators;
use Exception;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Data\DataSourceFactory;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\DocumentsMeta\CustomMeta;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\DocumentsMeta\NullCustomMeta;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Containers\MetaContainer;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Email\DocumentEmail;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Integration\DocumentNumber;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\DocumentGetters;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\DocumentSetters;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Settings\Settings;
/**
* Abstract document creator.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Creators
*/
abstract class AbstractDocumentCreator implements \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Creators\Creator
{
const TYPE = 'invoice';
/**
* @var string
*/
protected $button_label;
/**
* @var string
*/
protected $name;
/**
* @var Document
*/
protected $document;
/**
* @var DataSourceFactory
*/
protected $source_factory;
/**
* @var int
*/
protected $order_id;
/**
* @var string
*/
protected $source_type;
/**
* @param DataSourceFactory $source_factory
* @param string $button_label
* @param string $name
*/
public function __construct(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Data\DataSourceFactory $source_factory, string $button_label, string $name)
{
$this->button_label = $button_label;
$this->name = $name;
$this->source_factory = $source_factory;
}
/**
* @param int $order_id
*/
public function set_order_id(int $order_id)
{
$this->order_id = $order_id;
}
/**
* @return string
*/
public function get_type() : string
{
return self::TYPE;
}
/**
* @return string
*/
public function get_button_label() : string
{
return $this->button_label;
}
/**
* @return string
*/
public function get_name() : string
{
return $this->name;
}
/**
* @return Document
*/
public function get_document() : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document
{
return $this->document;
}
/**
* @return false
*/
public function is_allowed_for_create() : bool
{
return \true;
}
/**
* @return bool
*/
public function is_allowed_for_auto_create() : bool
{
return \true;
}
/**
* @return DocumentEmail
*/
public abstract function get_email_class();
/**
* @return false
*/
public function is_allowed_to_send() : bool
{
return \true;
}
/**
* @return bool
*/
public function is_allowed_for_edit() : bool
{
return \true;
}
/**
* @param Document $document
*
* @return DocumentNumber
*/
public function get_document_numbering(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document $document) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Integration\DocumentNumber
{
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Integration\DocumentNumber($this->source_factory->get_settings(), $document, $this->get_name());
}
/**
* @return bool
*/
public function can_show_document_in_my_account() : bool
{
return \true;
}
/**
* @param DocumentSetters $document
* @param int $post_id
* @param string $source_type
*
* @throws Exception
*/
protected function assign_data_from_source(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\DocumentSetters $document, int $post_id, string $source_type)
{
$data = $this->source_factory->get_source($post_id, $source_type, $this->get_type());
$document->set_number($data->get_number());
$document->set_formatted_number($data->get_formatted_number());
$document->set_date_of_pay($data->get_date_of_pay());
$document->set_date_of_paid($data->get_date_of_paid());
$document->set_date_of_issue($data->get_date_of_issue());
$document->set_date_of_sale($data->get_date_of_sale());
$document->set_customer($data->get_customer());
$document->set_recipient($data->get_recipient());
$document->set_customer_filter_field($data->get_customer_filter_field());
$document->set_seller($data->get_seller());
$document->set_currency($data->get_currency());
$document->set_discount($data->get_discount());
$document->set_id($data->get_id());
$document->set_items($data->get_items());
$document->set_payment_method($data->get_payment_method());
$document->set_payment_method_name($data->get_payment_method_name());
$document->set_payment_status($data->get_payment_status());
$document->set_notes($data->get_notes());
$document->set_tax($data->get_tax());
$document->set_total_gross($data->get_total_gross());
$document->set_total_net($data->get_total_net());
$document->set_total_paid($data->get_total_paid());
$document->set_total_gross($data->get_total_gross());
$document->set_total_tax($data->get_total_tax());
$document->set_user_lang($data->get_user_lang());
$document->set_show_order_number($data->get_show_order_number());
$document->set_order_id($data->get_order_id());
$document->set_corrected_id($data->get_corrected_id());
$this->document = $document;
}
/**
* @param DocumentGetters $document
* @param MetaContainer $meta
*
* @return CustomMeta
*/
public function custom_meta(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\DocumentGetters $document, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Containers\MetaContainer $meta)
{
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\DocumentsMeta\NullCustomMeta($document, $meta);
}
/**
* @return array
*/
public function get_auto_create_statuses() : array
{
$settings = new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Settings\Settings();
$status = $settings->get($this->get_type() . '_auto_create_status', []);
if (\is_string($status) && !empty($status)) {
return [$status];
}
if (\is_array($status)) {
return $status;
}
return [];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Creators;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Containers\MetaContainer;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Creator\DocumentCreator;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Creator\DocumentCreatorRestrictions;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\DocumentGetters;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\DocumentsMeta\CustomMeta;
/**
* Document creator.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Creators
*/
interface Creator extends \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Creator\DocumentCreator, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Creator\DocumentCreatorRestrictions
{
/**
* Returns class for saving additional custom meta for each document.
*
* @param DocumentGetters $document
* @param MetaContainer $meta
*
* @return CustomMeta
*/
public function custom_meta(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\DocumentGetters $document, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Containers\MetaContainer $meta);
}

View File

@@ -0,0 +1,40 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Creators;
use Exception;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Invoice;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Email\DocumentEmail;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Email\EmailInvoice;
/**
* Invoice creator.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Creators
*/
class InvoiceCreator extends \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Creators\AbstractDocumentCreator
{
/**
* @return string
*/
public function get_type() : string
{
return \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Invoice::DOCUMENT_TYPE;
}
/**
* @param int $document_id
* @param string $source_type
*
* @throws Exception
*/
public function create_document_from_source($document_id, $source_type)
{
$this->assign_data_from_source(new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Invoice(), $document_id, $source_type);
}
/**
* @return DocumentEmail
*/
public function get_email_class() : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Email\DocumentEmail
{
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Email\EmailInvoice();
}
}

View File

@@ -0,0 +1,398 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Data;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects\DocumentRecipient;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Settings\Settings;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects\DocumentCustomer;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects\DocumentSeller;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WordPress\Translator;
/**
* Abstraction for data source.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Data
*/
abstract class AbstractDataSource implements \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Data\SourceData
{
const ORDER_PAYMENT_PAID_STATUS = 'paid';
const ORDER_PAYMENT_TO_PAY_STATUS = 'topay';
const DOCUMENT_TYPE = 'invoice';
/**
* @var Settings
*/
protected $settings;
/**
* @var string
*/
protected $document_type = '';
/**
* @var string
*/
protected $formatted_number = '';
/**
* @var float
*/
protected $total_price = 0;
/**
* @var string
*/
protected $currency = '';
/**
* @var string
*/
protected $payment_method_name = '';
/**
* @var string
*/
protected $payment_method = '';
/**
* @var string
*/
protected $notes = '';
/**
* @var string
*/
protected $user_lang = 'en';
/**
* @var int
*/
protected $id = 0;
/**
* @var int
*/
protected $order_id = 0;
/**
* @var int
*/
protected $corrected_id = 0;
/**
* @var float
*/
protected $total_paid = 0.0;
/**
* @var string
*/
protected $payment_status = '';
/**
* @var array
*/
protected $items = [];
/**
* @var int
*/
protected $number = 0;
/**
* @var int
*/
protected $date_of_sale = 0;
/**
* @var int
*/
protected $date_of_issue = 0;
/**
* @var int
*/
protected $date_of_pay = 0;
/**
* @var int
*/
protected $paid_date = 0;
/**
* @var float
*/
protected $total_tax = 0.0;
/**
* @var float
*/
protected $total_net = 0.0;
/**
* @var float
*/
protected $total_gross = 0.0;
/**
* @var float
*/
protected $tax = 0.0;
/**
* @var Seller
*/
protected $seller;
/**
* @var Customer
*/
protected $customer;
/**
* @var Recipient
*/
protected $recipient;
/**
* @var string
*/
protected $customer_filtered_name = '';
/**
* @var float
*/
protected $discount = 0.0;
/**
* @var int
*/
protected $post_id = 0;
/**
* @param Settings $settings
* @param string $document_type
*/
public function __construct(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Settings\Settings $settings, string $document_type)
{
$this->settings = $settings;
$this->document_type = $document_type;
$this->set_wpml_user_lang(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WordPress\Translator::get_active_lang());
}
/**
* @param string $value
*/
public function set_wpml_user_lang(string $value)
{
$this->user_lang = $value;
}
/**
* @return string
*/
public function get_document_type() : string
{
return $this->document_type;
}
/**
* @return int
*/
public function get_number() : int
{
return $this->number;
}
/**
* @return string
*/
public function get_formatted_number() : string
{
return $this->formatted_number;
}
/**
* @return string
*/
public function get_currency() : string
{
return $this->currency;
}
/**
* @return string
*/
public function get_currency_symbol() : string
{
return $this->currency;
}
/**
* @return string
*/
public function get_payment_method() : string
{
return $this->payment_method;
}
/**
* @return string
*/
public function get_payment_method_name() : string
{
return $this->payment_method_name;
}
/**
* @return string
*/
public function get_notes() : string
{
return $this->settings->get($this->get_document_type() . '_notes', '');
}
/**
* @return string
*/
public function get_user_lang() : string
{
return $this->user_lang;
}
/**
* @return int
*/
public function get_id() : int
{
return $this->id;
}
/**
* @return int
*/
public function get_order_id() : int
{
return $this->order_id;
}
/**
* @return float
*/
public function get_total_paid() : float
{
return $this->total_paid;
}
/**
* @return string
*/
public function get_payment_status() : string
{
return $this->payment_status;
}
/**
* @return int
*/
public function get_date_of_sale() : int
{
return $this->date_of_sale;
}
/**
* @return int
*/
public function get_date_of_issue() : int
{
return $this->date_of_issue;
}
/**
* @return int
*/
public function get_date_of_pay() : int
{
return $this->date_of_pay;
}
/**
* @return int
*/
public function get_date_of_paid() : int
{
return $this->paid_date;
}
/**
* @return float
*/
public function get_total_tax() : float
{
return $this->total_tax;
}
/**
* @return float
*/
public function get_total_net() : float
{
return $this->total_net;
}
/**
* @return float
*/
public function get_total_gross() : float
{
return $this->total_gross;
}
/**
* @return float
*/
public function get_tax() : float
{
return $this->tax;
}
/**
* @return float
*/
public function get_discount() : float
{
return $this->discount;
}
/**
* @return string
*/
public function get_customer_filter_field() : string
{
return $this->customer_filtered_name;
}
/**
* @return Customer
*/
public function get_customer() : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer
{
$id = $this->customer['id'] ?? '';
$name = $this->customer['name'] ?? '';
$street = $this->customer['street'] ?? '';
$street2 = $this->customer['street2'] ?? '';
$postcode = $this->customer['postcode'] ?? '';
$city = $this->customer['city'] ?? '';
$vat_number = $this->customer['nip'] ?? '';
$country = $this->customer['country'] ?? '';
$phone = $this->customer['phone'] ?? '';
$email = $this->customer['email'] ?? '';
$state = $this->customer['state'] ?? '';
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects\DocumentCustomer($id, $name, $street, $postcode, $city, $vat_number, $country, $phone, $email, 'individual', $street2, $state);
}
/**
* @return Recipient
*/
public function get_recipient() : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient
{
$name = $this->recipient['name'] ?? '';
$street = $this->recipient['street'] ?? '';
$street2 = $this->recipient['street2'] ?? '';
$postcode = $this->recipient['postcode'] ?? '';
$city = $this->recipient['city'] ?? '';
$vat_number = $this->recipient['nip'] ?? '';
$country = $this->recipient['country'] ?? '';
$phone = $this->recipient['phone'] ?? '';
$email = $this->recipient['email'] ?? '';
$state = $this->recipient['state'] ?? '';
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects\DocumentRecipient($name, $street, $postcode, $city, $vat_number, $country, $phone, $email, $street2, $state);
}
/**
* @return Seller
*/
public function get_seller() : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller
{
$name = $this->settings->has('company_name') ? $this->settings->get('company_name') : '';
$address = $this->settings->has('company_address') ? $this->settings->get('company_address') : '';
$nip = $this->settings->has('company_nip') ? $this->settings->get('company_nip') : '';
$bank_name = $this->settings->has('bank_name') ? $this->settings->get('bank_name') : '';
$bank_account = $this->settings->has('account_number') ? $this->settings->get('account_number') : '';
$logo = $this->settings->has('company_logo') ? $this->settings->get('company_logo') : '';
$signature_user = $this->settings->has('signature_user') ? $this->settings->get('signature_user') : '';
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects\DocumentSeller(0, $logo, $name, $address, $nip, $bank_name, $bank_account, $signature_user);
}
/**
* @return array
*/
public function get_items() : array
{
return $this->items;
}
/**
* @return int
*/
public function get_show_order_number() : int
{
return 0;
}
/**
* @return int
*/
public function get_corrected_id() : int
{
return $this->corrected_id;
}
/**
* @return int
*/
public function get_is_correction() : int
{
return 0;
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Data;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentExceptions\InvalidDocumentDataException;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Invoice;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Settings\Settings;
/**
* This factory define document data sources. They can be taken from postmeta, $_POST or WC_Order.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Data
*/
class DataSourceFactory
{
const POST_SOURCE = 'post';
const META_SOURCE = 'meta';
const ORDER_SOURCE = 'order';
/**
* @var Settings
*/
private $settings;
/**
* @param Settings $settings
*/
public function __construct(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Settings\Settings $settings)
{
$this->settings = $settings;
}
/**
* @return Settings
*/
public function get_settings()
{
return $this->settings;
}
/**
* @param int $post_id
* @param string $source_type
*
* @param string $document_type
*
* @return SourceData
* @throws \Exception Unknown source.
* @throws InvalidDocumentDataException Invalid data exception.
*/
public function get_source($post_id, $source_type, $document_type = \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Invoice::DOCUMENT_TYPE)
{
try {
switch ($source_type) {
case self::POST_SOURCE:
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Data\PostDocumentDataSource($post_id, $this->settings, $document_type);
case self::META_SOURCE:
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Data\PostMetaDocumentDataSource($post_id, $this->settings, $document_type);
case self::ORDER_SOURCE:
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Data\OrderDocumentDataSource($post_id, $this->settings, $document_type);
default:
throw new \Exception('Unknown source');
}
} catch (\Exception $e) {
throw new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentExceptions\InvalidDocumentDataException($e->getMessage());
}
}
}

View File

@@ -0,0 +1,301 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Data;
use Exception;
use WC_Order;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects\DocumentRecipient;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\WooCommerce;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WooCommerce\OrderItems;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Settings\Settings;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects\DocumentCustomer;
use function strip_tags;
/**
* Get document data from order.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Data
*/
class OrderDocumentDataSource extends \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Data\AbstractDataSource
{
const ORDER_PAYMENT_STATUSES = ['processing', 'completed'];
/**
* @var WC_Order
*/
public $order;
/**
* @param int $order_id
* @param Settings $options_container
* @param string $document_type
*
* @throws Exception Throw exception if WooCommerce is not active.
*/
public function __construct(int $order_id, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Settings\Settings $options_container, string $document_type)
{
if (!\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\WooCommerce::is_active()) {
throw new \Exception('Order source cannot be used without WooCommerce!');
}
parent::__construct($options_container, $document_type);
$this->order = new \WC_Order($order_id);
$wpml_user_lang = $this->order->get_meta('wpml_user_lang', \true);
if (!empty($wpml_user_lang)) {
$this->set_wpml_user_lang($wpml_user_lang);
}
\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks::wpml_switch_language_hook($wpml_user_lang);
}
/**
* @return int
*/
public function get_date_of_sale() : int
{
$_date_sale = \time();
if ($this->order->get_date_created()) {
$_date_sale = $this->order->get_date_created()->getOffsetTimestamp();
}
if ($this->settings->get('woocommerce_date_of_sale', 'order_date') === 'order_completed') {
$completed_date = $this->order->get_date_completed();
if ($completed_date) {
$_date_sale = $completed_date->getOffsetTimestamp();
}
}
return $_date_sale;
}
/**
* @return int
*/
public function get_date_of_pay() : int
{
$pay_date = $this->get_date_of_issue() + 60 * 60 * 24 * \intval($this->settings->get($this->get_document_type() . '_default_due_time'), 0);
return (int) $pay_date;
}
/**
* @return int
*/
public function get_date_of_paid() : int
{
$paid_date = $this->order->get_meta('_paid_date', \true);
if ($paid_date) {
return \strtotime($paid_date);
}
return \strtotime(\current_time('mysql'));
}
/**
* @return int
*/
public function get_date_of_issue() : int
{
return \strtotime(\current_time('mysql'));
}
/**
* @return Customer
*/
public function get_customer() : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer
{
$billing_company = $this->order->get_billing_company();
if (empty($billing_company)) {
$type = 'individual';
$name = \strip_tags($this->order->get_formatted_billing_full_name());
} else {
$type = 'company';
$name = $billing_company;
}
$vat_number = $this->order->get_meta('_billing_vat_number', \true);
$id = $this->order->get_customer_id();
$street = $this->order->get_billing_address_1();
$street2 = $this->order->get_billing_address_2();
$postcode = $this->order->get_billing_postcode();
$city = $this->order->get_billing_city();
$nip = $vat_number;
$country = $this->order->get_billing_country();
$phone = $this->order->get_billing_phone();
$email = $this->order->get_billing_email();
$state = $this->order->get_billing_state();
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects\DocumentCustomer($id, $name, $street, $postcode, $city, $nip, $country, $phone, $email, $type, $street2, $state);
}
/**
* @return DocumentRecipient
*/
public function get_recipient() : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient
{
$show_recipient_type = $this->settings->get('woocommerce_shipping_address', 'none');
$billing_company = $this->order->get_billing_company();
if (empty($billing_company)) {
$billing_name = \strip_tags($this->order->get_formatted_billing_full_name());
} else {
$billing_name = $billing_company;
}
$shipping_company = $this->order->get_shipping_company();
if (empty($shipping_company)) {
$shipping_name = \strip_tags($this->order->get_formatted_shipping_full_name());
} else {
$shipping_name = $shipping_company;
}
if ($show_recipient_type === 'ifempty' && $this->has_different_address()) {
return $this->get_recipient_from_shipping($shipping_name);
}
if ($show_recipient_type === 'always' && !$this->has_different_address()) {
return $this->get_recipient_from_billing($billing_name);
}
if ($show_recipient_type === 'always') {
return $this->get_recipient_from_shipping($shipping_name);
}
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects\DocumentRecipient('', '', '', '', '', '', '', '', '', '');
}
/**
* @return bool
*/
private function has_different_address() : bool
{
$billing_address = $this->order->get_billing_address_1() . $this->order->get_billing_country() . $this->order->get_billing_city() . $this->order->get_billing_postcode();
$shipping_address = $this->order->get_shipping_address_1() . $this->order->get_shipping_country() . $this->order->get_shipping_city() . $this->order->get_shipping_postcode();
return $billing_address !== $shipping_address;
}
/**
* @param string $name
*
* @return Recipient
*/
private function get_recipient_from_billing(string $name) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient
{
$vat_number = $this->order->get_meta('_billing_vat_number', \true);
$street = $this->order->get_billing_address_1();
$street2 = $this->order->get_billing_address_2();
$postcode = $this->order->get_billing_postcode();
$city = $this->order->get_billing_city();
$nip = $vat_number;
$country = $this->order->get_billing_country();
$state = $this->order->get_billing_state();
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects\DocumentRecipient($name, $street, $postcode, $city, $nip, $country, '', '', $street2, $state);
}
/**
* @param string $name
*
* @return Recipient
*/
private function get_recipient_from_shipping(string $name) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient
{
$vat_number = $this->order->get_meta('_shipping_vat_number', \true);
$street = $this->order->get_shipping_address_1();
$street2 = $this->order->get_shipping_address_2();
$postcode = $this->order->get_shipping_postcode();
$city = $this->order->get_shipping_city();
$nip = $vat_number;
$country = $this->order->get_shipping_country();
$state = $this->order->get_shipping_state();
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects\DocumentRecipient($name, $street, $postcode, $city, $nip, $country, '', '', $street2, $state);
}
/**
* @return string
*/
public function get_customer_filter_field() : string
{
return $this->get_customer()->get_name();
}
/**
* @return string
*/
public function get_currency() : string
{
return $this->order->get_currency();
}
/**
* @return float
*/
public function get_discount() : float
{
return $this->order->get_total_discount();
}
/**
* @return int
*/
public function get_order_id() : int
{
return $this->order->get_id();
}
/**
* @return array
*/
public function get_items() : array
{
$order_items = new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WooCommerce\OrderItems($this->order);
return $order_items->get_items();
}
/**
* @return string
*/
public function get_payment_method() : string
{
return $this->order->get_payment_method();
}
/**
* @return string
*/
public function get_payment_method_name() : string
{
return $this->order->get_payment_method_title();
}
/**
* @return float
*/
public function get_total_gross() : float
{
return $this->order->get_total();
}
/**
* @return float
*/
public function get_total_net() : float
{
return $this->order->get_total() - $this->order->get_total_tax();
}
/**
* @return float
*/
public function get_total_paid() : float
{
if ($this->get_payment_status() === self::ORDER_PAYMENT_PAID_STATUS) {
return $this->order->get_total();
}
return $this->total_paid;
}
/**
* @return float
*/
public function get_total_tax() : float
{
return $this->order->get_total_tax();
}
/**
* @return string
*/
public function get_payment_status() : string
{
$payment_method = $this->order->get_payment_method();
if ($payment_method !== 'cod' && \in_array($this->order->get_status(), self::ORDER_PAYMENT_STATUSES, \true) && $this->settings->get('woocommerce_auto_paid_status') === 'yes') {
return self::ORDER_PAYMENT_PAID_STATUS;
}
if ($payment_method === 'cod' && $this->order->get_status() === 'completed' && $this->settings->get('invoice_auto_paid_status') === 'yes') {
return self::ORDER_PAYMENT_PAID_STATUS;
}
return self::ORDER_PAYMENT_TO_PAY_STATUS;
}
/**
* @return int
*/
public function get_show_order_number() : int
{
if ($this->settings->get('woocommerce_add_order_id', 'no') === 'yes') {
return 1;
}
return 0;
}
/**
* @return string
*/
public function get_user_lang() : string
{
return \strtolower($this->user_lang);
}
}

View File

@@ -0,0 +1,250 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Data;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\CalculateTotals;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\PriceFormatter;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Infrastructure\Request;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Settings\Settings;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects\DocumentSeller;
/**
* Get document data from POST.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Data
*/
class PostDocumentDataSource extends \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Data\AbstractDataSource
{
/**
* @var Request
*/
public $source;
/**
* @var array
*/
protected $products;
/**
* @var PostMetaDocumentDataSource
*/
private $post_meta_data;
/**
* @param int $post_id
* @param Settings $options_container
* @param string $document_type
*/
public function __construct(int $post_id, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Settings\Settings $options_container, string $document_type)
{
parent::__construct($options_container, $document_type);
$this->source = new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Infrastructure\Request();
$this->post_id = $post_id;
$this->customer = $this->source->param('post.client')->get_as_array();
$this->recipient = $this->source->param('post.recipient')->get_as_array();
$this->seller = $this->source->param('post.owner')->get_as_array();
$this->products = $this->source->param('post.product')->get_as_array();
$this->post_meta_data = new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Data\PostMetaDocumentDataSource($post_id, $options_container, $document_type);
}
public function get_id() : int
{
return $this->post_id;
}
/**
* @return int
*/
public function get_date_of_sale() : int
{
return (int) \strtotime($this->source->param('post.date_sale')->get());
}
/**
* @return int
*/
public function get_date_of_pay() : int
{
return (int) \strtotime($this->source->param('post.date_pay')->get());
}
/**
* @return int
*/
public function get_date_of_paid() : int
{
return (int) \strtotime($this->source->param('post.date_paid')->get());
}
/**
* @return int
*/
public function get_date_of_issue() : int
{
return (int) \strtotime($this->source->param('post.date_issue')->get());
}
/**
* @return string
*/
public function get_customer_filter_field() : string
{
return $this->get_customer()->get_name();
}
/**
* @return string
*/
public function get_currency() : string
{
return $this->source->param('post.currency')->get_as_string();
}
/**
* @return float
*/
public function get_discount() : float
{
return \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\PriceFormatter::string_to_float($this->source->param('post.discount')->get());
}
/**
* @return int
*/
public function get_order_id() : int
{
if (empty($this->source->param('post.wc_order_id')->get())) {
return $this->post_meta_data->get_order_id();
}
return $this->source->param('post.wc_order_id')->get();
}
/**
* @return array
*/
public function get_items() : array
{
$products = [];
if (\count($this->products) > 0) {
foreach ($this->products['name'] as $index => $name) {
$vat_type = \explode('|', $this->products['vat_type'][$index]);
$qty = $this->products['quantity'][$index] ?? 1;
if (empty($qty)) {
$qty = 1;
}
$products[] = ['name' => $name, 'sku' => $this->products['sku'][$index], 'unit' => $this->products['unit'][$index], 'quantity' => \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\PriceFormatter::string_to_float($qty), 'net_price' => \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\PriceFormatter::string_to_float($this->products['net_price'][$index]), 'discount' => $this->products['discount'][$index] ?? '', 'net_price_sum' => \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\PriceFormatter::string_to_float($this->products['net_price_sum'][$index]), 'vat_type' => $vat_type[1] ?? '0', 'vat_type_index' => $vat_type[0] ?? '0', 'vat_type_name' => $vat_type[2] ?? '0', 'vat_rate' => \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\PriceFormatter::string_to_float($this->products['vat_sum'][$index]) / \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\PriceFormatter::string_to_float($qty), 'vat_sum' => \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\PriceFormatter::string_to_float($this->products['vat_sum'][$index]), 'total_price' => \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\PriceFormatter::string_to_float($this->products['total_price'][$index])];
}
}
return $products;
}
/**
* @return string
*/
public function get_payment_method() : string
{
return $this->source->param('post.payment_method')->get_as_string();
}
/**
* @return string
*/
public function get_payment_method_name() : string
{
return $this->source->param('post.payment_method_name')->get_as_string();
}
/**
* @return string
*/
public function get_notes() : string
{
$notes = $this->source->param('post.notes')->get_as_string();
if (!empty($notes)) {
return $this->source->param('post.notes')->get_as_string();
}
return $this->settings->get($this->get_document_type() . '_notes', '');
}
/**
* @return float
*/
public function get_total_gross() : float
{
return \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\PriceFormatter::string_to_float($this->source->param('post.total_price')->get());
}
/**
* @return float
*/
public function get_total_net() : float
{
return $this->calculate_total_net();
}
/**
* @return float
*/
public function get_total_paid() : float
{
return \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\PriceFormatter::string_to_float($this->source->param('post.total_paid')->get());
}
/**
* @return float
*/
public function get_total_tax() : float
{
return $this->calculate_total_tax();
}
/**
* @return string
*/
public function get_user_lang() : string
{
if (empty($this->source->param('post.wpml_user_lang')->get_as_string())) {
return $this->post_meta_data->get_user_lang();
}
return $this->source->param('post.wpml_user_lang')->get_as_string();
}
/**
* @return string
*/
public function get_payment_status() : string
{
return $this->source->param('post.payment_status')->get_as_string();
}
/**
* @return Seller
*/
public function get_seller() : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller
{
$name = $this->seller['name'] ?? '';
$address = $this->seller['address'] ?? '';
$nip = $this->seller['nip'] ?? '';
$bank_name = $this->seller['bank'] ?? '';
$bank_account = $this->seller['account'] ?? '';
$logo = $this->seller['logo'] ?? '';
$signature_user = $this->seller['signature_user'] ?? '';
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects\DocumentSeller(0, $logo, $name, $address, $nip, $bank_name, $bank_account, $signature_user);
}
/**
* @return float
*/
private function calculate_total_tax() : float
{
$items_vats = $this->source->param('post.product.vat_sum')->get_as_array();
$vat_items = [];
foreach ($items_vats as $vat) {
$vat_items[]['vat_sum'] = $vat;
}
$total = \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\CalculateTotals::calculate_total_vat($vat_items);
if ($total > 0) {
return $total;
}
return $this->total_tax;
}
/**
* @return float
*/
private function calculate_total_net() : float
{
$items_nets = $this->source->param('post.product.net_price_sum')->get_as_array();
$items_net = [];
foreach ($items_nets as $vat) {
$items_net[]['net_price_sum'] = $vat;
}
$total = \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\CalculateTotals::calculate_total_net($items_net);
if ($total > 0) {
return $total;
}
return $this->total_tax;
}
/**
* @return int
*/
public function get_show_order_number() : int
{
return (int) $this->source->param('post.add_order_id')->get();
}
}

View File

@@ -0,0 +1,230 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Data;
use WP_Post;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\CalculateTotals;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\PriceFormatter;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Integration\MetaPostContainer;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Settings\Settings;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects\DocumentSeller;
use WPDeskWCInvoicesVendor\WPDesk\Persistence\PersistentContainer;
/**
* Get document data form post meta.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Data
*/
class PostMetaDocumentDataSource extends \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Data\AbstractDataSource
{
/**
* @var PersistentContainer
*/
public $meta;
/**
* @var WP_Post
*/
public $post;
/**
* @param int $post_id
* @param Settings $options_container
* @param string $document_type
*/
public function __construct($post_id, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Settings\Settings $options_container, string $document_type)
{
parent::__construct($options_container, $document_type);
$this->post_id = (int) $post_id;
$this->meta = new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Integration\MetaPostContainer($post_id);
$this->post = \get_post($this->post_id);
$this->customer = $this->meta->get_fallback('_client', []);
$this->recipient = $this->meta->get_fallback('_recipient', []);
$this->seller = $this->meta->get_fallback('_owner', []);
}
/**
* @return int
*/
public function get_id() : int
{
return $this->post_id;
}
/**
* @return int
*/
public function get_number() : int
{
return (int) $this->meta->get_fallback('_number', 1);
}
/**
* @return string
*/
public function get_formatted_number() : string
{
return $this->post->post_title ?? $this->meta->get_fallback('_formatted_number', '');
}
/**
* @return int
*/
public function get_date_of_sale() : int
{
return (int) $this->meta->get_fallback('_date_sale', \strtotime(\current_time('mysql')));
}
/**
* @return int
*/
public function get_date_of_pay() : int
{
return (int) $this->meta->get_fallback('_date_pay', $this->get_date_of_issue() + 60 * 60 * 24 * \intval($this->settings->get($this->get_document_type() . '_default_due_time'), 0));
}
/**
* @return int
*/
public function get_date_of_issue() : int
{
return (int) $this->meta->get_fallback('_date_issue', \strtotime(\current_time('mysql')));
}
/**
* @return Seller
*/
public function get_seller() : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller
{
if (empty($this->seller)) {
return parent::get_seller();
}
$name = $this->seller['name'] ?? '';
$address = $this->seller['address'] ?? '';
$nip = $this->seller['nip'] ?? '';
$bank_name = $this->seller['bank'] ?? '';
$bank_account = $this->seller['account'] ?? '';
$logo = $this->seller['logo'] ?? '';
$signature_user = $this->seller['signature_user'] ?? '';
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\ValueObjects\DocumentSeller(0, $logo, $name, $address, $nip, $bank_name, $bank_account, $signature_user);
}
/**
* @return string
*/
public function get_customer_filter_field() : string
{
return $this->get_customer()->get_name();
}
/**
* @return string
*/
public function get_currency() : string
{
return $this->meta->get('_currency');
}
/**
* @return float
*/
public function get_discount() : float
{
return \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\PriceFormatter::string_to_float($this->meta->get('_discount'));
}
/**
* @return int
*/
public function get_order_id() : int
{
return (int) $this->meta->get_fallback('_wc_order_id', 0);
}
/**
* @return array
*/
public function get_items() : array
{
$products = $this->meta->get_fallback('_products', []);
$shipping = $this->meta->get_fallback('_shipping', []);
if (\is_array($products) && \is_array($shipping)) {
return \array_merge($products, $shipping);
}
return [];
}
/**
* @return string
*/
public function get_payment_method() : string
{
return $this->meta->get('_payment_method');
}
/**
* @return string
*/
public function get_payment_status() : string
{
return $this->meta->get_fallback('_payment_status', 'due');
}
/**
* @return string
*/
public function get_payment_method_name() : string
{
return $this->meta->get('_payment_method_name');
}
/**
* @return string
*/
public function get_notes() : string
{
return $this->meta->get('_notes');
}
/**
* @return float
*/
public function get_total_gross() : float
{
return \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\PriceFormatter::string_to_float($this->meta->get_fallback('_total_price', 0.0));
}
/**
* @return float
*/
public function get_total_net() : float
{
return \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\PriceFormatter::string_to_float($this->meta->get_fallback('_total_net', \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\CalculateTotals::calculate_total_net($this->get_items())));
}
/**
* @return float
*/
public function get_total_paid() : float
{
return \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\PriceFormatter::string_to_float($this->meta->get_fallback('_total_paid', 0.0));
}
/**
* @return float
*/
public function get_total_tax() : float
{
return \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\PriceFormatter::string_to_float($this->meta->get_fallback('_total_tax', \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\CalculateTotals::calculate_total_vat($this->get_items())));
}
/**
* @return string
*/
public function get_user_lang() : string
{
$user_lang = $this->meta->get('wpml_user_lang');
if (empty($user_lang)) {
return \strtolower($this->get_customer()->get_country());
}
return $user_lang;
}
/**
* @return int
*/
public function get_corrected_id() : int
{
return (int) $this->meta->get_fallback('_corrected_invoice_id', 0);
}
/**
* @return int
*/
public function get_is_correction() : int
{
return (int) $this->meta->get_fallback('_correction', 0);
}
/**
* @return int
*/
public function get_show_order_number() : int
{
return (int) $this->meta->get_fallback('_add_order_id', 0);
}
}

View File

@@ -0,0 +1,135 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Data;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller;
/**
* This interface defines methods for different data sources.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Data
*/
interface SourceData
{
/**
* @return string
*/
public function get_document_type() : string;
/**
* @return array
*/
public function get_items() : array;
/**
* @return Seller
*/
public function get_seller() : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller;
/**
* @return Customer
*/
public function get_customer() : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer;
/**
* @return Recipient
*/
public function get_recipient() : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient;
/**
* @return string
*/
public function get_formatted_number() : string;
/**
* @return string
*/
public function get_currency() : string;
/**
* @return string
*/
public function get_currency_symbol() : string;
/**
* @return string
*/
public function get_payment_method() : string;
/**
* @return string
*/
public function get_payment_method_name() : string;
/**
* @return string
*/
public function get_notes() : string;
/**
* @return string
*/
public function get_user_lang() : string;
/**
* @return int
*/
public function get_id() : int;
/**
* @return int
*/
public function get_order_id() : int;
/**
* @return float
*/
public function get_total_paid() : float;
/**
* @return string
*/
public function get_payment_status() : string;
/**
* @return int
*/
public function get_number() : int;
/**
* @return int
*/
public function get_date_of_sale() : int;
/**
* @return int
*/
public function get_date_of_issue() : int;
/**
* @return int
*/
public function get_date_of_pay() : int;
/**
* @return int
*/
public function get_date_of_paid() : int;
/**
* @return float
*/
public function get_total_tax() : float;
/**
* @return float
*/
public function get_total_net() : float;
/**
* @return float
*/
public function get_total_gross() : float;
/**
* @return float
*/
public function get_tax() : float;
/**
* @return float
*/
public function get_discount() : float;
/**
* @return string
*/
public function get_customer_filter_field() : string;
/**
* @return int
*/
public function get_show_order_number() : int;
/**
* @return int
*/
public function get_is_correction() : int;
/**
* @return int
*/
public function get_corrected_id() : int;
}

View File

@@ -0,0 +1,481 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Decorators;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\WooCommerce;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\SettingsStrategy\SettingsStrategy;
/**
* Base decorator for document.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Decorators
*/
class BaseDecorator implements \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document
{
/**
* @var Document
*/
protected $document;
/**
* @var SettingsStrategy
*/
protected $strategy;
/**
* @var Helpers\Currency
*/
protected $currency_helper;
/**
* @param Document $document
* @param SettingsStrategy $strategy
*/
public function __construct(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document $document, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\SettingsStrategy\SettingsStrategy $strategy)
{
$this->document = $document;
$this->strategy = $strategy;
$this->currency_helper = new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Currency($document->get_currency());
}
/**
* @param string $value
*/
public function set_date_of_paid($value)
{
$this->document->set_date_of_paid($value);
}
/**
* @return string
*/
public function get_date_of_paid() : string
{
return $this->document->get_date_of_paid();
}
/**
* @param string $value
*/
public function set_date_of_issue($value)
{
$this->document->set_date_of_issue($value);
}
/**
* @return string
*/
public function get_date_of_issue() : string
{
return $this->document->get_date_of_issue();
}
/**
* @param string $value
*/
public function set_date_of_sale($value)
{
$this->document->set_date_of_sale($value);
}
/**
* @return string
*/
public function get_date_of_sale() : string
{
return $this->document->get_date_of_sale();
}
/**
* @param string $value
*/
public function set_date_of_pay($value)
{
$this->document->set_date_of_pay($value);
}
/**
* @return string
*/
public function get_date_of_pay() : string
{
return $this->document->get_date_of_pay();
}
/**
* @return string
*/
public function get_type() : string
{
return $this->document->get_type();
}
/**
* @param string $value
*/
public function set_formatted_number($value)
{
$this->document->set_formatted_number($value);
}
/**
* @return string
*/
public function get_formatted_number() : string
{
return $this->document->get_formatted_number();
}
/**
* @param string $value
*/
public function set_total_gross($value)
{
$this->document->set_total_gross($value);
}
/**
* @param string $value
*/
public function set_currency($value)
{
$this->document->set_currency($value);
}
/**
* @return string
*/
public function get_currency() : string
{
return $this->document->get_currency();
}
/**
* @return string
*/
public function get_currency_symbol() : string
{
return $this->document->get_currency_symbol();
}
/**
* @param string $value
*/
public function set_currency_symbol($value)
{
$this->document->set_currency_symbol($value);
}
/**
* @param string $value
*/
public function set_payment_method($value)
{
$this->document->set_payment_method($value);
}
/**
* @return string
*/
public function get_payment_method() : string
{
return $this->document->get_payment_method();
}
/**
* @param string $value
*/
public function set_payment_method_name($value)
{
$this->document->set_payment_method_name($value);
}
/**
* @param $value
*/
public function set_notes($value)
{
$this->document->set_notes(\esc_html($this->strategy->get_settings()->get('invoices_notice')));
}
/**
* @return string
*/
public function get_notes() : string
{
return $this->document->get_notes();
}
/**
* @param $value
*/
public function set_user_lang($value)
{
$this->document->set_user_lang($value);
}
public function get_user_lang() : string
{
return $this->document->get_user_lang();
}
/**
* @param int $id
*/
public function set_id($id)
{
$this->document->set_id($id);
}
/**
* @return int
*/
public function get_id() : int
{
return $this->document->get_id();
}
/**
* @param float $value
*/
public function set_total_paid($value)
{
$this->document->set_total_paid($value);
}
/**
* @return float
*/
public function get_total_paid() : float
{
return $this->currency_helper->number_format($this->document->get_total_paid());
}
/**
* @param string $value
*/
public function set_payment_status($value)
{
$this->document->set_payment_status($value);
}
/**
* @return string
*/
public function get_payment_status() : string
{
return $this->document->get_payment_status();
}
/**
* @return string
*/
public function get_payment_status_name() : string
{
return $this->document->get_payment_status();
}
/**
* @param array $items
*/
public function set_items($items)
{
$this->document->set_items($items);
}
/**
* @return array
*/
public function get_items() : array
{
return $this->document->get_items();
}
/**
* @param int $number
*/
public function set_number($number)
{
$this->document->set_number($number);
}
/**
* @return int
*/
public function get_number() : int
{
return $this->document->get_number();
}
/**
* @param float $value
*/
public function set_total_tax($value)
{
$this->document->set_total_tax($value);
}
/**
* @return float
*/
public function get_total_tax() : float
{
return $this->document->get_total_tax();
}
/**
* @return float
*/
public function get_total_net() : float
{
return $this->document->get_total_net();
}
/**
* @param float $value
*/
public function set_total_net($value)
{
$this->document->set_total_net($value);
}
/**
* @return float
*/
public function get_total_gross() : float
{
return $this->document->get_total_gross();
}
/**
* @param string $value
*/
public function set_tax($value)
{
$this->document->set_tax($value);
}
/**
* @return float
*/
public function get_tax() : float
{
return $this->document->get_tax();
}
/**
* @param Seller $seller
*/
public function set_seller(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller $seller)
{
$this->document->set_seller($seller);
}
/**
* @return Seller
*/
public function get_seller() : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller
{
return $this->document->get_seller();
}
/**
* @param Customer $customer
*/
public function set_customer(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer $customer)
{
$this->document->set_customer($customer);
}
public function get_customer() : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer
{
return $this->document->get_customer();
}
/**
* @param Recipient $recipient
*/
public function set_recipient(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient $recipient)
{
$this->document->set_recipient($recipient);
}
/**
* @return Recipient
*/
public function get_recipient() : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient
{
return $this->document->get_recipient();
}
/**
* @param string $customer_name
*/
public function set_customer_filter_field($customer_name)
{
$this->document->set_customer_filter_field($customer_name);
}
/**
* @return string
*/
public function get_customer_filter_field() : string
{
return $this->document->get_customer_filter_field();
}
/**
* @param float $value
*/
public function set_discount($value)
{
$this->document->set_discount($value);
}
/**
* @return float
*/
public function get_discount() : float
{
return $this->document->get_discount();
}
/**
* @param int $id
*/
public function set_order_id($id)
{
$this->document->set_order_id($id);
}
/**
* @return int
*/
public function get_order_id() : int
{
return $this->document->get_order_id();
}
/**
* @return string
*/
public function get_order_number() : string
{
$order_id = $this->document->get_order_id();
$order_number = $order_id;
if ($order_id && \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\WooCommerce::is_active()) {
$order = \wc_get_order($order_id);
if ($order) {
$order_number = $order->get_order_number();
}
}
return (string) $order_number;
}
/**
* @param int $id
*/
public function set_corrected_id($id)
{
$this->document->set_corrected_id($id);
}
/**
* @return int
*/
public function get_corrected_id() : int
{
return $this->document->get_corrected_id();
}
/**
* @param string $value
*/
public function set_show_order_number($value)
{
$this->document->set_show_order_number($value);
}
/**
* @return bool
*/
public function get_show_order_number() : bool
{
return $this->document->get_show_order_number();
}
/**
* @param bool $is_correction
*/
public function set_is_correction($is_correction)
{
$this->document->set_is_correction($is_correction);
}
/**
* @return int
*/
public function get_is_correction() : int
{
return $this->document->get_is_correction();
}
/**
* @return string
*/
public function get_payment_method_name() : string
{
$payment_method_name = $this->document->get_payment_method_name();
if (!empty($payment_method_name)) {
return $payment_method_name;
}
$payment_method_slug = $this->document->get_payment_method();
$payment_methods = $this->strategy->get_payment_methods();
foreach ($payment_methods as $methods_source) {
foreach ($methods_source as $payment_method_key => $payment_method_title) {
$methods[$payment_method_key] = $payment_method_title;
}
}
return $methods[$payment_method_slug] ?? $payment_method_slug;
}
}

View File

@@ -0,0 +1,78 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Decorators;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks;
/**
* Decorates document for editing && pdf.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Decorators
*/
class DocumentDecorator extends \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Decorators\BaseDecorator
{
/**
* @return string
*/
public function get_date_of_paid() : string
{
$date_format = \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks::document_date_paid_format_filter(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks::document_date_general_format_filter());
return \date($date_format, $this->document->get_date_of_paid());
}
/**
* @return string
*/
public function get_date_of_issue() : string
{
$date_format = \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks::document_date_issue_format_filter(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks::document_date_general_format_filter());
return \date($date_format, $this->document->get_date_of_issue());
}
/**
* @return string
*/
public function get_date_of_sale() : string
{
$date_format = \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks::document_date_sale_format_filter(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks::document_date_general_format_filter());
return \date($date_format, $this->document->get_date_of_sale());
}
/**
* @return string
*/
public function get_date_of_pay() : string
{
$date_format = \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks::document_date_pay_format_filter(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks::document_date_general_format_filter());
return \date($date_format, $this->document->get_date_of_pay());
}
/**
* @return string
*/
public function get_payment_status_name() : string
{
foreach ($this->strategy->get_payment_statuses() as $method_key => $method_name) {
if ($method_key === $this->document->get_payment_status()) {
return $method_name;
}
}
return $this->document->get_payment_status();
}
/**
* @return float
*/
public function get_total_tax() : float
{
return $this->currency_helper->number_format($this->document->get_total_tax());
}
/**
* @return float
*/
public function get_total_net() : float
{
return $this->currency_helper->number_format($this->document->get_total_net());
}
/**
* @return float
*/
public function get_total_gross() : float
{
return $this->currency_helper->number_format($this->document->get_total_gross());
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Decorators;
/**
* Decorates document for saving into post meta.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Decorators
*/
class PostMetaDocumentDecorator extends \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Decorators\BaseDecorator
{
/**
* @return array
*/
public function get_seller_as_array() : array
{
$seller = $this->document->get_seller();
return ['name' => $seller->get_name(), 'address' => $seller->get_address(), 'nip' => $seller->get_vat_number(), 'account' => $seller->get_bank_account_number(), 'bank' => $seller->get_bank_name(), 'logo' => $seller->get_logo(), 'id' => $seller->get_id(), 'signature_user' => $seller->get_signature_user()];
}
/**
* @return array
*/
public function get_customer_as_array() : array
{
$customer = $this->document->get_customer();
return ['name' => $customer->get_name(), 'street' => $customer->get_street(), 'street2' => $customer->get_street2(), 'postcode' => $customer->get_postcode(), 'city' => $customer->get_city(), 'nip' => $customer->get_vat_number(), 'country' => $customer->get_country(), 'phone' => $customer->get_phone(), 'email' => $customer->get_email(), 'type' => $customer->get_type(), 'state' => $customer->get_state()];
}
/**
* @return array
*/
public function get_recipient_as_array() : array
{
$recipient = $this->document->get_recipient();
return ['name' => $recipient->get_name(), 'street' => $recipient->get_street(), 'street2' => $recipient->get_street2(), 'postcode' => $recipient->get_postcode(), 'city' => $recipient->get_city(), 'nip' => $recipient->get_vat_number(), 'country' => $recipient->get_country(), 'phone' => $recipient->get_phone(), 'email' => $recipient->get_email(), 'state' => $recipient->get_state()];
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Decorators;
/**
* Decorates document for templates.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Decorators
*/
class TemplateDocumentDecorator extends \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Decorators\DocumentDecorator
{
/**
* Returns array of totals [ total_net_sum, total_tax_sum, total_gross_sum ].
*
* @return array
*/
public function get_totals() : array
{
$net_amount = 0;
$tax_amount = 0;
$gross_amount = 0;
foreach ($this->get_items() as $item) {
$net_amount += (float) $item['net_price_sum'];
$tax_amount += (float) $item['vat_sum'];
$gross_amount += (float) $item['total_price'];
}
return ['total_net_sum' => $net_amount, 'total_tax_sum' => $tax_amount, 'total_gross_sum' => $gross_amount];
}
/**
* @return array
*/
public function get_items_as_money() : array
{
$items = $this->document->get_items();
foreach ($items as &$item) {
$item['net_price'] = $this->currency_helper->string_as_money($item['net_price']);
$item['net_price_sum'] = $this->currency_helper->string_as_money($item['net_price_sum']);
$item['vat_sum'] = $this->currency_helper->string_as_money($item['vat_sum']);
$item['total_price'] = $this->currency_helper->string_as_money($item['total_price']);
}
return $items;
}
/**
* Returns array of tax totals [ [] => total_net_sum, total_vat_sum, total_gross_sum ].
*
* @return array
*/
public function get_totals_by_taxes() : array
{
$tax_types = [];
foreach ($this->get_items() as $item) {
if (!isset($tax_types[$item['vat_type_name']]['total_gross_sum'])) {
$tax_types[$item['vat_type_name']]['total_net_sum'] = 0;
$tax_types[$item['vat_type_name']]['total_vat_sum'] = 0;
$tax_types[$item['vat_type_name']]['total_gross_sum'] = 0;
}
$tax_types[$item['vat_type_name']]['total_net_sum'] += (float) $item['net_price_sum'];
$tax_types[$item['vat_type_name']]['total_vat_sum'] += (float) $item['vat_sum'];
$tax_types[$item['vat_type_name']]['total_gross_sum'] += (float) $item['total_price'];
}
return $tax_types;
}
/**
* @param array $data
*
* @return array
*/
public function array_to_string_as_money(array $data) : array
{
$new_data = [];
foreach ($data as $key => $value) {
if (!\is_array($value)) {
$new_data[$key] = $this->currency_helper->string_as_money($value);
} else {
$new_data[$key] = $this->array_to_string_as_money($value);
}
}
return $new_data;
}
}

View File

@@ -0,0 +1,540 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Data\DataSourceFactory;
/**
* Abstraction of Document Type Declaration.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Documents
*/
abstract class AbstractDocument implements \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document
{
const DOCUMENT_TYPE = 'invoice';
/**
* @var int
*/
private $number = 1;
/**
* @var string
*/
private $formatted_number = '';
/**
* @var string
*/
private $currency = '';
/**
* @var string
*/
private $payment_method_name = '';
/**
* @var string
*/
private $payment_method = 'topay';
/**
* @var string
*/
private $notes = '';
/**
* @var string
*/
private $user_lang = '';
/**
* @var int
*/
private $id = 0;
/**
* @var int
*/
private $order_id = 0;
/**
* @var float
*/
private $total_paid = 0;
/**
* @var string
*/
private $payment_status = '';
/**
* @var array
*/
private $items = [];
/**
* @var int
*/
private $date_of_sale = 0;
/**
* @var int
*/
private $date_of_issue = 0;
/**
* @var int
*/
private $date_of_pay = 0;
/**
* @var int
*/
private $paid_date = 0;
/**
* @var float
*/
private $total_tax = 0.0;
/**
* @var float
*/
private $total_net = 0.0;
/**
* @var float
*/
private $total_gross = 0.0;
/**
* @var float
*/
private $tax = 0.0;
/**
* @var Seller
*/
private $owner;
/**
* @var Customer
*/
private $client;
/**
* @var Recipient
*/
private $recipient;
/**
* @var string
*/
private $client_filtered_name = '';
/**
* @var float
*/
private $discount = 0.0;
/**
* @var int
*/
private $post_id = 0;
/**
* @var string
*/
private $show_order_number = 0;
/**
* @var int
*/
private $corrected_id = 0;
/**
* @var string
*/
private $is_correction = 0;
/**
* @param string $value
*/
public function set_formatted_number($value)
{
$this->formatted_number = $value;
}
/**
* @return string
*/
public function get_formatted_number()
{
return $this->formatted_number;
}
/**
* @param string $value
*/
public function set_currency($value)
{
$this->currency = $value;
}
/**
* @return string
*/
public function get_currency()
{
return $this->currency;
}
/**
* @param string $value
*/
public function set_currency_symbol($value)
{
$this->currency = $value;
}
/**
* @return string
*/
public function get_currency_symbol()
{
return $this->currency;
}
/**
* @param string $value
*/
public function set_payment_method($value)
{
$this->payment_method = $value;
}
/**
* @return string
*/
public function get_payment_method()
{
return $this->payment_method;
}
/**
* @param string $value
*/
public function set_payment_method_name($value)
{
$this->payment_method_name = $value;
}
/**
* @return string
*/
public function get_payment_method_name()
{
return $this->payment_method_name;
}
/**
* @param string $value
*/
public function set_notes($value)
{
$this->notes = $value;
}
/**
* @return string
*/
public function get_notes()
{
return $this->notes;
}
/**
* @param $value
*/
public function set_user_lang($value)
{
$this->user_lang = $value;
}
/**
* @return string
*/
public function get_user_lang()
{
return $this->user_lang;
}
/**
* @param int $id
*/
public function set_id($id)
{
$this->id = $id;
}
/**
* @return int
*/
public function get_id()
{
return $this->id;
}
/**
* @param string $value
*/
public function set_total_paid($value)
{
$this->total_paid = $value;
}
/**
* @return float
*/
public function get_total_paid()
{
return $this->total_paid;
}
/**
* @param string $value
*/
public function set_payment_status($value)
{
$this->payment_status = $value;
}
/**
* @return string
*/
public function get_payment_status()
{
return $this->payment_status;
}
/**
* @param array $items
*/
public function set_items($items)
{
$this->items = $items;
}
/**
* @return array
*/
public function get_items()
{
return $this->items;
}
/**
* @param int $number
*/
public function set_number($number)
{
$this->number = $number;
}
/**
* @return int
*/
public function get_number()
{
return $this->number;
}
/**
* @param int $value
*/
public function set_date_of_sale($value)
{
$this->date_of_sale = $value;
}
/**
* @return int
*/
public function get_date_of_sale()
{
return $this->date_of_sale;
}
/**
* @param int $value
*/
public function set_date_of_issue($value)
{
$this->date_of_issue = $value;
}
/**
* @return int
*/
public function get_date_of_issue()
{
return $this->date_of_issue;
}
/**
* @param int $value
*/
public function set_date_of_pay($value)
{
$this->date_of_pay = $value;
}
/**
* @return int
*/
public function get_date_of_pay()
{
return $this->date_of_pay;
}
/**
* @param int $value
*/
public function set_date_of_paid($value)
{
$this->paid_date = $value;
}
/**
* @return int
*/
public function get_date_of_paid()
{
return $this->paid_date;
}
/**
* @param float $value
*/
public function set_total_tax($value)
{
$this->total_tax = $value;
}
/**
* @return float
*/
public function get_total_tax()
{
return $this->total_tax;
}
/**
* @param float $value
*/
public function set_total_net($value)
{
$this->total_net = $value;
}
/**
* @return float
*/
public function get_total_net()
{
return $this->total_net;
}
/**
* @param float $value
*/
public function set_total_gross($value)
{
$this->total_gross = $value;
}
/**
* @return float
*/
public function get_total_gross()
{
return $this->total_gross;
}
/**
* @param $value
*/
public function set_tax($value)
{
$this->tax = $value;
}
/**
* @return float
*/
public function get_tax()
{
return $this->tax;
}
/**
* @param Seller $seller
*/
public function set_seller(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Seller $seller)
{
$this->owner = $seller;
}
/**
* @return Seller
*/
public function get_seller()
{
return $this->owner;
}
/**
* @param Customer $customer
*/
public function set_customer(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer $customer)
{
$this->client = $customer;
}
/**
* @return Customer
*/
public function get_customer()
{
return $this->client;
}
/**
* @param Recipient $recipient
*/
public function set_recipient(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Recipient $recipient)
{
$this->recipient = $recipient;
}
/**
* @return Recipient
*/
public function get_recipient()
{
return $this->recipient;
}
/**
* @param float $value
*/
public function set_discount($value)
{
$this->discount = $value;
}
/**
* @return float
*/
public function get_discount()
{
return $this->discount;
}
/**
* @param string $customer_name
*/
public function set_customer_filter_field($customer_name)
{
$this->client_filtered_name = $customer_name;
}
/**
* @return string
*/
public function get_customer_filter_field()
{
return $this->client_filtered_name;
}
/**
* @param string $value
*/
public function set_show_order_number($value)
{
$this->show_order_number = $value;
}
/**
* @return bool
*/
public function get_show_order_number()
{
return $this->show_order_number;
}
/**
* @param int $id
*/
public function set_order_id($id)
{
$this->order_id = $id;
}
/**
* @return int
*/
public function get_order_id()
{
return $this->order_id;
}
/**
* @param int $id
*/
public function set_corrected_id($id)
{
$this->corrected_id = $id;
}
/**
* @return int
*/
public function get_corrected_id()
{
return $this->corrected_id;
}
/**
* @param bool $is_correction
*/
public function set_is_correction($is_correction)
{
$this->is_correction = $is_correction;
}
/**
* @return int
*/
public function get_is_correction()
{
return $this->is_correction;
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents;
use Exception;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\DiscountItem;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\FeeItem;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\ItemFactory;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\ProductItem;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\ShippingItem;
class CreateDocumentItem
{
const ITEM_TYPES = [\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\ProductItem::TYPE, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\ShippingItem::TYPE, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\DiscountItem::TYPE, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\FeeItem::TYPE];
/**
* @var string
*/
private $type;
/**
* @throws Exception
*/
public function __construct(string $type)
{
if (!\in_array($type, self::ITEM_TYPES, \true)) {
throw new \Exception('Unknown item type! Choose from: ' . \implode(', ', self::ITEM_TYPES));
}
$this->type = $type;
}
/**
* @return Item
*/
private function get_item_type() : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
return (new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\ItemFactory($this->type))->get_item();
}
/**
* @param float $net_price
* @param float $vat_rate
* @param int $qty
*
* @return Item
*/
public function net_price(float $net_price, float $vat_rate, int $qty = 1) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$item = $this->get_item_type();
$item->set_qty($qty);
$item->set_net_price($net_price);
$item->set_net_price_sum($net_price * $qty);
$item->set_vat_rate($vat_rate);
$vat_sum = $vat_rate * ($net_price / 100);
$item->set_vat_sum($vat_sum * $qty);
$item->set_gross_price(($net_price + $vat_sum) * $qty);
return $item;
}
/**
* @param float $gross_price
* @param float $vat_rate
* @param int $qty
*
* @return Item
*/
public function gross_price(float $gross_price, float $vat_rate, int $qty = 1) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$item = $this->get_item_type();
$item->set_qty($qty);
$item->set_gross_price($gross_price);
$item->set_vat_rate($vat_rate);
$vat_divisor = 1 + $vat_rate / 100;
$net_price = $gross_price / $vat_divisor;
$vat_sum = $gross_price - $net_price;
$item->set_vat_sum($vat_sum * $qty);
$item->set_net_price($net_price);
$item->set_net_price_sum($net_price * $qty);
return $item;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents;
/**
* Define Invoice Document.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Documents
*/
class Invoice extends \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\AbstractDocument
{
const DOCUMENT_TYPE = 'invoice';
const META_GENERATED = '_invoice_generated';
/**
* @return string
*/
public function get_type()
{
return self::DOCUMENT_TYPE;
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items;
/**
* Discount item.
*
* This type of item can be used as product that stores total of discounted products.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Documents\Items
*/
class DiscountItem extends \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\DocumentItem
{
const TYPE = 'discount';
}

View File

@@ -0,0 +1,183 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items;
abstract class DocumentItem implements \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
const TYPE = 'item';
/**
* @var array
*/
protected $data = ['type' => 'item', 'name' => '', 'unit' => 'item', 'quantity' => 1, 'net_price' => 0.0, 'discount' => 0.0, 'net_price_sum' => 0.0, 'vat_rate' => 0.0, 'vat_sum' => 0.0, 'vat_type' => 0, 'vat_type_name' => '0%', 'vat_type_index' => 0, 'total_price' => 0.0, 'sku' => '', 'product_attributes' => [], 'item_meta' => []];
public function __construct()
{
$this->set_type(static::TYPE);
$this->data['item'] = \esc_html_x('item', 'Units Of Measure For Items In Inventory', 'flexible-invoices-woocommerce');
}
/**
* @param string $type
*
* @return $this
*/
public function set_name(string $type) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['name'] = $type;
return $this;
}
/**
* @param string $type
*
* @return $this
*/
public function set_type(string $type) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['type'] = $type;
return $this;
}
/**
* @return string
*/
public function get_type() : string
{
return $this->data['type'];
}
/**
* @param string $unit
*
* @return $this
*/
public function set_unit(string $unit) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['unit'] = $unit;
return $this;
}
/**
* @param float $quantity
*
* @return $this
*/
public function set_qty(float $quantity) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['quantity'] = $quantity;
return $this;
}
/**
* @param float $net_price
*
* @return $this
*/
public function set_net_price(float $net_price) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['net_price'] = $net_price;
return $this;
}
/**
* @param float $total_price
*
* @return $this
*/
public function set_gross_price(float $total_price) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['total_price'] = $total_price;
return $this;
}
/**
* @param float $vat_price
*
* @return $this
*/
public function set_vat_sum(float $vat_price) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['vat_sum'] = $vat_price;
return $this;
}
/**
* @param float $discount
*
* @return $this
*/
public function set_discount(float $discount) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['discount'] = $discount;
return $this;
}
/**
* @param float $net_price_sum
*
* @return $this
*/
public function set_net_price_sum(float $net_price_sum) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['net_price_sum'] = $net_price_sum;
return $this;
}
/**
* @param float $vat_rate
*
* @return $this
*/
public function set_vat_rate(float $vat_rate) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['vat_rate'] = $vat_rate;
$this->data['vat_type'] = $vat_rate;
$this->data['vat_type_name'] = $vat_rate . '%';
return $this;
}
/**
* @param string $vat_rate_name
*
* @return $this
*/
public function set_vat_rate_name(string $vat_rate_name) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['vat_type_name'] = $vat_rate_name;
return $this;
}
/**
* @param int $vat_type_index
*
* @return $this
*/
public function set_vat_type_index(int $vat_type_index) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['vat_type_index'] = $vat_type_index;
return $this;
}
/**
* @param string $sku
*
* @return $this
*/
public function set_sku(string $sku) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['sku'] = $sku;
return $this;
}
/**
* @param array $product_attributes
*
* @return $this
*/
public function set_product_attributes(array $product_attributes) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['product_attributes'] = $product_attributes;
return $this;
}
/**
* @param array $item_meta
*
* @return $this
*/
public function set_meta(array $item_meta) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['item_meta'] = $item_meta;
return $this;
}
/**
* @return array
*/
public function get() : array
{
return $this->data;
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items;
class FeeItem extends \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\DocumentItem
{
const TYPE = 'fee';
}

View File

@@ -0,0 +1,105 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items;
interface Item
{
/**
* @param string $type
*
* @return $this
*/
public function set_name(string $type) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item;
/**
* @param string $type
*
* @return $this
*/
public function set_type(string $type) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item;
/**
* @return string
*/
public function get_type() : string;
/**
* @param string $unit
*
* @return $this
*/
public function set_unit(string $unit) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item;
/**
* @param float $quantity
*
* @return $this
*/
public function set_qty(float $quantity) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item;
/**
* @param float $net_price
*
* @return $this
*/
public function set_net_price(float $net_price) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item;
/**
* @param float $total_price
*
* @return $this
*/
public function set_gross_price(float $total_price) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item;
/**
* @param float $vat_price
*
* @return $this
*/
public function set_vat_sum(float $vat_price) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item;
/**
* @param float $discount
*
* @return $this
*/
public function set_discount(float $discount) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item;
/**
* @param float $net_price_sum
*
* @return $this
*/
public function set_net_price_sum(float $net_price_sum) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item;
/**
* @param float $vat_rate
*
* @return $this
*/
public function set_vat_rate(float $vat_rate) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item;
/**
* @param float $vat_rate_name
*
* @return $this
*/
public function set_vat_rate_name(string $vat_rate_name) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item;
/**
* @param int $vat_type_index
*
* @return $this
*/
public function set_vat_type_index(int $vat_type_index) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item;
/**
* @param string $sku
*
* @return $this
*/
public function set_sku(string $sku) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item;
/**
* @param array $product_attributes
*
* @return $this
*/
public function set_product_attributes(array $product_attributes) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item;
/**
* @param array $item_meta
*
* @return $this
*/
public function set_meta(array $item_meta) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item;
/**
* @return array
*/
public function get() : array;
}

View File

@@ -0,0 +1,47 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\DiscountItem;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\DocumentItem;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\FeeItem;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\ProductItem;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\ShippingItem;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\WooProductItem;
/**
* Document item factory for WooCommerce order.
*
* @package WPDesk\Library\FlexibleInvoicesCore\WooCommerce
*/
class ItemFactory
{
/**
* @var string
*/
private $type;
/**
* @param string $type
*/
public function __construct(string $type)
{
$this->type = $type;
}
/**
* @return DocumentItem
*/
public function get_item() : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\DocumentItem
{
switch ($this->type) {
case 'shipping':
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\ShippingItem();
case 'fee':
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\FeeItem();
case 'discount':
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\DiscountItem();
case 'line_item':
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\WooProductItem();
default:
return new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\ProductItem();
}
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items;
class ProductItem extends \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\DocumentItem
{
const TYPE = 'product';
}

View File

@@ -0,0 +1,8 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items;
class ShippingItem extends \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\DocumentItem
{
const TYPE = 'shipping';
}

View File

@@ -0,0 +1,58 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items;
/**
* Define product item for WooCommerce.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Items
*/
class WooProductItem extends \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\ProductItem
{
const TYPE = 'product';
public function __construct()
{
parent::__construct();
$this->data = \array_merge($this->data, ['wc_item_type' => 'line_item', 'wc_order_item_id' => 0, 'wc_product_id' => 0, 'wc_variation_id' => 0]);
}
/**
* @param string $wc_item_type
*
* @return $this
*/
public function set_wc_item_type(string $wc_item_type = 'line_item') : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['wc_item_type'] = $wc_item_type;
return $this;
}
/**
* @param int $wc_order_item_id
*
* @return $this
*/
public function set_wc_order_item_id(int $wc_order_item_id) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['wc_order_item_id'] = $wc_order_item_id;
return $this;
}
/**
* @param int $wc_product_id
*
* @return $this
*/
public function set_wc_product_id(int $wc_product_id) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['wc_product_id'] = $wc_product_id;
return $this;
}
/**
* @param int $wc_variation_id
*
* @return $this
*/
public function set_wc_variation_id(int $wc_variation_id) : \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Documents\Items\Item
{
$this->data['wc_variation_id'] = $wc_variation_id;
return $this;
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\DocumentsMeta;
/**
* Custom meta interface.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Strategy
*/
interface CustomMeta
{
public function save();
}

View File

@@ -0,0 +1,35 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\DocumentsMeta;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Containers\MetaContainer;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\DocumentGetters;
/**
* Abstraction for retrieving custom meta for documents.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Strategy
*/
abstract class DocumentCustomMeta implements \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\DocumentsMeta\CustomMeta
{
/**
* @var DocumentGetters
*/
protected $document;
/**
* @var MetaContainer
*/
protected $meta_container;
/**
* @param DocumentGetters $document
* @param MetaContainer $meta_container
*/
public function __construct(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\DocumentGetters $document, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Containers\MetaContainer $meta_container)
{
$this->document = $document;
$this->meta_container = $meta_container;
}
/**
* @return void
*/
public abstract function save();
}

View File

@@ -0,0 +1,18 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\DocumentsMeta;
/**
* Null custom meta.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Creators
*/
class NullCustomMeta extends \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\DocumentsMeta\DocumentCustomMeta
{
/**
* @return void
*/
public function save()
{
}
}

View File

@@ -0,0 +1,114 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Email;
use Exception;
use WC_Email;
use WC_Order;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\EmailStatus;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Invoice;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WordPress\PDF;
/**
* Base email template for document emails.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Email
*/
class BaseEmail extends \WC_Email implements \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Email\DocumentEmail
{
/**
* @var string
*/
protected $download_url;
/**
* @var string
*/
protected $document_name;
public function __construct()
{
parent::__construct();
$this->template_base = \trailingslashit(__DIR__) . 'templates/';
$this->customer_email = \true;
$this->manual = \true;
}
/**
* @param string $template_base
*/
public function set_template_base(string $template_base)
{
$this->template_base = $template_base;
}
/**
* Get content HTML.
*
* @return string
*/
public function get_content_html() : string
{
return \wc_get_template_html($this->template_html, ['order' => $this->object, 'download_url' => $this->download_url, 'document_name' => $this->document_name, 'email_heading' => $this->get_heading(), 'sent_to_admin' => \false, 'plain_text' => \false, 'email' => $this->recipient], '', $this->template_base);
}
/**
* @return string
*/
public function get_content_plain() : string
{
return \wc_get_template_html($this->template_plain, ['order' => $this->object, 'download_url' => $this->download_url, 'document_name' => $this->document_name, 'email_heading' => $this->get_heading(), 'sent_to_admin' => \false, 'plain_text' => \true, 'email' => $this->recipient], '', $this->template_base);
}
/**
* Initialise Settings Form Fields
*
* @return void
*/
public function init_form_fields()
{
$this->form_fields = ['subject' => ['title' => \esc_html__('Subject', 'woocommerce'), 'type' => 'text', 'placeholder' => $this->subject, 'default' => ''], 'heading' => ['title' => \esc_html__('Email Heading', 'woocommerce'), 'type' => 'text', 'placeholder' => $this->heading, 'default' => ''], 'email_type' => ['title' => \esc_html__('Email type', 'woocommerce'), 'type' => 'select', 'description' => \esc_html__('Choose which format of email to send.', 'woocommerce'), 'default' => 'html', 'class' => 'email_type', 'options' => ['plain' => \esc_html__('Plain text', 'woocommerce'), 'html' => \esc_html__('HTML', 'woocommerce'), 'multipart' => \esc_html__('Multipart', 'woocommerce')]]];
}
/**
* @param WC_Order $order Order.
* @param Document $document Document.
* @param PDF $pdf
*
* @throws Exception Exception.
*/
public function should_send_email(\WC_Order $order, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document $document, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WordPress\PDF $pdf)
{
/**
* Fire hook before email send.
*
* @param Document $document
* @param PDF $pdf
*/
\do_action('fi/core/email/before/send', $document, $pdf);
$document_name = $document->get_formatted_number();
$download_url = \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Invoice::generate_download_url($document);
$this->object = $order;
$this->recipient = $order->get_billing_email();
$this->download_url = $download_url;
$this->document_name = $document_name;
$this->placeholders['{order_date}'] = \date(\wc_date_format(), $order->get_date_created() ? $order->get_date_created()->getTimestamp() : \strtotime(\current_time('mysql')));
$this->placeholders['{order_number}'] = $order->get_order_number();
if (!$this->get_recipient()) {
return;
}
$this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), []);
\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\EmailStatus::save($document, \true);
/**
* Fire hook after email send.
*
* @param Document $document
*/
\do_action('fi/core/email/after/send', $document);
}
/**
* Get email order items.
*
* @param WC_Order $order Order.
* @param bool $plain_text Is plain text.
*
* @return string
*/
public static function get_email_order_items(\WC_Order $order, bool $plain_text = \false) : string
{
return \wc_get_email_order_items($order, ['plain_text' => $plain_text]);
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Email;
use WC_Order;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WordPress\PDF;
/**
* @package WPDesk\Library\FlexibleInvoicesCore\Email
*/
interface DocumentEmail
{
/**
* @param WC_Order $order
* @param Document $document
* @param PDF $pdf
*
* @return void
*/
public function should_send_email(\WC_Order $order, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document $document, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WordPress\PDF $pdf);
}

View File

@@ -0,0 +1,132 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Email;
use Exception;
use WC_Order;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\EmailStatus;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Invoice;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\WooCommerce;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Infrastructure\Request;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Integration\DocumentFactory;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WooCommerce\OrderNote;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WordPress\PDF;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WordPress\Translator;
use WPDeskWCInvoicesVendor\WPDesk\PluginBuilder\Plugin\Hookable;
use function WC;
/**
* @package WPDesk\Library\FlexibleInvoicesCore\Email
*/
class EmailIntegration implements \WPDeskWCInvoicesVendor\WPDesk\PluginBuilder\Plugin\Hookable
{
/**
* @var DocumentFactory
*/
private $document_factory;
/**
* @var PDF
*/
private $pdf;
/**
* @var OrderNote
*/
private $order_note;
/**
* @param DocumentFactory $document_factory
* @param PDF $pdf
*/
public function __construct(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Integration\DocumentFactory $document_factory, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WordPress\PDF $pdf, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WooCommerce\OrderNote $order_note)
{
$this->document_factory = $document_factory;
$this->pdf = $pdf;
$this->order_note = $order_note;
}
/**
* Fire hooks.
*/
public function hooks()
{
\add_action('wp_ajax_fi_send_email', [$this, 'send_document']);
}
/**
* @return void
* @internal You should not use this directly from another application
*/
public function send_document()
{
$request = new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Infrastructure\Request();
$id = (int) $request->param('get.document_id')->get();
$nonce = $request->param('get._wpnonce')->get();
if ($id && ($nonce && \wp_verify_nonce($nonce))) {
try {
$creator = $this->document_factory->get_document_creator($id);
$document = $creator->get_document();
$client = $document->get_customer();
$order_id = $document->get_order_id();
if (empty($client->get_email()) || !\is_email($client->get_email())) {
\wp_send_json_error(['invoice_number' => '', 'msg' => \esc_html__('Email address is blank or invalid!', 'flexible-invoices-woocommerce')]);
}
$note = '';
if ($order_id) {
$order = \wc_get_order($order_id);
if ($order) {
$send = $this->send_email($order, $document, 'fi_' . $document->get_type());
} else {
$send = $this->send_manual_email($document);
}
$note = \sprintf(\esc_html__('%s was send to the customer', 'flexible-invoices-woocommerce'), $creator->get_name());
$this->order_note->add_note($order, $note);
} else {
$send = $this->send_manual_email($document);
}
if ($send) {
\wp_send_json_success(['invoice_number' => $document->get_formatted_number(), 'msg' => \esc_html__('Email was sent!', 'flexible-invoices-woocommerce'), 'email' => $client->get_email(), 'note' => $note]);
}
} catch (\Exception $e) {
\wp_send_json_error(['invoice_number' => '', 'msg' => $e->getMessage(), 'email' => '']);
}
}
\wp_send_json_error(['invoice_number' => '', 'status' => \false, 'msg' => \esc_html__('Invalid nonce or document ID', 'flexible-invoices-woocommerce'), 'email' => '']);
}
/**
* @param WC_Order $order
* @param Document $document
* @param string $email_class
*
* @return bool
*/
public function send_email(\WC_Order $order, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document $document, string $email_class) : bool
{
\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WordPress\Translator::switch_lang($document->get_user_lang());
\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WordPress\Translator::set_translate_lang($document->get_user_lang());
$mailer = \WC()->mailer();
$emails = $mailer->get_emails();
$client = $document->get_customer();
if (!empty($emails[$email_class]) && !empty($client->get_email())) {
if ($emails[$email_class] instanceof \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Email\DocumentEmail) {
$emails[$email_class]->should_send_email($order, $document, $this->pdf);
}
return \true;
}
return \false;
}
/**
* @param Document $document
*
* @return bool
*/
public function send_manual_email(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document $document) : bool
{
\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WordPress\Translator::switch_lang($document->get_user_lang());
\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WordPress\Translator::set_translate_lang($document->get_user_lang());
$mailer = \WC()->mailer();
$emails = $mailer->get_emails();
$client = $document->get_customer();
if (!empty($client->get_email())) {
$emails['fi_invoice_manual']->should_send_email($document, $this->pdf);
return \true;
}
return \false;
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Email;
/**
* Invoice email class.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Email
*/
class EmailInvoice extends \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Email\BaseEmail
{
public function __construct()
{
$this->id = 'fi_invoice';
$this->title = \esc_html__('Invoice (Flexible Invoices)', 'flexible-invoices-woocommerce');
$this->description = \esc_html__('Email with invoice (Flexible Invoices).', 'flexible-invoices-woocommerce');
$this->heading = \esc_html__('Email with invoice', 'flexible-invoices-woocommerce');
$this->subject = \esc_html__('[{site_title}] Invoice for order #{order_number}', 'flexible-invoices-woocommerce');
$this->template_html = 'emails/invoice.php';
$this->template_plain = 'emails/plain/invoice.php';
parent::__construct();
}
}

View File

@@ -0,0 +1,94 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Email;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\EmailStatus;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Invoice;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WordPress\PDF;
/**
* Invoice manual email class.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Email
*/
class EmailManualInvoice extends \WC_Email
{
/**
* @var string
*/
protected $download_url;
/**
* @var string
*/
private $document_name;
public function __construct()
{
parent::__construct();
$this->id = 'fi_invoice_manual';
$this->title = \esc_html__('Invoice Manual (Flexible Invoices)', 'flexible-invoices-woocommerce');
$this->description = \esc_html__('Email with invoice (Flexible Invoices).', 'flexible-invoices-woocommerce');
$this->heading = \esc_html__('Email with invoice', 'flexible-invoices-woocommerce');
$this->subject = \esc_html__('[{site_title}] {document_number}', 'flexible-invoices-woocommerce');
$this->template_html = 'emails/invoice-manual.php';
$this->template_plain = 'emails/plain/invoice-manual.php';
$this->template_base = \trailingslashit(__DIR__) . 'templates/';
$this->customer_email = \true;
$this->manual = \true;
}
/**
* Get content HTML.
*
* @return string
*/
public function get_content_html() : string
{
return \wc_get_template_html($this->template_html, ['order' => $this->object, 'download_url' => $this->download_url, 'document_name' => $this->document_name, 'email_heading' => $this->get_heading(), 'sent_to_admin' => \false, 'plain_text' => \false, 'email' => $this->recipient], '', $this->template_base);
}
/**
* @return string
*/
public function get_content_plain() : string
{
return \wc_get_template_html($this->template_plain, ['order' => $this->object, 'download_url' => $this->download_url, 'document_name' => $this->document_name, 'email_heading' => $this->get_heading(), 'sent_to_admin' => \false, 'plain_text' => \true, 'email' => $this->recipient], '', $this->template_base);
}
/**
* Initialise Settings Form Fields
*
* @return void
*/
public function init_form_fields()
{
$this->form_fields = ['subject' => ['title' => \esc_html__('Subject', 'woocommerce'), 'type' => 'text', 'placeholder' => $this->subject, 'default' => ''], 'heading' => ['title' => \esc_html__('Email Heading', 'woocommerce'), 'type' => 'text', 'placeholder' => $this->heading, 'default' => ''], 'email_type' => ['title' => \esc_html__('Email type', 'woocommerce'), 'type' => 'select', 'description' => \esc_html__('Choose which format of email to send.', 'woocommerce'), 'default' => 'html', 'class' => 'email_type', 'options' => ['plain' => \esc_html__('Plain text', 'woocommerce'), 'html' => \esc_html__('HTML', 'woocommerce'), 'multipart' => \esc_html__('Multipart', 'woocommerce')]]];
}
/**
* @param Document $document Document.
* @param PDF $pdf
*
* @throws \Exception Exception.
*/
public function should_send_email(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document $document, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\WordPress\PDF $pdf)
{
/**
* Fire hook before email send.
*
* @param Document $document
* @param PDF $pdf
*/
\do_action('fi/core/email/before/send', $document, $pdf);
$this->recipient = $document->get_customer()->get_email();
$this->download_url = \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Invoice::generate_download_url($document);
$this->document_name = $document->get_formatted_number();
$this->placeholders['{document_number}'] = $this->document_name;
if (!$this->get_recipient()) {
return;
}
$this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), []);
\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\EmailStatus::save($document, \true);
/**
* Fire hook after email send.
*
* @param Document $document
*/
\do_action('fi/core/email/after/send', $document);
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Email;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Integration\DocumentFactory;
use WPDeskWCInvoicesVendor\WPDesk\PluginBuilder\Plugin\Hookable;
/**
* Register email classes for WooCommerce.
*
* @package WPDesk\WooCommerceFakturownia\Email
*/
class RegisterEmails implements \WPDeskWCInvoicesVendor\WPDesk\PluginBuilder\Plugin\Hookable
{
/**
* @var DocumentFactory
*/
private $document_factory;
/**
* @param DocumentFactory $document_factory
*/
public function __construct(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Integration\DocumentFactory $document_factory)
{
$this->document_factory = $document_factory;
}
/**
* Hooks
*/
public function hooks()
{
\add_filter('woocommerce_email_classes', [$this, 'register_emails'], 11);
}
/**
* Register emails in WooCommerce.
*
* @param array $emails Emails.
*
* @return array
*/
public function register_emails(array $emails) : array
{
foreach ($this->document_factory->get_creators() as $creator) {
$emails['fi_' . $creator->get_type()] = $creator->get_email_class();
}
$emails['fi_invoice_manual'] = new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Email\EmailManualInvoice();
return $emails;
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace WPDeskWCInvoicesVendor;
/**
* Email z fakturą
*/
if (!\defined('ABSPATH')) {
exit;
}
// Exit if accessed directly
?>
<?php
\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks::woocommerce_email_header_hook($email_heading, $email);
?>
<?php
if (isset($download_url) && isset($document_name)) {
\printf(\__('Download Invoice: <a href="%s"><b>%s</b></a>', 'flexible-invoices-woocommerce'), $download_url, $document_name);
echo '<br/><br/>';
}
?>
<?php
/**
* Fires in footer section of email template.
*/
\do_action('woocommerce_email_footer');

View File

@@ -0,0 +1,116 @@
<?php
namespace WPDeskWCInvoicesVendor;
/**
* Email z fakturą
*/
if (!\defined('ABSPATH')) {
exit;
}
// Exit if accessed directly
?>
<?php
\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks::woocommerce_email_header_hook($email_heading, $email);
?>
<?php
if (isset($download_url) && isset($document_name)) {
\printf(\__('Download Invoice: <a href="%s"><b>%s</b></a>', 'flexible-invoices-woocommerce'), $download_url, $document_name);
echo '<br/><br/>';
}
?>
<h2><?php
\esc_html_e('Order', 'woocommerce') . ': ' . $order->get_order_number();
?> (<?php
\printf('<time datetime="%s">%s</time>', \date_i18n('c', \strtotime($order->get_date_created())), \date_i18n(\wc_date_format(), \strtotime($order->get_date_created())));
?>)</h2>
<table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">
<thead>
<tr>
<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php
\esc_html_e('Product', 'woocommerce');
?></th>
<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php
\esc_html_e('Quantity', 'woocommerce');
?></th>
<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php
\esc_html_e('Price', 'woocommerce');
?></th>
</tr>
</thead>
<tbody>
<?php
echo \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Email\BaseEmail::get_email_order_items($order);
?>
</tbody>
<tfoot>
<?php
if ($totals = $order->get_order_item_totals()) {
$i = 0;
foreach ($totals as $total) {
$i++;
// do not escape HTML for total items!
?><tr>
<th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php
if ($i === 1) {
echo 'border-top-width: 4px;';
}
?>"><?php
echo $total['label'];
?></th>
<td style="text-align:left; border: 1px solid #eee; <?php
if ($i === 1) {
echo 'border-top-width: 4px;';
}
?>"><?php
echo $total['value'];
?></td>
</tr><?php
}
}
?>
</tfoot>
</table>
<?php
\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks::woocommerce_email_after_order_table_hook($order, $sent_to_admin, $plain_text, $email);
\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks::woocommerce_email_order_meta_hook($order, $sent_to_admin, $plain_text, $email);
?>
<br/><br/>
<h2><?php
\esc_html_e('Customer details', 'woocommerce');
?></h2>
<?php
if ($order->get_billing_email()) {
?>
<p><strong><?php
\esc_html_e('Email', 'woocommerce');
?>: </strong> <?php
echo \esc_html($order->get_billing_email());
?></p>
<?php
}
if ($order->get_billing_phone()) {
?>
<p><strong><?php
\esc_html_e('Phone', 'woocommerce');
?>: </strong> <?php
echo \esc_html($order->get_billing_phone());
?></p>
<?php
}
?>
<?php
\wc_get_template('emails/email-addresses.php', ['order' => $order]);
?>
<?php
/**
* Fires in footer section of email template.
*/
\do_action('woocommerce_email_footer');

View File

@@ -0,0 +1,29 @@
<?php
namespace WPDeskWCInvoicesVendor;
/**
* Email z fakturą
*/
if (!\defined('ABSPATH')) {
exit;
}
// Exit if accessed directly
?>
<?php
\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks::woocommerce_email_header_hook($email_heading, $email);
?>
<?php
if (isset($download_url) && isset($document_name)) {
\printf(\__('Download Invoice: <a href="%s"><b>%s</b></a>', 'flexible-invoices-woocommerce'), $download_url, $document_name);
echo '<br/><br/>';
}
?>
<?php
/**
* Fires in footer section of email template.
*/
\do_action('woocommerce_email_footer');

View File

@@ -0,0 +1,48 @@
<?php
namespace WPDeskWCInvoicesVendor;
/**
* Email z fakturą (plain text)
*/
/**
* @var $order WC_Order
*/
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks;
if (!\defined('ABSPATH')) {
exit;
}
// Exit if accessed directly
echo $email_heading . "\n\n";
echo "****************************************************\n\n";
if (isset($download_url)) {
\printf(\__('Download Invoice: %s', 'flexible-invoices-woocommerce'), $download_url) . "\n\n";
}
echo \sprintf(\esc_html__('Order number: %s', 'woocommerce'), $order->get_order_number()) . "\n";
echo \sprintf(\esc_html__('Order date: %s', 'woocommerce'), \date_i18n(\wc_date_format(), \strtotime($order->get_date_created()))) . "\n";
\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks::woocommerce_email_order_meta_hook($order, $sent_to_admin, $plain_text, $email);
echo "\n";
echo \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Email\BaseEmail::get_email_order_items($order, \true);
echo "----------\n\n";
if ($totals = $order->get_order_item_totals()) {
foreach ($totals as $total) {
echo $total['label'] . "\t " . $total['value'] . "\n";
// do not escape HTML!
}
}
echo "\n****************************************************\n\n";
\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\Hooks::woocommerce_email_after_order_table_hook($order, $sent_to_admin, $plain_text, $email);
\esc_html_e('Your details', 'woocommerce') . "\n\n";
if ($order->get_billing_email()) {
\esc_html_e('Email', 'woocommerce');
}
?>: <?php
echo $order->get_billing_email() . "\n";
if ($order->get_billing_phone()) {
\esc_html_e('Phone', 'woocommerce');
}
?>: <?php
echo $order->get_billing_phone() . "\n";
\wc_get_template('emails/plain/email-addresses.php', ['order' => $order]);
echo "\n****************************************************\n\n";
echo \apply_filters('woocommerce_email_footer_text', \get_option('woocommerce_email_footer_text'));

View File

@@ -0,0 +1,88 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers;
/**
* Helper class for calculating totals for document items.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Helpers
*/
class CalculateTotals
{
/**
* @param array $items
*
* @return float
*/
public static function calculate_total_gross(array $items) : float
{
$total_tax_amount = 0.0;
if (\count($items) > 0) {
foreach ($items as $item) {
if (\is_array($item) && isset($item['total_price'])) {
$total_tax_amount += (float) $item['total_price'];
}
}
}
return $total_tax_amount;
}
/**
* @param array $items
*
* @return float
*/
public static function calculate_total_vat(array $items) : float
{
$total_tax_amount = 0.0;
if (\count($items) > 0) {
foreach ($items as $item) {
if (\is_array($item) && isset($item['vat_sum'])) {
$total_tax_amount += (float) $item['vat_sum'];
}
}
}
return $total_tax_amount;
}
/**
* @param array $items
*
* @return float
*/
public static function calculate_total_net(array $items) : float
{
$total_net_price = 0.0;
if (\count($items) > 0) {
foreach ($items as $item) {
if (\is_array($item) && isset($item['net_price_sum'])) {
$total_net_price += (float) $item['net_price_sum'];
}
}
}
return $total_net_price;
}
/**
* @param string|float $total_gross
* @param string|float $total_paid
*
* @return float
*/
public static function calculate_due_price($total_gross, $total_paid) : float
{
$total_gross = self::price_to_float($total_gross);
$total_paid = self::price_to_float($total_paid);
return \round($total_gross, 2) - \round($total_paid, 2);
}
/**
* @param float|string $price
*
* @return float
*/
public static function price_to_float($price) : float
{
if (\is_string($price)) {
$price = \str_replace(',', '.', $price);
return (float) $price;
}
return (float) $price;
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers;
/**
* Get country label from iso slug.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Helpers
*/
class Countries
{
/**
* @param string $slug
*
* @return string
*/
public static function get_country_label(string $slug) : string
{
if (\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\WooCommerce::is_active() && \strlen($slug) <= 3) {
$countries = \WC()->countries->get_countries();
if (isset($countries)) {
return $countries[$slug] ?? $slug;
}
}
return $slug;
}
/**
* @param string $slug
* @param string $country
*
* @return string
*/
public static function get_country_state_label(string $slug, string $country) : string
{
if (\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\WooCommerce::is_active() && \strlen($slug) <= 3) {
$states = \WC()->countries->get_states($country);
if (isset($states)) {
return $states[$slug] ?? $slug;
}
}
return $slug;
}
/**
* @param string $name
* @param string $value
* @param string $country
*
* @return string
*/
public static function generate_states_select(string $name, string $value = '', string $country = '') : string
{
if (\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\WooCommerce::is_active()) {
$states = \WC()->countries->get_states($country);
$output = '<select class="state-select2 medium hs-beacon-search" name="' . $name . '" id="customer_state" >';
foreach ($states as $state_code => $state_name) {
$output .= '<option ' . \selected($state_code, $value) . ' value="' . $state_code . '">' . $state_name . '</option>' . \PHP_EOL;
}
$output .= '</select>' . \PHP_EOL;
} else {
$output = '<input type="text" class="medium hs-beacon-search" name="' . $name . '" id="customer_state" />';
}
return $output;
}
/**
* Get filtered states.
*
* @return array
*/
public static function get_states() : array
{
$states = [];
if (\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\WooCommerce::is_active()) {
$countries_states = \WC()->countries->get_states();
foreach ($countries_states as $country_id => $country_states) {
if (!empty($country_states)) {
$states[$country_id] = $country_states;
}
}
}
return $states;
}
}

View File

@@ -0,0 +1,127 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Settings\Settings;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Configs;
/**
* Define currency settings for PDF printing.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Helpers
*/
class Currency
{
/**
* @var array
*/
private $currencies = [];
/**
* @var string
*/
private $currency_slug;
/**
* @param string $currency_slug
*/
public function __construct(string $currency_slug)
{
$this->currency_slug = $currency_slug;
$this->set_currencies_locale_from_woocommerce();
$this->set_currencies_locale_from_wordpress();
}
/**
* Prepare currencies settings from WooCommerce.
*/
private function set_currencies_locale_from_woocommerce()
{
if (\function_exists('WC')) {
$locales = (include \WC()->plugin_path() . '/i18n/locale-info.php');
foreach ($locales as $locale) {
$currency_slug = $locale['currency_code'];
$decimal_separator = $locale['decimal_sep'];
$thousand_separator = $locale['thousand_sep'];
$currency_position = $locale['currency_pos'];
$this->currencies[$currency_slug] = ['decimal_separator' => $decimal_separator, 'thousand_separator' => $thousand_separator, 'currency_position' => $currency_position, 'currency_symbol' => \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Configs\Currency::get_currency_symbol($currency_slug), 'currency' => $currency_slug];
}
}
}
/**
* Prepare currencies settings from WordPress.
*/
private function set_currencies_locale_from_wordpress()
{
$option = new \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Settings\Settings();
$currency_options = $option->get('currency');
foreach ($currency_options as $currency) {
$this->currencies[$currency['currency']]['decimal_separator'] = $currency['decimal_separator'];
$this->currencies[$currency['currency']]['thousand_separator'] = $currency['thousand_separator'];
$this->currencies[$currency['currency']]['currency_position'] = $currency['currency_position'];
$this->currencies[$currency['currency']]['currency_symbol'] = \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Configs\Currency::get_currency_symbol($currency['currency']);
$this->currencies[$currency['currency']]['currency'] = $currency['currency'];
}
}
/**
* @return array
*/
private function get_currency_settings() : array
{
$defaults = ['decimal_separator' => '.', 'thousand_separator' => '', 'currency_position' => 'right_space', 'currency_symbol' => \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Configs\Currency::get_currency_symbol($this->currency_slug), 'currency' => $this->currency_slug];
if (isset($this->currencies[$this->currency_slug])) {
return \wp_parse_args($this->currencies[$this->currency_slug], $defaults);
}
return $defaults;
}
/**
* @param float|string $amount
*
* @return string
*/
public function string_as_money($amount = 0.0) : string
{
$sign = '';
$amount = \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\CalculateTotals::price_to_float($amount);
if ($amount < 0) {
$sign = '-';
}
$currency_option = $this->get_currency_settings();
$ret = \number_format(\abs($amount), 2, $currency_option['decimal_separator'], $currency_option['thousand_separator']);
$symbol = \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Configs\Currency::get_currency_symbol($currency_option['currency']);
$currency_symbol = \apply_filters('woocommerce_currency_symbol', $symbol, $currency_option['currency']);
switch ($currency_option['currency_position']) {
case 'left':
$ret = $currency_symbol . $ret;
break;
case 'right':
$ret .= $currency_symbol;
break;
case 'left_space':
$ret = $currency_symbol . ' ' . $ret;
break;
case 'right_space':
$ret .= ' ' . $currency_symbol;
break;
}
return $sign . $ret;
}
/**
* @param array $item
*
* @return string
*/
public function discount_price(array $item) : string
{
if (isset($item['discount']) && (float) $item['discount'] > 0.0) {
return '-' . $this->string_as_money($item['discount']);
}
return $this->string_as_money($item['discount']);
}
/**
* @param string|float $value
*
* @return float
*/
public function number_format($value) : float
{
$value = \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers\CalculateTotals::price_to_float($value);
return (float) \number_format($value, 2, '.', '');
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document;
use WC_Order;
/**
* Email helper.
*
* @package WPDesk\Library\FlexibleInvoicesCore\Helpers
*/
class EmailStatus
{
/**
* @param Document $document
* @param WC_Order $order
*
* @return void
*/
public static function save(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document $document, $is_send = \false)
{
$status = $is_send ? 'yes' : 'no';
\update_post_meta($document->get_id(), '_' . $document->get_type() . '_email_send', $status);
}
/**
* @param Document $document
* @param WC_Order $order
*
* @return string
*/
public static function get(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document $document) : string
{
return (string) \get_post_meta($document->get_id(), '_' . $document->get_type() . '_email_send', \true);
}
}

View File

@@ -0,0 +1,289 @@
<?php
namespace WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesCore\Helpers;
use WC_Order;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer;
use WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document;
use WPDeskWCInvoicesVendor\WPDesk\Persistence\PersistentContainer;
class Hooks
{
/**
* @param array $users
* @param array $site_users
*
* @return array
*/
public static function signature_user_filter(array $users, array $site_users) : array
{
/**
* Filters the default signature users passed to select in general settings.
*
* @param array $users An array of prepared users.
* @param array $site_users An array of site users.
*
* @return array
* @since 1.3.5
*/
return \apply_filters('fi/core/settings/general/signature_users', $users, $site_users);
}
/**
* @param Document $document
* @param string $client_country
* @param bool $hide_vat
* @param bool $hide_vat_number
*/
public static function template_correction_after_notes(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document $document, string $client_country, bool $hide_vat, bool $hide_vat_number)
{
/**
* Fire hook after correction notes (deprecated - use fi/core/template/correction/after_notes).
*
* @param string $client_country Client country.
* @param bool $hide_vat Hide vat?.
* @param bool $hide_vat_number Hide vat number?.
* @param Document $document Document object.
*
* @deprecated
*
* @since 3.0.0
*/
\do_action('flexible_invoices_after_notes', $client_country, $hide_vat, $hide_vat_number, $document);
/**
* Fire hook after correction notes.
*
* @param Document $document Document object.
* @param string $client_country Client country.
* @param bool $hide_vat Hide vat?.
* @param bool $hide_vat_number Hide vat number?.
*
* @since 3.0.0
*/
\do_action('fi/core/template/correction/after_notes', $document, $client_country, $hide_vat, $hide_vat_number);
}
/**
* @param Document $document
* @param string $client_country
* @param bool $hide_vat
* @param bool $hide_vat_number
*/
public static function template_invoice_after_notes(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document $document, string $client_country, bool $hide_vat, bool $hide_vat_number)
{
/**
* Fire hook after invoice notes (deprecated - use fi/core/template/invoice/after_notes).
*
* @param string $client_country Client country.
* @param bool $hide_vat Hide vat?.
* @param bool $hide_vat_number Hide vat number?.
* @param Document $document Document object.
*
* @deprecated
*
* @since 3.0.0
*/
\do_action('flexible_invoices_after_notes', $client_country, $hide_vat, $hide_vat_number, $document);
/**
* Fire hook after invoice notes.
*
* @param Document $document Document object.
* @param string $client_country Client country.
* @param bool $hide_vat Hide vat?.
* @param bool $hide_vat_number Hide vat number?.
*
* @since 3.0.0
*/
\do_action('fi/core/template/invoice/after_notes', $document, $client_country, $hide_vat, $hide_vat_number);
}
/**
* @param string $output_street
* @param Customer $customer
*
* @return string
*/
public static function template_customer_street_filter(string $output_street, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer $customer) : string
{
/**
* Filters client street.
*
* @param string $output_street Customer street.
* @param Customer $customer Customer object.
*
* @since 3.0.0
*/
return \apply_filters('fi/core/template/invoice/client/street', $output_street, $customer);
}
/**
* @param PersistentContainer $settings Settings container.
*/
public static function template_custom_css_hook(\WPDeskWCInvoicesVendor\WPDesk\Persistence\PersistentContainer $settings)
{
/**
* Fires in custom CSS section.
*
* @param PersistentContainer $settings Settings.
*/
\do_action('fi/core/template/invoice/custom_css', $settings);
}
/**
* @param Document $document Document object (invoice, correction etc.)
* @param array $products Products.
* @param Customer $customer Customer object
*
* @return mixed|void
*/
public static function template_exchange_vertical_filter(\WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\Documents\Document $document, array $products, \WPDeskWCInvoicesVendor\WPDesk\Library\FlexibleInvoicesAbstracts\DocumentData\Customer $customer)
{
/**
* Filters template totals section.
*
* @param Document $document Document object (invoice, correction etc.).
* @param array $products Document products.
* @param Customer $customer Customer object.
*/
return \apply_filters('fi/core/template/invoice/exchange/vertical', '', $document, $products, $customer);
}
/**
* @param string $wpml_user_lang
*/
public static function wpml_switch_language_hook(string $wpml_user_lang)
{
/**
* WPML language switch.
*
* @param string $wpml_user_lang Current lang.
*/
\do_action('wpml_switch_language', $wpml_user_lang);
}
/**
* @param string $value
* @param string $textdomain
* @param string $id
* @param string $current_lang
*
* @return string
*/
public static function wpml_translate_single_string_filter(string $value, string $textdomain, string $id, string $current_lang) : string
{
/**
* @ignore WPML hook.
*/
return \apply_filters('wpml_translate_single_string', $value, $textdomain, $id, $current_lang);
}
/**
* @param WC_Order $order
* @param bool $sent_to_admin
* @param string $plain_text
* @param string $email
*/
public static function woocommerce_email_after_order_table_hook(\WC_Order $order, bool $sent_to_admin, string $plain_text, string $email)
{
/**
* Fires in email template.
*
* @param WC_Order $order Order.
* @param bool $sent_to_admin Sent to admin.
* @param string $plain_text Plain text,
* @param string $email Recipient email.
*/
\do_action('woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text, $email);
}
/**
* @param WC_Order $order
* @param bool $sent_to_admin
* @param string $plain_text
* @param string $email
*/
public static function woocommerce_email_order_meta_hook(\WC_Order $order, bool $sent_to_admin, string $plain_text, string $email)
{
/**
* Fires in email template.
*
* @param WC_Order $order Order.
* @param bool $sent_to_admin Sent to admin.
* @param string $plain_text Plain text,
* @param string $email Recipient email.
*/
\do_action('woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email);
}
/**
* @param bool $email_heading Sent to admin.
* @param string $email Recipient email.
*/
public static function woocommerce_email_header_hook($email_heading, string $email)
{
/**
* Fires in email template.
*
* @param string $email_heading Email heading.
* @param string $email Recipient email.
*/
\do_action('woocommerce_email_header', $email_heading, $email);
}
/**
* @param string $format Date format.
*/
public static function document_date_general_format_filter(string $format = 'Y-m-d')
{
/**
* General document date format.
*
* @param string $format Date format.
*/
return \apply_filters('fi/core/document/date/format', $format);
}
/**
* @param string $format Date format.
*/
public static function document_date_issue_format_filter(string $format = 'Y-m-d')
{
/**
* Date format for issue date.
*
* @param string $format Date format.
*
* @since 3.8.2
*/
return \apply_filters('fi/core/document/date/issue/format', $format);
}
/**
* @param string $format Date format.
*/
public static function document_date_pay_format_filter(string $format = 'Y-m-d')
{
/**
* Date format for payment date.
*
* @param string $format Date format.
*
* @since 3.8.2
*/
return \apply_filters('fi/core/document/date/payment/format', $format);
}
/**
* @param string $format Date format.
*/
public static function document_date_paid_format_filter(string $format = 'Y-m-d')
{
/**
* Date format for the date paid.
*
* @param string $format Date format.
*
* @since 3.8.2
*/
return \apply_filters('fi/core/document/date/paid/format', $format);
}
/**
* @param string $format Date format.
*/
public static function document_date_sale_format_filter(string $format = 'Y-m-d')
{
/**
* Date format for the sale date.
*
* @param string $format Date format.
*
* @since 3.8.2
*/
return \apply_filters('fi/core/document/date/sale/format', $format);
}
}

Some files were not shown because too many files have changed in this diff Show More