Exemplo n.º 1
0
 public function save($publicId, $data)
 {
     if ($publicId) {
         $task = Task::scope($publicId)->firstOrFail();
     } else {
         $task = Task::createNew();
     }
     if (isset($data['client']) && $data['client']) {
         $task->client_id = Client::getPrivateId($data['client']);
     }
     if (isset($data['description'])) {
         $task->description = trim($data['description']);
     }
     //$timeLog = $task->time_log ? json_decode($task->time_log, true) : [];
     $timeLog = isset($data['time_log']) ? json_decode($data['time_log']) : [];
     if ($data['action'] == 'start') {
         $task->is_running = true;
         $timeLog[] = [strtotime('now'), false];
     } else {
         if ($data['action'] == 'resume') {
             $task->is_running = true;
             $timeLog[] = [strtotime('now'), false];
         } else {
             if ($data['action'] == 'stop' && $task->is_running) {
                 $timeLog[count($timeLog) - 1][1] = time();
                 $task->is_running = false;
             }
         }
     }
     $task->time_log = json_encode($timeLog);
     $task->save();
     return $task;
 }
 public function save($publicId = null, $input)
 {
     if ($publicId) {
         $payment = Payment::scope($publicId)->firstOrFail();
     } else {
         $payment = Payment::createNew();
     }
     $paymentTypeId = $input['payment_type_id'] ? $input['payment_type_id'] : null;
     $payment->payment_type_id = $paymentTypeId;
     $payment->payment_date = Utils::toSqlDate($input['payment_date']);
     $payment->transaction_reference = trim($input['transaction_reference']);
     if (!$publicId) {
         $clientId = Client::getPrivateId($input['client']);
         $amount = Utils::parseFloat($input['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 = isset($input['invoice']) && $input['invoice'] != "-1" ? Invoice::getPrivateId($input['invoice']) : null;
         $payment->amount = $amount;
     }
     $payment->save();
     return $payment;
 }
 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);
 }
Exemplo n.º 4
0
 public function save($publicId, $data)
 {
     if ($publicId) {
         $task = Task::scope($publicId)->firstOrFail();
     } else {
         $task = Task::createNew();
     }
     if (isset($data['client']) && $data['client']) {
         $task->client_id = Client::getPrivateId($data['client']);
     }
     if (isset($data['description'])) {
         $task->description = trim($data['description']);
     }
     $timeLog = $task->time_log ? json_decode($task->time_log, true) : [];
     if ($data['action'] == 'start') {
         $task->start_time = Carbon::now()->toDateTimeString();
         $task->is_running = true;
         $timeLog[] = [strtotime('now'), false];
     } else {
         if ($data['action'] == 'resume') {
             $task->break_duration = strtotime('now') - strtotime($task->start_time) + $task->duration;
             $task->resume_time = Carbon::now()->toDateTimeString();
             $task->is_running = true;
             $timeLog[] = [strtotime('now'), false];
         } else {
             if ($data['action'] == 'stop' && $task->is_running) {
                 if ($task->resume_time) {
                     $task->duration = $task->duration + strtotime('now') - strtotime($task->resume_time);
                     $task->resume_time = null;
                 } else {
                     $task->duration = strtotime('now') - strtotime($task->start_time);
                 }
                 $timeLog[count($timeLog) - 1][1] = strtotime('now');
                 $task->is_running = false;
             } else {
                 if ($data['action'] == 'save' && !$task->is_running) {
                     $task->start_time = $data['start_time'];
                     $task->duration = $data['duration'];
                     $task->break_duration = $data['break_duration'];
                 }
             }
         }
     }
     $task->duration = max($task->duration, 0);
     $task->break_duration = max($task->break_duration, 0);
     $task->time_log = json_encode($timeLog);
     $task->save();
     return $task;
 }
Exemplo n.º 5
0
 public function save($publicId = null, $input)
 {
     if ($publicId) {
         $credit = Credit::scope($publicId)->firstOrFail();
     } else {
         $credit = Credit::createNew();
     }
     $credit->client_id = Client::getPrivateId($input['client']);
     $credit->credit_date = Utils::toSqlDate($input['credit_date']);
     $credit->amount = Utils::parseFloat($input['amount']);
     $credit->balance = Utils::parseFloat($input['amount']);
     $credit->private_notes = trim($input['private_notes']);
     $credit->save();
     return $credit;
 }
