/**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $expense = new Expense();
     if ($expense->destroy($id)) {
         return "success";
     }
 }
 public function messages()
 {
     $reportId = $this->route('reportId');
     if ($reportId == null) {
         $expenseId = $this->route('expenseId');
         $reportId = Expense::find($expenseId)->report_id;
     }
     $report = ExpenseReport::find($reportId);
     $messages = ['title.required' => "Title is required", 'date.after' => "Expense date should be on or after report start date (" . date('d M Y', strtotime($report->startDate)) . ")", $report->owner_id . '.numeric' => 'Contributions should be numeric', $report->owner_id . '.min' => 'Contributions cannot be negative', $report->owner_id . 'p.numeric' => 'Participation Ratios should be numeric', $report->owner_id . 'p.min' => 'Participation Ratios cannot be negative'];
     $amount = 0;
     $participationRatios = 0;
     $input = $this->all();
     foreach ($report->users as $user) {
         $amount += $input[$user->id];
         $participationRatios += $input[$user->id . 'p'];
         $messages[$user->id . '.numeric'] = 'Contributions should be numeric';
         $messages[$user->id . '.min'] = 'Contributions cannot be negative';
         $messages[$user->id . 'p.numeric'] = 'Participation Ratios should be numeric';
         $messages[$user->id . 'p.min'] = 'Participation Ratios cannot be negative';
     }
     if ($amount == 0) {
         $messages[$report->owner_id . '.min'] = 'Sum of Contributions cannot be 0';
         $messages[$report->owner_id . '.required'] = 'Sum of Contributions cannot be 0';
     }
     if ($participationRatios == 0) {
         $messages[$report->owner_id . 'p.min'] = 'Sum of Participation Ratios cannot be 0';
         $messages[$report->owner_id . 'p.required'] = 'Sum of Participation Ratios cannot be 0';
     }
     return $messages;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $expense = Expense::findOrFail($id);
     $expense->fill($request->all());
     $expense->save();
     //return ['Success' => 'ok', 'Expense' => $expense];
 }
 public function store_expense(CreateExpenseRequest $request)
 {
     $id = Auth::user()->id;
     $expenses = new Expense($request->all());
     $expenses->user_id = $id;
     $expenses->iduser_update = $id;
     $expenses->save();
     // if($action=='save_new')
     // {
     return redirect()->route('admin.salidas.index');
     // }
     //   else {
     //      return redirect()->back();
     //   }
     Session::flash('message', 'El proveedor: ' . $expenses->provider->name . ' realizo una salidad $$');
 }
 public function update(ExpenseRequest $request, Expense $expense)
 {
     //Client $client refrences a Route Model Binding method found is RouteServiceProvider.php
     $expense->update($request->all());
     $expense = Expense::latest()->first();
     \Session::flash('flash_message', 'Expense ' . $expense->id . ' was updated.');
     return redirect('expenses');
 }
 public function totalMonthlyExpenses(Request $request, $expenseId = null)
 {
     $query = "select sum(cost) as Total,\n                      DATE_FORMAT( created_at , \"%M\") as Month\n                      from trackedexpenses\n                      where MONTH(created_at) in(1,2,3,4,5,6,7,8,9,10,11,12)\n                            ";
     if (isset($expenseId)) {
         $query .= "AND trackedexpenses.expense_id = " . $expenseId;
     }
     $query .= "and DATE_FORMAT( created_at , \"%Y\") = 2016";
     $query .= " group by MONTH(created_at)";
     return ['totalMonthly' => DB::select($query), 'expenses' => Expense::all(['name', 'id'])];
 }
 public function update(EditExpenseRequest $request, $id)
 {
     $id_user = Auth::user()->id;
     $expenses = Expense::findOrFail($id);
     $expenses->iduser_update->{$id_user};
     $expenses->fill($request->all());
     $expenses->save();
     Session::flash('message', ' Se actualizo exitosamente');
     return redirect()->back();
 }
Example #8
0
 /**
  * Show the application dashboard to the user.
  *
  * @return Response
  */
 public function index()
 {
     $expensesss = Expense::where('project_id', '=', 0)->first();
     $expensess = Expense::where('project_id', '=', 0)->orderBy('paid_on', 'desc')->get();
     $clients = Client::orderBy('created_at', 'desc')->get();
     $projects = Project::orderBy('created_at', 'desc')->get();
     $expenses = Expense::where('project_id', '>', 0)->orderBy('paid_on', 'desc')->get();
     $payments = Payment::orderBy('created_at', 'desc')->get();
     $hours = Hour::where('amount_paid', '<', 0)->orderBy('day_worked', 'desc')->get();
     return view('home', compact('projects', 'expenses', 'payments', 'hours', 'clients', 'expensess', 'expensesss'));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     try {
         $expense = Expense::findOrFail($id);
         $expense->delete();
     } catch (ModelNotFoundException $e) {
         Log::error($e->getMessage());
         Log::info('Modelo no encontrado');
         return response()->make('Model not found', 400);
     }
 }
