本文整理汇总了PHP中app\models\Invoice类的典型用法代码示例。如果您正苦于以下问题:PHP Invoice类的具体用法?PHP Invoice怎么用?PHP Invoice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Invoice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
$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');
}
示例2: get
public static function get($x)
{
$sql = "SELECT * FROM invoices where invoiceID = :x";
$row = DB::SelectOne($sql, ["x" => $x]);
$invoice = new Invoice();
$invoice->id = $row->invoiceID;
$invoice->date = $row->invoiceDate;
$invoice->customer = $row->customer;
// I really want an array of items here....
/// How could i possibly fetch the items for just this inovice id????
$invoice->tools = Tool::getByInvoiceId($x);
$invoice->calcTotal();
return $invoice;
}
示例3: sendNotification
public function sendNotification(User $user, Invoice $invoice, $notificationType, Payment $payment = null)
{
if (!$user->email) {
return;
}
$entityType = $notificationType == 'approved' ? ENTITY_QUOTE : ENTITY_INVOICE;
$view = "{$entityType}_{$notificationType}";
$data = ['entityType' => $entityType, 'clientName' => $invoice->client->getDisplayName(), 'accountName' => $invoice->account->getDisplayName(), 'userName' => $user->getDisplayName(), 'invoiceAmount' => Utils::formatMoney($invoice->getRequestedAmount(), $invoice->client->getCurrencyId()), 'invoiceNumber' => $invoice->invoice_number, 'invoiceLink' => SITE_URL . "/{$entityType}s/{$invoice->public_id}"];
if ($payment) {
$data['paymentAmount'] = Utils::formatMoney($payment->amount, $invoice->client->getCurrencyId());
}
$subject = trans("texts.notification_{$entityType}_{$notificationType}_subject", ['invoice' => $invoice->invoice_number, 'client' => $invoice->client->getDisplayName()]);
$this->sendTo($user->email, CONTACT_EMAIL, CONTACT_NAME, $subject, $view, $data);
}
示例4: 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 frequency_id > 0 AND start_date <= ? AND (end_date IS NULL OR end_date >= ?)', [$today, $today])->orderBy('id', 'asc')->get();
$this->info(count($invoices) . ' recurring invoice(s) found');
foreach ($invoices as $recurInvoice) {
$shouldSendToday = $recurInvoice->shouldSendToday();
$this->info('Processing Invoice ' . $recurInvoice->id . ' - Should send ' . ($shouldSendToday ? 'YES' : 'NO'));
if (!$shouldSendToday) {
continue;
}
$recurInvoice->account->loadLocalizationSettings($recurInvoice->client);
$invoice = $this->invoiceRepo->createRecurringInvoice($recurInvoice);
if ($invoice && !$invoice->isPaid()) {
$this->info('Sending Invoice');
$this->mailer->sendInvoice($invoice);
}
}
$delayedAutoBillInvoices = Invoice::with('account.timezone', 'recurring_invoice', 'invoice_items', 'client', 'user')->whereRaw('is_deleted IS FALSE AND deleted_at IS NULL AND is_recurring IS FALSE
AND balance > 0 AND due_date = ? AND recurring_invoice_id IS NOT NULL', [$today->format('Y-m-d')])->orderBy('invoices.id', 'asc')->get();
$this->info(count($delayedAutoBillInvoices) . ' due recurring invoice instance(s) found');
/** @var Invoice $invoice */
foreach ($delayedAutoBillInvoices as $invoice) {
if ($invoice->isPaid()) {
continue;
}
if ($invoice->getAutoBillEnabled() && $invoice->client->autoBillLater()) {
$this->info('Processing Autobill-delayed Invoice ' . $invoice->id);
$this->paymentService->autoBillInvoice($invoice);
}
}
$this->info('Done');
}
示例5: save
public function save($publicId = null, $input)
{
if ($publicId) {
$payment = Payment::scope($publicId)->firstOrFail();
} else {
$payment = Payment::createNew();
}
$paymentTypeId = $input['payment_type_id'] ? $input['payment_type_id'] : null;
$payment->payment_type_id = $paymentTypeId;
$payment->payment_date = Utils::toSqlDate($input['payment_date']);
$payment->transaction_reference = trim($input['transaction_reference']);
if (!$publicId) {
$clientId = Client::getPrivateId($input['client']);
$amount = Utils::parseFloat($input['amount']);
if ($paymentTypeId == PAYMENT_TYPE_CREDIT) {
$credits = Credit::scope()->where('client_id', '=', $clientId)->where('balance', '>', 0)->orderBy('created_at')->get();
$applied = 0;
foreach ($credits as $credit) {
$applied += $credit->apply($amount);
if ($applied >= $amount) {
break;
}
}
}
$payment->client_id = $clientId;
$payment->invoice_id = isset($input['invoice']) && $input['invoice'] != "-1" ? Invoice::getPrivateId($input['invoice']) : null;
$payment->amount = $amount;
}
$payment->save();
return $payment;
}
示例6: update
public function update($id, Request $request)
{
$invoice = Invoice::find($id);
$rules = $invoice->getValidatorRules();
$validator = $this->validate($request, $rules);
if ($validator) {
return response()->json($validator, '404');
}
$input = $request->all();
$invoice->update($input);
/**
|-----------------------------------------------------
| Add customer to invoice
|-----------------------------------------------------
*/
$customer_id = $request->get('customer')['id'];
$customer = Customer::find($customer_id);
$invoice->updateCustomerWithShippingAddress($customer);
/**
|-----------------------------------------------------
| Add list products to invoice
|-----------------------------------------------------
*/
$invoice->addProductItems($request->get('items'));
/**
|-----------------------------------------------------
| Save to Db
|-----------------------------------------------------
*/
redirect()->route('sale.invoice.show', [$invoice], 302);
}
示例7: sendTo
public function sendTo($toEmail, $fromEmail, $fromName, $subject, $view, $data = [])
{
$views = ['emails.' . $view . '_html', 'emails.' . $view . '_text'];
try {
Mail::send($views, $data, function ($message) use($toEmail, $fromEmail, $fromName, $subject, $data) {
$replyEmail = $fromEmail;
$fromEmail = CONTACT_EMAIL;
if (isset($data['invoice_id'])) {
$invoice = Invoice::with('account')->where('id', '=', $data['invoice_id'])->get()->first();
if ($invoice->account->pdf_email_attachment && file_exists($invoice->getPDFPath())) {
$message->attach($invoice->getPDFPath(), array('as' => $invoice->getFileName(), 'mime' => 'application/pdf'));
}
}
$message->to($toEmail)->from($fromEmail, $fromName)->replyTo($replyEmail, $fromName)->subject($subject);
});
return true;
} catch (Exception $exception) {
if (method_exists($exception, 'getResponse')) {
$response = $exception->getResponse()->getBody()->getContents();
$response = json_decode($response);
return nl2br($response->Message);
} else {
return $exception->getMessage();
}
}
}
示例8: edit
public function edit($publicId)
{
$payment = Payment::scope($publicId)->firstOrFail();
$payment->payment_date = Utils::fromSqlDate($payment->payment_date);
$data = array('client' => null, 'invoice' => null, 'invoices' => Invoice::scope()->where('is_recurring', '=', false)->where('is_quote', '=', false)->with('client', 'invoice_status')->orderBy('invoice_number')->get(), 'payment' => $payment, 'method' => 'PUT', 'url' => 'payments/' . $publicId, 'title' => trans('texts.edit_payment'), 'paymentTypes' => Cache::get('paymentTypes'), 'clients' => Client::scope()->with('contacts')->orderBy('name')->get());
return View::make('payments.edit', $data);
}
示例9: store
public function store()
{
$data = Input::all();
$error = false;
if (isset($data['invoice_id'])) {
$invoice = Invoice::scope($data['invoice_id'])->with('client')->first();
if ($invoice) {
$data['invoice'] = $invoice->public_id;
$data['client'] = $invoice->client->public_id;
} else {
$error = trans('validation.not_in', ['attribute' => 'invoice_id']);
}
} else {
$error = trans('validation.not_in', ['attribute' => 'invoice_id']);
}
if (!isset($data['transaction_reference'])) {
$data['transaction_reference'] = '';
}
if (!$error) {
$payment = $this->paymentRepo->save($data);
$payment = Payment::scope($payment->public_id)->with('client', 'contact', 'user', 'invoice')->first();
$payment = Utils::remapPublicIds([$payment]);
}
$response = json_encode($error ?: $payment, JSON_PRETTY_PRINT);
$headers = Utils::getApiHeaders();
return Response::make($response, 200, $headers);
}
示例10: sendTo
public function sendTo($toEmail, $fromEmail, $fromName, $subject, $view, $data = [])
{
// https://github.com/wildbit/laravel-postmark-provider/issues/2
if (isset($data['invoice_id']) && isset($_ENV['POSTMARK_API_TOKEN'])) {
$views = 'emails.' . $view . '_html';
} else {
$views = ['emails.' . $view . '_html', 'emails.' . $view . '_text'];
}
try {
Mail::send($views, $data, function ($message) use($toEmail, $fromEmail, $fromName, $subject, $data) {
$toEmail = strtolower($toEmail);
$replyEmail = $fromEmail;
$fromEmail = CONTACT_EMAIL;
$message->to($toEmail)->from($fromEmail, $fromName)->replyTo($replyEmail, $fromName)->subject($subject);
if (isset($data['invoice_id'])) {
$invoice = Invoice::with('account')->where('id', '=', $data['invoice_id'])->first();
if ($invoice->account->pdf_email_attachment && file_exists($invoice->getPDFPath())) {
$message->attach($invoice->getPDFPath(), array('as' => $invoice->getFileName(), 'mime' => 'application/pdf'));
}
}
});
return true;
} catch (Exception $exception) {
Utils::logError('Email Error: ' . $exception->getMessage());
if (isset($_ENV['POSTMARK_API_TOKEN'])) {
$response = $exception->getResponse()->getBody()->getContents();
$response = json_decode($response);
return nl2br($response->Message);
} else {
return $exception->getMessage();
}
}
}
示例11: createNinjaInvoice
public function createNinjaInvoice($client)
{
$account = $this->getNinjaAccount();
$lastInvoice = Invoice::withTrashed()->whereAccountId($account->id)->orderBy('public_id', 'DESC')->first();
$publicId = $lastInvoice ? $lastInvoice->public_id + 1 : 1;
$invoice = new Invoice();
$invoice->account_id = $account->id;
$invoice->user_id = $account->users()->first()->id;
$invoice->public_id = $publicId;
$invoice->client_id = $client->id;
$invoice->invoice_number = $account->getNextInvoiceNumber();
$invoice->invoice_date = date_create()->format('Y-m-d');
$invoice->amount = PRO_PLAN_PRICE;
$invoice->balance = PRO_PLAN_PRICE;
$invoice->save();
$item = new InvoiceItem();
$item->account_id = $account->id;
$item->user_id = $account->users()->first()->id;
$item->public_id = $publicId;
$item->qty = 1;
$item->cost = PRO_PLAN_PRICE;
$item->notes = trans('texts.pro_plan_description');
$item->product_key = trans('texts.pro_plan_product');
$invoice->invoice_items()->save($item);
$invitation = new Invitation();
$invitation->account_id = $account->id;
$invitation->user_id = $account->users()->first()->id;
$invitation->public_id = $publicId;
$invitation->invoice_id = $invoice->id;
$invitation->contact_id = $client->contacts()->first()->id;
$invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
$invitation->save();
return $invitation;
}
示例12: fire
public function fire()
{
$this->info(date('Y-m-d') . ' ChargeRenewalInvoices...');
$ninjaAccount = $this->accountRepo->getNinjaAccount();
$invoices = Invoice::whereAccountId($ninjaAccount->id)->whereDueDate(date('Y-m-d'))->where('balance', '>', 0)->with('client')->orderBy('id')->get();
$this->info(count($invoices) . ' invoices found');
foreach ($invoices as $invoice) {
// check if account has switched to free since the invoice was created
$account = Account::find($invoice->client->public_id);
if (!$account) {
continue;
}
$company = $account->company;
if (!$company->plan || $company->plan == PLAN_FREE) {
continue;
}
try {
$this->info("Charging invoice {$invoice->invoice_number}");
$this->paymentService->autoBillInvoice($invoice);
} catch (Exception $exception) {
$this->info('Error: ' . $exception->getMessage());
}
}
$this->info('Done');
}
示例13: store
/**
* @SWG\Post(
* path="/payments",
* summary="Create a payment",
* tags={"payment"},
* @SWG\Parameter(
* in="body",
* name="body",
* @SWG\Schema(ref="#/definitions/Payment")
* ),
* @SWG\Response(
* response=200,
* description="New payment",
* @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Payment"))
* ),
* @SWG\Response(
* response="default",
* description="an ""unexpected"" error"
* )
* )
*/
public function store()
{
$data = Input::all();
$error = false;
if (isset($data['invoice_id'])) {
$invoice = Invoice::scope($data['invoice_id'])->with('client')->first();
if ($invoice) {
$data['invoice'] = $invoice->public_id;
$data['client'] = $invoice->client->public_id;
} else {
$error = trans('validation.not_in', ['attribute' => 'invoice_id']);
}
} else {
$error = trans('validation.not_in', ['attribute' => 'invoice_id']);
}
if (!isset($data['transaction_reference'])) {
$data['transaction_reference'] = '';
}
if ($error) {
return $error;
}
$payment = $this->paymentRepo->save($data);
$payment = Payment::scope($payment->public_id)->with('client', 'contact', 'user', 'invoice')->first();
$transformer = new PaymentTransformer(Auth::user()->account, Input::get('serializer'));
$data = $this->createItem($payment, $transformer, 'payment');
return $this->response($data);
}
示例14: actionInvoice
public function actionInvoice($id)
{
if (Yii::$app->user->identity->type == 'normal') {
return $this->redirect(['update', 'id' => $id]);
}
$admin_id = Yii::$app->user->identity->id;
$model = $this->findModel($id);
$invoice = Invoice::find();
$invoice = $invoice->where('job_id=' . $id);
$invoice = $invoice->orderBy('id DESC');
$invoice = $invoice->asArray();
$invoice = $invoice->limit(1);
$invoice = $invoice->all();
// $companies = Company::find();
// if(Yii::$app->user->identity->type=='normal'){
// $companies = $companies->innerJoin('wolf_admin_to_company wc','wc.company_id=wolf_company.company_id');
// $companies = $companies->where('admin_id='.$admin_id);
// }
// $companies = $companies->orderBy('company_name');
// $companies = $companies->asArray();
// $companies = $companies->all();
$jobScheduleSearch = new JobScheduleSearch(['job_id' => $id]);
$scheduleData = $jobScheduleSearch->search(Yii::$app->request->getQueryParams());
$scheduleData->pagination->pageSize = -1;
//infinite value
return $this->render('invoice', ['model' => $this->findModel($id), 'scheduleData' => $scheduleData, 'jobScheduleSearch' => $jobScheduleSearch, 'invoice' => $invoice]);
}
示例15: 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;
}