Exemplo n.º 6
0
 public function create($clientPublicId = 0)
 {
     if (!Utils::isPro()) {
         return Redirect::to('/invoices/create');
     }
     $account = Auth::user()->account;
     $clientId = null;
     if ($clientPublicId) {
         $clientId = Client::getPrivateId($clientPublicId);
     }
     $invoice = $account->createInvoice(ENTITY_QUOTE, $clientId);
     $invoice->public_id = 0;
     $data = ['entityType' => $invoice->getEntityType(), 'invoice' => $invoice, 'data' => Input::old('data'), 'method' => 'POST', 'url' => 'invoices', 'title' => trans('texts.new_quote')];
     $data = array_merge($data, self::getViewModel());
     return View::make('invoices.edit', $data);
 }
Exemplo n.º 7
0
 public function save($publicId, $data, $task = null)
 {
     if ($task) {
         // do nothing
     } elseif ($publicId) {
         $task = Task::scope($publicId)->withTrashed()->firstOrFail();
     } else {
         $task = Task::createNew();
     }
     if ($task->is_deleted) {
         return $task;
     }
     if (isset($data['client']) && $data['client']) {
         $task->client_id = Client::getPrivateId($data['client']);
     }
     if (isset($data['description'])) {
         $task->description = trim($data['description']);
     }
     if (isset($data['time_log'])) {
         $timeLog = json_decode($data['time_log']);
     } elseif ($task->time_log) {
         $timeLog = json_decode($task->time_log);
     } else {
         $timeLog = [];
     }
     array_multisort($timeLog);
     if (isset($data['action'])) {
         if ($data['action'] == 'start') {
             $task->is_running = true;
             $timeLog[] = [strtotime('now'), false];
         } else {
             if ($data['action'] == 'resume') {
                 $task->is_running = true;
                 $timeLog[] = [strtotime('now'), false];
             } else {
                 if ($data['action'] == 'stop' && $task->is_running) {
                     $timeLog[count($timeLog) - 1][1] = time();
                     $task->is_running = false;
                 }
             }
         }
     }
     $task->time_log = json_encode($timeLog);
     $task->save();
     return $task;
 }
Exemplo n.º 8
0
 public function getDatatable($clientPublicId)
 {
     $clientId = Client::getPrivateId($clientPublicId);
     if (!$clientId) {
         app()->abort(404);
     }
     $query = $this->activityRepo->findByClientId($clientId);
     return Datatable::query($query)->addColumn('activities.id', function ($model) {
         return Utils::timestampToDateTimeString(strtotime($model->created_at));
     })->addColumn('activity_type_id', function ($model) {
         $data = ['client' => link_to('/clients/' . $model->client_public_id, Utils::getClientDisplayName($model)), 'user' => $model->is_system ? '<i>' . trans('texts.system') . '</i>' : Utils::getPersonDisplayName($model->user_first_name, $model->user_last_name, $model->user_email), 'invoice' => $model->invoice ? link_to('/invoices/' . $model->invoice_public_id, $model->is_recurring ? trans('texts.recurring_invoice') : $model->invoice) : null, 'quote' => $model->invoice ? link_to('/quotes/' . $model->invoice_public_id, $model->invoice) : null, 'contact' => $model->contact_id ? link_to('/clients/' . $model->client_public_id, Utils::getClientDisplayName($model)) : Utils::getPersonDisplayName($model->user_first_name, $model->user_last_name, $model->user_email), 'payment' => $model->payment ?: '', 'credit' => Utils::formatMoney($model->credit, $model->currency_id)];
         return trans("texts.activity_{$model->activity_type_id}", $data);
     })->addColumn('balance', function ($model) {
         return Utils::formatMoney($model->balance, $model->currency_id);
     })->addColumn('adjustment', function ($model) {
         return $model->adjustment != 0 ? Utils::wrapAdjustment($model->adjustment, $model->currency_id) : '';
     })->make();
 }
 public function save($input, $credit = null)
 {
     $publicId = isset($data['public_id']) ? $data['public_id'] : false;
     if ($credit) {
         // do nothing
     } elseif ($publicId) {
         $credit = Credit::scope($publicId)->firstOrFail();
         \Log::warning('Entity not set in credit repo save');
     } else {
         $credit = Credit::createNew();
     }
     $credit->client_id = Client::getPrivateId($input['client']);
     $credit->credit_date = Utils::toSqlDate($input['credit_date']);
     $credit->amount = Utils::parseFloat($input['amount']);
     $credit->balance = Utils::parseFloat($input['amount']);
     $credit->private_notes = trim($input['private_notes']);
     $credit->save();
     return $credit;
 }
