|
|
@ -11,15 +11,36 @@ use Illuminate\Support\Collection; |
|
|
*/ |
|
|
*/ |
|
|
class InvoiceDraftCollection |
|
|
class InvoiceDraftCollection |
|
|
{ |
|
|
{ |
|
|
|
|
|
/** |
|
|
|
|
|
* Instance of invoice draft. |
|
|
|
|
|
* |
|
|
|
|
|
* @var string |
|
|
|
|
|
*/ |
|
|
private $instance; |
|
|
private $instance; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Laravel session. |
|
|
|
|
|
* |
|
|
|
|
|
* @var \Illuminate\Session\SessionManager |
|
|
|
|
|
*/ |
|
|
private $session; |
|
|
private $session; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Create new invoice draft instance. |
|
|
|
|
|
*/ |
|
|
public function __construct() |
|
|
public function __construct() |
|
|
{ |
|
|
{ |
|
|
$this->session = session(); |
|
|
$this->session = session(); |
|
|
$this->instance('drafts'); |
|
|
$this->instance('drafts'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Set new instance name of invoice draft. |
|
|
|
|
|
* |
|
|
|
|
|
* @param string $instance Invoice draft instance name. |
|
|
|
|
|
* |
|
|
|
|
|
* @return \App\Services\InvoiceDrafts\InvoiceDraft |
|
|
|
|
|
*/ |
|
|
public function instance($instance = null) |
|
|
public function instance($instance = null) |
|
|
{ |
|
|
{ |
|
|
$instance = $instance ?: 'drafts'; |
|
|
$instance = $instance ?: 'drafts'; |
|
|
@ -29,11 +50,21 @@ class InvoiceDraftCollection |
|
|
return $this; |
|
|
return $this; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Get instance name of current invoice draft. |
|
|
|
|
|
* |
|
|
|
|
|
* @return string |
|
|
|
|
|
*/ |
|
|
public function currentInstance() |
|
|
public function currentInstance() |
|
|
{ |
|
|
{ |
|
|
return str_replace('invoices.', '', $this->instance); |
|
|
return str_replace('invoices.', '', $this->instance); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Add new invoice draft. |
|
|
|
|
|
* |
|
|
|
|
|
* @param \App\Services\InvoiceDrafts\InvoiceDraft $draft Invoice draft. |
|
|
|
|
|
*/ |
|
|
public function add(InvoiceDraft $draft) |
|
|
public function add(InvoiceDraft $draft) |
|
|
{ |
|
|
{ |
|
|
$content = $this->getContent(); |
|
|
$content = $this->getContent(); |
|
|
@ -45,6 +76,13 @@ class InvoiceDraftCollection |
|
|
return $draft; |
|
|
return $draft; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Get an invoice draft. |
|
|
|
|
|
* |
|
|
|
|
|
* @param string $draftKey The invoice draft key. |
|
|
|
|
|
* |
|
|
|
|
|
* @return null|\App\Services\InvoiceDrafts\InvoiceDraft |
|
|
|
|
|
*/ |
|
|
public function get($draftKey) |
|
|
public function get($draftKey) |
|
|
{ |
|
|
{ |
|
|
$content = $this->getContent(); |
|
|
$content = $this->getContent(); |
|
|
@ -53,6 +91,14 @@ class InvoiceDraftCollection |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Update invoice draft attribute. |
|
|
|
|
|
* |
|
|
|
|
|
* @param string $draftKey Invoice draft key. |
|
|
|
|
|
* @param array $draftAttributes Invoice draft attribute to be updated. |
|
|
|
|
|
* |
|
|
|
|
|
* @return \App\Services\InvoiceDrafts\InvoiceDraft |
|
|
|
|
|
*/ |
|
|
public function updateDraftAttributes($draftKey, $draftAttributes) |
|
|
public function updateDraftAttributes($draftKey, $draftAttributes) |
|
|
{ |
|
|
{ |
|
|
$content = $this->getContent(); |
|
|
$content = $this->getContent(); |
|
|
@ -67,6 +113,13 @@ class InvoiceDraftCollection |
|
|
return $content[$draftKey]; |
|
|
return $content[$draftKey]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Empty out an invoice draft items. |
|
|
|
|
|
* |
|
|
|
|
|
* @param string $draftKey Invoice draft key. |
|
|
|
|
|
* |
|
|
|
|
|
* @return void |
|
|
|
|
|
*/ |
|
|
public function emptyDraft($draftKey) |
|
|
public function emptyDraft($draftKey) |
|
|
{ |
|
|
{ |
|
|
$content = $this->getContent(); |
|
|
$content = $this->getContent(); |
|
|
@ -74,6 +127,13 @@ class InvoiceDraftCollection |
|
|
$this->session->put($this->instance, $content); |
|
|
$this->session->put($this->instance, $content); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Remove an invocie draft. |
|
|
|
|
|
* |
|
|
|
|
|
* @param string $draftKey Invoice draft key. |
|
|
|
|
|
* |
|
|
|
|
|
* @return void |
|
|
|
|
|
*/ |
|
|
public function removeDraft($draftKey) |
|
|
public function removeDraft($draftKey) |
|
|
{ |
|
|
{ |
|
|
$content = $this->getContent(); |
|
|
$content = $this->getContent(); |
|
|
@ -81,11 +141,21 @@ class InvoiceDraftCollection |
|
|
$this->session->put($this->instance, $content); |
|
|
$this->session->put($this->instance, $content); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Get invoice draft collection content. |
|
|
|
|
|
* |
|
|
|
|
|
* @return \Illuminate\Support\Collection |
|
|
|
|
|
*/ |
|
|
public function content() |
|
|
public function content() |
|
|
{ |
|
|
{ |
|
|
return $this->getContent(); |
|
|
return $this->getContent(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Get invoice draft collection content. |
|
|
|
|
|
* |
|
|
|
|
|
* @return \Illuminate\Support\Collection |
|
|
|
|
|
*/ |
|
|
protected function getContent() |
|
|
protected function getContent() |
|
|
{ |
|
|
{ |
|
|
$content = $this->session->has($this->instance) ? $this->session->get($this->instance) : collect([]); |
|
|
$content = $this->session->has($this->instance) ? $this->session->get($this->instance) : collect([]); |
|
|
@ -93,16 +163,34 @@ class InvoiceDraftCollection |
|
|
return $content; |
|
|
return $content; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Get invoice draft keys collection. |
|
|
|
|
|
* |
|
|
|
|
|
* @return \Illuminate\Support\Collection Collection of keys. |
|
|
|
|
|
*/ |
|
|
public function keys() |
|
|
public function keys() |
|
|
{ |
|
|
{ |
|
|
return $this->getContent()->keys(); |
|
|
return $this->getContent()->keys(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Destroy an invoice draft. |
|
|
|
|
|
* |
|
|
|
|
|
* @return void |
|
|
|
|
|
*/ |
|
|
public function destroy() |
|
|
public function destroy() |
|
|
{ |
|
|
{ |
|
|
$this->session->remove($this->instance); |
|
|
$this->session->remove($this->instance); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Add an item to an invoice draft. |
|
|
|
|
|
* |
|
|
|
|
|
* @param string $draftKey Invoice draft key. |
|
|
|
|
|
* @param \App\Services\InvoiceDrafts\Item $item Invoice item. |
|
|
|
|
|
* |
|
|
|
|
|
* @return \App\Services\InvoiceDrafts\Item. |
|
|
|
|
|
*/ |
|
|
public function addItemToDraft($draftKey, Item $item) |
|
|
public function addItemToDraft($draftKey, Item $item) |
|
|
{ |
|
|
{ |
|
|
$content = $this->getContent(); |
|
|
$content = $this->getContent(); |
|
|
@ -113,6 +201,15 @@ class InvoiceDraftCollection |
|
|
return $item; |
|
|
return $item; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Update invoice draft item attributes. |
|
|
|
|
|
* |
|
|
|
|
|
* @param string $draftKey Invoice draft key. |
|
|
|
|
|
* @param string $itemKey Invoice item key. |
|
|
|
|
|
* @param array $newItemData Array of item attribute. |
|
|
|
|
|
* |
|
|
|
|
|
* @return void |
|
|
|
|
|
*/ |
|
|
public function updateDraftItem($draftKey, $itemKey, $newItemData) |
|
|
public function updateDraftItem($draftKey, $itemKey, $newItemData) |
|
|
{ |
|
|
{ |
|
|
$content = $this->getContent(); |
|
|
$content = $this->getContent(); |
|
|
@ -121,6 +218,14 @@ class InvoiceDraftCollection |
|
|
$this->session->put($this->instance, $content); |
|
|
$this->session->put($this->instance, $content); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Remove an invoice draft item. |
|
|
|
|
|
* |
|
|
|
|
|
* @param string $draftKey Invoice draft key. |
|
|
|
|
|
* @param string $itemKey Invoice item key. |
|
|
|
|
|
* |
|
|
|
|
|
* @return void |
|
|
|
|
|
*/ |
|
|
public function removeItemFromDraft($draftKey, $itemKey) |
|
|
public function removeItemFromDraft($draftKey, $itemKey) |
|
|
{ |
|
|
{ |
|
|
$content = $this->getContent(); |
|
|
$content = $this->getContent(); |
|
|
@ -129,16 +234,31 @@ class InvoiceDraftCollection |
|
|
$this->session->put($this->instance, $content); |
|
|
$this->session->put($this->instance, $content); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Get invoice drafts count. |
|
|
|
|
|
* |
|
|
|
|
|
* @return int |
|
|
|
|
|
*/ |
|
|
public function count() |
|
|
public function count() |
|
|
{ |
|
|
{ |
|
|
return $this->getContent()->count(); |
|
|
return $this->getContent()->count(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Check if current invoice draft is empty. |
|
|
|
|
|
* |
|
|
|
|
|
* @return boolean |
|
|
|
|
|
*/ |
|
|
public function isEmpty() |
|
|
public function isEmpty() |
|
|
{ |
|
|
{ |
|
|
return $this->count() == 0; |
|
|
return $this->count() == 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Check if current invoice draft has content. |
|
|
|
|
|
* |
|
|
|
|
|
* @return boolean |
|
|
|
|
|
*/ |
|
|
public function hasContent() |
|
|
public function hasContent() |
|
|
{ |
|
|
{ |
|
|
return !$this->isEmpty(); |
|
|
return !$this->isEmpty(); |
|
|
|