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


PHP Invitation::createNew方法代码示例

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


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

 public function store()
 {
     $data = Input::all();
     $error = null;
     if (isset($data['id']) || isset($data['public_id'])) {
         die("We don't yet support updating invoices");
     }
     if (isset($data['email'])) {
         $client = Client::scope()->whereHas('contacts', function ($query) use($data) {
             $query->where('email', '=', $data['email']);
         })->first();
         if (!$client) {
             $clientData = ['contact' => ['email' => $data['email']]];
             foreach (['name', 'private_notes'] as $field) {
                 if (isset($data[$field])) {
                     $clientData[$field] = $data[$field];
                 }
             }
             foreach (['first_name', 'last_name'] as $field) {
                 if (isset($data[$field])) {
                     $clientData[$field] = $data[$field];
                 }
             }
             $error = $this->clientRepo->getErrors($clientData);
             if (!$error) {
                 $client = $this->clientRepo->save($clientData);
             }
         }
     } else {
         if (isset($data['client_id'])) {
             $client = Client::scope($data['client_id'])->first();
         }
     }
     // check if the invoice number is set and unique
     if (!isset($data['invoice_number']) && !isset($data['id'])) {
         // do nothing... invoice number will be set automatically
     } else {
         if (isset($data['invoice_number'])) {
             $invoice = Invoice::scope()->where('invoice_number', '=', $data['invoice_number'])->first();
             if ($invoice) {
                 $error = trans('validation.unique', ['attribute' => 'texts.invoice_number']);
             }
         }
     }
     if (!$error) {
         if (!isset($data['client_id']) && !isset($data['email'])) {
             $error = trans('validation.', ['attribute' => 'client_id or email']);
         } else {
             if (!$client) {
                 $error = trans('validation.not_in', ['attribute' => 'client_id']);
             }
         }
     }
     if ($error) {
         $response = json_encode($error, JSON_PRETTY_PRINT);
     } else {
         $data = self::prepareData($data, $client);
         $data['client_id'] = $client->id;
         $invoice = $this->invoiceRepo->save($data);
         if (!isset($data['id'])) {
             $invitation = Invitation::createNew();
             $invitation->invoice_id = $invoice->id;
             $invitation->contact_id = $client->contacts[0]->id;
             $invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
             $invitation->save();
         }
         if (isset($data['email_invoice']) && $data['email_invoice']) {
             $this->mailer->sendInvoice($invoice);
         }
         // prepare the return data
         $invoice = Invoice::scope($invoice->public_id)->with('client', 'invoice_items', 'invitations')->first();
         $invoice = Utils::remapPublicIds([$invoice]);
         $response = json_encode($invoice, JSON_PRETTY_PRINT);
     }
     $headers = Utils::getApiHeaders();
     return Response::make($response, $error ? 400 : 200, $headers);
 }
开发者ID:n-a-m-e,项目名称:invoice-ninja,代码行数:77,代码来源:InvoiceApiController.php

