本文整理汇总了PHP中app\models\Invoice::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Invoice::load方法的具体用法?PHP Invoice::load怎么用?PHP Invoice::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Invoice
的用法示例。
在下文中一共展示了Invoice::load方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendInvoice
public function sendInvoice(Invoice $invoice, $reminder = false, $pdfString = false)
{
$invoice->load('invitations', 'client.language', 'account');
$entityType = $invoice->getEntityType();
$client = $invoice->client;
$account = $invoice->account;
if ($invoice->trashed() || $client->trashed()) {
return false;
}
$account->loadLocalizationSettings($client);
$emailTemplate = $account->getEmailTemplate($reminder ?: $entityType);
$emailSubject = $account->getEmailSubject($reminder ?: $entityType);
$sent = false;
if ($account->attatchPDF() && !$pdfString) {
$pdfString = $invoice->getPDFString();
}
foreach ($invoice->invitations as $invitation) {
if ($this->sendInvitation($invitation, $invoice, $emailTemplate, $emailSubject, $pdfString)) {
$sent = true;
}
}
$account->loadLocalizationSettings();
if ($sent === true) {
Event::fire(new InvoiceSent($invoice));
}
return $sent ?: trans('texts.email_error');
}
示例2: sendInvoice
public function sendInvoice(Invoice $invoice, $reminder = false, $pdfString = false)
{
$invoice->load('invitations', 'client.language', 'account');
$entityType = $invoice->getEntityType();
$client = $invoice->client;
$account = $invoice->account;
if ($client->trashed()) {
return trans('texts.email_errors.inactive_client');
} elseif ($invoice->trashed()) {
return trans('texts.email_errors.inactive_invoice');
}
$account->loadLocalizationSettings($client);
$emailTemplate = $account->getEmailTemplate($reminder ?: $entityType);
$emailSubject = $account->getEmailSubject($reminder ?: $entityType);
$sent = false;
if ($account->attatchPDF() && !$pdfString) {
$pdfString = $invoice->getPDFString();
}
foreach ($invoice->invitations as $invitation) {
$response = $this->sendInvitation($invitation, $invoice, $emailTemplate, $emailSubject, $pdfString);
if ($response === true) {
$sent = true;
}
}
$account->loadLocalizationSettings();
if ($sent === true) {
if ($invoice->is_quote) {
event(new QuoteWasEmailed($invoice));
} else {
event(new InvoiceWasEmailed($invoice));
}
}
return $response;
}
示例3: sendInvoice
public function sendInvoice(Invoice $invoice, $reminder = false)
{
$invoice->load('invitations', 'client.language', 'account');
$entityType = $invoice->getEntityType();
$client = $invoice->client;
$account = $invoice->account;
if ($invoice->trashed() || $client->trashed()) {
return false;
}
$account->loadLocalizationSettings($client);
if ($account->pdf_email_attachment) {
$invoice->updateCachedPDF();
}
$view = 'invoice';
$accountName = $invoice->account->getDisplayName();
$emailTemplate = $invoice->account->getEmailTemplate($reminder ?: $entityType);
$emailSubject = $invoice->account->getEmailSubject($reminder ?: $entityType);
$this->initClosure($invoice);
$response = false;
$sent = false;
foreach ($invoice->invitations as $invitation) {
if (Auth::check()) {
$user = Auth::user();
} else {
$user = $invitation->user;
if ($invitation->user->trashed()) {
$user = $account->users()->orderBy('id')->first();
}
}
if (!$user->email || !$user->confirmed) {
continue;
}
if (!$invitation->contact->email || $invitation->contact->trashed()) {
continue;
}
$invitation->sent_date = \Carbon::now()->toDateTimeString();
$invitation->save();
$variables = ['account' => $account, 'client' => $client, 'invitation' => $invitation, 'amount' => $invoice->getRequestedAmount()];
$data['body'] = $this->processVariables($emailTemplate, $variables);
$data['link'] = $invitation->getLink();
$data['entityType'] = $entityType;
$data['invoice_id'] = $invoice->id;
$subject = $this->processVariables($emailSubject, $variables);
$fromEmail = $user->email;
$response = $this->sendTo($invitation->contact->email, $fromEmail, $accountName, $subject, $view, $data);
if ($response === true) {
$sent = true;
Activity::emailInvoice($invitation);
}
}
if ($sent === true) {
if (!$invoice->isSent()) {
$invoice->invoice_status_id = INVOICE_STATUS_SENT;
$invoice->save();
}
$account->loadLocalizationSettings();
Event::fire(new InvoiceSent($invoice));
}
return $response ?: trans('texts.email_error');
}
示例4: sendInvoice
public function sendInvoice(Invoice $invoice)
{
$invoice->load('invitations', 'client', 'account');
$entityType = $invoice->getEntityType();
$view = 'invoice';
$subject = trans("texts.{$entityType}_subject", ['invoice' => $invoice->invoice_number, 'account' => $invoice->account->getDisplayName()]);
$accountName = $invoice->account->getDisplayName();
$emailTemplate = $invoice->account->getEmailTemplate($entityType);
$invoiceAmount = Utils::formatMoney($invoice->getRequestedAmount(), $invoice->client->currency_id);
foreach ($invoice->invitations as $invitation) {
if (!$invitation->user || !$invitation->user->email) {
return false;
}
if (!$invitation->contact || !$invitation->contact->email) {
return false;
}
$invitation->sent_date = \Carbon::now()->toDateTimeString();
$invitation->save();
$variables = ['$footer' => $invoice->account->getEmailFooter(), '$link' => $invitation->getLink(), '$client' => $invoice->client->getDisplayName(), '$account' => $accountName, '$contact' => $invitation->contact->getDisplayName(), '$amount' => $invoiceAmount];
$data['body'] = str_replace(array_keys($variables), array_values($variables), $emailTemplate);
$data['link'] = $invitation->getLink();
$data['entityType'] = $entityType;
$data['invoice_id'] = $invoice->id;
$fromEmail = $invitation->user->email;
$this->sendTo($invitation->contact->email, $fromEmail, $accountName, $subject, $view, $data);
Activity::emailInvoice($invitation);
}
if (!$invoice->isSent()) {
$invoice->invoice_status_id = INVOICE_STATUS_SENT;
$invoice->save();
}
Event::fire(new InvoiceSent($invoice));
}
示例5: actionCreate
/**
* Creates a new Invoice model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Invoice();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例6: actionCreate
public function actionCreate()
{
$model = new Invoice(['user_name' => Yii::$app->user->identity->name, 'status' => 'create']);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
}
示例7: sendInvoice
public function sendInvoice(Invoice $invoice, $reminder = false, $pdfString = false)
{
$invoice->load('invitations', 'client.language', 'account');
$entityType = $invoice->getEntityType();
$client = $invoice->client;
$account = $invoice->account;
$response = null;
if ($client->trashed()) {
return trans('texts.email_errors.inactive_client');
} elseif ($invoice->trashed()) {
return trans('texts.email_errors.inactive_invoice');
}
$account->loadLocalizationSettings($client);
$emailTemplate = $account->getEmailTemplate($reminder ?: $entityType);
$emailSubject = $account->getEmailSubject($reminder ?: $entityType);
$sent = false;
if ($account->attatchPDF() && !$pdfString) {
$pdfString = $invoice->getPDFString();
}
$documentStrings = array();
if ($account->document_email_attachment && $invoice->hasDocuments()) {
$documents = $invoice->documents;
foreach ($invoice->expenses as $expense) {
$documents = $documents->merge($expense->documents);
}
$documents = $documents->sortBy('size');
$size = 0;
$maxSize = MAX_EMAIL_DOCUMENTS_SIZE * 1000;
foreach ($documents as $document) {
$size += $document->size;
if ($size > $maxSize) {
break;
}
$documentStrings[] = array('name' => $document->name, 'data' => $document->getRaw());
}
}
foreach ($invoice->invitations as $invitation) {
$response = $this->sendInvitation($invitation, $invoice, $emailTemplate, $emailSubject, $pdfString, $documentStrings);
if ($response === true) {
$sent = true;
}
}
$account->loadLocalizationSettings();
if ($sent === true) {
if ($invoice->is_quote) {
event(new QuoteWasEmailed($invoice));
} else {
event(new InvoiceWasEmailed($invoice));
}
}
return $response;
}
示例8: createInvoice
public function createInvoice(Buyerable $buyer, Supplier $supplier, array $carts, TransactionShipping $transactionShipping, $note = null, $status = 'unpaid')
{
$invoice = new Invoice();
$invoice->code = $this->generateInvoiceNumber($supplier);
$invoice->note = $note;
$invoice->status = $status;
$invoice->buyer()->associate($buyer);
$invoice->transaction_shipping()->associate($transactionShipping);
$invoice->save();
foreach ($carts as $cart) {
$product = $cart['product'];
$invoice->details()->create(['name' => $product->name, 'description' => $product->description, 'quantity' => $cart['quantity'], 'price' => $product->price, 'product_id' => $product->id]);
}
return $invoice->load('details');
}
示例9: sendInvoice
public function sendInvoice(Invoice $invoice)
{
$invoice->load('invitations', 'client.language', 'account');
$entityType = $invoice->getEntityType();
$client = $invoice->client;
$account = $invoice->account;
$account->loadLocalizationSettings($client);
$view = 'invoice';
$subject = trans("texts.{$entityType}_subject", ['invoice' => $invoice->invoice_number, 'account' => $invoice->account->getDisplayName()]);
$accountName = $invoice->account->getDisplayName();
$emailTemplate = $invoice->account->getEmailTemplate($entityType);
$invoiceAmount = Utils::formatMoney($invoice->getRequestedAmount(), $client->getCurrencyId());
$this->initClosure($invoice);
foreach ($invoice->invitations as $invitation) {
if (!$invitation->user || !$invitation->user->email || $invitation->user->trashed()) {
return false;
}
if (!$invitation->contact || !$invitation->contact->email || $invitation->contact->trashed()) {
return false;
}
$invitation->sent_date = \Carbon::now()->toDateTimeString();
$invitation->save();
$variables = ['$footer' => $invoice->account->getEmailFooter(), '$link' => $invitation->getLink(), '$client' => $client->getDisplayName(), '$account' => $accountName, '$contact' => $invitation->contact->getDisplayName(), '$amount' => $invoiceAmount, '$advancedRawInvoice->' => '$'];
// Add variables for available payment types
foreach (Gateway::getPaymentTypeLinks() as $type) {
$variables["\${$type}_link"] = URL::to("/payment/{$invitation->invitation_key}/{$type}");
}
$data['body'] = str_replace(array_keys($variables), array_values($variables), $emailTemplate);
$data['body'] = preg_replace_callback('/\\{\\{\\$?(.*)\\}\\}/', $this->advancedTemplateHandler, $data['body']);
$data['link'] = $invitation->getLink();
$data['entityType'] = $entityType;
$data['invoice_id'] = $invoice->id;
$fromEmail = $invitation->user->email;
$response = $this->sendTo($invitation->contact->email, $fromEmail, $accountName, $subject, $view, $data);
if ($response !== true) {
return $response;
}
Activity::emailInvoice($invitation);
}
if (!$invoice->isSent()) {
$invoice->invoice_status_id = INVOICE_STATUS_SENT;
$invoice->save();
}
$account->loadLocalizationSettings();
Event::fire(new InvoiceSent($invoice));
return $response;
}
示例10: actionCreate
/**
* Creates a new Registration model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$registration_model = new Registration();
$registration_model->registration_type_id = 1;
$invoice_model = new Invoice();
if ($registration_model->load(Yii::$app->request->post())) {
$registration_model->file_payment_receipt = UploadedFile::getInstance($registration_model, 'file_payment_receipt');
switch ($registration_model->registration_type_id) {
case 2:
case 4:
case 5:
$registration_model->file_student_id = UploadedFile::getInstance($registration_model, 'file_student_id');
break;
}
$isValid = $registration_model->validate();
if ($registration_model->requires_invoice) {
if ($invoice_model->load(Yii::$app->request->post())) {
$isValid = $isValid && $invoice_model->validate();
var_dump($invoice_model->errors);
}
}
var_dump($registration_model->errors);
if ($isValid) {
if ($registration_model->save(false)) {
if ($registration_model->requires_invoice) {
$invoice_model->registration_id = $registration_model->id;
if ($invoice_model->save(false)) {
return $this->redirect(['view', 'id' => $registration_model->id]);
}
} else {
return $this->redirect(['view', 'id' => $registration_model->id]);
}
}
}
} else {
return $this->render('create', ['registration_model' => $registration_model, 'invoice_model' => $invoice_model]);
}
}
示例11: createRecurringInvoice
/**
* @param Invoice $recurInvoice
* @return mixed
*/
public function createRecurringInvoice(Invoice $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->invoice_type_id = INVOICE_TYPE_STANDARD;
$invoice->client_id = $recurInvoice->client_id;
$invoice->recurring_invoice_id = $recurInvoice->id;
$invoice->invoice_number = $recurInvoice->account->getNextInvoiceNumber($invoice);
$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_name1 = $recurInvoice->tax_name1;
$invoice->tax_rate1 = $recurInvoice->tax_rate1;
$invoice->tax_name2 = $recurInvoice->tax_name2;
$invoice->tax_rate2 = $recurInvoice->tax_rate2;
$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 = Utils::processVariables($recurInvoice->custom_text_value1);
$invoice->custom_text_value2 = Utils::processVariables($recurInvoice->custom_text_value2);
$invoice->is_amount_discount = $recurInvoice->is_amount_discount;
$invoice->due_date = $recurInvoice->getDueDate();
$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_name1 = $recurItem->tax_name1;
$item->tax_rate1 = $recurItem->tax_rate1;
$item->tax_name2 = $recurItem->tax_name2;
$item->tax_rate2 = $recurItem->tax_rate2;
$item->custom_value1 = Utils::processVariables($recurItem->custom_value1);
$item->custom_value2 = Utils::processVariables($recurItem->custom_value2);
$invoice->invoice_items()->save($item);
}
foreach ($recurInvoice->documents as $recurDocument) {
$document = $recurDocument->cloneDocument();
$invoice->documents()->save($document);
}
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->getAutoBillEnabled() && !$recurInvoice->account->auto_bill_on_due_date) {
// autoBillInvoice will check for ACH, so we're not checking here
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;
}