text: !function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=52)}([function(e,t,n){"use strict";n.d(t,"w",(function(){return h})),n.d(t,"y",(function(){return x})),n.d(t,"q",(function(){return w})),n.d(t,"i",(function(){return S})),n.d(t,"t",(function(){return j})),n.d(t,"j",(function(){return V})),n.d(t,"C",(function(){return C})),n.d(t,"k",(function(){return k})),n.d(t,"p",(function(){return T})),n.d(t,"s",(function(){return O})),n.d(t,"l",(function(){return N})),n.d(t,"b",(function(){return I})),n.d(t,"u",(function(){return A})),n.d(t,"v",(function(){return R})),n.d(t,"B",(function(){return _})),n.d(t,"f",(function(){return P})),n.d(t,"x",(function(){return E})),n.d(t,"r",(function(){return G})),n.d(t,"n",(function(){return M})),n.d(t,"m",(function(){return q})),n.d(t,"a",(function(){return D})),n.d(t,"c",(function(){return L})),n.d(t,"d",(function(){return B})),n.d(t,"h",(function(){return U})),n.d(t,"g",(function(){return F})),n.d(t,"e",(function(){return z})),n.d(t,"o",(function(){return W})),n.d(t,"A",(function(){return K})),n.d(t,"z",(function(){return J}));var r=n(8),o=n.n(r),a=n(6),i=n.n(a),s=n(3),c=n.n(s),u=n(40),d=n.n(u),p=n(41),l=n.n(p),m=n(1),g=n(11);function f(e,t,n,r,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function y(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function i(e){f(a,r,o,i,s,"next",e)}function s(e){f(a,r,o,i,s,"throw",e)}i(void 0)}))}}var b=c.a.model("User",g.a),v=l.a.Strategy,h=d.a.use(new v({clientID:m.a.production.googleClientID,clientSecret:m.a.production.googleClientSecret,callbackURL:m.a.production.callBackUrl},(function(e,t,n,r){return r(null,n)}))),$=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=e.split(" ").join("");return e.startsWith("+")||(t="+51"+e.split(" ").join("")),t},x=function(){var e=y(regeneratorRuntime.mark((function e(t,n,r){var a,i,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,a=t.body.displayName.toLowerCase(),(i=new b(t.body)).celular=$(t.body.celular),i.username=a,e.next=7,o.a.hash(t.body.password,10);case 7:return i.hashPassword=e.sent,i.type="low",i.nombre=t.body.nombre.toUpperCase(),i.apellido=t.body.apellido.toUpperCase(),e.next=13,i.save();case 13:(s=e.sent).hashPassword=void 0,t.savedUSer=s,r(),e.next=22;break;case 19:return e.prev=19,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 22:case"end":return e.stop()}}),e,null,[[0,19]])})));return function(t,n,r){return e.apply(this,arguments)}}(),w=function(){var e=y(regeneratorRuntime.mark((function e(t,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.findById(t.body.idUser);case 3:if(!1!==e.sent.verified){e.next=6;break}return e.abrupt("return",n.json({reload:!1}));case 6:return e.abrupt("return",n.json({reload:!0}));case 9:return e.prev=9,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 12:case"end":return e.stop()}}),e,null,[[0,9]])})));return function(t,n){return e.apply(this,arguments)}}(),S=function(){var e=y(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.findById(t.params.idUser);case 3:if(!1!==(r=e.sent).verified){e.next=9;break}return o=i.a.sign({_id:r._id},m.a.production.jwtLogin,{expiresIn:"120s"}),e.next=8,b.findByIdAndUpdate(r._id,{verified:!0},{useFindAndModify:!1});case 8:return e.abrupt("return",n.redirect("".concat(m.a.production.link_front,"login/auto/").concat(o)));case 9:return e.abrupt("return",n.status(202).send("<h1>Este usuario ya esta verificado.</h1>"));case 12:return e.prev=12,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 15:case"end":return e.stop()}}),e,null,[[0,12]])})));return function(t,n){return e.apply(this,arguments)}}(),j=function(){var e=y(regeneratorRuntime.mark((function e(t,n,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i.a.verify(t.body.loginToken,m.a.production.jwtLogin,(function(e,o){if(e)return"TokenExpiredError"===e.name?n.status(400).json({error:"Token Expirado"}):n.status(500).json({error:e.message});t.logintoken=o,r()}));case 1:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),V=function(){var e=y(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.findById(t.logintoken._id);case 3:return r=e.sent,e.abrupt("return",n.json({displayName:r.displayName,username:r.username,success:!0,message:"Success",type:r.type,token:i.a.sign({aud:r.username+" "+r.type,_id:r.id},m.a.production.jwtKey)}));case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),C=function(){var e=y(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.exists({username:t.params.username.toLowerCase()});case 3:return r=e.sent,e.abrupt("return",n.json({exists:r}));case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),k=function(){var e=y(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.exists({email:t.params.email.toLowerCase()});case 3:return r=e.sent,e.abrupt("return",n.json({exists:r}));case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),T=function(){var e=y(regeneratorRuntime.mark((function e(t,n,r){var o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.exists({email:t.user._json.email});case 3:if(!e.sent){e.next=6;break}return e.abrupt("return",r());case 6:return o=i.a.sign(t.user._json,m.a.production.jwtGoogleLogin,{expiresIn:"30s"}),e.abrupt("return",n.redirect("".concat(m.a.production.link_front,"login/registro/").concat(o)));case 10:return e.prev=10,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 13:case"end":return e.stop()}}),e,null,[[0,10]])})));return function(t,n,r){return e.apply(this,arguments)}}(),O=function(){var e=y(regeneratorRuntime.mark((function e(t,n,r){var o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.findOneAndUpdate({email:t.user._json.email},{verified:!0},{new:!0,useFindAndModify:!1});case 3:return o=e.sent,a=i.a.sign({_id:o._id},m.a.production.jwtLogin,{expiresIn:"120s"}),e.next=7,b.findByIdAndUpdate(o._id,{verified:!0},{useFindAndModify:!1});case 7:return e.abrupt("return",n.redirect("".concat(m.a.production.link_front,"login/auto/").concat(a)));case 10:return e.prev=10,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 13:case"end":return e.stop()}}),e,null,[[0,10]])})));return function(t,n,r){return e.apply(this,arguments)}}(),N=function(){var e=y(regeneratorRuntime.mark((function e(t,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i.a.verify(t.body.loginToken,m.a.production.jwtGoogleLogin,(function(e,t){return e?"TokenExpiredError"===e.name?n.status(400).json({error:"Token Expirado"}):n.status(500).json({error:e.message}):n.json(t)}));case 1:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),I=function(e,t,n){if(!e.user||"admin"!==e.user.aud.split(" ")[1])return t.status(401).json({message:"Usuario No Autorizado"});n()},A=function(e,t,n){if(!e.user||"low"!==e.user.aud.split(" ")[1])return t.status(401).json({message:"Usuario No Autorizado"});n()},R=function(e,t,n){if(!e.user||"vent"!==e.user.aud.split(" ")[1]&&"admin"!==e.user.aud.split(" ")[1]&&"contador"!==e.user.aud.split(" ")[1])return t.status(401).json({message:"Usuario No Autorizado"});n()},_=function(e,t,n){if(!e.user||"vent"!==e.user.aud.split(" ")[1]&&"admin"!==e.user.aud.split(" ")[1])return t.status(401).json({message:"Usuario No Autorizado"});n()},P=function(e,t,n){if(!e.user)return t.status(401).json({message:"Usuario No Autorizado"});n()},E=function(){var e=y(regeneratorRuntime.mark((function e(t,n){var r,a,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r=t.body.username,(a=new b(t.body)).displayName=r,a.username=r.toLowerCase(),e.next=7,o.a.hash(t.body.password,10);case 7:return a.hashPassword=e.sent,e.next=10,a.save();case 10:return(i=e.sent).hashPassword=void 0,e.abrupt("return",n.json(i));case 15:return e.prev=15,e.t0=e.catch(0),e.abrupt("return",n.status(e.t0.status||400).send({message:e.t0}));case 18:case"end":return e.stop()}}),e,null,[[0,15]])})));return function(t,n){return e.apply(this,arguments)}}(),G=function(){var e=y(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.findOne({username:t.body.username.toLowerCase()});case 3:if(r=e.sent){e.next=6;break}return e.abrupt("return",n.status(400).json({username:t.body.username,success:!1,message:"Authenticacion failed. No user found!",token:null}));case 6:return e.next=8,r.comparePassword(t.body.password,r.hashPassword);case 8:if(e.sent){e.next=12;break}return e.abrupt("return",n.status(400).json({username:t.body.username,success:!1,message:"Authenticacion failed. Incorrect Password!",token:null}));case 12:return e.abrupt("return",n.json({displayName:r.displayName,username:r.username,success:!0,message:"Success",type:r.type,token:i.a.sign({aud:r.username+" "+r.type,_id:r.id},m.a.production.jwtKey)}));case 13:e.next=18;break;case 15:throw e.prev=15,e.t0=e.catch(0),e.t0;case 18:case"end":return e.stop()}}),e,null,[[0,15]])})));return function(t,n){return e.apply(this,arguments)}}(),M=function(){var e=y(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.findOne({username:t.params.username.toLowerCase()});case 3:(r=e.sent).hashPassword=void 0,n.json(r),e.next=11;break;case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 11:case"end":return e.stop()}}),e,null,[[0,8]])})));return function(t,n){return e.apply(this,arguments)}}(),q=function(){var e=y(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.findOne({username:t.user.aud.split(" ")[0]});case 3:(r=e.sent).hashPassword=void 0,n.json(r),e.next=11;break;case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 11:case"end":return e.stop()}}),e,null,[[0,8]])})));return function(t,n){return e.apply(this,arguments)}}(),D=function(){var e=y(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.findOneAndUpdate({_id:t.body.id},{celular:$(t.body.celular)},{useFindAndModify:!1,new:!0});case 3:(r=e.sent).hashPassword=void 0,n.json(r),e.next=11;break;case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 11:case"end":return e.stop()}}),e,null,[[0,8]])})));return function(t,n){return e.apply(this,arguments)}}(),L=function(){var e=y(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.findOneAndUpdate({_id:t.body.id},{dirOne:t.body.dirOne,dirTwo:t.body.dirTwo||"",reference:t.body.reference,city:"Trujillo, La Libertad. Perú"},{useFindAndModify:!1,new:!0});case 3:(r=e.sent).hashPassword=void 0,n.json(r),e.next=11;break;case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 11:case"end":return e.stop()}}),e,null,[[0,8]])})));return function(t,n){return e.apply(this,arguments)}}(),B=function(){var e=y(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.findOneAndUpdate({_id:t.body.id},{documento:t.body.documento,tipoPersona:t.body.tipoPersona},{useFindAndModify:!1,new:!0});case 3:(r=e.sent).hashPassword=void 0,n.json(r),e.next=11;break;case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 11:case"end":return e.stop()}}),e,null,[[0,8]])})));return function(t,n){return e.apply(this,arguments)}}(),U=function(){var e=y(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.findById(t.body.id);case 3:return r=e.sent,e.next=6,r.comparePassword(t.body.oldPassword,r.hashPassword);case 6:if(e.sent){e.next=8;break}return e.abrupt("return",n.json({valid:!1}));case 8:n.json({valid:!0}),e.next=14;break;case 11:return e.prev=11,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 14:case"end":return e.stop()}}),e,null,[[0,11]])})));return function(t,n){return e.apply(this,arguments)}}(),F=function(){var e=y(regeneratorRuntime.mark((function e(t,n){var r,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.findById(t.body.id);case 3:return r=e.sent,e.next=6,r.comparePassword(t.body.passwordOld,r.hashPassword);case 6:if(e.sent){e.next=8;break}return e.abrupt("return",n.json({changed:!1}));case 8:return e.next=10,o.a.hash(t.body.password,10);case 10:return a=e.sent,e.next=13,b.findByIdAndUpdate(t.body.id,{hashPassword:a},{new:!0,useFindAndModify:!1});case 13:return e.abrupt("return",n.json({changed:!0}));case 16:return e.prev=16,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 19:case"end":return e.stop()}}),e,null,[[0,16]])})));return function(t,n){return e.apply(this,arguments)}}(),z=function(){var e=y(regeneratorRuntime.mark((function e(t,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.findOneAndUpdate({username:t.user.aud.split(" ")[0]},{$push:{ventaActiva:t.saveResult.codigo}},{useFindAndModify:!1});case 3:n.json({message:"Venta generada con el codigo: ".concat(t.saveResult.codigo),venta:t.saveResult}),e.next=9;break;case 6:return e.prev=6,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 9:case"end":return e.stop()}}),e,null,[[0,6]])})));return function(t,n){return e.apply(this,arguments)}}(),W=function(){var e=y(regeneratorRuntime.mark((function e(t,n,r){var o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.findOne({username:t.user.aud.split(" ")[0]});case 3:o=e.sent,n.json(o.ventaActiva),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n,r){return e.apply(this,arguments)}}(),K=function(){var e=y(regeneratorRuntime.mark((function e(t,n,r){var o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,b.findOne({username:t.user.aud.split(" ")[0]});case 3:if(!((o=e.sent).ventaActiva.lenght>4)){e.next=6;break}return e.abrupt("return",n.status(409).json({message:"Ya tienes 5 ventas activas."}));case 6:t.ventaCod=o.ventaActiva,r(),e.next=13;break;case 10:return e.prev=10,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 13:case"end":return e.stop()}}),e,null,[[0,10]])})));return function(t,n,r){return e.apply(this,arguments)}}(),J=function(){var e=y(regeneratorRuntime.mark((function e(t,n,r){var a,s,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,a=t.body.displayName.toLowerCase(),(s=new b(t.body)).celular=$(t.body.celular),s.username=a,e.next=7,o.a.hash(t.body.password,10);case 7:return s.hashPassword=e.sent,s.type="low",s.nombre=t.body.nombre.toUpperCase(),s.apellido=t.body.apellido.toUpperCase(),s.verified=!0,e.next=14,s.save();case 14:return(c=e.sent).hashPassword=void 0,e.abrupt("return",n.json({displayName:c.displayName,username:c.username,success:!0,message:"Success",type:c.type,token:i.a.sign({aud:c.username+" "+c.type,_id:c.id},m.a.production.jwtKey)}));case 19:return e.prev=19,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 22:case"end":return e.stop()}}),e,null,[[0,19]])})));return function(t,n,r){return e.apply(this,arguments)}}()},function(e,t,n){"use strict";var r=n(32),o=n.n(r),a=n(25);n(29).config();var i=a.name,s=a.version,c=function(e,t,n){return o.a.createLogger({name:"".concat(e,":").concat(t),level:n})},u={development:{PORT:process.env.PORT,mongoKey:process.env.MONGO_KEY,tinyKey:process.env.TINY_KEY,jwtKey:process.env.JWT_KEY,jwtLogin:process.env.JWT_LOGIN,jwtGoogleLogin:process.env.JWT_GOOGLE_LOGIN,awsID:process.env.AWS_ID,awsKey:process.env.AWS_KEY,bucket:process.env.S3_BUCKET,sunatToken:process.env.SUNAT_TOKEN,googleClientID:process.env.GOOGLE_CLIENT_ID,googleClientSecret:process.env.GOOGLE_CLIENT_SECRET,callBackUrl:process.env.CALLBACK_URL_TEST,BHOST:process.env.HOST_SENDIBLUE,BPORT:process.env.PORT_SENDIBLUE,BUSER:process.env.USER_SENDIBLUE,BPASS:process.env.PASSWORD_SENDIBLUE,nbfToken:process.env.NBF_TOKEN,reToken:process.env.RE_TOKEN,emailFrom:"loginmanager@siriodinar.com",version:s,link:"http://localhost:5000/",link_front:"http://localhost:4000/",origin:["http://localhost:4200","http://localhost:4000"],log:function(){return c(i,s,"debug")}},production:{PORT:process.env.PORT,mongoKey:process.env.MONGO_KEY,tinyKey:process.env.TINY_KEY,jwtKey:process.env.JWT_KEY,jwtLogin:process.env.JWT_LOGIN,jwtGoogleLogin:process.env.JWT_GOOGLE_LOGIN,awsID:process.env.AWS_ID,awsKey:process.env.AWS_KEY,bucket:process.env.S3_BUCKET,sunatToken:process.env.SUNAT_TOKEN,googleClientID:process.env.GOOGLE_CLIENT_ID,googleClientSecret:process.env.GOOGLE_CLIENT_SECRET,callBackUrl:process.env.CALLBACK_URL,BHOST:process.env.HOST_SENDIBLUE,BPORT:process.env.PORT_SENDIBLUE,BUSER:process.env.USER_SENDIBLUE,BPASS:process.env.PASSWORD_SENDIBLUE,nbfToken:process.env.NBF_TOKEN,reToken:process.env.RE_TOKEN,version:s,emailFrom:"loginmanager@siriodinar.com",link:"https://inventario-sirio-dinar.herokuapp.com/",link_front:"https://inventario.siriodinar.com/",origin:["https://inventario.siriodinar.com","https://sirio-inventario-front.herokuapp.com"],log:function(){return c(i,s,"debug")}}};t.a=u},function(e,t,n){"use strict";n.d(t,"p",(function(){return O})),n.d(t,"q",(function(){return N})),n.d(t,"E",(function(){return I})),n.d(t,"K",(function(){return A})),n.d(t,"S",(function(){return R})),n.d(t,"C",(function(){return _})),n.d(t,"D",(function(){return E})),n.d(t,"N",(function(){return G})),n.d(t,"g",(function(){return M})),n.d(t,"t",(function(){return q})),n.d(t,"X",(function(){return D})),n.d(t,"Z",(function(){return L})),n.d(t,"Y",(function(){return B})),n.d(t,"W",(function(){return U})),n.d(t,"c",(function(){return F})),n.d(t,"h",(function(){return W})),n.d(t,"T",(function(){return K})),n.d(t,"f",(function(){return J})),n.d(t,"o",(function(){return H})),n.d(t,"M",(function(){return Y})),n.d(t,"d",(function(){return Q})),n.d(t,"x",(function(){return Z})),n.d(t,"n",(function(){return X})),n.d(t,"I",(function(){return ee})),n.d(t,"e",(function(){return te})),n.d(t,"u",(function(){return re})),n.d(t,"j",(function(){return oe})),n.d(t,"k",(function(){return ae})),n.d(t,"v",(function(){return ie})),n.d(t,"w",(function(){return se})),n.d(t,"B",(function(){return ce})),n.d(t,"U",(function(){return ue})),n.d(t,"m",(function(){return de})),n.d(t,"V",(function(){return pe})),n.d(t,"i",(function(){return me})),n.d(t,"r",(function(){return ge})),n.d(t,"P",(function(){return fe})),n.d(t,"O",(function(){return ye})),n.d(t,"Q",(function(){return be})),n.d(t,"J",(function(){return ve})),n.d(t,"s",(function(){return he})),n.d(t,"A",(function(){return $e})),n.d(t,"G",(function(){return xe})),n.d(t,"y",(function(){return we})),n.d(t,"l",(function(){return Se})),n.d(t,"a",(function(){return je})),n.d(t,"R",(function(){return Ve})),n.d(t,"F",(function(){return Ce})),n.d(t,"H",(function(){return ke})),n.d(t,"z",(function(){return Te})),n.d(t,"ab",(function(){return Oe})),n.d(t,"L",(function(){return Ne})),n.d(t,"b",(function(){return Ie}));var r=n(3),o=n.n(r),a=n(9),i=n(15),s=n.n(i);function c(e,t,n,r,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}var u=function(){var e,t=(e=regeneratorRuntime.mark((function e(t){var n,r,o,a,i,c,u,g;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,n=new s.a.Workbook,r={sheetFormat:{defaultRowHeight:20,defaultColWidth:20}},o=n.addWorksheet("Gastos",r),a=n.addWorksheet("Ventas",r),i=n.addWorksheet("Balance",r),c=n.createStyle({font:{color:"black",size:12},border:{right:{style:"thin",color:"white"},left:{style:"thin",color:"white"},bottom:{style:"thin",color:"white"}},alignment:{vertical:"center"},numberFormat:"[$S/-es-PE]#,##0.00"}),u=n.createStyle({font:{color:"black",size:12},border:{right:{style:"thin",color:"white"},left:{style:"thin",color:"white"},bottom:{style:"thin",color:"white"}},alignment:{vertical:"center"},numberFormat:"[$S/-es-PE]#,##0.00",fill:{type:"pattern",patternType:"solid",fgColor:"#e2f3ff"}}),o.row(2).setHeight(40),o.column(1).setWidth(10),o.column(5).setWidth(60),a.row(2).setHeight(40),a.column(1).setWidth(10),a.column(5).setWidth(60),i.row(2).setHeight(40),i.column(1).setWidth(10),i.column(5).setWidth(60),d(n,o,a,i,t.name),p(n,o,a),l(o,t,5,c,u,0),m(a,t,5,c,u,0),e.next=23,n.writeToBuffer();case 23:return g=e.sent,e.abrupt("return",g);case 27:throw e.prev=27,e.t0=e.catch(0),new Error(e.t0);case 30:case"end":return e.stop()}}),e,null,[[0,27]])})),function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function i(e){c(a,r,o,i,s,"next",e)}function s(e){c(a,r,o,i,s,"throw",e)}i(void 0)}))});return function(e){return t.apply(this,arguments)}}(),d=function(e,t,n,r,o){var a=e.createStyle({font:{color:"white",size:16,bold:!0},alignment:{horizontal:"center",vertical:"center"},fill:{type:"pattern",patternType:"solid",fgColor:"#005087"}});t.cell(2,2,2,6,!0).string("Gastos | ".concat(o)).style(a),n.cell(2,2,2,6,!0).string("Ganancias | ".concat(o)).style(a),r.cell(2,2,2,6,!0).string("Balance | ".concat(o)).style(a),t.row(3).setHeight(10),n.row(3).setHeight(10),r.row(3).setHeight(10)},p=function(e,t,n){for(var r=e.createStyle({font:{color:"white",size:14},border:{right:{style:"thin",color:"white"},left:{style:"thin",color:"white"},bottom:{style:"thin",color:"white"}},alignment:{horizontal:"left",vertical:"center"},fill:{type:"pattern",patternType:"solid",fgColor:"#e87200"}}),o=2,a=0,i=["Fecha","Comentario","Cantidad","Sub Cantidad","Costo"];a<i.length;a++){var s=i[a];t.cell(4,o).string(s).style(r),n.cell(4,o).string(s).style(r),o++}t.row(4).filter({firstColumn:2,lastColumn:3}),n.row(4).filter({firstColumn:2,lastColumn:3})},l=function e(t,n,r,o,a,i){var s,c=r-5;if((c+=i)>=n.variaciones.length)return 5;if(!1===n.variaciones[c].tipo)return 0+e(t,n,r,o,a,i+1);s=r%2==0?a:o;var u=n.variaciones[c],d=new Date(u.date);t.cell(r,2).date(d.toLocaleDateString()).style(s).style({numberFormat:"dd-mm-yyy",alignment:{horizontal:"left",vertical:"center"}}),t.cell(r,4).string(u.cantidad.toString()).style(s);var p="";u.cantidadSC&&(u.cantidadSC.forEach((function(e){var t=e.cantidadVenta;"new item"===u.comentario&&(t=e.cantidadDisponible);var n="";e.nameSecond&&(n="-"+e.nameSecond),p=p+e.name+n+": "+t+", "})),p.length>1&&(p=p.slice(0,-2))),t.cell(r,5).string(p).style(s);var l=u.costoVar;t.cell(r,6).number(l).style(s);var m=u.comentario;return"new item"===u.comentario?m="Nuevo Item":"anular"===u.comentario.split("|")[0]&&(m="Anulada "+u.comentario.split("|")[1]),t.cell(r,3).string(m).style(s),1+e(t,n,r+1,o,a,i)},m=function e(t,n,r,o,a,i){var s,c=r-5;if((c+=i)>=n.variaciones.length)return 5;if(!0===n.variaciones[c].tipo)return 0+e(t,n,r,o,a,i+1);s=r%2==0?a:o;var u=n.variaciones[c],d=new Date(u.date);t.cell(r,2).date(d.toLocaleDateString()).style(s).style({numberFormat:"dd-mm-yyy",alignment:{horizontal:"left",vertical:"center"}}),t.cell(r,4).string(u.cantidad.toString()).style(s);var p="";u.cantidadSC&&(u.cantidadSC.forEach((function(e){var t=e.cantidadVenta;"new item"===u.comentario&&(t=e.cantidadDisponible);var n="";e.nameSecond&&(n="-"+e.nameSecond),p=p+e.name+n+": "+t+", "})),p.length>1&&(p=p.slice(0,-2))),t.cell(r,5).string(p).style(s);var l=u.costoVar;t.cell(r,6).number(l).style(s);var m=u.comentario;return"venta"===u.comentario.split("|")[0]&&(m="Venta "+u.comentario.split("|")[1]),t.cell(r,3).string(m).style(s),1+e(t,n,r+1,o,a,i)},g=n(12),f=new r.Schema({name:{type:String,required:!0,unique:!0},codigo:{type:String,required:!0,unique:!0},ruc:{type:Number}}),y=new r.Schema({name:{type:String,required:!0,unique:!0},deleted:{type:Boolean,default:!1}}),b=n(11),v=n(13),h=n(5);function $(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return x(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return x(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,s=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,a=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw a}}}}function x(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function w(e,t,n,r,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function S(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function i(e){w(a,r,o,i,s,"next",e)}function s(e){w(a,r,o,i,s,"throw",e)}i(void 0)}))}}var j=o.a.model("Item",g.a),V=o.a.model("Marca",f),C=o.a.model("Venta",v.a),k=o.a.model("User",b.a),T=o.a.model("Tag",y),O=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r=new RegExp(t.body.value+"+[a-z0-9._ ]*$","ig"),e.next=4,j.find({name:{$regex:r},deleted:!1}).limit(t.body.limit);case 4:o=e.sent,n.json(o),e.next=11;break;case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 11:case"end":return e.stop()}}),e,null,[[0,8]])})));return function(t,n){return e.apply(this,arguments)}}(),N=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r=new RegExp(t.body.value+"+[a-z0-9._ ]*$","ig"),e.next=4,T.find({name:{$regex:r},deleted:!1}).limit(t.body.limit);case 4:o=e.sent,n.json(o),e.next=11;break;case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 11:case"end":return e.stop()}}),e,null,[[0,8]])})));return function(t,n){return e.apply(this,arguments)}}(),I=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.find({oferta:{$gt:0},deleted:!1});case 3:r=e.sent,n.json(r),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),A=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.find({tipo:t.params.tipo,codigo:{$ne:t.params.codigo},deleted:!1}).limit(8);case 3:r=e.sent,n.json(r),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),R=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r=new RegExp(t.params.searchTerms+"+[a-z0-9._ ]*$","ig"),e.next=4,j.find({name:{$regex:r},deleted:!1}).limit(8);case 4:o=e.sent,n.json(o),e.next=11;break;case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:e.t0}));case 11:case"end":return e.stop()}}),e,null,[[0,8]])})));return function(t,n){return e.apply(this,arguments)}}(),_=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.findOne({codigo:t.params.codigo});case 3:r=e.sent,o=P(r.variaciones),n.json({message:o}),e.next=11;break;case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:e.t0}));case 11:case"end":return e.stop()}}),e,null,[[0,8]])})));return function(t,n){return e.apply(this,arguments)}}(),P=function(e){try{var t,n=0,r=0,o=$(e);try{for(o.s();!(t=o.n()).done;){var a=t.value;!0===a.tipo?r+=a.costoVar:n+=a.costoVar}}catch(e){o.e(e)}finally{o.f()}return Math.round(100*(n-r+Number.EPSILON))/100}catch(e){throw new Error(e)}},E=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.findOne({codigo:t.params.codigo});case 3:return r=e.sent,e.next=6,u(r);case 6:o=e.sent,n.writeHead(200,{"Content-Type":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","Content-Disposition":"attachment; filename=reporteItem-".concat(r.codigo,".xlsx")}),n.write(o,"binary"),n.end(null,"binary"),e.next=15;break;case 12:return e.prev=12,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:e.t0}));case 15:case"end":return e.stop()}}),e,null,[[0,12]])})));return function(t,n){return e.apply(this,arguments)}}(),G=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,C.aggregate([{$match:{codigo:t.body.codVenta}},{$unwind:"$itemsVendidos"},{$replaceRoot:{newRoot:"$itemsVendidos"}},{$unwind:{path:"$cantidadSC",preserveNullAndEmptyArrays:!0}}]);case 3:r=e.sent,n.json(r),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),M=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o,a,i,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,t.body.itemVendido.ventaCod=t.body.codigoVenta,e.next=4,C.aggregate([{$match:{codigo:t.body.codigoVenta}},{$unwind:"$itemsVendidos"},{$replaceRoot:{newRoot:"$itemsVendidos"}},{$match:{codigo:t.body.itemVendido.codigo}},{$count:"thisItem"}]);case 4:if(0===e.sent.length){e.next=15;break}return e.next=8,C.aggregate([{$match:{codigo:t.body.codigoVenta}},{$unwind:"$itemsVendidos"},{$replaceRoot:{newRoot:"$itemsVendidos"}},{$match:{codigo:t.body.itemVendido.codigo}}]);case 8:return r=e.sent,o=Math.round(100*(r[0].totalPrice-t.body.itemVendido.totalPrice+Number.EPSILON))/100*-1,a=Math.round(100*(r[0].totalPriceNoIGV-t.body.itemVendido.totalPriceNoIGV+Number.EPSILON))/100*-1,e.next=13,C.findOneAndUpdate({codigo:t.body.codigoVenta,itemsVendidos:{$elemMatch:{codigo:t.body.itemVendido.codigo}}},{$set:{"itemsVendidos.$":t.body.itemVendido},$inc:{totalPrice:o,totalPriceNoIGV:a}},{useFindAndModify:!1,new:!0});case 13:return i=e.sent,e.abrupt("return",n.json({message:"Cantidades actualizadas",venta:i}));case 15:return e.next=17,C.findOneAndUpdate({codigo:t.body.codigoVenta},{$push:{itemsVendidos:t.body.itemVendido},$inc:{totalPrice:t.body.itemVendido.totalPrice,totalPriceNoIGV:t.body.itemVendido.totalPriceNoIGV}},{useFindAndModify:!1,new:!0});case 17:s=e.sent,n.json({message:"Item agregado correctamente",venta:s}),e.next=24;break;case 21:return e.prev=21,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:e.t0}));case 24:case"end":return e.stop()}}),e,null,[[0,21]])})));return function(t,n){return e.apply(this,arguments)}}(),q=function(){var e=S(regeneratorRuntime.mark((function e(t,n,r){var o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,o=new C(t.body.venta),e.next=4,z(o.documento.type);case 4:return o.codigo=e.sent,o.itemsVendidos[0].ventaCod=o.codigo,o.vendedor=t.user.aud.split(" ")[0],e.next=9,o.save();case 9:t.saveResult=e.sent,r(),e.next=16;break;case 13:return e.prev=13,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 16:case"end":return e.stop()}}),e,null,[[0,13]])})));return function(t,n,r){return e.apply(this,arguments)}}(),D=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,i,s,c,u,d,p,l,m,g,f,y,b,v,h;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,o.a.startSession();case 2:return(r=e.sent).startTransaction(),e.prev=4,e.next=7,C.findOne({codigo:t.body.codigo});case 7:if("anuladaPost"!==e.sent.estado){e.next=13;break}return e.next=11,r.abortTransaction();case 11:return r.endSession(),e.abrupt("return",n.status(409).json({errorMSG:"Ya anulada"}));case 13:i=[],s=[],c=$(t.body.itemsVendidos);try{for(c.s();!(u=c.n()).done;)d=u.value,s.push(d.codigo),i.push({date:Date.now(),cantidad:d.cantidad,tipo:!0,comentario:"anular|"+t.body.codigo,costoVar:d.totalPrice,usuario:t.user.aud.split(" ")[0],cantidadSC:d.cantidadSC})}catch(e){c.e(e)}finally{c.f()}p=0,l=$(t.body.itemsVendidos),e.prev=19,l.s();case 21:if((m=l.n()).done){e.next=46;break}g=m.value,f=$(g.cantidadSC),e.prev=24,f.s();case 26:if((y=f.n()).done){e.next=33;break}if(!((b=y.value).cantidadVenta>0)){e.next=31;break}return e.next=31,j.findOneAndUpdate({codigo:g.codigo,"subConteo.order":{$elemMatch:{name:b.name,nameSecond:b.nameSecond}}},{$inc:{"subConteo.order.$.cantidad":b.cantidadVenta}},{useFindAndModify:!1,new:!0,session:r});case 31:e.next=26;break;case 33:e.next=38;break;case 35:e.prev=35,e.t0=e.catch(24),f.e(e.t0);case 38:return e.prev=38,f.f(),e.finish(38);case 41:return e.next=43,j.findOneAndUpdate({codigo:g.codigo},{$inc:{cantidad:g.cantidad},$push:{variaciones:i[p]}},{new:!0,useFindAndModify:!1,session:r});case 43:p++;case 44:e.next=21;break;case 46:e.next=51;break;case 48:e.prev=48,e.t1=e.catch(19),l.e(e.t1);case 51:return e.prev=51,l.f(),e.finish(51);case 54:if(v="","noone"===t.body.documento.type){e.next=64;break}if("factura"!==t.body.documento.type){e.next=60;break}return e.next=59,Object(a.a)(1,t.body.serie,t.body.numero,"Anulación de venta");case 59:v=e.sent;case 60:if("boleta"!==t.body.documento.type){e.next=64;break}return e.next=63,Object(a.a)(2,t.body.serie,t.body.numero,"Anulación de venta");case 63:v=e.sent;case 64:return e.next=66,C.findOneAndUpdate({codigo:t.body.codigo},{estado:"anuladaPost",linkComprobante:v},{useFindAndModify:!1,new:!0,session:r});case 66:return h=e.sent,e.next=69,r.commitTransaction();case 69:return r.endSession(),e.abrupt("return",n.json({message:"succes||".concat(h.codigo)}));case 73:return e.prev=73,e.t2=e.catch(4),e.next=77,r.abortTransaction();case 77:return r.endSession(),e.abrupt("return",n.status(500).json({errorMSG:e.t2}));case 79:case"end":return e.stop()}}),e,null,[[4,73],[19,48,51,54],[24,35,38,41]])})));return function(t,n){return e.apply(this,arguments)}}(),L=function(){var e=S(regeneratorRuntime.mark((function e(t,n,r){var a,i,s,c,u,d,p,l,m,g;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,o.a.startSession();case 2:return(a=e.sent).startTransaction(),e.prev=4,e.next=7,z(t.body.venta.documento.type);case 7:return i=e.sent,t.body.venta.itemsVendidos[0].ventaCod=i,e.next=11,j.findOne({codigo:t.body.venta.itemsVendidos[0].codigo});case 11:if(s=e.sent,c={date:Date.now(),cantidad:t.body.venta.itemsVendidos[0].cantidad,tipo:!1,comentario:"venta|"+i,usuario:t.user.aud.split(" ")[0],costoVar:t.body.venta.totalPrice,cantidadSC:t.body.venta.itemsVendidos[0].cantidadSC},0===t.body.venta.itemsVendidos[0].cantidadSC.length){e.next=43;break}u=$(t.body.venta.itemsVendidos[0].cantidadSC),e.prev=15,u.s();case 17:if((d=u.n()).done){e.next=35;break}if(!((p=d.value).cantidadVenta>0)){e.next=33;break}return e.next=22,j.findOneAndUpdate({codigo:t.body.venta.itemsVendidos[0].codigo,"subConteo.order":{$elemMatch:{name:p.name,nameSecond:p.nameSecond}}},{$inc:{"subConteo.order.$.cantidad":-p.cantidadVenta}},{useFindAndModify:!1,new:!0,session:a});case 22:l=e.sent,m=0;case 24:if(!(m<l.subConteo.order.length)){e.next=33;break}if(!(l.subConteo.order[m].cantidad<0)){e.next=30;break}return e.next=28,a.abortTransaction();case 28:return a.endSession(),e.abrupt("return",n.status(202).json({message:"La Cantidad Ha Cambiado",item:s}));case 30:m++,e.next=24;break;case 33:e.next=17;break;case 35:e.next=40;break;case 37:e.prev=37,e.t0=e.catch(15),u.e(e.t0);case 40:return e.prev=40,u.f(),e.finish(40);case 43:return e.next=45,j.findOneAndUpdate({codigo:t.body.venta.itemsVendidos[0].codigo},{$inc:{cantidad:-t.body.venta.itemsVendidos[0].cantidad},$push:{variaciones:c}},{new:!0,useFindAndModify:!1,session:a});case 45:if(!(e.sent.cantidad<0)){e.next=51;break}return e.next=49,a.abortTransaction();case 49:return a.endSession(),e.abrupt("return",n.status(202).json({message:"La Cantidad Ha Cambiado",item:s}));case 51:return(g=new C(t.body.venta)).codigo=i,g.vendedor=t.user.aud.split(" ")[0],e.next=56,g.save({session:a});case 56:if(t.ventResult=e.sent,"factura"!==g.documento.type){e.next=63;break}return e.next=60,C.countDocuments({tipoComprobante:{$eq:1}});case 60:t.count=e.sent,e.next=67;break;case 63:if("boleta"!==g.documento.type){e.next=67;break}return e.next=66,C.countDocuments({tipoComprobante:{$eq:2}});case 66:t.count=e.sent;case 67:if(!t.body.venta.guia){e.next=71;break}return e.next=70,C.countDocuments({guia:{$eq:!0}});case 70:t.countGuia=e.sent;case 71:return e.next=73,Object(h.h)(g);case 73:return e.next=75,a.commitTransaction();case 75:a.endSession(),r(),e.next=85;break;case 79:return e.prev=79,e.t1=e.catch(4),e.next=83,a.abortTransaction();case 83:return a.endSession(),e.abrupt("return",n.status(500).json({errorMSG:e.t1}));case 85:case"end":return e.stop()}}),e,null,[[4,79],[15,37,40,43]])})));return function(t,n,r){return e.apply(this,arguments)}}(),B=function(){var e=S(regeneratorRuntime.mark((function e(t,n,r){var a,i,s,c,u,d,p,l,m,g,f,y,b,v,x,w,S;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,o.a.startSession();case 2:return(a=e.sent).startTransaction(),e.prev=4,i=[],s=[],e.next=9,C.findOne({codigo:t.body.venta.codigo});case 9:if("ejecutada"!==(c=e.sent).estado){e.next=15;break}return e.next=13,a.abortTransaction();case 13:return a.endSession(),e.abrupt("return",n.status(409).json({errorMSG:"La venta ya ha sido ejecutada."}));case 15:u=$(c.itemsVendidos);try{for(u.s();!(d=u.n()).done;)"N"!==(p=d.value).codigo.charAt(2)&&"I"!==p.codigo.charAt(3)&&(s.push(p.codigo),i.push({date:Date.now(),cantidad:p.cantidad,tipo:!1,comentario:"venta|"+c.codigo,costoVar:p.totalPrice,usuario:t.user.aud.split(" ")[0],cantidadSC:p.cantidadSC}))}catch(e){u.e(e)}finally{u.f()}l=0,m=$(c.itemsVendidos),e.prev=19,m.s();case 21:if((g=m.n()).done){e.next=64;break}if("N"===(f=g.value).codigo.charAt(2)||"I"===f.codigo.charAt(3)){e.next=62;break}y=$(f.cantidadSC),e.prev=25,y.s();case 27:if((b=y.n()).done){e.next=45;break}if(!((v=b.value).cantidadVenta>0)){e.next=43;break}return e.next=32,j.findOneAndUpdate({codigo:f.codigo,"subConteo.order":{$elemMatch:{name:v.name,nameSecond:v.nameSecond}}},{$inc:{"subConteo.order.$.cantidad":-v.cantidadVenta}},{useFindAndModify:!1,new:!0,session:a});case 32:x=e.sent,w=0;case 34:if(!(w<x.subConteo.order.length)){e.next=43;break}if(!(x.subConteo.order[w].cantidad<0)){e.next=40;break}return e.next=38,a.abortTransaction();case 38:return a.endSession(),e.abrupt("return",n.status(202).json({message:"La Cantidad Ha Cambiado"}));case 40:w++,e.next=34;break;case 43:e.next=27;break;case 45:e.next=50;break;case 47:e.prev=47,e.t0=e.catch(25),y.e(e.t0);case 50:return e.prev=50,y.f(),e.finish(50);case 53:return e.next=55,j.findOneAndUpdate({codigo:f.codigo},{$inc:{cantidad:-f.cantidad},$push:{variaciones:i[l]}},{new:!0,useFindAndModify:!1,session:a});case 55:if(!(e.sent.cantidad<0)){e.next=61;break}return e.next=59,a.abortTransaction();case 59:return a.endSession(),e.abrupt("return",n.status(202).json({message:"La Cantidad Ha Cambiado"}));case 61:l++;case 62:e.next=21;break;case 64:e.next=69;break;case 66:e.prev=66,e.t1=e.catch(19),m.e(e.t1);case 69:return e.prev=69,m.f(),e.finish(69);case 72:return e.next=74,C.findOneAndUpdate({codigo:t.body.venta.codigo},{estado:"ejecutada",documento:t.body.venta.documento,guia:t.body.venta.guia,cliente_email:t.body.venta.cliente_email,medio_de_pago:t.body.venta.medio_de_pago},{useFindAndModify:!1,new:!0,session:a});case 74:if(S=e.sent,t.ventResult=S,"factura"!==S.documento.type){e.next=82;break}return e.next=79,C.countDocuments({tipoComprobante:{$eq:1}});case 79:t.count=e.sent,e.next=86;break;case 82:if("boleta"!==S.documento.type){e.next=86;break}return e.next=85,C.countDocuments({tipoComprobante:{$eq:2}});case 85:t.count=e.sent;case 86:if(!t.body.venta.guia){e.next=90;break}return e.next=89,C.countDocuments({guia:{$eq:!0}});case 89:t.countGuia=e.sent;case 90:return e.next=92,k.findOneAndUpdate({username:t.user.aud.split(" ")[0]},{$pull:{ventaActiva:t.body.venta.codigo}},{useFindAndModify:!1});case 92:return e.next=94,Object(h.h)(S);case 94:return e.next=96,a.commitTransaction();case 96:a.endSession(),r(),e.next=106;break;case 100:return e.prev=100,e.t2=e.catch(4),e.next=104,a.abortTransaction();case 104:return a.endSession(),e.abrupt("return",n.status(500).json({errorMSG:e.t2}));case 106:case"end":return e.stop()}}),e,null,[[4,100],[19,66,69,72],[25,47,50,53]])})));return function(t,n,r){return e.apply(this,arguments)}}(),U=function(){var e=S(regeneratorRuntime.mark((function e(t,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,C.findOneAndUpdate({codigo:t.body.venta.codigo},{estado:"anulada"},{useFindAndModify:!1});case 3:return e.next=5,k.findOneAndUpdate({username:t.user.aud.split(" ")[0]},{$pull:{ventaActiva:t.body.venta.codigo}},{useFindAndModify:!1});case 5:n.json({message:"succes"}),e.next=11;break;case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 11:case"end":return e.stop()}}),e,null,[[0,8]])})));return function(t,n){return e.apply(this,arguments)}}(),F=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,t.sunat_guia||(t.sunat_guia=""),e.next=4,C.findByIdAndUpdate(t.ventResult._id,{linkComprobante:t.sunat.enlace_del_pdf,numero:t.sunat.numero,guia_link:t.sunat_guia.enlace_del_pdf,serie:t.sunat.serie,tipoComprobante:t.sunat.tipo_de_comprobante},{new:!0,useFindAndModify:!1});case 4:r=e.sent,n.json({venta:r,message:"Succes||".concat(t.ventResult.codigo),_sunat:t.sunat}),e.next=11;break;case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 11:case"end":return e.stop()}}),e,null,[[0,8]])})));return function(t,n){return e.apply(this,arguments)}}(),z=function(){var e=S(regeneratorRuntime.mark((function e(t){var n,r,o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,C.countDocuments({});case 3:e.t0=e.sent,n=e.t0+1,r="SD01-000000",e.t1=t,e.next="factura"===e.t1?9:"boleta"===e.t1?11:13;break;case 9:return r="E002-000000",e.abrupt("break",14);case 11:return r="EB02-000000",e.abrupt("break",14);case 13:return e.abrupt("break",14);case 14:for(o=0;o<n.toString().length;o++)r=r.slice(0,-1);return a=r+n.toString(),e.abrupt("return",a);case 19:return e.prev=19,e.t2=e.catch(0),e.abrupt("return",res.status(500).json({errorMSG:e.t2}));case 22:case"end":return e.stop()}}),e,null,[[0,19]])})));return function(t){return e.apply(this,arguments)}}(),W=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o,a,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.findOne({codigo:t.body.codigo});case 3:if(r=e.sent,t.body.tipo){e.next=8;break}if(!(r.cantidad-t.body.cantidad<0)){e.next=8;break}throw"Cantidad Invalidad";case 8:return o=t.body.cantidad,a={date:Date.now(),cantidad:o,tipo:t.body.tipo,comentario:t.body.tipo?"agregar|"+t.body.comentario:"quitar|"+t.body.comentario,costoVar:t.body.costoVar*o,cantidadSC:[]},e.next=12,j.findOneAndUpdate({codigo:t.body.codigo},{$inc:{cantidad:t.body.tipo?t.body.cantidad:-1*t.body.cantidad},$push:{variaciones:a}},{new:!0,useFindAndModify:!1});case 12:i=e.sent,n.json(i),e.next=19;break;case 16:return e.prev=16,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 19:case"end":return e.stop()}}),e,null,[[0,16]])})));return function(t,n){return e.apply(this,arguments)}}(),K=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o,a,i,s,c,u,d,p,l,m;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r=0,e.next=4,j.findOne({codigo:t.body.codigo});case 4:o=e.sent,r=t.body.cantidad,a={date:Date.now(),cantidad:r,tipo:t.body.tipo,comentario:t.body.tipo?"agregar|"+t.body.comentario:"quitar|"+t.body.comentario,costoVar:t.body.costoVar*r,cantidadSC:[]},i=[],s=$(o.subConteo.order);try{for(u=function(){var e=c.value;-1!==t.body.subConteo.order.findIndex((function(t){return t.name===e.name&&t.nameSecond===e.nameSecond}))&&i.push(e)},s.s();!(c=s.n()).done;)u()}catch(e){s.e(e)}finally{s.f()}o.subConteo.order=i,d=$(t.body.subConteo.order);try{for(l=function(){var e=p.value,n=o.subConteo.order.findIndex((function(t){return t.name===e.name&&t.nameSecond===e.nameSecond})),r=n>-1?o.subConteo.order[n].cantidad:0;if(n>-1){if(t.body.tipo)o.subConteo.order[n].cantidad+=e.cantidad;else if(o.subConteo.order[n].cantidad-=e.cantidad,o.subConteo.order[n].cantidad<0)throw"Cantidad Invalidad"}else o.subConteo.order.push({cantidad:e.cantidad,name:e.name,nameSecond:e.nameSecond||void 0});a.cantidadSC.push({name:e.name,nameSecond:e.nameSecond,cantidadDisponible:r,cantidadVenta:e.cantidad})},d.s();!(p=d.n()).done;)l()}catch(e){d.e(e)}finally{d.f()}if(t.body.tipo){e.next=17;break}if(!(o.cantidad-t.body.cantidad<0)){e.next=17;break}return e.abrupt("return",n.status(400).json({errorMSG:"Cantidad Invalidad"}));case 17:return e.next=19,j.findOneAndUpdate({codigo:t.body.codigo},{subConteo:o.subConteo,$inc:{cantidad:t.body.tipo?t.body.cantidad:-1*t.body.cantidad},$push:{variaciones:a}},{new:!0,useFindAndModify:!1});case 19:m=e.sent,n.json(m),e.next=26;break;case 23:return e.prev=23,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 26:case"end":return e.stop()}}),e,null,[[0,23]])})));return function(t,n){return e.apply(this,arguments)}}(),J=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r=new T(t.body),e.next=4,r.save();case 4:return o=e.sent,e.abrupt("return",n.json(o));case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 11:case"end":return e.stop()}}),e,null,[[0,8]])})));return function(t,n){return e.apply(this,arguments)}}(),H=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,T.updateMany({name:{$in:t.body}},{deleted:!0});case 3:return r=e.sent,e.abrupt("return",n.json(r));case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),Y=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,T.find({deleted:!1});case 3:return r=e.sent,e.abrupt("return",n.json(r));case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),Q=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,(r=new V(t.body)).codigo=Date.now().toString(),e.next=5,r.save();case 5:return o=e.sent,e.abrupt("return",n.json(o));case 9:return e.prev=9,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 12:case"end":return e.stop()}}),e,null,[[0,9]])})));return function(t,n){return e.apply(this,arguments)}}(),Z=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.aggregate([{$match:{codigo:"4SDtT4"}},{$project:{cantidadTotal:{$sum:"$subConteo.order.cantidad"}}}]);case 3:r=e.sent,n.json(r),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),X=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r=t.params.deleteString.split("_"),e.next=4,V.deleteMany({name:{$in:r}});case 4:n.json({message:"succes"}),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),ee=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,V.find({});case 3:r=e.sent,n.json(r),e.next=9;break;case 7:e.prev=7,e.t0=e.catch(0);case 9:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),te=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o,a,i,s,c;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,(r=new j(t.body)).priceNoIGV=le(r.priceIGV),e.next=5,ne(r.name,r.tipo);case 5:if(r.codigo=e.sent,r.nameLowerCase=r.name,o={date:Date.now(),cantidad:r.cantidad,tipo:!0,comentario:"new item",costoVar:Math.round(100*(r.costoPropio*r.cantidad+Number.EPSILON))/100,cantidadSC:[]},r.subConteo){a=$(r.subConteo.order);try{for(a.s();!(i=a.n()).done;)s=i.value,o.cantidadSC.push({name:s.name,nameSecond:s.nameSecond,cantidadDisponible:s.cantidad,cantidadVenta:0})}catch(e){a.e(e)}finally{a.f()}}return r.variaciones=[o],e.next=12,r.save();case 12:return c=e.sent,e.abrupt("return",n.json(c));case 16:return e.prev=16,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 19:case"end":return e.stop()}}),e,null,[[0,16]])})));return function(t,n){return e.apply(this,arguments)}}(),ne=function(){var e=S(regeneratorRuntime.mark((function e(){var t,n,r,o=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=o.length>0&&void 0!==o[0]?o[0]:"",n=o.length>1&&void 0!==o[1]?o[1]:"",e.prev=2,e.next=5,j.countDocuments({});case 5:return r=e.sent,e.abrupt("return",r.toString()+"SD"+t.charAt(0)+n.charAt(0)+Math.floor(10*Math.random()).toString());case 9:return e.prev=9,e.t0=e.catch(2),e.abrupt("return",new Error(e.t0));case 12:case"end":return e.stop()}}),e,null,[[2,9]])})));return function(){return e.apply(this,arguments)}}(),re=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.find({deleted:!1}).sort({orderNumber:1});case 3:return r=e.sent,e.abrupt("return",n.json(r));case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),oe=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.findOneAndUpdate({codigo:t.body.codigo},{oferta:1},{new:!0,useFindAndModify:!1});case 3:return r=e.sent,e.abrupt("return",n.json(r));case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),ae=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.findOneAndUpdate({codigo:t.body.codigo},{oferta:0},{new:!0,useFindAndModify:!1});case 3:return r=e.sent,e.abrupt("return",n.json(r));case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),ie=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.find({tipo:t.params.tipo,deleted:!1});case 3:return r=e.sent,e.abrupt("return",n.json(r));case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),se=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.find({subTipo:t.params.subTipo,tipo:t.params.tipo,deleted:!1}).sort({orderNumber:1});case 3:return r=e.sent,e.abrupt("return",n.json(r));case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),ce=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r={},e.prev=1,e.t0=t.params.tipo,e.next="cod"===e.t0?5:"name"===e.t0?9:"tipo"===e.t0?13:17;break;case 5:return e.next=7,j.findOne({codigo:t.params.codigo});case 7:return r=e.sent,e.abrupt("break",19);case 9:return e.next=11,j.find({name:t.body.name});case 11:return r=e.sent,e.abrupt("break",19);case 13:return e.next=15,j.find({tipo:t.body.tipo});case 15:return r=e.sent,e.abrupt("break",19);case 17:return r={message:"Not A Type Of Search"},e.abrupt("break",19);case 19:return e.abrupt("return",n.json(r));case 22:return e.prev=22,e.t1=e.catch(1),e.abrupt("return",n.status(500).json({errorMSG:e.t1}));case 25:case"end":return e.stop()}}),e,null,[[1,22]])})));return function(t,n){return e.apply(this,arguments)}}(),ue=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,(r=t.body).priceIGV&&(r.priceNoIGV=le(r.priceIGV)),e.next=5,j.findOneAndUpdate({codigo:t.body.codigo},r,{new:!0,useFindAndModify:!1});case 5:o=e.sent,n.json(o),e.next=12;break;case 9:return e.prev=9,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 12:case"end":return e.stop()}}),e,null,[[0,9]])})));return function(t,n){return e.apply(this,arguments)}}(),de=function(){var e=S(regeneratorRuntime.mark((function e(t,n,r){var o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.findOneAndUpdate({codigo:t.params.codigo},{deleted:!0},{new:!0,useFindAndModify:!1});case 3:o=e.sent,t.result=o,t.photNameToDelete=o.photo,r(),e.next=12;break;case 9:return e.prev=9,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 12:case"end":return e.stop()}}),e,null,[[0,9]])})));return function(t,n,r){return e.apply(this,arguments)}}(),pe=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.findOneAndUpdate({codigo:t.params.codigo},{photo:t.fileName},{new:!0,useFindAndModify:!1});case 3:r=e.sent,n.status(200).json(r),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),le=function(e){var t=e/1.18;return Math.round(100*(t+Number.EPSILON))/100},me=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.findOneAndUpdate({codigo:t.params.codigo},{ficha:!0},{new:!0,useFindAndModify:!1});case 3:r=e.sent,n.status(200).json({res:r,uploadInfo:t.uploadInfo}),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),ge=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o,a,i,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,r=[],o=t.gananciaPorItem.filter((function(e){return!(6===e.name.length&&"N"===e.name.split("")[2]&&"I"===e.name.split("")[3])})).slice(0,4),-1!==(a=o.findIndex((function(e){return"3SDKP7"===e.name})))?o.splice(a,1):o.pop(),i=0;case 6:if(!(i<o.length)){e.next=15;break}return e.next=9,j.findOne({codigo:o[i].name});case 9:s=e.sent,o[i].name=s.name,r.push({name:o[i].name,series:[{name:"Ventas",value:o[i].totalVenta},{name:"Ganancias",value:o[i].value}]});case 12:i++,e.next=6;break;case 15:n.json(r),e.next=21;break;case 18:return e.prev=18,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 21:case"end":return e.stop()}}),e,null,[[0,18]])})));return function(t,n){return e.apply(this,arguments)}}(),fe=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o,a,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.aggregate([{$match:{deleted:!1}},{$project:{_id:0,codigo:1,name:1,variaciones:1}},{$unwind:"$variaciones"},{$match:{"variaciones.tipo":!1}},{$project:{variaciones:1,codVar:{$split:["$variaciones.comentario","|"]}}},{$project:{variaciones:1,firstPartVar:{$arrayElemAt:["$codVar",0]}}},{$match:{firstPartVar:"quitar"}},{$group:{_id:null,totalVarQuitar:{$sum:"$variaciones.costoVar"}}}]);case 3:return r=e.sent,e.next=6,j.aggregate([{$match:{deleted:!1}},{$project:{_id:0,codigo:1,name:1,variaciones:1}},{$unwind:"$variaciones"},{$match:{"variaciones.tipo":!0}},{$group:{_id:{codigo:"$codigo",name:"$name"},posVar:{$sum:"$variaciones.costoVar"}}},{$project:{_id:0,codigo:"$_id.codigo",name:"$_id.name",posVar:1}},{$sort:{name:1}},{$group:{_id:null,totalVarPos:{$sum:"$posVar"}}}]);case 6:return o=e.sent,e.next=9,j.aggregate([{$match:{deleted:!1}},{$project:{_id:0,codigo:1,name:1,variaciones:1}},{$unwind:"$variaciones"},{$match:{"variaciones.tipo":!1}},{$group:{_id:{codigo:"$codigo",name:"$name"},posVar:{$sum:"$variaciones.costoVar"}}},{$project:{_id:0,codigo:"$_id.codigo",name:"$_id.name",posVar:1}},{$sort:{name:1}},{$group:{_id:null,totalVarNeg:{$sum:"$posVar"}}}]);case 9:return a=e.sent,e.next=12,j.aggregate([{$match:{deleted:!1}},{$project:{_id:0,codigo:1,name:1,variaciones:1}},{$unwind:"$variaciones"},{$match:{"variaciones.tipo":!0}},{$project:{variaciones:1,codVar:{$split:["$variaciones.comentario","|"]}}},{$project:{variaciones:1,firstPartVar:{$arrayElemAt:["$codVar",0]}}},{$match:{firstPartVar:"anular"}},{$group:{_id:null,totalVarAnular:{$sum:"$variaciones.costoVar"}}}]);case 12:i=e.sent,n.json({gastosInventario:o[0].totalVarPos-((r[0]?r[0].totalVarQuitar:0)+(i[0]?i[0].totalVarAnular:0)),gananciasInventario:a[0].totalVarNeg-((r[0]?r[0].totalVarQuitar:0)+(i[0]?i[0].totalVarAnular:0))}),e.next=19;break;case 16:return e.prev=16,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 19:case"end":return e.stop()}}),e,null,[[0,16]])})));return function(t,n){return e.apply(this,arguments)}}(),ye=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o,a,i,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.aggregate([{$match:{deleted:!1}},{$project:{_id:0,codigo:1,name:1,variaciones:1}},{$unwind:"$variaciones"},{$match:{"variaciones.tipo":!1}},{$project:{variaciones:1,codVar:{$split:["$variaciones.comentario","|"]}}},{$project:{variaciones:1,firstPartVar:{$arrayElemAt:["$codVar",0]}}},{$match:{firstPartVar:"quitar"}},{$group:{_id:null,totalVarQuitar:{$sum:"$variaciones.costoVar"}}}]);case 3:return r=e.sent,e.next=6,j.aggregate([{$match:{deleted:!1}},{$project:{_id:0,codigo:1,name:1,variaciones:1}},{$unwind:"$variaciones"},{$match:{"variaciones.tipo":!0}},{$project:{variaciones:1,codVar:{$split:["$variaciones.comentario","|"]}}},{$project:{variaciones:1,firstPartVar:{$arrayElemAt:["$codVar",0]}}},{$match:{firstPartVar:"anular"}},{$group:{_id:null,totalVarAnular:{$sum:"$variaciones.costoVar"}}}]);case 6:return o=e.sent,e.next=9,j.aggregate([{$match:{deleted:!1}},{$project:{_id:0,codigo:1,name:1,variaciones:1}},{$unwind:"$variaciones"},{$match:{"variaciones.tipo":!0}},{$group:{_id:{codigo:"$codigo",name:"$name"},posVar:{$sum:"$variaciones.costoVar"}}},{$project:{_id:0,codigo:"$_id.codigo",name:"$_id.name",posVar:1}},{$sort:{name:1}},{$group:{_id:null,totalVarPos:{$sum:"$posVar"}}}]);case 9:return a=e.sent,e.next=12,C.aggregate([{$match:{date:{$gte:new Date("2021-01-01")},estado:"ejecutada"}},{$unwind:"$itemsVendidos"},{$replaceRoot:{newRoot:"$itemsVendidos"}},{$project:{codigo:1,codArray:{$split:["$codigo","NI"]},totalPrice:1,codSize:{$strLenCP:"$codigo"},costoTotalPropio:{$multiply:["$priceCosto","$cantidad"]}}},{$match:{codSize:6}},{$set:{arrayCodSize:{$size:"$codArray"}}},{$match:{arrayCodSize:2}},{$project:{codigo:1,costoTotalPropio:1,totalPrice:1,primeraParteLen:{$strLenCP:{$arrayElemAt:["$codArray",0]}},segundaParteLen:{$strLenCP:{$arrayElemAt:["$codArray",0]}}}},{$match:{primeraParteLen:2,segundaParteLen:2}},{$group:{_id:null,costoTotalPropio:{$sum:"$costoTotalPropio"},ingresoTotal:{$sum:"$totalPrice"}}}]);case 12:return i=e.sent,e.next=15,j.aggregate([{$match:{deleted:!1}},{$project:{_id:0,codigo:1,name:1,variaciones:1}},{$unwind:"$variaciones"},{$match:{"variaciones.tipo":!1}},{$group:{_id:{codigo:"$codigo",name:"$name"},posVar:{$sum:"$variaciones.costoVar"}}},{$project:{_id:0,codigo:"$_id.codigo",name:"$_id.name",posVar:1}},{$sort:{name:1}},{$group:{_id:null,totalVarNeg:{$sum:"$posVar"}}}]);case 15:s=e.sent,n.json({gastoTotalHistorico:a[0].totalVarPos-((r[0]?r[0].totalVarQuitar:0)+(o[0]?o[0].totalVarAnular:0))+i[0].costoTotalPropio,ingresoTotalHistorico:s[0].totalVarNeg-((r[0]?r[0].totalVarQuitar:0)+(o[0]?o[0].totalVarAnular:0))+i[0].ingresoTotal}),e.next=22;break;case 19:return e.prev=19,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 22:case"end":return e.stop()}}),e,null,[[0,19]])})));return function(t,n){return e.apply(this,arguments)}}(),be=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.aggregate([{$match:{deleted:!1}},{$project:{_id:0,cantidad:1,priceIGV:1,total:{$multiply:["$priceIGV","$cantidad"]}}},{$group:{_id:null,totalPotencial:{$sum:"$total"}}}]);case 3:return r=e.sent,e.next=6,j.aggregate([{$match:{deleted:!1}},{$project:{_id:0,cantidad:1,costoPropio:1,total:{$multiply:["$costoPropio","$cantidad"]}}},{$group:{_id:null,totalPotencial:{$sum:"$total"}}}]);case 6:o=e.sent,n.json({ventasPosibles:r[0].totalPotencial,costoPropioTotalAprox:o[0].totalPotencial,gananciaAprox:r[0].totalPotencial-o[0].totalPotencial}),e.next=13;break;case 10:return e.prev=10,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 13:case"end":return e.stop()}}),e,null,[[0,10]])})));return function(t,n){return e.apply(this,arguments)}}(),ve=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.aggregate([{$match:{deleted:!1}},{$unwind:"$variaciones"},{$project:{_id:0,codigo:1,name:1,variaciones:1,costoVarTrue:{$cond:[{$eq:["$variaciones.tipo",!0]},"$variaciones.costoVar",0]},costoVarFalse:{$cond:[{$eq:["$variaciones.tipo",!1]},"$variaciones.costoVar",0]}}},{$group:{_id:{name:"$name",codigo:"$codigo"},totalTrue:{$sum:"$costoVarTrue"},totalFalse:{$sum:"$costoVarFalse"}}},{$project:{_id:0,name:"$_id.name",codigo:"$_id.codigo",totalTrue:1,totalFalse:1,balance:{$subtract:["$totalFalse","$totalTrue"]}}},{$sort:{balance:1}}]);case 3:r=e.sent,n.json({peor:r[0],mejor:r[r.length-1]}),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),he=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.aggregate([{$match:{deleted:!1}},{$project:{codigo:1,name:1,cantidad:1,costoPropio:1,priceIGV:1,totalIngreso:{$multiply:["$cantidad","$priceIGV"]},totalCosto:{$multiply:["$cantidad","$costoPropio"]}}},{$project:{codigo:1,name:1,cantidad:1,costoPropio:1,priceIGV:1,balance:{$subtract:["$totalIngreso","$totalCosto"]}}}]).sort({balance:-1}).limit(1);case 3:r=e.sent,n.json(r[0]),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),$e=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,C.aggregate([{$match:{date:{$gte:new Date("2021-01-01")},estado:"ejecutada"}},{$unwind:"$itemsVendidos"},{$replaceRoot:{newRoot:"$itemsVendidos"}},{$project:{codigo:1,codArray:{$split:["$codigo","NI"]},totalPrice:1,codSize:{$strLenCP:"$codigo"},costoTotalPropio:{$multiply:["$priceCosto","$cantidad"]}}},{$match:{codSize:6}},{$set:{arrayCodSize:{$size:"$codArray"}}},{$match:{arrayCodSize:2}},{$project:{codigo:1,costoTotalPropio:1,totalPrice:1,primeraParteLen:{$strLenCP:{$arrayElemAt:["$codArray",0]}},segundaParteLen:{$strLenCP:{$arrayElemAt:["$codArray",1]}}}},{$match:{primeraParteLen:2,segundaParteLen:2}},{$group:{_id:null,costoTotalPropio:{$sum:"$costoTotalPropio"},ingresoTotal:{$sum:"$totalPrice"}}}]);case 3:return r=e.sent,e.next=6,C.aggregate([{$match:{date:{$gte:new Date("2021-01-01")},estado:"ejecutada"}},{$unwind:"$itemsVendidos"},{$replaceRoot:{newRoot:"$itemsVendidos"}},{$project:{codigo:1,totalPrice:1,costoTotalPropio:{$multiply:["$priceCosto","$cantidad"]}}},{$group:{_id:null,costoTotalPropio:{$sum:"$costoTotalPropio"},ingresoTotal:{$sum:"$totalPrice"}}}]);case 6:o=e.sent,n.json({gananciaEnVentasFueraTienda:r[0].ingresoTotal-r[0].costoTotalPropio,gananciaEnVentas:o[0].ingresoTotal-o[0].costoTotalPropio,gananciaEnVentasDeTienda:o[0].ingresoTotal-r[0].ingresoTotal-(o[0].costoTotalPropio-r[0].costoTotalPropio)}),e.next=13;break;case 10:return e.prev=10,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 13:case"end":return e.stop()}}),e,null,[[0,10]])})));return function(t,n){return e.apply(this,arguments)}}(),xe=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,C.aggregate([{$match:{date:{$gte:new Date("2021-01-01")},estado:"ejecutada"}},{$unwind:"$itemsVendidos"},{$replaceRoot:{newRoot:"$itemsVendidos"}},{$group:{_id:"$codigo",cantidad:{$sum:1}}},{$sort:{cantidad:-1}}]);case 3:return r=e.sent,e.next=6,j.findOne({codigo:r[0]._id});case 6:o=e.sent,n.json(o),e.next=13;break;case 10:return e.prev=10,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 13:case"end":return e.stop()}}),e,null,[[0,10]])})));return function(t,n){return e.apply(this,arguments)}}(),we=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,C.aggregate([{$match:{date:{$gte:new Date("2021-01-01")},estado:"ejecutada"}},{$unwind:"$documento"},{$replaceRoot:{newRoot:"$documento"}},{$match:{codigo:{$ne:null}}},{$group:{_id:{codigo:"$codigo",name:"$name"},cantidad:{$sum:1}}},{$sort:{cantidad:-1}}]);case 3:r=e.sent,n.json({cliente:r[0]._id.name,numero:r[0].cantidad}),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),Se=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.findOneAndUpdate({codigo:t.body.itemCod},{$pull:{caracteristicas:{$in:t.body.deleteArray}}},{useFindAndModify:!1,new:!0});case 3:r=e.sent,n.json(r),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),je=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.findOneAndUpdate({codigo:t.body.itemCod},{$push:{caracteristicas:t.body.newCaracteristica}},{useFindAndModify:!1,new:!0});case 3:r=e.sent,n.json(r),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),Ve=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,o.a.startSession();case 2:return(r=e.sent).startTransaction(),e.prev=4,e.next=7,j.countDocuments({deleted:!1,subTipo:t.body.itemReOrder[0].subTipo,tipo:t.body.itemReOrder[0].tipo});case 7:if(e.sent===t.body.itemReOrder.length){e.next=10;break}throw"Variacion Invalida";case 10:a=0;case 11:if(!(a<t.body.itemReOrder.length)){e.next=17;break}return e.next=14,j.findOneAndUpdate({codigo:t.body.itemReOrder[a].codigo},{orderNumber:a},{useFindAndModify:!1});case 14:a++,e.next=11;break;case 17:return e.next=19,r.commitTransaction();case 19:r.endSession(),n.json({message:"done"}),e.next=29;break;case 23:return e.prev=23,e.t0=e.catch(4),e.next=27,r.abortTransaction();case 27:return r.endSession(),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 29:case"end":return e.stop()}}),e,null,[[4,23]])})));return function(t,n){return e.apply(this,arguments)}}(),Ce=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.find({deleted:!1,$and:[{cantidad:{$lt:5}},{cantidad:{$gt:0}}]});case 3:r=e.sent,n.json(r),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),ke=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.find({deleted:!1,cantidad:0});case 3:r=e.sent,n.json(r),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),Te=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o,a,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.aggregate([{$match:{codigo:t.params.codigoItem}},{$unwind:"$variaciones"},{$project:{variaciones:1,codVar:{$split:["$variaciones.comentario","|"]}}},{$set:{firstPartVar:{$arrayElemAt:["$codVar",0]}}},{$set:{cantidadVarNI:{$cond:[{$eq:["$firstPartVar","new item"]},"$variaciones.cantidad",0]},cantidadVarQuitar:{$cond:[{$eq:["$firstPartVar","quitar"]},"$variaciones.cantidad",0]},cantidadVarAgregar:{$cond:[{$eq:["$firstPartVar","agregar"]},"$variaciones.cantidad",0]},cantidadVarAnular:{$cond:[{$eq:["$firstPartVar","anular"]},"$variaciones.cantidad",0]},cantidadVarVenta:{$cond:[{$eq:["$firstPartVar","venta"]},"$variaciones.cantidad",0]}}},{$group:{_id:null,totalCantidadNI:{$sum:"$cantidadVarNI"},totalCantidadQuitar:{$sum:"$cantidadVarQuitar"},totalCantidadAgregar:{$sum:"$cantidadVarAgregar"},totalCantidadVenta:{$sum:"$cantidadVarVenta"},totalCantidadAnular:{$sum:"$cantidadVarAnular"}}}]);case 3:return r=e.sent,e.next=6,j.aggregate([{$match:{codigo:t.params.codigoItem}},{$unwind:"$variaciones"},{$project:{_id:0,codigo:1,name:1,variaciones:1,costoVarTrue:{$cond:[{$eq:["$variaciones.tipo",!0]},"$variaciones.costoVar",0]},costoVarFalse:{$cond:[{$eq:["$variaciones.tipo",!1]},"$variaciones.costoVar",0]}}},{$group:{_id:{name:"$name",codigo:"$codigo"},totalTrue:{$sum:"$costoVarTrue"},totalFalse:{$sum:"$costoVarFalse"}}}]);case 6:return o=e.sent,e.next=9,j.aggregate([{$match:{codigo:t.params.codigoItem}},{$project:{_id:0,codigo:1,name:1,variaciones:1}},{$unwind:"$variaciones"},{$match:{"variaciones.tipo":!1}},{$project:{variaciones:1,codVar:{$split:["$variaciones.comentario","|"]}}},{$project:{variaciones:1,firstPartVar:{$arrayElemAt:["$codVar",0]}}},{$match:{firstPartVar:"quitar"}},{$group:{_id:null,totalVarQuitar:{$sum:"$variaciones.costoVar"}}}]);case 9:return a=e.sent,e.next=12,j.aggregate([{$match:{codigo:t.params.codigoItem}},{$project:{_id:0,codigo:1,name:1,variaciones:1}},{$unwind:"$variaciones"},{$match:{"variaciones.tipo":!0}},{$project:{variaciones:1,codVar:{$split:["$variaciones.comentario","|"]}}},{$project:{variaciones:1,firstPartVar:{$arrayElemAt:["$codVar",0]}}},{$match:{firstPartVar:"anular"}},{$group:{_id:null,totalVarAnular:{$sum:"$variaciones.costoVar"}}}]);case 12:i=e.sent,n.json({itemVendidos:r[0].totalCantidadVenta-r[0].totalCantidadAnular,cantidadHistorica:r[0].totalCantidadNI+r[0].totalCantidadAgregar-r[0].totalCantidadQuitar,totalCosto:o[0].totalTrue-((a[0]?a[0].totalVarQuitar:0)+(i[0]?i[0].totalVarAnular:0)),totalIngreso:o[0].totalFalse-((a[0]?a[0].totalVarQuitar:0)+(i[0]?i[0].totalVarAnular:0))}),e.next=19;break;case 16:return e.prev=16,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 19:case"end":return e.stop()}}),e,null,[[0,16]])})));return function(t,n){return e.apply(this,arguments)}}(),Oe=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.aggregate([{$match:{codigo:t.params.codigoItem}},{$unwind:"$variaciones"},{$project:{variaciones:1,codVar:{$split:["$variaciones.comentario","|"]}}},{$set:{firstPartVar:{$arrayElemAt:["$codVar",0]}}},{$set:{cantidadVarAnular:{$cond:[{$eq:["$firstPartVar","anular"]},"$variaciones.cantidad",0]},cantidadVarVenta:{$cond:[{$eq:["$firstPartVar","venta"]},"$variaciones.cantidad",0]},dateVar:{$dateToString:{format:"%Y-%m",date:"$variaciones.date",timezone:"-05:00"}}}},{$group:{_id:"$dateVar",valueVenta:{$sum:"$cantidadVarVenta"},valueAnular:{$sum:"$cantidadVarAnular"}}},{$project:{_id:0,name:"$_id",value:{$subtract:["$valueVenta","$valueAnular"]}}},{$sort:{name:1}}]);case 3:r=e.sent,o=[{name:"Cantidad",series:r}],n.json(o),e.next=11;break;case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 11:case"end":return e.stop()}}),e,null,[[0,8]])})));return function(t,n){return e.apply(this,arguments)}}(),Ne=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,j.aggregate([{$match:{deleted:!1}},{$unwind:"$variaciones"},{$project:{name:1,codigo:1,cantidad:1,variaciones:1,priceIGV:1,costoPropio:1,codVar:{$split:["$variaciones.comentario","|"]}}},{$set:{firstPartVar:{$arrayElemAt:["$codVar",0]}}},{$set:{cantidadVarAgregar:{$cond:[{$eq:["$firstPartVar","agregar"]},"$variaciones.costoVar",0]},cantidadVarNewItem:{$cond:[{$eq:["$firstPartVar","new item"]},"$variaciones.costoVar",0]},cantidadVarQuitar:{$cond:[{$eq:["$firstPartVar","quitar"]},"$variaciones.costoVar",0]},cantidadVarAnular:{$cond:[{$eq:["$firstPartVar","anular"]},"$variaciones.costoVar",0]},cantidadVarVenta:{$cond:[{$eq:["$firstPartVar","venta"]},"$variaciones.costoVar",0]}}},{$group:{_id:{name:"$name",codigo:"$codigo",cantidad:"$cantidad",priceIGV:"$priceIGV",costoPropio:"$costoPropio"},valueAgregar:{$sum:"$cantidadVarAgregar"},valueVenta:{$sum:"$cantidadVarVenta"},valueAnular:{$sum:"$cantidadVarAnular"},valueNewItem:{$sum:"$cantidadVarNewItem"},valueQuitar:{$sum:"$cantidadVarQuitar"}}},{$project:{_id:0,name:"$_id.name",codigo:"$_id.codigo",cantidad:"$_id.cantidad",priceIGV:"$_id.priceIGV",costoPropio:"$_id.costoPropio",valueQuitar:1,preValueGasto:{$sum:["$valueAgregar","$valueNewItem"]},valueIngreso:{$subtract:["$valueVenta","$valueAnular"]}}},{$project:{_id:0,name:1,codigo:1,cantidad:1,priceIGV:1,costoPropio:1,valueGasto:{$subtract:["$preValueGasto","$valueQuitar"]},valueIngreso:1}},{$sort:{valueIngreso:-1}}]);case 3:r=e.sent,n.json(r),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),Ie=function(){var e=S(regeneratorRuntime.mark((function e(t,n){var r,o,a,i,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,t.body.rating<=5&&t.body.rating>=1){e.next=3;break}return e.abrupt("return",n.status(400).json({errorMSG:"Rating no valido"}));case 3:return e.next=5,j.aggregate([{$match:{codigo:t.body.codigo}},{$unwind:"$variaciones"},{$match:{"variaciones.usuario":t.user.aud.split(" ")[0]}},{$limit:4}]);case 5:if(0!==e.sent.length){e.next=8;break}return e.abrupt("return",n.status(403).json({message:"No has comprado el item."}));case 8:return r=new Date,e.next=11,j.findOne({codigo:t.body.codigo});case 11:if(o=e.sent,a=!1,o.reviews.length>0&&(a=o.reviews.some((function(e){return e.user===t.user.aud.split(" ")[0]}))),!a){e.next=19;break}return e.next=17,j.findOneAndUpdate({codigo:t.body.codigo,"reviews.user":t.user.aud.split(" ")[0]},{$set:{"reviews.$.date":r.toISOString(),"reviews.$.rating":t.body.rating}},{new:!0,useFindAndModify:!1});case 17:return i=e.sent,e.abrupt("return",n.json(i));case 19:return e.next=21,j.findOneAndUpdate({codigo:t.body.codigo},{$push:{reviews:{user:t.user.aud.split(" ")[0],rating:t.body.rating,date:r.toISOString()}}},{new:!0,useFindAndModify:!1});case 21:return s=e.sent,e.abrupt("return",n.json(s));case 25:return e.prev=25,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 28:case"end":return e.stop()}}),e,null,[[0,25]])})));return function(t,n){return e.apply(this,arguments)}}()},function(e,t){e.exports=require("mongoose")},function(e,t){e.exports=require("express")},function(e,t,n){"use strict";n.d(t,"h",(function(){return T})),n.d(t,"a",(function(){return O})),n.d(t,"b",(function(){return N})),n.d(t,"d",(function(){return I})),n.d(t,"f",(function(){return A})),n.d(t,"g",(function(){return R})),n.d(t,"c",(function(){return _})),n.d(t,"e",(function(){return P}));var r=n(14),o=n.n(r),a=n(21),i=n.n(a),s=n(22),c=n.n(s),u=n(23),d=n.n(u),p=n(24),l=n.n(p),m=(n(18),n(1)),g=n(45),f=n.n(g),y=function(e,t){var n=new f.a({size:"A4",margin:50});return b(n,t),v(n,e),w(n,e),S(n),n},b=function(e,t){e.image(t,50,30,{width:70}).fillColor("#444444").fontSize(20).fontSize(10).text("Sirio Dinar | RUC: 20605746587",200,50,{align:"right"}).text("Jr. Felipe Pardo Y Aliaga 213, Trujillo.",200,65,{align:"right"}).text("+51 977-426-349",200,80,{align:"right"}).moveDown()},v=function(e,t){e.fillColor("#444444").fontSize(20).text("Comprobante",50,160),h(e,185);e.fontSize(10).text("Codigo:",50,200).font("Helvetica-Bold").text(t.codigo,150,200).font("Helvetica").text("Fecha de emisión:",50,240).text(x(new Date),150,240).font("Helvetica-Bold").text(t.documento.name,300,200).font("Helvetica").text(t.documento.codigo,300,240).moveDown(),h(e,260)},h=function(e,t){e.strokeColor("#aaaaaa").lineWidth(1).moveTo(50,t).lineTo(550,t).stroke()},$=function(e){return"S/"+e.toFixed(2)},x=function(e){var t=e.getDate(),n=e.getMonth()+1;return e.getFullYear()+"/"+n+"/"+t},w=function(e,t){var n,r=307;for(e.fontSize(8).font("Helvetica-Bold"),j(e,r,"Cod","Nombre","Descripcion","Precio","Cantidad","Total"),h(e,(r=300)+25),e.font("Helvetica"),n=0;n<t.itemsVendidos.length;n++){var o=t.itemsVendidos[n],a=o.descripcion;o.cantidadSC.length>0&&(a+="\nCantidades: ");for(var i=0;i<o.cantidadSC.length;i++)o.cantidadSC[i].cantidadVenta>0&&(a=a+o.cantidadSC[i].name+" - "+o.cantidadSC[i].nameSecond+": "+o.cantidadSC[i].cantidadVenta+", ");o.cantidadSC.length>0&&(a=a.slice(0,-2)+".");var s=r+30*(2*n+1);j(e,s,o.codigo,o.name,a,$(o.priceNoIGV),o.cantidad,$(o.totalPriceNoIGV)),h(e,s+55)}var c=r+31*(2*n+1);j(e,c,"","","","","Subtotal",$(t.totalPriceNoIGV));var u=c+15;j(e,u,"","","","","IGV 18%",$(t.totalPrice-t.totalPriceNoIGV));var d=u+15;e.font("Helvetica-Bold"),j(e,d,"","","","","Total",$(t.totalPrice)),e.font("Helvetica")},S=function(e){e.fontSize(10).text("siriodinar.com",50,780,{align:"center",width:500})},j=function(e,t,n,r,o,a,i,s){e.fontSize(8).text(n,50,t,{width:40}).text(r,100,t,{width:100}).text(o,210,t,{width:180}).text(a,400,t,{width:35,align:"right"}).text(i,460,t,{width:35,align:"right"}).text(s,0,t,{align:"right"})};function V(e,t,n,r,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function C(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function i(e){V(a,r,o,i,s,"next",e)}function s(e){V(a,r,o,i,s,"throw",e)}i(void 0)}))}}var k=new o.a.S3({accessKeyId:m.a.production.awsID,secretAccessKey:m.a.production.awsKey,Bucket:m.a.production.bucket,region:"us-east-1"}),T=function(){var e=C(regeneratorRuntime.mark((function e(t){var n,r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,k.getObject({Bucket:m.a.production.bucket,Key:"sirio-logo.png"}).promise();case 3:return n=e.sent,(r=y(t,n.Body)).end(),e.next=8,k.upload({Bucket:m.a.production.bucket,Key:"".concat(t.codigo,".pdf"),Body:r,ContentType:"application/pdf"}).promise();case 8:e.next=14;break;case 10:return e.prev=10,e.t0=e.catch(0),m.a.production.log().error(e.t0),e.abrupt("return",e.t0);case 14:case"end":return e.stop()}}),e,null,[[0,10]])})));return function(t){return e.apply(this,arguments)}}(),O=function(){var e=C(regeneratorRuntime.mark((function e(t,n,r){var o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,"noPhoto.jpg"===t.body.oldPhoto){e.next=7;break}return e.next=4,k.deleteObject({Bucket:m.a.production.bucket,Key:t.body.oldPhoto}).promise();case 4:return o=t.body.oldPhoto.split("."),e.next=7,k.deleteObject({Bucket:m.a.production.bucket,Key:"".concat(o[0],".webp")}).promise();case 7:r(),e.next=13;break;case 10:return e.prev=10,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:e.t0}));case 13:case"end":return e.stop()}}),e,null,[[0,10]])})));return function(t,n,r){return e.apply(this,arguments)}}(),N=function(){var e=C(regeneratorRuntime.mark((function e(t,n,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,"noPhoto.jpg"===t.photNameToDelete){e.next=4;break}return e.next=4,k.deleteObject({Bucket:m.a.production.bucket,Key:t.photNameToDelete}).promise();case 4:n.json(t.result),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n,r){return e.apply(this,arguments)}}(),I=function(){var e=C(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,k.getObject({Bucket:m.a.production.bucket,Key:t.params.pdfName}).promise();case 3:r=e.sent,n.writeHead(200,{"Content-Type":"aplication/pdf"}),n.write(r.Body,"binary"),n.end(null,"binary"),e.next=12;break;case 9:return e.prev=9,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:e.t0}));case 12:case"end":return e.stop()}}),e,null,[[0,9]])})));return function(t,n){return e.apply(this,arguments)}}(),A=d()({storage:l()({s3:k,bucket:m.a.production.bucket,metadata:function(e,t,n){n(null,Object.assign({},e.body))},key:function(e,t,n){var r=t.originalname.split(".")[1];n(null,"IMG-"+Date.now().toString()+"."+r)}}),limits:{fileSize:2e6},fileFilter:function(e,t,n){t.originalname.match(/\.(jpg|jpeg|png)$/)||n(new Error("Please upload JPG and PNG images only!")),t.size>2e6&&n(new Error("Tamaño Exedido!")),n(void 0,!0)}}),R=(d()({storage:l()({s3:k,bucket:m.a.production.bucket,metadata:function(e,t,n){n(null,Object.assign({},e.body))},key:function(e,t,n){var r=t.originalname.split(".")[1];n(null,"STI_".concat(e.params.codigo,"_").concat(e.params.subCat),"."+r)}}),limits:{fileSize:2e6},fileFilter:function(e,t,n){t.originalname.match(/\.(jpg|jpeg|png)$/)||n(new Error("Please upload JPG and PNG images only!")),t.size>2e6&&n(new Error("Tamaño Exedido!")),n(void 0,!0)}}),d()({storage:l()({s3:k,bucket:m.a.production.bucket,metadata:function(e,t,n){n(null,Object.assign({},e.body))},key:function(e,t,n){n(null,"ficha-"+e.params.codigo+".pdf")}}),limits:{fileSize:1e6},fileFilter:function(e,t,n){t.originalname.match(/\.(pdf)$/)||n(new Error("Please upload PDF only!")),n(void 0,!0)}})),_=function(e,t,n){var r=e.file;if(!r){var o=new Error("Please upload a file");return o.httpStatusCode=400,n(o)}e.uploadInfo={statusCode:200,status:"success",uploadedFile:r},n()},P=function(){var e=C(regeneratorRuntime.mark((function e(t,n,r){var o,a,s,u,d;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,o=t.file){e.next=6;break}return(a=new Error("Please upload a file")).httpStatusCode=400,e.abrupt("return",r(a));case 6:return s=o.key.split("."),e.next=9,k.getObject({Bucket:m.a.production.bucket,Key:o.key}).promise();case 9:return u=e.sent,e.next=12,i.a.buffer(u.Body,{plugins:[c()({quality:50})]});case 12:return d=e.sent,e.next=15,k.upload({Key:"".concat(s[0],".webp"),CacheControl:"max-age=604800",ACL:"public-read",ContentType:"image/webp",Body:d,Bucket:m.a.production.bucket}).promise();case 15:t.fileName=o.key,t.uploadInfo={statusCode:200,status:"success",uploadedFile:o},r(),e.next=23;break;case 20:return e.prev=20,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:"Ocurrio un error inesperado. Intentelo denuevo"}));case 23:case"end":return e.stop()}}),e,null,[[0,20]])})));return function(t,n,r){return e.apply(this,arguments)}}()},function(e,t){e.exports=require("jsonwebtoken")},function(e,t,n){"use strict";n.d(t,"a",(function(){return o})),n.d(t,"c",(function(){return a})),n.d(t,"b",(function(){return i}));var r=n(3),o=new r.Schema({name:{type:String},nameSecond:{type:String},cantidadDisponible:{type:Number},cantidadVenta:{type:Number}},{_id:!1}),a=new r.Schema({codigo:{type:String,required:!0,trim:!0},tipo:{type:String,trim:!0,default:"producto"},name:{type:String,trim:!0},descripcion:{type:String,trim:!0},priceIGV:{type:Number,required:!0,trim:!0},priceNoIGV:{type:Number,required:!0,trim:!0},priceCosto:{type:Number,default:0},cantidad:{type:Number,required:!0,trim:!0,min:0},cantidadSC:{type:[o],default:[]},totalPrice:{type:Number},totalPriceNoIGV:{type:Number},unidadDeMedida:{type:String},photo:{type:String},ventaCod:{type:String}},{_id:!1}),i=new r.Schema({type:{type:String,required:!0},name:{type:String,trim:!0,default:""},codigo:{type:Number,trim:!0},direccion:{type:String}},{_id:!1})},function(e,t){e.exports=require("bcrypt")},function(e,t,n){"use strict";n.d(t,"a",(function(){return v})),n.d(t,"c",(function(){return $})),n.d(t,"b",(function(){return w}));var r=n(16),o=n(17),a=n.n(o),i=n(1);function s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var c=function(){function e(t,n,r,o,a,i,s,c,u){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.unidad_de_medida=t,this.codigo=n,this.descripcion=r,this.cantidad=o,this.valor_unitario=a,this.precio_unitario=i,this.subtotal=s,this.tipo_de_igv=1,this.igv=c,this.total=u}var t,n,r;return t=e,(n=[{key:"toString",value:function(){return JSON.stringify(this)}},{key:"toJSON",value:function(e){var t={},n=e||this;Object.getOwnPropertyNames(n).forEach((function(e){var r=n[e];"toJSON"!==e&&"constructor"!==e&&(t[e]="function"!=typeof r?r:r.bind(t))}));var r=Object.getPrototypeOf(n);return null!==r&&Object.keys(this.toJSON(r)).forEach((function(e){t[e]||"constructor"===e||"toJSON"===e||("function"!=typeof r[e]?t[e]=r[e]:t[e]=r[e].bind(t))})),t}}])&&s(t.prototype,n),r&&s(t,r),e}();function u(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var d=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.operacion="generar_comprobante",this.tipo_de_comprobante=t.tipo_de_comprobante,1===this.tipo_de_comprobante?(this.cliente_tipo_de_documento="6",this.serie="FFF1"):(this.cliente_tipo_de_documento="1",this.serie="BBB1"),this.numero=t.numero,this.sunat_transaction=1,this.cliente_numero_de_documento=t.cliente_numero_de_documento,this.cliente_denominacion=t.cliente_denominacion,this.cliente_direccion=t.cliente_direccion||"",this.cliente_email=t.cliente_email||"",this.fecha_de_emision=t.fecha_de_emision,this.moneda=1,this.porcentaje_de_igv=18,this.total_gravada=t.total_gravada,this.total_igv=t.total_igv,this.total=t.total,this.detraccion=!1,this.enviar_automaticamente_a_la_sunat=!0,this.enviar_automaticamente_al_cliente=!1,this.formato_de_pdf="A4",this.items=t.items||[],this.guias=t.guias||[],this.codigo_unico=t.codigo_unico||"",this.cliente_email=t.cliente_email||"",this.enviar_automaticamente_al_cliente=t.enviar_automaticamente_al_cliente||!1,this.medio_de_pago=t.medio_de_pago}var t,n,r;return t=e,(n=[{key:"toString",value:function(){return Object.keys(this)}},{key:"toJSON",value:function(e){var t={},n=e||this;Object.getOwnPropertyNames(n).forEach((function(e){var r=n[e];"toJSON"!==e&&"constructor"!==e&&(t[e]="function"!=typeof r?r:r.bind(t))}));var r=Object.getPrototypeOf(n);return null!==r&&Object.keys(this.toJSON(r)).forEach((function(e){t[e]||"constructor"===e||"toJSON"===e||("function"!=typeof r[e]?t[e]=r[e]:t[e]=r[e].bind(t))})),t}}])&&u(t.prototype,n),r&&u(t,r),e}();function p(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var l=function(){function e(t,n,r,o,a,i){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.tipo_de_comprobante=t,this.numero=n,this.cliente_numero_de_documento=r,this.cliente_denominacion=o,this.fecha_de_emision=this.getNowDate(),this.items=[],this.guias=[],this.codigo_unico=a,this.medio_de_pago=i}var t,n,o;return t=e,(n=[{key:"getNowDate",value:function(){var e=r.DateTime.local().setZone("UTC-5").toLocaleString().split("/"),t=e[0];return e[0]=e[1],e[1]=t,console.log(e.join("-")),e.join("-")}},{key:"addDireccion",value:function(e){this.cliente_direccion=e}},{key:"addPrecios",value:function(e,t,n){this.total=n,this.total_gravada=e,this.total_igv=t}},{key:"addItem",value:function(e){this.items.push(e)}},{key:"addGuide",value:function(e){this.guias.push(e)}},{key:"build",value:function(){return new d(this)}},{key:"addEmail",value:function(e){this.enviar_automaticamente_al_cliente=!0,this.cliente_email=e}}])&&p(t.prototype,n),o&&p(t,o),e}(),m=n(44);function g(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function f(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function y(e,t,n,r,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function b(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function i(e){y(a,r,o,i,s,"next",e)}function s(e){y(a,r,o,i,s,"throw",e)}i(void 0)}))}}i.a.production.log();var v=function(){var e=b(regeneratorRuntime.mark((function e(){var t,n,r,o,s,c,u=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=u.length>0&&void 0!==u[0]?u[0]:1,n=u.length>1&&void 0!==u[1]?u[1]:"",r=u.length>2&&void 0!==u[2]?u[2]:0,o=u.length>3&&void 0!==u[3]?u[3]:"",e.prev=4,s={operacion:"generar_anulacion",tipo_de_comprobante:t,serie:n,numero:r,motivo:o},e.next=8,a()("https://api.nubefact.com/api/v1/9e79db57-8322-4c1a-ac73-fa5093668c3c",{method:"post",headers:{"Content-Type":"application/json",Authorization:i.a.production.nbfToken},body:JSON.stringify(s)}).then((function(e){return e.json()}));case 8:return c=e.sent,e.abrupt("return",c.enlace_del_pdf);case 12:throw e.prev=12,e.t0=e.catch(4),e.t0;case 15:case"end":return e.stop()}}),e,null,[[4,12]])})));return function(){return e.apply(this,arguments)}}(),h=function(){var e=r.DateTime.local().setZone("UTC-5").toLocaleString().split("/"),t=e[0];return e[0]=e[1],e[1]=t,e.join("-")},$=function(e,t,n){if(!e.body.venta.guia)return n();var r=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?g(Object(n),!0).forEach((function(t){f(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):g(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}({},m);r.numero=e.countGuia+1,"factura"===e.ventResult.documento.type?r.cliente_tipo_de_documento=6:"boleta"===e.ventResult.documento.type&&(r.cliente_tipo_de_documento=1);var o=7===e.ventResult.documento.codigo.toString().length||10===e.ventResult.documento.codigo.toString().length?"0"+e.ventResult.documento.codigo.toString():e.ventResult.documento.codigo;r.cliente_numero_de_documento=o,r.cliente_denominacion=e.ventResult.documento.name,r.cliente_direccion=e.ventResult.documento.direccion||"",r.fecha_de_emision=h(),r.fecha_de_inicio_de_traslado=h(),r.numero_de_bultos=e.body.venta.bultos,r.peso_bruto_total=e.body.venta.peso,8===e.body.venta.transportista_codigo.length?(r.transportista_documento_tipo=1,r.tipo_de_transporte="02"):(r.transportista_documento_tipo=6,r.tipo_de_transporte="01"),r.transportista_documento_numero=e.body.venta.transportista_codigo,r.transportista_denominacion=e.body.venta.transportista_nombre,r.transportista_placa_numero=e.body.venta.transportista_placa,r.conductor_documento_tipo=r.transportista_documento_tipo,r.conductor_documento_numero=r.transportista_documento_numero,r.conductor_denominacion=r.transportista_denominacion,r.punto_de_partida_ubigeo=e.body.venta.partida_ubigeo,r.punto_de_partida_direccion=e.body.venta.partida_direccion,r.punto_de_llegada_ubigeo=e.body.venta.llegada_ubigeo,r.punto_de_llegada_direccion=e.body.venta.llegada_direccion,r.formato_de_pdf="A4",r.cliente_email=e.ventResult.cliente_email||"",r.enviar_automaticamente_a_la_sunat=!0,r.enviar_automaticamente_al_cliente=!0,e.ventResult.itemsVendidos.forEach((function(e){var t={unidad_de_medida:"NIU",codigo:e.codigo,descripcion:e.name+" | "+e.descripcion,cantidad:e.cantidad};"UND"===e.unidadDeMedida?t.unidad_de_medida="NIU":"PAR"===e.unidadDeMedida?t.unidad_de_medida="PR":"CAJA"===e.unidadDeMedida&&(t.unidad_de_medida="BX"),r.items.push(t)})),a()("https://api.nubefact.com/api/v1/9e79db57-8322-4c1a-ac73-fa5093668c3c",{method:"post",headers:{"Content-Type":"application/json",Authorization:i.a.production.nbfToken},body:JSON.stringify(r)}).then((function(e){return e.json()})).then((function(t){e.sunat_guia=t,t.errors&&console.log("HANDLE"),n()})).catch((function(e){return t.status(e.status).json(e)}))},x=function(e){var t=e.medio_de_pago.split("|")[0],n=e.medio_de_pago.split("|")[1],r="";switch(t){case"efectivo":r="Efectivo";break;case"tarjeta":r="Tarjeta: "+n;break;case"yape":r="Yape: "+n;break;case"otro":r=n}return r},w=function(e,t,n){var r={};if("boleta"===e.ventResult.documento.type)r=function(e,t,n){var r="";if(e.documento.codigo.toString().length<8)for(var o=0;o<8-e.documento.codigo.toString().length;o++)r+="0";var a=e.documento.codigo.toString().length<8?r+e.documento.codigo.toString():e.documento.codigo,i=new l(2,1+t,a,e.documento.name,e.codigo,x(e));return i.addPrecios(e.totalPriceNoIGV,e.totalPrice-e.totalPriceNoIGV,e.totalPrice),e.cliente_email&&i.addEmail(e.cliente_email),e.itemsVendidos.forEach((function(e){var t=new c("NIU",e.codigo,e.name+" | "+e.descripcion,e.cantidad,e.priceNoIGV,e.priceIGV,e.totalPriceNoIGV,e.totalPrice-e.totalPriceNoIGV,e.totalPrice);"UND"===e.unidadDeMedida?t.unidad_de_medida="NIU":"PAR"===e.unidadDeMedida?t.unidad_de_medida="PR":"CAJA"===e.unidadDeMedida&&(t.unidad_de_medida="BX"),i.addItem(t.toJSON())})),e.guia&&i.addGuide({guia_tipo:1,guia_serie_numero:n.serie.toString()+"-"+n.numero}),i.build().toJSON()}(e.ventResult,e.count,e.sunat_guia);else{if("factura"!==e.ventResult.documento.type)return t.json({message:"Succes||".concat(e.ventResult.codigo),_sunat:null});r=function(e,t,n){var r="";if(e.documento.codigo.toString().length<11)for(var o=0;o<11-e.documento.codigo.toString().length;o++)r+="0";var a=e.documento.codigo.toString().length<11?r+e.documento.codigo.toString():e.documento.codigo,i=new l(1,1+t,a,e.documento.name,e.codigo,x(e));return i.addPrecios(e.totalPriceNoIGV,e.totalPrice-e.totalPriceNoIGV,e.totalPrice),e.cliente_email&&i.addEmail(e.cliente_email),e.itemsVendidos.forEach((function(e){var t=new c("NIU",e.codigo,e.name+" | "+e.descripcion,e.cantidad,e.priceNoIGV,e.priceIGV,e.totalPriceNoIGV,e.totalPrice-e.totalPriceNoIGV,e.totalPrice);"UND"===e.unidadDeMedida?t.unidad_de_medida="NIU":"PAR"===e.unidadDeMedida?t.unidad_de_medida="PR":"CAJA"===e.unidadDeMedida&&(t.unidad_de_medida="BX"),i.addItem(t.toJSON())})),i.addDireccion(e.documento.direccion),e.guia&&i.addGuide({guia_tipo:1,guia_serie_numero:n.serie.toString()+"-"+n.numero}),i.build().toJSON()}(e.ventResult,e.count,e.sunat_guia)}a()("https://api.nubefact.com/api/v1/9e79db57-8322-4c1a-ac73-fa5093668c3c",{method:"post",headers:{"Content-Type":"application/json",Authorization:i.a.production.nbfToken},body:JSON.stringify(r)}).then((function(e){return e.json()})).then((function(t){e.sunat=t,n()})).catch((function(n){t.status(n.status||500).json({message:"Succes||".concat(e.ventResult.codigo),_sunat:null})}))}},function(e,t){e.exports=require("path")},function(e,t,n){"use strict";n.d(t,"a",(function(){return s}));var r=n(3),o=n(8),a=n.n(o);function i(e,t,n,r,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}var s=new r.Schema({username:{type:String,required:!0,unique:!0,lowercase:!0,trim:!0},hashPassword:{type:String},type:{type:String,required:!0,trim:!0},created_date:{type:Date,default:Date.now},displayName:{type:String,required:!0,trim:!0},email:{type:String,trim:!0,unique:!0},dirOne:{type:String,trim:!0},dirTwo:{type:String,trim:!0},reference:{type:String,trim:!0},ciudad:{type:String,trim:!0},nombre:{type:String,trim:!0},apellido:{type:String,trim:!0},nomape:{type:String},googleCod:{type:String,unique:!0},documento:{type:String,trim:!0},tipoPersona:{type:String},verified:{type:Boolean,default:!1},celular:{type:String},ventaActiva:{type:[String],default:[]},carrito:{type:String,default:"not"}});s.methods.comparePassword=function(){var e,t=(e=regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,a.a.compare(t,n);case 3:return r=e.sent,e.abrupt("return",r);case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",e.t0);case 10:case"end":return e.stop()}}),e,null,[[0,7]])})),function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function s(e){i(a,r,o,s,c,"next",e)}function c(e){i(a,r,o,s,c,"throw",e)}s(void 0)}))});return function(e,n){return t.apply(this,arguments)}}()},function(e,t,n){"use strict";var r=n(3),o=n(7),a=new r.Schema({user:{type:String,trim:!0},rating:{type:Number,default:0},date:{type:Date,default:Date.now}},{_id:!1}),i=new r.Schema({name:{type:String,trim:!0,required:!0},nameSecond:{type:String,trim:!0},cantidad:{type:Number,min:0}},{_id:!1}),s=new r.Schema({name:{type:String,trim:!0,required:!0},nameSecond:{type:String,trim:!0},order:{type:[i]}},{_id:!1}),c=new r.Schema({date:{type:Date,default:Date.now},cantidad:{type:Number,default:0,min:0},tipo:{type:Boolean,default:!1},comentario:{type:String,trim:!0},costoVar:{type:Number},cantidadSC:{type:[o.a],default:[]},usuario:{type:String,default:"desconocido"}},{_id:!1}),u=new r.Schema({name:{type:String,required:!0,trim:!0,unique:!0},nameLowerCase:{type:String,trim:!0,lowercase:!0},priceIGV:{type:Number,required:!0},priceNoIGV:{type:Number},cantidad:{type:Number,default:0,min:0},subConteo:{type:s},variaciones:{type:[c]},codigo:{type:String,required:!0,trim:!0,unique:!0},tipo:{type:String,required:!0,trim:!0},subTipo:{type:String,default:"noone",trim:!0},unidadDeMedida:{type:String,default:"UND",trim:!0},oferta:{type:Number,default:0},date:{type:Date,default:Date.now},description:{type:String,trim:!0},photo:{type:String,trim:!0,default:"noPhoto.jpg"},ficha:{type:Boolean,default:!1},marca:{type:String,default:"noone"},costoPropio:{type:Number},multiSearchParams:{type:String,trim:!0},deleted:{type:Boolean,default:!1},tags:{type:[String],default:[]},caracteristicas:{type:[String],default:[]},orderNumber:{type:Number,default:-1},reviews:{type:[a],default:[]},googleCategory:{type:String,default:"2047"}});u.index({nameLowerCase:"text",tipo:"text",subTipo:"text",marca:"text",description:"text",tags:"text"}),t.a=u},function(e,t,n){"use strict";var r=n(3),o=n(7),a=new r.Schema({codigo:{type:String,required:!0,trim:!0,unique:!0},totalPrice:{type:Number,trim:!0,required:!0},totalPriceNoIGV:{type:Number,trim:!0,required:!0},estado:{type:String,trim:!0,required:!0},documento:{type:o.b},itemsVendidos:{type:[o.c],required:!0},date:{type:Date,default:Date.now},vendedor:{type:String},tipoVendedor:{type:String,default:"admin"},medio_de_pago:{type:String},linkComprobante:{type:String},serie:{type:String},tipoComprobante:{type:String},numero:{type:Number},cliente_email:{type:String},guia_serie:{type:String},guia_numero:{type:String},guia:{type:Boolean,default:!1},guia_link:{type:String},carrito_venta:{type:Boolean,default:!1},estado_carrito_comprando:{type:Boolean,default:!1}});t.a=a},function(e,t){e.exports=require("aws-sdk")},function(e,t){e.exports=require("excel4node")},function(e,t){e.exports=require("luxon")},function(e,t){e.exports=require("node-fetch")},function(e,t){e.exports=require("tinify")},function(e,t,n){"use strict";(function(e){n.d(t,"b",(function(){return g})),n.d(t,"a",(function(){return f}));var r=n(37),o=n(38),a=n.n(o),i=n(10),s=n.n(i),c=n(39);function u(e,t,n,r,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function d(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function i(e){u(a,r,o,i,s,"next",e)}function s(e){u(a,r,o,i,s,"throw",e)}i(void 0)}))}}var p=n(1).a.production,l=Object(c.promisify)(r.readFile),m=a.a.createTransport({host:p.BHOST,port:p.BPORT,secure:!1,auth:{user:p.BUSER,pass:p.BPASS}}),g=function(){var e=d(regeneratorRuntime.mark((function e(t,n){var r,o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,l(s.a.resolve("server/lib/emailContacto.html"),{encoding:"utf8"});case 3:return r=e.sent,o=r.replace("#replaceWithLinkOne","Mensaje de ".concat(t.body.nombre," ").concat(t.body.apellido,", su correo es: ").concat(t.body.email)),a=o.replace("#replaceWithLinkTwo",t.body.mensaje),e.next=8,m.sendMail({from:"siriodinar-no-replay@siriodinar.com",to:p.BUSER,subject:"Mensaje Contacto",html:a});case 8:n.json({enviado:!0}),e.next=14;break;case 11:return e.prev=11,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 14:case"end":return e.stop()}}),e,null,[[0,11]])})));return function(t,n){return e.apply(this,arguments)}}(),f=function(){var e=d(regeneratorRuntime.mark((function e(t,n){var r,o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,l(s.a.resolve("server/lib/email.html"),{encoding:"utf8"});case 3:return r=e.sent,t.savedUSer.hashPassword=void 0,o="".concat(p.link,"auth/confirmacion/").concat(t.savedUSer._id),a=r.replace("#replaceWithLink",'<a style="width: 400px; font-size: 20px; text-align: center; margin-top: 0.67em" href="'.concat(o,'" target="_blank">').concat(o,"</a>")),e.next=9,m.sendMail({from:"siriodinar-no-replay@siriodinar.com",to:t.savedUSer.email,subject:"Confimar registro de cuenta en Sirio Dinar",html:a});case 9:n.json(t.savedUSer),e.next=15;break;case 12:return e.prev=12,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({link:!1}));case 15:case"end":return e.stop()}}),e,null,[[0,12]])})));return function(t,n){return e.apply(this,arguments)}}()}).call(this,"/")},function(e,t,n){"use strict";(function(e){var r=n(33),o=n.n(r),a=n(34),i=n.n(a),s=n(26),c=n.n(s),u=n(4),d=n.n(u),p=n(35),l=n.n(p),m=n(6),g=n.n(m),f=n(10),y=n.n(f),b=n(18),v=n.n(b),h=n(1),$=n(36),x=n(51),w=n(48),S=n(43),j=n(49),V=n(50),C=n(28),k=n.n(C),T=n(46),O=n(47),N=n.n(O);v.a.key=h.a.production.tinyKey;var I=d()(),A=h.a.production.log();I.use(l()()),I.use(o()()),I.use(i()()),I.use(N()(":method :url")),I.options("*",c()({credentials:!0,origin:h.a.production.origin})),I.use(c()({credentials:!0,origin:h.a.production.origin})),I.use(d.a.json()),I.use(d.a.urlencoded({extended:!0})),I.use((function(e,t,n){if(e.headers&&e.headers.authorization&&"JWT"===e.headers.authorization.split(" ")[0]){var r=e.headers.authorization;g.a.verify(r.split(" ")[1],h.a.production.jwtKey,{audience:r.split(" ")[2]+" "+r.split(" ")[3]},(function(r,o){if(r)return e.user=void 0,t.status(401).json({message:"Usuario No Autorizado"});e.user=o,n()}))}else e.user=void 0,n()})),I.use("/inventario",j.a),I.use("/carrito",x.a),I.use("/auth",$.a),I.use("/ventas",V.a),I.use("/email",S.a),I.use("/coti",w.a),I.use("/api-docs",k.a.serve,k.a.setup(T)),I.get("/",(function(e,t){return t.redirect("/api-docs")})),I.use("/static",d.a.static(y.a.join(e,"uploads"))),I.use((function(e,t,n,r){return n.status(e.status||500),A.error(e),A.info(e),n.json({error:{message:e.message}})})),t.a=I}).call(this,"/")},function(e,t){e.exports=require("imagemin")},function(e,t){e.exports=require("imagemin-webp")},function(e,t){e.exports=require("multer")},function(e,t){e.exports=require("multer-s3")},function(e){e.exports=JSON.parse('{"name":"inv-mannager","version":"1.7.0","description":"Manejo General De Inventario De Sirio Dinar","main":"index.js","scripts":{"build":"webpack -p","start":"node ./dist/main.js","dev:start":"nodemon --exec babel-node ./bin/www.js | bunyan"},"keywords":["inventario","siriodinar"],"author":"Tac Etarip","license":"ISC","devDependencies":{"@babel/core":"^7.10.2","@babel/node":"^7.10.1","@babel/preset-env":"^7.10.2","babel-loader":"^8.1.0","eslint":"^7.30.0","webpack":"^4.43.0","webpack-cli":"^3.3.12","webpack-node-externals":"^2.5.0"},"dependencies":{"aws-sdk":"^2.713.0","axios":"^0.21.1","babel-polyfill":"^6.26.0","bcrypt":"^5.0.1","body-parser":"^1.19.0","bunyan":"^1.8.14","compression":"^1.7.4","cookie-parser":"^1.4.5","cors":"^2.8.5","dotenv":"^8.2.0","excel4node":"^1.7.2","express":"^4.17.1","helmet":"^3.23.3","imagemin":"^7.0.1","imagemin-webp":"^6.0.0","jsonwebtoken":"^8.5.1","luxon":"^1.26.0","mongoose":"^5.12.14","morgan":"^1.10.0","multer":"^1.4.2","multer-s3":"^2.9.0","node-fetch":"^2.6.1","nodemailer":"^6.4.17","passport":"^0.4.1","passport-google-oauth":"^2.0.0","passport-google-oauth20":"^2.0.0","pdfkit":"^0.11.0","pdfmake":"^0.1.70","replace-in-file":"^6.1.0","sitemap":"^7.0.0","swagger-jsdoc":"^6.1.0","swagger-ui-express":"^4.1.6","throng":"^5.0.0","tinify":"^1.6.0-beta.2"},"engines":{"node":"12.18.x"}}')},function(e,t){e.exports=require("cors")},function(e,t){e.exports=require("axios")},function(e,t){e.exports=require("swagger-ui-express")},function(e,t){e.exports=require("dotenv")},function(e,t){e.exports=require("http")},function(e,t){e.exports=require("throng")},function(e,t){e.exports=require("bunyan")},function(e,t){e.exports=require("compression")},function(e,t){e.exports=require("cookie-parser")},function(e,t){e.exports=require("helmet")},function(e,t,n){"use strict";var r=n(4),o=n(19),a=n(0),i=new r.Router;i.use(a.w.initialize()),i.post("/cambiarContrasena",a.f,a.g),i.post("/confirmarContr",a.f,a.h),i.put("/actCelular",a.f,a.a),i.post("/agregarDireccion",a.f,a.c),i.post("/agregarDocumento",a.f,a.d),i.post("/register",a.x),i.get("/google/callback",a.w.authenticate("google",{failureRedirect:"/failed",session:!1}),a.p,a.s),i.get("/google",a.w.authenticate("google",{scope:["profile","email"],session:!1})),i.post("/login",a.r),i.get("/userEx/:username",a.C),i.get("/emailEx/:email",a.k),i.post("/registerlow",a.y,o.a),i.post("/isValid",a.q),i.get("/confirmacion/:idUser",a.i),i.post("/loginfast",a.t,a.j),i.post("/loginGoogleRegistro",a.z),i.post("/getLoginInfoFromToken",a.l),i.get("/getUserInfo/:username",a.f,a.n),i.get("/getOwnUser",a.f,a.m),t.a=i},function(e,t){e.exports=require("fs")},function(e,t){e.exports=require("nodemailer")},function(e,t){e.exports=require("util")},function(e,t){e.exports=require("passport")},function(e,t){e.exports=require("passport-google-oauth20")},function(e,t){e.exports=require("pdfmake")},function(e,t,n){"use strict";var r=n(4),o=n.n(r),a=n(19),i=o.a.Router();i.post("/enviarMensaje",a.b),t.a=i},function(e){e.exports=JSON.parse('{"operacion":"generar_guia","tipo_de_comprobante":7,"serie":"TTT1","numero":1800,"cliente_tipo_de_documento":6,"cliente_numero_de_documento":"20517738701","cliente_denominacion":"CLINICA JESUS DEL NORTE S.A.C","cliente_direccion":"","cliente_email":"","cliente_email_1":"","cliente_email_2":"","fecha_de_emision":"2020-12-16T00:00:00","observaciones":"","motivo_de_traslado":"01","peso_bruto_total":0,"numero_de_bultos":10,"tipo_de_transporte":"02","fecha_de_inicio_de_traslado":"2020-12-16T00:00:00","transportista_documento_tipo":6,"transportista_documento_numero":"20538260674","transportista_denominacion":"AQUALIV SAC","transportista_placa_numero":"AVD-798","conductor_documento_tipo":1,"conductor_documento_numero":"40513206","conductor_denominacion":"DIAZ RIVERA HELMER","punto_de_partida_ubigeo":"PROV0008","punto_de_partida_direccion":"AV. PROLONGACION CHILLON MZ B LT 1 INT 1","punto_de_llegada_ubigeo":"PROV0008","punto_de_llegada_direccion":"AV. CARLOS IZAGUIRRE NRO. 153 Z.I. NORTE LIMA - LIMA - INDE","enviar_automaticamente_a_la_sunat":true,"enviar_automaticamente_al_cliente":true,"codigo_unico":"","formato_de_pdf":"","items":[]}')},function(e,t){e.exports=require("pdfkit")},function(e){e.exports=JSON.parse('{"openapi":"3.0.2","info":{"license":{"name":"MIT","url":"https://github.com/TacEtarip/sirioinventarioserver/blob/master/LICENSE"},"contact":{"email":"hu3rtas@outlook.com","name":"Luis Huertas","url":"https://github.com/TacEtarip/sirioinventarioserver"},"title":"Sirio Dinar Inventario API","version":"1.0","description":"Rest API para el uso del inventari de la empresa Sirio Dinar. Front End: https://inventario.siriodinar.com/"},"servers":[{"url":"https://inventario-sirio-dinar.herokuapp.com"},{"url":"http://localhost:5000"}],"tags":[{"name":"tipos","description":"Manejar los tipos de items."},{"name":"items","description":"Manejar los items"},{"name":"ventas","description":"Manejar las ventas"},{"name":"reportes","description":"Reportes sobre inventario."},{"name":"organizar","description":"Organizar la presentación de los tipos, sub-tipo e items."},{"name":"utilidades","description":"Utilidades para el inventario."},{"name":"auth","description":"Manejar la autenticación y usuarios."}],"components":{"responses":{"500":{"description":"Ocurrio un error en el servidor","content":{"aplication/json":{"schema":{"type":"object","properties":{"errorMSG":{"type":"string"}}}}}},"Error-401":{"description":"No exite un token de autorización valido"},"Succes":{"description":"Exito al procesar request"}},"securitySchemes":{"JWT TOKEN TRANSACCIONAL":{"type":"http","scheme":"bearer","bearerFormat":"JWT #token #usuario #tipo"},"JWT TOKEN ADMIN":{"type":"http","scheme":"bearer","bearerFormat":"JWT #token #usuario #tipo"},"JWT TOKEN ALL":{"type":"http","scheme":"bearer","bearerFormat":"JWT #token #usuario #tipo"}},"schemas":{"error401":{"description":"NO AUTORIZADO","type":"object","properties":{"message":{"type":"string"}}},"tipo":{"type":"object","required":["name"],"properties":{"name":{"type":"string","description":"Nombre del tipo"},"date":{"type":"string","description":"Fecha de creación del tipo","readOnly":true},"codigo":{"type":"string","description":"Codigo del tipo"},"subTipo":{"type":"array","description":"Listado de sub-tipos","items":{"type":"string","description":"Nombre del sub-tipo"}},"subTipoLink":{"type":"array","description":"Listado las imagenes de los sub-tipos","items":{"type":"string","description":"URL de imagén del sub-tipo"}},"deleted":{"type":"boolean"},"link":{"type":"string","description":"URL de imagén del tipo"},"order":{"type":"number","default":-1,"description":"Orden en que se muestra el tipo"}},"example":{"subTipo":["Respiradores 3M","Filtros 3M","Respiradores Master","Mascarillas","Respiradores Astara","Retenedores para filtros"],"name":"Pro. Respiratoria","date":"2021-01-14T20:04:04.125+00:00","codigo":"1610645929520","deleted":false,"link":"img-1610645929520-1621997665489.png","subTipoLink":["IMG-1622763250845.png","img-1622747657121.png","IMG-1622763288076.png","IMG-1622763339734.png","IMG-1631032975632.jpg","IMG-1630012297019.jpg"],"order":1}},"review":{"type":"object","required":["name"],"properties":{"user":{"type":"string","description":"Username de quien realizo la review"},"rating":{"type":"number","description":"Rating del item de 1 a 5"},"date":{"type":"string","description":"Fecha de publicación de la review"}}},"cantidadSC":{"type":"object","required":["name"],"properties":{"name":{"type":"string","description":"Nombre de la sub cantidad"},"nameSecond":{"type":"string","description":"Segundo nombre de la sub cantidad"},"cantidadDisponible":{"type":"number","description":"Cantidad disponible al momento de la variación"},"cantidadVenta":{"type":"number","description":"Cantidad"}}},"order":{"type":"object","required":["name"],"properties":{"name":{"type":"string","description":"Nombre especifico de la sub cantidad"},"nameSecond":{"type":"string","description":"Segundo especifico nombre de la sub cantidad"},"cantidad":{"type":"number","description":"Cantidad del subconteo"}}},"subConteo":{"type":"object","required":["name"],"properties":{"name":{"type":"string","description":"Nombre de la sub cantidad"},"nameSecond":{"type":"string","description":"Segundo nombre de la sub cantidad"},"order":{"type":"array","items":{"$ref":"#/components/schemas/order"}}}},"variacion":{"type":"object","properties":{"date":{"type":"string","description":"Fecha de la variación ISO STRING","readOnly":true},"tipo":{"type":"boolean","description":"Variación positiva o negativa"},"comentario":{"type":"string","description":"Comentario sobre la variación"},"costoVar":{"type":"number","description":"Costo de la variación"},"cantidad":{"type":"number","description":"Cantidad de variación"},"cantidadSC":{"type":"array","items":{"$ref":"#/components/schemas/cantidadSC"}},"usuario":{"type":"string","description":"Nombre del usuario que realizo la variación"}}},"item":{"type":"object","required":["name","priceIGV","tipo"],"properties":{"codigo":{"type":"string","description":"Codigo del producto, es auto generado."},"name":{"type":"string","description":"Nombre del producto"},"nameLowerCase":{"type":"string","description":"Nombre en minusculas"},"priceIGV":{"type":"number","description":" Precio del producto sin IGV"},"cantidad":{"type":"number","description":"Cantidad de items disponibles del producto"},"subConteo":{"$ref":"#/components/schemas/subConteo"},"variaciones":{"type":"array","items":{"$ref":"#/components/schemas/variacion"}},"tipo":{"type":"string","description":"Tipo al que pertenece el producto"},"subTipo":{"type":"string","description":"Sub tipo al que pertenece el producto"},"unidadDeMedida":{"type":"string","description":"Unidad de medida del item"},"oferta":{"type":"number","description":"Oferta del item"},"date":{"type":"string","description":"Fecha de creación del item ISO STRING","readOnly":true},"description":{"type":"string","description":"Descripción del producto"},"photo":{"type":"string","description":"URL de la foto de este item"},"ficha":{"type":"boolean","description":"Tiene una ficha este producto?"},"marca":{"type":"string","description":"Marca del item"},"costoPropio":{"type":"number","description":"Costo de compra de item"},"multiSearchParams":{"type":"string","description":"Parametros por los cuales puede ser buscado este item","deprecated":true},"deleted":{"type":"boolean","description":"Este item existe?"},"tags":{"type":"array","items":{"type":"string","description":"Tags del item"}},"caracteristicas":{"type":"array","items":{"type":"string","description":"Caracteristicas del item"}},"orderNumber":{"type":"number","description":"En que POS se muestra el nuemro"},"reviews":{"type":"array","items":{"$ref":"#/components/schemas/review"}},"googleCategory":{"type":"string","description":"Categoria del item segun google","default":"2047"}},"example":{"cantidad":425,"subTipo":"LENTES SPIDER","unidadDeMedida":"UND","oferta":0,"photo":"img-14SDLP4-1610836257167.jpeg","ficha":false,"marca":"CLUTE","deleted":false,"tags":[],"caracteristicas":["Lente de policarbonato de alta transparencia.","Proteccion de 99.9% de la radiacion UV.","Tratamiento anti-empañante que reduce la obstrucción de la visibilidad en ambientes húmedos y cambios bruscos de temperatura.","Tratamiento anti-rayadura que prolonga la vida útil del policarbonato."],"orderNumber":-2,"googleCategory":"2047","_id":"600368bd53a848001fc98ea4","name":"Lentes Alpine","priceIGV":35,"description":"Alipme","costoPropio":27,"tipo":"Protec. Visual","variaciones":[{"cantidad":432,"tipo":true,"usuario":"desconocido","date":"2021-01-16T22:29:17.386Z","comentario":"new item","costoVar":10800,"cantidadSC":[]},{"cantidad":1,"tipo":false,"usuario":"desconocido","date":"2021-02-17T22:49:35.594Z","comentario":"venta|SD01-000333","costoVar":35,"cantidadSC":[]},{"cantidad":1,"tipo":true,"usuario":"desconocido","date":"2021-02-17T23:01:24.220Z","comentario":"anular|SD01-000333","costoVar":35,"cantidadSC":[]},{"cantidad":2,"tipo":false,"usuario":"desconocido","date":"2021-06-08T22:44:08.841Z","comentario":"quitar|Actualización","costoVar":54,"cantidadSC":[]},{"cantidad":1,"tipo":false,"usuario":"desconocido","date":"2021-06-21T20:14:08.578Z","comentario":"venta|SD01-001013","costoVar":35,"cantidadSC":[]},{"cantidad":1,"tipo":false,"usuario":"admin","date":"2021-07-15T15:26:49.169Z","comentario":"venta|SD01-001157","costoVar":25,"cantidadSC":[]},{"cantidad":2,"tipo":false,"usuario":"desconocido","date":"2021-07-30T22:07:45.576Z","comentario":"quitar|Actualización","costoVar":54,"cantidadSC":[]},{"cantidad":1,"tipo":false,"usuario":"admin","date":"2021-08-27T22:15:32.180Z","comentario":"venta|SD01-001438","costoVar":35,"cantidadSC":[]}],"date":"2021-01-16T22:29:17.383Z","priceNoIGV":29.66,"codigo":"14SDLP4","nameLowerCase":"lentes alpine","__v":0,"reviews":[]}},"marca":{"type":"object","properties":{"name":{"type":"string","description":"Nombre de la marca"},"codigo":{"type":"string","description":"Codigo de la marca"},"ruc":{"type":"string"}}},"tag":{"type":"object","properties":{"name":{"type":"string","description":"Nombre del tag"},"deleted":{"type":"boolean"}}},"user":{"required":["username","email","created_date"],"type":"object","properties":{"username":{"type":"string"},"type":{"type":"string"},"created_date":{"type":"string"},"displayName":{"type":"string"},"email":{"type":"string"},"dirOne":{"type":"string"},"dirTwo":{"type":"string"},"reference":{"type":"string"},"ciudad":{"type":"string"},"nombre":{"type":"string"},"apellido":{"type":"string"},"nomape":{"type":"string"},"googleCod":{"type":"string"},"documento":{"type":"string"},"tipoPersona":{"type":"string"},"verified":{"type":"boolean"},"celular":{"type":"string"},"ventaActiva":{"type":"array","items":{"type":"string"}},"carrito":{"type":"string"}}},"login":{"type":"object","properties":{"username":{"type":"string"},"password":{"type":"string"}}},"authToken":{"type":"object","properties":{"displayName":{"type":"string"},"username":{"type":"string"},"message":{"type":"string"},"type":{"type":"string"},"token":{"type":"string"}}},"document":{"type":"object","properties":{"type":{"type":"string"},"name":{"type":"string"},"codigo":{"type":"number"},"direccion":{"type":"string"}}},"itemvendido":{"type":"object","properties":{"codigo":{"type":"string"},"tipo":{"type":"string"},"name":{"type":"string"},"descripcion":{"type":"string"},"priceIGV":{"type":"number"},"priceNoIGV":{"type":"number"},"priceCosto":{"type":"number"},"cantidad":{"type":"number"},"cantidadSC":{"type":"array","items":{"$ref":"#/components/schemas/cantidadSC"}},"totalPrice":{"type":"number"},"totalPriceNoIGV":{"type":"number"},"unidadDeMedida":{"type":"string"},"photo":{"type":"string"},"ventaCod":{"type":"string"}}},"venta":{"type":"object","properties":{"codigo":{"type":"string"},"totalPrice":{"type":"number"},"totalPriceNoIGV":{"type":"number"},"estado":{"type":"string"},"documento":{"$ref":"#/components/schemas/document"},"itemsVendidos":{"type":"array","items":{"$ref":"#/components/schemas/itemvendido"}},"date":{"type":"string"},"vendedor":{"type":"string"},"tipoVendedor":{"type":"string"},"medio_de_pago":{"type":"string"},"linkComprobante":{"type":"string"},"serie":{"type":"string"},"tipoComprobante":{"type":"string"},"numero":{"type":"number"},"cliente_email":{"type":"string"},"guia_serie":{"type":"string"},"guia_numero":{"type":"string"},"guia":{"type":"boolean"},"guia_link":{"type":"string"},"carrito_venta":{"type":"boolean"},"estado_carrito_comprando":{"type":"boolean"}}}}},"paths":{"/inventario/getTipos":{"get":{"tags":["tipos"],"summary":"Optener todos los tipos","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/tipo"}}}}}}}},"/inventario/getTipo/{nameTipo}":{"get":{"tags":["tipos"],"summary":"Obtener un tipo en especifico","parameters":[{"name":"nameTipo","in":"path","required":true,"allowEmptyValue":false,"example":"Pro. Respiratoria","schema":{"type":"string","description":"Nombre del tipo que deseamos"}}],"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/tipo"}}}}}}},"/inventario/addTipo":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["tipos"],"summary":"Agregar tipo","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/tipo"},"example":{"name":"Nuevo Tipo"}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/tipo"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/updateTipo":{"put":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["tipos"],"summary":"Actualizar tipo","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"codigo":{"type":"string","description":"Codigo del tipo"},"tipoName":{"type":"string","description":"Nuevo nombre del tipo"}}},"example":{"codigo":"123123","tipoName":"Tipo Editado"}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/tipo"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/deleteTipo/{codigo}":{"delete":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"parameters":[{"name":"codigo","in":"path","required":true,"allowEmptyValue":false,"example":"123456","schema":{"type":"string","description":"Codigo del tipo que deseamos eliminar"}}],"tags":["tipos"],"summary":"Elimina el tipo y todos los sub-tipos e items dentro del él.","responses":{"200":{"description":"Ok, Tipo eliminado","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/tipo"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/getSubTipos/{nameTipo}":{"get":{"tags":["tipos"],"summary":"Optener todos los sub-tipos","parameters":[{"name":"nameTipo","in":"path","required":true,"allowEmptyValue":false,"example":"Pro. Respiratoria","schema":{"type":"string","description":"Nombre del tipo que deseamos"}}],"responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"array","properties":{"subTipo":{"type":"array","items":{"type":"string"}}},"example":{"subTipo":["Respiradores 3M","Filtros 3M"]}}}}}}}},"/inventario/addSubTipo":{"put":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["tipos"],"summary":"Agregar sub-tipo","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"codigo":{"type":"string","description":"Codigo del tipo"},"subTipo":{"type":"string","description":"Nombre del sub-tipo"}}},"example":{"codigo":"123123","subTipo":"SubTipo Nuevo"}}}},"responses":{"200":{"$ref":"#/components/responses/Succes"},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/uptateSupTipos":{"put":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["tipos"],"summary":"Editar sub-tipo","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"codigo":{"type":"string","description":"Codigo del tipo"},"newSubName":{"type":"string","description":"Nuevo nombre del sub-tipo"},"antiguoSubName":{"type":"string","description":"Antiguo nombre del sub-tipo"}}},"example":{"codigo":"123123","newSubName":"SubTipo Nuevo","antiguoSubName":"SubTipo Antiguo"}}}},"responses":{"200":{"$ref":"#/components/responses/Succes"},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/deleteSupTipo/{codigo}/{subTipoName}":{"delete":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"parameters":[{"name":"codigo","in":"path","required":true,"allowEmptyValue":false,"example":"123456","schema":{"type":"string","description":"Codigo del tipo del sub-tipo que deseamos eliminar"}},{"name":"subTipoName","in":"path","required":true,"allowEmptyValue":false,"example":"Pro. Respiratoria","schema":{"type":"string","description":"Nombre del sub-tipo que se desea eliminar."}}],"tags":["tipos"],"summary":"Elimina el sub-tipo y todos los items dentro del él.","responses":{"200":{"description":"Ok, sub-tipo eliminado","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/tipo"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/getItem/cod/{codigo}":{"get":{"tags":["items"],"parameters":[{"name":"codigo","in":"path","required":true,"allowEmptyValue":false,"example":"1SDRP4","schema":{"type":"string","description":"Codigo del item"}}],"summary":"Obtener un item","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"$ref":"#/components/schemas/item"}}}}}}},"/inventario/getItems":{"get":{"tags":["items"],"deprecated":true,"summary":"Optener todos los items. No usar.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/item"}}}}}}}},"/inventario/getItemsDestacados":{"get":{"tags":["items"],"summary":"Obtener los items destacados","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/item"}}}}}}}},"/inventario/getItemsByType/{nameTipo}":{"get":{"tags":["items"],"parameters":[{"name":"nameTipo","in":"path","required":true,"allowEmptyValue":false,"example":"Pro. Respiratoria","schema":{"type":"string","description":"Nombre del tipo que deseamos"}}],"summary":"Obtener los items de un tipo","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/item"}}}}}}}},"/inventario/getItemsSubTipo/{nameTipo}/{subTipo}":{"get":{"tags":["items"],"parameters":[{"name":"nameTipo","in":"path","required":true,"allowEmptyValue":false,"example":"Pro. Respiratoria","schema":{"type":"string","description":"Nombre del tipo que deseamos"}},{"name":"subTipo","in":"path","required":true,"allowEmptyValue":false,"example":"Respiradores Master","schema":{"type":"string","description":"Nombre del sub-tipo que deseamos"}}],"summary":"Obtener los items de un sub-tipo","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/item"}}}}}}}},"/inventario/getItemsRelacionados/{tipo}/{codigo}":{"get":{"tags":["items"],"parameters":[{"name":"tipo","in":"path","required":true,"allowEmptyValue":false,"example":"Pro. Respiratoria","schema":{"type":"string","description":"Tipo del que buscar"}},{"name":"codigo","in":"path","required":true,"allowEmptyValue":false,"example":"1SDRP4","schema":{"type":"string","description":"Codigo del item del que queremos sacar items relacionados."}}],"summary":"Obtener los items realacionados, NOT COMPLETE","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/item"}}}}}}}},"/inventario/getItemsSearch/{searchTerms}":{"get":{"tags":["items"],"parameters":[{"name":"searchTerms","in":"path","required":true,"allowEmptyValue":false,"example":"Cualquier texto","schema":{"type":"string","description":"Terminos que se desean buscar"}}],"summary":"Obtener los items segun regex","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/item"}}}}}}}},"/inventario/addItem":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["items"],"summary":"Agregar item","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/item"},"example":{"cantidad":425,"subTipo":"LENTES SPIDER","unidadDeMedida":"UND","marca":"CLUTE","deleted":false,"googleCategory":"2047","name":"Lentes Alpine TEST","priceIGV":35,"description":"Alipme","costoPropio":27,"tipo":"Protec. Visual","priceNoIGV":29.66}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/item"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/updateItem":{"put":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["items"],"summary":"Actualizar item","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/item"},"example":{"codigo":"1SDRP4","cantidad":425,"unidadDeMedida":"UND","marca":"CLUTE","name":"Lentes Alpine TEST","priceIGV":35,"description":"Alipme","costoPropio":27,"tags":["Clute"]}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/item"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/uploadVariationSC":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["items"],"summary":"Actualizar item","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"codigo":{"type":"string"},"cantidad":{"type":"number"},"comentario":{"type":"string"},"tipo":{"type":"boolean"},"subConteo":{"$ref":"#/components/schemas/subConteo"}}}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/item"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/uploadVariationSimple":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["items"],"summary":"Actualizar item","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"codigo":{"type":"string"},"cantidad":{"type":"number"},"comentario":{"type":"string"},"tipo":{"type":"boolean"}}}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/item"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/addItemReview":{"post":{"security":[{"JWT TOKEN ALL":[]}],"tags":["items"],"summary":"Agrega una review al item.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/item"},"example":{"codigo":"1SDRP4","rating":5}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/item"}}}},"400":{"description":"Numero no valido","content":{"aplication/json":{"schema":{"type":"array","properties":{"errorMSG":{"description":"Mensaje de error"}}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/addCaracteristica":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["items"],"summary":"Agrega una caracteristica","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"itemCod":{"type":"string"}}},"example":{"itemCod":"1SDRP4"}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/item"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/deteleCaracteristicas":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["items"],"summary":"Eliminar caracteristica de item","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"itemCod":{"type":"string"},"deleteArray":{"type":"array","items":{"type":"string"}}}}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/item"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/toFavorite":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["items"],"summary":"Agregar item a favoritos o destacados","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/item"},"example":{"codigo":"1SDRP4"}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/item"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/toUnFavorite":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["items"],"summary":"Quitar item de favoritos o destacados","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/item"},"example":{"codigo":"1SDRP4"}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/item"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/deleteItem/{codigo}":{"delete":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["items"],"parameters":[{"name":"codigo","in":"path","required":true,"allowEmptyValue":false,"example":"1SDRP4","schema":{"type":"string","description":"Codigo del item que deseamos eliminar"}}],"summary":"Eliminar item","responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/item"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/uploads/image/{codigo}":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["items"],"summary":"Agregar o modificar imagen de item","requestBody":{"required":true,"content":{"form-data":{"schema":{"type":"object","properties":{"img":{"type":"string","description":"File Type"},"oldPhoto":{"type":"string","description":"URL de la imagén antigua."}}}}}},"parameters":[{"name":"codigo","in":"path","required":true,"allowEmptyValue":false,"example":"1SDRP4","schema":{"type":"string","description":"Codigo del item que queremos modificar la imagén"}}],"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/item"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/uploads/imageCat/{codigo}":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["tipos"],"summary":"Agregar o modificar imagen de tipo","requestBody":{"required":true,"content":{"form-data":{"schema":{"type":"object","properties":{"img":{"type":"string","description":"File Type"},"oldPhoto":{"type":"string","description":"URL de la imagén antigua."}}}}}},"parameters":[{"name":"codigo","in":"path","required":true,"allowEmptyValue":false,"example":"1SDRP4","schema":{"type":"string","description":"Codigo del tipo que queremos modificar la imagén"}}],"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/tipo"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/uploads/imageSubCat/{codigo}/{subCat}":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["tipos"],"summary":"Agregar o modificar imagen de sub-tipo","requestBody":{"required":true,"content":{"form-data":{"schema":{"type":"object","properties":{"img":{"type":"string","description":"File Type"},"oldPhoto":{"type":"string","description":"URL de la imagén antigua."}}}}}},"parameters":[{"name":"codigo","in":"path","required":true,"allowEmptyValue":false,"example":"1SDRP4","schema":{"type":"string","description":"Codigo del tipo del sub-tipo que queremos modificar la imagén"}},{"name":"subCat","in":"path","required":true,"allowEmptyValue":false,"example":"Un Sub Tipo","schema":{"type":"string","description":"Sub-tipo del que queremos modificar la imagén"}}],"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"type":"object","properties":{"newPhoto":{"type":"string","description":"Link de la nueva foto"}}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/changeFolder":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["organizar"],"summary":"Modificar a que tipo/sub-tipo un item pertenece.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["codigo"],"properties":{"codigo":{"type":"string","description":"Codigo del item"},"newTipo":{"type":"string","description":"Nombre del nuevo tipo."},"newSubTipo":{"type":"string","description":"Nombre del nuevo sub tipo"}}}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/item"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/reorderItems":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["organizar"],"summary":"Ordenar items.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["codigo"],"properties":{"itemReOrder":{"type":"array","items":{"$ref":"#/components/schemas/item"}}}}}}},"responses":{"200":{"$ref":"#/components/responses/Succes"},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/reorderTipos":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["organizar"],"summary":"Ordenar tipos.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["codigo"],"properties":{"tiposReOrder":{"type":"array","items":{"$ref":"#/components/schemas/tipo"}}}}}}},"responses":{"200":{"$ref":"#/components/responses/Succes"},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/reorderSubTipos":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["organizar"],"summary":"Ordenar sub-tipos.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["codigo"],"properties":{"tipoCodigo":{"type":"string","description":"Codigo del tipo al que pertenecen los sub-tipos"},"linksList":{"type":"array","items":{"type":"string"}},"subTipoList":{"type":"array","items":{"type":"string"}}}}}}},"responses":{"200":{"$ref":"#/components/responses/Succes"},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/getItemMayorGananciaPosible":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["reportes"],"summary":"Optener item con la mayor ganancia posible.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string","description":"Nombre del item"},"balance":{"type":"number","description":"Balance del item en soles (S/)"}}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/getItemsLowStock":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["reportes"],"summary":"Optener items con poca cantidad.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/item"}}}}}}}},"/inventario/getItemsNoStock":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["reportes"],"summary":"Optener items agotados.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/item"}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/getClienteConMasCompras":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["reportes"],"summary":"Optener clientes que más han comprado.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"object","properties":{"cliente":{"type":"string","description":"Nombre del cliente"},"numero":{"type":"number","description":"Cantidad de compras"}}}}}}}}},"/inventario/getItemsMasVendido":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["reportes"],"summary":"Optener item más vendido.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/item"}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/getGananciasTotalesSNS":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["reportes"],"summary":"Optener ganancias por ventas.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"object","properties":{"gananciaEnVentasFueraTienda":{"type":"number","description":"Ganancias por items no registrados en el inventario."},"gananciaEnVentas":{"type":"number","description":"Ganancias por ventas totales."},"gananciaEnVentasDeTienda":{"type":"number","description":"Ganancias por items registardos en el inventario."}}}}}}}}},"/inventario/gananciasInvercionTotal":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["reportes"],"summary":"Optener ganancias y gastos totales.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"object","properties":{"gastoTotalHistorico":{"type":"number","description":"Total de gastos registrados."},"ingresoTotalHistorico":{"type":"number","description":"Total de ganancias registradas."}}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/getPeorMejorItem":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["reportes"],"summary":"Optener los items con el mejor y peor rendimiento.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"object","properties":{"peor":{"type":"object","description":"Peor item.","properties":{"name":{"type":"string"},"balance":{"type":"number"}}},"mejor":{"type":"object","description":"Mejor item.","properties":{"name":{"type":"string"},"balance":{"type":"number"}}}}}}}}}}},"/inventario/ventasPotenciales":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["reportes"],"summary":"Optener ventas potenciales.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"object","properties":{"ventasPosibles":{"type":"number","description":"Ventas potenciales de los items"},"costoPropioTotalAprox":{"type":"number","description":"Cuanto han costado todos los items"},"gananciaAprox":{"type":"number","description":"Ganancias aproximadas"}}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/getTableInfItem":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["reportes"],"summary":"Obtener JSON con información necesaria para realizar un reporte por cada item.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"array","items":{"type":"object","properties":{"name":{"type":"string"},"codigo":{"type":"string"},"cantidad":{"type":"number"},"priceIGV":{"type":"number"},"costoPropio":{"type":"number"},"valueIngreso":{"type":"number"},"valueGasto":{"type":"number"}}}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/getItemBalance/{codigo}":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"parameters":[{"name":"codigo","in":"path","required":true,"allowEmptyValue":false,"example":"123dDF","schema":{"type":"string","description":"Codigo del item"}}],"tags":["reportes"],"summary":"Obtener balance de un item.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"number","description":"Balance del item"}}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/getItemReport/{codigo}":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"parameters":[{"name":"codigo","in":"path","required":true,"allowEmptyValue":false,"example":"123dDF","schema":{"type":"string","description":"Codigo del item"}}],"tags":["reportes"],"summary":"Obtener un excel con el reporte de variaciones del item.","responses":{"200":{"description":"Ok","content":{"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":{}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/getItemVentasPorMes/{codigo}":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"parameters":[{"name":"codigo","in":"path","required":true,"allowEmptyValue":false,"example":"123dDF","schema":{"type":"string","description":"Codigo del item"}}],"tags":["reportes"],"externalDocs":{"url":"https://swimlane.gitbook.io/ngx-charts/"},"summary":"Obtener ventas por mes para ser graficadas usando ngx-charts.","responses":{"200":{"$ref":"#/components/responses/Succes"},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/getItemGIC/{codigo}":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"parameters":[{"name":"codigo","in":"path","required":true,"allowEmptyValue":false,"example":"123dDF","schema":{"type":"string","description":"Codigo del item"}}],"tags":["reportes"],"summary":"Obtener ganancias, ingresos y costos de item.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"object","properties":{"itemVendidos":{"type":"number"},"cantidadHistorica":{"type":"number"},"totalCosto":{"type":"number"},"totalIngreso":{"type":"number"}}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/marcas/getAll":{"get":{"tags":["utilidades"],"summary":"Obtener todas las marcas.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/marca"}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/marcas/add":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["utilidades"],"summary":"Agregar una marca.","requestBody":{"content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/marca"},"example":{"nombre":"Marca X"}}}},"responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"$ref":"#/components/schemas/marca"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/marcas/delete/{deleteString}":{"delete":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["utilidades"],"summary":"Eliminar un listado de marcas.","parameters":[{"name":"deleteString","in":"path","required":true,"allowEmptyValue":false,"example":"marca marsa marxa marza","schema":{"type":"string","description":"String de marcas a elminar separados por un espacio en blanco"}}],"responses":{"200":{"$ref":"#/components/responses/Succes"},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/getTags":{"get":{"tags":["utilidades"],"summary":"Obtener todas los tags.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/tag"}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/getListOfTagsFilteredByRegex":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["utilidades"],"summary":"Obtener todas los tags.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"value":{"type":"string","description":"Regex para buscar"}}}}}},"responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/tag"}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/addTag":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["utilidades"],"summary":"Agregar un tag.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/tag"},"example":{"name":"TAGX"}}}},"responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"$ref":"#/components/schemas/tag"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/deteleTags":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["utilidades"],"summary":"Eliminar tags.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"array","items":{"type":"string"}}}}},"responses":{"200":{"$ref":"#/components/responses/Succes"},"401":{"$ref":"#/components/responses/Error-401"}}}},"/auth/login":{"post":{"tags":["auth"],"summary":"Realizar login.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/login"}}}},"responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"$ref":"#/components/schemas/authToken"}}}},"400":{"$ref":"#/components/responses/Error-401"}}}},"/auth/google":{"get":{"tags":["auth"],"summary":"Te redirije a el sistema de autorizacion de login de google.","externalDocs":{"url":"https://cloud.google.com/nodejs/getting-started/authenticate-users?hl=es"},"responses":{"302":{"description":"Redirijiendo"},"400":{"$ref":"#/components/responses/Error-401"}}}},"/auth/google/callback":{"get":{"tags":["auth"],"summary":"Callback a donde te redirije google. Detectara si ir a la pagina de registro o iniciar sesión.","externalDocs":{"url":"https://cloud.google.com/nodejs/getting-started/authenticate-users?hl=es"},"responses":{"302":{"description":"Redirijiendo."},"400":{"$ref":"#/components/responses/Error-401"}}}},"/auth/google/loginfast":{"post":{"tags":["auth"],"summary":"Usando un token se realiza el inicio de sesión.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"loginToken":{"type":"string"}}}}}},"responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"$ref":"#/components/schemas/authToken"}}}},"400":{"$ref":"#/components/responses/Error-401"}}}},"/auth/google/getLoginInfoFromToken":{"post":{"tags":["auth"],"summary":"Usando un token adquiera la información de usuario dada por google.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"loginToken":{"type":"string"}}}}}},"responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"type":"boolean","properties":{"given_name":{"type":"string"},"family_name":{"type":"string"},"email":{"type":"string"},"sub":{"type":"string","description":"Codigo de google"}}}}}},"400":{"$ref":"#/components/responses/Error-401"}}}},"/auth/google/registerlow":{"post":{"tags":["auth"],"summary":"Registra a un usuario, ademas envia un email de confirmación.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/user"}}}},"responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"$ref":"#/components/schemas/user"}}}},"400":{"$ref":"#/components/responses/Error-401"}}}},"/auth/cambiarContrasena":{"post":{"security":[{"JWT TOKEN ALL":[]}],"tags":["auth"],"summary":"Cambiar contraseña de usuario","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string","description":"ID del usuario"},"passwordOld":{"type":"string","description":"Contraseña antigua"}}}}}},"responses":{"200":{"$ref":"#/components/responses/Succes"},"400":{"$ref":"#/components/responses/Error-401"}}}},"/auth/actCelular":{"post":{"tags":["auth"],"security":[{"JWT TOKEN ALL":[]}],"summary":"Cambiar celular de usuario","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string","description":"ID del usuario"},"celular":{"type":"string","description":"Contraseña antigua"}}}}}},"responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"$ref":"#/components/schemas/user"}}}},"400":{"$ref":"#/components/responses/Error-401"}}}},"/auth/agregarDireccion":{"post":{"tags":["auth"],"security":[{"JWT TOKEN ALL":[]}],"summary":"Agregar o cambiar dirección de usuario.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string","description":"ID del usuario"},"dirOne":{"type":"string"},"dirTwo":{"type":"string"},"reference":{"type":"string"}}}}}},"responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"$ref":"#/components/schemas/user"}}}},"400":{"$ref":"#/components/responses/Error-401"}}}},"/auth/agregarDocumento":{"post":{"tags":["auth"],"security":[{"JWT TOKEN ALL":[]}],"summary":"Agregar o cambiar documento de usuario.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string","description":"ID del usuario"},"documento":{"type":"string"},"tipoPersona":{"type":"string","enum":["dni","ruc"]}}}}}},"responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"$ref":"#/components/schemas/user"}}}},"400":{"$ref":"#/components/responses/Error-401"}}}},"/auth/getUserInfo/{username}":{"get":{"security":[{"JWT TOKEN ALL":[]}],"parameters":[{"name":"username","in":"path","required":true,"allowEmptyValue":false,"example":"DWEWQX123D2D","schema":{"type":"string","description":"Codigo del usario"}}],"tags":["reportes"],"summary":"Obtener usuario.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"$ref":"#/components/schemas/user"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/auth/getOwnUser":{"get":{"security":[{"JWT TOKEN ALL":[]}],"tags":["reportes"],"summary":"Obtener usuario propio.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"$ref":"#/components/schemas/user"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/auth/userEx":{"get":{"security":[{"JWT TOKEN ALL":[]}],"parameters":[{"name":"username","in":"path","required":true,"allowEmptyValue":false,"example":"DWEWQX123D2D","schema":{"type":"string","description":"Codigo del usario"}}],"tags":["reportes"],"summary":"Buscar si el usuario existe.","responses":{"200":{"description":"Ok","content":{"application/json":{"schema":{"$ref":"#/components/schemas/user"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/ventas/ventaSimple":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["ventas"],"summary":"Realiza una venta con solo 1 item.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"venta":{"$ref":"#/components/schemas/venta"}}}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"type":"object","properties":{"venta":{"$ref":"#/components/schemas/venta"},"message":{"type":"string"},"_sunat":{"type":"object"}}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/ventas/agregarVenta":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["ventas"],"summary":"Crear una nueva venta con 1 item.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"venta":{"$ref":"#/components/schemas/venta"}}}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"type":"object","properties":{"venta":{"$ref":"#/components/schemas/venta"},"message":{"type":"string"}}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/ventas/agregarItemVenta":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["ventas"],"summary":"Agregar un item a una venta.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"codigoVenta":{"type":"string"},"itemVendido":{"$ref":"#/components/schemas/itemvendido"}}}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"type":"object","properties":{"venta":{"$ref":"#/components/schemas/venta"},"message":{"type":"string"}}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/ventas/ejecutarVenta":{"post":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["ventas"],"summary":"Ejecutar venta.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"venta":{"$ref":"#/components/schemas/venta"}}}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"type":"object","properties":{"venta":{"$ref":"#/components/schemas/venta"},"message":{"type":"string"},"_sunat":{"type":"object"}}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/ventas/anularVentaPost":{"put":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["ventas"],"summary":"Anular venta post ejecución.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/venta"}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"type":"object","properties":{"message":{"type":"string"}}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/ventas/anularVenta":{"put":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["ventas"],"summary":"Anular venta.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"venta":{"$ref":"#/components/schemas/venta"}}}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"type":"object","properties":{"message":{"type":"string"}}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/ventas/eliminarItemVenta":{"put":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["ventas"],"summary":"Eliminar item de venta.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/venta"}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/venta"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/ventas/eliminarItemSCVenta":{"put":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["ventas"],"summary":"Eliminar item de venta cuando el item tiene un sub-conteo.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/venta"}}}},"responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/venta"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/ventas/getVentasActivasList":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["ventas"],"summary":"Obetener listado de las ventas activas del usuario.","responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"type":"array","items":{"type":"string"}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/ventas/ventasActivasFull":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"tags":["ventas"],"summary":"Obetener listado detallado de las ventas activas del usuario.","responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/venta"}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/ventas/obtenerVenta/{ventaCod}":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"parameters":[{"name":"ventaCod","in":"path","required":true,"allowEmptyValue":false,"example":"SD222","schema":{"type":"string","description":"Codigo de la venta."}}],"tags":["ventas"],"summary":"Obetener venta.","responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"$ref":"#/components/schemas/venta"}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/ventas/getGananciaTotalPorItem/{codigoItem}":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"parameters":[{"name":"codigoItem","in":"path","required":true,"allowEmptyValue":false,"example":"SD222","schema":{"type":"string","description":"Codigo del item."}}],"tags":["reportes"],"summary":"Obetener ganancia total por item.","responses":{"200":{"description":"Ok","content":{"aplication/json":{"schema":{"type":"object","properties":{"value":{"type":"number"},"totalVenta":{"type":"number"}}}}}},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/getItemGananciaIngreso/{codigoItem}":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"parameters":[{"name":"codigoItem","in":"path","required":true,"allowEmptyValue":false,"example":"SD222","schema":{"type":"string","description":"Codigo del item."}}],"tags":["reportes"],"externalDocs":{"url":"https://swimlane.gitbook.io/ngx-charts/"},"summary":"Obtener ventas por mes para ser graficadas usando ngx-charts.","responses":{"200":{"$ref":"#/components/responses/Succes"},"401":{"$ref":"#/components/responses/Error-401"}}}},"/inventario/getItemsGanancias":{"get":{"security":[{"JWT TOKEN TRANSACCIONAL":[]}],"parameters":[{"name":"codigoItem","in":"path","required":true,"allowEmptyValue":false,"example":"SD222","schema":{"type":"string","description":"Codigo del item."}}],"tags":["reportes"],"externalDocs":{"url":"https://swimlane.gitbook.io/ngx-charts/"},"summary":"Obtener ventas por mes para ser graficadas usando ngx-charts.","responses":{"200":{"$ref":"#/components/responses/Succes"},"401":{"$ref":"#/components/responses/Error-401"}}}}}}')},function(e,t){e.exports=require("morgan")},function(e,t,n){"use strict";var r=n(4),o=n(14),a=n.n(o),i=n(3),s=n.n(i),c=n(1),u=n(15),d=n.n(u);function p(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return l(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return l(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,s=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,a=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw a}}}}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function m(e,t,n,r,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}var g=function(){var e,t=(e=regeneratorRuntime.mark((function e(t,n,r,o,a,i,s){var c,u,p,l,m,g,v,h,$,x=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(c=x.length>7&&void 0!==x[7]?x[7]:[],e.prev=1,u=new d.a.Workbook,p=u.addWorksheet(t,{sheetFormat:{defaultRowHeight:20,defaultColWidth:20},pageSetup:{orientation:"portrait"}}),l=u.createStyle({font:{color:"black",size:12,bold:!0},border:{right:{style:"thin",color:"#15181C"},left:{style:"thin",color:"#15181C"},bottom:{style:"thin",color:"#15181C"},top:{style:"thin",color:"#15181C"}},alignment:{vertical:"center",wrapText:!0},numberFormat:"[$S/-es-PE]#,##0.00"}),m=u.createStyle({font:{color:"black",size:12,bold:!0},border:{right:{style:"thin",color:"#15181C"},left:{style:"thin",color:"#15181C"},bottom:{style:"thin",color:"#15181C"}},alignment:{vertical:"center",wrapText:!0},numberFormat:"[$S/-es-PE]#,##0.00",fill:{type:"pattern",patternType:"solid",fgColor:"#e2f3ff"}}),p.column(1).setWidth(5),p.column(2).setWidth(15),p.column(3).setWidth(15),p.column(4).setWidth(15),p.column(5).setWidth(60),p.column(6).setWidth(15),p.column(7).setWidth(15),p.column(8).setWidth(15),g=15,v=b(p,o.itemsVendidos,g,l,m,g,s),y(u,p,r,g-1),f(u,p,n,o,i.observaciones),p.cell(v,7).string("Sub Total").style(l).style({font:{size:14,bold:!0,color:"white"},fill:{type:"pattern",patternType:"solid",fgColor:"#e87200"}}),p.cell(v,8).formula("SUBTOTAL(9,H5:H".concat(v-1,")")).style(l).style({font:{size:14,bold:!0,color:"black"},fill:{type:"pattern",patternType:"solid",fgColor:"white"}}),p.cell(v+1,7).string("IGV").style(l),p.cell(v+1,8).formula("H".concat(v," * ",.18)).style(l),p.cell(v+2,7).string("Envio").style(l).style({font:{size:14,bold:!0,color:"black"},fill:{type:"pattern",patternType:"solid",fgColor:"white"}}),p.cell(v+2,8).number(i.envio||0).style(l).style({font:{size:12,bold:!1,color:"black"},fill:{type:"pattern",patternType:"solid",fgColor:"white"}}),p.cell(v+3,7).string("Otro").style(l).style({font:{size:14,bold:!0,color:"black"},fill:{type:"pattern",patternType:"solid",fgColor:"white"}}),p.cell(v+3,8).number(i.otro||0).style(l).style({font:{size:12,bold:!1,color:"black"},fill:{type:"pattern",patternType:"solid",fgColor:"white"}}),p.cell(v+4,7).string("Total").style(l).style({font:{size:14,bold:!0,color:"white"},fill:{type:"pattern",patternType:"solid",fgColor:"#005087"}}),p.cell(v+4,8).formula("H".concat(v," + H").concat(v+1," + H").concat(v+2," + H").concat(v+3)).style(l).style({font:{size:14,bold:!0,color:"black"},fill:{type:"pattern",patternType:"solid",fgColor:"white"}}),p.cell(v+1,1,v+1,5,!0).style(l).string("BCP - SOLES: 570-2650880-0-39").style({font:{size:12,bold:!0,color:"black"},fill:{type:"pattern",patternType:"solid",fgColor:"#e2f3ff"}}),p.cell(v+2,1,v+2,5,!0).style(l).string("C.C.I. - SOLES: 002-57000265088003903").style({font:{size:12,bold:!0,color:"black"},fill:{type:"pattern",patternType:"solid",fgColor:"#e2f3ff"}}),i.porPagar&&p.cell(v+3,1,v+3,5,!0).style(l).string("SALDO A CANCELAR S/"+(i.porPagar.toString()||"")).style({font:{size:12,bold:!0,color:"black"},fill:{type:"pattern",patternType:"solid",fgColor:"#f1a054"}}),p.row(v).setHeight(20),p.row(v+1).setHeight(20),p.row(v+2).setHeight(20),p.row(v+3).setHeight(20),p.row(v+4).setHeight(20),h=1;h<g-1;h++)p.row(h).setHeight(20);return p.setPrintArea(1,1,v+4,8),p.addImage({image:a,type:"picture",position:{type:"absoluteAnchor",x:"1.5mm",y:"1.5mm"}}),s&&c.forEach((function(e,t){p.addImage({image:e.Body,type:"picture",position:{type:"twoCellAnchor",from:{col:2,colOff:"1mm",row:g+t,rowOff:"1mm"},to:{col:2,colOff:"35mm",row:g+t,rowOff:"35mm"}}})})),e.next=42,u.writeToBuffer();case 42:return $=e.sent,e.abrupt("return",$);case 46:throw e.prev=46,e.t0=e.catch(1),new Error(e.t0);case 49:case"end":return e.stop()}}),e,null,[[1,46]])})),function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function i(e){m(a,r,o,i,s,"next",e)}function s(e){m(a,r,o,i,s,"throw",e)}i(void 0)}))});return function(e,n,r,o,a,i,s){return t.apply(this,arguments)}}(),f=function(e,t,n,r,o){var a=e.createStyle({font:{color:"white",size:16,bold:!0},alignment:{horizontal:"center",vertical:"center"},fill:{type:"pattern",patternType:"solid",fgColor:"#005087"}});t.cell(4,5,4,8,!0).string(r.codigo).style(a).style({font:{color:"black",size:12,bold:!1},fill:{fgColor:"white"}});var i=new Date(r.date);t.cell(5,5,5,8,!0).date(i.toLocaleDateString()).style(a).style({font:{color:"black",size:14,bold:!1},fill:{fgColor:"white"}}).style({numberFormat:"dd-mm-yyy"}),t.cell(6,5,6,8,!0).string("Sirio Dinar - RUC: 20605746587").style(a).style({font:{color:"#005087",size:12,bold:!0},fill:{fgColor:"white"}}),t.cell(7,5,7,8,!0).link("https://inventario.siriodinar.com").style(a).style({font:{color:"#e87200",size:12,bold:!0},fill:{fgColor:"white"}}),t.cell(9,5,9,8,!0).string("Observaciones:").style(a).style({font:{color:"white",size:12,bold:!0},alignment:{horizontal:"left"},fill:{fgColor:"#005087"},border:{right:{style:"thin",color:"#15181C"},left:{style:"thin",color:"#15181C"},bottom:{style:"thin",color:"#15181C"},top:{style:"thin",color:"#15181C"}}}),t.cell(10,5,13,8,!0).string(o||"").style(a).style({font:{color:"black",size:12,bold:!1},fill:{fgColor:"white"},alignment:{horizontal:"left",vertical:"center"},border:{right:{style:"thin",color:"#15181C"},left:{style:"thin",color:"#15181C"},bottom:{style:"thin",color:"#15181C"},top:{style:"thin",color:"#15181C"}}}),t.cell(10,1,10,4,!0).string("Enviar a:").style(a).style({font:{color:"white",size:12,bold:!0},alignment:{horizontal:"left"},fill:{fgColor:"#005087"},border:{right:{style:"thin",color:"#15181C"},left:{style:"thin",color:"#15181C"},bottom:{style:"thin",color:"#15181C"},top:{style:"thin",color:"#15181C"}}}),t.cell(11,1,13,4,!0).string("".concat(r.documento.name," | ").concat(r.documento.codigo," ").concat(r.cliente_email?"\nemail: "+r.cliente_email:""," ").concat(r.celular_cliente?"\nCelular: "+r.celular_cliente:"")).style(a).style({font:{color:"black",size:12,bold:!1},fill:{fgColor:"white"},alignment:{horizontal:"left",vertical:"center",wrapText:!0},border:{right:{style:"thin",color:"#15181C"},left:{style:"thin",color:"#15181C"},bottom:{style:"thin",color:"#15181C"},top:{style:"thin",color:"#15181C"}}}),t.cell(7,1,7,4,!0).string("Jr. Pardo y Aliaga Nro. 207. Trujillo - Perú").style(a).style({font:{color:"black",size:12,bold:!0},fill:{fgColor:"white"},alignment:{horizontal:"left"}}),t.cell(8,1,8,4,!0).string("+51 977 426 349 | +51 922 412 404").style(a).style({font:{color:"black",size:12,bold:!0},fill:{fgColor:"white"},alignment:{horizontal:"left"}})},y=function(e,t,n,r){var o,a=e.createStyle({font:{color:"white",size:12,bold:!0},border:{right:{style:"thin",color:"#15181C"},left:{style:"thin",color:"#15181C"},bottom:{style:"thin",color:"#15181C"}},alignment:{horizontal:"center",vertical:"center",wrapText:!0},fill:{type:"pattern",patternType:"solid",fgColor:"#e87200"}}),i=1,s=p(n);try{for(s.s();!(o=s.n()).done;){var c=o.value;t.cell(r,i).string(c).style(a),i++}}catch(e){s.e(e)}finally{s.f()}t.row(r).filter({firstColumn:1,lastColumn:n.length}),t.row(r).setHeight(40)},b=function e(t,n,r,o,a,i,s){var c,u=r-i;if(u>=n.length)return i;s?t.row(r).setHeight(85):t.row(r).setHeight(35),c=r%2==0?a:o,t.cell(r,1).number(u+1).style(c).style({numberFormat:"0"}).style({alignment:{horizontal:"center"}}),t.cell(r,2).string("").style(c).style({alignment:{wrapText:!0}}),t.cell(r,3).string(n[u].unidadDeMedida||"UND").style(c).style({alignment:{wrapText:!0,horizontal:"center"}}),t.cell(r,4).string(n[u].name).style(c).style({alignment:{horizontal:"center",wrapText:!0}});var d=n[u].descripcion||"";if(n[u].cantidadSC&&n[u].cantidadSC.length>0){d+=". Detalle:";for(var p=0;p<n[u].cantidadSC.length;p++)n[u].cantidadSC[p].cantidadVenta>0&&(d=d+" ".concat(n[u].cantidadSC[p].name," ").concat(n[u].cantidadSC[p].nameSecond?"- ".concat(n[u].cantidadSC[p].nameSecond,": "):": ")+n[u].cantidadSC[p].cantidadVenta+"".concat(n[u].cantidadSC.length+1<p?",":"."))}return t.cell(r,5).string(d).style(c).style({alignment:{wrapText:!0}}),t.cell(r,6).number(n[u].cantidad).style(c).style({numberFormat:"0"}).style({alignment:{horizontal:"center"}}),t.cell(r,7).number(n[u].priceNoIGV).style(c),t.cell(r,8).formula("F".concat(r," * G").concat(r)).style(c),1+e(t,n,r+1,o,a,i,s)},v=n(42),h=n.n(v),$=(n(10),n(16)),x=void 0;function w(e){return function(e){if(Array.isArray(e))return V(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||j(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function S(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=j(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,s=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,a=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw a}}}}function j(e,t){if(e){if("string"==typeof e)return V(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?V(e,t):void 0}}function V(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}new a.a.S3({accessKeyId:c.a.production.awsID,secretAccessKey:c.a.production.awsKey,Bucket:c.a.production.bucket,region:"us-east-1"});var C=new h.a({Courier:{normal:"Courier",bold:"Courier-Bold",italics:"Courier-Oblique",bolditalics:"Courier-BoldOblique"},Helvetica:{normal:"Helvetica",bold:"Helvetica-Bold",italics:"Helvetica-Oblique",bolditalics:"Helvetica-BoldOblique"},Times:{normal:"Times-Roman",bold:"Times-Bold",italics:"Times-Italic",bolditalics:"Times-BoldItalic"},Symbol:{normal:"Symbol"},ZapfDingbats:{normal:"ZapfDingbats"}}),k={pageMargins:[40,40,40,50],content:[{style:"tableEnviar",table:{widths:["*","*"],body:[[{image:"",width:100,border:[!1,!1,!1,!1],style:"headerTitle"},{text:[{text:"",fontSize:18,bold:!0},{text:"\nSirio Dinar - RUC: 20605746587",color:"darkblue",fontSize:12},{text:"\ninventario.siriodinar.com",color:"orange",fontSize:12}],rowSpan:2,alignment:"center",style:"headerTitlePrinc",border:[!0,!0,!0,!1]}],[{text:"Jr. Pardo y Aliaga Nro. 207. Trujillo - Perú \n +51 977 426 349 | +51 922 412 404",width:100,height:100,border:[!1,!1,!1,!1],style:"headerTitle"}]]}},{style:"tableEnviar",table:{heights:[15,60],widths:[165,331],body:[[{text:"Enviar a:",fillColor:"#005087",bold:!0,color:"#EAF6FF",style:"tableMargin"},{text:"Observaciones:",fillColor:"#005087",bold:!0,color:"#EAF6FF",style:"tableMargin"}],[{text:"",border:[!0,!0,!0,!1],style:"tableMargin"},{text:"RR",border:[!0,!0,!0,!1],style:"tableMargin"}]]}},{style:"tableHeader",table:{heights:[15],widths:[15,97,35,70,120,35,35,35],body:[[{text:"Nº",style:"tableMarginSH"},{text:"IMAGÉN",style:"tableMarginSH"},{text:"UDM",style:"tableMarginSH"},{text:"NOMBRE",style:"tableMarginSH"},{text:"DESCRIPCIÓN",style:"tableMarginSH"},{text:"CANT.",style:"tableMarginSH"},{text:"P/CU",style:"tableMarginSH"},{text:"TOTAL",style:"tableMarginSH"}]]}},{layout:{paddingTop:function(e,t){return T(t,e,"center"),0}},style:{fontSize:10,bold:!1,alignment:"center"},table:{dontBreakRows:!0,heights:40,widths:[15,97,35,70,120,35,35,35],body:[]}},{style:"totales",table:{dontBreakRows:!0,heights:15,widths:[79,79],body:[[{text:"Sub Total:",border:[!0,!1,!1,!0],fillColor:"#E87100",color:"white",style:"totalesMargin"},{text:"S/ 111.00",border:[!0,!1,!0,!0],alignment:"right",style:"totalesMargin"}],[{text:"IGV:",color:"grey",style:"totalesMargin"},{text:"S/ 111.00",alignment:"right",color:"grey",style:"totalesMargin"}],[{text:"Envio:",color:"grey",style:"totalesMargin"},{text:"S/ 111.00",alignment:"right",color:"grey",style:"totalesMargin"}],[{text:"Otro:",color:"grey",style:"totalesMargin"},{text:"S/ 111.00",alignment:"right",color:"grey",style:"totalesMargin"}],[{text:"Total:",fillColor:"#005087",color:"white",style:"totalesMargin"},{text:"S/ 111.00",alignment:"right",style:"totalesMargin"}]]}}],styles:{totalesMargin:{margin:[0,5,0,0]},tableMarginSH:{margin:[0,5,0,0],fillColor:"#E87100",color:"#EAF6FF"},tableMargin:{fontSize:10,margin:[2,5,2,2]},headerTitlePrinc:{margin:[0,40,0,0],fontSize:14},headerTitle:{margin:[0,0,0,5]},header:{fontSize:18,bold:!0,margin:[10,10,10,10]},subheader:{fontSize:16,bold:!0,margin:[0,10,10,10]},tableEnviar:{margin:[0,0,0,0]},tableHeader:{bold:!0,fontSize:10,alignment:"center"},totales:{margin:[338,0,0,0]},marginSN:{margin:[2,12,2,6]}},defaultStyle:{font:"Helvetica",lineHeight:1.2}},T=function(e,t,n){var r=e.table.body[t].map((function(t,n){return function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,r=function(e){if(void 0===e)return{height:0,width:0};var r,o=0,a=S(e);try{for(a.s();!(r=a.n()).done;){var i=r.value;(n+=i.width)>t?(o+=i.height,n=i.width):o=Math.max(i.height,o)}}catch(e){a.e(e)}finally{a.f()}return{height:o,width:n}};if(e._offsets&&(n+=e._offsets.total),e._inlines&&e._inlines.length)return r(e._inlines);if(e.stack&&e.stack[0])return e.stack.map((function(e){return r(e._inlines)})).reduce((function(e,t){return{height:e.height+t.height,width:Math.max(e.width+t.width)}}));if(e.table){var o,a=0,i=S(e.table.body);try{for(i.s();!(o=i.n()).done;){var s=o.value,c=s.map((function(e){var r=x.findInlineHeight(e,t,n);return n=r.width,r.height}));a=Math.max.apply(Math,w(c).concat([a]))}}catch(e){i.e(e)}finally{i.f()}return{height:a,width:n}}return e._height?(n+=e._width,{height:e._height,width:n}):{height:null,width:n}}(t,e.table.widths[n]._calcWidth).height})),o=Math.max.apply(Math,w(r));e.table.body[t].forEach((function(e,t){var a;r[t]&&o>r[t]&&("bottom"===n?a=o-r[t]:"center"===n&&(a=(o-r[t])/2),e._margin?e._margin[1]=a:e._margin=[0,a,0,0])}))},O=function(e,t,n,r,o){N(e,t,n),o?(k.content[2].table={heights:[15],widths:[15,97,35,70,120,35,35,35],body:[[{text:"Nº",style:"tableMarginSH"},{text:"IMAGÉN",style:"tableMarginSH"},{text:"UDM",style:"tableMarginSH"},{text:"NOMBRE",style:"tableMarginSH"},{text:"DESCRIPCIÓN",style:"tableMarginSH"},{text:"CANT.",style:"tableMarginSH"},{text:"P/CU",style:"tableMarginSH"},{text:"TOTAL",style:"tableMarginSH"}]]},k.content[3].table={dontBreakRows:!0,heights:40,widths:[15,97,35,70,120,35,35,35],body:[]}):(k.content[2].table={heights:[15],widths:[20,35,83,193,40,40,40],body:[[{text:"Nº",style:"tableMarginSH"},{text:"UDM",style:"tableMarginSH"},{text:"NOMBRE",style:"tableMarginSH"},{text:"DESCRIPCIÓN",style:"tableMarginSH"},{text:"CANT.",style:"tableMarginSH"},{text:"P/CU",style:"tableMarginSH"},{text:"TOTAL",style:"tableMarginSH"}]]},k.content[3].table={heights:50,dontBreakRows:!0,widths:[20,35,83,193,40,40,40],body:[]}),I(t,r,o);var a=0;n.envio&&(a=n.envio);var i=0;return n.otro&&(i=n.otroR),k.content[4].table.body[0][1].text="S/ "+t.totalPriceNoIGV.toFixed(2),k.content[4].table.body[1][1].text="S/ "+(Math.round(100*(t.totalPrice-t.totalPriceNoIGV))/100).toFixed(2),k.content[4].table.body[2][1].text="S/ "+a.toFixed(2),k.content[4].table.body[3][1].text="S/ "+i.toFixed(2),k.content[4].table.body[4][1].text="S/ "+((n.otro||0)+(n.envio||0)+t.totalPrice).toFixed(2),C.createPdfKitDocument(k)},N=function(e,t,n){var r=$.DateTime.fromJSDate(t.date).toFormat("c LL yyyy").toLocaleString();k.content[0].table.body[0][0].image=e,k.content[0].table.body[0][1].text[0].text="".concat(t.codigo,"\n").concat(r.split(" ").join("/")),k.content[1].table.body[1][1].text=n.observaciones,k.content[1].table.body[1][0].text="".concat(t.documento.name," | ").concat(t.documento.codigo).concat(t.cliente_email?"\nemail: ".concat(t.cliente_email):"").concat("+51"===t.celular_cliente?"":"\nCelular:".concat(t.celular_cliente))},I=function(e,t,n){var r=[];e.itemsVendidos.forEach((function(e,o){var a=e.descripcion||"";if(e.cantidadSC&&e.cantidadSC.length>0){a+=". Detalle:";for(var i=0;i<e.cantidadSC.length;i++)e.cantidadSC[i].cantidadVenta>0&&(a=a+" ".concat(e.cantidadSC[i].name," ").concat(e.cantidadSC[i].nameSecond?"- ".concat(e.cantidadSC[i].nameSecond,": "):": ")+e.cantidadSC[i].cantidadVenta+"".concat(e.cantidadSC.length+1<i?",":"."))}n?r.push([{text:o+1,style:"tableMarginN"},{image:t[o].Body,width:95,height:95},{text:e.unidadDeMedida,style:"tableMarginN"},{text:e.name,style:"tableMarginN"},{text:a,alignment:"justify"},{text:e.cantidad.toString(),style:"tableMarginN"},{text:"S/"+e.priceNoIGV.toString(),style:"tableMarginN"},{text:"S/"+e.totalPriceNoIGV.toString(),style:"tableMarginN"}]):r.push([{text:o+1,style:"marginSN"},{text:e.unidadDeMedida,style:"marginSN"},{text:e.name,style:"marginSN"},{text:a,alignment:"justify",style:"marginSN"},{text:e.cantidad.toString(),style:"marginSN"},{text:"S/"+e.priceNoIGV.toString(),style:"marginSN"},{text:"S/"+e.totalPriceNoIGV.toString(),style:"marginSN"}]),k.content[3].table.body=r}))},A=n(7),R=new i.Schema({codigo:{type:String,required:!0,trim:!0,unique:!0},totalPrice:{type:Number,trim:!0,required:!0},totalPriceNoIGV:{type:Number,trim:!0,required:!0},estado:{type:String,trim:!0,required:!0},documento:{type:A.b},itemsVendidos:{type:[A.c],required:!0},date:{type:Date,default:Date.now},vendedor:{type:String},tipoVendedor:{type:String,default:"admin"},cliente_email:{type:String,trim:!0},celular_cliente:{type:String,trim:!0}});function _(e,t,n,r,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function P(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function i(e){_(a,r,o,i,s,"next",e)}function s(e){_(a,r,o,i,s,"throw",e)}i(void 0)}))}}var E=s.a.model("Cotizacion",R),G=new a.a.S3({accessKeyId:c.a.production.awsID,secretAccessKey:c.a.production.awsKey,Bucket:c.a.production.bucket,region:"us-east-1"}),M=function(){var e=P(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,t.body.venta._id=void 0,t.body.venta.codigo=void 0,r=new E(t.body.venta),e.next=6,D();case 6:return r.codigo=e.sent,r.celular_cliente=L(t.body.venta.celular_cliente),e.next=10,r.save();case 10:o=e.sent,n.json({message:"Cotización generada con el codigo: ".concat(o.codigo),coti:o}),e.next=17;break;case 14:return e.prev=14,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 17:case"end":return e.stop()}}),e,null,[[0,14]])})));return function(t,n){return e.apply(this,arguments)}}(),q=function(){var e=P(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,"noone"!==t.body.dateOne&&"noone"!==t.body.dateTwo){e.next=7;break}return e.next=4,E.find({estado:t.body.estado}).skip(parseInt(t.body.skip)).limit(parseInt(t.body.limit));case 4:r=e.sent,e.next=10;break;case 7:return e.next=9,E.find({estado:t.body.estado,date:{$gte:new Date(t.body.dateOne),$lt:new Date(t.body.dateTwo)}}).skip(parseInt(t.body.skip)).limit(parseInt(t.body.limit));case 9:r=e.sent;case 10:n.json(r),e.next=16;break;case 13:return e.prev=13,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 16:case"end":return e.stop()}}),e,null,[[0,13]])})));return function(t,n){return e.apply(this,arguments)}}(),D=function(){var e=P(regeneratorRuntime.mark((function e(){var t,n,r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,E.countDocuments({});case 3:for(e.t0=e.sent,t=e.t0+1,n="COTSD01-000000",r=0;r<t.toString().length;r++)n=n.slice(0,-1);return o=n+t.toString(),e.abrupt("return",o);case 11:return e.prev=11,e.t1=e.catch(0),e.abrupt("return",res.status(500).json({errorMSG:e.t1}));case 14:case"end":return e.stop()}}),e,null,[[0,11]])})));return function(){return e.apply(this,arguments)}}(),L=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=e.split(" ").join("");return e.startsWith("+")||(t="+51"+e.split(" ").join("")),t},B=function(){var e=P(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,E.findOne({codigo:t.params.cotiCod});case 3:r=e.sent,n.json(r),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),U=function(){var e=P(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,E.aggregate([{$match:{codigo:t.body.codCoti}},{$unwind:"$itemsVendidos"},{$replaceRoot:{newRoot:"$itemsVendidos"}},{$unwind:{path:"$cantidadSC",preserveNullAndEmptyArrays:!0}},{$match:{$or:[{"cantidadSC.cantidadVenta":{$gt:0}},{cantidadSC:null}]}}]);case 3:r=e.sent,n.json(r),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),F=function(){var e=P(regeneratorRuntime.mark((function e(t,n){var r,o,a,i,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,E.aggregate([{$match:{codigo:t.body.codigoCoti}},{$unwind:"$itemsVendidos"},{$replaceRoot:{newRoot:"$itemsVendidos"}},{$match:{codigo:t.body.itemVendido.codigo}},{$count:"thisItem"}]);case 3:if(0===e.sent.length){e.next=14;break}return e.next=7,E.aggregate([{$match:{codigo:t.body.codigoCoti}},{$unwind:"$itemsVendidos"},{$replaceRoot:{newRoot:"$itemsVendidos"}},{$match:{codigo:t.body.itemVendido.codigo}}]);case 7:return r=e.sent,o=Math.round(100*(r[0].totalPrice-t.body.itemVendido.totalPrice+Number.EPSILON))/100*-1,a=Math.round(100*(r[0].totalPriceNoIGV-t.body.itemVendido.totalPriceNoIGV+Number.EPSILON))/100*-1,e.next=12,E.findOneAndUpdate({codigo:t.body.codigoCoti,itemsVendidos:{$elemMatch:{codigo:t.body.itemVendido.codigo}}},{$set:{"itemsVendidos.$":t.body.itemVendido},$inc:{totalPrice:o,totalPriceNoIGV:a}},{useFindAndModify:!1,new:!0});case 12:return i=e.sent,e.abrupt("return",n.json({message:"Cantidades actualizadas",coti:i}));case 14:return e.next=16,E.findOneAndUpdate({codigo:t.body.codigoCoti},{$push:{itemsVendidos:t.body.itemVendido},$inc:{totalPrice:t.body.itemVendido.totalPrice,totalPriceNoIGV:t.body.itemVendido.totalPriceNoIGV}},{useFindAndModify:!1,new:!0});case 16:s=e.sent,n.json({message:"Item agregado correctamente",coti:s}),e.next=23;break;case 20:return e.prev=20,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:e.t0}));case 23:case"end":return e.stop()}}),e,null,[[0,20]])})));return function(t,n){return e.apply(this,arguments)}}(),z=function(){var e=P(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,E.findOneAndUpdate({codigo:t.body.codigo},{$inc:{totalPrice:-1*t.body.totalPrice,totalPriceNoIGV:-1*t.body.totalPriceNoIGV},$pull:{itemsVendidos:{codigo:t.body.codigoItem}}},{useFindAndModify:!1,new:!0});case 3:r=e.sent,n.json(r),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),W=function(){var e=P(regeneratorRuntime.mark((function e(t,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,E.findOneAndUpdate({codigo:t.body.codigo},{estado:"eliminada"});case 3:n.json({eliminada:!0}),e.next=9;break;case 6:return e.prev=6,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({message:e.t0}));case 9:case"end":return e.stop()}}),e,null,[[0,6]])})));return function(t,n){return e.apply(this,arguments)}}(),K=function(){var e=P(regeneratorRuntime.mark((function e(t,n){var r,o,a,i,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,G.getObject({Bucket:c.a.production.bucket,Key:"sirio-logo-small.png"}).promise();case 3:return r=e.sent,e.next=6,E.findOne({codigo:t.body.codigo});case 6:if(o=e.sent,a=[],!t.body.imagen){e.next=19;break}i=0;case 10:if(!(i<o.itemsVendidos.length)){e.next=19;break}return e.t0=a,e.next=14,G.getObject({Bucket:c.a.production.bucket,Key:o.itemsVendidos[i].photo}).promise();case 14:e.t1=e.sent,e.t0.push.call(e.t0,e.t1);case 16:i++,e.next=10;break;case 19:return e.next=21,g("Cotización","Temp Coti",["Nº","IMAGÉN","UNIDAD DE MEDIDA","NOMBRE","DESCRIPCIÓN","CANTIDAD","P/CU","TOTAL"],o,r.Body,t.body.extra,t.body.imagen,a);case 21:s=e.sent,n.writeHead(200,{"Content-Type":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","Content-Disposition":"attachment; filename=".concat(o.codigo,".xlsx")}),n.write(s,"binary"),n.end(null,"binary"),e.next=30;break;case 27:return e.prev=27,e.t2=e.catch(0),e.abrupt("return",n.status(500).json({message:e.t2}));case 30:case"end":return e.stop()}}),e,null,[[0,27]])})));return function(t,n){return e.apply(this,arguments)}}(),J=function(){var e=P(regeneratorRuntime.mark((function e(t,n){var r,o,a,i,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,E.findOne({codigo:t.body.codigo});case 3:return r=e.sent,e.next=6,G.getObject({Bucket:c.a.production.bucket,Key:"sirio-logo-small.png"}).promise();case 6:if(o=e.sent,a=[],!t.body.imagen){e.next=19;break}i=0;case 10:if(!(i<r.itemsVendidos.length)){e.next=19;break}return e.t0=a,e.next=14,G.getObject({Bucket:c.a.production.bucket,Key:r.itemsVendidos[i].photo}).promise();case 14:e.t1=e.sent,e.t0.push.call(e.t0,e.t1);case 16:i++,e.next=10;break;case 19:s=O(o.Body,r,t.body.extra,a,t.body.imagen),n.setHeader("Content-Type","application/pdf"),n.setHeader("Content-Disposition","attachment; filename=quote.pdf"),s.pipe(n),s.end(),e.next=29;break;case 26:return e.prev=26,e.t2=e.catch(0),e.abrupt("return",n.status(500).json({message:e.t2}));case 29:case"end":return e.stop()}}),e,null,[[0,26]])})));return function(t,n){return e.apply(this,arguments)}}(),H=n(0),Y=new r.Router;Y.post("/generarCoti",H.B,M),Y.post("/getPendientes",H.B,q),Y.get("/obtenerCoti/:cotiCod",H.B,B),Y.post("/cotiForCard",H.B,U),Y.post("/agregarItemCoti",H.B,F),Y.post("/eliminarItemCoti",H.B,z),Y.put("/eliminarCoti",H.B,W),Y.post("/getPdfCoti",H.B,J),Y.post("/getExcelCoti",H.B,K);t.a=Y},function(e,t,n){"use strict";var r=n(4),o=n(2),a=n(3),i=n.n(a),s=n(12),c=new a.Schema({name:{type:String,required:!0,unique:!0,trim:!0},date:{type:Date,default:Date.now},codigo:{type:String},subTipo:{type:[String],trim:!0},subTipoLink:{type:[String],trim:!0},deleted:{type:Boolean,default:!1},link:{type:String,default:"noPhoto.jpg"},order:{type:Number,default:-1}});function u(e,t,n,r,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function d(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function i(e){u(a,r,o,i,s,"next",e)}function s(e){u(a,r,o,i,s,"throw",e)}i(void 0)}))}}var p=i.a.model("Tipo",c),l=i.a.model("Item",s.a),m=function(){var e=d(regeneratorRuntime.mark((function e(t,n){var r,o,a,i,s,c,u;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,(r=new Date).setDate(r.getDate()-7),e.next=5,p.find({deleted:!1});case 5:return o=e.sent,e.next=8,l.find({deleted:!1});case 8:for(a=e.sent,i=[{url:"store/main",priority:1,changefreq:"monthly"},{url:"servicio-al-cliente/contactanos",priority:.8,changefreq:"monthly"},{url:"carrito",priority:.7,changefreq:"monthly"},{url:"servicio-al-cliente/terminos-y-condiciones",priority:.3,changefreq:"monthly"},{url:"servicio-al-cliente/politica-de-privacidad",priority:.3,changefreq:"monthly"},{url:"servicio-al-cliente/politica-de-devolucion",priority:.3,changefreq:"monthly"},{url:"servicio-al-cliente/politica-de-envio",priority:.3,changefreq:"monthly"},{url:"/",priority:1,changefreq:"monthly"},{url:"store/categorias",priority:.9,changefreq:"weekly"}],s=0;s<o.length;s++)for(i.push({url:"store/categorias/"+o[s].name,priority:.7,changefreq:"daily"}),c=0;c<o[s].subTipo.length;c++)i.push({url:"store/categorias/"+o[s].name+"/"+o[s].subTipo[c],priority:.6,changefreq:"daily"});for(u=0;u<a.length;u++)i.push({url:"store/categorias/"+a[u].tipo+"/"+a[u].subTipo+"/"+a[u].codigo,priority:.5,changefreq:"daily"});n.json(i),e.next=18;break;case 15:return e.prev=15,e.t0=e.catch(0),e.abrupt("return",n.status(500).end());case 18:case"end":return e.stop()}}),e,null,[[0,15]])})));return function(t,n){return e.apply(this,arguments)}}(),g=function(){var e=d(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,(r=new p(t.body)).codigo=Date.now().toString(),r.subTipo=[],e.next=6,r.save();case 6:return o=e.sent,e.abrupt("return",n.json(o));case 10:return e.prev=10,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 13:case"end":return e.stop()}}),e,null,[[0,10]])})));return function(t,n){return e.apply(this,arguments)}}(),f=function(){var e=d(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,p.findOne({name:t.body.codigo});case 3:if(!((r=e.sent).subTipo.indexOf(t.body.subTipo)>-1)){e.next=6;break}return e.abrupt("return",n.json(null));case 6:return e.next=8,p.updateOne({codigo:r.codigo},{$push:{subTipo:t.body.subTipo,subTipoLink:"noPhoto.jpg"}});case 8:return e.abrupt("return",n.json({message:"succes"}));case 11:return e.prev=11,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 14:case"end":return e.stop()}}),e,null,[[0,11]])})));return function(t,n){return e.apply(this,arguments)}}(),y=function(){var e=d(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,p.find({deleted:!1}).sort({order:1});case 3:return r=e.sent,e.abrupt("return",n.json(r));case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),b=function(){var e=d(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,p.findOne({name:t.params.tipoCod}).select("subTipo -_id");case 3:return r=e.sent,e.abrupt("return",n.json(r));case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),v=function(){var e=d(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,p.findOne({name:t.params.codigo});case 3:return r=e.sent,e.abrupt("return",n.json(r));case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),h=function(){var e=d(regeneratorRuntime.mark((function e(t,n){var r,o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i.a.startSession();case 2:return(r=e.sent).startTransaction(),e.prev=4,e.next=7,p.findOne({codigo:t.body.codigo});case 7:return o=e.sent,t.beforeName=o.name,e.next=11,p.findOneAndUpdate({codigo:t.body.codigo},{name:t.body.tipoName},{new:!0,useFindAndModify:!1});case 11:return a=e.sent,t.newTipo=a,e.next=15,l.updateMany({tipo:t.beforeName},{tipo:t.body.tipoName},{new:!0,useFindAndModify:!1,runValidators:!0});case 15:return e.next=17,r.commitTransaction();case 17:r.endSession(),n.json(t.newTipo),e.next=27;break;case 21:return e.prev=21,e.t0=e.catch(4),e.next=25,r.abortTransaction();case 25:return r.endSession(),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 27:case"end":return e.stop()}}),e,null,[[4,21]])})));return function(t,n){return e.apply(this,arguments)}}(),$=function(){var e=d(regeneratorRuntime.mark((function e(t,n){var r,o,a,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i.a.startSession();case 2:return(r=e.sent).startTransaction(),e.prev=4,e.next=7,p.findOne({name:t.body.codigo});case 7:if(!((o=e.sent).subTipo.indexOf(t.body.newSubName)>-1)){e.next=10;break}return e.abrupt("return",n.json(null));case 10:return a=o.subTipo.indexOf(t.body.antiguoSubName),o.subTipo[a]=t.body.newSubName,e.next=14,p.findOneAndUpdate({name:t.body.codigo},{subTipo:o.subTipo},{new:!0,useFindAndModify:!1});case 14:return e.next=16,l.updateMany({subTipo:t.body.antiguoSubName},{subTipo:t.body.newSubName},{new:!0,useFindAndModify:!1});case 16:return s=e.sent,e.next=19,r.commitTransaction();case 19:r.endSession(),n.json(s),e.next=29;break;case 23:return e.prev=23,e.t0=e.catch(4),e.next=27,r.abortTransaction();case 27:return r.endSession(),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 29:case"end":return e.stop()}}),e,null,[[4,23]])})));return function(t,n){return e.apply(this,arguments)}}(),x=function(){var e=d(regeneratorRuntime.mark((function e(t,n){var r,o,a,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i.a.startSession();case 2:return(r=e.sent).startTransaction(),e.prev=4,e.next=7,p.findOne({name:t.params.codigo});case 7:return o=e.sent,a=o.subTipo.indexOf(t.params.subTipoName),o.subTipo.splice(a,1),e.next=12,p.findOneAndUpdate({name:t.params.codigo},{subTipo:o.subTipo},{new:!0,useFindAndModify:!1});case 12:return e.next=14,l.updateMany({subTipo:t.params.subTipoName},{deleted:!0});case 14:return s=e.sent,e.next=17,r.commitTransaction();case 17:return r.endSession(),e.abrupt("return",n.json(s));case 21:return e.prev=21,e.t0=e.catch(4),e.next=25,r.abortTransaction();case 25:return r.endSession(),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 27:case"end":return e.stop()}}),e,null,[[4,21]])})));return function(t,n){return e.apply(this,arguments)}}(),w=function(){var e=d(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,p.findOneAndUpdate({codigo:t.params.codigo},{link:t.fileName},{new:!0,useFindAndModify:!1});case 3:r=e.sent,n.status(200).json(r),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),S=function(){var e=d(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,p.findOne({name:t.params.codigo});case 3:return r=e.sent,o=r.subTipo.findIndex((function(e){return e===t.params.subCat})),r.subTipoLink[o]=t.fileName,e.next=8,p.findOneAndUpdate({name:t.params.codigo},{subTipoLink:r.subTipoLink},{new:!0,useFindAndModify:!1});case 8:e.sent,n.status(200).json({newPhoto:r.subTipoLink[o]}),e.next=15;break;case 12:return e.prev=12,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 15:case"end":return e.stop()}}),e,null,[[0,12]])})));return function(t,n){return e.apply(this,arguments)}}(),j=function(){var e=d(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i.a.startSession();case 2:return(r=e.sent).startTransaction(),e.prev=4,e.next=7,p.findOneAndUpdate({codigo:t.params.codigo},{deleted:!0},{new:!0,useFindAndModify:!1});case 7:return o=e.sent,t.tipoDeleted=o,e.next=11,l.updateMany({tipo:t.tipoDeleted.name},{deleted:!0});case 11:return e.next=13,r.commitTransaction();case 13:r.endSession(),n.json(t.tipoDeleted),e.next=23;break;case 17:return e.prev=17,e.t0=e.catch(4),e.next=21,r.abortTransaction();case 21:return r.endSession(),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 23:case"end":return e.stop()}}),e,null,[[4,17]])})));return function(t,n){return e.apply(this,arguments)}}(),V=function(){var e=d(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i.a.startSession();case 2:return(r=e.sent).startTransaction(),e.prev=4,e.next=7,p.countDocuments({deleted:!1});case 7:if(e.sent===t.body.tiposReOrder.length){e.next=10;break}throw"Variacion Invalida";case 10:o=0;case 11:if(!(o<t.body.tiposReOrder.length)){e.next=17;break}return e.next=14,p.findOneAndUpdate({codigo:t.body.tiposReOrder[o].codigo},{order:o},{useFindAndModify:!1});case 14:o++,e.next=11;break;case 17:return e.next=19,r.commitTransaction();case 19:r.endSession(),n.json({message:"done"}),e.next=29;break;case 23:return e.prev=23,e.t0=e.catch(4),e.next=27,r.abortTransaction();case 27:return r.endSession(),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 29:case"end":return e.stop()}}),e,null,[[4,23]])})));return function(t,n){return e.apply(this,arguments)}}(),C=function(){var e=d(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,p.findOne({name:t.body.tipoCodigo});case 3:if(e.sent.subTipo.length===t.body.subTipoList.length){e.next=6;break}throw"Variacion Invalida";case 6:return e.next=8,p.findOneAndUpdate({name:t.body.tipoCodigo},{subTipoLink:t.body.linksList,subTipo:t.body.subTipoList},{useFindAndModify:!1,new:!0});case 8:r=e.sent,n.json(r),e.next=15;break;case 12:return e.prev=12,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 15:case"end":return e.stop()}}),e,null,[[0,12]])})));return function(t,n){return e.apply(this,arguments)}}(),k=function(){var e=d(regeneratorRuntime.mark((function e(t,n){var r,o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,i.a.startSession();case 2:return(r=e.sent).startTransaction(),e.prev=4,e.next=7,l.findOneAndUpdate({codigo:t.body.codigo},{subTipo:t.body.newSubTipo,tipo:t.body.newTipo,orderNumber:-2},{useFindAndModify:!1,new:!0});case 7:return o=e.sent,e.next=10,p.findOne({name:t.body.newTipo});case 10:if(null!==(a=e.sent)){e.next=13;break}throw"Tipo Ya No Existe";case 13:if(-1!==a.subTipo.indexOf(t.body.newSubTipo)){e.next=15;break}throw"Sub Tipo Ya No Existe";case 15:return e.next=17,r.commitTransaction();case 17:r.endSession(),n.json(o),e.next=27;break;case 21:return e.prev=21,e.t0=e.catch(4),e.next=25,r.abortTransaction();case 25:return r.endSession(),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 27:case"end":return e.stop()}}),e,null,[[4,21]])})));return function(t,n){return e.apply(this,arguments)}}(),T=n(5),O=n(0),N=new r.Router;N.get("/getTipos",y),N.get("/getTipo/:codigo",v),N.get("/getSubTipos/:tipoCod",b),N.get("/getItem/:tipo/:codigo",o.B),N.get("/getItems",o.u),N.get("/getItemsDestacados",o.E),N.get("/getItemsByType/:tipo",o.v),N.get("/getItemsSubTipo/:tipo/:subTipo",o.w),N.get("/getItemsRelacionados/:tipo/:codigo",o.K),N.get("/getItemsSearch/:searchTerms",o.S),N.get("/pdf/:pdfName",T.d),N.get("/getTags",o.M),N.get("/marcas/getAll",o.I),N.get("/getSiteMap",m),N.post("/getListOfItemsFilteredByRegex",o.p),N.post("/getListOfTagsFilteredByRegex",o.q),N.post("/addTipo",O.B,g),N.put("/updateTipo",O.B,h),N.put("/addSubTipo",O.B,f),N.put("/uptateSupTipos",O.B,$),N.post("/addItem",O.v,o.e),N.put("/updateItem",O.B,o.U),N.post("/addItemReview",O.f,o.b),N.post("/addCaracteristica",O.B,o.a),N.post("/deteleCaracteristicas",O.B,o.l),N.post("/addTag",O.B,o.f),N.post("/deteleTags",O.B,o.o),N.post("/toFavorite",O.B,o.j),N.post("/toUnFavorite",O.B,o.k),N.put("/uploadVariationSC",O.B,o.T),N.put("/uploadVariationSimple",O.B,o.h),N.post("/marcas/add",O.B,o.d),N.post("/changeFolder",O.B,k),N.post("/reorderItems",O.B,o.R),N.post("/reorderTipos",O.B,V),N.post("/reorderSubTipos",O.B,C),N.delete("/deleteItem/:codigo",O.b,o.m,T.b),N.delete("/deleteTipo/:codigo",O.b,j),N.delete("/deleteSupTipo/:codigo/:subTipoName",O.b,x),N.delete("/marcas/delete/:deleteString",O.B,o.n),N.get("/getItemMayorGananciaPosible",O.v,o.s),N.get("/getItemsLowStock",O.v,o.F),N.get("/getItemsNoStock",O.v,o.H),N.get("/getClienteConMasCompras",O.v,o.y),N.get("/getItemsMasVendido",O.v,o.G),N.get("/getGananciasTotalesSNS",O.v,o.A),N.get("/gananciasInvercionTotal",O.v,o.O),N.get("/getPeorMejorItem",O.v,o.J),N.get("/getVariacionPosnegAll",O.v,o.P),N.get("/ventasPotenciales",O.v,o.Q),N.get("/getItemBalance/:codigo",O.v,o.C),N.get("/getItemReport/:codigo",O.v,o.D),N.get("/getTableInfItem",O.v,o.L),N.get("/getItemVentasPorMes/:codigoItem",O.v,o.ab),N.get("/getItemGIC/:codigoItem",O.v,o.z),N.post("/uploads/image/:codigo",O.B,T.f.single("img"),T.e,T.a,o.V),N.post("/uploads/imageCat/:codigo",O.B,T.f.single("img"),T.e,T.a,w),N.post("/uploads/imageSubCat/:codigo/:subCat",O.B,T.f.single("img"),T.e,T.a,S),N.post("/uploads/ficha/:codigo",O.B,T.g.single("pdf"),T.c,o.i);t.a=N},function(e,t,n){"use strict";var r=n(4),o=n(2),a=n(9),i=n(0),s=n(27),c=n.n(s),u=n(3),d=n.n(u),p=n(1),l=n(15),m=n.n(l);function g(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,s=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,a=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw a}}}}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function y(e,t,n,r,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}var b=function(){var e,t=(e=regeneratorRuntime.mark((function e(t,n,r,o){var a,i,s,c,u,d;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,a=new m.a.Workbook,i=a.addWorksheet(t,{sheetFormat:{defaultRowHeight:20,defaultColWidth:20}}),s=a.createStyle({font:{color:"black",size:12},border:{right:{style:"thin",color:"white"},left:{style:"thin",color:"white"},bottom:{style:"thin",color:"white"}},alignment:{vertical:"center"},numberFormat:"[$S/-es-PE]#,##0.00"}),c=a.createStyle({font:{color:"black",size:12},border:{right:{style:"thin",color:"white"},left:{style:"thin",color:"white"},bottom:{style:"thin",color:"white"}},alignment:{vertical:"center"},numberFormat:"[$S/-es-PE]#,##0.00",fill:{type:"pattern",patternType:"solid",fgColor:"#e2f3ff"}}),i.row(2).setHeight(40),i.row(4).setHeight(20),i.column(1).setWidth(10),i.column(4).setWidth(60),v(a,i,n),h(a,i,r),u=$(i,o,5,s,c),i.cell(u,6).string("Total").style(s).style({font:{size:14,bold:!0,color:"white"},fill:{type:"pattern",patternType:"solid",fgColor:"#e87200"}}),i.cell(u,7).formula("SUBTOTAL(9,F5:F".concat(u-1,")")).style(s).style({font:{size:14,bold:!0,color:"black"},fill:{type:"pattern",patternType:"solid",fgColor:"white"}}),e.next=16,a.writeToBuffer();case 16:return d=e.sent,e.abrupt("return",d);case 20:throw e.prev=20,e.t0=e.catch(0),new Error(e.t0);case 23:case"end":return e.stop()}}),e,null,[[0,20]])})),function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function i(e){y(a,r,o,i,s,"next",e)}function s(e){y(a,r,o,i,s,"throw",e)}i(void 0)}))});return function(e,n,r,o){return t.apply(this,arguments)}}(),v=function(e,t,n){var r=e.createStyle({font:{color:"white",size:16,bold:!0},alignment:{horizontal:"center",vertical:"center"},fill:{type:"pattern",patternType:"solid",fgColor:"#005087"}});t.cell(2,2,2,7,!0).string(n).style(r),t.row(3).setHeight(10)},h=function(e,t,n){var r,o=e.createStyle({font:{color:"white",size:14},border:{right:{style:"thin",color:"white"},left:{style:"thin",color:"white"},bottom:{style:"thin",color:"white"}},alignment:{horizontal:"left",vertical:"center"},fill:{type:"pattern",patternType:"solid",fgColor:"#e87200"}}),a=2,i=g(n);try{for(i.s();!(r=i.n()).done;){var s=r.value;t.cell(4,a).string(s).style(o),a++}}catch(e){i.e(e)}finally{i.f()}t.row(4).filter({firstColumn:2,lastColumn:7})},$=function e(t,n,r,o,a){var i,s=r-5;if(s>=n.length)return 5;t.row(r).setHeight(20),i=r%2==0?a:o;var c=new Date(n[s].date);t.cell(r,2).date(c.toLocaleDateString()).style(i).style({numberFormat:"dd-mm-yyy",alignment:{horizontal:"left",vertical:"center"}}),t.cell(r,3).string(n[s].codigo).style(i);var u="";return n[s].documento.name&&(u=n[s].documento.name+" | "+n[s].documento.codigo),t.cell(r,4).string(u).style(i),t.cell(r,5).string(n[s].vendedor).style(i),t.cell(r,6).number(n[s].totalPriceNoIGV).style(i),t.cell(r,7).number(n[s].totalPrice).style(i),1+e(t,n,r+1,o,a)},x=n(13);function w(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return S(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return S(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,s=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,a=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw a}}}}function S(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function j(e,t,n,r,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function V(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function i(e){j(a,r,o,i,s,"next",e)}function s(e){j(a,r,o,i,s,"throw",e)}i(void 0)}))}}var C=p.a.production.sunatToken,k=d.a.model("Venta",x.a),T=function(){var e=V(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r=new RegExp(t.params.vendedor,"i"),e.next=4,k.find({vendedor:r}).sort({date:-1}).limit(20);case 4:o=e.sent,n.json(o),e.next=11;break;case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 11:case"end":return e.stop()}}),e,null,[[0,8]])})));return function(t,n){return e.apply(this,arguments)}}(),O=function(){var e=V(regeneratorRuntime.mark((function e(t,n){var r,o,a,i,s,c,u,d,p;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,k.findOne({codigo:t.body.codigo});case 3:r=e.sent,o=Math.round(100*(r.totalPrice-t.body.totalPriceSC+Number.EPSILON))/100,a=I(o),i=0,s=0,c=w(r.itemsVendidos),e.prev=9,c.s();case 11:if((u=c.n()).done){e.next=19;break}if(d=u.value,t.body.itemCodigo!==d.codigo){e.next=17;break}return i=Math.round(100*(d.totalPrice-t.body.totalPriceSC+Number.EPSILON))/100,s=I(i),e.abrupt("break",19);case 17:e.next=11;break;case 19:e.next=24;break;case 21:e.prev=21,e.t0=e.catch(9),c.e(e.t0);case 24:return e.prev=24,c.f(),e.finish(24);case 27:return e.next=29,k.findOneAndUpdate({codigo:t.body.codigo,itemsVendidos:{$elemMatch:{codigo:t.body.itemCodigo}}},{$pull:{"itemsVendidos.$.cantidadSC":{name:t.body.name,nameSecond:t.body.nameSecond}},$inc:{"itemsVendidos.$.cantidad":-t.body.cantidadVenta},$set:{"itemsVendidos.$.totalPrice":i,"itemsVendidos.$.totalPriceNoIGV":s,totalPrice:o,totalPriceNoIGV:a}},{new:!0,useFindAndModify:!1});case 29:p=e.sent,n.json(p),e.next=36;break;case 33:return e.prev=33,e.t1=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t1}));case 36:case"end":return e.stop()}}),e,null,[[0,33],[9,21,24,27]])})));return function(t,n){return e.apply(this,arguments)}}(),N=function(){var e=V(regeneratorRuntime.mark((function e(t,n){var r,o,a,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,k.findOne({codigo:t.body.codigo});case 3:if(r=e.sent,-1!==r.itemsVendidos.findIndex((function(e){return e.codigo===t.body.itemCodigo}))){e.next=7;break}return e.abrupt("return",n.status(409).json({errorMSG:"El item ya a sido eliminado"}));case 7:return o=Math.round(100*(r.totalPrice-t.body.totalItemPrice+Number.EPSILON))/100,a=I(o),e.next=11,k.findOneAndUpdate({codigo:t.body.codigo},{$pull:{itemsVendidos:{codigo:t.body.itemCodigo}},$set:{totalPrice:o,totalPriceNoIGV:a}},{new:!0,useFindAndModify:!1});case 11:return i=e.sent,e.abrupt("return",n.json(i));case 15:return e.prev=15,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 18:case"end":return e.stop()}}),e,null,[[0,15]])})));return function(t,n){return e.apply(this,arguments)}}(),I=function(e){var t=e/1.18;return Math.round(100*(t+Number.EPSILON))/100},A=function(){var e=V(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,k.findOne({codigo:t.params.ventaCod});case 3:r=e.sent,n.json(r),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),R=function(){var e=V(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,k.find({estado:"pendiente",vendedor:t.user.aud.split(" ")[0]});case 3:r=e.sent,n.json(r),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),_=function(){var e=V(regeneratorRuntime.mark((function e(t,n){var r,o,a,i,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,(o={})[t.body.orden]=t.body.ordenOrden,a=new RegExp(t.body.busqueda||"","gi"),i=new RegExp(t.body.busquedaItemCodigo||"","gi"),s=new RegExp(t.body.busquedaUsername||"","gi"),"noone"!==t.body.dateOne&&"noone"!==t.body.dateTwo){e.next=12;break}return e.next=9,k.find({estado:{$in:t.body.estado},"itemsVendidos.codigo":{$regex:i},vendedor:{$regex:s},$or:[{"documento.name":{$regex:a}},{"documento.codigo":Number(t.body.busqueda)||-1}],"documento.type":{$in:t.body.tipo}}).skip(parseInt(t.body.skip)).limit(parseInt(t.body.limit)).sort(o);case 9:r=e.sent,e.next=15;break;case 12:return e.next=14,k.find({estado:{$in:t.body.estado},"itemsVendidos.codigo":{$regex:i},vendedor:{$regex:s},$or:[{"documento.name":{$regex:a}},{"documento.codigo":Number(t.body.busqueda)||-1}],"documento.type":{$in:t.body.tipo},date:{$gte:new Date(t.body.dateOne),$lte:new Date(t.body.dateTwo)}}).skip(parseInt(t.body.skip)).limit(parseInt(t.body.limit)).sort(o);case 14:r=e.sent;case 15:n.json(r),e.next=21;break;case 18:return e.prev=18,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 21:case"end":return e.stop()}}),e,null,[[0,18]])})));return function(t,n){return e.apply(this,arguments)}}(),P=function(){var e=V(regeneratorRuntime.mark((function e(t,n){var r,o,a,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,o=new RegExp(t.body.busqueda||"","gi"),a=new RegExp(t.body.busquedaItemCodigo||"","gi"),i=new RegExp(t.body.busquedaUsername||"","gi"),"noone"!==t.body.dateOne&&"noone"!==t.body.dateTwo){e.next=10;break}return e.next=7,k.aggregate([{$match:{estado:{$in:t.body.estado},"itemsVendidos.codigo":{$regex:a},vendedor:{$regex:i},$or:[{"documento.name":{$regex:o}},{"documento.codigo":Number(t.body.busqueda)||-1}],"documento.type":{$in:t.body.tipo}}},{$count:"cantidadVentas"}]);case 7:r=e.sent,e.next=13;break;case 10:return e.next=12,k.aggregate([{$match:{estado:{$in:t.body.estado},"itemsVendidos.codigo":{$regex:a},vendedor:{$regex:i},$or:[{"documento.name":{$regex:o}},{"documento.codigo":Number(t.body.busqueda)||-1}],"documento.type":{$in:t.body.tipo},date:{$gte:new Date(t.body.dateOne),$lt:new Date(t.body.dateTwo)}}},{$count:"cantidadVentas"}]);case 12:r=e.sent;case 13:n.json(r[0]),e.next=19;break;case 16:return e.prev=16,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 19:case"end":return e.stop()}}),e,null,[[0,16]])})));return function(t,n){return e.apply(this,arguments)}}(),E=function(){var e=V(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,c.a.post("https://api.migo.pe/api/v1/dni",{token:C,dni:t.params.dni});case 3:r=e.sent,n.json(r.data),e.next=18;break;case 7:if(e.prev=7,e.t0=e.catch(0),422!==e.t0.response.status){e.next=13;break}return e.abrupt("return",n.status(422).json({errorMSG:"Numero Invalido"}));case 13:if(404!==e.t0.response.status){e.next=17;break}return e.abrupt("return",n.status(404).json({errorMSG:"Documento No Encontrado"}));case 17:return e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 18:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),G=function(){var e=V(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,c.a.post("https://api.migo.pe/api/v1/ruc",{token:C,ruc:t.params.ruc});case 3:r=e.sent,n.json(r.data),e.next=18;break;case 7:if(e.prev=7,e.t0=e.catch(0),422!==e.t0.response.status){e.next=13;break}return e.abrupt("return",n.status(422).json({errorMSG:"Numero Invalido"}));case 13:if(404!==e.t0.response.status){e.next=17;break}return e.abrupt("return",n.status(404).json({errorMSG:"Documento No Encontrado"}));case 17:return e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 18:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),M=function(){var e=V(regeneratorRuntime.mark((function e(t,n){var r,o,a,i,s;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r=new RegExp(t.body.busqueda||"","gi"),o=new RegExp(t.body.busquedaItemCodigo||"","gi"),a=new RegExp(t.body.busquedaUsername||"","gi"),e.next=6,k.find({estado:{$in:t.body.estado},"documento.type":{$in:t.body.tipo},"itemsVendidos.codigo":{$regex:o},vendedor:{$regex:a},date:{$gte:new Date(t.body.dateOne),$lte:new Date(t.body.dateTwo)},$or:[{"documento.name":{$regex:r}},{"documento.codigo":Number(t.body.busqueda)||-1}]});case 6:return i=e.sent,e.next=9,b("Ventas","Reporte De Ventas",["Fecha","Codigo","Para","Vendido Por","Precio No IGV","Precio"],i);case 9:s=e.sent,n.writeHead(200,{"Content-Type":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","Content-Disposition":"attachment; filename=reporte.xlsx"}),n.write(s,"binary"),n.end(null,"binary"),e.next=18;break;case 15:return e.prev=15,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 18:case"end":return e.stop()}}),e,null,[[0,15]])})));return function(t,n){return e.apply(this,arguments)}}(),q=function(){var e=V(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,k.aggregate([{$match:{date:{$gte:new Date("2021-01-01")},estado:"ejecutada"}},{$project:{codigo:"$documento.codigo",name:"$documento.name",_id:0,totalPrice:1}},{$group:{_id:"$name",value:{$sum:"$totalPrice"}}},{$match:{_id:{$ne:null,$exists:!0}}},{$match:{_id:{$ne:""}}},{$project:{_id:0,name:"$_id",value:1}},{$sort:{value:-1}},{$limit:4}]);case 3:r=e.sent,n.json(r),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),D=function(){var e=V(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,k.aggregate([{$match:{estado:"ejecutada"}},{$unwind:"$itemsVendidos"},{$match:{"itemsVendidos.codigo":t.params.codigoItem}},{$group:{_id:null,totalVenta:{$sum:{$multiply:["$itemsVendidos.priceIGV","$itemsVendidos.cantidad"]}},totalGasto:{$sum:{$multiply:["$itemsVendidos.priceCosto","$itemsVendidos.cantidad"]}}}},{$project:{_id:0,totalVenta:1,value:{$subtract:["$totalVenta","$totalGasto"]}}}]);case 3:r=e.sent,n.json(r[0]?r[0]:{value:0,totalVenta:0}),e.next=10;break;case 7:return e.prev=7,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}(),L=function(){var e=V(regeneratorRuntime.mark((function e(t,n){var r,o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,k.aggregate([{$match:{estado:"ejecutada"}},{$unwind:"$itemsVendidos"},{$match:{"itemsVendidos.codigo":t.params.codigoItem}},{$set:{mesVenta:{$dateToString:{format:"%Y-%m",date:"$date",timezone:"-05:00"}}}},{$group:{_id:"$mesVenta",totalVenta:{$sum:{$multiply:["$itemsVendidos.priceIGV","$itemsVendidos.cantidad"]}},totalGasto:{$sum:{$multiply:["$itemsVendidos.priceCosto","$itemsVendidos.cantidad"]}}}},{$project:{name:"$_id",_id:0,value:{$trunc:[{$subtract:["$totalVenta","$totalGasto"]},0]}}},{$sort:{name:1}}]);case 3:return r=e.sent,e.next=6,k.aggregate([{$match:{estado:"ejecutada"}},{$unwind:"$itemsVendidos"},{$match:{"itemsVendidos.codigo":t.params.codigoItem}},{$set:{mesVenta:{$dateToString:{format:"%Y-%m",date:"$date",timezone:"-05:00"}}}},{$group:{_id:"$mesVenta",totalVenta:{$sum:{$multiply:["$itemsVendidos.priceIGV","$itemsVendidos.cantidad"]}},totalGasto:{$sum:{$multiply:["$itemsVendidos.priceCosto","$itemsVendidos.cantidad"]}}}},{$project:{name:"$_id",_id:0,value:"$totalVenta"}},{$sort:{name:1}}]);case 6:o=e.sent,a=[{name:"Ingresos",series:o},{name:"Ganancia",series:r}],n.json(a),e.next=14;break;case 11:return e.prev=11,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 14:case"end":return e.stop()}}),e,null,[[0,11]])})));return function(t,n){return e.apply(this,arguments)}}(),B=function(){var e=V(regeneratorRuntime.mark((function e(t,n,r){var o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,k.aggregate([{$match:{date:{$gte:new Date("2021-01-01")},estado:"ejecutada"}},{$unwind:"$itemsVendidos"},{$replaceRoot:{newRoot:"$itemsVendidos"}},{$group:{_id:"$codigo",totalVenta:{$sum:{$multiply:["$priceIGV","$cantidad"]}},totalGasto:{$sum:{$multiply:["$priceCosto","$cantidad"]}}}},{$project:{name:"$_id",_id:0,totalVenta:1,value:{$trunc:[{$subtract:["$totalVenta","$totalGasto"]},0]}}},{$sort:{value:-1}}]);case 3:o=e.sent,t.gananciaPorItem=o,r(),e.next=11;break;case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 11:case"end":return e.stop()}}),e,null,[[0,8]])})));return function(t,n,r){return e.apply(this,arguments)}}(),U=function(){var e=V(regeneratorRuntime.mark((function e(t,n){var r,o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,k.aggregate([{$match:{date:{$gte:new Date("2021-01-01")},estado:"ejecutada"}},{$project:{month:{$dateToString:{format:"%Y-%m",date:"$date",timezone:"-05:00"}},date:1,totalPrice:1,totalPriceNoIGV:1}},{$group:{_id:"$month",value:{$sum:"$totalPrice"}}},{$project:{_id:0,value:{$trunc:["$value",0]},name:"$_id"}},{$sort:{name:1}}]);case 3:return r=e.sent,e.next=6,k.aggregate([{$match:{date:{$gte:new Date("2021-01-01")},estado:"ejecutada"}},{$project:{month:{$dateToString:{format:"%Y-%m",date:"$date",timezone:"-05:00"}},itemsVendidos:1}},{$unwind:"$itemsVendidos"},{$group:{_id:"$month",itemsVendidosPorMes:{$push:{$subtract:[{$multiply:["$itemsVendidos.cantidad","$itemsVendidos.priceIGV"]},{$multiply:["$itemsVendidos.cantidad","$itemsVendidos.priceCosto"]}]}}}},{$project:{_id:0,value:{$trunc:[{$sum:"$itemsVendidosPorMes"},0]},name:"$_id"}},{$sort:{name:1}}]);case 6:return o=e.sent,a=[{name:"Ventas",series:r},{name:"Ganancias",series:o}],e.abrupt("return",n.json(a));case 11:return e.prev=11,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 14:case"end":return e.stop()}}),e,null,[[0,11]])})));return function(t,n){return e.apply(this,arguments)}}(),F=function(){var e=V(regeneratorRuntime.mark((function e(t,n){var r,o,a,i,s,c,u;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,r=z(parseInt(t.params.month),parseInt(t.params.year)),e.next=4,k.aggregate([{$match:{date:{$gte:new Date("2021-01-01")},estado:"ejecutada"}},{$project:{_id:0,codigo:1,totalPrice:1,day:{$dayOfMonth:"$date"},gastosVenta:{$sum:{$map:{input:"$itemsVendidos",as:"itemVendido",in:{$multiply:["$$itemVendido.cantidad","$$itemVendido.priceCosto"]}}}},year:{$year:"$date"},month:{$month:"$date"}}},{$match:{year:parseInt(t.params.year),month:parseInt(t.params.month)}},{$project:{_id:0,codigo:1,totalPrice:1,day:1,gastosVenta:1,gananciasVenta:{$subtract:["$totalPrice","$gastosVenta"]}}},{$group:{_id:"$day",ganancias:{$sum:"$gananciasVenta"},ventas:{$sum:"$totalPrice"}}},{$sort:{_id:1}}]);case 4:o=e.sent,a=[],i=0,s=0,c=0;case 9:if(!(c<r)){e.next=22;break}if((u=o[s]?o[s]._id:-1)!==c+1){e.next=16;break}"ganancia"===t.params.calcular?i+=o[s].ganancias:"venta"===t.params.calcular&&(i+=o[s].ventas),s++,e.next=18;break;case 16:if(-1!==u){e.next=18;break}return e.abrupt("break",22);case 18:a.push({name:c+1,value:i.toFixed(2)});case 19:c++,e.next=9;break;case 22:n.json(a),e.next=28;break;case 25:return e.prev=25,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 28:case"end":return e.stop()}}),e,null,[[0,25]])})));return function(t,n){return e.apply(this,arguments)}}(),z=function(e,t){return new Date(t,e,0).getDate()},W=new r.Router;W.get("/getLastVentas/:vendedor",i.f,T),W.get("/getGananciaTotalPorItem/:codigoItem",i.v,D),W.get("/getItemGananciaIngreso/:codigoItem",i.v,L),W.get("/getVentasPorDiaMes/:month/:year/:calcular",i.v,F),W.get("/getMejoresClientes",i.v,q),W.get("/getItemsGanancias",i.v,B,o.r),W.get("/getInfoToPlotVentasOverTime",i.v,U),W.put("/eliminarItemVenta",i.B,N),W.put("/eliminarItemSCVenta",i.B,O),W.put("/anularVentaPost",i.B,o.X),W.get("/dni/:dni",i.f,E),W.post("/createExcelReport",i.v,M),W.post("/getEjecutadas",i.v,_),W.post("/getCantidadVentas",i.v,P),W.get("/testTotal",i.v,o.x),W.get("/ruc/:ruc",i.f,G),W.get("/obtenerVenta/:ventaCod",i.v,A),W.post("/ventaSimple",i.B,o.Z,a.c,a.b,o.c),W.post("/agregarVenta",i.B,i.A,o.t,i.e),W.get("/ventasActivasFull",i.v,R),W.get("/ventasActivasList",i.v,i.o),W.post("/agregarItemVenta",i.B,o.g),W.post("/ventasForCard",i.v,o.N),W.post("/ejecutarVenta",i.B,o.Y,a.c,a.b,o.c),W.put("/anularVenta",i.B,o.W);t.a=W},function(e,t,n){"use strict";var r=n(4),o=n(3),a=n.n(o),i=n(12),s=n(11),c=n(13);function u(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function d(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?u(Object(n),!0).forEach((function(t){p(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):u(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function p(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t,n,r,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function m(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function i(e){l(a,r,o,i,s,"next",e)}function s(e){l(a,r,o,i,s,"throw",e)}i(void 0)}))}}var g=a.a.model("Item",i.a),f=a.a.model("Venta",c.a),y=a.a.model("User",s.a),b=[{cod:0,mensaje:"Item Eliminado"},{cod:1,mensaje:"Cambio de precio"},{cod:2,mensaje:"Cantidad agotada"}],v=function(){var e=m(regeneratorRuntime.mark((function e(t,n){var r,o,i,s,c,u,d,p,l,m,b,v,$,x,w,S,j,V,C,k,T,O,N,I;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,a.a.startSession();case 2:return(r=e.sent).startTransaction(),e.prev=4,e.next=7,y.findOne({username:t.user.aud.split(" ")[0]});case 7:return o=e.sent,e.next=10,g.findOne({codigo:t.body.codigo});case 10:if((i=e.sent).subConteo&&(s=""!==i.subConteo.nameSecond?i.subConteo.order.find((function(e){return e.name===t.body.orderToAdd.name&&e.nameSecond===t.body.orderToAdd.nameSecond})):i.subConteo.order.find((function(e){return e.name===t.body.orderToAdd.name}))),!i.deleted){e.next=19;break}return e.next=15,r.abortTransaction();case 15:return r.endSession(),e.abrupt("return",n.status(410).json({errorMSG:"El item ha sido elminado"}));case 19:if(i.priceIGV===t.body.priceIGV){e.next=26;break}return e.next=22,r.abortTransaction();case 22:return r.endSession(),e.abrupt("return",n.status(409).json({errorMSG:"El precio del producto ha cambiado"}));case 26:if(!(i.cantidad<t.body.cantidad)){e.next=33;break}return e.next=29,r.abortTransaction();case 29:return r.endSession(),e.abrupt("return",n.status(409).json({errorMSG:"Ya no contamos con la cantidad deseada"}));case 33:if(!i.subConteo){e.next=39;break}if(!(s.cantidad<t.body.cantidad)){e.next=39;break}return e.next=37,r.abortTransaction();case 37:return r.endSession(),e.abrupt("return",n.status(409).json({errorMSG:"Ya no contamos con la cantidad deseada"}));case 39:if("not"!==o.carrito){e.next=54;break}return(c=new f({totalPrice:t.body.cantidad*i.priceIGV,totalPriceNoIGV:t.body.cantidad*i.priceNoIGV,estado:"pendiente",vendedor:t.user.aud.split(" ")[0],tipoVendedor:"low",medio_de_pago:"efectivo",cliente_email:o.email,itemsVendidos:[],carrito_venta:!0})).itemsVendidos.push({codigo:i.codigo,tipo:"producto",descripcion:i.description,name:i.name,priceIGV:i.priceIGV,priceNoIGV:i.priceNoIGV,priceCosto:i.costoPropio,cantidad:t.body.cantidad,cantidadSC:[],totalPrice:t.body.cantidad*i.priceIGV,totalPriceNoIGV:t.body.cantidad*i.priceNoIGV,unidadDeMedida:i.unidadDeMedida,photo:i.photo}),i.subConteo&&(""!==i.subConteo.nameSecond?c.itemsVendidos[0].cantidadSC.push({name:s.name,nameSecond:s.nameSecond,cantidadDisponible:s.cantidad,cantidadVenta:t.body.cantidad}):c.itemsVendidos[0].cantidadSC.push({name:s.name,nameSecond:void 0,cantidadDisponible:s.cantidad,cantidadVenta:t.body.cantidad})),e.next=45,h();case 45:return u=e.sent,c.codigo=u,e.next=49,c.save();case 49:return t.ventaGenerada=e.sent,e.next=52,y.findOneAndUpdate({username:t.user.aud.split(" ")[0]},{carrito:t.ventaGenerada.codigo},{useFindAndModify:!1,new:!0});case 52:e.next=100;break;case 54:return e.next=56,f.findOne({codigo:o.carrito});case 56:if(d=e.sent,-1!==(p=d.itemsVendidos.findIndex((function(e){return e.codigo===i.codigo})))){e.next=66;break}return l={codigo:i.codigo,tipo:"producto",descripcion:i.description,name:i.name,priceIGV:i.priceIGV,priceNoIGV:i.priceNoIGV,priceCosto:i.costoPropio,cantidad:t.body.cantidad,cantidadSC:[],totalPrice:t.body.cantidad*i.priceIGV,totalPriceNoIGV:t.body.cantidad*i.priceNoIGV,unidadDeMedida:i.unidadDeMedida,photo:i.photo},i.subConteo&&(""!==i.subConteo.nameSecond?l.cantidadSC.push({name:s.name,nameSecond:s.nameSecond,cantidadDisponible:s.cantidad,cantidadVenta:t.body.cantidad}):l.cantidadSC.push({name:s.name,nameSecond:void 0,cantidadDisponible:s.cantidad,cantidadVenta:t.body.cantidad})),e.next=63,f.findOneAndUpdate({codigo:o.carrito},{$push:{itemsVendidos:l},$inc:{totalPrice:l.totalPrice,totalPriceNoIGV:l.totalPriceNoIGV}},{useFindAndModify:!1,new:!0});case 63:t.ventaGenerada=e.sent,e.next=100;break;case 66:if(!(p>-1)){e.next=100;break}if(!i.subConteo){e.next=93;break}if(m=-1,-1!==(m=""===i.subConteo.nameSecond?d.itemsVendidos[p].cantidadSC.findIndex((function(e){return e.name===s.name})):d.itemsVendidos[p].cantidadSC.findIndex((function(e){return e.name===s.name&&e.nameSecond===s.nameSecond})))){e.next=81;break}return b=d.itemsVendidos[p].cantidad+t.body.cantidad,v=i.priceIGV*b,$=i.priceNoIGV*b,x=d.totalPrice-d.itemsVendidos[p].totalPrice+v,w=d.totalPriceNoIGV-d.itemsVendidos[p].totalPriceNoIGV+$,e.next=78,f.findOneAndUpdate({codigo:o.carrito,"itemsVendidos.codigo":i.codigo},{totalPrice:x,totalPriceNoIGV:w,$set:{"itemsVendidos.$.priceIGV":i.priceIGV,"itemsVendidos.$.priceNoIGV":i.priceNoIGV,"itemsVendidos.$.priceCosto":i.costoPropio,"itemsVendidos.$.cantidad":b,"itemsVendidos.$.totalPriceNoIGV":$,"itemsVendidos.$.totalPrice":v},$push:{"itemsVendidos.$.cantidadSC":{name:s.name,nameSecond:s.nameSecond||void 0,cantidadDisponible:s.cantidad,cantidadVenta:t.body.cantidad}}},{useFindAndModify:!1,new:!0});case 78:t.ventaGenerada=e.sent,e.next=91;break;case 81:return S=d.itemsVendidos[p].cantidad-d.itemsVendidos[p].cantidadSC[m].cantidadVenta+t.body.cantidad,j=i.priceIGV*S,V=i.priceNoIGV*S,C=d.totalPrice-d.itemsVendidos[p].totalPrice+j,k=d.totalPriceNoIGV-d.itemsVendidos[p].totalPriceNoIGV+V,d.itemsVendidos[p].cantidadSC[m].cantidadDisponible=s.cantidad,d.itemsVendidos[p].cantidadSC[m].cantidadVenta=t.body.cantidad,e.next=90,f.findOneAndUpdate({codigo:o.carrito,"itemsVendidos.codigo":i.codigo},{totalPrice:C,totalPriceNoIGV:k,$set:{"itemsVendidos.$.priceIGV":i.priceIGV,"itemsVendidos.$.priceNoIGV":i.priceNoIGV,"itemsVendidos.$.priceCosto":i.costoPropio,"itemsVendidos.$.cantidad":S,"itemsVendidos.$.totalPriceNoIGV":V,"itemsVendidos.$.totalPrice":j,"itemsVendidos.$.cantidadSC":d.itemsVendidos[p].cantidadSC}},{useFindAndModify:!1,new:!0});case 90:t.ventaGenerada=e.sent;case 91:e.next=100;break;case 93:return T=t.body.cantidad*i.priceIGV,O=t.body.cantidad*i.priceNoIGV,N=d.totalPrice-d.itemsVendidos[p].totalPrice+T,I=d.totalPriceNoIGV-d.itemsVendidos[p].totalPriceNoIGV+O,e.next=99,f.findOneAndUpdate({codigo:o.carrito,"itemsVendidos.codigo":i.codigo},{totalPrice:N,totalPriceNoIGV:I,$set:{"itemsVendidos.$.priceIGV":i.priceIGV,"itemsVendidos.$.priceNoIGV":i.priceNoIGV,"itemsVendidos.$.priceCosto":i.costoPropio,"itemsVendidos.$.cantidad":t.body.cantidad,"itemsVendidos.$.totalPriceNoIGV":O,"itemsVendidos.$.totalPrice":T}},{useFindAndModify:!1,new:!0});case 99:t.ventaGenerada=e.sent;case 100:return e.next=102,r.commitTransaction();case 102:return r.endSession(),e.abrupt("return",n.json(t.ventaGenerada));case 106:return e.prev=106,e.t0=e.catch(4),e.next=110,r.abortTransaction();case 110:return r.endSession(),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 112:case"end":return e.stop()}}),e,null,[[4,106]])})));return function(t,n){return e.apply(this,arguments)}}(),h=function(){var e=m(regeneratorRuntime.mark((function e(){var t,n,r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,f.countDocuments({});case 3:for(e.t0=e.sent,t=e.t0+1,n="SD01-000000",r=0;r<t.toString().length;r++)n=n.slice(0,-1);return o=n+t.toString(),e.abrupt("return",o);case 11:return e.prev=11,e.t1=e.catch(0),e.abrupt("return",res.status(500).json({errorMSG:e.t1}));case 14:case"end":return e.stop()}}),e,null,[[0,11]])})));return function(){return e.apply(this,arguments)}}(),$=function(){var e=m(regeneratorRuntime.mark((function e(t,n){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,a.a.startSession();case 2:return(r=e.sent).startTransaction(),e.prev=4,e.delegateYield(regeneratorRuntime.mark((function e(){var o,a,i,s,c,u,p,l,m,y,b,v,h;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,f.aggregate([{$match:{codigo:t.carrito_codigo}},{$unwind:"$itemsVendidos"},{$replaceRoot:{newRoot:"$itemsVendidos"}},{$unwind:{path:"$cantidadSC",preserveNullAndEmptyArrays:!0}},{$sort:{codigo:-1}}]);case 2:for(o=e.sent,a=[{cod:0,mensaje:"Item Eliminado"},{cod:1,mensaje:"Cambio de precio"}],i=[],s=[],c="",u=0;u<o.length;u++)o[u].codigo!==c&&s.push(o[u].codigo),c=o[u].codigo;return e.next=10,g.aggregate([{$match:{codigo:{$in:s}}},{$sort:{codigo:-1}}]);case 10:p=e.sent,l=[],m=0,y="",b="",v=regeneratorRuntime.mark((function e(n){var r,s,c,u;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!p[m].deleted){e.next=8;break}if(y===p[m].codigo){e.next=6;break}return y=p[m].codigo,i.push(d(d({},a[0]),{},{item_cod:p[m].codigo,item_name:p[m].name})),e.next=6,f.findOneAndUpdate({codigo:t.carrito_codigo},{$inc:{totalPrice:-o[n].cantidad*o[n].priceIGV,totalPriceNoIGV:-o[n].cantidad*o[n].priceNoIGV},$pull:{itemsVendidos:{codigo:y}}},{useFindAndModify:!1,new:!0});case 6:e.next=20;break;case 8:if(p[m].priceIGV===o[n].priceIGV||b===p[m].codigo){e.next=15;break}return b=p[m].codigo,i.push(d(d({},a[1]),{},{item_cod:p[m].codigo,item_name:p[m].name})),r=p[m].priceIGV*o[n].cantidad,s=p[m].priceNoIGV*o[n].cantidad,e.next=15,f.findOneAndUpdate({codigo:t.carrito_codigo,"itemsVendidos.codigo":p[m].codigo},{$inc:{totalPrice:r-o[n].totalPrice,totalPriceNoIGV:s-o[n].totalPriceNoIGV},$set:{"itemsVendidos.$.totalPrice":r,"itemsVendidos.$.totalPriceNoIGV":s,"itemsVendidos.$.priceIGV":p[m].priceIGV,"itemsVendidos.$.priceNoIGV":p[m].priceNoIGV}},{useFindAndModify:!1,new:!0});case 15:o[n].priceIGV=p[m].priceIGV,o[n].priceNoIGV=p[m].priceNoIGV,o[n].totalPrice=p[m].priceIGV*o[n].cantidad,o[n].totalPriceNoIGV=p[m].priceNoIGV*o[n].cantidad,p[m].subConteo?(c=o[n],u=p[m].subConteo.order.find((function(e){return e.name===c.cantidadSC.name&&e.nameSecond===o[n].cantidadSC.nameSecond})),l.push(d(d({},o[n]),{},{cantidadDisponible:u.cantidad,codVent:t.carrito_codigo}))):l.push(d(d({},o[n]),{},{cantidadDisponible:p[m].cantidad,codVent:t.carrito_codigo}));case 20:o[n].codigo!==(o[n+1]?o[n+1].codigo:"xxxxx")&&m++;case 21:case"end":return e.stop()}}),e)})),h=0;case 17:if(!(h<o.length)){e.next=22;break}return e.delegateYield(v(h),"t0",19);case 19:h++,e.next=17;break;case 22:return e.next=24,r.commitTransaction();case 24:r.endSession(),n.json({carrito:l,cod_carrito:t.carrito_codigo,estado_carrito:t.estadoCarrito,alerts:i});case 26:case"end":return e.stop()}}),e)}))(),"t0",6);case 6:e.next=14;break;case 8:return e.prev=8,e.t1=e.catch(4),e.next=12,r.abortTransaction();case 12:return r.endSession(),e.abrupt("return",n.status(500).json({errorMSG:e.t1}));case 14:case"end":return e.stop()}}),e,null,[[4,8]])})));return function(t,n){return e.apply(this,arguments)}}(),x=function(){var e=m(regeneratorRuntime.mark((function e(t,n){var r,o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,!((o=t.carritoActual[0]).cantidadSC&&o.cantidad-o.cantidadSC.cantidadVenta>0)){e.next=8;break}return e.next=5,f.findOneAndUpdate({codigo:t.body.codVent,"itemsVendidos.codigo":t.body.codigo},{$inc:{totalPrice:-o.cantidadSC.cantidadVenta*o.priceIGV,totalPriceNoIGV:-o.cantidadSC.cantidadVenta*o.priceNoIGV,"itemsVendidos.$.cantidad":-o.cantidadSC.cantidadVenta,"itemsVendidos.$.totalPrice":-o.cantidadSC.cantidadVenta*o.priceIGV,"itemsVendidos.$.totalPriceNoIGV":-o.cantidadSC.cantidadVenta*o.priceNoIGV},$pull:{"itemsVendidos.$.cantidadSC":{name:o.cantidadSC.name,nameSecond:o.cantidadSC.nameSecond}}},{useFindAndModify:!1,new:!0});case 5:r=e.sent,e.next=11;break;case 8:return e.next=10,f.findOneAndUpdate({codigo:t.body.codVent},{$inc:{totalPrice:-o.cantidad*o.priceIGV,totalPriceNoIGV:-o.cantidad*o.priceNoIGV},$pull:{itemsVendidos:{codigo:o.codigo}}},{useFindAndModify:!1,new:!0});case 10:r=e.sent;case 11:t.newCarrito=r,n.json(r),e.next=18;break;case 15:return e.prev=15,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 18:case"end":return e.stop()}}),e,null,[[0,15]])})));return function(t,n){return e.apply(this,arguments)}}(),w=function(){var e=m(regeneratorRuntime.mark((function e(t,n,r){var o;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,y.findOne({username:t.user.aud.split(" ")[0]});case 3:o=e.sent,t.carrito_codigo=o.carrito,r(),e.next=11;break;case 8:return e.prev=8,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 11:case"end":return e.stop()}}),e,null,[[0,8]])})));return function(t,n,r){return e.apply(this,arguments)}}(),S=function(){var e=m(regeneratorRuntime.mark((function e(t,n,r){var o,a;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,f.findOne({codigo:t.body.codVent});case 3:if(o=e.sent,t.estadoCarrito=o.estado_carrito_comprando,!t.body.cantidadSC){e.next=11;break}return e.next=8,f.aggregate([{$match:{codigo:t.body.codVent}},{$unwind:"$itemsVendidos"},{$replaceRoot:{newRoot:"$itemsVendidos"}},{$unwind:{path:"$cantidadSC",preserveNullAndEmptyArrays:!0}},{$match:{codigo:t.body.codigo}},{$match:{"cantidadSC.name":t.body.cantidadSC.name}},{$match:{"cantidadSC.nameSecond":t.body.cantidadSC.nameSecond}},{$sort:{codigo:-1}}]);case 8:a=e.sent,e.next=14;break;case 11:return e.next=13,f.aggregate([{$match:{codigo:t.body.codVent}},{$unwind:"$itemsVendidos"},{$replaceRoot:{newRoot:"$itemsVendidos"}},{$unwind:{path:"$cantidadSC",preserveNullAndEmptyArrays:!0}},{$match:{codigo:t.body.codigo}}]);case 13:a=e.sent;case 14:if(0!==a.length){e.next=16;break}return e.abrupt("return",n.status(409).json());case 16:t.carritoActual=a,r(),e.next=23;break;case 20:return e.prev=20,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 23:case"end":return e.stop()}}),e,null,[[0,20]])})));return function(t,n,r){return e.apply(this,arguments)}}(),j=function(){var e=m(regeneratorRuntime.mark((function e(t,n){var r,o,a,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,y.findOne({username:t.user.aud.split(" ")[0]});case 3:return r=e.sent,t.carrito_codigo=r.carrito,o=[],t.body.carrito.forEach((function(e){o.push(e.codigo)})),e.next=9,g.aggregate([{$match:{codigo:{$in:o}}},{$sort:{codigo:-1}}]);case 9:a=e.sent,i=V([],a,t.body.carrito),n.json(i),e.next=17;break;case 14:return e.prev=14,e.t0=e.catch(0),e.abrupt("return",n.status(500).json({errorMSG:e.t0}));case 17:case"end":return e.stop()}}),e,null,[[0,14]])})));return function(t,n){return e.apply(this,arguments)}}(),V=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;if(n[a].deleted&&t.push(d(d({},b[0]),{},{item_cod:n[a].codigo,item_name:n[a].name})),n[a].priceIGV!==r[o].priceIGV&&t.push(d(d({},b[1]),{},{item_cod:n[a].codigo,item_name:n[a].name})),r[o].cantidadSC){var i=n[a].subConteo.order.find((function(e){return e.name===r[o].cantidadSC.name&&e.nameSecond===r[o].cantidadSC.nameSecond}));i.cantidad-r[o].cantidadSC.cantidad<0&&t.push(d(d({},b[2]),{},{item_cod:n[a].codigo,item_name:n[a].name+" | "+i.carrito[o].cantidadSC.name+" "+i.carrito[o].cantidadSC.nameSecond}))}else n[a].cantidad-r[o].cantidad<0&&t.push(d(d({},b[2]),{},{item_cod:n[a].codigo,item_name:n[a].name}));return r[o].codigo!==(r[o+1]?r[o+1].codigo:"xxxxx")&&a++,o+1===r.length?t:(o++,e(t,n,r,o,a))},C=n(0),k=new r.Router;k.post("/agregarItem",C.u,v),k.post("/removeProductoDeCarrito",C.u,S,x),k.post("/iniciarCompra",C.u,j),k.get("/getCarrito",C.u,w,$);t.a=k},function(e,t,n){n(53),e.exports=n(54)},function(e,t){e.exports=require("babel-polyfill")},function(e,t,n){"use strict";n.r(t);var r=n(30),o=n.n(r),a=n(31),i=n.n(a),s=n(1),c=n(20),u=n(3),d=n.n(u);function p(e,t,n,r,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}var l=s.a.production.log(),m=function(){var e,t=(e=regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,d.a.connect(t,{useNewUrlParser:!0,useUnifiedTopology:!0,useCreateIndex:!0});case 3:return e.abrupt("return",l.info("Connected To DataBase"));case 6:return e.prev=6,e.t0=e.catch(0),e.abrupt("return",l.error(e.t0));case 9:case"end":return e.stop()}}),e,null,[[0,6]])})),function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function i(e){p(a,r,o,i,s,"next",e)}function s(e){p(a,r,o,i,s,"throw",e)}i(void 0)}))});return function(e){return t.apply(this,arguments)}}();n(29).config();var g=o.a.createServer(c.a),f=s.a.production.PORT,y=s.a.production.log(),b=process.env.WEB_CONCURRENCY||1;c.a.set("port",f);i()({worker:function(e,t){y.info("Id Worker ".concat(e)),g.listen(f||0),m(s.a.production.mongoKey)},count:b}),g.on("listening",(function(){y.info("Hi there! I'm listening on port ".concat(g.address().port," in ").concat(c.a.get("env")," mode."))}))}]);