Advertisement
oscarvogel

Impresoras Fiscales

Jul 27th, 2015
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Local TIPO_FACTURA
  2. Local TIPO_IVA
  3. Local TIPO_DOCU
  4. Local Se
  5. Local fd, nIva
  6. Local intentos
  7. Local todo_ok As Boolean
  8. Local lin
  9. Local Total As Decimal
  10. Local descuento As Decimal
  11. Local ndocu As String
  12. Local salctacte As Decimal
  13. Local dias As Integer
  14. Local cDirCom As String
  15. Local cDirRes As String
  16. Local sNombre As String
  17. Local cTalk As String
  18. Local nFlete As Decimal
  19. Local nDRet As Decimal
  20.  
  21. this.TodoOK = .F.
  22. cTalk = Set("Talk")
  23. Set Talk Off
  24.  
  25. thisform.EjecutaSQL(goApp.nCon, "select * from tiporesp where idTipoResp=?clientes.tiporesp", "tiporesp")
  26. If tiporesp.discrimina
  27.     this.Clase = "A"
  28. Else
  29.     this.Clase = "B"
  30. Endif
  31.  
  32. sCliente                = Thisformset.frmCliente.cliente1.validacod.value
  33. m.dias                  = 0&&This.dias()
  34. m.descuento             = 0.00&&Thisform.txtdescuento.Value  &&el descuento general de la factura
  35. nTOTAL                  = thisform.Totales.txtTotal.value  
  36. sNombre                 = Strtran(Thisformset.frmCliente.cliente1.lbltexto.Caption,"Ñ","N") &&saco las Ñ que no imprime el controlador fiscal
  37. If This.contado = "N"
  38.     m.salctacte         = This.SaldoCliente(sCliente, 0) &&Obtengo el saldo en cuenta corriente del cliente
  39. Else
  40.     m.salctacte = 0
  41. Endif
  42.  
  43. lImpreFiscal = trae_dirimprefiscal() &&devuelve el path donde estan las carpetas para el impresor fiscal
  44.  
  45. nIva = ASIVA21()
  46. m.salctacte = Iif(Isnull(m.salctacte),0.00, m.salctacte)
  47. nDRet = 0.00
  48. Select("det")
  49.  
  50. If -1 = SQLExec(goApp.nCon, "select * from localidades where idLocalidad=?clientes.idLocalidad","loc")
  51.     goApp.Error()
  52. Endif
  53. &&si el total supera los 5000 no se hace ticket, se obliga a que se haga una factura
  54. *!* Do While Empty(This.ticket)
  55. *!*     This.ticket = This.DefineComp()
  56. *!* Enddo
  57. This.Ticket = 'S'
  58. Se = Chr(28)  &&separador de comandos
  59. &&this.condicion indica si es nota de credito o factura o nota de debito
  60. If This.condicion <> "C"
  61.     If This.condicion = "D"  &&nota de debito
  62.         If This.clase = "B"
  63.             TIPO_FACTURA = "E"
  64.         Else
  65.             TIPO_FACTURA = "D"
  66.         Endif
  67.     Else
  68. && si no es nota de debito ni credito es factura
  69.         If This.clase = "B" Or this.clase = "C"
  70.             TIPO_FACTURA = "B"
  71.         Else
  72.             TIPO_FACTURA = "A"
  73.         Endif
  74.     Endif
  75. Else
  76.     If This.clase = "B"
  77.         TIPO_FACTURA = "S"
  78.     Else
  79.         TIPO_FACTURA = "R"
  80.     Endif
  81. Endif
  82.  
  83. &&traigo la tabla de parametros
  84. *!* If SQLExec(Thisform.con, "select * from parametr","parametr") = -1
  85. *!*     Messagebox("Se ha producido un error al recuperar el tipo de Documento" + Chr(10)+Chr(13)+Message(),0+48,"ERROR")
  86. *!*     Return -1
  87. *!* Endif
  88.  
  89. &&indica si el cliente tiene que poseer cuit
  90. If tiporesp.obligacuit
  91.     If Empty( Val( Strtran( clientes.cuit, "-" ) ) )
  92.         Messagebox ("ATENCION: Falta Registrar CUIT de Cliente", 0+48, "CUIT")
  93.         Do While Val(ndocu) < 2
  94.             ndocu = Inputbox("Ingrese CUIT")
  95.         Enddo
  96.         ndocu = Alltrim( Strtran( ndocu, "-" ) )
  97.     Else
  98.         TIPO_DOCU = 'C' &&tiporesp.tipo_iva &&"C"
  99.         ndocu = Alltrim( Strtran( clientes.cuit, "-" ) )
  100.     Endif
  101. Else
  102.     If SQLExec(goApp.nCon, "select * from tipodoc where codigo=?clientes.tipodocu","tipodoc") = -1
  103.         goApp.Error()
  104.         Return -1
  105.     Endif
  106.     If Reccount("tipodoc") > 0
  107.         TIPO_DOCU = tipodoc.tipo
  108.     Else
  109.         TIPO_DOCU = '2'
  110.     Endif
  111.     ndocu = Alltrim(Str(clientes.dni))
  112.     If Val(ndocu) < 2
  113.         ndocu = '11111111'
  114.     Endif
  115. Endif
  116.  
  117. TIPO_IVA = tiporesp.TIPOIVA
  118. Select("comando")
  119.  
  120. &&me fijo si es ticket factura o factura
  121. If This.Ticket = "S"
  122.     lin = "5"
  123. Else
  124.     lin = "3"
  125. Endif
  126.  
  127. If This.Ticket = "N"
  128. &&en caso de ser factura imprimo todo el encabezado que va en la factura
  129.     Select("comando")
  130.     Insert Into comando;
  131.         VALUES( "]" + Se + "1" + Se + Chr(127) )
  132.     Insert Into comando;
  133.         VALUES( "]" + Se + "2" + Se + Chr(127) )
  134.  
  135.     Insert Into comando;
  136.         values( "]" + Se + "2" + Se + "Ing.Brut. 914-532186-1"  )
  137.     If This.contado = "N"
  138.         Insert Into comando;
  139.             VALUES ("]" + Se + lin + Se + ;
  140.             "Vendedor: "+Alltrim(vendedor.nom_ven)+;
  141.             SPACE(10)+"Vencimiento de este Comp.: "+;
  142.             DTOC(This.FechaVen(Thisform.txtFecha.Value))+;
  143.             " Saldo Actual de CTA_CTE(S.E.U.O.): $"+;
  144.             ALLTRIM(Str((m.salctacte),12,2)))
  145.     Else
  146.         Insert Into comando;
  147.             VALUES ("]" + Se + lin + Se + "Vendedor: "+;
  148.             ALLTRIM(vendedor.nom_ven)+;
  149.             SPACE(10)+"Vencimiento de este Comp.: "+;
  150.             DTOC(This.FechaVen(Thisform.txtFecha.Value)))
  151.     Endif
  152.  
  153.     lin = Str(Val(lin)+1,1,0)
  154.  
  155.     Do Case
  156.     Case Used("obsfac")
  157.         Insert Into comando;
  158.             VALUES ("]" + Se + lin + Se + "OBS.: "+Alltrim(obsfac.obs1)+Alltrim(obsfac.obs2))
  159.     Case This.pagoanticipado &&det.pagoanticipado
  160.         If det.reparto
  161.             Insert Into comando;
  162.                 VALUES ("]" + Se + lin + Se + "PAGO ANTICIPADO - REPARTO")
  163.         Else
  164.             Insert Into comando;
  165.                 VALUES ("]" + Se + lin + Se + "PAGO ANTICIPADO - RETIRA")
  166.         Endif
  167.     Case This.lReparto
  168.         Insert Into comando;
  169.             VALUES ("]" + Se + lin + Se + "MERCADERIA DE REPARTO")
  170.     Case !This.lReparto
  171.         Insert Into comando;
  172.             VALUES ("]" + Se + lin + Se + "MERCADERIA PARA RETIRAR")
  173.     Otherwise
  174.         Insert Into comando;
  175.             VALUES ("]" + Se + lin + Se + "DEVOLUCIONES DENTRO DE LAS 48 HRS.")
  176.     Endcase
  177.  
  178.     lin = Str(Val(lin)+1,1,0)
  179.     This.letras.dicenum(m.nTOTAL)
  180.     Insert Into comando;
  181.         VALUES ( "]" + Se + lin + Se + ;
  182.         "SON:" + This.letras.retorno)
  183.  
  184.     lin = "11"
  185.  
  186. &&especifico las formas de cancelacion que posee la factura
  187.     If pagos.adic1 > 0 .Or. pagos.plazo1 > 0
  188.         Insert Into comando;
  189.             VALUES ( "]" + Se + lin + Se + ;
  190.             "OPCION DE PAGO: Hasta el "+;
  191.             Dtoc(Thisform.txtFecha.Value+This.dias())+ " "+;
  192.             STR(pagos.adic1)+" % Desc. $ "+;
  193.             STR(m.nTOTAL*pagos.adic1/100,08,2)+;
  194.             " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic1)/100),10,2))
  195.     Else
  196.         If Inlist(pagos.pago,'00','01','02')
  197.             Insert Into comando;
  198.                 VALUES ( "]" + Se + lin + Se + ;
  199.                 "OPCION DE PAGO: Contado Efectivo"+;
  200.                 " 3% Desc. "+;
  201.                 " Paga $ "+ Str(m.nTOTAL,10,2))
  202.         Else
  203.             Insert Into comando;
  204.                 VALUES ( "]" + Se + lin + Se + Chr(127))
  205.         Endif
  206.     Endif
  207.  
  208.     lin = Str(Val(lin)+1,2,0)
  209.  
  210.     If pagos.adic2 > 0 .Or. pagos.plazo2 > 0
  211.         If Isnull(pagos.dia) Or Empty(pagos.dia)
  212.             Insert Into comando;
  213.                 VALUES ( "]" + Se + lin + Se +;
  214.                 "OPCION DE PAGO: Hasta el "+ ;
  215.                 DTOC(This.FechaVen(Thisform.txtFecha.Value))+"  "+;
  216.                 STR(pagos.adic2)+" % Desc. $ ";
  217.                 +Str(m.nTOTAL*pagos.adic2/100,08,2)+;
  218.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  219.         Else
  220.             If pagos.pago = '51'
  221. *!* Pongo esto para que en esta condicion no me sume los dias de ADIC2
  222.                 Insert Into comando;
  223.                     VALUES ("]" + Se + lin + Se +  ;
  224.                     "OPCION DE PAGO: Hasta el "+ ;
  225.                     DTOC(pagos.dia)+"  "+;
  226.                     STR(pagos.adic2)+" % Desc. $ "+;
  227.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  228.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  229.             Else
  230.                 Insert Into comando;
  231.                     VALUES ("]" + Se + lin + Se +  ;
  232.                     "OPCION DE PAGO: Hasta el "+ ;
  233.                     DTOC(This.FechaVen(Thisform.txtFecha.Value))+"  "+;
  234.                     STR(pagos.adic2)+" % Desc. $ "+;
  235.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  236.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  237.             Endif
  238.         Endif
  239.     Else
  240.         Insert Into comando;
  241.             VALUES ( "]" + Se + lin + Se + Chr(127) )
  242.     Endif
  243.  
  244.     lin = Str(Val(lin)+1,2,0)
  245.  
  246.     If pagos.adic3 > 0 .Or. pagos.plazo3 >0
  247.         If Isnull(pagos.dia) Or Empty(pagos.dia)
  248.             Insert Into comando;
  249.                 VALUES ("]" + Se + lin + Se + ;
  250.                 "OPCION DE PAGO: Hasta el "+ ;
  251.                 DTOC(Thisform.txtFecha.Value+Cast(pagos.dias1 As Integer))+"  "+;
  252.                 STR(pagos.adic3)+" % Desc. $ "+;
  253.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  254.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  255.         Else
  256.             Insert Into comando;
  257.                 VALUES ("]" + Se + lin + Se + ;
  258.                 "OPCION DE PAGO: Hasta el "+ ;
  259.                 DTOC(pagos.dia+Cast(pagos.dias1 As Integer))+"  "+;
  260.                 STR(pagos.adic3)+" % Desc. $ "+;
  261.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  262.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  263.         Endif
  264.     Else
  265.         Insert Into comando;
  266.             VALUES ("]" + Se + lin + Se + Chr(127))
  267.     Endif
  268.  
  269.     lin = Str(Val(lin)+1,2,0)
  270. *!*     Insert Into comando;
  271. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  272.     If m.nFlete > 0 Or m.nDRet > 0
  273.         If m.nFlete > 0
  274.             Insert Into comando;
  275.                 VALUES ("]" + Se + lin + Se + ;
  276.                 "Prec. de Merc. Incl. Flete "+ ;
  277.                 Transform(m.nFlete, "@$ 99,999,999.99"))
  278.         Else
  279.             Insert Into comando;
  280.                 VALUES ("]" + Se + lin + Se + ;
  281.                 "Merc. Incl. Desc p/RETIRA "+ ;
  282.                 Transform(m.nDRet, "@$ 99,999,999.99"))
  283.         Endif
  284.     Else
  285.         Insert Into comando;
  286.             VALUES ("]" + Se + lin + Se + Chr(127))
  287.     Endif
  288.  
  289. &&si se factura sobre remitos se imprimen los remitos afectados
  290.     If Thisform.viene = "X" &&hay q revisar esto para ver q cuando se factura de remitos se imprima
  291.         Insert Into comando;
  292.             VALUES ( Chr(147) + Se + "1" + Se + Substr(This.remitosafacturar,1,17))
  293.         If !Empty(Substr(This.remitosafacturar,19,20))
  294.             Insert Into comando;
  295.                 VALUES (Chr(147) + Se + "2" + Se + Substr(This.remitosafacturar,19,20))
  296.         Endif
  297.     Endif
  298. Else
  299.     If This.contado = 'N'
  300.         Insert Into comando;
  301.             values("]" + Se + lin + Se+;
  302.             " Saldo de CTA_CTE: $"+;
  303.             ALLTRIM(Str((m.salctacte),12,2)))
  304.         lin = '6'
  305.     Else
  306.         Insert Into comando;
  307.             values("]" + Se + lin + Se + Chr(127))
  308.         lin = '6'
  309.     Endif
  310.  
  311.     Insert Into comando;
  312.         VALUES ( "]" + Se + lin + Se + "Vendedor: "+Alltrim(goApp.User) )
  313.  
  314.     lin = '7'
  315.     Insert Into comando;
  316.         VALUES ("]" + Se + lin + Se + Chr(127))
  317.  
  318.     lin = '8'
  319.     Insert Into comando;
  320.         VALUES ("]" + Se + lin + Se + Chr(127))
  321.  
  322.     lin = '11'
  323. *!*     Insert Into comando;
  324. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  325.     Insert Into comando;
  326.         VALUES ("]" + Se + lin + Se + Chr(127))
  327. Endif
  328.  
  329. If This.Ticket="S"
  330.     Insert Into comando;
  331.         VALUES ( "]" + Se + "9" + Se +Chr(127))
  332.     Insert Into comando;
  333.         VALUES ("]" + Se + "10" + Se +Chr(127))
  334.     If This.condicion = 'C' And Val(sCliente) = 1
  335.         Insert Into comando;
  336.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  337.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  338.             " S/NOMBRE")
  339.     Else
  340.         Insert Into comando;
  341.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  342.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  343.             SUBSTR(Alltrim(thisformset.frmCliente.txtDomicilio.Value)+" "+Alltrim(loc.nombre)+;
  344.             " "+Alltrim(loc.provincia),1,40))
  345.     Endif
  346.  
  347. Else
  348. &&"["+sCliente+"] "+
  349.     Insert Into comando;
  350.         VALUES ( "b" + Se + "[" + sCliente + "] " + Substr(sNombre,1,40) + Se +;
  351.         ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se + ;
  352.         ALLTRIM(Thisform.txtDom.Value)+" ("+Alltrim(clientes.codpos)+") "+;
  353.         Alltrim(loc.nombre)+" "+Alltrim(loc.provincia))
  354. Endif
  355. If This.condicion <> "C"
  356.     Insert Into comando;
  357.         VALUES (Chr(64)+Se+TIPO_FACTURA+Se+"T")
  358. Else
  359. &&Definir tipo y num de factura afectado por nota de credito
  360.     Insert Into comando;
  361.         VALUES (Chr(147) + Se + "1" + Se + cre.tipoaf + " " + cre.numeroaf)
  362.     Insert Into comando;
  363.         VALUES (Chr(128)+Se+TIPO_FACTURA+Se+"T")
  364. Endif
  365.  
  366. &&el cursor "DET" posee los items a facturar
  367. Select("det")
  368. Go Top
  369. Do While ! Eof()
  370. *!* Create Cursor det;
  371. *!*     (cantidad n(12,4), unidad c(8), detalle c(40), total n(12,2), idArticulo int,;
  372. *!*     unitario n(12,2), costo n(12,2), montoiva n(12,2), montodgr n(12,2), montomuni N(12,2),;
  373. *!*     poriva n(12,2), tipoiva c(2))  
  374.     If det.unitario != 0
  375.         If This.clase = "A"
  376.             If This.Ticket = "S"
  377.                 Insert Into comando;
  378.                     VALUES ("A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  379.                 Insert Into comando;
  380.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + Se +;
  381.                     ALLTRIM(Str(det.cantidad,6,2)+"0")+ Se +;
  382.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  383.                     ALLTRIM(Str(det.poriva,5,2)) + Se +;
  384.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  385.             Else
  386.                 Insert Into comando;
  387.                     VALUES ("B" + Se + det.unidad +" "+det.detalle+ Se + ;
  388.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  389.                     Alltrim(Str(det.unitario,13,2)) + ;
  390.                     Se +Alltrim(Str(det.poriva,5,2)) + Se + ;
  391.                     "M" + Se + "0" + Se + "" + Se + "T")
  392.  
  393.             Endif
  394.         Else
  395.             If This.Ticket = "S"
  396.                 Insert Into comando;
  397.                     VALUES ( "A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  398.                 Insert Into comando;
  399.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + ;
  400.                     Se +Alltrim(Str(det.cantidad,6,2)+"0")+ Se + ;
  401.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  402.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  403.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  404.             Else
  405.                 Insert Into comando;
  406.                     VALUES ("B" + Se + det.unidad+" "+det.detalle+ Se +;
  407.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  408.                     ALLTRIM(Str(det.unitario,13,2)) + Se +;
  409.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  410.                     "M" + Se + "0" + Se + "" + Se + "T")
  411.             Endif
  412.         Endif
  413.     Endif
  414.     Select("det")
  415.     Skip
  416. Enddo
  417.  
  418.  
  419. If This.condicion <> "C"
  420.     If This.Ticket = "S"
  421.         If This.contado = "S"
  422.             Insert Into comando;
  423.                 VALUES (Chr(68)+ Se + Substr(formapago.detalle,1,30)+ Se + ;
  424.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  425.         Else
  426.             Insert Into comando;
  427.                 VALUES ( Chr(68)+ Se + Substr(formapago.detalle,1,30)+ ;
  428.                 Se + Alltrim(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  429.         Endif
  430.     Else
  431.         If This.contado = "S"
  432.             Insert Into comando;
  433.                 VALUES (Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  434.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  435.         Else
  436.             Insert Into comando;
  437.                 VALUES(Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  438.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  439.         Endif
  440.     Endif
  441. Endif
  442.  
  443. If This.condicion <> "C"
  444.     Insert Into comando;
  445.         VALUES (Chr(69))
  446. Else
  447.     Insert Into comando;
  448.         VALUES ( Chr(129) )
  449. Endif
  450.  
  451.  
  452. &&en esta parte copio el archivo con los comandos a la carpeta desde el cual
  453. &&el spooler de impresion lee el archivo
  454. If This.Ticket ="S"
  455. && si es ticket me fijo a cual impresora debo enviar
  456.     If lImpreFiscal
  457.         mtXt = Alltrim(impfis.dircoticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  458.         maNs = Alltrim(impfis.dirreticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  459.     Else
  460.         mtXt = Alltrim(parametr.dirco)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  461.         maNs = Alltrim(parametr.dirre)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  462.     Endif
  463. *!*     cDirCom = "fpserver715" + "\impred.exe"
  464. *!*     cDirCom = Fullpath(cDirCom)
  465. *!* && Mato el proceso del spooler y lo vuelvo a cargar
  466. *!*     This.killprocessbyname("impred.exe")
  467. *!*     This.killprocessbyname("wspooler.exe")
  468. *!*     oShell = Createobject("Shell.Application")
  469. *!*     oShell.ShellExecute (cDirCom)
  470. Else
  471. &&aca envio a la 320
  472.     If lImpreFiscal
  473.         mtXt = Alltrim(impfis.dircofactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  474.         maNs = Alltrim(impfis.dirrefactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  475.     Else
  476.         mtXt = Alltrim(parametr.dirco)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  477.         maNs = Alltrim(parametr.dirre)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  478.     Endif
  479. Endif
  480.  
  481.  
  482. Select("comando")
  483. Goto Top
  484. &&en caso de que tenga un archivo en la cola de impresion de la impresora
  485. &&no se deja imprimir
  486. *Browse
  487. If File(mtXt)
  488.     Messagebox("ATENCION: Ud. ya tiene un Documento en Cola de Impresión"+Chr(10)+Chr(13)+;
  489.         " AGUARDE a que el mismo sea impreso o elimínelo luego vuelva a intentar")
  490.     Return This.TodoOK
  491. Else
  492.     Copy To &mtXt Sdf
  493.     If File(maNs)
  494.         Erase &maNs
  495.     Endif
  496.     If File(Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  497.         Erase (Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  498.     Endif
  499.     Wait Windows 'Esperando Respuesta del Controlador Fiscal...' Nowait
  500.     fd = -1
  501.     intentos =1
  502.     Do While fd < 0 .And. Lastkey() != 27
  503.         fd = Fopen(maNs, 0)
  504.         This.LeerSpooler("T")
  505.         If intentos = 30
  506.             Messagebox("ATENCION: Verifique que el Controlador Esté Conectado y Encendido. " + Chr(10) + Chr(13)+ ;
  507.                 "Verifique además que el Programa Spooler se esté ejecutando " + Chr(10) + Chr(13)+ ;
  508.                 "en el equipo al cual se encuentra conectado el Controlador Fiscal")
  509.             This.LeerSpooler("T")
  510.         Endif
  511.         If intentos = 70
  512.             Messagebox("ATENCION: Tiempo de Espera Agotado !!! Presione ESC. para cancelar este Comprobante")
  513.             This.LeerSpooler("T")
  514.         Endif
  515.         intentos = intentos + 1
  516. *For i=1 To 100
  517. *Next
  518.         Inkey(1)
  519.         If Lastkey() = 27
  520.             If Substr(comando.comando,17,16) = "Impresor Ocupado"
  521.                 Messagebox("ATENCION: No se aconseja cancelar este documento por programa, "+;
  522.                     CHR(10)+Chr(13)+"La impresora ya lo ha procesado y saldrá impreso"+;
  523.                     CHR(10)+Chr(13)+ "una vez que esta se ponga en linea")
  524.             Endif
  525.             If Messagebox("ATENCION: Realmente desea Cancelar la Emisión de este Documento??",4+256) = 6
  526.                 Messagebox(" Se proceder  a Cancelar el Documento por Sistema"+;
  527.                     CHR(10)+Chr(13)+" Verifique que la impresora también lo haya Cancelado.")
  528.                 Keyboard '{ESC}'
  529.             Else
  530.                 Keyboard ""
  531.             Endif
  532.         Endif
  533.     Enddo
  534.     If Lastkey() = 27.Or. fd < 0
  535.         If File(mtXt)
  536.             Erase &mtXt
  537.         Endif
  538.         fd = Fopen((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"), 0)
  539.         If fd < 0
  540.             Messagebox("Operación Cancelada: ERROR de comunicaciones con el Controlador.; Probablemente no se este ejecutando Spooler. ")
  541.         Else
  542.             fd =Fclose(fd)
  543.             This.LeerSpooler("T")
  544.         Endif
  545.     Else
  546.         fd = Fclose(fd)
  547.         Select("comando")
  548.         Zap
  549.         Append From &maNs Sdf
  550.         Goto Bottom
  551.         This.numero = Val(Substr(comando.comando,35,8))
  552.         If This.numero <> 0
  553.             SQLExec(goApp.nCon, "select * from puntero where sucursal=?param.sucursal","puntero")
  554.             If This.Ticket = "S"
  555.                 If This.MasDeMil
  556.                     This.numero = Val('0009'+strzero(This.numero,8))
  557.                 Else
  558.                     If lImpreFiscal
  559.                         This.numero = Val(impfis.PtoVtaTicket+strzero(This.numero,8))
  560.                     Else
  561.                         If Param.sucursal=0
  562.                             If File("c:\0009.txt")
  563.                                 This.numero = Val(strzero(9,4)+strzero(This.numero,8))
  564.                             Else
  565.                                 This.numero = Val(strzero(puntero.pvta_tic,4)+strzero(This.numero,8))
  566.                             Endif
  567.                         Else
  568.                             If Param.sucursal = 1
  569.                                 This.numero = Val(strzero(8,4)+strzero(This.numero,8))
  570.                             Endif
  571.                         Endif
  572.                     Endif
  573.                 Endif
  574.             Else
  575.                 If lImpreFiscal
  576.                     This.numero = Val(impfis.PtoVtaFac+strzero(This.numero,8))
  577.                 Else
  578.                     This.numero = Val(strzero(puntero.pvta_fac,4)+strzero(This.numero,8))
  579.                 Endif
  580.             Endif
  581.             This.TodoOK = .T.
  582.         Endif
  583.     Endif
  584.     If File((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"))
  585.         Erase Alltrim(paramfac.dirpa)+"SPOOLER.LOG"
  586.     Endif
  587. Endif
  588. *This.killprocessbyname("impred.exe")
  589. *This.killprocessbyname("wspooler.exe")
  590.  
  591. Set Talk &cTalk
  592. Return This.Todo
  593. *!* Do While Empty(This.ticket)
  594. *!*     This.ticket = This.DefineComp()
  595. *!* Enddo
  596. This.Ticket = 'S'
  597. Se = Chr(28)  &&separador de comandos
  598. &&this.condicion indica si es nota de credito o factura o nota de debito
  599. If This.condicion <> "C"
  600.     If This.condicion = "D"  &&nota de debito
  601.         If This.clase = "B"
  602.             TIPO_FACTURA = "E"
  603.         Else
  604.             TIPO_FACTURA = "D"
  605.         Endif
  606.     Else
  607. && si no es nota de debito ni credito es factura
  608.         If This.clase = "B" Or this.clase = "C"
  609.             TIPO_FACTURA = "B"
  610.         Else
  611.             TIPO_FACTURA = "A"
  612.         Endif
  613.     Endif
  614. Else
  615.     If This.clase = "B"
  616.         TIPO_FACTURA = "S"
  617.     Else
  618.         TIPO_FACTURA = "R"
  619.     Endif
  620. Endif
  621.  
  622. &&traigo la tabla de parametros
  623. *!* If SQLExec(Thisform.con, "select * from parametr","parametr") = -1
  624. *!*     Messagebox("Se ha producido un error al recuperar el tipo de Documento" + Chr(10)+Chr(13)+Message(),0+48,"ERROR")
  625. *!*     Return -1
  626. *!* Endif
  627.  
  628. &&indica si el cliente tiene que poseer cuit
  629. If tiporesp.obligacuit
  630.     If Empty( Val( Strtran( clientes.cuit, "-" ) ) )
  631.         Messagebox ("ATENCION: Falta Registrar CUIT de Cliente", 0+48, "CUIT")
  632.         Do While Val(ndocu) < 2
  633.             ndocu = Inputbox("Ingrese CUIT")
  634.         Enddo
  635.         ndocu = Alltrim( Strtran( ndocu, "-" ) )
  636.     Else
  637.         TIPO_DOCU = 'C' &&tiporesp.tipo_iva &&"C"
  638.         ndocu = Alltrim( Strtran( clientes.cuit, "-" ) )
  639.     Endif
  640. Else
  641.     If SQLExec(goApp.nCon, "select * from tipodoc where codigo=?clientes.tipodocu","tipodoc") = -1
  642.         goApp.Error()
  643.         Return -1
  644.     Endif
  645.     If Reccount("tipodoc") > 0
  646.         TIPO_DOCU = tipodoc.tipo
  647.     Else
  648.         TIPO_DOCU = '2'
  649.     Endif
  650.     ndocu = Alltrim(Str(clientes.dni))
  651.     If Val(ndocu) < 2
  652.         ndocu = '11111111'
  653.     Endif
  654. Endif
  655.  
  656. TIPO_IVA = tiporesp.TIPOIVA
  657. Select("comando")
  658.  
  659. &&me fijo si es ticket factura o factura
  660. If This.Ticket = "S"
  661.     lin = "5"
  662. Else
  663.     lin = "3"
  664. Endif
  665.  
  666. If This.Ticket = "N"
  667. &&en caso de ser factura imprimo todo el encabezado que va en la factura
  668.     Select("comando")
  669.     Insert Into comando;
  670.         VALUES( "]" + Se + "1" + Se + Chr(127) )
  671.     Insert Into comando;
  672.         VALUES( "]" + Se + "2" + Se + Chr(127) )
  673.  
  674.     Insert Into comando;
  675.         values( "]" + Se + "2" + Se + "Ing.Brut. 914-532186-1"  )
  676.     If This.contado = "N"
  677.         Insert Into comando;
  678.             VALUES ("]" + Se + lin + Se + ;
  679.             "Vendedor: "+Alltrim(vendedor.nom_ven)+;
  680.             SPACE(10)+"Vencimiento de este Comp.: "+;
  681.             DTOC(This.FechaVen(Thisform.txtFecha.Value))+;
  682.             " Saldo Actual de CTA_CTE(S.E.U.O.): $"+;
  683.             ALLTRIM(Str((m.salctacte),12,2)))
  684.     Else
  685.         Insert Into comando;
  686.             VALUES ("]" + Se + lin + Se + "Vendedor: "+;
  687.             ALLTRIM(vendedor.nom_ven)+;
  688.             SPACE(10)+"Vencimiento de este Comp.: "+;
  689.             DTOC(This.FechaVen(Thisform.txtFecha.Value)))
  690.     Endif
  691.  
  692.     lin = Str(Val(lin)+1,1,0)
  693.  
  694.     Do Case
  695.     Case Used("obsfac")
  696.         Insert Into comando;
  697.             VALUES ("]" + Se + lin + Se + "OBS.: "+Alltrim(obsfac.obs1)+Alltrim(obsfac.obs2))
  698.     Case This.pagoanticipado &&det.pagoanticipado
  699.         If det.reparto
  700.             Insert Into comando;
  701.                 VALUES ("]" + Se + lin + Se + "PAGO ANTICIPADO - REPARTO")
  702.         Else
  703.             Insert Into comando;
  704.                 VALUES ("]" + Se + lin + Se + "PAGO ANTICIPADO - RETIRA")
  705.         Endif
  706.     Case This.lReparto
  707.         Insert Into comando;
  708.             VALUES ("]" + Se + lin + Se + "MERCADERIA DE REPARTO")
  709.     Case !This.lReparto
  710.         Insert Into comando;
  711.             VALUES ("]" + Se + lin + Se + "MERCADERIA PARA RETIRAR")
  712.     Otherwise
  713.         Insert Into comando;
  714.             VALUES ("]" + Se + lin + Se + "DEVOLUCIONES DENTRO DE LAS 48 HRS.")
  715.     Endcase
  716.  
  717.     lin = Str(Val(lin)+1,1,0)
  718.     This.letras.dicenum(m.nTOTAL)
  719.     Insert Into comando;
  720.         VALUES ( "]" + Se + lin + Se + ;
  721.         "SON:" + This.letras.retorno)
  722.  
  723.     lin = "11"
  724.  
  725. &&especifico las formas de cancelacion que posee la factura
  726.     If pagos.adic1 > 0 .Or. pagos.plazo1 > 0
  727.         Insert Into comando;
  728.             VALUES ( "]" + Se + lin + Se + ;
  729.             "OPCION DE PAGO: Hasta el "+;
  730.             Dtoc(Thisform.txtFecha.Value+This.dias())+ " "+;
  731.             STR(pagos.adic1)+" % Desc. $ "+;
  732.             STR(m.nTOTAL*pagos.adic1/100,08,2)+;
  733.             " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic1)/100),10,2))
  734.     Else
  735.         If Inlist(pagos.pago,'00','01','02')
  736.             Insert Into comando;
  737.                 VALUES ( "]" + Se + lin + Se + ;
  738.                 "OPCION DE PAGO: Contado Efectivo"+;
  739.                 " 3% Desc. "+;
  740.                 " Paga $ "+ Str(m.nTOTAL,10,2))
  741.         Else
  742.             Insert Into comando;
  743.                 VALUES ( "]" + Se + lin + Se + Chr(127))
  744.         Endif
  745.     Endif
  746.  
  747.     lin = Str(Val(lin)+1,2,0)
  748.  
  749.     If pagos.adic2 > 0 .Or. pagos.plazo2 > 0
  750.         If Isnull(pagos.dia) Or Empty(pagos.dia)
  751.             Insert Into comando;
  752.                 VALUES ( "]" + Se + lin + Se +;
  753.                 "OPCION DE PAGO: Hasta el "+ ;
  754.                 DTOC(This.FechaVen(Thisform.txtFecha.Value))+"  "+;
  755.                 STR(pagos.adic2)+" % Desc. $ ";
  756.                 +Str(m.nTOTAL*pagos.adic2/100,08,2)+;
  757.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  758.         Else
  759.             If pagos.pago = '51'
  760. *!* Pongo esto para que en esta condicion no me sume los dias de ADIC2
  761.                 Insert Into comando;
  762.                     VALUES ("]" + Se + lin + Se +  ;
  763.                     "OPCION DE PAGO: Hasta el "+ ;
  764.                     DTOC(pagos.dia)+"  "+;
  765.                     STR(pagos.adic2)+" % Desc. $ "+;
  766.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  767.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  768.             Else
  769.                 Insert Into comando;
  770.                     VALUES ("]" + Se + lin + Se +  ;
  771.                     "OPCION DE PAGO: Hasta el "+ ;
  772.                     DTOC(This.FechaVen(Thisform.txtFecha.Value))+"  "+;
  773.                     STR(pagos.adic2)+" % Desc. $ "+;
  774.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  775.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  776.             Endif
  777.         Endif
  778.     Else
  779.         Insert Into comando;
  780.             VALUES ( "]" + Se + lin + Se + Chr(127) )
  781.     Endif
  782.  
  783.     lin = Str(Val(lin)+1,2,0)
  784.  
  785.     If pagos.adic3 > 0 .Or. pagos.plazo3 >0
  786.         If Isnull(pagos.dia) Or Empty(pagos.dia)
  787.             Insert Into comando;
  788.                 VALUES ("]" + Se + lin + Se + ;
  789.                 "OPCION DE PAGO: Hasta el "+ ;
  790.                 DTOC(Thisform.txtFecha.Value+Cast(pagos.dias1 As Integer))+"  "+;
  791.                 STR(pagos.adic3)+" % Desc. $ "+;
  792.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  793.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  794.         Else
  795.             Insert Into comando;
  796.                 VALUES ("]" + Se + lin + Se + ;
  797.                 "OPCION DE PAGO: Hasta el "+ ;
  798.                 DTOC(pagos.dia+Cast(pagos.dias1 As Integer))+"  "+;
  799.                 STR(pagos.adic3)+" % Desc. $ "+;
  800.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  801.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  802.         Endif
  803.     Else
  804.         Insert Into comando;
  805.             VALUES ("]" + Se + lin + Se + Chr(127))
  806.     Endif
  807.  
  808.     lin = Str(Val(lin)+1,2,0)
  809. *!*     Insert Into comando;
  810. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  811.     If m.nFlete > 0 Or m.nDRet > 0
  812.         If m.nFlete > 0
  813.             Insert Into comando;
  814.                 VALUES ("]" + Se + lin + Se + ;
  815.                 "Prec. de Merc. Incl. Flete "+ ;
  816.                 Transform(m.nFlete, "@$ 99,999,999.99"))
  817.         Else
  818.             Insert Into comando;
  819.                 VALUES ("]" + Se + lin + Se + ;
  820.                 "Merc. Incl. Desc p/RETIRA "+ ;
  821.                 Transform(m.nDRet, "@$ 99,999,999.99"))
  822.         Endif
  823.     Else
  824.         Insert Into comando;
  825.             VALUES ("]" + Se + lin + Se + Chr(127))
  826.     Endif
  827.  
  828. &&si se factura sobre remitos se imprimen los remitos afectados
  829.     If Thisform.viene = "X" &&hay q revisar esto para ver q cuando se factura de remitos se imprima
  830.         Insert Into comando;
  831.             VALUES ( Chr(147) + Se + "1" + Se + Substr(This.remitosafacturar,1,17))
  832.         If !Empty(Substr(This.remitosafacturar,19,20))
  833.             Insert Into comando;
  834.                 VALUES (Chr(147) + Se + "2" + Se + Substr(This.remitosafacturar,19,20))
  835.         Endif
  836.     Endif
  837. Else
  838.     If This.contado = 'N'
  839.         Insert Into comando;
  840.             values("]" + Se + lin + Se+;
  841.             " Saldo de CTA_CTE: $"+;
  842.             ALLTRIM(Str((m.salctacte),12,2)))
  843.         lin = '6'
  844.     Else
  845.         Insert Into comando;
  846.             values("]" + Se + lin + Se + Chr(127))
  847.         lin = '6'
  848.     Endif
  849.  
  850.     Insert Into comando;
  851.         VALUES ( "]" + Se + lin + Se + "Vendedor: "+Alltrim(goApp.User) )
  852.  
  853.     lin = '7'
  854.     Insert Into comando;
  855.         VALUES ("]" + Se + lin + Se + Chr(127))
  856.  
  857.     lin = '8'
  858.     Insert Into comando;
  859.         VALUES ("]" + Se + lin + Se + Chr(127))
  860.  
  861.     lin = '11'
  862. *!*     Insert Into comando;
  863. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  864.     Insert Into comando;
  865.         VALUES ("]" + Se + lin + Se + Chr(127))
  866. Endif
  867.  
  868. If This.Ticket="S"
  869.     Insert Into comando;
  870.         VALUES ( "]" + Se + "9" + Se +Chr(127))
  871.     Insert Into comando;
  872.         VALUES ("]" + Se + "10" + Se +Chr(127))
  873.     If This.condicion = 'C' And Val(sCliente) = 1
  874.         Insert Into comando;
  875.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  876.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  877.             " S/NOMBRE")
  878.     Else
  879.         Insert Into comando;
  880.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  881.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  882.             SUBSTR(Alltrim(thisformset.frmCliente.txtDomicilio.Value)+" "+Alltrim(loc.nombre)+;
  883.             " "+Alltrim(loc.provincia),1,40))
  884.     Endif
  885.  
  886. Else
  887. &&"["+sCliente+"] "+
  888.     Insert Into comando;
  889.         VALUES ( "b" + Se + "[" + sCliente + "] " + Substr(sNombre,1,40) + Se +;
  890.         ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se + ;
  891.         ALLTRIM(Thisform.txtDom.Value)+" ("+Alltrim(clientes.codpos)+") "+;
  892.         Alltrim(loc.nombre)+" "+Alltrim(loc.provincia))
  893. Endif
  894. If This.condicion <> "C"
  895.     Insert Into comando;
  896.         VALUES (Chr(64)+Se+TIPO_FACTURA+Se+"T")
  897. Else
  898. &&Definir tipo y num de factura afectado por nota de credito
  899.     Insert Into comando;
  900.         VALUES (Chr(147) + Se + "1" + Se + cre.tipoaf + " " + cre.numeroaf)
  901.     Insert Into comando;
  902.         VALUES (Chr(128)+Se+TIPO_FACTURA+Se+"T")
  903. Endif
  904.  
  905. &&el cursor "DET" posee los items a facturar
  906. Select("det")
  907. Go Top
  908. Do While ! Eof()
  909. *!* Create Cursor det;
  910. *!*     (cantidad n(12,4), unidad c(8), detalle c(40), total n(12,2), idArticulo int,;
  911. *!*     unitario n(12,2), costo n(12,2), montoiva n(12,2), montodgr n(12,2), montomuni N(12,2),;
  912. *!*     poriva n(12,2), tipoiva c(2))  
  913.     If det.unitario != 0
  914.         If This.clase = "A"
  915.             If This.Ticket = "S"
  916.                 Insert Into comando;
  917.                     VALUES ("A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  918.                 Insert Into comando;
  919.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + Se +;
  920.                     ALLTRIM(Str(det.cantidad,6,2)+"0")+ Se +;
  921.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  922.                     ALLTRIM(Str(det.poriva,5,2)) + Se +;
  923.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  924.             Else
  925.                 Insert Into comando;
  926.                     VALUES ("B" + Se + det.unidad +" "+det.detalle+ Se + ;
  927.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  928.                     Alltrim(Str(det.unitario,13,2)) + ;
  929.                     Se +Alltrim(Str(det.poriva,5,2)) + Se + ;
  930.                     "M" + Se + "0" + Se + "" + Se + "T")
  931.  
  932.             Endif
  933.         Else
  934.             If This.Ticket = "S"
  935.                 Insert Into comando;
  936.                     VALUES ( "A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  937.                 Insert Into comando;
  938.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + ;
  939.                     Se +Alltrim(Str(det.cantidad,6,2)+"0")+ Se + ;
  940.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  941.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  942.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  943.             Else
  944.                 Insert Into comando;
  945.                     VALUES ("B" + Se + det.unidad+" "+det.detalle+ Se +;
  946.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  947.                     ALLTRIM(Str(det.unitario,13,2)) + Se +;
  948.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  949.                     "M" + Se + "0" + Se + "" + Se + "T")
  950.             Endif
  951.         Endif
  952.     Endif
  953.     Select("det")
  954.     Skip
  955. Enddo
  956.  
  957.  
  958. If This.condicion <> "C"
  959.     If This.Ticket = "S"
  960.         If This.contado = "S"
  961.             Insert Into comando;
  962.                 VALUES (Chr(68)+ Se + Substr(formapago.detalle,1,30)+ Se + ;
  963.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  964.         Else
  965.             Insert Into comando;
  966.                 VALUES ( Chr(68)+ Se + Substr(formapago.detalle,1,30)+ ;
  967.                 Se + Alltrim(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  968.         Endif
  969.     Else
  970.         If This.contado = "S"
  971.             Insert Into comando;
  972.                 VALUES (Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  973.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  974.         Else
  975.             Insert Into comando;
  976.                 VALUES(Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  977.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  978.         Endif
  979.     Endif
  980. Endif
  981.  
  982. If This.condicion <> "C"
  983.     Insert Into comando;
  984.         VALUES (Chr(69))
  985. Else
  986.     Insert Into comando;
  987.         VALUES ( Chr(129) )
  988. Endif
  989.  
  990.  
  991. &&en esta parte copio el archivo con los comandos a la carpeta desde el cual
  992. &&el spooler de impresion lee el archivo
  993. If This.Ticket ="S"
  994. && si es ticket me fijo a cual impresora debo enviar
  995.     If lImpreFiscal
  996.         mtXt = Alltrim(impfis.dircoticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  997.         maNs = Alltrim(impfis.dirreticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  998.     Else
  999.         mtXt = Alltrim(parametr.dirco)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  1000.         maNs = Alltrim(parametr.dirre)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  1001.     Endif
  1002. *!*     cDirCom = "fpserver715" + "\impred.exe"
  1003. *!*     cDirCom = Fullpath(cDirCom)
  1004. *!* && Mato el proceso del spooler y lo vuelvo a cargar
  1005. *!*     This.killprocessbyname("impred.exe")
  1006. *!*     This.killprocessbyname("wspooler.exe")
  1007. *!*     oShell = Createobject("Shell.Application")
  1008. *!*     oShell.ShellExecute (cDirCom)
  1009. Else
  1010. &&aca envio a la 320
  1011.     If lImpreFiscal
  1012.         mtXt = Alltrim(impfis.dircofactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  1013.         maNs = Alltrim(impfis.dirrefactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  1014.     Else
  1015.         mtXt = Alltrim(parametr.dirco)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  1016.         maNs = Alltrim(parametr.dirre)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  1017.     Endif
  1018. Endif
  1019.  
  1020.  
  1021. Select("comando")
  1022. Goto Top
  1023. &&en caso de que tenga un archivo en la cola de impresion de la impresora
  1024. &&no se deja imprimir
  1025. *Browse
  1026. If File(mtXt)
  1027.     Messagebox("ATENCION: Ud. ya tiene un Documento en Cola de Impresión"+Chr(10)+Chr(13)+;
  1028.         " AGUARDE a que el mismo sea impreso o elimínelo luego vuelva a intentar")
  1029.     Return This.TodoOK
  1030. Else
  1031.     Copy To &mtXt Sdf
  1032.     If File(maNs)
  1033.         Erase &maNs
  1034.     Endif
  1035.     If File(Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  1036.         Erase (Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  1037.     Endif
  1038.     Wait Windows 'Esperando Respuesta del Controlador Fiscal...' Nowait
  1039.     fd = -1
  1040.     intentos =1
  1041.     Do While fd < 0 .And. Lastkey() != 27
  1042.         fd = Fopen(maNs, 0)
  1043.         This.LeerSpooler("T")
  1044.         If intentos = 30
  1045.             Messagebox("ATENCION: Verifique que el Controlador Esté Conectado y Encendido. " + Chr(10) + Chr(13)+ ;
  1046.                 "Verifique además que el Programa Spooler se esté ejecutando " + Chr(10) + Chr(13)+ ;
  1047.                 "en el equipo al cual se encuentra conectado el Controlador Fiscal")
  1048.             This.LeerSpooler("T")
  1049.         Endif
  1050.         If intentos = 70
  1051.             Messagebox("ATENCION: Tiempo de Espera Agotado !!! Presione ESC. para cancelar este Comprobante")
  1052.             This.LeerSpooler("T")
  1053.         Endif
  1054.         intentos = intentos + 1
  1055. *For i=1 To 100
  1056. *Next
  1057.         Inkey(1)
  1058.         If Lastkey() = 27
  1059.             If Substr(comando.comando,17,16) = "Impresor Ocupado"
  1060.                 Messagebox("ATENCION: No se aconseja cancelar este documento por programa, "+;
  1061.                     CHR(10)+Chr(13)+"La impresora ya lo ha procesado y saldrá impreso"+;
  1062.                     CHR(10)+Chr(13)+ "una vez que esta se ponga en linea")
  1063.             Endif
  1064.             If Messagebox("ATENCION: Realmente desea Cancelar la Emisión de este Documento??",4+256) = 6
  1065.                 Messagebox(" Se proceder  a Cancelar el Documento por Sistema"+;
  1066.                     CHR(10)+Chr(13)+" Verifique que la impresora también lo haya Cancelado.")
  1067.                 Keyboard '{ESC}'
  1068.             Else
  1069.                 Keyboard ""
  1070.             Endif
  1071.         Endif
  1072.     Enddo
  1073.     If Lastkey() = 27.Or. fd < 0
  1074.         If File(mtXt)
  1075.             Erase &mtXt
  1076.         Endif
  1077.         fd = Fopen((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"), 0)
  1078.         If fd < 0
  1079.             Messagebox("Operación Cancelada: ERROR de comunicaciones con el Controlador.; Probablemente no se este ejecutando Spooler. ")
  1080.         Else
  1081.             fd =Fclose(fd)
  1082.             This.LeerSpooler("T")
  1083.         Endif
  1084.     Else
  1085.         fd = Fclose(fd)
  1086.         Select("comando")
  1087.         Zap
  1088.         Append From &maNs Sdf
  1089.         Goto Bottom
  1090.         This.numero = Val(Substr(comando.comando,35,8))
  1091.         If This.numero <> 0
  1092.             SQLExec(goApp.nCon, "select * from puntero where sucursal=?param.sucursal","puntero")
  1093.             If This.Ticket = "S"
  1094.                 If This.MasDeMil
  1095.                     This.numero = Val('0009'+strzero(This.numero,8))
  1096.                 Else
  1097.                     If lImpreFiscal
  1098.                         This.numero = Val(impfis.PtoVtaTicket+strzero(This.numero,8))
  1099.                     Else
  1100.                         If Param.sucursal=0
  1101.                             If File("c:\0009.txt")
  1102.                                 This.numero = Val(strzero(9,4)+strzero(This.numero,8))
  1103.                             Else
  1104.                                 This.numero = Val(strzero(puntero.pvta_tic,4)+strzero(This.numero,8))
  1105.                             Endif
  1106.                         Else
  1107.                             If Param.sucursal = 1
  1108.                                 This.numero = Val(strzero(8,4)+strzero(This.numero,8))
  1109.                             Endif
  1110.                         Endif
  1111.                     Endif
  1112.                 Endif
  1113.             Else
  1114.                 If lImpreFiscal
  1115.                     This.numero = Val(impfis.PtoVtaFac+strzero(This.numero,8))
  1116.                 Else
  1117.                     This.numero = Val(strzero(puntero.pvta_fac,4)+strzero(This.numero,8))
  1118.                 Endif
  1119.             Endif
  1120.             This.TodoOK = .T.
  1121.         Endif
  1122.     Endif
  1123.     If File((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"))
  1124.         Erase Alltrim(paramfac.dirpa)+"SPOOLER.LOG"
  1125.     Endif
  1126. Endif
  1127. *This.killprocessbyname("impred.exe")
  1128. *This.killprocessbyname("wspooler.exe")
  1129.  
  1130. Set Talk &cTalk
  1131. Return This.Todo
  1132. *!*     This.ticket = This.DefineComp()
  1133. *!* Enddo
  1134. This.Ticket = 'S'
  1135. Se = Chr(28)  &&separador de comandos
  1136. &&this.condicion indica si es nota de credito o factura o nota de debito
  1137. If This.condicion <> "C"
  1138.     If This.condicion = "D"  &&nota de debito
  1139.         If This.clase = "B"
  1140.             TIPO_FACTURA = "E"
  1141.         Else
  1142.             TIPO_FACTURA = "D"
  1143.         Endif
  1144.     Else
  1145. && si no es nota de debito ni credito es factura
  1146.         If This.clase = "B" Or this.clase = "C"
  1147.             TIPO_FACTURA = "B"
  1148.         Else
  1149.             TIPO_FACTURA = "A"
  1150.         Endif
  1151.     Endif
  1152. Else
  1153.     If This.clase = "B"
  1154.         TIPO_FACTURA = "S"
  1155.     Else
  1156.         TIPO_FACTURA = "R"
  1157.     Endif
  1158. Endif
  1159.  
  1160. &&traigo la tabla de parametros
  1161. *!* If SQLExec(Thisform.con, "select * from parametr","parametr") = -1
  1162. *!*     Messagebox("Se ha producido un error al recuperar el tipo de Documento" + Chr(10)+Chr(13)+Message(),0+48,"ERROR")
  1163. *!*     Return -1
  1164. *!* Endif
  1165.  
  1166. &&indica si el cliente tiene que poseer cuit
  1167. If tiporesp.obligacuit
  1168.     If Empty( Val( Strtran( clientes.cuit, "-" ) ) )
  1169.         Messagebox ("ATENCION: Falta Registrar CUIT de Cliente", 0+48, "CUIT")
  1170.         Do While Val(ndocu) < 2
  1171.             ndocu = Inputbox("Ingrese CUIT")
  1172.         Enddo
  1173.         ndocu = Alltrim( Strtran( ndocu, "-" ) )
  1174.     Else
  1175.         TIPO_DOCU = 'C' &&tiporesp.tipo_iva &&"C"
  1176.         ndocu = Alltrim( Strtran( clientes.cuit, "-" ) )
  1177.     Endif
  1178. Else
  1179.     If SQLExec(goApp.nCon, "select * from tipodoc where codigo=?clientes.tipodocu","tipodoc") = -1
  1180.         goApp.Error()
  1181.         Return -1
  1182.     Endif
  1183.     If Reccount("tipodoc") > 0
  1184.         TIPO_DOCU = tipodoc.tipo
  1185.     Else
  1186.         TIPO_DOCU = '2'
  1187.     Endif
  1188.     ndocu = Alltrim(Str(clientes.dni))
  1189.     If Val(ndocu) < 2
  1190.         ndocu = '11111111'
  1191.     Endif
  1192. Endif
  1193.  
  1194. TIPO_IVA = tiporesp.TIPOIVA
  1195. Select("comando")
  1196.  
  1197. &&me fijo si es ticket factura o factura
  1198. If This.Ticket = "S"
  1199.     lin = "5"
  1200. Else
  1201.     lin = "3"
  1202. Endif
  1203.  
  1204. If This.Ticket = "N"
  1205. &&en caso de ser factura imprimo todo el encabezado que va en la factura
  1206.     Select("comando")
  1207.     Insert Into comando;
  1208.         VALUES( "]" + Se + "1" + Se + Chr(127) )
  1209.     Insert Into comando;
  1210.         VALUES( "]" + Se + "2" + Se + Chr(127) )
  1211.  
  1212.     Insert Into comando;
  1213.         values( "]" + Se + "2" + Se + "Ing.Brut. 914-532186-1"  )
  1214.     If This.contado = "N"
  1215.         Insert Into comando;
  1216.             VALUES ("]" + Se + lin + Se + ;
  1217.             "Vendedor: "+Alltrim(vendedor.nom_ven)+;
  1218.             SPACE(10)+"Vencimiento de este Comp.: "+;
  1219.             DTOC(This.FechaVen(Thisform.txtFecha.Value))+;
  1220.             " Saldo Actual de CTA_CTE(S.E.U.O.): $"+;
  1221.             ALLTRIM(Str((m.salctacte),12,2)))
  1222.     Else
  1223.         Insert Into comando;
  1224.             VALUES ("]" + Se + lin + Se + "Vendedor: "+;
  1225.             ALLTRIM(vendedor.nom_ven)+;
  1226.             SPACE(10)+"Vencimiento de este Comp.: "+;
  1227.             DTOC(This.FechaVen(Thisform.txtFecha.Value)))
  1228.     Endif
  1229.  
  1230.     lin = Str(Val(lin)+1,1,0)
  1231.  
  1232.     Do Case
  1233.     Case Used("obsfac")
  1234.         Insert Into comando;
  1235.             VALUES ("]" + Se + lin + Se + "OBS.: "+Alltrim(obsfac.obs1)+Alltrim(obsfac.obs2))
  1236.     Case This.pagoanticipado &&det.pagoanticipado
  1237.         If det.reparto
  1238.             Insert Into comando;
  1239.                 VALUES ("]" + Se + lin + Se + "PAGO ANTICIPADO - REPARTO")
  1240.         Else
  1241.             Insert Into comando;
  1242.                 VALUES ("]" + Se + lin + Se + "PAGO ANTICIPADO - RETIRA")
  1243.         Endif
  1244.     Case This.lReparto
  1245.         Insert Into comando;
  1246.             VALUES ("]" + Se + lin + Se + "MERCADERIA DE REPARTO")
  1247.     Case !This.lReparto
  1248.         Insert Into comando;
  1249.             VALUES ("]" + Se + lin + Se + "MERCADERIA PARA RETIRAR")
  1250.     Otherwise
  1251.         Insert Into comando;
  1252.             VALUES ("]" + Se + lin + Se + "DEVOLUCIONES DENTRO DE LAS 48 HRS.")
  1253.     Endcase
  1254.  
  1255.     lin = Str(Val(lin)+1,1,0)
  1256.     This.letras.dicenum(m.nTOTAL)
  1257.     Insert Into comando;
  1258.         VALUES ( "]" + Se + lin + Se + ;
  1259.         "SON:" + This.letras.retorno)
  1260.  
  1261.     lin = "11"
  1262.  
  1263. &&especifico las formas de cancelacion que posee la factura
  1264.     If pagos.adic1 > 0 .Or. pagos.plazo1 > 0
  1265.         Insert Into comando;
  1266.             VALUES ( "]" + Se + lin + Se + ;
  1267.             "OPCION DE PAGO: Hasta el "+;
  1268.             Dtoc(Thisform.txtFecha.Value+This.dias())+ " "+;
  1269.             STR(pagos.adic1)+" % Desc. $ "+;
  1270.             STR(m.nTOTAL*pagos.adic1/100,08,2)+;
  1271.             " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic1)/100),10,2))
  1272.     Else
  1273.         If Inlist(pagos.pago,'00','01','02')
  1274.             Insert Into comando;
  1275.                 VALUES ( "]" + Se + lin + Se + ;
  1276.                 "OPCION DE PAGO: Contado Efectivo"+;
  1277.                 " 3% Desc. "+;
  1278.                 " Paga $ "+ Str(m.nTOTAL,10,2))
  1279.         Else
  1280.             Insert Into comando;
  1281.                 VALUES ( "]" + Se + lin + Se + Chr(127))
  1282.         Endif
  1283.     Endif
  1284.  
  1285.     lin = Str(Val(lin)+1,2,0)
  1286.  
  1287.     If pagos.adic2 > 0 .Or. pagos.plazo2 > 0
  1288.         If Isnull(pagos.dia) Or Empty(pagos.dia)
  1289.             Insert Into comando;
  1290.                 VALUES ( "]" + Se + lin + Se +;
  1291.                 "OPCION DE PAGO: Hasta el "+ ;
  1292.                 DTOC(This.FechaVen(Thisform.txtFecha.Value))+"  "+;
  1293.                 STR(pagos.adic2)+" % Desc. $ ";
  1294.                 +Str(m.nTOTAL*pagos.adic2/100,08,2)+;
  1295.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  1296.         Else
  1297.             If pagos.pago = '51'
  1298. *!* Pongo esto para que en esta condicion no me sume los dias de ADIC2
  1299.                 Insert Into comando;
  1300.                     VALUES ("]" + Se + lin + Se +  ;
  1301.                     "OPCION DE PAGO: Hasta el "+ ;
  1302.                     DTOC(pagos.dia)+"  "+;
  1303.                     STR(pagos.adic2)+" % Desc. $ "+;
  1304.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  1305.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  1306.             Else
  1307.                 Insert Into comando;
  1308.                     VALUES ("]" + Se + lin + Se +  ;
  1309.                     "OPCION DE PAGO: Hasta el "+ ;
  1310.                     DTOC(This.FechaVen(Thisform.txtFecha.Value))+"  "+;
  1311.                     STR(pagos.adic2)+" % Desc. $ "+;
  1312.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  1313.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  1314.             Endif
  1315.         Endif
  1316.     Else
  1317.         Insert Into comando;
  1318.             VALUES ( "]" + Se + lin + Se + Chr(127) )
  1319.     Endif
  1320.  
  1321.     lin = Str(Val(lin)+1,2,0)
  1322.  
  1323.     If pagos.adic3 > 0 .Or. pagos.plazo3 >0
  1324.         If Isnull(pagos.dia) Or Empty(pagos.dia)
  1325.             Insert Into comando;
  1326.                 VALUES ("]" + Se + lin + Se + ;
  1327.                 "OPCION DE PAGO: Hasta el "+ ;
  1328.                 DTOC(Thisform.txtFecha.Value+Cast(pagos.dias1 As Integer))+"  "+;
  1329.                 STR(pagos.adic3)+" % Desc. $ "+;
  1330.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  1331.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  1332.         Else
  1333.             Insert Into comando;
  1334.                 VALUES ("]" + Se + lin + Se + ;
  1335.                 "OPCION DE PAGO: Hasta el "+ ;
  1336.                 DTOC(pagos.dia+Cast(pagos.dias1 As Integer))+"  "+;
  1337.                 STR(pagos.adic3)+" % Desc. $ "+;
  1338.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  1339.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  1340.         Endif
  1341.     Else
  1342.         Insert Into comando;
  1343.             VALUES ("]" + Se + lin + Se + Chr(127))
  1344.     Endif
  1345.  
  1346.     lin = Str(Val(lin)+1,2,0)
  1347. *!*     Insert Into comando;
  1348. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  1349.     If m.nFlete > 0 Or m.nDRet > 0
  1350.         If m.nFlete > 0
  1351.             Insert Into comando;
  1352.                 VALUES ("]" + Se + lin + Se + ;
  1353.                 "Prec. de Merc. Incl. Flete "+ ;
  1354.                 Transform(m.nFlete, "@$ 99,999,999.99"))
  1355.         Else
  1356.             Insert Into comando;
  1357.                 VALUES ("]" + Se + lin + Se + ;
  1358.                 "Merc. Incl. Desc p/RETIRA "+ ;
  1359.                 Transform(m.nDRet, "@$ 99,999,999.99"))
  1360.         Endif
  1361.     Else
  1362.         Insert Into comando;
  1363.             VALUES ("]" + Se + lin + Se + Chr(127))
  1364.     Endif
  1365.  
  1366. &&si se factura sobre remitos se imprimen los remitos afectados
  1367.     If Thisform.viene = "X" &&hay q revisar esto para ver q cuando se factura de remitos se imprima
  1368.         Insert Into comando;
  1369.             VALUES ( Chr(147) + Se + "1" + Se + Substr(This.remitosafacturar,1,17))
  1370.         If !Empty(Substr(This.remitosafacturar,19,20))
  1371.             Insert Into comando;
  1372.                 VALUES (Chr(147) + Se + "2" + Se + Substr(This.remitosafacturar,19,20))
  1373.         Endif
  1374.     Endif
  1375. Else
  1376.     If This.contado = 'N'
  1377.         Insert Into comando;
  1378.             values("]" + Se + lin + Se+;
  1379.             " Saldo de CTA_CTE: $"+;
  1380.             ALLTRIM(Str((m.salctacte),12,2)))
  1381.         lin = '6'
  1382.     Else
  1383.         Insert Into comando;
  1384.             values("]" + Se + lin + Se + Chr(127))
  1385.         lin = '6'
  1386.     Endif
  1387.  
  1388.     Insert Into comando;
  1389.         VALUES ( "]" + Se + lin + Se + "Vendedor: "+Alltrim(goApp.User) )
  1390.  
  1391.     lin = '7'
  1392.     Insert Into comando;
  1393.         VALUES ("]" + Se + lin + Se + Chr(127))
  1394.  
  1395.     lin = '8'
  1396.     Insert Into comando;
  1397.         VALUES ("]" + Se + lin + Se + Chr(127))
  1398.  
  1399.     lin = '11'
  1400. *!*     Insert Into comando;
  1401. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  1402.     Insert Into comando;
  1403.         VALUES ("]" + Se + lin + Se + Chr(127))
  1404. Endif
  1405.  
  1406. If This.Ticket="S"
  1407.     Insert Into comando;
  1408.         VALUES ( "]" + Se + "9" + Se +Chr(127))
  1409.     Insert Into comando;
  1410.         VALUES ("]" + Se + "10" + Se +Chr(127))
  1411.     If This.condicion = 'C' And Val(sCliente) = 1
  1412.         Insert Into comando;
  1413.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  1414.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  1415.             " S/NOMBRE")
  1416.     Else
  1417.         Insert Into comando;
  1418.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  1419.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  1420.             SUBSTR(Alltrim(thisformset.frmCliente.txtDomicilio.Value)+" "+Alltrim(loc.nombre)+;
  1421.             " "+Alltrim(loc.provincia),1,40))
  1422.     Endif
  1423.  
  1424. Else
  1425. &&"["+sCliente+"] "+
  1426.     Insert Into comando;
  1427.         VALUES ( "b" + Se + "[" + sCliente + "] " + Substr(sNombre,1,40) + Se +;
  1428.         ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se + ;
  1429.         ALLTRIM(Thisform.txtDom.Value)+" ("+Alltrim(clientes.codpos)+") "+;
  1430.         Alltrim(loc.nombre)+" "+Alltrim(loc.provincia))
  1431. Endif
  1432. If This.condicion <> "C"
  1433.     Insert Into comando;
  1434.         VALUES (Chr(64)+Se+TIPO_FACTURA+Se+"T")
  1435. Else
  1436. &&Definir tipo y num de factura afectado por nota de credito
  1437.     Insert Into comando;
  1438.         VALUES (Chr(147) + Se + "1" + Se + cre.tipoaf + " " + cre.numeroaf)
  1439.     Insert Into comando;
  1440.         VALUES (Chr(128)+Se+TIPO_FACTURA+Se+"T")
  1441. Endif
  1442.  
  1443. &&el cursor "DET" posee los items a facturar
  1444. Select("det")
  1445. Go Top
  1446. Do While ! Eof()
  1447. *!* Create Cursor det;
  1448. *!*     (cantidad n(12,4), unidad c(8), detalle c(40), total n(12,2), idArticulo int,;
  1449. *!*     unitario n(12,2), costo n(12,2), montoiva n(12,2), montodgr n(12,2), montomuni N(12,2),;
  1450. *!*     poriva n(12,2), tipoiva c(2))  
  1451.     If det.unitario != 0
  1452.         If This.clase = "A"
  1453.             If This.Ticket = "S"
  1454.                 Insert Into comando;
  1455.                     VALUES ("A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  1456.                 Insert Into comando;
  1457.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + Se +;
  1458.                     ALLTRIM(Str(det.cantidad,6,2)+"0")+ Se +;
  1459.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  1460.                     ALLTRIM(Str(det.poriva,5,2)) + Se +;
  1461.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  1462.             Else
  1463.                 Insert Into comando;
  1464.                     VALUES ("B" + Se + det.unidad +" "+det.detalle+ Se + ;
  1465.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  1466.                     Alltrim(Str(det.unitario,13,2)) + ;
  1467.                     Se +Alltrim(Str(det.poriva,5,2)) + Se + ;
  1468.                     "M" + Se + "0" + Se + "" + Se + "T")
  1469.  
  1470.             Endif
  1471.         Else
  1472.             If This.Ticket = "S"
  1473.                 Insert Into comando;
  1474.                     VALUES ( "A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  1475.                 Insert Into comando;
  1476.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + ;
  1477.                     Se +Alltrim(Str(det.cantidad,6,2)+"0")+ Se + ;
  1478.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  1479.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  1480.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  1481.             Else
  1482.                 Insert Into comando;
  1483.                     VALUES ("B" + Se + det.unidad+" "+det.detalle+ Se +;
  1484.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  1485.                     ALLTRIM(Str(det.unitario,13,2)) + Se +;
  1486.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  1487.                     "M" + Se + "0" + Se + "" + Se + "T")
  1488.             Endif
  1489.         Endif
  1490.     Endif
  1491.     Select("det")
  1492.     Skip
  1493. Enddo
  1494.  
  1495.  
  1496. If This.condicion <> "C"
  1497.     If This.Ticket = "S"
  1498.         If This.contado = "S"
  1499.             Insert Into comando;
  1500.                 VALUES (Chr(68)+ Se + Substr(formapago.detalle,1,30)+ Se + ;
  1501.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  1502.         Else
  1503.             Insert Into comando;
  1504.                 VALUES ( Chr(68)+ Se + Substr(formapago.detalle,1,30)+ ;
  1505.                 Se + Alltrim(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  1506.         Endif
  1507.     Else
  1508.         If This.contado = "S"
  1509.             Insert Into comando;
  1510.                 VALUES (Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  1511.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  1512.         Else
  1513.             Insert Into comando;
  1514.                 VALUES(Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  1515.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  1516.         Endif
  1517.     Endif
  1518. Endif
  1519.  
  1520. If This.condicion <> "C"
  1521.     Insert Into comando;
  1522.         VALUES (Chr(69))
  1523. Else
  1524.     Insert Into comando;
  1525.         VALUES ( Chr(129) )
  1526. Endif
  1527.  
  1528.  
  1529. &&en esta parte copio el archivo con los comandos a la carpeta desde el cual
  1530. &&el spooler de impresion lee el archivo
  1531. If This.Ticket ="S"
  1532. && si es ticket me fijo a cual impresora debo enviar
  1533.     If lImpreFiscal
  1534.         mtXt = Alltrim(impfis.dircoticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  1535.         maNs = Alltrim(impfis.dirreticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  1536.     Else
  1537.         mtXt = Alltrim(parametr.dirco)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  1538.         maNs = Alltrim(parametr.dirre)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  1539.     Endif
  1540. *!*     cDirCom = "fpserver715" + "\impred.exe"
  1541. *!*     cDirCom = Fullpath(cDirCom)
  1542. *!* && Mato el proceso del spooler y lo vuelvo a cargar
  1543. *!*     This.killprocessbyname("impred.exe")
  1544. *!*     This.killprocessbyname("wspooler.exe")
  1545. *!*     oShell = Createobject("Shell.Application")
  1546. *!*     oShell.ShellExecute (cDirCom)
  1547. Else
  1548. &&aca envio a la 320
  1549.     If lImpreFiscal
  1550.         mtXt = Alltrim(impfis.dircofactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  1551.         maNs = Alltrim(impfis.dirrefactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  1552.     Else
  1553.         mtXt = Alltrim(parametr.dirco)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  1554.         maNs = Alltrim(parametr.dirre)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  1555.     Endif
  1556. Endif
  1557.  
  1558.  
  1559. Select("comando")
  1560. Goto Top
  1561. &&en caso de que tenga un archivo en la cola de impresion de la impresora
  1562. &&no se deja imprimir
  1563. *Browse
  1564. If File(mtXt)
  1565.     Messagebox("ATENCION: Ud. ya tiene un Documento en Cola de Impresión"+Chr(10)+Chr(13)+;
  1566.         " AGUARDE a que el mismo sea impreso o elimínelo luego vuelva a intentar")
  1567.     Return This.TodoOK
  1568. Else
  1569.     Copy To &mtXt Sdf
  1570.     If File(maNs)
  1571.         Erase &maNs
  1572.     Endif
  1573.     If File(Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  1574.         Erase (Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  1575.     Endif
  1576.     Wait Windows 'Esperando Respuesta del Controlador Fiscal...' Nowait
  1577.     fd = -1
  1578.     intentos =1
  1579.     Do While fd < 0 .And. Lastkey() != 27
  1580.         fd = Fopen(maNs, 0)
  1581.         This.LeerSpooler("T")
  1582.         If intentos = 30
  1583.             Messagebox("ATENCION: Verifique que el Controlador Esté Conectado y Encendido. " + Chr(10) + Chr(13)+ ;
  1584.                 "Verifique además que el Programa Spooler se esté ejecutando " + Chr(10) + Chr(13)+ ;
  1585.                 "en el equipo al cual se encuentra conectado el Controlador Fiscal")
  1586.             This.LeerSpooler("T")
  1587.         Endif
  1588.         If intentos = 70
  1589.             Messagebox("ATENCION: Tiempo de Espera Agotado !!! Presione ESC. para cancelar este Comprobante")
  1590.             This.LeerSpooler("T")
  1591.         Endif
  1592.         intentos = intentos + 1
  1593. *For i=1 To 100
  1594. *Next
  1595.         Inkey(1)
  1596.         If Lastkey() = 27
  1597.             If Substr(comando.comando,17,16) = "Impresor Ocupado"
  1598.                 Messagebox("ATENCION: No se aconseja cancelar este documento por programa, "+;
  1599.                     CHR(10)+Chr(13)+"La impresora ya lo ha procesado y saldrá impreso"+;
  1600.                     CHR(10)+Chr(13)+ "una vez que esta se ponga en linea")
  1601.             Endif
  1602.             If Messagebox("ATENCION: Realmente desea Cancelar la Emisión de este Documento??",4+256) = 6
  1603.                 Messagebox(" Se proceder  a Cancelar el Documento por Sistema"+;
  1604.                     CHR(10)+Chr(13)+" Verifique que la impresora también lo haya Cancelado.")
  1605.                 Keyboard '{ESC}'
  1606.             Else
  1607.                 Keyboard ""
  1608.             Endif
  1609.         Endif
  1610.     Enddo
  1611.     If Lastkey() = 27.Or. fd < 0
  1612.         If File(mtXt)
  1613.             Erase &mtXt
  1614.         Endif
  1615.         fd = Fopen((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"), 0)
  1616.         If fd < 0
  1617.             Messagebox("Operación Cancelada: ERROR de comunicaciones con el Controlador.; Probablemente no se este ejecutando Spooler. ")
  1618.         Else
  1619.             fd =Fclose(fd)
  1620.             This.LeerSpooler("T")
  1621.         Endif
  1622.     Else
  1623.         fd = Fclose(fd)
  1624.         Select("comando")
  1625.         Zap
  1626.         Append From &maNs Sdf
  1627.         Goto Bottom
  1628.         This.numero = Val(Substr(comando.comando,35,8))
  1629.         If This.numero <> 0
  1630.             SQLExec(goApp.nCon, "select * from puntero where sucursal=?param.sucursal","puntero")
  1631.             If This.Ticket = "S"
  1632.                 If This.MasDeMil
  1633.                     This.numero = Val('0009'+strzero(This.numero,8))
  1634.                 Else
  1635.                     If lImpreFiscal
  1636.                         This.numero = Val(impfis.PtoVtaTicket+strzero(This.numero,8))
  1637.                     Else
  1638.                         If Param.sucursal=0
  1639.                             If File("c:\0009.txt")
  1640.                                 This.numero = Val(strzero(9,4)+strzero(This.numero,8))
  1641.                             Else
  1642.                                 This.numero = Val(strzero(puntero.pvta_tic,4)+strzero(This.numero,8))
  1643.                             Endif
  1644.                         Else
  1645.                             If Param.sucursal = 1
  1646.                                 This.numero = Val(strzero(8,4)+strzero(This.numero,8))
  1647.                             Endif
  1648.                         Endif
  1649.                     Endif
  1650.                 Endif
  1651.             Else
  1652.                 If lImpreFiscal
  1653.                     This.numero = Val(impfis.PtoVtaFac+strzero(This.numero,8))
  1654.                 Else
  1655.                     This.numero = Val(strzero(puntero.pvta_fac,4)+strzero(This.numero,8))
  1656.                 Endif
  1657.             Endif
  1658.             This.TodoOK = .T.
  1659.         Endif
  1660.     Endif
  1661.     If File((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"))
  1662.         Erase Alltrim(paramfac.dirpa)+"SPOOLER.LOG"
  1663.     Endif
  1664. Endif
  1665. *This.killprocessbyname("impred.exe")
  1666. *This.killprocessbyname("wspooler.exe")
  1667.  
  1668. Set Talk &cTalk
  1669. Return This.Todo
  1670. *!* Enddo
  1671. This.Ticket = 'S'
  1672. Se = Chr(28)  &&separador de comandos
  1673. &&this.condicion indica si es nota de credito o factura o nota de debito
  1674. If This.condicion <> "C"
  1675.     If This.condicion = "D"  &&nota de debito
  1676.         If This.clase = "B"
  1677.             TIPO_FACTURA = "E"
  1678.         Else
  1679.             TIPO_FACTURA = "D"
  1680.         Endif
  1681.     Else
  1682. && si no es nota de debito ni credito es factura
  1683.         If This.clase = "B" Or this.clase = "C"
  1684.             TIPO_FACTURA = "B"
  1685.         Else
  1686.             TIPO_FACTURA = "A"
  1687.         Endif
  1688.     Endif
  1689. Else
  1690.     If This.clase = "B"
  1691.         TIPO_FACTURA = "S"
  1692.     Else
  1693.         TIPO_FACTURA = "R"
  1694.     Endif
  1695. Endif
  1696.  
  1697. &&traigo la tabla de parametros
  1698. *!* If SQLExec(Thisform.con, "select * from parametr","parametr") = -1
  1699. *!*     Messagebox("Se ha producido un error al recuperar el tipo de Documento" + Chr(10)+Chr(13)+Message(),0+48,"ERROR")
  1700. *!*     Return -1
  1701. *!* Endif
  1702.  
  1703. &&indica si el cliente tiene que poseer cuit
  1704. If tiporesp.obligacuit
  1705.     If Empty( Val( Strtran( clientes.cuit, "-" ) ) )
  1706.         Messagebox ("ATENCION: Falta Registrar CUIT de Cliente", 0+48, "CUIT")
  1707.         Do While Val(ndocu) < 2
  1708.             ndocu = Inputbox("Ingrese CUIT")
  1709.         Enddo
  1710.         ndocu = Alltrim( Strtran( ndocu, "-" ) )
  1711.     Else
  1712.         TIPO_DOCU = 'C' &&tiporesp.tipo_iva &&"C"
  1713.         ndocu = Alltrim( Strtran( clientes.cuit, "-" ) )
  1714.     Endif
  1715. Else
  1716.     If SQLExec(goApp.nCon, "select * from tipodoc where codigo=?clientes.tipodocu","tipodoc") = -1
  1717.         goApp.Error()
  1718.         Return -1
  1719.     Endif
  1720.     If Reccount("tipodoc") > 0
  1721.         TIPO_DOCU = tipodoc.tipo
  1722.     Else
  1723.         TIPO_DOCU = '2'
  1724.     Endif
  1725.     ndocu = Alltrim(Str(clientes.dni))
  1726.     If Val(ndocu) < 2
  1727.         ndocu = '11111111'
  1728.     Endif
  1729. Endif
  1730.  
  1731. TIPO_IVA = tiporesp.TIPOIVA
  1732. Select("comando")
  1733.  
  1734. &&me fijo si es ticket factura o factura
  1735. If This.Ticket = "S"
  1736.     lin = "5"
  1737. Else
  1738.     lin = "3"
  1739. Endif
  1740.  
  1741. If This.Ticket = "N"
  1742. &&en caso de ser factura imprimo todo el encabezado que va en la factura
  1743.     Select("comando")
  1744.     Insert Into comando;
  1745.         VALUES( "]" + Se + "1" + Se + Chr(127) )
  1746.     Insert Into comando;
  1747.         VALUES( "]" + Se + "2" + Se + Chr(127) )
  1748.  
  1749.     Insert Into comando;
  1750.         values( "]" + Se + "2" + Se + "Ing.Brut. 914-532186-1"  )
  1751.     If This.contado = "N"
  1752.         Insert Into comando;
  1753.             VALUES ("]" + Se + lin + Se + ;
  1754.             "Vendedor: "+Alltrim(vendedor.nom_ven)+;
  1755.             SPACE(10)+"Vencimiento de este Comp.: "+;
  1756.             DTOC(This.FechaVen(Thisform.txtFecha.Value))+;
  1757.             " Saldo Actual de CTA_CTE(S.E.U.O.): $"+;
  1758.             ALLTRIM(Str((m.salctacte),12,2)))
  1759.     Else
  1760.         Insert Into comando;
  1761.             VALUES ("]" + Se + lin + Se + "Vendedor: "+;
  1762.             ALLTRIM(vendedor.nom_ven)+;
  1763.             SPACE(10)+"Vencimiento de este Comp.: "+;
  1764.             DTOC(This.FechaVen(Thisform.txtFecha.Value)))
  1765.     Endif
  1766.  
  1767.     lin = Str(Val(lin)+1,1,0)
  1768.  
  1769.     Do Case
  1770.     Case Used("obsfac")
  1771.         Insert Into comando;
  1772.             VALUES ("]" + Se + lin + Se + "OBS.: "+Alltrim(obsfac.obs1)+Alltrim(obsfac.obs2))
  1773.     Case This.pagoanticipado &&det.pagoanticipado
  1774.         If det.reparto
  1775.             Insert Into comando;
  1776.                 VALUES ("]" + Se + lin + Se + "PAGO ANTICIPADO - REPARTO")
  1777.         Else
  1778.             Insert Into comando;
  1779.                 VALUES ("]" + Se + lin + Se + "PAGO ANTICIPADO - RETIRA")
  1780.         Endif
  1781.     Case This.lReparto
  1782.         Insert Into comando;
  1783.             VALUES ("]" + Se + lin + Se + "MERCADERIA DE REPARTO")
  1784.     Case !This.lReparto
  1785.         Insert Into comando;
  1786.             VALUES ("]" + Se + lin + Se + "MERCADERIA PARA RETIRAR")
  1787.     Otherwise
  1788.         Insert Into comando;
  1789.             VALUES ("]" + Se + lin + Se + "DEVOLUCIONES DENTRO DE LAS 48 HRS.")
  1790.     Endcase
  1791.  
  1792.     lin = Str(Val(lin)+1,1,0)
  1793.     This.letras.dicenum(m.nTOTAL)
  1794.     Insert Into comando;
  1795.         VALUES ( "]" + Se + lin + Se + ;
  1796.         "SON:" + This.letras.retorno)
  1797.  
  1798.     lin = "11"
  1799.  
  1800. &&especifico las formas de cancelacion que posee la factura
  1801.     If pagos.adic1 > 0 .Or. pagos.plazo1 > 0
  1802.         Insert Into comando;
  1803.             VALUES ( "]" + Se + lin + Se + ;
  1804.             "OPCION DE PAGO: Hasta el "+;
  1805.             Dtoc(Thisform.txtFecha.Value+This.dias())+ " "+;
  1806.             STR(pagos.adic1)+" % Desc. $ "+;
  1807.             STR(m.nTOTAL*pagos.adic1/100,08,2)+;
  1808.             " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic1)/100),10,2))
  1809.     Else
  1810.         If Inlist(pagos.pago,'00','01','02')
  1811.             Insert Into comando;
  1812.                 VALUES ( "]" + Se + lin + Se + ;
  1813.                 "OPCION DE PAGO: Contado Efectivo"+;
  1814.                 " 3% Desc. "+;
  1815.                 " Paga $ "+ Str(m.nTOTAL,10,2))
  1816.         Else
  1817.             Insert Into comando;
  1818.                 VALUES ( "]" + Se + lin + Se + Chr(127))
  1819.         Endif
  1820.     Endif
  1821.  
  1822.     lin = Str(Val(lin)+1,2,0)
  1823.  
  1824.     If pagos.adic2 > 0 .Or. pagos.plazo2 > 0
  1825.         If Isnull(pagos.dia) Or Empty(pagos.dia)
  1826.             Insert Into comando;
  1827.                 VALUES ( "]" + Se + lin + Se +;
  1828.                 "OPCION DE PAGO: Hasta el "+ ;
  1829.                 DTOC(This.FechaVen(Thisform.txtFecha.Value))+"  "+;
  1830.                 STR(pagos.adic2)+" % Desc. $ ";
  1831.                 +Str(m.nTOTAL*pagos.adic2/100,08,2)+;
  1832.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  1833.         Else
  1834.             If pagos.pago = '51'
  1835. *!* Pongo esto para que en esta condicion no me sume los dias de ADIC2
  1836.                 Insert Into comando;
  1837.                     VALUES ("]" + Se + lin + Se +  ;
  1838.                     "OPCION DE PAGO: Hasta el "+ ;
  1839.                     DTOC(pagos.dia)+"  "+;
  1840.                     STR(pagos.adic2)+" % Desc. $ "+;
  1841.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  1842.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  1843.             Else
  1844.                 Insert Into comando;
  1845.                     VALUES ("]" + Se + lin + Se +  ;
  1846.                     "OPCION DE PAGO: Hasta el "+ ;
  1847.                     DTOC(This.FechaVen(Thisform.txtFecha.Value))+"  "+;
  1848.                     STR(pagos.adic2)+" % Desc. $ "+;
  1849.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  1850.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  1851.             Endif
  1852.         Endif
  1853.     Else
  1854.         Insert Into comando;
  1855.             VALUES ( "]" + Se + lin + Se + Chr(127) )
  1856.     Endif
  1857.  
  1858.     lin = Str(Val(lin)+1,2,0)
  1859.  
  1860.     If pagos.adic3 > 0 .Or. pagos.plazo3 >0
  1861.         If Isnull(pagos.dia) Or Empty(pagos.dia)
  1862.             Insert Into comando;
  1863.                 VALUES ("]" + Se + lin + Se + ;
  1864.                 "OPCION DE PAGO: Hasta el "+ ;
  1865.                 DTOC(Thisform.txtFecha.Value+Cast(pagos.dias1 As Integer))+"  "+;
  1866.                 STR(pagos.adic3)+" % Desc. $ "+;
  1867.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  1868.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  1869.         Else
  1870.             Insert Into comando;
  1871.                 VALUES ("]" + Se + lin + Se + ;
  1872.                 "OPCION DE PAGO: Hasta el "+ ;
  1873.                 DTOC(pagos.dia+Cast(pagos.dias1 As Integer))+"  "+;
  1874.                 STR(pagos.adic3)+" % Desc. $ "+;
  1875.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  1876.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  1877.         Endif
  1878.     Else
  1879.         Insert Into comando;
  1880.             VALUES ("]" + Se + lin + Se + Chr(127))
  1881.     Endif
  1882.  
  1883.     lin = Str(Val(lin)+1,2,0)
  1884. *!*     Insert Into comando;
  1885. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  1886.     If m.nFlete > 0 Or m.nDRet > 0
  1887.         If m.nFlete > 0
  1888.             Insert Into comando;
  1889.                 VALUES ("]" + Se + lin + Se + ;
  1890.                 "Prec. de Merc. Incl. Flete "+ ;
  1891.                 Transform(m.nFlete, "@$ 99,999,999.99"))
  1892.         Else
  1893.             Insert Into comando;
  1894.                 VALUES ("]" + Se + lin + Se + ;
  1895.                 "Merc. Incl. Desc p/RETIRA "+ ;
  1896.                 Transform(m.nDRet, "@$ 99,999,999.99"))
  1897.         Endif
  1898.     Else
  1899.         Insert Into comando;
  1900.             VALUES ("]" + Se + lin + Se + Chr(127))
  1901.     Endif
  1902.  
  1903. &&si se factura sobre remitos se imprimen los remitos afectados
  1904.     If Thisform.viene = "X" &&hay q revisar esto para ver q cuando se factura de remitos se imprima
  1905.         Insert Into comando;
  1906.             VALUES ( Chr(147) + Se + "1" + Se + Substr(This.remitosafacturar,1,17))
  1907.         If !Empty(Substr(This.remitosafacturar,19,20))
  1908.             Insert Into comando;
  1909.                 VALUES (Chr(147) + Se + "2" + Se + Substr(This.remitosafacturar,19,20))
  1910.         Endif
  1911.     Endif
  1912. Else
  1913.     If This.contado = 'N'
  1914.         Insert Into comando;
  1915.             values("]" + Se + lin + Se+;
  1916.             " Saldo de CTA_CTE: $"+;
  1917.             ALLTRIM(Str((m.salctacte),12,2)))
  1918.         lin = '6'
  1919.     Else
  1920.         Insert Into comando;
  1921.             values("]" + Se + lin + Se + Chr(127))
  1922.         lin = '6'
  1923.     Endif
  1924.  
  1925.     Insert Into comando;
  1926.         VALUES ( "]" + Se + lin + Se + "Vendedor: "+Alltrim(goApp.User) )
  1927.  
  1928.     lin = '7'
  1929.     Insert Into comando;
  1930.         VALUES ("]" + Se + lin + Se + Chr(127))
  1931.  
  1932.     lin = '8'
  1933.     Insert Into comando;
  1934.         VALUES ("]" + Se + lin + Se + Chr(127))
  1935.  
  1936.     lin = '11'
  1937. *!*     Insert Into comando;
  1938. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  1939.     Insert Into comando;
  1940.         VALUES ("]" + Se + lin + Se + Chr(127))
  1941. Endif
  1942.  
  1943. If This.Ticket="S"
  1944.     Insert Into comando;
  1945.         VALUES ( "]" + Se + "9" + Se +Chr(127))
  1946.     Insert Into comando;
  1947.         VALUES ("]" + Se + "10" + Se +Chr(127))
  1948.     If This.condicion = 'C' And Val(sCliente) = 1
  1949.         Insert Into comando;
  1950.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  1951.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  1952.             " S/NOMBRE")
  1953.     Else
  1954.         Insert Into comando;
  1955.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  1956.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  1957.             SUBSTR(Alltrim(thisformset.frmCliente.txtDomicilio.Value)+" "+Alltrim(loc.nombre)+;
  1958.             " "+Alltrim(loc.provincia),1,40))
  1959.     Endif
  1960.  
  1961. Else
  1962. &&"["+sCliente+"] "+
  1963.     Insert Into comando;
  1964.         VALUES ( "b" + Se + "[" + sCliente + "] " + Substr(sNombre,1,40) + Se +;
  1965.         ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se + ;
  1966.         ALLTRIM(Thisform.txtDom.Value)+" ("+Alltrim(clientes.codpos)+") "+;
  1967.         Alltrim(loc.nombre)+" "+Alltrim(loc.provincia))
  1968. Endif
  1969. If This.condicion <> "C"
  1970.     Insert Into comando;
  1971.         VALUES (Chr(64)+Se+TIPO_FACTURA+Se+"T")
  1972. Else
  1973. &&Definir tipo y num de factura afectado por nota de credito
  1974.     Insert Into comando;
  1975.         VALUES (Chr(147) + Se + "1" + Se + cre.tipoaf + " " + cre.numeroaf)
  1976.     Insert Into comando;
  1977.         VALUES (Chr(128)+Se+TIPO_FACTURA+Se+"T")
  1978. Endif
  1979.  
  1980. &&el cursor "DET" posee los items a facturar
  1981. Select("det")
  1982. Go Top
  1983. Do While ! Eof()
  1984. *!* Create Cursor det;
  1985. *!*     (cantidad n(12,4), unidad c(8), detalle c(40), total n(12,2), idArticulo int,;
  1986. *!*     unitario n(12,2), costo n(12,2), montoiva n(12,2), montodgr n(12,2), montomuni N(12,2),;
  1987. *!*     poriva n(12,2), tipoiva c(2))  
  1988.     If det.unitario != 0
  1989.         If This.clase = "A"
  1990.             If This.Ticket = "S"
  1991.                 Insert Into comando;
  1992.                     VALUES ("A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  1993.                 Insert Into comando;
  1994.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + Se +;
  1995.                     ALLTRIM(Str(det.cantidad,6,2)+"0")+ Se +;
  1996.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  1997.                     ALLTRIM(Str(det.poriva,5,2)) + Se +;
  1998.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  1999.             Else
  2000.                 Insert Into comando;
  2001.                     VALUES ("B" + Se + det.unidad +" "+det.detalle+ Se + ;
  2002.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  2003.                     Alltrim(Str(det.unitario,13,2)) + ;
  2004.                     Se +Alltrim(Str(det.poriva,5,2)) + Se + ;
  2005.                     "M" + Se + "0" + Se + "" + Se + "T")
  2006.  
  2007.             Endif
  2008.         Else
  2009.             If This.Ticket = "S"
  2010.                 Insert Into comando;
  2011.                     VALUES ( "A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  2012.                 Insert Into comando;
  2013.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + ;
  2014.                     Se +Alltrim(Str(det.cantidad,6,2)+"0")+ Se + ;
  2015.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  2016.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  2017.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  2018.             Else
  2019.                 Insert Into comando;
  2020.                     VALUES ("B" + Se + det.unidad+" "+det.detalle+ Se +;
  2021.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  2022.                     ALLTRIM(Str(det.unitario,13,2)) + Se +;
  2023.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  2024.                     "M" + Se + "0" + Se + "" + Se + "T")
  2025.             Endif
  2026.         Endif
  2027.     Endif
  2028.     Select("det")
  2029.     Skip
  2030. Enddo
  2031.  
  2032.  
  2033. If This.condicion <> "C"
  2034.     If This.Ticket = "S"
  2035.         If This.contado = "S"
  2036.             Insert Into comando;
  2037.                 VALUES (Chr(68)+ Se + Substr(formapago.detalle,1,30)+ Se + ;
  2038.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  2039.         Else
  2040.             Insert Into comando;
  2041.                 VALUES ( Chr(68)+ Se + Substr(formapago.detalle,1,30)+ ;
  2042.                 Se + Alltrim(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  2043.         Endif
  2044.     Else
  2045.         If This.contado = "S"
  2046.             Insert Into comando;
  2047.                 VALUES (Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  2048.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  2049.         Else
  2050.             Insert Into comando;
  2051.                 VALUES(Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  2052.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  2053.         Endif
  2054.     Endif
  2055. Endif
  2056.  
  2057. If This.condicion <> "C"
  2058.     Insert Into comando;
  2059.         VALUES (Chr(69))
  2060. Else
  2061.     Insert Into comando;
  2062.         VALUES ( Chr(129) )
  2063. Endif
  2064.  
  2065.  
  2066. &&en esta parte copio el archivo con los comandos a la carpeta desde el cual
  2067. &&el spooler de impresion lee el archivo
  2068. If This.Ticket ="S"
  2069. && si es ticket me fijo a cual impresora debo enviar
  2070.     If lImpreFiscal
  2071.         mtXt = Alltrim(impfis.dircoticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  2072.         maNs = Alltrim(impfis.dirreticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  2073.     Else
  2074.         mtXt = Alltrim(parametr.dirco)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  2075.         maNs = Alltrim(parametr.dirre)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  2076.     Endif
  2077. *!*     cDirCom = "fpserver715" + "\impred.exe"
  2078. *!*     cDirCom = Fullpath(cDirCom)
  2079. *!* && Mato el proceso del spooler y lo vuelvo a cargar
  2080. *!*     This.killprocessbyname("impred.exe")
  2081. *!*     This.killprocessbyname("wspooler.exe")
  2082. *!*     oShell = Createobject("Shell.Application")
  2083. *!*     oShell.ShellExecute (cDirCom)
  2084. Else
  2085. &&aca envio a la 320
  2086.     If lImpreFiscal
  2087.         mtXt = Alltrim(impfis.dircofactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  2088.         maNs = Alltrim(impfis.dirrefactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  2089.     Else
  2090.         mtXt = Alltrim(parametr.dirco)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  2091.         maNs = Alltrim(parametr.dirre)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  2092.     Endif
  2093. Endif
  2094.  
  2095.  
  2096. Select("comando")
  2097. Goto Top
  2098. &&en caso de que tenga un archivo en la cola de impresion de la impresora
  2099. &&no se deja imprimir
  2100. *Browse
  2101. If File(mtXt)
  2102.     Messagebox("ATENCION: Ud. ya tiene un Documento en Cola de Impresión"+Chr(10)+Chr(13)+;
  2103.         " AGUARDE a que el mismo sea impreso o elimínelo luego vuelva a intentar")
  2104.     Return This.TodoOK
  2105. Else
  2106.     Copy To &mtXt Sdf
  2107.     If File(maNs)
  2108.         Erase &maNs
  2109.     Endif
  2110.     If File(Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  2111.         Erase (Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  2112.     Endif
  2113.     Wait Windows 'Esperando Respuesta del Controlador Fiscal...' Nowait
  2114.     fd = -1
  2115.     intentos =1
  2116.     Do While fd < 0 .And. Lastkey() != 27
  2117.         fd = Fopen(maNs, 0)
  2118.         This.LeerSpooler("T")
  2119.         If intentos = 30
  2120.             Messagebox("ATENCION: Verifique que el Controlador Esté Conectado y Encendido. " + Chr(10) + Chr(13)+ ;
  2121.                 "Verifique además que el Programa Spooler se esté ejecutando " + Chr(10) + Chr(13)+ ;
  2122.                 "en el equipo al cual se encuentra conectado el Controlador Fiscal")
  2123.             This.LeerSpooler("T")
  2124.         Endif
  2125.         If intentos = 70
  2126.             Messagebox("ATENCION: Tiempo de Espera Agotado !!! Presione ESC. para cancelar este Comprobante")
  2127.             This.LeerSpooler("T")
  2128.         Endif
  2129.         intentos = intentos + 1
  2130. *For i=1 To 100
  2131. *Next
  2132.         Inkey(1)
  2133.         If Lastkey() = 27
  2134.             If Substr(comando.comando,17,16) = "Impresor Ocupado"
  2135.                 Messagebox("ATENCION: No se aconseja cancelar este documento por programa, "+;
  2136.                     CHR(10)+Chr(13)+"La impresora ya lo ha procesado y saldrá impreso"+;
  2137.                     CHR(10)+Chr(13)+ "una vez que esta se ponga en linea")
  2138.             Endif
  2139.             If Messagebox("ATENCION: Realmente desea Cancelar la Emisión de este Documento??",4+256) = 6
  2140.                 Messagebox(" Se proceder  a Cancelar el Documento por Sistema"+;
  2141.                     CHR(10)+Chr(13)+" Verifique que la impresora también lo haya Cancelado.")
  2142.                 Keyboard '{ESC}'
  2143.             Else
  2144.                 Keyboard ""
  2145.             Endif
  2146.         Endif
  2147.     Enddo
  2148.     If Lastkey() = 27.Or. fd < 0
  2149.         If File(mtXt)
  2150.             Erase &mtXt
  2151.         Endif
  2152.         fd = Fopen((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"), 0)
  2153.         If fd < 0
  2154.             Messagebox("Operación Cancelada: ERROR de comunicaciones con el Controlador.; Probablemente no se este ejecutando Spooler. ")
  2155.         Else
  2156.             fd =Fclose(fd)
  2157.             This.LeerSpooler("T")
  2158.         Endif
  2159.     Else
  2160.         fd = Fclose(fd)
  2161.         Select("comando")
  2162.         Zap
  2163.         Append From &maNs Sdf
  2164.         Goto Bottom
  2165.         This.numero = Val(Substr(comando.comando,35,8))
  2166.         If This.numero <> 0
  2167.             SQLExec(goApp.nCon, "select * from puntero where sucursal=?param.sucursal","puntero")
  2168.             If This.Ticket = "S"
  2169.                 If This.MasDeMil
  2170.                     This.numero = Val('0009'+strzero(This.numero,8))
  2171.                 Else
  2172.                     If lImpreFiscal
  2173.                         This.numero = Val(impfis.PtoVtaTicket+strzero(This.numero,8))
  2174.                     Else
  2175.                         If Param.sucursal=0
  2176.                             If File("c:\0009.txt")
  2177.                                 This.numero = Val(strzero(9,4)+strzero(This.numero,8))
  2178.                             Else
  2179.                                 This.numero = Val(strzero(puntero.pvta_tic,4)+strzero(This.numero,8))
  2180.                             Endif
  2181.                         Else
  2182.                             If Param.sucursal = 1
  2183.                                 This.numero = Val(strzero(8,4)+strzero(This.numero,8))
  2184.                             Endif
  2185.                         Endif
  2186.                     Endif
  2187.                 Endif
  2188.             Else
  2189.                 If lImpreFiscal
  2190.                     This.numero = Val(impfis.PtoVtaFac+strzero(This.numero,8))
  2191.                 Else
  2192.                     This.numero = Val(strzero(puntero.pvta_fac,4)+strzero(This.numero,8))
  2193.                 Endif
  2194.             Endif
  2195.             This.TodoOK = .T.
  2196.         Endif
  2197.     Endif
  2198.     If File((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"))
  2199.         Erase Alltrim(paramfac.dirpa)+"SPOOLER.LOG"
  2200.     Endif
  2201. Endif
  2202. *This.killprocessbyname("impred.exe")
  2203. *This.killprocessbyname("wspooler.exe")
  2204.  
  2205. Set Talk &cTalk
  2206. Return This.Todo
  2207. *!* If SQLExec(Thisform.con, "select * from parametr","parametr") = -1
  2208. *!*     Messagebox("Se ha producido un error al recuperar el tipo de Documento" + Chr(10)+Chr(13)+Message(),0+48,"ERROR")
  2209. *!*     Return -1
  2210. *!* Endif
  2211.  
  2212. &&indica si el cliente tiene que poseer cuit
  2213. If tiporesp.obligacuit
  2214.     If Empty( Val( Strtran( clientes.cuit, "-" ) ) )
  2215.         Messagebox ("ATENCION: Falta Registrar CUIT de Cliente", 0+48, "CUIT")
  2216.         Do While Val(ndocu) < 2
  2217.             ndocu = Inputbox("Ingrese CUIT")
  2218.         Enddo
  2219.         ndocu = Alltrim( Strtran( ndocu, "-" ) )
  2220.     Else
  2221.         TIPO_DOCU = 'C' &&tiporesp.tipo_iva &&"C"
  2222.         ndocu = Alltrim( Strtran( clientes.cuit, "-" ) )
  2223.     Endif
  2224. Else
  2225.     If SQLExec(goApp.nCon, "select * from tipodoc where codigo=?clientes.tipodocu","tipodoc") = -1
  2226.         goApp.Error()
  2227.         Return -1
  2228.     Endif
  2229.     If Reccount("tipodoc") > 0
  2230.         TIPO_DOCU = tipodoc.tipo
  2231.     Else
  2232.         TIPO_DOCU = '2'
  2233.     Endif
  2234.     ndocu = Alltrim(Str(clientes.dni))
  2235.     If Val(ndocu) < 2
  2236.         ndocu = '11111111'
  2237.     Endif
  2238. Endif
  2239.  
  2240. TIPO_IVA = tiporesp.TIPOIVA
  2241. Select("comando")
  2242.  
  2243. &&me fijo si es ticket factura o factura
  2244. If This.Ticket = "S"
  2245.     lin = "5"
  2246. Else
  2247.     lin = "3"
  2248. Endif
  2249.  
  2250. If This.Ticket = "N"
  2251. &&en caso de ser factura imprimo todo el encabezado que va en la factura
  2252.     Select("comando")
  2253.     Insert Into comando;
  2254.         VALUES( "]" + Se + "1" + Se + Chr(127) )
  2255.     Insert Into comando;
  2256.         VALUES( "]" + Se + "2" + Se + Chr(127) )
  2257.  
  2258.     Insert Into comando;
  2259.         values( "]" + Se + "2" + Se + "Ing.Brut. 914-532186-1"  )
  2260.     If This.contado = "N"
  2261.         Insert Into comando;
  2262.             VALUES ("]" + Se + lin + Se + ;
  2263.             "Vendedor: "+Alltrim(vendedor.nom_ven)+;
  2264.             SPACE(10)+"Vencimiento de este Comp.: "+;
  2265.             DTOC(This.FechaVen(Thisform.txtFecha.Value))+;
  2266.             " Saldo Actual de CTA_CTE(S.E.U.O.): $"+;
  2267.             ALLTRIM(Str((m.salctacte),12,2)))
  2268.     Else
  2269.         Insert Into comando;
  2270.             VALUES ("]" + Se + lin + Se + "Vendedor: "+;
  2271.             ALLTRIM(vendedor.nom_ven)+;
  2272.             SPACE(10)+"Vencimiento de este Comp.: "+;
  2273.             DTOC(This.FechaVen(Thisform.txtFecha.Value)))
  2274.     Endif
  2275.  
  2276.     lin = Str(Val(lin)+1,1,0)
  2277.  
  2278.     Do Case
  2279.     Case Used("obsfac")
  2280.         Insert Into comando;
  2281.             VALUES ("]" + Se + lin + Se + "OBS.: "+Alltrim(obsfac.obs1)+Alltrim(obsfac.obs2))
  2282.     Case This.pagoanticipado &&det.pagoanticipado
  2283.         If det.reparto
  2284.             Insert Into comando;
  2285.                 VALUES ("]" + Se + lin + Se + "PAGO ANTICIPADO - REPARTO")
  2286.         Else
  2287.             Insert Into comando;
  2288.                 VALUES ("]" + Se + lin + Se + "PAGO ANTICIPADO - RETIRA")
  2289.         Endif
  2290.     Case This.lReparto
  2291.         Insert Into comando;
  2292.             VALUES ("]" + Se + lin + Se + "MERCADERIA DE REPARTO")
  2293.     Case !This.lReparto
  2294.         Insert Into comando;
  2295.             VALUES ("]" + Se + lin + Se + "MERCADERIA PARA RETIRAR")
  2296.     Otherwise
  2297.         Insert Into comando;
  2298.             VALUES ("]" + Se + lin + Se + "DEVOLUCIONES DENTRO DE LAS 48 HRS.")
  2299.     Endcase
  2300.  
  2301.     lin = Str(Val(lin)+1,1,0)
  2302.     This.letras.dicenum(m.nTOTAL)
  2303.     Insert Into comando;
  2304.         VALUES ( "]" + Se + lin + Se + ;
  2305.         "SON:" + This.letras.retorno)
  2306.  
  2307.     lin = "11"
  2308.  
  2309. &&especifico las formas de cancelacion que posee la factura
  2310.     If pagos.adic1 > 0 .Or. pagos.plazo1 > 0
  2311.         Insert Into comando;
  2312.             VALUES ( "]" + Se + lin + Se + ;
  2313.             "OPCION DE PAGO: Hasta el "+;
  2314.             Dtoc(Thisform.txtFecha.Value+This.dias())+ " "+;
  2315.             STR(pagos.adic1)+" % Desc. $ "+;
  2316.             STR(m.nTOTAL*pagos.adic1/100,08,2)+;
  2317.             " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic1)/100),10,2))
  2318.     Else
  2319.         If Inlist(pagos.pago,'00','01','02')
  2320.             Insert Into comando;
  2321.                 VALUES ( "]" + Se + lin + Se + ;
  2322.                 "OPCION DE PAGO: Contado Efectivo"+;
  2323.                 " 3% Desc. "+;
  2324.                 " Paga $ "+ Str(m.nTOTAL,10,2))
  2325.         Else
  2326.             Insert Into comando;
  2327.                 VALUES ( "]" + Se + lin + Se + Chr(127))
  2328.         Endif
  2329.     Endif
  2330.  
  2331.     lin = Str(Val(lin)+1,2,0)
  2332.  
  2333.     If pagos.adic2 > 0 .Or. pagos.plazo2 > 0
  2334.         If Isnull(pagos.dia) Or Empty(pagos.dia)
  2335.             Insert Into comando;
  2336.                 VALUES ( "]" + Se + lin + Se +;
  2337.                 "OPCION DE PAGO: Hasta el "+ ;
  2338.                 DTOC(This.FechaVen(Thisform.txtFecha.Value))+"  "+;
  2339.                 STR(pagos.adic2)+" % Desc. $ ";
  2340.                 +Str(m.nTOTAL*pagos.adic2/100,08,2)+;
  2341.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  2342.         Else
  2343.             If pagos.pago = '51'
  2344. *!* Pongo esto para que en esta condicion no me sume los dias de ADIC2
  2345.                 Insert Into comando;
  2346.                     VALUES ("]" + Se + lin + Se +  ;
  2347.                     "OPCION DE PAGO: Hasta el "+ ;
  2348.                     DTOC(pagos.dia)+"  "+;
  2349.                     STR(pagos.adic2)+" % Desc. $ "+;
  2350.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  2351.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  2352.             Else
  2353.                 Insert Into comando;
  2354.                     VALUES ("]" + Se + lin + Se +  ;
  2355.                     "OPCION DE PAGO: Hasta el "+ ;
  2356.                     DTOC(This.FechaVen(Thisform.txtFecha.Value))+"  "+;
  2357.                     STR(pagos.adic2)+" % Desc. $ "+;
  2358.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  2359.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  2360.             Endif
  2361.         Endif
  2362.     Else
  2363.         Insert Into comando;
  2364.             VALUES ( "]" + Se + lin + Se + Chr(127) )
  2365.     Endif
  2366.  
  2367.     lin = Str(Val(lin)+1,2,0)
  2368.  
  2369.     If pagos.adic3 > 0 .Or. pagos.plazo3 >0
  2370.         If Isnull(pagos.dia) Or Empty(pagos.dia)
  2371.             Insert Into comando;
  2372.                 VALUES ("]" + Se + lin + Se + ;
  2373.                 "OPCION DE PAGO: Hasta el "+ ;
  2374.                 DTOC(Thisform.txtFecha.Value+Cast(pagos.dias1 As Integer))+"  "+;
  2375.                 STR(pagos.adic3)+" % Desc. $ "+;
  2376.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  2377.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  2378.         Else
  2379.             Insert Into comando;
  2380.                 VALUES ("]" + Se + lin + Se + ;
  2381.                 "OPCION DE PAGO: Hasta el "+ ;
  2382.                 DTOC(pagos.dia+Cast(pagos.dias1 As Integer))+"  "+;
  2383.                 STR(pagos.adic3)+" % Desc. $ "+;
  2384.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  2385.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  2386.         Endif
  2387.     Else
  2388.         Insert Into comando;
  2389.             VALUES ("]" + Se + lin + Se + Chr(127))
  2390.     Endif
  2391.  
  2392.     lin = Str(Val(lin)+1,2,0)
  2393. *!*     Insert Into comando;
  2394. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  2395.     If m.nFlete > 0 Or m.nDRet > 0
  2396.         If m.nFlete > 0
  2397.             Insert Into comando;
  2398.                 VALUES ("]" + Se + lin + Se + ;
  2399.                 "Prec. de Merc. Incl. Flete "+ ;
  2400.                 Transform(m.nFlete, "@$ 99,999,999.99"))
  2401.         Else
  2402.             Insert Into comando;
  2403.                 VALUES ("]" + Se + lin + Se + ;
  2404.                 "Merc. Incl. Desc p/RETIRA "+ ;
  2405.                 Transform(m.nDRet, "@$ 99,999,999.99"))
  2406.         Endif
  2407.     Else
  2408.         Insert Into comando;
  2409.             VALUES ("]" + Se + lin + Se + Chr(127))
  2410.     Endif
  2411.  
  2412. &&si se factura sobre remitos se imprimen los remitos afectados
  2413.     If Thisform.viene = "X" &&hay q revisar esto para ver q cuando se factura de remitos se imprima
  2414.         Insert Into comando;
  2415.             VALUES ( Chr(147) + Se + "1" + Se + Substr(This.remitosafacturar,1,17))
  2416.         If !Empty(Substr(This.remitosafacturar,19,20))
  2417.             Insert Into comando;
  2418.                 VALUES (Chr(147) + Se + "2" + Se + Substr(This.remitosafacturar,19,20))
  2419.         Endif
  2420.     Endif
  2421. Else
  2422.     If This.contado = 'N'
  2423.         Insert Into comando;
  2424.             values("]" + Se + lin + Se+;
  2425.             " Saldo de CTA_CTE: $"+;
  2426.             ALLTRIM(Str((m.salctacte),12,2)))
  2427.         lin = '6'
  2428.     Else
  2429.         Insert Into comando;
  2430.             values("]" + Se + lin + Se + Chr(127))
  2431.         lin = '6'
  2432.     Endif
  2433.  
  2434.     Insert Into comando;
  2435.         VALUES ( "]" + Se + lin + Se + "Vendedor: "+Alltrim(goApp.User) )
  2436.  
  2437.     lin = '7'
  2438.     Insert Into comando;
  2439.         VALUES ("]" + Se + lin + Se + Chr(127))
  2440.  
  2441.     lin = '8'
  2442.     Insert Into comando;
  2443.         VALUES ("]" + Se + lin + Se + Chr(127))
  2444.  
  2445.     lin = '11'
  2446. *!*     Insert Into comando;
  2447. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  2448.     Insert Into comando;
  2449.         VALUES ("]" + Se + lin + Se + Chr(127))
  2450. Endif
  2451.  
  2452. If This.Ticket="S"
  2453.     Insert Into comando;
  2454.         VALUES ( "]" + Se + "9" + Se +Chr(127))
  2455.     Insert Into comando;
  2456.         VALUES ("]" + Se + "10" + Se +Chr(127))
  2457.     If This.condicion = 'C' And Val(sCliente) = 1
  2458.         Insert Into comando;
  2459.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  2460.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  2461.             " S/NOMBRE")
  2462.     Else
  2463.         Insert Into comando;
  2464.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  2465.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  2466.             SUBSTR(Alltrim(thisformset.frmCliente.txtDomicilio.Value)+" "+Alltrim(loc.nombre)+;
  2467.             " "+Alltrim(loc.provincia),1,40))
  2468.     Endif
  2469.  
  2470. Else
  2471. &&"["+sCliente+"] "+
  2472.     Insert Into comando;
  2473.         VALUES ( "b" + Se + "[" + sCliente + "] " + Substr(sNombre,1,40) + Se +;
  2474.         ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se + ;
  2475.         ALLTRIM(Thisform.txtDom.Value)+" ("+Alltrim(clientes.codpos)+") "+;
  2476.         Alltrim(loc.nombre)+" "+Alltrim(loc.provincia))
  2477. Endif
  2478. If This.condicion <> "C"
  2479.     Insert Into comando;
  2480.         VALUES (Chr(64)+Se+TIPO_FACTURA+Se+"T")
  2481. Else
  2482. &&Definir tipo y num de factura afectado por nota de credito
  2483.     Insert Into comando;
  2484.         VALUES (Chr(147) + Se + "1" + Se + cre.tipoaf + " " + cre.numeroaf)
  2485.     Insert Into comando;
  2486.         VALUES (Chr(128)+Se+TIPO_FACTURA+Se+"T")
  2487. Endif
  2488.  
  2489. &&el cursor "DET" posee los items a facturar
  2490. Select("det")
  2491. Go Top
  2492. Do While ! Eof()
  2493. *!* Create Cursor det;
  2494. *!*     (cantidad n(12,4), unidad c(8), detalle c(40), total n(12,2), idArticulo int,;
  2495. *!*     unitario n(12,2), costo n(12,2), montoiva n(12,2), montodgr n(12,2), montomuni N(12,2),;
  2496. *!*     poriva n(12,2), tipoiva c(2))  
  2497.     If det.unitario != 0
  2498.         If This.clase = "A"
  2499.             If This.Ticket = "S"
  2500.                 Insert Into comando;
  2501.                     VALUES ("A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  2502.                 Insert Into comando;
  2503.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + Se +;
  2504.                     ALLTRIM(Str(det.cantidad,6,2)+"0")+ Se +;
  2505.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  2506.                     ALLTRIM(Str(det.poriva,5,2)) + Se +;
  2507.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  2508.             Else
  2509.                 Insert Into comando;
  2510.                     VALUES ("B" + Se + det.unidad +" "+det.detalle+ Se + ;
  2511.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  2512.                     Alltrim(Str(det.unitario,13,2)) + ;
  2513.                     Se +Alltrim(Str(det.poriva,5,2)) + Se + ;
  2514.                     "M" + Se + "0" + Se + "" + Se + "T")
  2515.  
  2516.             Endif
  2517.         Else
  2518.             If This.Ticket = "S"
  2519.                 Insert Into comando;
  2520.                     VALUES ( "A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  2521.                 Insert Into comando;
  2522.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + ;
  2523.                     Se +Alltrim(Str(det.cantidad,6,2)+"0")+ Se + ;
  2524.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  2525.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  2526.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  2527.             Else
  2528.                 Insert Into comando;
  2529.                     VALUES ("B" + Se + det.unidad+" "+det.detalle+ Se +;
  2530.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  2531.                     ALLTRIM(Str(det.unitario,13,2)) + Se +;
  2532.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  2533.                     "M" + Se + "0" + Se + "" + Se + "T")
  2534.             Endif
  2535.         Endif
  2536.     Endif
  2537.     Select("det")
  2538.     Skip
  2539. Enddo
  2540.  
  2541.  
  2542. If This.condicion <> "C"
  2543.     If This.Ticket = "S"
  2544.         If This.contado = "S"
  2545.             Insert Into comando;
  2546.                 VALUES (Chr(68)+ Se + Substr(formapago.detalle,1,30)+ Se + ;
  2547.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  2548.         Else
  2549.             Insert Into comando;
  2550.                 VALUES ( Chr(68)+ Se + Substr(formapago.detalle,1,30)+ ;
  2551.                 Se + Alltrim(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  2552.         Endif
  2553.     Else
  2554.         If This.contado = "S"
  2555.             Insert Into comando;
  2556.                 VALUES (Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  2557.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  2558.         Else
  2559.             Insert Into comando;
  2560.                 VALUES(Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  2561.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  2562.         Endif
  2563.     Endif
  2564. Endif
  2565.  
  2566. If This.condicion <> "C"
  2567.     Insert Into comando;
  2568.         VALUES (Chr(69))
  2569. Else
  2570.     Insert Into comando;
  2571.         VALUES ( Chr(129) )
  2572. Endif
  2573.  
  2574.  
  2575. &&en esta parte copio el archivo con los comandos a la carpeta desde el cual
  2576. &&el spooler de impresion lee el archivo
  2577. If This.Ticket ="S"
  2578. && si es ticket me fijo a cual impresora debo enviar
  2579.     If lImpreFiscal
  2580.         mtXt = Alltrim(impfis.dircoticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  2581.         maNs = Alltrim(impfis.dirreticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  2582.     Else
  2583.         mtXt = Alltrim(parametr.dirco)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  2584.         maNs = Alltrim(parametr.dirre)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  2585.     Endif
  2586. *!*     cDirCom = "fpserver715" + "\impred.exe"
  2587. *!*     cDirCom = Fullpath(cDirCom)
  2588. *!* && Mato el proceso del spooler y lo vuelvo a cargar
  2589. *!*     This.killprocessbyname("impred.exe")
  2590. *!*     This.killprocessbyname("wspooler.exe")
  2591. *!*     oShell = Createobject("Shell.Application")
  2592. *!*     oShell.ShellExecute (cDirCom)
  2593. Else
  2594. &&aca envio a la 320
  2595.     If lImpreFiscal
  2596.         mtXt = Alltrim(impfis.dircofactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  2597.         maNs = Alltrim(impfis.dirrefactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  2598.     Else
  2599.         mtXt = Alltrim(parametr.dirco)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  2600.         maNs = Alltrim(parametr.dirre)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  2601.     Endif
  2602. Endif
  2603.  
  2604.  
  2605. Select("comando")
  2606. Goto Top
  2607. &&en caso de que tenga un archivo en la cola de impresion de la impresora
  2608. &&no se deja imprimir
  2609. *Browse
  2610. If File(mtXt)
  2611.     Messagebox("ATENCION: Ud. ya tiene un Documento en Cola de Impresión"+Chr(10)+Chr(13)+;
  2612.         " AGUARDE a que el mismo sea impreso o elimínelo luego vuelva a intentar")
  2613.     Return This.TodoOK
  2614. Else
  2615.     Copy To &mtXt Sdf
  2616.     If File(maNs)
  2617.         Erase &maNs
  2618.     Endif
  2619.     If File(Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  2620.         Erase (Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  2621.     Endif
  2622.     Wait Windows 'Esperando Respuesta del Controlador Fiscal...' Nowait
  2623.     fd = -1
  2624.     intentos =1
  2625.     Do While fd < 0 .And. Lastkey() != 27
  2626.         fd = Fopen(maNs, 0)
  2627.         This.LeerSpooler("T")
  2628.         If intentos = 30
  2629.             Messagebox("ATENCION: Verifique que el Controlador Esté Conectado y Encendido. " + Chr(10) + Chr(13)+ ;
  2630.                 "Verifique además que el Programa Spooler se esté ejecutando " + Chr(10) + Chr(13)+ ;
  2631.                 "en el equipo al cual se encuentra conectado el Controlador Fiscal")
  2632.             This.LeerSpooler("T")
  2633.         Endif
  2634.         If intentos = 70
  2635.             Messagebox("ATENCION: Tiempo de Espera Agotado !!! Presione ESC. para cancelar este Comprobante")
  2636.             This.LeerSpooler("T")
  2637.         Endif
  2638.         intentos = intentos + 1
  2639. *For i=1 To 100
  2640. *Next
  2641.         Inkey(1)
  2642.         If Lastkey() = 27
  2643.             If Substr(comando.comando,17,16) = "Impresor Ocupado"
  2644.                 Messagebox("ATENCION: No se aconseja cancelar este documento por programa, "+;
  2645.                     CHR(10)+Chr(13)+"La impresora ya lo ha procesado y saldrá impreso"+;
  2646.                     CHR(10)+Chr(13)+ "una vez que esta se ponga en linea")
  2647.             Endif
  2648.             If Messagebox("ATENCION: Realmente desea Cancelar la Emisión de este Documento??",4+256) = 6
  2649.                 Messagebox(" Se proceder  a Cancelar el Documento por Sistema"+;
  2650.                     CHR(10)+Chr(13)+" Verifique que la impresora también lo haya Cancelado.")
  2651.                 Keyboard '{ESC}'
  2652.             Else
  2653.                 Keyboard ""
  2654.             Endif
  2655.         Endif
  2656.     Enddo
  2657.     If Lastkey() = 27.Or. fd < 0
  2658.         If File(mtXt)
  2659.             Erase &mtXt
  2660.         Endif
  2661.         fd = Fopen((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"), 0)
  2662.         If fd < 0
  2663.             Messagebox("Operación Cancelada: ERROR de comunicaciones con el Controlador.; Probablemente no se este ejecutando Spooler. ")
  2664.         Else
  2665.             fd =Fclose(fd)
  2666.             This.LeerSpooler("T")
  2667.         Endif
  2668.     Else
  2669.         fd = Fclose(fd)
  2670.         Select("comando")
  2671.         Zap
  2672.         Append From &maNs Sdf
  2673.         Goto Bottom
  2674.         This.numero = Val(Substr(comando.comando,35,8))
  2675.         If This.numero <> 0
  2676.             SQLExec(goApp.nCon, "select * from puntero where sucursal=?param.sucursal","puntero")
  2677.             If This.Ticket = "S"
  2678.                 If This.MasDeMil
  2679.                     This.numero = Val('0009'+strzero(This.numero,8))
  2680.                 Else
  2681.                     If lImpreFiscal
  2682.                         This.numero = Val(impfis.PtoVtaTicket+strzero(This.numero,8))
  2683.                     Else
  2684.                         If Param.sucursal=0
  2685.                             If File("c:\0009.txt")
  2686.                                 This.numero = Val(strzero(9,4)+strzero(This.numero,8))
  2687.                             Else
  2688.                                 This.numero = Val(strzero(puntero.pvta_tic,4)+strzero(This.numero,8))
  2689.                             Endif
  2690.                         Else
  2691.                             If Param.sucursal = 1
  2692.                                 This.numero = Val(strzero(8,4)+strzero(This.numero,8))
  2693.                             Endif
  2694.                         Endif
  2695.                     Endif
  2696.                 Endif
  2697.             Else
  2698.                 If lImpreFiscal
  2699.                     This.numero = Val(impfis.PtoVtaFac+strzero(This.numero,8))
  2700.                 Else
  2701.                     This.numero = Val(strzero(puntero.pvta_fac,4)+strzero(This.numero,8))
  2702.                 Endif
  2703.             Endif
  2704.             This.TodoOK = .T.
  2705.         Endif
  2706.     Endif
  2707.     If File((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"))
  2708.         Erase Alltrim(paramfac.dirpa)+"SPOOLER.LOG"
  2709.     Endif
  2710. Endif
  2711. *This.killprocessbyname("impred.exe")
  2712. *This.killprocessbyname("wspooler.exe")
  2713.  
  2714. Set Talk &cTalk
  2715. Return This.Todo
  2716. *!*     Messagebox("Se ha producido un error al recuperar el tipo de Documento" + Chr(10)+Chr(13)+Message(),0+48,"ERROR")
  2717. *!*     Return -1
  2718. *!* Endif
  2719.  
  2720. &&indica si el cliente tiene que poseer cuit
  2721. If tiporesp.obligacuit
  2722.     If Empty( Val( Strtran( clientes.cuit, "-" ) ) )
  2723.         Messagebox ("ATENCION: Falta Registrar CUIT de Cliente", 0+48, "CUIT")
  2724.         Do While Val(ndocu) < 2
  2725.             ndocu = Inputbox("Ingrese CUIT")
  2726.         Enddo
  2727.         ndocu = Alltrim( Strtran( ndocu, "-" ) )
  2728.     Else
  2729.         TIPO_DOCU = 'C' &&tiporesp.tipo_iva &&"C"
  2730.         ndocu = Alltrim( Strtran( clientes.cuit, "-" ) )
  2731.     Endif
  2732. Else
  2733.     If SQLExec(goApp.nCon, "select * from tipodoc where codigo=?clientes.tipodocu","tipodoc") = -1
  2734.         goApp.Error()
  2735.         Return -1
  2736.     Endif
  2737.     If Reccount("tipodoc") > 0
  2738.         TIPO_DOCU = tipodoc.tipo
  2739.     Else
  2740.         TIPO_DOCU = '2'
  2741.     Endif
  2742.     ndocu = Alltrim(Str(clientes.dni))
  2743.     If Val(ndocu) < 2
  2744.         ndocu = '11111111'
  2745.     Endif
  2746. Endif
  2747.  
  2748. TIPO_IVA = tiporesp.TIPOIVA
  2749. Select("comando")
  2750.  
  2751. &&me fijo si es ticket factura o factura
  2752. If This.Ticket = "S"
  2753.     lin = "5"
  2754. Else
  2755.     lin = "3"
  2756. Endif
  2757.  
  2758. If This.Ticket = "N"
  2759. &&en caso de ser factura imprimo todo el encabezado que va en la factura
  2760.     Select("comando")
  2761.     Insert Into comando;
  2762.         VALUES( "]" + Se + "1" + Se + Chr(127) )
  2763.     Insert Into comando;
  2764.         VALUES( "]" + Se + "2" + Se + Chr(127) )
  2765.  
  2766.     Insert Into comando;
  2767.         values( "]" + Se + "2" + Se + "Ing.Brut. 914-532186-1"  )
  2768.     If This.contado = "N"
  2769.         Insert Into comando;
  2770.             VALUES ("]" + Se + lin + Se + ;
  2771.             "Vendedor: "+Alltrim(vendedor.nom_ven)+;
  2772.             SPACE(10)+"Vencimiento de este Comp.: "+;
  2773.             DTOC(This.FechaVen(Thisform.txtFecha.Value))+;
  2774.             " Saldo Actual de CTA_CTE(S.E.U.O.): $"+;
  2775.             ALLTRIM(Str((m.salctacte),12,2)))
  2776.     Else
  2777.         Insert Into comando;
  2778.             VALUES ("]" + Se + lin + Se + "Vendedor: "+;
  2779.             ALLTRIM(vendedor.nom_ven)+;
  2780.             SPACE(10)+"Vencimiento de este Comp.: "+;
  2781.             DTOC(This.FechaVen(Thisform.txtFecha.Value)))
  2782.     Endif
  2783.  
  2784.     lin = Str(Val(lin)+1,1,0)
  2785.  
  2786.     Do Case
  2787.     Case Used("obsfac")
  2788.         Insert Into comando;
  2789.             VALUES ("]" + Se + lin + Se + "OBS.: "+Alltrim(obsfac.obs1)+Alltrim(obsfac.obs2))
  2790.     Case This.pagoanticipado &&det.pagoanticipado
  2791.         If det.reparto
  2792.             Insert Into comando;
  2793.                 VALUES ("]" + Se + lin + Se + "PAGO ANTICIPADO - REPARTO")
  2794.         Else
  2795.             Insert Into comando;
  2796.                 VALUES ("]" + Se + lin + Se + "PAGO ANTICIPADO - RETIRA")
  2797.         Endif
  2798.     Case This.lReparto
  2799.         Insert Into comando;
  2800.             VALUES ("]" + Se + lin + Se + "MERCADERIA DE REPARTO")
  2801.     Case !This.lReparto
  2802.         Insert Into comando;
  2803.             VALUES ("]" + Se + lin + Se + "MERCADERIA PARA RETIRAR")
  2804.     Otherwise
  2805.         Insert Into comando;
  2806.             VALUES ("]" + Se + lin + Se + "DEVOLUCIONES DENTRO DE LAS 48 HRS.")
  2807.     Endcase
  2808.  
  2809.     lin = Str(Val(lin)+1,1,0)
  2810.     This.letras.dicenum(m.nTOTAL)
  2811.     Insert Into comando;
  2812.         VALUES ( "]" + Se + lin + Se + ;
  2813.         "SON:" + This.letras.retorno)
  2814.  
  2815.     lin = "11"
  2816.  
  2817. &&especifico las formas de cancelacion que posee la factura
  2818.     If pagos.adic1 > 0 .Or. pagos.plazo1 > 0
  2819.         Insert Into comando;
  2820.             VALUES ( "]" + Se + lin + Se + ;
  2821.             "OPCION DE PAGO: Hasta el "+;
  2822.             Dtoc(Thisform.txtFecha.Value+This.dias())+ " "+;
  2823.             STR(pagos.adic1)+" % Desc. $ "+;
  2824.             STR(m.nTOTAL*pagos.adic1/100,08,2)+;
  2825.             " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic1)/100),10,2))
  2826.     Else
  2827.         If Inlist(pagos.pago,'00','01','02')
  2828.             Insert Into comando;
  2829.                 VALUES ( "]" + Se + lin + Se + ;
  2830.                 "OPCION DE PAGO: Contado Efectivo"+;
  2831.                 " 3% Desc. "+;
  2832.                 " Paga $ "+ Str(m.nTOTAL,10,2))
  2833.         Else
  2834.             Insert Into comando;
  2835.                 VALUES ( "]" + Se + lin + Se + Chr(127))
  2836.         Endif
  2837.     Endif
  2838.  
  2839.     lin = Str(Val(lin)+1,2,0)
  2840.  
  2841.     If pagos.adic2 > 0 .Or. pagos.plazo2 > 0
  2842.         If Isnull(pagos.dia) Or Empty(pagos.dia)
  2843.             Insert Into comando;
  2844.                 VALUES ( "]" + Se + lin + Se +;
  2845.                 "OPCION DE PAGO: Hasta el "+ ;
  2846.                 DTOC(This.FechaVen(Thisform.txtFecha.Value))+"  "+;
  2847.                 STR(pagos.adic2)+" % Desc. $ ";
  2848.                 +Str(m.nTOTAL*pagos.adic2/100,08,2)+;
  2849.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  2850.         Else
  2851.             If pagos.pago = '51'
  2852. *!* Pongo esto para que en esta condicion no me sume los dias de ADIC2
  2853.                 Insert Into comando;
  2854.                     VALUES ("]" + Se + lin + Se +  ;
  2855.                     "OPCION DE PAGO: Hasta el "+ ;
  2856.                     DTOC(pagos.dia)+"  "+;
  2857.                     STR(pagos.adic2)+" % Desc. $ "+;
  2858.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  2859.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  2860.             Else
  2861.                 Insert Into comando;
  2862.                     VALUES ("]" + Se + lin + Se +  ;
  2863.                     "OPCION DE PAGO: Hasta el "+ ;
  2864.                     DTOC(This.FechaVen(Thisform.txtFecha.Value))+"  "+;
  2865.                     STR(pagos.adic2)+" % Desc. $ "+;
  2866.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  2867.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  2868.             Endif
  2869.         Endif
  2870.     Else
  2871.         Insert Into comando;
  2872.             VALUES ( "]" + Se + lin + Se + Chr(127) )
  2873.     Endif
  2874.  
  2875.     lin = Str(Val(lin)+1,2,0)
  2876.  
  2877.     If pagos.adic3 > 0 .Or. pagos.plazo3 >0
  2878.         If Isnull(pagos.dia) Or Empty(pagos.dia)
  2879.             Insert Into comando;
  2880.                 VALUES ("]" + Se + lin + Se + ;
  2881.                 "OPCION DE PAGO: Hasta el "+ ;
  2882.                 DTOC(Thisform.txtFecha.Value+Cast(pagos.dias1 As Integer))+"  "+;
  2883.                 STR(pagos.adic3)+" % Desc. $ "+;
  2884.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  2885.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  2886.         Else
  2887.             Insert Into comando;
  2888.                 VALUES ("]" + Se + lin + Se + ;
  2889.                 "OPCION DE PAGO: Hasta el "+ ;
  2890.                 DTOC(pagos.dia+Cast(pagos.dias1 As Integer))+"  "+;
  2891.                 STR(pagos.adic3)+" % Desc. $ "+;
  2892.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  2893.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  2894.         Endif
  2895.     Else
  2896.         Insert Into comando;
  2897.             VALUES ("]" + Se + lin + Se + Chr(127))
  2898.     Endif
  2899.  
  2900.     lin = Str(Val(lin)+1,2,0)
  2901. *!*     Insert Into comando;
  2902. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  2903.     If m.nFlete > 0 Or m.nDRet > 0
  2904.         If m.nFlete > 0
  2905.             Insert Into comando;
  2906.                 VALUES ("]" + Se + lin + Se + ;
  2907.                 "Prec. de Merc. Incl. Flete "+ ;
  2908.                 Transform(m.nFlete, "@$ 99,999,999.99"))
  2909.         Else
  2910.             Insert Into comando;
  2911.                 VALUES ("]" + Se + lin + Se + ;
  2912.                 "Merc. Incl. Desc p/RETIRA "+ ;
  2913.                 Transform(m.nDRet, "@$ 99,999,999.99"))
  2914.         Endif
  2915.     Else
  2916.         Insert Into comando;
  2917.             VALUES ("]" + Se + lin + Se + Chr(127))
  2918.     Endif
  2919.  
  2920. &&si se factura sobre remitos se imprimen los remitos afectados
  2921.     If Thisform.viene = "X" &&hay q revisar esto para ver q cuando se factura de remitos se imprima
  2922.         Insert Into comando;
  2923.             VALUES ( Chr(147) + Se + "1" + Se + Substr(This.remitosafacturar,1,17))
  2924.         If !Empty(Substr(This.remitosafacturar,19,20))
  2925.             Insert Into comando;
  2926.                 VALUES (Chr(147) + Se + "2" + Se + Substr(This.remitosafacturar,19,20))
  2927.         Endif
  2928.     Endif
  2929. Else
  2930.     If This.contado = 'N'
  2931.         Insert Into comando;
  2932.             values("]" + Se + lin + Se+;
  2933.             " Saldo de CTA_CTE: $"+;
  2934.             ALLTRIM(Str((m.salctacte),12,2)))
  2935.         lin = '6'
  2936.     Else
  2937.         Insert Into comando;
  2938.             values("]" + Se + lin + Se + Chr(127))
  2939.         lin = '6'
  2940.     Endif
  2941.  
  2942.     Insert Into comando;
  2943.         VALUES ( "]" + Se + lin + Se + "Vendedor: "+Alltrim(goApp.User) )
  2944.  
  2945.     lin = '7'
  2946.     Insert Into comando;
  2947.         VALUES ("]" + Se + lin + Se + Chr(127))
  2948.  
  2949.     lin = '8'
  2950.     Insert Into comando;
  2951.         VALUES ("]" + Se + lin + Se + Chr(127))
  2952.  
  2953.     lin = '11'
  2954. *!*     Insert Into comando;
  2955. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  2956.     Insert Into comando;
  2957.         VALUES ("]" + Se + lin + Se + Chr(127))
  2958. Endif
  2959.  
  2960. If This.Ticket="S"
  2961.     Insert Into comando;
  2962.         VALUES ( "]" + Se + "9" + Se +Chr(127))
  2963.     Insert Into comando;
  2964.         VALUES ("]" + Se + "10" + Se +Chr(127))
  2965.     If This.condicion = 'C' And Val(sCliente) = 1
  2966.         Insert Into comando;
  2967.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  2968.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  2969.             " S/NOMBRE")
  2970.     Else
  2971.         Insert Into comando;
  2972.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  2973.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  2974.             SUBSTR(Alltrim(thisformset.frmCliente.txtDomicilio.Value)+" "+Alltrim(loc.nombre)+;
  2975.             " "+Alltrim(loc.provincia),1,40))
  2976.     Endif
  2977.  
  2978. Else
  2979. &&"["+sCliente+"] "+
  2980.     Insert Into comando;
  2981.         VALUES ( "b" + Se + "[" + sCliente + "] " + Substr(sNombre,1,40) + Se +;
  2982.         ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se + ;
  2983.         ALLTRIM(Thisform.txtDom.Value)+" ("+Alltrim(clientes.codpos)+") "+;
  2984.         Alltrim(loc.nombre)+" "+Alltrim(loc.provincia))
  2985. Endif
  2986. If This.condicion <> "C"
  2987.     Insert Into comando;
  2988.         VALUES (Chr(64)+Se+TIPO_FACTURA+Se+"T")
  2989. Else
  2990. &&Definir tipo y num de factura afectado por nota de credito
  2991.     Insert Into comando;
  2992.         VALUES (Chr(147) + Se + "1" + Se + cre.tipoaf + " " + cre.numeroaf)
  2993.     Insert Into comando;
  2994.         VALUES (Chr(128)+Se+TIPO_FACTURA+Se+"T")
  2995. Endif
  2996.  
  2997. &&el cursor "DET" posee los items a facturar
  2998. Select("det")
  2999. Go Top
  3000. Do While ! Eof()
  3001. *!* Create Cursor det;
  3002. *!*     (cantidad n(12,4), unidad c(8), detalle c(40), total n(12,2), idArticulo int,;
  3003. *!*     unitario n(12,2), costo n(12,2), montoiva n(12,2), montodgr n(12,2), montomuni N(12,2),;
  3004. *!*     poriva n(12,2), tipoiva c(2))  
  3005.     If det.unitario != 0
  3006.         If This.clase = "A"
  3007.             If This.Ticket = "S"
  3008.                 Insert Into comando;
  3009.                     VALUES ("A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  3010.                 Insert Into comando;
  3011.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + Se +;
  3012.                     ALLTRIM(Str(det.cantidad,6,2)+"0")+ Se +;
  3013.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  3014.                     ALLTRIM(Str(det.poriva,5,2)) + Se +;
  3015.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  3016.             Else
  3017.                 Insert Into comando;
  3018.                     VALUES ("B" + Se + det.unidad +" "+det.detalle+ Se + ;
  3019.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  3020.                     Alltrim(Str(det.unitario,13,2)) + ;
  3021.                     Se +Alltrim(Str(det.poriva,5,2)) + Se + ;
  3022.                     "M" + Se + "0" + Se + "" + Se + "T")
  3023.  
  3024.             Endif
  3025.         Else
  3026.             If This.Ticket = "S"
  3027.                 Insert Into comando;
  3028.                     VALUES ( "A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  3029.                 Insert Into comando;
  3030.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + ;
  3031.                     Se +Alltrim(Str(det.cantidad,6,2)+"0")+ Se + ;
  3032.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  3033.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  3034.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  3035.             Else
  3036.                 Insert Into comando;
  3037.                     VALUES ("B" + Se + det.unidad+" "+det.detalle+ Se +;
  3038.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  3039.                     ALLTRIM(Str(det.unitario,13,2)) + Se +;
  3040.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  3041.                     "M" + Se + "0" + Se + "" + Se + "T")
  3042.             Endif
  3043.         Endif
  3044.     Endif
  3045.     Select("det")
  3046.     Skip
  3047. Enddo
  3048.  
  3049.  
  3050. If This.condicion <> "C"
  3051.     If This.Ticket = "S"
  3052.         If This.contado = "S"
  3053.             Insert Into comando;
  3054.                 VALUES (Chr(68)+ Se + Substr(formapago.detalle,1,30)+ Se + ;
  3055.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  3056.         Else
  3057.             Insert Into comando;
  3058.                 VALUES ( Chr(68)+ Se + Substr(formapago.detalle,1,30)+ ;
  3059.                 Se + Alltrim(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  3060.         Endif
  3061.     Else
  3062.         If This.contado = "S"
  3063.             Insert Into comando;
  3064.                 VALUES (Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  3065.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  3066.         Else
  3067.             Insert Into comando;
  3068.                 VALUES(Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  3069.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  3070.         Endif
  3071.     Endif
  3072. Endif
  3073.  
  3074. If This.condicion <> "C"
  3075.     Insert Into comando;
  3076.         VALUES (Chr(69))
  3077. Else
  3078.     Insert Into comando;
  3079.         VALUES ( Chr(129) )
  3080. Endif
  3081.  
  3082.  
  3083. &&en esta parte copio el archivo con los comandos a la carpeta desde el cual
  3084. &&el spooler de impresion lee el archivo
  3085. If This.Ticket ="S"
  3086. && si es ticket me fijo a cual impresora debo enviar
  3087.     If lImpreFiscal
  3088.         mtXt = Alltrim(impfis.dircoticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  3089.         maNs = Alltrim(impfis.dirreticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  3090.     Else
  3091.         mtXt = Alltrim(parametr.dirco)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  3092.         maNs = Alltrim(parametr.dirre)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  3093.     Endif
  3094. *!*     cDirCom = "fpserver715" + "\impred.exe"
  3095. *!*     cDirCom = Fullpath(cDirCom)
  3096. *!* && Mato el proceso del spooler y lo vuelvo a cargar
  3097. *!*     This.killprocessbyname("impred.exe")
  3098. *!*     This.killprocessbyname("wspooler.exe")
  3099. *!*     oShell = Createobject("Shell.Application")
  3100. *!*     oShell.ShellExecute (cDirCom)
  3101. Else
  3102. &&aca envio a la 320
  3103.     If lImpreFiscal
  3104.         mtXt = Alltrim(impfis.dircofactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  3105.         maNs = Alltrim(impfis.dirrefactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  3106.     Else
  3107.         mtXt = Alltrim(parametr.dirco)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  3108.         maNs = Alltrim(parametr.dirre)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  3109.     Endif
  3110. Endif
  3111.  
  3112.  
  3113. Select("comando")
  3114. Goto Top
  3115. &&en caso de que tenga un archivo en la cola de impresion de la impresora
  3116. &&no se deja imprimir
  3117. *Browse
  3118. If File(mtXt)
  3119.     Messagebox("ATENCION: Ud. ya tiene un Documento en Cola de Impresión"+Chr(10)+Chr(13)+;
  3120.         " AGUARDE a que el mismo sea impreso o elimínelo luego vuelva a intentar")
  3121.     Return This.TodoOK
  3122. Else
  3123.     Copy To &mtXt Sdf
  3124.     If File(maNs)
  3125.         Erase &maNs
  3126.     Endif
  3127.     If File(Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  3128.         Erase (Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  3129.     Endif
  3130.     Wait Windows 'Esperando Respuesta del Controlador Fiscal...' Nowait
  3131.     fd = -1
  3132.     intentos =1
  3133.     Do While fd < 0 .And. Lastkey() != 27
  3134.         fd = Fopen(maNs, 0)
  3135.         This.LeerSpooler("T")
  3136.         If intentos = 30
  3137.             Messagebox("ATENCION: Verifique que el Controlador Esté Conectado y Encendido. " + Chr(10) + Chr(13)+ ;
  3138.                 "Verifique además que el Programa Spooler se esté ejecutando " + Chr(10) + Chr(13)+ ;
  3139.                 "en el equipo al cual se encuentra conectado el Controlador Fiscal")
  3140.             This.LeerSpooler("T")
  3141.         Endif
  3142.         If intentos = 70
  3143.             Messagebox("ATENCION: Tiempo de Espera Agotado !!! Presione ESC. para cancelar este Comprobante")
  3144.             This.LeerSpooler("T")
  3145.         Endif
  3146.         intentos = intentos + 1
  3147. *For i=1 To 100
  3148. *Next
  3149.         Inkey(1)
  3150.         If Lastkey() = 27
  3151.             If Substr(comando.comando,17,16) = "Impresor Ocupado"
  3152.                 Messagebox("ATENCION: No se aconseja cancelar este documento por programa, "+;
  3153.                     CHR(10)+Chr(13)+"La impresora ya lo ha procesado y saldrá impreso"+;
  3154.                     CHR(10)+Chr(13)+ "una vez que esta se ponga en linea")
  3155.             Endif
  3156.             If Messagebox("ATENCION: Realmente desea Cancelar la Emisión de este Documento??",4+256) = 6
  3157.                 Messagebox(" Se proceder  a Cancelar el Documento por Sistema"+;
  3158.                     CHR(10)+Chr(13)+" Verifique que la impresora también lo haya Cancelado.")
  3159.                 Keyboard '{ESC}'
  3160.             Else
  3161.                 Keyboard ""
  3162.             Endif
  3163.         Endif
  3164.     Enddo
  3165.     If Lastkey() = 27.Or. fd < 0
  3166.         If File(mtXt)
  3167.             Erase &mtXt
  3168.         Endif
  3169.         fd = Fopen((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"), 0)
  3170.         If fd < 0
  3171.             Messagebox("Operación Cancelada: ERROR de comunicaciones con el Controlador.; Probablemente no se este ejecutando Spooler. ")
  3172.         Else
  3173.             fd =Fclose(fd)
  3174.             This.LeerSpooler("T")
  3175.         Endif
  3176.     Else
  3177.         fd = Fclose(fd)
  3178.         Select("comando")
  3179.         Zap
  3180.         Append From &maNs Sdf
  3181.         Goto Bottom
  3182.         This.numero = Val(Substr(comando.comando,35,8))
  3183.         If This.numero <> 0
  3184.             SQLExec(goApp.nCon, "select * from puntero where sucursal=?param.sucursal","puntero")
  3185.             If This.Ticket = "S"
  3186.                 If This.MasDeMil
  3187.                     This.numero = Val('0009'+strzero(This.numero,8))
  3188.                 Else
  3189.                     If lImpreFiscal
  3190.                         This.numero = Val(impfis.PtoVtaTicket+strzero(This.numero,8))
  3191.                     Else
  3192.                         If Param.sucursal=0
  3193.                             If File("c:\0009.txt")
  3194.                                 This.numero = Val(strzero(9,4)+strzero(This.numero,8))
  3195.                             Else
  3196.                                 This.numero = Val(strzero(puntero.pvta_tic,4)+strzero(This.numero,8))
  3197.                             Endif
  3198.                         Else
  3199.                             If Param.sucursal = 1
  3200.                                 This.numero = Val(strzero(8,4)+strzero(This.numero,8))
  3201.                             Endif
  3202.                         Endif
  3203.                     Endif
  3204.                 Endif
  3205.             Else
  3206.                 If lImpreFiscal
  3207.                     This.numero = Val(impfis.PtoVtaFac+strzero(This.numero,8))
  3208.                 Else
  3209.                     This.numero = Val(strzero(puntero.pvta_fac,4)+strzero(This.numero,8))
  3210.                 Endif
  3211.             Endif
  3212.             This.TodoOK = .T.
  3213.         Endif
  3214.     Endif
  3215.     If File((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"))
  3216.         Erase Alltrim(paramfac.dirpa)+"SPOOLER.LOG"
  3217.     Endif
  3218. Endif
  3219. *This.killprocessbyname("impred.exe")
  3220. *This.killprocessbyname("wspooler.exe")
  3221.  
  3222. Set Talk &cTalk
  3223. Return This.Todo
  3224. *!*     Return -1
  3225. *!* Endif
  3226.  
  3227. &&indica si el cliente tiene que poseer cuit
  3228. If tiporesp.obligacuit
  3229.     If Empty( Val( Strtran( clientes.cuit, "-" ) ) )
  3230.         Messagebox ("ATENCION: Falta Registrar CUIT de Cliente", 0+48, "CUIT")
  3231.         Do While Val(ndocu) < 2
  3232.             ndocu = Inputbox("Ingrese CUIT")
  3233.         Enddo
  3234.         ndocu = Alltrim( Strtran( ndocu, "-" ) )
  3235.     Else
  3236.         TIPO_DOCU = 'C' &&tiporesp.tipo_iva &&"C"
  3237.         ndocu = Alltrim( Strtran( clientes.cuit, "-" ) )
  3238.     Endif
  3239. Else
  3240.     If SQLExec(goApp.nCon, "select * from tipodoc where codigo=?clientes.tipodocu","tipodoc") = -1
  3241.         goApp.Error()
  3242.         Return -1
  3243.     Endif
  3244.     If Reccount("tipodoc") > 0
  3245.         TIPO_DOCU = tipodoc.tipo
  3246.     Else
  3247.         TIPO_DOCU = '2'
  3248.     Endif
  3249.     ndocu = Alltrim(Str(clientes.dni))
  3250.     If Val(ndocu) < 2
  3251.         ndocu = '11111111'
  3252.     Endif
  3253. Endif
  3254.  
  3255. TIPO_IVA = tiporesp.TIPOIVA
  3256. Select("comando")
  3257.  
  3258. &&me fijo si es ticket factura o factura
  3259. If This.Ticket = "S"
  3260.     lin = "5"
  3261. Else
  3262.     lin = "3"
  3263. Endif
  3264.  
  3265. If This.Ticket = "N"
  3266. &&en caso de ser factura imprimo todo el encabezado que va en la factura
  3267.     Select("comando")
  3268.     Insert Into comando;
  3269.         VALUES( "]" + Se + "1" + Se + Chr(127) )
  3270.     Insert Into comando;
  3271.         VALUES( "]" + Se + "2" + Se + Chr(127) )
  3272.  
  3273.     Insert Into comando;
  3274.         values( "]" + Se + "2" + Se + "Ing.Brut. 914-532186-1"  )
  3275.     If This.contado = "N"
  3276.         Insert Into comando;
  3277.             VALUES ("]" + Se + lin + Se + ;
  3278.             "Vendedor: "+Alltrim(vendedor.nom_ven)+;
  3279.             SPACE(10)+"Vencimiento de este Comp.: "+;
  3280.             DTOC(This.FechaVen(Thisform.txtFecha.Value))+;
  3281.             " Saldo Actual de CTA_CTE(S.E.U.O.): $"+;
  3282.             ALLTRIM(Str((m.salctacte),12,2)))
  3283.     Else
  3284.         Insert Into comando;
  3285.             VALUES ("]" + Se + lin + Se + "Vendedor: "+;
  3286.             ALLTRIM(vendedor.nom_ven)+;
  3287.             SPACE(10)+"Vencimiento de este Comp.: "+;
  3288.             DTOC(This.FechaVen(Thisform.txtFecha.Value)))
  3289.     Endif
  3290.  
  3291.     lin = Str(Val(lin)+1,1,0)
  3292.  
  3293.     Do Case
  3294.     Case Used("obsfac")
  3295.         Insert Into comando;
  3296.             VALUES ("]" + Se + lin + Se + "OBS.: "+Alltrim(obsfac.obs1)+Alltrim(obsfac.obs2))
  3297.     Case This.pagoanticipado &&det.pagoanticipado
  3298.         If det.reparto
  3299.             Insert Into comando;
  3300.                 VALUES ("]" + Se + lin + Se + "PAGO ANTICIPADO - REPARTO")
  3301.         Else
  3302.             Insert Into comando;
  3303.                 VALUES ("]" + Se + lin + Se + "PAGO ANTICIPADO - RETIRA")
  3304.         Endif
  3305.     Case This.lReparto
  3306.         Insert Into comando;
  3307.             VALUES ("]" + Se + lin + Se + "MERCADERIA DE REPARTO")
  3308.     Case !This.lReparto
  3309.         Insert Into comando;
  3310.             VALUES ("]" + Se + lin + Se + "MERCADERIA PARA RETIRAR")
  3311.     Otherwise
  3312.         Insert Into comando;
  3313.             VALUES ("]" + Se + lin + Se + "DEVOLUCIONES DENTRO DE LAS 48 HRS.")
  3314.     Endcase
  3315.  
  3316.     lin = Str(Val(lin)+1,1,0)
  3317.     This.letras.dicenum(m.nTOTAL)
  3318.     Insert Into comando;
  3319.         VALUES ( "]" + Se + lin + Se + ;
  3320.         "SON:" + This.letras.retorno)
  3321.  
  3322.     lin = "11"
  3323.  
  3324. &&especifico las formas de cancelacion que posee la factura
  3325.     If pagos.adic1 > 0 .Or. pagos.plazo1 > 0
  3326.         Insert Into comando;
  3327.             VALUES ( "]" + Se + lin + Se + ;
  3328.             "OPCION DE PAGO: Hasta el "+;
  3329.             Dtoc(Thisform.txtFecha.Value+This.dias())+ " "+;
  3330.             STR(pagos.adic1)+" % Desc. $ "+;
  3331.             STR(m.nTOTAL*pagos.adic1/100,08,2)+;
  3332.             " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic1)/100),10,2))
  3333.     Else
  3334.         If Inlist(pagos.pago,'00','01','02')
  3335.             Insert Into comando;
  3336.                 VALUES ( "]" + Se + lin + Se + ;
  3337.                 "OPCION DE PAGO: Contado Efectivo"+;
  3338.                 " 3% Desc. "+;
  3339.                 " Paga $ "+ Str(m.nTOTAL,10,2))
  3340.         Else
  3341.             Insert Into comando;
  3342.                 VALUES ( "]" + Se + lin + Se + Chr(127))
  3343.         Endif
  3344.     Endif
  3345.  
  3346.     lin = Str(Val(lin)+1,2,0)
  3347.  
  3348.     If pagos.adic2 > 0 .Or. pagos.plazo2 > 0
  3349.         If Isnull(pagos.dia) Or Empty(pagos.dia)
  3350.             Insert Into comando;
  3351.                 VALUES ( "]" + Se + lin + Se +;
  3352.                 "OPCION DE PAGO: Hasta el "+ ;
  3353.                 DTOC(This.FechaVen(Thisform.txtFecha.Value))+"  "+;
  3354.                 STR(pagos.adic2)+" % Desc. $ ";
  3355.                 +Str(m.nTOTAL*pagos.adic2/100,08,2)+;
  3356.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  3357.         Else
  3358.             If pagos.pago = '51'
  3359. *!* Pongo esto para que en esta condicion no me sume los dias de ADIC2
  3360.                 Insert Into comando;
  3361.                     VALUES ("]" + Se + lin + Se +  ;
  3362.                     "OPCION DE PAGO: Hasta el "+ ;
  3363.                     DTOC(pagos.dia)+"  "+;
  3364.                     STR(pagos.adic2)+" % Desc. $ "+;
  3365.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  3366.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  3367.             Else
  3368.                 Insert Into comando;
  3369.                     VALUES ("]" + Se + lin + Se +  ;
  3370.                     "OPCION DE PAGO: Hasta el "+ ;
  3371.                     DTOC(This.FechaVen(Thisform.txtFecha.Value))+"  "+;
  3372.                     STR(pagos.adic2)+" % Desc. $ "+;
  3373.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  3374.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  3375.             Endif
  3376.         Endif
  3377.     Else
  3378.         Insert Into comando;
  3379.             VALUES ( "]" + Se + lin + Se + Chr(127) )
  3380.     Endif
  3381.  
  3382.     lin = Str(Val(lin)+1,2,0)
  3383.  
  3384.     If pagos.adic3 > 0 .Or. pagos.plazo3 >0
  3385.         If Isnull(pagos.dia) Or Empty(pagos.dia)
  3386.             Insert Into comando;
  3387.                 VALUES ("]" + Se + lin + Se + ;
  3388.                 "OPCION DE PAGO: Hasta el "+ ;
  3389.                 DTOC(Thisform.txtFecha.Value+Cast(pagos.dias1 As Integer))+"  "+;
  3390.                 STR(pagos.adic3)+" % Desc. $ "+;
  3391.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  3392.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  3393.         Else
  3394.             Insert Into comando;
  3395.                 VALUES ("]" + Se + lin + Se + ;
  3396.                 "OPCION DE PAGO: Hasta el "+ ;
  3397.                 DTOC(pagos.dia+Cast(pagos.dias1 As Integer))+"  "+;
  3398.                 STR(pagos.adic3)+" % Desc. $ "+;
  3399.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  3400.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  3401.         Endif
  3402.     Else
  3403.         Insert Into comando;
  3404.             VALUES ("]" + Se + lin + Se + Chr(127))
  3405.     Endif
  3406.  
  3407.     lin = Str(Val(lin)+1,2,0)
  3408. *!*     Insert Into comando;
  3409. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  3410.     If m.nFlete > 0 Or m.nDRet > 0
  3411.         If m.nFlete > 0
  3412.             Insert Into comando;
  3413.                 VALUES ("]" + Se + lin + Se + ;
  3414.                 "Prec. de Merc. Incl. Flete "+ ;
  3415.                 Transform(m.nFlete, "@$ 99,999,999.99"))
  3416.         Else
  3417.             Insert Into comando;
  3418.                 VALUES ("]" + Se + lin + Se + ;
  3419.                 "Merc. Incl. Desc p/RETIRA "+ ;
  3420.                 Transform(m.nDRet, "@$ 99,999,999.99"))
  3421.         Endif
  3422.     Else
  3423.         Insert Into comando;
  3424.             VALUES ("]" + Se + lin + Se + Chr(127))
  3425.     Endif
  3426.  
  3427. &&si se factura sobre remitos se imprimen los remitos afectados
  3428.     If Thisform.viene = "X" &&hay q revisar esto para ver q cuando se factura de remitos se imprima
  3429.         Insert Into comando;
  3430.             VALUES ( Chr(147) + Se + "1" + Se + Substr(This.remitosafacturar,1,17))
  3431.         If !Empty(Substr(This.remitosafacturar,19,20))
  3432.             Insert Into comando;
  3433.                 VALUES (Chr(147) + Se + "2" + Se + Substr(This.remitosafacturar,19,20))
  3434.         Endif
  3435.     Endif
  3436. Else
  3437.     If This.contado = 'N'
  3438.         Insert Into comando;
  3439.             values("]" + Se + lin + Se+;
  3440.             " Saldo de CTA_CTE: $"+;
  3441.             ALLTRIM(Str((m.salctacte),12,2)))
  3442.         lin = '6'
  3443.     Else
  3444.         Insert Into comando;
  3445.             values("]" + Se + lin + Se + Chr(127))
  3446.         lin = '6'
  3447.     Endif
  3448.  
  3449.     Insert Into comando;
  3450.         VALUES ( "]" + Se + lin + Se + "Vendedor: "+Alltrim(goApp.User) )
  3451.  
  3452.     lin = '7'
  3453.     Insert Into comando;
  3454.         VALUES ("]" + Se + lin + Se + Chr(127))
  3455.  
  3456.     lin = '8'
  3457.     Insert Into comando;
  3458.         VALUES ("]" + Se + lin + Se + Chr(127))
  3459.  
  3460.     lin = '11'
  3461. *!*     Insert Into comando;
  3462. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  3463.     Insert Into comando;
  3464.         VALUES ("]" + Se + lin + Se + Chr(127))
  3465. Endif
  3466.  
  3467. If This.Ticket="S"
  3468.     Insert Into comando;
  3469.         VALUES ( "]" + Se + "9" + Se +Chr(127))
  3470.     Insert Into comando;
  3471.         VALUES ("]" + Se + "10" + Se +Chr(127))
  3472.     If This.condicion = 'C' And Val(sCliente) = 1
  3473.         Insert Into comando;
  3474.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  3475.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  3476.             " S/NOMBRE")
  3477.     Else
  3478.         Insert Into comando;
  3479.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  3480.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  3481.             SUBSTR(Alltrim(thisformset.frmCliente.txtDomicilio.Value)+" "+Alltrim(loc.nombre)+;
  3482.             " "+Alltrim(loc.provincia),1,40))
  3483.     Endif
  3484.  
  3485. Else
  3486. &&"["+sCliente+"] "+
  3487.     Insert Into comando;
  3488.         VALUES ( "b" + Se + "[" + sCliente + "] " + Substr(sNombre,1,40) + Se +;
  3489.         ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se + ;
  3490.         ALLTRIM(Thisform.txtDom.Value)+" ("+Alltrim(clientes.codpos)+") "+;
  3491.         Alltrim(loc.nombre)+" "+Alltrim(loc.provincia))
  3492. Endif
  3493. If This.condicion <> "C"
  3494.     Insert Into comando;
  3495.         VALUES (Chr(64)+Se+TIPO_FACTURA+Se+"T")
  3496. Else
  3497. &&Definir tipo y num de factura afectado por nota de credito
  3498.     Insert Into comando;
  3499.         VALUES (Chr(147) + Se + "1" + Se + cre.tipoaf + " " + cre.numeroaf)
  3500.     Insert Into comando;
  3501.         VALUES (Chr(128)+Se+TIPO_FACTURA+Se+"T")
  3502. Endif
  3503.  
  3504. &&el cursor "DET" posee los items a facturar
  3505. Select("det")
  3506. Go Top
  3507. Do While ! Eof()
  3508. *!* Create Cursor det;
  3509. *!*     (cantidad n(12,4), unidad c(8), detalle c(40), total n(12,2), idArticulo int,;
  3510. *!*     unitario n(12,2), costo n(12,2), montoiva n(12,2), montodgr n(12,2), montomuni N(12,2),;
  3511. *!*     poriva n(12,2), tipoiva c(2))  
  3512.     If det.unitario != 0
  3513.         If This.clase = "A"
  3514.             If This.Ticket = "S"
  3515.                 Insert Into comando;
  3516.                     VALUES ("A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  3517.                 Insert Into comando;
  3518.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + Se +;
  3519.                     ALLTRIM(Str(det.cantidad,6,2)+"0")+ Se +;
  3520.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  3521.                     ALLTRIM(Str(det.poriva,5,2)) + Se +;
  3522.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  3523.             Else
  3524.                 Insert Into comando;
  3525.                     VALUES ("B" + Se + det.unidad +" "+det.detalle+ Se + ;
  3526.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  3527.                     Alltrim(Str(det.unitario,13,2)) + ;
  3528.                     Se +Alltrim(Str(det.poriva,5,2)) + Se + ;
  3529.                     "M" + Se + "0" + Se + "" + Se + "T")
  3530.  
  3531.             Endif
  3532.         Else
  3533.             If This.Ticket = "S"
  3534.                 Insert Into comando;
  3535.                     VALUES ( "A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  3536.                 Insert Into comando;
  3537.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + ;
  3538.                     Se +Alltrim(Str(det.cantidad,6,2)+"0")+ Se + ;
  3539.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  3540.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  3541.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  3542.             Else
  3543.                 Insert Into comando;
  3544.                     VALUES ("B" + Se + det.unidad+" "+det.detalle+ Se +;
  3545.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  3546.                     ALLTRIM(Str(det.unitario,13,2)) + Se +;
  3547.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  3548.                     "M" + Se + "0" + Se + "" + Se + "T")
  3549.             Endif
  3550.         Endif
  3551.     Endif
  3552.     Select("det")
  3553.     Skip
  3554. Enddo
  3555.  
  3556.  
  3557. If This.condicion <> "C"
  3558.     If This.Ticket = "S"
  3559.         If This.contado = "S"
  3560.             Insert Into comando;
  3561.                 VALUES (Chr(68)+ Se + Substr(formapago.detalle,1,30)+ Se + ;
  3562.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  3563.         Else
  3564.             Insert Into comando;
  3565.                 VALUES ( Chr(68)+ Se + Substr(formapago.detalle,1,30)+ ;
  3566.                 Se + Alltrim(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  3567.         Endif
  3568.     Else
  3569.         If This.contado = "S"
  3570.             Insert Into comando;
  3571.                 VALUES (Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  3572.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  3573.         Else
  3574.             Insert Into comando;
  3575.                 VALUES(Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  3576.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  3577.         Endif
  3578.     Endif
  3579. Endif
  3580.  
  3581. If This.condicion <> "C"
  3582.     Insert Into comando;
  3583.         VALUES (Chr(69))
  3584. Else
  3585.     Insert Into comando;
  3586.         VALUES ( Chr(129) )
  3587. Endif
  3588.  
  3589.  
  3590. &&en esta parte copio el archivo con los comandos a la carpeta desde el cual
  3591. &&el spooler de impresion lee el archivo
  3592. If This.Ticket ="S"
  3593. && si es ticket me fijo a cual impresora debo enviar
  3594.     If lImpreFiscal
  3595.         mtXt = Alltrim(impfis.dircoticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  3596.         maNs = Alltrim(impfis.dirreticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  3597.     Else
  3598.         mtXt = Alltrim(parametr.dirco)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  3599.         maNs = Alltrim(parametr.dirre)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  3600.     Endif
  3601. *!*     cDirCom = "fpserver715" + "\impred.exe"
  3602. *!*     cDirCom = Fullpath(cDirCom)
  3603. *!* && Mato el proceso del spooler y lo vuelvo a cargar
  3604. *!*     This.killprocessbyname("impred.exe")
  3605. *!*     This.killprocessbyname("wspooler.exe")
  3606. *!*     oShell = Createobject("Shell.Application")
  3607. *!*     oShell.ShellExecute (cDirCom)
  3608. Else
  3609. &&aca envio a la 320
  3610.     If lImpreFiscal
  3611.         mtXt = Alltrim(impfis.dircofactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  3612.         maNs = Alltrim(impfis.dirrefactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  3613.     Else
  3614.         mtXt = Alltrim(parametr.dirco)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  3615.         maNs = Alltrim(parametr.dirre)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  3616.     Endif
  3617. Endif
  3618.  
  3619.  
  3620. Select("comando")
  3621. Goto Top
  3622. &&en caso de que tenga un archivo en la cola de impresion de la impresora
  3623. &&no se deja imprimir
  3624. *Browse
  3625. If File(mtXt)
  3626.     Messagebox("ATENCION: Ud. ya tiene un Documento en Cola de Impresión"+Chr(10)+Chr(13)+;
  3627.         " AGUARDE a que el mismo sea impreso o elimínelo luego vuelva a intentar")
  3628.     Return This.TodoOK
  3629. Else
  3630.     Copy To &mtXt Sdf
  3631.     If File(maNs)
  3632.         Erase &maNs
  3633.     Endif
  3634.     If File(Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  3635.         Erase (Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  3636.     Endif
  3637.     Wait Windows 'Esperando Respuesta del Controlador Fiscal...' Nowait
  3638.     fd = -1
  3639.     intentos =1
  3640.     Do While fd < 0 .And. Lastkey() != 27
  3641.         fd = Fopen(maNs, 0)
  3642.         This.LeerSpooler("T")
  3643.         If intentos = 30
  3644.             Messagebox("ATENCION: Verifique que el Controlador Esté Conectado y Encendido. " + Chr(10) + Chr(13)+ ;
  3645.                 "Verifique además que el Programa Spooler se esté ejecutando " + Chr(10) + Chr(13)+ ;
  3646.                 "en el equipo al cual se encuentra conectado el Controlador Fiscal")
  3647.             This.LeerSpooler("T")
  3648.         Endif
  3649.         If intentos = 70
  3650.             Messagebox("ATENCION: Tiempo de Espera Agotado !!! Presione ESC. para cancelar este Comprobante")
  3651.             This.LeerSpooler("T")
  3652.         Endif
  3653.         intentos = intentos + 1
  3654. *For i=1 To 100
  3655. *Next
  3656.         Inkey(1)
  3657.         If Lastkey() = 27
  3658.             If Substr(comando.comando,17,16) = "Impresor Ocupado"
  3659.                 Messagebox("ATENCION: No se aconseja cancelar este documento por programa, "+;
  3660.                     CHR(10)+Chr(13)+"La impresora ya lo ha procesado y saldrá impreso"+;
  3661.                     CHR(10)+Chr(13)+ "una vez que esta se ponga en linea")
  3662.             Endif
  3663.             If Messagebox("ATENCION: Realmente desea Cancelar la Emisión de este Documento??",4+256) = 6
  3664.                 Messagebox(" Se proceder  a Cancelar el Documento por Sistema"+;
  3665.                     CHR(10)+Chr(13)+" Verifique que la impresora también lo haya Cancelado.")
  3666.                 Keyboard '{ESC}'
  3667.             Else
  3668.                 Keyboard ""
  3669.             Endif
  3670.         Endif
  3671.     Enddo
  3672.     If Lastkey() = 27.Or. fd < 0
  3673.         If File(mtXt)
  3674.             Erase &mtXt
  3675.         Endif
  3676.         fd = Fopen((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"), 0)
  3677.         If fd < 0
  3678.             Messagebox("Operación Cancelada: ERROR de comunicaciones con el Controlador.; Probablemente no se este ejecutando Spooler. ")
  3679.         Else
  3680.             fd =Fclose(fd)
  3681.             This.LeerSpooler("T")
  3682.         Endif
  3683.     Else
  3684.         fd = Fclose(fd)
  3685.         Select("comando")
  3686.         Zap
  3687.         Append From &maNs Sdf
  3688.         Goto Bottom
  3689.         This.numero = Val(Substr(comando.comando,35,8))
  3690.         If This.numero <> 0
  3691.             SQLExec(goApp.nCon, "select * from puntero where sucursal=?param.sucursal","puntero")
  3692.             If This.Ticket = "S"
  3693.                 If This.MasDeMil
  3694.                     This.numero = Val('0009'+strzero(This.numero,8))
  3695.                 Else
  3696.                     If lImpreFiscal
  3697.                         This.numero = Val(impfis.PtoVtaTicket+strzero(This.numero,8))
  3698.                     Else
  3699.                         If Param.sucursal=0
  3700.                             If File("c:\0009.txt")
  3701.                                 This.numero = Val(strzero(9,4)+strzero(This.numero,8))
  3702.                             Else
  3703.                                 This.numero = Val(strzero(puntero.pvta_tic,4)+strzero(This.numero,8))
  3704.                             Endif
  3705.                         Else
  3706.                             If Param.sucursal = 1
  3707.                                 This.numero = Val(strzero(8,4)+strzero(This.numero,8))
  3708.                             Endif
  3709.                         Endif
  3710.                     Endif
  3711.                 Endif
  3712.             Else
  3713.                 If lImpreFiscal
  3714.                     This.numero = Val(impfis.PtoVtaFac+strzero(This.numero,8))
  3715.                 Else
  3716.                     This.numero = Val(strzero(puntero.pvta_fac,4)+strzero(This.numero,8))
  3717.                 Endif
  3718.             Endif
  3719.             This.TodoOK = .T.
  3720.         Endif
  3721.     Endif
  3722.     If File((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"))
  3723.         Erase Alltrim(paramfac.dirpa)+"SPOOLER.LOG"
  3724.     Endif
  3725. Endif
  3726. *This.killprocessbyname("impred.exe")
  3727. *This.killprocessbyname("wspooler.exe")
  3728.  
  3729. Set Talk &cTalk
  3730. Return This.Todo
  3731. *!* Endif
  3732.  
  3733. &&indica si el cliente tiene que poseer cuit
  3734. If tiporesp.obligacuit
  3735.     If Empty( Val( Strtran( clientes.cuit, "-" ) ) )
  3736.         Messagebox ("ATENCION: Falta Registrar CUIT de Cliente", 0+48, "CUIT")
  3737.         Do While Val(ndocu) < 2
  3738.             ndocu = Inputbox("Ingrese CUIT")
  3739.         Enddo
  3740.         ndocu = Alltrim( Strtran( ndocu, "-" ) )
  3741.     Else
  3742.         TIPO_DOCU = 'C' &&tiporesp.tipo_iva &&"C"
  3743.         ndocu = Alltrim( Strtran( clientes.cuit, "-" ) )
  3744.     Endif
  3745. Else
  3746.     If SQLExec(goApp.nCon, "select * from tipodoc where codigo=?clientes.tipodocu","tipodoc") = -1
  3747.         goApp.Error()
  3748.         Return -1
  3749.     Endif
  3750.     If Reccount("tipodoc") > 0
  3751.         TIPO_DOCU = tipodoc.tipo
  3752.     Else
  3753.         TIPO_DOCU = '2'
  3754.     Endif
  3755.     ndocu = Alltrim(Str(clientes.dni))
  3756.     If Val(ndocu) < 2
  3757.         ndocu = '11111111'
  3758.     Endif
  3759. Endif
  3760.  
  3761. TIPO_IVA = tiporesp.TIPOIVA
  3762. Select("comando")
  3763.  
  3764. &&me fijo si es ticket factura o factura
  3765. If This.Ticket = "S"
  3766.     lin = "5"
  3767. Else
  3768.     lin = "3"
  3769. Endif
  3770.  
  3771. If This.Ticket = "N"
  3772. &&en caso de ser factura imprimo todo el encabezado que va en la factura
  3773.     Select("comando")
  3774.     Insert Into comando;
  3775.         VALUES( "]" + Se + "1" + Se + Chr(127) )
  3776.     Insert Into comando;
  3777.         VALUES( "]" + Se + "2" + Se + Chr(127) )
  3778.  
  3779.     Insert Into comando;
  3780.         values( "]" + Se + "2" + Se + "Ing.Brut. 914-532186-1"  )
  3781.     If This.contado = "N"
  3782.         Insert Into comando;
  3783.             VALUES ("]" + Se + lin + Se + ;
  3784.             "Vendedor: "+Alltrim(vendedor.nom_ven)+;
  3785.             SPACE(10)+"Vencimiento de este Comp.: "+;
  3786.             DTOC(This.FechaVen(Thisform.txtFecha.Value))+;
  3787.             " Saldo Actual de CTA_CTE(S.E.U.O.): $"+;
  3788.             ALLTRIM(Str((m.salctacte),12,2)))
  3789.     Else
  3790.         Insert Into comando;
  3791.             VALUES ("]" + Se + lin + Se + "Vendedor: "+;
  3792.             ALLTRIM(vendedor.nom_ven)+;
  3793.             SPACE(10)+"Vencimiento de este Comp.: "+;
  3794.             DTOC(This.FechaVen(Thisform.txtFecha.Value)))
  3795.     Endif
  3796.  
  3797.     lin = Str(Val(lin)+1,1,0)
  3798.  
  3799.     Do Case
  3800.     Case Used("obsfac")
  3801.         Insert Into comando;
  3802.             VALUES ("]" + Se + lin + Se + "OBS.: "+Alltrim(obsfac.obs1)+Alltrim(obsfac.obs2))
  3803.     Case This.pagoanticipado &&det.pagoanticipado
  3804.         If det.reparto
  3805.             Insert Into comando;
  3806.                 VALUES ("]" + Se + lin + Se + "PAGO ANTICIPADO - REPARTO")
  3807.         Else
  3808.             Insert Into comando;
  3809.                 VALUES ("]" + Se + lin + Se + "PAGO ANTICIPADO - RETIRA")
  3810.         Endif
  3811.     Case This.lReparto
  3812.         Insert Into comando;
  3813.             VALUES ("]" + Se + lin + Se + "MERCADERIA DE REPARTO")
  3814.     Case !This.lReparto
  3815.         Insert Into comando;
  3816.             VALUES ("]" + Se + lin + Se + "MERCADERIA PARA RETIRAR")
  3817.     Otherwise
  3818.         Insert Into comando;
  3819.             VALUES ("]" + Se + lin + Se + "DEVOLUCIONES DENTRO DE LAS 48 HRS.")
  3820.     Endcase
  3821.  
  3822.     lin = Str(Val(lin)+1,1,0)
  3823.     This.letras.dicenum(m.nTOTAL)
  3824.     Insert Into comando;
  3825.         VALUES ( "]" + Se + lin + Se + ;
  3826.         "SON:" + This.letras.retorno)
  3827.  
  3828.     lin = "11"
  3829.  
  3830. &&especifico las formas de cancelacion que posee la factura
  3831.     If pagos.adic1 > 0 .Or. pagos.plazo1 > 0
  3832.         Insert Into comando;
  3833.             VALUES ( "]" + Se + lin + Se + ;
  3834.             "OPCION DE PAGO: Hasta el "+;
  3835.             Dtoc(Thisform.txtFecha.Value+This.dias())+ " "+;
  3836.             STR(pagos.adic1)+" % Desc. $ "+;
  3837.             STR(m.nTOTAL*pagos.adic1/100,08,2)+;
  3838.             " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic1)/100),10,2))
  3839.     Else
  3840.         If Inlist(pagos.pago,'00','01','02')
  3841.             Insert Into comando;
  3842.                 VALUES ( "]" + Se + lin + Se + ;
  3843.                 "OPCION DE PAGO: Contado Efectivo"+;
  3844.                 " 3% Desc. "+;
  3845.                 " Paga $ "+ Str(m.nTOTAL,10,2))
  3846.         Else
  3847.             Insert Into comando;
  3848.                 VALUES ( "]" + Se + lin + Se + Chr(127))
  3849.         Endif
  3850.     Endif
  3851.  
  3852.     lin = Str(Val(lin)+1,2,0)
  3853.  
  3854.     If pagos.adic2 > 0 .Or. pagos.plazo2 > 0
  3855.         If Isnull(pagos.dia) Or Empty(pagos.dia)
  3856.             Insert Into comando;
  3857.                 VALUES ( "]" + Se + lin + Se +;
  3858.                 "OPCION DE PAGO: Hasta el "+ ;
  3859.                 DTOC(This.FechaVen(Thisform.txtFecha.Value))+"  "+;
  3860.                 STR(pagos.adic2)+" % Desc. $ ";
  3861.                 +Str(m.nTOTAL*pagos.adic2/100,08,2)+;
  3862.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  3863.         Else
  3864.             If pagos.pago = '51'
  3865. *!* Pongo esto para que en esta condicion no me sume los dias de ADIC2
  3866.                 Insert Into comando;
  3867.                     VALUES ("]" + Se + lin + Se +  ;
  3868.                     "OPCION DE PAGO: Hasta el "+ ;
  3869.                     DTOC(pagos.dia)+"  "+;
  3870.                     STR(pagos.adic2)+" % Desc. $ "+;
  3871.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  3872.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  3873.             Else
  3874.                 Insert Into comando;
  3875.                     VALUES ("]" + Se + lin + Se +  ;
  3876.                     "OPCION DE PAGO: Hasta el "+ ;
  3877.                     DTOC(This.FechaVen(Thisform.txtFecha.Value))+"  "+;
  3878.                     STR(pagos.adic2)+" % Desc. $ "+;
  3879.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  3880.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  3881.             Endif
  3882.         Endif
  3883.     Else
  3884.         Insert Into comando;
  3885.             VALUES ( "]" + Se + lin + Se + Chr(127) )
  3886.     Endif
  3887.  
  3888.     lin = Str(Val(lin)+1,2,0)
  3889.  
  3890.     If pagos.adic3 > 0 .Or. pagos.plazo3 >0
  3891.         If Isnull(pagos.dia) Or Empty(pagos.dia)
  3892.             Insert Into comando;
  3893.                 VALUES ("]" + Se + lin + Se + ;
  3894.                 "OPCION DE PAGO: Hasta el "+ ;
  3895.                 DTOC(Thisform.txtFecha.Value+Cast(pagos.dias1 As Integer))+"  "+;
  3896.                 STR(pagos.adic3)+" % Desc. $ "+;
  3897.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  3898.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  3899.         Else
  3900.             Insert Into comando;
  3901.                 VALUES ("]" + Se + lin + Se + ;
  3902.                 "OPCION DE PAGO: Hasta el "+ ;
  3903.                 DTOC(pagos.dia+Cast(pagos.dias1 As Integer))+"  "+;
  3904.                 STR(pagos.adic3)+" % Desc. $ "+;
  3905.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  3906.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  3907.         Endif
  3908.     Else
  3909.         Insert Into comando;
  3910.             VALUES ("]" + Se + lin + Se + Chr(127))
  3911.     Endif
  3912.  
  3913.     lin = Str(Val(lin)+1,2,0)
  3914. *!*     Insert Into comando;
  3915. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  3916.     If m.nFlete > 0 Or m.nDRet > 0
  3917.         If m.nFlete > 0
  3918.             Insert Into comando;
  3919.                 VALUES ("]" + Se + lin + Se + ;
  3920.                 "Prec. de Merc. Incl. Flete "+ ;
  3921.                 Transform(m.nFlete, "@$ 99,999,999.99"))
  3922.         Else
  3923.             Insert Into comando;
  3924.                 VALUES ("]" + Se + lin + Se + ;
  3925.                 "Merc. Incl. Desc p/RETIRA "+ ;
  3926.                 Transform(m.nDRet, "@$ 99,999,999.99"))
  3927.         Endif
  3928.     Else
  3929.         Insert Into comando;
  3930.             VALUES ("]" + Se + lin + Se + Chr(127))
  3931.     Endif
  3932.  
  3933. &&si se factura sobre remitos se imprimen los remitos afectados
  3934.     If Thisform.viene = "X" &&hay q revisar esto para ver q cuando se factura de remitos se imprima
  3935.         Insert Into comando;
  3936.             VALUES ( Chr(147) + Se + "1" + Se + Substr(This.remitosafacturar,1,17))
  3937.         If !Empty(Substr(This.remitosafacturar,19,20))
  3938.             Insert Into comando;
  3939.                 VALUES (Chr(147) + Se + "2" + Se + Substr(This.remitosafacturar,19,20))
  3940.         Endif
  3941.     Endif
  3942. Else
  3943.     If This.contado = 'N'
  3944.         Insert Into comando;
  3945.             values("]" + Se + lin + Se+;
  3946.             " Saldo de CTA_CTE: $"+;
  3947.             ALLTRIM(Str((m.salctacte),12,2)))
  3948.         lin = '6'
  3949.     Else
  3950.         Insert Into comando;
  3951.             values("]" + Se + lin + Se + Chr(127))
  3952.         lin = '6'
  3953.     Endif
  3954.  
  3955.     Insert Into comando;
  3956.         VALUES ( "]" + Se + lin + Se + "Vendedor: "+Alltrim(goApp.User) )
  3957.  
  3958.     lin = '7'
  3959.     Insert Into comando;
  3960.         VALUES ("]" + Se + lin + Se + Chr(127))
  3961.  
  3962.     lin = '8'
  3963.     Insert Into comando;
  3964.         VALUES ("]" + Se + lin + Se + Chr(127))
  3965.  
  3966.     lin = '11'
  3967. *!*     Insert Into comando;
  3968. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  3969.     Insert Into comando;
  3970.         VALUES ("]" + Se + lin + Se + Chr(127))
  3971. Endif
  3972.  
  3973. If This.Ticket="S"
  3974.     Insert Into comando;
  3975.         VALUES ( "]" + Se + "9" + Se +Chr(127))
  3976.     Insert Into comando;
  3977.         VALUES ("]" + Se + "10" + Se +Chr(127))
  3978.     If This.condicion = 'C' And Val(sCliente) = 1
  3979.         Insert Into comando;
  3980.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  3981.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  3982.             " S/NOMBRE")
  3983.     Else
  3984.         Insert Into comando;
  3985.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  3986.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  3987.             SUBSTR(Alltrim(thisformset.frmCliente.txtDomicilio.Value)+" "+Alltrim(loc.nombre)+;
  3988.             " "+Alltrim(loc.provincia),1,40))
  3989.     Endif
  3990.  
  3991. Else
  3992. &&"["+sCliente+"] "+
  3993.     Insert Into comando;
  3994.         VALUES ( "b" + Se + "[" + sCliente + "] " + Substr(sNombre,1,40) + Se +;
  3995.         ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se + ;
  3996.         ALLTRIM(Thisform.txtDom.Value)+" ("+Alltrim(clientes.codpos)+") "+;
  3997.         Alltrim(loc.nombre)+" "+Alltrim(loc.provincia))
  3998. Endif
  3999. If This.condicion <> "C"
  4000.     Insert Into comando;
  4001.         VALUES (Chr(64)+Se+TIPO_FACTURA+Se+"T")
  4002. Else
  4003. &&Definir tipo y num de factura afectado por nota de credito
  4004.     Insert Into comando;
  4005.         VALUES (Chr(147) + Se + "1" + Se + cre.tipoaf + " " + cre.numeroaf)
  4006.     Insert Into comando;
  4007.         VALUES (Chr(128)+Se+TIPO_FACTURA+Se+"T")
  4008. Endif
  4009.  
  4010. &&el cursor "DET" posee los items a facturar
  4011. Select("det")
  4012. Go Top
  4013. Do While ! Eof()
  4014. *!* Create Cursor det;
  4015. *!*     (cantidad n(12,4), unidad c(8), detalle c(40), total n(12,2), idArticulo int,;
  4016. *!*     unitario n(12,2), costo n(12,2), montoiva n(12,2), montodgr n(12,2), montomuni N(12,2),;
  4017. *!*     poriva n(12,2), tipoiva c(2))  
  4018.     If det.unitario != 0
  4019.         If This.clase = "A"
  4020.             If This.Ticket = "S"
  4021.                 Insert Into comando;
  4022.                     VALUES ("A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  4023.                 Insert Into comando;
  4024.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + Se +;
  4025.                     ALLTRIM(Str(det.cantidad,6,2)+"0")+ Se +;
  4026.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  4027.                     ALLTRIM(Str(det.poriva,5,2)) + Se +;
  4028.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  4029.             Else
  4030.                 Insert Into comando;
  4031.                     VALUES ("B" + Se + det.unidad +" "+det.detalle+ Se + ;
  4032.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  4033.                     Alltrim(Str(det.unitario,13,2)) + ;
  4034.                     Se +Alltrim(Str(det.poriva,5,2)) + Se + ;
  4035.                     "M" + Se + "0" + Se + "" + Se + "T")
  4036.  
  4037.             Endif
  4038.         Else
  4039.             If This.Ticket = "S"
  4040.                 Insert Into comando;
  4041.                     VALUES ( "A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  4042.                 Insert Into comando;
  4043.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + ;
  4044.                     Se +Alltrim(Str(det.cantidad,6,2)+"0")+ Se + ;
  4045.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  4046.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  4047.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  4048.             Else
  4049.                 Insert Into comando;
  4050.                     VALUES ("B" + Se + det.unidad+" "+det.detalle+ Se +;
  4051.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  4052.                     ALLTRIM(Str(det.unitario,13,2)) + Se +;
  4053.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  4054.                     "M" + Se + "0" + Se + "" + Se + "T")
  4055.             Endif
  4056.         Endif
  4057.     Endif
  4058.     Select("det")
  4059.     Skip
  4060. Enddo
  4061.  
  4062.  
  4063. If This.condicion <> "C"
  4064.     If This.Ticket = "S"
  4065.         If This.contado = "S"
  4066.             Insert Into comando;
  4067.                 VALUES (Chr(68)+ Se + Substr(formapago.detalle,1,30)+ Se + ;
  4068.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  4069.         Else
  4070.             Insert Into comando;
  4071.                 VALUES ( Chr(68)+ Se + Substr(formapago.detalle,1,30)+ ;
  4072.                 Se + Alltrim(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  4073.         Endif
  4074.     Else
  4075.         If This.contado = "S"
  4076.             Insert Into comando;
  4077.                 VALUES (Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  4078.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  4079.         Else
  4080.             Insert Into comando;
  4081.                 VALUES(Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  4082.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  4083.         Endif
  4084.     Endif
  4085. Endif
  4086.  
  4087. If This.condicion <> "C"
  4088.     Insert Into comando;
  4089.         VALUES (Chr(69))
  4090. Else
  4091.     Insert Into comando;
  4092.         VALUES ( Chr(129) )
  4093. Endif
  4094.  
  4095.  
  4096. &&en esta parte copio el archivo con los comandos a la carpeta desde el cual
  4097. &&el spooler de impresion lee el archivo
  4098. If This.Ticket ="S"
  4099. && si es ticket me fijo a cual impresora debo enviar
  4100.     If lImpreFiscal
  4101.         mtXt = Alltrim(impfis.dircoticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  4102.         maNs = Alltrim(impfis.dirreticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  4103.     Else
  4104.         mtXt = Alltrim(parametr.dirco)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  4105.         maNs = Alltrim(parametr.dirre)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  4106.     Endif
  4107. *!*     cDirCom = "fpserver715" + "\impred.exe"
  4108. *!*     cDirCom = Fullpath(cDirCom)
  4109. *!* && Mato el proceso del spooler y lo vuelvo a cargar
  4110. *!*     This.killprocessbyname("impred.exe")
  4111. *!*     This.killprocessbyname("wspooler.exe")
  4112. *!*     oShell = Createobject("Shell.Application")
  4113. *!*     oShell.ShellExecute (cDirCom)
  4114. Else
  4115. &&aca envio a la 320
  4116.     If lImpreFiscal
  4117.         mtXt = Alltrim(impfis.dircofactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  4118.         maNs = Alltrim(impfis.dirrefactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  4119.     Else
  4120.         mtXt = Alltrim(parametr.dirco)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  4121.         maNs = Alltrim(parametr.dirre)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  4122.     Endif
  4123. Endif
  4124.  
  4125.  
  4126. Select("comando")
  4127. Goto Top
  4128. &&en caso de que tenga un archivo en la cola de impresion de la impresora
  4129. &&no se deja imprimir
  4130. *Browse
  4131. If File(mtXt)
  4132.     Messagebox("ATENCION: Ud. ya tiene un Documento en Cola de Impresión"+Chr(10)+Chr(13)+;
  4133.         " AGUARDE a que el mismo sea impreso o elimínelo luego vuelva a intentar")
  4134.     Return This.TodoOK
  4135. Else
  4136.     Copy To &mtXt Sdf
  4137.     If File(maNs)
  4138.         Erase &maNs
  4139.     Endif
  4140.     If File(Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  4141.         Erase (Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  4142.     Endif
  4143.     Wait Windows 'Esperando Respuesta del Controlador Fiscal...' Nowait
  4144.     fd = -1
  4145.     intentos =1
  4146.     Do While fd < 0 .And. Lastkey() != 27
  4147.         fd = Fopen(maNs, 0)
  4148.         This.LeerSpooler("T")
  4149.         If intentos = 30
  4150.             Messagebox("ATENCION: Verifique que el Controlador Esté Conectado y Encendido. " + Chr(10) + Chr(13)+ ;
  4151.                 "Verifique además que el Programa Spooler se esté ejecutando " + Chr(10) + Chr(13)+ ;
  4152.                 "en el equipo al cual se encuentra conectado el Controlador Fiscal")
  4153.             This.LeerSpooler("T")
  4154.         Endif
  4155.         If intentos = 70
  4156.             Messagebox("ATENCION: Tiempo de Espera Agotado !!! Presione ESC. para cancelar este Comprobante")
  4157.             This.LeerSpooler("T")
  4158.         Endif
  4159.         intentos = intentos + 1
  4160. *For i=1 To 100
  4161. *Next
  4162.         Inkey(1)
  4163.         If Lastkey() = 27
  4164.             If Substr(comando.comando,17,16) = "Impresor Ocupado"
  4165.                 Messagebox("ATENCION: No se aconseja cancelar este documento por programa, "+;
  4166.                     CHR(10)+Chr(13)+"La impresora ya lo ha procesado y saldrá impreso"+;
  4167.                     CHR(10)+Chr(13)+ "una vez que esta se ponga en linea")
  4168.             Endif
  4169.             If Messagebox("ATENCION: Realmente desea Cancelar la Emisión de este Documento??",4+256) = 6
  4170.                 Messagebox(" Se proceder  a Cancelar el Documento por Sistema"+;
  4171.                     CHR(10)+Chr(13)+" Verifique que la impresora también lo haya Cancelado.")
  4172.                 Keyboard '{ESC}'
  4173.             Else
  4174.                 Keyboard ""
  4175.             Endif
  4176.         Endif
  4177.     Enddo
  4178.     If Lastkey() = 27.Or. fd < 0
  4179.         If File(mtXt)
  4180.             Erase &mtXt
  4181.         Endif
  4182.         fd = Fopen((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"), 0)
  4183.         If fd < 0
  4184.             Messagebox("Operación Cancelada: ERROR de comunicaciones con el Controlador.; Probablemente no se este ejecutando Spooler. ")
  4185.         Else
  4186.             fd =Fclose(fd)
  4187.             This.LeerSpooler("T")
  4188.         Endif
  4189.     Else
  4190.         fd = Fclose(fd)
  4191.         Select("comando")
  4192.         Zap
  4193.         Append From &maNs Sdf
  4194.         Goto Bottom
  4195.         This.numero = Val(Substr(comando.comando,35,8))
  4196.         If This.numero <> 0
  4197.             SQLExec(goApp.nCon, "select * from puntero where sucursal=?param.sucursal","puntero")
  4198.             If This.Ticket = "S"
  4199.                 If This.MasDeMil
  4200.                     This.numero = Val('0009'+strzero(This.numero,8))
  4201.                 Else
  4202.                     If lImpreFiscal
  4203.                         This.numero = Val(impfis.PtoVtaTicket+strzero(This.numero,8))
  4204.                     Else
  4205.                         If Param.sucursal=0
  4206.                             If File("c:\0009.txt")
  4207.                                 This.numero = Val(strzero(9,4)+strzero(This.numero,8))
  4208.                             Else
  4209.                                 This.numero = Val(strzero(puntero.pvta_tic,4)+strzero(This.numero,8))
  4210.                             Endif
  4211.                         Else
  4212.                             If Param.sucursal = 1
  4213.                                 This.numero = Val(strzero(8,4)+strzero(This.numero,8))
  4214.                             Endif
  4215.                         Endif
  4216.                     Endif
  4217.                 Endif
  4218.             Else
  4219.                 If lImpreFiscal
  4220.                     This.numero = Val(impfis.PtoVtaFac+strzero(This.numero,8))
  4221.                 Else
  4222.                     This.numero = Val(strzero(puntero.pvta_fac,4)+strzero(This.numero,8))
  4223.                 Endif
  4224.             Endif
  4225.             This.TodoOK = .T.
  4226.         Endif
  4227.     Endif
  4228.     If File((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"))
  4229.         Erase Alltrim(paramfac.dirpa)+"SPOOLER.LOG"
  4230.     Endif
  4231. Endif
  4232. *This.killprocessbyname("impred.exe")
  4233. *This.killprocessbyname("wspooler.exe")
  4234.  
  4235. Set Talk &cTalk
  4236. Return This.Todo
  4237. *!* Pongo esto para que en esta condicion no me sume los dias de ADIC2
  4238.                 Insert Into comando;
  4239.                     VALUES ("]" + Se + lin + Se +  ;
  4240.                     "OPCION DE PAGO: Hasta el "+ ;
  4241.                     DTOC(pagos.dia)+"  "+;
  4242.                     STR(pagos.adic2)+" % Desc. $ "+;
  4243.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  4244.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  4245.             Else
  4246.                 Insert Into comando;
  4247.                     VALUES ("]" + Se + lin + Se +  ;
  4248.                     "OPCION DE PAGO: Hasta el "+ ;
  4249.                     DTOC(This.FechaVen(Thisform.txtFecha.Value))+"  "+;
  4250.                     STR(pagos.adic2)+" % Desc. $ "+;
  4251.                     STR(m.nTOTAL*pagos.adic2/100,08,2)+;
  4252.                     " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic2)/100),10,2))
  4253.             Endif
  4254.         Endif
  4255.     Else
  4256.         Insert Into comando;
  4257.             VALUES ( "]" + Se + lin + Se + Chr(127) )
  4258.     Endif
  4259.  
  4260.     lin = Str(Val(lin)+1,2,0)
  4261.  
  4262.     If pagos.adic3 > 0 .Or. pagos.plazo3 >0
  4263.         If Isnull(pagos.dia) Or Empty(pagos.dia)
  4264.             Insert Into comando;
  4265.                 VALUES ("]" + Se + lin + Se + ;
  4266.                 "OPCION DE PAGO: Hasta el "+ ;
  4267.                 DTOC(Thisform.txtFecha.Value+Cast(pagos.dias1 As Integer))+"  "+;
  4268.                 STR(pagos.adic3)+" % Desc. $ "+;
  4269.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  4270.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  4271.         Else
  4272.             Insert Into comando;
  4273.                 VALUES ("]" + Se + lin + Se + ;
  4274.                 "OPCION DE PAGO: Hasta el "+ ;
  4275.                 DTOC(pagos.dia+Cast(pagos.dias1 As Integer))+"  "+;
  4276.                 STR(pagos.adic3)+" % Desc. $ "+;
  4277.                 STR(m.nTOTAL*pagos.adic3/100,08,2)+;
  4278.                 " Paga $ "+Str((m.nTOTAL-(m.nTOTAL*pagos.adic3/100)),10,2))
  4279.         Endif
  4280.     Else
  4281.         Insert Into comando;
  4282.             VALUES ("]" + Se + lin + Se + Chr(127))
  4283.     Endif
  4284.  
  4285.     lin = Str(Val(lin)+1,2,0)
  4286. *!*     Insert Into comando;
  4287. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  4288.     If m.nFlete > 0 Or m.nDRet > 0
  4289.         If m.nFlete > 0
  4290.             Insert Into comando;
  4291.                 VALUES ("]" + Se + lin + Se + ;
  4292.                 "Prec. de Merc. Incl. Flete "+ ;
  4293.                 Transform(m.nFlete, "@$ 99,999,999.99"))
  4294.         Else
  4295.             Insert Into comando;
  4296.                 VALUES ("]" + Se + lin + Se + ;
  4297.                 "Merc. Incl. Desc p/RETIRA "+ ;
  4298.                 Transform(m.nDRet, "@$ 99,999,999.99"))
  4299.         Endif
  4300.     Else
  4301.         Insert Into comando;
  4302.             VALUES ("]" + Se + lin + Se + Chr(127))
  4303.     Endif
  4304.  
  4305. &&si se factura sobre remitos se imprimen los remitos afectados
  4306.     If Thisform.viene = "X" &&hay q revisar esto para ver q cuando se factura de remitos se imprima
  4307.         Insert Into comando;
  4308.             VALUES ( Chr(147) + Se + "1" + Se + Substr(This.remitosafacturar,1,17))
  4309.         If !Empty(Substr(This.remitosafacturar,19,20))
  4310.             Insert Into comando;
  4311.                 VALUES (Chr(147) + Se + "2" + Se + Substr(This.remitosafacturar,19,20))
  4312.         Endif
  4313.     Endif
  4314. Else
  4315.     If This.contado = 'N'
  4316.         Insert Into comando;
  4317.             values("]" + Se + lin + Se+;
  4318.             " Saldo de CTA_CTE: $"+;
  4319.             ALLTRIM(Str((m.salctacte),12,2)))
  4320.         lin = '6'
  4321.     Else
  4322.         Insert Into comando;
  4323.             values("]" + Se + lin + Se + Chr(127))
  4324.         lin = '6'
  4325.     Endif
  4326.  
  4327.     Insert Into comando;
  4328.         VALUES ( "]" + Se + lin + Se + "Vendedor: "+Alltrim(goApp.User) )
  4329.  
  4330.     lin = '7'
  4331.     Insert Into comando;
  4332.         VALUES ("]" + Se + lin + Se + Chr(127))
  4333.  
  4334.     lin = '8'
  4335.     Insert Into comando;
  4336.         VALUES ("]" + Se + lin + Se + Chr(127))
  4337.  
  4338.     lin = '11'
  4339. *!*     Insert Into comando;
  4340. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  4341.     Insert Into comando;
  4342.         VALUES ("]" + Se + lin + Se + Chr(127))
  4343. Endif
  4344.  
  4345. If This.Ticket="S"
  4346.     Insert Into comando;
  4347.         VALUES ( "]" + Se + "9" + Se +Chr(127))
  4348.     Insert Into comando;
  4349.         VALUES ("]" + Se + "10" + Se +Chr(127))
  4350.     If This.condicion = 'C' And Val(sCliente) = 1
  4351.         Insert Into comando;
  4352.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  4353.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  4354.             " S/NOMBRE")
  4355.     Else
  4356.         Insert Into comando;
  4357.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  4358.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  4359.             SUBSTR(Alltrim(thisformset.frmCliente.txtDomicilio.Value)+" "+Alltrim(loc.nombre)+;
  4360.             " "+Alltrim(loc.provincia),1,40))
  4361.     Endif
  4362.  
  4363. Else
  4364. &&"["+sCliente+"] "+
  4365.     Insert Into comando;
  4366.         VALUES ( "b" + Se + "[" + sCliente + "] " + Substr(sNombre,1,40) + Se +;
  4367.         ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se + ;
  4368.         ALLTRIM(Thisform.txtDom.Value)+" ("+Alltrim(clientes.codpos)+") "+;
  4369.         Alltrim(loc.nombre)+" "+Alltrim(loc.provincia))
  4370. Endif
  4371. If This.condicion <> "C"
  4372.     Insert Into comando;
  4373.         VALUES (Chr(64)+Se+TIPO_FACTURA+Se+"T")
  4374. Else
  4375. &&Definir tipo y num de factura afectado por nota de credito
  4376.     Insert Into comando;
  4377.         VALUES (Chr(147) + Se + "1" + Se + cre.tipoaf + " " + cre.numeroaf)
  4378.     Insert Into comando;
  4379.         VALUES (Chr(128)+Se+TIPO_FACTURA+Se+"T")
  4380. Endif
  4381.  
  4382. &&el cursor "DET" posee los items a facturar
  4383. Select("det")
  4384. Go Top
  4385. Do While ! Eof()
  4386. *!* Create Cursor det;
  4387. *!*     (cantidad n(12,4), unidad c(8), detalle c(40), total n(12,2), idArticulo int,;
  4388. *!*     unitario n(12,2), costo n(12,2), montoiva n(12,2), montodgr n(12,2), montomuni N(12,2),;
  4389. *!*     poriva n(12,2), tipoiva c(2))  
  4390.     If det.unitario != 0
  4391.         If This.clase = "A"
  4392.             If This.Ticket = "S"
  4393.                 Insert Into comando;
  4394.                     VALUES ("A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  4395.                 Insert Into comando;
  4396.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + Se +;
  4397.                     ALLTRIM(Str(det.cantidad,6,2)+"0")+ Se +;
  4398.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  4399.                     ALLTRIM(Str(det.poriva,5,2)) + Se +;
  4400.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  4401.             Else
  4402.                 Insert Into comando;
  4403.                     VALUES ("B" + Se + det.unidad +" "+det.detalle+ Se + ;
  4404.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  4405.                     Alltrim(Str(det.unitario,13,2)) + ;
  4406.                     Se +Alltrim(Str(det.poriva,5,2)) + Se + ;
  4407.                     "M" + Se + "0" + Se + "" + Se + "T")
  4408.  
  4409.             Endif
  4410.         Else
  4411.             If This.Ticket = "S"
  4412.                 Insert Into comando;
  4413.                     VALUES ( "A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  4414.                 Insert Into comando;
  4415.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + ;
  4416.                     Se +Alltrim(Str(det.cantidad,6,2)+"0")+ Se + ;
  4417.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  4418.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  4419.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  4420.             Else
  4421.                 Insert Into comando;
  4422.                     VALUES ("B" + Se + det.unidad+" "+det.detalle+ Se +;
  4423.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  4424.                     ALLTRIM(Str(det.unitario,13,2)) + Se +;
  4425.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  4426.                     "M" + Se + "0" + Se + "" + Se + "T")
  4427.             Endif
  4428.         Endif
  4429.     Endif
  4430.     Select("det")
  4431.     Skip
  4432. Enddo
  4433.  
  4434.  
  4435. If This.condicion <> "C"
  4436.     If This.Ticket = "S"
  4437.         If This.contado = "S"
  4438.             Insert Into comando;
  4439.                 VALUES (Chr(68)+ Se + Substr(formapago.detalle,1,30)+ Se + ;
  4440.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  4441.         Else
  4442.             Insert Into comando;
  4443.                 VALUES ( Chr(68)+ Se + Substr(formapago.detalle,1,30)+ ;
  4444.                 Se + Alltrim(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  4445.         Endif
  4446.     Else
  4447.         If This.contado = "S"
  4448.             Insert Into comando;
  4449.                 VALUES (Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  4450.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  4451.         Else
  4452.             Insert Into comando;
  4453.                 VALUES(Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  4454.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  4455.         Endif
  4456.     Endif
  4457. Endif
  4458.  
  4459. If This.condicion <> "C"
  4460.     Insert Into comando;
  4461.         VALUES (Chr(69))
  4462. Else
  4463.     Insert Into comando;
  4464.         VALUES ( Chr(129) )
  4465. Endif
  4466.  
  4467.  
  4468. &&en esta parte copio el archivo con los comandos a la carpeta desde el cual
  4469. &&el spooler de impresion lee el archivo
  4470. If This.Ticket ="S"
  4471. && si es ticket me fijo a cual impresora debo enviar
  4472.     If lImpreFiscal
  4473.         mtXt = Alltrim(impfis.dircoticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  4474.         maNs = Alltrim(impfis.dirreticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  4475.     Else
  4476.         mtXt = Alltrim(parametr.dirco)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  4477.         maNs = Alltrim(parametr.dirre)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  4478.     Endif
  4479. *!*     cDirCom = "fpserver715" + "\impred.exe"
  4480. *!*     cDirCom = Fullpath(cDirCom)
  4481. *!* && Mato el proceso del spooler y lo vuelvo a cargar
  4482. *!*     This.killprocessbyname("impred.exe")
  4483. *!*     This.killprocessbyname("wspooler.exe")
  4484. *!*     oShell = Createobject("Shell.Application")
  4485. *!*     oShell.ShellExecute (cDirCom)
  4486. Else
  4487. &&aca envio a la 320
  4488.     If lImpreFiscal
  4489.         mtXt = Alltrim(impfis.dircofactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  4490.         maNs = Alltrim(impfis.dirrefactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  4491.     Else
  4492.         mtXt = Alltrim(parametr.dirco)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  4493.         maNs = Alltrim(parametr.dirre)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  4494.     Endif
  4495. Endif
  4496.  
  4497.  
  4498. Select("comando")
  4499. Goto Top
  4500. &&en caso de que tenga un archivo en la cola de impresion de la impresora
  4501. &&no se deja imprimir
  4502. *Browse
  4503. If File(mtXt)
  4504.     Messagebox("ATENCION: Ud. ya tiene un Documento en Cola de Impresión"+Chr(10)+Chr(13)+;
  4505.         " AGUARDE a que el mismo sea impreso o elimínelo luego vuelva a intentar")
  4506.     Return This.TodoOK
  4507. Else
  4508.     Copy To &mtXt Sdf
  4509.     If File(maNs)
  4510.         Erase &maNs
  4511.     Endif
  4512.     If File(Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  4513.         Erase (Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  4514.     Endif
  4515.     Wait Windows 'Esperando Respuesta del Controlador Fiscal...' Nowait
  4516.     fd = -1
  4517.     intentos =1
  4518.     Do While fd < 0 .And. Lastkey() != 27
  4519.         fd = Fopen(maNs, 0)
  4520.         This.LeerSpooler("T")
  4521.         If intentos = 30
  4522.             Messagebox("ATENCION: Verifique que el Controlador Esté Conectado y Encendido. " + Chr(10) + Chr(13)+ ;
  4523.                 "Verifique además que el Programa Spooler se esté ejecutando " + Chr(10) + Chr(13)+ ;
  4524.                 "en el equipo al cual se encuentra conectado el Controlador Fiscal")
  4525.             This.LeerSpooler("T")
  4526.         Endif
  4527.         If intentos = 70
  4528.             Messagebox("ATENCION: Tiempo de Espera Agotado !!! Presione ESC. para cancelar este Comprobante")
  4529.             This.LeerSpooler("T")
  4530.         Endif
  4531.         intentos = intentos + 1
  4532. *For i=1 To 100
  4533. *Next
  4534.         Inkey(1)
  4535.         If Lastkey() = 27
  4536.             If Substr(comando.comando,17,16) = "Impresor Ocupado"
  4537.                 Messagebox("ATENCION: No se aconseja cancelar este documento por programa, "+;
  4538.                     CHR(10)+Chr(13)+"La impresora ya lo ha procesado y saldrá impreso"+;
  4539.                     CHR(10)+Chr(13)+ "una vez que esta se ponga en linea")
  4540.             Endif
  4541.             If Messagebox("ATENCION: Realmente desea Cancelar la Emisión de este Documento??",4+256) = 6
  4542.                 Messagebox(" Se proceder  a Cancelar el Documento por Sistema"+;
  4543.                     CHR(10)+Chr(13)+" Verifique que la impresora también lo haya Cancelado.")
  4544.                 Keyboard '{ESC}'
  4545.             Else
  4546.                 Keyboard ""
  4547.             Endif
  4548.         Endif
  4549.     Enddo
  4550.     If Lastkey() = 27.Or. fd < 0
  4551.         If File(mtXt)
  4552.             Erase &mtXt
  4553.         Endif
  4554.         fd = Fopen((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"), 0)
  4555.         If fd < 0
  4556.             Messagebox("Operación Cancelada: ERROR de comunicaciones con el Controlador.; Probablemente no se este ejecutando Spooler. ")
  4557.         Else
  4558.             fd =Fclose(fd)
  4559.             This.LeerSpooler("T")
  4560.         Endif
  4561.     Else
  4562.         fd = Fclose(fd)
  4563.         Select("comando")
  4564.         Zap
  4565.         Append From &maNs Sdf
  4566.         Goto Bottom
  4567.         This.numero = Val(Substr(comando.comando,35,8))
  4568.         If This.numero <> 0
  4569.             SQLExec(goApp.nCon, "select * from puntero where sucursal=?param.sucursal","puntero")
  4570.             If This.Ticket = "S"
  4571.                 If This.MasDeMil
  4572.                     This.numero = Val('0009'+strzero(This.numero,8))
  4573.                 Else
  4574.                     If lImpreFiscal
  4575.                         This.numero = Val(impfis.PtoVtaTicket+strzero(This.numero,8))
  4576.                     Else
  4577.                         If Param.sucursal=0
  4578.                             If File("c:\0009.txt")
  4579.                                 This.numero = Val(strzero(9,4)+strzero(This.numero,8))
  4580.                             Else
  4581.                                 This.numero = Val(strzero(puntero.pvta_tic,4)+strzero(This.numero,8))
  4582.                             Endif
  4583.                         Else
  4584.                             If Param.sucursal = 1
  4585.                                 This.numero = Val(strzero(8,4)+strzero(This.numero,8))
  4586.                             Endif
  4587.                         Endif
  4588.                     Endif
  4589.                 Endif
  4590.             Else
  4591.                 If lImpreFiscal
  4592.                     This.numero = Val(impfis.PtoVtaFac+strzero(This.numero,8))
  4593.                 Else
  4594.                     This.numero = Val(strzero(puntero.pvta_fac,4)+strzero(This.numero,8))
  4595.                 Endif
  4596.             Endif
  4597.             This.TodoOK = .T.
  4598.         Endif
  4599.     Endif
  4600.     If File((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"))
  4601.         Erase Alltrim(paramfac.dirpa)+"SPOOLER.LOG"
  4602.     Endif
  4603. Endif
  4604. *This.killprocessbyname("impred.exe")
  4605. *This.killprocessbyname("wspooler.exe")
  4606.  
  4607. Set Talk &cTalk
  4608. Return This.Todo
  4609. *!*     Insert Into comando;
  4610. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  4611.     If m.nFlete > 0 Or m.nDRet > 0
  4612.         If m.nFlete > 0
  4613.             Insert Into comando;
  4614.                 VALUES ("]" + Se + lin + Se + ;
  4615.                 "Prec. de Merc. Incl. Flete "+ ;
  4616.                 Transform(m.nFlete, "@$ 99,999,999.99"))
  4617.         Else
  4618.             Insert Into comando;
  4619.                 VALUES ("]" + Se + lin + Se + ;
  4620.                 "Merc. Incl. Desc p/RETIRA "+ ;
  4621.                 Transform(m.nDRet, "@$ 99,999,999.99"))
  4622.         Endif
  4623.     Else
  4624.         Insert Into comando;
  4625.             VALUES ("]" + Se + lin + Se + Chr(127))
  4626.     Endif
  4627.  
  4628. &&si se factura sobre remitos se imprimen los remitos afectados
  4629.     If Thisform.viene = "X" &&hay q revisar esto para ver q cuando se factura de remitos se imprima
  4630.         Insert Into comando;
  4631.             VALUES ( Chr(147) + Se + "1" + Se + Substr(This.remitosafacturar,1,17))
  4632.         If !Empty(Substr(This.remitosafacturar,19,20))
  4633.             Insert Into comando;
  4634.                 VALUES (Chr(147) + Se + "2" + Se + Substr(This.remitosafacturar,19,20))
  4635.         Endif
  4636.     Endif
  4637. Else
  4638.     If This.contado = 'N'
  4639.         Insert Into comando;
  4640.             values("]" + Se + lin + Se+;
  4641.             " Saldo de CTA_CTE: $"+;
  4642.             ALLTRIM(Str((m.salctacte),12,2)))
  4643.         lin = '6'
  4644.     Else
  4645.         Insert Into comando;
  4646.             values("]" + Se + lin + Se + Chr(127))
  4647.         lin = '6'
  4648.     Endif
  4649.  
  4650.     Insert Into comando;
  4651.         VALUES ( "]" + Se + lin + Se + "Vendedor: "+Alltrim(goApp.User) )
  4652.  
  4653.     lin = '7'
  4654.     Insert Into comando;
  4655.         VALUES ("]" + Se + lin + Se + Chr(127))
  4656.  
  4657.     lin = '8'
  4658.     Insert Into comando;
  4659.         VALUES ("]" + Se + lin + Se + Chr(127))
  4660.  
  4661.     lin = '11'
  4662. *!*     Insert Into comando;
  4663. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  4664.     Insert Into comando;
  4665.         VALUES ("]" + Se + lin + Se + Chr(127))
  4666. Endif
  4667.  
  4668. If This.Ticket="S"
  4669.     Insert Into comando;
  4670.         VALUES ( "]" + Se + "9" + Se +Chr(127))
  4671.     Insert Into comando;
  4672.         VALUES ("]" + Se + "10" + Se +Chr(127))
  4673.     If This.condicion = 'C' And Val(sCliente) = 1
  4674.         Insert Into comando;
  4675.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  4676.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  4677.             " S/NOMBRE")
  4678.     Else
  4679.         Insert Into comando;
  4680.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  4681.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  4682.             SUBSTR(Alltrim(thisformset.frmCliente.txtDomicilio.Value)+" "+Alltrim(loc.nombre)+;
  4683.             " "+Alltrim(loc.provincia),1,40))
  4684.     Endif
  4685.  
  4686. Else
  4687. &&"["+sCliente+"] "+
  4688.     Insert Into comando;
  4689.         VALUES ( "b" + Se + "[" + sCliente + "] " + Substr(sNombre,1,40) + Se +;
  4690.         ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se + ;
  4691.         ALLTRIM(Thisform.txtDom.Value)+" ("+Alltrim(clientes.codpos)+") "+;
  4692.         Alltrim(loc.nombre)+" "+Alltrim(loc.provincia))
  4693. Endif
  4694. If This.condicion <> "C"
  4695.     Insert Into comando;
  4696.         VALUES (Chr(64)+Se+TIPO_FACTURA+Se+"T")
  4697. Else
  4698. &&Definir tipo y num de factura afectado por nota de credito
  4699.     Insert Into comando;
  4700.         VALUES (Chr(147) + Se + "1" + Se + cre.tipoaf + " " + cre.numeroaf)
  4701.     Insert Into comando;
  4702.         VALUES (Chr(128)+Se+TIPO_FACTURA+Se+"T")
  4703. Endif
  4704.  
  4705. &&el cursor "DET" posee los items a facturar
  4706. Select("det")
  4707. Go Top
  4708. Do While ! Eof()
  4709. *!* Create Cursor det;
  4710. *!*     (cantidad n(12,4), unidad c(8), detalle c(40), total n(12,2), idArticulo int,;
  4711. *!*     unitario n(12,2), costo n(12,2), montoiva n(12,2), montodgr n(12,2), montomuni N(12,2),;
  4712. *!*     poriva n(12,2), tipoiva c(2))  
  4713.     If det.unitario != 0
  4714.         If This.clase = "A"
  4715.             If This.Ticket = "S"
  4716.                 Insert Into comando;
  4717.                     VALUES ("A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  4718.                 Insert Into comando;
  4719.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + Se +;
  4720.                     ALLTRIM(Str(det.cantidad,6,2)+"0")+ Se +;
  4721.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  4722.                     ALLTRIM(Str(det.poriva,5,2)) + Se +;
  4723.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  4724.             Else
  4725.                 Insert Into comando;
  4726.                     VALUES ("B" + Se + det.unidad +" "+det.detalle+ Se + ;
  4727.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  4728.                     Alltrim(Str(det.unitario,13,2)) + ;
  4729.                     Se +Alltrim(Str(det.poriva,5,2)) + Se + ;
  4730.                     "M" + Se + "0" + Se + "" + Se + "T")
  4731.  
  4732.             Endif
  4733.         Else
  4734.             If This.Ticket = "S"
  4735.                 Insert Into comando;
  4736.                     VALUES ( "A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  4737.                 Insert Into comando;
  4738.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + ;
  4739.                     Se +Alltrim(Str(det.cantidad,6,2)+"0")+ Se + ;
  4740.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  4741.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  4742.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  4743.             Else
  4744.                 Insert Into comando;
  4745.                     VALUES ("B" + Se + det.unidad+" "+det.detalle+ Se +;
  4746.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  4747.                     ALLTRIM(Str(det.unitario,13,2)) + Se +;
  4748.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  4749.                     "M" + Se + "0" + Se + "" + Se + "T")
  4750.             Endif
  4751.         Endif
  4752.     Endif
  4753.     Select("det")
  4754.     Skip
  4755. Enddo
  4756.  
  4757.  
  4758. If This.condicion <> "C"
  4759.     If This.Ticket = "S"
  4760.         If This.contado = "S"
  4761.             Insert Into comando;
  4762.                 VALUES (Chr(68)+ Se + Substr(formapago.detalle,1,30)+ Se + ;
  4763.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  4764.         Else
  4765.             Insert Into comando;
  4766.                 VALUES ( Chr(68)+ Se + Substr(formapago.detalle,1,30)+ ;
  4767.                 Se + Alltrim(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  4768.         Endif
  4769.     Else
  4770.         If This.contado = "S"
  4771.             Insert Into comando;
  4772.                 VALUES (Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  4773.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  4774.         Else
  4775.             Insert Into comando;
  4776.                 VALUES(Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  4777.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  4778.         Endif
  4779.     Endif
  4780. Endif
  4781.  
  4782. If This.condicion <> "C"
  4783.     Insert Into comando;
  4784.         VALUES (Chr(69))
  4785. Else
  4786.     Insert Into comando;
  4787.         VALUES ( Chr(129) )
  4788. Endif
  4789.  
  4790.  
  4791. &&en esta parte copio el archivo con los comandos a la carpeta desde el cual
  4792. &&el spooler de impresion lee el archivo
  4793. If This.Ticket ="S"
  4794. && si es ticket me fijo a cual impresora debo enviar
  4795.     If lImpreFiscal
  4796.         mtXt = Alltrim(impfis.dircoticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  4797.         maNs = Alltrim(impfis.dirreticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  4798.     Else
  4799.         mtXt = Alltrim(parametr.dirco)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  4800.         maNs = Alltrim(parametr.dirre)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  4801.     Endif
  4802. *!*     cDirCom = "fpserver715" + "\impred.exe"
  4803. *!*     cDirCom = Fullpath(cDirCom)
  4804. *!* && Mato el proceso del spooler y lo vuelvo a cargar
  4805. *!*     This.killprocessbyname("impred.exe")
  4806. *!*     This.killprocessbyname("wspooler.exe")
  4807. *!*     oShell = Createobject("Shell.Application")
  4808. *!*     oShell.ShellExecute (cDirCom)
  4809. Else
  4810. &&aca envio a la 320
  4811.     If lImpreFiscal
  4812.         mtXt = Alltrim(impfis.dircofactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  4813.         maNs = Alltrim(impfis.dirrefactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  4814.     Else
  4815.         mtXt = Alltrim(parametr.dirco)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  4816.         maNs = Alltrim(parametr.dirre)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  4817.     Endif
  4818. Endif
  4819.  
  4820.  
  4821. Select("comando")
  4822. Goto Top
  4823. &&en caso de que tenga un archivo en la cola de impresion de la impresora
  4824. &&no se deja imprimir
  4825. *Browse
  4826. If File(mtXt)
  4827.     Messagebox("ATENCION: Ud. ya tiene un Documento en Cola de Impresión"+Chr(10)+Chr(13)+;
  4828.         " AGUARDE a que el mismo sea impreso o elimínelo luego vuelva a intentar")
  4829.     Return This.TodoOK
  4830. Else
  4831.     Copy To &mtXt Sdf
  4832.     If File(maNs)
  4833.         Erase &maNs
  4834.     Endif
  4835.     If File(Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  4836.         Erase (Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  4837.     Endif
  4838.     Wait Windows 'Esperando Respuesta del Controlador Fiscal...' Nowait
  4839.     fd = -1
  4840.     intentos =1
  4841.     Do While fd < 0 .And. Lastkey() != 27
  4842.         fd = Fopen(maNs, 0)
  4843.         This.LeerSpooler("T")
  4844.         If intentos = 30
  4845.             Messagebox("ATENCION: Verifique que el Controlador Esté Conectado y Encendido. " + Chr(10) + Chr(13)+ ;
  4846.                 "Verifique además que el Programa Spooler se esté ejecutando " + Chr(10) + Chr(13)+ ;
  4847.                 "en el equipo al cual se encuentra conectado el Controlador Fiscal")
  4848.             This.LeerSpooler("T")
  4849.         Endif
  4850.         If intentos = 70
  4851.             Messagebox("ATENCION: Tiempo de Espera Agotado !!! Presione ESC. para cancelar este Comprobante")
  4852.             This.LeerSpooler("T")
  4853.         Endif
  4854.         intentos = intentos + 1
  4855. *For i=1 To 100
  4856. *Next
  4857.         Inkey(1)
  4858.         If Lastkey() = 27
  4859.             If Substr(comando.comando,17,16) = "Impresor Ocupado"
  4860.                 Messagebox("ATENCION: No se aconseja cancelar este documento por programa, "+;
  4861.                     CHR(10)+Chr(13)+"La impresora ya lo ha procesado y saldrá impreso"+;
  4862.                     CHR(10)+Chr(13)+ "una vez que esta se ponga en linea")
  4863.             Endif
  4864.             If Messagebox("ATENCION: Realmente desea Cancelar la Emisión de este Documento??",4+256) = 6
  4865.                 Messagebox(" Se proceder  a Cancelar el Documento por Sistema"+;
  4866.                     CHR(10)+Chr(13)+" Verifique que la impresora también lo haya Cancelado.")
  4867.                 Keyboard '{ESC}'
  4868.             Else
  4869.                 Keyboard ""
  4870.             Endif
  4871.         Endif
  4872.     Enddo
  4873.     If Lastkey() = 27.Or. fd < 0
  4874.         If File(mtXt)
  4875.             Erase &mtXt
  4876.         Endif
  4877.         fd = Fopen((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"), 0)
  4878.         If fd < 0
  4879.             Messagebox("Operación Cancelada: ERROR de comunicaciones con el Controlador.; Probablemente no se este ejecutando Spooler. ")
  4880.         Else
  4881.             fd =Fclose(fd)
  4882.             This.LeerSpooler("T")
  4883.         Endif
  4884.     Else
  4885.         fd = Fclose(fd)
  4886.         Select("comando")
  4887.         Zap
  4888.         Append From &maNs Sdf
  4889.         Goto Bottom
  4890.         This.numero = Val(Substr(comando.comando,35,8))
  4891.         If This.numero <> 0
  4892.             SQLExec(goApp.nCon, "select * from puntero where sucursal=?param.sucursal","puntero")
  4893.             If This.Ticket = "S"
  4894.                 If This.MasDeMil
  4895.                     This.numero = Val('0009'+strzero(This.numero,8))
  4896.                 Else
  4897.                     If lImpreFiscal
  4898.                         This.numero = Val(impfis.PtoVtaTicket+strzero(This.numero,8))
  4899.                     Else
  4900.                         If Param.sucursal=0
  4901.                             If File("c:\0009.txt")
  4902.                                 This.numero = Val(strzero(9,4)+strzero(This.numero,8))
  4903.                             Else
  4904.                                 This.numero = Val(strzero(puntero.pvta_tic,4)+strzero(This.numero,8))
  4905.                             Endif
  4906.                         Else
  4907.                             If Param.sucursal = 1
  4908.                                 This.numero = Val(strzero(8,4)+strzero(This.numero,8))
  4909.                             Endif
  4910.                         Endif
  4911.                     Endif
  4912.                 Endif
  4913.             Else
  4914.                 If lImpreFiscal
  4915.                     This.numero = Val(impfis.PtoVtaFac+strzero(This.numero,8))
  4916.                 Else
  4917.                     This.numero = Val(strzero(puntero.pvta_fac,4)+strzero(This.numero,8))
  4918.                 Endif
  4919.             Endif
  4920.             This.TodoOK = .T.
  4921.         Endif
  4922.     Endif
  4923.     If File((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"))
  4924.         Erase Alltrim(paramfac.dirpa)+"SPOOLER.LOG"
  4925.     Endif
  4926. Endif
  4927. *This.killprocessbyname("impred.exe")
  4928. *This.killprocessbyname("wspooler.exe")
  4929.  
  4930. Set Talk &cTalk
  4931. Return This.Todo
  4932. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  4933.     If m.nFlete > 0 Or m.nDRet > 0
  4934.         If m.nFlete > 0
  4935.             Insert Into comando;
  4936.                 VALUES ("]" + Se + lin + Se + ;
  4937.                 "Prec. de Merc. Incl. Flete "+ ;
  4938.                 Transform(m.nFlete, "@$ 99,999,999.99"))
  4939.         Else
  4940.             Insert Into comando;
  4941.                 VALUES ("]" + Se + lin + Se + ;
  4942.                 "Merc. Incl. Desc p/RETIRA "+ ;
  4943.                 Transform(m.nDRet, "@$ 99,999,999.99"))
  4944.         Endif
  4945.     Else
  4946.         Insert Into comando;
  4947.             VALUES ("]" + Se + lin + Se + Chr(127))
  4948.     Endif
  4949.  
  4950. &&si se factura sobre remitos se imprimen los remitos afectados
  4951.     If Thisform.viene = "X" &&hay q revisar esto para ver q cuando se factura de remitos se imprima
  4952.         Insert Into comando;
  4953.             VALUES ( Chr(147) + Se + "1" + Se + Substr(This.remitosafacturar,1,17))
  4954.         If !Empty(Substr(This.remitosafacturar,19,20))
  4955.             Insert Into comando;
  4956.                 VALUES (Chr(147) + Se + "2" + Se + Substr(This.remitosafacturar,19,20))
  4957.         Endif
  4958.     Endif
  4959. Else
  4960.     If This.contado = 'N'
  4961.         Insert Into comando;
  4962.             values("]" + Se + lin + Se+;
  4963.             " Saldo de CTA_CTE: $"+;
  4964.             ALLTRIM(Str((m.salctacte),12,2)))
  4965.         lin = '6'
  4966.     Else
  4967.         Insert Into comando;
  4968.             values("]" + Se + lin + Se + Chr(127))
  4969.         lin = '6'
  4970.     Endif
  4971.  
  4972.     Insert Into comando;
  4973.         VALUES ( "]" + Se + lin + Se + "Vendedor: "+Alltrim(goApp.User) )
  4974.  
  4975.     lin = '7'
  4976.     Insert Into comando;
  4977.         VALUES ("]" + Se + lin + Se + Chr(127))
  4978.  
  4979.     lin = '8'
  4980.     Insert Into comando;
  4981.         VALUES ("]" + Se + lin + Se + Chr(127))
  4982.  
  4983.     lin = '11'
  4984. *!*     Insert Into comando;
  4985. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  4986.     Insert Into comando;
  4987.         VALUES ("]" + Se + lin + Se + Chr(127))
  4988. Endif
  4989.  
  4990. If This.Ticket="S"
  4991.     Insert Into comando;
  4992.         VALUES ( "]" + Se + "9" + Se +Chr(127))
  4993.     Insert Into comando;
  4994.         VALUES ("]" + Se + "10" + Se +Chr(127))
  4995.     If This.condicion = 'C' And Val(sCliente) = 1
  4996.         Insert Into comando;
  4997.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  4998.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  4999.             " S/NOMBRE")
  5000.     Else
  5001.         Insert Into comando;
  5002.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  5003.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  5004.             SUBSTR(Alltrim(thisformset.frmCliente.txtDomicilio.Value)+" "+Alltrim(loc.nombre)+;
  5005.             " "+Alltrim(loc.provincia),1,40))
  5006.     Endif
  5007.  
  5008. Else
  5009. &&"["+sCliente+"] "+
  5010.     Insert Into comando;
  5011.         VALUES ( "b" + Se + "[" + sCliente + "] " + Substr(sNombre,1,40) + Se +;
  5012.         ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se + ;
  5013.         ALLTRIM(Thisform.txtDom.Value)+" ("+Alltrim(clientes.codpos)+") "+;
  5014.         Alltrim(loc.nombre)+" "+Alltrim(loc.provincia))
  5015. Endif
  5016. If This.condicion <> "C"
  5017.     Insert Into comando;
  5018.         VALUES (Chr(64)+Se+TIPO_FACTURA+Se+"T")
  5019. Else
  5020. &&Definir tipo y num de factura afectado por nota de credito
  5021.     Insert Into comando;
  5022.         VALUES (Chr(147) + Se + "1" + Se + cre.tipoaf + " " + cre.numeroaf)
  5023.     Insert Into comando;
  5024.         VALUES (Chr(128)+Se+TIPO_FACTURA+Se+"T")
  5025. Endif
  5026.  
  5027. &&el cursor "DET" posee los items a facturar
  5028. Select("det")
  5029. Go Top
  5030. Do While ! Eof()
  5031. *!* Create Cursor det;
  5032. *!*     (cantidad n(12,4), unidad c(8), detalle c(40), total n(12,2), idArticulo int,;
  5033. *!*     unitario n(12,2), costo n(12,2), montoiva n(12,2), montodgr n(12,2), montomuni N(12,2),;
  5034. *!*     poriva n(12,2), tipoiva c(2))  
  5035.     If det.unitario != 0
  5036.         If This.clase = "A"
  5037.             If This.Ticket = "S"
  5038.                 Insert Into comando;
  5039.                     VALUES ("A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  5040.                 Insert Into comando;
  5041.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + Se +;
  5042.                     ALLTRIM(Str(det.cantidad,6,2)+"0")+ Se +;
  5043.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  5044.                     ALLTRIM(Str(det.poriva,5,2)) + Se +;
  5045.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  5046.             Else
  5047.                 Insert Into comando;
  5048.                     VALUES ("B" + Se + det.unidad +" "+det.detalle+ Se + ;
  5049.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  5050.                     Alltrim(Str(det.unitario,13,2)) + ;
  5051.                     Se +Alltrim(Str(det.poriva,5,2)) + Se + ;
  5052.                     "M" + Se + "0" + Se + "" + Se + "T")
  5053.  
  5054.             Endif
  5055.         Else
  5056.             If This.Ticket = "S"
  5057.                 Insert Into comando;
  5058.                     VALUES ( "A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  5059.                 Insert Into comando;
  5060.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + ;
  5061.                     Se +Alltrim(Str(det.cantidad,6,2)+"0")+ Se + ;
  5062.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  5063.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  5064.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  5065.             Else
  5066.                 Insert Into comando;
  5067.                     VALUES ("B" + Se + det.unidad+" "+det.detalle+ Se +;
  5068.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  5069.                     ALLTRIM(Str(det.unitario,13,2)) + Se +;
  5070.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  5071.                     "M" + Se + "0" + Se + "" + Se + "T")
  5072.             Endif
  5073.         Endif
  5074.     Endif
  5075.     Select("det")
  5076.     Skip
  5077. Enddo
  5078.  
  5079.  
  5080. If This.condicion <> "C"
  5081.     If This.Ticket = "S"
  5082.         If This.contado = "S"
  5083.             Insert Into comando;
  5084.                 VALUES (Chr(68)+ Se + Substr(formapago.detalle,1,30)+ Se + ;
  5085.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  5086.         Else
  5087.             Insert Into comando;
  5088.                 VALUES ( Chr(68)+ Se + Substr(formapago.detalle,1,30)+ ;
  5089.                 Se + Alltrim(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  5090.         Endif
  5091.     Else
  5092.         If This.contado = "S"
  5093.             Insert Into comando;
  5094.                 VALUES (Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  5095.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  5096.         Else
  5097.             Insert Into comando;
  5098.                 VALUES(Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  5099.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  5100.         Endif
  5101.     Endif
  5102. Endif
  5103.  
  5104. If This.condicion <> "C"
  5105.     Insert Into comando;
  5106.         VALUES (Chr(69))
  5107. Else
  5108.     Insert Into comando;
  5109.         VALUES ( Chr(129) )
  5110. Endif
  5111.  
  5112.  
  5113. &&en esta parte copio el archivo con los comandos a la carpeta desde el cual
  5114. &&el spooler de impresion lee el archivo
  5115. If This.Ticket ="S"
  5116. && si es ticket me fijo a cual impresora debo enviar
  5117.     If lImpreFiscal
  5118.         mtXt = Alltrim(impfis.dircoticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  5119.         maNs = Alltrim(impfis.dirreticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  5120.     Else
  5121.         mtXt = Alltrim(parametr.dirco)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  5122.         maNs = Alltrim(parametr.dirre)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  5123.     Endif
  5124. *!*     cDirCom = "fpserver715" + "\impred.exe"
  5125. *!*     cDirCom = Fullpath(cDirCom)
  5126. *!* && Mato el proceso del spooler y lo vuelvo a cargar
  5127. *!*     This.killprocessbyname("impred.exe")
  5128. *!*     This.killprocessbyname("wspooler.exe")
  5129. *!*     oShell = Createobject("Shell.Application")
  5130. *!*     oShell.ShellExecute (cDirCom)
  5131. Else
  5132. &&aca envio a la 320
  5133.     If lImpreFiscal
  5134.         mtXt = Alltrim(impfis.dircofactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  5135.         maNs = Alltrim(impfis.dirrefactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  5136.     Else
  5137.         mtXt = Alltrim(parametr.dirco)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  5138.         maNs = Alltrim(parametr.dirre)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  5139.     Endif
  5140. Endif
  5141.  
  5142.  
  5143. Select("comando")
  5144. Goto Top
  5145. &&en caso de que tenga un archivo en la cola de impresion de la impresora
  5146. &&no se deja imprimir
  5147. *Browse
  5148. If File(mtXt)
  5149.     Messagebox("ATENCION: Ud. ya tiene un Documento en Cola de Impresión"+Chr(10)+Chr(13)+;
  5150.         " AGUARDE a que el mismo sea impreso o elimínelo luego vuelva a intentar")
  5151.     Return This.TodoOK
  5152. Else
  5153.     Copy To &mtXt Sdf
  5154.     If File(maNs)
  5155.         Erase &maNs
  5156.     Endif
  5157.     If File(Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  5158.         Erase (Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  5159.     Endif
  5160.     Wait Windows 'Esperando Respuesta del Controlador Fiscal...' Nowait
  5161.     fd = -1
  5162.     intentos =1
  5163.     Do While fd < 0 .And. Lastkey() != 27
  5164.         fd = Fopen(maNs, 0)
  5165.         This.LeerSpooler("T")
  5166.         If intentos = 30
  5167.             Messagebox("ATENCION: Verifique que el Controlador Esté Conectado y Encendido. " + Chr(10) + Chr(13)+ ;
  5168.                 "Verifique además que el Programa Spooler se esté ejecutando " + Chr(10) + Chr(13)+ ;
  5169.                 "en el equipo al cual se encuentra conectado el Controlador Fiscal")
  5170.             This.LeerSpooler("T")
  5171.         Endif
  5172.         If intentos = 70
  5173.             Messagebox("ATENCION: Tiempo de Espera Agotado !!! Presione ESC. para cancelar este Comprobante")
  5174.             This.LeerSpooler("T")
  5175.         Endif
  5176.         intentos = intentos + 1
  5177. *For i=1 To 100
  5178. *Next
  5179.         Inkey(1)
  5180.         If Lastkey() = 27
  5181.             If Substr(comando.comando,17,16) = "Impresor Ocupado"
  5182.                 Messagebox("ATENCION: No se aconseja cancelar este documento por programa, "+;
  5183.                     CHR(10)+Chr(13)+"La impresora ya lo ha procesado y saldrá impreso"+;
  5184.                     CHR(10)+Chr(13)+ "una vez que esta se ponga en linea")
  5185.             Endif
  5186.             If Messagebox("ATENCION: Realmente desea Cancelar la Emisión de este Documento??",4+256) = 6
  5187.                 Messagebox(" Se proceder  a Cancelar el Documento por Sistema"+;
  5188.                     CHR(10)+Chr(13)+" Verifique que la impresora también lo haya Cancelado.")
  5189.                 Keyboard '{ESC}'
  5190.             Else
  5191.                 Keyboard ""
  5192.             Endif
  5193.         Endif
  5194.     Enddo
  5195.     If Lastkey() = 27.Or. fd < 0
  5196.         If File(mtXt)
  5197.             Erase &mtXt
  5198.         Endif
  5199.         fd = Fopen((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"), 0)
  5200.         If fd < 0
  5201.             Messagebox("Operación Cancelada: ERROR de comunicaciones con el Controlador.; Probablemente no se este ejecutando Spooler. ")
  5202.         Else
  5203.             fd =Fclose(fd)
  5204.             This.LeerSpooler("T")
  5205.         Endif
  5206.     Else
  5207.         fd = Fclose(fd)
  5208.         Select("comando")
  5209.         Zap
  5210.         Append From &maNs Sdf
  5211.         Goto Bottom
  5212.         This.numero = Val(Substr(comando.comando,35,8))
  5213.         If This.numero <> 0
  5214.             SQLExec(goApp.nCon, "select * from puntero where sucursal=?param.sucursal","puntero")
  5215.             If This.Ticket = "S"
  5216.                 If This.MasDeMil
  5217.                     This.numero = Val('0009'+strzero(This.numero,8))
  5218.                 Else
  5219.                     If lImpreFiscal
  5220.                         This.numero = Val(impfis.PtoVtaTicket+strzero(This.numero,8))
  5221.                     Else
  5222.                         If Param.sucursal=0
  5223.                             If File("c:\0009.txt")
  5224.                                 This.numero = Val(strzero(9,4)+strzero(This.numero,8))
  5225.                             Else
  5226.                                 This.numero = Val(strzero(puntero.pvta_tic,4)+strzero(This.numero,8))
  5227.                             Endif
  5228.                         Else
  5229.                             If Param.sucursal = 1
  5230.                                 This.numero = Val(strzero(8,4)+strzero(This.numero,8))
  5231.                             Endif
  5232.                         Endif
  5233.                     Endif
  5234.                 Endif
  5235.             Else
  5236.                 If lImpreFiscal
  5237.                     This.numero = Val(impfis.PtoVtaFac+strzero(This.numero,8))
  5238.                 Else
  5239.                     This.numero = Val(strzero(puntero.pvta_fac,4)+strzero(This.numero,8))
  5240.                 Endif
  5241.             Endif
  5242.             This.TodoOK = .T.
  5243.         Endif
  5244.     Endif
  5245.     If File((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"))
  5246.         Erase Alltrim(paramfac.dirpa)+"SPOOLER.LOG"
  5247.     Endif
  5248. Endif
  5249. *This.killprocessbyname("impred.exe")
  5250. *This.killprocessbyname("wspooler.exe")
  5251.  
  5252. Set Talk &cTalk
  5253. Return This.Todo
  5254. *!*     Insert Into comando;
  5255. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  5256.     Insert Into comando;
  5257.         VALUES ("]" + Se + lin + Se + Chr(127))
  5258. Endif
  5259.  
  5260. If This.Ticket="S"
  5261.     Insert Into comando;
  5262.         VALUES ( "]" + Se + "9" + Se +Chr(127))
  5263.     Insert Into comando;
  5264.         VALUES ("]" + Se + "10" + Se +Chr(127))
  5265.     If This.condicion = 'C' And Val(sCliente) = 1
  5266.         Insert Into comando;
  5267.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  5268.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  5269.             " S/NOMBRE")
  5270.     Else
  5271.         Insert Into comando;
  5272.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  5273.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  5274.             SUBSTR(Alltrim(thisformset.frmCliente.txtDomicilio.Value)+" "+Alltrim(loc.nombre)+;
  5275.             " "+Alltrim(loc.provincia),1,40))
  5276.     Endif
  5277.  
  5278. Else
  5279. &&"["+sCliente+"] "+
  5280.     Insert Into comando;
  5281.         VALUES ( "b" + Se + "[" + sCliente + "] " + Substr(sNombre,1,40) + Se +;
  5282.         ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se + ;
  5283.         ALLTRIM(Thisform.txtDom.Value)+" ("+Alltrim(clientes.codpos)+") "+;
  5284.         Alltrim(loc.nombre)+" "+Alltrim(loc.provincia))
  5285. Endif
  5286. If This.condicion <> "C"
  5287.     Insert Into comando;
  5288.         VALUES (Chr(64)+Se+TIPO_FACTURA+Se+"T")
  5289. Else
  5290. &&Definir tipo y num de factura afectado por nota de credito
  5291.     Insert Into comando;
  5292.         VALUES (Chr(147) + Se + "1" + Se + cre.tipoaf + " " + cre.numeroaf)
  5293.     Insert Into comando;
  5294.         VALUES (Chr(128)+Se+TIPO_FACTURA+Se+"T")
  5295. Endif
  5296.  
  5297. &&el cursor "DET" posee los items a facturar
  5298. Select("det")
  5299. Go Top
  5300. Do While ! Eof()
  5301. *!* Create Cursor det;
  5302. *!*     (cantidad n(12,4), unidad c(8), detalle c(40), total n(12,2), idArticulo int,;
  5303. *!*     unitario n(12,2), costo n(12,2), montoiva n(12,2), montodgr n(12,2), montomuni N(12,2),;
  5304. *!*     poriva n(12,2), tipoiva c(2))  
  5305.     If det.unitario != 0
  5306.         If This.clase = "A"
  5307.             If This.Ticket = "S"
  5308.                 Insert Into comando;
  5309.                     VALUES ("A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  5310.                 Insert Into comando;
  5311.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + Se +;
  5312.                     ALLTRIM(Str(det.cantidad,6,2)+"0")+ Se +;
  5313.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  5314.                     ALLTRIM(Str(det.poriva,5,2)) + Se +;
  5315.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  5316.             Else
  5317.                 Insert Into comando;
  5318.                     VALUES ("B" + Se + det.unidad +" "+det.detalle+ Se + ;
  5319.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  5320.                     Alltrim(Str(det.unitario,13,2)) + ;
  5321.                     Se +Alltrim(Str(det.poriva,5,2)) + Se + ;
  5322.                     "M" + Se + "0" + Se + "" + Se + "T")
  5323.  
  5324.             Endif
  5325.         Else
  5326.             If This.Ticket = "S"
  5327.                 Insert Into comando;
  5328.                     VALUES ( "A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  5329.                 Insert Into comando;
  5330.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + ;
  5331.                     Se +Alltrim(Str(det.cantidad,6,2)+"0")+ Se + ;
  5332.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  5333.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  5334.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  5335.             Else
  5336.                 Insert Into comando;
  5337.                     VALUES ("B" + Se + det.unidad+" "+det.detalle+ Se +;
  5338.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  5339.                     ALLTRIM(Str(det.unitario,13,2)) + Se +;
  5340.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  5341.                     "M" + Se + "0" + Se + "" + Se + "T")
  5342.             Endif
  5343.         Endif
  5344.     Endif
  5345.     Select("det")
  5346.     Skip
  5347. Enddo
  5348.  
  5349.  
  5350. If This.condicion <> "C"
  5351.     If This.Ticket = "S"
  5352.         If This.contado = "S"
  5353.             Insert Into comando;
  5354.                 VALUES (Chr(68)+ Se + Substr(formapago.detalle,1,30)+ Se + ;
  5355.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  5356.         Else
  5357.             Insert Into comando;
  5358.                 VALUES ( Chr(68)+ Se + Substr(formapago.detalle,1,30)+ ;
  5359.                 Se + Alltrim(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  5360.         Endif
  5361.     Else
  5362.         If This.contado = "S"
  5363.             Insert Into comando;
  5364.                 VALUES (Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  5365.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  5366.         Else
  5367.             Insert Into comando;
  5368.                 VALUES(Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  5369.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  5370.         Endif
  5371.     Endif
  5372. Endif
  5373.  
  5374. If This.condicion <> "C"
  5375.     Insert Into comando;
  5376.         VALUES (Chr(69))
  5377. Else
  5378.     Insert Into comando;
  5379.         VALUES ( Chr(129) )
  5380. Endif
  5381.  
  5382.  
  5383. &&en esta parte copio el archivo con los comandos a la carpeta desde el cual
  5384. &&el spooler de impresion lee el archivo
  5385. If This.Ticket ="S"
  5386. && si es ticket me fijo a cual impresora debo enviar
  5387.     If lImpreFiscal
  5388.         mtXt = Alltrim(impfis.dircoticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  5389.         maNs = Alltrim(impfis.dirreticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  5390.     Else
  5391.         mtXt = Alltrim(parametr.dirco)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  5392.         maNs = Alltrim(parametr.dirre)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  5393.     Endif
  5394. *!*     cDirCom = "fpserver715" + "\impred.exe"
  5395. *!*     cDirCom = Fullpath(cDirCom)
  5396. *!* && Mato el proceso del spooler y lo vuelvo a cargar
  5397. *!*     This.killprocessbyname("impred.exe")
  5398. *!*     This.killprocessbyname("wspooler.exe")
  5399. *!*     oShell = Createobject("Shell.Application")
  5400. *!*     oShell.ShellExecute (cDirCom)
  5401. Else
  5402. &&aca envio a la 320
  5403.     If lImpreFiscal
  5404.         mtXt = Alltrim(impfis.dircofactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  5405.         maNs = Alltrim(impfis.dirrefactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  5406.     Else
  5407.         mtXt = Alltrim(parametr.dirco)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  5408.         maNs = Alltrim(parametr.dirre)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  5409.     Endif
  5410. Endif
  5411.  
  5412.  
  5413. Select("comando")
  5414. Goto Top
  5415. &&en caso de que tenga un archivo en la cola de impresion de la impresora
  5416. &&no se deja imprimir
  5417. *Browse
  5418. If File(mtXt)
  5419.     Messagebox("ATENCION: Ud. ya tiene un Documento en Cola de Impresión"+Chr(10)+Chr(13)+;
  5420.         " AGUARDE a que el mismo sea impreso o elimínelo luego vuelva a intentar")
  5421.     Return This.TodoOK
  5422. Else
  5423.     Copy To &mtXt Sdf
  5424.     If File(maNs)
  5425.         Erase &maNs
  5426.     Endif
  5427.     If File(Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  5428.         Erase (Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  5429.     Endif
  5430.     Wait Windows 'Esperando Respuesta del Controlador Fiscal...' Nowait
  5431.     fd = -1
  5432.     intentos =1
  5433.     Do While fd < 0 .And. Lastkey() != 27
  5434.         fd = Fopen(maNs, 0)
  5435.         This.LeerSpooler("T")
  5436.         If intentos = 30
  5437.             Messagebox("ATENCION: Verifique que el Controlador Esté Conectado y Encendido. " + Chr(10) + Chr(13)+ ;
  5438.                 "Verifique además que el Programa Spooler se esté ejecutando " + Chr(10) + Chr(13)+ ;
  5439.                 "en el equipo al cual se encuentra conectado el Controlador Fiscal")
  5440.             This.LeerSpooler("T")
  5441.         Endif
  5442.         If intentos = 70
  5443.             Messagebox("ATENCION: Tiempo de Espera Agotado !!! Presione ESC. para cancelar este Comprobante")
  5444.             This.LeerSpooler("T")
  5445.         Endif
  5446.         intentos = intentos + 1
  5447. *For i=1 To 100
  5448. *Next
  5449.         Inkey(1)
  5450.         If Lastkey() = 27
  5451.             If Substr(comando.comando,17,16) = "Impresor Ocupado"
  5452.                 Messagebox("ATENCION: No se aconseja cancelar este documento por programa, "+;
  5453.                     CHR(10)+Chr(13)+"La impresora ya lo ha procesado y saldrá impreso"+;
  5454.                     CHR(10)+Chr(13)+ "una vez que esta se ponga en linea")
  5455.             Endif
  5456.             If Messagebox("ATENCION: Realmente desea Cancelar la Emisión de este Documento??",4+256) = 6
  5457.                 Messagebox(" Se proceder  a Cancelar el Documento por Sistema"+;
  5458.                     CHR(10)+Chr(13)+" Verifique que la impresora también lo haya Cancelado.")
  5459.                 Keyboard '{ESC}'
  5460.             Else
  5461.                 Keyboard ""
  5462.             Endif
  5463.         Endif
  5464.     Enddo
  5465.     If Lastkey() = 27.Or. fd < 0
  5466.         If File(mtXt)
  5467.             Erase &mtXt
  5468.         Endif
  5469.         fd = Fopen((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"), 0)
  5470.         If fd < 0
  5471.             Messagebox("Operación Cancelada: ERROR de comunicaciones con el Controlador.; Probablemente no se este ejecutando Spooler. ")
  5472.         Else
  5473.             fd =Fclose(fd)
  5474.             This.LeerSpooler("T")
  5475.         Endif
  5476.     Else
  5477.         fd = Fclose(fd)
  5478.         Select("comando")
  5479.         Zap
  5480.         Append From &maNs Sdf
  5481.         Goto Bottom
  5482.         This.numero = Val(Substr(comando.comando,35,8))
  5483.         If This.numero <> 0
  5484.             SQLExec(goApp.nCon, "select * from puntero where sucursal=?param.sucursal","puntero")
  5485.             If This.Ticket = "S"
  5486.                 If This.MasDeMil
  5487.                     This.numero = Val('0009'+strzero(This.numero,8))
  5488.                 Else
  5489.                     If lImpreFiscal
  5490.                         This.numero = Val(impfis.PtoVtaTicket+strzero(This.numero,8))
  5491.                     Else
  5492.                         If Param.sucursal=0
  5493.                             If File("c:\0009.txt")
  5494.                                 This.numero = Val(strzero(9,4)+strzero(This.numero,8))
  5495.                             Else
  5496.                                 This.numero = Val(strzero(puntero.pvta_tic,4)+strzero(This.numero,8))
  5497.                             Endif
  5498.                         Else
  5499.                             If Param.sucursal = 1
  5500.                                 This.numero = Val(strzero(8,4)+strzero(This.numero,8))
  5501.                             Endif
  5502.                         Endif
  5503.                     Endif
  5504.                 Endif
  5505.             Else
  5506.                 If lImpreFiscal
  5507.                     This.numero = Val(impfis.PtoVtaFac+strzero(This.numero,8))
  5508.                 Else
  5509.                     This.numero = Val(strzero(puntero.pvta_fac,4)+strzero(This.numero,8))
  5510.                 Endif
  5511.             Endif
  5512.             This.TodoOK = .T.
  5513.         Endif
  5514.     Endif
  5515.     If File((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"))
  5516.         Erase Alltrim(paramfac.dirpa)+"SPOOLER.LOG"
  5517.     Endif
  5518. Endif
  5519. *This.killprocessbyname("impred.exe")
  5520. *This.killprocessbyname("wspooler.exe")
  5521.  
  5522. Set Talk &cTalk
  5523. Return This.Todo
  5524. *!*             VALUES ("]" + Se + lin + Se + Chr(127))
  5525.     Insert Into comando;
  5526.         VALUES ("]" + Se + lin + Se + Chr(127))
  5527. Endif
  5528.  
  5529. If This.Ticket="S"
  5530.     Insert Into comando;
  5531.         VALUES ( "]" + Se + "9" + Se +Chr(127))
  5532.     Insert Into comando;
  5533.         VALUES ("]" + Se + "10" + Se +Chr(127))
  5534.     If This.condicion = 'C' And Val(sCliente) = 1
  5535.         Insert Into comando;
  5536.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  5537.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  5538.             " S/NOMBRE")
  5539.     Else
  5540.         Insert Into comando;
  5541.             VALUES ("b" + Se + Substr(sNombre,1,30) + Se + ;
  5542.             ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se +;
  5543.             SUBSTR(Alltrim(thisformset.frmCliente.txtDomicilio.Value)+" "+Alltrim(loc.nombre)+;
  5544.             " "+Alltrim(loc.provincia),1,40))
  5545.     Endif
  5546.  
  5547. Else
  5548. &&"["+sCliente+"] "+
  5549.     Insert Into comando;
  5550.         VALUES ( "b" + Se + "[" + sCliente + "] " + Substr(sNombre,1,40) + Se +;
  5551.         ndocu + Se + TIPO_IVA + Se + TIPO_DOCU + Se + ;
  5552.         ALLTRIM(Thisform.txtDom.Value)+" ("+Alltrim(clientes.codpos)+") "+;
  5553.         Alltrim(loc.nombre)+" "+Alltrim(loc.provincia))
  5554. Endif
  5555. If This.condicion <> "C"
  5556.     Insert Into comando;
  5557.         VALUES (Chr(64)+Se+TIPO_FACTURA+Se+"T")
  5558. Else
  5559. &&Definir tipo y num de factura afectado por nota de credito
  5560.     Insert Into comando;
  5561.         VALUES (Chr(147) + Se + "1" + Se + cre.tipoaf + " " + cre.numeroaf)
  5562.     Insert Into comando;
  5563.         VALUES (Chr(128)+Se+TIPO_FACTURA+Se+"T")
  5564. Endif
  5565.  
  5566. &&el cursor "DET" posee los items a facturar
  5567. Select("det")
  5568. Go Top
  5569. Do While ! Eof()
  5570. *!* Create Cursor det;
  5571. *!*     (cantidad n(12,4), unidad c(8), detalle c(40), total n(12,2), idArticulo int,;
  5572. *!*     unitario n(12,2), costo n(12,2), montoiva n(12,2), montodgr n(12,2), montomuni N(12,2),;
  5573. *!*     poriva n(12,2), tipoiva c(2))  
  5574.     If det.unitario != 0
  5575.         If This.clase = "A"
  5576.             If This.Ticket = "S"
  5577.                 Insert Into comando;
  5578.                     VALUES ("A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  5579.                 Insert Into comando;
  5580.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + Se +;
  5581.                     ALLTRIM(Str(det.cantidad,6,2)+"0")+ Se +;
  5582.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  5583.                     ALLTRIM(Str(det.poriva,5,2)) + Se +;
  5584.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  5585.             Else
  5586.                 Insert Into comando;
  5587.                     VALUES ("B" + Se + det.unidad +" "+det.detalle+ Se + ;
  5588.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  5589.                     Alltrim(Str(det.unitario,13,2)) + ;
  5590.                     Se +Alltrim(Str(det.poriva,5,2)) + Se + ;
  5591.                     "M" + Se + "0" + Se + "" + Se + "T")
  5592.  
  5593.             Endif
  5594.         Else
  5595.             If This.Ticket = "S"
  5596.                 Insert Into comando;
  5597.                     VALUES ( "A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  5598.                 Insert Into comando;
  5599.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + ;
  5600.                     Se +Alltrim(Str(det.cantidad,6,2)+"0")+ Se + ;
  5601.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  5602.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  5603.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  5604.             Else
  5605.                 Insert Into comando;
  5606.                     VALUES ("B" + Se + det.unidad+" "+det.detalle+ Se +;
  5607.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  5608.                     ALLTRIM(Str(det.unitario,13,2)) + Se +;
  5609.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  5610.                     "M" + Se + "0" + Se + "" + Se + "T")
  5611.             Endif
  5612.         Endif
  5613.     Endif
  5614.     Select("det")
  5615.     Skip
  5616. Enddo
  5617.  
  5618.  
  5619. If This.condicion <> "C"
  5620.     If This.Ticket = "S"
  5621.         If This.contado = "S"
  5622.             Insert Into comando;
  5623.                 VALUES (Chr(68)+ Se + Substr(formapago.detalle,1,30)+ Se + ;
  5624.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  5625.         Else
  5626.             Insert Into comando;
  5627.                 VALUES ( Chr(68)+ Se + Substr(formapago.detalle,1,30)+ ;
  5628.                 Se + Alltrim(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  5629.         Endif
  5630.     Else
  5631.         If This.contado = "S"
  5632.             Insert Into comando;
  5633.                 VALUES (Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  5634.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  5635.         Else
  5636.             Insert Into comando;
  5637.                 VALUES(Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  5638.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  5639.         Endif
  5640.     Endif
  5641. Endif
  5642.  
  5643. If This.condicion <> "C"
  5644.     Insert Into comando;
  5645.         VALUES (Chr(69))
  5646. Else
  5647.     Insert Into comando;
  5648.         VALUES ( Chr(129) )
  5649. Endif
  5650.  
  5651.  
  5652. &&en esta parte copio el archivo con los comandos a la carpeta desde el cual
  5653. &&el spooler de impresion lee el archivo
  5654. If This.Ticket ="S"
  5655. && si es ticket me fijo a cual impresora debo enviar
  5656.     If lImpreFiscal
  5657.         mtXt = Alltrim(impfis.dircoticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  5658.         maNs = Alltrim(impfis.dirreticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  5659.     Else
  5660.         mtXt = Alltrim(parametr.dirco)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  5661.         maNs = Alltrim(parametr.dirre)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  5662.     Endif
  5663. *!*     cDirCom = "fpserver715" + "\impred.exe"
  5664. *!*     cDirCom = Fullpath(cDirCom)
  5665. *!* && Mato el proceso del spooler y lo vuelvo a cargar
  5666. *!*     This.killprocessbyname("impred.exe")
  5667. *!*     This.killprocessbyname("wspooler.exe")
  5668. *!*     oShell = Createobject("Shell.Application")
  5669. *!*     oShell.ShellExecute (cDirCom)
  5670. Else
  5671. &&aca envio a la 320
  5672.     If lImpreFiscal
  5673.         mtXt = Alltrim(impfis.dircofactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  5674.         maNs = Alltrim(impfis.dirrefactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  5675.     Else
  5676.         mtXt = Alltrim(parametr.dirco)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  5677.         maNs = Alltrim(parametr.dirre)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  5678.     Endif
  5679. Endif
  5680.  
  5681.  
  5682. Select("comando")
  5683. Goto Top
  5684. &&en caso de que tenga un archivo en la cola de impresion de la impresora
  5685. &&no se deja imprimir
  5686. *Browse
  5687. If File(mtXt)
  5688.     Messagebox("ATENCION: Ud. ya tiene un Documento en Cola de Impresión"+Chr(10)+Chr(13)+;
  5689.         " AGUARDE a que el mismo sea impreso o elimínelo luego vuelva a intentar")
  5690.     Return This.TodoOK
  5691. Else
  5692.     Copy To &mtXt Sdf
  5693.     If File(maNs)
  5694.         Erase &maNs
  5695.     Endif
  5696.     If File(Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  5697.         Erase (Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  5698.     Endif
  5699.     Wait Windows 'Esperando Respuesta del Controlador Fiscal...' Nowait
  5700.     fd = -1
  5701.     intentos =1
  5702.     Do While fd < 0 .And. Lastkey() != 27
  5703.         fd = Fopen(maNs, 0)
  5704.         This.LeerSpooler("T")
  5705.         If intentos = 30
  5706.             Messagebox("ATENCION: Verifique que el Controlador Esté Conectado y Encendido. " + Chr(10) + Chr(13)+ ;
  5707.                 "Verifique además que el Programa Spooler se esté ejecutando " + Chr(10) + Chr(13)+ ;
  5708.                 "en el equipo al cual se encuentra conectado el Controlador Fiscal")
  5709.             This.LeerSpooler("T")
  5710.         Endif
  5711.         If intentos = 70
  5712.             Messagebox("ATENCION: Tiempo de Espera Agotado !!! Presione ESC. para cancelar este Comprobante")
  5713.             This.LeerSpooler("T")
  5714.         Endif
  5715.         intentos = intentos + 1
  5716. *For i=1 To 100
  5717. *Next
  5718.         Inkey(1)
  5719.         If Lastkey() = 27
  5720.             If Substr(comando.comando,17,16) = "Impresor Ocupado"
  5721.                 Messagebox("ATENCION: No se aconseja cancelar este documento por programa, "+;
  5722.                     CHR(10)+Chr(13)+"La impresora ya lo ha procesado y saldrá impreso"+;
  5723.                     CHR(10)+Chr(13)+ "una vez que esta se ponga en linea")
  5724.             Endif
  5725.             If Messagebox("ATENCION: Realmente desea Cancelar la Emisión de este Documento??",4+256) = 6
  5726.                 Messagebox(" Se proceder  a Cancelar el Documento por Sistema"+;
  5727.                     CHR(10)+Chr(13)+" Verifique que la impresora también lo haya Cancelado.")
  5728.                 Keyboard '{ESC}'
  5729.             Else
  5730.                 Keyboard ""
  5731.             Endif
  5732.         Endif
  5733.     Enddo
  5734.     If Lastkey() = 27.Or. fd < 0
  5735.         If File(mtXt)
  5736.             Erase &mtXt
  5737.         Endif
  5738.         fd = Fopen((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"), 0)
  5739.         If fd < 0
  5740.             Messagebox("Operación Cancelada: ERROR de comunicaciones con el Controlador.; Probablemente no se este ejecutando Spooler. ")
  5741.         Else
  5742.             fd =Fclose(fd)
  5743.             This.LeerSpooler("T")
  5744.         Endif
  5745.     Else
  5746.         fd = Fclose(fd)
  5747.         Select("comando")
  5748.         Zap
  5749.         Append From &maNs Sdf
  5750.         Goto Bottom
  5751.         This.numero = Val(Substr(comando.comando,35,8))
  5752.         If This.numero <> 0
  5753.             SQLExec(goApp.nCon, "select * from puntero where sucursal=?param.sucursal","puntero")
  5754.             If This.Ticket = "S"
  5755.                 If This.MasDeMil
  5756.                     This.numero = Val('0009'+strzero(This.numero,8))
  5757.                 Else
  5758.                     If lImpreFiscal
  5759.                         This.numero = Val(impfis.PtoVtaTicket+strzero(This.numero,8))
  5760.                     Else
  5761.                         If Param.sucursal=0
  5762.                             If File("c:\0009.txt")
  5763.                                 This.numero = Val(strzero(9,4)+strzero(This.numero,8))
  5764.                             Else
  5765.                                 This.numero = Val(strzero(puntero.pvta_tic,4)+strzero(This.numero,8))
  5766.                             Endif
  5767.                         Else
  5768.                             If Param.sucursal = 1
  5769.                                 This.numero = Val(strzero(8,4)+strzero(This.numero,8))
  5770.                             Endif
  5771.                         Endif
  5772.                     Endif
  5773.                 Endif
  5774.             Else
  5775.                 If lImpreFiscal
  5776.                     This.numero = Val(impfis.PtoVtaFac+strzero(This.numero,8))
  5777.                 Else
  5778.                     This.numero = Val(strzero(puntero.pvta_fac,4)+strzero(This.numero,8))
  5779.                 Endif
  5780.             Endif
  5781.             This.TodoOK = .T.
  5782.         Endif
  5783.     Endif
  5784.     If File((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"))
  5785.         Erase Alltrim(paramfac.dirpa)+"SPOOLER.LOG"
  5786.     Endif
  5787. Endif
  5788. *This.killprocessbyname("impred.exe")
  5789. *This.killprocessbyname("wspooler.exe")
  5790.  
  5791. Set Talk &cTalk
  5792. Return This.Todo
  5793. *!* Create Cursor det;
  5794. *!*     (cantidad n(12,4), unidad c(8), detalle c(40), total n(12,2), idArticulo int,;
  5795. *!*     unitario n(12,2), costo n(12,2), montoiva n(12,2), montodgr n(12,2), montomuni N(12,2),;
  5796. *!*     poriva n(12,2), tipoiva c(2))  
  5797.     If det.unitario != 0
  5798.         If This.clase = "A"
  5799.             If This.Ticket = "S"
  5800.                 Insert Into comando;
  5801.                     VALUES ("A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  5802.                 Insert Into comando;
  5803.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + Se +;
  5804.                     ALLTRIM(Str(det.cantidad,6,2)+"0")+ Se +;
  5805.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  5806.                     ALLTRIM(Str(det.poriva,5,2)) + Se +;
  5807.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  5808.             Else
  5809.                 Insert Into comando;
  5810.                     VALUES ("B" + Se + det.unidad +" "+det.detalle+ Se + ;
  5811.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  5812.                     Alltrim(Str(det.unitario,13,2)) + ;
  5813.                     Se +Alltrim(Str(det.poriva,5,2)) + Se + ;
  5814.                     "M" + Se + "0" + Se + "" + Se + "T")
  5815.  
  5816.             Endif
  5817.         Else
  5818.             If This.Ticket = "S"
  5819.                 Insert Into comando;
  5820.                     VALUES ( "A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  5821.                 Insert Into comando;
  5822.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + ;
  5823.                     Se +Alltrim(Str(det.cantidad,6,2)+"0")+ Se + ;
  5824.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  5825.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  5826.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  5827.             Else
  5828.                 Insert Into comando;
  5829.                     VALUES ("B" + Se + det.unidad+" "+det.detalle+ Se +;
  5830.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  5831.                     ALLTRIM(Str(det.unitario,13,2)) + Se +;
  5832.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  5833.                     "M" + Se + "0" + Se + "" + Se + "T")
  5834.             Endif
  5835.         Endif
  5836.     Endif
  5837.     Select("det")
  5838.     Skip
  5839. Enddo
  5840.  
  5841.  
  5842. If This.condicion <> "C"
  5843.     If This.Ticket = "S"
  5844.         If This.contado = "S"
  5845.             Insert Into comando;
  5846.                 VALUES (Chr(68)+ Se + Substr(formapago.detalle,1,30)+ Se + ;
  5847.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  5848.         Else
  5849.             Insert Into comando;
  5850.                 VALUES ( Chr(68)+ Se + Substr(formapago.detalle,1,30)+ ;
  5851.                 Se + Alltrim(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  5852.         Endif
  5853.     Else
  5854.         If This.contado = "S"
  5855.             Insert Into comando;
  5856.                 VALUES (Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  5857.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  5858.         Else
  5859.             Insert Into comando;
  5860.                 VALUES(Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  5861.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  5862.         Endif
  5863.     Endif
  5864. Endif
  5865.  
  5866. If This.condicion <> "C"
  5867.     Insert Into comando;
  5868.         VALUES (Chr(69))
  5869. Else
  5870.     Insert Into comando;
  5871.         VALUES ( Chr(129) )
  5872. Endif
  5873.  
  5874.  
  5875. &&en esta parte copio el archivo con los comandos a la carpeta desde el cual
  5876. &&el spooler de impresion lee el archivo
  5877. If This.Ticket ="S"
  5878. && si es ticket me fijo a cual impresora debo enviar
  5879.     If lImpreFiscal
  5880.         mtXt = Alltrim(impfis.dircoticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  5881.         maNs = Alltrim(impfis.dirreticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  5882.     Else
  5883.         mtXt = Alltrim(parametr.dirco)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  5884.         maNs = Alltrim(parametr.dirre)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  5885.     Endif
  5886. *!*     cDirCom = "fpserver715" + "\impred.exe"
  5887. *!*     cDirCom = Fullpath(cDirCom)
  5888. *!* && Mato el proceso del spooler y lo vuelvo a cargar
  5889. *!*     This.killprocessbyname("impred.exe")
  5890. *!*     This.killprocessbyname("wspooler.exe")
  5891. *!*     oShell = Createobject("Shell.Application")
  5892. *!*     oShell.ShellExecute (cDirCom)
  5893. Else
  5894. &&aca envio a la 320
  5895.     If lImpreFiscal
  5896.         mtXt = Alltrim(impfis.dircofactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  5897.         maNs = Alltrim(impfis.dirrefactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  5898.     Else
  5899.         mtXt = Alltrim(parametr.dirco)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  5900.         maNs = Alltrim(parametr.dirre)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  5901.     Endif
  5902. Endif
  5903.  
  5904.  
  5905. Select("comando")
  5906. Goto Top
  5907. &&en caso de que tenga un archivo en la cola de impresion de la impresora
  5908. &&no se deja imprimir
  5909. *Browse
  5910. If File(mtXt)
  5911.     Messagebox("ATENCION: Ud. ya tiene un Documento en Cola de Impresión"+Chr(10)+Chr(13)+;
  5912.         " AGUARDE a que el mismo sea impreso o elimínelo luego vuelva a intentar")
  5913.     Return This.TodoOK
  5914. Else
  5915.     Copy To &mtXt Sdf
  5916.     If File(maNs)
  5917.         Erase &maNs
  5918.     Endif
  5919.     If File(Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  5920.         Erase (Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  5921.     Endif
  5922.     Wait Windows 'Esperando Respuesta del Controlador Fiscal...' Nowait
  5923.     fd = -1
  5924.     intentos =1
  5925.     Do While fd < 0 .And. Lastkey() != 27
  5926.         fd = Fopen(maNs, 0)
  5927.         This.LeerSpooler("T")
  5928.         If intentos = 30
  5929.             Messagebox("ATENCION: Verifique que el Controlador Esté Conectado y Encendido. " + Chr(10) + Chr(13)+ ;
  5930.                 "Verifique además que el Programa Spooler se esté ejecutando " + Chr(10) + Chr(13)+ ;
  5931.                 "en el equipo al cual se encuentra conectado el Controlador Fiscal")
  5932.             This.LeerSpooler("T")
  5933.         Endif
  5934.         If intentos = 70
  5935.             Messagebox("ATENCION: Tiempo de Espera Agotado !!! Presione ESC. para cancelar este Comprobante")
  5936.             This.LeerSpooler("T")
  5937.         Endif
  5938.         intentos = intentos + 1
  5939. *For i=1 To 100
  5940. *Next
  5941.         Inkey(1)
  5942.         If Lastkey() = 27
  5943.             If Substr(comando.comando,17,16) = "Impresor Ocupado"
  5944.                 Messagebox("ATENCION: No se aconseja cancelar este documento por programa, "+;
  5945.                     CHR(10)+Chr(13)+"La impresora ya lo ha procesado y saldrá impreso"+;
  5946.                     CHR(10)+Chr(13)+ "una vez que esta se ponga en linea")
  5947.             Endif
  5948.             If Messagebox("ATENCION: Realmente desea Cancelar la Emisión de este Documento??",4+256) = 6
  5949.                 Messagebox(" Se proceder  a Cancelar el Documento por Sistema"+;
  5950.                     CHR(10)+Chr(13)+" Verifique que la impresora también lo haya Cancelado.")
  5951.                 Keyboard '{ESC}'
  5952.             Else
  5953.                 Keyboard ""
  5954.             Endif
  5955.         Endif
  5956.     Enddo
  5957.     If Lastkey() = 27.Or. fd < 0
  5958.         If File(mtXt)
  5959.             Erase &mtXt
  5960.         Endif
  5961.         fd = Fopen((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"), 0)
  5962.         If fd < 0
  5963.             Messagebox("Operación Cancelada: ERROR de comunicaciones con el Controlador.; Probablemente no se este ejecutando Spooler. ")
  5964.         Else
  5965.             fd =Fclose(fd)
  5966.             This.LeerSpooler("T")
  5967.         Endif
  5968.     Else
  5969.         fd = Fclose(fd)
  5970.         Select("comando")
  5971.         Zap
  5972.         Append From &maNs Sdf
  5973.         Goto Bottom
  5974.         This.numero = Val(Substr(comando.comando,35,8))
  5975.         If This.numero <> 0
  5976.             SQLExec(goApp.nCon, "select * from puntero where sucursal=?param.sucursal","puntero")
  5977.             If This.Ticket = "S"
  5978.                 If This.MasDeMil
  5979.                     This.numero = Val('0009'+strzero(This.numero,8))
  5980.                 Else
  5981.                     If lImpreFiscal
  5982.                         This.numero = Val(impfis.PtoVtaTicket+strzero(This.numero,8))
  5983.                     Else
  5984.                         If Param.sucursal=0
  5985.                             If File("c:\0009.txt")
  5986.                                 This.numero = Val(strzero(9,4)+strzero(This.numero,8))
  5987.                             Else
  5988.                                 This.numero = Val(strzero(puntero.pvta_tic,4)+strzero(This.numero,8))
  5989.                             Endif
  5990.                         Else
  5991.                             If Param.sucursal = 1
  5992.                                 This.numero = Val(strzero(8,4)+strzero(This.numero,8))
  5993.                             Endif
  5994.                         Endif
  5995.                     Endif
  5996.                 Endif
  5997.             Else
  5998.                 If lImpreFiscal
  5999.                     This.numero = Val(impfis.PtoVtaFac+strzero(This.numero,8))
  6000.                 Else
  6001.                     This.numero = Val(strzero(puntero.pvta_fac,4)+strzero(This.numero,8))
  6002.                 Endif
  6003.             Endif
  6004.             This.TodoOK = .T.
  6005.         Endif
  6006.     Endif
  6007.     If File((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"))
  6008.         Erase Alltrim(paramfac.dirpa)+"SPOOLER.LOG"
  6009.     Endif
  6010. Endif
  6011. *This.killprocessbyname("impred.exe")
  6012. *This.killprocessbyname("wspooler.exe")
  6013.  
  6014. Set Talk &cTalk
  6015. Return This.Todo
  6016. *!*     (cantidad n(12,4), unidad c(8), detalle c(40), total n(12,2), idArticulo int,;
  6017. *!*     unitario n(12,2), costo n(12,2), montoiva n(12,2), montodgr n(12,2), montomuni N(12,2),;
  6018. *!*     poriva n(12,2), tipoiva c(2))  
  6019.     If det.unitario != 0
  6020.         If This.clase = "A"
  6021.             If This.Ticket = "S"
  6022.                 Insert Into comando;
  6023.                     VALUES ("A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  6024.                 Insert Into comando;
  6025.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + Se +;
  6026.                     ALLTRIM(Str(det.cantidad,6,2)+"0")+ Se +;
  6027.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  6028.                     ALLTRIM(Str(det.poriva,5,2)) + Se +;
  6029.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  6030.             Else
  6031.                 Insert Into comando;
  6032.                     VALUES ("B" + Se + det.unidad +" "+det.detalle+ Se + ;
  6033.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  6034.                     Alltrim(Str(det.unitario,13,2)) + ;
  6035.                     Se +Alltrim(Str(det.poriva,5,2)) + Se + ;
  6036.                     "M" + Se + "0" + Se + "" + Se + "T")
  6037.  
  6038.             Endif
  6039.         Else
  6040.             If This.Ticket = "S"
  6041.                 Insert Into comando;
  6042.                     VALUES ( "A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  6043.                 Insert Into comando;
  6044.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + ;
  6045.                     Se +Alltrim(Str(det.cantidad,6,2)+"0")+ Se + ;
  6046.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  6047.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  6048.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  6049.             Else
  6050.                 Insert Into comando;
  6051.                     VALUES ("B" + Se + det.unidad+" "+det.detalle+ Se +;
  6052.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  6053.                     ALLTRIM(Str(det.unitario,13,2)) + Se +;
  6054.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  6055.                     "M" + Se + "0" + Se + "" + Se + "T")
  6056.             Endif
  6057.         Endif
  6058.     Endif
  6059.     Select("det")
  6060.     Skip
  6061. Enddo
  6062.  
  6063.  
  6064. If This.condicion <> "C"
  6065.     If This.Ticket = "S"
  6066.         If This.contado = "S"
  6067.             Insert Into comando;
  6068.                 VALUES (Chr(68)+ Se + Substr(formapago.detalle,1,30)+ Se + ;
  6069.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  6070.         Else
  6071.             Insert Into comando;
  6072.                 VALUES ( Chr(68)+ Se + Substr(formapago.detalle,1,30)+ ;
  6073.                 Se + Alltrim(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  6074.         Endif
  6075.     Else
  6076.         If This.contado = "S"
  6077.             Insert Into comando;
  6078.                 VALUES (Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  6079.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  6080.         Else
  6081.             Insert Into comando;
  6082.                 VALUES(Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  6083.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  6084.         Endif
  6085.     Endif
  6086. Endif
  6087.  
  6088. If This.condicion <> "C"
  6089.     Insert Into comando;
  6090.         VALUES (Chr(69))
  6091. Else
  6092.     Insert Into comando;
  6093.         VALUES ( Chr(129) )
  6094. Endif
  6095.  
  6096.  
  6097. &&en esta parte copio el archivo con los comandos a la carpeta desde el cual
  6098. &&el spooler de impresion lee el archivo
  6099. If This.Ticket ="S"
  6100. && si es ticket me fijo a cual impresora debo enviar
  6101.     If lImpreFiscal
  6102.         mtXt = Alltrim(impfis.dircoticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  6103.         maNs = Alltrim(impfis.dirreticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  6104.     Else
  6105.         mtXt = Alltrim(parametr.dirco)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  6106.         maNs = Alltrim(parametr.dirre)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  6107.     Endif
  6108. *!*     cDirCom = "fpserver715" + "\impred.exe"
  6109. *!*     cDirCom = Fullpath(cDirCom)
  6110. *!* && Mato el proceso del spooler y lo vuelvo a cargar
  6111. *!*     This.killprocessbyname("impred.exe")
  6112. *!*     This.killprocessbyname("wspooler.exe")
  6113. *!*     oShell = Createobject("Shell.Application")
  6114. *!*     oShell.ShellExecute (cDirCom)
  6115. Else
  6116. &&aca envio a la 320
  6117.     If lImpreFiscal
  6118.         mtXt = Alltrim(impfis.dircofactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  6119.         maNs = Alltrim(impfis.dirrefactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  6120.     Else
  6121.         mtXt = Alltrim(parametr.dirco)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  6122.         maNs = Alltrim(parametr.dirre)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  6123.     Endif
  6124. Endif
  6125.  
  6126.  
  6127. Select("comando")
  6128. Goto Top
  6129. &&en caso de que tenga un archivo en la cola de impresion de la impresora
  6130. &&no se deja imprimir
  6131. *Browse
  6132. If File(mtXt)
  6133.     Messagebox("ATENCION: Ud. ya tiene un Documento en Cola de Impresión"+Chr(10)+Chr(13)+;
  6134.         " AGUARDE a que el mismo sea impreso o elimínelo luego vuelva a intentar")
  6135.     Return This.TodoOK
  6136. Else
  6137.     Copy To &mtXt Sdf
  6138.     If File(maNs)
  6139.         Erase &maNs
  6140.     Endif
  6141.     If File(Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  6142.         Erase (Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  6143.     Endif
  6144.     Wait Windows 'Esperando Respuesta del Controlador Fiscal...' Nowait
  6145.     fd = -1
  6146.     intentos =1
  6147.     Do While fd < 0 .And. Lastkey() != 27
  6148.         fd = Fopen(maNs, 0)
  6149.         This.LeerSpooler("T")
  6150.         If intentos = 30
  6151.             Messagebox("ATENCION: Verifique que el Controlador Esté Conectado y Encendido. " + Chr(10) + Chr(13)+ ;
  6152.                 "Verifique además que el Programa Spooler se esté ejecutando " + Chr(10) + Chr(13)+ ;
  6153.                 "en el equipo al cual se encuentra conectado el Controlador Fiscal")
  6154.             This.LeerSpooler("T")
  6155.         Endif
  6156.         If intentos = 70
  6157.             Messagebox("ATENCION: Tiempo de Espera Agotado !!! Presione ESC. para cancelar este Comprobante")
  6158.             This.LeerSpooler("T")
  6159.         Endif
  6160.         intentos = intentos + 1
  6161. *For i=1 To 100
  6162. *Next
  6163.         Inkey(1)
  6164.         If Lastkey() = 27
  6165.             If Substr(comando.comando,17,16) = "Impresor Ocupado"
  6166.                 Messagebox("ATENCION: No se aconseja cancelar este documento por programa, "+;
  6167.                     CHR(10)+Chr(13)+"La impresora ya lo ha procesado y saldrá impreso"+;
  6168.                     CHR(10)+Chr(13)+ "una vez que esta se ponga en linea")
  6169.             Endif
  6170.             If Messagebox("ATENCION: Realmente desea Cancelar la Emisión de este Documento??",4+256) = 6
  6171.                 Messagebox(" Se proceder  a Cancelar el Documento por Sistema"+;
  6172.                     CHR(10)+Chr(13)+" Verifique que la impresora también lo haya Cancelado.")
  6173.                 Keyboard '{ESC}'
  6174.             Else
  6175.                 Keyboard ""
  6176.             Endif
  6177.         Endif
  6178.     Enddo
  6179.     If Lastkey() = 27.Or. fd < 0
  6180.         If File(mtXt)
  6181.             Erase &mtXt
  6182.         Endif
  6183.         fd = Fopen((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"), 0)
  6184.         If fd < 0
  6185.             Messagebox("Operación Cancelada: ERROR de comunicaciones con el Controlador.; Probablemente no se este ejecutando Spooler. ")
  6186.         Else
  6187.             fd =Fclose(fd)
  6188.             This.LeerSpooler("T")
  6189.         Endif
  6190.     Else
  6191.         fd = Fclose(fd)
  6192.         Select("comando")
  6193.         Zap
  6194.         Append From &maNs Sdf
  6195.         Goto Bottom
  6196.         This.numero = Val(Substr(comando.comando,35,8))
  6197.         If This.numero <> 0
  6198.             SQLExec(goApp.nCon, "select * from puntero where sucursal=?param.sucursal","puntero")
  6199.             If This.Ticket = "S"
  6200.                 If This.MasDeMil
  6201.                     This.numero = Val('0009'+strzero(This.numero,8))
  6202.                 Else
  6203.                     If lImpreFiscal
  6204.                         This.numero = Val(impfis.PtoVtaTicket+strzero(This.numero,8))
  6205.                     Else
  6206.                         If Param.sucursal=0
  6207.                             If File("c:\0009.txt")
  6208.                                 This.numero = Val(strzero(9,4)+strzero(This.numero,8))
  6209.                             Else
  6210.                                 This.numero = Val(strzero(puntero.pvta_tic,4)+strzero(This.numero,8))
  6211.                             Endif
  6212.                         Else
  6213.                             If Param.sucursal = 1
  6214.                                 This.numero = Val(strzero(8,4)+strzero(This.numero,8))
  6215.                             Endif
  6216.                         Endif
  6217.                     Endif
  6218.                 Endif
  6219.             Else
  6220.                 If lImpreFiscal
  6221.                     This.numero = Val(impfis.PtoVtaFac+strzero(This.numero,8))
  6222.                 Else
  6223.                     This.numero = Val(strzero(puntero.pvta_fac,4)+strzero(This.numero,8))
  6224.                 Endif
  6225.             Endif
  6226.             This.TodoOK = .T.
  6227.         Endif
  6228.     Endif
  6229.     If File((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"))
  6230.         Erase Alltrim(paramfac.dirpa)+"SPOOLER.LOG"
  6231.     Endif
  6232. Endif
  6233. *This.killprocessbyname("impred.exe")
  6234. *This.killprocessbyname("wspooler.exe")
  6235.  
  6236. Set Talk &cTalk
  6237. Return This.Todo
  6238. *!*     unitario n(12,2), costo n(12,2), montoiva n(12,2), montodgr n(12,2), montomuni N(12,2),;
  6239. *!*     poriva n(12,2), tipoiva c(2))  
  6240.     If det.unitario != 0
  6241.         If This.clase = "A"
  6242.             If This.Ticket = "S"
  6243.                 Insert Into comando;
  6244.                     VALUES ("A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  6245.                 Insert Into comando;
  6246.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + Se +;
  6247.                     ALLTRIM(Str(det.cantidad,6,2)+"0")+ Se +;
  6248.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  6249.                     ALLTRIM(Str(det.poriva,5,2)) + Se +;
  6250.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  6251.             Else
  6252.                 Insert Into comando;
  6253.                     VALUES ("B" + Se + det.unidad +" "+det.detalle+ Se + ;
  6254.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  6255.                     Alltrim(Str(det.unitario,13,2)) + ;
  6256.                     Se +Alltrim(Str(det.poriva,5,2)) + Se + ;
  6257.                     "M" + Se + "0" + Se + "" + Se + "T")
  6258.  
  6259.             Endif
  6260.         Else
  6261.             If This.Ticket = "S"
  6262.                 Insert Into comando;
  6263.                     VALUES ( "A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  6264.                 Insert Into comando;
  6265.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + ;
  6266.                     Se +Alltrim(Str(det.cantidad,6,2)+"0")+ Se + ;
  6267.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  6268.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  6269.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  6270.             Else
  6271.                 Insert Into comando;
  6272.                     VALUES ("B" + Se + det.unidad+" "+det.detalle+ Se +;
  6273.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  6274.                     ALLTRIM(Str(det.unitario,13,2)) + Se +;
  6275.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  6276.                     "M" + Se + "0" + Se + "" + Se + "T")
  6277.             Endif
  6278.         Endif
  6279.     Endif
  6280.     Select("det")
  6281.     Skip
  6282. Enddo
  6283.  
  6284.  
  6285. If This.condicion <> "C"
  6286.     If This.Ticket = "S"
  6287.         If This.contado = "S"
  6288.             Insert Into comando;
  6289.                 VALUES (Chr(68)+ Se + Substr(formapago.detalle,1,30)+ Se + ;
  6290.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  6291.         Else
  6292.             Insert Into comando;
  6293.                 VALUES ( Chr(68)+ Se + Substr(formapago.detalle,1,30)+ ;
  6294.                 Se + Alltrim(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  6295.         Endif
  6296.     Else
  6297.         If This.contado = "S"
  6298.             Insert Into comando;
  6299.                 VALUES (Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  6300.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  6301.         Else
  6302.             Insert Into comando;
  6303.                 VALUES(Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  6304.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  6305.         Endif
  6306.     Endif
  6307. Endif
  6308.  
  6309. If This.condicion <> "C"
  6310.     Insert Into comando;
  6311.         VALUES (Chr(69))
  6312. Else
  6313.     Insert Into comando;
  6314.         VALUES ( Chr(129) )
  6315. Endif
  6316.  
  6317.  
  6318. &&en esta parte copio el archivo con los comandos a la carpeta desde el cual
  6319. &&el spooler de impresion lee el archivo
  6320. If This.Ticket ="S"
  6321. && si es ticket me fijo a cual impresora debo enviar
  6322.     If lImpreFiscal
  6323.         mtXt = Alltrim(impfis.dircoticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  6324.         maNs = Alltrim(impfis.dirreticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  6325.     Else
  6326.         mtXt = Alltrim(parametr.dirco)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  6327.         maNs = Alltrim(parametr.dirre)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  6328.     Endif
  6329. *!*     cDirCom = "fpserver715" + "\impred.exe"
  6330. *!*     cDirCom = Fullpath(cDirCom)
  6331. *!* && Mato el proceso del spooler y lo vuelvo a cargar
  6332. *!*     This.killprocessbyname("impred.exe")
  6333. *!*     This.killprocessbyname("wspooler.exe")
  6334. *!*     oShell = Createobject("Shell.Application")
  6335. *!*     oShell.ShellExecute (cDirCom)
  6336. Else
  6337. &&aca envio a la 320
  6338.     If lImpreFiscal
  6339.         mtXt = Alltrim(impfis.dircofactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  6340.         maNs = Alltrim(impfis.dirrefactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  6341.     Else
  6342.         mtXt = Alltrim(parametr.dirco)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  6343.         maNs = Alltrim(parametr.dirre)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  6344.     Endif
  6345. Endif
  6346.  
  6347.  
  6348. Select("comando")
  6349. Goto Top
  6350. &&en caso de que tenga un archivo en la cola de impresion de la impresora
  6351. &&no se deja imprimir
  6352. *Browse
  6353. If File(mtXt)
  6354.     Messagebox("ATENCION: Ud. ya tiene un Documento en Cola de Impresión"+Chr(10)+Chr(13)+;
  6355.         " AGUARDE a que el mismo sea impreso o elimínelo luego vuelva a intentar")
  6356.     Return This.TodoOK
  6357. Else
  6358.     Copy To &mtXt Sdf
  6359.     If File(maNs)
  6360.         Erase &maNs
  6361.     Endif
  6362.     If File(Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  6363.         Erase (Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  6364.     Endif
  6365.     Wait Windows 'Esperando Respuesta del Controlador Fiscal...' Nowait
  6366.     fd = -1
  6367.     intentos =1
  6368.     Do While fd < 0 .And. Lastkey() != 27
  6369.         fd = Fopen(maNs, 0)
  6370.         This.LeerSpooler("T")
  6371.         If intentos = 30
  6372.             Messagebox("ATENCION: Verifique que el Controlador Esté Conectado y Encendido. " + Chr(10) + Chr(13)+ ;
  6373.                 "Verifique además que el Programa Spooler se esté ejecutando " + Chr(10) + Chr(13)+ ;
  6374.                 "en el equipo al cual se encuentra conectado el Controlador Fiscal")
  6375.             This.LeerSpooler("T")
  6376.         Endif
  6377.         If intentos = 70
  6378.             Messagebox("ATENCION: Tiempo de Espera Agotado !!! Presione ESC. para cancelar este Comprobante")
  6379.             This.LeerSpooler("T")
  6380.         Endif
  6381.         intentos = intentos + 1
  6382. *For i=1 To 100
  6383. *Next
  6384.         Inkey(1)
  6385.         If Lastkey() = 27
  6386.             If Substr(comando.comando,17,16) = "Impresor Ocupado"
  6387.                 Messagebox("ATENCION: No se aconseja cancelar este documento por programa, "+;
  6388.                     CHR(10)+Chr(13)+"La impresora ya lo ha procesado y saldrá impreso"+;
  6389.                     CHR(10)+Chr(13)+ "una vez que esta se ponga en linea")
  6390.             Endif
  6391.             If Messagebox("ATENCION: Realmente desea Cancelar la Emisión de este Documento??",4+256) = 6
  6392.                 Messagebox(" Se proceder  a Cancelar el Documento por Sistema"+;
  6393.                     CHR(10)+Chr(13)+" Verifique que la impresora también lo haya Cancelado.")
  6394.                 Keyboard '{ESC}'
  6395.             Else
  6396.                 Keyboard ""
  6397.             Endif
  6398.         Endif
  6399.     Enddo
  6400.     If Lastkey() = 27.Or. fd < 0
  6401.         If File(mtXt)
  6402.             Erase &mtXt
  6403.         Endif
  6404.         fd = Fopen((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"), 0)
  6405.         If fd < 0
  6406.             Messagebox("Operación Cancelada: ERROR de comunicaciones con el Controlador.; Probablemente no se este ejecutando Spooler. ")
  6407.         Else
  6408.             fd =Fclose(fd)
  6409.             This.LeerSpooler("T")
  6410.         Endif
  6411.     Else
  6412.         fd = Fclose(fd)
  6413.         Select("comando")
  6414.         Zap
  6415.         Append From &maNs Sdf
  6416.         Goto Bottom
  6417.         This.numero = Val(Substr(comando.comando,35,8))
  6418.         If This.numero <> 0
  6419.             SQLExec(goApp.nCon, "select * from puntero where sucursal=?param.sucursal","puntero")
  6420.             If This.Ticket = "S"
  6421.                 If This.MasDeMil
  6422.                     This.numero = Val('0009'+strzero(This.numero,8))
  6423.                 Else
  6424.                     If lImpreFiscal
  6425.                         This.numero = Val(impfis.PtoVtaTicket+strzero(This.numero,8))
  6426.                     Else
  6427.                         If Param.sucursal=0
  6428.                             If File("c:\0009.txt")
  6429.                                 This.numero = Val(strzero(9,4)+strzero(This.numero,8))
  6430.                             Else
  6431.                                 This.numero = Val(strzero(puntero.pvta_tic,4)+strzero(This.numero,8))
  6432.                             Endif
  6433.                         Else
  6434.                             If Param.sucursal = 1
  6435.                                 This.numero = Val(strzero(8,4)+strzero(This.numero,8))
  6436.                             Endif
  6437.                         Endif
  6438.                     Endif
  6439.                 Endif
  6440.             Else
  6441.                 If lImpreFiscal
  6442.                     This.numero = Val(impfis.PtoVtaFac+strzero(This.numero,8))
  6443.                 Else
  6444.                     This.numero = Val(strzero(puntero.pvta_fac,4)+strzero(This.numero,8))
  6445.                 Endif
  6446.             Endif
  6447.             This.TodoOK = .T.
  6448.         Endif
  6449.     Endif
  6450.     If File((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"))
  6451.         Erase Alltrim(paramfac.dirpa)+"SPOOLER.LOG"
  6452.     Endif
  6453. Endif
  6454. *This.killprocessbyname("impred.exe")
  6455. *This.killprocessbyname("wspooler.exe")
  6456.  
  6457. Set Talk &cTalk
  6458. Return This.Todo
  6459. *!*     poriva n(12,2), tipoiva c(2))  
  6460.     If det.unitario != 0
  6461.         If This.clase = "A"
  6462.             If This.Ticket = "S"
  6463.                 Insert Into comando;
  6464.                     VALUES ("A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  6465.                 Insert Into comando;
  6466.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + Se +;
  6467.                     ALLTRIM(Str(det.cantidad,6,2)+"0")+ Se +;
  6468.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  6469.                     ALLTRIM(Str(det.poriva,5,2)) + Se +;
  6470.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  6471.             Else
  6472.                 Insert Into comando;
  6473.                     VALUES ("B" + Se + det.unidad +" "+det.detalle+ Se + ;
  6474.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  6475.                     Alltrim(Str(det.unitario,13,2)) + ;
  6476.                     Se +Alltrim(Str(det.poriva,5,2)) + Se + ;
  6477.                     "M" + Se + "0" + Se + "" + Se + "T")
  6478.  
  6479.             Endif
  6480.         Else
  6481.             If This.Ticket = "S"
  6482.                 Insert Into comando;
  6483.                     VALUES ( "A" + Se + det.unidad +" "+Substr(det.detalle,1,19)+ Se + "0")
  6484.                 Insert Into comando;
  6485.                     VALUES ("B" + Se + Padr(Alltrim(Substr(det.detalle,20,20)),20,".") + ;
  6486.                     Se +Alltrim(Str(det.cantidad,6,2)+"0")+ Se + ;
  6487.                     ALLTRIM(Str(det.unitario,9,2)) + Se + ;
  6488.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  6489.                     "M" + Se + "0.00" + Se + "0" + Se + "T")
  6490.             Else
  6491.                 Insert Into comando;
  6492.                     VALUES ("B" + Se + det.unidad+" "+det.detalle+ Se +;
  6493.                     ALLTRIM(Str(det.cantidad,11,2))+ Se + ;
  6494.                     ALLTRIM(Str(det.unitario,13,2)) + Se +;
  6495.                     ALLTRIM(Str(det.poriva,5,2)) + Se + ;
  6496.                     "M" + Se + "0" + Se + "" + Se + "T")
  6497.             Endif
  6498.         Endif
  6499.     Endif
  6500.     Select("det")
  6501.     Skip
  6502. Enddo
  6503.  
  6504.  
  6505. If This.condicion <> "C"
  6506.     If This.Ticket = "S"
  6507.         If This.contado = "S"
  6508.             Insert Into comando;
  6509.                 VALUES (Chr(68)+ Se + Substr(formapago.detalle,1,30)+ Se + ;
  6510.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  6511.         Else
  6512.             Insert Into comando;
  6513.                 VALUES ( Chr(68)+ Se + Substr(formapago.detalle,1,30)+ ;
  6514.                 Se + Alltrim(Str(ThisForm.Saldacontado.txtPago.Value,10,2))+ Se +"T"+ Se+"0")
  6515.         Endif
  6516.     Else
  6517.         If This.contado = "S"
  6518.             Insert Into comando;
  6519.                 VALUES (Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  6520.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  6521.         Else
  6522.             Insert Into comando;
  6523.                 VALUES(Chr(68)+ Se + Alltrim(formapago.detalle)+ Se + ;
  6524.                 ALLTRIM(Str(ThisForm.Saldacontado.txtPago.Value,12,2))+ Se +"T"+ Se+"0")
  6525.         Endif
  6526.     Endif
  6527. Endif
  6528.  
  6529. If This.condicion <> "C"
  6530.     Insert Into comando;
  6531.         VALUES (Chr(69))
  6532. Else
  6533.     Insert Into comando;
  6534.         VALUES ( Chr(129) )
  6535. Endif
  6536.  
  6537.  
  6538. &&en esta parte copio el archivo con los comandos a la carpeta desde el cual
  6539. &&el spooler de impresion lee el archivo
  6540. If This.Ticket ="S"
  6541. && si es ticket me fijo a cual impresora debo enviar
  6542.     If lImpreFiscal
  6543.         mtXt = Alltrim(impfis.dircoticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  6544.         maNs = Alltrim(impfis.dirreticket) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  6545.     Else
  6546.         mtXt = Alltrim(parametr.dirco)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  6547.         maNs = Alltrim(parametr.dirre)+"715\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  6548.     Endif
  6549. *!*     cDirCom = "fpserver715" + "\impred.exe"
  6550. *!*     cDirCom = Fullpath(cDirCom)
  6551. *!* && Mato el proceso del spooler y lo vuelvo a cargar
  6552. *!*     This.killprocessbyname("impred.exe")
  6553. *!*     This.killprocessbyname("wspooler.exe")
  6554. *!*     oShell = Createobject("Shell.Application")
  6555. *!*     oShell.ShellExecute (cDirCom)
  6556. Else
  6557. &&aca envio a la 320
  6558.     If lImpreFiscal
  6559.         mtXt = Alltrim(impfis.dircofactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  6560.         maNs = Alltrim(impfis.dirrefactura) + Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  6561.     Else
  6562.         mtXt = Alltrim(parametr.dirco)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".txt"
  6563.         maNs = Alltrim(parametr.dirre)+"320\"+Substr(Sys(0),1,At("#",Sys(0))-2)+".ans"
  6564.     Endif
  6565. Endif
  6566.  
  6567.  
  6568. Select("comando")
  6569. Goto Top
  6570. &&en caso de que tenga un archivo en la cola de impresion de la impresora
  6571. &&no se deja imprimir
  6572. *Browse
  6573. If File(mtXt)
  6574.     Messagebox("ATENCION: Ud. ya tiene un Documento en Cola de Impresión"+Chr(10)+Chr(13)+;
  6575.         " AGUARDE a que el mismo sea impreso o elimínelo luego vuelva a intentar")
  6576.     Return This.TodoOK
  6577. Else
  6578.     Copy To &mtXt Sdf
  6579.     If File(maNs)
  6580.         Erase &maNs
  6581.     Endif
  6582.     If File(Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  6583.         Erase (Alltrim(paramfac.dirpa)+"SPOOLER.LOG")
  6584.     Endif
  6585.     Wait Windows 'Esperando Respuesta del Controlador Fiscal...' Nowait
  6586.     fd = -1
  6587.     intentos =1
  6588.     Do While fd < 0 .And. Lastkey() != 27
  6589.         fd = Fopen(maNs, 0)
  6590.         This.LeerSpooler("T")
  6591.         If intentos = 30
  6592.             Messagebox("ATENCION: Verifique que el Controlador Esté Conectado y Encendido. " + Chr(10) + Chr(13)+ ;
  6593.                 "Verifique además que el Programa Spooler se esté ejecutando " + Chr(10) + Chr(13)+ ;
  6594.                 "en el equipo al cual se encuentra conectado el Controlador Fiscal")
  6595.             This.LeerSpooler("T")
  6596.         Endif
  6597.         If intentos = 70
  6598.             Messagebox("ATENCION: Tiempo de Espera Agotado !!! Presione ESC. para cancelar este Comprobante")
  6599.             This.LeerSpooler("T")
  6600.         Endif
  6601.         intentos = intentos + 1
  6602. *For i=1 To 100
  6603. *Next
  6604.         Inkey(1)
  6605.         If Lastkey() = 27
  6606.             If Substr(comando.comando,17,16) = "Impresor Ocupado"
  6607.                 Messagebox("ATENCION: No se aconseja cancelar este documento por programa, "+;
  6608.                     CHR(10)+Chr(13)+"La impresora ya lo ha procesado y saldrá impreso"+;
  6609.                     CHR(10)+Chr(13)+ "una vez que esta se ponga en linea")
  6610.             Endif
  6611.             If Messagebox("ATENCION: Realmente desea Cancelar la Emisión de este Documento??",4+256) = 6
  6612.                 Messagebox(" Se proceder  a Cancelar el Documento por Sistema"+;
  6613.                     CHR(10)+Chr(13)+" Verifique que la impresora también lo haya Cancelado.")
  6614.                 Keyboard '{ESC}'
  6615.             Else
  6616.                 Keyboard ""
  6617.             Endif
  6618.         Endif
  6619.     Enddo
  6620.     If Lastkey() = 27.Or. fd < 0
  6621.         If File(mtXt)
  6622.             Erase &mtXt
  6623.         Endif
  6624.         fd = Fopen((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"), 0)
  6625.         If fd < 0
  6626.             Messagebox("Operación Cancelada: ERROR de comunicaciones con el Controlador.; Probablemente no se este ejecutando Spooler. ")
  6627.         Else
  6628.             fd =Fclose(fd)
  6629.             This.LeerSpooler("T")
  6630.         Endif
  6631.     Else
  6632.         fd = Fclose(fd)
  6633.         Select("comando")
  6634.         Zap
  6635.         Append From &maNs Sdf
  6636.         Goto Bottom
  6637.         This.numero = Val(Substr(comando.comando,35,8))
  6638.         If This.numero <> 0
  6639.             SQLExec(goApp.nCon, "select * from puntero where sucursal=?param.sucursal","puntero")
  6640.             If This.Ticket = "S"
  6641.                 If This.MasDeMil
  6642.                     This.numero = Val('0009'+strzero(This.numero,8))
  6643.                 Else
  6644.                     If lImpreFiscal
  6645.                         This.numero = Val(impfis.PtoVtaTicket+strzero(This.numero,8))
  6646.                     Else
  6647.                         If Param.sucursal=0
  6648.                             If File("c:\0009.txt")
  6649.                                 This.numero = Val(strzero(9,4)+strzero(This.numero,8))
  6650.                             Else
  6651.                                 This.numero = Val(strzero(puntero.pvta_tic,4)+strzero(This.numero,8))
  6652.                             Endif
  6653.                         Else
  6654.                             If Param.sucursal = 1
  6655.                                 This.numero = Val(strzero(8,4)+strzero(This.numero,8))
  6656.                             Endif
  6657.                         Endif
  6658.                     Endif
  6659.                 Endif
  6660.             Else
  6661.                 If lImpreFiscal
  6662.                     This.numero = Val(impfis.PtoVtaFac+strzero(This.numero,8))
  6663.                 Else
  6664.                     This.numero = Val(strzero(puntero.pvta_fac,4)+strzero(This.numero,8))
  6665.                 Endif
  6666.             Endif
  6667.             This.TodoOK = .T.
  6668.         Endif
  6669.     Endif
  6670.     If File((Alltrim(paramfac.dirpa)+"SPOOLER.LOG"))
  6671.         Erase Alltrim(paramfac.dirpa)+"SPOOLER.LOG"
  6672.     Endif
  6673. Endif
  6674. *This.killprocessbyname("impred.exe")
  6675. *This.killprocessbyname("wspooler.exe")
  6676.  
  6677. Set Talk &cTalk
  6678. Return This.TodoOK
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement