2018-11-22 22:12:41 +11:00
< ? php
2019-05-11 13:32:07 +10:00
/**
* Invoice Ninja ( https :// invoiceninja . com )
*
* @ link https :// github . com / invoiceninja / invoiceninja source repository
*
* @ copyright Copyright ( c ) 2019. Invoice Ninja LLC ( https :// invoiceninja . com )
*
* @ license https :// opensource . org / licenses / AAL
*/
2018-11-22 22:12:41 +11:00
namespace App\Repositories ;
2018-11-27 17:59:16 +11:00
use App\Models\Client ;
2018-11-22 22:12:41 +11:00
use App\Repositories\ClientContactRepository ;
2018-11-27 17:59:16 +11:00
use Illuminate\Http\Request ;
2018-11-22 22:12:41 +11:00
/**
2019-05-10 16:08:33 +10:00
* ClientRepository
2018-11-22 22:12:41 +11:00
*/
class ClientRepository extends BaseRepository
{
2019-04-16 15:28:30 +10:00
/**
* @ var ClientContactRepository
*/
2019-05-10 16:08:33 +10:00
protected $contact_repo ;
2019-04-16 15:28:30 +10:00
/**
* ClientController constructor .
2019-05-10 16:08:33 +10:00
* @ param ClientContactRepository $contact_repo
2019-04-16 15:28:30 +10:00
*/
2019-05-10 16:08:33 +10:00
public function __construct ( ClientContactRepository $contact_repo )
2019-04-16 15:28:30 +10:00
{
2019-05-10 16:08:33 +10:00
$this -> contact_repo = $contact_repo ;
2019-04-16 15:28:30 +10:00
}
2019-05-10 16:08:33 +10:00
/**
* Gets the class name .
*
* @ return string The class name .
*/
2019-01-19 21:35:21 +11:00
public function getClassName ()
{
2019-05-10 16:08:33 +10:00
2019-01-19 21:35:21 +11:00
return Client :: class ;
2019-05-10 16:08:33 +10:00
2019-01-19 21:35:21 +11:00
}
2019-05-10 16:08:33 +10:00
/**
* Saves the client and its contacts
*
* @ param array $data The data
* @ param \App\Models\Client $client The client
*
* @ return Client | \App\Models\Client | null Client Object
*/
public function save ( array $data , Client $client ) : ? Client
2018-11-22 22:12:41 +11:00
{
2019-05-10 16:08:33 +10:00
$client -> fill ( $data );
$client -> save ();
$client -> id_number = $client -> getNextNumber ( $client ); //todo write tests for this and make sure that custom client numbers also works as expected from here
2018-11-27 17:59:16 +11:00
$client -> save ();
2018-11-22 22:12:41 +11:00
2019-05-10 16:08:33 +10:00
if ( isset ( $data [ 'contacts' ]))
$contacts = $this -> contact_repo -> save ( $data [ 'contacts' ], $client );
2019-04-16 15:28:30 +10:00
2019-01-27 08:24:16 +11:00
return $client ;
2019-05-10 16:08:33 +10:00
2018-11-22 22:12:41 +11:00
}
}