public function isTrashed() { if ($this->client && $this->client->isTrashed()) { return true; } return parent::isTrashed(); }
public function process() { $invoice = $this->stateInvoice(); $invoiceItems = $this->requestInvoiceItems(); $data = array_merge($this->requestFields(), ['public_id' => $invoice->public_id, 'invoice_items' => array_merge($invoice->invoice_items->toArray(), $invoiceItems)]); // map the cost and qty fields to the invoice items if (isset($data['cost']) || isset($data['quantity'])) { foreach ($data['invoice_items'] as $key => $item) { // if it's new or we recently created it if (empty($item['public_id']) || in_array($item['public_id'], $this->entities(ENTITY_INVOICE_ITEM))) { $data['invoice_items'][$key]['cost'] = isset($data['cost']) ? $data['cost'] : $item['cost']; $data['invoice_items'][$key]['qty'] = isset($data['quantity']) ? $data['quantity'] : $item['qty']; } } } //var_dump($data); $valid = EntityModel::validate($data, ENTITY_INVOICE, $invoice); if ($valid !== true) { throw new Exception($valid); } $invoice = $this->invoiceRepo->save($data, $invoice); $invoiceItems = array_slice($invoice->invoice_items->toArray(), count($invoiceItems) * -1); $invoiceItemIds = array_map(function ($item) { return $item['public_id']; }, $invoiceItems); $this->setStateEntities(ENTITY_INVOICE_ITEM, $invoiceItemIds); $response = $invoice->load('invoice_items')->present()->skypeBot; return $this->createResponse(SKYPE_CARD_RECEIPT, $response); }
public function toArray() { $array = parent::toArray(); if (empty($this->visible) || in_array('converted_amount', $this->visible)) { $array['converted_amount'] = $this->convertedAmount(); } return $array; }
public function process() { $client = $this->requestClient(); $invoiceItems = $this->requestInvoiceItems(); if (!$client) { throw new Exception(trans('texts.client_not_found')); } $data = array_merge($this->requestFields(), ['client_id' => $client->id, 'invoice_items' => $invoiceItems]); //var_dump($data); $valid = EntityModel::validate($data, ENTITY_INVOICE); if ($valid !== true) { throw new Exception($valid); } $invoiceService = app('App\\Services\\InvoiceService'); $invoice = $invoiceService->save($data); $invoiceItemIds = array_map(function ($item) { return $item['public_id']; }, $invoice->invoice_items->toArray()); $this->setStateEntityType(ENTITY_INVOICE); $this->setStateEntities(ENTITY_CLIENT, $client->public_id); $this->setStateEntities(ENTITY_INVOICE, $invoice->public_id); $this->setStateEntities(ENTITY_INVOICE_ITEM, $invoiceItemIds); return $this->createResponse(SKYPE_CARD_RECEIPT, $invoice->present()->skypeBot); }
public static function renderHtml($accountId) { $lastClientId = false; $clientMap = []; $str = ''; $history = Session::get(RECENTLY_VIEWED, []); $history = isset($history[$accountId]) ? $history[$accountId] : []; foreach ($history as $item) { if ($item->entityType == ENTITY_CLIENT && isset($clientMap[$item->client_id])) { continue; } $clientMap[$item->client_id] = true; if ($lastClientId === false || $item->client_id != $lastClientId) { $icon = '<i class="fa fa-users" style="width:32px"></i>'; if ($item->client_id) { $link = url('/clients/' . $item->client_id); $name = $item->client_name; $buttonLink = url('/invoices/create/' . $item->client_id); $button = '<a type="button" class="btn btn-primary btn-sm pull-right" href="' . $buttonLink . '"> <i class="fa fa-plus-circle" style="width:20px" title="' . trans('texts.create_invoice') . '"></i> </a>'; } else { $link = '#'; $name = trans('texts.unassigned'); $button = ''; } $str .= sprintf('<li>%s<a href="%s"><div>%s %s</div></a></li>', $button, $link, $icon, $name); $lastClientId = $item->client_id; } if ($item->entityType == ENTITY_CLIENT) { continue; } $icon = '<i class="fa fa-' . EntityModel::getIcon($item->entityType . 's') . '" style="width:24px"></i>'; $str .= sprintf('<li style="text-align:right; padding-right:18px;"><a href="%s">%s %s</a></li>', $item->url, $item->name, $icon); } return $str; }
/** * @return array */ public function toArray() { $array = parent::toArray(); if (empty($this->visible) || in_array('url', $this->visible)) { $array['url'] = $this->getUrl(); } if (empty($this->visible) || in_array('preview_url', $this->visible)) { $array['preview_url'] = $this->getPreviewUrl(); } return $array; }
protected function itemResponse($item) { $transformerClass = EntityModel::getTransformerName($this->entityType); $transformer = new $transformerClass(Auth::user()->account, Input::get('serializer')); $data = $this->createItem($item, $transformer, $this->entityType); return $this->response($data); }
private function init() { EntityModel::$notifySubscriptions = false; foreach ([ENTITY_CLIENT, ENTITY_INVOICE, ENTITY_PAYMENT, ENTITY_QUOTE] as $entityType) { $this->results[$entityType] = [RESULT_SUCCESS => [], RESULT_FAILURE => []]; } }