AuthUser(); include_once(DOC_ROOT.'/pdf/dompdf_config.inc.php'); if(isset($_GET['cancelarId'])){ $pedidoId = intval($_GET['cancelarId']); $mode = 'cancelar'; }elseif(isset($_GET['show-pdf'])){ $pedidoId = intval($_GET['show-pdf']); $mode = 'show'; }elseif(isset($_GET['id'])){ $pedidoId = intval($_GET['id']); $mode = 'send'; }else{ header('Location: '.WEB_ROOT); exit; } if(WEB_ROOT == 'http://novomoda.ddns.net/html') $enProduccion = false; else $enProduccion = true; $pedido->setPedidoId($pedidoId); $info = $pedido->Info(); $rfc->setRfcId(1); $infE = $util->EncodeRow($rfc->Info()); $direccion = $infE['calle']; if($infE['noExt'] != '') $direccion .= ' No. Ext. '.$infE['noExt']; if($infE['noInt'] != '') $direccion .= ', No. Int. '.$infE['noInt']; if($infE['colonia'] != '') $direccion .= ', Col. '.$infE['colonia']; if($infE['localidad'] != '') $direccion .= ', '.$infE['localidad']; if($infE['ciudad'] != '') $direccion .= ', '.$infE['ciudad']; if($infE['municipio'] != '') $direccion .= ', '.$infE['municipio']; if($infE['estado'] != '') $direccion .= ', '.$infE['estado']; if($infE['codigoPostal'] != '') $direccion .= 'C.P. '.$infE['codigoPostal']; $infE['direccion'] = $direccion; $proveedor->setProveedorId($info['proveedorId']); $infPv = $util->EncodeRow($proveedor->Info()); $fecha = date('d-m-Y',strtotime($info['fecha'])); $fecha = $util->FormatDateDMMMY($fecha); $info['fecha'] = $fecha; $fechaEntrega = date('d-m-Y',strtotime($info['fechaEntrega'])); $info['fechaEntrega'] = $util->FormatDateDMMMY($fechaEntrega); if($info['fechaEntregaF']){ $fechaEntregaF = date('d-m-Y',strtotime($info['fechaEntregaF'])); $info['fechaEntrega'] .= ' al '.$util->FormatDateDMMMY($fechaEntregaF); } if($info['metodoCompra'] == 'conIva') $info['metodoCompra'] = 'IVA Incluido'; else $info['metodoCompra'] = 'IVA No Incluido'; //Distribuciones $resProducts = $pedido->GetProdsDistribucion(); $dist = array(); $sucIds = array(); foreach($resProducts as $res){ $productoId = $res['productoId']; $sucursalId = $res['sucursalId']; $pedido->setProductoId($productoId); $infPP['status'] = $pedido->GetInfoStatusProd(); if($infPP['status'] == 'Sugerencia'){ $pedido->setSucursalId($sucursalId); $infPS['cantidad'] = $pedido->GetInfoCantProdSug(); $res['cantidad'] = $infPS['cantidad']; } if($res['cantidad'] == 0) continue; $dist[$productoId][$sucursalId]['cantidad'] = $res['cantidad']; $dist[$productoId][$sucursalId]['pedDistId'] = $res['pedDistId']; if(!in_array($sucursalId, $sucIds)) $sucIds[] = $sucursalId; } //Sucursales $sucursals = array(); $tiendas = array(); foreach($sucIds as $sucursalId){ $res['sucursalId'] = $sucursalId; $sucursal->setSucursalId($sucursalId); $infS = $sucursal->Info(); $res['noSuc'] = $infS['noSuc']; $tiendas[] = $res; } if(count($tiendas) > 0){ $tiendas = $util->orderMultiDimensionalArray($tiendas, 'noSuc'); $sucursals[] = $tiendas; } //Productos $resProducts = $pedido->GetProductos(); $sugerencias = 0; $subtotalP = 0; $products = array(); foreach($resProducts as $card){ $prodCatId = $card['prodCatId']; $prodSubcatId = $card['prodSubcatId']; $productoId = $card['productoId']; $card['productoId'] = $productoId; $card['prodCatId'] = $prodCatId; $card['prodSubcatId'] = $prodSubcatId; $prodCat->setProdCatId($prodCatId); $card['departamento'] = $prodCat->GetNameById(); $prodSubcat->setProdSubcatId($prodSubcatId); $card['linea'] = $prodSubcat->GetNameById(); $producto->setProductoId($productoId); $infP = $producto->Info(); $card['modelo'] = $infP['modelo'].' '.$infP['descripcion']; $card['imagen'] = $infP['imagen']; $card['codigoBarra'] = $infP['codigoBarra']; $card['precioVentaIva'] = $infP['precioVentaIva']; $card['atributos'] = $producto->GetAtributosAll(); $card['cantidad'] = $card['totalLote'] * $card['cantLotes']; $totalP = $card['costo'] * $card['cantidad']; $card['total'] = number_format($totalP,2); $subtotalP += $totalP; //PROPORCIONES //Colores $producto->setProductoId($productoId); $resColores = $producto->GetColores(); $colores = array(); foreach($resColores as $res){ $colorId = $res['colorId']; $pedido->setColorId($colorId); $pedido->setProductoId($productoId); $cantidad = $pedido->GetProporcionByColor(); $proporcionC[$colorId] = $cantidad; $res['cantidad'] = $cantidad; $atribVal->setAtribValId($res['colorId']); $res['nombre'] = $atribVal->GetNameById(); $colores[$colorId] = $res; }//foreach //Tallas $producto->setProductoId($productoId); $resTallas = $producto->GetTallas(); $tallas = array(); foreach($resTallas as $res){ $tallaId = $res['tallaId']; $pedido->setTallaId($tallaId); $pedido->setProductoId($productoId); $cantidad = $pedido->GetProporcionByTalla(); $proporcionT[$tallaId] = $cantidad; $res['cantidad'] = $cantidad; $atribVal->setAtribValId($tallaId); $res['nombre'] = $atribVal->GetNameById(); $tallas[$tallaId] = $res; }//foreach //Obtenemos Totales $totales = array(); $subtotales = array(); foreach($tallas as $idT => $t){ $cantT = $t['cantidad']; $total = 0; foreach($colores as $idC => $c){ $cantC = $c['cantidad']; $subtotal = $cantC * $cantT; $total += $subtotal; $subtotales[$idT][$idC] = $subtotal; } $totales[$idT] = $total; }//foreach $card['tallas'] = $tallas; $card['colores'] = $colores; $card['totales'] = $totales; $card['subtotales'] = $subtotales; $card['proporcionT'] = $proporcionT; $card['proporcionC'] = $proporcionC; //FIN PROPORCIONES if($card['status'] == 'Sugerencia') $sugerencias++; $products[] = $card; }//foreach $info['subtotal'] = number_format($info['subtotal'],2); $info['iva'] = number_format($info['iva'],2); $info['total'] = number_format($info['total'],2); //HTML - PDF $html .= '

