当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::createNew方法代码示例

本文整理汇总了PHP中app\models\Client::createNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::createNew方法的具体用法?PHP Client::createNew怎么用?PHP Client::createNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Client的用法示例。


在下文中一共展示了Client::createNew方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 public function save($data)
 {
     $publicId = isset($data['public_id']) ? $data['public_id'] : false;
     if (!$publicId || $publicId == '-1') {
         $client = Client::createNew();
     } else {
         $client = Client::scope($publicId)->with('contacts')->firstOrFail();
     }
     $client->fill($data);
     $client->save();
     /*
     if ( ! isset($data['contact']) && ! isset($data['contacts'])) {
         return $client;
     }
     */
     $first = true;
     $contacts = isset($data['contact']) ? [$data['contact']] : $data['contacts'];
     $contactIds = [];
     foreach ($contacts as $contact) {
         $contact = $client->addContact($contact, $first);
         $contactIds[] = $contact->public_id;
         $first = false;
     }
     foreach ($client->contacts as $contact) {
         if (!in_array($contact->public_id, $contactIds)) {
             $contact->delete();
         }
     }
     return $client;
 }
开发者ID:CyBeRoni,项目名称:invoiceninja,代码行数:30,代码来源:ClientRepository.php

示例2: save

 public function save($data, $client = null)
 {
     $publicId = isset($data['public_id']) ? $data['public_id'] : false;
     if ($client) {
         // do nothing
     } elseif (!$publicId || $publicId == '-1') {
         $client = Client::createNew();
     } else {
         $client = Client::scope($publicId)->with('contacts')->firstOrFail();
     }
     if ($client->is_deleted) {
         return $client;
     }
     // convert currency code to id
     if (isset($data['currency_code'])) {
         $currencyCode = strtolower($data['currency_code']);
         $currency = Cache::get('currencies')->filter(function ($item) use($currencyCode) {
             return strtolower($item->code) == $currencyCode;
         })->first();
         if ($currency) {
             $data['currency_id'] = $currency->id;
         }
     }
     $client->fill($data);
     $client->save();
     /*
     if ( ! isset($data['contact']) && ! isset($data['contacts'])) {
         return $client;
     }
     */
     $first = true;
     $contacts = isset($data['contact']) ? [$data['contact']] : $data['contacts'];
     $contactIds = [];
     // If the primary is set ensure it's listed first
     usort($contacts, function ($left, $right) {
         if (isset($right['is_primary']) && isset($left['is_primary'])) {
             return $right['is_primary'] - $left['is_primary'];
         } else {
             return 0;
         }
     });
     foreach ($contacts as $contact) {
         $contact = $client->addContact($contact, $first);
         $contactIds[] = $contact->public_id;
         $first = false;
     }
     if (!$client->wasRecentlyCreated) {
         foreach ($client->contacts as $contact) {
             if (!in_array($contact->public_id, $contactIds)) {
                 $contact->delete();
             }
         }
     }
     if (!$publicId || $publicId == '-1') {
         event(new ClientWasCreated($client));
     } else {
         event(new ClientWasUpdated($client));
     }
     return $client;
 }
开发者ID:hillelcoren,项目名称:invoice-ninja,代码行数:60,代码来源:ClientRepository.php