Example #10
0
 /**
  * Get who it's tied to in one shot
  *
  * @return array[0] the amount or Carbon date by which this capital is set to begin
  * @return array[1] the Income or Expense object
  **/
 public function endsWhen()
 {
     $ends = (string) $this->end_at . '_end';
     $object = FALSE;
     if ($this->end_at === 'income') {
         $object = Income::findOrFail($this->income_end_id);
     }
     if ($this->end_at === 'expenses') {
         $object = Expense::findOrFail($this->expenses_end_id);
     }
     return array($object, $this->{$ends});
 }
 /**
  * Homepage Method
  * @method index
  * @return view The homepage HTML.
  */
 public function index()
 {
     // TODO: optimize these queries.
     // TODO: Decide whether or now to show a monthly earnings, instead of
     // just a weekly breakdown of the totals.
     $data['incomes'] = Income::all()->sortByDesc('amount');
     $data['expenses'] = Expense::all()->sortByDesc('amount');
     $data['totalIncome'] = DB::table('incomes')->sum('amount') / 4;
     $data['totalExpenses'] = DB::table('expenses')->sum('amount') / 4;
     $data['weeklyWorth'] = $data['totalIncome'] - $data['totalExpenses'];
     return view('index', $data);
 }
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $expenses = $this->input('expense_ids');
     if ($expenses != null && count($expenses) > 0) {
         $reportId = Expense::find($expenses[0])->report_id;
         $report = ExpenseReport::find($reportId);
         if ($report->status) {
             return false;
         }
     }
     return true;
 }
Example #13
0
 public function storepayment(CreatePaymentRequest $request)
 {
     $hour = Hour::find($request->employee_id);
     $hourspaid = $hour->where('amount_paid', '=', '')->where('employee_id', '=', $request->employee_id)->sum('hours');
     $hours = Hour::where('employee_id', '=', $request->employee_id)->where('amount_paid', '=', '')->groupBy('project_id')->get();
     foreach ($hours as $hour) {
         Expense::create(['project_id' => $hour->project_id, 'employee_id' => $request->employee_id, 'paid_on' => $request->paid_on, 'amount_paid' => round($request->amount_paid / $hourspaid * $hour->where('project_id', '=', $hour->project->id)->where('amount_paid', '=', '')->where('employee_id', '=', $request->employee_id)->sum('hours'), 2), 'reimbursment' => 2, 'office' => 2]);
     }
     $hours = Hour::where('employee_id', '=', $request->employee_id)->where('amount_paid', '=', '')->get();
     foreach ($hours as $hour) {
         $update = Hour::where('id', '=', $hour->id)->update(['amount_paid' => round($request->amount_paid / $request->hours * $hour->hours, 2)]);
     }
     //add a Pay Check table and send all $request info over
     return view('hours.createpayment', compact('hours', 'hour', 'hourspaid'));
 }
Example #14
0
 /**
  * Lists latest ten examples.
  * @return \Illuminate\View\View
  */
 public function index()
 {
     // Monthly statistics / totals.
     $month = array('total' => 0, 'luxury' => 0, 'regular' => 0);
     $month_expenses = Expense::query()->with('category')->where(DB::raw('MONTH(created_at)'), '=', date('n'))->get();
     foreach ($month_expenses as $expense) {
         $month['total'] += $expense->value;
         if ($expense->category->luxury) {
             $month['luxury'] += $expense->value;
         }
     }
     $month['regular'] = $month['total'] - $month['luxury'];
     // Last 10 expenses.
     $expenses = Expense::query()->with('category')->orderBy('created_at', 'desc')->take(10)->get();
     return view('dashboard.index', array('expenses' => $expenses, 'month' => $month));
 }
