<?php
if(!is_dir('ptov')){mkdir('ptov');}

include_once('lib_main.php');

if(!empty($empr)){$link_data=msql_connect('','','',$empr); $cfg_empr=$empr;}
$user_codigo=$_SESSION['user_codigo'];
$user0=data_maes('user',$user_codigo);
$empr0=data_maes('empr',$cfg_empr);
if(empty($user_codigo)){include('user_login0.php');return;}


$file_ptov='/ptov/PtoVta_'.strtoupper($cfg_empr).'_'.date('Y-m-d').'.html';
$file_ptov='https://'.$_SERVER['SERVER_NAME'].$file_ptov;
$zlabel='Visualizar Pto.Vta.';
$zonclick="window.open('".$file_ptov."','_blank')";
include('ele_button.php');


$file_ptov='/ptov/PtoVta_'.strtoupper($cfg_empr).'_'.date('Y-m-d').'.html';
$zlabel='Descargar Pto.Vta.';
$zonclick="down_url('".$file_ptov."')";
include('ele_button.php');





// https://demo.vcrxol.com/ptov/PtoVta_DEMO_2024-05-04.html


$file_ptov='../'.$cfg_empr.$file_ptov;
file_put_contents($file_ptov,'<!DOCTYPE html>');

$domd = new DOMDocument();
     $domd->encoding = 'utf-8';
     $domd->xmlVersion = '1.0';
     $domd->formatOutput = true;
$elem=$domd;


$html=$elem->appendChild($domd->createElement("html"));
     $html->setAttribute("id","html1");

$head=$html->appendChild($domd->createElement("head"));
     $head->appendChild($domd->createElement("title","Pto.Vta. ".$empr0['empr_descri']));

$css_file=file_get_contents('../_lib/regi_vtas1.css');
$script=$head->appendChild($domd->createElement("style",$css_file));



//////////////////////////////////////////////////////////
///// BODY
//////////////////////////////////////////////////////////
$body=$html->appendChild($domd->createElement("body"));

$js_file=file_get_contents('../_lib/regi_vtas1.js');
$script=$body->appendChild($domd->createElement("script",$js_file));
     $script->setAttribute("id","script1");


$screen1=$body->appendChild($domd->createElement("div",""));
     $screen1->setAttribute("id","screen1");
     $screen1->setAttribute("class","noprint");
     $screen1->setAttribute("style","font-family:arial; font-size:1.5em;");


     $div=$screen1->appendChild($domd->createElement("span",'Actualizado : '.date('Y-m-d H:i:s')));
          $div->setAttribute("id","update");
          $div->setAttribute("style","float:right; font-size:0.5em;");


     $hr=$screen1->appendChild($domd->createElement("hr"));
          $hr->setAttribute("size","1");
          $hr->setAttribute("color",$empr0['empr_color1']);
//           $hr->setAttribute("style","clear:both;margin-bottom:0.5em;margin-top:0em;");
//           $hr->setAttribute("noshade"," ");

     $div=$screen1->appendChild($domd->createElement("span",$empr0['empr_descri']));
          $div->setAttribute("id","empr_descri");
          $div->setAttribute("style","font-size:1.2em;");
          $div->setAttribute("value",$empr0['empr_descri']);

     $div=$screen1->appendChild($domd->createElement("span",$empr0['empr_ruc']));
          $div->setAttribute("id","empr_ruc");
          $div->setAttribute("style","font-size:1.2em; float:right;");
          $div->setAttribute("value",$empr0['empr_ruc']);

     $div=$screen1->appendChild($domd->createElement("input"));
          $div->setAttribute("style","display:none;");
          $div->setAttribute("id","empr");
          $div->setAttribute("value",$cfg_empr);


     $div=$screen1->appendChild($domd->createElement("input"));
          $div->setAttribute("style","display:none;");
          $div->setAttribute("id","fecha");
          $div->setAttribute("value",date('Y-m-d'));
          $div->setAttribute("readonly","");



     $hr=$screen1->appendChild($domd->createElement("hr"));
          $hr->setAttribute("size","3");
          $hr->setAttribute("color",$empr0['empr_color1']);