示例3: save

 public function save($data)
 {
     $publicId = isset($data['public_id']) ? $data['public_id'] : false;
     if (!$publicId || $publicId == '-1') {
         $client = Client::createNew();
     } else {
         $client = Client::scope($publicId)->with('contacts')->firstOrFail();
     }
     // convert currency code to id
     if (isset($data['currency_code'])) {
         $currencyCode = strtolower($data['currency_code']);
         $currency = Cache::get('currencies')->filter(function ($item) use($currencyCode) {
             return strtolower($item->code) == $currencyCode;
         })->first();
         if ($currency) {
             $data['currency_id'] = $currency->id;
         }
     }
     $client->fill($data);
     $client->save();
     /*
     if ( ! isset($data['contact']) && ! isset($data['contacts'])) {
         return $client;
     }
     */
     $first = true;
     $contacts = isset($data['contact']) ? [$data['contact']] : $data['contacts'];
     $contactIds = [];
     foreach ($contacts as $contact) {
         $contact = $client->addContact($contact, $first);
         $contactIds[] = $contact->public_id;
         $first = false;
     }
     foreach ($client->contacts as $contact) {
         if (!in_array($contact->public_id, $contactIds)) {
             $contact->delete();
         }
     }
     if (!$publicId || $publicId == '-1') {
         event(new ClientWasCreated($client));
     } else {
         event(new ClientWasUpdated($client));
     }
     return $client;
 }
开发者ID:sseshachala,项目名称:invoiceninja,代码行数:45,代码来源:ClientRepository.php

示例4: initialize

 public function initialize()
 {
     $account = $this->account;
     $this->invoice_date = Utils::today();
     $this->start_date = Utils::today();
     $this->invoice_design_id = $account->invoice_design_id;
     if (!$this->invoice_number) {
         if ($this->is_recurring) {
             $this->invoice_number = microtime(true);
         } else {
             if ($account->hasClientNumberPattern($this) && !$this->client) {
                 // do nothing, we don't yet know the value
             } else {
                 $this->invoice_number = $account->getNextInvoiceNumber($this);
             }
         }
     }
     if (!$this->client) {
         $this->client = Client::createNew($this);
         $this->client->public_id = 0;
     }
 }
开发者ID:unedeplus,项目名称:invoice-ninja,代码行数:22,代码来源:Invoice.php

示例5: createInvoice

 public function createInvoice($entityType, $clientId = null)
 {
     $invoice = Invoice::createNew();
     $invoice->invoice_date = Utils::today();
     $invoice->start_date = Utils::today();
     $invoice->invoice_design_id = $this->invoice_design_id;
     $invoice->client_id = $clientId;
     if ($entityType === ENTITY_RECURRING_INVOICE) {
         $invoice->invoice_number = microtime(true);
         $invoice->is_recurring = true;
     } else {
         if ($entityType == ENTITY_QUOTE) {
             $invoice->is_quote = true;
         }
         if ($this->hasClientNumberPattern($invoice) && !$clientId) {
             // do nothing, we don't yet know the value
         } else {
             $invoice->invoice_number = $this->getNextInvoiceNumber($invoice);
         }
     }
     if (!$clientId) {
         $invoice->client = Client::createNew();
         $invoice->client->public_id = 0;
     }
     return $invoice;
 }
开发者ID:vegardwikeby,项目名称:invoice-ninja,代码行数:26,代码来源:Account.php

