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


PHP Product::findProductByKey方法代码示例

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


在下文中一共展示了Product::findProductByKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: prepareItem

 private function prepareItem($item)
 {
     $fields = ['cost' => 0, 'product_key' => '', 'notes' => '', 'qty' => 1];
     foreach ($fields as $key => $val) {
         if (!isset($item[$key])) {
             $item[$key] = $val;
         }
     }
     // if only the product key is set we'll load the cost and notes
     if ($item['product_key'] && (!$item['cost'] || !$item['notes'])) {
         $product = Product::findProductByKey($item['product_key']);
         if ($product) {
             if (!$item['cost']) {
                 $item['cost'] = $product->cost;
             }
             if (!$item['notes']) {
                 $item['notes'] = $product->notes;
             }
         }
     }
     return $item;
 }
开发者ID:n-a-m-e,项目名称:invoice-ninja,代码行数:22,代码来源:InvoiceApiController.php

示例2: 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;
 }
开发者ID:saratonite,项目名称:invoiceninja,代码行数:101,代码来源:InvoiceRepository.php

示例3: save


//.........这里部分代码省略.........
     $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;
     }
     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 ($item['product_key'] && !$invoice->has_tasks) {
                 $product = Product::findProductByKey(trim($item['product_key']));
                 if (!$product) {
                     $product = Product::createNew();
                     $product->product_key = trim($item['product_key']);
                 }
                 if (\Auth::user()->account->update_products) {
                     $product->notes = $item['notes'];
                     $product->cost = $item['cost'];
                 }
                 $product->save();
             }
         }
         $invoiceItem = InvoiceItem::createNew();
         $invoiceItem->product_id = isset($product) ? $product->id : null;
         $invoiceItem->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;
 }
开发者ID:hanspoelmans,项目名称:invoice-ninja,代码行数:101,代码来源:InvoiceRepository.php

示例4: 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;
 }
开发者ID:rafaelsisweb,项目名称:invoice-ninja,代码行数:101,代码来源:InvoiceRepository.php


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