示例5: createRecurringInvoice

 public function createRecurringInvoice($recurInvoice)
 {
     $recurInvoice->load('account.timezone', 'invoice_items', 'client', 'user');
     if ($recurInvoice->client->deleted_at) {
         return false;
     }
     if (!$recurInvoice->user->confirmed) {
         return false;
     }
     if (!$recurInvoice->shouldSendToday()) {
         return false;
     }
     $invoice = Invoice::createNew($recurInvoice);
     $invoice->client_id = $recurInvoice->client_id;
     $invoice->recurring_invoice_id = $recurInvoice->id;
     $invoice->invoice_number = $recurInvoice->account->getNextInvoiceNumber(false, 'R');
     $invoice->amount = $recurInvoice->amount;
     $invoice->balance = $recurInvoice->amount;
     $invoice->invoice_date = date_create()->format('Y-m-d');
     $invoice->discount = $recurInvoice->discount;
     $invoice->po_number = $recurInvoice->po_number;
     $invoice->public_notes = Utils::processVariables($recurInvoice->public_notes);
     $invoice->terms = Utils::processVariables($recurInvoice->terms);
     $invoice->invoice_footer = Utils::processVariables($recurInvoice->invoice_footer);
     $invoice->tax_name = $recurInvoice->tax_name;
     $invoice->tax_rate = $recurInvoice->tax_rate;
     $invoice->invoice_design_id = $recurInvoice->invoice_design_id;
     $invoice->custom_value1 = $recurInvoice->custom_value1;
     $invoice->custom_value2 = $recurInvoice->custom_value2;
     $invoice->custom_taxes1 = $recurInvoice->custom_taxes1;
     $invoice->custom_taxes2 = $recurInvoice->custom_taxes2;
     $invoice->is_amount_discount = $recurInvoice->is_amount_discount;
     if ($invoice->client->payment_terms != 0) {
         $days = $invoice->client->payment_terms;
         if ($days == -1) {
             $days = 0;
         }
         $invoice->due_date = date_create()->modify($days . ' day')->format('Y-m-d');
     }
     $invoice->save();
     foreach ($recurInvoice->invoice_items as $recurItem) {
         $item = InvoiceItem::createNew($recurItem);
         $item->product_id = $recurItem->product_id;
         $item->qty = $recurItem->qty;
         $item->cost = $recurItem->cost;
         $item->notes = Utils::processVariables($recurItem->notes);
         $item->product_key = Utils::processVariables($recurItem->product_key);
         $item->tax_name = $recurItem->tax_name;
         $item->tax_rate = $recurItem->tax_rate;
         $invoice->invoice_items()->save($item);
     }
     foreach ($recurInvoice->invitations as $recurInvitation) {
         $invitation = Invitation::createNew($recurInvitation);
         $invitation->contact_id = $recurInvitation->contact_id;
         $invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
         $invoice->invitations()->save($invitation);
     }
     $recurInvoice->last_sent_date = Carbon::now()->toDateTimeString();
     $recurInvoice->save();
     return $invoice;
 }
开发者ID:hanspoelmans,项目名称:invoice-ninja,代码行数:61,代码来源:InvoiceRepository.php

示例6: store

 /**
  * @SWG\Post(
  *   path="/invoices",
  *   tags={"invoice"},
  *   summary="Create an invoice",
  *   @SWG\Parameter(
  *     in="body",
  *     name="body",
  *     @SWG\Schema(ref="#/definitions/Invoice")
  *   ),
  *   @SWG\Response(
  *     response=200,
  *     description="New invoice",
  *      @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Invoice"))
  *   ),
  *   @SWG\Response(
  *     response="default",
  *     description="an ""unexpected"" error"
  *   )
  * )
  */
 public function store(CreateInvoiceRequest $request)
 {
     $data = Input::all();
     $error = null;
     if (isset($data['email'])) {
         $email = $data['email'];
         $client = Client::scope()->whereHas('contacts', function ($query) use($email) {
             $query->where('email', '=', $email);
         })->first();
         if (!$client) {
             $validator = Validator::make(['email' => $email], ['email' => 'email']);
             if ($validator->fails()) {
                 $messages = $validator->messages();
                 return $messages->first();
             }
             $clientData = ['contact' => ['email' => $email]];
             foreach (['name', 'private_notes'] as $field) {
                 if (isset($data[$field])) {
                     $clientData[$field] = $data[$field];
                 }
             }
             foreach (['first_name', 'last_name'] as $field) {
                 if (isset($data[$field])) {
                     $clientData[$field] = $data[$field];
                 }
             }
             $client = $this->clientRepo->save($clientData);
         }
     } else {
         if (isset($data['client_id'])) {
             $client = Client::scope($data['client_id'])->firstOrFail();
         }
     }
     $data = self::prepareData($data, $client);
     $data['client_id'] = $client->id;
     $invoice = $this->invoiceRepo->save($data);
     if (!isset($data['id'])) {
         $invitation = Invitation::createNew();
         $invitation->invoice_id = $invoice->id;
         $invitation->contact_id = $client->contacts[0]->id;
         $invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
         $invitation->save();
     }
     if (isset($data['email_invoice']) && $data['email_invoice']) {
         $this->mailer->sendInvoice($invoice);
     }
     $invoice = Invoice::scope($invoice->public_id)->with('client', 'invoice_items', 'invitations')->first();
     $transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
     $data = $this->createItem($invoice, $transformer, 'invoice');
     return $this->response($data);
 }
开发者ID:j-beere,项目名称:invoiceninja,代码行数:72,代码来源:InvoiceApiController.php

示例7: 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

