本文整理汇总了PHP中app\models\Product::createNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::createNew方法的具体用法?PHP Product::createNew怎么用?PHP Product::createNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Product
的用法示例。
在下文中一共展示了Product::createNew方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
public function save($data, $product = null)
{
$publicId = isset($data['public_id']) ? $data['public_id'] : false;
if ($product) {
// do nothing
} elseif ($publicId) {
$product = Product::scope($publicId)->firstOrFail();
\Log::warning('Entity not set in product repo save');
} else {
$product = Product::createNew();
}
$product->fill($data);
$product->save();
return $product;
}
示例2: save
private function save($productPublicId = false)
{
if ($productPublicId) {
$product = Product::scope($productPublicId)->firstOrFail();
} else {
$product = Product::createNew();
}
$product->product_key = trim(Input::get('product_key'));
$product->notes = trim(Input::get('notes'));
$product->cost = trim(Input::get('cost'));
$product->save();
$message = $productPublicId ? trans('texts.updated_product') : trans('texts.created_product');
Session::flash('message', $message);
return Redirect::to('company/products');
}
示例3: save
private function save($productPublicId = false)
{
if ($productPublicId) {
$product = Product::scope($productPublicId)->firstOrFail();
} else {
$product = Product::createNew();
}
$product->product_key = trim(Input::get('product_key'));
$product->notes = trim(Input::get('notes'));
$product->cost = trim(Input::get('cost'));
$product->default_tax_rate_id = Input::get('default_tax_rate_id');
$product->save();
$message = $productPublicId ? trans('texts.updated_product') : trans('texts.created_product');
Session::flash('message', $message);
return Redirect::to('settings/' . ACCOUNT_PRODUCTS);
}
示例4: save
private function save($productPublicId = false)
{
if ($productPublicId) {
$product = Product::scope($productPublicId)->firstOrFail();
} else {
$product = Product::createNew();
}
$product->product_key = trim(Input::get('product_key'));
$product->notes = trim(Input::get('notes'));
$product->cost = trim(Input::get('cost'));
//$product->default_tax_rate_id = Input::get('default_tax_rate_id');
$product->save();
$transformer = new ProductTransformer(\Auth::user()->account, Input::get('serializer'));
$data = $this->createItem($product, $transformer, 'products');
return $this->response($data);
}
示例5: save
public function save($publicId, $data, $entityType)
{
if ($publicId) {
$invoice = Invoice::scope($publicId)->firstOrFail();
} else {
$invoice = Invoice::createNew();
if ($entityType == ENTITY_QUOTE) {
$invoice->is_quote = true;
}
}
$account = \Auth::user()->account;
if (isset($data['set_default_terms']) && $data['set_default_terms'] || isset($data['set_default_footer']) && $data['set_default_footer']) {
if (isset($data['set_default_terms']) && $data['set_default_terms']) {
$account->invoice_terms = trim($data['terms']);
}
if (isset($data['set_default_footer']) && $data['set_default_footer']) {
$account->invoice_footer = trim($data['invoice_footer']);
}
$account->save();
}
if (isset($data['invoice_number'])) {
$invoice->invoice_number = trim($data['invoice_number']);
}
$invoice->discount = round(Utils::parseFloat($data['discount']), 2);
$invoice->is_amount_discount = $data['is_amount_discount'] ? true : false;
$invoice->partial = round(Utils::parseFloat($data['partial']), 2);
$invoice->invoice_date = isset($data['invoice_date_sql']) ? $data['invoice_date_sql'] : Utils::toSqlDate($data['invoice_date']);
$invoice->has_tasks = isset($data['has_tasks']) ? $data['has_tasks'] : false;
if (!$publicId) {
$invoice->client_id = $data['client_id'];
$invoice->is_recurring = $data['is_recurring'] && !Utils::isDemo() ? true : false;
}
if ($invoice->is_recurring) {
$invoice->frequency_id = $data['frequency_id'] ? $data['frequency_id'] : 0;
$invoice->start_date = Utils::toSqlDate($data['start_date']);
$invoice->end_date = Utils::toSqlDate($data['end_date']);
$invoice->due_date = null;
} else {
$invoice->due_date = isset($data['due_date_sql']) ? $data['due_date_sql'] : Utils::toSqlDate($data['due_date']);
$invoice->frequency_id = 0;
$invoice->start_date = null;
$invoice->end_date = null;
}
$invoice->terms = trim($data['terms']) ? trim($data['terms']) : (!$publicId && $account->invoice_terms ? $account->invoice_terms : '');
$invoice->invoice_footer = trim($data['invoice_footer']) ? trim($data['invoice_footer']) : (!$publicId && $account->invoice_footer ? $account->invoice_footer : '');
$invoice->public_notes = trim($data['public_notes']);
// process date variables
$invoice->terms = Utils::processVariables($invoice->terms);
$invoice->invoice_footer = Utils::processVariables($invoice->invoice_footer);
$invoice->public_notes = Utils::processVariables($invoice->public_notes);
$invoice->po_number = trim($data['po_number']);
$invoice->invoice_design_id = $data['invoice_design_id'];
if (isset($data['tax_name']) && isset($data['tax_rate']) && $data['tax_name']) {
$invoice->tax_rate = Utils::parseFloat($data['tax_rate']);
$invoice->tax_name = trim($data['tax_name']);
} else {
$invoice->tax_rate = 0;
$invoice->tax_name = '';
}
$total = 0;
foreach ($data['invoice_items'] as $item) {
$item = (array) $item;
if (!$item['cost'] && !$item['product_key'] && !$item['notes']) {
continue;
}
$invoiceItemCost = round(Utils::parseFloat($item['cost']), 2);
$invoiceItemQty = round(Utils::parseFloat($item['qty']), 2);
$invoiceItemTaxRate = 0;
if (isset($item['tax_rate']) && Utils::parseFloat($item['tax_rate']) > 0) {
$invoiceItemTaxRate = Utils::parseFloat($item['tax_rate']);
}
$lineTotal = $invoiceItemCost * $invoiceItemQty;
$total += round($lineTotal + $lineTotal * $invoiceItemTaxRate / 100, 2);
}
if ($invoice->discount > 0) {
if ($invoice->is_amount_discount) {
$total -= $invoice->discount;
} else {
$total *= (100 - $invoice->discount) / 100;
}
}
$invoice->custom_value1 = round($data['custom_value1'], 2);
$invoice->custom_value2 = round($data['custom_value2'], 2);
$invoice->custom_taxes1 = $data['custom_taxes1'] ? true : false;
$invoice->custom_taxes2 = $data['custom_taxes2'] ? true : false;
// custom fields charged taxes
if ($invoice->custom_value1 && $invoice->custom_taxes1) {
$total += $invoice->custom_value1;
}
if ($invoice->custom_value2 && $invoice->custom_taxes2) {
$total += $invoice->custom_value2;
}
$total += $total * $invoice->tax_rate / 100;
$total = round($total, 2);
// custom fields not charged taxes
if ($invoice->custom_value1 && !$invoice->custom_taxes1) {
$total += $invoice->custom_value1;
}
if ($invoice->custom_value2 && !$invoice->custom_taxes2) {
$total += $invoice->custom_value2;
//.........这里部分代码省略.........
示例6: save
//.........这里部分代码省略.........
if ($invoice->is_amount_discount) {
$lineTotal -= round($lineTotal / $total * $invoice->discount, 2);
} else {
$lineTotal -= round($lineTotal * ($invoice->discount / 100), 2);
}
}
$itemTax += round($lineTotal * $invoiceItemTaxRate / 100, 2);
}
}
if ($invoice->discount > 0) {
if ($invoice->is_amount_discount) {
$total -= $invoice->discount;
} else {
$total *= (100 - $invoice->discount) / 100;
}
}
if (isset($data['custom_value1'])) {
$invoice->custom_value1 = round($data['custom_value1'], 2);
if ($isNew) {
$invoice->custom_taxes1 = $account->custom_invoice_taxes1 ?: false;
}
}
if (isset($data['custom_value2'])) {
$invoice->custom_value2 = round($data['custom_value2'], 2);
if ($isNew) {
$invoice->custom_taxes2 = $account->custom_invoice_taxes2 ?: false;
}
}
if (isset($data['custom_text_value1'])) {
$invoice->custom_text_value1 = trim($data['custom_text_value1']);
}
if (isset($data['custom_text_value2'])) {
$invoice->custom_text_value2 = trim($data['custom_text_value2']);
}
// custom fields charged taxes
if ($invoice->custom_value1 && $invoice->custom_taxes1) {
$total += $invoice->custom_value1;
}
if ($invoice->custom_value2 && $invoice->custom_taxes2) {
$total += $invoice->custom_value2;
}
$total += $total * $invoice->tax_rate / 100;
$total = round($total, 2);
$total += $itemTax;
// custom fields not charged taxes
if ($invoice->custom_value1 && !$invoice->custom_taxes1) {
$total += $invoice->custom_value1;
}
if ($invoice->custom_value2 && !$invoice->custom_taxes2) {
$total += $invoice->custom_value2;
}
if ($publicId) {
$invoice->balance = $total - ($invoice->amount - $invoice->balance);
} else {
$invoice->balance = $total;
}
$invoice->amount = $total;
$invoice->save();
if ($publicId) {
$invoice->invoice_items()->forceDelete();
}
foreach ($data['invoice_items'] as $item) {
$item = (array) $item;
if (!$item['cost'] && !$item['product_key'] && !$item['notes']) {
continue;
}
if (isset($item['task_public_id']) && $item['task_public_id']) {
$task = Task::scope($item['task_public_id'])->where('invoice_id', '=', null)->firstOrFail();
$task->invoice_id = $invoice->id;
$task->client_id = $invoice->client_id;
$task->save();
} else {
if (isset($item['product_key']) && $item['product_key'] && !$invoice->has_tasks) {
$product = Product::findProductByKey(trim($item['product_key']));
if (\Auth::user()->account->update_products) {
if (!$product) {
$product = Product::createNew();
$product->product_key = trim($item['product_key']);
}
$product->notes = $item['notes'];
$product->cost = $item['cost'];
$product->save();
}
}
}
$invoiceItem = InvoiceItem::createNew();
$invoiceItem->product_id = isset($product) ? $product->id : null;
$invoiceItem->product_key = isset($item['product_key']) ? trim($invoice->is_recurring ? $item['product_key'] : Utils::processVariables($item['product_key'])) : '';
$invoiceItem->notes = trim($invoice->is_recurring ? $item['notes'] : Utils::processVariables($item['notes']));
$invoiceItem->cost = Utils::parseFloat($item['cost']);
$invoiceItem->qty = Utils::parseFloat($item['qty']);
$invoiceItem->tax_rate = 0;
if (isset($item['tax_rate']) && isset($item['tax_name']) && $item['tax_name']) {
$invoiceItem['tax_rate'] = Utils::parseFloat($item['tax_rate']);
$invoiceItem['tax_name'] = trim($item['tax_name']);
}
$invoice->invoice_items()->save($invoiceItem);
}
return $invoice;
}
示例7: save
//.........这里部分代码省略.........
if ($publicId) {
$invoice->balance = $total - ($invoice->amount - $invoice->balance);
} else {
$invoice->balance = $total;
}
$invoice->amount = $total;
$invoice->save();
if ($publicId) {
$invoice->invoice_items()->forceDelete();
}
$document_ids = !empty($data['document_ids']) ? array_map('intval', $data['document_ids']) : [];
foreach ($document_ids as $document_id) {
$document = Document::scope($document_id)->first();
if ($document && Auth::user()->can('edit', $document)) {
if ($document->invoice_id && $document->invoice_id != $invoice->id) {
// From a clone
$document = $document->cloneDocument();
$document_ids[] = $document->public_id;
// Don't remove this document
}
$document->invoice_id = $invoice->id;
$document->expense_id = null;
$document->save();
}
}
if (!$invoice->wasRecentlyCreated) {
foreach ($invoice->documents as $document) {
if (!in_array($document->public_id, $document_ids)) {
// Removed
// Not checking permissions; deleting a document is just editing the invoice
if ($document->invoice_id == $invoice->id) {
// Make sure the document isn't on a clone
$document->delete();
}
}
}
}
foreach ($data['invoice_items'] as $item) {
$item = (array) $item;
if (empty($item['cost']) && empty($item['product_key']) && empty($item['notes']) && empty($item['custom_value1']) && empty($item['custom_value2'])) {
continue;
}
$task = false;
if (isset($item['task_public_id']) && $item['task_public_id']) {
$task = Task::scope($item['task_public_id'])->where('invoice_id', '=', null)->firstOrFail();
if (Auth::user()->can('edit', $task)) {
$task->invoice_id = $invoice->id;
$task->client_id = $invoice->client_id;
$task->save();
}
}
$expense = false;
if (isset($item['expense_public_id']) && $item['expense_public_id']) {
$expense = Expense::scope($item['expense_public_id'])->where('invoice_id', '=', null)->firstOrFail();
if (Auth::user()->can('edit', $expense)) {
$expense->invoice_id = $invoice->id;
$expense->client_id = $invoice->client_id;
$expense->save();
}
}
if ($productKey = trim($item['product_key'])) {
if (\Auth::user()->account->update_products && !$invoice->has_tasks && !$invoice->has_expenses) {
$product = Product::findProductByKey($productKey);
if (!$product) {
if (Auth::user()->can('create', ENTITY_PRODUCT)) {
$product = Product::createNew();
$product->product_key = trim($item['product_key']);
} else {
$product = null;
}
}
if ($product && Auth::user()->can('edit', $product)) {
$product->notes = $task || $expense ? '' : $item['notes'];
$product->cost = $expense ? 0 : $item['cost'];
$product->save();
}
}
}
$invoiceItem = InvoiceItem::createNew();
$invoiceItem->product_id = isset($product) ? $product->id : null;
$invoiceItem->product_key = isset($item['product_key']) ? trim($invoice->is_recurring ? $item['product_key'] : Utils::processVariables($item['product_key'])) : '';
$invoiceItem->notes = trim($invoice->is_recurring ? $item['notes'] : Utils::processVariables($item['notes']));
$invoiceItem->cost = Utils::parseFloat($item['cost']);
$invoiceItem->qty = Utils::parseFloat($item['qty']);
if (isset($item['custom_value1'])) {
$invoiceItem->custom_value1 = $item['custom_value1'];
}
if (isset($item['custom_value2'])) {
$invoiceItem->custom_value2 = $item['custom_value2'];
}
// provide backwards compatability
if (isset($item['tax_name']) && isset($item['tax_rate'])) {
$item['tax_name1'] = $item['tax_name'];
$item['tax_rate1'] = $item['tax_rate'];
}
$invoiceItem->fill($item);
$invoice->invoice_items()->save($invoiceItem);
}
return $invoice;
}