Example #15
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Define first day of current month.
     $date = date('Y-m') . '-01';
     // Get all the branches.
     $branches = Branch::all();
     foreach ($branches as $branch) {
         // Try to get expense.
         $expense = Expense::where('BranchId', '=', $branch->Id)->where('Date', '=', $date)->first();
         if (!$expense) {
             $default = json_decode($branch->DefaultExpenses);
             if ($default->regimen == 'cuotafija') {
                 Expense::create(array('Date' => $date, 'BranchId' => $branch->Id, 'Electricity' => $default->electricity, 'Water' => $default->water, 'Telecommunications' => $default->phone, 'Rent' => $default->rent, 'Depreciation' => $default->depreciation, 'Security' => $default->security, 'Government' => $default->government, 'Taxes' => $default->taxes, 'Regimen' => $default->regimen, 'TaxesSettled' => 1));
             } else {
                 Expense::create(array('Date' => $date, 'BranchId' => $branch->Id, 'Electricity' => $default->electricity, 'Water' => $default->water, 'Telecommunications' => $default->phone, 'Rent' => $default->rent, 'Depreciation' => $default->depreciation, 'Security' => $default->security, 'Government' => $default->government, 'Taxes' => $default->taxes, 'Regimen' => $default->regimen, 'TaxesSettled' => 0));
             }
         }
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     //view for admin, only read: agent and developer,
     //$expenses= Expense::whereBetween('created_at',array($request->get('from'),$request->get('to')))->get();
     //$payments= Payment::whereBetween('created_at',array($request->get('from'),$request->get('to')))->get();
     $expenses = Expense::orderBy('created_at', 'DESC');
     $payments_ = Payment::orderBy('created_at', 'DESC');
     $payments = Payment::filter($request->get('date'));
     //este filtro de fecha seria bueno transladarlo al modelo.
     $t_payments = $payments_->sum('value');
     // total de todos los ingresos
     $d_payments = $payments->sum('value');
     // el total de rango
     $t_expenses = $expenses->sum('value');
     //total de los gastos
     $total = $t_payments - $t_expenses;
     //total de caja
     return view('payments/list', compact('payments', 't_payments', 't_expenses', 'total', 'd_payments'));
 }
Example #17
0
 public function update(ExpenseRequest $request, Expense $expense)
 {
     //Client $client refrences a Route Model Binding method found is RouteServiceProvider.php
     if ($request->hasFile('file')) {
         $file = $request->file('file');
         $name = time() . 'expense.' . $file->guessClientExtension();
         $file->move('docs/expenses', $name);
         $expense->update($request->all());
         $file = $request->file('file');
         $name = time() . 'expense.' . $file->guessClientExtension();
         $url = Expense::latest()->first();
         $url->receipt_url = $name;
         $url->save();
     } else {
         $expense->update($request->all());
     }
     $expense = Expense::latest()->first();
     \Session::flash('flash_message', 'Expense ' . $expense->id . ' was updated.');
     return redirect('expenses');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $expense = Expense::find($id);
     $supplements = array_column($expense->supplements()->get()->toArray(), 'id');
     ExpenseSupplement::destroy($supplements);
     Expense::destroy($expense->id);
 }
Example #19
0
 private function seedDatabase()
 {
     Expense::truncate();
     $this->call('POST', '/expenses', ['title' => 'ropa', 'amount' => 20]);
     $this->post('/expenses', ['title' => 'juguetes', 'amount' => 30]);
 }