'.strtoupper($infE['razonSocial']).'
'.$infE['direccion'].'


No. PEDIDO METODO COMPRA FECHA DE SOLICITUD FECHA DE ENTREGA
'.$info['noPedido'].' '.$info['metodoCompra'].' '.$info['fecha'].' '.$info['fechaEntrega'].'
'; //DATOS DEL PROVEEDOR $html .= '
DATOS DEL PROVEEDOR
Razón Social '.$infPv['nombre'].' Calle '.$infPv['calle'].'
RFC '.$infPv['rfc'].' Colonia '.$infPv['colonia'].'
Teléfonos '.$infPv['phone'].' Delegación o Municipio '.$infPv['municipio'].'
C.P. '.$infS['codigoPostal'].' Estado '.$infS['estado'].'
'; //PRODUCTOS $html .= '
PRODUCTOS

'; foreach($products as $res){ //Tallas $hTallas = '
'; foreach($res['tallas'] as $val) $hTallas .= ''; $hTallas .= '
Proporción Tallas
'.$val['nombre'].'
'.$val['cantidad'].'
'; //Colores $hColores = '
'; foreach($res['colores'] as $val) $hColores .= ''; $hColores .= '
Proporción Colores
'.$val['nombre'].'
'.$val['cantidad'].'
'; //Producto $html .= '
CODIGO BARRA MODELO COSTO UNITARIO PRECIO VENTA CANTIDAD TOTAL
'.$res['codigoBarra'].' '.$res['modelo'].' $'.$res['costo'].' $'.$res['precioVentaIva'].' '.$res['cantidad'].' $'.$res['total'].'

