src/Noahtech/Sistemas/InterjamaBundle/Handler/McMovimientoHandler.php line 43

Open in your IDE?
  1. <?php
  2. namespace Noahtech\Sistemas\InterjamaBundle\Handler;
  3. use Noahtech\Sistemas\InterjamaBundle\Entity\McMovimiento;
  4. use Noahtech\Sistemas\InterjamaBundle\Utils\Constants;
  5. use Noahtech\Sistemas\InterjamaBundle\Utils\EmailsMessages;
  6. use Noahtech\Sistemas\InterjamaBundle\Utils\Encrypt;
  7. use DateInterval;
  8. use DateTime;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Symfony\Component\DependencyInjection\ContainerInterface;
  11. use Symfony\Component\HttpKernel\Exception\HttpException;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Noahtech\Sistemas\InterjamaBundle\Utils\PDF;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Exception;
  16. use Afip;
  17. date_default_timezone_set('America/Argentina/Buenos_Aires');
  18. class McMovimientoHandler extends BaseHandler {
  19.     public function __construct(ContainerInterface $containerEntityManagerInterface $entityManager) {
  20.         $this->container $container;
  21.         $this->entityManager $entityManager;
  22.         $this->repository $entityManager->getRepository(McMovimiento::class);
  23.     }
  24.     public function search($offset$limit$sortField$sortDirection$searchParam) {
  25.         $lp $this->repository->search($offset$limit$sortField$sortDirection$searchParam);
  26.         $movimientos $this->toarray($lp->getListado(), 'movimiento');
  27.         $lp->setListado($movimientos);
  28.         return $lp;
  29.     }
  30.     public function updateFacturado(McMovimiento $movimiento) {
  31.         $movimiento->setFacturado(true);
  32.         return $this->update($movimiento$movimiento->getId());
  33.     }
  34.     public function saveFromAtencionPrecarga($monedaId$cajaId$tipoPago$total$usuario$precarga null) {
  35.         $caja $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McCajaHandler")->getCajaById((int)$cajaId);
  36.         $moneda $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McMonedaHandler")->getMonedaById((int)$monedaId);
  37.         $tipo 'Ingreso';
  38.         $tipoDetalle 'Atención trámite';
  39.         $modalidad $tipoPago;
  40.         $monto = (float)$total;
  41.         $detalle 'Movimiento generado por la atención de una precarga.';
  42.         if (!is_null($precarga->getId())) {
  43.             $movimiento $this->repository->findOneByPrecarga($precarga->getId());
  44.             if (!is_null($movimiento)) {
  45.                 $movimiento->setFechaActualizacion(new DateTime());
  46.                 //Hay que restar de monto final de la caja lo que se ingreso
  47.                 $deleteOperacionCaja $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McCajaHandler")->saveOperacionCaja($movimiento->getCaja(), 'Egreso'$movimiento->getMonto(), $movimiento->getModalidad(), $movimiento->getMoneda()->getId());
  48.             } else {
  49.                 $movimiento = new McMovimiento();
  50.                 $movimiento->setFechaCreacion(new DateTime());
  51.             }
  52.         } else {
  53.             $movimiento = new McMovimiento();
  54.             $movimiento->setFechaCreacion(new DateTime());
  55.         }
  56.         
  57.         $movimiento->setCaja($caja);
  58.         $movimiento->setUsuario($usuario);
  59.         $movimiento->setTipo($tipo);
  60.         $movimiento->setTipoDetalle($tipoDetalle);
  61.         $movimiento->setMonto($monto);
  62.         $movimiento->setMoneda($moneda);
  63.         $movimiento->setModalidad($modalidad);
  64.         $movimiento->setDetalle($detalle);
  65.         $movimiento->setPrecarga($precarga);
  66.         $movimiento $this->save($movimiento);
  67.         $operacionCaja $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McCajaHandler")->saveOperacionCaja($caja$tipo$monto$modalidad, (int)$monedaId);
  68.         return $movimiento;
  69.     }
  70.     public function getMovimientoFromRequest(Request $request$usuario$cajaIdint $id null) {
  71.         $tipo $request->request->get('tipo');
  72.         $tipoDetalle $request->request->get('tipo_detalle');              
  73.         $monto = (float)$request->request->get('monto');
  74.         $monedaId $request->request->get('moneda');
  75.         $modalidad $request->request->get('modalidad');
  76.         $detalle $request->request->get('detalle');
  77.         $devolucion $request->request->get('devolucion');
  78.         $caja $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McCajaHandler")->getCajaById((int)$cajaId);
  79.         $moneda $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McMonedaHandler")->getMonedaById((int)$monedaId);
  80.         $monedaNacional $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McMonedaHandler")->getMonedaById(1);
  81.         $choferId $request->request->get('chofer');
  82.         $empresaId $request->request->get('empresa');
  83.         $cotizacion $request->request->get('cotizacion');
  84.         $montoDevolucion = (!is_null($request->request->get('monto_devolucion'))) ? (float)$request->request->get('monto_devolucion') : null;
  85.         if (!is_null($choferId)) {
  86.             $chofer $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McChoferHandler")->getChoferById((int)$choferId);
  87.         } else {
  88.             $chofer null;
  89.         }
  90.         if (!is_null($empresaId)) {
  91.             $cliente $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McClienteHandler")->getClienteById((int)$empresaId);
  92.         } else {
  93.             $cliente null;
  94.         }
  95.         if (is_null($id)) {
  96.             if ($tipo != 'Cambio de divisas') {
  97.                 //Valido que si es un egreso de dinero no sea superior al monto final de la caja
  98.                 $movimiento = new McMovimiento();
  99.                 $movimiento->setFechaCreacion(new DateTime());
  100.                 $operacionCaja $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McCajaHandler")->saveOperacionCaja($caja$tipo$monto$modalidad, (int)$monedaId);
  101.                 $movimiento->setCaja($caja);
  102.                 $movimiento->setCliente($cliente);
  103.                 $movimiento->setChofer($chofer);
  104.                 $movimiento->setUsuario($usuario);
  105.                 $movimiento->setTipo($tipo);
  106.                 $movimiento->setTipoDetalle($tipoDetalle);
  107.                 $movimiento->setMonto($monto);
  108.                 $movimiento->setMoneda($moneda);
  109.                 $movimiento->setModalidad($modalidad);
  110.                 $movimiento->setDetalle($detalle);
  111.                 $movimiento->setDevolucion($devolucion);
  112.                 $movimiento->setMontoDevolucion($montoDevolucion);
  113.                 $movimiento $this->save($movimiento);
  114.                 if (!is_null($request->request->get('movimiento_devolver'))) {
  115.                     $movimientoEgreso $this->repository->findOneById((int)$request->request->get('movimiento_devolver'));
  116.                     $movimientoEgreso->setMontoDevolucion($montoDevolucion);
  117.                     $this->save($movimientoEgreso);
  118.                 }
  119.                 return $movimiento;
  120.             } else {
  121.                 //Validar el si el egreso es viable
  122.                 $operacionCaja $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McCajaHandler")->saveOperacionDivisasCaja($caja$tipo$tipoDetalle$monto$modalidad, (int)$monedaId$cotizacion);
  123.                 if ($tipoDetalle == 'Compra') {
  124.                     //Ingreso
  125.                     $movimientoIngreso = new McMovimiento();
  126.                     $movimientoIngreso->setFechaCreacion(new DateTime());
  127.                     $movimientoIngreso->setTipo('Ingreso');
  128.                     $movimientoIngreso->setCaja($caja);
  129.                     $movimientoIngreso->setCliente($cliente);
  130.                     $movimientoIngreso->setChofer($chofer);
  131.                     $movimientoIngreso->setUsuario($usuario);
  132.                     
  133.                     $movimientoIngreso->setTipoDetalle($tipoDetalle);
  134.                     $movimientoIngreso->setMonto($monto);
  135.                     $movimientoIngreso->setMoneda($moneda);
  136.                     $movimientoIngreso->setModalidad($modalidad);
  137.                     $movimientoIngreso->setDetalle($detalle);
  138.                     $movimientoIngreso->setDevolucion($devolucion);
  139.                     $movimientoIngreso $this->save($movimientoIngreso);
  140.                     //Egreso
  141.                     $movimientoEgreso = new McMovimiento();
  142.                     $movimientoEgreso->setFechaCreacion(new DateTime());
  143.                     $movimientoEgreso->setTipo('Egreso');
  144.                     $movimientoEgreso->setCaja($caja);
  145.                     $movimientoEgreso->setCliente($cliente);
  146.                     $movimientoEgreso->setChofer($chofer);
  147.                     $movimientoEgreso->setUsuario($usuario);
  148.                     $movimientoEgreso->setTipoDetalle($tipoDetalle);
  149.                     $movimientoEgreso->setMonto((float)$cotizacion);
  150.                     $movimientoEgreso->setMoneda($monedaNacional);
  151.                     $movimientoEgreso->setModalidad($modalidad);
  152.                     $movimientoEgreso->setDetalle($detalle);
  153.                     $movimientoEgreso->setDevolucion($devolucion);
  154.                     $movimientoEgreso $this->save($movimientoEgreso);
  155.                     return $movimientoEgreso;
  156.                 } else {
  157.                     //Ingreso
  158.                     $movimientoIngreso = new McMovimiento();
  159.                     $movimientoIngreso->setFechaCreacion(new DateTime());
  160.                     $movimientoIngreso->setTipo('Ingreso');
  161.                     $movimientoIngreso->setCaja($caja);
  162.                     $movimientoIngreso->setCliente($cliente);
  163.                     $movimientoIngreso->setChofer($chofer);
  164.                     $movimientoIngreso->setUsuario($usuario);
  165.                     
  166.                     $movimientoIngreso->setTipoDetalle($tipoDetalle);
  167.                     $movimientoIngreso->setMonto((float)$cotizacion);
  168.                     $movimientoIngreso->setMoneda($monedaNacional);
  169.                     $movimientoIngreso->setModalidad($modalidad);
  170.                     $movimientoIngreso->setDetalle($detalle);
  171.                     $movimientoIngreso->setDevolucion($devolucion);
  172.                     $movimientoIngreso $this->save($movimientoIngreso);
  173.                     //Egreso
  174.                     $movimientoEgreso = new McMovimiento();
  175.                     $movimientoEgreso->setFechaCreacion(new DateTime());
  176.                     $movimientoEgreso->setTipo('Egreso');
  177.                     $movimientoEgreso->setCaja($caja);
  178.                     $movimientoEgreso->setCliente($cliente);
  179.                     $movimientoEgreso->setChofer($chofer);
  180.                     $movimientoEgreso->setUsuario($usuario);
  181.                     $movimientoEgreso->setTipoDetalle($tipoDetalle);
  182.                     $movimientoEgreso->setMonto($monto);
  183.                     $movimientoEgreso->setMoneda($moneda);
  184.                     $movimientoEgreso->setModalidad($modalidad);
  185.                     $movimientoEgreso->setDetalle($detalle);
  186.                     $movimientoEgreso->setDevolucion($devolucion);
  187.                     $movimientoEgreso $this->save($movimientoEgreso);
  188.                     return $movimientoEgreso;
  189.                 }
  190.             }
  191.             
  192.         }
  193.            
  194.     }
  195.     public function save(McMovimiento $movimiento) {
  196.         $movimiento $this->repository->save($movimiento);
  197.         $movimiento $this->toarray($movimiento"movimiento");
  198.         return $movimiento;
  199.     }
  200.     public function update(McMovimiento $movimiento$id) {
  201.         $movimiento $this->repository->update($movimiento);     
  202.         $movimiento $this->toarray($movimiento"movimiento");
  203.         return $movimiento;
  204.     }
  205.     public function getById($id) {
  206.         $movimiento $this->repository->findOneById($id);
  207.         $movimiento $this->toarray($movimiento"movimiento");
  208.         return $movimiento;
  209.     }
  210.     public function getMovimientoById($id) {
  211.         return $this->repository->findOneById($id);
  212.     }
  213.     public function  numeroAddZero($nro) {
  214.         $numero "";
  215.         $nro1 strlen((string)$nro);
  216.         switch($nro1) {
  217.             case 1:
  218.                 $numero "000000" $nro;
  219.             break;
  220.             case 2:
  221.                 $numero "00000" $nro;
  222.             break;
  223.             case 3:
  224.                 $numero "0000" $nro;
  225.             break;
  226.             case 4:
  227.                 $numero "000" $nro;
  228.             break;
  229.             case 5:
  230.                 $numero "00" $nro;
  231.             break;
  232.             case 6:
  233.                 $numero "0" $nro;
  234.             break;
  235.             case 7:
  236.                 $numero $nro;          
  237.             break;
  238.         }
  239.         return $numero;
  240.       }
  241.     public function descargaReciboMovimientoPdf($id) {
  242.         $movimiento $this->getById($id);
  243.         $numero $this->numeroAddZero($movimiento['id']);        
  244.         $fecha date("d/m/Y H:m"strtotime($movimiento['fecha_creacion']));
  245.         $empresa = (isset($movimiento['cliente']['id'])) ? $movimiento['cliente']['razon_social'] : null;
  246.         $chofer = (isset($movimiento['chofer']['id'])) ? $movimiento['chofer']['nombre'] .' '$movimiento['chofer']['apellido'] : null;
  247.         $devolucion = ($movimiento['devolucion']) ? 'Si' 'No';
  248.         $montoDevolucion = (is_null($movimiento['monto_devolucion'])) ? $movimiento['monto_devolucion'];
  249.         // create new PDF document
  250.         $pdf = new PDF();       
  251.         $pdf->SetTitle("Comprobante Movimiento");
  252.         $pdf->SetSubject("Comprobante Movimiento");
  253.         $pdf->setFontSubsetting(true);
  254.         // set default header data
  255.         $pdf->SetHeaderData(PDF_HEADER_LOGOPDF_HEADER_LOGO_WIDTHPDF_HEADER_TITLEPDF_HEADER_STRING);
  256.         $pdf->SetFont('helvetica'''11''true);
  257.         $pdf->SetMargins(PDF_MARGIN_LEFTPDF_MARGIN_TOPPDF_MARGIN_RIGHT);
  258.         $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  259.         $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  260.         $pdf->setPrintFooter(false);
  261.         // set auto page breaks
  262.         $pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);
  263.         // set image scale factor
  264.         $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  265.         $pdf->AddPage('P''A4');        
  266.         $html = <<<EOD
  267.         <h1> Comprobante - Movimiento</h1>
  268.         <table table border="0.5">
  269.             <tr>
  270.                 <th style="background-color: grey;"> Código</th>
  271.                 <td><b> {$numero}</b></td>
  272.             </tr>
  273.             <tr>
  274.                 <th style="background-color: grey;"> Tipo</th>
  275.                 <td><b> {$movimiento['caja']['tipo']}</b></td>
  276.             </tr>
  277.             <tr>
  278.                 <th style="background-color: grey;"> Fecha</th>
  279.                 <td><b> {$fecha}</b></td>
  280.             </tr>
  281.         </table>
  282.         <br/>
  283.         <br/>
  284.         <br/>
  285.         <table border="0.5">
  286.             <tr>
  287.                 <th style="background-color: grey;"> Tipo</th>
  288.                 <td><b> {$movimiento['tipo']}</b></td>
  289.             </tr>
  290.             <tr>
  291.                 <th style="background-color: grey;"> Tipo detalle</th>
  292.                 <td><b> {$movimiento['tipo_detalle']}</b></td>
  293.             </tr>
  294.             <tr>
  295.                 <th style="background-color: grey;"> Moneda</th>
  296.                 <td><b> {$movimiento['moneda']['nombre']}</b></td>
  297.             </tr>
  298.             <tr>
  299.                 <th style="background-color: grey;"> Monto</th>
  300.                 <td><b> {$movimiento['monto']}</b></td>
  301.             </tr>
  302.             <tr>
  303.                 <th style="background-color: grey;"> Modalidad de pago</th>
  304.                 <td><b> {$movimiento['modalidad']}</b></td>
  305.             </tr>
  306.             <tr>
  307.                 <th style="background-color: grey;"> Detalle del movimiento</th>
  308.                 <td><b> {$movimiento['detalle']}</b></td>
  309.             </tr>
  310.             <tr>
  311.                 <th style="background-color: grey;"> Empresa</th>
  312.                 <td><b> {$empresa}</b></td>
  313.             </tr>
  314.             <tr>
  315.                 <th style="background-color: grey;"> Chofer</th>
  316.                 <td><b> {$chofer}</b></td>
  317.             </tr>
  318.             <tr>
  319.                 <th style="background-color: grey;"> Con devolución</th>
  320.                 <td><b> {$devolucion}</b></td>
  321.             </tr>
  322.             <tr>
  323.                 <th style="background-color: grey;"> Monto devolución</th>
  324.                 <td><b> {$montoDevolucion}</b></td>
  325.             </tr>
  326.         </table>
  327.         EOD;
  328.         $pdf->writeHTML($htmltruefalsefalsefalse'');
  329.         return new Response($pdf->Output("Comprobante""S"), 200, array(
  330.             'Content-Type' => 'application/pdf',
  331.             'Content-Disposition' => 'attachment; filename="Movimiento-Comprobante.pdf"'
  332.                 )
  333.         );
  334.     
  335.     }
  336.     public function descargaReciboPdf($id) {
  337.         $movimiento $this->getById((int)$id);
  338.         $fechaHoy date('d-m-Y');
  339.         $anio substr($movimiento['fecha_creacion'], 04);
  340.         $fechaHoy date('d-m-Y');
  341.         // create new PDF document
  342.         $pdf = new PDF();       
  343.         $pdf->SetTitle("Recibo Movimiento");
  344.         $pdf->SetSubject("Recibo Movimiento");
  345.         $pdf->setFontSubsetting(true);
  346.         // set default header data
  347.         $pdf->SetHeaderData(PDF_HEADER_LOGOPDF_HEADER_LOGO_WIDTHPDF_HEADER_TITLEPDF_HEADER_STRING);
  348.         $pdf->SetFont('helvetica'''9''true);
  349.         $pdf->SetMargins(555);
  350.         $pdf->SetHeaderMargin(0);
  351.         $pdf->SetFooterMargin(0);
  352.         $pdf->setPrintFooter(false);
  353.         // set auto page breaks
  354.         $pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);
  355.         // set image scale factor
  356.         $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  357.         $pdf->AddPage('P''A4');
  358.         $html = <<<EOD
  359.                 <div style="border: 0.5px solid black; text-align: center;">ORIGINAL</div>
  360.                 <div style="border: 0.5px solid black; float:left; clear:none;">
  361.                     <div style="text-align: center;">RECIBO</div><br>
  362.                     <strong style="text-align: left;">INTERJAMA S.R.L</strong><br>
  363.                     <strong style="text-align: left;">Raz&oacute;n Social: </strong>INTERJAMA S.R.L<br>
  364.                     <strong style="text-align: left;">Domicilio comercial: </strong>Alvear 495 Piso:2 Dpto:C - San Salvador de Jujuy - Jujuy<br>                    
  365.                     <strong style="text-align: left;">Condici&oacute;n frente al IVA: IVA Responsable Inscripto</strong><br>
  366.                     <strong style="text-align: right;">Fecha de Emisi&oacute;n: {$fechaHoy}</strong><br>
  367.                     <strong style="text-align: left;">CUIT: </strong>30714865044<br>
  368.                     <strong style="text-align: left;">Ingresos Brutos: </strong>A-1-55049<br>
  369.                     <strong style="text-align: left;">Fecha de Inicio de Actividad: </strong>01/07/2015
  370.                 </div>
  371.                 <div style="width: 100%; border: 0.5px solid black; margin-top: 1px;">
  372.                     <strong style="margin-left: 10px;">Preriodo Facturado Desde:</strong> {$fechaHoy} <strong style="margin-left: 90px;">Hasta:</strong> {$fechaHoy} <strong style="margin-left: 200px;">Fecha de Vto. para el pago:</strong> {$fechaHoy}
  373.                 </div>
  374.                 <div style="width: 100%; border: 0.5px solid black; margin-top: 1px;">
  375.                     <strong style="text-align: left;">CUIT:</strong> {$movimiento['cliente']['cuit']}<br>
  376.                     <strong style="text-align: left;">Appelidoy Nombre / Raz&oacute;n Social</strong> {$movimiento['cliente']['razon_social']}<br>
  377.                     <strong style="text-align: left;">Condici&oacute;n frente al IVA:</strong> {$movimiento['cliente']['condicion_iva']}<br>
  378.                     <strong style="text-align: left;">Condici&oacute;n de venta:</strong> {$movimiento['modalidad']}
  379.                 </div>
  380.                 <br/>
  381.                 <table border="0.5">
  382.                     <tr style="background-color: grey;">
  383.                         <th> Cantidad</th>
  384.                         <th> Movimiento</th>
  385.                         <th> Detalle</th>
  386.                         <th> Moneda</th>
  387.                         <th> Importe</th>
  388.                         <th> Subtotal</th>
  389.                     </tr>
  390.                     <tr>
  391.                         <td> 1,00</td>
  392.                         <td> Ingreso/Devolución</td>
  393.                         <td> {$movimiento['tipo_detalle']}</td>
  394.                         <td> {$movimiento['moneda']['nombre']}</td>
  395.                         <td> {$movimiento['monto_devolucion']}</td>
  396.                         <td> {$movimiento['monto_devolucion']}</td>
  397.                     </tr>
  398.                 </table>
  399.                 <br/>
  400.                 <br/>
  401.                 <table border="0.5">
  402.                     <tr>
  403.                         <th><strong>Subtotal: $</strong> <span style="margin-left: 60px;">{$movimiento['monto_devolucion']}</span></th>
  404.                         <th><strong>Importe Total: $</strong> <span style="margin-left: 60px;">{$movimiento['monto_devolucion']}</span></th>
  405.                     </tr>
  406.                 </table>
  407.             EOD;
  408.         $pdf->writeHTML($htmltruefalsefalsefalse'');
  409.         return new Response($pdf->Output("Recibo""S"), 200, array(
  410.             'Content-Type' => 'application/pdf',
  411.             'Content-Disposition' => 'attachment; filename="Movimiento-Recibo.pdf"'
  412.                 )
  413.         );
  414.     }
  415.     public function descargaFacturaAfipPdf($id$factura) {
  416.         $movimiento $this->getById($id);
  417.         if (is_null($movimiento['facturado']) || !$movimiento['facturado']) {
  418.             $movimientoObj $this->getMovimientoById((int)$id);
  419.             $fechaHoy date('d/m/Y');
  420.             $tipoFactura "A";
  421.             $afip = new Afip(array(
  422.                 'CUIT' => 27332574049,
  423.                 'cert' => 'tramite/cert',
  424.                 'key' => 'tramite/key'         
  425.             ));
  426.                  
  427.             if ($factura == 'A') {
  428.                 try {
  429.                     $last_voucher $afip->ElectronicBilling->GetLastVoucher(1,1);
  430.                 } catch (Exception $e) {
  431.                     return "Servicio de AFIP momentaneamente no disponible.";
  432.                 }              
  433.             } elseif ($factura == 'B') {
  434.                 try {
  435.                     $last_voucher $afip->ElectronicBilling->GetLastVoucher(1,6);
  436.                 } catch (Exception $e) {
  437.                     return "Servicio de AFIP momentaneamente no disponible.";
  438.                 }
  439.             }        
  440.             $valfac $last_voucher 1;
  441.             $nroComprobante $this->numeroAddZero($valfac);
  442.             $ptoVta "0001";    
  443.             $neto round($tramite['importe'] / 1.212);
  444.             $iva =  round($neto 0.212);
  445.             //Se arma factura A
  446.             $data = array(
  447.                 'CantReg'     => 1,  // Cantidad de comprobantes a registrar
  448.                 'PtoVta'     => 1,  // Punto de venta            
  449.                 'Concepto'     => 1,  // Concepto del Comprobante: (1)Productos, (2)Servicios, (3)Productos y Servicios
  450.                 'DocTipo'     => 80// Tipo de documento del comprador (99 consumidor final, ver tipos disponibles)
  451.                 'DocNro'     => $movimiento['cliente']['cuit'],  // Número de documento del comprador (0 consumidor final)
  452.                 'CbteDesde' => $valfac,  // Número de comprobante o numero del primer comprobante en caso de ser mas de uno
  453.                 'CbteHasta' => $valfac,  // Número de comprobante o numero del último comprobante en caso de ser mas de uno
  454.                 'CbteFch'     => intval(date('Ymd')), // (Opcional) Fecha del comprobante (yyyymmdd) o fecha actual si es nulo
  455.                 'ImpTotal'     => $movimiento['monto'], // Importe total del comprobante
  456.                 'ImpTotConc' => 0,   // Importe neto no gravado
  457.                 'ImpNeto'     => $neto// Importe neto gravado
  458.                 'ImpOpEx'     => 0,   // Importe exento de IVA
  459.                 'ImpIVA'     => $iva,  //Importe total de IVA
  460.                 'ImpTrib'     => 0,   //Importe total de tributos
  461.                 'MonId'     => 'PES'//Tipo de moneda usada en el comprobante (ver tipos disponibles)('PES' para pesos argentinos) 
  462.                 'MonCotiz'     => 1,     // Cotización de la moneda usada (1 para pesos argentinos)
  463.                 'Iva'         => array( // (Opcional) Alícuotas asociadas al comprobante
  464.                 array(
  465.                     'Id'         => 5// Id del tipo de IVA (5 para 21%)(ver tipos disponibles) 
  466.                     'BaseImp'     => $neto// Base imponible
  467.                     'Importe'     => $iva // Importe 
  468.                 )
  469.                 ),
  470.             );
  471.             if ($factura == 'A') {
  472.                 $data['CbteTipo'] = 1;
  473.                 $codigo 'Código 01';
  474.             } elseif ($factura == 'B') {
  475.                 $data['CbteTipo'] = 6;
  476.                 $tipoFactura "B";
  477.                 $codigo 'Código 06';
  478.             } else {
  479.                 //Se arma factura E de exportación
  480.             }       
  481.             
  482.             try {
  483.                 $res $afip->ElectronicBilling->CreateVoucher($data);
  484.                 $this->container->get("Noahtech\Sistemas\InterjamaBundle\Handler\McFacturaHandler")->saveFacturaMovimiento($movimientoObj$tipoFactura$res$nroComprobante);
  485.                 $this->updateFacturado($movimientoObj);             
  486.             } catch (Exception $e) {
  487.                 return $e->getMessage();
  488.             }          
  489.     
  490.             $res['CAE']; //CAE asignado el comprobante
  491.             $res['CAEFchVto']; //Fecha de vencimiento del CAE (yyyy-mm-dd)
  492.             // Fin de sección de factura de AFIP
  493.         
  494.             //Creacion del PDF
  495.             // create new PDF document
  496.             $pdf = new PDF();    
  497.             $pdf->SetTitle("Movimiento");
  498.             $pdf->SetSubject("Movimiento");
  499.             $pdf->setFontSubsetting(true);
  500.             // set default header data
  501.             $pdf->SetHeaderData(PDF_HEADER_LOGOPDF_HEADER_LOGO_WIDTHPDF_HEADER_TITLEPDF_HEADER_STRING);
  502.             $pdf->SetFont('helvetica'''9''true);
  503.             $pdf->SetMargins(555);
  504.             $pdf->SetHeaderMargin(0);
  505.             $pdf->SetFooterMargin(0);
  506.             $pdf->SetPrintFooter(false);
  507.         
  508.             // set auto page breaks
  509.             $pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);
  510.         
  511.             // set image scale factor
  512.             $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  513.         
  514.             $pdf->AddPage('P''A4');
  515.             // Datos de la empresa emisora de la factura
  516.             $html = <<<EOD
  517.                 <table style="width: 100%; border-top: 1px solid black;border-left: 1px solid black;border-right: 1px solid black;">
  518.                     <tr>
  519.                         <th style="text-align: left">
  520.                         <span></span><br>
  521.                             <img src="app/images/interjama-logo.jpeg" alt="Interjama" width="300" height="100" />
  522.                         </th>
  523.                         <th style="text-align: center">
  524.                             <span style="font-size: 30px; font-weight: bold;">{$tipoFactura}</span><br>
  525.                             <span style="font-size: 10px;">{$codigo}</span>
  526.                         </th>
  527.                         <th style="text-align: center">
  528.                             <span></span><br>
  529.                             <span style="font-size: 12px; font-weight: bold;">Factura</span><br>
  530.                             <span style="font-size: 12px; font-weight: bold;">Nº {$nroComprobante}</span><br>
  531.                             <span style="font-size: 12px; font-weight: bold;">{$fechaHoy}</span>
  532.                         </th>
  533.                     </tr>
  534.                 </table>
  535.                 <table style="width: 100%; border-bottom: 1px solid black;border-left: 1px solid black;border-right: 1px solid black;">
  536.                     <tr>
  537.                         <th style="text-align: left; border-right: 1px solid black">
  538.                         <strong style="text-align: left;">Raz&oacute;n Social: </strong>INTERJAMA S.R.L.<br>
  539.                         <strong style="text-align: left;">Punto de venta: {$ptoVta}  Comp. Nro: {$nroComprobante}</strong><br>
  540.                         <strong style="text-align: left;">Domicilio comercial: </strong>Alvear 495 Piso:2 Dpto:C - San Salvador de Jujuy - Jujuy<br>
  541.                         <strong style="text-align: left;">Sitio web: </strong>www.interjama.com<br>
  542.                         </th>
  543.                         <th style="text-align: left">
  544.                         <strong style="text-align: left;">Condici&oacute;n frente al IVA: IVA Responsable Inscripto</strong><br>
  545.                         <strong style="text-align: left;">CUIT: </strong>30714865044<br>
  546.                         <strong style="text-align: left;">Ingresos Brutos: </strong>A-1-55049<br>
  547.                         <strong style="text-align: left;">Fecha de Inicio de Actividad: </strong>01/07/2015
  548.                         </th>
  549.                     </tr>
  550.                 </table>
  551.                 <br/>
  552.                 <div style="width: 100%; border: 0.5px solid black; margin-top: 2px;">
  553.                     <strong style="margin-left: 10px;">Preriodo Facturado Desde:</strong> {$fechaHoy} <strong style="margin-left: 90px;">Hasta:</strong> {$fechaHoy} <strong style="margin-left: 200px;">Fecha de Vto. para el pago:</strong> {$fechaHoy}
  554.                 </div>
  555.                 <div style="width: 100%; border: 0.5px solid black; margin-top: 2px;">
  556.                     <strong style="text-align: left;">CUIT:</strong> {$movimiento['cliente']['cuit']}<br>
  557.                     <strong style="text-align: left;">Appelidoy Nombre / Raz&oacute;n Social</strong> {$movimiento['cliente']['razon_social']}<br>
  558.                     <strong style="text-align: left;">Condici&oacute;n frente al IVA:</strong> {$movimiento['cliente']['condicion_iva']}<br>                
  559.                     <strong style="text-align: left;">Condici&oacute;n de venta:</strong> Contado
  560.                 </div>
  561.                 <div style="width: 100%; border: 0.5px solid black; margin-top: 2px;">
  562.                     <strong style="margin-left: 10px;">Referencia Comercial:</strong> CONTROL DE PESAJE
  563.                 </div>
  564.                 <br/>
  565.                 <table border="0.5">
  566.                     <tr style="background-color: grey;">
  567.                         <th>Cantidad</th>
  568.                         <th>Producto / Servicio</th>
  569.                         <th>U. Medida</th>
  570.                         <th>Precio Uni.</th>
  571.                         <th>% Bonif.</th>
  572.                         <th>Imp. Bonif.</th>
  573.                         <th>Subtotal</th>
  574.                     </tr>
  575.                     <tr>
  576.                         <td> 1,00</td>
  577.                         <td> Imngreso-devolución</td>
  578.                         <td> Otras unidades</td>
  579.                         <td> {$movimiento['monto_devolucion']}</td>
  580.                         <td> 0,00</td>
  581.                         <td> 0,00</td>
  582.                         <td> {$movimiento['monto_devolucion']}</td>
  583.                     </tr>
  584.                 </table>
  585.                 <br/>
  586.                 <br/>
  587.                 <table border="0.5">
  588.                     <tr>
  589.                         <th>
  590.                             <strong>Subtotal: $</strong> <span style="margin-left: 60px;">{$movimiento['monto_devolucion']}</span>
  591.                         </th>
  592.                         <th>
  593.                             <strong>Importe Otros Tributos: $</strong> <span style="margin-left: 84px;">0,00</span>
  594.                         </th>
  595.                         <th>
  596.                             <strong>Importe Total: $</strong> <span style="margin-left: 60px;">{$movimiento['monto_devolucion']}</span>
  597.                         </th>
  598.                     </tr>
  599.                 </table>
  600.                 <div style="width: 100%; border: 0.5px solid black; margin-top: 2px;">
  601.                     <span style="margin-left: 10px; font-style: italic;">"SERVICIOS ALTERNATIVOS EN COMERCIO EXTERIOR - SEGURIDAD PRIVADA - OBRAS DE INGENIERIA CIVIL-"</span>
  602.                 </div>
  603.                 <div style="float:right; margin-top: 2px; text-align: right;">
  604.                     <strong>CAE Nº:</strong> {$res['CAE']}<br>
  605.                     <strong>Fecha Vto. de CAE:</strong> {$res['CAEFchVto']}
  606.                 </div>
  607.                 <br/>
  608.                 <table style="width: 100%;">
  609.                     <tr>
  610.                         <th>
  611.                             <img src="app/images/qr.png" alt="Código QR" width="50" height="50"/>
  612.                         </th>
  613.                         <th>
  614.                             <img src="app/images/afip-logo.png" alt="Código QR" width="50" height="15"/><br>
  615.                             <span><b>Comprobante Autorizado</b></span>
  616.                         </th>
  617.                         <th>
  618.                         </th>
  619.                         <th>
  620.                         </th>
  621.                     </tr>
  622.                 </table>
  623.             EOD;
  624.         
  625.             $pdf->writeHTML($htmltruefalsefalsefalse'');
  626.             return new Response($pdf->Output("Tramite-Factura""S"), 200, array(
  627.                 'Content-Type' => 'application/pdf',
  628.                 'Content-Disposition' => 'attachment; filename="Movimiento-Recibo.pdf"'
  629.                     )
  630.             );
  631.         } else {
  632.             throw new HttpException(409"El movimiento ya se encuentra facturado.");  
  633.         }
  634.     }
  635.     public function getAllMovimientosByCaja($cajaId) {
  636.         $movimientos $this->repository->getAllMovimientosByCaja($cajaId);
  637.         return $this->toarray($movimientos'movimiento');
  638.     }
  639. }