Exemplo n.º 10
0
 public function create($clientPublicId = 0, $isRecurring = false)
 {
     $account = Auth::user()->account;
     $entityType = $isRecurring ? ENTITY_RECURRING_INVOICE : ENTITY_INVOICE;
     $clientId = null;
     if ($clientPublicId) {
         $clientId = Client::getPrivateId($clientPublicId);
     }
     $invoice = $account->createInvoice($entityType, $clientId);
     $invoice->public_id = 0;
     $data = ['clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(), 'entityType' => $invoice->getEntityType(), 'invoice' => $invoice, 'method' => 'POST', 'url' => 'invoices', 'title' => trans('texts.new_invoice')];
     $data = array_merge($data, self::getViewModel());
     return View::make('invoices.edit', $data);
 }
Exemplo n.º 11
0
 public function store(CreatePaymentRequest $request)
 {
     $input = $request->input();
     $input['invoice_id'] = Invoice::getPrivateId($input['invoice']);
     $input['client_id'] = Client::getPrivateId($input['client']);
     $payment = $this->paymentRepo->save($input);
     if (Input::get('email_receipt')) {
         $this->contactMailer->sendPaymentConfirmation($payment);
         Session::flash('message', trans('texts.created_payment_emailed_client'));
     } else {
         Session::flash('message', trans('texts.created_payment'));
     }
     return redirect()->to($payment->client->getRoute());
 }
Exemplo n.º 12
0
 public function getDatatable($clientPublicId = null)
 {
     $clientId = Client::getPrivateId($clientPublicId);
     $query = $this->activityRepo->findByClientId($clientId);
     return $this->createDatatable(ENTITY_ACTIVITY, $query);
 }
Exemplo n.º 13
0
 public function create(InvoiceRequest $request, $clientPublicId = 0, $isRecurring = false)
 {
     $account = Auth::user()->account;
     $entityType = $isRecurring ? ENTITY_RECURRING_INVOICE : ENTITY_INVOICE;
     $clientId = null;
     if ($request->client_id) {
         $clientId = Client::getPrivateId($request->client_id);
     }
     $invoice = $account->createInvoice($entityType, $clientId);
     $invoice->public_id = 0;
     if (Session::get('expenses')) {
         $invoice->expenses = Expense::scope(Session::get('expenses'))->with('documents')->get();
     }
     $clients = Client::scope()->with('contacts', 'country')->orderBy('name');
     if (!Auth::user()->hasPermission('view_all')) {
         $clients = $clients->where('clients.user_id', '=', Auth::user()->id);
     }
     $data = ['clients' => $clients->get(), 'entityType' => $invoice->getEntityType(), 'invoice' => $invoice, 'method' => 'POST', 'url' => 'invoices', 'title' => trans('texts.new_invoice')];
     $data = array_merge($data, self::getViewModel($invoice));
     return View::make('invoices.edit', $data);
 }
Exemplo n.º 14
0
 /**
  * @param null $clientPublicId
  * @return \Illuminate\Http\JsonResponse
  */
 public function getDatatable($clientPublicId = null)
 {
     $clientId = Client::getPrivateId($clientPublicId);
     $query = $this->activityRepo->findByClientId($clientId);
     return $this->datatableService->createDatatable(new ActivityDatatable(false), $query);
 }