Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.93 KB | None | 0 0
  1. ARCHIVO FUNCIONES.PHP
  2.  
  3. global $conexion;
  4. global $fecha;
  5. $fecha=strftime( "%Y-%m-%d %H:%M:%S", time() );
  6.  
  7. $conexion=null;
  8. function conectar()
  9. {global $conexion;
  10. $conexion = mysqli_connect("localhost", "admin", "admin", "admin");
  11. mysqli_set_charset($conexion,'utf8');
  12. }
  13. function desconectar(){
  14. global $conexion;
  15. mysqli_close($conexion);
  16. }
  17.  
  18. //modifica las referecnias de admin
  19.  
  20.  
  21. function alterreference($reference,$b){
  22. $conexion = mysqli_connect("localhost", "admin", "admin", "admin");
  23. mysqli_set_charset($conexion,'utf8');
  24. $respuesta=
  25. mysqli_query($conexion," update sma_sales set reference_no='$b' where reference_no='$reference'");
  26.  
  27.  
  28.  
  29. }
  30. function alterb($reference,$b,$tabla){
  31. $conexion = mysqli_connect("localhost", "admin", "admin", "admin");
  32. mysqli_set_charset($conexion,'utf8');
  33. $respuesta=
  34. mysqli_query($conexion," update ".$tabla." set reference='$reference' where id='$b'");
  35.  
  36.  
  37.  
  38. }
  39. function alterf($reference,$b,$tabla){
  40. $conexion = mysqli_connect("localhost", "admin", "admin", "admin");
  41. mysqli_set_charset($conexion,'utf8');
  42. $respuesta=
  43. mysqli_query($conexion," update ".$tabla." set reference='$reference' where id='$b'");
  44.  
  45.  
  46.  
  47. }
  48. //b y f
  49.  
  50. function insertarb($refence,$tabla,$idsales){
  51.  
  52. $conexion = mysqli_connect("localhost", "admin", "admin", "admin");
  53. mysqli_set_charset($conexion,'utf8');
  54. $respuesta=
  55. mysqli_query($conexion,"insert into ".$tabla." values(null,'$refence','hola','hola','$idsales')");
  56. // solo funciona localmente
  57.  
  58. }
  59.  
  60.  
  61.  
  62.  
  63. function insertarf($refence,$tabla,$idsales){
  64. $conexion = mysqli_connect("localhost", "admin", "admin", "admin");
  65. mysqli_set_charset($conexion,'utf8');
  66. $respuesta=
  67. mysqli_query($conexion,"insert into ".$tabla." values(null,'$refence','hola','hola','$idsales')");
  68. // solo funciona localmente
  69.  
  70. }
  71.  
  72. <?php
  73.  
  74. $cod = $customer->vat_no;
  75.  
  76.  
  77.  
  78. if (strlen($cod) > 1){
  79.  
  80. $ruta = $biller->cf1;
  81.  
  82. $token = $biller->cf2;
  83.  
  84. $direc = $customer->company;
  85. $adrs = $customer->address;
  86. $emailanta = $customer->email;
  87. $totales = $this->sma->$return_sale ? (($inv->total )+($return_sale->total )) : ($inv->total );
  88. $totaldat = $this->sma->$return_sale ? (($inv->product_tax)+($return_sale->product_tax )) : ($inv->product_tax );
  89. $totalcondat = $this->sma->$return_sale ? (($inv->grand_total + $inv->rounding)+$return_sale->grand_total) : ($inv->grand_total + $inv->rounding);
  90.  
  91.  
  92.  
  93. if (strlen($cod) === 8){
  94. $tipod = "2";
  95. $seried =$biller->cf4;
  96. $tabla="sma_eboleta".$biller->cf6;
  97. $tdedo = "1";
  98. $txtfe = "BOLETA DE VENTA";
  99.  
  100. require 'funciones.php';
  101.  
  102. insertarboleta($seried,$tabla);
  103. $res=maxi($tabla);
  104. foreach ($res as $respuesta ) {
  105. $respuesta['id'];
  106. }
  107. $numero=$respuesta['id'];
  108. alterreference($inv->reference_no,$seried."-".$numero);
  109. alterboleta($seried."-".$numero,$numero,$tabla);
  110. desconectar();
  111.  
  112. }
  113. elseif (strlen($cod) === 11) {
  114. $tipod = "1";
  115. $seried = $biller->cf5;
  116. $txtfe = "FACTURA";
  117. $tdedo = "6";
  118. $tabla="sma_efactura".$biller->cf6;
  119.  
  120. require 'funciones.php';
  121.  
  122. insertarfactura($seried,$tabla);
  123. $res=maxi($tabla);
  124. foreach ($res as $respuesta ) {
  125. $respuesta['id'];
  126. }
  127. $numero=$respuesta['id'];
  128. alterreference($inv->reference_no,$seried."-".$numero);
  129.  
  130. alterfactura($seried."-".$numero,$numero,$tabla);
  131.  
  132. desconectar();
  133. }
  134. else
  135. {
  136. $tipod = "error";
  137. $seried = "error";
  138. $txtfe = "Ticket";
  139. $tdedo = "error";
  140. }
  141.  
  142.  
  143.  
  144.  
  145.  
  146. $array_final = array();
  147.  
  148. foreach ($rows as $key => $object) {
  149.  
  150. $productypes = $object->product_type;
  151. $tipodes = str_replace(array("standard","service"), array("NIU","ZZ") , $productypes);
  152. $codigoparasunat = $object->second_name;
  153. $nombreproducto = $object->product_name . "-". $object->serial_no;
  154. $cantidaddeproducto = $object->quantity ;
  155. $preciosindatsun1 = $object->subtotal ;
  156. $datdelproducto = $object->item_tax ;
  157. $preciosindat = $object->net_unit_price ;
  158. $preciocondat = $object->unit_price ;
  159. $preciosindatsun = $preciocondat * $cantidaddeproducto ;
  160. $subtotalytotal = $object->subtotal ;
  161. $descuentoproducto = $object->item_discount ;
  162. $subtotalanta = ($preciosindat * $cantidaddeproducto) - $descuentoproducto;
  163.  
  164. $publicar = array(
  165.  
  166. "unidad_de_medida" => $tipodes,
  167. "codigo" => $codigoparasunat,
  168. "descripcion" => $nombreproducto,
  169. "cantidad" => $cantidaddeproducto,
  170. "valor_unitario" => $preciosindat,
  171. "precio_unitario" => $preciocondat,
  172. "descuento" => $descuentoproducto,
  173. "subtotal" => $subtotalanta,
  174. "tipo_de_dat" => "1",
  175. "dat" => $datdelproducto,
  176. "total" => $subtotalytotal,
  177. "anticipo_regularizacion" => "false",
  178. "anticipo_documento_serie" => "",
  179. "anticipo_documento_numero" => "",
  180.  
  181. );
  182.  
  183. array_push($array_final, $publicar);
  184. }
  185.  
  186.  
  187. $data = array(
  188. "operacion" => "generar_comprobante",
  189. "tipo_de_comprobante" => $tipod ,
  190. "serie" => $seried,
  191. "numero" => $numero,
  192. "sunat_transaction" => "1",
  193. "cliente_tipo_de_documento" => $tdedo,
  194. "cliente_numero_de_documento" => $cod,
  195. "cliente_denominacion" => $direc,
  196. "cliente_direccion" => $adrs,
  197. "cliente_email" => $emailanta,
  198. "cliente_email_1" => "",
  199. "cliente_email_2" => "",
  200. "fecha_de_emision" => date('d-m-Y'),
  201. "fecha_de_vencimiento" => "",
  202. "moneda" => "1",
  203. "tipo_de_cambio" => "",
  204. "porcentaje_de_dat" => "18.00",
  205. "descuento_global" => "",
  206. "descuento_global" => "",
  207. "total_descuento" => "",
  208. "total_anticipo" => "",
  209. "total_gravada" => $totales ,
  210. "total_inafecta" => "",
  211. "total_exonerada" => "",
  212. "total_dat" => $totaldat ,
  213. "total_gratuita" => "",
  214. "total_otros_cargos" => "",
  215. "total" => $totalcondat,
  216. "percepcion_tipo" => "",
  217. "percepcion_base_imponible" => "",
  218. "total_percepcion" => "",
  219. "total_incluido_percepcion" => "",
  220. "detraccion" => "false",
  221. "observaciones" => "",
  222. "documento_que_se_modifica_tipo" => "",
  223. "documento_que_se_modifica_serie" => "",
  224. "documento_que_se_modifica_numero" => "",
  225. "tipo_de_nota_de_credito" => "",
  226. "tipo_de_nota_de_debito" => "",
  227. "enviar_automaticamente_a_la_sunat" => "true",
  228. "enviar_automaticamente_al_cliente" => "false",
  229. "codigo_unico" => "false",
  230. "condiciones_de_pago" => "",
  231. "medio_de_pago" => "",
  232. "placa_vehiculo" => "",
  233. "orden_compra_servicio" => "",
  234. "tabla_personalizada_codigo" => "",
  235. "formato_de_pdf" => "",
  236. "items" => $array_final,
  237. );
  238.  
  239. $data_json = json_encode($data);
  240.  
  241. $ch = curl_init();
  242. curl_setopt($ch, CURLOPT_URL, $ruta);
  243. curl_setopt(
  244. $ch, CURLOPT_HTTPHEADER, array(
  245. 'Authorization: Token token="'.$token.'"',
  246. 'Content-Type: application/json',
  247. )
  248. );
  249. curl_setopt($ch, CURLOPT_POST, 1);
  250. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  251. curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
  252. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  253. $respuesta = curl_exec($ch);
  254. curl_close($ch);
  255.  
  256.  
  257.  
  258. }
  259.  
  260. else {
  261.  
  262.  
  263. }
  264.  
  265.  
  266.  
  267. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement