invoiceninja/app/Ninja/Repositories/VendorContactRepository.php

30 lines
787 B
PHP
Raw Permalink Normal View History

2017-01-30 21:40:43 +02:00
<?php
namespace App\Ninja\Repositories;
2016-01-06 15:23:58 +01:00
2016-07-21 15:35:23 +03:00
use App\Models\Vendor;
2016-01-06 15:23:58 +01:00
use App\Models\VendorContact;
2016-07-21 15:35:23 +03:00
// vendor
2016-01-06 15:23:58 +01:00
class VendorContactRepository extends BaseRepository
{
2016-07-21 15:35:23 +03:00
public function save($data)
2016-01-06 15:23:58 +01:00
{
$publicId = isset($data['public_id']) ? $data['public_id'] : false;
2018-06-19 22:46:35 +03:00
if (! $publicId || intval($publicId) < 0) {
2016-01-06 15:23:58 +01:00
$contact = VendorContact::createNew();
2016-07-21 15:35:23 +03: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 18:05:31 +02:00
}