示例8: cloneInvoice

 public function cloneInvoice($invoice, $quotePublicId = null)
 {
     $invoice->load('invitations', 'invoice_items');
     $account = $invoice->account;
     $clone = Invoice::createNew($invoice);
     $clone->balance = $invoice->amount;
     // if the invoice prefix is diff than quote prefix, use the same number for the invoice
     if (($account->invoice_number_prefix || $account->quote_number_prefix) && $account->invoice_number_prefix != $account->quote_number_prefix && $account->share_counter) {
         $invoiceNumber = $invoice->invoice_number;
         if ($account->quote_number_prefix && strpos($invoiceNumber, $account->quote_number_prefix) === 0) {
             $invoiceNumber = substr($invoiceNumber, strlen($account->quote_number_prefix));
         }
         $clone->invoice_number = $account->invoice_number_prefix . $invoiceNumber;
     } else {
         $clone->invoice_number = $account->getNextInvoiceNumber();
     }
     foreach (['client_id', 'discount', 'is_amount_discount', 'invoice_date', 'po_number', 'due_date', 'is_recurring', 'frequency_id', 'start_date', 'end_date', 'terms', 'invoice_footer', 'public_notes', 'invoice_design_id', 'tax_name', 'tax_rate', 'amount', 'is_quote', 'custom_value1', 'custom_value2', 'custom_taxes1', 'custom_taxes2', 'partial'] as $field) {
         $clone->{$field} = $invoice->{$field};
     }
     if ($quotePublicId) {
         $clone->is_quote = false;
         $clone->quote_id = $quotePublicId;
     }
     $clone->save();
     if ($quotePublicId) {
         $invoice->quote_invoice_id = $clone->public_id;
         $invoice->save();
     }
     foreach ($invoice->invoice_items as $item) {
         $cloneItem = InvoiceItem::createNew($invoice);
         foreach (['product_id', 'product_key', 'notes', 'cost', 'qty', 'tax_name', 'tax_rate'] as $field) {
             $cloneItem->{$field} = $item->{$field};
         }
         $clone->invoice_items()->save($cloneItem);
     }
     foreach ($invoice->invitations as $invitation) {
         $cloneInvitation = Invitation::createNew($invoice);
         $cloneInvitation->contact_id = $invitation->contact_id;
         $cloneInvitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
         $clone->invitations()->save($cloneInvitation);
     }
     return $clone;
 }
开发者ID:ricoa,项目名称:invoice-ninja,代码行数:43,代码来源:InvoiceRepository.php

示例9: 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

示例10: createRecurringInvoice

 public function createRecurringInvoice($recurInvoice)
 {
     $recurInvoice->load('account.timezone', 'invoice_items', 'client', 'user');
     if ($recurInvoice->client->deleted_at) {
         return false;
     }
     if (!$recurInvoice->user->confirmed) {
         return false;
     }
     if (!$recurInvoice->shouldSendToday()) {
         return false;
     }
     $invoice = Invoice::createNew($recurInvoice);
     $invoice->client_id = $recurInvoice->client_id;
     $invoice->recurring_invoice_id = $recurInvoice->id;
     $invoice->invoice_number = 'R' . $recurInvoice->account->getNextInvoiceNumber($recurInvoice);
     $invoice->amount = $recurInvoice->amount;
     $invoice->balance = $recurInvoice->amount;
     $invoice->invoice_date = date_create()->format('Y-m-d');
     $invoice->discount = $recurInvoice->discount;
     $invoice->po_number = $recurInvoice->po_number;
     $invoice->public_notes = Utils::processVariables($recurInvoice->public_notes);
     $invoice->terms = Utils::processVariables($recurInvoice->terms);
     $invoice->invoice_footer = Utils::processVariables($recurInvoice->invoice_footer);
     $invoice->tax_name = $recurInvoice->tax_name;
     $invoice->tax_rate = $recurInvoice->tax_rate;
     $invoice->invoice_design_id = $recurInvoice->invoice_design_id;
     $invoice->custom_value1 = $recurInvoice->custom_value1 ?: 0;
     $invoice->custom_value2 = $recurInvoice->custom_value2 ?: 0;
     $invoice->custom_taxes1 = $recurInvoice->custom_taxes1 ?: 0;
     $invoice->custom_taxes2 = $recurInvoice->custom_taxes2 ?: 0;
     $invoice->custom_text_value1 = $recurInvoice->custom_text_value1;
     $invoice->custom_text_value2 = $recurInvoice->custom_text_value2;
     $invoice->is_amount_discount = $recurInvoice->is_amount_discount;
     if ($invoice->client->payment_terms != 0) {
         $days = $invoice->client->payment_terms;
         if ($days == -1) {
             $days = 0;
         }
         $invoice->due_date = date_create()->modify($days . ' day')->format('Y-m-d');
     }
     $invoice->save();
     foreach ($recurInvoice->invoice_items as $recurItem) {
         $item = InvoiceItem::createNew($recurItem);
         $item->product_id = $recurItem->product_id;
         $item->qty = $recurItem->qty;
         $item->cost = $recurItem->cost;
         $item->notes = Utils::processVariables($recurItem->notes);
         $item->product_key = Utils::processVariables($recurItem->product_key);
         $item->tax_name = $recurItem->tax_name;
         $item->tax_rate = $recurItem->tax_rate;
         $invoice->invoice_items()->save($item);
     }
     foreach ($recurInvoice->invitations as $recurInvitation) {
         $invitation = Invitation::createNew($recurInvitation);
         $invitation->contact_id = $recurInvitation->contact_id;
         $invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
         $invoice->invitations()->save($invitation);
     }
     $recurInvoice->last_sent_date = date('Y-m-d');
     $recurInvoice->save();
     if ($recurInvoice->auto_bill) {
         if ($this->paymentService->autoBillInvoice($invoice)) {
             // update the invoice reference to match its actual state
             // this is to ensure a 'payment received' email is sent
             $invoice->invoice_status_id = INVOICE_STATUS_PAID;
         }
     }
     return $invoice;
 }