//      $span=$screen1->appendChild($domd->createElement("span"," "));
//           $span->setAttribute("style","float:; font-size:0.8em");
// //      $label=$span->appendChild($domd->createElement("label","FILE"));
//      $input=$span->appendChild($domd->createElement("input"));
//           $input->setAttribute("id","docunume");
//           $input->setAttribute("type","file");
//           $input->setAttribute("accept",".txt");
// //           $input->setAttribute("value","c:\\VCRX-PTOV\ptov_test.txt");


//      $input=$span->appendChild($domd->createElement("input"));
//           $input->setAttribute("id","numero");


//      $span=$screen1->appendChild($domd->createElement("span"," "));
//           $span->setAttribute("style","float:; font-size:0.8em");
//      $label=$span->appendChild($domd->createElement("label","PTO.VTA. : "));
//           $label->setAttribute("for","ptov");
//      $input=$span->appendChild($domd->createElement("input"));
//           $input->setAttribute("id","ptov");
//           $input->setAttribute("value","001101");
//           $input->setAttribute("readonly","");
//           $input->setAttribute("tabindex","-1");
//           $input->setAttribute("style","width:4em;");

     $span=$screen1->appendChild($domd->createElement("span"," "));
          $span->setAttribute("style","float:; font-size:0.8em");
     $label=$span->appendChild($domd->createElement("label","PTO.VTA. : "));
          $label->setAttribute("for","ptov");
     $input=$span->appendChild($domd->createElement("select"));
          $input->setAttribute("id","ptov");
          $input->setAttribute("value","001101");
          $input->setAttribute("readonly","");
          $input->setAttribute("tabindex","-1");
          $input->setAttribute("style","width:10em; font-size:1em;");



          $sql_ptov='select * from ptov0 where ifnull(ptov_status,"")not in("I","X") order by ptov_codigo';
          $res_ptov=msql_query($sql_ptov,$link_data);
          while($aso_ptov=msql_fetch_assoc($res_ptov))
          {
          $option=$input->appendChild($domd->createElement("option",$aso_ptov['ptov_descri']));
               $option->setAttribute("value",$aso_ptov['ptov_codigo']);
               
          }
//           $option=$input->appendChild($domd->createElement("option","001001 NOTA VENTA"));
//                $option->setAttribute("value","001001");
//           $option=$input->appendChild($domd->createElement("option","001101 FACTURA"));
//                $option->setAttribute("value","001101");



     $button=$screen1->appendChild($domd->createElement("button","GUARDAR"));
          $button->setAttribute("onclick","save_docu();");
          $button->setAttribute("style","float:right; background-color:seagreen; color:white; font-size:1.5em; font-weight:bold;");





     $hr=$screen1->appendChild($domd->createElement("hr"));
          $hr->setAttribute("size","0");
          $hr->setAttribute("color",$empr0['empr_color1']);
//           $hr->setAttribute("style","clear:both;margin-bottom:0.5em;margin-top:0em;");
//           $hr->setAttribute("noshade"," ");


     $maes='enti';
     $span=$screen1->appendChild($domd->createElement("span"," "));
     $label=$span->appendChild($domd->createElement("label","CLIENTE : "));
          $label->setAttribute("for",$maes);
     $input=$span->appendChild($domd->createElement("input"));
          $input->setAttribute("id",$maes);
          $input->setAttribute("value","9999999999");
          $input->setAttribute("list","dl_".$maes);
          $input->setAttribute("onblur","{document.getElementById('".$maes."_descri').value=document.getElementById('".$maes."_'+this.value).getAttribute('razsoc'); calc_total();}");
          $input->setAttribute("style","width:10em;");
     $label2=$span->appendChild($domd->createElement("input"," "));
          $label2->setAttribute("id",$maes."_descri");
          $label2->setAttribute("tabindex","-1");



     $maes='vndd';
     $span=$screen1->appendChild($domd->createElement("span"," "));
          $span->setAttribute("style","float:right;");
     $input=$span->appendChild($domd->createElement("input"));
          $input->setAttribute("id",$maes);
          $input->setAttribute("value","9999999999");
          $input->setAttribute("list","dl_".$maes);
     $label=$span->appendChild($domd->createElement("label","VENDEDOR : "));
          $label->setAttribute("for",$maes);
