public function create($clientPublicId = 0) { $client = null; // $invoiceNumber = Auth::user()->branch->getNextInvoiceNumber(); // 'invoiceNumber' => $invoiceNumber, $account = Account::with('country')->findOrFail(Auth::user()->account_id); if ($clientPublicId) { $client = Client::scope($clientPublicId)->firstOrFail(); } $invoiceDesigns = InvoiceDesign::where('account_id', \Auth::user()->account_id)->orderBy('public_id', 'desc')->get(); $data = array('entityType' => ENTITY_INVOICE, 'account' => $account, 'invoice' => null, 'showBreadcrumbs' => false, 'data' => Input::old('data'), 'invoiceDesigns' => $invoiceDesigns, 'method' => 'POST', 'url' => 'invoices', 'title' => trans('texts.new_invoice'), 'client' => $client); $data = array_merge($data, self::getViewModel()); return View::make('invoices.edit', $data); }
private static function getViewModel() { return ['entityType' => ENTITY_QUOTE, 'account' => Auth::user()->account, 'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')), 'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'invoiceDesigns' => InvoiceDesign::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'invoiceLabels' => Auth::user()->account->getInvoiceLabels()]; }
private function saveInvoiceDesign() { $account = Auth::user()->account; $account->op3 = true; $account->save(); if ($file = Input::file('logo') || Input::get('design') || Input::get('x')) { if (Auth::user()->account->isRegistered()) { $invoice_design = InvoiceDesign::createNew(); $invoice_design_old = InvoiceDesign::scope()->orderBy('public_id', 'desc')->firstOrFail(); $invoice_design->javascript = $invoice_design_old->javascript; $invoice_design->x = $invoice_design_old->x; $invoice_design->y = $invoice_design_old->y; $invoice_design->logo = $invoice_design_old->logo; } else { $invoice_design = InvoiceDesign::scope()->orderBy('public_id', 'desc')->firstOrFail(); } if ($file = Input::file('logo')) { $path = Input::file('logo')->getRealPath(); File::delete('logo/' . $account->account_key . '.jpg'); $image = Image::make($path)->resize(200, 120, true, false); Image::canvas($image->width, $image->height, '#FFFFFF')->insert($image)->save($account->getLogoPath()); $invoice_design->logo = HTML::image_data('logo/' . $account->account_key . '.jpg'); File::delete('logo/' . $account->account_key . '.jpg'); $invoice_design->save(); } if (Input::get('x') || Input::get('y')) { $invoice_design->x = Input::get('x'); $invoice_design->y = Input::get('y'); $invoice_design->save(); } if (Input::get('design')) { $invoice_design->javascript = Input::get('design'); $invoice_design->save(); } Session::flash('message', trans('texts.updated_settings')); } return Redirect::to('company/invoice_design'); }
private static function getViewModel() { $recurringHelp = ''; foreach (preg_split("/((\r?\n)|(\r\n?))/", trans('texts.recurring_help')) as $line) { $parts = explode("=>", $line); if (count($parts) > 1) { $line = $parts[0] . ' => ' . Utils::processVariables($parts[0]); $recurringHelp .= '<li>' . strip_tags($line) . '</li>'; } else { $recurringHelp .= $line; } } return ['account' => Auth::user()->account, 'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')), 'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']), 'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'invoiceDesigns' => InvoiceDesign::remember(DEFAULT_QUERY_CACHE, 'invoice_designs_cache_' . Auth::user()->maxInvoiceDesignId())->where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(), 'frequencies' => array(1 => 'Weekly', 2 => 'Two weeks', 3 => 'Four weeks', 4 => 'Monthly', 5 => 'Three months', 6 => 'Six months', 7 => 'Annually'), 'recurringHelp' => $recurringHelp]; }
public function showSection($section = ACCOUNT_DETAILS, $subSection = false) { if ($section == ACCOUNT_DETAILS) { $data = ['account' => Account::with('users')->findOrFail(Auth::user()->account_id), 'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'timezones' => Timezone::remember(DEFAULT_QUERY_CACHE)->orderBy('location')->get(), 'dateFormats' => DateFormat::remember(DEFAULT_QUERY_CACHE)->get(), 'datetimeFormats' => DatetimeFormat::remember(DEFAULT_QUERY_CACHE)->get(), 'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'languages' => Language::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'showUser' => Auth::user()->id === Auth::user()->account->users()->first()->id]; return View::make('accounts.details', $data); } else { if ($section == ACCOUNT_PAYMENTS) { $account = Account::with('account_gateways')->findOrFail(Auth::user()->account_id); $accountGateway = null; $config = null; $configFields = null; $selectedCards = 0; if (count($account->account_gateways) > 0) { $accountGateway = $account->account_gateways[0]; $config = $accountGateway->config; $selectedCards = $accountGateway->accepted_credit_cards; $configFields = json_decode($config); foreach ($configFields as $configField => $value) { $configFields->{$configField} = str_repeat('*', strlen($value)); } } else { $accountGateway = AccountGateway::createNew(); $accountGateway->gateway_id = GATEWAY_MOOLAH; } $recommendedGateways = Gateway::remember(DEFAULT_QUERY_CACHE)->where('recommended', '=', '1')->orderBy('sort_order')->get(); $recommendedGatewayArray = array(); foreach ($recommendedGateways as $recommendedGateway) { $arrayItem = array('value' => $recommendedGateway->id, 'other' => 'false', 'data-imageUrl' => asset($recommendedGateway->getLogoUrl()), 'data-siteUrl' => $recommendedGateway->site_url); $recommendedGatewayArray[$recommendedGateway->name] = $arrayItem; } $creditCardsArray = unserialize(CREDIT_CARDS); $creditCards = []; foreach ($creditCardsArray as $card => $name) { if ($selectedCards > 0 && ($selectedCards & $card) == $card) { $creditCards[$name['text']] = ['value' => $card, 'data-imageUrl' => asset($name['card']), 'checked' => 'checked']; } else { $creditCards[$name['text']] = ['value' => $card, 'data-imageUrl' => asset($name['card'])]; } } $otherItem = array('value' => 1000000, 'other' => 'true', 'data-imageUrl' => '', 'data-siteUrl' => ''); $recommendedGatewayArray['Other Options'] = $otherItem; $gateways = Gateway::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(); foreach ($gateways as $gateway) { $paymentLibrary = $gateway->paymentlibrary; $gateway->fields = $gateway->getFields(); if ($accountGateway && $accountGateway->gateway_id == $gateway->id) { $accountGateway->fields = $gateway->fields; } } $data = ['account' => $account, 'accountGateway' => $accountGateway, 'config' => $configFields, 'gateways' => $gateways, 'dropdownGateways' => Gateway::remember(DEFAULT_QUERY_CACHE)->where('recommended', '=', '0')->orderBy('name')->get(), 'recommendedGateways' => $recommendedGatewayArray, 'creditCardTypes' => $creditCards]; return View::make('accounts.payments', $data); } else { if ($section == ACCOUNT_NOTIFICATIONS) { $data = ['account' => Account::with('users')->findOrFail(Auth::user()->account_id)]; return View::make('accounts.notifications', $data); } else { if ($section == ACCOUNT_IMPORT_EXPORT) { return View::make('accounts.import_export'); } else { if ($section == ACCOUNT_ADVANCED_SETTINGS) { $data = ['account' => Auth::user()->account, 'feature' => $subSection]; if ($subSection == ACCOUNT_INVOICE_DESIGN) { $invoice = new stdClass(); $client = new stdClass(); $invoiceItem = new stdClass(); $client->name = 'Sample Client'; $client->address1 = ''; $client->city = ''; $client->state = ''; $client->postal_code = ''; $client->work_phone = ''; $client->work_email = ''; $invoice->invoice_number = Auth::user()->account->getNextInvoiceNumber(); $invoice->invoice_date = date_create()->format('Y-m-d'); $invoice->account = json_decode(Auth::user()->account->toJson()); $invoice->amount = $invoice->balance = 100; $invoiceItem->cost = 100; $invoiceItem->qty = 1; $invoiceItem->notes = 'Notes'; $invoiceItem->product_key = 'Item'; $invoice->client = $client; $invoice->invoice_items = [$invoiceItem]; $data['invoice'] = $invoice; $data['invoiceDesigns'] = InvoiceDesign::remember(DEFAULT_QUERY_CACHE, 'invoice_designs_cache_' . Auth::user()->maxInvoiceDesignId())->where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(); } return View::make("accounts.{$subSection}", $data); } else { if ($section == ACCOUNT_PRODUCTS) { $data = ['account' => Auth::user()->account]; return View::make('accounts.products', $data); } } } } } } }
private static function getViewModel() { return ['account' => Auth::user()->account, 'branch' => Auth::user()->branch, 'products' => Product::scope()->with('prices')->orderBy('id')->get(), 'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'currencies' => Currency::orderBy('name')->get(), 'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'invoiceDesigns' => InvoiceDesign::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'invoiceLabels' => Auth::user()->account->getInvoiceLabels(), 'frequencies' => array(1 => 'Semanal', 2 => 'Cada 2 semanas', 3 => 'Cada 4 semanas', 4 => 'Mensual', 5 => 'Trimestral', 6 => 'Semestral', 7 => 'Anual')]; }
private static function getViewModel() { return ['account' => Auth::user()->account, 'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')), 'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']), 'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'invoiceDesigns' => InvoiceDesign::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'invoiceLabels' => Auth::user()->account->getInvoiceLabels(), 'frequencies' => array(1 => 'Weekly', 2 => 'Two weeks', 3 => 'Four weeks', 4 => 'Monthly', 5 => 'Three months', 6 => 'Six months', 7 => 'Annually')]; }
} } // Make sure the account/user localization settings are in the session if (Auth::check() && !Session::has(SESSION_TIMEZONE)) { Event::fire('user.refresh'); } // Check if the user is claiming a license (ie, additional invoices, white label, etc.) $claimingLicense = Utils::startsWith($_SERVER['REQUEST_URI'], '/claim_license'); if (!$claimingLicense && Input::has('license_key') && Input::has('product_id')) { $licenseKey = Input::get('license_key'); $productId = Input::get('product_id'); $data = trim(file_get_contents((Utils::isNinjaDev() ? 'http://ninja.dev' : NINJA_APP_URL) . "/claim_license?license_key={$licenseKey}&product_id={$productId}")); if ($productId == PRODUCT_INVOICE_DESIGNS) { if ($data = json_decode($data)) { foreach ($data as $item) { $design = new InvoiceDesign(); $design->id = $item->id; $design->name = $item->name; $design->javascript = $item->javascript; $design->save(); } if (!Utils::isNinjaProd()) { Cache::forget('invoice_designs_cache_' . Auth::user()->maxInvoiceDesignId()); } Session::flash('message', trans('texts.bought_designs')); } } else { if ($productId == PRODUCT_WHITE_LABEL) { if ($data == 'valid') { $account = Auth::user()->account; $account->pro_plan_paid = NINJA_DATE;