'.$hTallas.' '.$hColores.'
'; //Distribucion $html .= '
DISTRIBUCION

'; $html .= ''; $bloque = 0; foreach($sucursals as $sucursales){ //$html .= ''; foreach($sucursales as $val){ $productoId = $res['productoId']; $sucursalId = $val['sucursalId']; $sucursal->setSucursalId($sucursalId); $infS = $sucursal->Info(); $noSuc = $infS['noSuc']; $distP = $dist[$productoId][$sucursalId]; if($distP['cantidad'] > 0){ $html .= ''; $bloque++; } if($bloque == 11){ $html .= ''; $bloque = 0; } }//foreach }//foreach $sucursals if($bloque == 0) $falta = 0; else $falta = 11 - $bloque; for($k=1; $k<=$falta; $k++) $html .= ''; $html .= ''; $html .= '
Suc. '.$noSuc.'
'.$distP['cantidad'].'
'; }//foreach //PRODUCTOS $html .= '
PIEZAS POR CAJA

'; $html .= ' '; foreach($products as $res){ $html .= ' '; } $html .= '
CODIGO BARRA MODELO CANTIDAD
'.$res['codigoBarra'].' '.$res['modelo'].' '.$res['piezasCaja'].'
'; //TOTALES $html .= '
TOTALES
  SUBTOTAL
IVA '.$ivaPorc.'%
TOTAL
$'.$info['subtotal'].'
$'.$info['iva'].'
$'.$info['total'].'
'; $dompdf = new DOMPDF(); $dompdf->set_paper('letter'); $dompdf->load_html($html); $dompdf->render(); if($mode == 'show'){ $dompdf->stream('orden_compra.pdf'); exit; } //Guardamos el archivo temporalmente $pdfoutput = $dompdf->output(); $filename = DOC_ROOT.'/temp/orden_compra.pdf'; $fp = fopen($filename, "a"); fwrite($fp, $pdfoutput); fclose($fp); $_mail = new PHPMailer(true); //Configurando el servidor SMTP $_mail->IsSMTP(); $_mail->SMTPAuth = true; $_mail->Host = SMTP_HOST; $_mail->Username = SMTP_USER; $_mail->Password = SMTP_PASS; $_mail->Port = SMTP_PORT; //Enviamos el mensaje $email = $infPv['emailVtas']; $proveedor = $infPv['nombre']; if($mode == 'cancelar'){ $subject = 'Cancelacion Orden de Compra No. '.$info['noPedido']; $message = 'Por medio de la presente le informamos que la Orden de Compra No. '.$info['noPedido']; $message .= 'ha sido cancelada.'; $message .= '

Lamentamos los inconvenientes que esto pudiera ocasionar.'; }else{ $subject = 'Envio Orden de Compra No. '.$info['noPedido']; $message = 'Por medio de la presente le hacemos llegar la Orden de Compra No. '.$info['noPedido']; } $message .= '

Por su atención'; $message .='

Gracias'; $html = ' '.$message.' '; try { $_mail->AddAddress($email, $proveedor); if($enProduccion){ $_mail->AddBCC('silvano.cruz@novomoda.com.mx'); $_mail->AddBCC('sonia.velazquez@novomoda.com.mx'); } $_mail->AddBCC('sistemas@novomoda.com.mx'); $_mail->SetFrom('contacto@novomoda.com.mx', 'Novomoda'); $_mail->Subject = $subject; $_mail->MsgHTML($html); $_mail->AddAttachment(DOC_ROOT.'/temp/orden_compra.pdf'); // attachment $_mail->Send(); $emailSent = 1; } catch (phpmailerException $e) { $emailSent = 2; } catch (Exception $e) { $emailSent = 2; } @unlink(DOC_ROOT.'/temp/orden_compra.pdf'); header('Location: '.WEB_ROOT.'/pedidos'); exit; ?>