CREATE VIEW VW_REPORTE_VENTA_CLIENTE_DOC AS
SELECT     s.doctypeid, dt.descr, dt.mindes, CASE LEFT(s.nbrdocument, 3) WHEN '102' THEN '002' + '-' + RIGHT(s.nbrdocument, 7) 
                      ELSE RIGHT('000' + LEFT(RIGHT(s.nbrdocument, 10), len(s.nbrdocument) - 7), 3) + '-' + RIGHT(s.nbrdocument, 7) END AS nro_documento, 
                      s.nbrdocument, s.datedoc, S.SUBTOTALPEN, S.SUBTOTALUSD, S.TAXIGVPEN, S.TAXIGVUSD, S.TOTALPEN, S.TOTALUSD, S.TAXREGNBR AS RUC, 
                      S.CUSTNAME AS CLIENTE
FROM         op_sales s(NOLOCK) INNER JOIN
                      doctype dt(NOLOCK) ON s.doctypeid = dt.doctypeid