public function __construct($code, $size = 100) { if (!file_exists("ticket_tmp/{$code}.png")) { $qr = new BarcodeQR(); $qr->text($code); $qr->draw($size, "../ticket_tmp/{$code}.png"); } }
/** * Verificamos si existe la imagen */ public function getQR_get($key) { $image = $key . ".png"; if (!file_exists("./assets/img/api/qr/" . $image)) { $qr = new BarcodeQR(); $qr->text($key); $qr->draw(330, "./assets/img/api/qr/" . $image); } }
public function confirm() { $this->language->load('payment/cod'); $this->load->model('account/order'); $this->load->model('account/payment'); $this->load->library('email/mailer'); if ($this->session->has('order_id')) { $this->data['order_id'] = $this->session->get('order_id'); } elseif ($this->request->hasQuery('order_id')) { $this->data['order_id'] = $this->request->getQuery('order_id'); } elseif ($this->request->hasPost('cod_order_id')) { $this->data['order_id'] = $this->request->getPost('cod_order_id'); } else { $this->data['order_id'] = 0; } $order_info = $this->modelOrder->getOrder($this->data['order_id']); if ($order_info && $this->customer->isLogged()) { $total_payment = $this->modelPayment->getSumPayments(array('order_id' => $order_info['order_id'], 'limit' => 1000)); $total = $order_info['total'] - $total_payment; $amount = explode(",", $this->request->getPost('cod_amount')); $payment = round(str_replace(".", "", $amount[0]) . "." . $amount[1], 2); $data['order_id'] = $order_info['order_id']; $data['payment_method'] = $this->language->get('text_title'); $data['amount'] = $payment; $data['comment'] = $this->language->get('text_date_of_payment') . ": " . $this->request->getPost('cod_date_of_payment') . "\n"; $data['comment'] .= $this->language->get('text_payment_method_on_delivery') . ": " . $this->request->getPost('cod_payment_method_on_delivery') . "\n"; $data['comment'] .= "\n" . $this->request->getPost('cod_comment'); $data['order_status_id'] = $this->config->get('cod_order_status_id'); $data['order_payment_status_id'] = $this->config->get('config_payment_status_id'); $json['payment_id'] = $payment_id = $this->modelPayment->add($data); $this->modelOrder->addOrderHistory($order_info['order_id'], $data); $this->modelOrder->updateStatus($order_info['order_id'], $this->config->get('cod_order_status_id')); $this->modelOrder->updatePaymentMethod($order_info['order_id'], $this->language->get('text_title')); $diff = $payment - $total; if ($diff < 0) { //falta dinero $diff = $diff * -1; $json['warning'] = 1; $json['msg'] = str_replace('{%payment_receipt%}', Url::createUrl("account/payment"), $this->language->get('error_moneyless')); $json['msg'] = str_replace('{%invoice%}', Url::createUrl("account/invoice", array('order_id' => $order_info['order_id'])), $json['msg']); $json['msg'] = str_replace('{%diff%}', $this->currency->format($diff), $json['msg']); } elseif ($diff > 0) { //sobra dinero $json['warning'] = 1; $json['msg'] = str_replace('{%payment_receipt%}', Url::createUrl("account/payment"), $this->language->get('error_moneymore')); $json['msg'] = str_replace('{%invoice%}', Url::createUrl("account/invoice", array('order_id' => $order_info['order_id'])), $json['msg']); $json['msg'] = str_replace('{%diff%}', $this->currency->format($diff), $json['msg']); } else { $json['success'] = 1; $json['msg'] = $this->language->get('text_success'); } $mailer = new Mailer(); if ($this->config->get('cod_newsletter_id')) { $this->load->model("marketing/newsletter"); $this->load->library('BarcodeQR'); $this->load->library('Barcode39'); $qr = new BarcodeQR(); $barcode = new Barcode39(C_CODE); $totals = $this->modelOrder->getOrderTotals($order_id); $text = $this->config->get('config_owner') . "\n"; $text .= "Pago ID: " . $payment_id . "\n"; $text .= "Pedido ID: " . $order_id . "\n"; $text .= "Fecha Emision del Pedido: " . date('d-m-Y h:i A', strtotime($order_info['date_added'])) . "\n"; $text .= "Cliente: " . $this->customer->getCompany() . "\n"; $text .= "RIF: " . $this->customer->getRif() . "\n"; $text .= "Direccion IP: " . $_SERVER['REMOTE_ADDR'] . "\n"; $qrStore = "cache/" . str_replace(".", "_", $this->config->get('config_owner')) . '.jpg'; $qrPayment = "cache/" . str_replace(" ", "_", $this->config->get('config_owner') . "_qr_code_payment_" . $payment_id) . '.jpg'; $eanStore = "cache/" . str_replace(" ", "_", $this->config->get('config_owner') . "_barcode_39_order_id_" . $order_id) . '.gif'; $qr->text($text); $qr->draw(150, DIR_IMAGE . $qrPayment); $qr->url(HTTP_HOME); $qr->draw(150, DIR_IMAGE . $qrStore); $barcode->draw(DIR_IMAGE . $eanStore); $payment_text = '<h1>' . $this->config->get('config_owner') . "</h1>"; $payment_text .= "Pago ID: " . $payment_id . "<br />"; $payment_text .= "Pedido ID: " . $order_id . "<br />"; $payment_text .= "Fecha Emision del Pedido: " . date('d-m-Y h:i A', strtotime($order_info['date_added'])) . "<br />"; $payment_text .= "Cliente: " . $this->customer->getCompany() . "<br />"; $payment_text .= "RIF: " . $this->customer->getRif() . "<br />"; $payment_text .= "Direccion IP: " . $_SERVER['REMOTE_ADDR'] . "<br />"; $total_html = "<div class=\"clear:both;float:none;\"></div><br /><table>"; foreach ($totals as $total) { $total_html .= "<tr>"; $total_html .= "<td style=\"text-align:right;\">" . $total['title'] . "</td>"; $total_html .= "<td style=\"text-align:right;\">" . $total['text'] . "</td>"; $total_html .= "</tr>"; } $total_html .= "</table>"; $payment_text .= $total_html; $result = $this->modelNewsletter->getById($this->config->get('cod_newsletter_id')); $message = $result['htmlbody']; $message = str_replace("{%title%}", 'Pago N° ' . $payment_id . " - " . $this->config->get('config_name'), $message); $message = str_replace("{%store_logo%}", '<img src="' . HTTP_IMAGE . $this->config->get('config_logo') . '" alt="' . $this->config->get('config_name') . '" />', $message); $message = str_replace("{%store_url%}", HTTP_HOME, $message); $message = str_replace("{%store_owner%}", $this->config->get('config_owner'), $message); $message = str_replace("{%store_name%}", $this->config->get('config_name'), $message); $message = str_replace("{%store_rif%}", $this->config->get('config_rif'), $message); $message = str_replace("{%store_email%}", $this->config->get('config_email'), $message); $message = str_replace("{%store_telephone%}", $this->config->get('config_telephone'), $message); $message = str_replace("{%store_address%}", $this->config->get('config_address'), $message); $message = str_replace("{%totals%}", $total_html, $message); $message = str_replace("{%order_id%}", $this->config->get('config_invoice_prefix') . $order_id, $message); $message = str_replace("{%invoice_id%}", $this->config->get('config_invoice_prefix') . $invoice_id, $message); $message = str_replace("{%rif%}", $this->customer->getRif(), $message); $message = str_replace("{%fullname%}", $this->customer->getFirstName() . " " . $this->customer->getFirstName(), $message); $message = str_replace("{%company%}", $this->customer->getCompany(), $message); $message = str_replace("{%email%}", $this->customer->getEmail(), $message); $message = str_replace("{%telephone%}", $this->customer->getTelephone(), $message); $message = str_replace("{%payment%}", $payment_text, $message); $message = str_replace("{%payment_method%}", $order_info['payment_method'], $message); $message = str_replace("{%date_added%}", date('d-m-Y h:i A', strtotime($order_info['date_added'])), $message); $message = str_replace("{%ip%}", $_SERVER['REMOTE_ADDR'], $message); $message = str_replace("{%qr_code_store%}", '<img src="' . HTTP_IMAGE . $qrStore . '" alt="QR Code" />', $message); $message = str_replace("{%comment%}", $order_info['comment'], $message); $message = str_replace("{%qr_code_payment%}", '<img src="' . HTTP_IMAGE . $qrPayment . '" alt="QR Code" />', $message); $message = str_replace("{%barcode_39_order_id%}", '<img src="' . HTTP_IMAGE . $eanStore . '" alt="QR Code" />', $message); $message .= "<p style=\"text-align:center\">Powered By Necotienda® " . date('Y') . "</p>"; } else { $message = $this->config->get('config_owner') . "\n"; $message .= "Pago ID: " . $payment_id . "\n"; $message .= "Pedido ID: " . $order_id . "\n"; $message .= "Fecha Emision: " . date('d-m-Y h:i A', strtotime($order_info['date_added'])) . "\n"; $message .= "Cliente: " . $this->customer->getCompany() . "\n"; $message .= "RIF: " . $this->customer->getRif() . "\n"; $message .= "Direccion IP: " . $_SERVER['REMOTE_ADDR'] . "\n"; $message .= "\n" . "Powered By Necotienda® " . date('Y') . "\n"; } if ($message) { if ($this->config->get('config_smtp_method') == 'smtp') { $mailer->IsSMTP(); $mailer->Host = $this->config->get('config_smtp_host'); $mailer->Username = $this->config->get('config_smtp_username'); $mailer->Password = base64_decode($this->config->get('config_smtp_password')); $mailer->Port = $this->config->get('config_smtp_port'); $mailer->Timeout = $this->config->get('config_smtp_timeout'); $mailer->SMTPSecure = $this->config->get('config_smtp_ssl'); $mailer->SMTPAuth = $this->config->get('config_smtp_auth') ? true : false; } elseif ($this->config->get('config_smtp_method') == 'sendmail') { $mailer->IsSendmail(); } else { $mailer->IsMail(); } $mailer->IsHTML(); $mailer->AddAddress($this->customer->getEmail(), $this->customer->getCompany()); $mailer->AddBCC($this->config->get('config_email'), $this->config->get('config_name')); $mailer->SetFrom($this->config->get('config_email'), $this->config->get('config_name')); $mailer->Subject = $this->config->get('config_owner') . " " . $this->language->get('text_new_payment') . " #" . $payment_id; $mailer->Body = html_entity_decode(htmlspecialchars_decode($message)); $mailer->Send(); } } elseif (!$this->customer->isLogged()) { $json['error'] = 1; $json['msg'] = $this->language->get('error_not_logged'); } else { $json['error'] = 1; $json['msg'] = $this->language->get('error_payment'); } $this->load->library('json'); $this->response->setOutput(Json::encode($json), $this->config->get('config_compression')); }
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 importFilei() { $data = Session::get('data'); $map = Input::get('map'); $count = 0; $hasHeaders = true; foreach ($data as $row) { if ($hasHeaders) { $hasHeaders = false; continue; } foreach ($row as $index => $value) { $field = $map[$index]; $value = trim($value); if ($field == Invoice::$fieldCodClient) { $clients = Client::scope()->get(); $flag = 1; foreach ($clients as $client) { $cod_client = intval($value); if ($client->public_id == $cod_client) { $flag = 1; } } if ($flag == 0) { $message = 'cliente no encontrado ' . $value . 'Favor revisar el archivo importado '; Session::flash('message', $message); return Redirect::to('company/import_export'); } } else { if ($field == Invoice::$fieldProduct) { if ($value == '') { $message = 'Concepto vacío. Favor revisar el archivo importado '; Session::flash('message', $message); return Redirect::to('company/import_export'); } } else { if ($field == Invoice::$fieldAmount) { if ($value == '') { $message = 'Monto vacío. Favor revisar el archivo importado '; Session::flash('message', $message); return Redirect::to('company/import_export'); } } } } } } $branch_id = Input::get('branch_id'); $clients = Client::scope()->get(); $clientMap = []; $data = Session::get('data'); Session::forget('data'); $hasHeaders = true; foreach ($clients as $client) { $i = 0; $clientMap[$client->public_id][$i] = $client->id; $clientMap[$client->public_id][$i + 1] = $client->nit; $clientMap[$client->public_id][$i + 2] = $client->name; } foreach ($data as $row) { if ($hasHeaders) { $hasHeaders = false; continue; } $invoice = Invoice::createNew(); $invoiceItem = InvoiceItem::createNew(); $count++; $branch = \DB::table('branches')->where('id', $branch_id)->first(); $invoice->branch_id = $branch_id; $invoiceNumber = $branch->invoice_number_counter; $invoice->invoice_number = $invoiceNumber; $today = new DateTime('now'); $invoice->invoice_date = $today->format('Y-m-d'); $invoiceDesign = \DB::table('invoice_designs')->where('account_id', \Auth::user()->account_id)->orderBy('public_id', 'desc')->first(); $invoice->invoice_design_id = $invoiceDesign->id; $account = \Auth::user()->account; $invoice->account_name = $account->name; $invoice->account_nit = $account->nit; $invoice->branch_name = $branch->name; $invoice->address1 = $branch->address1; $invoice->address2 = $branch->address2; $invoice->phone = $branch->postal_code; $invoice->city = $branch->city; $invoice->state = $branch->state; $invoice->number_autho = $branch->number_autho; $invoice->deadline = $branch->deadline; $invoice->key_dosage = $branch->key_dosage; $invoice->activity_pri = $branch->activity_pri; $invoice->activity_sec1 = $branch->activity_sec1; $invoice->law = $branch->law; foreach ($row as $index => $value) { $field = $map[$index]; $value = trim($value); if ($field == Invoice::$fieldCodClient) { $cod_client = intval($value); $invoice->client_id = $clientMap[$cod_client][0]; $invoice->client_nit = $clientMap[$cod_client][1]; $invoice->client_name = $clientMap[$cod_client][2]; } else { if ($field == Invoice::$fieldProduct) { $notes = $value; } else { if ($field == Invoice::$fieldAmount) { $invoiceItem->notes = wordwrap($notes, 70, "\n"); $str = str_replace(".", "", $value); $amount = str_replace(",", ".", $str); $invoiceItem->cost = $amount; $invoiceItem->qty = 1; $invoiceItem->tax_rate = 0; $invoice->subtotal = $invoiceItem->cost; $invoice->amount = $invoiceItem->cost; $invoice->balance = $invoiceItem->cost; } } } } $invoice_dateCC = date("Ymd", strtotime($invoice->invoice_date)); $invoice_date_limitCC = date("d/m/Y", strtotime($branch->deadline)); require_once app_path() . '/includes/control_code.php'; $cod_control = codigoControl($invoice->invoice_number, $invoice->client_nit, $invoice_dateCC, $invoice->amount, $branch->number_autho, $branch->key_dosage); $invoice->control_code = $cod_control; $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(); $invoice->invoice_items()->save($invoiceItem); // Activity::createInvoice($invoice, false); } $message = Utils::pluralize('created_invoicei', $count); Session::flash('message', $message); return Redirect::to('invoices'); }
if ($_POST['switch4'] == 'on') { $text .= $_SESSION['user']['instagramurl']; } else { $text .= ""; } $text .= "\n"; if ($_POST['switch5'] == 'on') { $text .= $_SESSION['user']['linkedinurl']; } else { $text .= ""; } // set BarcodeQR object $qr = new BarcodeQR(); //echo $text; // create URL QR code $qr->text($text); //save QR code image $qr->draw(300, $filename); //header("Location: generate.php"); //die("Redirecting to generate.php"); } //echo $text ?> <html lang="en"> <head> <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <link href='https://fonts.googleapis.com/css?family=Open+Sans:300' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"> <style>
/** * Renders QR code label of some type * * @param string $type * @param int $id */ public function qrCodeDraw($type, $id) { $type = vf($type); $id = vf($id, 3); $qr = new BarcodeQR(); switch ($type) { case 'in': if (isset($this->allIncoming[$id])) { $itemName = $this->allItemTypeNames[$this->allIncoming[$id]['itemtypeid']]; $qr->text($itemName . ' ' . __('Incoming operation') . '# ' . $id); } else { $qr->text('Wrong ID'); } break; case 'out': if (isset($this->allOutcoming[$id])) { $itemName = $this->allItemTypeNames[$this->allOutcoming[$id]['itemtypeid']]; $qr->text($itemName . ' ' . __('Outcoming operation') . '# ' . $id); } else { $qr->text('Wrong ID'); } case 'itemtype': if (isset($this->allItemTypeNames[$id])) { $qr->text($this->allItemTypeNames[$id]); } else { $qr->text('Wrong ID'); } break; default: $qr->text('Wrong type'); break; } $qr->draw(); }
public function guardarFacturaOffline() { /* David Guardando factura con el siguiente formato: //Formato Offline //nuevo formato para la cascada XD {"invoice_items":[{"qty":"2","id":"2","boni":"1","desc":"3"}],"client_id":"1","nit":"6047054","name":"torrez","public_id":"1","invoice_date":"14-10-2014","invoice_number":"0001","cod_control"} */ $input = Input::all(); // $invoice_number = Auth::user()->account->getNextInvoiceNumber(); $invoice_number = (int) Auth::user()->branch->getNextInvoiceNumber(); $numero = (int) $input['invoice_number']; // $numero =(int) $input['invoice_number']; if ($invoice_number != $numero) { return Response::json(array('resultado' => '1', 'invoice_number' => $invoice_number)); } $client_id = $input['client_id']; // $client = DB::table('clients')->select('id','nit','name','public_id')->where('id',$input['client_id'])->first(); $user_id = Auth::user()->getAuthIdentifier(); $user = DB::table('users')->select('account_id', 'branch_id', 'price_type_id')->where('id', $user_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(); $items = $input['invoice_items']; // $linea =""; $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(); // $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; $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; $icetotal = $icetotal + ($iceBruto - $iceNeto); // $fiscal = $fiscal + ($amount - ($item['qty'] *($pr->cc/1000)*$ice->rate) ); } } $fiscal = $amount - $bonidesc - $icetotal; $balance = $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, $input['nit'], $invoice_dateCC, $amount, $branch->number_autho, $branch->key_dosage); $cod_control = $input['cod_control']; $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->subtotal = $subtotal; $invoice->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->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 = $input['nit']; $invoice->name = $input['name']; $invoice->save(); $account = Auth::user()->account; require_once app_path() . '/includes/BarcodeQR.php'; $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; } $qr = new BarcodeQR(); $datosqr = '1006909025|' . $input['invoice_number'] . '|' . $invoice->number_autho . '|' . $invoice_date . '|' . $amount . '|' . $fiscal . '|' . $invoice->nit . '|' . $icef . '|0|0|' . $descf; $qr->text($datosqr); $qr->draw(150, 'qr/' . $account->account_key . '_' . $invoice->invoice_number . '.png'); $input_file = 'qr/' . $account->account_key . '_' . $invoice->invoice_number . '.png'; $output_file = 'qr/' . $account->account_key . '_' . $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 . '_' . $input['invoice_number'] . '.jpg'); $invoice->save(); $fecha = $input['fecha']; $f = date("Y-m-d", strtotime($fecha)); DB::table('invoices')->where('id', $invoice->id)->update(array('branch' => $branch->name, 'invoice_date' => $f)); //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')->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; $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 = $cost; $invoiceItem->boni = (int) $item['boni']; $invoiceItem->desc = $item['desc']; $invoiceItem->qty = (int) $item['qty']; $invoiceItem->line_total = $line_total; $invoiceItem->tax_rate = 0; $invoiceItem->save(); } // $invoiceItems =DB::table('invoice_items') // ->select('notes','cost','qty','boni','desc') // ->where('invoice_id','=',$invoice->id) // ->get(array('notes','cost','qty','boni','desc')); // $date = new DateTime($invoice->deadline); // $dateEmision = new DateTime($invoice->invoice_date); // $account = array('name' =>$branch->name,'nit'=>'1006909025' ); // $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, '.', '') // ); // $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(); $datos = array('resultado ' => "0"); //colocar una excepcion en caso de error // return Response::json($datos); return Response::json($datos); }
public function index() { $Url = new Url($this->registry); if ($this->config->get('config_store_mode') != 'store') { $this->redirect(HTTP_HOME); } $this->language->load('checkout/success'); $this->load->auto('account/address'); $address = $this->modelAddress->getAddress($this->customer->getAddressId()); $method_data = array(); $results = $this->modelExtension->getExtensions('payment'); foreach ($results as $result) { $this->load->model('payment/' . $result['key']); $this->language->load('payment/' . $result['key']); $method = $this->{'model_payment_' . $result['key']}->getMethod($address); if ($method) { $method_data[$result['key']] = $method; } } $sort_order = array(); foreach ($method_data as $key => $value) { $sort_order[$key] = $value['sort_order']; } array_multisort($sort_order, SORT_ASC, $method_data); $this->data['payment_methods'] = $method_data; foreach ($method_data as $key => $value) { $this->children[$key] = 'payment/' . $key; } $order_id = 0; if ($this->session->has('order_id')) { $order_id = $this->session->get('order_id'); } elseif ($this->request->hasPost('order_id')) { $order_id = $this->request->getPost('order_id'); } elseif ($this->request->hasQuery('order_id')) { $order_id = $this->request->getQuery('order_id'); } $this->data['order_id'] = $order_id; if ($order_id) { if ($this->config->get('marketing_email_new_order')) { $this->load->model('account/order'); $this->load->model('account/payment'); $this->load->model("marketing/newsletter"); $this->load->library('email/mailer'); $this->load->library('BarcodeQR'); $this->load->library('Barcode39'); $this->load->library('tcpdf/config/lang/spa'); $this->load->library('tcpdf/tcpdf'); $mailer = new Mailer(); $qr = new BarcodeQR(); $barcode = new Barcode39(C_CODE); $this->data['Currency'] = $this->currency; $this->data['order'] = $order = $this->modelOrder->getOrder($order_id); $this->data['products'] = $products = $this->modelOrder->getOrderProducts($order_id); $this->data['totals'] = $totals = $this->modelOrder->getOrderTotals($order_id); $this->data['payments'] = $payments = $this->modelPayment->getPayments(array('order_id' => $order_id, 'order_payment_status_id' => $this->config->get('order_payment_status_approved'))); $shipping_address = $order['shipping_address_1'] . ", " . $order['shipping_city'] . ". " . $order['shipping_zone'] . " - " . $order['shipping_country'] . ". CP " . $order['shipping_zone_code']; $payment_address = $order['payment_address_1'] . ", " . $order['payment_city'] . ". " . $order['payment_zone'] . " - " . $order['payment_country'] . ". CP " . $order['payment_zone_code']; $text = $this->config->get('config_owner') . "\n"; $text .= "Pedido ID: " . $order_id . "\n"; $text .= "Fecha Emision: " . date('d-m-Y h:i A', strtotime($order['date_added'])) . "\n"; $text .= "Cliente: " . $this->customer->getCompany() . "\n"; $text .= "RIF: " . $this->customer->getRif() . "\n"; $text .= "Direccion IP: " . $order['ip'] . "\n"; $text .= "Productos (" . count($products) . ")\n"; $text .= "Modelo\tCant.\tTotal\n"; foreach ($products as $key => $product) { $text .= $product['model'] . "\t" . $product['quantity'] . "\t" . $this->currency->format($product['total'], $order['currency'], $order['value']) . "\n"; } $qrStore = "cache/" . str_replace(".", "_", $this->config->get('config_owner')) . '.jpg'; $qrOrder = "cache/" . str_replace(" ", "_", $this->config->get('config_owner') . "_qr_code_order_" . $order_id) . '.jpg'; $eanStore = "cache/" . str_replace(" ", "_", $this->config->get('config_owner') . "_barcode_39_order_id_" . $order_id) . '.gif'; $qr->text($text); $qr->draw(150, DIR_IMAGE . $qrOrder); $qr->url(HTTP_HOME); $qr->draw(150, DIR_IMAGE . $qrStore); $barcode->draw(DIR_IMAGE . $eanStore); $product_html = "<table><thead><tr style=\"background:#ccc;color:#666;\"><th>Item</th><th>" . $this->language->get('column_description') . "</th><th>" . $this->language->get('column_model') . "</th><th>" . $this->language->get('column_quantity') . "</th><th>" . $this->language->get('column_price') . "</th><th>" . $this->language->get('column_total') . "</th></tr></thead><tbody>"; foreach ($products as $key => $product) { $options = $this->modelOrder->getOrderOptions($order_id, $product['order_product_id']); $option_data = ""; foreach ($options as $option) { $option_data .= " - " . $option['name'] . "<br />"; } $product_html .= "<tr>"; $product_html .= "<td style=\"width:5%\">" . (int) ($key + 1) . "</td>"; $product_html .= "<td style=\"width:45%\">" . $product['name'] . "<br />" . $option_data . "</td>"; $product_html .= "<td style=\"width:20%\">" . $product['model'] . "</td>"; $product_html .= "<td style=\"width:10%\">" . $product['quantity'] . "</td>"; $product_html .= "<td style=\"width:10%\">" . $this->currency->format($product['price'], $order['currency'], $order['value']) . "</td>"; $product_html .= "<td style=\"width:10%\">" . $this->currency->format($product['total'], $order['currency'], $order['value']) . "</td>"; $product_html .= "</tr>"; } $product_html .= "</tbody></table>"; $total_html = "<div class=\"clear:both;float:none;\"></div><br /><table style=\"float:right;\">"; foreach ($totals as $total) { $total_html .= "<tr>"; $total_html .= "<td style=\"text-align:right;\">" . $total['title'] . "</td>"; $total_html .= "<td style=\"text-align:right;\">" . $total['text'] . "</td>"; $total_html .= "</tr>"; } $total_html .= "</table>"; $result = $this->modelNewsletter->getById($this->config->get('marketing_email_new_order')); $message = $result['htmlbody']; $message = str_replace("{%title%}", 'Pedido N° ' . $order_id . " - " . $this->config->get('config_name'), $message); $message = str_replace("{%store_logo%}", '<img src="' . HTTP_IMAGE . $this->config->get('config_logo') . '" alt="' . $this->config->get('config_name') . '" />', $message); $message = str_replace("{%store_url%}", HTTP_HOME, $message); $message = str_replace("{%store_owner%}", $this->config->get('config_owner'), $message); $message = str_replace("{%store_name%}", $this->config->get('config_name'), $message); $message = str_replace("{%store_rif%}", $this->config->get('config_rif'), $message); $message = str_replace("{%store_email%}", $this->config->get('config_email'), $message); $message = str_replace("{%store_telephone%}", $this->config->get('config_telephone'), $message); $message = str_replace("{%store_address%}", $this->config->get('config_address'), $message); $message = str_replace("{%products%}", $product_html, $message); $message = str_replace("{%totals%}", $total_html, $message); $message = str_replace("{%order_id%}", $this->config->get('config_invoice_prefix') . $order_id, $message); $message = str_replace("{%invoice_id%}", $this->config->get('config_invoice_prefix') . $invoice_id, $message); $message = str_replace("{%rif%}", $this->customer->getRif(), $message); $message = str_replace("{%fullname%}", $this->customer->getFirstName() . " " . $this->customer->getFirstName(), $message); $message = str_replace("{%company%}", $this->customer->getCompany(), $message); $message = str_replace("{%email%}", $this->customer->getEmail(), $message); $message = str_replace("{%telephone%}", $this->customer->getTelephone(), $message); $message = str_replace("{%payment_address%}", $payment_address, $message); $message = str_replace("{%payment_method%}", $order['payment_method'], $message); $message = str_replace("{%shipping_address%}", $shipping_address, $message); $message = str_replace("{%shipping_method%}", $order['shipping_method'], $message); $message = str_replace("{%date_added%}", date('d-m-Y h:i A', strtotime($order['date_added'])), $message); $message = str_replace("{%ip%}", $order['ip'], $message); $message = str_replace("{%qr_code_store%}", '<img src="' . HTTP_IMAGE . $qrStore . '" alt="QR Code" />', $message); $message = str_replace("{%comment%}", $order['comment'], $message); $message = str_replace("{%qr_code_order%}", '<img src="' . HTTP_IMAGE . $qrOrder . '" alt="QR Code" />', $message); $message = str_replace("{%barcode_39_order_id%}", '<img src="' . HTTP_IMAGE . $eanStore . '" alt="QR Code" />', $message); $message .= "<p style=\"text-align:center\">Powered By <a href=\"http://www.necotienda.org\">Necotienda</a>® " . date('Y') . "</p>"; if ($this->config->get('marketing_email_order_pdf')) { $pdfFile = DIR_CACHE . str_replace(" ", "_", $this->config->get('config_owner') . "_pedido_" . $order_id) . '.pdf'; $result = $this->modelNewsletter->getById($this->config->get('marketing_email_order_pdf')); $pdfBody = html_entity_decode($result['htmlbody']); $pdfBody = str_replace("{%store_url%}", HTTP_HOME, $pdfBody); $pdfBody = str_replace("{%title%}", 'Pedido N° ' . $order_id . " - " . $this->config->get('config_name'), $pdfBody); $pdfBody = str_replace("{%store_owner%}", $this->config->get('config_owner'), $pdfBody); $pdfBody = str_replace("{%store_name%}", $this->config->get('config_name'), $pdfBody); $pdfBody = str_replace("{%store_rif%}", $this->config->get('config_rif'), $pdfBody); $pdfBody = str_replace("{%store_email%}", $this->config->get('config_email'), $pdfBody); $pdfBody = str_replace("{%store_telephone%}", $this->config->get('config_telephone'), $pdfBody); $pdfBody = str_replace("{%store_address%}", $this->config->get('config_address'), $pdfBody); $pdfBody = str_replace("{%products%}", $product_html, $pdfBody); $pdfBody = str_replace("{%totals%}", $total_html, $pdfBody); $pdfBody = str_replace("{%order_id%}", $this->config->get('config_invoice_prefix') . $order_id, $pdfBody); $pdfBody = str_replace("{%invoice_id%}", $this->config->get('config_invoice_prefix') . $invoice_id, $pdfBody); $pdfBody = str_replace("{%rif%}", $this->customer->getRif(), $pdfBody); $pdfBody = str_replace("{%fullname%}", $this->customer->getFirstName() . " " . $this->customer->getFirstName(), $pdfBody); $pdfBody = str_replace("{%company%}", $this->customer->getCompany(), $pdfBody); $pdfBody = str_replace("{%email%}", $this->customer->getEmail(), $pdfBody); $pdfBody = str_replace("{%telephone%}", $this->customer->getTelephone(), $pdfBody); $pdfBody = str_replace("{%payment_address%}", $payment_address, $pdfBody); $pdfBody = str_replace("{%payment_method%}", $order['payment_method'], $pdfBody); $pdfBody = str_replace("{%shipping_address%}", $shipping_address, $pdfBody); $pdfBody = str_replace("{%shipping_method%}", $order['shipping_method'], $pdfBody); $pdfBody = str_replace("{%date_added%}", date('d-m-Y h:i A', strtotime($order['date_added'])), $pdfBody); $pdfBody = str_replace("{%ip%}", $order['ip'], $pdfBody); $pdfBody = str_replace("{%comment%}", $order['comment'], $pdfBody); if (file_exists(DIR_IMAGE . $this->config->get('config_logo'))) { $pdfBody = str_replace("{%store_logo%}", '<img src="' . HTTP_IMAGE . $this->config->get('config_logo') . '" alt="' . $this->config->get('config_name') . '" />', $pdfBody); } else { $pdfBody = str_replace("{%store_logo%}", '', $pdfBody); } if (file_exists(DIR_IMAGE . $qrStore)) { $pdfBody = str_replace("{%qr_code_store%}", '<img src="' . HTTP_IMAGE . $qrStore . '" alt="QR Code" />', $pdfBody); } else { $pdfBody = str_replace("{%qr_code_store%}", '', $pdfBody); } if (file_exists(DIR_IMAGE . $qrOrder)) { $pdfBody = str_replace("{%qr_code_order%}", '<img src="' . HTTP_IMAGE . $qrOrder . '" alt="QR Code" />', $pdfBody); } else { $pdfBody = str_replace("{%qr_code_order%}", '', $pdfBody); } $pdfBody = str_replace("{%barcode_39_order_id%}", '<img src="' . HTTP_IMAGE . $eanStore . '" alt="QR Code" />', $pdfBody); $pdfBody .= "<p style=\"text-align:center\">Powered By Necotienda® " . date('Y') . "</p>"; // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator("Powered By NecoTienda®"); $pdf->SetTitle($this->config->get('config_name')); $pdf->SetAuthor($this->config->get('config_name')); $pdf->SetSubject($this->config->get('config_owner') . " " . $this->language->get('text_order') . " #" . $order_id); $pdf->SetKeywords($this->config->get('config_name') . ', ' . $product_tags . ',pdf'); // set default header data $pdf->SetHeaderData($this->config->get('config_logo'), PDF_HEADER_LOGO_WIDTH, $this->config->get('config_owner'), $this->config->get('config_name')); // set header and footer fonts $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings $pdf->setLanguageArray($l); // set font $pdf->SetFont('dejavusans', '', 10); // add a page $pdf->AddPage(); // output the HTML content $pdf->writeHTML($pdfBody, true, false, true, false, ''); //Close and output PDF document $pdf->Output($pdfFile, 'F'); } $subject = $this->config->get('config_owner') . " " . $this->language->get('text_new_order') . " #" . $order_id; if ($this->config->get('config_smtp_method') == 'smtp') { $mailer->IsSMTP(); $mailer->Host = $this->config->get('config_smtp_host'); $mailer->Username = $this->config->get('config_smtp_username'); $mailer->Password = base64_decode($this->config->get('config_smtp_password')); $mailer->Port = $this->config->get('config_smtp_port'); $mailer->Timeout = $this->config->get('config_smtp_timeout'); $mailer->SMTPSecure = $this->config->get('config_smtp_ssl'); $mailer->SMTPAuth = $this->config->get('config_smtp_auth') ? true : false; } elseif ($this->config->get('config_smtp_method') == 'sendmail') { $mailer->IsSendmail(); } else { $mailer->IsMail(); } $mailer->IsHTML(); $mailer->AddAddress($this->customer->getEmail(), $this->customer->getCompany()); $mailer->AddBCC($this->config->get('config_email'), $this->config->get('config_name')); $mailer->SetFrom($this->config->get('config_email'), $this->config->get('config_name')); $mailer->Subject = $subject; $mailer->Body = html_entity_decode(htmlspecialchars_decode($message)); if ($pdfFile && file_exists($pdfFile)) { $mailer->AddAttachment($pdfFile); } $mailer->Send(); } $order_id = $this->session->get('order_id'); $this->cart->clear(); $this->session->clear('shipping_method'); $this->session->clear('shipping_methods'); $this->session->clear('payment_method'); $this->session->clear('payment_methods'); $this->session->clear('guest'); $this->session->clear('comment'); $this->session->clear('order_id'); $this->session->clear('coupon'); } $this->document->title = $this->language->get('heading_title'); $this->document->breadcrumbs = array(); $this->document->breadcrumbs[] = array('href' => Url::createUrl("common/home"), 'text' => $this->language->get('text_home'), 'separator' => false); $this->document->breadcrumbs[] = array('href' => Url::createUrl("checkout/cart"), 'text' => $this->language->get('text_basket'), 'separator' => $this->language->get('text_separator')); $this->document->breadcrumbs[] = array('href' => Url::createUrl("checkout/success"), 'text' => $this->language->get('text_checkout_success'), 'separator' => $this->language->get('text_separator')); $this->data['breadcrumbs'] = $this->document->breadcrumbs; $this->data['heading_title'] = $this->language->get('heading_title'); if ($this->config->get('page_order_success')) { $this->load->model('content/page'); $page = $this->modelPage->getById($this->config->get('page_order_success')); $this->data['text_message'] = html_entity_decode($page['description']); } else { $this->data['text_message'] = sprintf($this->language->get('text_message'), Url::createUrl("account/account"), Url::createUrl("account/order"), Url::createUrl("page/contact")); } // style files $csspath = defined("CDN") ? CDN . CSS : HTTP_CSS; $styles[] = array('media' => 'all', 'href' => $csspath . 'jquery-ui/jquery-ui.min.css'); $styles[] = array('media' => 'all', 'href' => $csspath . 'neco.form.css'); $this->data['styles'] = $this->styles = array_merge($this->styles, $styles); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/checkout/success.tpl')) { $this->template = $this->config->get('config_template') . '/checkout/success.tpl'; } else { $this->template = 'choroni/checkout/success.tpl'; } $this->children[] = 'common/nav'; $this->children[] = 'common/footer'; $this->children[] = 'common/header'; $this->response->setOutput($this->render(true), $this->config->get('config_compression')); }
public function fire() { $this->info(date('Y-m-d') . ' Cargando SendRecurringInvoices...'); $today = new DateTime(); $invoices = Invoice::with('account.timezone', 'invoice_items', 'client')->whereRaw('is_deleted IS FALSE AND deleted_at IS NULL AND is_recurring IS TRUE AND start_date <= ? AND (end_date IS NULL OR end_date >= ?)', array($today, $today))->get(); $this->info(count($invoices) . ' facturas recurrentes encontradas'); foreach ($invoices as $recurInvoice) { if ($recurInvoice->client->deleted_at) { continue; } if (!$recurInvoice->user->confirmed) { continue; } date_default_timezone_set($recurInvoice->account->getTimezone()); $this->info('Procesando la factura con el id ' . $recurInvoice->id . ($recurInvoice->shouldSendToday() ? ' si se enviará' : ' no se enviará')); // if (!$recurInvoice->shouldSendToday()) // { // continue; // } $branch_id = $recurInvoice->branch_id; $branch = DB::table('branches')->where('id', $branch_id)->first(); $account_id = $recurInvoice->account_id; $account = DB::table('accounts')->where('id', $account_id)->first(); if (strtotime($branch->deadline) < strtotime('now')) { continue; } $invoice = Invoice::createNew($recurInvoice); $invoice->client_id = $recurInvoice->client_id; $invoice->recurring_invoice_id = $recurInvoice->id; $invoice->branch_id = $recurInvoice->branch_id; $invoiceNumber = $branch->invoice_number_counter; $invoice->invoice_number = $branch->invoice_number_counter; $invoice->amount = $recurInvoice->amount; $invoice->subtotal = $recurInvoice->subtotal; $invoice->balance = $recurInvoice->amount; $invoice->invoice_date = date_create()->format('Y-m-d'); $invoice->discount = $recurInvoice->discount; $invoice->po_number = $recurInvoice->po_number; $invoice->public_notes = $recurInvoice->public_notes; $invoice->terms = $recurInvoice->terms; // $invoice->tax_name = $recurInvoice->tax_name; // $invoice->tax_rate = $recurInvoice->tax_rate; $invoice->invoice_design_id = $recurInvoice->invoice_design_id; $invoice->account_name = $recurInvoice->account_name; $invoice->account_nit = $recurInvoice->account_nit; $invoice->branch_name = $branch->name; $invoice->address1 = $branch->address1; $invoice->address2 = $branch->address2; $invoice->phone = $branch->postal_code; $invoice->city = $branch->city; $invoice->state = $branch->state; $invoice->number_autho = $branch->number_autho; $invoice->deadline = $branch->deadline; $invoice->key_dosage = $branch->key_dosage; $invoice->client_nit = $recurInvoice->client_nit; $invoice->client_name = $recurInvoice->client_name; $invoice->activity_pri = $branch->activity_pri; $invoice->activity_sec1 = $branch->activity_sec1; $invoice->law = $branch->law; $invoice_dateCC = date("Ymd", strtotime($invoice->invoice_date)); $invoice_date_limitCC = date("d/m/Y", strtotime($branch->deadline)); require_once app_path() . '/includes/control_code.php'; $cod_control = codigoControl($invoice->invoice_number, $invoice->client_nit, $invoice_dateCC, $invoice->amount, $branch->number_autho, $branch->key_dosage); $invoice->control_code = $cod_control; $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, 'public/qr/' . $account->account_key . '_' . $branch->name . '_' . $invoice->invoice_number . '.png'); $input_file = 'public/qr/' . $account->account_key . '_' . $branch->name . '_' . $invoice->invoice_number . '.png'; $output_file = 'public/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'); if ($invoice->client->payment_terms) { $invoice->due_date = date_create()->modify($invoice->client->payment_terms . ' day')->format('Y-m-d'); } $invoice->save(); foreach ($recurInvoice->invoice_items as $recurItem) { $item = InvoiceItem::createNew($recurItem); $item->product_id = $recurItem->product_id; $item->qty = $recurItem->qty; $item->cost = $recurItem->cost; $item->notes = Utils::processVariables($recurItem->notes); $item->product_key = Utils::processVariables($recurItem->product_key); $item->tax_name = $recurItem->tax_name; $item->tax_rate = $recurItem->tax_rate; $invoice->invoice_items()->save($item); } foreach ($recurInvoice->invitations as $recurInvitation) { $invitation = Invitation::createNew($recurInvitation); $invitation->contact_id = $recurInvitation->contact_id; $invitation->invitation_key = str_random(RANDOM_KEY_LENGTH); $invoice->invitations()->save($invitation); } $this->mailer->sendInvoice($invoice); $recurInvoice->last_sent_date = Carbon::now()->toDateTimeString(); $recurInvoice->save(); } $this->info('Done'); }
<?php if (isset($_GET['data'])) { include "modules/engine/api.barcodeqr.php"; $data = trim($_GET['data']); $qr = new BarcodeQR(); $qr->text($data); $qr->draw(); }
public function executeViewhtml($request) { $folio = $this->getRequestParameter('folio'); $invoice = Doctrine::getTable('invoice')->getInvoiceByUser($folio); $this->invoiceObject = $invoice; $user_id = $this->getUser()->getGuardUser()->getId(); $invoiceData = unserialize(urldecode($invoice->getArr())); $this->invoiceData = $invoiceData; $this->comment = $invoice->getComment(); $xml = $invoice->getXml(); $xmlArr = simplexml_load_string(urldecode($xml)); $this->xmlData = $xmlArr; $dataSAT = $this->getSATData(urldecode($xml)); $this->dataSAT = $dataSAT; $barcodeFile = 'cfdiData/' . $user_id . '/barcode_' . $user_id . '-' . $folio . '.png'; if (!file_exists($barcodeFile)) { $qr = new BarcodeQR(); $dataQR = "?re=" . $invoiceData['Emisor']['rfc'] . '&rr=' . $invoiceData['Receptor']['rfc'] . '&tt=' . $invoiceData['total'] . '&id=' . $dataSAT['UUID']; // create URL QR code $qr->text($dataQR); // display new QR code image $qr->draw(150, "{$barcodeFile}"); } $this->barcodeFile = $barcodeFile; }
<title>Factura</title> <body> <?php use_helper('Number'); use_helper('Invoice'); ?> <?php $data = $invoiceData; $user_id = $sf_user->getGuardUser()->getId(); $barcodeFile = 'cfdiData/' . $user_id . '/barcode_' . $user_id . '-' . $data['folio'] . '.png'; if (!file_exists($barcodeFile)) { $qr = new BarcodeQR(); $dataQR = "?re=" . $data['Emisor']['rfc'] . '&rr=' . $data['Receptor']['rfc'] . '&tt=' . $data['total'] . '&id=' . $dataSAT['UUID']; // create URL QR code $qr->text($dataQR); // display new QR code image $qr->draw(150, "{$barcodeFile}"); } ?> <div align="center" style="width:950; border: 1px solid #000000; padding: 16px; margin: 10px;"> <table width="100%" border="0" align="center"> <tr> <td width="90%"> <table width="792" border="0"> <tr> <?php $logo = $sf_user->getGuardUser()->getProfile()->getLogo(); ?> <?php if ($logo != '') {