當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Invitation::scope方法代碼示例

本文整理匯總了PHP中app\models\Invitation::scope方法的典型用法代碼示例。如果您正苦於以下問題:PHP Invitation::scope方法的具體用法?PHP Invitation::scope怎麽用?PHP Invitation::scope使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\models\Invitation的用法示例。


在下文中一共展示了Invitation::scope方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: save

 public function save($data)
 {
     if (isset($data['client'])) {
         $client = $this->clientRepo->save($data['client']);
         $data['client_id'] = $client->id;
     }
     $invoice = $this->invoiceRepo->save($data);
     $client = $invoice->client;
     $client->load('contacts');
     $sendInvoiceIds = [];
     foreach ($client->contacts as $contact) {
         if ($contact->send_invoice || count($client->contacts) == 1) {
             $sendInvoiceIds[] = $contact->id;
         }
     }
     foreach ($client->contacts as $contact) {
         $invitation = Invitation::scope()->whereContactId($contact->id)->whereInvoiceId($invoice->id)->first();
         if (in_array($contact->id, $sendInvoiceIds) && !$invitation) {
             $invitation = Invitation::createNew();
             $invitation->invoice_id = $invoice->id;
             $invitation->contact_id = $contact->id;
             $invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
             $invitation->save();
         } elseif (!in_array($contact->id, $sendInvoiceIds) && $invitation) {
             $invitation->delete();
         }
     }
     return $invoice;
 }
開發者ID:lingxuan630,項目名稱:invoiceninja,代碼行數:29,代碼來源:InvoiceService.php

示例2: save

 /**
  * @param array $data
  * @param Invoice|null $invoice
  * @return \App\Models\Invoice|Invoice|mixed
  */
 public function save(array $data, Invoice $invoice = null)
 {
     if (isset($data['client'])) {
         $canSaveClient = false;
         $canViewClient = false;
         $clientPublicId = array_get($data, 'client.public_id') ?: array_get($data, 'client.id');
         if (empty($clientPublicId) || $clientPublicId == '-1') {
             $canSaveClient = Auth::user()->can('create', ENTITY_CLIENT);
         } else {
             $client = Client::scope($clientPublicId)->first();
             $canSaveClient = Auth::user()->can('edit', $client);
             $canViewClient = Auth::user()->can('view', $client);
         }
         if ($canSaveClient) {
             $client = $this->clientRepo->save($data['client']);
         }
         if ($canSaveClient || $canViewClient) {
             $data['client_id'] = $client->id;
         }
     }
     $invoice = $this->invoiceRepo->save($data, $invoice);
     $client = $invoice->client;
     $client->load('contacts');
     $sendInvoiceIds = [];
     foreach ($client->contacts as $contact) {
         if ($contact->send_invoice || count($client->contacts) == 1) {
             $sendInvoiceIds[] = $contact->id;
         }
     }
     foreach ($client->contacts as $contact) {
         $invitation = Invitation::scope()->whereContactId($contact->id)->whereInvoiceId($invoice->id)->first();
         if (in_array($contact->id, $sendInvoiceIds) && !$invitation) {
             $invitation = Invitation::createNew();
             $invitation->invoice_id = $invoice->id;
             $invitation->contact_id = $contact->id;
             $invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
             $invitation->save();
         } elseif (!in_array($contact->id, $sendInvoiceIds) && $invitation) {
             $invitation->delete();
         }
     }
     return $invoice;
 }
開發者ID:rafaelsisweb,項目名稱:invoice-ninja,代碼行數:48,代碼來源:InvoiceService.php

示例3: save

 public function save($data, $checkSubPermissions = false)
 {
     if (isset($data['client'])) {
         $can_save_client = !$checkSubPermissions;
         if (!$can_save_client) {
             if (empty($data['client']['public_id']) || $data['client']['public_id'] == '-1') {
                 $can_save_client = Client::canCreate();
             } else {
                 $can_save_client = Client::wherePublicId($data['client']['public_id'])->first()->canEdit();
             }
         }
         if ($can_save_client) {
             $client = $this->clientRepo->save($data['client']);
             $data['client_id'] = $client->id;
         }
     }
     $invoice = $this->invoiceRepo->save($data, $checkSubPermissions);
     $client = $invoice->client;
     $client->load('contacts');
     $sendInvoiceIds = [];
     foreach ($client->contacts as $contact) {
         if ($contact->send_invoice || count($client->contacts) == 1) {
             $sendInvoiceIds[] = $contact->id;
         }
     }
     foreach ($client->contacts as $contact) {
         $invitation = Invitation::scope()->whereContactId($contact->id)->whereInvoiceId($invoice->id)->first();
         if (in_array($contact->id, $sendInvoiceIds) && !$invitation) {
             $invitation = Invitation::createNew();
             $invitation->invoice_id = $invoice->id;
             $invitation->contact_id = $contact->id;
             $invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
             $invitation->save();
         } elseif (!in_array($contact->id, $sendInvoiceIds) && $invitation) {
             $invitation->delete();
         }
     }
     return $invoice;
 }
開發者ID:sseshachala,項目名稱:invoiceninja,代碼行數:39,代碼來源:InvoiceService.php

