public function edit($publicId) { $payment = Payment::scope($publicId)->firstOrFail(); $payment->payment_date = Utils::fromSqlDate($payment->payment_date); $data = array('client' => null, 'invoice' => null, 'invoices' => Invoice::scope()->where('is_recurring', '=', false)->where('is_quote', '=', false)->with('client', 'invoice_status')->orderBy('invoice_number')->get(), 'payment' => $payment, 'method' => 'PUT', 'url' => 'payments/' . $publicId, 'title' => 'Edit Payment', 'paymentTypes' => PaymentType::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'clients' => Client::scope()->with('contacts')->orderBy('name')->get()); return View::make('payments.edit', $data); }
public function index() { $publicId = 1; $invoice = Invoice::scope($publicId)->with('account.country', 'client.contacts', 'client.country', 'invoice_items')->firstOrFail(); Utils::trackViewed($invoice->invoice_number . ' - ' . $invoice->client->getDisplayName(), ENTITY_INVOICE); //$productos = InvoiceItem::scope(1)->get(); $invoice->invoice_date = Utils::fromSqlDate($invoice->invoice_date); $invoice->due_date = Utils::fromSqlDate($invoice->due_date); $invoice->start_date = Utils::fromSqlDate($invoice->start_date); $invoice->end_date = Utils::fromSqlDate($invoice->end_date); $invoice->is_pro = Auth::user()->isPro(); //print_r($invoice->invoice_items); //return Response::json($invoice); $contactIds = DB::table('invitations')->join('contacts', 'contacts.id', '=', 'invitations.contact_id')->where('invitations.invoice_id', '=', $invoice->id)->where('invitations.account_id', '=', Auth::user()->account_id)->where('invitations.deleted_at', '=', null)->select('contacts.public_id')->lists('public_id'); $data = array('showBreadcrumbs' => false, 'account' => $invoice->account, 'invoice' => $invoice, 'data' => false, 'method' => 'PUT', 'invitationContactIds' => $contactIds, 'url' => 'invoices/' . $publicId, 'title' => '- ' . $invoice->invoice_number, 'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->where('id', $invoice->client->id)->get(), 'client' => $invoice->client); $data = array_merge($data, self::getViewModel()); // Set the invitation link on the client's contacts $clients = $data['clients']; foreach ($clients as $client) { if ($client->id == $invoice->client->id) { foreach ($invoice->invitations as $invitation) { foreach ($client->contacts as $contact) { if ($invitation->contact_id == $contact->id) { $contact->invitation_link = $invitation->getLink(); } } } break; } } // print_r($data['invoice']); // echo "<br><br><br><br><br>"; //return View::make('invoices.edit', $data); return View::make('factura', $data); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($publicId) { $client = Client::withTrashed()->scope($publicId)->with('contacts', 'size', 'industry')->firstOrFail(); Utils::trackViewed($client->getDisplayName(), ENTITY_CLIENT); $actionLinks = [[trans('texts.create_invoice'), URL::to('invoices/create/' . $client->public_id)], [trans('texts.enter_payment'), URL::to('payments/create/' . $client->public_id)], [trans('texts.enter_credit'), URL::to('credits/create/' . $client->public_id)]]; if (Utils::isPro()) { array_unshift($actionLinks, [trans('texts.create_quote'), URL::to('quotes/create/' . $client->public_id)]); } $data = array('actionLinks' => $actionLinks, 'showBreadcrumbs' => false, 'client' => $client, 'credit' => $client->getTotalCredit(), 'title' => trans('texts.view_client'), 'hasRecurringInvoices' => Invoice::scope()->where('is_recurring', '=', true)->whereClientId($client->id)->count() > 0); return View::make('clients.show', $data); }
public function index() { if (!Utils::isPro()) { return Redirect::to('/'); } $invoices = Invoice::scope()->where('invoices.is_quote', '=', true)->orderBy('created_at', 'desc')->get(); $invoices = Utils::remapPublicIds($invoices->toArray()); $response = json_encode($invoices, JSON_PRETTY_PRINT); $headers = Utils::getApiHeaders(count($invoices)); return Response::make($response, 200, $headers); }
public function index() { if (!Utils::isPro()) { return Redirect::to('/invoices/create'); } $data = ['title' => trans('texts.quotes'), 'entityType' => ENTITY_QUOTE, 'columns' => Utils::trans(['checkbox', 'quote_number', 'client', 'quote_date', 'quote_total', 'due_date', 'status', 'action'])]; if (Invoice::scope()->where('is_recurring', '=', true)->count() > 0) { $data['secEntityType'] = ENTITY_RECURRING_INVOICE; $data['secColumns'] = Utils::trans(['checkbox', 'frequency', 'client', 'start_date', 'end_date', 'quote_total', 'action']); } return View::make('list', $data); }
public function index() { // total_income, billed_clients, invoice_sent and active_clients $select = DB::raw('COUNT(DISTINCT CASE WHEN invoices.id IS NOT NULL THEN clients.id ELSE null END) billed_clients, SUM(CASE WHEN invoices.invoice_status_id >= ' . INVOICE_STATUS_SENT . ' THEN 1 ELSE 0 END) invoices_sent, COUNT(DISTINCT clients.id) active_clients, AVG(invoices.amount) as invoice_avg'); $metrics = DB::table('accounts')->select($select)->leftJoin('clients', 'accounts.id', '=', 'clients.account_id')->leftJoin('invoices', 'clients.id', '=', 'invoices.client_id')->where('accounts.id', '=', Auth::user()->account_id)->where('clients.is_deleted', '=', false)->groupBy('accounts.id')->first(); $select = DB::raw('SUM(clients.paid_to_date) as value'); $totalIncome = DB::table('accounts')->select($select)->leftJoin('clients', 'accounts.id', '=', 'clients.account_id')->where('accounts.id', '=', Auth::user()->account_id)->where('clients.is_deleted', '=', false)->groupBy('accounts.id')->first(); $activities = Activity::where('activities.account_id', '=', Auth::user()->account_id)->orderBy('created_at', 'desc')->take(6)->get(); $pastDue = Invoice::scope()->where('due_date', '<', date('Y-m-d'))->where('balance', '>', 0)->where('is_recurring', '=', false)->where('is_quote', '=', false)->where('is_deleted', '=', false)->orderBy('due_date', 'asc')->take(6)->get(); $upcoming = Invoice::scope()->where('due_date', '>=', date('Y-m-d'))->where('balance', '>', 0)->where('is_recurring', '=', false)->where('is_quote', '=', false)->where('is_deleted', '=', false)->orderBy('due_date', 'asc')->take(6)->get(); $data = ['totalIncome' => Utils::formatMoney($totalIncome ? $totalIncome->value : 0, Session::get(SESSION_CURRENCY)), 'billedClients' => $metrics ? $metrics->billed_clients : 0, 'invoicesSent' => $metrics ? $metrics->invoices_sent : 0, 'activeClients' => $metrics ? $metrics->active_clients : 0, 'invoiceAvg' => Utils::formatMoney($metrics ? $metrics->invoice_avg : 0, Session::get(SESSION_CURRENCY)), 'activities' => $activities, 'pastDue' => $pastDue, 'upcoming' => $upcoming]; return View::make('dashboard', $data); }
private function save() { $rules = array('client' => 'required', 'invoice' => 'required', 'amount' => 'required|positive'); if (Input::get('invoice')) { $invoice = Invoice::scope(Input::get('invoice'))->firstOrFail(); $rules['amount'] .= '|less_than:' . $invoice->balance; } if (Input::get('payment_type_id') == PAYMENT_TYPE_CREDIT) { $rules['payment_type_id'] = 'has_credit:' . Input::get('client') . ',' . Input::get('amount'); } $messages = array('required' => 'El campo es Requerido', 'positive' => 'El Monto debe ser mayor a cero', 'less_than' => 'El Monto debe ser menor o igual a ' . $invoice->balance, 'has_credit' => 'El Cliente no tiene crédito suficiente'); $validator = \Validator::make(Input::all(), $rules, $messages); if ($validator->fails()) { $url = 'pagos/create'; return Redirect::to($url)->withErrors($validator)->withInput(); } else { $payment = Payment::createNew(); $paymentTypeId = Input::get('payment_type_id') ? Input::get('payment_type_id') : null; $clientId = Client::getPrivateId(Input::get('client')); $amount = floatval(Input::get('amount')); if ($paymentTypeId == PAYMENT_TYPE_CREDIT) { $credits = Credit::scope()->where('client_id', '=', $clientId)->where('balance', '>', 0)->orderBy('created_at')->get(); $applied = 0; foreach ($credits as $credit) { $applied += $credit->apply($amount); if ($applied >= $amount) { break; } } } $payment->client_id = $clientId; $payment->invoice_id = Invoice::getPrivateId(Input::get('invoice')); $payment->payment_type_id = $paymentTypeId; $payment->payment_date = date("Y-m-d", strtotime(Input::get('payment_date'))); $payment->amount = $amount; $payment->transaction_reference = trim(Input::get('transaction_reference')); $payment->save(); Session::flash('message', 'Pago creado con éxito'); return Redirect::to('clientes/' . Input::get('client')); } }
public function getNextInvoiceNumber() { // $invoices = Invoice::withTrashed()->scope(false, $this->id)->get(['invoice_number']); $invoices = Invoice::scope(false, $this->id)->get(['invoice_number']); $max = 0; foreach ($invoices as $invoice) { $number = intval(preg_replace("/[^0-9]/", "", $invoice->invoice_number)); $max = max($max, $number); } if ($max > 0) { return str_pad($max + 1, 4, "0", STR_PAD_LEFT); } else { return DEFAULT_INVOICE_NUMBER; } }
public function edit($publicId, $clone = false) { $invoice = Invoice::scope($publicId)->withTrashed()->with('invitations', 'account.country', 'client.contacts', 'client.country', 'invoice_items')->firstOrFail(); $entityType = $invoice->getEntityType(); $contactIds = DB::table('invitations')->join('contacts', 'contacts.id', '=', 'invitations.contact_id')->where('invitations.invoice_id', '=', $invoice->id)->where('invitations.account_id', '=', Auth::user()->account_id)->where('invitations.deleted_at', '=', null)->select('contacts.public_id')->lists('public_id'); if ($clone) { $invoice->id = null; $invoice->invoice_number = Auth::user()->account->getNextInvoiceNumber($invoice->is_quote); $invoice->balance = $invoice->amount; $method = 'POST'; $url = "{$entityType}s"; } else { Utils::trackViewed($invoice->invoice_number . ' - ' . $invoice->client->getDisplayName(), $invoice->getEntityType()); $method = 'PUT'; $url = "{$entityType}s/{$publicId}"; } $invoice->invoice_date = Utils::fromSqlDate($invoice->invoice_date); $invoice->due_date = Utils::fromSqlDate($invoice->due_date); $invoice->start_date = Utils::fromSqlDate($invoice->start_date); $invoice->end_date = Utils::fromSqlDate($invoice->end_date); $invoice->is_pro = Auth::user()->isPro(); $invoiceDesigns = InvoiceDesign::where('account_id', \Auth::user()->account_id)->orderBy('public_id', 'desc')->get(); // $invoiceDesigns = InvoiceDesign::where('account_id',\Auth::user()->account_id)->where('id',$invoice->invoice_design_id)->orderBy('public_id', 'desc')->first(); $data = array('entityType' => $entityType, 'showBreadcrumbs' => $clone, 'account' => $invoice->account, 'invoice' => $invoice, 'data' => false, 'method' => $method, 'invoiceDesigns' => $invoiceDesigns, 'invitationContactIds' => $contactIds, 'url' => $url, 'title' => trans("texts.edit_{$entityType}"), 'client' => $invoice->client); $data = array_merge($data, self::getViewModel()); // Set the invitation link on the client's contacts $clients = $data['clients']; foreach ($clients as $client) { if ($client->id == $invoice->client->id) { foreach ($invoice->invitations as $invitation) { foreach ($client->contacts as $contact) { if ($invitation->contact_id == $contact->id) { $contact->invitation_link = $invitation->getLink(); } } } break; } } return View::make('invoices.edit', $data); }
private function export() { $output = fopen('php://output', 'w') or Utils::fatalError(); header('Content-Type:application/csv'); header('Content-Disposition:attachment;filename=export.csv'); $clients = Client::scope()->get(); AccountController::exportData($output, $clients->toArray()); $contacts = Contact::scope()->get(); AccountController::exportData($output, $contacts->toArray()); $invoices = Invoice::scope()->get(); AccountController::exportData($output, $invoices->toArray()); $invoiceItems = InvoiceItem::scope()->get(); AccountController::exportData($output, $invoiceItems->toArray()); $payments = Payment::scope()->get(); AccountController::exportData($output, $payments->toArray()); $credits = Credit::scope()->get(); AccountController::exportData($output, $credits->toArray()); fclose($output); exit; }
public function factura($numeroFactura) { $invoice = Invoice::scope($numeroFactura)->withTrashed()->with('account.country', 'client.contacts', 'client.country', 'invoice_items')->firstOrFail(); return Response::json($invoice); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($publicId) { $client = Client::withTrashed()->scope($publicId)->with('contacts', 'industry')->firstOrFail(); Utils::trackViewed($client->getDisplayName(), ENTITY_CLIENT); $monday = ''; $tuesday = ''; $wednesday = ''; $thursday = ''; $friday = ''; $saturday = ''; $sunday = ''; $frecuency = strstr($client->custom_value1, '1'); if ($frecuency != false) { $monday = 'Lun, '; } $frecuency = strstr($client->custom_value1, '2'); if ($frecuency != false) { $tuesday = 'Mar, '; } $frecuency = strstr($client->custom_value1, '3'); if ($frecuency != false) { $wednesday = 'Mié, '; } $frecuency = strstr($client->custom_value1, '4'); if ($frecuency != false) { $thursday = 'Jue, '; } $frecuency = strstr($client->custom_value1, '5'); if ($frecuency != false) { $friday = 'Vie, '; } $frecuency = strstr($client->custom_value1, '6'); if ($frecuency != false) { $saturday = 'Sáb, '; } $frecuency = strstr($client->custom_value1, '7'); if ($frecuency != false) { $sunday = 'Dom, '; } $client->custom_value1 = $monday . $tuesday . $wednesday . $thursday . $friday . $saturday . $sunday; $actionLinks = [[trans('texts.create_invoice'), URL::to('invoices/create/' . $client->public_id)]]; $data = array('actionLinks' => $actionLinks, 'showBreadcrumbs' => false, 'client' => $client, 'title' => trans('texts.view_client'), 'hasRecurringInvoices' => Invoice::scope()->where('is_recurring', '=', true)->whereClientId($client->id)->count() > 0); return View::make('clients.show', $data); }