Example #20
0
 public function getDeleteTransaction($id)
 {
     $transaction = Transaction::find($id);
     $account_id = Input::get('data');
     $accounts = NameOfAccount::find($account_id);
     $accounts->opening_balance = $accounts->opening_balance + $transaction->amount;
     $expense = Expense::where('invoice_id', '=', $transaction->invoice_id)->first();
     $accounts->save();
     $transaction->delete();
     $checkTransaction = Transaction::where('invoice_id', '=', $transaction->invoice_id)->first();
     if ($checkTransaction) {
         $expense->status = "Partial";
     } else {
         $expense->status = "Activate";
     }
     $expense->save();
     $message = array('Transaction Successfully Deleted');
     return new JsonResponse($message);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     Expense::destroy($id);
     return redirect('/expense');
 }
    public function index()
    {
        $server = new Server('outlook.office365.com');
        // $connection is instance of \Ddeboer\Imap\Connection
        $connection = $server->authenticate('*****@*****.**', 'Data1992');
        $mailbox = $connection->getMailbox('INBOX/Home Depot');
        $search = new SearchExpression();
        $search->addCondition(new Unseen());
        $messages = $mailbox->getMessages($search);
        foreach ($messages as $message) {
            $strip = str_replace(' ', '', strip_tags($message->getBodyHtml()));
            $value = strpos($strip, 'TOTAL$');
            //Check if its a return or a purchase
            if ($value == false) {
                $thing = 'TOTAL-$';
                $num = 7;
            } else {
                $thing = 'TOTAL$';
                $num = 6;
            }
            //TOTAL $__
            $first = strpos($strip, $thing);
            $space = strpos($strip, 'X', $first) - $first - $num;
            // $value = substr($strip, $first+5, 1);
            //Check if its a return or a purchase
            if ($value == false) {
                $amount = '-' . substr($strip, $first + $num, $space);
            } else {
                $amount = substr($strip, $first + $num, $space);
            }
            //FIND PO/JOPBNAME...attach expense to project..if not porject is 0 and user is promped to select a project.
            $po = strpos($strip, 'JOBNAME:');
            if (is_bool($po)) {
                $project = '0';
            } else {
                $spc = strpos($strip, 'PRO', $po) - $po - 14;
                $pro = substr($strip, $po + 8, $spc);
                $project_id = Project::where('id', $pro)->first();
            }
            //check if PROJECT NAME/ PO/JOBNAME from receipt exists in database, if not, project is 0
            if (is_null($project_id)) {
                $project = '0';
            } else {
                $project = $project_id->id;
            }
            Expense::insert(['amount_paid' => $amount, 'employee_id' => '5', 'paid_on' => date('Y-m-d'), 'Project_id' => $project, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s"), 'reimbursment' => 2, 'office' => 2]);
            $attachments = $message->getAttachments();
            foreach ($attachments as $attachment) {
                $file = $attachment->getDecodedContent();
                $name = time() . 'expense.pdf';
                // $file->move('docs/expenses', $name);
                file_put_contents('docs/expenses/' . $name, $attachment->getDecodedContent());
                // $file = $request->file('file');
                $url = Expense::latest()->first();
                $url->receipt_url = $name;
                $url->save();
            }
            unset($project);
            unset($project_id);
            ?>
				<br>
				<?php 
        }
    }
 private function setPurchasePayment()
 {
     $accountPayment = NameOfAccount::find(Input::get('account_name_id'));
     if ($accountPayment->opening_balance >= Input::get('amount')) {
         $expense[0] = Expense::where('invoice_id', '=', Input::get('invoice_id'))->get();
         $expenseTransaction = new Transaction();
         $expenseTransaction->branch_id = Input::get('branch_id');
         $expenseTransaction->account_category_id = Input::get('account_category_id');
         $expenseTransaction->account_name_id = Input::get('account_name_id');
         $expenseTransaction->amount = Input::get('amount');
         $expenseTransaction->remarks = Input::get('remarks');
         $expenseTransaction->type = "Expense";
         $expenseTransaction->user_id = Session::get('user_id');
         $expenseTransaction->payment_method = Input::get('payment_method');
         $expenseTransaction->invoice_id = Input::get('invoice_id');
         $expenseTransaction->cheque_no = Input::get('cheque_no');
         $expenseTransaction->save();
         $totalAmount = 0;
         $transactions = Transaction::where('invoice_id', '=', $expenseTransaction->invoice_id)->get();
         foreach ($transactions as $transaction) {
             $totalAmount = $totalAmount + $transaction->amount;
         }
         $expense = Expense::find($expense[0][0]['id']);
         if ($totalAmount == $expense->amount) {
             $expense->status = "Completed";
         } else {
             $expense->status = "Partial";
         }
         $expense->save();
         $accountPayment->opening_balance = $accountPayment->opening_balance - Input::get('amount');
         $accountPayment->save();
         Session::flash('message', 'Expense has been Successfully Cleared.');
     } else {
         Session::flash('message', 'You dont have Enough Balance');
     }
 }
Example #24
0
 /**
  * Destroy the given expense.
  *
  * @param  Request  $request
  * @param  Task  $task
  * @return Response
  */
 public function destroy(Request $request, Expense $expense)
 {
     //$this->authorize('destroy', $product);
     $expense->delete();
     return redirect('/expense');
 }
Example #25
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $expense = Expense::findOrFail($id);
     $expense->delete();
     return redirect()->route('expenses.index')->with('message', 'Item deleted successfully.');
 }
Example #26
0
                                    <th>Received by</th>
                                    <th>Status</th>
                                    <th>Action</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php 
$slNo = 1;
?>
                                @foreach($purchaseregister as $reg)
                                    <?php 
if ($reg->type == 'Payment') {
    $sale = \App\PurchaseInvoice::where('invoice_id', '=', $reg->invoice_id)->first();
    $partyname = \App\Party::find($sale->party_id);
} else {
    $sale = \App\Expense::where('invoice_id', '=', $reg->invoice_id)->first();
}
$time = strtotime($reg->cheque_date);
$newformat = date('d', $time);
$today = date('d', time());
?>
                                    <tr>
                                        <td <?php 
if ($newformat >= $today - 2 && $newformat <= $today + 2) {
    echo "class='blink'";
}
?>
>{{$slNo}}</td>
                                        <td <?php 
if ($newformat >= $today - 2 && $newformat <= $today + 2) {
    echo "class='blink'";
Example #27
0
 public function postAdd(Request $request)
 {
     // Validation
     $v = Validator::make($request->all(), ['title' => 'required|min:1', 'category' => 'required|numeric|exists:categories,id', 'amount' => 'required|numeric', 'date' => 'required|date|before:tomorrow']);
     if ($v->fails()) {
         return redirect()->back()->withErrors($v->errors())->withInput();
     }
     // Save BDD
     $expense = new Expense();
     $expense->title = $request->input('title');
     $expense->category_id = $request->input('category');
     $expense->amount = $request->input('amount');
     $expense->date = $request->input('date');
     $expense->save();
     // Redirect
     return redirect('/')->with('message', 'Expense added');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($project_id, $id)
 {
     $expense = Expense::find($id);
     $expense->delete();
     flash()->success('Expense has been successfully deleted!');
     return redirect()->action('ProjectsController@show', $project_id);
 }
Example #29
0
 /**
  * Deletes an expense
  *
  * @param $id
  *
  * @return array
  */
 public function delete($id)
 {
     $expense = $this->expense->findOrFail($id);
     $expense->delete($id);
 }
Example #30
0
 public function expenseSave()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('electricity' => 'required', 'water' => 'required', 'phone' => 'required', 'rent' => 'required', 'government' => 'required', 'depreciation' => 'required', 'taxes' => 'required', 'security' => 'required'));
     if ($validator->fails()) {
         return response()->json(['error' => 'Es necesario escribir algo para buscar!']);
     }
     // Get Expenses of selected month.
     $expenses = Expense::where('Date', '=', Input::get('year') . '-' . Input::get('month') . '-01')->first();
     if (!$expenses) {
         $response['state'] = 'Error';
         $response['error'] = 'No se encontraron gastos registrados para este mes!';
         return response()->json($response);
     }
     // Check we are not modifying taxes from a cuotafija.
     if ($expenses->Regimen == 'cuotageneral' && Input::get('taxes') != $expenses->Taxes) {
         $response['state'] = 'Error';
         $response['error'] = 'No se permite modificar los impuestos de un mes con regimen de cuota general!';
         return response()->json($response);
     }
     $expenses->Electricity = Input::get('electricity');
     $expenses->Water = Input::get('water');
     $expenses->Telecommunications = Input::get('phone');
     $expenses->Rent = Input::get('rent');
     $expenses->Government = Input::get('government');
     $expenses->Depreciation = Input::get('depreciation');
     $expenses->Taxes = Input::get('taxes');
     $expenses->Security = Input::get('security');
     $expenses->save();
     $response['state'] = 'Success';
     $response['message'] = 'Gastos guardados exitosamente!';
     return response()->json($response);
 }