Ver Mensaje Individual
  #6 (permalink)  
Antiguo 20/08/2015, 15:47
Avatar de NSD
NSD
Colaborador
 
Fecha de Ingreso: mayo-2012
Ubicación: Somewhere
Mensajes: 1.332
Antigüedad: 12 años
Puntos: 320
Respuesta: while e includes

Código PHP:
Ver original
  1. <?php
  2.     // Datos de la factura.
  3.     $datos_factura = [
  4.         "<P0001>" => "A",
  5.         "<P0002>" => "COD 123",
  6.         "<P0003>" => "NUMERO",
  7.         "<P0004>" => "VALOR 1",
  8.         "<P0005>" => "VALOR 2",
  9.         "<P0006>" => "VALOR 3",
  10.         "<P0007>" => "VALOR 4",
  11.         "<P0008>" => "A",
  12.         "<P0009>" => "B",
  13.         "<P0010>" => "C",
  14.         "<P0011>" => "D",
  15.         "<P0012>" => "E",
  16.         "<P0013>" => "F",
  17.         "<P0014>" => "$ XXX",
  18.         "<P0015>" => "123456",
  19.         "<P0016>" => "123456",
  20.        
  21.         "<P6011>" => "1",
  22.         "<P6012>" => "2",
  23.         "<P6013>" => "aaa",
  24.         "<P6014>" => "$50",
  25.         "<P6015>" => "10",
  26.         "<P6016>" => "90",
  27.        
  28.         "<P6021>" => "",
  29.         "<P6022>" => "",
  30.         "<P6023>" => "",
  31.         "<P6024>" => "",
  32.         "<P6025>" => "",
  33.         "<P6026>" => "",
  34.        
  35.         "<P6031>" => "",
  36.         "<P6032>" => "",
  37.         "<P6033>" => "",
  38.         "<P6034>" => "",
  39.         "<P6035>" => "",
  40.         "<P6036>" => "",
  41.        
  42.         "<P6041>" => "",
  43.         "<P6042>" => "",
  44.         "<P6043>" => "",
  45.         "<P6044>" => "",
  46.         "<P6045>" => "",
  47.         "<P6046>" => "",
  48.        
  49.         "<P6051>" => "",
  50.         "<P6052>" => "",
  51.         "<P6053>" => "",
  52.         "<P6054>" => "",
  53.         "<P6055>" => "",
  54.         "<P6056>" => "",
  55.        
  56.         "<P6061>" => "",
  57.         "<P6062>" => "",
  58.         "<P6063>" => "",
  59.         "<P6064>" => "",
  60.         "<P6065>" => "",
  61.         "<P6066>" => "",
  62.        
  63.         "<P6071>" => "",
  64.         "<P6072>" => "",
  65.         "<P6073>" => "",
  66.         "<P6074>" => "",
  67.         "<P6075>" => "",
  68.         "<P6076>" => "",
  69.        
  70.         "<P6081>" => "",
  71.         "<P6082>" => "",
  72.         "<P6083>" => "",
  73.         "<P6084>" => "",
  74.         "<P6085>" => "",
  75.         "<P6086>" => "",
  76.        
  77.         "<P6091>" => "",
  78.         "<P6092>" => "",
  79.         "<P6093>" => "",
  80.         "<P6094>" => "",
  81.         "<P6095>" => "",
  82.         "<P6096>" => "",
  83.        
  84.         "<P6101>" => "",
  85.         "<P6102>" => "",
  86.         "<P6103>" => "",
  87.         "<P6104>" => "",
  88.         "<P6105>" => "",
  89.         "<P6106>" => "",
  90.        
  91.         "<P6111>" => "",
  92.         "<P6112>" => "",
  93.         "<P6113>" => "",
  94.         "<P6114>" => "",
  95.         "<P6115>" => "",
  96.         "<P6116>" => "",
  97.        
  98.         "<P6121>" => "",
  99.         "<P6122>" => "",
  100.         "<P6123>" => "",
  101.         "<P6124>" => "",
  102.         "<P6125>" => "",
  103.         "<P6126>" => "",
  104.        
  105.         "<P6131>" => "",
  106.         "<P6132>" => "",
  107.         "<P6133>" => "",
  108.         "<P6134>" => "",
  109.         "<P6135>" => "",
  110.         "<P6136>" => "",
  111.        
  112.         "<P1001>" => "$ XXX",
  113.         "<P1002>" => "$ XXX",
  114.         "<P1003>" => "$ XXX",
  115.         "<P1004>" => "$ XXX",
  116.         "<P1005>" => "$ XXX",
  117.         "<P1015>" => "123456789", // Barcode
  118.         "<P9001>" => "TITULO",
  119.         "<P9002>" => "DIRECCION",
  120.         "<P9003>" => "TELEFONO",
  121.         "<P9004>" => "SITIO WEB",
  122.         "<P9005>" => "CAMPO DE INTERES 1",
  123.         "<P9006>" => "CAMPO DE INTERES 2",
  124.         "<P9007>" => "CAMPO DE INTERES 3",
  125.         "<P9008>" => "CAMPO DE INTERES 4",
  126.         "<P9009>" => "CAMPO CLIENTE 1",
  127.         "<P9010>" => "CAMPO CLIENTE 2",
  128.         "<P9011>" => "CAMPO CLIENTE 3",
  129.         "<P9012>" => "CAMPO CLIENTE 4",
  130.         "<P9013>" => "CAMPO CLIENTE 5",
  131.         "<P9014>" => "CAMPO CLIENTE 6",
  132.         "<P9015>" => "CODIGO",
  133.         "<P9016>" => "CANTIDAD",
  134.         "<P9017>" => "DESCRIPCION",
  135.         "<P9018>" => "$/U",
  136.         "<P9019>" => "%DESC",
  137.         "<P9020>" => "Sub/T",
  138.         "<P9021>" => "OTRO CAMPO",
  139.         "<P9022>" => "OTRO CAMPO",
  140.         "<P9023>" => "OTRO CAMPO",
  141.         "<P9024>" => "OTRO CAMPO",
  142.         "<P9025>" => "OTRO CAMPO",
  143.         "<P9026>" => "TOTAL",
  144.         "<P9027>" => "CAE:",
  145.         "<P9028>" => "Vencimiento del CAE:",
  146.         "<P9029>" => "123456789",
  147.         "<P9030>" => "10/10/2010",
  148.         "<P9031>" => "RAZON SOCIAL",
  149.         "<P9032>" => "COMERCIO NOMBRE",
  150.     ];
  151.    
  152.     // Leer la factura.
  153.     $factura_pdf = file_get_contents("template-factura.pdf");
  154.    
  155.     // Completar y rellenar la factura.
  156.     foreach($datos_factura as $campo => $valor) {
  157.         $lenC = strlen($campo);
  158.         $lenV = strlen($valor);
  159.        
  160.         if($lenC != $lenV) {
  161.             if($lenC > $lenV)
  162.                 $valor .= str_repeat(" ", $lenC - $lenV);
  163.             else
  164.                 $campo .= str_repeat(" ", $lenV - $lenC);
  165.         }
  166.        
  167.         $factura_pdf = str_replace($campo, $valor, $factura_pdf);
  168.     }
  169.    
  170.     // Guardar la nueva factura.
  171.     file_put_contents("factura-nueva.pdf", $factura_pdf);
  172.    
  173.     echo "ok!";
__________________
Maratón de desafíos PHP Junio - Agosto 2015 en FDW | Reglamento - Desafios