public function index() { $publicId = 1; $invoice = Invoice::scope($publicId)->with('account.country', 'client.contacts', 'client.country', 'invoice_items')->firstOrFail(); Utils::trackViewed($invoice->invoice_number . ' - ' . $invoice->client->getDisplayName(), ENTITY_INVOICE); //$productos = InvoiceItem::scope(1)->get(); $invoice->invoice_date = Utils::fromSqlDate($invoice->invoice_date); $invoice->due_date = Utils::fromSqlDate($invoice->due_date); $invoice->start_date = Utils::fromSqlDate($invoice->start_date); $invoice->end_date = Utils::fromSqlDate($invoice->end_date); $invoice->is_pro = Auth::user()->isPro(); //print_r($invoice->invoice_items); //return Response::json($invoice); $contactIds = DB::table('invitations')->join('contacts', 'contacts.id', '=', 'invitations.contact_id')->where('invitations.invoice_id', '=', $invoice->id)->where('invitations.account_id', '=', Auth::user()->account_id)->where('invitations.deleted_at', '=', null)->select('contacts.public_id')->lists('public_id'); $data = array('showBreadcrumbs' => false, 'account' => $invoice->account, 'invoice' => $invoice, 'data' => false, 'method' => 'PUT', 'invitationContactIds' => $contactIds, 'url' => 'invoices/' . $publicId, 'title' => '- ' . $invoice->invoice_number, 'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->where('id', $invoice->client->id)->get(), 'client' => $invoice->client); $data = array_merge($data, self::getViewModel()); // Set the invitation link on the client's contacts $clients = $data['clients']; foreach ($clients as $client) { if ($client->id == $invoice->client->id) { foreach ($invoice->invitations as $invitation) { foreach ($client->contacts as $contact) { if ($invitation->contact_id == $contact->id) { $contact->invitation_link = $invitation->getLink(); } } } break; } } // print_r($data['invoice']); // echo "<br><br><br><br><br>"; //return View::make('invoices.edit', $data); return View::make('factura', $data); }
public function edit($publicId) { $credit = Credit::scope($publicId)->firstOrFail(); $credit->credit_date = Utils::fromSqlDate($credit->credit_date); $data = array('client' => null, 'credit' => $credit, 'method' => 'PUT', 'url' => 'credits/' . $publicId, 'title' => 'Edit Credit', 'clients' => Client::scope()->with('contacts')->orderBy('name')->get()); return View::make('credit.edit', $data); }
public function edit($publicId) { $payment = Payment::scope($publicId)->firstOrFail(); $payment->payment_date = Utils::fromSqlDate($payment->payment_date); $data = array('client' => null, 'invoice' => null, 'invoices' => Invoice::scope()->where('is_recurring', '=', false)->where('is_quote', '=', false)->with('client', 'invoice_status')->orderBy('invoice_number')->get(), 'payment' => $payment, 'method' => 'PUT', 'url' => 'payments/' . $publicId, 'title' => 'Edit Payment', 'paymentTypes' => PaymentType::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'clients' => Client::scope()->with('contacts')->orderBy('name')->get()); return View::make('payments.edit', $data); }
public function index() { if (!Utils::isPro()) { return Redirect::to('/'); } $clients = Client::scope()->with('contacts')->orderBy('created_at', 'desc')->get(); $clients = Utils::remapPublicIds($clients->toArray()); $response = json_encode($clients, JSON_PRETTY_PRINT); $headers = Utils::getApiHeaders(count($clients)); return Response::make($response, 200, $headers); }
public function saveClient($publicId, $data, $notify = true) { if (!$publicId || $publicId == "-1") { $client = Client::createNew(); $client->currency_id = 1; $contact = Contact::createNew(); $contact->is_primary = true; $contact->send_invoice = true; } else { $client = Client::scope($publicId)->with('contacts')->first(); $contact = $client->contacts()->where('is_primary', '=', true)->first(); } if (isset($data['nit'])) { $client->nit = trim($data['nit']); } if (isset($data['name'])) { $client->name = trim($data['name']); } if (isset($data['business_name'])) { $client->business_name = trim($data['business_name']); } if (isset($data['work_phone'])) { $client->work_phone = trim($data['work_phone']); } if (isset($data['custom_value1'])) { $client->custom_value1 = trim($data['custom_value1']); } if (isset($data['custom_value2'])) { $client->custom_value2 = trim($data['custom_value2']); } if (isset($data['address1'])) { $client->address1 = trim($data['address1']); } if (isset($data['address2'])) { $client->address2 = trim($data['address2']); } if (isset($data['city'])) { $client->city = trim($data['city']); } if (isset($data['state'])) { $client->state = trim($data['state']); } if (isset($data['private_notes'])) { $client->private_notes = trim($data['private_notes']); } $client->save(); $isPrimary = true; $contactIds = []; if (isset($data['contact'])) { $info = $data['contact']; if (isset($info['email'])) { $contact->email = trim(strtolower($info['email'])); } if (isset($info['first_name'])) { $contact->first_name = trim($info['first_name']); } if (isset($info['last_name'])) { $contact->last_name = trim($info['last_name']); } if (isset($info['phone'])) { $contact->phone = trim($info['phone']); } $contact->is_primary = true; $contact->send_invoice = true; $client->contacts()->save($contact); } else { foreach ($data['contacts'] as $record) { $record = (array) $record; if ($publicId != "-1" && isset($record['public_id']) && $record['public_id']) { $contact = Contact::scope($record['public_id'])->first(); } else { $contact = Contact::createNew(); } if (isset($record['email'])) { $contact->email = trim(strtolower($record['email'])); } if (isset($record['first_name'])) { $contact->first_name = trim($record['first_name']); } if (isset($record['last_name'])) { $contact->last_name = trim($record['last_name']); } if (isset($record['phone'])) { $contact->phone = trim($record['phone']); } $contact->is_primary = $isPrimary; $contact->send_invoice = isset($record['send_invoice']) ? $record['send_invoice'] : true; $isPrimary = false; $client->contacts()->save($contact); $contactIds[] = $contact->public_id; } foreach ($client->contacts as $contact) { if (!in_array($contact->public_id, $contactIds)) { $contact->delete(); } } } $client->save(); if (!$publicId || $publicId == "-1") { \Activity::createClient($client, $notify); } return $client; }
public function guardarFactura() { /* David Guardando factura con el siguiente formato: {"invoice_items":[{"qty":"2","id":"2"}],"client_id":"1"} //nuevo formato para la cascada XD {"invoice_items":[{"qty":"2","id":"2","boni":"1","desc":"3"}],"client_id":"1"} //para version generica {"invoice_items":[{"qty":"6","id":"11"}],"name":"Sin Nombre","nit":"0","client_id":"19"} */ $input = Input::all(); // $invoice_number = Auth::user()->account->getNextInvoiceNumber(); $invoice_number = Auth::user()->branch->getNextInvoiceNumber(); $client_id = $input['client_id']; $clientF = Client::scope($client_id)->firstOrFail(); $client = (object) array(); $client->id = $clientF->id; $client->name = $clientF->name; $client->nit = $clientF->nit; $client->public_id = $clientF->public_id; DB::table('clients')->where('id', $client->id)->update(array('nit' => $input['nit'], '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', $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', '=', $user->branch_id)->first(); $invoice_design = DB::table('invoice_designs')->select('id')->where('account_id', '=', $user->account_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(); // $pr->xd ='hola'; //me quede aqui me llego sueñito XD $amount = $amount + $pr->cost * $item['qty']; // $pr->qty = 1; $productos = $pr; // $pr = DB::table('products')->select('cost')->where('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']; // $bonidesc= $bonidesc +$bd; // $amount = $amount +$st-$bd; // // $fiscal = $fiscal +$amount; } // $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 = $user_id; $invoice->account_id = $user->account_id; $invoice->branch_id = $user->branch_id; $invoice->amount = number_format((double) $amount, 2, '.', ''); $invoice->invoice_design_id = $invoice_design->id; //------------- hasta aqui funciona despues sale error $invoice->law = $branch->law; $invoice->balance = $balance; $invoice->subtotal = $subtotal; $invoice->control_code = $cod_control; $invoice->start_date = $invoice_date; $invoice->invoice_date = $invoice_date; $invoice->activity_pri = $branch->activity_pri; $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->custom_value1 =$icetotal; // $invoice->ice = $ice->rate; // //cliente // $invoice->nit=$client->nit; // $invoice->name =$client->name; //adicionales de la nueva plataforma $invoice->account_name = $account->name; $invoice->account_nit = $account->nit; $invoice->client_name = $input['name']; $invoice->client_nit = $input['nit']; $invoice->phone = $branch->postal_code; $invoice->save(); // $account = Auth::user()->account; // $ice = $invoice->amount-$invoice->fiscal; // $desc = $invoice->subtotal-$invoice->amount; // $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; // } require_once app_path() . '/includes/BarcodeQR.php'; $icef = 0; $descf = 0; $qr = new BarcodeQR(); $datosqr = $invoice->account_nit . '|' . $invoice->invoice_number . '|' . $invoice->number_autho . '|' . $invoice_date . '|' . $invoice->amount . '|' . $invoice->amount . '|' . $invoice->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(); DB::table('invoices')->where('id', $invoice->id)->update(array('branch_name' => $branch->name)); //error verificar // $invoice = DB::table('invoices')->select('id')->where('invoice_number',$invoice_number)->first(); //guardadndo los invoice items foreach ($items as $item) { // $product = DB::table('products')->select('notes')->where('id',$product_id)->first(); $product_id = $item['id']; $product = DB::table('products')->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; $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 = $product->cost; $invoiceItem->qty = $item['qty']; // $invoiceItem->line_total=$line_total; $invoiceItem->tax_rate = 0; $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); // $ice = $invoice->amount-$invoice->fiscal; // $factura = array('invoice_number' => $invoice->invoice_number, // 'control_code'=>$invoice->control_code, // '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, '.', '') // ); $client->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->activity_pri, 'amount' => number_format((double) $invoice->amount, 2, '.', ''), 'subtotal' => number_format((double) $invoice->balance, 2, '.', ''), 'fiscal' => number_format((double) $invoice->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')); // $invoic = Invoice::scope($invoice_number)->withTrashed()->with('client.contacts', 'client.country', 'invoice_items')->firstOrFail(); // $d = Input::all(); //en caso de problemas irracionales me refiero a que se jodio // $input = Input::all(); // $client_id = $input['client_id']; // $client = DB::table('clients')->select('id','nit','name')->where('id',$input['client_id'])->first(); return Response::json($factura); }
private function mapFile() { $file = Input::file('file'); if ($file == null) { Session::flash('error', trans('texts.select_file')); return Redirect::to('company/import_export'); } $name = $file->getRealPath(); require_once app_path() . '/includes/parsecsv.lib.php'; $csv = new parseCSV(); $csv->heading = false; $csv->auto($name); if (count($csv->data) + Client::scope()->count() > Auth::user()->getMaxNumClients()) { $message = trans('texts.limit_clients', ['count' => Auth::user()->getMaxNumClients()]); Session::flash('error', $message); return Redirect::to('company/import_export'); } Session::put('data', $csv->data); $headers = false; $hasHeaders = false; $mapped = array(); $columns = array('', Client::$fieldVat_number, Client::$fieldName, Client::$fieldNit, Client::$fieldPhone, Client::$fieldAddress1, Client::$fieldAddress2, Client::$fieldNotes, Contact::$fieldFirstName, Contact::$fieldLastName, Contact::$fieldPhone, Contact::$fieldEmail); if (count($csv->data) > 0) { $headers = $csv->data[0]; foreach ($headers as $title) { if (strpos(strtolower($title), 'name') > 0) { $hasHeaders = true; break; } } for ($i = 0; $i < count($headers); $i++) { $title = strtolower($headers[$i]); $mapped[$i] = ''; if ($hasHeaders) { $map = array('Nombre' => Client::$fieldVat_number, 'Razón Social' => Client::$fieldName, 'Nit' => Client::$fieldNit, 'Teléfono' => Client::$fieldPhone, 'Zona/Barrio' => Client::$fieldAddress1, 'Dirección' => Client::$fieldAddress2, 'Antecedentes' => Client::$fieldNotes, 'Nombre(s)' => Contact::$fieldFirstName, 'Apellidos' => Contact::$fieldLastName, 'Correo' => Contact::$fieldEmail, 'Celular' => Contact::$fieldPhone); foreach ($map as $search => $column) { foreach (explode("|", $search) as $string) { if (strpos($title, 'sec') === 0) { continue; } if (strpos($title, $string) !== false) { $mapped[$i] = $column; break 2; } } } } } } $data = array('data' => $csv->data, 'headers' => $headers, 'hasHeaders' => $hasHeaders, 'columns' => $columns, 'mapped' => $mapped); return View::make('accounts.import_map', $data); }
private static function getViewModel() { return ['entityType' => ENTITY_QUOTE, 'account' => Auth::user()->account, 'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')), 'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'invoiceDesigns' => InvoiceDesign::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'invoiceLabels' => Auth::user()->account->getInvoiceLabels()]; }
private function save($publicId = null) { $rules = array('email' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { $url = $publicId ? 'clients/' . $publicId . '/edit' : 'clients/create'; return Redirect::to($url)->withErrors($validator)->withInput(Input::except('password')); } else { if ($publicId) { $client = Client::scope($publicId)->firstOrFail(); } else { $client = Client::createNew(); } $client->name = trim(Input::get('name')); $client->id_number = trim(Input::get('id_number')); $client->vat_number = trim(Input::get('vat_number')); $client->work_phone = trim(Input::get('work_phone')); $client->custom_value1 = trim(Input::get('custom_value1')); $client->custom_value2 = trim(Input::get('custom_value2')); $client->address1 = trim(Input::get('address1')); $client->address2 = trim(Input::get('address2')); $client->city = trim(Input::get('city')); $client->state = trim(Input::get('state')); $client->postal_code = trim(Input::get('postal_code')); $client->country_id = Input::get('country_id') ?: null; $client->private_notes = trim(Input::get('private_notes')); $client->size_id = Input::get('size_id') ?: null; $client->industry_id = Input::get('industry_id') ?: null; $client->currency_id = Input::get('currency_id') ?: null; $client->payment_terms = Input::get('payment_terms') ?: 0; $client->website = trim(Input::get('website')); $client->save(); $data = json_decode(Input::get('data')); $contactIds = []; $isPrimary = true; foreach ($data->contacts as $contact) { if (isset($contact->public_id) && $contact->public_id) { $record = Contact::scope($contact->public_id)->firstOrFail(); } else { $record = Contact::createNew(); } $record->email = trim(strtolower($contact->email)); $record->first_name = trim($contact->first_name); $record->last_name = trim($contact->last_name); $record->phone = trim($contact->phone); $record->is_primary = $isPrimary; $isPrimary = false; $client->contacts()->save($record); $contactIds[] = $record->public_id; } foreach ($client->contacts as $contact) { if (!in_array($contact->public_id, $contactIds)) { $contact->delete(); } } if ($publicId) { Session::flash('message', trans('texts.updated_client')); } else { Activity::createClient($client); Session::flash('message', trans('texts.created_client')); } return Redirect::to('clients/' . $client->public_id); } }
/** * Show the form for creating a new resource. * * @return Response */ public function create($clientPublicId = 0, $invoicePublicId = 0) { $data = ['clientPublicId' => Input::old('client') ? Input::old('client') : $clientPublicId, 'invoicePublicId' => Input::old('invoice') ? Input::old('invoice') : $invoicePublicId, 'invoices' => Invoice::scope()->where('is_recurring', '=', false)->where('is_quote', '=', false)->where('invoice_status_id', '<', '5')->where('balance', '>', 0)->with('client', 'invoice_status', 'branch')->orderBy('invoice_number')->get(), 'paymentTypes' => PaymentType::orderBy('id')->get(), 'clients' => Client::scope()->with('contacts')->orderBy('name')->get(), 'payment' => null, 'method' => 'POST', 'url' => 'pagos', 'title' => 'Nuevo pago']; return View::make('pagos.edit', $data); }
$locale = Session::get(SESSION_LOCALE); if ($locale == 'en') { return trans($text); } else { $string = trans($text); $english = trans($text, [], 'en'); return $string != $english ? $string : ''; } } Validator::extend('positive', function ($attribute, $value, $parameters) { return Utils::parseFloat($value) >= 0; }); Validator::extend('has_credit', function ($attribute, $value, $parameters) { $publicClientId = $parameters[0]; $amount = $parameters[1]; $client = Client::scope($publicClientId)->firstOrFail(); $credit = $client->getTotalCredit(); return $credit >= $amount; }); /* // Log all SQL queries to laravel.log Event::listen('illuminate.query', function($query, $bindings, $time, $name) { $data = compact('bindings', 'time', 'name'); // Format binding data for sql insertion foreach ($bindings as $i => $binding) { if ($binding instanceof \DateTime) { $bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
private function save($publicId = null, $isPos = null) { $rules = array('nit' => 'required'); // $clientId = $publicId ? Client::getPrivateId($publicId) : null; // $rules = ['nit' => 'unique:clients,nit,' . $clientId . ',id,account_id,' . Auth::user()->account_id]; $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { if ($isPos) { $datos = array('resultado' => 1, 'mensaje' => 'Nit ya ha sido registrado.'); return Response::json($datos); } else { $url = $publicId ? 'clients/' . $publicId . '/edit' : 'clients/create'; return Redirect::to($url)->withErrors($validator)->withInput(Input::except('password')); } } else { if ($publicId) { $client = Client::scope($publicId)->firstOrFail(); } else { $client = Client::createNew(); } $client->nit = trim(Input::get('nit')); $client->name = trim(Input::get('name')); $client->business_name = trim(Input::get('business_name')); $client->work_phone = trim(Input::get('work_phone')); if ($isPos) { $client->business_name = trim(Input::get('name')); } $client->custom_value1 = trim(Input::get('custom_value1')); $client->custom_value2 = trim(Input::get('custom_value2')); $client->custom_value3 = trim(Input::get('custom_value3')); $client->custom_value4 = trim(Input::get('custom_value4')); $client->custom_value5 = trim(Input::get('custom_value5')); $client->custom_value6 = trim(Input::get('custom_value6')); $client->custom_value7 = trim(Input::get('custom_value7')); $client->custom_value8 = trim(Input::get('custom_value8')); $client->custom_value9 = trim(Input::get('custom_value9')); $client->custom_value10 = trim(Input::get('custom_value10')); $client->custom_value11 = trim(Input::get('custom_value11')); $client->custom_value12 = trim(Input::get('custom_value12')); $client->address1 = trim(Input::get('address1')); $client->address2 = trim(Input::get('address2')); $client->city = trim(Input::get('city')); $client->state = trim(Input::get('state')); $client->private_notes = trim(Input::get('private_notes')); $client->save(); if (!$isPos) { $data = json_decode(Input::get('data')); $contactIds = []; $isPrimary = true; foreach ($data->contacts as $contact) { if (isset($contact->public_id) && $contact->public_id) { $record = Contact::scope($contact->public_id)->firstOrFail(); } else { $record = Contact::createNew(); } $record->email = trim(strtolower($contact->email)); $record->first_name = trim($contact->first_name); $record->last_name = trim($contact->last_name); $record->phone = trim($contact->phone); $record->is_primary = $isPrimary; $isPrimary = false; $client->contacts()->save($record); $contactIds[] = $record->public_id; } foreach ($client->contacts as $contact) { if (!in_array($contact->public_id, $contactIds)) { $contact->delete(); } } if ($publicId) { Activity::editClient($client); Session::flash('message', trans('texts.updated_client')); } else { Activity::createClient($client); Session::flash('message', trans('texts.created_client')); } return Redirect::to('clients/' . $client->public_id); } else { $record = Contact::createNew(); $record->is_primary = true; $client->contacts()->save($record); $clientPOS = array('id' => $client->id, 'public_id' => $client->public_id, 'name' => $client->name, 'nit' => $client->nit, 'business_name' => $client->business_name); $datos = array('resultado' => 0, 'cliente' => $clientPOS); return Response::json($datos); } } }
private function mapFile() { $file = Input::file('file'); if ($file == null) { Session::flash('error', trans('texts.select_file')); return Redirect::to('company/import_export'); } $name = $file->getRealPath(); require_once app_path() . '/includes/parsecsv.lib.php'; $csv = new parseCSV(); $csv->heading = false; $csv->auto($name); if (count($csv->data) + Client::scope()->count() > Auth::user()->getMaxNumClients()) { $message = trans('texts.limit_clients', ['count' => Auth::user()->getMaxNumClients()]); Session::flash('error', $message); return Redirect::to('company/import_export'); } Session::put('data', $csv->data); $headers = false; $hasHeaders = false; $mapped = array(); $columns = array('', Client::$fieldName, Client::$fieldPhone, Client::$fieldAddress1, Client::$fieldAddress2, Client::$fieldCity, Client::$fieldState, Client::$fieldPostalCode, Client::$fieldCountry, Client::$fieldNotes, Contact::$fieldFirstName, Contact::$fieldLastName, Contact::$fieldPhone, Contact::$fieldEmail); if (count($csv->data) > 0) { $headers = $csv->data[0]; foreach ($headers as $title) { if (strpos(strtolower($title), 'name') > 0) { $hasHeaders = true; break; } } for ($i = 0; $i < count($headers); $i++) { $title = strtolower($headers[$i]); $mapped[$i] = ''; if ($hasHeaders) { $map = array('first' => Contact::$fieldFirstName, 'last' => Contact::$fieldLastName, 'email' => Contact::$fieldEmail, 'mobile' => Contact::$fieldPhone, 'phone' => Client::$fieldPhone, 'name|organization' => Client::$fieldName, 'street|address|address1' => Client::$fieldAddress1, 'street2|address2' => Client::$fieldAddress2, 'city' => Client::$fieldCity, 'state|province' => Client::$fieldState, 'zip|postal|code' => Client::$fieldPostalCode, 'country' => Client::$fieldCountry, 'note' => Client::$fieldNotes); foreach ($map as $search => $column) { foreach (explode("|", $search) as $string) { if (strpos($title, 'sec') === 0) { continue; } if (strpos($title, $string) !== false) { $mapped[$i] = $column; break 2; } } } } } } $data = array('data' => $csv->data, 'headers' => $headers, 'hasHeaders' => $hasHeaders, 'columns' => $columns, 'mapped' => $mapped); return View::make('accounts.import_map', $data); }
public function create($clientPublicId = 0) { $client = null; $invoiceNumber = Auth::user()->branch->getNextInvoiceNumber(); $account = Account::with('country')->findOrFail(Auth::user()->account_id); if ($clientPublicId) { $client = Client::scope($clientPublicId)->firstOrFail(); } $data = array('account' => $account, 'invoice' => null, 'data' => Input::old('data'), 'invoiceNumber' => $invoiceNumber, 'method' => 'POST', 'url' => 'invoices', 'title' => '- New Invoice', 'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->where('id', $clientPublicId)->get(), 'client' => $client); $data = array_merge($data, self::getViewModel()); return View::make('invoices.edit', $data); }
private static function getViewModel() { return ['account' => Auth::user()->account, 'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')), 'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']), 'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'invoiceDesigns' => InvoiceDesign::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'invoiceLabels' => Auth::user()->account->getInvoiceLabels(), 'frequencies' => array(1 => 'Weekly', 2 => 'Two weeks', 3 => 'Four weeks', 4 => 'Monthly', 5 => 'Three months', 6 => 'Six months', 7 => 'Annually')]; }
private static function getViewModel() { $recurringHelp = ''; foreach (preg_split("/((\r?\n)|(\r\n?))/", trans('texts.recurring_help')) as $line) { $parts = explode("=>", $line); if (count($parts) > 1) { $line = $parts[0] . ' => ' . Utils::processVariables($parts[0]); $recurringHelp .= '<li>' . strip_tags($line) . '</li>'; } else { $recurringHelp .= $line; } } return ['account' => Auth::user()->account, 'products' => Product::scope()->orderBy('id')->get(array('product_key', 'notes', 'cost', 'qty')), 'countries' => Country::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'clients' => Client::scope()->with('contacts', 'country')->orderBy('name')->get(), 'taxRates' => TaxRate::scope()->orderBy('name')->get(), 'currencies' => Currency::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'sizes' => Size::remember(DEFAULT_QUERY_CACHE)->orderBy('id')->get(), 'paymentTerms' => PaymentTerm::remember(DEFAULT_QUERY_CACHE)->orderBy('num_days')->get(['name', 'num_days']), 'industries' => Industry::remember(DEFAULT_QUERY_CACHE)->orderBy('name')->get(), 'invoiceDesigns' => InvoiceDesign::remember(DEFAULT_QUERY_CACHE, 'invoice_designs_cache_' . Auth::user()->maxInvoiceDesignId())->where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get(), 'frequencies' => array(1 => 'Weekly', 2 => 'Two weeks', 3 => 'Four weeks', 4 => 'Monthly', 5 => 'Three months', 6 => 'Six months', 7 => 'Annually'), 'recurringHelp' => $recurringHelp]; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($public_id) { $client = Client::scope($public_id)->firstOrFail(); if ($client->borrar()) { Session::flash('message', $client->getErrorMessage()); // return $client->getErrorMessage(); return Redirect::to('clientes'); } Session::flash('error', $client->getErrorMessage()); // return var_dump($client); return Redirect::to('clientes/' . $public_id); // return Response::json(array('XD'=>'Ooooo')); // $getTotalBalance = $client->balance; // $getTotalCredit = Credit::scope()->where('client_id', '=', $client->id)->whereNull('deleted_at')->where('balance', '>', 0)->sum('balance'); // if ($getTotalBalance > 0) { // $message = "El cliente " . $client->name . " tiene " . $getTotalBalance . " pendiente de pago."; // Session::flash('error', $message); // return Redirect::to('clientes'); // }else if ($getTotalCredit > 0) { // $message = "El cliente " . $client->name . " tiene " . $getTotalCredit . " de Crédito disponible."; // Session::flash('error', $message); // return Redirect::to('clientes'); // }else{ // return Response::json($client); // $client->delete(); // $message = "Cliente eliminado con éxito"; // // return Redirect::to('clientes'); // } }
public function createcliente() { $user_id = Auth::user()->getAuthIdentifier(); $user = DB::table('users')->select('account_id')->where('id', $user_id)->first(); $i = 1; $aux = 'no'; //40360 for ($i = 1; $i <= 2000; $i++) { $client1 = DB::table('clients')->select('id', 'name', 'public_id')->where('account_id', $user->account_id)->where('id', $i)->where('deleted_at', NULL)->first(); if ($client1 != null) { $client = Client::scope($client1->public_id)->firstOrFail(); if ($client != null) { $contact = DB::table('contacts')->select('id', 'first_name')->where('account_id', $user->account_id)->where('client_id', $client->id)->where('is_primary', 1)->first(); if ($contact == null) { $contact = Contact::createNew(); $contact->is_primary = true; $client->contacts()->save($contact); $aux = 'si'; } } } } return Response::json($aux); }