diff --git a/detalleVenta.html b/detalleVenta.html index 8ec0b65..63f0998 100644 --- a/detalleVenta.html +++ b/detalleVenta.html @@ -23,16 +23,16 @@

detalle de venta

- +

Detalle venta diff --git a/foo.html b/foo.html new file mode 100644 index 0000000..30d74d2 --- /dev/null +++ b/foo.html @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/index.html b/index.html index b564897..4e13a4a 100644 --- a/index.html +++ b/index.html @@ -6,9 +6,15 @@ - + + + + + @@ -24,13 +30,13 @@

Ingreso a sistema Iworld

- +
- +
- +
- Atras

Tienda Mall Mirage

+ Atras

-

Total Ventas del dia:

-

Total Cajas del dia:

+ +

Total Ventas del dia:

+

Total Cajas del dia:


@@ -87,101 +91,70 @@

Footer

+
- Atras

Ventas Tienda Mall Mirage

+ Atras

+

-

-
- Atras

Ventas Tienda Mall Mirage

+ Atras

/h1>

-

+
- Atras

Boleta 174

eliminar + Atras

Eliminar
- - +

Detalle venta

- Forma de Pago: + Forma de Pago:
-
+
- Total: + Total:
- Vendedor + Vendedor:
@@ -189,34 +162,59 @@

Productos

-
    -
  • + + +
      +
-
- Atras

Caja 174

Eliminar + Atras

Eliminar

Content

+
- - - + +
+
+

Dialog

+
+
+

Eliminar ???

