public static function addVendor(ServerRequestInterface $request, ResponseInterface $response) { $om = static::getObjectManager(); $vendor = new Vendor(); $vendor->setName('Vendor ' . time()); $om->persist($vendor); $om->flush(); $response->getBody()->write(static::getTemplateRenderer()->render('index/add-vendor', ['vendor' => $vendor])); }
public function findVendor($vendorPublicId) { $vendorId = Vendor::getPrivateId($vendorPublicId); $accountid = \Auth::user()->account_id; $query = DB::table('expenses')->join('accounts', 'accounts.id', '=', 'expenses.account_id')->where('expenses.account_id', '=', $accountid)->where('expenses.vendor_id', '=', $vendorId)->select('expenses.id', 'expenses.expense_date', 'expenses.amount', 'expenses.public_notes', 'expenses.public_id', 'expenses.deleted_at', 'expenses.should_be_invoiced', 'expenses.created_at'); return $query; }
public function save($data, $vendor = null) { $publicId = isset($data['public_id']) ? $data['public_id'] : false; if ($vendor) { // do nothing } elseif (!$publicId || $publicId == '-1') { $vendor = Vendor::createNew(); } else { $vendor = Vendor::scope($publicId)->with('vendor_contacts')->firstOrFail(); if (Utils::isNinjaDev()) { \Log::warning('Entity not set in vendor repo save'); } } if ($vendor->is_deleted) { return $vendor; } $vendor->fill($data); $vendor->save(); $first = true; $vendorcontacts = isset($data['vendor_contact']) ? [$data['vendor_contact']] : $data['vendor_contacts']; $vendorcontactIds = []; foreach ($vendorcontacts as $vendorcontact) { $vendorcontact = $vendor->addVendorContact($vendorcontact, $first); $vendorcontactIds[] = $vendorcontact->public_id; $first = false; } if (!$vendor->wasRecentlyCreated) { foreach ($vendor->vendor_contacts as $contact) { if (!in_array($contact->public_id, $vendorcontactIds)) { $contact->delete(); } } } return $vendor; }
/** * @SWG\Post( * path="/vendors", * tags={"vendor"}, * summary="Create a vendor", * @SWG\Parameter( * in="body", * name="body", * @SWG\Schema(ref="#/definitions/Vendor") * ), * @SWG\Response( * response=200, * description="New vendor", * @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Vendor")) * ), * @SWG\Response( * response="default", * description="an ""unexpected"" error" * ) * ) */ public function store(CreateVendorRequest $request) { $vendor = $this->vendorRepo->save($request->input()); $vendor = Vendor::scope($vendor->public_id)->with('country', 'vendorcontacts', 'industry', 'size', 'currency')->first(); $transformer = new VendorTransformer(Auth::user()->account, Input::get('serializer')); $data = $this->createItem($vendor, $transformer, ENTITY_VENDOR); return $this->response($data); }
/** * Show the form for creating a new resource. * * @return Response */ public function create(VendorRequest $request) { if (Vendor::scope()->count() > Auth::user()->getMaxNumVendors()) { return View::make('error', ['hideHeader' => true, 'error' => "Sorry, you've exceeded the limit of " . Auth::user()->getMaxNumVendors() . ' vendors']); } $data = ['vendor' => null, 'method' => 'POST', 'url' => 'vendors', 'title' => trans('texts.new_vendor')]; $data = array_merge($data, self::getViewModel()); return View::make('vendors.edit', $data); }
public function vendorEmail() { $vendor = Vendor::find($this->vendor_id); if ($vendor && $vendor->email) { return $vendor->email; } else { return null; } }
public function save($data) { if (isset($data['client_id']) && $data['client_id']) { $data['client_id'] = Client::getPrivateId($data['client_id']); } if (isset($data['vendor_id']) && $data['vendor_id']) { $data['vendor_id'] = Vendor::getPrivateId($data['vendor_id']); } return $this->expenseRepo->save($data); }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // $obj = new Item(); $cols = $obj->current_columns(); $this->data['item'] = $cols; $this->data['vendor'] = Vendor::lists('name', 'id'); $measure = array(0 => 'US-Imperal', 1 => 'CA-Imperal', 2 => 'GB-Imperal'); $this->data['measure'] = $measure; $this->data['body'] = 'public.home.create'; return $this->output(); }
public function create() { $obj = new Item(); $cols = $obj->current_columns(); $this->data['item'] = $cols; $new_obj = new ItemRequest(); return dd($new_obj->rules()); $this->data['vendor'] = Vendor::lists('name', 'id'); $measure = array(0 => 'US-Imperal', 1 => 'CA-Imperal', 2 => 'GB-Imperal'); $this->data['measure'] = $measure; $this->data['title'] = "Management Warehouses"; $this->data['body'] = 'public.home.index'; return $this->output(); }
public function save($data) { $publicId = isset($data['public_id']) ? $data['public_id'] : false; if (!$publicId || $publicId == '-1') { $vendor = Vendor::createNew(); } else { $vendor = Vendor::scope($publicId)->with('vendorcontacts')->firstOrFail(); } $vendor->fill($data); $vendor->save(); $first = true; $vendorcontacts = isset($data['vendorcontact']) ? [$data['vendorcontact']] : $data['vendorcontacts']; foreach ($vendorcontacts as $vendorcontact) { $vendorcontact = $vendor->addVendorContact($vendorcontact, $first); $first = false; } return $vendor; }
public function save($data, $vendor = null) { $publicId = isset($data['public_id']) ? $data['public_id'] : false; if ($vendor) { // do nothing } elseif (!$publicId || $publicId == '-1') { $vendor = Vendor::createNew(); } else { $vendor = Vendor::scope($publicId)->with('vendor_contacts')->firstOrFail(); \Log::warning('Entity not set in vendor repo save'); } $vendor->fill($data); $vendor->save(); $first = true; $vendorcontacts = isset($data['vendor_contact']) ? [$data['vendor_contact']] : $data['vendor_contacts']; foreach ($vendorcontacts as $vendorcontact) { $vendorcontact = $vendor->addVendorContact($vendorcontact, $first); $first = false; } return $vendor; }
public function edit(ExpenseRequest $request) { $expense = $request->entity(); $expense->expense_date = Utils::fromSqlDate($expense->expense_date); $actions = []; if ($expense->invoice) { $actions[] = ['url' => URL::to("invoices/{$expense->invoice->public_id}/edit"), 'label' => trans("texts.view_invoice")]; } else { $actions[] = ['url' => 'javascript:submitAction("invoice")', 'label' => trans("texts.invoice_expense")]; } $actions[] = \DropdownButton::DIVIDER; if (!$expense->trashed()) { $actions[] = ['url' => 'javascript:submitAction("archive")', 'label' => trans('texts.archive_expense')]; $actions[] = ['url' => 'javascript:onDeleteClick()', 'label' => trans('texts.delete_expense')]; } else { $actions[] = ['url' => 'javascript:submitAction("restore")', 'label' => trans('texts.restore_expense')]; } $data = array('vendor' => null, 'expense' => $expense, 'method' => 'PUT', 'url' => 'expenses/' . $expense->public_id, 'title' => 'Edit Expense', 'actions' => $actions, 'vendors' => Vendor::scope()->with('vendor_contacts')->orderBy('name')->get(), 'vendorPublicId' => $expense->vendor ? $expense->vendor->public_id : null, 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), 'clientPublicId' => $expense->client ? $expense->client->public_id : null); $data = array_merge($data, self::getViewModel()); return View::make('expenses.edit', $data); }
protected function getDatatableColumns($entityType, $hideClient) { return [['vendor_name', function ($model) { if ($model->vendor_public_id) { if (!Vendor::canViewItemByOwner($model->vendor_user_id)) { return $model->vendor_name; } return link_to("vendors/{$model->vendor_public_id}", $model->vendor_name)->toHtml(); } else { return ''; } }], ['client_name', function ($model) { if ($model->client_public_id) { if (!Client::canViewItemByOwner($model->client_user_id)) { return Utils::getClientDisplayName($model); } return link_to("clients/{$model->client_public_id}", Utils::getClientDisplayName($model))->toHtml(); } else { return ''; } }], ['expense_date', function ($model) { if (!Expense::canEditItemByOwner($model->user_id)) { return Utils::fromSqlDate($model->expense_date); } return link_to("expenses/{$model->public_id}/edit", Utils::fromSqlDate($model->expense_date))->toHtml(); }], ['amount', function ($model) { // show both the amount and the converted amount if ($model->exchange_rate != 1) { $converted = round($model->amount * $model->exchange_rate, 2); return Utils::formatMoney($model->amount, $model->expense_currency_id) . ' | ' . Utils::formatMoney($converted, $model->invoice_currency_id); } else { return Utils::formatMoney($model->amount, $model->expense_currency_id); } }], ['public_notes', function ($model) { return $model->public_notes != null ? substr($model->public_notes, 0, 100) : ''; }], ['expense_status_id', function ($model) { return self::getStatusLabel($model->invoice_id, $model->should_be_invoiced); }]]; }
private function createVendorMap() { $vendorMap = []; $vendors = Vendor::scope()->withTrashed()->get(['id', 'name', 'transaction_name']); foreach ($vendors as $vendor) { $vendorMap[strtolower($vendor->name)] = $vendor; $vendorMap[strtolower($vendor->transaction_name)] = $vendor; } return $vendorMap; }
public function includeVendor(Product $product) { $vendor = Vendor::find($product->vendor_id); return $this->item($vendor, new VendorTransformer()); }
public function edit($publicId) { $expense = Expense::scope($publicId)->firstOrFail(); $expense->expense_date = Utils::fromSqlDate($expense->expense_date); $actions = []; if ($expense->invoice) { $actions[] = ['url' => URL::to("invoices/{$expense->invoice->public_id}/edit"), 'label' => trans("texts.view_invoice")]; } else { $actions[] = ['url' => 'javascript:submitAction("invoice")', 'label' => trans("texts.invoice_expense")]; /* // check for any open invoices $invoices = $task->client_id ? $this->invoiceRepo->findOpenInvoices($task->client_id) : []; foreach ($invoices as $invoice) { $actions[] = ['url' => 'javascript:submitAction("add_to_invoice", '.$invoice->public_id.')', 'label' => trans("texts.add_to_invoice", ["invoice" => $invoice->invoice_number])]; } */ } $actions[] = \DropdownButton::DIVIDER; if (!$expense->trashed()) { $actions[] = ['url' => 'javascript:submitAction("archive")', 'label' => trans('texts.archive_expense')]; $actions[] = ['url' => 'javascript:onDeleteClick()', 'label' => trans('texts.delete_expense')]; } else { $actions[] = ['url' => 'javascript:submitAction("restore")', 'label' => trans('texts.restore_expense')]; } $data = array('vendor' => null, 'expense' => $expense, 'method' => 'PUT', 'url' => 'expenses/' . $publicId, 'title' => 'Edit Expense', 'actions' => $actions, 'vendors' => Vendor::scope()->with('vendorcontacts')->orderBy('name')->get(), 'vendorPublicId' => $expense->vendor ? $expense->vendor->public_id : null, 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), 'clientPublicId' => $expense->client ? $expense->client->public_id : null); $data = array_merge($data, self::getViewModel()); if (Auth::user()->account->isNinjaAccount()) { if ($account = Account::whereId($client->public_id)->first()) { $data['proPlanPaid'] = $account['pro_plan_paid']; } } return View::make('expenses.edit', $data); }
public function importExpenses($bankId, $input) { $countVendors = 0; $countExpenses = 0; // create a vendor map $vendorMap = []; $vendors = Vendor::scope()->withTrashed()->get(['id', 'name', 'transaction_name']); foreach ($vendors as $vendor) { $vendorMap[strtolower($vendor->name)] = $vendor; $vendorMap[strtolower($vendor->transaction_name)] = $vendor; } foreach ($input as $transaction) { $vendorName = $transaction['vendor']; $key = strtolower($vendorName); $info = $transaction['info']; // find vendor otherwise create it if (isset($vendorMap[$key])) { $vendor = $vendorMap[$key]; } else { $field = $this->determineInfoField($info); $vendor = $this->vendorRepo->save([$field => $info, 'name' => $vendorName, 'transaction_name' => $transaction['vendor_orig'], 'vendorcontact' => []]); $vendorMap[$key] = $vendor; $vendorMap[$transaction['vendor_orig']] = $vendor; $countVendors++; } // create the expense record $this->expenseRepo->save(['vendor_id' => $vendor->id, 'amount' => $transaction['amount'], 'public_notes' => $transaction['memo'], 'expense_date' => $transaction['date'], 'transaction_id' => $transaction['id'], 'bank_id' => $bankId, 'should_be_invoiced' => true]); $countExpenses++; } return trans('texts.imported_expenses', ['count_vendors' => $countVendors, 'count_expenses' => $countExpenses]); }
/** * Bootstrap any application services. * * @return void */ public function boot() { Form::macro('image_data', function ($imagePath) { return 'data:image/jpeg;base64,' . base64_encode(file_get_contents($imagePath)); }); Form::macro('nav_link', function ($url, $text, $url2 = '', $extra = '') { $capitalize = config('former.capitalize_translations'); $class = Request::is($url) || Request::is($url . '/*') || Request::is($url2 . '/*') ? ' class="active"' : ''; if ($capitalize) { $title = ucwords(trans("texts.{$text}")) . Utils::getProLabel($text); } else { $title = trans("texts.{$text}") . Utils::getProLabel($text); } return '<li' . $class . '><a href="' . URL::to($url) . '" ' . $extra . '>' . $title . '</a></li>'; }); Form::macro('tab_link', function ($url, $text, $active = false) { $class = $active ? ' class="active"' : ''; return '<li' . $class . '><a href="' . URL::to($url) . '" data-toggle="tab">' . $text . '</a></li>'; }); Form::macro('menu_link', function ($type) { $types = $type . 's'; $Type = ucfirst($type); $Types = ucfirst($types); $class = (Request::is($types) || Request::is('*' . $type . '*')) && !Request::is('*settings*') ? ' active' : ''; $str = '<li class="dropdown ' . $class . '"> <a href="' . URL::to($types) . '" class="dropdown-toggle">' . trans("texts.{$types}") . '</a>'; $items = []; if (Auth::user()->hasPermission('create_all')) { $items[] = '<li><a href="' . URL::to($types . '/create') . '">' . trans("texts.new_{$type}") . '</a></li>'; } if ($type == ENTITY_INVOICE) { if (!empty($items)) { $items[] = '<li class="divider"></li>'; } $items[] = '<li><a href="' . URL::to('recurring_invoices') . '">' . trans("texts.recurring_invoices") . '</a></li>'; if (Invoice::canCreate()) { $items[] = '<li><a href="' . URL::to('recurring_invoices/create') . '">' . trans("texts.new_recurring_invoice") . '</a></li>'; } if (Auth::user()->isPro()) { $items[] = '<li class="divider"></li>'; $items[] = '<li><a href="' . URL::to('quotes') . '">' . trans("texts.quotes") . '</a></li>'; if (Invoice::canCreate()) { $items[] = '<li><a href="' . URL::to('quotes/create') . '">' . trans("texts.new_quote") . '</a></li>'; } } } else { if ($type == ENTITY_CLIENT) { if (!empty($items)) { $items[] = '<li class="divider"></li>'; } $items[] = '<li><a href="' . URL::to('credits') . '">' . trans("texts.credits") . '</a></li>'; if (Credit::canCreate()) { $items[] = '<li><a href="' . URL::to('credits/create') . '">' . trans("texts.new_credit") . '</a></li>'; } } else { if ($type == ENTITY_EXPENSE) { if (!empty($items)) { $items[] = '<li class="divider"></li>'; } $items[] = '<li><a href="' . URL::to('vendors') . '">' . trans("texts.vendors") . '</a></li>'; if (Vendor::canCreate()) { $items[] = '<li><a href="' . URL::to('vendors/create') . '">' . trans("texts.new_vendor") . '</a></li>'; } } } } if (!empty($items)) { $str .= '<ul class="dropdown-menu" id="menu1">' . implode($items) . '</ul>'; } $str .= '</li>'; return $str; }); Form::macro('flatButton', function ($label, $color) { return '<input type="button" value="' . trans("texts.{$label}") . '" style="background-color:' . $color . ';border:0 none;border-radius:5px;padding:12px 40px;margin:0 6px;cursor:hand;display:inline-block;font-size:14px;color:#fff;text-transform:none;font-weight:bold;"/>'; }); Form::macro('emailViewButton', function ($link = '#', $entityType = ENTITY_INVOICE) { return view('partials.email_button')->with(['link' => $link, 'field' => "view_{$entityType}", 'color' => '#0b4d78'])->render(); }); Form::macro('emailPaymentButton', function ($link = '#') { return view('partials.email_button')->with(['link' => $link, 'field' => 'pay_now', 'color' => '#36c157'])->render(); }); Form::macro('breadcrumbs', function ($status = false) { $str = '<ol class="breadcrumb">'; // Get the breadcrumbs by exploding the current path. $basePath = Utils::basePath(); $parts = explode('?', isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''); $path = $parts[0]; if ($basePath != '/') { $path = str_replace($basePath, '', $path); } $crumbs = explode('/', $path); foreach ($crumbs as $key => $val) { if (is_numeric($val)) { unset($crumbs[$key]); } } $crumbs = array_values($crumbs); for ($i = 0; $i < count($crumbs); $i++) { $crumb = trim($crumbs[$i]); if (!$crumb) { continue; } if ($crumb == 'company') { return ''; } $name = trans("texts.{$crumb}"); if ($i == count($crumbs) - 1) { $str .= "<li class='active'>{$name}</li>"; } else { $str .= '<li>' . link_to($crumb, $name) . '</li>'; } } if ($status) { $str .= ' ' . $status; } return $str . '</ol>'; }); Validator::extend('positive', function ($attribute, $value, $parameters) { return Utils::parseFloat($value) >= 0; }); Validator::extend('has_credit', function ($attribute, $value, $parameters) { $publicClientId = $parameters[0]; $amount = $parameters[1]; $client = \App\Models\Client::scope($publicClientId)->firstOrFail(); $credit = $client->getTotalCredit(); return $credit >= $amount; }); // check that the time log elements don't overlap Validator::extend('time_log', function ($attribute, $value, $parameters) { $lastTime = 0; $value = json_decode($value); array_multisort($value); foreach ($value as $timeLog) { list($startTime, $endTime) = $timeLog; if (!$endTime) { continue; } if ($startTime < $lastTime || $startTime > $endTime) { return false; } if ($endTime < min($startTime, $lastTime)) { return false; } $lastTime = max($lastTime, $endTime); } return true; }); Validator::extend('less_than', function ($attribute, $value, $parameters) { return floatval($value) <= floatval($parameters[0]); }); Validator::replacer('less_than', function ($message, $attribute, $rule, $parameters) { return str_replace(':value', $parameters[0], $message); }); Validator::extend('has_counter', function ($attribute, $value, $parameters) { return !$value || strstr($value, '{$counter}'); }); Validator::extend('valid_contacts', function ($attribute, $value, $parameters) { foreach ($value as $contact) { $validator = Validator::make($contact, ['email' => 'email|required_without:first_name', 'first_name' => 'required_without:email']); if ($validator->fails()) { return false; } } return true; }); Validator::extend('valid_invoice_items', function ($attribute, $value, $parameters) { $total = 0; foreach ($value as $item) { $qty = isset($item['qty']) ? $item['qty'] : 1; $cost = isset($item['cost']) ? $item['cost'] : 1; $total += $qty * $cost; } return $total <= MAX_INVOICE_AMOUNT; }); }
protected function fakeVendor() { $fakeVendor = new Vendor(); $fakeVendor->serial_number = "V284724"; $fakeVendor->primary_name = "Fake Vendor"; $fakeVendor->vendor_type_id = $this->fakeVendorType()->vendor_type_id; $fakeVendor->save(); return $fakeVendor; }
private function addEditView($id) { $data = array(); $benefit_type = BenefitType::all(); if (count($benefit_type) > 0) { $data["benefit_type"] = $benefit_type; } $vendors = Vendor::all(); if (count($vendors) > 0) { $data["vendors"] = $vendors; } $state = State::all(); if (count($state) > 0) { $data["states"] = $state; } $benefit = Benefit::find($id); if ($benefit) { $data["benefit"] = $benefit; $documents = $benefit->documents; if (count($documents) > 0) { $data["documents"] = $documents; } } return view('index', $data)->with('page', 'benefit_create_edit'); }
/** * Finds the Vendor model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Vendor the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Vendor::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('Продукт с номером ' . $id . ' не обнаружен в базе данных'); } }
/** * @param $request * * @return array */ private function getData($request) { $account = Auth::user()->account; $data = ['account' => $account, 'title' => 'Invoice Ninja v' . NINJA_VERSION . ' - ' . $account->formatDateTime($account->getDateTime()), 'multiUser' => $account->users->count() > 1]; if ($request->input('include') === 'all' || $request->input('clients')) { $data['clients'] = Client::scope()->with('user', 'contacts', 'country')->withArchived()->get(); } if ($request->input('include') === 'all' || $request->input('contacts')) { $data['contacts'] = Contact::scope()->with('user', 'client.contacts')->withTrashed()->get(); } if ($request->input('include') === 'all' || $request->input('credits')) { $data['credits'] = Credit::scope()->with('user', 'client.contacts')->get(); } if ($request->input('include') === 'all' || $request->input('tasks')) { $data['tasks'] = Task::scope()->with('user', 'client.contacts')->withArchived()->get(); } if ($request->input('include') === 'all' || $request->input('invoices')) { $data['invoices'] = Invoice::scope()->invoiceType(INVOICE_TYPE_STANDARD)->with('user', 'client.contacts', 'invoice_status')->withArchived()->where('is_recurring', '=', false)->get(); } if ($request->input('include') === 'all' || $request->input('quotes')) { $data['quotes'] = Invoice::scope()->invoiceType(INVOICE_TYPE_QUOTE)->with('user', 'client.contacts', 'invoice_status')->withArchived()->where('is_recurring', '=', false)->get(); } if ($request->input('include') === 'all' || $request->input('recurring')) { $data['recurringInvoices'] = Invoice::scope()->invoiceType(INVOICE_TYPE_STANDARD)->with('user', 'client.contacts', 'invoice_status', 'frequency')->withArchived()->where('is_recurring', '=', true)->get(); } if ($request->input('include') === 'all' || $request->input('payments')) { $data['payments'] = Payment::scope()->withArchived()->with('user', 'client.contacts', 'payment_type', 'invoice', 'account_gateway.gateway')->get(); } if ($request->input('include') === 'all' || $request->input('vendors')) { $data['vendors'] = Vendor::scope()->with('user', 'vendor_contacts', 'country')->withArchived()->get(); } if ($request->input('include') === 'all' || $request->input('vendor_contacts')) { $data['vendor_contacts'] = VendorContact::scope()->with('user', 'vendor.vendor_contacts')->withTrashed()->get(); } return $data; }
protected function createVendor($id, array $data) { return \App\Models\Vendor::create(['user_id' => $id, 'company_name' => $data['company_name'], 'address1' => $data['address1'], 'address2' => $data['address2'], 'city' => $data['city'], 'state_province_id' => $data['state_province_id'], 'country_id' => $data['country_id'], 'zip_postal' => $data['zip_postal'], 'contact_name' => $data['contact_name'], 'contact_title' => $data['contact_title'], 'contact_phone' => $data['contact_phone'], 'contact_email' => $data['contact_email'], 'contact_url' => $data['contact_url'], 'intro_text' => $data['intro_text'], 'about_text' => $data['about_text'], 'logo_image_path' => isset($data['logo_image_path']) ? $data['logo_image_path'] : null, 'background_image_path' => isset($data['background_image_path']) ? $data['background_image_path'] : null]); }
/** * @SWG\Post( * path="/vendors", * tags={"vendor"}, * summary="Create a vendor", * @SWG\Parameter( * in="body", * name="body", * @SWG\Schema(ref="#/definitions/Vendor") * ), * @SWG\Response( * response=200, * description="New vendor", * @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Vendor")) * ), * @SWG\Response( * response="default", * description="an ""unexpected"" error" * ) * ) */ public function store(CreateVendorRequest $request) { $vendor = $this->vendorRepo->save($request->input()); $vendor = Vendor::scope($vendor->public_id)->with('country', 'vendor_contacts', 'industry', 'size', 'currency')->first(); return $this->itemResponse($vendor); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($publicId) { $vendor = Vendor::scope($publicId)->with('vendorcontacts')->firstOrFail(); if (!$this->checkEditPermission($vendor, $response)) { return $response; } $data = ['vendor' => $vendor, 'method' => 'PUT', 'url' => 'vendors/' . $publicId, 'title' => trans('texts.edit_vendor')]; $data = array_merge($data, self::getViewModel()); if (Auth::user()->account->isNinjaAccount()) { if ($account = Account::whereId($vendor->public_id)->first()) { $data['proPlanPaid'] = $account['pro_plan_paid']; } } return View::make('vendors.edit', $data); }
public function findVendor($vendorPublicId) { $vendorId = Vendor::getPrivateId($vendorPublicId); $query = $this->find()->where('expenses.vendor_id', '=', $vendorId); return $query; }
private function getData($request) { $account = Auth::user()->account; $data = ['account' => $account, 'title' => 'Invoice Ninja v' . NINJA_VERSION . ' - ' . $account->formatDateTime($account->getDateTime()), 'multiUser' => $account->users->count() > 1]; if ($request->input(ENTITY_CLIENT)) { $data['clients'] = Client::scope()->with('user', 'contacts', 'country')->withArchived()->get(); $data['contacts'] = Contact::scope()->with('user', 'client.contacts')->withTrashed()->get(); $data['credits'] = Credit::scope()->with('user', 'client.contacts')->get(); } if ($request->input(ENTITY_TASK)) { $data['tasks'] = Task::scope()->with('user', 'client.contacts')->withArchived()->get(); } if ($request->input(ENTITY_INVOICE)) { $data['invoices'] = Invoice::scope()->with('user', 'client.contacts', 'invoice_status')->withArchived()->where('is_quote', '=', false)->where('is_recurring', '=', false)->get(); $data['quotes'] = Invoice::scope()->with('user', 'client.contacts', 'invoice_status')->withArchived()->where('is_quote', '=', true)->where('is_recurring', '=', false)->get(); $data['recurringInvoices'] = Invoice::scope()->with('user', 'client.contacts', 'invoice_status', 'frequency')->withArchived()->where('is_quote', '=', false)->where('is_recurring', '=', true)->get(); } if ($request->input(ENTITY_PAYMENT)) { $data['payments'] = Payment::scope()->withArchived()->with('user', 'client.contacts', 'payment_type', 'invoice', 'account_gateway.gateway')->get(); } if ($request->input(ENTITY_VENDOR)) { $data['clients'] = Vendor::scope()->with('user', 'vendorcontacts', 'country')->withArchived()->get(); $data['vendor_contacts'] = VendorContact::scope()->with('user', 'vendor.contacts')->withTrashed()->get(); /* $data['expenses'] = Credit::scope() ->with('user', 'client.contacts') ->get(); */ } return $data; }
public function edit(ExpenseRequest $request) { $expense = $request->entity(); $expense->expense_date = Utils::fromSqlDate($expense->expense_date); $actions = []; if ($expense->invoice) { $actions[] = ['url' => URL::to("invoices/{$expense->invoice->public_id}/edit"), 'label' => trans('texts.view_invoice')]; } else { $actions[] = ['url' => 'javascript:submitAction("invoice")', 'label' => trans('texts.invoice_expense')]; // check for any open invoices $invoices = $expense->client_id ? $this->invoiceRepo->findOpenInvoices($expense->client_id, ENTITY_EXPENSE) : []; foreach ($invoices as $invoice) { $actions[] = ['url' => 'javascript:submitAction("add_to_invoice", ' . $invoice->public_id . ')', 'label' => trans('texts.add_to_invoice', ['invoice' => $invoice->invoice_number])]; } } $actions[] = \DropdownButton::DIVIDER; if (!$expense->trashed()) { $actions[] = ['url' => 'javascript:submitAction("archive")', 'label' => trans('texts.archive_expense')]; $actions[] = ['url' => 'javascript:onDeleteClick()', 'label' => trans('texts.delete_expense')]; } else { $actions[] = ['url' => 'javascript:submitAction("restore")', 'label' => trans('texts.restore_expense')]; } $data = ['vendor' => null, 'expense' => $expense, 'method' => 'PUT', 'url' => 'expenses/' . $expense->public_id, 'title' => 'Edit Expense', 'actions' => $actions, 'vendors' => Vendor::scope()->with('vendor_contacts')->orderBy('name')->get(), 'vendorPublicId' => $expense->vendor ? $expense->vendor->public_id : null, 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), 'clientPublicId' => $expense->client ? $expense->client->public_id : null, 'categoryPublicId' => $expense->expense_category ? $expense->expense_category->public_id : null]; $data = array_merge($data, self::getViewModel()); return View::make('expenses.edit', $data); }
public function website($vendor_id) { $vendor = Vendor::find($vendor_id); if (!$vendor) { return abort(404); } if ($vendor->website) { return redirect()->away($vendor->website); } else { return abort(404); } }
if ($this->currency_id) { return $this->currency_id; } if (!$this->account) { $this->load('account'); } return $this->account->currency_id ?: DEFAULT_CURRENCY; } public function getTotalExpense() { return DB::table('expenses')->where('vendor_id', '=', $this->id)->whereNull('deleted_at')->sum('amount'); } } Vendor::creating(function ($vendor) { $vendor->setNullValues(); }); Vendor::created(function ($vendor) { event(new VendorWasCreated($vendor)); }); Vendor::updating(function ($vendor) { $vendor->setNullValues(); }); Vendor::updated(function ($vendor) { event(new VendorWasUpdated($vendor)); }); Vendor::deleting(function ($vendor) { $vendor->setNullValues(); }); Vendor::deleted(function ($vendor) { event(new VendorWasDeleted($vendor)); });