//           $input->setAttribute("onblur","{document.getElementById('".$maes."_descri').innerHTML=document.getElementById('".$maes."_'+this.value).getAttribute('razsoc');}");
          $input->setAttribute("style","width:7em;");
     $label2=$span->appendChild($domd->createElement("label"," "));
          $label2->setAttribute("id",$maes."_descri");



//      $br=$screen1->appendChild($domd->createElement("br"," "));

     $hr=$screen1->appendChild($domd->createElement("hr"));
          $hr->setAttribute("size","2");
          $hr->setAttribute("color",$empr0['empr_color1']);


     $maes='item';
     $span=$screen1->appendChild($domd->createElement("span",""));
     $label=$span->appendChild($domd->createElement("label","PRODUCTO : "));
          $label->setAttribute("for",$maes);
          $label->setAttribute("style","display:none;");
//      $br=$span->appendChild($domd->createElement("br"));
     $input=$span->appendChild($domd->createElement("input"));
          $input->setAttribute("id",$maes);
          $input->setAttribute("value","");
          $input->setAttribute("placeholder","codigo");
          $input->setAttribute("list","dl_".$maes);
          $input->setAttribute("onkeyup","{if(document.getElementById('".$maes."_'+this.value) || isValidBarcode(this.value)){add_row(this.value); this.value=null;};}");
     $label2=$span->appendChild($domd->createElement("input"," "));
          $label2->setAttribute("id",$maes."_descri");
          $label2->setAttribute("tabindex","-1");
          $label2->setAttribute("style","display:none;");



     $span=$screen1->appendChild($domd->createElement("span"," "));
          $span->setAttribute("style","float:right; display:;");
     $label=$span->appendChild($domd->createElement("label","TOTAL : "));
          $label->setAttribute("for","total");
     $input=$span->appendChild($domd->createElement("input"));
          $input->setAttribute("id","total");
          $input->setAttribute("readonly","");
          $input->setAttribute("tabindex","-1");
          $input->setAttribute("value",0.00);
          $input->setAttribute("onclick","calc_total();");
          $input->setAttribute("style","text-align:right; width:7em;");

     $span=$screen1->appendChild($domd->createElement("span"," "));
          $span->setAttribute("style","float:; display:none;");
     $label=$span->appendChild($domd->createElement("label","WsApp : "));
          $label->setAttribute("for","wsapp");
     $input=$span->appendChild($domd->createElement("input"));
          $input->setAttribute("id","wsapp");
          $input->setAttribute("type","number");
          $input->setAttribute("style","width:7em;");

     $br=$screen1->appendChild($domd->createElement("br"));

     $table=$screen1->appendChild($domd->createElement("table",""));
          $table->setAttribute("id","tab_detalle");
          $table->setAttribute("width","100%");
          $table->setAttribute("border","1");
          $table->setAttribute("style","");
               
          $thead=$table->appendChild($domd->createElement("thead",""));
          $tbody=$table->appendChild($domd->createElement("tbody",""));
               $tbody->setAttribute("id","body_detalle");
          $tfoot=$table->appendChild($domd->createElement("tfoot",""));


          $trow=$thead->appendChild($domd->createElement("tr",""));
               $tcol=$trow->appendChild($domd->createElement("th","CODIGO"));
               $tcol=$trow->appendChild($domd->createElement("th","PRODUCTO"));
               $tcol=$trow->appendChild($domd->createElement("th","CANT"));
               $tcol=$trow->appendChild($domd->createElement("th",""));
                    $tcol->setAttribute("style","display:none;");
               $tcol=$trow->appendChild($domd->createElement("th",""));
                    $tcol->setAttribute("style","display:none;");
               $tcol=$trow->appendChild($domd->createElement("th","I"));
               $tcol=$trow->appendChild($domd->createElement("th","PVP"));
               $tcol=$trow->appendChild($domd->createElement("th","SUBTOT"));
               $tcol=$trow->appendChild($domd->createElement("th"," "));
                    $tcol->setAttribute("align","center");

               $trow->setAttribute("style","background-color:".$empr0['empr_color1']);
     
                    $button=$tcol->appendChild($domd->createElement("button","Borrar TODO"));
                    $button->setAttribute("onclick","dele_all()");
                    $button->setAttribute("tabindex","-1");
                    $button->setAttribute("style","font-weight:bold; color:white; background-color:darkred; vertical-align:middle;");



     $maes='enti';
     $maes0=$maes.'0';
     $sql_data='select * from '.$maes0.' order by '.$maes.'_descri';
     $res_data=msql_query($sql_data,$link_data);
     $datalist=$screen1->appendChild($domd->createElement("datalist"));
          $datalist->setAttribute("id","dl_".$maes);
          $options=$datalist->appendChild($domd->createElement("options"));
          while($aso_data=msql_fetch_assoc($res_data))
          {
               $option=$options->appendChild($domd->createElement("option",htmlspecialchars($aso_data[$maes.'_descri'])));
                    $option->setAttribute("value",htmlspecialchars($aso_data[$maes.'_codigo']));
               
               $div=$screen1->appendChild($domd->createElement("div"));
                    $div->setAttribute("id",$maes.'_'.$aso_data[$maes.'_codigo']);
                    $div->setAttribute("descri",$aso_data[$maes.'_descri']);
                    $div->setAttribute("razsoc",$aso_data[$maes.'_razsoc']);
                    $div->setAttribute("nomcom",$aso_data[$maes.'_nomcom']);
                    $div->setAttribute("wsapp",$aso_data[$maes.'_wsapp']);
          }
          
     $maes='vndd';
     $maes0=$maes.'0';
     $sql_data='select * from '.$maes0.' order by '.$maes.'_descri';
     $res_data=msql_query($sql_data,$link_data);
     $datalist=$screen1->appendChild($domd->createElement("datalist"));
          $datalist->setAttribute("id","dl_".$maes);
          $options=$datalist->appendChild($domd->createElement("options"));
          while($aso_data=msql_fetch_assoc($res_data))
          {
               $option=$options->appendChild($domd->createElement("option",$aso_data[$maes.'_descri']));
                    $option->setAttribute("value",$aso_data[$maes.'_codigo']);
               
               $div=$screen1->appendChild($domd->createElement("div"));
                    $div->setAttribute("id",$maes.'_'.$aso_data[$maes.'_codigo']);
                    $div->setAttribute("descri",$aso_data[$maes.'_descri']);
                    $div->setAttribute("razsoc",$aso_data[$maes.'_razsoc']);
                    $div->setAttribute("nomcom",$aso_data[$maes.'_nomcom']);
                    $div->setAttribute("wsapp",$aso_data[$maes.'_wsapp']);
          }
          
     $maes='item';
     $maes0=$maes.'0';
     $sql_data='select * from '.$maes0.' order by '.$maes.'_descri';
     $res_data=msql_query($sql_data,$link_data);
     $datalist=$screen1->appendChild($domd->createElement("datalist"));
          $datalist->setAttribute("id","dl_".$maes);
          $options=$datalist->appendChild($domd->createElement("options"));
          while($aso_data=msql_fetch_assoc($res_data))
          {
               $option=$options->appendChild($domd->createElement("option",htmlspecialchars($aso_data[$maes.'_descri'].' $/. '.round($aso_data[$maes.'_pvp1'],2))));
                    $option->setAttribute("value",$aso_data[$maes.'_codigo']);
               
                $div=$screen1->appendChild($domd->createElement("div"));
                    $div->setAttribute("id",$maes.'_'.$aso_data[$maes.'_codigo']);
                    $div->setAttribute("descri",$aso_data[$maes.'_descri']);
                    $div->setAttribute("puni1",$aso_data[$maes.'_puni1']);
                    $div->setAttribute("iva",$aso_data[$maes.'_iva']);
                    $div->setAttribute("ice",$aso_data[$maes.'_ice']);
                    $div->setAttribute("pvp1",$aso_data[$maes.'_pvp1']);
         }


