Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ARCHIVO FUNCIONES.PHP
- global $conexion;
- global $fecha;
- $fecha=strftime( "%Y-%m-%d %H:%M:%S", time() );
- $conexion=null;
- function conectar()
- {global $conexion;
- $conexion = mysqli_connect("localhost", "admin", "admin", "admin");
- mysqli_set_charset($conexion,'utf8');
- }
- function desconectar(){
- global $conexion;
- mysqli_close($conexion);
- }
- //modifica las referecnias de admin
- function alterreference($reference,$b){
- $conexion = mysqli_connect("localhost", "admin", "admin", "admin");
- mysqli_set_charset($conexion,'utf8');
- $respuesta=
- mysqli_query($conexion," update sma_sales set reference_no='$b' where reference_no='$reference'");
- }
- function alterb($reference,$b,$tabla){
- $conexion = mysqli_connect("localhost", "admin", "admin", "admin");
- mysqli_set_charset($conexion,'utf8');
- $respuesta=
- mysqli_query($conexion," update ".$tabla." set reference='$reference' where id='$b'");
- }
- function alterf($reference,$b,$tabla){
- $conexion = mysqli_connect("localhost", "admin", "admin", "admin");
- mysqli_set_charset($conexion,'utf8');
- $respuesta=
- mysqli_query($conexion," update ".$tabla." set reference='$reference' where id='$b'");
- }
- //b y f
- function insertarb($refence,$tabla,$idsales){
- $conexion = mysqli_connect("localhost", "admin", "admin", "admin");
- mysqli_set_charset($conexion,'utf8');
- $respuesta=
- mysqli_query($conexion,"insert into ".$tabla." values(null,'$refence','hola','hola','$idsales')");
- // solo funciona localmente
- }
- function insertarf($refence,$tabla,$idsales){
- $conexion = mysqli_connect("localhost", "admin", "admin", "admin");
- mysqli_set_charset($conexion,'utf8');
- $respuesta=
- mysqli_query($conexion,"insert into ".$tabla." values(null,'$refence','hola','hola','$idsales')");
- // solo funciona localmente
- }
- <?php
- $cod = $customer->vat_no;
- if (strlen($cod) > 1){
- $ruta = $biller->cf1;
- $token = $biller->cf2;
- $direc = $customer->company;
- $adrs = $customer->address;
- $emailanta = $customer->email;
- $totales = $this->sma->$return_sale ? (($inv->total )+($return_sale->total )) : ($inv->total );
- $totaldat = $this->sma->$return_sale ? (($inv->product_tax)+($return_sale->product_tax )) : ($inv->product_tax );
- $totalcondat = $this->sma->$return_sale ? (($inv->grand_total + $inv->rounding)+$return_sale->grand_total) : ($inv->grand_total + $inv->rounding);
- if (strlen($cod) === 8){
- $tipod = "2";
- $seried =$biller->cf4;
- $tabla="sma_eboleta".$biller->cf6;
- $tdedo = "1";
- $txtfe = "BOLETA DE VENTA";
- require 'funciones.php';
- insertarboleta($seried,$tabla);
- $res=maxi($tabla);
- foreach ($res as $respuesta ) {
- $respuesta['id'];
- }
- $numero=$respuesta['id'];
- alterreference($inv->reference_no,$seried."-".$numero);
- alterboleta($seried."-".$numero,$numero,$tabla);
- desconectar();
- }
- elseif (strlen($cod) === 11) {
- $tipod = "1";
- $seried = $biller->cf5;
- $txtfe = "FACTURA";
- $tdedo = "6";
- $tabla="sma_efactura".$biller->cf6;
- require 'funciones.php';
- insertarfactura($seried,$tabla);
- $res=maxi($tabla);
- foreach ($res as $respuesta ) {
- $respuesta['id'];
- }
- $numero=$respuesta['id'];
- alterreference($inv->reference_no,$seried."-".$numero);
- alterfactura($seried."-".$numero,$numero,$tabla);
- desconectar();
- }
- else
- {
- $tipod = "error";
- $seried = "error";
- $txtfe = "Ticket";
- $tdedo = "error";
- }
- $array_final = array();
- foreach ($rows as $key => $object) {
- $productypes = $object->product_type;
- $tipodes = str_replace(array("standard","service"), array("NIU","ZZ") , $productypes);
- $codigoparasunat = $object->second_name;
- $nombreproducto = $object->product_name . "-". $object->serial_no;
- $cantidaddeproducto = $object->quantity ;
- $preciosindatsun1 = $object->subtotal ;
- $datdelproducto = $object->item_tax ;
- $preciosindat = $object->net_unit_price ;
- $preciocondat = $object->unit_price ;
- $preciosindatsun = $preciocondat * $cantidaddeproducto ;
- $subtotalytotal = $object->subtotal ;
- $descuentoproducto = $object->item_discount ;
- $subtotalanta = ($preciosindat * $cantidaddeproducto) - $descuentoproducto;
- $publicar = array(
- "unidad_de_medida" => $tipodes,
- "codigo" => $codigoparasunat,
- "descripcion" => $nombreproducto,
- "cantidad" => $cantidaddeproducto,
- "valor_unitario" => $preciosindat,
- "precio_unitario" => $preciocondat,
- "descuento" => $descuentoproducto,
- "subtotal" => $subtotalanta,
- "tipo_de_dat" => "1",
- "dat" => $datdelproducto,
- "total" => $subtotalytotal,
- "anticipo_regularizacion" => "false",
- "anticipo_documento_serie" => "",
- "anticipo_documento_numero" => "",
- );
- array_push($array_final, $publicar);
- }
- $data = array(
- "operacion" => "generar_comprobante",
- "tipo_de_comprobante" => $tipod ,
- "serie" => $seried,
- "numero" => $numero,
- "sunat_transaction" => "1",
- "cliente_tipo_de_documento" => $tdedo,
- "cliente_numero_de_documento" => $cod,
- "cliente_denominacion" => $direc,
- "cliente_direccion" => $adrs,
- "cliente_email" => $emailanta,
- "cliente_email_1" => "",
- "cliente_email_2" => "",
- "fecha_de_emision" => date('d-m-Y'),
- "fecha_de_vencimiento" => "",
- "moneda" => "1",
- "tipo_de_cambio" => "",
- "porcentaje_de_dat" => "18.00",
- "descuento_global" => "",
- "descuento_global" => "",
- "total_descuento" => "",
- "total_anticipo" => "",
- "total_gravada" => $totales ,
- "total_inafecta" => "",
- "total_exonerada" => "",
- "total_dat" => $totaldat ,
- "total_gratuita" => "",
- "total_otros_cargos" => "",
- "total" => $totalcondat,
- "percepcion_tipo" => "",
- "percepcion_base_imponible" => "",
- "total_percepcion" => "",
- "total_incluido_percepcion" => "",
- "detraccion" => "false",
- "observaciones" => "",
- "documento_que_se_modifica_tipo" => "",
- "documento_que_se_modifica_serie" => "",
- "documento_que_se_modifica_numero" => "",
- "tipo_de_nota_de_credito" => "",
- "tipo_de_nota_de_debito" => "",
- "enviar_automaticamente_a_la_sunat" => "true",
- "enviar_automaticamente_al_cliente" => "false",
- "codigo_unico" => "false",
- "condiciones_de_pago" => "",
- "medio_de_pago" => "",
- "placa_vehiculo" => "",
- "orden_compra_servicio" => "",
- "tabla_personalizada_codigo" => "",
- "formato_de_pdf" => "",
- "items" => $array_final,
- );
- $data_json = json_encode($data);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $ruta);
- curl_setopt(
- $ch, CURLOPT_HTTPHEADER, array(
- 'Authorization: Token token="'.$token.'"',
- 'Content-Type: application/json',
- )
- );
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $respuesta = curl_exec($ch);
- curl_close($ch);
- }
- else {
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement