2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Ninja\Repositories;
|
2016-01-06 15:23:58 +01:00
|
|
|
|
2016-07-21 14:35:23 +02:00
|
|
|
use App\Models\Vendor;
|
2016-01-06 15:23:58 +01:00
|
|
|
use App\Models\VendorContact;
|
2016-07-03 18:11:58 +02:00
|
|
|
|
2016-07-21 14:35:23 +02:00
|
|
|
// vendor
|
2016-01-06 15:23:58 +01:00
|
|
|
class VendorContactRepository extends BaseRepository
|
|
|
|
{
|
2016-07-21 14:35:23 +02:00
|
|
|
public function save($data)
|
2016-01-06 15:23:58 +01:00
|
|
|
{
|
|
|
|
$publicId = isset($data['public_id']) ? $data['public_id'] : false;
|
|
|
|
|
2017-01-30 20:40:43 +01:00
|
|
|
if (! $publicId || $publicId == '-1') {
|
2016-01-06 15:23:58 +01:00
|
|
|
$contact = VendorContact::createNew();
|
2016-07-21 14:35:23 +02:00
|
|
|
//$contact->send_invoice = true;
|
2016-01-06 15:23:58 +01:00
|
|
|
$contact->vendor_id = $data['vendor_id'];
|
|
|
|
$contact->is_primary = VendorContact::scope()->where('vendor_id', '=', $contact->vendor_id)->count() == 0;
|
|
|
|
} else {
|
|
|
|
$contact = VendorContact::scope($publicId)->firstOrFail();
|
|
|
|
}
|
|
|
|
|
|
|
|
$contact->fill($data);
|
|
|
|
$contact->save();
|
|
|
|
|
|
|
|
return $contact;
|
|
|
|
}
|
2017-01-30 17:05:31 +01:00
|
|
|
}
|