//  <div hide style='display:none;'>
//      <div id="empr">demo</div>
//      <div id="color1">#09C</div>
//      <div id="color2">#D8D8D8</div>
//      <div id="user_codigo">2</div>
//      <div id="user_descri">VICENTE RUIZ</div>
//      </div>


$print1=$body->appendChild($domd->createElement("div",""));
     $print1->setAttribute("id","print1");
//      $print1->setAttribute("class","noscreen");
     $print1->setAttribute("style","font-family:arial; font-size:0.5em; width:80mm;");


     $div=$print1->appendChild($domd->createElement("div",$empr0['empr_descri']));
          $div->setAttribute("style","text-align:center;");
     $div=$print1->appendChild($domd->createElement("div","RUC : ".$empr0['empr_ruc']));
          $div->setAttribute("style","text-align:center;");

     $div=$print1->appendChild($domd->createElement("div",""));
          $div->setAttribute("style","text-align:;");
          $span=$div->appendChild($domd->createElement("span","DOCUMENTO : "));
          $span=$div->appendChild($domd->createElement("span"," "));
               $span->setAttribute("id","print_docu");

     $div=$print1->appendChild($domd->createElement("div",""));
          $div->setAttribute("style","text-align:;");
          $span=$div->appendChild($domd->createElement("span","NUMERO : "));
          $span=$div->appendChild($domd->createElement("span"," "));
               $span->setAttribute("id","print_numero");

     $div=$print1->appendChild($domd->createElement("div",""));
          $div->setAttribute("style","text-align:;");
          $span=$div->appendChild($domd->createElement("span","CLIENTE : "));
          $span=$div->appendChild($domd->createElement("span"," "));
               $span->setAttribute("id","print_enti");


     $table=$print1->appendChild($domd->createElement("table",""));
