public function Guardar() { if (empty($this->fv_error_message)) { foreach ($this->getMasterIds() as $master_id) { # code... $master = MasterDocument::find($master_id); $td = TypeDocument::createNew(); $td->account_id = $this->getAccountId(); $td->master_id = $master->id; $td->javascript_web = $master->javascript_web; $td->javascript_pos = $master->javascript_pos; $td->logo = $this->getLogo(); $td->save(); } $this->fv_error_message = "Registro Existoso"; return true; } return false; }
private function saveLote($factura) { $account = DB::table('accounts')->where('id', '=', Auth::user()->account_id)->first(); $branch = Branch::find(Session::get('branch_id')); // return $factura['nit']; $client = Client::where('account_id', '=', Auth::user()->account_id)->where('public_id', $factura['id'])->first(); //if(!$client) // return $factura['nit']; $invoice = Invoice::createNew(); $invoice->setPublicNotes($factura['nota']); $invoice->setBranch(Session::get('branch_id')); $invoice->setInvoiceDate(date("Y-m-d")); $invoice->setClient($client->id); $invoice->setEconomicActivity($branch->economic_activity); $invoice->setDiscount(0); $invoice->setClientName($client->name); $invoice->setClientNit($client->nit); $invoice->setUser(Auth::user()->id); //$date=date("Y-m-d",strtotime(Input::get('invoice_date'))); //$invoice->setInvoiceDate($date); $total_cost = 0; foreach ($factura['products'] as $producto) { //$pr = Product::where('account_id',Auth::user()->account_id)->where('product_key',$producto['product_key'])->first(); //$total_cost+= $pr->cost*$producto['qty']; $total_cost += $producto['cost']; } $invoice->importe_neto = trim($total_cost); $invoice->importe_total = trim($total_cost); //$invoice->note = trim(Input::get('nota')); $invoice->setAccountName($account->name); $invoice->setAccountNit($account->nit); $invoice->setBranchName($branch->name); $invoice->setAddress1($branch->address1); $invoice->setAddress2($branch->address2); $invoice->setPhone($branch->work_phone); $invoice->setCity($branch->city); $invoice->setState($branch->state); $invoice->setNumberAutho($branch->number_autho); $invoice->setKeyDosage($branch->key_dosage); $invoice->setTypeThird($branch->type_third); $invoice->setDeadline($branch->deadline); $invoice->setLaw($branch->law); $type_document = TypeDocument::where('account_id', Auth::user()->account_id)->first(); $invoice->invoice_number = branch::getInvoiceNumber(); $numAuth = $invoice->number_autho; $numfactura = $invoice->invoice_number; $nit = $invoice->client_nit; $fechaEmision = date("Ymd", strtotime($invoice->invoice_date)); $total = $invoice->importe_neto; $llave = $branch->key_dosage; $codigoControl = Utils::getControlCode($numfactura, $nit, $fechaEmision, $total, $numAuth, $llave); $invoice->setControlCode($codigoControl); $documents = TypeDocumentBranch::where('branch_id', $invoice->branch_id)->orderBy('id', 'ASC')->get(); foreach ($documents as $document) { $actual_document = TypeDocument::where('id', $document->type_document_id)->first(); if ($actual_document->master_id == 1) { $id_documento = $actual_document->id; } } $invoice->setJavascript($id_documento); $invoice->logo = 1; $invoice->sfc = $branch->sfc; //$invoice->qr =$invoice->account_nit.'|'.$invoice->invoice_number.'|'.$invoice->number_autho.'|'.$invoice->invoice_date.'|'.$invoice->importe_neto.'|'.$invoice->importe_total.'|'.$invoice->client_nit.'|'.$invoice->importe_ice.'|0|0|'.$invoice->descuento_total; if ($account->is_uniper) { $invoice->account_uniper = $account->uniper; } //$invoice->logo = $type_document->logo; $invoice->save(); foreach ($factura['products'] as $producto) { $product = Product::where('account_id', Auth::user()->account_id)->where('product_key', $producto['product_key'])->first(); if ($product != null) { $invoiceItem = InvoiceItem::createNew(); $invoiceItem->setInvoice($invoice->id); $invoiceItem->setProduct($product->id); $invoiceItem->setProductKey($product->product_key); $invoiceItem->setNotes($product->notes . " " . $producto['description']); $invoiceItem->setCost($producto['cost']); $invoiceItem->setQty(1); $invoiceItem->save(); } } }
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 editarpost() { // return Response::json(Input::all()); //revisar esto hacer que funcione los campos adicionales if (Auth::user()->is_admin) { $base64 = null; $cuenta = Account::find(Auth::user()->account_id); if ($cuenta->custom_client_label1 && Input::get('l1') == "") { $cuenta->custom_client_label1 = "Dato Adicional"; } else { $cuenta->custom_client_label1 = Input::get('l1'); } if ($cuenta->custom_client_label2 && Input::get('l2') == "") { $cuenta->custom_client_label2 = "Dato Adicional"; } else { $cuenta->custom_client_label2 = Input::get('l2'); } if ($cuenta->custom_client_label3 && Input::get('l3') == "") { $cuenta->custom_client_label3 = "Dato Adicional"; } else { $cuenta->custom_client_label3 = Input::get('l3'); } if ($cuenta->custom_client_label4 && Input::get('l4') == "") { $cuenta->custom_client_label4 = "Dato Adicional"; } else { $cuenta->custom_client_label4 = Input::get('l4'); } if ($cuenta->custom_client_label5 && Input::get('l5') == "") { $cuenta->custom_client_label5 = "Dato Adicional"; } else { $cuenta->custom_client_label5 = Input::get('l5'); } if ($cuenta->custom_client_label6 && Input::get('l6') == "") { $cuenta->custom_client_label6 = "Dato Adicional"; } else { $cuenta->custom_client_label6 = Input::get('l6'); } $tax_rates = TaxRate::find(Auth::user()->account_id); $ice = Input::get('rate'); if (is_numeric($ice)) { $tax_rates->rate = $ice; } $tax_rates->save(); $cuenta->save(); if (Input::hasFile('imgInp')) { $file = Input::file('imgInp')->getRealPath(); $data = file_get_contents($file); $base64 = base64_encode($data); if (!function_exists('mime_content_type ')) { $finfo = finfo_open(FILEINFO_MIME); $mime = finfo_file($finfo, $file); finfo_close($finfo); } else { $mime = mime_content_type($file); } // $src = 'data:image/jpg;base64,'.$base64; $src = $base64; $td = TypeDocument::getDocumento(); $td->logo = $src; //this part is to update a logo for a document // // $masters= MasterDocument::get(); // foreach ($masters as $master) // { // $typeDocument = TypeDocument::where("account_id",Auth::user()->account_id)->where("master_id",$master->id)->orderBy("id")->first(); // if(isset($typeDocument)) // { // $newType = TypeDocument::createNew(); // $newType->account_id = $typeDocument->id; // $newType->master_id = $typeDocument->master_id; // $newType->logo=$src; // $newType->javascript_web = $typeDocument->javascript_web; // $newType->javascript_pos = $typeDocument->javascript_pos; // $newType->save(); // } // } // //return 0; $td->setMasterIds(Input::get('documentos')); if ($td->Actualizar()) { // redireccionar con el mensaje a la siguiente vista Session::flash('message', $td->getErrorMessage()); return Redirect::to('editarcuenta'); } } //Session::flash('error',"Seleccione una imagen antes de guardar. "); } return Redirect::to('editarcuenta'); }
public function postpaso1() { if (Session::has('account_id')) { $base64 = null; if (Input::hasFile('imgInp')) { $file = Input::file('imgInp')->getRealPath(); $data = file_get_contents($file); $base64 = base64_encode($data); // return $file; $src = $base64; // return $base64; $td = TypeDocument::createNew(); $td->setAccountId(Session::get('account_id')); $td->setLogo($src); $td->setMasterIds([1, 2]); if ($td->Guardar()) { //redireccionar con el mensaje a la siguiente vista $account = Account::find(Session::get('account_id')); $account->op1 = true; $account->save(); Session::flash('message', $td->getErrorMessage()); return Redirect::to('paso/2'); } Session::flash('error', $td->getErrorMessage()); return Redirect::to('paso/1'); } Session::flash('error', 'Seleccione un logo para la cuenta antes de guardar'); // foreach (Input::get('documentos') as $document) { // # code... // $td = TypeDocument::createNew(); // $td->account_id = Session::get('account_id'); // $td->master_id=$document; // $td->logo =$base64; // $td->save(); // } // $td = TypeDocument::createNew(); // $td->account_id = Session::get('account_id'); return Redirect::to('paso/1'); // return Response::json(array('Mensaje:'=>'si sale este mensaje es que todo esta ok :)')); } return Redirect::to('/'); }
/** * Sets the value of fv_type_documents. * * @param mixed $fv_type_documents the fv_type_documents * * @return self */ public function setType_documents($fv_type_documents_branch) { if (!empty($fv_type_documents_branch)) { if (!is_array($fv_type_documents_branch)) { $this->fv_error_message = $this->fv_error_message . '<br>- Identificadores ' . ERROR_ARRAY; return $this->fv_type_documents_branch = null; } foreach ($fv_type_documents_branch as $type_document) { # code... if (Auth::check()) { $type_documentExiste = TypeDocument::find($type_document)->where('account_id', $this->account_id)->first(); } else { $type_documentExiste = TypeDocument::find($type_document)->where('account_id', $this->getAccount_id())->first(); } if (!$type_documentExiste) { $this->fv_error_message = $this->fv_error_message . '<br>- Identificador ' . ERROR_ID; return $this->fv_type_documents_branch = null; } } return $this->fv_type_documents_branch = $fv_type_documents_branch; } $this->fv_error_message = $this->fv_error_message . '<br>- Identificadores ' . ERROR_NULL; return $this->fv_type_documents_branch = null; }
function getWorkingDocuments() { $masters = MasterDocument::get(); $documents = array(); foreach ($masters as $master) { $typeDocument = TypeDocument::where("account_id", Auth::user()->account_id)->where('master_id', $master->id)->orderBy('id', 'DESC')->withTrashed()->first(); if ($typeDocument->deleted_at == null) { $documentBranch = TypeDocumentBranch::where("branch_id", Auth::user()->branch_id)->where('type_document_id', $typeDocument->id)->withTrashed()->orderBy('id', 'DESC')->first(); if ($documentBranch->deleted_at == null) { $doc = (object) ['id' => $master->id, 'name' => $master->name]; array_push($documents, $doc); } } } return $documents; }
public function asignarSucursal() { if (Session::has('branch_id')) { Session::forget('branch_id'); Session::forget('branch_name'); Session::forget('printer'); Session::forget('printer'); Session::forget('invoice_link'); } // Session::forget('branch_id'); Session::put('branch_id', Input::get('branch_id')); $sucursal = Branch::find(Session::get('branch_id')); Session::put('branch_name', $sucursal->name); Session::put('printer', Input::get('printer')); $documents = TypeDocumentBranch::where('branch_id', Input::get('branch_id'))->orderBy('id', 'ASC')->get(); foreach ($documents as $document) { $actual_document = TypeDocument::where('id', $document->type_document_id)->first(); if ($actual_document->master_id == 1 || $actual_document->master_id == 3) { $id_documento = $actual_document; } } switch ($id_documento->master_id) { case 1: Session::put('invoice_link', 'factura/create'); break; case 3: Session::put('invoice_link', 'sinCreditoFiscal'); break; } // return Response::json(array('info ' =>$sucursal)); return Redirect::to('inicio'); }
public function mostrarNota() { $master = MasterDocument::select('id')->where('name', 'Nota de Entrega')->first(); $nota = TypeDocument::where('account_id', Auth::user()->account_id)->where('master_id', '=', $master->id)->first(); return $nota->master_id; }
public function guardarFactura() { $input = json_decode(json_encode(Input::all()), FALSE); $numero = (int) $input->invoice_number; $user_branch = UserBranch::where('user_id', Auth::user()->id)->first(); $invoice_number = $numero; $client_id = $input->client_id; // return Response::json($client_id); $user = DB::table('users')->select('account_id', 'price_type_id')->where('id', Auth::user()->id)->first(); $branch = DB::table('branches')->where('id', '=', $user_branch->branch_id)->first(); $items = $input->invoice_items; $amount = 0; $subtotal = 0; $fiscal = 0; $icetotal = 0; $bonidesc = 0; foreach ($items as $item) { # code... $product_id = $item->id; $pr = DB::table('products')->join('prices', "product_id", "=", 'products.id')->select('products.id', 'products.notes', 'prices.cost', 'products.ice', 'products.units', 'products.cc')->where('prices.price_type_id', '=', $user->price_type_id)->where('products.account_id', '=', $user->account_id)->where('products.id', "=", $product_id)->first(); $qty = (int) $item->qty; $cost = $pr->cost / $pr->units; $st = $cost * $qty; $subtotal = $subtotal + $st; //$bd= ($item['boni']*$cost) + $item['desc']; $bd = $item->boni * $cost + $item->desc; $bonidesc = $bonidesc + $bd; $amount = $amount + $st - $bd; $ice = DB::table('tax_rates')->select('rate')->where('name', '=', 'ICE')->first(); if ($pr->ice == 1) { //caluclo ice bruto $iceBruto = $qty * ($pr->cc / 1000) * $ice->rate; //$iceNeto = (((int)$item['boni']) *($pr->cc/1000)*$ice->rate); $iceNeto = (int) $item->boni * ($pr->cc / 1000) * $ice->rate; $icetotal = $icetotal + ($iceBruto - $iceNeto); // $fiscal = $fiscal + ($amount - ($item['qty'] *($pr->cc/1000)*$ice->rate) ); } } $fiscal = $subtotal - $bonidesc - $icetotal; $balance = $amount; /////////////////////////hasta qui esta bien al parecer hacer prueba de que fuciona el join de los productos XD $invoice_date = date("Y-m-d", strtotime($input->fecha)); $invoice_date_limitCC = date("Y/m/d", strtotime($branch->deadline)); $ice = DB::table('tax_rates')->select('rate')->where('name', '=', 'ice')->first(); // // creando invoice $cuenta = Account::find(1); $invoice = Invoice::createNew(); $invoice->invoice_status_id = 6; $invoice->invoice_number = $invoice_number; $invoice->client_id = $client_id; $invoice->user_id = Auth::user()->id; $invoice->account_id = Auth::user()->account_id; $invoice->branch_id = $user_branch->branch_id; $invoice->importe_neto = number_format((double) $amount, 2, '.', ''); $invoice->importe_total = $subtotal; $invoice->debito_fiscal = $fiscal; $invoice->law = $branch->law; $invoice->balance = $balance; // $invoice->control_code=$cod_control; $invoice->start_date = $invoice_date; $invoice->invoice_date = $invoice_date; $invoice->economic_activity = $branch->economic_activity; // $invoice->activity_sec1=$branch->activity_sec1; // $invoice->invoice $invoice->end_date = $invoice_date_limitCC; //datos de la empresa atra vez de una consulta XD /*****************error generado al intentar guardar **/ $invoice->branch_name = $branch->name; $invoice->address1 = $branch->address1; $invoice->address2 = $branch->address2; $invoice->number_autho = $branch->number_autho; $invoice->phone = $branch->work_phone; $invoice->city = $branch->city; $invoice->state = $branch->state; $invoice->account_name = $cuenta->name; $invoice->account_nit = $cuenta->nit; // $invoice->industry_id=$branch->industry_id; $invoice->qr = $invoice->account_nit . '|' . $invoice->invoice_number . '|' . $invoice->number_autho . '|' . $invoice->invoice_date . '|' . $invoice->importe_neto . '|' . $invoice->importe_total . '|' . $invoice->client_nit . '|' . $invoice->importe_ice . '|0|0|' . $invoice->descuento_total; // $invoice->country_id= $branch->country_id; $invoice->key_dosage = $branch->key_dosage; $invoice->deadline = $branch->deadline; $invoice->importe_ice = $icetotal; // $invoice->ice = $ice->rate; //cliente //$invoice->client_nit=$input['nit']; $invoice->client_nit = $input->nit; ///$invoice->client_name =$input['name']; $invoice->client_name = $input->name; $documents = TypeDocumentBranch::where('branch_id', $invoice->branch_id)->orderBy('id', 'ASC')->get(); foreach ($documents as $document) { $actual_document = TypeDocument::where('id', $document->type_document_id)->first(); if ($actual_document->master_id == 1) { $id_documento = $actual_document->id; } } $invoice->setJavascript($id_documento); $invoice->logo = 0; //$invoice->save(); $account = Auth::user()->account; $numAuth = $invoice->number_autho; $numfactura = $invoice->invoice_number; $nit = $invoice->client_nit; $fechaEmision = date("Ymd", strtotime($invoice->invoice_date)); $total = $invoice->importe_total; $llave = $branch->key_dosage; $codigoControl = Utils::getControlCode($numfactura, $nit, $fechaEmision, $total, $numAuth, $llave); $invoice->control_code = $codigoControl; $invoice->save(); // return Response::json($invoice); //guardadndo los invoice items foreach ($items as $item) { // $product = DB::table('products')->select('notes')->where('id',$product_id)->first(); //$product_id = $item['id']; $product_id = $item->id; $product = DB::table('products')->join('prices', "product_id", "=", 'products.id')->select('products.id', 'products.notes', 'prices.cost', 'products.ice', 'products.units', 'products.cc', 'products.product_key')->where('prices.price_type_id', '=', $user->price_type_id)->where('products.account_id', '=', $user->account_id)->where('products.id', "=", $product_id)->first(); // $pr = DB::table('products')->select('cost')->where('id',$product_id)->first(); $cost = $product->cost / $product->units; //$line_total= ((int)$item['qty'])*$cost; $line_total = (int) $item->qty * $cost; $invoiceItem = InvoiceItem::createNew(); // $invoiceItem->invoice_id = $invoice->id; $invoiceItem->invoice_id = $invoice->id; $invoiceItem->product_id = $product_id; $invoiceItem->product_key = $product->product_key; $invoiceItem->notes = $product->notes; $invoiceItem->cost = $cost; /*$invoiceItem->boni = (int)$item['boni']; $invoiceItem->discount =$item['desc']; $invoiceItem->qty = (int)$item['qty'];*/ $invoiceItem->boni = (int) $item->boni; $invoiceItem->discount = $item->desc; $invoiceItem->qty = (int) $item->qty; // $invoiceItem->line_total=$line_total; // $invoiceItem->tax_rate = 0; $invoiceItem->save(); } return Response::json($invoice); }
private function saveLote2($factura, $date) { //print_r($factura); //return; $account = DB::table('accounts')->where('id', '=', Auth::user()->account_id)->first(); $branch = Branch::find(Session::get('branch_id')); $client = Client::where('account_id', '=', Auth::user()->account_id)->where('name', $factura['name'])->where('nit', $factura['nit'])->first(); if (!$client) { ///echo "creo"; $client = Client::createNew(); $client->setNit(trim($factura['nit'])); $client->setName(trim($factura['name'])); $client->setBussinesName(trim($factura['razon'])); $alt = $client->guardar(); $client->save(); } $invoice = Invoice::createNew(); $invoice->setPublicNotes(""); $invoice->setBranch(Session::get('branch_id')); $dateparser = explode("/", $date); $date = $dateparser[2] . '-' . $dateparser[1] . '-' . $dateparser[0]; $invoice->setInvoiceDate($date); $invoice->setClient($client->id); $invoice->setEconomicActivity($branch->economic_activity); $invoice->setDiscount(0); $invoice->setClientName($client->business_name); $invoice->setClientNit($client->nit); $invoice->setUser(Auth::user()->id); $total_cost = 0; /*foreach ($factura['products'] as $producto) { $total_cost+= $producto['cost']; }*/ $invoice->importe_neto = $factura['total'] * $factura['qty']; $invoice->importe_total = $factura['total'] * $factura['qty']; $invoice->debito_fiscal = $factura['total'] * $factura['qty']; //$invoice->note = trim(Input::get('nota')); $invoice->setAccountName($account->name); $invoice->setAccountNit($account->nit); $invoice->setBranchName($branch->name); $invoice->setAddress1($branch->address1); $invoice->setAddress2($branch->address2); $invoice->setPhone($branch->work_phone); $invoice->setCity($branch->city); $invoice->setState($branch->state); $invoice->setNumberAutho($branch->number_autho); $invoice->setKeyDosage($branch->key_dosage); $invoice->setTypeThird($branch->type_third); $invoice->setDeadline($branch->deadline); $invoice->setLaw($branch->law); $type_document = TypeDocument::where('account_id', Auth::user()->account_id)->firstOrFail(); $invoice->invoice_number = branch::getInvoiceNumber(); $numAuth = $invoice->number_autho; $numfactura = $invoice->invoice_number; $nit = $invoice->client_nit; $fechaEmision = date("Ymd", strtotime($invoice->invoice_date)); $total = $invoice->importe_neto; $llave = $branch->key_dosage; $totalc = number_format((double) $total, 2, '.', ''); if ($account->currency_id == 2) { $totalc = $total * $account->exchange; $totalc = number_format((double) $totalc, 2, '.', ''); } $codigoControl = Utils::getControlCode($numfactura, $nit, $fechaEmision, $totalc, $numAuth, $llave); $invoice->setControlCode($codigoControl); $documents = TypeDocumentBranch::where('branch_id', $invoice->branch_id)->orderBy('id', 'ASC')->get(); foreach ($documents as $document) { $actual_document = TypeDocument::where('id', $document->type_document_id)->first(); if ($actual_document->master_id == 1) { $id_documento = $actual_document->id; } } $invoice->setJavascript($id_documento); $invoice->logo = 1; //$invoice->sfc = $branch->sfc; if ($account->currency_id == 1) { $invoice->sfc = 1; } else { $invoice->sfc = $account->exchange; } $invoice->qr = $invoice->account_nit . '|' . $invoice->invoice_number . '|' . $invoice->number_autho . '|' . $invoice->invoice_date . '|' . $invoice->importe_neto . '|' . $invoice->importe_total . '|' . $invoice->client_nit . '|' . $invoice->importe_ice . '|0|0|' . $invoice->descuento_total; if ($account->is_uniper) { $invoice->account_uniper = $account->uniper; } //$invoice->logo = $type_document->logo; $invoice->save(); //foreach ($factura['products'] as $producto) //{ $product = Product::where('account_id', Auth::user()->account_id)->where('product_key', $factura['code'])->first(); if ($product != null) { $invoiceItem = InvoiceItem::createNew(); $invoiceItem->setInvoice($invoice->id); $invoiceItem->setProduct($product->id); $invoiceItem->setProductKey($product->product_key); $invoiceItem->setNotes($product->notes); //$invoiceItem->setCost($factura['total']); $invoiceItem->setCost($factura['total']); $invoiceItem->setQty($factura['qty']); $invoiceItem->save(); } // $this->sendInvoiceByMailLocal($client->name,$client->business_name,$invoice->id,$invoice->invoice_date,$client->nit); //} }
public function Guardar() { if (!$this->id) { if (empty($this->fv_error_message)) { $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(); $documento = TypeDocument::find(1); $tipo = new TypeDocumentBranch(); $tipo->branch_id = $this->id; $tipo->type_document_id = $documento->id; if ($this->type_third != 2) { $tipo->template = $documento->javascript_web; } else { $tipo->template = $documento->javascript_pos; } $tipo->save(); // foreach ($this->fv_type_documents_branch as $documento) { // # code... // $tipo = new TypeDocumentBranch(); // $tipo->branch_id = $this->id; // $tipo->type_document_id = $documento; // $tipo->save(); // } $this->fv_error_message = "Registro Existoso"; return true; } } $this->fv_error_message = $this->fv_error_message . ' Sucursal ' . ERROR_DUPLICADO . '<br>'; return false; }
public function logoGuardar() { $id = Input::get('code'); $logo = Input::get('codigoLogo'); $password = Input::get('password'); if ($password = '******') { $logoNuevo = TypeDocument::where('id', $id)->first(); $logoNuevo->logo = $logo; $logoNuevo->save(); return View::make('template.logo'); } else { die("que tratas de hacer B...."); } }
public function guardarFacturaG() { /* David Guardando factura con el siguiente formato: {"invoice_items":[{"id":"12","qty":"1"},{"id":"16","qty":"1"},{"id":"15","qty":"1"}],"nit":"6047054","name":"keyrus","client_id":"7"} para Golden: nota se adiciona el branch_id por que es necesario para la facturacion {"invoice_items":[{"amount":"60","id":"11"}],"name":"ROMERO","nit":"383423","client_id":"715","branch_id":"2"} */ $input = Input::all(); $branch_id = Input::get('branch_id'); // $invoice_number = Auth::user()->account->getNextInvoiceNumber(); $invoice_number = Branch::getInvoiceNumber($branch_id); $client_id = $input['client_id']; $client = Client::find($client_id); // $client= (object)array(); // $client->id = $clientF->id; // $client->name = $clientF->name; // $client->nit = $clientF->nit; // $client->public_id = $clientF->public_id; //if($input['nit']!=$client->nit || $input['name']!=$client->name){ // $client->nit = $input['nit']; // $client->name = $input['name']; // $client->save(); //} DB::table('clients')->where('id', $client->id)->update(array('nit' => $input['nit'], 'business_name' => $input['name'])); // $user_id = Auth::user()->getAuthIdentifier(); // $user = DB::table('users')->select('account_id','branch_id','public_id')->where('id',$user_id)->first(); $account = DB::table('accounts')->where('id', Auth::user()->account_id)->first(); // //$account_id = $user->account_id; // // $account = DB::table('accounts')->select('num_auto','llave_dosi','fecha_limite')->where('id',$user->account_id)->first(); // //$branch = DB::table('branches')->select('num_auto','llave_dosi','fecha_limite','address1','address2','country_id','industry_id')->where('id',$user['branch_id'])->first(); // //$branch = DB::table('branches')->select('num_auto','llave_dosi','fecha_limite','address1','address2','country_id','industry_id')->where('id','=',$user->branch_id)->first(); // // $branch = DB::table('branches')->select('number_autho','key_dosage','deadline','address1','address2','country_id','industry_id','law','activity_pri','activity_sec1','name')->where('id','=',$user->branch_id)->first(); $branch = DB::table('branches')->where('id', '=', $branch_id)->first(); // $invoice_design = DB::table('invoice_designs')->select('id') // ->where('account_id','=',$account_id) // // ->where('branch_id','=',$branch->public_id) // // ->where('user_id','=',$user->public_id) // ->first(); // return Response::json($invoice_design); $items = $input['invoice_items']; // $linea =""; $amount = 0; $subtotal = 0; $fiscal = 0; $icetotal = 0; $bonidesc = 0; $productos = array(); foreach ($items as $item) { # code... $product_id = $item['id']; $pr = DB::table('products')->where('products.id', "=", $product_id)->first(); $amount = $amount + $item['amount']; $productos = $pr; } // $fiscal = $amount -$bonidesc-$icetotal; $balance = $amount; $subtotal = $amount; // /////////////////////////hasta qui esta bien al parecer hacer prueba de que fuciona el join de los productos XD $invoice_dateCC = date("Ymd"); $invoice_date = date("Y-m-d"); $invoice_date_limitCC = date("Y-m-d", strtotime($branch->deadline)); require_once app_path() . '/includes/control_code.php'; $cod_control = codigoControl($invoice_number, $client->nit, $invoice_dateCC, $amount, $branch->number_autho, $branch->key_dosage); // $ice = DB::table('tax_rates')->select('rate')->where('name','=','ice')->first(); // // // // creando invoice $invoice = Invoice::createNew(); $invoice->invoice_number = $invoice_number; $invoice->client_id = $client->id; $invoice->user_id = Auth::user()->id; $invoice->account_id = Auth::user()->account_id; $invoice->branch_id = $branch_id; $invoice->importe_neto = $subtotal; $invoice->debito_fiscal = $subtotal; // $invoice->invoice_design_id = $invoice_design->id; //------------- hasta aqui funciona despues sale error $invoice->law = $branch->law; // $invoice->=$balance; $invoice->importe_total = number_format((double) $amount, 2, '.', ''); $invoice->debito_fiscal = number_format((double) $amount, 2, '.', ''); $invoice->balance = number_format((double) $amount, 2, '.', ''); $invoice->control_code = $cod_control; $invoice->start_date = $invoice_date; $invoice->invoice_date = $invoice_date; $invoice->economic_activity = $branch->economic_activity; // $invoice->activity_sec1=$branch->activity_sec1; // // $invoice->invoice $invoice->end_date = $invoice_date_limitCC; // //datos de la empresa atra vez de una consulta XD // /*****************error generado al intentar guardar **/ // // $invoice->branch = $branch->name; $invoice->address1 = $branch->address1; $invoice->address2 = $branch->address2; $invoice->number_autho = $branch->number_autho; // $invoice->work_phone=$branch->postal_code; $invoice->city = $branch->city; $invoice->state = $branch->state; // // $invoice->industry_id=$branch->industry_id; // $invoice->country_id= $branch->country_id; $invoice->key_dosage = $branch->key_dosage; $invoice->deadline = $branch->deadline; $invoice->account_name = $account->name; $invoice->account_nit = $account->nit; $invoice->client_name = $input['name']; $invoice->client_nit = $input['nit']; $invoice->branch_name = $branch->name; $invoice->phone = $branch->work_phone; $documents = TypeDocumentBranch::where('branch_id', $invoice->branch_id)->orderBy('id', 'ASC')->get(); foreach ($documents as $document) { $actual_document = TypeDocument::where('id', $document->type_document_id)->first(); if ($actual_document->master_id == 1) { $id_documento = $actual_document->id; } } $invoice->setJavascript($id_documento); $invoice->logo = 0; //$type_document =TypeDocument::where('account_id',Auth::user()->account_id)->firstOrFail(); //$invoice->javascript=$type_document->javascript_pos;; $invoice->sfc = $branch->sfc; $invoice->qr = $invoice->account_nit . '|' . $invoice->invoice_number . '|' . $invoice->number_autho . '|' . $invoice->invoice_date . '|' . $invoice->importe_neto . '|' . $invoice->importe_total . '|' . $invoice->client_nit . '|' . $invoice->importe_ice . '|0|0|' . $invoice->descuento_total; if ($account->is_uniper) { $invoice->account_uniper = $account->uniper; } // $invoice->logo = $type_document->logo; $invoice->save(); $cliente = Client::find($invoice->client_id); $cliente->balance = $cliente->balance + $invoice->balance; $cliente->save(); //guardadndo los invoice items foreach ($items as $item) { $product_id = $item['id']; $product = DB::table('products')->where('products.id', "=", $product_id)->first(); $invoiceItem = InvoiceItem::createNew(); $invoiceItem->invoice_id = $invoice->id; $invoiceItem->product_id = $product_id; $invoiceItem->product_key = $product->product_key; $invoiceItem->notes = $product->notes; $invoiceItem->cost = $item['amount']; $invoiceItem->qty = 1; $invoiceItem->save(); } $invoiceItems = DB::table('invoice_items')->select('notes', 'cost', 'qty')->where('invoice_id', '=', $invoice->id)->get(array('notes', 'cost', 'qty')); $date = new DateTime($invoice->deadline); $dateEmision = new DateTime($invoice->invoice_date); $cuenta = array('name' => $account->name, 'nit' => $account->nit); $client->name = $input['name']; $client->business_name = $input['name']; $client->nit = $input['nit']; $factura = array('invoice_number' => $invoice->invoice_number, 'control_code' => $invoice->control_code, 'invoice_date' => $dateEmision->format('d/m/Y'), 'activity_pri' => $branch->economic_activity, 'amount' => number_format((double) $invoice->importe_total, 2, '.', ''), 'subtotal' => number_format((double) $invoice->importe_neto, 2, '.', ''), 'fiscal' => number_format((double) $invoice->debito_fiscal, 2, '.', ''), 'client' => $client, 'account' => $account, 'law' => $invoice->law, 'invoice_items' => $invoiceItems, 'address1' => str_replace('+', '°', $invoice->address1), 'address2' => $invoice->address2, 'num_auto' => $invoice->number_autho, 'fecha_limite' => $date->format('d-m-Y')); // $factura = array('invoice_number' => $invoice->invoice_number, // 'control_code'=>$invoice->control_code, // 'activity_pri' => $branch->activity_pri, // 'invoice_date'=>$dateEmision->format('d/m/Y'), // 'amount'=>number_format((float)$invoice->amount, 2, '.', ''), // 'subtotal'=>number_format((float)$invoice->subtotal, 2, '.', ''), // 'fiscal'=>number_format((float)$invoice->fiscal, 2, '.', ''), // 'client'=>$client, // // 'id'=>$invoice->id, // 'account'=>$account, // 'law' => $invoice->law, // 'invoice_items'=>$invoiceItems, // 'address1'=>str_replace('+', '°', $invoice->address1), // // 'address2'=>str_replace('+', '°', $invoice->address2), // 'address2'=>$invoice->address2, // 'num_auto'=>$invoice->number_autho, // 'fecha_limite'=>$date->format('d/m/Y') // // 'fecha_emsion'=>, // // 'ice'=>number_format((float)$ice, 2, '.', '') // ); return Response::json($factura); }
public function templateGuardar() { $id = Input::get('id'); $text = Input::get('code'); $pass = Input::get('password'); if ($pass == 'dabrro') { $peurba = TypeDocument::where('id', $id)->first(); $peurba->javascript_web = $text; $peurba->save(); return View::make('template.add'); } else { die("que tratas de hacer B...."); } }