本文整理汇总了PHP中app\models\Invoice::createNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Invoice::createNew方法的具体用法?PHP Invoice::createNew怎么用?PHP Invoice::createNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Invoice
的用法示例。
在下文中一共展示了Invoice::createNew方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public function create($clientPublicId = 0)
{
if (!Utils::isPro()) {
return Redirect::to('/invoices/create');
}
$client = null;
if ($clientPublicId) {
$client = Client::scope($clientPublicId)->firstOrFail();
}
$invoice = Invoice::createNew();
$invoice->client = $client;
$invoice->is_quote = true;
$invoice->initialize();
$data = ['entityType' => $invoice->getEntityType(), 'invoice' => $invoice, 'data' => Input::old('data'), 'method' => 'POST', 'url' => 'invoices', 'title' => trans('texts.new_quote')];
$data = array_merge($data, self::getViewModel());
return View::make('invoices.edit', $data);
}
示例2: saveData
private function saveData($source, $entityType, $row, $maps)
{
$transformer = $this->getTransformer($source, $entityType);
$resource = $transformer->transform($row, $maps);
if (!$resource) {
return;
}
$data = $this->fractal->createData($resource)->toArray();
// if the invoice number is blank we'll assign it
if ($entityType == ENTITY_INVOICE && !$data['invoice_number']) {
$account = Auth::user()->account;
$invoice = Invoice::createNew();
$data['invoice_number'] = $account->getNextInvoiceNumber($invoice);
}
if ($this->validate($data, $entityType) !== true) {
return;
}
$entity = $this->{"{$entityType}Repo"}->save($data);
// if the invoice is paid we'll also create a payment record
if ($entityType === ENTITY_INVOICE && isset($row->paid) && $row->paid) {
$this->createPayment($source, $row, $maps, $data['client_id'], $entity->public_id);
}
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: create
public function create($clientPublicId = 0, $isRecurring = false)
{
$client = null;
if ($clientPublicId) {
$client = Client::scope($clientPublicId)->firstOrFail();
}
$invoice = Invoice::createNew();
$invoice->client = $client;
$invoice->is_recurring = $isRecurring;
$invoice->initialize();
$data = ['entityType' => $invoice->getEntityType(), 'invoice' => $invoice, 'data' => Input::old('data'), 'method' => 'POST', 'url' => 'invoices', 'title' => trans('texts.new_invoice')];
$data = array_merge($data, self::getViewModel());
return View::make('invoices.edit', $data);
}
示例8: transformRow
/**
* @param $source
* @param $entityType
* @param $row
* @return bool|mixed
*/
private function transformRow($source, $entityType, $row)
{
$transformer = $this->getTransformer($source, $entityType, $this->maps);
// Create expesnse category
if ($entityType == ENTITY_EXPENSE) {
if (!empty($row->expense_category)) {
$categoryId = $transformer->getExpenseCategoryId($row->expense_category);
if (!$categoryId) {
$category = $this->expenseCategoryRepo->save(['name' => $row->expense_category]);
$this->addExpenseCategoryToMaps($category);
}
}
if (!empty($row->vendor)) {
$vendorId = $transformer->getVendorId($row->vendor);
if (!$vendorId) {
$vendor = $this->vendorRepo->save(['name' => $row->vendor, 'vendor_contact' => []]);
$this->addVendorToMaps($vendor);
}
}
}
$resource = $transformer->transform($row);
if (!$resource) {
return false;
}
$data = $this->fractal->createData($resource)->toArray();
// if the invoice number is blank we'll assign it
if ($entityType == ENTITY_INVOICE && !$data['invoice_number']) {
$account = Auth::user()->account;
$invoice = Invoice::createNew();
$data['invoice_number'] = $account->getNextInvoiceNumber($invoice);
}
if (EntityModel::validate($data, $entityType) !== true) {
return false;
}
if ($entityType == ENTITY_INVOICE) {
if (empty($this->processedRows[$data['invoice_number']])) {
$this->processedRows[$data['invoice_number']] = $data;
} else {
// Merge invoice items
$this->processedRows[$data['invoice_number']]['invoice_items'] = array_merge($this->processedRows[$data['invoice_number']]['invoice_items'], $data['invoice_items']);
return true;
}
} else {
$this->processedRows[] = $data;
}
end($this->processedRows);
return key($this->processedRows);
}
示例9: transformRow
/**
* @param $source
* @param $entityType
* @param $row
* @return bool|mixed
*/
private function transformRow($source, $entityType, $row)
{
$transformer = $this->getTransformer($source, $entityType, $this->maps);
$resource = $transformer->transform($row);
if (!$resource) {
return false;
}
$data = $this->fractal->createData($resource)->toArray();
// if the invoice number is blank we'll assign it
if ($entityType == ENTITY_INVOICE && !$data['invoice_number']) {
$account = Auth::user()->account;
$invoice = Invoice::createNew();
$data['invoice_number'] = $account->getNextInvoiceNumber($invoice);
}
if (EntityModel::validate($data, $entityType) !== true) {
return false;
}
if ($entityType == ENTITY_INVOICE) {
if (empty($this->processedRows[$data['invoice_number']])) {
$this->processedRows[$data['invoice_number']] = $data;
} else {
// Merge invoice items
$this->processedRows[$data['invoice_number']]['invoice_items'] = array_merge($this->processedRows[$data['invoice_number']]['invoice_items'], $data['invoice_items']);
return true;
}
} else {
$this->processedRows[] = $data;
}
end($this->processedRows);
return key($this->processedRows);
}
示例10: 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');
}