示例6: importFile

 private function importFile()
 {
     $data = Session::get('data');
     Session::forget('data');
     $map = Input::get('map');
     $count = 0;
     $hasHeaders = Input::get('header_checkbox');
     $countries = Cache::get('countries');
     $countryMap = [];
     foreach ($countries as $country) {
         $countryMap[strtolower($country->name)] = $country->id;
     }
     foreach ($data as $row) {
         if ($hasHeaders) {
             $hasHeaders = false;
             continue;
         }
         $client = Client::createNew();
         $contact = Contact::createNew();
         $contact->is_primary = true;
         $contact->send_invoice = true;
         $count++;
         foreach ($row as $index => $value) {
             $field = $map[$index];
             $value = trim($value);
             if ($field == Client::$fieldName && !$client->name) {
                 $client->name = $value;
             } elseif ($field == Client::$fieldPhone && !$client->work_phone) {
                 $client->work_phone = $value;
             } elseif ($field == Client::$fieldAddress1 && !$client->address1) {
                 $client->address1 = $value;
             } elseif ($field == Client::$fieldAddress2 && !$client->address2) {
                 $client->address2 = $value;
             } elseif ($field == Client::$fieldCity && !$client->city) {
                 $client->city = $value;
             } elseif ($field == Client::$fieldState && !$client->state) {
                 $client->state = $value;
             } elseif ($field == Client::$fieldPostalCode && !$client->postal_code) {
                 $client->postal_code = $value;
             } elseif ($field == Client::$fieldCountry && !$client->country_id) {
                 $value = strtolower($value);
                 $client->country_id = isset($countryMap[$value]) ? $countryMap[$value] : null;
             } elseif ($field == Client::$fieldNotes && !$client->private_notes) {
                 $client->private_notes = $value;
             } elseif ($field == Contact::$fieldFirstName && !$contact->first_name) {
                 $contact->first_name = $value;
             } elseif ($field == Contact::$fieldLastName && !$contact->last_name) {
                 $contact->last_name = $value;
             } elseif ($field == Contact::$fieldPhone && !$contact->phone) {
                 $contact->phone = $value;
             } elseif ($field == Contact::$fieldEmail && !$contact->email) {
                 $contact->email = strtolower($value);
             }
         }
         $client->save();
         $client->contacts()->save($contact);
         Activity::createClient($client, false);
     }
     $message = Utils::pluralize('created_client', $count);
     Session::flash('message', $message);
     return Redirect::to('clients');
 }
开发者ID:unedeplus,项目名称:invoice-ninja,代码行数:62,代码来源:AccountController.php

示例7: save

 private function save($publicId = null)
 {
     $rules = array('email' => 'email|required_without:first_name', 'first_name' => 'required_without:email');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         $url = $publicId ? 'clients/' . $publicId . '/edit' : 'clients/create';
         return Redirect::to($url)->withErrors($validator)->withInput(Input::except('password'));
     } else {
         if ($publicId) {
             $client = Client::scope($publicId)->firstOrFail();
         } else {
             $client = Client::createNew();
         }
         $client->name = trim(Input::get('name'));
         $client->id_number = trim(Input::get('id_number'));
         $client->vat_number = trim(Input::get('vat_number'));
         $client->work_phone = trim(Input::get('work_phone'));
         $client->custom_value1 = trim(Input::get('custom_value1'));
         $client->custom_value2 = trim(Input::get('custom_value2'));
         $client->address1 = trim(Input::get('address1'));
         $client->address2 = trim(Input::get('address2'));
         $client->city = trim(Input::get('city'));
         $client->state = trim(Input::get('state'));
         $client->postal_code = trim(Input::get('postal_code'));
         $client->country_id = Input::get('country_id') ?: null;
         $client->private_notes = trim(Input::get('private_notes'));
         $client->size_id = Input::get('size_id') ?: null;
         $client->industry_id = Input::get('industry_id') ?: null;
         $client->currency_id = Input::get('currency_id') ?: null;
         $client->payment_terms = Input::get('payment_terms') ?: 0;
         $client->website = trim(Input::get('website'));
         $client->save();
         $data = json_decode(Input::get('data'));
         $contactIds = [];
         $isPrimary = true;
         foreach ($data->contacts as $contact) {
             if (isset($contact->public_id) && $contact->public_id) {
                 $record = Contact::scope($contact->public_id)->firstOrFail();
             } else {
                 $record = Contact::createNew();
             }
             $record->email = trim($contact->email);
             $record->first_name = trim($contact->first_name);
             $record->last_name = trim($contact->last_name);
             $record->phone = trim($contact->phone);
             $record->is_primary = $isPrimary;
             $isPrimary = false;
             $client->contacts()->save($record);
             $contactIds[] = $record->public_id;
         }
         foreach ($client->contacts as $contact) {
             if (!in_array($contact->public_id, $contactIds)) {
                 $contact->delete();
             }
         }
         if ($publicId) {
             Session::flash('message', trans('texts.updated_client'));
         } else {
             Activity::createClient($client);
             Session::flash('message', trans('texts.created_client'));
         }
         return Redirect::to('clients/' . $client->public_id);
     }
 }