//           $table->setAttribute("id","tab_detalle");
          $table->setAttribute("width","100%");
          $table->setAttribute("border","1");
          $table->setAttribute("style","");
               
          $thead=$table->appendChild($domd->createElement("thead",""));
          $tbody=$table->appendChild($domd->createElement("tbody",""));
               $tbody->setAttribute("id","print_body");
          $tfoot=$table->appendChild($domd->createElement("tfoot",""));
               $thead->setAttribute("style","background-color:".$empr0['empr_color1']);


          $trow=$thead->appendChild($domd->createElement("tr",""));
               $tcol=$trow->appendChild($domd->createElement("th","L"));
               $tcol=$trow->appendChild($domd->createElement("th","PRODUCTO"));
                    $tcol->setAttribute("colspan","5");
          $trow=$thead->appendChild($domd->createElement("tr",""));
               $tcol=$trow->appendChild($domd->createElement("th"," "));
               $tcol=$trow->appendChild($domd->createElement("th","CANT."));
               $tcol=$trow->appendChild($domd->createElement("th","UNIT."));
               $tcol=$trow->appendChild($domd->createElement("th","SUBT."));
               $tcol=$trow->appendChild($domd->createElement("th"," "));
               $tcol=$trow->appendChild($domd->createElement("th","TOTAL"));
                    $tcol->setAttribute("align","center");
//                $thead->setAttribute("style","background-color:".$empr0['empr_color1']);



$file_html=$domd->saveHTML();

file_put_contents($file_ptov,$file_html,FILE_APPEND);





?>

<!-- 
<!DOCTYPE html>
<html translate="no" id="html" >
<head>
     
      -->