+
+
+ + + + + + + + + + + + + diff --git a/js/eventos.js b/js/eventos.js new file mode 100644 index 0000000..841465d --- /dev/null +++ b/js/eventos.js @@ -0,0 +1,272 @@ +$(document).ready(function(){ + + //location.href=""; + App.init(); + + $("#btnLogin").click(function(){ + App.recuperaToken(); + }); + +}); + + +App = { + token:"", + baseapiurl : "http://iworld.ingehost.cl", + nombreTienda :"", + tienda_id:"", + boleta_id:"", + caja_id:"", + tipoComprobante:{ + "1" :"boleta", + "2" :"factura" + }, + formaPago:{ + "1": "efectivo", + "2": "documento", + "3": "credito", + "4":"debito" + }, + estadoCaja:{ + "1": "abierta", + "2": "cerrada" + }, + + +init:function(){ + +}, +/** + * Obtener token de autentifcacion y cargar el HOME + */ +recuperaToken: function(){ + + var usuario = $("#nombre").val(); + var password = $("#password").val(); + + if(usuario == "" || password == ""){ + + alert("ingrese un nombre de usuario y password"); + + }else{ + $.ajax({ + url: App.baseapiurl +"/api-loggin/", + data: {username: usuario, password: password }, + type: 'post', + crossDomain: true, + dataType: 'json', + success: function(data) { + App.token = data.token; + location.href="#home"; + App.loadHome(); + }, + error: function() { + var token = ""; + alert("Error en la autentificación"); + }, + }); + } +}, +/** + * Cargar el HOME + * Uso de template UNDESCORE + */ +loadHome: function(){ + //Obtener la lista de las tiendas + $.ajax({ + url: App.baseapiurl + "/movil/tiendas", + type: 'GET', + dataType: 'json', + success: function(data) { + App.drawChart(); + var template = $("#template_listaTiendas").html(); + $("#listaTiendas").html(_.template(template,{items:data})).trigger('create'); + }, + error: function() { alert('error al cargar el home ( lista de tiendas) '); }, + beforeSend: App.setHeader + }); + + + //Cargar el total de ventas + $.ajax({ + url: App.baseapiurl + "/movil/totalventas", + type: 'GET', + dataType: 'json', + success: function(data) { + $("#totalVenta").html(data); + }, + error: function() { alert('error al cargar el total de ventas '); }, + beforeSend: App.setHeader + }); + + //Cargar el total de cajas + $.ajax({ + url: App.baseapiurl + "/movil/totalcaja", + type: 'GET', + dataType: 'json', + success: function(data) { + $("#totalCaja").html(data); + }, + error: function() { alert('error al cargar el total de ventas '); }, + beforeSend: App.setHeader + }); +}, + + +/** + * Cargar los datos de una tienda + * @constructor + * @param {string} title - The title of the book. + * @param {string} author - The author of the book. + */ +loadTienda: function(tienda_id,nombre){ + + $("#nombreTienda").text(nombre); + $.ajax({ + url: App.baseapiurl + "/movil/totalventastienda"+tienda_id, + type: 'GET', + dataType: 'json', + success: function(data) { + $("#detalleVentaDia").html(data); + }, + error: function() { alert('error al cargar la tienda '); }, + beforeSend: App.setHeader + }); + + $.ajax({ + url: App.baseapiurl + "/movil/totalcajatienda"+tienda_id, + type: 'GET', + dataType: 'json', + success: function(data) { + $("#detalleCajaDia").html(data); + }, + error: function() { alert('error al cargar el total de la caja '); }, + beforeSend: App.setHeader + }); + + App.tienda_id = tienda_id; + App.nombreTienda = nombre; + +}, +/** + * Cargar la lista de las Ventas + * @param {int} venta_id - El identificador de la venta + */ +getListadoVentas: function(){ + + $("#nombreVentaTienda").text("ventas "+ App.nombreTienda); + + + $.ajax({ + url: App.baseapiurl + "/movil/ventas/" +App.tienda_id, + type: 'GET', + dataType: 'json', + success: function(data) { + + + $("#listarVentas").html(""); + var lista = $("#listarVentas"); + $.each(data, function(i,item){ + + var html = "
  • " + App.tipoComprobante[item.tipoComprobante] +" "+ item.id + " - " + App.formaPago[item.formaPago] + " $ "+ item.total + "
  • "; + lista.append(html); + }) + lista.listview('refresh'); + + }, + error: function() { alert('error al cargar el loadListaVentas) '); }, + beforeSend: App.setHeader + }); +}, + +getListadoCajas:function(){ + + $("#nombreCajaTienda").text("Cajas "+ App.nombreTienda); + + $.ajax({ + url: App.baseapiurl + "/movil/caja/" +App.tienda_id, + type: 'GET', + dataType: 'json', + success: function(data) { + $("#listarCajas").html(""); + var lista = $("#listarCajas"); + $.each(data, function(i,item){ + var html = "
  • Caja " + item.id +" "+ App.estadoCaja[item.estado] +" $ "+ item.monto + "
  • "; + lista.append(html); + }) + lista.listview('refresh'); + + }, + error: function() { alert('error al cargar el loadListaVentas) '); }, + beforeSend: App.setHeader + }); + +}, + +getDetalleVenta: function(boleta_id){ + App.boleta_id = boleta_id; + $("#nombreBoleta").text("Boleta " +boleta_id); + + console.log("getDetalleVenta"); + $.ajax({ + url: App.baseapiurl + "/movil/detalleventa/"+boleta_id, + type: 'GET', + dataType: 'json', + success: function(data) { + $('#formaDePago').text(data.formaDePago); + $('#total').text(data.total); + $('#vendedor').text(data.vendedor); + + $.each(data.productos,function(i,item){ + $("#listarProductos").html(""); + var lista = $("#listarProductos"); + $.each(data.productos, function(i,item){ + console.log(item.codigo); + var html = "
  • " + item.codigo +" - "+ item.nombre +" ("+ item.cantidad+ ")
  • "; + lista.append(html); + }) + lista.listview('refresh'); + }); + + }, + error: function() { alert('no se puedo!'); }, + beforeSend: App.setHeader + }); +}, +getDetalleCaja: function(caja_id){ + App.caja_id = caja_id; + $("#nombreCaja").text("Caja " +caja_id); +}, + +logout:function(){ + App.token = "" +}, + + +setHeader : function(xhr){ + + xhr.setRequestHeader("Authorization", "Token "+ App.token); +}, +/** + * Graficar El detalle de venta (google chart) + */ +drawChart: function(){ + console.log("drawChart"); + var data = google.visualization.arrayToDataTable([ + ['Tienda', 'ventas'], + ['Temuco (Mall Mirage)', 1000 ], + ['Temuco (Centro)', 1170 ], + ['Puerto Montt (Costanera)', 660 ], + ]); + + var options = { + title: 'Ventas del dia por sucursal', + hAxis: {title: 'HOY', titleTextStyle: {color: 'red'}} + }; + + var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')); + chart.draw(data, options); + +}, + +}; \ No newline at end of file diff --git a/js/formateoVista.js b/js/formateoVista.js new file mode 100644 index 0000000..e69de29 diff --git a/js/jquery.mobile.router.min.js b/js/jquery.mobile.router.min.js new file mode 100644 index 0000000..ec9b821 --- /dev/null +++ b/js/jquery.mobile.router.min.js @@ -0,0 +1,10 @@ +/*! + * jQueryMobile-router v20130527 + * http://github.com/azicchetti/jquerymobile-router + * + * Copyright 2011-2013 (c) Andrea Zicchetti + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://github.com/azicchetti/jquerymobile-router/blob/master/MIT-LICENSE.txt + * http://github.com/azicchetti/jquerymobile-router/blob/master/GPL-LICENSE.txt + */ +(function(a,b){if(typeof define==="function"&&define.amd){define(["jquery"],b)}else{b(jQuery)}}(this,function(a){a(document).on("mobileinit",function(){var c=a.extend({fixFirstPageDataUrl:false,firstPageDataUrl:"index.html",ajaxApp:false,firstMatchOnly:false,defaultArgsRe:false},a.mobile.jqmRouter||{});var d=null,e=null,b=false;a(document).on("pagebeforechange",function(j,i){if(i.options.hasOwnProperty("_jqmrouter_handled")){return}var h;if(typeof i.toPage==="string"){h=i.toPage}else{h=i.toPage.jqmData("url")||"";if(i.toPage.attr("id")==h){h="#"+h}}i.options._jqmrouter_handled=true;if(i.options.data&&(i.options.type+"").toLowerCase()=="get"){h+="?"+i.options.data}var g=a.mobile.path.parseUrl(h);d=e;e=g;if(g.hash.indexOf("?")!=-1){i.options.dataUrl=g.hash.replace(/^#/,"")}var f=/^#|\?.*$/g;if(d&&g.hash!=d.hash&&g.hash.replace(f,"")==d.hash.replace(f,"")){i.options.allowSamePageTransition=true&&!b}b=false;if(window.location.hash.indexOf("&ui-state=dialog")!=-1){b=true}});if(c.fixFirstPageDataUrl){a(document).ready(function(){if(!window.location.pathname.match("/$")){return}var g=a(":jqmData(role='page')").first();var h=g.jqmData("url"),f=window.location.pathname+c.firstPageDataUrl+window.location.search+window.location.hash;if(h!=f){g.attr("data-url",f).jqmData("url",f)}})}a.mobile.Router=function(j,g,h){this.routes={pagebeforecreate:null,pagecreate:null,pagebeforeshow:null,pageshow:null,pagebeforehide:null,pagehide:null,pageinit:null,pageremove:null,pagebeforechange:null,pagebeforeload:null,pageload:null,popupbeforeposition:null,popupafteropen:null,popupafterclose:null};this.evtLookup={bC:"pagebeforechange",bl:"pagebeforeload",l:"pageload",bc:"pagebeforecreate",c:"pagecreate",bs:"pagebeforeshow",s:"pageshow",bh:"pagebeforehide",h:"pagehide",i:"pageinit",rm:"pageremove",pbp:"popupbeforeposition",pao:"popupafteropen",pac:"popupafterclose"};this.routesRex={};this.conf=a.extend({},c,h||{});this.defaultHandlerEvents={};if(this.conf.defaultHandlerEvents){var f=this.conf.defaultHandlerEvents.split(",");for(var k=0;k0){this._eventData={events:g.join(" "),selectors:":jqmData(role='page'),:jqmData(role='dialog')",handler:j};a(document).on(this._eventData.events,this._eventData.selectors,this._eventData.handler)}if(l.length>0){this._docEventData={events:l.join(" "),handler:j};a(document).on(this._docEventData.events,this._docEventData.handler)}},_processRoutes:function(k,o,l){var m=this,n,h,g=0,f=null;if(k.type=="pagebeforechange"){if(o.options._jqmrouter_bC){return}f={isString:typeof o.toPage==="string",deferred:a.Deferred(),toPage:o.toPage};l=!f.isString?o.toPage:null}if(k.type in {pagebeforehide:true,pagehide:true,pageremove:true}){n=d}else{n=e}h=!this.conf.ajaxApp?n.hash:(n.pathname+n.search+n.hash);if(h.length==0){n=null;if(!this.documentEvts[k.type]&&l){n=a(l).jqmData("url")}else{n=a.mobile.firstPage.jqmData("url")}if(n){n=a.mobile.path.parseUrl("#"+n);h=!this.conf.ajaxApp?n.hash:(n.pathname+n.search+n.hash)}}if(h.length==0){return}var j=false;a.each(this.routes[k.type],function(r,q){var s,u;if(f&&q.step!="all"){q.step=q.step||"page";if((f.isString&&q.step=="page")||(!f.isString&&q.step!="page")){return}}if((s=h.match(m.routesRex[r]))){if(typeof(q.handler)=="function"){u=q.handler}else{if(typeof(m.userHandlers[q.handler])=="function"){u=m.userHandlers[q.handler]}}if(u){try{if(f&&o){o.bCDeferred=f.deferred}u.apply(m.userHandlers,[k.type,s,o,l,k]);j=true}catch(t){m.debug(t)}}}if(j&&m.conf.firstMatchOnly){return false}});if(!j&&this.conf.defaultHandler&&this.defaultHandlerEvents[k.type]){var p;if(typeof(this.conf.defaultHandler)=="function"){p=this.conf.defaultHandler}else{if(typeof(this.userHandlers[this.conf.defaultHandler])=="function"){p=this.userHandlers[this.conf.defaultHandler]}}try{p.apply(this.userHandlers,[k.type,o,l,k])}catch(i){this.debug(i)}}if(f&&k.isDefaultPrevented()){f.deferred.done(function(){var q=(f.toPage===o.toPage?{_jqmrouter_handled:true,_jqmrouter_bC:true}:null);a.mobile.changePage(o.toPage,a.extend({allowSamePageTransition:o.options.allowSamePageTransition,changeHash:o.options.changeHash,data:o.options.data,dataUrl:o.options.dataUrl,pageContainer:o.options.pageContainer,reloadPage:o.options.reloadPage,reverse:o.options.reverse,role:o.options.role,showLoadMsg:o.options.showLoadMsg,transition:o.options.transition,type:o.options.type},q))})}},_detachEvents:function(){if(this._eventData){a(document).off(this._eventData.events,this._eventData.selectors,this._eventData.handler)}if(this._docEventData){a(document).off(this._docEventData.events,this._docEventData.handler)}},destroy:function(){this._detachEvents();this.routes=this.routesRex=null},getParams:function(f){if(!f){return null}var i={},g;var h=f.slice(f.indexOf("?")+1).split("&");a.each(h,function(l,j){g=j.split("=");g[0]=decodeURIComponent(g[0]);if(i[g[0]]){if(!(i[g[0]] instanceof Array)){i[g[0]]=[i[g[0]]]}i[g[0]].push(decodeURIComponent(g[1]))}else{i[g[0]]=decodeURIComponent(g[1])}});if(a.isEmptyObject(i)){return null}return i}})});return{}})); \ No newline at end of file diff --git a/js/router.js b/js/router.js new file mode 100644 index 0000000..2645fa3 --- /dev/null +++ b/js/router.js @@ -0,0 +1 @@ + var router=new $.mobile.Router(); \ No newline at end of file diff --git a/js/servicios.js b/js/servicios.js new file mode 100644 index 0000000..5dbf80b --- /dev/null +++ b/js/servicios.js @@ -0,0 +1,21 @@ +function getToken(usuario, password){ + + $.ajax({ + + url: 'http://iworld.ingehost.cl/api-loggin/', + data: {username: usuario, password: password }, + type: 'post', + crossDomain: true, + dataType: 'json', + success: function(data) { + console.log(data); + App.token = data.token; + return true; + }, + error: function() { + var token = ""; + return false; + }, + +}); +} \ No newline at end of file diff --git a/test.js b/test.js new file mode 100644 index 0000000..e69de29