开发者ID:rnaby,项目名称:invoiceninja,代码行数:70,代码来源:InvoiceRepository.php

示例11: store

 /**
  * @SWG\Post(
  *   path="/invoices",
  *   tags={"invoice"},
  *   summary="Create an invoice",
  *   @SWG\Parameter(
  *     in="body",
  *     name="body",
  *     @SWG\Schema(ref="#/definitions/Invoice")
  *   ),
  *   @SWG\Response(
  *     response=200,
  *     description="New invoice",
  *      @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Invoice"))
  *   ),
  *   @SWG\Response(
  *     response="default",
  *     description="an ""unexpected"" error"
  *   )
  * )
  */
 public function store()
 {
     $data = Input::all();
     $error = null;
     if (isset($data['id']) || isset($data['public_id'])) {
         die("We don't yet support updating invoices");
     }
     if (isset($data['email'])) {
         $email = $data['email'];
         $client = Client::scope()->whereHas('contacts', function ($query) use($email) {
             $query->where('email', '=', $email);
         })->first();
         if (!$client) {
             $validator = Validator::make(['email' => $email], ['email' => 'email']);
             if ($validator->fails()) {
                 $messages = $validator->messages();
                 return $messages->first();
             }
             $clientData = ['contact' => ['email' => $email]];
             foreach (['name', 'private_notes'] as $field) {
                 if (isset($data[$field])) {
                     $clientData[$field] = $data[$field];
                 }
             }
             foreach (['first_name', 'last_name'] as $field) {
                 if (isset($data[$field])) {
                     $clientData[$field] = $data[$field];
                 }
             }
             $client = $this->clientRepo->save($clientData);
         }
     } else {
         if (isset($data['client_id'])) {
             $client = Client::scope($data['client_id'])->first();
         }
     }
     // check if the invoice number is set and unique
     if (!isset($data['invoice_number']) && !isset($data['id'])) {
         // do nothing... invoice number will be set automatically
     } else {
         if (isset($data['invoice_number'])) {
             $invoice = Invoice::scope()->where('invoice_number', '=', $data['invoice_number'])->first();
             if ($invoice) {
                 $error = trans('validation.unique', ['attribute' => 'texts.invoice_number']);
             }
         }
     }
     if (!$error) {
         if (!isset($data['client_id']) && !isset($data['email'])) {
             $error = trans('validation.required_without', ['attribute' => 'client_id', 'values' => 'email']);
         } else {
             if (!$client) {
                 $error = trans('validation.not_in', ['attribute' => 'client_id']);
             }
         }
     }
     if ($error) {
         return $error;
     } else {
         $data = self::prepareData($data, $client);
         $data['client_id'] = $client->id;
         $invoice = $this->invoiceRepo->save($data);
         if (!isset($data['id'])) {
             $invitation = Invitation::createNew();
             $invitation->invoice_id = $invoice->id;
             $invitation->contact_id = $client->contacts[0]->id;
             $invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
             $invitation->save();
         }
         if (isset($data['email_invoice']) && $data['email_invoice']) {
             $this->mailer->sendInvoice($invoice);
         }
         $invoice = Invoice::scope($invoice->public_id)->with('client', 'invoice_items', 'invitations')->first();
         $transformer = new InvoiceTransformer(\Auth::user()->account, Input::get('serializer'));
         $data = $this->createItem($invoice, $transformer, 'invoice');
         return $this->response($data);
     }
 }