示例4: saveInvoice

 private function saveInvoice($publicId, $input, $entityType)
 {
     $invoice = $input->invoice;
     $this->taxRateRepo->save($input->tax_rates);
     $clientData = (array) $invoice->client;
     $client = $this->clientRepo->save($invoice->client->public_id, $clientData);
     $invoiceData = (array) $invoice;
     $invoiceData['client_id'] = $client->id;
     $invoice = $this->invoiceRepo->save($publicId, $invoiceData, $entityType);
     $account = Auth::user()->account;
     if ($account->invoice_taxes != $input->invoice_taxes || $account->invoice_item_taxes != $input->invoice_item_taxes || $account->invoice_design_id != $input->invoice->invoice_design_id || $account->show_item_taxes != $input->show_item_taxes) {
         $account->invoice_taxes = $input->invoice_taxes;
         $account->invoice_item_taxes = $input->invoice_item_taxes;
         $account->invoice_design_id = $input->invoice->invoice_design_id;
         $account->show_item_taxes = $input->show_item_taxes;
         $account->save();
     }
     $client->load('contacts');
     $sendInvoiceIds = [];
     foreach ($client->contacts as $contact) {
         if ($contact->send_invoice || count($client->contacts) == 1) {
             $sendInvoiceIds[] = $contact->id;
         }
     }
     foreach ($client->contacts as $contact) {
         $invitation = Invitation::scope()->whereContactId($contact->id)->whereInvoiceId($invoice->id)->first();
         if (in_array($contact->id, $sendInvoiceIds) && !$invitation) {
             $invitation = Invitation::createNew();
             $invitation->invoice_id = $invoice->id;
             $invitation->contact_id = $contact->id;
             $invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
             $invitation->save();
         } elseif (!in_array($contact->id, $sendInvoiceIds) && $invitation) {
             $invitation->delete();
         }
     }
     return $invoice;
 }
開發者ID:nafrente,項目名稱:invoice-ninja,代碼行數:38,代碼來源:InvoiceController.php

示例5: save

 private function save($publicId = null)
 {
     $action = Input::get('action');
     $entityType = Input::get('entityType');
     if (in_array($action, ['archive', 'delete', 'mark', 'restore'])) {
         return InvoiceController::bulk($entityType);
     }
     $input = json_decode(Input::get('data'));
     $invoice = $input->invoice;
     if ($errors = $this->invoiceRepo->getErrors($invoice)) {
         Session::flash('error', trans('texts.invoice_error'));
         return Redirect::to("{$entityType}s/create")->withInput()->withErrors($errors);
     } else {
         $this->taxRateRepo->save($input->tax_rates);
         $clientData = (array) $invoice->client;
         $client = $this->clientRepo->save($invoice->client->public_id, $clientData);
         $invoiceData = (array) $invoice;
         $invoiceData['client_id'] = $client->id;
         $invoice = $this->invoiceRepo->save($publicId, $invoiceData, $entityType);
         $account = Auth::user()->account;
         if ($account->invoice_taxes != $input->invoice_taxes || $account->invoice_item_taxes != $input->invoice_item_taxes || $account->invoice_design_id != $input->invoice->invoice_design_id) {
             $account->invoice_taxes = $input->invoice_taxes;
             $account->invoice_item_taxes = $input->invoice_item_taxes;
             $account->invoice_design_id = $input->invoice->invoice_design_id;
             $account->save();
         }
         $client->load('contacts');
         $sendInvoiceIds = [];
         foreach ($client->contacts as $contact) {
             if ($contact->send_invoice || count($client->contacts) == 1) {
                 $sendInvoiceIds[] = $contact->id;
             }
         }
         foreach ($client->contacts as $contact) {
             $invitation = Invitation::scope()->whereContactId($contact->id)->whereInvoiceId($invoice->id)->first();
             if (in_array($contact->id, $sendInvoiceIds) && !$invitation) {
                 $invitation = Invitation::createNew();
                 $invitation->invoice_id = $invoice->id;
                 $invitation->contact_id = $contact->id;
                 $invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
                 $invitation->save();
             } elseif (!in_array($contact->id, $sendInvoiceIds) && $invitation) {
                 $invitation->delete();
             }
         }
         $message = trans($publicId ? "texts.updated_{$entityType}" : "texts.created_{$entityType}");
         if ($input->invoice->client->public_id == '-1') {
             $message = $message . ' ' . trans('texts.and_created_client');
             $url = URL::to('clients/' . $client->public_id);
             Utils::trackViewed($client->getDisplayName(), ENTITY_CLIENT, $url);
         }
         $pdfUpload = Input::get('pdfupload');
         if (!empty($pdfUpload) && strpos($pdfUpload, 'data:application/pdf;base64,') === 0) {
             $this->storePDF(Input::get('pdfupload'), $invoice);
         }
         if ($action == 'clone') {
             return $this->cloneInvoice($publicId);
         } elseif ($action == 'convert') {
             return $this->convertQuote($publicId);
         } elseif ($action == 'email') {
             if (Auth::user()->confirmed && !Auth::user()->isDemo()) {
                 if ($invoice->is_recurring) {
                     if ($invoice->shouldSendToday()) {
                         $invoice = $this->invoiceRepo->createRecurringInvoice($invoice);
                         $response = $this->mailer->sendInvoice($invoice);
                     } else {
                         $response = trans('texts.recurring_too_soon');
                     }
                 } else {
                     $response = $this->mailer->sendInvoice($invoice);
                 }
                 if ($response === true) {
                     $message = trans("texts.emailed_{$entityType}");
                     Session::flash('message', $message);
                 } else {
                     Session::flash('error', $response);
                 }
             } else {
                 $errorMessage = trans(Auth::user()->registered ? 'texts.confirmation_required' : 'texts.registration_required');
                 Session::flash('error', $errorMessage);
                 Session::flash('message', $message);
             }
         } else {
             Session::flash('message', $message);
         }
         $url = "{$entityType}s/" . $invoice->public_id . '/edit';
         return Redirect::to($url);
     }
 }
開發者ID:jgyaipl,項目名稱:invoice-ninja,代碼行數:89,代碼來源:InvoiceController.php


注:本文中的app\models\Invitation::scope方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。