开发者ID:njmube,项目名称:invoice-ninja,代码行数:64,代码来源:ClientController.php

示例8: save

 public function save($publicId, $data, $notify = true)
 {
     if (!$publicId || $publicId == "-1") {
         $client = Client::createNew();
         $contact = Contact::createNew();
         $contact->is_primary = true;
         $contact->send_invoice = true;
     } else {
         $client = Client::scope($publicId)->with('contacts')->firstOrFail();
         $contact = $client->contacts()->where('is_primary', '=', true)->firstOrFail();
     }
     if (isset($data['name'])) {
         $client->name = trim($data['name']);
     }
     if (isset($data['id_number'])) {
         $client->id_number = trim($data['id_number']);
     }
     if (isset($data['vat_number'])) {
         $client->vat_number = trim($data['vat_number']);
     }
     if (isset($data['work_phone'])) {
         $client->work_phone = trim($data['work_phone']);
     }
     if (isset($data['custom_value1'])) {
         $client->custom_value1 = trim($data['custom_value1']);
     }
     if (isset($data['custom_value2'])) {
         $client->custom_value2 = trim($data['custom_value2']);
     }
     if (isset($data['address1'])) {
         $client->address1 = trim($data['address1']);
     }
     if (isset($data['address2'])) {
         $client->address2 = trim($data['address2']);
     }
     if (isset($data['city'])) {
         $client->city = trim($data['city']);
     }
     if (isset($data['state'])) {
         $client->state = trim($data['state']);
     }
     if (isset($data['postal_code'])) {
         $client->postal_code = trim($data['postal_code']);
     }
     if (isset($data['country_id'])) {
         $client->country_id = $data['country_id'] ? $data['country_id'] : null;
     }
     if (isset($data['private_notes'])) {
         $client->private_notes = trim($data['private_notes']);
     }
     if (isset($data['size_id'])) {
         $client->size_id = $data['size_id'] ? $data['size_id'] : null;
     }
     if (isset($data['industry_id'])) {
         $client->industry_id = $data['industry_id'] ? $data['industry_id'] : null;
     }
     if (isset($data['currency_id'])) {
         $client->currency_id = $data['currency_id'] ? $data['currency_id'] : null;
     }
     if (isset($data['language_id'])) {
         $client->language_id = $data['language_id'] ? $data['language_id'] : null;
     }
     if (isset($data['payment_terms'])) {
         $client->payment_terms = $data['payment_terms'];
     }
     if (isset($data['website'])) {
         $client->website = trim($data['website']);
     }
     $client->save();
     $isPrimary = true;
     $contactIds = [];
     if (isset($data['contact'])) {
         $info = $data['contact'];
         if (isset($info['email'])) {
             $contact->email = trim($info['email']);
         }
         if (isset($info['first_name'])) {
             $contact->first_name = trim($info['first_name']);
         }
         if (isset($info['last_name'])) {
             $contact->last_name = trim($info['last_name']);
         }
         if (isset($info['phone'])) {
             $contact->phone = trim($info['phone']);
         }
         $contact->is_primary = true;
         $contact->send_invoice = true;
         $client->contacts()->save($contact);
     } else {
         foreach ($data['contacts'] as $record) {
             $record = (array) $record;
             if ($publicId != "-1" && isset($record['public_id']) && $record['public_id']) {
                 $contact = Contact::scope($record['public_id'])->firstOrFail();
             } else {
                 $contact = Contact::createNew();
             }
             if (isset($record['email'])) {
                 $contact->email = trim($record['email']);
             }
             if (isset($record['first_name'])) {
//.........这里部分代码省略.........
开发者ID:nafrente,项目名称:invoice-ninja,代码行数:101,代码来源:ClientRepository.php


注:本文中的app\models\Client::createNew方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。