/** * Display the specified resource. * GET /accountreceivables/{id} * * @param int $id * @return Response */ public function show($id) { $invoices = Invoice::with('invoicedetail')->find($id); if ($invoices->type === "to tenant") { $total = $invoices->invoicedetail->rent + $invoices->invoicedetail->water + $invoices->invoicedetail->electricity + $invoices->invoicedetail->security + $invoices->invoicedetail->service + $invoices->invoicedetail->garbage; } elseif ($invoices->type === "refund") { $total = $invoices->invoicedetail->rentD + $invoices->invoicedetail->waterD + $invoices->invoicedetail->electricityD + $invoices->invoicedetail->g_repairs + $invoices->invoicedetail->transport_cost + $invoices->invoicedetail->o_bills + $invoices->invoicedetail->storage_fees + $invoices->invoicedetail->fixed_unit; } elseif ($invoices->type === "deposits") { $total = $invoices->invoicedetail->rentD + $invoices->invoicedetail->waterD + $invoices->invoicedetail->electricityD + $invoices->invoicedetail->g_repairs + $invoices->invoicedetail->transport_cost + $invoices->invoicedetail->o_bills + $invoices->invoicedetail->storage_fees + $invoices->invoicedetail->fixed_unit + $invoices->invoicedetail->rent; } $houseid = $invoices->id; $hid = $invoices->houseID; $housename = House::where('id', $hid)->pluck('name'); $propertyid = House::where('id', $hid)->pluck('propertyID'); $propertyname = Property::where('id', $propertyid)->pluck('name'); $allbal = Invoice::where('houseID', $hid)->sum('balance'); if ($invoices->amountpaid <= 0) { $outstandingbal = $allbal; } else { $outstandingbal = $allbal - $invoices->balance; } $balance = $invoices->balance; if ($outstandingbal == $invoices->balance) { $amountdue = $invoices->balance; } else { $amountdue = $invoices->balance + $outstandingbal; } $title = "Print Invoice"; return View::make('backend.code.invoice.show', compact('invoices', 'housename', 'title', 'outstandingbal', 'propertyname', 'invoicedetails', 'total', 'balance', 'amountdue')); }
/** * Display a listing of the resource. * GET /invoices * * @return Response */ public function index() { $user = Auth::user()->id; // Grab all the user invoices $invoices = $this->invoice->where('user_id', $user)->get(); $tax_rates = TaxRate::where('user_id', $user)->get(); $items = $this->invoice->item; //Include deleted invoices if (Input::get('withTrashed')) { } else { if (Input::get('onlyTrashed')) { $invoices = $this->invoice->onlyTrashed()->where('user_id', $user)->get(); } } return View::make('invoices.index', compact('invoices', 'tax_rates')); }
public function getInvoices() { $invoices = Invoice::where('account_id', Auth::user()->account_id)->where('branch_id', Session::get('branch_id'))->select('public_id', 'invoice_status_id', 'client_id', 'invoice_number', 'invoice_date', 'importe_total', 'branch_name')->orderBy('public_id', 'DESC')->get(); foreach ($invoices as $key => $invoice) { $invoice_razon = Client::where('account_id', Auth::user()->account_id)->select('name')->where('id', $invoice->client_id)->first(); $invoice->razon = $invoice_razon->name; $estado = InvoiceStatus::where('id', $invoice->invoice_status_id)->first(); $invoice->estado = $estado->name; $invoice->accion = "<a class='btn btn-primary btn-xs' data-task='view' href='factura/{$invoice->public_id}' style='text-decoration:none;color:white;'><i class='glyphicon glyphicon-eye-open'></i></a> <a class='btn btn-warning btn-xs' href='copia/{$invoice->public_id}' style='text-decoration:none;color:white;'><i class='glyphicon glyphicon-duplicate'></i></a>"; } $invoiceJson = ['data' => $invoices]; return Response::json($invoiceJson); }
public static function amendInvoice($booking) { $total = Booking::getTotalBookingAmount($booking); $invoice = Invoice::where('booking_id', $booking->id)->first(); if ($invoice) { $invoice->count = ++$invoice->count; $invoice->amount = $total; $invoice->save(); return true; } else { $invoiceData = array('amount' => $total, 'booking_id' => $booking->id); Invoice::create($invoiceData); return false; } }
public function showReceipt($id) { $receipts = Receipt::find($id); $hid = $receipts->houseID; $housename = $hid; $propertyid = House::where('name', $hid)->pluck('propertyID'); $propertyname = Property::where('id', $propertyid)->pluck('name'); $inid = $receipts->invoiceID; $allbal = Invoice::where('houseID', $hid)->sum('balance'); $current_bal = Invoice::where('id', $inid)->pluck('balance'); $outstandingbal = $allbal - $current_bal; $amountdue = $allbal; $balance = $receipts->balance; return View::make('backend.code.invoice.showr', compact('receipts', 'amountdue', 'housename', 'outstandingbal', 'propertyname', 'invoicedetails', 'total', 'balance', 'amountdue')); }
/** * Get next invoice number */ public static function next_invoice_number($type, $days) { $last = Invoice::where('type', $type)->where('days', $days)->orderBy('number', 'DESC')->first(); if ($last) { return $last->number + 1; } else { return 1; } }
private function save($publicId = null) { $action = Input::get('action'); $entityType = Input::get('entityType'); if ($action == 'archive' || $action == 'delete' || $action == 'mark') { return InvoiceController::bulk($entityType); } $input = json_decode(Input::get('data')); $invoice = $input->invoice; if (Utils::isAdmin()) { $branch_id = $input->invoice->branch_id; $branch = Branch::where('account_id', '=', Auth::user()->account_id)->where('public_id', $branch_id)->first(); // $branch = DB::table('branches')->where('id',$branch_id)->first(); } else { $branch = Auth::user()->branch; $branch_id = $branch->id; $branch = DB::table('branches')->where('id', $branch_id)->first(); } $today = new DateTime('now'); $today = $today->format('Y-m-d'); $datelimit = DateTime::createFromFormat('Y-m-d', $branch->deadline); $datelimit = $datelimit->format('Y-m-d'); $valoresPrimera = explode("-", $datelimit); $valoresSegunda = explode("-", $today); $diaPrimera = $valoresPrimera[2]; $mesPrimera = $valoresPrimera[1]; $anyoPrimera = $valoresPrimera[0]; $diaSegunda = $valoresSegunda[2]; $mesSegunda = $valoresSegunda[1]; $anyoSegunda = $valoresSegunda[0]; $a = gregoriantojd($mesPrimera, $diaPrimera, $anyoPrimera); $b = gregoriantojd($mesSegunda, $diaSegunda, $anyoSegunda); $errorS = "Expiró la fecha límite de " . $branch->name; if ($a - $b < 0) { Session::flash('error', $errorS); return Redirect::to("{$entityType}s/create")->withInput(); } else { $last_invoice = Invoice::where('account_id', '=', Auth::user()->account_id)->first(); if ($last_invoice) { $yesterday = $last_invoice->invoice_date; $today = date("Y-m-d", strtotime($invoice->invoice_date)); $errorD = "La fecha de la factura es incorrecta"; $yesterday = new DateTime($yesterday); $today = new DateTime($today); if ($yesterday > $today) { Session::flash('error', $errorD); return Redirect::to("{$entityType}s/create")->withInput(); } } if ($errors = $this->invoiceRepo->getErrors($invoice)) { Session::flash('error', trans('texts.invoice_error')); return Redirect::to("{$entityType}s/create")->withInput()->withErrors($errors); } else { $this->taxRateRepo->save($input->tax_rates); $clientData = (array) $invoice->client; $clientData['branch'] = $branch->id; $client = $this->clientRepo->save($invoice->client->public_id, $clientData); $invoiceData = (array) $invoice; $invoiceData['branch_id'] = $branch->id; $invoiceData['client_id'] = $client->id; $invoiceData['client_nit'] = $client->nit; $invoiceData['client_name'] = $client->name; $invoiceData['action'] = $action; $invoice = $this->invoiceRepo->save($publicId, $invoiceData, $entityType); $account = Auth::user()->account; // if ($account->invoice_taxes != $input->invoice_taxes // || $account->invoice_item_taxes != $input->invoice_item_taxes // || $account->invoice_design_id != $input->invoice->invoice_design_id) // { // $account->invoice_taxes = $input->invoice_taxes; // $account->invoice_item_taxes = $input->invoice_item_taxes; // $account->invoice_design_id = $input->invoice->invoice_design_id; // $account->save(); // } $client->load('contacts'); $sendInvoiceIds = []; foreach ($client->contacts as $contact) { if ($contact->send_invoice || count($client->contacts) == 1) { $sendInvoiceIds[] = $contact->id; } } foreach ($client->contacts as $contact) { $invitation = Invitation::scope()->whereContactId($contact->id)->whereInvoiceId($invoice->id)->first(); if (in_array($contact->id, $sendInvoiceIds) && !$invitation) { $invitation = Invitation::createNew(); $invitation->invoice_id = $invoice->id; $invitation->contact_id = $contact->id; $invitation->invitation_key = str_random(RANDOM_KEY_LENGTH); $invitation->save(); } else { if (!in_array($contact->id, $sendInvoiceIds) && $invitation) { $invitation->delete(); } } } $invoice_date = date("d/m/Y", strtotime($invoice->invoice_date)); require_once app_path() . '/includes/BarcodeQR.php'; // $ice = $invoice->amount-$invoice->fiscal; $desc = $invoice->subtotal - $invoice->amount; $subtotal = number_format($invoice->subtotal, 2, '.', ''); $amount = number_format($invoice->amount, 2, '.', ''); $fiscal = number_format($invoice->fiscal, 2, '.', ''); // $icef = number_format($ice, 2, '.', ''); $descf = number_format($desc, 2, '.', ''); // if($icef=="0.00"){ // $icef = 0; // } if ($descf == "0.00") { $descf = 0; } $icef = 0; $qr = new BarcodeQR(); $datosqr = $invoice->account_nit . '|' . $invoice->invoice_number . '|' . $invoice->number_autho . '|' . $invoice_date . '|' . $subtotal . '|' . $amount . '|' . $invoice->control_code . '|' . $invoice->client_nit . '|' . $icef . '|0|0|' . $descf; $qr->text($datosqr); $qr->draw(150, 'qr/' . $account->account_key . '_' . $branch->name . '_' . $invoice->invoice_number . '.png'); $input_file = 'qr/' . $account->account_key . '_' . $branch->name . '_' . $invoice->invoice_number . '.png'; $output_file = 'qr/' . $account->account_key . '_' . $branch->name . '_' . $invoice->invoice_number . '.jpg'; $inputqr = imagecreatefrompng($input_file); list($width, $height) = getimagesize($input_file); $output = imagecreatetruecolor($width, $height); $white = imagecolorallocate($output, 255, 255, 255); imagefilledrectangle($output, 0, 0, $width, $height, $white); imagecopy($output, $inputqr, 0, 0, 0, 0, $width, $height); imagejpeg($output, $output_file); $invoice->qr = HTML::image_data('qr/' . $account->account_key . '_' . $branch->name . '_' . $invoice->invoice_number . '.jpg'); $invoice->save(); $message = trans($publicId ? "texts.updated_{$entityType}" : "texts.created_{$entityType}"); if ($input->invoice->client->public_id == '-1') { $message = $message . ' ' . trans('texts.and_created_client'); $url = URL::to('clients/' . $client->public_id); Utils::trackViewed($client->getDisplayName(), ENTITY_CLIENT, $url); } if ($action == 'clone') { return $this->cloneInvoice($publicId); } else { if ($action == 'convert') { return $this->convertQuote($publicId); } else { if ($action == 'email') { $aux = 0; foreach ($client->contacts as $contact) { if ($contact->email) { $aux = 1; } } if ($aux == 0) { $errorMessage = trans('El cliente no tiene Correo Electrónico.'); Session::flash('error', $errorMessage); } else { if (Auth::user()->confirmed && !Auth::user()->isDemo()) { $message = trans("texts.emailed_{$entityType}"); $this->mailer->sendInvoice($invoice); Session::flash('message', $message); } else { $errorMessage = trans(Auth::user()->registered ? 'texts.confirmation_required' : 'texts.registration_required'); Session::flash('error', $errorMessage); Session::flash('message', $message); } } } else { if ($action == 'savepay') { $payment = Payment::createNew(); $payment->client_id = $client->id; $payment->invoice_id = $invoice->id; $payment->payment_type_id = 1; $payment->payment_date = $invoice->invoice_date; $payment->amount = $invoice->amount; $payment->save(); $message = trans("texts.savepay_{$entityType}"); Session::flash('message', $message); } else { if ($action == 'savepaycredit') { $payment = Payment::createNew(); $credits = Credit::scope()->where('client_id', '=', $client->id)->where('balance', '>', 0)->orderBy('created_at')->get(); $applied = 0; foreach ($credits as $credit) { $applied += $credit->apply($invoice->amount); if ($applied >= $invoice->amount) { break; } } $payment->client_id = $client->id; $payment->invoice_id = $invoice->id; $payment->payment_type_id = 2; $payment->payment_date = $invoice->invoice_date; $payment->amount = $invoice->amount; $payment->save(); $message = trans("texts.savepay_{$entityType}"); Session::flash('message', $message); } else { Session::flash('message', $message); } } } } } $url = "{$entityType}s/" . $invoice->public_id . '/edit'; return Redirect::to($url); } } }
/** * Funcion utilizada por ajax * * @param int $client_id * @return facturas */ public function obtenerFacturas($client_id) { $facturas = Invoice::where('account_id', Auth::user()->account_id)->where('client_id', $client_id)->where('balance', '>', '0')->select('id', 'invoice_number', 'importe_total', 'balance')->get(); $respuesta = get_object_vars($facturas); return Response::json($facturas); }
public function export() { $fecha = explode(" ", Input::get('date')); $vec = ["Ene" => '01', "Feb" => '02', "Mar" => '03', "Abr" => '04', "May" => '05', "Jun" => '06', "Jul" => '07', "Ago" => '08', "Sep" => '09', "Oct" => '10', "Nov" => '11', "Dic" => '12']; $date = $fecha[1] . "-" . $vec[substr($fecha[0], 0, 3)]; $output = fopen('php://output', 'w') or Utils::fatalError(); header('Content-Type:application/txt'); header('Content-Disposition:attachment;filename=export.txt'); $invoices = Invoice::where('account_id', Auth::user()->account_id)->where("invoice_number", "!=", "")->where("invoice_number", "!=", 0)->where('invoice_date', 'LIKE', $date . '%')->get(); $p = "|"; $sw = true; $num = 1; foreach ($invoices as $i) { $sw = false; if ($i->invoice_status_id == 6) { $i->client_nit = 0; $i->client_name = "ANULADA"; $i->importe_total = "0.00"; $i->importe_neto = "0.00"; //$i->control_code="0"; $i->discount = "0.00"; $status = "A"; } else { $status = "V"; } // $datos = $i->invoice_number.$i->client_nit.$p.$i->client_name.$p.$p.$i->account_nit.$p.$i->invoice_date.$p.$i->importe_total.$p.$i->importe_ice.$p.$i->importe_exento.$p.$i->importe_neto.$p.$i->debito_fiscal.$p.$status.$p.$i->control_code."\r\n"; $fecha = date("d/m/Y", strtotime($i->invoice_date)); $fecha = \DateTime::createFromFormat('Y-m-d', $i->invoice_date); if ($fecha == null) { $fecha = $i->invoice_date; } else { $fecha = $fecha->format('d/m/Y'); } //$doc =TypeDocumentBranch::where('branch_id',$i->branch_id)->orderBy('id','desc')->first(); $tipo = TypeDocument::where('id', $i->javascript)->first(); //echo $tipo->master_id."<br>"; $cuenta = Account::where('id', Auth::user()->account_id)->select('currency_id')->first(); $dolar = Invoice::where('account_id', Auth::user()->account_id)->select('sfc')->where('id', $i->id)->where('branch_id', $i->branch_id)->first(); if ($cuenta->currency_id == 2) { $i->importe_total = $i->importe_total * $dolar->sfc; $i->importe_total = number_format((double) $i->importe_total, 2, '.', ''); $i->importe_neto = $i->importe_neto * $dolar->sfc; $i->importe_neto = number_format((double) $i->importe_neto, 2, '.', ''); $i->discount = $i->discount * $dolar->sfc; $i->discount = number_format((double) $i->discount, 2, '.', ''); } if ($tipo->master_id == 1 || $tipo->master_id == 4) { $debito = $i->importe_neto * 0.13; $debito = number_format((double) $debito, 2, '.', ''); $datos = "3" . $p . $num . $p . $fecha . $p . $i->invoice_number . $p . $i->number_autho . $p . $status . $p . $i->client_nit . $p . $i->client_name . $p . $i->importe_total . $p . $i->importe_ice . $p . $i->importe_exento . $p . "0.00" . $p . $i->importe_total . $p . $i->discount . $p . $i->importe_neto . $p . $debito . $p . $i->control_code . "\r\n"; } if ($tipo->master_id == 3) { $datos = "3" . $p . $num . $p . $fecha . $p . $i->invoice_number . $p . $i->number_autho . $p . $status . $p . $i->client_nit . $p . $i->client_name . $p . $i->importe_total . $p . $i->importe_ice . $p . $i->importe_exento . $p . $i->importe_neto . $p . $i->importe_total . $p . $i->discount . $p . "0.00" . $p . "0.00" . $p . $i->control_code . "\r\n"; } $num++; //echo $i->invoice_number."<br>"; fputs($output, $datos); $datos = null; } //return 0; if ($sw) { fputs($output, "No se encontraron ventas en este periodo: " . Input::get('date')); } fclose($output); exit; }
public function getReport() { $input = Input::all(); $v = Validator::make(Input::All(), array('property_name' => 'required', 'from_date' => 'required', 'to_date' => 'required', 'type' => 'required', 'houseIDReport' => 'required', 'agent_id' => 'required')); if ($v->passes()) { $propertyid = Input::get('property_name'); $from_date = Input::get('from_date'); $to_date = Input::get('to_date'); $type = Input::get('type'); $houseID = Input::get('houseIDReport'); $start_day = date("Y-m-d H:i:s", strtotime($from_date)); $end_day = date("Y-m-d H:i:s", strtotime($to_date)); $agent_id = Input::get('agent_id'); $billedusr = User::find($agent_id); $hisBalance = $billedusr->credit_balance; $newBalance = $hisBalance - 3; $billedusr->credit_balance = $newBalance; $billedusr->save(); $billstatement = new Statement(); $billstatement->type = "Report Generation"; $billstatement->amount = 3; $billstatement->save(); if ($houseID === "All Report") { $sumReceipts = Receipt::whereBetween('created_at', array($start_day, $end_day))->where('propertyid', $propertyid)->sum('amountpaid'); $sumInvoiceBalance = Invoice::whereBetween('created_at', array($start_day, $end_day))->where('propertyid', $propertyid)->sum('balance'); $sumInvoicePaid = Invoice::whereBetween('created_at', array($start_day, $end_day))->where('propertyid', $propertyid)->sum('amountpaid'); $sumRefundPaid = Invoice::where('propertyid', $propertyid)->where('type', '=', 'refund')->sum('amountpaid'); $invoiceUn = Invoice::list('houseID'); $unitsUnpaid = House::whereIn('name', $invoiceUn)->count(); $sumInvoice = $sumInvoiceBalance + $sumInvoicePaid; $noteSum = array('error' => false, 'type' => "All", 'sumRefund' => $sumRefundPaid, 'unitsUnpaid' => $unitsUnpaid, 'sumInvoice' => $sumInvoice, 'sumReceipt' => $sumReceipts); } else { $sumReceipts = Receipt::where('houseID', $houseID)->whereBetween('created_at', array($start_day, $end_day))->sum('amountpaid'); $sumInvoiceBalance = Invoice::where('houseID', $houseID)->whereBetween('created_at', array($start_day, $end_day))->sum('balance'); $sumInvoicePaid = Invoice::where('houseID', $houseID)->whereBetween('created_at', array($start_day, $end_day))->sum('amountpaid'); $sumInvoice = $sumInvoiceBalance + $sumInvoicePaid; $noteSum = array('error' => false, 'type' => "House", 'sumInvoice' => $sumInvoice, 'sumReceipt' => $sumReceipts); } return $noteSum; } $notePE = array('error' => true, 'message' => 'Ensure that all the fields are set'); return $notePE; }
public function enviarCorreoFactura($min = 0, $max = 0) { //todotix http $min = Input::get('min'); $max = Input::get('max'); $branch = 1; $cuenta = Account::where('domain', 'roy')->where('id', 1)->first(); $invoices = Invoice::where('account_id', $cuenta->id)->where('branch_id', $branch)->where('public_id', '>=', $min)->where('public_id', '<=', $max)->get(); $count = 1; foreach ($invoices as $key => $invoice) { $client = Client::where('id', $invoice->client_id)->select('name', 'business_name', 'nit')->first(); if (filter_var($client->name, FILTER_VALIDATE_EMAIL)) { $this->sendInvoiceByMailLocal($client->name, $client->business_name, $invoice->id, $invoice->invoice_date, $client->nit); echo $count . " " . $client->name . " " . $invoice->control_code . " " . $invoice->invoice_number . "<br>"; sleep(0.2); $count = $count + 1; } } }
public function Actualizar() { if ($this->id) { if (empty($this->fv_error_message)) { $facturas = Invoice::where('branch_id', $this->id)->where('account_id', $this->account_id)->first(); //si no tienen facturas seguir if (!$facturas) { $usuarios = UserBranch::getUsersBranch($this->id, $this->account_id); // si no tiene usuarios asignados y no tiene facturas puede hacer los cambios --esto es para de baja necesito descansar XD // if(!$usuarios) // { $this->account_id = $this->account_id ? $this->account->id : $this->fv_account_id; $this->name = $this->fv_name; $this->number_branch = $this->fv_number_branch; $this->address2 = $this->fv_address2; $this->address1 = $this->fv_address1; $this->work_phone = $this->fv_workphone; $this->city = $this->fv_city; $this->state = $this->fv_state; $this->deadline = $this->fv_deadline; $this->key_dosage = $this->fv_key_dossage; $this->economic_activity = $this->fv_economic_activity; $this->number_process = $this->fv_number_process; $this->number_autho = $this->fv_nummber_autho; $this->law = $this->fv_law; $this->type_third = $this->getType_thrird(); $this->invoice_number_counter = 1; $this->save(); //verificar los nuevos asignados //aplicando algorimo de asignacion foreach (TypeDocumentBranch::where('branch_id', $this->id)->get() as $type_document_branch) { # code... $type_document_branch->delete(); } foreach ($this->fv_type_documents_branch as $type_document_nuevos) { # code... //TODO: acabar esta parte de la consulta me falta la asignacion XD ...... :() $existeAsignado = TypeDocumentBranch::withTrashed()->where('branch_id', $this->id)->where('type_document_id', $type_document_nuevos)->first(); if ($existeAsignado) { $existeAsignado->restore(); } else { $tipo = new TypeDocumentBranch(); $tipo->branch_id = $this->id; $tipo->type_document_id = $type_document_nuevos; $tipo->save(); } } $this->fv_error_message = "Registro Actualizado"; return true; // } // $this->fv_error_message = $this->fv_error_message . ' debe reasignar a los usuarios de esta sucursal <br>'; // return false; } //si tiene facturas hay que verificar la fecha actual sea mayor a la fecha limite $this->name = $this->fv_name; $this->address2 = $this->fv_address2; $this->address1 = $this->fv_address1; $this->work_phone = $this->fv_workphone; $this->city = $this->fv_city; $this->state = $this->fv_state; $fecha_actual = new DateTime("now"); $fecha_limite = new DateTime($this->deadline); if ($fecha_actual > $fecha_limite) { $this->number_branch = $this->fv_number_branch; //docificaciones y numero de invoicce nada masXD $this->deadline = $this->fv_deadline; $this->key_dosage = $this->fv_key_dossage; $this->economic_activity = $this->fv_economic_activity; $this->number_process = $this->fv_number_process; $this->number_autho = $this->fv_nummber_autho; $this->law = $this->fv_law; $this->type_third = $this->getType_thrird(); //colocamos la sucursal en 1 de nuevo $this->invoice_number_counter = 1; } $this->save(); //modificacion foreach (TypeDocumentBranch::where('branch_id', $this->id) as $type_document_branch) { # code... $type_document_branch->delete(); } foreach ($this->fv_type_documents_branch as $type_document_nuevos) { # code... //TODO: acabar esta parte de la consulta me falta la asignacion XD ...... :() $existeAsignado = TypeDocumentBranch::withTrashed()->where('branch_id', $this->id)->where('type_document_id', $type_document_nuevos)->first(); if ($existeAsignado) { $existeAsignado->restore(); } else { $tipo = new TypeDocumentBranch(); $tipo->branch_id = $this->id; $tipo->type_document_id = $type_document_nuevos; $tipo->save(); } } $this->fv_error_message = "Registro Actualizado"; return true; } } $this->fv_error_message = $this->fv_error_message . ' Sucursal ' . ERROR_NULL . '<br>'; return false; }
public function setAmount($amount) { if (is_null($amount)) { $this->fv_amount = "Factura " . ERROR_NULL . "<br>"; return; } $credit = Credit::where('account_id', $this->getAccountId())->where('client_id', $this->getClientId())->get(); $invoice = Invoice::where('id', $this->getInvoiceId())->first(); $credito = 0; foreach ($credit as $cre) { $credito += $cre->balance; } //echo $amount." - ".$credito; if ($credito < $amount && $this->getPaymentTypeId() == 2) { $this->fv_amount = "No tiene suficiente crédito para realizar este pago."; return; } if ($invoice->balance < $amount) { $this->fv_amount = "No es posible pagar mas de lo adeudado."; return; } if ($amount <= 0) { $this->fv_amount = "El monto no puede ser menor o igual a 0"; return; } $this->fv_amount = null; $this->amount = $amount; return $this; }
public function excel() { //print_r(Input::get('excel')); //return 0; //return View::make('factura.import'); $dir = "files/excel/"; $fecha = base64_encode("excel" . date('d/m/Y-H:m:i')); $file_name = $fecha; //return $file_name; $file = Input::file('excel'); $destinationPath = 'files/excel/'; // If the uploads fail due to file system, you can try doing public_path().'/uploads' $filename = $file_name; //str_random(12); //$filename = $file->getClientOriginalName(); //$extension =$file->getClientOriginalExtension(); $upload_success = Input::file('excel')->move($destinationPath, $filename); // if( $upload_success ) { // return Response::json('success', 200); // } else { // return Response::json('error', 400); // } // return 0; $results = Excel::selectSheetsByIndex(0)->load($dir . $file_name)->get(); $factura = array(); $groups = array(); //shattering file gotten $nit = ""; foreach ($results as $key => $res) { $dato = []; //$nit = ""; foreach ($res as $r) { if ($r != "") { array_push($dato, $r); } } //$nit = $dato[0]; if ($dato) { if ($nit == $dato[0]) { array_push($groups, $dato); } else { if ($groups) { $bbr = ['id' => $groups[0][0], 'nit' => $groups[0][1], 'nota' => $groups[0][5]]; $products = array(); foreach ($groups as $gru) { $pro['product_key'] = $gru[2]; $pro['description'] = $gru[3]; $pro['cost'] = $gru[4]; array_push($products, $pro); } $bbr['products'] = $products; array_push($factura, $bbr); } $groups = array(); $nit = $dato[0]; array_push($groups, $dato); } } } if ($groups) { $bbr = ['id' => $groups[0][0], 'nit' => $groups[0][1], 'nota' => $groups[0][5]]; $products = array(); foreach ($groups as $gru) { $pro['product_key'] = $gru[2]; $pro['description'] = $gru[3]; $pro['cost'] = $gru[4]; array_push($products, $pro); } $bbr['products'] = $products; array_push($factura, $bbr); } $returnable = $this->validateShatterExcel($factura); if ($returnable != "") { Session::flash('error', $returnable); return View::make('factura.import'); } //echo $returnable; //return 0; $cont = 0; foreach ($factura as $fac) { $this->saveLote($fac); $cont++; } Session::flash('message', 'Se importaron ' . $cont . ' facturas exitósamente'); $invoices = Invoice::where('account_id', Auth::user()->account_id)->where('branch_id', Session::get('branch_id'))->orderBy('public_id', 'DESC')->get(); return View::make('factura.index', array('invoices' => $invoices)); return 0; }
public function pagoCliente($client_id, $invoice_id) { $client = Client::where('id', $client_id)->first(); $invoice = Invoice::where('id', $invoice_id)->first(); $dato = ['now' => date('d/m/Y'), 'cliente' => $client->name, 'client_id' => $client->id, 'factura' => 'Factura #' . $invoice->invoice_number . ' Importe Total ' . $invoice->importe_total . '(' . $invoice->balance . ')', 'invoice_id' => $invoice->id, 'amount' => $invoice->balance]; return View::make('pagos.createCustom', $dato); }
public function getOpenInvoicesByUser() { return Invoice::where('status_id', '=', '1')->where('owner_id', '=', Sentry::getUser()->id)->get(); }
public static function addNote($id, $note_sent, $status) { $invoice = Invoice::where('id', '=', $id)->first(); if ($invoice->note == "") { $nota = array(); $nota[0] = ['date' => date('d-m-Y H:i:s'), 'note' => $note_sent]; } else { $nota = json_decode($invoice->note); $nota_add = ['date' => date('d-m-Y H:i:s'), 'note' => $note_sent]; array_push($nota, $nota_add); } $invoice->note = json_encode($nota); $invoice->invoice_status_id = $status; $invoice->save(); }
Route::get('refund-selected/{id}', array('as' => 'refund-selected', 'uses' => 'BillController@refundSelected')); Route::post('refund-tenant', array('as' => 'refund-tenant', 'uses' => 'BillController@refundStore')); //select unit Route::get('unit/{id}', array('as' => 'create-house', 'uses' => 'HousController@create')); Route::get('occupy/{id}', array('as' => 'create-occupancy', 'uses' => 'HousController@createOccupancy')); Route::get('invoicee/{id}', array('as' => 'create-invoice', 'uses' => 'HousController@createInvoice')); Route::get('refunds', array('as' => 'refunds', 'uses' => 'HousController@refunds')); Route::get('pay/{id}', array('as' => 'create-payment', 'uses' => 'HousController@createPayment')); Route::get('del/{id}', array('as' => 'del', 'uses' => 'HousesController@delHouse')); Route::get('del/property/{id}', array('as' => 'del/property', 'uses' => 'PropertiesController@delProperty')); Route::get('delete/{id}', array('as' => 'delete', 'uses' => 'InvoiceController@delInvoice')); Route::get('billing', array('as' => 'billing', 'uses' => 'HousController@billing')); Route::get('bill-house/{id}', array('as' => 'bill-house', 'uses' => 'HousController@billHouse')); Route::get('tenantadd', array('as' => 'tenant-add', 'uses' => 'HousController@addTenant')); Route::get('debts', ['as' => 'debts', function () { $invoices = Invoice::where('agent_id', '=', Sentry::getUser()->id)->with('invoicedetail')->get(); $countt = $invoices->sum('balance'); return number_format($countt); }]); }); /* |-------------------------------------------------------------------------- | Authentication and Authorization Routes |-------------------------------------------------------------------------- | | | */ Route::group(array('prefix' => 'auth'), function () { # Login Route::get('signin', array('as' => 'signin', 'uses' => 'AuthController@getSignin'));
/** * Remove the specified product from storage. * * @param int $id * @return Response */ public function destroy($id) { $orderItems = OrdersItem::where('order_id', '=', $id)->get(); $invoices = Invoice::where('order_id', '=', $id)->get(); if ($orderItems) { foreach ($orderItems as $orderItem) { OrdersItem::destroy($orderItem->id); } } if ($invoices) { foreach ($invoices as $invoice) { Invoice::destroy($invoice->id); } } Order::destroy($id); return Response::json(array('success' => true)); }
public function showSpeReceipts($id) { $invoices = Invoice::with('invoicedetail')->find($id); if ($invoices->type === "to tenant") { $total = $invoices->invoicedetail->rent + $invoices->invoicedetail->water + $invoices->invoicedetail->electricity + $invoices->invoicedetail->security + $invoices->invoicedetail->service + $invoices->invoicedetail->garbage; } elseif ($invoices->type === "refund") { $total = $invoices->invoicedetail->rentD + $invoices->invoicedetail->waterD + $invoices->invoicedetail->electricityD + $invoices->invoicedetail->g_repairs + $invoices->invoicedetail->transport_cost + $invoices->invoicedetail->o_bills + $invoices->invoicedetail->storage_fees + $invoices->invoicedetail->fixed_unit; } elseif ($invoices->type === "deposits") { $total = $invoices->invoicedetail->rentD + $invoices->invoicedetail->waterD + $invoices->invoicedetail->electricityD + $invoices->invoicedetail->g_repairs + $invoices->invoicedetail->transport_cost + $invoices->invoicedetail->o_bills + $invoices->invoicedetail->storage_fees + $invoices->invoicedetail->fixed_unit + $invoices->invoicedetail->rent; } $houseid = $invoices->id; $hid = $invoices->houseID; $housename = House::where('id', $hid)->pluck('name'); $tenantname = House::where('id', $hid)->pluck('tenant'); $propertyid = House::where('id', $hid)->pluck('propertyID'); $propertyname = Property::where('id', $propertyid)->pluck('name'); $allbal = Invoice::where('houseID', $hid)->sum('balance'); if ($invoices->amountpaid <= 0) { $outstandingbal = $allbal; } else { $outstandingbal = $allbal - $invoices->balance; } $balance = $invoices->balance; if ($outstandingbal == $invoices->balance) { $amountdue = $invoices->balance; } else { $amountdue = $invoices->balance + $outstandingbal; } $title = "Print Receipt"; /* $emailcontent = array ( 'propertyname'=> $propertyname, 'housename'=> $housename, 'tenant'=> $tenantname, 'tfname'=> $invoices->recipient, 'invoiceid'=> $invoices->id, 'created_at'=> $invoices->created_at, 'invoicetype'=> $invoices->type, 'rent'=> $invoices->invoicedetail->rent, 'water'=> $invoices->invoicedetail->water, 'electricity'=> $invoices->invoicedetail->electricity, 'security'=> $invoices->invoicedetail->security, 'service'=> $invoices->invoicedetail->service, 'garbage'=> $invoices->invoicedetail->garbage, 'rentD'=> $invoices->invoicedetail->rentD, 'rent'=> $invoices->invoicedetail->rent, 'waterD'=> $invoices->invoicedetail->waterD, 'electricityD'=> $invoices->invoicedetail->electricityD, 'garbage'=> $invoices->invoicedetail->garbage, 'transport_cost'=> $invoices->invoicedetail->transport_cost, 'g_repairs'=> $invoices->invoicedetail->g_repairs, 'o_bills'=> $invoices->invoicedetail->o_bills, 'storage_fees'=> $invoices->invoicedetail->storage_fees, 'total'=> $total, 'amountpaid'=> $invoices->amountpaid, 'balance'=> $balance, 'outstandingbal'=> $outstandingbal, 'amountdue'=> $amountdue, 'duedate'=> $invoices->duedate ); Mail::send('emails.receipts', $emailcontent, function($message) { $message->to('*****@*****.**') ->subject('Receipts'); }); */ return View::make('backend.code.invoice.show', compact('invoices', 'title', 'housename', 'outstandingbal', 'propertyname', 'invoicedetails', 'total', 'balance', 'amountdue')); }
public static function getTotalIncomeFromTo($start, $end) { $totalIncome = Invoice::where('date', '>=', $start)->where('date', '<=', $end)->sum('total'); return $totalIncome; }