开发者ID:madonion,项目名称:facturi,代码行数:99,代码来源:InvoiceApiController.php

示例12: fire

 public function fire()
 {
     $this->info(date('Y-m-d') . ' Running SendRecurringInvoices...');
     $today = new DateTime();
     $invoices = Invoice::with('account.timezone', 'invoice_items', 'client', 'user')->whereRaw('is_deleted IS FALSE AND deleted_at IS NULL AND is_recurring IS TRUE AND start_date <= ? AND (end_date IS NULL OR end_date >= ?)', array($today, $today))->get();
     $this->info(count($invoices) . ' recurring invoice(s) found');
     foreach ($invoices as $recurInvoice) {
         if ($recurInvoice->client->deleted_at) {
             continue;
         }
         if (!$recurInvoice->user->confirmed) {
             continue;
         }
         $this->info('Processing Invoice ' . $recurInvoice->id . ' - Should send ' . ($recurInvoice->shouldSendToday() ? 'YES' : 'NO'));
         if (!$recurInvoice->shouldSendToday()) {
             continue;
         }
         $invoice = Invoice::createNew($recurInvoice);
         $invoice->client_id = $recurInvoice->client_id;
         $invoice->recurring_invoice_id = $recurInvoice->id;
         $invoice->invoice_number = $recurInvoice->account->getNextInvoiceNumber(false, 'R');
         $invoice->amount = $recurInvoice->amount;
         $invoice->balance = $recurInvoice->amount;
         $invoice->invoice_date = date_create()->format('Y-m-d');
         $invoice->discount = $recurInvoice->discount;
         $invoice->po_number = $recurInvoice->po_number;
         $invoice->public_notes = Utils::processVariables($recurInvoice->public_notes);
         $invoice->terms = Utils::processVariables($recurInvoice->terms);
         $invoice->invoice_footer = Utils::processVariables($recurInvoice->invoice_footer);
         $invoice->tax_name = $recurInvoice->tax_name;
         $invoice->tax_rate = $recurInvoice->tax_rate;
         $invoice->invoice_design_id = $recurInvoice->invoice_design_id;
         $invoice->custom_value1 = $recurInvoice->custom_value1;
         $invoice->custom_value2 = $recurInvoice->custom_value2;
         $invoice->custom_taxes1 = $recurInvoice->custom_taxes1;
         $invoice->custom_taxes2 = $recurInvoice->custom_taxes2;
         $invoice->is_amount_discount = $recurInvoice->is_amount_discount;
         if ($invoice->client->payment_terms != 0) {
             $days = $invoice->client->payment_terms;
             if ($days == -1) {
                 $days = 0;
             }
             $invoice->due_date = date_create()->modify($days . ' day')->format('Y-m-d');
         }
         $invoice->save();
         foreach ($recurInvoice->invoice_items as $recurItem) {
             $item = InvoiceItem::createNew($recurItem);
             $item->product_id = $recurItem->product_id;
             $item->qty = $recurItem->qty;
             $item->cost = $recurItem->cost;
             $item->notes = Utils::processVariables($recurItem->notes);
             $item->product_key = Utils::processVariables($recurItem->product_key);
             $item->tax_name = $recurItem->tax_name;
             $item->tax_rate = $recurItem->tax_rate;
             $invoice->invoice_items()->save($item);
         }
         foreach ($recurInvoice->invitations as $recurInvitation) {
             $invitation = Invitation::createNew($recurInvitation);
             $invitation->contact_id = $recurInvitation->contact_id;
             $invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
             $invoice->invitations()->save($invitation);
         }
         $this->mailer->sendInvoice($invoice);
         $recurInvoice->last_sent_date = Carbon::now()->toDateTimeString();
         $recurInvoice->save();
     }
     $this->info('Done');
 }
开发者ID:ricoa,项目名称:invoice-ninja,代码行数:68,代码来源:SendRecurringInvoices.php


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